diff --git a/.agents/skills/code_style/SKILL.md b/.agents/skills/code_style/SKILL.md new file mode 100644 index 0000000000..0c929274f9 --- /dev/null +++ b/.agents/skills/code_style/SKILL.md @@ -0,0 +1,46 @@ +--- +name: code_style +description: Gkeyll's C/C++/CUDA code style is enforced by clang-format. Use when writing or editing any .c/.h/.cpp/.hpp/.cu/.cuh file, to know how to format it and which files must never be reformatted. +user-invocable: true +--- + +# Instructions + +* Operate relative to the repo root (detect via `git rev-parse --show-toplevel`). + +# Code style + +The style itself (indentation, brace placement, spacing, etc.) is defined entirely +by the root `.clang-format` file. Don't try to memorize or restate those rules -- +just run the formatter and let it decide: + +``` +clang-format -i +``` + +A `pre-commit` hook runs this automatically on commit, and CI (`.github/workflows/format-check.yml`) +double-checks on push/PR, so a file that hasn't been run through clang-format will +get reformatted or flagged regardless. + +## The rules the config file can't express: never format `ker/` or `core/minus/` + +Two kinds of files must never be run through clang-format, and never hand-formatted +to "match" the style either -- leave them exactly as they are: + +- Any path matching `*/ker/*` (e.g. `core/ker/`, `gyrokinetic/ker/`) contains + auto-generated DG kernel code (see `gkeyll_guide`'s note on `ker/`: generated with + Maxima, never hand-edited). +- Anything under `core/minus/` is a vendored third-party library (e.g. sqlite3, + kann, pcg_basic, STC), not Gkeyll's own code. + +The pre-commit hook and CI already exclude both for this reason. + +## Trailing commas in initializer lists are stripped automatically + +Don't add a trailing comma after the last element of a struct/array +initializer expecting it to force (or preserve) a multi-line layout -- +clang-format expands every element onto its own line whenever one is +present, which is rarely what's wanted. `ci/strip-trailing-commas.py` removes +any comma directly before a closing `}` before clang-format runs, via the +same pre-commit hook and CI check as clang-format itself, so there's also no +need to manually remove existing ones -- the tooling already does it. diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..d0b65e84a6 --- /dev/null +++ b/.clang-format @@ -0,0 +1,124 @@ +# Gkeyll code style (EXPERIMENTAL): the actual Linux kernel .clang-format +# (as shipped at the root of torvalds/linux), with every place it hard-codes +# the kernel's 8-character-wide indentation changed to 2 (spaces, not tabs). +# The upstream file's ForEachMacros list is dropped -- it enumerates Linux +# kernel internal iteration macros (bpf_*, drm_*, hlist_*, etc.) that don't +# exist in gkeyll, so keeping it would only add clutter with no effect. +# +# Applies to C/C++/CUDA source under core/, moments/, vlasov/, gyrokinetic/, +# pkpm/, gkeyll/ -- EXCLUDING anything under */ker/* (auto-generated DG kernel +# code) or core/minus/* (vendored third-party libraries), which must never be +# hand-formatted (see .agents/skills/code_style/SKILL.md). These exclusions +# are enforced by the tooling (pre-commit, CI, ci/format-all.sh), not by this +# file, since clang-format configs can't express path excludes. +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: BlockIndent +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +InsertBraces : true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: false +ColumnLimit: 100 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentGotoLabels: false +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true + +# Taken from git's rules (as in the upstream kernel .clang-format) +PenaltyBreakAssignment: 10 +PenaltyBreakBeforeFirstCallParameter: 30 +PenaltyBreakComment: 10 +PenaltyBreakFirstLessLess: 0 +PenaltyBreakString: 10 +PenaltyExcessCharacter: 100 +PenaltyReturnTypeOnItsOwnLine: 60 + +PointerAlignment: Right +ReflowComments: false +SortIncludes: false +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatementsExceptForEachMacros +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp03 +TabWidth: 2 +UseTab: Never +AttributeMacros: + - GKYL_CU_DH + - GKYL_CU_D diff --git a/.claude/skills/code_style b/.claude/skills/code_style new file mode 120000 index 0000000000..36b5b6fafb --- /dev/null +++ b/.claude/skills/code_style @@ -0,0 +1 @@ +../../.agents/skills/code_style \ No newline at end of file diff --git a/.codex/skills/code_style b/.codex/skills/code_style new file mode 120000 index 0000000000..36b5b6fafb --- /dev/null +++ b/.codex/skills/code_style @@ -0,0 +1 @@ +../../.agents/skills/code_style \ No newline at end of file diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml new file mode 100644 index 0000000000..fd1692fa5e --- /dev/null +++ b/.github/workflows/format-check.yml @@ -0,0 +1,24 @@ +name: Format Check + +on: + push: + branches: [main] + pull_request: + branches: [main] + types: [opened, synchronize, reopened, ready_for_review] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + clang-format: + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + - uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..2c715caef0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +repos: + - repo: local + hooks: + - id: strip-trailing-commas + name: Strip trailing commas before closing braces + entry: python3 ci/strip-trailing-commas.py + language: system + files: \.(c|h|cpp|hpp|cu|cuh)$ + exclude: (^|/)ker/|^core/minus/ + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v18.1.8 + hooks: + - id: clang-format + files: \.(c|h|cpp|hpp|cu|cuh)$ + exclude: (^|/)ker/|^core/minus/ diff --git a/README.md b/README.md index 5005a9d11b..544f7ecd25 100644 --- a/README.md +++ b/README.md @@ -380,3 +380,52 @@ srun -N 1 --ntasks=2 --gpus-per-task=1 --gpu-bind=closest compute-sanitizer --to ``` where the command line arguments must at least contain `-g -M -direction 2` with `direction` being the direction along which the domain is decomposed, e.g. `-e 2` for 3x2v gk simulations. + +## Code style + +C/C++/CUDA source is formatted by [clang-format](https://clang.llvm.org/docs/ClangFormat.html) +using the style defined in the root `.clang-format` (a Linux-kernel-flavored style with +2-space indentation). Two things are excluded and must never be hand-formatted: files +under any `*/ker/*` directory (auto-generated DG kernel code) and anything under +`core/minus/` (third-party libraries). + +One-time setup: + +``` +pip install pre-commit +pre-commit install +``` + +After that, `git commit` automatically reformats any staged C/C++/CUDA file that +isn't already formatted (excluding `ker/` and `core/minus/`). CI +(`.github/workflows/format-check.yml`) re-checks the same thing on push/PR as a backstop. + +clang-format's output differs slightly across versions, so `pre-commit` and CI both +pin `clang-format` `18.1.8` (see the `rev:` in `.pre-commit-config.yaml`). To run +`ci/format-all.sh` or configure your editor's format-on-save, install the same +version so you don't fight the pinned one: + +``` +pip install clang-format==18.1.8 +``` + +To format everything by hand (e.g. after pulling changes), run `ci/format-all.sh`, +or `ci/format-all.sh --check` to only check without modifying files. + +clang-format expands every element of a braced initializer list onto its own +line whenever the list already ends with a trailing comma, regardless of +column limit -- so the same struct/array literal formats differently +depending on whether its last author happened to add one. `ci/strip-trailing-commas.py` +removes any comma directly before a closing `}` before clang-format ever runs, +so don't rely on a trailing comma to keep an initializer list multi-line; that's +clang-format's call once the comma's gone. This runs automatically as part of +the same pre-commit hook and CI check as clang-format (and as part of +`ci/format-all.sh`), so you shouldn't need to run it by hand. + +Since the repo's history includes a single large reformatting commit, run: + +``` +git config blame.ignoreRevsFile .git-blame-ignore-revs +``` + +so `git blame` attributes lines to their original author instead of that commit. diff --git a/ci/format-all.sh b/ci/format-all.sh new file mode 100755 index 0000000000..10af9778a0 --- /dev/null +++ b/ci/format-all.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# Run trailing-comma stripping and clang-format over every in-scope C/C++/CUDA +# file in the repo, in that order (a trailing comma before a closing '}' +# makes clang-format expand the whole list onto one line per element, so it +# has to be gone before clang-format sees the file). +# +# In scope: tracked *.c/*.h/*.cpp/*.hpp/*.cu/*.cuh files, excluding anything +# under a */ker/* directory (auto-generated DG kernel code) or under +# core/minus/ (vendored third-party libraries) -- see +# .agents/skills/code_style/SKILL.md. +# +# Usage: +# ci/format-all.sh # reformat all in-scope files in place +# ci/format-all.sh --check # fail (exit 1) if any in-scope file is not formatted +set -euo pipefail + +PINNED_VERSION="18.1.8" # keep in sync with the `rev:` in .pre-commit-config.yaml + +repo_root=$(git -C "$(dirname "${BASH_SOURCE[0]}")" rev-parse --show-toplevel) +cd "$repo_root" + +mode=${1:-} + +version=$(clang-format --version | grep -o '[0-9][0-9.]*' | head -1) +if [[ "$version" != "$PINNED_VERSION" ]]; then + echo "warning: clang-format $version is on PATH, but pre-commit/CI enforce $PINNED_VERSION." >&2 + echo " results may not exactly match the CI check. See README.md." >&2 +fi + +list_files() { + git ls-files -z -- '*.c' '*.h' '*.cpp' '*.hpp' '*.cu' '*.cuh' \ + | grep -zv '/ker/' \ + | grep -zv '^core/minus/' +} + +if [[ "$mode" == "--check" ]]; then + status=0 + while IFS= read -r -d '' f; do + if ! python3 ci/strip-trailing-commas.py --check "$f" > /dev/null 2>&1; then + echo "trailing comma(s) found: $f" + status=1 + fi + if ! clang-format --dry-run --Werror "$f" > /dev/null 2>&1; then + echo "not formatted: $f" + status=1 + fi + done < <(list_files) + exit "$status" +else + count=0 + while IFS= read -r -d '' f; do + python3 ci/strip-trailing-commas.py "$f" + clang-format -i "$f" + count=$((count + 1)) + done < <(list_files) + echo "Formatted $count files." +fi diff --git a/ci/strip-trailing-commas.py b/ci/strip-trailing-commas.py new file mode 100755 index 0000000000..00a389708e --- /dev/null +++ b/ci/strip-trailing-commas.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +"""Strip trailing commas immediately before a closing '}' in C/C++/CUDA source. + +clang-format expands every element of a braced initializer list onto its own +line whenever the list already ends with a trailing comma, regardless of +column limit. Since some authors habitually add one and others don't, the +same kind of initializer formats inconsistently depending on who last edited +it. This script removes the comma before it ever reaches clang-format, so +formatting stays deterministic. + +Usage: + strip-trailing-commas.py FILE... # rewrite files in place + strip-trailing-commas.py --check FILE... # report only; exit 1 if any file would change +""" +import re +import sys + +# Matches an (optional) encoding prefix + R"delim(...)delim" raw string literal. +# The delimiter is captured and reused via a backreference so the literal's +# body -- which may itself contain quotes, braces, or comment-like sequences +# -- is never misread as comment/string/brace syntax. +_RAW_STRING_RE = re.compile( + r'(?:u8|u|U|L)?R"([^\s"\\()]{0,16})\((?:(?!\)\1").)*\)\1"', re.DOTALL +) + +_TRAILING_COMMA_RE = re.compile(r",\s*\}") + + +def _blank(out, start, end, filler): + for k in range(start, end): + if out[k] != "\n": + out[k] = filler + + +def _mask(text): + """Return a same-length copy of text safe to run the trailing-comma regex on. + + Comment contents are blanked to spaces, since a comment between a comma + and a '}' is trivia -- \\s* should swallow it. String/char/raw-string + literal contents are blanked to 'x' instead: they're real code (e.g. an + array element that happens to be a string literal), so they must NOT + look like whitespace, or a comma several elements back could wrongly + appear to be immediately followed by '}'. Delimiters and newlines are + preserved either way so offsets line up with the original text. + """ + out = list(text) + i = 0 + n = len(text) + while i < n: + two = text[i : i + 2] + if two == "//": + j = text.find("\n", i) + end = n if j == -1 else j + _blank(out, i, end, " ") + i = end + elif two == "/*": + end = text.find("*/", i + 2) + end = n if end == -1 else end + 2 + _blank(out, i, end, " ") + i = end + elif text[i] in "'\"": + quote = text[i] + j = i + 1 + while j < n and text[j] != quote: + if text[j] == "\\": + j += 1 + j += 1 + end = min(j + 1, n) + _blank(out, i, end, "x") + i = end + elif text[i] in "uUL8R" and _RAW_STRING_RE.match(text, i): + end = _RAW_STRING_RE.match(text, i).end() + _blank(out, i, end, "x") + i = end + else: + i += 1 + return "".join(out) + + +def strip_trailing_commas(text): + masked = _mask(text) + comma_offsets = [m.start() for m in _TRAILING_COMMA_RE.finditer(masked)] + if not comma_offsets: + return text + chars = list(text) + for offset in reversed(comma_offsets): + del chars[offset] + return "".join(chars) + + +def main(argv): + check = "--check" in argv + files = [a for a in argv if a != "--check"] + changed = [] + for path in files: + with open(path, "r") as f: + original = f.read() + updated = strip_trailing_commas(original) + if updated != original: + changed.append(path) + if not check: + with open(path, "w") as f: + f.write(updated) + if check: + for path in changed: + print(f"trailing comma(s) found: {path}") + return 1 if changed else 0 + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/core/apps/app_priv.c b/core/apps/app_priv.c index 5755b6a312..a6f27725e7 100644 --- a/core/apps/app_priv.c +++ b/core/apps/app_priv.c @@ -1,3 +1,2 @@ #include #include - diff --git a/core/apps/gkyl_app.h b/core/apps/gkyl_app.h index 9fb0c36385..91404fffc4 100644 --- a/core/apps/gkyl_app.h +++ b/core/apps/gkyl_app.h @@ -26,7 +26,7 @@ struct gkyl_app_comm_low_inp { // BC for blocks struct gkyl_block_physical_bcs { int bidx; // block index - int dir; // direction in which BC is specified + int dir; // direction in which BC is specified enum gkyl_edge_loc edge; // which edge this BC is for int bc_type; // BC code }; @@ -50,7 +50,7 @@ enum gkyl_species_bc_type { GKYL_SPECIES_FIXED_FUNC, // Fixed function, time-independent, boundary conditions GKYL_SPECIES_EMISSION, // Emission spectrum BCs GKYL_SPECIES_ZERO_FLUX, // Zero flux BCs; must be applied on both lower and upper BC - GKYL_SPECIES_RECYCLE, // Recycling BCs + GKYL_SPECIES_RECYCLE // Recycling BCs }; // Boundary conditions on fields @@ -64,12 +64,12 @@ enum gkyl_field_bc_type { GKYL_FIELD_FUNC, // Function boundary conditions GKYL_FIELD_DIRICHLET, // Dirichlet boundary conditions GKYL_FIELD_NEUMANN, // Nemann boundary conditions - GKYL_FIELD_NONE, // Do not apply any boundary conditions + GKYL_FIELD_NONE // Do not apply any boundary conditions }; // Type of file import for initial conditions enum gkyl_ic_import_type { GKYL_IC_IMPORT_NONE = 0, GKYL_IC_IMPORT_F, // Import f only. - GKYL_IC_IMPORT_AF, // Import f and scale by alpha(x). + GKYL_IC_IMPORT_AF // Import f and scale by alpha(x). }; diff --git a/core/apps/gkyl_app_priv.h b/core/apps/gkyl_app_priv.h index 2b3acbfcc4..466b95d540 100644 --- a/core/apps/gkyl_app_priv.h +++ b/core/apps/gkyl_app_priv.h @@ -19,48 +19,50 @@ struct app_skin_ghost_ranges { }; // allocate double array (filled with zeros) -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } // allocate integer array (filled with zeros) -static struct gkyl_array* -mk_int_arr(bool on_gpu, long nc, long size) +static struct gkyl_array *mk_int_arr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_INT, nc, size); - else + } else { a = gkyl_array_new(GKYL_INT, nc, size); + } return a; } // Compute out = c1*arr1 + c2*arr2 -static inline struct gkyl_array* -array_combine(struct gkyl_array *out, double c1, const struct gkyl_array *arr1, - double c2, const struct gkyl_array *arr2, const struct gkyl_range *rng) +static inline struct gkyl_array *array_combine( + struct gkyl_array *out, double c1, const struct gkyl_array *arr1, double c2, + const struct gkyl_array *arr2, const struct gkyl_range *rng +) { - return gkyl_array_accumulate_range(gkyl_array_set_range(out, c1, arr1, rng), - c2, arr2, rng); + return gkyl_array_accumulate_range(gkyl_array_set_range(out, c1, arr1, rng), c2, arr2, rng); } // Create ghost and skin sub-ranges given a parent range -static void -skin_ghost_ranges_init(struct app_skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_init( + struct app_skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { int ndim = parent->ndim; - - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } diff --git a/core/apps/gkyl_lw_priv.h b/core/apps/gkyl_lw_priv.h index 2a79f05255..9fa7b47d02 100644 --- a/core/apps/gkyl_lw_priv.h +++ b/core/apps/gkyl_lw_priv.h @@ -13,32 +13,33 @@ #include // Get basis type from string -static enum gkyl_basis_type -get_basis_type(const char *bnm) +static enum gkyl_basis_type get_basis_type(const char *bnm) { - if (strcmp(bnm, "serendipity") == 0) + if (strcmp(bnm, "serendipity") == 0) { return GKYL_BASIS_MODAL_SERENDIPITY; - if (strcmp(bnm, "tensor") == 0) + } + if (strcmp(bnm, "tensor") == 0) { return GKYL_BASIS_MODAL_TENSOR; - if (strcmp(bnm, "hybrid") == 0) + } + if (strcmp(bnm, "hybrid") == 0) { return GKYL_BASIS_MODAL_HYBRID; + } return GKYL_BASIS_MODAL_SERENDIPITY; } -static void -register_types(lua_State *L, const struct gkyl_str_int_pair types[], const char *nm) +static void register_types(lua_State *L, const struct gkyl_str_int_pair types[], const char *nm) { lua_getglobal(L, "G0"); // push in a table inside global G0 table lua_pushstring(L, nm); - + lua_newtable(L); - for (int i=0; types[i].str != 0; ++i) { + for (int i = 0; types[i].str != 0; ++i) { lua_pushstring(L, types[i].str); lua_pushinteger(L, types[i].val); lua_rawset(L, -3); } - + lua_rawset(L, -3); } @@ -54,29 +55,27 @@ struct lua_func_ctx { * * @param L Lua state to use. */ -void -gkyl_register_distribution_moment_types(lua_State *L); +void gkyl_register_distribution_moment_types(lua_State *L); /** * Add boundary condition flags for species into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_species_bc_types(lua_State *L); +void gkyl_register_species_bc_types(lua_State *L); /** * Add boundary condition flags for field into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_field_bc_types(lua_State *L); +void gkyl_register_field_bc_types(lua_State *L); /** * Wrapper around Lua function for use in eval callbacks. */ -void -gkyl_lw_eval_cb(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx); +void gkyl_lw_eval_cb( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +); #endif diff --git a/core/apps/gkyl_zero_lw.h b/core/apps/gkyl_zero_lw.h index 3fcac84457..f1177de60f 100644 --- a/core/apps/gkyl_zero_lw.h +++ b/core/apps/gkyl_zero_lw.h @@ -25,7 +25,7 @@ struct gkyl_tool_args *gkyl_tool_args_new(lua_State *L); * * @param args Argument struct to free */ -void gkyl_tool_args_release(struct gkyl_tool_args* args); +void gkyl_tool_args_release(struct gkyl_tool_args *args); /** * Load the zero-level Lua interface into the Lua interpreter. diff --git a/core/apps/lw_priv.c b/core/apps/lw_priv.c index e54533acfe..5813d0c877 100644 --- a/core/apps/lw_priv.c +++ b/core/apps/lw_priv.c @@ -6,77 +6,69 @@ // Define options for moments of a distribution function. static const struct gkyl_str_int_pair distribution_moms[] = { - { "M0", GKYL_F_MOMENT_M0 }, // Number density. - { "M1", GKYL_F_MOMENT_M1 }, // Momentum density. - { "M2", GKYL_F_MOMENT_M2 }, // Kinetic energy density. - { "M2par", GKYL_F_MOMENT_M2PAR }, // Parallel kinetic energy density. - { "M2perp", GKYL_F_MOMENT_M2PERP }, // Perpendicular kinetic energy density. - { "M2ij", GKYL_F_MOMENT_M2IJ }, // Kinetic energy tensor.. - { "M3", GKYL_F_MOMENT_M3 }, // Heat flux. - { "M3par", GKYL_F_MOMENT_M3PAR }, // Parallel energy flux. - { "M3perp", GKYL_F_MOMENT_M3PERP }, // Perpendicular energy flux. - { "M3ijk", GKYL_F_MOMENT_M3IJK }, // Heat flux in lab frame. - { "MaxwellianMoments", GKYL_F_MOMENT_MAXWELLIAN }, // M0, drift speed, T/m. - { "BiMaxwellianMoments",GKYL_F_MOMENT_BIMAXWELLIAN }, // M0, drift speed, Tpar/m, Tperp/m. - { "LTEMoments", GKYL_F_MOMENT_LTE }, // Maxwellian or Maxwell-Juttner moments. - { "M0M1M2", GKYL_F_MOMENT_M0M1M2 }, // M0, M1, M2. - { "M0M1M2parM2perp", GKYL_F_MOMENT_M0M1M2PARM2PERP }, // M0, M1, M2par, M2perp. - { "HamiltonianMoments", GKYL_F_MOMENT_HAMILTONIAN }, // M0, mass*M1, H moments. - { "M1_from_H", GKYL_F_MOMENT_M1_FROM_H }, // dH/dv / m moment. - { "EnergyMoment", GKYL_F_MOMENT_ENERGY }, // H moment. - { "M0EnergyM3", GKYL_F_MOMENT_M0ENERGYM3 }, // M0, Energy (H) and M3 moments. - { "Ni", GKYL_F_MOMENT_NI }, // M0, M1i for-vector. - { "Tij", GKYL_F_MOMENT_TIJ }, // Stress-energy tensor. - { 0, 0 } + {"M0", GKYL_F_MOMENT_M0}, // Number density. + {"M1", GKYL_F_MOMENT_M1}, // Momentum density. + {"M2", GKYL_F_MOMENT_M2}, // Kinetic energy density. + {"M2par", GKYL_F_MOMENT_M2PAR}, // Parallel kinetic energy density. + {"M2perp", GKYL_F_MOMENT_M2PERP}, // Perpendicular kinetic energy density. + {"M2ij", GKYL_F_MOMENT_M2IJ}, // Kinetic energy tensor.. + {"M3", GKYL_F_MOMENT_M3}, // Heat flux. + {"M3par", GKYL_F_MOMENT_M3PAR}, // Parallel energy flux. + {"M3perp", GKYL_F_MOMENT_M3PERP}, // Perpendicular energy flux. + {"M3ijk", GKYL_F_MOMENT_M3IJK}, // Heat flux in lab frame. + {"MaxwellianMoments", GKYL_F_MOMENT_MAXWELLIAN}, // M0, drift speed, T/m. + {"BiMaxwellianMoments", GKYL_F_MOMENT_BIMAXWELLIAN}, // M0, drift speed, Tpar/m, Tperp/m. + {"LTEMoments", GKYL_F_MOMENT_LTE}, // Maxwellian or Maxwell-Juttner moments. + {"M0M1M2", GKYL_F_MOMENT_M0M1M2}, // M0, M1, M2. + {"M0M1M2parM2perp", GKYL_F_MOMENT_M0M1M2PARM2PERP}, // M0, M1, M2par, M2perp. + {"HamiltonianMoments", GKYL_F_MOMENT_HAMILTONIAN}, // M0, mass*M1, H moments. + {"M1_from_H", GKYL_F_MOMENT_M1_FROM_H}, // dH/dv / m moment. + {"EnergyMoment", GKYL_F_MOMENT_ENERGY}, // H moment. + {"M0EnergyM3", GKYL_F_MOMENT_M0ENERGYM3}, // M0, Energy (H) and M3 moments. + {"Ni", GKYL_F_MOMENT_NI}, // M0, M1i for-vector. + {"Tij", GKYL_F_MOMENT_TIJ}, // Stress-energy tensor. + {0, 0} }; // Species boundary conditions -> enum map. static const struct gkyl_str_int_pair species_bcs[] = { - { "bcCopy", GKYL_SPECIES_COPY }, - { "bcWall", GKYL_SPECIES_REFLECT }, - { "bcReflect", GKYL_SPECIES_REFLECT }, - { "bcAbsorb", GKYL_SPECIES_ABSORB }, - { "bcNoSlip", GKYL_SPECIES_NO_SLIP }, - { "bcWedge", GKYL_SPECIES_WEDGE }, - { "bcFunc", GKYL_SPECIES_FUNC }, - { "bcFixedFunc", GKYL_SPECIES_FIXED_FUNC }, - { "bcZeroFlux", GKYL_SPECIES_ZERO_FLUX }, - { "bcRecycle", GKYL_SPECIES_RECYCLE }, - { 0, 0 } + {"bcCopy", GKYL_SPECIES_COPY}, + {"bcWall", GKYL_SPECIES_REFLECT}, + {"bcReflect", GKYL_SPECIES_REFLECT}, + {"bcAbsorb", GKYL_SPECIES_ABSORB}, + {"bcNoSlip", GKYL_SPECIES_NO_SLIP}, + {"bcWedge", GKYL_SPECIES_WEDGE}, + {"bcFunc", GKYL_SPECIES_FUNC}, + {"bcFixedFunc", GKYL_SPECIES_FIXED_FUNC}, + {"bcZeroFlux", GKYL_SPECIES_ZERO_FLUX}, + {"bcRecycle", GKYL_SPECIES_RECYCLE}, + {0, 0} }; // Field boundary conditions -> enum map. static const struct gkyl_str_int_pair field_bcs[] = { - { "bcCopy", GKYL_FIELD_COPY }, - { "bcWall", GKYL_FIELD_PEC_WALL }, - { "bcPECWall", GKYL_FIELD_PEC_WALL }, - { "bcSymWall", GKYL_FIELD_SYM_WALL }, - { "bcReservoir", GKYL_FIELD_RESERVOIR }, - { "bcWedge", GKYL_FIELD_WEDGE }, - { "bcFunc", GKYL_FIELD_FUNC }, - { 0, 0 } + {"bcCopy", GKYL_FIELD_COPY}, {"bcWall", GKYL_FIELD_PEC_WALL}, + {"bcPECWall", GKYL_FIELD_PEC_WALL}, {"bcSymWall", GKYL_FIELD_SYM_WALL}, + {"bcReservoir", GKYL_FIELD_RESERVOIR}, {"bcWedge", GKYL_FIELD_WEDGE}, + {"bcFunc", GKYL_FIELD_FUNC}, {0, 0} }; -void -gkyl_register_distribution_moment_types(lua_State *L) +void gkyl_register_distribution_moment_types(lua_State *L) { register_types(L, distribution_moms, "Moment"); } -void -gkyl_register_species_bc_types(lua_State *L) +void gkyl_register_species_bc_types(lua_State *L) { register_types(L, species_bcs, "SpeciesBc"); } -void -gkyl_register_field_bc_types(lua_State *L) +void gkyl_register_field_bc_types(lua_State *L) { register_types(L, field_bcs, "FieldBc"); } -void -gkyl_lw_eval_cb(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void gkyl_lw_eval_cb(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lua_func_ctx *fr = ctx; lua_State *L = fr->L; @@ -87,20 +79,20 @@ gkyl_lw_eval_cb(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT lua_pushnumber(L, t); lua_createtable(L, GKYL_MAX_DIM, 0); - for (int i=0; i=0; --i) { // need to fetch in reverse order + for (int i = nret - 1; i >= 0; --i) { // need to fetch in reverse order fout[i] = lua_tonumber(L, -1); lua_pop(L, 1); - } + } } #endif diff --git a/core/apps/zero_lw.c b/core/apps/zero_lw.c index 039e82e928..68ac70c481 100644 --- a/core/apps/zero_lw.c +++ b/core/apps/zero_lw.c @@ -21,22 +21,22 @@ #include -struct gkyl_tool_args * -gkyl_tool_args_new(lua_State *L) +struct gkyl_tool_args *gkyl_tool_args_new(lua_State *L) { struct gkyl_tool_args *args = gkyl_malloc(sizeof(*args)); - with_lua_global(L, "GKYL_COMMANDS") { + with_lua_global(L, "GKYL_COMMANDS") + { args->argc = glua_objlen(L); args->argv = 0; if (args->argc > 0) { - args->argv = gkyl_malloc(args->argc*sizeof(char*)); - - for (int i = 1; i <= glua_objlen(L); ++i) { + args->argv = gkyl_malloc(args->argc * sizeof(char *)); + + for (int i = 1; i <= glua_objlen(L); ++i) { const char *av = glua_tbl_iget_string(L, i, "x"); - args->argv[i-1] = gkyl_malloc(1+strlen(av)); - strcpy(args->argv[i-1], av); + args->argv[i - 1] = gkyl_malloc(1 + strlen(av)); + strcpy(args->argv[i - 1], av); } } } @@ -44,11 +44,11 @@ gkyl_tool_args_new(lua_State *L) return args; } -void -gkyl_tool_args_release(struct gkyl_tool_args* args) +void gkyl_tool_args_release(struct gkyl_tool_args *args) { - for (int i=0; iargc; ++i) + for (int i = 0; i < args->argc; ++i) { gkyl_free(args->argv[i]); + } gkyl_free(args->argv); gkyl_free(args); } @@ -66,64 +66,60 @@ struct rect_decomp_lw { }; // G0.RectDecomp.new { cells = { 100, 100}, cuts = { 2, 2 } } -static int -rect_decomp_lw_new(lua_State *L) +static int rect_decomp_lw_new(lua_State *L) { struct rect_decomp_lw *rd_lw = gkyl_malloc(sizeof(*rd_lw)); - + int ndim = 1; - int cells[GKYL_MAX_DIM] = { 0 }, cuts[GKYL_MAX_DIM] = { 1 }; - - with_lua_tbl_tbl(L, "cells") { + int cells[GKYL_MAX_DIM] = {0}, cuts[GKYL_MAX_DIM] = {1}; + + with_lua_tbl_tbl(L, "cells") + { ndim = glua_objlen(L); - for (int d=0; ddecomp = gkyl_rect_decomp_new_from_cuts_and_cells(ndim, cuts, cells); - + // create Lua userdata ... - struct rect_decomp_lw **l_rd_lw = lua_newuserdata(L, sizeof(struct rect_decomp_lw*)); + struct rect_decomp_lw **l_rd_lw = lua_newuserdata(L, sizeof(struct rect_decomp_lw *)); *l_rd_lw = rd_lw; // ... point it to the rect decomp pointer // set metatable luaL_getmetatable(L, RECT_DECOMP_METATABLE_NM); - lua_setmetatable(L, -2); - + lua_setmetatable(L, -2); + return 1; } // Clean up memory allocated for decomp -static int -rect_decomp_lw_gc(lua_State *L) +static int rect_decomp_lw_gc(lua_State *L) { struct rect_decomp_lw **l_rd_lw = GKYL_CHECK_UDATA(L, RECT_DECOMP_METATABLE_NM); struct rect_decomp_lw *rd_lw = *l_rd_lw; gkyl_rect_decomp_release(rd_lw->decomp); gkyl_free(*l_rd_lw); - + return 0; } // rect_decomp constructor -static struct luaL_Reg rect_decomp_ctor[] = { - { "new", rect_decomp_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg rect_decomp_ctor[] = {{"new", rect_decomp_lw_new}, {0, 0}}; // rect_decomp methods -static struct luaL_Reg rect_decomp_funcs[] = { - {0, 0} -}; +static struct luaL_Reg rect_decomp_funcs[] = {{0, 0}}; -static void -rect_decomp_openlibs(lua_State *L) +static void rect_decomp_openlibs(lua_State *L) { do { luaL_newmetatable(L, RECT_DECOMP_METATABLE_NM); @@ -135,9 +131,9 @@ rect_decomp_openlibs(lua_State *L) lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_register(L, NULL, rect_decomp_funcs); - + luaL_register(L, "G0.Zero.RectDecomp", rect_decomp_ctor); - + } while (0); } @@ -153,20 +149,16 @@ struct rect_grid_lw { struct gkyl_rect_grid grid; }; -static int -rect_grid_lw_gc(lua_State *L) +static int rect_grid_lw_gc(lua_State *L) { struct rect_grid_lw **l_g = GKYL_CHECK_UDATA(L, RECT_GRID_METATABLE_NM); gkyl_free(*l_g); return 0; } -static struct luaL_Reg rect_grid_funcs[] = { - { 0, 0 } -}; +static struct luaL_Reg rect_grid_funcs[] = {{0, 0}}; -static void -rect_grid_openlibs(lua_State *L) +static void rect_grid_openlibs(lua_State *L) { luaL_newmetatable(L, RECT_GRID_METATABLE_NM); @@ -189,8 +181,7 @@ struct array_lw { struct gkyl_array *arr; }; -static int -array_lw_gc(lua_State *L) +static int array_lw_gc(lua_State *L) { struct array_lw **l_a = GKYL_CHECK_UDATA(L, ARRAY_METATABLE_NM); gkyl_array_release((*l_a)->arr); @@ -198,12 +189,9 @@ array_lw_gc(lua_State *L) return 0; } -static struct luaL_Reg array_funcs[] = { - { 0, 0 } -}; +static struct luaL_Reg array_funcs[] = {{0, 0}}; -static void -array_openlibs(lua_State *L) +static void array_openlibs(lua_State *L) { luaL_newmetatable(L, ARRAY_METATABLE_NM); @@ -226,20 +214,16 @@ struct range_lw { struct gkyl_range range; }; -static int -range_lw_gc(lua_State *L) +static int range_lw_gc(lua_State *L) { struct range_lw **l_r = GKYL_CHECK_UDATA(L, RANGE_METATABLE_NM); gkyl_free(*l_r); return 0; } -static struct luaL_Reg range_funcs[] = { - { 0, 0 } -}; +static struct luaL_Reg range_funcs[] = {{0, 0}}; -static void -range_openlibs(lua_State *L) +static void range_openlibs(lua_State *L) { luaL_newmetatable(L, RANGE_METATABLE_NM); @@ -255,8 +239,7 @@ range_openlibs(lua_State *L) } /* -- Helper: push a rect_grid_lw onto the Lua stack -- */ -static void -push_rect_grid(lua_State *L, const struct gkyl_rect_grid *grid) +static void push_rect_grid(lua_State *L, const struct gkyl_rect_grid *grid) { struct rect_grid_lw *g_lw = gkyl_malloc(sizeof(*g_lw)); g_lw->grid = *grid; @@ -268,8 +251,7 @@ push_rect_grid(lua_State *L, const struct gkyl_rect_grid *grid) } /* -- Helper: push a range_lw onto the Lua stack -- */ -static void -push_range(lua_State *L, const struct gkyl_range *range) +static void push_range(lua_State *L, const struct gkyl_range *range) { struct range_lw *r_lw = gkyl_malloc(sizeof(*r_lw)); r_lw->range = *range; @@ -283,8 +265,7 @@ push_range(lua_State *L, const struct gkyl_range *range) /* -- G0.Zero.gkylFileType(fname) -> string -- */ // Returns one of: "field", "dynvector", "multi-range-field", // "block-topology", "multi-block-meta", or "not-gkyl". -static int -gkyl_file_type_lw(lua_State *L) +static int gkyl_file_type_lw(lua_State *L) { const char *fname = luaL_checkstring(L, 1); int ftype = gkyl_get_gkyl_file_type(fname); @@ -294,26 +275,26 @@ gkyl_file_type_lw(lua_State *L) // 4 = block-topology, 5 = multi-block-meta // names[] is indexed directly by ftype so names[0] is a placeholder. static const char *names[] = { - NULL, // [0] — not a valid file type - "field", // [1] — GKYL_FIELD_DATA_FILE - "dynvector", // [2] — GKYL_DYNVEC_DATA_FILE + NULL, // [0] — not a valid file type + "field", // [1] — GKYL_FIELD_DATA_FILE + "dynvector", // [2] — GKYL_DYNVEC_DATA_FILE "multi-range-field", // [3] — GKYL_MULTI_RANGE_DATA_FILE - "block-topology", // [4] — GKYL_BLOCK_TOPO_DATA_FILE - "multi-block-meta" // [5] — GKYL_MULTI_BLOCK_DATA_FILE + "block-topology", // [4] — GKYL_BLOCK_TOPO_DATA_FILE + "multi-block-meta" // [5] — GKYL_MULTI_BLOCK_DATA_FILE }; int nnames = (int)(sizeof(names) / sizeof(names[0])); - if (ftype <= 0 || ftype >= nnames || names[ftype] == NULL) + if (ftype <= 0 || ftype >= nnames || names[ftype] == NULL) { lua_pushstring(L, "not-gkyl"); - else + } else { lua_pushstring(L, names[ftype]); + } return 1; } /* -- G0.Zero.arrayNewFromFile(fname) -> grid_ud, array_ud (or nil, nil on failure) -- */ -static int -array_new_from_file_lw(lua_State *L) +static int array_new_from_file_lw(lua_State *L) { const char *fname = luaL_checkstring(L, 1); @@ -343,8 +324,7 @@ array_new_from_file_lw(lua_State *L) } /* -- G0.Zero.rectGridCmp(g1, g2) -> bool -- */ -static int -rect_grid_cmp_lw(lua_State *L) +static int rect_grid_cmp_lw(lua_State *L) { struct rect_grid_lw **l_g1 = luaL_checkudata(L, 1, RECT_GRID_METATABLE_NM); struct rect_grid_lw **l_g2 = luaL_checkudata(L, 2, RECT_GRID_METATABLE_NM); @@ -353,16 +333,15 @@ rect_grid_cmp_lw(lua_State *L) } /* -- G0.Zero.createGridRanges(grid_ud, nghost_table) -> range_ud, ext_range_ud -- */ -static int -create_grid_ranges_lw(lua_State *L) +static int create_grid_ranges_lw(lua_State *L) { struct rect_grid_lw **l_g = luaL_checkudata(L, 1, RECT_GRID_METATABLE_NM); luaL_checktype(L, 2, LUA_TTABLE); int ndim = (*l_g)->grid.ndim; - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; for (int d = 0; d < ndim; ++d) { - lua_rawgeti(L, 2, d+1); + lua_rawgeti(L, 2, d + 1); nghost[d] = (int)lua_tointeger(L, -1); lua_pop(L, 1); } @@ -379,15 +358,13 @@ create_grid_ranges_lw(lua_State *L) /* -- G0.Zero.arrayDiff(a1_ud, a2_ud, range_ud) -> table -- */ // Returned table has fields: is_compatible, max_abs_diff, min_abs_diff, // max_rel_diff, min_rel_diff. -static int -array_diff_lw(lua_State *L) +static int array_diff_lw(lua_State *L) { struct array_lw **l_a1 = luaL_checkudata(L, 1, ARRAY_METATABLE_NM); struct array_lw **l_a2 = luaL_checkudata(L, 2, ARRAY_METATABLE_NM); - struct range_lw **l_r = luaL_checkudata(L, 3, RANGE_METATABLE_NM); + struct range_lw **l_r = luaL_checkudata(L, 3, RANGE_METATABLE_NM); - struct gkyl_array_diff diff = gkyl_array_diff( - (*l_a1)->arr, (*l_a2)->arr, &(*l_r)->range); + struct gkyl_array_diff diff = gkyl_array_diff((*l_a1)->arr, (*l_a2)->arr, &(*l_r)->range); lua_newtable(L); @@ -411,17 +388,23 @@ array_diff_lw(lua_State *L) // Returns a Lua table with all diff fields set to zero and is_compatible=false. // Used as the early-exit return value whenever two dynvec files cannot be compared. -static int -dynvec_incompat(lua_State *L) +static int dynvec_incompat(lua_State *L) { lua_newtable(L); - lua_pushboolean(L, 0); lua_setfield(L, -2, "is_compatible"); - lua_pushnumber(L, 0); lua_setfield(L, -2, "max_abs_diff"); - lua_pushnumber(L, 0); lua_setfield(L, -2, "min_abs_diff"); - lua_pushnumber(L, 0); lua_setfield(L, -2, "max_rel_diff"); - lua_pushnumber(L, 0); lua_setfield(L, -2, "min_rel_diff"); - lua_pushnumber(L, 0); lua_setfield(L, -2, "tm_max_abs_diff"); - lua_pushnumber(L, 0); lua_setfield(L, -2, "tm_min_abs_diff"); + lua_pushboolean(L, 0); + lua_setfield(L, -2, "is_compatible"); + lua_pushnumber(L, 0); + lua_setfield(L, -2, "max_abs_diff"); + lua_pushnumber(L, 0); + lua_setfield(L, -2, "min_abs_diff"); + lua_pushnumber(L, 0); + lua_setfield(L, -2, "max_rel_diff"); + lua_pushnumber(L, 0); + lua_setfield(L, -2, "min_rel_diff"); + lua_pushnumber(L, 0); + lua_setfield(L, -2, "tm_max_abs_diff"); + lua_pushnumber(L, 0); + lua_setfield(L, -2, "tm_min_abs_diff"); return 1; } @@ -431,8 +414,7 @@ dynvec_incompat(lua_State *L) // fields (tm_max_abs_diff, tm_min_abs_diff). Timestamp differences are // computed but do not affect is_compatible: accumulated floating-point // drift in t += dt is expected and platform-dependent. -static int -dynvec_diff_lw(lua_State *L) +static int dynvec_diff_lw(lua_State *L) { const char *f1 = luaL_checkstring(L, 1); const char *f2 = luaL_checkstring(L, 2); @@ -442,13 +424,19 @@ dynvec_diff_lw(lua_State *L) struct gkyl_dynvec_etype_ncomp enc2 = gkyl_dynvec_read_ncomp(f2); // ncomp == 0 means the file couldn't be read or has an invalid header. - if (enc1.ncomp == 0 || enc2.ncomp == 0) return dynvec_incompat(L); + if (enc1.ncomp == 0 || enc2.ncomp == 0) { + return dynvec_incompat(L); + } // gkyl_array_diff only handles GKYL_DOUBLE safely. - if (enc1.type != GKYL_DOUBLE || enc2.type != GKYL_DOUBLE) return dynvec_incompat(L); + if (enc1.type != GKYL_DOUBLE || enc2.type != GKYL_DOUBLE) { + return dynvec_incompat(L); + } // Number of components must match. - if (enc1.ncomp != enc2.ncomp) return dynvec_incompat(L); + if (enc1.ncomp != enc2.ncomp) { + return dynvec_incompat(L); + } // Read full dynvecs. gkyl_dynvec dv1 = gkyl_dynvec_new(enc1.type, enc1.ncomp); @@ -483,19 +471,26 @@ dynvec_diff_lw(lua_State *L) gkyl_dynvec_release(dv1); gkyl_dynvec_release(dv2); lua_newtable(L); - lua_pushboolean(L, 1); lua_setfield(L, -2, "is_compatible"); - lua_pushnumber(L, 0.0); lua_setfield(L, -2, "max_abs_diff"); - lua_pushnumber(L, 0.0); lua_setfield(L, -2, "min_abs_diff"); - lua_pushnumber(L, 0.0); lua_setfield(L, -2, "max_rel_diff"); - lua_pushnumber(L, 0.0); lua_setfield(L, -2, "min_rel_diff"); - lua_pushnumber(L, 0.0); lua_setfield(L, -2, "tm_max_abs_diff"); - lua_pushnumber(L, 0.0); lua_setfield(L, -2, "tm_min_abs_diff"); + lua_pushboolean(L, 1); + lua_setfield(L, -2, "is_compatible"); + lua_pushnumber(L, 0.0); + lua_setfield(L, -2, "max_abs_diff"); + lua_pushnumber(L, 0.0); + lua_setfield(L, -2, "min_abs_diff"); + lua_pushnumber(L, 0.0); + lua_setfield(L, -2, "max_rel_diff"); + lua_pushnumber(L, 0.0); + lua_setfield(L, -2, "min_rel_diff"); + lua_pushnumber(L, 0.0); + lua_setfield(L, -2, "tm_max_abs_diff"); + lua_pushnumber(L, 0.0); + lua_setfield(L, -2, "tm_min_abs_diff"); return 1; } // Allocate flat arrays for timestamps (ncomp=1) and data (ncomp=enc1.ncomp). - struct gkyl_array *tm1 = gkyl_array_new(GKYL_DOUBLE, 1, nsteps); - struct gkyl_array *tm2 = gkyl_array_new(GKYL_DOUBLE, 1, nsteps); + struct gkyl_array *tm1 = gkyl_array_new(GKYL_DOUBLE, 1, nsteps); + struct gkyl_array *tm2 = gkyl_array_new(GKYL_DOUBLE, 1, nsteps); struct gkyl_array *da1 = gkyl_array_new(GKYL_DOUBLE, enc1.ncomp, nsteps); struct gkyl_array *da2 = gkyl_array_new(GKYL_DOUBLE, enc2.ncomp, nsteps); @@ -507,7 +502,7 @@ dynvec_diff_lw(lua_State *L) // Build a 1-D range [0, nsteps-1] for gkyl_array_diff. struct gkyl_range rng; - int shape[1] = { (int)nsteps }; + int shape[1] = {(int)nsteps}; gkyl_range_init_from_shape(&rng, 1, shape); struct gkyl_array_diff ddiff = gkyl_array_diff(da1, da2, &rng); @@ -550,8 +545,7 @@ dynvec_diff_lw(lua_State *L) // (same ndim, num_blocks, and all per-block connection entries), false // otherwise. Block topology contains only integer/enum data, so this // is an exact equality check rather than a numerical diff. -static int -block_topo_cmp_lw(lua_State *L) +static int block_topo_cmp_lw(lua_State *L) { const char *f1 = luaL_checkstring(L, 1); const char *f2 = luaL_checkstring(L, 2); @@ -561,8 +555,12 @@ block_topo_cmp_lw(lua_State *L) struct gkyl_block_topo *bt2 = gkyl_block_topo_read(f2, &st2); if (!bt1 || !bt2) { - if (bt1) gkyl_block_topo_release(bt1); - if (bt2) gkyl_block_topo_release(bt2); + if (bt1) { + gkyl_block_topo_release(bt1); + } + if (bt2) { + gkyl_block_topo_release(bt2); + } lua_pushboolean(L, 0); return 1; } @@ -570,15 +568,16 @@ block_topo_cmp_lw(lua_State *L) bool equal = (bt1->ndim == bt2->ndim) && (bt1->num_blocks == bt2->num_blocks); if (equal) { - int ndim = bt1->ndim; - int nblocks = bt1->num_blocks; + int ndim = bt1->ndim; + int nblocks = bt1->num_blocks; for (int b = 0; b < nblocks && equal; ++b) { for (int d = 0; d < ndim && equal; ++d) { for (int e = 0; e < 2 && equal; ++e) { struct gkyl_target_edge *c1 = &bt1->conn[b].connections[d][e]; struct gkyl_target_edge *c2 = &bt2->conn[b].connections[d][e]; - if (c1->bid != c2->bid || c1->dir != c2->dir || c1->edge != c2->edge) + if (c1->bid != c2->bid || c1->dir != c2->dir || c1->edge != c2->edge) { equal = false; + } } } } @@ -593,18 +592,13 @@ block_topo_cmp_lw(lua_State *L) // Module-level functions registered under G0.Zero static struct luaL_Reg zero_array_funcs[] = { - { "gkylFileType", gkyl_file_type_lw }, - { "arrayNewFromFile", array_new_from_file_lw }, - { "rectGridCmp", rect_grid_cmp_lw }, - { "createGridRanges", create_grid_ranges_lw }, - { "arrayDiff", array_diff_lw }, - { "dynvecDiff", dynvec_diff_lw }, - { "blockTopoCmp", block_topo_cmp_lw }, - { 0, 0 } + {"gkylFileType", gkyl_file_type_lw}, {"arrayNewFromFile", array_new_from_file_lw}, + {"rectGridCmp", rect_grid_cmp_lw}, {"createGridRanges", create_grid_ranges_lw}, + {"arrayDiff", array_diff_lw}, {"dynvecDiff", dynvec_diff_lw}, + {"blockTopoCmp", block_topo_cmp_lw}, {0, 0} }; -void -gkyl_zero_lw_openlibs(lua_State *L) +void gkyl_zero_lw_openlibs(lua_State *L) { // Push empty global table called "G0". lua_newtable(L); diff --git a/core/creg/rt_kann_bench.c b/core/creg/rt_kann_bench.c index da166ba86b..62a2981f0d 100644 --- a/core/creg/rt_kann_bench.c +++ b/core/creg/rt_kann_bench.c @@ -8,14 +8,12 @@ #include #include -static inline float -ufunc(float x) +static inline float ufunc(float x) { - return 1.0f/(1.0f+100.0f*x*x); + return 1.0f / (1.0f + 100.0f * x * x); } -static double -bench_train(int ntrain, int nwidth, int ndepth, bool use_gpu) +static double bench_train(int ntrain, int nwidth, int ndepth, bool use_gpu) { kad_node_t *t_net = kann_layer_input(1); for (int i = 0; i < ndepth; ++i) { @@ -47,11 +45,7 @@ bench_train(int ntrain, int nwidth, int ndepth, bool use_gpu) } struct gkyl_kann_train_params params = { - .learning_rate = 1e-3f, - .mini_size = 64, - .max_epoch = 50, - .max_drop_streak = 10, - .frac_val = 0.1f, + .learning_rate = 1e-3f, .mini_size = 64, .max_epoch = 50, .max_drop_streak = 10, .frac_val = 0.1f }; struct timespec t0, t1; @@ -72,9 +66,7 @@ bench_train(int ntrain, int nwidth, int ndepth, bool use_gpu) return elapsed; } -static double -bench_infer(int nvec, int nwidth, int ndepth, bool use_gpu, - const char *model_file) +static double bench_infer(int nvec, int nwidth, int ndepth, bool use_gpu, const char *model_file) { struct gkyl_kann_net *net = gkyl_kann_net_load(model_file, use_gpu); @@ -82,8 +74,9 @@ bench_infer(int nvec, int nwidth, int ndepth, bool use_gpu, struct gkyl_kn_vec *out = gkyl_kn_vec_new(nvec, 1); float dx = 2.0f / (nvec - 1); - for (int i = 0; i < nvec; ++i) + for (int i = 0; i < nvec; ++i) { inp->vals[i][0] = -1.0f + dx * i; + } struct gkyl_kn_vec *inp_t = inp, *out_t = out; struct gkyl_kn_vec *inp_cu = 0, *out_cu = 0; @@ -101,8 +94,9 @@ bench_infer(int nvec, int nwidth, int ndepth, bool use_gpu, int nreps = 100; struct timespec t0, t1; clock_gettime(CLOCK_MONOTONIC, &t0); - for (int r = 0; r < nreps; ++r) + for (int r = 0; r < nreps; ++r) { gkyl_kann_net_apply(net, inp_t, out_t); + } clock_gettime(CLOCK_MONOTONIC, &t1); double elapsed = ((t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) * 1e-9) / nreps; @@ -118,20 +112,18 @@ bench_infer(int nvec, int nwidth, int ndepth, bool use_gpu, return elapsed; } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int ntrain = 1001; int ninfer = 1001; - int widths[] = { 64, 128, 256, 512 }; - int depths[] = { 2, 4 }; + int widths[] = {64, 128, 256, 512}; + int depths[] = {2, 4}; int nw = sizeof(widths) / sizeof(widths[0]); int nd = sizeof(depths) / sizeof(depths[0]); fprintf(stdout, "=== Training Benchmark (ntrain=%d, 50 epochs, mini_size=64) ===\n", ntrain); - fprintf(stdout, "%6s %6s %10s %10s %10s\n", - "width", "depth", "CPU (s)", "GPU (s)", "speedup"); + fprintf(stdout, "%6s %6s %10s %10s %10s\n", "width", "depth", "CPU (s)", "GPU (s)", "speedup"); for (int di = 0; di < nd; ++di) { for (int wi = 0; wi < nw; ++wi) { @@ -140,14 +132,12 @@ main(int argc, char *argv[]) double t_cpu = bench_train(ntrain, w, d, false); double t_gpu = bench_train(ntrain, w, d, true); - fprintf(stdout, "%6d %6d %10.4f %10.4f %10.2fx\n", - w, d, t_cpu, t_gpu, t_cpu / t_gpu); + fprintf(stdout, "%6d %6d %10.4f %10.4f %10.2fx\n", w, d, t_cpu, t_gpu, t_cpu / t_gpu); } } fprintf(stdout, "\n=== Inference Benchmark (nvec=%d, avg of 100 reps) ===\n", ninfer); - fprintf(stdout, "%6s %6s %10s %10s %10s\n", - "width", "depth", "CPU (ms)", "GPU (ms)", "speedup"); + fprintf(stdout, "%6s %6s %10s %10s %10s\n", "width", "depth", "CPU (ms)", "GPU (ms)", "speedup"); for (int di = 0; di < nd; ++di) { for (int wi = 0; wi < nw; ++wi) { @@ -170,8 +160,11 @@ main(int argc, char *argv[]) out->vals[i][0] = ufunc(inp->vals[i][0]); } struct gkyl_kann_train_params params = { - .learning_rate = 1e-3f, .mini_size = 64, - .max_epoch = 5, .max_drop_streak = 5, .frac_val = 0.1f, + .learning_rate = 1e-3f, + .mini_size = 64, + .max_epoch = 5, + .max_drop_streak = 5, + .frac_val = 0.1f }; gkyl_kann_net_train_fnn1(net, ¶ms, inp, out); gkyl_kann_net_save(net, "bench_tmp.kann"); @@ -182,8 +175,9 @@ main(int argc, char *argv[]) double t_cpu = bench_infer(ninfer, w, d, false, "bench_tmp.kann"); double t_gpu = bench_infer(ninfer, w, d, true, "bench_tmp.kann"); - fprintf(stdout, "%6d %6d %10.4f %10.4f %10.2fx\n", - w, d, t_cpu * 1000, t_gpu * 1000, t_cpu / t_gpu); + fprintf( + stdout, "%6d %6d %10.4f %10.4f %10.2fx\n", w, d, t_cpu * 1000, t_gpu * 1000, t_cpu / t_gpu + ); } } diff --git a/core/creg/rt_kann_cmp_arch.c b/core/creg/rt_kann_cmp_arch.c index 2adfffebd5..1242f14183 100644 --- a/core/creg/rt_kann_cmp_arch.c +++ b/core/creg/rt_kann_cmp_arch.c @@ -12,24 +12,19 @@ struct xrange { int N; }; -static inline float -xrange_n(struct xrange xr, int n) +static inline float xrange_n(struct xrange xr, int n) { - float dx = (xr.xright-xr.xleft)/(xr.N-1); - return xr.xleft + dx*n; + float dx = (xr.xright - xr.xleft) / (xr.N - 1); + return xr.xleft + dx * n; } // function to fit -static inline float -ufunc(float t, float x) +static inline float ufunc(float t, float x) { - return sinf(2.0f*M_PI*x)*sinf(2.0f*t)*expf(-t); + return sinf(2.0f * M_PI * x) * sinf(2.0f * t) * expf(-t); } -enum ann_layer_type { - ANN_DENSE, - ANN_GRU -}; +enum ann_layer_type { ANN_DENSE, ANN_GRU }; struct train_inp { int ntrain[2]; @@ -39,55 +34,46 @@ struct train_inp { enum ann_layer_type layer_type; }; - -void -train_ann(struct train_inp *nn_inp, const char *nn_name) +void train_ann(struct train_inp *nn_inp, const char *nn_name) { kad_node_t *t_net; t_net = kann_layer_input(2); - for (int i=0; indepth; ++i) { - switch(nn_inp->layer_type) { - case ANN_DENSE: - t_net = kann_layer_dense(t_net, nn_inp->nwidth); - break; - case ANN_GRU: - t_net = kann_layer_gru(t_net, nn_inp->nwidth, 0); - break; + for (int i = 0; i < nn_inp->ndepth; ++i) { + switch (nn_inp->layer_type) { + case ANN_DENSE: + t_net = kann_layer_dense(t_net, nn_inp->nwidth); + break; + case ANN_GRU: + t_net = kann_layer_gru(t_net, nn_inp->nwidth, 0); + break; } t_net = kad_tanh(t_net); } - + t_net = kann_layer_cost(t_net, 1, KANN_C_MSE); kann_t *ann = kann_new(t_net, 0); // allocate memory for input/output vectors int Nt = nn_inp->ntrain[0], Nx = nn_inp->ntrain[1]; // training samples - struct gkyl_kn_vec *inp = gkyl_kn_vec_new(Nt*Nx, 2); - struct gkyl_kn_vec *out = gkyl_kn_vec_new(Nt*Nx, 1); + struct gkyl_kn_vec *inp = gkyl_kn_vec_new(Nt * Nx, 2); + struct gkyl_kn_vec *out = gkyl_kn_vec_new(Nt * Nx, 1); - struct xrange tr = { - .xleft = 0.0f, - .xright = 3.0f, - .N = Nt - }; + struct xrange tr = {.xleft = 0.0f, .xright = 3.0f, .N = Nt}; - struct xrange xr = { - .xleft = 0.0f, - .xright = 1.0f, - .N = Nx - }; + struct xrange xr = {.xleft = 0.0f, .xright = 1.0f, .N = Nx}; // initialize input/output mapping - for (int i=0; ivals[idx][0] = xrange_n(tr, i); double x = inp->vals[idx][1] = xrange_n(xr, j); out->vals[idx][0] = ufunc(t, x); } + } // hyper-parameters for training float lr = nn_inp->learning_rate; // learning rate @@ -95,31 +81,33 @@ train_ann(struct train_inp *nn_inp, const char *nn_name) int max_epoch = 50; int max_drop_streak = 10; float frac_val = 0.1f; // fraction of samples to use for validation - + // run training - kann_train_fnn1(ann, lr, mini_size, max_epoch, max_drop_streak, frac_val, Nx*Nt, inp->vals, out->vals); + kann_train_fnn1( + ann, lr, mini_size, max_epoch, max_drop_streak, frac_val, Nx * Nt, inp->vals, out->vals + ); kann_save(nn_name, ann); // save to file - + gkyl_kn_vec_release(inp); gkyl_kn_vec_release(out); - kann_delete(ann); + kann_delete(ann); } // run inference on N input values -void -infer_ann(const char *nn_name, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +void infer_ann(const char *nn_name, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) { kann_t *ann = kann_load(nn_name); const float *ov; - for (int i=0; invec; ++i) { + for (int i = 0; i < inp->nvec; ++i) { ov = kann_apply1(ann, inp->vals[i]); - for (int j=0; jN; ++j) out->vals[i][j] = ov[j]; + for (int j = 0; j < out->N; ++j) { + out->vals[i][j] = ov[j]; + } } kann_delete(ann); } -void -write_to_gplot(void) +void write_to_gplot(void) { const char *gp_code = "set macros\n" @@ -130,55 +118,57 @@ write_to_gplot(void) "set grid\n" "set title \"Comparing Different Architectures\"\n" "plot [0:3] sin(0.35*2*pi)*sin(2*x)*exp(-x) with lines ls @BLUE title \"Exact\" "; - + FILE *fp = 0; - with_file(fp, "rt_kann_cmp_arch.gp", "w") { + with_file(fp, "rt_kann_cmp_arch.gp", "w") + { fprintf(fp, "%s", gp_code); fprintf(fp, ", \"rt_kann_cmp_arch_mlp.txt\" using 1:2 with points pt 9 ps 3 title \"MLP\" "); - fprintf(fp, ", \"rt_kann_cmp_arch_gru.txt\" using 1:2 with points pt 5 ps 2 title \"GRU\" "); + fprintf(fp, ", \"rt_kann_cmp_arch_gru.txt\" using 1:2 with points pt 5 ps 2 title \"GRU\" "); fprintf(fp, "\n"); } } -void -write_infer_data(const char *fname, const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) +void write_infer_data( + const char *fname, const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out +) { FILE *fp = 0; - with_file(fp, fname, "w") { - for (int i=0; invec; ++i) + with_file(fp, fname, "w") + { + for (int i = 0; i < inp->nvec; ++i) { fprintf(fp, "%.5g %.5g\n", inp->vals[i][0], out->vals[i][0]); + } } } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int p_train = 0, p_infer = 0, p_verbose = 0, c; while ((c = getopt(argc, argv, "+htiv")) != -1) { - switch (c) - { - case 'h': - fprintf(stdout, "rt_kann_cmp_arch -i -t -v\n"); - fprintf(stdout, " -t Run Training\n"); - fprintf(stdout, " -i Run Inference\n"); - fprintf(stdout, " -v Verbose mode\n"); - exit(0); - break; - - case 't': - p_train = 1; - break; - - case 'i': - p_infer = 1; - break; - - case 'v': - p_verbose = 3; - break; - - case '?': - break; + switch (c) { + case 'h': + fprintf(stdout, "rt_kann_cmp_arch -i -t -v\n"); + fprintf(stdout, " -t Run Training\n"); + fprintf(stdout, " -i Run Inference\n"); + fprintf(stdout, " -v Verbose mode\n"); + exit(0); + break; + + case 't': + p_train = 1; + break; + + case 'i': + p_infer = 1; + break; + + case 'v': + p_verbose = 3; + break; + + case '?': + break; } } @@ -186,26 +176,26 @@ main(int argc, char *argv[]) if (p_train) { fprintf(stdout, "*** Training MLP\n"); - train_ann( &(struct train_inp) { - .ntrain = { 101, 101 }, + train_ann( + &(struct train_inp + ){.ntrain = {101, 101}, .ndepth = 2, .nwidth = 64, .learning_rate = 1e-3f, - .layer_type = ANN_DENSE - }, + .layer_type = ANN_DENSE}, "rt_kann_cmp_arch_mlp.kann" ); fprintf(stdout, "*** Training GRU\n"); - train_ann( &(struct train_inp) { - .ntrain = { 101, 101 }, + train_ann( + &(struct train_inp + ){.ntrain = {101, 101}, .ndepth = 2, .nwidth = 32, .learning_rate = 1e-3f, - .layer_type = ANN_GRU - }, + .layer_type = ANN_GRU}, "rt_kann_cmp_arch_gru.kann" - ); + ); } if (p_infer) { @@ -214,8 +204,8 @@ main(int argc, char *argv[]) struct gkyl_kn_vec *inp = gkyl_kn_vec_new(nvec, 2); struct gkyl_kn_vec *out = gkyl_kn_vec_new(nvec, 1); - struct xrange tr = { .xleft = 0.0f, .xright = 3.0f, .N = inp->nvec }; - for (int i=0; invec; ++i) { + struct xrange tr = {.xleft = 0.0f, .xright = 3.0f, .N = inp->nvec}; + for (int i = 0; i < inp->nvec; ++i) { inp->vals[i][0] = xrange_n(tr, i); inp->vals[i][1] = 0.35f; } @@ -231,8 +221,8 @@ main(int argc, char *argv[]) gkyl_kn_vec_release(inp); gkyl_kn_vec_release(out); } - + write_to_gplot(); - + return 0; } diff --git a/core/creg/rt_kann_cmp_arch_bench.c b/core/creg/rt_kann_cmp_arch_bench.c index fec1e780d2..5e519308ba 100644 --- a/core/creg/rt_kann_cmp_arch_bench.c +++ b/core/creg/rt_kann_cmp_arch_bench.c @@ -11,35 +11,29 @@ #include // 2D function to fit: sin(2*pi*x)*sin(2*t)*exp(-t) -static inline float -ufunc(float t, float x) +static inline float ufunc(float t, float x) { - return sinf(2.0f*(float)M_PI*x)*sinf(2.0f*t)*expf(-t); + return sinf(2.0f * (float)M_PI * x) * sinf(2.0f * t) * expf(-t); } -enum arch_type { - ARCH_MLP, - ARCH_GRU, - ARCH_GRU_NORM -}; +enum arch_type { ARCH_MLP, ARCH_GRU, ARCH_GRU_NORM }; -static const char *arch_name[] = { "MLP", "GRU", "GRU+Norm" }; +static const char *arch_name[] = {"MLP", "GRU", "GRU+Norm"}; -static kad_node_t* -build_net(enum arch_type arch, int nwidth, int ndepth) +static kad_node_t *build_net(enum arch_type arch, int nwidth, int ndepth) { kad_node_t *t = kann_layer_input(2); for (int i = 0; i < ndepth; ++i) { switch (arch) { - case ARCH_MLP: - t = kann_layer_dense(t, nwidth); - break; - case ARCH_GRU: - t = kann_layer_gru(t, nwidth, 0); - break; - case ARCH_GRU_NORM: - t = kann_layer_gru(t, nwidth, KANN_RNN_NORM); - break; + case ARCH_MLP: + t = kann_layer_dense(t, nwidth); + break; + case ARCH_GRU: + t = kann_layer_gru(t, nwidth, 0); + break; + case ARCH_GRU_NORM: + t = kann_layer_gru(t, nwidth, KANN_RNN_NORM); + break; } t = kad_tanh(t); } @@ -47,13 +41,11 @@ build_net(enum arch_type arch, int nwidth, int ndepth) return t; } -static void -fill_2d_data(struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out, - int Nt, int Nx) +static void fill_2d_data(struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out, int Nt, int Nx) { float dt = 3.0f / (Nt - 1); float dx = 1.0f / (Nx - 1); - for (int i = 0; i < Nt; ++i) + for (int i = 0; i < Nt; ++i) { for (int j = 0; j < Nx; ++j) { int idx = i * Nx + j; float t = dt * i; @@ -62,11 +54,13 @@ fill_2d_data(struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out, inp->vals[idx][1] = x; out->vals[idx][0] = ufunc(t, x); } + } } -static double -bench_train(enum arch_type arch, int ntrain_t, int ntrain_x, - int nwidth, int ndepth, bool use_gpu, const char *save_file) +static double bench_train( + enum arch_type arch, int ntrain_t, int ntrain_x, int nwidth, int ndepth, bool use_gpu, + const char *save_file +) { kad_node_t *cost = build_net(arch, nwidth, ndepth); struct gkyl_kann_net *net = gkyl_kann_net_new(cost, use_gpu); @@ -88,11 +82,7 @@ bench_train(enum arch_type arch, int ntrain_t, int ntrain_x, } struct gkyl_kann_train_params params = { - .learning_rate = 1e-3f, - .mini_size = 64, - .max_epoch = 50, - .max_drop_streak = 10, - .frac_val = 0.1f, + .learning_rate = 1e-3f, .mini_size = 64, .max_epoch = 50, .max_drop_streak = 10, .frac_val = 0.1f }; struct timespec t0, t1; @@ -102,8 +92,9 @@ bench_train(enum arch_type arch, int ntrain_t, int ntrain_x, double elapsed = (t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) * 1e-9; - if (save_file) + if (save_file) { gkyl_kann_net_save(net, save_file); + } if (use_gpu) { gkyl_kn_vec_release(inp_cu); @@ -116,8 +107,7 @@ bench_train(enum arch_type arch, int ntrain_t, int ntrain_x, return elapsed; } -static double -bench_infer_batch(const char *model_file, int nvec, bool use_gpu) +static double bench_infer_batch(const char *model_file, int nvec, bool use_gpu) { struct gkyl_kann_net *net = gkyl_kann_net_load(model_file, use_gpu); @@ -146,8 +136,9 @@ bench_infer_batch(const char *model_file, int nvec, bool use_gpu) int nreps = 100; struct timespec t0, t1; clock_gettime(CLOCK_MONOTONIC, &t0); - for (int r = 0; r < nreps; ++r) + for (int r = 0; r < nreps; ++r) { gkyl_kann_net_apply(net, inp_t, out_t); + } clock_gettime(CLOCK_MONOTONIC, &t1); double elapsed = ((t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) * 1e-9) / nreps; @@ -163,8 +154,7 @@ bench_infer_batch(const char *model_file, int nvec, bool use_gpu) return elapsed; } -static double -bench_infer_rnn(const char *model_file, int nvec, bool use_gpu) +static double bench_infer_rnn(const char *model_file, int nvec, bool use_gpu) { struct gkyl_kann_net *net = gkyl_kann_net_load(model_file, use_gpu); @@ -193,8 +183,9 @@ bench_infer_rnn(const char *model_file, int nvec, bool use_gpu) int nreps = 100; struct timespec t0, t1; clock_gettime(CLOCK_MONOTONIC, &t0); - for (int r = 0; r < nreps; ++r) + for (int r = 0; r < nreps; ++r) { gkyl_kann_net_apply_rnn(net, inp_t, out_t); + } clock_gettime(CLOCK_MONOTONIC, &t1); double elapsed = ((t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) * 1e-9) / nreps; @@ -210,46 +201,51 @@ bench_infer_rnn(const char *model_file, int nvec, bool use_gpu) return elapsed; } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int ntrain_t = 51, ntrain_x = 51; int ninfer = 101; - int widths[] = { 32, 64, 128 }; - int depths[] = { 2, 4 }; + int widths[] = {32, 64, 128}; + int depths[] = {2, 4}; int nw = sizeof(widths) / sizeof(widths[0]); int nd = sizeof(depths) / sizeof(depths[0]); - enum arch_type archs[] = { ARCH_MLP, ARCH_GRU, ARCH_GRU_NORM }; + enum arch_type archs[] = {ARCH_MLP, ARCH_GRU, ARCH_GRU_NORM}; int na = sizeof(archs) / sizeof(archs[0]); // ---- Training benchmark ---- - fprintf(stdout, "=== Training Benchmark (ntrain=%dx%d=%d, 50 epochs, mini_size=64) ===\n", - ntrain_t, ntrain_x, ntrain_t * ntrain_x); - fprintf(stdout, "%10s %6s %6s %10s %10s %10s\n", - "arch", "width", "depth", "CPU (s)", "GPU (s)", "speedup"); + fprintf( + stdout, "=== Training Benchmark (ntrain=%dx%d=%d, 50 epochs, mini_size=64) ===\n", ntrain_t, + ntrain_x, ntrain_t * ntrain_x + ); + fprintf( + stdout, "%10s %6s %6s %10s %10s %10s\n", "arch", "width", "depth", "CPU (s)", "GPU (s)", + "speedup" + ); for (int ai = 0; ai < na; ++ai) { for (int di = 0; di < nd; ++di) { for (int wi = 0; wi < nw; ++wi) { int w = widths[wi], d = depths[di]; - double t_cpu = bench_train(archs[ai], ntrain_t, ntrain_x, - w, d, false, NULL); - double t_gpu = bench_train(archs[ai], ntrain_t, ntrain_x, - w, d, true, NULL); + double t_cpu = bench_train(archs[ai], ntrain_t, ntrain_x, w, d, false, NULL); + double t_gpu = bench_train(archs[ai], ntrain_t, ntrain_x, w, d, true, NULL); - fprintf(stdout, "%10s %6d %6d %10.4f %10.4f %10.2fx\n", - arch_name[archs[ai]], w, d, t_cpu, t_gpu, t_cpu / t_gpu); + fprintf( + stdout, "%10s %6d %6d %10.4f %10.4f %10.2fx\n", arch_name[archs[ai]], w, d, t_cpu, t_gpu, + t_cpu / t_gpu + ); } } } // ---- Batch inference benchmark ---- fprintf(stdout, "\n=== Batch Inference Benchmark (nvec=%d, avg of 100 reps) ===\n", ninfer); - fprintf(stdout, "%10s %6s %6s %10s %10s %10s\n", - "arch", "width", "depth", "CPU (ms)", "GPU (ms)", "speedup"); + fprintf( + stdout, "%10s %6s %6s %10s %10s %10s\n", "arch", "width", "depth", "CPU (ms)", "GPU (ms)", + "speedup" + ); for (int ai = 0; ai < na; ++ai) { for (int di = 0; di < nd; ++di) { @@ -257,15 +253,15 @@ main(int argc, char *argv[]) int w = widths[wi], d = depths[di]; // Quick train to get a model file - bench_train(archs[ai], ntrain_t, ntrain_x, w, d, false, - "bench_cmp_tmp.kann"); + bench_train(archs[ai], ntrain_t, ntrain_x, w, d, false, "bench_cmp_tmp.kann"); double t_cpu = bench_infer_batch("bench_cmp_tmp.kann", ninfer, false); double t_gpu = bench_infer_batch("bench_cmp_tmp.kann", ninfer, true); - fprintf(stdout, "%10s %6d %6d %10.4f %10.4f %10.2fx\n", - arch_name[archs[ai]], w, d, t_cpu * 1000, t_gpu * 1000, - t_cpu / t_gpu); + fprintf( + stdout, "%10s %6d %6d %10.4f %10.4f %10.2fx\n", arch_name[archs[ai]], w, d, t_cpu * 1000, + t_gpu * 1000, t_cpu / t_gpu + ); remove("bench_cmp_tmp.kann"); } @@ -273,11 +269,15 @@ main(int argc, char *argv[]) } // ---- Sequential RNN inference benchmark (GRU and GRU+Norm only) ---- - fprintf(stdout, "\n=== Sequential RNN Inference Benchmark (nvec=%d, avg of 100 reps) ===\n", ninfer); - fprintf(stdout, "%10s %6s %6s %10s %10s %10s\n", - "arch", "width", "depth", "CPU (ms)", "GPU (ms)", "speedup"); - - enum arch_type rnn_archs[] = { ARCH_GRU, ARCH_GRU_NORM }; + fprintf( + stdout, "\n=== Sequential RNN Inference Benchmark (nvec=%d, avg of 100 reps) ===\n", ninfer + ); + fprintf( + stdout, "%10s %6s %6s %10s %10s %10s\n", "arch", "width", "depth", "CPU (ms)", "GPU (ms)", + "speedup" + ); + + enum arch_type rnn_archs[] = {ARCH_GRU, ARCH_GRU_NORM}; int nra = sizeof(rnn_archs) / sizeof(rnn_archs[0]); for (int ai = 0; ai < nra; ++ai) { @@ -285,15 +285,15 @@ main(int argc, char *argv[]) for (int wi = 0; wi < nw; ++wi) { int w = widths[wi], d = depths[di]; - bench_train(rnn_archs[ai], ntrain_t, ntrain_x, w, d, false, - "bench_cmp_tmp.kann"); + bench_train(rnn_archs[ai], ntrain_t, ntrain_x, w, d, false, "bench_cmp_tmp.kann"); double t_cpu = bench_infer_rnn("bench_cmp_tmp.kann", ninfer, false); double t_gpu = bench_infer_rnn("bench_cmp_tmp.kann", ninfer, true); - fprintf(stdout, "%10s %6d %6d %10.4f %10.4f %10.2fx\n", - arch_name[rnn_archs[ai]], w, d, t_cpu * 1000, t_gpu * 1000, - t_cpu / t_gpu); + fprintf( + stdout, "%10s %6d %6d %10.4f %10.4f %10.2fx\n", arch_name[rnn_archs[ai]], w, d, + t_cpu * 1000, t_gpu * 1000, t_cpu / t_gpu + ); remove("bench_cmp_tmp.kann"); } diff --git a/core/creg/rt_kann_cmp_arch_gkw.c b/core/creg/rt_kann_cmp_arch_gkw.c index bef4260cd9..294b6bb0fa 100644 --- a/core/creg/rt_kann_cmp_arch_gkw.c +++ b/core/creg/rt_kann_cmp_arch_gkw.c @@ -13,25 +13,19 @@ struct xrange { int N; }; -static inline float -xrange_n(struct xrange xr, int n) +static inline float xrange_n(struct xrange xr, int n) { - float dx = (xr.xright-xr.xleft)/(xr.N-1); - return xr.xleft + dx*n; + float dx = (xr.xright - xr.xleft) / (xr.N - 1); + return xr.xleft + dx * n; } // function to fit -static inline float -ufunc(float t, float x) +static inline float ufunc(float t, float x) { - return sinf(2.0f*M_PI*x)*sinf(2.0f*t)*expf(-t); + return sinf(2.0f * M_PI * x) * sinf(2.0f * t) * expf(-t); } -enum ann_layer_type { - ANN_DENSE, - ANN_GRU, - ANN_GRU_NORM -}; +enum ann_layer_type { ANN_DENSE, ANN_GRU, ANN_GRU_NORM }; struct train_inp { int ntrain[2]; @@ -42,23 +36,22 @@ struct train_inp { bool use_gpu; }; -void -train_ann(struct train_inp *nn_inp, const char *nn_name) +void train_ann(struct train_inp *nn_inp, const char *nn_name) { kad_node_t *t_net; t_net = kann_layer_input(2); - for (int i=0; indepth; ++i) { - switch(nn_inp->layer_type) { - case ANN_DENSE: - t_net = kann_layer_dense(t_net, nn_inp->nwidth); - break; - case ANN_GRU: - t_net = kann_layer_gru(t_net, nn_inp->nwidth, 0); - break; - case ANN_GRU_NORM: - t_net = kann_layer_gru(t_net, nn_inp->nwidth, KANN_RNN_NORM); - break; + for (int i = 0; i < nn_inp->ndepth; ++i) { + switch (nn_inp->layer_type) { + case ANN_DENSE: + t_net = kann_layer_dense(t_net, nn_inp->nwidth); + break; + case ANN_GRU: + t_net = kann_layer_gru(t_net, nn_inp->nwidth, 0); + break; + case ANN_GRU_NORM: + t_net = kann_layer_gru(t_net, nn_inp->nwidth, KANN_RNN_NORM); + break; } t_net = kad_tanh(t_net); } @@ -68,39 +61,32 @@ train_ann(struct train_inp *nn_inp, const char *nn_name) // allocate memory for input/output vectors int Nt = nn_inp->ntrain[0], Nx = nn_inp->ntrain[1]; - int N = Nt*Nx; + int N = Nt * Nx; struct gkyl_kn_vec *inp = gkyl_kn_vec_new(N, 2); struct gkyl_kn_vec *out = gkyl_kn_vec_new(N, 1); - struct xrange tr = { - .xleft = 0.0f, - .xright = 3.0f, - .N = Nt - }; + struct xrange tr = {.xleft = 0.0f, .xright = 3.0f, .N = Nt}; - struct xrange xr = { - .xleft = 0.0f, - .xright = 1.0f, - .N = Nx - }; + struct xrange xr = {.xleft = 0.0f, .xright = 1.0f, .N = Nx}; // initialize input/output mapping - for (int i=0; ivals[idx][0] = xrange_n(tr, i); double x = inp->vals[idx][1] = xrange_n(xr, j); out->vals[idx][0] = ufunc(t, x); } + } struct gkyl_kann_train_params params = { .learning_rate = nn_inp->learning_rate, .mini_size = 64, .max_epoch = 50, .max_drop_streak = 10, - .frac_val = 0.1f, + .frac_val = 0.1f }; if (nn_inp->use_gpu) { @@ -125,9 +111,9 @@ train_ann(struct train_inp *nn_inp, const char *nn_name) } // run inference on N input values (batch mode) -void -infer_ann(const char *nn_name, bool use_gpu, - const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +void infer_ann( + const char *nn_name, bool use_gpu, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out +) { struct gkyl_kann_net *net = gkyl_kann_net_load(nn_name, use_gpu); @@ -149,9 +135,9 @@ infer_ann(const char *nn_name, bool use_gpu, } // run sequential RNN inference (one timestep at a time with recurrence) -void -infer_ann_rnn(const char *nn_name, bool use_gpu, - const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +void infer_ann_rnn( + const char *nn_name, bool use_gpu, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out +) { struct gkyl_kann_net *net = gkyl_kann_net_load(nn_name, use_gpu); @@ -172,8 +158,7 @@ infer_ann_rnn(const char *nn_name, bool use_gpu, gkyl_kann_net_release(net); } -void -write_to_gplot(void) +void write_to_gplot(void) { const char *gp_code = "set macros\n" @@ -186,7 +171,8 @@ write_to_gplot(void) "plot [0:3] sin(0.35*2*pi)*sin(2*x)*exp(-x) with lines ls @BLUE title \"Exact\" "; FILE *fp = 0; - with_file(fp, "rt_kann_cmp_arch_gkw.gp", "w") { + with_file(fp, "rt_kann_cmp_arch_gkw.gp", "w") + { fprintf(fp, "%s", gp_code); fprintf(fp, ", \"rt_kann_cmp_arch_gkw_mlp.txt\" using 1:2 with points pt 9 ps 3 title \"MLP\" "); fprintf(fp, ", \"rt_kann_cmp_arch_gkw_gru.txt\" using 1:2 with points pt 5 ps 2 title \"GRU\" "); @@ -194,93 +180,91 @@ write_to_gplot(void) } } -void -write_infer_data(const char *fname, const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) +void write_infer_data( + const char *fname, const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out +) { FILE *fp = 0; - with_file(fp, fname, "w") { - for (int i=0; invec; ++i) + with_file(fp, fname, "w") + { + for (int i = 0; i < inp->nvec; ++i) { fprintf(fp, "%.5g %.5g\n", inp->vals[i][0], out->vals[i][0]); + } } } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int p_train = 0, p_infer = 0, p_verbose = 0, c; bool use_gpu = false; while ((c = getopt(argc, argv, "+htivg")) != -1) { - switch (c) - { - case 'h': - fprintf(stdout, "rt_kann_cmp_arch_gkw -i -t -v -g\n"); - fprintf(stdout, " -t Run Training\n"); - fprintf(stdout, " -i Run Inference\n"); - fprintf(stdout, " -v Verbose mode\n"); - fprintf(stdout, " -g Use GPU\n"); - exit(0); - break; - - case 't': - p_train = 1; - break; - - case 'i': - p_infer = 1; - break; - - case 'v': - p_verbose = 3; - break; - - case 'g': - use_gpu = true; - break; - - case '?': - break; + switch (c) { + case 'h': + fprintf(stdout, "rt_kann_cmp_arch_gkw -i -t -v -g\n"); + fprintf(stdout, " -t Run Training\n"); + fprintf(stdout, " -i Run Inference\n"); + fprintf(stdout, " -v Verbose mode\n"); + fprintf(stdout, " -g Use GPU\n"); + exit(0); + break; + + case 't': + p_train = 1; + break; + + case 'i': + p_infer = 1; + break; + + case 'v': + p_verbose = 3; + break; + + case 'g': + use_gpu = true; + break; + + case '?': + break; } } gkyl_kann_net_set_verbose(p_verbose); if (p_train) { - fprintf(stdout, "*** Training MLP%s (gkyl_kann_net wrapper)\n", - use_gpu ? " (GPU)" : ""); - train_ann( &(struct train_inp) { - .ntrain = { 101, 101 }, + fprintf(stdout, "*** Training MLP%s (gkyl_kann_net wrapper)\n", use_gpu ? " (GPU)" : ""); + train_ann( + &(struct train_inp + ){.ntrain = {101, 101}, .ndepth = 2, .nwidth = 64, .learning_rate = 1e-3f, .layer_type = ANN_DENSE, - .use_gpu = use_gpu - }, + .use_gpu = use_gpu}, "rt_kann_cmp_arch_gkw_mlp.kann" ); - fprintf(stdout, "*** Training GRU%s (gkyl_kann_net wrapper)\n", - use_gpu ? " (GPU)" : ""); - train_ann( &(struct train_inp) { - .ntrain = { 101, 101 }, + fprintf(stdout, "*** Training GRU%s (gkyl_kann_net wrapper)\n", use_gpu ? " (GPU)" : ""); + train_ann( + &(struct train_inp + ){.ntrain = {101, 101}, .ndepth = 2, .nwidth = 32, .learning_rate = 1e-3f, .layer_type = ANN_GRU, - .use_gpu = use_gpu - }, + .use_gpu = use_gpu}, "rt_kann_cmp_arch_gkw_gru.kann" ); - fprintf(stdout, "*** Training GRU+Norm%s (gkyl_kann_net wrapper)\n", - use_gpu ? " (GPU)" : ""); - train_ann( &(struct train_inp) { - .ntrain = { 101, 101 }, + fprintf(stdout, "*** Training GRU+Norm%s (gkyl_kann_net wrapper)\n", use_gpu ? " (GPU)" : ""); + train_ann( + &(struct train_inp + ){.ntrain = {101, 101}, .ndepth = 2, .nwidth = 32, .learning_rate = 1e-3f, .layer_type = ANN_GRU_NORM, - .use_gpu = use_gpu - }, + .use_gpu = use_gpu}, "rt_kann_cmp_arch_gkw_gru_norm.kann" ); } @@ -290,31 +274,27 @@ main(int argc, char *argv[]) struct gkyl_kn_vec *inp = gkyl_kn_vec_new(nvec, 2); struct gkyl_kn_vec *out = gkyl_kn_vec_new(nvec, 1); - struct xrange tr = { .xleft = 0.0f, .xright = 3.0f, .N = inp->nvec }; - for (int i=0; invec; ++i) { + struct xrange tr = {.xleft = 0.0f, .xright = 3.0f, .N = inp->nvec}; + for (int i = 0; i < inp->nvec; ++i) { inp->vals[i][0] = xrange_n(tr, i); inp->vals[i][1] = 0.35f; } - fprintf(stdout, "*** MLP Inference%s (gkyl_kann_net wrapper)\n", - use_gpu ? " (GPU)" : ""); + fprintf(stdout, "*** MLP Inference%s (gkyl_kann_net wrapper)\n", use_gpu ? " (GPU)" : ""); infer_ann("rt_kann_cmp_arch_gkw_mlp.kann", use_gpu, inp, out); write_infer_data("rt_kann_cmp_arch_gkw_mlp.txt", inp, out); - fprintf(stdout, "*** GRU Inference%s (gkyl_kann_net wrapper)\n", - use_gpu ? " (GPU)" : ""); + fprintf(stdout, "*** GRU Inference%s (gkyl_kann_net wrapper)\n", use_gpu ? " (GPU)" : ""); infer_ann("rt_kann_cmp_arch_gkw_gru.kann", use_gpu, inp, out); write_infer_data("rt_kann_cmp_arch_gkw_gru.txt", inp, out); - fprintf(stdout, "*** GRU+Norm Inference%s (gkyl_kann_net wrapper)\n", - use_gpu ? " (GPU)" : ""); + fprintf(stdout, "*** GRU+Norm Inference%s (gkyl_kann_net wrapper)\n", use_gpu ? " (GPU)" : ""); infer_ann("rt_kann_cmp_arch_gkw_gru_norm.kann", use_gpu, inp, out); write_infer_data("rt_kann_cmp_arch_gkw_gru_norm.txt", inp, out); // Sequential RNN inference: exercises pre-recurrence (hidden state // carries forward across timesteps) - fprintf(stdout, "*** GRU Sequential RNN Inference%s\n", - use_gpu ? " (GPU)" : ""); + fprintf(stdout, "*** GRU Sequential RNN Inference%s\n", use_gpu ? " (GPU)" : ""); infer_ann_rnn("rt_kann_cmp_arch_gkw_gru.kann", use_gpu, inp, out); write_infer_data("rt_kann_cmp_arch_gkw_gru_rnn.txt", inp, out); diff --git a/core/creg/rt_kann_gpu_cpu_verify.c b/core/creg/rt_kann_gpu_cpu_verify.c index 00e5637eb4..fa2a98dd98 100644 --- a/core/creg/rt_kann_gpu_cpu_verify.c +++ b/core/creg/rt_kann_gpu_cpu_verify.c @@ -9,15 +9,12 @@ #include #include -static inline float -ufunc(float x) +static inline float ufunc(float x) { - return 1.0f/(1.0f+100.0f*x*x); + return 1.0f / (1.0f + 100.0f * x * x); } -static void -train_and_save(int ntrain, int nwidth, int ndepth, bool use_gpu, - const char *filename) +static void train_and_save(int ntrain, int nwidth, int ndepth, bool use_gpu, const char *filename) { kad_node_t *t_net = kann_layer_input(1); for (int i = 0; i < ndepth; ++i) { @@ -49,11 +46,7 @@ train_and_save(int ntrain, int nwidth, int ndepth, bool use_gpu, } struct gkyl_kann_train_params params = { - .learning_rate = 1e-3f, - .mini_size = 64, - .max_epoch = 50, - .max_drop_streak = 10, - .frac_val = 0.1f, + .learning_rate = 1e-3f, .mini_size = 64, .max_epoch = 50, .max_drop_streak = 10, .frac_val = 0.1f }; gkyl_kann_net_train_fnn1(net, ¶ms, inp_t, out_t); @@ -70,8 +63,7 @@ train_and_save(int ntrain, int nwidth, int ndepth, bool use_gpu, // Run inference and return outputs in out (always host kn_vec) static void -infer(const char *filename, bool use_gpu, - const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +infer(const char *filename, bool use_gpu, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) { struct gkyl_kann_net *net = gkyl_kann_net_load(filename, use_gpu); @@ -91,14 +83,13 @@ infer(const char *filename, bool use_gpu, gkyl_kann_net_release(net); } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int ntrain = 1001; int ninfer = 21; - int widths[] = { 64, 128, 256, 512 }; - int depths[] = { 2, 4 }; + int widths[] = {64, 128, 256, 512}; + int depths[] = {2, 4}; int nw = sizeof(widths) / sizeof(widths[0]); int nd = sizeof(depths) / sizeof(depths[0]); @@ -107,8 +98,9 @@ main(int argc, char *argv[]) struct gkyl_kn_vec *out_gpu = gkyl_kn_vec_new(ninfer, 1); float dx = 2.0f / (ninfer - 1); - for (int i = 0; i < ninfer; ++i) + for (int i = 0; i < ninfer; ++i) { inp->vals[i][0] = -1.0f + dx * i; + } fprintf(stdout, "=== Test 1: Train on CPU, compare CPU vs GPU inference ===\n"); fprintf(stdout, " (Same model, same weights — should match to float precision)\n\n"); @@ -125,12 +117,13 @@ main(int argc, char *argv[]) float max_diff = 0; for (int i = 0; i < ninfer; ++i) { float diff = fabsf(out_cpu->vals[i][0] - out_gpu->vals[i][0]); - if (diff > max_diff) max_diff = diff; + if (diff > max_diff) { + max_diff = diff; + } } const char *status = max_diff < 1e-4f ? "PASS" : "FAIL"; - fprintf(stdout, " width=%3d depth=%d: max|cpu-gpu|=%.3e [%s]\n", - w, d, max_diff, status); + fprintf(stdout, " width=%3d depth=%d: max|cpu-gpu|=%.3e [%s]\n", w, d, max_diff, status); } } @@ -153,12 +146,13 @@ main(int argc, char *argv[]) } mse /= ninfer; - float val_at_0 = out_cpu->vals[ninfer/2][0]; + float val_at_0 = out_cpu->vals[ninfer / 2][0]; - const char *status = (mse < 0.05f && fabsf(val_at_0 - 1.0f) < 0.2f) - ? "PASS" : "FAIL"; - fprintf(stdout, " width=%3d depth=%d: mse=%.3e f(0)=%.4f (exact=1.0) [%s]\n", - w, d, mse, val_at_0, status); + const char *status = (mse < 0.05f && fabsf(val_at_0 - 1.0f) < 0.2f) ? "PASS" : "FAIL"; + fprintf( + stdout, " width=%3d depth=%d: mse=%.3e f(0)=%.4f (exact=1.0) [%s]\n", w, d, mse, + val_at_0, status + ); } } diff --git a/core/creg/rt_kann_mlp.c b/core/creg/rt_kann_mlp.c index 753c169617..5d372a9e15 100644 --- a/core/creg/rt_kann_mlp.c +++ b/core/creg/rt_kann_mlp.c @@ -11,18 +11,16 @@ struct xrange { int N; }; -static inline float -xrange_n(struct xrange xr, int n) +static inline float xrange_n(struct xrange xr, int n) { - float dx = (xr.xright-xr.xleft)/(xr.N-1); - return xr.xleft + dx*n; + float dx = (xr.xright - xr.xleft) / (xr.N - 1); + return xr.xleft + dx * n; } // function to fit -static inline float -ufunc(float x) +static inline float ufunc(float x) { - return 1.0f/(1.0f+100.0f*x*x); + return 1.0f / (1.0f + 100.0f * x * x); } struct train_inp { @@ -32,17 +30,16 @@ struct train_inp { float learning_rate; }; -void -train_ann(struct train_inp *nn_inp, const char *nn_name) +void train_ann(struct train_inp *nn_inp, const char *nn_name) { kad_node_t *t_net; t_net = kann_layer_input(1); - for (int i=0; indepth; ++i) { + for (int i = 0; i < nn_inp->ndepth; ++i) { t_net = kann_layer_dense(t_net, nn_inp->nwidth); t_net = kad_tanh(t_net); } - + t_net = kann_layer_cost(t_net, 1, KANN_C_MSE); kann_t *ann = kann_new(t_net, 0); @@ -51,14 +48,10 @@ train_ann(struct train_inp *nn_inp, const char *nn_name) struct gkyl_kn_vec *inp = gkyl_kn_vec_new(N, 1); struct gkyl_kn_vec *out = gkyl_kn_vec_new(N, 1); - struct xrange xr = { - .xleft = -1.0, - .xright = 1.0, - .N = N - }; + struct xrange xr = {.xleft = -1.0, .xright = 1.0, .N = N}; // initialize input/output mapping - for (int i=0; ivals[i][0] = xrange_n(xr, i); out->vals[i][0] = ufunc(inp->vals[i][0]); } @@ -69,82 +62,83 @@ train_ann(struct train_inp *nn_inp, const char *nn_name) int max_epoch = 50; int max_drop_streak = 10; float frac_val = 0.1f; // fraction of samples to use for validation - + // run training kann_train_fnn1(ann, lr, mini_size, max_epoch, max_drop_streak, frac_val, N, inp->vals, out->vals); kann_save(nn_name, ann); // save to file - + gkyl_kn_vec_release(inp); gkyl_kn_vec_release(out); - kann_delete(ann); + kann_delete(ann); } // run inference on N input values -void -infer_ann(const char *nn_name, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +void infer_ann(const char *nn_name, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) { kann_t *ann = kann_load(nn_name); const float *ov; - for (int i=0; invec; ++i) { + for (int i = 0; i < inp->nvec; ++i) { ov = kann_apply1(ann, inp->vals[i]); - for (int j=0; jN; ++j) out->vals[i][j] = ov[j]; + for (int j = 0; j < out->N; ++j) { + out->vals[i][j] = ov[j]; + } } kann_delete(ann); } -void -write_to_gplot(const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) +void write_to_gplot(const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) { - const char *gpcode = - "set macros\n" - "set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 5 # blue\n" - "set style line 2 lc rgb '#dd181f' lt 1 lw 2 pt 7 # red\n" - "BLUE = \"1\"\n" - "RED = \"2\"\n" - "set grid\n" - "plot \"rt_kann_mlp_data.txt\" using 1:2 with points pt 9 ps 3 title \"NN\", [-1:1] 1/(1+100*x**2) with lines ls @BLUE title \"Exact\""; + const char *gpcode = "set macros\n" + "set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 5 # blue\n" + "set style line 2 lc rgb '#dd181f' lt 1 lw 2 pt 7 # red\n" + "BLUE = \"1\"\n" + "RED = \"2\"\n" + "set grid\n" + "plot \"rt_kann_mlp_data.txt\" using 1:2 with points pt 9 ps 3 title " + "\"NN\", [-1:1] 1/(1+100*x**2) with lines ls @BLUE title \"Exact\""; FILE *fp = 0; - with_file(fp, "rt_kann_mlp.gp", "w") { + with_file(fp, "rt_kann_mlp.gp", "w") + { fprintf(fp, "%s", gpcode); } fp = 0; - with_file(fp, "rt_kann_mlp_data.txt", "w") { - for (int i=0; invec; ++i) + with_file(fp, "rt_kann_mlp_data.txt", "w") + { + for (int i = 0; i < inp->nvec; ++i) { fprintf(fp, "%.5g %.5g\n", inp->vals[i][0], out->vals[i][0]); + } } } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int p_train = 0, p_infer = 0, p_verbose = 0, c; while ((c = getopt(argc, argv, "+htiv")) != -1) { - switch (c) - { - case 'h': - fprintf(stdout, "rt_kann_mlp -i -t -v\n"); - fprintf(stdout, " -t Run Training\n"); - fprintf(stdout, " -i Run Inference\n"); - fprintf(stdout, " -v Verbose mode\n"); - exit(0); - break; - - case 't': - p_train = 1; - break; - - case 'i': - p_infer = 1; - break; - - case 'v': - p_verbose = 3; - break; - - case '?': - break; + switch (c) { + case 'h': + fprintf(stdout, "rt_kann_mlp -i -t -v\n"); + fprintf(stdout, " -t Run Training\n"); + fprintf(stdout, " -i Run Inference\n"); + fprintf(stdout, " -v Verbose mode\n"); + exit(0); + break; + + case 't': + p_train = 1; + break; + + case 'i': + p_infer = 1; + break; + + case 'v': + p_verbose = 3; + break; + + case '?': + break; } } @@ -152,12 +146,8 @@ main(int argc, char *argv[]) if (p_train) { fprintf(stdout, "*** Training\n"); - train_ann( &(struct train_inp) { - .ntrain = 1001, - .ndepth = 2, - .nwidth = 256, - .learning_rate = 1e-3f - }, + train_ann( + &(struct train_inp){.ntrain = 1001, .ndepth = 2, .nwidth = 256, .learning_rate = 1e-3f}, "rt_kann_mlp.kann" ); } @@ -169,16 +159,17 @@ main(int argc, char *argv[]) struct gkyl_kn_vec *inp = gkyl_kn_vec_new(nvec, 1); struct gkyl_kn_vec *out = gkyl_kn_vec_new(nvec, 1); - struct xrange xr = { .xleft = -1.0, .xright = 1.0, .N = inp->nvec }; - for (int i=0; invec; ++i) + struct xrange xr = {.xleft = -1.0, .xright = 1.0, .N = inp->nvec}; + for (int i = 0; i < inp->nvec; ++i) { inp->vals[i][0] = xrange_n(xr, i); - + } + infer_ann("rt_kann_mlp.kann", inp, out); write_to_gplot(inp, out); - + gkyl_kn_vec_release(inp); gkyl_kn_vec_release(out); } - + return 0; } diff --git a/core/creg/rt_kann_mlp_gkw.c b/core/creg/rt_kann_mlp_gkw.c index 50fbabfa07..719ce8e0e1 100644 --- a/core/creg/rt_kann_mlp_gkw.c +++ b/core/creg/rt_kann_mlp_gkw.c @@ -13,18 +13,16 @@ struct xrange { int N; }; -static inline float -xrange_n(struct xrange xr, int n) +static inline float xrange_n(struct xrange xr, int n) { - float dx = (xr.xright-xr.xleft)/(xr.N-1); - return xr.xleft + dx*n; + float dx = (xr.xright - xr.xleft) / (xr.N - 1); + return xr.xleft + dx * n; } // function to fit -static inline float -ufunc(float x) +static inline float ufunc(float x) { - return 1.0f/(1.0f+100.0f*x*x); + return 1.0f / (1.0f + 100.0f * x * x); } struct train_inp { @@ -35,13 +33,12 @@ struct train_inp { bool use_gpu; }; -void -train_ann(struct train_inp *nn_inp, const char *nn_name) +void train_ann(struct train_inp *nn_inp, const char *nn_name) { kad_node_t *t_net; t_net = kann_layer_input(1); - for (int i=0; indepth; ++i) { + for (int i = 0; i < nn_inp->ndepth; ++i) { t_net = kann_layer_dense(t_net, nn_inp->nwidth); t_net = kad_tanh(t_net); } @@ -55,13 +52,9 @@ train_ann(struct train_inp *nn_inp, const char *nn_name) struct gkyl_kn_vec *inp = gkyl_kn_vec_new(N, 1); struct gkyl_kn_vec *out = gkyl_kn_vec_new(N, 1); - struct xrange xr = { - .xleft = -1.0, - .xright = 1.0, - .N = N - }; + struct xrange xr = {.xleft = -1.0, .xright = 1.0, .N = N}; - for (int i=0; ivals[i][0] = xrange_n(xr, i); out->vals[i][0] = ufunc(inp->vals[i][0]); } @@ -71,7 +64,7 @@ train_ann(struct train_inp *nn_inp, const char *nn_name) .mini_size = 64, .max_epoch = 50, .max_drop_streak = 10, - .frac_val = 0.1f, + .frac_val = 0.1f }; if (nn_inp->use_gpu) { @@ -97,9 +90,7 @@ train_ann(struct train_inp *nn_inp, const char *nn_name) } // run inference on N input values -void -infer_ann(const char *nn_name, bool use_gpu, - struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +void infer_ann(const char *nn_name, bool use_gpu, struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) { struct gkyl_kann_net *net = gkyl_kann_net_load(nn_name, use_gpu); @@ -120,65 +111,65 @@ infer_ann(const char *nn_name, bool use_gpu, gkyl_kann_net_release(net); } -void -write_to_gplot(const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) +void write_to_gplot(const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) { - const char *gpcode = - "set macros\n" - "set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 5 # blue\n" - "set style line 2 lc rgb '#dd181f' lt 1 lw 2 pt 7 # red\n" - "BLUE = \"1\"\n" - "RED = \"2\"\n" - "set grid\n" - "plot \"rt_kann_mlp_gkw_data.txt\" using 1:2 with points pt 9 ps 3 title \"NN\", [-1:1] 1/(1+100*x**2) with lines ls @BLUE title \"Exact\""; + const char *gpcode = "set macros\n" + "set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 5 # blue\n" + "set style line 2 lc rgb '#dd181f' lt 1 lw 2 pt 7 # red\n" + "BLUE = \"1\"\n" + "RED = \"2\"\n" + "set grid\n" + "plot \"rt_kann_mlp_gkw_data.txt\" using 1:2 with points pt 9 ps 3 title " + "\"NN\", [-1:1] 1/(1+100*x**2) with lines ls @BLUE title \"Exact\""; FILE *fp = 0; - with_file(fp, "rt_kann_mlp_gkw.gp", "w") { + with_file(fp, "rt_kann_mlp_gkw.gp", "w") + { fprintf(fp, "%s", gpcode); } fp = 0; - with_file(fp, "rt_kann_mlp_gkw_data.txt", "w") { - for (int i=0; invec; ++i) + with_file(fp, "rt_kann_mlp_gkw_data.txt", "w") + { + for (int i = 0; i < inp->nvec; ++i) { fprintf(fp, "%.5g %.5g\n", inp->vals[i][0], out->vals[i][0]); + } } } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int p_train = 0, p_infer = 0, p_verbose = 0, c; bool use_gpu = false; while ((c = getopt(argc, argv, "+htivg")) != -1) { - switch (c) - { - case 'h': - fprintf(stdout, "rt_kann_mlp_gkw -i -t -v -g\n"); - fprintf(stdout, " -t Run Training\n"); - fprintf(stdout, " -i Run Inference\n"); - fprintf(stdout, " -v Verbose mode\n"); - fprintf(stdout, " -g Run on GPU\n"); - exit(0); - break; - - case 't': - p_train = 1; - break; - - case 'i': - p_infer = 1; - break; - - case 'v': - p_verbose = 3; - break; - - case 'g': - use_gpu = true; - break; - - case '?': - break; + switch (c) { + case 'h': + fprintf(stdout, "rt_kann_mlp_gkw -i -t -v -g\n"); + fprintf(stdout, " -t Run Training\n"); + fprintf(stdout, " -i Run Inference\n"); + fprintf(stdout, " -v Verbose mode\n"); + fprintf(stdout, " -g Run on GPU\n"); + exit(0); + break; + + case 't': + p_train = 1; + break; + + case 'i': + p_infer = 1; + break; + + case 'v': + p_verbose = 3; + break; + + case 'g': + use_gpu = true; + break; + + case '?': + break; } } @@ -186,13 +177,9 @@ main(int argc, char *argv[]) if (p_train) { fprintf(stdout, "*** Training%s\n", use_gpu ? " (GPU)" : ""); - train_ann( &(struct train_inp) { - .ntrain = 1001, - .ndepth = 2, - .nwidth = 256, - .learning_rate = 1e-3f, - .use_gpu = use_gpu - }, + train_ann( + &(struct train_inp + ){.ntrain = 1001, .ndepth = 2, .nwidth = 256, .learning_rate = 1e-3f, .use_gpu = use_gpu}, "rt_kann_mlp_gkw.kann" ); } @@ -203,9 +190,10 @@ main(int argc, char *argv[]) struct gkyl_kn_vec *inp = gkyl_kn_vec_new(nvec, 1); struct gkyl_kn_vec *out = gkyl_kn_vec_new(nvec, 1); - struct xrange xr = { .xleft = -1.0, .xright = 1.0, .N = inp->nvec }; - for (int i=0; invec; ++i) + struct xrange xr = {.xleft = -1.0, .xright = 1.0, .N = inp->nvec}; + for (int i = 0; i < inp->nvec; ++i) { inp->vals[i][0] = xrange_n(xr, i); + } infer_ann("rt_kann_mlp_gkw.kann", use_gpu, inp, out); write_to_gplot(inp, out); diff --git a/core/creg/rt_kann_moe.c b/core/creg/rt_kann_moe.c index 66b4902dde..02e90f6cdf 100644 --- a/core/creg/rt_kann_moe.c +++ b/core/creg/rt_kann_moe.c @@ -12,23 +12,20 @@ struct xrange { int N; }; -static inline float -xrange_n(struct xrange xr, int n) +static inline float xrange_n(struct xrange xr, int n) { float dx = (xr.xright - xr.xleft) / (xr.N - 1); return xr.xleft + dx * n; } // Family of pretraining functions. -static inline float -tfunc(int n, float x) +static inline float tfunc(int n, float x) { return sinf((2.0f * M_PI * (n + 1) * x) + n); } // Function to fit. -static inline float -ufunc(float x) +static inline float ufunc(float x) { return 1.0f / (1.0f + 100.0f * x * x); } @@ -42,8 +39,7 @@ struct train_inp { }; // Construct an MLP (with tanh activation) to use as a single "expert". -static inline kad_node_t* -single_expert(kad_node_t *input, int n_layers, int n_hidden, int n_output) +static inline kad_node_t *single_expert(kad_node_t *input, int n_layers, int n_hidden, int n_output) { kad_node_t *t_net; @@ -57,8 +53,7 @@ single_expert(kad_node_t *input, int n_layers, int n_hidden, int n_output) } // Construct a "weighted expert", with an initial (trainable) scalar weight and a trainable scalar bias. -static inline kad_node_t* -weighted_expert(kad_node_t *expert, int n_output, float init_weight) +static inline kad_node_t *weighted_expert(kad_node_t *expert, int n_output, float init_weight) { kad_node_t *weight, *bias; kad_node_t *t_net; @@ -73,7 +68,7 @@ weighted_expert(kad_node_t *expert, int n_output, float init_weight) } // Construct a "mixture of experts" architecture consisting of multiple single "experts" linked together (with tanh activation and MSE cost). -static inline kad_node_t* +static inline kad_node_t * mixture_of_experts(int n_input, int n_layers, int n_hidden, int n_experts, int n_output) { kad_node_t *input; @@ -85,12 +80,12 @@ mixture_of_experts(int n_input, int n_layers, int n_hidden, int n_experts, int n input = kann_layer_input(n_input); - experts = gkyl_malloc(n_experts * sizeof(kad_node_t*)); + experts = gkyl_malloc(n_experts * sizeof(kad_node_t *)); for (int i = 0; i < n_experts; i++) { experts[i] = single_expert(input, n_layers, n_hidden, n_output); } - weighted_experts = gkyl_malloc(n_experts * sizeof(kad_node_t*)); + weighted_experts = gkyl_malloc(n_experts * sizeof(kad_node_t *)); for (int i = 0; i < n_experts; i++) { weighted_experts[i] = weighted_expert(experts[i], n_output, 1.0f / n_experts); } @@ -108,15 +103,14 @@ mixture_of_experts(int n_input, int n_layers, int n_hidden, int n_experts, int n cost = kad_mse(activation, truth); cost->ext_flag |= KANN_F_COST; - + gkyl_free(experts); gkyl_free(weighted_experts); return cost; } -void -train_mixture(struct train_inp *nn_inp, const char *nn_name) +void train_mixture(struct train_inp *nn_inp, const char *nn_name) { kad_node_t *t_net = mixture_of_experts(1, nn_inp->ndepth, nn_inp->nwidth, nn_inp->nexperts, 1); kann_t *ann = kann_new(t_net, 0); @@ -135,11 +129,7 @@ train_mixture(struct train_inp *nn_inp, const char *nn_name) struct gkyl_kn_vec *inp_expert = gkyl_kn_vec_new(N_expert, 1); struct gkyl_kn_vec *out_expert = gkyl_kn_vec_new(N_expert, 1); - struct xrange xr_expert = { - .xleft = -1.0, - .xright = 1.0, - .N = N_expert - }; + struct xrange xr_expert = {.xleft = -1.0, .xright = 1.0, .N = N_expert}; // Initialize input/output mapping for individual experts. for (int j = 0; j < N_expert; j++) { @@ -147,7 +137,10 @@ train_mixture(struct train_inp *nn_inp, const char *nn_name) out_expert->vals[j][0] = tfunc(i, inp_expert->vals[j][0]); } - kann_train_fnn1(ann, lr, mini_size, max_epoch, max_drop_streak, frac_val, N_expert, inp_expert->vals, out_expert->vals); + kann_train_fnn1( + ann, lr, mini_size, max_epoch, max_drop_streak, frac_val, N_expert, inp_expert->vals, + out_expert->vals + ); gkyl_kn_vec_release(inp_expert); gkyl_kn_vec_release(out_expert); @@ -158,30 +151,25 @@ train_mixture(struct train_inp *nn_inp, const char *nn_name) struct gkyl_kn_vec *inp = gkyl_kn_vec_new(N, 1); struct gkyl_kn_vec *out = gkyl_kn_vec_new(N, 1); - struct xrange xr = { - .xleft = -1.0, - .xright = 1.0, - .N = N - }; + struct xrange xr = {.xleft = -1.0, .xright = 1.0, .N = N}; // Initialize input/output mapping. for (int i = 0; i < N; i++) { inp->vals[i][0] = xrange_n(xr, i); out->vals[i][0] = ufunc(inp->vals[i][0]); } - + // Run mixture of experts training (i.e. finetuning). kann_train_fnn1(ann, lr, mini_size, max_epoch, max_drop_streak, frac_val, N, inp->vals, out->vals); kann_save(nn_name, ann); // Save to file. - + gkyl_kn_vec_release(inp); gkyl_kn_vec_release(out); - kann_delete(ann); + kann_delete(ann); } // Run inference on N input values. -void -infer_ann(const char *nn_name, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +void infer_ann(const char *nn_name, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) { kann_t *ann = kann_load(nn_name); const float *ov; @@ -194,60 +182,59 @@ infer_ann(const char *nn_name, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec kann_delete(ann); } -void -write_to_gplot(const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) +void write_to_gplot(const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) { - const char *gpcode = - "set macros\n" - "set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 5 # blue\n" - "set style line 2 lc rgb '#dd181f' lt 1 lw 2 pt 7 # red\n" - "BLUE = \"1\"\n" - "RED = \"2\"\n" - "set grid\n" - "plot \"rt_kann_moe_data.txt\" using 1:2 with points pt 9 ps 3 title \"NN\", [-1:1] 1/(1+100*x**2) with lines ls @BLUE title \"Exact\""; + const char *gpcode = "set macros\n" + "set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 5 # blue\n" + "set style line 2 lc rgb '#dd181f' lt 1 lw 2 pt 7 # red\n" + "BLUE = \"1\"\n" + "RED = \"2\"\n" + "set grid\n" + "plot \"rt_kann_moe_data.txt\" using 1:2 with points pt 9 ps 3 title " + "\"NN\", [-1:1] 1/(1+100*x**2) with lines ls @BLUE title \"Exact\""; FILE *fp = 0; - with_file(fp, "rt_kann_moe.gp", "w") { + with_file(fp, "rt_kann_moe.gp", "w") + { fprintf(fp, "%s", gpcode); } fp = 0; - with_file(fp, "rt_kann_moe_data.txt", "w") { + with_file(fp, "rt_kann_moe_data.txt", "w") + { for (int i = 0; i < inp->nvec; i++) { fprintf(fp, "%.5g %.5g\n", inp->vals[i][0], out->vals[i][0]); } } } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int p_train = 0, p_infer = 0, p_verbose = 0, c; while ((c = getopt(argc, argv, "+htiv")) != -1) { - switch (c) - { - case 'h': - fprintf(stdout, "rt_kann_moe -i -t -v\n"); - fprintf(stdout, " -t Run Training\n"); - fprintf(stdout, " -i Run Inference\n"); - fprintf(stdout, " -v Verbose mode\n"); - exit(0); - break; - - case 't': - p_train = 1; - break; - - case 'i': - p_infer = 1; - break; - - case 'v': - p_verbose = 3; - break; - - case '?': - break; + switch (c) { + case 'h': + fprintf(stdout, "rt_kann_moe -i -t -v\n"); + fprintf(stdout, " -t Run Training\n"); + fprintf(stdout, " -i Run Inference\n"); + fprintf(stdout, " -v Verbose mode\n"); + exit(0); + break; + + case 't': + p_train = 1; + break; + + case 'i': + p_infer = 1; + break; + + case 'v': + p_verbose = 3; + break; + + case '?': + break; } } @@ -255,13 +242,9 @@ main(int argc, char *argv[]) if (p_train) { fprintf(stdout, "*** Training\n"); - train_mixture( &(struct train_inp) { - .ntrain = 1001, - .ndepth = 2, - .nwidth = 256, - .nexperts = 3, - .learning_rate = 1e-3f - }, + train_mixture( + &(struct train_inp + ){.ntrain = 1001, .ndepth = 2, .nwidth = 256, .nexperts = 3, .learning_rate = 1e-3f}, "rt_kann_moe.kann" ); } @@ -273,17 +256,17 @@ main(int argc, char *argv[]) struct gkyl_kn_vec *inp = gkyl_kn_vec_new(nvec, 1); struct gkyl_kn_vec *out = gkyl_kn_vec_new(nvec, 1); - struct xrange xr = { .xleft = -1.0, .xright = 1.0, .N = inp->nvec }; + struct xrange xr = {.xleft = -1.0, .xright = 1.0, .N = inp->nvec}; for (int i = 0; i < inp->nvec; i++) { inp->vals[i][0] = xrange_n(xr, i); } - + infer_ann("rt_kann_moe.kann", inp, out); write_to_gplot(inp, out); - + gkyl_kn_vec_release(inp); gkyl_kn_vec_release(out); } - + return 0; } \ No newline at end of file diff --git a/core/creg/rt_kann_moe_gkw.c b/core/creg/rt_kann_moe_gkw.c index 6870aabcfb..43040c790c 100644 --- a/core/creg/rt_kann_moe_gkw.c +++ b/core/creg/rt_kann_moe_gkw.c @@ -12,23 +12,20 @@ struct xrange { int N; }; -static inline float -xrange_n(struct xrange xr, int n) +static inline float xrange_n(struct xrange xr, int n) { float dx = (xr.xright - xr.xleft) / (xr.N - 1); return xr.xleft + dx * n; } // Family of pretraining functions. -static inline float -tfunc(int n, float x) +static inline float tfunc(int n, float x) { return sinf((2.0f * M_PI * (n + 1) * x) + n); } // Function to fit. -static inline float -ufunc(float x) +static inline float ufunc(float x) { return 1.0f / (1.0f + 100.0f * x * x); } @@ -43,8 +40,7 @@ struct train_inp { }; // Construct an MLP (with tanh activation) to use as a single "expert". -static inline kad_node_t* -single_expert(kad_node_t *input, int n_layers, int n_hidden, int n_output) +static inline kad_node_t *single_expert(kad_node_t *input, int n_layers, int n_hidden, int n_output) { kad_node_t *t_net; @@ -58,8 +54,7 @@ single_expert(kad_node_t *input, int n_layers, int n_hidden, int n_output) } // Construct a "weighted expert", with an initial (trainable) scalar weight and a trainable scalar bias. -static inline kad_node_t* -weighted_expert(kad_node_t *expert, int n_output, float init_weight) +static inline kad_node_t *weighted_expert(kad_node_t *expert, int n_output, float init_weight) { kad_node_t *weight, *bias; kad_node_t *t_net; @@ -74,7 +69,7 @@ weighted_expert(kad_node_t *expert, int n_output, float init_weight) } // Construct a "mixture of experts" architecture consisting of multiple single "experts" linked together (with tanh activation and MSE cost). -static inline kad_node_t* +static inline kad_node_t * mixture_of_experts(int n_input, int n_layers, int n_hidden, int n_experts, int n_output) { kad_node_t *input; @@ -86,12 +81,12 @@ mixture_of_experts(int n_input, int n_layers, int n_hidden, int n_experts, int n input = kann_layer_input(n_input); - experts = gkyl_malloc(n_experts * sizeof(kad_node_t*)); + experts = gkyl_malloc(n_experts * sizeof(kad_node_t *)); for (int i = 0; i < n_experts; i++) { experts[i] = single_expert(input, n_layers, n_hidden, n_output); } - weighted_experts = gkyl_malloc(n_experts * sizeof(kad_node_t*)); + weighted_experts = gkyl_malloc(n_experts * sizeof(kad_node_t *)); for (int i = 0; i < n_experts; i++) { weighted_experts[i] = weighted_expert(experts[i], n_output, 1.0f / n_experts); } @@ -109,15 +104,14 @@ mixture_of_experts(int n_input, int n_layers, int n_hidden, int n_experts, int n cost = kad_mse(activation, truth); cost->ext_flag |= KANN_F_COST; - + gkyl_free(experts); gkyl_free(weighted_experts); return cost; } -void -train_mixture(struct train_inp *nn_inp, const char *nn_name) +void train_mixture(struct train_inp *nn_inp, const char *nn_name) { kad_node_t *t_net = mixture_of_experts(1, nn_inp->ndepth, nn_inp->nwidth, nn_inp->nexperts, 1); struct gkyl_kann_net *net = gkyl_kann_net_new(t_net, nn_inp->use_gpu); @@ -128,7 +122,7 @@ train_mixture(struct train_inp *nn_inp, const char *nn_name) .mini_size = 64, .max_epoch = 50, .max_drop_streak = 10, - .frac_val = 0.1f, + .frac_val = 0.1f }; // Run individual expert training (i.e. pretraining). @@ -139,11 +133,7 @@ train_mixture(struct train_inp *nn_inp, const char *nn_name) struct gkyl_kn_vec *inp_expert = gkyl_kn_vec_new(N_expert, 1); struct gkyl_kn_vec *out_expert = gkyl_kn_vec_new(N_expert, 1); - struct xrange xr_expert = { - .xleft = -1.0, - .xright = 1.0, - .N = N_expert - }; + struct xrange xr_expert = {.xleft = -1.0, .xright = 1.0, .N = N_expert}; for (int j = 0; j < N_expert; j++) { inp_expert->vals[j][0] = xrange_n(xr_expert, j); @@ -175,11 +165,7 @@ train_mixture(struct train_inp *nn_inp, const char *nn_name) struct gkyl_kn_vec *inp = gkyl_kn_vec_new(N, 1); struct gkyl_kn_vec *out = gkyl_kn_vec_new(N, 1); - struct xrange xr = { - .xleft = -1.0, - .xright = 1.0, - .N = N - }; + struct xrange xr = {.xleft = -1.0, .xright = 1.0, .N = N}; for (int i = 0; i < N; i++) { inp->vals[i][0] = xrange_n(xr, i); @@ -209,9 +195,7 @@ train_mixture(struct train_inp *nn_inp, const char *nn_name) } // Run inference on N input values. -void -infer_ann(const char *nn_name, bool use_gpu, - struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +void infer_ann(const char *nn_name, bool use_gpu, struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) { struct gkyl_kann_net *net = gkyl_kann_net_load(nn_name, use_gpu); @@ -232,66 +216,65 @@ infer_ann(const char *nn_name, bool use_gpu, gkyl_kann_net_release(net); } -void -write_to_gplot(const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) +void write_to_gplot(const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) { - const char *gpcode = - "set macros\n" - "set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 5 # blue\n" - "set style line 2 lc rgb '#dd181f' lt 1 lw 2 pt 7 # red\n" - "BLUE = \"1\"\n" - "RED = \"2\"\n" - "set grid\n" - "plot \"rt_kann_moe_gkw_data.txt\" using 1:2 with points pt 9 ps 3 title \"NN\", [-1:1] 1/(1+100*x**2) with lines ls @BLUE title \"Exact\""; + const char *gpcode = "set macros\n" + "set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 5 # blue\n" + "set style line 2 lc rgb '#dd181f' lt 1 lw 2 pt 7 # red\n" + "BLUE = \"1\"\n" + "RED = \"2\"\n" + "set grid\n" + "plot \"rt_kann_moe_gkw_data.txt\" using 1:2 with points pt 9 ps 3 title " + "\"NN\", [-1:1] 1/(1+100*x**2) with lines ls @BLUE title \"Exact\""; FILE *fp = 0; - with_file(fp, "rt_kann_moe_gkw.gp", "w") { + with_file(fp, "rt_kann_moe_gkw.gp", "w") + { fprintf(fp, "%s", gpcode); } fp = 0; - with_file(fp, "rt_kann_moe_gkw_data.txt", "w") { + with_file(fp, "rt_kann_moe_gkw_data.txt", "w") + { for (int i = 0; i < inp->nvec; i++) { fprintf(fp, "%.5g %.5g\n", inp->vals[i][0], out->vals[i][0]); } } } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int p_train = 0, p_infer = 0, p_verbose = 0, c; bool use_gpu = false; while ((c = getopt(argc, argv, "+htivg")) != -1) { - switch (c) - { - case 'h': - fprintf(stdout, "rt_kann_moe_gkw -i -t -v -g\n"); - fprintf(stdout, " -t Run Training\n"); - fprintf(stdout, " -i Run Inference\n"); - fprintf(stdout, " -v Verbose mode\n"); - fprintf(stdout, " -g Run on GPU\n"); - exit(0); - break; - - case 't': - p_train = 1; - break; - - case 'i': - p_infer = 1; - break; - - case 'v': - p_verbose = 3; - break; - - case 'g': - use_gpu = true; - break; - - case '?': - break; + switch (c) { + case 'h': + fprintf(stdout, "rt_kann_moe_gkw -i -t -v -g\n"); + fprintf(stdout, " -t Run Training\n"); + fprintf(stdout, " -i Run Inference\n"); + fprintf(stdout, " -v Verbose mode\n"); + fprintf(stdout, " -g Run on GPU\n"); + exit(0); + break; + + case 't': + p_train = 1; + break; + + case 'i': + p_infer = 1; + break; + + case 'v': + p_verbose = 3; + break; + + case 'g': + use_gpu = true; + break; + + case '?': + break; } } @@ -299,14 +282,14 @@ main(int argc, char *argv[]) if (p_train) { fprintf(stdout, "*** Training%s\n", use_gpu ? " (GPU)" : ""); - train_mixture( &(struct train_inp) { - .ntrain = 1001, + train_mixture( + &(struct train_inp + ){.ntrain = 1001, .ndepth = 2, .nwidth = 256, .nexperts = 3, .learning_rate = 1e-3f, - .use_gpu = use_gpu - }, + .use_gpu = use_gpu}, "rt_kann_moe_gkw.kann" ); } @@ -317,7 +300,7 @@ main(int argc, char *argv[]) struct gkyl_kn_vec *inp = gkyl_kn_vec_new(nvec, 1); struct gkyl_kn_vec *out = gkyl_kn_vec_new(nvec, 1); - struct xrange xr = { .xleft = -1.0, .xright = 1.0, .N = inp->nvec }; + struct xrange xr = {.xleft = -1.0, .xright = 1.0, .N = inp->nvec}; for (int i = 0; i < inp->nvec; i++) { inp->vals[i][0] = xrange_n(xr, i); } diff --git a/core/unit/ctest_alloc.c b/core/unit/ctest_alloc.c index 5f68b22449..25f96af728 100644 --- a/core/unit/ctest_alloc.c +++ b/core/unit/ctest_alloc.c @@ -1,41 +1,41 @@ #include #include -void -test_aligned_alloc_ho() +void test_aligned_alloc_ho() { - int *d1 = gkyl_aligned_alloc(8, 100*sizeof(int)); - TEST_CHECK( (ptrdiff_t) d1 % 8 == 0 ); + int *d1 = gkyl_aligned_alloc(8, 100 * sizeof(int)); + TEST_CHECK((ptrdiff_t)d1 % 8 == 0); gkyl_aligned_free(d1); - int *d2 = gkyl_aligned_alloc(16, 100*sizeof(int)); - TEST_CHECK( (ptrdiff_t) d2 % 16 == 0 ); + int *d2 = gkyl_aligned_alloc(16, 100 * sizeof(int)); + TEST_CHECK((ptrdiff_t)d2 % 16 == 0); gkyl_aligned_free(d2); - int *d3 = gkyl_aligned_alloc(32, 100*sizeof(int)); - TEST_CHECK( (ptrdiff_t) d3 % 32 == 0 ); + int *d3 = gkyl_aligned_alloc(32, 100 * sizeof(int)); + TEST_CHECK((ptrdiff_t)d3 % 32 == 0); gkyl_aligned_free(d3); - int *d4 = gkyl_aligned_alloc(64, 100*sizeof(int)); - TEST_CHECK( (ptrdiff_t) d4 % 64 == 0 ); + int *d4 = gkyl_aligned_alloc(64, 100 * sizeof(int)); + TEST_CHECK((ptrdiff_t)d4 % 64 == 0); gkyl_aligned_free(d4); } -void -test_aligned_realloc_ho() +void test_aligned_realloc_ho() { int n = 10; - int *d = gkyl_aligned_alloc(16, n*sizeof(int)); + int *d = gkyl_aligned_alloc(16, n * sizeof(int)); - for (int i=0; i #include - int dev_cu_malloc_array(double **arr, int narr, int nelem); +int dev_cu_malloc_array(double **arr, int narr, int nelem); } -__global__ void -ker_dev_cu_malloc_array(double **arr, int narr, int nelem, int *nfail) +__global__ void ker_dev_cu_malloc_array(double **arr, int narr, int nelem, int *nfail) { *nfail = 0; - for (int k=0; k>>(arr, narr, nelem, nfail_dev); + int *nfail_dev = (int *)gkyl_cu_malloc(sizeof(int)); + ker_dev_cu_malloc_array<<<1, 1> > >(arr, narr, nelem, nfail_dev); int nfail; gkyl_cu_memcpy(&nfail, nfail_dev, sizeof(int), GKYL_CU_MEMCPY_D2H); diff --git a/core/unit/ctest_array.c b/core/unit/ctest_array.c index 9964b2b566..9412cae6f1 100644 --- a/core/unit/ctest_array.c +++ b/core/unit/ctest_array.c @@ -14,9 +14,10 @@ static void set_array_to_zero_ho(struct gkyl_array *arr) { - double *arr_d = arr->data; - for (unsigned i=0; isize; ++i) + double *arr_d = arr->data; + for (unsigned i = 0; i < arr->size; ++i) { arr_d[i] = 0.0; + } } void test_array_0_ho() @@ -29,62 +30,65 @@ void test_array_base_ho() { struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, 1, 200); - TEST_CHECK( gkyl_array_is_using_buffer(arr) == false ); + TEST_CHECK(gkyl_array_is_using_buffer(arr) == false); - TEST_CHECK( arr->type = GKYL_DOUBLE ); - TEST_CHECK( arr->elemsz == sizeof(double) ); - TEST_CHECK( arr->ncomp == 1 ); - TEST_CHECK( arr->size == 20*10 ); - TEST_CHECK( arr->ref_count.count == 1 ); + TEST_CHECK(arr->type = GKYL_DOUBLE); + TEST_CHECK(arr->elemsz == sizeof(double)); + TEST_CHECK(arr->ncomp == 1); + TEST_CHECK(arr->size == 20 * 10); + TEST_CHECK(arr->ref_count.count == 1); - TEST_CHECK( arr->on_dev == arr ); + TEST_CHECK(arr->on_dev == arr); - TEST_CHECK( gkyl_array_is_cu_dev(arr) == false ); + TEST_CHECK(gkyl_array_is_cu_dev(arr) == false); - double *arrData = arr->data; - for (unsigned i=0; isize; ++i){ - TEST_CHECK( arrData[i] == 0. ); - arrData[i] = (i+0.5)*0.1; + double *arrData = arr->data; + for (unsigned i = 0; i < arr->size; ++i) { + TEST_CHECK(arrData[i] == 0.); + arrData[i] = (i + 0.5) * 0.1; } // clone array struct gkyl_array *brr = gkyl_array_clone(arr); - TEST_CHECK( brr->elemsz == sizeof(double) ); - TEST_CHECK( arr->ncomp == 1 ); - TEST_CHECK( brr->size == 20*10 ); - TEST_CHECK( brr->ref_count.count == 1 ); + TEST_CHECK(brr->elemsz == sizeof(double)); + TEST_CHECK(arr->ncomp == 1); + TEST_CHECK(brr->size == 20 * 10); + TEST_CHECK(brr->ref_count.count == 1); - double *brrData = brr->data; - for (unsigned i=0; isize; ++i) - TEST_CHECK( brrData[i] == arrData[i] ); + double *brrData = brr->data; + for (unsigned i = 0; i < brr->size; ++i) { + TEST_CHECK(brrData[i] == arrData[i]); + } // reset values in brr - for (unsigned i=0; isize; ++i) - brrData[i] = (i-0.5)*0.5; + for (unsigned i = 0; i < brr->size; ++i) { + brrData[i] = (i - 0.5) * 0.5; + } gkyl_array_copy(arr, brr); - for (unsigned i=0; isize; ++i) - TEST_CHECK( arrData[i] == brrData[i] ); + for (unsigned i = 0; i < arr->size; ++i) { + TEST_CHECK(arrData[i] == brrData[i]); + } // acquire pointer struct gkyl_array *crr = gkyl_array_acquire(arr); - TEST_CHECK( crr->ref_count.count == 2 ); - TEST_CHECK( arr->ref_count.count == 2 ); + TEST_CHECK(crr->ref_count.count == 2); + TEST_CHECK(arr->ref_count.count == 2); struct gkyl_array *drr = gkyl_array_acquire(crr); - TEST_CHECK( drr->ref_count.count == 3 ); - TEST_CHECK( crr->ref_count.count == 3 ); - TEST_CHECK( arr->ref_count.count == 3 ); - + TEST_CHECK(drr->ref_count.count == 3); + TEST_CHECK(crr->ref_count.count == 3); + TEST_CHECK(arr->ref_count.count == 3); + gkyl_array_release(crr); - TEST_CHECK( arr->ref_count.count == 2 ); + TEST_CHECK(arr->ref_count.count == 2); gkyl_array_release(drr); - TEST_CHECK( arr->ref_count.count == 1 ); - + TEST_CHECK(arr->ref_count.count == 1); + gkyl_array_release(arr); gkyl_array_release(brr); } @@ -93,52 +97,56 @@ void test_array_fetch_ho() { struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, 1, 20); - double *arrData = arr->data; - for (unsigned i=0; isize; ++i) - arrData[i] = (i+0.5)*0.1; + double *arrData = arr->data; + for (unsigned i = 0; i < arr->size; ++i) { + arrData[i] = (i + 0.5) * 0.1; + } double *arrDataLh = gkyl_array_fetch(arr, 0); - TEST_CHECK( arrDataLh[0] == 0.05 ); + TEST_CHECK(arrDataLh[0] == 0.05); double *arrDataUh = gkyl_array_fetch(arr, 10); - TEST_CHECK( arrDataUh[0] == (10+0.5)*0.1); - + TEST_CHECK(arrDataUh[0] == (10 + 0.5) * 0.1); + gkyl_array_release(arr); } void test_array_non_numeric_ho() { - struct euler { double rho, u, E; }; + struct euler { + double rho, u, E; + }; struct gkyl_array *arr = gkyl_array_new(GKYL_USER, sizeof(struct euler), 10); - for (unsigned i=0; isize; ++i) { + for (unsigned i = 0; i < arr->size; ++i) { struct euler *e = gkyl_array_fetch(arr, i); - e->rho = 1.0; e->u = 0.0; e->E = 100.5; + e->rho = 1.0; + e->u = 0.0; + e->E = 100.5; } - + struct gkyl_array *brr = gkyl_array_new(GKYL_USER, sizeof(struct euler), 10); gkyl_array_copy(brr, arr); - for (unsigned i=0; isize; ++i) { + for (unsigned i = 0; i < arr->size; ++i) { struct euler *e = gkyl_array_fetch(brr, i); - TEST_CHECK( e->rho == 1.0 ); - TEST_CHECK( e->u == 0.0 ); - TEST_CHECK( e->E == 100.5 ); - } + TEST_CHECK(e->rho == 1.0); + TEST_CHECK(e->u == 0.0); + TEST_CHECK(e->E == 100.5); + } gkyl_array_release(arr); gkyl_array_release(brr); } -void -test_grid_sub_array_read_1_ho() +void test_grid_sub_array_read_1_ho() { double lower[] = {1.0, 1.0}, upper[] = {2.5, 5.0}; int cells[] = {20, 60}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 2, lower, upper, cells); - int nghost[] = { 1, 2 }; + int nghost[] = {1, 2}; struct gkyl_range range, ext_range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); @@ -152,8 +160,9 @@ test_grid_sub_array_read_1_ho() long loc = gkyl_range_idx(&range, iter.idx); double *d = gkyl_array_fetch(arr, loc); - for (int k=0; k<2; ++k) - d[k] = (10.5*iter.idx[0] + 220.5*iter.idx[1])*(k+0.5); + for (int k = 0; k < 2; ++k) { + d[k] = (10.5 * iter.idx[0] + 220.5 * iter.idx[1]) * (k + 0.5); + } } gkyl_grid_sub_array_write(&grid, &range, 0, arr, "ctest_grid_sub_array_1.gkyl"); @@ -165,78 +174,77 @@ test_grid_sub_array_read_1_ho() // read just header FILE *fp; - with_file(fp, "ctest_grid_sub_array_1.gkyl", "r") { + with_file(fp, "ctest_grid_sub_array_1.gkyl", "r") + { struct gkyl_array_header_info hdr; - + int status = gkyl_grid_sub_array_header_read_fp(&grid2, &hdr, fp); - TEST_CHECK( status == 0 ); + TEST_CHECK(status == 0); - TEST_CHECK( hdr.file_type == 1); - TEST_CHECK( hdr.etype == GKYL_DOUBLE); + TEST_CHECK(hdr.file_type == 1); + TEST_CHECK(hdr.etype == GKYL_DOUBLE); long tot_cells = 1L; - TEST_CHECK( grid.ndim == grid2.ndim ); - for (int d=0; desznc ); - TEST_CHECK( hdr.tot_cells == tot_cells ); + TEST_CHECK(hdr.esznc = arr->esznc); + TEST_CHECK(hdr.tot_cells == tot_cells); - TEST_CHECK( 0 == hdr.meta_size ); - TEST_CHECK( 1 == hdr.nrange ); + TEST_CHECK(0 == hdr.meta_size); + TEST_CHECK(1 == hdr.nrange); } int file_type = gkyl_get_gkyl_file_type("ctest_grid_sub_array_1.gkyl"); - TEST_CHECK( 1 == file_type ); - + TEST_CHECK(1 == file_type); + // read back the grid and the array - int err = - gkyl_grid_sub_array_read(&grid2, &range, arr2, "ctest_grid_sub_array_1.gkyl"); + int err = gkyl_grid_sub_array_read(&grid2, &range, arr2, "ctest_grid_sub_array_1.gkyl"); - TEST_CHECK( err < 1 ); - - if (err < 1) { + TEST_CHECK(err < 1); - TEST_CHECK( grid.ndim == grid2.ndim ); - for (int d=0; dtype == GKYL_DOUBLE ); + TEST_CHECK(arr2->type == GKYL_DOUBLE); - TEST_CHECK( grid.ndim == grid2.ndim ); - for (int d=0; d 0 ); + TEST_CHECK(hdr.meta_size > 0); mpack_tree_t tree; mpack_tree_init_data(&tree, hdr.meta, hdr.meta_size); @@ -392,47 +401,50 @@ test_grid_array_read_p1_ho(void) TEST_CHECK(mpack_node_type(root) == mpack_type_map); mpack_node_t tm_node = mpack_node_map_cstr(root, "time"); - TEST_CHECK( mpack_node_double(tm_node) > 0.80675 ); + TEST_CHECK(mpack_node_double(tm_node) > 0.80675); mpack_node_t fr_node = mpack_node_map_cstr(root, "frame"); - TEST_CHECK( mpack_node_i64(fr_node) == 1 ); + TEST_CHECK(mpack_node_i64(fr_node) == 1); status = mpack_tree_destroy(&tree); - TEST_CHECK( mpack_ok == status ); + TEST_CHECK(mpack_ok == status); gkyl_free(hdr.meta); } - size_t nc = hdr.esznc/gkyl_elem_type_size[hdr.etype]; + size_t nc = hdr.esznc / gkyl_elem_type_size[hdr.etype]; - int nghost[] = { 1, 2 }; + int nghost[] = {1, 2}; struct gkyl_range range, ext_range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); // read serial data for comparison struct gkyl_rect_grid s_grid; struct gkyl_array *s_arr = gkyl_array_new(hdr.etype, nc, ext_range.volume); - int s_status = gkyl_grid_sub_array_read(&s_grid, &range, s_arr, - "core/data/unit/ser-euler_riem_2d_hllc-euler_1.gkyl"); + int s_status = gkyl_grid_sub_array_read( + &s_grid, &range, s_arr, "core/data/unit/ser-euler_riem_2d_hllc-euler_1.gkyl" + ); // read parallel data (whole domain) do { - struct gkyl_rect_grid p_grid; - struct gkyl_array *p_arr = gkyl_array_new(hdr.etype, nc, ext_range.volume); - int p_status = gkyl_grid_sub_array_read(&p_grid, &range, p_arr, - "core/data/unit/euler_riem_2d_hllc-euler_1.gkyl"); + struct gkyl_rect_grid p_grid; + struct gkyl_array *p_arr = gkyl_array_new(hdr.etype, nc, ext_range.volume); + int p_status = gkyl_grid_sub_array_read( + &p_grid, &range, p_arr, "core/data/unit/euler_riem_2d_hllc-euler_1.gkyl" + ); + + TEST_CHECK(0 == p_status); - TEST_CHECK( 0 == p_status ); - struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); const double *s_dat = gkyl_array_fetch(s_arr, loc); const double *p_dat = gkyl_array_fetch(p_arr, loc); - - for (int c=0; ctype = GKYL_DOUBLE ); - TEST_CHECK( arr->elemsz == sizeof(double) ); - TEST_CHECK( arr->ncomp == 1 ); - TEST_CHECK( arr->size == 20*10 ); - TEST_CHECK( arr->ref_count.count == 1 ); + TEST_CHECK(arr->type = GKYL_DOUBLE); + TEST_CHECK(arr->elemsz == sizeof(double)); + TEST_CHECK(arr->ncomp == 1); + TEST_CHECK(arr->size == 20 * 10); + TEST_CHECK(arr->ref_count.count == 1); - TEST_CHECK( arr->on_dev == arr ); + TEST_CHECK(arr->on_dev == arr); - TEST_CHECK( gkyl_array_is_cu_dev(arr) == false ); + TEST_CHECK(gkyl_array_is_cu_dev(arr) == false); set_array_to_zero_ho(arr); - - double *arrData = arr->data; - for (unsigned i=0; isize; ++i){ - TEST_CHECK( arrData[i] == 0. ); - arrData[i] = (i+0.5)*0.1; + + double *arrData = arr->data; + for (unsigned i = 0; i < arr->size; ++i) { + TEST_CHECK(arrData[i] == 0.); + arrData[i] = (i + 0.5) * 0.1; } // clone array struct gkyl_array *brr = gkyl_array_clone(arr); - TEST_CHECK( brr->elemsz == sizeof(double) ); - TEST_CHECK( arr->ncomp == 1 ); - TEST_CHECK( brr->size == 20*10 ); - TEST_CHECK( brr->ref_count.count == 1 ); + TEST_CHECK(brr->elemsz == sizeof(double)); + TEST_CHECK(arr->ncomp == 1); + TEST_CHECK(brr->size == 20 * 10); + TEST_CHECK(brr->ref_count.count == 1); - double *brrData = brr->data; - for (unsigned i=0; isize; ++i) - TEST_CHECK( brrData[i] == arrData[i] ); + double *brrData = brr->data; + for (unsigned i = 0; i < brr->size; ++i) { + TEST_CHECK(brrData[i] == arrData[i]); + } // reset values in brr - for (unsigned i=0; isize; ++i) - brrData[i] = (i-0.5)*0.5; + for (unsigned i = 0; i < brr->size; ++i) { + brrData[i] = (i - 0.5) * 0.5; + } gkyl_array_copy(arr, brr); - for (unsigned i=0; isize; ++i) - TEST_CHECK( arrData[i] == brrData[i] ); + for (unsigned i = 0; i < arr->size; ++i) { + TEST_CHECK(arrData[i] == brrData[i]); + } // acquire pointer struct gkyl_array *crr = gkyl_array_acquire(arr); - TEST_CHECK( crr->ref_count.count == 2 ); - TEST_CHECK( arr->ref_count.count == 2 ); + TEST_CHECK(crr->ref_count.count == 2); + TEST_CHECK(arr->ref_count.count == 2); struct gkyl_array *drr = gkyl_array_acquire(crr); - TEST_CHECK( drr->ref_count.count == 3 ); - TEST_CHECK( crr->ref_count.count == 3 ); - TEST_CHECK( arr->ref_count.count == 3 ); - + TEST_CHECK(drr->ref_count.count == 3); + TEST_CHECK(crr->ref_count.count == 3); + TEST_CHECK(arr->ref_count.count == 3); + gkyl_array_release(crr); - TEST_CHECK( arr->ref_count.count == 2 ); + TEST_CHECK(arr->ref_count.count == 2); gkyl_array_release(drr); - TEST_CHECK( arr->ref_count.count == 1 ); + TEST_CHECK(arr->ref_count.count == 1); gkyl_free(buff); - + gkyl_array_release(arr); gkyl_array_release(brr); } @@ -565,19 +581,19 @@ test_array_from_buff_ho(void) #ifdef GKYL_HAVE_CUDA /* Function signatures of kernel calls */ -int cu_array_test_and_flip_sign( struct gkyl_array *arr); +int cu_array_test_and_flip_sign(struct gkyl_array *arr); void test_array_base_dev() { struct gkyl_array *arr_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, 200); - TEST_CHECK( arr_cu->type = GKYL_DOUBLE ); - TEST_CHECK( arr_cu->elemsz == sizeof(double) ); - TEST_CHECK( arr_cu->ncomp == 1 ); - TEST_CHECK( arr_cu->size == 20*10 ); - TEST_CHECK( arr_cu->ref_count.count == 1 ); + TEST_CHECK(arr_cu->type = GKYL_DOUBLE); + TEST_CHECK(arr_cu->elemsz == sizeof(double)); + TEST_CHECK(arr_cu->ncomp == 1); + TEST_CHECK(arr_cu->size == 20 * 10); + TEST_CHECK(arr_cu->ref_count.count == 1); - TEST_CHECK( gkyl_array_is_cu_dev(arr_cu) == true ); + TEST_CHECK(gkyl_array_is_cu_dev(arr_cu) == true); // create host array and initialize it struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, 1, 200); @@ -585,23 +601,25 @@ void test_array_base_dev() gkyl_array_copy(arr, arr_cu); double *arrData = arr->data; - for (unsigned i=0; isize; ++i) { - TEST_CHECK( arrData[i] == 0. ); - arrData[i] = (i+0.5)*0.1; + for (unsigned i = 0; i < arr->size; ++i) { + TEST_CHECK(arrData[i] == 0.); + arrData[i] = (i + 0.5) * 0.1; } // copy to device gkyl_array_copy(arr_cu, arr); // reset host array - for (unsigned i=0; isize; ++i) + for (unsigned i = 0; i < arr->size; ++i) { arrData[i] = 0.0; + } // copy from device and check if things are ok gkyl_array_copy(arr, arr_cu); - for (unsigned i=0; isize; ++i) - TEST_CHECK( arrData[i] == (i+0.5)*0.1 ); + for (unsigned i = 0; i < arr->size; ++i) { + TEST_CHECK(arrData[i] == (i + 0.5) * 0.1); + } gkyl_array_release(arr); gkyl_array_release(arr_cu); @@ -612,19 +630,20 @@ void test_array_kernel_dev() // create a host array struct containing device data struct gkyl_array *arr_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, 20); - TEST_CHECK( arr_cu->type = GKYL_DOUBLE ); - TEST_CHECK( arr_cu->elemsz == sizeof(double) ); - TEST_CHECK( arr_cu->ncomp == 1 ); - TEST_CHECK( arr_cu->size == 20 ); - TEST_CHECK( arr_cu->ref_count.count == 1 ); - TEST_CHECK( gkyl_array_is_cu_dev(arr_cu) == true ); + TEST_CHECK(arr_cu->type = GKYL_DOUBLE); + TEST_CHECK(arr_cu->elemsz == sizeof(double)); + TEST_CHECK(arr_cu->ncomp == 1); + TEST_CHECK(arr_cu->size == 20); + TEST_CHECK(arr_cu->ref_count.count == 1); + TEST_CHECK(gkyl_array_is_cu_dev(arr_cu) == true); // create host array and initialize it struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, arr_cu->ncomp, arr_cu->size); - double *arrData = arr->data; - for (unsigned i=0; isize; ++i) - arrData[i] = (i+0.5)*0.1; + double *arrData = arr->data; + for (unsigned i = 0; i < arr->size; ++i) { + arrData[i] = (i + 0.5) * 0.1; + } // copy arr data to device data in arr_cu gkyl_array_copy(arr_cu, arr); @@ -634,50 +653,52 @@ void test_array_kernel_dev() // check arr_cu on device and flip sign int nfail = cu_array_test_and_flip_sign(arr_cu->on_dev); - TEST_CHECK( nfail == 0 ); + TEST_CHECK(nfail == 0); // restore arr_cu by copying from arr_cu_cl, and test again gkyl_array_copy(arr_cu, arr_cu_cl); nfail = cu_array_test_and_flip_sign(arr_cu->on_dev); - TEST_CHECK( nfail == 0 ); + TEST_CHECK(nfail == 0); // check arr_cu_cl on device and flip sign nfail = cu_array_test_and_flip_sign(arr_cu_cl->on_dev); - TEST_CHECK( nfail == 0 ); + TEST_CHECK(nfail == 0); // copy arr_cu back to host and check gkyl_array_copy(arr, arr_cu); - for (unsigned i=0; isize; ++i) - TEST_CHECK( arrData[i] == -(i+0.5)*0.1); + for (unsigned i = 0; i < arr->size; ++i) { + TEST_CHECK(arrData[i] == -(i + 0.5) * 0.1); + } // copy arr_cu_cl back to host and check // zero out arr first (no cheating) set_array_to_zero_ho(arr); gkyl_array_copy(arr, arr_cu_cl); - for (unsigned i=0; isize; ++i) - TEST_CHECK( arrData[i] == -(i+0.5)*0.1); + for (unsigned i = 0; i < arr->size; ++i) { + TEST_CHECK(arrData[i] == -(i + 0.5) * 0.1); + } // release all data - gkyl_array_release(arr_cu_cl); + gkyl_array_release(arr_cu_cl); gkyl_array_release(arr); - gkyl_array_release(arr_cu); + gkyl_array_release(arr_cu); } #endif TEST_LIST = { - { "array_0_ho", test_array_0_ho }, - { "array_base_ho", test_array_base_ho }, - { "array_fetch_ho", test_array_fetch_ho }, - { "array_non_numeric_ho", test_array_non_numeric_ho }, - { "grid_sub_array_read_1_ho", test_grid_sub_array_read_1_ho }, - { "grid_sub_array_read_2_ho", test_grid_sub_array_read_2_ho }, - { "grid_array_new_from_file_1_ho", test_grid_array_new_from_file_1_ho }, - { "grid_array_read_p1_ho", test_grid_array_read_p1_ho }, - { "array_from_buff_ho", test_array_from_buff_ho }, + {"array_0_ho", test_array_0_ho}, + {"array_base_ho", test_array_base_ho}, + {"array_fetch_ho", test_array_fetch_ho}, + {"array_non_numeric_ho", test_array_non_numeric_ho}, + {"grid_sub_array_read_1_ho", test_grid_sub_array_read_1_ho}, + {"grid_sub_array_read_2_ho", test_grid_sub_array_read_2_ho}, + {"grid_array_new_from_file_1_ho", test_grid_array_new_from_file_1_ho}, + {"grid_array_read_p1_ho", test_grid_array_read_p1_ho}, + {"array_from_buff_ho", test_array_from_buff_ho}, #ifdef GKYL_HAVE_CUDA - { "array_base_dev", test_array_base_dev }, - { "array_kernel_dev", test_array_kernel_dev }, + {"array_base_dev", test_array_base_dev}, + {"array_kernel_dev", test_array_kernel_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/core/unit/ctest_array_average.c b/core/unit/ctest_array_average.c index 7b00664c95..c95f2841df 100644 --- a/core/unit/ctest_array_average.c +++ b/core/unit/ctest_array_average.c @@ -18,59 +18,64 @@ updater. #include // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size, bool use_gpu) +static struct gkyl_array *mkarr(long nc, long size, bool use_gpu) { - return use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + return use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); } // Compare the computed result with the average computed with another updater. -double solution_array_integrate(struct gkyl_rect_grid grid, struct gkyl_basis basis, - struct gkyl_range local_ext, struct gkyl_range local, struct gkyl_array *win, struct gkyl_array *fin, bool use_gpu) { - - double *avgf_ref = use_gpu? gkyl_cu_malloc(sizeof(double)) : gkyl_malloc(sizeof(double)); +double solution_array_integrate( + struct gkyl_rect_grid grid, struct gkyl_basis basis, struct gkyl_range local_ext, + struct gkyl_range local, struct gkyl_array *win, struct gkyl_array *fin, bool use_gpu +) +{ + double *avgf_ref = use_gpu ? gkyl_cu_malloc(sizeof(double)) : gkyl_malloc(sizeof(double)); - if(win) + if (win) { gkyl_dg_mul_op_range(&basis, 0, fin, 0, win, 0, fin, &local_ext); + } - struct gkyl_array_integrate* arr_integ = gkyl_array_integrate_new(&grid, &basis, 1, GKYL_ARRAY_INTEGRATE_OP_NONE, use_gpu); + struct gkyl_array_integrate *arr_integ = + gkyl_array_integrate_new(&grid, &basis, 1, GKYL_ARRAY_INTEGRATE_OP_NONE, use_gpu); gkyl_array_integrate_advance(arr_integ, fin, 1.0, fin, &local, &local, avgf_ref); gkyl_array_integrate_release(arr_integ); double *avgf_ref_ho = gkyl_malloc(sizeof(double)); - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(avgf_ref_ho, avgf_ref, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(avgf_ref_ho, avgf_ref, sizeof(double)); - + } + double out = avgf_ref_ho[0]; - if(use_gpu) + if (use_gpu) { gkyl_cu_free(avgf_ref); - else + } else { gkyl_free(avgf_ref); + } gkyl_free(avgf_ref_ho); return out; } // test 1x -void evalFunc_1x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double lower[] = {-4.0}, upper[] = {6.0}; // Has to match the test below. - double Lx = upper[0]-lower[0]; - double k_x = 2.*M_PI/Lx; + double Lx = upper[0] - lower[0]; + double k_x = 2. * M_PI / Lx; double phi = 0.5; - fout[0] = x*sin(k_x*x + phi); + fout[0] = x * sin(k_x * x + phi); } -void evalWeight_1x(double t, const double *xn, double* restrict fout, void *ctx) +void evalWeight_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 1+x*x; + fout[0] = 1 + x * x; } // direct weighted averaging x -> avg void test_1x(int poly_order, bool use_gpu) @@ -98,28 +103,30 @@ void test_1x(int poly_order, bool use_gpu) gkyl_cart_modal_serendip(&red_basis, 1, poly_order); // project the target function and weight - gkyl_proj_on_basis *projf = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalFunc_1x, NULL); + gkyl_proj_on_basis *projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_1x, NULL); struct gkyl_array *fx_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *fx_c_ho = use_gpu? mkarr(fx_c->ncomp, fx_c->size, false) : gkyl_array_acquire(fx_c); + struct gkyl_array *fx_c_ho = use_gpu ? mkarr(fx_c->ncomp, fx_c->size, false) : + gkyl_array_acquire(fx_c); gkyl_proj_on_basis_advance(projf, 0.0, &local, fx_c_ho); gkyl_array_copy(fx_c, fx_c_ho); gkyl_proj_on_basis_release(projf); - gkyl_proj_on_basis *projw = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalWeight_1x, NULL); + gkyl_proj_on_basis *projw = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalWeight_1x, NULL); struct gkyl_array *wx_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *wx_c_ho = use_gpu? mkarr(wx_c->ncomp, wx_c->size, false) : gkyl_array_acquire(wx_c); + struct gkyl_array *wx_c_ho = use_gpu ? mkarr(wx_c->ncomp, wx_c->size, false) : + gkyl_array_acquire(wx_c); gkyl_proj_on_basis_advance(projw, 0.0, &local_ext, wx_c_ho); gkyl_array_copy(wx_c, wx_c_ho); gkyl_proj_on_basis_release(projw); // compute weighted average - int avg_dim_x[] = {1,0,0}; + int avg_dim_x[] = {1, 0, 0}; struct gkyl_array_average_inp inp_avg_full = { .grid = &grid, .basis = basis, @@ -139,18 +146,19 @@ void test_1x(int poly_order, bool use_gpu) gkyl_array_average_release(avg_full); // fetch and transfer results - double * avg_c0 = gkyl_array_fetch(avgf_c, 0); + double *avg_c0 = gkyl_array_fetch(avgf_c, 0); double *avg_c0_ho = gkyl_malloc(sizeof(double)); - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(avg_c0_ho, avg_c0, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(avg_c0_ho, avg_c0, sizeof(double)); + } // check results double intf_ref = solution_array_integrate(grid, basis, local_ext, local, wx_c, fx_c, use_gpu); double intw_ref = solution_array_integrate(grid, basis, local_ext, local, NULL, wx_c, use_gpu); - double solution = intf_ref/intw_ref; - double result = avg_c0_ho[0]*0.5*sqrt(2); + double solution = intf_ref / intw_ref; + double result = avg_c0_ho[0] * 0.5 * sqrt(2); double rel_err = fabs(result - solution) / fabs(solution); TEST_CHECK(gkyl_compare(result, solution, 1e-12)); @@ -164,20 +172,20 @@ void test_1x(int poly_order, bool use_gpu) } // tests 2x -void evalFunc_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; double lower[] = {-4., -3.}, upper[] = {6., 5.}; - double Lx = upper[0]-lower[0], Ly = upper[1]-lower[1]; - double k_x = 2.*M_PI/Lx, k_y = 2.*M_PI/Ly; + double Lx = upper[0] - lower[0], Ly = upper[1] - lower[1]; + double k_x = 2. * M_PI / Lx, k_y = 2. * M_PI / Ly; double phi = 0.5; - fout[0] = 1 + sin(k_x*x + k_y*y); - fout[0] = x * y * sin(1.5*k_x*x + 0.75*k_y*y + phi) * cos(1.42*k_y*y); + fout[0] = 1 + sin(k_x * x + k_y * y); + fout[0] = x * y * sin(1.5 * k_x * x + 0.75 * k_y * y + phi) * cos(1.42 * k_y * y); } -void evalWeight_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalWeight_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; - fout[0] = 1 + x*x + y*y; + fout[0] = 1 + x * x + y * y; } // one step weighted averaging x,y -> avg @@ -206,30 +214,32 @@ void test_2x_1step(int poly_order, bool use_gpu) gkyl_cart_modal_serendip(&red_basis, 1, poly_order); // project the target and weight functions - gkyl_proj_on_basis *projf = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalFunc_2x, NULL); + gkyl_proj_on_basis *projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_2x, NULL); struct gkyl_array *fxy_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *fxy_c_ho = use_gpu? mkarr(fxy_c->ncomp, fxy_c->size, false) : gkyl_array_acquire(fxy_c); + struct gkyl_array *fxy_c_ho = use_gpu ? mkarr(fxy_c->ncomp, fxy_c->size, false) : + gkyl_array_acquire(fxy_c); gkyl_proj_on_basis_advance(projf, 0.0, &local_ext, fxy_c_ho); gkyl_array_copy(fxy_c, fxy_c_ho); gkyl_proj_on_basis_release(projf); - gkyl_proj_on_basis *projw = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalWeight_2x, NULL); + gkyl_proj_on_basis *projw = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalWeight_2x, NULL); struct gkyl_array *wxy_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *wxy_c_ho = use_gpu? mkarr(wxy_c->ncomp, wxy_c->size, false) : gkyl_array_acquire(wxy_c); + struct gkyl_array *wxy_c_ho = use_gpu ? mkarr(wxy_c->ncomp, wxy_c->size, false) : + gkyl_array_acquire(wxy_c); gkyl_proj_on_basis_advance(projw, 0.0, &local_ext, wxy_c_ho); gkyl_array_copy(wxy_c, wxy_c_ho); gkyl_proj_on_basis_release(projw); // perform the one step average - int avg_dim_xy[] = {1,1,0}; + int avg_dim_xy[] = {1, 1, 0}; struct gkyl_array_average_inp inp_avg_xy = { .grid = &grid, .basis = basis, @@ -251,16 +261,16 @@ void test_2x_1step(int poly_order, bool use_gpu) // check results double *avgf_c0 = gkyl_array_fetch(avgf_c, 0); double avgf_c0_ho[1]; - if (use_gpu){ + if (use_gpu) { gkyl_cu_memcpy(avgf_c0_ho, avgf_c0, sizeof(double), GKYL_CU_MEMCPY_D2H); - } else{ + } else { memcpy(avgf_c0_ho, avgf_c0, sizeof(double)); } - double result = avgf_c0_ho[0] * sqrt(2)/2; + double result = avgf_c0_ho[0] * sqrt(2) / 2; double intwf_ref = solution_array_integrate(grid, basis, local_ext, local, wxy_c, fxy_c, use_gpu); - double intw_ref = solution_array_integrate(grid, basis, local_ext, local, NULL, wxy_c, use_gpu); - double solution = intwf_ref/intw_ref; + double intw_ref = solution_array_integrate(grid, basis, local_ext, local, NULL, wxy_c, use_gpu); + double solution = intwf_ref / intw_ref; double rel_err = fabs(result - solution) / fabs(solution); TEST_CHECK(gkyl_compare(rel_err, 0, 1e-12)); @@ -287,7 +297,7 @@ void test_2x_intx_inty(int poly_order, bool use_gpu) struct gkyl_rect_grid grid_y; gkyl_rect_grid_init(&grid_y, 1, &lower[1], &upper[1], &cells[1]); - + struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); @@ -296,7 +306,7 @@ void test_2x_intx_inty(int poly_order, bool use_gpu) struct gkyl_basis red_basis; gkyl_cart_modal_serendip(&red_basis, 1, poly_order); - + struct gkyl_range local, local_ext; gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); @@ -308,19 +318,20 @@ void test_2x_intx_inty(int poly_order, bool use_gpu) gkyl_range_init(&red_local, 1, &local.lower[0], &local.lower[0]); gkyl_range_init(&red_local_ext, 1, &local_ext.lower[0], &local_ext.lower[0]); - gkyl_proj_on_basis *projw = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalWeight_2x, NULL); + gkyl_proj_on_basis *projw = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalWeight_2x, NULL); struct gkyl_array *wxy_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *wxy_c_ho = use_gpu? mkarr(wxy_c->ncomp, wxy_c->size, false) : gkyl_array_acquire(wxy_c); + struct gkyl_array *wxy_c_ho = use_gpu ? mkarr(wxy_c->ncomp, wxy_c->size, false) : + gkyl_array_acquire(wxy_c); gkyl_proj_on_basis_advance(projw, 0.0, &local_ext, wxy_c_ho); gkyl_array_copy(wxy_c, wxy_c_ho); gkyl_proj_on_basis_release(projw); // integration over x only, (x,y) to (y) - int int_dim_x[] = {1,0,0}; + int int_dim_x[] = {1, 0, 0}; struct gkyl_array_average_inp inp_int_x = { .grid = &grid, .basis = basis, @@ -340,7 +351,7 @@ void test_2x_intx_inty(int poly_order, bool use_gpu) gkyl_array_average_release(int_x); // integration over remaining dimensions (y) - int int_dim_y[] = {1,0,0}; + int int_dim_y[] = {1, 0, 0}; struct gkyl_array_average_inp inp_int_y = { .grid = &grid_y, .basis = basis_y, @@ -361,17 +372,19 @@ void test_2x_intx_inty(int poly_order, bool use_gpu) // multiply by the volume to get the integral double volume = 1; - for (int d = 0; d < ndim; d++) + for (int d = 0; d < ndim; d++) { volume *= grid.upper[d] - grid.lower[d]; - gkyl_array_scale(intw_c,volume); + } + gkyl_array_scale(intw_c, volume); // retrieve the computed average from the device (if applicable) double *intw_c0 = gkyl_array_fetch(intw_c, 0); double intw_c0_ho[1]; - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(intw_c0_ho, intw_c0, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intw_c0_ho, intw_c0, sizeof(double)); + } double result = intw_c0_ho[0]; @@ -424,29 +437,31 @@ void test_2x_avgx_avgy(int poly_order, bool use_gpu) gkyl_cart_modal_serendip(&red_basis, 1, poly_order); // project the target function and weight - gkyl_proj_on_basis *projf = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalFunc_2x, NULL); + gkyl_proj_on_basis *projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_2x, NULL); struct gkyl_array *fxy_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *fxy_c_ho = use_gpu? mkarr(fxy_c->ncomp, fxy_c->size, false) : gkyl_array_acquire(fxy_c); + struct gkyl_array *fxy_c_ho = use_gpu ? mkarr(fxy_c->ncomp, fxy_c->size, false) : + gkyl_array_acquire(fxy_c); gkyl_proj_on_basis_advance(projf, 0.0, &local_ext, fxy_c_ho); - gkyl_array_copy(fxy_c,fxy_c_ho); + gkyl_array_copy(fxy_c, fxy_c_ho); gkyl_proj_on_basis_release(projf); - gkyl_proj_on_basis *projw = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalWeight_2x, NULL); + gkyl_proj_on_basis *projw = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalWeight_2x, NULL); struct gkyl_array *wxy_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *wxy_c_ho = use_gpu? mkarr(wxy_c->ncomp, wxy_c->size, false) : gkyl_array_acquire(wxy_c); + struct gkyl_array *wxy_c_ho = use_gpu ? mkarr(wxy_c->ncomp, wxy_c->size, false) : + gkyl_array_acquire(wxy_c); gkyl_proj_on_basis_advance(projw, 0.0, &local_ext, wxy_c_ho); - gkyl_array_copy(wxy_c,wxy_c_ho); + gkyl_array_copy(wxy_c, wxy_c_ho); gkyl_proj_on_basis_release(projw); // create and run the array average updater to average on x only - int avg_dim_x[] = {1,0,0}; + int avg_dim_x[] = {1, 0, 0}; struct gkyl_array_average_inp inp_avg_x = { .grid = &grid, .basis = basis, @@ -461,8 +476,11 @@ void test_2x_avgx_avgy(int poly_order, bool use_gpu) struct gkyl_array *fy_c = mkarr(basis_y.num_basis, local_y_ext.volume, use_gpu); struct gkyl_array_average *avg_x = gkyl_array_average_inew(&inp_avg_x); - gkyl_array_average_advance(avg_x, fxy_c, fy_c); // fy_c is DG coeff of int[w(x,y) f(x,y)]dx / int[w(x,y)]dx - + gkyl_array_average_advance( + avg_x, fxy_c, + fy_c + ); // fy_c is DG coeff of int[w(x,y) f(x,y)]dx / int[w(x,y)]dx + gkyl_array_average_release(avg_x); // obtain x integral of the weight too @@ -485,10 +503,13 @@ void test_2x_avgx_avgy(int poly_order, bool use_gpu) gkyl_array_average_release(int_x); // we now remove manually the denominator - gkyl_dg_mul_op_range(&basis_y, 0, fy_c, 0, fy_c, 0, wy_c, &local_y); // fy_c is DG coeff of int[w(x,y) f(x,y)]dx + gkyl_dg_mul_op_range( + &basis_y, 0, fy_c, 0, fy_c, 0, wy_c, + &local_y + ); // fy_c is DG coeff of int[w(x,y) f(x,y)]dx // average over y now - int avg_dim_y[] = {1,0,0}; + int avg_dim_y[] = {1, 0, 0}; struct gkyl_array_average_inp inp_int_y = { .grid = &grid_y, .basis = basis_y, @@ -503,7 +524,10 @@ void test_2x_avgx_avgy(int poly_order, bool use_gpu) struct gkyl_array_average *int_y = gkyl_array_average_inew(&inp_int_y); struct gkyl_array *intf_c = mkarr(red_basis.num_basis, red_local.volume, use_gpu); - gkyl_array_average_advance(int_y, fy_c, intf_c); // intf_c is DG coeff of int[int[w(x,y) f(x,y)]dx]dy + gkyl_array_average_advance( + int_y, fy_c, + intf_c + ); // intf_c is DG coeff of int[int[w(x,y) f(x,y)]dx]dy struct gkyl_array *intw_c = mkarr(red_basis.num_basis, red_local.volume, use_gpu); gkyl_array_average_advance(int_y, wy_c, intw_c); // intw_c is DG coeff of int[int[w(x,y)]dx]dy @@ -511,27 +535,29 @@ void test_2x_avgx_avgy(int poly_order, bool use_gpu) gkyl_array_average_release(int_y); // retrieve the computed average from the device (if applicable) - double *intf_c0 = gkyl_array_fetch(intf_c, 0); + double *intf_c0 = gkyl_array_fetch(intf_c, 0); double intf_c0_ho[1]; - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(intf_c0_ho, intf_c0, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intf_c0_ho, intf_c0, sizeof(double)); + } double *intw_c0 = gkyl_array_fetch(intw_c, 0); double intw_c0_ho[1]; - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(intw_c0_ho, intw_c0, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intw_c0_ho, intw_c0, sizeof(double)); + } double integral_wf = intf_c0_ho[0]; double integral_w = intw_c0_ho[0]; - double result = integral_wf/integral_w; + double result = integral_wf / integral_w; double intwf_ref = solution_array_integrate(grid, basis, local_ext, local, wxy_c, fxy_c, use_gpu); - double intw_ref = solution_array_integrate(grid, basis, local_ext, local, NULL, wxy_c, use_gpu); - double solution = intwf_ref/intw_ref; + double intw_ref = solution_array_integrate(grid, basis, local_ext, local, NULL, wxy_c, use_gpu); + double solution = intwf_ref / intw_ref; double rel_err = fabs(result - solution) / fabs(solution); @@ -587,29 +613,31 @@ void test_2x_avgy_avgx(int poly_order, bool use_gpu) gkyl_cart_modal_serendip(&red_basis, 1, poly_order); // project the target function and weight - gkyl_proj_on_basis *projf = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalFunc_2x, NULL); + gkyl_proj_on_basis *projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_2x, NULL); struct gkyl_array *fxy_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *fxy_c_ho = use_gpu? mkarr(fxy_c->ncomp, fxy_c->size, false) : gkyl_array_acquire(fxy_c); + struct gkyl_array *fxy_c_ho = use_gpu ? mkarr(fxy_c->ncomp, fxy_c->size, false) : + gkyl_array_acquire(fxy_c); gkyl_proj_on_basis_advance(projf, 0.0, &local_ext, fxy_c_ho); - gkyl_array_copy(fxy_c,fxy_c_ho); + gkyl_array_copy(fxy_c, fxy_c_ho); gkyl_proj_on_basis_release(projf); - gkyl_proj_on_basis *projw = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalWeight_2x, NULL); + gkyl_proj_on_basis *projw = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalWeight_2x, NULL); struct gkyl_array *wxy_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *wxy_c_ho = use_gpu? mkarr(wxy_c->ncomp, wxy_c->size, false) : gkyl_array_acquire(wxy_c); + struct gkyl_array *wxy_c_ho = use_gpu ? mkarr(wxy_c->ncomp, wxy_c->size, false) : + gkyl_array_acquire(wxy_c); gkyl_proj_on_basis_advance(projw, 0.0, &local_ext, wxy_c_ho); - gkyl_array_copy(wxy_c,wxy_c_ho); + gkyl_array_copy(wxy_c, wxy_c_ho); gkyl_proj_on_basis_release(projw); // create and run the array average updater to average on y only - int avg_dim_y[] = {0,1,0}; + int avg_dim_y[] = {0, 1, 0}; struct gkyl_array_average_inp inp_avg_x = { .grid = &grid, .basis = basis, @@ -625,7 +653,10 @@ void test_2x_avgy_avgx(int poly_order, bool use_gpu) struct gkyl_array *fx_c = mkarr(basis_x.num_basis, local_x_ext.volume, use_gpu); - gkyl_array_average_advance(avg_x, fxy_c, fx_c); // fx_c is DG coeff of int[w(x,y) f(x,y)]dx / int[w(x,y)]dx + gkyl_array_average_advance( + avg_x, fxy_c, + fx_c + ); // fx_c is DG coeff of int[w(x,y) f(x,y)]dx / int[w(x,y)]dx gkyl_array_average_release(avg_x); @@ -649,10 +680,13 @@ void test_2x_avgy_avgx(int poly_order, bool use_gpu) gkyl_array_average_release(int_x); // we now remove manually the denominator - gkyl_dg_mul_op_range(&basis_x, 0, fx_c, 0, fx_c, 0, wx_c, &local_x); // fx_c is DG coeff of int[w(x,y) f(x,y)]dx + gkyl_dg_mul_op_range( + &basis_x, 0, fx_c, 0, fx_c, 0, wx_c, + &local_x + ); // fx_c is DG coeff of int[w(x,y) f(x,y)]dx // create and run the array average updater to integrate on y - int avg_dim_x[] = {1,0,0}; + int avg_dim_x[] = {1, 0, 0}; struct gkyl_array_average_inp inp_int_y = { .grid = &grid_x, .basis = basis_x, @@ -667,7 +701,10 @@ void test_2x_avgy_avgx(int poly_order, bool use_gpu) struct gkyl_array_average *int_y = gkyl_array_average_inew(&inp_int_y); struct gkyl_array *intf_c = mkarr(red_basis.num_basis, red_local.volume, use_gpu); - gkyl_array_average_advance(int_y, fx_c, intf_c); // intf_c is DG coeff of int[int[w(x,y) f(x,y)]dx]dy + gkyl_array_average_advance( + int_y, fx_c, + intf_c + ); // intf_c is DG coeff of int[int[w(x,y) f(x,y)]dx]dy // obtain full integral of weight too struct gkyl_array *intw_c = mkarr(red_basis.num_basis, red_local.volume, use_gpu); @@ -677,26 +714,28 @@ void test_2x_avgy_avgx(int poly_order, bool use_gpu) // check results two step avg double intf_c0_ho[1]; - double *intf_c0 = gkyl_array_fetch(intf_c, 0); - if (use_gpu) + double *intf_c0 = gkyl_array_fetch(intf_c, 0); + if (use_gpu) { gkyl_cu_memcpy(intf_c0_ho, intf_c0, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intf_c0_ho, intf_c0, sizeof(double)); + } double intw_c0_ho[1]; double *intw_c0 = gkyl_array_fetch(intw_c, 0); - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(intw_c0_ho, intw_c0, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intw_c0_ho, intw_c0, sizeof(double)); + } double integral_wf = intf_c0_ho[0]; double integral_w = intw_c0_ho[0]; - double result = integral_wf/integral_w; + double result = integral_wf / integral_w; double intwf_ref = solution_array_integrate(grid, basis, local_ext, local, wxy_c, fxy_c, use_gpu); - double intw_ref = solution_array_integrate(grid, basis, local_ext, local, NULL, wxy_c, use_gpu); - double solution = intwf_ref/intw_ref; + double intw_ref = solution_array_integrate(grid, basis, local_ext, local, NULL, wxy_c, use_gpu); + double solution = intwf_ref / intw_ref; double rel_err = fabs(result - solution) / fabs(solution); @@ -714,27 +753,28 @@ void test_2x_avgy_avgx(int poly_order, bool use_gpu) } // test 3x -void evalFunc_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_3x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double y = xn[1]; double z = xn[2]; double lower[] = {-4., -3., -2.}, upper[] = {6., 5., 4.}; - double Lx = upper[0]-lower[0]; - double Ly = upper[1]-lower[1]; - double Lz = upper[2]-lower[2]; - double k_x = 2.*M_PI/Lx; - double k_y = 2.*M_PI/Ly; - double k_z = 2.*M_PI/Lz; + double Lx = upper[0] - lower[0]; + double Ly = upper[1] - lower[1]; + double Lz = upper[2] - lower[2]; + double k_x = 2. * M_PI / Lx; + double k_y = 2. * M_PI / Ly; + double k_z = 2. * M_PI / Lz; double phi = 0.5; - fout[0] = x * y * z * sin(1.5*k_x*x + 0.75*k_y*y + 0.5*k_z*z + phi) * cos(1.42*k_y*y) * cos(4.20*k_z*z); + fout[0] = x * y * z * sin(1.5 * k_x * x + 0.75 * k_y * y + 0.5 * k_z * z + phi) * + cos(1.42 * k_y * y) * cos(4.20 * k_z * z); } -void evalWeight_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalWeight_3x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double y = xn[1]; double z = xn[2]; - fout[0] = 1 + x*x + y*y + z*z; + fout[0] = 1 + x * x + y * y + z * z; } // two steps average x,y,z -> y,z -> avg void test_3x_avgx_avgyz(int poly_order, bool use_gpu) @@ -759,7 +799,7 @@ void test_3x_avgx_avgyz(int poly_order, bool use_gpu) struct gkyl_rect_grid grid_yz; double yz_grid_lower[] = {grid.lower[1], grid.lower[2]}; double yz_grid_upper[] = {grid.upper[1], grid.upper[2]}; - int yz_grid_cells[] = {grid.cells[1], grid.cells[2]}; + int yz_grid_cells[] = {grid.cells[1], grid.cells[2]}; gkyl_rect_grid_init(&grid_yz, 2, yz_grid_lower, yz_grid_upper, yz_grid_cells); struct gkyl_range local_yz, local_yz_ext; @@ -778,28 +818,30 @@ void test_3x_avgx_avgyz(int poly_order, bool use_gpu) gkyl_cart_modal_serendip(&red_basis, 1, poly_order); // project the target function and weight - gkyl_proj_on_basis *projf = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalFunc_3x, NULL); + gkyl_proj_on_basis *projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_3x, NULL); struct gkyl_array *fxyz_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *fxyz_c_ho = use_gpu? mkarr(fxyz_c->ncomp, fxyz_c->size, false) : gkyl_array_acquire(fxyz_c); + struct gkyl_array *fxyz_c_ho = use_gpu ? mkarr(fxyz_c->ncomp, fxyz_c->size, false) : + gkyl_array_acquire(fxyz_c); gkyl_proj_on_basis_advance(projf, 0.0, &local_ext, fxyz_c_ho); - gkyl_array_copy(fxyz_c,fxyz_c_ho); + gkyl_array_copy(fxyz_c, fxyz_c_ho); gkyl_proj_on_basis_release(projf); - gkyl_proj_on_basis *projw = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalWeight_3x, NULL); + gkyl_proj_on_basis *projw = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalWeight_3x, NULL); struct gkyl_array *wxyz_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *wxyz_c_ho = use_gpu? mkarr(wxyz_c->ncomp, wxyz_c->size, false) : gkyl_array_acquire(wxyz_c); + struct gkyl_array *wxyz_c_ho = use_gpu ? mkarr(wxyz_c->ncomp, wxyz_c->size, false) : + gkyl_array_acquire(wxyz_c); gkyl_proj_on_basis_advance(projw, 0.0, &local_ext, wxyz_c_ho); - gkyl_array_copy(wxyz_c,wxyz_c_ho); + gkyl_array_copy(wxyz_c, wxyz_c_ho); gkyl_proj_on_basis_release(projw); // create and run the array average updater to average on x only - int avg_dim_x[] = {1,0,0}; + int avg_dim_x[] = {1, 0, 0}; struct gkyl_array_average_inp inp_avg_xyz_to_yz = { .grid = &grid, .basis = basis, @@ -814,7 +856,9 @@ void test_3x_avgx_avgyz(int poly_order, bool use_gpu) struct gkyl_array_average *avg_xyz_to_yz = gkyl_array_average_inew(&inp_avg_xyz_to_yz); struct gkyl_array *fyz_c = mkarr(basis_yz.num_basis, local_yz_ext.volume, use_gpu); - gkyl_array_average_advance(avg_xyz_to_yz, fxyz_c, fyz_c); // fy_c is DG coeff of int[w(x,y,z) f(x,y,z)]dx / int[w(x,y,z)]dx + gkyl_array_average_advance( + avg_xyz_to_yz, fxyz_c, fyz_c + ); // fy_c is DG coeff of int[w(x,y,z) f(x,y,z)]dx / int[w(x,y,z)]dx gkyl_array_average_release(avg_xyz_to_yz); // obtain x integral of the weight too @@ -836,10 +880,13 @@ void test_3x_avgx_avgyz(int poly_order, bool use_gpu) gkyl_array_average_release(int_xyz_to_yz); // we now remove manually the denominator - gkyl_dg_mul_op_range(&basis_yz, 0, fyz_c, 0, fyz_c, 0, wyz_c, &local_yz); // fy_c is DG coeff of int[w(x,y) f(x,y)]dy + gkyl_dg_mul_op_range( + &basis_yz, 0, fyz_c, 0, fyz_c, 0, wyz_c, + &local_yz + ); // fy_c is DG coeff of int[w(x,y) f(x,y)]dy // create and run the array average updater to average on y and z (first second dim) - int avg_dim_yz[] = {1,1,0}; + int avg_dim_yz[] = {1, 1, 0}; struct gkyl_array_average_inp inp_int_yz = { .grid = &grid_yz, .basis = basis_yz, @@ -854,7 +901,10 @@ void test_3x_avgx_avgyz(int poly_order, bool use_gpu) struct gkyl_array_average *int_yz = gkyl_array_average_inew(&inp_int_yz); struct gkyl_array *intf_c = mkarr(red_basis.num_basis, red_local.volume, use_gpu); - gkyl_array_average_advance(int_yz, fyz_c, intf_c); // intf_c is DG coeff of int[int[w(x,y) f(x,y)]dy]dx + gkyl_array_average_advance( + int_yz, fyz_c, + intf_c + ); // intf_c is DG coeff of int[int[w(x,y) f(x,y)]dy]dx // obtain full integral of weight too struct gkyl_array *intw_c = mkarr(red_basis.num_basis, red_local.volume, use_gpu); @@ -863,27 +913,30 @@ void test_3x_avgx_avgyz(int poly_order, bool use_gpu) gkyl_array_average_release(int_yz); // check results - double *intf_c0 = gkyl_array_fetch(intf_c, 0); + double *intf_c0 = gkyl_array_fetch(intf_c, 0); double *intf_c0_ho = gkyl_malloc(sizeof(double)); - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(intf_c0_ho, intf_c0, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intf_c0_ho, intf_c0, sizeof(double)); + } double *intw_c0 = gkyl_array_fetch(intw_c, 0); double *intw_c0_ho = gkyl_malloc(sizeof(double)); - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(intw_c0_ho, intw_c0, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intw_c0_ho, intw_c0, sizeof(double)); + } double integral_wf = intf_c0_ho[0]; double integral_w = intw_c0_ho[0]; - double result = integral_wf/integral_w; + double result = integral_wf / integral_w; - double intwf_ref = solution_array_integrate(grid, basis, local_ext, local, wxyz_c, fxyz_c, use_gpu); - double intw_ref = solution_array_integrate(grid, basis, local_ext, local, NULL, wxyz_c, use_gpu); - double solution = intwf_ref/intw_ref; + double intwf_ref = + solution_array_integrate(grid, basis, local_ext, local, wxyz_c, fxyz_c, use_gpu); + double intw_ref = solution_array_integrate(grid, basis, local_ext, local, NULL, wxyz_c, use_gpu); + double solution = intwf_ref / intw_ref; double rel_err = fabs(result - solution) / fabs(solution); @@ -940,29 +993,30 @@ void test_3x_avgyz_avgx(int poly_order, bool use_gpu) gkyl_cart_modal_serendip(&red_basis, 1, poly_order); // project the target function and weight - gkyl_proj_on_basis *projf = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalFunc_3x, NULL); + gkyl_proj_on_basis *projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_3x, NULL); struct gkyl_array *fxyz_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *fxyz_c_ho = use_gpu? mkarr(fxyz_c->ncomp, fxyz_c->size, false) : gkyl_array_acquire(fxyz_c); + struct gkyl_array *fxyz_c_ho = use_gpu ? mkarr(fxyz_c->ncomp, fxyz_c->size, false) : + gkyl_array_acquire(fxyz_c); gkyl_proj_on_basis_advance(projf, 0.0, &local_ext, fxyz_c_ho); - gkyl_array_copy(fxyz_c,fxyz_c_ho); + gkyl_array_copy(fxyz_c, fxyz_c_ho); gkyl_proj_on_basis_release(projf); - gkyl_proj_on_basis *projw = gkyl_proj_on_basis_new( - &grid, &basis, poly_order + 1, 1, evalWeight_3x, NULL); + gkyl_proj_on_basis *projw = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalWeight_3x, NULL); struct gkyl_array *wxyz_c = mkarr(basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *wxyz_c_ho = use_gpu? mkarr(wxyz_c->ncomp, wxyz_c->size, false) : gkyl_array_acquire(wxyz_c); + struct gkyl_array *wxyz_c_ho = use_gpu ? mkarr(wxyz_c->ncomp, wxyz_c->size, false) : + gkyl_array_acquire(wxyz_c); gkyl_proj_on_basis_advance(projw, 0.0, &local_ext, wxyz_c_ho); - gkyl_array_copy(wxyz_c,wxyz_c_ho); + gkyl_array_copy(wxyz_c, wxyz_c_ho); gkyl_proj_on_basis_release(projw); - // create and run the array average updater to average y and z - int avg_dim_yz[] = {0,1,1}; + int avg_dim_yz[] = {0, 1, 1}; struct gkyl_array_average_inp inp_avg_xyz_to_x = { .grid = &grid, .basis = basis, @@ -977,7 +1031,7 @@ void test_3x_avgyz_avgx(int poly_order, bool use_gpu) struct gkyl_array_average *avg_xyz_to_x = gkyl_array_average_inew(&inp_avg_xyz_to_x); struct gkyl_array *fx_c = mkarr(basis_x.num_basis, local_x_ext.volume, use_gpu); - gkyl_array_average_advance(avg_xyz_to_x, fxyz_c, fx_c); // + gkyl_array_average_advance(avg_xyz_to_x, fxyz_c, fx_c); // gkyl_array_average_release(avg_xyz_to_x); @@ -1001,10 +1055,13 @@ void test_3x_avgyz_avgx(int poly_order, bool use_gpu) gkyl_array_average_release(int_xyz_to_x); // remove manually the denominator - gkyl_dg_mul_op_range(&basis_x, 0, fx_c, 0, fx_c, 0, wx_c, &local_x); // fy_c is DG coeff of int[w(x,y) f(x,y)]dy + gkyl_dg_mul_op_range( + &basis_x, 0, fx_c, 0, fx_c, 0, wx_c, + &local_x + ); // fy_c is DG coeff of int[w(x,y) f(x,y)]dy // create and run the array average updater to average on x - int avg_dim_x[] = {1,0,0}; + int avg_dim_x[] = {1, 0, 0}; struct gkyl_array_average_inp inp_int_x = { .grid = &grid_x, .basis = basis_x, @@ -1019,36 +1076,45 @@ void test_3x_avgyz_avgx(int poly_order, bool use_gpu) struct gkyl_array_average *int_x = gkyl_array_average_inew(&inp_int_x); struct gkyl_array *intf_c = mkarr(red_basis.num_basis, red_local.volume, use_gpu); - gkyl_array_average_advance(int_x, fx_c, intf_c); // intf_c is DG coeff of int[int[int[w(x,y) f(x,y)]dy]dz]dx + gkyl_array_average_advance( + int_x, fx_c, + intf_c + ); // intf_c is DG coeff of int[int[int[w(x,y) f(x,y)]dy]dz]dx // obtain full integral of weight too struct gkyl_array *intw_c = mkarr(red_basis.num_basis, red_local.volume, use_gpu); - gkyl_array_average_advance(int_x, wx_c, intw_c); // intw_c is DG coeff of int[int[int[w(x,y)]dy]dz]dx + gkyl_array_average_advance( + int_x, wx_c, + intw_c + ); // intw_c is DG coeff of int[int[int[w(x,y)]dy]dz]dx gkyl_array_average_release(int_x); // check results two step avg - double *intf_c0 = gkyl_array_fetch(intf_c, 0); + double *intf_c0 = gkyl_array_fetch(intf_c, 0); double *intf_c0_ho = gkyl_malloc(sizeof(double)); - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(intf_c0_ho, intf_c0, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intf_c0_ho, intf_c0, sizeof(double)); + } double *intw_c0 = gkyl_array_fetch(intw_c, 0); double *intw_c0_ho = gkyl_malloc(sizeof(double)); - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(intw_c0_ho, intw_c0, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intw_c0_ho, intw_c0, sizeof(double)); + } double integral_wf = intf_c0_ho[0]; double integral_w = intw_c0_ho[0]; - double result = integral_wf/integral_w; + double result = integral_wf / integral_w; - double intwf_ref = solution_array_integrate(grid, basis, local_ext, local, wxyz_c, fxyz_c, use_gpu); - double intw_ref = solution_array_integrate(grid, basis, local_ext, local, NULL, wxyz_c, use_gpu); - double solution = intwf_ref/intw_ref; + double intwf_ref = + solution_array_integrate(grid, basis, local_ext, local, wxyz_c, fxyz_c, use_gpu); + double intw_ref = solution_array_integrate(grid, basis, local_ext, local, NULL, wxyz_c, use_gpu); + double solution = intwf_ref / intw_ref; double rel_err = fabs(result - solution) / fabs(solution); @@ -1069,13 +1135,14 @@ void test_3x_avgyz_avgx(int poly_order, bool use_gpu) void test_array_average_1x_ho() { - for (int p = 1; p<=2; p++) - test_1x(p, false); + for (int p = 1; p <= 2; p++) { + test_1x(p, false); + } } void test_array_average_2x_ho() { - for (int p = 1; p<=2; p++) { + for (int p = 1; p <= 2; p++) { test_2x_1step(p, false); test_2x_intx_inty(p, false); test_2x_avgx_avgy(p, false); @@ -1085,7 +1152,7 @@ void test_array_average_2x_ho() void test_array_average_3x_ho() { - for (int p = 1; p<=2; p++) { + for (int p = 1; p <= 2; p++) { test_3x_avgx_avgyz(p, false); test_3x_avgyz_avgx(p, false); } @@ -1094,13 +1161,14 @@ void test_array_average_3x_ho() #ifdef GKYL_HAVE_CUDA void test_array_average_1x_dev() { - for (int p = 1; p<=2; p++) - test_1x(p, true); + for (int p = 1; p <= 2; p++) { + test_1x(p, true); + } } void test_array_average_2x_dev() { - for (int p = 1; p<=2; p++) { + for (int p = 1; p <= 2; p++) { test_2x_1step(p, true); test_2x_intx_inty(p, true); test_2x_avgx_avgy(p, true); @@ -1110,7 +1178,7 @@ void test_array_average_2x_dev() void test_array_average_3x_dev() { - for (int p = 1; p<=2; p++) { + for (int p = 1; p <= 2; p++) { test_3x_avgx_avgyz(p, true); test_3x_avgyz_avgx(p, true); } @@ -1119,13 +1187,13 @@ void test_array_average_3x_dev() #endif TEST_LIST = { - { "test_array_average_1x_ho", test_array_average_1x_ho }, - { "test_array_average_2x_ho", test_array_average_2x_ho }, - { "test_array_average_3x_ho", test_array_average_3x_ho }, + {"test_array_average_1x_ho", test_array_average_1x_ho}, + {"test_array_average_2x_ho", test_array_average_2x_ho}, + {"test_array_average_3x_ho", test_array_average_3x_ho}, #ifdef GKYL_HAVE_CUDA - { "test_array_average_1x_dev", test_array_average_1x_dev }, - { "test_array_average_2x_dev", test_array_average_2x_dev }, - { "test_array_average_3x_dev", test_array_average_3x_dev }, + {"test_array_average_1x_dev", test_array_average_1x_dev}, + {"test_array_average_2x_dev", test_array_average_2x_dev}, + {"test_array_average_3x_dev", test_array_average_3x_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/core/unit/ctest_array_cu.cu b/core/unit/ctest_array_cu.cu index 0c59425f64..8b4ec4f7fc 100644 --- a/core/unit/ctest_array_cu.cu +++ b/core/unit/ctest_array_cu.cu @@ -6,46 +6,43 @@ extern "C" { #include #include #include - int cu_array_test_and_flip_sign( struct gkyl_array *arr); - void set_array_copy_fn(struct gkyl_array_copy_func *fn); +int cu_array_test_and_flip_sign(struct gkyl_array *arr); +void set_array_copy_fn(struct gkyl_array_copy_func *fn); } -GKYL_CU_DH static void -buffer_fn_cu(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_DH static void buffer_fn_cu(size_t nc, double *out, const double *inp, void *ctx) { - for (size_t i=0; itype == GKYL_DOUBLE, nfail ); - GKYL_CU_CHECK( arr->elemsz ==sizeof(double), nfail ); - GKYL_CU_CHECK( arr->ncomp == 1, nfail ); - GKYL_CU_CHECK( arr->size == 20, nfail ); - - double *data = (double *) arr->data; - for (unsigned i=0; isize; ++i) { - GKYL_CU_CHECK( data[i] == (i+0.5)*0.1, nfail ); + + GKYL_CU_CHECK(arr->type == GKYL_DOUBLE, nfail); + GKYL_CU_CHECK(arr->elemsz == sizeof(double), nfail); + GKYL_CU_CHECK(arr->ncomp == 1, nfail); + GKYL_CU_CHECK(arr->size == 20, nfail); + + double *data = (double *)arr->data; + for (unsigned i = 0; i < arr->size; ++i) { + GKYL_CU_CHECK(data[i] == (i + 0.5) * 0.1, nfail); data[i] *= -1; } } -__global__ void -ker_set_array_copy_fn(struct gkyl_array_copy_func *fn) +__global__ void ker_set_array_copy_fn(struct gkyl_array_copy_func *fn) { fn->func = buffer_fn_cu; fn->ctx = 0; } -int -cu_array_test_and_flip_sign( struct gkyl_array *arr) +int cu_array_test_and_flip_sign(struct gkyl_array *arr) { - int *nfail_dev = (int *) gkyl_cu_malloc(sizeof(int)); - ker_cu_array_test_and_flip_sign<<<1,1>>>(arr, nfail_dev); + int *nfail_dev = (int *)gkyl_cu_malloc(sizeof(int)); + ker_cu_array_test_and_flip_sign<<<1, 1> > >(arr, nfail_dev); int nfail; gkyl_cu_memcpy(&nfail, nfail_dev, sizeof(int), GKYL_CU_MEMCPY_D2H); @@ -54,8 +51,7 @@ cu_array_test_and_flip_sign( struct gkyl_array *arr) return nfail; } -void -set_array_copy_fn(struct gkyl_array_copy_func *fn) +void set_array_copy_fn(struct gkyl_array_copy_func *fn) { - ker_set_array_copy_fn<<<1,1>>>(fn); + ker_set_array_copy_fn<<<1, 1> > >(fn); } diff --git a/core/unit/ctest_array_dg_reduce.c b/core/unit/ctest_array_dg_reduce.c index 29702389e2..f9a0017d1e 100644 --- a/core/unit/ctest_array_dg_reduce.c +++ b/core/unit/ctest_array_dg_reduce.c @@ -16,14 +16,13 @@ void test_reduce_dg(bool use_gpu) double lower[] = {-M_PI}, upper[] = {M_PI}; int cells[] = {20}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); struct gkyl_basis *basis; if (use_gpu) { basis = gkyl_cu_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_serendip_cu_dev(basis, ndim, poly_order); - } - else { + } else { basis = gkyl_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_serendip(basis, ndim, poly_order); } @@ -34,22 +33,28 @@ void test_reduce_dg(bool use_gpu) gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); int ghost[ndim]; - for (int d=0; dncomp, arr->size) : gkyl_array_acquire(arr); + struct gkyl_array *arr = + use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, ncomp * basis_ho.num_basis, local_ext.volume) : + gkyl_array_new(GKYL_DOUBLE, ncomp * basis_ho.num_basis, local_ext.volume); + struct gkyl_array *arr_ho = use_gpu ? gkyl_array_new(GKYL_DOUBLE, arr->ncomp, arr->size) : + gkyl_array_acquire(arr); // Load 1D Gauss-Legendre nodes. - int num_quad = poly_order+1; + int num_quad = poly_order + 1; double ordinates1[num_quad]; memcpy(ordinates1, gkyl_gauss_ordinates[num_quad], sizeof(double[num_quad])); // Create range to loop over nodes. int qshape[GKYL_MAX_DIM]; - for (int i=0; isize; ++i) { - + for (size_t i = 0; i < arr->size; ++i) { double *arr_c = gkyl_array_fetch(arr_ho, i); int idx[GKYL_MAX_DIM]; @@ -84,23 +89,27 @@ void test_reduce_dg(bool use_gpu) double xc[GKYL_MAX_DIM]; gkyl_rect_grid_cell_center(&grid, idx, xc); - for (int ci=0; cincomp, arr->size) : gkyl_array_acquire(arr); - + struct gkyl_array *arr = + use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, ncomp * basis_ho.num_basis, local_ext.volume) : + gkyl_array_new(GKYL_DOUBLE, ncomp * basis_ho.num_basis, local_ext.volume); + struct gkyl_array *arr_ho = use_gpu ? gkyl_array_new(GKYL_DOUBLE, arr->ncomp, arr->size) : + gkyl_array_acquire(arr); // Load 1D Gauss-Legendre nodes. - int num_quad = poly_order+1; + int num_quad = poly_order + 1; double ordinates1[num_quad]; memcpy(ordinates1, gkyl_gauss_ordinates[num_quad], sizeof(double[num_quad])); // Create range to loop over nodes. int qshape[GKYL_MAX_DIM]; - for (int i=0; i // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size, bool use_gpu) +static struct gkyl_array *mkarr(long nc, long size, bool use_gpu) { - struct gkyl_array *a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -void evalFunc_1x_nc1_op_none(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_1x_nc1_op_none(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double lower[] = {-6.0}, upper[] = {6.0}; // Has to match the test below. - fout[0] = 1./(upper[0]-lower[0]); + fout[0] = 1. / (upper[0] - lower[0]); } -void evalFunc_1x_nc1_op_sq(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_1x_nc1_op_sq(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double lower[] = {-6.0}, upper[] = {6.0}; // Has to match the test below. - fout[0] = 1./sqrt(upper[0]-lower[0]); + fout[0] = 1. / sqrt(upper[0] - lower[0]); } void test_1x_nc1_op(enum gkyl_array_integrate_op integ_op, int poly_order, bool use_gpu) { double lower[] = {-6.0}, upper[] = {6.0}; int cells[] = {16}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int nc = 1; // grids @@ -50,78 +49,87 @@ void test_1x_nc1_op(enum gkyl_array_integrate_op integ_op, int poly_order, bool struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); - int ghost[] = { 1 }; + int ghost[] = {1}; struct gkyl_range local, local_ext; // local, local-ext ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // projection updater for dist-function gkyl_proj_on_basis *projf; - if (integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ) - projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, nc, evalFunc_1x_nc1_op_sq, NULL); - else - projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, nc, evalFunc_1x_nc1_op_none, NULL); + if (integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ) { + projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, nc, evalFunc_1x_nc1_op_sq, NULL); + } else { + projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, nc, evalFunc_1x_nc1_op_none, NULL); + } // create distribution function array - struct gkyl_array *distf = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *distf_ho = use_gpu? mkarr(nc*basis.num_basis, local_ext.volume, false) : distf; + struct gkyl_array *distf = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); + struct gkyl_array *distf_ho = use_gpu ? mkarr(nc * basis.num_basis, local_ext.volume, false) : + distf; // project distribution function on basis gkyl_proj_on_basis_advance(projf, 0.0, &local, distf_ho); - if (use_gpu) gkyl_array_copy(distf, distf_ho); + if (use_gpu) { + gkyl_array_copy(distf, distf_ho); + } - if (integ_op == GKYL_ARRAY_INTEGRATE_OP_ABS) + if (integ_op == GKYL_ARRAY_INTEGRATE_OP_ABS) { gkyl_array_scale(distf, -1.); + } // integrate distribution function. - struct gkyl_array_integrate *integ_up = gkyl_array_integrate_new(&grid, &basis, nc, integ_op, use_gpu); + struct gkyl_array_integrate *integ_up = + gkyl_array_integrate_new(&grid, &basis, nc, integ_op, use_gpu); - double *fint = use_gpu? gkyl_cu_malloc(nc*sizeof(double)) : gkyl_malloc(nc*sizeof(double)); - struct gkyl_array *weight = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); + double *fint = use_gpu ? gkyl_cu_malloc(nc * sizeof(double)) : gkyl_malloc(nc * sizeof(double)); + struct gkyl_array *weight = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); gkyl_array_integrate_advance(integ_up, distf, 1., weight, &local, &local, fint); gkyl_array_integrate_release(integ_up); - double *fint_ho = gkyl_malloc(nc*sizeof(double)); - if (use_gpu) - gkyl_cu_memcpy(fint_ho, fint, nc*sizeof(double), GKYL_CU_MEMCPY_D2H); - else - memcpy(fint_ho, fint, nc*sizeof(double)); + double *fint_ho = gkyl_malloc(nc * sizeof(double)); + if (use_gpu) { + gkyl_cu_memcpy(fint_ho, fint, nc * sizeof(double), GKYL_CU_MEMCPY_D2H); + } else { + memcpy(fint_ho, fint, nc * sizeof(double)); + } - TEST_CHECK( gkyl_compare( 1.0, fint_ho[0], 1e-12) ); + TEST_CHECK(gkyl_compare(1.0, fint_ho[0], 1e-12)); gkyl_array_release(distf); gkyl_array_release(weight); gkyl_proj_on_basis_release(projf); gkyl_free(fint_ho); - if (use_gpu) + if (use_gpu) { gkyl_cu_free(fint); - else + } else { gkyl_free(fint); + } } -void evalFunc_1x_nc3_op_none(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_1x_nc3_op_none(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double lower[] = {-6.0}, upper[] = {6.0}; // Has to match the test below. - fout[0] = 1./(upper[0]-lower[0]); - fout[1] = 1.5/(upper[0]-lower[0]); - fout[2] = 2.5/(upper[0]-lower[0]); + fout[0] = 1. / (upper[0] - lower[0]); + fout[1] = 1.5 / (upper[0] - lower[0]); + fout[2] = 2.5 / (upper[0] - lower[0]); } -void evalFunc_1x_nc3_op_sq(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_1x_nc3_op_sq(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double lower[] = {-6.0}, upper[] = {6.0}; // Has to match the test below. - fout[0] = 1./sqrt(upper[0]-lower[0]); - fout[1] = 1.5/sqrt(upper[0]-lower[0]); - fout[2] = 2.5/sqrt(upper[0]-lower[0]); + fout[0] = 1. / sqrt(upper[0] - lower[0]); + fout[1] = 1.5 / sqrt(upper[0] - lower[0]); + fout[2] = 2.5 / sqrt(upper[0] - lower[0]); } void test_1x_nc3_op(enum gkyl_array_integrate_op integ_op, int poly_order, bool use_gpu) { double lower[] = {-6.0}, upper[] = {6.0}; int cells[] = {16}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int nc = 3; // grids @@ -132,76 +140,89 @@ void test_1x_nc3_op(enum gkyl_array_integrate_op integ_op, int poly_order, bool struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); - int ghost[] = { 1 }; + int ghost[] = {1}; struct gkyl_range local, local_ext; // local, local-ext ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // projection updater for dist-function gkyl_proj_on_basis *projf; - if (integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ) - projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, nc, evalFunc_1x_nc3_op_sq, NULL); - else - projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, nc, evalFunc_1x_nc3_op_none, NULL); + if (integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ) { + projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, nc, evalFunc_1x_nc3_op_sq, NULL); + } else { + projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, nc, evalFunc_1x_nc3_op_none, NULL); + } // create distribution function array - struct gkyl_array *distf = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *distf_ho = use_gpu? mkarr(nc*basis.num_basis, local_ext.volume, false) : distf; + struct gkyl_array *distf = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); + struct gkyl_array *distf_ho = use_gpu ? mkarr(nc * basis.num_basis, local_ext.volume, false) : + distf; // project distribution function on basis gkyl_proj_on_basis_advance(projf, 0.0, &local, distf_ho); - if (use_gpu) gkyl_array_copy(distf, distf_ho); + if (use_gpu) { + gkyl_array_copy(distf, distf_ho); + } - if (integ_op == GKYL_ARRAY_INTEGRATE_OP_ABS) + if (integ_op == GKYL_ARRAY_INTEGRATE_OP_ABS) { gkyl_array_scale(distf, -1.); + } // integrate distribution function. - struct gkyl_array_integrate *integ_up = gkyl_array_integrate_new(&grid, &basis, nc, integ_op, use_gpu); + struct gkyl_array_integrate *integ_up = + gkyl_array_integrate_new(&grid, &basis, nc, integ_op, use_gpu); - double *fint = use_gpu? gkyl_cu_malloc(nc*sizeof(double)) : gkyl_malloc(nc*sizeof(double)); - struct gkyl_array *weight = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); + double *fint = use_gpu ? gkyl_cu_malloc(nc * sizeof(double)) : gkyl_malloc(nc * sizeof(double)); + struct gkyl_array *weight = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); gkyl_array_integrate_advance(integ_up, distf, 1., weight, &local, &local, fint); gkyl_array_integrate_release(integ_up); - double *fint_ho = gkyl_malloc(nc*sizeof(double)); - if (use_gpu) - gkyl_cu_memcpy(fint_ho, fint, nc*sizeof(double), GKYL_CU_MEMCPY_D2H); - else - memcpy(fint_ho, fint, nc*sizeof(double)); - - TEST_CHECK( gkyl_compare( 1.0, fint_ho[0], 1e-12) ); - TEST_CHECK( gkyl_compare( integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ? 1.5*1.5 : 1.5, fint_ho[1], 1e-12) ); - TEST_CHECK( gkyl_compare( integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ? 2.5*2.5 : 2.5, fint_ho[2], 1e-12) ); + double *fint_ho = gkyl_malloc(nc * sizeof(double)); + if (use_gpu) { + gkyl_cu_memcpy(fint_ho, fint, nc * sizeof(double), GKYL_CU_MEMCPY_D2H); + } else { + memcpy(fint_ho, fint, nc * sizeof(double)); + } + + TEST_CHECK(gkyl_compare(1.0, fint_ho[0], 1e-12)); + TEST_CHECK( + gkyl_compare(integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ ? 1.5 * 1.5 : 1.5, fint_ho[1], 1e-12) + ); + TEST_CHECK( + gkyl_compare(integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ ? 2.5 * 2.5 : 2.5, fint_ho[2], 1e-12) + ); gkyl_array_release(distf); gkyl_array_release(weight); gkyl_proj_on_basis_release(projf); gkyl_free(fint_ho); - if (use_gpu) + if (use_gpu) { gkyl_cu_free(fint); - else + } else { gkyl_free(fint); + } } -void evalFunc_2x_nc1_op_none(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_2x_nc1_op_none(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double lower[] = {0., -6.0}, upper[] = {2., 6.0}; // Has to match the test below. - fout[0] = 1./((upper[0]-lower[0])*(upper[1]-lower[1])); + fout[0] = 1. / ((upper[0] - lower[0]) * (upper[1] - lower[1])); } -void evalFunc_2x_nc1_op_sq(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_2x_nc1_op_sq(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double lower[] = {0., -6.0}, upper[] = {2., 6.0}; // Has to match the test below. - fout[0] = 1./sqrt((upper[0]-lower[0])*(upper[1]-lower[1])); + fout[0] = 1. / sqrt((upper[0] - lower[0]) * (upper[1] - lower[1])); } void test_2x_nc1_op(enum gkyl_array_integrate_op integ_op, int poly_order, bool use_gpu) { double lower[] = {0., -6.0}, upper[] = {2., 6.0}; int cells[] = {6, 16}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int nc = 1; // grids @@ -212,79 +233,90 @@ void test_2x_nc1_op(enum gkyl_array_integrate_op integ_op, int poly_order, bool struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); - int ghost[] = { 1, 0 }; + int ghost[] = {1, 0}; struct gkyl_range local, local_ext; // local, local-ext ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // projection updater for dist-function gkyl_proj_on_basis *projf; - if (integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ) - projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, nc, evalFunc_2x_nc1_op_sq, NULL); - else - projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, nc, evalFunc_2x_nc1_op_none, NULL); + if (integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ) { + projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, nc, evalFunc_2x_nc1_op_sq, NULL); + } else { + projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, nc, evalFunc_2x_nc1_op_none, NULL); + } // create distribution function array - struct gkyl_array *distf = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *distf_ho = use_gpu? mkarr(nc*basis.num_basis, local_ext.volume, false) : distf; + struct gkyl_array *distf = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); + struct gkyl_array *distf_ho = use_gpu ? mkarr(nc * basis.num_basis, local_ext.volume, false) : + distf; // project distribution function on basis gkyl_proj_on_basis_advance(projf, 0.0, &local, distf_ho); - if (use_gpu) gkyl_array_copy(distf, distf_ho); + if (use_gpu) { + gkyl_array_copy(distf, distf_ho); + } - if (integ_op == GKYL_ARRAY_INTEGRATE_OP_ABS) + if (integ_op == GKYL_ARRAY_INTEGRATE_OP_ABS) { gkyl_array_scale(distf, -1.); + } // integrate distribution function. - struct gkyl_array_integrate *integ_up = gkyl_array_integrate_new(&grid, &basis, nc, integ_op, use_gpu); + struct gkyl_array_integrate *integ_up = + gkyl_array_integrate_new(&grid, &basis, nc, integ_op, use_gpu); - double *fint = use_gpu? gkyl_cu_malloc(nc*sizeof(double)) : gkyl_malloc(nc*sizeof(double)); - struct gkyl_array *weight = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); + double *fint = use_gpu ? gkyl_cu_malloc(nc * sizeof(double)) : gkyl_malloc(nc * sizeof(double)); + struct gkyl_array *weight = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); gkyl_array_integrate_advance(integ_up, distf, 1., weight, &local, &local, fint); gkyl_array_integrate_release(integ_up); - double *fint_ho = gkyl_malloc(nc*sizeof(double)); - if (use_gpu) - gkyl_cu_memcpy(fint_ho, fint, nc*sizeof(double), GKYL_CU_MEMCPY_D2H); - else - memcpy(fint_ho, fint, nc*sizeof(double)); + double *fint_ho = gkyl_malloc(nc * sizeof(double)); + if (use_gpu) { + gkyl_cu_memcpy(fint_ho, fint, nc * sizeof(double), GKYL_CU_MEMCPY_D2H); + } else { + memcpy(fint_ho, fint, nc * sizeof(double)); + } - TEST_CHECK( gkyl_compare( 1.0, fint_ho[0], 1e-12) ); + TEST_CHECK(gkyl_compare(1.0, fint_ho[0], 1e-12)); gkyl_array_release(distf); gkyl_array_release(weight); - if (use_gpu) gkyl_array_release(distf_ho); + if (use_gpu) { + gkyl_array_release(distf_ho); + } gkyl_proj_on_basis_release(projf); gkyl_free(fint_ho); - if (use_gpu) + if (use_gpu) { gkyl_cu_free(fint); - else + } else { gkyl_free(fint); + } } -void evalFunc_2x_nc3_op_none(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_2x_nc3_op_none(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double lower[] = {0., -6.0}, upper[] = {2., 6.0}; // Has to match the test below. - fout[0] = 1./((upper[0]-lower[0])*(upper[1]-lower[1])); - fout[1] = 1.5/((upper[0]-lower[0])*(upper[1]-lower[1])); - fout[2] = 2.5/((upper[0]-lower[0])*(upper[1]-lower[1])); + fout[0] = 1. / ((upper[0] - lower[0]) * (upper[1] - lower[1])); + fout[1] = 1.5 / ((upper[0] - lower[0]) * (upper[1] - lower[1])); + fout[2] = 2.5 / ((upper[0] - lower[0]) * (upper[1] - lower[1])); } -void evalFunc_2x_nc3_op_sq(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_2x_nc3_op_sq(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double lower[] = {0., -6.0}, upper[] = {2., 6.0}; // Has to match the test below. - fout[0] = 1./sqrt((upper[0]-lower[0])*(upper[1]-lower[1])); - fout[1] = 1.5/sqrt((upper[0]-lower[0])*(upper[1]-lower[1])); - fout[2] = 2.5/sqrt((upper[0]-lower[0])*(upper[1]-lower[1])); + fout[0] = 1. / sqrt((upper[0] - lower[0]) * (upper[1] - lower[1])); + fout[1] = 1.5 / sqrt((upper[0] - lower[0]) * (upper[1] - lower[1])); + fout[2] = 2.5 / sqrt((upper[0] - lower[0]) * (upper[1] - lower[1])); } void test_2x_nc3_op(enum gkyl_array_integrate_op integ_op, int poly_order, bool use_gpu) { double lower[] = {0., -6.0}, upper[] = {2., 6.0}; int cells[] = {6, 16}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int nc = 3; // grids @@ -295,69 +327,84 @@ void test_2x_nc3_op(enum gkyl_array_integrate_op integ_op, int poly_order, bool struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); - int ghost[] = { 1, 0 }; + int ghost[] = {1, 0}; struct gkyl_range local, local_ext; // local, local-ext ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // projection updater for dist-function gkyl_proj_on_basis *projf; - if (integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ) - projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, nc, evalFunc_2x_nc3_op_sq, NULL); - else - projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, nc, evalFunc_2x_nc3_op_none, NULL); + if (integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ) { + projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, nc, evalFunc_2x_nc3_op_sq, NULL); + } else { + projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, nc, evalFunc_2x_nc3_op_none, NULL); + } // create distribution function array - struct gkyl_array *distf = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *distf_ho = use_gpu? mkarr(nc*basis.num_basis, local_ext.volume, false) : distf; + struct gkyl_array *distf = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); + struct gkyl_array *distf_ho = use_gpu ? mkarr(nc * basis.num_basis, local_ext.volume, false) : + distf; // project distribution function on basis gkyl_proj_on_basis_advance(projf, 0.0, &local, distf_ho); - if (use_gpu) gkyl_array_copy(distf, distf_ho); + if (use_gpu) { + gkyl_array_copy(distf, distf_ho); + } - if (integ_op == GKYL_ARRAY_INTEGRATE_OP_ABS) + if (integ_op == GKYL_ARRAY_INTEGRATE_OP_ABS) { gkyl_array_scale(distf, -1.); + } // integrate distribution function. - struct gkyl_array_integrate *integ_up = gkyl_array_integrate_new(&grid, &basis, nc, integ_op, use_gpu); + struct gkyl_array_integrate *integ_up = + gkyl_array_integrate_new(&grid, &basis, nc, integ_op, use_gpu); - double *fint = use_gpu? gkyl_cu_malloc(nc*sizeof(double)) : gkyl_malloc(nc*sizeof(double)); - struct gkyl_array *weight = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); + double *fint = use_gpu ? gkyl_cu_malloc(nc * sizeof(double)) : gkyl_malloc(nc * sizeof(double)); + struct gkyl_array *weight = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); gkyl_array_integrate_advance(integ_up, distf, 1., weight, &local, &local, fint); gkyl_array_integrate_release(integ_up); - double *fint_ho = gkyl_malloc(nc*sizeof(double)); - if (use_gpu) - gkyl_cu_memcpy(fint_ho, fint, nc*sizeof(double), GKYL_CU_MEMCPY_D2H); - else - memcpy(fint_ho, fint, nc*sizeof(double)); - - TEST_CHECK( gkyl_compare( 1.0, fint_ho[0], 1e-12) ); - TEST_CHECK( gkyl_compare( integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ? 1.5*1.5 : 1.5, fint_ho[1], 1e-12) ); - TEST_CHECK( gkyl_compare( integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ? 2.5*2.5 : 2.5, fint_ho[2], 1e-12) ); + double *fint_ho = gkyl_malloc(nc * sizeof(double)); + if (use_gpu) { + gkyl_cu_memcpy(fint_ho, fint, nc * sizeof(double), GKYL_CU_MEMCPY_D2H); + } else { + memcpy(fint_ho, fint, nc * sizeof(double)); + } + + TEST_CHECK(gkyl_compare(1.0, fint_ho[0], 1e-12)); + TEST_CHECK( + gkyl_compare(integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ ? 1.5 * 1.5 : 1.5, fint_ho[1], 1e-12) + ); + TEST_CHECK( + gkyl_compare(integ_op == GKYL_ARRAY_INTEGRATE_OP_SQ ? 2.5 * 2.5 : 2.5, fint_ho[2], 1e-12) + ); gkyl_array_release(distf); gkyl_array_release(weight); - if (use_gpu) gkyl_array_release(distf_ho); + if (use_gpu) { + gkyl_array_release(distf_ho); + } gkyl_proj_on_basis_release(projf); gkyl_free(fint_ho); - if (use_gpu) + if (use_gpu) { gkyl_cu_free(fint); - else + } else { gkyl_free(fint); + } } -void evalFunc_1x_op_gradsq(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_1x_op_gradsq(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 3.1*x; + fout[0] = 3.1 * x; } void test_1x_op_gradsq(int poly_order, bool use_gpu) { double lower[] = {-6.0}, upper[] = {6.0}; int cells[] = {16}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int nc = 1; // grids @@ -368,68 +415,80 @@ void test_1x_op_gradsq(int poly_order, bool use_gpu) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); - int ghost[] = { 1 }; + int ghost[] = {1}; struct gkyl_range local, local_ext; // local, local-ext ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // projection updater for dist-function - gkyl_proj_on_basis *projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, nc, evalFunc_1x_op_gradsq, NULL); + gkyl_proj_on_basis *projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, nc, evalFunc_1x_op_gradsq, NULL); // create distribution function array - struct gkyl_array *distf = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *distf_ho = use_gpu? mkarr(nc*basis.num_basis, local_ext.volume, false) : distf; + struct gkyl_array *distf = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); + struct gkyl_array *distf_ho = use_gpu ? mkarr(nc * basis.num_basis, local_ext.volume, false) : + distf; // project distribution function on basis gkyl_proj_on_basis_advance(projf, 0.0, &local, distf_ho); - if (use_gpu) gkyl_array_copy(distf, distf_ho); + if (use_gpu) { + gkyl_array_copy(distf, distf_ho); + } // integrate distribution function. - struct gkyl_array_integrate *integ_up = gkyl_array_integrate_new(&grid, &basis, nc, GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ, use_gpu); + struct gkyl_array_integrate *integ_up = + gkyl_array_integrate_new(&grid, &basis, nc, GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ, use_gpu); - double *fint = use_gpu? gkyl_cu_malloc(nc*sizeof(double)) : gkyl_malloc(nc*sizeof(double)); - struct gkyl_array *weight = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); + double *fint = use_gpu ? gkyl_cu_malloc(nc * sizeof(double)) : gkyl_malloc(nc * sizeof(double)); + struct gkyl_array *weight = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); gkyl_array_integrate_advance(integ_up, distf, 1., weight, &local, &local, fint); gkyl_array_integrate_release(integ_up); - double *fint_ho = gkyl_malloc(nc*sizeof(double)); - if (use_gpu) - gkyl_cu_memcpy(fint_ho, fint, nc*sizeof(double), GKYL_CU_MEMCPY_D2H); - else - memcpy(fint_ho, fint, nc*sizeof(double)); - - double *arr = gkyl_array_fetch(distf_ho,1); - double volFac = grid.dx[0]/2.; - double dx0Sq = pow(grid.dx[0],2); - if (poly_order == 1) - TEST_CHECK( gkyl_compare( cells[0]*12.*pow(arr[1],2)*volFac/dx0Sq, fint_ho[0], 1e-12) ); - else if (poly_order == 2) - TEST_CHECK( gkyl_compare( cells[0]*12.*(5.*pow(arr[2],2)+pow(arr[1],2))*volFac/dx0Sq, fint_ho[0], 1e-12) ); - else + double *fint_ho = gkyl_malloc(nc * sizeof(double)); + if (use_gpu) { + gkyl_cu_memcpy(fint_ho, fint, nc * sizeof(double), GKYL_CU_MEMCPY_D2H); + } else { + memcpy(fint_ho, fint, nc * sizeof(double)); + } + + double *arr = gkyl_array_fetch(distf_ho, 1); + double volFac = grid.dx[0] / 2.; + double dx0Sq = pow(grid.dx[0], 2); + if (poly_order == 1) { + TEST_CHECK(gkyl_compare(cells[0] * 12. * pow(arr[1], 2) * volFac / dx0Sq, fint_ho[0], 1e-12)); + } else if (poly_order == 2) { + TEST_CHECK(gkyl_compare( + cells[0] * 12. * (5. * pow(arr[2], 2) + pow(arr[1], 2)) * volFac / dx0Sq, fint_ho[0], 1e-12 + )); + } else { assert(false); + } gkyl_array_release(distf); gkyl_array_release(weight); - if (use_gpu) gkyl_array_release(distf_ho); + if (use_gpu) { + gkyl_array_release(distf_ho); + } gkyl_proj_on_basis_release(projf); gkyl_free(fint_ho); - if (use_gpu) + if (use_gpu) { gkyl_cu_free(fint); - else + } else { gkyl_free(fint); + } } -void evalFunc_2x_op_gradsq(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_2x_op_gradsq(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; - fout[0] = 3.1*x; + fout[0] = 3.1 * x; } void test_2x_op_gradsq(int poly_order, bool use_gpu) { double lower[] = {0., -6.0}, upper[] = {1., 6.0}; int cells[] = {6, 16}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int nc = 1; // grids @@ -440,55 +499,77 @@ void test_2x_op_gradsq(int poly_order, bool use_gpu) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range local, local_ext; // local, local-ext ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // projection updater for dist-function - gkyl_proj_on_basis *projf = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, nc, evalFunc_2x_op_gradsq, NULL); + gkyl_proj_on_basis *projf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, nc, evalFunc_2x_op_gradsq, NULL); // create distribution function array - struct gkyl_array *distf = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); - struct gkyl_array *distf_ho = use_gpu? mkarr(nc*basis.num_basis, local_ext.volume, false) : distf; + struct gkyl_array *distf = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); + struct gkyl_array *distf_ho = use_gpu ? mkarr(nc * basis.num_basis, local_ext.volume, false) : + distf; // project distribution function on basis gkyl_proj_on_basis_advance(projf, 0.0, &local, distf_ho); - if (use_gpu) gkyl_array_copy(distf, distf_ho); + if (use_gpu) { + gkyl_array_copy(distf, distf_ho); + } // integrate distribution function. - struct gkyl_array_integrate *integ_up = gkyl_array_integrate_new(&grid, &basis, nc, GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ, use_gpu); + struct gkyl_array_integrate *integ_up = + gkyl_array_integrate_new(&grid, &basis, nc, GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ, use_gpu); - double *fint = use_gpu? gkyl_cu_malloc(nc*sizeof(double)) : gkyl_malloc(nc*sizeof(double)); - struct gkyl_array *weight = mkarr(nc*basis.num_basis, local_ext.volume, use_gpu); + double *fint = use_gpu ? gkyl_cu_malloc(nc * sizeof(double)) : gkyl_malloc(nc * sizeof(double)); + struct gkyl_array *weight = mkarr(nc * basis.num_basis, local_ext.volume, use_gpu); gkyl_array_integrate_advance(integ_up, distf, 1., weight, &local, &local, fint); gkyl_array_integrate_release(integ_up); - double *fint_ho = gkyl_malloc(nc*sizeof(double)); - if (use_gpu) - gkyl_cu_memcpy(fint_ho, fint, nc*sizeof(double), GKYL_CU_MEMCPY_D2H); - else - memcpy(fint_ho, fint, nc*sizeof(double)); - - double *fIn = gkyl_array_fetch(distf_ho,cells[1]+2+1); - double volFac = (grid.dx[0]/2.)*(grid.dx[1]/2.); - double dx0Sq = pow(grid.dx[0],2), dx1Sq = pow(grid.dx[1],2); - if (poly_order == 1) - TEST_CHECK( gkyl_compare( cells[0]*cells[1]*12.*((dx1Sq+dx0Sq)*fIn[3]*fIn[3]+dx0Sq*fIn[2]*fIn[2]+dx1Sq*fIn[1]*fIn[1])*volFac/(dx0Sq*dx1Sq), fint_ho[0], 1e-12) ); - else if (poly_order == 2) - TEST_CHECK( gkyl_compare( cells[0]*cells[1]*12.*((dx1Sq+5*dx0Sq)*fIn[7]*fIn[7]+(5*dx1Sq+dx0Sq)*fIn[6]*fIn[6]+5*dx0Sq*fIn[5]*fIn[5]+5*dx1Sq*fIn[4]*fIn[4]+(dx1Sq+dx0Sq)*fIn[3]*fIn[3]+dx0Sq*fIn[2]*fIn[2]+dx1Sq*fIn[1]*fIn[1])*volFac/(dx0Sq*dx1Sq), fint_ho[0], 1e-12) ); - else + double *fint_ho = gkyl_malloc(nc * sizeof(double)); + if (use_gpu) { + gkyl_cu_memcpy(fint_ho, fint, nc * sizeof(double), GKYL_CU_MEMCPY_D2H); + } else { + memcpy(fint_ho, fint, nc * sizeof(double)); + } + + double *fIn = gkyl_array_fetch(distf_ho, cells[1] + 2 + 1); + double volFac = (grid.dx[0] / 2.) * (grid.dx[1] / 2.); + double dx0Sq = pow(grid.dx[0], 2), dx1Sq = pow(grid.dx[1], 2); + if (poly_order == 1) { + TEST_CHECK(gkyl_compare( + cells[0] * cells[1] * 12. * + ((dx1Sq + dx0Sq) * fIn[3] * fIn[3] + dx0Sq * fIn[2] * fIn[2] + dx1Sq * fIn[1] * fIn[1]) * + volFac / (dx0Sq * dx1Sq), + fint_ho[0], 1e-12 + )); + } else if (poly_order == 2) { + TEST_CHECK(gkyl_compare( + cells[0] * cells[1] * 12. * + ((dx1Sq + 5 * dx0Sq) * fIn[7] * fIn[7] + (5 * dx1Sq + dx0Sq) * fIn[6] * fIn[6] + + 5 * dx0Sq * fIn[5] * fIn[5] + 5 * dx1Sq * fIn[4] * fIn[4] + + (dx1Sq + dx0Sq) * fIn[3] * fIn[3] + dx0Sq * fIn[2] * fIn[2] + dx1Sq * fIn[1] * fIn[1]) * + volFac / (dx0Sq * dx1Sq), + fint_ho[0], 1e-12 + )); + } else { assert(false); + } gkyl_array_release(distf); gkyl_array_release(weight); - if (use_gpu) gkyl_array_release(distf_ho); + if (use_gpu) { + gkyl_array_release(distf_ho); + } gkyl_proj_on_basis_release(projf); gkyl_free(fint_ho); - if (use_gpu) + if (use_gpu) { gkyl_cu_free(fint); - else + } else { gkyl_free(fint); + } } void test_array_integrate_1x_ho() @@ -614,15 +695,15 @@ void test_array_integrate_2x_gradsq_dev() #endif TEST_LIST = { - { "test_array_integrate_1x_ho", test_array_integrate_1x_ho }, - { "test_array_integrate_2x_ho", test_array_integrate_2x_ho }, - { "test_array_integrate_1x_gradsq_ho", test_array_integrate_1x_gradsq_ho }, - { "test_array_integrate_2x_gradsq_ho", test_array_integrate_2x_gradsq_ho }, + {"test_array_integrate_1x_ho", test_array_integrate_1x_ho}, + {"test_array_integrate_2x_ho", test_array_integrate_2x_ho}, + {"test_array_integrate_1x_gradsq_ho", test_array_integrate_1x_gradsq_ho}, + {"test_array_integrate_2x_gradsq_ho", test_array_integrate_2x_gradsq_ho}, #ifdef GKYL_HAVE_CUDA - { "test_array_integrate_1x_dev", test_array_integrate_1x_dev }, - { "test_array_integrate_2x_dev", test_array_integrate_2x_dev }, - { "test_array_integrate_1x_gradsq_dev", test_array_integrate_1x_gradsq_dev }, - { "test_array_integrate_2x_gradsq_dev", test_array_integrate_2x_gradsq_dev }, + {"test_array_integrate_1x_dev", test_array_integrate_1x_dev}, + {"test_array_integrate_2x_dev", test_array_integrate_2x_dev}, + {"test_array_integrate_1x_gradsq_dev", test_array_integrate_1x_gradsq_dev}, + {"test_array_integrate_2x_gradsq_dev", test_array_integrate_2x_gradsq_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/core/unit/ctest_array_ops.c b/core/unit/ctest_array_ops.c index 4c10ed2269..9cb631d859 100644 --- a/core/unit/ctest_array_ops.c +++ b/core/unit/ctest_array_ops.c @@ -13,12 +13,11 @@ #include #include -static struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { // Allocate array (filled with zeros) - struct gkyl_array* a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } @@ -27,10 +26,11 @@ void test_array_clear_ho() struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 1, 10); gkyl_array_clear(a1, 0.5); - double *a1_d = a1->data; + double *a1_d = a1->data; - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(a1_d[i], 0.5, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(a1_d[i], 0.5, 1e-14)); + } gkyl_array_release(a1); } @@ -40,13 +40,14 @@ void test_array_clear_range_ho() int shape[] = {10, 20}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 1, range.volume); gkyl_array_clear_range(a1, 0.5, &range); double *a1_d = a1->data; - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(a1_d[i], 0.5, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(a1_d[i], 0.5, 1e-14)); + } gkyl_array_release(a1); } @@ -56,16 +57,17 @@ void test_array_accumulate_ho() struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 1, 10); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 1, 10); - double *a1_d = a1->data, *a2_d = a2->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; - a2_d[i] = i*0.1; + double *a1_d = a1->data, *a2_d = a2->data; + for (unsigned i = 0; i < a1->size; ++i) { + a1_d[i] = i * 1.0; + a2_d[i] = i * 0.1; } gkyl_array_accumulate(a1, 0.5, a2); - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(a1_d[i], i*1.0+0.5*i*0.1, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(a1_d[i], i * 1.0 + 0.5 * i * 0.1, 1e-14)); + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -76,7 +78,7 @@ void test_array_accumulate_range_ho() int shape[] = {10, 20}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 8, range.volume); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3, range.volume); @@ -88,14 +90,16 @@ void test_array_accumulate_range_ho() struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a1d = gkyl_array_fetch(a1, loc); - for (int i=0; i<3; ++i) - TEST_CHECK( a1d[i] == 0.5 + 0.5*1.5 ); - for (int i=3; i<8; ++i) - TEST_CHECK( a1d[i] == 0.5); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(a1d[i] == 0.5 + 0.5 * 1.5); + } + for (int i = 3; i < 8; ++i) { + TEST_CHECK(a1d[i] == 0.5); + } } // test a2 = a2 + 0.5*a @@ -105,13 +109,14 @@ void test_array_accumulate_range_ho() gkyl_array_accumulate_range(a2, 0.5, a1, &range); gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a2d = gkyl_array_fetch(a2, loc); - for (int i=0; i<3; ++i) - TEST_CHECK( a2d[i] == 1.5 + 0.5*0.5 ); - } + for (int i = 0; i < 3; ++i) { + TEST_CHECK(a2d[i] == 1.5 + 0.5 * 0.5); + } + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -120,38 +125,49 @@ void test_array_accumulate_range_ho() void test_array_accumulate_offset_ho() { struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 2, 10); - struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3*a1->ncomp, 10); + struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3 * a1->ncomp, 10); - double *a1_d = a1->data, *a2_d = a2->data; + double *a1_d = a1->data, *a2_d = a2->data; // test a1 = 0.1*a2[a1->ncomp] - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - a1_d[i*a1->ncomp+j] = i*1.0+j; + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + a1_d[i * a1->ncomp + j] = i * 1.0 + j; + } + } - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp/a1->ncomp; ++j) - for (unsigned k=0; kncomp; ++k) - a2_d[i*a2->ncomp+j*a1->ncomp+k] = i*0.1+k; + for (unsigned i = 0; i < a2->size; ++i) { + for (unsigned j = 0; j < a2->ncomp / a1->ncomp; ++j) { + for (unsigned k = 0; k < a1->ncomp; ++k) { + a2_d[i * a2->ncomp + j * a1->ncomp + k] = i * 0.1 + k; + } + } + } - gkyl_array_accumulate_offset(a1, 0.5, a2, 1*a1->ncomp); + gkyl_array_accumulate_offset(a1, 0.5, a2, 1 * a1->ncomp); - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - TEST_CHECK( gkyl_compare(a1_d[i*a1->ncomp+j], i*1.0+j+0.5*(i*0.1+j), 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + TEST_CHECK(gkyl_compare(a1_d[i * a1->ncomp + j], i * 1.0 + j + 0.5 * (i * 0.1 + j), 1e-14)); + } + } // test a2[a1->ncomp] = 0.1*a1 - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - a1_d[i*a1->ncomp+j] = i*1.0+j; + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + a1_d[i * a1->ncomp + j] = i * 1.0 + j; + } + } - gkyl_array_accumulate_offset(a2, 0.5, a1, 1*a1->ncomp); + gkyl_array_accumulate_offset(a2, 0.5, a1, 1 * a1->ncomp); - for (unsigned i=0; isize; ++i) { - for (unsigned j=0; jncomp; ++j) { - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+0*a1->ncomp+j], i*0.1+j, 1e-14) ); - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+1*a1->ncomp+j], i*0.1+j+0.5*(i*1.0+j), 1e-14) ); - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+2*a1->ncomp+j], i*0.1+j, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + TEST_CHECK(gkyl_compare(a2_d[i * a2->ncomp + 0 * a1->ncomp + j], i * 0.1 + j, 1e-14)); + TEST_CHECK(gkyl_compare( + a2_d[i * a2->ncomp + 1 * a1->ncomp + j], i * 0.1 + j + 0.5 * (i * 1.0 + j), 1e-14 + )); + TEST_CHECK(gkyl_compare(a2_d[i * a2->ncomp + 2 * a1->ncomp + j], i * 0.1 + j, 1e-14)); } } @@ -164,42 +180,43 @@ void test_array_accumulate_offset_range_ho() int shape[] = {10, 20}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 2, range.volume); - struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3*a1->ncomp, range.volume); + struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3 * a1->ncomp, range.volume); // test a1 = a1+0.5*a2[a1->ncomp] gkyl_array_clear(a1, 0.5); gkyl_array_clear(a2, 1.5); - gkyl_array_accumulate_offset_range(a1, 0.5, a2, 1*a1->ncomp, &range); + gkyl_array_accumulate_offset_range(a1, 0.5, a2, 1 * a1->ncomp, &range); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a1d = gkyl_array_fetch(a1, loc); - for (int i=0; incomp; ++i) - TEST_CHECK( a1d[i] == 0.5+0.5*1.5 ); + for (int i = 0; i < a1->ncomp; ++i) { + TEST_CHECK(a1d[i] == 0.5 + 0.5 * 1.5); + } } // test a2[a1->ncomp] = a2[a1->ncomp]+0.5*a1 gkyl_array_clear(a1, 0.5); gkyl_array_clear(a2, 1.5); - gkyl_array_accumulate_offset_range(a2, 0.5, a1, 1*a1->ncomp, &range); + gkyl_array_accumulate_offset_range(a2, 0.5, a1, 1 * a1->ncomp, &range); gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a2d = gkyl_array_fetch(a2, loc); - for (int i=0; incomp; ++i) { - TEST_CHECK( a2d[i+0*a1->ncomp] == 1.5 ); - TEST_CHECK( a2d[i+1*a1->ncomp] == 1.5+0.5*0.5 ); - TEST_CHECK( a2d[i+2*a1->ncomp] == 1.5 ); + for (int i = 0; i < a1->ncomp; ++i) { + TEST_CHECK(a2d[i + 0 * a1->ncomp] == 1.5); + TEST_CHECK(a2d[i + 1 * a1->ncomp] == 1.5 + 0.5 * 0.5); + TEST_CHECK(a2d[i + 2 * a1->ncomp] == 1.5); } - } + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -211,18 +228,19 @@ void test_array_combine_ho() struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 1, 10); struct gkyl_array *b = gkyl_array_new(GKYL_DOUBLE, 1, 10); - double *a1_d = a1->data, *a2_d = a2->data, *b_d = b->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; - a2_d[i] = i*0.1; + double *a1_d = a1->data, *a2_d = a2->data, *b_d = b->data; + for (unsigned i = 0; i < a1->size; ++i) { + a1_d[i] = i * 1.0; + a2_d[i] = i * 0.1; b_d[i] = 10.5; } // b = 0.5*a1 + 2.5*a2 gkyl_array_accumulate(gkyl_array_set(b, 0.5, a1), 2.5, a2); - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(b_d[i], 0.5*i*1.0+2.5*i*0.1, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(b_d[i], 0.5 * i * 1.0 + 2.5 * i * 0.1, 1e-14)); + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -234,16 +252,17 @@ void test_array_set_ho() struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 1, 10); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 1, 10); - double *a1_d = a1->data, *a2_d = a2->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; - a2_d[i] = i*0.1; + double *a1_d = a1->data, *a2_d = a2->data; + for (unsigned i = 0; i < a1->size; ++i) { + a1_d[i] = i * 1.0; + a2_d[i] = i * 0.1; } gkyl_array_set(a1, 0.5, a2); - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(a1_d[i], 0.5*i*0.1, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(a1_d[i], 0.5 * i * 0.1, 1e-14)); + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -254,7 +273,7 @@ void test_array_set_range_ho() int shape[] = {10, 20}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 8, range.volume); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3, range.volume); @@ -266,14 +285,16 @@ void test_array_set_range_ho() struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a1d = gkyl_array_fetch(a1, loc); - for (int i=0; i<3; ++i) - TEST_CHECK( a1d[i] == 0.5*1.5 ); - for (int i=3; i<8; ++i) - TEST_CHECK( a1d[i] == 0.5); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(a1d[i] == 0.5 * 1.5); + } + for (int i = 3; i < 8; ++i) { + TEST_CHECK(a1d[i] == 0.5); + } } // test a2 = 0.5*a1 @@ -283,13 +304,14 @@ void test_array_set_range_ho() gkyl_array_set_range(a2, 0.5, a1, &range); gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a2d = gkyl_array_fetch(a2, loc); - for (int i=0; i<3; ++i) - TEST_CHECK( a2d[i] == 0.5*0.5 ); - } + for (int i = 0; i < 3; ++i) { + TEST_CHECK(a2d[i] == 0.5 * 0.5); + } + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -298,38 +320,49 @@ void test_array_set_range_ho() void test_array_set_offset_ho() { struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 2, 10); - struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3*a1->ncomp, a1->size); + struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3 * a1->ncomp, a1->size); double *a1_d = a1->data, *a2_d = a2->data; // Assign a component of the vector to the scalar. - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - a1_d[i*a1->ncomp+j] = i*0.2+2*j; + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + a1_d[i * a1->ncomp + j] = i * 0.2 + 2 * j; + } + } - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp/a1->ncomp; ++j) - for (unsigned k=0; kncomp; ++k) - a2_d[i*a2->ncomp+j*a1->ncomp+k] = i*0.1+k; + for (unsigned i = 0; i < a2->size; ++i) { + for (unsigned j = 0; j < a2->ncomp / a1->ncomp; ++j) { + for (unsigned k = 0; k < a1->ncomp; ++k) { + a2_d[i * a2->ncomp + j * a1->ncomp + k] = i * 0.1 + k; + } + } + } - gkyl_array_set_offset(a1, 0.5, a2, 1*a1->ncomp); + gkyl_array_set_offset(a1, 0.5, a2, 1 * a1->ncomp); - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - TEST_CHECK( gkyl_compare(a1_d[i*a1->ncomp+j], 0.5*(i*0.1+j), 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + TEST_CHECK(gkyl_compare(a1_d[i * a1->ncomp + j], 0.5 * (i * 0.1 + j), 1e-14)); + } + } // Assign the scalar to a component of the vector. - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - a1_d[i*a1->ncomp+j] = i*0.2+2*j; + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + a1_d[i * a1->ncomp + j] = i * 0.2 + 2 * j; + } + } - gkyl_array_set_offset(a2, 2., a1, 1*a1->ncomp); + gkyl_array_set_offset(a2, 2., a1, 1 * a1->ncomp); - for (unsigned i=0; isize; ++i) { - for (unsigned j=0; jncomp; ++j) { - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+0*a1->ncomp+j], i*0.1+j, 1e-14) ); - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+1*a1->ncomp+j], 2.*(i*0.2+2*j), 1e-14) ); - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+2*a1->ncomp+j], i*0.1+j, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + TEST_CHECK(gkyl_compare(a2_d[i * a2->ncomp + 0 * a1->ncomp + j], i * 0.1 + j, 1e-14)); + TEST_CHECK( + gkyl_compare(a2_d[i * a2->ncomp + 1 * a1->ncomp + j], 2. * (i * 0.2 + 2 * j), 1e-14) + ); + TEST_CHECK(gkyl_compare(a2_d[i * a2->ncomp + 2 * a1->ncomp + j], i * 0.1 + j, 1e-14)); } } @@ -342,41 +375,42 @@ void test_array_set_offset_range_ho() int shape[] = {10, 20}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 2, range.volume); - struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3*a1->ncomp, range.volume); + struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3 * a1->ncomp, range.volume); // test a1 = 0.1*a2[a1->ncomp] gkyl_array_clear_range(a1, 0.5, &range); gkyl_array_clear_range(a2, 1.5, &range); - gkyl_array_set_offset_range(a1, 0.1, a2, 1*a1->ncomp, &range); + gkyl_array_set_offset_range(a1, 0.1, a2, 1 * a1->ncomp, &range); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a1d = gkyl_array_fetch(a1, loc); - for (int i=0; incomp; ++i) - TEST_CHECK( a1d[i] == 0.1*1.5 ); + for (int i = 0; i < a1->ncomp; ++i) { + TEST_CHECK(a1d[i] == 0.1 * 1.5); + } } // test a2[a1->ncomp] = 0.1*a1 gkyl_array_clear(a1, 0.5); gkyl_array_clear(a2, 1.5); - gkyl_array_set_offset_range(a2, 0.1, a1, 1*a1->ncomp, &range); + gkyl_array_set_offset_range(a2, 0.1, a1, 1 * a1->ncomp, &range); gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a2d = gkyl_array_fetch(a2, loc); - for (int i=0; incomp; ++i) { - TEST_CHECK( a2d[i+0*a1->ncomp] == 1.5 ); - TEST_CHECK( a2d[i+1*a1->ncomp] == 0.1*0.5 ); - TEST_CHECK( a2d[i+2*a1->ncomp] == 1.5 ); + for (int i = 0; i < a1->ncomp; ++i) { + TEST_CHECK(a2d[i + 0 * a1->ncomp] == 1.5); + TEST_CHECK(a2d[i + 1 * a1->ncomp] == 0.1 * 0.5); + TEST_CHECK(a2d[i + 2 * a1->ncomp] == 1.5); } - } + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -386,15 +420,16 @@ void test_array_scale_ho() { struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 1, 10); - double *a1_d = a1->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; + double *a1_d = a1->data; + for (unsigned i = 0; i < a1->size; ++i) { + a1_d[i] = i * 1.0; } gkyl_array_scale(a1, 0.25); - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(a1_d[i], i*0.25, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(a1_d[i], i * 0.25, 1e-14)); + } gkyl_array_release(a1); } @@ -404,20 +439,20 @@ void test_array_scale_by_cell_ho() struct gkyl_array *a1 = mkarr(false, 3, 10); struct gkyl_array *s = mkarr(false, 1, 10); - double *a1_d = a1->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; + double *a1_d = a1->data; + for (unsigned i = 0; i < a1->size; ++i) { + a1_d[i] = i * 1.0; } - double *s_d = s->data; - for (unsigned i=0; isize; ++i) { - s_d[i] = i*1.0; + double *s_d = s->data; + for (unsigned i = 0; i < s->size; ++i) { + s_d[i] = i * 1.0; } gkyl_array_scale_by_cell(a1, s); - for (unsigned i=0; isize; ++i) { - int fact = (i/a1->ncomp); - TEST_CHECK( gkyl_compare(a1_d[i], i*1.0*fact, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + int fact = (i / a1->ncomp); + TEST_CHECK(gkyl_compare(a1_d[i], i * 1.0 * fact, 1e-14)); } gkyl_array_release(a1); @@ -429,20 +464,20 @@ void test_array_divide_by_cell() struct gkyl_array *a1 = mkarr(false, 3, 10); struct gkyl_array *s = mkarr(false, 1, 10); - double *a1_d = a1->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; + double *a1_d = a1->data; + for (unsigned i = 0; i < a1->size; ++i) { + a1_d[i] = i * 1.0; } - double *s_d = s->data; - for (unsigned i=0; isize; ++i) { - s_d[i] = i*1.0; + double *s_d = s->data; + for (unsigned i = 0; i < s->size; ++i) { + s_d[i] = i * 1.0; } gkyl_array_divide_by_cell(a1, s); - for (unsigned i=0; isize; ++i) { - int fact = (i/a1->ncomp); - TEST_CHECK( gkyl_compare(a1_d[i], i*1.0/fact, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + int fact = (i / a1->ncomp); + TEST_CHECK(gkyl_compare(a1_d[i], i * 1.0 / fact, 1e-14)); } gkyl_array_release(a1); @@ -455,43 +490,53 @@ void test_array_shiftc_ho() double s = -0.5; double *a1_d = a1->data; - for (unsigned i=0; isize; ++i) { - for (size_t k=0; kncomp; ++k) a1_d[i*a1->ncomp+k] = i*2.0+k; + for (unsigned i = 0; i < a1->size; ++i) { + for (size_t k = 0; k < a1->ncomp; ++k) { + a1_d[i * a1->ncomp + k] = i * 2.0 + k; + } } gkyl_array_shiftc(a1, s, 0); - TEST_CHECK( gkyl_compare(a1_d[0], 0*1.0+0+s, 1e-14) ); - for (unsigned i=0; isize; ++i) { - for (size_t k=1; kncomp; ++k) - TEST_CHECK( gkyl_compare(a1_d[i*a1->ncomp+k], i*2.0+k, 1e-14) ); + TEST_CHECK(gkyl_compare(a1_d[0], 0 * 1.0 + 0 + s, 1e-14)); + for (unsigned i = 0; i < a1->size; ++i) { + for (size_t k = 1; k < a1->ncomp; ++k) { + TEST_CHECK(gkyl_compare(a1_d[i * a1->ncomp + k], i * 2.0 + k, 1e-14)); + } } gkyl_array_release(a1); // Repeat the test but shifting another coefficient as well. int shiftks[] = {0, 2}; - int nks = sizeof(shiftks)/sizeof(shiftks[0]); + int nks = sizeof(shiftks) / sizeof(shiftks[0]); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 4, 8); double *a2_d = a2->data; - for (unsigned i=0; isize; ++i) { - for (size_t k=0; kncomp; ++k) a2_d[i*a2->ncomp+k] = i*2.0+k; + for (unsigned i = 0; i < a2->size; ++i) { + for (size_t k = 0; k < a2->ncomp; ++k) { + a2_d[i * a2->ncomp + k] = i * 2.0 + k; + } } - for (size_t l=0; lsize; ++i) { - for (size_t k=0; kncomp; ++k) { + for (unsigned i = 0; i < a2->size; ++i) { + for (size_t k = 0; k < a2->ncomp; ++k) { bool isshifted = false; - for (size_t l=0; lncomp + k], i * 2.0 + k + s, 1e-14)); + } else { + TEST_CHECK(gkyl_compare(a2_d[i * a2->ncomp + k], i * 2.0 + k, 1e-14)); } - if (isshifted) - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+k], i*2.0+k+s, 1e-14) ); - else - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+k], i*2.0+k, 1e-14) ); } } @@ -506,17 +551,21 @@ void test_array_invert_by_cell_ho() // Set values: 1.0, 2.0, 4.0, 5.0, 10.0, 0.5, 0.25, 0.1 double test_vals[] = {1.0, 2.0, 4.0, 5.0, 10.0, 0.5, 0.25, 0.1}; double expected_inv[] = {1.0, 0.5, 0.25, 0.2, 0.1, 2.0, 4.0, 10.0}; - - for (unsigned i=0; isize; ++i) - for (size_t k=0; kncomp; ++k) - a1_d[i*a1->ncomp+k] = test_vals[i]; + + for (unsigned i = 0; i < a1->size; ++i) { + for (size_t k = 0; k < a1->ncomp; ++k) { + a1_d[i * a1->ncomp + k] = test_vals[i]; + } + } gkyl_array_invert_by_cell(a1, a1); // Check inverted values - for (unsigned i=0; isize; ++i) - for (size_t k=0; kncomp; ++k) - TEST_CHECK( gkyl_compare(a1_d[i*a1->ncomp+k], expected_inv[i], 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + for (size_t k = 0; k < a1->ncomp; ++k) { + TEST_CHECK(gkyl_compare(a1_d[i * a1->ncomp + k], expected_inv[i], 1e-14)); + } + } gkyl_array_release(a1); } @@ -529,14 +578,21 @@ void test_array_shiftc_range(bool on_gpu) struct gkyl_array *a1_ho = gkyl_array_new(GKYL_DOUBLE, 3, range.volume); struct gkyl_array *a1 = a1_ho; - if (on_gpu) a1 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a1_ho->ncomp, a1_ho->size); + if (on_gpu) { + a1 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a1_ho->ncomp, a1_ho->size); + } double s = -0.5; double *a1_ho_d = a1_ho->data; - for (unsigned i=0; isize; ++i) - for (size_t k=0; kncomp; ++k) a1_ho_d[i*a1_ho->ncomp+k] = i*2.0+k; + for (unsigned i = 0; i < a1_ho->size; ++i) { + for (size_t k = 0; k < a1_ho->ncomp; ++k) { + a1_ho_d[i * a1_ho->ncomp + k] = i * 2.0 + k; + } + } - if (on_gpu) gkyl_array_copy(a1, a1_ho); + if (on_gpu) { + gkyl_array_copy(a1, a1_ho); + } int lowerSub[] = {2}, upperSub[] = {6}; struct gkyl_range subrange; @@ -544,124 +600,167 @@ void test_array_shiftc_range(bool on_gpu) gkyl_array_shiftc_range(a1, s, 0, &subrange); - if (on_gpu) gkyl_array_copy(a1_ho, a1); + if (on_gpu) { + gkyl_array_copy(a1_ho, a1); + } - for (size_t k=1; kncomp; ++k) { - for (unsigned i=0; i<1; ++i) - TEST_CHECK( gkyl_compare(a1_ho_d[i*a1_ho->ncomp+k], i*2.0+k, 1e-14) ); - for (unsigned i=6; i<10; ++i) - TEST_CHECK( gkyl_compare(a1_ho_d[i*a1_ho->ncomp+k], i*2.0+k, 1e-14) ); + for (size_t k = 1; k < a1_ho->ncomp; ++k) { + for (unsigned i = 0; i < 1; ++i) { + TEST_CHECK(gkyl_compare(a1_ho_d[i * a1_ho->ncomp + k], i * 2.0 + k, 1e-14)); + } + for (unsigned i = 6; i < 10; ++i) { + TEST_CHECK(gkyl_compare(a1_ho_d[i * a1_ho->ncomp + k], i * 2.0 + k, 1e-14)); + } + } + for (unsigned i = 1; i < 6; ++i) { + TEST_CHECK(gkyl_compare(a1_ho_d[i * a1_ho->ncomp + 0], i * 2.0 + 0 + s, 1e-14)); } - for (unsigned i=1; i<6; ++i) - TEST_CHECK( gkyl_compare(a1_ho_d[i*a1_ho->ncomp+0], i*2.0+0+s, 1e-14) ); gkyl_array_release(a1_ho); - if (on_gpu) gkyl_array_release(a1); + if (on_gpu) { + gkyl_array_release(a1); + } // Repeat the test but shifting another coefficient as well. int shiftks[] = {0, 2}; - int nks = sizeof(shiftks)/sizeof(shiftks[0]); + int nks = sizeof(shiftks) / sizeof(shiftks[0]); - lower[0] = 1; upper[0] = 8; + lower[0] = 1; + upper[0] = 8; struct gkyl_range range2; gkyl_range_init(&range2, 1, lower, upper); struct gkyl_array *a2_ho = gkyl_array_new(GKYL_DOUBLE, 4, range2.volume); struct gkyl_array *a2 = a2_ho; - if (on_gpu) a2 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a2_ho->ncomp, a2_ho->size); + if (on_gpu) { + a2 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a2_ho->ncomp, a2_ho->size); + } double *a2_ho_d = a2_ho->data; - for (unsigned i=0; isize; ++i) { - for (size_t k=0; kncomp; ++k) a2_ho_d[i*a2_ho->ncomp+k] = i*2.0+k; + for (unsigned i = 0; i < a2_ho->size; ++i) { + for (size_t k = 0; k < a2_ho->ncomp; ++k) { + a2_ho_d[i * a2_ho->ncomp + k] = i * 2.0 + k; + } } - if (on_gpu) gkyl_array_copy(a2, a2_ho); + if (on_gpu) { + gkyl_array_copy(a2, a2_ho); + } - for (size_t l=0; lncomp; ++k) { - for (unsigned i=0; i<1; ++i) - TEST_CHECK( gkyl_compare(a2_ho_d[i*a2_ho->ncomp+k], i*2.0+k, 1e-14) ); - for (unsigned i=6; i<8; ++i) - TEST_CHECK( gkyl_compare(a2_ho_d[i*a2_ho->ncomp+k], i*2.0+k, 1e-14) ); + for (size_t k = 0; k < a2_ho->ncomp; ++k) { + for (unsigned i = 0; i < 1; ++i) { + TEST_CHECK(gkyl_compare(a2_ho_d[i * a2_ho->ncomp + k], i * 2.0 + k, 1e-14)); + } + for (unsigned i = 6; i < 8; ++i) { + TEST_CHECK(gkyl_compare(a2_ho_d[i * a2_ho->ncomp + k], i * 2.0 + k, 1e-14)); + } } - for (unsigned i=1; i<6; ++i) { - for (size_t k=0; kncomp; ++k) { + for (unsigned i = 1; i < 6; ++i) { + for (size_t k = 0; k < a2_ho->ncomp; ++k) { bool isshifted = false; - for (size_t l=0; lncomp + k], i * 2.0 + k + s, 1e-14)); + } else { + TEST_CHECK(gkyl_compare(a2_ho_d[i * a2_ho->ncomp + k], i * 2.0 + k, 1e-14)); } - if (isshifted) - TEST_CHECK( gkyl_compare(a2_ho_d[i*a2_ho->ncomp+k], i*2.0+k+s, 1e-14) ); - else - TEST_CHECK( gkyl_compare(a2_ho_d[i*a2_ho->ncomp+k], i*2.0+k, 1e-14) ); } } gkyl_array_release(a2); - if (on_gpu) gkyl_array_release(a2); + if (on_gpu) { + gkyl_array_release(a2); + } } void test_array_min_by_cell(bool on_gpu) { struct gkyl_array *a1_ho = gkyl_array_new(GKYL_DOUBLE, 3, 10); struct gkyl_array *a1 = a1_ho; - if (on_gpu) a1 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a1_ho->ncomp, a1_ho->size); + if (on_gpu) { + a1 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a1_ho->ncomp, a1_ho->size); + } double *a1_ho_d = a1_ho->data; - for (unsigned i=0; isize; ++i) { - for (size_t k=0; kncomp; ++k) - a1_ho_d[i*a1_ho->ncomp+k] = i*10.0+k; + for (unsigned i = 0; i < a1_ho->size; ++i) { + for (size_t k = 0; k < a1_ho->ncomp; ++k) { + a1_ho_d[i * a1_ho->ncomp + k] = i * 10.0 + k; + } } - if (on_gpu) gkyl_array_copy(a1, a1_ho); + if (on_gpu) { + gkyl_array_copy(a1, a1_ho); + } // Apply min with threshold 15.0 gkyl_array_min_by_cell(a1, a1, 15.0); - if (on_gpu) gkyl_array_copy(a1_ho, a1); + if (on_gpu) { + gkyl_array_copy(a1_ho, a1); + } // Check that values > 15.0 are clamped to 15.0 - for (unsigned i=0; isize; ++i) { - for (size_t k=0; kncomp; ++k) { - double expected = (i*10.0+k < 15.0) ? i*10.0+k : 15.0; - TEST_CHECK( gkyl_compare(a1_ho_d[i*a1_ho->ncomp+k], expected, 1e-14) ); + for (unsigned i = 0; i < a1_ho->size; ++i) { + for (size_t k = 0; k < a1_ho->ncomp; ++k) { + double expected = (i * 10.0 + k < 15.0) ? i * 10.0 + k : 15.0; + TEST_CHECK(gkyl_compare(a1_ho_d[i * a1_ho->ncomp + k], expected, 1e-14)); } } gkyl_array_release(a1_ho); - if (on_gpu) gkyl_array_release(a1); + if (on_gpu) { + gkyl_array_release(a1); + } // Test with negative threshold struct gkyl_array *a2_ho = gkyl_array_new(GKYL_DOUBLE, 4, 8); struct gkyl_array *a2 = a2_ho; - if (on_gpu) a2 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a2_ho->ncomp, a2_ho->size); + if (on_gpu) { + a2 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a2_ho->ncomp, a2_ho->size); + } double *a2_ho_d = a2_ho->data; - for (unsigned i=0; isize; ++i) { - for (size_t k=0; kncomp; ++k) - a2_ho_d[i*a2_ho->ncomp+k] = (double)i - 5.0 + k*0.1; + for (unsigned i = 0; i < a2_ho->size; ++i) { + for (size_t k = 0; k < a2_ho->ncomp; ++k) { + a2_ho_d[i * a2_ho->ncomp + k] = (double)i - 5.0 + k * 0.1; + } } - if (on_gpu) gkyl_array_copy(a2, a2_ho); + if (on_gpu) { + gkyl_array_copy(a2, a2_ho); + } gkyl_array_min_by_cell(a2, a2, -2.5); - if (on_gpu) gkyl_array_copy(a2_ho, a2); + if (on_gpu) { + gkyl_array_copy(a2_ho, a2); + } - for (unsigned i=0; isize; ++i) { - for (size_t k=0; kncomp; ++k) { - double orig = (double)i - 5.0 + k*0.1; + for (unsigned i = 0; i < a2_ho->size; ++i) { + for (size_t k = 0; k < a2_ho->ncomp; ++k) { + double orig = (double)i - 5.0 + k * 0.1; double expected = (orig < -2.5) ? orig : -2.5; - TEST_CHECK( gkyl_compare(a2_ho_d[i*a2_ho->ncomp+k], expected, 1e-14) ); + TEST_CHECK(gkyl_compare(a2_ho_d[i * a2_ho->ncomp + k], expected, 1e-14)); } } gkyl_array_release(a2_ho); - if (on_gpu) gkyl_array_release(a2); + if (on_gpu) { + gkyl_array_release(a2); + } } void test_array_min_range(bool on_gpu) @@ -672,14 +771,20 @@ void test_array_min_range(bool on_gpu) struct gkyl_array *a1_ho = gkyl_array_new(GKYL_DOUBLE, 3, range.volume); struct gkyl_array *a1 = a1_ho; - if (on_gpu) a1 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a1_ho->ncomp, a1_ho->size); + if (on_gpu) { + a1 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a1_ho->ncomp, a1_ho->size); + } double *a1_ho_d = a1_ho->data; - for (unsigned i=0; isize; ++i) - for (size_t k=0; kncomp; ++k) - a1_ho_d[i*a1_ho->ncomp+k] = i*10.0+k; + for (unsigned i = 0; i < a1_ho->size; ++i) { + for (size_t k = 0; k < a1_ho->ncomp; ++k) { + a1_ho_d[i * a1_ho->ncomp + k] = i * 10.0 + k; + } + } - if (on_gpu) gkyl_array_copy(a1, a1_ho); + if (on_gpu) { + gkyl_array_copy(a1, a1_ho); + } // Apply min only to subrange [2, 6] int lowerSub[] = {2}, upperSub[] = {6}; @@ -688,84 +793,103 @@ void test_array_min_range(bool on_gpu) gkyl_array_min_by_cell_range(a1, a1, 12.0, &subrange); - if (on_gpu) gkyl_array_copy(a1_ho, a1); + if (on_gpu) { + gkyl_array_copy(a1_ho, a1); + } // Check cells outside subrange are unchanged - for (size_t k=0; kncomp; ++k) { - for (unsigned i=0; i<1; ++i) - TEST_CHECK( gkyl_compare(a1_ho_d[i*a1_ho->ncomp+k], i*10.0+k, 1e-14) ); - for (unsigned i=6; i<10; ++i) - TEST_CHECK( gkyl_compare(a1_ho_d[i*a1_ho->ncomp+k], i*10.0+k, 1e-14) ); + for (size_t k = 0; k < a1_ho->ncomp; ++k) { + for (unsigned i = 0; i < 1; ++i) { + TEST_CHECK(gkyl_compare(a1_ho_d[i * a1_ho->ncomp + k], i * 10.0 + k, 1e-14)); + } + for (unsigned i = 6; i < 10; ++i) { + TEST_CHECK(gkyl_compare(a1_ho_d[i * a1_ho->ncomp + k], i * 10.0 + k, 1e-14)); + } } - + // Check cells in subrange have min applied - for (unsigned i=1; i<6; ++i) { - for (size_t k=0; kncomp; ++k) { - double orig = i*10.0+k; + for (unsigned i = 1; i < 6; ++i) { + for (size_t k = 0; k < a1_ho->ncomp; ++k) { + double orig = i * 10.0 + k; double expected = (orig < 12.0) ? orig : 12.0; - TEST_CHECK( gkyl_compare(a1_ho_d[i*a1_ho->ncomp+k], expected, 1e-14) ); + TEST_CHECK(gkyl_compare(a1_ho_d[i * a1_ho->ncomp + k], expected, 1e-14)); } } gkyl_array_release(a1_ho); - if (on_gpu) gkyl_array_release(a1); + if (on_gpu) { + gkyl_array_release(a1); + } // Test with different range and threshold - lower[0] = 1; upper[0] = 8; + lower[0] = 1; + upper[0] = 8; struct gkyl_range range2; gkyl_range_init(&range2, 1, lower, upper); struct gkyl_array *a2_ho = gkyl_array_new(GKYL_DOUBLE, 4, range2.volume); struct gkyl_array *a2 = a2_ho; - if (on_gpu) a2 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a2_ho->ncomp, a2_ho->size); + if (on_gpu) { + a2 = gkyl_array_cu_dev_new(GKYL_DOUBLE, a2_ho->ncomp, a2_ho->size); + } double *a2_ho_d = a2_ho->data; - for (unsigned i=0; isize; ++i) { - for (size_t k=0; kncomp; ++k) - a2_ho_d[i*a2_ho->ncomp+k] = i*5.0+k; + for (unsigned i = 0; i < a2_ho->size; ++i) { + for (size_t k = 0; k < a2_ho->ncomp; ++k) { + a2_ho_d[i * a2_ho->ncomp + k] = i * 5.0 + k; + } } - if (on_gpu) gkyl_array_copy(a2, a2_ho); + if (on_gpu) { + gkyl_array_copy(a2, a2_ho); + } gkyl_array_min_by_cell_range(a2, a2, 8.0, &subrange); - if (on_gpu) gkyl_array_copy(a2_ho, a2); + if (on_gpu) { + gkyl_array_copy(a2_ho, a2); + } - for (size_t k=0; kncomp; ++k) { - for (unsigned i=0; i<1; ++i) - TEST_CHECK( gkyl_compare(a2_ho_d[i*a2_ho->ncomp+k], i*5.0+k, 1e-14) ); - for (unsigned i=6; i<8; ++i) - TEST_CHECK( gkyl_compare(a2_ho_d[i*a2_ho->ncomp+k], i*5.0+k, 1e-14) ); + for (size_t k = 0; k < a2_ho->ncomp; ++k) { + for (unsigned i = 0; i < 1; ++i) { + TEST_CHECK(gkyl_compare(a2_ho_d[i * a2_ho->ncomp + k], i * 5.0 + k, 1e-14)); + } + for (unsigned i = 6; i < 8; ++i) { + TEST_CHECK(gkyl_compare(a2_ho_d[i * a2_ho->ncomp + k], i * 5.0 + k, 1e-14)); + } } - - for (unsigned i=1; i<6; ++i) { - for (size_t k=0; kncomp; ++k) { - double orig = i*5.0+k; + + for (unsigned i = 1; i < 6; ++i) { + for (size_t k = 0; k < a2_ho->ncomp; ++k) { + double orig = i * 5.0 + k; double expected = (orig < 8.0) ? orig : 8.0; - TEST_CHECK( gkyl_compare(a2_ho_d[i*a2_ho->ncomp+k], expected, 1e-14) ); + TEST_CHECK(gkyl_compare(a2_ho_d[i * a2_ho->ncomp + k], expected, 1e-14)); } } gkyl_array_release(a2_ho); - if (on_gpu) gkyl_array_release(a2); + if (on_gpu) { + gkyl_array_release(a2); + } } void test_array_opcombine_ho() { - struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 1, 10); + struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 1, 10); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 1, 10); - double *a1_d = a1->data, *a2_d = a2->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; - a2_d[i] = i*0.1; + double *a1_d = a1->data, *a2_d = a2->data; + for (unsigned i = 0; i < a1->size; ++i) { + a1_d[i] = i * 1.0; + a2_d[i] = i * 0.1; } // a1 <- 0.25*(a1 + 0.5*a2) gkyl_array_scale(gkyl_array_set(a1, 0.5, a2), 0.25); - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(a1_d[i], 0.25*0.5*i*0.1, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(a1_d[i], 0.25 * 0.5 * i * 0.1, 1e-14)); + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -776,18 +900,20 @@ void test_array_ops_comp_ho() // more than 1 "component" in array int nc = 5; // number of "components" struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, nc, 10); - for (unsigned i=0; isize; ++i) { + for (unsigned i = 0; i < arr->size; ++i) { double *d = gkyl_array_fetch(arr, i); - for (int k=0; ksize; ++i) { + for (unsigned i = 0; i < arr->size; ++i) { const double *d = gkyl_array_fetch(arr, i); - for (int k=0; kdata; - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(a1_d[i], 0.5, 1e-14) ); + double *a1_d = a1->data; + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(a1_d[i], 0.5, 1e-14)); + } gkyl_array_release(a1); gkyl_array_release(a1_cu); @@ -1179,9 +1321,10 @@ void test_array_clear_range_dev() // copy from device and check if things are ok gkyl_array_copy(a1, a1_cu); - double *a1_d = a1->data; - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(a1_d[i], 0.5, 1e-14) ); + double *a1_d = a1->data; + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(a1_d[i], 0.5, 1e-14)); + } gkyl_array_release(a1); gkyl_array_release(a1_cu); @@ -1189,7 +1332,7 @@ void test_array_clear_range_dev() void test_array_accumulate_dev() { - // create host arrays + // create host arrays struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 1, 10); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 1, 10); // make device copies @@ -1197,10 +1340,10 @@ void test_array_accumulate_dev() struct gkyl_array *a2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, 10); // initialize data - double *a1_d = a1->data, *a2_d = a2->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; - a2_d[i] = i*0.1; + double *a1_d = a1->data, *a2_d = a2->data; + for (unsigned i = 0; i < a1->size; ++i) { + a1_d[i] = i * 1.0; + a2_d[i] = i * 0.1; } // copy initialized arrays to device @@ -1211,8 +1354,9 @@ void test_array_accumulate_dev() // copy from device and check if things are ok gkyl_array_copy(a1, a1_cu); - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(a1_d[i], i*1.0+0.5*i*0.1, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(a1_d[i], i * 1.0 + 0.5 * i * 0.1, 1e-14)); + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -1225,7 +1369,7 @@ void test_array_accumulate_range_dev() int shape[] = {20, 10}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 8, range.volume); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3, range.volume); @@ -1234,12 +1378,14 @@ void test_array_accumulate_range_dev() struct gkyl_array *a2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3, range.volume); // initialize data - double *a1_d = a1->data, *a2_d = a2->data; - for (unsigned i=0; isize; ++i) { - for(unsigned c=0; cncomp; ++c) - a1_d[c+a1->ncomp*i] = i*1.0 + .01*c; - for(unsigned c=0; cncomp; ++c) - a2_d[c+a2->ncomp*i] = i*0.1 + .01*c; + double *a1_d = a1->data, *a2_d = a2->data; + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned c = 0; c < a1->ncomp; ++c) { + a1_d[c + a1->ncomp * i] = i * 1.0 + .01 * c; + } + for (unsigned c = 0; c < a2->ncomp; ++c) { + a2_d[c + a2->ncomp * i] = i * 0.1 + .01 * c; + } } // copy initialized arrays to device @@ -1249,19 +1395,20 @@ void test_array_accumulate_range_dev() // a1 = a1 + 0.5*a2 gkyl_array_accumulate_range(a1_cu, 0.5, a2_cu, &range); - // copy from device and check if things are ok + // copy from device and check if things are ok gkyl_array_copy(a1, a1_cu); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a1d = gkyl_array_fetch(a1, loc); - for (int c=0; cncomp; ++c) { - TEST_CHECK( gkyl_compare( a1d[c], (.01+.5*.01)*c + loc*1.0 + .5*loc*.1, 1e-14 ) ); + for (int c = 0; c < a2->ncomp; ++c) { + TEST_CHECK(gkyl_compare(a1d[c], (.01 + .5 * .01) * c + loc * 1.0 + .5 * loc * .1, 1e-14)); + } + for (int c = a2->ncomp; c < a1->ncomp; ++c) { + TEST_CHECK(a1d[c] == (.01) * c + loc * 1.0); } - for (int c=a2->ncomp; cncomp; ++c) - TEST_CHECK( a1d[c] == (.01)*c + loc*1.0 ); } // test a2 = a2 + 0.5*a @@ -1270,16 +1417,17 @@ void test_array_accumulate_range_dev() gkyl_array_accumulate_range(a2_cu, 0.5, a1_cu, &range); - // copy from device and check if things are ok + // copy from device and check if things are ok gkyl_array_copy(a2, a2_cu); gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a2d = gkyl_array_fetch(a2, loc); - for (int i=0; incomp; ++i) - TEST_CHECK( a2d[i] == 1.5 + 0.5*0.5 ); - } + for (int i = 0; i < a2->ncomp; ++i) { + TEST_CHECK(a2d[i] == 1.5 + 0.5 * 0.5); + } + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -1289,50 +1437,61 @@ void test_array_accumulate_range_dev() void test_array_accumulate_offset_dev() { - // create host arrays + // create host arrays struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 2, 10); - struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3*a1->ncomp, a1->size); + struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3 * a1->ncomp, a1->size); // make device copies struct gkyl_array *a1_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, a1->ncomp, a1->size); struct gkyl_array *a2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, a2->ncomp, a2->size); // initialize data - double *a1_d = a1->data, *a2_d = a2->data; - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - a1_d[i*a1->ncomp+j] = i*1.0+j; + double *a1_d = a1->data, *a2_d = a2->data; + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + a1_d[i * a1->ncomp + j] = i * 1.0 + j; + } + } - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp/a1->ncomp; ++j) - for (unsigned k=0; kncomp; ++k) - a2_d[i*a2->ncomp+j*a1->ncomp+k] = i*0.1+k; + for (unsigned i = 0; i < a2->size; ++i) { + for (unsigned j = 0; j < a2->ncomp / a1->ncomp; ++j) { + for (unsigned k = 0; k < a1->ncomp; ++k) { + a2_d[i * a2->ncomp + j * a1->ncomp + k] = i * 0.1 + k; + } + } + } // copy initialized arrays to device gkyl_array_copy(a1_cu, a1); gkyl_array_copy(a2_cu, a2); // test a1 = 0.1*a2[a1->ncomp] - gkyl_array_accumulate_offset(a1_cu, 0.5, a2_cu, 1*a1->ncomp); + gkyl_array_accumulate_offset(a1_cu, 0.5, a2_cu, 1 * a1->ncomp); gkyl_array_copy(a1, a1_cu); - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - TEST_CHECK( gkyl_compare(a1_d[i*a1->ncomp+j], i*1.0+j+0.5*(i*0.1+j), 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + TEST_CHECK(gkyl_compare(a1_d[i * a1->ncomp + j], i * 1.0 + j + 0.5 * (i * 0.1 + j), 1e-14)); + } + } // test a2[a1->ncomp] = 0.1*a1 - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - a1_d[i*a1->ncomp+j] = i*1.0+j; + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + a1_d[i * a1->ncomp + j] = i * 1.0 + j; + } + } gkyl_array_copy(a1_cu, a1); - gkyl_array_accumulate_offset(a2_cu, 0.5, a1_cu, 1*a1->ncomp); + gkyl_array_accumulate_offset(a2_cu, 0.5, a1_cu, 1 * a1->ncomp); gkyl_array_copy(a2, a2_cu); - for (unsigned i=0; isize; ++i) { - for (unsigned j=0; jncomp; ++j) { - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+0*a1->ncomp+j], i*0.1+j, 1e-14) ); - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+1*a1->ncomp+j], i*0.1+j+0.5*(i*1.0+j), 1e-14) ); - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+2*a1->ncomp+j], i*0.1+j, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + TEST_CHECK(gkyl_compare(a2_d[i * a2->ncomp + 0 * a1->ncomp + j], i * 0.1 + j, 1e-14)); + TEST_CHECK(gkyl_compare( + a2_d[i * a2->ncomp + 1 * a1->ncomp + j], i * 0.1 + j + 0.5 * (i * 1.0 + j), 1e-14 + )); + TEST_CHECK(gkyl_compare(a2_d[i * a2->ncomp + 2 * a1->ncomp + j], i * 0.1 + j, 1e-14)); } } @@ -1347,22 +1506,25 @@ void test_array_accumulate_offset_range_dev() int shape[] = {20, 10}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 2, range.volume); - struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3*a1->ncomp, range.volume); + struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3 * a1->ncomp, range.volume); // make device copies of arrays struct gkyl_array *a1_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, a1->ncomp, range.volume); struct gkyl_array *a2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, a2->ncomp, range.volume); // initialize data - double *a1_d = a1->data, *a2_d = a2->data; - for (unsigned i=0; isize; ++i) { - for(unsigned c=0; cncomp; ++c) - a1_d[i*a1->ncomp+c] = i*1.0 + .01*c; - for(unsigned j=0; jncomp/a1->ncomp; ++j) - for(unsigned c=0; cncomp; ++c) - a2_d[i*a2->ncomp+j*a1->ncomp+c] = i*0.1 + .01*c; + double *a1_d = a1->data, *a2_d = a2->data; + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned c = 0; c < a1->ncomp; ++c) { + a1_d[i * a1->ncomp + c] = i * 1.0 + .01 * c; + } + for (unsigned j = 0; j < a2->ncomp / a1->ncomp; ++j) { + for (unsigned c = 0; c < a1->ncomp; ++c) { + a2_d[i * a2->ncomp + j * a1->ncomp + c] = i * 0.1 + .01 * c; + } + } } // copy initialized arrays to device @@ -1370,7 +1532,7 @@ void test_array_accumulate_offset_range_dev() gkyl_array_copy(a2_cu, a2); // a1 = a1 + 0.5*a2[1*a1->ncomp] - gkyl_array_accumulate_offset_range(a1_cu, 0.5, a2_cu, 1*a1->ncomp, &range); + gkyl_array_accumulate_offset_range(a1_cu, 0.5, a2_cu, 1 * a1->ncomp, &range); gkyl_array_copy(a1, a1_cu); struct gkyl_range_iter iter; @@ -1378,27 +1540,28 @@ void test_array_accumulate_offset_range_dev() while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a1d = gkyl_array_fetch(a1, loc); - for (int c=0; cncomp; ++c) - TEST_CHECK( gkyl_compare( a1d[c], loc*1.0+.01*c + 0.5*(loc*0.1+0.01*c), 1e-14 ) ); + for (int c = 0; c < a1->ncomp; ++c) { + TEST_CHECK(gkyl_compare(a1d[c], loc * 1.0 + .01 * c + 0.5 * (loc * 0.1 + 0.01 * c), 1e-14)); + } } // test a2[1*a1->ncomp] = a2[1*a1->ncomp] + 0.5*a1 gkyl_array_clear(a1_cu, 0.5); gkyl_array_clear(a2_cu, 1.5); - gkyl_array_accumulate_offset_range(a2_cu, 0.5, a1_cu, 1*a1->ncomp, &range); + gkyl_array_accumulate_offset_range(a2_cu, 0.5, a1_cu, 1 * a1->ncomp, &range); gkyl_array_copy(a2, a2_cu); gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a2d = gkyl_array_fetch(a2, loc); - for (int i=0; incomp; ++i) { - TEST_CHECK( a2d[i+0*a1->ncomp] == 1.5 ); - TEST_CHECK( a2d[i+1*a1->ncomp] == 1.5+0.5*0.5 ); - TEST_CHECK( a2d[i+2*a1->ncomp] == 1.5 ); + for (int i = 0; i < a1->ncomp; ++i) { + TEST_CHECK(a2d[i + 0 * a1->ncomp] == 1.5); + TEST_CHECK(a2d[i + 1 * a1->ncomp] == 1.5 + 0.5 * 0.5); + TEST_CHECK(a2d[i + 2 * a1->ncomp] == 1.5); } - } + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -1408,11 +1571,11 @@ void test_array_accumulate_offset_range_dev() void test_array_accumulate_range_4d_dev() { - int lower[] = { 1, 1, 1, 1 }; - int upper[] = { 46, 46, 32, 32}; + int lower[] = {1, 1, 1, 1}; + int upper[] = {46, 46, 32, 32}; struct gkyl_range range; gkyl_range_init(&range, 4, lower, upper); - + struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 8, range.volume); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3, range.volume); @@ -1423,33 +1586,35 @@ void test_array_accumulate_range_4d_dev() // initialize data gkyl_array_clear(a1, 0.5); gkyl_array_clear(a2, 1.5); - + // copy initialized arrays to device gkyl_array_copy(a1_cu, a1); gkyl_array_copy(a2_cu, a2); - int slower[] = { 2, 2, 1, 1 }; - int supper[] = { 45, 45, 32, 32 }; + int slower[] = {2, 2, 1, 1}; + int supper[] = {45, 45, 32, 32}; struct gkyl_range sub_range; gkyl_sub_range_init(&sub_range, &range, slower, supper); // a1 = a1 + 0.5*a2 (only first 3 components of a1 are modified) gkyl_array_accumulate_range(a1_cu, 0.5, a2_cu, &sub_range); - // copy from device and check if things are ok - gkyl_array_clear(a1, 0.0); + // copy from device and check if things are ok + gkyl_array_clear(a1, 0.0); gkyl_array_copy(a1, a1_cu); - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &sub_range); - + while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a1d = gkyl_array_fetch(a1, loc); - for (int c=0; c<3; ++c) - TEST_CHECK( a1d[c] == 0.5 + 0.5*1.5 ); - for (int c=3; c<8; ++c) - TEST_CHECK( a1d[c] == 0.5 ); + for (int c = 0; c < 3; ++c) { + TEST_CHECK(a1d[c] == 0.5 + 0.5 * 1.5); + } + for (int c = 3; c < 8; ++c) { + TEST_CHECK(a1d[c] == 0.5); + } } gkyl_array_release(a1); @@ -1460,7 +1625,7 @@ void test_array_accumulate_range_4d_dev() void test_array_combine_dev() { - // create host arrays + // create host arrays struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 1, 10); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 1, 10); struct gkyl_array *b = gkyl_array_new(GKYL_DOUBLE, 1, 10); @@ -1470,10 +1635,10 @@ void test_array_combine_dev() struct gkyl_array *a2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, 10); struct gkyl_array *b_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, 10); - double *a1_d = a1->data, *a2_d = a2->data, *b_d = b->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; - a2_d[i] = i*0.1; + double *a1_d = a1->data, *a2_d = a2->data, *b_d = b->data; + for (unsigned i = 0; i < a1->size; ++i) { + a1_d[i] = i * 1.0; + a2_d[i] = i * 0.1; b_d[i] = 10.5; } @@ -1488,8 +1653,9 @@ void test_array_combine_dev() // copy from device and check if things are ok gkyl_array_copy(b, b_cu); - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(b_d[i], 0.5*i*1.0+2.5*i*0.1, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(b_d[i], 0.5 * i * 1.0 + 2.5 * i * 0.1, 1e-14)); + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -1501,7 +1667,7 @@ void test_array_combine_dev() void test_array_set_dev() { - // create host arrays + // create host arrays struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 1, 10); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 1, 10); // make device copies @@ -1509,10 +1675,10 @@ void test_array_set_dev() struct gkyl_array *a2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, 10); // initialize data - double *a1_d = a1->data, *a2_d = a2->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; - a2_d[i] = i*0.1; + double *a1_d = a1->data, *a2_d = a2->data; + for (unsigned i = 0; i < a1->size; ++i) { + a1_d[i] = i * 1.0; + a2_d[i] = i * 0.1; } // copy initialized arrays to device @@ -1523,8 +1689,9 @@ void test_array_set_dev() // copy from device and check if things are ok gkyl_array_copy(a1, a1_cu); - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(a1_d[i], 0.5*i*0.1, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(a1_d[i], 0.5 * i * 0.1, 1e-14)); + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -1537,7 +1704,7 @@ void test_array_set_range_dev() int shape[] = {10, 20}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 8, range.volume); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3, range.volume); @@ -1555,18 +1722,20 @@ void test_array_set_range_dev() gkyl_array_set_range(a1_cu, 0.5, a2_cu, &range); - // copy from device and check if things are ok + // copy from device and check if things are ok gkyl_array_copy(a1, a1_cu); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a1d = gkyl_array_fetch(a1, loc); - for (int i=0; i<3; ++i) - TEST_CHECK( a1d[i] == 0.5*1.5 ); - for (int i=3; i<8; ++i) - TEST_CHECK( a1d[i] == 0.5); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(a1d[i] == 0.5 * 1.5); + } + for (int i = 3; i < 8; ++i) { + TEST_CHECK(a1d[i] == 0.5); + } } // test a2 = 0.5*a1 @@ -1578,13 +1747,14 @@ void test_array_set_range_dev() // copy from device and check if things are ok gkyl_array_copy(a2, a2_cu); gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a2d = gkyl_array_fetch(a2, loc); - for (int i=0; i<3; ++i) - TEST_CHECK( a2d[i] == 0.5*0.5 ); - } + for (int i = 0; i < 3; ++i) { + TEST_CHECK(a2d[i] == 0.5 * 0.5); + } + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -1594,50 +1764,59 @@ void test_array_set_range_dev() void test_array_set_offset_dev() { - // create host arrays + // create host arrays struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 2, 10); - struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3*a1->ncomp, a1->size); + struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3 * a1->ncomp, a1->size); // make device copies struct gkyl_array *a1_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, a1->ncomp, a1->size); struct gkyl_array *a2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, a2->ncomp, a2->size); // initialize data - double *a1_d = a1->data, *a2_d = a2->data; - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - a1_d[i*a1->ncomp+j] = i*1.0+j; + double *a1_d = a1->data, *a2_d = a2->data; + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + a1_d[i * a1->ncomp + j] = i * 1.0 + j; + } + } - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp/a1->ncomp; ++j) - for (unsigned k=0; kncomp; ++k) - a2_d[i*a2->ncomp+j*a1->ncomp+k] = i*0.1+k; + for (unsigned i = 0; i < a2->size; ++i) { + for (unsigned j = 0; j < a2->ncomp / a1->ncomp; ++j) { + for (unsigned k = 0; k < a1->ncomp; ++k) { + a2_d[i * a2->ncomp + j * a1->ncomp + k] = i * 0.1 + k; + } + } + } // copy initialized arrays to device gkyl_array_copy(a1_cu, a1); gkyl_array_copy(a2_cu, a2); // test a1 = 0.5*a2[a1->ncomp] - gkyl_array_set_offset(a1_cu, 0.5, a2_cu, 1*a1->ncomp); + gkyl_array_set_offset(a1_cu, 0.5, a2_cu, 1 * a1->ncomp); gkyl_array_copy(a1, a1_cu); - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - TEST_CHECK( gkyl_compare(a1_d[i*a1->ncomp+j], 0.5*(i*0.1+j), 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + TEST_CHECK(gkyl_compare(a1_d[i * a1->ncomp + j], 0.5 * (i * 0.1 + j), 1e-14)); + } + } // test a2[a1->ncomp] = 0.1*a1 - for (unsigned i=0; isize; ++i) - for (unsigned j=0; jncomp; ++j) - a1_d[i*a1->ncomp+j] = i*1.0+j; + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + a1_d[i * a1->ncomp + j] = i * 1.0 + j; + } + } gkyl_array_copy(a1_cu, a1); - gkyl_array_set_offset(a2_cu, 0.5, a1_cu, 1*a1->ncomp); + gkyl_array_set_offset(a2_cu, 0.5, a1_cu, 1 * a1->ncomp); gkyl_array_copy(a2, a2_cu); - for (unsigned i=0; isize; ++i) { - for (unsigned j=0; jncomp; ++j) { - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+0*a1->ncomp+j], i*0.1+j, 1e-14) ); - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+1*a1->ncomp+j], 0.5*(i*1.0+j), 1e-14) ); - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+2*a1->ncomp+j], i*0.1+j, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + for (unsigned j = 0; j < a1->ncomp; ++j) { + TEST_CHECK(gkyl_compare(a2_d[i * a2->ncomp + 0 * a1->ncomp + j], i * 0.1 + j, 1e-14)); + TEST_CHECK(gkyl_compare(a2_d[i * a2->ncomp + 1 * a1->ncomp + j], 0.5 * (i * 1.0 + j), 1e-14)); + TEST_CHECK(gkyl_compare(a2_d[i * a2->ncomp + 2 * a1->ncomp + j], i * 0.1 + j, 1e-14)); } } @@ -1652,9 +1831,9 @@ void test_array_set_offset_range_dev() int shape[] = {10, 20}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *a1 = gkyl_array_new(GKYL_DOUBLE, 2, range.volume); - struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3*a1->ncomp, range.volume); + struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 3 * a1->ncomp, range.volume); // make device copies of arrays struct gkyl_array *a1_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, a1->ncomp, range.volume); @@ -1668,7 +1847,7 @@ void test_array_set_offset_range_dev() gkyl_array_clear(a1_cu, 0.5); gkyl_array_clear(a2_cu, 1.5); - gkyl_array_set_offset_range(a1_cu, 0.5, a2_cu, 1*a1->ncomp, &range); + gkyl_array_set_offset_range(a1_cu, 0.5, a2_cu, 1 * a1->ncomp, &range); gkyl_array_copy(a1, a1_cu); struct gkyl_range_iter iter; @@ -1676,27 +1855,28 @@ void test_array_set_offset_range_dev() while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a1d = gkyl_array_fetch(a1, loc); - for (int i=0; incomp; ++i) - TEST_CHECK( a1d[i] == 0.5*1.5 ); + for (int i = 0; i < a1->ncomp; ++i) { + TEST_CHECK(a1d[i] == 0.5 * 1.5); + } } // test a2[a1->ncomp] = 0.5*a1 gkyl_array_clear(a1_cu, 0.5); gkyl_array_clear(a2_cu, 1.5); - gkyl_array_set_offset_range(a2_cu, 0.5, a1_cu, 1*a1->ncomp, &range); + gkyl_array_set_offset_range(a2_cu, 0.5, a1_cu, 1 * a1->ncomp, &range); gkyl_array_copy(a2, a2_cu); gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&range, iter.idx); double *a2d = gkyl_array_fetch(a2, loc); - for (int i=0; incomp; ++i) { - TEST_CHECK( a2d[i+0*a1->ncomp] == 1.5 ); - TEST_CHECK( a2d[i+1*a1->ncomp] == 0.5*0.5 ); - TEST_CHECK( a2d[i+2*a1->ncomp] == 1.5 ); + for (int i = 0; i < a1->ncomp; ++i) { + TEST_CHECK(a2d[i + 0 * a1->ncomp] == 1.5); + TEST_CHECK(a2d[i + 1 * a1->ncomp] == 0.5 * 0.5); + TEST_CHECK(a2d[i + 2 * a1->ncomp] == 1.5); } - } + } gkyl_array_release(a1); gkyl_array_release(a2); @@ -1711,9 +1891,9 @@ void test_array_scale_dev() struct gkyl_array *a1_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, 10); // initialize data - double *a1_d = a1->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; + double *a1_d = a1->data; + for (unsigned i = 0; i < a1->size; ++i) { + a1_d[i] = i * 1.0; } // copy host arrays to device @@ -1721,10 +1901,11 @@ void test_array_scale_dev() gkyl_array_scale(a1_cu, 0.25); - // copy from device and check if things are ok + // copy from device and check if things are ok gkyl_array_copy(a1, a1_cu); - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(a1_d[i], i*0.25, 1e-14) ); + for (unsigned i = 0; i < a1->size; ++i) { + TEST_CHECK(gkyl_compare(a1_d[i], i * 0.25, 1e-14)); + } gkyl_array_release(a1); gkyl_array_release(a1_cu); @@ -1739,13 +1920,13 @@ void test_array_scale_by_cell_dev() struct gkyl_array *s_ho = mkarr(false, s->ncomp, s->size); // initialize data - double *a1_d = a1_ho->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; + double *a1_d = a1_ho->data; + for (unsigned i = 0; i < a1_ho->size; ++i) { + a1_d[i] = i * 1.0; } - double *s_d = s_ho->data; - for (unsigned i=0; isize; ++i) { - s_d[i] = i*1.0; + double *s_d = s_ho->data; + for (unsigned i = 0; i < s_ho->size; ++i) { + s_d[i] = i * 1.0; } // Copy host arrays to device. @@ -1756,9 +1937,9 @@ void test_array_scale_by_cell_dev() // Copy from device and check if things are ok. gkyl_array_copy(a1_ho, a1); - for (unsigned i=0; isize; ++i) { - int fact = (i/a1_ho->ncomp); - TEST_CHECK( gkyl_compare(a1_d[i], i*1.0*fact, 1e-14) ); + for (unsigned i = 0; i < a1_ho->size; ++i) { + int fact = (i / a1_ho->ncomp); + TEST_CHECK(gkyl_compare(a1_d[i], i * 1.0 * fact, 1e-14)); } gkyl_array_release(a1); @@ -1776,13 +1957,13 @@ void test_cu_array_divide_by_cell() struct gkyl_array *s_ho = mkarr(false, s->ncomp, s->size); // initialize data - double *a1_d = a1_ho->data; - for (unsigned i=0; isize; ++i) { - a1_d[i] = i*1.0; + double *a1_d = a1_ho->data; + for (unsigned i = 0; i < a1_ho->size; ++i) { + a1_d[i] = i * 1.0; } - double *s_d = s_ho->data; - for (unsigned i=0; isize; ++i) { - s_d[i] = i*1.0; + double *s_d = s_ho->data; + for (unsigned i = 0; i < s_ho->size; ++i) { + s_d[i] = i * 1.0; } // Copy host arrays to device. @@ -1793,9 +1974,9 @@ void test_cu_array_divide_by_cell() // Copy from device and check if things are ok. gkyl_array_copy(a1_ho, a1); - for (unsigned i=0; isize; ++i) { - int fact = (i/a1_ho->ncomp); - TEST_CHECK( gkyl_compare(a1_d[i], i*1.0/fact, 1e-14) ); + for (unsigned i = 0; i < a1_ho->size; ++i) { + int fact = (i / a1_ho->ncomp); + TEST_CHECK(gkyl_compare(a1_d[i], i * 1.0 / fact, 1e-14)); } gkyl_array_release(a1); @@ -1813,9 +1994,11 @@ void test_array_shiftc_dev() struct gkyl_array *a1_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3, 10); // initialize data - double *a1_d = a1->data; - for (unsigned i=0; isize; ++i) { - for (size_t k=0; kncomp; ++k) a1_d[i*a1->ncomp+k] = i*2.0+k; + double *a1_d = a1->data; + for (unsigned i = 0; i < a1->size; ++i) { + for (size_t k = 0; k < a1->ncomp; ++k) { + a1_d[i * a1->ncomp + k] = i * 2.0 + k; + } } // copy host arrays to device @@ -1825,10 +2008,11 @@ void test_array_shiftc_dev() // copy from device and check if things are ok gkyl_array_copy(a1, a1_cu); - TEST_CHECK( gkyl_compare(a1_d[0], 0*1.0+0-0.5, 1e-14) ); - for (unsigned i=0; isize; ++i) { - for (size_t k=1; kncomp; ++k) - TEST_CHECK( gkyl_compare(a1_d[i*a1->ncomp+k], i*2.0+k, 1e-14) ); + TEST_CHECK(gkyl_compare(a1_d[0], 0 * 1.0 + 0 - 0.5, 1e-14)); + for (unsigned i = 0; i < a1->size; ++i) { + for (size_t k = 1; k < a1->ncomp; ++k) { + TEST_CHECK(gkyl_compare(a1_d[i * a1->ncomp + k], i * 2.0 + k, 1e-14)); + } } gkyl_array_release(a1); @@ -1836,30 +2020,37 @@ void test_array_shiftc_dev() // Repeat the test but shifting another coefficient as well. int shiftks[] = {0, 2}; - int nks = sizeof(shiftks)/sizeof(shiftks[0]); + int nks = sizeof(shiftks) / sizeof(shiftks[0]); struct gkyl_array *a2 = gkyl_array_new(GKYL_DOUBLE, 4, 8); struct gkyl_array *a2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 4, 8); double *a2_d = a2->data; - for (unsigned i=0; isize; ++i) { - for (size_t k=0; kncomp; ++k) a2_d[i*a2->ncomp+k] = i*2.0+k; + for (unsigned i = 0; i < a2->size; ++i) { + for (size_t k = 0; k < a2->ncomp; ++k) { + a2_d[i * a2->ncomp + k] = i * 2.0 + k; + } } gkyl_array_copy(a2_cu, a2); - for (size_t l=0; lsize; ++i) { - for (size_t k=0; kncomp; ++k) { + for (unsigned i = 0; i < a2->size; ++i) { + for (size_t k = 0; k < a2->ncomp; ++k) { bool isshifted = false; - for (size_t l=0; lncomp + k], i * 2.0 + k + s, 1e-14)); + } else { + TEST_CHECK(gkyl_compare(a2_d[i * a2->ncomp + k], i * 2.0 + k, 1e-14)); } - if (isshifted) - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+k], i*2.0+k+s, 1e-14) ); - else - TEST_CHECK( gkyl_compare(a2_d[i*a2->ncomp+k], i*2.0+k, 1e-14) ); } } @@ -1876,10 +2067,12 @@ void test_array_invert_by_cell_dev() // Set values: 1.0, 2.0, 4.0, 5.0, 10.0, 0.5, 0.25, 0.1 double test_vals[] = {1.0, 2.0, 4.0, 5.0, 10.0, 0.5, 0.25, 0.1}; double expected_inv[] = {1.0, 0.5, 0.25, 0.2, 0.1, 2.0, 4.0, 10.0}; - - for (unsigned i=0; isize; ++i) - for (size_t k=0; kncomp; ++k) - a1_ho_d[i*a1_ho->ncomp+k] = test_vals[i]; + + for (unsigned i = 0; i < a1_ho->size; ++i) { + for (size_t k = 0; k < a1_ho->ncomp; ++k) { + a1_ho_d[i * a1_ho->ncomp + k] = test_vals[i]; + } + } // Copy to device gkyl_array_copy(a1, a1_ho); @@ -1890,9 +2083,11 @@ void test_array_invert_by_cell_dev() gkyl_array_copy(a1_ho, a1); // Check inverted values - for (unsigned i=0; isize; ++i) - for (size_t k=0; kncomp; ++k) - TEST_CHECK( gkyl_compare(a1_ho_d[i*a1_ho->ncomp+k], expected_inv[i], 1e-14) ); + for (unsigned i = 0; i < a1_ho->size; ++i) { + for (size_t k = 0; k < a1_ho->ncomp; ++k) { + TEST_CHECK(gkyl_compare(a1_ho_d[i * a1_ho->ncomp + k], expected_inv[i], 1e-14)); + } + } gkyl_array_release(a1_ho); gkyl_array_release(a1); @@ -1903,7 +2098,7 @@ void test_array_copy_buffer_dev() int shape[] = {10, 20}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, 1, range.volume); // make device copies of arrays struct gkyl_array *arr_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, range.volume); @@ -1913,7 +2108,7 @@ void test_array_copy_buffer_dev() gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { double *d = gkyl_array_fetch(arr, gkyl_range_idx(&range, iter.idx)); - d[0] = iter.idx[0] + 10.5*iter.idx[1]; + d[0] = iter.idx[0] + 10.5 * iter.idx[1]; } // copy host array to device @@ -1923,7 +2118,7 @@ void test_array_copy_buffer_dev() struct gkyl_range sub_range; gkyl_sub_range_init(&sub_range, &range, lower, upper); - double *buff_cu = gkyl_cu_malloc(sizeof(double)*sub_range.volume); + double *buff_cu = gkyl_cu_malloc(sizeof(double) * sub_range.volume); gkyl_array_copy_to_buffer(buff_cu, arr_cu, &sub_range); gkyl_array_clear(arr, 0.0); @@ -1935,7 +2130,7 @@ void test_array_copy_buffer_dev() gkyl_range_iter_init(&iter, &sub_range); while (gkyl_range_iter_next(&iter)) { double *d = gkyl_array_fetch(arr, gkyl_range_idx(&sub_range, iter.idx)); - TEST_CHECK( d[0] == iter.idx[0] + 10.5*iter.idx[1] ); + TEST_CHECK(d[0] == iter.idx[0] + 10.5 * iter.idx[1]); } gkyl_array_release(arr); @@ -1951,7 +2146,7 @@ void test_array_copy_buffer_fn_dev() int shape[] = {10, 20}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, 1, range.volume); // make device copy of array @@ -1961,7 +2156,7 @@ void test_array_copy_buffer_fn_dev() gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { double *d = gkyl_array_fetch(arr, gkyl_range_idx(&range, iter.idx)); - d[0] = iter.idx[0] + 10.5*iter.idx[1]; + d[0] = iter.idx[0] + 10.5 * iter.idx[1]; } // copy host array to device @@ -1974,8 +2169,8 @@ void test_array_copy_buffer_fn_dev() // create function pointer on device struct gkyl_array_copy_func *fn = gkyl_cu_malloc(sizeof(*fn)); set_array_copy_fn(fn); - - double *buff_cu = gkyl_cu_malloc(sizeof(double)*sub_range.volume); + + double *buff_cu = gkyl_cu_malloc(sizeof(double) * sub_range.volume); gkyl_array_copy_to_buffer_fn_cu(buff_cu, arr_cu, &sub_range, fn); // copy back from buffer gkyl_array_copy_from_buffer(arr_cu, buff_cu, &sub_range); @@ -1985,7 +2180,7 @@ void test_array_copy_buffer_fn_dev() gkyl_range_iter_init(&iter, &sub_range); while (gkyl_range_iter_next(&iter)) { double *d = gkyl_array_fetch(arr, gkyl_range_idx(&sub_range, iter.idx)); - TEST_CHECK( d[0] == 2*(iter.idx[0] + 10.5*iter.idx[1]) ); + TEST_CHECK(d[0] == 2 * (iter.idx[0] + 10.5 * iter.idx[1])); } gkyl_array_release(arr); @@ -1999,7 +2194,7 @@ void test_array_flip_copy_buffer_fn_dev() int shape[] = {10, 20}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - + struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, 1, range.volume); // make device copy of array @@ -2009,7 +2204,7 @@ void test_array_flip_copy_buffer_fn_dev() gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { double *d = gkyl_array_fetch(arr, gkyl_range_idx(&range, iter.idx)); - d[0] = iter.idx[0] + 10.5*iter.idx[1]; + d[0] = iter.idx[0] + 10.5 * iter.idx[1]; } // copy host array to device gkyl_array_copy(arr_cu, arr); @@ -2021,8 +2216,8 @@ void test_array_flip_copy_buffer_fn_dev() // create function pointer on device struct gkyl_array_copy_func *fn = gkyl_cu_malloc(sizeof(*fn)); set_array_copy_fn(fn); - - double *buff_cu = gkyl_cu_malloc(sizeof(double)*sub_range.volume); + + double *buff_cu = gkyl_cu_malloc(sizeof(double) * sub_range.volume); // test flip copy on first direction of 2D array gkyl_array_flip_copy_to_buffer_fn_cu(buff_cu, arr_cu, 0, &sub_range, fn); @@ -2031,24 +2226,24 @@ void test_array_flip_copy_buffer_fn_dev() // copy back from buffer gkyl_array_copy_from_buffer(arr_cu, buff_cu, &sub_range); - gkyl_array_clear(arr, 0.0); + gkyl_array_clear(arr, 0.0); // copy from device and check if things are ok gkyl_array_copy(arr, arr_cu); gkyl_range_iter_init(&iter, &sub_range); while (gkyl_range_iter_next(&iter)) { double *d = gkyl_array_fetch(arr, gkyl_range_idx(&sub_range, iter.idx)); - TEST_CHECK( d[0] == 2*((5+1)-iter.idx[0] + 10.5*iter.idx[1]) ); + TEST_CHECK(d[0] == 2 * ((5 + 1) - iter.idx[0] + 10.5 * iter.idx[1])); } // re-initialize the array gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { double *d = gkyl_array_fetch(arr, gkyl_range_idx(&range, iter.idx)); - d[0] = iter.idx[0] + 10.5*iter.idx[1]; + d[0] = iter.idx[0] + 10.5 * iter.idx[1]; } // copy host array to device gkyl_array_copy(arr_cu, arr); - + // test flip copy on second direction of 2D array gkyl_array_flip_copy_to_buffer_fn(buff_cu, arr_cu, 1, &sub_range, fn); @@ -2063,7 +2258,7 @@ void test_array_flip_copy_buffer_fn_dev() while (gkyl_range_iter_next(&iter)) { double *d = gkyl_array_fetch(arr, gkyl_range_idx(&sub_range, iter.idx)); //printf("%lg %lg\n", d[0], 2*(iter.idx[0] + 10.5*((10+1)-iter.idx[1])) ); - TEST_CHECK( d[0] == 2*(iter.idx[0] + 10.5*((10+1)-iter.idx[1])) ); + TEST_CHECK(d[0] == 2 * (iter.idx[0] + 10.5 * ((10 + 1) - iter.idx[1]))); } gkyl_array_release(arr); @@ -2083,13 +2278,13 @@ void test_array_copy_range_dev() // make device copies of arrays struct gkyl_array *a1_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 10, range.volume); - struct gkyl_array *a2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 10, range.volume); - + struct gkyl_array *a2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 10, range.volume); + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { double *d = gkyl_array_fetch(a1, gkyl_range_idx(&range, iter.idx)); - d[0] = iter.idx[0] + 10.5*iter.idx[1]; + d[0] = iter.idx[0] + 10.5 * iter.idx[1]; } // copy host array to device @@ -2104,18 +2299,18 @@ void test_array_copy_range_dev() gkyl_range_iter_init(&iter, &range); while (gkyl_range_iter_next(&iter)) { double *d = gkyl_array_fetch(a2, gkyl_range_idx(&range, iter.idx)); - TEST_CHECK( d[0] == iter.idx[0] + 10.5*iter.idx[1] ); + TEST_CHECK(d[0] == iter.idx[0] + 10.5 * iter.idx[1]); } // clear array for second test gkyl_array_clear_cu(a2_cu, 0.0); // initialize left sub-range - int lower_l[] = {range.lower[0], range.lower[1]}, upper_l[] = {range.lower[0], shape[1]/2-1}; + int lower_l[] = {range.lower[0], range.lower[1]}, upper_l[] = {range.lower[0], shape[1] / 2 - 1}; struct gkyl_range sub_range_l; gkyl_sub_range_init(&sub_range_l, &range, lower_l, upper_l); - + // initialize right sub-range - int lower_r[] = {range.upper[0], shape[1]/2}, upper_r[] = {range.upper[0], range.upper[1]}; + int lower_r[] = {range.upper[0], shape[1] / 2}, upper_r[] = {range.upper[0], range.upper[1]}; struct gkyl_range sub_range_r; gkyl_sub_range_init(&sub_range_r, &range, lower_r, upper_r); @@ -2126,10 +2321,12 @@ void test_array_copy_range_dev() gkyl_range_iter_init(&iter, &sub_range_r); while (gkyl_range_iter_next(&iter)) { int idx_l[GKYL_MAX_DIM]; - idx_l[0] = range.lower[0], idx_l[1] = iter.idx[1]-shape[1]/2; + idx_l[0] = range.lower[0], idx_l[1] = iter.idx[1] - shape[1] / 2; double *d = gkyl_array_fetch(a2, gkyl_range_idx(&sub_range_r, iter.idx)); - TEST_CHECK( d[0] == idx_l[0] + 10.5*idx_l[1] ); - TEST_MSG("Expected: %.13e in cell (%d,%d)", iter.idx[0] + 10.5*iter.idx[1], iter.idx[0], iter.idx[1]); + TEST_CHECK(d[0] == idx_l[0] + 10.5 * idx_l[1]); + TEST_MSG( + "Expected: %.13e in cell (%d,%d)", iter.idx[0] + 10.5 * iter.idx[1], iter.idx[0], iter.idx[1] + ); TEST_MSG("Produced: %.13e", d[0]); } @@ -2139,76 +2336,81 @@ void test_array_copy_range_dev() gkyl_array_release(a2_cu); } -void test_array_shiftc_range_dev() { +void test_array_shiftc_range_dev() +{ test_array_shiftc_range(true); } -void test_array_copy_range_to_range_diff_range_dim_dev() { +void test_array_copy_range_to_range_diff_range_dim_dev() +{ test_array_copy_range_to_range_diff_range_dim(true); } -void test_array_min_by_cell_dev() { +void test_array_min_by_cell_dev() +{ test_array_min_by_cell(true); } -void test_array_min_range_dev() { +void test_array_min_range_dev() +{ test_array_min_range(true); } #endif TEST_LIST = { - { "array_clear_ho", test_array_clear_ho }, - { "array_clear_range_ho", test_array_clear_range_ho }, - { "array_accumulate_ho", test_array_accumulate_ho }, - { "array_accumulate_range_ho", test_array_accumulate_range_ho }, - { "array_accumulate_offset_ho", test_array_accumulate_offset_ho }, - { "array_accumulate_offset_range_ho", test_array_accumulate_offset_range_ho }, - { "array_combine_ho", test_array_combine_ho }, - { "array_set_ho", test_array_set_ho }, - { "array_set_range_ho", test_array_set_range_ho }, - { "array_set_offset_ho", test_array_set_offset_ho }, - { "array_set_offset_range_ho", test_array_set_offset_range_ho }, - { "array_scale_ho", test_array_scale_ho }, - { "array_scale_by_cell_ho", test_array_scale_by_cell_ho }, - { "array_invert_by_cell_ho", test_array_invert_by_cell_ho }, - { "array_shiftc_ho", test_array_shiftc_ho }, - { "array_shiftc_range_ho", test_array_shiftc_range_ho }, - { "array_min_by_cell_ho", test_array_min_by_cell_ho }, - { "array_min_range_ho", test_array_min_range_ho }, - { "array_opcombine_ho", test_array_opcombine_ho }, - { "array_ops_comp_ho", test_array_ops_comp_ho }, - { "array_copy_buffer_ho", test_array_copy_buffer_ho }, - { "array_copy_buffer_fn_ho", test_array_copy_buffer_fn_ho }, - { "array_flip_copy_buffer_fn_ho", test_array_flip_copy_buffer_fn_ho }, - { "array_copy_range_ho", test_array_copy_range_ho}, - { "array_copy_split_ho", test_array_copy_split_ho }, - { "array_copy_range_to_range_diff_range_dim_ho", test_array_copy_range_to_range_diff_range_dim_ho}, + {"array_clear_ho", test_array_clear_ho}, + {"array_clear_range_ho", test_array_clear_range_ho}, + {"array_accumulate_ho", test_array_accumulate_ho}, + {"array_accumulate_range_ho", test_array_accumulate_range_ho}, + {"array_accumulate_offset_ho", test_array_accumulate_offset_ho}, + {"array_accumulate_offset_range_ho", test_array_accumulate_offset_range_ho}, + {"array_combine_ho", test_array_combine_ho}, + {"array_set_ho", test_array_set_ho}, + {"array_set_range_ho", test_array_set_range_ho}, + {"array_set_offset_ho", test_array_set_offset_ho}, + {"array_set_offset_range_ho", test_array_set_offset_range_ho}, + {"array_scale_ho", test_array_scale_ho}, + {"array_scale_by_cell_ho", test_array_scale_by_cell_ho}, + {"array_invert_by_cell_ho", test_array_invert_by_cell_ho}, + {"array_shiftc_ho", test_array_shiftc_ho}, + {"array_shiftc_range_ho", test_array_shiftc_range_ho}, + {"array_min_by_cell_ho", test_array_min_by_cell_ho}, + {"array_min_range_ho", test_array_min_range_ho}, + {"array_opcombine_ho", test_array_opcombine_ho}, + {"array_ops_comp_ho", test_array_ops_comp_ho}, + {"array_copy_buffer_ho", test_array_copy_buffer_ho}, + {"array_copy_buffer_fn_ho", test_array_copy_buffer_fn_ho}, + {"array_flip_copy_buffer_fn_ho", test_array_flip_copy_buffer_fn_ho}, + {"array_copy_range_ho", test_array_copy_range_ho}, + {"array_copy_split_ho", test_array_copy_split_ho}, + {"array_copy_range_to_range_diff_range_dim_ho", test_array_copy_range_to_range_diff_range_dim_ho}, #ifdef GKYL_HAVE_CUDA - { "array_clear_dev", test_array_clear_dev}, - { "array_clear_range_dev", test_array_clear_range_dev}, - { "array_accumulate_dev", test_array_accumulate_dev}, - { "array_accumulate_range_dev", test_array_accumulate_range_dev}, - { "array_accumulate_offset_dev", test_array_accumulate_offset_dev}, - { "array_accumulate_offset_range_dev", test_array_accumulate_offset_range_dev}, - { "array_accumulate_range_4d_dev", test_array_accumulate_range_4d_dev }, - { "array_combine_dev", test_array_combine_dev}, - { "array_set_dev", test_array_set_dev }, - { "array_set_range_dev", test_array_set_range_dev }, - { "array_set_offset_dev", test_array_set_offset_dev }, - { "array_set_offset_range_dev", test_array_set_offset_range_dev }, - { "array_scale_dev", test_array_scale_dev }, - { "array_scale_by_cell_dev", test_array_scale_by_cell_dev }, - { "array_invert_by_cell_dev", test_array_invert_by_cell_dev }, - { "array_shiftc_dev", test_array_shiftc_dev }, - { "array_shiftc_range_dev", test_array_shiftc_range_dev }, - { "array_min_by_cell_dev", test_array_min_by_cell_dev }, - { "array_min_by_cell_range_dev", test_array_min_range_dev }, - { "array_copy_buffer_dev", test_array_copy_buffer_dev }, - { "array_copy_buffer_fn_dev", test_array_copy_buffer_fn_dev }, - { "array_flip_copy_buffer_fn_dev", test_array_flip_copy_buffer_fn_dev }, - { "array_copy_range_dev", test_array_copy_range_dev }, - { "array_copy_range_to_range_diff_range_dim_dev", test_array_copy_range_to_range_diff_range_dim_dev}, + {"array_clear_dev", test_array_clear_dev}, + {"array_clear_range_dev", test_array_clear_range_dev}, + {"array_accumulate_dev", test_array_accumulate_dev}, + {"array_accumulate_range_dev", test_array_accumulate_range_dev}, + {"array_accumulate_offset_dev", test_array_accumulate_offset_dev}, + {"array_accumulate_offset_range_dev", test_array_accumulate_offset_range_dev}, + {"array_accumulate_range_4d_dev", test_array_accumulate_range_4d_dev}, + {"array_combine_dev", test_array_combine_dev}, + {"array_set_dev", test_array_set_dev}, + {"array_set_range_dev", test_array_set_range_dev}, + {"array_set_offset_dev", test_array_set_offset_dev}, + {"array_set_offset_range_dev", test_array_set_offset_range_dev}, + {"array_scale_dev", test_array_scale_dev}, + {"array_scale_by_cell_dev", test_array_scale_by_cell_dev}, + {"array_invert_by_cell_dev", test_array_invert_by_cell_dev}, + {"array_shiftc_dev", test_array_shiftc_dev}, + {"array_shiftc_range_dev", test_array_shiftc_range_dev}, + {"array_min_by_cell_dev", test_array_min_by_cell_dev}, + {"array_min_by_cell_range_dev", test_array_min_range_dev}, + {"array_copy_buffer_dev", test_array_copy_buffer_dev}, + {"array_copy_buffer_fn_dev", test_array_copy_buffer_fn_dev}, + {"array_flip_copy_buffer_fn_dev", test_array_flip_copy_buffer_fn_dev}, + {"array_copy_range_dev", test_array_copy_range_dev}, + {"array_copy_range_to_range_diff_range_dim_dev", test_array_copy_range_to_range_diff_range_dim_dev + }, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/core/unit/ctest_array_reduce.c b/core/unit/ctest_array_reduce.c index 153e1a2e61..48c535f707 100644 --- a/core/unit/ctest_array_reduce.c +++ b/core/unit/ctest_array_reduce.c @@ -18,19 +18,20 @@ void test_reduce_ho() int ncomp = 3, ncells = 200; struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, ncomp, ncells); - for (size_t i=0; isize; ++i) { + for (size_t i = 0; i < arr->size; ++i) { double *d = gkyl_array_fetch(arr, i); - for (size_t c=0; cdata; - for (unsigned i=0; idata; - for (unsigned i=0; idata; - for (unsigned i=0; idata; double *b1_d = b1->data; - for (unsigned i=0; idata; double *b1_d = b1->data; - for (unsigned i=0; i #include -void -test_ser_1d_members(struct gkyl_basis basis1) +void test_ser_1d_members(struct gkyl_basis basis1) { - TEST_CHECK( basis1.ndim == 1 ); - TEST_CHECK( basis1.poly_order == 1 ); - TEST_CHECK( basis1.num_basis == 2 ); - TEST_CHECK( strcmp(basis1.id, "serendipity") == 0 ); - TEST_CHECK( basis1.b_type == GKYL_BASIS_MODAL_SERENDIPITY ); + TEST_CHECK(basis1.ndim == 1); + TEST_CHECK(basis1.poly_order == 1); + TEST_CHECK(basis1.num_basis == 2); + TEST_CHECK(strcmp(basis1.id, "serendipity") == 0); + TEST_CHECK(basis1.b_type == GKYL_BASIS_MODAL_SERENDIPITY); double z[basis1.num_basis], b[basis1.num_basis]; z[0] = 0.0; basis1.eval(z, b); - TEST_CHECK( gkyl_compare(b[0], 1/sqrt(2.0), 1e-15) ); - TEST_CHECK( b[1] == 0.0 ); + TEST_CHECK(gkyl_compare(b[0], 1 / sqrt(2.0), 1e-15)); + TEST_CHECK(b[1] == 0.0); - z[0] = 0.5; basis1.eval(z, b); - - TEST_CHECK( gkyl_compare(b[0], 1/sqrt(2.0), 1e-15) ); - TEST_CHECK( b[1] == sqrt(3.0/2.0)*0.5 ); + z[0] = 0.5; + basis1.eval(z, b); - double nodes[basis1.ndim*basis1.num_basis]; + TEST_CHECK(gkyl_compare(b[0], 1 / sqrt(2.0), 1e-15)); + TEST_CHECK(b[1] == sqrt(3.0 / 2.0) * 0.5); + + double nodes[basis1.ndim * basis1.num_basis]; basis1.node_list(nodes); - TEST_CHECK( nodes[0] == -1 ); - TEST_CHECK( nodes[1] == 1 ); + TEST_CHECK(nodes[0] == -1); + TEST_CHECK(nodes[1] == 1); double f[basis1.num_basis]; - for (int i=0; i #include #include - int dev_cu_ser_2d(struct gkyl_basis *basis); +int dev_cu_ser_2d(struct gkyl_basis *basis); } -__global__ -void -ker_dev_cu_ser_2d(struct gkyl_basis *basis, int *nfail) +__global__ void ker_dev_cu_ser_2d(struct gkyl_basis *basis, int *nfail) { *nfail = 0; - GKYL_CU_CHECK( basis->ndim == 2, nfail); - GKYL_CU_CHECK( basis->poly_order == 2, nfail); - GKYL_CU_CHECK( basis->num_basis == 8, nfail); - GKYL_CU_CHECK( basis->b_type == GKYL_BASIS_MODAL_SERENDIPITY, nfail); + GKYL_CU_CHECK(basis->ndim == 2, nfail); + GKYL_CU_CHECK(basis->poly_order == 2, nfail); + GKYL_CU_CHECK(basis->num_basis == 8, nfail); + GKYL_CU_CHECK(basis->b_type == GKYL_BASIS_MODAL_SERENDIPITY, nfail); double z[128], b[128]; - z[0] = 0.0; z[1] = 0.0; + z[0] = 0.0; + z[1] = 0.0; basis->eval(z, b); double fin[128], fout[128]; - for (int i=0; inum_basis; ++i) { + for (int i = 0; i < basis->num_basis; ++i) { fin[i] = 1.0; fout[i] = 0.0; } basis->flip_odd_sign(0, fin, fout); - GKYL_CU_CHECK( fin[0] == fout[0], nfail); - GKYL_CU_CHECK( -fin[1] == fout[1], nfail); - GKYL_CU_CHECK( fin[2] == fout[2], nfail); - GKYL_CU_CHECK( -fin[3] == fout[3], nfail); - GKYL_CU_CHECK( fin[4] == fout[4], nfail); - GKYL_CU_CHECK( fin[5] == fout[5], nfail); - GKYL_CU_CHECK( fin[6] == fout[6], nfail); - GKYL_CU_CHECK( -fin[7] == fout[7], nfail); + GKYL_CU_CHECK(fin[0] == fout[0], nfail); + GKYL_CU_CHECK(-fin[1] == fout[1], nfail); + GKYL_CU_CHECK(fin[2] == fout[2], nfail); + GKYL_CU_CHECK(-fin[3] == fout[3], nfail); + GKYL_CU_CHECK(fin[4] == fout[4], nfail); + GKYL_CU_CHECK(fin[5] == fout[5], nfail); + GKYL_CU_CHECK(fin[6] == fout[6], nfail); + GKYL_CU_CHECK(-fin[7] == fout[7], nfail); basis->flip_odd_sign(1, fin, fout); - GKYL_CU_CHECK( fin[0] == fout[0], nfail); - GKYL_CU_CHECK( fin[1] == fout[1], nfail); - GKYL_CU_CHECK( -fin[2] == fout[2], nfail); - GKYL_CU_CHECK( -fin[3] == fout[3], nfail); - GKYL_CU_CHECK( fin[4] == fout[4], nfail); - GKYL_CU_CHECK( fin[5] == fout[5], nfail); - GKYL_CU_CHECK( -fin[6] == fout[6], nfail); - GKYL_CU_CHECK( fin[7] == fout[7], nfail); + GKYL_CU_CHECK(fin[0] == fout[0], nfail); + GKYL_CU_CHECK(fin[1] == fout[1], nfail); + GKYL_CU_CHECK(-fin[2] == fout[2], nfail); + GKYL_CU_CHECK(-fin[3] == fout[3], nfail); + GKYL_CU_CHECK(fin[4] == fout[4], nfail); + GKYL_CU_CHECK(fin[5] == fout[5], nfail); + GKYL_CU_CHECK(-fin[6] == fout[6], nfail); + GKYL_CU_CHECK(fin[7] == fout[7], nfail); basis->flip_even_sign(0, fin, fout); - GKYL_CU_CHECK( -fin[0] == fout[0], nfail); - GKYL_CU_CHECK( fin[1] == fout[1], nfail); - GKYL_CU_CHECK( -fin[2] == fout[2], nfail); - GKYL_CU_CHECK( fin[3] == fout[3], nfail); - GKYL_CU_CHECK( -fin[4] == fout[4], nfail); - GKYL_CU_CHECK( -fin[5] == fout[5], nfail); - GKYL_CU_CHECK( -fin[6] == fout[6], nfail); - GKYL_CU_CHECK( fin[7] == fout[7], nfail); + GKYL_CU_CHECK(-fin[0] == fout[0], nfail); + GKYL_CU_CHECK(fin[1] == fout[1], nfail); + GKYL_CU_CHECK(-fin[2] == fout[2], nfail); + GKYL_CU_CHECK(fin[3] == fout[3], nfail); + GKYL_CU_CHECK(-fin[4] == fout[4], nfail); + GKYL_CU_CHECK(-fin[5] == fout[5], nfail); + GKYL_CU_CHECK(-fin[6] == fout[6], nfail); + GKYL_CU_CHECK(fin[7] == fout[7], nfail); basis->flip_even_sign(1, fin, fout); - GKYL_CU_CHECK( -fin[0] == fout[0], nfail); - GKYL_CU_CHECK( -fin[1] == fout[1], nfail); - GKYL_CU_CHECK( fin[2] == fout[2], nfail); - GKYL_CU_CHECK( fin[3] == fout[3], nfail); - GKYL_CU_CHECK( -fin[4] == fout[4], nfail); - GKYL_CU_CHECK( -fin[5] == fout[5], nfail); - GKYL_CU_CHECK( fin[6] == fout[6], nfail); - GKYL_CU_CHECK( -fin[7] == fout[7], nfail); - - double nodes[128*128]; + GKYL_CU_CHECK(-fin[0] == fout[0], nfail); + GKYL_CU_CHECK(-fin[1] == fout[1], nfail); + GKYL_CU_CHECK(fin[2] == fout[2], nfail); + GKYL_CU_CHECK(fin[3] == fout[3], nfail); + GKYL_CU_CHECK(-fin[4] == fout[4], nfail); + GKYL_CU_CHECK(-fin[5] == fout[5], nfail); + GKYL_CU_CHECK(fin[6] == fout[6], nfail); + GKYL_CU_CHECK(-fin[7] == fout[7], nfail); + + double nodes[128 * 128]; basis->node_list(nodes); - GKYL_CU_CHECK( nodes[0] == -1, nfail); - GKYL_CU_CHECK( nodes[1] == -1, nfail); + GKYL_CU_CHECK(nodes[0] == -1, nfail); + GKYL_CU_CHECK(nodes[1] == -1, nfail); - GKYL_CU_CHECK( nodes[2] == 0, nfail); - GKYL_CU_CHECK( nodes[3] == -1, nfail); + GKYL_CU_CHECK(nodes[2] == 0, nfail); + GKYL_CU_CHECK(nodes[3] == -1, nfail); - GKYL_CU_CHECK( nodes[4] == 1, nfail); - GKYL_CU_CHECK( nodes[5] == -1, nfail); + GKYL_CU_CHECK(nodes[4] == 1, nfail); + GKYL_CU_CHECK(nodes[5] == -1, nfail); } -int -dev_cu_ser_2d(struct gkyl_basis *basis) +int dev_cu_ser_2d(struct gkyl_basis *basis) { - int *nfail_dev = (int *) gkyl_cu_malloc(sizeof(int)); - ker_dev_cu_ser_2d<<<1,1>>>(basis, nfail_dev); + int *nfail_dev = (int *)gkyl_cu_malloc(sizeof(int)); + ker_dev_cu_ser_2d<<<1, 1> > >(basis, nfail_dev); int nfail; gkyl_cu_memcpy(&nfail, nfail_dev, sizeof(int), GKYL_CU_MEMCPY_D2H); diff --git a/core/unit/ctest_block_geom.c b/core/unit/ctest_block_geom.c index 2fc03b15c2..065e2e1fcc 100644 --- a/core/unit/ctest_block_geom.c +++ b/core/unit/ctest_block_geom.c @@ -1,14 +1,13 @@ #include #include -static void -test_block_geom_L_domain_ho() +static void test_block_geom_L_domain_ho() { // 2D with 3 blocks struct gkyl_block_geom *bgeom = gkyl_block_geom_new(2, 3); - TEST_CHECK( 0 == gkyl_block_geom_check_consistency(bgeom) ); - TEST_CHECK( 3 == gkyl_block_geom_num_blocks(bgeom) ); + TEST_CHECK(0 == gkyl_block_geom_check_consistency(bgeom)); + TEST_CHECK(3 == gkyl_block_geom_num_blocks(bgeom)); /* Block layout @@ -23,85 +22,96 @@ test_block_geom_L_domain_ho() */ // block 0 - gkyl_block_geom_set_block(bgeom, 0, &(struct gkyl_block_geom_info) { - .lower = { 0, 0 }, - .upper = { 1, 1 }, - .cells = { 10, 10 }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } // physical boundary - } - } + gkyl_block_geom_set_block( + bgeom, 0, + &(struct gkyl_block_geom_info + ){.lower = {0, 0}, + .upper = {1, 1}, + .cells = {10, 10}, + + .connections[0] = + { + // x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + { + // y-direction connections + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); // topology is inconsistent at this point! - TEST_CHECK( 0 == gkyl_block_geom_check_consistency(bgeom) ); - + TEST_CHECK(0 == gkyl_block_geom_check_consistency(bgeom)); + // block 1 - gkyl_block_geom_set_block(bgeom, 1, &(struct gkyl_block_geom_info) { - .lower = { 0, 0 }, - .upper = { 1, 1 }, - .cells = { 10, 10 }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE } - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE } - } - } + gkyl_block_geom_set_block( + bgeom, 1, + &(struct gkyl_block_geom_info + ){.lower = {0, 0}, + .upper = {1, 1}, + .cells = {10, 10}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // geomlogy is inconsistent at this point! - TEST_CHECK( 0 == gkyl_block_geom_check_consistency(bgeom) ); + TEST_CHECK(0 == gkyl_block_geom_check_consistency(bgeom)); // block 2 - gkyl_block_geom_set_block(bgeom, 2, &(struct gkyl_block_geom_info) { - .lower = { 0, 0 }, - .upper = { 1, 1 }, - .cells = { 10, 10 }, - - .connections[0] = { // x-direction connections - { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } // physical boundary - } - } + gkyl_block_geom_set_block( + bgeom, 2, + &(struct gkyl_block_geom_info + ){.lower = {0, 0}, + .upper = {1, 1}, + .cells = {10, 10}, + + .connections[0] = + { + // x-direction connections + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + { + // y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); // should be fully consistent as all blocks properly specified - TEST_CHECK( 1 == gkyl_block_geom_check_consistency(bgeom) ); + TEST_CHECK(1 == gkyl_block_geom_check_consistency(bgeom)); struct gkyl_block_topo *btopo = gkyl_block_geom_topo(bgeom); - TEST_CHECK( 3 == btopo->num_blocks ); - TEST_CHECK( 1 == gkyl_block_topo_check_consistency(btopo) ); + TEST_CHECK(3 == btopo->num_blocks); + TEST_CHECK(1 == gkyl_block_topo_check_consistency(btopo)); int nblocks = gkyl_block_geom_num_blocks(bgeom); - for (int i=0; icells[0] ); - TEST_CHECK( 10 == ginfo->cells[1] ); + TEST_CHECK(10 == ginfo->cells[0]); + TEST_CHECK(10 == ginfo->cells[1]); - TEST_CHECK( 1 == ginfo->cuts[0] ); - TEST_CHECK( 1 == ginfo->cuts[1] ); + TEST_CHECK(1 == ginfo->cuts[0]); + TEST_CHECK(1 == ginfo->cuts[1]); } - gkyl_block_geom_release(bgeom); gkyl_block_topo_release(btopo); } -static void -test_block_geom_mobius_domain_ho() +static void test_block_geom_mobius_domain_ho() { // 2D with 1 block struct gkyl_block_geom *bgeom = gkyl_block_geom_new(2, 1); @@ -117,31 +127,32 @@ test_block_geom_mobius_domain_ho() */ // block 0 - gkyl_block_geom_set_block(bgeom, 0, &(struct gkyl_block_geom_info) { - .lower = { 0, 0 }, - .upper = { 1, 1 }, - .cells = { 10, 10 }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_UPPER_NEGATIVE }, // note twist - { .bid = 0, .dir = 0, .edge = GKYL_LOWER_NEGATIVE } - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE } - } - } + gkyl_block_geom_set_block( + bgeom, 0, + &(struct gkyl_block_geom_info + ){.lower = {0, 0}, + .upper = {1, 1}, + .cells = {10, 10}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_UPPER_NEGATIVE}, // note twist + {.bid = 0, .dir = 0, .edge = GKYL_LOWER_NEGATIVE} + }, + .connections[1] = + {// y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); - TEST_CHECK( 1 == gkyl_block_geom_check_consistency(bgeom) ); - + TEST_CHECK(1 == gkyl_block_geom_check_consistency(bgeom)); + gkyl_block_geom_release(bgeom); } - - TEST_LIST = { - { "block_geom_mobius_domain_ho", test_block_geom_mobius_domain_ho }, - { "block_geom_L_domain_ho", test_block_geom_L_domain_ho }, - { NULL, NULL }, + {"block_geom_mobius_domain_ho", test_block_geom_mobius_domain_ho}, + {"block_geom_L_domain_ho", test_block_geom_L_domain_ho}, + {NULL, NULL} }; diff --git a/core/unit/ctest_block_topo.c b/core/unit/ctest_block_topo.c index d3d84fc5ca..5909e8c129 100644 --- a/core/unit/ctest_block_topo.c +++ b/core/unit/ctest_block_topo.c @@ -2,15 +2,14 @@ #include #include -static struct gkyl_block_topo * -create_L_domain(void) +static struct gkyl_block_topo *create_L_domain(void) { // 2D with 3 blocks struct gkyl_block_topo *btopo = gkyl_block_topo_new(2, 3); - TEST_CHECK( 3 == btopo->num_blocks ); + TEST_CHECK(3 == btopo->num_blocks); // topology is inconsistent at this point! - TEST_CHECK( 0 == gkyl_block_topo_check_consistency(btopo) ); + TEST_CHECK(0 == gkyl_block_topo_check_consistency(btopo)); /* Block layout @@ -25,68 +24,70 @@ create_L_domain(void) */ // block 0 - btopo->conn[0] = (struct gkyl_block_connections) { - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } // physical boundary - } - }; + btopo->conn[0] = (struct gkyl_block_connections + ){.connections[0] = + { + // x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = { + // y-direction connections + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }}; // topology is inconsistent at this point! - TEST_CHECK( 0 == gkyl_block_topo_check_consistency(btopo) ); - + TEST_CHECK(0 == gkyl_block_topo_check_consistency(btopo)); + // block 1 - btopo->conn[1] = (struct gkyl_block_connections) { - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE } - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE } - } - }; + btopo->conn[1] = (struct gkyl_block_connections + ){.connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = {// y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; // topology is inconsistent at this point! - TEST_CHECK( 0 == gkyl_block_topo_check_consistency(btopo) ); - + TEST_CHECK(0 == gkyl_block_topo_check_consistency(btopo)); + // block 2 - btopo->conn[2] = (struct gkyl_block_connections) { - .connections[0] = { // x-direction connections - { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } // physical boundary - } - }; + btopo->conn[2] = (struct gkyl_block_connections + ){.connections[0] = + { + // x-direction connections + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = { + // y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }}; return btopo; } -static void -test_block_topo_L_domain_ho() +static void test_block_topo_L_domain_ho() { struct gkyl_block_topo *btopo = create_L_domain(); // should be fully consistent as all blocks properly specified - TEST_CHECK( 1 == gkyl_block_topo_check_consistency(btopo) ); + TEST_CHECK(1 == gkyl_block_topo_check_consistency(btopo)); gkyl_block_topo_release(btopo); } -static void -test_block_topo_mobius_domain_ho() +static void test_block_topo_mobius_domain_ho() { // 2D with 1 block struct gkyl_block_topo *btopo = gkyl_block_topo_new(2, 1); - TEST_CHECK( 1 == btopo->num_blocks ); + TEST_CHECK(1 == btopo->num_blocks); // topology is inconsistent at this point! - TEST_CHECK( 0 == gkyl_block_topo_check_consistency(btopo) ); + TEST_CHECK(0 == gkyl_block_topo_check_consistency(btopo)); /* Block layout @@ -99,48 +100,47 @@ test_block_topo_mobius_domain_ho() */ // block 0 - btopo->conn[0] = (struct gkyl_block_connections) { - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_UPPER_NEGATIVE }, // note twist - { .bid = 0, .dir = 0, .edge = GKYL_LOWER_NEGATIVE } - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE } - } - }; - - TEST_CHECK( 1 == gkyl_block_topo_check_consistency(btopo) ); + btopo->conn[0] = (struct gkyl_block_connections + ){.connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_UPPER_NEGATIVE}, // note twist + {.bid = 0, .dir = 0, .edge = GKYL_LOWER_NEGATIVE} + }, + .connections[1] = {// y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + TEST_CHECK(1 == gkyl_block_topo_check_consistency(btopo)); gkyl_block_topo_release(btopo); } -static void -test_topo_io_ho() +static void test_topo_io_ho() { struct gkyl_block_topo *btopo = create_L_domain(); int status_out = gkyl_block_topo_write(btopo, "ctest_block_topo_L_domain.gkyl"); - TEST_CHECK( GKYL_ARRAY_RIO_SUCCESS == status_out ); + TEST_CHECK(GKYL_ARRAY_RIO_SUCCESS == status_out); int status_inp; - struct gkyl_block_topo *btopo_inp = gkyl_block_topo_read("ctest_block_topo_L_domain.gkyl", - &status_inp); - TEST_CHECK( GKYL_ARRAY_RIO_SUCCESS == status_out ); + struct gkyl_block_topo *btopo_inp = + gkyl_block_topo_read("ctest_block_topo_L_domain.gkyl", &status_inp); + TEST_CHECK(GKYL_ARRAY_RIO_SUCCESS == status_out); if (status_out == GKYL_ARRAY_RIO_SUCCESS) { - TEST_CHECK( 2 == btopo_inp->ndim ); - TEST_CHECK( 3 == btopo_inp->num_blocks ); - TEST_CHECK( 1 == gkyl_block_topo_check_consistency(btopo_inp) ); - + TEST_CHECK(2 == btopo_inp->ndim); + TEST_CHECK(3 == btopo_inp->num_blocks); + TEST_CHECK(1 == gkyl_block_topo_check_consistency(btopo_inp)); + gkyl_block_topo_release(btopo_inp); } - + gkyl_block_topo_release(btopo); } TEST_LIST = { - { "block_topo_mobius_domain_ho", test_block_topo_mobius_domain_ho }, - { "block_topo_L_domain_ho", test_block_topo_L_domain_ho }, - { "topo_io_ho", test_topo_io_ho }, - { NULL, NULL }, + {"block_topo_mobius_domain_ho", test_block_topo_mobius_domain_ho}, + {"block_topo_L_domain_ho", test_block_topo_L_domain_ho}, + {"topo_io_ho", test_topo_io_ho}, + {NULL, NULL} }; diff --git a/core/unit/ctest_cudss.cu b/core/unit/ctest_cudss.cu index f7d8897a38..e4d8442e97 100644 --- a/core/unit/ctest_cudss.cu +++ b/core/unit/ctest_cudss.cu @@ -15,14 +15,17 @@ void test_cudss_ops_update_amat(); void test_cudss_ops_multiple_rhs(); } -#define checkCUDSS(call, status, msg) \ -do { \ - status = call; \ - if (status != CUDSS_STATUS_SUCCESS) { \ - printf("Example FAILED: CUDSS call ended unsuccessfully with status = %d, details: " #msg "\n", status); \ - exit(EXIT_FAILURE); \ - } \ -} while(0); +#define checkCUDSS(call, status, msg) \ + do { \ + status = call; \ + if (status != CUDSS_STATUS_SUCCESS) { \ + printf( \ + "Example FAILED: CUDSS call ended unsuccessfully with status = %d, details: " #msg "\n", \ + status \ + ); \ + exit(EXIT_FAILURE); \ + } \ + } while (0); void test_cudss_simple() { @@ -49,16 +52,15 @@ void test_cudss_simple() double *csr_values_d = NULL; double *x_values_d = NULL, *b_values_d = NULL; - csr_offsets_h = (int*)malloc((n + 1) * sizeof(int)); - csr_columns_h = (int*)malloc(nnz * sizeof(int)); - csr_values_h = (double*)malloc(nnz * sizeof(double)); - x_values_h = (double*)malloc(nrhs * n * sizeof(double)); - b_values_h = (double*)malloc(nrhs * n * sizeof(double)); + csr_offsets_h = (int *)malloc((n + 1) * sizeof(int)); + csr_columns_h = (int *)malloc(nnz * sizeof(int)); + csr_values_h = (double *)malloc(nnz * sizeof(double)); + x_values_h = (double *)malloc(nrhs * n * sizeof(double)); + b_values_h = (double *)malloc(nrhs * n * sizeof(double)); - if (!csr_offsets_h || ! csr_columns_h || !csr_values_h || - !x_values_h || !b_values_h) { - printf("Error: host memory allocation failed\n"); - assert(false); + if (!csr_offsets_h || !csr_columns_h || !csr_values_h || !x_values_h || !b_values_h) { + printf("Error: host memory allocation failed\n"); + assert(false); } /* Initialize host memory for A and b */ @@ -71,16 +73,22 @@ void test_cudss_simple() csr_offsets_h[i++] = 8; i = 0; - csr_columns_h[i++] = 0; csr_columns_h[i++] = 2; - csr_columns_h[i++] = 1; csr_columns_h[i++] = 2; - csr_columns_h[i++] = 2; csr_columns_h[i++] = 4; + csr_columns_h[i++] = 0; + csr_columns_h[i++] = 2; + csr_columns_h[i++] = 1; + csr_columns_h[i++] = 2; + csr_columns_h[i++] = 2; + csr_columns_h[i++] = 4; csr_columns_h[i++] = 3; csr_columns_h[i++] = 4; i = 0; - csr_values_h[i++] = 4.0; csr_values_h[i++] = 1.0; - csr_values_h[i++] = 3.0; csr_values_h[i++] = 2.0; - csr_values_h[i++] = 5.0; csr_values_h[i++] = 1.0; + csr_values_h[i++] = 4.0; + csr_values_h[i++] = 1.0; + csr_values_h[i++] = 3.0; + csr_values_h[i++] = 2.0; + csr_values_h[i++] = 5.0; + csr_values_h[i++] = 1.0; csr_values_h[i++] = 1.0; csr_values_h[i++] = 2.0; @@ -101,7 +109,8 @@ void test_cudss_simple() checkCuda(cudaMalloc(&x_values_d, nrhs * n * sizeof(double))); /* Copy host memory to device for A and b */ - checkCuda(cudaMemcpy(csr_offsets_d, csr_offsets_h, (n + 1) * sizeof(int), cudaMemcpyHostToDevice)); + checkCuda(cudaMemcpy(csr_offsets_d, csr_offsets_h, (n + 1) * sizeof(int), cudaMemcpyHostToDevice) + ); checkCuda(cudaMemcpy(csr_columns_d, csr_columns_h, nnz * sizeof(int), cudaMemcpyHostToDevice)); checkCuda(cudaMemcpy(csr_values_d, csr_values_h, nnz * sizeof(double), cudaMemcpyHostToDevice)); checkCuda(cudaMemcpy(b_values_d, b_values_h, nrhs * n * sizeof(double), cudaMemcpyHostToDevice)); @@ -130,31 +139,45 @@ void test_cudss_simple() int64_t nrows = n, ncols = n; int ldb = ncols, ldx = nrows; - checkCUDSS(cudssMatrixCreateDn(&b, ncols, nrhs, ldb, b_values_d, CUDA_R_64F, CUDSS_LAYOUT_COL_MAJOR), - status, "cudssMatrixCreateDn for b"); - checkCUDSS(cudssMatrixCreateDn(&x, nrows, nrhs, ldx, x_values_d, CUDA_R_64F, CUDSS_LAYOUT_COL_MAJOR), - status, "cudssMatrixCreateDn for x"); + checkCUDSS( + cudssMatrixCreateDn(&b, ncols, nrhs, ldb, b_values_d, CUDA_R_64F, CUDSS_LAYOUT_COL_MAJOR), + status, "cudssMatrixCreateDn for b" + ); + checkCUDSS( + cudssMatrixCreateDn(&x, nrows, nrhs, ldx, x_values_d, CUDA_R_64F, CUDSS_LAYOUT_COL_MAJOR), + status, "cudssMatrixCreateDn for x" + ); /* Create a matrix object for the sparse input matrix. */ cudssMatrix_t A; - cudssMatrixType_t mtype = CUDSS_MTYPE_SPD; + cudssMatrixType_t mtype = CUDSS_MTYPE_SPD; cudssMatrixViewType_t mview = CUDSS_MVIEW_UPPER; - cudssIndexBase_t base = CUDSS_BASE_ZERO; - checkCUDSS(cudssMatrixCreateCsr(&A, nrows, ncols, nnz, csr_offsets_d, NULL, - csr_columns_d, csr_values_d, CUDA_R_32I, CUDA_R_64F, mtype, mview, - base), status, "cudssMatrixCreateCsr"); + cudssIndexBase_t base = CUDSS_BASE_ZERO; + checkCUDSS( + cudssMatrixCreateCsr( + &A, nrows, ncols, nnz, csr_offsets_d, NULL, csr_columns_d, csr_values_d, CUDA_R_32I, + CUDA_R_64F, mtype, mview, base + ), + status, "cudssMatrixCreateCsr" + ); /* Symbolic factorization */ - checkCUDSS(cudssExecute(handle, CUDSS_PHASE_ANALYSIS, solverConfig, solverData, - A, x, b), status, "cudssExecute for analysis"); + checkCUDSS( + cudssExecute(handle, CUDSS_PHASE_ANALYSIS, solverConfig, solverData, A, x, b), status, + "cudssExecute for analysis" + ); /* Factorization */ - checkCUDSS(cudssExecute(handle, CUDSS_PHASE_FACTORIZATION, solverConfig, - solverData, A, x, b), status, "cudssExecute for factor"); + checkCUDSS( + cudssExecute(handle, CUDSS_PHASE_FACTORIZATION, solverConfig, solverData, A, x, b), status, + "cudssExecute for factor" + ); /* Solving */ - checkCUDSS(cudssExecute(handle, CUDSS_PHASE_SOLVE, solverConfig, solverData, - A, x, b), status, "cudssExecute for solve"); + checkCUDSS( + cudssExecute(handle, CUDSS_PHASE_SOLVE, solverConfig, solverData, A, x, b), status, + "cudssExecute for solve" + ); /* Destroying opaque objects, matrix wrappers and the cuDSS library handle */ checkCUDSS(cudssMatrixDestroy(A), status, "cudssMatrixDestroy for A"); @@ -196,18 +219,24 @@ void test_cudss_simple() void test_cudss_ops() { - int nfail = 0; + int nfail = 0; double s, u, p, e, r, l; - int nrhs, m, n; + int nrhs, m, n; /* Initialize matrix A. */ /* A : matrix([s,0,u,u,0],[l,u,0,0,0],[0,l,p,0,0],[0,0,0,e,u],[l,l,0,0,r]); */ m = n = 5; nrhs = 1; - - s = 19.0; u = 21.0; p = 16.0; e = 5.0; r = 18.0; l = 12.0; + + s = 19.0; + u = 21.0; + p = 16.0; + e = 5.0; + r = 18.0; + l = 12.0; /* A : matrix([s,0,u,u,0],[l,u,0,0,0],[0,l,p,0,0],[0,0,0,e,u],[l,l,0,0,r]); */ - struct gkyl_mat_triples **tri_arr = (struct gkyl_mat_triples **) gkyl_malloc(sizeof(struct gkyl_mat_triples *)); + struct gkyl_mat_triples **tri_arr = + (struct gkyl_mat_triples **)gkyl_malloc(sizeof(struct gkyl_mat_triples *)); tri_arr[0] = gkyl_mat_triples_new(m, n); struct gkyl_mat_triples *tri = tri_arr[0]; gkyl_mat_triples_set_rowmaj_order(tri); @@ -251,29 +280,45 @@ void test_cudss_ops() gkyl_culinsolver_finish_host(prob); // Solution is: [-1/32, 11/168, 3/224, 1/16, 11/336]. - GKYL_CU_CHECK( gkyl_compare_double(-1.0/32.0, gkyl_culinsolver_get_sol_lin(prob,0), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double( 11.0/168.0, gkyl_culinsolver_get_sol_lin(prob,1), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double( 3.0/224.0, gkyl_culinsolver_get_sol_lin(prob,2), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double( 1.0/16.0, gkyl_culinsolver_get_sol_lin(prob,3), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double( 11.0/336.0, gkyl_culinsolver_get_sol_lin(prob,4), 1e-14), &nfail ); + GKYL_CU_CHECK( + gkyl_compare_double(-1.0 / 32.0, gkyl_culinsolver_get_sol_lin(prob, 0), 1e-14), &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double(11.0 / 168.0, gkyl_culinsolver_get_sol_lin(prob, 1), 1e-14), &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double(3.0 / 224.0, gkyl_culinsolver_get_sol_lin(prob, 2), 1e-14), &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double(1.0 / 16.0, gkyl_culinsolver_get_sol_lin(prob, 3), 1e-14), &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double(11.0 / 336.0, gkyl_culinsolver_get_sol_lin(prob, 4), 1e-14), &nfail + ); gkyl_culinsolver_prob_release(prob); } void test_cudss_ops_update_amat() { - int nfail = 0; + int nfail = 0; double s, u, p, e, r, l; - int nrhs, m, n; + int nrhs, m, n; /* Initialize matrix A. */ /* A : matrix([s,0,u,u,0],[l,u,0,0,0],[0,l,p,0,0],[0,0,0,e,u],[l,l,0,0,r]); */ m = n = 5; nrhs = 1; - - s = 19.0; u = 21.0; p = 16.0; e = 5.0; r = 18.0; l = 12.0; + + s = 19.0; + u = 21.0; + p = 16.0; + e = 5.0; + r = 18.0; + l = 12.0; /* A : matrix([s,0,u,u,0],[l,u,0,0,0],[0,l,p,0,0],[0,0,0,e,u],[l,l,0,0,r]); */ - struct gkyl_mat_triples **tri_arr = (struct gkyl_mat_triples **) gkyl_malloc(sizeof(struct gkyl_mat_triples *)); + struct gkyl_mat_triples **tri_arr = + (struct gkyl_mat_triples **)gkyl_malloc(sizeof(struct gkyl_mat_triples *)); tri_arr[0] = gkyl_mat_triples_new(m, n); struct gkyl_mat_triples *tri = tri_arr[0]; gkyl_mat_triples_set_rowmaj_order(tri); @@ -314,33 +359,43 @@ void test_cudss_ops_update_amat() gkyl_culinsolver_finish_host(prob); // Solution is: [-1/32, 11/168, 3/224, 1/16, 11/336]. - GKYL_CU_CHECK( gkyl_compare_double(-1.0/32.0 , gkyl_culinsolver_get_sol_lin(prob,0), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double( 11.0/168.0, gkyl_culinsolver_get_sol_lin(prob,1), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double( 3.0/224.0 , gkyl_culinsolver_get_sol_lin(prob,2), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double( 1.0/16.0 , gkyl_culinsolver_get_sol_lin(prob,3), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double( 11.0/336.0, gkyl_culinsolver_get_sol_lin(prob,4), 1e-14), &nfail ); + GKYL_CU_CHECK( + gkyl_compare_double(-1.0 / 32.0, gkyl_culinsolver_get_sol_lin(prob, 0), 1e-14), &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double(11.0 / 168.0, gkyl_culinsolver_get_sol_lin(prob, 1), 1e-14), &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double(3.0 / 224.0, gkyl_culinsolver_get_sol_lin(prob, 2), 1e-14), &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double(1.0 / 16.0, gkyl_culinsolver_get_sol_lin(prob, 3), 1e-14), &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double(11.0 / 336.0, gkyl_culinsolver_get_sol_lin(prob, 4), 1e-14), &nfail + ); // Now update the LHS matrix. Multiply it by a constant so the solution should be the same as before but divided by that constant. double prob_fac = 1.3; gkyl_mat_triples_set_rowmaj_order(tri); // row 0 - gkyl_mat_triples_insert(tri, 0, 0, s*prob_fac); - gkyl_mat_triples_insert(tri, 0, 2, u*prob_fac); - gkyl_mat_triples_insert(tri, 0, 3, u*prob_fac); + gkyl_mat_triples_insert(tri, 0, 0, s * prob_fac); + gkyl_mat_triples_insert(tri, 0, 2, u * prob_fac); + gkyl_mat_triples_insert(tri, 0, 3, u * prob_fac); // row 1 - gkyl_mat_triples_insert(tri, 1, 0, l*prob_fac); - gkyl_mat_triples_insert(tri, 1, 1, u*prob_fac); + gkyl_mat_triples_insert(tri, 1, 0, l * prob_fac); + gkyl_mat_triples_insert(tri, 1, 1, u * prob_fac); // row 2 - gkyl_mat_triples_insert(tri, 2, 1, l*prob_fac); - gkyl_mat_triples_insert(tri, 2, 2, p*prob_fac); + gkyl_mat_triples_insert(tri, 2, 1, l * prob_fac); + gkyl_mat_triples_insert(tri, 2, 2, p * prob_fac); // row 3 - gkyl_mat_triples_insert(tri, 3, 3, e*prob_fac); - gkyl_mat_triples_insert(tri, 3, 4, u*prob_fac); + gkyl_mat_triples_insert(tri, 3, 3, e * prob_fac); + gkyl_mat_triples_insert(tri, 3, 4, u * prob_fac); // row 4 - gkyl_mat_triples_insert(tri, 4, 0, l*prob_fac); - gkyl_mat_triples_insert(tri, 4, 1, l*prob_fac); - gkyl_mat_triples_insert(tri, 4, 4, r*prob_fac); + gkyl_mat_triples_insert(tri, 4, 0, l * prob_fac); + gkyl_mat_triples_insert(tri, 4, 1, l * prob_fac); + gkyl_mat_triples_insert(tri, 4, 4, r * prob_fac); gkyl_culinsolver_amat_update_from_triples(prob, tri_arr); @@ -351,11 +406,36 @@ void test_cudss_ops_update_amat() gkyl_culinsolver_finish_host(prob); // Solution is: (1/prob_fac)*[-1/32, 11/168, 3/224, 1/16, 11/336]. - GKYL_CU_CHECK( gkyl_compare_double((1.0/prob_fac)*(-1.0/32.0 ), gkyl_culinsolver_get_sol_lin(prob,0), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double((1.0/prob_fac)*( 11.0/168.0), gkyl_culinsolver_get_sol_lin(prob,1), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double((1.0/prob_fac)*( 3.0/224.0 ), gkyl_culinsolver_get_sol_lin(prob,2), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double((1.0/prob_fac)*( 1.0/16.0 ), gkyl_culinsolver_get_sol_lin(prob,3), 1e-14), &nfail ); - GKYL_CU_CHECK( gkyl_compare_double((1.0/prob_fac)*( 11.0/336.0), gkyl_culinsolver_get_sol_lin(prob,4), 1e-14), &nfail ); + GKYL_CU_CHECK( + gkyl_compare_double( + (1.0 / prob_fac) * (-1.0 / 32.0), gkyl_culinsolver_get_sol_lin(prob, 0), 1e-14 + ), + &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double( + (1.0 / prob_fac) * (11.0 / 168.0), gkyl_culinsolver_get_sol_lin(prob, 1), 1e-14 + ), + &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double( + (1.0 / prob_fac) * (3.0 / 224.0), gkyl_culinsolver_get_sol_lin(prob, 2), 1e-14 + ), + &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double( + (1.0 / prob_fac) * (1.0 / 16.0), gkyl_culinsolver_get_sol_lin(prob, 3), 1e-14 + ), + &nfail + ); + GKYL_CU_CHECK( + gkyl_compare_double( + (1.0 / prob_fac) * (11.0 / 336.0), gkyl_culinsolver_get_sol_lin(prob, 4), 1e-14 + ), + &nfail + ); gkyl_mat_triples_release(tri); gkyl_free(tri_arr); @@ -366,16 +446,22 @@ void test_cudss_ops_update_amat() void test_cudss_ops_multiple_rhs() { double s, u, p, e, r, l; - int nrhs, m, n; + int nrhs, m, n; /* Initialize matrix A. */ /* A : matrix([s,0,u,u,0],[l,u,0,0,0],[0,l,p,0,0],[0,0,0,e,u],[l,l,0,0,r]); */ m = n = 5; nrhs = 3; - - s = 19.0; u = 21.0; p = 16.0; e = 5.0; r = 18.0; l = 12.0; + + s = 19.0; + u = 21.0; + p = 16.0; + e = 5.0; + r = 18.0; + l = 12.0; /* A : matrix([s,0,u,u,0],[l,u,0,0,0],[0,l,p,0,0],[0,0,0,e,u],[l,l,0,0,r]); */ - struct gkyl_mat_triples **tri_arr = (struct gkyl_mat_triples **) gkyl_malloc(sizeof(struct gkyl_mat_triples *)); + struct gkyl_mat_triples **tri_arr = + (struct gkyl_mat_triples **)gkyl_malloc(sizeof(struct gkyl_mat_triples *)); tri_arr[0] = gkyl_mat_triples_new(m, n); struct gkyl_mat_triples *tri = tri_arr[0]; gkyl_mat_triples_set_rowmaj_order(tri); @@ -407,7 +493,7 @@ void test_cudss_ops_multiple_rhs() // Create right-hand side matrix B = transpose([1,1,1,1,1]). gkyl_mat_triples *triRHS = gkyl_mat_triples_new(m, nrhs); - for (int k=0; k // Helper function to create test arrays -static struct gkyl_array * -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { - struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } // Test basic mask creation and initialization void test_mask_new(bool use_gpu) { - int shape[] = { 10, 20 }; + int shape[] = {10, 20}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); @@ -53,7 +52,7 @@ void test_mask_new(bool use_gpu) for (unsigned i = 0; i < range.volume; ++i) { const double *mask_d = gkyl_array_cfetch(mask_ho, i); - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); } gkyl_array_release(mask_ho); @@ -63,9 +62,7 @@ void test_mask_new(bool use_gpu) // Test mask with NONE type void test_mask_none_type(bool use_gpu) { - struct gkyl_dg_array_mask_inp mask_inp = { - .use_gpu = use_gpu - }; + struct gkyl_dg_array_mask_inp mask_inp = {.use_gpu = use_gpu}; struct gkyl_dg_array_mask *mask = gkyl_dg_array_mask_new(mask_inp); TEST_CHECK(mask->type == GKYL_DG_ARRAY_MASK_NONE); @@ -78,7 +75,7 @@ void test_mask_none_type(bool use_gpu) // Test mask advance with threshold void test_mask_advance_threshold(bool use_gpu) { - int shape[] = { 10 }; + int shape[] = {10}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 1, shape); @@ -121,10 +118,9 @@ void test_mask_advance_threshold(bool use_gpu) const double *mask_d = gkyl_array_cfetch(mask_ho, i); const double *arr_d = gkyl_array_cfetch(arr_ho, i); if (fabs(arr_d[0]) < expected_threshold) { - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); // True (masked) - } - else { - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); // False (not masked) + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); // True (masked) + } else { + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); // False (not masked) } } @@ -137,7 +133,7 @@ void test_mask_advance_threshold(bool use_gpu) // Test mask advance with all values below threshold void test_mask_advance_all_below(bool use_gpu) { - int shape[] = { 5, 5 }; + int shape[] = {5, 5}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); @@ -157,7 +153,7 @@ void test_mask_advance_all_below(bool use_gpu) struct gkyl_array *arr_ho = mkarr(false, arr->ncomp, arr->size); gkyl_array_clear(arr_ho, 1e-12); gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -171,7 +167,7 @@ void test_mask_advance_all_below(bool use_gpu) // All cells should be masked (1.0) for (unsigned i = 0; i < range.volume; ++i) { const double *mask_d = gkyl_array_cfetch(mask_ho, i); - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); } gkyl_array_release(arr_ho); @@ -183,7 +179,7 @@ void test_mask_advance_all_below(bool use_gpu) // Test mask advance with all values above threshold void test_mask_advance_all_above(bool use_gpu) { - int shape[] = { 5, 5 }; + int shape[] = {5, 5}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); @@ -203,7 +199,7 @@ void test_mask_advance_all_above(bool use_gpu) struct gkyl_array *arr_ho = mkarr(false, arr->ncomp, arr->size); gkyl_array_clear(arr_ho, 100.0); gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -217,7 +213,7 @@ void test_mask_advance_all_above(bool use_gpu) // No cells should be masked (-1.0) for (unsigned i = 0; i < range.volume; ++i) { const double *mask_d = gkyl_array_cfetch(mask_ho, i); - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); } gkyl_array_release(arr_ho); @@ -229,7 +225,7 @@ void test_mask_advance_all_above(bool use_gpu) // Test mask advance with negative values void test_mask_advance_negative_values(bool use_gpu) { - int shape[] = { 8 }; + int shape[] = {8}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 1, shape); @@ -247,13 +243,13 @@ void test_mask_advance_negative_values(bool use_gpu) // Create test array with negative and positive values struct gkyl_array *arr = mkarr(use_gpu, 1, range.volume); struct gkyl_array *arr_ho = mkarr(false, arr->ncomp, arr->size); - double vals[] = { 0.1, -0.1, 1.0, -1.0, 0.3, -0.3, 2.0, -2.0 }; + double vals[] = {0.1, -0.1, 1.0, -1.0, 0.3, -0.3, 2.0, -2.0}; for (unsigned i = 0; i < range.volume; ++i) { double *arr_d = gkyl_array_fetch(arr_ho, i); arr_d[0] = vals[i]; } gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -270,10 +266,9 @@ void test_mask_advance_negative_values(bool use_gpu) const double *mask_d = gkyl_array_cfetch(mask_ho, i); const double *arr_d = gkyl_array_cfetch(arr_ho, i); if (fabs(arr_d[0]) < expected_threshold) { - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); - } - else { - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); + } else { + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); } } @@ -286,7 +281,7 @@ void test_mask_advance_negative_values(bool use_gpu) // Test mask advance with GREATER_THAN threshold void test_mask_advance_greater_than_threshold(bool use_gpu) { - int shape[] = { 10 }; + int shape[] = {10}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 1, shape); @@ -310,7 +305,7 @@ void test_mask_advance_greater_than_threshold(bool use_gpu) arr_d[0] = (i % 2 == 0) ? 0.1 : 1.0; } gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -327,10 +322,9 @@ void test_mask_advance_greater_than_threshold(bool use_gpu) const double *mask_d = gkyl_array_cfetch(mask_ho, i); const double *arr_d = gkyl_array_cfetch(arr_ho, i); if (fabs(arr_d[0]) > expected_threshold) { - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); // True (masked) - } - else { - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); // False (not masked) + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); // True (masked) + } else { + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); // False (not masked) } } @@ -343,7 +337,7 @@ void test_mask_advance_greater_than_threshold(bool use_gpu) // Test GREATER_THAN mask with all values above threshold void test_mask_advance_greater_than_all_above(bool use_gpu) { - int shape[] = { 5, 5 }; + int shape[] = {5, 5}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); @@ -377,7 +371,7 @@ void test_mask_advance_greater_than_all_above(bool use_gpu) // All cells should be masked (1.0) since values > threshold for (unsigned i = 0; i < range.volume; ++i) { const double *mask_d = gkyl_array_cfetch(mask_ho, i); - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); } gkyl_array_release(arr_ho); @@ -389,7 +383,7 @@ void test_mask_advance_greater_than_all_above(bool use_gpu) // Test GREATER_THAN mask with all values below threshold void test_mask_advance_greater_than_all_below(bool use_gpu) { - int shape[] = { 5, 5 }; + int shape[] = {5, 5}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); @@ -409,7 +403,7 @@ void test_mask_advance_greater_than_all_below(bool use_gpu) struct gkyl_array *arr_ho = mkarr(false, arr->ncomp, arr->size); gkyl_array_clear(arr_ho, 1e-12); gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -423,7 +417,7 @@ void test_mask_advance_greater_than_all_below(bool use_gpu) // No cells should be masked (-1.0) since values < threshold for (unsigned i = 0; i < range.volume; ++i) { const double *mask_d = gkyl_array_cfetch(mask_ho, i); - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); } gkyl_array_release(arr_ho); @@ -435,7 +429,7 @@ void test_mask_advance_greater_than_all_below(bool use_gpu) // Test GREATER_THAN mask with negative values void test_mask_advance_greater_than_negative_values(bool use_gpu) { - int shape[] = { 8 }; + int shape[] = {8}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 1, shape); @@ -453,13 +447,13 @@ void test_mask_advance_greater_than_negative_values(bool use_gpu) // Create test array with negative and positive values struct gkyl_array *arr = mkarr(use_gpu, 1, range.volume); struct gkyl_array *arr_ho = mkarr(false, arr->ncomp, arr->size); - double vals[] = { 0.1, -0.1, 1.0, -1.0, 0.3, -0.3, 2.0, -2.0 }; + double vals[] = {0.1, -0.1, 1.0, -1.0, 0.3, -0.3, 2.0, -2.0}; for (unsigned i = 0; i < range.volume; ++i) { double *arr_d = gkyl_array_fetch(arr_ho, i); arr_d[0] = vals[i]; } gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -476,10 +470,9 @@ void test_mask_advance_greater_than_negative_values(bool use_gpu) const double *arr_d = gkyl_array_cfetch(arr_ho, i); const double *mask_d = gkyl_array_cfetch(mask_ho, i); if (fabs(arr_d[0]) > expected_threshold) { - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); - } - else { - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); + } else { + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); } } @@ -492,7 +485,7 @@ void test_mask_advance_greater_than_negative_values(bool use_gpu) // Test mask eval inline function void test_mask_eval(bool use_gpu) { - int shape[] = { 6 }; + int shape[] = {6}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 1, shape); @@ -512,13 +505,13 @@ void test_mask_eval(bool use_gpu) struct gkyl_array *arr_ho = mkarr(false, arr->ncomp, arr->size); // Set up values so that mask will be: true, false, true, false, true, false double *arr_d; - double vals[] = { 0.1, 1.0, 0.2, 2.0, 0.3, 5.0 }; + double vals[] = {0.1, 1.0, 0.2, 2.0, 0.3, 5.0}; for (int i = 0; i < shape[0]; i++) { arr_d = gkyl_array_fetch(arr_ho, i); arr_d[0] = vals[i]; } gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -529,28 +522,31 @@ void test_mask_eval(bool use_gpu) // returned on the GPU, but needs a host evaluation for the TEST_CHECK bool *mask_cond_ho, *mask_cond; mask_cond_ho = gkyl_malloc(sizeof(bool)); - if (use_gpu) + if (use_gpu) { mask_cond = gkyl_cu_malloc(sizeof(bool)); - else + } else { mask_cond = gkyl_malloc(sizeof(bool)); + } bool mask_cond_ref[] = {true, false, true, false, true, false}; - for (int i=0; ithreshold, expected1d, 1e-14) ); + TEST_CHECK(gkyl_compare(mask1d->threshold, expected1d, 1e-14)); gkyl_dg_array_mask_release(mask1d); // Test 2D - int shape2d[] = { 5, 5 }; + int shape2d[] = {5, 5}; struct gkyl_range range2d; gkyl_range_init_from_shape(&range2d, 2, shape2d); @@ -731,11 +728,11 @@ void test_mask_threshold_scaling(bool use_gpu) struct gkyl_dg_array_mask *mask2d = gkyl_dg_array_mask_new(mask_inp2d); double expected2d = threshold * pow(sqrt(2.0), 2); - TEST_CHECK(gkyl_compare(mask2d->threshold, expected2d, 1e-14) ); + TEST_CHECK(gkyl_compare(mask2d->threshold, expected2d, 1e-14)); gkyl_dg_array_mask_release(mask2d); // Test 3D - int shape3d[] = { 3, 3, 3 }; + int shape3d[] = {3, 3, 3}; struct gkyl_range range3d; gkyl_range_init_from_shape(&range3d, 3, shape3d); @@ -749,14 +746,14 @@ void test_mask_threshold_scaling(bool use_gpu) struct gkyl_dg_array_mask *mask3d = gkyl_dg_array_mask_new(mask_inp3d); double expected3d = threshold * pow(sqrt(2.0), 3); - TEST_CHECK(gkyl_compare(mask3d->threshold, expected3d, 1e-14) ); + TEST_CHECK(gkyl_compare(mask3d->threshold, expected3d, 1e-14)); gkyl_dg_array_mask_release(mask3d); } // Test fractional threshold mask (global) void test_mask_advance_frac_threshold(bool use_gpu) { - int shape[] = { 10 }; + int shape[] = {10}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 1, shape); @@ -796,10 +793,9 @@ void test_mask_advance_frac_threshold(bool use_gpu) const double *mask_d = gkyl_array_cfetch(mask_ho, i); const double *arr_d = gkyl_array_cfetch(arr_ho, i); if (fabs(arr_d[0]) < expected_threshold) { - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); // True (masked) - } - else { - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); // False (not masked) + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); // True (masked) + } else { + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); // False (not masked) } } @@ -812,7 +808,7 @@ void test_mask_advance_frac_threshold(bool use_gpu) // Test fractional threshold mask GREATER_THAN (global) void test_mask_advance_frac_threshold_greater(bool use_gpu) { - int shape[] = { 8 }; + int shape[] = {8}; struct gkyl_range range; gkyl_range_init_from_shape(&range, 1, shape); @@ -830,14 +826,14 @@ void test_mask_advance_frac_threshold_greater(bool use_gpu) // Create test array with varying values struct gkyl_array *arr = mkarr(use_gpu, 1, range.volume); struct gkyl_array *arr_ho = mkarr(false, arr->ncomp, arr->size); - double vals[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + double vals[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}; double max_val = 8.0; for (unsigned i = 0; i < range.volume; ++i) { double *arr_d = gkyl_array_fetch(arr_ho, i); arr_d[0] = vals[i]; } gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -854,10 +850,9 @@ void test_mask_advance_frac_threshold_greater(bool use_gpu) const double *mask_d = gkyl_array_cfetch(mask_ho, i); const double *arr_d = gkyl_array_cfetch(arr_ho, i); if (fabs(arr_d[0]) > expected_threshold) { - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); // True (masked) - } - else { - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); // False (not masked) + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); // True (masked) + } else { + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); // False (not masked) } } @@ -871,9 +866,9 @@ void test_mask_advance_frac_threshold_greater(bool use_gpu) void test_mask_advance_frac_threshold_spatial(bool use_gpu) { // Set up 2x2 configuration space, 3x3 velocity space - int conf_shape[] = { 2, 2 }; - int vel_shape[] = { 3, 3 }; - int phase_shape[] = { 2, 2, 3, 3 }; + int conf_shape[] = {2, 2}; + int vel_shape[] = {3, 3}; + int phase_shape[] = {2, 2, 3, 3}; struct gkyl_range conf_rng, vel_rng, phase_rng; gkyl_range_init_from_shape(&conf_rng, 2, conf_shape); @@ -927,7 +922,7 @@ void test_mask_advance_frac_threshold_spatial(bool use_gpu) } gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -960,10 +955,9 @@ void test_mask_advance_frac_threshold_spatial(bool use_gpu) const double *arr_d = gkyl_array_cfetch(arr_ho, phase_idx); if (fabs(arr_d[0]) < expected_threshold) { - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); // True (masked) - } - else { - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); // False (not masked) + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); // True (masked) + } else { + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); // False (not masked) } } } @@ -978,9 +972,9 @@ void test_mask_advance_frac_threshold_spatial(bool use_gpu) void test_mask_advance_frac_threshold_spatial_greater(bool use_gpu) { // Simpler test: 2 config cells, 4 velocity cells - int conf_shape[] = { 2 }; - int vel_shape[] = { 4 }; - int phase_shape[] = { 2, 4 }; + int conf_shape[] = {2}; + int vel_shape[] = {4}; + int phase_shape[] = {2, 4}; struct gkyl_range conf_rng, vel_rng, phase_rng; gkyl_range_init_from_shape(&conf_rng, 1, conf_shape); @@ -1008,7 +1002,7 @@ void test_mask_advance_frac_threshold_spatial_greater(bool use_gpu) for (int ic = 0; ic < 2; ic++) { double local_max = (ic + 1) * 10.0; for (int iv = 0; iv < 4; iv++) { - int pidx[2] = { ic, iv }; + int pidx[2] = {ic, iv}; long phase_idx = gkyl_range_idx(&phase_rng, pidx); double *arr_d = gkyl_array_fetch(arr_ho, phase_idx); // Values: 2.5, 5.0, 7.5, 10.0 for ic=0 and 5.0, 10.0, 15.0, 20.0 for ic=1 @@ -1017,7 +1011,7 @@ void test_mask_advance_frac_threshold_spatial_greater(bool use_gpu) } gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -1034,17 +1028,16 @@ void test_mask_advance_frac_threshold_spatial_greater(bool use_gpu) double expected_threshold = frac_threshold * local_max; // 6.0 and 12.0 for (int iv = 0; iv < 4; iv++) { - int pidx[2] = { ic, iv }; + int pidx[2] = {ic, iv}; long phase_idx = gkyl_range_idx(&phase_rng, pidx); const double *mask_d = gkyl_array_cfetch(mask_ho, phase_idx); const double *arr_d = gkyl_array_cfetch(arr_ho, phase_idx); if (fabs(arr_d[0]) > expected_threshold) { - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); // True (masked) - } - else { - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); // False (not masked) + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); // True (masked) + } else { + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); // False (not masked) } } } @@ -1060,9 +1053,9 @@ void test_mask_advance_frac_threshold_spatial_greater(bool use_gpu) // Test mask advance with value threshold and extended range (ghost cells) void test_mask_advance_threshold_ext_range(bool use_gpu, int ncell, int nghost_cell) { - double lower[] = { 0.0 }; - double upper[] = { 8.0 }; - int cells[] = { ncell }; + double lower[] = {0.0}; + double upper[] = {8.0}; + int cells[] = {ncell}; int ndim = sizeof(lower) / sizeof(lower[0]); struct gkyl_rect_grid grid; @@ -1103,7 +1096,7 @@ void test_mask_advance_threshold_ext_range(bool use_gpu, int ncell, int nghost_c } gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -1122,10 +1115,9 @@ void test_mask_advance_threshold_ext_range(bool use_gpu, int ncell, int nghost_c const double *mask_d = gkyl_array_cfetch(mask_ho, lidx); const double *arr_d = gkyl_array_cfetch(arr_ho, lidx); if (fabs(arr_d[0]) < expected_threshold) { - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); // True (masked) - } - else { - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); // False (not masked) + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); // True (masked) + } else { + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); // False (not masked) } } @@ -1153,9 +1145,9 @@ void test_mask_advance_threshold_ext_range(bool use_gpu, int ncell, int nghost_c // Test fractional threshold mask with extended range (ghost cells) void test_mask_advance_frac_threshold_ext_range(bool use_gpu) { - double lower[] = { 0.0 }; - double upper[] = { 10.0 }; - int cells[] = { 10 }; + double lower[] = {0.0}; + double upper[] = {10.0}; + int cells[] = {10}; int ndim = sizeof(lower) / sizeof(lower[0]); struct gkyl_rect_grid grid; @@ -1199,8 +1191,7 @@ void test_mask_advance_frac_threshold_ext_range(bool use_gpu) // Interior: values from 1.0 to 10.0 based on position in local range int local_pos = iter.idx[0] - local.lower[0]; arr_d[0] = (local_pos + 1) * 1.0; - } - else { + } else { // Ghost cells: small value arr_d[0] = 0.5; } @@ -1228,10 +1219,9 @@ void test_mask_advance_frac_threshold_ext_range(bool use_gpu) const double *mask_d = gkyl_array_cfetch(mask_ho, lidx); const double *arr_d = gkyl_array_cfetch(arr_ho, lidx); if (fabs(arr_d[0]) < expected_threshold) { - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); // True (masked) - } - else { - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); // False (not masked) + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); // True (masked) + } else { + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); // False (not masked) } } @@ -1263,9 +1253,9 @@ void test_mask_advance_frac_threshold_spatial_ext_range(bool use_gpu) // Using gkyl_create_grid_ranges for both config and phase space // to ensure consistent indexing - double conf_lower[] = { 0.0 }; - double conf_upper[] = { 4.0 }; - int conf_cells[] = { 4 }; + double conf_lower[] = {0.0}; + double conf_upper[] = {4.0}; + int conf_cells[] = {4}; int conf_ndim = 1; struct gkyl_rect_grid conf_grid; @@ -1280,9 +1270,9 @@ void test_mask_advance_frac_threshold_spatial_ext_range(bool use_gpu) gkyl_create_grid_ranges(&conf_grid, conf_nghost, &conf_local_ext, &conf_local); // Velocity space using grid ranges as well for consistency - double vel_lower[] = { 0.0 }; - double vel_upper[] = { 4.0 }; - int vel_cells[] = { 4 }; + double vel_lower[] = {0.0}; + double vel_upper[] = {4.0}; + int vel_cells[] = {4}; int vel_ndim = 1; struct gkyl_rect_grid vel_grid; @@ -1295,9 +1285,9 @@ void test_mask_advance_frac_threshold_spatial_ext_range(bool use_gpu) gkyl_create_grid_ranges(&vel_grid, vel_nghost, &vel_local_ext, &vel_local); // Phase space = config x velocity, with ghost cells in config direction only - double phase_lower[] = { 0.0, 0.0 }; - double phase_upper[] = { 4.0, 4.0 }; - int phase_cells[] = { 4, 4 }; + double phase_lower[] = {0.0, 0.0}; + double phase_upper[] = {4.0, 4.0}; + int phase_cells[] = {4, 4}; int phase_ndim = 2; struct gkyl_rect_grid phase_grid; @@ -1340,7 +1330,7 @@ void test_mask_advance_frac_threshold_spatial_ext_range(bool use_gpu) gkyl_range_iter_init(&iter_vel, &vel_local); while (gkyl_range_iter_next(&iter_vel)) { - int pidx[2] = { iter_conf.idx[0], iter_vel.idx[0] }; + int pidx[2] = {iter_conf.idx[0], iter_vel.idx[0]}; long phase_idx = gkyl_range_idx(&phase_local_ext, pidx); int vel_pos = iter_vel.idx[0] - vel_local.lower[0]; @@ -1351,7 +1341,7 @@ void test_mask_advance_frac_threshold_spatial_ext_range(bool use_gpu) } gkyl_array_copy(arr, arr_ho); - + double global_max = 0.0; gkyl_array_reduce(&global_max, arr_ho, GKYL_MAX); gkyl_dg_array_mask_advance_threshold(mask, global_max); @@ -1372,17 +1362,16 @@ void test_mask_advance_frac_threshold_spatial_ext_range(bool use_gpu) gkyl_range_iter_init(&iter_vel, &vel_local); while (gkyl_range_iter_next(&iter_vel)) { - int pidx[2] = { iter_conf.idx[0], iter_vel.idx[0] }; + int pidx[2] = {iter_conf.idx[0], iter_vel.idx[0]}; long phase_idx = gkyl_range_idx(&phase_local_ext, pidx); const double *mask_d = gkyl_array_cfetch(mask_ho, phase_idx); const double *arr_d = gkyl_array_cfetch(arr_ho, phase_idx); if (fabs(arr_d[0]) < expected_threshold) { - TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14) ); // True (masked) - } - else { - TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14) ); // False (not masked) + TEST_CHECK(gkyl_compare(mask_d[0], 1.0, 1e-14)); // True (masked) + } else { + TEST_CHECK(gkyl_compare(mask_d[0], -1.0, 1e-14)); // False (not masked) } } } @@ -1399,7 +1388,7 @@ void test_mask_advance_frac_threshold_spatial_ext_range(bool use_gpu) gkyl_range_iter_init(&iter_vel, &vel_local); while (gkyl_range_iter_next(&iter_vel)) { - int pidx[2] = { iter_conf.idx[0], iter_vel.idx[0] }; + int pidx[2] = {iter_conf.idx[0], iter_vel.idx[0]}; long phase_idx = gkyl_range_idx(&phase_local_ext, pidx); const double *arr_d = gkyl_array_cfetch(arr_ho, phase_idx); @@ -1669,60 +1658,60 @@ void test_mask_advance_frac_threshold_spatial_ext_range_dev() #endif TEST_LIST = { - { "mask_new_ho", test_mask_new_ho }, - { "mask_none_type_ho", test_mask_none_type_ho }, - { "mask_advance_threshold_ho", test_mask_advance_threshold_ho }, - { "mask_advance_all_below_ho", test_mask_advance_all_below_ho }, - { "mask_advance_all_above_ho", test_mask_advance_all_above_ho }, - { "mask_advance_negative_values_ho", test_mask_advance_negative_values_ho }, - { "mask_advance_greater_than_threshold_ho", test_mask_advance_greater_than_threshold_ho }, - { "mask_advance_greater_than_all_above_ho", test_mask_advance_greater_than_all_above_ho }, - { "mask_advance_greater_than_all_below_ho", test_mask_advance_greater_than_all_below_ho }, - { "mask_advance_greater_than_neg_vals_ho", test_mask_advance_greater_than_negative_values_ho }, - { "mask_eval_ho", test_mask_eval_ho }, - { "mask_eval_none_type_ho", test_mask_eval_none_type_ho }, - { "mask_scale_by_cell_ho", test_mask_scale_by_cell_ho }, - { "mask_acquire_release_ho", test_mask_acquire_release_ho }, - { "mask_threshold_scaling_ho", test_mask_threshold_scaling_ho }, - { "mask_advance_frac_threshold_ho", test_mask_advance_frac_threshold_ho }, - { "mask_advance_frac_threshold_greater_ho", test_mask_advance_frac_threshold_greater_ho }, - { "mask_advance_frac_threshold_spatial_ho", test_mask_advance_frac_threshold_spatial_ho }, - { "mask_advance_frac_threshold_spatial_greater_ho", - test_mask_advance_frac_threshold_spatial_greater_ho }, - { "mask_advance_threshold_ext_range_1_ho", test_mask_advance_threshold_ext_range_1_ho }, - { "mask_advance_threshold_ext_range_2_ho", test_mask_advance_threshold_ext_range_2_ho }, - { "mask_advance_threshold_ext_range_3_ho", test_mask_advance_threshold_ext_range_3_ho }, - { "mask_advance_threshold_ext_range_4_ho", test_mask_advance_threshold_ext_range_4_ho }, - { "mask_advance_frac_threshold_ext_range_ho", test_mask_advance_frac_threshold_ext_range_ho }, - { "mask_advance_frac_threshold_spatial_ext_range_ho", - test_mask_advance_frac_threshold_spatial_ext_range_ho }, + {"mask_new_ho", test_mask_new_ho}, + {"mask_none_type_ho", test_mask_none_type_ho}, + {"mask_advance_threshold_ho", test_mask_advance_threshold_ho}, + {"mask_advance_all_below_ho", test_mask_advance_all_below_ho}, + {"mask_advance_all_above_ho", test_mask_advance_all_above_ho}, + {"mask_advance_negative_values_ho", test_mask_advance_negative_values_ho}, + {"mask_advance_greater_than_threshold_ho", test_mask_advance_greater_than_threshold_ho}, + {"mask_advance_greater_than_all_above_ho", test_mask_advance_greater_than_all_above_ho}, + {"mask_advance_greater_than_all_below_ho", test_mask_advance_greater_than_all_below_ho}, + {"mask_advance_greater_than_neg_vals_ho", test_mask_advance_greater_than_negative_values_ho}, + {"mask_eval_ho", test_mask_eval_ho}, + {"mask_eval_none_type_ho", test_mask_eval_none_type_ho}, + {"mask_scale_by_cell_ho", test_mask_scale_by_cell_ho}, + {"mask_acquire_release_ho", test_mask_acquire_release_ho}, + {"mask_threshold_scaling_ho", test_mask_threshold_scaling_ho}, + {"mask_advance_frac_threshold_ho", test_mask_advance_frac_threshold_ho}, + {"mask_advance_frac_threshold_greater_ho", test_mask_advance_frac_threshold_greater_ho}, + {"mask_advance_frac_threshold_spatial_ho", test_mask_advance_frac_threshold_spatial_ho}, + {"mask_advance_frac_threshold_spatial_greater_ho", + test_mask_advance_frac_threshold_spatial_greater_ho}, + {"mask_advance_threshold_ext_range_1_ho", test_mask_advance_threshold_ext_range_1_ho}, + {"mask_advance_threshold_ext_range_2_ho", test_mask_advance_threshold_ext_range_2_ho}, + {"mask_advance_threshold_ext_range_3_ho", test_mask_advance_threshold_ext_range_3_ho}, + {"mask_advance_threshold_ext_range_4_ho", test_mask_advance_threshold_ext_range_4_ho}, + {"mask_advance_frac_threshold_ext_range_ho", test_mask_advance_frac_threshold_ext_range_ho}, + {"mask_advance_frac_threshold_spatial_ext_range_ho", + test_mask_advance_frac_threshold_spatial_ext_range_ho}, #ifdef GKYL_HAVE_CUDA - { "mask_new_dev", test_mask_new_dev }, - { "mask_none_type_dev", test_mask_none_type_dev }, - { "mask_advance_threshold_dev", test_mask_advance_threshold_dev }, - { "mask_advance_all_below_dev", test_mask_advance_all_below_dev }, - { "mask_advance_all_above_dev", test_mask_advance_all_above_dev }, - { "mask_advance_negative_values_dev", test_mask_advance_negative_values_dev }, - { "mask_advance_greater_than_threshold_dev", test_mask_advance_greater_than_threshold_dev }, - { "mask_advance_greater_than_all_above_dev", test_mask_advance_greater_than_all_above_dev }, - { "mask_advance_greater_than_all_below_dev", test_mask_advance_greater_than_all_below_dev }, - { "mask_advance_greater_than_neg_vals_dev", test_mask_advance_greater_than_negative_values_dev }, - { "mask_eval_none_type_dev", test_mask_eval_none_type_dev }, - { "mask_scale_by_cell_dev", test_mask_scale_by_cell_dev }, - { "mask_acquire_release_dev", test_mask_acquire_release_dev }, - { "mask_threshold_scaling_dev", test_mask_threshold_scaling_dev }, - { "mask_advance_frac_threshold_dev", test_mask_advance_frac_threshold_dev }, - { "mask_advance_frac_threshold_greater_dev", test_mask_advance_frac_threshold_greater_dev }, - { "mask_advance_frac_threshold_spatial_dev", test_mask_advance_frac_threshold_spatial_dev }, - { "mask_advance_frac_threshold_spatial_greater_dev", - test_mask_advance_frac_threshold_spatial_greater_dev }, - { "mask_advance_threshold_ext_range_1_dev", test_mask_advance_threshold_ext_range_1_dev }, - { "mask_advance_threshold_ext_range_2_dev", test_mask_advance_threshold_ext_range_2_dev }, - { "mask_advance_threshold_ext_range_3_dev", test_mask_advance_threshold_ext_range_3_dev }, - { "mask_advance_threshold_ext_range_4_dev", test_mask_advance_threshold_ext_range_4_dev }, - { "mask_advance_frac_threshold_ext_range_dev", test_mask_advance_frac_threshold_ext_range_dev }, - { "mask_advance_frac_threshold_spatial_ext_range_dev", - test_mask_advance_frac_threshold_spatial_ext_range_dev }, + {"mask_new_dev", test_mask_new_dev}, + {"mask_none_type_dev", test_mask_none_type_dev}, + {"mask_advance_threshold_dev", test_mask_advance_threshold_dev}, + {"mask_advance_all_below_dev", test_mask_advance_all_below_dev}, + {"mask_advance_all_above_dev", test_mask_advance_all_above_dev}, + {"mask_advance_negative_values_dev", test_mask_advance_negative_values_dev}, + {"mask_advance_greater_than_threshold_dev", test_mask_advance_greater_than_threshold_dev}, + {"mask_advance_greater_than_all_above_dev", test_mask_advance_greater_than_all_above_dev}, + {"mask_advance_greater_than_all_below_dev", test_mask_advance_greater_than_all_below_dev}, + {"mask_advance_greater_than_neg_vals_dev", test_mask_advance_greater_than_negative_values_dev}, + {"mask_eval_none_type_dev", test_mask_eval_none_type_dev}, + {"mask_scale_by_cell_dev", test_mask_scale_by_cell_dev}, + {"mask_acquire_release_dev", test_mask_acquire_release_dev}, + {"mask_threshold_scaling_dev", test_mask_threshold_scaling_dev}, + {"mask_advance_frac_threshold_dev", test_mask_advance_frac_threshold_dev}, + {"mask_advance_frac_threshold_greater_dev", test_mask_advance_frac_threshold_greater_dev}, + {"mask_advance_frac_threshold_spatial_dev", test_mask_advance_frac_threshold_spatial_dev}, + {"mask_advance_frac_threshold_spatial_greater_dev", + test_mask_advance_frac_threshold_spatial_greater_dev}, + {"mask_advance_threshold_ext_range_1_dev", test_mask_advance_threshold_ext_range_1_dev}, + {"mask_advance_threshold_ext_range_2_dev", test_mask_advance_threshold_ext_range_2_dev}, + {"mask_advance_threshold_ext_range_3_dev", test_mask_advance_threshold_ext_range_3_dev}, + {"mask_advance_threshold_ext_range_4_dev", test_mask_advance_threshold_ext_range_4_dev}, + {"mask_advance_frac_threshold_ext_range_dev", test_mask_advance_frac_threshold_ext_range_dev}, + {"mask_advance_frac_threshold_spatial_ext_range_dev", + test_mask_advance_frac_threshold_spatial_ext_range_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/core/unit/ctest_dg_basis_ops.c b/core/unit/ctest_dg_basis_ops.c index 202921296e..dcce3a30a1 100644 --- a/core/unit/ctest_dg_basis_ops.c +++ b/core/unit/ctest_dg_basis_ops.c @@ -6,57 +6,61 @@ #include #include - -static inline double sq(double x) { return x*x; } -static inline double cub(double x) { return x*x*x; } +static inline double sq(double x) +{ + return x * x; +} +static inline double cub(double x) +{ + return x * x * x; +} // Allocate array (filled with zeros). -static struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { - struct gkyl_array* a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } static void -eval_array_at_coord_1d_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +eval_array_at_coord_1d_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0]; double Lx = 5.0; - fout[0] = 3.3*0.5*(1.0+cos((2*M_PI/Lx)*x)); + fout[0] = 3.3 * 0.5 * (1.0 + cos((2 * M_PI / Lx) * x)); } -void -test_eval_array_at_coord_1d_p_hodev(int poly_order, bool use_gpu) +void test_eval_array_at_coord_1d_p_hodev(int poly_order, bool use_gpu) { - double lower[] = { 0.0 }, upper[] = { 5.0 }; - int cells[] = { 8 }; + double lower[] = {0.0}, upper[] = {5.0}; + int cells[] = {8}; double eval_coord_ho[] = {3.0}; // Result = 3.3*0.5*(1+sin((2*pi/5)*3.0)) = 0.315121959 - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); int nghost[GKYL_MAX_DIM]; - for (int d=0; deval_cubic_wgrad(0.0, xn, fout, evf->ctx); - TEST_CHECK( gkyl_compare_double(fout[0], sq(xn[0])*sq(xn[1]), 1.0e-14) ); - TEST_CHECK( gkyl_compare_double(fout[1], 2*xn[0]*sq(xn[1]), 1.0e-14) ); - TEST_CHECK( gkyl_compare_double(fout[2], 2*sq(xn[0])*xn[1], 1.0e-14) ); + TEST_CHECK(gkyl_compare_double(fout[0], sq(xn[0]) * sq(xn[1]), 1.0e-14)); + TEST_CHECK(gkyl_compare_double(fout[1], 2 * xn[0] * sq(xn[1]), 1.0e-14)); + TEST_CHECK(gkyl_compare_double(fout[2], 2 * sq(xn[0]) * xn[1], 1.0e-14)); // Test wgrad2 function: f, d2f/dx2, d2f/dy2, and d2f/dxdy evf->eval_cubic_wgrad2(0.0, xn, fout, evf->ctx); - TEST_CHECK( gkyl_compare_double(fout[0], sq(xn[0])*sq(xn[1]), 1.0e-14) ); - TEST_CHECK( gkyl_compare_double(fout[1], 2*sq(xn[1]), 1.0e-14) ); - TEST_CHECK( gkyl_compare_double(fout[2], 2*sq(xn[0]), 1.0e-14) ); - TEST_CHECK( gkyl_compare_double(fout[3], 4*xn[0]*xn[1], 1.0e-14) ); + TEST_CHECK(gkyl_compare_double(fout[0], sq(xn[0]) * sq(xn[1]), 1.0e-14)); + TEST_CHECK(gkyl_compare_double(fout[1], 2 * sq(xn[1]), 1.0e-14)); + TEST_CHECK(gkyl_compare_double(fout[2], 2 * sq(xn[0]), 1.0e-14)); + TEST_CHECK(gkyl_compare_double(fout[3], 4 * xn[0] * xn[1], 1.0e-14)); gkyl_array_release(psi_nodal); gkyl_array_release(psi_cubic); - + gkyl_dg_basis_op_mem_release(mem); gkyl_dg_basis_ops_evalf_release(evf); } -void -test_basis_ops_eval_array_at_coord_1d_ho() { +void test_basis_ops_eval_array_at_coord_1d_ho() +{ // p = 1 test_eval_array_at_coord_1d_p_hodev(1, false); } #ifdef GKYL_HAVE_CUDA -void -test_basis_ops_eval_array_at_coord_1d_dev() { +void test_basis_ops_eval_array_at_coord_1d_dev() +{ // p = 1 test_eval_array_at_coord_1d_p_hodev(1, true); } #endif TEST_LIST = { - { "test_basis_ops_eval_array_at_coord_1d_ho", test_basis_ops_eval_array_at_coord_1d_ho }, - { "basis_ops_cubic_1d_ho", test_basis_ops_cubic_1d_ho }, - { "basis_ops_cubic_2d_ho", test_basis_ops_cubic_2d_ho }, - { "basis_ops_cubic_evalf_2d_ho", test_basis_ops_cubic_evalf_2d_ho }, + {"test_basis_ops_eval_array_at_coord_1d_ho", test_basis_ops_eval_array_at_coord_1d_ho}, + {"basis_ops_cubic_1d_ho", test_basis_ops_cubic_1d_ho}, + {"basis_ops_cubic_2d_ho", test_basis_ops_cubic_2d_ho}, + {"basis_ops_cubic_evalf_2d_ho", test_basis_ops_cubic_evalf_2d_ho}, #ifdef GKYL_HAVE_CUDA - { "test_basis_ops_eval_array_at_coord_1d_dev", test_basis_ops_eval_array_at_coord_1d_dev }, + {"test_basis_ops_eval_array_at_coord_1d_dev", test_basis_ops_eval_array_at_coord_1d_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; - diff --git a/core/unit/ctest_dg_bin_ops.c b/core/unit/ctest_dg_bin_ops.c index ecbb07e63c..3792c254a4 100644 --- a/core/unit/ctest_dg_bin_ops.c +++ b/core/unit/ctest_dg_bin_ops.c @@ -10,76 +10,160 @@ #include #include -void f_1d(double t, const double *xn, double* restrict fout, void *ctx) +void f_1d(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 2 + x; } -void g_1d(double t, const double *xn, double* restrict fout, void *ctx) +void g_1d(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 2*x*x + 8; + fout[0] = 2 * x * x + 8; } -void fv2_1d(double t, const double *xn, double* restrict fout, void *ctx) +void fv2_1d(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 2. + x; fout[1] = 1. - x; } -void gv2_1d(double t, const double *xn, double* restrict fout, void *ctx) +void gv2_1d(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 2*x*x + 8; - fout[1] = x*x - 8; + fout[0] = 2 * x * x + 8; + fout[1] = x * x - 8; } -void fv3_1d(double t, const double *xn, double* restrict fout, void *ctx) +void fv3_1d(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 2. + x; fout[1] = 1. - x; fout[2] = 0.5 + x; } -void gv3_1d(double t, const double *xn, double* restrict fout, void *ctx) +void gv3_1d(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 2*x*x + 8; - fout[1] = x*x - 8; - fout[2] = 0.5*x*x + 4; + fout[0] = 2 * x * x + 8; + fout[1] = x * x - 8; + fout[2] = 0.5 * x * x + 4; } -void check_dot_product_1d(const double *fv1_d, const double *gv1_d, const double *fvdgv1_d, - const double *fv2_d, const double *gv2_d, const double *fvdgv2_d, - const double *fv3_d, const double *gv3_d, const double *fvdgv3_d, - int poly_order) { +void check_dot_product_1d( + const double *fv1_d, const double *gv1_d, const double *fvdgv1_d, const double *fv2_d, + const double *gv2_d, const double *fvdgv2_d, const double *fv3_d, const double *gv3_d, + const double *fvdgv3_d, int poly_order +) +{ if (poly_order == 1) { - TEST_CHECK( gkyl_compare(fvdgv1_d[0], 0.7071067811865475*(fv1_d[1]*gv1_d[1]+fv1_d[0]*gv1_d[0]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv1_d[1], 0.7071067811865475*(fv1_d[0]*gv1_d[1]+gv1_d[0]*fv1_d[1]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv2_d[0], 0.7071067811865475*(fv2_d[3]*gv2_d[3]+fv2_d[2]*gv2_d[2]+fv2_d[1]*gv2_d[1]+fv2_d[0]*gv2_d[0]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv2_d[1], 0.7071067811865475*(fv2_d[2]*gv2_d[3]+gv2_d[2]*fv2_d[3]+fv2_d[0]*gv2_d[1]+gv2_d[0]*fv2_d[1]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv3_d[0], 0.7071067811865475*(fv3_d[5]*gv3_d[5]+fv3_d[4]*gv3_d[4]+fv3_d[3]*gv3_d[3]+fv3_d[2]*gv3_d[2]+fv3_d[1]*gv3_d[1]+fv3_d[0]*gv3_d[0]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv3_d[1], 0.7071067811865475*(fv3_d[4]*gv3_d[5]+gv3_d[4]*fv3_d[5]+fv3_d[2]*gv3_d[3]+gv3_d[2]*fv3_d[3]+fv3_d[0]*gv3_d[1]+gv3_d[0]*fv3_d[1]), 1e-12) ); + TEST_CHECK(gkyl_compare( + fvdgv1_d[0], 0.7071067811865475 * (fv1_d[1] * gv1_d[1] + fv1_d[0] * gv1_d[0]), 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv1_d[1], 0.7071067811865475 * (fv1_d[0] * gv1_d[1] + gv1_d[0] * fv1_d[1]), 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv2_d[0], + 0.7071067811865475 * + (fv2_d[3] * gv2_d[3] + fv2_d[2] * gv2_d[2] + fv2_d[1] * gv2_d[1] + fv2_d[0] * gv2_d[0]), + 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv2_d[1], + 0.7071067811865475 * + (fv2_d[2] * gv2_d[3] + gv2_d[2] * fv2_d[3] + fv2_d[0] * gv2_d[1] + gv2_d[0] * fv2_d[1]), + 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv3_d[0], + 0.7071067811865475 * (fv3_d[5] * gv3_d[5] + fv3_d[4] * gv3_d[4] + fv3_d[3] * gv3_d[3] + + fv3_d[2] * gv3_d[2] + fv3_d[1] * gv3_d[1] + fv3_d[0] * gv3_d[0]), + 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv3_d[1], + 0.7071067811865475 * (fv3_d[4] * gv3_d[5] + gv3_d[4] * fv3_d[5] + fv3_d[2] * gv3_d[3] + + gv3_d[2] * fv3_d[3] + fv3_d[0] * gv3_d[1] + gv3_d[0] * fv3_d[1]), + 1e-12 + )); } else if (poly_order == 2) { - TEST_CHECK( gkyl_compare(fvdgv1_d[0], 0.7071067811865475*(fv1_d[2]*gv1_d[2]+fv1_d[1]*gv1_d[1]+fv1_d[0]*gv1_d[0]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv1_d[1], 0.1414213562373095*(4.47213595499958*fv1_d[1]*gv1_d[2]+4.47213595499958*gv1_d[1]*fv1_d[2]+5.0*fv1_d[0]*gv1_d[1]+5.0*gv1_d[0]*fv1_d[1]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv1_d[2], 0.02020305089104421*((22.3606797749979*fv1_d[2]+35.0*fv1_d[0])*gv1_d[2]+35.0*gv1_d[0]*fv1_d[2]+31.30495168499706*fv1_d[1]*gv1_d[1]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv2_d[0], 0.7071067811865475*(fv2_d[5]*gv2_d[5]+fv2_d[4]*gv2_d[4]+fv2_d[3]*gv2_d[3]+fv2_d[2]*gv2_d[2]+fv2_d[1]*gv2_d[1]+fv2_d[0]*gv2_d[0]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv2_d[1], 0.1414213562373095*(4.47213595499958*fv2_d[4]*gv2_d[5]+4.47213595499958*gv2_d[4]*fv2_d[5]+5.0*fv2_d[3]*gv2_d[4]+5.0*gv2_d[3]*fv2_d[4]+4.47213595499958*fv2_d[1]*gv2_d[2]+4.47213595499958*gv2_d[1]*fv2_d[2]+5.0*fv2_d[0]*gv2_d[1]+5.0*gv2_d[0]*fv2_d[1]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv2_d[2], 0.02020305089104421*((22.3606797749979*fv2_d[5]+35.0*fv2_d[3])*gv2_d[5]+35.0*gv2_d[3]*fv2_d[5]+31.30495168499706*fv2_d[4]*gv2_d[4]+(22.3606797749979*fv2_d[2]+35.0*fv2_d[0])*gv2_d[2]+35.0*gv2_d[0]*fv2_d[2]+31.30495168499706*fv2_d[1]*gv2_d[1]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv3_d[0], 0.7071067811865475*(fv3_d[8]*gv3_d[8]+fv3_d[7]*gv3_d[7]+fv3_d[6]*gv3_d[6]+fv3_d[5]*gv3_d[5]+fv3_d[4]*gv3_d[4]+fv3_d[3]*gv3_d[3]+fv3_d[2]*gv3_d[2]+fv3_d[1]*gv3_d[1]+fv3_d[0]*gv3_d[0]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv3_d[1], 0.1414213562373095*(4.47213595499958*fv3_d[7]*gv3_d[8]+4.47213595499958*gv3_d[7]*fv3_d[8]+5.0*fv3_d[6]*gv3_d[7]+5.0*gv3_d[6]*fv3_d[7]+4.47213595499958*fv3_d[4]*gv3_d[5]+4.47213595499958*gv3_d[4]*fv3_d[5]+5.0*fv3_d[3]*gv3_d[4]+5.0*gv3_d[3]*fv3_d[4]+4.47213595499958*fv3_d[1]*gv3_d[2]+4.47213595499958*gv3_d[1]*fv3_d[2]+5.0*fv3_d[0]*gv3_d[1]+5.0*gv3_d[0]*fv3_d[1]), 1e-12) ); - TEST_CHECK( gkyl_compare(fvdgv3_d[2], 0.02020305089104421*((22.3606797749979*fv3_d[8]+35.0*fv3_d[6])*gv3_d[8]+35.0*gv3_d[6]*fv3_d[8]+31.30495168499706*fv3_d[7]*gv3_d[7]+(22.3606797749979*fv3_d[5]+35.0*fv3_d[3])*gv3_d[5]+35.0*gv3_d[3]*fv3_d[5]+31.30495168499706*fv3_d[4]*gv3_d[4]+(22.3606797749979*fv3_d[2]+35.0*fv3_d[0])*gv3_d[2]+35.0*gv3_d[0]*fv3_d[2]+31.30495168499706*fv3_d[1]*gv3_d[1]), 1e-12) ); + TEST_CHECK(gkyl_compare( + fvdgv1_d[0], + 0.7071067811865475 * (fv1_d[2] * gv1_d[2] + fv1_d[1] * gv1_d[1] + fv1_d[0] * gv1_d[0]), 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv1_d[1], + 0.1414213562373095 * + (4.47213595499958 * fv1_d[1] * gv1_d[2] + 4.47213595499958 * gv1_d[1] * fv1_d[2] + + 5.0 * fv1_d[0] * gv1_d[1] + 5.0 * gv1_d[0] * fv1_d[1]), + 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv1_d[2], + 0.02020305089104421 * ((22.3606797749979 * fv1_d[2] + 35.0 * fv1_d[0]) * gv1_d[2] + + 35.0 * gv1_d[0] * fv1_d[2] + 31.30495168499706 * fv1_d[1] * gv1_d[1]), + 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv2_d[0], + 0.7071067811865475 * (fv2_d[5] * gv2_d[5] + fv2_d[4] * gv2_d[4] + fv2_d[3] * gv2_d[3] + + fv2_d[2] * gv2_d[2] + fv2_d[1] * gv2_d[1] + fv2_d[0] * gv2_d[0]), + 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv2_d[1], + 0.1414213562373095 * + (4.47213595499958 * fv2_d[4] * gv2_d[5] + 4.47213595499958 * gv2_d[4] * fv2_d[5] + + 5.0 * fv2_d[3] * gv2_d[4] + 5.0 * gv2_d[3] * fv2_d[4] + + 4.47213595499958 * fv2_d[1] * gv2_d[2] + 4.47213595499958 * gv2_d[1] * fv2_d[2] + + 5.0 * fv2_d[0] * gv2_d[1] + 5.0 * gv2_d[0] * fv2_d[1]), + 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv2_d[2], + 0.02020305089104421 * ((22.3606797749979 * fv2_d[5] + 35.0 * fv2_d[3]) * gv2_d[5] + + 35.0 * gv2_d[3] * fv2_d[5] + 31.30495168499706 * fv2_d[4] * gv2_d[4] + + (22.3606797749979 * fv2_d[2] + 35.0 * fv2_d[0]) * gv2_d[2] + + 35.0 * gv2_d[0] * fv2_d[2] + 31.30495168499706 * fv2_d[1] * gv2_d[1]), + 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv3_d[0], + 0.7071067811865475 * (fv3_d[8] * gv3_d[8] + fv3_d[7] * gv3_d[7] + fv3_d[6] * gv3_d[6] + + fv3_d[5] * gv3_d[5] + fv3_d[4] * gv3_d[4] + fv3_d[3] * gv3_d[3] + + fv3_d[2] * gv3_d[2] + fv3_d[1] * gv3_d[1] + fv3_d[0] * gv3_d[0]), + 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv3_d[1], + 0.1414213562373095 * + (4.47213595499958 * fv3_d[7] * gv3_d[8] + 4.47213595499958 * gv3_d[7] * fv3_d[8] + + 5.0 * fv3_d[6] * gv3_d[7] + 5.0 * gv3_d[6] * fv3_d[7] + + 4.47213595499958 * fv3_d[4] * gv3_d[5] + 4.47213595499958 * gv3_d[4] * fv3_d[5] + + 5.0 * fv3_d[3] * gv3_d[4] + 5.0 * gv3_d[3] * fv3_d[4] + + 4.47213595499958 * fv3_d[1] * gv3_d[2] + 4.47213595499958 * gv3_d[1] * fv3_d[2] + + 5.0 * fv3_d[0] * gv3_d[1] + 5.0 * gv3_d[0] * fv3_d[1]), + 1e-12 + )); + TEST_CHECK(gkyl_compare( + fvdgv3_d[2], + 0.02020305089104421 * ((22.3606797749979 * fv3_d[8] + 35.0 * fv3_d[6]) * gv3_d[8] + + 35.0 * gv3_d[6] * fv3_d[8] + 31.30495168499706 * fv3_d[7] * gv3_d[7] + + (22.3606797749979 * fv3_d[5] + 35.0 * fv3_d[3]) * gv3_d[5] + + 35.0 * gv3_d[3] * fv3_d[5] + 31.30495168499706 * fv3_d[4] * gv3_d[4] + + (22.3606797749979 * fv3_d[2] + 35.0 * fv3_d[0]) * gv3_d[2] + + 35.0 * gv3_d[0] * fv3_d[2] + 31.30495168499706 * fv3_d[1] * gv3_d[1]), + 1e-12 + )); } return; } -void -test_1d(int poly_order, bool use_gpu) +void test_1d(int poly_order, bool use_gpu) { double lower[] = {0.0}, upper[] = {1.0}; int cells[] = {2}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); @@ -88,18 +172,24 @@ test_1d(int poly_order, bool use_gpu) gkyl_cart_modal_serendip(&basis, ndim, poly_order); // projection updater for dist-function - struct gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, 1, f_1d, NULL); - struct gkyl_proj_on_basis *projDistg = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, 1, g_1d, NULL); + struct gkyl_proj_on_basis *projDistf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, f_1d, NULL); + struct gkyl_proj_on_basis *projDistg = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, g_1d, NULL); // projection updaters for vector fields. - struct gkyl_proj_on_basis *projfv2 = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, 2, fv2_1d, NULL); - struct gkyl_proj_on_basis *projgv2 = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, 2, gv2_1d, NULL); - struct gkyl_proj_on_basis *projfv3 = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, 3, fv3_1d, NULL); - struct gkyl_proj_on_basis *projgv3 = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, 3, gv3_1d, NULL); + struct gkyl_proj_on_basis *projfv2 = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 2, fv2_1d, NULL); + struct gkyl_proj_on_basis *projgv2 = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 2, gv2_1d, NULL); + struct gkyl_proj_on_basis *projfv3 = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 3, fv3_1d, NULL); + struct gkyl_proj_on_basis *projgv3 = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 3, gv3_1d, NULL); // create array range: no ghost-cells in velocity space - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; - gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); + gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); // create distribution function struct gkyl_array *distf = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); @@ -126,20 +216,20 @@ test_1d(int poly_order, bool use_gpu) gkyl_array_clear(g_bar, 0.0); // Vector fields for dot product. - struct gkyl_array *fv1 = gkyl_array_new(GKYL_DOUBLE, 1*basis.num_basis, arr_range.volume); - struct gkyl_array *gv1 = gkyl_array_new(GKYL_DOUBLE, 1*basis.num_basis, arr_range.volume); - struct gkyl_array *fv2 = gkyl_array_new(GKYL_DOUBLE, 2*basis.num_basis, arr_range.volume); - struct gkyl_array *gv2 = gkyl_array_new(GKYL_DOUBLE, 2*basis.num_basis, arr_range.volume); - struct gkyl_array *fv3 = gkyl_array_new(GKYL_DOUBLE, 3*basis.num_basis, arr_range.volume); - struct gkyl_array *gv3 = gkyl_array_new(GKYL_DOUBLE, 3*basis.num_basis, arr_range.volume); + struct gkyl_array *fv1 = gkyl_array_new(GKYL_DOUBLE, 1 * basis.num_basis, arr_range.volume); + struct gkyl_array *gv1 = gkyl_array_new(GKYL_DOUBLE, 1 * basis.num_basis, arr_range.volume); + struct gkyl_array *fv2 = gkyl_array_new(GKYL_DOUBLE, 2 * basis.num_basis, arr_range.volume); + struct gkyl_array *gv2 = gkyl_array_new(GKYL_DOUBLE, 2 * basis.num_basis, arr_range.volume); + struct gkyl_array *fv3 = gkyl_array_new(GKYL_DOUBLE, 3 * basis.num_basis, arr_range.volume); + struct gkyl_array *gv3 = gkyl_array_new(GKYL_DOUBLE, 3 * basis.num_basis, arr_range.volume); struct gkyl_array *fv1_cu, *gv1_cu, *fv2_cu, *gv2_cu, *fv3_cu, *gv3_cu; if (use_gpu) { - fv1_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1*basis.num_basis, arr_range.volume); - gv1_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1*basis.num_basis, arr_range.volume); - fv2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 2*basis.num_basis, arr_range.volume); - gv2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 2*basis.num_basis, arr_range.volume); - fv3_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3*basis.num_basis, arr_range.volume); - gv3_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3*basis.num_basis, arr_range.volume); + fv1_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1 * basis.num_basis, arr_range.volume); + gv1_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1 * basis.num_basis, arr_range.volume); + fv2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 2 * basis.num_basis, arr_range.volume); + gv2_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 2 * basis.num_basis, arr_range.volume); + fv3_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3 * basis.num_basis, arr_range.volume); + gv3_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3 * basis.num_basis, arr_range.volume); } // project vector fields on basis. @@ -195,7 +285,7 @@ test_1d(int poly_order, bool use_gpu) if (use_gpu) { // allocate memory mem = gkyl_dg_bin_op_mem_cu_dev_new(f_bar->size, basis.num_basis); - + // h = f*g gkyl_dg_mul_op(&basis, 0, h_cu, 0, distf_cu, 0, distg_cu); // f_bar = h/g = f @@ -207,7 +297,7 @@ test_1d(int poly_order, bool use_gpu) gkyl_dg_dot_product_op(&basis, fvdgv1_cu, fv1_cu, gv1_cu); gkyl_dg_dot_product_op(&basis, fvdgv2_cu, fv2_cu, gv2_cu); gkyl_dg_dot_product_op(&basis, fvdgv3_cu, fv3_cu, gv3_cu); - + // copy from device and check if things are ok gkyl_array_copy(f_bar, f_bar_cu); gkyl_array_copy(g_bar, g_bar_cu); @@ -232,14 +322,14 @@ test_1d(int poly_order, bool use_gpu) gkyl_dg_dot_product_op(&basis, fvdgv3, fv3, gv3); } - for (size_t i=0; isize, basis.num_basis); + gkyl_dg_bin_op_mem *mem = gkyl_dg_bin_op_mem_new(f_bar->size, basis.num_basis); // h = f*g gkyl_dg_mul_op(&basis, 0, h, 0, distf, 0, distg); @@ -1787,14 +3048,14 @@ test_bin_ops_3d_p3_ho() // g_bar = h/f = g gkyl_dg_div_op(mem, &basis, 0, g_bar, 0, h, 0, distf); - for (size_t i=0; i pout = g - f gkyl_array_copy(pout, g_full); - gkyl_dg_mul_conf_phase_op_accumulate_range(&subbasis, &basis, pout, -1.0, - f_sub, ones_phase, &sub_local, &local); + gkyl_dg_mul_conf_phase_op_accumulate_range( + &subbasis, &basis, pout, -1.0, f_sub, ones_phase, &sub_local, &local + ); // Copy pout back to host if using GPU gkyl_array_copy(pout_ho, pout); @@ -1936,10 +3210,11 @@ test_subspace_accumulate(int poly_order, bool use_gpu) gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&local, iter.idx); - const double *pout_d = gkyl_array_cfetch(pout_ho, loc); - const double *h_d = gkyl_array_cfetch(h_sol_ho, loc); - for (int k = 0; k < basis.num_basis; ++k) - TEST_CHECK( gkyl_compare(h_d[k], pout_d[k], 1e-11) ); + const double *pout_d = gkyl_array_cfetch(pout_ho, loc); + const double *h_d = gkyl_array_cfetch(h_sol_ho, loc); + for (int k = 0; k < basis.num_basis; ++k) { + TEST_CHECK(gkyl_compare(h_d[k], pout_d[k], 1e-11)); + } } // cleanup @@ -1954,34 +3229,69 @@ test_subspace_accumulate(int poly_order, bool use_gpu) gkyl_array_release(pout_ho); } -void test_bin_ops_conf_phase_accumulate_subtract_p1_ho() { test_subspace_accumulate(1, false); } -void test_bin_ops_conf_phase_accumulate_subtract_p2_ho() { test_subspace_accumulate(2, false); } +void test_bin_ops_conf_phase_accumulate_subtract_p1_ho() +{ + test_subspace_accumulate(1, false); +} +void test_bin_ops_conf_phase_accumulate_subtract_p2_ho() +{ + test_subspace_accumulate(2, false); +} // Cuda specific tests #ifdef GKYL_HAVE_CUDA -void test_bin_ops_1d_p1_dev(){ test_1d(1, true); } -void test_bin_ops_1d_p2_dev(){ test_1d(2, true); } -void test_bin_ops_1d_p3_dev(){ test_1d(3, true); } +void test_bin_ops_1d_p1_dev() +{ + test_1d(1, true); +} +void test_bin_ops_1d_p2_dev() +{ + test_1d(2, true); +} +void test_bin_ops_1d_p3_dev() +{ + test_1d(3, true); +} -void test_bin_ops_inv_1d_p1_dev(){ test_inv_1d(1, true); } +void test_bin_ops_inv_1d_p1_dev() +{ + test_inv_1d(1, true); +} -void test_bin_ops_2d_p1_dev(){ test_2d(1, true); } -void test_bin_ops_2d_p2_dev(){ test_2d(2, true); } -void test_bin_ops_2d_p3_dev(){ test_2d(3, true); } +void test_bin_ops_2d_p1_dev() +{ + test_2d(1, true); +} +void test_bin_ops_2d_p2_dev() +{ + test_2d(2, true); +} +void test_bin_ops_2d_p3_dev() +{ + test_2d(3, true); +} -void test_bin_ops_inv_2d_p1_dev(){ test_inv_2d(1, true); } +void test_bin_ops_inv_2d_p1_dev() +{ + test_inv_2d(1, true); +} -void test_bin_ops_3d_p1_dev(){ test_3d(1, true); } -void test_bin_ops_3d_p2_dev(){ test_3d(2, true); } +void test_bin_ops_3d_p1_dev() +{ + test_3d(1, true); +} +void test_bin_ops_3d_p2_dev() +{ + test_3d(2, true); +} -void -test_bin_ops_3d_p3_dev() +void test_bin_ops_3d_p3_dev() { int poly_order = 3; double lower[] = {0.0, 0.0, 0.0}, upper[] = {1.0, 1.0, 1.0}; int cells[] = {2, 2, 2}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); @@ -1994,7 +3304,7 @@ test_bin_ops_3d_p3_dev() struct gkyl_proj_on_basis *projDistg = gkyl_proj_on_basis_new(&grid, &basis, 5, 1, g_3d_p3, NULL); // create array range: no ghost-cells in velocity space - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -2003,8 +3313,10 @@ test_bin_ops_3d_p3_dev() struct gkyl_array *distg = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); // make device copies of arrays - struct gkyl_array *distf_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); - struct gkyl_array *distg_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); + struct gkyl_array *distf_cu = + gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); + struct gkyl_array *distg_cu = + gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); // project distribution function on basis on CPU gkyl_proj_on_basis_advance(projDistf, 0.0, &arr_range, distf); @@ -2019,12 +3331,14 @@ test_bin_ops_3d_p3_dev() gkyl_array_clear(h_cu, 0.0); struct gkyl_array *f_bar = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); - struct gkyl_array *f_bar_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); + struct gkyl_array *f_bar_cu = + gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); gkyl_array_clear(f_bar, 0.0); gkyl_array_clear(f_bar_cu, 0.0); struct gkyl_array *g_bar = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); - struct gkyl_array *g_bar_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); + struct gkyl_array *g_bar_cu = + gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, arr_range.volume); gkyl_array_clear(g_bar, 0.0); gkyl_array_clear(g_bar_cu, 0.0); @@ -2040,14 +3354,14 @@ test_bin_ops_3d_p3_dev() // copy from device and check if things are ok gkyl_array_copy(f_bar, f_bar_cu); gkyl_array_copy(g_bar, g_bar_cu); - for (size_t i=0; i // Allocate array (filled with zeros). -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } @@ -26,18 +26,16 @@ struct fin_ctx { double exp_c[20]; // Expansion coefficients in test function. }; -void fin_1x_func(double t, const double *xn, double* restrict fout, void *ctx) +void fin_1x_func(double t, const double *xn, double *restrict fout, void *ctx) { - struct fin_ctx *params = ctx; const double *a = params->exp_c; double x = xn[0]; - fout[0] = a[0] + a[1]*x; + fout[0] = a[0] + a[1] * x; } -void -test_dg_differentiate_1x(int poly_order, bool use_gpu) +void test_dg_differentiate_1x(int poly_order, bool use_gpu) { double lower[] = {-M_PI}, upper[] = {M_PI}; int cells[] = {6}; @@ -47,7 +45,7 @@ test_dg_differentiate_1x(int poly_order, bool use_gpu) inp_params.exp_c[0] = 2.0; inp_params.exp_c[1] = 0.3; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); // Basis. struct gkyl_basis basis; @@ -59,29 +57,34 @@ test_dg_differentiate_1x(int poly_order, bool use_gpu) // Ranges int ghost[GKYL_MAX_DIM] = {0}; - for (int d=0; dncomp, fin->size) - : gkyl_array_acquire(fin); + struct gkyl_array *fin_ho = use_gpu ? mkarr(false, fin->ncomp, fin->size) : + gkyl_array_acquire(fin); gkyl_proj_on_basis_advance(proj_fin, 0.0, &local, fin_ho); gkyl_array_copy(fin, fin_ho); struct gkyl_array *derf = mkarr(use_gpu, basis.num_basis, local_ext.volume); - struct gkyl_array *derf_ho = use_gpu? mkarr(false, derf->ncomp, derf->size) - : gkyl_array_acquire(derf); + struct gkyl_array *derf_ho = use_gpu ? mkarr(false, derf->ncomp, derf->size) : + gkyl_array_acquire(derf); // Differentiate input field. int diff_dir = 0; int diff_order = 1; - gkyl_dg_differentiate_op_local_range(&basis, diff_dir, diff_order, grid.dx[diff_dir], 0, derf, 0, fin, &local); + gkyl_dg_differentiate_op_local_range( + &basis, diff_dir, diff_order, grid.dx[diff_dir], 0, derf, 0, fin, &local + ); // Check results. gkyl_array_copy(derf_ho, derf); @@ -94,14 +97,14 @@ test_dg_differentiate_1x(int poly_order, bool use_gpu) double ref_val; m = 0; - ref_val = inp_params.exp_c[1]*pow(sqrt(2.0),ndim); - TEST_CHECK( gkyl_compare(derf_c[m], ref_val, 1e-10) ); - TEST_MSG( "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, derf_c[m], ref_val); + ref_val = inp_params.exp_c[1] * pow(sqrt(2.0), ndim); + TEST_CHECK(gkyl_compare(derf_c[m], ref_val, 1e-10)); + TEST_MSG("idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, derf_c[m], ref_val); m = 1; ref_val = 0.0; - TEST_CHECK( gkyl_compare(derf_c[m], ref_val, 1e-10) ); - TEST_MSG( "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, derf_c[m], ref_val); + TEST_CHECK(gkyl_compare(derf_c[m], ref_val, 1e-10)); + TEST_MSG("idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, derf_c[m], ref_val); } gkyl_proj_on_basis_release(proj_fin); @@ -109,18 +112,16 @@ test_dg_differentiate_1x(int poly_order, bool use_gpu) gkyl_array_release(fin_ho); } -void fin_2x_func(double t, const double *xn, double* restrict fout, void *ctx) +void fin_2x_func(double t, const double *xn, double *restrict fout, void *ctx) { - struct fin_ctx *params = ctx; const double *a = params->exp_c; double x = xn[0], y = xn[1]; - fout[0] = a[0] + a[1]*x + a[2]*y + a[3]*x*y; + fout[0] = a[0] + a[1] * x + a[2] * y + a[3] * x * y; } -void -test_dg_differentiate_2x(int poly_order, bool use_gpu) +void test_dg_differentiate_2x(int poly_order, bool use_gpu) { double lower[] = {-M_PI, -2.0}, upper[] = {M_PI, 2.0}; int cells[] = {6, 4}; @@ -132,7 +133,7 @@ test_dg_differentiate_2x(int poly_order, bool use_gpu) inp_params.exp_c[2] = 1.7; inp_params.exp_c[3] = 1.1; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); // Basis. struct gkyl_basis basis; @@ -144,29 +145,34 @@ test_dg_differentiate_2x(int poly_order, bool use_gpu) // Ranges int ghost[GKYL_MAX_DIM] = {0}; - for (int d=0; dncomp, fin->size) - : gkyl_array_acquire(fin); + struct gkyl_array *fin_ho = use_gpu ? mkarr(false, fin->ncomp, fin->size) : + gkyl_array_acquire(fin); gkyl_proj_on_basis_advance(proj_fin, 0.0, &local, fin_ho); gkyl_array_copy(fin, fin_ho); struct gkyl_array *derf = mkarr(use_gpu, basis.num_basis, local_ext.volume); - struct gkyl_array *derf_ho = use_gpu? mkarr(false, derf->ncomp, derf->size) - : gkyl_array_acquire(derf); - + struct gkyl_array *derf_ho = use_gpu ? mkarr(false, derf->ncomp, derf->size) : + gkyl_array_acquire(derf); + // Differentiate input field along x. int diff_dir = 0; int diff_order = 1; - gkyl_dg_differentiate_op_local_range(&basis, diff_dir, diff_order, grid.dx[diff_dir], 0, derf, 0, fin, &local); + gkyl_dg_differentiate_op_local_range( + &basis, diff_dir, diff_order, grid.dx[diff_dir], 0, derf, 0, fin, &local + ); // Check results. gkyl_array_copy(derf_ho, derf); @@ -182,30 +188,44 @@ test_dg_differentiate_2x(int poly_order, bool use_gpu) gkyl_rect_grid_cell_center(&grid, iter.idx, xc); m = 0; - ref_val = (inp_params.exp_c[1]+xc[1]*inp_params.exp_c[3])*pow(sqrt(2.0),ndim); - TEST_CHECK( gkyl_compare(derf_c[m], ref_val, 1e-10) ); - TEST_MSG( "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], ref_val); + ref_val = (inp_params.exp_c[1] + xc[1] * inp_params.exp_c[3]) * pow(sqrt(2.0), ndim); + TEST_CHECK(gkyl_compare(derf_c[m], ref_val, 1e-10)); + TEST_MSG( + "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], + ref_val + ); m = 1; ref_val = 0.0; - TEST_CHECK( gkyl_compare(derf_c[m], ref_val, 1e-10) ); - TEST_MSG( "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], ref_val); + TEST_CHECK(gkyl_compare(derf_c[m], ref_val, 1e-10)); + TEST_MSG( + "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], + ref_val + ); m = 2; - ref_val = inp_params.exp_c[3]*grid.dx[1]/sqrt(3.0); - TEST_CHECK( gkyl_compare(derf_c[m], ref_val, 1e-10) ); - TEST_MSG( "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], ref_val); + ref_val = inp_params.exp_c[3] * grid.dx[1] / sqrt(3.0); + TEST_CHECK(gkyl_compare(derf_c[m], ref_val, 1e-10)); + TEST_MSG( + "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], + ref_val + ); m = 3; ref_val = 0.0; - TEST_CHECK( gkyl_compare(derf_c[m], ref_val, 1e-10) ); - TEST_MSG( "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], ref_val); + TEST_CHECK(gkyl_compare(derf_c[m], ref_val, 1e-10)); + TEST_MSG( + "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], + ref_val + ); } // Differentiate input field along y. diff_dir = 1; diff_order = 1; - gkyl_dg_differentiate_op_local_range(&basis, diff_dir, diff_order, grid.dx[diff_dir], 0, derf, 0, fin, &local); + gkyl_dg_differentiate_op_local_range( + &basis, diff_dir, diff_order, grid.dx[diff_dir], 0, derf, 0, fin, &local + ); // Check results. gkyl_array_copy(derf_ho, derf); @@ -220,24 +240,36 @@ test_dg_differentiate_2x(int poly_order, bool use_gpu) gkyl_rect_grid_cell_center(&grid, iter.idx, xc); m = 0; - ref_val = (inp_params.exp_c[2]+xc[0]*inp_params.exp_c[3])*pow(sqrt(2.0),ndim); - TEST_CHECK( gkyl_compare(derf_c[m], ref_val, 1e-10) ); - TEST_MSG( "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], ref_val); + ref_val = (inp_params.exp_c[2] + xc[0] * inp_params.exp_c[3]) * pow(sqrt(2.0), ndim); + TEST_CHECK(gkyl_compare(derf_c[m], ref_val, 1e-10)); + TEST_MSG( + "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], + ref_val + ); m = 1; - ref_val = inp_params.exp_c[3]*grid.dx[0]/sqrt(3.0); - TEST_CHECK( gkyl_compare(derf_c[m], ref_val, 1e-10) ); - TEST_MSG( "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], ref_val); + ref_val = inp_params.exp_c[3] * grid.dx[0] / sqrt(3.0); + TEST_CHECK(gkyl_compare(derf_c[m], ref_val, 1e-10)); + TEST_MSG( + "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], + ref_val + ); m = 2; ref_val = 0.0; - TEST_CHECK( gkyl_compare(derf_c[m], ref_val, 1e-10) ); - TEST_MSG( "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], ref_val); + TEST_CHECK(gkyl_compare(derf_c[m], ref_val, 1e-10)); + TEST_MSG( + "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], + ref_val + ); m = 3; ref_val = 0.0; - TEST_CHECK( gkyl_compare(derf_c[m], ref_val, 1e-10) ); - TEST_MSG( "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], ref_val); + TEST_CHECK(gkyl_compare(derf_c[m], ref_val, 1e-10)); + TEST_MSG( + "idx=%d,%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], iter.idx[1], m, derf_c[m], + ref_val + ); } gkyl_proj_on_basis_release(proj_fin); @@ -245,19 +277,17 @@ test_dg_differentiate_2x(int poly_order, bool use_gpu) gkyl_array_release(fin_ho); } -void fin_3x_func(double t, const double *xn, double* restrict fout, void *ctx) +void fin_3x_func(double t, const double *xn, double *restrict fout, void *ctx) { - struct fin_ctx *params = ctx; const double *a = params->exp_c; double x = xn[0], y = xn[1], z = xn[2]; - fout[0] = a[0] + a[1]*x + a[2]*y + a[3]*x*y + a[4]*z + a[5]*x*z + a[6]*y*z + a[7]*x*y*z; - + fout[0] = a[0] + a[1] * x + a[2] * y + a[3] * x * y + a[4] * z + a[5] * x * z + a[6] * y * z + + a[7] * x * y * z; } -void -test_dg_differentiate_3x(int poly_order, bool use_gpu) +void test_dg_differentiate_3x(int poly_order, bool use_gpu) { double lower[] = {-M_PI, -2.0, 1.0}, upper[] = {M_PI, 2.0, 3.5}; int cells[] = {6, 4, 4}; @@ -273,7 +303,7 @@ test_dg_differentiate_3x(int poly_order, bool use_gpu) inp_params.exp_c[6] = 4.1; inp_params.exp_c[7] = 0.5; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); // Basis. struct gkyl_basis basis; @@ -285,25 +315,28 @@ test_dg_differentiate_3x(int poly_order, bool use_gpu) // Ranges int ghost[GKYL_MAX_DIM] = {0}; - for (int d=0; dncomp, fin->size) - : gkyl_array_acquire(fin); + struct gkyl_array *fin_ho = use_gpu ? mkarr(false, fin->ncomp, fin->size) : + gkyl_array_acquire(fin); gkyl_proj_on_basis_advance(proj_fin, 0.0, &local, fin_ho); gkyl_array_copy(fin, fin_ho); struct gkyl_array *derf = mkarr(use_gpu, basis.num_basis, local_ext.volume); - struct gkyl_array *derf_ho = use_gpu? mkarr(false, derf->ncomp, derf->size) - : gkyl_array_acquire(derf); - + struct gkyl_array *derf_ho = use_gpu ? mkarr(false, derf->ncomp, derf->size) : + gkyl_array_acquire(derf); + int diff_dir; int diff_order; struct gkyl_range_iter iter; @@ -311,7 +344,9 @@ test_dg_differentiate_3x(int poly_order, bool use_gpu) // Differentiate input field along x. diff_dir = 0; diff_order = 1; - gkyl_dg_differentiate_op_local_range(&basis, diff_dir, diff_order, grid.dx[diff_dir], 0, derf, 0, fin, &local); + gkyl_dg_differentiate_op_local_range( + &basis, diff_dir, diff_order, grid.dx[diff_dir], 0, derf, 0, fin, &local + ); // Check results. gkyl_array_copy(derf_ho, derf); @@ -327,26 +362,32 @@ test_dg_differentiate_3x(int poly_order, bool use_gpu) const double *a = inp_params.exp_c; const double ref_val[] = { - pow(sqrt(2),3)*xc[1]*xc[2]*a[7]+pow(sqrt(2),3)*xc[2]*a[5]+pow(sqrt(2),3)*xc[1]*a[3]+pow(sqrt(2),3)*a[1], + pow(sqrt(2), 3) * xc[1] * xc[2] * a[7] + pow(sqrt(2), 3) * xc[2] * a[5] + + pow(sqrt(2), 3) * xc[1] * a[3] + pow(sqrt(2), 3) * a[1], 0, - (sqrt(2)*sqrt(3)*dx[1]*xc[2]*a[7]+sqrt(2)*sqrt(3)*dx[1]*a[3])/3, - (sqrt(2)*sqrt(3)*xc[1]*dx[2]*a[7]+sqrt(2)*sqrt(3)*dx[2]*a[5])/3, + (sqrt(2) * sqrt(3) * dx[1] * xc[2] * a[7] + sqrt(2) * sqrt(3) * dx[1] * a[3]) / 3, + (sqrt(2) * sqrt(3) * xc[1] * dx[2] * a[7] + sqrt(2) * sqrt(3) * dx[2] * a[5]) / 3, 0, 0, - (dx[1]*dx[2]*a[7])/(3*sqrt(2)), + (dx[1] * dx[2] * a[7]) / (3 * sqrt(2)), 0 }; - for (int m=0; m #include -static struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { // Allocate array (filled with zeros). - return use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + return use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); } -static void -eval_f_1x(double t, const double *xn, double *restrict fout, void *ctx) +static void eval_f_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 1.0 + 2.0*x; + fout[0] = 1.0 + 2.0 * x; } -static void -test_1x_to_scalar(int poly_order, bool use_gpu) +static void test_1x_to_scalar(int poly_order, bool use_gpu) { // Evaluate a 1D DG field at a fixed x0, reducing to a scalar. // Verified by comparing against the analytic value f(x0) * (1/sqrt(2)). @@ -37,7 +34,7 @@ test_1x_to_scalar(int poly_order, bool use_gpu) double x0 = 0.75; // lies in the second x-cell [0.5, 1.0] - int ndim_do = sizeof(cells_do)/sizeof(cells_do[0]); + int ndim_do = sizeof(cells_do) / sizeof(cells_do[0]); struct gkyl_rect_grid grid_do; gkyl_rect_grid_init(&grid_do, ndim_do, lower_do, upper_do, cells_do); @@ -51,10 +48,10 @@ test_1x_to_scalar(int poly_order, bool use_gpu) // Project f(x) onto the donor basis. struct gkyl_array *fdo = mkarr(use_gpu, basis_do.num_basis, local_ext_do.volume); - struct gkyl_array *fdo_ho = use_gpu? mkarr(false, fdo->ncomp, fdo->size) - : gkyl_array_acquire(fdo); - gkyl_proj_on_basis *proj_do = gkyl_proj_on_basis_new(&grid_do, &basis_do, - poly_order+1, 1, eval_f_1x, NULL); + struct gkyl_array *fdo_ho = use_gpu ? mkarr(false, fdo->ncomp, fdo->size) : + gkyl_array_acquire(fdo); + gkyl_proj_on_basis *proj_do = + gkyl_proj_on_basis_new(&grid_do, &basis_do, poly_order + 1, 1, eval_f_1x, NULL); gkyl_proj_on_basis_advance(proj_do, 0.0, &local_do, fdo_ho); gkyl_array_copy(fdo, fdo_ho); @@ -64,21 +61,21 @@ test_1x_to_scalar(int poly_order, bool use_gpu) gkyl_range_init(&local_tar, 1, lower_tar, upper_tar); struct gkyl_array *ftar = mkarr(use_gpu, 1, local_tar.volume); - struct gkyl_array *ftar_ho = use_gpu? mkarr(false, 1, 1) - : gkyl_array_acquire(ftar); + struct gkyl_array *ftar_ho = use_gpu ? mkarr(false, 1, 1) : gkyl_array_acquire(ftar); // Create the updater: evaluate in x (dir 0). int eval_dirs[] = {0}; - int num_eval_dirs = sizeof(eval_dirs)/sizeof(eval_dirs[0]); - struct gkyl_dg_eval_at_coord_proj *up = gkyl_dg_eval_at_coord_proj_new( - basis_do.ndim, &basis_do, num_eval_dirs, eval_dirs, use_gpu); + int num_eval_dirs = sizeof(eval_dirs) / sizeof(eval_dirs[0]); + struct gkyl_dg_eval_at_coord_proj *up = + gkyl_dg_eval_at_coord_proj_new(basis_do.ndim, &basis_do, num_eval_dirs, eval_dirs, use_gpu); // Apply updater at x = x0. double eval_coords[] = {x0}; bool pick_lower[] = {false}; int known_index[] = {-1}; - gkyl_dg_eval_at_coord_proj_advance(up, eval_coords, &grid_do, pick_lower, known_index, - &local_do, &local_tar, fdo, ftar); + gkyl_dg_eval_at_coord_proj_advance( + up, eval_coords, &grid_do, pick_lower, known_index, &local_do, &local_tar, fdo, ftar + ); // Reference: f(x0) / sqrt(2). double fref; @@ -107,18 +104,16 @@ struct dg_evproj_tst_ctx { int dirs_tar[GKYL_MAX_DIM]; }; -static void -eval_f_2x(double t, const double *xn, double *restrict fout, void *ctx) +static void eval_f_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; - fout[0] = 1.0 + 2.0*x + 3.0*y + 4.0*x*y; + fout[0] = 1.0 + 2.0 * x + 3.0 * y + 4.0 * x * y; } -static void -eval_f_2x_at_coord(double t, const double *xn, double *restrict fout, void *ctx) +static void eval_f_2x_at_coord(double t, const double *xn, double *restrict fout, void *ctx) { - struct dg_evproj_tst_ctx *params = (struct dg_evproj_tst_ctx *) ctx; + struct dg_evproj_tst_ctx *params = (struct dg_evproj_tst_ctx *)ctx; int ndim_do = params->ndim_do; int num_eval_dirs = params->num_eval_dirs; @@ -128,18 +123,21 @@ eval_f_2x_at_coord(double t, const double *xn, double *restrict fout, void *ctx) int *dirs_tar = params->dirs_tar; double xn_p[GKYL_MAX_DIM]; - for (int d=0; dncomp, fdo->size) - : gkyl_array_acquire(fdo); - - gkyl_proj_on_basis *proj_do = gkyl_proj_on_basis_new(&grid_do, &basis_do, - poly_order+1, 1, eval_f_2x, NULL); + struct gkyl_array *fdo_ho = use_gpu ? mkarr(false, fdo->ncomp, fdo->size) : + gkyl_array_acquire(fdo); + + gkyl_proj_on_basis *proj_do = + gkyl_proj_on_basis_new(&grid_do, &basis_do, poly_order + 1, 1, eval_f_2x, NULL); gkyl_proj_on_basis_advance(proj_do, 0.0, &local_do, fdo_ho); gkyl_array_copy(fdo, fdo_ho); @@ -202,31 +201,34 @@ test_2x_ev_at_1dcoord(int ndim_do, const double *lower_do, const double *upper_d struct dg_evproj_tst_ctx eval_params; eval_params.ndim_do = ndim_do; eval_params.num_eval_dirs = num_eval_dirs; - for (int d=0; dncomp, ftar->size) - : gkyl_array_acquire(ftar); + struct gkyl_array *ftar_ho = use_gpu ? mkarr(false, ftar->ncomp, ftar->size) : + gkyl_array_acquire(ftar); bool pick_lower[] = {false, false, false, false, false, false}; int known_index[] = {-1, -1, -1, -1, -1, -1}; - gkyl_dg_eval_at_coord_proj_advance(up, eval_coords, &grid_do, pick_lower, known_index, - &local_do, &local_tar, fdo, ftar); + gkyl_dg_eval_at_coord_proj_advance( + up, eval_coords, &grid_do, pick_lower, known_index, &local_do, &local_tar, fdo, ftar + ); // Check answer. gkyl_array_copy(ftar_ho, ftar); @@ -252,8 +254,7 @@ test_2x_ev_at_1dcoord(int ndim_do, const double *lower_do, const double *upper_d gkyl_array_release(fref_ho); } -static void -test_2x_to_1x(int poly_order, bool use_gpu) +static void test_2x_to_1x(int poly_order, bool use_gpu) { // Project a 2D DG field onto 1D by evaluating in x at a fixed // computational coordinate x0. Verified by comparing against a direct 1D @@ -261,27 +262,30 @@ test_2x_to_1x(int poly_order, bool use_gpu) double lower_do[] = {0.0, 0.0}, upper_do[] = {1.0, 1.0}; int cells_do[] = {2, 2}; - int ndim_do = sizeof(cells_do)/sizeof(cells_do[0]); + int ndim_do = sizeof(cells_do) / sizeof(cells_do[0]); int eval_dirs[1]; double eval_coords[1]; - int num_eval_dirs = sizeof(eval_dirs)/sizeof(eval_dirs[0]); + int num_eval_dirs = sizeof(eval_dirs) / sizeof(eval_dirs[0]); // Evaluate at x. eval_dirs[0] = 0; eval_coords[0] = 0.75; // lies in the second x-cell [0.5, 1.0] - test_2x_ev_at_1dcoord(ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, - eval_dirs, eval_coords, poly_order, use_gpu); + test_2x_ev_at_1dcoord( + ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, eval_dirs, eval_coords, poly_order, + use_gpu + ); // Evaluate at y. eval_dirs[0] = 1; eval_coords[0] = 0.25; // lies in the second x-cell [0.5, 1.0] - test_2x_ev_at_1dcoord(ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, - eval_dirs, eval_coords, poly_order, use_gpu); + test_2x_ev_at_1dcoord( + ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, eval_dirs, eval_coords, poly_order, + use_gpu + ); } -static void -test_2x_to_scalar(int poly_order, bool use_gpu) +static void test_2x_to_scalar(int poly_order, bool use_gpu) { // Evaluate a 2D DG field at a fixed (x0, y0), reducing to a scalar. // Verified by comparing against the analytic value f(x0, y0). @@ -292,7 +296,7 @@ test_2x_to_scalar(int poly_order, bool use_gpu) double x0 = 0.75, y0 = 0.25; // x0 in [0.5, 1.0], y0 in [0.0, 0.5] - int ndim_do = sizeof(cells_do)/sizeof(cells_do[0]); + int ndim_do = sizeof(cells_do) / sizeof(cells_do[0]); struct gkyl_rect_grid grid_do; gkyl_rect_grid_init(&grid_do, ndim_do, lower_do, upper_do, cells_do); @@ -306,10 +310,10 @@ test_2x_to_scalar(int poly_order, bool use_gpu) // Project f(x,y) onto the donor basis. struct gkyl_array *fdo = mkarr(use_gpu, basis_do.num_basis, local_ext_do.volume); - struct gkyl_array *fdo_ho = use_gpu? mkarr(false, fdo->ncomp, fdo->size) - : gkyl_array_acquire(fdo); - gkyl_proj_on_basis *proj_do = gkyl_proj_on_basis_new(&grid_do, &basis_do, - poly_order+1, 1, eval_f_2x, NULL); + struct gkyl_array *fdo_ho = use_gpu ? mkarr(false, fdo->ncomp, fdo->size) : + gkyl_array_acquire(fdo); + gkyl_proj_on_basis *proj_do = + gkyl_proj_on_basis_new(&grid_do, &basis_do, poly_order + 1, 1, eval_f_2x, NULL); gkyl_proj_on_basis_advance(proj_do, 0.0, &local_do, fdo_ho); gkyl_array_copy(fdo, fdo_ho); @@ -319,27 +323,28 @@ test_2x_to_scalar(int poly_order, bool use_gpu) gkyl_range_init(&local_tar, 1, lower_tar, upper_tar); struct gkyl_array *ftar = mkarr(use_gpu, 1, local_tar.volume); - struct gkyl_array *ftar_ho = use_gpu? mkarr(false, ftar->ncomp, ftar->size) - : gkyl_array_acquire(ftar); + struct gkyl_array *ftar_ho = use_gpu ? mkarr(false, ftar->ncomp, ftar->size) : + gkyl_array_acquire(ftar); // Evaluate and project field. int eval_dirs[] = {0, 1}; - int num_eval_dirs = sizeof(eval_dirs)/sizeof(eval_dirs[0]); - struct gkyl_dg_eval_at_coord_proj *up = gkyl_dg_eval_at_coord_proj_new( - basis_do.ndim, &basis_do, num_eval_dirs, eval_dirs, use_gpu); + int num_eval_dirs = sizeof(eval_dirs) / sizeof(eval_dirs[0]); + struct gkyl_dg_eval_at_coord_proj *up = + gkyl_dg_eval_at_coord_proj_new(basis_do.ndim, &basis_do, num_eval_dirs, eval_dirs, use_gpu); // Apply updater at (x0, y0). double eval_coords[] = {x0, y0}; bool pick_lower[] = {false, false}; int known_index[] = {-1, -1}; - gkyl_dg_eval_at_coord_proj_advance(up, eval_coords, &grid_do, pick_lower, known_index, - &local_do, &local_tar, fdo, ftar); + gkyl_dg_eval_at_coord_proj_advance( + up, eval_coords, &grid_do, pick_lower, known_index, &local_do, &local_tar, fdo, ftar + ); // Check the results. double fref; - eval_f_2x(0.0, (const double[2]){x0,y0}, &fref, 0); + eval_f_2x(0.0, (const double[2]){x0, y0}, &fref, 0); // Apply normalization for p0. - fref *= 1.0/sqrt(2.0); + fref *= 1.0 / sqrt(2.0); gkyl_array_copy(ftar_ho, ftar); const double *ftar_c = gkyl_array_cfetch(ftar_ho, 0); @@ -354,19 +359,17 @@ test_2x_to_scalar(int poly_order, bool use_gpu) gkyl_array_release(ftar_ho); } -static void -eval_f_3x(double t, const double *xn, double *restrict fout, void *ctx) +static void eval_f_3x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; - fout[0] = 1.0 + 2.0*x + 3.0*y + 4.0*z - + 5.0*x*y + 6.0*x*z + 7.0*y*z + 8.0*x*y*z; + fout[0] = + 1.0 + 2.0 * x + 3.0 * y + 4.0 * z + 5.0 * x * y + 6.0 * x * z + 7.0 * y * z + 8.0 * x * y * z; } -static void -eval_f_3x_at_coord(double t, const double *xn, double *restrict fout, void *ctx) +static void eval_f_3x_at_coord(double t, const double *xn, double *restrict fout, void *ctx) { - struct dg_evproj_tst_ctx *params = (struct dg_evproj_tst_ctx *) ctx; + struct dg_evproj_tst_ctx *params = (struct dg_evproj_tst_ctx *)ctx; int num_eval_dirs = params->num_eval_dirs; int *eval_dirs = params->eval_dirs; @@ -375,18 +378,21 @@ eval_f_3x_at_coord(double t, const double *xn, double *restrict fout, void *ctx) int *dirs_tar = params->dirs_tar; double xn_p[GKYL_MAX_DIM]; - for (int d=0; dncomp, fdo->size) - : gkyl_array_acquire(fdo); - gkyl_proj_on_basis *proj_do = gkyl_proj_on_basis_new(&grid_do, &basis_do, - poly_order+1, 1, eval_f_3x, NULL); + struct gkyl_array *fdo_ho = use_gpu ? mkarr(false, fdo->ncomp, fdo->size) : + gkyl_array_acquire(fdo); + gkyl_proj_on_basis *proj_do = + gkyl_proj_on_basis_new(&grid_do, &basis_do, poly_order + 1, 1, eval_f_3x, NULL); gkyl_proj_on_basis_advance(proj_do, 0.0, &local_do, fdo_ho); gkyl_array_copy(fdo, fdo_ho); @@ -447,31 +454,34 @@ test_3x_ev_at_coord(int ndim_do, const double *lower_do, const double *upper_do, struct dg_evproj_tst_ctx eval_params; eval_params.ndim_do = ndim_do; eval_params.num_eval_dirs = num_eval_dirs; - for (int d=0; dncomp, ftar->size) - : gkyl_array_acquire(ftar); + struct gkyl_array *ftar_ho = use_gpu ? mkarr(false, ftar->ncomp, ftar->size) : + gkyl_array_acquire(ftar); bool pick_lower[] = {false, false, false, false, false, false}; int known_index[] = {-1, -1, -1, -1, -1, -1}; - gkyl_dg_eval_at_coord_proj_advance(up, eval_coords, &grid_do, pick_lower, known_index, - &local_do, &local_tar, fdo, ftar); + gkyl_dg_eval_at_coord_proj_advance( + up, eval_coords, &grid_do, pick_lower, known_index, &local_do, &local_tar, fdo, ftar + ); // Check answer. gkyl_array_copy(ftar_ho, ftar); @@ -497,74 +507,83 @@ test_3x_ev_at_coord(int ndim_do, const double *lower_do, const double *upper_do, gkyl_array_release(fref_ho); } -static void -test_3x_to_2x(int poly_order, bool use_gpu) +static void test_3x_to_2x(int poly_order, bool use_gpu) { double lower_do[] = {0.0, 0.0, 0.0}, upper_do[] = {1.0, 1.0, 1.0}; int cells_do[] = {2, 2, 2}; - int ndim_do = sizeof(cells_do)/sizeof(cells_do[0]); + int ndim_do = sizeof(cells_do) / sizeof(cells_do[0]); int eval_dirs[1]; double eval_coords[1]; - int num_eval_dirs = sizeof(eval_dirs)/sizeof(eval_dirs[0]); + int num_eval_dirs = sizeof(eval_dirs) / sizeof(eval_dirs[0]); // Evaluate at x. eval_dirs[0] = 0; eval_coords[0] = 0.75; - test_3x_ev_at_coord(ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, - eval_dirs, eval_coords, poly_order, use_gpu); + test_3x_ev_at_coord( + ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, eval_dirs, eval_coords, poly_order, + use_gpu + ); // Evaluate at y. eval_dirs[0] = 1; eval_coords[0] = 0.25; - test_3x_ev_at_coord(ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, - eval_dirs, eval_coords, poly_order, use_gpu); + test_3x_ev_at_coord( + ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, eval_dirs, eval_coords, poly_order, + use_gpu + ); // Evaluate at z. eval_dirs[0] = 2; eval_coords[0] = 0.6; - test_3x_ev_at_coord(ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, - eval_dirs, eval_coords, poly_order, use_gpu); + test_3x_ev_at_coord( + ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, eval_dirs, eval_coords, poly_order, + use_gpu + ); } -static void -test_3x_to_1x(int poly_order, bool use_gpu) +static void test_3x_to_1x(int poly_order, bool use_gpu) { double lower_do[] = {0.0, 0.0, 0.0}, upper_do[] = {1.0, 1.0, 1.0}; int cells_do[] = {2, 2, 2}; - int ndim_do = sizeof(cells_do)/sizeof(cells_do[0]); + int ndim_do = sizeof(cells_do) / sizeof(cells_do[0]); int eval_dirs[2]; double eval_coords[2]; - int num_eval_dirs = sizeof(eval_dirs)/sizeof(eval_dirs[0]); + int num_eval_dirs = sizeof(eval_dirs) / sizeof(eval_dirs[0]); // Evaluate at (x, y). eval_dirs[0] = 0; eval_dirs[1] = 1; eval_coords[0] = 0.75; eval_coords[1] = 0.25; - test_3x_ev_at_coord(ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, - eval_dirs, eval_coords, poly_order, use_gpu); + test_3x_ev_at_coord( + ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, eval_dirs, eval_coords, poly_order, + use_gpu + ); // Evaluate at (x, z). eval_dirs[0] = 0; eval_dirs[1] = 2; eval_coords[0] = 0.75; eval_coords[1] = 0.6; - test_3x_ev_at_coord(ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, - eval_dirs, eval_coords, poly_order, use_gpu); + test_3x_ev_at_coord( + ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, eval_dirs, eval_coords, poly_order, + use_gpu + ); // Evaluate at (y, z). eval_dirs[0] = 1; eval_dirs[1] = 2; eval_coords[0] = 0.25; eval_coords[1] = 0.6; - test_3x_ev_at_coord(ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, - eval_dirs, eval_coords, poly_order, use_gpu); + test_3x_ev_at_coord( + ndim_do, lower_do, upper_do, cells_do, num_eval_dirs, eval_dirs, eval_coords, poly_order, + use_gpu + ); } -static void -test_3x_to_scalar(int poly_order, bool use_gpu) +static void test_3x_to_scalar(int poly_order, bool use_gpu) { // Evaluate a 3D DG field at a fixed (x0, y0, z0), reducing to a scalar. // Verified by comparing against the analytic value f(x0, y0, z0) / sqrt(2). @@ -576,7 +595,7 @@ test_3x_to_scalar(int poly_order, bool use_gpu) // x0 in [0.5,1.0], y0 in [0.0,0.5], z0 in [0.5,1.0] double x0 = 0.75, y0 = 0.25, z0 = 0.6; - int ndim_do = sizeof(cells_do)/sizeof(cells_do[0]); + int ndim_do = sizeof(cells_do) / sizeof(cells_do[0]); struct gkyl_rect_grid grid_do; gkyl_rect_grid_init(&grid_do, ndim_do, lower_do, upper_do, cells_do); @@ -590,10 +609,10 @@ test_3x_to_scalar(int poly_order, bool use_gpu) // Project f(x,y,z) onto the donor basis. struct gkyl_array *fdo = mkarr(use_gpu, basis_do.num_basis, local_ext_do.volume); - struct gkyl_array *fdo_ho = use_gpu? mkarr(false, fdo->ncomp, fdo->size) - : gkyl_array_acquire(fdo); - gkyl_proj_on_basis *proj_do = gkyl_proj_on_basis_new(&grid_do, &basis_do, - poly_order+1, 1, eval_f_3x, NULL); + struct gkyl_array *fdo_ho = use_gpu ? mkarr(false, fdo->ncomp, fdo->size) : + gkyl_array_acquire(fdo); + gkyl_proj_on_basis *proj_do = + gkyl_proj_on_basis_new(&grid_do, &basis_do, poly_order + 1, 1, eval_f_3x, NULL); gkyl_proj_on_basis_advance(proj_do, 0.0, &local_do, fdo_ho); gkyl_array_copy(fdo, fdo_ho); @@ -603,21 +622,21 @@ test_3x_to_scalar(int poly_order, bool use_gpu) gkyl_range_init(&local_tar, 1, lower_tar, upper_tar); struct gkyl_array *ftar = mkarr(use_gpu, 1, local_tar.volume); - struct gkyl_array *ftar_ho = use_gpu? mkarr(false, 1, 1) - : gkyl_array_acquire(ftar); + struct gkyl_array *ftar_ho = use_gpu ? mkarr(false, 1, 1) : gkyl_array_acquire(ftar); // Create the updater: evaluate in x (dir 0), y (dir 1), and z (dir 2). int eval_dirs[] = {0, 1, 2}; - int num_eval_dirs = sizeof(eval_dirs)/sizeof(eval_dirs[0]); - struct gkyl_dg_eval_at_coord_proj *up = gkyl_dg_eval_at_coord_proj_new( - basis_do.ndim, &basis_do, num_eval_dirs, eval_dirs, use_gpu); + int num_eval_dirs = sizeof(eval_dirs) / sizeof(eval_dirs[0]); + struct gkyl_dg_eval_at_coord_proj *up = + gkyl_dg_eval_at_coord_proj_new(basis_do.ndim, &basis_do, num_eval_dirs, eval_dirs, use_gpu); // Apply updater at (x0, y0, z0). double eval_coords[] = {x0, y0, z0}; bool pick_lower[] = {false, false, false}; int known_index[] = {-1, -1, -1}; - gkyl_dg_eval_at_coord_proj_advance(up, eval_coords, &grid_do, pick_lower, known_index, - &local_do, &local_tar, fdo, ftar); + gkyl_dg_eval_at_coord_proj_advance( + up, eval_coords, &grid_do, pick_lower, known_index, &local_do, &local_tar, fdo, ftar + ); // Reference: f(x0, y0, z0) / sqrt(2). double fref; @@ -637,100 +656,118 @@ test_3x_to_scalar(int poly_order, bool use_gpu) gkyl_array_release(ftar_ho); } -void test_dg_evproj_1x_to_scalar_p1_ho(void) { +void test_dg_evproj_1x_to_scalar_p1_ho(void) +{ test_1x_to_scalar(1, false); } -void test_dg_evproj_1x_to_scalar_p2_ho(void) { +void test_dg_evproj_1x_to_scalar_p2_ho(void) +{ test_1x_to_scalar(2, false); } -void test_dg_evproj_2x_to_1x_p1_ho(void) { +void test_dg_evproj_2x_to_1x_p1_ho(void) +{ test_2x_to_1x(1, false); } -void test_dg_evproj_2x_to_1x_p2_ho(void) { +void test_dg_evproj_2x_to_1x_p2_ho(void) +{ test_2x_to_1x(2, false); } -void test_dg_evproj_2x_to_scalar_p1_ho(void) { +void test_dg_evproj_2x_to_scalar_p1_ho(void) +{ test_2x_to_scalar(1, false); } -void test_dg_evproj_2x_to_scalar_p2_ho(void) { +void test_dg_evproj_2x_to_scalar_p2_ho(void) +{ test_2x_to_scalar(2, false); } -void test_dg_evproj_3x_to_2x_p1_ho(void) { +void test_dg_evproj_3x_to_2x_p1_ho(void) +{ test_3x_to_2x(1, false); } -void test_dg_evproj_3x_to_1x_p1_ho(void) { +void test_dg_evproj_3x_to_1x_p1_ho(void) +{ test_3x_to_1x(1, false); } -void test_dg_evproj_3x_to_scalar_p1_ho(void) { +void test_dg_evproj_3x_to_scalar_p1_ho(void) +{ test_3x_to_scalar(1, false); } #ifdef GKYL_HAVE_CUDA -void test_dg_evproj_1x_to_scalar_p1_dev(void) { +void test_dg_evproj_1x_to_scalar_p1_dev(void) +{ test_1x_to_scalar(1, true); } -void test_dg_evproj_1x_to_scalar_p2_dev(void) { +void test_dg_evproj_1x_to_scalar_p2_dev(void) +{ test_1x_to_scalar(2, true); } -void test_dg_evproj_2x_to_1x_p1_dev(void) { +void test_dg_evproj_2x_to_1x_p1_dev(void) +{ test_2x_to_1x(1, true); } -void test_dg_evproj_2x_to_1x_p2_dev(void) { +void test_dg_evproj_2x_to_1x_p2_dev(void) +{ test_2x_to_1x(2, true); } -void test_dg_evproj_2x_to_scalar_p1_dev(void) { +void test_dg_evproj_2x_to_scalar_p1_dev(void) +{ test_2x_to_scalar(1, true); } -void test_dg_evproj_2x_to_scalar_p2_dev(void) { +void test_dg_evproj_2x_to_scalar_p2_dev(void) +{ test_2x_to_scalar(2, true); } -void test_dg_evproj_3x_to_2x_p1_dev(void) { +void test_dg_evproj_3x_to_2x_p1_dev(void) +{ test_3x_to_2x(1, true); } -void test_dg_evproj_3x_to_1x_p1_dev(void) { +void test_dg_evproj_3x_to_1x_p1_dev(void) +{ test_3x_to_1x(1, true); } -void test_dg_evproj_3x_to_scalar_p1_dev(void) { +void test_dg_evproj_3x_to_scalar_p1_dev(void) +{ test_3x_to_scalar(1, true); } #endif TEST_LIST = { - { "test_dg_evproj_1x_to_scalar_p1_ho", test_dg_evproj_1x_to_scalar_p1_ho }, - { "test_dg_evproj_1x_to_scalar_p2_ho", test_dg_evproj_1x_to_scalar_p2_ho }, - { "test_dg_evproj_2x_to_1x_p1_ho", test_dg_evproj_2x_to_1x_p1_ho }, - { "test_dg_evproj_2x_to_1x_p2_ho", test_dg_evproj_2x_to_1x_p2_ho }, - { "test_dg_evproj_2x_to_scalar_p1_ho", test_dg_evproj_2x_to_scalar_p1_ho }, - { "test_dg_evproj_2x_to_scalar_p2_ho", test_dg_evproj_2x_to_scalar_p2_ho }, - { "test_dg_evproj_3x_to_2x_p1_ho", test_dg_evproj_3x_to_2x_p1_ho }, - { "test_dg_evproj_3x_to_1x_p1_ho", test_dg_evproj_3x_to_1x_p1_ho }, - { "test_dg_evproj_3x_to_scalar_p1_ho", test_dg_evproj_3x_to_scalar_p1_ho }, + {"test_dg_evproj_1x_to_scalar_p1_ho", test_dg_evproj_1x_to_scalar_p1_ho}, + {"test_dg_evproj_1x_to_scalar_p2_ho", test_dg_evproj_1x_to_scalar_p2_ho}, + {"test_dg_evproj_2x_to_1x_p1_ho", test_dg_evproj_2x_to_1x_p1_ho}, + {"test_dg_evproj_2x_to_1x_p2_ho", test_dg_evproj_2x_to_1x_p2_ho}, + {"test_dg_evproj_2x_to_scalar_p1_ho", test_dg_evproj_2x_to_scalar_p1_ho}, + {"test_dg_evproj_2x_to_scalar_p2_ho", test_dg_evproj_2x_to_scalar_p2_ho}, + {"test_dg_evproj_3x_to_2x_p1_ho", test_dg_evproj_3x_to_2x_p1_ho}, + {"test_dg_evproj_3x_to_1x_p1_ho", test_dg_evproj_3x_to_1x_p1_ho}, + {"test_dg_evproj_3x_to_scalar_p1_ho", test_dg_evproj_3x_to_scalar_p1_ho}, #ifdef GKYL_HAVE_CUDA - { "test_dg_evproj_1x_to_scalar_p1_dev", test_dg_evproj_1x_to_scalar_p1_dev }, - { "test_dg_evproj_1x_to_scalar_p2_dev", test_dg_evproj_1x_to_scalar_p2_dev }, - { "test_dg_evproj_2x_to_1x_p1_dev", test_dg_evproj_2x_to_1x_p1_dev }, - { "test_dg_evproj_2x_to_1x_p2_dev", test_dg_evproj_2x_to_1x_p2_dev }, - { "test_dg_evproj_2x_to_scalar_p1_dev", test_dg_evproj_2x_to_scalar_p1_dev }, - { "test_dg_evproj_2x_to_scalar_p2_dev", test_dg_evproj_2x_to_scalar_p2_dev }, - { "test_dg_evproj_3x_to_2x_p1_dev", test_dg_evproj_3x_to_2x_p1_dev }, - { "test_dg_evproj_3x_to_1x_p1_dev", test_dg_evproj_3x_to_1x_p1_dev }, - { "test_dg_evproj_3x_to_scalar_p1_dev", test_dg_evproj_3x_to_scalar_p1_dev }, + {"test_dg_evproj_1x_to_scalar_p1_dev", test_dg_evproj_1x_to_scalar_p1_dev}, + {"test_dg_evproj_1x_to_scalar_p2_dev", test_dg_evproj_1x_to_scalar_p2_dev}, + {"test_dg_evproj_2x_to_1x_p1_dev", test_dg_evproj_2x_to_1x_p1_dev}, + {"test_dg_evproj_2x_to_1x_p2_dev", test_dg_evproj_2x_to_1x_p2_dev}, + {"test_dg_evproj_2x_to_scalar_p1_dev", test_dg_evproj_2x_to_scalar_p1_dev}, + {"test_dg_evproj_2x_to_scalar_p2_dev", test_dg_evproj_2x_to_scalar_p2_dev}, + {"test_dg_evproj_3x_to_2x_p1_dev", test_dg_evproj_3x_to_2x_p1_dev}, + {"test_dg_evproj_3x_to_1x_p1_dev", test_dg_evproj_3x_to_1x_p1_dev}, + {"test_dg_evproj_3x_to_scalar_p1_dev", test_dg_evproj_3x_to_scalar_p1_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/core/unit/ctest_dual_num.c b/core/unit/ctest_dual_num.c index 547e471690..9c3455d9b9 100644 --- a/core/unit/ctest_dual_num.c +++ b/core/unit/ctest_dual_num.c @@ -5,46 +5,38 @@ #include #include -static inline bool -cmp_dn(struct gkyl_dn x, struct gkyl_dn xcmp) +static inline bool cmp_dn(struct gkyl_dn x, struct gkyl_dn xcmp) { return (x.x[0] == xcmp.x[0]) && (x.x[1] == xcmp.x[1]); } -static inline bool -cmp_dn2(struct gkyl_dn2 x, struct gkyl_dn2 xcmp) +static inline bool cmp_dn2(struct gkyl_dn2 x, struct gkyl_dn2 xcmp) { return (x.x[0] == xcmp.x[0]) && (x.x[1] == xcmp.x[1]) && (x.x[2] == xcmp.x[2]); } -static void -show_dn(FILE *fp, const char *msg, struct gkyl_dn d1) +static void show_dn(FILE *fp, const char *msg, struct gkyl_dn d1) { fprintf(fp, "%s: [%lg, %lg]\n", msg, d1.x[0], d1.x[1]); } -static inline -struct gkyl_dn -func_1(struct gkyl_dn x) +static inline struct gkyl_dn func_1(struct gkyl_dn x) { // -2*x + x^2/(3+x^3) + 1/x return gdn_add( - gdn_smul(-2.0, x), - gdn_add( - gdn_div(gdn_sq(x), gdn_sadd(3, gdn_cube(x))), - gdn_inv(x) - ) + gdn_smul(-2.0, x), gdn_add(gdn_div(gdn_sq(x), gdn_sadd(3, gdn_cube(x))), gdn_inv(x)) ); } double func_1_0(double x) { - return -2*x+x*x/(3+x*x*x) + 1/x; + return -2 * x + x * x / (3 + x * x * x) + 1 / x; } double func_1_1(double x) { - return 2*x/(3+x*x*x) - 3*x*x*x*x/((3+x*x*x)*(3+x*x*x)) - 1/(x*x) - 2; + return 2 * x / (3 + x * x * x) - 3 * x * x * x * x / ((3 + x * x * x) * (3 + x * x * x)) - + 1 / (x * x) - 2; } void test_dual_num_basic_ho(void) @@ -52,37 +44,36 @@ void test_dual_num_basic_ho(void) double x10 = 2.5; struct gkyl_dn x1 = gdn_new1(x10); - struct gkyl_dn res = { }; + struct gkyl_dn res = {}; res = gdn_sq(x1); - TEST_CHECK( cmp_dn(res, gdn_new(x10*x10, 2*x10)) ); + TEST_CHECK(cmp_dn(res, gdn_new(x10 * x10, 2 * x10))); res = gdn_cube(x1); - TEST_CHECK( cmp_dn(res, gdn_new(x10*x10*x10, 3*x10*x10)) ); + TEST_CHECK(cmp_dn(res, gdn_new(x10 * x10 * x10, 3 * x10 * x10))); res = gdn_npow(x1, 5); - TEST_CHECK( cmp_dn(res, gdn_new(pow(x10,5), 5*pow(x10,4))) ); + TEST_CHECK(cmp_dn(res, gdn_new(pow(x10, 5), 5 * pow(x10, 4)))); res = gdn_sqrt(x1); - TEST_CHECK( cmp_dn(res, gdn_new(sqrt(x10), 0.5/sqrt(x10))) ); + TEST_CHECK(cmp_dn(res, gdn_new(sqrt(x10), 0.5 / sqrt(x10)))); res = gdn_cos(x1); - TEST_CHECK( cmp_dn(res, gdn_new(cos(x10), -sin(x10))) ); + TEST_CHECK(cmp_dn(res, gdn_new(cos(x10), -sin(x10)))); res = gdn_sin(x1); - TEST_CHECK( cmp_dn(res, gdn_new(sin(x10), cos(x10))) ); + TEST_CHECK(cmp_dn(res, gdn_new(sin(x10), cos(x10)))); res = gdn_tan(x1); - TEST_CHECK( res.x[0] == tan(x10) ); - TEST_CHECK( gkyl_compare_double(res.x[1], 1/(cos(x10)*cos(x10)), 1e-15) ); + TEST_CHECK(res.x[0] == tan(x10)); + TEST_CHECK(gkyl_compare_double(res.x[1], 1 / (cos(x10) * cos(x10)), 1e-15)); res = gdn_log(x1); - TEST_CHECK( res.x[0] == log(x10) ); - TEST_CHECK( gkyl_compare_double(res.x[1], 1/x10, 1e-15) ); + TEST_CHECK(res.x[0] == log(x10)); + TEST_CHECK(gkyl_compare_double(res.x[1], 1 / x10, 1e-15)); res = func_1(x1); - TEST_CHECK( cmp_dn(res, gdn_new(func_1_0(x10), func_1_1(x10))) ); - + TEST_CHECK(cmp_dn(res, gdn_new(func_1_0(x10), func_1_1(x10)))); } void test_dual_num_basic2_ho(void) @@ -90,130 +81,123 @@ void test_dual_num_basic2_ho(void) double x10 = 2.5; struct gkyl_dn2 x1 = gdn2_new(x10, 1.0, 2.0); - struct gkyl_dn2 res = { }; + struct gkyl_dn2 res = {}; res = gdn2_sq(x1); - TEST_CHECK( cmp_dn2(res, gdn2_new(x10*x10, 2*x10, 2.0*2*x10)) ); + TEST_CHECK(cmp_dn2(res, gdn2_new(x10 * x10, 2 * x10, 2.0 * 2 * x10))); res = gdn2_cube(x1); - TEST_CHECK( cmp_dn2(res, gdn2_new(x10*x10*x10, 3*x10*x10, 2.0*3*x10*x10)) ); + TEST_CHECK(cmp_dn2(res, gdn2_new(x10 * x10 * x10, 3 * x10 * x10, 2.0 * 3 * x10 * x10))); res = gdn2_npow(x1, 5); - TEST_CHECK( cmp_dn2(res, gdn2_new(pow(x10,5), 5*pow(x10,4), 2.0*5*pow(x10,4))) ); + TEST_CHECK(cmp_dn2(res, gdn2_new(pow(x10, 5), 5 * pow(x10, 4), 2.0 * 5 * pow(x10, 4)))); res = gdn2_sqrt(x1); - TEST_CHECK( cmp_dn2(res, gdn2_new(sqrt(x10), 0.5/sqrt(x10), 2.0*0.5/sqrt(x10))) ); + TEST_CHECK(cmp_dn2(res, gdn2_new(sqrt(x10), 0.5 / sqrt(x10), 2.0 * 0.5 / sqrt(x10)))); res = gdn2_cos(x1); - TEST_CHECK( cmp_dn2(res, gdn2_new(cos(x10), -sin(x10), -2.0*sin(x10))) ); + TEST_CHECK(cmp_dn2(res, gdn2_new(cos(x10), -sin(x10), -2.0 * sin(x10)))); res = gdn2_sin(x1); - TEST_CHECK( cmp_dn2(res, gdn2_new(sin(x10), cos(x10), 2.0*cos(x10))) ); + TEST_CHECK(cmp_dn2(res, gdn2_new(sin(x10), cos(x10), 2.0 * cos(x10)))); res = gdn2_log(x1); - TEST_CHECK( cmp_dn2(res, gdn2_new(log(x10), 1/x10, 2.0/x10)) ); + TEST_CHECK(cmp_dn2(res, gdn2_new(log(x10), 1 / x10, 2.0 / x10))); res = gdn2_tan(x1); - TEST_CHECK( res.x[0] == tan(x10) ); - TEST_CHECK( gkyl_compare_double(res.x[1], 1/(cos(x10)*cos(x10)), 1e-15) ); - TEST_CHECK( gkyl_compare_double(res.x[2], 2.0/(cos(x10)*cos(x10)), 1e-15) ); + TEST_CHECK(res.x[0] == tan(x10)); + TEST_CHECK(gkyl_compare_double(res.x[1], 1 / (cos(x10) * cos(x10)), 1e-15)); + TEST_CHECK(gkyl_compare_double(res.x[2], 2.0 / (cos(x10) * cos(x10)), 1e-15)); } -static struct gkyl_dn2 -fxy( struct gkyl_dn2 x, struct gkyl_dn2 y) +static struct gkyl_dn2 fxy(struct gkyl_dn2 x, struct gkyl_dn2 y) { // cos(x/y) - return gdn2_cos( gdn2_div(x,y) ); + return gdn2_cos(gdn2_div(x, y)); } -static struct gkyl_dn2 -psixy( struct gkyl_dn2 x, struct gkyl_dn2 y) +static struct gkyl_dn2 psixy(struct gkyl_dn2 x, struct gkyl_dn2 y) { // sqrt(x^2 + y^2) - return gdn2_sqrt( gdn2_add(gdn2_sq(x), gdn2_sq(y)) ); + return gdn2_sqrt(gdn2_add(gdn2_sq(x), gdn2_sq(y))); } -static struct gkyl_dn2 -custom_xy( struct gkyl_dn2 x, struct gkyl_dn2 y) +static struct gkyl_dn2 custom_xy(struct gkyl_dn2 x, struct gkyl_dn2 y) { // example of custom function of x,y with hand-computed gradient - - double g0 = (x.x[0]*x.x[0])/(y.x[0]*y.x[0]); - double g0x = 2.0*x.x[0]/(y.x[0]*y.x[0]); - double g0y = -2.0*(x.x[0]*x.x[0])/(y.x[0]*y.x[0]*y.x[0]); - - return (struct gkyl_dn2) { - g0, - x.x[1]*g0x + y.x[1]*g0y, - x.x[2]*g0x + y.x[2]*g0y - }; + + double g0 = (x.x[0] * x.x[0]) / (y.x[0] * y.x[0]); + double g0x = 2.0 * x.x[0] / (y.x[0] * y.x[0]); + double g0y = -2.0 * (x.x[0] * x.x[0]) / (y.x[0] * y.x[0] * y.x[0]); + + return (struct gkyl_dn2){g0, x.x[1] * g0x + y.x[1] * g0y, x.x[2] * g0x + y.x[2] * g0y}; } void test_dual_num_xy_ho(void) { struct gkyl_dn2 x = gdn2_new10(2.5), y = gdn2_new01(1.5); - struct gkyl_dn2 res = { }; + struct gkyl_dn2 res = {}; res = fxy(x, y); - TEST_CHECK( gkyl_compare_double(res.x[0], cos(x.x[0]/y.x[0]), 1e-14) ); - TEST_CHECK( gkyl_compare_double(res.x[1], -sin(x.x[0]/y.x[0])/y.x[0], 1e-14) ); - TEST_CHECK( gkyl_compare_double(res.x[2], x.x[0]*sin(x.x[0]/y.x[0])/(y.x[0]*y.x[0]), 1e-14) ); + TEST_CHECK(gkyl_compare_double(res.x[0], cos(x.x[0] / y.x[0]), 1e-14)); + TEST_CHECK(gkyl_compare_double(res.x[1], -sin(x.x[0] / y.x[0]) / y.x[0], 1e-14)); + TEST_CHECK(gkyl_compare_double(res.x[2], x.x[0] * sin(x.x[0] / y.x[0]) / (y.x[0] * y.x[0]), 1e-14) + ); - double psi0 = sqrt(x.x[0]*x.x[0] + y.x[0]*y.x[0]); + double psi0 = sqrt(x.x[0] * x.x[0] + y.x[0] * y.x[0]); res = psixy(x, y); - TEST_CHECK( gkyl_compare_double(res.x[0], psi0, 1e-14) ); - TEST_CHECK( gkyl_compare_double(res.x[1], x.x[0]/psi0, 1e-14) ); - TEST_CHECK( gkyl_compare_double(res.x[2], y.x[0]/psi0, 1e-14) ); - - res = gdn2_cos( custom_xy(x, y) ); // cos of custom defined function - - double cus0 = cos(x.x[0]*x.x[0]/(y.x[0]*y.x[0])); - double cusx = -2.0*x.x[0]*sin(x.x[0]*x.x[0]/(y.x[0]*y.x[0]))/(y.x[0]*y.x[0]); - double cusy = 2.0*x.x[0]*x.x[0]*sin(x.x[0]*x.x[0]/(y.x[0]*y.x[0]))/(y.x[0]*y.x[0]*y.x[0]); - TEST_CHECK( gkyl_compare_double(res.x[0], cus0, 1e-14) ); - TEST_CHECK( gkyl_compare_double(res.x[1], cusx, 1e-14) ); - TEST_CHECK( gkyl_compare_double(res.x[2], cusy, 1e-14) ); + TEST_CHECK(gkyl_compare_double(res.x[0], psi0, 1e-14)); + TEST_CHECK(gkyl_compare_double(res.x[1], x.x[0] / psi0, 1e-14)); + TEST_CHECK(gkyl_compare_double(res.x[2], y.x[0] / psi0, 1e-14)); + + res = gdn2_cos(custom_xy(x, y)); // cos of custom defined function + + double cus0 = cos(x.x[0] * x.x[0] / (y.x[0] * y.x[0])); + double cusx = -2.0 * x.x[0] * sin(x.x[0] * x.x[0] / (y.x[0] * y.x[0])) / (y.x[0] * y.x[0]); + double cusy = + 2.0 * x.x[0] * x.x[0] * sin(x.x[0] * x.x[0] / (y.x[0] * y.x[0])) / (y.x[0] * y.x[0] * y.x[0]); + TEST_CHECK(gkyl_compare_double(res.x[0], cus0, 1e-14)); + TEST_CHECK(gkyl_compare_double(res.x[1], cusx, 1e-14)); + TEST_CHECK(gkyl_compare_double(res.x[2], cusy, 1e-14)); } // for testing 1D mapc2p determine by its inverse mapping -struct inv_map_ctx { double s0; }; +struct inv_map_ctx { + double s0; +}; -static inline struct gkyl_dn -gdn_inv_mapc2p(struct gkyl_dn x, void *ctx) +static inline struct gkyl_dn gdn_inv_mapc2p(struct gkyl_dn x, void *ctx) { struct inv_map_ctx *imctx = ctx; double s0 = imctx->s0; // sqrt(x+4) - 2 - s0 - return gdn_sadd(-2.0-s0, gdn_sqrt(gdn_sadd(4.0, x))); + return gdn_sadd(-2.0 - s0, gdn_sqrt(gdn_sadd(4.0, x))); } -static inline double -inv_mapc2p(double x, void *ctx) +static inline double inv_mapc2p(double x, void *ctx) { - return gdn_inv_mapc2p(gdn_new0(x),ctx).x[0]; + return gdn_inv_mapc2p(gdn_new0(x), ctx).x[0]; } void test_dual_num_inv_mapc2p_ho(void) { - struct inv_map_ctx imctx = { 0.75 }; + struct inv_map_ctx imctx = {0.75}; double xl = 0.0, xr = 5.0; double fl = inv_mapc2p(xl, &imctx); double fr = inv_mapc2p(xr, &imctx); - struct gkyl_qr_res root = - gkyl_ridders(inv_mapc2p, &imctx, xl, xr, fl, fr, 100, 1e-10); + struct gkyl_qr_res root = gkyl_ridders(inv_mapc2p, &imctx, xl, xr, fl, fr, 100, 1e-10); // compute derivative at the root struct gkyl_dn res = gdn_inv_mapc2p(gdn_new1(root.res), &imctx); // at this point 1/res.x[1] is the derivative of the mapping wrt s // at the root - - TEST_CHECK( gkyl_compare_double(root.res, 3.5625, 1e-14) ); - TEST_CHECK( gkyl_compare_double(1/res.x[1], 5.5, 1e-14) ); + + TEST_CHECK(gkyl_compare_double(root.res, 3.5625, 1e-14)); + TEST_CHECK(gkyl_compare_double(1 / res.x[1], 5.5, 1e-14)); } -static void -mapc2p(const struct gkyl_dn xc[2], struct gkyl_dn xp[2]) +static void mapc2p(const struct gkyl_dn xc[2], struct gkyl_dn xp[2]) { // mapping from r,theta -> x,y xp[0] = gdn_mul(xc[0], gdn_cos(xc[1])); @@ -222,32 +206,33 @@ mapc2p(const struct gkyl_dn xc[2], struct gkyl_dn xp[2]) void test_dual_num_mapc2p_ho(void) { - double r = 1.5, theta = M_PI/3; + double r = 1.5, theta = M_PI / 3; struct gkyl_dn xc[2], xp[2]; // compute gradient wrt r (notice new0 used for theta) - xc[0] = gdn_new1(r); xc[1] = gdn_new0(theta); + xc[0] = gdn_new1(r); + xc[1] = gdn_new0(theta); mapc2p(xc, xp); - TEST_CHECK( xp[0].x[0] == r*cos(theta) ); - TEST_CHECK( xp[1].x[0] == r*sin(theta) ); + TEST_CHECK(xp[0].x[0] == r * cos(theta)); + TEST_CHECK(xp[1].x[0] == r * sin(theta)); - TEST_CHECK( xp[0].x[1] == cos(theta) ); - TEST_CHECK( xp[1].x[1] == sin(theta) ); + TEST_CHECK(xp[0].x[1] == cos(theta)); + TEST_CHECK(xp[1].x[1] == sin(theta)); // compute gradient wrt theta (notice new0 used for r) - xc[0] = gdn_new0(r); xc[1] = gdn_new1(theta); + xc[0] = gdn_new0(r); + xc[1] = gdn_new1(theta); mapc2p(xc, xp); - TEST_CHECK( xp[0].x[0] == r*cos(theta) ); - TEST_CHECK( xp[1].x[0] == r*sin(theta) ); + TEST_CHECK(xp[0].x[0] == r * cos(theta)); + TEST_CHECK(xp[1].x[0] == r * sin(theta)); - TEST_CHECK( xp[0].x[1] == -r*sin(theta) ); - TEST_CHECK( xp[1].x[1] == r*cos(theta) ); + TEST_CHECK(xp[0].x[1] == -r * sin(theta)); + TEST_CHECK(xp[1].x[1] == r * cos(theta)); } -static void -mapc2p_2(const struct gkyl_dn2 xc[2], struct gkyl_dn2 xp[2]) +static void mapc2p_2(const struct gkyl_dn2 xc[2], struct gkyl_dn2 xp[2]) { // mapping from r,theta -> x,y xp[0] = gdn2_mul(xc[0], gdn2_cos(xc[1])); @@ -256,27 +241,29 @@ mapc2p_2(const struct gkyl_dn2 xc[2], struct gkyl_dn2 xp[2]) void test_dual_num_mapc2p_2_ho(void) { - double r = 1.5, theta = M_PI/3; + double r = 1.5, theta = M_PI / 3; struct gkyl_dn2 xc[2], xp[2]; // compute function and gradients - xc[0] = gdn2_new10(r); xc[1] = gdn2_new01(theta); + xc[0] = gdn2_new10(r); + xc[1] = gdn2_new01(theta); mapc2p_2(xc, xp); - TEST_CHECK( xp[0].x[0] == r*cos(theta) ); - TEST_CHECK( xp[0].x[1] == cos(theta) ); - TEST_CHECK( xp[0].x[2] == -r*sin(theta) ); + TEST_CHECK(xp[0].x[0] == r * cos(theta)); + TEST_CHECK(xp[0].x[1] == cos(theta)); + TEST_CHECK(xp[0].x[2] == -r * sin(theta)); - TEST_CHECK( xp[1].x[0] == r*sin(theta) ); - TEST_CHECK( xp[1].x[1] == sin(theta) ); - TEST_CHECK( xp[1].x[2] == r*cos(theta) ); + TEST_CHECK(xp[1].x[0] == r * sin(theta)); + TEST_CHECK(xp[1].x[1] == sin(theta)); + TEST_CHECK(xp[1].x[2] == r * cos(theta)); } +static inline double sq(double x) +{ + return x * x; +} -static inline double sq(double x) { return x * x; } - -static inline struct gkyl_dn2 -RpsiZ_ellip(const struct gkyl_dn2 psiZ[2]) +static inline struct gkyl_dn2 RpsiZ_ellip(const struct gkyl_dn2 psiZ[2]) { // psi*sin(Z) return gdn2_mul(psiZ[0], gdn2_sin(psiZ[1])); @@ -289,25 +276,24 @@ RpsiZ_ellip(const struct gkyl_dn2 psiZ[2]) /* double dRdZ = RpsiZ.x[2]; */ /* } */ -void -test_dual_num_psi_mapping_ho(void) +void test_dual_num_psi_mapping_ho(void) { - double pz[2] = { 1.0, 2.0 }; - struct gkyl_dn2 psiZ[2] = { gdn2_new10(pz[0]), gdn2_new01(pz[1]) }; + double pz[2] = {1.0, 2.0}; + struct gkyl_dn2 psiZ[2] = {gdn2_new10(pz[0]), gdn2_new01(pz[1])}; struct gkyl_dn2 RpsiZ = RpsiZ_ellip(psiZ); - TEST_CHECK( RpsiZ.x[0] == pz[0]*sin(pz[1]) ); - TEST_CHECK( RpsiZ.x[1] == sin(pz[1]) ); // dR/dpsi - TEST_CHECK( RpsiZ.x[2] == pz[0]*cos(pz[1]) ); // dR/dZ + TEST_CHECK(RpsiZ.x[0] == pz[0] * sin(pz[1])); + TEST_CHECK(RpsiZ.x[1] == sin(pz[1])); // dR/dpsi + TEST_CHECK(RpsiZ.x[2] == pz[0] * cos(pz[1])); // dR/dZ } TEST_LIST = { - { "test_dual_num_basic_ho", test_dual_num_basic_ho }, - { "test_dual_num_basic2_ho", test_dual_num_basic2_ho }, - { "test_dual_num_xy_ho", test_dual_num_xy_ho }, - { "test_dual_num_inv_mapc2p_ho", test_dual_num_inv_mapc2p_ho }, - { "test_dual_num_mapc2p_ho", test_dual_num_mapc2p_ho }, - { "test_dual_num_mapc2p_2_ho", test_dual_num_mapc2p_2_ho }, - { "test_dual_num_psi_mapping_ho", test_dual_num_psi_mapping_ho }, - { NULL, NULL }, + {"test_dual_num_basic_ho", test_dual_num_basic_ho}, + {"test_dual_num_basic2_ho", test_dual_num_basic2_ho}, + {"test_dual_num_xy_ho", test_dual_num_xy_ho}, + {"test_dual_num_inv_mapc2p_ho", test_dual_num_inv_mapc2p_ho}, + {"test_dual_num_mapc2p_ho", test_dual_num_mapc2p_ho}, + {"test_dual_num_mapc2p_2_ho", test_dual_num_mapc2p_2_ho}, + {"test_dual_num_psi_mapping_ho", test_dual_num_psi_mapping_ho}, + {NULL, NULL} }; diff --git a/core/unit/ctest_dynvec.c b/core/unit/ctest_dynvec.c index ef2e22577c..b7b642996d 100644 --- a/core/unit/ctest_dynvec.c +++ b/core/unit/ctest_dynvec.c @@ -4,330 +4,329 @@ #include -void -test_dynvec_1_ho() +void test_dynvec_1_ho() { gkyl_dynvec dv = gkyl_dynvec_new(GKYL_DOUBLE, 3); - TEST_CHECK( gkyl_dynvec_elem_type(dv) == GKYL_DOUBLE ); - TEST_CHECK( gkyl_dynvec_ncomp(dv) == 3 ); + TEST_CHECK(gkyl_dynvec_elem_type(dv) == GKYL_DOUBLE); + TEST_CHECK(gkyl_dynvec_ncomp(dv) == 3); double out[3]; - TEST_CHECK( gkyl_dynvec_size(dv) == 0 ); - TEST_CHECK( gkyl_dynvec_getlast(dv, out) == false ); + TEST_CHECK(gkyl_dynvec_size(dv) == 0); + TEST_CHECK(gkyl_dynvec_getlast(dv, out) == false); // add some data - for (int i=0; i<2000; ++i) - gkyl_dynvec_append(dv, 0.1*i, (double[3]) { i, i+1, i+2 } ); - TEST_CHECK( gkyl_dynvec_size(dv) == 2000 ); + for (int i = 0; i < 2000; ++i) { + gkyl_dynvec_append(dv, 0.1 * i, (double[3]){i, i + 1, i + 2}); + } + TEST_CHECK(gkyl_dynvec_size(dv) == 2000); - TEST_CHECK( gkyl_dynvec_getlast_tm(dv) == 1999*0.1 ); - TEST_CHECK( gkyl_dynvec_getlast(dv, out) == true ); - TEST_CHECK( out[0] == 1999 ); - TEST_CHECK( out[1] == 2000 ); - TEST_CHECK( out[2] == 2001 ); + TEST_CHECK(gkyl_dynvec_getlast_tm(dv) == 1999 * 0.1); + TEST_CHECK(gkyl_dynvec_getlast(dv, out) == true); + TEST_CHECK(out[0] == 1999); + TEST_CHECK(out[1] == 2000); + TEST_CHECK(out[2] == 2001); - for (int i=0; i<2000; ++i) { + for (int i = 0; i < 2000; ++i) { double d[3]; - TEST_CHECK( gkyl_dynvec_get(dv, i, d) == true ); - TEST_CHECK( d[0] == i ); - TEST_CHECK( d[1] == i+1 ); - TEST_CHECK( d[2] == i+2 ); + TEST_CHECK(gkyl_dynvec_get(dv, i, d) == true); + TEST_CHECK(d[0] == i); + TEST_CHECK(d[1] == i + 1); + TEST_CHECK(d[2] == i + 2); - TEST_CHECK( gkyl_dynvec_get_tm(dv, i) == i*0.1 ); + TEST_CHECK(gkyl_dynvec_get_tm(dv, i) == i * 0.1); } - TEST_CHECK( gkyl_dynvec_capacity(dv) > 2000 ); - TEST_CHECK( gkyl_dynvec_capacity(dv) < 5000 ); + TEST_CHECK(gkyl_dynvec_capacity(dv) > 2000); + TEST_CHECK(gkyl_dynvec_capacity(dv) < 5000); gkyl_dynvec_reserve_more(dv, 5000); - TEST_CHECK( gkyl_dynvec_capacity(dv) > 2000+5000 ); - - for (int i=0; i<2000; ++i) { + TEST_CHECK(gkyl_dynvec_capacity(dv) > 2000 + 5000); + + for (int i = 0; i < 2000; ++i) { double d[3]; - TEST_CHECK( gkyl_dynvec_get(dv, i, d) == true ); - TEST_CHECK( d[0] == i ); - TEST_CHECK( d[1] == i+1 ); - TEST_CHECK( d[2] == i+2 ); + TEST_CHECK(gkyl_dynvec_get(dv, i, d) == true); + TEST_CHECK(d[0] == i); + TEST_CHECK(d[1] == i + 1); + TEST_CHECK(d[2] == i + 2); - TEST_CHECK( gkyl_dynvec_get_tm(dv, i) == i*0.1 ); - } + TEST_CHECK(gkyl_dynvec_get_tm(dv, i) == i * 0.1); + } gkyl_dynvec_clear(dv); - TEST_CHECK( gkyl_dynvec_size(dv) == 0 ); - TEST_CHECK( gkyl_dynvec_getlast(dv, out) == false ); + TEST_CHECK(gkyl_dynvec_size(dv) == 0); + TEST_CHECK(gkyl_dynvec_getlast(dv, out) == false); gkyl_dynvec dv2 = gkyl_dynvec_acquire(dv); - + gkyl_dynvec_release(dv); gkyl_dynvec_release(dv2); } -void -test_dynvec_2_ho() +void test_dynvec_2_ho() { // store user-defined struct - struct euler { double rho, rhou, rhov; }; + struct euler { + double rho, rhou, rhov; + }; gkyl_dynvec dv = gkyl_dynvec_new(GKYL_USER, sizeof(struct euler)); // add some data - for (int i=0; i<2000; ++i) - gkyl_dynvec_append(dv, 0.1*i, &(struct euler) { i, i+1, i+2 }); - - TEST_CHECK( gkyl_dynvec_size(dv) == 2000 ); + for (int i = 0; i < 2000; ++i) { + gkyl_dynvec_append(dv, 0.1 * i, &(struct euler){i, i + 1, i + 2}); + } - for (int i=0; i<2000; ++i) { + TEST_CHECK(gkyl_dynvec_size(dv) == 2000); + + for (int i = 0; i < 2000; ++i) { struct euler eu; - TEST_CHECK( gkyl_dynvec_get(dv, i, &eu) == true ); - TEST_CHECK( eu.rho == i ); - TEST_CHECK( eu.rhou == i+1 ); - TEST_CHECK( eu.rhov == i+2 ); + TEST_CHECK(gkyl_dynvec_get(dv, i, &eu) == true); + TEST_CHECK(eu.rho == i); + TEST_CHECK(eu.rhou == i + 1); + TEST_CHECK(eu.rhov == i + 2); - TEST_CHECK( gkyl_dynvec_get_tm(dv, i) == i*0.1 ); - } + TEST_CHECK(gkyl_dynvec_get_tm(dv, i) == i * 0.1); + } gkyl_dynvec_release(dv); } -void -test_dynvec_3_ho() +void test_dynvec_3_ho() { gkyl_dynvec dv = gkyl_dynvec_new(GKYL_DOUBLE, 3); double out[3]; - TEST_CHECK( gkyl_dynvec_size(dv) == 0 ); - TEST_CHECK( gkyl_dynvec_getlast(dv, out) == false ); + TEST_CHECK(gkyl_dynvec_size(dv) == 0); + TEST_CHECK(gkyl_dynvec_getlast(dv, out) == false); // add some data - for (int i=0; i<2000; ++i) - gkyl_dynvec_append(dv, 0.1*i, (double[3]) { i, i+1, i+2 } ); - - TEST_CHECK( gkyl_dynvec_size(dv) == 2000 ); - - TEST_CHECK( gkyl_dynvec_getlast_tm(dv) == 1999*0.1 ); - TEST_CHECK( gkyl_dynvec_getlast(dv, out) == true ); - TEST_CHECK( out[0] == 1999 ); - TEST_CHECK( out[1] == 2000 ); - TEST_CHECK( out[2] == 2001 ); - - for (int i=0; i<2000; ++i) { + for (int i = 0; i < 2000; ++i) { + gkyl_dynvec_append(dv, 0.1 * i, (double[3]){i, i + 1, i + 2}); + } + + TEST_CHECK(gkyl_dynvec_size(dv) == 2000); + + TEST_CHECK(gkyl_dynvec_getlast_tm(dv) == 1999 * 0.1); + TEST_CHECK(gkyl_dynvec_getlast(dv, out) == true); + TEST_CHECK(out[0] == 1999); + TEST_CHECK(out[1] == 2000); + TEST_CHECK(out[2] == 2001); + + for (int i = 0; i < 2000; ++i) { double d[3]; - TEST_CHECK( gkyl_dynvec_get(dv, i, d) == true ); - TEST_CHECK( d[0] == i ); - TEST_CHECK( d[1] == i+1 ); - TEST_CHECK( d[2] == i+2 ); + TEST_CHECK(gkyl_dynvec_get(dv, i, d) == true); + TEST_CHECK(d[0] == i); + TEST_CHECK(d[1] == i + 1); + TEST_CHECK(d[2] == i + 2); - TEST_CHECK( gkyl_dynvec_get_tm(dv, i) == i*0.1 ); + TEST_CHECK(gkyl_dynvec_get_tm(dv, i) == i * 0.1); } gkyl_dynvec_clear_all_but(dv, 3); - TEST_CHECK( gkyl_dynvec_size(dv) == 3 ); - - TEST_CHECK( gkyl_dynvec_getlast(dv, out) == true ); - TEST_CHECK( out[0] == 1999 ); - TEST_CHECK( out[1] == 2000 ); - TEST_CHECK( out[2] == 2001 ); - TEST_CHECK( gkyl_dynvec_getlast_tm(dv) == 1999*0.1 ); - - TEST_CHECK( gkyl_dynvec_get(dv, 0, out) == true ); - TEST_CHECK( out[0] == 2000-3 ); - TEST_CHECK( out[1] == 2000-3+1 ); - TEST_CHECK( out[2] == 2000-3+2 ); - TEST_CHECK( gkyl_dynvec_get_tm(dv, 0) == (2000-3)*0.1 ); - - TEST_CHECK( gkyl_dynvec_get(dv, 1, out) == true ); - TEST_CHECK( out[0] == 2000-2 ); - TEST_CHECK( out[1] == 2000-2+1 ); - TEST_CHECK( out[2] == 2000-2+2 ); - TEST_CHECK( gkyl_dynvec_get_tm(dv, 1) == (2000-2)*0.1 ); - - TEST_CHECK( gkyl_dynvec_get(dv, 2, out) == true ); - TEST_CHECK( out[0] == 2000-1 ); - TEST_CHECK( out[1] == 2000-1+1 ); - TEST_CHECK( out[2] == 2000-1+2 ); - TEST_CHECK( gkyl_dynvec_get_tm(dv, 2) == (2000-1)*0.1 ); - + TEST_CHECK(gkyl_dynvec_size(dv) == 3); + + TEST_CHECK(gkyl_dynvec_getlast(dv, out) == true); + TEST_CHECK(out[0] == 1999); + TEST_CHECK(out[1] == 2000); + TEST_CHECK(out[2] == 2001); + TEST_CHECK(gkyl_dynvec_getlast_tm(dv) == 1999 * 0.1); + + TEST_CHECK(gkyl_dynvec_get(dv, 0, out) == true); + TEST_CHECK(out[0] == 2000 - 3); + TEST_CHECK(out[1] == 2000 - 3 + 1); + TEST_CHECK(out[2] == 2000 - 3 + 2); + TEST_CHECK(gkyl_dynvec_get_tm(dv, 0) == (2000 - 3) * 0.1); + + TEST_CHECK(gkyl_dynvec_get(dv, 1, out) == true); + TEST_CHECK(out[0] == 2000 - 2); + TEST_CHECK(out[1] == 2000 - 2 + 1); + TEST_CHECK(out[2] == 2000 - 2 + 2); + TEST_CHECK(gkyl_dynvec_get_tm(dv, 1) == (2000 - 2) * 0.1); + + TEST_CHECK(gkyl_dynvec_get(dv, 2, out) == true); + TEST_CHECK(out[0] == 2000 - 1); + TEST_CHECK(out[1] == 2000 - 1 + 1); + TEST_CHECK(out[2] == 2000 - 1 + 2); + TEST_CHECK(gkyl_dynvec_get_tm(dv, 2) == (2000 - 1) * 0.1); + gkyl_dynvec_release(dv); } -void -test_dynvec_4_ho() +void test_dynvec_4_ho() { gkyl_dynvec dv = gkyl_dynvec_new(GKYL_DOUBLE, 3); double out[3]; - TEST_CHECK( gkyl_dynvec_size(dv) == 0 ); - TEST_CHECK( gkyl_dynvec_getlast(dv, out) == false ); + TEST_CHECK(gkyl_dynvec_size(dv) == 0); + TEST_CHECK(gkyl_dynvec_getlast(dv, out) == false); gkyl_dynvec_clear_all_but(dv, 3); - TEST_CHECK( gkyl_dynvec_size(dv) == 0 ); - TEST_CHECK( gkyl_dynvec_getlast(dv, out) == false ); + TEST_CHECK(gkyl_dynvec_size(dv) == 0); + TEST_CHECK(gkyl_dynvec_getlast(dv, out) == false); // add some data - for (int i=0; i<20; ++i) - gkyl_dynvec_append(dv, 0.1*i, (double[3]) { i, i+1, i+2 } ); - - TEST_CHECK( gkyl_dynvec_size(dv) == 20 ); + for (int i = 0; i < 20; ++i) { + gkyl_dynvec_append(dv, 0.1 * i, (double[3]){i, i + 1, i + 2}); + } + + TEST_CHECK(gkyl_dynvec_size(dv) == 20); gkyl_dynvec_clear_all_but(dv, 30); // clearing more elements - TEST_CHECK( gkyl_dynvec_size(dv) == 20 ); + TEST_CHECK(gkyl_dynvec_size(dv) == 20); - TEST_CHECK( gkyl_dynvec_getlast_tm(dv) == 19*0.1 ); - TEST_CHECK( gkyl_dynvec_getlast(dv, out) == true ); - TEST_CHECK( out[0] == 19 ); - TEST_CHECK( out[1] == 20 ); - TEST_CHECK( out[2] == 21 ); + TEST_CHECK(gkyl_dynvec_getlast_tm(dv) == 19 * 0.1); + TEST_CHECK(gkyl_dynvec_getlast(dv, out) == true); + TEST_CHECK(out[0] == 19); + TEST_CHECK(out[1] == 20); + TEST_CHECK(out[2] == 21); - for (int i=0; i<20; ++i) { + for (int i = 0; i < 20; ++i) { double d[3]; - TEST_CHECK( gkyl_dynvec_get(dv, i, d) == true ); - TEST_CHECK( d[0] == i ); - TEST_CHECK( d[1] == i+1 ); - TEST_CHECK( d[2] == i+2 ); + TEST_CHECK(gkyl_dynvec_get(dv, i, d) == true); + TEST_CHECK(d[0] == i); + TEST_CHECK(d[1] == i + 1); + TEST_CHECK(d[2] == i + 2); - TEST_CHECK( gkyl_dynvec_get_tm(dv, i) == i*0.1 ); + TEST_CHECK(gkyl_dynvec_get_tm(dv, i) == i * 0.1); } - + gkyl_dynvec_release(dv); } -void -test_dynvec_io_ho() +void test_dynvec_io_ho() { gkyl_dynvec dv = gkyl_dynvec_new(GKYL_DOUBLE, 3); double out[3]; - for (int i=0; i<1000; ++i) { - out[0] = cos(0.1*i); - out[1] = sin(0.1*i); - out[2] = cos(0.1*i)*sin(0.1*i); - gkyl_dynvec_append(dv, i*0.1, out); + for (int i = 0; i < 1000; ++i) { + out[0] = cos(0.1 * i); + out[1] = sin(0.1 * i); + out[2] = cos(0.1 * i) * sin(0.1 * i); + gkyl_dynvec_append(dv, i * 0.1, out); } // write and clear gkyl_dynvec_write(dv, "ctest_dynvec_test_io_1.gkyl"); gkyl_dynvec_clear(dv); - struct gkyl_dynvec_etype_ncomp enc = { }; + struct gkyl_dynvec_etype_ncomp enc = {}; enc = gkyl_dynvec_read_ncomp("ctest_dynvec_test_io_1.gkyl"); - TEST_CHECK( enc.ncomp == 3 ); - TEST_CHECK( enc.type == GKYL_DOUBLE ); + TEST_CHECK(enc.ncomp == 3); + TEST_CHECK(enc.type == GKYL_DOUBLE); int file_type = gkyl_get_gkyl_file_type("ctest_dynvec_test_io_1.gkyl"); - TEST_CHECK( 2 == file_type ); - + TEST_CHECK(2 == file_type); + bool res = gkyl_dynvec_read(dv, "ctest_dynvec_test_io_1.gkyl"); - TEST_CHECK( res ); + TEST_CHECK(res); - TEST_CHECK( gkyl_dynvec_size(dv) == 1000 ); + TEST_CHECK(gkyl_dynvec_size(dv) == 1000); - for (int i=0; i<1000; ++i) { + for (int i = 0; i < 1000; ++i) { gkyl_dynvec_get(dv, i, out); - TEST_CHECK( out[0] == cos(0.1*i) ); - TEST_CHECK( out[1] == sin(0.1*i) ); - TEST_CHECK( out[2] == cos(0.1*i)*sin(0.1*i) ); + TEST_CHECK(out[0] == cos(0.1 * i)); + TEST_CHECK(out[1] == sin(0.1 * i)); + TEST_CHECK(out[2] == cos(0.1 * i) * sin(0.1 * i)); - TEST_CHECK( gkyl_dynvec_get_tm(dv, i) == i*0.1 ); + TEST_CHECK(gkyl_dynvec_get_tm(dv, i) == i * 0.1); } gkyl_dynvec_clear(dv); // add some elements before reading - for (int i=0; i<10; ++i) { - out[0] = 0.1*i; - out[1] = 0.2*i; - out[2] = 0.3*i; - gkyl_dynvec_append(dv, i*0.1, out); + for (int i = 0; i < 10; ++i) { + out[0] = 0.1 * i; + out[1] = 0.2 * i; + out[2] = 0.3 * i; + gkyl_dynvec_append(dv, i * 0.1, out); } - TEST_CHECK( gkyl_dynvec_size(dv) == 10 ); + TEST_CHECK(gkyl_dynvec_size(dv) == 10); res = gkyl_dynvec_read(dv, "ctest_dynvec_test_io_1.gkyl"); - TEST_CHECK( res ); + TEST_CHECK(res); - for (int i=0; i<10; ++i) { + for (int i = 0; i < 10; ++i) { gkyl_dynvec_get(dv, i, out); - TEST_CHECK( out[0] == 0.1*i ); - TEST_CHECK( out[1] == 0.2*i ); - TEST_CHECK( out[2] == 0.3*i ); + TEST_CHECK(out[0] == 0.1 * i); + TEST_CHECK(out[1] == 0.2 * i); + TEST_CHECK(out[2] == 0.3 * i); - TEST_CHECK( gkyl_dynvec_get_tm(dv, i) == i*0.1 ); + TEST_CHECK(gkyl_dynvec_get_tm(dv, i) == i * 0.1); } - TEST_CHECK( gkyl_dynvec_size(dv) == 10+1000 ); + TEST_CHECK(gkyl_dynvec_size(dv) == 10 + 1000); - for (int i=10; i<1000+10; ++i) { + for (int i = 10; i < 1000 + 10; ++i) { gkyl_dynvec_get(dv, i, out); - TEST_CHECK( out[0] == cos(0.1*(i-10)) ); - TEST_CHECK( out[1] == sin(0.1*(i-10)) ); - TEST_CHECK( out[2] == cos(0.1*(i-10))*sin(0.1*(i-10)) ); + TEST_CHECK(out[0] == cos(0.1 * (i - 10))); + TEST_CHECK(out[1] == sin(0.1 * (i - 10))); + TEST_CHECK(out[2] == cos(0.1 * (i - 10)) * sin(0.1 * (i - 10))); - TEST_CHECK( gkyl_dynvec_get_tm(dv, i) == (i-10)*0.1 ); - } + TEST_CHECK(gkyl_dynvec_get_tm(dv, i) == (i - 10) * 0.1); + } gkyl_dynvec_release(dv); } -void -test_dynvec_io_2_ho() +void test_dynvec_io_2_ho() { gkyl_dynvec dv = gkyl_dynvec_new(GKYL_DOUBLE, 3); double out[3]; - for (int i=0; i<1000; ++i) { - out[0] = cos(0.1*i); - out[1] = sin(0.1*i); - out[2] = cos(0.1*i)*sin(0.1*i); - gkyl_dynvec_append(dv, i*0.1, out); + for (int i = 0; i < 1000; ++i) { + out[0] = cos(0.1 * i); + out[1] = sin(0.1 * i); + out[2] = cos(0.1 * i) * sin(0.1 * i); + gkyl_dynvec_append(dv, i * 0.1, out); } // write twice to the same file gkyl_dynvec_write(dv, "ctest_dynvec_test_io_2.gkyl"); gkyl_dynvec_awrite(dv, "ctest_dynvec_test_io_2.gkyl"); - + gkyl_dynvec_clear(dv); bool res = gkyl_dynvec_read(dv, "ctest_dynvec_test_io_2.gkyl"); - TEST_CHECK( res ); + TEST_CHECK(res); - TEST_CHECK( gkyl_dynvec_size(dv) == 2000 ); + TEST_CHECK(gkyl_dynvec_size(dv) == 2000); - for (int i=0; i<1000; ++i) { + for (int i = 0; i < 1000; ++i) { gkyl_dynvec_get(dv, i, out); - TEST_CHECK( out[0] == cos(0.1*i) ); - TEST_CHECK( out[1] == sin(0.1*i) ); - TEST_CHECK( out[2] == cos(0.1*i)*sin(0.1*i) ); + TEST_CHECK(out[0] == cos(0.1 * i)); + TEST_CHECK(out[1] == sin(0.1 * i)); + TEST_CHECK(out[2] == cos(0.1 * i) * sin(0.1 * i)); - TEST_CHECK( gkyl_dynvec_get_tm(dv, i) == i*0.1 ); + TEST_CHECK(gkyl_dynvec_get_tm(dv, i) == i * 0.1); } - for (int j=1000; j<2000; ++j) { - int i = j-1000; + for (int j = 1000; j < 2000; ++j) { + int i = j - 1000; gkyl_dynvec_get(dv, i, out); - TEST_CHECK( out[0] == cos(0.1*i) ); - TEST_CHECK( out[1] == sin(0.1*i) ); - TEST_CHECK( out[2] == cos(0.1*i)*sin(0.1*i) ); + TEST_CHECK(out[0] == cos(0.1 * i)); + TEST_CHECK(out[1] == sin(0.1 * i)); + TEST_CHECK(out[2] == cos(0.1 * i) * sin(0.1 * i)); - TEST_CHECK( gkyl_dynvec_get_tm(dv, i) == i*0.1 ); - } + TEST_CHECK(gkyl_dynvec_get_tm(dv, i) == i * 0.1); + } gkyl_dynvec_release(dv); } -void -test_dynvec_to_array_ho() +void test_dynvec_to_array_ho() { gkyl_dynvec dv = gkyl_dynvec_new(GKYL_DOUBLE, 3); - double out[3] = { 0.0 }; - for (int i=0; i<10; ++i) { - out[0] = 0.1*i; - out[1] = 0.2*i; - out[2] = 0.3*i; - gkyl_dynvec_append(dv, i*0.1, out); + double out[3] = {0.0}; + for (int i = 0; i < 10; ++i) { + out[0] = 0.1 * i; + out[1] = 0.2 * i; + out[2] = 0.3 * i; + gkyl_dynvec_append(dv, i * 0.1, out); } struct gkyl_array *tm_mesh = gkyl_array_new(GKYL_DOUBLE, 1, gkyl_dynvec_size(dv)); @@ -335,29 +334,29 @@ test_dynvec_to_array_ho() gkyl_dynvec_to_array(dv, tm_mesh, dyn_data); - for (int i=0; i<10; ++i) { + for (int i = 0; i < 10; ++i) { const double *tm_i = gkyl_array_cfetch(tm_mesh, i); const double *dd_i = gkyl_array_cfetch(dyn_data, i); - TEST_CHECK( tm_i[0] == i*0.1 ); + TEST_CHECK(tm_i[0] == i * 0.1); - TEST_CHECK( dd_i[0] == i*0.1 ); - TEST_CHECK( dd_i[1] == i*0.2 ); - TEST_CHECK( dd_i[2] == i*0.3 ); + TEST_CHECK(dd_i[0] == i * 0.1); + TEST_CHECK(dd_i[1] == i * 0.2); + TEST_CHECK(dd_i[2] == i * 0.3); } - + gkyl_dynvec_release(dv); gkyl_array_release(tm_mesh); gkyl_array_release(dyn_data); } TEST_LIST = { - { "test_dynvec_1_ho", test_dynvec_1_ho }, - { "test_dynvec_2_ho", test_dynvec_2_ho }, - { "test_dynvec_3_ho", test_dynvec_3_ho }, - { "test_dynvec_4_ho", test_dynvec_4_ho }, - { "test_dynvec_io_ho", test_dynvec_io_ho }, - { "test_dynvec_io_2_ho", test_dynvec_io_2_ho }, - { "test_dynvec_to_array_ho", test_dynvec_to_array_ho }, - { NULL, NULL }, + {"test_dynvec_1_ho", test_dynvec_1_ho}, + {"test_dynvec_2_ho", test_dynvec_2_ho}, + {"test_dynvec_3_ho", test_dynvec_3_ho}, + {"test_dynvec_4_ho", test_dynvec_4_ho}, + {"test_dynvec_io_ho", test_dynvec_io_ho}, + {"test_dynvec_io_2_ho", test_dynvec_io_2_ho}, + {"test_dynvec_to_array_ho", test_dynvec_to_array_ho}, + {NULL, NULL} }; diff --git a/core/unit/ctest_eval_offset_fd.c b/core/unit/ctest_eval_offset_fd.c index ba0b5b3322..0ac933ef0c 100644 --- a/core/unit/ctest_eval_offset_fd.c +++ b/core/unit/ctest_eval_offset_fd.c @@ -3,12 +3,12 @@ #include #include -void elc_field_1d(double t, const double *xn, double* restrict fout, void *ctx) +void elc_field_1d(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = x+0.1; - fout[1] = x*x+0.2; - fout[2] = x*x*x+0.3; + fout[0] = x + 0.1; + fout[1] = x * x + 0.2; + fout[2] = x * x * x + 0.3; } void test_eval_offset_fd_1d_ho() @@ -18,22 +18,12 @@ void test_eval_offset_fd_1d_ho() struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 1, lower, upper, cells); - struct gkyl_offset_descr offsets[] = { - { 0.0 }, - { -0.5 }, - { -0.5 } - }; - - struct gkyl_eval_offset_fd *ev = gkyl_eval_offset_fd_new( - &(struct gkyl_eval_offset_fd_inp) { - .grid = &grid, - .num_ret_vals = 3, - .offsets = offsets, - .eval = elc_field_1d - } - ); - - int nghost[GKYL_MAX_DIM] = { 0 }; + struct gkyl_offset_descr offsets[] = {{0.0}, {-0.5}, {-0.5}}; + + struct gkyl_eval_offset_fd *ev = gkyl_eval_offset_fd_new(&(struct gkyl_eval_offset_fd_inp + ){.grid = &grid, .num_ret_vals = 3, .offsets = offsets, .eval = elc_field_1d}); + + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -48,28 +38,25 @@ void test_eval_offset_fd_1d_ho() gkyl_range_iter_next(&iter); const double *El = gkyl_array_cfetch(elc_fld, gkyl_range_idx(&arr_range, iter.idx)); - elc_field_1d(0.0, (double[]) { -1.0 }, elc_out, 0); - TEST_CHECK( El[0] == elc_out[0] ); - - elc_field_1d(0.0, (double[]) { -2.0 }, elc_out, 0); - TEST_CHECK( El[1] == elc_out[1] ); - TEST_CHECK( El[2] == elc_out[2] ); + elc_field_1d(0.0, (double[]){-1.0}, elc_out, 0); + TEST_CHECK(El[0] == elc_out[0]); + + elc_field_1d(0.0, (double[]){-2.0}, elc_out, 0); + TEST_CHECK(El[1] == elc_out[1]); + TEST_CHECK(El[2] == elc_out[2]); gkyl_range_iter_next(&iter); const double *Er = gkyl_array_cfetch(elc_fld, gkyl_range_idx(&arr_range, iter.idx)); - elc_field_1d(0.0, (double[]) { 1.0 }, elc_out, 0); - TEST_CHECK( Er[0] == elc_out[0] ); - - elc_field_1d(0.0, (double[]) { 0.0 }, elc_out, 0); - TEST_CHECK( Er[1] == elc_out[1] ); - TEST_CHECK( Er[2] == elc_out[2] ); + elc_field_1d(0.0, (double[]){1.0}, elc_out, 0); + TEST_CHECK(Er[0] == elc_out[0]); + + elc_field_1d(0.0, (double[]){0.0}, elc_out, 0); + TEST_CHECK(Er[1] == elc_out[1]); + TEST_CHECK(Er[2] == elc_out[2]); gkyl_eval_offset_fd_release(ev); gkyl_array_release(elc_fld); } -TEST_LIST = { - { "test_eval_offset_fd_1d_ho", test_eval_offset_fd_1d_ho }, - { NULL, NULL }, -}; +TEST_LIST = {{"test_eval_offset_fd_1d_ho", test_eval_offset_fd_1d_ho}, {NULL, NULL}}; diff --git a/core/unit/ctest_eval_on_nodes.c b/core/unit/ctest_eval_on_nodes.c index d98b979e34..9092c5ceaf 100644 --- a/core/unit/ctest_eval_on_nodes.c +++ b/core/unit/ctest_eval_on_nodes.c @@ -9,23 +9,23 @@ #include -void evalFunc_1x_quad(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_1x_quad(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = x*x; + fout[0] = x * x; } -void evalFunc_1x_trig(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_1x_trig(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = sin((2.*M_PI/(4.))*x); + fout[0] = sin((2. * M_PI / (4.)) * x); } void test_1x(int poly_order, int test_func_op) { double lower[] = {-2.0}, upper[] = {2.0}; int cells[] = {2}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); @@ -35,13 +35,14 @@ void test_1x(int poly_order, int test_func_op) // projection updater for dist-function gkyl_eval_on_nodes *evup; - if (test_func_op==0) + if (test_func_op == 0) { evup = gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc_1x_quad, NULL); - else if (test_func_op==1) + } else if (test_func_op == 1) { evup = gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc_1x_trig, NULL); + } // create array range: no ghost-cells - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -52,35 +53,35 @@ void test_1x(int poly_order, int test_func_op) gkyl_eval_on_nodes_advance(evup, 0.0, &arr_range, distf); gkyl_grid_sub_array_write(&grid, &arr_range, 0, distf, "ctest_eval_on_nodes_distf.gkyl"); - double *dfl = gkyl_array_fetch(distf, 0); // left cell - double *dfr = gkyl_array_fetch(distf, 1); // right cell + double *dfl = gkyl_array_fetch(distf, 0); // left cell + double *dfr = gkyl_array_fetch(distf, 1); // right cell if (poly_order == 1) { - if (test_func_op==0) { - TEST_CHECK( gkyl_compare( 2.82842712474619e+00, dfl[0], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.63299316185545e+00, dfl[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.82842712474619e+00, dfr[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.63299316185545e+00, dfr[1], 1e-12) ); - } else if (test_func_op==1) { - TEST_CHECK( gkyl_compare(-8.65956056235493e-17, dfl[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.99959962173949e-17, dfl[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 8.65956056235493e-17, dfr[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.99959962173949e-17, dfr[1], 1e-12) ); + if (test_func_op == 0) { + TEST_CHECK(gkyl_compare(2.82842712474619e+00, dfl[0], 1e-12)); + TEST_CHECK(gkyl_compare(-1.63299316185545e+00, dfl[1], 1e-12)); + TEST_CHECK(gkyl_compare(2.82842712474619e+00, dfr[0], 1e-12)); + TEST_CHECK(gkyl_compare(1.63299316185545e+00, dfr[1], 1e-12)); + } else if (test_func_op == 1) { + TEST_CHECK(gkyl_compare(-8.65956056235493e-17, dfl[0], 1e-12)); + TEST_CHECK(gkyl_compare(4.99959962173949e-17, dfl[1], 1e-12)); + TEST_CHECK(gkyl_compare(8.65956056235493e-17, dfr[0], 1e-12)); + TEST_CHECK(gkyl_compare(4.99959962173949e-17, dfr[1], 1e-12)); } } else if (poly_order == 2) { - if (test_func_op==0) { - TEST_CHECK( gkyl_compare( 1.88561808316413e+00, dfl[0], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.63299316185545e+00, dfl[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.21637021355784e-01, dfl[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.88561808316413e+00, dfr[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.63299316185545e+00, dfr[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.21637021355784e-01, dfr[2], 1e-12) ); - } else if (test_func_op==1) { - TEST_CHECK( gkyl_compare(-9.42809041582064e-01, dfl[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.99959962173949e-17, dfl[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.21637021355784e-01, dfl[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 9.42809041582064e-01, dfr[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.99959962173949e-17, dfr[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-4.21637021355784e-01, dfr[2], 1e-12) ); + if (test_func_op == 0) { + TEST_CHECK(gkyl_compare(1.88561808316413e+00, dfl[0], 1e-12)); + TEST_CHECK(gkyl_compare(-1.63299316185545e+00, dfl[1], 1e-12)); + TEST_CHECK(gkyl_compare(4.21637021355784e-01, dfl[2], 1e-12)); + TEST_CHECK(gkyl_compare(1.88561808316413e+00, dfr[0], 1e-12)); + TEST_CHECK(gkyl_compare(1.63299316185545e+00, dfr[1], 1e-12)); + TEST_CHECK(gkyl_compare(4.21637021355784e-01, dfr[2], 1e-12)); + } else if (test_func_op == 1) { + TEST_CHECK(gkyl_compare(-9.42809041582064e-01, dfl[0], 1e-12)); + TEST_CHECK(gkyl_compare(4.99959962173949e-17, dfl[1], 1e-12)); + TEST_CHECK(gkyl_compare(4.21637021355784e-01, dfl[2], 1e-12)); + TEST_CHECK(gkyl_compare(9.42809041582064e-01, dfr[0], 1e-12)); + TEST_CHECK(gkyl_compare(4.99959962173949e-17, dfr[1], 1e-12)); + TEST_CHECK(gkyl_compare(-4.21637021355784e-01, dfr[2], 1e-12)); } } @@ -88,23 +89,24 @@ void test_1x(int poly_order, int test_func_op) gkyl_array_release(distf); } -void evalFunc_2x_quad(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_2x_quad(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; - fout[0] = x*x + x*y + y*y; + fout[0] = x * x + x * y + y * y; } -void evalFunc_2x_trig(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_2x_trig(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; - fout[0] = sin((2.*M_PI/(4.))*x) + sin((2.*M_PI/(4.))*x)*cos((2.*M_PI/(4.))*y) + cos((2.*M_PI/(4.))*y); + fout[0] = sin((2. * M_PI / (4.)) * x) + + sin((2. * M_PI / (4.)) * x) * cos((2. * M_PI / (4.)) * y) + cos((2. * M_PI / (4.)) * y); } void test_2x(int poly_order, int test_func_op) { double lower[] = {-2.0, -2.0}, upper[] = {2.0, 2.0}; int cells[] = {2, 2}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); @@ -114,13 +116,14 @@ void test_2x(int poly_order, int test_func_op) // projection updater for dist-function gkyl_eval_on_nodes *evup; - if (test_func_op==0) + if (test_func_op == 0) { evup = gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc_2x_quad, NULL); - else if (test_func_op==1) + } else if (test_func_op == 1) { evup = gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc_2x_trig, NULL); + } // create array range: no ghost-cells - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -131,113 +134,113 @@ void test_2x(int poly_order, int test_func_op) gkyl_eval_on_nodes_advance(evup, 0.0, &arr_range, distf); gkyl_grid_sub_array_write(&grid, &arr_range, 0, distf, "ctest_eval_on_nodes_distf.gkyl"); - double *dfll = gkyl_array_fetch(distf, 0); // left, low cell - double *dflu = gkyl_array_fetch(distf, 1); // left, up cell - double *dfrl = gkyl_array_fetch(distf, 2); // right, low cell - double *dfru = gkyl_array_fetch(distf, 3); // right, up cell + double *dfll = gkyl_array_fetch(distf, 0); // left, low cell + double *dflu = gkyl_array_fetch(distf, 1); // left, up cell + double *dfrl = gkyl_array_fetch(distf, 2); // right, low cell + double *dfru = gkyl_array_fetch(distf, 3); // right, up cell if (poly_order == 1) { - if (test_func_op==0) { - TEST_CHECK( gkyl_compare( 1.00000000000000e+01, dfll[0], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.46410161513776e+00, dfll[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.46410161513776e+00, dfll[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01, dfll[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.00000000000000e+00, dflu[0], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.15470053837925e+00, dflu[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.15470053837925e+00, dflu[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01, dflu[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.00000000000000e+00, dfrl[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.15470053837925e+00, dfrl[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.15470053837925e+00, dfrl[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01, dfrl[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.00000000000000e+01, dfru[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.46410161513776e+00, dfru[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.46410161513776e+00, dfru[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01, dfru[3], 1e-12) ); - } else if (test_func_op==1) { - TEST_CHECK( gkyl_compare(-1.11022302462516e-16 , dfll[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.55111512312578e-17 , dfll[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.15470053837925e+00 , dfll[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.77555756156289e-17 , dfll[3], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.11022302462516e-16 , dflu[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.55111512312578e-17 , dflu[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.15470053837925e+00 , dflu[2], 1e-12) ); - TEST_CHECK( gkyl_compare(-2.77555756156289e-17 , dflu[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.11022302462516e-16 , dfrl[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.55111512312578e-17 , dfrl[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.15470053837925e+00 , dfrl[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.77555756156289e-17 , dfrl[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 0.00000000000000e+00 , dfru[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.55111512312578e-17 , dfru[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.15470053837925e+00 , dfru[2], 1e-12) ); - TEST_CHECK( gkyl_compare(-2.77555756156289e-17 , dfru[3], 1e-12) ); + if (test_func_op == 0) { + TEST_CHECK(gkyl_compare(1.00000000000000e+01, dfll[0], 1e-12)); + TEST_CHECK(gkyl_compare(-3.46410161513776e+00, dfll[1], 1e-12)); + TEST_CHECK(gkyl_compare(-3.46410161513776e+00, dfll[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dfll[3], 1e-12)); + TEST_CHECK(gkyl_compare(6.00000000000000e+00, dflu[0], 1e-12)); + TEST_CHECK(gkyl_compare(-1.15470053837925e+00, dflu[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.15470053837925e+00, dflu[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dflu[3], 1e-12)); + TEST_CHECK(gkyl_compare(6.00000000000000e+00, dfrl[0], 1e-12)); + TEST_CHECK(gkyl_compare(1.15470053837925e+00, dfrl[1], 1e-12)); + TEST_CHECK(gkyl_compare(-1.15470053837925e+00, dfrl[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dfrl[3], 1e-12)); + TEST_CHECK(gkyl_compare(1.00000000000000e+01, dfru[0], 1e-12)); + TEST_CHECK(gkyl_compare(3.46410161513776e+00, dfru[1], 1e-12)); + TEST_CHECK(gkyl_compare(3.46410161513776e+00, dfru[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dfru[3], 1e-12)); + } else if (test_func_op == 1) { + TEST_CHECK(gkyl_compare(-1.11022302462516e-16, dfll[0], 1e-12)); + TEST_CHECK(gkyl_compare(5.55111512312578e-17, dfll[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.15470053837925e+00, dfll[2], 1e-12)); + TEST_CHECK(gkyl_compare(2.77555756156289e-17, dfll[3], 1e-12)); + TEST_CHECK(gkyl_compare(-1.11022302462516e-16, dflu[0], 1e-12)); + TEST_CHECK(gkyl_compare(5.55111512312578e-17, dflu[1], 1e-12)); + TEST_CHECK(gkyl_compare(-1.15470053837925e+00, dflu[2], 1e-12)); + TEST_CHECK(gkyl_compare(-2.77555756156289e-17, dflu[3], 1e-12)); + TEST_CHECK(gkyl_compare(1.11022302462516e-16, dfrl[0], 1e-12)); + TEST_CHECK(gkyl_compare(5.55111512312578e-17, dfrl[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.15470053837925e+00, dfrl[2], 1e-12)); + TEST_CHECK(gkyl_compare(2.77555756156289e-17, dfrl[3], 1e-12)); + TEST_CHECK(gkyl_compare(0.00000000000000e+00, dfru[0], 1e-12)); + TEST_CHECK(gkyl_compare(5.55111512312578e-17, dfru[1], 1e-12)); + TEST_CHECK(gkyl_compare(-1.15470053837925e+00, dfru[2], 1e-12)); + TEST_CHECK(gkyl_compare(-2.77555756156289e-17, dfru[3], 1e-12)); } } else if (poly_order == 2) { - if (test_func_op==0) { - TEST_CHECK( gkyl_compare( 7.33333333333333e+00, dfll[0], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.46410161513775e+00, dfll[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.46410161513775e+00, dfll[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01, dfll[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.96284793999945e-01, dfll[4], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.96284793999945e-01, dfll[5], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.11022302462516e-16, dfll[6], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.11022302462516e-16, dfll[7], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.33333333333333e+00, dflu[0], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.15470053837925e+00, dflu[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.15470053837925e+00, dflu[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01, dflu[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.96284793999944e-01, dflu[4], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.96284793999944e-01, dflu[5], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.55111512312578e-17, dflu[6], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.55111512312578e-17, dflu[7], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.33333333333333e+00, dfrl[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.15470053837925e+00, dfrl[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.15470053837925e+00, dfrl[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01, dfrl[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.96284793999944e-01, dfrl[4], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.96284793999944e-01, dfrl[5], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.55111512312578e-17, dfrl[6], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.55111512312578e-17, dfrl[7], 1e-12) ); - TEST_CHECK( gkyl_compare( 7.33333333333333e+00, dfru[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.46410161513775e+00, dfru[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.46410161513775e+00, dfru[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01, dfru[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.96284793999944e-01, dfru[4], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.96284793999944e-01, dfru[5], 1e-12) ); - TEST_CHECK( gkyl_compare( 0.00000000000000e+00, dfru[6], 1e-12) ); - TEST_CHECK( gkyl_compare( 0.00000000000000e+00, dfru[7], 1e-12) ); - } else if (test_func_op==1) { - TEST_CHECK( gkyl_compare(-1.33333333333333e+00, dfll[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.93889390390723e-17, dfll[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.84900179459750e-01, dfll[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.77555756156289e-17, dfll[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.96284793999944e-01, dfll[4], 1e-12) ); - TEST_CHECK( gkyl_compare( 0.00000000000000e+00, dfll[5], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.44265186329548e-01, dfll[6], 1e-12) ); - TEST_CHECK( gkyl_compare( 0.00000000000000e+00, dfll[7], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.33333333333333e+00, dflu[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.93889390390723e-17, dflu[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.84900179459750e-01, dflu[2], 1e-12) ); - TEST_CHECK( gkyl_compare(-2.77555756156289e-17, dflu[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.96284793999944e-01, dflu[4], 1e-12) ); - TEST_CHECK( gkyl_compare(-2.77555756156289e-17, dflu[5], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.44265186329548e-01, dflu[6], 1e-12) ); - TEST_CHECK( gkyl_compare( 0.00000000000000e+00, dflu[7], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.33333333333333e+00, dfrl[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.55111512312578e-17, dfrl[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.92450089729875e+00, dfrl[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.77555756156289e-17, dfrl[3], 1e-12) ); - TEST_CHECK( gkyl_compare(-5.96284793999944e-01, dfrl[4], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.38777878078145e-16, dfrl[5], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.44265186329548e-01, dfrl[6], 1e-12) ); - TEST_CHECK( gkyl_compare( 0.00000000000000e+00, dfrl[7], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.33333333333333e+00, dfru[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.93889390390723e-17, dfru[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.92450089729875e+00, dfru[2], 1e-12) ); - TEST_CHECK( gkyl_compare(-2.77555756156289e-17, dfru[3], 1e-12) ); - TEST_CHECK( gkyl_compare(-5.96284793999944e-01, dfru[4], 1e-12) ); - TEST_CHECK( gkyl_compare( 8.32667268468867e-17, dfru[5], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.44265186329548e-01, dfru[6], 1e-12) ); - TEST_CHECK( gkyl_compare(-6.93889390390723e-17, dfru[7], 1e-12) ); + if (test_func_op == 0) { + TEST_CHECK(gkyl_compare(7.33333333333333e+00, dfll[0], 1e-12)); + TEST_CHECK(gkyl_compare(-3.46410161513775e+00, dfll[1], 1e-12)); + TEST_CHECK(gkyl_compare(-3.46410161513775e+00, dfll[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dfll[3], 1e-12)); + TEST_CHECK(gkyl_compare(5.96284793999945e-01, dfll[4], 1e-12)); + TEST_CHECK(gkyl_compare(5.96284793999945e-01, dfll[5], 1e-12)); + TEST_CHECK(gkyl_compare(1.11022302462516e-16, dfll[6], 1e-12)); + TEST_CHECK(gkyl_compare(1.11022302462516e-16, dfll[7], 1e-12)); + TEST_CHECK(gkyl_compare(3.33333333333333e+00, dflu[0], 1e-12)); + TEST_CHECK(gkyl_compare(-1.15470053837925e+00, dflu[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.15470053837925e+00, dflu[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dflu[3], 1e-12)); + TEST_CHECK(gkyl_compare(5.96284793999944e-01, dflu[4], 1e-12)); + TEST_CHECK(gkyl_compare(5.96284793999944e-01, dflu[5], 1e-12)); + TEST_CHECK(gkyl_compare(5.55111512312578e-17, dflu[6], 1e-12)); + TEST_CHECK(gkyl_compare(5.55111512312578e-17, dflu[7], 1e-12)); + TEST_CHECK(gkyl_compare(3.33333333333333e+00, dfrl[0], 1e-12)); + TEST_CHECK(gkyl_compare(1.15470053837925e+00, dfrl[1], 1e-12)); + TEST_CHECK(gkyl_compare(-1.15470053837925e+00, dfrl[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dfrl[3], 1e-12)); + TEST_CHECK(gkyl_compare(5.96284793999944e-01, dfrl[4], 1e-12)); + TEST_CHECK(gkyl_compare(5.96284793999944e-01, dfrl[5], 1e-12)); + TEST_CHECK(gkyl_compare(5.55111512312578e-17, dfrl[6], 1e-12)); + TEST_CHECK(gkyl_compare(5.55111512312578e-17, dfrl[7], 1e-12)); + TEST_CHECK(gkyl_compare(7.33333333333333e+00, dfru[0], 1e-12)); + TEST_CHECK(gkyl_compare(3.46410161513775e+00, dfru[1], 1e-12)); + TEST_CHECK(gkyl_compare(3.46410161513775e+00, dfru[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dfru[3], 1e-12)); + TEST_CHECK(gkyl_compare(5.96284793999944e-01, dfru[4], 1e-12)); + TEST_CHECK(gkyl_compare(5.96284793999944e-01, dfru[5], 1e-12)); + TEST_CHECK(gkyl_compare(0.00000000000000e+00, dfru[6], 1e-12)); + TEST_CHECK(gkyl_compare(0.00000000000000e+00, dfru[7], 1e-12)); + } else if (test_func_op == 1) { + TEST_CHECK(gkyl_compare(-1.33333333333333e+00, dfll[0], 1e-12)); + TEST_CHECK(gkyl_compare(6.93889390390723e-17, dfll[1], 1e-12)); + TEST_CHECK(gkyl_compare(3.84900179459750e-01, dfll[2], 1e-12)); + TEST_CHECK(gkyl_compare(2.77555756156289e-17, dfll[3], 1e-12)); + TEST_CHECK(gkyl_compare(5.96284793999944e-01, dfll[4], 1e-12)); + TEST_CHECK(gkyl_compare(0.00000000000000e+00, dfll[5], 1e-12)); + TEST_CHECK(gkyl_compare(3.44265186329548e-01, dfll[6], 1e-12)); + TEST_CHECK(gkyl_compare(0.00000000000000e+00, dfll[7], 1e-12)); + TEST_CHECK(gkyl_compare(-1.33333333333333e+00, dflu[0], 1e-12)); + TEST_CHECK(gkyl_compare(6.93889390390723e-17, dflu[1], 1e-12)); + TEST_CHECK(gkyl_compare(-3.84900179459750e-01, dflu[2], 1e-12)); + TEST_CHECK(gkyl_compare(-2.77555756156289e-17, dflu[3], 1e-12)); + TEST_CHECK(gkyl_compare(5.96284793999944e-01, dflu[4], 1e-12)); + TEST_CHECK(gkyl_compare(-2.77555756156289e-17, dflu[5], 1e-12)); + TEST_CHECK(gkyl_compare(-3.44265186329548e-01, dflu[6], 1e-12)); + TEST_CHECK(gkyl_compare(0.00000000000000e+00, dflu[7], 1e-12)); + TEST_CHECK(gkyl_compare(1.33333333333333e+00, dfrl[0], 1e-12)); + TEST_CHECK(gkyl_compare(5.55111512312578e-17, dfrl[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.92450089729875e+00, dfrl[2], 1e-12)); + TEST_CHECK(gkyl_compare(2.77555756156289e-17, dfrl[3], 1e-12)); + TEST_CHECK(gkyl_compare(-5.96284793999944e-01, dfrl[4], 1e-12)); + TEST_CHECK(gkyl_compare(-1.38777878078145e-16, dfrl[5], 1e-12)); + TEST_CHECK(gkyl_compare(-3.44265186329548e-01, dfrl[6], 1e-12)); + TEST_CHECK(gkyl_compare(0.00000000000000e+00, dfrl[7], 1e-12)); + TEST_CHECK(gkyl_compare(1.33333333333333e+00, dfru[0], 1e-12)); + TEST_CHECK(gkyl_compare(6.93889390390723e-17, dfru[1], 1e-12)); + TEST_CHECK(gkyl_compare(-1.92450089729875e+00, dfru[2], 1e-12)); + TEST_CHECK(gkyl_compare(-2.77555756156289e-17, dfru[3], 1e-12)); + TEST_CHECK(gkyl_compare(-5.96284793999944e-01, dfru[4], 1e-12)); + TEST_CHECK(gkyl_compare(8.32667268468867e-17, dfru[5], 1e-12)); + TEST_CHECK(gkyl_compare(3.44265186329548e-01, dfru[6], 1e-12)); + TEST_CHECK(gkyl_compare(-6.93889390390723e-17, dfru[7], 1e-12)); } } @@ -249,24 +252,26 @@ void test_1x1v_hyb(int poly_order, int test_func_op) { double lower[] = {-2.0, -2.0}, upper[] = {2.0, 2.0}; int cells[] = {2, 2}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); // basis functions struct gkyl_basis basis; - int cdim = 1; int vdim = 1; + int cdim = 1; + int vdim = 1; gkyl_cart_modal_hybrid(&basis, cdim, vdim); // projection updater for dist-function gkyl_eval_on_nodes *evup; - if (test_func_op==0) + if (test_func_op == 0) { evup = gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc_2x_quad, NULL); - else if (test_func_op==1) + } else if (test_func_op == 1) { evup = gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc_2x_trig, NULL); + } // create array range: no ghost-cells - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -277,61 +282,61 @@ void test_1x1v_hyb(int poly_order, int test_func_op) gkyl_eval_on_nodes_advance(evup, 0.0, &arr_range, distf); gkyl_grid_sub_array_write(&grid, &arr_range, 0, distf, "ctest_eval_on_nodes_distf_hyb.gkyl"); - double *dfll = gkyl_array_fetch(distf, 0); // left, low cell - double *dflu = gkyl_array_fetch(distf, 1); // left, up cell - double *dfrl = gkyl_array_fetch(distf, 2); // right, low cell - double *dfru = gkyl_array_fetch(distf, 3); // right, up cell + double *dfll = gkyl_array_fetch(distf, 0); // left, low cell + double *dflu = gkyl_array_fetch(distf, 1); // left, up cell + double *dfrl = gkyl_array_fetch(distf, 2); // right, low cell + double *dfru = gkyl_array_fetch(distf, 3); // right, up cell if (poly_order == 1) { - if (test_func_op==0) { - TEST_CHECK( gkyl_compare( 8.6666666666666679e+00, dfll[0], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.46410161513776e+00 , dfll[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.46410161513776e+00 , dfll[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01 , dfll[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.9628479399994472e-01, dfll[4], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.7755575615628914e-16, dfll[5], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.6666666666666670e+00, dflu[0], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.15470053837925e+00 , dflu[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.15470053837925e+00 , dflu[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01 , dflu[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.9628479399994450e-01, dflu[4], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.1102230246251565e-16, dflu[5], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.6666666666666670e+00, dfrl[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.15470053837925e+00 , dfrl[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.15470053837925e+00 , dfrl[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01 , dfrl[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.9628479399994450e-01, dfrl[4], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.1102230246251565e-16, dfrl[5], 1e-12) ); - TEST_CHECK( gkyl_compare( 8.6666666666666679e+00, dfru[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.46410161513776e+00 , dfru[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.46410161513776e+00 , dfru[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.66666666666667e-01 , dfru[3], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.9628479399994472e-01, dfru[4], 1e-12) ); - TEST_CHECK( gkyl_compare(-2.7755575615628914e-16, dfru[5], 1e-12) ); - } else if (test_func_op==1) { - TEST_CHECK( gkyl_compare(-3.7007434154171901e-17 , dfll[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.8502929347591034e-17 , dfll[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.1547005383792517e+00 , dfll[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.7007434154171895e-17 , dfll[3], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.3100455376630308e-17 , dfll[4], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.9696061028207229e-18 , dfll[5], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.7007434154171901e-17 , dflu[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.8502929347591034e-17 , dflu[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.1547005383792517e+00 , dflu[2], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.7007434154171895e-17 , dflu[3], 1e-12) ); - TEST_CHECK( gkyl_compare(-3.3100455376630308e-17 , dflu[4], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.9696061028207229e-18 , dflu[5], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.3730110819465753e-16 , dfrl[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 8.9869181418519517e-17 , dfrl[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.1547005383792517e+00 , dfrl[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 7.4014868308343790e-17 , dfrl[3], 1e-12) ); - TEST_CHECK( gkyl_compare(-6.8229156819663812e-18 , dfrl[4], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.7140950719175985e-17 , dfrl[5], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.3730110819465753e-16 , dfru[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 8.9869181418519517e-17 , dfru[1], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.1547005383792517e+00 , dfru[2], 1e-12) ); - TEST_CHECK( gkyl_compare(-7.4014868308343790e-17 , dfru[3], 1e-12) ); - TEST_CHECK( gkyl_compare(-6.8229156819663812e-18 , dfru[4], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.7140950719175985e-17 , dfru[5], 1e-12) ); + if (test_func_op == 0) { + TEST_CHECK(gkyl_compare(8.6666666666666679e+00, dfll[0], 1e-12)); + TEST_CHECK(gkyl_compare(-3.46410161513776e+00, dfll[1], 1e-12)); + TEST_CHECK(gkyl_compare(-3.46410161513776e+00, dfll[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dfll[3], 1e-12)); + TEST_CHECK(gkyl_compare(5.9628479399994472e-01, dfll[4], 1e-12)); + TEST_CHECK(gkyl_compare(2.7755575615628914e-16, dfll[5], 1e-12)); + TEST_CHECK(gkyl_compare(4.6666666666666670e+00, dflu[0], 1e-12)); + TEST_CHECK(gkyl_compare(-1.15470053837925e+00, dflu[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.15470053837925e+00, dflu[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dflu[3], 1e-12)); + TEST_CHECK(gkyl_compare(5.9628479399994450e-01, dflu[4], 1e-12)); + TEST_CHECK(gkyl_compare(1.1102230246251565e-16, dflu[5], 1e-12)); + TEST_CHECK(gkyl_compare(4.6666666666666670e+00, dfrl[0], 1e-12)); + TEST_CHECK(gkyl_compare(1.15470053837925e+00, dfrl[1], 1e-12)); + TEST_CHECK(gkyl_compare(-1.15470053837925e+00, dfrl[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dfrl[3], 1e-12)); + TEST_CHECK(gkyl_compare(5.9628479399994450e-01, dfrl[4], 1e-12)); + TEST_CHECK(gkyl_compare(-1.1102230246251565e-16, dfrl[5], 1e-12)); + TEST_CHECK(gkyl_compare(8.6666666666666679e+00, dfru[0], 1e-12)); + TEST_CHECK(gkyl_compare(3.46410161513776e+00, dfru[1], 1e-12)); + TEST_CHECK(gkyl_compare(3.46410161513776e+00, dfru[2], 1e-12)); + TEST_CHECK(gkyl_compare(6.66666666666667e-01, dfru[3], 1e-12)); + TEST_CHECK(gkyl_compare(5.9628479399994472e-01, dfru[4], 1e-12)); + TEST_CHECK(gkyl_compare(-2.7755575615628914e-16, dfru[5], 1e-12)); + } else if (test_func_op == 1) { + TEST_CHECK(gkyl_compare(-3.7007434154171901e-17, dfll[0], 1e-12)); + TEST_CHECK(gkyl_compare(6.8502929347591034e-17, dfll[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.1547005383792517e+00, dfll[2], 1e-12)); + TEST_CHECK(gkyl_compare(3.7007434154171895e-17, dfll[3], 1e-12)); + TEST_CHECK(gkyl_compare(-3.3100455376630308e-17, dfll[4], 1e-12)); + TEST_CHECK(gkyl_compare(-1.9696061028207229e-18, dfll[5], 1e-12)); + TEST_CHECK(gkyl_compare(-3.7007434154171901e-17, dflu[0], 1e-12)); + TEST_CHECK(gkyl_compare(6.8502929347591034e-17, dflu[1], 1e-12)); + TEST_CHECK(gkyl_compare(-1.1547005383792517e+00, dflu[2], 1e-12)); + TEST_CHECK(gkyl_compare(-3.7007434154171895e-17, dflu[3], 1e-12)); + TEST_CHECK(gkyl_compare(-3.3100455376630308e-17, dflu[4], 1e-12)); + TEST_CHECK(gkyl_compare(-1.9696061028207229e-18, dflu[5], 1e-12)); + TEST_CHECK(gkyl_compare(2.3730110819465753e-16, dfrl[0], 1e-12)); + TEST_CHECK(gkyl_compare(8.9869181418519517e-17, dfrl[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.1547005383792517e+00, dfrl[2], 1e-12)); + TEST_CHECK(gkyl_compare(7.4014868308343790e-17, dfrl[3], 1e-12)); + TEST_CHECK(gkyl_compare(-6.8229156819663812e-18, dfrl[4], 1e-12)); + TEST_CHECK(gkyl_compare(1.7140950719175985e-17, dfrl[5], 1e-12)); + TEST_CHECK(gkyl_compare(2.3730110819465753e-16, dfru[0], 1e-12)); + TEST_CHECK(gkyl_compare(8.9869181418519517e-17, dfru[1], 1e-12)); + TEST_CHECK(gkyl_compare(-1.1547005383792517e+00, dfru[2], 1e-12)); + TEST_CHECK(gkyl_compare(-7.4014868308343790e-17, dfru[3], 1e-12)); + TEST_CHECK(gkyl_compare(-6.8229156819663812e-18, dfru[4], 1e-12)); + TEST_CHECK(gkyl_compare(1.7140950719175985e-17, dfru[5], 1e-12)); } } else { assert(true); @@ -340,25 +345,26 @@ void test_1x1v_hyb(int poly_order, int test_func_op) gkyl_array_release(distf); } -void evalFunc_3x_quad(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_3x_quad(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; - fout[0] = x*x + x*y + y*y + x*z + y*z + z*z; + fout[0] = x * x + x * y + y * y + x * z + y * z + z * z; } -void evalFunc_3x_trig(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_3x_trig(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; - fout[0] = sin((2.*M_PI/(4.))*x) + sin((2.*M_PI/(4.))*x)*cos((2.*M_PI/(4.))*y) + cos((2.*M_PI/(4.))*y) - + sin((2.*M_PI/(4.))*x)*cos((2.*M_PI/(4.))*z) - + cos((2.*M_PI/(4.))*y)*cos((2.*M_PI/(4.))*z) + cos((2.*M_PI/(4.))*z); + fout[0] = + sin((2. * M_PI / (4.)) * x) + sin((2. * M_PI / (4.)) * x) * cos((2. * M_PI / (4.)) * y) + + cos((2. * M_PI / (4.)) * y) + sin((2. * M_PI / (4.)) * x) * cos((2. * M_PI / (4.)) * z) + + cos((2. * M_PI / (4.)) * y) * cos((2. * M_PI / (4.)) * z) + cos((2. * M_PI / (4.)) * z); } void test_3x(int poly_order, int test_func_op) { double lower[] = {-2.0, -2.0, -2.0}, upper[] = {2.0, 2.0, 2.0}; int cells[] = {2, 2, 2}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); @@ -368,13 +374,14 @@ void test_3x(int poly_order, int test_func_op) // projection updater for dist-function gkyl_eval_on_nodes *evup; - if (test_func_op==0) + if (test_func_op == 0) { evup = gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc_3x_quad, NULL); - else if (test_func_op==1) + } else if (test_func_op == 1) { evup = gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc_3x_trig, NULL); + } // create array range: no ghost-cells - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -386,124 +393,164 @@ void test_3x(int poly_order, int test_func_op) gkyl_grid_sub_array_write(&grid, &arr_range, 0, distf, "ctest_eval_on_nodes_distf.gkyl"); - double *dfllf = gkyl_array_fetch(distf, 0); // left, low, front cell - double *dfllb = gkyl_array_fetch(distf, 1); // left, low, back cell - double *dfluf = gkyl_array_fetch(distf, 2); // left, up, front cell - double *dflub = gkyl_array_fetch(distf, 3); // left, up, back cell - double *dfrlf = gkyl_array_fetch(distf, 4); // right, low, front cell - double *dfrlb = gkyl_array_fetch(distf, 5); // right, low, back cell - double *dfruf = gkyl_array_fetch(distf, 6); // right, up, front cell - double *dfrub = gkyl_array_fetch(distf, 7); // right, up, back cell + double *dfllf = gkyl_array_fetch(distf, 0); // left, low, front cell + double *dfllb = gkyl_array_fetch(distf, 1); // left, low, back cell + double *dfluf = gkyl_array_fetch(distf, 2); // left, up, front cell + double *dflub = gkyl_array_fetch(distf, 3); // left, up, back cell + double *dfrlf = gkyl_array_fetch(distf, 4); // right, low, front cell + double *dfrlb = gkyl_array_fetch(distf, 5); // right, low, back cell + double *dfruf = gkyl_array_fetch(distf, 6); // right, up, front cell + double *dfrub = gkyl_array_fetch(distf, 7); // right, up, back cell if (poly_order == 1) { - if (test_func_op==0) { + if (test_func_op == 0) { double fref[] = { - 2.54558441227157e+01, -6.53197264742181e+00, -6.53197264742181e+00, -6.53197264742181e+00, 9.42809041582064e-01, 9.42809041582062e-01, - 9.42809041582062e-01, -5.55111512312578e-17, 1.41421356237310e+01, -3.26598632371091e+00, -3.26598632371090e+00, 7.77156117237610e-16, - 9.42809041582064e-01, 9.42809041582063e-01, 9.42809041582063e-01, -5.55111512312578e-17, 1.41421356237309e+01, -3.26598632371091e+00, - 3.33066907387547e-16, -3.26598632371090e+00, 9.42809041582064e-01, 9.42809041582063e-01, 9.42809041582064e-01, 5.55111512312578e-17, - 1.41421356237310e+01, 0.00000000000000e+00, 3.26598632371091e+00, 3.26598632371091e+00, 9.42809041582064e-01, 9.42809041582064e-01, - 9.42809041582064e-01, 0.00000000000000e+00, 1.41421356237309e+01, 2.22044604925031e-16, -3.26598632371090e+00, -3.26598632371090e+00, - 9.42809041582064e-01, 9.42809041582064e-01, 9.42809041582063e-01, 0.00000000000000e+00, 1.41421356237310e+01, 3.26598632371091e+00, - 8.88178419700125e-16, 3.26598632371091e+00, 9.42809041582064e-01, 9.42809041582064e-01, 9.42809041582064e-01, 0.00000000000000e+00, - 1.41421356237310e+01, 3.26598632371091e+00, 3.26598632371091e+00, 8.88178419700125e-16, 9.42809041582064e-01, 9.42809041582064e-01, - 9.42809041582064e-01, 0.00000000000000e+00, 2.54558441227157e+01, 6.53197264742181e+00, 6.53197264742181e+00, 6.53197264742181e+00, - 9.42809041582064e-01, 9.42809041582065e-01, 9.42809041582065e-01, 0.00000000000000e+00, + 2.54558441227157e+01, -6.53197264742181e+00, -6.53197264742181e+00, -6.53197264742181e+00, + 9.42809041582064e-01, 9.42809041582062e-01, 9.42809041582062e-01, -5.55111512312578e-17, + 1.41421356237310e+01, -3.26598632371091e+00, -3.26598632371090e+00, 7.77156117237610e-16, + 9.42809041582064e-01, 9.42809041582063e-01, 9.42809041582063e-01, -5.55111512312578e-17, + 1.41421356237309e+01, -3.26598632371091e+00, 3.33066907387547e-16, -3.26598632371090e+00, + 9.42809041582064e-01, 9.42809041582063e-01, 9.42809041582064e-01, 5.55111512312578e-17, + 1.41421356237310e+01, 0.00000000000000e+00, 3.26598632371091e+00, 3.26598632371091e+00, + 9.42809041582064e-01, 9.42809041582064e-01, 9.42809041582064e-01, 0.00000000000000e+00, + 1.41421356237309e+01, 2.22044604925031e-16, -3.26598632371090e+00, -3.26598632371090e+00, + 9.42809041582064e-01, 9.42809041582064e-01, 9.42809041582063e-01, 0.00000000000000e+00, + 1.41421356237310e+01, 3.26598632371091e+00, 8.88178419700125e-16, 3.26598632371091e+00, + 9.42809041582064e-01, 9.42809041582064e-01, 9.42809041582064e-01, 0.00000000000000e+00, + 1.41421356237310e+01, 3.26598632371091e+00, 3.26598632371091e+00, 8.88178419700125e-16, + 9.42809041582064e-01, 9.42809041582064e-01, 9.42809041582064e-01, 0.00000000000000e+00, + 2.54558441227157e+01, 6.53197264742181e+00, 6.53197264742181e+00, 6.53197264742181e+00, + 9.42809041582064e-01, 9.42809041582065e-01, 9.42809041582065e-01, 0.00000000000000e+00 }; - for (int i=0; i #include -void evalFunc(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = x*x; + fout[0] = x * x; } -void -test_fv_proj_1_ho() +void test_fv_proj_1_ho() { double lower[] = {-2.0}, upper[] = {4.0}; int cells[] = {2}; @@ -22,7 +21,7 @@ test_fv_proj_1_ho() gkyl_fv_proj *fv_proj = gkyl_fv_proj_new(&grid, 2, 1, evalFunc, NULL); // create array range: no ghost-cells - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -34,17 +33,14 @@ test_fv_proj_1_ho() // left cell double *dfl = gkyl_array_fetch(distf, 0); - TEST_CHECK( gkyl_compare(1.0, dfl[0], 1e-12) ); + TEST_CHECK(gkyl_compare(1.0, dfl[0], 1e-12)); // right cell double *dfr = gkyl_array_fetch(distf, 1); - TEST_CHECK( gkyl_compare(7.0, dfr[0], 1e-12) ); + TEST_CHECK(gkyl_compare(7.0, dfr[0], 1e-12)); gkyl_fv_proj_release(fv_proj); gkyl_array_release(distf); } -TEST_LIST = { - { "test_fv_proj_1_ho", test_fv_proj_1_ho }, - { NULL, NULL }, -}; +TEST_LIST = {{"test_fv_proj_1_ho", test_fv_proj_1_ho}, {NULL, NULL}}; diff --git a/core/unit/ctest_gauss_quad.c b/core/unit/ctest_gauss_quad.c index f4f967258e..b9defc3a62 100644 --- a/core/unit/ctest_gauss_quad.c +++ b/core/unit/ctest_gauss_quad.c @@ -3,64 +3,63 @@ #include #include -static void -test_gauss_quad_basic_ho() +static void test_gauss_quad_basic_ho() { int gauss_max = gkyl_gauss_max; double w[gauss_max], x[gauss_max]; - - for (unsigned n=1; n<=gkyl_gauss_max; ++n) { + + for (unsigned n = 1; n <= gkyl_gauss_max; ++n) { // use the generic routine to get the ordinates and weights gkyl_gauleg(-1, 1, &x[0], &w[0], n); // compare with pre-computed values const double *xp = gkyl_gauss_ordinates[n]; const double *wp = gkyl_gauss_weights[n]; - - for (unsigned i=0; i #include -void -test_mat_base_ho() +void test_mat_base_ho() { struct gkyl_mat *m = gkyl_mat_new(10, 20, 0.25); - TEST_CHECK( 10 == m->nr ); - TEST_CHECK( 20 == m->nc ); + TEST_CHECK(10 == m->nr); + TEST_CHECK(20 == m->nc); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) - TEST_CHECK ( 0.25 == gkyl_mat_get(m, i, j) ); + for (size_t j = 0; j < m->nc; ++j) { + for (size_t i = 0; i < m->nr; ++i) { + TEST_CHECK(0.25 == gkyl_mat_get(m, i, j)); + } + } gkyl_mat_clear(m, 0.1); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) - TEST_CHECK ( 0.1 == gkyl_mat_get(m, i, j) ); + for (size_t j = 0; j < m->nc; ++j) { + for (size_t i = 0; i < m->nr; ++i) { + TEST_CHECK(0.1 == gkyl_mat_get(m, i, j)); + } + } size_t count = 0; - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < m->nc; ++j) { + for (size_t i = 0; i < m->nr; ++i) { gkyl_mat_set(m, i, j, count++); + } + } count = 0; - for (size_t j=0; jnc; ++j) { - const double* col = gkyl_mat_get_ccol(m, j); - for (size_t i=0; inr; ++i) - TEST_CHECK( col[i] == count++ ); + for (size_t j = 0; j < m->nc; ++j) { + const double *col = gkyl_mat_get_ccol(m, j); + for (size_t i = 0; i < m->nr; ++i) { + TEST_CHECK(col[i] == count++); + } } count = 0; - for (size_t i=0; inr*m->nc; ++i) - TEST_CHECK( m->data[i] == i ); + for (size_t i = 0; i < m->nr * m->nc; ++i) { + TEST_CHECK(m->data[i] == i); + } gkyl_mat_diag(m, 1.0); - - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) - TEST_CHECK( gkyl_mat_get(m, i, j) == ( i==j ? 1.0 : 0.0 ) ); + + for (size_t j = 0; j < m->nc; ++j) { + for (size_t i = 0; i < m->nr; ++i) { + TEST_CHECK(gkyl_mat_get(m, i, j) == (i == j ? 1.0 : 0.0)); + } + } struct gkyl_mat *m2 = gkyl_mat_clone(m); - TEST_CHECK( m2->nr == m->nr ); - TEST_CHECK( m2->nc == m->nc ); + TEST_CHECK(m2->nr == m->nr); + TEST_CHECK(m2->nc == m->nc); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) - TEST_CHECK( gkyl_mat_get(m, i, j) == gkyl_mat_get(m2, i, j) ); + for (size_t j = 0; j < m->nc; ++j) { + for (size_t i = 0; i < m->nr; ++i) { + TEST_CHECK(gkyl_mat_get(m, i, j) == gkyl_mat_get(m2, i, j)); + } + } double old = gkyl_mat_get(m, 3, 4); double inc = -123.0; gkyl_mat_inc(m, 3, 4, inc); - TEST_CHECK( gkyl_mat_get(m, 3, 4) == old + inc ); + TEST_CHECK(gkyl_mat_get(m, 3, 4) == old + inc); gkyl_mat_release(m); gkyl_mat_release(m2); } -void -test_mat_mm_op_ho() +void test_mat_mm_op_ho() { struct gkyl_mat *A = gkyl_mat_new(2, 3, 0.0); struct gkyl_mat *B = gkyl_mat_new(3, 2, 0.0); @@ -72,52 +82,53 @@ test_mat_mm_op_ho() double val = 1.0; // A : matrix( [1,2,3], [4,5,6] ); - for (int i=0; inr; ++i) - for (int j=0; jnc; ++j) { - gkyl_mat_set(A,i,j,val); + for (int i = 0; i < A->nr; ++i) { + for (int j = 0; j < A->nc; ++j) { + gkyl_mat_set(A, i, j, val); val += 1.0; } + } // B : matrix( [7,8], [9,10], [11,12] ); - for (int i=0; inr; ++i) - for (int j=0; jnc; ++j) { - gkyl_mat_set(B,i,j,val); + for (int i = 0; i < B->nr; ++i) { + for (int j = 0; j < B->nc; ++j) { + gkyl_mat_set(B, i, j, val); val += 1.0; } + } // C = 0.5*A*B + 0.0*C gkyl_mat_mm(0.5, 0.0, GKYL_NO_TRANS, A, GKYL_NO_TRANS, B, C, false); // C : matrix( [29.0, 32.0], [69.5, 77.0] ) - TEST_CHECK( gkyl_mat_get(C, 0, 0) == 29.0 ); - TEST_CHECK( gkyl_mat_get(C, 0, 1) == 32.0 ); - TEST_CHECK( gkyl_mat_get(C, 1, 0) == 69.5 ); - TEST_CHECK( gkyl_mat_get(C, 1, 1) == 77.0 ); + TEST_CHECK(gkyl_mat_get(C, 0, 0) == 29.0); + TEST_CHECK(gkyl_mat_get(C, 0, 1) == 32.0); + TEST_CHECK(gkyl_mat_get(C, 1, 0) == 69.5); + TEST_CHECK(gkyl_mat_get(C, 1, 1) == 77.0); // D = 0.5*A'*B' gkyl_mat_mm(0.5, 0.0, GKYL_TRANS, A, GKYL_TRANS, B, D, false); // D : matrix( [ 19.5 24.5 29.5 ], [ 27.0 34.0 41.0 ], [ 34.5 43.5 52.5 ] ) - TEST_CHECK( gkyl_mat_get(D, 0, 0) == 19.5 ); - TEST_CHECK( gkyl_mat_get(D, 0, 1) == 24.5 ); - TEST_CHECK( gkyl_mat_get(D, 0, 2) == 29.5 ); - - TEST_CHECK( gkyl_mat_get(D, 1, 0) == 27.0 ); - TEST_CHECK( gkyl_mat_get(D, 1, 1) == 34.0 ); - TEST_CHECK( gkyl_mat_get(D, 1, 2) == 41.0 ); - - TEST_CHECK( gkyl_mat_get(D, 2, 0) == 34.5 ); - TEST_CHECK( gkyl_mat_get(D, 2, 1) == 43.5 ); - TEST_CHECK( gkyl_mat_get(D, 2, 2) == 52.5 ); - + TEST_CHECK(gkyl_mat_get(D, 0, 0) == 19.5); + TEST_CHECK(gkyl_mat_get(D, 0, 1) == 24.5); + TEST_CHECK(gkyl_mat_get(D, 0, 2) == 29.5); + + TEST_CHECK(gkyl_mat_get(D, 1, 0) == 27.0); + TEST_CHECK(gkyl_mat_get(D, 1, 1) == 34.0); + TEST_CHECK(gkyl_mat_get(D, 1, 2) == 41.0); + + TEST_CHECK(gkyl_mat_get(D, 2, 0) == 34.5); + TEST_CHECK(gkyl_mat_get(D, 2, 1) == 43.5); + TEST_CHECK(gkyl_mat_get(D, 2, 2) == 52.5); + gkyl_mat_release(A); gkyl_mat_release(B); gkyl_mat_release(C); gkyl_mat_release(D); } -void -test_mat_linsolve_ho() +void test_mat_linsolve_ho() { struct gkyl_mat *A = gkyl_mat_new(3, 3, 0.0); struct gkyl_mat *x = gkyl_mat_new(3, 1, 0.0); @@ -125,12 +136,13 @@ test_mat_linsolve_ho() double val = 1.0; // A : matrix( [1,2,3], [4,5,6], [7,8,10] ); - for (int i=0; inr; ++i) - for (int j=0; jnc; ++j) { - gkyl_mat_set(A,i,j,val); + for (int i = 0; i < A->nr; ++i) { + for (int j = 0; j < A->nc; ++j) { + gkyl_mat_set(A, i, j, val); val += 1.0; } - gkyl_mat_set(A,2,2,10.0); // ensures determinant is not zero + } + gkyl_mat_set(A, 2, 2, 10.0); // ensures determinant is not zero struct gkyl_mat *AA = gkyl_mat_clone(A); //gkyl_mat_show("A", stdout, A); @@ -144,15 +156,15 @@ test_mat_linsolve_ho() // solve linear system: sol : matrix( [-1, 1, 0] ) bool status = gkyl_mat_linsolve_lu(A, x, gkyl_mem_buff_data(ipiv)); - TEST_CHECK( status ); + TEST_CHECK(status); //gkyl_mat_show("A", stdout, A); //gkyl_mat_show("x", stdout, x); - TEST_CHECK( gkyl_compare(gkyl_mat_get(x,0,0), -1.0, 1e-15) ); - TEST_CHECK( gkyl_compare(gkyl_mat_get(x,1,0), 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare(gkyl_mat_get(x,2,0), 0.0, 1e-15) ); - + TEST_CHECK(gkyl_compare(gkyl_mat_get(x, 0, 0), -1.0, 1e-15)); + TEST_CHECK(gkyl_compare(gkyl_mat_get(x, 1, 0), 1.0, 1e-15)); + TEST_CHECK(gkyl_compare(gkyl_mat_get(x, 2, 0), 0.0, 1e-15)); + // trivial extension of the test above; rhs is two column vectors struct gkyl_mat *xx = gkyl_mat_new(3, 2, 1.0); gkyl_mat_set(xx, 0, 1, 2.0); @@ -160,12 +172,12 @@ test_mat_linsolve_ho() gkyl_mat_set(xx, 2, 1, 2.0); status = gkyl_mat_linsolve_lu(AA, xx, gkyl_mem_buff_data(ipiv)); - TEST_CHECK( gkyl_compare(gkyl_mat_get(xx,0,0), -1.0, 1e-15) ); - TEST_CHECK( gkyl_compare(gkyl_mat_get(xx,1,0), 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare(gkyl_mat_get(xx,2,0), 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare(gkyl_mat_get(xx,0,1), -2.0, 1e-15) ); - TEST_CHECK( gkyl_compare(gkyl_mat_get(xx,1,1), 2.0, 1e-15) ); - TEST_CHECK( gkyl_compare(gkyl_mat_get(xx,2,1), 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare(gkyl_mat_get(xx, 0, 0), -1.0, 1e-15)); + TEST_CHECK(gkyl_compare(gkyl_mat_get(xx, 1, 0), 1.0, 1e-15)); + TEST_CHECK(gkyl_compare(gkyl_mat_get(xx, 2, 0), 0.0, 1e-15)); + TEST_CHECK(gkyl_compare(gkyl_mat_get(xx, 0, 1), -2.0, 1e-15)); + TEST_CHECK(gkyl_compare(gkyl_mat_get(xx, 1, 1), 2.0, 1e-15)); + TEST_CHECK(gkyl_compare(gkyl_mat_get(xx, 2, 1), 0.0, 1e-15)); gkyl_mat_release(AA); gkyl_mat_release(xx); @@ -174,83 +186,92 @@ test_mat_linsolve_ho() gkyl_mem_buff_release(ipiv); } -void -test_nmat_base_ho() +void test_nmat_base_ho() { // 5 matrices with shape 10x20 struct gkyl_nmat *nmat = gkyl_nmat_new(5, 10, 20); - TEST_CHECK( false == gkyl_nmat_is_cu_dev(nmat) ); + TEST_CHECK(false == gkyl_nmat_is_cu_dev(nmat)); - TEST_CHECK( 5 == nmat->num ); - TEST_CHECK( 10 == nmat->nr ); - TEST_CHECK( 20 == nmat->nc ); + TEST_CHECK(5 == nmat->num); + TEST_CHECK(10 == nmat->nr); + TEST_CHECK(20 == nmat->nc); struct gkyl_mat m = gkyl_nmat_get(nmat, 0); - TEST_CHECK( 10 == m.nr ); - TEST_CHECK( 20 == m.nc ); + TEST_CHECK(10 == m.nr); + TEST_CHECK(20 == m.nc); - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat, n); - - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) - gkyl_mat_set(&m, i, j, n*0.5); + + for (size_t j = 0; j < nmat->nc; ++j) { + for (size_t i = 0; i < nmat->nr; ++i) { + gkyl_mat_set(&m, i, j, n * 0.5); + } + } } - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat, n); - - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) - TEST_CHECK ( n*0.5 == gkyl_mat_get(&m, i, j) ); - } - for (size_t n=0; nnum; ++n) - for (size_t i=0; inr*nmat->nc; ++i) - TEST_CHECK( nmat->mptr[n][i] == n*0.5 ); + for (size_t j = 0; j < nmat->nc; ++j) { + for (size_t i = 0; i < nmat->nr; ++i) { + TEST_CHECK(n * 0.5 == gkyl_mat_get(&m, i, j)); + } + } + } + + for (size_t n = 0; n < nmat->num; ++n) { + for (size_t i = 0; i < nmat->nr * nmat->nc; ++i) { + TEST_CHECK(nmat->mptr[n][i] == n * 0.5); + } + } // copy matrix struct gkyl_nmat *ncpy = gkyl_nmat_new(nmat->num, nmat->nr, nmat->nc); gkyl_nmat_copy(ncpy, nmat); - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < ncpy->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(ncpy, n); - - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) - TEST_CHECK ( n*0.5 == gkyl_mat_get(&m, i, j) ); - } - for (size_t n=0; nnum; ++n) - for (size_t i=0; inr*ncpy->nc; ++i) - TEST_CHECK( ncpy->mptr[n][i] == n*0.5 ); + for (size_t j = 0; j < ncpy->nc; ++j) { + for (size_t i = 0; i < ncpy->nr; ++i) { + TEST_CHECK(n * 0.5 == gkyl_mat_get(&m, i, j)); + } + } + } + + for (size_t n = 0; n < ncpy->num; ++n) { + for (size_t i = 0; i < ncpy->nr * ncpy->nc; ++i) { + TEST_CHECK(ncpy->mptr[n][i] == n * 0.5); + } + } gkyl_nmat_release(nmat); gkyl_nmat_release(ncpy); } -void -test_nmat_linsolve_(bool pre_alloc) +void test_nmat_linsolve_(bool pre_alloc) { struct gkyl_nmat *As = gkyl_nmat_new(5, 3, 3); struct gkyl_nmat *xs = gkyl_nmat_new(5, 3, 1); - for (int n=0; nnum; ++n) { + for (int n = 0; n < As->num; ++n) { struct gkyl_mat A = gkyl_nmat_get(As, n); - + double val = 1.0; // A : matrix( [1,2,3], [4,5,6], [7,8,10] ); - for (int i=0; inum; ++n) { + for (size_t n = 0; n < As->num; ++n) { struct gkyl_mat x = gkyl_nmat_get(xs, n); gkyl_mat_clear(&x, 1.0); } @@ -262,53 +283,59 @@ test_nmat_linsolve_(bool pre_alloc) gkyl_nmat_mem *mem = gkyl_nmat_linsolve_lu_new(As->num, As->nr); status = gkyl_nmat_linsolve_lu_pa(mem, As, xs); gkyl_nmat_linsolve_lu_release(mem); - } - else { + } else { status = gkyl_nmat_linsolve_lu(As, xs); } - TEST_CHECK( status ); + TEST_CHECK(status); //gkyl_mat_show("A", stdout, A); //gkyl_mat_show("x", stdout, x); - for (int n=0; nnum; ++n) { + for (int n = 0; n < xs->num; ++n) { struct gkyl_mat x = gkyl_nmat_get(xs, n); - TEST_CHECK( gkyl_compare(gkyl_mat_get(&x,0,0), -1.0, 1e-15) ); - TEST_CHECK( gkyl_compare(gkyl_mat_get(&x,1,0), 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare(gkyl_mat_get(&x,2,0), 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare(gkyl_mat_get(&x, 0, 0), -1.0, 1e-15)); + TEST_CHECK(gkyl_compare(gkyl_mat_get(&x, 1, 0), 1.0, 1e-15)); + TEST_CHECK(gkyl_compare(gkyl_mat_get(&x, 2, 0), 0.0, 1e-15)); } - + gkyl_nmat_release(As); gkyl_nmat_release(xs); } -void test_nmat_linsolve_ho() { test_nmat_linsolve_(false); } -void test_nmat_linsolve_pa_ho() { test_nmat_linsolve_(true); } +void test_nmat_linsolve_ho() +{ + test_nmat_linsolve_(false); +} +void test_nmat_linsolve_pa_ho() +{ + test_nmat_linsolve_(true); +} #ifdef GKYL_HAVE_CUDA -void -test_nmat_base_dev() +void test_nmat_base_dev() { // 5 matrices with shape 10x20 struct gkyl_nmat *nmat = gkyl_nmat_cu_dev_new(5, 10, 20); - TEST_CHECK( 5 == nmat->num ); - TEST_CHECK( 10 == nmat->nr ); - TEST_CHECK( 20 == nmat->nc ); + TEST_CHECK(5 == nmat->num); + TEST_CHECK(10 == nmat->nr); + TEST_CHECK(20 == nmat->nc); - TEST_CHECK( gkyl_nmat_is_cu_dev(nmat) == true ); + TEST_CHECK(gkyl_nmat_is_cu_dev(nmat) == true); // create host-side matrix struct gkyl_nmat *h1 = gkyl_nmat_new(5, 10, 20); - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < h1->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(h1, n); - - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) - gkyl_mat_set(&m, i, j, n*0.5); + + for (size_t j = 0; j < h1->nc; ++j) { + for (size_t i = 0; i < h1->nr; ++i) { + gkyl_mat_set(&m, i, j, n * 0.5); + } + } } // copy to device @@ -319,13 +346,15 @@ test_nmat_base_dev() gkyl_nmat_copy(h2, nmat); // check - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < h1->num; ++n) { struct gkyl_mat m1 = gkyl_nmat_get(h1, n); struct gkyl_mat m2 = gkyl_nmat_get(h2, n); - - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) - TEST_CHECK( gkyl_mat_get(&m1, i, j) == gkyl_mat_get(&m2, i, j) ); + + for (size_t j = 0; j < h1->nc; ++j) { + for (size_t i = 0; i < h1->nr; ++i) { + TEST_CHECK(gkyl_mat_get(&m1, i, j) == gkyl_mat_get(&m2, i, j)); + } + } } gkyl_nmat_release(nmat); @@ -333,27 +362,27 @@ test_nmat_base_dev() gkyl_nmat_release(h2); } -void -test_cu_nmat_linsolve_(bool pre_alloc) +void test_cu_nmat_linsolve_(bool pre_alloc) { struct gkyl_nmat *As = gkyl_nmat_new(5, 3, 3); struct gkyl_nmat *xs = gkyl_nmat_new(5, 3, 1); - for (int n=0; nnum; ++n) { + for (int n = 0; n < As->num; ++n) { struct gkyl_mat A = gkyl_nmat_get(As, n); - + double val = 1.0; // A : matrix( [1,2,3], [4,5,6], [7,8,10] ); - for (int i=0; inum; ++n) { + for (size_t n = 0; n < As->num; ++n) { struct gkyl_mat x = gkyl_nmat_get(xs, n); gkyl_mat_clear(&x, 1.0); } @@ -372,25 +401,24 @@ test_cu_nmat_linsolve_(bool pre_alloc) gkyl_nmat_mem *mem = gkyl_nmat_linsolve_lu_cu_dev_new(As->num, As->nr); status = gkyl_nmat_linsolve_lu_pa(mem, As_d, xs_d); gkyl_nmat_linsolve_lu_release(mem); - } - else { + } else { status = gkyl_nmat_linsolve_lu(As_d, xs_d); } - TEST_CHECK( status ); + TEST_CHECK(status); // copy solution back gkyl_nmat_copy(As, As_d); gkyl_nmat_copy(xs, xs_d); - for (int n=0; nnum; ++n) { + for (int n = 0; n < xs->num; ++n) { struct gkyl_mat x = gkyl_nmat_get(xs, n); - TEST_CHECK( gkyl_compare(gkyl_mat_get(&x,0,0), -1.0, 1e-15) ); - TEST_CHECK( gkyl_compare(gkyl_mat_get(&x,1,0), 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare(gkyl_mat_get(&x,2,0), 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare(gkyl_mat_get(&x, 0, 0), -1.0, 1e-15)); + TEST_CHECK(gkyl_compare(gkyl_mat_get(&x, 1, 0), 1.0, 1e-15)); + TEST_CHECK(gkyl_compare(gkyl_mat_get(&x, 2, 0), 0.0, 1e-15)); } - + gkyl_nmat_release(As); gkyl_nmat_release(xs); @@ -398,22 +426,29 @@ test_cu_nmat_linsolve_(bool pre_alloc) gkyl_nmat_release(xs_d); } -void test_nmat_linsolve_dev() { test_cu_nmat_linsolve_(false); } -void test_nmat_linsolve_pa_dev() { test_cu_nmat_linsolve_(true); } +void test_nmat_linsolve_dev() +{ + test_cu_nmat_linsolve_(false); +} +void test_nmat_linsolve_pa_dev() +{ + test_cu_nmat_linsolve_(true); +} #endif void test_mat_mv_ho() { - struct gkyl_mat *A = gkyl_mat_new(4, 4, 1); struct gkyl_mat *x = gkyl_mat_new(4, 1, 2); struct gkyl_mat *y = gkyl_mat_new(4, 1, 1); // y = 1.0*A*x + 0.0*C gkyl_mat_mv(1.0, 0.0, GKYL_NO_TRANS, A, x, y); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) - TEST_CHECK ( 8 == gkyl_mat_get(y, i, j) ); + for (size_t j = 0; j < y->nc; ++j) { + for (size_t i = 0; i < y->nr; ++i) { + TEST_CHECK(8 == gkyl_mat_get(y, i, j)); + } + } gkyl_mat_release(A); gkyl_mat_release(x); @@ -422,7 +457,6 @@ void test_mat_mv_ho() void test_nmat_mv_ho() { - // n_do matrices with shape 4x4 int n_do = 3; struct gkyl_nmat *nmat_A = gkyl_nmat_new(n_do, 4, 4); @@ -430,27 +464,33 @@ void test_nmat_mv_ho() struct gkyl_nmat *nmat_y = gkyl_nmat_new(n_do, 4, 1); // fill each A matrix with its number - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_A->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_A, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_A->nc; ++j) { + for (size_t i = 0; i < nmat_A->nr; ++i) { gkyl_mat_set(&m, i, j, n); + } + } } // fill each x vecotr with ones - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_x->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_x, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_x->nc; ++j) { + for (size_t i = 0; i < nmat_x->nr; ++i) { gkyl_mat_set(&m, i, j, 1); + } + } } // fill each y matrix with 0 - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_y->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_y, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_y->nc; ++j) { + for (size_t i = 0; i < nmat_y->nr; ++i) { gkyl_mat_set(&m, i, j, 0); + } + } } enum gkyl_mat_trans transa = GKYL_NO_TRANS; @@ -459,14 +499,15 @@ void test_nmat_mv_ho() gkyl_nmat_mv(alpha, beta, transa, nmat_A, nmat_x, nmat_y); - // check the expected result - for (size_t n=0; nnum; ++n) { - struct gkyl_mat y = gkyl_nmat_get(nmat_y,n); - double expected = 4*n; - for (size_t j=0; jnum; ++n) { + struct gkyl_mat y = gkyl_nmat_get(nmat_y, n); + double expected = 4 * n; + for (size_t j = 0; j < y.nc; ++j) { + for (size_t i = 0; i < y.nr; ++i) { + TEST_CHECK(expected == gkyl_mat_get(&y, i, j)); + } + } } gkyl_nmat_release(nmat_A); @@ -476,34 +517,39 @@ void test_nmat_mv_ho() void test_nmat_mm_ho() { - int n_do = 3; struct gkyl_nmat *nmat_A = gkyl_nmat_new(n_do, 4, 3); struct gkyl_nmat *nmat_x = gkyl_nmat_new(n_do, 3, 2); struct gkyl_nmat *nmat_y = gkyl_nmat_new(n_do, 4, 2); // fill each A matrix with its number - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_A->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_A, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_A->nc; ++j) { + for (size_t i = 0; i < nmat_A->nr; ++i) { gkyl_mat_set(&m, i, j, n); + } + } } // fill each x vector with ones - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_x->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_x, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_x->nc; ++j) { + for (size_t i = 0; i < nmat_x->nr; ++i) { gkyl_mat_set(&m, i, j, 1); + } + } } // fill each y matrix with 0 - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_y->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_y, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_y->nc; ++j) { + for (size_t i = 0; i < nmat_y->nr; ++i) { gkyl_mat_set(&m, i, j, 0); + } + } } enum gkyl_mat_trans transa = GKYL_NO_TRANS; @@ -513,36 +559,35 @@ void test_nmat_mm_ho() gkyl_nmat_mm(alpha, beta, transa, nmat_A, transb, nmat_x, nmat_y); - // check the expected result - for (size_t n=0; nnum; ++n) { - struct gkyl_mat y = gkyl_nmat_get(nmat_y,n); - double expected = 3*n; - for (size_t j=0; jnum; ++n) { + struct gkyl_mat y = gkyl_nmat_get(nmat_y, n); + double expected = 3 * n; + for (size_t j = 0; j < y.nc; ++j) { + for (size_t i = 0; i < y.nr; ++i) { + TEST_CHECK(expected == gkyl_mat_get(&y, i, j)); + } + } } gkyl_nmat_release(nmat_A); gkyl_nmat_release(nmat_x); - gkyl_nmat_release(nmat_y); + gkyl_nmat_release(nmat_y); } - void test_mat_mm_arrays_ho() { - struct gkyl_mat_mm_array_mem *ctest_prob_mem; - ctest_prob_mem = gkyl_mat_mm_array_mem_new(4, 3, 1.0, 0.0, - GKYL_NO_TRANS, GKYL_NO_TRANS, false); + struct gkyl_mat_mm_array_mem *ctest_prob_mem; + ctest_prob_mem = gkyl_mat_mm_array_mem_new(4, 3, 1.0, 0.0, GKYL_NO_TRANS, GKYL_NO_TRANS, false); struct gkyl_mat *mat_A = ctest_prob_mem->A; struct gkyl_array *array_x = gkyl_array_new(GKYL_DOUBLE, 3, 2); struct gkyl_array *array_y = gkyl_array_new(GKYL_DOUBLE, 4, 2); // fill each A matrix with its number - for (size_t j=0; jnc; ++j){ - for (size_t i=0; inr; ++i){ - double a_val = i*3 + j; + for (size_t j = 0; j < mat_A->nc; ++j) { + for (size_t i = 0; i < mat_A->nr; ++i) { + double a_val = i * 3 + j; gkyl_mat_set(mat_A, i, j, a_val); double actual = gkyl_mat_get(mat_A, i, j); //printf("A(m=%d,n=%d): %1.2e,\n", i, j, actual); @@ -550,48 +595,45 @@ void test_mat_mm_arrays_ho() } // fill each x vector with ones - for (size_t j=0; jsize; ++j){ - double *x = gkyl_array_fetch(array_x,j); - for (size_t i=0; incomp; ++i){ - x[i] = i*2 + j; + for (size_t j = 0; j < array_x->size; ++j) { + double *x = gkyl_array_fetch(array_x, j); + for (size_t i = 0; i < array_x->ncomp; ++i) { + x[i] = i * 2 + j; //printf("B(m=%d,n=%d): %1.2e,\n", i, j, x[i]); } - } + } - for (size_t j=0; jsize; ++j){ - double *y = gkyl_array_fetch(array_y,j); - for (size_t i=0; incomp; ++i){ + for (size_t j = 0; j < array_y->size; ++j) { + double *y = gkyl_array_fetch(array_y, j); + for (size_t i = 0; i < array_y->ncomp; ++i) { y[i] = 0.0; //printf("C(m=%d,n=%d): %1.2e,\n", i, j, 0.0); } - } + } // Preform the matrix multiply gkyl_mat_mm_array(ctest_prob_mem, array_x, array_y); // check the expected result double expected_array[8] = {10.0, 13.0, 28.0, 40.0, 46.0, 67.0, 64.0, 94.0}; - for (size_t j=0; jsize; ++j){ - double *y = gkyl_array_fetch(array_y,j); - for (size_t i=0; incomp; ++i){ + for (size_t j = 0; j < array_y->size; ++j) { + double *y = gkyl_array_fetch(array_y, j); + for (size_t i = 0; i < array_y->ncomp; ++i) { double actual = y[i]; - double expected = expected_array[i*2 + j]; + double expected = expected_array[i * 2 + j]; //printf("expected: %1.2e, actual: %1.2e\n", expected, actual); - TEST_CHECK ( expected == actual ); + TEST_CHECK(expected == actual); } } gkyl_array_release(array_x); gkyl_array_release(array_y); gkyl_mat_mm_array_mem_release(ctest_prob_mem); - } - #ifdef GKYL_HAVE_CUDA void test_nmat_mv_dev() { - // n_do matrices with shape 4x4 int n_do = 3; struct gkyl_nmat *nmat_A = gkyl_nmat_new(n_do, 4, 4); @@ -603,27 +645,33 @@ void test_nmat_mv_dev() struct gkyl_nmat *nmat_ycu = gkyl_nmat_cu_dev_new(n_do, 4, 1); // fill each A matrix with its number - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_A->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_A, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_A->nc; ++j) { + for (size_t i = 0; i < nmat_A->nr; ++i) { gkyl_mat_set(&m, i, j, n); + } + } } // fill each x vecotr with ones - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_x->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_x, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_x->nc; ++j) { + for (size_t i = 0; i < nmat_x->nr; ++i) { gkyl_mat_set(&m, i, j, 1); + } + } } // fill each y matrix with 0 - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_y->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_y, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_y->nc; ++j) { + for (size_t i = 0; i < nmat_y->nr; ++i) { gkyl_mat_set(&m, i, j, 0); + } + } } enum gkyl_mat_trans transa = GKYL_NO_TRANS; @@ -631,7 +679,6 @@ void test_nmat_mv_dev() double alpha = 1.0; double beta = 0.0; - // copy to device gkyl_nmat_copy(nmat_Acu, nmat_A); gkyl_nmat_copy(nmat_xcu, nmat_x); @@ -644,15 +691,14 @@ void test_nmat_mv_dev() gkyl_nmat_copy(nmat_x, nmat_xcu); gkyl_nmat_copy(nmat_y, nmat_ycu); - // check the expected result - for (size_t n=0; nnum; ++n) { - struct gkyl_mat y = gkyl_nmat_get(nmat_y,n); - double expected = 4*n; - for (size_t j=0; jnum; ++n) { + struct gkyl_mat y = gkyl_nmat_get(nmat_y, n); + double expected = 4 * n; + for (size_t j = 0; j < y.nc; ++j) { + for (size_t i = 0; i < y.nr; ++i) { double actual = gkyl_mat_get(&y, i, j); - TEST_CHECK ( expected == actual ); + TEST_CHECK(expected == actual); } } } @@ -662,14 +708,10 @@ void test_nmat_mv_dev() gkyl_nmat_release(nmat_Acu); gkyl_nmat_release(nmat_xcu); gkyl_nmat_release(nmat_ycu); - - } - void test_mat_mm_dev() { - struct gkyl_mat *mat_A = gkyl_mat_new(4, 3, 0); struct gkyl_mat *mat_x = gkyl_mat_new(3, 2, 0); struct gkyl_mat *mat_y = gkyl_mat_new(4, 2, 0); @@ -679,27 +721,31 @@ void test_mat_mm_dev() struct gkyl_mat *mat_ycu = gkyl_mat_cu_dev_new(4, 2); // fill each A matrix with its number - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < mat_A->nc; ++j) { + for (size_t i = 0; i < mat_A->nr; ++i) { gkyl_mat_set(mat_A, i, j, 1); + } + } // fill each x vecotr with ones - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < mat_x->nc; ++j) { + for (size_t i = 0; i < mat_x->nr; ++i) { gkyl_mat_set(mat_x, i, j, 1); - + } + } // fill each y matrix with 0 - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < mat_y->nc; ++j) { + for (size_t i = 0; i < mat_y->nr; ++i) { gkyl_mat_set(mat_y, i, j, 0); + } + } enum gkyl_mat_trans transa = GKYL_NO_TRANS; enum gkyl_mat_trans transb = GKYL_NO_TRANS; double alpha = 1.0; double beta = 0.0; - // copy to device gkyl_mat_copy(mat_Acu, mat_A); gkyl_mat_copy(mat_xcu, mat_x); @@ -712,13 +758,12 @@ void test_mat_mm_dev() gkyl_mat_copy(mat_x, mat_xcu); gkyl_mat_copy(mat_y, mat_ycu); - // check the expected result double expected = 3; - for (size_t j=0; jnc; ++j){ - for (size_t i=0; inr; ++i){ + for (size_t j = 0; j < mat_y->nc; ++j) { + for (size_t i = 0; i < mat_y->nr; ++i) { double actual = gkyl_mat_get(mat_y, i, j); - TEST_CHECK ( expected == actual ); + TEST_CHECK(expected == actual); } } gkyl_mat_release(mat_A); @@ -727,13 +772,10 @@ void test_mat_mm_dev() gkyl_mat_release(mat_Acu); gkyl_mat_release(mat_xcu); gkyl_mat_release(mat_ycu); - - } void test_nmat_mm_dev() { - int n_do = 3; struct gkyl_nmat *nmat_A = gkyl_nmat_new(n_do, 4, 3); struct gkyl_nmat *nmat_x = gkyl_nmat_new(n_do, 3, 2); @@ -744,34 +786,39 @@ void test_nmat_mm_dev() struct gkyl_nmat *nmat_ycu = gkyl_nmat_cu_dev_new(n_do, 4, 2); // fill each A matrix with its number - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_A->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_A, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_A->nc; ++j) { + for (size_t i = 0; i < nmat_A->nr; ++i) { gkyl_mat_set(&m, i, j, n); + } + } } // fill each x vecotr with ones - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_x->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_x, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_x->nc; ++j) { + for (size_t i = 0; i < nmat_x->nr; ++i) { gkyl_mat_set(&m, i, j, 1); + } + } } // fill each y matrix with 0 - for (size_t n=0; nnum; ++n) { + for (size_t n = 0; n < nmat_y->num; ++n) { struct gkyl_mat m = gkyl_nmat_get(nmat_y, n); - for (size_t j=0; jnc; ++j) - for (size_t i=0; inr; ++i) + for (size_t j = 0; j < nmat_y->nc; ++j) { + for (size_t i = 0; i < nmat_y->nr; ++i) { gkyl_mat_set(&m, i, j, 0); + } + } } enum gkyl_mat_trans transa = GKYL_NO_TRANS; double alpha = 1.0; double beta = 0.0; - // copy to device gkyl_nmat_copy(nmat_Acu, nmat_A); gkyl_nmat_copy(nmat_xcu, nmat_x); @@ -784,15 +831,14 @@ void test_nmat_mm_dev() gkyl_nmat_copy(nmat_x, nmat_xcu); gkyl_nmat_copy(nmat_y, nmat_ycu); - // check the expected result - for (size_t n=0; nnum; ++n) { - struct gkyl_mat y = gkyl_nmat_get(nmat_y,n); - double expected = 3*n; - for (size_t j=0; jnum; ++n) { + struct gkyl_mat y = gkyl_nmat_get(nmat_y, n); + double expected = 3 * n; + for (size_t j = 0; j < y.nc; ++j) { + for (size_t i = 0; i < y.nr; ++i) { double actual = gkyl_mat_get(&y, i, j); - TEST_CHECK ( expected == actual ); + TEST_CHECK(expected == actual); } } } @@ -802,18 +848,14 @@ void test_nmat_mm_dev() gkyl_nmat_release(nmat_Acu); gkyl_nmat_release(nmat_xcu); gkyl_nmat_release(nmat_ycu); - - } - void test_mat_mm_arrays_dev() { - struct gkyl_mat_mm_array_mem *ctest_prob_mem_ho, *ctest_prob_mem_cu; - ctest_prob_mem_ho = gkyl_mat_mm_array_mem_new(4, 3, 1.0, 0.0, - GKYL_NO_TRANS, GKYL_NO_TRANS, false); - ctest_prob_mem_cu = gkyl_mat_mm_array_mem_new(4, 3, 1.0, 0.0, - GKYL_NO_TRANS, GKYL_NO_TRANS, true); + struct gkyl_mat_mm_array_mem *ctest_prob_mem_ho, *ctest_prob_mem_cu; + ctest_prob_mem_ho = + gkyl_mat_mm_array_mem_new(4, 3, 1.0, 0.0, GKYL_NO_TRANS, GKYL_NO_TRANS, false); + ctest_prob_mem_cu = gkyl_mat_mm_array_mem_new(4, 3, 1.0, 0.0, GKYL_NO_TRANS, GKYL_NO_TRANS, true); struct gkyl_mat *mat_A = ctest_prob_mem_ho->A; struct gkyl_array *array_x = gkyl_array_new(GKYL_DOUBLE, 3, 2); @@ -824,9 +866,9 @@ void test_mat_mm_arrays_dev() struct gkyl_array *array_ycu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 4, 2); // fill each A matrix with its number - for (size_t j=0; jnc; ++j){ - for (size_t i=0; inr; ++i){ - double a_val = i*3 + j; + for (size_t j = 0; j < mat_A->nc; ++j) { + for (size_t i = 0; i < mat_A->nr; ++i) { + double a_val = i * 3 + j; gkyl_mat_set(mat_A, i, j, a_val); double actual = gkyl_mat_get(mat_A, i, j); //printf("A(m=%d,n=%d): %1.2e,\n", i, j, actual); @@ -834,21 +876,21 @@ void test_mat_mm_arrays_dev() } // fill each x vector with ones - for (size_t j=0; jsize; ++j){ - double *x = gkyl_array_fetch(array_x,j); - for (size_t i=0; incomp; ++i){ - x[i] = i*2 + j; + for (size_t j = 0; j < array_x->size; ++j) { + double *x = gkyl_array_fetch(array_x, j); + for (size_t i = 0; i < array_x->ncomp; ++i) { + x[i] = i * 2 + j; //printf("B(m=%d,n=%d): %1.2e,\n", i, j, x[i]); } - } + } - for (size_t j=0; jsize; ++j){ - double *y = gkyl_array_fetch(array_y,j); - for (size_t i=0; incomp; ++i){ + for (size_t j = 0; j < array_y->size; ++j) { + double *y = gkyl_array_fetch(array_y, j); + for (size_t i = 0; i < array_y->ncomp; ++i) { y[i] = 0.0; //printf("C(m=%d,n=%d): %1.2e,\n", i, j, 0.0); } - } + } // copy to device gkyl_mat_copy(mat_Acu, mat_A); @@ -862,16 +904,15 @@ void test_mat_mm_arrays_dev() gkyl_array_copy(array_x, array_xcu); gkyl_array_copy(array_y, array_ycu); - // check the expected result double expected_array[8] = {10.0, 13.0, 28.0, 40.0, 46.0, 67.0, 64.0, 94.0}; - for (size_t j=0; jsize; ++j){ - double *y = gkyl_array_fetch(array_y,j); - for (size_t i=0; incomp; ++i){ + for (size_t j = 0; j < array_y->size; ++j) { + double *y = gkyl_array_fetch(array_y, j); + for (size_t i = 0; i < array_y->ncomp; ++i) { double actual = y[i]; - double expected = expected_array[i*2 + j]; + double expected = expected_array[i * 2 + j]; //printf("expected: %1.2e, actual: %1.2e\n", expected, actual); - TEST_CHECK ( expected == actual ); + TEST_CHECK(expected == actual); } } gkyl_array_release(array_x); @@ -880,34 +921,29 @@ void test_mat_mm_arrays_dev() gkyl_array_release(array_ycu); gkyl_mat_mm_array_mem_release(ctest_prob_mem_ho); gkyl_mat_mm_array_mem_release(ctest_prob_mem_cu); - } #endif - - - TEST_LIST = { - { "mat_base_ho", test_mat_base_ho }, - { "mat_mm_op_ho", test_mat_mm_op_ho }, - { "mat_linsolve_ho", test_mat_linsolve_ho }, - { "nmat_base_ho", test_nmat_base_ho }, - { "nmat_linsolve_ho", test_nmat_linsolve_ho }, - { "nmat_linsolve_pa_ho", test_nmat_linsolve_pa_ho }, - { "mat_mv_ho", test_mat_mv_ho}, - { "nmat_mv_ho", test_nmat_mv_ho}, - { "nmat_mm_ho", test_nmat_mm_ho}, - { "mat_mm_arrays_ho", test_mat_mm_arrays_ho}, + {"mat_base_ho", test_mat_base_ho}, + {"mat_mm_op_ho", test_mat_mm_op_ho}, + {"mat_linsolve_ho", test_mat_linsolve_ho}, + {"nmat_base_ho", test_nmat_base_ho}, + {"nmat_linsolve_ho", test_nmat_linsolve_ho}, + {"nmat_linsolve_pa_ho", test_nmat_linsolve_pa_ho}, + {"mat_mv_ho", test_mat_mv_ho}, + {"nmat_mv_ho", test_nmat_mv_ho}, + {"nmat_mm_ho", test_nmat_mm_ho}, + {"mat_mm_arrays_ho", test_mat_mm_arrays_ho}, #ifdef GKYL_HAVE_CUDA - { "nmat_base_dev", test_nmat_base_dev }, - { "nmat_linsolve_dev", test_nmat_linsolve_dev }, - { "nmat_linsolve_pa_dev", test_nmat_linsolve_pa_dev }, - { "nmat_mv_dev", test_nmat_mv_dev}, - { "mat_mm_dev", test_mat_mm_dev}, - { "nmat_mm_dev", test_nmat_mm_dev}, - { "mat_mm_arrays_dev", test_mat_mm_arrays_dev}, + {"nmat_base_dev", test_nmat_base_dev}, + {"nmat_linsolve_dev", test_nmat_linsolve_dev}, + {"nmat_linsolve_pa_dev", test_nmat_linsolve_pa_dev}, + {"nmat_mv_dev", test_nmat_mv_dev}, + {"mat_mm_dev", test_mat_mm_dev}, + {"nmat_mm_dev", test_nmat_mm_dev}, + {"mat_mm_arrays_dev", test_mat_mm_arrays_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; - diff --git a/core/unit/ctest_mat_triples.c b/core/unit/ctest_mat_triples.c index 4ef98b98bf..4d9750b918 100644 --- a/core/unit/ctest_mat_triples.c +++ b/core/unit/ctest_mat_triples.c @@ -31,12 +31,12 @@ void test_mat_triples_1_ho() gkyl_mat_triples_insert(tri, 4, 1, 12.0); gkyl_mat_triples_insert(tri, 4, 4, 18.0); - TEST_CHECK( gkyl_mat_triples_get(tri, 4, 4) == 18.0 ); - TEST_CHECK( gkyl_mat_triples_get(tri, 4, 0) == 12.0 ); + TEST_CHECK(gkyl_mat_triples_get(tri, 4, 4) == 18.0); + TEST_CHECK(gkyl_mat_triples_get(tri, 4, 0) == 12.0); - TEST_CHECK( gkyl_mat_triples_get(tri, 0, 1) == 0.0 ); // zero element + TEST_CHECK(gkyl_mat_triples_get(tri, 0, 1) == 0.0); // zero element - TEST_CHECK( gkyl_mat_triples_size(tri) == 12 ); + TEST_CHECK(gkyl_mat_triples_size(tri) == 12); gkyl_mat_triples_release(tri); } @@ -56,23 +56,21 @@ void test_mat_triples_2_ho() // row 2 gkyl_mat_triples_insert(tri, 2, 2, 3.0); - TEST_CHECK( gkyl_mat_triples_size(tri) == 5 ); + TEST_CHECK(gkyl_mat_triples_size(tri) == 5); // order in which col-maj sorting should return indices - size_t cm_idx[][2] = { - {0,0}, {1,0}, {1,1}, {0,2}, {2,2} - }; + size_t cm_idx[][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}, {2, 2}}; - double vals[] = { 1.0, 2.1, 2.0, 1.1, 3.0 }; + double vals[] = {1.0, 2.1, 2.0, 1.1, 3.0}; int i = 0; gkyl_mat_triples_iter *iter = gkyl_mat_triples_iter_new(tri); while (gkyl_mat_triples_iter_next(iter)) { struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); - - TEST_CHECK( (mt.row == cm_idx[i][0]) && (mt.col == cm_idx[i][1]) ); - TEST_CHECK( mt.val == vals[i] ); - + + TEST_CHECK((mt.row == cm_idx[i][0]) && (mt.col == cm_idx[i][1])); + TEST_CHECK(mt.val == vals[i]); + i += 1; } @@ -84,7 +82,7 @@ void test_mat_triples_3_ho() { gkyl_mat_triples *tri = gkyl_mat_triples_new(3, 3); - double vals[] = { 1.0, 2.1, 2.0, 1.1, 3.0 }; + double vals[] = {1.0, 2.1, 2.0, 1.1, 3.0}; // row 1 gkyl_mat_triples_insert(tri, 1, 1, 2.0); @@ -99,7 +97,7 @@ void test_mat_triples_3_ho() gkyl_mat_triples_iter *iter = gkyl_mat_triples_iter_new(tri); while (gkyl_mat_triples_iter_next(iter)) { struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); - TEST_CHECK( mt.val == vals[i] ); + TEST_CHECK(mt.val == vals[i]); i += 1; } @@ -108,7 +106,7 @@ void test_mat_triples_3_ho() gkyl_mat_triples_iter_init(iter, tri); while (gkyl_mat_triples_iter_next(iter)) { struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); - TEST_CHECK( mt.val == 0. ); + TEST_CHECK(mt.val == 0.); TEST_MSG("Expected: %.13e in (%zu,%zu)", 0., mt.row, mt.col); TEST_MSG("Produced: %.13e", mt.val); } @@ -123,7 +121,7 @@ void test_mat_triples_3_ho() gkyl_mat_triples_iter_init(iter, tri); while (gkyl_mat_triples_iter_next(iter)) { struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); - TEST_CHECK( mt.val == vals[i] ); + TEST_CHECK(mt.val == vals[i]); i += 1; } @@ -132,8 +130,8 @@ void test_mat_triples_3_ho() } TEST_LIST = { - { "mat_triples_1_ho", test_mat_triples_1_ho }, - { "mat_triples_2_ho", test_mat_triples_2_ho }, - { "mat_triples_3_ho", test_mat_triples_3_ho }, - { NULL, NULL } + {"mat_triples_1_ho", test_mat_triples_1_ho}, + {"mat_triples_2_ho", test_mat_triples_2_ho}, + {"mat_triples_3_ho", test_mat_triples_3_ho}, + {NULL, NULL} }; diff --git a/core/unit/ctest_math.c b/core/unit/ctest_math.c index 786dced804..04266114e2 100644 --- a/core/unit/ctest_math.c +++ b/core/unit/ctest_math.c @@ -5,121 +5,126 @@ #include // Table on Page 5 of van Engelen paper. See math.c for full reference -double func_1(double x, void *ctx) { return x*x*x-2*x*x+x; } - -double func_2(double x, void *ctx) { return 1/(1+x); } +double func_1(double x, void *ctx) +{ + return x * x * x - 2 * x * x + x; +} -double func_12(double x, void *ctx) { return 1/sqrt(sin(M_PI*x)); } +double func_2(double x, void *ctx) +{ + return 1 / (1 + x); +} -double func_13(double x, void *ctx) { return pow(sin(M_PI*x), -0.8); } +double func_12(double x, void *ctx) +{ + return 1 / sqrt(sin(M_PI * x)); +} -double -func_cir(double x, void *ctx) +double func_13(double x, void *ctx) { - return sqrt(1+x*x/(1-x*x)); + return pow(sin(M_PI * x), -0.8); } +double func_cir(double x, void *ctx) +{ + return sqrt(1 + x * x / (1 - x * x)); +} -static void -show_qr_res(struct gkyl_qr_res res, const char *msg) +static void show_qr_res(struct gkyl_qr_res res, const char *msg) { fprintf(stdout, "%s\n", msg); - fprintf(stdout, ">> Status = %d. Res = %.15lg, Error = %g, Neval = %d. Nlevel = %d\n", - res.status, res.res, res.error, res.nevals, res.nlevels); + fprintf( + stdout, ">> Status = %d. Res = %.15lg, Error = %g, Neval = %d. Nlevel = %d\n", res.status, + res.res, res.error, res.nevals, res.nlevels + ); } -void -test_math_dbl_exp_ho(void) +void test_math_dbl_exp_ho(void) { do { struct gkyl_qr_res res = gkyl_dbl_exp(func_1, 0, 0.0, 1.0, 10, 1e-11); //show_quad_res(res, "func_1"); - TEST_CHECK( gkyl_compare(res.res, 1.0/12.0, 1e-10) ); - } while(0); + TEST_CHECK(gkyl_compare(res.res, 1.0 / 12.0, 1e-10)); + } while (0); do { struct gkyl_qr_res res = gkyl_dbl_exp(func_2, 0, 0.0, 1.0, 10, 1e-11); //show_quad_res(res, "func_2"); - TEST_CHECK( gkyl_compare(res.res, log(2.0), 1e-10) ); - } while(0); + TEST_CHECK(gkyl_compare(res.res, log(2.0), 1e-10)); + } while (0); do { // seems the following only gets to 1e-7 accuracy struct gkyl_qr_res res = gkyl_dbl_exp(func_12, 0, 0.0, 1.0, 10, 1e-15); //show_quad_res(res, "func_12"); - TEST_CHECK( gkyl_compare(res.res, 1.669253683348149, 1e-7) ); - } while(0); + TEST_CHECK(gkyl_compare(res.res, 1.669253683348149, 1e-7)); + } while (0); do { // The following integral 13 does not converge due to singularities // at the end point. van Engelen claims it does. I can't make it work. - + /* struct gkyl_quad_res res = gkyl_dbl_exp(func_13, 0, 0.0, 1.0, 10, 1e-11); */ /* show_quad_res(res, "func_13"); */ /* TEST_CHECK( gkyl_compare(res.quad_res, 3.604250526330095, 1e-10) ); */ - } while(0); + } while (0); do { struct gkyl_qr_res res = gkyl_dbl_exp(func_cir, 0, -1.0, 1.0, 10, 1e-16); //show_qr_res(res, "func_2"); - TEST_CHECK( gkyl_compare(res.res, M_PI, 1e-7) ); - } while(0); + TEST_CHECK(gkyl_compare(res.res, M_PI, 1e-7)); + } while (0); } double rfunc_1(double x, void *ctx) { - return x*x-1; + return x * x - 1; } double rfunc_2(double x, void *ctx) { // flat around the root x = 0 - return x*sin(x*x); + return x * sin(x * x); } double rfunc_3(double x, void *ctx) { - return x*exp(x)-10; + return x * exp(x) - 10; } -void -test_math_ridders_ho(void) +void test_math_ridders_ho(void) { do { double x1 = 0.5, x2 = 2.0; double f1 = rfunc_1(x1, 0), f2 = rfunc_1(x2, 0); - struct gkyl_qr_res res = gkyl_ridders(rfunc_1, 0, x1, x2, f1, f2, - 100, 1e-12); -// show_qr_res(res, "rfunc_1"); - TEST_CHECK( gkyl_compare(res.res, 1.0, 1e-10) ); - } while(0); + struct gkyl_qr_res res = gkyl_ridders(rfunc_1, 0, x1, x2, f1, f2, 100, 1e-12); + // show_qr_res(res, "rfunc_1"); + TEST_CHECK(gkyl_compare(res.res, 1.0, 1e-10)); + } while (0); do { double x1 = -2.0, x2 = 0.0; double f1 = rfunc_1(x1, 0), f2 = rfunc_1(x2, 0); - struct gkyl_qr_res res = gkyl_ridders(rfunc_1, 0, x1, x2, f1, f2, - 100, 1e-12); -// show_qr_res(res, "rfunc_1"); - TEST_CHECK( gkyl_compare(res.res, -1.0, 1e-10) ); - } while(0); + struct gkyl_qr_res res = gkyl_ridders(rfunc_1, 0, x1, x2, f1, f2, 100, 1e-12); + // show_qr_res(res, "rfunc_1"); + TEST_CHECK(gkyl_compare(res.res, -1.0, 1e-10)); + } while (0); do { double x1 = -0.5, x2 = 1.0; double f1 = rfunc_2(x1, 0), f2 = rfunc_2(x2, 0); - struct gkyl_qr_res res = gkyl_ridders(rfunc_2, 0, x1, x2, f1, f2, - 100, 1e-12); -// show_qr_res(res, "rfunc_2"); - TEST_CHECK( gkyl_compare(res.res, 0.0, 1e-10) ); - } while(0); + struct gkyl_qr_res res = gkyl_ridders(rfunc_2, 0, x1, x2, f1, f2, 100, 1e-12); + // show_qr_res(res, "rfunc_2"); + TEST_CHECK(gkyl_compare(res.res, 0.0, 1e-10)); + } while (0); do { double x1 = -1.0, x2 = 5.0; double f1 = rfunc_3(x1, 0), f2 = rfunc_3(x2, 0); - struct gkyl_qr_res res = gkyl_ridders(rfunc_3, 0, x1, x2, f1, f2, - 100, 1e-12); -// show_qr_res(res, "rfunc_3"); - TEST_CHECK( gkyl_compare(res.res, 1.745528002740699, 1e-10) ); - } while(0); + struct gkyl_qr_res res = gkyl_ridders(rfunc_3, 0, x1, x2, f1, f2, 100, 1e-12); + // show_qr_res(res, "rfunc_3"); + TEST_CHECK(gkyl_compare(res.res, 1.745528002740699, 1e-10)); + } while (0); } struct idx_status { @@ -130,170 +135,148 @@ struct idx_status { static struct idx_status check_in_list(int nvals, const double complex *vals, double complex tocheck, double eps) { - for (int i=0; irpart[i]+I*rts->impart[i], 1e-14).status - ); + for (int i = 0; i < 4; ++i) { + TEST_CHECK(check_in_list(4, res, rts->rpart[i] + I * rts->impart[i], 1e-14).status); + } gkyl_poly_roots_release(rts); } while (0); do { struct gkyl_poly_roots *rts = gkyl_poly_roots_new(5); - - double c1[] = { 14400.0, -11400.0, 1174.0, 711.0, -126.0 }; + + double c1[] = {14400.0, -11400.0, 1174.0, 711.0, -126.0}; gkyl_calc_poly_roots(rts, c1); - double complex res[5] = { 120.0, 5.0, 3.0, 2.0, -4.0 }; + double complex res[5] = {120.0, 5.0, 3.0, 2.0, -4.0}; - for (int i=0; i<5; ++i) - TEST_CHECK( - check_in_list(5, res, rts->rpart[i]+I*rts->impart[i], 1e-14).status - ); + for (int i = 0; i < 5; ++i) { + TEST_CHECK(check_in_list(5, res, rts->rpart[i] + I * rts->impart[i], 1e-14).status); + } gkyl_poly_roots_release(rts); - } while (0); - + } while (0); } - -void -test_math_sturn_root_intervals_ho(void) +void test_math_sturn_root_intervals_ho(void) { - // Test from wiki example: 2 real, distinct roots // https://en.wikipedia.org/wiki/Sturm%27s_theorem do { - struct gkyl_root_intervals root_intervals; + struct gkyl_root_intervals root_intervals; // Setup the specific test double coeff[4] = {-1.0, -1.0, 0.0, 1.0}; @@ -301,15 +284,15 @@ test_math_sturn_root_intervals_ho(void) double tol = 1e-13; // compute root inverals - root_intervals = gkyl_calc_quartic_root_intervals( coeff, domain, tol); + root_intervals = gkyl_calc_quartic_root_intervals(coeff, domain, tol); // Check the outputs - double lower[4] = {-3.0,0.0,0.0,0.0}; - double upper[4] = {0.0,3.0,0.0,0.0}; - TEST_CHECK( root_intervals.status == 0 ); - TEST_CHECK( root_intervals.nroots == 2 ); - TEST_CHECK( root_intervals.niter > 0 ); - for (int i=0; i<4; ++i){ + double lower[4] = {-3.0, 0.0, 0.0, 0.0}; + double upper[4] = {0.0, 3.0, 0.0, 0.0}; + TEST_CHECK(root_intervals.status == 0); + TEST_CHECK(root_intervals.nroots == 2); + TEST_CHECK(root_intervals.niter > 0); + for (int i = 0; i < 4; ++i) { TEST_CHECK(gkyl_compare_double(upper[i], root_intervals.root_bound_upper[i], 1e-12)); TEST_CHECK(gkyl_compare_double(lower[i], root_intervals.root_bound_lower[i], 1e-12)); } @@ -318,10 +301,10 @@ test_math_sturn_root_intervals_ho(void) gkyl_root_isolation_from_intervals_via_ridders(&root_intervals, tol); // Check the outputs of the roots via ridders - double roots[4] = {-1.0,1.0,0.0,0.0}; - for (int i=0; i 0 ); + TEST_CHECK(root_intervals.status_refinement[i] == 0); + TEST_CHECK(root_intervals.niter_refinement[i] > 0); } - } while (0); + } while (0); // Test: 4 real roots do { - struct gkyl_root_intervals root_intervals; + struct gkyl_root_intervals root_intervals; // Setup the specific test double coeff[4] = {0.1000, 0.0, -1.0000, 0.0}; @@ -350,15 +333,15 @@ test_math_sturn_root_intervals_ho(void) double tol = 1e-13; // compute root inverals - root_intervals = gkyl_calc_quartic_root_intervals( coeff, domain, tol); + root_intervals = gkyl_calc_quartic_root_intervals(coeff, domain, tol); // Check the outputs - double lower[4] = {-1.5,-0.75,0.0,0.75}; - double upper[4] = {-0.75,0.0,0.75,1.5}; - TEST_CHECK( root_intervals.status == 0 ); - TEST_CHECK( root_intervals.nroots == 4 ); - TEST_CHECK( root_intervals.niter > 0 ); - for (int i=0; i<4; ++i){ + double lower[4] = {-1.5, -0.75, 0.0, 0.75}; + double upper[4] = {-0.75, 0.0, 0.75, 1.5}; + TEST_CHECK(root_intervals.status == 0); + TEST_CHECK(root_intervals.nroots == 4); + TEST_CHECK(root_intervals.niter > 0); + for (int i = 0; i < 4; ++i) { TEST_CHECK(gkyl_compare_double(upper[i], root_intervals.root_bound_upper[i], 1e-12)); TEST_CHECK(gkyl_compare_double(lower[i], root_intervals.root_bound_lower[i], 1e-12)); } @@ -367,10 +350,12 @@ test_math_sturn_root_intervals_ho(void) gkyl_root_isolation_from_intervals_via_ridders(&root_intervals, tol); // Check the outputs of the roots via ridders - double roots[4] = {-0.9419651451198933,-0.3357106870197288,0.3357106870197288,0.9419651451198933}; - for (int i=0; i 0 ); + TEST_CHECK(root_intervals.status_refinement[i] == 0); + TEST_CHECK(root_intervals.niter_refinement[i] > 0); } - } while (0); - + } while (0); // Test: 4 real roots, more complex polynomial do { - struct gkyl_root_intervals root_intervals; + struct gkyl_root_intervals root_intervals; // Setup the specific test double coeff[4] = {-0.5170, 1.2377, 0.0354, -1.7561}; @@ -400,15 +390,15 @@ test_math_sturn_root_intervals_ho(void) double tol = 1e-13; // compute root inverals - root_intervals = gkyl_calc_quartic_root_intervals( coeff, domain, tol); + root_intervals = gkyl_calc_quartic_root_intervals(coeff, domain, tol); // Check the outputs - double lower[4] = {-3.0,0.0,0.75,0.9375}; - double upper[4] = {0,0.75,0.9375,1.1250}; - TEST_CHECK( root_intervals.status == 0 ); - TEST_CHECK( root_intervals.nroots == 4 ); - TEST_CHECK( root_intervals.niter > 0 ); - for (int i=0; i<4; ++i){ + double lower[4] = {-3.0, 0.0, 0.75, 0.9375}; + double upper[4] = {0, 0.75, 0.9375, 1.1250}; + TEST_CHECK(root_intervals.status == 0); + TEST_CHECK(root_intervals.nroots == 4); + TEST_CHECK(root_intervals.niter > 0); + for (int i = 0; i < 4; ++i) { TEST_CHECK(gkyl_compare_double(upper[i], root_intervals.root_bound_upper[i], 1e-12)); TEST_CHECK(gkyl_compare_double(lower[i], root_intervals.root_bound_lower[i], 1e-12)); } @@ -417,10 +407,13 @@ test_math_sturn_root_intervals_ho(void) gkyl_root_isolation_from_intervals_via_ridders(&root_intervals, tol); // Check the outputs of the roots via ridders - double roots[4] = {-8.3856473883897131e-01,6.5873479706025262e-01,9.3592994177871747e-01,1.0000000000000040e+00}; - for (int i=0; i 0 ); + TEST_CHECK(root_intervals.status_refinement[i] == 0); + TEST_CHECK(root_intervals.niter_refinement[i] > 0); } // Compute the roots via ridders using the refined domains gkyl_root_isolation_from_intervals_via_ridders(&root_intervals, tol); // Check the outputs of the roots via ridders - for (int i=0; i 0 ); - for (int i=0; i<4; ++i){ + double lower[4] = {0.6, -1.2, -0.3, 0.0}; + double upper[4] = {3.0, -0.3, 0.6, 0.0}; + TEST_CHECK(root_intervals.status == 0); + TEST_CHECK(root_intervals.nroots == 3); + TEST_CHECK(root_intervals.niter > 0); + for (int i = 0; i < 4; ++i) { TEST_CHECK(gkyl_compare_double(upper[i], root_intervals.root_bound_upper[i], 1e-12)); TEST_CHECK(gkyl_compare_double(lower[i], root_intervals.root_bound_lower[i], 1e-12)); } @@ -475,36 +473,39 @@ test_math_sturn_root_intervals_ho(void) // Compute the roots via ridders using the refined domains gkyl_root_isolation_from_intervals_via_ridders(&root_intervals, tol); - // Ridders fails to find the repeated root! (root 3), returns status_ridders == 1 + // Ridders fails to find the repeated root! (root 3), returns status_ridders == 1 // Check the outputs of the roots via ridders - double roots[4] = {1.0,-1.0,0.0,0.0}; - for (int i=0; i<2; ++i){ + double roots[4] = {1.0, -1.0, 0.0, 0.0}; + for (int i = 0; i < 2; ++i) { TEST_CHECK(gkyl_compare_double(roots[i], root_intervals.real_roots_ridders[i], 1e-12)); - TEST_CHECK( root_intervals.status_ridders[i] == 0 ); + TEST_CHECK(root_intervals.status_ridders[i] == 0); } - // test refined root intervals + // test refined root intervals gkyl_refine_root_intervals_bisection(&root_intervals, tol); // Roots: [0,0,+1,-1] // Check the outputs of the refinement pass - double lower_refined[4] = {9.9999999999997746e-01,-1.0000000000000455e+00,-1.6979010789934061e-14,0.0}; - double upper_refined[4] = {1.0000000000000457e+00,-9.9999999999999434e-01,3.4180066184793154e-14,0.0}; - for (int i=0; i 0 ); + TEST_CHECK(root_intervals.status_refinement[i] == 0); + TEST_CHECK(root_intervals.niter_refinement[i] > 0); } - } while (0); - + } while (0); - // Test: 3-distinct roots, large ordering - // Maxima res: [x=-1.0*10^-10,x=1.0*10^-10,x=0.0] + // Test: 3-distinct roots, large ordering + // Maxima res: [x=-1.0*10^-10,x=1.0*10^-10,x=0.0] do { - struct gkyl_root_intervals root_intervals; + struct gkyl_root_intervals root_intervals; // Setup the specific test double coeff[4] = {0.0, 0.0, -1.0e-20, 0.0}; @@ -512,55 +513,58 @@ test_math_sturn_root_intervals_ho(void) double tol = 1e-13; // compute root inverals - root_intervals = gkyl_calc_quartic_root_intervals( coeff, domain, tol); + root_intervals = gkyl_calc_quartic_root_intervals(coeff, domain, tol); // Check the outputs - double lower[4] = {-2.793966983697753e-10,-6.984911908129258e-11,3.492467056294875e-11,0.0}; - double upper[4] = {-6.984911908129258e-11,3.492467056294875e-11,1.396984602071901e-10,0.0}; - TEST_CHECK( root_intervals.status == 0 ); - TEST_CHECK( root_intervals.nroots == 3 ); - TEST_CHECK( root_intervals.niter > 0 ); - for (int i=0; i<4; ++i){ + double lower[4] = {-2.793966983697753e-10, -6.984911908129258e-11, 3.492467056294875e-11, 0.0}; + double upper[4] = {-6.984911908129258e-11, 3.492467056294875e-11, 1.396984602071901e-10, 0.0}; + TEST_CHECK(root_intervals.status == 0); + TEST_CHECK(root_intervals.nroots == 3); + TEST_CHECK(root_intervals.niter > 0); + for (int i = 0; i < 4; ++i) { TEST_CHECK(gkyl_compare_double(upper[i], root_intervals.root_bound_upper[i], 1e-12)); TEST_CHECK(gkyl_compare_double(lower[i], root_intervals.root_bound_lower[i], 1e-12)); } - // Compute the roots via ridders using the refined domains + // Compute the roots via ridders using the refined domains gkyl_root_isolation_from_intervals_via_ridders(&root_intervals, tol); - // Ridders fails to find the repeated root! (root 2), returns status_ridders == 1 + // Ridders fails to find the repeated root! (root 2), returns status_ridders == 1 // Check the outputs of the roots via ridders - double roots[4] = {-1.0*10e-10,0.0,1.0*10e-10,0.0}; - for (int i=0; i 0 ); + TEST_CHECK(root_intervals.status_refinement[i] == 0); + TEST_CHECK(root_intervals.niter_refinement[i] > 0); } - } while (0); - + } while (0); // Test: 3-distinct roots, shifted (x+1.1)^4 - (x+1.1)^2 = 0 // Maxima res: [x=-2.1,x=-0.1,x=-1.1] // FAILS TO FIND REPEATED ROOT AT x = -0.1! do { - struct gkyl_root_intervals root_intervals; + struct gkyl_root_intervals root_intervals; // Setup the specific test double coeff[4] = {0.2541, 3.1240, 6.2600, 4.4000}; @@ -568,7 +572,7 @@ test_math_sturn_root_intervals_ho(void) double tol = 1e-13; // compute root inverals - root_intervals = gkyl_calc_quartic_root_intervals( coeff, domain, tol); + root_intervals = gkyl_calc_quartic_root_intervals(coeff, domain, tol); // Check we have the right number of roots etc //printf("\nnum-roots: %d\n",root_intervals.nroots); @@ -580,17 +584,17 @@ test_math_sturn_root_intervals_ho(void) //} // Check the outputs - double lower[4] = {-3.0,-1.5,0.0,0.0}; - double upper[4] = {-1.5,0.0,0.0,0.0}; - TEST_CHECK( root_intervals.status == 0 ); - TEST_CHECK( root_intervals.nroots == 2 ); - TEST_CHECK( root_intervals.niter > 0 ); - for (int i=0; i<4; ++i){ + double lower[4] = {-3.0, -1.5, 0.0, 0.0}; + double upper[4] = {-1.5, 0.0, 0.0, 0.0}; + TEST_CHECK(root_intervals.status == 0); + TEST_CHECK(root_intervals.nroots == 2); + TEST_CHECK(root_intervals.niter > 0); + for (int i = 0; i < 4; ++i) { TEST_CHECK(gkyl_compare_double(upper[i], root_intervals.root_bound_upper[i], 1e-12)); TEST_CHECK(gkyl_compare_double(lower[i], root_intervals.root_bound_lower[i], 1e-12)); } - // Compute the roots via ridders using the refined domains + // Compute the roots via ridders using the refined domains gkyl_root_isolation_from_intervals_via_ridders(&root_intervals, tol); // Check we have the right number of roots etc @@ -604,10 +608,10 @@ test_math_sturn_root_intervals_ho(void) //} // Check the outputs of the roots via ridders - double roots[4] = {-2.1,-0.1,0.0,0.0}; - for (int i=0; i 0 ); + TEST_CHECK(root_intervals.status_refinement[i] == 0); + TEST_CHECK(root_intervals.niter_refinement[i] > 0); } } while (0); - } TEST_LIST = { - { "math_dbl_exp_ho", test_math_dbl_exp_ho }, - { "math_ridders_ho", test_math_ridders_ho }, - { "math_poly2_roots_ho", test_math_poly2_roots_ho }, - { "math_poly3_roots_ho", test_math_poly3_roots_ho }, - { "math_poly4_roots_ho", test_math_poly4_roots_ho }, - { "math_sturn_root_intervals_ho", test_math_sturn_root_intervals_ho }, - { "math_polyn_roots_ho", test_math_polyn_roots_ho }, - { NULL, NULL }, + {"math_dbl_exp_ho", test_math_dbl_exp_ho}, + {"math_ridders_ho", test_math_ridders_ho}, + {"math_poly2_roots_ho", test_math_poly2_roots_ho}, + {"math_poly3_roots_ho", test_math_poly3_roots_ho}, + {"math_poly4_roots_ho", test_math_poly4_roots_ho}, + {"math_sturn_root_intervals_ho", test_math_sturn_root_intervals_ho}, + {"math_polyn_roots_ho", test_math_polyn_roots_ho}, + {NULL, NULL} }; diff --git a/core/unit/ctest_mpack.c b/core/unit/ctest_mpack.c index a43768b582..50f0cd6d74 100644 --- a/core/unit/ctest_mpack.c +++ b/core/unit/ctest_mpack.c @@ -2,8 +2,7 @@ #include #include -void -test_mpack_map_1_ho(void) +void test_mpack_map_1_ho(void) { char *data; mpack_writer_t writer; @@ -12,7 +11,7 @@ test_mpack_map_1_ho(void) // add some data to mpack mpack_build_map(&writer); - + mpack_write_cstr(&writer, "time"); mpack_write_double(&writer, 1.5); @@ -33,7 +32,7 @@ test_mpack_map_1_ho(void) // finish writing int status = mpack_writer_destroy(&writer); - TEST_CHECK( mpack_ok == status ); + TEST_CHECK(mpack_ok == status); // read it back mpack_tree_t tree; @@ -43,41 +42,40 @@ test_mpack_map_1_ho(void) mpack_node_t root = mpack_tree_root(&tree); TEST_CHECK(mpack_node_type(root) == mpack_type_map); - TEST_CHECK( 4 == mpack_node_map_count(root) ); + TEST_CHECK(4 == mpack_node_map_count(root)); - TEST_CHECK( mpack_node_map_contains_cstr(root, "time") ); - TEST_CHECK( mpack_node_map_contains_cstr(root, "bogus") == false ); + TEST_CHECK(mpack_node_map_contains_cstr(root, "time")); + TEST_CHECK(mpack_node_map_contains_cstr(root, "bogus") == false); mpack_node_t tm_node = mpack_node_map_cstr(root, "time"); - TEST_CHECK( mpack_node_double(tm_node) == 1.5 ); + TEST_CHECK(mpack_node_double(tm_node) == 1.5); mpack_node_t fr_node = mpack_node_map_cstr(root, "frame"); - TEST_CHECK( mpack_node_i64(fr_node) == 100 ); + TEST_CHECK(mpack_node_i64(fr_node) == 100); mpack_node_t bs_node = mpack_node_map_cstr(root, "basis"); - char *basis_str = mpack_node_cstr_alloc(bs_node, mpack_node_strlen(bs_node)+1); - TEST_CHECK( strcmp("ms", basis_str) == 0 ); + char *basis_str = mpack_node_cstr_alloc(bs_node, mpack_node_strlen(bs_node) + 1); + TEST_CHECK(strcmp("ms", basis_str) == 0); MPACK_FREE(basis_str); mpack_node_t vl_node = mpack_node_map_cstr(root, "values"); - TEST_CHECK( mpack_node_type(vl_node) == mpack_type_array ); - TEST_CHECK( mpack_node_array_length(vl_node) == 3 ); + TEST_CHECK(mpack_node_type(vl_node) == mpack_type_array); + TEST_CHECK(mpack_node_array_length(vl_node) == 3); double v = 0.1; - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { mpack_node_t dn = mpack_node_array_at(vl_node, i); - TEST_CHECK( gkyl_compare_double(v, mpack_node_double(dn), 1e-15) ); + TEST_CHECK(gkyl_compare_double(v, mpack_node_double(dn), 1e-15)); v += 0.1; } - + status = mpack_tree_destroy(&tree); - TEST_CHECK( mpack_ok == status ); + TEST_CHECK(mpack_ok == status); free(data); } -void -test_msgpack_1_ho(void) +void test_msgpack_1_ho(void) { struct gkyl_msgpack_map_elem elist[] = { GKYL_MSGPACK_MAP_ELEM("bool", true), // 0 @@ -88,27 +86,23 @@ test_msgpack_1_ho(void) GKYL_MSGPACK_MAP_ELEM("string", "Hello, World!") // 5 }; - TEST_CHECK( elist[0].elem_type == GKYL_MP_INT ); // bools are int? - TEST_CHECK( elist[0].bval == true ); - - TEST_CHECK( elist[1].elem_type == GKYL_MP_INT ); - TEST_CHECK( elist[1].ival == -10 ); + TEST_CHECK(elist[0].elem_type == GKYL_MP_INT); // bools are int? + TEST_CHECK(elist[0].bval == true); + + TEST_CHECK(elist[1].elem_type == GKYL_MP_INT); + TEST_CHECK(elist[1].ival == -10); - TEST_CHECK( elist[2].elem_type == GKYL_MP_UNSIGNED_INT ); - TEST_CHECK( elist[2].uval == 10u ); + TEST_CHECK(elist[2].elem_type == GKYL_MP_UNSIGNED_INT); + TEST_CHECK(elist[2].uval == 10u); - TEST_CHECK( elist[3].elem_type == GKYL_MP_FLOAT ); - TEST_CHECK( elist[3].fval == 1.0f ); + TEST_CHECK(elist[3].elem_type == GKYL_MP_FLOAT); + TEST_CHECK(elist[3].fval == 1.0f); - TEST_CHECK( elist[4].elem_type == GKYL_MP_DOUBLE ); - TEST_CHECK( elist[4].dval == 1.0 ); + TEST_CHECK(elist[4].elem_type == GKYL_MP_DOUBLE); + TEST_CHECK(elist[4].dval == 1.0); - TEST_CHECK( elist[5].elem_type == GKYL_MP_STRING ); - TEST_CHECK( strcmp(elist[5].cval, "Hello, World!") == 0 ); + TEST_CHECK(elist[5].elem_type == GKYL_MP_STRING); + TEST_CHECK(strcmp(elist[5].cval, "Hello, World!") == 0); } -TEST_LIST = { - { "mpack_map_1_ho", test_mpack_map_1_ho }, - { "msgpack_1_ho", test_msgpack_1_ho }, - { 0, 0 }, -}; +TEST_LIST = {{"mpack_map_1_ho", test_mpack_map_1_ho}, {"msgpack_1_ho", test_msgpack_1_ho}, {0, 0}}; diff --git a/core/unit/ctest_multib_comm_conn.c b/core/unit/ctest_multib_comm_conn.c index 9d04359f3b..cedb8caf7a 100644 --- a/core/unit/ctest_multib_comm_conn.c +++ b/core/unit/ctest_multib_comm_conn.c @@ -3,12 +3,11 @@ #include #include -static struct gkyl_block_geom * -create_L_domain(const int *cuts) +static struct gkyl_block_geom *create_L_domain(const int *cuts) { - // 2D with 3 blocks + // 2D with 3 blocks struct gkyl_block_geom *bgeom = gkyl_block_geom_new(2, 3); - + /* Block layout +------+ @@ -22,392 +21,385 @@ create_L_domain(const int *cuts) */ // block 0 - gkyl_block_geom_set_block(bgeom, 0, &(struct gkyl_block_geom_info) { - .lower = { 0, 0 }, - .upper = { 1, 1 }, - .cells = { 300, 300 }, - .cuts = { cuts[0], cuts[1] }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } // physical boundary - } - } + gkyl_block_geom_set_block( + bgeom, 0, + &(struct gkyl_block_geom_info + ){.lower = {0, 0}, + .upper = {1, 1}, + .cells = {300, 300}, + .cuts = {cuts[0], cuts[1]}, + + .connections[0] = + { + // x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + { + // y-direction connections + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); - + // block 1 - gkyl_block_geom_set_block(bgeom, 1, &(struct gkyl_block_geom_info) { - .lower = { 0, 0 }, - .upper = { 1, 1 }, - .cells = { 300, 300 }, - .cuts = { cuts[0], cuts[1] }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE } - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE } - } - } + gkyl_block_geom_set_block( + bgeom, 1, + &(struct gkyl_block_geom_info + ){.lower = {0, 0}, + .upper = {1, 1}, + .cells = {300, 300}, + .cuts = {cuts[0], cuts[1]}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 2 - gkyl_block_geom_set_block(bgeom, 2, &(struct gkyl_block_geom_info) { - .lower = { 0, 0 }, - .upper = { 1, 1 }, - .cells = { 300, 300 }, - .cuts = { cuts[0], cuts[1] }, - - .connections[0] = { // x-direction connections - { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } // physical boundary - } - } + gkyl_block_geom_set_block( + bgeom, 2, + &(struct gkyl_block_geom_info + ){.lower = {0, 0}, + .upper = {1, 1}, + .cells = {300, 300}, + .cuts = {cuts[0], cuts[1]}, + + .connections[0] = + { + // x-direction connections + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + { + // y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); return bgeom; } -static void -test_multib_comm_conn_0_ho(void) +static void test_multib_comm_conn_0_ho(void) { - struct gkyl_comm_conn cclist[] = { - { .rank = 1 }, - { .rank = 2 }, - }; + struct gkyl_comm_conn cclist[] = {{.rank = 1}, {.rank = 2}}; struct gkyl_multib_comm_conn *mbcc = gkyl_multib_comm_conn_new(2, cclist); - TEST_CHECK( mbcc->num_comm_conn == 2 ); + TEST_CHECK(mbcc->num_comm_conn == 2); gkyl_multib_comm_conn_release(mbcc); } -static void -test_multib_comm_conn_L_domain_send_c1_ho(void) +static void test_multib_comm_conn_L_domain_send_c1_ho(void) { - struct gkyl_block_geom *geom = create_L_domain((int[]) { 1, 1 } ); + struct gkyl_block_geom *geom = create_L_domain((int[]){1, 1}); struct gkyl_block_topo *topo = gkyl_block_geom_topo(geom); int num_blocks = topo->num_blocks; int num_cuts[num_blocks]; - int nghost[] = { 1, 1 }; - + int nghost[] = {1, 1}; + // construct decomp objects - struct gkyl_rect_decomp **decomp = - gkyl_malloc(sizeof(struct gkyl_rect_decomp*[num_blocks])); - for (int i=0; indim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } // for testing - int num_send_neigh[] = { 1, 2, 1 }; + int num_send_neigh[] = {1, 2, 1}; // for testing (these hard-coded values depend on how the algorithm - // is implemented) - struct gkyl_comm_conn conn_0[] = { - { .block_id = 1, .rank = 0 } - }; - gkyl_range_init(&conn_0[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 1 }); - - struct gkyl_comm_conn conn_1[] = { - { .block_id = 2, .rank = 0 }, - { .block_id = 0, .rank = 0 }, - }; - gkyl_range_init(&conn_1[0].range, 2, (int[]) { 300, 1 }, (int[]) { 300, 300 }); - gkyl_range_init(&conn_1[1].range, 2, (int[]) { 1, 300 }, (int[]) { 300, 300 }); - - struct gkyl_comm_conn conn_2[] = { - { .block_id = 1, .rank = 0 }, - }; - gkyl_range_init(&conn_2[0].range, 2, (int[]) { 1, 1 }, (int[]) { 1, 300 }); - - struct gkyl_comm_conn *block_conn[] = { conn_0, conn_1, conn_2 }; - - for (int bid=0; bidconn[bid], decomp); - - TEST_CHECK( num_send_neigh[bid] == mbcc->num_comm_conn ); - for (int ns=0; nsnum_comm_conn; ++ns) { - TEST_CHECK( block_conn[bid][ns].block_id == mbcc->comm_conn[ns].block_id); - TEST_CHECK( block_conn[bid][ns].rank == mbcc->comm_conn[ns].rank); - TEST_CHECK( gkyl_range_compare(&block_conn[bid][ns].range, &mbcc->comm_conn[ns].range) ); + // is implemented) + struct gkyl_comm_conn conn_0[] = {{.block_id = 1, .rank = 0}}; + gkyl_range_init(&conn_0[0].range, 2, (int[]){1, 1}, (int[]){300, 1}); + + struct gkyl_comm_conn conn_1[] = {{.block_id = 2, .rank = 0}, {.block_id = 0, .rank = 0}}; + gkyl_range_init(&conn_1[0].range, 2, (int[]){300, 1}, (int[]){300, 300}); + gkyl_range_init(&conn_1[1].range, 2, (int[]){1, 300}, (int[]){300, 300}); + + struct gkyl_comm_conn conn_2[] = {{.block_id = 1, .rank = 0}}; + gkyl_range_init(&conn_2[0].range, 2, (int[]){1, 1}, (int[]){1, 300}); + + struct gkyl_comm_conn *block_conn[] = {conn_0, conn_1, conn_2}; + + for (int bid = 0; bid < num_blocks; ++bid) { + for (int brank = 0; brank < num_cuts[bid]; ++brank) { + struct gkyl_multib_comm_conn *mbcc = + gkyl_multib_comm_conn_new_send(bid, brank, nghost, &topo->conn[bid], decomp); + + TEST_CHECK(num_send_neigh[bid] == mbcc->num_comm_conn); + for (int ns = 0; ns < mbcc->num_comm_conn; ++ns) { + TEST_CHECK(block_conn[bid][ns].block_id == mbcc->comm_conn[ns].block_id); + TEST_CHECK(block_conn[bid][ns].rank == mbcc->comm_conn[ns].rank); + TEST_CHECK(gkyl_range_compare(&block_conn[bid][ns].range, &mbcc->comm_conn[ns].range)); } gkyl_multib_comm_conn_release(mbcc); } } - for (int i=0; inum_blocks; int num_cuts[num_blocks]; - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; int elo[2], eup[2]; - for (int d=0; d<2; ++d) + for (int d = 0; d < 2; ++d) { elo[d] = eup[d] = nghost[d]; - + } + // construct decomp objects - struct gkyl_rect_decomp **decomp = - gkyl_malloc(sizeof(struct gkyl_rect_decomp*[num_blocks])); - for (int i=0; indim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } int nsend_tot = 0; - for (int bid=0; bidconn[bid], decomp); - - for (int ns=0; nsnum_comm_conn; ++ns) { - nsend_tot +=1 ; - TEST_CHECK( mbcc->comm_conn[ns].range.volume == 100 ); + for (int bid = 0; bid < num_blocks; ++bid) { + for (int brank = 0; brank < num_cuts[bid]; ++brank) { + struct gkyl_multib_comm_conn *mbcc = + gkyl_multib_comm_conn_new_send(bid, brank, nghost, &topo->conn[bid], decomp); + + for (int ns = 0; ns < mbcc->num_comm_conn; ++ns) { + nsend_tot += 1; + TEST_CHECK(mbcc->comm_conn[ns].range.volume == 100); } gkyl_multib_comm_conn_release(mbcc); } } - TEST_CHECK( nsend_tot == 12 ); - - for (int i=0; inum_blocks; int num_cuts[num_blocks]; - int nghost[] = { 1, 1 }; - + int nghost[] = {1, 1}; + // construct decomp objects - struct gkyl_rect_decomp **decomp = - gkyl_malloc(sizeof(struct gkyl_rect_decomp*[num_blocks])); - for (int i=0; indim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } // for testing - int num_send_neigh[] = { 1, 2, 1 }; + int num_send_neigh[] = {1, 2, 1}; // for testing (these hard-coded values depend on how the algorithm - // is implemented) - struct gkyl_comm_conn conn_0[] = { - { .block_id = 1, .rank = 0 } - }; - gkyl_range_init(&conn_0[0].range, 2, (int[]) { 1, 0 }, (int[]) { 300, 0 }); - - struct gkyl_comm_conn conn_1[] = { - { .block_id = 2, .rank = 0 }, - { .block_id = 0, .rank = 0 }, - }; - gkyl_range_init(&conn_1[0].range, 2, (int[]) { 301, 1 }, (int[]) { 301, 300 }); - gkyl_range_init(&conn_1[1].range, 2, (int[]) { 1, 301 }, (int[]) { 300, 301 }); - - struct gkyl_comm_conn conn_2[] = { - { .block_id = 1, .rank = 0 }, - }; - gkyl_range_init(&conn_2[0].range, 2, (int[]) { 0, 1 }, (int[]) { 0, 300 }); - - struct gkyl_comm_conn *block_conn[] = { conn_0, conn_1, conn_2 }; - - for (int bid=0; bidconn[bid], decomp); - - TEST_CHECK( num_send_neigh[bid] == mbcc->num_comm_conn ); - for (int ns=0; nsnum_comm_conn; ++ns) { - TEST_CHECK( block_conn[bid][ns].block_id == mbcc->comm_conn[ns].block_id); - TEST_CHECK( block_conn[bid][ns].rank == mbcc->comm_conn[ns].rank); - TEST_CHECK( gkyl_range_compare(&block_conn[bid][ns].range, &mbcc->comm_conn[ns].range) ); + // is implemented) + struct gkyl_comm_conn conn_0[] = {{.block_id = 1, .rank = 0}}; + gkyl_range_init(&conn_0[0].range, 2, (int[]){1, 0}, (int[]){300, 0}); + + struct gkyl_comm_conn conn_1[] = {{.block_id = 2, .rank = 0}, {.block_id = 0, .rank = 0}}; + gkyl_range_init(&conn_1[0].range, 2, (int[]){301, 1}, (int[]){301, 300}); + gkyl_range_init(&conn_1[1].range, 2, (int[]){1, 301}, (int[]){300, 301}); + + struct gkyl_comm_conn conn_2[] = {{.block_id = 1, .rank = 0}}; + gkyl_range_init(&conn_2[0].range, 2, (int[]){0, 1}, (int[]){0, 300}); + + struct gkyl_comm_conn *block_conn[] = {conn_0, conn_1, conn_2}; + + for (int bid = 0; bid < num_blocks; ++bid) { + for (int brank = 0; brank < num_cuts[bid]; ++brank) { + struct gkyl_multib_comm_conn *mbcc = + gkyl_multib_comm_conn_new_recv(bid, brank, nghost, &topo->conn[bid], decomp); + + TEST_CHECK(num_send_neigh[bid] == mbcc->num_comm_conn); + for (int ns = 0; ns < mbcc->num_comm_conn; ++ns) { + TEST_CHECK(block_conn[bid][ns].block_id == mbcc->comm_conn[ns].block_id); + TEST_CHECK(block_conn[bid][ns].rank == mbcc->comm_conn[ns].rank); + TEST_CHECK(gkyl_range_compare(&block_conn[bid][ns].range, &mbcc->comm_conn[ns].range)); } gkyl_multib_comm_conn_release(mbcc); } } - for (int i=0; inum_blocks; int num_cuts[num_blocks]; - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; int elo[2], eup[2]; - for (int d=0; d<2; ++d) + for (int d = 0; d < 2; ++d) { elo[d] = eup[d] = nghost[d]; - + } + // construct decomp objects - struct gkyl_rect_decomp **decomp = - gkyl_malloc(sizeof(struct gkyl_rect_decomp*[num_blocks])); - for (int i=0; indim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } int nrecv_tot = 0; - for (int bid=0; bidconn[bid], decomp); - - for (int ns=0; nsnum_comm_conn; ++ns) { - nrecv_tot +=1 ; - TEST_CHECK( mbcc->comm_conn[ns].range.volume == 100 ); + for (int bid = 0; bid < num_blocks; ++bid) { + for (int brank = 0; brank < num_cuts[bid]; ++brank) { + struct gkyl_multib_comm_conn *mbcc = + gkyl_multib_comm_conn_new_recv(bid, brank, nghost, &topo->conn[bid], decomp); + + for (int ns = 0; ns < mbcc->num_comm_conn; ++ns) { + nrecv_tot += 1; + TEST_CHECK(mbcc->comm_conn[ns].range.volume == 100); } gkyl_multib_comm_conn_release(mbcc); } } - TEST_CHECK( nrecv_tot == 12 ); - - for (int i=0; inum_blocks; int num_cuts[num_blocks]; - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; int elo[2], eup[2]; - for (int d=0; d<2; ++d) + for (int d = 0; d < 2; ++d) { elo[d] = eup[d] = nghost[d]; - + } + // construct decomp objects - struct gkyl_rect_decomp **decomp = - gkyl_malloc(sizeof(struct gkyl_rect_decomp*[num_blocks])); - for (int i=0; indim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } - for (int bid=0; bidconn[bid], decomp); + for (int bid = 0; bid < num_blocks; ++bid) { + for (int brank = 0; brank < num_cuts[bid]; ++brank) { + struct gkyl_multib_comm_conn *mbcc = + gkyl_multib_comm_conn_new_recv(bid, brank, nghost, &topo->conn[bid], decomp); gkyl_multib_comm_conn_release(mbcc); } } - for (int i=0; i #include -void -test_null_comm_1d_ho() +void test_null_comm_1d_ho() { struct gkyl_range range; - gkyl_range_init(&range, 1, (int[]) { 1 }, (int[]) { 100 }); + gkyl_range_init(&range, 1, (int[]){1}, (int[]){100}); - int cuts[] = { 1 }; - struct gkyl_rect_decomp *decomp = - gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); + int cuts[] = {1}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); - struct gkyl_comm *comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = decomp - } - ); + struct gkyl_comm *comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.decomp = decomp}); - TEST_CHECK( strcmp(comm->id, "null_comm") == 0 ); - TEST_CHECK( comm->has_decomp ); + TEST_CHECK(strcmp(comm->id, "null_comm") == 0); + TEST_CHECK(comm->has_decomp); int rank; gkyl_comm_get_rank(comm, &rank); - TEST_CHECK( rank == 0 ); + TEST_CHECK(rank == 0); int sz; gkyl_comm_get_size(comm, &sz); - TEST_CHECK( sz == 1 ); + TEST_CHECK(sz == 1); - double out[3], inp[3] = { 2.0, 4.0, 8.0 }; + double out[3], inp[3] = {2.0, 4.0, 8.0}; gkyl_comm_allreduce(comm, GKYL_DOUBLE, GKYL_MIN, 3, inp, out); - for (int i=0; i<3; ++i) - TEST_CHECK( out[i] == inp[i] ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(out[i] == inp[i]); + } - int nghost[] = { 1 }; + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -48,33 +44,34 @@ test_null_comm_1d_ho() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr, idx); + double *f = gkyl_array_fetch(arr, idx); f[0] = iter.idx[0]; } - int per_dirs[] = { 0 }; - gkyl_comm_array_per_sync(comm, &local, &local_ext, 1, per_dirs, arr ); + int per_dirs[] = {0}; + gkyl_comm_array_per_sync(comm, &local, &local_ext, 1, per_dirs, arr); - int idx[GKYL_MAX_DIM] = { 0 }; - - for (int d=0; d local.upper[d]) + } + if (idx[d] > local.upper[d]) { idx[d] = idx[d] - ncell; - else + } else { idx[d] = idx[d] + ncell; + } - const double *f = gkyl_array_cfetch(arr, lidx); - TEST_CHECK( idx[0] == f[0] ); + const double *f = gkyl_array_cfetch(arr, lidx); + TEST_CHECK(idx[0] == f[0]); } } } @@ -84,26 +81,21 @@ test_null_comm_1d_ho() gkyl_array_release(arr); } -void -test_null_comm_allgather_1d_ho() +void test_null_comm_allgather_1d_ho() { struct gkyl_range range; - gkyl_range_init(&range, 1, (int[]) { 1 }, (int[]) { 100 }); + gkyl_range_init(&range, 1, (int[]){1}, (int[]){100}); - int cuts[] = { 1 }; - struct gkyl_rect_decomp *decomp = - gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); + int cuts[] = {1}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); - struct gkyl_comm *comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = decomp - } - ); + struct gkyl_comm *comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.decomp = decomp}); int rank, sz; gkyl_comm_get_rank(comm, &rank); gkyl_comm_get_size(comm, &sz); - int nghost[] = { 1 }; + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -113,17 +105,17 @@ test_null_comm_allgather_1d_ho() struct gkyl_range_iter iter; // Test gkyl_comm_array_allgather - + struct gkyl_array *arr_recv = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); gkyl_comm_array_allgather(comm, &local, &local, arr, arr_recv); - for (int d=0; dranges[rank], nghost, &local_ext, &local); @@ -176,31 +163,31 @@ test_null_comm_bcast_1d_ho() gkyl_array_clear(arr, 200005); struct gkyl_range_iter iter; - // Test gkyl_comm_array_bcast + // Test gkyl_comm_array_bcast int bcast_rank = 0; gkyl_array_clear(arr_recv, 0); gkyl_comm_array_bcast(comm, arr, arr_recv, bcast_rank); - for (int d=0; dranges[rank], nghost, &local_ext, &local); struct gkyl_range local_x[2], local_ext_x[2]; - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { nghost[0], 0 }, - &local_ext_x[0], &local_x[0]); - - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { 0, nghost[1] }, - &local_ext_x[1], &local_x[1]); + gkyl_create_ranges(&decomp->ranges[rank], (int[]){nghost[0], 0}, &local_ext_x[0], &local_x[0]); + + gkyl_create_ranges(&decomp->ranges[rank], (int[]){0, nghost[1]}, &local_ext_x[1], &local_x[1]); struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); gkyl_array_clear(arr, 200005); @@ -246,37 +226,40 @@ test_null_comm_2d_ho() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr, idx); + double *f = gkyl_array_fetch(arr, idx); - for (int d=0; d local.upper[d]) + } + if (idx[d] > local.upper[d]) { idx[d] = idx[d] - ncell; - else + } else { idx[d] = idx[d] + ncell; + } - const double *f = gkyl_array_cfetch(arr, lidx); - for (int n=0; nranges[rank], nghost, &local_ext, &local); struct gkyl_range local_x[2], local_ext_x[2]; - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { nghost[0], 0 }, - &local_ext_x[0], &local_x[0]); - - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { 0, nghost[1] }, - &local_ext_x[1], &local_x[1]); + gkyl_create_ranges(&decomp->ranges[rank], (int[]){nghost[0], 0}, &local_ext_x[0], &local_x[0]); + + gkyl_create_ranges(&decomp->ranges[rank], (int[]){0, nghost[1]}, &local_ext_x[1], &local_x[1]); struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); struct gkyl_array *arr_recv = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); gkyl_array_clear(arr, 200005); struct gkyl_range_iter iter; - // Test gkyl_comm_array_bcast + // Test gkyl_comm_array_bcast int bcast_rank = 0; gkyl_array_clear(arr_recv, 0); gkyl_comm_array_bcast(comm, arr, arr_recv, bcast_rank); - for (int d=0; dranges[rank], nghost, &local_ext, &local); struct gkyl_range local_x[2], local_ext_x[2]; - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { nghost[0], 0 }, - &local_ext_x[0], &local_x[0]); - - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { 0, nghost[1] }, - &local_ext_x[1], &local_x[1]); + gkyl_create_ranges(&decomp->ranges[rank], (int[]){nghost[0], 0}, &local_ext_x[0], &local_x[0]); + + gkyl_create_ranges(&decomp->ranges[rank], (int[]){0, nghost[1]}, &local_ext_x[1], &local_x[1]); struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); struct gkyl_array *arr_recv = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); @@ -392,27 +362,27 @@ test_null_comm_allgather_2d_ho(){ gkyl_comm_array_allgather(comm, &local, &local, arr, arr_recv); - for (int d=0; dranges[rank], nghost, &local_ext, &local); @@ -456,20 +421,20 @@ test_null_comm_io_2d_ho() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr, idx); + double *f = gkyl_array_fetch(arr, idx); - double xc[GKYL_MAX_DIM] = { 0.0 }; + double xc[GKYL_MAX_DIM] = {0.0}; gkyl_rect_grid_cell_center(&grid, iter.idx, xc); - f[0] = sin(2*M_PI*xc[0])*sin(2*M_PI*xc[1]); - f[1] = cos(2*M_PI*xc[0])*sin(2*M_PI*xc[1]); - } + f[0] = sin(2 * M_PI * xc[0]) * sin(2 * M_PI * xc[1]); + f[1] = cos(2 * M_PI * xc[0]) * sin(2 * M_PI * xc[1]); + } int status; status = gkyl_comm_array_write(comm, &grid, &local, 0, arr, "ctest_null_comm_io_2d.gkyl"); - struct gkyl_array *arr_rw = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); + struct gkyl_array *arr_rw = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); status = gkyl_comm_array_read(comm, &grid, &local, arr_rw, "ctest_null_comm_io_2d.gkyl"); - TEST_CHECK( status == 0 ); + TEST_CHECK(status == 0); gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { @@ -477,53 +442,49 @@ test_null_comm_io_2d_ho() const double *f = gkyl_array_cfetch(arr, idx); const double *frw = gkyl_array_cfetch(arr_rw, idx); - TEST_CHECK( gkyl_compare_double(f[0], frw[0], 1e-15) ); - TEST_CHECK( gkyl_compare_double(f[1], frw[1], 1e-15) ); + TEST_CHECK(gkyl_compare_double(f[0], frw[0], 1e-15)); + TEST_CHECK(gkyl_compare_double(f[1], frw[1], 1e-15)); } - + gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); gkyl_array_release(arr); gkyl_array_release(arr_rw); } -void -test_null_comm_io_p1_p4_ho(void) +void test_null_comm_io_p1_p4_ho(void) { struct gkyl_rect_grid grid; struct gkyl_array_header_info hdr; - gkyl_grid_sub_array_header_read(&grid, &hdr, - "core/data/unit/ser-euler_riem_2d_hllc-euler_1.gkyl"); + gkyl_grid_sub_array_header_read(&grid, &hdr, "core/data/unit/ser-euler_riem_2d_hllc-euler_1.gkyl"); + + size_t nc = hdr.esznc / gkyl_elem_type_size[hdr.etype]; - size_t nc = hdr.esznc/gkyl_elem_type_size[hdr.etype]; - - int nghost[] = { 1, 2 }; + int nghost[] = {1, 2}; struct gkyl_range range, ext_range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); - int cuts[] = { 1, 1 }; - struct gkyl_rect_decomp *decomp = - gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); - - struct gkyl_comm *comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = decomp - } - ); - + int cuts[] = {1, 1}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); + + struct gkyl_comm *comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.decomp = decomp}); + struct gkyl_array *s_arr = gkyl_array_new(hdr.etype, nc, ext_range.volume); gkyl_array_clear(s_arr, 0.0); int status; - status = gkyl_grid_sub_array_read(&grid, &range, s_arr, - "core/data/unit/ser-euler_riem_2d_hllc-euler_1.gkyl"); + status = gkyl_grid_sub_array_read( + &grid, &range, s_arr, "core/data/unit/ser-euler_riem_2d_hllc-euler_1.gkyl" + ); - TEST_CHECK( 0 == status ); + TEST_CHECK(0 == status); struct gkyl_array *p_arr = gkyl_array_new(hdr.etype, nc, ext_range.volume); gkyl_array_clear(p_arr, 0.0); - status = gkyl_comm_array_read(comm, &grid, &range, p_arr, - "core/data/unit/euler_riem_2d_hllc-euler_1.gkyl"); + status = gkyl_comm_array_read( + comm, &grid, &range, p_arr, "core/data/unit/euler_riem_2d_hllc-euler_1.gkyl" + ); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); @@ -531,11 +492,12 @@ test_null_comm_io_p1_p4_ho(void) const double *s_dat = gkyl_array_cfetch(s_arr, gkyl_range_idx(&range, iter.idx)); const double *p_dat = gkyl_array_cfetch(p_arr, gkyl_range_idx(&range, iter.idx)); - for (int c=0; c #include -void evalFunc(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = x*x; + fout[0] = x * x; } -void -test_proj_on_basis_1_ho() +void test_proj_on_basis_1_ho() { int poly_order = 1; double lower[] = {-2.0}, upper[] = {2.0}; @@ -26,11 +25,11 @@ test_proj_on_basis_1_ho() gkyl_cart_modal_serendip(&basis, 1, poly_order); // projection updater for dist-function - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc, NULL); + gkyl_proj_on_basis *projDistf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc, NULL); // create array range: no ghost-cells - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -42,20 +41,19 @@ test_proj_on_basis_1_ho() // left cell double *dfl = gkyl_array_fetch(distf, 0); - TEST_CHECK( gkyl_compare(1.885618083164127, dfl[0], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.632993161855453, dfl[1], 1e-12) ); + TEST_CHECK(gkyl_compare(1.885618083164127, dfl[0], 1e-12)); + TEST_CHECK(gkyl_compare(-1.632993161855453, dfl[1], 1e-12)); // right cell double *dfr = gkyl_array_fetch(distf, 1); - TEST_CHECK( gkyl_compare(1.885618083164127, dfr[0], 1e-12) ); - TEST_CHECK( gkyl_compare(1.632993161855453, dfr[1], 1e-12) ); + TEST_CHECK(gkyl_compare(1.885618083164127, dfr[0], 1e-12)); + TEST_CHECK(gkyl_compare(1.632993161855453, dfr[1], 1e-12)); gkyl_proj_on_basis_release(projDistf); gkyl_array_release(distf); } -void -test_proj_on_basis_2_ho() +void test_proj_on_basis_2_ho() { int poly_order = 1; double lower[] = {-2.0}, upper[] = {2.0}; @@ -67,18 +65,16 @@ test_proj_on_basis_2_ho() struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, 1, poly_order); - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &grid, - .basis = &basis, - .qtype = GKYL_GAUSS_LOBATTO_QUAD, - .num_quad = 3, - .num_ret_vals = 1, - .eval = evalFunc, - } - ); + gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &grid, + .basis = &basis, + .qtype = GKYL_GAUSS_LOBATTO_QUAD, + .num_quad = 3, + .num_ret_vals = 1, + .eval = evalFunc}); // create array range: no ghost-cells - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -90,25 +86,24 @@ test_proj_on_basis_2_ho() // left cell double *dfl = gkyl_array_fetch(distf, 0); - TEST_CHECK( gkyl_compare(1.885618083164127, dfl[0], 1e-12) ); - TEST_CHECK( gkyl_compare(-1.632993161855453, dfl[1], 1e-12) ); + TEST_CHECK(gkyl_compare(1.885618083164127, dfl[0], 1e-12)); + TEST_CHECK(gkyl_compare(-1.632993161855453, dfl[1], 1e-12)); // right cell double *dfr = gkyl_array_fetch(distf, 1); - TEST_CHECK( gkyl_compare(1.885618083164127, dfr[0], 1e-12) ); - TEST_CHECK( gkyl_compare(1.632993161855453, dfr[1], 1e-12) ); + TEST_CHECK(gkyl_compare(1.885618083164127, dfr[0], 1e-12)); + TEST_CHECK(gkyl_compare(1.632993161855453, dfr[1], 1e-12)); gkyl_proj_on_basis_release(projDistf); gkyl_array_release(distf); } -void -test_proj_on_basis_2_2d_ho() +void test_proj_on_basis_2_2d_ho() { int poly_order = 1; - double lower[] = {-2.0,-2.0}, upper[] = {2.0,2.0}; + double lower[] = {-2.0, -2.0}, upper[] = {2.0, 2.0}; int cells[] = {2, 2}; - int ndim = sizeof(cells)/sizeof(cells[0]); + int ndim = sizeof(cells) / sizeof(cells[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); @@ -116,18 +111,16 @@ test_proj_on_basis_2_2d_ho() struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &grid, - .basis = &basis, - .qtype = GKYL_GAUSS_LOBATTO_QUAD, - .num_quad = poly_order+1, - .num_ret_vals = 1, - .eval = evalFunc, - } - ); + gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &grid, + .basis = &basis, + .qtype = GKYL_GAUSS_LOBATTO_QUAD, + .num_quad = poly_order + 1, + .num_ret_vals = 1, + .eval = evalFunc}); // create array range: no ghost-cells - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -143,60 +136,59 @@ test_proj_on_basis_2_2d_ho() // left cell double *dfl = gkyl_array_fetch(distf, 0); xval = -2.; - basisval = 1./pow(sqrt(2.),ndim); + basisval = 1. / pow(sqrt(2.), ndim); fval = pow(xval, 2); - dgval = 2.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfl[0], 1e-12) ); + dgval = 2. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfl[0], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfl[0]); xc = -1.; - xlog = (xval-xc)/(dx/2.); - basisval = (sqrt(3.)/pow(sqrt(2.),ndim))*xlog; + xlog = (xval - xc) / (dx / 2.); + basisval = (sqrt(3.) / pow(sqrt(2.), ndim)) * xlog; fval = pow(xval, 2); - dgval = 2.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfl[1], 1e-12) ); + dgval = 2. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfl[1], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfl[1]); dgval = 0.; - TEST_CHECK( gkyl_compare(dgval, dfl[2], 1e-12) ); + TEST_CHECK(gkyl_compare(dgval, dfl[2], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfl[2]); - TEST_CHECK( gkyl_compare(dgval, dfl[3], 1e-12) ); + TEST_CHECK(gkyl_compare(dgval, dfl[3], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfl[3]); // right cell double *dfr = gkyl_array_fetch(distf, 2); xval = 2.; - basisval = 1./pow(sqrt(2.),ndim); + basisval = 1. / pow(sqrt(2.), ndim); fval = pow(xval, 2); - dgval = 2.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfr[0], 1e-12) ); + dgval = 2. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfr[0], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfr[0]); xc = 1.; - xlog = (xval-xc)/(dx/2.); - basisval = (sqrt(3.)/pow(sqrt(2.),ndim))*xlog; + xlog = (xval - xc) / (dx / 2.); + basisval = (sqrt(3.) / pow(sqrt(2.), ndim)) * xlog; fval = pow(xval, 2); - dgval = 2.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfr[1], 1e-12) ); + dgval = 2. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfr[1], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfr[1]); dgval = 0.; - TEST_CHECK( gkyl_compare(dgval, dfr[2], 1e-12) ); + TEST_CHECK(gkyl_compare(dgval, dfr[2], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfr[2]); - TEST_CHECK( gkyl_compare(dgval, dfr[3], 1e-12) ); + TEST_CHECK(gkyl_compare(dgval, dfr[3], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfr[3]); gkyl_proj_on_basis_release(projDistf); gkyl_array_release(distf); } -void -test_proj_on_basis_2_3d_ho() +void test_proj_on_basis_2_3d_ho() { int poly_order = 1; - double lower[] = {-2.0,-2.0,-2.0}, upper[] = {2.0,2.0,2.0}; + double lower[] = {-2.0, -2.0, -2.0}, upper[] = {2.0, 2.0, 2.0}; int cells[] = {2, 2, 2}; - int ndim = sizeof(cells)/sizeof(cells[0]); + int ndim = sizeof(cells) / sizeof(cells[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); @@ -204,18 +196,16 @@ test_proj_on_basis_2_3d_ho() struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &grid, - .basis = &basis, - .qtype = GKYL_GAUSS_LOBATTO_QUAD, - .num_quad = poly_order+1, - .num_ret_vals = 1, - .eval = evalFunc, - } - ); + gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &grid, + .basis = &basis, + .qtype = GKYL_GAUSS_LOBATTO_QUAD, + .num_quad = poly_order + 1, + .num_ret_vals = 1, + .eval = evalFunc}); // create array range: no ghost-cells - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -231,70 +221,69 @@ test_proj_on_basis_2_3d_ho() // left cell double *dfl = gkyl_array_fetch(distf, 0); xval = -2.; - basisval = 1./pow(sqrt(2.),ndim); + basisval = 1. / pow(sqrt(2.), ndim); fval = pow(xval, 2); - dgval = 4.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfl[0], 1e-12) ); + dgval = 4. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfl[0], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfl[0]); xc = -1.; - xlog = (xval-xc)/(dx/2.); - basisval = (sqrt(3.)/pow(sqrt(2.),ndim))*xlog; + xlog = (xval - xc) / (dx / 2.); + basisval = (sqrt(3.) / pow(sqrt(2.), ndim)) * xlog; fval = pow(xval, 2); - dgval = 4.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfl[1], 1e-12) ); + dgval = 4. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfl[1], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfl[1]); dgval = 0.; - TEST_CHECK( gkyl_compare(dgval, dfl[2], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfl[3], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfl[4], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfl[5], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfl[6], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfl[7], 1e-12) ); + TEST_CHECK(gkyl_compare(dgval, dfl[2], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfl[3], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfl[4], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfl[5], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfl[6], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfl[7], 1e-12)); // right cell double *dfr = gkyl_array_fetch(distf, 4); xval = 2.; - basisval = 1./pow(sqrt(2.),ndim); + basisval = 1. / pow(sqrt(2.), ndim); fval = pow(xval, 2); - dgval = 4.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfr[0], 1e-12) ); + dgval = 4. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfr[0], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfr[0]); xc = 1.; - xlog = (xval-xc)/(dx/2.); - basisval = (sqrt(3.)/pow(sqrt(2.),ndim))*xlog; + xlog = (xval - xc) / (dx / 2.); + basisval = (sqrt(3.) / pow(sqrt(2.), ndim)) * xlog; fval = pow(xval, 2); - dgval = 4.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfr[1], 1e-12) ); + dgval = 4. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfr[1], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfr[1]); dgval = 0.; - TEST_CHECK( gkyl_compare(dgval, dfr[2], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfr[3], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfr[4], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfr[5], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfr[6], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfr[7], 1e-12) ); + TEST_CHECK(gkyl_compare(dgval, dfr[2], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfr[3], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfr[4], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfr[5], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfr[6], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfr[7], 1e-12)); gkyl_proj_on_basis_release(projDistf); gkyl_array_release(distf); } -void evalFuncP(double t, const double *xn, double* restrict fout, void *ctx) +void evalFuncP(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; - fout[0] = z*z; + fout[0] = z * z; } -void -test_proj_on_basis_3_3d_ho() +void test_proj_on_basis_3_3d_ho() { int poly_order = 1; - double lower[] = {-2.0,-2.0,-2.0}, upper[] = {2.0,2.0,2.0}; + double lower[] = {-2.0, -2.0, -2.0}, upper[] = {2.0, 2.0, 2.0}; int cells[] = {2, 2, 2}; - int ndim = sizeof(cells)/sizeof(cells[0]); + int ndim = sizeof(cells) / sizeof(cells[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); @@ -302,18 +291,16 @@ test_proj_on_basis_3_3d_ho() struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &grid, - .basis = &basis, - .qtype = GKYL_GAUSS_LOBATTO_QUAD, - .num_quad = poly_order+1, - .num_ret_vals = 1, - .eval = evalFuncP, - } - ); + gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &grid, + .basis = &basis, + .qtype = GKYL_GAUSS_LOBATTO_QUAD, + .num_quad = poly_order + 1, + .num_ret_vals = 1, + .eval = evalFuncP}); // create array range: no ghost-cells - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -329,62 +316,62 @@ test_proj_on_basis_3_3d_ho() // left cell double *dfl = gkyl_array_fetch(distf, 0); xval = -2.; - basisval = 1./pow(sqrt(2.),ndim); + basisval = 1. / pow(sqrt(2.), ndim); fval = pow(xval, 2); - dgval = 4.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfl[0], 1e-12) ); + dgval = 4. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfl[0], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfl[0]); xc = -1.; - xlog = (xval-xc)/(dx/2.); - basisval = (sqrt(3.)/pow(sqrt(2.),ndim))*xlog; + xlog = (xval - xc) / (dx / 2.); + basisval = (sqrt(3.) / pow(sqrt(2.), ndim)) * xlog; fval = pow(xval, 2); - dgval = 4.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfl[3], 1e-12) ); + dgval = 4. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfl[3], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfl[3]); dgval = 0.; - TEST_CHECK( gkyl_compare(dgval, dfl[1], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfl[2], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfl[4], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfl[5], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfl[6], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfl[7], 1e-12) ); + TEST_CHECK(gkyl_compare(dgval, dfl[1], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfl[2], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfl[4], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfl[5], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfl[6], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfl[7], 1e-12)); // right cell double *dfr = gkyl_array_fetch(distf, 1); xval = 2.; - basisval = 1./pow(sqrt(2.),ndim); + basisval = 1. / pow(sqrt(2.), ndim); fval = pow(xval, 2); - dgval = 4.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfr[0], 1e-12) ); + dgval = 4. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfr[0], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfr[0]); xc = 1.; - xlog = (xval-xc)/(dx/2.); - basisval = (sqrt(3.)/pow(sqrt(2.),ndim))*xlog; + xlog = (xval - xc) / (dx / 2.); + basisval = (sqrt(3.) / pow(sqrt(2.), ndim)) * xlog; fval = pow(xval, 2); - dgval = 4.*fval*basisval; - TEST_CHECK( gkyl_compare(dgval, dfr[3], 1e-12) ); + dgval = 4. * fval * basisval; + TEST_CHECK(gkyl_compare(dgval, dfr[3], 1e-12)); TEST_MSG("Expected: %.13e | Produced: %.13e", dgval, dfr[3]); dgval = 0.; - TEST_CHECK( gkyl_compare(dgval, dfr[1], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfr[2], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfr[4], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfr[5], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfr[6], 1e-12) ); - TEST_CHECK( gkyl_compare(dgval, dfr[7], 1e-12) ); + TEST_CHECK(gkyl_compare(dgval, dfr[1], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfr[2], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfr[4], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfr[5], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfr[6], 1e-12)); + TEST_CHECK(gkyl_compare(dgval, dfr[7], 1e-12)); gkyl_proj_on_basis_release(projDistf); gkyl_array_release(distf); } TEST_LIST = { - { "test_proj_on_basis_1_ho", test_proj_on_basis_1_ho }, - { "test_proj_on_basis_2_ho", test_proj_on_basis_2_ho }, - { "test_proj_on_basis_2_2d_ho", test_proj_on_basis_2_2d_ho }, - { "test_proj_on_basis_2_3d_ho", test_proj_on_basis_2_3d_ho }, - { "test_proj_on_basis_3_3d_ho", test_proj_on_basis_3_3d_ho }, - { NULL, NULL }, + {"test_proj_on_basis_1_ho", test_proj_on_basis_1_ho}, + {"test_proj_on_basis_2_ho", test_proj_on_basis_2_ho}, + {"test_proj_on_basis_2_2d_ho", test_proj_on_basis_2_2d_ho}, + {"test_proj_on_basis_2_3d_ho", test_proj_on_basis_2_3d_ho}, + {"test_proj_on_basis_3_3d_ho", test_proj_on_basis_3_3d_ho}, + {NULL, NULL} }; diff --git a/core/unit/ctest_proj_powsqrt_on_basis.c b/core/unit/ctest_proj_powsqrt_on_basis.c index 72eacaeba4..5d0d7570ba 100644 --- a/core/unit/ctest_proj_powsqrt_on_basis.c +++ b/core/unit/ctest_proj_powsqrt_on_basis.c @@ -11,37 +11,35 @@ #include "math.h" // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { - struct gkyl_array* a = gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -void eval_fun_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_fun_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - double Lx = 2.*M_PI; - fout[0] = 0.5*(1.+cos(0.5*2.*M_PI*x/Lx)); + double Lx = 2. * M_PI; + fout[0] = 0.5 * (1. + cos(0.5 * 2. * M_PI * x / Lx)); } -void eval_powsqrt_fun_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_powsqrt_fun_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - double Lx = 2.*M_PI; + double Lx = 2. * M_PI; double exponent = 3; double fun[1]; eval_fun_1x(t, xn, fun, ctx); - fout[0] = pow( sqrt(fun[0]), exponent); + fout[0] = pow(sqrt(fun[0]), exponent); } -void -test_1x(int poly_order, bool use_gpu) +void test_1x(int poly_order, bool use_gpu) { - double Lx = 2.*M_PI; - double lower[] = {-Lx/2.}, upper[] = {Lx/2.}; + double Lx = 2. * M_PI; + double lower[] = {-Lx / 2.}, upper[] = {Lx / 2.}; int cells[] = {32}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; @@ -51,7 +49,7 @@ test_1x(int poly_order, bool use_gpu) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); - int ghost[] = { 1 }; + int ghost[] = {1}; struct gkyl_range local, local_ext; // Local, local-ext phase-space ranges. gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); @@ -61,12 +59,12 @@ test_1x(int poly_order, bool use_gpu) g = mkarr(basis.num_basis, local_ext.volume); struct gkyl_array *f_cu, *g_cu; if (use_gpu) { // Create device copies - f_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); - g_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); + f_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); + g_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); } - gkyl_proj_on_basis *proj_f = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_fun_1x, NULL); + gkyl_proj_on_basis *proj_f = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_fun_1x, NULL); gkyl_proj_on_basis_advance(proj_f, 0.0, &local, f); @@ -76,7 +74,8 @@ test_1x(int poly_order, bool use_gpu) } // Create pow(sqrt( ), ) updater. - gkyl_proj_powsqrt_on_basis *proj_up = gkyl_proj_powsqrt_on_basis_new(&basis, poly_order+1, use_gpu); + gkyl_proj_powsqrt_on_basis *proj_up = + gkyl_proj_powsqrt_on_basis_new(&basis, poly_order + 1, use_gpu); if (use_gpu) { gkyl_proj_powsqrt_on_basis_advance(proj_up, &local, 3, f_cu, g_cu); @@ -88,25 +87,28 @@ test_1x(int poly_order, bool use_gpu) // Project expected g. struct gkyl_array *gA; gA = mkarr(basis.num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_g = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_powsqrt_fun_1x, NULL); + gkyl_proj_on_basis *proj_g = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_powsqrt_fun_1x, NULL); gkyl_proj_on_basis_advance(proj_g, 0.0, &local, gA); - for (int k=0; kndim == 0 ); - TEST_CHECK( range->volume == 1 ); + TEST_CHECK(range->ndim == 0); + TEST_CHECK(range->volume == 1); - TEST_CHECK( gkyl_range_is_sub_range(range) == 0 ); + TEST_CHECK(gkyl_range_is_sub_range(range) == 0); } void test_range_0_stack_ho() @@ -28,8 +28,8 @@ void test_range_0_heap_ho() struct gkyl_range *range = gkyl_range_new(0, NULL, NULL); test_range_0(range); - TEST_CHECK( range->ndim == gkyl_range_get_ndim(range)); - TEST_CHECK( range->volume == gkyl_range_get_volume(range)); + TEST_CHECK(range->ndim == gkyl_range_get_ndim(range)); + TEST_CHECK(range->volume == gkyl_range_get_volume(range)); gkyl_range_release(range); } @@ -40,12 +40,12 @@ void test_range_1_ho() struct gkyl_range range; gkyl_range_init(&range, 2, lower, upper); - TEST_CHECK( range.ndim == 2); - TEST_CHECK( range.volume == 200); + TEST_CHECK(range.ndim == 2); + TEST_CHECK(range.volume == 200); - for (unsigned i=0; i<2; ++i) { - TEST_CHECK( range.lower[i] == lower[i]); - TEST_CHECK( range.upper[i] == upper[i]); + for (unsigned i = 0; i < 2; ++i) { + TEST_CHECK(range.lower[i] == lower[i]); + TEST_CHECK(range.upper[i] == upper[i]); } } @@ -55,12 +55,12 @@ void test_range_shape_ho() struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, shape); - TEST_CHECK( range.ndim == 2); - TEST_CHECK( range.volume == 25*50); + TEST_CHECK(range.ndim == 2); + TEST_CHECK(range.volume == 25 * 50); - for (unsigned i=0; i<2; ++i) { - TEST_CHECK( range.lower[i] == 0); - TEST_CHECK( range.upper[i] == shape[i]-1); + for (unsigned i = 0; i < 2; ++i) { + TEST_CHECK(range.lower[i] == 0); + TEST_CHECK(range.upper[i] == shape[i] - 1); } } @@ -70,12 +70,12 @@ void test_range_shape1_ho() struct gkyl_range range; gkyl_range_init_from_shape1(&range, 2, shape); - TEST_CHECK( range.ndim == 2); - TEST_CHECK( range.volume == 25*50); + TEST_CHECK(range.ndim == 2); + TEST_CHECK(range.volume == 25 * 50); - for (unsigned i=0; i<2; ++i) { - TEST_CHECK( range.lower[i] == 1); - TEST_CHECK( range.upper[i] == shape[i]); + for (unsigned i = 0; i < 2; ++i) { + TEST_CHECK(range.lower[i] == 1); + TEST_CHECK(range.upper[i] == shape[i]); } } @@ -85,40 +85,41 @@ void test_range_shift_ho() struct gkyl_range range; gkyl_range_init(&range, 2, lower, upper); - int delta[] = { 10, -20 }; - + int delta[] = {10, -20}; + struct gkyl_range rshift; gkyl_range_shift(&rshift, &range, delta); - TEST_CHECK( rshift.ndim = range.ndim ); - TEST_CHECK( rshift.volume = range.volume ); + TEST_CHECK(rshift.ndim = range.ndim); + TEST_CHECK(rshift.volume = range.volume); - for (int d=0; dupper. - int lower2d_empty0[] = {18,1}, upper2d_empty0[] = {17,6}; + int lower2d_empty0[] = {18, 1}, upper2d_empty0[] = {17, 6}; struct gkyl_range range2d_empty0; gkyl_range_init(&range2d_empty0, 2, lower2d_empty0, upper2d_empty0); struct gkyl_range_iter iter2d_empty0; gkyl_range_iter_init(&iter2d_empty0, &range2d_empty0); - while (gkyl_range_iter_next(&iter2d_empty0)) TEST_CHECK(false); // Shouldn't be in here. + while (gkyl_range_iter_next(&iter2d_empty0)) { + TEST_CHECK(false); // Shouldn't be in here. + } - int lower2d_empty1[] = {28,1}, upper2d_empty1[] = {17,6}; + int lower2d_empty1[] = {28, 1}, upper2d_empty1[] = {17, 6}; struct gkyl_range range2d_empty1; gkyl_range_init(&range2d_empty1, 2, lower2d_empty1, upper2d_empty1); struct gkyl_range_iter iter2d_empty1; gkyl_range_iter_init(&iter2d_empty1, &range2d_empty1); - while (gkyl_range_iter_next(&iter2d_empty1)) TEST_CHECK(false); // Shouldn't be in here. + while (gkyl_range_iter_next(&iter2d_empty1)) { + TEST_CHECK(false); // Shouldn't be in here. + } - int lower2d_empty2[] = {1,7}, upper2d_empty2[] = {17,6}; + int lower2d_empty2[] = {1, 7}, upper2d_empty2[] = {17, 6}; struct gkyl_range range2d_empty2; gkyl_range_init(&range2d_empty2, 2, lower2d_empty2, upper2d_empty2); struct gkyl_range_iter iter2d_empty2; gkyl_range_iter_init(&iter2d_empty2, &range2d_empty2); - while (gkyl_range_iter_next(&iter2d_empty2)) TEST_CHECK(false); // Shouldn't be in here. + while (gkyl_range_iter_next(&iter2d_empty2)) { + TEST_CHECK(false); // Shouldn't be in here. + } - int lower2d_empty3[] = {1,27}, upper2d_empty3[] = {17,6}; + int lower2d_empty3[] = {1, 27}, upper2d_empty3[] = {17, 6}; struct gkyl_range range2d_empty3; gkyl_range_init(&range2d_empty3, 2, lower2d_empty3, upper2d_empty3); struct gkyl_range_iter iter2d_empty3; gkyl_range_iter_init(&iter2d_empty3, &range2d_empty3); - while (gkyl_range_iter_next(&iter2d_empty3)) TEST_CHECK(false); // Shouldn't be in here. - + while (gkyl_range_iter_next(&iter2d_empty3)) { + TEST_CHECK(false); // Shouldn't be in here. + } } void test_sub_range_ho() @@ -192,21 +200,23 @@ void test_sub_range_ho() struct gkyl_range range; gkyl_range_init(&range, 2, lower, upper); - int sublower[] = {2, 2}, subupper[] = { 5, 10 }; + int sublower[] = {2, 2}, subupper[] = {5, 10}; struct gkyl_range subrange; gkyl_sub_range_init(&subrange, &range, sublower, subupper); - TEST_CHECK( subrange.volume == 4*9 ); - TEST_CHECK( gkyl_range_is_sub_range(&subrange) == 1 ); + TEST_CHECK(subrange.volume == 4 * 9); + TEST_CHECK(gkyl_range_is_sub_range(&subrange) == 1); - for (unsigned d=0; d<2; ++d) { - TEST_CHECK( subrange.lower[d] == sublower[d] ); - TEST_CHECK( subrange.upper[d] == subupper[d] ); + for (unsigned d = 0; d < 2; ++d) { + TEST_CHECK(subrange.lower[d] == sublower[d]); + TEST_CHECK(subrange.upper[d] == subupper[d]); } - for (int i=subrange.lower[0]; i<=subrange.upper[0]; ++i) - for (int j=subrange.lower[1]; j<=subrange.upper[1]; ++j) - TEST_CHECK( gkyl_ridx(subrange, i, j) == gkyl_ridx(range, i, j) ); + for (int i = subrange.lower[0]; i <= subrange.upper[0]; ++i) { + for (int j = subrange.lower[1]; j <= subrange.upper[1]; ++j) { + TEST_CHECK(gkyl_ridx(subrange, i, j) == gkyl_ridx(range, i, j)); + } + } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &subrange); @@ -216,16 +226,16 @@ void test_sub_range_ho() int lidx = gkyl_ridx(subrange, iter.idx[0], iter.idx[1]); gkyl_range_inv_idx(&subrange, lidx, invIdx); - TEST_CHECK( invIdx[0] == iter.idx[0] ); - TEST_CHECK( invIdx[1] == iter.idx[1] ); + TEST_CHECK(invIdx[0] == iter.idx[0]); + TEST_CHECK(invIdx[1] == iter.idx[1]); } - TEST_CHECK( gkyl_range_contains_idx(&range, (int[]) { 1, 1 }) == 1 ); - TEST_CHECK( gkyl_range_contains_idx(&range, (int[]) { 1, 5 }) == 1 ); - TEST_CHECK( gkyl_range_contains_idx(&range, (int[]) { 1, 10 }) == 1 ); - TEST_CHECK( gkyl_range_contains_idx(&range, (int[]) { 10, 20 }) == 1 ); + TEST_CHECK(gkyl_range_contains_idx(&range, (int[]){1, 1}) == 1); + TEST_CHECK(gkyl_range_contains_idx(&range, (int[]){1, 5}) == 1); + TEST_CHECK(gkyl_range_contains_idx(&range, (int[]){1, 10}) == 1); + TEST_CHECK(gkyl_range_contains_idx(&range, (int[]){10, 20}) == 1); - TEST_CHECK( gkyl_range_contains_idx(&range, (int[]) { 0, 20 }) == 0 ); + TEST_CHECK(gkyl_range_contains_idx(&range, (int[]){0, 20}) == 0); } void test_sub_range_inv_idx_ho() @@ -234,7 +244,7 @@ void test_sub_range_inv_idx_ho() struct gkyl_range range; gkyl_range_init(&range, 2, lower, upper); - int sublower[] = {2, 2}, subupper[] = { 5, 10 }; + int sublower[] = {2, 2}, subupper[] = {5, 10}; struct gkyl_range subrange; gkyl_sub_range_init(&subrange, &range, sublower, subupper); @@ -243,13 +253,12 @@ void test_sub_range_inv_idx_ho() gkyl_range_init(&range2, 2, sublower, subupper); struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &subrange); + gkyl_range_iter_init(&iter, &subrange); int idx[2]; - for (int i=0; indim; ++d) - TEST_CHECK( iter.idx[d] == idx[d] ); + for (int d = 0; d < range->ndim; ++d) { + TEST_CHECK(iter.idx[d] == idx[d]); + } } } @@ -628,13 +682,13 @@ void test_range_inv_idx_heap_ho() struct gkyl_range *range = gkyl_range_new(3, lower, upper); test_range_inv_idx(range); - TEST_CHECK( range->ndim == gkyl_range_get_ndim(range)); - TEST_CHECK( range->volume == gkyl_range_get_volume(range)); + TEST_CHECK(range->ndim == gkyl_range_get_ndim(range)); + TEST_CHECK(range->volume == gkyl_range_get_volume(range)); gkyl_range_get_lower(range, lower); gkyl_range_get_upper(range, upper); - for (int d=0; dndim; d++) { - TEST_CHECK( range->lower[d] == lower[d]); - TEST_CHECK( range->upper[d] == upper[d]); + for (int d = 0; d < range->ndim; d++) { + TEST_CHECK(range->lower[d] == lower[d]); + TEST_CHECK(range->upper[d] == upper[d]); } gkyl_range_release(range); @@ -646,18 +700,19 @@ void test_huge_range_ho() struct gkyl_range range; gkyl_range_init(&range, 6, lower, upper); - long vol = 1L*64*64*64*64*64*64; + long vol = 1L * 64 * 64 * 64 * 64 * 64 * 64; - TEST_CHECK( vol == range.volume ); + TEST_CHECK(vol == range.volume); long lidx = gkyl_ridxn(range, lower); long uidx = gkyl_ridxn(range, upper); - TEST_CHECK( (uidx-lidx+1) == range.volume ); + TEST_CHECK((uidx - lidx + 1) == range.volume); int idx[6]; gkyl_range_inv_idx(&range, uidx, idx); - for (unsigned d=0; d<6; ++d) - TEST_CHECK( idx[d] == upper[d] ); + for (unsigned d = 0; d < 6; ++d) { + TEST_CHECK(idx[d] == upper[d]); + } } void test_range_deflate_ho() @@ -671,76 +726,86 @@ void test_range_deflate_ho() struct gkyl_range defr; gkyl_range_deflate(&defr, &range, remDir, locDir); - TEST_CHECK( gkyl_range_is_sub_range(&defr) ); + TEST_CHECK(gkyl_range_is_sub_range(&defr)); + + TEST_CHECK(defr.ndim == 2); + TEST_CHECK(defr.volume == 200); - TEST_CHECK( defr.ndim == 2 ); - TEST_CHECK( defr.volume == 200 ); - - TEST_CHECK( defr.lower[0] == lower[0] ); - TEST_CHECK( defr.upper[0] == upper[0] ); - - TEST_CHECK( defr.lower[1] == lower[1] ); - TEST_CHECK( defr.upper[1] == upper[1] ); + TEST_CHECK(defr.lower[0] == lower[0]); + TEST_CHECK(defr.upper[0] == upper[0]); - int idx[3]; idx[2] = locDir[2]; + TEST_CHECK(defr.lower[1] == lower[1]); + TEST_CHECK(defr.upper[1] == upper[1]); + + int idx[3]; + idx[2] = locDir[2]; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &defr); - while (gkyl_range_iter_next(&iter)) { // loop over deflated region. - idx[0] = iter.idx[0]; idx[1] = iter.idx[1]; - TEST_CHECK( - gkyl_range_idx(&defr, iter.idx) == gkyl_range_idx(&range, idx) - ); + while (gkyl_range_iter_next(&iter)) { // loop over deflated region. + idx[0] = iter.idx[0]; + idx[1] = iter.idx[1]; + TEST_CHECK(gkyl_range_idx(&defr, iter.idx) == gkyl_range_idx(&range, idx)); } // Remove first dimension. - remDir[0] = 1; remDir[1] = 0; remDir[2] = 0; - locDir[0] = 3; locDir[1] = 0; locDir[2] = 0; + remDir[0] = 1; + remDir[1] = 0; + remDir[2] = 0; + locDir[0] = 3; + locDir[1] = 0; + locDir[2] = 0; gkyl_range_deflate(&defr, &range, remDir, locDir); idx[0] = locDir[0]; gkyl_range_iter_init(&iter, &defr); - while (gkyl_range_iter_next(&iter)) { // loop over deflated region - idx[1] = iter.idx[0]; idx[2] = iter.idx[1]; - TEST_CHECK( - gkyl_range_idx(&defr, iter.idx) == gkyl_range_idx(&range, idx) - ); + while (gkyl_range_iter_next(&iter)) { // loop over deflated region + idx[1] = iter.idx[0]; + idx[2] = iter.idx[1]; + TEST_CHECK(gkyl_range_idx(&defr, iter.idx) == gkyl_range_idx(&range, idx)); } // remove two directions - remDir[0] = 0; remDir[1] = 1; remDir[2] = 1; - locDir[0] = 0; locDir[1] = upper[1]; locDir[2] = lower[2]; + remDir[0] = 0; + remDir[1] = 1; + remDir[2] = 1; + locDir[0] = 0; + locDir[1] = upper[1]; + locDir[2] = lower[2]; gkyl_range_deflate(&defr, &range, remDir, locDir); - TEST_CHECK( defr.ndim == 1 ); - TEST_CHECK( defr.volume == 10 ); - - TEST_CHECK( defr.lower[0] == lower[0] ); - TEST_CHECK( defr.upper[0] == upper[0] ); - - idx[1] = locDir[1]; idx[2] = locDir[2]; + TEST_CHECK(defr.ndim == 1); + TEST_CHECK(defr.volume == 10); + + TEST_CHECK(defr.lower[0] == lower[0]); + TEST_CHECK(defr.upper[0] == upper[0]); + + idx[1] = locDir[1]; + idx[2] = locDir[2]; gkyl_range_iter_init(&iter, &defr); - while (gkyl_range_iter_next(&iter)) { // loop over deflated region + while (gkyl_range_iter_next(&iter)) { // loop over deflated region idx[0] = iter.idx[0]; - TEST_CHECK( - gkyl_range_idx(&defr, iter.idx) == gkyl_range_idx(&range, idx) - ); + TEST_CHECK(gkyl_range_idx(&defr, iter.idx) == gkyl_range_idx(&range, idx)); } // remove all three directions - remDir[0] = 1; remDir[1] = 1; remDir[2] = 1; - locDir[0] = 5; locDir[1] = upper[1]; locDir[2] = lower[2]; + remDir[0] = 1; + remDir[1] = 1; + remDir[2] = 1; + locDir[0] = 5; + locDir[1] = upper[1]; + locDir[2] = lower[2]; gkyl_range_deflate(&defr, &range, remDir, locDir); - TEST_CHECK( defr.ndim == 0 ); - TEST_CHECK( defr.volume == 1 ); - - idx[0] = 5; idx[1] = upper[1]; idx[2] = lower[2]; + TEST_CHECK(defr.ndim == 0); + TEST_CHECK(defr.volume == 1); + + idx[0] = 5; + idx[1] = upper[1]; + idx[2] = lower[2]; gkyl_range_iter_init(&iter, &defr); - while (gkyl_range_iter_next(&iter)) { // loop over deflated region - TEST_CHECK( - gkyl_range_idx(&defr, iter.idx) == gkyl_range_idx(&range, idx) - ); + while (gkyl_range_iter_next(&iter)) { // loop over deflated region + TEST_CHECK(gkyl_range_idx(&defr, iter.idx) == gkyl_range_idx(&range, idx)); } } @@ -750,26 +815,26 @@ void test_range_skip_iter_ho() struct gkyl_range range; gkyl_range_init(&range, 3, lower, upper); - // skip iter for full range + // skip iter for full range struct gkyl_range_skip_iter skip; gkyl_range_skip_iter_init(&skip, &range); - TEST_CHECK( skip.delta == range.volume ); - TEST_CHECK( skip.range.ndim == 0 ); - TEST_CHECK( skip.range.volume == 1 ); - TEST_CHECK( gkyl_range_idx(&skip.range, NULL) == 0 ); + TEST_CHECK(skip.delta == range.volume); + TEST_CHECK(skip.range.ndim == 0); + TEST_CHECK(skip.range.volume == 1); + TEST_CHECK(gkyl_range_idx(&skip.range, NULL) == 0); // --- int lowerSub[] = {1, 1, 1}, upperSub[] = {4, 8, 16}; struct gkyl_range localRange; gkyl_sub_range_init(&localRange, &range, lowerSub, upperSub); - // skip iter for local range + // skip iter for local range gkyl_range_skip_iter_init(&skip, &localRange); - TEST_CHECK( skip.delta == 16 ); - TEST_CHECK( skip.delta*skip.range.volume == localRange.volume ); - TEST_CHECK( skip.range.ndim == 2 ); + TEST_CHECK(skip.delta == 16); + TEST_CHECK(skip.delta * skip.range.volume == localRange.volume); + TEST_CHECK(skip.range.ndim == 2); long count = 0; // loops are an outer while loop, with an inner for loop @@ -777,10 +842,11 @@ void test_range_skip_iter_ho() gkyl_range_iter_init(&iter, &skip.range); while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&skip.range, iter.idx); - for (long i=start; i #include #include - int cu_range_test(const struct gkyl_range rng); +int cu_range_test(const struct gkyl_range rng); } -__global__ -void ker_cu_range_test(const struct gkyl_range rng, int *nfail) +__global__ void ker_cu_range_test(const struct gkyl_range rng, int *nfail) { *nfail = 0; int lower[] = {0, 0}, upper[] = {24, 49}; - GKYL_CU_CHECK( rng.ndim == 2, nfail ); - GKYL_CU_CHECK( rng.volume == 25*50, nfail ); + GKYL_CU_CHECK(rng.ndim == 2, nfail); + GKYL_CU_CHECK(rng.volume == 25 * 50, nfail); - for (unsigned i=0; i<2; ++i) { - GKYL_CU_CHECK( rng.lower[i] == lower[i], nfail ); - GKYL_CU_CHECK( rng.upper[i] == upper[i], nfail ); - } + for (unsigned i = 0; i < 2; ++i) { + GKYL_CU_CHECK(rng.lower[i] == lower[i], nfail); + GKYL_CU_CHECK(rng.upper[i] == upper[i], nfail); + } } int cu_range_test(const struct gkyl_range rng) { - int *nfail_dev = (int *) gkyl_cu_malloc(sizeof(int)); - ker_cu_range_test<<<1,1>>>(rng, nfail_dev); + int *nfail_dev = (int *)gkyl_cu_malloc(sizeof(int)); + ker_cu_range_test<<<1, 1> > >(rng, nfail_dev); int nfail; gkyl_cu_memcpy(&nfail, nfail_dev, sizeof(int), GKYL_CU_MEMCPY_D2H); gkyl_cu_free(nfail_dev); - return nfail; + return nfail; } - - diff --git a/core/unit/ctest_rect_decomp.c b/core/unit/ctest_rect_decomp.c index 046a26ed2c..3257364224 100644 --- a/core/unit/ctest_rect_decomp.c +++ b/core/unit/ctest_rect_decomp.c @@ -5,201 +5,199 @@ void test_rect_decomp_ranges_1d_ho() { - double lower[] = { 1.0 }, upper[] = {2.5 }; - int cells[] = { 20 }; + double lower[] = {1.0}, upper[] = {2.5}; + int cells[] = {20}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 1, lower, upper, cells); - int nghost[] = { 1 }; + int nghost[] = {1}; struct gkyl_range ext_range, range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); - TEST_CHECK( ext_range.ndim == 1 ); - TEST_CHECK( ext_range.volume == 22 ); - TEST_CHECK( ext_range.lower[0] == 0 ); - TEST_CHECK( ext_range.upper[0] == 21 ); + TEST_CHECK(ext_range.ndim == 1); + TEST_CHECK(ext_range.volume == 22); + TEST_CHECK(ext_range.lower[0] == 0); + TEST_CHECK(ext_range.upper[0] == 21); - TEST_CHECK( range.ndim == 1 ); - TEST_CHECK( range.volume == 20 ); - TEST_CHECK( range.lower[0] == 1 ); - TEST_CHECK( range.upper[0] == 20 ); + TEST_CHECK(range.ndim == 1); + TEST_CHECK(range.volume == 20); + TEST_CHECK(range.lower[0] == 1); + TEST_CHECK(range.upper[0] == 20); - TEST_CHECK( gkyl_range_is_sub_range(&range) == 1 ); + TEST_CHECK(gkyl_range_is_sub_range(&range) == 1); } void test_rect_decomp_ranges_2d_ho() { - double lower[] = { 1.0, 1.0 }, upper[] = { 2.5, 5.0 }; - int cells[] = { 20, 40 }; + double lower[] = {1.0, 1.0}, upper[] = {2.5, 5.0}; + int cells[] = {20, 40}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 2, lower, upper, cells); - int nghost[] = { 1, 0 }; + int nghost[] = {1, 0}; struct gkyl_range ext_range, range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); - TEST_CHECK( ext_range.ndim == 2 ); - TEST_CHECK( ext_range.volume == 22*40 ); - TEST_CHECK( ext_range.lower[0] == 0 ); - TEST_CHECK( ext_range.upper[0] == 21 ); - TEST_CHECK( ext_range.lower[1] == 1 ); - TEST_CHECK( ext_range.upper[1] == 40 ); - - TEST_CHECK( range.ndim == 2 ); - TEST_CHECK( range.volume == 20*40 ); - TEST_CHECK( range.lower[0] == 1 ); - TEST_CHECK( range.upper[0] == 20 ); - TEST_CHECK( range.lower[1] == 1 ); - TEST_CHECK( range.upper[1] == 40 ); - - TEST_CHECK( gkyl_range_is_sub_range(&range) == 1 ); + TEST_CHECK(ext_range.ndim == 2); + TEST_CHECK(ext_range.volume == 22 * 40); + TEST_CHECK(ext_range.lower[0] == 0); + TEST_CHECK(ext_range.upper[0] == 21); + TEST_CHECK(ext_range.lower[1] == 1); + TEST_CHECK(ext_range.upper[1] == 40); + + TEST_CHECK(range.ndim == 2); + TEST_CHECK(range.volume == 20 * 40); + TEST_CHECK(range.lower[0] == 1); + TEST_CHECK(range.upper[0] == 20); + TEST_CHECK(range.lower[1] == 1); + TEST_CHECK(range.upper[1] == 40); + + TEST_CHECK(gkyl_range_is_sub_range(&range) == 1); } void test_rect_decomp_ranges_3d_ho() { - double lower[] = { 1.0, 1.0, 1.0 }, upper[] = { 2.5, 5.0, 2.0 }; - int cells[] = { 20, 40, 10 }; + double lower[] = {1.0, 1.0, 1.0}, upper[] = {2.5, 5.0, 2.0}; + int cells[] = {20, 40, 10}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 3, lower, upper, cells); - int nghost[] = { 1, 0, 2 }; + int nghost[] = {1, 0, 2}; struct gkyl_range ext_range, range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); - TEST_CHECK( ext_range.ndim == 3 ); - TEST_CHECK( ext_range.volume == 22*40*14 ); - TEST_CHECK( ext_range.lower[0] == 0 ); - TEST_CHECK( ext_range.upper[0] == 21 ); - TEST_CHECK( ext_range.lower[1] == 1 ); - TEST_CHECK( ext_range.upper[1] == 40 ); - TEST_CHECK( ext_range.lower[2] == -1 ); - TEST_CHECK( ext_range.upper[2] == 12 ); - - TEST_CHECK( range.ndim == 3 ); - TEST_CHECK( range.volume == 20*40*10 ); - TEST_CHECK( range.lower[0] == 1 ); - TEST_CHECK( range.upper[0] == 20 ); - TEST_CHECK( range.lower[1] == 1 ); - TEST_CHECK( range.upper[1] == 40 ); - TEST_CHECK( range.lower[2] == 1 ); - TEST_CHECK( range.upper[2] == 10 ); - - TEST_CHECK( gkyl_range_is_sub_range(&range) == 1 ); - + TEST_CHECK(ext_range.ndim == 3); + TEST_CHECK(ext_range.volume == 22 * 40 * 14); + TEST_CHECK(ext_range.lower[0] == 0); + TEST_CHECK(ext_range.upper[0] == 21); + TEST_CHECK(ext_range.lower[1] == 1); + TEST_CHECK(ext_range.upper[1] == 40); + TEST_CHECK(ext_range.lower[2] == -1); + TEST_CHECK(ext_range.upper[2] == 12); + + TEST_CHECK(range.ndim == 3); + TEST_CHECK(range.volume == 20 * 40 * 10); + TEST_CHECK(range.lower[0] == 1); + TEST_CHECK(range.upper[0] == 20); + TEST_CHECK(range.lower[1] == 1); + TEST_CHECK(range.upper[1] == 40); + TEST_CHECK(range.lower[2] == 1); + TEST_CHECK(range.upper[2] == 10); + + TEST_CHECK(gkyl_range_is_sub_range(&range) == 1); } -static void -test_rect_decomp_ranges_from_range_2d_ho(void) +static void test_rect_decomp_ranges_from_range_2d_ho(void) { struct gkyl_range inlocal; - gkyl_range_init(&inlocal, 2, (int[]) { 1, 2 }, (int[]) { 10, 20 }); + gkyl_range_init(&inlocal, 2, (int[]){1, 2}, (int[]){10, 20}); struct gkyl_range local, local_ext; - gkyl_create_ranges(&inlocal, (int[]) { 2, 1 }, &local_ext, &local); - - TEST_CHECK( local.ndim == inlocal.ndim ); - TEST_CHECK( local_ext.ndim == inlocal.ndim ); - - for (int i=0; indim == 2 ); - TEST_CHECK( decomp->ndecomp == cuts[0]*cuts[1] ); + TEST_CHECK(decomp->ndim == 2); + TEST_CHECK(decomp->ndecomp == cuts[0] * cuts[1]); - TEST_CHECK( gkyl_range_compare(&range, &decomp->parent_range) ); + TEST_CHECK(gkyl_range_compare(&range, &decomp->parent_range)); long vol = 0; - for (int i=0; indecomp; ++i) + for (int i = 0; i < decomp->ndecomp; ++i) { vol += decomp->ranges[i].volume; + } - TEST_CHECK( vol == range.volume ); - TEST_CHECK( gkyl_rect_decomp_check_covering(decomp) ); + TEST_CHECK(vol == range.volume); + TEST_CHECK(gkyl_rect_decomp_check_covering(decomp)); long offs = 0; - for (int i=0; indecomp; ++i) { - TEST_CHECK( offs == gkyl_rect_decomp_calc_offset(decomp, i) ); + for (int i = 0; i < decomp->ndecomp; ++i) { + TEST_CHECK(offs == gkyl_rect_decomp_calc_offset(decomp, i)); offs += decomp->ranges[i].volume; } @@ -209,50 +207,48 @@ test_rect_decomp_2d_ho(void) // check decomposition without corner neighbors gkyl_range_iter_init(&iter, &crange); - while ( gkyl_range_iter_next(&iter) ) { - + while (gkyl_range_iter_next(&iter)) { struct gkyl_rect_decomp_neigh *neigh = gkyl_rect_decomp_calc_neigh(decomp, false, gkyl_range_idx(&crange, iter.idx)); - - if (is_on_corner(2, iter.idx, cuts)) - TEST_CHECK( neigh->num_neigh == 2 ); - else if (is_on_face(2, iter.idx, cuts) ) - TEST_CHECK( neigh->num_neigh == 3 ); - else - TEST_CHECK( neigh->num_neigh == 4 ); + + if (is_on_corner(2, iter.idx, cuts)) { + TEST_CHECK(neigh->num_neigh == 2); + } else if (is_on_face(2, iter.idx, cuts)) { + TEST_CHECK(neigh->num_neigh == 3); + } else { + TEST_CHECK(neigh->num_neigh == 4); + } gkyl_rect_decomp_neigh_release(neigh); } // check decomposition with corner neighbors gkyl_range_iter_init(&iter, &crange); - while ( gkyl_range_iter_next(&iter) ) { - + while (gkyl_range_iter_next(&iter)) { struct gkyl_rect_decomp_neigh *neigh = gkyl_rect_decomp_calc_neigh(decomp, true, gkyl_range_idx(&crange, iter.idx)); - if (is_on_corner(2, iter.idx, cuts)) - TEST_CHECK( neigh->num_neigh == 3 ); - else if (is_on_face(2, iter.idx, cuts) ) - TEST_CHECK( neigh->num_neigh == 5 ); - else - TEST_CHECK( neigh->num_neigh == 8 ); + if (is_on_corner(2, iter.idx, cuts)) { + TEST_CHECK(neigh->num_neigh == 3); + } else if (is_on_face(2, iter.idx, cuts)) { + TEST_CHECK(neigh->num_neigh == 5); + } else { + TEST_CHECK(neigh->num_neigh == 8); + } gkyl_rect_decomp_neigh_release(neigh); } // check dir and edge without corners - for (int i=0; indecomp; ++i) { - struct gkyl_rect_decomp_neigh *neigh = - gkyl_rect_decomp_calc_neigh(decomp, false, i); + for (int i = 0; i < decomp->ndecomp; ++i) { + struct gkyl_rect_decomp_neigh *neigh = gkyl_rect_decomp_calc_neigh(decomp, false, i); - for (int n=0; nnum_neigh; ++n) { + for (int n = 0; n < neigh->num_neigh; ++n) { struct gkyl_range_dir_edge dir_ed = - gkyl_range_edge_match(&decomp->ranges[i], - &decomp->ranges[neigh->neigh[n]]); - - TEST_CHECK( dir_ed.dir == neigh->dir[n] ); - TEST_CHECK( dir_ed.eloc == neigh->edge[n] ); + gkyl_range_edge_match(&decomp->ranges[i], &decomp->ranges[neigh->neigh[n]]); + + TEST_CHECK(dir_ed.dir == neigh->dir[n]); + TEST_CHECK(dir_ed.eloc == neigh->edge[n]); } gkyl_rect_decomp_neigh_release(neigh); @@ -261,32 +257,33 @@ test_rect_decomp_2d_ho(void) // Check the method to get cuts. int cuts_new[decomp->ndim]; gkyl_rect_decomp_get_cuts(decomp, cuts_new); - for (int d=0; dndim; d++) - TEST_CHECK( cuts_new[d] == cuts[d] ); + for (int d = 0; d < decomp->ndim; d++) { + TEST_CHECK(cuts_new[d] == cuts[d]); + } gkyl_rect_decomp_release(decomp); } -static void -test_rect_decomp_3d_ho(void) +static void test_rect_decomp_3d_ho(void) { struct gkyl_range range; - gkyl_range_init(&range, 3, (int[]) { 1, 2, 3 }, (int[]) { 100, 200, 300 }); - - int cuts[] = { 5, 6, 7 }; + gkyl_range_init(&range, 3, (int[]){1, 2, 3}, (int[]){100, 200, 300}); + + int cuts[] = {5, 6, 7}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(3, cuts, &range); - TEST_CHECK( decomp->ndim == 3 ); - TEST_CHECK( decomp->ndecomp == cuts[0]*cuts[1]*cuts[2] ); + TEST_CHECK(decomp->ndim == 3); + TEST_CHECK(decomp->ndecomp == cuts[0] * cuts[1] * cuts[2]); - TEST_CHECK( gkyl_range_compare(&range, &decomp->parent_range) ); + TEST_CHECK(gkyl_range_compare(&range, &decomp->parent_range)); long vol = 0; - for (int i=0; indecomp; ++i) + for (int i = 0; i < decomp->ndecomp; ++i) { vol += decomp->ranges[i].volume; + } - TEST_CHECK( vol == range.volume ); - TEST_CHECK( gkyl_rect_decomp_check_covering(decomp) ); + TEST_CHECK(vol == range.volume); + TEST_CHECK(gkyl_rect_decomp_check_covering(decomp)); struct gkyl_range crange; gkyl_range_init_from_shape(&crange, 3, cuts); @@ -294,123 +291,121 @@ test_rect_decomp_3d_ho(void) // check decomposition without corner neighbors gkyl_range_iter_init(&iter, &crange); - while ( gkyl_range_iter_next(&iter) ) { - + while (gkyl_range_iter_next(&iter)) { struct gkyl_rect_decomp_neigh *neigh = gkyl_rect_decomp_calc_neigh(decomp, false, gkyl_range_idx(&crange, iter.idx)); - - if (is_on_corner(3, iter.idx, cuts)) - TEST_CHECK( neigh->num_neigh == 3 ); - else if (is_on_edge(3, iter.idx, cuts) ) - TEST_CHECK( neigh->num_neigh == 4 ); - else if (is_on_face(3, iter.idx, cuts) ) - TEST_CHECK( neigh->num_neigh == 5 ); - else - TEST_CHECK( neigh->num_neigh == 6 ); + + if (is_on_corner(3, iter.idx, cuts)) { + TEST_CHECK(neigh->num_neigh == 3); + } else if (is_on_edge(3, iter.idx, cuts)) { + TEST_CHECK(neigh->num_neigh == 4); + } else if (is_on_face(3, iter.idx, cuts)) { + TEST_CHECK(neigh->num_neigh == 5); + } else { + TEST_CHECK(neigh->num_neigh == 6); + } gkyl_rect_decomp_neigh_release(neigh); } // check decomposition with corner neighbors gkyl_range_iter_init(&iter, &crange); - while ( gkyl_range_iter_next(&iter) ) { - + while (gkyl_range_iter_next(&iter)) { struct gkyl_rect_decomp_neigh *neigh = gkyl_rect_decomp_calc_neigh(decomp, true, gkyl_range_idx(&crange, iter.idx)); - - if (is_on_corner(3, iter.idx, cuts)) - TEST_CHECK( neigh->num_neigh == 7 ); - else if (is_on_edge(3, iter.idx, cuts) ) - TEST_CHECK( neigh->num_neigh == 11 ); - else if (is_on_face(3, iter.idx, cuts) ) - TEST_CHECK( neigh->num_neigh == 17 ); - else - TEST_CHECK( neigh->num_neigh == 26 ); + + if (is_on_corner(3, iter.idx, cuts)) { + TEST_CHECK(neigh->num_neigh == 7); + } else if (is_on_edge(3, iter.idx, cuts)) { + TEST_CHECK(neigh->num_neigh == 11); + } else if (is_on_face(3, iter.idx, cuts)) { + TEST_CHECK(neigh->num_neigh == 17); + } else { + TEST_CHECK(neigh->num_neigh == 26); + } gkyl_rect_decomp_neigh_release(neigh); - } + } // check dir and edge without corners - for (int i=0; indecomp; ++i) { - struct gkyl_rect_decomp_neigh *neigh = - gkyl_rect_decomp_calc_neigh(decomp, false, i); + for (int i = 0; i < decomp->ndecomp; ++i) { + struct gkyl_rect_decomp_neigh *neigh = gkyl_rect_decomp_calc_neigh(decomp, false, i); - for (int n=0; nnum_neigh; ++n) { + for (int n = 0; n < neigh->num_neigh; ++n) { struct gkyl_range_dir_edge dir_ed = - gkyl_range_edge_match(&decomp->ranges[i], - &decomp->ranges[neigh->neigh[n]]); - - TEST_CHECK( dir_ed.dir == neigh->dir[n] ); - TEST_CHECK( dir_ed.eloc == neigh->edge[n] ); + gkyl_range_edge_match(&decomp->ranges[i], &decomp->ranges[neigh->neigh[n]]); + + TEST_CHECK(dir_ed.dir == neigh->dir[n]); + TEST_CHECK(dir_ed.eloc == neigh->edge[n]); } gkyl_rect_decomp_neigh_release(neigh); - } - + } + // Check the method to get cuts. int cuts_new[decomp->ndim]; gkyl_rect_decomp_get_cuts(decomp, cuts_new); - for (int d=0; dndim; d++) - TEST_CHECK( cuts_new[d] == cuts[d] ); + for (int d = 0; d < decomp->ndim; d++) { + TEST_CHECK(cuts_new[d] == cuts[d]); + } gkyl_rect_decomp_release(decomp); } -static void -test_rect_decomp_4d_ho(void) +static void test_rect_decomp_4d_ho(void) { struct gkyl_range range; - gkyl_range_init(&range, 4, (int[]) { 1, 2, 3, 4 }, (int[]) { 10, 20, 30, 40 }); - - int cuts[] = { 2, 1, 3, 4 }; + gkyl_range_init(&range, 4, (int[]){1, 2, 3, 4}, (int[]){10, 20, 30, 40}); + + int cuts[] = {2, 1, 3, 4}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(4, cuts, &range); - TEST_CHECK( decomp->ndim == 4 ); - TEST_CHECK( decomp->ndecomp == cuts[0]*cuts[1]*cuts[2]*cuts[3] ); + TEST_CHECK(decomp->ndim == 4); + TEST_CHECK(decomp->ndecomp == cuts[0] * cuts[1] * cuts[2] * cuts[3]); - TEST_CHECK( gkyl_range_compare(&range, &decomp->parent_range) ); + TEST_CHECK(gkyl_range_compare(&range, &decomp->parent_range)); long vol = 0; - for (int i=0; indecomp; ++i) + for (int i = 0; i < decomp->ndecomp; ++i) { vol += decomp->ranges[i].volume; + } - TEST_CHECK( vol == range.volume ); - TEST_CHECK( gkyl_rect_decomp_check_covering(decomp) ); + TEST_CHECK(vol == range.volume); + TEST_CHECK(gkyl_rect_decomp_check_covering(decomp)); // Check the method to get cuts. int cuts_new[decomp->ndim]; gkyl_rect_decomp_get_cuts(decomp, cuts_new); - for (int d=0; dndim; d++) - TEST_CHECK( cuts_new[d] == cuts[d] ); + for (int d = 0; d < decomp->ndim; d++) { + TEST_CHECK(cuts_new[d] == cuts[d]); + } gkyl_rect_decomp_release(decomp); } -static void -test_rect_decomp_per_2d_ho(void) +static void test_rect_decomp_per_2d_ho(void) { struct gkyl_range range; - gkyl_range_init(&range, 2, (int[]) { 1, 2 }, (int[]) { 100, 100 }); - - int cuts[GKYL_MAX_DIM] = { 3, 3 }; + gkyl_range_init(&range, 2, (int[]){1, 2}, (int[]){100, 100}); + + int cuts[GKYL_MAX_DIM] = {3, 3}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); struct gkyl_range crange; - gkyl_range_init_from_shape(&crange, 2, cuts); + gkyl_range_init_from_shape(&crange, 2, cuts); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &crange); - while ( gkyl_range_iter_next(&iter) ) { - - for (int d=0; dnum_neigh == 1 ); + TEST_CHECK(neigh->num_neigh == 1); } - + gkyl_rect_decomp_neigh_release(neigh); } } @@ -418,37 +413,36 @@ test_rect_decomp_per_2d_ho(void) // Check the method to get cuts. int cuts_new[decomp->ndim]; gkyl_rect_decomp_get_cuts(decomp, cuts_new); - for (int d=0; dndim; d++) - TEST_CHECK( cuts_new[d] == cuts[d] ); + for (int d = 0; d < decomp->ndim; d++) { + TEST_CHECK(cuts_new[d] == cuts[d]); + } gkyl_rect_decomp_release(decomp); } -static void -test_rect_decomp_per_2d_2_ho(void) +static void test_rect_decomp_per_2d_2_ho(void) { struct gkyl_range range; - gkyl_range_init(&range, 2, (int[]) { 1, 2 }, (int[]) { 100, 100 }); - - int cuts[] = { 1, 2 }; + gkyl_range_init(&range, 2, (int[]){1, 2}, (int[]){100, 100}); + + int cuts[] = {1, 2}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); struct gkyl_range crange; - gkyl_range_init_from_shape(&crange, 2, cuts); + gkyl_range_init_from_shape(&crange, 2, cuts); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &crange); - while ( gkyl_range_iter_next(&iter) ) { - - for (int d=0; dnum_neigh == 1 ); + TEST_CHECK(neigh->num_neigh == 1); } - + gkyl_rect_decomp_neigh_release(neigh); } } @@ -456,37 +450,36 @@ test_rect_decomp_per_2d_2_ho(void) // Check the method to get cuts. int cuts_new[decomp->ndim]; gkyl_rect_decomp_get_cuts(decomp, cuts_new); - for (int d=0; dndim; d++) - TEST_CHECK( cuts_new[d] == cuts[d] ); + for (int d = 0; d < decomp->ndim; d++) { + TEST_CHECK(cuts_new[d] == cuts[d]); + } gkyl_rect_decomp_release(decomp); } -static void -test_rect_decomp_per_2d_corner_ho(void) +static void test_rect_decomp_per_2d_corner_ho(void) { struct gkyl_range range; - gkyl_range_init(&range, 2, (int[]) { 1, 2 }, (int[]) { 100, 100 }); - - int cuts[] = { 2, 2 }; + gkyl_range_init(&range, 2, (int[]){1, 2}, (int[]){100, 100}); + + int cuts[] = {2, 2}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); struct gkyl_range crange; - gkyl_range_init_from_shape(&crange, 2, cuts); + gkyl_range_init_from_shape(&crange, 2, cuts); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &crange); - while ( gkyl_range_iter_next(&iter) ) { - - for (int d=0; dnum_neigh == 2 ); // each domain has 2 neighbors + TEST_CHECK(neigh->num_neigh == 2); // each domain has 2 neighbors } - + gkyl_rect_decomp_neigh_release(neigh); } } @@ -494,19 +487,19 @@ test_rect_decomp_per_2d_corner_ho(void) // Check the method to get cuts. int cuts_new[decomp->ndim]; gkyl_rect_decomp_get_cuts(decomp, cuts_new); - for (int d=0; dndim; d++) - TEST_CHECK( cuts_new[d] == cuts[d] ); + for (int d = 0; d < decomp->ndim; d++) { + TEST_CHECK(cuts_new[d] == cuts[d]); + } gkyl_rect_decomp_release(decomp); } -static void -test_rect_decomp_per_3d_ho(void) +static void test_rect_decomp_per_3d_ho(void) { struct gkyl_range range; - gkyl_range_init(&range, 3, (int[]) { 1, 1, 1 }, (int[]) { 100, 100, 100 }); - - int cuts[] = { 3, 3, 3 }; + gkyl_range_init(&range, 3, (int[]){1, 1, 1}, (int[]){100, 100, 100}); + + int cuts[] = {3, 3, 3}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); struct gkyl_range crange; @@ -515,16 +508,15 @@ test_rect_decomp_per_3d_ho(void) struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &crange); - while ( gkyl_range_iter_next(&iter) ) { - - for (int d=0; dnum_neigh == 1 ); + TEST_CHECK(neigh->num_neigh == 1); } - + gkyl_rect_decomp_neigh_release(neigh); } } @@ -532,97 +524,97 @@ test_rect_decomp_per_3d_ho(void) // Check the method to get cuts. int cuts_new[decomp->ndim]; gkyl_rect_decomp_get_cuts(decomp, cuts_new); - for (int d=0; dndim; d++) - TEST_CHECK( cuts_new[d] == cuts[d] ); + for (int d = 0; d < decomp->ndim; d++) { + TEST_CHECK(cuts_new[d] == cuts[d]); + } - gkyl_rect_decomp_release(decomp); + gkyl_rect_decomp_release(decomp); } -static void -test_rect_decomp_2d_2v_ho(void) +static void test_rect_decomp_2d_2v_ho(void) { struct gkyl_range range; - gkyl_range_init(&range, 2, (int[]) { 1, 2 }, (int[]) { 100, 100 }); - - int cuts[] = { 5, 6 }; + gkyl_range_init(&range, 2, (int[]){1, 2}, (int[]){100, 100}); + + int cuts[] = {5, 6}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); - TEST_CHECK( decomp->ndim == 2 ); - TEST_CHECK( decomp->ndecomp == cuts[0]*cuts[1] ); + TEST_CHECK(decomp->ndim == 2); + TEST_CHECK(decomp->ndecomp == cuts[0] * cuts[1]); struct gkyl_range vrange; - gkyl_range_init(&vrange, 2, (int[]) { 1, 2 }, (int[]) { 16, 16 }); + gkyl_range_init(&vrange, 2, (int[]){1, 2}, (int[]){16, 16}); - struct gkyl_rect_decomp *ext_decomp = gkyl_rect_decomp_extended_new( - &vrange, decomp); + struct gkyl_rect_decomp *ext_decomp = gkyl_rect_decomp_extended_new(&vrange, decomp); - TEST_CHECK( ext_decomp->ndim == 4 ); - TEST_CHECK( ext_decomp->ndecomp == cuts[0]*cuts[1] ); + TEST_CHECK(ext_decomp->ndim == 4); + TEST_CHECK(ext_decomp->ndecomp == cuts[0] * cuts[1]); - TEST_CHECK( ext_decomp->parent_range.volume = decomp->parent_range.volume*vrange.volume ); - for (int i=0; indecomp; ++i) - TEST_CHECK( ext_decomp->ranges[i].volume == decomp->ranges[i].volume*vrange.volume ); + TEST_CHECK(ext_decomp->parent_range.volume = decomp->parent_range.volume * vrange.volume); + for (int i = 0; i < decomp->ndecomp; ++i) { + TEST_CHECK(ext_decomp->ranges[i].volume == decomp->ranges[i].volume * vrange.volume); + } - for (int i=0; indecomp; ++i) { - - for (int d=0; dranges[d].lower[range.ndim+d] == vrange.lower[d] ); - TEST_CHECK( ext_decomp->ranges[d].upper[range.ndim+d] == vrange.upper[d] ); + for (int i = 0; i < decomp->ndecomp; ++i) { + for (int d = 0; d < vrange.ndim; ++d) { + TEST_CHECK(ext_decomp->ranges[d].lower[range.ndim + d] == vrange.lower[d]); + TEST_CHECK(ext_decomp->ranges[d].upper[range.ndim + d] == vrange.upper[d]); } } // Check the method to get cuts. int cuts_new[decomp->ndim]; gkyl_rect_decomp_get_cuts(decomp, cuts_new); - for (int d=0; dndim; d++) - TEST_CHECK( cuts_new[d] == cuts[d] ); + for (int d = 0; d < decomp->ndim; d++) { + TEST_CHECK(cuts_new[d] == cuts[d]); + } gkyl_rect_decomp_release(decomp); gkyl_rect_decomp_release(ext_decomp); } -static void -test_rect_decomp_from_cuts_and_cells_ho(void) +static void test_rect_decomp_from_cuts_and_cells_ho(void) { - int cuts[] = { 5, 6, 7 }; - int cells[] = { 100, 200, 300 }; + int cuts[] = {5, 6, 7}; + int cells[] = {100, 200, 300}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts_and_cells(3, cuts, cells); - TEST_CHECK( decomp->ndim == 3 ); - TEST_CHECK( decomp->ndecomp == cuts[0]*cuts[1]*cuts[2] ); + TEST_CHECK(decomp->ndim == 3); + TEST_CHECK(decomp->ndecomp == cuts[0] * cuts[1] * cuts[2]); - TEST_CHECK( gkyl_rect_decomp_check_covering(decomp) ); + TEST_CHECK(gkyl_rect_decomp_check_covering(decomp)); // Check the method to get cuts. int cuts_new[decomp->ndim]; gkyl_rect_decomp_get_cuts(decomp, cuts_new); - for (int d=0; dndim; d++) - TEST_CHECK( cuts_new[d] == cuts[d] ); + for (int d = 0; d < decomp->ndim; d++) { + TEST_CHECK(cuts_new[d] == cuts[d]); + } gkyl_rect_decomp_release(decomp); } TEST_LIST = { - { "rect_decomp_ranges_1d_ho", test_rect_decomp_ranges_1d_ho }, - { "rect_decomp_ranges_2d_ho", test_rect_decomp_ranges_2d_ho }, - { "rect_decomp_ranges_3d_ho", test_rect_decomp_ranges_3d_ho }, + {"rect_decomp_ranges_1d_ho", test_rect_decomp_ranges_1d_ho}, + {"rect_decomp_ranges_2d_ho", test_rect_decomp_ranges_2d_ho}, + {"rect_decomp_ranges_3d_ho", test_rect_decomp_ranges_3d_ho}, + + {"rect_decomp_ranges_from_range_2d_ho", test_rect_decomp_ranges_from_range_2d_ho}, + {"rect_decomp_ranges_from_range_3d_ho", test_rect_decomp_ranges_from_range_3d_ho}, - { "rect_decomp_ranges_from_range_2d_ho", test_rect_decomp_ranges_from_range_2d_ho }, - { "rect_decomp_ranges_from_range_3d_ho", test_rect_decomp_ranges_from_range_3d_ho }, + {"rect_decomp_2d_ho", test_rect_decomp_2d_ho}, + {"rect_decomp_3d_ho", test_rect_decomp_3d_ho}, + {"rect_decomp_4d_ho", test_rect_decomp_4d_ho}, - { "rect_decomp_2d_ho", test_rect_decomp_2d_ho }, - { "rect_decomp_3d_ho", test_rect_decomp_3d_ho }, - { "rect_decomp_4d_ho", test_rect_decomp_4d_ho }, + {"rect_decomp_per_2d_ho", test_rect_decomp_per_2d_ho}, + {"rect_decomp_per_2d_2_ho", test_rect_decomp_per_2d_2_ho}, + {"rect_decomp_per_3d_ho", test_rect_decomp_per_3d_ho}, - { "rect_decomp_per_2d_ho", test_rect_decomp_per_2d_ho }, - { "rect_decomp_per_2d_2_ho", test_rect_decomp_per_2d_2_ho }, - { "rect_decomp_per_3d_ho", test_rect_decomp_per_3d_ho }, + {"rect_decomp_per_2d_corner_ho", test_rect_decomp_per_2d_corner_ho}, - { "rect_decomp_per_2d_corner_ho", test_rect_decomp_per_2d_corner_ho }, + {"rect_decomp_2d_2v_ho", test_rect_decomp_2d_2v_ho}, - { "rect_decomp_2d_2v_ho", test_rect_decomp_2d_2v_ho }, + {"rect_decomp_from_cuts_and_cells_ho", test_rect_decomp_from_cuts_and_cells_ho}, - { "rect_decomp_from_cuts_and_cells_ho", test_rect_decomp_from_cuts_and_cells_ho }, - - { NULL, NULL }, + {NULL, NULL} }; diff --git a/core/unit/ctest_rect_grid.c b/core/unit/ctest_rect_grid.c index 34e231eb01..66e944d5a2 100644 --- a/core/unit/ctest_rect_grid.c +++ b/core/unit/ctest_rect_grid.c @@ -11,50 +11,51 @@ void test_grid_2d_ho() struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 2, lower, upper, cells); - TEST_CHECK( grid.ndim == 2 ); - for (int i=0; i #include #include - int cu_rect_grid_test(const struct gkyl_rect_grid grid); +int cu_rect_grid_test(const struct gkyl_rect_grid grid); } -__global__ -void ker_cu_rect_grid_test(const struct gkyl_rect_grid grid, int *nfail) +__global__ void ker_cu_rect_grid_test(const struct gkyl_rect_grid grid, int *nfail) { *nfail = 0; double lower[] = {1.0, 1.0}, upper[] = {2.5, 5.0}; int cells[] = {20, 20}; - GKYL_CU_CHECK( grid.ndim == 2, nfail ); - for (int i=0; i>>(grid, nfail_dev); + int *nfail_dev = (int *)gkyl_cu_malloc(sizeof(int)); + ker_cu_rect_grid_test<<<1, 1> > >(grid, nfail_dev); int nfail; gkyl_cu_memcpy(&nfail, nfail_dev, sizeof(int), GKYL_CU_MEMCPY_D2H); gkyl_cu_free(nfail_dev); - return nfail; + return nfail; } diff --git a/core/unit/ctest_ref_count.c b/core/unit/ctest_ref_count.c index ea5aa4dfa8..d75011c808 100644 --- a/core/unit/ctest_ref_count.c +++ b/core/unit/ctest_ref_count.c @@ -2,7 +2,6 @@ #include #include - // global to indicate if free was called static int free_called = 0; @@ -11,53 +10,45 @@ struct range { struct gkyl_ref_count ref_count; }; -void -range_free(const struct gkyl_ref_count* rc) +void range_free(const struct gkyl_ref_count *rc) { struct range *on_dev = container_of(rc, struct range, ref_count); free_called = 1; gkyl_free(on_dev); } -struct range* -range_new(int value) +struct range *range_new(int value) { struct range *rng = gkyl_malloc(sizeof(*rng)); rng->value = value; - rng->ref_count = (struct gkyl_ref_count) { range_free, 1 }; + rng->ref_count = (struct gkyl_ref_count){range_free, 1}; return rng; } -struct range* -range_acquire(const struct range *rng) +struct range *range_acquire(const struct range *rng) { gkyl_ref_count_inc(&rng->ref_count); - return (struct range*) rng; + return (struct range *)rng; } -void -range_release(const struct range *rng) +void range_release(const struct range *rng) { gkyl_ref_count_dec(&rng->ref_count); } -void -test_ref_count_ho() +void test_ref_count_ho() { struct range *rng = range_new(10); - TEST_CHECK( rng->ref_count.count == 1 ); + TEST_CHECK(rng->ref_count.count == 1); struct range *rngp = range_acquire(rng); - TEST_CHECK( rng->ref_count.count == 2 ); + TEST_CHECK(rng->ref_count.count == 2); range_release(rngp); - TEST_CHECK( rng->ref_count.count == 1 ); + TEST_CHECK(rng->ref_count.count == 1); range_release(rngp); - TEST_CHECK( free_called == 1 ); + TEST_CHECK(free_called == 1); } -TEST_LIST = { - { "ref_count_ho", test_ref_count_ho }, - { NULL, NULL }, -}; +TEST_LIST = {{"ref_count_ho", test_ref_count_ho}, {NULL, NULL}}; diff --git a/core/unit/ctest_rrobin_decomp.c b/core/unit/ctest_rrobin_decomp.c index 34304cf8dd..c57418b549 100644 --- a/core/unit/ctest_rrobin_decomp.c +++ b/core/unit/ctest_rrobin_decomp.c @@ -2,214 +2,200 @@ #include -static void -test_rrobin_decomp_1_ho(void) +static void test_rrobin_decomp_1_ho(void) { - const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(1, 3, - (int[]) { 1, 1, 1 }); + const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(1, 3, (int[]){1, 1, 1}); - TEST_CHECK( 1 == rr->total_ranks ); - TEST_CHECK( 3 == rr->nblocks ); + TEST_CHECK(1 == rr->total_ranks); + TEST_CHECK(3 == rr->nblocks); int b0_ranks[1]; gkyl_rrobin_decomp_getranks(rr, 0, b0_ranks); - TEST_CHECK( 0 == b0_ranks[0] ); + TEST_CHECK(0 == b0_ranks[0]); int b1_ranks[1]; gkyl_rrobin_decomp_getranks(rr, 1, b1_ranks); - TEST_CHECK( 0 == b1_ranks[0] ); + TEST_CHECK(0 == b1_ranks[0]); int b2_ranks[1]; gkyl_rrobin_decomp_getranks(rr, 2, b2_ranks); - TEST_CHECK( 0 == b2_ranks[0] ); - + TEST_CHECK(0 == b2_ranks[0]); + gkyl_rrobin_decomp_release(rr); } -static void -test_rrobin_decomp_2_ho(void) +static void test_rrobin_decomp_2_ho(void) { - const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(4, 3, - (int[]) { 4, 1, 1 }); + const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(4, 3, (int[]){4, 1, 1}); - TEST_CHECK( 4 == rr->total_ranks ); - TEST_CHECK( 3 == rr->nblocks ); + TEST_CHECK(4 == rr->total_ranks); + TEST_CHECK(3 == rr->nblocks); int b0_ranks[4]; gkyl_rrobin_decomp_getranks(rr, 0, b0_ranks); - TEST_CHECK( 0 == b0_ranks[0] ); - TEST_CHECK( 1 == b0_ranks[1] ); - TEST_CHECK( 2 == b0_ranks[2] ); - TEST_CHECK( 3 == b0_ranks[3] ); + TEST_CHECK(0 == b0_ranks[0]); + TEST_CHECK(1 == b0_ranks[1]); + TEST_CHECK(2 == b0_ranks[2]); + TEST_CHECK(3 == b0_ranks[3]); int b1_ranks[1]; gkyl_rrobin_decomp_getranks(rr, 1, b1_ranks); - TEST_CHECK( 0 == b1_ranks[0] ); + TEST_CHECK(0 == b1_ranks[0]); int b2_ranks[1]; gkyl_rrobin_decomp_getranks(rr, 2, b2_ranks); - TEST_CHECK( 1 == b2_ranks[0] ); - + TEST_CHECK(1 == b2_ranks[0]); + gkyl_rrobin_decomp_release(rr); } -static void -test_rrobin_decomp_3_ho(void) +static void test_rrobin_decomp_3_ho(void) { - const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(6, 3, - (int[]) { 4, 1, 1 }); + const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(6, 3, (int[]){4, 1, 1}); - TEST_CHECK( 6 == rr->total_ranks ); - TEST_CHECK( 3 == rr->nblocks ); + TEST_CHECK(6 == rr->total_ranks); + TEST_CHECK(3 == rr->nblocks); int b0_ranks[4]; gkyl_rrobin_decomp_getranks(rr, 0, b0_ranks); - TEST_CHECK( 0 == b0_ranks[0] ); - TEST_CHECK( 1 == b0_ranks[1] ); - TEST_CHECK( 2 == b0_ranks[2] ); - TEST_CHECK( 3 == b0_ranks[3] ); + TEST_CHECK(0 == b0_ranks[0]); + TEST_CHECK(1 == b0_ranks[1]); + TEST_CHECK(2 == b0_ranks[2]); + TEST_CHECK(3 == b0_ranks[3]); int b1_ranks[1]; gkyl_rrobin_decomp_getranks(rr, 1, b1_ranks); - TEST_CHECK( 4 == b1_ranks[0] ); + TEST_CHECK(4 == b1_ranks[0]); int b2_ranks[1]; gkyl_rrobin_decomp_getranks(rr, 2, b2_ranks); - TEST_CHECK( 5 == b2_ranks[0] ); - + TEST_CHECK(5 == b2_ranks[0]); + gkyl_rrobin_decomp_release(rr); } -static void -test_rrobin_decomp_4_ho(void) +static void test_rrobin_decomp_4_ho(void) { - const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(6, 3, - (int[]) { 4, 2, 3 }); + const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(6, 3, (int[]){4, 2, 3}); - TEST_CHECK( 6 == rr->total_ranks ); - TEST_CHECK( 3 == rr->nblocks ); + TEST_CHECK(6 == rr->total_ranks); + TEST_CHECK(3 == rr->nblocks); int b0_ranks[4]; gkyl_rrobin_decomp_getranks(rr, 0, b0_ranks); - TEST_CHECK( 0 == b0_ranks[0] ); - TEST_CHECK( 1 == b0_ranks[1] ); - TEST_CHECK( 2 == b0_ranks[2] ); - TEST_CHECK( 3 == b0_ranks[3] ); + TEST_CHECK(0 == b0_ranks[0]); + TEST_CHECK(1 == b0_ranks[1]); + TEST_CHECK(2 == b0_ranks[2]); + TEST_CHECK(3 == b0_ranks[3]); int b1_ranks[2]; gkyl_rrobin_decomp_getranks(rr, 1, b1_ranks); - TEST_CHECK( 4 == b1_ranks[0] ); - TEST_CHECK( 5 == b1_ranks[1] ); + TEST_CHECK(4 == b1_ranks[0]); + TEST_CHECK(5 == b1_ranks[1]); int b2_ranks[3]; gkyl_rrobin_decomp_getranks(rr, 2, b2_ranks); - TEST_CHECK( 0 == b2_ranks[0] ); - TEST_CHECK( 1 == b2_ranks[1] ); - TEST_CHECK( 2 == b2_ranks[2] ); - + TEST_CHECK(0 == b2_ranks[0]); + TEST_CHECK(1 == b2_ranks[1]); + TEST_CHECK(2 == b2_ranks[2]); + gkyl_rrobin_decomp_release(rr); } -static void -test_rrobin_decomp_5_ho(void) +static void test_rrobin_decomp_5_ho(void) { - const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(9, 3, - (int[]) { 4, 2, 3 }); + const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(9, 3, (int[]){4, 2, 3}); - TEST_CHECK( 9 == rr->total_ranks ); - TEST_CHECK( 3 == rr->nblocks ); + TEST_CHECK(9 == rr->total_ranks); + TEST_CHECK(3 == rr->nblocks); int b0_ranks[4]; gkyl_rrobin_decomp_getranks(rr, 0, b0_ranks); - TEST_CHECK( 0 == b0_ranks[0] ); - TEST_CHECK( 1 == b0_ranks[1] ); - TEST_CHECK( 2 == b0_ranks[2] ); - TEST_CHECK( 3 == b0_ranks[3] ); + TEST_CHECK(0 == b0_ranks[0]); + TEST_CHECK(1 == b0_ranks[1]); + TEST_CHECK(2 == b0_ranks[2]); + TEST_CHECK(3 == b0_ranks[3]); int b1_ranks[2]; gkyl_rrobin_decomp_getranks(rr, 1, b1_ranks); - TEST_CHECK( 4 == b1_ranks[0] ); - TEST_CHECK( 5 == b1_ranks[1] ); + TEST_CHECK(4 == b1_ranks[0]); + TEST_CHECK(5 == b1_ranks[1]); int b2_ranks[3]; gkyl_rrobin_decomp_getranks(rr, 2, b2_ranks); - TEST_CHECK( 6 == b2_ranks[0] ); - TEST_CHECK( 7 == b2_ranks[1] ); - TEST_CHECK( 8 == b2_ranks[2] ); - + TEST_CHECK(6 == b2_ranks[0]); + TEST_CHECK(7 == b2_ranks[1]); + TEST_CHECK(8 == b2_ranks[2]); + gkyl_rrobin_decomp_release(rr); } -static void -test_rrobin_decomp_6_ho(void) +static void test_rrobin_decomp_6_ho(void) { - const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(6, 3, - (int[]) { 2, 4, 3 }); + const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(6, 3, (int[]){2, 4, 3}); - TEST_CHECK( 6 == rr->total_ranks ); - TEST_CHECK( 3 == rr->nblocks ); + TEST_CHECK(6 == rr->total_ranks); + TEST_CHECK(3 == rr->nblocks); int b0_ranks[2]; gkyl_rrobin_decomp_getranks(rr, 0, b0_ranks); - TEST_CHECK( 0 == b0_ranks[0] ); - TEST_CHECK( 1 == b0_ranks[1] ); + TEST_CHECK(0 == b0_ranks[0]); + TEST_CHECK(1 == b0_ranks[1]); int b1_ranks[4]; gkyl_rrobin_decomp_getranks(rr, 1, b1_ranks); - TEST_CHECK( 2 == b1_ranks[0] ); - TEST_CHECK( 3 == b1_ranks[1] ); - TEST_CHECK( 4 == b1_ranks[2] ); - TEST_CHECK( 5 == b1_ranks[3] ); + TEST_CHECK(2 == b1_ranks[0]); + TEST_CHECK(3 == b1_ranks[1]); + TEST_CHECK(4 == b1_ranks[2]); + TEST_CHECK(5 == b1_ranks[3]); int b2_ranks[3]; gkyl_rrobin_decomp_getranks(rr, 2, b2_ranks); - TEST_CHECK( 0 == b2_ranks[0] ); - TEST_CHECK( 1 == b2_ranks[1] ); - TEST_CHECK( 2 == b2_ranks[2] ); - + TEST_CHECK(0 == b2_ranks[0]); + TEST_CHECK(1 == b2_ranks[1]); + TEST_CHECK(2 == b2_ranks[2]); + gkyl_rrobin_decomp_release(rr); } -static void -test_rrobin_decomp_7_ho(void) +static void test_rrobin_decomp_7_ho(void) { // this is a rather strange decomposition: only 2 ranks while the // largest block needs 4 ranks for full concurrency - - const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(2, 3, - (int[]) { 2, 4, 3 }); - TEST_CHECK( 2 == rr->total_ranks ); - TEST_CHECK( 3 == rr->nblocks ); + const struct gkyl_rrobin_decomp *rr = gkyl_rrobin_decomp_new(2, 3, (int[]){2, 4, 3}); + + TEST_CHECK(2 == rr->total_ranks); + TEST_CHECK(3 == rr->nblocks); int b0_ranks[2]; gkyl_rrobin_decomp_getranks(rr, 0, b0_ranks); - TEST_CHECK( 0 == b0_ranks[0] ); - TEST_CHECK( 1 == b0_ranks[1] ); + TEST_CHECK(0 == b0_ranks[0]); + TEST_CHECK(1 == b0_ranks[1]); int b1_ranks[4]; gkyl_rrobin_decomp_getranks(rr, 1, b1_ranks); - TEST_CHECK( 0 == b1_ranks[0] ); - TEST_CHECK( 1 == b1_ranks[1] ); - TEST_CHECK( 0 == b1_ranks[2] ); - TEST_CHECK( 1 == b1_ranks[3] ); + TEST_CHECK(0 == b1_ranks[0]); + TEST_CHECK(1 == b1_ranks[1]); + TEST_CHECK(0 == b1_ranks[2]); + TEST_CHECK(1 == b1_ranks[3]); int b2_ranks[3]; gkyl_rrobin_decomp_getranks(rr, 2, b2_ranks); - TEST_CHECK( 0 == b2_ranks[0] ); - TEST_CHECK( 1 == b2_ranks[1] ); - TEST_CHECK( 0 == b2_ranks[2] ); - + TEST_CHECK(0 == b2_ranks[0]); + TEST_CHECK(1 == b2_ranks[1]); + TEST_CHECK(0 == b2_ranks[2]); + gkyl_rrobin_decomp_release(rr); } TEST_LIST = { - { "test_rrobin_decomp_1_ho", test_rrobin_decomp_1_ho }, - { "test_rrobin_decomp_2_ho", test_rrobin_decomp_2_ho }, - { "test_rrobin_decomp_3_ho", test_rrobin_decomp_3_ho }, - { "test_rrobin_decomp_4_ho", test_rrobin_decomp_4_ho }, - { "test_rrobin_decomp_5_ho", test_rrobin_decomp_5_ho }, - { "test_rrobin_decomp_6_ho", test_rrobin_decomp_6_ho }, - { "test_rrobin_decomp_7_ho", test_rrobin_decomp_7_ho }, - { NULL, NULL }, + {"test_rrobin_decomp_1_ho", test_rrobin_decomp_1_ho}, + {"test_rrobin_decomp_2_ho", test_rrobin_decomp_2_ho}, + {"test_rrobin_decomp_3_ho", test_rrobin_decomp_3_ho}, + {"test_rrobin_decomp_4_ho", test_rrobin_decomp_4_ho}, + {"test_rrobin_decomp_5_ho", test_rrobin_decomp_5_ho}, + {"test_rrobin_decomp_6_ho", test_rrobin_decomp_6_ho}, + {"test_rrobin_decomp_7_ho", test_rrobin_decomp_7_ho}, + {NULL, NULL} }; diff --git a/core/unit/ctest_skin_surf_from_ghost.c b/core/unit/ctest_skin_surf_from_ghost.c index 1e067444cd..1af33b383e 100644 --- a/core/unit/ctest_skin_surf_from_ghost.c +++ b/core/unit/ctest_skin_surf_from_ghost.c @@ -10,47 +10,61 @@ #include #include #include -#include +#include // Evaluate the projection of the modal representation inside a cell from 1x to 3x double eval_f(const double *phi, double x, double y, double z, int cdim); // Function to allocate a gkyl array, zero-initialized, on CPU or GPU -static struct gkyl_array* mkarr(bool on_gpu, long nc, long size) { - return on_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) +{ + return on_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); } // Analytical field evaluation function, setting field to zero -void eval_field(double t, const double *xn, double* restrict fout, void *ctx) { +void eval_field(double t, const double *xn, double *restrict fout, void *ctx) +{ fout[0] = 0.0; } // Function to set up and test the ghost-to-skin surface copy updater -void test_ssfg(int cdim, int poly_order, bool use_gpu, enum gkyl_edge_loc edge, int dir, bool control) { +void test_ssfg( + int cdim, int poly_order, bool use_gpu, enum gkyl_edge_loc edge, int dir, bool control +) +{ double lower[cdim], upper[cdim]; int cells[cdim]; - switch(cdim) { - case 3: - lower[0] = 0.0; lower[1] = 0.0; lower[2] = 0.0; - upper[0] = 1.0; upper[1] = 1.0; upper[2] = 1.0; - cells[0] = 2; cells[1] = 4; cells[2] = 6; - break; - case 2: - lower[0] = 0.0; lower[1] = 0.0; - upper[0] = 1.0; upper[1] = 1.0; - cells[0] = 4; cells[1] = 6; - break; - case 1: - lower[0] = 0.0; - upper[0] = 1.0; - cells[0] = 6; - break; - default: - fprintf(stderr, "Invalid cdim value: %d\n", cdim); - exit(1); + switch (cdim) { + case 3: + lower[0] = 0.0; + lower[1] = 0.0; + lower[2] = 0.0; + upper[0] = 1.0; + upper[1] = 1.0; + upper[2] = 1.0; + cells[0] = 2; + cells[1] = 4; + cells[2] = 6; + break; + case 2: + lower[0] = 0.0; + lower[1] = 0.0; + upper[0] = 1.0; + upper[1] = 1.0; + cells[0] = 4; + cells[1] = 6; + break; + case 1: + lower[0] = 0.0; + upper[0] = 1.0; + cells[0] = 6; + break; + default: + fprintf(stderr, "Invalid cdim value: %d\n", cdim); + exit(1); } - const int ndim = sizeof(cells)/sizeof(cells[0]); + const int ndim = sizeof(cells) / sizeof(cells[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, cdim, lower, upper, cells); @@ -68,15 +82,15 @@ void test_ssfg(int cdim, int poly_order, bool use_gpu, enum gkyl_edge_loc edge, struct gkyl_array *field_ho, *field; field = mkarr(use_gpu, basis.num_basis, local_ext.volume); - field_ho = use_gpu ? mkarr(false, field->ncomp, field->size) - : gkyl_array_acquire(field); + field_ho = use_gpu ? mkarr(false, field->ncomp, field->size) : gkyl_array_acquire(field); - gkyl_proj_on_basis *proj_field = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_field, NULL); + gkyl_proj_on_basis *proj_field = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_field, NULL); gkyl_proj_on_basis_advance(proj_field, 0.0, &local, field_ho); gkyl_proj_on_basis_release(proj_field); - + // Set ghost cell modal values - double fg0 = sqrt(pow(2,cdim)); + double fg0 = sqrt(pow(2, cdim)); double fg1 = 1.0; double fg2 = 2.0; double fg3 = 3.0; @@ -91,11 +105,11 @@ void test_ssfg(int cdim, int poly_order, bool use_gpu, enum gkyl_edge_loc edge, double *f_i = gkyl_array_fetch(field_ho, linidx); f_i[0] = fg0; f_i[1] = fg1; - if (cdim > 1){ + if (cdim > 1) { f_i[2] = fg2; f_i[3] = fg3; } - if (cdim > 2){ + if (cdim > 2) { f_i[4] = fg4; f_i[5] = fg5; f_i[6] = fg6; @@ -107,9 +121,11 @@ void test_ssfg(int cdim, int poly_order, bool use_gpu, enum gkyl_edge_loc edge, gkyl_array_copy(field, field_ho); // Initialize the skin-surf updater and call it if control is false - gkyl_skin_surf_from_ghost* up = gkyl_skin_surf_from_ghost_new(dir, edge, basis, &skin_r, &ghost_r, use_gpu); - if (!control) // to test identity operation + gkyl_skin_surf_from_ghost *up = + gkyl_skin_surf_from_ghost_new(dir, edge, basis, &skin_r, &ghost_r, use_gpu); + if (!control) { // to test identity operation gkyl_skin_surf_from_ghost_advance(up, field); + } gkyl_skin_surf_from_ghost_release(up); // Copy field values back to host for checking @@ -125,36 +141,36 @@ void test_ssfg(int cdim, int poly_order, bool use_gpu, enum gkyl_edge_loc edge, const double *fskin = gkyl_array_cfetch(field_ho, skin_linidx); // Get ghost cell corresponding to skin cell gkyl_copy_int_arr(ndim, iter_skin.idx, gidx); - gidx[dir] = edge == GKYL_LOWER_EDGE? iter_skin.idx[dir]-1 : iter_skin.idx[dir]+1; + gidx[dir] = edge == GKYL_LOWER_EDGE ? iter_skin.idx[dir] - 1 : iter_skin.idx[dir] + 1; long ghost_linidx = gkyl_range_idx(&ghost_r, gidx); - const double *fghost = (const double*) gkyl_array_cfetch(field_ho, ghost_linidx); + const double *fghost = (const double *)gkyl_array_cfetch(field_ho, ghost_linidx); double xs = 0.0, ys = 0.0, zs = 0.0, xg = 0.0, yg = 0.0, zg = 0.0; char dir_c; - double edge_skin = edge == GKYL_UPPER_EDGE? 1.0 : -1.0; - switch(dir) { - case 0: - xs = edge_skin; - xg = -edge_skin; - dir_c = 'x'; - break; - case 1: - ys = edge_skin; - yg = -edge_skin; - dir_c = 'y'; - break; - case 2: - zs = edge_skin; - zg = -edge_skin; - dir_c = 'z'; - break; + double edge_skin = edge == GKYL_UPPER_EDGE ? 1.0 : -1.0; + switch (dir) { + case 0: + xs = edge_skin; + xg = -edge_skin; + dir_c = 'x'; + break; + case 1: + ys = edge_skin; + yg = -edge_skin; + dir_c = 'y'; + break; + case 2: + zs = edge_skin; + zg = -edge_skin; + dir_c = 'z'; + break; } - double vskin = eval_f(fskin,xs,ys,zs,cdim); - double vghost = eval_f(fghost,xg,yg,zg,cdim); + double vskin = eval_f(fskin, xs, ys, zs, cdim); + double vghost = eval_f(fghost, xg, yg, zg, cdim); double check_val; // Test values based on control mode - check_val = control? 0.0 : vghost; + check_val = control ? 0.0 : vghost; TEST_CHECK(gkyl_compare(vskin, check_val, 1e-14)); } gkyl_array_release(field); @@ -162,12 +178,13 @@ void test_ssfg(int cdim, int poly_order, bool use_gpu, enum gkyl_edge_loc edge, } // Tests for 3D case on CPU -void test_ssfg_ho() { - bool use_gpu = false; - int poly_order = 1; +void test_ssfg_ho() +{ + bool use_gpu = false; + int poly_order = 1; for (int cdim = 1; cdim <= 3; cdim++) { for (int control = 0; control <= 0; control++) { - for (int dir = 0; dir <= cdim-1; dir++) { + for (int dir = 0; dir <= cdim - 1; dir++) { test_ssfg(cdim, poly_order, use_gpu, GKYL_UPPER_EDGE, dir, control == 1); test_ssfg(cdim, poly_order, use_gpu, GKYL_LOWER_EDGE, dir, control == 1); } @@ -176,46 +193,48 @@ void test_ssfg_ho() { } // Tests for 3D case on GPU (if available) -void test_ssfg_dev() { - int poly_order = 1; - bool use_gpu = true; +void test_ssfg_dev() +{ + int poly_order = 1; + bool use_gpu = true; for (int cdim = 1; cdim <= 3; cdim++) { for (int control = 0; control <= 0; control++) { - for (int dir = 0; dir <= cdim-1; dir++) { - test_ssfg(cdim, poly_order, use_gpu, GKYL_UPPER_EDGE, dir, control==1); - test_ssfg(cdim, poly_order, use_gpu, GKYL_LOWER_EDGE, dir, control==1); + for (int dir = 0; dir <= cdim - 1; dir++) { + test_ssfg(cdim, poly_order, use_gpu, GKYL_UPPER_EDGE, dir, control == 1); + test_ssfg(cdim, poly_order, use_gpu, GKYL_LOWER_EDGE, dir, control == 1); } } } } // Evaluate the projection of the modal representation inside a cell from 1x to 3x -double eval_f(const double *phi, const double x, const double y, const double z, const int cdim) { +double eval_f(const double *phi, const double x, const double y, const double z, const int cdim) +{ double sqrt2 = sqrt(2.0); double sqrt3 = sqrt(3.0); double denom = pow(2.0, 1.5); switch (cdim) { - case 1: - return (sqrt3 * phi[1] * x) / sqrt2 + phi[0] / sqrt2; - case 2: - return (3 * phi[3] * x * y) / 2.0 + (sqrt3 * phi[2] * y) / 2.0 - + (sqrt3 * phi[1] * x) / 2.0 + phi[0] / 2.0; - case 3: - return (pow(3.0, 1.5) * phi[7] * x * y * z) / denom + (3 * phi[6] * y * z) / denom - + (3 * phi[5] * x * z) / denom + (sqrt3 * phi[3] * z) / denom - + (3 * phi[4] * x * y) / denom + (sqrt3 * phi[2] * y) / denom - + (sqrt3 * phi[1] * x) / denom + phi[0] / denom; - default: - fprintf(stderr, "Invalid cdim value: %d. Must be 0, 1, or 2.\n", cdim); - return 0.0; + case 1: + return (sqrt3 * phi[1] * x) / sqrt2 + phi[0] / sqrt2; + case 2: + return (3 * phi[3] * x * y) / 2.0 + (sqrt3 * phi[2] * y) / 2.0 + (sqrt3 * phi[1] * x) / 2.0 + + phi[0] / 2.0; + case 3: + return (pow(3.0, 1.5) * phi[7] * x * y * z) / denom + (3 * phi[6] * y * z) / denom + + (3 * phi[5] * x * z) / denom + (sqrt3 * phi[3] * z) / denom + + (3 * phi[4] * x * y) / denom + (sqrt3 * phi[2] * y) / denom + + (sqrt3 * phi[1] * x) / denom + phi[0] / denom; + default: + fprintf(stderr, "Invalid cdim value: %d. Must be 0, 1, or 2.\n", cdim); + return 0.0; } } // List of tests for the test framework TEST_LIST = { - { "test_ssfg_ho", test_ssfg_ho }, + {"test_ssfg_ho", test_ssfg_ho}, #ifdef GKYL_HAVE_CUDA - { "test_ssfg_dev", test_ssfg_dev }, + {"test_ssfg_dev", test_ssfg_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; \ No newline at end of file diff --git a/core/unit/ctest_struct_of_arrays.c b/core/unit/ctest_struct_of_arrays.c index 1df6ce7836..90fc8ece5e 100644 --- a/core/unit/ctest_struct_of_arrays.c +++ b/core/unit/ctest_struct_of_arrays.c @@ -29,46 +29,50 @@ void test_array_container_accumulate_ho() int num_containers = 2; // Number of array containers (i.e. no. of arrays). // Allocate objects. - struct gkyl_array_container *acs1 = gkyl_malloc(num_containers * sizeof(struct gkyl_array_container)); - struct gkyl_array_container *acs2 = gkyl_malloc(num_containers * sizeof(struct gkyl_array_container)); + struct gkyl_array_container *acs1 = + gkyl_malloc(num_containers * sizeof(struct gkyl_array_container)); + struct gkyl_array_container *acs2 = + gkyl_malloc(num_containers * sizeof(struct gkyl_array_container)); - for (int k=0; karr = gkyl_array_new(GKYL_DOUBLE, arr_ncomp, arr_size); arrc2->arr = gkyl_array_new(GKYL_DOUBLE, arr_ncomp, arr_size); } // Assign arrays. - for (int k=0; karr->data; - for (unsigned i=0; iarr->size; ++i) { - arr1_d[i] = k*100.0 + i*1.0; + for (unsigned i = 0; i < arrc1->arr->size; ++i) { + arr1_d[i] = k * 100.0 + i * 1.0; } - double *arr2_d = arrc2->arr->data; - for (unsigned i=0; iarr->size; ++i) { - arr2_d[i] = k*200.0 + i*2.0; + double *arr2_d = arrc2->arr->data; + for (unsigned i = 0; i < arrc2->arr->size; ++i) { + arr2_d[i] = k * 200.0 + i * 2.0; } } // Accumulate arrays. - for (int k=0; karr, 0.5, arrc2->arr); } // Check results. - for (int k=0; karr->data; - for (unsigned i=0; iarr->size; ++i) - TEST_CHECK( gkyl_compare(arr1_d[i], 2.0*(k*100.0+i*1.0), 1e-14) ); + double *arr1_d = arrc1->arr->data; + for (unsigned i = 0; i < arrc1->arr->size; ++i) { + TEST_CHECK(gkyl_compare(arr1_d[i], 2.0 * (k * 100.0 + i * 1.0), 1e-14)); + } } // Free objects. - for (int k=0; karr); gkyl_array_release(arrc2->arr); } @@ -88,12 +92,12 @@ void test_container_pack_accumulate_ho() struct gkyl_container_pack *cp1 = gkyl_malloc(num_packs * sizeof(struct gkyl_container_pack)); struct gkyl_container_pack *cp2 = gkyl_malloc(num_packs * sizeof(struct gkyl_container_pack)); - for (int j=0; jarr = gkyl_array_new(GKYL_DOUBLE, arr_ncomp, arr_size); arrc2->arr = gkyl_array_new(GKYL_DOUBLE, arr_ncomp, arr_size); @@ -101,47 +105,49 @@ void test_container_pack_accumulate_ho() } // Assign arrays. - for (int j=0; jarr->data; - for (unsigned i=0; iarr->size; ++i) { - arr1_d[i] = k*100.0 + i*1.0; + for (unsigned i = 0; i < arrc1->arr->size; ++i) { + arr1_d[i] = k * 100.0 + i * 1.0; } - double *arr2_d = arrc2->arr->data; - for (unsigned i=0; iarr->size; ++i) { - arr2_d[i] = k*200.0 + i*2.0; + double *arr2_d = arrc2->arr->data; + for (unsigned i = 0; i < arrc2->arr->size; ++i) { + arr2_d[i] = k * 200.0 + i * 2.0; } } } // Accumulate arrays. - for (int j=0; jarr, 0.5, arrc2->arr); } } // Check results. - for (int j=0; jarr->data; - for (unsigned i=0; iarr->size; ++i) - TEST_CHECK( gkyl_compare(arr1_d[i], 2.0*(k*100.0+i*1.0), 1e-14) ); + double *arr1_d = arrc1->arr->data; + for (unsigned i = 0; i < arrc1->arr->size; ++i) { + TEST_CHECK(gkyl_compare(arr1_d[i], 2.0 * (k * 100.0 + i * 1.0), 1e-14)); + } } } // Free objects. - for (int j=0; jarr); gkyl_array_release(arrc2->arr); } @@ -164,12 +170,12 @@ void test_array_bag_accumulate_ho() struct gkyl_array_bag *ab1 = gkyl_malloc(num_bags * sizeof(struct gkyl_array_bag)); struct gkyl_array_bag *ab2 = gkyl_malloc(num_bags * sizeof(struct gkyl_array_bag)); - for (int j=0; jbag[k], *innerbag2 = &bag2->bag[k]; innerbag1->arr = gkyl_array_new(GKYL_DOUBLE, arr_ncomp, arr_size); innerbag2->arr = gkyl_array_new(GKYL_DOUBLE, arr_ncomp, arr_size); @@ -177,27 +183,27 @@ void test_array_bag_accumulate_ho() } // Assign arrays. - for (int j=0; jbag[k], *innerbag2 = &bag2->bag[k]; struct gkyl_array *arr1 = innerbag1->arr, *arr2 = innerbag2->arr; double *arr1_d = arr1->data; - for (unsigned i=0; isize; ++i) { - arr1_d[i] = k*100.0 + i*1.0; + for (unsigned i = 0; i < arr1->size; ++i) { + arr1_d[i] = k * 100.0 + i * 1.0; } - double *arr2_d = arr2->data; - for (unsigned i=0; isize; ++i) { - arr2_d[i] = k*200.0 + i*2.0; + double *arr2_d = arr2->data; + for (unsigned i = 0; i < arr2->size; ++i) { + arr2_d[i] = k * 200.0 + i * 2.0; } } } // Accumulate arrays. - for (int j=0; jbag[k], *innerbag2 = &bag2->bag[k]; struct gkyl_array *arr1 = innerbag1->arr, *arr2 = innerbag2->arr; gkyl_array_accumulate(arr1, 0.5, arr2); @@ -205,21 +211,22 @@ void test_array_bag_accumulate_ho() } // Check results. - for (int j=0; jbag[k], *innerbag2 = &bag2->bag[k]; struct gkyl_array *arr1 = innerbag1->arr, *arr2 = innerbag2->arr; double *arr1_d = arr1->data; - for (unsigned i=0; isize; ++i) - TEST_CHECK( gkyl_compare(arr1_d[i], 2.0*(k*100.0+i*1.0), 1e-14) ); + for (unsigned i = 0; i < arr1->size; ++i) { + TEST_CHECK(gkyl_compare(arr1_d[i], 2.0 * (k * 100.0 + i * 1.0), 1e-14)); + } } } // Free objects. - for (int j=0; jbag[k], *innerbag2 = &bag2->bag[k]; gkyl_array_release(innerbag1->arr); gkyl_array_release(innerbag2->arr); @@ -234,23 +241,33 @@ void test_array_bag_accumulate_ho() #ifdef GKYL_HAVE_CUDA /* Function signatures of kernel calls */ -void test_array_container_accumulate_dev_assign_cu(int arr_ncomp, int arr_size, int num_containers, - struct gkyl_array_container *acs1, struct gkyl_array_container *acs2); - -void test_array_container_accumulate_dev_accumulate_cu(int arr_ncomp, int arr_size, int num_containers, - struct gkyl_array_container *acs1, double a, struct gkyl_array_container *acs2); - -int test_array_container_accumulate_dev_check_cu(int arr_ncomp, int arr_size, int num_containers, - struct gkyl_array_container *acs1); - -void test_array_bag_accumulate_dev_assign_cu(int arr_ncomp, int arr_size, int num_bags, - struct gkyl_array_bag *bag1, struct gkyl_array_bag *bag2); - -void test_array_bag_accumulate_dev_accumulate_cu(int arr_ncomp, int arr_size, int num_bags, - struct gkyl_array_bag *bag1, double a, struct gkyl_array_bag *bag2); - -int test_array_bag_accumulate_dev_check_cu(int arr_ncomp, int arr_size, int num_bags, - struct gkyl_array_bag *bag1); +void test_array_container_accumulate_dev_assign_cu( + int arr_ncomp, int arr_size, int num_containers, struct gkyl_array_container *acs1, + struct gkyl_array_container *acs2 +); + +void test_array_container_accumulate_dev_accumulate_cu( + int arr_ncomp, int arr_size, int num_containers, struct gkyl_array_container *acs1, double a, + struct gkyl_array_container *acs2 +); + +int test_array_container_accumulate_dev_check_cu( + int arr_ncomp, int arr_size, int num_containers, struct gkyl_array_container *acs1 +); + +void test_array_bag_accumulate_dev_assign_cu( + int arr_ncomp, int arr_size, int num_bags, struct gkyl_array_bag *bag1, + struct gkyl_array_bag *bag2 +); + +void test_array_bag_accumulate_dev_accumulate_cu( + int arr_ncomp, int arr_size, int num_bags, struct gkyl_array_bag *bag1, double a, + struct gkyl_array_bag *bag2 +); + +int test_array_bag_accumulate_dev_check_cu( + int arr_ncomp, int arr_size, int num_bags, struct gkyl_array_bag *bag1 +); void test_array_container_accumulate_dev() { @@ -261,18 +278,22 @@ void test_array_container_accumulate_dev() // Allocate objects. // These hold the host memory pointers. - struct gkyl_array_container *acs1_ho = gkyl_malloc(num_containers * sizeof(struct gkyl_array_container)); - struct gkyl_array_container *acs2_ho = gkyl_malloc(num_containers * sizeof(struct gkyl_array_container)); - for (int k=0; karr = gkyl_array_cu_dev_new(GKYL_DOUBLE, arr_ncomp, arr_size); arrc2->arr = gkyl_array_cu_dev_new(GKYL_DOUBLE, arr_ncomp, arr_size); } // These hold the device-memory pointers. - struct gkyl_array_container *acs1_dev = gkyl_malloc(num_containers * sizeof(struct gkyl_array_container)); - struct gkyl_array_container *acs2_dev = gkyl_malloc(num_containers * sizeof(struct gkyl_array_container)); - for (int k=0; karr = arrc1_ho->arr->on_dev; @@ -280,10 +301,16 @@ void test_array_container_accumulate_dev() } // These are pointers to device memory, and they hold the device-memory pointers. - struct gkyl_array_container *acs1 = gkyl_cu_malloc(num_containers * sizeof(struct gkyl_array_container)); - struct gkyl_array_container *acs2 = gkyl_cu_malloc(num_containers * sizeof(struct gkyl_array_container)); - gkyl_cu_memcpy(acs1, acs1_dev, num_containers * sizeof(struct gkyl_array_container), GKYL_CU_MEMCPY_H2D); - gkyl_cu_memcpy(acs2, acs2_dev, num_containers * sizeof(struct gkyl_array_container), GKYL_CU_MEMCPY_H2D); + struct gkyl_array_container *acs1 = + gkyl_cu_malloc(num_containers * sizeof(struct gkyl_array_container)); + struct gkyl_array_container *acs2 = + gkyl_cu_malloc(num_containers * sizeof(struct gkyl_array_container)); + gkyl_cu_memcpy( + acs1, acs1_dev, num_containers * sizeof(struct gkyl_array_container), GKYL_CU_MEMCPY_H2D + ); + gkyl_cu_memcpy( + acs2, acs2_dev, num_containers * sizeof(struct gkyl_array_container), GKYL_CU_MEMCPY_H2D + ); // We can free the _dev ones because we don't need them anymore. gkyl_free(acs1_dev); gkyl_free(acs2_dev); @@ -292,19 +319,23 @@ void test_array_container_accumulate_dev() test_array_container_accumulate_dev_assign_cu(arr_ncomp, arr_size, num_containers, acs1, acs2); // Accumulate arrays. - test_array_container_accumulate_dev_accumulate_cu(arr_ncomp, arr_size, num_containers, acs1, 0.5, acs2); + test_array_container_accumulate_dev_accumulate_cu( + arr_ncomp, arr_size, num_containers, acs1, 0.5, acs2 + ); // Check results. - int nfail = test_array_container_accumulate_dev_check_cu(arr_ncomp, arr_size, num_containers, acs1); - TEST_CHECK( nfail == 0 ); + int nfail = + test_array_container_accumulate_dev_check_cu(arr_ncomp, arr_size, num_containers, acs1); + TEST_CHECK(nfail == 0); // Free objects. // Note that when you call array_release here you also free the // memory that the pointers in acs1/acs2 point to. gkyl_cu_free(acs1); gkyl_cu_free(acs2); - for (int k=0; karr); gkyl_array_release(arrc2->arr); } @@ -327,12 +358,12 @@ void test_container_pack_accumulate_dev() struct gkyl_container_pack *cp1_ho = gkyl_malloc(num_packs * sizeof(struct gkyl_container_pack)); struct gkyl_container_pack *cp2_ho = gkyl_malloc(num_packs * sizeof(struct gkyl_container_pack)); - for (int j=0; jarr = gkyl_array_cu_dev_new(GKYL_DOUBLE, arr_ncomp, arr_size); arrc2->arr = gkyl_array_cu_dev_new(GKYL_DOUBLE, arr_ncomp, arr_size); @@ -342,13 +373,13 @@ void test_container_pack_accumulate_dev() // These hold the device-memory pointers. struct gkyl_container_pack *cp1_dev = gkyl_malloc(num_packs * sizeof(struct gkyl_container_pack)); struct gkyl_container_pack *cp2_dev = gkyl_malloc(num_packs * sizeof(struct gkyl_container_pack)); - for (int j=0; jarr = arrc1_ho->arr->on_dev; @@ -359,47 +390,57 @@ void test_container_pack_accumulate_dev() // These are pointers to host memory, and they hold the device-memory pointers. struct gkyl_container_pack *cp1 = gkyl_malloc(num_packs * sizeof(struct gkyl_container_pack)); struct gkyl_container_pack *cp2 = gkyl_malloc(num_packs * sizeof(struct gkyl_container_pack)); - for (int j=0; jarr); gkyl_array_release(arrc2->arr); } @@ -424,12 +465,12 @@ void test_array_bag_accumulate_dev() // These hold the host memory pointers. struct gkyl_array_bag *ab1_ho = gkyl_malloc(num_bags * sizeof(struct gkyl_array_bag)); struct gkyl_array_bag *ab2_ho = gkyl_malloc(num_bags * sizeof(struct gkyl_array_bag)); - for (int j=0; jbag[k], *innerbag2 = &bag2->bag[k]; innerbag1->arr = gkyl_array_cu_dev_new(GKYL_DOUBLE, arr_ncomp, arr_size); innerbag2->arr = gkyl_array_cu_dev_new(GKYL_DOUBLE, arr_ncomp, arr_size); @@ -439,13 +480,13 @@ void test_array_bag_accumulate_dev() // These hold the device-memory pointers. struct gkyl_array_bag *ab1_dev = gkyl_malloc(num_bags * sizeof(struct gkyl_array_bag)); struct gkyl_array_bag *ab2_dev = gkyl_malloc(num_bags * sizeof(struct gkyl_array_bag)); - for (int j=0; jbag[k], *innerbag2_ho = &bag2_ho->bag[k]; struct gkyl_array_bag *innerbag1_dev = &bag1_dev->bag[k], *innerbag2_dev = &bag2_dev->bag[k]; innerbag1_dev->arr = innerbag1_ho->arr->on_dev; @@ -456,47 +497,53 @@ void test_array_bag_accumulate_dev() // These are pointers to host memory, and they hold the device-memory pointers. struct gkyl_array_bag *ab1 = gkyl_malloc(num_bags * sizeof(struct gkyl_array_bag)); struct gkyl_array_bag *ab2 = gkyl_malloc(num_bags * sizeof(struct gkyl_array_bag)); - for (int j=0; jbag, bag2->bag); // Accumulate arrays. - test_array_bag_accumulate_dev_accumulate_cu(arr_ncomp, arr_size, num_arrays, bag1->bag, 0.5, bag2->bag); + test_array_bag_accumulate_dev_accumulate_cu( + arr_ncomp, arr_size, num_arrays, bag1->bag, 0.5, bag2->bag + ); // Check results. int nfail = test_array_bag_accumulate_dev_check_cu(arr_ncomp, arr_size, num_arrays, bag1->bag); - TEST_CHECK( nfail == 0 ); + TEST_CHECK(nfail == 0); } // Free objects. // Note that when you call array_release here you also free the // memory that the pointers in ab1/ab2 point to. - for (int j=0; jbag[k], *innerbag2 = &bag2->bag[k]; gkyl_array_release(innerbag1->arr); gkyl_array_release(innerbag2->arr); @@ -511,13 +558,13 @@ void test_array_bag_accumulate_dev() #endif TEST_LIST = { - { "array_container_accumulate_ho", test_array_container_accumulate_ho }, - { "container_pack_accumulate_ho", test_container_pack_accumulate_ho }, - { "array_bag_accumulate_ho", test_array_bag_accumulate_ho }, + {"array_container_accumulate_ho", test_array_container_accumulate_ho}, + {"container_pack_accumulate_ho", test_container_pack_accumulate_ho}, + {"array_bag_accumulate_ho", test_array_bag_accumulate_ho}, #ifdef GKYL_HAVE_CUDA - { "array_container_accumulate_dev", test_array_container_accumulate_dev }, - { "container_pack_accumulate_dev", test_container_pack_accumulate_dev }, - { "array_bag_accumulate_dev", test_array_bag_accumulate_dev }, + {"array_container_accumulate_dev", test_array_container_accumulate_dev}, + {"container_pack_accumulate_dev", test_container_pack_accumulate_dev}, + {"array_bag_accumulate_dev", test_array_bag_accumulate_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/core/unit/ctest_struct_of_arrays_cu.cu b/core/unit/ctest_struct_of_arrays_cu.cu index dbcdbbbaa7..8f57b6da76 100644 --- a/core/unit/ctest_struct_of_arrays_cu.cu +++ b/core/unit/ctest_struct_of_arrays_cu.cu @@ -7,39 +7,49 @@ extern "C" { #include #include - struct gkyl_array_container { - struct gkyl_array *arr; - }; - - struct gkyl_container_pack { - struct gkyl_array_container *ac; - }; - - struct gkyl_array_bag { - struct gkyl_array *arr; - struct gkyl_array_bag *bag; - }; - - // Functions for test_array_container. - void test_array_container_accumulate_dev_assign_cu(int arr_ncomp, int arr_size, int num_containers, - struct gkyl_array_container *acs1, struct gkyl_array_container *acs2); - void test_array_container_accumulate_dev_accumulate_cu(int arr_ncomp, int arr_size, int num_containers, - struct gkyl_array_container *acs1, double a, struct gkyl_array_container *acs2); - int test_array_container_accumulate_dev_check_cu(int arr_ncomp, int arr_size, int num_containers, - struct gkyl_array_container *acs1); - - // Functions for test_array_bag. - void test_array_bag_accumulate_dev_assign_cu(int arr_ncomp, int arr_size, int num_bags, - struct gkyl_array_bag *bag1, struct gkyl_array_bag *bag2); - void test_array_bag_accumulate_dev_accumulate_cu(int arr_ncomp, int arr_size, int num_bags, - struct gkyl_array_bag *bag1, double a, struct gkyl_array_bag *bag2); - int test_array_bag_accumulate_dev_check_cu(int arr_ncomp, int arr_size, int num_bags, - struct gkyl_array_bag *bag1); +struct gkyl_array_container { + struct gkyl_array *arr; +}; + +struct gkyl_container_pack { + struct gkyl_array_container *ac; +}; + +struct gkyl_array_bag { + struct gkyl_array *arr; + struct gkyl_array_bag *bag; +}; + +// Functions for test_array_container. +void test_array_container_accumulate_dev_assign_cu( + int arr_ncomp, int arr_size, int num_containers, struct gkyl_array_container *acs1, + struct gkyl_array_container *acs2 +); +void test_array_container_accumulate_dev_accumulate_cu( + int arr_ncomp, int arr_size, int num_containers, struct gkyl_array_container *acs1, double a, + struct gkyl_array_container *acs2 +); +int test_array_container_accumulate_dev_check_cu( + int arr_ncomp, int arr_size, int num_containers, struct gkyl_array_container *acs1 +); + +// Functions for test_array_bag. +void test_array_bag_accumulate_dev_assign_cu( + int arr_ncomp, int arr_size, int num_bags, struct gkyl_array_bag *bag1, + struct gkyl_array_bag *bag2 +); +void test_array_bag_accumulate_dev_accumulate_cu( + int arr_ncomp, int arr_size, int num_bags, struct gkyl_array_bag *bag1, double a, + struct gkyl_array_bag *bag2 +); +int test_array_bag_accumulate_dev_check_cu( + int arr_ncomp, int arr_size, int num_bags, struct gkyl_array_bag *bag1 +); } -#define START_ID (threadIdx.x + blockIdx.x*blockDim.x) +#define START_ID (threadIdx.x + blockIdx.x * blockDim.x) // Compute number of elements stored in array 'arr' -#define NELM(arr) (arr->size*arr->ncomp) +#define NELM(arr) (arr->size * arr->ncomp) // Compute size of 'arr' #define NSIZE(arr) (arr->size) // Compute number of components stored in array 'arr' @@ -49,79 +59,85 @@ extern "C" { // Functions for test_array_container. // -__global__ -void ker_cu_array_container_accumulate_dev_assign(int num_containers, - struct gkyl_array_container *acs1, struct gkyl_array_container *acs2) +__global__ void ker_cu_array_container_accumulate_dev_assign( + int num_containers, struct gkyl_array_container *acs1, struct gkyl_array_container *acs2 +) { - for (int k=0; karr->data; - for (unsigned long linc = START_ID; linc < NELM(arrc1->arr); linc += blockDim.x*gridDim.x) { - arr1_d[linc] = k*100.0 + linc*1.0; + double *arr1_d = (double *)arrc1->arr->data; + for (unsigned long linc = START_ID; linc < NELM(arrc1->arr); linc += blockDim.x * gridDim.x) { + arr1_d[linc] = k * 100.0 + linc * 1.0; } struct gkyl_array_container *arrc2 = &acs2[k]; - double *arr2_d = (double*) arrc2->arr->data; - for (unsigned long linc = START_ID; linc < NELM(arrc2->arr); linc += blockDim.x*gridDim.x) { - arr2_d[linc] = k*200.0 + linc*2.0; + double *arr2_d = (double *)arrc2->arr->data; + for (unsigned long linc = START_ID; linc < NELM(arrc2->arr); linc += blockDim.x * gridDim.x) { + arr2_d[linc] = k * 200.0 + linc * 2.0; } } } -void -test_array_container_accumulate_dev_assign_cu(int arr_ncomp, int arr_size, int num_containers, - struct gkyl_array_container *acs1, struct gkyl_array_container *acs2) +void test_array_container_accumulate_dev_assign_cu( + int arr_ncomp, int arr_size, int num_containers, struct gkyl_array_container *acs1, + struct gkyl_array_container *acs2 +) { int nthreads = GKYL_DEFAULT_NUM_THREADS; - int nblocks = gkyl_int_div_up(arr_size*arr_ncomp, nthreads); - ker_cu_array_container_accumulate_dev_assign<<>>(num_containers, acs1, acs2); + int nblocks = gkyl_int_div_up(arr_size * arr_ncomp, nthreads); + ker_cu_array_container_accumulate_dev_assign<< > >(num_containers, acs1, acs2); } -__global__ -void ker_cu_array_container_accumulate_dev_accumulate(int num_containers, - struct gkyl_array_container *acs1, double a, struct gkyl_array_container *acs2) +__global__ void ker_cu_array_container_accumulate_dev_accumulate( + int num_containers, struct gkyl_array_container *acs1, double a, struct gkyl_array_container *acs2 +) { - for (int k=0; karr->data; - double *arr2_d = (double*) arrc2->arr->data; - for (unsigned long linc = START_ID; linc < NELM(arrc1->arr); linc += blockDim.x*gridDim.x) { - arr1_d[linc] += a*arr2_d[linc]; + double *arr1_d = (double *)arrc1->arr->data; + double *arr2_d = (double *)arrc2->arr->data; + for (unsigned long linc = START_ID; linc < NELM(arrc1->arr); linc += blockDim.x * gridDim.x) { + arr1_d[linc] += a * arr2_d[linc]; } } } -void -test_array_container_accumulate_dev_accumulate_cu(int arr_ncomp, int arr_size, int num_containers, - struct gkyl_array_container *acs1, double a, struct gkyl_array_container *acs2) +void test_array_container_accumulate_dev_accumulate_cu( + int arr_ncomp, int arr_size, int num_containers, struct gkyl_array_container *acs1, double a, + struct gkyl_array_container *acs2 +) { int nthreads = GKYL_DEFAULT_NUM_THREADS; - int nblocks = gkyl_int_div_up(arr_size*arr_ncomp, nthreads); - ker_cu_array_container_accumulate_dev_accumulate<<>>(num_containers, acs1, a, acs2); + int nblocks = gkyl_int_div_up(arr_size * arr_ncomp, nthreads); + ker_cu_array_container_accumulate_dev_accumulate<< > >( + num_containers, acs1, a, acs2 + ); } -__global__ -void ker_cu_array_container_accumulate_dev_check(int num_containers, - struct gkyl_array_container *acs1, int *nfail) +__global__ void ker_cu_array_container_accumulate_dev_check( + int num_containers, struct gkyl_array_container *acs1, int *nfail +) { - for (int k=0; karr->data; - for (unsigned long linc = START_ID; linc < NELM(arrc1->arr); linc += blockDim.x*gridDim.x) { - GKYL_CU_CHECK( arr1_d[linc] == 2.0*(k*100.0+linc*1.0), nfail ); + double *arr1_d = (double *)arrc1->arr->data; + for (unsigned long linc = START_ID; linc < NELM(arrc1->arr); linc += blockDim.x * gridDim.x) { + GKYL_CU_CHECK(arr1_d[linc] == 2.0 * (k * 100.0 + linc * 1.0), nfail); } } } -int -test_array_container_accumulate_dev_check_cu(int arr_ncomp, int arr_size, int num_containers, - struct gkyl_array_container *acs1) +int test_array_container_accumulate_dev_check_cu( + int arr_ncomp, int arr_size, int num_containers, struct gkyl_array_container *acs1 +) { - int *nfail_dev = (int *) gkyl_cu_malloc(sizeof(int)); + int *nfail_dev = (int *)gkyl_cu_malloc(sizeof(int)); int nthreads = GKYL_DEFAULT_NUM_THREADS; - int nblocks = gkyl_int_div_up(arr_size*arr_ncomp, nthreads); - ker_cu_array_container_accumulate_dev_check<<>>(num_containers, acs1, nfail_dev); + int nblocks = gkyl_int_div_up(arr_size * arr_ncomp, nthreads); + ker_cu_array_container_accumulate_dev_check<< > >( + num_containers, acs1, nfail_dev + ); int nfail; gkyl_cu_memcpy(&nfail, nfail_dev, sizeof(int), GKYL_CU_MEMCPY_D2H); @@ -134,87 +150,90 @@ test_array_container_accumulate_dev_check_cu(int arr_ncomp, int arr_size, int nu // Functions for test_array_bag. // -__global__ -void ker_cu_array_bag_accumulate_dev_assign(int num_arrays, - struct gkyl_array_bag *bag1, struct gkyl_array_bag *bag2) +__global__ void ker_cu_array_bag_accumulate_dev_assign( + int num_arrays, struct gkyl_array_bag *bag1, struct gkyl_array_bag *bag2 +) { - for (int k=0; karr; - double *arr1_d = (double *) arr1->data; - for (unsigned long linc = START_ID; linc < NELM(arr1); linc += blockDim.x*gridDim.x) { - arr1_d[linc] = k*100.0 + linc*1.0; + double *arr1_d = (double *)arr1->data; + for (unsigned long linc = START_ID; linc < NELM(arr1); linc += blockDim.x * gridDim.x) { + arr1_d[linc] = k * 100.0 + linc * 1.0; } struct gkyl_array_bag *innerbag2 = &bag2[k]; struct gkyl_array *arr2 = innerbag2->arr; - double *arr2_d = (double *) arr2->data; - for (unsigned long linc = START_ID; linc < NELM(arr2); linc += blockDim.x*gridDim.x) { - arr2_d[linc] = k*200.0 + linc*2.0; + double *arr2_d = (double *)arr2->data; + for (unsigned long linc = START_ID; linc < NELM(arr2); linc += blockDim.x * gridDim.x) { + arr2_d[linc] = k * 200.0 + linc * 2.0; } } } -void -test_array_bag_accumulate_dev_assign_cu(int arr_ncomp, int arr_size, int num_arrays, - struct gkyl_array_bag *innerbag1, struct gkyl_array_bag *innerbag2) +void test_array_bag_accumulate_dev_assign_cu( + int arr_ncomp, int arr_size, int num_arrays, struct gkyl_array_bag *innerbag1, + struct gkyl_array_bag *innerbag2 +) { int nthreads = GKYL_DEFAULT_NUM_THREADS; - int nblocks = gkyl_int_div_up(arr_size*arr_ncomp, nthreads); - ker_cu_array_bag_accumulate_dev_assign<<>>(num_arrays, innerbag1, innerbag2); + int nblocks = gkyl_int_div_up(arr_size * arr_ncomp, nthreads); + ker_cu_array_bag_accumulate_dev_assign<< > >(num_arrays, innerbag1, innerbag2); } -__global__ -void ker_cu_array_bag_accumulate_dev_accumulate(int num_bags, - struct gkyl_array_bag *bag1, double a, struct gkyl_array_bag *bag2) +__global__ void ker_cu_array_bag_accumulate_dev_accumulate( + int num_bags, struct gkyl_array_bag *bag1, double a, struct gkyl_array_bag *bag2 +) { - for (int k=0; karr; - double *arr1_d = (double *) arr1->data; + double *arr1_d = (double *)arr1->data; struct gkyl_array_bag *innerbag2 = &bag2[k]; struct gkyl_array *arr2 = innerbag2->arr; - double *arr2_d = (double *) arr2->data; + double *arr2_d = (double *)arr2->data; - for (unsigned long linc = START_ID; linc < NELM(arr1); linc += blockDim.x*gridDim.x) { - arr1_d[linc] += a*arr2_d[linc]; + for (unsigned long linc = START_ID; linc < NELM(arr1); linc += blockDim.x * gridDim.x) { + arr1_d[linc] += a * arr2_d[linc]; } } } -void -test_array_bag_accumulate_dev_accumulate_cu(int arr_ncomp, int arr_size, int num_bags, - struct gkyl_array_bag *innerbag1, double a, struct gkyl_array_bag *innerbag2) +void test_array_bag_accumulate_dev_accumulate_cu( + int arr_ncomp, int arr_size, int num_bags, struct gkyl_array_bag *innerbag1, double a, + struct gkyl_array_bag *innerbag2 +) { int nthreads = GKYL_DEFAULT_NUM_THREADS; - int nblocks = gkyl_int_div_up(arr_size*arr_ncomp, nthreads); - ker_cu_array_bag_accumulate_dev_accumulate<<>>(num_bags, innerbag1, a, innerbag2); + int nblocks = gkyl_int_div_up(arr_size * arr_ncomp, nthreads); + ker_cu_array_bag_accumulate_dev_accumulate<< > >( + num_bags, innerbag1, a, innerbag2 + ); } -__global__ -void ker_cu_array_bag_accumulate_dev_check(int num_bags, - struct gkyl_array_bag *bag1, int *nfail) +__global__ void +ker_cu_array_bag_accumulate_dev_check(int num_bags, struct gkyl_array_bag *bag1, int *nfail) { - for (int k=0; karr; - double *arr1_d = (double *) arr1->data; - for (unsigned long linc = START_ID; linc < NELM(arr1); linc += blockDim.x*gridDim.x) { - GKYL_CU_CHECK( arr1_d[linc] == 2.0*(k*100.0+linc*1.0), nfail ); + double *arr1_d = (double *)arr1->data; + for (unsigned long linc = START_ID; linc < NELM(arr1); linc += blockDim.x * gridDim.x) { + GKYL_CU_CHECK(arr1_d[linc] == 2.0 * (k * 100.0 + linc * 1.0), nfail); } } } -int -test_array_bag_accumulate_dev_check_cu(int arr_ncomp, int arr_size, int num_bags, - struct gkyl_array_bag *innerbag1) +int test_array_bag_accumulate_dev_check_cu( + int arr_ncomp, int arr_size, int num_bags, struct gkyl_array_bag *innerbag1 +) { - int *nfail_dev = (int *) gkyl_cu_malloc(sizeof(int)); + int *nfail_dev = (int *)gkyl_cu_malloc(sizeof(int)); int nthreads = GKYL_DEFAULT_NUM_THREADS; - int nblocks = gkyl_int_div_up(arr_size*arr_ncomp, nthreads); - ker_cu_array_bag_accumulate_dev_check<<>>(num_bags, innerbag1, nfail_dev); + int nblocks = gkyl_int_div_up(arr_size * arr_ncomp, nthreads); + ker_cu_array_bag_accumulate_dev_check<< > >(num_bags, innerbag1, nfail_dev); int nfail; gkyl_cu_memcpy(&nfail, nfail_dev, sizeof(int), GKYL_CU_MEMCPY_D2H); diff --git a/core/unit/ctest_tensor_field.c b/core/unit/ctest_tensor_field.c index 3bfb284dae..aeef70b40f 100644 --- a/core/unit/ctest_tensor_field.c +++ b/core/unit/ctest_tensor_field.c @@ -4,182 +4,189 @@ #include #include - void test_tensor_field_ho() { - // Tensor field size - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; // All covaraint indices enum gkyl_tensor_index_loc iloc[GKYL_MAX_DIM]; - for (int i=0; irank == 2 ); - TEST_CHECK( tfld->ndim == 3 ); - TEST_CHECK( tfld->size == 10 ); - TEST_CHECK( tfld->ref_count.count == 1 ); + TEST_CHECK(tfld->rank == 2); + TEST_CHECK(tfld->ndim == 3); + TEST_CHECK(tfld->size == 10); + TEST_CHECK(tfld->ref_count.count == 1); - TEST_CHECK( tfld->tdata->on_dev == tfld->tdata ); + TEST_CHECK(tfld->tdata->on_dev == tfld->tdata); - TEST_CHECK( gkyl_array_is_cu_dev(tfld->tdata) == false ); + TEST_CHECK(gkyl_array_is_cu_dev(tfld->tdata) == false); - TEST_CHECK( tfld->tdata->size == size ); - TEST_CHECK( tfld->tdata->ncomp == pow(ndim,rank) ); + TEST_CHECK(tfld->tdata->size == size); + TEST_CHECK(tfld->tdata->ncomp == pow(ndim, rank)); - double *tfldData = tfld->tdata->data; + double *tfldData = tfld->tdata->data; // Iterate over the array (with is size*(ndim)^rank) - for (unsigned i=0; itdata->size; ++i){ - TEST_CHECK( tfldData[i] == 0. ); - tfldData[i] = (i+0.5)*0.1; + for (unsigned i = 0; i < tfld->tdata->size; ++i) { + TEST_CHECK(tfldData[i] == 0.); + tfldData[i] = (i + 0.5) * 0.1; } // acquire pointer struct gkyl_tensor_field *crr = gkyl_tensor_field_acquire(tfld); - TEST_CHECK( crr->ref_count.count == 2 ); - TEST_CHECK( tfld->ref_count.count == 2 ); + TEST_CHECK(crr->ref_count.count == 2); + TEST_CHECK(tfld->ref_count.count == 2); struct gkyl_tensor_field *drr = gkyl_tensor_field_acquire(crr); - TEST_CHECK( drr->ref_count.count == 3 ); - TEST_CHECK( crr->ref_count.count == 3 ); - TEST_CHECK( tfld->ref_count.count == 3 ); - + TEST_CHECK(drr->ref_count.count == 3); + TEST_CHECK(crr->ref_count.count == 3); + TEST_CHECK(tfld->ref_count.count == 3); + gkyl_tensor_field_release(crr); - TEST_CHECK( tfld->ref_count.count == 2 ); + TEST_CHECK(tfld->ref_count.count == 2); gkyl_tensor_field_release(drr); - TEST_CHECK( tfld->ref_count.count == 1 ); - + TEST_CHECK(tfld->ref_count.count == 1); + gkyl_tensor_field_release(tfld); } void test_tensor_field_fetch_ho() { - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; enum gkyl_tensor_index_loc iloc[GKYL_MAX_DIM]; - for (int i=0; itdata->data; - for (unsigned i=0; isize; ++i){ + double *tfldData = tfld->tdata->data; + for (unsigned i = 0; i < tfld->size; ++i) { double *tensor = gkyl_array_fetch(tfld->tdata, i); - for (unsigned j=0; jtdata->ncomp; ++j) { - tensor[j] = i + j; + for (unsigned j = 0; j < tfld->tdata->ncomp; ++j) { + tensor[j] = i + j; } } // Tensor fetch method double *tfldDataLh = gkyl_tensor_field_fetch(tfld, 0); - TEST_CHECK( tfldDataLh[0] == (0.0 + 0.0) ); + TEST_CHECK(tfldDataLh[0] == (0.0 + 0.0)); double *tfldDataUh = gkyl_tensor_field_fetch(tfld, 8); - TEST_CHECK( tfldDataUh[3] == (8.0 + 3.0) ); + TEST_CHECK(tfldDataUh[3] == (8.0 + 3.0)); // Tensor element fetch method - int indxLh[GKYL_MAX_DIM] = {0.0, 0.0}; - indxLh[0] = 0; indxLh[1] = 2; + int indxLh[GKYL_MAX_DIM] = {0.0, 0.0}; + indxLh[0] = 0; + indxLh[1] = 2; double tfldDataLhElem = gkyl_tensor_field_elem_fetch(tfld, 0, indxLh); - TEST_CHECK( tfldDataLhElem == (0.0 + 2.0) ); + TEST_CHECK(tfldDataLhElem == (0.0 + 2.0)); - int indxUh[GKYL_MAX_DIM] = {0.0, 0.0}; - indxUh[0] = 2; indxUh[1] = 0; + int indxUh[GKYL_MAX_DIM] = {0.0, 0.0}; + indxUh[0] = 2; + indxUh[1] = 0; double tfldDataUhElem = gkyl_tensor_field_elem_fetch(tfld, 5, indxUh); - TEST_CHECK( tfldDataUhElem == (5.0 + 6.0) ); - + TEST_CHECK(tfldDataUhElem == (5.0 + 6.0)); + gkyl_tensor_field_release(tfld); } - void test_tensor_field_set_ho() { - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; enum gkyl_tensor_index_loc iloc[GKYL_MAX_DIM]; - for (int i=0; itdata->data; - for (unsigned i=0; isize; ++i){ + double *tfldData = tfld->tdata->data; + for (unsigned i = 0; i < tfld->size; ++i) { double *tensor = gkyl_array_fetch(tfld->tdata, i); - for (unsigned j=0; jtdata->ncomp; ++j) { + for (unsigned j = 0; j < tfld->tdata->ncomp; ++j) { tensor[j] = i + j; } } - int idx[GKYL_MAX_DIM] = {0.0, 0.0}; - for (unsigned i=0; irank == 2 ); - TEST_CHECK( tfld_cu->ndim == 3 ); - TEST_CHECK( tfld_cu->size == 10 ); - TEST_CHECK( tfld_cu->ref_count.count == 1 ); + TEST_CHECK(tfld_cu->rank == 2); + TEST_CHECK(tfld_cu->ndim == 3); + TEST_CHECK(tfld_cu->size == 10); + TEST_CHECK(tfld_cu->ref_count.count == 1); - TEST_CHECK( gkyl_tensor_field_is_cu_dev(tfld_cu) == true ); + TEST_CHECK(gkyl_tensor_field_is_cu_dev(tfld_cu) == true); - TEST_CHECK( tfld_cu->tdata->size == size ); - TEST_CHECK( tfld_cu->tdata->ncomp == pow(ndim,rank) ); + TEST_CHECK(tfld_cu->tdata->size == size); + TEST_CHECK(tfld_cu->tdata->ncomp == pow(ndim, rank)); // create host array and initialize it - struct gkyl_tensor_field *tfld = gkyl_tensor_field_new(rank,ndim,size,iloc); + struct gkyl_tensor_field *tfld = gkyl_tensor_field_new(rank, ndim, size, iloc); gkyl_tensor_field_copy(tfld, tfld_cu); double *tfldData = tfld->tdata->data; // Iterate over the array (with is size*(ndim)^rank) - for (unsigned i=0; itdata->size; ++i){ - TEST_CHECK( tfldData[i] == 0. ); - tfldData[i] = (i+0.5)*0.1; + for (unsigned i = 0; i < tfld->tdata->size; ++i) { + TEST_CHECK(tfldData[i] == 0.); + tfldData[i] = (i + 0.5) * 0.1; } gkyl_tensor_field_copy(tfld_cu, tfld); // reset host array - for (unsigned i=0; itdata->size; ++i){ + for (unsigned i = 0; i < tfld->tdata->size; ++i) { tfldData[i] = 0.0; } gkyl_tensor_field_copy(tfld, tfld_cu); - for (unsigned i=0; itdata->size; ++i) - TEST_CHECK( tfldData[i] == (i+0.5)*0.1 ); + for (unsigned i = 0; i < tfld->tdata->size; ++i) { + TEST_CHECK(tfldData[i] == (i + 0.5) * 0.1); + } gkyl_tensor_field_release(tfld); gkyl_tensor_field_release(tfld_cu); @@ -240,14 +248,13 @@ void test_tensor_field_base_dev() #endif - TEST_LIST = { - { "test_tensor_field_ho", test_tensor_field_ho }, - { "test_tensor_field_base_ho", test_tensor_field_base_ho }, - { "test_tensor_field_fetch_ho", test_tensor_field_fetch_ho }, - { "test_tensor_field_set_ho", test_tensor_field_set_ho }, + {"test_tensor_field_ho", test_tensor_field_ho}, + {"test_tensor_field_base_ho", test_tensor_field_base_ho}, + {"test_tensor_field_fetch_ho", test_tensor_field_fetch_ho}, + {"test_tensor_field_set_ho", test_tensor_field_set_ho}, #ifdef GKYL_HAVE_CUDA - { "tensor_field_base_dev", test_tensor_field_base_dev }, + {"tensor_field_base_dev", test_tensor_field_base_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; \ No newline at end of file diff --git a/core/unit/ctest_tensor_field_ops.c b/core/unit/ctest_tensor_field_ops.c index aefb29aecb..f83b5dfde9 100644 --- a/core/unit/ctest_tensor_field_ops.c +++ b/core/unit/ctest_tensor_field_ops.c @@ -8,36 +8,36 @@ // This test is intended to verify: verify: h^ij h_jk = \delta^i_k = \delta_i^k raised in place void test_tensor_field_raise_idx_in_place_ho() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; iiloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(mem); @@ -74,35 +79,35 @@ void test_tensor_field_raise_idx_in_place_ho() // This test is intended to verify: h_ij h^jk = \delta_i^k raised in place void test_tensor_field_lower_idx_in_place_ho() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; iiloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(mem); @@ -140,38 +150,67 @@ void test_tensor_field_lower_idx_in_place_ho() // Tests a denser, but still symmetric A, multiplication void test_tensor_field_lower_idx_in_place_2_ho() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; iiloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(mem); @@ -209,38 +253,67 @@ void test_tensor_field_lower_idx_in_place_2_ho() // Tests a denser, asymmetric A, multiplication void test_tensor_field_raise_idx_in_place_2_ho() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; iiloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(mem); @@ -277,35 +355,35 @@ void test_tensor_field_raise_idx_in_place_2_ho() // This test is intended to verify: verify: h^ij h_jk = \delta^i_k = \delta_i^k raised, set void test_tensor_field_raise_idx_set_ho() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; iiloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( ten_res->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( ten_res->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(ten_res->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(ten_res->iloc[1] == GKYL_TENSOR_INDEX_LOWER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(diag_metric_contra); @@ -345,34 +428,34 @@ void test_tensor_field_raise_idx_set_ho() // This test is intended to verify: h_ij h^jk = \delta_i^k loweredå, set void test_tensor_field_lower_idx_set_ho() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; iiloc[0] == GKYL_TENSOR_INDEX_UPPER); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( ten_res->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( ten_res->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(ten_res->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(ten_res->iloc[1] == GKYL_TENSOR_INDEX_UPPER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(diag_metric_contra); @@ -413,37 +501,66 @@ void test_tensor_field_lower_idx_set_ho() // Tests a denser, but still symmetric A, multiplication void test_tensor_field_lower_idx_set_2_ho() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; iiloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( ten_res->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( ten_res->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(ten_res->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(ten_res->iloc[1] == GKYL_TENSOR_INDEX_UPPER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(diag_metric_contra); @@ -484,37 +606,66 @@ void test_tensor_field_lower_idx_set_2_ho() // Tests a denser, asymmetric A, multiplication void test_tensor_field_raise_idx_set_2_ho() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; iiloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( ten_res->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( ten_res->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(ten_res->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(ten_res->iloc[1] == GKYL_TENSOR_INDEX_LOWER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(diag_metric_contra); gkyl_tensor_field_release(ten_res); } - // Cuda specific tests #ifdef GKYL_HAVE_CUDA -// This test is intended to verify: A_ij A^jk = \delta_i^k lowered and set +// This test is intended to verify: A_ij A^jk = \delta_i^k lowered and set // Tests a denser, asymmetric A, multiplication void test_tensor_field_lower_idx_set_dev() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; - enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; irank == 2 ); - TEST_CHECK( diag_metric_cov_cu->ndim == 3 ); - TEST_CHECK( diag_metric_cov_cu->size == 10 ); - TEST_CHECK( diag_metric_cov_cu->ref_count.count == 1 ); + TEST_CHECK(diag_metric_cov_cu->rank == 2); + TEST_CHECK(diag_metric_cov_cu->ndim == 3); + TEST_CHECK(diag_metric_cov_cu->size == 10); + TEST_CHECK(diag_metric_cov_cu->ref_count.count == 1); - TEST_CHECK( gkyl_tensor_field_is_cu_dev(diag_metric_cov_cu) == true ); + TEST_CHECK(gkyl_tensor_field_is_cu_dev(diag_metric_cov_cu) == true); - TEST_CHECK( diag_metric_cov_cu->tdata->size == size ); - TEST_CHECK( diag_metric_cov_cu->tdata->ncomp == pow(ndim,rank) ); + TEST_CHECK(diag_metric_cov_cu->tdata->size == size); + TEST_CHECK(diag_metric_cov_cu->tdata->ncomp == pow(ndim, rank)); // create host array and initialize it - struct gkyl_tensor_field *diag_metric_cov = gkyl_tensor_field_new(rank,ndim,size,iloc_cov); - struct gkyl_tensor_field *ten_res = gkyl_tensor_field_new(rank,ndim,size,iloc_contra); - struct gkyl_tensor_field *diag_metric_contra = gkyl_tensor_field_new(rank,ndim,size,iloc_contra); + struct gkyl_tensor_field *diag_metric_cov = gkyl_tensor_field_new(rank, ndim, size, iloc_cov); + struct gkyl_tensor_field *ten_res = gkyl_tensor_field_new(rank, ndim, size, iloc_contra); + struct gkyl_tensor_field *diag_metric_contra = + gkyl_tensor_field_new(rank, ndim, size, iloc_contra); gkyl_tensor_field_copy(diag_metric_cov, diag_metric_cov_cu); gkyl_tensor_field_copy(ten_res, ten_res_cu); gkyl_tensor_field_copy(diag_metric_contra, diag_metric_contra_cu); - int idx[GKYL_MAX_DIM] = {0.0, 0.0}; - for (unsigned i=0; iiloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( ten_res->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); + TEST_CHECK(ten_res->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(ten_res->iloc[1] == GKYL_TENSOR_INDEX_UPPER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(diag_metric_cov_cu); @@ -665,61 +860,90 @@ void test_tensor_field_lower_idx_set_dev() gkyl_tensor_field_release(diag_metric_contra_cu); } - void test_tensor_field_raise_idx_set_dev() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; - enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; irank == 2 ); - TEST_CHECK( diag_metric_cov_cu->ndim == 3 ); - TEST_CHECK( diag_metric_cov_cu->size == 10 ); - TEST_CHECK( diag_metric_cov_cu->ref_count.count == 1 ); + TEST_CHECK(diag_metric_cov_cu->rank == 2); + TEST_CHECK(diag_metric_cov_cu->ndim == 3); + TEST_CHECK(diag_metric_cov_cu->size == 10); + TEST_CHECK(diag_metric_cov_cu->ref_count.count == 1); - TEST_CHECK( gkyl_tensor_field_is_cu_dev(diag_metric_cov_cu) == true ); + TEST_CHECK(gkyl_tensor_field_is_cu_dev(diag_metric_cov_cu) == true); - TEST_CHECK( diag_metric_cov_cu->tdata->size == size ); - TEST_CHECK( diag_metric_cov_cu->tdata->ncomp == pow(ndim,rank) ); + TEST_CHECK(diag_metric_cov_cu->tdata->size == size); + TEST_CHECK(diag_metric_cov_cu->tdata->ncomp == pow(ndim, rank)); // create host array and initialize it - struct gkyl_tensor_field *diag_metric_cov = gkyl_tensor_field_new(rank,ndim,size,iloc_cov); - struct gkyl_tensor_field *ten_res = gkyl_tensor_field_new(rank,ndim,size,iloc_cov); - struct gkyl_tensor_field *diag_metric_contra = gkyl_tensor_field_new(rank,ndim,size,iloc_contra); + struct gkyl_tensor_field *diag_metric_cov = gkyl_tensor_field_new(rank, ndim, size, iloc_cov); + struct gkyl_tensor_field *ten_res = gkyl_tensor_field_new(rank, ndim, size, iloc_cov); + struct gkyl_tensor_field *diag_metric_contra = + gkyl_tensor_field_new(rank, ndim, size, iloc_contra); gkyl_tensor_field_copy(diag_metric_cov, diag_metric_cov_cu); gkyl_tensor_field_copy(ten_res, ten_res_cu); gkyl_tensor_field_copy(diag_metric_contra, diag_metric_contra_cu); - int idx[GKYL_MAX_DIM] = {0.0, 0.0}; - for (unsigned i=0; iiloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( ten_res->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); + TEST_CHECK(ten_res->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(ten_res->iloc[1] == GKYL_TENSOR_INDEX_LOWER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(diag_metric_cov_cu); @@ -773,81 +1006,111 @@ void test_tensor_field_raise_idx_set_dev() gkyl_tensor_field_release(diag_metric_contra_cu); } -// This test is intended to verify: A_ij A^jk = \delta_i^k lowered and in place +// This test is intended to verify: A_ij A^jk = \delta_i^k lowered and in place // Tests a denser, asymmetric A, multiplication void test_tensor_field_lower_idx_in_place_dev() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; - enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; iiloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); + TEST_CHECK(diag_metric_cov_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER); - TEST_CHECK( diag_metric_cov_cu->rank == 2 ); - TEST_CHECK( diag_metric_cov_cu->ndim == 3 ); - TEST_CHECK( diag_metric_cov_cu->size == 10 ); - TEST_CHECK( diag_metric_cov_cu->ref_count.count == 1 ); + TEST_CHECK(diag_metric_cov_cu->rank == 2); + TEST_CHECK(diag_metric_cov_cu->ndim == 3); + TEST_CHECK(diag_metric_cov_cu->size == 10); + TEST_CHECK(diag_metric_cov_cu->ref_count.count == 1); - TEST_CHECK( gkyl_tensor_field_is_cu_dev(diag_metric_cov_cu) == true ); + TEST_CHECK(gkyl_tensor_field_is_cu_dev(diag_metric_cov_cu) == true); - TEST_CHECK( diag_metric_cov_cu->tdata->size == size ); - TEST_CHECK( diag_metric_cov_cu->tdata->ncomp == pow(ndim,rank) ); + TEST_CHECK(diag_metric_cov_cu->tdata->size == size); + TEST_CHECK(diag_metric_cov_cu->tdata->ncomp == pow(ndim, rank)); // create host array and initialize it - struct gkyl_tensor_field *diag_metric_cov = gkyl_tensor_field_new(rank,ndim,size,iloc_cov); - struct gkyl_tensor_field *mem = gkyl_tensor_field_new(rank,ndim,size,iloc_cov); - struct gkyl_tensor_field *diag_metric_contra = gkyl_tensor_field_new(rank,ndim,size,iloc_contra); + struct gkyl_tensor_field *diag_metric_cov = gkyl_tensor_field_new(rank, ndim, size, iloc_cov); + struct gkyl_tensor_field *mem = gkyl_tensor_field_new(rank, ndim, size, iloc_cov); + struct gkyl_tensor_field *diag_metric_contra = + gkyl_tensor_field_new(rank, ndim, size, iloc_contra); - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); gkyl_tensor_field_copy(diag_metric_cov, diag_metric_cov_cu); gkyl_tensor_field_copy(mem, mem_cu); gkyl_tensor_field_copy(diag_metric_contra, diag_metric_contra_cu); - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - - int idx[GKYL_MAX_DIM] = {0.0, 0.0}; - for (unsigned i=0; iiloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + + int idx[GKYL_MAX_DIM] = {0.0, 0.0}; + for (unsigned i = 0; i < size; ++i) { + for (unsigned j = 0; j < ndim; ++j) { + for (unsigned k = 0; k < ndim; ++k) { + double val = 0; + double val_inv; + idx[0] = j; + idx[1] = k; + if (j == 0 && k == 0) { + val = 5.0; + val_inv = -0.121990369181380; + } + if (j == 0 && k == 1) { + val = 3.0; + val_inv = 0.552166934189406; + } + if (j == 0 && k == 2) { + val = 1.0; + val_inv = 0.112359550561798; + } + if (j == 1 && k == 0) { + val = 2.0; + val_inv = 0.529695024077047; + } + if (j == 1 && k == 1) { + val = 0.5; + val_inv = -0.818619582664526; + } + if (j == 1 && k == 2) { + val = -1.0; + val_inv = -0.224719101123595; + } + if (j == 2 && k == 0) { + val = 4.5; + val_inv = 0.020866773675762; + } + if (j == 2 && k == 1) { + val = 0.8; + val_inv = -0.304975922953451; + } + if (j == 2 && k == 2) { + val = 6.0; + val_inv = 0.112359550561798; + } gkyl_tensor_field_elem_set(diag_metric_cov, i, idx, val); gkyl_tensor_field_elem_set(diag_metric_contra, i, idx, val_inv); } @@ -857,34 +1120,38 @@ void test_tensor_field_lower_idx_in_place_dev() gkyl_tensor_field_copy(diag_metric_cov_cu, diag_metric_cov); gkyl_tensor_field_copy(diag_metric_contra_cu, diag_metric_contra); - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER); // compute the lowering on device, save to ten_res int idx_to_raise = 0; - gkyl_tensor_field_lower_idx_in_place(diag_metric_cov_cu, idx_to_raise, diag_metric_contra_cu, mem_cu); - - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); + gkyl_tensor_field_lower_idx_in_place( + diag_metric_cov_cu, idx_to_raise, diag_metric_contra_cu, mem_cu + ); + + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER); // reset host array to zeros - for (unsigned i=0; iiloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - - // test that the result is delta^i_j - for (unsigned i=0; iiloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + + // test that the result is delta^i_j + for (unsigned i = 0; i < size; ++i) { + for (unsigned j = 0; j < ndim; ++j) { + for (unsigned k = 0; k < ndim; ++k) { + idx[0] = j; + idx[1] = k; const double val = gkyl_tensor_field_elem_fetch(diag_metric_contra, i, idx); //printf("delta(%d,%d) = %1.16e\n",j,k,val); - if (j == k) TEST_CHECK( gkyl_compare_double(val, 1.0, 1e-14) ); - if (j != k) TEST_CHECK( gkyl_compare_double(val, 0.0, 1e-14) ); + if (j == k) { + TEST_CHECK(gkyl_compare_double(val, 1.0, 1e-14)); + } + if (j != k) { + TEST_CHECK(gkyl_compare_double(val, 0.0, 1e-14)); + } } } } - TEST_CHECK( diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - TEST_CHECK( diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra->iloc[1] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_cov_cu->iloc[1] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra_cu->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + TEST_CHECK(diag_metric_contra_cu->iloc[1] == GKYL_TENSOR_INDEX_UPPER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(diag_metric_cov_cu); @@ -933,60 +1205,89 @@ void test_tensor_field_lower_idx_in_place_dev() gkyl_tensor_field_release(diag_metric_contra_cu); } - void test_tensor_field_raise_idx_in_place_dev() { - - int rank = 2; + int rank = 2; int ndim = 3; int size = 10; - enum gkyl_tensor_index_loc iloc_cov[GKYL_MAX_DIM]; enum gkyl_tensor_index_loc iloc_contra[GKYL_MAX_DIM]; - for (int i=0; irank == 2 ); - TEST_CHECK( diag_metric_cov_cu->ndim == 3 ); - TEST_CHECK( diag_metric_cov_cu->size == 10 ); - TEST_CHECK( diag_metric_cov_cu->ref_count.count == 1 ); + TEST_CHECK(diag_metric_cov_cu->rank == 2); + TEST_CHECK(diag_metric_cov_cu->ndim == 3); + TEST_CHECK(diag_metric_cov_cu->size == 10); + TEST_CHECK(diag_metric_cov_cu->ref_count.count == 1); - TEST_CHECK( gkyl_tensor_field_is_cu_dev(diag_metric_cov_cu) == true ); + TEST_CHECK(gkyl_tensor_field_is_cu_dev(diag_metric_cov_cu) == true); - TEST_CHECK( diag_metric_cov_cu->tdata->size == size ); - TEST_CHECK( diag_metric_cov_cu->tdata->ncomp == pow(ndim,rank) ); + TEST_CHECK(diag_metric_cov_cu->tdata->size == size); + TEST_CHECK(diag_metric_cov_cu->tdata->ncomp == pow(ndim, rank)); // create host array and initialize it - struct gkyl_tensor_field *diag_metric_cov = gkyl_tensor_field_new(rank,ndim,size,iloc_cov); - struct gkyl_tensor_field *mem = gkyl_tensor_field_new(rank,ndim,size,iloc_cov); - struct gkyl_tensor_field *diag_metric_contra = gkyl_tensor_field_new(rank,ndim,size,iloc_contra); + struct gkyl_tensor_field *diag_metric_cov = gkyl_tensor_field_new(rank, ndim, size, iloc_cov); + struct gkyl_tensor_field *mem = gkyl_tensor_field_new(rank, ndim, size, iloc_cov); + struct gkyl_tensor_field *diag_metric_contra = + gkyl_tensor_field_new(rank, ndim, size, iloc_contra); gkyl_tensor_field_copy(diag_metric_cov, diag_metric_cov_cu); gkyl_tensor_field_copy(diag_metric_contra, diag_metric_contra_cu); - int idx[GKYL_MAX_DIM] = {0.0, 0.0}; - for (unsigned i=0; iiloc[0] == GKYL_TENSOR_INDEX_UPPER ); - TEST_CHECK( diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); + TEST_CHECK(diag_metric_cov->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + TEST_CHECK(diag_metric_cov->iloc[1] == GKYL_TENSOR_INDEX_LOWER); gkyl_tensor_field_release(diag_metric_cov); gkyl_tensor_field_release(diag_metric_cov_cu); @@ -1039,24 +1349,22 @@ void test_tensor_field_raise_idx_in_place_dev() gkyl_tensor_field_release(diag_metric_contra_cu); } - #endif - TEST_LIST = { - { "test_tensor_field_raise_idx_in_place_ho", test_tensor_field_raise_idx_in_place_ho }, - { "test_tensor_field_lower_idx_in_place_ho", test_tensor_field_lower_idx_in_place_ho }, - { "test_tensor_field_lower_idx_in_place_2_ho", test_tensor_field_lower_idx_in_place_2_ho }, - { "test_tensor_field_raise_idx_in_place_2_ho", test_tensor_field_raise_idx_in_place_2_ho }, - { "test_tensor_field_raise_idx_set_ho", test_tensor_field_raise_idx_set_ho }, - { "test_tensor_field_lower_idx_set_ho", test_tensor_field_lower_idx_set_ho }, - { "test_tensor_field_lower_idx_set_2_ho", test_tensor_field_lower_idx_set_2_ho }, - { "test_tensor_field_raise_idx_set_2_ho", test_tensor_field_raise_idx_set_2_ho }, + {"test_tensor_field_raise_idx_in_place_ho", test_tensor_field_raise_idx_in_place_ho}, + {"test_tensor_field_lower_idx_in_place_ho", test_tensor_field_lower_idx_in_place_ho}, + {"test_tensor_field_lower_idx_in_place_2_ho", test_tensor_field_lower_idx_in_place_2_ho}, + {"test_tensor_field_raise_idx_in_place_2_ho", test_tensor_field_raise_idx_in_place_2_ho}, + {"test_tensor_field_raise_idx_set_ho", test_tensor_field_raise_idx_set_ho}, + {"test_tensor_field_lower_idx_set_ho", test_tensor_field_lower_idx_set_ho}, + {"test_tensor_field_lower_idx_set_2_ho", test_tensor_field_lower_idx_set_2_ho}, + {"test_tensor_field_raise_idx_set_2_ho", test_tensor_field_raise_idx_set_2_ho}, #ifdef GKYL_HAVE_CUDA - { "tensor_field_lower_idx_in_place_dev", test_tensor_field_lower_idx_in_place_dev }, - { "tensor_field_raise_idx_in_place_dev", test_tensor_field_raise_idx_in_place_dev }, - { "tensor_field_lower_idx_set_dev", test_tensor_field_lower_idx_set_dev }, - { "tensor_field_raise_idx_set_dev", test_tensor_field_raise_idx_set_dev }, -#endif - { NULL, NULL }, + {"tensor_field_lower_idx_in_place_dev", test_tensor_field_lower_idx_in_place_dev}, + {"tensor_field_raise_idx_in_place_dev", test_tensor_field_raise_idx_in_place_dev}, + {"tensor_field_lower_idx_set_dev", test_tensor_field_lower_idx_set_dev}, + {"tensor_field_raise_idx_set_dev", test_tensor_field_raise_idx_set_dev}, +#endif + {NULL, NULL} }; \ No newline at end of file diff --git a/core/unit/lctest_lua_utils.c b/core/unit/lctest_lua_utils.c index 4bb4485e8b..ca90c71247 100644 --- a/core/unit/lctest_lua_utils.c +++ b/core/unit/lctest_lua_utils.c @@ -4,8 +4,7 @@ #include -static lua_State * -new_lua_State(void) +static lua_State *new_lua_State(void) { lua_State *L = luaL_newstate(); lua_gc(L, LUA_GCSTOP, 0); @@ -14,126 +13,134 @@ new_lua_State(void) return L; } -void -test_0(void) +void test_0(void) { lua_State *L = new_lua_State(); const char *lcode1 = "tbl = { x = 1 }"; glua_run_lua(L, lcode1, strlen(lcode1), stderr); - with_lua_global(L, "tbl") { - - with_lua_tbl_tbl(L, "nope") { - TEST_CHECK( false ); + with_lua_global(L, "tbl") + { + with_lua_tbl_tbl(L, "nope") + { + TEST_CHECK(false); } - with_lua_tbl_tbl(L, "x") { - TEST_CHECK( false ); + with_lua_tbl_tbl(L, "x") + { + TEST_CHECK(false); } - with_lua_tbl_key(L, "nope") { - TEST_CHECK( false ); + with_lua_tbl_key(L, "nope") + { + TEST_CHECK(false); } - TEST_CHECK( 1 == glua_tbl_get_integer(L, "x", 0) ); + TEST_CHECK(1 == glua_tbl_get_integer(L, "x", 0)); } - - lua_close(L); + + lua_close(L); } -void -test_1(void) +void test_1(void) { lua_State *L = new_lua_State(); - + const char *lcode1 = "kvpairs = { x1 = 25.5, n1 = 2345, x2 = 32.5, n2 = 1234, bc = \"periodic\" }"; glua_run_lua(L, lcode1, strlen(lcode1), stderr); - const char *lcode2 = - "nums = { 0.5, 10.5, 20.5, 30.5 }"; + const char *lcode2 = "nums = { 0.5, 10.5, 20.5, 30.5 }"; glua_run_lua(L, lcode2, strlen(lcode2), stderr); - TEST_CHECK( 0 == lua_gettop(L) ); - with_lua_global(L, "does-not-exist") { - TEST_CHECK( false ); + TEST_CHECK(0 == lua_gettop(L)); + with_lua_global(L, "does-not-exist") + { + TEST_CHECK(false); } - TEST_CHECK( 0 == lua_gettop(L) ); + TEST_CHECK(0 == lua_gettop(L)); - with_lua_global(L, "kvpairs") { - TEST_CHECK( 1 == lua_gettop(L) ); + with_lua_global(L, "kvpairs") + { + TEST_CHECK(1 == lua_gettop(L)); } - TEST_CHECK( 0 == lua_gettop(L) ); + TEST_CHECK(0 == lua_gettop(L)); // push table on top of stack - with_lua_global(L, "kvpairs") { + with_lua_global(L, "kvpairs") + { + TEST_CHECK(0 == glua_objlen(L)); - TEST_CHECK( 0 == glua_objlen(L) ); + TEST_CHECK(glua_tbl_has_key(L, "x1")); + TEST_CHECK(glua_tbl_has_key(L, "x3") == false); - TEST_CHECK( glua_tbl_has_key(L, "x1") ); - TEST_CHECK( glua_tbl_has_key(L, "x3") == false ); - - TEST_CHECK( 25.5 == glua_tbl_get_number(L, "x1", 0.0) ); - TEST_CHECK( 32.5 == glua_tbl_get_number(L, "x2", 0.0) ); - TEST_CHECK( 12.5 == glua_tbl_get_number(L, "x3", 12.5) ); + TEST_CHECK(25.5 == glua_tbl_get_number(L, "x1", 0.0)); + TEST_CHECK(32.5 == glua_tbl_get_number(L, "x2", 0.0)); + TEST_CHECK(12.5 == glua_tbl_get_number(L, "x3", 12.5)); - TEST_CHECK( glua_tbl_has_key(L, "n1") ); - TEST_CHECK( glua_tbl_has_key(L, "n3") == false ); - - TEST_CHECK( glua_tbl_has_key(L, "bc") ); - TEST_CHECK( strcmp("periodic", glua_tbl_get_string(L, "bc", "N")) == 0 ); + TEST_CHECK(glua_tbl_has_key(L, "n1")); + TEST_CHECK(glua_tbl_has_key(L, "n3") == false); - with_lua_tbl_key(L, "bc") { + TEST_CHECK(glua_tbl_has_key(L, "bc")); + TEST_CHECK(strcmp("periodic", glua_tbl_get_string(L, "bc", "N")) == 0); + + with_lua_tbl_key(L, "bc") + { const char *val = lua_tostring(L, -1); - TEST_CHECK( strcmp("periodic", val) == 0 ); + TEST_CHECK(strcmp("periodic", val) == 0); } - with_lua_tbl_key(L, "does-not-exist") { - TEST_CHECK( false ); + with_lua_tbl_key(L, "does-not-exist") + { + TEST_CHECK(false); } - TEST_CHECK( 2345 == glua_tbl_get_integer(L, "n1", 0) ); - TEST_CHECK( 1234 == glua_tbl_get_integer(L, "n2", 0) ); - TEST_CHECK( 7890 == glua_tbl_get_integer(L, "n3", 7890) ); + TEST_CHECK(2345 == glua_tbl_get_integer(L, "n1", 0)); + TEST_CHECK(1234 == glua_tbl_get_integer(L, "n2", 0)); + TEST_CHECK(7890 == glua_tbl_get_integer(L, "n3", 7890)); } - TEST_CHECK( 0 == lua_gettop(L) ); + TEST_CHECK(0 == lua_gettop(L)); lua_close(L); } -void -test_2(void) +void test_2(void) { lua_State *L = new_lua_State(); - - const char *lcode1 = - "kvpairs = { tEnd = 101.1, nums = { 11, 12, 13, v = 2222 }, names = { \"Vlasov\", \"Maxwell\"} }"; - glua_run_lua(L, lcode1, strlen(lcode1), stderr); - with_lua_global(L, "kvpairs") { + const char *lcode1 = "kvpairs = { tEnd = 101.1, nums = { 11, 12, 13, v = 2222 }, names = { " + "\"Vlasov\", \"Maxwell\"} }"; + glua_run_lua(L, lcode1, strlen(lcode1), stderr); - with_lua_tbl_tbl(L, "nope") { - TEST_CHECK( false ); + with_lua_global(L, "kvpairs") + { + with_lua_tbl_tbl(L, "nope") + { + TEST_CHECK(false); } - with_lua_tbl_tbl(L, "nums") { + with_lua_tbl_tbl(L, "nums") + { TEST_CHECK(glua_tbl_has_key(L, "v")); TEST_CHECK(2222 == glua_tbl_get_integer(L, "v", 0)); TEST_CHECK(3 == glua_objlen(L)); - for (int i = 1; i <= glua_objlen(L); ++i) + for (int i = 1; i <= glua_objlen(L); ++i) { TEST_CHECK(10 + i == glua_tbl_iget_integer(L, i, 0)); + } - for (int i = 1; i <= glua_objlen(L); ++i) + for (int i = 1; i <= glua_objlen(L); ++i) { TEST_CHECK(10 + i == glua_tbl_iget_number(L, i, 0)); + } } TEST_CHECK(glua_tbl_has_key(L, "names")); - with_lua_tbl_tbl(L, "names") { + with_lua_tbl_tbl(L, "names") + { TEST_CHECK(2 == glua_objlen(L)); TEST_CHECK(strcmp("Vlasov", glua_tbl_iget_string(L, 1, "Einstein")) == 0); TEST_CHECK(strcmp("Maxwell", glua_tbl_iget_string(L, 2, "Einstein")) == 0); @@ -146,53 +153,51 @@ test_2(void) lua_close(L); } -void -test_3(void) +void test_3(void) { lua_State *L = new_lua_State(); - const char *lcode1 = - "function mysq(x) return x*x end; function twov(x) return x, 2*x end"; + const char *lcode1 = "function mysq(x) return x*x end; function twov(x) return x, 2*x end"; glua_run_lua(L, lcode1, strlen(lcode1), stderr); - TEST_CHECK( 0 == lua_gettop(L) ); - - with_lua_global(L, "mysq") { + TEST_CHECK(0 == lua_gettop(L)); + + with_lua_global(L, "mysq") + { lua_pushnumber(L, 2.5); if (lua_pcall(L, 1, 1, 0)) { // signal error condition - } - else { + } else { double res = lua_tonumber(L, -1); - TEST_CHECK( 2.5*2.5 == res ); + TEST_CHECK(2.5 * 2.5 == res); lua_pop(L, 1); } } - with_lua_global(L, "twov") { + with_lua_global(L, "twov") + { lua_pushnumber(L, 2.5); if (lua_pcall(L, 1, 2, 0)) { // signal error condition - } - else { + } else { // returned values are accessed in reverse order double r2 = lua_tonumber(L, -1); - TEST_CHECK( 2*2.5 == r2 ); + TEST_CHECK(2 * 2.5 == r2); lua_pop(L, 1); double r1 = lua_tonumber(L, -1); - TEST_CHECK( 2.5 == r1 ); + TEST_CHECK(2.5 == r1); lua_pop(L, 1); } - } + } - TEST_CHECK( 0 == lua_gettop(L) ); + TEST_CHECK(0 == lua_gettop(L)); const char *lcode2 = "kvpairs = { sq = function(x) return x*x end, x = 10.5 } "; glua_run_lua(L, lcode2, strlen(lcode2), stderr); - with_lua_global(L, "kvpairs") { - + with_lua_global(L, "kvpairs") + { if (glua_tbl_get_func(L, "no_sq")) { TEST_CHECK(false); } @@ -201,25 +206,23 @@ test_3(void) lua_pushnumber(L, 3.5); if (lua_pcall(L, 1, 1, 0)) { // signal error condition - } - else { + } else { double res = lua_tonumber(L, -1); - TEST_CHECK( 3.5*3.5 == res ); + TEST_CHECK(3.5 * 3.5 == res); lua_pop(L, 1); } } } - TEST_CHECK( 0 == lua_gettop(L) ); + TEST_CHECK(0 == lua_gettop(L)); lua_close(L); } -void -test_4(void) +void test_4(void) { /* lua_State *L = new_lua_State(); */ - + /* const char *lcode1 = */ /* "kvpairs = { tEnd = 101.1, nums = { 11, 12, 13, v = 2222 }, names = { \"Vlasov\", \"Maxwell\"} }"; */ /* glua_run_lua(L, lcode1, strlen(lcode1), stderr); */ @@ -230,15 +233,15 @@ test_4(void) /* printf("Stack top: %d\n", lua_gettop(L)); */ /* lua_pushnil(L); // initial key is nil */ - + /* while (lua_next(L, -2) != 0) { */ /* // key at -2 and value at -1 */ - + /* printf("-> Stack top: %d\n", lua_gettop(L)); */ /* printf("%s - %s\n", */ /* lua_typename(L, lua_type(L,-2)), */ /* lua_typename(L, lua_type(L,-1))); */ - + /* if (lua_type(L,-2) == LUA_TSTRING) { */ /* const char *key = lua_tolstring(L, -2, 0); */ /* printf("--> key is '%s'\n", key); */ @@ -250,22 +253,14 @@ test_4(void) /* TEST_CHECK( 0 == lua_gettop(L) ); */ /* lua_close(L); */ - } -TEST_LIST = { - { "test_0", test_0 }, - { "test_1", test_1 }, - { "test_2", test_2 }, - { "test_3", test_3 }, - {NULL, NULL}, -}; +TEST_LIST = + {{"test_0", test_0}, {"test_1", test_1}, {"test_2", test_2}, {"test_3", test_3}, {NULL, NULL}}; #else // nothing to test if not building with MPI -TEST_LIST = { - {NULL, NULL}, -}; +TEST_LIST = {{NULL, NULL}}; #endif diff --git a/core/unit/mctest_mpi_comm.c b/core/unit/mctest_mpi_comm.c index 976faff971..52180cf557 100644 --- a/core/unit/mctest_mpi_comm.c +++ b/core/unit/mctest_mpi_comm.c @@ -15,85 +15,76 @@ #include #include -static void -mpi_0_ho() +static void mpi_0_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); - TEST_CHECK( strcmp(comm->id, "mpi_comm") == 0 ); - TEST_CHECK( false == comm->has_decomp ); + TEST_CHECK(strcmp(comm->id, "mpi_comm") == 0); + TEST_CHECK(false == comm->has_decomp); int rank; gkyl_comm_get_rank(comm, &rank); int m_rank; MPI_Comm_rank(MPI_COMM_WORLD, &m_rank); - TEST_CHECK( rank == m_rank ); + TEST_CHECK(rank == m_rank); int sz; gkyl_comm_get_size(comm, &sz); - TEST_CHECK( sz == m_sz ); + TEST_CHECK(sz == m_sz); gkyl_comm_release(comm); } -static void -mpi_1_ho() +static void mpi_1_ho() { struct gkyl_range range; - gkyl_range_init(&range, 2, (int[]) { 1, 1 }, (int[]) { 100, 100 }); + gkyl_range_init(&range, 2, (int[]){1, 1}, (int[]){100, 100}); int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - - int cuts[] = { m_sz, 1 }; - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp - } - ); - TEST_CHECK( comm->has_decomp ); + int cuts[] = {m_sz, 1}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); + + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + + TEST_CHECK(comm->has_decomp); int rank; gkyl_comm_get_rank(comm, &rank); int m_rank; MPI_Comm_rank(MPI_COMM_WORLD, &m_rank); - TEST_CHECK( rank == m_rank ); + TEST_CHECK(rank == m_rank); int sz; gkyl_comm_get_size(comm, &sz); - TEST_CHECK( sz == m_sz ); + TEST_CHECK(sz == m_sz); gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); } -static void -mpi_n2_allreduce_ho() +static void mpi_n2_allreduce_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 2) return; - + if (m_sz != 2) { + return; + } + struct gkyl_range range; - gkyl_range_init(&range, 2, (int[]) { 1, 1 }, (int[]) { 100, 100 }); - - int cuts[] = { 1, 1 }; - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp - } - ); + gkyl_range_init(&range, 2, (int[]){1, 1}, (int[]){100, 100}); + + int cuts[] = {1, 1}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); + + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); int m_rank; MPI_Comm_rank(MPI_COMM_WORLD, &m_rank); @@ -111,44 +102,42 @@ mpi_n2_allreduce_ho() double v_max[2], v_min[2], v_sum[2]; gkyl_comm_allreduce(comm, GKYL_DOUBLE, GKYL_MAX, 2, vals, v_max); - TEST_CHECK( v_max[0] == 3.0 ); - TEST_CHECK( v_max[1] == 2.0 ); + TEST_CHECK(v_max[0] == 3.0); + TEST_CHECK(v_max[1] == 2.0); gkyl_comm_allreduce(comm, GKYL_DOUBLE, GKYL_MIN, 2, vals, v_min); - TEST_CHECK( v_min[0] == 1.0 ); - TEST_CHECK( v_min[1] == -1.0 ); + TEST_CHECK(v_min[0] == 1.0); + TEST_CHECK(v_min[1] == -1.0); gkyl_comm_allreduce(comm, GKYL_DOUBLE, GKYL_SUM, 2, vals, v_sum); - TEST_CHECK( v_sum[0] == 4.0 ); - TEST_CHECK( v_sum[1] == 1.0 ); + TEST_CHECK(v_sum[0] == 4.0); + TEST_CHECK(v_sum[1] == 1.0); gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); } -static void -mpi_n2_allgather_1d_ho() +static void mpi_n2_allgather_1d_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 2) return; + if (m_sz != 2) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); struct gkyl_range global; - gkyl_range_init(&global, 1, (int[]) { 1 }, (int[]) { 10 }); + gkyl_range_init(&global, 1, (int[]){1}, (int[]){10}); - int cuts[] = { 2 }; + int cuts[] = {2}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(global.ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); - int nghost[] = { 1 }; + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -161,8 +150,8 @@ mpi_n2_allgather_1d_ho() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr_local, idx); - f[0] = idx+10.0*rank; + double *f = gkyl_array_fetch(arr_local, idx); + f[0] = idx + 10.0 * rank; } gkyl_comm_array_allgather(comm, &local, &global, arr_local, arr_global); @@ -173,43 +162,42 @@ mpi_n2_allgather_1d_ho() long idx = gkyl_range_idx(&global, iter_global.idx); double *f = gkyl_array_fetch(arr_global, idx); // first 5 entries are 1-5, second 5 entries are 11-15 - if (idx < local.volume) - TEST_CHECK( idx+1.0 == f[0] ); - else - TEST_CHECK( idx+6.0 == f[0] ); + if (idx < local.volume) { + TEST_CHECK(idx + 1.0 == f[0]); + } else { + TEST_CHECK(idx + 6.0 == f[0]); + } } gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_array_release(arr_local); - gkyl_array_release(arr_global); + gkyl_array_release(arr_local); + gkyl_array_release(arr_global); } -static void -mpi_n4_allgather_2d_ho() +static void mpi_n4_allgather_2d_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); // create global range - int cells[] = { 10, 10 }; + int cells[] = {10, 10}; struct gkyl_range global; gkyl_create_global_range(2, cells, &global); - int cuts[] = { 2, 2 }; - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &global); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + int cuts[] = {2, 2}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &global); - int nghost[] = { 1, 1 }; + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -222,9 +210,9 @@ mpi_n4_allgather_2d_ho() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr_local, idx); - f[0] = iter.idx[0] + iter.idx[1]*(rank+1.0) + 10.0*rank; - } + double *f = gkyl_array_fetch(arr_local, idx); + f[0] = iter.idx[0] + iter.idx[1] * (rank + 1.0) + 10.0 * rank; + } gkyl_comm_array_allgather(comm, &local, &global, arr_local, arr_global); @@ -233,53 +221,53 @@ mpi_n4_allgather_2d_ho() while (gkyl_range_iter_next(&iter_global)) { long idx = gkyl_range_idx(&global, iter_global.idx); double *f = gkyl_array_fetch(arr_global, idx); - // check value of {2, 2} decomp organized as + // check value of {2, 2} decomp organized as // rank 0 owns {1, 1} to {5, 5} - // rank 1 owns {1, 6} to {5, 10} - // rank 2 owns {6, 1} to {10, 5} + // rank 1 owns {1, 6} to {5, 10} + // rank 2 owns {6, 1} to {10, 5} // rank 3 owns {6, 6} to {10, 10} double val; - if (iter_global.idx[0] <= cells[0]/cuts[0] && iter_global.idx[1] <= cells[1]/cuts[1]) + if (iter_global.idx[0] <= cells[0] / cuts[0] && iter_global.idx[1] <= cells[1] / cuts[1]) { val = iter_global.idx[0] + iter_global.idx[1]; - else if (iter_global.idx[0] <= cells[0]/cuts[0] && iter_global.idx[1] > cells[1]/cuts[1]) - val = iter_global.idx[0] + iter_global.idx[1]*2.0 + 10.0; - else if (iter_global.idx[0] > cells[0]/cuts[0] && iter_global.idx[1] <= cells[1]/cuts[1]) - val = iter_global.idx[0] + iter_global.idx[1]*3.0 + 20.0; - else - val = iter_global.idx[0] + iter_global.idx[1]*4.0 + 30.0; - TEST_CHECK( val == f[0] ); + } else if (iter_global.idx[0] <= cells[0] / cuts[0] && + iter_global.idx[1] > cells[1] / cuts[1]) { + val = iter_global.idx[0] + iter_global.idx[1] * 2.0 + 10.0; + } else if (iter_global.idx[0] > cells[0] / cuts[0] && + iter_global.idx[1] <= cells[1] / cuts[1]) { + val = iter_global.idx[0] + iter_global.idx[1] * 3.0 + 20.0; + } else { + val = iter_global.idx[0] + iter_global.idx[1] * 4.0 + 30.0; + } + TEST_CHECK(val == f[0]); } gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_array_release(arr_local); - gkyl_array_release(arr_global); + gkyl_array_release(arr_local); + gkyl_array_release(arr_global); } - -static void -mpi_n2_allgather_1d_host_ho() +static void mpi_n2_allgather_1d_host_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 2) return; + if (m_sz != 2) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); struct gkyl_range global; - gkyl_range_init(&global, 1, (int[]) { 1 }, (int[]) { 10 }); + gkyl_range_init(&global, 1, (int[]){1}, (int[]){10}); - int cuts[] = { 2 }; + int cuts[] = {2}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(global.ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); - int nghost[] = { 1 }; + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -292,8 +280,8 @@ mpi_n2_allgather_1d_host_ho() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr_local, idx); - f[0] = idx+10.0*rank; + double *f = gkyl_array_fetch(arr_local, idx); + f[0] = idx + 10.0 * rank; } gkyl_comm_array_allgather_host(comm, &local, &global, arr_local, arr_global); @@ -304,43 +292,42 @@ mpi_n2_allgather_1d_host_ho() long idx = gkyl_range_idx(&global, iter_global.idx); double *f = gkyl_array_fetch(arr_global, idx); // first 5 entries are 1-5, second 5 entries are 11-15 - if (idx < local.volume) - TEST_CHECK( idx+1.0 == f[0] ); - else - TEST_CHECK( idx+6.0 == f[0] ); + if (idx < local.volume) { + TEST_CHECK(idx + 1.0 == f[0]); + } else { + TEST_CHECK(idx + 6.0 == f[0]); + } } gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_array_release(arr_local); - gkyl_array_release(arr_global); + gkyl_array_release(arr_local); + gkyl_array_release(arr_global); } -static void -mpi_n4_allgather_2d_host_ho() +static void mpi_n4_allgather_2d_host_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); // create global range - int cells[] = { 10, 10 }; + int cells[] = {10, 10}; struct gkyl_range global; gkyl_create_global_range(2, cells, &global); - int cuts[] = { 2, 2 }; - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &global); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + int cuts[] = {2, 2}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &global); + + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -353,9 +340,9 @@ mpi_n4_allgather_2d_host_ho() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr_local, idx); - f[0] = iter.idx[0] + iter.idx[1]*(rank+1.0) + 10.0*rank; - } + double *f = gkyl_array_fetch(arr_local, idx); + f[0] = iter.idx[0] + iter.idx[1] * (rank + 1.0) + 10.0 * rank; + } gkyl_comm_array_allgather_host(comm, &local, &global, arr_local, arr_global); @@ -364,53 +351,53 @@ mpi_n4_allgather_2d_host_ho() while (gkyl_range_iter_next(&iter_global)) { long idx = gkyl_range_idx(&global, iter_global.idx); double *f = gkyl_array_fetch(arr_global, idx); - // check value of {2, 2} decomp organized as + // check value of {2, 2} decomp organized as // rank 0 owns {1, 1} to {5, 5} - // rank 1 owns {1, 6} to {5, 10} - // rank 2 owns {6, 1} to {10, 5} + // rank 1 owns {1, 6} to {5, 10} + // rank 2 owns {6, 1} to {10, 5} // rank 3 owns {6, 6} to {10, 10} double val; - if (iter_global.idx[0] <= cells[0]/cuts[0] && iter_global.idx[1] <= cells[1]/cuts[1]) + if (iter_global.idx[0] <= cells[0] / cuts[0] && iter_global.idx[1] <= cells[1] / cuts[1]) { val = iter_global.idx[0] + iter_global.idx[1]; - else if (iter_global.idx[0] <= cells[0]/cuts[0] && iter_global.idx[1] > cells[1]/cuts[1]) - val = iter_global.idx[0] + iter_global.idx[1]*2.0 + 10.0; - else if (iter_global.idx[0] > cells[0]/cuts[0] && iter_global.idx[1] <= cells[1]/cuts[1]) - val = iter_global.idx[0] + iter_global.idx[1]*3.0 + 20.0; - else - val = iter_global.idx[0] + iter_global.idx[1]*4.0 + 30.0; - TEST_CHECK( val == f[0] ); + } else if (iter_global.idx[0] <= cells[0] / cuts[0] && + iter_global.idx[1] > cells[1] / cuts[1]) { + val = iter_global.idx[0] + iter_global.idx[1] * 2.0 + 10.0; + } else if (iter_global.idx[0] > cells[0] / cuts[0] && + iter_global.idx[1] <= cells[1] / cuts[1]) { + val = iter_global.idx[0] + iter_global.idx[1] * 3.0 + 20.0; + } else { + val = iter_global.idx[0] + iter_global.idx[1] * 4.0 + 30.0; + } + TEST_CHECK(val == f[0]); } gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_array_release(arr_local); - gkyl_array_release(arr_global); + gkyl_array_release(arr_local); + gkyl_array_release(arr_global); } -static void -mpi_n2_sync_1d_ho() +static void mpi_n2_sync_1d_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 2) return; + if (m_sz != 2) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); struct gkyl_range range; - gkyl_range_init(&range, 1, (int[]) { 1 }, (int[]) { 10 }); + gkyl_range_init(&range, 1, (int[]){1}, (int[]){10}); - int cuts[] = { 2 }; + int cuts[] = {2}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - .sync_corners = false, - } - ); - int nghost[] = { 1 }; + struct gkyl_comm *comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp, .sync_corners = false}); + + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -421,7 +408,7 @@ mpi_n2_sync_1d_ho() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr, idx); + double *f = gkyl_array_fetch(arr, idx); f[0] = iter.idx[0]; } @@ -433,9 +420,9 @@ mpi_n2_sync_1d_ho() gkyl_range_iter_init(&iter, &in_range); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&in_range, iter.idx); - const double *f = gkyl_array_cfetch(arr, idx); - - TEST_CHECK( iter.idx[0] == f[0] ); + const double *f = gkyl_array_cfetch(arr, idx); + + TEST_CHECK(iter.idx[0] == f[0]); } gkyl_rect_decomp_release(decomp); @@ -443,51 +430,47 @@ mpi_n2_sync_1d_ho() gkyl_array_release(arr); } -static void -mpi_n4_sync_2d(bool use_corners) +static void mpi_n4_sync_2d(bool use_corners) { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); struct gkyl_range range; - gkyl_range_init(&range, 2, (int[]) { 1, 1 }, (int[]) { 10, 10 }); - - int cuts[] = { 2, 2 }; - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - .sync_corners = use_corners, - } - ); + gkyl_range_init(&range, 2, (int[]){1, 1}, (int[]){10, 10}); + + int cuts[] = {2, 2}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); - int nghost[] = { 1, 1 }; + struct gkyl_comm *comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp, .sync_corners = use_corners}); + + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); struct gkyl_range local_x, local_ext_x, local_y, local_ext_y; - gkyl_create_ranges(&decomp->ranges[rank], (int[]) {1, 0}, - &local_ext_x, &local_x); - - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { 0, 1 }, - &local_ext_y, &local_y); + gkyl_create_ranges(&decomp->ranges[rank], (int[]){1, 0}, &local_ext_x, &local_x); + + gkyl_create_ranges(&decomp->ranges[rank], (int[]){0, 1}, &local_ext_y, &local_y); struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, 2, local_ext.volume); gkyl_array_clear(arr, 200005); gkyl_comm_barrier(comm); - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr, idx); - f[0] = iter.idx[0]; f[1] = iter.idx[1]; + double *f = gkyl_array_fetch(arr, idx); + f[0] = iter.idx[0]; + f[1] = iter.idx[1]; } gkyl_comm_array_sync(comm, &local, &local_ext, arr); @@ -498,17 +481,17 @@ mpi_n4_sync_2d(bool use_corners) gkyl_range_iter_init(&iter, &in_range); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&in_range, iter.idx); - const double *f = gkyl_array_cfetch(arr, idx); + const double *f = gkyl_array_cfetch(arr, idx); if (use_corners) { - TEST_CHECK( iter.idx[0] == f[0] ); - TEST_CHECK( iter.idx[1] == f[1] ); - } - else { + TEST_CHECK(iter.idx[0] == f[0]); + TEST_CHECK(iter.idx[1] == f[1]); + } else { // excludes corners - if (gkyl_range_contains_idx(&local_ext_x, iter.idx) || gkyl_range_contains_idx(&local_ext_y, iter.idx)) { - TEST_CHECK( iter.idx[0] == f[0] ); - TEST_CHECK( iter.idx[1] == f[1] ); + if (gkyl_range_contains_idx(&local_ext_x, iter.idx) || + gkyl_range_contains_idx(&local_ext_y, iter.idx)) { + TEST_CHECK(iter.idx[0] == f[0]); + TEST_CHECK(iter.idx[1] == f[1]); } } } @@ -518,38 +501,41 @@ mpi_n4_sync_2d(bool use_corners) gkyl_array_release(arr); } -void mpi_n4_sync_2d_no_corner_ho() { mpi_n4_sync_2d(false); } -void mpi_n4_sync_2d_use_corner_ho() { mpi_n4_sync_2d(true); } +void mpi_n4_sync_2d_no_corner_ho() +{ + mpi_n4_sync_2d(false); +} +void mpi_n4_sync_2d_use_corner_ho() +{ + mpi_n4_sync_2d(true); +} -static void -mpi_n4_sync_1x1v_ho() +static void mpi_n4_sync_1x1v_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); struct gkyl_range range; - gkyl_range_init(&range, 1, (int[]) { 1 }, (int[]) { 512 }); + gkyl_range_init(&range, 1, (int[]){1}, (int[]){512}); - int cuts[] = { m_sz }; + int cuts[] = {m_sz}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(1, cuts, &range); - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); struct gkyl_range vrange; - gkyl_range_init(&vrange, 1, (int[]) { 1 }, (int[]) { 64 } ); + gkyl_range_init(&vrange, 1, (int[]){1}, (int[]){64}); - struct gkyl_rect_decomp *ext_decomp = - gkyl_rect_decomp_extended_new(&vrange, decomp); + struct gkyl_rect_decomp *ext_decomp = gkyl_rect_decomp_extended_new(&vrange, decomp); - int nghost[] = { 1, 0 }; + int nghost[] = {1, 0}; struct gkyl_range local, local_ext; gkyl_create_ranges(&ext_decomp->ranges[rank], nghost, &local_ext, &local); @@ -563,8 +549,9 @@ mpi_n4_sync_1x1v_ho() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr, idx); - f[0] = iter.idx[0]; f[1] = iter.idx[1]; + double *f = gkyl_array_fetch(arr, idx); + f[0] = iter.idx[0]; + f[1] = iter.idx[1]; } gkyl_comm_array_sync(ext_comm, &local, &local_ext, arr); @@ -575,10 +562,10 @@ mpi_n4_sync_1x1v_ho() gkyl_range_iter_init(&iter, &in_range); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&in_range, iter.idx); - const double *f = gkyl_array_cfetch(arr, idx); + const double *f = gkyl_array_cfetch(arr, idx); - TEST_CHECK( iter.idx[0] == f[0] ); - TEST_CHECK( iter.idx[1] == f[1] ); + TEST_CHECK(iter.idx[0] == f[0]); + TEST_CHECK(iter.idx[1] == f[1]); } gkyl_array_release(arr); @@ -588,39 +575,34 @@ mpi_n4_sync_1x1v_ho() gkyl_rect_decomp_release(decomp); } -static void -mpi_n1_per_sync_2d_tests(int num_per_dirs, int *per_dirs) +static void mpi_n1_per_sync_2d_tests(int num_per_dirs, int *per_dirs) { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 1) return; - + if (m_sz != 1) { + return; + } + struct gkyl_range range; - gkyl_range_init(&range, 2, (int[]) { 1, 1 }, (int[]) { 4, 4 }); + gkyl_range_init(&range, 2, (int[]){1, 1}, (int[]){4, 4}); - int cuts[] = { 1, 1 }; - struct gkyl_rect_decomp *decomp = - gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); + int cuts[] = {1, 1}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .decomp = decomp, - .mpi_comm = MPI_COMM_WORLD, - } - ); + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.decomp = decomp, .mpi_comm = MPI_COMM_WORLD}); int rank; gkyl_comm_get_rank(comm, &rank); - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); struct gkyl_range local_x[2], local_ext_x[2]; - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { nghost[0], 0 }, - &local_ext_x[0], &local_x[0]); - - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { 0, nghost[1] }, - &local_ext_x[1], &local_x[1]); + gkyl_create_ranges(&decomp->ranges[rank], (int[]){nghost[0], 0}, &local_ext_x[0], &local_x[0]); + + gkyl_create_ranges(&decomp->ranges[rank], (int[]){0, nghost[1]}, &local_ext_x[1], &local_x[1]); struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); gkyl_array_clear(arr, 200005); @@ -629,39 +611,44 @@ mpi_n1_per_sync_2d_tests(int num_per_dirs, int *per_dirs) gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr, idx); + double *f = gkyl_array_fetch(arr, idx); - for (int d=0; d local.upper[d]) + } + if (idx[d] > local.upper[d]) { idx[d] = idx[d] - ncell; - else + } else { idx[d] = idx[d] + ncell; - - const double *f = gkyl_array_cfetch(arr, lidx); - for (int n=0; nranges[rank], nghost, &local_ext, &local); struct gkyl_range local_x[2], local_ext_x[2]; - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { nghost[0], 0 }, - &local_ext_x[0], &local_x[0]); - - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { 0, nghost[1] }, - &local_ext_x[1], &local_x[1]); + gkyl_create_ranges(&decomp->ranges[rank], (int[]){nghost[0], 0}, &local_ext_x[0], &local_x[0]); + + gkyl_create_ranges(&decomp->ranges[rank], (int[]){0, nghost[1]}, &local_ext_x[1], &local_x[1]); // Redefine local_ext_x so it's local shifted in the right direction // so it covers the ghost cells of interest. int decomp_dir = cuts[0] > 1 ? 0 : 1; int delta[] = {0, 0}; - delta[decomp_dir] = 2*rank-1; + delta[decomp_dir] = 2 * rank - 1; struct gkyl_range local_ext_x_shifted; gkyl_range_shift(&local_ext_x_shifted, &local_ext_x[decomp_dir], delta); - gkyl_sub_range_init(&local_ext_x[decomp_dir], &local_ext, local_ext_x_shifted.lower, local_ext_x_shifted.upper); + gkyl_sub_range_init( + &local_ext_x[decomp_dir], &local_ext, local_ext_x_shifted.lower, local_ext_x_shifted.upper + ); struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); gkyl_array_clear(arr, 200005); @@ -736,39 +719,45 @@ mpi_n2_per_sync_2d_tests(int *cuts, int num_per_dirs, int *per_dirs) gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr, idx); + double *f = gkyl_array_fetch(arr, idx); - for (int d=0; d local.upper[d]) + for (int n = 0; n < local.ndim; ++n) { + idx[n] = iter.idx[n]; + } + + if (idx[d] > local.upper[d]) { idx[d] = idx[d] - ncell; - else if (idx[d] < local.lower[d]) + } else if (idx[d] < local.lower[d]) { idx[d] = idx[d] + ncell; - - const double *f = gkyl_array_cfetch(arr, lidx); - for (int n=0; nranges[rank], nghost, &local_ext, &local); - struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, 1, local_ext.volume); gkyl_array_clear_range(arr, 1.5, &local); gkyl_comm_array_sync(comm, &local, &local_ext, arr); - gkyl_comm_array_per_sync(comm, &local, &local_ext, 2, (int[]) { 0, 1 }, arr); + gkyl_comm_array_per_sync(comm, &local, &local_ext, 2, (int[]){0, 1}, arr); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local_ext); while (gkyl_range_iter_next(&iter)) { const double *d = gkyl_array_cfetch(arr, gkyl_range_idx(&local_ext, iter.idx)); - TEST_CHECK( d[0] == 1.5 ); + TEST_CHECK(d[0] == 1.5); } gkyl_rect_decomp_release(decomp); @@ -824,30 +808,26 @@ mpi_per_sync_corner_2d(int nrank, int cuts[]) gkyl_array_release(arr); } -static void -mpi_n1_per_sync_corner_2d_ho(void) +static void mpi_n1_per_sync_corner_2d_ho(void) { - mpi_per_sync_corner_2d(1, (int[]) { 1, 1 }); + mpi_per_sync_corner_2d(1, (int[]){1, 1}); } -static void -mpi_n2_per_sync_corner_2d_ho(void) +static void mpi_n2_per_sync_corner_2d_ho(void) { - mpi_per_sync_corner_2d(2, (int[]) { 2, 1 }); + mpi_per_sync_corner_2d(2, (int[]){2, 1}); } -static void -mpi_n4_per_sync_corner_2d_ho(void) +static void mpi_n4_per_sync_corner_2d_ho(void) { - mpi_per_sync_corner_2d(4, (int[]) { 2, 2 }); + mpi_per_sync_corner_2d(4, (int[]){2, 2}); } -static void -mpi_n2_per_sync_2d_ho() +static void mpi_n2_per_sync_2d_ho() { - int cuts_21[] = {2,1}; - int cuts_12[] = {1,2}; + int cuts_21[] = {2, 1}; + int cuts_12[] = {1, 2}; int per_dirs_0[] = {0}; int per_dirs_1[] = {1}; - int per_dirs_01[] = {0,1}; + int per_dirs_01[] = {0, 1}; mpi_n2_per_sync_2d_tests(cuts_21, 1, per_dirs_0); mpi_n2_per_sync_2d_tests(cuts_21, 1, per_dirs_1); @@ -858,30 +838,26 @@ mpi_n2_per_sync_2d_ho() mpi_n2_per_sync_2d_tests(cuts_12, 2, per_dirs_01); } -static void -mpi_per_sync_corner_3d(int nrank, int cuts[]) +static void mpi_per_sync_corner_3d(int nrank, int cuts[]) { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != nrank) return; - + if (m_sz != nrank) { + return; + } + struct gkyl_range range; - gkyl_range_init(&range, 3, (int[]) { 1, 1, 1 }, (int[]) { 10, 10, 10 }); + gkyl_range_init(&range, 3, (int[]){1, 1, 1}, (int[]){10, 10, 10}); - struct gkyl_rect_decomp *decomp = - gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .decomp = decomp, - .mpi_comm = MPI_COMM_WORLD, - .sync_corners = true - } - ); + struct gkyl_comm *comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.decomp = decomp, .mpi_comm = MPI_COMM_WORLD, .sync_corners = true}); int rank; gkyl_comm_get_rank(comm, &rank); - int nghost[] = { 1, 1, 1 }; + int nghost[] = {1, 1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -890,16 +866,17 @@ mpi_per_sync_corner_3d(int nrank, int cuts[]) gkyl_array_clear_range(arr, 1.5, &local); gkyl_comm_array_sync(comm, &local, &local_ext, arr); - gkyl_comm_array_per_sync(comm, &local, &local_ext, 3, (int[]) { 0, 1, 2 }, arr); + gkyl_comm_array_per_sync(comm, &local, &local_ext, 3, (int[]){0, 1, 2}, arr); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local_ext); while (gkyl_range_iter_next(&iter)) { const double *d = gkyl_array_cfetch(arr, gkyl_range_idx(&local_ext, iter.idx)); - if (!TEST_CHECK( d[0] == 1.5 )) { - TEST_MSG("3D periodic sync failed on rank %d (%d,%d,%d). Expected %g. Got %g\n", - rank, iter.idx[0], iter.idx[1], iter.idx[2], - 1.5, d[0]); + if (!TEST_CHECK(d[0] == 1.5)) { + TEST_MSG( + "3D periodic sync failed on rank %d (%d,%d,%d). Expected %g. Got %g\n", rank, iter.idx[0], + iter.idx[1], iter.idx[2], 1.5, d[0] + ); } } @@ -908,30 +885,25 @@ mpi_per_sync_corner_3d(int nrank, int cuts[]) gkyl_array_release(arr); } -static void -mpi_n1_per_sync_corner_3d_ho(void) +static void mpi_n1_per_sync_corner_3d_ho(void) { - mpi_per_sync_corner_3d(1, (int[]) { 1, 1, 1 }); + mpi_per_sync_corner_3d(1, (int[]){1, 1, 1}); } -static void -mpi_n2_per_sync_corner_3d_ho(void) +static void mpi_n2_per_sync_corner_3d_ho(void) { - mpi_per_sync_corner_3d(2, (int[]) { 2, 1, 1 }); + mpi_per_sync_corner_3d(2, (int[]){2, 1, 1}); } -static void -mpi_n4_per_sync_corner_3d_ho(void) +static void mpi_n4_per_sync_corner_3d_ho(void) { - mpi_per_sync_corner_3d(4, (int[]) { 2, 1, 2 }); + mpi_per_sync_corner_3d(4, (int[]){2, 1, 2}); } -static void -mpi_n8_per_sync_corner_3d_ho(void) +static void mpi_n8_per_sync_corner_3d_ho(void) { - mpi_per_sync_corner_3d(8, (int[]) { 2, 2, 2 }); + mpi_per_sync_corner_3d(8, (int[]){2, 2, 2}); } -static void -mpi_n27_per_sync_corner_3d_ho(void) +static void mpi_n27_per_sync_corner_3d_ho(void) { - mpi_per_sync_corner_3d(27, (int[]) { 3, 3, 3 }); + mpi_per_sync_corner_3d(27, (int[]){3, 3, 3}); } /* static void */ @@ -1081,7 +1053,7 @@ mpi_n27_per_sync_corner_3d_ho(void) /* int confcuts[] = { 2, 1 }; */ /* struct gkyl_rect_decomp *confdecomp = gkyl_rect_decomp_new_from_cuts(2, confcuts, &range); */ - + /* int worldrank; */ /* gkyl_comm_get_rank(worldcomm, &worldrank); */ @@ -1163,60 +1135,60 @@ mpi_n27_per_sync_corner_3d_ho(void) /* gkyl_comm_release(worldcomm); */ /* } */ -static void -mpi_n4_create_comm_from_ranks_1_ho() +static void mpi_n4_create_comm_from_ranks_1_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); - int branks[2] = { 2, 2 }; + int branks[2] = {2, 2}; bool status = false; - - const struct gkyl_rrobin_decomp *rrd = - gkyl_rrobin_decomp_new(m_sz, 2, branks); + + const struct gkyl_rrobin_decomp *rrd = gkyl_rrobin_decomp_new(m_sz, 2, branks); int rb1[4]; gkyl_rrobin_decomp_getranks(rrd, 0, rb1); - struct gkyl_comm *comm_b1 = - gkyl_comm_create_comm_from_ranks(comm, branks[0], rb1, 0, &status); + struct gkyl_comm *comm_b1 = gkyl_comm_create_comm_from_ranks(comm, branks[0], rb1, 0, &status); - if (rank == rb1[0]) - TEST_CHECK( status ); - if (rank == rb1[1]) - TEST_CHECK( status ); + if (rank == rb1[0]) { + TEST_CHECK(status); + } + if (rank == rb1[1]) { + TEST_CHECK(status); + } if (comm_b1) { int sz_b1; gkyl_comm_get_size(comm_b1, &sz_b1); - TEST_CHECK( branks[0] == sz_b1); + TEST_CHECK(branks[0] == sz_b1); } int rb2[4]; gkyl_rrobin_decomp_getranks(rrd, 1, rb2); - struct gkyl_comm *comm_b2 = - gkyl_comm_create_comm_from_ranks(comm, branks[1], rb2, 0, &status); + struct gkyl_comm *comm_b2 = gkyl_comm_create_comm_from_ranks(comm, branks[1], rb2, 0, &status); - if (rank == rb2[0]) - TEST_CHECK( status ); - if (rank == rb2[1]) - TEST_CHECK( status ); + if (rank == rb2[0]) { + TEST_CHECK(status); + } + if (rank == rb2[1]) { + TEST_CHECK(status); + } if (comm_b2) { int sz_b2; gkyl_comm_get_size(comm_b2, &sz_b2); - TEST_CHECK( branks[1] == sz_b2); - } + TEST_CHECK(branks[1] == sz_b2); + } gkyl_rrobin_decomp_release(rrd); gkyl_comm_release(comm); @@ -1224,63 +1196,65 @@ mpi_n4_create_comm_from_ranks_1_ho() gkyl_comm_release(comm_b2); } -static void -mpi_n4_create_comm_from_ranks_2_ho() +static void mpi_n4_create_comm_from_ranks_2_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); - int branks[2] = { 4, 2 }; + int branks[2] = {4, 2}; bool status = false; - - const struct gkyl_rrobin_decomp *rrd = - gkyl_rrobin_decomp_new(m_sz, 2, branks); + + const struct gkyl_rrobin_decomp *rrd = gkyl_rrobin_decomp_new(m_sz, 2, branks); int rb1[4]; gkyl_rrobin_decomp_getranks(rrd, 0, rb1); - struct gkyl_comm *comm_b1 = - gkyl_comm_create_comm_from_ranks(comm, branks[0], rb1, 0, &status); + struct gkyl_comm *comm_b1 = gkyl_comm_create_comm_from_ranks(comm, branks[0], rb1, 0, &status); - if (rank == rb1[0]) - TEST_CHECK( status ); - if (rank == rb1[1]) - TEST_CHECK( status ); - if (rank == rb1[2]) - TEST_CHECK( status ); - if (rank == rb1[3]) - TEST_CHECK( status ); + if (rank == rb1[0]) { + TEST_CHECK(status); + } + if (rank == rb1[1]) { + TEST_CHECK(status); + } + if (rank == rb1[2]) { + TEST_CHECK(status); + } + if (rank == rb1[3]) { + TEST_CHECK(status); + } if (comm_b1) { int sz_b1; gkyl_comm_get_size(comm_b1, &sz_b1); - TEST_CHECK( branks[0] == sz_b1); + TEST_CHECK(branks[0] == sz_b1); } int rb2[4]; gkyl_rrobin_decomp_getranks(rrd, 1, rb2); - struct gkyl_comm *comm_b2 = - gkyl_comm_create_comm_from_ranks(comm, branks[1], rb2, 0, &status); + struct gkyl_comm *comm_b2 = gkyl_comm_create_comm_from_ranks(comm, branks[1], rb2, 0, &status); - if (rank == rb2[0]) - TEST_CHECK( status ); - if (rank == rb2[1]) - TEST_CHECK( status ); + if (rank == rb2[0]) { + TEST_CHECK(status); + } + if (rank == rb2[1]) { + TEST_CHECK(status); + } if (comm_b2) { int sz_b2; gkyl_comm_get_size(comm_b2, &sz_b2); - TEST_CHECK( branks[1] == sz_b2); + TEST_CHECK(branks[1] == sz_b2); } gkyl_rrobin_decomp_release(rrd); @@ -1289,30 +1263,27 @@ mpi_n4_create_comm_from_ranks_2_ho() gkyl_comm_release(comm_b2); } -static void -mpi_bcast_1d_ho() +static void mpi_bcast_1d_ho() { int bcast_rank = 1; int m_sz, rank; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if (m_sz == 1) + if (m_sz == 1) { bcast_rank = 0; + } struct gkyl_range global; - gkyl_range_init(&global, 1, (int[]) { 1 }, (int[]) { 8*27*125 }); + gkyl_range_init(&global, 1, (int[]){1}, (int[]){8 * 27 * 125}); - int cuts[] = { m_sz }; + int cuts[] = {m_sz}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(global.ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); - int nghost[] = { 1 }; + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -1324,7 +1295,7 @@ mpi_bcast_1d_ho() while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr, linidx); - f[0] = linidx+10.0*rank; + f[0] = linidx + 10.0 * rank; } gkyl_comm_array_bcast(comm, arr, arr, bcast_rank); @@ -1333,40 +1304,37 @@ mpi_bcast_1d_ho() while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr, linidx); - TEST_CHECK( linidx+10.0*bcast_rank == f[0] ); + TEST_CHECK(linidx + 10.0 * bcast_rank == f[0]); } gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_array_release(arr); + gkyl_array_release(arr); } -static void -mpi_bcast_2d_test(int *cuts) +static void mpi_bcast_2d_test(int *cuts) { int bcast_rank = 1; int m_sz, rank; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if (m_sz == 1) + if (m_sz == 1) { bcast_rank = 0; - + } + // create global range - int cells[] = { 4*9*25, 4*9*25 }; - int ndim = sizeof(cells)/sizeof(cells[0]); + int cells[] = {4 * 9 * 25, 4 * 9 * 25}; + int ndim = sizeof(cells) / sizeof(cells[0]); struct gkyl_range global; gkyl_create_global_range(ndim, cells, &global); - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(ndim, cuts, &global); + + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -1378,8 +1346,8 @@ mpi_bcast_2d_test(int *cuts) while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr, linidx); - f[0] = iter.idx[0] + iter.idx[1]*(rank+1.0) + 10.0*rank; - } + f[0] = iter.idx[0] + iter.idx[1] * (rank + 1.0) + 10.0 * rank; + } gkyl_comm_array_bcast(comm, arr, arr, bcast_rank); @@ -1389,9 +1357,12 @@ mpi_bcast_2d_test(int *cuts) while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&bcast_rank_local, iter.idx); double *f = gkyl_array_fetch(arr, linidx); - double val = iter.idx[0] + iter.idx[1]*(bcast_rank+1.0) + 10.0*bcast_rank; - TEST_CHECK( val == f[0] ); - TEST_MSG( "rank:%d | At idx=(%d,%d) | Expected: %.13e | Produced: %.13e", rank, iter.idx[0], iter.idx[1], val, f[0] ); + double val = iter.idx[0] + iter.idx[1] * (bcast_rank + 1.0) + 10.0 * bcast_rank; + TEST_CHECK(val == f[0]); + TEST_MSG( + "rank:%d | At idx=(%d,%d) | Expected: %.13e | Produced: %.13e", rank, iter.idx[0], + iter.idx[1], val, f[0] + ); } gkyl_rect_decomp_release(decomp); @@ -1399,8 +1370,7 @@ mpi_bcast_2d_test(int *cuts) gkyl_array_release(arr); } -static void -mpi_bcast_2d_ho() +static void mpi_bcast_2d_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); @@ -1408,50 +1378,44 @@ mpi_bcast_2d_ho() if (m_sz == 2) { int cuts12[] = {1, 2}; mpi_bcast_2d_test(cuts12); - + int cuts21[] = {2, 1}; mpi_bcast_2d_test(cuts21); - - } - else if (m_sz == 3) { + + } else if (m_sz == 3) { int cuts13[] = {1, 3}; mpi_bcast_2d_test(cuts13); - + int cuts31[] = {3, 1}; mpi_bcast_2d_test(cuts31); - } - else if (m_sz == 4) { + } else if (m_sz == 4) { int cuts22[] = {2, 2}; mpi_bcast_2d_test(cuts22); } } - -void -mpi_bcast_1d_host_ho() +void mpi_bcast_1d_host_ho() { int bcast_rank = 1; int m_sz, rank; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if (m_sz == 1) + if (m_sz == 1) { bcast_rank = 0; + } struct gkyl_range global; - gkyl_range_init(&global, 1, (int[]) { 1 }, (int[]) { 8*27*125 }); + gkyl_range_init(&global, 1, (int[]){1}, (int[]){8 * 27 * 125}); - int cuts[] = { m_sz }; + int cuts[] = {m_sz}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(global.ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); - int nghost[] = { 1 }; + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -1463,7 +1427,7 @@ mpi_bcast_1d_host_ho() while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr, linidx); - f[0] = linidx+10.0*rank; + f[0] = linidx + 10.0 * rank; } gkyl_comm_array_bcast_host(comm, arr, arr, bcast_rank); @@ -1472,40 +1436,37 @@ mpi_bcast_1d_host_ho() while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr, linidx); - TEST_CHECK( linidx+10.0*bcast_rank == f[0] ); + TEST_CHECK(linidx + 10.0 * bcast_rank == f[0]); } gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_array_release(arr); + gkyl_array_release(arr); } -void -mpi_bcast_2d_host_test(int *cuts) +void mpi_bcast_2d_host_test(int *cuts) { int bcast_rank = 1; int m_sz, rank; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if (m_sz == 1) + if (m_sz == 1) { bcast_rank = 0; - + } + // create global range - int cells[] = { 4*9*25, 4*9*25 }; - int ndim = sizeof(cells)/sizeof(cells[0]); + int cells[] = {4 * 9 * 25, 4 * 9 * 25}; + int ndim = sizeof(cells) / sizeof(cells[0]); struct gkyl_range global; gkyl_create_global_range(ndim, cells, &global); - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(ndim, cuts, &global); + + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -1517,8 +1478,8 @@ mpi_bcast_2d_host_test(int *cuts) while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr, linidx); - f[0] = iter.idx[0] + iter.idx[1]*(rank+1.0) + 10.0*rank; - } + f[0] = iter.idx[0] + iter.idx[1] * (rank + 1.0) + 10.0 * rank; + } gkyl_comm_array_bcast_host(comm, arr, arr, bcast_rank); @@ -1528,9 +1489,12 @@ mpi_bcast_2d_host_test(int *cuts) while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&bcast_rank_local, iter.idx); double *f = gkyl_array_fetch(arr, linidx); - double val = iter.idx[0] + iter.idx[1]*(bcast_rank+1.0) + 10.0*bcast_rank; - TEST_CHECK( val == f[0] ); - TEST_MSG( "rank:%d | At idx=(%d,%d) | Expected: %.13e | Produced: %.13e", rank, iter.idx[0], iter.idx[1], val, f[0] ); + double val = iter.idx[0] + iter.idx[1] * (bcast_rank + 1.0) + 10.0 * bcast_rank; + TEST_CHECK(val == f[0]); + TEST_MSG( + "rank:%d | At idx=(%d,%d) | Expected: %.13e | Produced: %.13e", rank, iter.idx[0], + iter.idx[1], val, f[0] + ); } gkyl_rect_decomp_release(decomp); @@ -1538,8 +1502,7 @@ mpi_bcast_2d_host_test(int *cuts) gkyl_array_release(arr); } -void -mpi_bcast_2d_host_ho() +void mpi_bcast_2d_host_ho() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); @@ -1547,76 +1510,71 @@ mpi_bcast_2d_host_ho() if (m_sz == 2) { int cuts12[] = {1, 2}; mpi_bcast_2d_host_test(cuts12); - + int cuts21[] = {2, 1}; mpi_bcast_2d_host_test(cuts21); - - } - else if (m_sz == 3) { + + } else if (m_sz == 3) { int cuts13[] = {1, 3}; mpi_bcast_2d_host_test(cuts13); - + int cuts31[] = {3, 1}; mpi_bcast_2d_host_test(cuts31); - } - else if (m_sz == 4) { + } else if (m_sz == 4) { int cuts22[] = {2, 2}; mpi_bcast_2d_host_test(cuts22); } } - TEST_LIST = { - {"mpi_0_ho", mpi_0_ho}, + {"mpi_0_ho", mpi_0_ho}, {"mpi_1_ho", mpi_1_ho}, {"mpi_n2_allreduce_ho", mpi_n2_allreduce_ho}, - + {"mpi_n2_allgather_1d_ho", mpi_n2_allgather_1d_ho}, {"mpi_n4_allgather_2d_ho", mpi_n4_allgather_2d_ho}, {"mpi_n2_allgather_1d_host_ho", mpi_n2_allgather_1d_host_ho}, {"mpi_n4_allgather_2d_host_ho", mpi_n4_allgather_2d_host_ho}, - + {"mpi_n2_sync_1d_ho", mpi_n2_sync_1d_ho}, - {"mpi_n4_sync_2d_no_corner_ho", mpi_n4_sync_2d_no_corner_ho }, + {"mpi_n4_sync_2d_no_corner_ho", mpi_n4_sync_2d_no_corner_ho}, {"mpi_n4_sync_2d_use_corner_ho", mpi_n4_sync_2d_use_corner_ho}, - {"mpi_n4_sync_1x1v_ho", mpi_n4_sync_1x1v_ho }, - - {"mpi_n1_per_sync_2d_ho", mpi_n1_per_sync_2d_ho }, - {"mpi_n2_per_sync_2d_ho", mpi_n2_per_sync_2d_ho }, - - {"mpi_n1_per_sync_corner_2d_ho", mpi_n1_per_sync_corner_2d_ho }, - {"mpi_n2_per_sync_corner_2d_ho", mpi_n2_per_sync_corner_2d_ho }, - {"mpi_n4_per_sync_corner_2d_ho", mpi_n4_per_sync_corner_2d_ho }, - - {"mpi_n1_per_sync_corner_3d_ho", mpi_n1_per_sync_corner_3d_ho }, - {"mpi_n2_per_sync_corner_3d_ho", mpi_n2_per_sync_corner_3d_ho }, - {"mpi_n4_per_sync_corner_3d_ho", mpi_n4_per_sync_corner_3d_ho }, - {"mpi_n8_per_sync_corner_3d_ho", mpi_n8_per_sync_corner_3d_ho }, - {"mpi_n27_per_sync_corner_3d_ho", mpi_n27_per_sync_corner_3d_ho }, - + {"mpi_n4_sync_1x1v_ho", mpi_n4_sync_1x1v_ho}, + + {"mpi_n1_per_sync_2d_ho", mpi_n1_per_sync_2d_ho}, + {"mpi_n2_per_sync_2d_ho", mpi_n2_per_sync_2d_ho}, + + {"mpi_n1_per_sync_corner_2d_ho", mpi_n1_per_sync_corner_2d_ho}, + {"mpi_n2_per_sync_corner_2d_ho", mpi_n2_per_sync_corner_2d_ho}, + {"mpi_n4_per_sync_corner_2d_ho", mpi_n4_per_sync_corner_2d_ho}, + + {"mpi_n1_per_sync_corner_3d_ho", mpi_n1_per_sync_corner_3d_ho}, + {"mpi_n2_per_sync_corner_3d_ho", mpi_n2_per_sync_corner_3d_ho}, + {"mpi_n4_per_sync_corner_3d_ho", mpi_n4_per_sync_corner_3d_ho}, + {"mpi_n8_per_sync_corner_3d_ho", mpi_n8_per_sync_corner_3d_ho}, + {"mpi_n27_per_sync_corner_3d_ho", mpi_n27_per_sync_corner_3d_ho}, + /* {"mpi_n2_array_send_irecv_1d_ho", mpi_n2_array_send_irecv_1d_ho }, */ /* {"mpi_n2_array_isend_irecv_2d_ho", mpi_n2_array_isend_irecv_2d_ho }, */ - + /* {"mpi_n4_split_comm_2d_ho", mpi_n4_split_comm_2d_ho }, */ - {"mpi_n4_create_comm_from_ranks_1_ho", mpi_n4_create_comm_from_ranks_1_ho }, - {"mpi_n4_create_comm_from_ranks_2_ho", mpi_n4_create_comm_from_ranks_2_ho }, - + {"mpi_n4_create_comm_from_ranks_1_ho", mpi_n4_create_comm_from_ranks_1_ho}, + {"mpi_n4_create_comm_from_ranks_2_ho", mpi_n4_create_comm_from_ranks_2_ho}, + {"mpi_bcast_1d_ho", mpi_bcast_1d_ho}, {"mpi_bcast_2d_ho", mpi_bcast_2d_ho}, - {"mpi_bcast_1d_host_ho", mpi_bcast_1d_host_ho }, - {"mpi_bcast_2d_host_ho", mpi_bcast_2d_host_ho }, + {"mpi_bcast_1d_host_ho", mpi_bcast_1d_host_ho}, + {"mpi_bcast_2d_host_ho", mpi_bcast_2d_host_ho}, - {NULL, NULL}, + {NULL, NULL} }; #else // nothing to test if not building with MPI -TEST_LIST = { - {NULL, NULL}, -}; +TEST_LIST = {{NULL, NULL}}; #endif diff --git a/core/unit/mctest_mpi_comm_read.c b/core/unit/mctest_mpi_comm_read.c index 6bda0729f9..f894bd1596 100644 --- a/core/unit/mctest_mpi_comm_read.c +++ b/core/unit/mctest_mpi_comm_read.c @@ -15,12 +15,13 @@ #include #include -void -mpi_read(int nrank, int cuts[2]) +void mpi_read(int nrank, int cuts[2]) { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != nrank) return; + if (m_sz != nrank) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -30,35 +31,34 @@ mpi_read(int nrank, int cuts[2]) struct gkyl_rect_grid grid; struct gkyl_array_header_info hdr; - status = gkyl_grid_sub_array_header_read(&grid, &hdr, - "core/data/unit/ser-euler_riem_2d_hllc-euler_1.gkyl"); + status = gkyl_grid_sub_array_header_read( + &grid, &hdr, "core/data/unit/ser-euler_riem_2d_hllc-euler_1.gkyl" + ); - TEST_CHECK( GKYL_ARRAY_RIO_SUCCESS == status ); + TEST_CHECK(GKYL_ARRAY_RIO_SUCCESS == status); - if (hdr.meta_size > 0) + if (hdr.meta_size > 0) { free(hdr.meta); + } - int nghost[] = { 2, 2 }; + int nghost[] = {2, 2}; struct gkyl_range global, ext_global; gkyl_create_grid_ranges(&grid, nghost, &ext_global, &global); - size_t nc = hdr.esznc/gkyl_elem_type_size[hdr.etype]; + size_t nc = hdr.esznc / gkyl_elem_type_size[hdr.etype]; struct gkyl_array *s_arr = gkyl_array_new(hdr.etype, nc, ext_global.volume); gkyl_array_clear(s_arr, 0.0); - status = gkyl_grid_sub_array_read(&grid, &global, s_arr, - "core/data/unit/ser-euler_riem_2d_hllc-euler_1.gkyl"); + status = gkyl_grid_sub_array_read( + &grid, &global, s_arr, "core/data/unit/ser-euler_riem_2d_hllc-euler_1.gkyl" + ); - TEST_CHECK( GKYL_ARRAY_RIO_SUCCESS == status ); + TEST_CHECK(GKYL_ARRAY_RIO_SUCCESS == status); - struct gkyl_rect_decomp *decomp = - gkyl_rect_decomp_new_from_cuts(global.ndim, cuts, &global); + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(global.ndim, cuts, &global); - struct gkyl_comm *comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp - } - ); + struct gkyl_comm *comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); struct gkyl_range local, ext_local; gkyl_create_ranges(&decomp->ranges[rank], nghost, &ext_local, &local); @@ -66,10 +66,11 @@ mpi_read(int nrank, int cuts[2]) struct gkyl_array *p_arr = gkyl_array_new(hdr.etype, nc, ext_local.volume); gkyl_array_clear(p_arr, 0.0); - status = gkyl_comm_array_read(comm, &grid, &local, p_arr, - "core/data/unit/euler_riem_2d_hllc-euler_1.gkyl"); + status = gkyl_comm_array_read( + comm, &grid, &local, p_arr, "core/data/unit/euler_riem_2d_hllc-euler_1.gkyl" + ); - TEST_CHECK( GKYL_ARRAY_RIO_SUCCESS == status ); + TEST_CHECK(GKYL_ARRAY_RIO_SUCCESS == status); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local); @@ -77,8 +78,9 @@ mpi_read(int nrank, int cuts[2]) const double *s_dat = gkyl_array_cfetch(s_arr, gkyl_range_idx(&global, iter.idx)); const double *p_dat = gkyl_array_cfetch(p_arr, gkyl_range_idx(&local, iter.idx)); - for (int c=0; c #include -void -nccl_allreduce_dev() +void nccl_allreduce_dev() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 2) return; - + if (m_sz != 2) { + return; + } + struct gkyl_range range; - gkyl_range_init(&range, 2, (int[]) { 1, 1 }, (int[]) { 100, 100 }); - - int cuts[] = { 1, 1 }; - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); - - struct gkyl_comm *comm_ho = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + gkyl_range_init(&range, 2, (int[]){1, 1}, (int[]){100, 100}); + + int cuts[] = {1, 1}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); + + struct gkyl_comm *comm_ho = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); int m_rank; MPI_Comm_rank(MPI_COMM_WORLD, &m_rank); - struct gkyl_comm *comm_dev = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + struct gkyl_comm *comm_dev = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); int n_rank, n_sz; gkyl_comm_get_rank(comm_dev, &n_rank); gkyl_comm_get_size(comm_dev, &n_sz); - TEST_CHECK( n_rank == m_rank ); - TEST_CHECK( n_sz == m_sz ); + TEST_CHECK(n_rank == m_rank); + TEST_CHECK(n_sz == m_sz); double vals_ho[2]; if (m_rank == 0) { @@ -54,28 +49,28 @@ nccl_allreduce_dev() vals_ho[0] = 3.0; vals_ho[1] = -1.0; } - double *vals = gkyl_cu_malloc(2*sizeof(double)); - gkyl_cu_memcpy(vals, vals_ho, 2*sizeof(double), GKYL_CU_MEMCPY_H2D); + double *vals = gkyl_cu_malloc(2 * sizeof(double)); + gkyl_cu_memcpy(vals, vals_ho, 2 * sizeof(double), GKYL_CU_MEMCPY_H2D); double v_max_ho[2], v_min_ho[2], v_sum_ho[2]; - double *v_max = gkyl_cu_malloc(2*sizeof(double)); - double *v_min = gkyl_cu_malloc(2*sizeof(double)); - double *v_sum = gkyl_cu_malloc(2*sizeof(double)); + double *v_max = gkyl_cu_malloc(2 * sizeof(double)); + double *v_min = gkyl_cu_malloc(2 * sizeof(double)); + double *v_sum = gkyl_cu_malloc(2 * sizeof(double)); gkyl_comm_allreduce(comm_dev, GKYL_DOUBLE, GKYL_MAX, 2, vals, v_max); - gkyl_cu_memcpy(v_max_ho, v_max, 2*sizeof(double), GKYL_CU_MEMCPY_D2H); - TEST_CHECK( v_max_ho[0] == 3.0 ); - TEST_CHECK( v_max_ho[1] == 2.0 ); + gkyl_cu_memcpy(v_max_ho, v_max, 2 * sizeof(double), GKYL_CU_MEMCPY_D2H); + TEST_CHECK(v_max_ho[0] == 3.0); + TEST_CHECK(v_max_ho[1] == 2.0); gkyl_comm_allreduce(comm_dev, GKYL_DOUBLE, GKYL_MIN, 2, vals, v_min); - gkyl_cu_memcpy(v_min_ho, v_min, 2*sizeof(double), GKYL_CU_MEMCPY_D2H); - TEST_CHECK( v_min_ho[0] == 1.0 ); - TEST_CHECK( v_min_ho[1] == -1.0 ); + gkyl_cu_memcpy(v_min_ho, v_min, 2 * sizeof(double), GKYL_CU_MEMCPY_D2H); + TEST_CHECK(v_min_ho[0] == 1.0); + TEST_CHECK(v_min_ho[1] == -1.0); gkyl_comm_allreduce(comm_dev, GKYL_DOUBLE, GKYL_SUM, 2, vals, v_sum); - gkyl_cu_memcpy(v_sum_ho, v_sum, 2*sizeof(double), GKYL_CU_MEMCPY_D2H); - TEST_CHECK( v_sum_ho[0] == 4.0 ); - TEST_CHECK( v_sum_ho[1] == 1.0 ); + gkyl_cu_memcpy(v_sum_ho, v_sum, 2 * sizeof(double), GKYL_CU_MEMCPY_D2H); + TEST_CHECK(v_sum_ho[0] == 4.0); + TEST_CHECK(v_sum_ho[1] == 1.0); gkyl_cu_free(vals); gkyl_cu_free(v_max); @@ -87,29 +82,27 @@ nccl_allreduce_dev() gkyl_comm_release(comm_dev); } -void -nccl_n2_allgather_1d_dev() +void nccl_n2_allgather_1d_dev() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 2) return; + if (m_sz != 2) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); struct gkyl_range global; - gkyl_range_init(&global, 1, (int[]) { 1 }, (int[]) { 10 }); + gkyl_range_init(&global, 1, (int[]){1}, (int[]){10}); - int cuts[] = { 2 }; + int cuts[] = {2}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(global.ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); - int nghost[] = { 1 }; + struct gkyl_comm *comm = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -124,8 +117,8 @@ nccl_n2_allgather_1d_dev() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr_local_ho, idx); - f[0] = idx+10.0*rank; + double *f = gkyl_array_fetch(arr_local_ho, idx); + f[0] = idx + 10.0 * rank; } gkyl_array_copy(arr_local, arr_local_ho); @@ -138,45 +131,44 @@ nccl_n2_allgather_1d_dev() long idx = gkyl_range_idx(&global, iter_global.idx); double *f = gkyl_array_fetch(arr_global_ho, idx); // first 5 entries are 1-5, second 5 entries are 11-15 - if (idx < local.volume) - TEST_CHECK( idx+1.0 == f[0] ); - else - TEST_CHECK( idx+6.0 == f[0] ); + if (idx < local.volume) { + TEST_CHECK(idx + 1.0 == f[0]); + } else { + TEST_CHECK(idx + 6.0 == f[0]); + } } gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_array_release(arr_local); - gkyl_array_release(arr_global); - gkyl_array_release(arr_local_ho); - gkyl_array_release(arr_global_ho); + gkyl_array_release(arr_local); + gkyl_array_release(arr_global); + gkyl_array_release(arr_local_ho); + gkyl_array_release(arr_global_ho); } -void -nccl_n4_allgather_2d_dev() +void nccl_n4_allgather_2d_dev() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); // create global range - int cells[] = { 10, 10 }; + int cells[] = {10, 10}; struct gkyl_range global; gkyl_create_global_range(2, cells, &global); - int cuts[] = { 2, 2 }; - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &global); - - struct gkyl_comm *comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + int cuts[] = {2, 2}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &global); + + struct gkyl_comm *comm = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -191,9 +183,9 @@ nccl_n4_allgather_2d_dev() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr_local_ho, idx); - f[0] = iter.idx[0] + iter.idx[1]*(rank+1.0) + 10.0*rank; - } + double *f = gkyl_array_fetch(arr_local_ho, idx); + f[0] = iter.idx[0] + iter.idx[1] * (rank + 1.0) + 10.0 * rank; + } gkyl_array_copy(arr_local, arr_local_ho); gkyl_comm_array_allgather(comm, &local, &global, arr_local, arr_global); @@ -204,21 +196,24 @@ nccl_n4_allgather_2d_dev() while (gkyl_range_iter_next(&iter_global)) { long idx = gkyl_range_idx(&global, iter_global.idx); double *f = gkyl_array_fetch(arr_global_ho, idx); - // check value of {2, 2} decomp organized as + // check value of {2, 2} decomp organized as // rank 0 owns {1, 1} to {5, 5} - // rank 1 owns {1, 6} to {5, 10} - // rank 2 owns {6, 1} to {10, 5} + // rank 1 owns {1, 6} to {5, 10} + // rank 2 owns {6, 1} to {10, 5} // rank 3 owns {6, 6} to {10, 10} double val; - if (iter_global.idx[0] <= cells[0]/cuts[0] && iter_global.idx[1] <= cells[1]/cuts[1]) + if (iter_global.idx[0] <= cells[0] / cuts[0] && iter_global.idx[1] <= cells[1] / cuts[1]) { val = iter_global.idx[0] + iter_global.idx[1]; - else if (iter_global.idx[0] <= cells[0]/cuts[0] && iter_global.idx[1] > cells[1]/cuts[1]) - val = iter_global.idx[0] + iter_global.idx[1]*2.0 + 10.0; - else if (iter_global.idx[0] > cells[0]/cuts[0] && iter_global.idx[1] <= cells[1]/cuts[1]) - val = iter_global.idx[0] + iter_global.idx[1]*3.0 + 20.0; - else - val = iter_global.idx[0] + iter_global.idx[1]*4.0 + 30.0; - TEST_CHECK( val == f[0] ); + } else if (iter_global.idx[0] <= cells[0] / cuts[0] && + iter_global.idx[1] > cells[1] / cuts[1]) { + val = iter_global.idx[0] + iter_global.idx[1] * 2.0 + 10.0; + } else if (iter_global.idx[0] > cells[0] / cuts[0] && + iter_global.idx[1] <= cells[1] / cuts[1]) { + val = iter_global.idx[0] + iter_global.idx[1] * 3.0 + 20.0; + } else { + val = iter_global.idx[0] + iter_global.idx[1] * 4.0 + 30.0; + } + TEST_CHECK(val == f[0]); } gkyl_rect_decomp_release(decomp); @@ -229,30 +224,27 @@ nccl_n4_allgather_2d_dev() gkyl_array_release(arr_global_ho); } - -void -nccl_n2_allgather_1d_host_dev() +void nccl_n2_allgather_1d_host_dev() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 2) return; + if (m_sz != 2) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); struct gkyl_range global; - gkyl_range_init(&global, 1, (int[]) { 1 }, (int[]) { 10 }); + gkyl_range_init(&global, 1, (int[]){1}, (int[]){10}); - int cuts[] = { 2 }; + int cuts[] = {2}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(global.ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); - int nghost[] = { 1 }; + struct gkyl_comm *comm = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -264,8 +256,8 @@ nccl_n2_allgather_1d_host_dev() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr_local_ho, idx); - f[0] = idx+10.0*rank; + double *f = gkyl_array_fetch(arr_local_ho, idx); + f[0] = idx + 10.0 * rank; } gkyl_comm_array_allgather_host(comm, &local, &global, arr_local_ho, arr_global_ho); @@ -276,43 +268,42 @@ nccl_n2_allgather_1d_host_dev() long idx = gkyl_range_idx(&global, iter_global.idx); double *f = gkyl_array_fetch(arr_global_ho, idx); // first 5 entries are 1-5, second 5 entries are 11-15 - if (idx < local.volume) - TEST_CHECK( idx+1.0 == f[0] ); - else - TEST_CHECK( idx+6.0 == f[0] ); + if (idx < local.volume) { + TEST_CHECK(idx + 1.0 == f[0]); + } else { + TEST_CHECK(idx + 6.0 == f[0]); + } } gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_array_release(arr_local_ho); - gkyl_array_release(arr_global_ho); + gkyl_array_release(arr_local_ho); + gkyl_array_release(arr_global_ho); } -void -nccl_n4_allgather_2d_host_dev() +void nccl_n4_allgather_2d_host_dev() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); // create global range - int cells[] = { 10, 10 }; + int cells[] = {10, 10}; struct gkyl_range global; gkyl_create_global_range(2, cells, &global); - int cuts[] = { 2, 2 }; - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &global); - - struct gkyl_comm *comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + int cuts[] = {2, 2}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &global); + + struct gkyl_comm *comm = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -324,9 +315,9 @@ nccl_n4_allgather_2d_host_dev() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr_local_ho, idx); - f[0] = iter.idx[0] + iter.idx[1]*(rank+1.0) + 10.0*rank; - } + double *f = gkyl_array_fetch(arr_local_ho, idx); + f[0] = iter.idx[0] + iter.idx[1] * (rank + 1.0) + 10.0 * rank; + } gkyl_comm_array_allgather_host(comm, &local, &global, arr_local_ho, arr_global_ho); @@ -335,21 +326,24 @@ nccl_n4_allgather_2d_host_dev() while (gkyl_range_iter_next(&iter_global)) { long idx = gkyl_range_idx(&global, iter_global.idx); double *f = gkyl_array_fetch(arr_global_ho, idx); - // check value of {2, 2} decomp organized as + // check value of {2, 2} decomp organized as // rank 0 owns {1, 1} to {5, 5} - // rank 1 owns {1, 6} to {5, 10} - // rank 2 owns {6, 1} to {10, 5} + // rank 1 owns {1, 6} to {5, 10} + // rank 2 owns {6, 1} to {10, 5} // rank 3 owns {6, 6} to {10, 10} double val; - if (iter_global.idx[0] <= cells[0]/cuts[0] && iter_global.idx[1] <= cells[1]/cuts[1]) + if (iter_global.idx[0] <= cells[0] / cuts[0] && iter_global.idx[1] <= cells[1] / cuts[1]) { val = iter_global.idx[0] + iter_global.idx[1]; - else if (iter_global.idx[0] <= cells[0]/cuts[0] && iter_global.idx[1] > cells[1]/cuts[1]) - val = iter_global.idx[0] + iter_global.idx[1]*2.0 + 10.0; - else if (iter_global.idx[0] > cells[0]/cuts[0] && iter_global.idx[1] <= cells[1]/cuts[1]) - val = iter_global.idx[0] + iter_global.idx[1]*3.0 + 20.0; - else - val = iter_global.idx[0] + iter_global.idx[1]*4.0 + 30.0; - TEST_CHECK( val == f[0] ); + } else if (iter_global.idx[0] <= cells[0] / cuts[0] && + iter_global.idx[1] > cells[1] / cuts[1]) { + val = iter_global.idx[0] + iter_global.idx[1] * 2.0 + 10.0; + } else if (iter_global.idx[0] > cells[0] / cuts[0] && + iter_global.idx[1] <= cells[1] / cuts[1]) { + val = iter_global.idx[0] + iter_global.idx[1] * 3.0 + 20.0; + } else { + val = iter_global.idx[0] + iter_global.idx[1] * 4.0 + 30.0; + } + TEST_CHECK(val == f[0]); } gkyl_rect_decomp_release(decomp); @@ -365,44 +359,44 @@ nccl_n4_allgather_2d_host_dev() // // Test array_send and array_recv with a nonblocking comm. // struct gkyl_range range; // gkyl_range_init(&range, 2, (int[]) { 1, 1 }, (int[]) { 100, 100 }); -// +// // int comm_size; // MPI_Comm_size(MPI_COMM_WORLD, &comm_size); // if (comm_size != 2) return; -// +// // int cuts[] = { comm_size, 1 }; -// struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); -// +// struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); +// // struct gkyl_comm *comm_ho = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { // .mpi_comm = MPI_COMM_WORLD, // .decomp = decomp // } // ); -// +// // int rank, sz; // gkyl_comm_get_rank(comm_ho, &rank); // gkyl_comm_get_size(comm_ho, &sz); -// +// // struct gkyl_comm *comm_dev = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { // .mpi_comm = MPI_COMM_WORLD, // .decomp = decomp, // } // ); -// +// // // Allocate send/recv buffers. // double sendval = rank==0? 20005. : 30005.; // double recvval = rank==0? 30005. : 20005.; -// +// // // Assume the range is not decomposed. // struct gkyl_array *arrA = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, range.volume); // struct gkyl_array *arrB = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, range.volume); // struct gkyl_array *recvbuff_ho = gkyl_array_new(GKYL_DOUBLE, 1, range.volume); // gkyl_array_clear(arrA, sendval*(1-rank)); // gkyl_array_clear(arrB, sendval*rank); -// +// // struct gkyl_array *recvbuff = rank==0? arrB : arrA; // struct gkyl_array *sendbuff = rank==0? arrA : arrB; -// +// // struct gkyl_comm_state *cstate = gkyl_comm_state_new(comm_dev); // int tag = 13; // // Communicate data from rank 0 to rank 1. @@ -410,10 +404,10 @@ nccl_n4_allgather_2d_host_dev() // gkyl_comm_array_irecv(comm_dev, recvbuff, (rank+1) % 2, tag, cstate); // if (rank == 0) // gkyl_comm_array_send(comm_dev, sendbuff, (rank+1) % 2, tag); -// +// // if (rank == 1) { // gkyl_comm_state_wait(comm_dev, cstate); -// +// // gkyl_array_copy(recvbuff_ho, recvbuff); // struct gkyl_range_iter iter; // gkyl_range_iter_init(&iter, &range); @@ -423,16 +417,16 @@ nccl_n4_allgather_2d_host_dev() // TEST_CHECK( f[0] == recvval ); // } // } -// +// // // Communicate data from rank 1 to rank 0. // if (rank == 0) // gkyl_comm_array_irecv(comm_dev, recvbuff, (rank+1) % 2, tag, cstate); // if (rank == 1) // gkyl_comm_array_send(comm_dev, sendbuff, (rank+1) % 2, tag); -// +// // if (rank == 0) { // gkyl_comm_state_wait(comm_dev, cstate); -// +// // gkyl_array_copy(recvbuff_ho, recvbuff); // struct gkyl_range_iter iter; // gkyl_range_iter_init(&iter, &range); @@ -442,7 +436,7 @@ nccl_n4_allgather_2d_host_dev() // TEST_CHECK( f[0] == recvval ); // } // } -// +// // // Communicate data between rank 0 and 1 at the same time. // gkyl_array_clear(recvbuff, 0.); // gkyl_comm_group_call_start(comm_dev); @@ -450,7 +444,7 @@ nccl_n4_allgather_2d_host_dev() // gkyl_comm_array_send(comm_dev, sendbuff, (rank+1) % 2, tag); // gkyl_comm_group_call_end(comm_dev); // gkyl_comm_state_wait(comm_dev, cstate); -// +// // gkyl_array_copy(recvbuff_ho, recvbuff); // struct gkyl_range_iter iter; // gkyl_range_iter_init(&iter, &range); @@ -459,63 +453,63 @@ nccl_n4_allgather_2d_host_dev() // const double *f = gkyl_array_cfetch(recvbuff_ho, idx); // TEST_CHECK( f[0] == recvval ); // } -// +// // gkyl_comm_barrier(comm_dev); -// +// // gkyl_comm_state_release(comm_dev, cstate); // gkyl_array_release(recvbuff_ho); // gkyl_array_release(arrA); // gkyl_array_release(arrB); -// +// // gkyl_rect_decomp_release(decomp); // gkyl_comm_release(comm_dev); // gkyl_comm_release(comm_ho); // } -// +// // void // nccl_n2_array_isend_irecv_2d_dev() // { // // Test array_send and array_recv with a nonblocking comm. // struct gkyl_range range; // gkyl_range_init(&range, 2, (int[]) { 1, 1 }, (int[]) { 100, 100 }); -// +// // int comm_size; // MPI_Comm_size(MPI_COMM_WORLD, &comm_size); // if (comm_size != 2) return; -// +// // int cuts[] = { comm_size, 1 }; -// struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); -// +// struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); +// // struct gkyl_comm *comm_ho = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { // .mpi_comm = MPI_COMM_WORLD, // .decomp = decomp, // } // ); -// +// // int rank, sz; // gkyl_comm_get_rank(comm_ho, &rank); // gkyl_comm_get_size(comm_ho, &sz); -// +// // struct gkyl_comm *comm_dev = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { // .mpi_comm = MPI_COMM_WORLD, // .decomp = decomp, // } // ); -// +// // // Allocate send/recv buffers. // double sendval = rank==0? 20005. : 30005.; // double recvval = rank==0? 30005. : 20005.; -// +// // // Assume the range is not decomposed. // struct gkyl_array *arrA = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, range.volume); // struct gkyl_array *arrB = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, range.volume); // struct gkyl_array *recvbuff_ho = gkyl_array_new(GKYL_DOUBLE, 1, range.volume); // gkyl_array_clear(arrA, sendval*(1-rank)); // gkyl_array_clear(arrB, sendval*rank); -// +// // struct gkyl_array *recvbuff = rank==0? arrB : arrA; // struct gkyl_array *sendbuff = rank==0? arrA : arrB; -// +// // struct gkyl_comm_state *cstate_r = gkyl_comm_state_new(comm_dev); // struct gkyl_comm_state *cstate_s = gkyl_comm_state_new(comm_dev); // int tag = 13; @@ -524,10 +518,10 @@ nccl_n4_allgather_2d_host_dev() // gkyl_comm_array_irecv(comm_dev, recvbuff, (rank+1) % 2, tag, cstate_r); // if (rank == 0) // gkyl_comm_array_isend(comm_dev, sendbuff, (rank+1) % 2, tag, cstate_s); -// +// // gkyl_comm_state_wait(comm_dev, cstate_r); // gkyl_comm_state_wait(comm_dev, cstate_s); -// +// // if (rank == 1) { // gkyl_array_copy(recvbuff_ho, recvbuff); // struct gkyl_range_iter iter; @@ -538,16 +532,16 @@ nccl_n4_allgather_2d_host_dev() // TEST_CHECK( f[0] == recvval ); // } // } -// +// // // Communicate data from rank 1 to rank 0. // if (rank == 0) // gkyl_comm_array_irecv(comm_dev, recvbuff, (rank+1) % 2, tag, cstate_r); // if (rank == 1) // gkyl_comm_array_isend(comm_dev, sendbuff, (rank+1) % 2, tag, cstate_s); -// +// // gkyl_comm_state_wait(comm_dev, cstate_r); // gkyl_comm_state_wait(comm_dev, cstate_s); -// +// // if (rank == 0) { // gkyl_array_copy(recvbuff_ho, recvbuff); // struct gkyl_range_iter iter; @@ -558,7 +552,7 @@ nccl_n4_allgather_2d_host_dev() // TEST_CHECK( f[0] == recvval ); // } // } -// +// // // Communicate data between rank 0 and 1 at the same time. // gkyl_array_clear(recvbuff, 0.); // gkyl_comm_group_call_start(comm_dev); @@ -567,7 +561,7 @@ nccl_n4_allgather_2d_host_dev() // gkyl_comm_group_call_end(comm_dev); // gkyl_comm_state_wait(comm_dev, cstate_r); // gkyl_comm_state_wait(comm_dev, cstate_s); -// +// // gkyl_array_copy(recvbuff_ho, recvbuff); // struct gkyl_range_iter iter; // gkyl_range_iter_init(&iter, &range); @@ -576,51 +570,44 @@ nccl_n4_allgather_2d_host_dev() // const double *f = gkyl_array_cfetch(recvbuff_ho, idx); // TEST_CHECK( f[0] == recvval ); // } -// +// // gkyl_comm_barrier(comm_dev); -// +// // gkyl_comm_state_release(comm_dev, cstate_r); // gkyl_comm_state_release(comm_dev, cstate_s); // gkyl_array_release(recvbuff_ho); // gkyl_array_release(arrA); // gkyl_array_release(arrB); -// +// // gkyl_rect_decomp_release(decomp); // gkyl_comm_release(comm_dev); // gkyl_comm_release(comm_ho); // } -void -nccl_n2_sync_1d_dev() +void nccl_n2_sync_1d_dev() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 2) return; + if (m_sz != 2) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); struct gkyl_range range; - gkyl_range_init(&range, 1, (int[]) { 1 }, (int[]) { 10 }); + gkyl_range_init(&range, 1, (int[]){1}, (int[]){10}); - int cuts[] = { 2 }; + int cuts[] = {2}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); - - struct gkyl_comm *comm_ho = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - .sync_corners = false, - } - ); - struct gkyl_comm *comm_dev = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - .sync_corners = false, - } - ); + struct gkyl_comm *comm_ho = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp, .sync_corners = false}); + + struct gkyl_comm *comm_dev = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp, .sync_corners = false}); - int nghost[] = { 1 }; + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -632,7 +619,7 @@ nccl_n2_sync_1d_dev() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr_ho, idx); + double *f = gkyl_array_fetch(arr_ho, idx); f[0] = iter.idx[0]; } gkyl_array_copy(arr, arr_ho); @@ -646,9 +633,9 @@ nccl_n2_sync_1d_dev() gkyl_range_iter_init(&iter, &in_range); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&in_range, iter.idx); - const double *f = gkyl_array_cfetch(arr_ho, idx); - - TEST_CHECK( iter.idx[0] == f[0] ); + const double *f = gkyl_array_cfetch(arr_ho, idx); + + TEST_CHECK(iter.idx[0] == f[0]); } gkyl_rect_decomp_release(decomp); @@ -658,59 +645,51 @@ nccl_n2_sync_1d_dev() gkyl_comm_release(comm_ho); } -void -nccl_n4_sync_2d(bool use_corners) +void nccl_n4_sync_2d(bool use_corners) { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); struct gkyl_range range; - gkyl_range_init(&range, 2, (int[]) { 1, 1 }, (int[]) { 10, 10 }); - - int cuts[] = { 2, 2 }; - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); - - struct gkyl_comm *comm_ho = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - .sync_corners = use_corners, - } - ); + gkyl_range_init(&range, 2, (int[]){1, 1}, (int[]){10, 10}); - struct gkyl_comm *comm_dev = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - .sync_corners = use_corners, - } - ); + int cuts[] = {2, 2}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(2, cuts, &range); + + struct gkyl_comm *comm_ho = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp, .sync_corners = use_corners}); + + struct gkyl_comm *comm_dev = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp, .sync_corners = use_corners}); - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); struct gkyl_range local_x, local_ext_x, local_y, local_ext_y; - gkyl_create_ranges(&decomp->ranges[rank], (int[]) {1, 0}, - &local_ext_x, &local_x); - - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { 0, 1 }, - &local_ext_y, &local_y); + gkyl_create_ranges(&decomp->ranges[rank], (int[]){1, 0}, &local_ext_x, &local_x); + + gkyl_create_ranges(&decomp->ranges[rank], (int[]){0, 1}, &local_ext_y, &local_y); struct gkyl_array *arr_ho = gkyl_array_new(GKYL_DOUBLE, 2, local_ext.volume); struct gkyl_array *arr = gkyl_array_cu_dev_new(GKYL_DOUBLE, 2, local_ext.volume); gkyl_array_clear(arr_ho, 200005); gkyl_comm_barrier(comm_dev); - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr_ho, idx); - f[0] = iter.idx[0]; f[1] = iter.idx[1]; + double *f = gkyl_array_fetch(arr_ho, idx); + f[0] = iter.idx[0]; + f[1] = iter.idx[1]; } gkyl_array_copy(arr, arr_ho); @@ -724,17 +703,17 @@ nccl_n4_sync_2d(bool use_corners) gkyl_range_iter_init(&iter, &in_range); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&in_range, iter.idx); - const double *f = gkyl_array_cfetch(arr_ho, idx); + const double *f = gkyl_array_cfetch(arr_ho, idx); if (use_corners) { - TEST_CHECK( iter.idx[0] == f[0] ); - TEST_CHECK( iter.idx[1] == f[1] ); - } - else { + TEST_CHECK(iter.idx[0] == f[0]); + TEST_CHECK(iter.idx[1] == f[1]); + } else { // excludes corners - if (gkyl_range_contains_idx(&local_ext_x, iter.idx) || gkyl_range_contains_idx(&local_ext_y, iter.idx)) { - TEST_CHECK( iter.idx[0] == f[0] ); - TEST_CHECK( iter.idx[1] == f[1] ); + if (gkyl_range_contains_idx(&local_ext_x, iter.idx) || + gkyl_range_contains_idx(&local_ext_y, iter.idx)) { + TEST_CHECK(iter.idx[0] == f[0]); + TEST_CHECK(iter.idx[1] == f[1]); } } } @@ -746,38 +725,41 @@ nccl_n4_sync_2d(bool use_corners) gkyl_comm_release(comm_ho); } -void nccl_n4_sync_2d_no_corner_dev() { nccl_n4_sync_2d(false); } -void nccl_n4_sync_2d_use_corner_dev() { nccl_n4_sync_2d(true); } +void nccl_n4_sync_2d_no_corner_dev() +{ + nccl_n4_sync_2d(false); +} +void nccl_n4_sync_2d_use_corner_dev() +{ + nccl_n4_sync_2d(true); +} -void -nccl_n4_sync_1x1v_dev() +void nccl_n4_sync_1x1v_dev() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); struct gkyl_range range; - gkyl_range_init(&range, 1, (int[]) { 1 }, (int[]) { 512 }); + gkyl_range_init(&range, 1, (int[]){1}, (int[]){512}); - int cuts[] = { m_sz }; + int cuts[] = {m_sz}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(1, cuts, &range); - struct gkyl_comm *comm_dev = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + struct gkyl_comm *comm_dev = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); struct gkyl_range vrange; - gkyl_range_init(&vrange, 1, (int[]) { 1 }, (int[]) { 64 } ); + gkyl_range_init(&vrange, 1, (int[]){1}, (int[]){64}); - struct gkyl_rect_decomp *ext_decomp = - gkyl_rect_decomp_extended_new(&vrange, decomp); + struct gkyl_rect_decomp *ext_decomp = gkyl_rect_decomp_extended_new(&vrange, decomp); - int nghost[] = { 1, 0 }; + int nghost[] = {1, 0}; struct gkyl_range local, local_ext; gkyl_create_ranges(&ext_decomp->ranges[rank], nghost, &local_ext, &local); @@ -792,8 +774,9 @@ nccl_n4_sync_1x1v_dev() gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); - double *f = gkyl_array_fetch(arr_ho, idx); - f[0] = iter.idx[0]; f[1] = iter.idx[1]; + double *f = gkyl_array_fetch(arr_ho, idx); + f[0] = iter.idx[0]; + f[1] = iter.idx[1]; } gkyl_array_copy(arr, arr_ho); @@ -806,10 +789,10 @@ nccl_n4_sync_1x1v_dev() gkyl_range_iter_init(&iter, &in_range); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&in_range, iter.idx); - const double *f = gkyl_array_cfetch(arr_ho, idx); + const double *f = gkyl_array_cfetch(arr_ho, idx); - TEST_CHECK( iter.idx[0] == f[0] ); - TEST_CHECK( iter.idx[1] == f[1] ); + TEST_CHECK(iter.idx[0] == f[0]); + TEST_CHECK(iter.idx[1] == f[1]); } gkyl_rect_decomp_release(decomp); @@ -820,39 +803,34 @@ nccl_n4_sync_1x1v_dev() gkyl_array_release(arr_ho); } -void -nccl_n1_per_sync_2d_tests(int num_per_dirs, int *per_dirs) +void nccl_n1_per_sync_2d_tests(int num_per_dirs, int *per_dirs) { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 1) return; - + if (m_sz != 1) { + return; + } + struct gkyl_range range; - gkyl_range_init(&range, 2, (int[]) { 1, 1 }, (int[]) { 4, 4 }); + gkyl_range_init(&range, 2, (int[]){1, 1}, (int[]){4, 4}); - int cuts[] = { 1, 1 }; - struct gkyl_rect_decomp *decomp = - gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); + int cuts[] = {1, 1}; + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(range.ndim, cuts, &range); - struct gkyl_comm *comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + struct gkyl_comm *comm = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); int rank; gkyl_comm_get_rank(comm, &rank); - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); struct gkyl_range local_x[2], local_ext_x[2]; - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { nghost[0], 0 }, - &local_ext_x[0], &local_x[0]); - - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { 0, nghost[1] }, - &local_ext_x[1], &local_x[1]); + gkyl_create_ranges(&decomp->ranges[rank], (int[]){nghost[0], 0}, &local_ext_x[0], &local_x[0]); + + gkyl_create_ranges(&decomp->ranges[rank], (int[]){0, nghost[1]}, &local_ext_x[1], &local_x[1]); struct gkyl_array *arr = gkyl_array_cu_dev_new(GKYL_DOUBLE, range.ndim, local_ext.volume); struct gkyl_array *arr_ho = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); @@ -864,39 +842,45 @@ nccl_n1_per_sync_2d_tests(int num_per_dirs, int *per_dirs) long idx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr_ho, idx); - for (int d=0; d local.upper[d]) + for (int n = 0; n < local.ndim; ++n) { + idx[n] = iter.idx[n]; + } + + if (idx[d] > local.upper[d]) { idx[d] = idx[d] - ncell; - else + } else { idx[d] = idx[d] + ncell; - - const double *f = gkyl_array_cfetch(arr_ho, lidx); - for (int n=0; nranges[rank], nghost, &local_ext, &local); struct gkyl_range local_x[2], local_ext_x[2]; - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { nghost[0], 0 }, - &local_ext_x[0], &local_x[0]); - - gkyl_create_ranges(&decomp->ranges[rank], (int[]) { 0, nghost[1] }, - &local_ext_x[1], &local_x[1]); + gkyl_create_ranges(&decomp->ranges[rank], (int[]){nghost[0], 0}, &local_ext_x[0], &local_x[0]); + + gkyl_create_ranges(&decomp->ranges[rank], (int[]){0, nghost[1]}, &local_ext_x[1], &local_x[1]); // Redefine local_ext_x so it's local shifted in the right direction // so it covers the ghost cells of interest. - int decomp_dir = cuts[0]>1? 0 : 1; + int decomp_dir = cuts[0] > 1 ? 0 : 1; int delta[] = {0, 0}; - delta[decomp_dir] = 2*rank-1; + delta[decomp_dir] = 2 * rank - 1; struct gkyl_range local_ext_x_shifted; gkyl_range_shift(&local_ext_x_shifted, &local_ext_x[decomp_dir], delta); - gkyl_sub_range_init(&local_ext_x[decomp_dir], &local_ext, local_ext_x_shifted.lower, local_ext_x_shifted.upper); + gkyl_sub_range_init( + &local_ext_x[decomp_dir], &local_ext, local_ext_x_shifted.lower, local_ext_x_shifted.upper + ); struct gkyl_array *arr = gkyl_array_cu_dev_new(GKYL_DOUBLE, range.ndim, local_ext.volume); struct gkyl_array *arr_ho = gkyl_array_new(GKYL_DOUBLE, range.ndim, local_ext.volume); @@ -975,39 +955,45 @@ nccl_n2_per_sync_2d_tests(int *cuts, int num_per_dirs, int *per_dirs) long idx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr_ho, idx); - for (int d=0; d local.upper[d]) + for (int n = 0; n < local.ndim; ++n) { + idx[n] = iter.idx[n]; + } + + if (idx[d] > local.upper[d]) { idx[d] = idx[d] - ncell; - else if (idx[d] < local.lower[d]) + } else if (idx[d] < local.lower[d]) { idx[d] = idx[d] + ncell; - - const double *f = gkyl_array_cfetch(arr_ho, lidx); - for (int n=0; nndecomp); + int confcuts[] = {2, 1}; + struct gkyl_rect_decomp *confdecomp = gkyl_rect_decomp_new_from_cuts(2, confcuts, &range); + + int confcolor = floor(worldrank / confdecomp->ndecomp); struct gkyl_comm *confcomm = gkyl_comm_split_comm(worldcomm, confcolor, confdecomp); int confrank; gkyl_comm_get_rank(confcomm, &confrank); @@ -1073,7 +1056,7 @@ nccl_n4_multicomm_2d_dev() int speciesrank; gkyl_comm_get_rank(speciescomm, &speciesrank); - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&confdecomp->ranges[confrank], nghost, &local_ext, &local); @@ -1085,10 +1068,10 @@ nccl_n4_multicomm_2d_dev() gkyl_array_clear(arrB_ho, 0.); // Sync across the conf-space communicator. - struct gkyl_array *recvbuff = speciesrank==0? arrB : arrA; - struct gkyl_array *sendbuff = speciesrank==0? arrA : arrB; - struct gkyl_array *recvbuff_ho = speciesrank==0? arrB_ho : arrA_ho; - struct gkyl_array *sendbuff_ho = speciesrank==0? arrA_ho : arrB_ho; + struct gkyl_array *recvbuff = speciesrank == 0 ? arrB : arrA; + struct gkyl_array *sendbuff = speciesrank == 0 ? arrA : arrB; + struct gkyl_array *recvbuff_ho = speciesrank == 0 ? arrB_ho : arrA_ho; + struct gkyl_array *sendbuff_ho = speciesrank == 0 ? arrA_ho : arrB_ho; gkyl_comm_barrier(worldcomm); @@ -1097,7 +1080,8 @@ nccl_n4_multicomm_2d_dev() while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(sendbuff_ho, idx); - f[0] = iter.idx[0]; f[1] = iter.idx[1]; + f[0] = iter.idx[0]; + f[1] = iter.idx[1]; } gkyl_array_copy(sendbuff, sendbuff_ho); @@ -1108,43 +1092,44 @@ nccl_n4_multicomm_2d_dev() struct gkyl_range in_range; // interior, including ghost cells gkyl_sub_range_intersect(&in_range, &local_ext, &range); struct gkyl_range local_x, local_ext_x, local_y, local_ext_y; - gkyl_create_ranges(&confdecomp->ranges[confrank], (int[]) {1, 0}, &local_ext_x, &local_x); - gkyl_create_ranges(&confdecomp->ranges[confrank], (int[]) { 0, 1 }, &local_ext_y, &local_y); + gkyl_create_ranges(&confdecomp->ranges[confrank], (int[]){1, 0}, &local_ext_x, &local_x); + gkyl_create_ranges(&confdecomp->ranges[confrank], (int[]){0, 1}, &local_ext_y, &local_y); gkyl_range_iter_init(&iter, &in_range); while (gkyl_range_iter_next(&iter)) { long idx = gkyl_range_idx(&in_range, iter.idx); const double *f = gkyl_array_cfetch(sendbuff_ho, idx); // exclude corners - if (gkyl_range_contains_idx(&local_ext_x, iter.idx) || gkyl_range_contains_idx(&local_ext_y, iter.idx)) { - TEST_CHECK( iter.idx[0] == f[0] ); - TEST_CHECK( iter.idx[1] == f[1] ); + if (gkyl_range_contains_idx(&local_ext_x, iter.idx) || + gkyl_range_contains_idx(&local_ext_y, iter.idx)) { + TEST_CHECK(iter.idx[0] == f[0]); + TEST_CHECK(iter.idx[1] == f[1]); } } -// MF 2024/09/12: disable these for now per 498b7d1569eaa9285ae59581bd22dab124672f7b. -// // Now send/recv across species communicator and check results. -// struct gkyl_comm_state *cstate = gkyl_comm_state_new(speciescomm); -// int tag = 13; -// // Post irecv before send. -// gkyl_comm_group_call_start(speciescomm); -// gkyl_comm_array_irecv(speciescomm, recvbuff, (speciesrank+1) % 2, tag, cstate); -// gkyl_comm_array_send(speciescomm, sendbuff, (speciesrank+1) % 2, tag); -// gkyl_comm_group_call_end(speciescomm); -// gkyl_comm_state_wait(speciescomm, cstate); -// -// gkyl_array_copy(recvbuff_ho, recvbuff); -// gkyl_range_iter_init(&iter, &in_range); -// while (gkyl_range_iter_next(&iter)) { -// long idx = gkyl_range_idx(&in_range, iter.idx); -// const double *f = gkyl_array_cfetch(recvbuff_ho, idx); -// // exclude corners -// if (gkyl_range_contains_idx(&local_ext_x, iter.idx) || gkyl_range_contains_idx(&local_ext_y, iter.idx)) { -// TEST_CHECK( iter.idx[0] == f[0] ); -// TEST_CHECK( iter.idx[1] == f[1] ); -// } -// } -// -// gkyl_comm_state_release(speciescomm, cstate); + // MF 2024/09/12: disable these for now per 498b7d1569eaa9285ae59581bd22dab124672f7b. + // // Now send/recv across species communicator and check results. + // struct gkyl_comm_state *cstate = gkyl_comm_state_new(speciescomm); + // int tag = 13; + // // Post irecv before send. + // gkyl_comm_group_call_start(speciescomm); + // gkyl_comm_array_irecv(speciescomm, recvbuff, (speciesrank+1) % 2, tag, cstate); + // gkyl_comm_array_send(speciescomm, sendbuff, (speciesrank+1) % 2, tag); + // gkyl_comm_group_call_end(speciescomm); + // gkyl_comm_state_wait(speciescomm, cstate); + // + // gkyl_array_copy(recvbuff_ho, recvbuff); + // gkyl_range_iter_init(&iter, &in_range); + // while (gkyl_range_iter_next(&iter)) { + // long idx = gkyl_range_idx(&in_range, iter.idx); + // const double *f = gkyl_array_cfetch(recvbuff_ho, idx); + // // exclude corners + // if (gkyl_range_contains_idx(&local_ext_x, iter.idx) || gkyl_range_contains_idx(&local_ext_y, iter.idx)) { + // TEST_CHECK( iter.idx[0] == f[0] ); + // TEST_CHECK( iter.idx[1] == f[1] ); + // } + // } + // + // gkyl_comm_state_release(speciescomm, cstate); gkyl_array_release(arrA); gkyl_array_release(arrB); gkyl_array_release(arrA_ho); @@ -1154,61 +1139,61 @@ nccl_n4_multicomm_2d_dev() gkyl_comm_release(worldcomm); gkyl_rect_decomp_release(confdecomp); } - -static void -nccl_n4_create_comm_from_ranks_1_dev() + +static void nccl_n4_create_comm_from_ranks_1_dev() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - struct gkyl_comm *comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + struct gkyl_comm *comm = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); - int branks[2] = { 2, 2 }; + int branks[2] = {2, 2}; bool status = false; - - const struct gkyl_rrobin_decomp *rrd = - gkyl_rrobin_decomp_new(m_sz, 2, branks); + + const struct gkyl_rrobin_decomp *rrd = gkyl_rrobin_decomp_new(m_sz, 2, branks); int rb1[4]; gkyl_rrobin_decomp_getranks(rrd, 0, rb1); - struct gkyl_comm *comm_b1 = - gkyl_comm_create_comm_from_ranks(comm, branks[0], rb1, 0, &status); + struct gkyl_comm *comm_b1 = gkyl_comm_create_comm_from_ranks(comm, branks[0], rb1, 0, &status); - if (rank == rb1[0]) - TEST_CHECK( status ); - if (rank == rb1[1]) - TEST_CHECK( status ); + if (rank == rb1[0]) { + TEST_CHECK(status); + } + if (rank == rb1[1]) { + TEST_CHECK(status); + } if (comm_b1) { int sz_b1; gkyl_comm_get_size(comm_b1, &sz_b1); - TEST_CHECK( branks[0] == sz_b1); + TEST_CHECK(branks[0] == sz_b1); } int rb2[4]; gkyl_rrobin_decomp_getranks(rrd, 1, rb2); - struct gkyl_comm *comm_b2 = - gkyl_comm_create_comm_from_ranks(comm, branks[1], rb2, 0, &status); + struct gkyl_comm *comm_b2 = gkyl_comm_create_comm_from_ranks(comm, branks[1], rb2, 0, &status); - if (rank == rb2[0]) - TEST_CHECK( status ); - if (rank == rb2[1]) - TEST_CHECK( status ); + if (rank == rb2[0]) { + TEST_CHECK(status); + } + if (rank == rb2[1]) { + TEST_CHECK(status); + } if (comm_b2) { int sz_b2; gkyl_comm_get_size(comm_b2, &sz_b2); - TEST_CHECK( branks[1] == sz_b2); - } + TEST_CHECK(branks[1] == sz_b2); + } gkyl_rrobin_decomp_release(rrd); gkyl_comm_release(comm); @@ -1216,63 +1201,65 @@ nccl_n4_create_comm_from_ranks_1_dev() gkyl_comm_release(comm_b2); } -static void -nccl_n4_create_comm_from_ranks_2_dev() +static void nccl_n4_create_comm_from_ranks_2_dev() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); - if (m_sz != 4) return; + if (m_sz != 4) { + return; + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - struct gkyl_comm *comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + struct gkyl_comm *comm = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); - int branks[2] = { 4, 2 }; + int branks[2] = {4, 2}; bool status = false; - - const struct gkyl_rrobin_decomp *rrd = - gkyl_rrobin_decomp_new(m_sz, 2, branks); + + const struct gkyl_rrobin_decomp *rrd = gkyl_rrobin_decomp_new(m_sz, 2, branks); int rb1[4]; gkyl_rrobin_decomp_getranks(rrd, 0, rb1); - struct gkyl_comm *comm_b1 = - gkyl_comm_create_comm_from_ranks(comm, branks[0], rb1, 0, &status); + struct gkyl_comm *comm_b1 = gkyl_comm_create_comm_from_ranks(comm, branks[0], rb1, 0, &status); - if (rank == rb1[0]) - TEST_CHECK( status ); - if (rank == rb1[1]) - TEST_CHECK( status ); - if (rank == rb1[2]) - TEST_CHECK( status ); - if (rank == rb1[3]) - TEST_CHECK( status ); + if (rank == rb1[0]) { + TEST_CHECK(status); + } + if (rank == rb1[1]) { + TEST_CHECK(status); + } + if (rank == rb1[2]) { + TEST_CHECK(status); + } + if (rank == rb1[3]) { + TEST_CHECK(status); + } if (comm_b1) { int sz_b1; gkyl_comm_get_size(comm_b1, &sz_b1); - TEST_CHECK( branks[0] == sz_b1); + TEST_CHECK(branks[0] == sz_b1); } int rb2[4]; gkyl_rrobin_decomp_getranks(rrd, 1, rb2); - struct gkyl_comm *comm_b2 = - gkyl_comm_create_comm_from_ranks(comm, branks[1], rb2, 0, &status); + struct gkyl_comm *comm_b2 = gkyl_comm_create_comm_from_ranks(comm, branks[1], rb2, 0, &status); - if (rank == rb2[0]) - TEST_CHECK( status ); - if (rank == rb2[1]) - TEST_CHECK( status ); + if (rank == rb2[0]) { + TEST_CHECK(status); + } + if (rank == rb2[1]) { + TEST_CHECK(status); + } if (comm_b2) { int sz_b2; gkyl_comm_get_size(comm_b2, &sz_b2); - TEST_CHECK( branks[1] == sz_b2); + TEST_CHECK(branks[1] == sz_b2); } gkyl_rrobin_decomp_release(rrd); @@ -1281,28 +1268,24 @@ nccl_n4_create_comm_from_ranks_2_dev() gkyl_comm_release(comm_b2); } -void -nccl_bcast_1d_dev() +void nccl_bcast_1d_dev() { int m_sz, rank; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - int bcast_rank = m_sz > 1? 1 : 0; + int bcast_rank = m_sz > 1 ? 1 : 0; struct gkyl_range global; - gkyl_range_init(&global, 1, (int[]) { 1 }, (int[]) { 8*27*125 }); + gkyl_range_init(&global, 1, (int[]){1}, (int[]){8 * 27 * 125}); - int cuts[] = { m_sz }; + int cuts[] = {m_sz}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(global.ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); - int nghost[] = { 1 }; + struct gkyl_comm *comm = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -1315,7 +1298,7 @@ nccl_bcast_1d_dev() while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr_ho, linidx); - f[0] = linidx+10.0*rank; + f[0] = linidx + 10.0 * rank; } gkyl_array_copy(arr, arr_ho); @@ -1326,39 +1309,35 @@ nccl_bcast_1d_dev() while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr_ho, linidx); - TEST_CHECK( linidx+10.0*bcast_rank == f[0] ); + TEST_CHECK(linidx + 10.0 * bcast_rank == f[0]); } gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_array_release(arr); - gkyl_array_release(arr_ho); + gkyl_array_release(arr); + gkyl_array_release(arr_ho); } -void -nccl_bcast_2d_test(int *cuts) +void nccl_bcast_2d_test(int *cuts) { int m_sz, rank; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - int bcast_rank = m_sz > 1? 1 : 0; + int bcast_rank = m_sz > 1 ? 1 : 0; // create global range - int cells[] = { 4*9*25, 4*9*25 }; - int ndim = sizeof(cells)/sizeof(cells[0]); + int cells[] = {4 * 9 * 25, 4 * 9 * 25}; + int ndim = sizeof(cells) / sizeof(cells[0]); struct gkyl_range global; gkyl_create_global_range(ndim, cells, &global); - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(ndim, cuts, &global); + + struct gkyl_comm *comm = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -1371,8 +1350,8 @@ nccl_bcast_2d_test(int *cuts) while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr_ho, linidx); - f[0] = iter.idx[0] + iter.idx[1]*(rank+1.0) + 10.0*rank; - } + f[0] = iter.idx[0] + iter.idx[1] * (rank + 1.0) + 10.0 * rank; + } gkyl_array_copy(arr, arr_ho); gkyl_comm_array_bcast(comm, arr, arr, bcast_rank); @@ -1384,9 +1363,12 @@ nccl_bcast_2d_test(int *cuts) while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&bcast_rank_local, iter.idx); double *f = gkyl_array_fetch(arr_ho, linidx); - double val = iter.idx[0] + iter.idx[1]*(bcast_rank+1.0) + 10.0*bcast_rank; - TEST_CHECK( val == f[0] ); - TEST_MSG( "rank:%d | At idx=(%d,%d) | Expected: %.13e | Produced: %.13e", rank, iter.idx[0], iter.idx[1], val, f[0] ); + double val = iter.idx[0] + iter.idx[1] * (bcast_rank + 1.0) + 10.0 * bcast_rank; + TEST_CHECK(val == f[0]); + TEST_MSG( + "rank:%d | At idx=(%d,%d) | Expected: %.13e | Produced: %.13e", rank, iter.idx[0], + iter.idx[1], val, f[0] + ); } gkyl_rect_decomp_release(decomp); @@ -1395,8 +1377,7 @@ nccl_bcast_2d_test(int *cuts) gkyl_array_release(arr_ho); } -void -nccl_bcast_2d_dev() +void nccl_bcast_2d_dev() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); @@ -1404,46 +1385,41 @@ nccl_bcast_2d_dev() if (m_sz == 2) { int cuts12[] = {1, 2}; nccl_bcast_2d_test(cuts12); - + int cuts21[] = {2, 1}; nccl_bcast_2d_test(cuts21); - + } else if (m_sz == 3) { int cuts13[] = {1, 3}; nccl_bcast_2d_test(cuts13); - + int cuts31[] = {3, 1}; nccl_bcast_2d_test(cuts31); } else if (m_sz == 4) { int cuts22[] = {2, 2}; nccl_bcast_2d_test(cuts22); - } } -void -nccl_bcast_1d_host_dev() +void nccl_bcast_1d_host_dev() { int m_sz, rank; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - int bcast_rank = m_sz > 1? 1 : 0; + int bcast_rank = m_sz > 1 ? 1 : 0; struct gkyl_range global; - gkyl_range_init(&global, 1, (int[]) { 1 }, (int[]) { 8*27*125 }); + gkyl_range_init(&global, 1, (int[]){1}, (int[]){8 * 27 * 125}); - int cuts[] = { m_sz }; + int cuts[] = {m_sz}; struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(global.ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); - int nghost[] = { 1 }; + struct gkyl_comm *comm = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + + int nghost[] = {1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -1455,7 +1431,7 @@ nccl_bcast_1d_host_dev() while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr_ho, linidx); - f[0] = linidx+10.0*rank; + f[0] = linidx + 10.0 * rank; } gkyl_comm_array_bcast_host(comm, arr_ho, arr_ho, bcast_rank); @@ -1464,38 +1440,34 @@ nccl_bcast_1d_host_dev() while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr_ho, linidx); - TEST_CHECK( linidx+10.0*bcast_rank == f[0] ); + TEST_CHECK(linidx + 10.0 * bcast_rank == f[0]); } gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_array_release(arr_ho); + gkyl_array_release(arr_ho); } -void -nccl_bcast_2d_host_test(int *cuts) +void nccl_bcast_2d_host_test(int *cuts) { int m_sz, rank; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - int bcast_rank = m_sz > 1? 1 : 0; + int bcast_rank = m_sz > 1 ? 1 : 0; // create global range - int cells[] = { 4*9*25, 4*9*25 }; - int ndim = sizeof(cells)/sizeof(cells[0]); + int cells[] = {4 * 9 * 25, 4 * 9 * 25}; + int ndim = sizeof(cells) / sizeof(cells[0]); struct gkyl_range global; gkyl_create_global_range(ndim, cells, &global); - struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(ndim, cuts, &global); - - struct gkyl_comm *comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp, - } - ); + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(ndim, cuts, &global); + + struct gkyl_comm *comm = + gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); - int nghost[] = { 1, 1 }; + int nghost[] = {1, 1}; struct gkyl_range local, local_ext; gkyl_create_ranges(&decomp->ranges[rank], nghost, &local_ext, &local); @@ -1507,8 +1479,8 @@ nccl_bcast_2d_host_test(int *cuts) while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); double *f = gkyl_array_fetch(arr_ho, linidx); - f[0] = iter.idx[0] + iter.idx[1]*(rank+1.0) + 10.0*rank; - } + f[0] = iter.idx[0] + iter.idx[1] * (rank + 1.0) + 10.0 * rank; + } gkyl_comm_array_bcast_host(comm, arr_ho, arr_ho, bcast_rank); @@ -1518,9 +1490,12 @@ nccl_bcast_2d_host_test(int *cuts) while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&bcast_rank_local, iter.idx); double *f = gkyl_array_fetch(arr_ho, linidx); - double val = iter.idx[0] + iter.idx[1]*(bcast_rank+1.0) + 10.0*bcast_rank; - TEST_CHECK( val == f[0] ); - TEST_MSG( "rank:%d | At idx=(%d,%d) | Expected: %.13e | Produced: %.13e", rank, iter.idx[0], iter.idx[1], val, f[0] ); + double val = iter.idx[0] + iter.idx[1] * (bcast_rank + 1.0) + 10.0 * bcast_rank; + TEST_CHECK(val == f[0]); + TEST_MSG( + "rank:%d | At idx=(%d,%d) | Expected: %.13e | Produced: %.13e", rank, iter.idx[0], + iter.idx[1], val, f[0] + ); } gkyl_rect_decomp_release(decomp); @@ -1528,8 +1503,7 @@ nccl_bcast_2d_host_test(int *cuts) gkyl_array_release(arr_ho); } -void -nccl_bcast_2d_host_dev() +void nccl_bcast_2d_host_dev() { int m_sz; MPI_Comm_size(MPI_COMM_WORLD, &m_sz); @@ -1537,54 +1511,50 @@ nccl_bcast_2d_host_dev() if (m_sz == 2) { int cuts12[] = {1, 2}; nccl_bcast_2d_host_test(cuts12); - + int cuts21[] = {2, 1}; nccl_bcast_2d_host_test(cuts21); - + } else if (m_sz == 3) { int cuts13[] = {1, 3}; nccl_bcast_2d_host_test(cuts13); - + int cuts31[] = {3, 1}; nccl_bcast_2d_host_test(cuts31); } else if (m_sz == 4) { int cuts22[] = {2, 2}; nccl_bcast_2d_host_test(cuts22); - } } - TEST_LIST = { {"nccl_allreduce_dev", nccl_allreduce_dev}, {"nccl_n2_allgather_1d_dev", nccl_n2_allgather_1d_dev}, {"nccl_n4_allgather_2d_dev", nccl_n4_allgather_2d_dev}, {"nccl_n2_allgather_1d_host_dev", nccl_n2_allgather_1d_host_dev}, {"nccl_n4_allgather_2d_host_dev", nccl_n4_allgather_2d_host_dev}, -// {"nccl_n2_array_send_irecv_2d_dev", nccl_n2_array_send_irecv_2d_dev}, -// {"nccl_n2_array_isend_irecv_2d_dev", nccl_n2_array_isend_irecv_2d_dev}, + // {"nccl_n2_array_send_irecv_2d_dev", nccl_n2_array_send_irecv_2d_dev}, + // {"nccl_n2_array_isend_irecv_2d_dev", nccl_n2_array_isend_irecv_2d_dev}, {"nccl_n2_sync_1d_dev", nccl_n2_sync_1d_dev}, - {"nccl_n4_sync_2d_no_corner_dev", nccl_n4_sync_2d_no_corner_dev }, + {"nccl_n4_sync_2d_no_corner_dev", nccl_n4_sync_2d_no_corner_dev}, {"nccl_n4_sync_2d_use_corner_dev", nccl_n4_sync_2d_use_corner_dev}, - {"nccl_n4_sync_1x1v_dev", nccl_n4_sync_1x1v_dev }, - {"nccl_n1_per_sync_2d_dev", nccl_n1_per_sync_2d_dev }, - {"nccl_n2_per_sync_2d_dev", nccl_n2_per_sync_2d_dev }, + {"nccl_n4_sync_1x1v_dev", nccl_n4_sync_1x1v_dev}, + {"nccl_n1_per_sync_2d_dev", nccl_n1_per_sync_2d_dev}, + {"nccl_n2_per_sync_2d_dev", nccl_n2_per_sync_2d_dev}, {"nccl_n4_multicomm_2d_dev", nccl_n4_multicomm_2d_dev}, - {"nccl_n4_create_comm_from_ranks_1_dev", nccl_n4_create_comm_from_ranks_1_dev }, - {"nccl_n4_create_comm_from_ranks_2_dev", nccl_n4_create_comm_from_ranks_2_dev }, + {"nccl_n4_create_comm_from_ranks_1_dev", nccl_n4_create_comm_from_ranks_1_dev}, + {"nccl_n4_create_comm_from_ranks_2_dev", nccl_n4_create_comm_from_ranks_2_dev}, {"nccl_bcast_1d_dev", nccl_bcast_1d_dev}, {"nccl_bcast_2d_dev", nccl_bcast_2d_dev}, {"nccl_bcast_1d_host_dev", nccl_bcast_1d_host_dev}, {"nccl_bcast_2d_host_dev", nccl_bcast_2d_host_dev}, - {NULL, NULL}, + {NULL, NULL} }; #else // nothing to test if not building with NCCL -TEST_LIST = { - {NULL, NULL}, -}; +TEST_LIST = {{NULL, NULL}}; #endif diff --git a/core/zero/alloc.c b/core/zero/alloc.c index 46b28afb02..3b45b2b0ae 100644 --- a/core/zero/alloc.c +++ b/core/zero/alloc.c @@ -9,16 +9,18 @@ #include // Output command for use in debugging memory usage -#define GKYL_MEMMSG(fmt, ...) do { \ - if (gkyl_mem_debug) \ - fprintf(stderr, fmt, __VA_ARGS__); \ +#define GKYL_MEMMSG(fmt, ...) \ + do { \ + if (gkyl_mem_debug) \ + fprintf(stderr, fmt, __VA_ARGS__); \ } while (0); // Output command for use in debugging CUDA memory usage -#define GKYL_CU_MEMMSG(fmt, ...) do { \ - if (gkyl_cu_dev_mem_debug) \ - fprintf(stderr, fmt, __VA_ARGS__); \ - } while (0); +#define GKYL_CU_MEMMSG(fmt, ...) \ + do { \ + if (gkyl_cu_dev_mem_debug) \ + fprintf(stderr, fmt, __VA_ARGS__); \ + } while (0); // by default, do not print memory allocation traces static bool gkyl_mem_debug = false; @@ -35,58 +37,57 @@ void gkyl_cu_dev_mem_debug_set(bool flag) } // Compute first 'align' boundary after 'num' -#define align_up(num, align) \ - (((num) + ((align) - 1)) & ~((align) - 1)) +#define align_up(num, align) (((num) + ((align) - 1)) & ~((align) - 1)) static const size_t PTR_OFFSET_SZ = sizeof(uint16_t); -void* -gkyl_malloc_(const char *file, int line, const char *func, size_t size) +void *gkyl_malloc_(const char *file, int line, const char *func, size_t size) { void *mem = malloc(size); - GKYL_MEMMSG("%p [%zu] 0.malloc: %s %s:%d\n", mem, size, file, func, line); - if (0 == mem) gkyl_exit("malloc failed!"); + GKYL_MEMMSG("%p [%zu] 0.malloc: %s %s:%d\n", mem, size, file, func, line); + if (0 == mem) { + gkyl_exit("malloc failed!"); + } return mem; } -void* -gkyl_calloc_(const char *file, int line, const char *func, size_t num, size_t size) +void *gkyl_calloc_(const char *file, int line, const char *func, size_t num, size_t size) { void *mem = calloc(num, size); GKYL_MEMMSG("%p [%zu] 0.calloc: %s %s:%d\n", mem, size, file, func, line); - if (0 == mem) gkyl_exit("calloc failed!"); + if (0 == mem) { + gkyl_exit("calloc failed!"); + } return mem; } -void* -gkyl_realloc_(const char *file, int line, const char *func, void *ptr, size_t new_size) +void *gkyl_realloc_(const char *file, int line, const char *func, void *ptr, size_t new_size) { void *mem = realloc(ptr, new_size); - GKYL_MEMMSG("%p [%zu] 0.realloc: %s %s:%d\n", mem, new_size, file, func, line); - if (0 == mem) gkyl_exit("realloc failed!"); + GKYL_MEMMSG("%p [%zu] 0.realloc: %s %s:%d\n", mem, new_size, file, func, line); + if (0 == mem) { + gkyl_exit("realloc failed!"); + } return mem; } -void -gkyl_free_(const char *file, int line, const char *func, void *ptr) +void gkyl_free_(const char *file, int line, const char *func, void *ptr) { GKYL_MEMMSG("%p 1.free: %s %s:%d\n", ptr, file, func, line); free(ptr); } -void* -gkyl_aligned_alloc_(const char *file, int line, const char *func, - size_t align, size_t size) +void *gkyl_aligned_alloc_(const char *file, int line, const char *func, size_t align, size_t size) { void *ptr = 0; - assert((align & (align-1)) == 0); // power of 2? + assert((align & (align - 1)) == 0); // power of 2? if (align && size) { - uint32_t hdr_size = PTR_OFFSET_SZ + (align-1); - void *p = gkyl_calloc(size+hdr_size, 1); + uint32_t hdr_size = PTR_OFFSET_SZ + (align - 1); + void *p = gkyl_calloc(size + hdr_size, 1); if (p) { - ptr = (void *) align_up(((uintptr_t)p + PTR_OFFSET_SZ), align); - *((uint16_t *)ptr - 1) = (uint16_t) ((uintptr_t) ptr - (uintptr_t) p); + ptr = (void *)align_up(((uintptr_t)p + PTR_OFFSET_SZ), align); + *((uint16_t *)ptr - 1) = (uint16_t)((uintptr_t)ptr - (uintptr_t)p); } } @@ -94,9 +95,10 @@ gkyl_aligned_alloc_(const char *file, int line, const char *func, return ptr; } -void* -gkyl_aligned_realloc_(const char *file, int line, const char *func, - void *ptr, size_t align, size_t old_sz, size_t new_sz) +void *gkyl_aligned_realloc_( + const char *file, int line, const char *func, void *ptr, size_t align, size_t old_sz, + size_t new_sz +) { void *nptr = gkyl_aligned_alloc(align, new_sz); if (0 == nptr) { @@ -110,13 +112,11 @@ gkyl_aligned_realloc_(const char *file, int line, const char *func, return nptr; } -void -gkyl_aligned_free_(const char *file, int line, const char *func, - void* ptr) +void gkyl_aligned_free_(const char *file, int line, const char *func, void *ptr) { assert(ptr); GKYL_MEMMSG("%p 1.aligned_free: %s %s:%d\n", ptr, file, func, line); - + uint16_t offset = *((uint16_t *)ptr - 1); gkyl_free((uint8_t *)ptr - offset); } @@ -127,8 +127,7 @@ struct gkyl_mem_buff_tag { char *data; // Allocated memory }; -gkyl_mem_buff -gkyl_mem_buff_new(size_t count) +gkyl_mem_buff gkyl_mem_buff_new(size_t count) { struct gkyl_mem_buff_tag *mem = gkyl_malloc(sizeof(*mem)); mem->on_gpu = false; @@ -137,8 +136,7 @@ gkyl_mem_buff_new(size_t count) return mem; } -gkyl_mem_buff -gkyl_mem_buff_cu_new(size_t count) +gkyl_mem_buff gkyl_mem_buff_cu_new(size_t count) { struct gkyl_mem_buff_tag *mem = gkyl_malloc(sizeof(*mem)); mem->on_gpu = true; @@ -147,8 +145,7 @@ gkyl_mem_buff_cu_new(size_t count) return mem; } -gkyl_mem_buff -gkyl_mem_buff_resize(gkyl_mem_buff mem, size_t count) +gkyl_mem_buff gkyl_mem_buff_resize(gkyl_mem_buff mem, size_t count) { if (count > mem->count) { if (mem->on_gpu) { @@ -156,8 +153,7 @@ gkyl_mem_buff_resize(gkyl_mem_buff mem, size_t count) gkyl_cu_memcpy(data_new, mem->data, mem->count, GKYL_CU_MEMCPY_D2D); gkyl_cu_free(mem->data); mem->data = data_new; - } - else { + } else { mem->data = gkyl_realloc(mem->data, count); } mem->count = count; @@ -165,26 +161,24 @@ gkyl_mem_buff_resize(gkyl_mem_buff mem, size_t count) return mem; } -size_t -gkyl_mem_buff_size(gkyl_mem_buff mem) +size_t gkyl_mem_buff_size(gkyl_mem_buff mem) { return mem->count; } -char* -gkyl_mem_buff_data(gkyl_mem_buff mem) +char *gkyl_mem_buff_data(gkyl_mem_buff mem) { return mem->data; } -void -gkyl_mem_buff_release(gkyl_mem_buff mem) +void gkyl_mem_buff_release(gkyl_mem_buff mem) { - if (mem->on_gpu) + if (mem->on_gpu) { gkyl_cu_free(mem->data); - else + } else { gkyl_free(mem->data); - + } + gkyl_free(mem); } @@ -194,49 +188,46 @@ gkyl_mem_buff_release(gkyl_mem_buff mem) #include -void* -gkyl_cu_malloc_(const char *file, int line, const char *func, size_t size) +void *gkyl_cu_malloc_(const char *file, int line, const char *func, size_t size) { void *ptr; cudaError_t err = cudaMalloc(&ptr, size); - if (err != cudaSuccess) + if (err != cudaSuccess) { gkyl_exit("cudaMalloc failed!"); - + } + GKYL_CU_MEMMSG("%p 0.cudaMalloc: %s %s:%d\n", ptr, file, func, line); return ptr; } -void* -gkyl_cu_malloc_host_(const char *file, int line, const char *func, size_t size) +void *gkyl_cu_malloc_host_(const char *file, int line, const char *func, size_t size) { // Allocate pinned host memory. void *ptr; cudaError_t err = cudaMallocHost(&ptr, size); - if (err != cudaSuccess) + if (err != cudaSuccess) { gkyl_exit("cudaMallocHost failed!"); + } GKYL_CU_MEMMSG("%p 0.cudaMallocHost: %s %s:%d\n", ptr, file, func, line); return ptr; } -void -gkyl_cu_free_(const char *file, int line, const char *func, void *ptr) +void gkyl_cu_free_(const char *file, int line, const char *func, void *ptr) { GKYL_CU_MEMMSG("%p 1.cudaFree: %s %s:%d\n", ptr, file, func, line); cudaFree(ptr); } -void -gkyl_cu_free_host_(const char *file, int line, const char *func, void *ptr) +void gkyl_cu_free_host_(const char *file, int line, const char *func, void *ptr) { GKYL_CU_MEMMSG("%p 1.cudaFreeHost: %s %s:%d\n", ptr, file, func, line); cudaFreeHost(ptr); } -void -gkyl_cu_memcpy(void *dst, const void *src, size_t count, enum gkyl_cu_memcpy_kind kind) +void gkyl_cu_memcpy(void *dst, const void *src, size_t count, enum gkyl_cu_memcpy_kind kind) { cudaError_t err = cudaMemcpy(dst, src, count, kind); if (err != cudaSuccess) { @@ -246,8 +237,9 @@ gkyl_cu_memcpy(void *dst, const void *src, size_t count, enum gkyl_cu_memcpy_kin } } -void -gkyl_cu_memcpy_async(void *dst, const void *src, size_t count, enum gkyl_cu_memcpy_kind kind, cudaStream_t stream) +void gkyl_cu_memcpy_async( + void *dst, const void *src, size_t count, enum gkyl_cu_memcpy_kind kind, cudaStream_t stream +) { cudaError_t err = cudaMemcpyAsync(dst, src, count, kind, stream); if (err != cudaSuccess) { @@ -257,12 +249,12 @@ gkyl_cu_memcpy_async(void *dst, const void *src, size_t count, enum gkyl_cu_memc } } -void -gkyl_cu_memset(void *data, int val, size_t count) +void gkyl_cu_memset(void *data, int val, size_t count) { cudaError_t err = cudaMemset(data, val, count); - if (err != cudaSuccess) + if (err != cudaSuccess) { gkyl_exit("gkyl_cu_memset failed!"); + } } #else @@ -270,48 +262,43 @@ gkyl_cu_memset(void *data, int val, size_t count) // These non-CUDA functions will simply abort. When not using CUDA // none of these methods should be called at all. -void* -gkyl_cu_malloc_(const char *file, int line, const char *func, size_t size) +void *gkyl_cu_malloc_(const char *file, int line, const char *func, size_t size) { assert(false); return 0; } -void* -gkyl_cu_malloc_host_(const char *file, int line, const char *func, size_t size) +void *gkyl_cu_malloc_host_(const char *file, int line, const char *func, size_t size) { assert(false); return 0; } -void -gkyl_cu_free_(const char *file, int line, const char *func, void *ptr) +void gkyl_cu_free_(const char *file, int line, const char *func, void *ptr) { assert(false); } -void -gkyl_cu_free_host_(const char *file, int line, const char *func, void *ptr) +void gkyl_cu_free_host_(const char *file, int line, const char *func, void *ptr) { assert(false); } -void -gkyl_cu_memcpy(void *dst, const void *src, size_t count, enum gkyl_cu_memcpy_kind kind) +void gkyl_cu_memcpy(void *dst, const void *src, size_t count, enum gkyl_cu_memcpy_kind kind) { - assert(false); + assert(false); } -void -gkyl_cu_memcpy_async(void *dst, const void *src, size_t count, enum gkyl_cu_memcpy_kind kind, int stream) +void gkyl_cu_memcpy_async( + void *dst, const void *src, size_t count, enum gkyl_cu_memcpy_kind kind, int stream +) { - assert(false); + assert(false); } -void -gkyl_cu_memset(void *data, int val, size_t count) +void gkyl_cu_memset(void *data, int val, size_t count) { - assert(false); + assert(false); } #endif // CUDA specific code diff --git a/core/zero/array.c b/core/zero/array.c index 79219d19f6..a5e7daa3dd 100644 --- a/core/zero/array.c +++ b/core/zero/array.c @@ -12,30 +12,30 @@ // alignment boundary is 32 bytes to be compatible with AVX static const size_t ARRAY_ALIGN_BND = 32; -#define set_arr_dat_zero_ho(arr, data) \ - for (size_t i=0; isize*arr->ncomp; ++i) data[i] = 0 +#define set_arr_dat_zero_ho(arr, data) \ + for (size_t i = 0; i < arr->size * arr->ncomp; ++i) \ + data[i] = 0 -#define set_arr_dat_zero_dev(arr, data_ho) \ - for (size_t i=0; isize*arr->ncomp; ++i) data_ho[i] = 0; \ - gkyl_cu_memcpy(arr->data, data_ho, arr->size*arr->esznc, GKYL_CU_MEMCPY_H2D); +#define set_arr_dat_zero_dev(arr, data_ho) \ + for (size_t i = 0; i < arr->size * arr->ncomp; ++i) \ + data_ho[i] = 0; \ + gkyl_cu_memcpy(arr->data, data_ho, arr->size * arr->esznc, GKYL_CU_MEMCPY_H2D); -static void* -g_array_alloc(size_t num, size_t sz) +static void *g_array_alloc(size_t num, size_t sz) { #ifdef USE_ALIGNED_ALLOC - return gkyl_aligned_alloc(ARRAY_ALIGN_BND, num*sz); + return gkyl_aligned_alloc(ARRAY_ALIGN_BND, num * sz); #else return gkyl_calloc(num, sz); #endif } -static void -g_array_free(void* ptr) +static void g_array_free(void *ptr) { -#ifdef USE_ALIGNED_ALLOC +#ifdef USE_ALIGNED_ALLOC gkyl_aligned_free(ptr); #else gkyl_free(ptr); -#endif +#endif } // size in bytes for various data-types @@ -44,37 +44,34 @@ static const size_t array_elem_size[] = { [GKYL_LONG] = sizeof(long), [GKYL_FLOAT] = sizeof(float), [GKYL_DOUBLE] = sizeof(double), - [GKYL_USER] = 1, + [GKYL_USER] = 1 }; -static void -array_free(const struct gkyl_ref_count *ref) +static void array_free(const struct gkyl_ref_count *ref) { struct gkyl_array *arr = container_of(ref, struct gkyl_array, ref_count); if (false == GKYL_IS_ALLOC_EXTERN(arr->flags)) { // only free if we allocated memory ourselves - + if (GKYL_IS_CU_ALLOC(arr->flags)) { -#ifdef GKYL_HAVE_CUDA +#ifdef GKYL_HAVE_CUDA cudaStreamDestroy(arr->iostream); #endif gkyl_cu_free(arr->data); gkyl_cu_free(arr->on_dev); - } - else { + } else { g_array_free(arr->data); } - } gkyl_free(arr); } // internal method to allocate array -static struct gkyl_array* +static struct gkyl_array * array_new(enum gkyl_elem_type type, size_t ncomp, size_t size, bool is_alloc_extern, void *buff) { - struct gkyl_array* arr = gkyl_malloc(sizeof(struct gkyl_array)); + struct gkyl_array *arr = gkyl_malloc(sizeof(struct gkyl_array)); arr->type = type; arr->elemsz = array_elem_size[type]; @@ -82,23 +79,25 @@ array_new(enum gkyl_elem_type type, size_t ncomp, size_t size, bool is_alloc_ext arr->size = size; arr->flags = 0; - if (is_alloc_extern) + if (is_alloc_extern) { GKYL_SET_ALLOC_EXTERN(arr->flags); - else + } else { GKYL_CLEAR_ALLOC_EXTERN(arr->flags); - + } + GKYL_CLEAR_CU_ALLOC(arr->flags); -#ifdef USE_ALIGNED_ALLOC +#ifdef USE_ALIGNED_ALLOC GKYL_SET_ALLOC_ALIGNED(arr->flags); #else GKYL_CLEAR_ALLOC_ALIGNED(arr->flags); #endif - - arr->esznc = arr->elemsz*arr->ncomp; - arr->data = buff; - if (!is_alloc_extern) + + arr->esznc = arr->elemsz * arr->ncomp; + arr->data = buff; + if (!is_alloc_extern) { arr->data = g_array_alloc(arr->size, arr->esznc); - + } + arr->ref_count = gkyl_ref_count_init(array_free); arr->nthreads = 1; @@ -111,16 +110,13 @@ array_new(enum gkyl_elem_type type, size_t ncomp, size_t size, bool is_alloc_ext if (type == GKYL_INT) { int *dat_p = arr->data; set_arr_dat_zero_ho(arr, dat_p); - } - else if (type == GKYL_LONG) { + } else if (type == GKYL_LONG) { long *dat_p = arr->data; set_arr_dat_zero_ho(arr, dat_p); - } - else if (type == GKYL_FLOAT) { + } else if (type == GKYL_FLOAT) { float *dat_p = arr->data; set_arr_dat_zero_ho(arr, dat_p); - } - else if (type == GKYL_DOUBLE) { + } else if (type == GKYL_DOUBLE) { double *dat_p = arr->data; set_arr_dat_zero_ho(arr, dat_p); } @@ -129,35 +125,31 @@ array_new(enum gkyl_elem_type type, size_t ncomp, size_t size, bool is_alloc_ext return arr; } -struct gkyl_array* -gkyl_array_new(enum gkyl_elem_type type, size_t ncomp, size_t size) +struct gkyl_array *gkyl_array_new(enum gkyl_elem_type type, size_t ncomp, size_t size) { return array_new(type, ncomp, size, false, 0); } -struct gkyl_array* +struct gkyl_array * gkyl_array_new_from_buff(enum gkyl_elem_type type, size_t ncomp, size_t size, void *buff) { return array_new(type, ncomp, size, true, buff); } -bool -gkyl_array_is_cu_dev(const struct gkyl_array *arr) +bool gkyl_array_is_cu_dev(const struct gkyl_array *arr) { - return GKYL_IS_CU_ALLOC(arr->flags); + return GKYL_IS_CU_ALLOC(arr->flags); } -bool -gkyl_array_is_using_buffer(const struct gkyl_array *arr) +bool gkyl_array_is_using_buffer(const struct gkyl_array *arr) { return GKYL_IS_ALLOC_EXTERN(arr->flags); } -struct gkyl_array* -gkyl_array_copy(struct gkyl_array* dest, const struct gkyl_array* src) +struct gkyl_array *gkyl_array_copy(struct gkyl_array *dest, const struct gkyl_array *src) { assert(dest->esznc == src->esznc); - + long ncopy = src->size < dest->size ? src->size : dest->size; bool dest_is_cu_dev = gkyl_array_is_cu_dev(dest); @@ -165,27 +157,27 @@ gkyl_array_copy(struct gkyl_array* dest, const struct gkyl_array* src) if (src_is_cu_dev) { // source is on device - if (dest_is_cu_dev) - gkyl_cu_memcpy(dest->data, src->data, ncopy*src->esznc, GKYL_CU_MEMCPY_D2D); - else - gkyl_cu_memcpy(dest->data, src->data, ncopy*src->esznc, GKYL_CU_MEMCPY_D2H); - } - else { + if (dest_is_cu_dev) { + gkyl_cu_memcpy(dest->data, src->data, ncopy * src->esznc, GKYL_CU_MEMCPY_D2D); + } else { + gkyl_cu_memcpy(dest->data, src->data, ncopy * src->esznc, GKYL_CU_MEMCPY_D2H); + } + } else { // source is on host - if (dest_is_cu_dev) - gkyl_cu_memcpy(dest->data, src->data, ncopy*src->esznc, GKYL_CU_MEMCPY_H2D); - else - memcpy(dest->data, src->data, ncopy*src->esznc); + if (dest_is_cu_dev) { + gkyl_cu_memcpy(dest->data, src->data, ncopy * src->esznc, GKYL_CU_MEMCPY_H2D); + } else { + memcpy(dest->data, src->data, ncopy * src->esznc); + } } - + return dest; } -struct gkyl_array* -gkyl_array_copy_async(struct gkyl_array* dest, const struct gkyl_array* src) +struct gkyl_array *gkyl_array_copy_async(struct gkyl_array *dest, const struct gkyl_array *src) { assert(dest->esznc == src->esznc); - + long ncopy = src->size < dest->size ? src->size : dest->size; bool dest_is_cu_dev = gkyl_array_is_cu_dev(dest); @@ -193,26 +185,32 @@ gkyl_array_copy_async(struct gkyl_array* dest, const struct gkyl_array* src) if (src_is_cu_dev) { // source is on device - if (dest_is_cu_dev) - gkyl_cu_memcpy_async(dest->data, src->data, ncopy*src->esznc, GKYL_CU_MEMCPY_D2D, src->iostream); - else - gkyl_cu_memcpy_async(dest->data, src->data, ncopy*src->esznc, GKYL_CU_MEMCPY_D2H, src->iostream); - } - else { + if (dest_is_cu_dev) { + gkyl_cu_memcpy_async( + dest->data, src->data, ncopy * src->esznc, GKYL_CU_MEMCPY_D2D, src->iostream + ); + } else { + gkyl_cu_memcpy_async( + dest->data, src->data, ncopy * src->esznc, GKYL_CU_MEMCPY_D2H, src->iostream + ); + } + } else { // source is on host - if (dest_is_cu_dev) - gkyl_cu_memcpy_async(dest->data, src->data, ncopy*src->esznc, GKYL_CU_MEMCPY_H2D, dest->iostream); - else - memcpy(dest->data, src->data, ncopy*src->esznc); + if (dest_is_cu_dev) { + gkyl_cu_memcpy_async( + dest->data, src->data, ncopy * src->esznc, GKYL_CU_MEMCPY_H2D, dest->iostream + ); + } else { + memcpy(dest->data, src->data, ncopy * src->esznc); + } } - + return dest; } -struct gkyl_array* -gkyl_array_clone(const struct gkyl_array* src) +struct gkyl_array *gkyl_array_clone(const struct gkyl_array *src) { - struct gkyl_array* arr = gkyl_malloc(sizeof(struct gkyl_array)); + struct gkyl_array *arr = gkyl_malloc(sizeof(struct gkyl_array)); arr->type = src->type; arr->elemsz = src->elemsz; @@ -225,7 +223,7 @@ gkyl_array_clone(const struct gkyl_array* src) if (!GKYL_IS_CU_ALLOC(src->flags)) { arr->data = g_array_alloc(arr->size, arr->esznc); - memcpy(arr->data, src->data, arr->size*arr->esznc); + memcpy(arr->data, src->data, arr->size * arr->esznc); } #ifdef GKYL_HAVE_CUDA if (GKYL_IS_CU_ALLOC(src->flags)) { @@ -234,41 +232,39 @@ gkyl_array_clone(const struct gkyl_array* src) cudaStreamCreate(&arr->iostream); - arr->data = gkyl_cu_malloc(arr->size*arr->esznc); + arr->data = gkyl_cu_malloc(arr->size * arr->esznc); arr->on_dev = gkyl_cu_malloc(sizeof(struct gkyl_array)); - gkyl_cu_memcpy(arr->data, src->data, arr->size*arr->esznc, GKYL_CU_MEMCPY_D2D); + gkyl_cu_memcpy(arr->data, src->data, arr->size * arr->esznc, GKYL_CU_MEMCPY_D2D); gkyl_cu_memcpy(arr->on_dev, src->on_dev, sizeof(struct gkyl_array), GKYL_CU_MEMCPY_D2D); - gkyl_cu_memcpy(&((arr->on_dev)->data), &arr->data, sizeof(void*), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(&((arr->on_dev)->data), &arr->data, sizeof(void *), GKYL_CU_MEMCPY_H2D); } #endif - + arr->ref_count = gkyl_ref_count_init(array_free); - + return arr; } -struct gkyl_array* -gkyl_array_acquire(const struct gkyl_array* arr) +struct gkyl_array *gkyl_array_acquire(const struct gkyl_array *arr) { gkyl_ref_count_inc(&arr->ref_count); - return (struct gkyl_array*) arr; + return (struct gkyl_array *)arr; } -void -gkyl_array_release(const struct gkyl_array* arr) +void gkyl_array_release(const struct gkyl_array *arr) { - if (arr) + if (arr) { gkyl_ref_count_dec(&arr->ref_count); + } } // CUDA specific code #ifdef GKYL_HAVE_CUDA -struct gkyl_array* -gkyl_array_cu_dev_new(enum gkyl_elem_type type, size_t ncomp, size_t size) +struct gkyl_array *gkyl_array_cu_dev_new(enum gkyl_elem_type type, size_t ncomp, size_t size) { - struct gkyl_array* arr = gkyl_malloc(sizeof(struct gkyl_array)); + struct gkyl_array *arr = gkyl_malloc(sizeof(struct gkyl_array)); arr->type = type; arr->elemsz = array_elem_size[type]; @@ -279,12 +275,12 @@ gkyl_array_cu_dev_new(enum gkyl_elem_type type, size_t ncomp, size_t size) GKYL_CLEAR_ALLOC_EXTERN(arr->flags); GKYL_SET_CU_ALLOC(arr->flags); GKYL_CLEAR_ALLOC_ALIGNED(arr->flags); - - arr->esznc = arr->elemsz*arr->ncomp; + + arr->esznc = arr->elemsz * arr->ncomp; arr->ref_count = gkyl_ref_count_init(array_free); - arr->data = gkyl_cu_malloc(arr->size*arr->esznc); + arr->data = gkyl_cu_malloc(arr->size * arr->esznc); arr->nthreads = GKYL_DEFAULT_NUM_THREADS; - arr->nblocks = gkyl_int_div_up(arr->size*arr->ncomp, arr->nthreads); + arr->nblocks = gkyl_int_div_up(arr->size * arr->ncomp, arr->nthreads); cudaStreamCreate(&arr->iostream); @@ -292,28 +288,25 @@ gkyl_array_cu_dev_new(enum gkyl_elem_type type, size_t ncomp, size_t size) // so that the whole arr->on_dev struct can be passed to a device kernel arr->on_dev = gkyl_cu_malloc(sizeof(struct gkyl_array)); gkyl_cu_memcpy(arr->on_dev, arr, sizeof(struct gkyl_array), GKYL_CU_MEMCPY_H2D); - // set device-side data pointer in arr->on_dev to arr->data + // set device-side data pointer in arr->on_dev to arr->data // (which is the host-side pointer to the device data) - gkyl_cu_memcpy(&((arr->on_dev)->data), &arr->data, sizeof(void*), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(&((arr->on_dev)->data), &arr->data, sizeof(void *), GKYL_CU_MEMCPY_H2D); // Zero out array elements (not for user-defined type). if (type == GKYL_INT) { - int *data_ho = gkyl_malloc(arr->size*arr->esznc); + int *data_ho = gkyl_malloc(arr->size * arr->esznc); set_arr_dat_zero_dev(arr, data_ho); gkyl_free(data_ho); - } - else if (type == GKYL_LONG) { - long *data_ho = gkyl_malloc(arr->size*arr->esznc); + } else if (type == GKYL_LONG) { + long *data_ho = gkyl_malloc(arr->size * arr->esznc); set_arr_dat_zero_dev(arr, data_ho); gkyl_free(data_ho); - } - else if (type == GKYL_FLOAT) { - float *data_ho = gkyl_malloc(arr->size*arr->esznc); + } else if (type == GKYL_FLOAT) { + float *data_ho = gkyl_malloc(arr->size * arr->esznc); set_arr_dat_zero_dev(arr, data_ho); gkyl_free(data_ho); - } - else if (type == GKYL_DOUBLE) { - double *data_ho = gkyl_malloc(arr->size*arr->esznc); + } else if (type == GKYL_DOUBLE) { + double *data_ho = gkyl_malloc(arr->size * arr->esznc); set_arr_dat_zero_dev(arr, data_ho); gkyl_free(data_ho); } @@ -321,10 +314,9 @@ gkyl_array_cu_dev_new(enum gkyl_elem_type type, size_t ncomp, size_t size) return arr; } -struct gkyl_array* -gkyl_array_cu_host_new(enum gkyl_elem_type type, size_t ncomp, size_t size) +struct gkyl_array *gkyl_array_cu_host_new(enum gkyl_elem_type type, size_t ncomp, size_t size) { - struct gkyl_array* arr = gkyl_cu_malloc_host(sizeof(struct gkyl_array)); + struct gkyl_array *arr = gkyl_cu_malloc_host(sizeof(struct gkyl_array)); arr->type = type; arr->elemsz = array_elem_size[type]; @@ -334,35 +326,32 @@ gkyl_array_cu_host_new(enum gkyl_elem_type type, size_t ncomp, size_t size) GKYL_CLEAR_ALLOC_EXTERN(arr->flags); GKYL_CLEAR_CU_ALLOC(arr->flags); -#ifdef USE_ALIGNED_ALLOC +#ifdef USE_ALIGNED_ALLOC GKYL_SET_ALLOC_ALIGNED(arr->flags); #else GKYL_CLEAR_ALLOC_ALIGNED(arr->flags); #endif - - arr->esznc = arr->elemsz*arr->ncomp; - arr->data = gkyl_cu_malloc_host(arr->size*arr->esznc); + + arr->esznc = arr->elemsz * arr->ncomp; + arr->data = gkyl_cu_malloc_host(arr->size * arr->esznc); arr->ref_count = gkyl_ref_count_init(array_free); arr->nthreads = 1; arr->nblocks = 1; arr->on_dev = arr; // on_dev reference - + // Zero out array elements (not for user-defined type). if (type == GKYL_INT) { int *dat_p = arr->data; set_arr_dat_zero_ho(arr, dat_p); - } - else if (type == GKYL_LONG) { + } else if (type == GKYL_LONG) { long *dat_p = arr->data; set_arr_dat_zero_ho(arr, dat_p); - } - else if (type == GKYL_FLOAT) { + } else if (type == GKYL_FLOAT) { float *dat_p = arr->data; set_arr_dat_zero_ho(arr, dat_p); - } - else if (type == GKYL_DOUBLE) { + } else if (type == GKYL_DOUBLE) { double *dat_p = arr->data; set_arr_dat_zero_ho(arr, dat_p); } @@ -370,18 +359,15 @@ gkyl_array_cu_host_new(enum gkyl_elem_type type, size_t ncomp, size_t size) return arr; } - #else -struct gkyl_array* -gkyl_array_cu_dev_new(enum gkyl_elem_type type, size_t ncomp, size_t size) +struct gkyl_array *gkyl_array_cu_dev_new(enum gkyl_elem_type type, size_t ncomp, size_t size) { assert(false); return 0; } -struct gkyl_array* -gkyl_array_cu_host_new(enum gkyl_elem_type type, size_t ncomp, size_t size) +struct gkyl_array *gkyl_array_cu_host_new(enum gkyl_elem_type type, size_t ncomp, size_t size) { assert(false); return 0; diff --git a/core/zero/array_average.c b/core/zero/array_average.c index b1f01bb972..93d34502e9 100644 --- a/core/zero/array_average.c +++ b/core/zero/array_average.c @@ -6,30 +6,29 @@ #include -struct gkyl_array_average* gkyl_array_average_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, - const struct gkyl_basis *basis_avg, const struct gkyl_range *local, const struct gkyl_range *local_avg, - const struct gkyl_range *local_avg_ext, const struct gkyl_array *weight, const int *avg_dim, bool use_gpu) +struct gkyl_array_average *gkyl_array_average_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_basis *basis_avg, const struct gkyl_range *local, + const struct gkyl_range *local_avg, const struct gkyl_range *local_avg_ext, + const struct gkyl_array *weight, const int *avg_dim, bool use_gpu +) { - return gkyl_array_average_inew( - &(struct gkyl_array_average_inp) { - .grid = grid, - .basis = *basis, - .basis_avg = *basis_avg, - .local = local, - .local_avg = local_avg, - .local_avg_ext = local_avg_ext, - .weight = weight, - .avg_dim = avg_dim, - .use_gpu = use_gpu - } - ); + return gkyl_array_average_inew(&(struct gkyl_array_average_inp + ){.grid = grid, + .basis = *basis, + .basis_avg = *basis_avg, + .local = local, + .local_avg = local_avg, + .local_avg_ext = local_avg_ext, + .weight = weight, + .avg_dim = avg_dim, + .use_gpu = use_gpu}); } -struct gkyl_array_average* -gkyl_array_average_inew(const struct gkyl_array_average_inp *inp) +struct gkyl_array_average *gkyl_array_average_inew(const struct gkyl_array_average_inp *inp) { // works for p <=2 only due to the gkyl_dg_div_op_range call in advance - assert(inp->basis.poly_order <= 2); + assert(inp->basis.poly_order <= 2); // allocate space for new updater. struct gkyl_array_average *up = gkyl_malloc(sizeof(struct gkyl_array_average)); @@ -44,20 +43,21 @@ gkyl_array_average_inew(const struct gkyl_array_average_inp *inp) // set up the array of all dimensions that are conserved after the average (=0 for removed) // according to the operation input variable up->num_avg_dim = 0; - for (int d=0; d < up->ndim; ++d) { + for (int d = 0; d < up->ndim; ++d) { up->avg_dim[d] = inp->avg_dim[d]; - up->num_avg_dim += inp->avg_dim[d]; + up->num_avg_dim += inp->avg_dim[d]; } assert(up->num_avg_dim <= up->ndim); up->num_dim_remain = up->ndim - up->num_avg_dim; - for (int d=0; d < up->ndim; ++d) + for (int d = 0; d < up->ndim; ++d) { up->dim_remains[d] = 1 - inp->avg_dim[d]; + } int k = 0; - for (int d=0; d < up->ndim; ++d) { - if(up->dim_remains[d]){ + for (int d = 0; d < up->ndim; ++d) { + if (up->dim_remains[d]) { up->sub_dir[k] = d; k++; } @@ -65,14 +65,18 @@ gkyl_array_average_inew(const struct gkyl_array_average_inp *inp) // compute the inverse of the volume of the averaging space up->vol_avg_inv = 1.; - for (int d = 0; d < up->ndim; d++) - up->vol_avg_inv *= up->avg_dim[d]? inp->grid->upper[d] - inp->grid->lower[d] : 1.0; - up->vol_avg_inv = 1./up->vol_avg_inv; + for (int d = 0; d < up->ndim; d++) { + up->vol_avg_inv *= up->avg_dim[d] ? inp->grid->upper[d] - inp->grid->lower[d] : 1.0; + } + up->vol_avg_inv = 1. / up->vol_avg_inv; // compute the cell sub-dimensional volume up->subvol = 1.0; - for (int d=0; d < up->ndim; ++d) - if (up->avg_dim[d]) up->subvol *= 0.5*inp->grid->dx[d]; + for (int d = 0; d < up->ndim; ++d) { + if (up->avg_dim[d]) { + up->subvol *= 0.5 * inp->grid->dx[d]; + } + } // handle a possible weighted average up->isweighted = false; @@ -82,8 +86,10 @@ gkyl_array_average_inew(const struct gkyl_array_average_inp *inp) if (inp->weight) { up->isweighted = true; // compute the subdim integral of the weight (for volume division after integration) - up->weight_avg = up->use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, up->basis_avg.num_basis, inp->local_avg_ext->volume) - : gkyl_array_new(GKYL_DOUBLE, up->basis_avg.num_basis, inp->local_avg_ext->volume); + up->weight_avg = + up->use_gpu ? + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->basis_avg.num_basis, inp->local_avg_ext->volume) : + gkyl_array_new(GKYL_DOUBLE, up->basis_avg.num_basis, inp->local_avg_ext->volume); // create new average routine to integrate the weight struct gkyl_array_average_inp inp_integral = { .grid = inp->grid, @@ -100,37 +106,38 @@ gkyl_array_average_inew(const struct gkyl_array_average_inp *inp) gkyl_array_average_advance(int_w, inp->weight, up->weight_avg); gkyl_array_average_release(int_w); // multiply by the volume to get the integral and not the average - gkyl_array_scale(up->weight_avg,1./up->vol_avg_inv); + gkyl_array_scale(up->weight_avg, 1. / up->vol_avg_inv); // allocate memory to prepare the weak division at the end of the advance routine - up->div_mem = up->use_gpu? gkyl_dg_bin_op_mem_cu_dev_new(up->local_avg.volume, up->basis_avg.num_basis) - : gkyl_dg_bin_op_mem_new(up->local_avg.volume, up->basis_avg.num_basis); + up->div_mem = up->use_gpu ? + gkyl_dg_bin_op_mem_cu_dev_new(up->local_avg.volume, up->basis_avg.num_basis) : + gkyl_dg_bin_op_mem_new(up->local_avg.volume, up->basis_avg.num_basis); // assign the weight pointer to the input weight array up->weight = gkyl_array_acquire(inp->weight); - } - else { + } else { // assign the weight pointer to the identity weight - up->weight = up->use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, up->basis.num_basis, 1) - : gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, 1); - gkyl_array_shiftc(up->weight, pow(sqrt(2.),up->ndim), 0); + up->weight = up->use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, up->basis.num_basis, 1) : + gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, 1); + gkyl_array_shiftc(up->weight, pow(sqrt(2.), up->ndim), 0); // divide by the total volume through the subvol up->subvol *= up->vol_avg_inv; } #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { return gkyl_array_average_cu_dev_new(up); + } #endif - + // choose the kernel that performs the desired operation within the integral. gkyl_array_average_choose_kernel(up); return up; } -void gkyl_array_average_advance(const struct gkyl_array_average *up, - const struct gkyl_array * fin, struct gkyl_array *avgout) +void gkyl_array_average_advance( + const struct gkyl_array_average *up, const struct gkyl_array *fin, struct gkyl_array *avgout +) { - #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { gkyl_array_average_advance_cu(up, fin, avgout); @@ -143,7 +150,7 @@ void gkyl_array_average_advance(const struct gkyl_array_average *up, struct gkyl_range_iter iter_cmp, iter_avg; struct gkyl_range rng_cmp; // this is the complementary range, sub + cmp = full - + // we now loop on the range of the averaged array gkyl_range_iter_init(&iter_avg, &up->local_avg); while (gkyl_range_iter_next(&iter_avg)) { @@ -156,7 +163,7 @@ void gkyl_array_average_advance(const struct gkyl_array_average *up, for (int i = 0; i < up->basis.ndim; i++) { if (up->dim_remains[i]) { parent_idx[i] = iter_avg.idx[cnter]; - cnter ++; + cnter++; } } @@ -167,25 +174,28 @@ void gkyl_array_average_advance(const struct gkyl_array_average *up, long lidx_cmp = gkyl_range_idx(&rng_cmp, iter_cmp.idx); const double *fin_i = gkyl_array_cfetch(fin, lidx_cmp); - const double *win_i = up->isweighted? gkyl_array_cfetch(up->weight, lidx_cmp) : - gkyl_array_cfetch(up->weight, 0); + const double *win_i = up->isweighted ? gkyl_array_cfetch(up->weight, lidx_cmp) : + gkyl_array_cfetch(up->weight, 0); up->kernel(up->subvol, win_i, fin_i, avg_i); } } // if we provided some weight, we now divide by the integrated weight - if (up->isweighted) - gkyl_dg_div_op_range(up->div_mem, &up->basis_avg, 0, avgout, 0, avgout, 0, up->weight_avg, &up->local_avg); - + if (up->isweighted) { + gkyl_dg_div_op_range( + up->div_mem, &up->basis_avg, 0, avgout, 0, avgout, 0, up->weight_avg, &up->local_avg + ); + } } void gkyl_array_average_release(struct gkyl_array_average *up) { // release memory associated with this updater. #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { gkyl_cu_free(up->on_dev); + } #endif gkyl_array_release(up->weight); diff --git a/core/zero/array_average_cu.cu b/core/zero/array_average_cu.cu index 1440cd457b..bf475cf7b5 100644 --- a/core/zero/array_average_cu.cu +++ b/core/zero/array_average_cu.cu @@ -8,27 +8,24 @@ extern "C" { #include } -__global__ void -gkyl_array_average_set_ker_cu(struct gkyl_array_average *up) +__global__ void gkyl_array_average_set_ker_cu(struct gkyl_array_average *up) { - int ndim = up->basis.ndim, poly_order = up->basis.poly_order; + int ndim = up->basis.ndim, poly_order = up->basis.poly_order; int op = -1; // -1 shifted to start with 0 - for (int d = 0; d < ndim; d++) - op += pow(2,d) * up->avg_dim[d]; - - up->kernel = gkyl_array_average_ker_list[ndim-1].list[op].kernels[poly_order-1]; + for (int d = 0; d < ndim; d++) { + op += pow(2, d) * up->avg_dim[d]; + } + up->kernel = gkyl_array_average_ker_list[ndim - 1].list[op].kernels[poly_order - 1]; } -struct gkyl_array_average* -gkyl_array_average_cu_dev_new(struct gkyl_array_average *up) +struct gkyl_array_average *gkyl_array_average_cu_dev_new(struct gkyl_array_average *up) { struct gkyl_array *weight_ho; if (up->isweighted) { weight_ho = gkyl_array_acquire(up->weight); - } - else { + } else { weight_ho = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->weight->ncomp, up->weight->size); gkyl_array_copy(weight_ho, up->weight); } @@ -36,11 +33,12 @@ gkyl_array_average_cu_dev_new(struct gkyl_array_average *up) up->weight = weight_ho->on_dev; // Copy struct to device. - struct gkyl_array_average *up_cu = (struct gkyl_array_average*) gkyl_cu_malloc(sizeof(struct gkyl_array_average)); + struct gkyl_array_average *up_cu = + (struct gkyl_array_average *)gkyl_cu_malloc(sizeof(struct gkyl_array_average)); gkyl_cu_memcpy(up_cu, up, sizeof(struct gkyl_array_average), GKYL_CU_MEMCPY_H2D); // Set the kernel. - gkyl_array_average_set_ker_cu<<<1,1>>>(up_cu); + gkyl_array_average_set_ker_cu<<<1, 1> > >(up_cu); up->weight = weight_ho; @@ -49,16 +47,15 @@ gkyl_array_average_cu_dev_new(struct gkyl_array_average *up) return up; } -__global__ void -gkyl_array_average_advance_cu_ker(const struct gkyl_array_average *up, - const struct gkyl_array *fin, struct gkyl_array *avgout) +__global__ void gkyl_array_average_advance_cu_ker( + const struct gkyl_array_average *up, const struct gkyl_array *fin, struct gkyl_array *avgout +) { - int idx[GKYL_MAX_DIM] = {0}; + int idx[GKYL_MAX_DIM] = {0}; int idx_avg[GKYL_MAX_DIM] = {0}; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < up->local.volume; tid += blockDim.x*gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < up->local.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&up->local, tid, idx); // get the linear idx in the local range @@ -70,7 +67,7 @@ gkyl_array_average_advance_cu_ker(const struct gkyl_array_average *up, for (int i = 0; i < up->basis.ndim; i++) { if (up->dim_remains[i]) { idx_avg[cnter] = idx[i]; - cnter ++; + cnter++; } } } else { @@ -80,27 +77,31 @@ gkyl_array_average_advance_cu_ker(const struct gkyl_array_average *up, long lidx_avg = gkyl_range_idx(&up->local_avg, idx_avg); // fetch the addresses where the weight and function are - const double *fin_i = (const double*) gkyl_array_cfetch(fin, lidx); - const double *win_i = up->isweighted? (const double*) gkyl_array_cfetch(up->weight, lidx) : - (const double*) gkyl_array_cfetch(up->weight, 0); + const double *fin_i = (const double *)gkyl_array_cfetch(fin, lidx); + const double *win_i = up->isweighted ? (const double *)gkyl_array_cfetch(up->weight, lidx) : + (const double *)gkyl_array_cfetch(up->weight, 0); // fetch the address where the avg is returned - double *avg_i = (double*) gkyl_array_fetch(avgout, lidx_avg); - + double *avg_i = (double *)gkyl_array_fetch(avgout, lidx_avg); + up->kernel(up->subvol, win_i, fin_i, avg_i); } } -void gkyl_array_average_advance_cu(const struct gkyl_array_average *up, - const struct gkyl_array *fin, struct gkyl_array *avgout) +void gkyl_array_average_advance_cu( + const struct gkyl_array_average *up, const struct gkyl_array *fin, struct gkyl_array *avgout +) { - int nblocks = up->local.nblocks, nthreads = up->local.nthreads; gkyl_array_clear_range(avgout, 0.0, &up->local_avg); - gkyl_array_average_advance_cu_ker<<>>(up->on_dev, fin->on_dev, avgout->on_dev); - - if (up->isweighted) - gkyl_dg_div_op_range(up->div_mem, &up->basis_avg, 0, avgout, 0, avgout, 0, up->weight_avg, &up->local_avg); + gkyl_array_average_advance_cu_ker<< > >( + up->on_dev, fin->on_dev, avgout->on_dev + ); + if (up->isweighted) { + gkyl_dg_div_op_range( + up->div_mem, &up->basis_avg, 0, avgout, 0, avgout, 0, up->weight_avg, &up->local_avg + ); + } } diff --git a/core/zero/array_dg_reduce.c b/core/zero/array_dg_reduce.c index 0414f3d424..cdcaa625ff 100644 --- a/core/zero/array_dg_reduce.c +++ b/core/zero/array_dg_reduce.c @@ -3,24 +3,25 @@ #include #include -void -gkyl_array_dg_reducec(double *out, const struct gkyl_array *arr, int comp, - enum gkyl_array_op op, const struct gkyl_basis *basis) +void gkyl_array_dg_reducec( + double *out, const struct gkyl_array *arr, int comp, enum gkyl_array_op op, + const struct gkyl_basis *basis +) { assert(arr->type == GKYL_DOUBLE); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(arr)) { switch (op) { - case GKYL_MAX: - gkyl_array_dg_reducec_max_cu(out, arr, comp, basis); - break; - case GKYL_MIN: - gkyl_array_dg_reducec_min_cu(out, arr, comp, basis); - break; - case GKYL_SUM: - gkyl_array_dg_reducec_sum_cu(out, arr, comp, basis); - break; + case GKYL_MAX: + gkyl_array_dg_reducec_max_cu(out, arr, comp, basis); + break; + case GKYL_MIN: + gkyl_array_dg_reducec_min_cu(out, arr, comp, basis); + break; + case GKYL_SUM: + gkyl_array_dg_reducec_sum_cu(out, arr, comp, basis); + break; } return; } @@ -31,62 +32,63 @@ gkyl_array_dg_reducec(double *out, const struct gkyl_array *arr, int comp, int num_nodes = basis->num_quad; switch (op) { - case GKYL_MIN: - out[0] = DBL_MAX; - for (size_t i=0; isize; ++i) { - const double *d = gkyl_array_cfetch(arr, i); - double arr_nodal[num_nodes]; - for (int k=0; kmodal_to_quad_nodal(&d[comp*basis->num_basis], arr_nodal, k); - out[0] = fmin(out[0], arr_nodal[k]); - } + case GKYL_MIN: + out[0] = DBL_MAX; + for (size_t i = 0; i < arr->size; ++i) { + const double *d = gkyl_array_cfetch(arr, i); + double arr_nodal[num_nodes]; + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&d[comp * basis->num_basis], arr_nodal, k); + out[0] = fmin(out[0], arr_nodal[k]); } - break; - - case GKYL_MAX: - out[0] = -DBL_MAX; - for (size_t i=0; isize; ++i) { - const double *d = gkyl_array_cfetch(arr, i); - double arr_nodal[num_nodes]; - for (int k=0; kmodal_to_quad_nodal(&d[comp*basis->num_basis], arr_nodal, k); - out[0] = fmax(out[0], arr_nodal[k]); - } + } + break; + + case GKYL_MAX: + out[0] = -DBL_MAX; + for (size_t i = 0; i < arr->size; ++i) { + const double *d = gkyl_array_cfetch(arr, i); + double arr_nodal[num_nodes]; + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&d[comp * basis->num_basis], arr_nodal, k); + out[0] = fmax(out[0], arr_nodal[k]); } - break; - - case GKYL_SUM: - out[0] = 0; - for (size_t i=0; isize; ++i) { - const double *d = gkyl_array_cfetch(arr, i); - double arr_nodal[num_nodes]; - for (int k=0; kmodal_to_quad_nodal(&d[comp*basis->num_basis], arr_nodal, k); - out[0] += arr_nodal[k]; - } + } + break; + + case GKYL_SUM: + out[0] = 0; + for (size_t i = 0; i < arr->size; ++i) { + const double *d = gkyl_array_cfetch(arr, i); + double arr_nodal[num_nodes]; + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&d[comp * basis->num_basis], arr_nodal, k); + out[0] += arr_nodal[k]; } - break; + } + break; } } -void -gkyl_array_dg_reducec_range(double *out, const struct gkyl_array *arr, int comp, - enum gkyl_array_op op, const struct gkyl_basis *basis, const struct gkyl_range *range) +void gkyl_array_dg_reducec_range( + double *out, const struct gkyl_array *arr, int comp, enum gkyl_array_op op, + const struct gkyl_basis *basis, const struct gkyl_range *range +) { assert(arr->type == GKYL_DOUBLE); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(arr)) { switch (op) { - case GKYL_MAX: - gkyl_array_dg_reducec_range_max_cu(out, arr, comp, basis, range); - break; - case GKYL_MIN: - gkyl_array_dg_reducec_range_min_cu(out, arr, comp, basis, range); - break; - case GKYL_SUM: - gkyl_array_dg_reducec_range_sum_cu(out, arr, comp, basis, range); - break; + case GKYL_MAX: + gkyl_array_dg_reducec_range_max_cu(out, arr, comp, basis, range); + break; + case GKYL_MIN: + gkyl_array_dg_reducec_range_min_cu(out, arr, comp, basis, range); + break; + case GKYL_SUM: + gkyl_array_dg_reducec_range_sum_cu(out, arr, comp, basis, range); + break; } return; } @@ -100,44 +102,43 @@ gkyl_array_dg_reducec_range(double *out, const struct gkyl_array *arr, int comp, gkyl_range_iter_init(&iter, range); switch (op) { - case GKYL_MIN: - out[0] = DBL_MAX; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(range, iter.idx); - const double *d = gkyl_array_cfetch(arr, start); - double arr_nodal[num_nodes]; - for (int k=0; kmodal_to_quad_nodal(&d[comp*basis->num_basis], arr_nodal, k); - out[0] = fmin(out[0], arr_nodal[k]); - } + case GKYL_MIN: + out[0] = DBL_MAX; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(range, iter.idx); + const double *d = gkyl_array_cfetch(arr, start); + double arr_nodal[num_nodes]; + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&d[comp * basis->num_basis], arr_nodal, k); + out[0] = fmin(out[0], arr_nodal[k]); } - break; - - case GKYL_MAX: - out[0] = -DBL_MAX; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(range, iter.idx); - const double *d = gkyl_array_cfetch(arr, start); - double arr_nodal[num_nodes]; - for (int k=0; kmodal_to_quad_nodal(&d[comp*basis->num_basis], arr_nodal, k); - out[0] = fmax(out[0], arr_nodal[k]); - } + } + break; + + case GKYL_MAX: + out[0] = -DBL_MAX; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(range, iter.idx); + const double *d = gkyl_array_cfetch(arr, start); + double arr_nodal[num_nodes]; + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&d[comp * basis->num_basis], arr_nodal, k); + out[0] = fmax(out[0], arr_nodal[k]); } - break; - - case GKYL_SUM: - out[0] = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(range, iter.idx); - const double *d = gkyl_array_cfetch(arr, start); - double arr_nodal[num_nodes]; - for (int k=0; kmodal_to_quad_nodal(&d[comp*basis->num_basis], arr_nodal, k); - out[0] += arr_nodal[k]; - } + } + break; + + case GKYL_SUM: + out[0] = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(range, iter.idx); + const double *d = gkyl_array_cfetch(arr, start); + double arr_nodal[num_nodes]; + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&d[comp * basis->num_basis], arr_nodal, k); + out[0] += arr_nodal[k]; } - break; + } + break; } } - diff --git a/core/zero/array_dg_reduce_cu.cu b/core/zero/array_dg_reduce_cu.cu index e654c84746..496c14934f 100644 --- a/core/zero/array_dg_reduce_cu.cu +++ b/core/zero/array_dg_reduce_cu.cu @@ -17,40 +17,41 @@ extern "C" { // if the condition is satisfied, along the way doing the double_as_longlong and longlong_as_double // conversions needed to determine if the double (as a long long) is indeed greater than or less than // the output. Note that because this operation is done thread-by-thread we still use CUB to perform -// the reduction over CUDA blocks, but then the threads are compared thread-by-thread. -// These particular functions are adapted from (adapted by JJ on 03/14/24): +// the reduction over CUDA blocks, but then the threads are compared thread-by-thread. +// These particular functions are adapted from (adapted by JJ on 03/14/24): // https://github.com/treecode/Bonsai/blob/master/runtime/profiling/derived_atomic_functions.h -__device__ static __forceinline__ double -atomicMax_double(double *address, double val) +__device__ static __forceinline__ double atomicMax_double(double *address, double val) { unsigned long long int ret = __double_as_longlong(*address); - while(val > __longlong_as_double(ret)) - { + while (val > __longlong_as_double(ret)) { unsigned long long int old = ret; - if((ret = atomicCAS((unsigned long long int*)address, old, __double_as_longlong(val))) == old) + if ((ret = atomicCAS((unsigned long long int *)address, old, __double_as_longlong(val))) == + old) { break; + } } return __longlong_as_double(ret); } -__device__ static __forceinline__ double -atomicMin_double(double *address, double val) +__device__ static __forceinline__ double atomicMin_double(double *address, double val) { unsigned long long int ret = __double_as_longlong(*address); - while(val < __longlong_as_double(ret)) - { + while (val < __longlong_as_double(ret)) { unsigned long long int old = ret; - if((ret = atomicCAS((unsigned long long int*)address, old, __double_as_longlong(val))) == old) + if ((ret = atomicCAS((unsigned long long int *)address, old, __double_as_longlong(val))) == + old) { break; + } } return __longlong_as_double(ret); } -template -__global__ void -dg_arrayMax_blockRedAtomic_cub(const struct gkyl_array* inp, double* out, int comp, const struct gkyl_basis *basis) +template +__global__ void dg_arrayMax_blockRedAtomic_cub( + const struct gkyl_array *inp, double *out, int comp, const struct gkyl_basis *basis +) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -63,36 +64,38 @@ dg_arrayMax_blockRedAtomic_cub(const struct gkyl_array* inp, double* out, int co int num_nodes = basis->num_quad; const int num_nodes_max = 27; // MF 2025/01/15: hard coded to p=2 3x for now. - const double *inp_d = (const double*) inp->data; + const double *inp_d = (const double *)inp->data; out[0] = -DBL_MAX; double f = -DBL_MAX; if (linc < nCells) { double arr_nodal[num_nodes_max]; - for (int k=0; kmodal_to_quad_nodal(&inp_d[linc*nComp+comp*basis->num_basis], arr_nodal, k); + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&inp_d[linc * nComp + comp * basis->num_basis], arr_nodal, k); f = fmax(f, arr_nodal[k]); } } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 ::cuda::maximum() #else cub::Max() #endif - ); + ); if (threadIdx.x < BLOCKSIZE) { atomicMax_double(&out[0], bResult); } } -template -__global__ void -dg_arrayMax_range_blockRedAtomic_cub(const struct gkyl_array* inp, double* out, - int comp, const struct gkyl_basis *basis, struct gkyl_range range) +template +__global__ void dg_arrayMax_range_blockRedAtomic_cub( + const struct gkyl_array *inp, double *out, int comp, const struct gkyl_basis *basis, + struct gkyl_range range +) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -107,56 +110,62 @@ dg_arrayMax_range_blockRedAtomic_cub(const struct gkyl_array* inp, double* out, int idx[GKYL_MAX_DIM]; gkyl_sub_range_inv_idx(&range, linc, idx); long start = gkyl_range_idx(&range, idx); - const double* inp_d = (const double*) gkyl_array_cfetch(inp, start); + const double *inp_d = (const double *)gkyl_array_cfetch(inp, start); out[0] = -DBL_MAX; double f = -DBL_MAX; if (linc < nCells) { double arr_nodal[num_nodes_max]; - for (int k=0; kmodal_to_quad_nodal(&inp_d[comp*basis->num_basis], arr_nodal, k); + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&inp_d[comp * basis->num_basis], arr_nodal, k); f = fmax(f, arr_nodal[k]); } } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 ::cuda::maximum() #else cub::Max() #endif - ); + ); if (threadIdx.x < BLOCKSIZE) { atomicMax_double(&out[0], bResult); } } -void -gkyl_array_dg_reducec_max_cu(double *out_d, const struct gkyl_array* inp, int comp, const struct gkyl_basis *basis) +void gkyl_array_dg_reducec_max_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis +) { - const int nthreads = GKYL_DEFAULT_NUM_THREADS; + const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(inp->size, nthreads); - dg_arrayMax_blockRedAtomic_cub<<>>(inp->on_dev, out_d, comp, basis); + dg_arrayMax_blockRedAtomic_cub + << > >(inp->on_dev, out_d, comp, basis); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } -void -gkyl_array_dg_reducec_range_max_cu(double *out_d, const struct gkyl_array* inp, - int comp, const struct gkyl_basis *basis, const struct gkyl_range *range) +void gkyl_array_dg_reducec_range_max_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis, + const struct gkyl_range *range +) { - const int nthreads = GKYL_DEFAULT_NUM_THREADS; + const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(range->volume, nthreads); - dg_arrayMax_range_blockRedAtomic_cub<<>>(inp->on_dev, out_d, comp, basis, *range); + dg_arrayMax_range_blockRedAtomic_cub + << > >(inp->on_dev, out_d, comp, basis, *range); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } -template -__global__ void -dg_arrayMin_blockRedAtomic_cub(const struct gkyl_array* inp, double* out, int comp, const struct gkyl_basis *basis) +template +__global__ void dg_arrayMin_blockRedAtomic_cub( + const struct gkyl_array *inp, double *out, int comp, const struct gkyl_basis *basis +) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -169,36 +178,38 @@ dg_arrayMin_blockRedAtomic_cub(const struct gkyl_array* inp, double* out, int co int num_nodes = basis->num_quad; const int num_nodes_max = 27; // MF 2025/01/15: hard coded to p=2 3x for now. - const double *inp_d = (const double*) inp->data; + const double *inp_d = (const double *)inp->data; out[0] = DBL_MAX; double f = DBL_MAX; if (linc < nCells) { double arr_nodal[num_nodes_max]; - for (int k=0; kmodal_to_quad_nodal(&inp_d[linc*nComp+comp*basis->num_basis], arr_nodal, k); + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&inp_d[linc * nComp + comp * basis->num_basis], arr_nodal, k); f = fmin(f, arr_nodal[k]); } } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 ::cuda::minimum() #else cub::Min() #endif - ); + ); if (threadIdx.x < BLOCKSIZE) { atomicMin_double(&out[0], bResult); } } -template -__global__ void -dg_arrayMin_range_blockRedAtomic_cub(const struct gkyl_array* inp, double* out, - int comp, const struct gkyl_basis *basis, struct gkyl_range range) +template +__global__ void dg_arrayMin_range_blockRedAtomic_cub( + const struct gkyl_array *inp, double *out, int comp, const struct gkyl_basis *basis, + struct gkyl_range range +) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -213,56 +224,62 @@ dg_arrayMin_range_blockRedAtomic_cub(const struct gkyl_array* inp, double* out, int idx[GKYL_MAX_DIM]; gkyl_sub_range_inv_idx(&range, linc, idx); long start = gkyl_range_idx(&range, idx); - const double* inp_d = (const double*) gkyl_array_cfetch(inp, start); + const double *inp_d = (const double *)gkyl_array_cfetch(inp, start); out[0] = DBL_MAX; double f = DBL_MAX; if (linc < nCells) { double arr_nodal[num_nodes_max]; - for (int k=0; kmodal_to_quad_nodal(&inp_d[comp*basis->num_basis], arr_nodal, k); + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&inp_d[comp * basis->num_basis], arr_nodal, k); f = fmin(f, arr_nodal[k]); } } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 ::cuda::minimum() #else cub::Min() #endif - ); + ); if (threadIdx.x < BLOCKSIZE) { atomicMin_double(&out[0], bResult); } } -void -gkyl_array_dg_reducec_min_cu(double *out_d, const struct gkyl_array* inp, int comp, const struct gkyl_basis *basis) +void gkyl_array_dg_reducec_min_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis +) { - const int nthreads = GKYL_DEFAULT_NUM_THREADS; + const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(inp->size, nthreads); - dg_arrayMin_blockRedAtomic_cub<<>>(inp->on_dev, out_d, comp, basis); + dg_arrayMin_blockRedAtomic_cub + << > >(inp->on_dev, out_d, comp, basis); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } -void -gkyl_array_dg_reducec_range_min_cu(double *out_d, const struct gkyl_array* inp, - int comp, const struct gkyl_basis *basis, const struct gkyl_range *range) +void gkyl_array_dg_reducec_range_min_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis, + const struct gkyl_range *range +) { - const int nthreads = GKYL_DEFAULT_NUM_THREADS; + const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(range->volume, nthreads); - dg_arrayMin_range_blockRedAtomic_cub<<>>(inp->on_dev, out_d, comp, basis, *range); + dg_arrayMin_range_blockRedAtomic_cub + << > >(inp->on_dev, out_d, comp, basis, *range); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } -template -__global__ void -dg_arraySum_blockRedAtomic_cub(const struct gkyl_array* inp, double* out, int comp, const struct gkyl_basis *basis) +template +__global__ void dg_arraySum_blockRedAtomic_cub( + const struct gkyl_array *inp, double *out, int comp, const struct gkyl_basis *basis +) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -275,35 +292,37 @@ dg_arraySum_blockRedAtomic_cub(const struct gkyl_array* inp, double* out, int co int num_nodes = basis->num_quad; const int num_nodes_max = 27; // MF 2025/01/15: hard coded to p=2 3x for now. - const double *inp_d = (const double*) inp->data; + const double *inp_d = (const double *)inp->data; double f = 0; if (linc < nCells) { double arr_nodal[num_nodes_max]; - for (int k=0; kmodal_to_quad_nodal(&inp_d[linc*nComp+comp*basis->num_basis], arr_nodal, k); + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&inp_d[linc * nComp + comp * basis->num_basis], arr_nodal, k); f += arr_nodal[k]; } } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 ::cuda::std::plus() #else cub::Sum() #endif - ); + ); if (threadIdx.x == 0) { atomicAdd(&out[0], bResult); } } -template -__global__ void -dg_arraySum_range_blockRedAtomic_cub(const struct gkyl_array* inp, double* out, -int comp, const struct gkyl_basis *basis, struct gkyl_range range) +template +__global__ void dg_arraySum_range_blockRedAtomic_cub( + const struct gkyl_array *inp, double *out, int comp, const struct gkyl_basis *basis, + struct gkyl_range range +) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -318,51 +337,55 @@ int comp, const struct gkyl_basis *basis, struct gkyl_range range) int idx[GKYL_MAX_DIM]; gkyl_sub_range_inv_idx(&range, linc, idx); long start = gkyl_range_idx(&range, idx); - const double* inp_d = (const double*) gkyl_array_cfetch(inp, start); + const double *inp_d = (const double *)gkyl_array_cfetch(inp, start); double f = 0; if (linc < nCells) { double arr_nodal[num_nodes_max]; - for (int k=0; kmodal_to_quad_nodal(&inp_d[comp*basis->num_basis], arr_nodal, k); + for (int k = 0; k < num_nodes; ++k) { + basis->modal_to_quad_nodal(&inp_d[comp * basis->num_basis], arr_nodal, k); f += arr_nodal[k]; } } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 ::cuda::std::plus() #else cub::Sum() #endif - ); + ); if (threadIdx.x == 0) { atomicAdd(&out[0], bResult); } } -void -gkyl_array_dg_reducec_sum_cu(double *out_d, const struct gkyl_array* inp, int comp, const struct gkyl_basis *basis) +void gkyl_array_dg_reducec_sum_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis +) { gkyl_cu_memset(out_d, 0, sizeof(double)); - const int nthreads = GKYL_DEFAULT_NUM_THREADS; + const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(inp->size, nthreads); - dg_arraySum_blockRedAtomic_cub<<>>(inp->on_dev, out_d, comp, basis); + dg_arraySum_blockRedAtomic_cub + << > >(inp->on_dev, out_d, comp, basis); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } -void -gkyl_array_dg_reducec_range_sum_cu(double *out_d, const struct gkyl_array* inp, - int comp, const struct gkyl_basis *basis, const struct gkyl_range *range) +void gkyl_array_dg_reducec_range_sum_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis, + const struct gkyl_range *range +) { gkyl_cu_memset(out_d, 0, sizeof(double)); - const int nthreads = GKYL_DEFAULT_NUM_THREADS; + const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(range->volume, nthreads); - dg_arraySum_range_blockRedAtomic_cub<<>>(inp->on_dev, out_d, comp, basis, *range); + dg_arraySum_range_blockRedAtomic_cub + << > >(inp->on_dev, out_d, comp, basis, *range); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } - diff --git a/core/zero/array_integrate.c b/core/zero/array_integrate.c index 5fcf5eb452..30de58fd11 100644 --- a/core/zero/array_integrate.c +++ b/core/zero/array_integrate.c @@ -3,13 +3,15 @@ #include #include -struct gkyl_array_integrate* -gkyl_array_integrate_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, - int num_comp, enum gkyl_array_integrate_op op, bool use_gpu) +struct gkyl_array_integrate *gkyl_array_integrate_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, int num_comp, + enum gkyl_array_integrate_op op, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) + if (use_gpu) { return gkyl_array_integrate_cu_dev_new(grid, basis, num_comp, op); + } #endif // Allocate space for new updater. @@ -19,14 +21,17 @@ gkyl_array_integrate_new(const struct gkyl_rect_grid *grid, const struct gkyl_ba up->num_basis = basis->num_basis; up->num_comp = num_comp; up->use_gpu = use_gpu; - for (int d=0; dndim; ++d) up->dxSq[d] = grid->dx[d]*grid->dx[d]; + for (int d = 0; d < grid->ndim; ++d) { + up->dxSq[d] = grid->dx[d] * grid->dx[d]; + } assert(basis->poly_order > 0); // Need to check normalization for p=0. int ndim = basis->ndim; up->vol = 1.0; - for (unsigned d=0; dvol *= grid->dx[d]/2.0; + for (unsigned d = 0; d < ndim; ++d) { + up->vol *= grid->dx[d] / 2.0; + } // Choose the kernel that performs the desired operation within the integral. gkyl_array_integrate_choose_kernel(op, basis, up); @@ -34,9 +39,11 @@ gkyl_array_integrate_new(const struct gkyl_rect_grid *grid, const struct gkyl_ba return up; } -void gkyl_array_integrate_advance(gkyl_array_integrate *up, const struct gkyl_array *fin, - double factor, const struct gkyl_array *weight, const struct gkyl_range *range, - const struct gkyl_range *weight_range, double *out) +void gkyl_array_integrate_advance( + gkyl_array_integrate *up, const struct gkyl_array *fin, double factor, + const struct gkyl_array *weight, const struct gkyl_range *range, + const struct gkyl_range *weight_range, double *out +) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { @@ -46,20 +53,25 @@ void gkyl_array_integrate_advance(gkyl_array_integrate *up, const struct gkyl_ar #endif int widx[GKYL_MAX_DIM]; - for (int d=0; dnum_comp; k++) out[k] = 0; + for (int k = 0; k < up->num_comp; k++) { + out[k] = 0; + } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, range); while (gkyl_range_iter_next(&iter)) { - long linidx = gkyl_range_idx(range, iter.idx); const double *fin_d = gkyl_array_cfetch(fin, linidx); const double *wei_d = 0; if (weight) { - for (int d=0; dndim; d++) widx[d] = iter.idx[d]; + for (int d = 0; d < weight_range->ndim; d++) { + widx[d] = iter.idx[d]; + } long linidx_w = gkyl_range_idx(weight_range, widx); wei_d = gkyl_array_cfetch(weight, linidx_w); } @@ -67,15 +79,18 @@ void gkyl_array_integrate_advance(gkyl_array_integrate *up, const struct gkyl_ar up->kernel(up->dxSq, up->vol, up->num_comp, up->num_basis, wei_d, fin_d, out); } - for (int k=0; knum_comp; k++) out[k] *= factor; + for (int k = 0; k < up->num_comp; k++) { + out[k] *= factor; + } } void gkyl_array_integrate_release(gkyl_array_integrate *up) { // Release memory associated with this updater. #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { gkyl_cu_free(up->on_dev); + } #endif gkyl_free(up); } diff --git a/core/zero/array_integrate_cu.cu b/core/zero/array_integrate_cu.cu index 24db1df3d7..9697b3daed 100644 --- a/core/zero/array_integrate_cu.cu +++ b/core/zero/array_integrate_cu.cu @@ -10,65 +10,68 @@ extern "C" { #include } -__global__ static void -gkyl_array_integrate_set_ker_cu(struct gkyl_array_integrate *up, enum gkyl_array_integrate_op op, struct gkyl_basis basis) +__global__ static void gkyl_array_integrate_set_ker_cu( + struct gkyl_array_integrate *up, enum gkyl_array_integrate_op op, struct gkyl_basis basis +) { int ndim = basis.ndim, poly_order = basis.poly_order; if (op == GKYL_ARRAY_INTEGRATE_OP_NONE) { - up->kernel = gkyl_array_integrate_none_ker_list_ser[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_ABS) { - up->kernel = gkyl_array_integrate_abs_ker_list_ser[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_SQ) { - up->kernel = gkyl_array_integrate_sq_ker_list_ser[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_SQ_WEIGHTED) { - if (basis.b_type == GKYL_BASIS_MODAL_SERENDIPITY) - up->kernel = gkyl_array_integrate_sq_weighted_ker_list_ser[ndim-1].kernels[poly_order-1]; - else if (basis.b_type == GKYL_BASIS_MODAL_GKHYBRID) - up->kernel = gkyl_array_integrate_sq_weighted_ker_list_gkhyb[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ) { - up->kernel = gkyl_array_integrate_gradsq_ker_list[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_GRADPERP_SQ) { - up->kernel = gkyl_array_integrate_gradperpsq_ker_list[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_EPS_GRADPERP_SQ) { - up->kernel = gkyl_array_integrate_epsgradperpsq_ker_list[ndim-1].kernels[poly_order-1]; + up->kernel = gkyl_array_integrate_none_ker_list_ser[ndim - 1].kernels[poly_order - 1]; + } else if (op == GKYL_ARRAY_INTEGRATE_OP_ABS) { + up->kernel = gkyl_array_integrate_abs_ker_list_ser[ndim - 1].kernels[poly_order - 1]; + } else if (op == GKYL_ARRAY_INTEGRATE_OP_SQ) { + up->kernel = gkyl_array_integrate_sq_ker_list_ser[ndim - 1].kernels[poly_order - 1]; + } else if (op == GKYL_ARRAY_INTEGRATE_OP_SQ_WEIGHTED) { + if (basis.b_type == GKYL_BASIS_MODAL_SERENDIPITY) { + up->kernel = gkyl_array_integrate_sq_weighted_ker_list_ser[ndim - 1].kernels[poly_order - 1]; + } else if (basis.b_type == GKYL_BASIS_MODAL_GKHYBRID) { + up->kernel = + gkyl_array_integrate_sq_weighted_ker_list_gkhyb[ndim - 1].kernels[poly_order - 1]; + } + } else if (op == GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ) { + up->kernel = gkyl_array_integrate_gradsq_ker_list[ndim - 1].kernels[poly_order - 1]; + } else if (op == GKYL_ARRAY_INTEGRATE_OP_GRADPERP_SQ) { + up->kernel = gkyl_array_integrate_gradperpsq_ker_list[ndim - 1].kernels[poly_order - 1]; + } else if (op == GKYL_ARRAY_INTEGRATE_OP_EPS_GRADPERP_SQ) { + up->kernel = gkyl_array_integrate_epsgradperpsq_ker_list[ndim - 1].kernels[poly_order - 1]; } else { assert(false); } } -struct gkyl_array_integrate* -gkyl_array_integrate_cu_dev_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, - int num_comp, enum gkyl_array_integrate_op op) +struct gkyl_array_integrate *gkyl_array_integrate_cu_dev_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, int num_comp, + enum gkyl_array_integrate_op op +) { // Allocate space for new updater. - struct gkyl_array_integrate *up = (struct gkyl_array_integrate*) gkyl_malloc(sizeof(struct gkyl_array_integrate)); + struct gkyl_array_integrate *up = + (struct gkyl_array_integrate *)gkyl_malloc(sizeof(struct gkyl_array_integrate)); up->op = op; up->num_basis = basis->num_basis; up->num_comp = num_comp; up->use_gpu = true; - for (int d=0; dndim; ++d) up->dxSq[d] = grid->dx[d]*grid->dx[d]; + for (int d = 0; d < grid->ndim; ++d) { + up->dxSq[d] = grid->dx[d] * grid->dx[d]; + } assert(basis->poly_order > 0); // Need to check normalization for p=0. int ndim = basis->ndim; up->vol = 1.0; - for (unsigned d=0; dvol *= grid->dx[d]/2.0; + for (unsigned d = 0; d < ndim; ++d) { + up->vol *= grid->dx[d] / 2.0; + } // Copy struct to device. - struct gkyl_array_integrate *up_cu = (struct gkyl_array_integrate*) gkyl_cu_malloc(sizeof(struct gkyl_array_integrate)); + struct gkyl_array_integrate *up_cu = + (struct gkyl_array_integrate *)gkyl_cu_malloc(sizeof(struct gkyl_array_integrate)); gkyl_cu_memcpy(up_cu, up, sizeof(struct gkyl_array_integrate), GKYL_CU_MEMCPY_H2D); // Set the kernel. - gkyl_array_integrate_set_ker_cu<<<1,1>>>(up_cu, op, *basis); + gkyl_array_integrate_set_ker_cu<<<1, 1> > >(up_cu, op, *basis); up->on_dev = up_cu; @@ -76,11 +79,13 @@ gkyl_array_integrate_cu_dev_new(const struct gkyl_rect_grid *grid, const struct } template -__global__ void -array_integrate_blockRedAtomic_cub(struct gkyl_array_integrate *up, const struct gkyl_array *inp, - double factor, const struct gkyl_array *weight, const struct gkyl_range range, struct gkyl_range weight_range, double *out) +__global__ void array_integrate_blockRedAtomic_cub( + struct gkyl_array_integrate *up, const struct gkyl_array *inp, double factor, + const struct gkyl_array *weight, const struct gkyl_range range, struct gkyl_range weight_range, + double *out +) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -93,42 +98,50 @@ array_integrate_blockRedAtomic_cub(struct gkyl_array_integrate *up, const struct long start = gkyl_range_idx(&range, idx); double outLocal[10]; // Set to max of 10 (e.g. heat flux tensor). - for (unsigned int k=0; knum_comp; ++k) + for (unsigned int k = 0; k < up->num_comp; ++k) { outLocal[k] = 0.0; + } // Integrate in this cell if (linc < range.volume) { - const double *fptr = (const double*) gkyl_array_cfetch(inp, start); + const double *fptr = (const double *)gkyl_array_cfetch(inp, start); const double *wptr = 0; if (weight) { int widx[GKYL_MAX_DIM]; - for (int d=0; dkernel(up->dxSq, up->vol*factor, up->num_comp, up->num_basis, wptr, fptr, outLocal); + up->kernel(up->dxSq, up->vol * factor, up->num_comp, up->num_basis, wptr, fptr, outLocal); } for (size_t k = 0; k < up->num_comp; ++k) { double bResult = 0; - bResult = BlockReduceT(temp).Reduce(outLocal[k], + bResult = BlockReduceT(temp).Reduce( + outLocal[k], #if CUDART_VERSION > 12090 - ::cuda::std::plus() + ::cuda::std::plus() #else - cub::Sum() + cub::Sum() #endif ); - if (threadIdx.x == 0) + if (threadIdx.x == 0) { atomicAdd(&out[k], bResult); + } } } -void gkyl_array_integrate_advance_cu(gkyl_array_integrate *up, const struct gkyl_array *fin, - double factor, const struct gkyl_array *weight, const struct gkyl_range *range, const struct gkyl_range *weight_range, double *out) +void gkyl_array_integrate_advance_cu( + gkyl_array_integrate *up, const struct gkyl_array *fin, double factor, + const struct gkyl_array *weight, const struct gkyl_range *range, + const struct gkyl_range *weight_range, double *out +) { - gkyl_cu_memset(out, 0, up->num_comp*sizeof(double)); + gkyl_cu_memset(out, 0, up->num_comp * sizeof(double)); const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(range->volume, nthreads); @@ -138,8 +151,9 @@ void gkyl_array_integrate_advance_cu(gkyl_array_integrate *up, const struct gkyl weight_on_dev = weight->on_dev; weight_range_copy = *weight_range; } - array_integrate_blockRedAtomic_cub<<>>(up->on_dev, fin->on_dev, factor, - weight_on_dev, *range, weight_range_copy, out); + array_integrate_blockRedAtomic_cub<< > >( + up->on_dev, fin->on_dev, factor, weight_on_dev, *range, weight_range_copy, out + ); // device synchronize required because out may be host pinned memory cudaDeviceSynchronize(); } diff --git a/core/zero/array_ops.c b/core/zero/array_ops.c index 7c5dccb47b..44450bf0dd 100644 --- a/core/zero/array_ops.c +++ b/core/zero/array_ops.c @@ -10,170 +10,203 @@ #include #include -bool -gkyl_array_copy_func_is_cu_dev(const struct gkyl_array_copy_func *bc) +bool gkyl_array_copy_func_is_cu_dev(const struct gkyl_array_copy_func *bc) { return GKYL_IS_CU_ALLOC(bc->flags); } -struct gkyl_array* -gkyl_array_clear(struct gkyl_array* out, double val) +struct gkyl_array *gkyl_array_clear(struct gkyl_array *out, double val) { assert(out->type == GKYL_DOUBLE); #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(out)) {gkyl_array_clear_cu(out, val); return out; } + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_clear_cu(out, val); + return out; + } #endif double *out_d = out->data; - for (size_t i=0; itype == GKYL_DOUBLE); assert(out->size == inp->size && out->elemsz == inp->elemsz); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out) && gkyl_array_is_cu_dev(inp)) { gkyl_array_accumulate_cu(out, a, inp); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out) && gkyl_array_is_cu_dev(inp)) { + gkyl_array_accumulate_cu(out, a, inp); + return out; + } #endif double *out_d = out->data; const double *inp_d = inp->data; - for (size_t i=0; itype == GKYL_DOUBLE); assert(out->size == inp->size); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out) && gkyl_array_is_cu_dev(inp)) { gkyl_array_accumulate_offset_cu(out, a, inp, coff); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out) && gkyl_array_is_cu_dev(inp)) { + gkyl_array_accumulate_offset_cu(out, a, inp, coff); + return out; + } #endif double *out_d = out->data; const double *inp_d = inp->data; if (NCOM(out) < NCOM(inp)) { // Interpret offset as offset in input components. - for (size_t i=0; isize; ++i) - for (size_t c=0; csize; ++i) { + for (size_t c = 0; c < NCOM(out); ++c) { + out_d[i * NCOM(out) + c] += a * inp_d[i * NCOM(inp) + c + coff]; + } + } } else { // Interpret offset as offset in output components. - for (size_t i=0; isize; ++i) - for (size_t c=0; csize; ++i) { + for (size_t c = 0; c < NCOM(inp); ++c) { + out_d[i * NCOM(out) + c + coff] += a * inp_d[i * NCOM(inp) + c]; + } + } } return out; } -struct gkyl_array* -gkyl_array_set(struct gkyl_array* out, double a, - const struct gkyl_array* inp) +struct gkyl_array *gkyl_array_set(struct gkyl_array *out, double a, const struct gkyl_array *inp) { assert(out->type == GKYL_DOUBLE); assert(out->size == inp->size && out->elemsz == inp->elemsz); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out)) { gkyl_array_set_cu(out, a, inp); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_set_cu(out, a, inp); + return out; + } #endif double *out_d = out->data; const double *inp_d = inp->data; - for (size_t i=0; itype == GKYL_DOUBLE); assert(out->size == inp->size); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out)) { gkyl_array_set_offset_cu(out, a, inp, coff); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_set_offset_cu(out, a, inp, coff); + return out; + } #endif double *out_d = out->data; const double *inp_d = inp->data; if (NCOM(out) < NCOM(inp)) { // Interpret offset as offset in input components. - for (size_t i=0; isize; ++i) - for (size_t c=0; csize; ++i) { + for (size_t c = 0; c < NCOM(out); ++c) { + out_d[i * NCOM(out) + c] = a * inp_d[i * NCOM(inp) + c + coff]; + } + } } else { // Interpret offset as offset in output components. - for (size_t i=0; isize; ++i) - for (size_t c=0; csize; ++i) { + for (size_t c = 0; c < NCOM(inp); ++c) { + out_d[i * NCOM(out) + c + coff] = a * inp_d[i * NCOM(inp) + c]; + } + } } return out; } -struct gkyl_array* -gkyl_array_scale(struct gkyl_array* out, double a) +struct gkyl_array *gkyl_array_scale(struct gkyl_array *out, double a) { #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(out)) { gkyl_array_scale_cu(out, a); return out; } + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_scale_cu(out, a); + return out; + } #endif return gkyl_array_set(out, a, out); } -struct gkyl_array* -gkyl_array_scale_by_cell(struct gkyl_array* out, const struct gkyl_array* a) +struct gkyl_array *gkyl_array_scale_by_cell(struct gkyl_array *out, const struct gkyl_array *a) { assert(out->type == GKYL_DOUBLE); assert(out->size == a->size && NCOM(a) == 1); #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(out)) { gkyl_array_scale_by_cell_cu(out, a); return out; } + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_scale_by_cell_cu(out, a); + return out; + } #endif double *out_d = out->data; const double *a_d = a->data; - for (size_t i=0; isize; ++i) - for (size_t c=0; csize; ++i) { + for (size_t c = 0; c < NCOM(out); ++c) { + out_d[i * NCOM(out) + c] = a_d[i] * out_d[i * NCOM(out) + c]; + } + } return out; } -struct gkyl_array* -gkyl_array_min_by_cell(struct gkyl_array* out, const struct gkyl_array *inp, double a) +struct gkyl_array * +gkyl_array_min_by_cell(struct gkyl_array *out, const struct gkyl_array *inp, double a) { assert(out->type == GKYL_DOUBLE); #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(out)) { gkyl_array_min_by_cell_cu(out, inp, a); return out; } + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_min_by_cell_cu(out, inp, a); + return out; + } #endif double *out_d = out->data; const double *inp_d = inp->data; - for (size_t i=0; itype == GKYL_DOUBLE); #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(out)) { gkyl_array_min_by_cell_range_cu(out, inp, a, range); return out; } + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_min_by_cell_range_cu(out, inp, a, range); + return out; + } #endif struct gkyl_range_iter iter; @@ -183,67 +216,81 @@ gkyl_array_min_by_cell_range(struct gkyl_array* out, const struct gkyl_array *in long start = gkyl_range_idx(range, iter.idx); double *out_d = gkyl_array_fetch(out, start); const double *inp_d = gkyl_array_cfetch(inp, start); - for (size_t c=0; ctype == GKYL_DOUBLE); assert(out->size == a->size && NCOM(a) == 1); #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(out)) { gkyl_array_divide_by_cell_cu(out, a); return out; } + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_divide_by_cell_cu(out, a); + return out; + } #endif double *out_d = out->data; const double *a_d = a->data; - for (size_t i=0; isize; ++i) - for (size_t c=0; csize; ++i) { + for (size_t c = 0; c < NCOM(out); ++c) { + out_d[i * NCOM(out) + c] = out_d[i * NCOM(out) + c] / a_d[i]; + } + } return out; } -struct gkyl_array* -gkyl_array_invert_by_cell(struct gkyl_array* out, const struct gkyl_array *inp) +struct gkyl_array *gkyl_array_invert_by_cell(struct gkyl_array *out, const struct gkyl_array *inp) { assert(out->type == GKYL_DOUBLE); #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(out)) { gkyl_array_invert_by_cell_cu(out, inp); return out; } + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_invert_by_cell_cu(out, inp); + return out; + } #endif double *out_d = out->data; const double *inp_d = inp->data; - for (size_t i=0; itype == GKYL_DOUBLE); assert(k < NCOM(out)); #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(out)) { gkyl_array_shiftc_cu(out, a, k); return out; } + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_shiftc_cu(out, a, k); + return out; + } #endif double *out_d = out->data; - for (size_t i=0; isize; ++i) - out_d[i*NCOM(out)+k] = a+out_d[i*NCOM(out)+k]; + for (size_t i = 0; i < out->size; ++i) { + out_d[i * NCOM(out) + k] = a + out_d[i * NCOM(out) + k]; + } return out; } // range based methods -struct gkyl_array* +struct gkyl_array * gkyl_array_clear_range(struct gkyl_array *out, double val, const struct gkyl_range *range) { assert(out->type == GKYL_DOUBLE); #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(out)) { gkyl_array_clear_range_cu(out, val, range); return out; } + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_clear_range_cu(out, val, range); + return out; + } #endif long n = NCOM(out); @@ -259,44 +306,50 @@ gkyl_array_clear_range(struct gkyl_array *out, double val, const struct gkyl_ran return out; } -struct gkyl_array* -gkyl_array_accumulate_range(struct gkyl_array *out, - double a, const struct gkyl_array *inp, const struct gkyl_range *range) +struct gkyl_array *gkyl_array_accumulate_range( + struct gkyl_array *out, double a, const struct gkyl_array *inp, const struct gkyl_range *range +) { assert(out->type == GKYL_DOUBLE); assert(out->size == inp->size); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out)) { gkyl_array_accumulate_range_cu(out, a, inp, range); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_accumulate_range_cu(out, a, inp, range); + return out; + } #endif long outnc = NCOM(out), inpnc = NCOM(inp); - long n = outnctype == GKYL_DOUBLE); assert(out->size == inp->size); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out)) { gkyl_array_accumulate_offset_range_cu(out, a, inp, coff, range); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_accumulate_offset_range_cu(out, a, inp, coff, range); + return out; + } #endif long outnc = NCOM(out), inpnc = NCOM(inp); @@ -318,57 +371,63 @@ gkyl_array_accumulate_offset_range(struct gkyl_array *out, long start = gkyl_range_idx(range, iter.idx); double *out_d = gkyl_array_fetch(out, start); const double *inp_d = gkyl_array_cfetch(inp, start); - array_acc1(n, out_d+outoff, a, inp_d+inoff); + array_acc1(n, out_d + outoff, a, inp_d + inoff); } return out; } -struct gkyl_array* -gkyl_array_set_range(struct gkyl_array *out, - double a, const struct gkyl_array *inp, const struct gkyl_range *range) +struct gkyl_array *gkyl_array_set_range( + struct gkyl_array *out, double a, const struct gkyl_array *inp, const struct gkyl_range *range +) { assert(out->type == GKYL_DOUBLE && inp->type == GKYL_DOUBLE); assert(out->size == inp->size); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out)) { gkyl_array_set_range_cu(out, a, inp, range); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_set_range_cu(out, a, inp, range); + return out; + } #endif long outnc = NCOM(out), inpnc = NCOM(inp); - long n = outncelemsz == inp->elemsz); assert((inp_range->volume < 1) || (out_range->volume == inp_range->volume)); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out)) { gkyl_array_set_range_to_range_cu(out, a, inp, out_range, inp_range); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_set_range_to_range_cu(out, a, inp, out_range, inp_range); + return out; + } #endif long outnc = NCOM(out), inpnc = NCOM(inp); - long n = outncndim; ++d){ + for (int d = 0; d < out_range->ndim; ++d) { iloLocal_out[d] = out_range->lower[d]; iloLocal_inp[d] = inp_range->lower[d]; } @@ -377,28 +436,32 @@ gkyl_array_set_range_to_range(struct gkyl_array *out, double a, struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, inp_range); while (gkyl_range_iter_next(&iter)) { - for (int d=0; dndim; ++d) + for (int d = 0; d < out_range->ndim; ++d) { idx_out[d] = iloLocal_out[d] + (iter.idx[d] - iloLocal_inp[d]); + } long linidx_inp = gkyl_range_idx(inp_range, iter.idx); long linidx_out = gkyl_range_idx(out_range, idx_out); - array_set1(n, - gkyl_array_fetch(out, linidx_out), a, gkyl_array_cfetch(inp, linidx_inp)); + array_set1(n, gkyl_array_fetch(out, linidx_out), a, gkyl_array_cfetch(inp, linidx_inp)); } return out; } -struct gkyl_array* -gkyl_array_set_offset_range(struct gkyl_array *out, - double a, const struct gkyl_array *inp, int coff, const struct gkyl_range *range) +struct gkyl_array *gkyl_array_set_offset_range( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff, + const struct gkyl_range *range +) { assert(out->type == GKYL_DOUBLE && inp->type == GKYL_DOUBLE); assert(out->size == inp->size); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out)) { gkyl_array_set_offset_range_cu(out, a, inp, coff, range); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_set_offset_range_cu(out, a, inp, coff, range); + return out; + } #endif long outnc = NCOM(out), inpnc = NCOM(inp); @@ -420,30 +483,35 @@ gkyl_array_set_offset_range(struct gkyl_array *out, long start = gkyl_range_idx(range, iter.idx); double *out_d = gkyl_array_fetch(out, start); const double *inp_d = gkyl_array_cfetch(inp, start); - array_set1(n, out_d+outoff, a, inp_d+inoff); + array_set1(n, out_d + outoff, a, inp_d + inoff); } return out; } -struct gkyl_array* -gkyl_array_scale_range(struct gkyl_array *out, - double a, const struct gkyl_range *range) +struct gkyl_array * +gkyl_array_scale_range(struct gkyl_array *out, double a, const struct gkyl_range *range) { #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(out)) { gkyl_array_scale_range_cu(out, a, range); return out; } + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_scale_range_cu(out, a, range); + return out; + } #endif return gkyl_array_set_range(out, a, out, range); } -struct gkyl_array* -gkyl_array_shiftc_range(struct gkyl_array* out, double a, unsigned k, const struct gkyl_range *range) +struct gkyl_array * +gkyl_array_shiftc_range(struct gkyl_array *out, double a, unsigned k, const struct gkyl_range *range) { assert(out->type == GKYL_DOUBLE); assert(k < NCOM(out)); #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(out)) { gkyl_array_shiftc_range_cu(out, a, k, range); return out; } + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_shiftc_range_cu(out, a, k, range); + return out; + } #endif struct gkyl_range_iter iter; @@ -457,15 +525,18 @@ gkyl_array_shiftc_range(struct gkyl_array* out, double a, unsigned k, const stru return out; } -struct gkyl_array* -gkyl_array_copy_range(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range) +struct gkyl_array *gkyl_array_copy_range( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +) { assert(out->size == inp->size && out->elemsz == inp->elemsz); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out)) { gkyl_array_copy_range_cu(out, inp, range); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_copy_range_cu(out, inp, range); + return out; + } #endif struct gkyl_range_iter iter; @@ -478,21 +549,25 @@ gkyl_array_copy_range(struct gkyl_array *out, return out; } -struct gkyl_array* -gkyl_array_copy_range_to_range(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *out_range, const struct gkyl_range *inp_range) +struct gkyl_array *gkyl_array_copy_range_to_range( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *out_range, + const struct gkyl_range *inp_range +) { assert(out->elemsz == inp->elemsz); assert((inp_range->volume < 1) || (out_range->volume == inp_range->volume)); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out)) { gkyl_array_copy_range_to_range_cu(out, inp, out_range, inp_range); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out)) { + gkyl_array_copy_range_to_range_cu(out, inp, out_range, inp_range); + return out; + } #endif // Setup linear counter offset for output range/array. int iloLocal_out[GKYL_MAX_DIM], iloLocal_inp[GKYL_MAX_DIM]; - for (int d=0; dndim; ++d){ + for (int d = 0; d < out_range->ndim; ++d) { iloLocal_out[d] = out_range->lower[d]; iloLocal_inp[d] = inp_range->lower[d]; } @@ -501,8 +576,9 @@ gkyl_array_copy_range_to_range(struct gkyl_array *out, struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, inp_range); while (gkyl_range_iter_next(&iter)) { - for (int d=0; dndim; ++d) + for (int d = 0; d < out_range->ndim; ++d) { idx_out[d] = iloLocal_out[d] + (iter.idx[d] - iloLocal_inp[d]); + } long linidx_inp = gkyl_range_idx(inp_range, iter.idx); long linidx_out = gkyl_range_idx(out_range, idx_out); @@ -511,12 +587,15 @@ gkyl_array_copy_range_to_range(struct gkyl_array *out, return out; } -void -gkyl_array_copy_to_buffer(void *data, const struct gkyl_array *arr, - const struct gkyl_range *range) +void gkyl_array_copy_to_buffer( + void *data, const struct gkyl_array *arr, const struct gkyl_range *range +) { #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(arr)) { gkyl_array_copy_to_buffer_cu(data, arr, range); return; } + if (gkyl_array_is_cu_dev(arr)) { + gkyl_array_copy_to_buffer_cu(data, arr, range); + return; + } #endif #define _F(loc) gkyl_array_cfetch(arr, loc) @@ -527,18 +606,21 @@ gkyl_array_copy_to_buffer(void *data, const struct gkyl_array *arr, long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(range, iter.idx); - memcpy(((char*) data) + arr->esznc*count++, _F(start), arr->esznc); + memcpy(((char *)data) + arr->esznc * count++, _F(start), arr->esznc); } #undef _F } -void -gkyl_array_copy_from_buffer(struct gkyl_array *arr, - const void *data, const struct gkyl_range *range) +void gkyl_array_copy_from_buffer( + struct gkyl_array *arr, const void *data, const struct gkyl_range *range +) { #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(arr)) { gkyl_array_copy_from_buffer_cu(arr, data, range); return; } + if (gkyl_array_is_cu_dev(arr)) { + gkyl_array_copy_from_buffer_cu(arr, data, range); + return; + } #endif #define _F(loc) gkyl_array_fetch(arr, loc) @@ -549,18 +631,22 @@ gkyl_array_copy_from_buffer(struct gkyl_array *arr, long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(range, iter.idx); - memcpy(_F(start), ((char*) data) + arr->esznc*count++, arr->esznc); + memcpy(_F(start), ((char *)data) + arr->esznc * count++, arr->esznc); } #undef _F } -void -gkyl_array_copy_to_buffer_fn(void *data, const struct gkyl_array *arr, - const struct gkyl_range *range, struct gkyl_array_copy_func *cf) +void gkyl_array_copy_to_buffer_fn( + void *data, const struct gkyl_array *arr, const struct gkyl_range *range, + struct gkyl_array_copy_func *cf +) { #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(arr)) { gkyl_array_copy_to_buffer_fn_cu(data, arr, range, cf); return; } + if (gkyl_array_is_cu_dev(arr)) { + gkyl_array_copy_to_buffer_fn_cu(data, arr, range, cf); + return; + } #endif struct gkyl_range_iter iter; @@ -571,19 +657,23 @@ gkyl_array_copy_to_buffer_fn(void *data, const struct gkyl_array *arr, long loc = gkyl_range_idx(range, iter.idx); const double *inp = gkyl_array_cfetch(arr, loc); - double *out = gkyl_flat_fetch(data, arr->esznc*count); + double *out = gkyl_flat_fetch(data, arr->esznc * count); cf->func(NCOM(arr), out, inp, cf->ctx); count += 1; } } -void -gkyl_array_flip_copy_to_buffer_fn(void *data, const struct gkyl_array *arr, - int dir, const struct gkyl_range *range, struct gkyl_array_copy_func *cf) +void gkyl_array_flip_copy_to_buffer_fn( + void *data, const struct gkyl_array *arr, int dir, const struct gkyl_range *range, + struct gkyl_array_copy_func *cf +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(arr)) { - if (gkyl_array_is_cu_dev(arr)) { gkyl_array_flip_copy_to_buffer_fn_cu(data, arr, dir, range, cf); return; } + if (gkyl_array_is_cu_dev(arr)) { + gkyl_array_flip_copy_to_buffer_fn_cu(data, arr, dir, range, cf); + return; + } } #endif @@ -594,35 +684,41 @@ gkyl_array_flip_copy_to_buffer_fn(void *data, const struct gkyl_array *arr, struct gkyl_range buff_range; gkyl_range_init(&buff_range, range->ndim, range->lower, range->upper); - int uplo = range->upper[dir]+range->lower[dir]; + int uplo = range->upper[dir] + range->lower[dir]; while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(range, iter.idx); gkyl_copy_int_arr(range->ndim, iter.idx, fidx); fidx[dir] = uplo - iter.idx[dir]; - + long count = gkyl_range_idx(&buff_range, fidx); const double *inp = gkyl_array_cfetch(arr, loc); - double *out = gkyl_flat_fetch(data, arr->esznc*count); + double *out = gkyl_flat_fetch(data, arr->esznc * count); cf->func(NCOM(arr), out, inp, cf->ctx); } } -static double -calc_rel_diff(double a, double b) +static double calc_rel_diff(double a, double b) { - if (isnan(a) || isnan(b)) return DBL_MAX; - - double absa = fabs(a), absb = fabs(b), diff = fabs(a-b); - if (a == b) return 0; - if (a == 0 || b == 0 || (absa+absb < DBL_MIN)) return diff; - return diff/fmin(absa+absb, DBL_MAX); + if (isnan(a) || isnan(b)) { + return DBL_MAX; + } + + double absa = fabs(a), absb = fabs(b), diff = fabs(a - b); + if (a == b) { + return 0; + } + if (a == 0 || b == 0 || (absa + absb < DBL_MIN)) { + return diff; + } + return diff / fmin(absa + absb, DBL_MAX); } -struct gkyl_array_diff -gkyl_array_diff(const struct gkyl_array *arr1, const struct gkyl_array *arr2, const struct gkyl_range *range) +struct gkyl_array_diff gkyl_array_diff( + const struct gkyl_array *arr1, const struct gkyl_array *arr2, const struct gkyl_range *range +) { struct gkyl_array_diff incompat = { .is_compatible = false, @@ -632,59 +728,66 @@ gkyl_array_diff(const struct gkyl_array *arr1, const struct gkyl_array *arr2, co .min_rel_diff = DBL_MAX }; - if ((arr1->type != GKYL_DOUBLE) && (arr2->type != GKYL_DOUBLE)) + if ((arr1->type != GKYL_DOUBLE) && (arr2->type != GKYL_DOUBLE)) { return incompat; + } - if (gkyl_array_is_cu_dev(arr1) || gkyl_array_is_cu_dev(arr2)) - return incompat; + if (gkyl_array_is_cu_dev(arr1) || gkyl_array_is_cu_dev(arr2)) { + return incompat; + } - if (arr1->elemsz != arr2->elemsz) - return incompat; + if (arr1->elemsz != arr2->elemsz) { + return incompat; + } - if (arr1->ncomp != arr2->ncomp) + if (arr1->ncomp != arr2->ncomp) { return incompat; + } - if (arr1->size != arr2->size) + if (arr1->size != arr2->size) { return incompat; + } double max_abs_diff = -DBL_MAX, max_rel_diff = -DBL_MAX; double min_abs_diff = DBL_MAX, min_rel_diff = DBL_MAX; - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, range); while (gkyl_range_iter_next(&iter)) { - long loc = gkyl_range_idx(range, iter.idx); const double *a1 = gkyl_array_cfetch(arr1, loc); const double *a2 = gkyl_array_cfetch(arr2, loc); - for (int c=0; cncomp; ++c) { - max_abs_diff = fmax(max_abs_diff, a1[c]-a2[c]); - min_abs_diff = fmin(min_abs_diff, a1[c]-a2[c]); + for (int c = 0; c < arr1->ncomp; ++c) { + max_abs_diff = fmax(max_abs_diff, a1[c] - a2[c]); + min_abs_diff = fmin(min_abs_diff, a1[c] - a2[c]); double rel_diff = calc_rel_diff(a1[c], a2[c]); max_rel_diff = fmax(max_rel_diff, rel_diff); min_rel_diff = fmin(min_rel_diff, rel_diff); } } - return (struct gkyl_array_diff) { - .is_compatible = true, + return (struct gkyl_array_diff + ){.is_compatible = true, .max_abs_diff = max_abs_diff, .min_abs_diff = min_abs_diff, .max_rel_diff = max_rel_diff, - .min_rel_diff = min_rel_diff - }; + .min_rel_diff = min_rel_diff}; } -struct gkyl_array* -gkyl_array_max_by_cell_per_cell_avg_range(struct gkyl_array* out, const struct gkyl_array* inp, struct gkyl_range *range) +struct gkyl_array *gkyl_array_max_by_cell_per_cell_avg_range( + struct gkyl_array *out, const struct gkyl_array *inp, struct gkyl_range *range +) { assert(out->type == GKYL_DOUBLE); assert(out->size == inp->size && out->elemsz == inp->elemsz); #ifdef GKYL_HAVE_CUDA - assert(gkyl_array_is_cu_dev(out)==gkyl_array_is_cu_dev(inp)); - if (gkyl_array_is_cu_dev(out) && gkyl_array_is_cu_dev(inp)) { gkyl_array_max_by_cell_per_cell_avg_range_cu(out, inp, range); return out; } + assert(gkyl_array_is_cu_dev(out) == gkyl_array_is_cu_dev(inp)); + if (gkyl_array_is_cu_dev(out) && gkyl_array_is_cu_dev(inp)) { + gkyl_array_max_by_cell_per_cell_avg_range_cu(out, inp, range); + return out; + } #endif long nc = NCOM(out); @@ -696,7 +799,7 @@ gkyl_array_max_by_cell_per_cell_avg_range(struct gkyl_array* out, const struct g double *out_d = gkyl_array_fetch(out, start); const double *inp_d = gkyl_array_cfetch(inp, start); if (out_d[0] < inp_d[0]) { - for (int c=0; c // start ID for use in various loops -#define START_ID (threadIdx.x + blockIdx.x*blockDim.x) +#define START_ID (threadIdx.x + blockIdx.x * blockDim.x) // NOTE: This is duplicated in dg_bin_ops_cu. Should be cleaned up 01/05/22 static void -gkyl_get_array_range_kernel_launch_dims(dim3* dimGrid, dim3* dimBlock, gkyl_range range, int ncomp) +gkyl_get_array_range_kernel_launch_dims(dim3 *dimGrid, dim3 *dimBlock, gkyl_range range, int ncomp) { int ndim = range.ndim; // ac1 = size of last dimension of range (fastest moving dimension) - int ac1 = range.iac[ndim-1] > 0 ? range.iac[ndim-1] : 1; + int ac1 = range.iac[ndim - 1] > 0 ? range.iac[ndim - 1] : 1; // CUDA Max block size in x is 2^31 - 1, Max block size in y is 2^16-1 // Thus, x block size should be bigger to avoid max block size limits - dimBlock->y = GKYL_MIN2(ncomp*ac1, GKYL_DEFAULT_NUM_THREADS); - dimGrid->y = gkyl_int_div_up(ncomp*ac1, dimBlock->y); - dimBlock->x = gkyl_int_div_up(GKYL_DEFAULT_NUM_THREADS, ncomp*ac1); - dimGrid->x = gkyl_int_div_up(range.volume, ac1*dimBlock->x); + dimBlock->y = GKYL_MIN2(ncomp * ac1, GKYL_DEFAULT_NUM_THREADS); + dimGrid->y = gkyl_int_div_up(ncomp * ac1, dimBlock->y); + dimBlock->x = gkyl_int_div_up(GKYL_DEFAULT_NUM_THREADS, ncomp * ac1); + dimGrid->x = gkyl_int_div_up(range.volume, ac1 * dimBlock->x); } -__global__ void -gkyl_array_clear_cu_kernel(struct gkyl_array* out, double val) +__global__ void gkyl_array_clear_cu_kernel(struct gkyl_array *out, double val) { - double *out_d = (double*) out->data; - for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x*gridDim.x) + double *out_d = (double *)out->data; + for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x * gridDim.x) { out_d[linc] = val; + } } __global__ void -gkyl_array_accumulate_cu_kernel(struct gkyl_array* out, double a, - const struct gkyl_array* inp) +gkyl_array_accumulate_cu_kernel(struct gkyl_array *out, double a, const struct gkyl_array *inp) { - double *out_d = (double*) out->data; - const double *inp_d = (const double*) inp->data; - for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x*gridDim.x) - out_d[linc] += a*inp_d[linc]; + double *out_d = (double *)out->data; + const double *inp_d = (const double *)inp->data; + for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x * gridDim.x) { + out_d[linc] += a * inp_d[linc]; + } } -__global__ void -gkyl_array_accumulate_offset_cu_kernel(struct gkyl_array* out, double a, - const struct gkyl_array* inp, int coff) +__global__ void gkyl_array_accumulate_offset_cu_kernel( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff +) { - double *out_d = (double*) out->data; - const double *inp_d = (const double*) inp->data; + double *out_d = (double *)out->data; + const double *inp_d = (const double *)inp->data; if (NCOM(out) < NCOM(inp)) { - for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x*gridDim.x) - for (unsigned k=0; kdata; - const double *inp_d = (const double*) inp->data; - for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x*gridDim.x) - out_d[linc] = a*inp_d[linc]; + double *out_d = (double *)out->data; + const double *inp_d = (const double *)inp->data; + for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x * gridDim.x) { + out_d[linc] = a * inp_d[linc]; + } } -__global__ void -gkyl_array_set_offset_cu_kernel(struct gkyl_array* out, double a, - const struct gkyl_array* inp, int coff) +__global__ void gkyl_array_set_offset_cu_kernel( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff +) { - double *out_d = (double*) out->data; - const double *inp_d = (const double*) inp->data; + double *out_d = (double *)out->data; + const double *inp_d = (const double *)inp->data; if (NCOM(out) < NCOM(inp)) { - for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x*gridDim.x) - for (unsigned k=0; kdata; - const double *a_d = (double*) a->data; - for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x*gridDim.x) - out_d[linc] = a_d[linc/out->ncomp]*out_d[linc]; + double *out_d = (double *)out->data; + const double *a_d = (double *)a->data; + for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x * gridDim.x) { + out_d[linc] = a_d[linc / out->ncomp] * out_d[linc]; + } } __global__ void -gkyl_array_divide_by_cell_cu_kernel(struct gkyl_array* out, const struct gkyl_array* a) +gkyl_array_divide_by_cell_cu_kernel(struct gkyl_array *out, const struct gkyl_array *a) { - double *out_d = (double*) out->data; - const double *a_d = (double*) a->data; - for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x*gridDim.x) - out_d[linc] = out_d[linc]/a_d[linc/out->ncomp]; + double *out_d = (double *)out->data; + const double *a_d = (double *)a->data; + for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x * gridDim.x) { + out_d[linc] = out_d[linc] / a_d[linc / out->ncomp]; + } } __global__ void -gkyl_array_invert_by_cell_cu_kernel(struct gkyl_array* out, const struct gkyl_array *inp) +gkyl_array_invert_by_cell_cu_kernel(struct gkyl_array *out, const struct gkyl_array *inp) { - double *out_d = (double*) out->data; - const double *inp_d = (const double*) inp->data; - for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x*gridDim.x) - out_d[linc] = 1.0/inp_d[linc]; + double *out_d = (double *)out->data; + const double *inp_d = (const double *)inp->data; + for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x * gridDim.x) { + out_d[linc] = 1.0 / inp_d[linc]; + } } -__global__ void -gkyl_array_shiftc_cu_kernel(struct gkyl_array* out, double a, unsigned k) +__global__ void gkyl_array_shiftc_cu_kernel(struct gkyl_array *out, double a, unsigned k) { - double *out_d = (double*) out->data; - for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x*gridDim.x) - out_d[linc*out->ncomp+k] = a+out_d[linc*out->ncomp+k]; + double *out_d = (double *)out->data; + for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x * gridDim.x) { + out_d[linc * out->ncomp + k] = a + out_d[linc * out->ncomp + k]; + } } __global__ void -gkyl_array_min_by_cell_cu_kernel(struct gkyl_array* out, const struct gkyl_array *inp, double a) +gkyl_array_min_by_cell_cu_kernel(struct gkyl_array *out, const struct gkyl_array *inp, double a) { - double *out_d = (double*) out->data; - const double *inp_d = (const double*) inp->data; - for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x*gridDim.x) + double *out_d = (double *)out->data; + const double *inp_d = (const double *)inp->data; + for (unsigned long linc = START_ID; linc < NELM(out); linc += blockDim.x * gridDim.x) { out_d[linc] = fmin(inp_d[linc], a); + } } // Host-side wrappers for array operations -void -gkyl_array_clear_cu(struct gkyl_array* out, double val) +void gkyl_array_clear_cu(struct gkyl_array *out, double val) { - gkyl_array_clear_cu_kernel<<nblocks, out->nthreads>>>(out->on_dev, val); + gkyl_array_clear_cu_kernel<<nblocks, out->nthreads> > >(out->on_dev, val); } -void -gkyl_array_accumulate_cu(struct gkyl_array* out, double a, const struct gkyl_array* inp) +void gkyl_array_accumulate_cu(struct gkyl_array *out, double a, const struct gkyl_array *inp) { - gkyl_array_accumulate_cu_kernel<<nblocks, out->nthreads>>>(out->on_dev, a, inp->on_dev); + gkyl_array_accumulate_cu_kernel<<nblocks, out->nthreads> > >(out->on_dev, a, inp->on_dev); } -void -gkyl_array_accumulate_offset_cu(struct gkyl_array* out, double a, const struct gkyl_array* inp, int coff) +void gkyl_array_accumulate_offset_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff +) { int nblocks = gkyl_int_div_up(out->size, out->nthreads); - gkyl_array_accumulate_offset_cu_kernel<<nthreads>>>(out->on_dev, a, inp->on_dev, coff); + gkyl_array_accumulate_offset_cu_kernel<<nthreads> > >( + out->on_dev, a, inp->on_dev, coff + ); } -void -gkyl_array_set_cu(struct gkyl_array* out, double a, const struct gkyl_array* inp) +void gkyl_array_set_cu(struct gkyl_array *out, double a, const struct gkyl_array *inp) { - gkyl_array_set_cu_kernel<<nblocks, out->nthreads>>>(out->on_dev, a, inp->on_dev); + gkyl_array_set_cu_kernel<<nblocks, out->nthreads> > >(out->on_dev, a, inp->on_dev); } -void -gkyl_array_set_offset_cu(struct gkyl_array* out, double a, const struct gkyl_array* inp, int coff) +void gkyl_array_set_offset_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff +) { int nblocks = gkyl_int_div_up(out->size, out->nthreads); - gkyl_array_set_offset_cu_kernel<<nthreads>>>(out->on_dev, a, inp->on_dev, coff); + gkyl_array_set_offset_cu_kernel<<nthreads> > >(out->on_dev, a, inp->on_dev, coff); } -void -gkyl_array_scale_cu(struct gkyl_array* out, double a) +void gkyl_array_scale_cu(struct gkyl_array *out, double a) { - gkyl_array_set_cu_kernel<<nblocks, out->nthreads>>>(out->on_dev, a, out->on_dev); + gkyl_array_set_cu_kernel<<nblocks, out->nthreads> > >(out->on_dev, a, out->on_dev); } -void -gkyl_array_scale_by_cell_cu(struct gkyl_array* out, const struct gkyl_array* a) +void gkyl_array_scale_by_cell_cu(struct gkyl_array *out, const struct gkyl_array *a) { - gkyl_array_scale_by_cell_cu_kernel<<nblocks, out->nthreads>>>(out->on_dev, a->on_dev); + gkyl_array_scale_by_cell_cu_kernel<<nblocks, out->nthreads> > >(out->on_dev, a->on_dev); } -void -gkyl_array_divide_by_cell_cu(struct gkyl_array* out, const struct gkyl_array* a) +void gkyl_array_divide_by_cell_cu(struct gkyl_array *out, const struct gkyl_array *a) { - gkyl_array_divide_by_cell_cu_kernel<<nblocks, out->nthreads>>>(out->on_dev, a->on_dev); + gkyl_array_divide_by_cell_cu_kernel<<nblocks, out->nthreads> > >(out->on_dev, a->on_dev); } -void -gkyl_array_invert_by_cell_cu(struct gkyl_array* out, const struct gkyl_array *inp) +void gkyl_array_invert_by_cell_cu(struct gkyl_array *out, const struct gkyl_array *inp) { - gkyl_array_invert_by_cell_cu_kernel<<nblocks, out->nthreads>>>(out->on_dev, inp->on_dev); + gkyl_array_invert_by_cell_cu_kernel<<nblocks, out->nthreads> > >(out->on_dev, inp->on_dev); } -void -gkyl_array_shiftc_cu(struct gkyl_array* out, double a, unsigned k) +void gkyl_array_shiftc_cu(struct gkyl_array *out, double a, unsigned k) { - gkyl_array_shiftc_cu_kernel<<nblocks, out->nthreads>>>(out->on_dev, a, k); + gkyl_array_shiftc_cu_kernel<<nblocks, out->nthreads> > >(out->on_dev, a, k); } -void -gkyl_array_min_by_cell_cu(struct gkyl_array* out, const struct gkyl_array *inp, double a) +void gkyl_array_min_by_cell_cu(struct gkyl_array *out, const struct gkyl_array *inp, double a) { - gkyl_array_min_by_cell_cu_kernel<<nblocks, out->nthreads>>>(out->on_dev, inp->on_dev, a); + gkyl_array_min_by_cell_cu_kernel<<nblocks, out->nthreads> > >(out->on_dev, inp->on_dev, a); } // Range-based methods @@ -222,387 +229,380 @@ gkyl_array_clear_range_cu_kernel(struct gkyl_array *out, double val, struct gkyl int idx[GKYL_MAX_DIM]; int ndim = range.ndim; // ac1 = size of last dimension of range (fastest moving dimension) - long ac1 = range.iac[ndim-1] > 0 ? range.iac[ndim-1] : 1; + long ac1 = range.iac[ndim - 1] > 0 ? range.iac[ndim - 1] : 1; // 2D thread grid // linc2 = c + n*idx1 (contiguous data, including component index c, with idx1 = 0,.., ac1-1) - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; // linc1 = idx2 + ac2*idx3 + ... - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume/ac1; - linc1 += gridDim.x*blockDim.x) - { - // full linear cell index (not including components) is + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume / ac1; + linc1 += gridDim.x * blockDim.x) { + // full linear cell index (not including components) is // idx1 + ac1*idx2 + ac1*ac2*idx3 + ... = idx1 + ac1*linc1. - // we want to find the start linear index of each contiguous data block, - // which corresponds to idx1 = 0. + // we want to find the start linear index of each contiguous data block, + // which corresponds to idx1 = 0. // so linear index of start of contiguous block is ac1*linc2. - gkyl_sub_range_inv_idx(&range, ac1*linc1, idx); + gkyl_sub_range_inv_idx(&range, ac1 * linc1, idx); long start = gkyl_range_idx(&range, idx); - - double* out_d = (double*) gkyl_array_fetch(out, start); + + double *out_d = (double *)gkyl_array_fetch(out, start); // do operation on contiguous data block - if (linc2 < n*ac1) + if (linc2 < n * ac1) { out_d[linc2] = val; + } } } -__global__ void -gkyl_array_accumulate_range_cu_kernel(struct gkyl_array *out, - double a, const struct gkyl_array* inp, struct gkyl_range range) +__global__ void gkyl_array_accumulate_range_cu_kernel( + struct gkyl_array *out, double a, const struct gkyl_array *inp, struct gkyl_range range +) { long outnc = NCOM(out), inpnc = NCOM(inp); - long n = outnc 0 ? range.iac[ndim-1] : 1; + long ac1 = range.iac[ndim - 1] > 0 ? range.iac[ndim - 1] : 1; // 2D thread grid // linc2 = c + n*idx1 (contiguous data, including component index c, with idx1 = 0,.., ac1-1) - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; long c = linc2 % n; long idx1 = linc2 / n; - // get corresponding linc1 index for inp and out + // get corresponding linc1 index for inp and out // (one of these will not be contiguous if outnc!=inpnc) - long linc2_in = c + inpnc*idx1; - long linc2_out = c + outnc*idx1; + long linc2_in = c + inpnc * idx1; + long linc2_out = c + outnc * idx1; // linc1 = idx2 + ac2*idx3 + ... - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume/ac1; - linc1 += gridDim.x*blockDim.x) - { - // full linear cell index (not including components) is + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume / ac1; + linc1 += gridDim.x * blockDim.x) { + // full linear cell index (not including components) is // idx1 + ac1*idx2 + ac1*ac2*idx3 + ... = idx1 + ac1*linc1. - // we want to find the start linear index of each contiguous data block, - // which corresponds to idx1 = 0. + // we want to find the start linear index of each contiguous data block, + // which corresponds to idx1 = 0. // so linear index of start of contiguous block is ac1*linc2. - gkyl_sub_range_inv_idx(&range, ac1*linc1, idx); + gkyl_sub_range_inv_idx(&range, ac1 * linc1, idx); long start = gkyl_range_idx(&range, idx); - - double* out_d = (double*) gkyl_array_fetch(out, start); - const double* inp_d = (const double*) gkyl_array_cfetch(inp, start); + + double *out_d = (double *)gkyl_array_fetch(out, start); + const double *inp_d = (const double *)gkyl_array_cfetch(inp, start); // do operation on contiguous data block - if (linc2 < n*ac1) - out_d[linc2_out] += a*inp_d[linc2_in]; + if (linc2 < n * ac1) { + out_d[linc2_out] += a * inp_d[linc2_in]; + } } } -__global__ void -gkyl_array_accumulate_offset_range_cu_kernel(struct gkyl_array *out, - double a, const struct gkyl_array* inp, int coff, struct gkyl_range range) +__global__ void gkyl_array_accumulate_offset_range_cu_kernel( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff, struct gkyl_range range +) { long outnc = NCOM(out), inpnc = NCOM(inp); long n; int outoff, inpoff; if (outnc < inpnc) { - n = outnc; - outoff = 0; - inpoff = coff; + n = outnc; + outoff = 0; + inpoff = coff; } else { - n = inpnc; - outoff = coff; - inpoff = 0; + n = inpnc; + outoff = coff; + inpoff = 0; } int idx[GKYL_MAX_DIM]; int ndim = range.ndim; // ac1 = size of last dimension of range (fastest moving dimension) - long ac1 = range.iac[ndim-1] > 0 ? range.iac[ndim-1] : 1; + long ac1 = range.iac[ndim - 1] > 0 ? range.iac[ndim - 1] : 1; // 2D thread grid // linc2 = c + n*idx1 (contiguous data, including component index c, with idx1 = 0,.., ac1-1) - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; long c = linc2 % n; long idx1 = linc2 / n; - // get corresponding linc1 index for inp and out + // get corresponding linc1 index for inp and out // (one of these will not be contiguous if outnc!=inpnc) - long linc2_in = c + inpnc*idx1; - long linc2_out = c + outnc*idx1; + long linc2_in = c + inpnc * idx1; + long linc2_out = c + outnc * idx1; // linc1 = idx2 + ac2*idx3 + ... - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume/ac1; - linc1 += gridDim.x*blockDim.x) - { - // full linear cell index (not including components) is + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume / ac1; + linc1 += gridDim.x * blockDim.x) { + // full linear cell index (not including components) is // idx1 + ac1*idx2 + ac1*ac2*idx3 + ... = idx1 + ac1*linc1. - // we want to find the start linear index of each contiguous data block, - // which corresponds to idx1 = 0. + // we want to find the start linear index of each contiguous data block, + // which corresponds to idx1 = 0. // so linear index of start of contiguous block is ac1*linc2. - gkyl_sub_range_inv_idx(&range, ac1*linc1, idx); + gkyl_sub_range_inv_idx(&range, ac1 * linc1, idx); long start = gkyl_range_idx(&range, idx); - - double* out_d = (double*) gkyl_array_fetch(out, start); - const double* inp_d = (const double*) gkyl_array_cfetch(inp, start); + + double *out_d = (double *)gkyl_array_fetch(out, start); + const double *inp_d = (const double *)gkyl_array_cfetch(inp, start); // do operation on contiguous data block - if (linc2 < n*ac1) - out_d[linc2_out+outoff] += a*inp_d[linc2_in+inpoff]; + if (linc2 < n * ac1) { + out_d[linc2_out + outoff] += a * inp_d[linc2_in + inpoff]; + } } } -__global__ void -gkyl_array_set_range_cu_kernel(struct gkyl_array *out, double a, - const struct gkyl_array* inp, struct gkyl_range out_range, struct gkyl_range inp_range) +__global__ void gkyl_array_set_range_cu_kernel( + struct gkyl_array *out, double a, const struct gkyl_array *inp, struct gkyl_range out_range, + struct gkyl_range inp_range +) { long outnc = NCOM(out), inpnc = NCOM(inp); - long n = outnc 0 ? inp_range.iac[ndim-1] : 1; + long ac1 = inp_range.iac[ndim - 1] > 0 ? inp_range.iac[ndim - 1] : 1; // 2D thread grid // linc2 = c + n*idx1 (contiguous data, including component index c, with idx1 = 0,.., ac1-1) - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; long c = linc2 % n; long idx1 = linc2 / n; - // get corresponding linc1 index for inp and out + // get corresponding linc1 index for inp and out // (one of these will not be contiguous if outnc!=inpnc) - long linc2_in = c + inpnc*idx1; - long linc2_out = c + outnc*idx1; + long linc2_in = c + inpnc * idx1; + long linc2_out = c + outnc * idx1; // linc1 = idx2 + ac2*idx3 + ... - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < inp_range.volume/ac1; - linc1 += gridDim.x*blockDim.x) - { - // full linear cell index (not including components) is + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < inp_range.volume / ac1; + linc1 += gridDim.x * blockDim.x) { + // full linear cell index (not including components) is // idx1 + ac1*idx2 + ac1*ac2*idx3 + ... = idx1 + ac1*linc1. - // we want to find the start linear index of each contiguous data block, - // which corresponds to idx1 = 0. + // we want to find the start linear index of each contiguous data block, + // which corresponds to idx1 = 0. // so linear index of start of contiguous block is ac1*linc2. - gkyl_sub_range_inv_idx(&out_range, ac1*linc1, idx_out); - gkyl_sub_range_inv_idx(&inp_range, ac1*linc1, idx_inp); + gkyl_sub_range_inv_idx(&out_range, ac1 * linc1, idx_out); + gkyl_sub_range_inv_idx(&inp_range, ac1 * linc1, idx_inp); long start_out = gkyl_range_idx(&out_range, idx_out); long start_inp = gkyl_range_idx(&inp_range, idx_inp); - - double* out_d = (double*) gkyl_array_fetch(out, start_out); - const double* inp_d = (const double*) gkyl_array_cfetch(inp, start_inp); + + double *out_d = (double *)gkyl_array_fetch(out, start_out); + const double *inp_d = (const double *)gkyl_array_cfetch(inp, start_inp); // do operation on contiguous data block - if (linc2 < n*ac1) - out_d[linc2_out] = a*inp_d[linc2_in]; + if (linc2 < n * ac1) { + out_d[linc2_out] = a * inp_d[linc2_in]; + } } } -__global__ void -gkyl_array_set_offset_range_cu_kernel(struct gkyl_array *out, - double a, const struct gkyl_array* inp, int coff, struct gkyl_range range) +__global__ void gkyl_array_set_offset_range_cu_kernel( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff, struct gkyl_range range +) { long outnc = NCOM(out), inpnc = NCOM(inp); long n; int outoff, inpoff; if (outnc < inpnc) { - n = outnc; - outoff = 0; - inpoff = coff; + n = outnc; + outoff = 0; + inpoff = coff; } else { - n = inpnc; - outoff = coff; - inpoff = 0; + n = inpnc; + outoff = coff; + inpoff = 0; } int idx[GKYL_MAX_DIM]; int ndim = range.ndim; // ac1 = size of last dimension of range (fastest moving dimension) - long ac1 = range.iac[ndim-1] > 0 ? range.iac[ndim-1] : 1; + long ac1 = range.iac[ndim - 1] > 0 ? range.iac[ndim - 1] : 1; // 2D thread grid // linc2 = c + n*idx1 (contiguous data, including component index c, with idx1 = 0,.., ac1-1) - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; long c = linc2 % n; long idx1 = linc2 / n; - // get corresponding linc1 index for inp and out + // get corresponding linc1 index for inp and out // (one of these will not be contiguous if outnc!=inpnc) - long linc2_in = c + inpnc*idx1; - long linc2_out = c + outnc*idx1; + long linc2_in = c + inpnc * idx1; + long linc2_out = c + outnc * idx1; // linc1 = idx2 + ac2*idx3 + ... - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume/ac1; - linc1 += gridDim.x*blockDim.x) - { - // full linear cell index (not including components) is + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume / ac1; + linc1 += gridDim.x * blockDim.x) { + // full linear cell index (not including components) is // idx1 + ac1*idx2 + ac1*ac2*idx3 + ... = idx1 + ac1*linc1. - // we want to find the start linear index of each contiguous data block, - // which corresponds to idx1 = 0. + // we want to find the start linear index of each contiguous data block, + // which corresponds to idx1 = 0. // so linear index of start of contiguous block is ac1*linc2. - gkyl_sub_range_inv_idx(&range, ac1*linc1, idx); + gkyl_sub_range_inv_idx(&range, ac1 * linc1, idx); long start = gkyl_range_idx(&range, idx); - - double* out_d = (double*) gkyl_array_fetch(out, start); - const double* inp_d = (const double*) gkyl_array_cfetch(inp, start); + + double *out_d = (double *)gkyl_array_fetch(out, start); + const double *inp_d = (const double *)gkyl_array_cfetch(inp, start); // do operation on contiguous data block - if (linc2 < n*ac1) - out_d[linc2_out+outoff] = a*inp_d[linc2_in+inpoff]; + if (linc2 < n * ac1) { + out_d[linc2_out + outoff] = a * inp_d[linc2_in + inpoff]; + } } } -__global__ void -gkyl_array_shiftc_range_cu_kernel(struct gkyl_array* out, double a, - unsigned k, struct gkyl_range range) +__global__ void gkyl_array_shiftc_range_cu_kernel( + struct gkyl_array *out, double a, unsigned k, struct gkyl_range range +) { long ncomp = NCOM(out); int idx[GKYL_MAX_DIM]; int ndim = range.ndim; // ac1 = size of last dimension of range (fastest moving dimension). - long ac1 = range.iac[ndim-1] > 0 ? range.iac[ndim-1] : 1; + long ac1 = range.iac[ndim - 1] > 0 ? range.iac[ndim - 1] : 1; // 2D thread grid // linc2 = c + ncomp*idx1 (contiguous data, including component index c, with idx1 = 0,.., ac1-1) - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; // linc1 = idx2 + ac2*idx3 + ... - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume/ac1; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume / ac1; + linc1 += gridDim.x * blockDim.x) { // full linear cell index (not including components) is // idx1 + ac1*idx2 + ac1*ac2*idx3 + ... = idx1 + ac1*linc1. // we want to find the start linear index of each contiguous data block, // which corresponds to idx1 = 0. // so linear index of start of contiguous block is ac1*linc2. - gkyl_sub_range_inv_idx(&range, ac1*linc1, idx); + gkyl_sub_range_inv_idx(&range, ac1 * linc1, idx); long start = gkyl_range_idx(&range, idx); - double* out_d = (double*) gkyl_array_fetch(out, start); + double *out_d = (double *)gkyl_array_fetch(out, start); // do operation on contiguous data block - if (linc2*ncomp < ncomp*ac1) - out_d[linc2*ncomp+k] += a; + if (linc2 * ncomp < ncomp * ac1) { + out_d[linc2 * ncomp + k] += a; + } } } -__global__ void -gkyl_array_min_by_cell_range_cu_kernel(struct gkyl_array* out, const struct gkyl_array* inp, - double a, struct gkyl_range range) +__global__ void gkyl_array_min_by_cell_range_cu_kernel( + struct gkyl_array *out, const struct gkyl_array *inp, double a, struct gkyl_range range +) { long ncomp = NCOM(out); int idx[GKYL_MAX_DIM]; int ndim = range.ndim; // ac1 = size of last dimension of range (fastest moving dimension). - long ac1 = range.iac[ndim-1] > 0 ? range.iac[ndim-1] : 1; + long ac1 = range.iac[ndim - 1] > 0 ? range.iac[ndim - 1] : 1; // 2D thread grid // linc2 = c + ncomp*idx1 (contiguous data, including component index c, with idx1 = 0,.., ac1-1) - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; // linc1 = idx2 + ac2*idx3 + ... - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume/ac1; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume / ac1; + linc1 += gridDim.x * blockDim.x) { // full linear cell index (not including components) is // idx1 + ac1*idx2 + ac1*ac2*idx3 + ... = idx1 + ac1*linc1. // we want to find the start linear index of each contiguous data block, // which corresponds to idx1 = 0. // so linear index of start of contiguous block is ac1*linc2. - gkyl_sub_range_inv_idx(&range, ac1*linc1, idx); + gkyl_sub_range_inv_idx(&range, ac1 * linc1, idx); long start = gkyl_range_idx(&range, idx); - double* out_d = (double*) gkyl_array_fetch(out, start); - const double* inp_d = (const double*) gkyl_array_cfetch(inp, start); + double *out_d = (double *)gkyl_array_fetch(out, start); + const double *inp_d = (const double *)gkyl_array_cfetch(inp, start); // do operation on contiguous data block - if (linc2 < ncomp*ac1) + if (linc2 < ncomp * ac1) { out_d[linc2] = fmin(inp_d[linc2], a); + } } } -__global__ void -gkyl_array_copy_range_cu_kernel(struct gkyl_array *out, const struct gkyl_array* inp, - struct gkyl_range out_range, struct gkyl_range inp_range) +__global__ void gkyl_array_copy_range_cu_kernel( + struct gkyl_array *out, const struct gkyl_array *inp, struct gkyl_range out_range, + struct gkyl_range inp_range +) { int idx_out[GKYL_MAX_DIM], idx_inp[GKYL_MAX_DIM]; long n = NCOM(out); // assume ncomp_in == ncomp_out int ndim = inp_range.ndim; // ac1 = size of last dimension in input range (fastest moving dimension) - long ac1 = inp_range.iac[ndim-1] > 0 ? inp_range.iac[ndim-1] : 1; + long ac1 = inp_range.iac[ndim - 1] > 0 ? inp_range.iac[ndim - 1] : 1; // 2D thread grid // linc2 = c + n*idx1 (contiguous data, including component index c, with idx1 = 0,.., ac1-1) - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; // linc1 = idx2 + ac2*idx3 + ... - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < inp_range.volume/ac1; - linc1 += gridDim.x*blockDim.x) - { - // full linear cell index (not including components) is + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < inp_range.volume / ac1; + linc1 += gridDim.x * blockDim.x) { + // full linear cell index (not including components) is // idx1 + ac1*idx2 + ac1*ac2*idx3 + ... = idx1 + ac1*linc1. - // we want to find the start linear index of each contiguous data block, - // which corresponds to idx1 = 0. + // we want to find the start linear index of each contiguous data block, + // which corresponds to idx1 = 0. // so linear index of start of contiguous block is ac1*linc1. // NOTE: the above necessarily applies only to inp_range - gkyl_sub_range_inv_idx(&out_range, ac1*linc1, idx_out); - gkyl_sub_range_inv_idx(&inp_range, ac1*linc1, idx_inp); + gkyl_sub_range_inv_idx(&out_range, ac1 * linc1, idx_out); + gkyl_sub_range_inv_idx(&inp_range, ac1 * linc1, idx_inp); long start_out = gkyl_range_idx(&out_range, idx_out); long start_inp = gkyl_range_idx(&inp_range, idx_inp); - - double* out_d = (double*) gkyl_array_fetch(out, start_out); - const double* inp_d = (const double*) gkyl_array_cfetch(inp, start_inp); + + double *out_d = (double *)gkyl_array_fetch(out, start_out); + const double *inp_d = (const double *)gkyl_array_cfetch(inp, start_inp); // do operation on contiguous data block - if (linc2 < n*ac1) + if (linc2 < n * ac1) { out_d[linc2] = inp_d[linc2]; + } } } -__global__ void -gkyl_array_copy_to_buffer_cu_kernel(void *data, const struct gkyl_array *arr, - struct gkyl_range range) +__global__ void gkyl_array_copy_to_buffer_cu_kernel( + void *data, const struct gkyl_array *arr, struct gkyl_range range +) { - double *d_data = (double*) data; + double *d_data = (double *)data; int idx[GKYL_MAX_DIM]; long n = NCOM(arr); // assume ncomp_in == ncomp_out int ndim = range.ndim; // ac1 = size of last dimension of range (fastest moving dimension) - long ac1 = range.iac[ndim-1] > 0 ? range.iac[ndim-1] : 1; + long ac1 = range.iac[ndim - 1] > 0 ? range.iac[ndim - 1] : 1; // 2D thread grid // linc2 = c + n*idx1 (contiguous data, including component index c, with idx1 = 0,.., ac1-1) - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; // linc1 = idx2 + ac2*idx3 + ... - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume/ac1; - linc1 += gridDim.x*blockDim.x) - { - // full linear cell index (not including components) is + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume / ac1; + linc1 += gridDim.x * blockDim.x) { + // full linear cell index (not including components) is // idx1 + ac1*idx2 + ac1*ac2*idx3 + ... = idx1 + ac1*linc1. - // we want to find the start linear index of each contiguous data block, - // which corresponds to idx1 = 0. + // we want to find the start linear index of each contiguous data block, + // which corresponds to idx1 = 0. // so linear index of start of contiguous block is ac1*linc2. - gkyl_sub_range_inv_idx(&range, ac1*linc1, idx); + gkyl_sub_range_inv_idx(&range, ac1 * linc1, idx); long start = gkyl_range_idx(&range, idx); - - const double* arr_d = (const double*) gkyl_array_cfetch(arr, start); + + const double *arr_d = (const double *)gkyl_array_cfetch(arr, start); // read from contiguous data block - if (linc2 < n*ac1) - d_data[linc2 + n*ac1*linc1] = arr_d[linc2]; + if (linc2 < n * ac1) { + d_data[linc2 + n * ac1 * linc1] = arr_d[linc2]; + } } } -__global__ void -gkyl_array_copy_from_buffer_cu_kernel(struct gkyl_array *arr, const void *data, - struct gkyl_range range) +__global__ void gkyl_array_copy_from_buffer_cu_kernel( + struct gkyl_array *arr, const void *data, struct gkyl_range range +) { int idx[GKYL_MAX_DIM]; - const double *d_data = (const double*) data; + const double *d_data = (const double *)data; long n = NCOM(arr); - + // since input data is just a linear array, just stream through data linearly // linc = c + n*idx1 + n*ac1*idx2 + ... - for (unsigned long linc = START_ID; linc < range.volume*n; linc += blockDim.x*gridDim.x) { + for (unsigned long linc = START_ID; linc < range.volume * n; linc += blockDim.x * gridDim.x) { int c = linc % n; long linc2 = linc / n; // = idx1 + ac1*idx2 + ... gkyl_sub_range_inv_idx(&range, linc2, idx); long start = gkyl_range_idx(&range, idx); - - double *arr_data = (double*) gkyl_array_fetch(arr, start); + + double *arr_data = (double *)gkyl_array_fetch(arr, start); arr_data[c] = d_data[linc]; } } -__global__ void -gkyl_array_copy_to_buffer_fn_cu_kernel(void *data, const struct gkyl_array *arr, - struct gkyl_range range, struct gkyl_array_copy_func *cf) +__global__ void gkyl_array_copy_to_buffer_fn_cu_kernel( + void *data, const struct gkyl_array *arr, struct gkyl_range range, struct gkyl_array_copy_func *cf +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; linc1 += blockDim.x*gridDim.x) { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += blockDim.x * gridDim.x) { // inverse index from linc1 to idxc // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idxc={1,1,...} // since update_range is a subrange @@ -612,24 +612,24 @@ gkyl_array_copy_to_buffer_fn_cu_kernel(void *data, const struct gkyl_array *arr, // linc will have jumps in it to jump over ghost cells long linc = gkyl_range_idx(&range, idx); - const double *inp = (const double*) gkyl_array_cfetch(arr, linc); - double *out = (double*) gkyl_flat_fetch(data, arr->esznc*linc1); + const double *inp = (const double *)gkyl_array_cfetch(arr, linc); + double *out = (double *)gkyl_flat_fetch(data, arr->esznc * linc1); cf->func(arr->ncomp, out, inp, cf->ctx); } } -__global__ void -gkyl_array_flip_copy_to_buffer_fn_cu_kernel(void *data, const struct gkyl_array *arr, - int dir, struct gkyl_range range, struct gkyl_range buff_range, - struct gkyl_array_copy_func *cf) +__global__ void gkyl_array_flip_copy_to_buffer_fn_cu_kernel( + void *data, const struct gkyl_array *arr, int dir, struct gkyl_range range, + struct gkyl_range buff_range, struct gkyl_array_copy_func *cf +) { int idx[GKYL_MAX_DIM]; int fidx[GKYL_MAX_DIM]; // flipped index - int uplo = range.upper[dir]+range.lower[dir]; + int uplo = range.upper[dir] + range.lower[dir]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; linc1 += blockDim.x*gridDim.x) { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += blockDim.x * gridDim.x) { // inverse index from linc1 to idxc // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idxc={1,1,...} // since update_range is a subrange @@ -642,47 +642,45 @@ gkyl_array_flip_copy_to_buffer_fn_cu_kernel(void *data, const struct gkyl_array // linc and flipped linc (flinc) will have jumps in it to jump over ghost cells long linc = gkyl_range_idx(&range, idx); long flinc = gkyl_range_idx(&buff_range, fidx); - - const double *inp = (const double*) gkyl_array_cfetch(arr, linc); - double *out = (double*) gkyl_flat_fetch(data, arr->esznc*flinc); + + const double *inp = (const double *)gkyl_array_cfetch(arr, linc); + double *out = (double *)gkyl_flat_fetch(data, arr->esznc * flinc); cf->func(arr->ncomp, out, inp, cf->ctx); } } -__global__ void -gkyl_array_max_by_cell_per_cell_avg_range_cu_kernel(struct gkyl_array *out, - const struct gkyl_array* inp, struct gkyl_range range) +__global__ void gkyl_array_max_by_cell_per_cell_avg_range_cu_kernel( + struct gkyl_array *out, const struct gkyl_array *inp, struct gkyl_range range +) { long outnc = NCOM(out), inpnc = NCOM(inp); // For ceil, we assume component counts match, or we limit to outnc - long n = outnc; + long n = outnc; int idx[GKYL_MAX_DIM]; int ndim = range.ndim; // ac1 = size of last dimension of range (fastest moving dimension) - long ac1 = range.iac[ndim-1] > 0 ? range.iac[ndim-1] : 1; + long ac1 = range.iac[ndim - 1] > 0 ? range.iac[ndim - 1] : 1; // 2D thread grid // In this kernel, linc2 corresponds directly to idx1 (the cell index in the contiguous strip) // We do not split by component 'c' here because the check on c=0 must gate the copy of c=1..N - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; - - // Note: linc2 acts as idx1 here. + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; + + // Note: linc2 acts as idx1 here. // We effectively handle all 'n' components for the cell at 'idx1' in this single thread. // linc1 = idx2 + ac2*idx3 + ... - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume/ac1; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume / ac1; + linc1 += gridDim.x * blockDim.x) { // full linear cell index calculation (same as accumulate) // idx1 + ac1*idx2 + ... // We find the start linear index of the contiguous block (idx1=0) - gkyl_sub_range_inv_idx(&range, ac1*linc1, idx); + gkyl_sub_range_inv_idx(&range, ac1 * linc1, idx); long start = gkyl_range_idx(&range, idx); - - double* out_d = (double*) gkyl_array_fetch(out, start); - const double* inp_d = (const double*) gkyl_array_cfetch(inp, start); + + double *out_d = (double *)gkyl_array_fetch(out, start); + const double *inp_d = (const double *)gkyl_array_cfetch(inp, start); // do operation on contiguous data block if (linc2 < ac1) { @@ -694,7 +692,6 @@ gkyl_array_max_by_cell_per_cell_avg_range_cu_kernel(struct gkyl_array *out, // Check the condition on the 0-th component (Cell Average) if (out_d[cell_offset_out] < inp_d[cell_offset_inp]) { - // If condition passed, copy ALL components for this cell for (int k = 0; k < n; ++k) { out_d[cell_offset_out + k] = inp_d[cell_offset_inp + k]; @@ -705,162 +702,175 @@ gkyl_array_max_by_cell_per_cell_avg_range_cu_kernel(struct gkyl_array *out, } // Host-side wrappers for range-based array operations -void -gkyl_array_clear_range_cu(struct gkyl_array *out, double val, const struct gkyl_range *range) +void gkyl_array_clear_range_cu(struct gkyl_array *out, double val, const struct gkyl_range *range) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *range, out->ncomp); - gkyl_array_clear_range_cu_kernel<<>>(out->on_dev, val, *range); + gkyl_array_clear_range_cu_kernel<< > >(out->on_dev, val, *range); } -void -gkyl_array_accumulate_range_cu(struct gkyl_array *out, - double a, const struct gkyl_array* inp, const struct gkyl_range *range) +void gkyl_array_accumulate_range_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, const struct gkyl_range *range +) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *range, min(out->ncomp, inp->ncomp)); - gkyl_array_accumulate_range_cu_kernel<<>>(out->on_dev, a, inp->on_dev, *range); + gkyl_array_accumulate_range_cu_kernel<< > >( + out->on_dev, a, inp->on_dev, *range + ); } -void -gkyl_array_accumulate_offset_range_cu(struct gkyl_array *out, - double a, const struct gkyl_array* inp, int coff, const struct gkyl_range *range) +void gkyl_array_accumulate_offset_range_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff, + const struct gkyl_range *range +) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *range, min(out->ncomp, inp->ncomp)); - gkyl_array_accumulate_offset_range_cu_kernel<<>>(out->on_dev, a, inp->on_dev, coff, *range); + gkyl_array_accumulate_offset_range_cu_kernel<< > >( + out->on_dev, a, inp->on_dev, coff, *range + ); } -void -gkyl_array_set_range_cu(struct gkyl_array *out, - double a, const struct gkyl_array* inp, const struct gkyl_range *range) +void gkyl_array_set_range_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, const struct gkyl_range *range +) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *range, min(out->ncomp, inp->ncomp)); - gkyl_array_set_range_cu_kernel<<>>(out->on_dev, - a, inp->on_dev, *range, *range); + gkyl_array_set_range_cu_kernel<< > >( + out->on_dev, a, inp->on_dev, *range, *range + ); } -void -gkyl_array_set_range_to_range_cu(struct gkyl_array *out, double a, - const struct gkyl_array* inp, const struct gkyl_range *out_range, const struct gkyl_range *inp_range) +void gkyl_array_set_range_to_range_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, + const struct gkyl_range *out_range, const struct gkyl_range *inp_range +) { if (inp_range->volume > 0) { dim3 dimGrid, dimBlock; - gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *inp_range, min(out->ncomp, inp->ncomp)); + gkyl_get_array_range_kernel_launch_dims( + &dimGrid, &dimBlock, *inp_range, min(out->ncomp, inp->ncomp) + ); - gkyl_array_set_range_cu_kernel<<>>(out->on_dev, - a, inp->on_dev, *out_range, *inp_range); + gkyl_array_set_range_cu_kernel<< > >( + out->on_dev, a, inp->on_dev, *out_range, *inp_range + ); } } -void -gkyl_array_set_offset_range_cu(struct gkyl_array *out, - double a, const struct gkyl_array* inp, int coff, const struct gkyl_range *range) +void gkyl_array_set_offset_range_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff, + const struct gkyl_range *range +) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *range, min(out->ncomp, inp->ncomp)); - gkyl_array_set_offset_range_cu_kernel<<>>(out->on_dev, - a, inp->on_dev, coff, *range); + gkyl_array_set_offset_range_cu_kernel<< > >( + out->on_dev, a, inp->on_dev, coff, *range + ); } -void -gkyl_array_scale_range_cu(struct gkyl_array *out, - double a, const struct gkyl_range *range) +void gkyl_array_scale_range_cu(struct gkyl_array *out, double a, const struct gkyl_range *range) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *range, out->ncomp); - gkyl_array_set_range_cu_kernel<<>>(out->on_dev, - a, out->on_dev, *range, *range); + gkyl_array_set_range_cu_kernel<< > >( + out->on_dev, a, out->on_dev, *range, *range + ); } -void -gkyl_array_shiftc_range_cu(struct gkyl_array* out, double a, unsigned k, const struct gkyl_range *range) +void gkyl_array_shiftc_range_cu( + struct gkyl_array *out, double a, unsigned k, const struct gkyl_range *range +) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *range, 1); - gkyl_array_shiftc_range_cu_kernel<<>>(out->on_dev, a, k, *range); + gkyl_array_shiftc_range_cu_kernel<< > >(out->on_dev, a, k, *range); } -void -gkyl_array_min_by_cell_range_cu(struct gkyl_array* out, const struct gkyl_array* inp, - double a, const struct gkyl_range *range) +void gkyl_array_min_by_cell_range_cu( + struct gkyl_array *out, const struct gkyl_array *inp, double a, const struct gkyl_range *range +) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *range, out->ncomp); - gkyl_array_min_by_cell_range_cu_kernel<<>>(out->on_dev, inp->on_dev, a, *range); + gkyl_array_min_by_cell_range_cu_kernel<< > >( + out->on_dev, inp->on_dev, a, *range + ); } -void -gkyl_array_copy_range_cu(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range) +void gkyl_array_copy_range_cu( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *range, out->ncomp); - gkyl_array_copy_range_cu_kernel<<>>(out->on_dev, - inp->on_dev, *range, *range); + gkyl_array_copy_range_cu_kernel<< > >(out->on_dev, inp->on_dev, *range, *range); } -void -gkyl_array_copy_range_to_range_cu(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *out_range, const struct gkyl_range *inp_range) +void gkyl_array_copy_range_to_range_cu( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *out_range, + const struct gkyl_range *inp_range +) { if (inp_range->volume > 0) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *inp_range, inp->ncomp); - gkyl_array_copy_range_cu_kernel<<>>(out->on_dev, - inp->on_dev, *out_range, *inp_range); + gkyl_array_copy_range_cu_kernel<< > >( + out->on_dev, inp->on_dev, *out_range, *inp_range + ); } } -void -gkyl_array_copy_to_buffer_cu(void *data, - const struct gkyl_array *arr, const struct gkyl_range *range) +void gkyl_array_copy_to_buffer_cu( + void *data, const struct gkyl_array *arr, const struct gkyl_range *range +) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *range, arr->ncomp); - gkyl_array_copy_to_buffer_cu_kernel<<>>(data, - arr->on_dev, *range); + gkyl_array_copy_to_buffer_cu_kernel<< > >(data, arr->on_dev, *range); } -void -gkyl_array_copy_from_buffer_cu(struct gkyl_array *arr, - const void *data, const struct gkyl_range *range) +void gkyl_array_copy_from_buffer_cu( + struct gkyl_array *arr, const void *data, const struct gkyl_range *range +) { - int nelem = range->volume*arr->ncomp; + int nelem = range->volume * arr->ncomp; int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(nelem, nthreads); - gkyl_array_copy_from_buffer_cu_kernel<<>>(arr->on_dev, - data, *range); + gkyl_array_copy_from_buffer_cu_kernel<< > >(arr->on_dev, data, *range); } -void -gkyl_array_copy_to_buffer_fn_cu(void *data, const struct gkyl_array *arr, - const struct gkyl_range *range, struct gkyl_array_copy_func *cf) +void gkyl_array_copy_to_buffer_fn_cu( + void *data, const struct gkyl_array *arr, const struct gkyl_range *range, + struct gkyl_array_copy_func *cf +) { if (range->volume > 0) { int nblocks = range->nblocks; int nthreads = range->nthreads; - gkyl_array_copy_to_buffer_fn_cu_kernel<<>>( - data, arr->on_dev, *range, cf); + gkyl_array_copy_to_buffer_fn_cu_kernel<< > >(data, arr->on_dev, *range, cf); } } -void -gkyl_array_flip_copy_to_buffer_fn_cu(void *data, const struct gkyl_array *arr, - int dir, const struct gkyl_range *range, struct gkyl_array_copy_func *cf) +void gkyl_array_flip_copy_to_buffer_fn_cu( + void *data, const struct gkyl_array *arr, int dir, const struct gkyl_range *range, + struct gkyl_array_copy_func *cf +) { if (range->volume > 0) { int nblocks = range->nblocks; @@ -868,17 +878,20 @@ gkyl_array_flip_copy_to_buffer_fn_cu(void *data, const struct gkyl_array *arr, struct gkyl_range buff_range; gkyl_range_init(&buff_range, range->ndim, range->lower, range->upper); - - gkyl_array_flip_copy_to_buffer_fn_cu_kernel<<>>(data, - arr->on_dev, dir, *range, buff_range, cf); + + gkyl_array_flip_copy_to_buffer_fn_cu_kernel<< > >( + data, arr->on_dev, dir, *range, buff_range, cf + ); } } -void -gkyl_array_max_by_cell_per_cell_avg_range_cu(struct gkyl_array *out, - const struct gkyl_array* inp, const struct gkyl_range *range) +void gkyl_array_max_by_cell_per_cell_avg_range_cu( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +) { dim3 dimGrid, dimBlock; gkyl_get_array_range_kernel_launch_dims(&dimGrid, &dimBlock, *range, 1); - gkyl_array_max_by_cell_per_cell_avg_range_cu_kernel<<>>(out->on_dev, inp->on_dev, *range); + gkyl_array_max_by_cell_per_cell_avg_range_cu_kernel<< > >( + out->on_dev, inp->on_dev, *range + ); } diff --git a/core/zero/array_reduce.c b/core/zero/array_reduce.c index 35f7740b99..3544233df7 100644 --- a/core/zero/array_reduce.c +++ b/core/zero/array_reduce.c @@ -3,23 +3,22 @@ #include #include -void -gkyl_array_reduce(double *out, const struct gkyl_array *arr, enum gkyl_array_op op) +void gkyl_array_reduce(double *out, const struct gkyl_array *arr, enum gkyl_array_op op) { assert(arr->type == GKYL_DOUBLE); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(arr)) { switch (op) { - case GKYL_MAX: - gkyl_array_reduce_max_cu(out, arr); - break; - case GKYL_MIN: - gkyl_array_reduce_min_cu(out, arr); - break; - case GKYL_SUM: - gkyl_array_reduce_sum_cu(out, arr); - break; + case GKYL_MAX: + gkyl_array_reduce_max_cu(out, arr); + break; + case GKYL_MIN: + gkyl_array_reduce_min_cu(out, arr); + break; + case GKYL_SUM: + gkyl_array_reduce_sum_cu(out, arr); + break; } return; } @@ -29,53 +28,62 @@ gkyl_array_reduce(double *out, const struct gkyl_array *arr, enum gkyl_array_op double *arr_d = arr->data; switch (op) { - case GKYL_MIN: - for (long k=0; ksize; ++i) { - const double *d = gkyl_array_cfetch(arr, i); - for (long k=0; ksize; ++i) { + const double *d = gkyl_array_cfetch(arr, i); + for (long k = 0; k < nc; ++k) { + out[k] = fmin(out[k], d[k]); } - break; + } + break; - case GKYL_MAX: - for (long k=0; ksize; ++i) { - const double *d = gkyl_array_cfetch(arr, i); - for (long k=0; ksize; ++i) { + const double *d = gkyl_array_cfetch(arr, i); + for (long k = 0; k < nc; ++k) { + out[k] = fmax(out[k], d[k]); } - break; + } + break; - case GKYL_SUM: - for (long k=0; ksize; ++i) { - const double *d = gkyl_array_cfetch(arr, i); - for (long k=0; ksize; ++i) { + const double *d = gkyl_array_cfetch(arr, i); + for (long k = 0; k < nc; ++k) { + out[k] += d[k]; } - break; + } + break; } } -void -gkyl_array_reduce_range(double *res, - const struct gkyl_array *arr, enum gkyl_array_op op, const struct gkyl_range *range) +void gkyl_array_reduce_range( + double *res, const struct gkyl_array *arr, enum gkyl_array_op op, const struct gkyl_range *range +) { assert(arr->type == GKYL_DOUBLE); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(arr)) { switch (op) { - case GKYL_MAX: - gkyl_array_reduce_range_max_cu(res, arr, range); - break; - case GKYL_MIN: - gkyl_array_reduce_range_min_cu(res, arr, range); - break; - case GKYL_SUM: - gkyl_array_reduce_range_sum_cu(res, arr, range); - break; + case GKYL_MAX: + gkyl_array_reduce_range_max_cu(res, arr, range); + break; + case GKYL_MIN: + gkyl_array_reduce_range_min_cu(res, arr, range); + break; + case GKYL_SUM: + gkyl_array_reduce_range_sum_cu(res, arr, range); + break; } return; } @@ -86,36 +94,44 @@ gkyl_array_reduce_range(double *res, gkyl_range_iter_init(&iter, range); switch (op) { - case GKYL_MIN: - for (long i=0; i __longlong_as_double(ret)) - { + while (val > __longlong_as_double(ret)) { unsigned long long int old = ret; - if((ret = atomicCAS((unsigned long long int*)address, old, __double_as_longlong(val))) == old) + if ((ret = atomicCAS((unsigned long long int *)address, old, __double_as_longlong(val))) == + old) { break; + } } return __longlong_as_double(ret); } -__device__ static __forceinline__ double -atomicMin_double(double *address, double val) +__device__ static __forceinline__ double atomicMin_double(double *address, double val) { unsigned long long int ret = __double_as_longlong(*address); - while(val < __longlong_as_double(ret)) - { + while (val < __longlong_as_double(ret)) { unsigned long long int old = ret; - if((ret = atomicCAS((unsigned long long int*)address, old, __double_as_longlong(val))) == old) + if ((ret = atomicCAS((unsigned long long int *)address, old, __double_as_longlong(val))) == + old) { break; + } } return __longlong_as_double(ret); } -template -__global__ void -arrayMax_blockRedAtomic_cub(const struct gkyl_array* inp, double* out) +template +__global__ void arrayMax_blockRedAtomic_cub(const struct gkyl_array *inp, double *out) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -61,18 +60,21 @@ arrayMax_blockRedAtomic_cub(const struct gkyl_array* inp, double* out) long nCells = inp->size; size_t nComp = inp->ncomp; - const double *inp_d = (const double*) inp->data; + const double *inp_d = (const double *)inp->data; for (size_t k = 0; k < nComp; ++k) { out[k] = -DBL_MAX; double f = -DBL_MAX; - if (linc < nCells) f = inp_d[linc*nComp+k]; + if (linc < nCells) { + f = inp_d[linc * nComp + k]; + } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 - ::cuda::maximum() + ::cuda::maximum() #else - cub::Max() + cub::Max() #endif ); if (threadIdx.x < BLOCKSIZE) { @@ -82,10 +84,11 @@ arrayMax_blockRedAtomic_cub(const struct gkyl_array* inp, double* out) } template -__global__ void -arrayMax_range_blockRedAtomic_cub(const struct gkyl_array* inp, const struct gkyl_range range, double* out) +__global__ void arrayMax_range_blockRedAtomic_cub( + const struct gkyl_array *inp, const struct gkyl_range range, double *out +) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -102,15 +105,18 @@ arrayMax_range_blockRedAtomic_cub(const struct gkyl_array* inp, const struct gky out[k] = -DBL_MAX; gkyl_sub_range_inv_idx(&range, linc, idx); long start = gkyl_range_idx(&range, idx); - const double* fptr = (const double*) gkyl_array_cfetch(inp, start); + const double *fptr = (const double *)gkyl_array_cfetch(inp, start); double f = -DBL_MAX; - if (linc < nCells) f = fptr[k]; + if (linc < nCells) { + f = fptr[k]; + } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 - ::cuda::maximum() + ::cuda::maximum() #else - cub::Max() + cub::Max() #endif ); if (threadIdx.x < BLOCKSIZE) { @@ -119,31 +125,30 @@ arrayMax_range_blockRedAtomic_cub(const struct gkyl_array* inp, const struct gky } } -void -gkyl_array_reduce_max_cu(double *out_d, const struct gkyl_array* inp) +void gkyl_array_reduce_max_cu(double *out_d, const struct gkyl_array *inp) { - const int nthreads = GKYL_DEFAULT_NUM_THREADS; + const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(inp->size, nthreads); - arrayMax_blockRedAtomic_cub<<>>(inp->on_dev, out_d); + arrayMax_blockRedAtomic_cub<< > >(inp->on_dev, out_d); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } -void -gkyl_array_reduce_range_max_cu(double *out_d, const struct gkyl_array* inp, const struct gkyl_range *range) +void gkyl_array_reduce_range_max_cu( + double *out_d, const struct gkyl_array *inp, const struct gkyl_range *range +) { const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(range->volume, nthreads); - arrayMax_range_blockRedAtomic_cub<<>>(inp->on_dev, *range, out_d); + arrayMax_range_blockRedAtomic_cub<< > >(inp->on_dev, *range, out_d); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } -template -__global__ void -arrayMin_blockRedAtomic_cub(const struct gkyl_array* inp, double* out) +template +__global__ void arrayMin_blockRedAtomic_cub(const struct gkyl_array *inp, double *out) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -154,18 +159,21 @@ arrayMin_blockRedAtomic_cub(const struct gkyl_array* inp, double* out) long nCells = inp->size; size_t nComp = inp->ncomp; - const double *inp_d = (const double*) inp->data; + const double *inp_d = (const double *)inp->data; for (size_t k = 0; k < nComp; ++k) { out[k] = DBL_MAX; double f = DBL_MAX; - if (linc < nCells) f = inp_d[linc*nComp+k]; + if (linc < nCells) { + f = inp_d[linc * nComp + k]; + } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 - ::cuda::minimum() + ::cuda::minimum() #else - cub::Min() + cub::Min() #endif ); if (threadIdx.x < BLOCKSIZE) { @@ -175,10 +183,11 @@ arrayMin_blockRedAtomic_cub(const struct gkyl_array* inp, double* out) } template -__global__ void -arrayMin_range_blockRedAtomic_cub(const struct gkyl_array* inp, const struct gkyl_range range, double* out) +__global__ void arrayMin_range_blockRedAtomic_cub( + const struct gkyl_array *inp, const struct gkyl_range range, double *out +) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -195,48 +204,50 @@ arrayMin_range_blockRedAtomic_cub(const struct gkyl_array* inp, const struct gky out[k] = DBL_MAX; gkyl_sub_range_inv_idx(&range, linc, idx); long start = gkyl_range_idx(&range, idx); - const double* fptr = (const double*) gkyl_array_cfetch(inp, start); + const double *fptr = (const double *)gkyl_array_cfetch(inp, start); double f = DBL_MAX; - if (linc < nCells) f = fptr[k]; + if (linc < nCells) { + f = fptr[k]; + } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 - ::cuda::minimum() + ::cuda::minimum() #else - cub::Min() + cub::Min() #endif ); - if (threadIdx.x < BLOCKSIZE) { + if (threadIdx.x < BLOCKSIZE) { atomicMin_double(&out[k], bResult); } } } -void -gkyl_array_reduce_min_cu(double *out_d, const struct gkyl_array* inp) +void gkyl_array_reduce_min_cu(double *out_d, const struct gkyl_array *inp) { - const int nthreads = GKYL_DEFAULT_NUM_THREADS; + const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(inp->size, nthreads); - arrayMin_blockRedAtomic_cub<<>>(inp->on_dev, out_d); + arrayMin_blockRedAtomic_cub<< > >(inp->on_dev, out_d); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } -void -gkyl_array_reduce_range_min_cu(double *out_d, const struct gkyl_array* inp, const struct gkyl_range *range) +void gkyl_array_reduce_range_min_cu( + double *out_d, const struct gkyl_array *inp, const struct gkyl_range *range +) { const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(range->volume, nthreads); - arrayMin_range_blockRedAtomic_cub<<>>(inp->on_dev, *range, out_d); + arrayMin_range_blockRedAtomic_cub<< > >(inp->on_dev, *range, out_d); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } -template -__global__ void -arraySum_blockRedAtomic_cub(const struct gkyl_array* inp, double* out) +template +__global__ void arraySum_blockRedAtomic_cub(const struct gkyl_array *inp, double *out) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -247,17 +258,20 @@ arraySum_blockRedAtomic_cub(const struct gkyl_array* inp, double* out) long nCells = inp->size; size_t nComp = inp->ncomp; - const double *inp_d = (const double*) inp->data; + const double *inp_d = (const double *)inp->data; for (size_t k = 0; k < nComp; ++k) { double f = 0; - if (linc < nCells) f = inp_d[linc*nComp+k]; + if (linc < nCells) { + f = inp_d[linc * nComp + k]; + } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 - ::cuda::std::plus() + ::cuda::std::plus() #else - cub::Sum() + cub::Sum() #endif ); if (threadIdx.x == 0) { @@ -267,10 +281,11 @@ arraySum_blockRedAtomic_cub(const struct gkyl_array* inp, double* out) } template -__global__ void -arraySum_range_blockRedAtomic_cub(const struct gkyl_array* inp, const struct gkyl_range range, double* out) +__global__ void arraySum_range_blockRedAtomic_cub( + const struct gkyl_array *inp, const struct gkyl_range range, double *out +) { - unsigned long linc = blockIdx.x*blockDim.x + threadIdx.x; + unsigned long linc = blockIdx.x * blockDim.x + threadIdx.x; // Specialize BlockReduce for type double. typedef cub::BlockReduce BlockReduceT; @@ -286,15 +301,18 @@ arraySum_range_blockRedAtomic_cub(const struct gkyl_array* inp, const struct gky for (size_t k = 0; k < nComp; ++k) { gkyl_sub_range_inv_idx(&range, linc, idx); long start = gkyl_range_idx(&range, idx); - const double* fptr = (const double*) gkyl_array_cfetch(inp, start); + const double *fptr = (const double *)gkyl_array_cfetch(inp, start); double f = 0; - if (linc < nCells) f = fptr[k]; + if (linc < nCells) { + f = fptr[k]; + } double bResult = 0; - bResult = BlockReduceT(temp).Reduce(f, + bResult = BlockReduceT(temp).Reduce( + f, #if CUDART_VERSION > 12090 - ::cuda::std::plus() + ::cuda::std::plus() #else - cub::Sum() + cub::Sum() #endif ); if (threadIdx.x == 0) { @@ -303,27 +321,26 @@ arraySum_range_blockRedAtomic_cub(const struct gkyl_array* inp, const struct gky } } -void -gkyl_array_reduce_sum_cu(double *out_d, const struct gkyl_array* inp) +void gkyl_array_reduce_sum_cu(double *out_d, const struct gkyl_array *inp) { - gkyl_cu_memset(out_d, 0, inp->ncomp*sizeof(double)); - - const int nthreads = GKYL_DEFAULT_NUM_THREADS; + gkyl_cu_memset(out_d, 0, inp->ncomp * sizeof(double)); + + const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(inp->size, nthreads); - arraySum_blockRedAtomic_cub<<>>(inp->on_dev, out_d); + arraySum_blockRedAtomic_cub<< > >(inp->on_dev, out_d); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } -void -gkyl_array_reduce_range_sum_cu(double *out_d, const struct gkyl_array* inp, const struct gkyl_range *range) +void gkyl_array_reduce_range_sum_cu( + double *out_d, const struct gkyl_array *inp, const struct gkyl_range *range +) { - gkyl_cu_memset(out_d, 0, inp->ncomp*sizeof(double)); - + gkyl_cu_memset(out_d, 0, inp->ncomp * sizeof(double)); + const int nthreads = GKYL_DEFAULT_NUM_THREADS; int nblocks = gkyl_int_div_up(range->volume, nthreads); - arraySum_range_blockRedAtomic_cub<<>>(inp->on_dev, *range, out_d); + arraySum_range_blockRedAtomic_cub<< > >(inp->on_dev, *range, out_d); // device synchronize required because out_d may be host pinned memory cudaDeviceSynchronize(); } - diff --git a/core/zero/array_rio.c b/core/zero/array_rio.c index d9e7a1a6bf..b3c6e104f2 100644 --- a/core/zero/array_rio.c +++ b/core/zero/array_rio.c @@ -21,15 +21,13 @@ static const char *array_rio_status_msg[] = { [GKYL_ARRAY_RIO_META_FAILED] = "Metadata output failed" }; -const char* -gkyl_array_rio_status_msg(enum gkyl_array_rio_status status) +const char *gkyl_array_rio_status_msg(enum gkyl_array_rio_status status) { return array_rio_status_msg[status]; } static void -sub_array_write_priv(const struct gkyl_range *range, - const struct gkyl_array *arr, FILE *fp) +sub_array_write_priv(const struct gkyl_range *range, const struct gkyl_array *arr, FILE *fp) { #define _F(loc) gkyl_array_cfetch(arr, loc) @@ -43,13 +41,12 @@ sub_array_write_priv(const struct gkyl_range *range, while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&skip.range, iter.idx); - fwrite(_F(start), arr->esznc*skip.delta, 1, fp); + fwrite(_F(start), arr->esznc * skip.delta, 1, fp); } #undef _F } -int -gkyl_header_meta_write_fp(const struct gkyl_array_header_info *hdr, FILE *fp) +int gkyl_header_meta_write_fp(const struct gkyl_array_header_info *hdr, FILE *fp) { const char g0[5] = "gkyl0"; @@ -60,18 +57,19 @@ gkyl_header_meta_write_fp(const struct gkyl_array_header_info *hdr, FILE *fp) fwrite(&hdr->file_type, sizeof(uint64_t), 1, fp); uint64_t meta_size = hdr->meta_size; fwrite(&meta_size, sizeof(uint64_t), 1, fp); - if (meta_size > 0) + if (meta_size > 0) { fwrite(hdr->meta, meta_size, 1, fp); + } return GKYL_ARRAY_RIO_SUCCESS; } -int -gkyl_grid_sub_array_header_write_fp(const struct gkyl_rect_grid *grid, - const struct gkyl_array_header_info *hdr, FILE *fp) +int gkyl_grid_sub_array_header_write_fp( + const struct gkyl_rect_grid *grid, const struct gkyl_array_header_info *hdr, FILE *fp +) { - gkyl_header_meta_write_fp(hdr, fp); - + gkyl_header_meta_write_fp(hdr, fp); + // Version 0 format is used for rest of the header uint64_t real_type = gkyl_array_data_type[hdr->etype]; fwrite(&real_type, sizeof(uint64_t), 1, fp); @@ -83,30 +81,32 @@ gkyl_grid_sub_array_header_write_fp(const struct gkyl_rect_grid *grid, return GKYL_ARRAY_RIO_SUCCESS; } -int -gkyl_header_meta_read_fp(struct gkyl_array_header_info *hdr, FILE *fp) +int gkyl_header_meta_read_fp(struct gkyl_array_header_info *hdr, FILE *fp) { size_t frr; hdr->meta_size = 0; char g0[6]; frr = fread(g0, sizeof(char[5]), 1, fp); // no trailing '\0' - g0[5] = '\0'; // add the NULL - if (strcmp(g0, "gkyl0") != 0) + g0[5] = '\0'; // add the NULL + if (strcmp(g0, "gkyl0") != 0) { return GKYL_ARRAY_RIO_BAD_VERSION; - + } + uint64_t version; frr = fread(&version, sizeof(uint64_t), 1, fp); - if (version != 1) + if (version != 1) { return GKYL_ARRAY_RIO_BAD_VERSION; + } uint64_t file_type; frr = fread(&file_type, sizeof(uint64_t), 1, fp); uint64_t meta_size; frr = fread(&meta_size, sizeof(uint64_t), 1, fp); - if (1 != frr) + if (1 != frr) { return GKYL_ARRAY_RIO_FREAD_FAILED; + } hdr->meta = 0; if (meta_size > 0) { @@ -122,36 +122,40 @@ gkyl_header_meta_read_fp(struct gkyl_array_header_info *hdr, FILE *fp) hdr->tot_cells = 0; hdr->meta_size = meta_size; - return GKYL_ARRAY_RIO_SUCCESS; + return GKYL_ARRAY_RIO_SUCCESS; } -static int -grid_sub_array_header_read_fp(struct gkyl_rect_grid *grid, - struct gkyl_array_header_info *hdr, bool read_meta, FILE *fp) +static int grid_sub_array_header_read_fp( + struct gkyl_rect_grid *grid, struct gkyl_array_header_info *hdr, bool read_meta, FILE *fp +) { size_t frr; hdr->meta_size = 0; char g0[6]; frr = fread(g0, sizeof(char[5]), 1, fp); // no trailing '\0' - g0[5] = '\0'; // add the NULL - if (strcmp(g0, "gkyl0") != 0) + g0[5] = '\0'; // add the NULL + if (strcmp(g0, "gkyl0") != 0) { return GKYL_ARRAY_RIO_BAD_VERSION; - + } + uint64_t version; frr = fread(&version, sizeof(uint64_t), 1, fp); - if (version != 1) + if (version != 1) { return GKYL_ARRAY_RIO_BAD_VERSION; + } uint64_t file_type; frr = fread(&file_type, sizeof(uint64_t), 1, fp); - if (1 != frr) + if (1 != frr) { return GKYL_ARRAY_RIO_FREAD_FAILED; + } uint64_t meta_size; frr = fread(&meta_size, sizeof(uint64_t), 1, fp); - if (1 != frr) + if (1 != frr) { return GKYL_ARRAY_RIO_FREAD_FAILED; + } if (meta_size > 0) { if (read_meta) { @@ -160,30 +164,34 @@ grid_sub_array_header_read_fp(struct gkyl_rect_grid *grid, gkyl_free(hdr->meta); return GKYL_ARRAY_RIO_FREAD_FAILED; } - } - else { + } else { fseek(fp, meta_size, SEEK_CUR); } } uint64_t real_type = 0; - if (1 != fread(&real_type, sizeof(uint64_t), 1, fp)) + if (1 != fread(&real_type, sizeof(uint64_t), 1, fp)) { return GKYL_ARRAY_RIO_FREAD_FAILED; + } gkyl_rect_grid_read(grid, fp); uint64_t esznc = 0; - if (1 != fread(&esznc, sizeof(uint64_t), 1, fp)) - return GKYL_ARRAY_RIO_FREAD_FAILED;; + if (1 != fread(&esznc, sizeof(uint64_t), 1, fp)) { + return GKYL_ARRAY_RIO_FREAD_FAILED; + }; uint64_t tot_cells = 0; - if (1 != fread(&tot_cells, sizeof(uint64_t), 1, fp)) - return GKYL_ARRAY_RIO_FREAD_FAILED;; + if (1 != fread(&tot_cells, sizeof(uint64_t), 1, fp)) { + return GKYL_ARRAY_RIO_FREAD_FAILED; + }; uint64_t nrange = 1; - if (file_type == gkyl_file_type_int[GKYL_MULTI_RANGE_DATA_FILE]) - if (1 != fread(&nrange, sizeof(uint64_t), 1, fp)) + if (file_type == gkyl_file_type_int[GKYL_MULTI_RANGE_DATA_FILE]) { + if (1 != fread(&nrange, sizeof(uint64_t), 1, fp)) { return GKYL_ARRAY_RIO_FREAD_FAILED; + } + } hdr->file_type = file_type; hdr->etype = gkyl_array_code_to_data_type[real_type]; @@ -195,76 +203,76 @@ grid_sub_array_header_read_fp(struct gkyl_rect_grid *grid, return GKYL_ARRAY_RIO_SUCCESS; } -int -gkyl_grid_sub_array_header_read_fp(struct gkyl_rect_grid *grid, - struct gkyl_array_header_info *hdr, FILE *fp) +int gkyl_grid_sub_array_header_read_fp( + struct gkyl_rect_grid *grid, struct gkyl_array_header_info *hdr, FILE *fp +) { return grid_sub_array_header_read_fp(grid, hdr, true, fp); } -void -gkyl_grid_sub_array_header_release(struct gkyl_array_header_info *hdr) +void gkyl_grid_sub_array_header_release(struct gkyl_array_header_info *hdr) { - if (hdr->meta_size>0) { + if (hdr->meta_size > 0) { gkyl_free(hdr->meta); hdr->meta_size = 0; } } -enum gkyl_array_rio_status -gkyl_grid_sub_array_header_read(struct gkyl_rect_grid *grid, - struct gkyl_array_header_info *hdr, const char *fname) +enum gkyl_array_rio_status gkyl_grid_sub_array_header_read( + struct gkyl_rect_grid *grid, struct gkyl_array_header_info *hdr, const char *fname +) { enum gkyl_array_rio_status status = GKYL_ARRAY_RIO_FOPEN_FAILED; FILE *fp = 0; - with_file(fp, fname, "r") { + with_file(fp, fname, "r") + { status = gkyl_grid_sub_array_header_read_fp(grid, hdr, fp); } return status; } -void -gkyl_array_header_info_release(struct gkyl_array_header_info *info) +void gkyl_array_header_info_release(struct gkyl_array_header_info *info) { - if (info->meta_size > 0) + if (info->meta_size > 0) { gkyl_free(info->meta); + } } -enum gkyl_array_rio_status -gkyl_grid_sub_array_write(const struct gkyl_rect_grid *grid, const struct gkyl_range *range, - const struct gkyl_msgpack_data *meta, - const struct gkyl_array *arr, const char *fname) +enum gkyl_array_rio_status gkyl_grid_sub_array_write( + const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + const struct gkyl_msgpack_data *meta, const struct gkyl_array *arr, const char *fname +) { enum gkyl_array_rio_status status = GKYL_ARRAY_RIO_FOPEN_FAILED; FILE *fp = 0; int err; - with_file (fp, fname, "w") { - - status = gkyl_grid_sub_array_header_write_fp(grid, - &(struct gkyl_array_header_info) { - .file_type = gkyl_file_type_int[GKYL_FIELD_DATA_FILE], + with_file(fp, fname, "w") + { + status = gkyl_grid_sub_array_header_write_fp( + grid, + &(struct gkyl_array_header_info + ){.file_type = gkyl_file_type_int[GKYL_FIELD_DATA_FILE], .etype = arr->type, .esznc = arr->esznc, .tot_cells = range->volume, .meta_size = meta ? meta->meta_sz : 0, - .meta = meta ? meta->meta : 0 - }, + .meta = meta ? meta->meta : 0}, fp ); - if (status == GKYL_ARRAY_RIO_SUCCESS) + if (status == GKYL_ARRAY_RIO_SUCCESS) { sub_array_write_priv(range, arr, fp); + } } return status; } -static enum gkyl_array_rio_status -grid_sub_array_read_ft_1(const struct gkyl_rect_grid *grid, - struct gkyl_array_header_info *hdr, const struct gkyl_range *range, - struct gkyl_array *arr, FILE *fp) +static enum gkyl_array_rio_status grid_sub_array_read_ft_1( + const struct gkyl_rect_grid *grid, struct gkyl_array_header_info *hdr, + const struct gkyl_range *range, struct gkyl_array *arr, FILE *fp +) { - size_t loc = gkyl_base_hdr_size(hdr->meta_size) - + gkyl_file_type_1_hrd_size(grid->ndim); + size_t loc = gkyl_base_hdr_size(hdr->meta_size) + gkyl_file_type_1_hrd_size(grid->ndim); fseek(fp, loc, SEEK_SET); struct gkyl_range blk_rng; @@ -275,53 +283,55 @@ grid_sub_array_read_ft_1(const struct gkyl_rect_grid *grid, if (not_empty) { uint64_t sz = hdr->tot_cells; - gkyl_mem_buff buff = gkyl_mem_buff_new(sz*hdr->esznc); + gkyl_mem_buff buff = gkyl_mem_buff_new(sz * hdr->esznc); - if (1 != fread(gkyl_mem_buff_data(buff), sz*hdr->esznc, 1, fp)) { + if (1 != fread(gkyl_mem_buff_data(buff), sz * hdr->esznc, 1, fp)) { gkyl_mem_buff_release(buff); return GKYL_ARRAY_RIO_FREAD_FAILED; } - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &inter); while (gkyl_range_iter_next(&iter)) { - char *out = gkyl_array_fetch(arr, gkyl_range_idx(range, iter.idx)); - const char *inp = gkyl_mem_buff_data(buff) + hdr->esznc*gkyl_range_idx(&blk_rng, iter.idx); + const char *inp = gkyl_mem_buff_data(buff) + hdr->esznc * gkyl_range_idx(&blk_rng, iter.idx); memcpy(out, inp, hdr->esznc); - } + } gkyl_mem_buff_release(buff); } - + return GKYL_ARRAY_RIO_SUCCESS; } -static enum gkyl_array_rio_status -grid_sub_array_read_ft_3(const struct gkyl_rect_grid *grid, - struct gkyl_array_header_info *hdr, const struct gkyl_range *range, - struct gkyl_array *arr, FILE *fp) +static enum gkyl_array_rio_status grid_sub_array_read_ft_3( + const struct gkyl_rect_grid *grid, struct gkyl_array_header_info *hdr, + const struct gkyl_range *range, struct gkyl_array *arr, FILE *fp +) { size_t rng_sz = gkyl_file_type_3_range_hrd_size(grid->ndim); size_t loc = gkyl_base_hdr_size(hdr->meta_size) + gkyl_file_type_3_hrd_size(grid->ndim); gkyl_mem_buff buff = gkyl_mem_buff_new(10); // will be reallocated - for (int r=0; rnrange; ++r) { + for (int r = 0; r < hdr->nrange; ++r) { uint64_t sz, loidx[GKYL_MAX_DIM], upidx[GKYL_MAX_DIM]; fseek(fp, loc, SEEK_SET); // read lower, upper indices and number of elements stored - if (1 != fread(loidx, sizeof(uint64_t[grid->ndim]), 1, fp)) + if (1 != fread(loidx, sizeof(uint64_t[grid->ndim]), 1, fp)) { return GKYL_ARRAY_RIO_FREAD_FAILED; - if (1 != fread(upidx, sizeof(uint64_t[grid->ndim]), 1, fp)) + } + if (1 != fread(upidx, sizeof(uint64_t[grid->ndim]), 1, fp)) { return GKYL_ARRAY_RIO_FREAD_FAILED; - if (1 != fread(&sz, sizeof(uint64_t), 1, fp)) + } + if (1 != fread(&sz, sizeof(uint64_t), 1, fp)) { return GKYL_ARRAY_RIO_FREAD_FAILED; + } // construct range of indices corresponding to data in block - int loidx_i[GKYL_MAX_DIM]= { 0 } , upidx_i[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim; ++d) { + int loidx_i[GKYL_MAX_DIM] = {0}, upidx_i[GKYL_MAX_DIM] = {0}; + for (int d = 0; d < grid->ndim; ++d) { loidx_i[d] = loidx[d]; upidx_i[d] = upidx[d]; } @@ -331,9 +341,8 @@ grid_sub_array_read_ft_3(const struct gkyl_rect_grid *grid, struct gkyl_range inter; // intersection int not_empty = gkyl_range_intersect(&inter, &blk_rng, range); if (not_empty) { - - buff = gkyl_mem_buff_resize(buff, sz*hdr->esznc); - if (1 != fread(gkyl_mem_buff_data(buff), sz*hdr->esznc, 1, fp)) { + buff = gkyl_mem_buff_resize(buff, sz * hdr->esznc); + if (1 != fread(gkyl_mem_buff_data(buff), sz * hdr->esznc, 1, fp)) { gkyl_mem_buff_release(buff); return GKYL_ARRAY_RIO_FREAD_FAILED; } @@ -342,53 +351,59 @@ grid_sub_array_read_ft_3(const struct gkyl_rect_grid *grid, gkyl_range_iter_init(&iter, &inter); while (gkyl_range_iter_next(&iter)) { char *out = gkyl_array_fetch(arr, gkyl_range_idx(range, iter.idx)); - const char *inp = gkyl_mem_buff_data(buff) + hdr->esznc*gkyl_range_idx(&blk_rng, iter.idx); + const char *inp = + gkyl_mem_buff_data(buff) + hdr->esznc * gkyl_range_idx(&blk_rng, iter.idx); memcpy(out, inp, hdr->esznc); } } - loc += rng_sz + sz*hdr->esznc; + loc += rng_sz + sz * hdr->esznc; } gkyl_mem_buff_release(buff); - + return GKYL_ARRAY_RIO_SUCCESS; } -enum gkyl_array_rio_status -gkyl_grid_sub_array_read(struct gkyl_rect_grid *grid, const struct gkyl_range *range, - struct gkyl_array *arr, const char *fname) +enum gkyl_array_rio_status gkyl_grid_sub_array_read( + struct gkyl_rect_grid *grid, const struct gkyl_range *range, struct gkyl_array *arr, + const char *fname +) { enum gkyl_array_rio_status status = GKYL_ARRAY_RIO_FOPEN_FAILED; struct gkyl_array_header_info hdr; FILE *fp = 0; - with_file (fp, fname, "r") { + with_file(fp, fname, "r") + { grid_sub_array_header_read_fp(grid, &hdr, false, fp); - - if (hdr.file_type == 1) + + if (hdr.file_type == 1) { status = grid_sub_array_read_ft_1(grid, &hdr, range, arr, fp); - if (hdr.file_type == 3) + } + if (hdr.file_type == 3) { status = grid_sub_array_read_ft_3(grid, &hdr, range, arr, fp); + } } return status; } -struct gkyl_array* -gkyl_grid_array_new_from_file(struct gkyl_rect_grid *grid, const char* fname) +struct gkyl_array *gkyl_grid_array_new_from_file(struct gkyl_rect_grid *grid, const char *fname) { struct gkyl_array *arr = 0; struct gkyl_array_header_info hdr; enum gkyl_array_rio_status status = GKYL_ARRAY_RIO_FREAD_FAILED; FILE *fp = 0; - with_file (fp, fname, "r") { + with_file(fp, fname, "r") + { status = grid_sub_array_header_read_fp(grid, &hdr, false, fp); } - if (status != GKYL_ARRAY_RIO_SUCCESS) + if (status != GKYL_ARRAY_RIO_SUCCESS) { return 0; + } - size_t nc = hdr.esznc/gkyl_elem_type_size[hdr.etype]; + size_t nc = hdr.esznc / gkyl_elem_type_size[hdr.etype]; arr = gkyl_array_new(hdr.etype, nc, hdr.tot_cells); struct gkyl_range range; gkyl_range_init_from_shape1(&range, grid->ndim, grid->cells); @@ -399,6 +414,6 @@ gkyl_grid_array_new_from_file(struct gkyl_rect_grid *grid, const char* fname) gkyl_array_release(arr); arr = 0; } - + return arr; } diff --git a/core/zero/array_rio_format_desc.c b/core/zero/array_rio_format_desc.c index cfb5106ab8..f50344bd31 100644 --- a/core/zero/array_rio_format_desc.c +++ b/core/zero/array_rio_format_desc.c @@ -6,8 +6,7 @@ #include -size_t -gkyl_base_hdr_size(size_t meta_sz) +size_t gkyl_base_hdr_size(size_t meta_sz) { size_t sz = 0; // magic string @@ -22,8 +21,7 @@ gkyl_base_hdr_size(size_t meta_sz) return sz; } -size_t -gkyl_file_type_1_partial_hrd_size(int ndim) +size_t gkyl_file_type_1_partial_hrd_size(int ndim) { size_t sz = 0; // real_type @@ -33,12 +31,11 @@ gkyl_file_type_1_partial_hrd_size(int ndim) // cells sz += sizeof(uint64_t[ndim]); // lower, upper - sz += sizeof(double[2*ndim]); + sz += sizeof(double[2 * ndim]); return sz; } -size_t -gkyl_file_type_1_hrd_size(int ndim) +size_t gkyl_file_type_1_hrd_size(int ndim) { size_t sz = gkyl_file_type_1_partial_hrd_size(ndim); // esznc @@ -48,8 +45,7 @@ gkyl_file_type_1_hrd_size(int ndim) return sz; } -size_t -gkyl_file_type_2_hrd_size(void) +size_t gkyl_file_type_2_hrd_size(void) { size_t sz = 0; // real_type @@ -61,58 +57,55 @@ gkyl_file_type_2_hrd_size(void) return sz; } -size_t -gkyl_file_type_3_hrd_size(int ndim) +size_t gkyl_file_type_3_hrd_size(int ndim) { size_t sz = gkyl_file_type_1_hrd_size(ndim); sz += sizeof(uint64_t); // nrange return sz; } -size_t -gkyl_file_type_3_range_hrd_size(int ndim) +size_t gkyl_file_type_3_range_hrd_size(int ndim) { size_t sz = 0; // loidx and upidx - sz += sizeof(uint64_t[2*ndim]); + sz += sizeof(uint64_t[2 * ndim]); sz += sizeof(uint64_t); return sz; } -int -gkyl_get_gkyl_file_type(const char *fname) +int gkyl_get_gkyl_file_type(const char *fname) { int file_type = -1; FILE *fp = 0; - with_file(fp, fname, "r") { + with_file(fp, fname, "r") + { size_t frr; char g0[6]; frr = fread(g0, sizeof(char[5]), 1, fp); // no trailing '\0' - g0[5] = '\0'; // add the NULL + g0[5] = '\0'; // add the NULL if (strcmp(g0, "gkyl0") != 0) { file_type = -1; goto finish_with_file; } - + uint64_t version; frr = fread(&version, sizeof(uint64_t), 1, fp); if (version != 1) { file_type = -1; goto finish_with_file; } - + uint64_t file_type_u64; frr = fread(&file_type_u64, sizeof(uint64_t), 1, fp); if (1 != frr) { file_type = -1; - goto finish_with_file; + goto finish_with_file; } file_type = file_type_u64; - - finish_with_file: - ; + +finish_with_file:; } return file_type; } diff --git a/core/zero/basis.c b/core/zero/basis.c index d4ee9c373f..867c9bbb73 100644 --- a/core/zero/basis.c +++ b/core/zero/basis.c @@ -1,38 +1,32 @@ #include #include -void -gkyl_cart_modal_basis_release(struct gkyl_basis *basis) +void gkyl_cart_modal_basis_release(struct gkyl_basis *basis) { gkyl_free(basis); } -void -gkyl_cart_modal_basis_release_cu(struct gkyl_basis *basis) +void gkyl_cart_modal_basis_release_cu(struct gkyl_basis *basis) { gkyl_cu_free(basis); } -unsigned -gkyl_cart_modal_basis_get_ndim(const struct gkyl_basis *basis) +unsigned gkyl_cart_modal_basis_get_ndim(const struct gkyl_basis *basis) { return basis->ndim; } -unsigned -gkyl_cart_modal_basis_get_poly_order(const struct gkyl_basis *basis) +unsigned gkyl_cart_modal_basis_get_poly_order(const struct gkyl_basis *basis) { return basis->poly_order; } -unsigned -gkyl_cart_modal_basis_get_num_basis(const struct gkyl_basis *basis) +unsigned gkyl_cart_modal_basis_get_num_basis(const struct gkyl_basis *basis) { return basis->num_basis; } -enum -gkyl_basis_type gkyl_cart_modal_basis_get_type(const struct gkyl_basis *basis) +enum gkyl_basis_type gkyl_cart_modal_basis_get_type(const struct gkyl_basis *basis) { return basis->b_type; } diff --git a/core/zero/block_geom.c b/core/zero/block_geom.c index e8f022131f..323ab9aefb 100644 --- a/core/zero/block_geom.c +++ b/core/zero/block_geom.c @@ -9,12 +9,11 @@ struct gkyl_block_geom { int num_blocks; // total number of blocks struct gkyl_block_geom_info *blocks; // info for each block struct gkyl_block_topo *btopo; // topology of blocks - + struct gkyl_ref_count ref_count; }; -static void -block_geom_free(const struct gkyl_ref_count *ref) +static void block_geom_free(const struct gkyl_ref_count *ref) { struct gkyl_block_geom *bgeom = container_of(ref, struct gkyl_block_geom, ref_count); gkyl_free(bgeom->blocks); @@ -22,8 +21,7 @@ block_geom_free(const struct gkyl_ref_count *ref) gkyl_free(bgeom); } -struct gkyl_block_geom* -gkyl_block_geom_new(int ndim, int nblocks) +struct gkyl_block_geom *gkyl_block_geom_new(int ndim, int nblocks) { struct gkyl_block_geom *bgeom = gkyl_malloc(sizeof(struct gkyl_block_geom)); bgeom->ndim = ndim; @@ -37,35 +35,37 @@ gkyl_block_geom_new(int ndim, int nblocks) return bgeom; } -int -gkyl_block_geom_ndim(const struct gkyl_block_geom *bgeom) +int gkyl_block_geom_ndim(const struct gkyl_block_geom *bgeom) { return bgeom->ndim; } -int -gkyl_block_geom_num_blocks(const struct gkyl_block_geom *bgeom) +int gkyl_block_geom_num_blocks(const struct gkyl_block_geom *bgeom) { return bgeom->num_blocks; } -void -gkyl_block_geom_set_block(struct gkyl_block_geom *bgeom, int bidx, - const struct gkyl_block_geom_info *info) +void gkyl_block_geom_set_block( + struct gkyl_block_geom *bgeom, int bidx, const struct gkyl_block_geom_info *info +) { memcpy(&bgeom->blocks[bidx], info, sizeof(struct gkyl_block_geom_info)); - - for (int d=0; dndim; ++d) + + for (int d = 0; d < bgeom->ndim; ++d) { bgeom->blocks[bidx].cuts[d] = info->cuts[d] > 0 ? info->cuts[d] : 1; - + } + // set topology information - for (int i=0; indim; ++i) - for (int e=0; e<2; ++e) - bgeom->btopo->conn[bidx].connections[i][e] = info->connections[i][e]; + for (int i = 0; i < bgeom->ndim; ++i) { + for (int e = 0; e < 2; ++e) { + bgeom->btopo->conn[bidx].connections[i][e] = info->connections[i][e]; + } + } } -void -gkyl_block_geom_reset_block_extents(struct gkyl_block_geom *bgeom, int bidx, double *lower, double *upper) +void gkyl_block_geom_reset_block_extents( + struct gkyl_block_geom *bgeom, int bidx, double *lower, double *upper +) { struct gkyl_block_geom_info *bgi = &bgeom->blocks[bidx]; for (int i = 0; i < bgeom->ndim; ++i) { @@ -74,34 +74,30 @@ gkyl_block_geom_reset_block_extents(struct gkyl_block_geom *bgeom, int bidx, dou } } -const struct gkyl_block_geom_info* +const struct gkyl_block_geom_info * gkyl_block_geom_get_block(const struct gkyl_block_geom *bgeom, int bidx) { return &bgeom->blocks[bidx]; } -int -gkyl_block_geom_check_consistency(const struct gkyl_block_geom *bgeom) +int gkyl_block_geom_check_consistency(const struct gkyl_block_geom *bgeom) { // MORE TESTS ARE NEEDED HERE return gkyl_block_topo_check_consistency(bgeom->btopo); } -struct gkyl_block_geom * -gkyl_block_geom_acquire(const struct gkyl_block_geom* bgeom) +struct gkyl_block_geom *gkyl_block_geom_acquire(const struct gkyl_block_geom *bgeom) { gkyl_ref_count_inc(&bgeom->ref_count); - return (struct gkyl_block_geom*) bgeom; + return (struct gkyl_block_geom *)bgeom; } -struct gkyl_block_topo* -gkyl_block_geom_topo(const struct gkyl_block_geom *bgeom) +struct gkyl_block_topo *gkyl_block_geom_topo(const struct gkyl_block_geom *bgeom) { return gkyl_block_topo_acquire(bgeom->btopo); } -void -gkyl_block_geom_release(struct gkyl_block_geom* bgeom) +void gkyl_block_geom_release(struct gkyl_block_geom *bgeom) { gkyl_ref_count_dec(&bgeom->ref_count); } diff --git a/core/zero/block_topo.c b/core/zero/block_topo.c index b0ed833eee..019cd60741 100644 --- a/core/zero/block_topo.c +++ b/core/zero/block_topo.c @@ -13,21 +13,19 @@ static const enum gkyl_oriented_edge complimentary_edges[] = { [GKYL_LOWER_NEGATIVE] = GKYL_UPPER_NEGATIVE, [GKYL_UPPER_POSITIVE] = GKYL_LOWER_POSITIVE, [GKYL_UPPER_NEGATIVE] = GKYL_LOWER_NEGATIVE, - [GKYL_PHYSICAL] = GKYL_PHYSICAL, + [GKYL_PHYSICAL] = GKYL_PHYSICAL }; -static const char *block_edge_names[] = { "lower", "upper" }; +static const char *block_edge_names[] = {"lower", "upper"}; -static void -block_topo_free(const struct gkyl_ref_count *ref) +static void block_topo_free(const struct gkyl_ref_count *ref) { struct gkyl_block_topo *btopo = container_of(ref, struct gkyl_block_topo, ref_count); gkyl_free(btopo->conn); gkyl_free(btopo); } -static struct gkyl_msgpack_data * -btopo_create_mpack(const struct gkyl_block_topo *btopo) +static struct gkyl_msgpack_data *btopo_create_mpack(const struct gkyl_block_topo *btopo) { struct gkyl_msgpack_data *mt = gkyl_malloc(sizeof(*mt)); mt->meta_sz = 0; @@ -41,20 +39,20 @@ btopo_create_mpack(const struct gkyl_block_topo *btopo) mpack_write_cstr(&writer, "ndim"); mpack_write_i64(&writer, btopo->ndim); - + mpack_write_cstr(&writer, "num_blocks"); mpack_write_i64(&writer, btopo->num_blocks); // 3 values written (block ID, direction, edge) for each of the 2 edges: - size_t num_arr_elems = btopo->num_blocks*btopo->ndim*3*2; + size_t num_arr_elems = btopo->num_blocks * btopo->ndim * 3 * 2; // write each block connectivity into an array mpack_write_cstr(&writer, "connections"); mpack_start_array(&writer, num_arr_elems); // Store connectivity data as a flat array - for (int i=0; inum_blocks; ++i) { - for (int d=0; dndim; ++d) { - for (int e=0; e<2; ++e) { + for (int i = 0; i < btopo->num_blocks; ++i) { + for (int d = 0; d < btopo->ndim; ++d) { + for (int e = 0; e < 2; ++e) { mpack_write_i64(&writer, btopo->conn[i].connections[d][e].bid); mpack_write_i64(&writer, btopo->conn[i].connections[d][e].dir); mpack_write_i64(&writer, btopo->conn[i].connections[d][e].edge); @@ -71,21 +69,21 @@ btopo_create_mpack(const struct gkyl_block_topo *btopo) free(mt->meta); // we need to use free here as mpack does its own malloc gkyl_free(mt); mt = 0; - } + } return mt; } -static void -btopo_array_meta_release(struct gkyl_msgpack_data *amet) +static void btopo_array_meta_release(struct gkyl_msgpack_data *amet) { - if (!amet) return; + if (!amet) { + return; + } MPACK_FREE(amet->meta); gkyl_free(amet); } -struct gkyl_block_topo* -gkyl_block_topo_new(int ndim, int nblocks) +struct gkyl_block_topo *gkyl_block_topo_new(int ndim, int nblocks) { struct gkyl_block_topo *btopo = gkyl_malloc(sizeof(struct gkyl_block_topo)); btopo->ndim = ndim; @@ -97,36 +95,37 @@ gkyl_block_topo_new(int ndim, int nblocks) return btopo; } -int -gkyl_block_topo_check_consistency(const struct gkyl_block_topo *btopo) +int gkyl_block_topo_check_consistency(const struct gkyl_block_topo *btopo) { - for (int i=0; inum_blocks; ++i) { - for (int d=0; dndim; ++d) { - + for (int i = 0; i < btopo->num_blocks; ++i) { + for (int d = 0; d < btopo->ndim; ++d) { const struct gkyl_target_edge *te = btopo->conn[i].connections[d]; - - for (int e=0; e<2; ++e) { // 0: lower, 1: upper - if (te[e].edge < 1) // unspecified edges are defaulted to 0 + + for (int e = 0; e < 2; ++e) { // 0: lower, 1: upper + if (te[e].edge < 1) { // unspecified edges are defaulted to 0 return 0; + } // check consistency if (te[e].edge != GKYL_PHYSICAL) { - if (te[e].bid < 0 || te[e].bid >= btopo->num_blocks) // improperly numbered block + if (te[e].bid < 0 || te[e].bid >= btopo->num_blocks) { // improperly numbered block return 0; + } // fetch edge which should point back to ith-block const struct gkyl_target_edge *te_back = - &btopo->conn[te[e].bid].connections[d][(e+1)%2]; + &btopo->conn[te[e].bid].connections[d][(e + 1) % 2]; // check if the edge belongs to block 'i' - if (te_back->bid != i) + if (te_back->bid != i) { return 0; + } // check if edge orientation is complimentary - if (te_back->edge != complimentary_edges[te[e].edge]) + if (te_back->edge != complimentary_edges[te[e].edge]) { return 0; + } } - } } } @@ -134,41 +133,40 @@ gkyl_block_topo_check_consistency(const struct gkyl_block_topo *btopo) return 1; } -int -gkyl_block_topo_write(const struct gkyl_block_topo *btopo, const char *fname) +int gkyl_block_topo_write(const struct gkyl_block_topo *btopo, const char *fname) { enum gkyl_array_rio_status status = GKYL_ARRAY_RIO_FOPEN_FAILED; FILE *fp = 0; int err; - with_file (fp, fname, "w") { + with_file(fp, fname, "w") + { struct gkyl_msgpack_data *amet = btopo_create_mpack(btopo); if (amet) { - status = gkyl_header_meta_write_fp( &(struct gkyl_array_header_info) { - .file_type = gkyl_file_type_int[GKYL_BLOCK_TOPO_DATA_FILE], + status = gkyl_header_meta_write_fp( + &(struct gkyl_array_header_info + ){.file_type = gkyl_file_type_int[GKYL_BLOCK_TOPO_DATA_FILE], .meta_size = amet->meta_sz, - .meta = amet->meta - }, + .meta = amet->meta}, fp ); btopo_array_meta_release(amet); - } - else { + } else { status = GKYL_ARRAY_RIO_META_FAILED; } } return status; } -struct gkyl_block_topo * -gkyl_block_topo_read(const char *fname, int *status) +struct gkyl_block_topo *gkyl_block_topo_read(const char *fname, int *status) { struct gkyl_block_topo *btopo = 0; - + enum gkyl_array_rio_status read_status = GKYL_ARRAY_RIO_FOPEN_FAILED; FILE *fp = 0; int err; - with_file (fp, fname, "r") { - struct gkyl_array_header_info hdr = { }; + with_file(fp, fname, "r") + { + struct gkyl_array_header_info hdr = {}; read_status = gkyl_header_meta_read_fp(&hdr, fp); if (hdr.file_type != 4) { read_status = GKYL_ARRAY_RIO_BAD_VERSION; @@ -191,15 +189,14 @@ gkyl_block_topo_read(const char *fname, int *status) mpack_node_t conn_array_node = mpack_node_map_cstr(root, "connections"); int array_idx = 0; - for (int i=0; iconn[i] = conn; } - + mpack_tree_destroy(&tree); gkyl_free(hdr.meta); } } - + *status = read_status; return btopo; } -struct gkyl_block_topo * -gkyl_block_topo_acquire(const struct gkyl_block_topo* btopo) +struct gkyl_block_topo *gkyl_block_topo_acquire(const struct gkyl_block_topo *btopo) { gkyl_ref_count_inc(&btopo->ref_count); - return (struct gkyl_block_topo*) btopo; -} + return (struct gkyl_block_topo *)btopo; +} -void -gkyl_block_topo_release(struct gkyl_block_topo* btopo) +void gkyl_block_topo_release(struct gkyl_block_topo *btopo) { gkyl_ref_count_dec(&btopo->ref_count); } diff --git a/core/zero/cart_modal_gkhybrid.c b/core/zero/cart_modal_gkhybrid.c index 3ecfb35406..0295c79b35 100644 --- a/core/zero/cart_modal_gkhybrid.c +++ b/core/zero/cart_modal_gkhybrid.c @@ -5,13 +5,12 @@ #include -void -gkyl_cart_modal_gkhybrid(struct gkyl_basis *basis, int cdim, int vdim) +void gkyl_cart_modal_gkhybrid(struct gkyl_basis *basis, int cdim, int vdim) { - int ndim = cdim+vdim; - assert(ndim>1 && ndim<6); - assert(cdim<4 && vdim>0 && vdim<3); - + int ndim = cdim + vdim; + assert(ndim > 1 && ndim < 6); + assert(cdim < 4 && vdim > 0 && vdim < 3); + basis->ndim = ndim; basis->poly_order = 1; basis->num_basis = num_basis_list[ndim].count[1]; @@ -31,8 +30,7 @@ gkyl_cart_modal_gkhybrid(struct gkyl_basis *basis, int cdim, int vdim) basis->modal_to_quad_nodal = m2qn_list[ndim].n2m[1]; } -struct gkyl_basis * -gkyl_cart_modal_gkhybrid_new(int cdim, int vdim) +struct gkyl_basis *gkyl_cart_modal_gkhybrid_new(int cdim, int vdim) { struct gkyl_basis *basis = gkyl_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_gkhybrid(basis, cdim, vdim); @@ -40,14 +38,12 @@ gkyl_cart_modal_gkhybrid_new(int cdim, int vdim) } #ifndef GKYL_HAVE_CUDA -void -gkyl_cart_modal_gkhybrid_cu_dev(struct gkyl_basis *basis, int cdim, int vdim) +void gkyl_cart_modal_gkhybrid_cu_dev(struct gkyl_basis *basis, int cdim, int vdim) { assert(false); } -struct gkyl_basis * -gkyl_cart_modal_gkhybrid_cu_dev_new(int cdim, int vdim) +struct gkyl_basis *gkyl_cart_modal_gkhybrid_cu_dev_new(int cdim, int vdim) { assert(false); } diff --git a/core/zero/cart_modal_gkhybrid_cu.cu b/core/zero/cart_modal_gkhybrid_cu.cu index 4a2515482d..4790beb839 100644 --- a/core/zero/cart_modal_gkhybrid_cu.cu +++ b/core/zero/cart_modal_gkhybrid_cu.cu @@ -3,26 +3,27 @@ #include "gkyl_util.h" extern "C" { #include -#include - +#include + #include #include #include } -__global__ void static -gkyl_cart_modal_gkhybrid_cu_dev_kern(struct gkyl_basis *basis, int cdim, int vdim) +__global__ void static gkyl_cart_modal_gkhybrid_cu_dev_kern( + struct gkyl_basis *basis, int cdim, int vdim +) { - int ndim = cdim+vdim; + int ndim = cdim + vdim; assert(ev_list[ndim].ev[1]); - basis->ndim = cdim+vdim; + basis->ndim = cdim + vdim; basis->poly_order = 1; basis->num_basis = num_basis_list[ndim].count[1]; basis->num_quad = num_quad_list[ndim].count[1]; basis->b_type = GKYL_BASIS_MODAL_GKHYBRID; - + // function pointers basis->eval = ev_list[ndim].ev[1]; basis->eval_expand = eve_list[ndim].ev[1]; @@ -35,28 +36,25 @@ gkyl_cart_modal_gkhybrid_cu_dev_kern(struct gkyl_basis *basis, int cdim, int vdi basis->modal_to_quad_nodal = m2qn_list[ndim].n2m[1]; } -void -gkyl_cart_modal_gkhybrid_cu_dev(struct gkyl_basis *basis, int cdim, int vdim) +void gkyl_cart_modal_gkhybrid_cu_dev(struct gkyl_basis *basis, int cdim, int vdim) { - int ndim = cdim+vdim; - assert(ndim>1 && ndim<6); - assert(cdim<4 && vdim>0 && vdim<3); + int ndim = cdim + vdim; + assert(ndim > 1 && ndim < 6); + assert(cdim < 4 && vdim > 0 && vdim < 3); struct gkyl_basis ho_basis; strcpy(ho_basis.id, "gkhybrid"); // this copy needs to be done here as the strcpy needed in the // "type" field can't be done on the device - gkyl_cu_memcpy(basis, &ho_basis, sizeof(struct gkyl_basis), - GKYL_CU_MEMCPY_H2D); - - gkyl_cart_modal_gkhybrid_cu_dev_kern<<<1,1>>>(basis, cdim, vdim); + gkyl_cu_memcpy(basis, &ho_basis, sizeof(struct gkyl_basis), GKYL_CU_MEMCPY_H2D); + + gkyl_cart_modal_gkhybrid_cu_dev_kern<<<1, 1> > >(basis, cdim, vdim); } -struct gkyl_basis * -gkyl_cart_modal_gkhybrid_cu_dev_new(int cdim, int vdim) +struct gkyl_basis *gkyl_cart_modal_gkhybrid_cu_dev_new(int cdim, int vdim) { - struct gkyl_basis *basis = (struct gkyl_basis *) gkyl_cu_malloc(sizeof(struct gkyl_basis)); + struct gkyl_basis *basis = (struct gkyl_basis *)gkyl_cu_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_gkhybrid_cu_dev(basis, cdim, vdim); return basis; } diff --git a/core/zero/cart_modal_gkhybrid_vel.c b/core/zero/cart_modal_gkhybrid_vel.c index dd1dacc026..81fd9d4358 100644 --- a/core/zero/cart_modal_gkhybrid_vel.c +++ b/core/zero/cart_modal_gkhybrid_vel.c @@ -5,12 +5,11 @@ #include -void -gkyl_cart_modal_gkhybrid_vel(struct gkyl_basis *basis, int vdim) +void gkyl_cart_modal_gkhybrid_vel(struct gkyl_basis *basis, int vdim) { int ndim = vdim; - assert(ndim==1 || ndim==2); - + assert(ndim == 1 || ndim == 2); + basis->ndim = ndim; basis->poly_order = 1; basis->num_basis = num_basis_list[ndim].count[1]; @@ -30,8 +29,7 @@ gkyl_cart_modal_gkhybrid_vel(struct gkyl_basis *basis, int vdim) basis->modal_to_quad_nodal = m2qn_list[ndim].n2m[1]; } -struct gkyl_basis * -gkyl_cart_modal_gkhybrid_vel_new(int vdim) +struct gkyl_basis *gkyl_cart_modal_gkhybrid_vel_new(int vdim) { struct gkyl_basis *basis = gkyl_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_gkhybrid_vel(basis, vdim); @@ -39,14 +37,12 @@ gkyl_cart_modal_gkhybrid_vel_new(int vdim) } #ifndef GKYL_HAVE_CUDA -void -gkyl_cart_modal_gkhybrid_vel_cu_dev(struct gkyl_basis *basis, int vdim) +void gkyl_cart_modal_gkhybrid_vel_cu_dev(struct gkyl_basis *basis, int vdim) { assert(false); } -struct gkyl_basis * -gkyl_cart_modal_gkhybrid_vel_cu_dev_new(int vdim) +struct gkyl_basis *gkyl_cart_modal_gkhybrid_vel_cu_dev_new(int vdim) { assert(false); } diff --git a/core/zero/cart_modal_gkhybrid_vel_cu.cu b/core/zero/cart_modal_gkhybrid_vel_cu.cu index 63e792cfe4..8fcd49ac53 100644 --- a/core/zero/cart_modal_gkhybrid_vel_cu.cu +++ b/core/zero/cart_modal_gkhybrid_vel_cu.cu @@ -3,16 +3,15 @@ #include "gkyl_util.h" extern "C" { #include -#include - +#include + #include #include #include } -__global__ void static -gkyl_cart_modal_gkhybrid_vel_cu_dev_kern(struct gkyl_basis *basis, int vdim) +__global__ void static gkyl_cart_modal_gkhybrid_vel_cu_dev_kern(struct gkyl_basis *basis, int vdim) { int ndim = vdim; assert(ev_list[ndim].ev[1]); @@ -22,7 +21,7 @@ gkyl_cart_modal_gkhybrid_vel_cu_dev_kern(struct gkyl_basis *basis, int vdim) basis->num_basis = num_basis_list[ndim].count[1]; basis->num_quad = num_quad_list[ndim].count[1]; basis->b_type = GKYL_BASIS_MODAL_GKHYBRID_VEL; - + // function pointers basis->eval = ev_list[ndim].ev[1]; basis->eval_expand = eve_list[ndim].ev[1]; @@ -35,27 +34,24 @@ gkyl_cart_modal_gkhybrid_vel_cu_dev_kern(struct gkyl_basis *basis, int vdim) basis->modal_to_quad_nodal = m2qn_list[ndim].n2m[1]; } -void -gkyl_cart_modal_gkhybrid_vel_cu_dev(struct gkyl_basis *basis, int vdim) +void gkyl_cart_modal_gkhybrid_vel_cu_dev(struct gkyl_basis *basis, int vdim) { int ndim = vdim; - assert(ndim>0 && ndim<3); + assert(ndim > 0 && ndim < 3); struct gkyl_basis ho_basis; strcpy(ho_basis.id, "gkhybrid_vel"); // this copy needs to be done here as the strcpy needed in the // "type" field can't be done on the device - gkyl_cu_memcpy(basis, &ho_basis, sizeof(struct gkyl_basis), - GKYL_CU_MEMCPY_H2D); - - gkyl_cart_modal_gkhybrid_vel_cu_dev_kern<<<1,1>>>(basis, vdim); + gkyl_cu_memcpy(basis, &ho_basis, sizeof(struct gkyl_basis), GKYL_CU_MEMCPY_H2D); + + gkyl_cart_modal_gkhybrid_vel_cu_dev_kern<<<1, 1> > >(basis, vdim); } -struct gkyl_basis * -gkyl_cart_modal_gkhybrid_vel_cu_dev_new(int vdim) +struct gkyl_basis *gkyl_cart_modal_gkhybrid_vel_cu_dev_new(int vdim) { - struct gkyl_basis *basis = (struct gkyl_basis *) gkyl_cu_malloc(sizeof(struct gkyl_basis)); + struct gkyl_basis *basis = (struct gkyl_basis *)gkyl_cu_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_gkhybrid_vel_cu_dev(basis, vdim); return basis; } diff --git a/core/zero/cart_modal_hybrid.c b/core/zero/cart_modal_hybrid.c index b8008628d3..bf1300f4a5 100644 --- a/core/zero/cart_modal_hybrid.c +++ b/core/zero/cart_modal_hybrid.c @@ -5,13 +5,12 @@ #include -void -gkyl_cart_modal_hybrid(struct gkyl_basis *basis, int cdim, int vdim) +void gkyl_cart_modal_hybrid(struct gkyl_basis *basis, int cdim, int vdim) { - int ndim = cdim+vdim; - assert(ndim>1 && ndim<7); - assert(cdim<4 && vdim>0 && vdim<4); - + int ndim = cdim + vdim; + assert(ndim > 1 && ndim < 7); + assert(cdim < 4 && vdim > 0 && vdim < 4); + basis->ndim = ndim; basis->poly_order = 1; basis->num_basis = num_basis_list[cdim].count[vdim]; @@ -31,8 +30,7 @@ gkyl_cart_modal_hybrid(struct gkyl_basis *basis, int cdim, int vdim) basis->modal_to_quad_nodal = m2qn_list[cdim].n2m[vdim]; } -struct gkyl_basis * -gkyl_cart_modal_hybrid_new(int cdim, int vdim) +struct gkyl_basis *gkyl_cart_modal_hybrid_new(int cdim, int vdim) { struct gkyl_basis *basis = gkyl_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_hybrid(basis, cdim, vdim); @@ -40,14 +38,12 @@ gkyl_cart_modal_hybrid_new(int cdim, int vdim) } #ifndef GKYL_HAVE_CUDA -void -gkyl_cart_modal_hybrid_cu_dev(struct gkyl_basis *basis, int cdim, int vdim) +void gkyl_cart_modal_hybrid_cu_dev(struct gkyl_basis *basis, int cdim, int vdim) { assert(false); } -struct gkyl_basis * -gkyl_cart_modal_hybrid_cu_dev_new(int cdim, int vdim) +struct gkyl_basis *gkyl_cart_modal_hybrid_cu_dev_new(int cdim, int vdim) { assert(false); } diff --git a/core/zero/cart_modal_hybrid_cu.cu b/core/zero/cart_modal_hybrid_cu.cu index 9cb9a3c867..8b05ddbbbc 100644 --- a/core/zero/cart_modal_hybrid_cu.cu +++ b/core/zero/cart_modal_hybrid_cu.cu @@ -3,25 +3,26 @@ #include extern "C" { #include -#include - +#include + #include #include #include } -__global__ void static -gkyl_cart_modal_hybrid_cu_dev_kern(struct gkyl_basis *basis, int cdim, int vdim) +__global__ void static gkyl_cart_modal_hybrid_cu_dev_kern( + struct gkyl_basis *basis, int cdim, int vdim +) { assert(ev_list[cdim].ev[vdim]); - basis->ndim = cdim+vdim; + basis->ndim = cdim + vdim; basis->poly_order = 1; basis->num_basis = num_basis_list[cdim].count[vdim]; basis->num_quad = num_quad_list[cdim].count[vdim]; - basis->b_type = GKYL_BASIS_MODAL_HYBRID; - + basis->b_type = GKYL_BASIS_MODAL_HYBRID; + // function pointers basis->eval = ev_list[cdim].ev[vdim]; basis->eval_expand = eve_list[cdim].ev[vdim]; @@ -34,28 +35,25 @@ gkyl_cart_modal_hybrid_cu_dev_kern(struct gkyl_basis *basis, int cdim, int vdim) basis->modal_to_quad_nodal = m2qn_list[cdim].n2m[vdim]; } -void -gkyl_cart_modal_hybrid_cu_dev(struct gkyl_basis *basis, int cdim, int vdim) +void gkyl_cart_modal_hybrid_cu_dev(struct gkyl_basis *basis, int cdim, int vdim) { - int ndim = cdim+vdim; - assert(ndim>1 && ndim<7); - assert(cdim<4 && vdim>0 && vdim<4); + int ndim = cdim + vdim; + assert(ndim > 1 && ndim < 7); + assert(cdim < 4 && vdim > 0 && vdim < 4); struct gkyl_basis ho_basis; strcpy(ho_basis.id, "hybrid"); // this copy needs to be done here as the strcpy needed in the // "type" field can't be done on the device - gkyl_cu_memcpy(basis, &ho_basis, sizeof(struct gkyl_basis), - GKYL_CU_MEMCPY_H2D); - - gkyl_cart_modal_hybrid_cu_dev_kern<<<1,1>>>(basis, cdim, vdim); + gkyl_cu_memcpy(basis, &ho_basis, sizeof(struct gkyl_basis), GKYL_CU_MEMCPY_H2D); + + gkyl_cart_modal_hybrid_cu_dev_kern<<<1, 1> > >(basis, cdim, vdim); } -struct gkyl_basis * -gkyl_cart_modal_hybrid_cu_dev_new(int cdim, int vdim) +struct gkyl_basis *gkyl_cart_modal_hybrid_cu_dev_new(int cdim, int vdim) { - struct gkyl_basis *basis = (struct gkyl_basis *) gkyl_cu_malloc(sizeof(struct gkyl_basis)); + struct gkyl_basis *basis = (struct gkyl_basis *)gkyl_cu_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_hybrid_cu_dev(basis, cdim, vdim); return basis; } diff --git a/core/zero/cart_modal_serendip.c b/core/zero/cart_modal_serendip.c index 3fa22552ed..304a9b3232 100644 --- a/core/zero/cart_modal_serendip.c +++ b/core/zero/cart_modal_serendip.c @@ -5,12 +5,11 @@ #include -void -gkyl_cart_modal_serendip(struct gkyl_basis *basis, int ndim, int poly_order) +void gkyl_cart_modal_serendip(struct gkyl_basis *basis, int ndim, int poly_order) { - assert(ndim>0 && ndim<=6); + assert(ndim > 0 && ndim <= 6); assert(ev_list[ndim].ev[poly_order]); - + basis->ndim = ndim; basis->poly_order = poly_order; basis->num_basis = num_basis_list[ndim].count[poly_order]; @@ -26,12 +25,12 @@ gkyl_cart_modal_serendip(struct gkyl_basis *basis, int ndim, int poly_order) basis->flip_even_sign = fes_list[ndim].fs[poly_order]; basis->node_list = nl_list[ndim].nl[poly_order]; basis->nodal_to_modal = n2m_list[ndim].n2m[poly_order]; - if (ndim>1) { + if (ndim > 1) { basis->nodal_to_modal_quad_surf[0] = n2m_quad_surf_list_x[ndim].n2m[poly_order]; basis->nodal_to_modal_quad_surf[1] = n2m_quad_surf_list_y[ndim].n2m[poly_order]; basis->node_quad_surf_list[0] = nl_quad_surf_list_x[ndim].nl[poly_order]; basis->node_quad_surf_list[1] = nl_quad_surf_list_y[ndim].nl[poly_order]; - if (ndim>2) { + if (ndim > 2) { basis->nodal_to_modal_quad_surf[2] = n2m_quad_surf_list_z[ndim].n2m[poly_order]; basis->node_quad_surf_list[2] = nl_quad_surf_list_z[ndim].nl[poly_order]; } @@ -40,8 +39,7 @@ gkyl_cart_modal_serendip(struct gkyl_basis *basis, int ndim, int poly_order) basis->modal_to_quad_nodal = m2qn_list[ndim].n2m[poly_order]; } -struct gkyl_basis * -gkyl_cart_modal_serendip_new(int ndim, int poly_order) +struct gkyl_basis *gkyl_cart_modal_serendip_new(int ndim, int poly_order) { struct gkyl_basis *basis = gkyl_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_serendip(basis, ndim, poly_order); @@ -49,14 +47,12 @@ gkyl_cart_modal_serendip_new(int ndim, int poly_order) } #ifndef GKYL_HAVE_CUDA -void -gkyl_cart_modal_serendip_cu_dev(struct gkyl_basis *basis, int ndim, int poly_order) +void gkyl_cart_modal_serendip_cu_dev(struct gkyl_basis *basis, int ndim, int poly_order) { assert(false); } -struct gkyl_basis * -gkyl_cart_modal_serendip_cu_dev_new(int ndim, int poly_order) +struct gkyl_basis *gkyl_cart_modal_serendip_cu_dev_new(int ndim, int poly_order) { assert(false); } diff --git a/core/zero/cart_modal_serendip_cu.cu b/core/zero/cart_modal_serendip_cu.cu index cd3b318fb5..2db2dac68d 100644 --- a/core/zero/cart_modal_serendip_cu.cu +++ b/core/zero/cart_modal_serendip_cu.cu @@ -3,16 +3,17 @@ #include extern "C" { #include -#include - +#include + #include #include #include } -__global__ void static -gkyl_cart_modal_serendip_cu_dev_kern(struct gkyl_basis *basis, int ndim, int poly_order) +__global__ void static gkyl_cart_modal_serendip_cu_dev_kern( + struct gkyl_basis *basis, int ndim, int poly_order +) { assert(ev_list[ndim].ev[poly_order]); @@ -20,8 +21,8 @@ gkyl_cart_modal_serendip_cu_dev_kern(struct gkyl_basis *basis, int ndim, int pol basis->poly_order = poly_order; basis->num_basis = num_basis_list[ndim].count[poly_order]; basis->num_quad = num_quad_list[ndim].count[poly_order]; - basis->b_type = GKYL_BASIS_MODAL_SERENDIPITY; - + basis->b_type = GKYL_BASIS_MODAL_SERENDIPITY; + // function pointers basis->eval = ev_list[ndim].ev[poly_order]; basis->eval_expand = eve_list[ndim].ev[poly_order]; @@ -34,26 +35,23 @@ gkyl_cart_modal_serendip_cu_dev_kern(struct gkyl_basis *basis, int ndim, int pol basis->modal_to_quad_nodal = m2qn_list[ndim].n2m[poly_order]; } -void -gkyl_cart_modal_serendip_cu_dev(struct gkyl_basis *basis, int ndim, int poly_order) +void gkyl_cart_modal_serendip_cu_dev(struct gkyl_basis *basis, int ndim, int poly_order) { - assert(ndim>0 && ndim<=6); + assert(ndim > 0 && ndim <= 6); struct gkyl_basis ho_basis; strcpy(ho_basis.id, "serendipity"); // this copy needs to be done here as the strcpy needed in the // "type" field can't be done on the device - gkyl_cu_memcpy(basis, &ho_basis, sizeof(struct gkyl_basis), - GKYL_CU_MEMCPY_H2D); - - gkyl_cart_modal_serendip_cu_dev_kern<<<1,1>>>(basis, ndim, poly_order); + gkyl_cu_memcpy(basis, &ho_basis, sizeof(struct gkyl_basis), GKYL_CU_MEMCPY_H2D); + + gkyl_cart_modal_serendip_cu_dev_kern<<<1, 1> > >(basis, ndim, poly_order); } -struct gkyl_basis * -gkyl_cart_modal_serendip_cu_dev_new(int ndim, int poly_order) +struct gkyl_basis *gkyl_cart_modal_serendip_cu_dev_new(int ndim, int poly_order) { - struct gkyl_basis *basis = (struct gkyl_basis *) gkyl_cu_malloc(sizeof(struct gkyl_basis)); + struct gkyl_basis *basis = (struct gkyl_basis *)gkyl_cu_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_serendip_cu_dev(basis, ndim, poly_order); return basis; } diff --git a/core/zero/cart_modal_tensor.c b/core/zero/cart_modal_tensor.c index 4c859932bd..64f9fcdd71 100644 --- a/core/zero/cart_modal_tensor.c +++ b/core/zero/cart_modal_tensor.c @@ -6,15 +6,14 @@ #include -void -gkyl_cart_modal_tensor(struct gkyl_basis *basis, int ndim, int poly_order) +void gkyl_cart_modal_tensor(struct gkyl_basis *basis, int ndim, int poly_order) { - assert(ndim>0 && ndim<=6); + assert(ndim > 0 && ndim <= 6); assert(ev_list[ndim].ev[poly_order]); - + basis->ndim = ndim; basis->poly_order = poly_order; - basis->num_basis = pow(poly_order+1, ndim); + basis->num_basis = pow(poly_order + 1, ndim); basis->num_quad = num_quad_list[ndim].count[poly_order]; strcpy(basis->id, "tensor"); basis->b_type = GKYL_BASIS_MODAL_TENSOR; @@ -31,8 +30,7 @@ gkyl_cart_modal_tensor(struct gkyl_basis *basis, int ndim, int poly_order) basis->modal_to_quad_nodal = m2qn_list[ndim].n2m[poly_order]; } -struct gkyl_basis * -gkyl_cart_modal_tensor_new(int ndim, int poly_order) +struct gkyl_basis *gkyl_cart_modal_tensor_new(int ndim, int poly_order) { struct gkyl_basis *basis = gkyl_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_tensor(basis, ndim, poly_order); @@ -40,14 +38,12 @@ gkyl_cart_modal_tensor_new(int ndim, int poly_order) } #ifndef GKYL_HAVE_CUDA -void -gkyl_cart_modal_tensor_cu_dev(struct gkyl_basis *basis, int ndim, int poly_order) +void gkyl_cart_modal_tensor_cu_dev(struct gkyl_basis *basis, int ndim, int poly_order) { assert(false); } -struct gkyl_basis * -gkyl_cart_modal_tensor_cu_dev_new(int ndim, int poly_order) +struct gkyl_basis *gkyl_cart_modal_tensor_cu_dev_new(int ndim, int poly_order) { assert(false); } diff --git a/core/zero/cart_modal_tensor_cu.cu b/core/zero/cart_modal_tensor_cu.cu index bcad1b38e8..2ff0a99d28 100644 --- a/core/zero/cart_modal_tensor_cu.cu +++ b/core/zero/cart_modal_tensor_cu.cu @@ -2,25 +2,26 @@ extern "C" { #include -#include - +#include + #include #include #include #include } -__global__ void static -gkyl_cart_modal_tensor_cu_dev_kern(struct gkyl_basis *basis, int ndim, int poly_order) +__global__ void static gkyl_cart_modal_tensor_cu_dev_kern( + struct gkyl_basis *basis, int ndim, int poly_order +) { assert(ev_list[ndim].ev[poly_order]); basis->ndim = ndim; basis->poly_order = poly_order; - basis->num_basis = pow(poly_order+1, ndim); + basis->num_basis = pow(poly_order + 1, ndim); basis->num_quad = num_quad_list[ndim].count[poly_order]; - basis->b_type = GKYL_BASIS_MODAL_TENSOR; - + basis->b_type = GKYL_BASIS_MODAL_TENSOR; + // function pointers basis->eval = ev_list[ndim].ev[poly_order]; basis->eval_expand = eve_list[ndim].ev[poly_order]; @@ -33,26 +34,23 @@ gkyl_cart_modal_tensor_cu_dev_kern(struct gkyl_basis *basis, int ndim, int poly_ basis->modal_to_quad_nodal = m2qn_list[ndim].n2m[poly_order]; } -void -gkyl_cart_modal_tensor_cu_dev(struct gkyl_basis *basis, int ndim, int poly_order) +void gkyl_cart_modal_tensor_cu_dev(struct gkyl_basis *basis, int ndim, int poly_order) { - assert(ndim>0 && ndim<=6); + assert(ndim > 0 && ndim <= 6); struct gkyl_basis ho_basis; strcpy(ho_basis.id, "tensor"); // this copy needs to be done here as the strcpy needed in the // "type" field can't be done on the device - gkyl_cu_memcpy(basis, &ho_basis, sizeof(struct gkyl_basis), - GKYL_CU_MEMCPY_H2D); - - gkyl_cart_modal_tensor_cu_dev_kern<<<1,1>>>(basis, ndim, poly_order); + gkyl_cu_memcpy(basis, &ho_basis, sizeof(struct gkyl_basis), GKYL_CU_MEMCPY_H2D); + + gkyl_cart_modal_tensor_cu_dev_kern<<<1, 1> > >(basis, ndim, poly_order); } -struct gkyl_basis * -gkyl_cart_modal_tensor_cu_dev_new(int ndim, int poly_order) +struct gkyl_basis *gkyl_cart_modal_tensor_cu_dev_new(int ndim, int poly_order) { - struct gkyl_basis *basis = (struct gkyl_basis *) gkyl_cu_malloc(sizeof(struct gkyl_basis)); + struct gkyl_basis *basis = (struct gkyl_basis *)gkyl_cu_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_tensor_cu_dev(basis, ndim, poly_order); return basis; } diff --git a/core/zero/comm.c b/core/zero/comm.c index e4c3a4d0c6..086e2eac03 100644 --- a/core/zero/comm.c +++ b/core/zero/comm.c @@ -1,173 +1,163 @@ #include -struct gkyl_comm* -gkyl_comm_acquire(const struct gkyl_comm *comm) +struct gkyl_comm *gkyl_comm_acquire(const struct gkyl_comm *comm) { gkyl_ref_count_inc(&comm->ref_count); - return (struct gkyl_comm*) comm; + return (struct gkyl_comm *)comm; } -void -gkyl_comm_release(const struct gkyl_comm *comm) +void gkyl_comm_release(const struct gkyl_comm *comm) { - if (comm) + if (comm) { gkyl_ref_count_dec(&comm->ref_count); + } } -int -gkyl_comm_get_rank(struct gkyl_comm *pcomm, int *rank) +int gkyl_comm_get_rank(struct gkyl_comm *pcomm, int *rank) { struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->get_rank(pcomm, rank); } -int -gkyl_comm_get_size(struct gkyl_comm *pcomm, int *sz) +int gkyl_comm_get_size(struct gkyl_comm *pcomm, int *sz) { struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->get_size(pcomm, sz); } -int -gkyl_comm_allreduce(struct gkyl_comm *pcomm, enum gkyl_elem_type type, - enum gkyl_array_op op, int nelem, const void *inp, void *out) +int gkyl_comm_allreduce( + struct gkyl_comm *pcomm, enum gkyl_elem_type type, enum gkyl_array_op op, int nelem, + const void *inp, void *out +) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->allreduce(pcomm, type, op, nelem, inp, out); } -int -gkyl_comm_allreduce_host(struct gkyl_comm *pcomm, enum gkyl_elem_type type, - enum gkyl_array_op op, int nelem, const void *inp, void *out) +int gkyl_comm_allreduce_host( + struct gkyl_comm *pcomm, enum gkyl_elem_type type, enum gkyl_array_op op, int nelem, + const void *inp, void *out +) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->allreduce_host(pcomm, type, op, nelem, inp, out); } -int -gkyl_comm_array_allgather(struct gkyl_comm *pcomm, - const struct gkyl_range *local, const struct gkyl_range *global, - const struct gkyl_array *array_local, struct gkyl_array *array_global) +int gkyl_comm_array_allgather( + struct gkyl_comm *pcomm, const struct gkyl_range *local, const struct gkyl_range *global, + const struct gkyl_array *array_local, struct gkyl_array *array_global +) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->gkyl_array_allgather(pcomm, local, global, array_local, array_global); } -int -gkyl_comm_array_allgather_host(struct gkyl_comm *pcomm, - const struct gkyl_range *local, const struct gkyl_range *global, - const struct gkyl_array *array_local, struct gkyl_array *array_global) +int gkyl_comm_array_allgather_host( + struct gkyl_comm *pcomm, const struct gkyl_range *local, const struct gkyl_range *global, + const struct gkyl_array *array_local, struct gkyl_array *array_global +) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->gkyl_array_allgather_host(pcomm, local, global, array_local, array_global); } -int -gkyl_comm_array_bcast(struct gkyl_comm *pcomm, - const struct gkyl_array *array_send, struct gkyl_array *array_recv, int root) +int gkyl_comm_array_bcast( + struct gkyl_comm *pcomm, const struct gkyl_array *array_send, struct gkyl_array *array_recv, + int root +) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->gkyl_array_bcast(pcomm, array_send, array_recv, root); } -int -gkyl_comm_array_bcast_host(struct gkyl_comm *pcomm, - const struct gkyl_array *array_send, struct gkyl_array *array_recv, int root) +int gkyl_comm_array_bcast_host( + struct gkyl_comm *pcomm, const struct gkyl_array *array_send, struct gkyl_array *array_recv, + int root +) { struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->gkyl_array_bcast_host(pcomm, array_send, array_recv, root); } -int -gkyl_comm_array_sync(struct gkyl_comm *pcomm, - const struct gkyl_range *local, - const struct gkyl_range *local_ext, - struct gkyl_array *array) +int gkyl_comm_array_sync( + struct gkyl_comm *pcomm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + struct gkyl_array *array +) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); comm->barrier(pcomm); return comm->gkyl_array_sync(pcomm, local, local_ext, array); } -int -gkyl_comm_array_per_sync(struct gkyl_comm *pcomm, - const struct gkyl_range *local, - const struct gkyl_range *local_ext, - int nper_dirs, const int *per_dirs, - struct gkyl_array *array) +int gkyl_comm_array_per_sync( + struct gkyl_comm *pcomm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + int nper_dirs, const int *per_dirs, struct gkyl_array *array +) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); comm->barrier(pcomm); - return comm->gkyl_array_per_sync(pcomm, local, local_ext, - nper_dirs, per_dirs, array); + return comm->gkyl_array_per_sync(pcomm, local, local_ext, nper_dirs, per_dirs, array); } -int -gkyl_comm_barrier(struct gkyl_comm *pcomm) +int gkyl_comm_barrier(struct gkyl_comm *pcomm) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->barrier(pcomm); } -void -gkyl_comm_group_call_start(struct gkyl_comm *pcomm) +void gkyl_comm_group_call_start(struct gkyl_comm *pcomm) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); comm->comm_group_call_start(); } -void -gkyl_comm_group_call_end(struct gkyl_comm *pcomm) +void gkyl_comm_group_call_end(struct gkyl_comm *pcomm) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); comm->comm_group_call_end(); } -int -gkyl_comm_array_write(struct gkyl_comm *pcomm, - const struct gkyl_rect_grid *grid, - const struct gkyl_range *range, - const struct gkyl_msgpack_data *meta, - const struct gkyl_array *arr, const char *fname) +int gkyl_comm_array_write( + struct gkyl_comm *pcomm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + const struct gkyl_msgpack_data *meta, const struct gkyl_array *arr, const char *fname +) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); int status = comm->gkyl_array_write(pcomm, grid, range, meta, arr, fname); gkyl_comm_barrier(pcomm); return status; } -int -gkyl_comm_array_read(struct gkyl_comm *pcomm, - const struct gkyl_rect_grid *grid, const struct gkyl_range *range, - struct gkyl_array *arr, const char *fname) +int gkyl_comm_array_read( + struct gkyl_comm *pcomm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + struct gkyl_array *arr, const char *fname +) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); int status = comm->gkyl_array_read(pcomm, grid, range, arr, fname); gkyl_comm_barrier(pcomm); return status; } -struct gkyl_comm* -gkyl_comm_extend_comm(const struct gkyl_comm *pcomm, - const struct gkyl_range *erange) +struct gkyl_comm * +gkyl_comm_extend_comm(const struct gkyl_comm *pcomm, const struct gkyl_range *erange) { struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->extend_comm(pcomm, erange); } -struct gkyl_comm* -gkyl_comm_split_comm(const struct gkyl_comm *pcomm, int color, - struct gkyl_rect_decomp *new_decomp) +struct gkyl_comm * +gkyl_comm_split_comm(const struct gkyl_comm *pcomm, int color, struct gkyl_rect_decomp *new_decomp) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->split_comm(pcomm, color, new_decomp); } -struct gkyl_comm * -gkyl_comm_create_comm_from_ranks(const struct gkyl_comm *pcomm, int nranks, - const int *ranks, struct gkyl_rect_decomp *new_decomp, - bool *is_valid) +struct gkyl_comm *gkyl_comm_create_comm_from_ranks( + const struct gkyl_comm *pcomm, int nranks, const int *ranks, struct gkyl_rect_decomp *new_decomp, + bool *is_valid +) { - struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); + struct gkyl_comm_priv *comm = container_of(pcomm, struct gkyl_comm_priv, pub_comm); return comm->create_comm_from_ranks(pcomm, nranks, ranks, new_decomp, is_valid); } diff --git a/core/zero/cudss_ops.cu b/core/zero/cudss_ops.cu index 47284f3711..1d1544f9a7 100644 --- a/core/zero/cudss_ops.cu +++ b/core/zero/cudss_ops.cu @@ -12,14 +12,18 @@ extern "C" { #include } -#define checkCUDSS(call, status, msg) \ -do { \ - status = call; \ - if (status != CUDSS_STATUS_SUCCESS) { \ - fprintf(stderr, "Example FAILED: CUDSS call ended unsuccessfully with status = %d, details: " #msg "\n", status); \ - exit(EXIT_FAILURE); \ - } \ -} while(0); +#define checkCUDSS(call, status, msg) \ + do { \ + status = call; \ + if (status != CUDSS_STATUS_SUCCESS) { \ + fprintf( \ + stderr, \ + "Example FAILED: CUDSS call ended unsuccessfully with status = %d, details: " #msg "\n", \ + status \ + ); \ + exit(EXIT_FAILURE); \ + } \ + } while (0); struct gkyl_culinsolver_prob { double *rhs_ho, *rhs_cu; // right-hand side vector. @@ -43,20 +47,19 @@ struct gkyl_culinsolver_prob { int *csr_rowptr_cu, *csr_colind_cu; }; -gkyl_culinsolver_prob* -gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs) +gkyl_culinsolver_prob *gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs) { - struct gkyl_culinsolver_prob *prob = (struct gkyl_culinsolver_prob*) gkyl_malloc(sizeof(*prob)); + struct gkyl_culinsolver_prob *prob = (struct gkyl_culinsolver_prob *)gkyl_malloc(sizeof(*prob)); prob->nprob = nprob; prob->mrow = mrow; prob->ncol = ncol; prob->nrhs = nrhs; - prob->rhs_ho = (double*) gkyl_malloc(nprob * nrhs * mrow * sizeof(double)); - prob->rhs_cu = (double*) gkyl_cu_malloc(nprob * nrhs * mrow * sizeof(double)); - prob->x_ho = (double*) gkyl_malloc(nprob * nrhs * mrow * sizeof(double)); - prob->x_cu = (double*) gkyl_cu_malloc(nprob * nrhs * mrow * sizeof(double)); + prob->rhs_ho = (double *)gkyl_malloc(nprob * nrhs * mrow * sizeof(double)); + prob->rhs_cu = (double *)gkyl_cu_malloc(nprob * nrhs * mrow * sizeof(double)); + prob->x_ho = (double *)gkyl_malloc(nprob * nrhs * mrow * sizeof(double)); + prob->x_cu = (double *)gkyl_cu_malloc(nprob * nrhs * mrow * sizeof(double)); cudssStatus_t status = CUDSS_STATUS_SUCCESS; @@ -71,9 +74,9 @@ gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs) checkCUDSS(cudssSetStream(prob->handle, prob->stream), status, "cudssSetStream"); /* Creating cuDSS solver configuration and data objects */ - prob->solverConfig = (cudssConfig_t *) gkyl_malloc(nprob * sizeof(cudssConfig_t)); - prob->solverData = (cudssData_t *) gkyl_malloc(nprob * sizeof(cudssData_t)); - for (int i=0; isolverConfig = (cudssConfig_t *)gkyl_malloc(nprob * sizeof(cudssConfig_t)); + prob->solverData = (cudssData_t *)gkyl_malloc(nprob * sizeof(cudssData_t)); + for (int i = 0; i < nprob; i++) { checkCUDSS(cudssConfigCreate(&prob->solverConfig[i]), status, "cudssConfigCreate"); checkCUDSS(cudssDataCreate(prob->handle, &prob->solverData[i]), status, "cudssDataCreate"); } @@ -81,53 +84,72 @@ gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs) /* Create matrix objects for the right-hand side b and solution x (as dense matrices). */ int64_t mrow_64 = mrow, ncol_64 = ncol; int ldb = ncol_64, ldx = mrow_64; - for (int i=0; irhs_ho[i] = 1.0; - gkyl_cu_memcpy(prob->rhs_cu, prob->rhs_ho, nprob * nrhs * mrow * sizeof(double), GKYL_CU_MEMCPY_H2D); + } + gkyl_cu_memcpy( + prob->rhs_cu, prob->rhs_ho, nprob * nrhs * mrow * sizeof(double), GKYL_CU_MEMCPY_H2D + ); gkyl_cu_memcpy(prob->x_cu, prob->rhs_ho, nprob * nrhs * mrow * sizeof(double), GKYL_CU_MEMCPY_H2D); - prob->b = (cudssMatrix_t *) gkyl_malloc(nprob * sizeof(cudssMatrix_t)); - prob->x = (cudssMatrix_t *) gkyl_malloc(nprob * sizeof(cudssMatrix_t)); + prob->b = (cudssMatrix_t *)gkyl_malloc(nprob * sizeof(cudssMatrix_t)); + prob->x = (cudssMatrix_t *)gkyl_malloc(nprob * sizeof(cudssMatrix_t)); - for (int i=0; ib[i], ncol_64, nrhs, ldb, prob->rhs_cu+off, CUDA_R_64F, CUDSS_LAYOUT_COL_MAJOR), - status, "cudssMatrixCreateDn for b"); - checkCUDSS(cudssMatrixCreateDn(&prob->x[i], mrow_64, nrhs, ldx, prob->x_cu+off, CUDA_R_64F, CUDSS_LAYOUT_COL_MAJOR), - status, "cudssMatrixCreateDn for x"); + checkCUDSS( + cudssMatrixCreateDn( + &prob->b[i], ncol_64, nrhs, ldb, prob->rhs_cu + off, CUDA_R_64F, CUDSS_LAYOUT_COL_MAJOR + ), + status, "cudssMatrixCreateDn for b" + ); + checkCUDSS( + cudssMatrixCreateDn( + &prob->x[i], mrow_64, nrhs, ldx, prob->x_cu + off, CUDA_R_64F, CUDSS_LAYOUT_COL_MAJOR + ), + status, "cudssMatrixCreateDn for x" + ); } return prob; } -void -gkyl_culinsolver_amat_from_triples(struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri) +void gkyl_culinsolver_amat_from_triples( + struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri +) { prob->nnz = gkyl_mat_triples_size(tri[0]); - for (size_t k=0; knprob; k++) { - assert(gkyl_mat_triples_size(tri[k]) == prob->nnz); // No. of nonzeros must be the same for every problem. - assert(gkyl_mat_triples_is_rowmaj(tri[k])); // Triples must be in rowmaj order for cusolver. + for (size_t k = 0; k < prob->nprob; k++) { + assert( + gkyl_mat_triples_size(tri[k]) == prob->nnz + ); // No. of nonzeros must be the same for every problem. + assert(gkyl_mat_triples_is_rowmaj(tri[k])); // Triples must be in rowmaj order for cusolver. } // Convert triples to CSR arrays on device. // Use CSR format - prob->csr_val_ho = (double*) gkyl_malloc(prob->nprob*prob->nnz*sizeof(double)); // non-zero matrix elements. - int *csr_colind = (int*) gkyl_malloc(sizeof(int)*prob->nnz); // col index of entries in csrvalA. - int *csr_rowptr = (int*) gkyl_malloc(sizeof(int)*(prob->mrow+1)); // 1st entry of each row as index in csrvalA. - - bool *csr_rowptr_assigned = (bool*) gkyl_malloc(sizeof(bool)*prob->mrow); - for (size_t i=0; imrow; i++) csr_rowptr_assigned[i] = false; + prob->csr_val_ho = + (double *)gkyl_malloc(prob->nprob * prob->nnz * sizeof(double)); // non-zero matrix elements. + int *csr_colind = (int *)gkyl_malloc(sizeof(int) * prob->nnz); // col index of entries in csrvalA. + int *csr_rowptr = (int *)gkyl_malloc( + sizeof(int) * (prob->mrow + 1) + ); // 1st entry of each row as index in csrvalA. + + bool *csr_rowptr_assigned = (bool *)gkyl_malloc(sizeof(bool) * prob->mrow); + for (size_t i = 0; i < prob->mrow; i++) { + csr_rowptr_assigned[i] = false; + } // Sorted (row-major order) keys (linear indices to flattened matrix). - for (size_t k=0; knprob; k++) { + for (size_t k = 0; k < prob->nprob; k++) { gkyl_mat_triples_iter *iter = gkyl_mat_triples_iter_new(tri[k]); - for (size_t i=0; innz; ++i) { + for (size_t i = 0; i < prob->nnz; ++i) { gkyl_mat_triples_iter_next(iter); // bump iterator. struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); - size_t idx[2] = { mt.row, mt.col }; + size_t idx[2] = {mt.row, mt.col}; - prob->csr_val_ho[k*prob->nnz+i] = mt.val; - if (k==0) { + prob->csr_val_ho[k * prob->nnz + i] = mt.val; + if (k == 0) { csr_colind[i] = idx[1]; if (!csr_rowptr_assigned[idx[0]]) { csr_rowptr[idx[0]] = i; @@ -141,177 +163,219 @@ gkyl_culinsolver_amat_from_triples(struct gkyl_culinsolver_prob *prob, struct gk gkyl_free(csr_rowptr_assigned); // Copy arrays to device. - prob->csr_val_cu = (double*) gkyl_cu_malloc(prob->nprob*prob->nnz*sizeof(double)); // Non-zero matrix elements. - prob->csr_colind_cu = (int*) gkyl_cu_malloc(sizeof(int)*prob->nnz); // Col index of entries in csrvalA. - prob->csr_rowptr_cu = (int*) gkyl_cu_malloc(sizeof(int)*(prob->mrow+1)); // 1st entry of each row as index in csrvalA. - gkyl_cu_memcpy(prob->csr_val_cu, prob->csr_val_ho, prob->nprob*prob->nnz*sizeof(double), GKYL_CU_MEMCPY_H2D); - gkyl_cu_memcpy(prob->csr_colind_cu, csr_colind, sizeof(int)*prob->nnz, GKYL_CU_MEMCPY_H2D); - gkyl_cu_memcpy(prob->csr_rowptr_cu, csr_rowptr, sizeof(int)*(prob->mrow+1), GKYL_CU_MEMCPY_H2D); + prob->csr_val_cu = + (double *)gkyl_cu_malloc(prob->nprob * prob->nnz * sizeof(double)); // Non-zero matrix elements. + prob->csr_colind_cu = + (int *)gkyl_cu_malloc(sizeof(int) * prob->nnz); // Col index of entries in csrvalA. + prob->csr_rowptr_cu = (int *)gkyl_cu_malloc( + sizeof(int) * (prob->mrow + 1) + ); // 1st entry of each row as index in csrvalA. + gkyl_cu_memcpy( + prob->csr_val_cu, prob->csr_val_ho, prob->nprob * prob->nnz * sizeof(double), GKYL_CU_MEMCPY_H2D + ); + gkyl_cu_memcpy(prob->csr_colind_cu, csr_colind, sizeof(int) * prob->nnz, GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + prob->csr_rowptr_cu, csr_rowptr, sizeof(int) * (prob->mrow + 1), GKYL_CU_MEMCPY_H2D + ); // Create a matrix object for the sparse input matrix. cudssStatus_t status = CUDSS_STATUS_SUCCESS; -// cudssMatrixType_t mtype = CUDSS_MTYPE_SPD; - cudssMatrixType_t mtype = CUDSS_MTYPE_GENERAL; + // cudssMatrixType_t mtype = CUDSS_MTYPE_SPD; + cudssMatrixType_t mtype = CUDSS_MTYPE_GENERAL; cudssMatrixViewType_t mview = CUDSS_MVIEW_UPPER; - cudssIndexBase_t base = CUDSS_BASE_ZERO; - prob->A = (cudssMatrix_t *) gkyl_malloc(prob->nprob * sizeof(cudssMatrix_t)); - for (int i=0; inprob; i++) { + cudssIndexBase_t base = CUDSS_BASE_ZERO; + prob->A = (cudssMatrix_t *)gkyl_malloc(prob->nprob * sizeof(cudssMatrix_t)); + for (int i = 0; i < prob->nprob; i++) { long off = i * prob->nnz; - checkCUDSS(cudssMatrixCreateCsr(&prob->A[i], prob->mrow, prob->ncol, prob->nnz, prob->csr_rowptr_cu, NULL, - prob->csr_colind_cu, prob->csr_val_cu+off, CUDA_R_32I, CUDA_R_64F, mtype, mview, - base), status, "cudssMatrixCreateCsr"); - + checkCUDSS( + cudssMatrixCreateCsr( + &prob->A[i], prob->mrow, prob->ncol, prob->nnz, prob->csr_rowptr_cu, NULL, + prob->csr_colind_cu, prob->csr_val_cu + off, CUDA_R_32I, CUDA_R_64F, mtype, mview, base + ), + status, "cudssMatrixCreateCsr" + ); + // Symbolic factorization. - checkCUDSS(cudssExecute(prob->handle, CUDSS_PHASE_ANALYSIS, prob->solverConfig[i], prob->solverData[i], - prob->A[i], prob->x[i], prob->b[i]), status, "cudssExecute for analysis"); - + checkCUDSS( + cudssExecute( + prob->handle, CUDSS_PHASE_ANALYSIS, prob->solverConfig[i], prob->solverData[i], prob->A[i], + prob->x[i], prob->b[i] + ), + status, "cudssExecute for analysis" + ); + // Factorization. - checkCUDSS(cudssExecute(prob->handle, CUDSS_PHASE_FACTORIZATION, prob->solverConfig[i], - prob->solverData[i], prob->A[i], prob->x[i], prob->b[i]), status, "cudssExecute for factor"); + checkCUDSS( + cudssExecute( + prob->handle, CUDSS_PHASE_FACTORIZATION, prob->solverConfig[i], prob->solverData[i], + prob->A[i], prob->x[i], prob->b[i] + ), + status, "cudssExecute for factor" + ); } gkyl_free(csr_colind); gkyl_free(csr_rowptr); } -void -gkyl_culinsolver_amat_update_from_triples(struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri) +void gkyl_culinsolver_amat_update_from_triples( + struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri +) { // Convert triples to CSR arrays on device. // Sorted (row-major order) keys (linear indices to flattened matrix). - for (size_t k=0; knprob; k++) { + for (size_t k = 0; k < prob->nprob; k++) { gkyl_mat_triples_iter *iter = gkyl_mat_triples_iter_new(tri[k]); - for (size_t i=0; innz; ++i) { + for (size_t i = 0; i < prob->nnz; ++i) { gkyl_mat_triples_iter_next(iter); // bump iterator. struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); - prob->csr_val_ho[k*prob->nnz+i] = mt.val; + prob->csr_val_ho[k * prob->nnz + i] = mt.val; } gkyl_mat_triples_iter_release(iter); } // Copy arrays to device. - gkyl_cu_memcpy(prob->csr_val_cu, prob->csr_val_ho, prob->nprob*prob->nnz*sizeof(double), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + prob->csr_val_cu, prob->csr_val_ho, prob->nprob * prob->nnz * sizeof(double), GKYL_CU_MEMCPY_H2D + ); - for (int i=0; inprob; i++) { + for (int i = 0; i < prob->nprob; i++) { long off = i * prob->nnz; cudssStatus_t status = CUDSS_STATUS_SUCCESS; // Set matrix values. - checkCUDSS(cudssMatrixSetValues(prob->A[i], prob->csr_val_cu+off), status, "cudssMatrixSetValues for resetting A."); + checkCUDSS( + cudssMatrixSetValues(prob->A[i], prob->csr_val_cu + off), status, + "cudssMatrixSetValues for resetting A." + ); // Factorize. - checkCUDSS(cudssExecute(prob->handle, CUDSS_PHASE_FACTORIZATION, prob->solverConfig[i], - prob->solverData[i], prob->A[i], prob->x[i], prob->b[i]), status, "cudssExecute for factor"); + checkCUDSS( + cudssExecute( + prob->handle, CUDSS_PHASE_FACTORIZATION, prob->solverConfig[i], prob->solverData[i], + prob->A[i], prob->x[i], prob->b[i] + ), + status, "cudssExecute for factor" + ); } } -void -gkyl_culinsolver_amat_update(struct gkyl_culinsolver_prob *prob, double *csr_values) +void gkyl_culinsolver_amat_update(struct gkyl_culinsolver_prob *prob, double *csr_values) { - for (int i=0; inprob; i++) { + for (int i = 0; i < prob->nprob; i++) { long off = i * prob->nnz; cudssStatus_t status = CUDSS_STATUS_SUCCESS; // Set matrix values. - checkCUDSS(cudssMatrixSetValues(prob->A[i], csr_values+off), status, "cudssMatrixSetValues for resetting A."); + checkCUDSS( + cudssMatrixSetValues(prob->A[i], csr_values + off), status, + "cudssMatrixSetValues for resetting A." + ); // Factorize. - checkCUDSS(cudssExecute(prob->handle, CUDSS_PHASE_FACTORIZATION, prob->solverConfig[i], - prob->solverData[i], prob->A[i], prob->x[i], prob->b[i]), status, "cudssExecute for factor"); + checkCUDSS( + cudssExecute( + prob->handle, CUDSS_PHASE_FACTORIZATION, prob->solverConfig[i], prob->solverData[i], + prob->A[i], prob->x[i], prob->b[i] + ), + status, "cudssExecute for factor" + ); } } -void -gkyl_culinsolver_brhs_from_triples(struct gkyl_culinsolver_prob *prob, gkyl_mat_triples *tri) +void gkyl_culinsolver_brhs_from_triples(struct gkyl_culinsolver_prob *prob, gkyl_mat_triples *tri) { - long nnz_rhs = gkyl_mat_triples_size(tri); // Number of non-zero entries in RHS matrix B. + long nnz_rhs = gkyl_mat_triples_size(tri); // Number of non-zero entries in RHS matrix B. // Sorted (column-major order) keys (linear indices to flattened matrix). gkyl_mat_triples_iter *iter = gkyl_mat_triples_iter_new(tri); - for (size_t i=0; irhs_ho[i] = mt.val; } gkyl_mat_triples_iter_release(iter); - gkyl_cu_memcpy(prob->rhs_cu, prob->rhs_ho, prob->nprob*prob->mrow*prob->nrhs*sizeof(double), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + prob->rhs_cu, prob->rhs_ho, prob->nprob * prob->mrow * prob->nrhs * sizeof(double), + GKYL_CU_MEMCPY_H2D + ); cudssStatus_t status = CUDSS_STATUS_SUCCESS; - for (size_t i=0; inprob; i++) { - long off = i * prob->mrow*prob->nrhs; - checkCUDSS(cudssMatrixSetValues(prob->b[i], prob->rhs_cu+off), - status, "cudssMatrixSetValues for setting brhs_from_triples"); + for (size_t i = 0; i < prob->nprob; i++) { + long off = i * prob->mrow * prob->nrhs; + checkCUDSS( + cudssMatrixSetValues(prob->b[i], prob->rhs_cu + off), status, + "cudssMatrixSetValues for setting brhs_from_triples" + ); } } -void -gkyl_culinsolver_solve(struct gkyl_culinsolver_prob *prob) +void gkyl_culinsolver_solve(struct gkyl_culinsolver_prob *prob) { cudssStatus_t status = CUDSS_STATUS_SUCCESS; - for (size_t i=0; inprob; i++) { - checkCUDSS(cudssExecute(prob->handle, CUDSS_PHASE_SOLVE, prob->solverConfig[i], prob->solverData[i], - prob->A[i], prob->x[i], prob->b[i]), status, "cudssExecute for solve"); + for (size_t i = 0; i < prob->nprob; i++) { + checkCUDSS( + cudssExecute( + prob->handle, CUDSS_PHASE_SOLVE, prob->solverConfig[i], prob->solverData[i], prob->A[i], + prob->x[i], prob->b[i] + ), + status, "cudssExecute for solve" + ); } } -void -gkyl_culinsolver_sync(struct gkyl_culinsolver_prob *prob) +void gkyl_culinsolver_sync(struct gkyl_culinsolver_prob *prob) { cudaStreamSynchronize(prob->stream); } -void -gkyl_culinsolver_finish_host(struct gkyl_culinsolver_prob *prob) +void gkyl_culinsolver_finish_host(struct gkyl_culinsolver_prob *prob) { //cudaStreamSynchronize(prob->stream); // not needed when using blocking stream - gkyl_cu_memcpy(prob->x_ho, prob->x_cu, prob->nprob*prob->mrow*prob->nrhs*sizeof(double), GKYL_CU_MEMCPY_D2H); + gkyl_cu_memcpy( + prob->x_ho, prob->x_cu, prob->nprob * prob->mrow * prob->nrhs * sizeof(double), + GKYL_CU_MEMCPY_D2H + ); } -void -gkyl_culinsolver_clear_rhs(struct gkyl_culinsolver_prob *prob, double val) +void gkyl_culinsolver_clear_rhs(struct gkyl_culinsolver_prob *prob, double val) { - gkyl_cu_memset(prob->rhs_cu, val, prob->nprob*prob->mrow*prob->nrhs*sizeof(double)); + gkyl_cu_memset(prob->rhs_cu, val, prob->nprob * prob->mrow * prob->nrhs * sizeof(double)); } -void -gkyl_culinsolver_clear_csr_values(struct gkyl_culinsolver_prob *prob, double val) +void gkyl_culinsolver_clear_csr_values(struct gkyl_culinsolver_prob *prob, double val) { - gkyl_cu_memset(prob->csr_val_cu, val, prob->nprob*prob->nnz*sizeof(double)); + gkyl_cu_memset(prob->csr_val_cu, val, prob->nprob * prob->nnz * sizeof(double)); } -double* -gkyl_culinsolver_get_rhs_ptr(struct gkyl_culinsolver_prob *prob, long loc) +double *gkyl_culinsolver_get_rhs_ptr(struct gkyl_culinsolver_prob *prob, long loc) { - return prob->rhs_cu+loc; + return prob->rhs_cu + loc; } -double* -gkyl_culinsolver_get_sol_ptr(struct gkyl_culinsolver_prob *prob, long loc) +double *gkyl_culinsolver_get_sol_ptr(struct gkyl_culinsolver_prob *prob, long loc) { - return prob->x_cu+loc; + return prob->x_cu + loc; } -double* -gkyl_culinsolver_get_csr_values_ptr(struct gkyl_culinsolver_prob *prob, long loc) +double *gkyl_culinsolver_get_csr_values_ptr(struct gkyl_culinsolver_prob *prob, long loc) { - return prob->csr_val_cu+loc; + return prob->csr_val_cu + loc; } -double -gkyl_culinsolver_get_sol_lin(struct gkyl_culinsolver_prob *prob, long loc) +double gkyl_culinsolver_get_sol_lin(struct gkyl_culinsolver_prob *prob, long loc) { return prob->x_ho[loc]; } -void -gkyl_culinsolver_prob_release(struct gkyl_culinsolver_prob *prob) +void gkyl_culinsolver_prob_release(struct gkyl_culinsolver_prob *prob) { cudssStatus_t status = CUDSS_STATUS_SUCCESS; - for (size_t i=0; inprob; i++) { + for (size_t i = 0; i < prob->nprob; i++) { checkCUDSS(cudssMatrixDestroy(prob->A[i]), status, "cudssMatrixDestroy for A"); checkCUDSS(cudssMatrixDestroy(prob->b[i]), status, "cudssMatrixDestroy for b"); checkCUDSS(cudssMatrixDestroy(prob->x[i]), status, "cudssMatrixDestroy for x"); diff --git a/core/zero/cusolver_ops.cu b/core/zero/cusolver_ops.cu index 8634a30ed8..ae9eb38ab8 100644 --- a/core/zero/cusolver_ops.cu +++ b/core/zero/cusolver_ops.cu @@ -23,7 +23,7 @@ extern "C" { // struct gkyl_culinsolver_prob { - double *rhs, *rhs_cu; // right-hand side vector (reused to store the answer x). + double *rhs, *rhs_cu; // right-hand side vector (reused to store the answer x). double *x; double *csrvalA_cu; int *csrrowptrA_cu, *csrcolindA_cu; @@ -56,27 +56,29 @@ struct gkyl_culinsolver_prob { double **csrvalApointers_cu; // array of pointers to LHS A matrices. }; -gkyl_culinsolver_prob* -gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs) +gkyl_culinsolver_prob *gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs) { - assert((nprob==1) || (nrhs==1)); + assert((nprob == 1) || (nrhs == 1)); - struct gkyl_culinsolver_prob *prob = (struct gkyl_culinsolver_prob*) gkyl_malloc(sizeof(*prob)); + struct gkyl_culinsolver_prob *prob = (struct gkyl_culinsolver_prob *)gkyl_malloc(sizeof(*prob)); prob->nprob = nprob; prob->mrow = mrow; prob->ncol = ncol; - prob->nrhs = GKYL_MAX2(nprob,nrhs); + prob->nrhs = GKYL_MAX2(nprob, nrhs); - prob->rhs = (double*) gkyl_malloc(mrow*prob->nrhs*sizeof(double)); - prob->rhs_cu = (double*) gkyl_cu_malloc(mrow*prob->nrhs*sizeof(double)); + prob->rhs = (double *)gkyl_malloc(mrow * prob->nrhs * sizeof(double)); + prob->rhs_cu = (double *)gkyl_cu_malloc(mrow * prob->nrhs * sizeof(double)); if (prob->nrhs > 1) { - double **rhspointers = (double**) gkyl_malloc(prob->nrhs*sizeof(double*)); - prob->rhspointers_cu = (double**) gkyl_cu_malloc(prob->nrhs*sizeof(double*)); - for (size_t k=0; knrhs; k++) - rhspointers[k] = &prob->rhs_cu[k*mrow]; - gkyl_cu_memcpy(prob->rhspointers_cu, rhspointers, prob->nrhs*sizeof(double*), GKYL_CU_MEMCPY_H2D); + double **rhspointers = (double **)gkyl_malloc(prob->nrhs * sizeof(double *)); + prob->rhspointers_cu = (double **)gkyl_cu_malloc(prob->nrhs * sizeof(double *)); + for (size_t k = 0; k < prob->nrhs; k++) { + rhspointers[k] = &prob->rhs_cu[k * mrow]; + } + gkyl_cu_memcpy( + prob->rhspointers_cu, rhspointers, prob->nrhs * sizeof(double *), GKYL_CU_MEMCPY_H2D + ); gkyl_free(rhspointers); } @@ -91,7 +93,7 @@ gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs) cusparseCreateMatDescr(&prob->A); cusparseSetMatType(prob->A, CUSPARSE_MATRIX_TYPE_GENERAL); - cusparseSetMatIndexBase(prob->A, CUSPARSE_INDEX_BASE_ZERO); + cusparseSetMatIndexBase(prob->A, CUSPARSE_INDEX_BASE_ZERO); cusparseCreate(&prob->cusparseH); cusparseSetStream(prob->cusparseH, prob->stream); @@ -103,7 +105,7 @@ gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs) // nzero is the value below which zero pivot is flagged. // nboost is the value which is substitured for zero pivot. prob->nzero = 0.0; - prob->nboost= 0.0; + prob->nboost = 0.0; // Constants used in cusolverSp: // singularity is -1 if A is invertible under tol // tol determines the condition of singularity @@ -117,34 +119,42 @@ gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs) return prob; } -void -gkyl_culinsolver_amat_from_triples(struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri) +void gkyl_culinsolver_amat_from_triples( + struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri +) { prob->nnz = gkyl_mat_triples_size(tri[0]); - for (size_t k=0; knprob; k++) { - assert(gkyl_mat_triples_size(tri[k]) == prob->nnz); // No. of nonzeros must be the same for every problem. - assert(gkyl_mat_triples_is_rowmaj(tri[k])); // Triples must be in rowmaj order for cusolver. + for (size_t k = 0; k < prob->nprob; k++) { + assert( + gkyl_mat_triples_size(tri[k]) == prob->nnz + ); // No. of nonzeros must be the same for every problem. + assert(gkyl_mat_triples_is_rowmaj(tri[k])); // Triples must be in rowmaj order for cusolver. } // Convert triples to CSR arrays on device. // Use CSR format - double *csrvalA = (double*) gkyl_malloc(prob->nprob*prob->nnz*sizeof(double)); // non-zero matrix elements. - int *csrcolindA = (int*) gkyl_malloc(sizeof(int)*prob->nnz); // col index of entries in csrvalA. - int *csrrowptrA = (int*) gkyl_malloc(sizeof(int)*(prob->mrow+1)); // 1st entry of each row as index in csrvalA. - - bool *csrrowptrA_assigned = (bool*) gkyl_malloc(sizeof(bool)*prob->mrow); - for (size_t i=0; imrow; i++) csrrowptrA_assigned[i] = false; + double *csrvalA = + (double *)gkyl_malloc(prob->nprob * prob->nnz * sizeof(double)); // non-zero matrix elements. + int *csrcolindA = (int *)gkyl_malloc(sizeof(int) * prob->nnz); // col index of entries in csrvalA. + int *csrrowptrA = (int *)gkyl_malloc( + sizeof(int) * (prob->mrow + 1) + ); // 1st entry of each row as index in csrvalA. + + bool *csrrowptrA_assigned = (bool *)gkyl_malloc(sizeof(bool) * prob->mrow); + for (size_t i = 0; i < prob->mrow; i++) { + csrrowptrA_assigned[i] = false; + } // Sorted (row-major order) keys (linear indices to flattened matrix). - for (size_t k=0; knprob; k++) { + for (size_t k = 0; k < prob->nprob; k++) { gkyl_mat_triples_iter *iter = gkyl_mat_triples_iter_new(tri[k]); - for (size_t i=0; innz; ++i) { + for (size_t i = 0; i < prob->nnz; ++i) { gkyl_mat_triples_iter_next(iter); // bump iterator. struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); - size_t idx[2] = { mt.row, mt.col }; - - csrvalA[k*prob->nnz+i] = mt.val; - if (k==0) { + size_t idx[2] = {mt.row, mt.col}; + + csrvalA[k * prob->nnz + i] = mt.val; + if (k == 0) { csrcolindA[i] = idx[1]; if (!csrrowptrA_assigned[idx[0]]) { csrrowptrA[idx[0]] = i; @@ -158,103 +168,138 @@ gkyl_culinsolver_amat_from_triples(struct gkyl_culinsolver_prob *prob, struct gk gkyl_free(csrrowptrA_assigned); // copy arrays to device - prob->csrvalA_cu = (double*) gkyl_cu_malloc(prob->nprob*prob->nnz*sizeof(double)); // non-zero matrix elements. - prob->csrcolindA_cu = (int*) gkyl_cu_malloc(sizeof(int)*prob->nnz); // col index of entries in csrvalA. - prob->csrrowptrA_cu = (int*) gkyl_cu_malloc(sizeof(int)*(prob->mrow+1)); // 1st entry of each row as index in csrvalA. - gkyl_cu_memcpy(prob->csrvalA_cu, csrvalA, prob->nprob*prob->nnz*sizeof(double), GKYL_CU_MEMCPY_H2D); - gkyl_cu_memcpy(prob->csrcolindA_cu, csrcolindA, sizeof(int)*prob->nnz, GKYL_CU_MEMCPY_H2D); - gkyl_cu_memcpy(prob->csrrowptrA_cu, csrrowptrA, sizeof(int)*(prob->mrow+1), GKYL_CU_MEMCPY_H2D); + prob->csrvalA_cu = + (double *)gkyl_cu_malloc(prob->nprob * prob->nnz * sizeof(double)); // non-zero matrix elements. + prob->csrcolindA_cu = + (int *)gkyl_cu_malloc(sizeof(int) * prob->nnz); // col index of entries in csrvalA. + prob->csrrowptrA_cu = (int *)gkyl_cu_malloc( + sizeof(int) * (prob->mrow + 1) + ); // 1st entry of each row as index in csrvalA. + gkyl_cu_memcpy( + prob->csrvalA_cu, csrvalA, prob->nprob * prob->nnz * sizeof(double), GKYL_CU_MEMCPY_H2D + ); + gkyl_cu_memcpy(prob->csrcolindA_cu, csrcolindA, sizeof(int) * prob->nnz, GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + prob->csrrowptrA_cu, csrrowptrA, sizeof(int) * (prob->mrow + 1), GKYL_CU_MEMCPY_H2D + ); double **csrvalApointers; if (prob->nrhs > 1) { // cusolverRfBatch also needs an array of pointers to // the various A matrices (all the same if nprob=1). - csrvalApointers = (double**) gkyl_malloc(prob->nrhs*sizeof(double*)); - prob->csrvalApointers_cu = (double**) gkyl_cu_malloc(prob->nrhs*sizeof(double*)); - for (size_t k=0; knrhs; k++) - csrvalApointers[k] = prob->nprob == 1? &prob->csrvalA_cu[0] : &prob->csrvalA_cu[k*prob->nnz]; - gkyl_cu_memcpy(prob->csrvalApointers_cu, csrvalApointers, sizeof(double*)*prob->nrhs, GKYL_CU_MEMCPY_H2D); + csrvalApointers = (double **)gkyl_malloc(prob->nrhs * sizeof(double *)); + prob->csrvalApointers_cu = (double **)gkyl_cu_malloc(prob->nrhs * sizeof(double *)); + for (size_t k = 0; k < prob->nrhs; k++) { + csrvalApointers[k] = prob->nprob == 1 ? &prob->csrvalA_cu[0] : + &prob->csrvalA_cu[k * prob->nnz]; + } + gkyl_cu_memcpy( + prob->csrvalApointers_cu, csrvalApointers, sizeof(double *) * prob->nrhs, GKYL_CU_MEMCPY_H2D + ); } // Use CusolverRf // reorder to reduce zero fill-in // Qreorder = symrcm(A) or Qreroder = symamd(A) - int *h_Qreorder = (int*)gkyl_malloc(sizeof(int)*prob->ncol); + int *h_Qreorder = (int *)gkyl_malloc(sizeof(int) * prob->ncol); // RCM reordering -- seems much slower than others! -// cusolverSpXcsrsymrcmHost(prob->cusolverSpH, prob->mrow, prob->nnz, -// prob->A, csrrowptrA, csrcolindA, h_Qreorder); + // cusolverSpXcsrsymrcmHost(prob->cusolverSpH, prob->mrow, prob->nnz, + // prob->A, csrrowptrA, csrcolindA, h_Qreorder); // AMD reordering - cusolverSpXcsrsymamdHost(prob->cusolverSpH, prob->mrow, prob->nnz, - prob->A, csrrowptrA, csrcolindA, h_Qreorder); + cusolverSpXcsrsymamdHost( + prob->cusolverSpH, prob->mrow, prob->nnz, prob->A, csrrowptrA, csrcolindA, h_Qreorder + ); // MDQ reordering -// cusolverSpXcsrsymmdqHost(prob->cusolverSpH, prob->mrow, prob->nnz, -// prob->A, csrrowptrA, csrcolindA, h_Qreorder); + // cusolverSpXcsrsymmdqHost(prob->cusolverSpH, prob->mrow, prob->nnz, + // prob->A, csrrowptrA, csrcolindA, h_Qreorder); // METIS reordering -// cusolverSpXcsrmetisndHost(prob->cusolverSpH, prob->mrow, prob->nnz, -// prob->A, csrrowptrA, csrcolindA, NULL, h_Qreorder); + // cusolverSpXcsrmetisndHost(prob->cusolverSpH, prob->mrow, prob->nnz, + // prob->A, csrrowptrA, csrcolindA, NULL, h_Qreorder); // ............... Compute B = Q*A*Q^T ................... // - int *h_csrRowIndB = (int*) gkyl_malloc(sizeof(int)*(prob->mrow+1)); - int *h_csrColIndB = (int*) gkyl_malloc(sizeof(int)*prob->nnz); - memcpy(h_csrRowIndB, csrrowptrA, sizeof(int)*(prob->mrow+1)); - memcpy(h_csrColIndB, csrcolindA, sizeof(int)*prob->nnz); + int *h_csrRowIndB = (int *)gkyl_malloc(sizeof(int) * (prob->mrow + 1)); + int *h_csrColIndB = (int *)gkyl_malloc(sizeof(int) * prob->nnz); + memcpy(h_csrRowIndB, csrrowptrA, sizeof(int) * (prob->mrow + 1)); + memcpy(h_csrColIndB, csrcolindA, sizeof(int) * prob->nnz); size_t size_perm = 0; - cusolverSpXcsrperm_bufferSizeHost(prob->cusolverSpH, prob->mrow, prob->ncol, prob->nnz, - prob->A, h_csrRowIndB, h_csrColIndB, h_Qreorder, h_Qreorder, &size_perm); + cusolverSpXcsrperm_bufferSizeHost( + prob->cusolverSpH, prob->mrow, prob->ncol, prob->nnz, prob->A, h_csrRowIndB, h_csrColIndB, + h_Qreorder, h_Qreorder, &size_perm + ); - void *buffer_cpu = NULL; // working space for permutation (B = Q*A*Q^T) and LU w/ partial pivoting in cusolverSp. - buffer_cpu = (void*) gkyl_malloc(sizeof(char)*size_perm); + void *buffer_cpu = + NULL; // working space for permutation (B = Q*A*Q^T) and LU w/ partial pivoting in cusolverSp. + buffer_cpu = (void *)gkyl_malloc(sizeof(char) * size_perm); // h_mapBfromA = Identity - int *h_mapBfromA = (int*) gkyl_malloc(sizeof(int)*prob->nnz); - for(int j = 0 ; j < prob->nnz ; j++) h_mapBfromA[j] = j; - cusolverSpXcsrpermHost(prob->cusolverSpH, prob->mrow, prob->ncol, prob->nnz, prob->A, - h_csrRowIndB, h_csrColIndB, h_Qreorder, h_Qreorder, h_mapBfromA, buffer_cpu); + int *h_mapBfromA = (int *)gkyl_malloc(sizeof(int) * prob->nnz); + for (int j = 0; j < prob->nnz; j++) { + h_mapBfromA[j] = j; + } + cusolverSpXcsrpermHost( + prob->cusolverSpH, prob->mrow, prob->ncol, prob->nnz, prob->A, h_csrRowIndB, h_csrColIndB, + h_Qreorder, h_Qreorder, h_mapBfromA, buffer_cpu + ); // B = A( mapBfromA ) - double *h_csrValB = (double*) gkyl_malloc(sizeof(double)*prob->nnz); - for(int j = 0 ; j < prob->nnz ; j++) h_csrValB[j] = csrvalA[ h_mapBfromA[j] ]; + double *h_csrValB = (double *)gkyl_malloc(sizeof(double) * prob->nnz); + for (int j = 0; j < prob->nnz; j++) { + h_csrValB[j] = csrvalA[h_mapBfromA[j]]; + } // ................ Solve A*x = b by LU(B) in cusolverSp ................ // // Analyze LU(B) to know structure of Q and R, and upper bound for nnz(L+U). - cusolverSpXcsrluAnalysisHost(prob->cusolverSpH, prob->mrow, prob->nnz, - prob->A, h_csrRowIndB, h_csrColIndB, prob->infolu); + cusolverSpXcsrluAnalysisHost( + prob->cusolverSpH, prob->mrow, prob->nnz, prob->A, h_csrRowIndB, h_csrColIndB, prob->infolu + ); // Workspace for LU(B). size_t size_lu = 0; // Size of working space for csrlu. - cusolverSpDcsrluBufferInfoHost(prob->cusolverSpH, prob->mrow, prob->nnz, prob->A, - h_csrValB, h_csrRowIndB, h_csrColIndB, prob->infolu, &prob->size_internal, &size_lu); + cusolverSpDcsrluBufferInfoHost( + prob->cusolverSpH, prob->mrow, prob->nnz, prob->A, h_csrValB, h_csrRowIndB, h_csrColIndB, + prob->infolu, &prob->size_internal, &size_lu + ); - if (buffer_cpu) free(buffer_cpu); - buffer_cpu = (void*)gkyl_malloc(sizeof(char)*size_lu); + if (buffer_cpu) { + free(buffer_cpu); + } + buffer_cpu = (void *)gkyl_malloc(sizeof(char) * size_lu); // Compute Ppivot*B = L*U. - cusolverSpDcsrluFactorHost(prob->cusolverSpH, prob->mrow, prob->nnz, prob->A, - h_csrValB, h_csrRowIndB, h_csrColIndB, prob->infolu, prob->pivot_threshold, buffer_cpu); + cusolverSpDcsrluFactorHost( + prob->cusolverSpH, prob->mrow, prob->nnz, prob->A, h_csrValB, h_csrRowIndB, h_csrColIndB, + prob->infolu, prob->pivot_threshold, buffer_cpu + ); // Check if the matrix is singular \n"); int singularity = 0; cusolverSpDcsrluZeroPivotHost(prob->cusolverSpH, prob->infolu, prob->tol, &singularity); - if ( 0 <= singularity){ + if (0 <= singularity) { fprintf(stderr, "Error: A is not invertible, singularity=%d\n", singularity); assert(false); } // Solve A*x = b, i.e. solve B*(Qx) = Q*b. - double *h_b = (double*) gkyl_malloc(sizeof(double)*prob->mrow); - for (size_t i=0; imrow; i++) h_b[i] = 1.0; // Use arbitrary RHS for now. - double *h_bhat = (double*) gkyl_malloc(sizeof(double)*prob->mrow); // b_hat = Q*b. - double *h_xhat = (double*) gkyl_malloc(sizeof(double)*prob->ncol); // Q*x_hat = x. - for(int j = 0 ; j < prob->mrow ; j++) h_bhat[j] = h_b[h_Qreorder[j]]; // b_hat = Q*b + double *h_b = (double *)gkyl_malloc(sizeof(double) * prob->mrow); + for (size_t i = 0; i < prob->mrow; i++) { + h_b[i] = 1.0; // Use arbitrary RHS for now. + } + double *h_bhat = (double *)gkyl_malloc(sizeof(double) * prob->mrow); // b_hat = Q*b. + double *h_xhat = (double *)gkyl_malloc(sizeof(double) * prob->ncol); // Q*x_hat = x. + for (int j = 0; j < prob->mrow; j++) { + h_bhat[j] = h_b[h_Qreorder[j]]; // b_hat = Q*b + } // B*x_hat = b_hat. cusolverSpDcsrluSolveHost(prob->cusolverSpH, prob->mrow, h_bhat, h_xhat, prob->infolu, buffer_cpu); // x = Q^T * x_hat - double *h_x = (double*) gkyl_malloc(sizeof(double)*prob->ncol); // x = A \ b - for (int j = 0 ; j < prob->mrow ; j++) h_x[h_Qreorder[j]] = h_xhat[j]; + double *h_x = (double *)gkyl_malloc(sizeof(double) * prob->ncol); // x = A \ b + for (int j = 0; j < prob->mrow; j++) { + h_x[h_Qreorder[j]] = h_xhat[j]; + } // .............. Extract P, Q, L and U from P*B*Q^T = L*U .............. // @@ -262,18 +307,19 @@ gkyl_culinsolver_amat_from_triples(struct gkyl_culinsolver_prob *prob, struct gk int nnzL = 0, nnzU = 0; cusolverSpXcsrluNnzHost(prob->cusolverSpH, &nnzL, &nnzU, prob->infolu); - int *h_Plu = (int*) gkyl_malloc(sizeof(int)*prob->mrow); - int *h_Qlu = (int*) gkyl_malloc(sizeof(int)*prob->ncol); - double *h_csrValL = (double*)gkyl_malloc(sizeof(double)*nnzL); - int *h_csrRowIndL = (int*)gkyl_malloc(sizeof(int)*(prob->mrow+1)); - int *h_csrColIndL = (int*)gkyl_malloc(sizeof(int)*nnzL); - double *h_csrValU = (double*)gkyl_malloc(sizeof(double)*nnzU); - int *h_csrRowIndU = (int*)gkyl_malloc(sizeof(int)*(prob->mrow+1)); - int *h_csrColIndU = (int*)gkyl_malloc(sizeof(int)*nnzU); + int *h_Plu = (int *)gkyl_malloc(sizeof(int) * prob->mrow); + int *h_Qlu = (int *)gkyl_malloc(sizeof(int) * prob->ncol); + double *h_csrValL = (double *)gkyl_malloc(sizeof(double) * nnzL); + int *h_csrRowIndL = (int *)gkyl_malloc(sizeof(int) * (prob->mrow + 1)); + int *h_csrColIndL = (int *)gkyl_malloc(sizeof(int) * nnzL); + double *h_csrValU = (double *)gkyl_malloc(sizeof(double) * nnzU); + int *h_csrRowIndU = (int *)gkyl_malloc(sizeof(int) * (prob->mrow + 1)); + int *h_csrColIndU = (int *)gkyl_malloc(sizeof(int) * nnzU); - cusolverSpDcsrluExtractHost(prob->cusolverSpH, h_Plu, h_Qlu, prob->A, - h_csrValL, h_csrRowIndL, h_csrColIndL, prob->A, - h_csrValU, h_csrRowIndU, h_csrColIndU, prob->infolu, buffer_cpu); + cusolverSpDcsrluExtractHost( + prob->cusolverSpH, h_Plu, h_Qlu, prob->A, h_csrValL, h_csrRowIndL, h_csrColIndL, prob->A, + h_csrValU, h_csrRowIndU, h_csrColIndU, prob->infolu, buffer_cpu + ); /* B = Qreorder*A*Qreorder^T * Plu*B*Qlu^T = L*U @@ -286,16 +332,20 @@ gkyl_culinsolver_amat_from_triples(struct gkyl_culinsolver_prob *prob, struct gk * which is the fundamental relation in cusolverRf. */ // ............ Form P*A*Q^T = L*U .................. // - int *h_P = (int*)gkyl_malloc(sizeof(int)*prob->mrow); - int *h_Q = (int*)gkyl_malloc(sizeof(int)*prob->ncol); + int *h_P = (int *)gkyl_malloc(sizeof(int) * prob->mrow); + int *h_Q = (int *)gkyl_malloc(sizeof(int) * prob->ncol); // P = Plu*Qreroder. // Gather operation, P = Qreorder(Plu). - for(int j = 0 ; j < prob->mrow ; j++) h_P[j] = h_Qreorder[h_Plu[j]]; + for (int j = 0; j < prob->mrow; j++) { + h_P[j] = h_Qreorder[h_Plu[j]]; + } // Q = Qlu*Qreorder. // Gather operation, Q = Qreorder(Qlu). - for(int j = 0 ; j < prob->ncol ; j++) h_Q[j] = h_Qreorder[h_Qlu[j]]; + for (int j = 0; j < prob->ncol; j++) { + h_Q[j] = h_Qreorder[h_Qlu[j]]; + } // ............... Create cusolverRf handle ................ // cusolverRfCreate(&prob->cusolverRfH); @@ -308,162 +358,182 @@ gkyl_culinsolver_amat_from_triples(struct gkyl_culinsolver_prob *prob, struct gk cusolverRfSetAlgs(prob->cusolverRfH, prob->fact_alg, prob->solve_alg); // Matrix mode: L and U are CSR format, and L has implicit unit diagonal - cusolverRfSetMatrixFormat(prob->cusolverRfH, CUSOLVERRF_MATRIX_FORMAT_CSR, CUSOLVERRF_UNIT_DIAGONAL_ASSUMED_L); + cusolverRfSetMatrixFormat( + prob->cusolverRfH, CUSOLVERRF_MATRIX_FORMAT_CSR, CUSOLVERRF_UNIT_DIAGONAL_ASSUMED_L + ); // Fast mode for matrix assembling cusolverRfSetResetValuesFastMode(prob->cusolverRfH, CUSOLVERRF_RESET_VALUES_FAST_MODE_ON); // ............... Assemble P*A*Q = L*U .................. // if ((prob->nprob == 1) && (prob->nrhs == 1)) { - cusolverRfSetupHost(prob->mrow, prob->nnz, csrrowptrA, csrcolindA, csrvalA, - nnzL, h_csrRowIndL, h_csrColIndL, h_csrValL, - nnzU, h_csrRowIndU, h_csrColIndU, h_csrValU, h_P, h_Q, prob->cusolverRfH); + cusolverRfSetupHost( + prob->mrow, prob->nnz, csrrowptrA, csrcolindA, csrvalA, nnzL, h_csrRowIndL, h_csrColIndL, + h_csrValL, nnzU, h_csrRowIndU, h_csrColIndU, h_csrValU, h_P, h_Q, prob->cusolverRfH + ); } else { - for (size_t k=0; knrhs; k++) - csrvalApointers[k] = prob->nprob == 1? &csrvalA[0] : &csrvalA[k*prob->nnz]; - cusolverRfBatchSetupHost(prob->nrhs, prob->mrow, prob->nnz, csrrowptrA, csrcolindA, csrvalApointers, - nnzL, h_csrRowIndL, h_csrColIndL, h_csrValL, - nnzU, h_csrRowIndU, h_csrColIndU, h_csrValU, h_P, h_Q, prob->cusolverRfH); + for (size_t k = 0; k < prob->nrhs; k++) { + csrvalApointers[k] = prob->nprob == 1 ? &csrvalA[0] : &csrvalA[k * prob->nnz]; + } + cusolverRfBatchSetupHost( + prob->nrhs, prob->mrow, prob->nnz, csrrowptrA, csrcolindA, csrvalApointers, nnzL, + h_csrRowIndL, h_csrColIndL, h_csrValL, nnzU, h_csrRowIndU, h_csrColIndU, h_csrValU, h_P, h_Q, + prob->cusolverRfH + ); } cudaDeviceSynchronize(); // ................ Analyze to extract parallelism ............ // - if (prob->nrhs == 1) + if (prob->nrhs == 1) { cusolverRfAnalyze(prob->cusolverRfH); - else + } else { cusolverRfBatchAnalyze(prob->cusolverRfH); + } // ................ Import A to cusolverRf ................... // - prob->d_P = (int*) gkyl_cu_malloc(sizeof(int)*prob->mrow); // P*A*Q^T = L*U - prob->d_Q = (int*) gkyl_cu_malloc(sizeof(int)*prob->ncol); - gkyl_cu_memcpy(prob->d_P, h_P, sizeof(int)*prob->mrow, GKYL_CU_MEMCPY_H2D); - gkyl_cu_memcpy(prob->d_Q, h_Q, sizeof(int)*prob->ncol, GKYL_CU_MEMCPY_H2D); - - if (prob->nrhs == 1) - cusolverRfResetValues(prob->mrow, prob->nnz, prob->csrrowptrA_cu, prob->csrcolindA_cu, - prob->csrvalA_cu, prob->d_P, prob->d_Q, prob->cusolverRfH); - else - cusolverRfBatchResetValues(prob->nrhs, prob->mrow, prob->nnz, prob->csrrowptrA_cu, prob->csrcolindA_cu, - prob->csrvalApointers_cu, prob->d_P, prob->d_Q, prob->cusolverRfH); - + prob->d_P = (int *)gkyl_cu_malloc(sizeof(int) * prob->mrow); // P*A*Q^T = L*U + prob->d_Q = (int *)gkyl_cu_malloc(sizeof(int) * prob->ncol); + gkyl_cu_memcpy(prob->d_P, h_P, sizeof(int) * prob->mrow, GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(prob->d_Q, h_Q, sizeof(int) * prob->ncol, GKYL_CU_MEMCPY_H2D); + + if (prob->nrhs == 1) { + cusolverRfResetValues( + prob->mrow, prob->nnz, prob->csrrowptrA_cu, prob->csrcolindA_cu, prob->csrvalA_cu, prob->d_P, + prob->d_Q, prob->cusolverRfH + ); + } else { + cusolverRfBatchResetValues( + prob->nrhs, prob->mrow, prob->nnz, prob->csrrowptrA_cu, prob->csrcolindA_cu, + prob->csrvalApointers_cu, prob->d_P, prob->d_Q, prob->cusolverRfH + ); + } + cudaDeviceSynchronize(); - + //................... Refactorization .................... // - - if (prob->nrhs == 1) + + if (prob->nrhs == 1) { cusolverRfRefactor(prob->cusolverRfH); - else + } else { cusolverRfBatchRefactor(prob->cusolverRfH); - + } + cudaDeviceSynchronize(); - if (prob->nrhs == 1) - prob->d_T = (double*) gkyl_cu_malloc(sizeof(double)*prob->mrow); // Working space in cusolverRfSolve, |d_T| = n * nrhs. - else - prob->d_T = (double*) gkyl_cu_malloc(sizeof(double)*prob->mrow*prob->nrhs*2); // Working space in cusolverRfSolve, |d_T| = 2*n*nrhs*batchSize. + if (prob->nrhs == 1) { + prob->d_T = (double *)gkyl_cu_malloc( + sizeof(double) * prob->mrow + ); // Working space in cusolverRfSolve, |d_T| = n * nrhs. + } else { + prob->d_T = (double *)gkyl_cu_malloc( + sizeof(double) * prob->mrow * prob->nrhs * 2 + ); // Working space in cusolverRfSolve, |d_T| = 2*n*nrhs*batchSize. + } gkyl_free(h_Qreorder); gkyl_free(h_csrRowIndB); gkyl_free(h_csrColIndB); - gkyl_free(h_csrValB ); - gkyl_free(h_mapBfromA ); - + gkyl_free(h_csrValB); + gkyl_free(h_mapBfromA); + gkyl_free(h_b); gkyl_free(h_x); gkyl_free(h_xhat); gkyl_free(h_bhat); - + gkyl_free(buffer_cpu); - + gkyl_free(h_Plu); gkyl_free(h_Qlu); gkyl_free(h_csrRowIndL); gkyl_free(h_csrColIndL); - gkyl_free(h_csrValL ); + gkyl_free(h_csrValL); gkyl_free(h_csrRowIndU); gkyl_free(h_csrColIndU); - gkyl_free(h_csrValU ); - + gkyl_free(h_csrValU); + gkyl_free(h_P); gkyl_free(h_Q); gkyl_free(csrcolindA); gkyl_free(csrrowptrA); gkyl_free(csrvalA); - if (prob->nrhs > 1) gkyl_free(csrvalApointers); - + if (prob->nrhs > 1) { + gkyl_free(csrvalApointers); + } } -void -gkyl_culinsolver_brhs_from_triples(struct gkyl_culinsolver_prob *prob, gkyl_mat_triples *tri) +void gkyl_culinsolver_brhs_from_triples(struct gkyl_culinsolver_prob *prob, gkyl_mat_triples *tri) { - long nnz_rhs = gkyl_mat_triples_size(tri); // number of non-zero entries in RHS matrix B - + long nnz_rhs = gkyl_mat_triples_size(tri); // number of non-zero entries in RHS matrix B + // sorted (column-major order) keys (linear indices to flattened matrix) gkyl_mat_triples_iter *iter = gkyl_mat_triples_iter_new(tri); - for (size_t i=0; irhs[i] = mt.val; } gkyl_mat_triples_iter_release(iter); - - gkyl_cu_memcpy(prob->rhs_cu, prob->rhs, sizeof(double)*prob->mrow*prob->nrhs, GKYL_CU_MEMCPY_H2D); + + gkyl_cu_memcpy( + prob->rhs_cu, prob->rhs, sizeof(double) * prob->mrow * prob->nrhs, GKYL_CU_MEMCPY_H2D + ); } -void -gkyl_culinsolver_solve(struct gkyl_culinsolver_prob *prob) +void gkyl_culinsolver_solve(struct gkyl_culinsolver_prob *prob) { // MF 2023/05/25: the 1 below is nrhs, and cuSolver docs say only 1 is supported. To me it is not // clear whether this means one can only solve 1 system, or whether we can solve multiple systems // but each system can only have nrhs=1. I think it's the latter. - if (prob->nrhs==1) - cusolverRfSolve(prob->cusolverRfH, prob->d_P, prob->d_Q, 1, prob->d_T, prob->mrow, prob->rhs_cu, prob->mrow); - else - cusolverRfBatchSolve(prob->cusolverRfH, prob->d_P, prob->d_Q, 1, prob->d_T, prob->mrow, prob->rhspointers_cu, prob->mrow); + if (prob->nrhs == 1) { + cusolverRfSolve( + prob->cusolverRfH, prob->d_P, prob->d_Q, 1, prob->d_T, prob->mrow, prob->rhs_cu, prob->mrow + ); + } else { + cusolverRfBatchSolve( + prob->cusolverRfH, prob->d_P, prob->d_Q, 1, prob->d_T, prob->mrow, prob->rhspointers_cu, + prob->mrow + ); + } } -void -gkyl_culinsolver_finish_host(struct gkyl_culinsolver_prob *prob) +void gkyl_culinsolver_finish_host(struct gkyl_culinsolver_prob *prob) { //cudaStreamSynchronize(prob->stream); // not needed when using blocking stream - gkyl_cu_memcpy(prob->rhs, prob->rhs_cu, sizeof(double)*prob->mrow*prob->nrhs, GKYL_CU_MEMCPY_D2H); + gkyl_cu_memcpy( + prob->rhs, prob->rhs_cu, sizeof(double) * prob->mrow * prob->nrhs, GKYL_CU_MEMCPY_D2H + ); } -void -gkyl_culinsolver_clear_rhs(struct gkyl_culinsolver_prob *prob, double val) +void gkyl_culinsolver_clear_rhs(struct gkyl_culinsolver_prob *prob, double val) { - gkyl_cu_memset(prob->rhs_cu, val, prob->mrow*prob->nrhs*sizeof(double)); + gkyl_cu_memset(prob->rhs_cu, val, prob->mrow * prob->nrhs * sizeof(double)); } -double* -gkyl_culinsolver_get_rhs_ptr(struct gkyl_culinsolver_prob *prob, long loc) +double *gkyl_culinsolver_get_rhs_ptr(struct gkyl_culinsolver_prob *prob, long loc) { - return prob->rhs_cu+loc; + return prob->rhs_cu + loc; } -double* -gkyl_culinsolver_get_sol_ptr(struct gkyl_culinsolver_prob *prob, long loc) +double *gkyl_culinsolver_get_sol_ptr(struct gkyl_culinsolver_prob *prob, long loc) { - return prob->rhs_cu+loc; + return prob->rhs_cu + loc; } -double -gkyl_culinsolver_get_sol_ij(struct gkyl_culinsolver_prob *prob, long ielement, long jprob) +double gkyl_culinsolver_get_sol_ij(struct gkyl_culinsolver_prob *prob, long ielement, long jprob) { - return prob->rhs[jprob*prob->mrow+ielement]; + return prob->rhs[jprob * prob->mrow + ielement]; } -double -gkyl_culinsolver_get_sol_lin(struct gkyl_culinsolver_prob *prob, long loc) +double gkyl_culinsolver_get_sol_lin(struct gkyl_culinsolver_prob *prob, long loc) { return prob->rhs[loc]; } -void -gkyl_culinsolver_prob_release(struct gkyl_culinsolver_prob *prob) +void gkyl_culinsolver_prob_release(struct gkyl_culinsolver_prob *prob) { gkyl_cu_free(prob->rhs_cu); gkyl_cu_free(prob->csrcolindA_cu); diff --git a/core/zero/dg_array_mask.c b/core/zero/dg_array_mask.c index 673aeb3076..2ca9d124e6 100644 --- a/core/zero/dg_array_mask.c +++ b/core/zero/dg_array_mask.c @@ -9,9 +9,10 @@ #include // Apply less-than threshold mask over phase range -static void -apply_mask_less_than(struct gkyl_array *mask_arr, const struct gkyl_array *arr_in, - const struct gkyl_range *mask_rng, double threshold) +static void apply_mask_less_than( + struct gkyl_array *mask_arr, const struct gkyl_array *arr_in, const struct gkyl_range *mask_rng, + double threshold +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, mask_rng); @@ -27,9 +28,10 @@ apply_mask_less_than(struct gkyl_array *mask_arr, const struct gkyl_array *arr_i } // Apply greater-than threshold mask over phase range -static void -apply_mask_greater_than(struct gkyl_array *mask_arr, const struct gkyl_array *arr_in, - const struct gkyl_range *mask_rng, double threshold) +static void apply_mask_greater_than( + struct gkyl_array *mask_arr, const struct gkyl_array *arr_in, const struct gkyl_range *mask_rng, + double threshold +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, mask_rng); @@ -45,10 +47,10 @@ apply_mask_greater_than(struct gkyl_array *mask_arr, const struct gkyl_array *ar } // Find max value in velocity space for a given configuration space cell -static double -find_local_max_in_vel_space(const struct gkyl_array *arr_in, - const struct gkyl_range *conf_rng, const struct gkyl_range *vel_rng, - const struct gkyl_range *mask_rng, const int *conf_idx) +static double find_local_max_in_vel_space( + const struct gkyl_array *arr_in, const struct gkyl_range *conf_rng, + const struct gkyl_range *vel_rng, const struct gkyl_range *mask_rng, const int *conf_idx +) { double local_max = -DBL_MAX; @@ -77,10 +79,11 @@ find_local_max_in_vel_space(const struct gkyl_array *arr_in, } // Apply spatial fractional mask (less-than) for a given configuration space cell -static void -apply_conf_mask_less_than(struct gkyl_array *mask_arr, const struct gkyl_array *arr_in, - const struct gkyl_range *conf_rng, const struct gkyl_range *vel_rng, - const struct gkyl_range *mask_rng, const int *conf_idx, double threshold) +static void apply_conf_mask_less_than( + struct gkyl_array *mask_arr, const struct gkyl_array *arr_in, const struct gkyl_range *conf_rng, + const struct gkyl_range *vel_rng, const struct gkyl_range *mask_rng, const int *conf_idx, + double threshold +) { struct gkyl_range_iter iter_vel; gkyl_range_iter_init(&iter_vel, vel_rng); @@ -104,10 +107,11 @@ apply_conf_mask_less_than(struct gkyl_array *mask_arr, const struct gkyl_array * } // Apply spatial fractional mask (greater-than) for a given configuration space cell -static void -apply_conf_mask_greater_than(struct gkyl_array *mask_arr, const struct gkyl_array *arr_in, - const struct gkyl_range *conf_rng, const struct gkyl_range *vel_rng, - const struct gkyl_range *mask_rng, const int *conf_idx, double threshold) +static void apply_conf_mask_greater_than( + struct gkyl_array *mask_arr, const struct gkyl_array *arr_in, const struct gkyl_range *conf_rng, + const struct gkyl_range *vel_rng, const struct gkyl_range *mask_rng, const int *conf_idx, + double threshold +) { struct gkyl_range_iter iter_vel; gkyl_range_iter_init(&iter_vel, vel_rng); @@ -130,20 +134,16 @@ apply_conf_mask_greater_than(struct gkyl_array *mask_arr, const struct gkyl_arra } } -static void -advance_threshold_none(struct gkyl_dg_array_mask *mask, const double global_max) +static void advance_threshold_none(struct gkyl_dg_array_mask *mask, const double global_max) { } -static void -advance_threshold_frac(struct gkyl_dg_array_mask *mask, const double global_max) +static void advance_threshold_frac(struct gkyl_dg_array_mask *mask, const double global_max) { mask->threshold = mask->frac_threshold * global_max; } -void -gkyl_dg_array_mask_advance_threshold(struct gkyl_dg_array_mask *mask, - const double global_max) +void gkyl_dg_array_mask_advance_threshold(struct gkyl_dg_array_mask *mask, const double global_max) { #ifdef GKYL_HAVE_CUDA if (mask->use_gpu) { @@ -154,19 +154,16 @@ gkyl_dg_array_mask_advance_threshold(struct gkyl_dg_array_mask *mask, mask->advance_threshold_func(mask, global_max); } -static void -advance_none(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in) +static void advance_none(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in) { } -static void -advance_less_than(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in) +static void advance_less_than(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in) { apply_mask_less_than(mask->mask_arr, arr_in, mask->mask_rng, mask->threshold); } -static void -advance_greater_than(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in) +static void advance_greater_than(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in) { apply_mask_greater_than(mask->mask_arr, arr_in, mask->mask_rng, mask->threshold); } @@ -178,11 +175,14 @@ advance_less_than_frac_conf(struct gkyl_dg_array_mask *mask, const struct gkyl_a gkyl_range_iter_init(&iter_conf, mask->conf_rng); while (gkyl_range_iter_next(&iter_conf)) { - double local_max = find_local_max_in_vel_space(arr_in, - mask->conf_rng, mask->vel_rng, mask->mask_rng, iter_conf.idx); + double local_max = find_local_max_in_vel_space( + arr_in, mask->conf_rng, mask->vel_rng, mask->mask_rng, iter_conf.idx + ); double frac_threshold = mask->threshold * local_max; - apply_conf_mask_less_than(mask->mask_arr, arr_in, - mask->conf_rng, mask->vel_rng, mask->mask_rng, iter_conf.idx, frac_threshold); + apply_conf_mask_less_than( + mask->mask_arr, arr_in, mask->conf_rng, mask->vel_rng, mask->mask_rng, iter_conf.idx, + frac_threshold + ); } } @@ -193,11 +193,14 @@ advance_greater_than_frac_conf(struct gkyl_dg_array_mask *mask, const struct gky gkyl_range_iter_init(&iter_conf, mask->conf_rng); while (gkyl_range_iter_next(&iter_conf)) { - double local_max = find_local_max_in_vel_space(arr_in, - mask->conf_rng, mask->vel_rng, mask->mask_rng, iter_conf.idx); + double local_max = find_local_max_in_vel_space( + arr_in, mask->conf_rng, mask->vel_rng, mask->mask_rng, iter_conf.idx + ); double frac_threshold = mask->threshold * local_max; - apply_conf_mask_greater_than(mask->mask_arr, arr_in, - mask->conf_rng, mask->vel_rng, mask->mask_rng, iter_conf.idx, frac_threshold); + apply_conf_mask_greater_than( + mask->mask_arr, arr_in, mask->conf_rng, mask->vel_rng, mask->mask_rng, iter_conf.idx, + frac_threshold + ); } } @@ -212,8 +215,7 @@ scale_by_cell_active(struct gkyl_dg_array_mask *mask, const struct gkyl_array *a gkyl_array_scale_by_cell(mask->mask_arr, arr_to_multiply); } -void -gkyl_dg_array_mask_free(const struct gkyl_ref_count *ref) +void gkyl_dg_array_mask_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_array_mask *mask = container_of(ref, struct gkyl_dg_array_mask, ref_count); @@ -232,8 +234,7 @@ gkyl_dg_array_mask_free(const struct gkyl_ref_count *ref) gkyl_free(mask); } -struct gkyl_dg_array_mask* -gkyl_dg_array_mask_new(struct gkyl_dg_array_mask_inp mask_inp) +struct gkyl_dg_array_mask *gkyl_dg_array_mask_new(struct gkyl_dg_array_mask_inp mask_inp) { struct gkyl_dg_array_mask *mask = gkyl_malloc(sizeof(*mask)); @@ -263,36 +264,37 @@ gkyl_dg_array_mask_new(struct gkyl_dg_array_mask_inp mask_inp) // Set function pointers based on mask type (evaluated once here, not in advance) switch (mask->type) { - case GKYL_DG_ARRAY_MASK_NONE: - break; - case GKYL_DG_ARRAY_MASK_C0_LESS: - mask->advance_func = advance_less_than; - break; - case GKYL_DG_ARRAY_MASK_C0_GREATER: - mask->advance_func = advance_greater_than; - break; - case GKYL_DG_ARRAY_MASK_C0_LESS_FRAC: - mask->advance_func = advance_less_than; - mask->advance_threshold_func = advance_threshold_frac; - break; - case GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC: - mask->advance_func = advance_greater_than; - mask->advance_threshold_func = advance_threshold_frac; - break; - case GKYL_DG_ARRAY_MASK_C0_LESS_FRAC_CONF: - mask->advance_func = advance_less_than_frac_conf; - break; - case GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF: - mask->advance_func = advance_greater_than_frac_conf; - break; - default: - break; + case GKYL_DG_ARRAY_MASK_NONE: + break; + case GKYL_DG_ARRAY_MASK_C0_LESS: + mask->advance_func = advance_less_than; + break; + case GKYL_DG_ARRAY_MASK_C0_GREATER: + mask->advance_func = advance_greater_than; + break; + case GKYL_DG_ARRAY_MASK_C0_LESS_FRAC: + mask->advance_func = advance_less_than; + mask->advance_threshold_func = advance_threshold_frac; + break; + case GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC: + mask->advance_func = advance_greater_than; + mask->advance_threshold_func = advance_threshold_frac; + break; + case GKYL_DG_ARRAY_MASK_C0_LESS_FRAC_CONF: + mask->advance_func = advance_less_than_frac_conf; + break; + case GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF: + mask->advance_func = advance_greater_than_frac_conf; + break; + default: + break; } - if (mask->type == GKYL_DG_ARRAY_MASK_NONE) + if (mask->type == GKYL_DG_ARRAY_MASK_NONE) { mask->eval_idx_func = eval_idx_ker_disabled; - else + } else { mask->eval_idx_func = eval_idx_ker_enabled; + } if (mask->type != GKYL_DG_ARRAY_MASK_NONE) { // Store all ranges from input as pointers. @@ -304,30 +306,29 @@ gkyl_dg_array_mask_new(struct gkyl_dg_array_mask_inp mask_inp) if (mask_inp.phase_rng != 0) { mask->mask_rng = mask_inp.phase_rng; mask->mask_rng_ext = mask_inp.phase_rng_ext; - } - else { + } else { mask->mask_rng = mask_inp.conf_rng; mask->mask_rng_ext = mask_inp.conf_rng_ext; } mask->mask_rng_ndim = mask->mask_rng->ndim; mask->scale_by_cell_func = scale_by_cell_active; - if (mask->type == GKYL_DG_ARRAY_MASK_C0_LESS || - mask->type == GKYL_DG_ARRAY_MASK_C0_GREATER) { + if (mask->type == GKYL_DG_ARRAY_MASK_C0_LESS || mask->type == GKYL_DG_ARRAY_MASK_C0_GREATER) { mask->threshold = mask_inp.threshold * pow(sqrt(2.0), mask->mask_rng->ndim); - } - else if (mask->type == GKYL_DG_ARRAY_MASK_C0_LESS_FRAC || - mask->type == GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC) { + } else if (mask->type == GKYL_DG_ARRAY_MASK_C0_LESS_FRAC || + mask->type == GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC) { mask->frac_threshold = mask_inp.threshold; - } - else if (mask->type == GKYL_DG_ARRAY_MASK_C0_LESS_FRAC_CONF || - mask->type == GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF) { + } else if (mask->type == GKYL_DG_ARRAY_MASK_C0_LESS_FRAC_CONF || + mask->type == GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF) { mask->threshold = mask_inp.threshold; } // Initialize the mask array on host. mask->mask_arr = gkyl_array_new(GKYL_DOUBLE, 1, mask->mask_rng_ext->volume); - gkyl_array_clear(mask->mask_arr, mask->default_value ? 1.0 : -1.0); // Initialize all cells to false for safety. + gkyl_array_clear( + mask->mask_arr, + mask->default_value ? 1.0 : -1.0 + ); // Initialize all cells to false for safety. } struct gkyl_dg_array_mask *mask_out = mask; @@ -341,8 +342,7 @@ gkyl_dg_array_mask_new(struct gkyl_dg_array_mask_inp mask_inp) return mask_out; } -void -gkyl_dg_array_mask_advance(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in) +void gkyl_dg_array_mask_advance(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in) { #ifdef GKYL_HAVE_CUDA if (mask->use_gpu) { @@ -353,22 +353,20 @@ gkyl_dg_array_mask_advance(struct gkyl_dg_array_mask *mask, const struct gkyl_ar mask->advance_func(mask, arr_in); } -void -gkyl_dg_array_mask_scale_by_cell(struct gkyl_dg_array_mask *mask, - const struct gkyl_array *arr_to_multiply) +void gkyl_dg_array_mask_scale_by_cell( + struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_to_multiply +) { mask->scale_by_cell_func(mask, arr_to_multiply); } -struct gkyl_dg_array_mask* -gkyl_dg_array_mask_acquire(struct gkyl_dg_array_mask *mask) +struct gkyl_dg_array_mask *gkyl_dg_array_mask_acquire(struct gkyl_dg_array_mask *mask) { gkyl_ref_count_inc(&mask->ref_count); return (struct gkyl_dg_array_mask *)mask; } -void -gkyl_dg_array_mask_eval_idx(struct gkyl_dg_array_mask *mask, const int *idx, bool *val) +void gkyl_dg_array_mask_eval_idx(struct gkyl_dg_array_mask *mask, const int *idx, bool *val) { #ifdef GKYL_HAVE_CUDA if (mask->use_gpu) { @@ -380,20 +378,17 @@ gkyl_dg_array_mask_eval_idx(struct gkyl_dg_array_mask *mask, const int *idx, boo val[0] = mask->eval_idx_func(mask, idx); } -struct gkyl_dg_array_mask* -gkyl_dg_array_mask_get_dev_ptr(struct gkyl_dg_array_mask *mask) +struct gkyl_dg_array_mask *gkyl_dg_array_mask_get_dev_ptr(struct gkyl_dg_array_mask *mask) { return mask->on_dev; } -const struct gkyl_array* -gkyl_dg_array_mask_get_mask(const struct gkyl_dg_array_mask *mask) +const struct gkyl_array *gkyl_dg_array_mask_get_mask(const struct gkyl_dg_array_mask *mask) { return mask->mask_arr; } -void -gkyl_dg_array_mask_release(struct gkyl_dg_array_mask *mask) +void gkyl_dg_array_mask_release(struct gkyl_dg_array_mask *mask) { if (mask) { gkyl_ref_count_dec(&mask->ref_count); diff --git a/core/zero/dg_array_mask_cu.cu b/core/zero/dg_array_mask_cu.cu index d791de71bc..4aa297a9fc 100644 --- a/core/zero/dg_array_mask_cu.cu +++ b/core/zero/dg_array_mask_cu.cu @@ -11,15 +11,15 @@ extern "C" { } // CUDA kernel for LESS_THAN_THRESHOLD masks -__global__ void -gkyl_dg_array_mask_less_than_kernel(struct gkyl_range mask_rng, - const struct gkyl_array *arr_to_mask, struct gkyl_array *mask, double f_threshold) +__global__ void gkyl_dg_array_mask_less_than_kernel( + struct gkyl_range mask_rng, const struct gkyl_array *arr_to_mask, struct gkyl_array *mask, + double f_threshold +) { int idx[GKYL_MAX_DIM]; - for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; - tid < mask_rng.volume; tid += blockDim.x * gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < mask_rng.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&mask_rng, tid, idx); if (gkyl_range_contains_idx(&mask_rng, idx)) { @@ -34,15 +34,15 @@ gkyl_dg_array_mask_less_than_kernel(struct gkyl_range mask_rng, } // CUDA kernel for GREATER_THAN_THRESHOLD masks -__global__ void -gkyl_dg_array_mask_greater_than_kernel(struct gkyl_range mask_rng, - const struct gkyl_array *arr_to_mask, struct gkyl_array *mask, double f_threshold) +__global__ void gkyl_dg_array_mask_greater_than_kernel( + struct gkyl_range mask_rng, const struct gkyl_array *arr_to_mask, struct gkyl_array *mask, + double f_threshold +) { int idx[GKYL_MAX_DIM]; - for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; - tid < mask_rng.volume; tid += blockDim.x * gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < mask_rng.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&mask_rng, tid, idx); if (gkyl_range_contains_idx(&mask_rng, idx)) { @@ -57,16 +57,15 @@ gkyl_dg_array_mask_greater_than_kernel(struct gkyl_range mask_rng, } // CUDA kernel to find max value in velocity space for each configuration cell -__global__ void -gkyl_dg_array_mask_find_local_max_kernel(struct gkyl_range conf_rng, struct gkyl_range vel_rng, - struct gkyl_range mask_rng, const struct gkyl_array *arr_to_mask, - struct gkyl_array *local_max_arr) +__global__ void gkyl_dg_array_mask_find_local_max_kernel( + struct gkyl_range conf_rng, struct gkyl_range vel_rng, struct gkyl_range mask_rng, + const struct gkyl_array *arr_to_mask, struct gkyl_array *local_max_arr +) { int conf_idx[GKYL_MAX_DIM]; - for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; - tid < conf_rng.volume; tid += blockDim.x * gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_rng.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_rng, tid, conf_idx); if (gkyl_range_contains_idx(&conf_rng, conf_idx)) { @@ -103,16 +102,16 @@ gkyl_dg_array_mask_find_local_max_kernel(struct gkyl_range conf_rng, struct gkyl } // CUDA kernel to apply spatial fractional mask (LESS_THAN) -__global__ void -gkyl_dg_array_mask_spatial_frac_less_than_kernel(struct gkyl_range conf_rng, - struct gkyl_range vel_rng, struct gkyl_range mask_rng, const struct gkyl_array *arr_to_mask, - struct gkyl_array *mask, const struct gkyl_array *local_max_arr, double frac_threshold) +__global__ void gkyl_dg_array_mask_spatial_frac_less_than_kernel( + struct gkyl_range conf_rng, struct gkyl_range vel_rng, struct gkyl_range mask_rng, + const struct gkyl_array *arr_to_mask, struct gkyl_array *mask, + const struct gkyl_array *local_max_arr, double frac_threshold +) { int conf_idx[GKYL_MAX_DIM]; - for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; - tid < conf_rng.volume; tid += blockDim.x * gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_rng.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_rng, tid, conf_idx); if (gkyl_range_contains_idx(&conf_rng, conf_idx)) { @@ -145,16 +144,16 @@ gkyl_dg_array_mask_spatial_frac_less_than_kernel(struct gkyl_range conf_rng, } // CUDA kernel to apply spatial fractional mask (GREATER_THAN) -__global__ void -gkyl_dg_array_mask_spatial_frac_greater_than_kernel(struct gkyl_range conf_rng, - struct gkyl_range vel_rng, struct gkyl_range mask_rng, const struct gkyl_array *arr_to_mask, - struct gkyl_array *mask, const struct gkyl_array *local_max_arr, double frac_threshold) +__global__ void gkyl_dg_array_mask_spatial_frac_greater_than_kernel( + struct gkyl_range conf_rng, struct gkyl_range vel_rng, struct gkyl_range mask_rng, + const struct gkyl_array *arr_to_mask, struct gkyl_array *mask, + const struct gkyl_array *local_max_arr, double frac_threshold +) { int conf_idx[GKYL_MAX_DIM]; - for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; - tid < conf_rng.volume; tid += blockDim.x * gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_rng.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_rng, tid, conf_idx); if (gkyl_range_contains_idx(&conf_rng, conf_idx)) { @@ -189,8 +188,7 @@ gkyl_dg_array_mask_spatial_frac_greater_than_kernel(struct gkyl_range conf_rng, // Static host functions that launch the appropriate CUDA kernels. // These are assigned to the advance_func_cu function pointer at init time. -static void -advance_cu_none(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_to_mask) +static void advance_cu_none(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_to_mask) { // Do nothing for NONE type } @@ -200,8 +198,9 @@ advance_cu_less_than(struct gkyl_dg_array_mask *mask, const struct gkyl_array *a { int nblocks = arr_to_mask->nblocks; int nthreads = arr_to_mask->nthreads; - gkyl_dg_array_mask_less_than_kernel<<>>( - *mask->mask_rng, arr_to_mask->on_dev, mask->mask_arr->on_dev, mask->threshold); + gkyl_dg_array_mask_less_than_kernel<< > >( + *mask->mask_rng, arr_to_mask->on_dev, mask->mask_arr->on_dev, mask->threshold + ); } static void @@ -209,55 +208,59 @@ advance_cu_greater_than(struct gkyl_dg_array_mask *mask, const struct gkyl_array { int nblocks = arr_to_mask->nblocks; int nthreads = arr_to_mask->nthreads; - gkyl_dg_array_mask_greater_than_kernel<<>>( - *mask->mask_rng, arr_to_mask->on_dev, mask->mask_arr->on_dev, mask->threshold); + gkyl_dg_array_mask_greater_than_kernel<< > >( + *mask->mask_rng, arr_to_mask->on_dev, mask->mask_arr->on_dev, mask->threshold + ); } static void -advance_cu_less_than_frac_conf(struct gkyl_dg_array_mask *mask, - const struct gkyl_array *arr_to_mask) +advance_cu_less_than_frac_conf(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_to_mask) { int nthreads = mask->mask_arr->nthreads; int conf_nblocks = mask->conf_rng->nblocks; // Phase 1: Find max in velocity space for each configuration cell - gkyl_dg_array_mask_find_local_max_kernel<<>>( + gkyl_dg_array_mask_find_local_max_kernel<< > >( *mask->conf_rng, *mask->vel_rng, *mask->mask_rng, arr_to_mask->on_dev, - mask->local_max_arr->on_dev); + mask->local_max_arr->on_dev + ); // Phase 2: Apply mask based on local thresholds - gkyl_dg_array_mask_spatial_frac_less_than_kernel<<>>( - *mask->conf_rng, *mask->vel_rng, *mask->mask_rng, arr_to_mask->on_dev, - mask->mask_arr->on_dev, mask->local_max_arr->on_dev, mask->threshold); + gkyl_dg_array_mask_spatial_frac_less_than_kernel<< > >( + *mask->conf_rng, *mask->vel_rng, *mask->mask_rng, arr_to_mask->on_dev, mask->mask_arr->on_dev, + mask->local_max_arr->on_dev, mask->threshold + ); } -static void -advance_cu_greater_than_frac_conf(struct gkyl_dg_array_mask *mask, - const struct gkyl_array *arr_to_mask) +static void advance_cu_greater_than_frac_conf( + struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_to_mask +) { int nthreads = mask->mask_arr->nthreads; int conf_nblocks = mask->conf_rng->nblocks; // Phase 1: Find max in velocity space for each configuration cell - gkyl_dg_array_mask_find_local_max_kernel<<>>( + gkyl_dg_array_mask_find_local_max_kernel<< > >( *mask->conf_rng, *mask->vel_rng, *mask->mask_rng, arr_to_mask->on_dev, - mask->local_max_arr->on_dev); + mask->local_max_arr->on_dev + ); // Phase 2: Apply mask based on local thresholds - gkyl_dg_array_mask_spatial_frac_greater_than_kernel<<>>( - *mask->conf_rng, *mask->vel_rng, *mask->mask_rng, arr_to_mask->on_dev, - mask->mask_arr->on_dev, mask->local_max_arr->on_dev, mask->threshold); + gkyl_dg_array_mask_spatial_frac_greater_than_kernel<< > >( + *mask->conf_rng, *mask->vel_rng, *mask->mask_rng, arr_to_mask->on_dev, mask->mask_arr->on_dev, + mask->local_max_arr->on_dev, mask->threshold + ); } // Host function to launch CUDA kernel. -void -gkyl_dg_array_mask_advance_cu(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_to_mask) +void gkyl_dg_array_mask_advance_cu( + struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_to_mask +) { mask->advance_func_cu(mask, arr_to_mask); } -__global__ void -advance_threshold_none(struct gkyl_dg_array_mask *mask, const double global_max) +__global__ void advance_threshold_none(struct gkyl_dg_array_mask *mask, const double global_max) { } @@ -267,14 +270,14 @@ advance_threshold_frac_kernel(struct gkyl_dg_array_mask *mask, const double glob mask->threshold = mask->frac_threshold * global_max; } -static void -advance_threshold_frac(struct gkyl_dg_array_mask *mask, const double global_max) +static void advance_threshold_frac(struct gkyl_dg_array_mask *mask, const double global_max) { - advance_threshold_frac_kernel<<<1, 1>>>(mask->on_dev, global_max); + advance_threshold_frac_kernel<<<1, 1> > >(mask->on_dev, global_max); } -void -gkyl_dg_array_mask_advance_threshold_cu(struct gkyl_dg_array_mask *mask, const double global_max) +void gkyl_dg_array_mask_advance_threshold_cu( + struct gkyl_dg_array_mask *mask, const double global_max +) { mask->advance_threshold_func(mask, global_max); } @@ -283,35 +286,34 @@ struct dg_array_mask_idx { int idx[GKYL_MAX_DIM]; // Index. }; -__global__ static void -gkyl_dg_array_mask_eval_idx_kernel(struct gkyl_dg_array_mask *mask, - struct dg_array_mask_idx idx_struct, bool *val) +__global__ static void gkyl_dg_array_mask_eval_idx_kernel( + struct gkyl_dg_array_mask *mask, struct dg_array_mask_idx idx_struct, bool *val +) { val[0] = mask->eval_idx_func(mask, idx_struct.idx); } -void -gkyl_dg_array_mask_eval_idx_cu(struct gkyl_dg_array_mask *mask, const int *idx, bool *val) +void gkyl_dg_array_mask_eval_idx_cu(struct gkyl_dg_array_mask *mask, const int *idx, bool *val) { struct dg_array_mask_idx idx_struct = {}; for (int d = 0; d < mask->mask_rng_ndim; d++) { idx_struct.idx[d] = idx[d]; } - gkyl_dg_array_mask_eval_idx_kernel<<<1, 1>>>(mask->on_dev, idx_struct, val); + gkyl_dg_array_mask_eval_idx_kernel<<<1, 1> > >(mask->on_dev, idx_struct, val); } __global__ static void gkyl_dg_array_mask_set_dev_func_ptr(struct gkyl_dg_array_mask *mask, enum gkyl_dg_array_mask_types) { - if (mask->type == GKYL_DG_ARRAY_MASK_NONE) + if (mask->type == GKYL_DG_ARRAY_MASK_NONE) { mask->eval_idx_func = eval_idx_ker_disabled; - else + } else { mask->eval_idx_func = eval_idx_ker_enabled; + } } -struct gkyl_dg_array_mask* -gkyl_dg_array_mask_cu_dev_new(struct gkyl_dg_array_mask *mask_ho) +struct gkyl_dg_array_mask *gkyl_dg_array_mask_cu_dev_new(struct gkyl_dg_array_mask *mask_ho) { struct gkyl_dg_array_mask *mask = (struct gkyl_dg_array_mask *)gkyl_malloc(sizeof(*mask)); @@ -341,35 +343,36 @@ gkyl_dg_array_mask_cu_dev_new(struct gkyl_dg_array_mask *mask_ho) // Set GPU advance function pointer based on mask type switch (mask->type) { - case GKYL_DG_ARRAY_MASK_NONE: - mask->advance_func_cu = advance_cu_none; - break; - case GKYL_DG_ARRAY_MASK_C0_LESS: - mask->advance_func_cu = advance_cu_less_than; - break; - case GKYL_DG_ARRAY_MASK_C0_GREATER: - mask->advance_func_cu = advance_cu_greater_than; - break; - case GKYL_DG_ARRAY_MASK_C0_LESS_FRAC: - mask->advance_func_cu = advance_cu_less_than; - break; - case GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC: - mask->advance_func_cu = advance_cu_greater_than; - break; - case GKYL_DG_ARRAY_MASK_C0_LESS_FRAC_CONF: - mask->advance_func_cu = advance_cu_less_than_frac_conf; - break; - case GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF: - mask->advance_func_cu = advance_cu_greater_than_frac_conf; - break; - default: - break; + case GKYL_DG_ARRAY_MASK_NONE: + mask->advance_func_cu = advance_cu_none; + break; + case GKYL_DG_ARRAY_MASK_C0_LESS: + mask->advance_func_cu = advance_cu_less_than; + break; + case GKYL_DG_ARRAY_MASK_C0_GREATER: + mask->advance_func_cu = advance_cu_greater_than; + break; + case GKYL_DG_ARRAY_MASK_C0_LESS_FRAC: + mask->advance_func_cu = advance_cu_less_than; + break; + case GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC: + mask->advance_func_cu = advance_cu_greater_than; + break; + case GKYL_DG_ARRAY_MASK_C0_LESS_FRAC_CONF: + mask->advance_func_cu = advance_cu_less_than_frac_conf; + break; + case GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF: + mask->advance_func_cu = advance_cu_greater_than_frac_conf; + break; + default: + break; } - if (mask->type == GKYL_DG_ARRAY_MASK_NONE) + if (mask->type == GKYL_DG_ARRAY_MASK_NONE) { mask->eval_idx_func = eval_idx_ker_disabled; - else + } else { mask->eval_idx_func = eval_idx_ker_enabled; + } if (mask->type == GKYL_DG_ARRAY_MASK_NONE) { // Initialize the device object. @@ -377,18 +380,18 @@ gkyl_dg_array_mask_cu_dev_new(struct gkyl_dg_array_mask *mask_ho) (struct gkyl_dg_array_mask *)gkyl_cu_malloc(sizeof(*mask_cu)); gkyl_cu_memcpy(mask_cu, mask, sizeof(struct gkyl_dg_array_mask), GKYL_CU_MEMCPY_H2D); mask->on_dev = mask_cu; - } - else { - struct gkyl_array *mask_array = gkyl_array_cu_dev_new(GKYL_DOUBLE, mask_ho->mask_arr->ncomp, - mask_ho->mask_arr->size); + } else { + struct gkyl_array *mask_array = + gkyl_array_cu_dev_new(GKYL_DOUBLE, mask_ho->mask_arr->ncomp, mask_ho->mask_arr->size); gkyl_array_copy(mask_array, mask_ho->mask_arr); mask->mask_arr = mask_array->on_dev; if (mask->type == GKYL_DG_ARRAY_MASK_C0_LESS_FRAC_CONF || - mask->type == GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF) { + mask->type == GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF) { mask->local_max_arr = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, mask->conf_rng_ext->volume); } if (mask->type == GKYL_DG_ARRAY_MASK_C0_LESS_FRAC || - mask->type == GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC) {} + mask->type == GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC) { + } // Initialize the device object. struct gkyl_dg_array_mask *mask_cu = @@ -400,7 +403,7 @@ gkyl_dg_array_mask_cu_dev_new(struct gkyl_dg_array_mask *mask_ho) mask->mask_arr = mask_array; } - gkyl_dg_array_mask_set_dev_func_ptr<<<1, 1>>>(mask->on_dev, mask->type); + gkyl_dg_array_mask_set_dev_func_ptr<<<1, 1> > >(mask->on_dev, mask->type); // For NONE type, don't allocate mask array return mask; diff --git a/core/zero/dg_basis_ops.c b/core/zero/dg_basis_ops.c index 9d8630ce05..a1f7240272 100644 --- a/core/zero/dg_basis_ops.c +++ b/core/zero/dg_basis_ops.c @@ -8,10 +8,10 @@ #include #include -void -gkyl_dg_basis_ops_eval_array_at_coord_comp(const struct gkyl_array *arr, const double *coord, - const struct gkyl_basis *basis, const struct gkyl_rect_grid *grid, const struct gkyl_range *rng, - double *out) +void gkyl_dg_basis_ops_eval_array_at_coord_comp( + const struct gkyl_array *arr, const double *coord, const struct gkyl_basis *basis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *rng, double *out +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(arr)) { @@ -28,21 +28,19 @@ gkyl_dg_basis_ops_eval_array_at_coord_comp(const struct gkyl_array *arr, const d // Logical coordinate. double xc[grid->ndim], coord_log[grid->ndim]; gkyl_rect_grid_cell_center(grid, coord_idx, xc); - for (int d=0; dndim; d++) - coord_log[d] = (2.0/grid->dx[d])*(coord[d]-xc[d]); + for (int d = 0; d < grid->ndim; d++) { + coord_log[d] = (2.0 / grid->dx[d]) * (coord[d] - xc[d]); + } long linidx = gkyl_range_idx(rng, coord_idx); const double *arr_c = gkyl_array_cfetch(arr, linidx); out[0] = basis->eval_expand(coord_log, arr_c); - } - else + } else { out[0] = -DBL_MAX; + } } -enum dg_basis_op_code { - GKYL_DG_BASIS_OP_CUBIC_1D, - GKYL_DG_BASIS_OP_CUBIC_2D -}; +enum dg_basis_op_code { GKYL_DG_BASIS_OP_CUBIC_1D, GKYL_DG_BASIS_OP_CUBIC_2D }; struct gkyl_dg_basis_op_mem { enum dg_basis_op_code opcode; @@ -65,73 +63,137 @@ struct dg_basis_ops_evalf_ctx { struct gkyl_rect_grid grid; // grid on which cubic is define struct gkyl_range local, local_ext; // ranges for cubic struct gkyl_basis basis; // p=3 basis functions - + struct gkyl_array *cubic; // cubic DG representation }; -void -gkyl_dg_calc_cubic_1d(const double val[2], const double grad[2], double *coeff) +void gkyl_dg_calc_cubic_1d(const double val[2], const double grad[2], double *coeff) { - coeff[0] = 0.7071067811865475*val[1]-0.2357022603955158*grad[1]+0.7071067811865475*val[0]+0.2357022603955158*grad[0]; - coeff[1] = 0.4898979485566357*val[1]-0.08164965809277261*grad[1]-0.4898979485566357*val[0]-0.08164965809277261*grad[0]; - coeff[2] = 0.105409255338946*grad[1]-0.105409255338946*grad[0]; - coeff[3] = (-0.05345224838248487*val[1])+0.05345224838248487*grad[1]+0.05345224838248487*val[0]+0.05345224838248487*grad[0]; + coeff[0] = 0.7071067811865475 * val[1] - 0.2357022603955158 * grad[1] + + 0.7071067811865475 * val[0] + 0.2357022603955158 * grad[0]; + coeff[1] = 0.4898979485566357 * val[1] - 0.08164965809277261 * grad[1] - + 0.4898979485566357 * val[0] - 0.08164965809277261 * grad[0]; + coeff[2] = 0.105409255338946 * grad[1] - 0.105409255338946 * grad[0]; + coeff[3] = (-0.05345224838248487 * val[1]) + 0.05345224838248487 * grad[1] + + 0.05345224838248487 * val[0] + 0.05345224838248487 * grad[0]; } -void -gkyl_dg_calc_cubic_2d(const double f[4], - const double fx[4], const double fy[4], const double fxy[4], - double *coeff) +void gkyl_dg_calc_cubic_2d( + const double f[4], const double fx[4], const double fy[4], const double fxy[4], double *coeff +) { - coeff[0] = (-0.1666666666666667*fy[3])+0.05555555555555555*fxy[3]-0.1666666666666667*fx[3]+0.5*f[3]+0.1666666666666667*fy[2]-0.05555555555555555*fxy[2]-0.1666666666666667*fx[2]+0.5*f[2]-0.1666666666666667*fy[1]-0.05555555555555555*fxy[1]+0.1666666666666667*fx[1]+0.5*f[1]+0.1666666666666667*fy[0]+0.05555555555555555*fxy[0]+0.1666666666666667*fx[0]+0.5*f[0]; - coeff[1] = (-0.1154700538379252*fy[3])+0.01924500897298753*fxy[3]-0.05773502691896259*fx[3]+0.3464101615137755*f[3]+0.1154700538379252*fy[2]-0.01924500897298753*fxy[2]-0.05773502691896259*fx[2]+0.3464101615137755*f[2]+0.1154700538379252*fy[1]+0.01924500897298753*fxy[1]-0.05773502691896259*fx[1]-0.3464101615137755*f[1]-0.1154700538379252*fy[0]-0.01924500897298753*fxy[0]-0.05773502691896259*fx[0]-0.3464101615137755*f[0]; - coeff[2] = (-0.05773502691896259*fy[3])+0.01924500897298753*fxy[3]-0.1154700538379252*fx[3]+0.3464101615137755*f[3]-0.05773502691896259*fy[2]+0.01924500897298753*fxy[2]+0.1154700538379252*fx[2]-0.3464101615137755*f[2]-0.05773502691896259*fy[1]-0.01924500897298753*fxy[1]+0.1154700538379252*fx[1]+0.3464101615137755*f[1]-0.05773502691896259*fy[0]-0.01924500897298753*fxy[0]-0.1154700538379252*fx[0]-0.3464101615137755*f[0]; - coeff[3] = (-0.04*fy[3])+0.006666666666666667*fxy[3]-0.04*fx[3]+0.24*f[3]-0.04*fy[2]+0.006666666666666667*fxy[2]+0.04*fx[2]-0.24*f[2]+0.04*fy[1]+0.006666666666666667*fxy[1]-0.04*fx[1]-0.24*f[1]+0.04*fy[0]+0.006666666666666667*fxy[0]+0.04*fx[0]+0.24*f[0]; - coeff[4] = (-0.02484519974999766*fxy[3])+0.07453559924999298*fx[3]+0.02484519974999766*fxy[2]+0.07453559924999298*fx[2]+0.02484519974999766*fxy[1]-0.07453559924999298*fx[1]-0.02484519974999766*fxy[0]-0.07453559924999298*fx[0]; - coeff[5] = 0.07453559924999298*fy[3]-0.02484519974999766*fxy[3]-0.07453559924999298*fy[2]+0.02484519974999766*fxy[2]+0.07453559924999298*fy[1]+0.02484519974999766*fxy[1]-0.07453559924999298*fy[0]-0.02484519974999766*fxy[0]; - coeff[6] = (-0.008606629658238702*fxy[3])+0.05163977794943223*fx[3]-0.008606629658238702*fxy[2]-0.05163977794943223*fx[2]+0.008606629658238702*fxy[1]-0.05163977794943223*fx[1]+0.008606629658238702*fxy[0]+0.05163977794943223*fx[0]; - coeff[7] = 0.05163977794943223*fy[3]-0.008606629658238702*fxy[3]-0.05163977794943223*fy[2]+0.008606629658238702*fxy[2]-0.05163977794943223*fy[1]-0.008606629658238702*fxy[1]+0.05163977794943223*fy[0]+0.008606629658238702*fxy[0]; - coeff[8] = 0.01259881576697424*fy[3]-0.01259881576697424*fxy[3]+0.03779644730092272*fx[3]-0.03779644730092272*f[3]-0.01259881576697424*fy[2]+0.01259881576697424*fxy[2]+0.03779644730092272*fx[2]-0.03779644730092272*f[2]-0.01259881576697424*fy[1]-0.01259881576697424*fxy[1]+0.03779644730092272*fx[1]+0.03779644730092272*f[1]+0.01259881576697424*fy[0]+0.01259881576697424*fxy[0]+0.03779644730092272*fx[0]+0.03779644730092272*f[0]; - coeff[9] = 0.03779644730092272*fy[3]-0.01259881576697424*fxy[3]+0.01259881576697424*fx[3]-0.03779644730092272*f[3]+0.03779644730092272*fy[2]-0.01259881576697424*fxy[2]-0.01259881576697424*fx[2]+0.03779644730092272*f[2]+0.03779644730092272*fy[1]+0.01259881576697424*fxy[1]-0.01259881576697424*fx[1]-0.03779644730092272*f[1]+0.03779644730092272*fy[0]+0.01259881576697424*fxy[0]+0.01259881576697424*fx[0]+0.03779644730092272*f[0]; - coeff[10] = 0.01111111111111111*fxy[3]-0.01111111111111111*fxy[2]-0.01111111111111111*fxy[1]+0.01111111111111111*fxy[0]; - coeff[11] = 0.004364357804719848*fy[3]-0.004364357804719848*fxy[3]+0.02618614682831908*fx[3]-0.02618614682831908*f[3]+0.004364357804719848*fy[2]-0.004364357804719848*fxy[2]-0.02618614682831908*fx[2]+0.02618614682831908*f[2]-0.004364357804719848*fy[1]-0.004364357804719848*fxy[1]+0.02618614682831908*fx[1]+0.02618614682831908*f[1]-0.004364357804719848*fy[0]-0.004364357804719848*fxy[0]-0.02618614682831908*fx[0]-0.02618614682831908*f[0]; - coeff[12] = 0.02618614682831908*fy[3]-0.004364357804719848*fxy[3]+0.004364357804719848*fx[3]-0.02618614682831908*f[3]+0.02618614682831908*fy[2]-0.004364357804719848*fxy[2]-0.004364357804719848*fx[2]+0.02618614682831908*f[2]-0.02618614682831908*fy[1]-0.004364357804719848*fxy[1]+0.004364357804719848*fx[1]+0.02618614682831908*f[1]-0.02618614682831908*fy[0]-0.004364357804719848*fxy[0]-0.004364357804719848*fx[0]-0.02618614682831908*f[0]; - coeff[13] = (-0.00563436169819011*fy[3])+0.00563436169819011*fxy[3]+0.00563436169819011*fy[2]-0.00563436169819011*fxy[2]+0.00563436169819011*fy[1]+0.00563436169819011*fxy[1]-0.00563436169819011*fy[0]-0.00563436169819011*fxy[0]; - coeff[14] = 0.00563436169819011*fxy[3]-0.00563436169819011*fx[3]+0.00563436169819011*fxy[2]+0.00563436169819011*fx[2]-0.00563436169819011*fxy[1]+0.00563436169819011*fx[1]-0.00563436169819011*fxy[0]-0.00563436169819011*fx[0]; - coeff[15] = (-0.002857142857142857*fy[3])+0.002857142857142857*fxy[3]-0.002857142857142857*fx[3]+0.002857142857142857*f[3]-0.002857142857142857*fy[2]+0.002857142857142857*fxy[2]+0.002857142857142857*fx[2]-0.002857142857142857*f[2]+0.002857142857142857*fy[1]+0.002857142857142857*fxy[1]-0.002857142857142857*fx[1]-0.002857142857142857*f[1]+0.002857142857142857*fy[0]+0.002857142857142857*fxy[0]+0.002857142857142857*fx[0]+0.002857142857142857*f[0]; + coeff[0] = (-0.1666666666666667 * fy[3]) + 0.05555555555555555 * fxy[3] - + 0.1666666666666667 * fx[3] + 0.5 * f[3] + 0.1666666666666667 * fy[2] - + 0.05555555555555555 * fxy[2] - 0.1666666666666667 * fx[2] + 0.5 * f[2] - + 0.1666666666666667 * fy[1] - 0.05555555555555555 * fxy[1] + + 0.1666666666666667 * fx[1] + 0.5 * f[1] + 0.1666666666666667 * fy[0] + + 0.05555555555555555 * fxy[0] + 0.1666666666666667 * fx[0] + 0.5 * f[0]; + coeff[1] = (-0.1154700538379252 * fy[3]) + 0.01924500897298753 * fxy[3] - + 0.05773502691896259 * fx[3] + 0.3464101615137755 * f[3] + 0.1154700538379252 * fy[2] - + 0.01924500897298753 * fxy[2] - 0.05773502691896259 * fx[2] + + 0.3464101615137755 * f[2] + 0.1154700538379252 * fy[1] + 0.01924500897298753 * fxy[1] - + 0.05773502691896259 * fx[1] - 0.3464101615137755 * f[1] - 0.1154700538379252 * fy[0] - + 0.01924500897298753 * fxy[0] - 0.05773502691896259 * fx[0] - 0.3464101615137755 * f[0]; + coeff[2] = (-0.05773502691896259 * fy[3]) + 0.01924500897298753 * fxy[3] - + 0.1154700538379252 * fx[3] + 0.3464101615137755 * f[3] - 0.05773502691896259 * fy[2] + + 0.01924500897298753 * fxy[2] + 0.1154700538379252 * fx[2] - 0.3464101615137755 * f[2] - + 0.05773502691896259 * fy[1] - 0.01924500897298753 * fxy[1] + + 0.1154700538379252 * fx[1] + 0.3464101615137755 * f[1] - 0.05773502691896259 * fy[0] - + 0.01924500897298753 * fxy[0] - 0.1154700538379252 * fx[0] - 0.3464101615137755 * f[0]; + coeff[3] = (-0.04 * fy[3]) + 0.006666666666666667 * fxy[3] - 0.04 * fx[3] + 0.24 * f[3] - + 0.04 * fy[2] + 0.006666666666666667 * fxy[2] + 0.04 * fx[2] - 0.24 * f[2] + + 0.04 * fy[1] + 0.006666666666666667 * fxy[1] - 0.04 * fx[1] - 0.24 * f[1] + + 0.04 * fy[0] + 0.006666666666666667 * fxy[0] + 0.04 * fx[0] + 0.24 * f[0]; + coeff[4] = (-0.02484519974999766 * fxy[3]) + 0.07453559924999298 * fx[3] + + 0.02484519974999766 * fxy[2] + 0.07453559924999298 * fx[2] + + 0.02484519974999766 * fxy[1] - 0.07453559924999298 * fx[1] - + 0.02484519974999766 * fxy[0] - 0.07453559924999298 * fx[0]; + coeff[5] = 0.07453559924999298 * fy[3] - 0.02484519974999766 * fxy[3] - + 0.07453559924999298 * fy[2] + 0.02484519974999766 * fxy[2] + + 0.07453559924999298 * fy[1] + 0.02484519974999766 * fxy[1] - + 0.07453559924999298 * fy[0] - 0.02484519974999766 * fxy[0]; + coeff[6] = (-0.008606629658238702 * fxy[3]) + 0.05163977794943223 * fx[3] - + 0.008606629658238702 * fxy[2] - 0.05163977794943223 * fx[2] + + 0.008606629658238702 * fxy[1] - 0.05163977794943223 * fx[1] + + 0.008606629658238702 * fxy[0] + 0.05163977794943223 * fx[0]; + coeff[7] = 0.05163977794943223 * fy[3] - 0.008606629658238702 * fxy[3] - + 0.05163977794943223 * fy[2] + 0.008606629658238702 * fxy[2] - + 0.05163977794943223 * fy[1] - 0.008606629658238702 * fxy[1] + + 0.05163977794943223 * fy[0] + 0.008606629658238702 * fxy[0]; + coeff[8] = + 0.01259881576697424 * fy[3] - 0.01259881576697424 * fxy[3] + 0.03779644730092272 * fx[3] - + 0.03779644730092272 * f[3] - 0.01259881576697424 * fy[2] + 0.01259881576697424 * fxy[2] + + 0.03779644730092272 * fx[2] - 0.03779644730092272 * f[2] - 0.01259881576697424 * fy[1] - + 0.01259881576697424 * fxy[1] + 0.03779644730092272 * fx[1] + 0.03779644730092272 * f[1] + + 0.01259881576697424 * fy[0] + 0.01259881576697424 * fxy[0] + 0.03779644730092272 * fx[0] + + 0.03779644730092272 * f[0]; + coeff[9] = + 0.03779644730092272 * fy[3] - 0.01259881576697424 * fxy[3] + 0.01259881576697424 * fx[3] - + 0.03779644730092272 * f[3] + 0.03779644730092272 * fy[2] - 0.01259881576697424 * fxy[2] - + 0.01259881576697424 * fx[2] + 0.03779644730092272 * f[2] + 0.03779644730092272 * fy[1] + + 0.01259881576697424 * fxy[1] - 0.01259881576697424 * fx[1] - 0.03779644730092272 * f[1] + + 0.03779644730092272 * fy[0] + 0.01259881576697424 * fxy[0] + 0.01259881576697424 * fx[0] + + 0.03779644730092272 * f[0]; + coeff[10] = 0.01111111111111111 * fxy[3] - 0.01111111111111111 * fxy[2] - + 0.01111111111111111 * fxy[1] + 0.01111111111111111 * fxy[0]; + coeff[11] = + 0.004364357804719848 * fy[3] - 0.004364357804719848 * fxy[3] + 0.02618614682831908 * fx[3] - + 0.02618614682831908 * f[3] + 0.004364357804719848 * fy[2] - 0.004364357804719848 * fxy[2] - + 0.02618614682831908 * fx[2] + 0.02618614682831908 * f[2] - 0.004364357804719848 * fy[1] - + 0.004364357804719848 * fxy[1] + 0.02618614682831908 * fx[1] + 0.02618614682831908 * f[1] - + 0.004364357804719848 * fy[0] - 0.004364357804719848 * fxy[0] - 0.02618614682831908 * fx[0] - + 0.02618614682831908 * f[0]; + coeff[12] = + 0.02618614682831908 * fy[3] - 0.004364357804719848 * fxy[3] + 0.004364357804719848 * fx[3] - + 0.02618614682831908 * f[3] + 0.02618614682831908 * fy[2] - 0.004364357804719848 * fxy[2] - + 0.004364357804719848 * fx[2] + 0.02618614682831908 * f[2] - 0.02618614682831908 * fy[1] - + 0.004364357804719848 * fxy[1] + 0.004364357804719848 * fx[1] + 0.02618614682831908 * f[1] - + 0.02618614682831908 * fy[0] - 0.004364357804719848 * fxy[0] - 0.004364357804719848 * fx[0] - + 0.02618614682831908 * f[0]; + coeff[13] = (-0.00563436169819011 * fy[3]) + 0.00563436169819011 * fxy[3] + + 0.00563436169819011 * fy[2] - 0.00563436169819011 * fxy[2] + + 0.00563436169819011 * fy[1] + 0.00563436169819011 * fxy[1] - + 0.00563436169819011 * fy[0] - 0.00563436169819011 * fxy[0]; + coeff[14] = 0.00563436169819011 * fxy[3] - 0.00563436169819011 * fx[3] + + 0.00563436169819011 * fxy[2] + 0.00563436169819011 * fx[2] - + 0.00563436169819011 * fxy[1] + 0.00563436169819011 * fx[1] - + 0.00563436169819011 * fxy[0] - 0.00563436169819011 * fx[0]; + coeff[15] = + (-0.002857142857142857 * fy[3]) + 0.002857142857142857 * fxy[3] - 0.002857142857142857 * fx[3] + + 0.002857142857142857 * f[3] - 0.002857142857142857 * fy[2] + 0.002857142857142857 * fxy[2] + + 0.002857142857142857 * fx[2] - 0.002857142857142857 * f[2] + 0.002857142857142857 * fy[1] + + 0.002857142857142857 * fxy[1] - 0.002857142857142857 * fx[1] - 0.002857142857142857 * f[1] + + 0.002857142857142857 * fy[0] + 0.002857142857142857 * fxy[0] + 0.002857142857142857 * fx[0] + + 0.002857142857142857 * f[0]; } -static inline double -calc_bilinear_grad_xy(double val[4], double dx[2]) +static inline double calc_bilinear_grad_xy(double val[4], double dx[2]) { - return ( (val[3]-val[2])/dx[1] - (val[1]-val[0])/dx[1])/dx[0]; + return ((val[3] - val[2]) / dx[1] - (val[1] - val[0]) / dx[1]) / dx[0]; } -gkyl_dg_basis_op_mem * -gkyl_dg_alloc_cubic_1d(int cells) +gkyl_dg_basis_op_mem *gkyl_dg_alloc_cubic_1d(int cells) { struct gkyl_dg_basis_op_mem *mem = gkyl_malloc(sizeof(*mem)); mem->opcode = GKYL_DG_BASIS_OP_CUBIC_1D; - mem->grad1dx = gkyl_array_new(GKYL_DOUBLE, 1, cells+1); + mem->grad1dx = gkyl_array_new(GKYL_DOUBLE, 1, cells + 1); return mem; } -gkyl_dg_basis_op_mem * -gkyl_dg_alloc_cubic_2d(int cells[2]) +gkyl_dg_basis_op_mem *gkyl_dg_alloc_cubic_2d(int cells[2]) { struct gkyl_dg_basis_op_mem *mem = gkyl_malloc(sizeof(*mem)); mem->opcode = GKYL_DG_BASIS_OP_CUBIC_2D; - size_t ncells = (cells[0]+1)*(cells[1]+1); + size_t ncells = (cells[0] + 1) * (cells[1] + 1); mem->grad2dx = gkyl_array_new(GKYL_DOUBLE, 1, ncells); mem->grad2dy = gkyl_array_new(GKYL_DOUBLE, 1, ncells); mem->grad2dxy = gkyl_array_new(GKYL_DOUBLE, 1, ncells); - + return mem; } -void -gkyl_dg_basis_op_mem_release(gkyl_dg_basis_op_mem *mem) +void gkyl_dg_basis_op_mem_release(gkyl_dg_basis_op_mem *mem) { if (mem->opcode == GKYL_DG_BASIS_OP_CUBIC_1D) { gkyl_array_release(mem->grad1dx); @@ -140,28 +202,29 @@ gkyl_dg_basis_op_mem_release(gkyl_dg_basis_op_mem *mem) gkyl_array_release(mem->grad2dx); gkyl_array_release(mem->grad2dy); gkyl_array_release(mem->grad2dxy); - } + } gkyl_free(mem); } -void -gkyl_dg_calc_cubic_1d_from_nodal_vals(gkyl_dg_basis_op_mem *mem, int cells, double dx, - const struct gkyl_array *nodal_vals, struct gkyl_array *cubic) +void gkyl_dg_calc_cubic_1d_from_nodal_vals( + gkyl_dg_basis_op_mem *mem, int cells, double dx, const struct gkyl_array *nodal_vals, + struct gkyl_array *cubic +) { enum { I, LL, L, R, RR, XE }; // i, i-2, i-1, i+1, i+2 nodes - + struct gkyl_range range; - gkyl_range_init_from_shape(&range, 1, (int[]) { cells }); + gkyl_range_init_from_shape(&range, 1, (int[]){cells}); struct gkyl_range nc_range; - gkyl_range_init_from_shape(&nc_range, 1, (int[]) { cells+1 }); + gkyl_range_init_from_shape(&nc_range, 1, (int[]){cells + 1}); long offset[XE]; offset[I] = 0; // i - offset[LL] = gkyl_range_offset(&nc_range, (int[]) { -2 } ); // i-1 - offset[L] = gkyl_range_offset(&nc_range, (int[]) { -1 } ); // i-1 - offset[R] = gkyl_range_offset(&nc_range, (int[]) { 1 } ); // i+1 - offset[RR] = gkyl_range_offset(&nc_range, (int[]) { 2 } ); // i+2 + offset[LL] = gkyl_range_offset(&nc_range, (int[]){-2}); // i-1 + offset[L] = gkyl_range_offset(&nc_range, (int[]){-1}); // i-1 + offset[R] = gkyl_range_offset(&nc_range, (int[]){1}); // i+1 + offset[RR] = gkyl_range_offset(&nc_range, (int[]){2}); // i+2 struct gkyl_array *gradx = mem->grad1dx; @@ -175,104 +238,116 @@ gkyl_dg_calc_cubic_1d_from_nodal_vals(gkyl_dg_basis_op_mem *mem, int cells, doub if ((iter.idx[0] != ilo) && (iter.idx[0] != iup)) { // interior nodes - const double *val_L = gkyl_array_cfetch(nodal_vals, nidx+offset[L]); - const double *val_R = gkyl_array_cfetch(nodal_vals, nidx+offset[R]); - - double *grad_I = gkyl_array_fetch(gradx, nidx+offset[I]); - grad_I[0] = (val_R[0]-val_L[0])/(2*dx); + const double *val_L = gkyl_array_cfetch(nodal_vals, nidx + offset[L]); + const double *val_R = gkyl_array_cfetch(nodal_vals, nidx + offset[R]); + + double *grad_I = gkyl_array_fetch(gradx, nidx + offset[I]); + grad_I[0] = (val_R[0] - val_L[0]) / (2 * dx); } if (iter.idx[0] == ilo) { // left boundary: use second-order one sided differencing - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_R = gkyl_array_cfetch(nodal_vals, nidx+offset[R]); - const double *val_RR = gkyl_array_cfetch(nodal_vals, nidx+offset[RR]); - - double *grad_I = gkyl_array_fetch(gradx, nidx+offset[I]); - grad_I[0] = -(val_RR[0]-4*val_R[0]+3*val_I[0])/(2*dx); + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_R = gkyl_array_cfetch(nodal_vals, nidx + offset[R]); + const double *val_RR = gkyl_array_cfetch(nodal_vals, nidx + offset[RR]); + + double *grad_I = gkyl_array_fetch(gradx, nidx + offset[I]); + grad_I[0] = -(val_RR[0] - 4 * val_R[0] + 3 * val_I[0]) / (2 * dx); } if (iter.idx[0] == iup) { // right boundary: use second-order one sided differencing - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_L = gkyl_array_cfetch(nodal_vals, nidx+offset[L]); - const double *val_LL = gkyl_array_cfetch(nodal_vals, nidx+offset[LL]); - - double *grad_I = gkyl_array_fetch(gradx, nidx+offset[I]); - grad_I[0] = (3*val_I[0]-4*val_L[0]+val_LL[0])/(2*dx); + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_L = gkyl_array_cfetch(nodal_vals, nidx + offset[L]); + const double *val_LL = gkyl_array_cfetch(nodal_vals, nidx + offset[LL]); + + double *grad_I = gkyl_array_fetch(gradx, nidx + offset[I]); + grad_I[0] = (3 * val_I[0] - 4 * val_L[0] + val_LL[0]) / (2 * dx); } } // Step 2: compute cubic expansions in each cell gkyl_range_iter_init(&iter, &range); // loop is over cells while (gkyl_range_iter_next(&iter)) { - long nidx = gkyl_range_idx(&nc_range, iter.idx); - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_R = gkyl_array_cfetch(nodal_vals, nidx+offset[R]); - const double *grad_I = gkyl_array_cfetch(gradx, nidx+offset[I]); - const double *grad_R = gkyl_array_cfetch(gradx, nidx+offset[R]); + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_R = gkyl_array_cfetch(nodal_vals, nidx + offset[R]); + const double *grad_I = gkyl_array_cfetch(gradx, nidx + offset[I]); + const double *grad_R = gkyl_array_cfetch(gradx, nidx + offset[R]); - double val[2] = { val_I[0], val_R[0] }; - double grad[2] = { grad_I[0]*dx/2, grad_R[0]*dx/2 }; + double val[2] = {val_I[0], val_R[0]}; + double grad[2] = {grad_I[0] * dx / 2, grad_R[0] * dx / 2}; - long cidx = gkyl_range_idx(&range, iter.idx); + long cidx = gkyl_range_idx(&range, iter.idx); gkyl_dg_calc_cubic_1d(val, grad, gkyl_array_fetch(cubic, cidx)); } } -void -gkyl_dg_calc_cubic_2d_from_nodal_vals(gkyl_dg_basis_op_mem *mem, int cells[2], double dx[2], - const struct gkyl_array *nodal_vals, struct gkyl_array *cubic) +void gkyl_dg_calc_cubic_2d_from_nodal_vals( + gkyl_dg_basis_op_mem *mem, int cells[2], double dx[2], const struct gkyl_array *nodal_vals, + struct gkyl_array *cubic +) { enum { I, // (i,j) - LL, L, R, RR, // (i-2,j) (i-1,j) (i+1,j) (i+2,j) - BB, B, T, TT, // (i,j-2) (i,j-1) (i,j+1) (i,j+2) - LT, RT, // (i-1,j+1), (i+1,j+1) - LB, RB, // (i-1,j-1), (i+1,j-1) - RRT, RRB, // (i+2,j+1) (i+2,j-1) - LLT, LLB, // (i-2,j+1) (i-2,j-1) - LTT, RTT, // (i-1,j+2), (i+1,j+2) - LBB, RBB, // (i-1,j-2), (i+1,j-2) + LL, + L, + R, + RR, // (i-2,j) (i-1,j) (i+1,j) (i+2,j) + BB, + B, + T, + TT, // (i,j-2) (i,j-1) (i,j+1) (i,j+2) + LT, + RT, // (i-1,j+1), (i+1,j+1) + LB, + RB, // (i-1,j-1), (i+1,j-1) + RRT, + RRB, // (i+2,j+1) (i+2,j-1) + LLT, + LLB, // (i-2,j+1) (i-2,j-1) + LTT, + RTT, // (i-1,j+2), (i+1,j+2) + LBB, + RBB, // (i-1,j-2), (i+1,j-2) XE - }; - + }; + struct gkyl_range range; gkyl_range_init_from_shape(&range, 2, cells); struct gkyl_range nc_range; - gkyl_range_init_from_shape(&nc_range, 2, (int[]) { cells[0]+1, cells[1]+1 }); + gkyl_range_init_from_shape(&nc_range, 2, (int[]){cells[0] + 1, cells[1] + 1}); long offset[XE]; offset[I] = 0; // i,j - offset[LL] = gkyl_range_offset(&nc_range, (int[]) { -2,0 } ); // i-2,j - offset[L] = gkyl_range_offset(&nc_range, (int[]) { -1,0 } ); // i-1,j - offset[R] = gkyl_range_offset(&nc_range, (int[]) { 1,0 } ); // i+1,j - offset[RR] = gkyl_range_offset(&nc_range, (int[]) { 2,0 } ); // i+2,j - - offset[BB] = gkyl_range_offset(&nc_range, (int[]) { 0,-2 } ); // i,j-2 - offset[B] = gkyl_range_offset(&nc_range, (int[]) { 0,-1 } ); // i,j-1 - offset[T] = gkyl_range_offset(&nc_range, (int[]) { 0,1 } ); // i,j+1 - offset[TT] = gkyl_range_offset(&nc_range, (int[]) { 0,2 } ); // i,j+2 + offset[LL] = gkyl_range_offset(&nc_range, (int[]){-2, 0}); // i-2,j + offset[L] = gkyl_range_offset(&nc_range, (int[]){-1, 0}); // i-1,j + offset[R] = gkyl_range_offset(&nc_range, (int[]){1, 0}); // i+1,j + offset[RR] = gkyl_range_offset(&nc_range, (int[]){2, 0}); // i+2,j + + offset[BB] = gkyl_range_offset(&nc_range, (int[]){0, -2}); // i,j-2 + offset[B] = gkyl_range_offset(&nc_range, (int[]){0, -1}); // i,j-1 + offset[T] = gkyl_range_offset(&nc_range, (int[]){0, 1}); // i,j+1 + offset[TT] = gkyl_range_offset(&nc_range, (int[]){0, 2}); // i,j+2 - offset[LT] = gkyl_range_offset(&nc_range, (int[]) { -1,1 } ); // i-1,j+1 - offset[RT] = gkyl_range_offset(&nc_range, (int[]) { 1,1 } ); // i+1,j+1 - offset[LB] = gkyl_range_offset(&nc_range, (int[]) { -1,-1 } ); // i-1,j-1 - offset[RB] = gkyl_range_offset(&nc_range, (int[]) { 1,-1 } ); // i+1,j-1 + offset[LT] = gkyl_range_offset(&nc_range, (int[]){-1, 1}); // i-1,j+1 + offset[RT] = gkyl_range_offset(&nc_range, (int[]){1, 1}); // i+1,j+1 + offset[LB] = gkyl_range_offset(&nc_range, (int[]){-1, -1}); // i-1,j-1 + offset[RB] = gkyl_range_offset(&nc_range, (int[]){1, -1}); // i+1,j-1 - offset[RRT] = gkyl_range_offset(&nc_range, (int[]) { 2,1 } ); // i+2,j+1 - offset[RRB] = gkyl_range_offset(&nc_range, (int[]) { 2,-1 } ); // i+2,j-1 + offset[RRT] = gkyl_range_offset(&nc_range, (int[]){2, 1}); // i+2,j+1 + offset[RRB] = gkyl_range_offset(&nc_range, (int[]){2, -1}); // i+2,j-1 - offset[LLT] = gkyl_range_offset(&nc_range, (int[]) { -2,1 } ); // i-2,j+1 - offset[LLB] = gkyl_range_offset(&nc_range, (int[]) { -2,-1 } ); // i-2,j-1 + offset[LLT] = gkyl_range_offset(&nc_range, (int[]){-2, 1}); // i-2,j+1 + offset[LLB] = gkyl_range_offset(&nc_range, (int[]){-2, -1}); // i-2,j-1 - offset[LTT] = gkyl_range_offset(&nc_range, (int[]) { -1,2 } ); // i-1,j+2 - offset[RTT] = gkyl_range_offset(&nc_range, (int[]) { 1,2 } ); // i+1,j+2 + offset[LTT] = gkyl_range_offset(&nc_range, (int[]){-1, 2}); // i-1,j+2 + offset[RTT] = gkyl_range_offset(&nc_range, (int[]){1, 2}); // i+1,j+2 - offset[LBB] = gkyl_range_offset(&nc_range, (int[]) { -1,-2 } ); // i-1,j-2 - offset[RBB] = gkyl_range_offset(&nc_range, (int[]) { 1,-2 } ); // i+1,j-2 + offset[LBB] = gkyl_range_offset(&nc_range, (int[]){-1, -2}); // i-1,j-2 + offset[RBB] = gkyl_range_offset(&nc_range, (int[]){1, -2}); // i+1,j-2 struct gkyl_array *gradx = mem->grad2dx; struct gkyl_array *grady = mem->grad2dy; @@ -284,220 +359,220 @@ gkyl_dg_calc_cubic_2d_from_nodal_vals(gkyl_dg_basis_op_mem *mem, int cells[2], d // Step 1.0: compute gradients at interior nodes using differencing struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &nc_range); // loop over node range - + while (gkyl_range_iter_next(&iter)) { long nidx = gkyl_range_idx(&nc_range, iter.idx); - if ((iter.idx[0] != ilo) && (iter.idx[0] != iup) && (iter.idx[1] != jlo) && (iter.idx[1] != jup)) { + if ((iter.idx[0] != ilo) && (iter.idx[0] != iup) && (iter.idx[1] != jlo) && + (iter.idx[1] != jup)) { // interior nodes - const double *val_L = gkyl_array_cfetch(nodal_vals, nidx+offset[L]); - const double *val_R = gkyl_array_cfetch(nodal_vals, nidx+offset[R]); - const double *val_T = gkyl_array_cfetch(nodal_vals, nidx+offset[T]); - const double *val_B = gkyl_array_cfetch(nodal_vals, nidx+offset[B]); - - double *gradx_I = gkyl_array_fetch(gradx, nidx+offset[I]); - gradx_I[0] = (val_R[0]-val_L[0])/(2*dx[0]); - - double *grady_I = gkyl_array_fetch(grady, nidx+offset[I]); - grady_I[0] = (val_T[0]-val_B[0])/(2*dx[1]); - - const double *val_LT = gkyl_array_cfetch(nodal_vals, nidx+offset[LT]); - const double *val_RT = gkyl_array_cfetch(nodal_vals, nidx+offset[RT]); - const double *val_LB = gkyl_array_cfetch(nodal_vals, nidx+offset[LB]); - const double *val_RB = gkyl_array_cfetch(nodal_vals, nidx+offset[RB]); - - double *gradxy_I = gkyl_array_fetch(gradxy, nidx+offset[I]); - gradxy_I[0] = ( - (val_RT[0]-val_RB[0])/(2*dx[1]) - (val_LT[0]-val_LB[0])/(2*dx[1]) - )/(2*dx[0]); + const double *val_L = gkyl_array_cfetch(nodal_vals, nidx + offset[L]); + const double *val_R = gkyl_array_cfetch(nodal_vals, nidx + offset[R]); + const double *val_T = gkyl_array_cfetch(nodal_vals, nidx + offset[T]); + const double *val_B = gkyl_array_cfetch(nodal_vals, nidx + offset[B]); + + double *gradx_I = gkyl_array_fetch(gradx, nidx + offset[I]); + gradx_I[0] = (val_R[0] - val_L[0]) / (2 * dx[0]); + + double *grady_I = gkyl_array_fetch(grady, nidx + offset[I]); + grady_I[0] = (val_T[0] - val_B[0]) / (2 * dx[1]); + + const double *val_LT = gkyl_array_cfetch(nodal_vals, nidx + offset[LT]); + const double *val_RT = gkyl_array_cfetch(nodal_vals, nidx + offset[RT]); + const double *val_LB = gkyl_array_cfetch(nodal_vals, nidx + offset[LB]); + const double *val_RB = gkyl_array_cfetch(nodal_vals, nidx + offset[RB]); + + double *gradxy_I = gkyl_array_fetch(gradxy, nidx + offset[I]); + gradxy_I[0] = + ((val_RT[0] - val_RB[0]) / (2 * dx[1]) - (val_LT[0] - val_LB[0]) / (2 * dx[1])) / + (2 * dx[0]); } - + if ((iter.idx[0] == ilo) && (iter.idx[1] != jlo) && (iter.idx[1] != jup)) { // left boundary (excluding corners) - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_R = gkyl_array_cfetch(nodal_vals, nidx+offset[R]); - const double *val_RR = gkyl_array_cfetch(nodal_vals, nidx+offset[RR]); - const double *val_T = gkyl_array_cfetch(nodal_vals, nidx+offset[T]); - const double *val_B = gkyl_array_cfetch(nodal_vals, nidx+offset[B]); - - double *gradx_I = gkyl_array_fetch(gradx, nidx+offset[I]); - gradx_I[0] = -(val_RR[0]-4*val_R[0]+3*val_I[0])/(2*dx[0]); - - double *grady_I = gkyl_array_fetch(grady, nidx+offset[I]); - grady_I[0] = (val_T[0]-val_B[0])/(2*dx[1]); - - const double *val_RT = gkyl_array_cfetch(nodal_vals, nidx+offset[RT]); - const double *val_RB = gkyl_array_cfetch(nodal_vals, nidx+offset[RB]); - const double *val_RRT = gkyl_array_cfetch(nodal_vals, nidx+offset[RRT]); - const double *val_RRB = gkyl_array_cfetch(nodal_vals, nidx+offset[RRB]); - - double gy_RR = (val_RRT[0]-val_RRB[0])/(2*dx[1]); - double gy_R = (val_RT[0]-val_RB[0])/(2*dx[1]); - double gy_I = (val_T[0]-val_B[0])/(2*dx[1]); - - double *gradxy_I = gkyl_array_fetch(gradxy, nidx+offset[I]); - gradxy_I[0] = -(gy_RR-4*gy_R+3*gy_I)/(2*dx[0]); + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_R = gkyl_array_cfetch(nodal_vals, nidx + offset[R]); + const double *val_RR = gkyl_array_cfetch(nodal_vals, nidx + offset[RR]); + const double *val_T = gkyl_array_cfetch(nodal_vals, nidx + offset[T]); + const double *val_B = gkyl_array_cfetch(nodal_vals, nidx + offset[B]); + + double *gradx_I = gkyl_array_fetch(gradx, nidx + offset[I]); + gradx_I[0] = -(val_RR[0] - 4 * val_R[0] + 3 * val_I[0]) / (2 * dx[0]); + + double *grady_I = gkyl_array_fetch(grady, nidx + offset[I]); + grady_I[0] = (val_T[0] - val_B[0]) / (2 * dx[1]); + + const double *val_RT = gkyl_array_cfetch(nodal_vals, nidx + offset[RT]); + const double *val_RB = gkyl_array_cfetch(nodal_vals, nidx + offset[RB]); + const double *val_RRT = gkyl_array_cfetch(nodal_vals, nidx + offset[RRT]); + const double *val_RRB = gkyl_array_cfetch(nodal_vals, nidx + offset[RRB]); + + double gy_RR = (val_RRT[0] - val_RRB[0]) / (2 * dx[1]); + double gy_R = (val_RT[0] - val_RB[0]) / (2 * dx[1]); + double gy_I = (val_T[0] - val_B[0]) / (2 * dx[1]); + + double *gradxy_I = gkyl_array_fetch(gradxy, nidx + offset[I]); + gradxy_I[0] = -(gy_RR - 4 * gy_R + 3 * gy_I) / (2 * dx[0]); } if ((iter.idx[0] == iup) && (iter.idx[1] != jlo) && (iter.idx[1] != jup)) { // right boundary (excluding corners) - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_L = gkyl_array_cfetch(nodal_vals, nidx+offset[L]); - const double *val_LL = gkyl_array_cfetch(nodal_vals, nidx+offset[LL]); - const double *val_T = gkyl_array_cfetch(nodal_vals, nidx+offset[T]); - const double *val_B = gkyl_array_cfetch(nodal_vals, nidx+offset[B]); - - double *gradx_I = gkyl_array_fetch(gradx, nidx+offset[I]); - gradx_I[0] = (3*val_I[0]-4*val_L[0]+val_LL[0])/(2*dx[0]); - - double *grady_I = gkyl_array_fetch(grady, nidx+offset[I]); - grady_I[0] = (val_T[0]-val_B[0])/(2*dx[1]); - - const double *val_LT = gkyl_array_cfetch(nodal_vals, nidx+offset[LT]); - const double *val_LB = gkyl_array_cfetch(nodal_vals, nidx+offset[LB]); - const double *val_LLT = gkyl_array_cfetch(nodal_vals, nidx+offset[LLT]); - const double *val_LLB = gkyl_array_cfetch(nodal_vals, nidx+offset[LLB]); - - double gy_LL = (val_LLT[0]-val_LLB[0])/(2*dx[1]); - double gy_L = (val_LT[0]-val_LB[0])/(2*dx[1]); - double gy_I = (val_T[0]-val_B[0])/(2*dx[1]); - - double *gradxy_I = gkyl_array_fetch(gradxy, nidx+offset[I]); - gradxy_I[0] = (3*gy_I-4*gy_L+gy_LL)/(2*dx[0]); + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_L = gkyl_array_cfetch(nodal_vals, nidx + offset[L]); + const double *val_LL = gkyl_array_cfetch(nodal_vals, nidx + offset[LL]); + const double *val_T = gkyl_array_cfetch(nodal_vals, nidx + offset[T]); + const double *val_B = gkyl_array_cfetch(nodal_vals, nidx + offset[B]); + + double *gradx_I = gkyl_array_fetch(gradx, nidx + offset[I]); + gradx_I[0] = (3 * val_I[0] - 4 * val_L[0] + val_LL[0]) / (2 * dx[0]); + + double *grady_I = gkyl_array_fetch(grady, nidx + offset[I]); + grady_I[0] = (val_T[0] - val_B[0]) / (2 * dx[1]); + + const double *val_LT = gkyl_array_cfetch(nodal_vals, nidx + offset[LT]); + const double *val_LB = gkyl_array_cfetch(nodal_vals, nidx + offset[LB]); + const double *val_LLT = gkyl_array_cfetch(nodal_vals, nidx + offset[LLT]); + const double *val_LLB = gkyl_array_cfetch(nodal_vals, nidx + offset[LLB]); + + double gy_LL = (val_LLT[0] - val_LLB[0]) / (2 * dx[1]); + double gy_L = (val_LT[0] - val_LB[0]) / (2 * dx[1]); + double gy_I = (val_T[0] - val_B[0]) / (2 * dx[1]); + + double *gradxy_I = gkyl_array_fetch(gradxy, nidx + offset[I]); + gradxy_I[0] = (3 * gy_I - 4 * gy_L + gy_LL) / (2 * dx[0]); } if ((iter.idx[0] != ilo) && (iter.idx[0] != iup) && (iter.idx[1] == jlo)) { // bottom boundary (excluding corners) - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_T = gkyl_array_cfetch(nodal_vals, nidx+offset[T]); - const double *val_TT = gkyl_array_cfetch(nodal_vals, nidx+offset[TT]); - const double *val_L = gkyl_array_cfetch(nodal_vals, nidx+offset[L]); - const double *val_R = gkyl_array_cfetch(nodal_vals, nidx+offset[R]); - - double *gradx_I = gkyl_array_fetch(gradx, nidx+offset[I]); - gradx_I[0] = (val_R[0]-val_L[0])/(2*dx[0]); - - double *grady_I = gkyl_array_fetch(grady, nidx+offset[I]); - grady_I[0] = -(val_TT[0]-4*val_T[0]+3*val_I[0])/(2*dx[1]); - - const double *val_LT = gkyl_array_cfetch(nodal_vals, nidx+offset[LT]); - const double *val_RT = gkyl_array_cfetch(nodal_vals, nidx+offset[RT]); - const double *val_LTT = gkyl_array_cfetch(nodal_vals, nidx+offset[LTT]); - const double *val_RTT = gkyl_array_cfetch(nodal_vals, nidx+offset[RTT]); - - double gx_TT = (val_RTT[0]-val_LTT[0])/(2*dx[0]); - double gx_T = (val_RT[0]-val_LT[0])/(2*dx[0]); - double gx_I = (val_R[0]-val_L[0])/(2*dx[0]); - - double *gradxy_I = gkyl_array_fetch(gradxy, nidx+offset[I]); - gradxy_I[0] = -(gx_TT-4*gx_T+3*gx_I)/(2*dx[1]); + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_T = gkyl_array_cfetch(nodal_vals, nidx + offset[T]); + const double *val_TT = gkyl_array_cfetch(nodal_vals, nidx + offset[TT]); + const double *val_L = gkyl_array_cfetch(nodal_vals, nidx + offset[L]); + const double *val_R = gkyl_array_cfetch(nodal_vals, nidx + offset[R]); + + double *gradx_I = gkyl_array_fetch(gradx, nidx + offset[I]); + gradx_I[0] = (val_R[0] - val_L[0]) / (2 * dx[0]); + + double *grady_I = gkyl_array_fetch(grady, nidx + offset[I]); + grady_I[0] = -(val_TT[0] - 4 * val_T[0] + 3 * val_I[0]) / (2 * dx[1]); + + const double *val_LT = gkyl_array_cfetch(nodal_vals, nidx + offset[LT]); + const double *val_RT = gkyl_array_cfetch(nodal_vals, nidx + offset[RT]); + const double *val_LTT = gkyl_array_cfetch(nodal_vals, nidx + offset[LTT]); + const double *val_RTT = gkyl_array_cfetch(nodal_vals, nidx + offset[RTT]); + + double gx_TT = (val_RTT[0] - val_LTT[0]) / (2 * dx[0]); + double gx_T = (val_RT[0] - val_LT[0]) / (2 * dx[0]); + double gx_I = (val_R[0] - val_L[0]) / (2 * dx[0]); + + double *gradxy_I = gkyl_array_fetch(gradxy, nidx + offset[I]); + gradxy_I[0] = -(gx_TT - 4 * gx_T + 3 * gx_I) / (2 * dx[1]); } if ((iter.idx[0] != ilo) && (iter.idx[0] != iup) && (iter.idx[1] == jup)) { // top boundary (excluding corners) - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_B = gkyl_array_cfetch(nodal_vals, nidx+offset[B]); - const double *val_BB = gkyl_array_cfetch(nodal_vals, nidx+offset[BB]); - const double *val_L = gkyl_array_cfetch(nodal_vals, nidx+offset[L]); - const double *val_R = gkyl_array_cfetch(nodal_vals, nidx+offset[R]); - - double *gradx_I = gkyl_array_fetch(gradx, nidx+offset[I]); - gradx_I[0] = (val_R[0]-val_L[0])/(2*dx[0]); - - double *grady_I = gkyl_array_fetch(grady, nidx+offset[I]); - grady_I[0] = (3*val_I[0]-4*val_B[0]+val_BB[0])/(2*dx[1]); - - const double *val_LB = gkyl_array_cfetch(nodal_vals, nidx+offset[LB]); - const double *val_RB = gkyl_array_cfetch(nodal_vals, nidx+offset[RB]); - const double *val_LBB = gkyl_array_cfetch(nodal_vals, nidx+offset[LBB]); - const double *val_RBB = gkyl_array_cfetch(nodal_vals, nidx+offset[RBB]); - - double gx_BB = (val_RBB[0]-val_LBB[0])/(2*dx[0]); - double gx_B = (val_RB[0]-val_LB[0])/(2*dx[0]); - double gx_I = (val_R[0]-val_L[0])/(2*dx[0]); - - double *gradxy_I = gkyl_array_fetch(gradxy, nidx+offset[I]); - gradxy_I[0] = (3*gx_I-4*gx_B+gx_BB)/(2*dx[1]); + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_B = gkyl_array_cfetch(nodal_vals, nidx + offset[B]); + const double *val_BB = gkyl_array_cfetch(nodal_vals, nidx + offset[BB]); + const double *val_L = gkyl_array_cfetch(nodal_vals, nidx + offset[L]); + const double *val_R = gkyl_array_cfetch(nodal_vals, nidx + offset[R]); + + double *gradx_I = gkyl_array_fetch(gradx, nidx + offset[I]); + gradx_I[0] = (val_R[0] - val_L[0]) / (2 * dx[0]); + + double *grady_I = gkyl_array_fetch(grady, nidx + offset[I]); + grady_I[0] = (3 * val_I[0] - 4 * val_B[0] + val_BB[0]) / (2 * dx[1]); + + const double *val_LB = gkyl_array_cfetch(nodal_vals, nidx + offset[LB]); + const double *val_RB = gkyl_array_cfetch(nodal_vals, nidx + offset[RB]); + const double *val_LBB = gkyl_array_cfetch(nodal_vals, nidx + offset[LBB]); + const double *val_RBB = gkyl_array_cfetch(nodal_vals, nidx + offset[RBB]); + + double gx_BB = (val_RBB[0] - val_LBB[0]) / (2 * dx[0]); + double gx_B = (val_RB[0] - val_LB[0]) / (2 * dx[0]); + double gx_I = (val_R[0] - val_L[0]) / (2 * dx[0]); + + double *gradxy_I = gkyl_array_fetch(gradxy, nidx + offset[I]); + gradxy_I[0] = (3 * gx_I - 4 * gx_B + gx_BB) / (2 * dx[1]); } if ((iter.idx[0] == ilo) && (iter.idx[1] == jlo)) { // lower-left corner - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_R = gkyl_array_cfetch(nodal_vals, nidx+offset[R]); - const double *val_RR = gkyl_array_cfetch(nodal_vals, nidx+offset[RR]); - const double *val_T = gkyl_array_cfetch(nodal_vals, nidx+offset[T]); - const double *val_TT = gkyl_array_cfetch(nodal_vals, nidx+offset[TT]); - const double *val_RT = gkyl_array_cfetch(nodal_vals, nidx+offset[RT]); - - double *gradx_I = gkyl_array_fetch(gradx, nidx+offset[I]); - gradx_I[0] = -(val_RR[0]-4*val_R[0]+3*val_I[0])/(2*dx[0]); - - double *grady_I = gkyl_array_fetch(grady, nidx+offset[I]); - grady_I[0] = -(val_TT[0]-4*val_T[0]+3*val_I[0])/(2*dx[1]); - - double *gradxy_I = gkyl_array_fetch(gradxy, nidx+offset[I]); - double vxy[4] = { val_I[0], val_T[0], val_R[0], val_RT[0] }; + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_R = gkyl_array_cfetch(nodal_vals, nidx + offset[R]); + const double *val_RR = gkyl_array_cfetch(nodal_vals, nidx + offset[RR]); + const double *val_T = gkyl_array_cfetch(nodal_vals, nidx + offset[T]); + const double *val_TT = gkyl_array_cfetch(nodal_vals, nidx + offset[TT]); + const double *val_RT = gkyl_array_cfetch(nodal_vals, nidx + offset[RT]); + + double *gradx_I = gkyl_array_fetch(gradx, nidx + offset[I]); + gradx_I[0] = -(val_RR[0] - 4 * val_R[0] + 3 * val_I[0]) / (2 * dx[0]); + + double *grady_I = gkyl_array_fetch(grady, nidx + offset[I]); + grady_I[0] = -(val_TT[0] - 4 * val_T[0] + 3 * val_I[0]) / (2 * dx[1]); + + double *gradxy_I = gkyl_array_fetch(gradxy, nidx + offset[I]); + double vxy[4] = {val_I[0], val_T[0], val_R[0], val_RT[0]}; gradxy_I[0] = calc_bilinear_grad_xy(vxy, dx); } if ((iter.idx[0] == ilo) && (iter.idx[1] == jup)) { // upper-left corner - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_R = gkyl_array_cfetch(nodal_vals, nidx+offset[R]); - const double *val_RR = gkyl_array_cfetch(nodal_vals, nidx+offset[RR]); - const double *val_B = gkyl_array_cfetch(nodal_vals, nidx+offset[B]); - const double *val_BB = gkyl_array_cfetch(nodal_vals, nidx+offset[BB]); - const double *val_RB = gkyl_array_cfetch(nodal_vals, nidx+offset[RB]); - - double *gradx_I = gkyl_array_fetch(gradx, nidx+offset[I]); - gradx_I[0] = -(val_RR[0]-4*val_R[0]+3*val_I[0])/(2*dx[0]); - - double *grady_I = gkyl_array_fetch(grady, nidx+offset[I]); - grady_I[0] = (3*val_I[0]-4*val_B[0]+val_BB[0])/(2*dx[1]); - - double *gradxy_I = gkyl_array_fetch(gradxy, nidx+offset[I]); - double vxy[4] = { val_B[0], val_I[0], val_RB[0], val_R[0] }; + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_R = gkyl_array_cfetch(nodal_vals, nidx + offset[R]); + const double *val_RR = gkyl_array_cfetch(nodal_vals, nidx + offset[RR]); + const double *val_B = gkyl_array_cfetch(nodal_vals, nidx + offset[B]); + const double *val_BB = gkyl_array_cfetch(nodal_vals, nidx + offset[BB]); + const double *val_RB = gkyl_array_cfetch(nodal_vals, nidx + offset[RB]); + + double *gradx_I = gkyl_array_fetch(gradx, nidx + offset[I]); + gradx_I[0] = -(val_RR[0] - 4 * val_R[0] + 3 * val_I[0]) / (2 * dx[0]); + + double *grady_I = gkyl_array_fetch(grady, nidx + offset[I]); + grady_I[0] = (3 * val_I[0] - 4 * val_B[0] + val_BB[0]) / (2 * dx[1]); + + double *gradxy_I = gkyl_array_fetch(gradxy, nidx + offset[I]); + double vxy[4] = {val_B[0], val_I[0], val_RB[0], val_R[0]}; gradxy_I[0] = calc_bilinear_grad_xy(vxy, dx); } if ((iter.idx[0] == iup) && (iter.idx[1] == jlo)) { // lower-right corner - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_L = gkyl_array_cfetch(nodal_vals, nidx+offset[L]); - const double *val_LL = gkyl_array_cfetch(nodal_vals, nidx+offset[LL]); - const double *val_T = gkyl_array_cfetch(nodal_vals, nidx+offset[T]); - const double *val_TT = gkyl_array_cfetch(nodal_vals, nidx+offset[TT]); - const double *val_LT = gkyl_array_cfetch(nodal_vals, nidx+offset[LT]); - - double *gradx_I = gkyl_array_fetch(gradx, nidx+offset[I]); - gradx_I[0] = (3*val_I[0]-4*val_L[0]+val_LL[0])/(2*dx[0]); - - double *grady_I = gkyl_array_fetch(grady, nidx+offset[I]); - grady_I[0] = -(val_TT[0]-4*val_T[0]+3*val_I[0])/(2*dx[1]); - - double *gradxy_I = gkyl_array_fetch(gradxy, nidx+offset[I]); - double vxy[4] = { val_L[0], val_LT[0], val_I[0], val_T[0] }; + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_L = gkyl_array_cfetch(nodal_vals, nidx + offset[L]); + const double *val_LL = gkyl_array_cfetch(nodal_vals, nidx + offset[LL]); + const double *val_T = gkyl_array_cfetch(nodal_vals, nidx + offset[T]); + const double *val_TT = gkyl_array_cfetch(nodal_vals, nidx + offset[TT]); + const double *val_LT = gkyl_array_cfetch(nodal_vals, nidx + offset[LT]); + + double *gradx_I = gkyl_array_fetch(gradx, nidx + offset[I]); + gradx_I[0] = (3 * val_I[0] - 4 * val_L[0] + val_LL[0]) / (2 * dx[0]); + + double *grady_I = gkyl_array_fetch(grady, nidx + offset[I]); + grady_I[0] = -(val_TT[0] - 4 * val_T[0] + 3 * val_I[0]) / (2 * dx[1]); + + double *gradxy_I = gkyl_array_fetch(gradxy, nidx + offset[I]); + double vxy[4] = {val_L[0], val_LT[0], val_I[0], val_T[0]}; gradxy_I[0] = calc_bilinear_grad_xy(vxy, dx); } - if ((iter.idx[0] == iup) && (iter.idx[1] == jup)) { // upper-right corner - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_L = gkyl_array_cfetch(nodal_vals, nidx+offset[L]); - const double *val_LL = gkyl_array_cfetch(nodal_vals, nidx+offset[LL]); - const double *val_B = gkyl_array_cfetch(nodal_vals, nidx+offset[B]); - const double *val_BB = gkyl_array_cfetch(nodal_vals, nidx+offset[BB]); - const double *val_LB = gkyl_array_cfetch(nodal_vals, nidx+offset[LB]); - - double *gradx_I = gkyl_array_fetch(gradx, nidx+offset[I]); - gradx_I[0] = (3*val_I[0]-4*val_L[0]+val_LL[0])/(2*dx[0]); - - double *grady_I = gkyl_array_fetch(grady, nidx+offset[I]); - grady_I[0] = (3*val_I[0]-4*val_B[0]+val_BB[0])/(2*dx[1]); - - double *gradxy_I = gkyl_array_fetch(gradxy, nidx+offset[I]); - double vxy[4] = { val_LB[0], val_L[0], val_B[0], val_I[0] }; + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_L = gkyl_array_cfetch(nodal_vals, nidx + offset[L]); + const double *val_LL = gkyl_array_cfetch(nodal_vals, nidx + offset[LL]); + const double *val_B = gkyl_array_cfetch(nodal_vals, nidx + offset[B]); + const double *val_BB = gkyl_array_cfetch(nodal_vals, nidx + offset[BB]); + const double *val_LB = gkyl_array_cfetch(nodal_vals, nidx + offset[LB]); + + double *gradx_I = gkyl_array_fetch(gradx, nidx + offset[I]); + gradx_I[0] = (3 * val_I[0] - 4 * val_L[0] + val_LL[0]) / (2 * dx[0]); + + double *grady_I = gkyl_array_fetch(grady, nidx + offset[I]); + grady_I[0] = (3 * val_I[0] - 4 * val_B[0] + val_BB[0]) / (2 * dx[1]); + + double *gradxy_I = gkyl_array_fetch(gradxy, nidx + offset[I]); + double vxy[4] = {val_LB[0], val_L[0], val_B[0], val_I[0]}; gradxy_I[0] = calc_bilinear_grad_xy(vxy, dx); } } @@ -505,34 +580,42 @@ gkyl_dg_calc_cubic_2d_from_nodal_vals(gkyl_dg_basis_op_mem *mem, int cells[2], d // Step 2: compute cubic expansions in each cell gkyl_range_iter_init(&iter, &range); // loop is over cells while (gkyl_range_iter_next(&iter)) { - long nidx = gkyl_range_idx(&nc_range, iter.idx); // four corners nodes of cell - const double *val_I = gkyl_array_cfetch(nodal_vals, nidx+offset[I]); - const double *val_R = gkyl_array_cfetch(nodal_vals, nidx+offset[R]); - const double *val_T = gkyl_array_cfetch(nodal_vals, nidx+offset[T]); - const double *val_RT = gkyl_array_cfetch(nodal_vals, nidx+offset[RT]); - - const double *gradx_I = gkyl_array_cfetch(gradx, nidx+offset[I]); - const double *gradx_R = gkyl_array_cfetch(gradx, nidx+offset[R]); - const double *gradx_T = gkyl_array_cfetch(gradx, nidx+offset[T]); - const double *gradx_RT = gkyl_array_cfetch(gradx, nidx+offset[RT]); - - const double *grady_I = gkyl_array_cfetch(grady, nidx+offset[I]); - const double *grady_R = gkyl_array_cfetch(grady, nidx+offset[R]); - const double *grady_T = gkyl_array_cfetch(grady, nidx+offset[T]); - const double *grady_RT = gkyl_array_cfetch(grady, nidx+offset[RT]); - - const double *gradxy_I = gkyl_array_cfetch(gradxy, nidx+offset[I]); - const double *gradxy_R = gkyl_array_cfetch(gradxy, nidx+offset[R]); - const double *gradxy_T = gkyl_array_cfetch(gradxy, nidx+offset[T]); - const double *gradxy_RT = gkyl_array_cfetch(gradxy, nidx+offset[RT]); - - double val[4] = { val_I[0], val_T[0], val_R[0], val_RT[0] }; - double gradx[4] = { gradx_I[0]*dx[0]/2, gradx_T[0]*dx[0]/2, gradx_R[0]*dx[0]/2, gradx_RT[0]*dx[0]/2 }; - double grady[4] = { grady_I[0]*dx[1]/2, grady_T[0]*dx[1]/2, grady_R[0]*dx[1]/2, grady_RT[0]*dx[1]/2 }; - double gradxy[4] = { gradxy_I[0]*dx[0]/2*dx[1]/2, gradxy_T[0]*dx[0]/2*dx[1]/2, gradxy_R[0]*dx[0]/2*dx[1]/2, gradxy_RT[0]*dx[0]/2*dx[1]/2 }; + const double *val_I = gkyl_array_cfetch(nodal_vals, nidx + offset[I]); + const double *val_R = gkyl_array_cfetch(nodal_vals, nidx + offset[R]); + const double *val_T = gkyl_array_cfetch(nodal_vals, nidx + offset[T]); + const double *val_RT = gkyl_array_cfetch(nodal_vals, nidx + offset[RT]); + + const double *gradx_I = gkyl_array_cfetch(gradx, nidx + offset[I]); + const double *gradx_R = gkyl_array_cfetch(gradx, nidx + offset[R]); + const double *gradx_T = gkyl_array_cfetch(gradx, nidx + offset[T]); + const double *gradx_RT = gkyl_array_cfetch(gradx, nidx + offset[RT]); + + const double *grady_I = gkyl_array_cfetch(grady, nidx + offset[I]); + const double *grady_R = gkyl_array_cfetch(grady, nidx + offset[R]); + const double *grady_T = gkyl_array_cfetch(grady, nidx + offset[T]); + const double *grady_RT = gkyl_array_cfetch(grady, nidx + offset[RT]); + + const double *gradxy_I = gkyl_array_cfetch(gradxy, nidx + offset[I]); + const double *gradxy_R = gkyl_array_cfetch(gradxy, nidx + offset[R]); + const double *gradxy_T = gkyl_array_cfetch(gradxy, nidx + offset[T]); + const double *gradxy_RT = gkyl_array_cfetch(gradxy, nidx + offset[RT]); + + double val[4] = {val_I[0], val_T[0], val_R[0], val_RT[0]}; + double gradx[4] = { + gradx_I[0] * dx[0] / 2, gradx_T[0] * dx[0] / 2, gradx_R[0] * dx[0] / 2, + gradx_RT[0] * dx[0] / 2 + }; + double grady[4] = { + grady_I[0] * dx[1] / 2, grady_T[0] * dx[1] / 2, grady_R[0] * dx[1] / 2, + grady_RT[0] * dx[1] / 2 + }; + double gradxy[4] = { + gradxy_I[0] * dx[0] / 2 * dx[1] / 2, gradxy_T[0] * dx[0] / 2 * dx[1] / 2, + gradxy_R[0] * dx[0] / 2 * dx[1] / 2, gradxy_RT[0] * dx[0] / 2 * dx[1] / 2 + }; long cidx = gkyl_range_idx(&range, iter.idx); double *coeff = gkyl_array_fetch(cubic, cidx); @@ -540,33 +623,45 @@ gkyl_dg_calc_cubic_2d_from_nodal_vals(gkyl_dg_basis_op_mem *mem, int cells[2], d } } - -static double -eval_laplacian_expand_2d_tensor_p3(int dir, const double *z, const double *f ) +static double eval_laplacian_expand_2d_tensor_p3(int dir, const double *z, const double *f) { const double z0 = z[0]; const double z1 = z[1]; - if (dir == 0) - return 131.25*f[15]*z0*z1*z1*z1+22.18529918662356*f[14]*z1*z1*z1+66.55589755987069*f[13]*z0*z1*z1+11.25*f[10]*z1*z1-78.75*f[15]*z0*z1+ 34.3693177121688*f[11]*z0*z1-13.31117951197414*f[14]*z1+5.809475019311125*f[6]*z1-22.18529918662356*f[13]*z0+ 19.84313483298443*f[8]*z0-3.75*f[10]+3.354101966249685*f[4]; + if (dir == 0) { + return 131.25 * f[15] * z0 * z1 * z1 * z1 + 22.18529918662356 * f[14] * z1 * z1 * z1 + + 66.55589755987069 * f[13] * z0 * z1 * z1 + 11.25 * f[10] * z1 * z1 - + 78.75 * f[15] * z0 * z1 + 34.3693177121688 * f[11] * z0 * z1 - + 13.31117951197414 * f[14] * z1 + 5.809475019311125 * f[6] * z1 - + 22.18529918662356 * f[13] * z0 + 19.84313483298443 * f[8] * z0 - 3.75 * f[10] + + 3.354101966249685 * f[4]; + } - if (dir == 1) - return 131.25*f[15]*z0*z0*z0*z1+66.55589755987069*f[14]*z0*z0*z1-78.75*f[15]*z0*z1+34.3693177121688*f[12]*z0*z1-22.18529918662356*f[14]*z1+19.84313483298443*f[9]*z1+22.18529918662356*f[13]*z0*z0*z0+11.25*f[10]*z0*z0-13.31117951197414*f[13]*z0+5.809475019311125*f[7]*z0-3.75*f[10]+3.354101966249685*f[5]; + if (dir == 1) { + return 131.25 * f[15] * z0 * z0 * z0 * z1 + 66.55589755987069 * f[14] * z0 * z0 * z1 - + 78.75 * f[15] * z0 * z1 + 34.3693177121688 * f[12] * z0 * z1 - + 22.18529918662356 * f[14] * z1 + 19.84313483298443 * f[9] * z1 + + 22.18529918662356 * f[13] * z0 * z0 * z0 + 11.25 * f[10] * z0 * z0 - + 13.31117951197414 * f[13] * z0 + 5.809475019311125 * f[7] * z0 - 3.75 * f[10] + + 3.354101966249685 * f[5]; + } return 0.0; // can't happen, suppresses warning - } -static double -eval_mixedpartial_expand_2d_tensor_p3(const double *z, const double *f ) +static double eval_mixedpartial_expand_2d_tensor_p3(const double *z, const double *f) { const double z0 = z[0]; const double z1 = z[1]; - return 196.875*f[15]*z0*z0*z1*z1+66.55589755987069*f[14]*z0*z1*z1-39.375*f[15]*z1*z1+17.1846588560844*f[12]*z1*z1+66.55589755987069*f[13]*z0*z0*z1+22.5*f[10]*z0*z1-13.31117951197414*f[13]*z1+5.809475019311125*f[7]*z1-39.375*f[15]*z0*z0+17.1846588560844*f[11]*z0*z0-13.31117951197414*f[14]*z0+5.809475019311125*f[6]*z0+7.875*f[15]-3.43693177121688*f[12]-3.43693177121688*f[11]+1.5*f[3]; - + return 196.875 * f[15] * z0 * z0 * z1 * z1 + 66.55589755987069 * f[14] * z0 * z1 * z1 - + 39.375 * f[15] * z1 * z1 + 17.1846588560844 * f[12] * z1 * z1 + + 66.55589755987069 * f[13] * z0 * z0 * z1 + 22.5 * f[10] * z0 * z1 - + 13.31117951197414 * f[13] * z1 + 5.809475019311125 * f[7] * z1 - 39.375 * f[15] * z0 * z0 + + 17.1846588560844 * f[11] * z0 * z0 - 13.31117951197414 * f[14] * z0 + + 5.809475019311125 * f[6] * z0 + 7.875 * f[15] - 3.43693177121688 * f[12] - + 3.43693177121688 * f[11] + 1.5 * f[3]; } -static void -evalf_free(const struct gkyl_ref_count* rc) +static void evalf_free(const struct gkyl_ref_count *rc) { struct gkyl_basis_ops_evalf *evf = container_of(rc, struct gkyl_basis_ops_evalf, ref_count); @@ -577,14 +672,13 @@ evalf_free(const struct gkyl_ref_count* rc) } // function for computing cubic at a specified coordinate -static void -eval_cubic(double t, const double *xn, double *fout, void *ctx) +static void eval_cubic(double t, const double *xn, double *fout, void *ctx) { struct dg_basis_ops_evalf_ctx *ectx = ctx; - - int idx[GKYL_MAX_DIM]; + + int idx[GKYL_MAX_DIM]; gkyl_rect_grid_coord_idx(&ectx->grid, xn, idx); - for (int d=0; dndim; ++d) { + for (int d = 0; d < ectx->ndim; ++d) { idx[d] = GKYL_MIN2(ectx->local.upper[d], idx[d]); idx[d] = GKYL_MAX2(ectx->local.lower[d], idx[d]); } @@ -593,24 +687,24 @@ eval_cubic(double t, const double *xn, double *fout, void *ctx) gkyl_rect_grid_cell_center(&ectx->grid, idx, xc); double eta[GKYL_MAX_DIM]; - for (int d=0; dndim; ++d) - eta[d] = 2.0*(xn[d]-xc[d])/ectx->grid.dx[d]; - + for (int d = 0; d < ectx->ndim; ++d) { + eta[d] = 2.0 * (xn[d] - xc[d]) / ectx->grid.dx[d]; + } + long lidx = gkyl_range_idx(&ectx->local, idx); const double *fdg = gkyl_array_cfetch(ectx->cubic, lidx); - + fout[0] = ectx->basis.eval_expand(eta, fdg); } // function for computing cubic at a specified coordinate -static void -eval_cubic_wgrad(double t, const double *xn, double *fout, void *ctx) +static void eval_cubic_wgrad(double t, const double *xn, double *fout, void *ctx) { struct dg_basis_ops_evalf_ctx *ectx = ctx; - - int idx[GKYL_MAX_DIM]; + + int idx[GKYL_MAX_DIM]; gkyl_rect_grid_coord_idx(&ectx->grid, xn, idx); - for (int d=0; dndim; ++d) { + for (int d = 0; d < ectx->ndim; ++d) { idx[d] = GKYL_MIN2(ectx->local.upper[d], idx[d]); idx[d] = GKYL_MAX2(ectx->local.lower[d], idx[d]); } @@ -619,27 +713,28 @@ eval_cubic_wgrad(double t, const double *xn, double *fout, void *ctx) gkyl_rect_grid_cell_center(&ectx->grid, idx, xc); double eta[GKYL_MAX_DIM]; - for (int d=0; dndim; ++d) - eta[d] = 2.0*(xn[d]-xc[d])/ectx->grid.dx[d]; - + for (int d = 0; d < ectx->ndim; ++d) { + eta[d] = 2.0 * (xn[d] - xc[d]) / ectx->grid.dx[d]; + } + long lidx = gkyl_range_idx(&ectx->local, idx); const double *fdg = gkyl_array_cfetch(ectx->cubic, lidx); - + fout[0] = ectx->basis.eval_expand(eta, fdg); - fout[1] = ectx->basis.eval_grad_expand(0, eta, fdg)*2/ectx->grid.dx[0]; - if (ectx->ndim > 1) - fout[2] = ectx->basis.eval_grad_expand(1, eta, fdg)*2/ectx->grid.dx[1]; + fout[1] = ectx->basis.eval_grad_expand(0, eta, fdg) * 2 / ectx->grid.dx[0]; + if (ectx->ndim > 1) { + fout[2] = ectx->basis.eval_grad_expand(1, eta, fdg) * 2 / ectx->grid.dx[1]; + } } // function for computing cubic at a specified coordinate -static void -eval_cubic_wgrad2(double t, const double *xn, double *fout, void *ctx) +static void eval_cubic_wgrad2(double t, const double *xn, double *fout, void *ctx) { struct dg_basis_ops_evalf_ctx *ectx = ctx; int idx[GKYL_MAX_DIM]; gkyl_rect_grid_coord_idx(&ectx->grid, xn, idx); - for (int d=0; dndim; ++d) { + for (int d = 0; d < ectx->ndim; ++d) { idx[d] = GKYL_MIN2(ectx->local.upper[d], idx[d]); idx[d] = GKYL_MAX2(ectx->local.lower[d], idx[d]); } @@ -648,41 +743,45 @@ eval_cubic_wgrad2(double t, const double *xn, double *fout, void *ctx) gkyl_rect_grid_cell_center(&ectx->grid, idx, xc); double eta[GKYL_MAX_DIM]; - for (int d=0; dndim; ++d) - eta[d] = 2.0*(xn[d]-xc[d])/ectx->grid.dx[d]; + for (int d = 0; d < ectx->ndim; ++d) { + eta[d] = 2.0 * (xn[d] - xc[d]) / ectx->grid.dx[d]; + } long lidx = gkyl_range_idx(&ectx->local, idx); const double *fdg = gkyl_array_cfetch(ectx->cubic, lidx); fout[0] = ectx->basis.eval_expand(eta, fdg); if (ectx->ndim > 1) { - fout[1] = eval_laplacian_expand_2d_tensor_p3(0, eta, fdg)*2/ectx->grid.dx[0]*2/ectx->grid.dx[0]; - fout[2] = eval_laplacian_expand_2d_tensor_p3(1, eta, fdg)*2/ectx->grid.dx[1]*2/ectx->grid.dx[1]; - fout[3] = eval_mixedpartial_expand_2d_tensor_p3(eta, fdg)*2/ectx->grid.dx[0]*2/ectx->grid.dx[1]; + fout[1] = + eval_laplacian_expand_2d_tensor_p3(0, eta, fdg) * 2 / ectx->grid.dx[0] * 2 / ectx->grid.dx[0]; + fout[2] = + eval_laplacian_expand_2d_tensor_p3(1, eta, fdg) * 2 / ectx->grid.dx[1] * 2 / ectx->grid.dx[1]; + fout[3] = + eval_mixedpartial_expand_2d_tensor_p3(eta, fdg) * 2 / ectx->grid.dx[0] * 2 / ectx->grid.dx[1]; } } - -struct gkyl_basis_ops_evalf* -gkyl_dg_basis_ops_evalf_new(const struct gkyl_rect_grid *grid, - const struct gkyl_array *nodal_vals) +struct gkyl_basis_ops_evalf * +gkyl_dg_basis_ops_evalf_new(const struct gkyl_rect_grid *grid, const struct gkyl_array *nodal_vals) { - if (grid->ndim > 2) return 0; + if (grid->ndim > 2) { + return 0; + } struct dg_basis_ops_evalf_ctx *ctx = gkyl_malloc(sizeof(*ctx)); int ndim = ctx->ndim = grid->ndim; - + int cells[2]; double dx[2]; - size_t vol = 1; - for (int d=0; dcells[d]; - dx[d] = ctx->dx[d] = grid->dx[d]; + dx[d] = ctx->dx[d] = grid->dx[d]; cells[d] = ctx->cells[d] = grid->cells[d]; } ctx->grid = *grid; - int nghost[GKYL_MAX_CDIM] = { 0 }; + int nghost[GKYL_MAX_CDIM] = {0}; gkyl_create_grid_ranges(grid, nghost, &ctx->local_ext, &ctx->local); gkyl_cart_modal_tensor(&ctx->basis, ndim, 3); @@ -706,39 +805,35 @@ gkyl_dg_basis_ops_evalf_new(const struct gkyl_rect_grid *grid, evf->eval_cubic_wgrad2 = eval_cubic_wgrad2; evf->eval_cubic_laplacian = eval_laplacian_expand_2d_tensor_p3; evf->eval_cubic_mixedpartial = eval_mixedpartial_expand_2d_tensor_p3; - evf->ref_count = (struct gkyl_ref_count) { evalf_free, 1 }; - + evf->ref_count = (struct gkyl_ref_count){evalf_free, 1}; + return evf; } -bool -gkyl_dg_basis_ops_evalf_write_cubic(const struct gkyl_basis_ops_evalf *evf, const char *fname) +bool gkyl_dg_basis_ops_evalf_write_cubic(const struct gkyl_basis_ops_evalf *evf, const char *fname) { struct dg_basis_ops_evalf_ctx *ectx = evf->ctx; - struct gkyl_msgpack_data *mdata = gkyl_msgpack_create(2, - (struct gkyl_msgpack_map_elem []) { - { .key = "polyOrder", .elem_type = GKYL_MP_INT, .ival = 3 }, - { .key = "basisType", .elem_type = GKYL_MP_STRING, .cval = ectx->basis.id } - } + struct gkyl_msgpack_data *mdata = gkyl_msgpack_create( + 2, (struct gkyl_msgpack_map_elem[] + ){{.key = "polyOrder", .elem_type = GKYL_MP_INT, .ival = 3}, + {.key = "basisType", .elem_type = GKYL_MP_STRING, .cval = ectx->basis.id}} ); enum gkyl_array_rio_status status = gkyl_grid_sub_array_write(&ectx->grid, &ectx->local, mdata, ectx->cubic, fname); - gkyl_msgpack_data_release(mdata); - + gkyl_msgpack_data_release(mdata); + return status == GKYL_ARRAY_RIO_SUCCESS; } -struct gkyl_basis_ops_evalf * -gkyl_dg_basis_ops_evalf_acquire(const struct gkyl_basis_ops_evalf *evf) +struct gkyl_basis_ops_evalf *gkyl_dg_basis_ops_evalf_acquire(const struct gkyl_basis_ops_evalf *evf) { gkyl_ref_count_inc(&evf->ref_count); - return (struct gkyl_basis_ops_evalf*) evf; + return (struct gkyl_basis_ops_evalf *)evf; } -void -gkyl_dg_basis_ops_evalf_release(struct gkyl_basis_ops_evalf *evf) +void gkyl_dg_basis_ops_evalf_release(struct gkyl_basis_ops_evalf *evf) { gkyl_ref_count_dec(&evf->ref_count); } diff --git a/core/zero/dg_basis_ops_cu.cu b/core/zero/dg_basis_ops_cu.cu index 582982f33c..31c48d383c 100644 --- a/core/zero/dg_basis_ops_cu.cu +++ b/core/zero/dg_basis_ops_cu.cu @@ -8,10 +8,10 @@ extern "C" { #include } -__global__ void -gkyl_dg_basis_ops_eval_array_at_coord_comp_cu_ker_eval(const struct gkyl_array *arr, const double *coord, - const struct gkyl_basis *basis, struct gkyl_rect_grid grid, struct gkyl_range rng, - double *out) +__global__ void gkyl_dg_basis_ops_eval_array_at_coord_comp_cu_ker_eval( + const struct gkyl_array *arr, const double *coord, const struct gkyl_basis *basis, + struct gkyl_rect_grid grid, struct gkyl_range rng, double *out +) { int coord_idx[GKYL_MAX_DIM]; gkyl_rect_grid_coord_idx(&grid, coord, coord_idx); @@ -19,30 +19,32 @@ gkyl_dg_basis_ops_eval_array_at_coord_comp_cu_ker_eval(const struct gkyl_array * if (gkyl_range_contains_idx(&rng, coord_idx)) { double xc[GKYL_MAX_DIM], coord_log[GKYL_MAX_DIM]; gkyl_rect_grid_cell_center(&grid, coord_idx, xc); - for (int d=0; deval_expand(coord_log, arr_c); - } - else + } else { out[0] = -DBL_MAX; + } } -__global__ void -gkyl_dg_basis_ops_eval_array_at_coord_comp_cu_ker_none(const struct gkyl_array *arr, const double *coord, - const struct gkyl_basis *basis, struct gkyl_rect_grid grid, struct gkyl_range rng, - double *out) +__global__ void gkyl_dg_basis_ops_eval_array_at_coord_comp_cu_ker_none( + const struct gkyl_array *arr, const double *coord, const struct gkyl_basis *basis, + struct gkyl_rect_grid grid, struct gkyl_range rng, double *out +) { out[0] = -DBL_MAX; } -void -gkyl_dg_basis_ops_eval_array_at_coord_comp_cu(const struct gkyl_array *arr, const double *coord, - const struct gkyl_basis *basis, const struct gkyl_rect_grid *grid, const struct gkyl_range *rng, - double *out) +void gkyl_dg_basis_ops_eval_array_at_coord_comp_cu( + const struct gkyl_array *arr, const double *coord, const struct gkyl_basis *basis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *rng, double *out +) { - gkyl_dg_basis_ops_eval_array_at_coord_comp_cu_ker_eval<<<1,1>>>(arr->on_dev, - coord, basis, *grid, *rng, out); + gkyl_dg_basis_ops_eval_array_at_coord_comp_cu_ker_eval<<<1, 1> > >( + arr->on_dev, coord, basis, *grid, *rng, out + ); } diff --git a/core/zero/dg_bin_ops.c b/core/zero/dg_bin_ops.c index 483dfe77a6..226e6ef742 100644 --- a/core/zero/dg_bin_ops.c +++ b/core/zero/dg_bin_ops.c @@ -7,15 +7,14 @@ #include #include -gkyl_dg_bin_op_mem* -gkyl_dg_bin_op_mem_new(size_t nbatch, size_t neqn) +gkyl_dg_bin_op_mem *gkyl_dg_bin_op_mem_new(size_t nbatch, size_t neqn) { struct gkyl_dg_bin_op_mem *mem = gkyl_malloc(sizeof(struct gkyl_dg_bin_op_mem)); mem->on_gpu = false; mem->batch_sz = nbatch; mem->ncols = mem->nrows = neqn; - + mem->As = gkyl_nmat_new(nbatch, neqn, neqn); mem->xs = gkyl_nmat_new(nbatch, neqn, 1); mem->lu_mem = gkyl_nmat_linsolve_lu_new(mem->As->num, mem->As->nr); @@ -23,15 +22,14 @@ gkyl_dg_bin_op_mem_new(size_t nbatch, size_t neqn) return mem; } -gkyl_dg_bin_op_mem* -gkyl_dg_bin_op_mem_cu_dev_new(size_t nbatch, size_t neqn) +gkyl_dg_bin_op_mem *gkyl_dg_bin_op_mem_cu_dev_new(size_t nbatch, size_t neqn) { struct gkyl_dg_bin_op_mem *mem = gkyl_malloc(sizeof(struct gkyl_dg_bin_op_mem)); mem->on_gpu = false; mem->batch_sz = nbatch; mem->ncols = mem->nrows = neqn; - + mem->As = gkyl_nmat_cu_dev_new(nbatch, neqn, neqn); mem->xs = gkyl_nmat_cu_dev_new(nbatch, neqn, 1); mem->lu_mem = gkyl_nmat_linsolve_lu_cu_dev_new(mem->As->num, mem->As->nr); @@ -39,25 +37,24 @@ gkyl_dg_bin_op_mem_cu_dev_new(size_t nbatch, size_t neqn) return mem; } -void -gkyl_dg_bin_op_mem_release(gkyl_dg_bin_op_mem *mem) +void gkyl_dg_bin_op_mem_release(gkyl_dg_bin_op_mem *mem) { gkyl_nmat_release(mem->As); gkyl_nmat_release(mem->xs); gkyl_nmat_linsolve_lu_release(mem->lu_mem); - - if (mem->on_gpu) + + if (mem->on_gpu) { gkyl_cu_free(mem); - else + } else { gkyl_free(mem); + } } // multiplication -void -gkyl_dg_mul_op(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop) +void gkyl_dg_mul_op( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_lop, + const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -70,33 +67,33 @@ gkyl_dg_mul_op(const struct gkyl_basis *basis, int poly_order = basis->poly_order; mul_op_t mul_op; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - mul_op = choose_ser_mul_kern(ndim, poly_order); - break; - case GKYL_BASIS_MODAL_TENSOR: - mul_op = choose_ten_mul_kern(ndim, poly_order); - - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + mul_op = choose_ser_mul_kern(ndim, poly_order); + break; + case GKYL_BASIS_MODAL_TENSOR: + mul_op = choose_ten_mul_kern(ndim, poly_order); - default: - assert(false); - break; + break; + + default: + assert(false); + break; } - for (size_t i=0; isize; ++i) { - + for (size_t i = 0; i < out->size; ++i) { const double *lop_d = gkyl_array_cfetch(lop, i); const double *rop_d = gkyl_array_cfetch(rop, i); double *out_d = gkyl_array_fetch(out, i); - mul_op(lop_d+c_lop*num_basis, rop_d+c_rop*num_basis, out_d+c_oop*num_basis); + mul_op(lop_d + c_lop * num_basis, rop_d + c_rop * num_basis, out_d + c_oop * num_basis); } } -void gkyl_dg_mul_op_range(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop, const struct gkyl_range *range) +void gkyl_dg_mul_op_range( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_lop, + const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop, + const struct gkyl_range *range +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -109,17 +106,17 @@ void gkyl_dg_mul_op_range(const struct gkyl_basis *basis, int poly_order = basis->poly_order; mul_op_t mul_op; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - mul_op = choose_ser_mul_kern(ndim, poly_order); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + mul_op = choose_ser_mul_kern(ndim, poly_order); + break; - case GKYL_BASIS_MODAL_TENSOR: - mul_op = choose_ten_mul_kern(ndim, poly_order); - break; + case GKYL_BASIS_MODAL_TENSOR: + mul_op = choose_ten_mul_kern(ndim, poly_order); + break; - default: - assert(false); - break; + default: + assert(false); + break; } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, range); @@ -131,16 +128,15 @@ void gkyl_dg_mul_op_range(const struct gkyl_basis *basis, const double *rop_d = gkyl_array_cfetch(rop, loc); double *out_d = gkyl_array_fetch(out, loc); - mul_op(lop_d+c_lop*num_basis, rop_d+c_rop*num_basis, out_d+c_oop*num_basis); + mul_op(lop_d + c_lop * num_basis, rop_d + c_rop * num_basis, out_d + c_oop * num_basis); } } // Dot product. -void -gkyl_dg_dot_product_op(const struct gkyl_basis *basis, - struct gkyl_array* out, - const struct gkyl_array* lop, - const struct gkyl_array* rop) +void gkyl_dg_dot_product_op( + const struct gkyl_basis *basis, struct gkyl_array *out, const struct gkyl_array *lop, + const struct gkyl_array *rop +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -152,43 +148,46 @@ gkyl_dg_dot_product_op(const struct gkyl_basis *basis, int poly_order = basis->poly_order; mul_op_t mul_op; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - mul_op = choose_ser_mul_kern(ndim, poly_order); + case GKYL_BASIS_MODAL_SERENDIPITY: + mul_op = choose_ser_mul_kern(ndim, poly_order); + + break; - break; + case GKYL_BASIS_MODAL_TENSOR: + mul_op = choose_ten_mul_kern(ndim, poly_order); - case GKYL_BASIS_MODAL_TENSOR: - mul_op = choose_ten_mul_kern(ndim, poly_order); - - break; + break; - default: - assert(false); - break; + default: + assert(false); + break; } int num_basis = basis->num_basis; - int vcomp = lop->ncomp/out->ncomp; + int vcomp = lop->ncomp / out->ncomp; - for (size_t i=0; isize; ++i) { - + for (size_t i = 0; i < out->size; ++i) { const double *lop_d = gkyl_array_cfetch(lop, i); const double *rop_d = gkyl_array_cfetch(rop, i); double *out_d = gkyl_array_fetch(out, i); - for (int k=0; kpoly_order; mul_op_t mul_op; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - mul_op = choose_ser_mul_kern(ndim, poly_order); + case GKYL_BASIS_MODAL_SERENDIPITY: + mul_op = choose_ser_mul_kern(ndim, poly_order); + + break; - break; + case GKYL_BASIS_MODAL_TENSOR: + mul_op = choose_ten_mul_kern(ndim, poly_order); - case GKYL_BASIS_MODAL_TENSOR: - mul_op = choose_ten_mul_kern(ndim, poly_order); - - break; + break; - default: - assert(false); - break; + default: + assert(false); + break; } int num_basis = basis->num_basis; - int vcomp = lop->ncomp/out->ncomp; + int vcomp = lop->ncomp / out->ncomp; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, range); @@ -226,21 +225,26 @@ void gkyl_dg_dot_product_op_range(const struct gkyl_basis *basis, const double *lop_d = gkyl_array_cfetch(lop, loc); const double *rop_d = gkyl_array_cfetch(rop, loc); double *out_d = gkyl_array_fetch(out, loc); - for (int k=0; kndim; int vdim = pbasis->ndim - cdim; int poly_order = cbasis->poly_order; - mul_accumulate_op_t mul_accumulate_op = choose_mul_conf_phase_accumulate_kern(pbasis->b_type, cdim, vdim, poly_order); + mul_accumulate_op_t mul_accumulate_op = + choose_mul_conf_phase_accumulate_kern(pbasis->b_type, cdim, vdim, poly_order); struct gkyl_range_iter piter; gkyl_range_iter_init(&piter, prange); @@ -304,8 +313,10 @@ void gkyl_dg_mul_conf_phase_op_accumulate_range(const struct gkyl_basis *cbasis, const double *pop_d = gkyl_array_cfetch(pop, ploc); double *pout_d = gkyl_array_fetch(pout, ploc); - int cidx[3]; - for (int d=0; dpoly_order; div_set_op_t div_set_op; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - div_set_op = choose_ser_div_set_kern(ndim, poly_order); + case GKYL_BASIS_MODAL_SERENDIPITY: + div_set_op = choose_ser_div_set_kern(ndim, poly_order); + + break; - break; + case GKYL_BASIS_MODAL_TENSOR: + div_set_op = choose_ten_div_set_kern(ndim, poly_order); - case GKYL_BASIS_MODAL_TENSOR: - div_set_op = choose_ten_div_set_kern(ndim, poly_order); - - break; + break; - default: - assert(false); - break; + default: + assert(false); + break; } struct gkyl_nmat *As = mem->As; struct gkyl_nmat *xs = mem->xs; - for (size_t i=0; isize; ++i) { - + for (size_t i = 0; i < out->size; ++i) { const double *lop_d = gkyl_array_cfetch(lop, i); const double *rop_d = gkyl_array_cfetch(rop, i); struct gkyl_mat A = gkyl_nmat_get(As, i); struct gkyl_mat x = gkyl_nmat_get(xs, i); - gkyl_mat_clear(&A, 0.0); gkyl_mat_clear(&x, 0.0); - div_set_op(&A, &x, lop_d+c_lop*num_basis, rop_d+c_rop*num_basis); + gkyl_mat_clear(&A, 0.0); + gkyl_mat_clear(&x, 0.0); + div_set_op(&A, &x, lop_d + c_lop * num_basis, rop_d + c_rop * num_basis); } bool status = gkyl_nmat_linsolve_lu_pa(mem->lu_mem, As, xs); assert(status); - for (size_t i=0; isize; ++i) { + for (size_t i = 0; i < out->size; ++i) { double *out_d = gkyl_array_fetch(out, i); struct gkyl_mat x = gkyl_nmat_get(xs, i); - binop_div_copy_sol(&x, out_d+c_oop*num_basis); + binop_div_copy_sol(&x, out_d + c_oop * num_basis); } } -void gkyl_dg_div_op_range(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop, const struct gkyl_range *range) +void gkyl_dg_div_op_range( + gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, + int c_lop, const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop, + const struct gkyl_range *range +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -386,19 +397,19 @@ void gkyl_dg_div_op_range(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basi int poly_order = basis->poly_order; div_set_op_t div_set_op; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - div_set_op = choose_ser_div_set_kern(ndim, poly_order); + case GKYL_BASIS_MODAL_SERENDIPITY: + div_set_op = choose_ser_div_set_kern(ndim, poly_order); - break; + break; - case GKYL_BASIS_MODAL_TENSOR: - div_set_op = choose_ten_div_set_kern(ndim, poly_order); - - break; + case GKYL_BASIS_MODAL_TENSOR: + div_set_op = choose_ten_div_set_kern(ndim, poly_order); - default: - assert(false); - break; + break; + + default: + assert(false); + break; } // allocate memory for use in kernels @@ -416,9 +427,10 @@ void gkyl_dg_div_op_range(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basi struct gkyl_mat A = gkyl_nmat_get(As, count); struct gkyl_mat x = gkyl_nmat_get(xs, count); - gkyl_mat_clear(&A, 0.0); gkyl_mat_clear(&x, 0.0); + gkyl_mat_clear(&A, 0.0); + gkyl_mat_clear(&x, 0.0); - div_set_op(&A, &x, lop_d+c_lop*num_basis, rop_d+c_rop*num_basis); + div_set_op(&A, &x, lop_d + c_lop * num_basis, rop_d + c_rop * num_basis); count += 1; } @@ -433,14 +445,16 @@ void gkyl_dg_div_op_range(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basi double *out_d = gkyl_array_fetch(out, loc); struct gkyl_mat x = gkyl_nmat_get(xs, count); - binop_div_copy_sol(&x, out_d+c_oop*num_basis); + binop_div_copy_sol(&x, out_d + c_oop * num_basis); count += 1; } } -void gkyl_dg_inv_op(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, int c_iop, const struct gkyl_array* iop) +void gkyl_dg_inv_op( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -453,27 +467,28 @@ void gkyl_dg_inv_op(const struct gkyl_basis *basis, int poly_order = basis->poly_order; inv_op_t inv_op; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - inv_op = choose_ser_inv_kern(ndim, poly_order); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + inv_op = choose_ser_inv_kern(ndim, poly_order); + break; - default: - assert(false); - break; + default: + assert(false); + break; } assert(inv_op); - for (size_t i=0; isize; ++i) { + for (size_t i = 0; i < out->size; ++i) { const double *iop_d = gkyl_array_cfetch(iop, i); double *out_d = gkyl_array_fetch(out, i); - inv_op(iop_d+c_iop*num_basis, out_d+c_oop*num_basis); + inv_op(iop_d + c_iop * num_basis, out_d + c_oop * num_basis); } } -void gkyl_dg_inv_op_range(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, int c_iop, const struct gkyl_array* iop, - const struct gkyl_range *range) +void gkyl_dg_inv_op_range( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, const struct gkyl_range *range +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -486,13 +501,13 @@ void gkyl_dg_inv_op_range(const struct gkyl_basis *basis, int poly_order = basis->poly_order; inv_op_t inv_op; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - inv_op = choose_ser_inv_kern(ndim, poly_order); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + inv_op = choose_ser_inv_kern(ndim, poly_order); + break; - default: - assert(false); - break; + default: + assert(false); + break; } assert(inv_op); @@ -505,28 +520,28 @@ void gkyl_dg_inv_op_range(const struct gkyl_basis *basis, const double *iop_d = gkyl_array_cfetch(iop, loc); double *out_d = gkyl_array_fetch(out, loc); - inv_op(iop_d+c_iop*num_basis, out_d+c_oop*num_basis); + inv_op(iop_d + c_iop * num_basis, out_d + c_oop * num_basis); } } -void -gkyl_dg_calc_op_range(const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, - int c_iop, const struct gkyl_array *iop, - struct gkyl_range range, enum gkyl_dg_op op) +void gkyl_dg_calc_op_range( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, struct gkyl_range range, enum gkyl_dg_op op +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { return gkyl_dg_calc_op_range_cu(basis, c_oop, out, c_iop, iop, range, op); } #endif - + int num_basis = basis->num_basis; int ndim = basis->ndim; int poly_order = basis->poly_order; dp_op_t op_func = dg_get_op_func(op); double fact = // factor for rescaling return value of op_func - op == GKYL_DG_OP_MEAN ? sqrt(pow(2,ndim)) : pow(2,ndim); + op == GKYL_DG_OP_MEAN ? sqrt(pow(2, ndim)) : pow(2, ndim); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); @@ -537,23 +552,22 @@ gkyl_dg_calc_op_range(const struct gkyl_basis *basis, int c_oop, struct gkyl_arr const double *iop_d = gkyl_array_cfetch(iop, loc); double *out_d = gkyl_array_fetch(out, loc); - out_d[c_oop] = - op_func(num_basis, iop_d+c_iop*num_basis)/fact; - } + out_d[c_oop] = op_func(num_basis, iop_d + c_iop * num_basis) / fact; + } } -void -gkyl_dg_calc_average_range(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_iop, const struct gkyl_array* iop, struct gkyl_range range) +void gkyl_dg_calc_average_range( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, struct gkyl_range range +) { gkyl_dg_calc_op_range(basis, c_oop, out, c_iop, iop, range, GKYL_DG_OP_MEAN); } -void -gkyl_dg_calc_l2_range(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_iop, const struct gkyl_array* iop, struct gkyl_range range) +void gkyl_dg_calc_l2_range( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, struct gkyl_range range +) { gkyl_dg_calc_op_range(basis, c_oop, out, c_iop, iop, range, GKYL_DG_OP_MEAN_L2); } \ No newline at end of file diff --git a/core/zero/dg_bin_ops_cu.cu b/core/zero/dg_bin_ops_cu.cu index 4676c8a52d..6ad0d90235 100644 --- a/core/zero/dg_bin_ops_cu.cu +++ b/core/zero/dg_bin_ops_cu.cu @@ -13,45 +13,42 @@ extern "C" { } // start ID for use in various loops -#define START_ID (threadIdx.x + blockIdx.x*blockDim.x) +#define START_ID (threadIdx.x + blockIdx.x * blockDim.x) -__global__ void -gkyl_dg_mul_op_cu_kernel(struct gkyl_basis basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop) +__global__ void gkyl_dg_mul_op_cu_kernel( + struct gkyl_basis basis, int c_oop, struct gkyl_array *out, int c_lop, + const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop +) { int num_basis = basis.num_basis; int ndim = basis.ndim; int poly_order = basis.poly_order; mul_op_t mul_op = choose_ser_mul_kern(ndim, poly_order); - for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x*gridDim.x) { - - const double *lop_d = (const double*) gkyl_array_cfetch(lop, linc); - const double *rop_d = (const double*) gkyl_array_cfetch(rop, linc); - double *out_d = (double*) gkyl_array_fetch(out, linc); + for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x * gridDim.x) { + const double *lop_d = (const double *)gkyl_array_cfetch(lop, linc); + const double *rop_d = (const double *)gkyl_array_cfetch(rop, linc); + double *out_d = (double *)gkyl_array_fetch(out, linc); - mul_op(lop_d+c_lop*num_basis, rop_d+c_rop*num_basis, out_d+c_oop*num_basis); - } + mul_op(lop_d + c_lop * num_basis, rop_d + c_rop * num_basis, out_d + c_oop * num_basis); + } } // Host-side wrapper for dg multiplication operation -void -gkyl_dg_mul_op_cu(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop) +void gkyl_dg_mul_op_cu( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_lop, + const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop +) { - gkyl_dg_mul_op_cu_kernel<<nblocks, out->nthreads>>>(*basis, c_oop, out->on_dev, - c_lop, lop->on_dev, c_rop, rop->on_dev); + gkyl_dg_mul_op_cu_kernel<<nblocks, out->nthreads> > >( + *basis, c_oop, out->on_dev, c_lop, lop->on_dev, c_rop, rop->on_dev + ); } -__global__ void -gkyl_dg_mul_op_range_cu_kernel(struct gkyl_basis basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop, struct gkyl_range range) +__global__ void gkyl_dg_mul_op_range_cu_kernel( + struct gkyl_basis basis, int c_oop, struct gkyl_array *out, int c_lop, + const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop, struct gkyl_range range +) { int num_basis = basis.num_basis; int ndim = basis.ndim; @@ -60,10 +57,8 @@ gkyl_dg_mul_op_range_cu_kernel(struct gkyl_basis basis, int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -73,32 +68,33 @@ gkyl_dg_mul_op_range_cu_kernel(struct gkyl_basis basis, // linc will have jumps in it to jump over ghost cells long start = gkyl_range_idx(&range, idx); - const double *lop_d = (const double*) gkyl_array_cfetch(lop, start); - const double *rop_d = (const double*) gkyl_array_cfetch(rop, start); - double *out_d = (double*) gkyl_array_fetch(out, start); + const double *lop_d = (const double *)gkyl_array_cfetch(lop, start); + const double *rop_d = (const double *)gkyl_array_cfetch(rop, start); + double *out_d = (double *)gkyl_array_fetch(out, start); - mul_op(lop_d+c_lop*num_basis, rop_d+c_rop*num_basis, out_d+c_oop*num_basis); + mul_op(lop_d + c_lop * num_basis, rop_d + c_rop * num_basis, out_d + c_oop * num_basis); } } // Host-side wrapper for range-based dg multiplication operation -void -gkyl_dg_mul_op_range_cu(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop, const struct gkyl_range *range) +void gkyl_dg_mul_op_range_cu( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_lop, + const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop, + const struct gkyl_range *range +) { int nblocks = range->nblocks; int nthreads = range->nthreads; - gkyl_dg_mul_op_range_cu_kernel<<>>(*basis, c_oop, out->on_dev, - c_lop, lop->on_dev, c_rop, rop->on_dev, *range); + gkyl_dg_mul_op_range_cu_kernel<< > >( + *basis, c_oop, out->on_dev, c_lop, lop->on_dev, c_rop, rop->on_dev, *range + ); } -__global__ void -gkyl_dg_mul_conf_phase_op_range_cu_kernel(struct gkyl_basis cbasis, - struct gkyl_basis pbasis, struct gkyl_array* pout, - const struct gkyl_array* cop, const struct gkyl_array* pop, - struct gkyl_range crange, struct gkyl_range prange) +__global__ void gkyl_dg_mul_conf_phase_op_range_cu_kernel( + struct gkyl_basis cbasis, struct gkyl_basis pbasis, struct gkyl_array *pout, + const struct gkyl_array *cop, const struct gkyl_array *pop, struct gkyl_range crange, + struct gkyl_range prange +) { int cdim = cbasis.ndim; int vdim = pbasis.ndim - cdim; @@ -107,10 +103,8 @@ gkyl_dg_mul_conf_phase_op_range_cu_kernel(struct gkyl_basis cbasis, int pidx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < prange.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < prange.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -120,61 +114,63 @@ gkyl_dg_mul_conf_phase_op_range_cu_kernel(struct gkyl_basis cbasis, // linc will have jumps in it to jump over ghost cells long start = gkyl_range_idx(&prange, pidx); - const double *pop_d = (const double*) gkyl_array_cfetch(pop, start); - double *pout_d = (double*) gkyl_array_fetch(pout, start); + const double *pop_d = (const double *)gkyl_array_cfetch(pop, start); + double *pout_d = (double *)gkyl_array_fetch(pout, start); int cidx[3]; - for (int d=0; dnblocks; int nthreads = prange->nthreads; - gkyl_dg_mul_conf_phase_op_range_cu_kernel<<>>(*cbasis, *pbasis, - pout->on_dev, cop->on_dev, pop->on_dev, *crange, *prange); + gkyl_dg_mul_conf_phase_op_range_cu_kernel<< > >( + *cbasis, *pbasis, pout->on_dev, cop->on_dev, pop->on_dev, *crange, *prange + ); } -static void -gkyl_parallelize_components_kernel_launch_dims(dim3* dimGrid, dim3* dimBlock, gkyl_range range, int ncomp) +static void gkyl_parallelize_components_kernel_launch_dims( + dim3 *dimGrid, dim3 *dimBlock, gkyl_range range, int ncomp +) { - // Create a 2D thread grid so we launch ncomp*range.volume number of threads + // Create a 2D thread grid so we launch ncomp*range.volume number of threads // so we can parallelize over components too dimBlock->y = ncomp; // ncomp *must* be less than 256 dimGrid->y = 1; - dimBlock->x = GKYL_DEFAULT_NUM_THREADS/ncomp; + dimBlock->x = GKYL_DEFAULT_NUM_THREADS / ncomp; dimGrid->x = gkyl_int_div_up(range.volume, dimBlock->x); } -__global__ void -gkyl_dg_mul_conf_phase_op_accumulate_range_cu_kernel(struct gkyl_basis cbasis, - struct gkyl_basis pbasis, struct gkyl_array* pout, double a, - const struct gkyl_array* cop, const struct gkyl_array* pop, - struct gkyl_range crange, struct gkyl_range prange) +__global__ void gkyl_dg_mul_conf_phase_op_accumulate_range_cu_kernel( + struct gkyl_basis cbasis, struct gkyl_basis pbasis, struct gkyl_array *pout, double a, + const struct gkyl_array *cop, const struct gkyl_array *pop, struct gkyl_range crange, + struct gkyl_range prange +) { int cdim = cbasis.ndim; int vdim = pbasis.ndim - cdim; int poly_order = cbasis.poly_order; // On GPU, choose kernels which parallelize over components - mul_accumulate_comp_par_op_t mul_accumulate_op = choose_mul_conf_phase_accumulate_comp_par_kern(pbasis.b_type, - cdim, vdim, poly_order); + mul_accumulate_comp_par_op_t mul_accumulate_op = + choose_mul_conf_phase_accumulate_comp_par_kern(pbasis.b_type, cdim, vdim, poly_order); int pidx[GKYL_MAX_DIM]; - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < prange.volume; - linc1 += gridDim.x*blockDim.x) - { + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < prange.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -184,88 +180,93 @@ gkyl_dg_mul_conf_phase_op_accumulate_range_cu_kernel(struct gkyl_basis cbasis, // linc will have jumps in it to jump over ghost cells long start = gkyl_range_idx(&prange, pidx); - const double *pop_d = (const double*) gkyl_array_cfetch(pop, start); - double *pout_d = (double*) gkyl_array_fetch(pout, start); + const double *pop_d = (const double *)gkyl_array_cfetch(pop, start); + double *pout_d = (double *)gkyl_array_fetch(pout, start); int cidx[3]; - for (int d=0; dnum_basis; gkyl_parallelize_components_kernel_launch_dims(&dimGrid, &dimBlock, *prange, num_phase_basis); - gkyl_dg_mul_conf_phase_op_accumulate_range_cu_kernel<<>>(*cbasis, *pbasis, - pout->on_dev, a, cop->on_dev, pop->on_dev, *crange, *prange); + gkyl_dg_mul_conf_phase_op_accumulate_range_cu_kernel<< > >( + *cbasis, *pbasis, pout->on_dev, a, cop->on_dev, pop->on_dev, *crange, *prange + ); } -__global__ void -gkyl_dg_dot_product_op_cu_kernel(struct gkyl_basis basis, - struct gkyl_array* out, const struct gkyl_array* lop, - const struct gkyl_array* rop) +__global__ void gkyl_dg_dot_product_op_cu_kernel( + struct gkyl_basis basis, struct gkyl_array *out, const struct gkyl_array *lop, + const struct gkyl_array *rop +) { int ndim = basis.ndim; int poly_order = basis.poly_order; mul_op_t mul_op = choose_ser_mul_kern(ndim, poly_order); int num_basis = basis.num_basis; - int vcomp = lop->ncomp/out->ncomp; - - for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x*gridDim.x) { - - const double *lop_d = (const double*) gkyl_array_cfetch(lop, linc); - const double *rop_d = (const double*) gkyl_array_cfetch(rop, linc); - double *out_d = (double*) gkyl_array_fetch(out, linc); - for (int k=0; kncomp / out->ncomp; + + for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x * gridDim.x) { + const double *lop_d = (const double *)gkyl_array_cfetch(lop, linc); + const double *rop_d = (const double *)gkyl_array_cfetch(rop, linc); + double *out_d = (double *)gkyl_array_fetch(out, linc); + for (int k = 0; k < num_basis; k++) { + out_d[k] = 0.; } - } + + for (int d = 0; d < vcomp; d++) { + double comp_out[20]; // MF 2022/09/08: Hardcoded to number of basis in 3x p=2. + mul_op(lop_d + d * num_basis, rop_d + d * num_basis, comp_out); + for (int k = 0; k < num_basis; k++) { + out_d[k] += comp_out[k]; + } + } + } } // Host-side wrapper for dg dot product operation. -void -gkyl_dg_dot_product_op_cu(const struct gkyl_basis *basis, - struct gkyl_array* out, const struct gkyl_array* lop, - const struct gkyl_array* rop) +void gkyl_dg_dot_product_op_cu( + const struct gkyl_basis *basis, struct gkyl_array *out, const struct gkyl_array *lop, + const struct gkyl_array *rop +) { assert(basis->num_basis <= 20); // MF 2022/09/08: see hardcode in kernel above. - gkyl_dg_dot_product_op_cu_kernel<<nblocks, out->nthreads>>>(*basis, out->on_dev, - lop->on_dev, rop->on_dev); + gkyl_dg_dot_product_op_cu_kernel<<nblocks, out->nthreads> > >( + *basis, out->on_dev, lop->on_dev, rop->on_dev + ); } -__global__ void -gkyl_dg_dot_product_op_range_cu_kernel(struct gkyl_basis basis, - struct gkyl_array* out, const struct gkyl_array* lop, - const struct gkyl_array* rop, struct gkyl_range range) +__global__ void gkyl_dg_dot_product_op_range_cu_kernel( + struct gkyl_basis basis, struct gkyl_array *out, const struct gkyl_array *lop, + const struct gkyl_array *rop, struct gkyl_range range +) { int ndim = basis.ndim; int poly_order = basis.poly_order; mul_op_t mul_op = choose_ser_mul_kern(ndim, poly_order); int num_basis = basis.num_basis; - int vcomp = lop->ncomp/out->ncomp; + int vcomp = lop->ncomp / out->ncomp; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -275,95 +276,99 @@ gkyl_dg_dot_product_op_range_cu_kernel(struct gkyl_basis basis, // linc will have jumps in it to jump over ghost cells long start = gkyl_range_idx(&range, idx); - const double *lop_d = (const double*) gkyl_array_cfetch(lop, start); - const double *rop_d = (const double*) gkyl_array_cfetch(rop, start); - double *out_d = (double*) gkyl_array_fetch(out, start); - for (int k=0; knblocks; int nthreads = range->nthreads; assert(basis->num_basis <= 20); // MF 2022/09/08: see hardcode in kernel above. - gkyl_dg_dot_product_op_range_cu_kernel<<>>(*basis, out->on_dev, - lop->on_dev, rop->on_dev, *range); + gkyl_dg_dot_product_op_range_cu_kernel<< > >( + *basis, out->on_dev, lop->on_dev, rop->on_dev, *range + ); } -__global__ void -gkyl_dg_div_set_op_cu_kernel(struct gkyl_nmat *As, struct gkyl_nmat *xs, - struct gkyl_basis basis, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop) +__global__ void gkyl_dg_div_set_op_cu_kernel( + struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_basis basis, struct gkyl_array *out, + int c_lop, const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop +) { int num_basis = basis.num_basis; int ndim = basis.ndim; int poly_order = basis.poly_order; div_set_op_t div_set_op = choose_ser_div_set_kern(ndim, poly_order); - for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x*gridDim.x) { - - const double *lop_d = (const double*) gkyl_array_cfetch(lop, linc); - const double *rop_d = (const double*) gkyl_array_cfetch(rop, linc); + for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x * gridDim.x) { + const double *lop_d = (const double *)gkyl_array_cfetch(lop, linc); + const double *rop_d = (const double *)gkyl_array_cfetch(rop, linc); struct gkyl_mat A = gkyl_nmat_get(As, linc); struct gkyl_mat x = gkyl_nmat_get(xs, linc); - gkyl_mat_clear(&A, 0.0); gkyl_mat_clear(&x, 0.0); - div_set_op(&A, &x, lop_d+c_lop*num_basis, rop_d+c_rop*num_basis); + gkyl_mat_clear(&A, 0.0); + gkyl_mat_clear(&x, 0.0); + div_set_op(&A, &x, lop_d + c_lop * num_basis, rop_d + c_rop * num_basis); } } -__global__ void -gkyl_dg_div_copy_sol_op_cu_kernel(struct gkyl_nmat *xs, - struct gkyl_basis basis, - int c_oop, struct gkyl_array* out) +__global__ void gkyl_dg_div_copy_sol_op_cu_kernel( + struct gkyl_nmat *xs, struct gkyl_basis basis, int c_oop, struct gkyl_array *out +) { int num_basis = basis.num_basis; - for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x*gridDim.x) { - double *out_d = (double*) gkyl_array_fetch(out, linc); + for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x * gridDim.x) { + double *out_d = (double *)gkyl_array_fetch(out, linc); struct gkyl_mat x = gkyl_nmat_get(xs, linc); - binop_div_copy_sol(&x, out_d+c_oop*num_basis); - } + binop_div_copy_sol(&x, out_d + c_oop * num_basis); + } } // Host-side wrapper for dg division operation -void -gkyl_dg_div_op_cu(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop) +void gkyl_dg_div_op_cu( + gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, + int c_lop, const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop +) { // allocate memory for use in kernels struct gkyl_nmat *A_d = mem->As; struct gkyl_nmat *x_d = mem->xs; // construct matrices using CUDA kernel - gkyl_dg_div_set_op_cu_kernel<<nblocks, out->nthreads>>>(A_d->on_dev, x_d->on_dev, - *basis, out->on_dev, c_lop, lop->on_dev, c_rop, rop->on_dev); + gkyl_dg_div_set_op_cu_kernel<<nblocks, out->nthreads> > >( + A_d->on_dev, x_d->on_dev, *basis, out->on_dev, c_lop, lop->on_dev, c_rop, rop->on_dev + ); // invert all matrices in batch mode bool status = gkyl_nmat_linsolve_lu_pa(mem->lu_mem, A_d, x_d); assert(status); // copy solution into array (also lives on the device) - gkyl_dg_div_copy_sol_op_cu_kernel<<nblocks, out->nthreads>>>(x_d->on_dev, *basis, c_oop, out->on_dev); - + gkyl_dg_div_copy_sol_op_cu_kernel<<nblocks, out->nthreads> > >( + x_d->on_dev, *basis, c_oop, out->on_dev + ); } -__global__ void -gkyl_dg_div_set_op_range_cu_kernel(struct gkyl_nmat *As, struct gkyl_nmat *xs, - struct gkyl_basis basis, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop, struct gkyl_range range) +__global__ void gkyl_dg_div_set_op_range_cu_kernel( + struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_basis basis, struct gkyl_array *out, + int c_lop, const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop, + struct gkyl_range range +) { int num_basis = basis.num_basis; int ndim = basis.ndim; @@ -372,10 +377,8 @@ gkyl_dg_div_set_op_range_cu_kernel(struct gkyl_nmat *As, struct gkyl_nmat *xs, int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -385,30 +388,29 @@ gkyl_dg_div_set_op_range_cu_kernel(struct gkyl_nmat *As, struct gkyl_nmat *xs, // linc will have jumps in it to jump over ghost cells long start = gkyl_range_idx(&range, idx); - const double *lop_d = (const double*) gkyl_array_cfetch(lop, start); - const double *rop_d = (const double*) gkyl_array_cfetch(rop, start); + const double *lop_d = (const double *)gkyl_array_cfetch(lop, start); + const double *rop_d = (const double *)gkyl_array_cfetch(rop, start); struct gkyl_mat A = gkyl_nmat_get(As, linc1); struct gkyl_mat x = gkyl_nmat_get(xs, linc1); - gkyl_mat_clear(&A, 0.0); gkyl_mat_clear(&x, 0.0); + gkyl_mat_clear(&A, 0.0); + gkyl_mat_clear(&x, 0.0); - div_set_op(&A, &x, lop_d+c_lop*num_basis, rop_d+c_rop*num_basis); + div_set_op(&A, &x, lop_d + c_lop * num_basis, rop_d + c_rop * num_basis); } } -__global__ void -gkyl_dg_div_copy_sol_op_range_cu_kernel(struct gkyl_nmat *xs, - struct gkyl_basis basis, - int c_oop, struct gkyl_array* out, struct gkyl_range range) +__global__ void gkyl_dg_div_copy_sol_op_range_cu_kernel( + struct gkyl_nmat *xs, struct gkyl_basis basis, int c_oop, struct gkyl_array *out, + struct gkyl_range range +) { int num_basis = basis.num_basis; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -418,20 +420,20 @@ gkyl_dg_div_copy_sol_op_range_cu_kernel(struct gkyl_nmat *xs, // linc will have jumps in it to jump over ghost cells long start = gkyl_range_idx(&range, idx); - double *out_d = (double*) gkyl_array_fetch(out, start); + double *out_d = (double *)gkyl_array_fetch(out, start); struct gkyl_mat x = gkyl_nmat_get(xs, linc1); - binop_div_copy_sol(&x, out_d+c_oop*num_basis); - } + binop_div_copy_sol(&x, out_d + c_oop * num_basis); + } } // Host-side wrapper for range-based dg division operation -void -gkyl_dg_div_op_range_cu(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop, const struct gkyl_range *range) +void gkyl_dg_div_op_range_cu( + gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, + int c_lop, const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop, + const struct gkyl_range *range +) { int nblocks = range->nblocks; int nthreads = range->nthreads; @@ -439,21 +441,23 @@ gkyl_dg_div_op_range_cu(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, struct gkyl_nmat *A_d = mem->As; struct gkyl_nmat *x_d = mem->xs; - // construct matrices using CUDA kernel - gkyl_dg_div_set_op_range_cu_kernel<<>>(A_d->on_dev, - x_d->on_dev, *basis, out->on_dev, c_lop, lop->on_dev, c_rop, rop->on_dev, *range); + // construct matrices using CUDA kernel + gkyl_dg_div_set_op_range_cu_kernel<< > >( + A_d->on_dev, x_d->on_dev, *basis, out->on_dev, c_lop, lop->on_dev, c_rop, rop->on_dev, *range + ); // invert all matrices in batch mode bool status = gkyl_nmat_linsolve_lu_pa(mem->lu_mem, A_d, x_d); assert(status); // copy solution into array (also lives on the device) - gkyl_dg_div_copy_sol_op_range_cu_kernel<<>>(x_d->on_dev, - *basis, c_oop, out->on_dev, *range); + gkyl_dg_div_copy_sol_op_range_cu_kernel<< > >( + x_d->on_dev, *basis, c_oop, out->on_dev, *range + ); } -__global__ void -gkyl_dg_inv_op_cu_kernel(struct gkyl_basis basis, - int c_oop, struct gkyl_array* out, - int c_iop, const struct gkyl_array* iop) +__global__ void gkyl_dg_inv_op_cu_kernel( + struct gkyl_basis basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop +) { int num_basis = basis.num_basis; int ndim = basis.ndim; @@ -461,28 +465,29 @@ gkyl_dg_inv_op_cu_kernel(struct gkyl_basis basis, inv_op_t inv_op = choose_ser_inv_kern(ndim, poly_order); assert(inv_op); - for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x*gridDim.x) { - const double *iop_d = (const double*) gkyl_array_cfetch(iop, linc); - double *out_d = (double*) gkyl_array_fetch(out, linc); + for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x * gridDim.x) { + const double *iop_d = (const double *)gkyl_array_cfetch(iop, linc); + double *out_d = (double *)gkyl_array_fetch(out, linc); - inv_op(iop_d+c_iop*num_basis, out_d+c_oop*num_basis); - } + inv_op(iop_d + c_iop * num_basis, out_d + c_oop * num_basis); + } } // Host-side wrapper for dg inversion operation. -void -gkyl_dg_inv_op_cu(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_iop, const struct gkyl_array* iop) +void gkyl_dg_inv_op_cu( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop +) { - gkyl_dg_inv_op_cu_kernel<<nblocks, out->nthreads>>>(*basis, c_oop, out->on_dev, - c_iop, iop->on_dev); + gkyl_dg_inv_op_cu_kernel<<nblocks, out->nthreads> > >( + *basis, c_oop, out->on_dev, c_iop, iop->on_dev + ); } -__global__ void -gkyl_dg_inv_op_range_cu_kernel(struct gkyl_basis basis, - int c_oop, struct gkyl_array* out, - int c_iop, const struct gkyl_array* iop, struct gkyl_range range) +__global__ void gkyl_dg_inv_op_range_cu_kernel( + struct gkyl_basis basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, struct gkyl_range range +) { int num_basis = basis.num_basis; int ndim = basis.ndim; @@ -492,10 +497,8 @@ gkyl_dg_inv_op_range_cu_kernel(struct gkyl_basis basis, int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -505,43 +508,42 @@ gkyl_dg_inv_op_range_cu_kernel(struct gkyl_basis basis, // linc will have jumps in it to jump over ghost cells long start = gkyl_range_idx(&range, idx); - const double *iop_d = (const double*) gkyl_array_cfetch(iop, start); - double *out_d = (double*) gkyl_array_fetch(out, start); + const double *iop_d = (const double *)gkyl_array_cfetch(iop, start); + double *out_d = (double *)gkyl_array_fetch(out, start); - inv_op(iop_d+c_iop*num_basis, out_d+c_oop*num_basis); + inv_op(iop_d + c_iop * num_basis, out_d + c_oop * num_basis); } } // Host-side wrapper for range-based dg invtiplication operation -void -gkyl_dg_inv_op_range_cu(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_iop, const struct gkyl_array* iop, const struct gkyl_range *range) +void gkyl_dg_inv_op_range_cu( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, const struct gkyl_range *range +) { int nblocks = range->nblocks; int nthreads = range->nthreads; - gkyl_dg_inv_op_range_cu_kernel<<>>(*basis, c_oop, out->on_dev, - c_iop, iop->on_dev, *range); + gkyl_dg_inv_op_range_cu_kernel<< > >( + *basis, c_oop, out->on_dev, c_iop, iop->on_dev, *range + ); } -__global__ void -gkyl_dg_calc_op_range_cu_kernel(struct gkyl_basis basis, int c_oop, struct gkyl_array *out, - int c_iop, const struct gkyl_array *iop, - struct gkyl_range range, enum gkyl_dg_op op) +__global__ void gkyl_dg_calc_op_range_cu_kernel( + struct gkyl_basis basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, struct gkyl_range range, enum gkyl_dg_op op +) { int num_basis = basis.num_basis; int ndim = basis.ndim; dp_op_t op_func = dg_get_op_func(op); double fact = // factor for rescaling return value of op_func - op == GKYL_DG_OP_MEAN ? sqrt(pow(2,ndim)) : pow(2,ndim); + op == GKYL_DG_OP_MEAN ? sqrt(pow(2, ndim)) : pow(2, ndim); int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -551,19 +553,19 @@ gkyl_dg_calc_op_range_cu_kernel(struct gkyl_basis basis, int c_oop, struct gkyl_ // linc will have jumps in it to jump over ghost cells long start = gkyl_range_idx(&range, idx); - const double *iop_d = (const double*) gkyl_array_cfetch(iop, start); - double *out_d = (double*) gkyl_array_fetch(out, start); + const double *iop_d = (const double *)gkyl_array_cfetch(iop, start); + double *out_d = (double *)gkyl_array_fetch(out, start); - out_d[c_oop] = - op_func(num_basis, iop_d+c_iop*num_basis)/fact; + out_d[c_oop] = op_func(num_basis, iop_d + c_iop * num_basis) / fact; } } -void -gkyl_dg_calc_op_range_cu(const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, - int c_iop, const struct gkyl_array *iop, - struct gkyl_range range, enum gkyl_dg_op op) +void gkyl_dg_calc_op_range_cu( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, struct gkyl_range range, enum gkyl_dg_op op +) { - gkyl_dg_calc_op_range_cu_kernel<<nblocks, out->nthreads>>>(*basis, c_oop, out->on_dev, - c_iop, iop->on_dev, range, op); + gkyl_dg_calc_op_range_cu_kernel<<nblocks, out->nthreads> > >( + *basis, c_oop, out->on_dev, c_iop, iop->on_dev, range, op + ); } diff --git a/core/zero/dg_differentiate.c b/core/zero/dg_differentiate.c index d15095419f..4356e76b80 100644 --- a/core/zero/dg_differentiate.c +++ b/core/zero/dg_differentiate.c @@ -6,9 +6,10 @@ #include #include -void -gkyl_dg_differentiate_op_local(const struct gkyl_basis *basis, int dir, int diff_order, - double dx, int c_oop, struct gkyl_array *out, int c_iop, const struct gkyl_array *inp) +void gkyl_dg_differentiate_op_local( + const struct gkyl_basis *basis, int dir, int diff_order, double dx, int c_oop, + struct gkyl_array *out, int c_iop, const struct gkyl_array *inp +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -21,35 +22,37 @@ gkyl_dg_differentiate_op_local(const struct gkyl_basis *basis, int dir, int diff differentiate_op_t diff_op; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - diff_op = choose_ser_differentiate_kern(ndim, dir, poly_order, diff_order); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + diff_op = choose_ser_differentiate_kern(ndim, dir, poly_order, diff_order); + break; - case GKYL_BASIS_MODAL_TENSOR: - diff_op = choose_ten_differentiate_kern(ndim, dir, poly_order, diff_order); - break; + case GKYL_BASIS_MODAL_TENSOR: + diff_op = choose_ten_differentiate_kern(ndim, dir, poly_order, diff_order); + break; - default: - assert(false); - break; + default: + assert(false); + break; } assert(diff_op); - for (size_t i=0; isize; ++i) { + for (size_t i = 0; i < out->size; ++i) { const double *inp_d = gkyl_array_cfetch(inp, i); double *out_d = gkyl_array_fetch(out, i); - diff_op(dx, inp_d+c_iop*num_basis, out_d+c_oop*num_basis); + diff_op(dx, inp_d + c_iop * num_basis, out_d + c_oop * num_basis); } } -void -gkyl_dg_differentiate_op_local_range(const struct gkyl_basis *basis, int dir, int diff_order, - double dx, int c_oop, struct gkyl_array *out, int c_iop, const struct gkyl_array *inp, - const struct gkyl_range *range) +void gkyl_dg_differentiate_op_local_range( + const struct gkyl_basis *basis, int dir, int diff_order, double dx, int c_oop, + struct gkyl_array *out, int c_iop, const struct gkyl_array *inp, const struct gkyl_range *range +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { - return gkyl_dg_differentiate_op_local_range_cu(basis, dir, diff_order, dx, c_oop, out, c_iop, inp, range); + return gkyl_dg_differentiate_op_local_range_cu( + basis, dir, diff_order, dx, c_oop, out, c_iop, inp, range + ); } #endif int num_basis = basis->num_basis; @@ -58,17 +61,17 @@ gkyl_dg_differentiate_op_local_range(const struct gkyl_basis *basis, int dir, in differentiate_op_t diff_op; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - diff_op = choose_ser_differentiate_kern(ndim, dir, poly_order, diff_order); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + diff_op = choose_ser_differentiate_kern(ndim, dir, poly_order, diff_order); + break; - case GKYL_BASIS_MODAL_TENSOR: - diff_op = choose_ten_differentiate_kern(ndim, dir, poly_order, diff_order); - break; + case GKYL_BASIS_MODAL_TENSOR: + diff_op = choose_ten_differentiate_kern(ndim, dir, poly_order, diff_order); + break; - default: - assert(false); - break; + default: + assert(false); + break; } assert(diff_op); @@ -79,6 +82,6 @@ gkyl_dg_differentiate_op_local_range(const struct gkyl_basis *basis, int dir, in long loc = gkyl_range_idx(range, iter.idx); const double *inp_d = gkyl_array_cfetch(inp, loc); double *out_d = gkyl_array_fetch(out, loc); - diff_op(dx, inp_d+c_iop*num_basis, out_d+c_oop*num_basis); + diff_op(dx, inp_d + c_iop * num_basis, out_d + c_oop * num_basis); } } diff --git a/core/zero/dg_differentiate_cu.cu b/core/zero/dg_differentiate_cu.cu index 7a05c0ed88..77c93fb042 100644 --- a/core/zero/dg_differentiate_cu.cu +++ b/core/zero/dg_differentiate_cu.cu @@ -6,13 +6,14 @@ extern "C" { #include } -#define START_ID (threadIdx.x + blockIdx.x*blockDim.x) -// Compute size of 'arr' +#define START_ID (threadIdx.x + blockIdx.x * blockDim.x) +// Compute size of 'arr' #define NSIZE(arr) (arr->size) -__global__ void -gkyl_dg_differentiate_op_local_cu_kernel(struct gkyl_basis basis, int dir, int diff_order, - double dx, int c_oop, struct gkyl_array *out, int c_iop, const struct gkyl_array *inp) +__global__ void gkyl_dg_differentiate_op_local_cu_kernel( + struct gkyl_basis basis, int dir, int diff_order, double dx, int c_oop, struct gkyl_array *out, + int c_iop, const struct gkyl_array *inp +) { int num_basis = basis.num_basis; int ndim = basis.ndim; @@ -20,35 +21,37 @@ gkyl_dg_differentiate_op_local_cu_kernel(struct gkyl_basis basis, int dir, int d differentiate_op_t diff_op; switch (basis.b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - diff_op = choose_ser_differentiate_kern(ndim, dir, poly_order, diff_order); - break; - case GKYL_BASIS_MODAL_TENSOR: - diff_op = choose_ten_differentiate_kern(ndim, dir, poly_order, diff_order); - break; - default: - return; + case GKYL_BASIS_MODAL_SERENDIPITY: + diff_op = choose_ser_differentiate_kern(ndim, dir, poly_order, diff_order); + break; + case GKYL_BASIS_MODAL_TENSOR: + diff_op = choose_ten_differentiate_kern(ndim, dir, poly_order, diff_order); + break; + default: + return; } - for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x*gridDim.x) { - const double *inp_d = (const double *) gkyl_array_cfetch(inp, linc); - double *out_d = (double *) gkyl_array_fetch(out, linc); - diff_op(dx, inp_d+c_iop*num_basis, out_d+c_oop*num_basis); + for (unsigned long linc = START_ID; linc < NSIZE(out); linc += blockDim.x * gridDim.x) { + const double *inp_d = (const double *)gkyl_array_cfetch(inp, linc); + double *out_d = (double *)gkyl_array_fetch(out, linc); + diff_op(dx, inp_d + c_iop * num_basis, out_d + c_oop * num_basis); } } -void -gkyl_dg_differentiate_op_local_cu(const struct gkyl_basis *basis, int dir, int diff_order, - double dx, int c_oop, struct gkyl_array *out, int c_iop, const struct gkyl_array *inp) +void gkyl_dg_differentiate_op_local_cu( + const struct gkyl_basis *basis, int dir, int diff_order, double dx, int c_oop, + struct gkyl_array *out, int c_iop, const struct gkyl_array *inp +) { - gkyl_dg_differentiate_op_local_cu_kernel<<nblocks, out->nthreads>>>( - *basis, dir, diff_order, dx, c_oop, out->on_dev, c_iop, inp->on_dev); + gkyl_dg_differentiate_op_local_cu_kernel<<nblocks, out->nthreads> > >( + *basis, dir, diff_order, dx, c_oop, out->on_dev, c_iop, inp->on_dev + ); } -__global__ void -gkyl_dg_differentiate_op_local_range_cu_kernel(struct gkyl_basis basis, int dir, int diff_order, - double dx, int c_oop, struct gkyl_array *out, int c_iop, const struct gkyl_array *inp, - struct gkyl_range range) +__global__ void gkyl_dg_differentiate_op_local_range_cu_kernel( + struct gkyl_basis basis, int dir, int diff_order, double dx, int c_oop, struct gkyl_array *out, + int c_iop, const struct gkyl_array *inp, struct gkyl_range range +) { int num_basis = basis.num_basis; int ndim = basis.ndim; @@ -56,22 +59,20 @@ gkyl_dg_differentiate_op_local_range_cu_kernel(struct gkyl_basis basis, int dir, differentiate_op_t diff_op; switch (basis.b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - diff_op = choose_ser_differentiate_kern(ndim, dir, poly_order, diff_order); - break; - case GKYL_BASIS_MODAL_TENSOR: - diff_op = choose_ten_differentiate_kern(ndim, dir, poly_order, diff_order); - break; - default: - return; + case GKYL_BASIS_MODAL_SERENDIPITY: + diff_op = choose_ser_differentiate_kern(ndim, dir, poly_order, diff_order); + break; + case GKYL_BASIS_MODAL_TENSOR: + diff_op = choose_ten_differentiate_kern(ndim, dir, poly_order, diff_order); + break; + default: + return; } int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -80,19 +81,20 @@ gkyl_dg_differentiate_op_local_range_cu_kernel(struct gkyl_basis basis, int dir, // convert back to a linear index on the super-range (with ghost cells) long start = gkyl_range_idx(&range, idx); - const double *inp_d = (const double *) gkyl_array_cfetch(inp, start); - double *out_d = (double *) gkyl_array_fetch(out, start); - diff_op(dx, inp_d+c_iop*num_basis, out_d+c_oop*num_basis); + const double *inp_d = (const double *)gkyl_array_cfetch(inp, start); + double *out_d = (double *)gkyl_array_fetch(out, start); + diff_op(dx, inp_d + c_iop * num_basis, out_d + c_oop * num_basis); } } -void -gkyl_dg_differentiate_op_local_range_cu(const struct gkyl_basis *basis, int dir, int diff_order, - double dx, int c_oop, struct gkyl_array *out, int c_iop, const struct gkyl_array *inp, - const struct gkyl_range *range) +void gkyl_dg_differentiate_op_local_range_cu( + const struct gkyl_basis *basis, int dir, int diff_order, double dx, int c_oop, + struct gkyl_array *out, int c_iop, const struct gkyl_array *inp, const struct gkyl_range *range +) { int nblocks = range->nblocks; int nthreads = range->nthreads; - gkyl_dg_differentiate_op_local_range_cu_kernel<<>>( - *basis, dir, diff_order, dx, c_oop, out->on_dev, c_iop, inp->on_dev, *range); + gkyl_dg_differentiate_op_local_range_cu_kernel<< > >( + *basis, dir, diff_order, dx, c_oop, out->on_dev, c_iop, inp->on_dev, *range + ); } diff --git a/core/zero/dg_eval_at_coord_proj.c b/core/zero/dg_eval_at_coord_proj.c index 02d8fd033f..ecf5da0107 100644 --- a/core/zero/dg_eval_at_coord_proj.c +++ b/core/zero/dg_eval_at_coord_proj.c @@ -5,9 +5,10 @@ #include #include -struct gkyl_dg_eval_at_coord_proj* -gkyl_dg_eval_at_coord_proj_new(int cdim_do, const struct gkyl_basis *basis_do, - int num_eval_dirs, const int *eval_dirs, bool use_gpu) +struct gkyl_dg_eval_at_coord_proj *gkyl_dg_eval_at_coord_proj_new( + int cdim_do, const struct gkyl_basis *basis_do, int num_eval_dirs, const int *eval_dirs, + bool use_gpu +) { int ndim_do = basis_do->ndim; int ndim_tar = ndim_do - num_eval_dirs; @@ -17,7 +18,7 @@ gkyl_dg_eval_at_coord_proj_new(int cdim_do, const struct gkyl_basis *basis_do, assert(ndim_tar == ndim_do - num_eval_dirs); assert(basis_do->poly_order >= 1 && basis_do->poly_order <= 3); - struct gkyl_dg_eval_at_coord_proj *up = gkyl_calloc(1,sizeof(*up)); + struct gkyl_dg_eval_at_coord_proj *up = gkyl_calloc(1, sizeof(*up)); up->use_gpu = use_gpu; up->ndim_do = ndim_do; @@ -25,30 +26,36 @@ gkyl_dg_eval_at_coord_proj_new(int cdim_do, const struct gkyl_basis *basis_do, up->num_basis_do = basis_do->num_basis; up->num_eval_dirs = num_eval_dirs; - for (int i=0; ieval_dirs[i] = eval_dirs[i]; + } - for (int d=0; dis_eval[d] = false; + } - for (int i=0; iis_eval[eval_dirs[i]] = true; + } - up->kers = dg_eval_at_coord_choose_ker(use_gpu, cdim_do, ndim_do, basis_do, num_eval_dirs, eval_dirs); + up->kers = + dg_eval_at_coord_choose_ker(use_gpu, cdim_do, ndim_do, basis_do, num_eval_dirs, eval_dirs); return up; } -void -gkyl_dg_eval_at_coord_proj_advance(struct gkyl_dg_eval_at_coord_proj *up, const double *eval_coords, +void gkyl_dg_eval_at_coord_proj_advance( + struct gkyl_dg_eval_at_coord_proj *up, const double *eval_coords, const struct gkyl_rect_grid *grid, const bool *pick_lower, const int *known_index, - const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, - const struct gkyl_array *fdo, struct gkyl_array *ftar) + const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, const struct gkyl_array *fdo, + struct gkyl_array *ftar +) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - gkyl_dg_eval_at_coord_proj_advance_cu(up, eval_coords, grid, pick_lower, known_index, - rng_do, rng_tar, fdo, ftar); + gkyl_dg_eval_at_coord_proj_advance_cu( + up, eval_coords, grid, pick_lower, known_index, rng_do, rng_tar, fdo, ftar + ); return; } #endif @@ -63,11 +70,12 @@ gkyl_dg_eval_at_coord_proj_advance(struct gkyl_dg_eval_at_coord_proj *up, const // center of the lowest cell in rng_do for that direction. double point[GKYL_MAX_DIM]; int eval_ctr = 0; - for (int d=0; dndim_do; d++) { - if (up->is_eval[d]) + for (int d = 0; d < up->ndim_do; d++) { + if (up->is_eval[d]) { point[d] = eval_coords[eval_ctr++]; - else + } else { point[d] = grid->lower[d] + (rng_do->lower[d] - 0.5) * grid->dx[d]; + } } int cell_idx[GKYL_MAX_DIM]; @@ -75,13 +83,13 @@ gkyl_dg_eval_at_coord_proj_advance(struct gkyl_dg_eval_at_coord_proj *up, const // Convert comp eval_coords to logical coords. double eval_coords_log[GKYL_MAX_DIM]; - for (int i=0; inum_eval_dirs; i++) { + for (int i = 0; i < up->num_eval_dirs; i++) { int d = up->eval_dirs[i]; double xc_d = grid->lower[d] + (cell_idx[d] - 0.5) * grid->dx[d]; eval_coords_log[i] = 2.0 * (eval_coords[i] - xc_d) / grid->dx[d]; // Force to be between -1 and 1, to account for floating point precision // causing results outside of [-1,1]. - eval_coords_log[i] = GKYL_MAX2(-1.0, GKYL_MIN2(eval_coords_log[i],1.0) ); + eval_coords_log[i] = GKYL_MAX2(-1.0, GKYL_MIN2(eval_coords_log[i], 1.0)); } int idx_do[GKYL_MAX_DIM] = {0}; @@ -97,26 +105,29 @@ gkyl_dg_eval_at_coord_proj_advance(struct gkyl_dg_eval_at_coord_proj *up, const const double *fdo_c = gkyl_array_cfetch(fdo, linidx_do); double *ftar_c = gkyl_array_fetch(ftar, linidx_tar); - for (int n=0; nkers->ev_ker(eval_coords_log, fdo_c+n*up->num_basis_do, ftar_c+n*num_basis_tar); + for (int n = 0; n < ncomp; n++) { + up->kers->ev_ker(eval_coords_log, fdo_c + n * up->num_basis_do, ftar_c + n * num_basis_tar); + } } } -void -gkyl_dg_eval_at_coord_proj_target_basis(struct gkyl_dg_eval_at_coord_proj *up, - int *cdim, int *ndim, enum gkyl_basis_type *btype, int *poly_order, int *num_basis) +void gkyl_dg_eval_at_coord_proj_target_basis( + struct gkyl_dg_eval_at_coord_proj *up, int *cdim, int *ndim, enum gkyl_basis_type *btype, + int *poly_order, int *num_basis +) { up->kers->basis_ker(cdim, ndim, btype, poly_order, num_basis); } -void -gkyl_dg_eval_at_coord_proj_release(struct gkyl_dg_eval_at_coord_proj *up) +void gkyl_dg_eval_at_coord_proj_release(struct gkyl_dg_eval_at_coord_proj *up) { - if (!up->use_gpu) + if (!up->use_gpu) { gkyl_free(up->kers); + } #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { gkyl_cu_free(up->kers); + } #endif gkyl_free(up); } diff --git a/core/zero/dg_eval_at_coord_proj_cu.cu b/core/zero/dg_eval_at_coord_proj_cu.cu index 333c4487c1..eb88917dff 100644 --- a/core/zero/dg_eval_at_coord_proj_cu.cu +++ b/core/zero/dg_eval_at_coord_proj_cu.cu @@ -7,9 +7,10 @@ extern "C" { #include } -__global__ void -dg_eval_at_coord_choose_ker_cu_ker(int cdim, int ndim, struct gkyl_basis basis, int num_eval_dirs, - dg_evproj_struct_int_t eval_dirs, struct dg_ev_proj_kernels *kers) +__global__ void dg_eval_at_coord_choose_ker_cu_ker( + int cdim, int ndim, struct gkyl_basis basis, int num_eval_dirs, dg_evproj_struct_int_t eval_dirs, + struct dg_ev_proj_kernels *kers +) { int dir_mask = eval_dirs_to_mask(num_eval_dirs, eval_dirs.c); @@ -20,77 +21,80 @@ dg_eval_at_coord_choose_ker_cu_ker(int cdim, int ndim, struct gkyl_basis basis, assert(poly_order >= 1 && poly_order <= 3); switch (basis.b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - kers->ev_ker = ser_eval_at_coord_list[ndim-1][dir_mask-1].kernels[poly_order-1]; - kers->basis_ker = ser_basis_tar_list[ndim-1][dir_mask-1].kernels[poly_order-1]; - break; - case GKYL_BASIS_MODAL_TENSOR: - kers->ev_ker = ten_eval_at_coord_list[ndim-1][dir_mask-1].kernels[poly_order-1]; - kers->basis_ker = ten_basis_tar_list[ndim-1][dir_mask-1].kernels[poly_order-1]; - break; - case GKYL_BASIS_MODAL_GKHYBRID: - kers->ev_ker = gkhyb_eval_at_coord_list[ndim-2][dir_mask-1].kernels[poly_order-1]; - kers->basis_ker = gkhyb_basis_tar_list[ndim-2][dir_mask-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + kers->ev_ker = ser_eval_at_coord_list[ndim - 1][dir_mask - 1].kernels[poly_order - 1]; + kers->basis_ker = ser_basis_tar_list[ndim - 1][dir_mask - 1].kernels[poly_order - 1]; + break; + case GKYL_BASIS_MODAL_TENSOR: + kers->ev_ker = ten_eval_at_coord_list[ndim - 1][dir_mask - 1].kernels[poly_order - 1]; + kers->basis_ker = ten_basis_tar_list[ndim - 1][dir_mask - 1].kernels[poly_order - 1]; + break; + case GKYL_BASIS_MODAL_GKHYBRID: + kers->ev_ker = gkhyb_eval_at_coord_list[ndim - 2][dir_mask - 1].kernels[poly_order - 1]; + kers->basis_ker = gkhyb_basis_tar_list[ndim - 2][dir_mask - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } assert(kers->ev_ker); } -struct dg_ev_proj_kernels* -dg_eval_at_coord_choose_ker_cu(int cdim, int ndim, const struct gkyl_basis *basis, - int num_eval_dirs, const int *eval_dirs) +struct dg_ev_proj_kernels *dg_eval_at_coord_choose_ker_cu( + int cdim, int ndim, const struct gkyl_basis *basis, int num_eval_dirs, const int *eval_dirs +) { - struct dg_ev_proj_kernels *kers = (struct dg_ev_proj_kernels *) gkyl_cu_malloc(sizeof(struct dg_ev_proj_kernels)); + struct dg_ev_proj_kernels *kers = + (struct dg_ev_proj_kernels *)gkyl_cu_malloc(sizeof(struct dg_ev_proj_kernels)); dg_evproj_struct_int_t eval_dirs_st = {0}; - for (int i=0; i>>(cdim, ndim, *basis, num_eval_dirs, eval_dirs_st, kers); + dg_eval_at_coord_choose_ker_cu_ker<<<1, 1> > >( + cdim, ndim, *basis, num_eval_dirs, eval_dirs_st, kers + ); return kers; } -__global__ void -dg_eval_at_coord_proj_range_cu_kernel(int num_basis_do, int num_basis_tar, int ncomp, - dg_evproj_struct_bool_t is_eval, dg_evproj_struct_double_t eval_coords_log, dg_evproj_struct_int_t cell_idx, - struct dg_ev_proj_kernels *kers, - struct gkyl_range rng_do, struct gkyl_range rng_tar, - const struct gkyl_array *fdo, struct gkyl_array *ftar) +__global__ void dg_eval_at_coord_proj_range_cu_kernel( + int num_basis_do, int num_basis_tar, int ncomp, dg_evproj_struct_bool_t is_eval, + dg_evproj_struct_double_t eval_coords_log, dg_evproj_struct_int_t cell_idx, + struct dg_ev_proj_kernels *kers, struct gkyl_range rng_do, struct gkyl_range rng_tar, + const struct gkyl_array *fdo, struct gkyl_array *ftar +) { int idx_tar[GKYL_MAX_DIM]; int idx_do[GKYL_MAX_DIM]; const int ndim_do = rng_do.ndim; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < rng_tar.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < rng_tar.volume; + linc1 += gridDim.x * blockDim.x) { gkyl_sub_range_inv_idx(&rng_tar, linc1, idx_tar); eval_at_coord_get_idx_do(is_eval.c, ndim_do, idx_tar, cell_idx.c, idx_do); - long start_do = gkyl_range_idx(&rng_do, idx_do); + long start_do = gkyl_range_idx(&rng_do, idx_do); long start_tar = gkyl_range_idx(&rng_tar, idx_tar); - const double *fdo_c = (const double *) gkyl_array_cfetch(fdo, start_do); - double *ftar_c = (double *) gkyl_array_fetch(ftar, start_tar); + const double *fdo_c = (const double *)gkyl_array_cfetch(fdo, start_do); + double *ftar_c = (double *)gkyl_array_fetch(ftar, start_tar); - for (int n=0; nev_ker(eval_coords_log.c, fdo_c+n*num_basis_do, ftar_c+n*num_basis_tar); + for (int n = 0; n < ncomp; n++) { + kers->ev_ker(eval_coords_log.c, fdo_c + n * num_basis_do, ftar_c + n * num_basis_tar); + } } } -void -gkyl_dg_eval_at_coord_proj_advance_cu(struct gkyl_dg_eval_at_coord_proj *up, const double *eval_coords, +void gkyl_dg_eval_at_coord_proj_advance_cu( + struct gkyl_dg_eval_at_coord_proj *up, const double *eval_coords, const struct gkyl_rect_grid *grid, const bool *pick_lower, const int *known_index, - const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, - const struct gkyl_array *fdo, struct gkyl_array *ftar) + const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, const struct gkyl_array *fdo, + struct gkyl_array *ftar +) { - // We assume that if fdo has multiple DG fields (vector components), ftar has the // same number of vector components. int ncomp = fdo->ncomp / up->num_basis_do; @@ -99,11 +103,12 @@ gkyl_dg_eval_at_coord_proj_advance_cu(struct gkyl_dg_eval_at_coord_proj *up, con // Build full ndim_do-dimensional point for gkyl_rect_grid_find_cell. double point[GKYL_MAX_DIM]; int eval_ctr = 0; - for (int d=0; dndim_do; d++) { - if (up->is_eval[d]) + for (int d = 0; d < up->ndim_do; d++) { + if (up->is_eval[d]) { point[d] = eval_coords[eval_ctr++]; - else + } else { point[d] = grid->lower[d] + (rng_do->lower[d] - 0.5) * grid->dx[d]; + } } dg_evproj_struct_int_t cell_idx = {0}; @@ -111,20 +116,22 @@ gkyl_dg_eval_at_coord_proj_advance_cu(struct gkyl_dg_eval_at_coord_proj *up, con // Convert comp eval_coords to logical coords. dg_evproj_struct_double_t eval_coords_log = {0}; - for (int i=0; inum_eval_dirs; i++) { + for (int i = 0; i < up->num_eval_dirs; i++) { int d = up->eval_dirs[i]; double xc_d = grid->lower[d] + (cell_idx.c[d] - 0.5) * grid->dx[d]; eval_coords_log.c[i] = 2.0 * (eval_coords[i] - xc_d) / grid->dx[d]; } dg_evproj_struct_bool_t is_eval = {0}; - for (int d=0; dis_eval[d]; + } int nblocks = rng_tar->nblocks; int nthreads = rng_tar->nthreads; - dg_eval_at_coord_proj_range_cu_kernel<<>>(up->num_basis_do, num_basis_tar, - ncomp, is_eval, eval_coords_log, cell_idx, up->kers, - *rng_do, *rng_tar, fdo->on_dev, ftar->on_dev); + dg_eval_at_coord_proj_range_cu_kernel<< > >( + up->num_basis_do, num_basis_tar, ncomp, is_eval, eval_coords_log, cell_idx, up->kers, *rng_do, + *rng_tar, fdo->on_dev, ftar->on_dev + ); } diff --git a/core/zero/dg_geom.c b/core/zero/dg_geom.c index 88cbe367c0..98caf045a9 100644 --- a/core/zero/dg_geom.c +++ b/core/zero/dg_geom.c @@ -9,19 +9,18 @@ #include #include -static bool -dg_geom_is_cu_dev(const struct gkyl_dg_geom* dgg) +static bool dg_geom_is_cu_dev(const struct gkyl_dg_geom *dgg) { return GKYL_IS_CU_ALLOC(dgg->flags); } -void -dg_geom_free(const struct gkyl_ref_count *ref) +void dg_geom_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_geom *dgg = container_of(ref, struct gkyl_dg_geom, ref_count); - for (int d=0; drange.ndim; ++d) + for (int d = 0; d < dgg->range.ndim; ++d) { gkyl_array_release(dgg->surf_geom[d]); + } gkyl_array_release(dgg->vol_geom); @@ -32,16 +31,15 @@ dg_geom_free(const struct gkyl_ref_count *ref) gkyl_free(dgg->surf_weights); gkyl_free(dgg->surf_ords); } - - if (dg_geom_is_cu_dev(dgg)) - gkyl_cu_free(dgg->on_dev); + + if (dg_geom_is_cu_dev(dgg)) { + gkyl_cu_free(dgg->on_dev); + } gkyl_free(dgg); } - -struct gkyl_dg_geom * -gkyl_dg_geom_new(const struct gkyl_dg_geom_inp *inp) +struct gkyl_dg_geom *gkyl_dg_geom_new(const struct gkyl_dg_geom_inp *inp) { struct gkyl_dg_geom *dgg = gkyl_malloc(sizeof *dgg); @@ -49,65 +47,66 @@ gkyl_dg_geom_new(const struct gkyl_dg_geom_inp *inp) int ndim = dgg->range.ndim; int shape[GKYL_MAX_CDIM]; - for (int d=0; dnquad; + for (int d = 0; d < ndim; ++d) { + shape[d] = inp->nquad; + } // NOTE: surfaces are ndim-1 objects - gkyl_range_init_from_shape(&dgg->surf_quad_range, ndim-1, shape); + gkyl_range_init_from_shape(&dgg->surf_quad_range, ndim - 1, shape); gkyl_range_init_from_shape(&dgg->vol_quad_range, ndim, shape); - for (int d=0; dsurf_geom[d] = gkyl_array_new(GKYL_USER, - sizeof(struct gkyl_dg_surf_geom[dgg->surf_quad_range.volume]), dgg->range.volume); + for (int d = 0; d < ndim; ++d) { + dgg->surf_geom[d] = gkyl_array_new( + GKYL_USER, sizeof(struct gkyl_dg_surf_geom[dgg->surf_quad_range.volume]), dgg->range.volume + ); + } + + dgg->vol_geom = gkyl_array_new( + GKYL_USER, sizeof(struct gkyl_dg_vol_geom[dgg->vol_quad_range.volume]), dgg->range.volume + ); - dgg->vol_geom = gkyl_array_new(GKYL_USER, - sizeof(struct gkyl_dg_vol_geom[dgg->vol_quad_range.volume]), dgg->range.volume); - // compute surface and volume quadrature weights & ordinates long nsq = dgg->surf_quad_range.volume; - dgg->surf_weights = gkyl_malloc(sizeof(double)*nsq); - dgg->surf_ords = gkyl_malloc(sizeof(double)*nsq*(ndim-1)); - gkyl_ndim_ordinates_weights(ndim-1, dgg->surf_ords, dgg->surf_weights, inp->nquad); + dgg->surf_weights = gkyl_malloc(sizeof(double) * nsq); + dgg->surf_ords = gkyl_malloc(sizeof(double) * nsq * (ndim - 1)); + gkyl_ndim_ordinates_weights(ndim - 1, dgg->surf_ords, dgg->surf_weights, inp->nquad); long nvq = dgg->vol_quad_range.volume; - dgg->vol_weights = gkyl_malloc(sizeof(double)*nvq); - dgg->vol_ords = gkyl_malloc(sizeof(double)*nvq*ndim); + dgg->vol_weights = gkyl_malloc(sizeof(double) * nvq); + dgg->vol_ords = gkyl_malloc(sizeof(double) * nvq * ndim); gkyl_ndim_ordinates_weights(ndim, dgg->vol_ords, dgg->vol_weights, inp->nquad); - + dgg->flags = 0; GKYL_CLEAR_CU_ALLOC(dgg->flags); dgg->ref_count = gkyl_ref_count_init(dg_geom_free); dgg->on_dev = dgg; // CPU eqn obj points to itself - + return dgg; } -struct gkyl_dg_geom * -gkyl_dg_geom_new_from_host(const struct gkyl_dg_geom_inp *inp, struct gkyl_dg_geom *up_host, bool use_gpu) +struct gkyl_dg_geom *gkyl_dg_geom_new_from_host( + const struct gkyl_dg_geom_inp *inp, struct gkyl_dg_geom *up_host, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_dg_geom_cu_dev_new_from_host(inp, up_host); - } -#endif + } +#endif return up_host; } - -struct gkyl_dg_geom* -gkyl_dg_geom_acquire(const struct gkyl_dg_geom* dgg) +struct gkyl_dg_geom *gkyl_dg_geom_acquire(const struct gkyl_dg_geom *dgg) { gkyl_ref_count_inc(&dgg->ref_count); - return (struct gkyl_dg_geom*) dgg; + return (struct gkyl_dg_geom *)dgg; } -void -gkyl_dg_geom_write(const struct gkyl_dg_geom* dgg, const char *fname) +void gkyl_dg_geom_write(const struct gkyl_dg_geom *dgg, const char *fname) { - } -void -gkyl_dg_geom_release(const struct gkyl_dg_geom *dgg) +void gkyl_dg_geom_release(const struct gkyl_dg_geom *dgg) { gkyl_ref_count_dec(&dgg->ref_count); } diff --git a/core/zero/dg_geom_cu.cu b/core/zero/dg_geom_cu.cu index bf38c3abc5..3dd7197350 100644 --- a/core/zero/dg_geom_cu.cu +++ b/core/zero/dg_geom_cu.cu @@ -13,53 +13,59 @@ extern "C" { struct gkyl_dg_geom * gkyl_dg_geom_cu_dev_new_from_host(const struct gkyl_dg_geom_inp *inp, struct gkyl_dg_geom *up_host) { - struct gkyl_dg_geom *dgg = (struct gkyl_dg_geom *) gkyl_malloc(sizeof *dgg); + struct gkyl_dg_geom *dgg = (struct gkyl_dg_geom *)gkyl_malloc(sizeof *dgg); dgg->range = *inp->range; int ndim = dgg->range.ndim; int shape[GKYL_MAX_CDIM]; - for (int d=0; dnquad; + for (int d = 0; d < ndim; ++d) { + shape[d] = inp->nquad; + } // NOTE: surfaces are ndim-1 objects - gkyl_range_init_from_shape(&dgg->surf_quad_range, ndim-1, shape); + gkyl_range_init_from_shape(&dgg->surf_quad_range, ndim - 1, shape); gkyl_range_init_from_shape(&dgg->vol_quad_range, ndim, shape); // Copy the host-side initialized geometry object to the device - struct gkyl_array *vol_geom_dev = gkyl_array_cu_dev_new(GKYL_USER, - sizeof(struct gkyl_dg_vol_geom[dgg->vol_quad_range.volume]), dgg->range.volume); + struct gkyl_array *vol_geom_dev = gkyl_array_cu_dev_new( + GKYL_USER, sizeof(struct gkyl_dg_vol_geom[dgg->vol_quad_range.volume]), dgg->range.volume + ); struct gkyl_array *surf_geom_dev[ndim]; - for (int dir=0; dirsurf_quad_range.volume]), dgg->range.volume); + for (int dir = 0; dir < ndim; ++dir) { + surf_geom_dev[dir] = gkyl_array_cu_dev_new( + GKYL_USER, sizeof(struct gkyl_dg_surf_geom[dgg->surf_quad_range.volume]), dgg->range.volume + ); } gkyl_array_copy(vol_geom_dev, up_host->vol_geom); - for (int dir=0; dirsurf_geom[dir]); + } // this is for the memcpy below dgg->vol_geom = vol_geom_dev->on_dev; - for (int dir=0; dirsurf_geom[dir] = surf_geom_dev[dir]->on_dev; + for (int dir = 0; dir < ndim; ++dir) { + dgg->surf_geom[dir] = surf_geom_dev[dir]->on_dev; + } dgg->flags = 0; GKYL_SET_CU_ALLOC(dgg->flags); dgg->ref_count = gkyl_ref_count_init(dg_geom_free); // Initialize the device geometry object - struct gkyl_dg_geom *dgg_cu = (struct gkyl_dg_geom*) gkyl_cu_malloc(sizeof(struct gkyl_dg_geom)); + struct gkyl_dg_geom *dgg_cu = (struct gkyl_dg_geom *)gkyl_cu_malloc(sizeof(struct gkyl_dg_geom)); gkyl_cu_memcpy(dgg_cu, dgg, sizeof(struct gkyl_dg_geom), GKYL_CU_MEMCPY_H2D); dgg->on_dev = dgg_cu; // geometry object should store host pointer dgg->vol_geom = vol_geom_dev; - for (int dir=0; dirsurf_geom[dir] = surf_geom_dev[dir]; + } - return dgg; } diff --git a/core/zero/dg_interpolate.c b/core/zero/dg_interpolate.c index 2910642a2b..ad0ae7b745 100644 --- a/core/zero/dg_interpolate.c +++ b/core/zero/dg_interpolate.c @@ -3,11 +3,11 @@ #include #include -struct gkyl_dg_interpolate* -gkyl_dg_interpolate_new(int cdim, const struct gkyl_basis *basis, - const struct gkyl_rect_grid *grid_do, const struct gkyl_rect_grid *grid_tar, - const struct gkyl_range *range_do, const struct gkyl_range *range_tar, - const int *nghost, bool use_gpu) +struct gkyl_dg_interpolate *gkyl_dg_interpolate_new( + int cdim, const struct gkyl_basis *basis, const struct gkyl_rect_grid *grid_do, + const struct gkyl_rect_grid *grid_tar, const struct gkyl_range *range_do, + const struct gkyl_range *range_tar, const int *nghost, bool use_gpu +) { // Allocate space for new updater. struct gkyl_dg_interpolate *up = gkyl_malloc(sizeof(*up)); @@ -19,25 +19,29 @@ gkyl_dg_interpolate_new(int cdim, const struct gkyl_basis *basis, // Perform some basic checks: assert(grid_do->ndim == grid_tar->ndim); - for (int d=0; dndim; d++) { + for (int d = 0; d < up->ndim; d++) { assert(fabs(grid_do->lower[d] - grid_tar->lower[d]) < 1e-14); assert(fabs(grid_do->upper[d] - grid_tar->upper[d]) < 1e-14); // Only (2^a)*(3^b)*(5^c) grids have been tested. int num_prime_facs_max = 32; int prime_factors[num_prime_facs_max]; - int num_prime_facs_do = dg_interp_prime_factors(grid_do->cells[d], prime_factors, num_prime_facs_max); - for (int k=0; kcells[d], prime_factors, num_prime_facs_max); + for (int k = 0; k < num_prime_facs_do; k++) { assert(prime_factors[k] == 2 || prime_factors[k] == 3 || prime_factors[k] == 5); - - int num_prime_facs_tar = dg_interp_prime_factors(grid_tar->cells[d], prime_factors, num_prime_facs_max); - for (int k=0; kcells[d], prime_factors, num_prime_facs_max); + for (int k = 0; k < num_prime_facs_tar; k++) { assert(prime_factors[k] == 2 || prime_factors[k] == 3 || prime_factors[k] == 5); + } } // Make a list of directions to be coarsened/refined. up->num_interp_dirs = 0; - for (int d=0; dndim; d++) { + for (int d = 0; d < up->ndim; d++) { if (grid_do->cells[d] != grid_tar->cells[d]) { up->interp_dirs[up->num_interp_dirs] = d; up->num_interp_dirs++; @@ -46,56 +50,61 @@ gkyl_dg_interpolate_new(int cdim, const struct gkyl_basis *basis, // Create a series of grids, each one the same as the previous one except // that it has the number of target cells along one new direction. - up->grids = gkyl_malloc((up->num_interp_dirs+1) * sizeof(struct gkyl_rect_grid)); + up->grids = gkyl_malloc((up->num_interp_dirs + 1) * sizeof(struct gkyl_rect_grid)); double lower_new[up->ndim], upper_new[up->ndim]; - for (int d=0; dndim; d++) { + for (int d = 0; d < up->ndim; d++) { lower_new[d] = grid_do->lower[d]; upper_new[d] = grid_do->upper[d]; } memcpy(&up->grids[0], grid_do, sizeof(struct gkyl_rect_grid)); - for (int k=1; knum_interp_dirs; k++) { + for (int k = 1; k < up->num_interp_dirs; k++) { int cells_new[up->ndim]; - for (int d=0; dndim; d++) - cells_new[d] = up->grids[k-1].cells[d]; - cells_new[up->interp_dirs[k-1]] = grid_tar->cells[up->interp_dirs[k-1]]; + for (int d = 0; d < up->ndim; d++) { + cells_new[d] = up->grids[k - 1].cells[d]; + } + cells_new[up->interp_dirs[k - 1]] = grid_tar->cells[up->interp_dirs[k - 1]]; gkyl_rect_grid_init(&up->grids[k], up->ndim, lower_new, upper_new, cells_new); } memcpy(&up->grids[up->num_interp_dirs], grid_tar, sizeof(struct gkyl_rect_grid)); // Create a donor and target range for each interpolation. - up->ranges = gkyl_malloc((up->num_interp_dirs+1) * sizeof(struct gkyl_range)); - struct gkyl_range *ranges_ext = gkyl_malloc((up->num_interp_dirs+1) * sizeof(struct gkyl_range)); + up->ranges = gkyl_malloc((up->num_interp_dirs + 1) * sizeof(struct gkyl_range)); + struct gkyl_range *ranges_ext = + gkyl_malloc((up->num_interp_dirs + 1) * sizeof(struct gkyl_range)); memcpy(&up->ranges[0], range_do, sizeof(struct gkyl_range)); - for (int k=1; knum_interp_dirs; k++) { + for (int k = 1; k < up->num_interp_dirs; k++) { gkyl_create_grid_ranges(&up->grids[k], nghost, &ranges_ext[k], &up->ranges[k]); } memcpy(&up->ranges[up->num_interp_dirs], range_tar, sizeof(struct gkyl_range)); // Create an interpolation updater for each interpolation. - up->interp_ops = gkyl_malloc(up->num_interp_dirs * sizeof(struct gkyl_dg_interpolate*)); + up->interp_ops = gkyl_malloc(up->num_interp_dirs * sizeof(struct gkyl_dg_interpolate *)); if (up->num_interp_dirs == 1) { up->interp_ops[0] = up; - } - else { - for (int k=0; knum_interp_dirs; k++) - up->interp_ops[k] = gkyl_dg_interpolate_new(cdim, basis, &up->grids[k], &up->grids[k+1], - &up->ranges[k], &up->ranges[k+1], nghost, use_gpu); + } else { + for (int k = 0; k < up->num_interp_dirs; k++) { + up->interp_ops[k] = gkyl_dg_interpolate_new( + cdim, basis, &up->grids[k], &up->grids[k + 1], &up->ranges[k], &up->ranges[k + 1], nghost, + use_gpu + ); + } } // Pre-allocate fields for intermediate grids. - up->fields = gkyl_malloc((up->num_interp_dirs+1) * sizeof(struct gkyl_array *)); - for (int k=1; knum_interp_dirs; k++) { - up->fields[k] = up->use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis->num_basis, ranges_ext[k].volume) - : gkyl_array_new(GKYL_DOUBLE, basis->num_basis, ranges_ext[k].volume); - + up->fields = gkyl_malloc((up->num_interp_dirs + 1) * sizeof(struct gkyl_array *)); + for (int k = 1; k < up->num_interp_dirs; k++) { + up->fields[k] = up->use_gpu ? + gkyl_array_cu_dev_new(GKYL_DOUBLE, basis->num_basis, ranges_ext[k].volume) : + gkyl_array_new(GKYL_DOUBLE, basis->num_basis, ranges_ext[k].volume); } gkyl_free(ranges_ext); - if (up->num_interp_dirs > 1) + if (up->num_interp_dirs > 1) { return up; // Only allocate the remaining objects if doing 1D interpolation. + } // Identify direction to be coarsened/refined: - for (int d=0; dndim; d++) { + for (int d = 0; d < up->ndim; d++) { if (grid_do->cells[d] != grid_tar->cells[d]) { up->dir = d; break; @@ -103,26 +112,25 @@ gkyl_dg_interpolate_new(int cdim, const struct gkyl_basis *basis, } // Ratio of cell-lengths in each direction. - up->dxRat = grid_do->dx[up->dir]/grid_tar->dx[up->dir]; + up->dxRat = grid_do->dx[up->dir] / grid_tar->dx[up->dir]; // Interior (away from boundaries) stencil size. int intStencilSize = -1; if (up->dxRat > 1) { // Mesh refinement. // Brute force search. Start with the size of the boundary stencil. - int maxSize = floor(up->dxRat) + ceil( up->dxRat-floor(up->dxRat) ); - for (int i=2; icells[up->dir]; i++) { - double decimalL = 1.0-((i-1)*up->dxRat-floor((i-1)*up->dxRat)); - double decimalU = 1.0-(ceil(i*up->dxRat)-i*up->dxRat); - int currSize = dg_interp_floor(up->dxRat-decimalL-decimalU, 1e-13, 0.0) + dg_interp_ceil(decimalL, 1e-13, 0.0) - + dg_interp_ceil(decimalU, 1e-13, 0.0); - maxSize = GKYL_MAX2(maxSize, currSize); + int maxSize = floor(up->dxRat) + ceil(up->dxRat - floor(up->dxRat)); + for (int i = 2; i < grid_do->cells[up->dir]; i++) { + double decimalL = 1.0 - ((i - 1) * up->dxRat - floor((i - 1) * up->dxRat)); + double decimalU = 1.0 - (ceil(i * up->dxRat) - i * up->dxRat); + int currSize = dg_interp_floor(up->dxRat - decimalL - decimalU, 1e-13, 0.0) + + dg_interp_ceil(decimalL, 1e-13, 0.0) + dg_interp_ceil(decimalU, 1e-13, 0.0); + maxSize = GKYL_MAX2(maxSize, currSize); } intStencilSize = maxSize; - } - else { + } else { // Mesh coarsening, or no change in resolution (dxRat=1). - intStencilSize = 1+ceil(1*(1/up->dxRat-floor(1/up->dxRat))); + intStencilSize = 1 + ceil(1 * (1 / up->dxRat - floor(1 / up->dxRat))); } // This updater will loop through the donor grid. At each donor cell it will give @@ -143,7 +151,7 @@ gkyl_dg_interpolate_new(int cdim, const struct gkyl_basis *basis, offset_upper[0] = intStencilSize; sc++; // Other stencils. - for (int mp=-1; mp<2; mp += 2) { + for (int mp = -1; mp < 2; mp += 2) { offset_upper[sc] = floor(up->dxRat) + ceil(up->dxRat - floor(up->dxRat)); sc++; } @@ -167,10 +175,11 @@ gkyl_dg_interpolate_new(int cdim, const struct gkyl_basis *basis, up->kernels->interp = dg_interp_choose_gk_interp_kernel(cdim, *basis, up->dir); // Map from grid to stencil index in each direction. - if (up->dxRat > 1) + if (up->dxRat > 1) { up->kernels->grid2stencil = dg_interp_index_stencil_map_refine; - else + } else { up->kernels->grid2stencil = dg_interp_index_stencil_map_coarsen; + } } #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { @@ -185,12 +194,11 @@ gkyl_dg_interpolate_new(int cdim, const struct gkyl_basis *basis, return up; } -static void -dg_interpolate_advance_1x(gkyl_dg_interpolate* up, - const struct gkyl_range *range_do, const struct gkyl_range *range_tar, - const struct gkyl_array *GKYL_RESTRICT fdo, struct gkyl_array *GKYL_RESTRICT ftar) +static void dg_interpolate_advance_1x( + gkyl_dg_interpolate *up, const struct gkyl_range *range_do, const struct gkyl_range *range_tar, + const struct gkyl_array *GKYL_RESTRICT fdo, struct gkyl_array *GKYL_RESTRICT ftar +) { - #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { gkyl_dg_interpolate_advance_1x_cu(up, range_do, range_tar, fdo, ftar); @@ -209,7 +217,6 @@ dg_interpolate_advance_1x(gkyl_dg_interpolate* up, struct gkyl_range_iter iter_do; gkyl_range_iter_init(&iter_do, range_do); while (gkyl_range_iter_next(&iter_do)) { - int *idx_do = iter_do.idx; gkyl_rect_grid_cell_center(&up->grid_do, idx_do, xc_do); @@ -218,18 +225,19 @@ dg_interpolate_advance_1x(gkyl_dg_interpolate* up, const double *fdo_c = gkyl_array_cfetch(fdo, linidx_do); // Compute the index of the lower target cell this cell contributes to. - double eveOI = up->dxRat*(idx_do[up->dir]-1); - idx_tar_lo = ceil(eveOI)+((int) ceil(eveOI-floor(eveOI))+1) % 2; + double eveOI = up->dxRat * (idx_do[up->dir] - 1); + idx_tar_lo = ceil(eveOI) + ((int)ceil(eveOI - floor(eveOI)) + 1) % 2; // Get the index to the stencil for this donor cell. - int idx_sten = up->kernels->grid2stencil(idx_do[up->dir], up->grid_do.cells[up->dir], up->dxRat); + int idx_sten = + up->kernels->grid2stencil(idx_do[up->dir], up->grid_do.cells[up->dir], up->dxRat); - for (int d=0; dndim; d++) + for (int d = 0; d < up->ndim; d++) { idx_tar[d] = idx_do[d]; + } // Loop over the target-grid cells this donor cell contributes to. - for (int off=0; offoffset_upper[idx_sten]; off++) { - + for (int off = 0; off < up->offset_upper[idx_sten]; off++) { idx_tar[up->dir] = idx_tar_lo + off; gkyl_rect_grid_cell_center(&up->grid_tar, idx_tar, xc_tar); @@ -238,28 +246,26 @@ dg_interpolate_advance_1x(gkyl_dg_interpolate* up, double *ftar_c = gkyl_array_fetch(ftar, linidx_tar); up->kernels->interp(xc_do, xc_tar, up->grid_do.dx, up->grid_tar.dx, fdo_c, ftar_c); - } - } } -void -gkyl_dg_interpolate_advance(gkyl_dg_interpolate* up, - struct gkyl_array *fdo, struct gkyl_array *ftar) +void gkyl_dg_interpolate_advance( + gkyl_dg_interpolate *up, struct gkyl_array *fdo, struct gkyl_array *ftar +) { up->fields[0] = fdo; up->fields[up->num_interp_dirs] = ftar; // Loop over interpolating dimensions and do each interpolation separately. - for (int k=0; knum_interp_dirs; k++) { - dg_interpolate_advance_1x(up->interp_ops[k], &up->ranges[k], &up->ranges[k+1], - up->fields[k], up->fields[k+1]); + for (int k = 0; k < up->num_interp_dirs; k++) { + dg_interpolate_advance_1x( + up->interp_ops[k], &up->ranges[k], &up->ranges[k + 1], up->fields[k], up->fields[k + 1] + ); } } -void -gkyl_dg_interpolate_release(gkyl_dg_interpolate* up) +void gkyl_dg_interpolate_release(gkyl_dg_interpolate *up) { // Release memory associated with this updater. @@ -278,13 +284,15 @@ gkyl_dg_interpolate_release(gkyl_dg_interpolate* up) gkyl_free(up->grids); if (up->num_interp_dirs > 1) { - for (int k=0; knum_interp_dirs; k++) + for (int k = 0; k < up->num_interp_dirs; k++) { gkyl_dg_interpolate_release(up->interp_ops[k]); + } } gkyl_free(up->interp_ops); gkyl_free(up->ranges); - for (int k=1; knum_interp_dirs; k++) + for (int k = 1; k < up->num_interp_dirs; k++) { gkyl_array_release(up->fields[k]); + } gkyl_free(up->fields); gkyl_free(up); diff --git a/core/zero/dg_interpolate_cu.cu b/core/zero/dg_interpolate_cu.cu index 0f12096449..26a8f488eb 100644 --- a/core/zero/dg_interpolate_cu.cu +++ b/core/zero/dg_interpolate_cu.cu @@ -10,30 +10,35 @@ extern "C" { // CUDA kernel to set device pointer to interpolating kernel. // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_interp_choose_kernel_ptrs_cu(struct gkyl_dg_interpolate_kernels *kernels, int cdim, struct gkyl_basis basis, int dir, double dxRat) +__global__ static void dg_interp_choose_kernel_ptrs_cu( + struct gkyl_dg_interpolate_kernels *kernels, int cdim, struct gkyl_basis basis, int dir, + double dxRat +) { kernels->interp = dg_interp_choose_gk_interp_kernel(cdim, basis, dir); // Map from grid to stencil index in each direction. - if (dxRat > 1) + if (dxRat > 1) { kernels->grid2stencil = dg_interp_index_stencil_map_refine; - else + } else { kernels->grid2stencil = dg_interp_index_stencil_map_coarsen; + } } -void -dg_interp_choose_kernel_cu(struct gkyl_dg_interpolate_kernels *kernels, int cdim, struct gkyl_basis basis, int dir, double dxRat) +void dg_interp_choose_kernel_cu( + struct gkyl_dg_interpolate_kernels *kernels, int cdim, struct gkyl_basis basis, int dir, + double dxRat +) { - dg_interp_choose_kernel_ptrs_cu<<<1,1>>>(kernels, cdim, basis, dir, dxRat); + dg_interp_choose_kernel_ptrs_cu<<<1, 1> > >(kernels, cdim, basis, dir, dxRat); } -__global__ static void -gkyl_dg_interpolate_advance_1x_cu_ker(struct gkyl_dg_interpolate_kernels *kernels, - int dir, double dxRat, int *offset_upper, - struct gkyl_rect_grid grid_do, struct gkyl_rect_grid grid_tar, - struct gkyl_range range_do, struct gkyl_range range_tar, - const struct gkyl_array* GKYL_RESTRICT fdo, struct gkyl_array* GKYL_RESTRICT ftar) +__global__ static void gkyl_dg_interpolate_advance_1x_cu_ker( + struct gkyl_dg_interpolate_kernels *kernels, int dir, double dxRat, int *offset_upper, + struct gkyl_rect_grid grid_do, struct gkyl_rect_grid grid_tar, struct gkyl_range range_do, + struct gkyl_range range_tar, const struct gkyl_array *GKYL_RESTRICT fdo, + struct gkyl_array *GKYL_RESTRICT ftar +) { int idx_do[GKYL_MAX_DIM] = {-1}; int idx_tar[GKYL_MAX_DIM] = {-1}; @@ -43,52 +48,51 @@ gkyl_dg_interpolate_advance_1x_cu_ker(struct gkyl_dg_interpolate_kernels *kernel int ndim = range_do.ndim; - for (unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < range_do.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < range_do.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&range_do, tid, idx_do); gkyl_rect_grid_cell_center(&grid_do, idx_do, xc_do); long linidx_do = gkyl_range_idx(&range_do, idx_do); - const double *fdo_c = (const double *) gkyl_array_cfetch(fdo, linidx_do); + const double *fdo_c = (const double *)gkyl_array_cfetch(fdo, linidx_do); // Compute the index of the lower cell this cell contributes to. - double eveOI = dxRat*(idx_do[dir]-1); - idx_tar_lo = ceil(eveOI)+((int) ceil(eveOI-floor(eveOI))+1) % 2; + double eveOI = dxRat * (idx_do[dir] - 1); + idx_tar_lo = ceil(eveOI) + ((int)ceil(eveOI - floor(eveOI)) + 1) % 2; // Get the index to the stencil for this donor cell. int idx_sten = kernels->grid2stencil(idx_do[dir], grid_do.cells[dir], dxRat); - for (int d=0; dinterp(xc_do, xc_tar, grid_do.dx, grid_tar.dx, fdo_c, ftar_c); - } } } - -void -gkyl_dg_interpolate_advance_1x_cu(gkyl_dg_interpolate* up, - const struct gkyl_range *range_do, const struct gkyl_range *range_tar, - const struct gkyl_array *GKYL_RESTRICT fdo, struct gkyl_array *GKYL_RESTRICT ftar) +void gkyl_dg_interpolate_advance_1x_cu( + gkyl_dg_interpolate *up, const struct gkyl_range *range_do, const struct gkyl_range *range_tar, + const struct gkyl_array *GKYL_RESTRICT fdo, struct gkyl_array *GKYL_RESTRICT ftar +) { gkyl_array_clear_range(ftar, 0.0, range_tar); int nblocks = range_do->nblocks, nthreads = range_do->nthreads; - gkyl_dg_interpolate_advance_1x_cu_ker<<>> - (up->kernels, up->dir, up->dxRat, up->offset_upper, up->grid_do, up->grid_tar, - *range_do, *range_tar, fdo->on_dev, ftar->on_dev); + gkyl_dg_interpolate_advance_1x_cu_ker<< > >( + up->kernels, up->dir, up->dxRat, up->offset_upper, up->grid_do, up->grid_tar, *range_do, + *range_tar, fdo->on_dev, ftar->on_dev + ); } diff --git a/core/zero/dynvec.c b/core/zero/dynvec.c index 68e9e337c6..4f6be44ce8 100644 --- a/core/zero/dynvec.c +++ b/core/zero/dynvec.c @@ -23,12 +23,11 @@ struct gkyl_dynvec_tag { size_t esznc; // elemsz*ncomp void *data; // pointer to data double *tm_mesh; // time stamps - - struct gkyl_ref_count ref_count; + + struct gkyl_ref_count ref_count; }; -static void -dynvec_free(const struct gkyl_ref_count *ref) +static void dynvec_free(const struct gkyl_ref_count *ref) { struct gkyl_dynvec_tag *dv = container_of(ref, struct gkyl_dynvec_tag, ref_count); gkyl_free(dv->data); @@ -36,150 +35,151 @@ dynvec_free(const struct gkyl_ref_count *ref) gkyl_free(dv); } -gkyl_dynvec -gkyl_dynvec_new(enum gkyl_elem_type type, size_t ncomp) +gkyl_dynvec gkyl_dynvec_new(enum gkyl_elem_type type, size_t ncomp) { struct gkyl_dynvec_tag *dv = gkyl_malloc(sizeof(struct gkyl_dynvec_tag)); dv->type = type; dv->elemsz = gkyl_elem_type_size[type]; dv->ncomp = ncomp; - dv->esznc = dv->elemsz*dv->ncomp; + dv->esznc = dv->elemsz * dv->ncomp; dv->csize = DYNVEC_ALLOC_SZ; dv->cloc = 0; - + dv->data = gkyl_calloc(dv->csize, dv->esznc); dv->tm_mesh = gkyl_calloc(dv->csize, sizeof(double)); - + dv->ref_count = gkyl_ref_count_init(dynvec_free); - + return dv; } -int gkyl_dynvec_elem_type(gkyl_dynvec vec) { return vec->type; } -int gkyl_dynvec_ncomp(gkyl_dynvec vec) { return vec->ncomp; } +int gkyl_dynvec_elem_type(gkyl_dynvec vec) +{ + return vec->type; +} +int gkyl_dynvec_ncomp(gkyl_dynvec vec) +{ + return vec->ncomp; +} -void -gkyl_dynvec_reserve_more(gkyl_dynvec dv, size_t rsize) +void gkyl_dynvec_reserve_more(gkyl_dynvec dv, size_t rsize) { int n = gkyl_int_div_up(rsize, DYNVEC_ALLOC_SZ); - dv->csize = n*DYNVEC_ALLOC_SZ + dv->csize; - dv->data = gkyl_realloc(dv->data, dv->csize*dv->esznc); - dv->tm_mesh = gkyl_realloc(dv->tm_mesh, dv->csize*sizeof(double)); + dv->csize = n * DYNVEC_ALLOC_SZ + dv->csize; + dv->data = gkyl_realloc(dv->data, dv->csize * dv->esznc); + dv->tm_mesh = gkyl_realloc(dv->tm_mesh, dv->csize * sizeof(double)); } -void -gkyl_dynvec_append(gkyl_dynvec dv, double tm, const void *data) +void gkyl_dynvec_append(gkyl_dynvec dv, double tm, const void *data) { size_t loc = dv->cloc; if (loc >= dv->csize) { dv->csize += DYNVEC_ALLOC_SZ; - dv->data = gkyl_realloc(dv->data, dv->csize*dv->esznc); - dv->tm_mesh = gkyl_realloc(dv->tm_mesh, dv->csize*sizeof(double)); + dv->data = gkyl_realloc(dv->data, dv->csize * dv->esznc); + dv->tm_mesh = gkyl_realloc(dv->tm_mesh, dv->csize * sizeof(double)); } // set data dv->tm_mesh[loc] = tm; - memcpy((char*)dv->data + dv->esznc*loc, data, dv->esznc); - + memcpy((char *)dv->data + dv->esznc * loc, data, dv->esznc); + dv->cloc += 1; } -bool -gkyl_dynvec_get(const gkyl_dynvec dv, size_t idx, void *data) +bool gkyl_dynvec_get(const gkyl_dynvec dv, size_t idx, void *data) { - if (idx >= dv->cloc) return false; - memcpy(data, (char*)dv->data + dv->esznc*idx, dv->esznc); - return true; + if (idx >= dv->cloc) { + return false; + } + memcpy(data, (char *)dv->data + dv->esznc * idx, dv->esznc); + return true; } -double -gkyl_dynvec_get_tm(const gkyl_dynvec dv, size_t idx) +double gkyl_dynvec_get_tm(const gkyl_dynvec dv, size_t idx) { - if (idx >= dv->cloc) return 0.0; + if (idx >= dv->cloc) { + return 0.0; + } return dv->tm_mesh[idx]; } -bool -gkyl_dynvec_getlast(const gkyl_dynvec dv, void *data) +bool gkyl_dynvec_getlast(const gkyl_dynvec dv, void *data) { size_t loc = dv->cloc; - if (loc == 0) return false; - return gkyl_dynvec_get(dv, loc-1, data); + if (loc == 0) { + return false; + } + return gkyl_dynvec_get(dv, loc - 1, data); } -double -gkyl_dynvec_getlast_tm(const gkyl_dynvec dv) +double gkyl_dynvec_getlast_tm(const gkyl_dynvec dv) { size_t loc = dv->cloc; - return loc == 0 ? 0.0 : dv->tm_mesh[loc-1]; + return loc == 0 ? 0.0 : dv->tm_mesh[loc - 1]; } -size_t -gkyl_dynvec_size(const gkyl_dynvec vec) +size_t gkyl_dynvec_size(const gkyl_dynvec vec) { return vec->cloc; } -size_t -gkyl_dynvec_capacity(const gkyl_dynvec vec) +size_t gkyl_dynvec_capacity(const gkyl_dynvec vec) { return vec->csize; } -void -gkyl_dynvec_clear(gkyl_dynvec dv) +void gkyl_dynvec_clear(gkyl_dynvec dv) { dv->cloc = 0; dv->csize = DYNVEC_ALLOC_SZ; - dv->data = gkyl_realloc(dv->data, dv->csize*dv->esznc); - dv->tm_mesh = gkyl_realloc(dv->tm_mesh, dv->csize*sizeof(double)); + dv->data = gkyl_realloc(dv->data, dv->csize * dv->esznc); + dv->tm_mesh = gkyl_realloc(dv->tm_mesh, dv->csize * sizeof(double)); } -void -gkyl_dynvec_clear_all_but(gkyl_dynvec dv, size_t num) +void gkyl_dynvec_clear_all_but(gkyl_dynvec dv, size_t num) { - if (num>dv->cloc) return; - + if (num > dv->cloc) { + return; + } + size_t cloc = dv->cloc; dv->csize = DYNVEC_ALLOC_SZ; - void *data = gkyl_malloc(num*dv->esznc); + void *data = gkyl_malloc(num * dv->esznc); double *tm_mesh = gkyl_malloc(sizeof(double[num])); - size_t low = num>cloc ? 0 : cloc-num; // lower index to copy from - size_t ncpy = num>cloc ? cloc : num; // number of elemetns to copy + size_t low = num > cloc ? 0 : cloc - num; // lower index to copy from + size_t ncpy = num > cloc ? cloc : num; // number of elemetns to copy dv->cloc = ncpy; - memcpy(tm_mesh, dv->tm_mesh+low, ncpy*sizeof(double)); - memcpy(data, (char*)dv->data+low*dv->esznc, ncpy*dv->esznc); - - dv->data = gkyl_realloc(dv->data, dv->csize*dv->esznc); - dv->tm_mesh = gkyl_realloc(dv->tm_mesh, dv->csize*sizeof(double)); + memcpy(tm_mesh, dv->tm_mesh + low, ncpy * sizeof(double)); + memcpy(data, (char *)dv->data + low * dv->esznc, ncpy * dv->esznc); - memcpy(dv->data, data, ncpy*dv->esznc); - memcpy(dv->tm_mesh, tm_mesh, ncpy*sizeof(double)); + dv->data = gkyl_realloc(dv->data, dv->csize * dv->esznc); + dv->tm_mesh = gkyl_realloc(dv->tm_mesh, dv->csize * sizeof(double)); + + memcpy(dv->data, data, ncpy * dv->esznc); + memcpy(dv->tm_mesh, tm_mesh, ncpy * sizeof(double)); gkyl_free(data); gkyl_free(tm_mesh); } -gkyl_dynvec -gkyl_dynvec_acquire(const gkyl_dynvec vec) +gkyl_dynvec gkyl_dynvec_acquire(const gkyl_dynvec vec) { gkyl_ref_count_inc(&vec->ref_count); - return (struct gkyl_dynvec_tag*) vec; + return (struct gkyl_dynvec_tag *)vec; } -static int -gkyl_dynvec_write_mode(const gkyl_dynvec vec, - const char *fname, const char *mode) +static int gkyl_dynvec_write_mode(const gkyl_dynvec vec, const char *fname, const char *mode) { const char g0[5] = "gkyl0"; FILE *fp = 0; - with_file (fp, fname, mode) { + with_file(fp, fname, mode) + { fseek(fp, 0, SEEK_END); - + // Version 1 header fwrite(g0, sizeof(char[5]), 1, fp); uint64_t version = 1; @@ -187,31 +187,32 @@ gkyl_dynvec_write_mode(const gkyl_dynvec vec, fwrite(&gkyl_file_type_int[GKYL_DYNVEC_DATA_FILE], sizeof(uint64_t), 1, fp); uint64_t meta_size = 0; // THIS WILL CHANGE ONCE METADATA IS EMBEDDED fwrite(&meta_size, sizeof(uint64_t), 1, fp); - + uint64_t real_type = gkyl_array_data_type[vec->type]; fwrite(&real_type, sizeof(uint64_t), 1, fp); uint64_t esznc = vec->esznc, size = gkyl_dynvec_size(vec); fwrite(&esznc, sizeof(uint64_t), 1, fp); - fwrite(&size, sizeof(uint64_t), 1, fp); + fwrite(&size, sizeof(uint64_t), 1, fp); - fwrite(vec->tm_mesh, sizeof(double)*size, 1, fp); - fwrite(vec->data, esznc*size, 1, fp); + fwrite(vec->tm_mesh, sizeof(double) * size, 1, fp); + fwrite(vec->data, esznc * size, 1, fp); } return errno; } -static int -gkyl_dynvec_write_mode_wmeta(const gkyl_dynvec vec, const char *fname, - const struct gkyl_msgpack_data *meta, const char *mode) +static int gkyl_dynvec_write_mode_wmeta( + const gkyl_dynvec vec, const char *fname, const struct gkyl_msgpack_data *meta, const char *mode +) { const char g0[5] = "gkyl0"; FILE *fp = 0; - with_file (fp, fname, mode) { + with_file(fp, fname, mode) + { fseek(fp, 0, SEEK_END); - + // Version 1 header fwrite(g0, sizeof(char[5]), 1, fp); uint64_t version = 1; @@ -219,63 +220,66 @@ gkyl_dynvec_write_mode_wmeta(const gkyl_dynvec vec, const char *fname, fwrite(&gkyl_file_type_int[GKYL_DYNVEC_DATA_FILE], sizeof(uint64_t), 1, fp); uint64_t meta_size = meta->meta_sz; fwrite(&meta_size, sizeof(uint64_t), 1, fp); - if (meta_size > 0) + if (meta_size > 0) { fwrite(meta->meta, meta_size, 1, fp); - + } + uint64_t real_type = gkyl_array_data_type[vec->type]; fwrite(&real_type, sizeof(uint64_t), 1, fp); uint64_t esznc = vec->esznc, size = gkyl_dynvec_size(vec); fwrite(&esznc, sizeof(uint64_t), 1, fp); - fwrite(&size, sizeof(uint64_t), 1, fp); + fwrite(&size, sizeof(uint64_t), 1, fp); - fwrite(vec->tm_mesh, sizeof(double)*size, 1, fp); - fwrite(vec->data, esznc*size, 1, fp); + fwrite(vec->tm_mesh, sizeof(double) * size, 1, fp); + fwrite(vec->data, esznc * size, 1, fp); } return errno; } -int -gkyl_dynvec_write(const gkyl_dynvec vec, const char *fname) +int gkyl_dynvec_write(const gkyl_dynvec vec, const char *fname) { return gkyl_dynvec_write_mode(vec, fname, "w"); } -int -gkyl_dynvec_awrite(const gkyl_dynvec vec, const char *fname) +int gkyl_dynvec_awrite(const gkyl_dynvec vec, const char *fname) { return gkyl_dynvec_write_mode(vec, fname, "a"); } -int -gkyl_dynvec_write_wmeta(const gkyl_dynvec vec, const char *fname, const struct gkyl_msgpack_data *meta) +int gkyl_dynvec_write_wmeta( + const gkyl_dynvec vec, const char *fname, const struct gkyl_msgpack_data *meta +) { return gkyl_dynvec_write_mode_wmeta(vec, fname, meta, "w"); } // ncomp returned in 'ncomp' -static bool -gkyl_dynvec_read_ncomp_1(FILE *fp, struct gkyl_dynvec_etype_ncomp *enc) +static bool gkyl_dynvec_read_ncomp_1(FILE *fp, struct gkyl_dynvec_etype_ncomp *enc) { size_t frr; // Version 1 header char g0[6]; - if (1 != fread(g0, sizeof(char[5]), 1, fp)) + if (1 != fread(g0, sizeof(char[5]), 1, fp)) { return false; + } g0[5] = '\0'; // add the NULL - if (strcmp(g0, "gkyl0") != 0) + if (strcmp(g0, "gkyl0") != 0) { return false; + } uint64_t version; frr = fread(&version, sizeof(uint64_t), 1, fp); - if (version != 1) + if (version != 1) { return false; + } uint64_t file_type; frr = fread(&file_type, sizeof(uint64_t), 1, fp); - if (file_type != gkyl_file_type_int[GKYL_DYNVEC_DATA_FILE]) + if (file_type != gkyl_file_type_int[GKYL_DYNVEC_DATA_FILE]) { return false; + } uint64_t meta_size; frr = fread(&meta_size, sizeof(uint64_t), 1, fp); @@ -285,54 +289,54 @@ gkyl_dynvec_read_ncomp_1(FILE *fp, struct gkyl_dynvec_etype_ncomp *enc) fseek(fp, meta_size, SEEK_CUR); uint64_t real_code = 0; - if (1 != fread(&real_code, sizeof(uint64_t), 1, fp)) + if (1 != fread(&real_code, sizeof(uint64_t), 1, fp)) { return false; + } enc->type = gkyl_array_code_to_data_type[real_code]; uint64_t esznc; - if (1 != fread(&esznc, sizeof(uint64_t), 1, fp)) + if (1 != fread(&esznc, sizeof(uint64_t), 1, fp)) { return false; + } int real_type = gkyl_array_code_to_data_type[real_code]; - enc->ncomp = esznc/gkyl_elem_type_size[real_type]; - + enc->ncomp = esznc / gkyl_elem_type_size[real_type]; + return true; } - -struct gkyl_dynvec_etype_ncomp -gkyl_dynvec_read_ncomp(const char *fname) +struct gkyl_dynvec_etype_ncomp gkyl_dynvec_read_ncomp(const char *fname) { - struct gkyl_dynvec_etype_ncomp enc = { - .type = GKYL_DOUBLE, - .ncomp = 0 - }; + struct gkyl_dynvec_etype_ncomp enc = {.type = GKYL_DOUBLE, .ncomp = 0}; FILE *fp = 0; - with_file(fp, fname, "r") - gkyl_dynvec_read_ncomp_1(fp, &enc); + with_file(fp, fname, "r") gkyl_dynvec_read_ncomp_1(fp, &enc); return enc; } -static bool -gkyl_dynvec_read_1(gkyl_dynvec vec, FILE *fp) { +static bool gkyl_dynvec_read_1(gkyl_dynvec vec, FILE *fp) +{ size_t frr; // Version 1 header char g0[6]; - if (1 != fread(g0, sizeof(char[5]), 1, fp)) + if (1 != fread(g0, sizeof(char[5]), 1, fp)) { return false; + } g0[5] = '\0'; // add the NULL - if (strcmp(g0, "gkyl0") != 0) + if (strcmp(g0, "gkyl0") != 0) { return false; + } uint64_t version; frr = fread(&version, sizeof(uint64_t), 1, fp); - if (version != 1) + if (version != 1) { return false; + } uint64_t file_type; frr = fread(&file_type, sizeof(uint64_t), 1, fp); - if (file_type != gkyl_file_type_int[GKYL_DYNVEC_DATA_FILE]) + if (file_type != gkyl_file_type_int[GKYL_DYNVEC_DATA_FILE]) { return false; + } uint64_t meta_size; frr = fread(&meta_size, sizeof(uint64_t), 1, fp); @@ -342,19 +346,24 @@ gkyl_dynvec_read_1(gkyl_dynvec vec, FILE *fp) { fseek(fp, meta_size, SEEK_CUR); uint64_t real_type = 0; - if (1 != fread(&real_type, sizeof(uint64_t), 1, fp)) + if (1 != fread(&real_type, sizeof(uint64_t), 1, fp)) { return false; - if (real_type != gkyl_array_data_type[vec->type]) + } + if (real_type != gkyl_array_data_type[vec->type]) { return false; + } uint64_t esznc, size; - if (1 != fread(&esznc, sizeof(uint64_t), 1, fp)) + if (1 != fread(&esznc, sizeof(uint64_t), 1, fp)) { return false; - if (vec->esznc != esznc) + } + if (vec->esznc != esznc) { return false; + } - if (1 != fread(&size, sizeof(uint64_t), 1, fp)) + if (1 != fread(&size, sizeof(uint64_t), 1, fp)) { return false; + } // resize vector to allow storing new data gkyl_dynvec_reserve_more(vec, size); @@ -370,8 +379,7 @@ gkyl_dynvec_read_1(gkyl_dynvec vec, FILE *fp) { return true; } -bool -gkyl_dynvec_read(gkyl_dynvec vec, const char *fname) +bool gkyl_dynvec_read(gkyl_dynvec vec, const char *fname) { bool status = false; FILE *fp = fopen(fname, "r"); @@ -381,23 +389,24 @@ gkyl_dynvec_read(gkyl_dynvec vec, const char *fname) status = gkyl_dynvec_read_1(vec, fp); fpos_t curr_pos; fgetpos(fp, &curr_pos); - + char g0[6]; - if (1 != fread(g0, sizeof(char[5]), 1, fp)) + if (1 != fread(g0, sizeof(char[5]), 1, fp)) { break; + } fsetpos(fp, &curr_pos); } fclose(fp); - + return status; } -void -gkyl_dynvec_to_array(const gkyl_dynvec vec, struct gkyl_array *tm_mesh, - struct gkyl_array *dyndata) +void gkyl_dynvec_to_array( + const gkyl_dynvec vec, struct gkyl_array *tm_mesh, struct gkyl_array *dyndata +) { int nv = gkyl_dynvec_size(vec); - for (int i=0; iref_count); + } } diff --git a/core/zero/eval_offset_fd.c b/core/zero/eval_offset_fd.c index 3c0560f89f..a9880063ba 100644 --- a/core/zero/eval_offset_fd.c +++ b/core/zero/eval_offset_fd.c @@ -4,7 +4,6 @@ #include struct gkyl_eval_offset_fd { - struct gkyl_rect_grid grid; int num_ret_vals; // number of values returned by eval function struct gkyl_offset_descr *offsets; // size num_ret_vals @@ -12,8 +11,7 @@ struct gkyl_eval_offset_fd { void *ctx; // evaluation context }; -gkyl_eval_offset_fd* -gkyl_eval_offset_fd_new(const struct gkyl_eval_offset_fd_inp *inp) +gkyl_eval_offset_fd *gkyl_eval_offset_fd_new(const struct gkyl_eval_offset_fd_inp *inp) { struct gkyl_eval_offset_fd *up = gkyl_malloc(sizeof(*up)); @@ -28,26 +26,29 @@ gkyl_eval_offset_fd_new(const struct gkyl_eval_offset_fd_inp *inp) return up; } -static inline void -comp_to_phys(int ndim, const double *eta, - const double * GKYL_RESTRICT dx, const double * GKYL_RESTRICT xc, - double* GKYL_RESTRICT xout) +static inline void comp_to_phys( + int ndim, const double *eta, const double *GKYL_RESTRICT dx, const double *GKYL_RESTRICT xc, + double *GKYL_RESTRICT xout +) { - for (int d=0; dnum_ret_vals; double fvals[num_ret_vals]; - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, update_rng); - + while (gkyl_range_iter_next(&iter)) { gkyl_rect_grid_cell_center(&up->grid, iter.idx, xc); @@ -57,7 +58,7 @@ gkyl_eval_offset_fd_advance(const gkyl_eval_offset_fd *up, double xc[GKYL_MAX_DIM]; gkyl_rect_grid_cell_center(&up->grid, iter.idx, xc); - for (int c=0; coffsets); gkyl_free(up); diff --git a/core/zero/eval_on_nodes.c b/core/zero/eval_on_nodes.c index 32c8e7c5f6..39e5458d40 100644 --- a/core/zero/eval_on_nodes.c +++ b/core/zero/eval_on_nodes.c @@ -13,8 +13,8 @@ struct gkyl_eval_on_nodes { evalf_t eval; // function to project void *ctx; // evaluation context - void (*nodal_to_modal)(const double *fnodal, double *fmodal); - + void (*nodal_to_modal)(const double *fnodal, double *fmodal); + int num_basis; // number of basis functions struct gkyl_array *nodes; // local nodal coordinates @@ -23,32 +23,31 @@ struct gkyl_eval_on_nodes { }; // Identity comp to phys coord mapping, for when user doesn't provide a map. -static inline void -c2p_identity(const double *xcomp, double *xphys, void *ctx) +static inline void c2p_identity(const double *xcomp, double *xphys, void *ctx) { struct gkyl_rect_grid *grid = ctx; int ndim = grid->ndim; - for (int d=0; dnodal_to_modal = inp->basis->nodal_to_modal; up->num_basis = inp->basis->num_basis; - // initialize node local coordinates + // initialize node local coordinates up->nodes = gkyl_array_new(GKYL_DOUBLE, inp->grid->ndim, inp->basis->num_basis); inp->basis->node_list(gkyl_array_fetch(up->nodes, 0)); if (inp->c2p_func == 0) { up->c2p = c2p_identity; up->c2p_ctx = &up->grid; // Use grid as the context since all we need is ndim. - } - else { + } else { up->c2p = inp->c2p_func; up->c2p_ctx = inp->c2p_func_ctx; } @@ -75,50 +73,59 @@ gkyl_eval_on_nodes_inew(const struct gkyl_eval_on_nodes_inp *inp) return up; } -static inline void -log_to_comp(int ndim, const double *eta, - const double * GKYL_RESTRICT dx, const double * GKYL_RESTRICT xc, - double* GKYL_RESTRICT xout) +static inline void log_to_comp( + int ndim, const double *eta, const double *GKYL_RESTRICT dx, const double *GKYL_RESTRICT xc, + double *GKYL_RESTRICT xout +) { - for (int d=0; dnodes, node); } -void -gkyl_eval_on_nodes_nod2mod(const struct gkyl_eval_on_nodes *up, const struct gkyl_array *fun_at_nodes, double *f) +void gkyl_eval_on_nodes_nod2mod( + const struct gkyl_eval_on_nodes *up, const struct gkyl_array *fun_at_nodes, double *f +) { const double *fao = gkyl_array_cfetch(fun_at_nodes, 0); // pointer to values at nodes - + int num_ret_vals = up->num_ret_vals; int num_basis = up->num_basis; double fnodal[num_basis]; // to store nodal function values - for (int i=0; inodal_to_modal(fnodal, &f[num_basis*i]); + up->nodal_to_modal(fnodal, &f[num_basis * i]); } } -void -gkyl_eval_on_nodes_advance(const struct gkyl_eval_on_nodes *up, - double tm, const struct gkyl_range *update_range, struct gkyl_array *arr) +void gkyl_eval_on_nodes_advance( + const struct gkyl_eval_on_nodes *up, double tm, const struct gkyl_range *update_range, + struct gkyl_array *arr +) { #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(arr)) assert(false); // arr should be a host array. + if (gkyl_array_is_cu_dev(arr)) { + assert(false); // arr should be a host array. + } #endif double xc[GKYL_MAX_DIM], xmu[GKYL_MAX_DIM]; @@ -129,13 +136,12 @@ gkyl_eval_on_nodes_advance(const struct gkyl_eval_on_nodes *up, struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, update_range); - + while (gkyl_range_iter_next(&iter)) { gkyl_rect_grid_cell_center(&up->grid, iter.idx, xc); - for (int i=0; igrid.ndim, gkyl_array_cfetch(up->nodes, i), - up->grid.dx, xc, xmu); + for (int i = 0; i < num_basis; ++i) { + log_to_comp(up->grid.ndim, gkyl_array_cfetch(up->nodes, i), up->grid.dx, xc, xmu); up->c2p(xmu, xmu, up->c2p_ctx); up->eval(tm, xmu, gkyl_array_fetch(fun_at_nodes, i), up->ctx); } @@ -147,8 +153,7 @@ gkyl_eval_on_nodes_advance(const struct gkyl_eval_on_nodes *up, gkyl_array_release(fun_at_nodes); } -void -gkyl_eval_on_nodes_release(struct gkyl_eval_on_nodes* up) +void gkyl_eval_on_nodes_release(struct gkyl_eval_on_nodes *up) { gkyl_array_release(up->nodes); gkyl_free(up); diff --git a/core/zero/fv_proj.c b/core/zero/fv_proj.c index 7ee84cfa12..aac9fc12a0 100644 --- a/core/zero/fv_proj.c +++ b/core/zero/fv_proj.c @@ -3,9 +3,9 @@ #include #include -gkyl_fv_proj* -gkyl_fv_proj_new(const struct gkyl_rect_grid *grid, - int num_quad, int num_ret_vals, evalf_t eval, void *ctx) +gkyl_fv_proj *gkyl_fv_proj_new( + const struct gkyl_rect_grid *grid, int num_quad, int num_ret_vals, evalf_t eval, void *ctx +) { // This updater is just a wrapper around more general // gkyl_proj_on_basis updater, however specialized to poly_order=0 @@ -14,19 +14,18 @@ gkyl_fv_proj_new(const struct gkyl_rect_grid *grid, return gkyl_proj_on_basis_new(grid, &basis, num_quad, num_ret_vals, eval, ctx); } -void -gkyl_fv_proj_advance(const gkyl_fv_proj *pob, - double tm, const struct gkyl_range *update_rng, struct gkyl_array *out) +void gkyl_fv_proj_advance( + const gkyl_fv_proj *pob, double tm, const struct gkyl_range *update_rng, struct gkyl_array *out +) { gkyl_proj_on_basis_advance(pob, tm, update_rng, out); // from projections, compute cell average - double denorm = 1.0/sqrt(pow(2, update_rng->ndim)); + double denorm = 1.0 / sqrt(pow(2, update_rng->ndim)); gkyl_array_scale_range(out, denorm, update_rng); } -void -gkyl_fv_proj_release(gkyl_fv_proj* pob) +void gkyl_fv_proj_release(gkyl_fv_proj *pob) { gkyl_proj_on_basis_release(pob); } diff --git a/core/zero/gauss_quad_data.c b/core/zero/gauss_quad_data.c index e49b31bd5c..5e0aa3900f 100644 --- a/core/zero/gauss_quad_data.c +++ b/core/zero/gauss_quad_data.c @@ -7,43 +7,40 @@ #define GUASS_QUAD_EPS 3.0e-15 // This is based on an implementation in Numerical Recipes in C book -static void -priv_gkyl_gauleg( double x1, double x2, double x[], double w[], int n) +static void priv_gkyl_gauleg(double x1, double x2, double x[], double w[], int n) { double z1, xm, xl, pp, p3, p2, p1; - int m = (n+1)/2; - - xm = 0.5*(x2+x1); - xl = 0.5*(x2-x1); + int m = (n + 1) / 2; + + xm = 0.5 * (x2 + x1); + xl = 0.5 * (x2 - x1); for (int i = 1; i <= m; i++) { - double z = cos(GKYL_PI*(i-0.25)/(n+0.5)); + double z = cos(GKYL_PI * (i - 0.25) / (n + 0.5)); do { p1 = 1.0; p2 = 0.0; for (int j = 1; j <= n; j++) { p3 = p2; p2 = p1; - p1 = ((2.0*j-1.0)*z*p2-(j-1.0)*p3)/j; + p1 = ((2.0 * j - 1.0) * z * p2 - (j - 1.0) * p3) / j; } - pp = n*(z*p1-p2)/(z*z-1.0); + pp = n * (z * p1 - p2) / (z * z - 1.0); z1 = z; - z = z1-p1/pp; - } while( fabs(z-z1) > GUASS_QUAD_EPS ); - x[i] = xm-xl*z; - x[n+1-i] = xm+xl*z; - w[i] = 2.0*xl/((1.0-z*z)*pp*pp); - w[n+1-i] = w[i]; + z = z1 - p1 / pp; + } while (fabs(z - z1) > GUASS_QUAD_EPS); + x[i] = xm - xl * z; + x[n + 1 - i] = xm + xl * z; + w[i] = 2.0 * xl / ((1.0 - z * z) * pp * pp); + w[n + 1 - i] = w[i]; } } -void -gkyl_gauleg(double x1, double x2, double x[], double w[], int n) +void gkyl_gauleg(double x1, double x2, double x[], double w[], int n) { - priv_gkyl_gauleg(x1, x2, x-1, w-1, n); // actual routine assumes 1-offset arrays + priv_gkyl_gauleg(x1, x2, x - 1, w - 1, n); // actual routine assumes 1-offset arrays } -void -gkyl_ndim_ordinates_weights(int ndim, double *x, double *w, int nq) +void gkyl_ndim_ordinates_weights(int ndim, double *x, double *w, int nq) { double ordinates1[nq], weights1[nq]; @@ -52,14 +49,15 @@ gkyl_ndim_ordinates_weights(int ndim, double *x, double *w, int nq) // than computing them on the fly) memcpy(ordinates1, gkyl_gauss_ordinates[nq], sizeof(double[nq])); memcpy(weights1, gkyl_gauss_weights[nq], sizeof(double[nq])); - } - else { + } else { gkyl_gauleg(-1, 1, ordinates1, weights1, nq); } - + int shape[ndim]; - for (int d=0; ddata) + loc*arr->esznc; + return ((char *)arr->data) + loc * arr->esznc; } /** Same as above, except fetches a constant pointer */ -GKYL_CU_DH -static inline const void* -gkyl_array_cfetch(const struct gkyl_array* arr, long loc) +GKYL_CU_DH static inline const void *gkyl_array_cfetch(const struct gkyl_array *arr, long loc) { - return ((const char*) arr->data) + loc*arr->esznc; + return ((const char *)arr->data) + loc * arr->esznc; } /** @@ -161,11 +154,11 @@ gkyl_array_cfetch(const struct gkyl_array* arr, long loc) * @param arr Array to which a pointer is needed * @return Pointer to acquired array */ -struct gkyl_array* gkyl_array_acquire(const struct gkyl_array* arr); +struct gkyl_array *gkyl_array_acquire(const struct gkyl_array *arr); /** * Release pointer to array * * @param arr Array to release. */ -void gkyl_array_release(const struct gkyl_array* arr); +void gkyl_array_release(const struct gkyl_array *arr); diff --git a/core/zero/gkyl_array_average.h b/core/zero/gkyl_array_average.h index 6bd407ae94..9e47f535f9 100644 --- a/core/zero/gkyl_array_average.h +++ b/core/zero/gkyl_array_average.h @@ -66,8 +66,7 @@ struct gkyl_array_average_inp { * * @param inp see gkyl_array_average_inp structure */ -struct gkyl_array_average* -gkyl_array_average_inew(const struct gkyl_array_average_inp *inp); +struct gkyl_array_average *gkyl_array_average_inew(const struct gkyl_array_average_inp *inp); /** * Create a new updater that computes the weighted average of a gkyl_array. @@ -82,10 +81,12 @@ gkyl_array_average_inew(const struct gkyl_array_average_inp *inp); * @param avg_dim Flag array to set which dimension is averaged * @param use_gpu Boolean flag indicating whether the computation should be performed on a GPU. */ -struct gkyl_array_average* -gkyl_array_average_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, - const struct gkyl_basis *basis_avg, const struct gkyl_range *local, const struct gkyl_range *local_avg, - const struct gkyl_range *local_avg_ext, const struct gkyl_array *weight, const int *avg_dim, bool use_gpu); +struct gkyl_array_average *gkyl_array_average_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_basis *basis_avg, const struct gkyl_range *local, + const struct gkyl_range *local_avg, const struct gkyl_range *local_avg_ext, + const struct gkyl_array *weight, const int *avg_dim, bool use_gpu +); /** * Compute the array average. Note: the weight is linked to the updater. @@ -94,8 +95,9 @@ gkyl_array_average_new(const struct gkyl_rect_grid *grid, const struct gkyl_basi * @param fin input gkyl_array * @param avgout Output gkyl_array */ -void gkyl_array_average_advance(const struct gkyl_array_average *up, - const struct gkyl_array *fin, struct gkyl_array *avgout); +void gkyl_array_average_advance( + const struct gkyl_array_average *up, const struct gkyl_array *fin, struct gkyl_array *avgout +); /** * Release memory associated with this updater. diff --git a/core/zero/gkyl_array_average_priv.h b/core/zero/gkyl_array_average_priv.h index 3d81677794..5790056d4c 100644 --- a/core/zero/gkyl_array_average_priv.h +++ b/core/zero/gkyl_array_average_priv.h @@ -10,49 +10,48 @@ #include // function pointer type for array_average kernels. -typedef void (*array_average_t)( const double subvol, const double *win, const double *fin, double* GKYL_RESTRICT out); +typedef void (*array_average_t)( + const double subvol, const double *win, const double *fin, double *GKYL_RESTRICT out +); // for use in kernel tables. -typedef struct { array_average_t kernels[2]; } array_average_kern_list; -typedef struct { array_average_kern_list list[7]; } dim_array_average_kern_list; - -GKYL_CU_D -static const dim_array_average_kern_list gkyl_array_average_ker_list[] = { - { // kernel list for 1x integration - .list = - { - {gkyl_array_average_1x_ser_p1_avgx, gkyl_array_average_1x_ser_p2_avgx}, - {NULL, NULL}, - {NULL, NULL}, - {NULL, NULL}, - {NULL, NULL}, - {NULL, NULL}, - {NULL, NULL}, - } +typedef struct { + array_average_t kernels[2]; +} array_average_kern_list; +typedef struct { + array_average_kern_list list[7]; +} dim_array_average_kern_list; + +GKYL_CU_D static const dim_array_average_kern_list gkyl_array_average_ker_list[] = { + {// kernel list for 1x integration + .list = + {{gkyl_array_average_1x_ser_p1_avgx, gkyl_array_average_1x_ser_p2_avgx}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}} }, - { // kernel list for 2x integration - .list = - { - {gkyl_array_average_2x_ser_p1_avgx, gkyl_array_average_2x_ser_p2_avgy}, - {gkyl_array_average_2x_ser_p1_avgy, gkyl_array_average_2x_ser_p2_avgy}, - {gkyl_array_average_2x_ser_p1_avgxy, gkyl_array_average_2x_ser_p2_avgxy}, - {NULL, NULL}, - {NULL, NULL}, - {NULL, NULL}, - {NULL, NULL}, - } + {// kernel list for 2x integration + .list = + {{gkyl_array_average_2x_ser_p1_avgx, gkyl_array_average_2x_ser_p2_avgy}, + {gkyl_array_average_2x_ser_p1_avgy, gkyl_array_average_2x_ser_p2_avgy}, + {gkyl_array_average_2x_ser_p1_avgxy, gkyl_array_average_2x_ser_p2_avgxy}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}} }, - { // kernel list for 3x integration - .list = - { - {gkyl_array_average_3x_ser_p1_avgx, gkyl_array_average_3x_ser_p2_avgx}, - {gkyl_array_average_3x_ser_p1_avgy, gkyl_array_average_3x_ser_p2_avgy}, - {gkyl_array_average_3x_ser_p1_avgxy, gkyl_array_average_3x_ser_p2_avgxy}, - {gkyl_array_average_3x_ser_p1_avgz, gkyl_array_average_3x_ser_p2_avgz}, - {gkyl_array_average_3x_ser_p1_avgxz, gkyl_array_average_3x_ser_p2_avgxz}, - {gkyl_array_average_3x_ser_p1_avgyz, gkyl_array_average_3x_ser_p2_avgyz}, - {gkyl_array_average_3x_ser_p1_avgxyz, gkyl_array_average_3x_ser_p2_avgxyz}, - } + {// kernel list for 3x integration + .list = + {{gkyl_array_average_3x_ser_p1_avgx, gkyl_array_average_3x_ser_p2_avgx}, + {gkyl_array_average_3x_ser_p1_avgy, gkyl_array_average_3x_ser_p2_avgy}, + {gkyl_array_average_3x_ser_p1_avgxy, gkyl_array_average_3x_ser_p2_avgxy}, + {gkyl_array_average_3x_ser_p1_avgz, gkyl_array_average_3x_ser_p2_avgz}, + {gkyl_array_average_3x_ser_p1_avgxz, gkyl_array_average_3x_ser_p2_avgxz}, + {gkyl_array_average_3x_ser_p1_avgyz, gkyl_array_average_3x_ser_p2_avgyz}, + {gkyl_array_average_3x_ser_p1_avgxyz, gkyl_array_average_3x_ser_p2_avgxyz}} } }; @@ -83,13 +82,13 @@ struct gkyl_array_average { // examples: // - for 3x op_yz, then sub_dir = {1,2}, // - for 2x op_x, then sub_dir = {0} - int sub_dir[GKYL_MAX_CDIM]; + int sub_dir[GKYL_MAX_CDIM]; // Single-cell sub-volume element (length for 1D avg, area for 2D) double subvol; // Single cell average kernel. - array_average_t kernel; + array_average_t kernel; // Pointer to itself on device. struct gkyl_array_average *on_dev; @@ -100,33 +99,31 @@ struct gkyl_array_average { struct gkyl_array *weight; struct gkyl_array *weight_avg; // inverse volume of the average domain - double vol_avg_inv; + double vol_avg_inv; // memory for the weak division at the end of averaging gkyl_dg_bin_op_mem *div_mem; - }; -GKYL_CU_D static -void gkyl_array_average_choose_kernel(struct gkyl_array_average *up) +GKYL_CU_D static void gkyl_array_average_choose_kernel(struct gkyl_array_average *up) { - int ndim = up->basis.ndim, poly_order = up->basis.poly_order; + int ndim = up->basis.ndim, poly_order = up->basis.poly_order; - // We encode the average operations as a binary number + // We encode the average operations as a binary number // (e.g. 011 = 3 = avgxy, 101 = 5 = avgxz, 111 = 7 = avgxyz) int op = -1; // -1 shifted to start with 0 - for (int d = 0; d < ndim; d++) - op += pow(2,d) * up->avg_dim[d]; - - up->kernel = gkyl_array_average_ker_list[ndim-1].list[op].kernels[poly_order-1]; + for (int d = 0; d < ndim; d++) { + op += pow(2, d) * up->avg_dim[d]; + } + up->kernel = gkyl_array_average_ker_list[ndim - 1].list[op].kernels[poly_order - 1]; } #ifdef GKYL_HAVE_CUDA // Device new functions -struct gkyl_array_average* -gkyl_array_average_cu_dev_new(struct gkyl_array_average *up); +struct gkyl_array_average *gkyl_array_average_cu_dev_new(struct gkyl_array_average *up); // Device advance functions -void gkyl_array_average_advance_cu(const struct gkyl_array_average *up, -const struct gkyl_array *fin, struct gkyl_array *avgout); +void gkyl_array_average_advance_cu( + const struct gkyl_array_average *up, const struct gkyl_array *fin, struct gkyl_array *avgout +); #endif diff --git a/core/zero/gkyl_array_dg_reduce.h b/core/zero/gkyl_array_dg_reduce.h index d0253d6b2c..abac203e0d 100644 --- a/core/zero/gkyl_array_dg_reduce.h +++ b/core/zero/gkyl_array_dg_reduce.h @@ -18,8 +18,10 @@ * @param op Reduction operators. * @param basis Basis DG coefficients are expanded in (device pointer if use_gpu=true). */ -void gkyl_array_dg_reducec(double *out, const struct gkyl_array *arr, int comp, - enum gkyl_array_op op, const struct gkyl_basis *basis); +void gkyl_array_dg_reducec( + double *out, const struct gkyl_array *arr, int comp, enum gkyl_array_op op, + const struct gkyl_basis *basis +); /** * Perform a "reduce" operation of data in the array accounting for the DG @@ -35,7 +37,7 @@ void gkyl_array_dg_reducec(double *out, const struct gkyl_array *arr, int comp, * @param basis Basis DG coefficients are expanded in (device pointer if use_gpu=true). * @param range Range specifying region. */ -void gkyl_array_dg_reducec_range(double *out, const struct gkyl_array *arr, int comp, - enum gkyl_array_op op, const struct gkyl_basis *basis, const struct gkyl_range *range); - - +void gkyl_array_dg_reducec_range( + double *out, const struct gkyl_array *arr, int comp, enum gkyl_array_op op, + const struct gkyl_basis *basis, const struct gkyl_range *range +); diff --git a/core/zero/gkyl_array_dg_reduce_priv.h b/core/zero/gkyl_array_dg_reduce_priv.h index 2e952893b6..06d39a3b0d 100644 --- a/core/zero/gkyl_array_dg_reduce_priv.h +++ b/core/zero/gkyl_array_dg_reduce_priv.h @@ -14,7 +14,9 @@ * @param comp Vector component to reduce. * @param basis Baisis DG coefficients expand in (device pointer). */ -void gkyl_array_dg_reducec_max_cu(double *out_d, const struct gkyl_array* inp, int comp, const struct gkyl_basis *basis); +void gkyl_array_dg_reducec_max_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis +); /** * Min reduce a gkyl_array evaluating the DG field in each cell at Gauss-Legendre nodes @@ -26,7 +28,9 @@ void gkyl_array_dg_reducec_max_cu(double *out_d, const struct gkyl_array* inp, i * @param comp Vector component to reduce. * @param basis Baisis DG coefficients expand in (device pointer). */ -void gkyl_array_dg_reducec_min_cu(double *out_d, const struct gkyl_array* inp, int comp, const struct gkyl_basis *basis); +void gkyl_array_dg_reducec_min_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis +); /** * Sum reduce a gkyl_array evaluating the DG field in each cell at Gauss-Legendre nodes @@ -38,7 +42,9 @@ void gkyl_array_dg_reducec_min_cu(double *out_d, const struct gkyl_array* inp, i * @param comp Vector component to reduce. * @param basis Baisis DG coefficients expand in (device pointer). */ -void gkyl_array_dg_reducec_sum_cu(double *out_d, const struct gkyl_array* inp, int comp, const struct gkyl_basis *basis); +void gkyl_array_dg_reducec_sum_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis +); /** * Max reduce a gkyl_array evaluating the DG field in each cell (within the input range) @@ -50,8 +56,10 @@ void gkyl_array_dg_reducec_sum_cu(double *out_d, const struct gkyl_array* inp, i * @param comp Vector component to reduce. * @param basis Baisis DG coefficients expand in (device pointer). */ -void gkyl_array_dg_reducec_range_max_cu(double *out_d, const struct gkyl_array* inp, - int comp, const struct gkyl_basis *basis, const struct gkyl_range *range); +void gkyl_array_dg_reducec_range_max_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis, + const struct gkyl_range *range +); /** * Min reduce a gkyl_array evaluating the DG field in each cell (within the input range) @@ -63,8 +71,10 @@ void gkyl_array_dg_reducec_range_max_cu(double *out_d, const struct gkyl_array* * @param comp Vector component to reduce. * @param basis Baisis DG coefficients expand in (device pointer). */ -void gkyl_array_dg_reducec_range_min_cu(double *out_d, const struct gkyl_array* inp, - int comp, const struct gkyl_basis *basis, const struct gkyl_range *range); +void gkyl_array_dg_reducec_range_min_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis, + const struct gkyl_range *range +); /** * Sum reduce a gkyl_array evaluating the DG field in each cell (within the input range) @@ -76,7 +86,9 @@ void gkyl_array_dg_reducec_range_min_cu(double *out_d, const struct gkyl_array* * @param comp Vector component to reduce. * @param basis Baisis DG coefficients expand in (device pointer). */ -void gkyl_array_dg_reducec_range_sum_cu(double *out_d, const struct gkyl_array* inp, - int comp, const struct gkyl_basis *basis, const struct gkyl_range *range); +void gkyl_array_dg_reducec_range_sum_cu( + double *out_d, const struct gkyl_array *inp, int comp, const struct gkyl_basis *basis, + const struct gkyl_range *range +); #endif diff --git a/core/zero/gkyl_array_integrate.h b/core/zero/gkyl_array_integrate.h index 4a87615d53..ad057f46e0 100644 --- a/core/zero/gkyl_array_integrate.h +++ b/core/zero/gkyl_array_integrate.h @@ -9,13 +9,13 @@ typedef struct gkyl_array_integrate gkyl_array_integrate; enum gkyl_array_integrate_op { - GKYL_ARRAY_INTEGRATE_OP_NONE = 0, // int dx f - GKYL_ARRAY_INTEGRATE_OP_ABS, // int dx |f| - GKYL_ARRAY_INTEGRATE_OP_SQ, // int dx f^2 - GKYL_ARRAY_INTEGRATE_OP_SQ_WEIGHTED, // int dx w * f^2 - GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ, // int dx |nabla f|^2 - GKYL_ARRAY_INTEGRATE_OP_GRADPERP_SQ, // int dx |nabla_perp f|^2 - GKYL_ARRAY_INTEGRATE_OP_EPS_GRADPERP_SQ, // int dx epsilon*|nabla_perp f|^2 + GKYL_ARRAY_INTEGRATE_OP_NONE = 0, // int dx f + GKYL_ARRAY_INTEGRATE_OP_ABS, // int dx |f| + GKYL_ARRAY_INTEGRATE_OP_SQ, // int dx f^2 + GKYL_ARRAY_INTEGRATE_OP_SQ_WEIGHTED, // int dx w * f^2 + GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ, // int dx |nabla f|^2 + GKYL_ARRAY_INTEGRATE_OP_GRADPERP_SQ, // int dx |nabla_perp f|^2 + GKYL_ARRAY_INTEGRATE_OP_EPS_GRADPERP_SQ // int dx epsilon*|nabla_perp f|^2 }; /** @@ -28,9 +28,10 @@ enum gkyl_array_integrate_op { * @param op Additional operator to apply in very cell. * @param use_gpu Indicate whether to perform integral on the device. */ -struct gkyl_array_integrate* -gkyl_array_integrate_new(const struct gkyl_rect_grid* grid, const struct gkyl_basis* basis, - int num_comp, enum gkyl_array_integrate_op op, bool use_gpu); +struct gkyl_array_integrate *gkyl_array_integrate_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, int num_comp, + enum gkyl_array_integrate_op op, bool use_gpu +); /** * Compute the array integral. @@ -43,9 +44,11 @@ gkyl_array_integrate_new(const struct gkyl_rect_grid* grid, const struct gkyl_ba * @param weight_range Range of the weight. * @return out Output integral result(s). On device memory if use_gpu=true. */ -void gkyl_array_integrate_advance(gkyl_array_integrate *up, const struct gkyl_array *fin, - double factor, const struct gkyl_array *weight, const struct gkyl_range *range, - const struct gkyl_range *weight_range, double *out); +void gkyl_array_integrate_advance( + gkyl_array_integrate *up, const struct gkyl_array *fin, double factor, + const struct gkyl_array *weight, const struct gkyl_range *range, + const struct gkyl_range *weight_range, double *out +); /** * Release memory associated with this updater. diff --git a/core/zero/gkyl_array_integrate_priv.h b/core/zero/gkyl_array_integrate_priv.h index 424fc84695..21cf2c90a4 100644 --- a/core/zero/gkyl_array_integrate_priv.h +++ b/core/zero/gkyl_array_integrate_priv.h @@ -9,74 +9,88 @@ #include // Function pointer type for array_integrate kernels. -typedef void (*array_integrate_t)(double *dxSq, double vol, int num_comp, - int num_basis, const double *weight, const double *fIn, double *out); +typedef void (*array_integrate_t)( + double *dxSq, double vol, int num_comp, int num_basis, const double *weight, const double *fIn, + double *out +); // For use in kernel tables. -typedef struct { array_integrate_t kernels[2]; } array_integrate_none_kern_list; -typedef struct { array_integrate_t kernels[2]; } array_integrate_abs_kern_list; -typedef struct { array_integrate_t kernels[2]; } array_integrate_sq_kern_list; -typedef struct { array_integrate_t kernels[2]; } array_integrate_sq_weighted_kern_list; -typedef struct { array_integrate_t kernels[2]; } array_integrate_gradsq_kern_list; -typedef struct { array_integrate_t kernels[2]; } array_integrate_gradperpsq_kern_list; -typedef struct { array_integrate_t kernels[2]; } array_integrate_epsgradperpsq_kern_list; - -GKYL_CU_D -static const array_integrate_none_kern_list gkyl_array_integrate_none_ker_list_ser[] = { +typedef struct { + array_integrate_t kernels[2]; +} array_integrate_none_kern_list; +typedef struct { + array_integrate_t kernels[2]; +} array_integrate_abs_kern_list; +typedef struct { + array_integrate_t kernels[2]; +} array_integrate_sq_kern_list; +typedef struct { + array_integrate_t kernels[2]; +} array_integrate_sq_weighted_kern_list; +typedef struct { + array_integrate_t kernels[2]; +} array_integrate_gradsq_kern_list; +typedef struct { + array_integrate_t kernels[2]; +} array_integrate_gradperpsq_kern_list; +typedef struct { + array_integrate_t kernels[2]; +} array_integrate_epsgradperpsq_kern_list; + +GKYL_CU_D static const array_integrate_none_kern_list gkyl_array_integrate_none_ker_list_ser[] = { {gkyl_array_integrate_op_none_1x_ser_p1, gkyl_array_integrate_op_none_1x_ser_p2}, {gkyl_array_integrate_op_none_2x_ser_p1, gkyl_array_integrate_op_none_2x_ser_p2}, - {gkyl_array_integrate_op_none_3x_ser_p1, gkyl_array_integrate_op_none_3x_ser_p2}, + {gkyl_array_integrate_op_none_3x_ser_p1, gkyl_array_integrate_op_none_3x_ser_p2} }; -GKYL_CU_D -static const array_integrate_abs_kern_list gkyl_array_integrate_abs_ker_list_ser[] = { +GKYL_CU_D static const array_integrate_abs_kern_list gkyl_array_integrate_abs_ker_list_ser[] = { {gkyl_array_integrate_op_abs_1x_ser_p1, gkyl_array_integrate_op_abs_1x_ser_p2}, {gkyl_array_integrate_op_abs_2x_ser_p1, gkyl_array_integrate_op_abs_2x_ser_p2}, - {gkyl_array_integrate_op_abs_3x_ser_p1, gkyl_array_integrate_op_abs_3x_ser_p2}, + {gkyl_array_integrate_op_abs_3x_ser_p1, gkyl_array_integrate_op_abs_3x_ser_p2} }; -GKYL_CU_D -static const array_integrate_sq_kern_list gkyl_array_integrate_sq_ker_list_ser[] = { +GKYL_CU_D static const array_integrate_sq_kern_list gkyl_array_integrate_sq_ker_list_ser[] = { {gkyl_array_integrate_op_sq_1x_ser_p1, gkyl_array_integrate_op_sq_1x_ser_p2}, {gkyl_array_integrate_op_sq_2x_ser_p1, gkyl_array_integrate_op_sq_2x_ser_p2}, - {gkyl_array_integrate_op_sq_3x_ser_p1, gkyl_array_integrate_op_sq_3x_ser_p2}, + {gkyl_array_integrate_op_sq_3x_ser_p1, gkyl_array_integrate_op_sq_3x_ser_p2} }; -GKYL_CU_D -static const array_integrate_sq_weighted_kern_list gkyl_array_integrate_sq_weighted_ker_list_ser[] = { - {gkyl_array_integrate_op_sq_weighted_1x_ser_p1, gkyl_array_integrate_op_sq_weighted_1x_ser_p2}, - {gkyl_array_integrate_op_sq_weighted_2x_ser_p1, gkyl_array_integrate_op_sq_weighted_2x_ser_p2}, - {gkyl_array_integrate_op_sq_weighted_3x_ser_p1, gkyl_array_integrate_op_sq_weighted_3x_ser_p2}, +GKYL_CU_D static const array_integrate_sq_weighted_kern_list + gkyl_array_integrate_sq_weighted_ker_list_ser[] = { + {gkyl_array_integrate_op_sq_weighted_1x_ser_p1, gkyl_array_integrate_op_sq_weighted_1x_ser_p2}, + {gkyl_array_integrate_op_sq_weighted_2x_ser_p1, gkyl_array_integrate_op_sq_weighted_2x_ser_p2}, + {gkyl_array_integrate_op_sq_weighted_3x_ser_p1, gkyl_array_integrate_op_sq_weighted_3x_ser_p2} }; -GKYL_CU_D -static const array_integrate_sq_weighted_kern_list gkyl_array_integrate_sq_weighted_ker_list_gkhyb[] = { - {NULL, NULL}, - {gkyl_array_integrate_op_sq_weighted_1x1v_gkhyb_p1, NULL}, - {gkyl_array_integrate_op_sq_weighted_1x2v_gkhyb_p1, NULL}, - {gkyl_array_integrate_op_sq_weighted_2x2v_gkhyb_p1, NULL}, - {gkyl_array_integrate_op_sq_weighted_3x2v_gkhyb_p1, NULL}, +GKYL_CU_D static const array_integrate_sq_weighted_kern_list + gkyl_array_integrate_sq_weighted_ker_list_gkhyb[] = { + {NULL, NULL}, + {gkyl_array_integrate_op_sq_weighted_1x1v_gkhyb_p1, NULL}, + {gkyl_array_integrate_op_sq_weighted_1x2v_gkhyb_p1, NULL}, + {gkyl_array_integrate_op_sq_weighted_2x2v_gkhyb_p1, NULL}, + {gkyl_array_integrate_op_sq_weighted_3x2v_gkhyb_p1, NULL} }; -GKYL_CU_D -static const array_integrate_gradsq_kern_list gkyl_array_integrate_gradsq_ker_list[] = { +GKYL_CU_D static const array_integrate_gradsq_kern_list gkyl_array_integrate_gradsq_ker_list[] = { {gkyl_array_integrate_op_grad_sq_1x_ser_p1, gkyl_array_integrate_op_grad_sq_1x_ser_p2}, {gkyl_array_integrate_op_grad_sq_2x_ser_p1, gkyl_array_integrate_op_grad_sq_2x_ser_p2}, - {gkyl_array_integrate_op_grad_sq_3x_ser_p1, NULL}, + {gkyl_array_integrate_op_grad_sq_3x_ser_p1, NULL} }; -GKYL_CU_D -static const array_integrate_gradperpsq_kern_list gkyl_array_integrate_gradperpsq_ker_list[] = { - {NULL, NULL}, - {gkyl_array_integrate_op_grad_sq_2x_ser_p1, gkyl_array_integrate_op_grad_sq_2x_ser_p2}, - {gkyl_array_integrate_op_gradperp_sq_3x_ser_p1, gkyl_array_integrate_op_gradperp_sq_3x_ser_p2}, +GKYL_CU_D static const array_integrate_gradperpsq_kern_list + gkyl_array_integrate_gradperpsq_ker_list[] = { + {NULL, NULL}, + {gkyl_array_integrate_op_grad_sq_2x_ser_p1, gkyl_array_integrate_op_grad_sq_2x_ser_p2}, + {gkyl_array_integrate_op_gradperp_sq_3x_ser_p1, gkyl_array_integrate_op_gradperp_sq_3x_ser_p2} }; -GKYL_CU_D -static const array_integrate_epsgradperpsq_kern_list gkyl_array_integrate_epsgradperpsq_ker_list[] = { - {NULL, NULL}, - {gkyl_array_integrate_op_eps_gradperp_sq_2x_ser_p1, gkyl_array_integrate_op_eps_gradperp_sq_2x_ser_p2}, - {gkyl_array_integrate_op_eps_gradperp_sq_3x_ser_p1, gkyl_array_integrate_op_eps_gradperp_sq_3x_ser_p2}, +GKYL_CU_D static const array_integrate_epsgradperpsq_kern_list + gkyl_array_integrate_epsgradperpsq_ker_list[] = { + {NULL, NULL}, + {gkyl_array_integrate_op_eps_gradperp_sq_2x_ser_p1, + gkyl_array_integrate_op_eps_gradperp_sq_2x_ser_p2}, + {gkyl_array_integrate_op_eps_gradperp_sq_3x_ser_p1, + gkyl_array_integrate_op_eps_gradperp_sq_3x_ser_p2} }; // Primary struct in this updater. @@ -85,50 +99,49 @@ struct gkyl_array_integrate { int num_basis, num_comp; bool use_gpu; double dxSq[GKYL_MAX_DIM]; - double vol; // Single-cell volume factor. - array_integrate_t kernel; // Single cell integration kernel. - struct gkyl_array_integrate *on_dev; // Pointer to itself on device. + double vol; // Single-cell volume factor. + array_integrate_t kernel; // Single cell integration kernel. + struct gkyl_array_integrate *on_dev; // Pointer to itself on device. }; -GKYL_CU_D static -void gkyl_array_integrate_choose_kernel(enum gkyl_array_integrate_op op, - const struct gkyl_basis *basis, struct gkyl_array_integrate *up) +GKYL_CU_D static void gkyl_array_integrate_choose_kernel( + enum gkyl_array_integrate_op op, const struct gkyl_basis *basis, struct gkyl_array_integrate *up +) { int ndim = basis->ndim, poly_order = basis->poly_order; if (op == GKYL_ARRAY_INTEGRATE_OP_NONE) { - up->kernel = gkyl_array_integrate_none_ker_list_ser[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_ABS) { - up->kernel = gkyl_array_integrate_abs_ker_list_ser[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_SQ) { - up->kernel = gkyl_array_integrate_sq_ker_list_ser[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_SQ_WEIGHTED) { - if (basis->b_type == GKYL_BASIS_MODAL_SERENDIPITY) - up->kernel = gkyl_array_integrate_sq_weighted_ker_list_ser[ndim-1].kernels[poly_order-1]; - else if (basis->b_type == GKYL_BASIS_MODAL_GKHYBRID) - up->kernel = gkyl_array_integrate_sq_weighted_ker_list_gkhyb[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ) { - up->kernel = gkyl_array_integrate_gradsq_ker_list[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_GRADPERP_SQ) { - up->kernel = gkyl_array_integrate_gradperpsq_ker_list[ndim-1].kernels[poly_order-1]; - } - else if (op == GKYL_ARRAY_INTEGRATE_OP_EPS_GRADPERP_SQ) { - up->kernel = gkyl_array_integrate_epsgradperpsq_ker_list[ndim-1].kernels[poly_order-1]; - } - else { + up->kernel = gkyl_array_integrate_none_ker_list_ser[ndim - 1].kernels[poly_order - 1]; + } else if (op == GKYL_ARRAY_INTEGRATE_OP_ABS) { + up->kernel = gkyl_array_integrate_abs_ker_list_ser[ndim - 1].kernels[poly_order - 1]; + } else if (op == GKYL_ARRAY_INTEGRATE_OP_SQ) { + up->kernel = gkyl_array_integrate_sq_ker_list_ser[ndim - 1].kernels[poly_order - 1]; + } else if (op == GKYL_ARRAY_INTEGRATE_OP_SQ_WEIGHTED) { + if (basis->b_type == GKYL_BASIS_MODAL_SERENDIPITY) { + up->kernel = gkyl_array_integrate_sq_weighted_ker_list_ser[ndim - 1].kernels[poly_order - 1]; + } else if (basis->b_type == GKYL_BASIS_MODAL_GKHYBRID) { + up->kernel = + gkyl_array_integrate_sq_weighted_ker_list_gkhyb[ndim - 1].kernels[poly_order - 1]; + } + } else if (op == GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ) { + up->kernel = gkyl_array_integrate_gradsq_ker_list[ndim - 1].kernels[poly_order - 1]; + } else if (op == GKYL_ARRAY_INTEGRATE_OP_GRADPERP_SQ) { + up->kernel = gkyl_array_integrate_gradperpsq_ker_list[ndim - 1].kernels[poly_order - 1]; + } else if (op == GKYL_ARRAY_INTEGRATE_OP_EPS_GRADPERP_SQ) { + up->kernel = gkyl_array_integrate_epsgradperpsq_ker_list[ndim - 1].kernels[poly_order - 1]; + } else { assert(false); } assert(up->kernel); } -struct gkyl_array_integrate* -gkyl_array_integrate_cu_dev_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, - int num_comp, enum gkyl_array_integrate_op op); +struct gkyl_array_integrate *gkyl_array_integrate_cu_dev_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, int num_comp, + enum gkyl_array_integrate_op op +); -void gkyl_array_integrate_advance_cu(gkyl_array_integrate *up, const struct gkyl_array *arr, - double factor, const struct gkyl_array *weight, const struct gkyl_range *range, const struct gkyl_range *weight_range, double *out); +void gkyl_array_integrate_advance_cu( + gkyl_array_integrate *up, const struct gkyl_array *arr, double factor, + const struct gkyl_array *weight, const struct gkyl_range *range, + const struct gkyl_range *weight_range, double *out +); diff --git a/core/zero/gkyl_array_ops.h b/core/zero/gkyl_array_ops.h index 5429fdb67c..06ae5543c0 100644 --- a/core/zero/gkyl_array_ops.h +++ b/core/zero/gkyl_array_ops.h @@ -6,11 +6,9 @@ #include #include -GKYL_CU_DH -static inline void* -gkyl_flat_fetch(void *data, size_t loc) +GKYL_CU_DH static inline void *gkyl_flat_fetch(void *data, size_t loc) { - return ((char*) data) + loc; + return ((char *)data) + loc; } // Struct used to pass function pointer and context to various buffer @@ -33,7 +31,7 @@ struct gkyl_array_diff { double min_abs_diff; // minmum absolute difference double max_rel_diff; // maximum relative difference double min_rel_diff; // minmum relative difference -}; +}; /** * Check if array_copy_func is on device. @@ -41,8 +39,7 @@ struct gkyl_array_diff { * @param bc BC function to check * @return true if eqn on device, false otherwise */ -bool -gkyl_array_copy_func_is_cu_dev(const struct gkyl_array_copy_func *bc); +bool gkyl_array_copy_func_is_cu_dev(const struct gkyl_array_copy_func *bc); /** * Clear out = val. Returns out. @@ -51,7 +48,7 @@ gkyl_array_copy_func_is_cu_dev(const struct gkyl_array_copy_func *bc); * @param val Factor to set * @return out array */ -struct gkyl_array* gkyl_array_clear(struct gkyl_array *out, double val); +struct gkyl_array *gkyl_array_clear(struct gkyl_array *out, double val); /** * Compute out = out + a*inp. Returns out. @@ -61,8 +58,8 @@ struct gkyl_array* gkyl_array_clear(struct gkyl_array *out, double val); * @param inp Input array * @return out array */ -struct gkyl_array* gkyl_array_accumulate(struct gkyl_array *out, - double a, const struct gkyl_array *inp); +struct gkyl_array * +gkyl_array_accumulate(struct gkyl_array *out, double a, const struct gkyl_array *inp); /** * Compute out = out + a*inp[coff] where coff is a component-offset if @@ -75,8 +72,9 @@ struct gkyl_array* gkyl_array_accumulate(struct gkyl_array *out, * @param coff Component offset * @return out array */ -struct gkyl_array* gkyl_array_accumulate_offset(struct gkyl_array *out, - double a, const struct gkyl_array *inp, int coff); +struct gkyl_array *gkyl_array_accumulate_offset( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff +); /** * Set out = a*inp. Returns out. @@ -86,8 +84,7 @@ struct gkyl_array* gkyl_array_accumulate_offset(struct gkyl_array *out, * @param inp Input array * @return out array */ -struct gkyl_array* gkyl_array_set(struct gkyl_array *out, - double a, const struct gkyl_array *inp); +struct gkyl_array *gkyl_array_set(struct gkyl_array *out, double a, const struct gkyl_array *inp); /** * Set out = a*inp[coff] where coff is a component-offset if @@ -100,8 +97,8 @@ struct gkyl_array* gkyl_array_set(struct gkyl_array *out, * @param coff Component offset * @return out array */ -struct gkyl_array* gkyl_array_set_offset(struct gkyl_array *out, - double a, const struct gkyl_array *inp, int coff); +struct gkyl_array * +gkyl_array_set_offset(struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff); /** * Scale out = a*out. Returns out. @@ -110,7 +107,7 @@ struct gkyl_array* gkyl_array_set_offset(struct gkyl_array *out, * @param a Factor to scale * @return out array */ -struct gkyl_array* gkyl_array_scale(struct gkyl_array *out, double a); +struct gkyl_array *gkyl_array_scale(struct gkyl_array *out, double a); /** * Scale out = a*out. Returns out. @@ -119,7 +116,7 @@ struct gkyl_array* gkyl_array_scale(struct gkyl_array *out, double a); * @param a Factor to scale that varies by cell. * @return out array. */ -struct gkyl_array* gkyl_array_scale_by_cell(struct gkyl_array *out, const struct gkyl_array *a); +struct gkyl_array *gkyl_array_scale_by_cell(struct gkyl_array *out, const struct gkyl_array *a); /** * Divide out = out/a. Returns out. @@ -128,7 +125,7 @@ struct gkyl_array* gkyl_array_scale_by_cell(struct gkyl_array *out, const struct * @param a Factor to divide by that varies by cell. * @return out array. */ -struct gkyl_array* gkyl_array_divide_by_cell(struct gkyl_array *out, const struct gkyl_array *a); +struct gkyl_array *gkyl_array_divide_by_cell(struct gkyl_array *out, const struct gkyl_array *a); /** * Compute element-wise reciprocal, out = 1/inp. Returns out. @@ -138,7 +135,7 @@ struct gkyl_array* gkyl_array_divide_by_cell(struct gkyl_array *out, const struc * @param inp Input array. * @return out array. */ -struct gkyl_array* gkyl_array_invert_by_cell(struct gkyl_array *out, const struct gkyl_array *inp); +struct gkyl_array *gkyl_array_invert_by_cell(struct gkyl_array *out, const struct gkyl_array *inp); /** * Shift the k-th coefficient in every cell, out_k = a+out_k. Returns out. @@ -148,7 +145,7 @@ struct gkyl_array* gkyl_array_invert_by_cell(struct gkyl_array *out, const struc * @param k Coefficient to be shifted. * @return out array. */ -struct gkyl_array* gkyl_array_shiftc(struct gkyl_array *out, double a, unsigned k); +struct gkyl_array *gkyl_array_shiftc(struct gkyl_array *out, double a, unsigned k); /** * Take element-wise minimum: out = min(inp, a). Returns out. @@ -159,7 +156,8 @@ struct gkyl_array* gkyl_array_shiftc(struct gkyl_array *out, double a, unsigned * @param a Value to compare against each element. * @return out array. */ -struct gkyl_array* gkyl_array_min_by_cell(struct gkyl_array *out, const struct gkyl_array *inp, double a); +struct gkyl_array * +gkyl_array_min_by_cell(struct gkyl_array *out, const struct gkyl_array *inp, double a); /** * Clear out = val. Returns out. @@ -168,8 +166,8 @@ struct gkyl_array* gkyl_array_min_by_cell(struct gkyl_array *out, const struct g * @param val Factor to set * @return out array */ -struct gkyl_array* gkyl_array_clear_range(struct gkyl_array *out, double val, - const struct gkyl_range *range); +struct gkyl_array * +gkyl_array_clear_range(struct gkyl_array *out, double val, const struct gkyl_range *range); /** * Compute out = out + a*inp over a range of indices. @@ -180,8 +178,9 @@ struct gkyl_array* gkyl_array_clear_range(struct gkyl_array *out, double val, * @param range Range specifying region to accumulate * @return out array */ -struct gkyl_array* gkyl_array_accumulate_range(struct gkyl_array *out, - double a, const struct gkyl_array *inp, const struct gkyl_range *range); +struct gkyl_array *gkyl_array_accumulate_range( + struct gkyl_array *out, double a, const struct gkyl_array *inp, const struct gkyl_range *range +); /** * Compute out = out + a*inp[coff] where coff is a component-offset if @@ -194,8 +193,10 @@ struct gkyl_array* gkyl_array_accumulate_range(struct gkyl_array *out, * @param coff Component offset * @return out array */ -struct gkyl_array* gkyl_array_accumulate_offset_range(struct gkyl_array *out, - double a, const struct gkyl_array *inp, int coff, const struct gkyl_range *range); +struct gkyl_array *gkyl_array_accumulate_offset_range( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff, + const struct gkyl_range *range +); /** * Set out = a*inp. Returns out. @@ -206,8 +207,9 @@ struct gkyl_array* gkyl_array_accumulate_offset_range(struct gkyl_array *out, * @return out array * @param range Range specifying region to set */ -struct gkyl_array* gkyl_array_set_range(struct gkyl_array *out, - double a, const struct gkyl_array *inp, const struct gkyl_range *range); +struct gkyl_array *gkyl_array_set_range( + struct gkyl_array *out, double a, const struct gkyl_array *inp, const struct gkyl_range *range +); /** * Set out = a*inp over specified ranges. Returns out. @@ -220,8 +222,10 @@ struct gkyl_array* gkyl_array_set_range(struct gkyl_array *out, * @param out_range Range specifying region of out to set * @param inp_range Range specifying region of inp to use */ -struct gkyl_array* gkyl_array_set_range_to_range(struct gkyl_array *out, double a, - const struct gkyl_array *inp, const struct gkyl_range *out_range, const struct gkyl_range *inp_range); +struct gkyl_array *gkyl_array_set_range_to_range( + struct gkyl_array *out, double a, const struct gkyl_array *inp, + const struct gkyl_range *out_range, const struct gkyl_range *inp_range +); /** * Set out = a*inp[coff] where coff is a component-offset if @@ -234,8 +238,10 @@ struct gkyl_array* gkyl_array_set_range_to_range(struct gkyl_array *out, double * @return out array * @param range Range specifying region to set */ -struct gkyl_array* gkyl_array_set_offset_range(struct gkyl_array *out, - double a, const struct gkyl_array *inp, int coff, const struct gkyl_range *range); +struct gkyl_array *gkyl_array_set_offset_range( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff, + const struct gkyl_range *range +); /** * Scale out = a*ut. Returns out. @@ -245,8 +251,8 @@ struct gkyl_array* gkyl_array_set_offset_range(struct gkyl_array *out, * @return out array * @param range Range specifying region to scale */ -struct gkyl_array* gkyl_array_scale_range(struct gkyl_array *out, - double a, const struct gkyl_range *range); +struct gkyl_array * +gkyl_array_scale_range(struct gkyl_array *out, double a, const struct gkyl_range *range); /** * Shift the k-th coefficient in every cell, out_k = a+out_k within @@ -258,8 +264,9 @@ struct gkyl_array* gkyl_array_scale_range(struct gkyl_array *out, * @param range Range to shift coefficient k in. * @return out array. */ -struct gkyl_array* gkyl_array_shiftc_range(struct gkyl_array *out, double a, - unsigned k, const struct gkyl_range *range); +struct gkyl_array *gkyl_array_shiftc_range( + struct gkyl_array *out, double a, unsigned k, const struct gkyl_range *range +); /** * Take element-wise minimum: out = min(inp, a) within a given range. Returns out. @@ -271,8 +278,9 @@ struct gkyl_array* gkyl_array_shiftc_range(struct gkyl_array *out, double a, * @param range Range to apply minimum operation in. * @return out array. */ -struct gkyl_array* gkyl_array_min_by_cell_range(struct gkyl_array *out, const struct gkyl_array *inp, - double a, const struct gkyl_range *range); +struct gkyl_array *gkyl_array_min_by_cell_range( + struct gkyl_array *out, const struct gkyl_array *inp, double a, const struct gkyl_range *range +); /** * Copy out inp. Returns out. @@ -282,8 +290,9 @@ struct gkyl_array* gkyl_array_min_by_cell_range(struct gkyl_array *out, const st * @param range Range specifying region to copy * @return out array */ -struct gkyl_array* gkyl_array_copy_range(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range); +struct gkyl_array *gkyl_array_copy_range( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +); /** * Copy out inp over specified ranges. Returns out. @@ -295,8 +304,10 @@ struct gkyl_array* gkyl_array_copy_range(struct gkyl_array *out, * @param inp_range Range specifying region to copy to from in inp array * @return out array */ -struct gkyl_array* gkyl_array_copy_range_to_range(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *out_range, const struct gkyl_range *inp_range); +struct gkyl_array *gkyl_array_copy_range_to_range( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *out_range, + const struct gkyl_range *inp_range +); /** * Copy region of array into a buffer. The buffer must be preallocated @@ -306,8 +317,9 @@ struct gkyl_array* gkyl_array_copy_range_to_range(struct gkyl_array *out, * @param arr Array to copy from * @param range Range specifying region to copy from */ -void gkyl_array_copy_to_buffer(void *data, const struct gkyl_array *arr, - const struct gkyl_range *range); +void gkyl_array_copy_to_buffer( + void *data, const struct gkyl_array *arr, const struct gkyl_range *range +); /** * Copy buffer into region of array. The array must be preallocated. @@ -316,8 +328,9 @@ void gkyl_array_copy_to_buffer(void *data, const struct gkyl_array *arr, * @param data Input data buffer. * @param range Range specifying region to copy into */ -void gkyl_array_copy_from_buffer(struct gkyl_array *arr, const void *data, - const struct gkyl_range *range); +void gkyl_array_copy_from_buffer( + struct gkyl_array *arr, const void *data, const struct gkyl_range *range +); /** * Copy region of array into a buffer, calling user-specified function @@ -329,8 +342,10 @@ void gkyl_array_copy_from_buffer(struct gkyl_array *arr, const void *data, * @param range Range specifying region to copy from * @param cf Function pointer and context */ -void gkyl_array_copy_to_buffer_fn(void *data, const struct gkyl_array *arr, - const struct gkyl_range *range, struct gkyl_array_copy_func *cf); +void gkyl_array_copy_to_buffer_fn( + void *data, const struct gkyl_array *arr, const struct gkyl_range *range, + struct gkyl_array_copy_func *cf +); /** * Copy region of array into a buffer, calling user-specified function @@ -345,8 +360,10 @@ void gkyl_array_copy_to_buffer_fn(void *data, const struct gkyl_array *arr, * @param range Range specifying region to copy from * @param cf Function pointer and context */ -void gkyl_array_flip_copy_to_buffer_fn(void *data, const struct gkyl_array *arr, - int dir, const struct gkyl_range *range, struct gkyl_array_copy_func *cf); +void gkyl_array_flip_copy_to_buffer_fn( + void *data, const struct gkyl_array *arr, int dir, const struct gkyl_range *range, + struct gkyl_array_copy_func *cf +); /** * Return difference between two arrays. Mostly useful for testing. @@ -356,8 +373,9 @@ void gkyl_array_flip_copy_to_buffer_fn(void *data, const struct gkyl_array *arr, * @param range Range to compare over * @return diff between arrays */ -struct gkyl_array_diff gkyl_array_diff(const struct gkyl_array *arr1, - const struct gkyl_array *arr2, const struct gkyl_range *range); +struct gkyl_array_diff gkyl_array_diff( + const struct gkyl_array *arr1, const struct gkyl_array *arr2, const struct gkyl_range *range +); /** * Compute out = max(out,inp) based on cell avg. Returns out. @@ -367,77 +385,104 @@ struct gkyl_array_diff gkyl_array_diff(const struct gkyl_array *arr1, * @param range Range to take max over * @return out array */ -struct gkyl_array* gkyl_array_max_by_cell_per_cell_avg_range(struct gkyl_array *out, - const struct gkyl_array *inp, struct gkyl_range *range); +struct gkyl_array *gkyl_array_max_by_cell_per_cell_avg_range( + struct gkyl_array *out, const struct gkyl_array *inp, struct gkyl_range *range +); /** * Host-side wrappers for array operations */ -void gkyl_array_clear_cu(struct gkyl_array* out, double val); +void gkyl_array_clear_cu(struct gkyl_array *out, double val); -void gkyl_array_accumulate_cu(struct gkyl_array* out, double a, const struct gkyl_array* inp); +void gkyl_array_accumulate_cu(struct gkyl_array *out, double a, const struct gkyl_array *inp); -void gkyl_array_accumulate_offset_cu(struct gkyl_array* out, double a, const struct gkyl_array* inp, int coff); +void gkyl_array_accumulate_offset_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff +); -void gkyl_array_set_cu(struct gkyl_array* out, double a, const struct gkyl_array* inp); +void gkyl_array_set_cu(struct gkyl_array *out, double a, const struct gkyl_array *inp); -void gkyl_array_set_offset_cu(struct gkyl_array* out, double a, const struct gkyl_array* inp, int coff); +void gkyl_array_set_offset_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff +); -void gkyl_array_scale_cu(struct gkyl_array* out, double a); +void gkyl_array_scale_cu(struct gkyl_array *out, double a); -void gkyl_array_scale_by_cell_cu(struct gkyl_array* out, const struct gkyl_array* a); +void gkyl_array_scale_by_cell_cu(struct gkyl_array *out, const struct gkyl_array *a); -void gkyl_array_divide_by_cell_cu(struct gkyl_array* out, const struct gkyl_array* a); +void gkyl_array_divide_by_cell_cu(struct gkyl_array *out, const struct gkyl_array *a); -void gkyl_array_invert_by_cell_cu(struct gkyl_array* out, const struct gkyl_array *inp); +void gkyl_array_invert_by_cell_cu(struct gkyl_array *out, const struct gkyl_array *inp); -void gkyl_array_shiftc_cu(struct gkyl_array* out, double a, unsigned k); +void gkyl_array_shiftc_cu(struct gkyl_array *out, double a, unsigned k); -void gkyl_array_min_by_cell_cu(struct gkyl_array* out, const struct gkyl_array *inp, double a); +void gkyl_array_min_by_cell_cu(struct gkyl_array *out, const struct gkyl_array *inp, double a); -void gkyl_array_shiftc_range_cu(struct gkyl_array *out, double a, unsigned k, const struct gkyl_range *range); +void gkyl_array_shiftc_range_cu( + struct gkyl_array *out, double a, unsigned k, const struct gkyl_range *range +); /** * Host-side wrappers for range-based array operations */ void gkyl_array_clear_range_cu(struct gkyl_array *out, double val, const struct gkyl_range *range); -void gkyl_array_accumulate_range_cu(struct gkyl_array *out, - double a, const struct gkyl_array* inp, const struct gkyl_range *range); - -void gkyl_array_accumulate_offset_range_cu(struct gkyl_array *out, - double a, const struct gkyl_array* inp, int coff, const struct gkyl_range *range); - -void gkyl_array_set_range_cu(struct gkyl_array *out, - double a, const struct gkyl_array* inp, const struct gkyl_range *range); - -void gkyl_array_set_range_to_range_cu(struct gkyl_array *out, double a, - const struct gkyl_array *inp, const struct gkyl_range *out_range, const struct gkyl_range *inp_range); - -void gkyl_array_set_offset_range_cu(struct gkyl_array *out, - double a, const struct gkyl_array* inp, int coff, const struct gkyl_range *range); - -void gkyl_array_scale_range_cu(struct gkyl_array *out, - double a, const struct gkyl_range *range); - -void gkyl_array_min_by_cell_range_cu(struct gkyl_array *out, const struct gkyl_array *inp, double a, const struct gkyl_range *range); - -void gkyl_array_copy_range_cu(struct gkyl_array *out, const struct gkyl_array* inp, - const struct gkyl_range *range); - -void gkyl_array_copy_range_to_range_cu(struct gkyl_array *out, const struct gkyl_array* inp, - const struct gkyl_range *out_range, const struct gkyl_range *inp_range); - -void gkyl_array_copy_to_buffer_cu(void *data, const struct gkyl_array *arr, - const struct gkyl_range *range); - -void gkyl_array_copy_from_buffer_cu(struct gkyl_array *arr, const void *data, - const struct gkyl_range *range); - -void gkyl_array_copy_to_buffer_fn_cu(void *data, const struct gkyl_array *arr, - const struct gkyl_range *range, struct gkyl_array_copy_func *cf); - -void gkyl_array_flip_copy_to_buffer_fn_cu(void *data, const struct gkyl_array *arr, - int dir, const struct gkyl_range *range, struct gkyl_array_copy_func *cf); - -void gkyl_array_max_by_cell_per_cell_avg_range_cu(struct gkyl_array* out, const struct gkyl_array* inp, const struct gkyl_range *range); +void gkyl_array_accumulate_range_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, const struct gkyl_range *range +); + +void gkyl_array_accumulate_offset_range_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff, + const struct gkyl_range *range +); + +void gkyl_array_set_range_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, const struct gkyl_range *range +); + +void gkyl_array_set_range_to_range_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, + const struct gkyl_range *out_range, const struct gkyl_range *inp_range +); + +void gkyl_array_set_offset_range_cu( + struct gkyl_array *out, double a, const struct gkyl_array *inp, int coff, + const struct gkyl_range *range +); + +void gkyl_array_scale_range_cu(struct gkyl_array *out, double a, const struct gkyl_range *range); + +void gkyl_array_min_by_cell_range_cu( + struct gkyl_array *out, const struct gkyl_array *inp, double a, const struct gkyl_range *range +); + +void gkyl_array_copy_range_cu( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +); + +void gkyl_array_copy_range_to_range_cu( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *out_range, + const struct gkyl_range *inp_range +); + +void gkyl_array_copy_to_buffer_cu( + void *data, const struct gkyl_array *arr, const struct gkyl_range *range +); + +void gkyl_array_copy_from_buffer_cu( + struct gkyl_array *arr, const void *data, const struct gkyl_range *range +); + +void gkyl_array_copy_to_buffer_fn_cu( + void *data, const struct gkyl_array *arr, const struct gkyl_range *range, + struct gkyl_array_copy_func *cf +); + +void gkyl_array_flip_copy_to_buffer_fn_cu( + void *data, const struct gkyl_array *arr, int dir, const struct gkyl_range *range, + struct gkyl_array_copy_func *cf +); + +void gkyl_array_max_by_cell_per_cell_avg_range_cu( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +); diff --git a/core/zero/gkyl_array_ops_priv.h b/core/zero/gkyl_array_ops_priv.h index 8283a224c9..aaa33c4505 100644 --- a/core/zero/gkyl_array_ops_priv.h +++ b/core/zero/gkyl_array_ops_priv.h @@ -3,42 +3,39 @@ // Private header, not for direct use in user code // Compute number of elements stored in array 'arr' -#define NELM(arr) (arr->size*arr->ncomp) -// Compute size of 'arr' +#define NELM(arr) (arr->size * arr->ncomp) +// Compute size of 'arr' #define NSIZE(arr) (arr->size) // Compute number of components stored in array 'arr' #define NCOM(arr) (arr->ncomp) -GKYL_CU_DH -static inline void -array_clear1(long n, double *out, double val) +GKYL_CU_DH static inline void array_clear1(long n, double *out, double val) { - for (int c=0; c 0) does this call @@ -70,9 +71,10 @@ void gkyl_array_header_info_release(struct gkyl_array_header_info *info); * @param fname Name of output file (include .gkyl extension) * @return Status flag */ -enum gkyl_array_rio_status gkyl_grid_sub_array_write(const struct gkyl_rect_grid *grid, - const struct gkyl_range *range, const struct gkyl_msgpack_data *meta, - const struct gkyl_array *arr, const char *fname); +enum gkyl_array_rio_status gkyl_grid_sub_array_write( + const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + const struct gkyl_msgpack_data *meta, const struct gkyl_array *arr, const char *fname +); /** * Read grid and array data from file. The input array must be @@ -84,9 +86,10 @@ enum gkyl_array_rio_status gkyl_grid_sub_array_write(const struct gkyl_rect_grid * @param fname Name of input file * @return Status flag */ -enum gkyl_array_rio_status gkyl_grid_sub_array_read(struct gkyl_rect_grid *grid, - const struct gkyl_range *range, - struct gkyl_array *arr, const char* fname); +enum gkyl_array_rio_status gkyl_grid_sub_array_read( + struct gkyl_rect_grid *grid, const struct gkyl_range *range, struct gkyl_array *arr, + const char *fname +); /** * Read grid and array data from file, creating a new array. @@ -95,5 +98,4 @@ enum gkyl_array_rio_status gkyl_grid_sub_array_read(struct gkyl_rect_grid *grid, * @param fname Name of input file * @return Newly created array object. NULL if failed */ -struct gkyl_array *gkyl_grid_array_new_from_file(struct gkyl_rect_grid *grid, - const char* fname); +struct gkyl_array *gkyl_grid_array_new_from_file(struct gkyl_rect_grid *grid, const char *fname); diff --git a/core/zero/gkyl_array_rio_priv.h b/core/zero/gkyl_array_rio_priv.h index 4826955122..8e5158f189 100644 --- a/core/zero/gkyl_array_rio_priv.h +++ b/core/zero/gkyl_array_rio_priv.h @@ -30,8 +30,9 @@ int gkyl_header_meta_read_fp(struct gkyl_array_header_info *hdr, FILE *fp); * @param hrd Header data. * @return Status flag: 0 if write succeeded, 'errno' otherwise */ -int gkyl_grid_sub_array_header_write_fp(const struct gkyl_rect_grid *grid, - const struct gkyl_array_header_info *hdr, FILE *fp); +int gkyl_grid_sub_array_header_write_fp( + const struct gkyl_rect_grid *grid, const struct gkyl_array_header_info *hdr, FILE *fp +); /** * Read grid and array data header data from file. Note that only @@ -47,8 +48,9 @@ int gkyl_grid_sub_array_header_write_fp(const struct gkyl_rect_grid *grid, * @param hrd On output, Header data. * @return Status flag: 0 if read succeeded, 'errno' otherwise */ -int gkyl_grid_sub_array_header_read_fp(struct gkyl_rect_grid *grid, - struct gkyl_array_header_info *hdr, FILE *fp); +int gkyl_grid_sub_array_header_read_fp( + struct gkyl_rect_grid *grid, struct gkyl_array_header_info *hdr, FILE *fp +); /** * Release memory for header. diff --git a/core/zero/gkyl_basis.h b/core/zero/gkyl_basis.h index 27ddd0a0c5..76ecab079f 100644 --- a/core/zero/gkyl_basis.h +++ b/core/zero/gkyl_basis.h @@ -6,7 +6,7 @@ enum gkyl_basis_type { GKYL_BASIS_MODAL_TENSOR, GKYL_BASIS_MODAL_HYBRID, GKYL_BASIS_MODAL_GKHYBRID, - GKYL_BASIS_MODAL_GKHYBRID_VEL, + GKYL_BASIS_MODAL_GKHYBRID_VEL }; typedef void (*nodal_to_modal_quad_surf_t)(const double *fnodal, double *fmodal); @@ -19,8 +19,8 @@ struct gkyl_basis { unsigned ndim, poly_order, num_basis, num_quad; char id[64]; // "serendipity", "tensor", "hybrid, "gkhybrid", "gkhybrid_vel" enum gkyl_basis_type b_type; // identifier for basis function - -/** + + /** * Evaluate basis in unit cell (i.e. a hypercube with each side * [-1,1]) * @@ -29,7 +29,7 @@ struct gkyl_basis { */ void (*eval)(const double *z, double *b); -/** + /** * Evaluate expansion at point in the logical cell (hypercube) * * @param z Location to evaluate exansion. z \in [-1,1]^n @@ -38,7 +38,7 @@ struct gkyl_basis { */ double (*eval_expand)(const double *z, const double *f); -/** + /** * Evaluate gradient, given expansion at point in the logical cell * (hypercube) * @@ -49,7 +49,7 @@ struct gkyl_basis { */ double (*eval_grad_expand)(int dir, const double *z, const double *f); -/** + /** * Flip-sign function: changes signs of input expansion cofficients by * changing sign of odd monomial powers in specified direction. So if * dir=0, all odd powers of x appearing in the expansion will have @@ -72,7 +72,7 @@ struct gkyl_basis { */ void (*flip_even_sign)(int dir, const double *f, double *fout); -/** + /** * Construct list of nodes corresponding to this basis set. The nodes * coordinates are in the unit cell [-1,1]^ndim and stored such that * the coodinates of a node are contiguous, starting at index ndim*n, @@ -81,7 +81,7 @@ struct gkyl_basis { */ void (*node_list)(double *node_coords); -/** + /** * Given expansion coefficients on nodal basis (nodes specified by the * node_list method), compute modal expansion coefficients. * @@ -90,7 +90,7 @@ struct gkyl_basis { */ void (*nodal_to_modal)(const double *fnodal, double *fmodal); -/** + /** * Given expansion coefficients on nodes at the surface in one direction, * and Gauss-Legendre nodes in the other, compute modal expansion coefficients. * @@ -99,7 +99,7 @@ struct gkyl_basis { */ nodal_to_modal_quad_surf_t nodal_to_modal_quad_surf[3]; -/** + /** * Construct list of nodes that are on the surface in one direction * and on Gauss-Legendre coordinates in the other. The nodes * coordinates are in the unit cell [-1,1]^ndim and stored such that @@ -109,7 +109,7 @@ struct gkyl_basis { */ node_quad_surf_list_t node_quad_surf_list[3]; -/** + /** * Given expansion coefficients on nodal basis defined by Gauss-Legendre * quadrature points, compute modal expansion coefficients. * @@ -117,9 +117,9 @@ struct gkyl_basis { * @param fmodal On output, coefficients of modal expansion * @param linc2 Modal component being updated (allows for parallelization over basis functions) */ - void (*quad_nodal_to_modal)(const double *fquad, double *fmodal, long linc2); + void (*quad_nodal_to_modal)(const double *fquad, double *fmodal, long linc2); -/** + /** * Given expansion coefficients of DG modal basis, evaluate basis at Gauss-Legendre * quadrature points of order p+1 (the Gauss-Legendre nodal basis). * @@ -127,8 +127,8 @@ struct gkyl_basis { * @param fquad On output, evaluation of modal expansion at Gauss-Legendre quadrature nodal basis * @param linc2 Quadrature node being updated (allows for parallelization over quadrature points) */ - void (*modal_to_quad_nodal)(const double *fmodal, double *fquad, long linc2); -}; + void (*modal_to_quad_nodal)(const double *fmodal, double *fquad, long linc2); +}; /** * Assign object members in modal serendipity basis object. @@ -137,11 +137,8 @@ struct gkyl_basis { * @param ndim Dimension of reference element. * @param poly_order Polynomial order. */ -void gkyl_cart_modal_serendip(struct gkyl_basis *basis, int ndim, - int poly_order); -void gkyl_cart_modal_serendip_cu_dev(struct gkyl_basis *basis, int ndim, - int poly_order); - +void gkyl_cart_modal_serendip(struct gkyl_basis *basis, int ndim, int poly_order); +void gkyl_cart_modal_serendip_cu_dev(struct gkyl_basis *basis, int ndim, int poly_order); /** * Create new modal serendipity basis function object. @@ -151,8 +148,8 @@ void gkyl_cart_modal_serendip_cu_dev(struct gkyl_basis *basis, int ndim, * @param poly_order Polynomial order. * @return new basis struct. */ -struct gkyl_basis * gkyl_cart_modal_serendip_new(int ndim, int poly_order); -struct gkyl_basis * gkyl_cart_modal_serendip_cu_dev_new(int ndim, int poly_order); +struct gkyl_basis *gkyl_cart_modal_serendip_new(int ndim, int poly_order); +struct gkyl_basis *gkyl_cart_modal_serendip_cu_dev_new(int ndim, int poly_order); /** * Assign object members in modal tensor-product basis object. @@ -161,10 +158,8 @@ struct gkyl_basis * gkyl_cart_modal_serendip_cu_dev_new(int ndim, int poly_order * @param ndim Dimension of reference element. * @param poly_order Polynomial order. */ -void gkyl_cart_modal_tensor(struct gkyl_basis *basis, int ndim, - int poly_order); -void gkyl_cart_modal_tensor_cu_dev(struct gkyl_basis *basis, int ndim, - int poly_order); +void gkyl_cart_modal_tensor(struct gkyl_basis *basis, int ndim, int poly_order); +void gkyl_cart_modal_tensor_cu_dev(struct gkyl_basis *basis, int ndim, int poly_order); /** * Create new modal tensor-product basis function object. @@ -174,8 +169,8 @@ void gkyl_cart_modal_tensor_cu_dev(struct gkyl_basis *basis, int ndim, * @param poly_order Polynomial order. * @return new basis struct. */ -struct gkyl_basis * gkyl_cart_modal_tensor_new(int ndim, int poly_order); -struct gkyl_basis * gkyl_cart_modal_tensor_cu_dev_new(int ndim, int poly_order); +struct gkyl_basis *gkyl_cart_modal_tensor_new(int ndim, int poly_order); +struct gkyl_basis *gkyl_cart_modal_tensor_cu_dev_new(int ndim, int poly_order); /** * Assign object members in hybrid basis. These are p=1 in configuration space @@ -197,8 +192,8 @@ void gkyl_cart_modal_hybrid_cu_dev(struct gkyl_basis *basis, int cdim, int vdim) * @param vdim dimension of velocity space. * @return new basis struct. */ -struct gkyl_basis * gkyl_cart_modal_hybrid_new(int cdim, int vdim); -struct gkyl_basis * gkyl_cart_modal_hybrid_cu_dev_new(int cdim, int vdim); +struct gkyl_basis *gkyl_cart_modal_hybrid_new(int cdim, int vdim); +struct gkyl_basis *gkyl_cart_modal_hybrid_cu_dev_new(int cdim, int vdim); /** * Assign object members in hybrid basis for use in gyrokinetics p=1 @@ -222,8 +217,8 @@ void gkyl_cart_modal_gkhybrid_cu_dev(struct gkyl_basis *basis, int cdim, int vdi * @param vdim dimension of velocity space. * @return new basis struct. */ -struct gkyl_basis * gkyl_cart_modal_gkhybrid_new(int cdim, int vdim); -struct gkyl_basis * gkyl_cart_modal_gkhybrid_cu_dev_new(int cdim, int vdim); +struct gkyl_basis *gkyl_cart_modal_gkhybrid_new(int cdim, int vdim); +struct gkyl_basis *gkyl_cart_modal_gkhybrid_cu_dev_new(int cdim, int vdim); /** * Assign object members in hybrid basis for use in gyrokinetics p=1 @@ -247,8 +242,8 @@ void gkyl_cart_modal_gkhybrid_vel_cu_dev(struct gkyl_basis *basis, int vdim); * @param vdim dimension of velocity space. * @return new basis struct. */ -struct gkyl_basis * gkyl_cart_modal_gkhybrid_vel_new(int vdim); -struct gkyl_basis * gkyl_cart_modal_gkhybrid_vel_cu_dev_new(int vdim); +struct gkyl_basis *gkyl_cart_modal_gkhybrid_vel_new(int vdim); +struct gkyl_basis *gkyl_cart_modal_gkhybrid_vel_cu_dev_new(int vdim); /** * Get the dimensionality of a basis (for opaque pointers). diff --git a/core/zero/gkyl_block_geom.h b/core/zero/gkyl_block_geom.h index c77b953b6a..d0cf613c50 100644 --- a/core/zero/gkyl_block_geom.h +++ b/core/zero/gkyl_block_geom.h @@ -8,7 +8,7 @@ struct gkyl_block_geom_info { // lower and upper extents of blocks double lower[GKYL_MAX_CDIM], upper[GKYL_MAX_CDIM]; int cells[GKYL_MAX_CDIM]; // cells extents in each direction - int cuts[GKYL_MAX_CDIM]; // domain split to use + int cuts[GKYL_MAX_CDIM]; // domain split to use struct gkyl_target_edge connections[GKYL_MAX_CDIM][2]; // block connections }; @@ -49,7 +49,7 @@ int gkyl_block_geom_num_blocks(const struct gkyl_block_geom *bgeom); * @param bgeom Block geometry to which reference is required * @return Pointer to acquired block-topo */ -struct gkyl_block_geom* gkyl_block_geom_acquire(const struct gkyl_block_geom *bgeom); +struct gkyl_block_geom *gkyl_block_geom_acquire(const struct gkyl_block_geom *bgeom); /** * Acquire a pointer to the block topology. The caller must release @@ -58,7 +58,7 @@ struct gkyl_block_geom* gkyl_block_geom_acquire(const struct gkyl_block_geom *bg * @param bgeom Geometry object from which to fetch topology * @return topology object */ -struct gkyl_block_topo* gkyl_block_geom_topo(const struct gkyl_block_geom *bgeom); +struct gkyl_block_topo *gkyl_block_geom_topo(const struct gkyl_block_geom *bgeom); /** * Set geometry and connectivity information about a block. @@ -68,9 +68,9 @@ struct gkyl_block_topo* gkyl_block_geom_topo(const struct gkyl_block_geom *bgeom * @param info Geometry info for block @a bidx * */ -void gkyl_block_geom_set_block(struct gkyl_block_geom *bgeom, int bidx, - const struct gkyl_block_geom_info *info); - +void gkyl_block_geom_set_block( + struct gkyl_block_geom *bgeom, int bidx, const struct gkyl_block_geom_info *info +); /** * Reset grid extents for block geometry info @@ -80,9 +80,9 @@ void gkyl_block_geom_set_block(struct gkyl_block_geom *bgeom, int bidx, * @param lower Lower extents * @param upper Upper extents */ -void -gkyl_block_geom_reset_block_extents(struct gkyl_block_geom *bgeom, int bidx, - double *lower, double *upper); +void gkyl_block_geom_reset_block_extents( + struct gkyl_block_geom *bgeom, int bidx, double *lower, double *upper +); /** * Get geometry and connectivity information about a block. @@ -92,9 +92,9 @@ gkyl_block_geom_reset_block_extents(struct gkyl_block_geom *bgeom, int bidx, * @return Geometry info for block @a bidx * */ -const struct gkyl_block_geom_info *gkyl_block_geom_get_block( - const struct gkyl_block_geom *bgeom, int bidx); - +const struct gkyl_block_geom_info * +gkyl_block_geom_get_block(const struct gkyl_block_geom *bgeom, int bidx); + /** * Check consistency of block geometry: the geometry typically has * redundant data in it. This method ensures the redundant data is @@ -111,4 +111,4 @@ int gkyl_block_geom_check_consistency(const struct gkyl_block_geom *bgeom); * * @return Block geometry to free */ -void gkyl_block_geom_release(struct gkyl_block_geom* bgeom); +void gkyl_block_geom_release(struct gkyl_block_geom *bgeom); diff --git a/core/zero/gkyl_block_topo.h b/core/zero/gkyl_block_topo.h index 5f93b77c0a..60df0f2e7b 100644 --- a/core/zero/gkyl_block_topo.h +++ b/core/zero/gkyl_block_topo.h @@ -11,7 +11,7 @@ enum gkyl_oriented_edge { GKYL_LOWER_NEGATIVE, GKYL_UPPER_POSITIVE, GKYL_UPPER_NEGATIVE, - GKYL_PHYSICAL, // edge on physical domain boundary + GKYL_PHYSICAL // edge on physical domain boundary }; // Connection to a given target edge @@ -46,7 +46,7 @@ struct gkyl_block_topo { * @param nblocks Total number of blocks in topology * @return New block topology */ -struct gkyl_block_topo* gkyl_block_topo_new(int ndim, int nblocks); +struct gkyl_block_topo *gkyl_block_topo_new(int ndim, int nblocks); /** * Acquire pointer to block-topology. The pointer must be released @@ -55,7 +55,7 @@ struct gkyl_block_topo* gkyl_block_topo_new(int ndim, int nblocks); * @param btopo Block-topo to which reference is required * @return Pointer to acquired block-topo */ -struct gkyl_block_topo* gkyl_block_topo_acquire(const struct gkyl_block_topo* btopo); +struct gkyl_block_topo *gkyl_block_topo_acquire(const struct gkyl_block_topo *btopo); /** * Check consistency of block topology: the topology typically has @@ -87,11 +87,11 @@ int gkyl_block_topo_write(const struct gkyl_block_topo *btopo, const char *fname * @param status On output, status as enum gkyl_array_rio_status * @return btopo New block-topology from file */ -struct gkyl_block_topo* gkyl_block_topo_read(const char *fname, int *status); +struct gkyl_block_topo *gkyl_block_topo_read(const char *fname, int *status); /** * Free block topology. * * @return Block topology to free */ -void gkyl_block_topo_release(struct gkyl_block_topo* btopo); +void gkyl_block_topo_release(struct gkyl_block_topo *btopo); diff --git a/core/zero/gkyl_cart_modal_gkhybrid_priv.h b/core/zero/gkyl_cart_modal_gkhybrid_priv.h index e54337d21c..9bfd161cd2 100644 --- a/core/zero/gkyl_cart_modal_gkhybrid_priv.h +++ b/core/zero/gkyl_cart_modal_gkhybrid_priv.h @@ -3,127 +3,126 @@ #include // Basis function eval for each dimension: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*ev[4])(const double *z, double *b); } ev_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, eval_1x1v_gkhyb_p1, NULL, NULL }, - { NULL, eval_1x2v_gkhyb_p1, NULL, NULL }, - { NULL, eval_2x2v_gkhyb_p1, NULL, NULL }, - { NULL, eval_3x2v_gkhyb_p1, NULL, NULL }, - { NULL, NULL, NULL, NULL }, // No 6D basis functions +GKYL_CU_D static struct { + void (*ev[4])(const double *z, double *b); +} ev_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, eval_1x1v_gkhyb_p1, NULL, NULL}, + {NULL, eval_1x2v_gkhyb_p1, NULL, NULL}, + {NULL, eval_2x2v_gkhyb_p1, NULL, NULL}, + {NULL, eval_3x2v_gkhyb_p1, NULL, NULL}, + {NULL, NULL, NULL, NULL} // No 6D basis functions }; // Expansion eval for each dimension: eve_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { double (*ev[4])(const double *z, const double *f); } eve_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, eval_expand_1x1v_gkhyb_p1, NULL, NULL }, - { NULL, eval_expand_1x2v_gkhyb_p1, NULL, NULL }, - { NULL, eval_expand_2x2v_gkhyb_p1, NULL, NULL }, - { NULL, eval_expand_3x2v_gkhyb_p1, NULL, NULL }, - { NULL, NULL, NULL, NULL }, // No 6D basis functions +GKYL_CU_D static struct { + double (*ev[4])(const double *z, const double *f); +} eve_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, eval_expand_1x1v_gkhyb_p1, NULL, NULL}, + {NULL, eval_expand_1x2v_gkhyb_p1, NULL, NULL}, + {NULL, eval_expand_2x2v_gkhyb_p1, NULL, NULL}, + {NULL, eval_expand_3x2v_gkhyb_p1, NULL, NULL}, + {NULL, NULL, NULL, NULL} // No 6D basis functions }; // Expansion eval_grad for each dimension: eveg_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { double (*ev[4])(int dir, const double *z, const double *f); } eveg_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, eval_grad_expand_1x1v_gkhyb_p1, NULL, NULL }, - { NULL, eval_grad_expand_1x2v_gkhyb_p1, NULL, NULL }, - { NULL, eval_grad_expand_2x2v_gkhyb_p1, NULL, NULL }, - { NULL, eval_grad_expand_3x2v_gkhyb_p1, NULL, NULL }, - { NULL, NULL, NULL, NULL }, // No 6D basis functions +GKYL_CU_D static struct { + double (*ev[4])(int dir, const double *z, const double *f); +} eveg_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, eval_grad_expand_1x1v_gkhyb_p1, NULL, NULL}, + {NULL, eval_grad_expand_1x2v_gkhyb_p1, NULL, NULL}, + {NULL, eval_grad_expand_2x2v_gkhyb_p1, NULL, NULL}, + {NULL, eval_grad_expand_3x2v_gkhyb_p1, NULL, NULL}, + {NULL, NULL, NULL, NULL} // No 6D basis functions }; // Flip-sign functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*fs[4])(int dir, const double *f, double *fout); } fos_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, flip_odd_sign_1x1v_gkhyb_p1, NULL, NULL }, - { NULL, flip_odd_sign_1x2v_gkhyb_p1, NULL, NULL }, - { NULL, flip_odd_sign_2x2v_gkhyb_p1, NULL, NULL }, - { NULL, flip_odd_sign_3x2v_gkhyb_p1, NULL, NULL }, - { NULL, NULL, NULL, NULL }, // No 6D basis functions +GKYL_CU_D static struct { + void (*fs[4])(int dir, const double *f, double *fout); +} fos_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, flip_odd_sign_1x1v_gkhyb_p1, NULL, NULL}, + {NULL, flip_odd_sign_1x2v_gkhyb_p1, NULL, NULL}, + {NULL, flip_odd_sign_2x2v_gkhyb_p1, NULL, NULL}, + {NULL, flip_odd_sign_3x2v_gkhyb_p1, NULL, NULL}, + {NULL, NULL, NULL, NULL} // No 6D basis functions }; // Flip-sign functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*fs[4])(int dir, const double *f, double *fout); } fes_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, flip_even_sign_1x1v_gkhyb_p1, NULL, NULL }, - { NULL, flip_even_sign_1x2v_gkhyb_p1, NULL, NULL }, - { NULL, flip_even_sign_2x2v_gkhyb_p1, NULL, NULL }, - { NULL, flip_even_sign_3x2v_gkhyb_p1, NULL, NULL }, - { NULL, NULL, NULL, NULL }, // No 6D basis functions +GKYL_CU_D static struct { + void (*fs[4])(int dir, const double *f, double *fout); +} fes_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, flip_even_sign_1x1v_gkhyb_p1, NULL, NULL}, + {NULL, flip_even_sign_1x2v_gkhyb_p1, NULL, NULL}, + {NULL, flip_even_sign_2x2v_gkhyb_p1, NULL, NULL}, + {NULL, flip_even_sign_3x2v_gkhyb_p1, NULL, NULL}, + {NULL, NULL, NULL, NULL} // No 6D basis functions }; // Number of basis functions: num_basis_list[ndim].count[poly_order] -GKYL_CU_D -static struct { int count[4]; } num_basis_list[] = { - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 6, 0, 0 }, - { 0, 12, 0, 0 }, - { 0, 24, 0, 0 }, - { 0, 48, 0, 0 }, -}; +GKYL_CU_D static struct { + int count[4]; +} num_basis_list[] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 6, 0, 0}, + {0, 12, 0, 0}, {0, 24, 0, 0}, {0, 48, 0, 0}}; // Node list function: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*nl[4])(double * node_list); } nl_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, node_coords_1x1v_gkhyb_p1, NULL, NULL }, - { NULL, node_coords_1x2v_gkhyb_p1, NULL, NULL }, - { NULL, node_coords_2x2v_gkhyb_p1, NULL, NULL }, - { NULL, node_coords_3x2v_gkhyb_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*nl[4])(double *node_list); +} nl_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, node_coords_1x1v_gkhyb_p1, NULL, NULL}, + {NULL, node_coords_1x2v_gkhyb_p1, NULL, NULL}, + {NULL, node_coords_2x2v_gkhyb_p1, NULL, NULL}, + {NULL, node_coords_3x2v_gkhyb_p1, NULL, NULL} }; // Nodal -> modal conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fnodal, double *fmodal); } n2m_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, nodal_to_modal_1x1v_gkhyb_p1, NULL, NULL }, - { NULL, nodal_to_modal_1x2v_gkhyb_p1, NULL, NULL }, - { NULL, nodal_to_modal_2x2v_gkhyb_p1, NULL, NULL }, - { NULL, nodal_to_modal_3x2v_gkhyb_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fnodal, double *fmodal); +} n2m_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, nodal_to_modal_1x1v_gkhyb_p1, NULL, NULL}, + {NULL, nodal_to_modal_1x2v_gkhyb_p1, NULL, NULL}, + {NULL, nodal_to_modal_2x2v_gkhyb_p1, NULL, NULL}, + {NULL, nodal_to_modal_3x2v_gkhyb_p1, NULL, NULL} }; // Gauss-Legendre quadrature nodes nodal basis -> modal basis conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fquad, double *fmodal, long linc2); } qn2m_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, quad_to_modal_1x1v_gkhyb_p1, NULL, NULL }, - { NULL, quad_to_modal_1x2v_gkhyb_p1, NULL, NULL }, - { NULL, quad_to_modal_2x2v_gkhyb_p1, NULL, NULL }, - { NULL, quad_to_modal_3x2v_gkhyb_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fquad, double *fmodal, long linc2); +} qn2m_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, quad_to_modal_1x1v_gkhyb_p1, NULL, NULL}, + {NULL, quad_to_modal_1x2v_gkhyb_p1, NULL, NULL}, + {NULL, quad_to_modal_2x2v_gkhyb_p1, NULL, NULL}, + {NULL, quad_to_modal_3x2v_gkhyb_p1, NULL, NULL} }; // Number of quadrature nodes: num_quad_list[ndim].count[poly_order] -GKYL_CU_D -static struct { int count[4]; } num_quad_list[] = { - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 6, 0, 0 }, - { 0, 12, 0, 0 }, - { 0, 24, 0, 0 }, - { 0, 48, 0, 0 }, -}; +GKYL_CU_D static struct { + int count[4]; +} num_quad_list[] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 6, 0, 0}, + {0, 12, 0, 0}, {0, 24, 0, 0}, {0, 48, 0, 0}}; // modal basis -> Gauss-Legendre quadrature nodes nodal basis conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fmodal, double *fquad, long linc2); } m2qn_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, modal_to_quad_1x1v_gkhyb_p1, NULL, NULL }, - { NULL, modal_to_quad_1x2v_gkhyb_p1, NULL, NULL }, - { NULL, modal_to_quad_2x2v_gkhyb_p1, NULL, NULL }, - { NULL, modal_to_quad_3x2v_gkhyb_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fmodal, double *fquad, long linc2); +} m2qn_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, modal_to_quad_1x1v_gkhyb_p1, NULL, NULL}, + {NULL, modal_to_quad_1x2v_gkhyb_p1, NULL, NULL}, + {NULL, modal_to_quad_2x2v_gkhyb_p1, NULL, NULL}, + {NULL, modal_to_quad_3x2v_gkhyb_p1, NULL, NULL} }; \ No newline at end of file diff --git a/core/zero/gkyl_cart_modal_gkhybrid_vel_priv.h b/core/zero/gkyl_cart_modal_gkhybrid_vel_priv.h index 9e711dd323..399bcac3b4 100644 --- a/core/zero/gkyl_cart_modal_gkhybrid_vel_priv.h +++ b/core/zero/gkyl_cart_modal_gkhybrid_vel_priv.h @@ -3,89 +3,92 @@ #include // Basis function eval for each dimension: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*ev[4])(const double *z, double *b); } ev_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, eval_1d_gkhyb_vel_p1, NULL, NULL }, - { NULL, eval_2d_gkhyb_vel_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*ev[4])(const double *z, double *b); +} ev_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, eval_1d_gkhyb_vel_p1, NULL, NULL}, + {NULL, eval_2d_gkhyb_vel_p1, NULL, NULL} }; // Expansion eval for each dimension: eve_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { double (*ev[4])(const double *z, const double *f); } eve_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, eval_expand_1d_gkhyb_vel_p1, NULL, NULL }, - { NULL, eval_expand_2d_gkhyb_vel_p1, NULL, NULL }, +GKYL_CU_D static struct { + double (*ev[4])(const double *z, const double *f); +} eve_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, eval_expand_1d_gkhyb_vel_p1, NULL, NULL}, + {NULL, eval_expand_2d_gkhyb_vel_p1, NULL, NULL} }; // Expansion eval_grad for each dimension: eveg_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { double (*ev[4])(int dir, const double *z, const double *f); } eveg_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, eval_grad_expand_1d_gkhyb_vel_p1, NULL, NULL }, - { NULL, eval_grad_expand_2d_gkhyb_vel_p1, NULL, NULL }, +GKYL_CU_D static struct { + double (*ev[4])(int dir, const double *z, const double *f); +} eveg_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, eval_grad_expand_1d_gkhyb_vel_p1, NULL, NULL}, + {NULL, eval_grad_expand_2d_gkhyb_vel_p1, NULL, NULL} }; // Flip-sign functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*fs[4])(int dir, const double *f, double *fout); } fos_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, flip_odd_sign_1d_gkhyb_vel_p1, NULL, NULL }, - { NULL, flip_odd_sign_2d_gkhyb_vel_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*fs[4])(int dir, const double *f, double *fout); +} fos_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, flip_odd_sign_1d_gkhyb_vel_p1, NULL, NULL}, + {NULL, flip_odd_sign_2d_gkhyb_vel_p1, NULL, NULL} }; // Flip-sign functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*fs[4])(int dir, const double *f, double *fout); } fes_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, flip_even_sign_1d_gkhyb_vel_p1, NULL, NULL }, - { NULL, flip_even_sign_2d_gkhyb_vel_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*fs[4])(int dir, const double *f, double *fout); +} fes_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, flip_even_sign_1d_gkhyb_vel_p1, NULL, NULL}, + {NULL, flip_even_sign_2d_gkhyb_vel_p1, NULL, NULL} }; // Number of basis functions: num_basis_list[ndim].count[poly_order] -GKYL_CU_D -static struct { int count[4]; } num_basis_list[] = { - { 0, 0, 0, 0 }, - { 0, 3, 0, 0 }, - { 0, 6, 0, 0 }, -}; +GKYL_CU_D static struct { + int count[4]; +} num_basis_list[] = {{0, 0, 0, 0}, {0, 3, 0, 0}, {0, 6, 0, 0}}; // Node list function: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*nl[4])(double * node_list); } nl_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, node_coords_1d_gkhyb_vel_p1, NULL, NULL }, - { NULL, node_coords_2d_gkhyb_vel_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*nl[4])(double *node_list); +} nl_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, node_coords_1d_gkhyb_vel_p1, NULL, NULL}, + {NULL, node_coords_2d_gkhyb_vel_p1, NULL, NULL} }; // Nodal -> modal conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fnodal, double *fmodal); } n2m_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, nodal_to_modal_1d_gkhyb_vel_p1, NULL, NULL }, - { NULL, nodal_to_modal_2d_gkhyb_vel_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fnodal, double *fmodal); +} n2m_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, nodal_to_modal_1d_gkhyb_vel_p1, NULL, NULL}, + {NULL, nodal_to_modal_2d_gkhyb_vel_p1, NULL, NULL} }; // Gauss-Legendre quadrature nodes nodal basis -> modal basis conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fquad, double *fmodal, long linc2); } qn2m_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, quad_to_modal_1d_gkhyb_vel_p1, NULL, NULL }, - { NULL, quad_to_modal_2d_gkhyb_vel_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fquad, double *fmodal, long linc2); +} qn2m_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, quad_to_modal_1d_gkhyb_vel_p1, NULL, NULL}, + {NULL, quad_to_modal_2d_gkhyb_vel_p1, NULL, NULL} }; // Number of quadrature nodes: num_quad_list[ndim].count[poly_order] -GKYL_CU_D -static struct { int count[4]; } num_quad_list[] = { - { 0, 0, 0, 0 }, - { 0, 3, 0, 0 }, - { 0, 6, 0, 0 }, -}; +GKYL_CU_D static struct { + int count[4]; +} num_quad_list[] = {{0, 0, 0, 0}, {0, 3, 0, 0}, {0, 6, 0, 0}}; // modal basis -> Gauss-Legendre quadrature nodes nodal basis conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fmodal, double *fquad, long linc2); } m2qn_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, modal_to_quad_1d_gkhyb_vel_p1, NULL, NULL }, - { NULL, modal_to_quad_2d_gkhyb_vel_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fmodal, double *fquad, long linc2); +} m2qn_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, modal_to_quad_1d_gkhyb_vel_p1, NULL, NULL}, + {NULL, modal_to_quad_2d_gkhyb_vel_p1, NULL, NULL} }; diff --git a/core/zero/gkyl_cart_modal_hybrid_priv.h b/core/zero/gkyl_cart_modal_hybrid_priv.h index 0624c92f8d..3b07d3b20c 100644 --- a/core/zero/gkyl_cart_modal_hybrid_priv.h +++ b/core/zero/gkyl_cart_modal_hybrid_priv.h @@ -3,100 +3,106 @@ #include // Basis function eval for each dimension: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*ev[4])(const double *z, double *b); } ev_list[] = { - { NULL, NULL, NULL, NULL }, // No 0x basis functions - { NULL, eval_1x1v_hyb_p1, eval_1x2v_hyb_p1, eval_1x3v_hyb_p1, }, - { NULL, eval_2x1v_hyb_p1, eval_2x2v_hyb_p1, eval_2x3v_hyb_p1, }, - { NULL, eval_3x1v_hyb_p1, eval_3x2v_hyb_p1, eval_3x3v_hyb_p1, }, +GKYL_CU_D static struct { + void (*ev[4])(const double *z, double *b); +} ev_list[] = { + {NULL, NULL, NULL, NULL}, // No 0x basis functions + {NULL, eval_1x1v_hyb_p1, eval_1x2v_hyb_p1, eval_1x3v_hyb_p1}, + {NULL, eval_2x1v_hyb_p1, eval_2x2v_hyb_p1, eval_2x3v_hyb_p1}, + {NULL, eval_3x1v_hyb_p1, eval_3x2v_hyb_p1, eval_3x3v_hyb_p1} }; // Expansion eval for each dimension: eve_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { double (*ev[4])(const double *z, const double *f); } eve_list[] = { - { NULL, NULL, NULL, NULL }, // No 0x basis functions - { NULL, eval_expand_1x1v_hyb_p1, eval_expand_1x2v_hyb_p1, eval_expand_1x3v_hyb_p1 }, - { NULL, eval_expand_2x1v_hyb_p1, eval_expand_2x2v_hyb_p1, eval_expand_2x3v_hyb_p1 }, - { NULL, eval_expand_3x1v_hyb_p1, eval_expand_3x2v_hyb_p1, eval_expand_3x3v_hyb_p1 }, +GKYL_CU_D static struct { + double (*ev[4])(const double *z, const double *f); +} eve_list[] = { + {NULL, NULL, NULL, NULL}, // No 0x basis functions + {NULL, eval_expand_1x1v_hyb_p1, eval_expand_1x2v_hyb_p1, eval_expand_1x3v_hyb_p1}, + {NULL, eval_expand_2x1v_hyb_p1, eval_expand_2x2v_hyb_p1, eval_expand_2x3v_hyb_p1}, + {NULL, eval_expand_3x1v_hyb_p1, eval_expand_3x2v_hyb_p1, eval_expand_3x3v_hyb_p1} }; // Expansion eval_grad for each dimension: eveg_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { double (*ev[4])(int dir, const double *z, const double *f); } eveg_list[] = { - { NULL, NULL, NULL, NULL }, // No 0x basis functions - { NULL, eval_grad_expand_1x1v_hyb_p1, eval_grad_expand_1x2v_hyb_p1, eval_grad_expand_1x3v_hyb_p1 }, - { NULL, eval_grad_expand_2x1v_hyb_p1, eval_grad_expand_2x2v_hyb_p1, eval_grad_expand_2x3v_hyb_p1 }, - { NULL, eval_grad_expand_3x1v_hyb_p1, eval_grad_expand_3x2v_hyb_p1, eval_grad_expand_3x3v_hyb_p1 }, +GKYL_CU_D static struct { + double (*ev[4])(int dir, const double *z, const double *f); +} eveg_list[] = { + {NULL, NULL, NULL, NULL}, // No 0x basis functions + {NULL, eval_grad_expand_1x1v_hyb_p1, eval_grad_expand_1x2v_hyb_p1, eval_grad_expand_1x3v_hyb_p1}, + {NULL, eval_grad_expand_2x1v_hyb_p1, eval_grad_expand_2x2v_hyb_p1, eval_grad_expand_2x3v_hyb_p1}, + {NULL, eval_grad_expand_3x1v_hyb_p1, eval_grad_expand_3x2v_hyb_p1, eval_grad_expand_3x3v_hyb_p1} }; // Flip-sign functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*fs[4])(int dir, const double *f, double *fout); } fos_list[] = { - { NULL, NULL, NULL, NULL }, // No 0x basis functions - { NULL, flip_odd_sign_1x1v_hyb_p1 , flip_odd_sign_1x2v_hyb_p1 , flip_odd_sign_1x3v_hyb_p1 }, - { NULL, flip_odd_sign_2x1v_hyb_p1 , flip_odd_sign_2x2v_hyb_p1 , flip_odd_sign_2x3v_hyb_p1 }, - { NULL, flip_odd_sign_3x1v_hyb_p1 , flip_odd_sign_3x2v_hyb_p1 , flip_odd_sign_3x3v_hyb_p1 }, +GKYL_CU_D static struct { + void (*fs[4])(int dir, const double *f, double *fout); +} fos_list[] = { + {NULL, NULL, NULL, NULL}, // No 0x basis functions + {NULL, flip_odd_sign_1x1v_hyb_p1, flip_odd_sign_1x2v_hyb_p1, flip_odd_sign_1x3v_hyb_p1}, + {NULL, flip_odd_sign_2x1v_hyb_p1, flip_odd_sign_2x2v_hyb_p1, flip_odd_sign_2x3v_hyb_p1}, + {NULL, flip_odd_sign_3x1v_hyb_p1, flip_odd_sign_3x2v_hyb_p1, flip_odd_sign_3x3v_hyb_p1} }; // Flip-sign functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*fs[4])(int dir, const double *f, double *fout); } fes_list[] = { - { NULL, NULL, NULL, NULL }, // No 0x basis functions - { NULL, flip_even_sign_1x1v_hyb_p1, flip_even_sign_1x2v_hyb_p1, flip_even_sign_1x3v_hyb_p1 }, - { NULL, flip_even_sign_2x1v_hyb_p1, flip_even_sign_2x2v_hyb_p1, flip_even_sign_2x3v_hyb_p1 }, - { NULL, flip_even_sign_3x1v_hyb_p1, flip_even_sign_3x2v_hyb_p1, flip_even_sign_3x3v_hyb_p1 }, +GKYL_CU_D static struct { + void (*fs[4])(int dir, const double *f, double *fout); +} fes_list[] = { + {NULL, NULL, NULL, NULL}, // No 0x basis functions + {NULL, flip_even_sign_1x1v_hyb_p1, flip_even_sign_1x2v_hyb_p1, flip_even_sign_1x3v_hyb_p1}, + {NULL, flip_even_sign_2x1v_hyb_p1, flip_even_sign_2x2v_hyb_p1, flip_even_sign_2x3v_hyb_p1}, + {NULL, flip_even_sign_3x1v_hyb_p1, flip_even_sign_3x2v_hyb_p1, flip_even_sign_3x3v_hyb_p1} }; // Number of basis functions: num_basis_list[ndim].count[poly_order] -GKYL_CU_D -static struct { int count[4]; } num_basis_list[] = { - { 0, 0, 0, 0 }, // No 0x basis functions. - { 0, 6, 16, 40 }, - { 0, 12, 32, 80 }, - { 0, 24, 64, 160 }, +GKYL_CU_D static struct { + int count[4]; +} num_basis_list[] = { + {0, 0, 0, 0}, // No 0x basis functions. + {0, 6, 16, 40}, + {0, 12, 32, 80}, + {0, 24, 64, 160} }; // Node list function: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*nl[4])(double * node_list); } nl_list[] = { - { NULL, NULL, NULL, NULL }, // No 0x basis functions - { NULL, node_coords_1x1v_hyb_p1, node_coords_1x2v_hyb_p1, node_coords_1x3v_hyb_p1 }, - { NULL, node_coords_2x1v_hyb_p1, node_coords_2x2v_hyb_p1, node_coords_2x3v_hyb_p1 }, - { NULL, node_coords_3x1v_hyb_p1, node_coords_3x2v_hyb_p1, node_coords_3x3v_hyb_p1 }, +GKYL_CU_D static struct { + void (*nl[4])(double *node_list); +} nl_list[] = { + {NULL, NULL, NULL, NULL}, // No 0x basis functions + {NULL, node_coords_1x1v_hyb_p1, node_coords_1x2v_hyb_p1, node_coords_1x3v_hyb_p1}, + {NULL, node_coords_2x1v_hyb_p1, node_coords_2x2v_hyb_p1, node_coords_2x3v_hyb_p1}, + {NULL, node_coords_3x1v_hyb_p1, node_coords_3x2v_hyb_p1, node_coords_3x3v_hyb_p1} }; // Nodal -> modal conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fnodal, double *fmodal); } n2m_list[] = { - { NULL, NULL, NULL, NULL }, // No 0x basis functions - { NULL, nodal_to_modal_1x1v_hyb_p1, nodal_to_modal_1x2v_hyb_p1, nodal_to_modal_1x3v_hyb_p1 }, - { NULL, nodal_to_modal_2x1v_hyb_p1, nodal_to_modal_2x2v_hyb_p1, nodal_to_modal_2x3v_hyb_p1 }, - { NULL, nodal_to_modal_3x1v_hyb_p1, nodal_to_modal_3x2v_hyb_p1, nodal_to_modal_3x3v_hyb_p1 }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fnodal, double *fmodal); +} n2m_list[] = { + {NULL, NULL, NULL, NULL}, // No 0x basis functions + {NULL, nodal_to_modal_1x1v_hyb_p1, nodal_to_modal_1x2v_hyb_p1, nodal_to_modal_1x3v_hyb_p1}, + {NULL, nodal_to_modal_2x1v_hyb_p1, nodal_to_modal_2x2v_hyb_p1, nodal_to_modal_2x3v_hyb_p1}, + {NULL, nodal_to_modal_3x1v_hyb_p1, nodal_to_modal_3x2v_hyb_p1, nodal_to_modal_3x3v_hyb_p1} }; // Gauss-Legendre quadrature nodes nodal basis -> modal basis conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fquad, double *fmodal, long linc2); } qn2m_list[] = { - { NULL, NULL, NULL, NULL }, // No 0x basis functions - { NULL, quad_to_modal_1x1v_hyb_p1, quad_to_modal_1x2v_hyb_p1, quad_to_modal_1x3v_hyb_p1 }, - { NULL, quad_to_modal_2x1v_hyb_p1, quad_to_modal_2x2v_hyb_p1, quad_to_modal_2x3v_hyb_p1 }, - { NULL, quad_to_modal_3x1v_hyb_p1, quad_to_modal_3x2v_hyb_p1, quad_to_modal_3x3v_hyb_p1 }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fquad, double *fmodal, long linc2); +} qn2m_list[] = { + {NULL, NULL, NULL, NULL}, // No 0x basis functions + {NULL, quad_to_modal_1x1v_hyb_p1, quad_to_modal_1x2v_hyb_p1, quad_to_modal_1x3v_hyb_p1}, + {NULL, quad_to_modal_2x1v_hyb_p1, quad_to_modal_2x2v_hyb_p1, quad_to_modal_2x3v_hyb_p1}, + {NULL, quad_to_modal_3x1v_hyb_p1, quad_to_modal_3x2v_hyb_p1, quad_to_modal_3x3v_hyb_p1} }; // Number of quadrature nodes: num_quad_list[ndim].count[poly_order] -GKYL_CU_D -static struct { int count[4]; } num_quad_list[] = { - { 0, 0, 0, 0 }, - { 0, 6, 18, 54 }, - { 0, 12, 36, 108 }, - { 0, 24, 72, 216 }, -}; +GKYL_CU_D static struct { + int count[4]; +} num_quad_list[] = {{0, 0, 0, 0}, {0, 6, 18, 54}, {0, 12, 36, 108}, {0, 24, 72, 216}}; // modal basis -> Gauss-Legendre quadrature nodes nodal basis conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fmodal, double *fquad, long linc2); } m2qn_list[] = { - { NULL, NULL, NULL, NULL }, // No 0x basis functions - { NULL, modal_to_quad_1x1v_hyb_p1, modal_to_quad_1x2v_hyb_p1, modal_to_quad_1x3v_hyb_p1 }, - { NULL, modal_to_quad_2x1v_hyb_p1, modal_to_quad_2x2v_hyb_p1, modal_to_quad_2x3v_hyb_p1 }, - { NULL, modal_to_quad_3x1v_hyb_p1, modal_to_quad_3x2v_hyb_p1, modal_to_quad_3x3v_hyb_p1 }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fmodal, double *fquad, long linc2); +} m2qn_list[] = { + {NULL, NULL, NULL, NULL}, // No 0x basis functions + {NULL, modal_to_quad_1x1v_hyb_p1, modal_to_quad_1x2v_hyb_p1, modal_to_quad_1x3v_hyb_p1}, + {NULL, modal_to_quad_2x1v_hyb_p1, modal_to_quad_2x2v_hyb_p1, modal_to_quad_2x3v_hyb_p1}, + {NULL, modal_to_quad_3x1v_hyb_p1, modal_to_quad_3x2v_hyb_p1, modal_to_quad_3x3v_hyb_p1} }; diff --git a/core/zero/gkyl_cart_modal_serendip_priv.h b/core/zero/gkyl_cart_modal_serendip_priv.h index 319b563840..482299efff 100644 --- a/core/zero/gkyl_cart_modal_serendip_priv.h +++ b/core/zero/gkyl_cart_modal_serendip_priv.h @@ -3,182 +3,197 @@ #include // Basis function eval for each dimension: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*ev[4])(const double *z, double *b); } ev_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { eval_1d_ser_p0, eval_1d_ser_p1, eval_1d_ser_p2, eval_1d_ser_p3 }, - { eval_2d_ser_p0, eval_2d_ser_p1, eval_2d_ser_p2, eval_2d_ser_p3 }, - { eval_3d_ser_p0, eval_3d_ser_p1, eval_3d_ser_p2, eval_3d_ser_p3 }, - { eval_4d_ser_p0, eval_4d_ser_p1, eval_4d_ser_p2, eval_4d_ser_p3 }, - { eval_5d_ser_p0, eval_5d_ser_p1, eval_5d_ser_p2, NULL }, - { eval_6d_ser_p0, eval_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*ev[4])(const double *z, double *b); +} ev_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {eval_1d_ser_p0, eval_1d_ser_p1, eval_1d_ser_p2, eval_1d_ser_p3}, + {eval_2d_ser_p0, eval_2d_ser_p1, eval_2d_ser_p2, eval_2d_ser_p3}, + {eval_3d_ser_p0, eval_3d_ser_p1, eval_3d_ser_p2, eval_3d_ser_p3}, + {eval_4d_ser_p0, eval_4d_ser_p1, eval_4d_ser_p2, eval_4d_ser_p3}, + {eval_5d_ser_p0, eval_5d_ser_p1, eval_5d_ser_p2, NULL}, + {eval_6d_ser_p0, eval_6d_ser_p1, NULL, NULL} }; // Expansion eval for each dimension: eve_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { double (*ev[4])(const double *z, const double *f); } eve_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { eval_expand_1d_ser_p0, eval_expand_1d_ser_p1, eval_expand_1d_ser_p2, eval_expand_1d_ser_p3 }, - { eval_expand_2d_ser_p0, eval_expand_2d_ser_p1, eval_expand_2d_ser_p2, eval_expand_2d_ser_p3 }, - { eval_expand_3d_ser_p0, eval_expand_3d_ser_p1, eval_expand_3d_ser_p2, eval_expand_3d_ser_p3 }, - { eval_expand_4d_ser_p0, eval_expand_4d_ser_p1, eval_expand_4d_ser_p2, eval_expand_4d_ser_p3 }, - { eval_expand_5d_ser_p0, eval_expand_5d_ser_p1, eval_expand_5d_ser_p2, NULL }, - { eval_expand_6d_ser_p0, eval_expand_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + double (*ev[4])(const double *z, const double *f); +} eve_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {eval_expand_1d_ser_p0, eval_expand_1d_ser_p1, eval_expand_1d_ser_p2, eval_expand_1d_ser_p3}, + {eval_expand_2d_ser_p0, eval_expand_2d_ser_p1, eval_expand_2d_ser_p2, eval_expand_2d_ser_p3}, + {eval_expand_3d_ser_p0, eval_expand_3d_ser_p1, eval_expand_3d_ser_p2, eval_expand_3d_ser_p3}, + {eval_expand_4d_ser_p0, eval_expand_4d_ser_p1, eval_expand_4d_ser_p2, eval_expand_4d_ser_p3}, + {eval_expand_5d_ser_p0, eval_expand_5d_ser_p1, eval_expand_5d_ser_p2, NULL}, + {eval_expand_6d_ser_p0, eval_expand_6d_ser_p1, NULL, NULL} }; // Expansion eval_grad for each dimension: eveg_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { double (*ev[4])(int dir, const double *z, const double *f); } eveg_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { eval_grad_expand_1d_ser_p0, eval_grad_expand_1d_ser_p1, eval_grad_expand_1d_ser_p2, eval_grad_expand_1d_ser_p3 }, - { eval_grad_expand_2d_ser_p0, eval_grad_expand_2d_ser_p1, eval_grad_expand_2d_ser_p2, eval_grad_expand_2d_ser_p3 }, - { eval_grad_expand_3d_ser_p0, eval_grad_expand_3d_ser_p1, eval_grad_expand_3d_ser_p2, eval_grad_expand_3d_ser_p3 }, - { eval_grad_expand_4d_ser_p0, eval_grad_expand_4d_ser_p1, eval_grad_expand_4d_ser_p2, eval_grad_expand_4d_ser_p3 }, - { eval_grad_expand_5d_ser_p0, eval_grad_expand_5d_ser_p1, eval_grad_expand_5d_ser_p2, NULL }, - { eval_grad_expand_6d_ser_p0, eval_grad_expand_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + double (*ev[4])(int dir, const double *z, const double *f); +} eveg_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {eval_grad_expand_1d_ser_p0, eval_grad_expand_1d_ser_p1, eval_grad_expand_1d_ser_p2, + eval_grad_expand_1d_ser_p3}, + {eval_grad_expand_2d_ser_p0, eval_grad_expand_2d_ser_p1, eval_grad_expand_2d_ser_p2, + eval_grad_expand_2d_ser_p3}, + {eval_grad_expand_3d_ser_p0, eval_grad_expand_3d_ser_p1, eval_grad_expand_3d_ser_p2, + eval_grad_expand_3d_ser_p3}, + {eval_grad_expand_4d_ser_p0, eval_grad_expand_4d_ser_p1, eval_grad_expand_4d_ser_p2, + eval_grad_expand_4d_ser_p3}, + {eval_grad_expand_5d_ser_p0, eval_grad_expand_5d_ser_p1, eval_grad_expand_5d_ser_p2, NULL}, + {eval_grad_expand_6d_ser_p0, eval_grad_expand_6d_ser_p1, NULL, NULL} }; // Flip-sign functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*fs[4])(int dir, const double *f, double *fout); } fos_list[] = { +GKYL_CU_D static struct { + void (*fs[4])(int dir, const double *f, double *fout); +} fos_list[] = { {NULL, NULL, NULL, NULL}, // No 0D basis functions - {flip_odd_sign_1d_ser_p0, flip_odd_sign_1d_ser_p1, flip_odd_sign_1d_ser_p2, flip_odd_sign_1d_ser_p3}, - {flip_odd_sign_2d_ser_p0, flip_odd_sign_2d_ser_p1, flip_odd_sign_2d_ser_p2, flip_odd_sign_2d_ser_p3}, - {flip_odd_sign_3d_ser_p0, flip_odd_sign_3d_ser_p1, flip_odd_sign_3d_ser_p2, flip_odd_sign_3d_ser_p3}, - {flip_odd_sign_4d_ser_p0, flip_odd_sign_4d_ser_p1, flip_odd_sign_4d_ser_p2, flip_odd_sign_4d_ser_p3}, + {flip_odd_sign_1d_ser_p0, flip_odd_sign_1d_ser_p1, flip_odd_sign_1d_ser_p2, + flip_odd_sign_1d_ser_p3}, + {flip_odd_sign_2d_ser_p0, flip_odd_sign_2d_ser_p1, flip_odd_sign_2d_ser_p2, + flip_odd_sign_2d_ser_p3}, + {flip_odd_sign_3d_ser_p0, flip_odd_sign_3d_ser_p1, flip_odd_sign_3d_ser_p2, + flip_odd_sign_3d_ser_p3}, + {flip_odd_sign_4d_ser_p0, flip_odd_sign_4d_ser_p1, flip_odd_sign_4d_ser_p2, + flip_odd_sign_4d_ser_p3}, {flip_odd_sign_5d_ser_p0, flip_odd_sign_5d_ser_p1, flip_odd_sign_5d_ser_p2, NULL}, - {flip_odd_sign_6d_ser_p0, flip_odd_sign_6d_ser_p1, NULL, NULL}, + {flip_odd_sign_6d_ser_p0, flip_odd_sign_6d_ser_p1, NULL, NULL} }; // Flip-sign functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*fs[4])(int dir, const double *f, double *fout); } fes_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { flip_even_sign_1d_ser_p0, flip_even_sign_1d_ser_p1, flip_even_sign_1d_ser_p2, flip_even_sign_1d_ser_p3 }, - { flip_even_sign_2d_ser_p0, flip_even_sign_2d_ser_p1, flip_even_sign_2d_ser_p2, flip_even_sign_2d_ser_p3 }, - { flip_even_sign_3d_ser_p0, flip_even_sign_3d_ser_p1, flip_even_sign_3d_ser_p2, flip_even_sign_3d_ser_p3 }, - { flip_even_sign_4d_ser_p0, flip_even_sign_4d_ser_p1, flip_even_sign_4d_ser_p2, flip_even_sign_4d_ser_p3 }, - { flip_even_sign_5d_ser_p0, flip_even_sign_5d_ser_p1, flip_even_sign_5d_ser_p2, NULL }, - { flip_even_sign_6d_ser_p0, flip_even_sign_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*fs[4])(int dir, const double *f, double *fout); +} fes_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {flip_even_sign_1d_ser_p0, flip_even_sign_1d_ser_p1, flip_even_sign_1d_ser_p2, + flip_even_sign_1d_ser_p3}, + {flip_even_sign_2d_ser_p0, flip_even_sign_2d_ser_p1, flip_even_sign_2d_ser_p2, + flip_even_sign_2d_ser_p3}, + {flip_even_sign_3d_ser_p0, flip_even_sign_3d_ser_p1, flip_even_sign_3d_ser_p2, + flip_even_sign_3d_ser_p3}, + {flip_even_sign_4d_ser_p0, flip_even_sign_4d_ser_p1, flip_even_sign_4d_ser_p2, + flip_even_sign_4d_ser_p3}, + {flip_even_sign_5d_ser_p0, flip_even_sign_5d_ser_p1, flip_even_sign_5d_ser_p2, NULL}, + {flip_even_sign_6d_ser_p0, flip_even_sign_6d_ser_p1, NULL, NULL} }; // Number of basis functions: num_basis_list[ndim].count[poly_order] -GKYL_CU_D -static struct { int count[4]; } num_basis_list[] = { - { 1, 1, 1, 1 }, - { 1, 2, 3, 4 }, - { 1, 4, 8, 12 }, - { 1, 8, 20, 32 }, - { 1, 16, 48, 80 }, - { 1, 32, 112, 192 }, - { 1, 64, 256, 0 }, -}; +GKYL_CU_D static struct { + int count[4]; +} num_basis_list[] = {{1, 1, 1, 1}, {1, 2, 3, 4}, {1, 4, 8, 12}, {1, 8, 20, 32}, + {1, 16, 48, 80}, {1, 32, 112, 192}, {1, 64, 256, 0}}; // Node list function: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*nl[4])(double * node_list); } nl_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { node_coords_1d_ser_p0, node_coords_1d_ser_p1, node_coords_1d_ser_p2, NULL }, - { node_coords_2d_ser_p0, node_coords_2d_ser_p1, node_coords_2d_ser_p2, NULL }, - { node_coords_3d_ser_p0, node_coords_3d_ser_p1, node_coords_3d_ser_p2, NULL }, - { node_coords_4d_ser_p0, node_coords_4d_ser_p1, node_coords_4d_ser_p2, NULL }, - { node_coords_5d_ser_p0, node_coords_5d_ser_p1, node_coords_5d_ser_p2, NULL }, - { node_coords_6d_ser_p0, node_coords_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*nl[4])(double *node_list); +} nl_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {node_coords_1d_ser_p0, node_coords_1d_ser_p1, node_coords_1d_ser_p2, NULL}, + {node_coords_2d_ser_p0, node_coords_2d_ser_p1, node_coords_2d_ser_p2, NULL}, + {node_coords_3d_ser_p0, node_coords_3d_ser_p1, node_coords_3d_ser_p2, NULL}, + {node_coords_4d_ser_p0, node_coords_4d_ser_p1, node_coords_4d_ser_p2, NULL}, + {node_coords_5d_ser_p0, node_coords_5d_ser_p1, node_coords_5d_ser_p2, NULL}, + {node_coords_6d_ser_p0, node_coords_6d_ser_p1, NULL, NULL} }; // Nodal -> modal conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fnodal, double *fmodal); } n2m_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, nodal_to_modal_1d_ser_p1, nodal_to_modal_1d_ser_p2, NULL }, - { NULL, nodal_to_modal_2d_ser_p1, nodal_to_modal_2d_ser_p2, NULL }, - { NULL, nodal_to_modal_3d_ser_p1, nodal_to_modal_3d_ser_p2, NULL }, - { NULL, nodal_to_modal_4d_ser_p1, nodal_to_modal_4d_ser_p2, NULL }, - { NULL, nodal_to_modal_5d_ser_p1, nodal_to_modal_5d_ser_p2, NULL }, - { NULL, nodal_to_modal_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fnodal, double *fmodal); +} n2m_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, nodal_to_modal_1d_ser_p1, nodal_to_modal_1d_ser_p2, NULL}, + {NULL, nodal_to_modal_2d_ser_p1, nodal_to_modal_2d_ser_p2, NULL}, + {NULL, nodal_to_modal_3d_ser_p1, nodal_to_modal_3d_ser_p2, NULL}, + {NULL, nodal_to_modal_4d_ser_p1, nodal_to_modal_4d_ser_p2, NULL}, + {NULL, nodal_to_modal_5d_ser_p1, nodal_to_modal_5d_ser_p2, NULL}, + {NULL, nodal_to_modal_6d_ser_p1, NULL, NULL} }; // Nodal -> modal conversion functions for nodes on a surface in one direction // and Gauss-Legendre in the others: ev_list[ndim].ev[poly_order].indir[dir] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fnodal, double *fmodal); } n2m_quad_surf_list_x[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, nodal_to_modal_quad_surfx_2d_ser_p1, nodal_to_modal_quad_surfx_2d_ser_p2, NULL }, - { NULL, nodal_to_modal_quad_surfx_3d_ser_p1, nodal_to_modal_quad_surfx_3d_ser_p2, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fnodal, double *fmodal); +} n2m_quad_surf_list_x[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, nodal_to_modal_quad_surfx_2d_ser_p1, nodal_to_modal_quad_surfx_2d_ser_p2, NULL}, + {NULL, nodal_to_modal_quad_surfx_3d_ser_p1, nodal_to_modal_quad_surfx_3d_ser_p2, NULL} }; -GKYL_CU_D -static struct { void (*n2m[4])(const double *fnodal, double *fmodal); } n2m_quad_surf_list_y[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, nodal_to_modal_quad_surfy_2d_ser_p1, nodal_to_modal_quad_surfy_2d_ser_p2, NULL }, - { NULL, nodal_to_modal_quad_surfy_3d_ser_p1, nodal_to_modal_quad_surfy_3d_ser_p2, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fnodal, double *fmodal); +} n2m_quad_surf_list_y[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, nodal_to_modal_quad_surfy_2d_ser_p1, nodal_to_modal_quad_surfy_2d_ser_p2, NULL}, + {NULL, nodal_to_modal_quad_surfy_3d_ser_p1, nodal_to_modal_quad_surfy_3d_ser_p2, NULL} }; -GKYL_CU_D -static struct { void (*n2m[4])(const double *fnodal, double *fmodal); } n2m_quad_surf_list_z[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, NULL, NULL, NULL }, // No 2D basis functions - { NULL, nodal_to_modal_quad_surfz_3d_ser_p1, nodal_to_modal_quad_surfz_3d_ser_p2, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fnodal, double *fmodal); +} n2m_quad_surf_list_z[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, NULL, NULL, NULL}, // No 2D basis functions + {NULL, nodal_to_modal_quad_surfz_3d_ser_p1, nodal_to_modal_quad_surfz_3d_ser_p2, NULL} }; -// Node list function: +// Node list function: // List of nodes on a surface in one direction // and Gauss-Legendre in the others: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*nl[4])(double * node_list); } nl_quad_surf_list_x[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, node_coords_quad_surfx_2d_ser_p1, node_coords_quad_surfx_2d_ser_p2, NULL }, - { NULL, node_coords_quad_surfx_3d_ser_p1, node_coords_quad_surfx_3d_ser_p2, NULL }, +GKYL_CU_D static struct { + void (*nl[4])(double *node_list); +} nl_quad_surf_list_x[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, node_coords_quad_surfx_2d_ser_p1, node_coords_quad_surfx_2d_ser_p2, NULL}, + {NULL, node_coords_quad_surfx_3d_ser_p1, node_coords_quad_surfx_3d_ser_p2, NULL} }; -GKYL_CU_D -static struct { void (*nl[4])(double * node_list); } nl_quad_surf_list_y[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, node_coords_quad_surfy_2d_ser_p1, node_coords_quad_surfy_2d_ser_p2, NULL }, - { NULL, node_coords_quad_surfy_3d_ser_p1, node_coords_quad_surfy_3d_ser_p2, NULL }, +GKYL_CU_D static struct { + void (*nl[4])(double *node_list); +} nl_quad_surf_list_y[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, node_coords_quad_surfy_2d_ser_p1, node_coords_quad_surfy_2d_ser_p2, NULL}, + {NULL, node_coords_quad_surfy_3d_ser_p1, node_coords_quad_surfy_3d_ser_p2, NULL} }; -GKYL_CU_D -static struct { void (*nl[4])(double * node_list); } nl_quad_surf_list_z[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, NULL, NULL, NULL }, // No 1D basis functions - { NULL, NULL, NULL, NULL }, // No 2D basis functions - { NULL, node_coords_quad_surfz_3d_ser_p1, node_coords_quad_surfz_3d_ser_p2, NULL }, +GKYL_CU_D static struct { + void (*nl[4])(double *node_list); +} nl_quad_surf_list_z[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, NULL, NULL, NULL}, // No 1D basis functions + {NULL, NULL, NULL, NULL}, // No 2D basis functions + {NULL, node_coords_quad_surfz_3d_ser_p1, node_coords_quad_surfz_3d_ser_p2, NULL} }; // Gauss-Legendre quadrature nodes nodal basis -> modal basis conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fquad, double *fmodal, long linc2); } qn2m_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, quad_to_modal_1d_ser_p1, quad_to_modal_1d_ser_p2, NULL }, - { NULL, quad_to_modal_2d_ser_p1, quad_to_modal_2d_ser_p2, NULL }, - { NULL, quad_to_modal_3d_ser_p1, quad_to_modal_3d_ser_p2, NULL }, - { NULL, quad_to_modal_4d_ser_p1, quad_to_modal_4d_ser_p2, NULL }, - { NULL, quad_to_modal_5d_ser_p1, quad_to_modal_5d_ser_p2, NULL }, - { NULL, quad_to_modal_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fquad, double *fmodal, long linc2); +} qn2m_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, quad_to_modal_1d_ser_p1, quad_to_modal_1d_ser_p2, NULL}, + {NULL, quad_to_modal_2d_ser_p1, quad_to_modal_2d_ser_p2, NULL}, + {NULL, quad_to_modal_3d_ser_p1, quad_to_modal_3d_ser_p2, NULL}, + {NULL, quad_to_modal_4d_ser_p1, quad_to_modal_4d_ser_p2, NULL}, + {NULL, quad_to_modal_5d_ser_p1, quad_to_modal_5d_ser_p2, NULL}, + {NULL, quad_to_modal_6d_ser_p1, NULL, NULL} }; // Number of quadrature nodes: num_quad_list[ndim].count[poly_order] -GKYL_CU_D -static struct { int count[4]; } num_quad_list[] = { - { 0, 0, 0, 0 }, - { 0, 2, 3, 0 }, - { 0, 4, 9, 0 }, - { 0, 8, 27, 0 }, - { 0, 16, 81, 0 }, - { 0, 32, 243, 0 }, - { 0, 64, 0, 0 }, -}; +GKYL_CU_D static struct { + int count[4]; +} num_quad_list[] = {{0, 0, 0, 0}, {0, 2, 3, 0}, {0, 4, 9, 0}, {0, 8, 27, 0}, + {0, 16, 81, 0}, {0, 32, 243, 0}, {0, 64, 0, 0}}; // modal basis -> Gauss-Legendre quadrature nodes nodal basis conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fmodal, double *fquad, long linc2); } m2qn_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, modal_to_quad_1d_ser_p1, modal_to_quad_1d_ser_p2, NULL }, - { NULL, modal_to_quad_2d_ser_p1, modal_to_quad_2d_ser_p2, NULL }, - { NULL, modal_to_quad_3d_ser_p1, modal_to_quad_3d_ser_p2, NULL }, - { NULL, modal_to_quad_4d_ser_p1, modal_to_quad_4d_ser_p2, NULL }, - { NULL, modal_to_quad_5d_ser_p1, modal_to_quad_5d_ser_p2, NULL }, - { NULL, modal_to_quad_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*n2m[4])(const double *fmodal, double *fquad, long linc2); +} m2qn_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, modal_to_quad_1d_ser_p1, modal_to_quad_1d_ser_p2, NULL}, + {NULL, modal_to_quad_2d_ser_p1, modal_to_quad_2d_ser_p2, NULL}, + {NULL, modal_to_quad_3d_ser_p1, modal_to_quad_3d_ser_p2, NULL}, + {NULL, modal_to_quad_4d_ser_p1, modal_to_quad_4d_ser_p2, NULL}, + {NULL, modal_to_quad_5d_ser_p1, modal_to_quad_5d_ser_p2, NULL}, + {NULL, modal_to_quad_6d_ser_p1, NULL, NULL} }; diff --git a/core/zero/gkyl_cart_modal_tensor_priv.h b/core/zero/gkyl_cart_modal_tensor_priv.h index 267e9ba1d3..8474019ded 100644 --- a/core/zero/gkyl_cart_modal_tensor_priv.h +++ b/core/zero/gkyl_cart_modal_tensor_priv.h @@ -4,121 +4,131 @@ #include // Basis function eval for each dimension: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*ev[4])(const double *z, double *b); } ev_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { eval_1d_ser_p0, eval_1d_ser_p1, eval_1d_ser_p2, eval_1d_ser_p3 }, - { eval_2d_ser_p0, eval_2d_ser_p1, eval_2d_tensor_p2, eval_2d_tensor_p3 }, - { eval_3d_ser_p0, eval_3d_ser_p1, eval_3d_tensor_p2, NULL }, - { eval_4d_ser_p0, eval_4d_ser_p1, eval_4d_tensor_p2, NULL }, - { eval_5d_ser_p0, eval_5d_ser_p1, eval_5d_tensor_p2, NULL }, - { eval_6d_ser_p0, eval_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*ev[4])(const double *z, double *b); +} ev_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {eval_1d_ser_p0, eval_1d_ser_p1, eval_1d_ser_p2, eval_1d_ser_p3}, + {eval_2d_ser_p0, eval_2d_ser_p1, eval_2d_tensor_p2, eval_2d_tensor_p3}, + {eval_3d_ser_p0, eval_3d_ser_p1, eval_3d_tensor_p2, NULL}, + {eval_4d_ser_p0, eval_4d_ser_p1, eval_4d_tensor_p2, NULL}, + {eval_5d_ser_p0, eval_5d_ser_p1, eval_5d_tensor_p2, NULL}, + {eval_6d_ser_p0, eval_6d_ser_p1, NULL, NULL} }; // Expansion eval for each dimension: eve_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { double (*ev[4])(const double *z, const double *f); } eve_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { eval_expand_1d_ser_p0, eval_expand_1d_ser_p1, eval_expand_1d_ser_p2, eval_expand_1d_ser_p3 }, - { eval_expand_2d_ser_p0, eval_expand_2d_ser_p1, eval_expand_2d_tensor_p2, eval_expand_2d_tensor_p3 }, - { eval_expand_3d_ser_p0, eval_expand_3d_ser_p1, eval_expand_3d_tensor_p2, NULL }, - { eval_expand_4d_ser_p0, eval_expand_4d_ser_p1, eval_expand_4d_tensor_p2, NULL }, - { eval_expand_5d_ser_p0, eval_expand_5d_ser_p1, eval_expand_5d_tensor_p2, NULL }, - { eval_expand_6d_ser_p0, eval_expand_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + double (*ev[4])(const double *z, const double *f); +} eve_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {eval_expand_1d_ser_p0, eval_expand_1d_ser_p1, eval_expand_1d_ser_p2, eval_expand_1d_ser_p3}, + {eval_expand_2d_ser_p0, eval_expand_2d_ser_p1, eval_expand_2d_tensor_p2, eval_expand_2d_tensor_p3 + }, + {eval_expand_3d_ser_p0, eval_expand_3d_ser_p1, eval_expand_3d_tensor_p2, NULL}, + {eval_expand_4d_ser_p0, eval_expand_4d_ser_p1, eval_expand_4d_tensor_p2, NULL}, + {eval_expand_5d_ser_p0, eval_expand_5d_ser_p1, eval_expand_5d_tensor_p2, NULL}, + {eval_expand_6d_ser_p0, eval_expand_6d_ser_p1, NULL, NULL} }; // Expansion eval_grad for each dimension: eveg_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { double (*ev[4])(int dir, const double *z, const double *f); } eveg_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { eval_grad_expand_1d_ser_p0, eval_grad_expand_1d_ser_p1, eval_grad_expand_1d_ser_p2, eval_grad_expand_1d_ser_p3 }, - { eval_grad_expand_2d_ser_p0, eval_grad_expand_2d_ser_p1, eval_grad_expand_2d_tensor_p2, eval_grad_expand_2d_tensor_p3 }, - { eval_grad_expand_3d_ser_p0, eval_grad_expand_3d_ser_p1, eval_grad_expand_3d_tensor_p2, NULL }, - { eval_grad_expand_4d_ser_p0, eval_grad_expand_4d_ser_p1, eval_grad_expand_4d_tensor_p2, NULL }, - { eval_grad_expand_5d_ser_p0, eval_grad_expand_5d_ser_p1, eval_grad_expand_5d_tensor_p2, NULL }, - { eval_grad_expand_6d_ser_p0, eval_grad_expand_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + double (*ev[4])(int dir, const double *z, const double *f); +} eveg_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {eval_grad_expand_1d_ser_p0, eval_grad_expand_1d_ser_p1, eval_grad_expand_1d_ser_p2, + eval_grad_expand_1d_ser_p3}, + {eval_grad_expand_2d_ser_p0, eval_grad_expand_2d_ser_p1, eval_grad_expand_2d_tensor_p2, + eval_grad_expand_2d_tensor_p3}, + {eval_grad_expand_3d_ser_p0, eval_grad_expand_3d_ser_p1, eval_grad_expand_3d_tensor_p2, NULL}, + {eval_grad_expand_4d_ser_p0, eval_grad_expand_4d_ser_p1, eval_grad_expand_4d_tensor_p2, NULL}, + {eval_grad_expand_5d_ser_p0, eval_grad_expand_5d_ser_p1, eval_grad_expand_5d_tensor_p2, NULL}, + {eval_grad_expand_6d_ser_p0, eval_grad_expand_6d_ser_p1, NULL, NULL} }; // Flip-sign functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*fs[4])(int dir, const double *f, double *fout); } fos_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { flip_odd_sign_1d_ser_p0, flip_odd_sign_1d_ser_p1, flip_odd_sign_1d_ser_p2, flip_odd_sign_1d_ser_p3 }, - { flip_odd_sign_2d_ser_p0, flip_odd_sign_2d_ser_p1, flip_odd_sign_2d_tensor_p2, flip_odd_sign_2d_tensor_p3 }, - { flip_odd_sign_3d_ser_p0, flip_odd_sign_3d_ser_p1, flip_odd_sign_3d_tensor_p2, NULL }, - { flip_odd_sign_4d_ser_p0, flip_odd_sign_4d_ser_p1, flip_odd_sign_4d_tensor_p2, NULL }, - { flip_odd_sign_5d_ser_p0, flip_odd_sign_5d_ser_p1, flip_odd_sign_5d_tensor_p2, NULL }, - { flip_odd_sign_6d_ser_p0, flip_odd_sign_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*fs[4])(int dir, const double *f, double *fout); +} fos_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {flip_odd_sign_1d_ser_p0, flip_odd_sign_1d_ser_p1, flip_odd_sign_1d_ser_p2, + flip_odd_sign_1d_ser_p3}, + {flip_odd_sign_2d_ser_p0, flip_odd_sign_2d_ser_p1, flip_odd_sign_2d_tensor_p2, + flip_odd_sign_2d_tensor_p3}, + {flip_odd_sign_3d_ser_p0, flip_odd_sign_3d_ser_p1, flip_odd_sign_3d_tensor_p2, NULL}, + {flip_odd_sign_4d_ser_p0, flip_odd_sign_4d_ser_p1, flip_odd_sign_4d_tensor_p2, NULL}, + {flip_odd_sign_5d_ser_p0, flip_odd_sign_5d_ser_p1, flip_odd_sign_5d_tensor_p2, NULL}, + {flip_odd_sign_6d_ser_p0, flip_odd_sign_6d_ser_p1, NULL, NULL} }; // Flip-sign functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*fs[4])(int dir, const double *f, double *fout); } fes_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { flip_even_sign_1d_ser_p0, flip_even_sign_1d_ser_p1, flip_even_sign_1d_ser_p2, flip_even_sign_1d_ser_p3 }, - { flip_even_sign_2d_ser_p0, flip_even_sign_2d_ser_p1, flip_even_sign_2d_tensor_p2, flip_even_sign_2d_tensor_p3 }, - { flip_even_sign_3d_ser_p0, flip_even_sign_3d_ser_p1, flip_even_sign_3d_tensor_p2, NULL }, - { flip_even_sign_4d_ser_p0, flip_even_sign_4d_ser_p1, flip_even_sign_4d_tensor_p2, NULL }, - { flip_even_sign_5d_ser_p0, flip_even_sign_5d_ser_p1, flip_even_sign_5d_tensor_p2, NULL }, - { flip_even_sign_6d_ser_p0, flip_even_sign_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*fs[4])(int dir, const double *f, double *fout); +} fes_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {flip_even_sign_1d_ser_p0, flip_even_sign_1d_ser_p1, flip_even_sign_1d_ser_p2, + flip_even_sign_1d_ser_p3}, + {flip_even_sign_2d_ser_p0, flip_even_sign_2d_ser_p1, flip_even_sign_2d_tensor_p2, + flip_even_sign_2d_tensor_p3}, + {flip_even_sign_3d_ser_p0, flip_even_sign_3d_ser_p1, flip_even_sign_3d_tensor_p2, NULL}, + {flip_even_sign_4d_ser_p0, flip_even_sign_4d_ser_p1, flip_even_sign_4d_tensor_p2, NULL}, + {flip_even_sign_5d_ser_p0, flip_even_sign_5d_ser_p1, flip_even_sign_5d_tensor_p2, NULL}, + {flip_even_sign_6d_ser_p0, flip_even_sign_6d_ser_p1, NULL, NULL} }; // Node list function: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*nl[4])(double * node_list); } nl_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { node_coords_1d_ser_p0, node_coords_1d_ser_p1, node_coords_1d_ser_p2, NULL }, - { node_coords_2d_ser_p0, node_coords_2d_ser_p1, node_coords_2d_tensor_p2, NULL }, - { node_coords_3d_ser_p0, node_coords_3d_ser_p1, node_coords_3d_tensor_p2, NULL }, - { node_coords_4d_ser_p0, node_coords_4d_ser_p1, node_coords_4d_tensor_p2, NULL }, - { node_coords_5d_ser_p0, node_coords_5d_ser_p1, node_coords_5d_tensor_p2, NULL }, - { node_coords_6d_ser_p0, node_coords_6d_ser_p1, NULL, NULL }, +GKYL_CU_D static struct { + void (*nl[4])(double *node_list); +} nl_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {node_coords_1d_ser_p0, node_coords_1d_ser_p1, node_coords_1d_ser_p2, NULL}, + {node_coords_2d_ser_p0, node_coords_2d_ser_p1, node_coords_2d_tensor_p2, NULL}, + {node_coords_3d_ser_p0, node_coords_3d_ser_p1, node_coords_3d_tensor_p2, NULL}, + {node_coords_4d_ser_p0, node_coords_4d_ser_p1, node_coords_4d_tensor_p2, NULL}, + {node_coords_5d_ser_p0, node_coords_5d_ser_p1, node_coords_5d_tensor_p2, NULL}, + {node_coords_6d_ser_p0, node_coords_6d_ser_p1, NULL, NULL} }; // Nodal -> modal conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fnodal, double *fmodal); } n2m_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, nodal_to_modal_1d_ser_p1, nodal_to_modal_1d_ser_p2, NULL }, - { NULL, nodal_to_modal_2d_ser_p1, nodal_to_modal_2d_tensor_p2, NULL }, - { NULL, nodal_to_modal_3d_ser_p1, nodal_to_modal_3d_tensor_p2, NULL }, - { NULL, nodal_to_modal_4d_ser_p1, nodal_to_modal_4d_tensor_p2, NULL }, - { NULL, nodal_to_modal_5d_ser_p1, NULL, NULL }, // TODO - { NULL, nodal_to_modal_6d_ser_p1, NULL, NULL }, // TODO +GKYL_CU_D static struct { + void (*n2m[4])(const double *fnodal, double *fmodal); +} n2m_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, nodal_to_modal_1d_ser_p1, nodal_to_modal_1d_ser_p2, NULL}, + {NULL, nodal_to_modal_2d_ser_p1, nodal_to_modal_2d_tensor_p2, NULL}, + {NULL, nodal_to_modal_3d_ser_p1, nodal_to_modal_3d_tensor_p2, NULL}, + {NULL, nodal_to_modal_4d_ser_p1, nodal_to_modal_4d_tensor_p2, NULL}, + {NULL, nodal_to_modal_5d_ser_p1, NULL, NULL}, // TODO + {NULL, nodal_to_modal_6d_ser_p1, NULL, NULL} // TODO }; // Gauss-Legendre quadrature nodes nodal basis -> modal basis conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fquad, double *fmodal, long linc2); } qn2m_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, quad_to_modal_1d_ser_p1, quad_to_modal_1d_ser_p2, NULL }, - { NULL, quad_to_modal_2d_ser_p1, quad_to_modal_2d_tensor_p2, NULL }, - { NULL, quad_to_modal_3d_ser_p1, quad_to_modal_3d_tensor_p2, NULL }, - { NULL, quad_to_modal_4d_ser_p1, quad_to_modal_4d_tensor_p2, NULL }, - { NULL, quad_to_modal_5d_ser_p1, NULL, NULL }, // TODO - { NULL, quad_to_modal_6d_ser_p1, NULL, NULL }, // TODO +GKYL_CU_D static struct { + void (*n2m[4])(const double *fquad, double *fmodal, long linc2); +} qn2m_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, quad_to_modal_1d_ser_p1, quad_to_modal_1d_ser_p2, NULL}, + {NULL, quad_to_modal_2d_ser_p1, quad_to_modal_2d_tensor_p2, NULL}, + {NULL, quad_to_modal_3d_ser_p1, quad_to_modal_3d_tensor_p2, NULL}, + {NULL, quad_to_modal_4d_ser_p1, quad_to_modal_4d_tensor_p2, NULL}, + {NULL, quad_to_modal_5d_ser_p1, NULL, NULL}, // TODO + {NULL, quad_to_modal_6d_ser_p1, NULL, NULL} // TODO }; // Number of quadrature nodes: num_quad_list[ndim].count[poly_order] -GKYL_CU_D -static struct { int count[4]; } num_quad_list[] = { - { 0, 0, 0, 0 }, - { 0, 2, 3, 0 }, - { 0, 4, 8, 0 }, - { 0, 8, 27, 0 }, - { 0, 16, 81, 0 }, - { 0, 32, 0, 0 }, - { 0, 64, 0, 0 }, -}; +GKYL_CU_D static struct { + int count[4]; +} num_quad_list[] = {{0, 0, 0, 0}, {0, 2, 3, 0}, {0, 4, 8, 0}, {0, 8, 27, 0}, + {0, 16, 81, 0}, {0, 32, 0, 0}, {0, 64, 0, 0}}; // modal basis -> Gauss-Legendre quadrature nodes nodal basis conversion functions: ev_list[ndim].ev[poly_order] -GKYL_CU_D -static struct { void (*n2m[4])(const double *fmodal, double *fquad, long linc2); } m2qn_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, modal_to_quad_1d_ser_p1, modal_to_quad_1d_ser_p2, NULL }, - { NULL, modal_to_quad_2d_ser_p1, modal_to_quad_2d_tensor_p2, NULL }, - { NULL, modal_to_quad_3d_ser_p1, modal_to_quad_3d_tensor_p2, NULL }, - { NULL, modal_to_quad_4d_ser_p1, modal_to_quad_4d_tensor_p2, NULL }, - { NULL, modal_to_quad_5d_ser_p1, NULL, NULL }, // TODO - { NULL, modal_to_quad_6d_ser_p1, NULL, NULL }, // TODO +GKYL_CU_D static struct { + void (*n2m[4])(const double *fmodal, double *fquad, long linc2); +} m2qn_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, modal_to_quad_1d_ser_p1, modal_to_quad_1d_ser_p2, NULL}, + {NULL, modal_to_quad_2d_ser_p1, modal_to_quad_2d_tensor_p2, NULL}, + {NULL, modal_to_quad_3d_ser_p1, modal_to_quad_3d_tensor_p2, NULL}, + {NULL, modal_to_quad_4d_ser_p1, modal_to_quad_4d_tensor_p2, NULL}, + {NULL, modal_to_quad_5d_ser_p1, NULL, NULL}, // TODO + {NULL, modal_to_quad_6d_ser_p1, NULL, NULL} // TODO }; diff --git a/core/zero/gkyl_comm.h b/core/zero/gkyl_comm.h index 71b59c50c1..792a3aefd9 100644 --- a/core/zero/gkyl_comm.h +++ b/core/zero/gkyl_comm.h @@ -46,8 +46,10 @@ int gkyl_comm_get_size(struct gkyl_comm *comm, int *sz); * @param out Reduced values. * @return error code: 0 for success. */ -int gkyl_comm_allreduce(struct gkyl_comm *comm, enum gkyl_elem_type type, - enum gkyl_array_op op, int nelem, const void *inp, void *out); +int gkyl_comm_allreduce( + struct gkyl_comm *comm, enum gkyl_elem_type type, enum gkyl_array_op op, int nelem, + const void *inp, void *out +); /** * All reduce values across domains on the host/MPI communicator. @@ -60,8 +62,10 @@ int gkyl_comm_allreduce(struct gkyl_comm *comm, enum gkyl_elem_type type, * @param out Reduced values. * @return error code: 0 for success. */ -int gkyl_comm_allreduce_host(struct gkyl_comm *comm, enum gkyl_elem_type type, - enum gkyl_array_op op, int nelem, const void *inp, void *out); +int gkyl_comm_allreduce_host( + struct gkyl_comm *comm, enum gkyl_elem_type type, enum gkyl_array_op op, int nelem, + const void *inp, void *out +); /** * Gather all local data into a global array on each process. @@ -73,9 +77,10 @@ int gkyl_comm_allreduce_host(struct gkyl_comm *comm, enum gkyl_elem_type type, * @param array_global Global array. * @return error code: 0 for success. */ -int gkyl_comm_array_allgather(struct gkyl_comm *comm, - const struct gkyl_range *local, const struct gkyl_range *global, - const struct gkyl_array *array_local, struct gkyl_array *array_global); +int gkyl_comm_array_allgather( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *global, + const struct gkyl_array *array_local, struct gkyl_array *array_global +); /** * Gather all local data on host into a global array on each process. @@ -87,9 +92,10 @@ int gkyl_comm_array_allgather(struct gkyl_comm *comm, * @param array_global Global array. * @return error code: 0 for success. */ -int gkyl_comm_array_allgather_host(struct gkyl_comm *comm, - const struct gkyl_range *local, const struct gkyl_range *global, - const struct gkyl_array *array_local, struct gkyl_array *array_global); +int gkyl_comm_array_allgather_host( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *global, + const struct gkyl_array *array_local, struct gkyl_array *array_global +); /** * Broadcast an array to other processes. @@ -100,8 +106,10 @@ int gkyl_comm_array_allgather_host(struct gkyl_comm *comm, * @param root Broadcasting process. * @return error code: 0 for success. */ -int gkyl_comm_array_bcast(struct gkyl_comm *comm, - const struct gkyl_array *array_send, struct gkyl_array *array_recv, int root); +int gkyl_comm_array_bcast( + struct gkyl_comm *comm, const struct gkyl_array *array_send, struct gkyl_array *array_recv, + int root +); /** * Broadcast a host side array to other processes. @@ -112,8 +120,10 @@ int gkyl_comm_array_bcast(struct gkyl_comm *comm, * @param root Broadcasting process. * @return error code: 0 for success. */ -int gkyl_comm_array_bcast_host(struct gkyl_comm *comm, - const struct gkyl_array *array_send, struct gkyl_array *array_recv, int root); +int gkyl_comm_array_bcast_host( + struct gkyl_comm *comm, const struct gkyl_array *array_send, struct gkyl_array *array_recv, + int root +); /** * Synchronize array across domain. @@ -124,10 +134,10 @@ int gkyl_comm_array_bcast_host(struct gkyl_comm *comm, * @param array Array to synchronize. * @return error code: 0 for success. */ -int gkyl_comm_array_sync(struct gkyl_comm *comm, - const struct gkyl_range *local, - const struct gkyl_range *local_ext, - struct gkyl_array *array); +int gkyl_comm_array_sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + struct gkyl_array *array +); /** * Synchronize array across domain in periodic directions. @@ -140,11 +150,10 @@ int gkyl_comm_array_sync(struct gkyl_comm *comm, * @param array Array to synchronize. * @return error code: 0 for success. */ -int gkyl_comm_array_per_sync(struct gkyl_comm *comm, - const struct gkyl_range *local, - const struct gkyl_range *local_ext, - int nper_dirs, const int *per_dirs, - struct gkyl_array *array); +int gkyl_comm_array_per_sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + int nper_dirs, const int *per_dirs, struct gkyl_array *array +); /** * Barrier across domains @@ -154,7 +163,6 @@ int gkyl_comm_array_per_sync(struct gkyl_comm *comm, */ int gkyl_comm_barrier(struct gkyl_comm *comm); - /** * Start and end a group call * @@ -173,8 +181,8 @@ void gkyl_comm_group_call_end(struct gkyl_comm *comm); * @param erange Range to extend by. * @return Newly created communicator. */ -struct gkyl_comm* gkyl_comm_extend_comm(const struct gkyl_comm *comm, - const struct gkyl_range *erange); +struct gkyl_comm * +gkyl_comm_extend_comm(const struct gkyl_comm *comm, const struct gkyl_range *erange); /** * Split a communicator into a new communcator based on color. All @@ -186,8 +194,8 @@ struct gkyl_comm* gkyl_comm_extend_comm(const struct gkyl_comm *comm, * @param new_decomp Decomp object to associate new communicator. Can be NULL. * @return Newly created communicator. */ -struct gkyl_comm* gkyl_comm_split_comm(const struct gkyl_comm *comm, int color, - struct gkyl_rect_decomp *new_decomp); +struct gkyl_comm * +gkyl_comm_split_comm(const struct gkyl_comm *comm, int color, struct gkyl_rect_decomp *new_decomp); /** * Create a new communicator that incudes a subset of ranks in @a @@ -202,9 +210,10 @@ struct gkyl_comm* gkyl_comm_split_comm(const struct gkyl_comm *comm, int color, * @param is_valid On output, true if comm is usable, false otherwise. * @return Newly created communicator. */ -struct gkyl_comm* gkyl_comm_create_comm_from_ranks(const struct gkyl_comm *comm, int nranks, - const int *ranks, struct gkyl_rect_decomp *new_decomp, - bool *is_valid); +struct gkyl_comm *gkyl_comm_create_comm_from_ranks( + const struct gkyl_comm *comm, int nranks, const int *ranks, struct gkyl_rect_decomp *new_decomp, + bool *is_valid +); /** * Acquire pointer to communicator @@ -212,7 +221,7 @@ struct gkyl_comm* gkyl_comm_create_comm_from_ranks(const struct gkyl_comm *comm, * @param comm Communicator to to get acquire. * @return Acquired comm obj pointer. */ -struct gkyl_comm* gkyl_comm_acquire(const struct gkyl_comm *comm); +struct gkyl_comm *gkyl_comm_acquire(const struct gkyl_comm *comm); /** * Release communicator memory. diff --git a/core/zero/gkyl_comm_io.h b/core/zero/gkyl_comm_io.h index f89a438c1b..28979598e3 100644 --- a/core/zero/gkyl_comm_io.h +++ b/core/zero/gkyl_comm_io.h @@ -12,11 +12,10 @@ * @param fname Name of output file (include .gkyl extension) * @return Status flag: 0 if write succeeded, 'errno' otherwise */ -int gkyl_comm_array_write(struct gkyl_comm *comm, - const struct gkyl_rect_grid *grid, - const struct gkyl_range *range, - const struct gkyl_msgpack_data *meta, - const struct gkyl_array *arr, const char *fname); +int gkyl_comm_array_write( + struct gkyl_comm *comm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + const struct gkyl_msgpack_data *meta, const struct gkyl_array *arr, const char *fname +); /** * Read array data from .gkyl format. The input grid must be @@ -30,6 +29,7 @@ int gkyl_comm_array_write(struct gkyl_comm *comm, * @param fname Name of output file (include .gkyl extension) * @return Status flag: 0 if write succeeded, 'errno' otherwise */ -int gkyl_comm_array_read(struct gkyl_comm *comm, - const struct gkyl_rect_grid *grid, const struct gkyl_range *range, - struct gkyl_array *arr, const char *fname); +int gkyl_comm_array_read( + struct gkyl_comm *comm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + struct gkyl_array *arr, const char *fname +); diff --git a/core/zero/gkyl_comm_priv.h b/core/zero/gkyl_comm_priv.h index 7c9100fe32..64096ec39b 100644 --- a/core/zero/gkyl_comm_priv.h +++ b/core/zero/gkyl_comm_priv.h @@ -9,59 +9,65 @@ typedef int (*get_rank_t)(struct gkyl_comm *comm, int *rank); typedef int (*get_size_t)(struct gkyl_comm *comm, int *sz); // "Reduce" all elements of @a type in array @a data and store output in @a out -typedef int (*allreduce_t)(struct gkyl_comm *comm, enum gkyl_elem_type type, - enum gkyl_array_op op, int nelem, const void *inp, void *out); +typedef int (*allreduce_t)( + struct gkyl_comm *comm, enum gkyl_elem_type type, enum gkyl_array_op op, int nelem, + const void *inp, void *out +); // Gather local arrays into global array on each process. -typedef int (*gkyl_array_allgather_t)(struct gkyl_comm *comm, - const struct gkyl_range *local, const struct gkyl_range *global, - const struct gkyl_array *array_local, struct gkyl_array *array_global); +typedef int (*gkyl_array_allgather_t)( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *global, + const struct gkyl_array *array_local, struct gkyl_array *array_global +); // Broadcast array to other processes. -typedef int (*gkyl_array_bcast_t)(struct gkyl_comm *comm, - const struct gkyl_array *array_send, struct gkyl_array *array_recv, int root); +typedef int (*gkyl_array_bcast_t)( + struct gkyl_comm *comm, const struct gkyl_array *array_send, struct gkyl_array *array_recv, + int root +); // "Synchronize" @a array across the regions or blocks. -typedef int (*gkyl_array_sync_t)(struct gkyl_comm *comm, - const struct gkyl_range *local, const struct gkyl_range *local_ext, - struct gkyl_array *array); +typedef int (*gkyl_array_sync_t)( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + struct gkyl_array *array +); // "Synchronize" @a array across the periodic directions -typedef int (*gkyl_array_per_sync_t)(struct gkyl_comm *comm, - const struct gkyl_range *local, - const struct gkyl_range *local_ext, - int nper_dirs, const int *per_dirs, - struct gkyl_array *array); +typedef int (*gkyl_array_per_sync_t)( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + int nper_dirs, const int *per_dirs, struct gkyl_array *array +); // Write array to specified file -typedef int (*gkyl_array_write_t)(struct gkyl_comm *comm, - const struct gkyl_rect_grid *grid, - const struct gkyl_range *range, - const struct gkyl_msgpack_data *meta, - const struct gkyl_array *arr, const char *fname); +typedef int (*gkyl_array_write_t)( + struct gkyl_comm *comm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + const struct gkyl_msgpack_data *meta, const struct gkyl_array *arr, const char *fname +); // Read array from specified file -typedef int (*gkyl_array_read_t)(struct gkyl_comm *comm, - const struct gkyl_rect_grid *grid, const struct gkyl_range *range, - struct gkyl_array *arr, const char *fname); +typedef int (*gkyl_array_read_t)( + struct gkyl_comm *comm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + struct gkyl_array *arr, const char *fname +); // Create a new communicator that extends the communcator to work on a // extended domain specified by erange -typedef struct gkyl_comm* (*extend_comm_t)(const struct gkyl_comm *comm, - const struct gkyl_range *erange); +typedef struct gkyl_comm *(*extend_comm_t)( + const struct gkyl_comm *comm, const struct gkyl_range *erange +); // Create a new communicator by splitting a comm, and choosing members // of new communicator according to the color rank. It can be used with // a new decomp object, or the same one used for the parent comm, depending // of the use case. -typedef struct gkyl_comm* (*split_comm_t)(const struct gkyl_comm *comm, - int color, struct gkyl_rect_decomp *new_decomp); +typedef struct gkyl_comm *(*split_comm_t)( + const struct gkyl_comm *comm, int color, struct gkyl_rect_decomp *new_decomp +); // Create a new communicator from the input comm that takes a list of // ranks to include in it. typedef struct gkyl_comm *(*create_comm_from_ranks_t)( - const struct gkyl_comm *comm, int nranks, const int *ranks, - struct gkyl_rect_decomp *new_decomp, + const struct gkyl_comm *comm, int nranks, const int *ranks, struct gkyl_rect_decomp *new_decomp, bool *is_valid ); @@ -78,21 +84,21 @@ struct gkyl_comm_priv { struct gkyl_comm pub_comm; // public facing communicator // FOLLOWING DO NOT NEED A DECOMP - + get_rank_t get_rank; // get local rank function. get_size_t get_size; // get number of ranks. barrier_t barrier; // barrier. allreduce_t allreduce; // all reduce function allreduce_t allreduce_host; // all reduce using the host (MPI) communicator - + extend_comm_t extend_comm; // extend communcator - split_comm_t split_comm; // split communicator. - create_comm_from_ranks_t create_comm_from_ranks; // communictor from ranks + split_comm_t split_comm; // split communicator. + create_comm_from_ranks_t create_comm_from_ranks; // communictor from ranks comm_group_call_start_t comm_group_call_start; // start a group call comm_group_call_end_t comm_group_call_end; // end a group call - // FOLLOWING NEED A DECOMP + // FOLLOWING NEED A DECOMP gkyl_array_allgather_t gkyl_array_allgather; // gather local arrays to global array gkyl_array_allgather_t gkyl_array_allgather_host; // gather local arrays to global array on host diff --git a/core/zero/gkyl_const.h b/core/zero/gkyl_const.h index 45bbdf9cbb..ddc33b8c32 100644 --- a/core/zero/gkyl_const.h +++ b/core/zero/gkyl_const.h @@ -1,7 +1,7 @@ #pragma once #define GKYL_PI (3.141592653589793238462643383279502884) -#define GKYL_E (2.718281828459045235360287471352662497) +#define GKYL_E (2.718281828459045235360287471352662497) #define GKYL_SPEED_OF_LIGHT (299792458.0) // m/s #define GKYL_PLANCKS_CONSTANT_H (6.62606896e-34) // joule*seconds #define GKYL_ELECTRON_MASS (9.10938215e-31) // Kg @@ -10,5 +10,5 @@ #define GKYL_ELEMENTARY_CHARGE (1.602176487e-19) // Coulomb #define GKYL_BOLTZMANN_CONSTANT (1.3806488e-23) #define GKYL_EPSILON0 (8.854187817620389850536563031710750260608e-12) // farad/meter -#define GKYL_MU0 (12.56637061435917295385057353311801153679e-7) // newtons/ampere/ampere -#define GKYL_EV2KELVIN (GKYL_ELEMENTARY_CHARGE/GKYL_BOLTZMANN_CONSTANT) +#define GKYL_MU0 (12.56637061435917295385057353311801153679e-7) // newtons/ampere/ampere +#define GKYL_EV2KELVIN (GKYL_ELEMENTARY_CHARGE / GKYL_BOLTZMANN_CONSTANT) diff --git a/core/zero/gkyl_cudss_ops.h b/core/zero/gkyl_cudss_ops.h index 239457be02..91bedfeea1 100644 --- a/core/zero/gkyl_cudss_ops.h +++ b/core/zero/gkyl_cudss_ops.h @@ -22,7 +22,7 @@ typedef struct gkyl_culinsolver_prob gkyl_culinsolver_prob; * This solver assumes that nrhs is the same for all nprob problems, * and that the sparsity pattern of all A_i's is the same. */ -struct gkyl_culinsolver_prob* gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs); +struct gkyl_culinsolver_prob *gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs); /** * Initialize cuDSS matrix A in Ax=B problem from a list of triples. @@ -30,7 +30,9 @@ struct gkyl_culinsolver_prob* gkyl_culinsolver_prob_new(int nprob, int mrow, int * @param prob cuDSS struct holding arrays used in problem. * @param tri (array of) coordinates & values of non-zero entries in A matrix (triplets). */ -void gkyl_culinsolver_amat_from_triples(struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri); +void gkyl_culinsolver_amat_from_triples( + struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri +); /** * Update the cuDSS matrix A in Ax=B problem using an array of values (on the device). @@ -48,7 +50,9 @@ void gkyl_culinsolver_amat_update(struct gkyl_culinsolver_prob *prob, double *cs * @param prob cuDSS struct holding arrays used in problem. * @param tri (array of) coordinates & values of non-zero entries in A matrix (triplets). */ -void gkyl_culinsolver_amat_update_from_triples(struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri); +void gkyl_culinsolver_amat_update_from_triples( + struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri +); /** * Initialize right-hand-side cuDSS matrix B in Ax=B problem from a list of @@ -103,7 +107,7 @@ void gkyl_culinsolver_clear_csr_values(struct gkyl_culinsolver_prob *prob, doubl * @param loc element we wish to return a pointer to. * @return pointer to loc-th element in RHS vector. */ -double* gkyl_culinsolver_get_rhs_ptr(struct gkyl_culinsolver_prob *prob, long loc); +double *gkyl_culinsolver_get_rhs_ptr(struct gkyl_culinsolver_prob *prob, long loc); /** * Get a pointer to the element of the solution vector at a given location. @@ -114,7 +118,7 @@ double* gkyl_culinsolver_get_rhs_ptr(struct gkyl_culinsolver_prob *prob, long lo * @param loc element we wish to return a pointer to. * @return pointer to loc-th element in solution vector. */ -double* gkyl_culinsolver_get_sol_ptr(struct gkyl_culinsolver_prob *prob, long loc); +double *gkyl_culinsolver_get_sol_ptr(struct gkyl_culinsolver_prob *prob, long loc); /** * Obtain the RHS value at location loc (a linear index into the RHS matrix). @@ -133,7 +137,7 @@ double gkyl_culinsolver_get_sol_lin(struct gkyl_culinsolver_prob *prob, long loc * @param loc linear index into the csr_val array. * @return RHS value. */ -double* gkyl_culinsolver_get_csr_values_ptr(struct gkyl_culinsolver_prob *prob, long loc); +double *gkyl_culinsolver_get_csr_values_ptr(struct gkyl_culinsolver_prob *prob, long loc); /** * Release cuDSS problem diff --git a/core/zero/gkyl_cusolver_ops.h b/core/zero/gkyl_cusolver_ops.h index ade556c3e9..c27cc4739d 100644 --- a/core/zero/gkyl_cusolver_ops.h +++ b/core/zero/gkyl_cusolver_ops.h @@ -25,7 +25,7 @@ typedef struct gkyl_culinsolver_prob gkyl_culinsolver_prob; * dimensions and sparsity pattern) where each problem only has a * right-side vector with a single column. */ -struct gkyl_culinsolver_prob* gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs); +struct gkyl_culinsolver_prob *gkyl_culinsolver_prob_new(int nprob, int mrow, int ncol, int nrhs); /** * Initialize cuSolver matrix A in Ax=B problem from a list of triples. @@ -33,7 +33,9 @@ struct gkyl_culinsolver_prob* gkyl_culinsolver_prob_new(int nprob, int mrow, int * @param prob cuSolver struct holding arrays used in problem. * @param tri (array of) coordinates & values of non-zero entries in A matrix (triplets). */ -void gkyl_culinsolver_amat_from_triples(struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri); +void gkyl_culinsolver_amat_from_triples( + struct gkyl_culinsolver_prob *prob, struct gkyl_mat_triples **tri +); /** * Initialize right-hand-side cuSolver matrix B in Ax=B problem from a list of @@ -73,7 +75,7 @@ void gkyl_culinsolver_clear_rhs(struct gkyl_culinsolver_prob *prob, double val); * @param loc element we wish to return a pointer to. * @return pointer to loc-th element in RHS vector. */ -double* gkyl_culinsolver_get_rhs_ptr(struct gkyl_culinsolver_prob *prob, long loc); +double *gkyl_culinsolver_get_rhs_ptr(struct gkyl_culinsolver_prob *prob, long loc); /** * Get a pointer to the element of the solution vector at a given location. @@ -84,7 +86,7 @@ double* gkyl_culinsolver_get_rhs_ptr(struct gkyl_culinsolver_prob *prob, long lo * @param loc element we wish to return a pointer to. * @return pointer to loc-th element in solution vector. */ -double* gkyl_culinsolver_get_sol_ptr(struct gkyl_culinsolver_prob *prob, long loc); +double *gkyl_culinsolver_get_sol_ptr(struct gkyl_culinsolver_prob *prob, long loc); /** * Obtain the RHS ielement-th value of the jprob-th linear problem. diff --git a/core/zero/gkyl_dflt.h b/core/zero/gkyl_dflt.h index f5181bb409..a4a82d44ba 100644 --- a/core/zero/gkyl_dflt.h +++ b/core/zero/gkyl_dflt.h @@ -1,7 +1,7 @@ #pragma once #if defined(__GNUC__) || defined(__GNUG__) -#if defined(__arm__) || defined(__arm64__) || defined(__powerpc64__) +#if defined(__arm__) || defined(__arm64__) || defined(__powerpc64__) // nothing for arm chips / power9 #else #include @@ -16,14 +16,13 @@ #include #endif #endif -#endif +#endif /** Disable denormalized floats from occuring */ -static void -disable_denorm_float(void) +static void disable_denorm_float(void) { #if defined(__GNUC__) || defined(__GNUG__) -#if defined(__arm__) || defined(__arm64__) || defined(__powerpc64__) +#if defined(__arm__) || defined(__arm64__) || defined(__powerpc64__) // nothing for arm chips #else _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); @@ -38,5 +37,5 @@ disable_denorm_float(void) fesetenv(FE_DFL_DISABLE_SSE_DENORMS_ENV); #endif #endif -#endif +#endif } diff --git a/core/zero/gkyl_dg_array_mask.h b/core/zero/gkyl_dg_array_mask.h index 5b40fd5338..e2717b6e73 100644 --- a/core/zero/gkyl_dg_array_mask.h +++ b/core/zero/gkyl_dg_array_mask.h @@ -9,26 +9,27 @@ typedef struct gkyl_dg_array_mask gkyl_dg_array_mask; enum gkyl_dg_array_mask_types { - GKYL_DG_ARRAY_MASK_NONE = 0, // No mask applied. - GKYL_DG_ARRAY_MASK_C0_LESS, // Mask applied based on the 0th component of the array. - GKYL_DG_ARRAY_MASK_C0_LESS_FRAC, // Applies the mask based on the global maximum 0th component of the input array. - GKYL_DG_ARRAY_MASK_C0_LESS_FRAC_CONF, // Applies the mask based on the local maximum 0th component of the input array, which is spatially dependent. - GKYL_DG_ARRAY_MASK_C0_GREATER, // Mask applied based on the 0th component of the array. - GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC, // Applies the mask based on the global maximum 0th component of the input array. - GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF, // Applies the mask based on the local maximum 0th component of the input array, which is spatially dependent. + GKYL_DG_ARRAY_MASK_NONE = 0, // No mask applied. + GKYL_DG_ARRAY_MASK_C0_LESS, // Mask applied based on the 0th component of the array. + GKYL_DG_ARRAY_MASK_C0_LESS_FRAC, // Applies the mask based on the global maximum 0th component of the input array. + GKYL_DG_ARRAY_MASK_C0_LESS_FRAC_CONF, // Applies the mask based on the local maximum 0th component of the input array, which is spatially dependent. + GKYL_DG_ARRAY_MASK_C0_GREATER, // Mask applied based on the 0th component of the array. + GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC, // Applies the mask based on the global maximum 0th component of the input array. + GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF // Applies the mask based on the local maximum 0th component of the input array, which is spatially dependent. }; // Input structure for creating a mask object. struct gkyl_dg_array_mask_inp { - enum gkyl_dg_array_mask_types type; // Type of mask. - bool default_value; // Default value for mask (true/false) if no masking is applied. - double threshold; // Threshold for marking cells as masked. Absolute value for *_THRESHOLD types, fraction (0-1) for *_FRAC_THRESHOLD types. - const struct gkyl_range *phase_rng; // Phase-space range. + enum gkyl_dg_array_mask_types type; // Type of mask. + bool default_value; // Default value for mask (true/false) if no masking is applied. + double + threshold; // Threshold for marking cells as masked. Absolute value for *_THRESHOLD types, fraction (0-1) for *_FRAC_THRESHOLD types. + const struct gkyl_range *phase_rng; // Phase-space range. const struct gkyl_range *phase_rng_ext; // Extended phase-space range. - const struct gkyl_range *conf_rng; // Configuration-space range. - const struct gkyl_range *conf_rng_ext; // Extended configuration-space range. - const struct gkyl_range *vel_rng; // Velocity-space range. - bool use_gpu; // Flag indicating GPU usage. + const struct gkyl_range *conf_rng; // Configuration-space range. + const struct gkyl_range *conf_rng_ext; // Extended configuration-space range. + const struct gkyl_range *vel_rng; // Velocity-space range. + bool use_gpu; // Flag indicating GPU usage. }; /** @@ -40,8 +41,7 @@ struct gkyl_dg_array_mask_inp { * @param mask_inp Input parameters for mask. * @return New mask object. */ -struct gkyl_dg_array_mask* -gkyl_dg_array_mask_new(struct gkyl_dg_array_mask_inp mask_inp); +struct gkyl_dg_array_mask *gkyl_dg_array_mask_new(struct gkyl_dg_array_mask_inp mask_inp); /** * Compute the appropriate threshold for fractional threshold masks. @@ -49,9 +49,7 @@ gkyl_dg_array_mask_new(struct gkyl_dg_array_mask_inp mask_inp); * @param mask Mask updater. * @param global_max Global maximum value from input array. */ -void -gkyl_dg_array_mask_advance_threshold(struct gkyl_dg_array_mask *mask, - const double global_max); +void gkyl_dg_array_mask_advance_threshold(struct gkyl_dg_array_mask *mask, const double global_max); /** * Compute the appropriate mask given the input array. @@ -59,8 +57,7 @@ gkyl_dg_array_mask_advance_threshold(struct gkyl_dg_array_mask *mask, * @param mask Mask updater. * @param arr_in Array which the mask is applied on top of. */ -void -gkyl_dg_array_mask_advance(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in); +void gkyl_dg_array_mask_advance(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in); /** * Evaluate if the conditional mask is true at a given multi-dimensional index. @@ -83,14 +80,14 @@ void gkyl_dg_array_mask_eval_idx(struct gkyl_dg_array_mask *mask, const int *idx * @param mask Mask object. * @param arr_in Array to be multiplied by the mask. */ -void -gkyl_dg_array_mask_scale_by_cell(struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in); +void gkyl_dg_array_mask_scale_by_cell( + struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_in +); /** * Acquire a reference to the mask object. */ -struct gkyl_dg_array_mask* -gkyl_dg_array_mask_acquire(struct gkyl_dg_array_mask *mask); +struct gkyl_dg_array_mask *gkyl_dg_array_mask_acquire(struct gkyl_dg_array_mask *mask); /** * Get the underlying mask array. @@ -98,21 +95,18 @@ gkyl_dg_array_mask_acquire(struct gkyl_dg_array_mask *mask); * @param mask Mask object. * @return Pointer to the mask array. */ -const struct gkyl_array* -gkyl_dg_array_mask_get_mask(const struct gkyl_dg_array_mask *mask); +const struct gkyl_array *gkyl_dg_array_mask_get_mask(const struct gkyl_dg_array_mask *mask); /** * Get device pointer to mask object. * * @param mask Mask object. */ -struct gkyl_dg_array_mask* -gkyl_dg_array_mask_get_dev_ptr(struct gkyl_dg_array_mask *mask); +struct gkyl_dg_array_mask *gkyl_dg_array_mask_get_dev_ptr(struct gkyl_dg_array_mask *mask); /** * Release memory associated with mask object. * * @param mask Mask object to release. */ -void -gkyl_dg_array_mask_release(struct gkyl_dg_array_mask *mask); +void gkyl_dg_array_mask_release(struct gkyl_dg_array_mask *mask); diff --git a/core/zero/gkyl_dg_array_mask_priv.h b/core/zero/gkyl_dg_array_mask_priv.h index 3b51d51f79..bc9816b6de 100644 --- a/core/zero/gkyl_dg_array_mask_priv.h +++ b/core/zero/gkyl_dg_array_mask_priv.h @@ -9,18 +9,21 @@ * Skip cell object definition. */ struct gkyl_dg_array_mask { - enum gkyl_dg_array_mask_types type; // Type of mask operation. - bool default_value; // Default value for mask (true/false) if no masking is applied. Defaults to false (-1.0). - struct gkyl_array *mask_arr; // Mask array (1.0 is true, -1.0 is false). - double threshold; // Threshold for marking cells as masked. Scaled absolute value for *_THRESHOLD types, fraction for *_FRAC_THRESHOLD types. - double frac_threshold; // Fractional threshold, which is 0-1 for global fraction mask. - const struct gkyl_range *mask_rng; // Pointer to range over which mask is applied (phase_rng for kinetic, conf_rng for fluid). - int mask_rng_ndim; // Dimensionality of the mask's range. - const struct gkyl_range *mask_rng_ext; // Pointer to extended range for mask allocation. - const struct gkyl_range *conf_rng; // Configuration-space range. - const struct gkyl_range *conf_rng_ext; // Extended configuration-space range. - const struct gkyl_range *vel_rng; // Velocity-space range. - bool use_gpu; // Flag indicating GPU usage. + enum gkyl_dg_array_mask_types type; // Type of mask operation. + bool + default_value; // Default value for mask (true/false) if no masking is applied. Defaults to false (-1.0). + struct gkyl_array *mask_arr; // Mask array (1.0 is true, -1.0 is false). + double + threshold; // Threshold for marking cells as masked. Scaled absolute value for *_THRESHOLD types, fraction for *_FRAC_THRESHOLD types. + double frac_threshold; // Fractional threshold, which is 0-1 for global fraction mask. + const struct gkyl_range * + mask_rng; // Pointer to range over which mask is applied (phase_rng for kinetic, conf_rng for fluid). + int mask_rng_ndim; // Dimensionality of the mask's range. + const struct gkyl_range *mask_rng_ext; // Pointer to extended range for mask allocation. + const struct gkyl_range *conf_rng; // Configuration-space range. + const struct gkyl_range *conf_rng_ext; // Extended configuration-space range. + const struct gkyl_range *vel_rng; // Velocity-space range. + bool use_gpu; // Flag indicating GPU usage. struct gkyl_array *local_max_arr; // Pre-allocated config-space array for spatial fractional masks. @@ -35,8 +38,9 @@ struct gkyl_dg_array_mask { bool (*eval_idx_func)(struct gkyl_dg_array_mask *mask, const int *idx); // Function pointer for scale_by_cell method, set at init time based on mask type. - void (*scale_by_cell_func)(struct gkyl_dg_array_mask *mask, - const struct gkyl_array *arr_to_multiply); + void (*scale_by_cell_func)( + struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_to_multiply + ); uint32_t flags; struct gkyl_dg_array_mask *on_dev; // Pointer to device object. @@ -52,16 +56,12 @@ struct gkyl_dg_array_mask { */ void gkyl_dg_array_mask_free(const struct gkyl_ref_count *ref); -GKYL_CU_DH -static bool -eval_idx_ker_disabled(struct gkyl_dg_array_mask *mask, const int *idx) +GKYL_CU_DH static bool eval_idx_ker_disabled(struct gkyl_dg_array_mask *mask, const int *idx) { return mask->default_value; } -GKYL_CU_DH -static bool -eval_idx_ker_enabled(struct gkyl_dg_array_mask *mask, const int *idx) +GKYL_CU_DH static bool eval_idx_ker_enabled(struct gkyl_dg_array_mask *mask, const int *idx) { long linidx = gkyl_range_idx(mask->mask_rng, idx); const double *mask_c = (const double *)gkyl_array_cfetch(mask->mask_arr, linidx); @@ -75,8 +75,7 @@ eval_idx_ker_enabled(struct gkyl_dg_array_mask *mask, const int *idx) * @param idx Multi-dimensional index array. * @return Value of the mask at the given index. */ -GKYL_CU_DH -static inline bool +GKYL_CU_DH static inline bool gkyl_dg_array_mask_eval_idx_ker(struct gkyl_dg_array_mask *mask, const int *idx) { return mask->eval_idx_func(mask, idx); @@ -90,7 +89,7 @@ gkyl_dg_array_mask_eval_idx_ker(struct gkyl_dg_array_mask *mask, const int *idx) * @param mask_ho Host-side dg_array_mask object. * @return New dg_array_mask object on device. */ -struct gkyl_dg_array_mask* gkyl_dg_array_mask_cu_dev_new(struct gkyl_dg_array_mask *mask_ho); +struct gkyl_dg_array_mask *gkyl_dg_array_mask_cu_dev_new(struct gkyl_dg_array_mask *mask_ho); /** * CUDA device function to update dg_array_mask on GPU. @@ -98,9 +97,9 @@ struct gkyl_dg_array_mask* gkyl_dg_array_mask_cu_dev_new(struct gkyl_dg_array_ma * @param mask dg_array_mask object. * @param arr_to_mask Array to mask. */ -void gkyl_dg_array_mask_advance_cu(struct gkyl_dg_array_mask *mask, - const struct gkyl_array *arr_to_mask); - +void gkyl_dg_array_mask_advance_cu( + struct gkyl_dg_array_mask *mask, const struct gkyl_array *arr_to_mask +); /** * CUDA device function to update the mask's threshold on GPU. @@ -108,9 +107,9 @@ void gkyl_dg_array_mask_advance_cu(struct gkyl_dg_array_mask *mask, * @param mask dg_array_mask object. * @param global_max Global maximum value used for fractional thresholding. */ -void -gkyl_dg_array_mask_advance_threshold_cu(struct gkyl_dg_array_mask *mask, - const double global_max); +void gkyl_dg_array_mask_advance_threshold_cu( + struct gkyl_dg_array_mask *mask, const double global_max +); /** * CUDA device function to evaluate the mask at an index. diff --git a/core/zero/gkyl_dg_basis_ops.h b/core/zero/gkyl_dg_basis_ops.h index fe8c7059ce..be75867363 100644 --- a/core/zero/gkyl_dg_basis_ops.h +++ b/core/zero/gkyl_dg_basis_ops.h @@ -21,9 +21,10 @@ typedef struct gkyl_dg_basis_op_mem gkyl_dg_basis_op_mem; * @param rng Range object (should contain coord). * @param out Evaluation of the array at coord (on GPU if arr is on GPU). **/ -void gkyl_dg_basis_ops_eval_array_at_coord_comp(const struct gkyl_array *arr, const double *coord, - const struct gkyl_basis *basis, const struct gkyl_rect_grid *grid, const struct gkyl_range *rng, - double *out); +void gkyl_dg_basis_ops_eval_array_at_coord_comp( + const struct gkyl_array *arr, const double *coord, const struct gkyl_basis *basis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *rng, double *out +); /** * Evaluate laplacian, given expansion at point in the logical cell @@ -53,17 +54,17 @@ struct gkyl_basis_ops_evalf { void *ctx; // function context evalf_t eval_cubic; // function pointer to evaluate the cubic evalf_t eval_cubic_wgrad; // function pointer to evaluate the cubic & its gradient with signature - // void (*evalf_t)(double t, const double *xn, double *fout, void *ctx); - // On return, fout[0], fout[1], and fout[2] are the value, gradient in direction 0, - // and gradient in direction 1 of the cubic evaluated at grid coordinates xn. + // void (*evalf_t)(double t, const double *xn, double *fout, void *ctx); + // On return, fout[0], fout[1], and fout[2] are the value, gradient in direction 0, + // and gradient in direction 1 of the cubic evaluated at grid coordinates xn. evalf_t eval_cubic_wgrad2; // function pointer to evaluate the cubic & its 2nd derivatives - // On return, fout[0], fout[1], fout[2], and fout[3] are the value, second derivative - // in direction 0, second derivative in direction 1, and mixed partial derivative - // of the cubic evaluated at grid coordinates xn. + // On return, fout[0], fout[1], fout[2], and fout[3] are the value, second derivative + // in direction 0, second derivative in direction 1, and mixed partial derivative + // of the cubic evaluated at grid coordinates xn. eval_laplacian_expand eval_cubic_laplacian; // function pointer to evaluate the laplacian eval_mixedpartial_expand eval_cubic_mixedpartial; // function pointer to evaluate the mixed partial - struct gkyl_ref_count ref_count; -}; + struct gkyl_ref_count ref_count; +}; /** * Given values and gradients at the corner of a 1D cell, compute the @@ -104,9 +105,10 @@ void gkyl_dg_calc_cubic_1d(const double val[2], const double grad[2], double *co * @param gradxy gradxy[i] is the xy- (cross) derivative at node i * @param coeff On output, the DG expansion coefficients for p=3 tensor basis. */ -void gkyl_dg_calc_cubic_2d(const double val[4], - const double gradx[4], const double grady[4], const double gradxy[4], - double *coeff); +void gkyl_dg_calc_cubic_2d( + const double val[4], const double gradx[4], const double grady[4], const double gradxy[4], + double *coeff +); /** * Allocate memory for use in the computing 1D cubic reconstruction @@ -145,8 +147,10 @@ void gkyl_dg_basis_op_mem_release(gkyl_dg_basis_op_mem *mem); * @param nodal_vals Array holding nodal values * @param cubic On output, DG expansions of cubic */ -void gkyl_dg_calc_cubic_1d_from_nodal_vals(gkyl_dg_basis_op_mem *mem, int cells, double dx, - const struct gkyl_array *nodal_vals, struct gkyl_array *cubic); +void gkyl_dg_calc_cubic_1d_from_nodal_vals( + gkyl_dg_basis_op_mem *mem, int cells, double dx, const struct gkyl_array *nodal_vals, + struct gkyl_array *cubic +); /** * Compute cubic expansion from 2D nodal values. Note that the @@ -160,8 +164,10 @@ void gkyl_dg_calc_cubic_1d_from_nodal_vals(gkyl_dg_basis_op_mem *mem, int cells, * @param nodal_vals Array holding nodal values * @param cubic On output, DG expansions of cubic */ -void gkyl_dg_calc_cubic_2d_from_nodal_vals(gkyl_dg_basis_op_mem *mem, int cells[2], double dx[2], - const struct gkyl_array *nodal_vals, struct gkyl_array *cubic); +void gkyl_dg_calc_cubic_2d_from_nodal_vals( + gkyl_dg_basis_op_mem *mem, int cells[2], double dx[2], const struct gkyl_array *nodal_vals, + struct gkyl_array *cubic +); /** * Create a wrapper to the cubic interpolation from a given set of @@ -172,8 +178,8 @@ void gkyl_dg_calc_cubic_2d_from_nodal_vals(gkyl_dg_basis_op_mem *mem, int cells[ * @param nodal_vals Array holding nodal values * @return Struct with context and function pointer */ -struct gkyl_basis_ops_evalf* gkyl_dg_basis_ops_evalf_new(const struct gkyl_rect_grid *grid, - const struct gkyl_array *nodal_vals); +struct gkyl_basis_ops_evalf * +gkyl_dg_basis_ops_evalf_new(const struct gkyl_rect_grid *grid, const struct gkyl_array *nodal_vals); /** * Write the cubic DG representation to specified file. @@ -190,7 +196,8 @@ bool gkyl_dg_basis_ops_evalf_write_cubic(const struct gkyl_basis_ops_evalf *evf, * @param evf Memory to acquire * @retrun Pointer to newly acquired memory */ -struct gkyl_basis_ops_evalf* gkyl_dg_basis_ops_evalf_acquire(const struct gkyl_basis_ops_evalf *evf); +struct gkyl_basis_ops_evalf *gkyl_dg_basis_ops_evalf_acquire(const struct gkyl_basis_ops_evalf *evf +); /** * Release memory allocated for cubic interpolation. diff --git a/core/zero/gkyl_dg_basis_ops_priv.h b/core/zero/gkyl_dg_basis_ops_priv.h index a314da78c2..e5824dc513 100644 --- a/core/zero/gkyl_dg_basis_ops_priv.h +++ b/core/zero/gkyl_dg_basis_ops_priv.h @@ -12,8 +12,8 @@ * @param rng Range object (should contain coord). * @param out Evaluation of the array at coord (on GPU if arr is on GPU). **/ -void -gkyl_dg_basis_ops_eval_array_at_coord_comp_cu(const struct gkyl_array *arr, const double *coord, - const struct gkyl_basis *basis, const struct gkyl_rect_grid *grid, const struct gkyl_range *rng, - double *out); +void gkyl_dg_basis_ops_eval_array_at_coord_comp_cu( + const struct gkyl_array *arr, const double *coord, const struct gkyl_basis *basis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *rng, double *out +); #endif diff --git a/core/zero/gkyl_dg_bin_ops.h b/core/zero/gkyl_dg_bin_ops.h index 698ea4a06a..35f0936b21 100644 --- a/core/zero/gkyl_dg_bin_ops.h +++ b/core/zero/gkyl_dg_bin_ops.h @@ -15,7 +15,7 @@ typedef struct gkyl_dg_bin_op_mem gkyl_dg_bin_op_mem; * @param nbatch Batch size * @param neqn Number of equations in each batch */ -gkyl_dg_bin_op_mem* gkyl_dg_bin_op_mem_new(size_t nbatch, size_t neqn); +gkyl_dg_bin_op_mem *gkyl_dg_bin_op_mem_new(size_t nbatch, size_t neqn); // Same as above, except for GPUs gkyl_dg_bin_op_mem *gkyl_dg_bin_op_mem_cu_dev_new(size_t nbatch, size_t neqn); @@ -40,10 +40,10 @@ void gkyl_dg_bin_op_mem_release(gkyl_dg_bin_op_mem *mem); * @param c_rop Component of right operand to use in product * @param rop Right operand DG field */ -void gkyl_dg_mul_op(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop); +void gkyl_dg_mul_op( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_lop, + const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop +); /** * Same as gkyl_dg_mul_op, except operator is applied only on @@ -58,10 +58,11 @@ void gkyl_dg_mul_op(const struct gkyl_basis *basis, * @param rop Right operand DG field * @param range Range to apply multiplication operator */ -void gkyl_dg_mul_op_range(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop, const struct gkyl_range *range); +void gkyl_dg_mul_op_range( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_lop, + const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop, + const struct gkyl_range *range +); /** * Compute pout = cop*pop on specified range (sub-range of range @@ -76,10 +77,11 @@ void gkyl_dg_mul_op_range(const struct gkyl_basis *basis, * @param crange Conf-space range to apply multiplication operator. * @param prange Phase-space range to apply multiplication operator. */ -void gkyl_dg_mul_conf_phase_op_range(const struct gkyl_basis *cbasis, - const struct gkyl_basis *pbasis, struct gkyl_array* pout, - const struct gkyl_array* cop, const struct gkyl_array* pop, - const struct gkyl_range *crange, const struct gkyl_range *prange); +void gkyl_dg_mul_conf_phase_op_range( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, struct gkyl_array *pout, + const struct gkyl_array *cop, const struct gkyl_array *pop, const struct gkyl_range *crange, + const struct gkyl_range *prange +); /** * Compute pout += a*cop*pop on specified range (sub-range of range @@ -95,10 +97,11 @@ void gkyl_dg_mul_conf_phase_op_range(const struct gkyl_basis *cbasis, * @param crange Conf-space range to apply multiplication operator. * @param prange Phase-space range to apply multiplication operator. */ -void gkyl_dg_mul_conf_phase_op_accumulate_range(const struct gkyl_basis *cbasis, - const struct gkyl_basis *pbasis, struct gkyl_array* pout, double a, - const struct gkyl_array* cop, const struct gkyl_array* pop, - const struct gkyl_range *crange, const struct gkyl_range *prange); +void gkyl_dg_mul_conf_phase_op_accumulate_range( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, struct gkyl_array *pout, + double a, const struct gkyl_array *cop, const struct gkyl_array *pop, + const struct gkyl_range *crange, const struct gkyl_range *prange +); /** * Compute out = lop . rop, where lop and rop are vector fields. @@ -110,9 +113,10 @@ void gkyl_dg_mul_conf_phase_op_accumulate_range(const struct gkyl_basis *cbasis, * @param lop Left operand DG vector field. * @param rop Right operand DG vector field. */ -void gkyl_dg_dot_product_op(const struct gkyl_basis *basis, - struct gkyl_array* out, const struct gkyl_array* lop, - const struct gkyl_array* rop); +void gkyl_dg_dot_product_op( + const struct gkyl_basis *basis, struct gkyl_array *out, const struct gkyl_array *lop, + const struct gkyl_array *rop +); /** * Same as gkyl_dg_dot_product_op, except operator is applied only on @@ -124,9 +128,10 @@ void gkyl_dg_dot_product_op(const struct gkyl_basis *basis, * @param rop Right operand DG vector field. * @param range Range to apply dot product operator. */ -void gkyl_dg_dot_product_op_range(const struct gkyl_basis *basis, - struct gkyl_array* out, const struct gkyl_array* lop, - const struct gkyl_array* rop, const struct gkyl_range *range); +void gkyl_dg_dot_product_op_range( + const struct gkyl_basis *basis, struct gkyl_array *out, const struct gkyl_array *lop, + const struct gkyl_array *rop, const struct gkyl_range *range +); /** * Compute out = lop/rop. The c_oop, c_lop and c_rop are the @@ -143,10 +148,10 @@ void gkyl_dg_dot_product_op_range(const struct gkyl_basis *basis, * @param c_rop Component of right operand to use in product * @param rop Right operand DG field */ -void gkyl_dg_div_op(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop); +void gkyl_dg_div_op( + gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, + int c_lop, const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop +); /** * Same as gkyl_dg_div_op, except operator is applied only on @@ -162,10 +167,11 @@ void gkyl_dg_div_op(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, * @param rop Right operand DG field * @param range Range to apply multiplication operator */ -void gkyl_dg_div_op_range(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop, const struct gkyl_range *range); +void gkyl_dg_div_op_range( + gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, + int c_lop, const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop, + const struct gkyl_range *range +); /** * Compute out = 1/iop. The c_oop and c_iop are the @@ -179,8 +185,10 @@ void gkyl_dg_div_op_range(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basi * @param c_iop Component of input operand. * @param iop Input operand DG field. */ -void gkyl_dg_inv_op(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, int c_iop, const struct gkyl_array* iop); +void gkyl_dg_inv_op( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop +); /** * Compute out = 1/iop on specified range. The c_oop and c_iop are @@ -194,9 +202,10 @@ void gkyl_dg_inv_op(const struct gkyl_basis *basis, * @param c_iop Component of input operand. * @param iop Input operand DG field. */ -void gkyl_dg_inv_op_range(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, int c_iop, const struct gkyl_array* iop, - const struct gkyl_range *range); +void gkyl_dg_inv_op_range( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, const struct gkyl_range *range +); /** * Compute the cell-average of input array iop and store it in out @@ -209,9 +218,10 @@ void gkyl_dg_inv_op_range(const struct gkyl_basis *basis, * @param iop Input DG field * @param range Range to apply multiplication operator */ -void gkyl_dg_calc_average_range(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_iop, const struct gkyl_array* iop, struct gkyl_range range); +void gkyl_dg_calc_average_range( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, struct gkyl_range range +); /** * Compute the mean L2 norm of input array iop and store it in out @@ -224,67 +234,64 @@ void gkyl_dg_calc_average_range(const struct gkyl_basis *basis, * @param iop Input DG field * @param range Range to apply multiplication operator */ -void gkyl_dg_calc_l2_range(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_iop, const struct gkyl_array* iop, struct gkyl_range range); +void gkyl_dg_calc_l2_range( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, struct gkyl_range range +); /** * Host-side wrappers for dg_bin_op operations */ -void -gkyl_dg_mul_op_cu(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop); +void gkyl_dg_mul_op_cu( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_lop, + const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop +); -void -gkyl_dg_mul_op_range_cu(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop, const struct gkyl_range *range); +void gkyl_dg_mul_op_range_cu( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_lop, + const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop, + const struct gkyl_range *range +); -void -gkyl_dg_mul_conf_phase_op_range_cu(const struct gkyl_basis *cbasis, - const struct gkyl_basis *pbasis, struct gkyl_array* pout, - const struct gkyl_array* cop, const struct gkyl_array* pop, - const struct gkyl_range *crange, const struct gkyl_range *prange); +void gkyl_dg_mul_conf_phase_op_range_cu( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, struct gkyl_array *pout, + const struct gkyl_array *cop, const struct gkyl_array *pop, const struct gkyl_range *crange, + const struct gkyl_range *prange +); -void -gkyl_dg_mul_conf_phase_op_accumulate_range_cu(const struct gkyl_basis *cbasis, - const struct gkyl_basis *pbasis, struct gkyl_array* pout, double a, - const struct gkyl_array* cop, const struct gkyl_array* pop, - const struct gkyl_range *crange, const struct gkyl_range *prange); +void gkyl_dg_mul_conf_phase_op_accumulate_range_cu( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, struct gkyl_array *pout, + double a, const struct gkyl_array *cop, const struct gkyl_array *pop, + const struct gkyl_range *crange, const struct gkyl_range *prange +); -void -gkyl_dg_dot_product_op_cu(const struct gkyl_basis *basis, - struct gkyl_array* out, - const struct gkyl_array* lop, - const struct gkyl_array* rop); +void gkyl_dg_dot_product_op_cu( + const struct gkyl_basis *basis, struct gkyl_array *out, const struct gkyl_array *lop, + const struct gkyl_array *rop +); -void -gkyl_dg_dot_product_op_range_cu(const struct gkyl_basis *basis, - struct gkyl_array* out, - const struct gkyl_array* lop, - const struct gkyl_array* rop, const struct gkyl_range *range); +void gkyl_dg_dot_product_op_range_cu( + const struct gkyl_basis *basis, struct gkyl_array *out, const struct gkyl_array *lop, + const struct gkyl_array *rop, const struct gkyl_range *range +); -void -gkyl_dg_div_op_cu(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop); +void gkyl_dg_div_op_cu( + gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, + int c_lop, const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop +); -void -gkyl_dg_div_op_range_cu(gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_lop, const struct gkyl_array* lop, - int c_rop, const struct gkyl_array* rop, const struct gkyl_range *range); +void gkyl_dg_div_op_range_cu( + gkyl_dg_bin_op_mem *mem, const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, + int c_lop, const struct gkyl_array *lop, int c_rop, const struct gkyl_array *rop, + const struct gkyl_range *range +); -void -gkyl_dg_inv_op_cu(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_iop, const struct gkyl_array* iop); +void gkyl_dg_inv_op_cu( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop +); -void -gkyl_dg_inv_op_range_cu(const struct gkyl_basis *basis, - int c_oop, struct gkyl_array* out, - int c_iop, const struct gkyl_array* iop, const struct gkyl_range *range); +void gkyl_dg_inv_op_range_cu( + const struct gkyl_basis *basis, int c_oop, struct gkyl_array *out, int c_iop, + const struct gkyl_array *iop, const struct gkyl_range *range +); diff --git a/core/zero/gkyl_dg_bin_ops_priv.h b/core/zero/gkyl_dg_bin_ops_priv.h index 04a4a2485c..b29d793f3c 100644 --- a/core/zero/gkyl_dg_bin_ops_priv.h +++ b/core/zero/gkyl_dg_bin_ops_priv.h @@ -24,7 +24,7 @@ enum gkyl_dg_op { GKYL_DG_OP_MEAN, GKYL_DG_OP_MEAN_L2 }; // Memory for use in the bin ops struct gkyl_dg_bin_op_mem { - bool on_gpu; // flag to indicate if we are on GPU + bool on_gpu; // flag to indicate if we are on GPU size_t batch_sz; // number of elements in batch size_t nrows, ncols; // number of rows and colsx struct gkyl_nmat *As, *xs; // data for matrices needed in division @@ -34,432 +34,506 @@ struct gkyl_dg_bin_op_mem { // Function pointer type for multiplication typedef void (*mul_op_t)(const double *f, const double *g, double *fg); typedef void (*mul_accumulate_op_t)(double a, const double *f, const double *g, double *fg); -typedef void (*mul_accumulate_comp_par_op_t)(double a, const double *f, const double *g, double *fg, int linc2); +typedef void (*mul_accumulate_comp_par_op_t)( + double a, const double *f, const double *g, double *fg, int linc2 +); typedef struct gkyl_kern_op_count (*mul_op_count_t)(void); // Function pointer type for setting matrices for division -typedef void (*div_set_op_t)(struct gkyl_mat *A, struct gkyl_mat *rhs, const double *f, const double *g); +typedef void (*div_set_op_t)( + struct gkyl_mat *A, struct gkyl_mat *rhs, const double *f, const double *g +); // Function pointer type for inverting a DG field. typedef void (*inv_op_t)(const double *A, double *A_inv); // for use in kernel tables -typedef struct { mul_op_t kernels[4]; } mul_op_kern_list; -typedef struct { mul_accumulate_op_t kernels[4]; } mul_accumulate_op_kern_list; -typedef struct { mul_accumulate_comp_par_op_t kernels[4]; } mul_accumulate_comp_par_op_kern_list; -typedef struct { mul_op_kern_list list[3]; } cross_mul_op_kern_list; -typedef struct { mul_accumulate_op_kern_list list[3]; } cross_mul_accumulate_op_kern_list; -typedef struct { mul_accumulate_comp_par_op_kern_list list[3]; } cross_mul_accumulate_comp_par_op_kern_list; -typedef struct { mul_op_count_t kernels[4]; } mul_op_count_kern_list; -typedef struct { div_set_op_t kernels[4]; } div_set_op_kern_list; -typedef struct { inv_op_t kernels[4]; } inv_op_kern_list; +typedef struct { + mul_op_t kernels[4]; +} mul_op_kern_list; +typedef struct { + mul_accumulate_op_t kernels[4]; +} mul_accumulate_op_kern_list; +typedef struct { + mul_accumulate_comp_par_op_t kernels[4]; +} mul_accumulate_comp_par_op_kern_list; +typedef struct { + mul_op_kern_list list[3]; +} cross_mul_op_kern_list; +typedef struct { + mul_accumulate_op_kern_list list[3]; +} cross_mul_accumulate_op_kern_list; +typedef struct { + mul_accumulate_comp_par_op_kern_list list[3]; +} cross_mul_accumulate_comp_par_op_kern_list; +typedef struct { + mul_op_count_t kernels[4]; +} mul_op_count_kern_list; +typedef struct { + div_set_op_t kernels[4]; +} div_set_op_kern_list; +typedef struct { + inv_op_t kernels[4]; +} inv_op_kern_list; // Serendipity multiplication kernels -GKYL_CU_D -static const mul_op_kern_list ser_mul_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { binop_mul_1d_ser_p0, binop_mul_1d_ser_p1, binop_mul_1d_ser_p2, binop_mul_1d_ser_p3 }, - { binop_mul_2d_ser_p0, binop_mul_2d_ser_p1, binop_mul_2d_ser_p2, binop_mul_2d_ser_p3 }, - { binop_mul_3d_ser_p0, binop_mul_3d_ser_p1, binop_mul_3d_ser_p2, binop_mul_3d_ser_p3 } +GKYL_CU_D static const mul_op_kern_list ser_mul_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {binop_mul_1d_ser_p0, binop_mul_1d_ser_p1, binop_mul_1d_ser_p2, binop_mul_1d_ser_p3}, + {binop_mul_2d_ser_p0, binop_mul_2d_ser_p1, binop_mul_2d_ser_p2, binop_mul_2d_ser_p3}, + {binop_mul_3d_ser_p0, binop_mul_3d_ser_p1, binop_mul_3d_ser_p2, binop_mul_3d_ser_p3} }; // Tensor multiplication kernels -GKYL_CU_D -static const mul_op_kern_list ten_mul_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { binop_mul_1d_ser_p0, binop_mul_1d_ser_p1, binop_mul_1d_ser_p2, binop_mul_1d_ser_p3 }, - { binop_mul_2d_ser_p0, binop_mul_2d_ser_p1, binop_mul_2d_tensor_p2, NULL }, - { binop_mul_3d_ser_p0, binop_mul_3d_ser_p1, binop_mul_3d_tensor_p2, NULL } +GKYL_CU_D static const mul_op_kern_list ten_mul_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {binop_mul_1d_ser_p0, binop_mul_1d_ser_p1, binop_mul_1d_ser_p2, binop_mul_1d_ser_p3}, + {binop_mul_2d_ser_p0, binop_mul_2d_ser_p1, binop_mul_2d_tensor_p2, NULL}, + {binop_mul_3d_ser_p0, binop_mul_3d_ser_p1, binop_mul_3d_tensor_p2, NULL} }; // Serendipity conf*phase multiplication kernels -GKYL_CU_D -static const cross_mul_op_kern_list ser_cross_mul_list[] = { - // pdim=2 - { .list = {{ NULL, binop_cross_mul_1d_2d_ser_p1, binop_cross_mul_1d_2d_ser_p2, binop_cross_mul_1d_2d_ser_p3 }, - { NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL },} }, +GKYL_CU_D static const cross_mul_op_kern_list ser_cross_mul_list[] = { // pdim=2 + {.list = + {{NULL, binop_cross_mul_1d_2d_ser_p1, binop_cross_mul_1d_2d_ser_p2, + binop_cross_mul_1d_2d_ser_p3}, + {NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}}}, // pdim=3 - { .list = {{ NULL, binop_cross_mul_1d_3d_ser_p1, binop_cross_mul_1d_3d_ser_p2, binop_cross_mul_1d_3d_ser_p3 }, - { NULL, binop_cross_mul_2d_3d_ser_p1, binop_cross_mul_2d_3d_ser_p2, binop_cross_mul_2d_3d_ser_p3 }, - { NULL, NULL, NULL, NULL },} }, + {.list = + {{NULL, binop_cross_mul_1d_3d_ser_p1, binop_cross_mul_1d_3d_ser_p2, + binop_cross_mul_1d_3d_ser_p3}, + {NULL, binop_cross_mul_2d_3d_ser_p1, binop_cross_mul_2d_3d_ser_p2, + binop_cross_mul_2d_3d_ser_p3}, + {NULL, NULL, NULL, NULL}}}, // pdim=4 - { .list = {{ NULL, binop_cross_mul_1d_4d_ser_p1, binop_cross_mul_1d_4d_ser_p2, binop_cross_mul_1d_4d_ser_p3 }, - { NULL, binop_cross_mul_2d_4d_ser_p1, binop_cross_mul_2d_4d_ser_p2, binop_cross_mul_2d_4d_ser_p3 }, - { NULL, binop_cross_mul_3d_4d_ser_p1, binop_cross_mul_3d_4d_ser_p2, binop_cross_mul_3d_4d_ser_p3 },} }, + {.list = + {{NULL, binop_cross_mul_1d_4d_ser_p1, binop_cross_mul_1d_4d_ser_p2, + binop_cross_mul_1d_4d_ser_p3}, + {NULL, binop_cross_mul_2d_4d_ser_p1, binop_cross_mul_2d_4d_ser_p2, + binop_cross_mul_2d_4d_ser_p3}, + {NULL, binop_cross_mul_3d_4d_ser_p1, binop_cross_mul_3d_4d_ser_p2, + binop_cross_mul_3d_4d_ser_p3}}}, // pdim=5 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_2d_5d_ser_p1, binop_cross_mul_2d_5d_ser_p2, NULL }, - { NULL, binop_cross_mul_3d_5d_ser_p1, binop_cross_mul_3d_5d_ser_p2, NULL },} }, + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_2d_5d_ser_p1, binop_cross_mul_2d_5d_ser_p2, NULL}, + {NULL, binop_cross_mul_3d_5d_ser_p1, binop_cross_mul_3d_5d_ser_p2, NULL}}}, // pdim=6 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_3d_6d_ser_p1, NULL, NULL },} }, + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_3d_6d_ser_p1, NULL, NULL}}} }; // Serendipity conf*phase multiplication with accumulation to output kernels -GKYL_CU_D -static const cross_mul_accumulate_op_kern_list ser_cross_mul_accumulate_list[] = { +GKYL_CU_D static const cross_mul_accumulate_op_kern_list ser_cross_mul_accumulate_list[] = { // pdim=2 - { .list = {{ NULL, binop_cross_mul_accumulate_1d_2d_ser_p1, binop_cross_mul_accumulate_1d_2d_ser_p2, binop_cross_mul_accumulate_1d_2d_ser_p3 }, - { NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL },} }, + {.list = + {{NULL, binop_cross_mul_accumulate_1d_2d_ser_p1, binop_cross_mul_accumulate_1d_2d_ser_p2, + binop_cross_mul_accumulate_1d_2d_ser_p3}, + {NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}}}, // pdim=3 - { .list = {{ NULL, binop_cross_mul_accumulate_1d_3d_ser_p1, binop_cross_mul_accumulate_1d_3d_ser_p2, binop_cross_mul_accumulate_1d_3d_ser_p3 }, - { NULL, binop_cross_mul_accumulate_2d_3d_ser_p1, binop_cross_mul_accumulate_2d_3d_ser_p2, binop_cross_mul_accumulate_2d_3d_ser_p3 }, - { NULL, NULL, NULL, NULL },} }, + {.list = + {{NULL, binop_cross_mul_accumulate_1d_3d_ser_p1, binop_cross_mul_accumulate_1d_3d_ser_p2, + binop_cross_mul_accumulate_1d_3d_ser_p3}, + {NULL, binop_cross_mul_accumulate_2d_3d_ser_p1, binop_cross_mul_accumulate_2d_3d_ser_p2, + binop_cross_mul_accumulate_2d_3d_ser_p3}, + {NULL, NULL, NULL, NULL}}}, // pdim=4 - { .list = {{ NULL, binop_cross_mul_accumulate_1d_4d_ser_p1, binop_cross_mul_accumulate_1d_4d_ser_p2, binop_cross_mul_accumulate_1d_4d_ser_p3 }, - { NULL, binop_cross_mul_accumulate_2d_4d_ser_p1, binop_cross_mul_accumulate_2d_4d_ser_p2, binop_cross_mul_accumulate_2d_4d_ser_p3 }, - { NULL, binop_cross_mul_accumulate_3d_4d_ser_p1, binop_cross_mul_accumulate_3d_4d_ser_p2, binop_cross_mul_accumulate_3d_4d_ser_p3 },} }, + {.list = + {{NULL, binop_cross_mul_accumulate_1d_4d_ser_p1, binop_cross_mul_accumulate_1d_4d_ser_p2, + binop_cross_mul_accumulate_1d_4d_ser_p3}, + {NULL, binop_cross_mul_accumulate_2d_4d_ser_p1, binop_cross_mul_accumulate_2d_4d_ser_p2, + binop_cross_mul_accumulate_2d_4d_ser_p3}, + {NULL, binop_cross_mul_accumulate_3d_4d_ser_p1, binop_cross_mul_accumulate_3d_4d_ser_p2, + binop_cross_mul_accumulate_3d_4d_ser_p3}}}, // pdim=5 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_accumulate_2d_5d_ser_p1, binop_cross_mul_accumulate_2d_5d_ser_p2, NULL }, - { NULL, binop_cross_mul_accumulate_3d_5d_ser_p1, binop_cross_mul_accumulate_3d_5d_ser_p2, NULL },} }, + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_accumulate_2d_5d_ser_p1, binop_cross_mul_accumulate_2d_5d_ser_p2, NULL}, + {NULL, binop_cross_mul_accumulate_3d_5d_ser_p1, binop_cross_mul_accumulate_3d_5d_ser_p2, NULL} + }}, // pdim=6 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_accumulate_3d_6d_ser_p1, NULL, NULL },} }, + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_accumulate_3d_6d_ser_p1, NULL, NULL}}} }; // Serendipity conf*phase multiplication with accumulation to output kernels and parallelization over components -GKYL_CU_D -static const cross_mul_accumulate_comp_par_op_kern_list ser_cross_mul_accumulate_comp_par_list[] = { - // pdim=2 - { .list = {{ NULL, binop_cross_mul_accumulate_comp_par_1d_2d_ser_p1, binop_cross_mul_accumulate_comp_par_1d_2d_ser_p2, binop_cross_mul_accumulate_comp_par_1d_2d_ser_p3 }, - { NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL },} }, - // pdim=3 - { .list = {{ NULL, binop_cross_mul_accumulate_comp_par_1d_3d_ser_p1, binop_cross_mul_accumulate_comp_par_1d_3d_ser_p2, binop_cross_mul_accumulate_comp_par_1d_3d_ser_p3 }, - { NULL, binop_cross_mul_accumulate_comp_par_2d_3d_ser_p1, binop_cross_mul_accumulate_comp_par_2d_3d_ser_p2, binop_cross_mul_accumulate_comp_par_2d_3d_ser_p3 }, - { NULL, NULL, NULL, NULL },} }, - // pdim=4 - { .list = {{ NULL, binop_cross_mul_accumulate_comp_par_1d_4d_ser_p1, binop_cross_mul_accumulate_comp_par_1d_4d_ser_p2, binop_cross_mul_accumulate_comp_par_1d_4d_ser_p3 }, - { NULL, binop_cross_mul_accumulate_comp_par_2d_4d_ser_p1, binop_cross_mul_accumulate_comp_par_2d_4d_ser_p2, binop_cross_mul_accumulate_comp_par_2d_4d_ser_p3 }, - { NULL, binop_cross_mul_accumulate_comp_par_3d_4d_ser_p1, binop_cross_mul_accumulate_comp_par_3d_4d_ser_p2, binop_cross_mul_accumulate_comp_par_3d_4d_ser_p3 },} }, - // pdim=5 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_accumulate_comp_par_2d_5d_ser_p1, binop_cross_mul_accumulate_comp_par_2d_5d_ser_p2, NULL }, - { NULL, binop_cross_mul_accumulate_comp_par_3d_5d_ser_p1, binop_cross_mul_accumulate_comp_par_3d_5d_ser_p2, NULL },} }, - // pdim=6 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_accumulate_comp_par_3d_6d_ser_p1, NULL, NULL },} }, +GKYL_CU_D static const cross_mul_accumulate_comp_par_op_kern_list + ser_cross_mul_accumulate_comp_par_list[] = { // pdim=2 + {.list = + {{NULL, binop_cross_mul_accumulate_comp_par_1d_2d_ser_p1, + binop_cross_mul_accumulate_comp_par_1d_2d_ser_p2, + binop_cross_mul_accumulate_comp_par_1d_2d_ser_p3}, + {NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}}}, + // pdim=3 + {.list = + {{NULL, binop_cross_mul_accumulate_comp_par_1d_3d_ser_p1, + binop_cross_mul_accumulate_comp_par_1d_3d_ser_p2, + binop_cross_mul_accumulate_comp_par_1d_3d_ser_p3}, + {NULL, binop_cross_mul_accumulate_comp_par_2d_3d_ser_p1, + binop_cross_mul_accumulate_comp_par_2d_3d_ser_p2, + binop_cross_mul_accumulate_comp_par_2d_3d_ser_p3}, + {NULL, NULL, NULL, NULL}}}, + // pdim=4 + {.list = + {{NULL, binop_cross_mul_accumulate_comp_par_1d_4d_ser_p1, + binop_cross_mul_accumulate_comp_par_1d_4d_ser_p2, + binop_cross_mul_accumulate_comp_par_1d_4d_ser_p3}, + {NULL, binop_cross_mul_accumulate_comp_par_2d_4d_ser_p1, + binop_cross_mul_accumulate_comp_par_2d_4d_ser_p2, + binop_cross_mul_accumulate_comp_par_2d_4d_ser_p3}, + {NULL, binop_cross_mul_accumulate_comp_par_3d_4d_ser_p1, + binop_cross_mul_accumulate_comp_par_3d_4d_ser_p2, + binop_cross_mul_accumulate_comp_par_3d_4d_ser_p3}}}, + // pdim=5 + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_accumulate_comp_par_2d_5d_ser_p1, + binop_cross_mul_accumulate_comp_par_2d_5d_ser_p2, NULL}, + {NULL, binop_cross_mul_accumulate_comp_par_3d_5d_ser_p1, + binop_cross_mul_accumulate_comp_par_3d_5d_ser_p2, NULL}}}, + // pdim=6 + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_accumulate_comp_par_3d_6d_ser_p1, NULL, NULL}}} }; // Tensor conf*phase multiplication kernels -GKYL_CU_D -static const cross_mul_op_kern_list ten_cross_mul_list[] = { - // pdim=2 - { .list = {{ NULL, binop_cross_mul_1d_2d_ser_p1, binop_cross_mul_1d_2d_tensor_p2, NULL }, - { NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL },} }, +GKYL_CU_D static const cross_mul_op_kern_list ten_cross_mul_list[] = { // pdim=2 + {.list = + {{NULL, binop_cross_mul_1d_2d_ser_p1, binop_cross_mul_1d_2d_tensor_p2, NULL}, + {NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}}}, // pdim=3 - { .list = {{ NULL, binop_cross_mul_1d_3d_ser_p1, binop_cross_mul_1d_3d_tensor_p2, NULL }, - { NULL, binop_cross_mul_2d_3d_ser_p1, binop_cross_mul_2d_3d_tensor_p2, NULL }, - { NULL, NULL, NULL, NULL },} }, + {.list = + {{NULL, binop_cross_mul_1d_3d_ser_p1, binop_cross_mul_1d_3d_tensor_p2, NULL}, + {NULL, binop_cross_mul_2d_3d_ser_p1, binop_cross_mul_2d_3d_tensor_p2, NULL}, + {NULL, NULL, NULL, NULL}}}, // pdim=4 - { .list = {{ NULL, binop_cross_mul_1d_4d_ser_p1, binop_cross_mul_1d_4d_tensor_p2, NULL }, - { NULL, binop_cross_mul_2d_4d_ser_p1, binop_cross_mul_2d_4d_tensor_p2, NULL }, - { NULL, binop_cross_mul_3d_4d_ser_p1, NULL, NULL },} }, + {.list = + {{NULL, binop_cross_mul_1d_4d_ser_p1, binop_cross_mul_1d_4d_tensor_p2, NULL}, + {NULL, binop_cross_mul_2d_4d_ser_p1, binop_cross_mul_2d_4d_tensor_p2, NULL}, + {NULL, binop_cross_mul_3d_4d_ser_p1, NULL, NULL}}}, // pdim=5 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_2d_5d_ser_p1, binop_cross_mul_2d_5d_tensor_p2, NULL }, - { NULL, binop_cross_mul_3d_5d_ser_p1, NULL, NULL },} }, + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_2d_5d_ser_p1, binop_cross_mul_2d_5d_tensor_p2, NULL}, + {NULL, binop_cross_mul_3d_5d_ser_p1, NULL, NULL}}}, // pdim=6 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_3d_6d_ser_p1, NULL, NULL },} }, + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_3d_6d_ser_p1, NULL, NULL}}} }; -// Tensor conf*phase multiplication with accumulation to output kernels -GKYL_CU_D -static const cross_mul_accumulate_op_kern_list ten_cross_mul_accumulate_list[] = { +// Tensor conf*phase multiplication with accumulation to output kernels +GKYL_CU_D static const cross_mul_accumulate_op_kern_list ten_cross_mul_accumulate_list[] = { // pdim=2 - { .list = {{ NULL, binop_cross_mul_accumulate_1d_2d_ser_p1, binop_cross_mul_accumulate_1d_2d_tensor_p2, NULL }, - { NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL },} }, + {.list = + {{NULL, binop_cross_mul_accumulate_1d_2d_ser_p1, binop_cross_mul_accumulate_1d_2d_tensor_p2, + NULL}, + {NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}}}, // pdim=3 - { .list = {{ NULL, binop_cross_mul_accumulate_1d_3d_ser_p1, binop_cross_mul_accumulate_1d_3d_tensor_p2, NULL }, - { NULL, binop_cross_mul_accumulate_2d_3d_ser_p1, binop_cross_mul_accumulate_2d_3d_tensor_p2, NULL }, - { NULL, NULL, NULL, NULL },} }, + {.list = + {{NULL, binop_cross_mul_accumulate_1d_3d_ser_p1, binop_cross_mul_accumulate_1d_3d_tensor_p2, + NULL}, + {NULL, binop_cross_mul_accumulate_2d_3d_ser_p1, binop_cross_mul_accumulate_2d_3d_tensor_p2, + NULL}, + {NULL, NULL, NULL, NULL}}}, // pdim=4 - { .list = {{ NULL, binop_cross_mul_accumulate_1d_4d_ser_p1, binop_cross_mul_accumulate_1d_4d_tensor_p2, NULL }, - { NULL, binop_cross_mul_accumulate_2d_4d_ser_p1, binop_cross_mul_accumulate_2d_4d_tensor_p2, NULL }, - { NULL, NULL, NULL, NULL },} }, + {.list = + {{NULL, binop_cross_mul_accumulate_1d_4d_ser_p1, binop_cross_mul_accumulate_1d_4d_tensor_p2, + NULL}, + {NULL, binop_cross_mul_accumulate_2d_4d_ser_p1, binop_cross_mul_accumulate_2d_4d_tensor_p2, + NULL}, + {NULL, NULL, NULL, NULL}}}, // pdim=5 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_accumulate_2d_5d_ser_p1, binop_cross_mul_accumulate_2d_5d_tensor_p2, NULL }, - { NULL, binop_cross_mul_accumulate_3d_5d_ser_p1, NULL, NULL },} }, + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_accumulate_2d_5d_ser_p1, binop_cross_mul_accumulate_2d_5d_tensor_p2, + NULL}, + {NULL, binop_cross_mul_accumulate_3d_5d_ser_p1, NULL, NULL}}}, // pdim=6 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_accumulate_3d_6d_ser_p1, NULL, NULL },} }, + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_accumulate_3d_6d_ser_p1, NULL, NULL}}} }; // Tensor conf*phase multiplication with accumulation to output kernels and parallelization over components -GKYL_CU_D -static const cross_mul_accumulate_comp_par_op_kern_list ten_cross_mul_accumulate_comp_par_list[] = { - // pdim=2 - { .list = {{ NULL, binop_cross_mul_accumulate_comp_par_1d_2d_ser_p1, binop_cross_mul_accumulate_comp_par_1d_2d_tensor_p2, NULL }, - { NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL },} }, - // pdim=3 - { .list = {{ NULL, binop_cross_mul_accumulate_comp_par_1d_3d_ser_p1, binop_cross_mul_accumulate_comp_par_1d_3d_tensor_p2, NULL }, - { NULL, binop_cross_mul_accumulate_comp_par_2d_3d_ser_p1, binop_cross_mul_accumulate_comp_par_2d_3d_tensor_p2, NULL }, - { NULL, NULL, NULL, NULL },} }, - // pdim=4 - { .list = {{ NULL, binop_cross_mul_accumulate_comp_par_1d_4d_ser_p1, binop_cross_mul_accumulate_comp_par_1d_4d_tensor_p2, NULL }, - { NULL, binop_cross_mul_accumulate_comp_par_2d_4d_ser_p1, binop_cross_mul_accumulate_comp_par_2d_4d_tensor_p2, NULL }, - { NULL, NULL, NULL, NULL },} }, - // pdim=5 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_accumulate_comp_par_2d_5d_ser_p1, binop_cross_mul_accumulate_comp_par_2d_5d_tensor_p2, NULL }, - { NULL, binop_cross_mul_accumulate_comp_par_3d_5d_ser_p1, NULL, NULL },} }, - // pdim=6 - { .list = {{ NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL }, - { NULL, binop_cross_mul_accumulate_comp_par_3d_6d_ser_p1, NULL, NULL },} }, +GKYL_CU_D static const cross_mul_accumulate_comp_par_op_kern_list + ten_cross_mul_accumulate_comp_par_list[] = { // pdim=2 + {.list = + {{NULL, binop_cross_mul_accumulate_comp_par_1d_2d_ser_p1, + binop_cross_mul_accumulate_comp_par_1d_2d_tensor_p2, NULL}, + {NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}}}, + // pdim=3 + {.list = + {{NULL, binop_cross_mul_accumulate_comp_par_1d_3d_ser_p1, + binop_cross_mul_accumulate_comp_par_1d_3d_tensor_p2, NULL}, + {NULL, binop_cross_mul_accumulate_comp_par_2d_3d_ser_p1, + binop_cross_mul_accumulate_comp_par_2d_3d_tensor_p2, NULL}, + {NULL, NULL, NULL, NULL}}}, + // pdim=4 + {.list = + {{NULL, binop_cross_mul_accumulate_comp_par_1d_4d_ser_p1, + binop_cross_mul_accumulate_comp_par_1d_4d_tensor_p2, NULL}, + {NULL, binop_cross_mul_accumulate_comp_par_2d_4d_ser_p1, + binop_cross_mul_accumulate_comp_par_2d_4d_tensor_p2, NULL}, + {NULL, NULL, NULL, NULL}}}, + // pdim=5 + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_accumulate_comp_par_2d_5d_ser_p1, + binop_cross_mul_accumulate_comp_par_2d_5d_tensor_p2, NULL}, + {NULL, binop_cross_mul_accumulate_comp_par_3d_5d_ser_p1, NULL, NULL}}}, + // pdim=6 + {.list = + {{NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}, + {NULL, binop_cross_mul_accumulate_comp_par_3d_6d_ser_p1, NULL, NULL}}} }; -// Hybrid basis conf*phase multiplication kernels -GKYL_CU_D -static const mul_op_kern_list hyb_cross_mul_list[] = { - { binop_cross_mul_1x1v_hyb_p1, binop_cross_mul_1x2v_hyb_p1, binop_cross_mul_1x3v_hyb_p1 }, - { binop_cross_mul_2x1v_hyb_p1, binop_cross_mul_2x2v_hyb_p1, binop_cross_mul_2x3v_hyb_p1 }, - { binop_cross_mul_3x1v_hyb_p1, binop_cross_mul_3x2v_hyb_p1, binop_cross_mul_3x3v_hyb_p1 }, +// Hybrid basis conf*phase multiplication kernels +GKYL_CU_D static const mul_op_kern_list hyb_cross_mul_list[] = { + {binop_cross_mul_1x1v_hyb_p1, binop_cross_mul_1x2v_hyb_p1, binop_cross_mul_1x3v_hyb_p1}, + {binop_cross_mul_2x1v_hyb_p1, binop_cross_mul_2x2v_hyb_p1, binop_cross_mul_2x3v_hyb_p1}, + {binop_cross_mul_3x1v_hyb_p1, binop_cross_mul_3x2v_hyb_p1, binop_cross_mul_3x3v_hyb_p1} }; -// Hybrid basis conf*phase multiplication with accumulation to output kernels -GKYL_CU_D -static const mul_accumulate_op_kern_list hyb_cross_mul_accumulate_list[] = { - { binop_cross_mul_accumulate_1x1v_hyb_p1, binop_cross_mul_accumulate_1x2v_hyb_p1, binop_cross_mul_accumulate_1x3v_hyb_p1 }, - { binop_cross_mul_accumulate_2x1v_hyb_p1, binop_cross_mul_accumulate_2x2v_hyb_p1, binop_cross_mul_accumulate_2x3v_hyb_p1 }, - { binop_cross_mul_accumulate_3x1v_hyb_p1, binop_cross_mul_accumulate_3x2v_hyb_p1, binop_cross_mul_accumulate_3x3v_hyb_p1 }, +// Hybrid basis conf*phase multiplication with accumulation to output kernels +GKYL_CU_D static const mul_accumulate_op_kern_list hyb_cross_mul_accumulate_list[] = { + {binop_cross_mul_accumulate_1x1v_hyb_p1, binop_cross_mul_accumulate_1x2v_hyb_p1, + binop_cross_mul_accumulate_1x3v_hyb_p1}, + {binop_cross_mul_accumulate_2x1v_hyb_p1, binop_cross_mul_accumulate_2x2v_hyb_p1, + binop_cross_mul_accumulate_2x3v_hyb_p1}, + {binop_cross_mul_accumulate_3x1v_hyb_p1, binop_cross_mul_accumulate_3x2v_hyb_p1, + binop_cross_mul_accumulate_3x3v_hyb_p1} }; // Hybrid basis conf*phase multiplication with accumulation to output kernels and parallelization over components -GKYL_CU_D -static const mul_accumulate_comp_par_op_kern_list hyb_cross_mul_accumulate_comp_par_list[] = { - { binop_cross_mul_accumulate_comp_par_1x1v_hyb_p1, binop_cross_mul_accumulate_comp_par_1x2v_hyb_p1, binop_cross_mul_accumulate_comp_par_1x3v_hyb_p1 }, - { binop_cross_mul_accumulate_comp_par_2x1v_hyb_p1, binop_cross_mul_accumulate_comp_par_2x2v_hyb_p1, binop_cross_mul_accumulate_comp_par_2x3v_hyb_p1 }, - { binop_cross_mul_accumulate_comp_par_3x1v_hyb_p1, binop_cross_mul_accumulate_comp_par_3x2v_hyb_p1, binop_cross_mul_accumulate_comp_par_3x3v_hyb_p1 }, +GKYL_CU_D static const mul_accumulate_comp_par_op_kern_list + hyb_cross_mul_accumulate_comp_par_list[] = { + {binop_cross_mul_accumulate_comp_par_1x1v_hyb_p1, + binop_cross_mul_accumulate_comp_par_1x2v_hyb_p1, + binop_cross_mul_accumulate_comp_par_1x3v_hyb_p1}, + {binop_cross_mul_accumulate_comp_par_2x1v_hyb_p1, + binop_cross_mul_accumulate_comp_par_2x2v_hyb_p1, + binop_cross_mul_accumulate_comp_par_2x3v_hyb_p1}, + {binop_cross_mul_accumulate_comp_par_3x1v_hyb_p1, + binop_cross_mul_accumulate_comp_par_3x2v_hyb_p1, + binop_cross_mul_accumulate_comp_par_3x3v_hyb_p1} }; -// GK hybrid basis conf*phase multiplication kernels -GKYL_CU_D -static const mul_op_kern_list gkhyb_cross_mul_list[] = { - { binop_cross_mul_1x1v_gkhyb_p1, binop_cross_mul_1x2v_gkhyb_p1 }, - { NULL, binop_cross_mul_2x2v_gkhyb_p1 }, - { NULL, binop_cross_mul_3x2v_gkhyb_p1 }, +// GK hybrid basis conf*phase multiplication kernels +GKYL_CU_D static const mul_op_kern_list gkhyb_cross_mul_list[] = { + {binop_cross_mul_1x1v_gkhyb_p1, binop_cross_mul_1x2v_gkhyb_p1}, + {NULL, binop_cross_mul_2x2v_gkhyb_p1}, + {NULL, binop_cross_mul_3x2v_gkhyb_p1} }; -// GK hybrid basis conf*phase multiplication with accumulation to output kernels -GKYL_CU_D -static const mul_accumulate_op_kern_list gkhyb_cross_mul_accumulate_list[] = { - { binop_cross_mul_accumulate_1x1v_gkhyb_p1, binop_cross_mul_accumulate_1x2v_gkhyb_p1 }, - { NULL, binop_cross_mul_accumulate_2x2v_gkhyb_p1 }, - { NULL, binop_cross_mul_accumulate_3x2v_gkhyb_p1 }, +// GK hybrid basis conf*phase multiplication with accumulation to output kernels +GKYL_CU_D static const mul_accumulate_op_kern_list gkhyb_cross_mul_accumulate_list[] = { + {binop_cross_mul_accumulate_1x1v_gkhyb_p1, binop_cross_mul_accumulate_1x2v_gkhyb_p1}, + {NULL, binop_cross_mul_accumulate_2x2v_gkhyb_p1}, + {NULL, binop_cross_mul_accumulate_3x2v_gkhyb_p1} }; // GK hybrid basis conf*phase multiplication with accumulation to output kernels and parallelization over components -GKYL_CU_D -static const mul_accumulate_comp_par_op_kern_list gkhyb_cross_mul_accumulate_comp_par_list[] = { - { binop_cross_mul_accumulate_comp_par_1x1v_gkhyb_p1, binop_cross_mul_accumulate_comp_par_1x2v_gkhyb_p1 }, - { NULL, binop_cross_mul_accumulate_comp_par_2x2v_gkhyb_p1 }, - { NULL, binop_cross_mul_accumulate_comp_par_3x2v_gkhyb_p1 }, +GKYL_CU_D static const mul_accumulate_comp_par_op_kern_list + gkhyb_cross_mul_accumulate_comp_par_list[] = { + {binop_cross_mul_accumulate_comp_par_1x1v_gkhyb_p1, + binop_cross_mul_accumulate_comp_par_1x2v_gkhyb_p1}, + {NULL, binop_cross_mul_accumulate_comp_par_2x2v_gkhyb_p1}, + {NULL, binop_cross_mul_accumulate_comp_par_3x2v_gkhyb_p1} }; static const mul_op_count_kern_list ser_mul_op_count_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { op_count_binop_mul_1d_ser_p0, op_count_binop_mul_1d_ser_p1, op_count_binop_mul_1d_ser_p2, op_count_binop_mul_1d_ser_p3 }, - { op_count_binop_mul_2d_ser_p0, op_count_binop_mul_2d_ser_p1, op_count_binop_mul_2d_ser_p2, op_count_binop_mul_2d_ser_p3 }, - { op_count_binop_mul_3d_ser_p0, op_count_binop_mul_3d_ser_p1, op_count_binop_mul_3d_ser_p2, op_count_binop_mul_3d_ser_p3 } + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {op_count_binop_mul_1d_ser_p0, op_count_binop_mul_1d_ser_p1, op_count_binop_mul_1d_ser_p2, + op_count_binop_mul_1d_ser_p3}, + {op_count_binop_mul_2d_ser_p0, op_count_binop_mul_2d_ser_p1, op_count_binop_mul_2d_ser_p2, + op_count_binop_mul_2d_ser_p3}, + {op_count_binop_mul_3d_ser_p0, op_count_binop_mul_3d_ser_p1, op_count_binop_mul_3d_ser_p2, + op_count_binop_mul_3d_ser_p3} }; // Serendipity division kernels -GKYL_CU_D -static const div_set_op_kern_list ser_div_set_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { binop_div_set_1d_ser_p0, binop_div_set_1d_ser_p1, binop_div_set_1d_ser_p2, binop_div_set_1d_ser_p3 }, - { binop_div_set_2d_ser_p0, binop_div_set_2d_ser_p1, binop_div_set_2d_ser_p2, binop_div_set_2d_ser_p3 }, - { binop_div_set_3d_ser_p0, binop_div_set_3d_ser_p1, binop_div_set_3d_ser_p2, binop_div_set_3d_ser_p3 } +GKYL_CU_D static const div_set_op_kern_list ser_div_set_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {binop_div_set_1d_ser_p0, binop_div_set_1d_ser_p1, binop_div_set_1d_ser_p2, + binop_div_set_1d_ser_p3}, + {binop_div_set_2d_ser_p0, binop_div_set_2d_ser_p1, binop_div_set_2d_ser_p2, + binop_div_set_2d_ser_p3}, + {binop_div_set_3d_ser_p0, binop_div_set_3d_ser_p1, binop_div_set_3d_ser_p2, + binop_div_set_3d_ser_p3} }; // Tensor division kernels -GKYL_CU_D -static const div_set_op_kern_list ten_div_set_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { binop_div_set_1d_ser_p0, binop_div_set_1d_ser_p1, binop_div_set_1d_ser_p2, binop_div_set_1d_ser_p3 }, - { binop_div_set_2d_ser_p0, binop_div_set_2d_ser_p1, binop_div_set_2d_tensor_p2, NULL }, - { binop_div_set_3d_ser_p0, binop_div_set_3d_ser_p1, binop_div_set_3d_tensor_p2, NULL } +GKYL_CU_D static const div_set_op_kern_list ten_div_set_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {binop_div_set_1d_ser_p0, binop_div_set_1d_ser_p1, binop_div_set_1d_ser_p2, + binop_div_set_1d_ser_p3}, + {binop_div_set_2d_ser_p0, binop_div_set_2d_ser_p1, binop_div_set_2d_tensor_p2, NULL}, + {binop_div_set_3d_ser_p0, binop_div_set_3d_ser_p1, binop_div_set_3d_tensor_p2, NULL} }; // Serendipity inv kernels -GKYL_CU_D -static const inv_op_kern_list ser_inv_list[] = { - { NULL, NULL, NULL, NULL }, // No 0D basis functions - { NULL, ser_1x_p1_inv, NULL, NULL }, - { NULL, ser_2x_p1_inv, NULL, NULL }, - { NULL, ser_3x_p1_inv, NULL, NULL } +GKYL_CU_D static const inv_op_kern_list ser_inv_list[] = { + {NULL, NULL, NULL, NULL}, // No 0D basis functions + {NULL, ser_1x_p1_inv, NULL, NULL}, + {NULL, ser_2x_p1_inv, NULL, NULL}, + {NULL, ser_3x_p1_inv, NULL, NULL} }; -GKYL_CU_D -static mul_op_t -choose_ser_mul_kern(int dim, int poly_order) +GKYL_CU_D static mul_op_t choose_ser_mul_kern(int dim, int poly_order) { assert(dim < 4); return ser_mul_list[dim].kernels[poly_order]; } -GKYL_CU_D -static mul_op_t -choose_ten_mul_kern(int dim, int poly_order) +GKYL_CU_D static mul_op_t choose_ten_mul_kern(int dim, int poly_order) { assert(dim < 4); return ten_mul_list[dim].kernels[poly_order]; } -GKYL_CU_D -static mul_op_t +GKYL_CU_D static mul_op_t choose_mul_conf_phase_kern(enum gkyl_basis_type btype, int cdim, int vdim, int poly_order) { - int pdim = cdim+vdim; - + int pdim = cdim + vdim; + switch (btype) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_cross_mul_list[pdim-2].list[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_HYBRID: - return hyb_cross_mul_list[cdim-1].kernels[vdim-1]; - break; - case GKYL_BASIS_MODAL_GKHYBRID: - return gkhyb_cross_mul_list[cdim-1].kernels[vdim-1]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_cross_mul_list[pdim-2].list[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_cross_mul_list[pdim - 2].list[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_HYBRID: + return hyb_cross_mul_list[cdim - 1].kernels[vdim - 1]; + break; + case GKYL_BASIS_MODAL_GKHYBRID: + return gkhyb_cross_mul_list[cdim - 1].kernels[vdim - 1]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_cross_mul_list[pdim - 2].list[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static mul_accumulate_op_t +GKYL_CU_D static mul_accumulate_op_t choose_mul_conf_phase_accumulate_kern(enum gkyl_basis_type btype, int cdim, int vdim, int poly_order) { - int pdim = cdim+vdim; - + int pdim = cdim + vdim; + switch (btype) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_cross_mul_accumulate_list[pdim-2].list[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_HYBRID: - return hyb_cross_mul_accumulate_list[cdim-1].kernels[vdim-1]; - break; - case GKYL_BASIS_MODAL_GKHYBRID: - return gkhyb_cross_mul_accumulate_list[cdim-1].kernels[vdim-1]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_cross_mul_accumulate_list[pdim-2].list[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_cross_mul_accumulate_list[pdim - 2].list[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_HYBRID: + return hyb_cross_mul_accumulate_list[cdim - 1].kernels[vdim - 1]; + break; + case GKYL_BASIS_MODAL_GKHYBRID: + return gkhyb_cross_mul_accumulate_list[cdim - 1].kernels[vdim - 1]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_cross_mul_accumulate_list[pdim - 2].list[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static mul_accumulate_comp_par_op_t -choose_mul_conf_phase_accumulate_comp_par_kern(enum gkyl_basis_type btype, int cdim, int vdim, int poly_order) +GKYL_CU_D static mul_accumulate_comp_par_op_t choose_mul_conf_phase_accumulate_comp_par_kern( + enum gkyl_basis_type btype, int cdim, int vdim, int poly_order +) { - int pdim = cdim+vdim; - + int pdim = cdim + vdim; + switch (btype) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_cross_mul_accumulate_comp_par_list[pdim-2].list[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_HYBRID: - return hyb_cross_mul_accumulate_comp_par_list[cdim-1].kernels[vdim-1]; - break; - case GKYL_BASIS_MODAL_GKHYBRID: - return gkhyb_cross_mul_accumulate_comp_par_list[cdim-1].kernels[vdim-1]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_cross_mul_accumulate_comp_par_list[pdim-2].list[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_cross_mul_accumulate_comp_par_list[pdim - 2].list[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_HYBRID: + return hyb_cross_mul_accumulate_comp_par_list[cdim - 1].kernels[vdim - 1]; + break; + case GKYL_BASIS_MODAL_GKHYBRID: + return gkhyb_cross_mul_accumulate_comp_par_list[cdim - 1].kernels[vdim - 1]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_cross_mul_accumulate_comp_par_list[pdim - 2].list[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } return 0; } -static mul_op_count_t -choose_ser_mul_op_count_kern(int dim, int poly_order) +static mul_op_count_t choose_ser_mul_op_count_kern(int dim, int poly_order) { return ser_mul_op_count_list[dim].kernels[poly_order]; } -GKYL_CU_D -static div_set_op_t -choose_ser_div_set_kern(int dim, int poly_order) +GKYL_CU_D static div_set_op_t choose_ser_div_set_kern(int dim, int poly_order) { return ser_div_set_list[dim].kernels[poly_order]; } -GKYL_CU_D -static div_set_op_t -choose_ten_div_set_kern(int dim, int poly_order) +GKYL_CU_D static div_set_op_t choose_ten_div_set_kern(int dim, int poly_order) { return ten_div_set_list[dim].kernels[poly_order]; } -GKYL_CU_D -static inv_op_t -choose_ser_inv_kern(int dim, int poly_order) +GKYL_CU_D static inv_op_t choose_ser_inv_kern(int dim, int poly_order) { return ser_inv_list[dim].kernels[poly_order]; } -GKYL_CU_D -static inline double -dg_cell_mean(int nc, const double *f) +GKYL_CU_D static inline double dg_cell_mean(int nc, const double *f) { return f[0]; } -GKYL_CU_D -static inline double -dg_cell_mean_l2(int nb, const double *f) +GKYL_CU_D static inline double dg_cell_mean_l2(int nb, const double *f) { double sum = 0.0; - for (int i=0; i= 1 && ndim <= 3); assert(dir >= 0 && dir < ndim); assert(diff_order >= 1 && diff_order <= 2); - return ser_differentiate_list[ndim-1][dir][diff_order-1].kernels[poly_order-1]; + return ser_differentiate_list[ndim - 1][dir][diff_order - 1].kernels[poly_order - 1]; } -GKYL_CU_D -static differentiate_op_t +GKYL_CU_D static differentiate_op_t choose_ten_differentiate_kern(int ndim, int dir, int poly_order, int diff_order) { assert(ndim >= 1 && ndim <= 3); assert(dir >= 0 && dir < ndim); assert(diff_order >= 1 && diff_order <= 2); - return ten_differentiate_list[ndim-1][dir][diff_order-1].kernels[poly_order-1]; + return ten_differentiate_list[ndim - 1][dir][diff_order - 1].kernels[poly_order - 1]; } /** * Host-side wrappers for GPU implementations. */ -void gkyl_dg_differentiate_op_local_cu(const struct gkyl_basis *basis, int dir, int diff_order, - double dx, int c_oop, struct gkyl_array *out, int c_iop, const struct gkyl_array *inp); +void gkyl_dg_differentiate_op_local_cu( + const struct gkyl_basis *basis, int dir, int diff_order, double dx, int c_oop, + struct gkyl_array *out, int c_iop, const struct gkyl_array *inp +); -void gkyl_dg_differentiate_op_local_range_cu(const struct gkyl_basis *basis, int dir, int diff_order, - double dx, int c_oop, struct gkyl_array *out, int c_iop, const struct gkyl_array *inp, - const struct gkyl_range *range); +void gkyl_dg_differentiate_op_local_range_cu( + const struct gkyl_basis *basis, int dir, int diff_order, double dx, int c_oop, + struct gkyl_array *out, int c_iop, const struct gkyl_array *inp, const struct gkyl_range *range +); diff --git a/core/zero/gkyl_dg_eval_at_coord_proj.h b/core/zero/gkyl_dg_eval_at_coord_proj.h index 63f6b84272..6f6c547b56 100644 --- a/core/zero/gkyl_dg_eval_at_coord_proj.h +++ b/core/zero/gkyl_dg_eval_at_coord_proj.h @@ -27,9 +27,10 @@ typedef struct gkyl_dg_eval_at_coord_proj gkyl_dg_eval_at_coord_proj; * @param use_gpu Whether to run on GPU. * @return New updater object. */ -struct gkyl_dg_eval_at_coord_proj* -gkyl_dg_eval_at_coord_proj_new(int cdim_do, const struct gkyl_basis *basis_do, - int num_eval_dirs, const int *eval_dirs, bool use_gpu); +struct gkyl_dg_eval_at_coord_proj *gkyl_dg_eval_at_coord_proj_new( + int cdim_do, const struct gkyl_basis *basis_do, int num_eval_dirs, const int *eval_dirs, + bool use_gpu +); /** * Apply the dg_eval_at_coord operator. @@ -45,10 +46,12 @@ gkyl_dg_eval_at_coord_proj_new(int cdim_do, const struct gkyl_basis *basis_do, * @param ncomp Number of scalar DG fields packed in fdo/ftar. * @param ftar Target DG field (written by this call). */ -void gkyl_dg_eval_at_coord_proj_advance(struct gkyl_dg_eval_at_coord_proj *up, const double *eval_coords, +void gkyl_dg_eval_at_coord_proj_advance( + struct gkyl_dg_eval_at_coord_proj *up, const double *eval_coords, const struct gkyl_rect_grid *grid, const bool *pick_lower, const int *known_index, - const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, - const struct gkyl_array *fdo, struct gkyl_array *ftar); + const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, const struct gkyl_array *fdo, + struct gkyl_array *ftar +); /** * Return the properties of the target basis. @@ -60,9 +63,10 @@ void gkyl_dg_eval_at_coord_proj_advance(struct gkyl_dg_eval_at_coord_proj *up, c * @param poly_order Polynomial order. * @param num_basis Number of basis functions. */ -void -gkyl_dg_eval_at_coord_proj_target_basis(struct gkyl_dg_eval_at_coord_proj *up, - int *cdim, int *ndim, enum gkyl_basis_type *btype, int *poly_order, int *num_basis); +void gkyl_dg_eval_at_coord_proj_target_basis( + struct gkyl_dg_eval_at_coord_proj *up, int *cdim, int *ndim, enum gkyl_basis_type *btype, + int *poly_order, int *num_basis +); /** * Release the memory associated with this updater. diff --git a/core/zero/gkyl_dg_eval_at_coord_proj_priv.h b/core/zero/gkyl_dg_eval_at_coord_proj_priv.h index 0f1de3f1e5..55f29922d2 100644 --- a/core/zero/gkyl_dg_eval_at_coord_proj_priv.h +++ b/core/zero/gkyl_dg_eval_at_coord_proj_priv.h @@ -13,20 +13,32 @@ typedef void (*eval_at_coord_t)(const double *coords, const double *fdo, double *ftar); // Function pointer type for kernels returning target basis. -typedef void (*basis_tar_t)(int *cdim, int *ndim, enum gkyl_basis_type *btype, int *poly_order, int *num_basis); +typedef void (*basis_tar_t)( + int *cdim, int *ndim, enum gkyl_basis_type *btype, int *poly_order, int *num_basis +); // For use in kernel tables. -typedef struct { eval_at_coord_t kernels[3]; } eval_at_coord_kern_list; -typedef struct { basis_tar_t kernels[3]; } basis_tar_kern_list; +typedef struct { + eval_at_coord_t kernels[3]; +} eval_at_coord_kern_list; +typedef struct { + basis_tar_t kernels[3]; +} basis_tar_kern_list; // Struct with double array for passing coordinates to CUDA kernels. -typedef struct { double c[GKYL_MAX_DIM]; } dg_evproj_struct_double_t; +typedef struct { + double c[GKYL_MAX_DIM]; +} dg_evproj_struct_double_t; // Struct with int array for passing cell index to CUDA kernels. -typedef struct { int c[GKYL_MAX_DIM]; } dg_evproj_struct_int_t; +typedef struct { + int c[GKYL_MAX_DIM]; +} dg_evproj_struct_int_t; // Struct with bool array for passing is_dir_eval to CUDA kernels. -typedef struct { bool c[GKYL_MAX_DIM]; } dg_evproj_struct_bool_t; +typedef struct { + bool c[GKYL_MAX_DIM]; +} dg_evproj_struct_bool_t; // Serendipity kernels. // Indexed as [ndim_do-1][dir_bitmask-1].kernels[poly_order-1] @@ -36,515 +48,496 @@ typedef struct { bool c[GKYL_MAX_DIM]; } dg_evproj_struct_bool_t; // ndim_do = 4 -> index 3 (15 combos) // ndim_do = 5 -> index 4 (31 combos) // ndim_do = 6 -> index 5 (63 combos) -GKYL_CU_D -static const eval_at_coord_kern_list ser_eval_at_coord_list[6][63] = { - // ndim_do = 1. - { - { gkyl_dg_eval_at_coord_proj_1x_ser_p1_eval_dirs_0, gkyl_dg_eval_at_coord_proj_1x_ser_p2_eval_dirs_0, NULL }, - }, +GKYL_CU_D static const eval_at_coord_kern_list ser_eval_at_coord_list[6][63] = { // ndim_do = 1. + {{gkyl_dg_eval_at_coord_proj_1x_ser_p1_eval_dirs_0, + gkyl_dg_eval_at_coord_proj_1x_ser_p2_eval_dirs_0, NULL}}, // ndim_do = 2. - { - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_0 , gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_0 , NULL }, - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_1 , gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_1 , NULL }, - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_01, gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_01, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_0, + gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_0, NULL}, + {gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_1, + gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_1, NULL}, + {gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_01, + gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_01, NULL}}, // ndim_do = 3. - { - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_0 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_1 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_01 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_2 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_02 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_12 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_012, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_0, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_1, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_01, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_2, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_02, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_12, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_012, NULL, NULL}}, // ndim_do = 4. - { - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_0 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_0 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_1 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_1 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_01 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_01 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_2 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_2 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_02 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_02 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_12 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_12 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_012 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_012 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_3 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_3 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_03 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_03 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_13 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_13 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_013 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_013 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_23 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_23 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_023 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_023 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_123 , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_123 , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_0123, gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_0123, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_0, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_0, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_1, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_1, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_01, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_01, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_2, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_2, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_02, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_02, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_12, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_12, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_012, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_012, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_3, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_3, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_03, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_03, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_13, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_13, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_013, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_013, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_23, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_23, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_023, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_023, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_123, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_123, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_0123, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_0123, NULL}}, // ndim_do = 5. - { - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_1 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_01 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_2 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_02 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_12 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_012 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_3 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_03 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_13 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_013 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_23 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_023 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_123 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0123 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_4 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_04 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_14 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_014 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_24 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_024 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_124 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0124 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_34 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_034 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_134 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0134 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_234 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0234 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_1234 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_01234, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_1, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_01, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_2, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_02, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_12, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_012, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_3, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_03, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_13, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_013, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_23, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_023, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_123, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0123, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_4, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_04, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_14, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_014, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_24, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_024, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_124, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0124, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_34, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_034, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_134, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0134, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_234, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0234, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_1234, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_01234, NULL, NULL}}, // ndim_do = 6. - { - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_2 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_02 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_12 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_012 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_3 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_03 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_13 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_013 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_23 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_023 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_123 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0123 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_4 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_04 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_14 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_014 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_24 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_024 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_124 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0124 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_34 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_034 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_134 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0134 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_234 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0234 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1234 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01234 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_5 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_05 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_15 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_015 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_25 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_025 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_125 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0125 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_35 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_035 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_135 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0135 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_235 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0235 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1235 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01235 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_45 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_045 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_145 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0145 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_245 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0245 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1245 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01245 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_345 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0345 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1345 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01345 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_2345 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_02345 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_12345 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_012345, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_2, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_02, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_12, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_012, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_3, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_03, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_13, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_013, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_23, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_023, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_123, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0123, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_4, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_04, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_14, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_014, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_24, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_024, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_124, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0124, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_34, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_034, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_134, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0134, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_234, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0234, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1234, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01234, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_5, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_05, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_15, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_015, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_25, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_025, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_125, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0125, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_35, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_035, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_135, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0135, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_235, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0235, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1235, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01235, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_45, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_045, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_145, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0145, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_245, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0245, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1245, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01245, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_345, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0345, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1345, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01345, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_2345, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_02345, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_12345, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_012345, NULL, NULL}} }; -GKYL_CU_D -static const basis_tar_kern_list ser_basis_tar_list[6][63] = { - // ndim_do = 1. - { - { gkyl_dg_eval_at_coord_proj_1x_ser_p1_eval_dirs_0_target_basis, gkyl_dg_eval_at_coord_proj_1x_ser_p2_eval_dirs_0_target_basis, NULL }, - }, +GKYL_CU_D static const basis_tar_kern_list ser_basis_tar_list[6][63] = { // ndim_do = 1. + {{gkyl_dg_eval_at_coord_proj_1x_ser_p1_eval_dirs_0_target_basis, + gkyl_dg_eval_at_coord_proj_1x_ser_p2_eval_dirs_0_target_basis, NULL}}, // ndim_do = 2. - { - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_0_target_basis , gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_0_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_1_target_basis , gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_1_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_01_target_basis, gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_01_target_basis, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_0_target_basis, + gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_0_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_1_target_basis, + gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_1_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_01_target_basis, + gkyl_dg_eval_at_coord_proj_2x_ser_p2_eval_dirs_01_target_basis, NULL}}, // ndim_do = 3. - { - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_0_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_1_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_01_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_2_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_02_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_12_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_012_target_basis, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_0_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_1_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_01_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_2_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_02_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_12_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_012_target_basis, NULL, NULL}}, // ndim_do = 4. - { - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_0_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_0_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_1_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_1_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_01_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_01_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_2_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_2_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_02_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_02_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_12_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_12_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_012_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_012_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_3_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_3_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_03_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_03_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_13_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_13_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_013_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_013_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_23_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_23_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_023_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_023_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_123_target_basis , gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_123_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_0123_target_basis, gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_0123_target_basis, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_0_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_0_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_1_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_1_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_01_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_01_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_2_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_2_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_02_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_02_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_12_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_12_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_012_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_012_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_3_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_3_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_03_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_03_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_13_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_13_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_013_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_013_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_23_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_23_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_023_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_023_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_123_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_123_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_4x_ser_p1_eval_dirs_0123_target_basis, + gkyl_dg_eval_at_coord_proj_4x_ser_p2_eval_dirs_0123_target_basis, NULL}}, // ndim_do = 5. - { - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_1_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_01_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_2_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_02_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_12_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_012_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_3_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_03_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_13_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_013_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_23_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_023_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_123_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0123_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_4_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_04_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_14_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_014_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_24_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_024_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_124_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0124_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_34_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_034_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_134_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0134_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_234_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0234_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_1234_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_01234_target_basis, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_1_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_01_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_2_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_02_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_12_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_012_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_3_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_03_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_13_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_013_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_23_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_023_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_123_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0123_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_4_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_04_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_14_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_014_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_24_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_024_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_124_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0124_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_34_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_034_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_134_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0134_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_234_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_0234_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_1234_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_5x_ser_p1_eval_dirs_01234_target_basis, NULL, NULL}}, // ndim_do = 6. - { - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_2_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_02_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_12_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_012_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_3_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_03_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_13_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_013_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_23_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_023_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_123_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0123_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_4_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_04_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_14_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_014_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_24_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_024_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_124_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0124_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_34_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_034_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_134_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0134_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_234_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0234_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1234_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01234_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_5_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_05_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_15_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_015_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_25_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_025_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_125_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0125_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_35_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_035_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_135_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0135_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_235_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0235_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1235_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01235_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_45_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_045_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_145_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0145_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_245_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0245_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1245_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01245_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_345_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0345_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1345_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01345_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_2345_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_02345_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_12345_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_012345_target_basis, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_2_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_02_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_12_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_012_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_3_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_03_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_13_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_013_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_23_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_023_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_123_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0123_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_4_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_04_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_14_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_014_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_24_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_024_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_124_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0124_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_34_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_034_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_134_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0134_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_234_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0234_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1234_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01234_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_5_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_05_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_15_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_015_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_25_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_025_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_125_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0125_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_35_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_035_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_135_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0135_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_235_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0235_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1235_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01235_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_45_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_045_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_145_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0145_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_245_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0245_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1245_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01245_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_345_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_0345_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_1345_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_01345_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_2345_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_02345_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_12345_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_6x_ser_p1_eval_dirs_012345_target_basis, NULL, NULL}} }; // Tensor kernels. -GKYL_CU_D -static const eval_at_coord_kern_list ten_eval_at_coord_list[3][7] = { - // ndim_do = 1. - { - { gkyl_dg_eval_at_coord_proj_1x_ser_p1_eval_dirs_0, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - }, +GKYL_CU_D static const eval_at_coord_kern_list ten_eval_at_coord_list[3][7] = { // ndim_do = 1. + {{gkyl_dg_eval_at_coord_proj_1x_ser_p1_eval_dirs_0, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}}, // ndim_do = 2. - { - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_0 , gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_0 , NULL }, - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_1 , gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_1 , NULL }, - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_01, gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_01, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_0, + gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_0, NULL}, + {gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_1, + gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_1, NULL}, + {gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_01, + gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_01, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}}, // ndim_do = 3. - { - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_0 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_1 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_01 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_2 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_02 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_12 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_012, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_0, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_1, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_01, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_2, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_02, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_12, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_012, NULL, NULL}} }; -GKYL_CU_D -static const basis_tar_kern_list ten_basis_tar_list[3][7] = { - // ndim_do = 1. - { - { gkyl_dg_eval_at_coord_proj_1x_ser_p1_eval_dirs_0_target_basis, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - }, +GKYL_CU_D static const basis_tar_kern_list ten_basis_tar_list[3][7] = { // ndim_do = 1. + {{gkyl_dg_eval_at_coord_proj_1x_ser_p1_eval_dirs_0_target_basis, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}}, // ndim_do = 2. - { - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_0_target_basis , gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_0_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_1_target_basis , gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_1_target_basis , NULL }, - { gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_01_target_basis, gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_01_target_basis, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_0_target_basis, + gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_0_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_1_target_basis, + gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_1_target_basis, NULL}, + {gkyl_dg_eval_at_coord_proj_2x_ser_p1_eval_dirs_01_target_basis, + gkyl_dg_eval_at_coord_proj_2x_tensor_p2_eval_dirs_01_target_basis, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}}, // ndim_do = 3. - { - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_0_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_1_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_01_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_2_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_02_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_12_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_012_target_basis, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_0_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_1_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_01_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_2_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_02_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_12_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x_ser_p1_eval_dirs_012_target_basis, NULL, NULL}} }; // GK-hybrid kernels. -GKYL_CU_D -static const eval_at_coord_kern_list gkhyb_eval_at_coord_list[4][31] = { - // 1x1v. - { - { gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_0 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_1 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_01, NULL, NULL }, - }, +GKYL_CU_D static const eval_at_coord_kern_list gkhyb_eval_at_coord_list[4][31] = { // 1x1v. + {{gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_0, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_1, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_01, NULL, NULL}}, // 1x2v. - { - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_0 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_1 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_01 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_2 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_02 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_12 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_012, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_0, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_1, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_01, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_2, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_02, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_12, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_012, NULL, NULL}}, // 2x2v. - { - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_0 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_1 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_01 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_2 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_02 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_12 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_012 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_3 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_03 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_13 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_013 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_23 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_023 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_123 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_0123, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_0, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_1, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_01, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_2, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_02, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_12, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_012, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_3, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_03, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_13, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_013, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_23, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_023, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_123, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_0123, NULL, NULL}}, // 3x2v. - { - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_1 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_01 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_2 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_02 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_12 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_012 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_3 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_03 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_13 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_013 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_23 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_023 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_123 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0123 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_4 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_04 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_14 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_014 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_24 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_024 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_124 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0124 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_34 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_034 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_134 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0134 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_234 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0234 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_1234 , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_01234, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_1, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_01, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_2, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_02, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_12, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_012, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_3, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_03, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_13, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_013, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_23, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_023, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_123, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0123, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_4, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_04, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_14, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_014, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_24, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_024, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_124, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0124, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_34, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_034, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_134, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0134, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_234, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0234, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_1234, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_01234, NULL, NULL}} }; -GKYL_CU_D -static const basis_tar_kern_list gkhyb_basis_tar_list[4][31] = { - // 1x1v. - { - { gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_0_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_1_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_01_target_basis, NULL, NULL }, - }, +GKYL_CU_D static const basis_tar_kern_list gkhyb_basis_tar_list[4][31] = { // 1x1v. + {{gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_0_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_1_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x1v_gkhyb_p1_eval_dirs_01_target_basis, NULL, NULL}}, // 1x2v. - { - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_0_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_1_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_01_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_2_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_02_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_12_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_012_target_basis, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_0_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_1_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_01_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_2_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_02_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_12_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_1x2v_gkhyb_p1_eval_dirs_012_target_basis, NULL, NULL}}, // 2x2v. - { - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_0_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_1_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_01_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_2_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_02_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_12_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_012_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_3_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_03_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_13_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_013_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_23_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_023_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_123_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_0123_target_basis, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_0_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_1_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_01_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_2_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_02_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_12_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_012_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_3_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_03_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_13_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_013_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_23_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_023_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_123_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_2x2v_gkhyb_p1_eval_dirs_0123_target_basis, NULL, NULL}}, // 3x2v. - { - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_1_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_01_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_2_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_02_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_12_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_012_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_3_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_03_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_13_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_013_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_23_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_023_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_123_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0123_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_4_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_04_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_14_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_014_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_24_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_024_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_124_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0124_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_34_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_034_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_134_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0134_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_234_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0234_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_1234_target_basis , NULL, NULL }, - { gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_01234_target_basis, NULL, NULL }, - }, + {{gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_1_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_01_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_2_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_02_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_12_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_012_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_3_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_03_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_13_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_013_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_23_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_023_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_123_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0123_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_4_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_04_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_14_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_014_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_24_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_024_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_124_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0124_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_34_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_034_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_134_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0134_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_234_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_0234_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_1234_target_basis, NULL, NULL}, + {gkyl_dg_eval_at_coord_proj_3x2v_gkhyb_p1_eval_dirs_01234_target_basis, NULL, NULL}} }; -GKYL_CU_DH static void -eval_at_coord_get_idx_do(const bool *is_eval, int ndim_do, - const int *idx_tar, const int *cell_idx, int *idx_do) +GKYL_CU_DH static void eval_at_coord_get_idx_do( + const bool *is_eval, int ndim_do, const int *idx_tar, const int *cell_idx, int *idx_do +) { // Translate a target index to the corresponding donor index. int c = 0; - for (int d=0; d= 1 && poly_order <= 3); switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - kers->ev_ker = ser_eval_at_coord_list[ndim-1][dir_mask-1].kernels[poly_order-1]; - kers->basis_ker = ser_basis_tar_list[ndim-1][dir_mask-1].kernels[poly_order-1]; - break; - case GKYL_BASIS_MODAL_TENSOR: - kers->ev_ker = ten_eval_at_coord_list[ndim-1][dir_mask-1].kernels[poly_order-1]; - kers->basis_ker = ten_basis_tar_list[ndim-1][dir_mask-1].kernels[poly_order-1]; - break; - case GKYL_BASIS_MODAL_GKHYBRID: - kers->ev_ker = gkhyb_eval_at_coord_list[ndim-2][dir_mask-1].kernels[poly_order-1]; - kers->basis_ker = gkhyb_basis_tar_list[ndim-2][dir_mask-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + kers->ev_ker = ser_eval_at_coord_list[ndim - 1][dir_mask - 1].kernels[poly_order - 1]; + kers->basis_ker = ser_basis_tar_list[ndim - 1][dir_mask - 1].kernels[poly_order - 1]; + break; + case GKYL_BASIS_MODAL_TENSOR: + kers->ev_ker = ten_eval_at_coord_list[ndim - 1][dir_mask - 1].kernels[poly_order - 1]; + kers->basis_ker = ten_basis_tar_list[ndim - 1][dir_mask - 1].kernels[poly_order - 1]; + break; + case GKYL_BASIS_MODAL_GKHYBRID: + kers->ev_ker = gkhyb_eval_at_coord_list[ndim - 2][dir_mask - 1].kernels[poly_order - 1]; + kers->basis_ker = gkhyb_basis_tar_list[ndim - 2][dir_mask - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } assert(kers->ev_ker); diff --git a/core/zero/gkyl_dg_geom.h b/core/zero/gkyl_dg_geom.h index 4bc9dd849a..eb909670d3 100644 --- a/core/zero/gkyl_dg_geom.h +++ b/core/zero/gkyl_dg_geom.h @@ -22,25 +22,25 @@ struct gkyl_dg_vol_geom { double Jc; // Jacobian = e_1*(e_2 X e_3) = 1/e^1*(e^2 X e^3) }; -// geometry information over a range of cells: +// geometry information over a range of cells: struct gkyl_dg_geom { struct gkyl_range range; // range over which geometry is defined struct gkyl_range surf_quad_range; // range for indexing surface nodes - struct gkyl_range vol_quad_range; // range for indexing volume nodes + struct gkyl_range vol_quad_range; // range for indexing volume nodes // index weights and ords arrays below using the appropriate // methods below - + // weights and ordinates for surface quadrature double *surf_weights, *surf_ords; // weights and ordinates for surface quadrature double *vol_weights, *vol_ords; - + struct gkyl_array *surf_geom[GKYL_MAX_CDIM]; // surface geometry in dir 'd' in each cell struct gkyl_array *vol_geom; // cell geometry - + uint32_t flags; - struct gkyl_ref_count ref_count; + struct gkyl_ref_count ref_count; struct gkyl_dg_geom *on_dev; // pointer to itself or device object }; @@ -60,7 +60,7 @@ struct gkyl_dg_geom_inp { * * @param inp Inputs for use in constructing geometry */ -struct gkyl_dg_geom* gkyl_dg_geom_new(const struct gkyl_dg_geom_inp *inp); +struct gkyl_dg_geom *gkyl_dg_geom_new(const struct gkyl_dg_geom_inp *inp); /** * Create a new DG geometry object from host object. @@ -69,10 +69,12 @@ struct gkyl_dg_geom* gkyl_dg_geom_new(const struct gkyl_dg_geom_inp *inp); * @param inp Inputs for use in constructing geometry * @param use_gpu whether to use gpu */ -struct gkyl_dg_geom* gkyl_dg_geom_new_from_host(const struct gkyl_dg_geom_inp *inp, struct gkyl_dg_geom *up_host, bool use_gpu); - -struct gkyl_dg_geom* gkyl_dg_geom_cu_dev_new_from_host(const struct gkyl_dg_geom_inp *inp, struct gkyl_dg_geom *up_host); +struct gkyl_dg_geom *gkyl_dg_geom_new_from_host( + const struct gkyl_dg_geom_inp *inp, struct gkyl_dg_geom *up_host, bool use_gpu +); +struct gkyl_dg_geom * +gkyl_dg_geom_cu_dev_new_from_host(const struct gkyl_dg_geom_inp *inp, struct gkyl_dg_geom *up_host); /** * Acquire pointer to geometry object. The pointer must be released @@ -81,7 +83,7 @@ struct gkyl_dg_geom* gkyl_dg_geom_cu_dev_new_from_host(const struct gkyl_dg_geom * @param dgg Geometry to which a pointer is needed * @return Pointer to acquired geometry */ -struct gkyl_dg_geom* gkyl_dg_geom_acquire(const struct gkyl_dg_geom* dgg); +struct gkyl_dg_geom *gkyl_dg_geom_acquire(const struct gkyl_dg_geom *dgg); /** * Write out geometry data to file. The "fprefix" is the prefix of the @@ -90,7 +92,7 @@ struct gkyl_dg_geom* gkyl_dg_geom_acquire(const struct gkyl_dg_geom* dgg); * @param dgg Geometry to which a pointer is needed * @param fname Name of output file to write */ -void gkyl_dg_geom_write(const struct gkyl_dg_geom* dgg, const char *fprefix); +void gkyl_dg_geom_write(const struct gkyl_dg_geom *dgg, const char *fprefix); /** * Get pointer to geometry on the surface normal to 'd' given by idx @@ -103,11 +105,12 @@ void gkyl_dg_geom_write(const struct gkyl_dg_geom* dgg, const char *fprefix); * @param idx Index into grid * @return Pointer to surface geometry at all quadrature nodes in cell @a idx */ -GKYL_CU_DH -static inline const struct gkyl_dg_surf_geom* +GKYL_CU_DH static inline const struct gkyl_dg_surf_geom * gkyl_dg_geom_get_surf(const struct gkyl_dg_geom *dgg, int d, const int *idx) { - return (const struct gkyl_dg_surf_geom*) gkyl_array_cfetch(dgg->surf_geom[d], gkyl_range_idx(&dgg->range, idx)); + return (const struct gkyl_dg_surf_geom *)gkyl_array_cfetch( + dgg->surf_geom[d], gkyl_range_idx(&dgg->range, idx) + ); } /** @@ -118,8 +121,7 @@ gkyl_dg_geom_get_surf(const struct gkyl_dg_geom *dgg, int d, const int *idx) * @param sidx Index (ndim-1) of surface quadrature node * @return Weight at surface quadrature node */ -GKYL_CU_DH -static inline long +GKYL_CU_DH static inline long gkyl_dg_geom_surf_quad_idx(const struct gkyl_dg_geom *dgg, const int *sidx) { return gkyl_range_idx(&dgg->surf_quad_range, sidx); @@ -133,8 +135,7 @@ gkyl_dg_geom_surf_quad_idx(const struct gkyl_dg_geom *dgg, const int *sidx) * @param sidx Index (ndim-1) of surface quadrature node * @return Weight at node */ -GKYL_CU_DH -static inline double +GKYL_CU_DH static inline double gkyl_dg_geom_surf_quad_weight(const struct gkyl_dg_geom *dgg, const int *sidx) { return dgg->surf_weights[gkyl_dg_geom_surf_quad_idx(dgg, sidx)]; @@ -148,12 +149,11 @@ gkyl_dg_geom_surf_quad_weight(const struct gkyl_dg_geom *dgg, const int *sidx) * @param sidx Index of surface quadrature node * @return Ordinates at nodes: ndim-1 size array */ -GKYL_CU_DH -static inline const double* +GKYL_CU_DH static inline const double * gkyl_dg_geom_surf_quad_ords(const struct gkyl_dg_geom *dgg, const int *sidx) { int sdim = dgg->surf_quad_range.ndim; - return &dgg->surf_ords[sdim*gkyl_dg_geom_surf_quad_idx(dgg, sidx)]; + return &dgg->surf_ords[sdim * gkyl_dg_geom_surf_quad_idx(dgg, sidx)]; } /** @@ -165,11 +165,12 @@ gkyl_dg_geom_surf_quad_ords(const struct gkyl_dg_geom *dgg, const int *sidx) * @param idx Index into grid * @return Pointer to cell geometry at all quadrature nodes in cell @a idx */ -GKYL_CU_DH -static inline const struct gkyl_dg_vol_geom* +GKYL_CU_DH static inline const struct gkyl_dg_vol_geom * gkyl_dg_geom_get_vol(const struct gkyl_dg_geom *dgg, const int *idx) { - return (const struct gkyl_dg_vol_geom*) gkyl_array_cfetch(dgg->vol_geom, gkyl_range_idx(&dgg->range, idx)); + return (const struct gkyl_dg_vol_geom *)gkyl_array_cfetch( + dgg->vol_geom, gkyl_range_idx(&dgg->range, idx) + ); } /** @@ -180,8 +181,7 @@ gkyl_dg_geom_get_vol(const struct gkyl_dg_geom *dgg, const int *idx) * @param vidx Index of volume quadrature node * @return Linear index for indexing volume quadrature array */ -GKYL_CU_DH -static inline long +GKYL_CU_DH static inline long gkyl_dg_geom_vol_quad_idx(const struct gkyl_dg_geom *dgg, const int *vidx) { return gkyl_range_idx(&dgg->vol_quad_range, vidx); @@ -195,8 +195,7 @@ gkyl_dg_geom_vol_quad_idx(const struct gkyl_dg_geom *dgg, const int *vidx) * @param vidx Index of volume quadrature node * @return Weight at node */ -GKYL_CU_DH -static inline double +GKYL_CU_DH static inline double gkyl_dg_geom_vol_quad_weight(const struct gkyl_dg_geom *dgg, const int *vidx) { return dgg->vol_weights[gkyl_dg_geom_vol_quad_idx(dgg, vidx)]; @@ -210,12 +209,11 @@ gkyl_dg_geom_vol_quad_weight(const struct gkyl_dg_geom *dgg, const int *vidx) * @param vidx Index of volume quadrature node * @return Ordinates at nodes: ndim size array */ -GKYL_CU_DH -static inline const double* +GKYL_CU_DH static inline const double * gkyl_dg_geom_vol_quad_ords(const struct gkyl_dg_geom *dgg, const int *vidx) { int ndim = dgg->vol_quad_range.ndim; - return &dgg->vol_ords[ndim*gkyl_dg_geom_vol_quad_idx(dgg, vidx)]; + return &dgg->vol_ords[ndim * gkyl_dg_geom_vol_quad_idx(dgg, vidx)]; } /** @@ -231,4 +229,3 @@ void gkyl_dg_geom_release(const struct gkyl_dg_geom *dgg); * @param inp Inputs for use in constructing geometry */ void dg_geom_free(const struct gkyl_ref_count *ref); - diff --git a/core/zero/gkyl_dg_interpolate.h b/core/zero/gkyl_dg_interpolate.h index f721e902e9..a93a2002ac 100644 --- a/core/zero/gkyl_dg_interpolate.h +++ b/core/zero/gkyl_dg_interpolate.h @@ -25,11 +25,11 @@ typedef struct gkyl_dg_interpolate gkyl_dg_interpolate; * @param use_gpu bool to determine if on GPU. * @return New interpolation updater. */ -struct gkyl_dg_interpolate* -gkyl_dg_interpolate_new(int cdim, const struct gkyl_basis *basis, - const struct gkyl_rect_grid *grid_do, const struct gkyl_rect_grid *grid_tar, - const struct gkyl_range *range_do, const struct gkyl_range *range_tar, - const int *nghost, bool use_gpu); +struct gkyl_dg_interpolate *gkyl_dg_interpolate_new( + int cdim, const struct gkyl_basis *basis, const struct gkyl_rect_grid *grid_do, + const struct gkyl_rect_grid *grid_tar, const struct gkyl_range *range_do, + const struct gkyl_range *range_tar, const int *nghost, bool use_gpu +); /** * Run the interpolation updater in the indicated range. @@ -38,14 +38,13 @@ gkyl_dg_interpolate_new(int cdim, const struct gkyl_basis *basis, * @param fdo Donor field. * @param ftar Target field. */ -void -gkyl_dg_interpolate_advance(gkyl_dg_interpolate* up, - struct gkyl_array *fdo, struct gkyl_array *ftar); +void gkyl_dg_interpolate_advance( + gkyl_dg_interpolate *up, struct gkyl_array *fdo, struct gkyl_array *ftar +); /** * Release the memory associated with this interpolating updater. * * @param up Interpolation updater. */ -void -gkyl_dg_interpolate_release(gkyl_dg_interpolate* up); +void gkyl_dg_interpolate_release(gkyl_dg_interpolate *up); diff --git a/core/zero/gkyl_dg_interpolate_priv.h b/core/zero/gkyl_dg_interpolate_priv.h index 02888b513c..e66dc22127 100644 --- a/core/zero/gkyl_dg_interpolate_priv.h +++ b/core/zero/gkyl_dg_interpolate_priv.h @@ -8,20 +8,27 @@ #include // Function that translates a grid index into a stencil index. -typedef int (*dg_interp_grid2stencilIdx_t)(int idx, - int num_cells, double dx_rat); +typedef int (*dg_interp_grid2stencilIdx_t)(int idx, int num_cells, double dx_rat); // Function pointer type for sheath reflection kernels. -typedef void (*dg_interp_t)(const double *wDo, const double *wTar, - const double *dxDo, const double *dxTar, const double *fldDo, double *fldTar); +typedef void (*dg_interp_t)( + const double *wDo, const double *wTar, const double *dxDo, const double *dxTar, + const double *fldDo, double *fldTar +); // For use in kernel tables. -typedef struct {dg_interp_t dirs[6];} dg_interp_kern_dir_list; -typedef struct {dg_interp_kern_dir_list list[2];} dg_interp_kern_p_list; -typedef struct {dg_interp_kern_p_list vdim[3];} dg_interp_kern_p_list_vlasov; +typedef struct { + dg_interp_t dirs[6]; +} dg_interp_kern_dir_list; +typedef struct { + dg_interp_kern_dir_list list[2]; +} dg_interp_kern_p_list; +typedef struct { + dg_interp_kern_p_list vdim[3]; +} dg_interp_kern_p_list_vlasov; struct gkyl_dg_interpolate_kernels { - dg_interp_t interp; // Kernel that performs the interpolation. + dg_interp_t interp; // Kernel that performs the interpolation. dg_interp_grid2stencilIdx_t grid2stencil; // Translate grid to stencil index. }; @@ -44,129 +51,114 @@ struct gkyl_dg_interpolate { }; // Serendipity kernels. -GKYL_CU_D -static const dg_interp_kern_p_list dg_interp_kern_list_ser[] = { - // 1x - { .list = { - { dg_interpolate_1x_ser_p1_x, NULL, NULL, NULL, NULL, NULL, }, - { dg_interpolate_1x_ser_p2_x, NULL, NULL, NULL, NULL, NULL, }, - }, - }, +GKYL_CU_D static const dg_interp_kern_p_list dg_interp_kern_list_ser[] = { // 1x + {.list = + {{dg_interpolate_1x_ser_p1_x, NULL, NULL, NULL, NULL, NULL}, + {dg_interpolate_1x_ser_p2_x, NULL, NULL, NULL, NULL, NULL}}}, // 2x - { .list = { - { dg_interpolate_2x_ser_p1_x, dg_interpolate_2x_ser_p1_y, NULL, NULL, NULL, NULL, }, - { dg_interpolate_2x_ser_p2_x, dg_interpolate_2x_ser_p2_y, NULL, NULL, NULL, NULL, }, - }, - }, + {.list = + {{dg_interpolate_2x_ser_p1_x, dg_interpolate_2x_ser_p1_y, NULL, NULL, NULL, NULL}, + {dg_interpolate_2x_ser_p2_x, dg_interpolate_2x_ser_p2_y, NULL, NULL, NULL, NULL}}}, // 3x - { .list = { - { dg_interpolate_3x_ser_p1_x, dg_interpolate_3x_ser_p1_y, dg_interpolate_3x_ser_p1_z, NULL, NULL, NULL, }, - { dg_interpolate_3x_ser_p2_x, dg_interpolate_3x_ser_p2_y, dg_interpolate_3x_ser_p2_z, NULL, NULL, NULL, }, - }, - }, + {.list = + {{dg_interpolate_3x_ser_p1_x, dg_interpolate_3x_ser_p1_y, dg_interpolate_3x_ser_p1_z, NULL, + NULL, NULL}, + {dg_interpolate_3x_ser_p2_x, dg_interpolate_3x_ser_p2_y, dg_interpolate_3x_ser_p2_z, NULL, + NULL, NULL}}} }; -GKYL_CU_D -static const dg_interp_kern_p_list dg_interp_kern_list_gk_ser[] = { - // 1x1v - { .list = { - { dg_interpolate_gyrokinetic_1x1v_ser_p1_x, dg_interpolate_gyrokinetic_1x1v_ser_p1_vpar, NULL, NULL, NULL, NULL, }, - { dg_interpolate_gyrokinetic_1x1v_ser_p2_x, dg_interpolate_gyrokinetic_1x1v_ser_p2_vpar, NULL, NULL, NULL, NULL, }, - }, - }, +GKYL_CU_D static const dg_interp_kern_p_list dg_interp_kern_list_gk_ser[] = { // 1x1v + {.list = + {{dg_interpolate_gyrokinetic_1x1v_ser_p1_x, dg_interpolate_gyrokinetic_1x1v_ser_p1_vpar, NULL, + NULL, NULL, NULL}, + {dg_interpolate_gyrokinetic_1x1v_ser_p2_x, dg_interpolate_gyrokinetic_1x1v_ser_p2_vpar, NULL, + NULL, NULL, NULL}}}, // 1x2v - { .list = { - { dg_interpolate_gyrokinetic_1x2v_ser_p1_x, dg_interpolate_gyrokinetic_1x2v_ser_p1_vpar, dg_interpolate_gyrokinetic_1x2v_ser_p1_mu, NULL, NULL, NULL, }, - { dg_interpolate_gyrokinetic_1x2v_ser_p2_x, dg_interpolate_gyrokinetic_1x2v_ser_p2_vpar, dg_interpolate_gyrokinetic_1x2v_ser_p2_mu, NULL, NULL, NULL, }, - }, - }, + {.list = + {{dg_interpolate_gyrokinetic_1x2v_ser_p1_x, dg_interpolate_gyrokinetic_1x2v_ser_p1_vpar, + dg_interpolate_gyrokinetic_1x2v_ser_p1_mu, NULL, NULL, NULL}, + {dg_interpolate_gyrokinetic_1x2v_ser_p2_x, dg_interpolate_gyrokinetic_1x2v_ser_p2_vpar, + dg_interpolate_gyrokinetic_1x2v_ser_p2_mu, NULL, NULL, NULL}}}, // 2x2v - { .list = { - { dg_interpolate_gyrokinetic_2x2v_ser_p1_x, dg_interpolate_gyrokinetic_2x2v_ser_p1_z, dg_interpolate_gyrokinetic_2x2v_ser_p1_vpar, dg_interpolate_gyrokinetic_2x2v_ser_p1_mu, NULL, NULL, }, - { dg_interpolate_gyrokinetic_2x2v_ser_p2_x, dg_interpolate_gyrokinetic_2x2v_ser_p2_z, dg_interpolate_gyrokinetic_2x2v_ser_p2_vpar, dg_interpolate_gyrokinetic_2x2v_ser_p2_mu, NULL, NULL, }, - }, - }, + {.list = + {{dg_interpolate_gyrokinetic_2x2v_ser_p1_x, dg_interpolate_gyrokinetic_2x2v_ser_p1_z, + dg_interpolate_gyrokinetic_2x2v_ser_p1_vpar, dg_interpolate_gyrokinetic_2x2v_ser_p1_mu, NULL, + NULL}, + {dg_interpolate_gyrokinetic_2x2v_ser_p2_x, dg_interpolate_gyrokinetic_2x2v_ser_p2_z, + dg_interpolate_gyrokinetic_2x2v_ser_p2_vpar, dg_interpolate_gyrokinetic_2x2v_ser_p2_mu, NULL, + NULL}}}, // 3x2v - { .list = { - { dg_interpolate_gyrokinetic_3x2v_ser_p1_x, dg_interpolate_gyrokinetic_3x2v_ser_p1_y, dg_interpolate_gyrokinetic_3x2v_ser_p1_z, dg_interpolate_gyrokinetic_3x2v_ser_p1_vpar, dg_interpolate_gyrokinetic_3x2v_ser_p1_mu, NULL, }, - { NULL, NULL, NULL, NULL, NULL, NULL, }, - }, - }, + {.list = + {{dg_interpolate_gyrokinetic_3x2v_ser_p1_x, dg_interpolate_gyrokinetic_3x2v_ser_p1_y, + dg_interpolate_gyrokinetic_3x2v_ser_p1_z, dg_interpolate_gyrokinetic_3x2v_ser_p1_vpar, + dg_interpolate_gyrokinetic_3x2v_ser_p1_mu, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL}}} }; -GKYL_CU_D -static const dg_interp_kern_p_list_vlasov dg_interp_kern_list_vlasov_ser[] = { - // 1x - { .vdim = { - { .list = { - { dg_interpolate_vlasov_1x1v_ser_p1_x, dg_interpolate_vlasov_1x1v_ser_p1_vx, NULL, NULL, NULL, NULL, }, - { dg_interpolate_vlasov_1x1v_ser_p2_x, dg_interpolate_vlasov_1x1v_ser_p2_vx, NULL, NULL, NULL, NULL, }, - }, - }, - { .list = { - { dg_interpolate_vlasov_1x2v_ser_p1_x, dg_interpolate_vlasov_1x2v_ser_p1_vx, dg_interpolate_vlasov_1x2v_ser_p1_vy, NULL, NULL, NULL, }, - { dg_interpolate_vlasov_1x2v_ser_p2_x, dg_interpolate_vlasov_1x2v_ser_p2_vx, dg_interpolate_vlasov_1x2v_ser_p2_vy, NULL, NULL, NULL, }, - }, - }, - { .list = { - { dg_interpolate_vlasov_1x3v_ser_p1_x, dg_interpolate_vlasov_1x3v_ser_p1_vx, dg_interpolate_vlasov_1x2v_ser_p1_vy, dg_interpolate_vlasov_1x3v_ser_p1_vz, NULL, NULL, }, - { dg_interpolate_vlasov_1x3v_ser_p2_x, dg_interpolate_vlasov_1x3v_ser_p2_vx, dg_interpolate_vlasov_1x2v_ser_p2_vy, dg_interpolate_vlasov_1x3v_ser_p2_vz, NULL, NULL, }, - }, - }, - }, - }, +GKYL_CU_D static const dg_interp_kern_p_list_vlasov dg_interp_kern_list_vlasov_ser[] = { // 1x + {.vdim = + {{.list = + {{dg_interpolate_vlasov_1x1v_ser_p1_x, dg_interpolate_vlasov_1x1v_ser_p1_vx, NULL, NULL, + NULL, NULL}, + {dg_interpolate_vlasov_1x1v_ser_p2_x, dg_interpolate_vlasov_1x1v_ser_p2_vx, NULL, NULL, + NULL, NULL}}}, + {.list = + {{dg_interpolate_vlasov_1x2v_ser_p1_x, dg_interpolate_vlasov_1x2v_ser_p1_vx, + dg_interpolate_vlasov_1x2v_ser_p1_vy, NULL, NULL, NULL}, + {dg_interpolate_vlasov_1x2v_ser_p2_x, dg_interpolate_vlasov_1x2v_ser_p2_vx, + dg_interpolate_vlasov_1x2v_ser_p2_vy, NULL, NULL, NULL}}}, + {.list = + {{dg_interpolate_vlasov_1x3v_ser_p1_x, dg_interpolate_vlasov_1x3v_ser_p1_vx, + dg_interpolate_vlasov_1x2v_ser_p1_vy, dg_interpolate_vlasov_1x3v_ser_p1_vz, NULL, NULL}, + {dg_interpolate_vlasov_1x3v_ser_p2_x, dg_interpolate_vlasov_1x3v_ser_p2_vx, + dg_interpolate_vlasov_1x2v_ser_p2_vy, dg_interpolate_vlasov_1x3v_ser_p2_vz, NULL, NULL}}} + }}, // 2x - { .vdim = { - { .list = { - { NULL, NULL, NULL, NULL, NULL, NULL, }, - { NULL, NULL, NULL, NULL, NULL, NULL, }, - }, - }, - { .list = { - { dg_interpolate_vlasov_2x2v_ser_p1_x, dg_interpolate_vlasov_2x2v_ser_p1_y, dg_interpolate_vlasov_2x2v_ser_p1_vx, dg_interpolate_vlasov_2x2v_ser_p1_vy, NULL, NULL, }, - { dg_interpolate_vlasov_2x2v_ser_p2_x, dg_interpolate_vlasov_2x2v_ser_p2_y, dg_interpolate_vlasov_2x2v_ser_p2_vx, dg_interpolate_vlasov_2x2v_ser_p2_vy, NULL, NULL, }, - }, - }, - { .list = { - { dg_interpolate_vlasov_2x3v_ser_p1_x, dg_interpolate_vlasov_2x3v_ser_p1_y, dg_interpolate_vlasov_2x3v_ser_p1_vx, dg_interpolate_vlasov_2x2v_ser_p1_vy, dg_interpolate_vlasov_2x3v_ser_p1_vz, NULL, }, - { dg_interpolate_vlasov_2x3v_ser_p2_x, dg_interpolate_vlasov_2x3v_ser_p2_y, dg_interpolate_vlasov_2x3v_ser_p2_vx, dg_interpolate_vlasov_2x2v_ser_p2_vy, dg_interpolate_vlasov_2x3v_ser_p2_vz, NULL, }, - }, - }, - }, + { + .vdim = + {{.list = {{NULL, NULL, NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL}}}, + {.list = + {{dg_interpolate_vlasov_2x2v_ser_p1_x, dg_interpolate_vlasov_2x2v_ser_p1_y, + dg_interpolate_vlasov_2x2v_ser_p1_vx, dg_interpolate_vlasov_2x2v_ser_p1_vy, NULL, NULL}, + {dg_interpolate_vlasov_2x2v_ser_p2_x, dg_interpolate_vlasov_2x2v_ser_p2_y, + dg_interpolate_vlasov_2x2v_ser_p2_vx, dg_interpolate_vlasov_2x2v_ser_p2_vy, NULL, NULL}} + }, + {.list = + {{dg_interpolate_vlasov_2x3v_ser_p1_x, dg_interpolate_vlasov_2x3v_ser_p1_y, + dg_interpolate_vlasov_2x3v_ser_p1_vx, dg_interpolate_vlasov_2x2v_ser_p1_vy, + dg_interpolate_vlasov_2x3v_ser_p1_vz, NULL}, + {dg_interpolate_vlasov_2x3v_ser_p2_x, dg_interpolate_vlasov_2x3v_ser_p2_y, + dg_interpolate_vlasov_2x3v_ser_p2_vx, dg_interpolate_vlasov_2x2v_ser_p2_vy, + dg_interpolate_vlasov_2x3v_ser_p2_vz, NULL}}}} }, // 3x - { .vdim = { - { .list = { - { NULL, NULL, NULL, NULL, NULL, NULL, }, - { NULL, NULL, NULL, NULL, NULL, NULL, }, - }, - }, - { .list = { - { NULL, NULL, NULL, NULL, NULL, NULL, }, - { NULL, NULL, NULL, NULL, NULL, NULL, }, - }, - }, - { .list = { - { dg_interpolate_vlasov_3x3v_ser_p1_x, dg_interpolate_vlasov_3x3v_ser_p1_y, dg_interpolate_vlasov_3x3v_ser_p1_z, dg_interpolate_vlasov_3x3v_ser_p1_vx, dg_interpolate_vlasov_3x3v_ser_p1_vy, dg_interpolate_vlasov_3x3v_ser_p1_vz, }, - { NULL, NULL, NULL, NULL, NULL, NULL, }, - }, - }, - }, - }, + { + .vdim = + {{.list = {{NULL, NULL, NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL}}}, + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL}}}, + {.list = + {{dg_interpolate_vlasov_3x3v_ser_p1_x, dg_interpolate_vlasov_3x3v_ser_p1_y, + dg_interpolate_vlasov_3x3v_ser_p1_z, dg_interpolate_vlasov_3x3v_ser_p1_vx, + dg_interpolate_vlasov_3x3v_ser_p1_vy, dg_interpolate_vlasov_3x3v_ser_p1_vz}, + {NULL, NULL, NULL, NULL, NULL, NULL}}}} + } }; #ifdef GKYL_HAVE_CUDA // Declaration of cuda device functions. -void dg_interp_choose_kernel_cu(struct gkyl_dg_interpolate_kernels *kernels, - int cdim, struct gkyl_basis basis, int dir, double dxRat); +void dg_interp_choose_kernel_cu( + struct gkyl_dg_interpolate_kernels *kernels, int cdim, struct gkyl_basis basis, int dir, + double dxRat +); -void gkyl_dg_interpolate_advance_1x_cu(gkyl_dg_interpolate* up, - const struct gkyl_range *phase_rng_do, const struct gkyl_range *phase_rng_tar, - const struct gkyl_array *GKYL_RESTRICT fdo, struct gkyl_array *GKYL_RESTRICT ftar); +void gkyl_dg_interpolate_advance_1x_cu( + gkyl_dg_interpolate *up, const struct gkyl_range *phase_rng_do, + const struct gkyl_range *phase_rng_tar, const struct gkyl_array *GKYL_RESTRICT fdo, + struct gkyl_array *GKYL_RESTRICT ftar +); #endif -GKYL_CU_D -static dg_interp_t +GKYL_CU_D static dg_interp_t dg_interp_choose_gk_interp_kernel(int cdim, struct gkyl_basis basis, int dir) { enum gkyl_basis_type basis_type = basis.b_type; @@ -176,28 +168,27 @@ dg_interp_choose_gk_interp_kernel(int cdim, struct gkyl_basis basis, int dir) if (vdim == 0) { switch (basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return dg_interp_kern_list_ser[ndim-1].list[poly_order-1].dirs[dir]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return dg_interp_kern_list_ser[ndim - 1].list[poly_order - 1].dirs[dir]; + break; + default: + assert(false); + break; } - } - else { + } else { switch (basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return dg_interp_kern_list_vlasov_ser[cdim-1].vdim[vdim-1].list[poly_order-1].dirs[dir]; - break; - case GKYL_BASIS_MODAL_HYBRID: - return dg_interp_kern_list_vlasov_ser[cdim-1].vdim[vdim-1].list[poly_order-1].dirs[dir]; - break; - case GKYL_BASIS_MODAL_GKHYBRID: - return dg_interp_kern_list_gk_ser[ndim-2].list[poly_order-1].dirs[dir]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return dg_interp_kern_list_vlasov_ser[cdim - 1].vdim[vdim - 1].list[poly_order - 1].dirs[dir]; + break; + case GKYL_BASIS_MODAL_HYBRID: + return dg_interp_kern_list_vlasov_ser[cdim - 1].vdim[vdim - 1].list[poly_order - 1].dirs[dir]; + break; + case GKYL_BASIS_MODAL_GKHYBRID: + return dg_interp_kern_list_gk_ser[ndim - 2].list[poly_order - 1].dirs[dir]; + break; + default: + assert(false); + break; } } @@ -207,19 +198,21 @@ dg_interp_choose_gk_interp_kernel(int cdim, struct gkyl_basis basis, int dir) static int dg_interp_floor(double a, double tol, double b) { // Floor function but if tol<|a|, it assumes it is b; - if (tol < fabs(a)) + if (tol < fabs(a)) { return floor(a); - else + } else { return b; + } } static int dg_interp_ceil(double a, double tol, double b) { // Ceiling function but if tol<|a|, it assumes it is b; - if (tol < fabs(a)) + if (tol < fabs(a)) { return ceil(a); - else + } else { return b; + } } static int dg_interp_prime_factors(int n, int *pfs, int pfs_size) @@ -234,62 +227,56 @@ static int dg_interp_prime_factors(int n, int *pfs, int pfs_size) pf_count++; assert(pf_count < pfs_size); n /= c; - } - else + } else { c++; + } } return pf_count; } -GKYL_CU_DH -static int dg_interp_index_stencil_map_refine(int idx, - int num_cells, double dx_rat) +GKYL_CU_DH static int dg_interp_index_stencil_map_refine(int idx, int num_cells, double dx_rat) { // Given an index 'idx' to a cell in the coarse grid with 'num_cells' // cells, return the index of the refinement stencil needed, within // the table that holds stencils. Here 'dx_rat' is the ratio of // donor to target cell length in the interpolating direction. - double remDecL = (idx-1)*dx_rat-floor((idx-1)*dx_rat); - double remDecU = ceil(idx*dx_rat)-idx*dx_rat; + double remDecL = (idx - 1) * dx_rat - floor((idx - 1) * dx_rat); + double remDecU = ceil(idx * dx_rat) - idx * dx_rat; int stencilOut = 1; - if ((idx == 1) || // First cell. - (remDecL == 0) || // Interior cell with a left-boundary-like stencil. + if ((idx == 1) || // First cell. + (remDecL == 0) || // Interior cell with a left-boundary-like stencil. ((remDecL <= 0.5) && (remDecU <= 0.5))) { - stencilOut = 2*stencilOut; - } - else if ((idx == num_cells) || // Last cell. - (remDecU == 0)) { // Interior cell with a right-boundary-like stencil. - stencilOut = 2*stencilOut + 1; + stencilOut = 2 * stencilOut; + } else if ((idx == num_cells) || // Last cell. + (remDecU == 0)) { // Interior cell with a right-boundary-like stencil. + stencilOut = 2 * stencilOut + 1; } - return stencilOut-1; + return stencilOut - 1; } -GKYL_CU_DH -static int dg_interp_index_stencil_map_coarsen(int idx, - int num_cells, double dx_rat) +GKYL_CU_DH static int dg_interp_index_stencil_map_coarsen(int idx, int num_cells, double dx_rat) { // Given an index 'idx' to a cell in the fine grid with 'num_cells' // cells, return the index of the coarsening stencil needed, within // the table that holds stencils. Here 'dx_rat' is the ratio of // donor to target cell length in the interpolating direction. - double remDecL = (idx-1)*dx_rat-floor(idx*dx_rat); - double remDecU = ceil(idx*dx_rat)-idx*dx_rat; + double remDecL = (idx - 1) * dx_rat - floor(idx * dx_rat); + double remDecU = ceil(idx * dx_rat) - idx * dx_rat; int stencilOut = 1; if ((idx == 1) || // First cell. (remDecL == 0) || // Interior cell with a left-boundary-like stencil. ((remDecL > 0) && (remDecU > 0))) { - stencilOut = 2*stencilOut; + stencilOut = 2 * stencilOut; + } else if ((idx == num_cells) || // Last cell. + (remDecU == 0)) { // Interior cell with a right-boundary-like stencil. + stencilOut = 2 * stencilOut + 1; } - else if ((idx == num_cells) || // Last cell. - (remDecU == 0)) { // Interior cell with a right-boundary-like stencil. - stencilOut = 2*stencilOut + 1; - } - return stencilOut-1; + return stencilOut - 1; } -static void -dg_interpolate_check_cell_overlap(struct gkyl_dg_interpolate *up, const struct gkyl_range *range_do, - const int *offset_upper) +static void dg_interpolate_check_cell_overlap( + struct gkyl_dg_interpolate *up, const struct gkyl_range *range_do, const int *offset_upper +) { // Check that for a given donor cell the target cells used are actually // overlapping with this donor. This code is similar to the one in the @@ -303,55 +290,61 @@ dg_interpolate_check_cell_overlap(struct gkyl_dg_interpolate *up, const struct g struct gkyl_range_iter iter_do; gkyl_range_iter_init(&iter_do, range_do); while (gkyl_range_iter_next(&iter_do)) { - int *idx_do = iter_do.idx; gkyl_rect_grid_cell_center(&up->grid_do, idx_do, xc_do); - for (int d=0; dndim; d++) { - xlo_do[d] = xc_do[d] - 0.5*up->grid_do.dx[d]; - xup_do[d] = xc_do[d] + 0.5*up->grid_do.dx[d]; + for (int d = 0; d < up->ndim; d++) { + xlo_do[d] = xc_do[d] - 0.5 * up->grid_do.dx[d]; + xup_do[d] = xc_do[d] + 0.5 * up->grid_do.dx[d]; } // Compute the index of the lower target cell this cell contributes to. - double eveOI = up->dxRat*(idx_do[up->dir]-1); - int idx_tar_lo = ceil(eveOI)+((int) ceil(eveOI-floor(eveOI))+1) % 2; + double eveOI = up->dxRat * (idx_do[up->dir] - 1); + int idx_tar_lo = ceil(eveOI) + ((int)ceil(eveOI - floor(eveOI)) + 1) % 2; // Get the index to the stencil for this donor cell. int idx_sten; - if (up->dxRat > 1) - idx_sten = dg_interp_index_stencil_map_refine(idx_do[up->dir], up->grid_do.cells[up->dir], up->dxRat); - else - idx_sten = dg_interp_index_stencil_map_coarsen(idx_do[up->dir], up->grid_do.cells[up->dir], up->dxRat); + if (up->dxRat > 1) { + idx_sten = + dg_interp_index_stencil_map_refine(idx_do[up->dir], up->grid_do.cells[up->dir], up->dxRat); + } else { + idx_sten = + dg_interp_index_stencil_map_coarsen(idx_do[up->dir], up->grid_do.cells[up->dir], up->dxRat); + } - for (int d=0; dndim; d++) + for (int d = 0; d < up->ndim; d++) { idx_tar[d] = idx_do[d]; + } // Loop over the target-grid cells this donor cell contributes to. - for (int off=0; offdir] = idx_tar_lo + off; gkyl_rect_grid_cell_center(&up->grid_tar, idx_tar, xc_tar); - for (int d=0; dndim; d++) { - xlo_tar[d] = xc_tar[d] - 0.5*up->grid_tar.dx[d]; - xup_tar[d] = xc_tar[d] + 0.5*up->grid_tar.dx[d]; + for (int d = 0; d < up->ndim; d++) { + xlo_tar[d] = xc_tar[d] - 0.5 * up->grid_tar.dx[d]; + xup_tar[d] = xc_tar[d] + 0.5 * up->grid_tar.dx[d]; } // Check that either edge of this cell is contained within the donor cell. - for (int d=0; dndim; d++) { + for (int d = 0; d < up->ndim; d++) { bool overlaps = (xlo_do[d] <= xup_tar[d]) && (xlo_tar[d] <= xup_do[d]); if (!overlaps) { // Print some info and exit. printf("\nidx_do="); - for (int d=0; dndim; d++) - printf("%d ",idx_do[d]); + for (int d = 0; d < up->ndim; d++) { + printf("%d ", idx_do[d]); + } printf(" extents="); - for (int d=0; dndim; d++) - printf("[%e,%e] ",xlo_do[d],xup_do[d]); + for (int d = 0; d < up->ndim; d++) { + printf("[%e,%e] ", xlo_do[d], xup_do[d]); + } printf("\nidx_tar="); - for (int d=0; dndim; d++) - printf("%d ",idx_tar[d]); + for (int d = 0; d < up->ndim; d++) { + printf("%d ", idx_tar[d]); + } printf(" extents="); - for (int d=0; dndim; d++) - printf("[%e,%e] ",xlo_tar[d],xup_tar[d]); + for (int d = 0; d < up->ndim; d++) { + printf("[%e,%e] ", xlo_tar[d], xup_tar[d]); + } printf("\n"); assert(overlaps); diff --git a/core/zero/gkyl_dual_num.h b/core/zero/gkyl_dual_num.h index 7dba8201aa..2b215c47ed 100644 --- a/core/zero/gkyl_dual_num.h +++ b/core/zero/gkyl_dual_num.h @@ -4,9 +4,13 @@ #include // Dual or hyperreal number -struct gkyl_dn { double x[2]; }; +struct gkyl_dn { + double x[2]; +}; // Dual or hyperreal 2D number -struct gkyl_dn2 { double x[3]; }; +struct gkyl_dn2 { + double x[3]; +}; /** Use the new0 constructor to create a real number and new1 to create @@ -18,160 +22,111 @@ struct gkyl_dn2 { double x[3]; }; */ // Construct new dual numbers -GKYL_CU_DH -static inline struct gkyl_dn -gdn_new(double x0, double x1) +GKYL_CU_DH static inline struct gkyl_dn gdn_new(double x0, double x1) { - return (struct gkyl_dn) { x0, x1 }; + return (struct gkyl_dn){x0, x1}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_new0(double x0) +GKYL_CU_DH static inline struct gkyl_dn gdn_new0(double x0) { return gdn_new(x0, 0.0); } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_new1(double x0) +GKYL_CU_DH static inline struct gkyl_dn gdn_new1(double x0) { return gdn_new(x0, 1.0); } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_neg(struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_neg(struct gkyl_dn d1) { - return (struct gkyl_dn) { -d1.x[0], -d1.x[1] }; + return (struct gkyl_dn){-d1.x[0], -d1.x[1]}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_add(struct gkyl_dn d1, struct gkyl_dn d2) +GKYL_CU_DH static inline struct gkyl_dn gdn_add(struct gkyl_dn d1, struct gkyl_dn d2) { - return (struct gkyl_dn) { d1.x[0]+d2.x[0], d1.x[1]+d2.x[1] }; + return (struct gkyl_dn){d1.x[0] + d2.x[0], d1.x[1] + d2.x[1]}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_sadd(double s, struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_sadd(double s, struct gkyl_dn d1) { - return (struct gkyl_dn) { s+d1.x[0], d1.x[1] }; + return (struct gkyl_dn){s + d1.x[0], d1.x[1]}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_sub(struct gkyl_dn d1, struct gkyl_dn d2) +GKYL_CU_DH static inline struct gkyl_dn gdn_sub(struct gkyl_dn d1, struct gkyl_dn d2) { - return (struct gkyl_dn) { d1.x[0]-d2.x[0], d1.x[1]-d2.x[1] }; + return (struct gkyl_dn){d1.x[0] - d2.x[0], d1.x[1] - d2.x[1]}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_ssub(double s, struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_ssub(double s, struct gkyl_dn d1) { - return (struct gkyl_dn) { s-d1.x[0], -d1.x[1] }; + return (struct gkyl_dn){s - d1.x[0], -d1.x[1]}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_mul(struct gkyl_dn d1, struct gkyl_dn d2) +GKYL_CU_DH static inline struct gkyl_dn gdn_mul(struct gkyl_dn d1, struct gkyl_dn d2) { - return (struct gkyl_dn) { - d1.x[0]*d2.x[0], - d1.x[0]*d2.x[1] + d1.x[1]*d2.x[0] - }; + return (struct gkyl_dn){d1.x[0] * d2.x[0], d1.x[0] * d2.x[1] + d1.x[1] * d2.x[0]}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_smul(double s, struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_smul(double s, struct gkyl_dn d1) { - return (struct gkyl_dn) { s*d1.x[0], s*d1.x[1] }; + return (struct gkyl_dn){s * d1.x[0], s * d1.x[1]}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_inv(struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_inv(struct gkyl_dn d1) { - return (struct gkyl_dn) { - 1.0/d1.x[0], - -d1.x[1]/(d1.x[0]*d1.x[0]) - }; + return (struct gkyl_dn){1.0 / d1.x[0], -d1.x[1] / (d1.x[0] * d1.x[0])}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_div(struct gkyl_dn d1, struct gkyl_dn d2) +GKYL_CU_DH static inline struct gkyl_dn gdn_div(struct gkyl_dn d1, struct gkyl_dn d2) { return gdn_mul(d1, gdn_inv(d2)); } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_sdiv(double s, struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_sdiv(double s, struct gkyl_dn d1) { return gdn_smul(s, gdn_inv(d1)); } - -GKYL_CU_DH -static inline struct gkyl_dn -gdn_sq(struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_sq(struct gkyl_dn d1) { - return (struct gkyl_dn) { d1.x[0]*d1.x[0], 2.0*d1.x[0]*d1.x[1] }; + return (struct gkyl_dn){d1.x[0] * d1.x[0], 2.0 * d1.x[0] * d1.x[1]}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_cube(struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_cube(struct gkyl_dn d1) { return gdn_mul(d1, gdn_sq(d1)); } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_npow(struct gkyl_dn d1, int n) +GKYL_CU_DH static inline struct gkyl_dn gdn_npow(struct gkyl_dn d1, int n) { - double pn1 = pow(d1.x[0], n-1); - return (struct gkyl_dn) { pn1*d1.x[0], n*pn1*d1.x[1] }; + double pn1 = pow(d1.x[0], n - 1); + return (struct gkyl_dn){pn1 * d1.x[0], n * pn1 * d1.x[1]}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_sqrt(struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_sqrt(struct gkyl_dn d1) { double sx = sqrt(d1.x[0]); - return (struct gkyl_dn) { sx, d1.x[1]*0.5/sx }; + return (struct gkyl_dn){sx, d1.x[1] * 0.5 / sx}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_sin(struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_sin(struct gkyl_dn d1) { - return (struct gkyl_dn) { sin(d1.x[0]), d1.x[1]*cos(d1.x[0]) }; + return (struct gkyl_dn){sin(d1.x[0]), d1.x[1] * cos(d1.x[0])}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_cos(struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_cos(struct gkyl_dn d1) { - return (struct gkyl_dn) { cos(d1.x[0]), -d1.x[1]*sin(d1.x[0]) }; + return (struct gkyl_dn){cos(d1.x[0]), -d1.x[1] * sin(d1.x[0])}; } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_tan(struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_tan(struct gkyl_dn d1) { return gdn_div(gdn_sin(d1), gdn_cos(d1)); } -GKYL_CU_DH -static inline struct gkyl_dn -gdn_log(struct gkyl_dn d1) +GKYL_CU_DH static inline struct gkyl_dn gdn_log(struct gkyl_dn d1) { - return (struct gkyl_dn) { log(d1.x[0]), d1.x[1]/d1.x[0] }; + return (struct gkyl_dn){log(d1.x[0]), d1.x[1] / d1.x[0]}; } /***************/ @@ -179,172 +134,122 @@ gdn_log(struct gkyl_dn d1) /***************/ // Construct new dual numbers -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_new(double x0, double x1, double x2) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_new(double x0, double x1, double x2) { - return (struct gkyl_dn2) { x0, x1, x2 }; + return (struct gkyl_dn2){x0, x1, x2}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_new00(double x0) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_new00(double x0) { return gdn2_new(x0, 0.0, 0.0); } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_new01(double x0) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_new01(double x0) { return gdn2_new(x0, 0.0, 1.0); } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_new10(double x0) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_new10(double x0) { return gdn2_new(x0, 1.0, 0.0); } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_new11(double x0) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_new11(double x0) { - return (struct gkyl_dn2) { x0, 1.0, 1.0 }; + return (struct gkyl_dn2){x0, 1.0, 1.0}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_neg(struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_neg(struct gkyl_dn2 d1) { - return (struct gkyl_dn2) { -d1.x[0], -d1.x[1], -d1.x[2] }; + return (struct gkyl_dn2){-d1.x[0], -d1.x[1], -d1.x[2]}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_add(struct gkyl_dn2 d1, struct gkyl_dn2 d2) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_add(struct gkyl_dn2 d1, struct gkyl_dn2 d2) { - return (struct gkyl_dn2) { d1.x[0]+d2.x[0], d1.x[1]+d2.x[1], d1.x[2]+d2.x[2] }; + return (struct gkyl_dn2){d1.x[0] + d2.x[0], d1.x[1] + d2.x[1], d1.x[2] + d2.x[2]}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_sadd(double s, struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_sadd(double s, struct gkyl_dn2 d1) { - return (struct gkyl_dn2) { s+d1.x[0], d1.x[1], d1.x[2] }; + return (struct gkyl_dn2){s + d1.x[0], d1.x[1], d1.x[2]}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_sub(struct gkyl_dn2 d1, struct gkyl_dn2 d2) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_sub(struct gkyl_dn2 d1, struct gkyl_dn2 d2) { - return (struct gkyl_dn2) { d1.x[0]-d2.x[0], d1.x[1]-d2.x[1], d1.x[2]-d2.x[2] }; + return (struct gkyl_dn2){d1.x[0] - d2.x[0], d1.x[1] - d2.x[1], d1.x[2] - d2.x[2]}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_ssub(double s, struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_ssub(double s, struct gkyl_dn2 d1) { - return (struct gkyl_dn2) { s-d1.x[0], -d1.x[1], -d1.x[2] }; + return (struct gkyl_dn2){s - d1.x[0], -d1.x[1], -d1.x[2]}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_mul(struct gkyl_dn2 d1, struct gkyl_dn2 d2) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_mul(struct gkyl_dn2 d1, struct gkyl_dn2 d2) { - return (struct gkyl_dn2) { - d1.x[0]*d2.x[0], - d1.x[0]*d2.x[1] + d1.x[1]*d2.x[0], - d1.x[0]*d2.x[2] + d1.x[2]*d2.x[0], + return (struct gkyl_dn2 + ){d1.x[0] * d2.x[0], d1.x[0] * d2.x[1] + d1.x[1] * d2.x[0], d1.x[0] * d2.x[2] + d1.x[2] * d2.x[0] }; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_smul(double s, struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_smul(double s, struct gkyl_dn2 d1) { - return (struct gkyl_dn2) { s*d1.x[0], s*d1.x[1], s*d1.x[2] }; + return (struct gkyl_dn2){s * d1.x[0], s * d1.x[1], s * d1.x[2]}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_inv(struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_inv(struct gkyl_dn2 d1) { - return (struct gkyl_dn2) { - 1.0/d1.x[0], -d1.x[1]/(d1.x[0]*d1.x[0]), -d1.x[2]/(d1.x[0]*d1.x[0]), - }; + return (struct gkyl_dn2 + ){1.0 / d1.x[0], -d1.x[1] / (d1.x[0] * d1.x[0]), -d1.x[2] / (d1.x[0] * d1.x[0])}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_div(struct gkyl_dn2 d1, struct gkyl_dn2 d2) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_div(struct gkyl_dn2 d1, struct gkyl_dn2 d2) { return gdn2_mul(d1, gdn2_inv(d2)); } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_sdiv(double s, struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_sdiv(double s, struct gkyl_dn2 d1) { return gdn2_smul(s, gdn2_inv(d1)); } - -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_sq(struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_sq(struct gkyl_dn2 d1) { return gdn2_mul(d1, d1); } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_cube(struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_cube(struct gkyl_dn2 d1) { return gdn2_mul(d1, gdn2_sq(d1)); } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_npow(struct gkyl_dn2 d1, int n) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_npow(struct gkyl_dn2 d1, int n) { - double pn1 = pow(d1.x[0], n-1); - return (struct gkyl_dn2) { pn1*d1.x[0], n*pn1*d1.x[1], n*pn1*d1.x[2] }; + double pn1 = pow(d1.x[0], n - 1); + return (struct gkyl_dn2){pn1 * d1.x[0], n * pn1 * d1.x[1], n * pn1 * d1.x[2]}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_sqrt(struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_sqrt(struct gkyl_dn2 d1) { double sx = sqrt(d1.x[0]); - return (struct gkyl_dn2) { sx, d1.x[1]*0.5/sx, d1.x[2]*0.5/sx }; + return (struct gkyl_dn2){sx, d1.x[1] * 0.5 / sx, d1.x[2] * 0.5 / sx}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_sin(struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_sin(struct gkyl_dn2 d1) { - return (struct gkyl_dn2) { sin(d1.x[0]), d1.x[1]*cos(d1.x[0]), d1.x[2]*cos(d1.x[0]) }; + return (struct gkyl_dn2){sin(d1.x[0]), d1.x[1] * cos(d1.x[0]), d1.x[2] * cos(d1.x[0])}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_cos(struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_cos(struct gkyl_dn2 d1) { - return (struct gkyl_dn2) { cos(d1.x[0]), -d1.x[1]*sin(d1.x[0]), -d1.x[2]*sin(d1.x[0]) }; + return (struct gkyl_dn2){cos(d1.x[0]), -d1.x[1] * sin(d1.x[0]), -d1.x[2] * sin(d1.x[0])}; } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_tan(struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_tan(struct gkyl_dn2 d1) { return gdn2_div(gdn2_sin(d1), gdn2_cos(d1)); } -GKYL_CU_DH -static inline struct gkyl_dn2 -gdn2_log(struct gkyl_dn2 d1) +GKYL_CU_DH static inline struct gkyl_dn2 gdn2_log(struct gkyl_dn2 d1) { - return (struct gkyl_dn2) { log(d1.x[0]), d1.x[1]/d1.x[0], d1.x[2]/d1.x[0] }; + return (struct gkyl_dn2){log(d1.x[0]), d1.x[1] / d1.x[0], d1.x[2] / d1.x[0]}; } diff --git a/core/zero/gkyl_dynvec.h b/core/zero/gkyl_dynvec.h index ab14dc29a8..96a6671e87 100644 --- a/core/zero/gkyl_dynvec.h +++ b/core/zero/gkyl_dynvec.h @@ -7,7 +7,7 @@ #include /** Dynamic vector to store time-dependent diagnostics */ -typedef struct gkyl_dynvec_tag* gkyl_dynvec; +typedef struct gkyl_dynvec_tag *gkyl_dynvec; // Element type and number of components struct gkyl_dynvec_etype_ncomp { @@ -167,7 +167,9 @@ int gkyl_dynvec_write(const gkyl_dynvec vec, const char *fname); * @param fname Name of output file. * @return 0 if succeeded. */ -int gkyl_dynvec_write_wmeta(const gkyl_dynvec vec, const char *fname, const struct gkyl_msgpack_data *meta); +int gkyl_dynvec_write_wmeta( + const gkyl_dynvec vec, const char *fname, const struct gkyl_msgpack_data *meta +); /** * Write out dynvec to file. The dynvec is appened to the end of the @@ -206,8 +208,9 @@ bool gkyl_dynvec_read(gkyl_dynvec vec, const char *fname); * @param tm_mesh On output, time-mesh of data * @param dyndata On output, data in dynamic array */ -void gkyl_dynvec_to_array(const gkyl_dynvec vec, struct gkyl_array *tm_mesh, - struct gkyl_array *dyndata); +void gkyl_dynvec_to_array( + const gkyl_dynvec vec, struct gkyl_array *tm_mesh, struct gkyl_array *dyndata +); /** * Release dynvec. @@ -215,4 +218,3 @@ void gkyl_dynvec_to_array(const gkyl_dynvec vec, struct gkyl_array *tm_mesh, * @param vec Vector to release */ void gkyl_dynvec_release(gkyl_dynvec vec); - diff --git a/core/zero/gkyl_elem_type_priv.h b/core/zero/gkyl_elem_type_priv.h index be51d610ec..192f77feb5 100644 --- a/core/zero/gkyl_elem_type_priv.h +++ b/core/zero/gkyl_elem_type_priv.h @@ -2,44 +2,29 @@ #include - // code for array datatype for use in IO static const uint64_t gkyl_array_data_type[] = { - [GKYL_INT] = 0, - [GKYL_FLOAT] = 1, - [GKYL_DOUBLE] = 2, - [GKYL_INT_64] = 3, - [GKYL_LONG] = 4, - [GKYL_USER] = 32, + [GKYL_INT] = 0, [GKYL_FLOAT] = 1, [GKYL_DOUBLE] = 2, + [GKYL_INT_64] = 3, [GKYL_LONG] = 4, [GKYL_USER] = 32 }; // mapping of code to datatype: MUST be consistent with the // gkyl_array_data_type array above static const int gkyl_array_code_to_data_type[] = { - [0] = GKYL_INT, - [1] = GKYL_FLOAT, - [2] = GKYL_DOUBLE, - [3] = GKYL_INT_64, - [4] = GKYL_LONG, - [32] = GKYL_USER -}; + [0] = GKYL_INT, [1] = GKYL_FLOAT, [2] = GKYL_DOUBLE, + [3] = GKYL_INT_64, [4] = GKYL_LONG, [32] = GKYL_USER +}; // size in bytes for various data-types static const size_t gkyl_elem_type_size[] = { - [GKYL_INT] = sizeof(int), - [GKYL_FLOAT] = sizeof(float), - [GKYL_DOUBLE] = sizeof(double), - [GKYL_INT_64] = sizeof(int64_t), - [GKYL_LONG] = sizeof(long), - [GKYL_USER] = 1, + [GKYL_INT] = sizeof(int), [GKYL_FLOAT] = sizeof(float), [GKYL_DOUBLE] = sizeof(double), + [GKYL_INT_64] = sizeof(int64_t), [GKYL_LONG] = sizeof(long), [GKYL_USER] = 1 }; - static const uint64_t gkyl_file_type_int[] = { [GKYL_FIELD_DATA_FILE] = 1, [GKYL_DYNVEC_DATA_FILE] = 2, [GKYL_MULTI_RANGE_DATA_FILE] = 3, [GKYL_BLOCK_TOPO_DATA_FILE] = 4, - [GKYL_MULTI_BLOCK_DATA_FILE] = 5, + [GKYL_MULTI_BLOCK_DATA_FILE] = 5 }; - diff --git a/core/zero/gkyl_eqn_type.h b/core/zero/gkyl_eqn_type.h index 10e7da7cf6..93b1eedbea 100644 --- a/core/zero/gkyl_eqn_type.h +++ b/core/zero/gkyl_eqn_type.h @@ -2,14 +2,14 @@ // Identifiers for various equation systems enum gkyl_eqn_type { - GKYL_EQN_EULER, // Euler equations - GKYL_EQN_SR_EULER, // SR Euler equations + GKYL_EQN_EULER, // Euler equations + GKYL_EQN_SR_EULER, // SR Euler equations GKYL_EQN_ISO_EULER, // Isothermal Euler equations GKYL_EQN_COLDFLUID, // Cold fluid equations GKYL_EQN_COLDFLUID_SR, // Relativistic Cold fluid equations GKYL_EQN_TEN_MOMENT, // Ten-moment (with pressure tensor) GKYL_EQN_MAXWELL, // Maxwell equations - GKYL_EQN_MHD, // Ideal MHD equations + GKYL_EQN_MHD, // Ideal MHD equations GKYL_EQN_BURGERS, // Burgers equations GKYL_EQN_ADVECTION, // Scalar advection equation GKYL_EQN_GR_EULER, // General relativistic Euler equations with ideal gas equation of state. @@ -31,15 +31,16 @@ enum gkyl_eqn_type { GKYL_EQN_EULER_RGFM, // Euler Riemann ghost fluid equations. GKYL_EQN_CAN_PB_INCOMPRESS_EULER, // Canonical Poisson Bracket form of incompressible Euler. GKYL_EQN_CAN_PB_HASEGAWA_MIMA, // Canonical Poisson Bracket form of Hasegawa-Mima. - GKYL_EQN_CAN_PB_HASEGAWA_WAKATANI, // Canonical Poisson Bracket form of Hasegawa-Wakatani. + GKYL_EQN_CAN_PB_HASEGAWA_WAKATANI // Canonical Poisson Bracket form of Hasegawa-Wakatani. }; // Identifiers for specific gyrokinetic field object types. enum gkyl_gkfield_id { GKYL_GK_FIELD_ES = 0, // Electrostatic GK. This is default. - GKYL_GK_FIELD_BOLTZMANN = 1, // GK Boltzmann, isothermal electrons, phi = phi_sheath + (T_e/e)*ln(n_i/n_is). + GKYL_GK_FIELD_BOLTZMANN = + 1, // GK Boltzmann, isothermal electrons, phi = phi_sheath + (T_e/e)*ln(n_i/n_is). GKYL_GK_FIELD_ADIABATIC = 2, // GK field with an adiabatic species. - GKYL_GK_FIELD_EM = 4, // Electromagnetic GK. + GKYL_GK_FIELD_EM = 4 // Electromagnetic GK. }; // Identifiers for specific field object types. @@ -48,7 +49,7 @@ enum gkyl_field_id { GKYL_FIELD_PHI = 1, // Poisson (only phi). GKYL_FIELD_PHI_EXT_POTENTIALS = 2, // Poisson + external potentials (phi_ext, A_ext). GKYL_FIELD_PHI_EXT_FIELDS = 3, // Poisson + external fields (E_ext, B_ext). - GKYL_FIELD_NULL = 4, // no field is present. + GKYL_FIELD_NULL = 4 // no field is present. }; // Identifiers for subsidary models. @@ -57,7 +58,7 @@ enum gkyl_model_id { GKYL_MODEL_DEFAULT = 0, // No subsidiary model specified. GKYL_MODEL_SR = 1, GKYL_MODEL_CANONICAL_PB = 2, - GKYL_MODEL_CANONICAL_PB_GR = 3, + GKYL_MODEL_CANONICAL_PB_GR = 3 }; // Identifiers for specific collision object types. @@ -65,7 +66,7 @@ enum gkyl_collision_id { GKYL_NO_COLLISIONS = 0, // No collisions. This is default. GKYL_BGK_COLLISIONS, // BGK Collision operator. GKYL_LBO_COLLISIONS, // LBO Collision operator. - GKYL_FPO_COLLISIONS, // FPO Collision operator. + GKYL_FPO_COLLISIONS // FPO Collision operator. }; // Identifiers for specific source object types. @@ -81,7 +82,7 @@ enum gkyl_source_bgk_id { GKYL_NO_SOURCE_BGK = 0, // No source. This is default. GKYL_SOURCE_BGK_STATIC, // BGK source with user specified rate and eq. function. GKYL_SOURCE_BGK_HEATING, // Only energy source. - GKYL_SOURCE_BGK_EXTERNAL, // External particle, momentum, and energy source. + GKYL_SOURCE_BGK_EXTERNAL // External particle, momentum, and energy source. }; // Identifiers for specific projection object types @@ -91,15 +92,15 @@ enum gkyl_projection_id { GKYL_PROJ_MAXWELLIAN_LAB, // Maxwellian projection from lab moments (M0, M1, M2) GKYL_PROJ_BIMAXWELLIAN, // Bi-Maxwellian projection GKYL_PROJ_VLASOV_LTE, // LTE (Local thermodynamic equilibrium) projection for Vlasov - // (Maxwellian for non-relativistic, Maxwell-Juttner for relativistic) - GKYL_PROJ_MAXWELLIAN_GAUSSIAN, // Maxwellian in velocity space + Gaussian in configuration space + // (Maxwellian for non-relativistic, Maxwell-Juttner for relativistic) + GKYL_PROJ_MAXWELLIAN_GAUSSIAN // Maxwellian in velocity space + Gaussian in configuration space }; // Identifiers for specific radiation object types enum gkyl_radiation_id { GKYL_NO_RADIATION = 0, // No radiation. This is default GKYL_GK_RADIATION, // Radiation in gyrokinetic equations. - GKYL_VM_COMPTON_RADIATION, // Vlasov simple Compton radiation model. + GKYL_VM_COMPTON_RADIATION // Vlasov simple Compton radiation model. }; // Identifiers for specific reaction object types @@ -107,28 +108,29 @@ enum gkyl_react_id { GKYL_NO_REACT = 0, // No reactions. This is default GKYL_REACT_IZ, // Ionization. GKYL_REACT_CX, // Charge exchange. - GKYL_REACT_RECOMB, // Recombination. + GKYL_REACT_RECOMB // Recombination. }; enum gkyl_te_min_model { - GKYL_VARY_TE_CONSERVATIVE = 0, // Minimum temperature depends on V0, turns off at (relatively) high Te, so low chance of negative emissivity. This is default - GKYL_VARY_TE_AGGRESSIVE, // Minimum temperature depends on V0, turns off at (relatively) low Te, so higher chance of negative emissivity - GKYL_CONST_TE, // A constant minimum temperature, below which radiation is turned off + GKYL_VARY_TE_CONSERVATIVE = + 0, // Minimum temperature depends on V0, turns off at (relatively) high Te, so low chance of negative emissivity. This is default + GKYL_VARY_TE_AGGRESSIVE, // Minimum temperature depends on V0, turns off at (relatively) low Te, so higher chance of negative emissivity + GKYL_CONST_TE // A constant minimum temperature, below which radiation is turned off }; // Identifiers for different ion reaction types enum gkyl_ion_type { - GKYL_ION_H = 0, // Hydrogen ions - GKYL_ION_D = 1, // Deuterium ions (for CX) + GKYL_ION_H = 0, // Hydrogen ions + GKYL_ION_D = 1, // Deuterium ions (for CX) GKYL_ION_HE = 2, // Helium ions GKYL_ION_LI = 3, // Lithium ions GKYL_ION_BE = 4, // Beryllium ions - GKYL_ION_B = 5, // Boron ions - GKYL_ION_C = 6, // Carbon ions - GKYL_ION_N = 7, // Nitrogen ions - GKYL_ION_O = 8, // Oxygen ions + GKYL_ION_B = 5, // Boron ions + GKYL_ION_C = 6, // Carbon ions + GKYL_ION_N = 7, // Nitrogen ions + GKYL_ION_O = 8, // Oxygen ions GKYL_ION_NE = 9, // Neon ions - GKYL_ION_AR = 10, // Argon ions + GKYL_ION_AR = 10 // Argon ions }; // Identifiers for different self in reaction @@ -137,10 +139,10 @@ enum gkyl_ion_type { // - For RECOMB: GKYL_SELF_ELC, GKYL_SELF_ION, GKYL_SELF_RECVR. enum gkyl_react_self_type { GKYL_SELF_ELC = 0, // Electron species in reaction - GKYL_SELF_ION = 1, // Ion species in reaction + GKYL_SELF_ION = 1, // Ion species in reaction GKYL_SELF_DONOR = 2, // Donating species in reaction (giving up electron) GKYL_SELF_RECVR = 3, // Receiving species in reaction (receiving electron) - GKYL_SELF_PARTNER = 4, // Neutral species in CX + GKYL_SELF_PARTNER = 4 // Neutral species in CX }; // Identifiers for specific geometry types @@ -149,7 +151,7 @@ enum gkyl_geometry_id { GKYL_GEOMETRY_TOKAMAK, // Tokamak Geometry from Efit. GKYL_GEOMETRY_MIRROR, // Mirror Geometry from Efit. GKYL_GEOMETRY_MAPC2P, // General geometry from user provided mapc2p. - GKYL_GEOMETRY_FROMFILE, // Geometry from file. + GKYL_GEOMETRY_FROMFILE // Geometry from file. }; // type of quadrature to use @@ -160,22 +162,26 @@ enum gkyl_quad_type { }; /** Flags for indicating acting edge of velocity space */ -enum gkyl_vel_edge { - GKYL_VX_LOWER, GKYL_VY_LOWER, GKYL_VZ_LOWER, - GKYL_VX_UPPER, GKYL_VY_UPPER, GKYL_VZ_UPPER +enum gkyl_vel_edge { + GKYL_VX_LOWER, + GKYL_VY_LOWER, + GKYL_VZ_LOWER, + GKYL_VX_UPPER, + GKYL_VY_UPPER, + GKYL_VZ_UPPER }; // Identifiers for FLR models (in gyrokinetics). enum gkyl_gk_flr_type { GKYL_GK_FLR_NONE = 0, // No FLR effects. - GKYL_GK_FLR_PADE_CONST, // Pade-based approx. w/ const. rho_ts=sqrt(Tperp_s/m_s) + GKYL_GK_FLR_PADE_CONST // Pade-based approx. w/ const. rho_ts=sqrt(Tperp_s/m_s) }; // Gyrokinetic anomaous diffusion models. enum gkyl_gk_anomalous_diff_id { GKYL_GK_ANOMALOUS_DIFF_NONE = 0, // No anomalous diffusion. GKYL_GK_ANOMALOUS_DIFF_D, // Specify D only. - GKYL_GK_ANOMALOUS_DIFF_D_CHI, // Specify D and chi. + GKYL_GK_ANOMALOUS_DIFF_D_CHI // Specify D and chi. }; enum gkyl_gk_collisionless_type { @@ -186,5 +192,5 @@ enum gkyl_gk_collisionless_type { GKYL_GK_COLLISIONLESS_EM_BPAR, // Electromagnetic with B_par fluctuations. GKYL_GK_COLLISIONLESS_EM, // Electromagnetic with B_perp and B_par fluctuations. GKYL_GK_COLLISIONLESS_NEUTRAL, // Neutral collisionless terms. - GKYL_GK_COLLISIONLESS_PASSIVE, // Passive advection (for dev/debug). + GKYL_GK_COLLISIONLESS_PASSIVE // Passive advection (for dev/debug). }; diff --git a/core/zero/gkyl_eval_offset_fd.h b/core/zero/gkyl_eval_offset_fd.h index d13c7a48fc..2c7a340790 100644 --- a/core/zero/gkyl_eval_offset_fd.h +++ b/core/zero/gkyl_eval_offset_fd.h @@ -20,7 +20,7 @@ struct gkyl_eval_offset_fd_inp { int num_ret_vals; // number of return values in eval function struct gkyl_offset_descr *offsets; // size num_ret_vals - + evalf_t eval; // function to project void *ctx; // function context }; @@ -34,7 +34,7 @@ struct gkyl_eval_offset_fd_inp { * @param inp Input parameters * @return New updater pointer. */ -gkyl_eval_offset_fd* gkyl_eval_offset_fd_new(const struct gkyl_eval_offset_fd_inp *inp); +gkyl_eval_offset_fd *gkyl_eval_offset_fd_new(const struct gkyl_eval_offset_fd_inp *inp); /** * Compute function of nodes. The update_rng MUST be a sub-range of @@ -47,8 +47,10 @@ gkyl_eval_offset_fd* gkyl_eval_offset_fd_new(const struct gkyl_eval_offset_fd_in * @param update_rng Range on which to run projection. * @param out Output array */ -void gkyl_eval_offset_fd_advance(const gkyl_eval_offset_fd *up, - double tm, const struct gkyl_range *update_rng, struct gkyl_array *out); +void gkyl_eval_offset_fd_advance( + const gkyl_eval_offset_fd *up, double tm, const struct gkyl_range *update_rng, + struct gkyl_array *out +); /** * Delete updater. diff --git a/core/zero/gkyl_eval_on_nodes.h b/core/zero/gkyl_eval_on_nodes.h index b69f3af880..d95aaf86f1 100644 --- a/core/zero/gkyl_eval_on_nodes.h +++ b/core/zero/gkyl_eval_on_nodes.h @@ -19,7 +19,7 @@ struct gkyl_eval_on_nodes_inp { void *ctx; // Context for function evaluation. Can be NULL. eval_on_nodes_c2p_t c2p_func; // Function that transforms a set of ndim - // computational coordinates to physical ones. + // computational coordinates to physical ones. void *c2p_func_ctx; // Context for c2p_func. }; @@ -31,7 +31,7 @@ struct gkyl_eval_on_nodes_inp { * @param inp Input parameters * @return New updater pointer. */ -gkyl_eval_on_nodes* gkyl_eval_on_nodes_inew(const struct gkyl_eval_on_nodes_inp *inp); +gkyl_eval_on_nodes *gkyl_eval_on_nodes_inew(const struct gkyl_eval_on_nodes_inp *inp); /** * Create new updater to compute function on nodes and calculate its @@ -45,9 +45,10 @@ gkyl_eval_on_nodes* gkyl_eval_on_nodes_inew(const struct gkyl_eval_on_nodes_inp * @param ctx Context for function evaluation. Can be NULL. * @return New updater pointer. */ -gkyl_eval_on_nodes* gkyl_eval_on_nodes_new( - const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, - int num_ret_vals, evalf_t eval, void *ctx); +gkyl_eval_on_nodes *gkyl_eval_on_nodes_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, int num_ret_vals, evalf_t eval, + void *ctx +); /** * Compute evaluation on nodes and corresponding expansion @@ -61,8 +62,10 @@ gkyl_eval_on_nodes* gkyl_eval_on_nodes_new( * @param update_rng Range on which to run eval. * @param out Output array */ -void gkyl_eval_on_nodes_advance(const gkyl_eval_on_nodes *up, - double tm, const struct gkyl_range *update_rng, struct gkyl_array *out); +void gkyl_eval_on_nodes_advance( + const gkyl_eval_on_nodes *up, double tm, const struct gkyl_range *update_rng, + struct gkyl_array *out +); /** * Perform the nodal to modal transformation. @@ -71,7 +74,9 @@ void gkyl_eval_on_nodes_advance(const gkyl_eval_on_nodes *up, * @param fun_at_nodes Function evaluated at nodes in one cell. * @param f Modal coefficients of the function in one cell. */ -void gkyl_eval_on_nodes_nod2mod(const gkyl_eval_on_nodes *up, const struct gkyl_array *fun_at_nodes, double *f); +void gkyl_eval_on_nodes_nod2mod( + const gkyl_eval_on_nodes *up, const struct gkyl_array *fun_at_nodes, double *f +); /** * Get the coordinates of a given node. @@ -80,7 +85,7 @@ void gkyl_eval_on_nodes_nod2mod(const gkyl_eval_on_nodes *up, const struct gkyl_ * @param node Index indicate the desired node. * @return Node coordinates. */ -double* gkyl_eval_on_nodes_fetch_node(const gkyl_eval_on_nodes *up, long node); +double *gkyl_eval_on_nodes_fetch_node(const gkyl_eval_on_nodes *up, long node); /** * Delete updater. diff --git a/core/zero/gkyl_evalf_def.h b/core/zero/gkyl_evalf_def.h index e687463cce..b1806bfac8 100644 --- a/core/zero/gkyl_evalf_def.h +++ b/core/zero/gkyl_evalf_def.h @@ -25,7 +25,9 @@ typedef void (*evalf_t)(double t, const double *xn, double *fout, void *ctx); * @param ghost Pointer to data in ghost-cell * @param ctx Context for function evaluation. Can be NULL */ -typedef void (*wv_bc_func_t)(const struct gkyl_wv_eqn* eqn, double t, int ncomp, const double* skin, double* ghost, void* ctx); +typedef void (*wv_bc_func_t)( + const struct gkyl_wv_eqn *eqn, double t, int ncomp, const double *skin, double *ghost, void *ctx +); /** * Type of function for use in array copy op. @@ -45,5 +47,4 @@ typedef void (*array_copy_func_t)(size_t nc, double *out, const double *inp, voi * @param delta Difference across surface. * @param ctx Context for function evaluation. Can be NULL */ -typedef void (*wv_embed_func_t)(const double *q, double *qphi, double *delta, - void *ctx); +typedef void (*wv_embed_func_t)(const double *q, double *qphi, double *delta, void *ctx); diff --git a/core/zero/gkyl_fv_proj.h b/core/zero/gkyl_fv_proj.h index c4c388a47a..9c2cb49e65 100644 --- a/core/zero/gkyl_fv_proj.h +++ b/core/zero/gkyl_fv_proj.h @@ -16,8 +16,9 @@ typedef struct gkyl_proj_on_basis gkyl_fv_proj; * @param ctx Context for function evaluation. Can be NULL. * @return New updater pointer. */ -gkyl_fv_proj* gkyl_fv_proj_new(const struct gkyl_rect_grid *grid, - int num_quad, int num_ret_vals, evalf_t eval, void *ctx); +gkyl_fv_proj *gkyl_fv_proj_new( + const struct gkyl_rect_grid *grid, int num_quad, int num_ret_vals, evalf_t eval, void *ctx +); /** * Compute cell averages. The update_rng MUST be a sub-range of @@ -30,12 +31,13 @@ gkyl_fv_proj* gkyl_fv_proj_new(const struct gkyl_rect_grid *grid, * @param update_rng Range on which to run projection. * @param out Output array */ -void gkyl_fv_proj_advance(const gkyl_fv_proj *pob, - double tm, const struct gkyl_range *update_rng, struct gkyl_array *out); +void gkyl_fv_proj_advance( + const gkyl_fv_proj *pob, double tm, const struct gkyl_range *update_rng, struct gkyl_array *out +); /** * Delete updater. * * @param pob Updater to delete. */ -void gkyl_fv_proj_release(gkyl_fv_proj* pob); +void gkyl_fv_proj_release(gkyl_fv_proj *pob); diff --git a/core/zero/gkyl_gauss_quad_data.h b/core/zero/gkyl_gauss_quad_data.h index abe3d09349..93e517751c 100644 --- a/core/zero/gkyl_gauss_quad_data.h +++ b/core/zero/gkyl_gauss_quad_data.h @@ -7,44 +7,62 @@ enum { gkyl_gauss_max = 8 }; // Ordinates -static const double gkyl_gauss_ordinates_1[] = -{ 0.0 }; -static const double gkyl_gauss_ordinates_2[] = -{ -0.5773502691896257645091, 0.5773502691896257645091 }; -static const double gkyl_gauss_ordinates_3[] = -{ -0.7745966692414833770359, 0, 0.7745966692414833770359 }; -static const double gkyl_gauss_ordinates_4[] = -{ -0.8611363115940525752239, -0.3399810435848562648027, 0.3399810435848562648027, 0.8611363115940525752239 }; -static const double gkyl_gauss_ordinates_5[] = -{ -0.9061798459386639927976, -0.5384693101056830910363, 0, 0.5384693101056830910363, 0.9061798459386639927976 }; -static const double gkyl_gauss_ordinates_6[] = -{ -0.9324695142031520278123, -0.6612093864662645136614, -0.2386191860831969086305, 0.2386191860831969086305, 0.6612093864662645136614, 0.9324695142031520278123 }; -static const double gkyl_gauss_ordinates_7[] = -{ -0.9491079123427585245262, -0.7415311855993944398639, -0.4058451513773971669066, 0, 0.4058451513773971669066, 0.7415311855993944398639, 0.9491079123427585245262 }; -static const double gkyl_gauss_ordinates_8[] = -{ -0.960289856497536231684, -0.7966664774136267395916, -0.5255324099163289858177, -0.1834346424956498049395, 0.1834346424956498049395, 0.525532409916328985818, 0.796666477413626739592, 0.9602898564975362316836 }; +static const double gkyl_gauss_ordinates_1[] = {0.0}; +static const double gkyl_gauss_ordinates_2[] = {-0.5773502691896257645091, 0.5773502691896257645091}; +static const double gkyl_gauss_ordinates_3[] = { + -0.7745966692414833770359, 0, 0.7745966692414833770359 +}; +static const double gkyl_gauss_ordinates_4[] = { + -0.8611363115940525752239, -0.3399810435848562648027, 0.3399810435848562648027, + 0.8611363115940525752239 +}; +static const double gkyl_gauss_ordinates_5[] = { + -0.9061798459386639927976, -0.5384693101056830910363, 0, 0.5384693101056830910363, + 0.9061798459386639927976 +}; +static const double gkyl_gauss_ordinates_6[] = { + -0.9324695142031520278123, -0.6612093864662645136614, -0.2386191860831969086305, + 0.2386191860831969086305, 0.6612093864662645136614, 0.9324695142031520278123 +}; +static const double gkyl_gauss_ordinates_7[] = { + -0.9491079123427585245262, -0.7415311855993944398639, -0.4058451513773971669066, 0, + 0.4058451513773971669066, 0.7415311855993944398639, 0.9491079123427585245262 +}; +static const double gkyl_gauss_ordinates_8[] = { + -0.960289856497536231684, -0.7966664774136267395916, -0.5255324099163289858177, + -0.1834346424956498049395, 0.1834346424956498049395, 0.525532409916328985818, + 0.796666477413626739592, 0.9602898564975362316836 +}; // Weights -static const double gkyl_gauss_weights_1[] = -{ 2.0 }; -static const double gkyl_gauss_weights_2[] = -{ 1.0, 1.0 }; -static const double gkyl_gauss_weights_3[] = -{ 0.5555555555555555555556, 0.888888888888888888889, 0.555555555555555555556 }; -static const double gkyl_gauss_weights_4[] = -{ 0.3478548451374538573731, 0.6521451548625461426269, 0.652145154862546142627, 0.3478548451374538573731 }; -static const double gkyl_gauss_weights_5[] = -{ 0.2369268850561890875143, 0.4786286704993664680413, 0.568888888888888888889, 0.478628670499366468041, 0.236926885056189087514 }; -static const double gkyl_gauss_weights_6[] = -{ 0.1713244923791703450403, 0.36076157304813860757, 0.46791393457269104739, 0.46791393457269104739, 0.36076157304813860757, 0.1713244923791703450403 }; -static const double gkyl_gauss_weights_7[] = -{ 0.1294849661688696932706, 0.279705391489276667901, 0.38183005050511894495, 0.4179591836734693877552, 0.38183005050511894495, 0.279705391489276667901, 0.1294849661688696932706 }; -static const double gkyl_gauss_weights_8[] = -{ 0.1012285362903762591525, 0.222381034453374470544, 0.313706645877887287338, 0.3626837833783619829652, 0.3626837833783619829652, 0.31370664587788728734, 0.222381034453374470544, 0.1012285362903762591525 }; +static const double gkyl_gauss_weights_1[] = {2.0}; +static const double gkyl_gauss_weights_2[] = {1.0, 1.0}; +static const double gkyl_gauss_weights_3[] = { + 0.5555555555555555555556, 0.888888888888888888889, 0.555555555555555555556 +}; +static const double gkyl_gauss_weights_4[] = { + 0.3478548451374538573731, 0.6521451548625461426269, 0.652145154862546142627, + 0.3478548451374538573731 +}; +static const double gkyl_gauss_weights_5[] = { + 0.2369268850561890875143, 0.4786286704993664680413, 0.568888888888888888889, + 0.478628670499366468041, 0.236926885056189087514 +}; +static const double gkyl_gauss_weights_6[] = {0.1713244923791703450403, 0.36076157304813860757, + 0.46791393457269104739, 0.46791393457269104739, + 0.36076157304813860757, 0.1713244923791703450403}; +static const double gkyl_gauss_weights_7[] = {0.1294849661688696932706, 0.279705391489276667901, + 0.38183005050511894495, 0.4179591836734693877552, + 0.38183005050511894495, 0.279705391489276667901, + 0.1294849661688696932706}; +static const double gkyl_gauss_weights_8[] = {0.1012285362903762591525, 0.222381034453374470544, + 0.313706645877887287338, 0.3626837833783619829652, + 0.3626837833783619829652, 0.31370664587788728734, + 0.222381034453374470544, 0.1012285362903762591525}; // gkyl_gauss_ordinates[N] are ordinates for N-point Guassian // integration -static const double* gkyl_gauss_ordinates[] = { +static const double *gkyl_gauss_ordinates[] = { 0, // N=0 makes no sense, gkyl_gauss_ordinates_1, gkyl_gauss_ordinates_2, @@ -69,44 +87,60 @@ static const double *gkyl_gauss_weights[] = { gkyl_gauss_weights_8 }; - // Lobatto quadrature // Ordinates -static const double gkyl_gauss_lobatto_ordinates_2[] = -{ -1.0,1.0 }; -static const double gkyl_gauss_lobatto_ordinates_3[] = -{ -1.0,0.0,1.0 }; -static const double gkyl_gauss_lobatto_ordinates_4[] = -{ -1.0,-0.4472135954999579,0.4472135954999579,1.0 }; -static const double gkyl_gauss_lobatto_ordinates_5[] = -{ -1.0,-0.6546536707079771,0.0,0.6546536707079771,1.0 }; -static const double gkyl_gauss_lobatto_ordinates_6[] = -{ -1.0,-0.7650553239294646,-0.285231516480645,0.285231516480645,0.7650553239294646,1.0 }; -static const double gkyl_gauss_lobatto_ordinates_7[] = -{ -1.0,-0.8302238962785669,-0.4688487934707142,0.0,0.4688487934707142,0.8302238962785669,1.0 }; -static const double gkyl_gauss_lobatto_ordinates_8[] = -{ -1.0,-0.8717401485096066,-0.5917001814331423,-0.2092992179024789,0.2092992179024789,0.5917001814331423,0.8717401485096066,1.0 }; +static const double gkyl_gauss_lobatto_ordinates_2[] = {-1.0, 1.0}; +static const double gkyl_gauss_lobatto_ordinates_3[] = {-1.0, 0.0, 1.0}; +static const double gkyl_gauss_lobatto_ordinates_4[] = { + -1.0, -0.4472135954999579, 0.4472135954999579, 1.0 +}; +static const double gkyl_gauss_lobatto_ordinates_5[] = { + -1.0, -0.6546536707079771, 0.0, 0.6546536707079771, 1.0 +}; +static const double gkyl_gauss_lobatto_ordinates_6[] = { + -1.0, -0.7650553239294646, -0.285231516480645, 0.285231516480645, 0.7650553239294646, 1.0 +}; +static const double gkyl_gauss_lobatto_ordinates_7[] = { + -1.0, -0.8302238962785669, -0.4688487934707142, 0.0, 0.4688487934707142, 0.8302238962785669, 1.0 +}; +static const double gkyl_gauss_lobatto_ordinates_8[] = { + -1.0, + -0.8717401485096066, + -0.5917001814331423, + -0.2092992179024789, + 0.2092992179024789, + 0.5917001814331423, + 0.8717401485096066, + 1.0 +}; // Weights -static const double gkyl_gauss_lobatto_weights_2[] = -{ 1.0,1.0 }; -static const double gkyl_gauss_lobatto_weights_3[] = -{ 0.3333333333333333,1.333333333333333,0.3333333333333333 }; -static const double gkyl_gauss_lobatto_weights_4[] = -{ 0.1666666666666667,0.8333333333333334,0.8333333333333334,0.1666666666666667 }; -static const double gkyl_gauss_lobatto_weights_5[] = -{ 0.1,0.5444444444444444,0.7111111111111111,0.5444444444444444,0.1 }; -static const double gkyl_gauss_lobatto_weights_6[] = -{ 0.06666666666666667,0.378474956297847,0.5548583770354863,0.5548583770354863,0.378474956297847,0.06666666666666667 }; -static const double gkyl_gauss_lobatto_weights_7[] = -{ 0.04761904761904762,0.276826047361566,0.4317453812098626,0.4876190476190476,0.4317453812098626,0.276826047361566,0.04761904761904762 }; -static const double gkyl_gauss_lobatto_weights_8[] = -{ 0.03571428571428571,0.210704227143506,0.3411226924835044,0.4124587946587039,0.4124587946587039,0.3411226924835044,0.210704227143506,0.03571428571428571 }; +static const double gkyl_gauss_lobatto_weights_2[] = {1.0, 1.0}; +static const double gkyl_gauss_lobatto_weights_3[] = { + 0.3333333333333333, 1.333333333333333, 0.3333333333333333 +}; +static const double gkyl_gauss_lobatto_weights_4[] = { + 0.1666666666666667, 0.8333333333333334, 0.8333333333333334, 0.1666666666666667 +}; +static const double gkyl_gauss_lobatto_weights_5[] = { + 0.1, 0.5444444444444444, 0.7111111111111111, 0.5444444444444444, 0.1 +}; +static const double gkyl_gauss_lobatto_weights_6[] = {0.06666666666666667, 0.378474956297847, + 0.5548583770354863, 0.5548583770354863, + 0.378474956297847, 0.06666666666666667}; +static const double gkyl_gauss_lobatto_weights_7[] = {0.04761904761904762, 0.276826047361566, + 0.4317453812098626, 0.4876190476190476, + 0.4317453812098626, 0.276826047361566, + 0.04761904761904762}; +static const double gkyl_gauss_lobatto_weights_8[] = {0.03571428571428571, 0.210704227143506, + 0.3411226924835044, 0.4124587946587039, + 0.4124587946587039, 0.3411226924835044, + 0.210704227143506, 0.03571428571428571}; // gkyl_gauss_lobatto_ordinates[N] are ordinates for N-point // Guass-Lobatto integration -static const double* gkyl_gauss_lobatto_ordinates[] = { +static const double *gkyl_gauss_lobatto_ordinates[] = { 0, // N=0 makes no sense, 0, // N=1 makes no sense, gkyl_gauss_lobatto_ordinates_2, @@ -122,7 +156,7 @@ static const double* gkyl_gauss_lobatto_ordinates[] = { // integration static const double *gkyl_gauss_lobatto_weights[] = { 0, // N=0 makes no sense, - 0, // N=1 makes no sense, + 0, // N=1 makes no sense, gkyl_gauss_lobatto_weights_2, gkyl_gauss_lobatto_weights_3, gkyl_gauss_lobatto_weights_4, @@ -141,7 +175,7 @@ static const double *gkyl_gauss_lobatto_weights[] = { * @param w On output, weights. * @param n Order of the quadrature. */ -void gkyl_gauleg(double x1, double x2, double x[], double w[], int n); +void gkyl_gauleg(double x1, double x2, double x[], double w[], int n); /** * Compute ordinates and weights for use in n-dimensiona Gaussian diff --git a/core/zero/gkyl_gauss_quad_utilities_priv.h b/core/zero/gkyl_gauss_quad_utilities_priv.h index b1bc7c9065..f154d4e241 100644 --- a/core/zero/gkyl_gauss_quad_utilities_priv.h +++ b/core/zero/gkyl_gauss_quad_utilities_priv.h @@ -5,9 +5,12 @@ #include // create range to loop over quadrature points. -static inline struct gkyl_range get_qrange(int dim, int num_quad) { +static inline struct gkyl_range get_qrange(int dim, int num_quad) +{ int qshape[GKYL_MAX_DIM]; - for (int i=0; indim; double ordinates1[num_quad], weights1[num_quad]; @@ -27,8 +31,7 @@ init_quad_values(const struct gkyl_basis *basis, int num_quad, // than computing them on the fly) memcpy(ordinates1, gkyl_gauss_ordinates[num_quad], sizeof(double[num_quad])); memcpy(weights1, gkyl_gauss_weights[num_quad], sizeof(double[num_quad])); - } - else { + } else { gkyl_gauleg(-1, 1, ordinates1, weights1, num_quad); } @@ -53,24 +56,28 @@ init_quad_values(const struct gkyl_basis *basis, int num_quad, // set ordinates double *ord = gkyl_array_fetch(ordinates_ho, node); - for (int i=0; inum_basis, tot_quad); - if (use_gpu) + if (use_gpu) { *basis_at_ords = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis->num_basis, tot_quad); - else + } else { *basis_at_ords = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, tot_quad); - for (int n=0; neval(gkyl_array_fetch(ordinates_ho, n), gkyl_array_fetch(basis_at_ords_ho, n)); + } // copy host array to device array gkyl_array_copy(*weights, weights_ho); diff --git a/core/zero/gkyl_job_pool.h b/core/zero/gkyl_job_pool.h index 64d590ed19..2c14fb4b6a 100644 --- a/core/zero/gkyl_job_pool.h +++ b/core/zero/gkyl_job_pool.h @@ -5,7 +5,7 @@ // forward declare for use in function pointers struct gkyl_job_pool; -// Function pointer sig for function that does the actual work +// Function pointer sig for function that does the actual work typedef void (*jp_work_func)(void *ctx); // Function sig that adds work to the pool @@ -19,7 +19,7 @@ struct gkyl_job_pool { jp_add_work add_work; // function to add work to pool jp_wait wait; // function to wait for jobs to finish - struct gkyl_ref_count ref_count; // reference count + struct gkyl_ref_count ref_count; // reference count }; /** @@ -45,11 +45,11 @@ void gkyl_job_pool_wait(const struct gkyl_job_pool *jp); * * @param jp Job-pool object. */ -struct gkyl_job_pool* gkyl_job_pool_acquire(const struct gkyl_job_pool *jp); +struct gkyl_job_pool *gkyl_job_pool_acquire(const struct gkyl_job_pool *jp); /** * Delete job-pool object * * @param jp Object to delete. */ -void gkyl_job_pool_release(const struct gkyl_job_pool* jp); +void gkyl_job_pool_release(const struct gkyl_job_pool *jp); diff --git a/core/zero/gkyl_kann_net.h b/core/zero/gkyl_kann_net.h index 059a24dbe5..ef2d4a61ea 100644 --- a/core/zero/gkyl_kann_net.h +++ b/core/zero/gkyl_kann_net.h @@ -19,11 +19,11 @@ struct gkyl_kann_net; * Hyperparameters for training a feed-forward network. */ struct gkyl_kann_train_params { - float learning_rate; // learning rate for RMSprop - int mini_size; // mini-batch size - int max_epoch; // maximum number of training epochs - int max_drop_streak; // max epochs without validation improvement - float frac_val; // fraction of samples used for validation + float learning_rate; // learning rate for RMSprop + int mini_size; // mini-batch size + int max_epoch; // maximum number of training epochs + int max_drop_streak; // max epochs without validation improvement + float frac_val; // fraction of samples used for validation }; /** @@ -35,7 +35,7 @@ struct gkyl_kann_train_params { * @param use_gpu If true, allocate network data on GPU * @return New network wrapper, or NULL on failure */ -struct gkyl_kann_net* gkyl_kann_net_new(kad_node_t *cost, bool use_gpu); +struct gkyl_kann_net *gkyl_kann_net_new(kad_node_t *cost, bool use_gpu); /** * Load a previously saved KANN network from file. @@ -44,7 +44,7 @@ struct gkyl_kann_net* gkyl_kann_net_new(kad_node_t *cost, bool use_gpu); * @param use_gpu If true, allocate network data on GPU * @return Loaded network wrapper, or NULL on failure */ -struct gkyl_kann_net* gkyl_kann_net_load(const char *filename, bool use_gpu); +struct gkyl_kann_net *gkyl_kann_net_load(const char *filename, bool use_gpu); /** * Save the network to file. If the network is on GPU, weights are @@ -65,9 +65,10 @@ void gkyl_kann_net_save(const struct gkyl_kann_net *net, const char *filename); * @param out Training output vectors (nvec samples, each of length N) * @return Number of epochs completed */ -int gkyl_kann_net_train_fnn1(struct gkyl_kann_net *net, - const struct gkyl_kann_train_params *params, - const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out); +int gkyl_kann_net_train_fnn1( + struct gkyl_kann_net *net, const struct gkyl_kann_train_params *params, + const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out +); /** * Run inference on a batch of input vectors. @@ -77,8 +78,9 @@ int gkyl_kann_net_train_fnn1(struct gkyl_kann_net *net, * @param out Output vectors (nvec samples, each of length N = n_out). * Filled by this function. */ -void gkyl_kann_net_apply(struct gkyl_kann_net *net, - const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out); +void gkyl_kann_net_apply( + struct gkyl_kann_net *net, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out +); /** * Run sequential RNN inference over a sequence of input vectors. @@ -92,8 +94,9 @@ void gkyl_kann_net_apply(struct gkyl_kann_net *net, * @param out Output vectors (nvec timesteps, each of length N = n_out). * Filled by this function. */ -void gkyl_kann_net_apply_rnn(struct gkyl_kann_net *net, - const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out); +void gkyl_kann_net_apply_rnn( + struct gkyl_kann_net *net, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out +); /** * Get the input dimension of the network (number of floats per input @@ -135,7 +138,7 @@ bool gkyl_kann_net_is_cu_dev(const struct gkyl_kann_net *net); * @param net Network to acquire * @return Pointer to acquired network */ -struct gkyl_kann_net* gkyl_kann_net_acquire(const struct gkyl_kann_net *net); +struct gkyl_kann_net *gkyl_kann_net_acquire(const struct gkyl_kann_net *net); /** * Release a reference to the network. When the reference count diff --git a/core/zero/gkyl_kann_net_cu_priv.h b/core/zero/gkyl_kann_net_cu_priv.h index 076bb0bd8c..cd800ab00a 100644 --- a/core/zero/gkyl_kann_net_cu_priv.h +++ b/core/zero/gkyl_kann_net_cu_priv.h @@ -14,83 +14,83 @@ // Per-node metadata in the flattened graph (fixed-size, GPU-friendly) struct kann_cu_node { - uint16_t op; // operator index - uint8_t n_d; // number of dimensions - uint8_t flag; // KAD_VAR, KAD_CONST, etc. - int32_t n_child; // number of children + uint16_t op; // operator index + uint8_t n_d; // number of dimensions + uint8_t flag; // KAD_VAR, KAD_CONST, etc. + int32_t n_child; // number of children int32_t child_idx[KANN_CU_MAX_CHILD]; // indices of children in node array - int32_t d[KAD_MAX_DIM]; // dimensions - int32_t x_off; // offset into flat x (value) buffer - int32_t g_off; // offset into flat g (gradient) buffer - int32_t len; // current number of floats (product of dims) - int32_t ptr_i32; // integer parameter (e.g. select index) - uint32_t ext_flag; // external flags (KANN_F_IN, etc.) - int32_t ext_label; // external label - int32_t pre_idx; // index of pre-linked node (-1 if none) - int32_t si_off; // offset into stdnorm_si buffer (-1 if not stdnorm) + int32_t d[KAD_MAX_DIM]; // dimensions + int32_t x_off; // offset into flat x (value) buffer + int32_t g_off; // offset into flat g (gradient) buffer + int32_t len; // current number of floats (product of dims) + int32_t ptr_i32; // integer parameter (e.g. select index) + uint32_t ext_flag; // external flags (KANN_F_IN, etc.) + int32_t ext_label; // external label + int32_t pre_idx; // index of pre-linked node (-1 if none) + int32_t si_off; // offset into stdnorm_si buffer (-1 if not stdnorm) }; // Per-variable-node metadata for scattered upload/download/RMSprop struct kann_cu_var_node { - int x_off; // offset of this variable's data in the flat x buffer - int g_off; // offset of this variable's gradient in the flat g buffer - int r_off; // offset into the RMSprop accumulator buffer - int len; // number of floats in this variable node + int x_off; // offset of this variable's data in the flat x buffer + int g_off; // offset of this variable's gradient in the flat g buffer + int r_off; // offset into the RMSprop accumulator buffer + int len; // number of floats in this variable node }; // The complete flattened graph living on GPU struct kann_cu_graph { - int n_node; // total number of nodes - struct kann_cu_node *nodes; // device array [n_node] of node metadata - struct kann_cu_node *h_nodes; // host mirror of node metadata (persistent) + int n_node; // total number of nodes + struct kann_cu_node *nodes; // device array [n_node] of node metadata + struct kann_cu_node *h_nodes; // host mirror of node metadata (persistent) - float *x; // device buffer for all node values - float *g; // device buffer for all node gradients - int x_total; // total floats in x buffer (at max batch) - int g_total; // total floats in g buffer (at max batch) + float *x; // device buffer for all node values + float *g; // device buffer for all node gradients + int x_total; // total floats in x buffer (at max batch) + int g_total; // total floats in g buffer (at max batch) // Per-variable-node scatter info (variables are NOT contiguous in x buf) struct kann_cu_var_node *h_vars; // host array [n_var_nodes] - int n_var_nodes; // number of variable nodes - int n_var; // total number of trainable variable floats + int n_var_nodes; // number of variable nodes + int n_var; // total number of trainable variable floats // Per-constant-node scatter info struct kann_cu_var_node *h_consts; // host array [n_const_nodes] - int n_const_nodes; // number of constant nodes - int n_const; // total number of constant floats + int n_const_nodes; // number of constant nodes + int n_const; // total number of constant floats // Training support - float *r; // device buffer for RMSprop running average [n_var] + float *r; // device buffer for RMSprop running average [n_var] // Feed node bookkeeping - int in_node_idx; // index of the input feed node - int truth_node_idx; // index of the truth feed node - int cost_node_idx; // index of the cost node - int out_node_idx; // index of the output node + int in_node_idx; // index of the input feed node + int truth_node_idx; // index of the truth feed node + int cost_node_idx; // index of the cost node + int out_node_idx; // index of the output node // Topological order for forward/backward - int *h_fwd_order; // host array: internal node indices in forward order - int *h_bwd_order; // host array: internal node indices in backward order - int n_internal; // number of internal (non-leaf) nodes + int *h_fwd_order; // host array: internal node indices in forward order + int *h_bwd_order; // host array: internal node indices in backward order + int n_internal; // number of internal (non-leaf) nodes // Stdnorm (layer normalization, op 32) support - float *stdnorm_si; // device buffer for per-row std_inv cache - int stdnorm_si_total; // total floats in stdnorm_si buffer + float *stdnorm_si; // device buffer for per-row std_inv cache + int stdnorm_si_total; // total floats in stdnorm_si buffer // RNN pre-linkage: pairs of (output_node_idx, h0_node_idx) // After forward, copy output's x to h0's x for recurrence - int *h_pre_pairs; // host array [2 * n_pre_pairs] - int n_pre_pairs; // number of pre-linked node pairs + int *h_pre_pairs; // host array [2 * n_pre_pairs] + int n_pre_pairs; // number of pre-linked node pairs // Batch size tracking - int max_batch_size; // batch size used for buffer allocation - int cur_batch_size; // current batch size + int max_batch_size; // batch size used for buffer allocation + int cur_batch_size; // current batch size }; // Build a flattened GPU graph from a host-side kann_t. // The host graph should be synced to max_batch_size via kad_sync_dim first. // Allocates device buffers sized for these dimensions. -struct kann_cu_graph* kann_cu_graph_new(kann_t *ann, int max_batch_size); +struct kann_cu_graph *kann_cu_graph_new(kann_t *ann, int max_batch_size); // Free all device and host memory associated with the flattened graph. void kann_cu_graph_free(struct kann_cu_graph *g); @@ -129,16 +129,19 @@ void kann_cu_feed_truth(struct kann_cu_graph *g, int batch_size, const float *y_ // Gather mini-batch from device dataset into input feed node. // indices_d is a device array of sample indices; offset is where in // indices_d the current mini-batch starts. -void kann_cu_gather_input(struct kann_cu_graph *g, const float *data_d, - const int *indices_d, int offset, int batch_size, int stride); +void kann_cu_gather_input( + struct kann_cu_graph *g, const float *data_d, const int *indices_d, int offset, int batch_size, + int stride +); // Gather mini-batch from device dataset into truth feed node. -void kann_cu_gather_truth(struct kann_cu_graph *g, const float *data_d, - const int *indices_d, int offset, int batch_size, int stride); +void kann_cu_gather_truth( + struct kann_cu_graph *g, const float *data_d, const int *indices_d, int offset, int batch_size, + int stride +); // Feed input data directly from a device pointer (contiguous batch). -void kann_cu_feed_input_dev(struct kann_cu_graph *g, int batch_size, - const float *x_dev, int stride); +void kann_cu_feed_input_dev(struct kann_cu_graph *g, int batch_size, const float *x_dev, int stride); // Read back cost scalar from device. float kann_cu_get_cost(const struct kann_cu_graph *g); diff --git a/core/zero/gkyl_kann_net_priv.h b/core/zero/gkyl_kann_net_priv.h index 6a48719ad0..a2329b66b9 100644 --- a/core/zero/gkyl_kann_net_priv.h +++ b/core/zero/gkyl_kann_net_priv.h @@ -8,18 +8,18 @@ #endif struct gkyl_kann_net { - kann_t *ann; // underlying KANN network + kann_t *ann; // underlying KANN network - int n_var; // number of trainable variable floats - int n_const; // number of constant floats - int n_in; // input dimension (per sample) - int n_out; // output dimension (per sample) + int n_var; // number of trainable variable floats + int n_const; // number of constant floats + int n_in; // input dimension (per sample) + int n_out; // output dimension (per sample) uint32_t flags; struct gkyl_ref_count ref_count; #ifdef GKYL_HAVE_CUDA - cublasHandle_t cublas_h; // persistent cuBLAS handle (GPU only) - struct kann_cu_graph *cg; // flattened graph on device (GPU only) + cublasHandle_t cublas_h; // persistent cuBLAS handle (GPU only) + struct kann_cu_graph *cg; // flattened graph on device (GPU only) #endif }; diff --git a/core/zero/gkyl_knutils.h b/core/zero/gkyl_knutils.h index 8234cddd43..5244fc757b 100644 --- a/core/zero/gkyl_knutils.h +++ b/core/zero/gkyl_knutils.h @@ -27,7 +27,7 @@ struct gkyl_kn_vec { * @param N Length of each vector * @return New kn_vec */ -struct gkyl_kn_vec* gkyl_kn_vec_new(int nvec, int N); +struct gkyl_kn_vec *gkyl_kn_vec_new(int nvec, int N); /** * Create a new device kn_vec. The data member lives on GPU. @@ -37,7 +37,7 @@ struct gkyl_kn_vec* gkyl_kn_vec_new(int nvec, int N); * @param N Length of each vector * @return New device kn_vec */ -struct gkyl_kn_vec* gkyl_kn_vec_cu_dev_new(int nvec, int N); +struct gkyl_kn_vec *gkyl_kn_vec_cu_dev_new(int nvec, int N); /** * Copy data between kn_vecs. Direction (H2D, D2H, D2D, H2H) is @@ -47,8 +47,7 @@ struct gkyl_kn_vec* gkyl_kn_vec_cu_dev_new(int nvec, int N); * @param src Source kn_vec * @return dest */ -struct gkyl_kn_vec* gkyl_kn_vec_copy(struct gkyl_kn_vec *dest, - const struct gkyl_kn_vec *src); +struct gkyl_kn_vec *gkyl_kn_vec_copy(struct gkyl_kn_vec *dest, const struct gkyl_kn_vec *src); /** * Check if a kn_vec has device data. @@ -64,7 +63,7 @@ bool gkyl_kn_vec_is_cu_dev(const struct gkyl_kn_vec *vec); * @param vec Vector to which reference is needed * @return Pointer to acquired array */ -struct gkyl_kn_vec* gkyl_kn_vec_acquire(const struct gkyl_kn_vec* vec); +struct gkyl_kn_vec *gkyl_kn_vec_acquire(const struct gkyl_kn_vec *vec); /** * Release kn_vec. diff --git a/core/zero/gkyl_lua_utils.h b/core/zero/gkyl_lua_utils.h index 0876e3f05b..1289bc1d08 100644 --- a/core/zero/gkyl_lua_utils.h +++ b/core/zero/gkyl_lua_utils.h @@ -11,35 +11,37 @@ // Gets a table with given name from a table, pushing it on the // stack. Table is popped when the scope ends -#define with_lua_tbl_tbl(L, key) \ - for (bool _break = (lua_getfield(L, -1, key), (lua_isnil(L,-1) || !lua_istable(L, -1) ? (lua_pop(L, 1), false) : true)); \ - _break; \ - _break = false, lua_pop(L, 1)) +#define with_lua_tbl_tbl(L, key) \ + for (bool _break = \ + (lua_getfield(L, -1, key), \ + (lua_isnil(L, -1) || !lua_istable(L, -1) ? (lua_pop(L, 1), false) : true)); \ + _break; _break = false, lua_pop(L, 1)) // Pushes the value associated with key on stack, popping it when the scope exits -#define with_lua_tbl_key(L, key) \ - for (bool _break = (lua_getfield(L, -1, key), (lua_isnil(L,-1) ? (lua_pop(L, 1), false) : true)); \ - _break; \ - _break = false, lua_pop(L, 1)) +#define with_lua_tbl_key(L, key) \ + for (bool _break = \ + (lua_getfield(L, -1, key), (lua_isnil(L, -1) ? (lua_pop(L, 1), false) : true)); \ + _break; _break = false, lua_pop(L, 1)) // This macro pushes the named global on the stack and restores the // stack when the scope is complete. If the global is a function it is // not popped on scope exit. This is not a problem if the function is // used inside the scope. If you do not use it, then you must call an // explict pop yourself. -#define with_lua_global(L, name) \ - for (bool _break = (lua_getglobal(L, name), (lua_isnil(L,-1) ? (lua_pop(L, 1), false) : true)), _isfun = lua_isfunction(L,-1); \ - _break; \ - _break = false, _isfun ? 0 : lua_pop(L, 1)) +#define with_lua_global(L, name) \ + for (bool _break = (lua_getglobal(L, name), (lua_isnil(L, -1) ? (lua_pop(L, 1), false) : true)), \ + _isfun = lua_isfunction(L, -1); \ + _break; _break = false, _isfun ? 0 : lua_pop(L, 1)) // Check and fetch user-data based on metatable name #define GKYL_CHECK_UDATA(L, mnm) luaL_checkudata(L, 1, mnm) // For debugging top of stack -#define gkyl_lua_trace_stack_top(L, fnm) do { \ - fprintf(stdout, "Inside function %s\n", fnm); \ - fprintf(stdout, "--> Top of stack is %s\n", lua_typename(L, lua_type(L, -1))); \ - } while (0); +#define gkyl_lua_trace_stack_top(L, fnm) \ + do { \ + fprintf(stdout, "Inside function %s\n", fnm); \ + fprintf(stdout, "--> Top of stack is %s\n", lua_typename(L, lua_type(L, -1))); \ + } while (0); /** * Get length of object on top of stack. (Table size, string length @@ -47,7 +49,10 @@ * * @return Length of object on top of stack. */ -static inline size_t glua_objlen(lua_State *L) { return lua_objlen(L, -1); } +static inline size_t glua_objlen(lua_State *L) +{ + return lua_objlen(L, -1); +} /** * Check if table has specifed key in it. Table must be on top of the diff --git a/core/zero/gkyl_mat.h b/core/zero/gkyl_mat.h index 30aa92f1cb..5fd9651412 100644 --- a/core/zero/gkyl_mat.h +++ b/core/zero/gkyl_mat.h @@ -18,7 +18,7 @@ struct gkyl_mat { size_t nr, nc; // Number of rows, columns double *data; // Pointer to data - uint32_t flags; + uint32_t flags; struct gkyl_ref_count ref_count; struct gkyl_mat *on_dev; // pointer to itself or device data }; @@ -32,16 +32,16 @@ struct gkyl_nmat { double *data; // Pointer to data double **mptr; // pointers to start of each sub-matrix - uint32_t flags; + uint32_t flags; struct gkyl_ref_count ref_count; - struct gkyl_nmat *on_dev; // pointer to itself or device data + struct gkyl_nmat *on_dev; // pointer to itself or device data }; // Type for storing preallocating memory needed in various batch // operations typedef struct gkyl_nmat_mem gkyl_nmat_mem; -// Type for storing preallocating memory needed specificially for +// Type for storing preallocating memory needed specificially for // mat_mm_array typedef struct gkyl_mat_mm_array_mem gkyl_mat_mm_array_mem; @@ -54,79 +54,69 @@ typedef struct gkyl_mat_mm_array_mem gkyl_mat_mm_array_mem; * @param val Initial value * @return Pointer to new matrix. */ -struct gkyl_mat* gkyl_mat_new(size_t nr, size_t nc, double val); +struct gkyl_mat *gkyl_mat_new(size_t nr, size_t nc, double val); /** * Clone matrix. */ -struct gkyl_mat* gkyl_mat_clone(const struct gkyl_mat *in); +struct gkyl_mat *gkyl_mat_clone(const struct gkyl_mat *in); /** * Set value in matrix. */ -GKYL_CU_DH -static inline void -gkyl_mat_set(struct gkyl_mat *mat, size_t r, size_t c, double val) +GKYL_CU_DH static inline void gkyl_mat_set(struct gkyl_mat *mat, size_t r, size_t c, double val) { - mat->data[c*mat->nr+r] = val; + mat->data[c * mat->nr + r] = val; } /** * Increase value in matrix. */ -GKYL_CU_DH -static inline void -gkyl_mat_inc(struct gkyl_mat *mat, size_t r, size_t c, double val) +GKYL_CU_DH static inline void gkyl_mat_inc(struct gkyl_mat *mat, size_t r, size_t c, double val) { - mat->data[c*mat->nr+r] += val; + mat->data[c * mat->nr + r] += val; } /** * Get value from matrix. */ -GKYL_CU_DH -static inline double -gkyl_mat_get(const struct gkyl_mat *mat, size_t r, size_t c) +GKYL_CU_DH static inline double gkyl_mat_get(const struct gkyl_mat *mat, size_t r, size_t c) { - return mat->data[c*mat->nr+r]; + return mat->data[c * mat->nr + r]; } /** * Get column of matrix as const pointer. */ -GKYL_CU_DH -static inline const double* -gkyl_mat_get_ccol(const struct gkyl_mat *mat, size_t c) +GKYL_CU_DH static inline const double *gkyl_mat_get_ccol(const struct gkyl_mat *mat, size_t c) { - return mat->data+c*mat->nr; + return mat->data + c * mat->nr; } /** * Get column of matrix as pointer. */ -GKYL_CU_DH -static inline double* -gkyl_mat_get_col(struct gkyl_mat *mat, size_t c) +GKYL_CU_DH static inline double *gkyl_mat_get_col(struct gkyl_mat *mat, size_t c) { - return mat->data+c*mat->nr; + return mat->data + c * mat->nr; } /** * Set all elements of matrix to specified value. Returns pointer to @a mat. */ -GKYL_CU_DH -static inline struct gkyl_mat* -gkyl_mat_clear(struct gkyl_mat *mat, double val) +GKYL_CU_DH static inline struct gkyl_mat *gkyl_mat_clear(struct gkyl_mat *mat, double val) { - for (size_t i=0; inr*mat->nc; ++i) mat->data[i] = val; + for (size_t i = 0; i < mat->nr * mat->nc; ++i) { + mat->data[i] = val; + } return mat; } /** * Set all elements on diagonal to specified value. All other elements * are set to 0.0. Returns pointer to @a mat. - */ -struct gkyl_mat* gkyl_mat_diag(struct gkyl_mat *mat, double val); + */ +struct gkyl_mat *gkyl_mat_diag(struct gkyl_mat *mat, double val); /** * Write matrix to file. Output is in Maxima matrix format @@ -143,9 +133,10 @@ void gkyl_mat_show(const char *name, FILE *fp, const struct gkyl_mat *mat); * * C is returned */ -struct gkyl_mat* gkyl_mat_mm(double alpha, double beta, - enum gkyl_mat_trans transa, const struct gkyl_mat *A, - enum gkyl_mat_trans transb, const struct gkyl_mat *B, struct gkyl_mat *, bool on_gpu); +struct gkyl_mat *gkyl_mat_mm( + double alpha, double beta, enum gkyl_mat_trans transa, const struct gkyl_mat *A, + enum gkyl_mat_trans transb, const struct gkyl_mat *B, struct gkyl_mat *, bool on_gpu +); /** * Computes matrix-vector product: @@ -157,9 +148,10 @@ struct gkyl_mat* gkyl_mat_mm(double alpha, double beta, * * C is returned */ -struct gkyl_mat* gkyl_mat_mv(double alpha, double beta, - enum gkyl_mat_trans transa, const struct gkyl_mat *A, - const struct gkyl_mat *x, struct gkyl_mat *y); +struct gkyl_mat *gkyl_mat_mv( + double alpha, double beta, enum gkyl_mat_trans transa, const struct gkyl_mat *A, + const struct gkyl_mat *x, struct gkyl_mat *y +); /** * Does a batch of matrix-vector products: @@ -173,9 +165,10 @@ struct gkyl_mat* gkyl_mat_mv(double alpha, double beta, * @param x batch of vectors to be multiplied * @param y batch of output vectors */ -void -gkyl_nmat_mv(double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_nmat *A, - struct gkyl_nmat *x, struct gkyl_nmat *y); +void gkyl_nmat_mv( + double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_nmat *A, struct gkyl_nmat *x, + struct gkyl_nmat *y +); /** * Does a batch of matrix-matrix products: @@ -190,9 +183,10 @@ gkyl_nmat_mv(double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_ * @param B batch of matrices to be multiplied * @param C batch f output matrices */ -void -gkyl_nmat_mm(double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_nmat *A, - enum gkyl_mat_trans transb, struct gkyl_nmat *B, struct gkyl_nmat *C); +void gkyl_nmat_mm( + double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_nmat *A, + enum gkyl_mat_trans transb, struct gkyl_nmat *B, struct gkyl_nmat *C +); /** * Solve system of linear equations using LU decomposition. On input @@ -213,7 +207,7 @@ gkyl_nmat_mm(double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_ * The reason for passing ipiv to this function is that it avoids * allocations inside this function. */ -bool gkyl_mat_linsolve_lu(struct gkyl_mat *A, struct gkyl_mat *x, void* ipiv); +bool gkyl_mat_linsolve_lu(struct gkyl_mat *A, struct gkyl_mat *x, void *ipiv); /** * Release matrix @@ -252,7 +246,7 @@ struct gkyl_nmat *gkyl_nmat_new(size_t num, size_t nr, size_t nc); * @param nc Number of cols * @return Pointer to new multi-matrix. */ -struct gkyl_mat* gkyl_mat_cu_dev_new(size_t nr, size_t nc); +struct gkyl_mat *gkyl_mat_cu_dev_new(size_t nr, size_t nc); /** * Construct new multi-matrix (batch of matrices). Delete using @@ -272,7 +266,7 @@ struct gkyl_mat* gkyl_mat_cu_dev_new(size_t nr, size_t nc); * @param nc Number of cols * @return Pointer to new multi-matrix. */ -struct gkyl_nmat* gkyl_nmat_cu_dev_new(size_t num, size_t nr, size_t nc); +struct gkyl_nmat *gkyl_nmat_cu_dev_new(size_t num, size_t nr, size_t nc); /** * Copy into nmat: pointer to dest nmat is returned. 'dest' and 'src' @@ -282,7 +276,7 @@ struct gkyl_nmat* gkyl_nmat_cu_dev_new(size_t num, size_t nr, size_t nc); * @param src Srouce to copy from. * @return dest is returned */ -struct gkyl_nmat* gkyl_nmat_copy(struct gkyl_nmat *dest, const struct gkyl_nmat *src); +struct gkyl_nmat *gkyl_nmat_copy(struct gkyl_nmat *dest, const struct gkyl_nmat *src); /** * Copy into mat: pointer to dest mat is returned. 'dest' and 'src' @@ -292,7 +286,7 @@ struct gkyl_nmat* gkyl_nmat_copy(struct gkyl_nmat *dest, const struct gkyl_nmat * @param src Srouce to copy from. * @return dest is returned */ -struct gkyl_mat* gkyl_mat_copy(struct gkyl_mat *dest, const struct gkyl_mat *src); +struct gkyl_mat *gkyl_mat_copy(struct gkyl_mat *dest, const struct gkyl_mat *src); /** * Get a matrix from multi-matrix. DO NOT free the returned matrix! @@ -300,15 +294,10 @@ struct gkyl_mat* gkyl_mat_copy(struct gkyl_mat *dest, const struct gkyl_mat *src * @param n Matrix to fetch * @return Matrix (DO NOT free/release this) */ -GKYL_CU_DH -static inline struct gkyl_mat -gkyl_nmat_get(struct gkyl_nmat *mat, size_t num) +GKYL_CU_DH static inline struct gkyl_mat gkyl_nmat_get(struct gkyl_nmat *mat, size_t num) { - return (struct gkyl_mat) { - .nr = mat->nr, - .nc = mat->nc, - .data = mat->data+num*mat->nr*mat->nc - }; + return (struct gkyl_mat + ){.nr = mat->nr, .nc = mat->nc, .data = mat->data + num * mat->nr * mat->nc}; } /** @@ -326,7 +315,7 @@ bool gkyl_nmat_is_cu_dev(const struct gkyl_nmat *mat); * @param mat Multi-matrix to which a pointer is needed * @return Pointer to acquired multi-matrix. */ -struct gkyl_nmat* gkyl_nmat_acquire(const struct gkyl_nmat *mat); +struct gkyl_nmat *gkyl_nmat_acquire(const struct gkyl_nmat *mat); /** * Allocate memory needed in batched LU solves on host. Free using the @@ -359,8 +348,10 @@ void gkyl_nmat_linsolve_lu_release(gkyl_nmat_mem *mem); * @param use_gpu * @return Preallocated memory */ -gkyl_mat_mm_array_mem *gkyl_mat_mm_array_mem_new(int nr, int nc, double alpha, - double beta, enum gkyl_mat_trans transa, enum gkyl_mat_trans transb, bool use_gpu); +gkyl_mat_mm_array_mem *gkyl_mat_mm_array_mem_new( + int nr, int nc, double alpha, double beta, enum gkyl_mat_trans transa, enum gkyl_mat_trans transb, + bool use_gpu +); /** * Release memory allocated for batched LU solves. @@ -381,7 +372,9 @@ void gkyl_mat_mm_array_mem_release(gkyl_mat_mm_array_mem *mem); * @param B gkyl_array matrix for computing A*B = C * @param C gkyl_array matrix for computing A*B = C */ -void gkyl_mat_mm_array(struct gkyl_mat_mm_array_mem *mem, const struct gkyl_array *B, struct gkyl_array *C); +void gkyl_mat_mm_array( + struct gkyl_mat_mm_array_mem *mem, const struct gkyl_array *B, struct gkyl_array *C +); /** * Solve a batched system of linear equations using LU diff --git a/core/zero/gkyl_mat_priv.h b/core/zero/gkyl_mat_priv.h index 63422b40aa..c4633cce0d 100644 --- a/core/zero/gkyl_mat_priv.h +++ b/core/zero/gkyl_mat_priv.h @@ -5,7 +5,6 @@ #include #include - #include #include #include @@ -16,10 +15,8 @@ #endif #endif - struct gkyl_mat_mm_array_mem { - - // info for alpha*matrix_multiplication(A,B) + Beta*C = C + // info for alpha*matrix_multiplication(A,B) + Beta*C = C // using mat_mm_array bool on_gpu; // flag to indicate if we are on GPU double alpha; @@ -30,5 +27,5 @@ struct gkyl_mat_mm_array_mem { #ifdef GKYL_HAVE_CUDA cublasHandle_t cuh; // cublas handle -#endif +#endif }; \ No newline at end of file diff --git a/core/zero/gkyl_mat_triples.h b/core/zero/gkyl_mat_triples.h index 474e3a6c7a..46d499d773 100644 --- a/core/zero/gkyl_mat_triples.h +++ b/core/zero/gkyl_mat_triples.h @@ -8,7 +8,7 @@ // A triple stores 'val' at (row, col) struct gkyl_mtriple { size_t row, col; - double val; + double val; }; /** Triples stores list of (i,j,val) for use in constructing sparse matrices */ @@ -23,7 +23,7 @@ typedef struct gkyl_mat_triples_iter gkyl_mat_triples_iter; * @param nc Number of cols * @return Pointer to new empty triples object. */ -gkyl_mat_triples* gkyl_mat_triples_new(size_t nr, size_t nc); +gkyl_mat_triples *gkyl_mat_triples_new(size_t nr, size_t nc); /* * Set row-major/col-major ordering for triples. diff --git a/core/zero/gkyl_math.h b/core/zero/gkyl_math.h index ee048fa027..f1a177017b 100644 --- a/core/zero/gkyl_math.h +++ b/core/zero/gkyl_math.h @@ -3,80 +3,71 @@ #include // Three-component vector -struct gkyl_vec3 { double x[3]; }; +struct gkyl_vec3 { + double x[3]; +}; -// new vector with zeros -static inline struct gkyl_vec3 -gkyl_vec3_zeros() +// new vector with zeros +static inline struct gkyl_vec3 gkyl_vec3_zeros() { - return (struct gkyl_vec3) { .x = { 0.0, 0.0, 0.0} }; + return (struct gkyl_vec3){.x = {0.0, 0.0, 0.0}}; } // new vector with x,y,z components -static inline struct gkyl_vec3 -gkyl_vec3_new(double x, double y, double z) +static inline struct gkyl_vec3 gkyl_vec3_new(double x, double y, double z) { - return (struct gkyl_vec3) { .x = { x, y, z} }; + return (struct gkyl_vec3){.x = {x, y, z}}; } // scalar*a -static inline struct gkyl_vec3 -gkyl_vec3_scale(double scalar, struct gkyl_vec3 a) +static inline struct gkyl_vec3 gkyl_vec3_scale(double scalar, struct gkyl_vec3 a) { - return (struct gkyl_vec3) { .x = { scalar*a.x[0], scalar*a.x[1], scalar*a.x[2] } }; + return (struct gkyl_vec3){.x = {scalar * a.x[0], scalar * a.x[1], scalar * a.x[2]}}; } // a+b -static inline struct gkyl_vec3 -gkyl_vec3_add(struct gkyl_vec3 a, struct gkyl_vec3 b) +static inline struct gkyl_vec3 gkyl_vec3_add(struct gkyl_vec3 a, struct gkyl_vec3 b) { - return (struct gkyl_vec3) { .x = { a.x[0]+b.x[0], a.x[1]+b.x[1], a.x[2]+b.x[2] } }; + return (struct gkyl_vec3){.x = {a.x[0] + b.x[0], a.x[1] + b.x[1], a.x[2] + b.x[2]}}; } // a-b -static inline struct gkyl_vec3 -gkyl_vec3_sub(struct gkyl_vec3 a, struct gkyl_vec3 b) +static inline struct gkyl_vec3 gkyl_vec3_sub(struct gkyl_vec3 a, struct gkyl_vec3 b) { - return (struct gkyl_vec3) { .x = { a.x[0]-b.x[0], a.x[1]-b.x[1], a.x[2]-b.x[2] } }; + return (struct gkyl_vec3){.x = {a.x[0] - b.x[0], a.x[1] - b.x[1], a.x[2] - b.x[2]}}; } // |a| -static inline double -gkyl_vec3_len(struct gkyl_vec3 a) +static inline double gkyl_vec3_len(struct gkyl_vec3 a) { - return sqrt( a.x[0]*a.x[0] + a.x[1]*a.x[1] + a.x[2]*a.x[2] ); + return sqrt(a.x[0] * a.x[0] + a.x[1] * a.x[1] + a.x[2] * a.x[2]); } // normalize a -static inline struct gkyl_vec3 -gkyl_vec3_norm(struct gkyl_vec3 a) +static inline struct gkyl_vec3 gkyl_vec3_norm(struct gkyl_vec3 a) { double len = gkyl_vec3_len(a); - return (struct gkyl_vec3) { .x = { a.x[0]/len, a.x[1]/len, a.x[2]/len } }; + return (struct gkyl_vec3){.x = {a.x[0] / len, a.x[1] / len, a.x[2] / len}}; } // a \dot b -static inline double -gkyl_vec3_dot(struct gkyl_vec3 a, struct gkyl_vec3 b) +static inline double gkyl_vec3_dot(struct gkyl_vec3 a, struct gkyl_vec3 b) { - return a.x[0]*b.x[0] + a.x[1]*b.x[1] + a.x[2]*b.x[2]; + return a.x[0] * b.x[0] + a.x[1] * b.x[1] + a.x[2] * b.x[2]; } // a \times b -static inline struct gkyl_vec3 -gkyl_vec3_cross(struct gkyl_vec3 a, struct gkyl_vec3 b) +static inline struct gkyl_vec3 gkyl_vec3_cross(struct gkyl_vec3 a, struct gkyl_vec3 b) { - return (struct gkyl_vec3) { .x = { - a.x[1]*b.x[2]-a.x[2]*b.x[1], - a.x[2]*b.x[0]-a.x[0]*b.x[2], - a.x[0]*b.x[1]-a.x[1]*b.x[0] - } - }; + return (struct gkyl_vec3 + ){.x = { + a.x[1] * b.x[2] - a.x[2] * b.x[1], a.x[2] * b.x[0] - a.x[0] * b.x[2], + a.x[0] * b.x[1] - a.x[1] * b.x[0] + }}; } // a \dot (b \times c) -static inline double -gkyl_vec3_triple(struct gkyl_vec3 a, struct gkyl_vec3 b, struct gkyl_vec3 c) +static inline double gkyl_vec3_triple(struct gkyl_vec3 a, struct gkyl_vec3 b, struct gkyl_vec3 c) { return gkyl_vec3_dot(a, gkyl_vec3_cross(b, c)); } @@ -113,11 +104,11 @@ gkyl_vec3_polar_con_to_cart(double r, double phi, struct gkyl_vec3 pin) static inline struct gkyl_vec3 gkyl_vec3_polar_cov_to_cart(double r, double phi, struct gkyl_vec3 pin) { - double c0 = pin.x[0]*cos(phi)-(pin.x[1]*sin(phi))/r; - double c1 = pin.x[0]*sin(phi)+(pin.x[1]*cos(phi))/r; + double c0 = pin.x[0] * cos(phi) - (pin.x[1] * sin(phi)) / r; + double c1 = pin.x[0] * sin(phi) + (pin.x[1] * cos(phi)) / r; double c2 = pin.x[2]; return gkyl_vec3_new(c0, c1, c2); -} +} /** * Convert contravariant components of a vector in polar coordinate @@ -129,8 +120,7 @@ gkyl_vec3_polar_cov_to_cart(double r, double phi, struct gkyl_vec3 pin) * @param pin Input contravariant vector components * @return Cartesian component for @a pin */ -static inline struct gkyl_vec3 -gkyl_vec3_polar_con_to_cov(double r, struct gkyl_vec3 pin) +static inline struct gkyl_vec3 gkyl_vec3_polar_con_to_cov(double r, struct gkyl_vec3 pin) { double c0 = pin.x[0]; double c1 = pin.x[1] * r * r; @@ -141,59 +131,58 @@ gkyl_vec3_polar_con_to_cov(double r, struct gkyl_vec3 pin) // minmod(a,b,c, ...) returns min of all parameters are positive, max // of all parameters if all are negative, and zero otherwise. - // minmod(x,y) -static inline double -gkyl_minmod_2(double x, double y) +static inline double gkyl_minmod_2(double x, double y) { - if (x>0 && y>0) - return fmin(x,y); - if (x<0 && y<0) - return fmax(x,y); + if (x > 0 && y > 0) { + return fmin(x, y); + } + if (x < 0 && y < 0) { + return fmax(x, y); + } return 0.0; } // minmod(x,y) -static inline double -gkyl_minmod_3(double x, double y, double z) +static inline double gkyl_minmod_3(double x, double y, double z) { - if (x>0 && y>0 && z>0) - return fmin(fmin(x,y),z); - if (x<0 && y<0 && z<0) - return fmax(fmax(x,y),z); + if (x > 0 && y > 0 && z > 0) { + return fmin(fmin(x, y), z); + } + if (x < 0 && y < 0 && z < 0) { + return fmax(fmax(x, y), z); + } return 0.0; } // minmod(x,y,z,w) -static inline double -gkyl_minmod_4(double x, double y, double z, double w) +static inline double gkyl_minmod_4(double x, double y, double z, double w) { - if (x>0 && y>0 && z>0 && w>0) - return fmin(fmin(x,y),fmin(z,w)); - if (x<0 && y<0 && z<0 && w<0) - return fmax(fmax(x,y),fmax(z,w)); + if (x > 0 && y > 0 && z > 0 && w > 0) { + return fmin(fmin(x, y), fmin(z, w)); + } + if (x < 0 && y < 0 && z < 0 && w < 0) { + return fmax(fmax(x, y), fmax(z, w)); + } return 0.0; } // median(x,y,z) returns the value between two others -static inline double -gkyl_median(double x, double y, double z) +static inline double gkyl_median(double x, double y, double z) { - return x + gkyl_minmod_2(y-x,z-x); + return x + gkyl_minmod_2(y - x, z - x); } // min(x,y,z) -static inline double -gkyl_min_3(double x, double y, double z) +static inline double gkyl_min_3(double x, double y, double z) { - return fmin(x,fmin(y,z)); + return fmin(x, fmin(y, z)); } // max(x,y,z) -static inline double -gkyl_max_3(double x, double y, double z) +static inline double gkyl_max_3(double x, double y, double z) { - return fmax(x,fmax(y,z)); + return fmax(x, fmax(y, z)); } // Result from numerical quadrature @@ -206,11 +195,7 @@ struct gkyl_qr_res { }; // polynomial order for low-order polynomial -enum gkyl_lo_poly_order { - GKYL_LO_POLY_2 = 2, - GKYL_LO_POLY_3, - GKYL_LO_POLY_4, -}; +enum gkyl_lo_poly_order { GKYL_LO_POLY_2 = 2, GKYL_LO_POLY_3, GKYL_LO_POLY_4 }; // Polynomial roots for low-order polynomials (upto 4th order) struct gkyl_lo_poly_roots { @@ -225,9 +210,9 @@ struct gkyl_poly_roots { int poly_order; // polynomial order double *rpart, *impart; // real and imaginary part of roots double *err; // estimated error for each root - int niter; // number of iterations + int niter; // number of iterations void *work; // some memory needed internally. Do not muck or access! -}; +}; // Quartic polynomial to hand off to ridders struct gkyl_quartic_polynomial { @@ -254,7 +239,7 @@ struct gkyl_root_intervals { int nroots; // number of distinct-real-roots struct gkyl_sturm_polynomials sturn_chain; double real_roots_ridders[4]; // Output of the root finding algorithm - int status_ridders[4]; // Status of the ridders' ability to find the roots + int status_ridders[4]; // Status of the ridders' ability to find the roots }; /** @@ -271,8 +256,8 @@ struct gkyl_root_intervals { * @param eps Error to compute integral * @return Result of quadrature */ -struct gkyl_qr_res gkyl_dbl_exp(double (*func)(double, void *), void *ctx, - double a, double b, int n, double eps); +struct gkyl_qr_res +gkyl_dbl_exp(double (*func)(double, void *), void *ctx, double a, double b, int n, double eps); /** * Compute single real root of a function using Ridders' method. See @@ -290,8 +275,10 @@ struct gkyl_qr_res gkyl_dbl_exp(double (*func)(double, void *), void *ctx, * @param eps Desired error bound * @return Result of root finder */ -struct gkyl_qr_res gkyl_ridders(double (*func)(double,void*), void *ctx, - double x1, double x2, double f1, double f2, int max_iter, double eps); +struct gkyl_qr_res gkyl_ridders( + double (*func)(double, void *), void *ctx, double x1, double x2, double f1, double f2, + int max_iter, double eps +); /** * Compute all simple roots of the low-order polynomial with monomial @@ -307,8 +294,7 @@ struct gkyl_qr_res gkyl_ridders(double (*func)(double,void*), void *ctx, * @param coeff Coefficients of the polynomial * @return Roots of the polynomial */ -struct gkyl_lo_poly_roots gkyl_calc_lo_poly_roots(enum gkyl_lo_poly_order order, - double coeff[4]); +struct gkyl_lo_poly_roots gkyl_calc_lo_poly_roots(enum gkyl_lo_poly_order order, double coeff[4]); /** * Allocate memory to store polynomial roots. @@ -316,7 +302,7 @@ struct gkyl_lo_poly_roots gkyl_calc_lo_poly_roots(enum gkyl_lo_poly_order order, * @param poly_order Polynomial order * @return newly allocated memory. Free using release method. */ -struct gkyl_poly_roots* gkyl_poly_roots_new(int poly_order); +struct gkyl_poly_roots *gkyl_poly_roots_new(int poly_order); /** * Compute all simple roots of polymomial with real coefficients. The @@ -347,8 +333,8 @@ void gkyl_calc_poly_roots(struct gkyl_poly_roots *pr, const double *coeff); * @param tol Tolerance of the quartic solve * @return Roots of the polynomial */ -struct gkyl_root_intervals gkyl_calc_quartic_root_intervals( - double coeff[4], double domain[2], double tol); +struct gkyl_root_intervals +gkyl_calc_quartic_root_intervals(double coeff[4], double domain[2], double tol); /** * Refine the result of gkyl_calc_quartic_root_intervals() using bisection search @@ -366,9 +352,7 @@ struct gkyl_root_intervals gkyl_calc_quartic_root_intervals( * @param tol Tolerance of the interval isolation * @return Roots of the polynomial */ -void gkyl_refine_root_intervals_bisection(struct gkyl_root_intervals *root_intervals, - double tol); - +void gkyl_refine_root_intervals_bisection(struct gkyl_root_intervals *root_intervals, double tol); /** * Compute the roots from the intervals given by gkyl_calc_quartic_root_intervals() @@ -386,8 +370,9 @@ void gkyl_refine_root_intervals_bisection(struct gkyl_root_intervals *root_inter * @param tol Tolerance of the interval isolation * @return Roots of the polynomial */ -void gkyl_root_isolation_from_intervals_via_ridders(struct gkyl_root_intervals *root_intervals, - double tol); +void gkyl_root_isolation_from_intervals_via_ridders( + struct gkyl_root_intervals *root_intervals, double tol +); /** * Release memory for use in polynomial root finder. @@ -395,4 +380,3 @@ void gkyl_root_isolation_from_intervals_via_ridders(struct gkyl_root_intervals * * @param pr Memory to release. */ void gkyl_poly_roots_release(struct gkyl_poly_roots *pr); - diff --git a/core/zero/gkyl_mom_type.h b/core/zero/gkyl_mom_type.h index e1e18c71ac..6a74237867 100644 --- a/core/zero/gkyl_mom_type.h +++ b/core/zero/gkyl_mom_type.h @@ -18,14 +18,14 @@ enum gkyl_distribution_moments { GKYL_F_MOMENT_MAXWELLIAN, // M0, drift speed, T/m. GKYL_F_MOMENT_BIMAXWELLIAN, // M0, drift speed, Tpar/m, Tperp/m. GKYL_F_MOMENT_LTE, // Maxwellian or Maxwell-Juttner moments. - GKYL_F_MOMENT_M0M1M2, // M0, M1, M2. - GKYL_F_MOMENT_M0M1M2PARM2PERP, // M0, M1, M2par, M2perp. - GKYL_F_MOMENT_HAMILTONIAN, // M0, mass*M1, H moments. + GKYL_F_MOMENT_M0M1M2, // M0, M1, M2. + GKYL_F_MOMENT_M0M1M2PARM2PERP, // M0, M1, M2par, M2perp. + GKYL_F_MOMENT_HAMILTONIAN, // M0, mass*M1, H moments. GKYL_F_MOMENT_M1_FROM_H, // dH/dv / m moment. GKYL_F_MOMENT_ENERGY, // H moment. GKYL_F_MOMENT_M0ENERGYM3, // M0, Energy (H) and M3 moments. GKYL_F_MOMENT_NI, // M0, M1i for-vector. - GKYL_F_MOMENT_TIJ, // Stress-energy tensor. + GKYL_F_MOMENT_TIJ // Stress-energy tensor. }; // String names corresponding to the enum options above. @@ -50,7 +50,7 @@ static const char *gkyl_distribution_moments_strs[] = { "EnergyMoment", "M0EnergyM3", "Ni", - "Tij", + "Tij" }; // Descriptions for each distribution moment. @@ -69,13 +69,14 @@ static const char *gkyl_distribution_moments_descriptions[] = { "Number density, drift velocity, parallel and perpendicular thermal speed squared.", "Number density, drift velocity, and thermal speed squared.", "Number density, momentum density divided by mass, and kinetic energy density times 2/mass.", - "Number density, momentum density divided by mass, and parallel and perpendicular kinetic energy density times 2/mass.", + "Number density, momentum density divided by mass, and parallel and perpendicular kinetic energy " + "density times 2/mass.", "Number density, momentum density, and Hamiltonian energy density.", "Momentum density (divided by mass) from the velocity gradient of the Hamiltonian.", "Hamiltonian energy density (for neutrals).", "Number density, Hamiltonian energy density, and heat flux density times 2/mass.", "4-momentum (M0, M1).", - "Stress-energy tensor.", + "Stress-energy tensor." }; // Forward declare for use in function pointers @@ -84,9 +85,10 @@ struct gkyl_mom_type; /** * Function pointer type to compute the needed moment. */ -typedef void (*momf_t)(const struct gkyl_mom_type *momt, - const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param); +typedef void (*momf_t)( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +); struct gkyl_mom_type { int cdim; // config-space dim @@ -116,14 +118,14 @@ bool gkyl_mom_type_is_cu_dev(const struct gkyl_mom_type *momt); * @param momt Moment object to get pointer from. * @return acquired object */ -struct gkyl_mom_type* gkyl_mom_type_acquire(const struct gkyl_mom_type* momt); +struct gkyl_mom_type *gkyl_mom_type_acquire(const struct gkyl_mom_type *momt); /** * Delete moment object * * @param momt Moment object to delete. */ -void gkyl_mom_type_release(const struct gkyl_mom_type* momt); +void gkyl_mom_type_release(const struct gkyl_mom_type *momt); /** * Calculate moment specified by mom_type object. @@ -135,9 +137,10 @@ void gkyl_mom_type_release(const struct gkyl_mom_type* momt); * @param f Input pointer to distribution function in cell * @param out On output, contribution to moment from phase-space cell */ -void gkyl_mom_type_calc(const struct gkyl_mom_type* momt, - const double *xc, const double *dx, const int *idx, - const double *f, double* GKYL_RESTRICT out, void *param); +void gkyl_mom_type_calc( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *GKYL_RESTRICT out, void *param +); /** * Get number of moments specified by mom_type object @@ -145,4 +148,4 @@ void gkyl_mom_type_calc(const struct gkyl_mom_type* momt, * @param momt Moment type object * returns int Number of moments */ -int gkyl_mom_type_num_mom(const struct gkyl_mom_type* momt); +int gkyl_mom_type_num_mom(const struct gkyl_mom_type *momt); diff --git a/core/zero/gkyl_mpi_comm_priv.h b/core/zero/gkyl_mpi_comm_priv.h index 919a8f7b8a..1119a14900 100644 --- a/core/zero/gkyl_mpi_comm_priv.h +++ b/core/zero/gkyl_mpi_comm_priv.h @@ -44,8 +44,6 @@ struct mpi_comm { struct comm_buff_stat send[MAX_RECV_NEIGH]; // info for send data // buffers for for allgather - struct comm_buff_stat allgather_buff_local; - struct comm_buff_stat allgather_buff_global; + struct comm_buff_stat allgather_buff_local; + struct comm_buff_stat allgather_buff_global; }; - - diff --git a/core/zero/gkyl_multib_comm_conn.h b/core/zero/gkyl_multib_comm_conn.h index c8ee43f9fe..0aeae78866 100644 --- a/core/zero/gkyl_multib_comm_conn.h +++ b/core/zero/gkyl_multib_comm_conn.h @@ -22,7 +22,7 @@ struct gkyl_comm_conn { struct gkyl_multib_comm_conn { int num_comm_conn; // number of send/recv struct gkyl_comm_conn *comm_conn; // communication connections (size num_comm_conn) - struct gkyl_ref_count ref_count; + struct gkyl_ref_count ref_count; }; /** @@ -33,8 +33,8 @@ struct gkyl_multib_comm_conn { * @param comm_conn List of individual communication connections * @return New communication connection object */ -struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new(int num, - const struct gkyl_comm_conn *comm_conn); +struct gkyl_multib_comm_conn * +gkyl_multib_comm_conn_new(int num, const struct gkyl_comm_conn *comm_conn); /** * Construct the send communication connections for a rank from its @@ -48,8 +48,9 @@ struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new(int num, * @return New communication connection object for sends */ struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new_send( - int block_id, int block_rank, const int *nghost, - const struct gkyl_block_connections *block_conn, struct gkyl_rect_decomp **decomp); + int block_id, int block_rank, const int *nghost, const struct gkyl_block_connections *block_conn, + struct gkyl_rect_decomp **decomp +); /** * Construct the received communication connections for a rank from @@ -63,8 +64,9 @@ struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new_send( * @return New communication connection object receives */ struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new_recv( - int block_id, int block_rank, const int *nghost, - const struct gkyl_block_connections *block_conn, struct gkyl_rect_decomp **decomp); + int block_id, int block_rank, const int *nghost, const struct gkyl_block_connections *block_conn, + struct gkyl_rect_decomp **decomp +); /** * Construct the send communication connections for a rank from its @@ -79,9 +81,9 @@ struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new_recv( * @return New communication connection object for sends */ struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new_send_from_connections( - int block_id, int block_rank, const int *nghost, - int nconnected, int* block_list, int dir, - struct gkyl_rect_decomp **decomp); + int block_id, int block_rank, const int *nghost, int nconnected, int *block_list, int dir, + struct gkyl_rect_decomp **decomp +); /** * Construct the recv communication connections for a rank from its @@ -96,9 +98,9 @@ struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new_send_from_connections( * @return New communication connection object for sends */ struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new_recv_from_connections( - int block_id, int block_rank, const int *nghost, - int nconnected, int* block_list, int dir, - struct gkyl_rect_decomp **decomp); + int block_id, int block_rank, const int *nghost, int nconnected, int *block_list, int dir, + struct gkyl_rect_decomp **decomp +); /** * Transfer data from 'ain' and to 'aout' according to connections in @@ -112,10 +114,11 @@ struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new_recv_from_connections( * @param arr_send Array to send from (for each local block). * @param arr_recv Array to receive into (for each local block). */ -int gkyl_multib_comm_conn_array_transfer(struct gkyl_comm *comm, - int num_blocks_local, const int *local_blocks, +int gkyl_multib_comm_conn_array_transfer( + struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, struct gkyl_multib_comm_conn **mbcc_send, struct gkyl_multib_comm_conn **mbcc_recv, - struct gkyl_array **arr_send, struct gkyl_array **arr_recv); + struct gkyl_array **arr_send, struct gkyl_array **arr_recv +); /** * Create a multib range and extended range that spans @@ -128,9 +131,10 @@ int gkyl_multib_comm_conn_array_transfer(struct gkyl_comm *comm, * @param dir direction in which blocks are connected * @param decomp List of decomposition objects for each block */ -void gkyl_multib_comm_conn_create_multib_ranges_in_dir(struct gkyl_range *multib_range_ext, - struct gkyl_range *multib_range, const int *nghost, int nconnected, - int* block_list, int dir, struct gkyl_rect_decomp **decomp); +void gkyl_multib_comm_conn_create_multib_ranges_in_dir( + struct gkyl_range *multib_range_ext, struct gkyl_range *multib_range, const int *nghost, + int nconnected, int *block_list, int dir, struct gkyl_rect_decomp **decomp +); /** * Sort the connections in ascending order according to rank, and block id. diff --git a/core/zero/gkyl_multib_comm_conn_priv.h b/core/zero/gkyl_multib_comm_conn_priv.h index f6e234a30d..d101a2f79b 100644 --- a/core/zero/gkyl_multib_comm_conn_priv.h +++ b/core/zero/gkyl_multib_comm_conn_priv.h @@ -8,23 +8,26 @@ // // Functions for a null_comm. // -int gkyl_multib_comm_conn_array_transfer_null(struct gkyl_comm *comm, - int num_blocks_local, const int *local_blocks, +int gkyl_multib_comm_conn_array_transfer_null( + struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, struct gkyl_multib_comm_conn **mbcc_send, struct gkyl_multib_comm_conn **mbcc_recv, - struct gkyl_array **arr_send, struct gkyl_array **arr_recv); + struct gkyl_array **arr_send, struct gkyl_array **arr_recv +); // // Functions for a mpi_comm. // -int gkyl_multib_comm_conn_array_transfer_mpi(struct gkyl_comm *comm, - int num_blocks_local, const int *local_blocks, +int gkyl_multib_comm_conn_array_transfer_mpi( + struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, struct gkyl_multib_comm_conn **mbcc_send, struct gkyl_multib_comm_conn **mbcc_recv, - struct gkyl_array **arr_send, struct gkyl_array **arr_recv); + struct gkyl_array **arr_send, struct gkyl_array **arr_recv +); // // Functions for a nccl_comm. // -int gkyl_multib_comm_conn_array_transfer_nccl(struct gkyl_comm *comm, - int num_blocks_local, const int *local_blocks, +int gkyl_multib_comm_conn_array_transfer_nccl( + struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, struct gkyl_multib_comm_conn **mbcc_send, struct gkyl_multib_comm_conn **mbcc_recv, - struct gkyl_array **arr_send, struct gkyl_array **arr_recv); + struct gkyl_array **arr_send, struct gkyl_array **arr_recv +); diff --git a/core/zero/gkyl_nccl_comm_priv.h b/core/zero/gkyl_nccl_comm_priv.h index 945c59e340..eeec7238ca 100644 --- a/core/zero/gkyl_nccl_comm_priv.h +++ b/core/zero/gkyl_nccl_comm_priv.h @@ -18,19 +18,21 @@ // for some reason, having only one check function may be a problem. // We could create a separate check function which waits and times out // after a set amount of time. -#define checkNCCL(cmd) do { \ - ncclResult_t res = cmd; \ - if (res != ncclSuccess && res != ncclInProgress) { \ - fprintf(stderr, "Failed, NCCL error %s:%d '%s'\n", \ - __FILE__,__LINE__,ncclGetErrorString(res)); \ - exit(EXIT_FAILURE); \ - } \ -} while(0) +#define checkNCCL(cmd) \ + do { \ + ncclResult_t res = cmd; \ + if (res != ncclSuccess && res != ncclInProgress) { \ + fprintf( \ + stderr, "Failed, NCCL error %s:%d '%s'\n", __FILE__, __LINE__, ncclGetErrorString(res) \ + ); \ + exit(EXIT_FAILURE); \ + } \ + } while (0) // Object with a range, a status and a buffer used for send/recv. struct comm_buff_stat { struct gkyl_range range; -// MPI_Request status; + // MPI_Request status; gkyl_mem_buff buff; }; @@ -65,6 +67,6 @@ struct nccl_comm { bool touches_any_edge; // true if this range touches any edge // buffers for for allgather - struct comm_buff_stat allgather_buff_local; - struct comm_buff_stat allgather_buff_global; + struct comm_buff_stat allgather_buff_local; + struct comm_buff_stat allgather_buff_global; }; diff --git a/core/zero/gkyl_nodal_ops.h b/core/zero/gkyl_nodal_ops.h index 88a0692e73..308d267819 100644 --- a/core/zero/gkyl_nodal_ops.h +++ b/core/zero/gkyl_nodal_ops.h @@ -6,7 +6,7 @@ #include #include -// Struct definition. Used to store nodal values +// Struct definition. Used to store nodal values struct gkyl_nodal_ops { struct gkyl_array *nodes; int poly_order; @@ -20,7 +20,8 @@ struct gkyl_nodal_ops { * @param use_gpu Boolean for whether nodes are stored on device * Returns pointer to gkyl_nodal_ops struct. */ -struct gkyl_nodal_ops* gkyl_nodal_ops_new(const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, bool use_gpu); +struct gkyl_nodal_ops * +gkyl_nodal_ops_new(const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, bool use_gpu); /** * Transform nodal representation to modal representation @@ -36,10 +37,12 @@ struct gkyl_nodal_ops* gkyl_nodal_ops_new(const struct gkyl_basis *cbasis, const * @param use_quad flag to indicate whether to use interior quadrature points * if false, serendipity nodes are used */ -void gkyl_nodal_ops_n2m(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - const struct gkyl_array *nodal_fld, struct gkyl_array *modal_fld, bool use_quad); +void gkyl_nodal_ops_n2m( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, const struct gkyl_array *nodal_fld, + struct gkyl_array *modal_fld, bool use_quad +); /** * Transform nodal representation to modal representation @@ -56,11 +59,12 @@ void gkyl_nodal_ops_n2m(const struct gkyl_nodal_ops *nodal_ops, * @param dir direction of surfaces * if false, serendipity nodes are used */ -void -gkyl_nodal_ops_n2m_surface(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - const struct gkyl_array *nodal_fld, struct gkyl_array *modal_fld, int dir) ; +void gkyl_nodal_ops_n2m_surface( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, const struct gkyl_array *nodal_fld, + struct gkyl_array *modal_fld, int dir +); /** * Transform modal representation to nodal representation @@ -77,11 +81,12 @@ gkyl_nodal_ops_n2m_surface(const struct gkyl_nodal_ops *nodal_ops, * @param dir direction of surfaces * if false, serendipity nodes are used */ -void -gkyl_nodal_ops_m2n_surface(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *modal_fld, int dir) ; +void gkyl_nodal_ops_m2n_surface( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, struct gkyl_array *nodal_fld, + const struct gkyl_array *modal_fld, int dir +); /** * Transform modal representation to nodal representation @@ -97,10 +102,12 @@ gkyl_nodal_ops_m2n_surface(const struct gkyl_nodal_ops *nodal_ops, * @param use_quad flag to indicate whether to use interior quadrature points * if false, serendipity nodes are used */ -void gkyl_nodal_ops_m2n(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *modal_fld, bool use_quad); +void gkyl_nodal_ops_m2n( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, struct gkyl_array *nodal_fld, + const struct gkyl_array *modal_fld, bool use_quad +); /** * Transform modal representation of dim = d-1 of to nodal representation @@ -117,10 +124,13 @@ void gkyl_nodal_ops_m2n(const struct gkyl_nodal_ops *nodal_ops, * @param deflated_modal_fld Input modal representation with dim = d-1 */ -void gkyl_nodal_ops_m2n_deflated(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *deflated_cbasis, const struct gkyl_rect_grid *deflated_grid, - const struct gkyl_range *nrange, const struct gkyl_range *deflated_nrange, const struct gkyl_range *deflated_update_range, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *deflated_modal_fld, int extra_idx) ; +void gkyl_nodal_ops_m2n_deflated( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *deflated_cbasis, + const struct gkyl_rect_grid *deflated_grid, const struct gkyl_range *nrange, + const struct gkyl_range *deflated_nrange, const struct gkyl_range *deflated_update_range, + int num_comp, struct gkyl_array *nodal_fld, const struct gkyl_array *deflated_modal_fld, + int extra_idx +); /** * Delete pointer to gkyl_nodal_ops struct. @@ -133,20 +143,24 @@ void gkyl_nodal_ops_release(struct gkyl_nodal_ops *up); * Host-side wrappers for nodal-modal transformation operations on device */ -void gkyl_nodal_ops_n2m_cu(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - const struct gkyl_array *nodal_fld, struct gkyl_array *modal_fld); - -void gkyl_nodal_ops_m2n_cu(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *modal_fld); - -void gkyl_nodal_ops_m2n_deflated_cu(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *deflated_cbasis, const struct gkyl_rect_grid *deflated_grid, - const struct gkyl_range *nrange, const struct gkyl_range *deflated_nrange, const struct gkyl_range *deflated_update_range, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *deflated_modal_fld, int extra_idx) ; - - - +void gkyl_nodal_ops_n2m_cu( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, const struct gkyl_array *nodal_fld, + struct gkyl_array *modal_fld +); + +void gkyl_nodal_ops_m2n_cu( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, struct gkyl_array *nodal_fld, + const struct gkyl_array *modal_fld +); + +void gkyl_nodal_ops_m2n_deflated_cu( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *deflated_cbasis, + const struct gkyl_rect_grid *deflated_grid, const struct gkyl_range *nrange, + const struct gkyl_range *deflated_nrange, const struct gkyl_range *deflated_update_range, + int num_comp, struct gkyl_array *nodal_fld, const struct gkyl_array *deflated_modal_fld, + int extra_idx +); diff --git a/core/zero/gkyl_null_comm.h b/core/zero/gkyl_null_comm.h index b14ac1aca0..653fe30638 100644 --- a/core/zero/gkyl_null_comm.h +++ b/core/zero/gkyl_null_comm.h @@ -6,7 +6,7 @@ // input to create new MPI communicator struct gkyl_null_comm_inp { - bool use_gpu; // flag to use if this communicator is on GPUs + bool use_gpu; // flag to use if this communicator is on GPUs const struct gkyl_rect_decomp *decomp; // pre-computed decomposition bool sync_corners; // should we sync corners? }; @@ -19,4 +19,3 @@ struct gkyl_null_comm_inp { * @return New communicator */ struct gkyl_comm *gkyl_null_comm_inew(const struct gkyl_null_comm_inp *inp); - diff --git a/core/zero/gkyl_null_comm_priv.h b/core/zero/gkyl_null_comm_priv.h index 37a19ac76a..167090606e 100644 --- a/core/zero/gkyl_null_comm_priv.h +++ b/core/zero/gkyl_null_comm_priv.h @@ -30,12 +30,11 @@ struct null_comm { bool use_gpu; // flag to use if this communicator is on GPUs bool sync_corners; // should we sync corners? - + struct gkyl_range grange; // range to "hash" ghost layout cmap_l2sgr l2sgr; // map from long -> skin_ghost_ranges cmap_l2sgr l2sgr_wc; // map from long -> skin_ghost_ranges with corners - + gkyl_mem_buff pbuff; // CUDA buffer for periodic BCs }; - diff --git a/core/zero/gkyl_null_pool.h b/core/zero/gkyl_null_pool.h index 67935461cc..b874925a75 100644 --- a/core/zero/gkyl_null_pool.h +++ b/core/zero/gkyl_null_pool.h @@ -9,4 +9,4 @@ * @param nthreads Number of "threads" to create (no real threading) * @return Pointer to new job-pool object */ -struct gkyl_job_pool* gkyl_null_pool_new(int nthreads); +struct gkyl_job_pool *gkyl_null_pool_new(int nthreads); diff --git a/core/zero/gkyl_proj_on_basis.h b/core/zero/gkyl_proj_on_basis.h index 878bc6efe6..342c4422a5 100644 --- a/core/zero/gkyl_proj_on_basis.h +++ b/core/zero/gkyl_proj_on_basis.h @@ -19,14 +19,14 @@ struct gkyl_proj_on_basis_inp { const struct gkyl_basis *basis; // basis functions enum gkyl_quad_type qtype; // quadrature to use - + int num_quad; // number of quadrature points int num_ret_vals; // number of return values in eval function evalf_t eval; // function to project void *ctx; // function context proj_on_basis_c2p_t c2p_func; // Function that transforms a set of ndim - // computational coordinates to physical ones. + // computational coordinates to physical ones. void *c2p_func_ctx; // Context for c2p_func. }; @@ -37,7 +37,7 @@ struct gkyl_proj_on_basis_inp { * @param inp Input parameters * @return New updater pointer. */ -gkyl_proj_on_basis* gkyl_proj_on_basis_inew(const struct gkyl_proj_on_basis_inp *inp); +gkyl_proj_on_basis *gkyl_proj_on_basis_inew(const struct gkyl_proj_on_basis_inp *inp); /** * Create new updater to project function on basis functions on a @@ -51,8 +51,10 @@ gkyl_proj_on_basis* gkyl_proj_on_basis_inew(const struct gkyl_proj_on_basis_inp * @param ctx Context for function evaluation. Can be NULL. * @return New updater pointer. */ -gkyl_proj_on_basis *gkyl_proj_on_basis_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, int num_quad, int num_ret_vals, evalf_t eval, void *ctx); +gkyl_proj_on_basis *gkyl_proj_on_basis_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, int num_quad, int num_ret_vals, + evalf_t eval, void *ctx +); /** * Compute projection on basis. The update_rng MUST be a sub-range of @@ -65,8 +67,10 @@ gkyl_proj_on_basis *gkyl_proj_on_basis_new(const struct gkyl_rect_grid *grid, * @param update_rng Range on which to run projection. * @param out Output array */ -void gkyl_proj_on_basis_advance(const gkyl_proj_on_basis *pob, - double tm, const struct gkyl_range *update_rng, struct gkyl_array *out); +void gkyl_proj_on_basis_advance( + const gkyl_proj_on_basis *pob, double tm, const struct gkyl_range *update_rng, + struct gkyl_array *out +); /** * Perform the quadrature in the proj_on_basis procedure. @@ -76,7 +80,9 @@ void gkyl_proj_on_basis_advance(const gkyl_proj_on_basis *pob, * @param fun_at_ords Function evaluated at ordinates in one cell. * @param f Output projected function in one cell. */ -void gkyl_proj_on_basis_quad(const gkyl_proj_on_basis *up, const struct gkyl_array *fun_at_ords, double* f); +void gkyl_proj_on_basis_quad( + const gkyl_proj_on_basis *up, const struct gkyl_array *fun_at_ords, double *f +); /** * Return the total number of quadrature points/ordinates. @@ -93,11 +99,11 @@ int gkyl_proj_on_basis_get_tot_quad(const gkyl_proj_on_basis *up); * @param node Index indicate the desired node. * @return Node coordinates. */ -double* gkyl_proj_on_basis_fetch_ordinate(const gkyl_proj_on_basis *up, long node); +double *gkyl_proj_on_basis_fetch_ordinate(const gkyl_proj_on_basis *up, long node); /** * Delete updater. * * @param pob Updater to delete. */ -void gkyl_proj_on_basis_release(gkyl_proj_on_basis* pob); +void gkyl_proj_on_basis_release(gkyl_proj_on_basis *pob); diff --git a/core/zero/gkyl_proj_powsqrt_on_basis.h b/core/zero/gkyl_proj_powsqrt_on_basis.h index 01bfb2970d..a354e4ed91 100644 --- a/core/zero/gkyl_proj_powsqrt_on_basis.h +++ b/core/zero/gkyl_proj_powsqrt_on_basis.h @@ -15,8 +15,8 @@ typedef struct gkyl_proj_powsqrt_on_basis gkyl_proj_powsqrt_on_basis; * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -gkyl_proj_powsqrt_on_basis* gkyl_proj_powsqrt_on_basis_new( - const struct gkyl_basis *basis, int num_quad, bool use_gpu); +gkyl_proj_powsqrt_on_basis * +gkyl_proj_powsqrt_on_basis_new(const struct gkyl_basis *basis, int num_quad, bool use_gpu); /** * Compute pow( sqrt(fIn), expIn) via quadrature. @@ -27,13 +27,14 @@ gkyl_proj_powsqrt_on_basis* gkyl_proj_powsqrt_on_basis_new( * @param fIn Input scalar field. * @param fOut Ouput scalar field. */ -void gkyl_proj_powsqrt_on_basis_advance(const gkyl_proj_powsqrt_on_basis *up, - const struct gkyl_range *range, double expIn, const struct gkyl_array *fIn, - struct gkyl_array *fOut); +void gkyl_proj_powsqrt_on_basis_advance( + const gkyl_proj_powsqrt_on_basis *up, const struct gkyl_range *range, double expIn, + const struct gkyl_array *fIn, struct gkyl_array *fOut +); /** * Delete updater. * * @param pob Updater to delete. */ -void gkyl_proj_powsqrt_on_basis_release(gkyl_proj_powsqrt_on_basis* up); +void gkyl_proj_powsqrt_on_basis_release(gkyl_proj_powsqrt_on_basis *up); diff --git a/core/zero/gkyl_proj_powsqrt_on_basis_priv.h b/core/zero/gkyl_proj_powsqrt_on_basis_priv.h index 5380fbe9fa..68969a3887 100644 --- a/core/zero/gkyl_proj_powsqrt_on_basis_priv.h +++ b/core/zero/gkyl_proj_powsqrt_on_basis_priv.h @@ -14,10 +14,10 @@ struct gkyl_proj_powsqrt_on_basis { struct gkyl_array *basis_at_ords; // conf-space basis functions at ordinates struct gkyl_array *fun_at_ords; // function (Maxwellian) evaluated at - // ordinates in a cell. + // ordinates in a cell. }; -void -gkyl_proj_powsqrt_on_basis_advance_cu(const gkyl_proj_powsqrt_on_basis *up, - const struct gkyl_range *range, double expIn, const struct gkyl_array *fIn, - struct gkyl_array *fOut); +void gkyl_proj_powsqrt_on_basis_advance_cu( + const gkyl_proj_powsqrt_on_basis *up, const struct gkyl_range *range, double expIn, + const struct gkyl_array *fIn, struct gkyl_array *fOut +); diff --git a/core/zero/gkyl_range.h b/core/zero/gkyl_range.h index 25207600b7..04d08aa723 100644 --- a/core/zero/gkyl_range.h +++ b/core/zero/gkyl_range.h @@ -9,20 +9,21 @@ /** * Series of indexing "functions" to compute linear index into range */ -#define gkyl_ridx1(r, i1) \ - ((r).ac[0]+(i1)*(r).ac[1]) -#define gkyl_ridx2(r, i1, i2) \ - ((r).ac[0]+((i1)*(r).ac[1]+(i2)*(r).ac[2])) -#define gkyl_ridx3(r, i1, i2, i3) \ - (((r).ac[0]+(i1)*(r).ac[1])+((i2)*(r).ac[2]+(i3)*(r).ac[3])) -#define gkyl_ridx4(r, i1, i2, i3, i4) \ - (((r).ac[0]+(i1)*(r).ac[1])+((i2)*(r).ac[2]+(i3)*(r).ac[3]+(i4)*(r).ac[4])) -#define gkyl_ridx5(r, i1, i2, i3, i4, i5) \ - (((r).ac[0]+(i1)*(r).ac[1])+((i2)*(r).ac[2]+(i3)*(r).ac[3])+((i4)*(r).ac[4]+(i5)*(r).ac[5])) -#define gkyl_ridx6(r, i1, i2, i3, i4, i5, i6) \ - (((r).ac[0]+(i1)*(r).ac[1])+((i2)*(r).ac[2]+(i3)*(r).ac[3])+((i4)*(r).ac[4]+(i5)*(r).ac[5]+(i6)*(r).ac[6])) -#define gkyl_ridx7(r, i1, i2, i3, i4, i5, i6, i7) \ - (((r).ac[0]+(i1)*(r).ac[1])+((i2)*(r).ac[2]+(i3)*(r).ac[3])+((i4)*(r).ac[4]+(i5)*(r).ac[5]+(i6)*(r).ac[6]) + (i7)*(r).ac[7]) +#define gkyl_ridx1(r, i1) ((r).ac[0] + (i1) * (r).ac[1]) +#define gkyl_ridx2(r, i1, i2) ((r).ac[0] + ((i1) * (r).ac[1] + (i2) * (r).ac[2])) +#define gkyl_ridx3(r, i1, i2, i3) \ + (((r).ac[0] + (i1) * (r).ac[1]) + ((i2) * (r).ac[2] + (i3) * (r).ac[3])) +#define gkyl_ridx4(r, i1, i2, i3, i4) \ + (((r).ac[0] + (i1) * (r).ac[1]) + ((i2) * (r).ac[2] + (i3) * (r).ac[3] + (i4) * (r).ac[4])) +#define gkyl_ridx5(r, i1, i2, i3, i4, i5) \ + (((r).ac[0] + (i1) * (r).ac[1]) + ((i2) * (r).ac[2] + (i3) * (r).ac[3]) + \ + ((i4) * (r).ac[4] + (i5) * (r).ac[5])) +#define gkyl_ridx6(r, i1, i2, i3, i4, i5, i6) \ + (((r).ac[0] + (i1) * (r).ac[1]) + ((i2) * (r).ac[2] + (i3) * (r).ac[3]) + \ + ((i4) * (r).ac[4] + (i5) * (r).ac[5] + (i6) * (r).ac[6])) +#define gkyl_ridx7(r, i1, i2, i3, i4, i5, i6, i7) \ + (((r).ac[0] + (i1) * (r).ac[1]) + ((i2) * (r).ac[2] + (i3) * (r).ac[3]) + \ + ((i4) * (r).ac[4] + (i5) * (r).ac[5] + (i6) * (r).ac[6]) + (i7) * (r).ac[7]) /** Generic indexing: works for 1D-7D (VFUNC1 is defined-ed in * gkyl_vargm.h) */ @@ -38,7 +39,7 @@ enum gkyl_edge_loc { GKYL_LOWER_EDGE = 0, GKYL_UPPER_EDGE, GKYL_NO_EDGE }; struct gkyl_range_dir_edge { int dir; enum gkyl_edge_loc eloc; -}; +}; /** * Range object, representing an N-dimensional integer index @@ -49,12 +50,12 @@ struct gkyl_range { int lower[GKYL_MAX_DIM]; // lower bound int upper[GKYL_MAX_DIM]; // upper bound (inclusive) long volume; // total volume of range - + // do not access directly uint32_t flags; // Flags for internal use int ilo[GKYL_MAX_DIM]; // for use in inverse indexer - long ac[GKYL_MAX_DIM+1]; // coefficients for indexing - long iac[GKYL_MAX_DIM+1]; // for use in sub-range inverse indexer + long ac[GKYL_MAX_DIM + 1]; // coefficients for indexing + long iac[GKYL_MAX_DIM + 1]; // for use in sub-range inverse indexer long linIdxZero; // linear index of {0,0,...} int nsplit, tid; // number of splits, split ID @@ -91,8 +92,7 @@ struct gkyl_range_skip_iter { * @param lower Lower indices of range * @param upper Upper indices of range */ -void gkyl_range_init(struct gkyl_range *rng, int ndim, - const int *lower, const int *upper); +void gkyl_range_init(struct gkyl_range *rng, int ndim, const int *lower, const int *upper); /** * Create and initialize a new range object. Free with gkyl_range_release. @@ -102,7 +102,7 @@ void gkyl_range_init(struct gkyl_range *rng, int ndim, * @param upper Upper indices of range * @return Pointer to new range object. */ -struct gkyl_range* gkyl_range_new(int ndim, const int *lower, const int *upper); +struct gkyl_range *gkyl_range_new(int ndim, const int *lower, const int *upper); /** * Create new range object from specified shape. This sets the lower @@ -113,8 +113,7 @@ struct gkyl_range* gkyl_range_new(int ndim, const int *lower, const int *upper); * @param shape Shape of region */ -void gkyl_range_init_from_shape(struct gkyl_range *rng, int ndim, - const int *shape); +void gkyl_range_init_from_shape(struct gkyl_range *rng, int ndim, const int *shape); /** * Create new range object from specified shape. This sets the lower @@ -125,8 +124,7 @@ void gkyl_range_init_from_shape(struct gkyl_range *rng, int ndim, * @param shape Shape of region */ -void gkyl_range_init_from_shape1(struct gkyl_range *rng, int ndim, - const int *shape); +void gkyl_range_init_from_shape1(struct gkyl_range *rng, int ndim, const int *shape); /** * Create a new range which is a tensor product of @a a and @a b input @@ -136,8 +134,9 @@ void gkyl_range_init_from_shape1(struct gkyl_range *rng, int ndim, * @param a First operand of tensor-product * @param b Second operand of tensor-product */ -void gkyl_range_ten_prod(struct gkyl_range *rng, const struct gkyl_range *a, - const struct gkyl_range *b); +void gkyl_range_ten_prod( + struct gkyl_range *rng, const struct gkyl_range *a, const struct gkyl_range *b +); /** * Create a new range that is the same shape as inp range, but the @@ -147,8 +146,7 @@ void gkyl_range_ten_prod(struct gkyl_range *rng, const struct gkyl_range *a, * @param inp Input range to shift * @param delta Range indices are shifted by delta[dir] in each direction */ -void gkyl_range_shift(struct gkyl_range *rng, const struct gkyl_range *inp, - const int *delta); +void gkyl_range_shift(struct gkyl_range *rng, const struct gkyl_range *inp, const int *delta); /** * Create a new range that is the same shape as inp range, but lower @@ -158,8 +156,7 @@ void gkyl_range_shift(struct gkyl_range *rng, const struct gkyl_range *inp, * @param inp Input range to reset * @param lower New lower indices */ -void gkyl_range_reset_lower(struct gkyl_range *rng, const struct gkyl_range *inp, - const int *lower); +void gkyl_range_reset_lower(struct gkyl_range *rng, const struct gkyl_range *inp, const int *lower); /** * Shape in direction dir @@ -168,10 +165,9 @@ void gkyl_range_reset_lower(struct gkyl_range *rng, const struct gkyl_range *inp * @param dir Direction to compute shape * @return Shape in direction dit */ -GKYL_CU_DH -static inline int gkyl_range_shape(const struct gkyl_range *rng, int dir) +GKYL_CU_DH static inline int gkyl_range_shape(const struct gkyl_range *rng, int dir) { - return rng->upper[dir]-rng->lower[dir]+1; + return rng->upper[dir] - rng->lower[dir] + 1; } /** @@ -188,12 +184,12 @@ int gkyl_range_is_sub_range(const struct gkyl_range *rng); * @param rng Range obkect * @return 1 if true, 0 otherwise */ -GKYL_CU_DH -static inline int gkyl_range_contains_idx(const struct gkyl_range *rng, const int *idx) +GKYL_CU_DH static inline int gkyl_range_contains_idx(const struct gkyl_range *rng, const int *idx) { - for (int i=0; indim; ++i) { - if ( (idx[i] < rng->lower[i]) || (idx[i] > rng->upper[i]) ) + for (int i = 0; i < rng->ndim; ++i) { + if ((idx[i] < rng->lower[i]) || (idx[i] > rng->upper[i])) { return 0; + } } return 1; } @@ -209,8 +205,9 @@ static inline int gkyl_range_contains_idx(const struct gkyl_range *rng, const in * @param sublower Lower indices of sub-range * @param subupper Upper indices of sub-range */ -void gkyl_sub_range_init(struct gkyl_range *rng, - const struct gkyl_range *bigrng, const int *sublower, const int *subupper); +void gkyl_sub_range_init( + struct gkyl_range *rng, const struct gkyl_range *bigrng, const int *sublower, const int *subupper +); /** * Creates a new range that is a split of the given range. The only @@ -246,8 +243,9 @@ long gkyl_range_split_len(const struct gkyl_range *rng); * @param remDir 'ndim' Array of flags: 0 to keep direction, 1 to remove * @param loc Index to set removed direction. */ -void gkyl_range_deflate(struct gkyl_range* srng, - const struct gkyl_range* rng, const int *remDir, const int *locDir); +void gkyl_range_deflate( + struct gkyl_range *srng, const struct gkyl_range *rng, const int *remDir, const int *locDir +); /** * Return range which has 'dir' direction shortened to length @@ -260,8 +258,9 @@ void gkyl_range_deflate(struct gkyl_range* srng, * @param dir Direction to shorten * @param len Length of shortened direction */ -void gkyl_range_shorten_from_above(struct gkyl_range *rng, - const struct gkyl_range* range, int dir, int len); +void gkyl_range_shorten_from_above( + struct gkyl_range *rng, const struct gkyl_range *range, int dir, int len +); /** * Return range which has 'dir' direction shortened to length @@ -274,8 +273,9 @@ void gkyl_range_shorten_from_above(struct gkyl_range *rng, * @param dir Direction to shorten * @param len Length of shortened direction */ -void gkyl_range_shorten_from_below(struct gkyl_range *rng, - const struct gkyl_range* range, int dir, int len); +void gkyl_range_shorten_from_below( + struct gkyl_range *rng, const struct gkyl_range *range, int dir, int len +); /** * Return a new range that is an extension of the input range. The @@ -287,8 +287,9 @@ void gkyl_range_shorten_from_below(struct gkyl_range *rng, * @param elo Lower in dir is reduced by elo[dir] * @param eup Upper in dir is increased by eup[dir] */ -void gkyl_range_extend(struct gkyl_range *erng, const struct gkyl_range *rng, - const int *elo, const int *eup); +void gkyl_range_extend( + struct gkyl_range *erng, const struct gkyl_range *rng, const int *elo, const int *eup +); /** * Return a new range that is an extension of the input range. The @@ -302,8 +303,9 @@ void gkyl_range_extend(struct gkyl_range *erng, const struct gkyl_range *rng, * @param elo Lower in dir is reduced by elo[dir] * @param eup Upper in dir is increased by eup[dir] */ -void gkyl_range_perp_extend(struct gkyl_range *erng, int dir, - const struct gkyl_range* rng, const int *elo, const int *eup); +void gkyl_range_perp_extend( + struct gkyl_range *erng, int dir, const struct gkyl_range *rng, const int *elo, const int *eup +); /** * Return range in direction 'dir' which corresponds to the "lower @@ -315,8 +317,9 @@ void gkyl_range_perp_extend(struct gkyl_range *erng, int dir, * @param dir Direction to find lower skin cells in * @param nskin Number of skin cells */ -void gkyl_range_lower_skin(struct gkyl_range* srng, - const struct gkyl_range* range, int dir, int nskin); +void gkyl_range_lower_skin( + struct gkyl_range *srng, const struct gkyl_range *range, int dir, int nskin +); /** * Return range in direction 'dir' which corresponds to the "upper @@ -328,8 +331,9 @@ void gkyl_range_lower_skin(struct gkyl_range* srng, * @param dir Direction to find upper skin cells in * @param nskin Number of skin cells */ -void gkyl_range_upper_skin(struct gkyl_range* srng, - const struct gkyl_range* range, int dir, int nskin); +void gkyl_range_upper_skin( + struct gkyl_range *srng, const struct gkyl_range *range, int dir, int nskin +); /** * Create ghost and skin sub-ranges given parent *extended* range. The @@ -370,8 +374,10 @@ void gkyl_range_upper_skin(struct gkyl_range* srng, * @param parent Range for which skin/ghost are computed * @param nghost Number of ghost cells in 'dir' are nghost[dir] */ -void gkyl_skin_ghost_ranges(struct gkyl_range *skin, struct gkyl_range *ghost, - int dir, enum gkyl_edge_loc edge, const struct gkyl_range *parent, const int *nghost); +void gkyl_skin_ghost_ranges( + struct gkyl_range *skin, struct gkyl_range *ghost, int dir, enum gkyl_edge_loc edge, + const struct gkyl_range *parent, const int *nghost +); /** * Create ghost and skin sub-ranges given parent *extended* range. The @@ -412,8 +418,10 @@ void gkyl_skin_ghost_ranges(struct gkyl_range *skin, struct gkyl_range *ghost, * @param parent Range for which skin/ghost are computed * @param nghost Number of ghost cells in 'dir' are nghost[dir] */ -void gkyl_skin_ghost_with_corners_ranges(struct gkyl_range *skin, struct gkyl_range *ghost, - int dir, enum gkyl_edge_loc edge, const struct gkyl_range *parent, const int *nghost); +void gkyl_skin_ghost_with_corners_ranges( + struct gkyl_range *skin, struct gkyl_range *ghost, int dir, enum gkyl_edge_loc edge, + const struct gkyl_range *parent, const int *nghost +); /** * Compute intersection of two ranges. No sub-range information is @@ -424,8 +432,9 @@ void gkyl_skin_ghost_with_corners_ranges(struct gkyl_range *skin, struct gkyl_ra * @param r2 Range to intersect * @return 1 if intersection is not-empty, 0 otherwise */ -int gkyl_range_intersect(struct gkyl_range *irng, const struct gkyl_range *r1, - const struct gkyl_range *r2); +int gkyl_range_intersect( + struct gkyl_range *irng, const struct gkyl_range *r1, const struct gkyl_range *r2 +); /** * Compute intersection of two ranges. The intersection is a sub-range @@ -436,8 +445,9 @@ int gkyl_range_intersect(struct gkyl_range *irng, const struct gkyl_range *r1, * @param r2 Range to intersect * @return 1 if intersection is not-empty, 0 otherwise */ -int gkyl_sub_range_intersect(struct gkyl_range* irng, - const struct gkyl_range *r1, const struct gkyl_range *r2); +int gkyl_sub_range_intersect( + struct gkyl_range *irng, const struct gkyl_range *r1, const struct gkyl_range *r2 +); /** * Check if range touches the lower edge of parent range in direction @@ -448,8 +458,9 @@ int gkyl_sub_range_intersect(struct gkyl_range* irng, * @param parent Parent range * @return true if range is on lower edge, false otherwise */ -bool gkyl_range_is_on_lower_edge(int dir, const struct gkyl_range *range, - const struct gkyl_range *parent); +bool gkyl_range_is_on_lower_edge( + int dir, const struct gkyl_range *range, const struct gkyl_range *parent +); /** * Check if range touches the upper edge of parent range in direction @@ -460,8 +471,9 @@ bool gkyl_range_is_on_lower_edge(int dir, const struct gkyl_range *range, * @param parent Parent range * @return true if range is on upper edge, false otherwise */ -bool gkyl_range_is_on_upper_edge(int dir, const struct gkyl_range *range, - const struct gkyl_range *parent); +bool gkyl_range_is_on_upper_edge( + int dir, const struct gkyl_range *range, const struct gkyl_range *parent +); /** * Check if @a targ range shares an edge with the @a base range. The @@ -473,9 +485,9 @@ bool gkyl_range_is_on_upper_edge(int dir, const struct gkyl_range *range, * @return direction and edge. Returned struct eloc is set * to GKYL_NO_EDGE if ranges dont match. */ -struct gkyl_range_dir_edge gkyl_range_edge_match(const struct gkyl_range *base, - const struct gkyl_range *targ); - +struct gkyl_range_dir_edge +gkyl_range_edge_match(const struct gkyl_range *base, const struct gkyl_range *targ); + /** * General indexing function. Returns linear index into the index * range mapped by 'range'. @@ -483,36 +495,34 @@ struct gkyl_range_dir_edge gkyl_range_edge_match(const struct gkyl_range *base, * @param range Range object to index * @param idx Index for which to compute linear index */ -GKYL_CU_DH -static inline long -gkyl_range_idx(const struct gkyl_range* range, const int *idx) +GKYL_CU_DH static inline long gkyl_range_idx(const struct gkyl_range *range, const int *idx) { #define RI(...) gkyl_ridx(*range, __VA_ARGS__) switch (range->ndim) { - case 0: - return range->ac[0]; - break; - case 1: - return RI(idx[0]); - break; - case 2: - return RI(idx[0], idx[1]); - break; - case 3: - return RI(idx[0], idx[1], idx[2]); - break; - case 4: - return RI(idx[0], idx[1], idx[2], idx[3]); - break; - case 5: - return RI(idx[0], idx[1], idx[2], idx[3], idx[4]); - break; - case 6: - return RI(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); - break; - case 7: - return RI(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5], idx[6]); - break; + case 0: + return range->ac[0]; + break; + case 1: + return RI(idx[0]); + break; + case 2: + return RI(idx[0], idx[1]); + break; + case 3: + return RI(idx[0], idx[1], idx[2]); + break; + case 4: + return RI(idx[0], idx[1], idx[2], idx[3]); + break; + case 5: + return RI(idx[0], idx[1], idx[2], idx[3], idx[4]); + break; + case 6: + return RI(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); + break; + case 7: + return RI(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5], idx[6]); + break; } return 0; #undef RI @@ -527,9 +537,7 @@ gkyl_range_idx(const struct gkyl_range* range, const int *idx) * @param idx Relative index for offset calculation * @return Relatice offset to idx. */ -GKYL_CU_DH -static inline long -gkyl_range_offset(const struct gkyl_range* range, const int *idx) +GKYL_CU_DH static inline long gkyl_range_offset(const struct gkyl_range *range, const int *idx) { return gkyl_range_idx(range, idx) - range->linIdxZero; } @@ -542,15 +550,13 @@ gkyl_range_offset(const struct gkyl_range* range, const int *idx) * @param loc Linear index in [0, range->volume) * @param idx On output, the N-dimensional index into 'range' */ -GKYL_CU_DH -static inline void -gkyl_range_inv_idx(const struct gkyl_range *range, long loc, int *idx) +GKYL_CU_DH static inline void gkyl_range_inv_idx(const struct gkyl_range *range, long loc, int *idx) { long n = loc; - for (int i=1; i<=range->ndim; ++i) { - long quot = n/range->ac[i]; + for (int i = 1; i <= range->ndim; ++i) { + long quot = n / range->ac[i]; long rem = n % range->ac[i]; - idx[i-1] = quot + range->ilo[i-1]; + idx[i - 1] = quot + range->ilo[i - 1]; n = rem; } } @@ -564,15 +570,14 @@ gkyl_range_inv_idx(const struct gkyl_range *range, long loc, int *idx) * @param loc Linear index in [0, range->volume) * @param idx On output, the N-dimensional index into 'range' */ -GKYL_CU_DH -static inline void +GKYL_CU_DH static inline void gkyl_sub_range_inv_idx(const struct gkyl_range *range, long loc, int *idx) { long n = loc; - for (int i=1; i<=range->ndim; ++i) { - long quot = n/range->iac[i]; + for (int i = 1; i <= range->ndim; ++i) { + long quot = n / range->iac[i]; long rem = n % range->iac[i]; - idx[i-1] = quot + range->lower[i-1]; + idx[i - 1] = quot + range->lower[i - 1]; n = rem; } } @@ -585,8 +590,7 @@ gkyl_sub_range_inv_idx(const struct gkyl_range *range, long loc, int *idx) * @param range Range object. * @return New iterator object for 'range' */ -void gkyl_range_iter_init(struct gkyl_range_iter *iter, - const struct gkyl_range* range); +void gkyl_range_iter_init(struct gkyl_range_iter *iter, const struct gkyl_range *range); /** * Create iterator, ignoring split information in range. @@ -594,8 +598,7 @@ void gkyl_range_iter_init(struct gkyl_range_iter *iter, * @param range Range object. * @return New iterator object for 'range' */ -void gkyl_range_iter_no_split_init(struct gkyl_range_iter *iter, - const struct gkyl_range* range); +void gkyl_range_iter_no_split_init(struct gkyl_range_iter *iter, const struct gkyl_range *range); /** * Get next index into range. The iter->idx array holds the next @@ -613,8 +616,7 @@ int gkyl_range_iter_next(struct gkyl_range_iter *iter); * @param range Range object. * @return New iterator object for 'range' */ -void gkyl_range_skip_iter_init(struct gkyl_range_skip_iter *iter, - const struct gkyl_range* range); +void gkyl_range_skip_iter_init(struct gkyl_range_skip_iter *iter, const struct gkyl_range *range); /** * Print range information to file object. @@ -623,7 +625,7 @@ void gkyl_range_skip_iter_init(struct gkyl_range_skip_iter *iter, * @param nm Name of range * @param fp File object to print range information */ -void gkyl_print_range(const struct gkyl_range* range, const char *nm, FILE *fp); +void gkyl_print_range(const struct gkyl_range *range, const char *nm, FILE *fp); /** * Compares two ranges: ranges are the same if they have the same @@ -633,14 +635,14 @@ void gkyl_print_range(const struct gkyl_range* range, const char *nm, FILE *fp); * @param r2 Range 2 to compare * @return true if ranges are same, false otherwise */ -bool gkyl_range_compare(const struct gkyl_range* r1, const struct gkyl_range* r2); +bool gkyl_range_compare(const struct gkyl_range *r1, const struct gkyl_range *r2); /** * Get the number of dimensions from range (for opaque pointer). * * @return Number of dimensions. */ -int gkyl_range_get_ndim(const struct gkyl_range* range); +int gkyl_range_get_ndim(const struct gkyl_range *range); /** * Get the lower extents of a range (for opaque pointer). @@ -648,7 +650,7 @@ int gkyl_range_get_ndim(const struct gkyl_range* range); * @param range Range object. * @param lower Lower extents of the range (pre-allocated). */ -void gkyl_range_get_lower(const struct gkyl_range* range, int *lower); +void gkyl_range_get_lower(const struct gkyl_range *range, int *lower); /** * Get the upper extents of a range (for opaque pointer). @@ -656,7 +658,7 @@ void gkyl_range_get_lower(const struct gkyl_range* range, int *lower); * @param range Range object. * @param upper Upper extents of the range (pre-allocated). */ -void gkyl_range_get_upper(const struct gkyl_range* range, int *upper); +void gkyl_range_get_upper(const struct gkyl_range *range, int *upper); /** * Get the volume of a range (for opaque pointer). @@ -664,12 +666,11 @@ void gkyl_range_get_upper(const struct gkyl_range* range, int *upper); * @param range Range object. * @return Volume of the range. */ -long gkyl_range_get_volume(const struct gkyl_range* range); +long gkyl_range_get_volume(const struct gkyl_range *range); /** * Free dynamically allocated range object (with gkyl_range_new). * * @param range Range object. */ -void gkyl_range_release(struct gkyl_range* range); - +void gkyl_range_release(struct gkyl_range *range); diff --git a/core/zero/gkyl_rect_decomp.h b/core/zero/gkyl_rect_decomp.h index a0dff044a5..e028cef395 100644 --- a/core/zero/gkyl_rect_decomp.h +++ b/core/zero/gkyl_rect_decomp.h @@ -14,7 +14,7 @@ struct gkyl_rect_decomp { struct gkyl_ref_count ref_count; }; -// List of neighbors +// List of neighbors struct gkyl_rect_decomp_neigh { int num_neigh; // number of neighbors const int *neigh; // list of neighbors @@ -35,8 +35,8 @@ struct gkyl_rect_decomp_neigh { * @param range Range to decompose * @return Decomposition of @a range */ -struct gkyl_rect_decomp* gkyl_rect_decomp_new_from_cuts(int ndim, const int cuts[], - const struct gkyl_range *range); +struct gkyl_rect_decomp * +gkyl_rect_decomp_new_from_cuts(int ndim, const int cuts[], const struct gkyl_range *range); /** * Create a new decomposition given @a cuts and cells in each @@ -48,8 +48,8 @@ struct gkyl_rect_decomp* gkyl_rect_decomp_new_from_cuts(int ndim, const int cuts * @param cells Number of cells in each direction * @return Decomposition of range based on cuts */ -struct gkyl_rect_decomp *gkyl_rect_decomp_new_from_cuts_and_cells(int ndim, - const int cuts[], const int cells[]); +struct gkyl_rect_decomp * +gkyl_rect_decomp_new_from_cuts_and_cells(int ndim, const int cuts[], const int cells[]); /** * Create a new decomposition from a given decomposition. The new @@ -59,8 +59,9 @@ struct gkyl_rect_decomp *gkyl_rect_decomp_new_from_cuts_and_cells(int ndim, * @param arange Range to extend by * @return New extended decomposition */ -struct gkyl_rect_decomp *gkyl_rect_decomp_extended_new(const struct gkyl_range *arange, - const struct gkyl_rect_decomp *decomp); +struct gkyl_rect_decomp *gkyl_rect_decomp_extended_new( + const struct gkyl_range *arange, const struct gkyl_rect_decomp *decomp +); /** * Acquire a pointer to the decomposition. @@ -68,7 +69,7 @@ struct gkyl_rect_decomp *gkyl_rect_decomp_extended_new(const struct gkyl_range * * @param decomp Decom to acquire pointer to * @return New decomposition */ -struct gkyl_rect_decomp* gkyl_rect_decomp_acquire(const struct gkyl_rect_decomp *decomp); +struct gkyl_rect_decomp *gkyl_rect_decomp_acquire(const struct gkyl_rect_decomp *decomp); /** * Check if decomposition is a valid covering of the range. @@ -90,8 +91,8 @@ bool gkyl_rect_decomp_check_covering(const struct gkyl_rect_decomp *decomp); * @param nidx Index of range for which neighbor data is needed * @return Neighbor list for range nidx */ -struct gkyl_rect_decomp_neigh* gkyl_rect_decomp_calc_neigh( - const struct gkyl_rect_decomp *decomp, bool inc_corners, int nidx); +struct gkyl_rect_decomp_neigh * +gkyl_rect_decomp_calc_neigh(const struct gkyl_rect_decomp *decomp, bool inc_corners, int nidx); /** * Compute the periodic neighbor of range @a nidx in the specified @@ -104,8 +105,9 @@ struct gkyl_rect_decomp_neigh* gkyl_rect_decomp_calc_neigh( * @param nidx Index of range for which neighbor data is needed * @return Periodic neighbor list for range nidx */ -struct gkyl_rect_decomp_neigh* gkyl_rect_decomp_calc_periodic_neigh( - const struct gkyl_rect_decomp *decomp, int dir, bool inc_corners, int nidx); +struct gkyl_rect_decomp_neigh *gkyl_rect_decomp_calc_periodic_neigh( + const struct gkyl_rect_decomp *decomp, int dir, bool inc_corners, int nidx +); /** * Free neighbor memory @@ -154,9 +156,10 @@ void gkyl_create_global_range(int ndim, const int *cells, struct gkyl_range *ran * @param ext_range On output, extended range spanning grid+ghost-cells * @param range On output, range spanning grid. Sub-range of ext_range. */ -void gkyl_create_grid_ranges(const struct gkyl_rect_grid *grid, - const int *nghost, struct gkyl_range *ext_range, - struct gkyl_range *range); +void gkyl_create_grid_ranges( + const struct gkyl_rect_grid *grid, const int *nghost, struct gkyl_range *ext_range, + struct gkyl_range *range +); /** * Create range and extended ranges from given range and ghost-cell @@ -167,8 +170,10 @@ void gkyl_create_grid_ranges(const struct gkyl_rect_grid *grid, * @param ext_range On output, extended range spanning inrange+ghost-cells * @param range On output, range same as inrange, but sub-range of ext_range. */ -void gkyl_create_ranges(const struct gkyl_range *inrange, - const int *nghost, struct gkyl_range *ext_range, struct gkyl_range *range); +void gkyl_create_ranges( + const struct gkyl_range *inrange, const int *nghost, struct gkyl_range *ext_range, + struct gkyl_range *range +); /** * Create range and extended vertex ranges from given range and ghost-cell @@ -179,8 +184,10 @@ void gkyl_create_ranges(const struct gkyl_range *inrange, * @param ext_range On output, extended range spanning inrange+ghost-cells * @param range On output, range same as inrange, but sub-range of ext_range. */ -void gkyl_create_vertex_ranges(const struct gkyl_range *inrange, - const int *nghost, struct gkyl_range *ext_range, struct gkyl_range *range); +void gkyl_create_vertex_ranges( + const struct gkyl_range *inrange, const int *nghost, struct gkyl_range *ext_range, + struct gkyl_range *range +); /** * Return the cuts used to create the the decomposition object. @@ -188,4 +195,4 @@ void gkyl_create_vertex_ranges(const struct gkyl_range *inrange, * @param decomp Decomposition object. * @param cuts Output cuts in each direction. */ -void gkyl_rect_decomp_get_cuts(struct gkyl_rect_decomp* decomp, int* cuts); +void gkyl_rect_decomp_get_cuts(struct gkyl_rect_decomp *decomp, int *cuts); diff --git a/core/zero/gkyl_rect_grid.h b/core/zero/gkyl_rect_grid.h index dbf7d6f150..87c3a978cd 100644 --- a/core/zero/gkyl_rect_grid.h +++ b/core/zero/gkyl_rect_grid.h @@ -13,7 +13,7 @@ struct gkyl_rect_grid { int ndim; // number of dimensions double lower[GKYL_MAX_DIM]; // lower-left corner double upper[GKYL_MAX_DIM]; // upper-right corner - int cells[GKYL_MAX_DIM]; // number of cells + int cells[GKYL_MAX_DIM]; // number of cells double dx[GKYL_MAX_DIM]; // cell spacing double cellVolume; // cell volume }; @@ -27,8 +27,9 @@ struct gkyl_rect_grid { * @param upper Coordinates of upper-right corner of grid * @param cells Number of cells in each direction */ -void gkyl_rect_grid_init(struct gkyl_rect_grid *grid, int ndim, - const double *lower, const double *upper, const int *cells); +void gkyl_rect_grid_init( + struct gkyl_rect_grid *grid, int ndim, const double *lower, const double *upper, const int *cells +); /** * Create and initialize a new grid object. Release with gkyl_rect_grid_release. @@ -39,8 +40,8 @@ void gkyl_rect_grid_init(struct gkyl_rect_grid *grid, int ndim, * @param upper Coordinates of upper-right corner of grid * @param cells Number of cells in each direction */ -struct gkyl_rect_grid* gkyl_rect_grid_new(int ndim, - const double *lower, const double *upper, const int *cells); +struct gkyl_rect_grid * +gkyl_rect_grid_new(int ndim, const double *lower, const double *upper, const int *cells); /** * Find cell indices of point @@ -52,9 +53,10 @@ struct gkyl_rect_grid* gkyl_rect_grid_new(int ndim, * @param cell_index Pointer to cell indices. * Asserts: point lies within cell(s) specified by known_index (if specified). */ -GKYL_CU_DH -void gkyl_rect_grid_find_cell(const struct gkyl_rect_grid *grid, const double *point, - const bool *pick_lower, const int *known_index, int *cell_index); +GKYL_CU_DH void gkyl_rect_grid_find_cell( + const struct gkyl_rect_grid *grid, const double *point, const bool *pick_lower, + const int *known_index, int *cell_index +); /** * Get cell-center coordinates. Note that idx is a 1-based cell index, @@ -64,13 +66,12 @@ void gkyl_rect_grid_find_cell(const struct gkyl_rect_grid *grid, const double *p * @param idx Index of cell (lower-left corner has all index (1,1,...) ) * @param xc On output, cell-center coordinates of cell 'idx' */ -GKYL_CU_DH -static inline void -gkyl_rect_grid_cell_center(const struct gkyl_rect_grid *grid, - const int *idx, double *xc) +GKYL_CU_DH static inline void +gkyl_rect_grid_cell_center(const struct gkyl_rect_grid *grid, const int *idx, double *xc) { - for (int i=0; indim; ++i) - xc[i] = grid->lower[i]+(idx[i]-0.5)*grid->dx[i]; + for (int i = 0; i < grid->ndim; ++i) { + xc[i] = grid->lower[i] + (idx[i] - 0.5) * grid->dx[i]; + } } /** @@ -81,13 +82,12 @@ gkyl_rect_grid_cell_center(const struct gkyl_rect_grid *grid, * @param idx Index of cell (lower-left corner has all index (1,1,...) ) * @param xn On output, coordinates of lower-left node */ -GKYL_CU_DH -static inline void -gkyl_rect_grid_ll_node(const struct gkyl_rect_grid *grid, - const int *idx, double *xc) +GKYL_CU_DH static inline void +gkyl_rect_grid_ll_node(const struct gkyl_rect_grid *grid, const int *idx, double *xc) { - for (int i=0; indim; ++i) - xc[i] = grid->lower[i]+(idx[i]-1)*grid->dx[i]; + for (int i = 0; i < grid->ndim; ++i) { + xc[i] = grid->lower[i] + (idx[i] - 1) * grid->dx[i]; + } } /** @@ -97,11 +97,11 @@ gkyl_rect_grid_ll_node(const struct gkyl_rect_grid *grid, * @param dir Direction in which to get extents * @param ext On output, inclusive extents in direction @a dir. */ -GKYL_CU_DH -static inline void +GKYL_CU_DH static inline void gkyl_rect_grid_extents(const struct gkyl_rect_grid *grid, int dir, int ext[2]) { - ext[0] = 1; ext[1] = grid->cells[dir]; + ext[0] = 1; + ext[1] = grid->cells[dir]; } /** @@ -111,15 +111,14 @@ gkyl_rect_grid_extents(const struct gkyl_rect_grid *grid, int dir, int ext[2]) * @param xn Coordinate of point in grid * @param idx On output, index of point in grid */ -GKYL_CU_DH -static inline void -gkyl_rect_grid_coord_idx(const struct gkyl_rect_grid *grid, - const double *xn, int *idx) +GKYL_CU_DH static inline void +gkyl_rect_grid_coord_idx(const struct gkyl_rect_grid *grid, const double *xn, int *idx) { - for (int d=0; dndim; ++d) { - int ext[2]; gkyl_rect_grid_extents(grid, d, ext); + for (int d = 0; d < grid->ndim; ++d) { + int ext[2]; + gkyl_rect_grid_extents(grid, d, ext); double xlower = grid->lower[d], dx = grid->dx[d]; - idx[d] = ext[0] + (int) floor((xn[d]-xlower)/dx); + idx[d] = ext[0] + (int)floor((xn[d] - xlower) / dx); } } diff --git a/core/zero/gkyl_rect_grid_priv.h b/core/zero/gkyl_rect_grid_priv.h index 7dbd554f1f..74c14f87d2 100644 --- a/core/zero/gkyl_rect_grid_priv.h +++ b/core/zero/gkyl_rect_grid_priv.h @@ -10,19 +10,20 @@ * @params lower_boundaries: lower sides of given cell (output) * @params upper_boundaries: upper sides of given cell (output) */ -GKYL_CU_DH -void in_dir(const struct gkyl_rect_grid *grid, int *cell_in, const int *dim_trans, - const int *known_index, double lower_boundaries[], double upper_boundaries[]) +GKYL_CU_DH void in_dir( + const struct gkyl_rect_grid *grid, int *cell_in, const int *dim_trans, const int *known_index, + double lower_boundaries[], double upper_boundaries[] +) { int ndim, check_index; const double *dx, *lower; - ndim = grid -> ndim; - dx = grid -> dx; - lower = grid -> lower; - for (int d=0; dndim; + dx = grid->dx; + lower = grid->lower; + for (int d = 0; d < ndim; d++) { check_index = known_index[d] < 0 ? cell_in[dim_trans[d]] : known_index[d]; - lower_boundaries[d] = lower[d]+(check_index-1)*dx[d]; - upper_boundaries[d] = lower[d]+(check_index)*dx[d]; + lower_boundaries[d] = lower[d] + (check_index - 1) * dx[d]; + upper_boundaries[d] = lower[d] + (check_index)*dx[d]; } } @@ -34,26 +35,27 @@ void in_dir(const struct gkyl_rect_grid *grid, int *cell_in, const int *dim_tran * @params known_index: Any already known indices * @returns bool: true if point is in given cell */ -GKYL_CU_DH -bool is_in_cell(const struct gkyl_rect_grid *grid, const double *point, - int *cell_in, const int *dim_trans, const int *known_index) +GKYL_CU_DH bool is_in_cell( + const struct gkyl_rect_grid *grid, const double *point, int *cell_in, const int *dim_trans, + const int *known_index +) { int ndim; - ndim = grid -> ndim; + ndim = grid->ndim; double lower_boundaries[ndim], upper_boundaries[ndim]; - for (int d=0; ddx[d]>point[d] || upper_boundaries[d]+eps*grid->dx[d]dx[d] > point[d] || + upper_boundaries[d] + eps * grid->dx[d] < point[d]) { in_cell = false; break; } } return in_cell; } - diff --git a/core/zero/gkyl_ref_count.h b/core/zero/gkyl_ref_count.h index 7e72e93bde..8ff0961b51 100644 --- a/core/zero/gkyl_ref_count.h +++ b/core/zero/gkyl_ref_count.h @@ -9,7 +9,7 @@ * Object holding use count and pointer to destructor function. */ struct gkyl_ref_count { - void (*free)(const struct gkyl_ref_count* ); + void (*free)(const struct gkyl_ref_count *); int count; }; @@ -20,13 +20,9 @@ struct gkyl_ref_count { * @param free Function pointer to the delete function * @return Ref object */ -static inline struct gkyl_ref_count -gkyl_ref_count_init(void (*free)(const struct gkyl_ref_count* )) +static inline struct gkyl_ref_count gkyl_ref_count_init(void (*free)(const struct gkyl_ref_count *)) { - return (struct gkyl_ref_count) { - .free = free, - .count = 1, - }; + return (struct gkyl_ref_count){.free = free, .count = 1}; } /** @@ -34,8 +30,7 @@ gkyl_ref_count_init(void (*free)(const struct gkyl_ref_count* )) * * @param ref Object to increment. */ -static inline void -gkyl_ref_count_inc(const struct gkyl_ref_count *ref) +static inline void gkyl_ref_count_inc(const struct gkyl_ref_count *ref) { ((struct gkyl_ref_count *)ref)->count++; } @@ -46,9 +41,9 @@ gkyl_ref_count_inc(const struct gkyl_ref_count *ref) * * @param ref Object to decrement. */ -static inline void -gkyl_ref_count_dec(const struct gkyl_ref_count *ref) +static inline void gkyl_ref_count_dec(const struct gkyl_ref_count *ref) { - if (--((struct gkyl_ref_count *)ref)->count == 0) + if (--((struct gkyl_ref_count *)ref)->count == 0) { ref->free(ref); + } } diff --git a/core/zero/gkyl_rrobin_decomp.h b/core/zero/gkyl_rrobin_decomp.h index df99fa7fce..cb134e7cc0 100644 --- a/core/zero/gkyl_rrobin_decomp.h +++ b/core/zero/gkyl_rrobin_decomp.h @@ -4,7 +4,7 @@ struct gkyl_rrobin_decomp { int total_ranks; // total number of ranks in decomp int nblocks; // number of blocks in decomposition -}; +}; /** * Create a new round-robin decomposition with given @a total_ranks, @@ -15,8 +15,8 @@ struct gkyl_rrobin_decomp { * @param branks An array of @a nblocks size, each with ranks in each block * @return New round-robin decomposition */ -const struct gkyl_rrobin_decomp* gkyl_rrobin_decomp_new(int total_ranks, int nblocks, - const int *branks); +const struct gkyl_rrobin_decomp * +gkyl_rrobin_decomp_new(int total_ranks, int nblocks, const int *branks); /** * Get number of ranks in block @a bn. diff --git a/core/zero/gkyl_skin_surf_from_ghost.h b/core/zero/gkyl_skin_surf_from_ghost.h index 6e53aa2134..635cb7ba1e 100644 --- a/core/zero/gkyl_skin_surf_from_ghost.h +++ b/core/zero/gkyl_skin_surf_from_ghost.h @@ -31,9 +31,10 @@ typedef struct gkyl_skin_surf_from_ghost gkyl_skin_surf_from_ghost; * @param use_gpu Boolean flag to indicate whether GPU computation should be used. * @return Pointer to the newly created updater. */ -struct gkyl_skin_surf_from_ghost* gkyl_skin_surf_from_ghost_new(int dir, enum gkyl_edge_loc edge, - const struct gkyl_basis basis, const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, - bool use_gpu); +struct gkyl_skin_surf_from_ghost *gkyl_skin_surf_from_ghost_new( + int dir, enum gkyl_edge_loc edge, const struct gkyl_basis basis, const struct gkyl_range *skin_r, + const struct gkyl_range *ghost_r, bool use_gpu +); /** * Enforce that the value of the skin cell at the node facing the ghost cell is equal to the ghost value @@ -42,7 +43,9 @@ struct gkyl_skin_surf_from_ghost* gkyl_skin_surf_from_ghost_new(int dir, enum gk * @param up Pointer to the boundary condition updater. * @param field Array representing the field values to update (currently works only in configuration space). */ -void gkyl_skin_surf_from_ghost_advance(const struct gkyl_skin_surf_from_ghost *up, struct gkyl_array *field); +void gkyl_skin_surf_from_ghost_advance( + const struct gkyl_skin_surf_from_ghost *up, struct gkyl_array *field +); /** * Free the memory associated with the skin_surf_from_ghost updater. diff --git a/core/zero/gkyl_skin_surf_from_ghost_priv.h b/core/zero/gkyl_skin_surf_from_ghost_priv.h index b010d235e4..25efaa53b8 100644 --- a/core/zero/gkyl_skin_surf_from_ghost_priv.h +++ b/core/zero/gkyl_skin_surf_from_ghost_priv.h @@ -9,73 +9,40 @@ // Function pointer type for the kernel setting the skin value equal to the ghost value at surface typedef void (*skin_surf_from_ghost_t)(const double *fghost, double *fskin); -typedef struct { skin_surf_from_ghost_t kernels[2]; } skin_surf_from_ghost_kern_list; // For use in kernel tables. -typedef struct { skin_surf_from_ghost_kern_list dirlist[3]; } dir_skin_surf_from_ghost_kern_list; -typedef struct { dir_skin_surf_from_ghost_kern_list edgedlist[3]; } edged_skin_surf_from_ghost_kern_list; +typedef struct { + skin_surf_from_ghost_t kernels[2]; +} skin_surf_from_ghost_kern_list; // For use in kernel tables. +typedef struct { + skin_surf_from_ghost_kern_list dirlist[3]; +} dir_skin_surf_from_ghost_kern_list; +typedef struct { + dir_skin_surf_from_ghost_kern_list edgedlist[3]; +} edged_skin_surf_from_ghost_kern_list; // Serendipity kernels. -GKYL_CU_D -static const edged_skin_surf_from_ghost_kern_list ser_skin_surf_from_ghost_list[] = { - { - .edgedlist= - { - { - .dirlist= - { - { skin_surf_from_ghost_lowerx_1x_ser_p1, NULL }, - { NULL, NULL }, - { NULL, NULL }, - } - }, - { - .dirlist= - { - { skin_surf_from_ghost_lowerx_2x_ser_p1, NULL }, - { skin_surf_from_ghost_lowery_2x_ser_p1, NULL }, - { NULL, NULL }, - } - }, - { - .dirlist= - { - { skin_surf_from_ghost_lowerx_3x_ser_p1, NULL }, - { skin_surf_from_ghost_lowery_3x_ser_p1, NULL }, - { skin_surf_from_ghost_lowerz_3x_ser_p1, NULL }, - } - } - } - }, - { - .edgedlist= - { - { - .dirlist= - { - { skin_surf_from_ghost_upperx_1x_ser_p1, NULL }, - { NULL, NULL }, - { NULL, NULL }, - } - }, - { - .dirlist= - { - { skin_surf_from_ghost_upperx_2x_ser_p1, NULL }, - { skin_surf_from_ghost_uppery_2x_ser_p1, NULL }, - { NULL, NULL }, - } - }, - { - .dirlist= - { - { skin_surf_from_ghost_upperx_3x_ser_p1, NULL }, - { skin_surf_from_ghost_uppery_3x_ser_p1, NULL }, - { skin_surf_from_ghost_upperz_3x_ser_p1, NULL }, - } - } - } - } +GKYL_CU_D static const edged_skin_surf_from_ghost_kern_list ser_skin_surf_from_ghost_list[] = { + {.edgedlist = + {{.dirlist = {{skin_surf_from_ghost_lowerx_1x_ser_p1, NULL}, {NULL, NULL}, {NULL, NULL}}}, + {.dirlist = + {{skin_surf_from_ghost_lowerx_2x_ser_p1, NULL}, + {skin_surf_from_ghost_lowery_2x_ser_p1, NULL}, + {NULL, NULL}}}, + {.dirlist = + {{skin_surf_from_ghost_lowerx_3x_ser_p1, NULL}, + {skin_surf_from_ghost_lowery_3x_ser_p1, NULL}, + {skin_surf_from_ghost_lowerz_3x_ser_p1, NULL}}}}}, + {.edgedlist = + {{.dirlist = {{skin_surf_from_ghost_upperx_1x_ser_p1, NULL}, {NULL, NULL}, {NULL, NULL}}}, + {.dirlist = + {{skin_surf_from_ghost_upperx_2x_ser_p1, NULL}, + {skin_surf_from_ghost_uppery_2x_ser_p1, NULL}, + {NULL, NULL}}}, + {.dirlist = + {{skin_surf_from_ghost_upperx_3x_ser_p1, NULL}, + {skin_surf_from_ghost_uppery_3x_ser_p1, NULL}, + {skin_surf_from_ghost_upperz_3x_ser_p1, NULL}}}}} }; - + struct gkyl_skin_surf_from_ghost_kernels { skin_surf_from_ghost_t ghost_to_skin; }; @@ -85,22 +52,27 @@ struct gkyl_skin_surf_from_ghost { int dir, cdim; enum gkyl_edge_loc edge; bool use_gpu; - struct gkyl_skin_surf_from_ghost_kernels *kernels; // skin surface from ghost kernel. - struct gkyl_skin_surf_from_ghost_kernels *kernels_cu; // device copy. + struct gkyl_skin_surf_from_ghost_kernels *kernels; // skin surface from ghost kernel. + struct gkyl_skin_surf_from_ghost_kernels *kernels_cu; // device copy. const struct gkyl_range *skin_r, *ghost_r; }; #ifdef GKYL_HAVE_CUDA -void skin_surf_from_ghost_choose_kernel_cu(const struct gkyl_basis basis, enum gkyl_edge_loc edge, - int dir, struct gkyl_skin_surf_from_ghost_kernels *kers); +void skin_surf_from_ghost_choose_kernel_cu( + const struct gkyl_basis basis, enum gkyl_edge_loc edge, int dir, + struct gkyl_skin_surf_from_ghost_kernels *kers +); -void skin_surf_from_ghost_advance_cu(const struct gkyl_skin_surf_from_ghost *up, struct gkyl_array *field); +void skin_surf_from_ghost_advance_cu( + const struct gkyl_skin_surf_from_ghost *up, struct gkyl_array *field +); #endif -GKYL_CU_D -static void skin_surf_from_ghost_choose_kernel(const struct gkyl_basis basis, enum gkyl_edge_loc edge, - int dir, bool use_gpu, struct gkyl_skin_surf_from_ghost_kernels *kernels) +GKYL_CU_D static void skin_surf_from_ghost_choose_kernel( + const struct gkyl_basis basis, enum gkyl_edge_loc edge, int dir, bool use_gpu, + struct gkyl_skin_surf_from_ghost_kernels *kernels +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { @@ -113,11 +85,12 @@ static void skin_surf_from_ghost_choose_kernel(const struct gkyl_basis basis, en enum gkyl_basis_type basis_type = basis.b_type; int poly_order = basis.poly_order; switch (basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - kernels->ghost_to_skin = ser_skin_surf_from_ghost_list[edge].edgedlist[dim-1].dirlist[dir].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + kernels->ghost_to_skin = + ser_skin_surf_from_ghost_list[edge].edgedlist[dim - 1].dirlist[dir].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } } diff --git a/core/zero/gkyl_superlu_ops.h b/core/zero/gkyl_superlu_ops.h index c69cbb2f97..5879dd18e4 100644 --- a/core/zero/gkyl_superlu_ops.h +++ b/core/zero/gkyl_superlu_ops.h @@ -18,7 +18,7 @@ typedef struct gkyl_superlu_prob gkyl_superlu_prob; * dimensions and sparsity pattern) where each problem only has a * right-side vector with a single column. */ -struct gkyl_superlu_prob* gkyl_superlu_prob_new(int nprob, int mrow, int ncol, int nrhs); +struct gkyl_superlu_prob *gkyl_superlu_prob_new(int nprob, int mrow, int ncol, int nrhs); /** * Initialize SuperLU matrix A in Ax=B problem from a list of triples. @@ -72,7 +72,9 @@ void gkyl_superlu_solve(struct gkyl_superlu_prob *prob); * @param prob SuperLu struct holding arrays used in problem. * @param tri coordinates & values of non-zero entries in A matrix (triplets). */ -void gkyl_superlu_amat_update_from_triples(struct gkyl_superlu_prob *prob, struct gkyl_mat_triples **tri); +void gkyl_superlu_amat_update_from_triples( + struct gkyl_superlu_prob *prob, struct gkyl_mat_triples **tri +); /** * Obtain the RHS ielement-th value of the jprob-th linear problem. @@ -91,7 +93,7 @@ double gkyl_superlu_get_rhs_ij(struct gkyl_superlu_prob *prob, long ielement, lo */ double gkyl_superlu_get_rhs_lin(struct gkyl_superlu_prob *prob, long loc); -double* gkyl_superlu_get_rhs_ptr(struct gkyl_superlu_prob *prob, long loc); +double *gkyl_superlu_get_rhs_ptr(struct gkyl_superlu_prob *prob, long loc); /** * Release SuperLU problem diff --git a/core/zero/gkyl_tensor_field.h b/core/zero/gkyl_tensor_field.h index eb64dd303b..982318fab7 100644 --- a/core/zero/gkyl_tensor_field.h +++ b/core/zero/gkyl_tensor_field.h @@ -3,11 +3,8 @@ #include #include -enum gkyl_tensor_index_loc { - GKYL_TENSOR_INDEX_LOWER, - GKYL_TENSOR_INDEX_UPPER, -}; - +enum gkyl_tensor_index_loc { GKYL_TENSOR_INDEX_LOWER, GKYL_TENSOR_INDEX_UPPER }; + struct gkyl_tensor_field { size_t ndim, rank; // dimension and rank of tensor size_t size; // number of indices @@ -18,8 +15,8 @@ struct gkyl_tensor_field { enum gkyl_tensor_index_loc iloc[GKYL_MAX_DIM]; // covariant index 0, contravariant index 1 // note: maximum number of indices is fixed - struct gkyl_ref_count ref_count; - + struct gkyl_ref_count ref_count; + uint32_t flags; struct gkyl_tensor_field *on_dev; // pointer to itself or device data @@ -34,7 +31,8 @@ struct gkyl_tensor_field { * @param iloc Enum array of size GKYL_MAX_DIM which for lower or upper indices * @return Pointer to newly allocated tensor field. */ -struct gkyl_tensor_field *gkyl_tensor_field_new(size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc); +struct gkyl_tensor_field * +gkyl_tensor_field_new(size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc); /** * Create new tensor field with tdata on NV-GPU. Delete using gkyl_tensor_field_release method. @@ -45,7 +43,9 @@ struct gkyl_tensor_field *gkyl_tensor_field_new(size_t rank, size_t ndim, size_t * @param iloc Enum array of size GKYL_MAX_DIM which for lower or upper indices * @return Pointer to newly allocated tensor field. */ -struct gkyl_tensor_field *gkyl_tensor_field_cu_dev_new(size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc); +struct gkyl_tensor_field *gkyl_tensor_field_cu_dev_new( + size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc +); /** * Create new tensor field with host-pinned tdata for use with NV-GPU. @@ -57,7 +57,9 @@ struct gkyl_tensor_field *gkyl_tensor_field_cu_dev_new(size_t rank, size_t ndim, * @param iloc Enum array of size GKYL_MAX_DIM which for lower or upper indices * @return Pointer to newly allocated tensor field. */ -struct gkyl_tensor_field *gkyl_tensor_field_cu_host_new(size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc); +struct gkyl_tensor_field *gkyl_tensor_field_cu_host_new( + size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc +); /** * Fetches a pointer to the tensor stored at the index 'loc'. @@ -66,19 +68,16 @@ struct gkyl_tensor_field *gkyl_tensor_field_cu_host_new(size_t rank, size_t ndim * @param loc Tensor to fetch * @return Tensor at loc */ -GKYL_CU_DH -static inline double * -gkyl_tensor_field_fetch(struct gkyl_tensor_field *ten, long loc) +GKYL_CU_DH static inline double *gkyl_tensor_field_fetch(struct gkyl_tensor_field *ten, long loc) { - return (double*) gkyl_array_fetch(ten->tdata, loc); + return (double *)gkyl_array_fetch(ten->tdata, loc); } /** Same as above, except fetches a constant pointer */ -GKYL_CU_DH -static inline const double * +GKYL_CU_DH static inline const double * gkyl_tensor_field_cfetch(const struct gkyl_tensor_field *ten, long loc) { - return (const double*) gkyl_array_cfetch(ten->tdata, loc); + return (const double *)gkyl_array_cfetch(ten->tdata, loc); } /** @@ -88,12 +87,11 @@ gkyl_tensor_field_cfetch(const struct gkyl_tensor_field *ten, long loc) * @param idx Element of the tensor * @return Index to the array storing the tensor field data */ -GKYL_CU_DH -static inline long +GKYL_CU_DH static inline long gkyl_tensor_field_idx(const struct gkyl_tensor_field *ten, int idx[GKYL_MAX_DIM]) { return gkyl_range_idx(&ten->trange, idx); -} +} /** * Fetches the element to the tensor stored at the index 'loc' and index idx. @@ -103,12 +101,11 @@ gkyl_tensor_field_idx(const struct gkyl_tensor_field *ten, int idx[GKYL_MAX_DIM] * @param idx Element to fetch * @return Tensor at loc and element at idx */ -GKYL_CU_DH -static inline double +GKYL_CU_DH static inline double gkyl_tensor_field_elem_fetch(const struct gkyl_tensor_field *ten, long loc, int idx[GKYL_MAX_DIM]) { const double *val = gkyl_tensor_field_cfetch(ten, loc); - return val[ gkyl_range_idx(&ten->trange, idx) ]; + return val[gkyl_range_idx(&ten->trange, idx)]; } /** @@ -119,12 +116,11 @@ gkyl_tensor_field_elem_fetch(const struct gkyl_tensor_field *ten, long loc, int * @param idx Element to set * @param ev Double to set */ -GKYL_CU_DH -static inline void +GKYL_CU_DH static inline void gkyl_tensor_field_elem_set(struct gkyl_tensor_field *ten, long loc, int idx[GKYL_MAX_DIM], double ev) { double *val = gkyl_tensor_field_fetch(ten, loc); - val[ gkyl_range_idx(&ten->trange, idx) ] = ev; + val[gkyl_range_idx(&ten->trange, idx)] = ev; } /** @@ -134,8 +130,7 @@ gkyl_tensor_field_elem_set(struct gkyl_tensor_field *ten, long loc, int idx[GKYL * @param tfld Tensor field to which a pointer is needed * @return Pointer to acquired Tensor field */ -struct gkyl_tensor_field* gkyl_tensor_field_acquire(const struct gkyl_tensor_field* tfld); - +struct gkyl_tensor_field *gkyl_tensor_field_acquire(const struct gkyl_tensor_field *tfld); /** * Acquire pointer to tensor field. The pointer must be released using @@ -144,8 +139,8 @@ struct gkyl_tensor_field* gkyl_tensor_field_acquire(const struct gkyl_tensor_fie * @param dest Tensor field to which a pointer is needed * @return Pointer to acquired Tensor field */ -struct gkyl_tensor_field* -gkyl_tensor_field_copy(struct gkyl_tensor_field* dest, const struct gkyl_tensor_field* src); +struct gkyl_tensor_field * +gkyl_tensor_field_copy(struct gkyl_tensor_field *dest, const struct gkyl_tensor_field *src); /** * Returns true if tensor field lives on NV-GPU. @@ -160,4 +155,4 @@ bool gkyl_tensor_field_is_cu_dev(const struct gkyl_tensor_field *tfld); * * @param tensor_field Tensor field to release. */ -void gkyl_tensor_field_release(const struct gkyl_tensor_field* tensor_field); \ No newline at end of file +void gkyl_tensor_field_release(const struct gkyl_tensor_field *tensor_field); \ No newline at end of file diff --git a/core/zero/gkyl_tensor_field_ops.h b/core/zero/gkyl_tensor_field_ops.h index e16b62b377..b791a61b9e 100644 --- a/core/zero/gkyl_tensor_field_ops.h +++ b/core/zero/gkyl_tensor_field_ops.h @@ -2,7 +2,6 @@ #include - /** * Lowers the index of tensor using the associated metric in place (in ten) * @@ -10,8 +9,10 @@ * @param lowered_idx Index to lower of ten * @param ten Tensor field */ -void gkyl_tensor_field_lower_idx_in_place(struct gkyl_tensor_field *metric, int lowered_idx, - struct gkyl_tensor_field *ten, struct gkyl_tensor_field *mem); +void gkyl_tensor_field_lower_idx_in_place( + struct gkyl_tensor_field *metric, int lowered_idx, struct gkyl_tensor_field *ten, + struct gkyl_tensor_field *mem +); /** * Raises the index of tensor using the associated metric in place (in ten) @@ -20,8 +21,10 @@ void gkyl_tensor_field_lower_idx_in_place(struct gkyl_tensor_field *metric, int * @param raised_idx Index to raise of ten * @param ten Tensor field */ -void gkyl_tensor_field_raise_idx_in_place(struct gkyl_tensor_field *metric, int raised_idx, - struct gkyl_tensor_field *ten, struct gkyl_tensor_field *mem); +void gkyl_tensor_field_raise_idx_in_place( + struct gkyl_tensor_field *metric, int raised_idx, struct gkyl_tensor_field *ten, + struct gkyl_tensor_field *mem +); /** * Lowers the index of tensor using the associated metric in place (in ten) @@ -31,8 +34,10 @@ void gkyl_tensor_field_raise_idx_in_place(struct gkyl_tensor_field *metric, int * @param ten Tensor field * @param ten_out (output) Tensor field */ -void gkyl_tensor_field_lower_idx_set(const struct gkyl_tensor_field *metric, int lowered_idx, - const struct gkyl_tensor_field *ten, struct gkyl_tensor_field *ten_out); +void gkyl_tensor_field_lower_idx_set( + const struct gkyl_tensor_field *metric, int lowered_idx, const struct gkyl_tensor_field *ten, + struct gkyl_tensor_field *ten_out +); /** * Raises the index of tensor using the associated metric in place (in ten) @@ -42,12 +47,15 @@ void gkyl_tensor_field_lower_idx_set(const struct gkyl_tensor_field *metric, int * @param ten Tensor field * @param ten_out (output) Tensor field */ -void gkyl_tensor_field_raise_idx_set(const struct gkyl_tensor_field *metric, int raised_idx, - const struct gkyl_tensor_field *ten, struct gkyl_tensor_field *ten_out); +void gkyl_tensor_field_raise_idx_set( + const struct gkyl_tensor_field *metric, int raised_idx, const struct gkyl_tensor_field *ten, + struct gkyl_tensor_field *ten_out +); /** * Host-side wrappers for array operations */ -void -tensor_field_raise_or_lower_idx_set_cu(const struct gkyl_tensor_field *met, int raised_idx, - const struct gkyl_tensor_field *ten, struct gkyl_tensor_field *tensor_out); \ No newline at end of file +void tensor_field_raise_or_lower_idx_set_cu( + const struct gkyl_tensor_field *met, int raised_idx, const struct gkyl_tensor_field *ten, + struct gkyl_tensor_field *tensor_out +); \ No newline at end of file diff --git a/core/zero/gkyl_thread_pool.h b/core/zero/gkyl_thread_pool.h index 147a4e2199..5127c32ca1 100644 --- a/core/zero/gkyl_thread_pool.h +++ b/core/zero/gkyl_thread_pool.h @@ -8,5 +8,4 @@ * @param nthreads Number of threads to create * @return Pointer to new job-pool object */ -struct gkyl_job_pool* gkyl_thread_pool_new(int nthreads); - +struct gkyl_job_pool *gkyl_thread_pool_new(int nthreads); diff --git a/core/zero/gkyl_util.h b/core/zero/gkyl_util.h index 8c434c1226..61463e0281 100644 --- a/core/zero/gkyl_util.h +++ b/core/zero/gkyl_util.h @@ -12,86 +12,86 @@ #ifdef __cplusplus // extern "C" guards needed when using code from C++ -# define EXTERN_C_BEG extern "C" { -# define EXTERN_C_END } +#define EXTERN_C_BEG extern "C" { +#define EXTERN_C_END } #else -# define EXTERN_C_BEG -# define EXTERN_C_END +#define EXTERN_C_BEG +#define EXTERN_C_END #endif // restrict keyword in C and C++ are different #ifdef __cplusplus -# define GKYL_RESTRICT __restrict__ +#define GKYL_RESTRICT __restrict__ #else -# define GKYL_RESTRICT restrict +#define GKYL_RESTRICT restrict #endif // Maximum configuration-space dimensions supported #ifndef GKYL_MAX_CDIM -# define GKYL_MAX_CDIM 3 +#define GKYL_MAX_CDIM 3 #endif // Maximum velocity-space dimensions supported #ifndef GKYL_MAX_VDIM -# define GKYL_MAX_VDIM 3 +#define GKYL_MAX_VDIM 3 #endif // Maximum dimensions supported #ifndef GKYL_MAX_DIM -# define GKYL_MAX_DIM 7 +#define GKYL_MAX_DIM 7 #endif // Maximum number of supported species #ifndef GKYL_MAX_SPECIES -# define GKYL_MAX_SPECIES 16 +#define GKYL_MAX_SPECIES 16 #endif // Maximum number of supported species #ifndef GKYL_MAX_REACT -# define GKYL_MAX_REACT 3*GKYL_MAX_SPECIES +#define GKYL_MAX_REACT 3 * GKYL_MAX_SPECIES #endif // Maximum number of supported sources #ifndef GKYL_MAX_SOURCES -# define GKYL_MAX_SOURCES 4 +#define GKYL_MAX_SOURCES 4 #endif // Maximum number of supported fdot multiplier types #ifndef GKYL_MAX_FDOT_MUL -# define GKYL_MAX_FDOT_MUL 4 +#define GKYL_MAX_FDOT_MUL 4 #endif // Maximum number of supported charge states #ifndef GKYL_MAX_CHARGE_STATE -# define GKYL_MAX_CHARGE_STATE 18 +#define GKYL_MAX_CHARGE_STATE 18 #endif // Maximum number of supported densities for radiation #ifndef GKYL_MAX_RAD_DENSITIES -# define GKYL_MAX_RAD_DENSITIES 26 +#define GKYL_MAX_RAD_DENSITIES 26 #endif // Maximum number of supported projection objects #ifndef GKYL_MAX_PROJ -# define GKYL_MAX_PROJ 4 +#define GKYL_MAX_PROJ 4 #endif // Maximum number of ghost cells in each direction #ifndef GKYL_MAX_NGHOST -# define GKYL_MAX_NGHOST 8 +#define GKYL_MAX_NGHOST 8 #endif // Default alignment boundary #ifndef GKYL_DEF_ALIGN -# define GKYL_DEF_ALIGN 64 +#define GKYL_DEF_ALIGN 64 #endif // Maximum number of blocks #ifndef GKYL_MAX_BLOCKS -# define GKYL_MAX_BLOCKS 12 +#define GKYL_MAX_BLOCKS 12 #endif // CUDA specific defines etc @@ -102,7 +102,7 @@ #define GKYL_HAVE_CUDA #define GKYL_CU_DH __device__ __host__ -#define GKYL_CU_D __device__ +#define GKYL_CU_D __device__ // for directional copies enum gkyl_cu_memcpy_kind { @@ -115,12 +115,15 @@ enum gkyl_cu_memcpy_kind { #define GKYL_DEFAULT_NUM_THREADS 256 // CUDA helper function to find CUDA errors -#define checkCuda(val) __checkCudaErrors__ ( (val), #val, __FILE__, __LINE__ ) -inline cudaError_t __checkCudaErrors__(cudaError_t code, const char *func, const char *file, int line) +#define checkCuda(val) __checkCudaErrors__((val), #val, __FILE__, __LINE__) +inline cudaError_t +__checkCudaErrors__(cudaError_t code, const char *func, const char *file, int line) { if (code) { - fprintf(stderr, "CUDA error: %s (code=%u) \"%s\" at %s:%d \n", - cudaGetErrorString(code), (unsigned int)code, func, file, line); + fprintf( + stderr, "CUDA error: %s (code=%u) \"%s\" at %s:%d \n", cudaGetErrorString(code), + (unsigned int)code, func, file, line + ); cudaDeviceReset(); exit(EXIT_FAILURE); } @@ -132,13 +135,13 @@ inline cudaError_t __checkCudaErrors__(cudaError_t code, const char *func, const #undef GKYL_HAVE_CUDA #define GKYL_CU_DH #define GKYL_CU_D -#define checkCuda(val) +#define checkCuda(val) // for directional copies enum gkyl_cu_memcpy_kind { GKYL_CU_MEMCPY_H2H, GKYL_CU_MEMCPY_H2D, GKYL_CU_MEMCPY_D2H, - GKYL_CU_MEMCPY_D2D, + GKYL_CU_MEMCPY_D2D }; #define GKYL_DEFAULT_NUM_THREADS 1 @@ -150,41 +153,38 @@ enum gkyl_cu_memcpy_kind { // 'member' inside 'type'. (Did I just write this gobbledygook?!) // // See https://en.wikipedia.org/wiki/Offsetof -#define container_of(ptr, type, member) \ - ((type *)((char *)(1 ? (ptr) : &((type *)0)->member) - offsetof(type, member))) +#define container_of(ptr, type, member) \ + ((type *)((char *)(1 ? (ptr) : &((type *)0)->member) - offsetof(type, member))) // Select type-specific compare function -#define gkyl_compare(a, b, eps) \ - _Generic((a), \ - float: gkyl_compare_float, \ - double: gkyl_compare_double) \ - (a, b, eps) +#define gkyl_compare(a, b, eps) \ + _Generic((a), float: gkyl_compare_float, double: gkyl_compare_double)(a, b, eps) // a quick-and-dirty macro for testing (mostly) CUDA kernel code -#define GKYL_CU_CHECK(expr, cntr) do { \ - if (!(expr)) { \ - *cntr += 1; \ - printf("%s failed! (%s:%d)\n", #expr, __FILE__, __LINE__); \ - } \ - } while (0) +#define GKYL_CU_CHECK(expr, cntr) \ + do { \ + if (!(expr)) { \ + *cntr += 1; \ + printf("%s failed! (%s:%d)\n", #expr, __FILE__, __LINE__); \ + } \ + } while (0) // Computes length of string needed given a format specifier and data. Example: // // size_t len = gkyl_calc_strlen("%s-%d", "gkyl", 25); -// +// #define gkyl_calc_strlen(fmt, ...) snprintf(0, 0, fmt, __VA_ARGS__) // Open file 'fname' with 'mode; into handle 'fp'. Handle is closed // when block attached to with_file exits -#define with_file(fp, fname, mode) \ - for (bool _break = (fp = fopen(fname, mode), (fp != NULL)); _break; \ - _break = false, fclose(fp)) +#define with_file(fp, fname, mode) \ + for (bool _break = (fp = fopen(fname, mode), (fp != NULL)); _break; _break = false, fclose(fp)) // Code -#define GKYL_MIN2(x,y) ((x)<(y) ? (x) : (y)) -#define GKYL_MAX2(x,y) ((x)>(y) ? (x) : (y)) -#define GKYL_SGN(b) (((b)>=0.) ? 1.0 : -1.0) +#define GKYL_MIN2(x, y) ((x) < (y) ? (x) : (y)) +#define GKYL_MAX2(x, y) ((x) > (y) ? (x) : (y)) +#define GKYL_SGN(b) (((b) >= 0.) ? 1.0 : -1.0) // GKYL_ALIGN_UP finds the integer that is closest to "a" that is // multiple of "b" @@ -217,7 +217,9 @@ struct gkyl_str_int_pair { * @param def Default value to return * @return value corresponding to @a str, or @a def. */ -int gkyl_search_str_int_pair_by_str(const struct gkyl_str_int_pair pairs[], const char *str, int def); +int gkyl_search_str_int_pair_by_str( + const struct gkyl_str_int_pair pairs[], const char *str, int def +); /** * Search @a pairs list for @a val and return the corresponding string @@ -229,7 +231,8 @@ int gkyl_search_str_int_pair_by_str(const struct gkyl_str_int_pair pairs[], cons * @param def Default value to return * @return value corresponding to @a val, or @a def. */ -const char* gkyl_search_str_int_pair_by_int(const struct gkyl_str_int_pair pairs[], int val, const char *def); +const char * +gkyl_search_str_int_pair_by_int(const struct gkyl_str_int_pair pairs[], int val, const char *def); /** * Time-trigger. Typical initialization is: @@ -257,7 +260,7 @@ int gkyl_tm_trigger_check_and_bump(struct gkyl_tm_trigger *tmt, double tcurr); * * @param msg Error message. */ -void gkyl_exit(const char* msg); +void gkyl_exit(const char *msg); /** * Compares two float numbers 'a' and 'b' to check if they are @@ -278,11 +281,12 @@ int gkyl_compare_double(double a, double b, double eps); * @param inp Input array * @param out Output array */ -GKYL_CU_DH -static inline void -gkyl_copy_int_arr(int n, const int* GKYL_RESTRICT inp, int* GKYL_RESTRICT out) +GKYL_CU_DH static inline void +gkyl_copy_int_arr(int n, const int *GKYL_RESTRICT inp, int *GKYL_RESTRICT out) { - for (int i=0; i -bool -gkyl_job_pool_add_work(const struct gkyl_job_pool *jp, jp_work_func func, void *ctx) +bool gkyl_job_pool_add_work(const struct gkyl_job_pool *jp, jp_work_func func, void *ctx) { return jp->add_work(jp, func, ctx); } -void -gkyl_job_pool_wait(const struct gkyl_job_pool *jp) +void gkyl_job_pool_wait(const struct gkyl_job_pool *jp) { jp->wait(jp); } -struct gkyl_job_pool* -gkyl_job_pool_acquire(const struct gkyl_job_pool *jp) +struct gkyl_job_pool *gkyl_job_pool_acquire(const struct gkyl_job_pool *jp) { gkyl_ref_count_inc(&jp->ref_count); - return (struct gkyl_job_pool*) jp; + return (struct gkyl_job_pool *)jp; } -void -gkyl_job_pool_release(const struct gkyl_job_pool* jp) +void gkyl_job_pool_release(const struct gkyl_job_pool *jp) { gkyl_ref_count_dec(&jp->ref_count); } - - diff --git a/core/zero/kann_net.c b/core/zero/kann_net.c index 1eda794d8a..930be0fdcc 100644 --- a/core/zero/kann_net.c +++ b/core/zero/kann_net.c @@ -13,25 +13,25 @@ // Mirror of kann_verbose in kann.c (set via gkyl_kann_net_set_verbose) static int kann_net_verbose = 0; -static void -kann_net_free(const struct gkyl_ref_count *ref) +static void kann_net_free(const struct gkyl_ref_count *ref) { struct gkyl_kann_net *net = container_of(ref, struct gkyl_kann_net, ref_count); #ifdef GKYL_HAVE_CUDA if (GKYL_IS_CU_ALLOC(net->flags)) { - if (net->cg) + if (net->cg) { kann_cu_graph_free(net->cg); + } cublasDestroy(net->cublas_h); } #endif - if (net->ann) + if (net->ann) { kann_delete(net->ann); + } gkyl_free(net); } // Initialize cached dimensions from the underlying kann_t -static void -kann_net_cache_dims(struct gkyl_kann_net *net) +static void kann_net_cache_dims(struct gkyl_kann_net *net) { net->n_in = kann_dim_in(net->ann); net->n_out = kann_dim_out(net->ann); @@ -39,8 +39,7 @@ kann_net_cache_dims(struct gkyl_kann_net *net) net->n_const = kann_size_const(net->ann); } -struct gkyl_kann_net* -gkyl_kann_net_new(kad_node_t *cost, bool use_gpu) +struct gkyl_kann_net *gkyl_kann_net_new(kad_node_t *cost, bool use_gpu) { struct gkyl_kann_net *net = gkyl_malloc(sizeof(*net)); @@ -67,11 +66,12 @@ gkyl_kann_net_new(kad_node_t *cost, bool use_gpu) return net; } -struct gkyl_kann_net* -gkyl_kann_net_load(const char *filename, bool use_gpu) +struct gkyl_kann_net *gkyl_kann_net_load(const char *filename, bool use_gpu) { kann_t *ann = kann_load(filename); - if (!ann) return 0; + if (!ann) { + return 0; + } struct gkyl_kann_net *net = gkyl_malloc(sizeof(*net)); net->ann = ann; @@ -92,8 +92,7 @@ gkyl_kann_net_load(const char *filename, bool use_gpu) return net; } -void -gkyl_kann_net_save(const struct gkyl_kann_net *net, const char *filename) +void gkyl_kann_net_save(const struct gkyl_kann_net *net, const char *filename) { #ifdef GKYL_HAVE_CUDA if (GKYL_IS_CU_ALLOC(net->flags) && net->cg) { @@ -108,10 +107,10 @@ gkyl_kann_net_save(const struct gkyl_kann_net *net, const char *filename) // All training data lives on device via kn_vec on_dev; mini-batches are // assembled on device via gather kernels. #ifdef GKYL_HAVE_CUDA -static int -kann_net_train_fnn1_cu(struct gkyl_kann_net *net, - const struct gkyl_kann_train_params *params, - const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) +static int kann_net_train_fnn1_cu( + struct gkyl_kann_net *net, const struct gkyl_kann_train_params *params, + const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out +) { kann_t *ann = net->ann; int n = inp->nvec; @@ -121,7 +120,9 @@ kann_net_train_fnn1_cu(struct gkyl_kann_net *net, // Lazily create GPU graph sized for this mini-batch if (!net->cg || net->cg->max_batch_size < mini_size) { - if (net->cg) kann_cu_graph_free(net->cg); + if (net->cg) { + kann_cu_graph_free(net->cg); + } net->cg = kann_cu_graph_new(ann, mini_size); } struct kann_cu_graph *cg = net->cg; @@ -138,8 +139,9 @@ kann_net_train_fnn1_cu(struct gkyl_kann_net *net, // Build initial train/val split: shuf[0..n_train-1] = train, // shuf[n_train..n-1] = val (indices into original data) int *idx = (int *)malloc(n * sizeof(int)); - for (int j = 0; j < n; ++j) + for (int j = 0; j < n; ++j) { idx[j] = shuf[j]; + } int n_val = (int)(n * params->frac_val); int n_train = n - n_val; @@ -164,8 +166,9 @@ kann_net_train_fnn1_cu(struct gkyl_kann_net *net, // Reshuffle training indices and upload to device kann_shuffle(n_train, shuf); - for (int j = 0; j < n_train; ++j) + for (int j = 0; j < n_train; ++j) { shuf[j] = idx[shuf[j]]; + } gkyl_cu_memcpy(d_idx, shuf, n_train * sizeof(int), GKYL_CU_MEMCPY_H2D); // Training pass @@ -194,8 +197,7 @@ kann_net_train_fnn1_cu(struct gkyl_kann_net *net, double val_cost = 0.0; if (n_val > 0) { // Upload validation indices to device - gkyl_cu_memcpy(d_idx, &idx[n_train], n_val * sizeof(int), - GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(d_idx, &idx[n_train], n_val * sizeof(int), GKYL_CU_MEMCPY_H2D); n_proc = 0; while (n_proc < n_val) { @@ -213,9 +215,12 @@ kann_net_train_fnn1_cu(struct gkyl_kann_net *net, val_cost /= n_val; } - if (kann_net_verbose >= 3) - fprintf(stderr, "epoch: %d; training cost: %g; validation cost: %g\n", - epoch + 1, train_cost, val_cost); + if (kann_net_verbose >= 3) { + fprintf( + stderr, "epoch: %d; training cost: %g; validation cost: %g\n", epoch + 1, train_cost, + val_cost + ); + } if (epoch >= params->max_drop_streak && n_val > 0) { if (val_cost < min_val_cost) { @@ -225,8 +230,9 @@ kann_net_train_fnn1_cu(struct gkyl_kann_net *net, memcpy(min_c, ann->c, n_const * sizeof(float)); drop_streak = 0; min_val_cost = (float)val_cost; - } else if (++drop_streak >= params->max_drop_streak) + } else if (++drop_streak >= params->max_drop_streak) { break; + } } } @@ -241,42 +247,39 @@ kann_net_train_fnn1_cu(struct gkyl_kann_net *net, } gkyl_cu_free(d_idx); - free(min_c); free(min_x); - free(idx); free(shuf); + free(min_c); + free(min_x); + free(idx); + free(shuf); return epoch; } #endif -int -gkyl_kann_net_train_fnn1(struct gkyl_kann_net *net, - const struct gkyl_kann_train_params *params, - const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out) +int gkyl_kann_net_train_fnn1( + struct gkyl_kann_net *net, const struct gkyl_kann_train_params *params, + const struct gkyl_kn_vec *inp, const struct gkyl_kn_vec *out +) { assert(inp->nvec == out->nvec); assert(inp->N == net->n_in); assert(out->N == net->n_out); #ifdef GKYL_HAVE_CUDA - if (GKYL_IS_CU_ALLOC(net->flags)) + if (GKYL_IS_CU_ALLOC(net->flags)) { return kann_net_train_fnn1_cu(net, params, inp, out); + } #endif - return kann_train_fnn1(net->ann, - params->learning_rate, - params->mini_size, - params->max_epoch, - params->max_drop_streak, - params->frac_val, - inp->nvec, - inp->vals, - out->vals); + return kann_train_fnn1( + net->ann, params->learning_rate, params->mini_size, params->max_epoch, params->max_drop_streak, + params->frac_val, inp->nvec, inp->vals, out->vals + ); } // GPU inference: feed device input, run forward, copy output to device kn_vec #ifdef GKYL_HAVE_CUDA static void -kann_net_apply_cu(struct gkyl_kann_net *net, - const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +kann_net_apply_cu(struct gkyl_kann_net *net, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) { int n_in = net->n_in, n_out = net->n_out; int nvec = inp->nvec; @@ -286,7 +289,9 @@ kann_net_apply_cu(struct gkyl_kann_net *net, // Lazily create GPU graph if needed if (!net->cg || net->cg->max_batch_size < nvec) { - if (net->cg) kann_cu_graph_free(net->cg); + if (net->cg) { + kann_cu_graph_free(net->cg); + } net->cg = kann_cu_graph_new(net->ann, nvec); } struct kann_cu_graph *cg = net->cg; @@ -301,14 +306,13 @@ kann_net_apply_cu(struct gkyl_kann_net *net, // Copy output from graph directly to device kn_vec int idx = cg->out_node_idx >= 0 ? cg->out_node_idx : cg->cost_node_idx; struct kann_cu_node *hn = &cg->h_nodes[idx]; - gkyl_cu_memcpy(out->data, cg->x + hn->x_off, - nvec * n_out * sizeof(float), GKYL_CU_MEMCPY_D2D); + gkyl_cu_memcpy(out->data, cg->x + hn->x_off, nvec * n_out * sizeof(float), GKYL_CU_MEMCPY_D2D); } #endif -void -gkyl_kann_net_apply(struct gkyl_kann_net *net, - const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +void gkyl_kann_net_apply( + struct gkyl_kann_net *net, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out +) { assert(inp->N == net->n_in); assert(out->N == net->n_out); @@ -330,9 +334,9 @@ gkyl_kann_net_apply(struct gkyl_kann_net *net, // GPU sequential RNN inference: process one timestep at a time with // pre-recurrence between steps. #ifdef GKYL_HAVE_CUDA -static void -kann_net_apply_rnn_cu(struct gkyl_kann_net *net, - const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +static void kann_net_apply_rnn_cu( + struct gkyl_kann_net *net, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out +) { int n_in = net->n_in, n_out = net->n_out; int nvec = inp->nvec; @@ -341,7 +345,9 @@ kann_net_apply_rnn_cu(struct gkyl_kann_net *net, // Graph needs batch_size=1 for sequential processing if (!net->cg || net->cg->max_batch_size < 1) { - if (net->cg) kann_cu_graph_free(net->cg); + if (net->cg) { + kann_cu_graph_free(net->cg); + } net->cg = kann_cu_graph_new(net->ann, 1); } struct kann_cu_graph *cg = net->cg; @@ -353,7 +359,7 @@ kann_net_apply_rnn_cu(struct gkyl_kann_net *net, // Zero h0 nodes (initial hidden state) for (int i = 0; i < cg->n_pre_pairs; ++i) { - int h0_idx = cg->h_pre_pairs[2*i+1]; + int h0_idx = cg->h_pre_pairs[2 * i + 1]; struct kann_cu_node *h0_n = &cg->h_nodes[h0_idx]; cudaMemset(cg->x + h0_n->x_off, 0, h0_n->len * sizeof(float)); } @@ -366,8 +372,9 @@ kann_net_apply_rnn_cu(struct gkyl_kann_net *net, // Copy output for this timestep struct kann_cu_node *hn = &cg->h_nodes[out_idx]; - gkyl_cu_memcpy(out->data + t * n_out, cg->x + hn->x_off, - n_out * sizeof(float), GKYL_CU_MEMCPY_D2D); + gkyl_cu_memcpy( + out->data + t * n_out, cg->x + hn->x_off, n_out * sizeof(float), GKYL_CU_MEMCPY_D2D + ); // Apply pre-recurrence: copy output node x to h0 node x kann_cu_apply_pre(cg); @@ -375,9 +382,9 @@ kann_net_apply_rnn_cu(struct gkyl_kann_net *net, } #endif -void -gkyl_kann_net_apply_rnn(struct gkyl_kann_net *net, - const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out) +void gkyl_kann_net_apply_rnn( + struct gkyl_kann_net *net, const struct gkyl_kn_vec *inp, struct gkyl_kn_vec *out +) { assert(inp->N == net->n_in); assert(out->N == net->n_out); @@ -399,41 +406,36 @@ gkyl_kann_net_apply_rnn(struct gkyl_kann_net *net, kann_rnn_end(net->ann); } -int -gkyl_kann_net_dim_in(const struct gkyl_kann_net *net) +int gkyl_kann_net_dim_in(const struct gkyl_kann_net *net) { return net->n_in; } -int -gkyl_kann_net_dim_out(const struct gkyl_kann_net *net) +int gkyl_kann_net_dim_out(const struct gkyl_kann_net *net) { return net->n_out; } -void -gkyl_kann_net_set_verbose(int level) +void gkyl_kann_net_set_verbose(int level) { kann_net_verbose = level; kann_set_verbose_level(level); } -bool -gkyl_kann_net_is_cu_dev(const struct gkyl_kann_net *net) +bool gkyl_kann_net_is_cu_dev(const struct gkyl_kann_net *net) { return GKYL_IS_CU_ALLOC(net->flags); } -struct gkyl_kann_net* -gkyl_kann_net_acquire(const struct gkyl_kann_net *net) +struct gkyl_kann_net *gkyl_kann_net_acquire(const struct gkyl_kann_net *net) { gkyl_ref_count_inc(&net->ref_count); - return (struct gkyl_kann_net*) net; + return (struct gkyl_kann_net *)net; } -void -gkyl_kann_net_release(struct gkyl_kann_net *net) +void gkyl_kann_net_release(struct gkyl_kann_net *net) { - if (net) + if (net) { gkyl_ref_count_dec(&net->ref_count); + } } diff --git a/core/zero/kann_net_cu.cu b/core/zero/kann_net_cu.cu index 607b712ff0..37ac28d752 100644 --- a/core/zero/kann_net_cu.cu +++ b/core/zero/kann_net_cu.cu @@ -28,150 +28,140 @@ extern "C" { // ============================================================ // --- add (op 1): p = child[0] + child[1] (with broadcasting) --- -__global__ static void -ker_add_fwd(int n0, int n1, const float *x0, const float *x1, float *px) +__global__ static void ker_add_fwd(int n0, int n1, const float *x0, const float *x1, float *px) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n0; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n0; i += blockDim.x * gridDim.x) { px[i] = x0[i] + x1[i % n1]; + } } -__global__ static void -ker_add_bwd_child0(int n, const float *pg, float *g0) +__global__ static void ker_add_bwd_child0(int n, const float *pg, float *g0) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { g0[i] += pg[i]; + } } -__global__ static void -ker_add_bwd_child1(int n0, int n1, const float *pg, float *g1) +__global__ static void ker_add_bwd_child1(int n0, int n1, const float *pg, float *g1) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n1; - i += blockDim.x * gridDim.x) { + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n1; i += blockDim.x * gridDim.x) { float s = 0.0f; - for (int j = i; j < n0; j += n1) + for (int j = i; j < n0; j += n1) { s += pg[j]; + } g1[i] += s; } } // --- mul (op 2): element-wise multiplication with broadcasting --- -__global__ static void -ker_mul_fwd(int n0, int n1, const float *x0, const float *x1, float *px) +__global__ static void ker_mul_fwd(int n0, int n1, const float *x0, const float *x1, float *px) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n0; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n0; i += blockDim.x * gridDim.x) { px[i] = x0[i] * x1[i % n1]; + } } __global__ static void ker_mul_bwd_child0(int n0, int n1, const float *pg, const float *x1, float *g0) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n0; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n0; i += blockDim.x * gridDim.x) { g0[i] += pg[i] * x1[i % n1]; + } } __global__ static void ker_mul_bwd_child1(int n0, int n1, const float *pg, const float *x0, float *g1) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n1; - i += blockDim.x * gridDim.x) { + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n1; i += blockDim.x * gridDim.x) { float s = 0.0f; - for (int j = i; j < n0; j += n1) + for (int j = i; j < n0; j += n1) { s += pg[j] * x0[j]; + } g1[i] += s; } } // --- sigm (op 6): sigmoid --- -__global__ static void -ker_sigm_fwd(int n, const float *qx, float *px) +__global__ static void ker_sigm_fwd(int n, const float *qx, float *px) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { px[i] = 1.0f / (1.0f + expf(-qx[i])); + } } -__global__ static void -ker_sigm_bwd(int n, const float *pg, const float *px, float *qg) +__global__ static void ker_sigm_bwd(int n, const float *pg, const float *px, float *qg) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { qg[i] += pg[i] * (px[i] * (1.0f - px[i])); + } } // --- tanh (op 7) --- -__global__ static void -ker_tanh_fwd(int n, const float *qx, float *px) +__global__ static void ker_tanh_fwd(int n, const float *qx, float *px) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) { - if (qx[i] < -20.0f) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { + if (qx[i] < -20.0f) { px[i] = -1.0f; - else { + } else { float y = expf(-2.0f * qx[i]); px[i] = (1.0f - y) / (1.0f + y); } } } -__global__ static void -ker_tanh_bwd(int n, const float *pg, const float *px, float *qg) +__global__ static void ker_tanh_bwd(int n, const float *pg, const float *px, float *qg) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { qg[i] += pg[i] * (1.0f - px[i] * px[i]); + } } // --- relu (op 8) --- -__global__ static void -ker_relu_fwd(int n, const float *qx, float *px) +__global__ static void ker_relu_fwd(int n, const float *qx, float *px) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { px[i] = qx[i] > 0.0f ? qx[i] : 0.0f; + } } -__global__ static void -ker_relu_bwd(int n, const float *pg, const float *qx, float *qg) +__global__ static void ker_relu_bwd(int n, const float *pg, const float *qx, float *qg) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) - if (qx[i] > 0.0f) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { + if (qx[i] > 0.0f) { qg[i] += pg[i]; + } + } } // --- 1minus (op 11): p = 1 - child --- -__global__ static void -ker_1minus_fwd(int n, const float *qx, float *px) +__global__ static void ker_1minus_fwd(int n, const float *qx, float *px) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { px[i] = 1.0f - qx[i]; + } } -__global__ static void -ker_1minus_bwd(int n, const float *pg, float *qg) +__global__ static void ker_1minus_bwd(int n, const float *pg, float *qg) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { qg[i] -= pg[i]; + } } // --- softmax (op 14) --- -__global__ static void -ker_softmax_fwd(int d0, int n1, const float *qx, float *px) +__global__ static void ker_softmax_fwd(int d0, int n1, const float *qx, float *px) { int row = blockIdx.x; - if (row >= d0) return; + if (row >= d0) { + return; + } const float *x = qx + row * n1; float *y = px + row * n1; float mx = -FLT_MAX; - for (int i = 0; i < n1; ++i) + for (int i = 0; i < n1; ++i) { mx = fmaxf(mx, x[i]); + } float s = 0.0f; for (int i = 0; i < n1; ++i) { @@ -179,29 +169,32 @@ ker_softmax_fwd(int d0, int n1, const float *qx, float *px) s += y[i]; } s = 1.0f / s; - for (int i = 0; i < n1; ++i) + for (int i = 0; i < n1; ++i) { y[i] *= s; + } } -__global__ static void -ker_softmax_bwd(int d0, int n1, const float *pg, const float *px, float *qg) +__global__ static void ker_softmax_bwd(int d0, int n1, const float *pg, const float *px, float *qg) { int row = blockIdx.x; - if (row >= d0) return; + if (row >= d0) { + return; + } const float *g = pg + row * n1; const float *y = px + row * n1; float *h = qg + row * n1; float s = 0.0f; - for (int i = 0; i < n1; ++i) + for (int i = 0; i < n1; ++i) { s += g[i] * y[i]; - for (int i = 0; i < n1; ++i) + } + for (int i = 0; i < n1; ++i) { h[i] += y[i] * (g[i] - s); + } } // --- mse (op 29): mean square error --- -__global__ static void -ker_mse_fwd(int n, const float *y1, const float *y0, float *cost) +__global__ static void ker_mse_fwd(int n, const float *y1, const float *y0, float *cost) { __shared__ float sdata[KANN_CU_THREADS]; int tid = threadIdx.x; @@ -214,81 +207,94 @@ ker_mse_fwd(int n, const float *y1, const float *y0, float *cost) __syncthreads(); for (int s = blockDim.x / 2; s > 0; s >>= 1) { - if (tid < s) + if (tid < s) { sdata[tid] += sdata[tid + s]; + } __syncthreads(); } - if (tid == 0) + if (tid == 0) { cost[0] = sdata[0] / n; + } } __global__ static void ker_mse_bwd(int n, const float *pg, const float *y1, const float *y0, float *y1g) { float t = 2.0f * pg[0] / n; - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { y1g[i] += t * (y1[i] - y0[i]); + } } // --- stdnorm (op 32): layer normalization --- // Each row of length n is independently normalized: subtract mean, divide by std. // si_out stores per-row 1/std for backward pass. // One block per row, shared-memory reduction. -__global__ static void -ker_stdnorm_fwd(int m, int n, const float *qx, float *px, float *si_out) +__global__ static void ker_stdnorm_fwd(int m, int n, const float *qx, float *px, float *si_out) { int row = blockIdx.x; - if (row >= m) return; + if (row >= m) { + return; + } const float *in = qx + row * n; float *out = px + row * n; // Compute mean via shared reduction extern __shared__ float smem[]; float sum = 0.0f; - for (int i = threadIdx.x; i < n; i += blockDim.x) + for (int i = threadIdx.x; i < n; i += blockDim.x) { sum += in[i]; + } smem[threadIdx.x] = sum; __syncthreads(); for (int s = blockDim.x / 2; s > 0; s >>= 1) { - if (threadIdx.x < s) smem[threadIdx.x] += smem[threadIdx.x + s]; + if (threadIdx.x < s) { + smem[threadIdx.x] += smem[threadIdx.x + s]; + } __syncthreads(); } float avg = smem[0] / n; // Subtract mean - for (int i = threadIdx.x; i < n; i += blockDim.x) + for (int i = threadIdx.x; i < n; i += blockDim.x) { out[i] = in[i] - avg; + } __syncthreads(); // Compute variance sum = 0.0f; - for (int i = threadIdx.x; i < n; i += blockDim.x) + for (int i = threadIdx.x; i < n; i += blockDim.x) { sum += out[i] * out[i]; + } smem[threadIdx.x] = sum; __syncthreads(); for (int s = blockDim.x / 2; s > 0; s >>= 1) { - if (threadIdx.x < s) smem[threadIdx.x] += smem[threadIdx.x + s]; + if (threadIdx.x < s) { + smem[threadIdx.x] += smem[threadIdx.x + s]; + } __syncthreads(); } float var = smem[0] / n; float std_inv = (var == 0.0f) ? 1.0f : rsqrtf(var); // Scale by 1/std - for (int i = threadIdx.x; i < n; i += blockDim.x) + for (int i = threadIdx.x; i < n; i += blockDim.x) { out[i] *= std_inv; + } - if (threadIdx.x == 0) + if (threadIdx.x == 0) { si_out[row] = std_inv; + } } // Backward: qg[i] += std_inv * (pg[i] - mean(pg) - px[i] * mean(px * pg)) __global__ static void -ker_stdnorm_bwd(int m, int n, const float *pg, const float *px, - const float *si, float *qg) +ker_stdnorm_bwd(int m, int n, const float *pg, const float *px, const float *si, float *qg) { int row = blockIdx.x; - if (row >= m) return; + if (row >= m) { + return; + } const float *pg_r = pg + row * n; const float *px_r = px + row * n; float *qg_r = qg + row * n; @@ -317,37 +323,34 @@ ker_stdnorm_bwd(int m, int n, const float *pg, const float *px, float s_avg = smem_s[0] / n; float t_avg = smem_t[0] / n; - for (int i = threadIdx.x; i < n; i += blockDim.x) + for (int i = threadIdx.x; i < n; i += blockDim.x) { qg_r[i] += std_inv * (pg_r[i] - s_avg - px_r[i] * t_avg); + } } // ============================================================ // Support kernels // ============================================================ -__global__ static void -ker_zero(int n, float *buf) +__global__ static void ker_zero(int n, float *buf) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { buf[i] = 0.0f; + } } -__global__ static void -ker_saxpy(int n, float a, const float *x, float *y) +__global__ static void ker_saxpy(int n, float a, const float *x, float *y) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { y[i] += a * x[i]; + } } // RMSprop: r = (1-decay)*g^2 + decay*r; t -= lr/sqrt(r+eps)*g -__global__ static void -ker_rmsprop(int n, float lr, float decay, const float *g, float *t, float *r) +__global__ static void ker_rmsprop(int n, float lr, float decay, const float *g, float *t, float *r) { float d1 = 1.0f - decay; - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; - i += blockDim.x * gridDim.x) { + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < n; i += blockDim.x * gridDim.x) { r[i] = d1 * g[i] * g[i] + decay * r[i]; t[i] -= lr * rsqrtf(1e-6f + r[i]) * g[i]; } @@ -368,12 +371,13 @@ static inline int cu_nblocks(int n) static int host_kad_len(const kad_node_t *p) { int n = 1; - for (int i = 0; i < p->n_d; ++i) n *= p->d[i]; + for (int i = 0; i < p->n_d; ++i) { + n *= p->d[i]; + } return n; } -struct kann_cu_graph* -kann_cu_graph_new(kann_t *ann, int max_batch_size) +struct kann_cu_graph *kann_cu_graph_new(kann_t *ann, int max_batch_size) { int n = ann->n; kad_node_t **v = ann->v; @@ -381,15 +385,13 @@ kann_cu_graph_new(kann_t *ann, int max_batch_size) // Sync host graph to max batch size so buffer allocation is large enough kad_sync_dim(n, v, max_batch_size); - struct kann_cu_graph *cg = - (struct kann_cu_graph *)calloc(1, sizeof(struct kann_cu_graph)); + struct kann_cu_graph *cg = (struct kann_cu_graph *)calloc(1, sizeof(struct kann_cu_graph)); cg->n_node = n; cg->max_batch_size = max_batch_size; cg->cur_batch_size = max_batch_size; // Build host-side node metadata array (persisted as host mirror) - cg->h_nodes = - (struct kann_cu_node *)calloc(n, sizeof(struct kann_cu_node)); + cg->h_nodes = (struct kann_cu_node *)calloc(n, sizeof(struct kann_cu_node)); // First pass: assign offsets into flat x/g buffers int x_total = 0, g_total = 0; @@ -404,13 +406,15 @@ kann_cu_graph_new(kann_t *ann, int max_batch_size) cg->h_nodes[i].ext_flag = p->ext_flag; cg->h_nodes[i].ext_label = p->ext_label; cg->h_nodes[i].len = len; - for (int d = 0; d < KAD_MAX_DIM; ++d) + for (int d = 0; d < KAD_MAX_DIM; ++d) { cg->h_nodes[i].d[d] = p->d[d]; + } // Integer parameter for select op cg->h_nodes[i].ptr_i32 = 0; - if (p->ptr && (p->op == 12)) + if (p->ptr && (p->op == 12)) { cg->h_nodes[i].ptr_i32 = *(int32_t *)p->ptr; + } // Pre-linkage (RNN recurrence) cg->h_nodes[i].pre_idx = -1; @@ -459,10 +463,18 @@ kann_cu_graph_new(kann_t *ann, int max_batch_size) int n_var = 0, n_const = 0; for (int i = 0; i < n; ++i) { kad_node_t *p = v[i]; - if (p->ext_flag & KANN_F_IN) cg->in_node_idx = i; - if (p->ext_flag & KANN_F_TRUTH) cg->truth_node_idx = i; - if (p->ext_flag & KANN_F_COST) cg->cost_node_idx = i; - if (p->ext_flag & KANN_F_OUT) cg->out_node_idx = i; + if (p->ext_flag & KANN_F_IN) { + cg->in_node_idx = i; + } + if (p->ext_flag & KANN_F_TRUTH) { + cg->truth_node_idx = i; + } + if (p->ext_flag & KANN_F_COST) { + cg->cost_node_idx = i; + } + if (p->ext_flag & KANN_F_OUT) { + cg->out_node_idx = i; + } if (kad_is_var(p)) { n_var_nodes++; @@ -475,13 +487,11 @@ kann_cu_graph_new(kann_t *ann, int max_batch_size) } // Build scatter arrays - cg->h_vars = (struct kann_cu_var_node *)malloc( - n_var_nodes * sizeof(struct kann_cu_var_node)); + cg->h_vars = (struct kann_cu_var_node *)malloc(n_var_nodes * sizeof(struct kann_cu_var_node)); cg->n_var_nodes = n_var_nodes; cg->n_var = n_var; - cg->h_consts = (struct kann_cu_var_node *)malloc( - n_const_nodes * sizeof(struct kann_cu_var_node)); + cg->h_consts = (struct kann_cu_var_node *)malloc(n_const_nodes * sizeof(struct kann_cu_var_node)); cg->n_const_nodes = n_const_nodes; cg->n_const = n_const; @@ -509,17 +519,23 @@ kann_cu_graph_new(kann_t *ann, int max_batch_size) // Build forward/backward order (internal nodes only) int n_internal = 0; - for (int i = 0; i < n; ++i) - if (v[i]->n_child > 0) n_internal++; + for (int i = 0; i < n; ++i) { + if (v[i]->n_child > 0) { + n_internal++; + } + } cg->h_fwd_order = (int *)malloc(n_internal * sizeof(int)); cg->h_bwd_order = (int *)malloc(n_internal * sizeof(int)); int fi = 0; - for (int i = 0; i < n; ++i) - if (v[i]->n_child > 0) + for (int i = 0; i < n; ++i) { + if (v[i]->n_child > 0) { cg->h_fwd_order[fi++] = i; - for (int i = 0; i < n_internal; ++i) + } + } + for (int i = 0; i < n_internal; ++i) { cg->h_bwd_order[i] = cg->h_fwd_order[n_internal - 1 - i]; + } cg->n_internal = n_internal; @@ -540,8 +556,8 @@ kann_cu_graph_new(kann_t *ann, int max_batch_size) } // Assign stdnorm cache offset (m floats per stdnorm node) if (p->op == 32 && p->n_child > 0) { - int child_n = cg->h_nodes[cg->h_nodes[i].child_idx[0]].d[ - cg->h_nodes[cg->h_nodes[i].child_idx[0]].n_d - 1]; + int child_n = + cg->h_nodes[cg->h_nodes[i].child_idx[0]].d[cg->h_nodes[cg->h_nodes[i].child_idx[0]].n_d - 1]; int m = cg->h_nodes[i].len / child_n; cg->h_nodes[i].si_off = si_total; si_total += m; @@ -556,8 +572,8 @@ kann_cu_graph_new(kann_t *ann, int max_batch_size) int pi = 0; for (int i = 0; i < n; ++i) { if (cg->h_nodes[i].pre_idx >= 0) { - cg->h_pre_pairs[2*pi] = i; // output node - cg->h_pre_pairs[2*pi+1] = cg->h_nodes[i].pre_idx; // h0 node + cg->h_pre_pairs[2 * pi] = i; // output node + cg->h_pre_pairs[2 * pi + 1] = cg->h_nodes[i].pre_idx; // h0 node pi++; } } @@ -570,12 +586,10 @@ kann_cu_graph_new(kann_t *ann, int max_batch_size) cg->x = (float *)gkyl_cu_malloc(x_total * sizeof(float)); cg->g = (float *)gkyl_cu_malloc(g_total * sizeof(float)); cg->r = (float *)gkyl_cu_malloc(n_var * sizeof(float)); - cg->stdnorm_si = si_total > 0 - ? (float *)gkyl_cu_malloc(si_total * sizeof(float)) : NULL; + cg->stdnorm_si = si_total > 0 ? (float *)gkyl_cu_malloc(si_total * sizeof(float)) : NULL; // Upload node metadata to device - gkyl_cu_memcpy(cg->nodes, cg->h_nodes, n * sizeof(struct kann_cu_node), - GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(cg->nodes, cg->h_nodes, n * sizeof(struct kann_cu_node), GKYL_CU_MEMCPY_H2D); // Zero out device buffers cudaMemset(cg->x, 0, x_total * sizeof(float)); @@ -587,8 +601,7 @@ kann_cu_graph_new(kann_t *ann, int max_batch_size) kad_node_t *p = v[i]; int len = cg->h_nodes[i].len; if (p->x && len > 0 && kad_is_ext(p)) { - gkyl_cu_memcpy(cg->x + cg->h_nodes[i].x_off, p->x, - len * sizeof(float), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(cg->x + cg->h_nodes[i].x_off, p->x, len * sizeof(float), GKYL_CU_MEMCPY_H2D); } } @@ -598,15 +611,18 @@ kann_cu_graph_new(kann_t *ann, int max_batch_size) return cg; } -void -kann_cu_graph_free(struct kann_cu_graph *cg) +void kann_cu_graph_free(struct kann_cu_graph *cg) { - if (!cg) return; + if (!cg) { + return; + } gkyl_cu_free(cg->nodes); gkyl_cu_free(cg->x); gkyl_cu_free(cg->g); gkyl_cu_free(cg->r); - if (cg->stdnorm_si) gkyl_cu_free(cg->stdnorm_si); + if (cg->stdnorm_si) { + gkyl_cu_free(cg->stdnorm_si); + } free(cg->h_nodes); free(cg->h_vars); free(cg->h_consts); @@ -616,41 +632,47 @@ kann_cu_graph_free(struct kann_cu_graph *cg) free(cg); } -void -kann_cu_graph_upload_vars(struct kann_cu_graph *cg, const kann_t *ann) +void kann_cu_graph_upload_vars(struct kann_cu_graph *cg, const kann_t *ann) { - if (!ann->x) return; + if (!ann->x) { + return; + } int host_off = 0; for (int i = 0; i < cg->n_var_nodes; ++i) { struct kann_cu_var_node *vn = &cg->h_vars[i]; - gkyl_cu_memcpy(cg->x + vn->x_off, ann->x + host_off, - vn->len * sizeof(float), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + cg->x + vn->x_off, ann->x + host_off, vn->len * sizeof(float), GKYL_CU_MEMCPY_H2D + ); host_off += vn->len; } } -void -kann_cu_graph_download_vars(struct kann_cu_graph *cg, kann_t *ann) +void kann_cu_graph_download_vars(struct kann_cu_graph *cg, kann_t *ann) { - if (!ann->x) return; + if (!ann->x) { + return; + } int host_off = 0; for (int i = 0; i < cg->n_var_nodes; ++i) { struct kann_cu_var_node *vn = &cg->h_vars[i]; - gkyl_cu_memcpy(ann->x + host_off, cg->x + vn->x_off, - vn->len * sizeof(float), GKYL_CU_MEMCPY_D2H); + gkyl_cu_memcpy( + ann->x + host_off, cg->x + vn->x_off, vn->len * sizeof(float), GKYL_CU_MEMCPY_D2H + ); host_off += vn->len; } } -void -kann_cu_graph_upload_consts(struct kann_cu_graph *cg, const kann_t *ann) +void kann_cu_graph_upload_consts(struct kann_cu_graph *cg, const kann_t *ann) { - if (!ann->c) return; + if (!ann->c) { + return; + } int host_off = 0; for (int i = 0; i < cg->n_const_nodes; ++i) { struct kann_cu_var_node *cn = &cg->h_consts[i]; - gkyl_cu_memcpy(cg->x + cn->x_off, ann->c + host_off, - cn->len * sizeof(float), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + cg->x + cn->x_off, ann->c + host_off, cn->len * sizeof(float), GKYL_CU_MEMCPY_H2D + ); host_off += cn->len; } } @@ -658,10 +680,11 @@ kann_cu_graph_upload_consts(struct kann_cu_graph *cg, const kann_t *ann) // Update node dimensions for a new batch size. Uses the host kann_t // to run proper kad_sync_dim propagation, then copies updated dims // to the host mirror and re-uploads to device. -void -kann_cu_sync_dim(struct kann_cu_graph *cg, kann_t *ann, int batch_size) +void kann_cu_sync_dim(struct kann_cu_graph *cg, kann_t *ann, int batch_size) { - if (batch_size == cg->cur_batch_size) return; + if (batch_size == cg->cur_batch_size) { + return; + } assert(batch_size <= cg->max_batch_size); // Run proper dimension propagation on host @@ -671,14 +694,16 @@ kann_cu_sync_dim(struct kann_cu_graph *cg, kann_t *ann, int batch_size) for (int i = 0; i < cg->n_node; ++i) { kad_node_t *p = ann->v[i]; cg->h_nodes[i].n_d = p->n_d; - for (int d = 0; d < KAD_MAX_DIM; ++d) + for (int d = 0; d < KAD_MAX_DIM; ++d) { cg->h_nodes[i].d[d] = p->d[d]; + } cg->h_nodes[i].len = host_kad_len(p); } // Re-upload metadata to device - gkyl_cu_memcpy(cg->nodes, cg->h_nodes, - cg->n_node * sizeof(struct kann_cu_node), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + cg->nodes, cg->h_nodes, cg->n_node * sizeof(struct kann_cu_node), GKYL_CU_MEMCPY_H2D + ); cg->cur_batch_size = batch_size; } @@ -688,14 +713,15 @@ kann_cu_sync_dim(struct kann_cu_graph *cg, kann_t *ann, int batch_size) // ============================================================ static void -dispatch_forward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, - struct kann_cu_node *hn, int idx) +dispatch_forward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, struct kann_cu_node *hn, int idx) { struct kann_cu_node *p = &hn[idx]; int len = p->len; float *px = cg->x + p->x_off; - if (p->n_child == 0) return; + if (p->n_child == 0) { + return; + } float *cx[KANN_CU_MAX_CHILD]; int clen[KANN_CU_MAX_CHILD]; @@ -710,88 +736,92 @@ dispatch_forward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, switch (p->op) { case 1: // add nb = cu_nblocks(clen[0]); - ker_add_fwd<<>>(clen[0], clen[1], cx[0], cx[1], px); + ker_add_fwd<< > >(clen[0], clen[1], cx[0], cx[1], px); break; case 2: // mul nb = cu_nblocks(clen[0]); - ker_mul_fwd<<>>(clen[0], clen[1], cx[0], cx[1], px); + ker_mul_fwd<< > >(clen[0], clen[1], cx[0], cx[1], px); break; case 3: { // cmul: Y = X * W^T via cublasSgemm struct kann_cu_node *q0 = &hn[p->child_idx[0]]; struct kann_cu_node *q1 = &hn[p->child_idx[1]]; - int n_col = q0->d[q0->n_d - 1] > q1->d[q1->n_d - 1] - ? q0->d[q0->n_d - 1] : q1->d[q1->n_d - 1]; + int n_col = q0->d[q0->n_d - 1] > q1->d[q1->n_d - 1] ? q0->d[q0->n_d - 1] : q1->d[q1->n_d - 1]; int n_a_col = 1, n_b_col = 1; - for (int i = q0->n_d - 1; i >= 0; --i) { if (n_a_col < n_col) n_a_col *= q0->d[i]; } - for (int i = q1->n_d - 1; i >= 0; --i) { if (n_b_col < n_col) n_b_col *= q1->d[i]; } + for (int i = q0->n_d - 1; i >= 0; --i) { + if (n_a_col < n_col) { + n_a_col *= q0->d[i]; + } + } + for (int i = q1->n_d - 1; i >= 0; --i) { + if (n_b_col < n_col) { + n_b_col *= q1->d[i]; + } + } int n_a_row = q0->len / n_a_col; int n_b_row = q1->len / n_b_col; // Row-major C = A * B^T <==> col-major C^T = B * A^T float alpha = 1.0f, beta = 0.0f; - cublasSgemm(cublas_h, - CUBLAS_OP_T, CUBLAS_OP_N, - n_b_row, n_a_row, n_col, - &alpha, - cx[1], n_b_col, - cx[0], n_a_col, - &beta, - px, n_b_row); + cublasSgemm( + cublas_h, CUBLAS_OP_T, CUBLAS_OP_N, n_b_row, n_a_row, n_col, &alpha, cx[1], n_b_col, cx[0], + n_a_col, &beta, px, n_b_row + ); break; } case 6: // sigm nb = cu_nblocks(len); - ker_sigm_fwd<<>>(len, cx[0], px); + ker_sigm_fwd<< > >(len, cx[0], px); break; case 7: // tanh nb = cu_nblocks(len); - ker_tanh_fwd<<>>(len, cx[0], px); + ker_tanh_fwd<< > >(len, cx[0], px); break; case 8: // relu nb = cu_nblocks(len); - ker_relu_fwd<<>>(len, cx[0], px); + ker_relu_fwd<< > >(len, cx[0], px); break; case 10: { // avg: mean of n_child tensors float inv = 1.0f / p->n_child; nb = cu_nblocks(len); - ker_zero<<>>(len, px); + ker_zero<< > >(len, px); for (int c = 0; c < p->n_child; ++c) { int ci = p->child_idx[c]; - ker_saxpy<<>>(len, inv, cg->x + hn[ci].x_off, px); + ker_saxpy<< > >(len, inv, cg->x + hn[ci].x_off, px); } break; } case 11: // 1minus nb = cu_nblocks(len); - ker_1minus_fwd<<>>(len, cx[0], px); + ker_1minus_fwd<< > >(len, cx[0], px); break; case 12: { // select int which = p->ptr_i32; - if (which < 0) which += p->n_child; + if (which < 0) { + which += p->n_child; + } int ci = p->child_idx[which]; int slen = hn[ci].len; - cudaMemcpy(px, cg->x + hn[ci].x_off, slen * sizeof(float), - cudaMemcpyDeviceToDevice); + cudaMemcpy(px, cg->x + hn[ci].x_off, slen * sizeof(float), cudaMemcpyDeviceToDevice); break; } case 14: { // softmax int n1 = hn[p->child_idx[0]].d[hn[p->child_idx[0]].n_d - 1]; int d0 = clen[0] / n1; - ker_softmax_fwd<<>>(d0, n1, cx[0], px); + ker_softmax_fwd<< > >(d0, n1, cx[0], px); break; } case 29: // mse - ker_mse_fwd<<<1, KANN_CU_THREADS>>>(clen[0], cx[0], cx[1], px); + ker_mse_fwd<<<1, KANN_CU_THREADS> > >(clen[0], cx[0], cx[1], px); break; case 32: { // stdnorm (layer normalization) @@ -799,12 +829,15 @@ dispatch_forward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, int sn = q->d[q->n_d - 1]; int sm = len / sn; int threads = KANN_CU_THREADS; - if (threads > sn) threads = sn; + if (threads > sn) { + threads = sn; + } // Round down to power of 2 for shared-memory reduction int t2 = 1; - while (t2 * 2 <= threads) t2 *= 2; - ker_stdnorm_fwd<<>>( - sm, sn, cx[0], px, cg->stdnorm_si + p->si_off); + while (t2 * 2 <= threads) { + t2 *= 2; + } + ker_stdnorm_fwd<< > >(sm, sn, cx[0], px, cg->stdnorm_si + p->si_off); break; } @@ -814,14 +847,16 @@ dispatch_forward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, } } -static void -dispatch_backward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, - struct kann_cu_node *hn, int idx) +static void dispatch_backward( + struct kann_cu_graph *cg, cublasHandle_t cublas_h, struct kann_cu_node *hn, int idx +) { struct kann_cu_node *p = &hn[idx]; float *pg = cg->g + p->g_off; - if (p->n_child == 0) return; + if (p->n_child == 0) { + return; + } float *cx[KANN_CU_MAX_CHILD], *cg_arr[KANN_CU_MAX_CHILD]; int clen[KANN_CU_MAX_CHILD]; @@ -840,58 +875,57 @@ dispatch_backward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, case 1: // add if ((cflag[0] & KAD_VAR) && cg_arr[0]) { nb = cu_nblocks(clen[0]); - ker_add_bwd_child0<<>>(clen[0], pg, cg_arr[0]); + ker_add_bwd_child0<< > >(clen[0], pg, cg_arr[0]); } if ((cflag[1] & KAD_VAR) && cg_arr[1]) { nb = cu_nblocks(clen[1]); - ker_add_bwd_child1<<>>(clen[0], clen[1], pg, cg_arr[1]); + ker_add_bwd_child1<< > >(clen[0], clen[1], pg, cg_arr[1]); } break; case 2: // mul if ((cflag[0] & KAD_VAR) && cg_arr[0]) { nb = cu_nblocks(clen[0]); - ker_mul_bwd_child0<<>>(clen[0], clen[1], pg, cx[1], cg_arr[0]); + ker_mul_bwd_child0<< > >(clen[0], clen[1], pg, cx[1], cg_arr[0]); } if ((cflag[1] & KAD_VAR) && cg_arr[1]) { nb = cu_nblocks(clen[1]); - ker_mul_bwd_child1<<>>(clen[0], clen[1], pg, cx[0], cg_arr[1]); + ker_mul_bwd_child1<< > >(clen[0], clen[1], pg, cx[0], cg_arr[1]); } break; case 3: { // cmul backward struct kann_cu_node *q0 = &hn[p->child_idx[0]]; struct kann_cu_node *q1 = &hn[p->child_idx[1]]; - int n_col = q0->d[q0->n_d - 1] > q1->d[q1->n_d - 1] - ? q0->d[q0->n_d - 1] : q1->d[q1->n_d - 1]; + int n_col = q0->d[q0->n_d - 1] > q1->d[q1->n_d - 1] ? q0->d[q0->n_d - 1] : q1->d[q1->n_d - 1]; int n_a_col = 1, n_b_col = 1; - for (int i = q0->n_d - 1; i >= 0; --i) { if (n_a_col < n_col) n_a_col *= q0->d[i]; } - for (int i = q1->n_d - 1; i >= 0; --i) { if (n_b_col < n_col) n_b_col *= q1->d[i]; } + for (int i = q0->n_d - 1; i >= 0; --i) { + if (n_a_col < n_col) { + n_a_col *= q0->d[i]; + } + } + for (int i = q1->n_d - 1; i >= 0; --i) { + if (n_b_col < n_col) { + n_b_col *= q1->d[i]; + } + } int n_a_row = q0->len / n_a_col; int n_b_row = q1->len / n_b_col; float alpha = 1.0f, beta = 1.0f; // G_x += G_y * W if ((cflag[0] & KAD_VAR) && cg_arr[0]) { - cublasSgemm(cublas_h, - CUBLAS_OP_N, CUBLAS_OP_N, - n_a_col, n_a_row, n_b_row, - &alpha, - cx[1], n_b_col, - pg, n_b_row, - &beta, - cg_arr[0], n_a_col); + cublasSgemm( + cublas_h, CUBLAS_OP_N, CUBLAS_OP_N, n_a_col, n_a_row, n_b_row, &alpha, cx[1], n_b_col, pg, + n_b_row, &beta, cg_arr[0], n_a_col + ); } // G_w += G_y^T * X if ((cflag[1] & KAD_VAR) && cg_arr[1]) { - cublasSgemm(cublas_h, - CUBLAS_OP_N, CUBLAS_OP_T, - n_b_col, n_b_row, n_a_row, - &alpha, - cx[0], n_a_col, - pg, n_b_row, - &beta, - cg_arr[1], n_b_col); + cublasSgemm( + cublas_h, CUBLAS_OP_N, CUBLAS_OP_T, n_b_col, n_b_row, n_a_row, &alpha, cx[0], n_a_col, pg, + n_b_row, &beta, cg_arr[1], n_b_col + ); } break; } @@ -900,7 +934,7 @@ dispatch_backward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, if ((cflag[0] & KAD_VAR) && cg_arr[0]) { float *px = cg->x + p->x_off; nb = cu_nblocks(p->len); - ker_sigm_bwd<<>>(p->len, pg, px, cg_arr[0]); + ker_sigm_bwd<< > >(p->len, pg, px, cg_arr[0]); } break; @@ -908,14 +942,14 @@ dispatch_backward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, if ((cflag[0] & KAD_VAR) && cg_arr[0]) { float *px = cg->x + p->x_off; nb = cu_nblocks(p->len); - ker_tanh_bwd<<>>(p->len, pg, px, cg_arr[0]); + ker_tanh_bwd<< > >(p->len, pg, px, cg_arr[0]); } break; case 8: // relu if ((cflag[0] & KAD_VAR) && cg_arr[0]) { nb = cu_nblocks(p->len); - ker_relu_bwd<<>>(p->len, pg, cx[0], cg_arr[0]); + ker_relu_bwd<< > >(p->len, pg, cx[0], cg_arr[0]); } break; @@ -924,8 +958,9 @@ dispatch_backward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, nb = cu_nblocks(p->len); for (int c = 0; c < p->n_child; ++c) { int ci = p->child_idx[c]; - if ((hn[ci].flag & KAD_VAR) && hn[ci].g_off >= 0) - ker_saxpy<<>>(p->len, inv, pg, cg->g + hn[ci].g_off); + if ((hn[ci].flag & KAD_VAR) && hn[ci].g_off >= 0) { + ker_saxpy<< > >(p->len, inv, pg, cg->g + hn[ci].g_off); + } } break; } @@ -933,18 +968,20 @@ dispatch_backward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, case 11: // 1minus if ((cflag[0] & KAD_VAR) && cg_arr[0]) { nb = cu_nblocks(p->len); - ker_1minus_bwd<<>>(p->len, pg, cg_arr[0]); + ker_1minus_bwd<< > >(p->len, pg, cg_arr[0]); } break; case 12: { // select int which = p->ptr_i32; - if (which < 0) which += p->n_child; + if (which < 0) { + which += p->n_child; + } int ci = p->child_idx[which]; if ((hn[ci].flag & KAD_VAR) && hn[ci].g_off >= 0) { int slen = hn[ci].len; nb = cu_nblocks(slen); - ker_saxpy<<>>(slen, 1.0f, pg, cg->g + hn[ci].g_off); + ker_saxpy<< > >(slen, 1.0f, pg, cg->g + hn[ci].g_off); } break; } @@ -955,7 +992,7 @@ dispatch_backward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, int n1 = q->d[q->n_d - 1]; int d0 = q->len / n1; float *px = cg->x + p->x_off; - ker_softmax_bwd<<>>(d0, n1, pg, px, cg_arr[0]); + ker_softmax_bwd<< > >(d0, n1, pg, px, cg_arr[0]); } break; } @@ -963,7 +1000,7 @@ dispatch_backward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, case 29: // mse if ((cflag[0] & KAD_VAR) && cg_arr[0]) { nb = cu_nblocks(clen[0]); - ker_mse_bwd<<>>(clen[0], pg, cx[0], cx[1], cg_arr[0]); + ker_mse_bwd<< > >(clen[0], pg, cx[0], cx[1], cg_arr[0]); } break; @@ -974,11 +1011,16 @@ dispatch_backward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, int sm = p->len / sn; float *px = cg->x + p->x_off; int threads = KANN_CU_THREADS; - if (threads > sn) threads = sn; + if (threads > sn) { + threads = sn; + } int t2 = 1; - while (t2 * 2 <= threads) t2 *= 2; - ker_stdnorm_bwd<<>>( - sm, sn, pg, px, cg->stdnorm_si + p->si_off, cg_arr[0]); + while (t2 * 2 <= threads) { + t2 *= 2; + } + ker_stdnorm_bwd<< > >( + sm, sn, pg, px, cg->stdnorm_si + p->si_off, cg_arr[0] + ); } break; } @@ -993,129 +1035,126 @@ dispatch_backward(struct kann_cu_graph *cg, cublasHandle_t cublas_h, // Public API implementations // ============================================================ -void -kann_cu_forward(struct kann_cu_graph *cg, void *cublas_h, int to) +void kann_cu_forward(struct kann_cu_graph *cg, void *cublas_h, int to) { struct kann_cu_node *hn = cg->h_nodes; // use persistent host mirror int stop = (to >= 0) ? to : cg->n_node - 1; for (int fi = 0; fi < cg->n_internal; ++fi) { int idx = cg->h_fwd_order[fi]; - if (idx > stop) break; + if (idx > stop) { + break; + } dispatch_forward(cg, (cublasHandle_t)cublas_h, hn, idx); } } -void -kann_cu_backward(struct kann_cu_graph *cg, void *cublas_h, int from) +void kann_cu_backward(struct kann_cu_graph *cg, void *cublas_h, int from) { struct kann_cu_node *hn = cg->h_nodes; // Zero all gradients - if (cg->g_total > 0) + if (cg->g_total > 0) { cudaMemset(cg->g, 0, cg->g_total * sizeof(float)); + } // Set cost gradient to 1.0 if (from >= 0 && hn[from].g_off >= 0) { float one = 1.0f; - gkyl_cu_memcpy(cg->g + hn[from].g_off, &one, sizeof(float), - GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(cg->g + hn[from].g_off, &one, sizeof(float), GKYL_CU_MEMCPY_H2D); } // Backward pass int start = (from >= 0) ? from : cg->n_node - 1; for (int bi = 0; bi < cg->n_internal; ++bi) { int idx = cg->h_bwd_order[bi]; - if (idx > start) continue; + if (idx > start) { + continue; + } dispatch_backward(cg, (cublasHandle_t)cublas_h, hn, idx); } } -void -kann_cu_zero_grad(struct kann_cu_graph *cg) +void kann_cu_zero_grad(struct kann_cu_graph *cg) { - if (cg->g_total > 0) + if (cg->g_total > 0) { cudaMemset(cg->g, 0, cg->g_total * sizeof(float)); + } } -void -kann_cu_rmsprop(struct kann_cu_graph *cg, float lr, float decay) +void kann_cu_rmsprop(struct kann_cu_graph *cg, float lr, float decay) { // Variables are scattered in the x buffer, so iterate per variable node for (int i = 0; i < cg->n_var_nodes; ++i) { struct kann_cu_var_node *vn = &cg->h_vars[i]; int nb = cu_nblocks(vn->len); - ker_rmsprop<<>>( + ker_rmsprop<< > >( vn->len, lr, decay, - cg->g + vn->g_off, // this variable's gradients (contiguous in g) - cg->x + vn->x_off, // this variable's values (scattered in x) - cg->r + vn->r_off // this variable's RMSprop accumulator + cg->g + vn->g_off, // this variable's gradients (contiguous in g) + cg->x + vn->x_off, // this variable's values (scattered in x) + cg->r + vn->r_off // this variable's RMSprop accumulator ); } } -void -kann_cu_feed_input(struct kann_cu_graph *cg, int batch_size, const float *x_host) +void kann_cu_feed_input(struct kann_cu_graph *cg, int batch_size, const float *x_host) { struct kann_cu_node *hn = &cg->h_nodes[cg->in_node_idx]; - gkyl_cu_memcpy(cg->x + hn->x_off, x_host, - hn->len * sizeof(float), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(cg->x + hn->x_off, x_host, hn->len * sizeof(float), GKYL_CU_MEMCPY_H2D); } -void -kann_cu_feed_truth(struct kann_cu_graph *cg, int batch_size, const float *y_host) +void kann_cu_feed_truth(struct kann_cu_graph *cg, int batch_size, const float *y_host) { struct kann_cu_node *hn = &cg->h_nodes[cg->truth_node_idx]; - gkyl_cu_memcpy(cg->x + hn->x_off, y_host, - hn->len * sizeof(float), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(cg->x + hn->x_off, y_host, hn->len * sizeof(float), GKYL_CU_MEMCPY_H2D); } // Gather kernel: pick rows from src using indices and write contiguous __global__ static void -ker_gather_rows(int total, int stride, const float *src, - const int *indices, int offset, float *dst) +ker_gather_rows(int total, int stride, const float *src, const int *indices, int offset, float *dst) { - for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < total; - i += blockDim.x * gridDim.x) { + for (int i = threadIdx.x + blockIdx.x * blockDim.x; i < total; i += blockDim.x * gridDim.x) { int row = i / stride; int col = i % stride; dst[i] = src[indices[offset + row] * stride + col]; } } -void -kann_cu_gather_input(struct kann_cu_graph *cg, const float *data_d, - const int *indices_d, int offset, int batch_size, int stride) +void kann_cu_gather_input( + struct kann_cu_graph *cg, const float *data_d, const int *indices_d, int offset, int batch_size, + int stride +) { struct kann_cu_node *hn = &cg->h_nodes[cg->in_node_idx]; int total = batch_size * stride; int nb = cu_nblocks(total); - ker_gather_rows<<>>( - total, stride, data_d, indices_d, offset, cg->x + hn->x_off); + ker_gather_rows<< > >( + total, stride, data_d, indices_d, offset, cg->x + hn->x_off + ); } -void -kann_cu_gather_truth(struct kann_cu_graph *cg, const float *data_d, - const int *indices_d, int offset, int batch_size, int stride) +void kann_cu_gather_truth( + struct kann_cu_graph *cg, const float *data_d, const int *indices_d, int offset, int batch_size, + int stride +) { struct kann_cu_node *hn = &cg->h_nodes[cg->truth_node_idx]; int total = batch_size * stride; int nb = cu_nblocks(total); - ker_gather_rows<<>>( - total, stride, data_d, indices_d, offset, cg->x + hn->x_off); + ker_gather_rows<< > >( + total, stride, data_d, indices_d, offset, cg->x + hn->x_off + ); } -void -kann_cu_feed_input_dev(struct kann_cu_graph *cg, int batch_size, - const float *x_dev, int stride) +void kann_cu_feed_input_dev(struct kann_cu_graph *cg, int batch_size, const float *x_dev, int stride) { struct kann_cu_node *hn = &cg->h_nodes[cg->in_node_idx]; - cudaMemcpy(cg->x + hn->x_off, x_dev, - batch_size * stride * sizeof(float), cudaMemcpyDeviceToDevice); + cudaMemcpy( + cg->x + hn->x_off, x_dev, batch_size * stride * sizeof(float), cudaMemcpyDeviceToDevice + ); } -float -kann_cu_get_cost(const struct kann_cu_graph *cg) +float kann_cu_get_cost(const struct kann_cu_graph *cg) { struct kann_cu_node *hn = &cg->h_nodes[cg->cost_node_idx]; float cost; @@ -1123,25 +1162,23 @@ kann_cu_get_cost(const struct kann_cu_graph *cg) return cost; } -void -kann_cu_get_output(const struct kann_cu_graph *cg, int batch_size, float *out_host) +void kann_cu_get_output(const struct kann_cu_graph *cg, int batch_size, float *out_host) { int idx = cg->out_node_idx >= 0 ? cg->out_node_idx : cg->cost_node_idx; struct kann_cu_node *hn = &cg->h_nodes[idx]; - gkyl_cu_memcpy(out_host, cg->x + hn->x_off, - hn->len * sizeof(float), GKYL_CU_MEMCPY_D2H); + gkyl_cu_memcpy(out_host, cg->x + hn->x_off, hn->len * sizeof(float), GKYL_CU_MEMCPY_D2H); } -void -kann_cu_apply_pre(struct kann_cu_graph *cg) +void kann_cu_apply_pre(struct kann_cu_graph *cg) { for (int i = 0; i < cg->n_pre_pairs; ++i) { - int out_idx = cg->h_pre_pairs[2*i]; - int h0_idx = cg->h_pre_pairs[2*i+1]; + int out_idx = cg->h_pre_pairs[2 * i]; + int h0_idx = cg->h_pre_pairs[2 * i + 1]; struct kann_cu_node *out_n = &cg->h_nodes[out_idx]; - struct kann_cu_node *h0_n = &cg->h_nodes[h0_idx]; + struct kann_cu_node *h0_n = &cg->h_nodes[h0_idx]; int len = h0_n->len < out_n->len ? h0_n->len : out_n->len; - cudaMemcpy(cg->x + h0_n->x_off, cg->x + out_n->x_off, - len * sizeof(float), cudaMemcpyDeviceToDevice); + cudaMemcpy( + cg->x + h0_n->x_off, cg->x + out_n->x_off, len * sizeof(float), cudaMemcpyDeviceToDevice + ); } } diff --git a/core/zero/knutils.c b/core/zero/knutils.c index a7785fe29d..ad1b3cbb85 100644 --- a/core/zero/knutils.c +++ b/core/zero/knutils.c @@ -7,8 +7,7 @@ #include #include -static void -kn_vec_free(const struct gkyl_ref_count *ref) +static void kn_vec_free(const struct gkyl_ref_count *ref) { struct gkyl_kn_vec *vec = container_of(ref, struct gkyl_kn_vec, ref_count); @@ -22,8 +21,7 @@ kn_vec_free(const struct gkyl_ref_count *ref) gkyl_free(vec); } -struct gkyl_kn_vec* -gkyl_kn_vec_new(int nvec, int N) +struct gkyl_kn_vec *gkyl_kn_vec_new(int nvec, int N) { struct gkyl_kn_vec *vec = gkyl_malloc(sizeof(*vec)); vec->nvec = nvec; @@ -31,12 +29,13 @@ gkyl_kn_vec_new(int nvec, int N) vec->flags = 0; vec->on_dev = 0; - vec->vals = gkyl_malloc(nvec * sizeof(float*)); + vec->vals = gkyl_malloc(nvec * sizeof(float *)); vec->data = gkyl_calloc(nvec * N, sizeof(float)); vec->vals[0] = &vec->data[0]; - for (int i = 1; i < nvec; ++i) - vec->vals[i] = vec->vals[i-1] + N; + for (int i = 1; i < nvec; ++i) { + vec->vals[i] = vec->vals[i - 1] + N; + } vec->ref_count = gkyl_ref_count_init(kn_vec_free); @@ -45,8 +44,7 @@ gkyl_kn_vec_new(int nvec, int N) #ifdef GKYL_HAVE_CUDA -struct gkyl_kn_vec* -gkyl_kn_vec_cu_dev_new(int nvec, int N) +struct gkyl_kn_vec *gkyl_kn_vec_cu_dev_new(int nvec, int N) { struct gkyl_kn_vec *vec = gkyl_malloc(sizeof(*vec)); vec->nvec = nvec; @@ -61,16 +59,14 @@ gkyl_kn_vec_cu_dev_new(int nvec, int N) // device-resident struct clone vec->on_dev = gkyl_cu_malloc(sizeof(struct gkyl_kn_vec)); - gkyl_cu_memcpy(vec->on_dev, vec, sizeof(struct gkyl_kn_vec), - GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(vec->on_dev, vec, sizeof(struct gkyl_kn_vec), GKYL_CU_MEMCPY_H2D); return vec; } #else -struct gkyl_kn_vec* -gkyl_kn_vec_cu_dev_new(int nvec, int N) +struct gkyl_kn_vec *gkyl_kn_vec_cu_dev_new(int nvec, int N) { assert(false); return 0; @@ -78,8 +74,7 @@ gkyl_kn_vec_cu_dev_new(int nvec, int N) #endif -struct gkyl_kn_vec* -gkyl_kn_vec_copy(struct gkyl_kn_vec *dest, const struct gkyl_kn_vec *src) +struct gkyl_kn_vec *gkyl_kn_vec_copy(struct gkyl_kn_vec *dest, const struct gkyl_kn_vec *src) { assert(dest->nvec == src->nvec); assert(dest->N == src->N); @@ -89,35 +84,34 @@ gkyl_kn_vec_copy(struct gkyl_kn_vec *dest, const struct gkyl_kn_vec *src) bool src_is_cu = GKYL_IS_CU_ALLOC(src->flags); if (src_is_cu) { - if (dest_is_cu) + if (dest_is_cu) { gkyl_cu_memcpy(dest->data, src->data, nbytes, GKYL_CU_MEMCPY_D2D); - else + } else { gkyl_cu_memcpy(dest->data, src->data, nbytes, GKYL_CU_MEMCPY_D2H); + } } else { - if (dest_is_cu) + if (dest_is_cu) { gkyl_cu_memcpy(dest->data, src->data, nbytes, GKYL_CU_MEMCPY_H2D); - else + } else { memcpy(dest->data, src->data, nbytes); + } } return dest; } -bool -gkyl_kn_vec_is_cu_dev(const struct gkyl_kn_vec *vec) +bool gkyl_kn_vec_is_cu_dev(const struct gkyl_kn_vec *vec) { return GKYL_IS_CU_ALLOC(vec->flags); } -struct gkyl_kn_vec* -gkyl_kn_vec_acquire(const struct gkyl_kn_vec *vec) +struct gkyl_kn_vec *gkyl_kn_vec_acquire(const struct gkyl_kn_vec *vec) { gkyl_ref_count_inc(&vec->ref_count); - return (struct gkyl_kn_vec*) vec; + return (struct gkyl_kn_vec *)vec; } -void -gkyl_kn_vec_release(struct gkyl_kn_vec *vec) +void gkyl_kn_vec_release(struct gkyl_kn_vec *vec) { gkyl_ref_count_dec(&vec->ref_count); } diff --git a/core/zero/lua_utils.c b/core/zero/lua_utils.c index 5edc299abe..fad1fe34cd 100644 --- a/core/zero/lua_utils.c +++ b/core/zero/lua_utils.c @@ -2,144 +2,142 @@ #include -static inline void -glua_getfield_int(lua_State *L, long key) +static inline void glua_getfield_int(lua_State *L, long key) { lua_pushinteger(L, key); lua_gettable(L, -2); } -bool -glua_tbl_has_key(lua_State *L, const char *key) +bool glua_tbl_has_key(lua_State *L, const char *key) { lua_getfield(L, -1, key); bool has_key = !lua_isnil(L, -1); lua_pop(L, 1); - return has_key; + return has_key; } -double -glua_tbl_get_number(lua_State *L, const char *key, double def) +double glua_tbl_get_number(lua_State *L, const char *key, double def) { double out = def; lua_getfield(L, -1, key); - if (!lua_isnil(L, -1) && lua_isnumber(L, -1)) + if (!lua_isnil(L, -1) && lua_isnumber(L, -1)) { out = lua_tonumber(L, -1); + } lua_pop(L, 1); return out; } -double -glua_tbl_iget_number(lua_State *L, long key, double def) +double glua_tbl_iget_number(lua_State *L, long key, double def) { double out = def; glua_getfield_int(L, key); - if (!lua_isnil(L, -1) && lua_isnumber(L, -1)) + if (!lua_isnil(L, -1) && lua_isnumber(L, -1)) { out = lua_tonumber(L, -1); + } lua_pop(L, 1); return out; } -long -glua_tbl_get_integer(lua_State *L, const char *key, long def) +long glua_tbl_get_integer(lua_State *L, const char *key, long def) { long out = def; lua_getfield(L, -1, key); - if (!lua_isnil(L, -1) && lua_isnumber(L, -1)) + if (!lua_isnil(L, -1) && lua_isnumber(L, -1)) { out = lua_tointeger(L, -1); + } lua_pop(L, 1); return out; } -long -glua_tbl_iget_integer(lua_State *L, long key, long def) +long glua_tbl_iget_integer(lua_State *L, long key, long def) { long out = def; glua_getfield_int(L, key); - if (!lua_isnil(L, -1) && lua_isnumber(L, -1)) + if (!lua_isnil(L, -1) && lua_isnumber(L, -1)) { out = lua_tointeger(L, -1); + } lua_pop(L, 1); return out; } -int -glua_tbl_get_bool(lua_State *L, const char *key, int def) +int glua_tbl_get_bool(lua_State *L, const char *key, int def) { int out = def; lua_getfield(L, -1, key); - if (!lua_isnil(L, -1) && lua_isboolean(L, -1)) + if (!lua_isnil(L, -1) && lua_isboolean(L, -1)) { out = lua_toboolean(L, -1); - lua_pop(L, 1); + } + lua_pop(L, 1); return out; } -int -glua_tbl_iget_bool(lua_State *L, long key, int def) +int glua_tbl_iget_bool(lua_State *L, long key, int def) { int out = def; glua_getfield_int(L, key); - if (!lua_isnil(L, -1) && lua_isboolean(L, -1)) + if (!lua_isnil(L, -1) && lua_isboolean(L, -1)) { out = lua_toboolean(L, -1); + } lua_pop(L, 1); - return out; + return out; } -const char * -glua_tbl_get_string(lua_State *L, const char *key, const char *def) +const char *glua_tbl_get_string(lua_State *L, const char *key, const char *def) { const char *out = def; lua_getfield(L, -1, key); - if (!lua_isnil(L, -1) && lua_isstring(L, -1)) + if (!lua_isnil(L, -1) && lua_isstring(L, -1)) { out = lua_tostring(L, -1); + } lua_pop(L, 1); return out; } -const char * -glua_tbl_iget_string(lua_State *L, long key, const char *def) +const char *glua_tbl_iget_string(lua_State *L, long key, const char *def) { const char *out = def; glua_getfield_int(L, key); - if (!lua_isnil(L, -1) && lua_isstring(L, -1)) + if (!lua_isnil(L, -1) && lua_isstring(L, -1)) { out = lua_tostring(L, -1); + } lua_pop(L, 1); return out; } -bool -glua_tbl_get_tbl(lua_State *L, const char *key) +bool glua_tbl_get_tbl(lua_State *L, const char *key) { lua_getfield(L, -1, key); return !lua_isnil(L, -1) && lua_istable(L, -1); } -bool -glua_tbl_iget_tbl(lua_State *L, long key) +bool glua_tbl_iget_tbl(lua_State *L, long key) { glua_getfield_int(L, key); return !lua_isnil(L, -1) && lua_istable(L, -1); } -bool -glua_tbl_get_func(lua_State *L, const char *key) +bool glua_tbl_get_func(lua_State *L, const char *key) { lua_getfield(L, -1, key); bool has_func = !lua_isnil(L, -1) && lua_isfunction(L, -1); - if (!has_func) lua_pop(L, 1); + if (!has_func) { + lua_pop(L, 1); + } return has_func; } -bool -glua_tbl_iget_func(lua_State *L, long key) +bool glua_tbl_iget_func(lua_State *L, long key) { glua_getfield_int(L, key); bool has_func = !lua_isnil(L, -1) && lua_isfunction(L, -1); - if (!has_func) lua_pop(L, 1); + if (!has_func) { + lua_pop(L, 1); + } return has_func; } -int -glua_run_lua(lua_State *L, const char *str, long sz, FILE *err) +int glua_run_lua(lua_State *L, const char *str, long sz, FILE *err) { if (luaL_loadbuffer(L, str, sz, "gkyl_run_lua-inp") || lua_pcall(L, 0, LUA_MULTRET, 0)) { - const char* ret = lua_tostring(L, -1); - if (err) + const char *ret = lua_tostring(L, -1); + if (err) { fprintf(err, "*** ERROR: %s\n", ret); + } return 1; } return 0; diff --git a/core/zero/mat.c b/core/zero/mat.c index 553dd998e1..d8e0750e1c 100644 --- a/core/zero/mat.c +++ b/core/zero/mat.c @@ -8,28 +8,25 @@ #include #ifdef GKYL_HAVE_CUDA -# include -# include +#include +#include #endif // BLAS and LAPACKE includes #ifdef GKYL_USING_FRAMEWORK_ACCELERATE -# include +#include #else // On non-Darwin platforms use OpenBLAS -# include -# include +#include +#include #endif #include #include /** Map Gkyl flags to CBLAS flags */ -static int cblas_trans_flags[] = { - [GKYL_NO_TRANS] = CblasNoTrans, - [GKYL_TRANS] = CblasTrans, - [GKYL_CONJ_TRANS] = CblasConjTrans -}; +static int cblas_trans_flags[] = + {[GKYL_NO_TRANS] = CblasNoTrans, [GKYL_TRANS] = CblasTrans, [GKYL_CONJ_TRANS] = CblasConjTrans}; struct gkyl_nmat_mem { bool on_gpu; // flag to indicate if we are on GPU @@ -46,74 +43,74 @@ struct gkyl_nmat_mem { #ifdef GKYL_HAVE_CUDA cublasHandle_t cuh; // cublas handle -#endif +#endif }; /** Helper functions to determine sizes needed in BLAS/LAPACKE routines */ -struct mat_sizes { size_t nr, nc; }; +struct mat_sizes { + size_t nr, nc; +}; -static inline struct mat_sizes -get_mat_sizes(enum gkyl_mat_trans trans, const struct gkyl_mat *A) +static inline struct mat_sizes get_mat_sizes(enum gkyl_mat_trans trans, const struct gkyl_mat *A) { - if (trans == GKYL_NO_TRANS) - return (struct mat_sizes) { .nr = A->nr, .nc = A->nc }; - return (struct mat_sizes) { .nr = A->nc, .nc = A->nr }; + if (trans == GKYL_NO_TRANS) { + return (struct mat_sizes){.nr = A->nr, .nc = A->nc}; + } + return (struct mat_sizes){.nr = A->nc, .nc = A->nr}; } -struct gkyl_mat* -gkyl_mat_clone(const struct gkyl_mat *in) +struct gkyl_mat *gkyl_mat_clone(const struct gkyl_mat *in) { struct gkyl_mat *m = gkyl_malloc(sizeof(struct gkyl_mat)); - m->data = gkyl_malloc(sizeof(double[in->nr*in->nc])); - m->nc = in->nc; m->nr = in->nr; - size_t tot = sizeof(double[in->nr*in->nc]); + m->data = gkyl_malloc(sizeof(double[in->nr * in->nc])); + m->nc = in->nc; + m->nr = in->nr; + size_t tot = sizeof(double[in->nr * in->nc]); memcpy(m->data, in->data, tot); return m; } -struct gkyl_mat* -gkyl_mat_diag(struct gkyl_mat *mat, double val) +struct gkyl_mat *gkyl_mat_diag(struct gkyl_mat *mat, double val) { gkyl_mat_clear(mat, 0.0); - for (size_t i=0; inr, mat->nc); ++i) + for (size_t i = 0; i < GKYL_MIN2(mat->nr, mat->nc); ++i) { gkyl_mat_set(mat, i, i, val); + } return mat; } -void -gkyl_mat_show(const char *name, FILE *fp, const struct gkyl_mat *mat) +void gkyl_mat_show(const char *name, FILE *fp, const struct gkyl_mat *mat) { fprintf(fp, "%s : matrix( ", name); - for (int i=0; inr-1; ++i) { + for (int i = 0; i < mat->nr - 1; ++i) { fprintf(fp, "["); - for (int j=0; jnc-1; ++j) { - fprintf(fp, "%lg, ", gkyl_mat_get(mat,i,j)); + for (int j = 0; j < mat->nc - 1; ++j) { + fprintf(fp, "%lg, ", gkyl_mat_get(mat, i, j)); } - fprintf(fp, "%lg ", gkyl_mat_get(mat,i,mat->nc-1)); + fprintf(fp, "%lg ", gkyl_mat_get(mat, i, mat->nc - 1)); fprintf(fp, "], "); } fprintf(fp, "["); - for (int j=0; jnc-1; ++j) { - fprintf(fp, "%lg, ", gkyl_mat_get(mat,mat->nr-1,j)); + for (int j = 0; j < mat->nc - 1; ++j) { + fprintf(fp, "%lg, ", gkyl_mat_get(mat, mat->nr - 1, j)); } - fprintf(fp, "%lg ", gkyl_mat_get(mat,mat->nr-1,mat->nc-1)); + fprintf(fp, "%lg ", gkyl_mat_get(mat, mat->nr - 1, mat->nc - 1)); fprintf(fp, "] "); - + fprintf(fp, " )\n"); } #ifdef GKYL_HAVE_CUDA -void -cu_mat_mm(double alpha, double beta, - enum gkyl_mat_trans transa, const struct gkyl_mat *A, - enum gkyl_mat_trans transb, const struct gkyl_mat *B, struct gkyl_mat *C) +void cu_mat_mm( + double alpha, double beta, enum gkyl_mat_trans transa, const struct gkyl_mat *A, + enum gkyl_mat_trans transb, const struct gkyl_mat *B, struct gkyl_mat *C +) { - // device handle - cublasHandle_t cuh; - cublasCreate_v2(&cuh); + cublasHandle_t cuh; + cublasCreate_v2(&cuh); // determine matrix sizes struct mat_sizes sza = get_mat_sizes(transa, A); @@ -125,29 +122,23 @@ cu_mat_mm(double alpha, double beta, size_t lda = transa == GKYL_NO_TRANS ? C->nr : k; size_t ldb = transb == GKYL_NO_TRANS ? k : C->nc; size_t ldc = C->nr; - - assert( (sza.nr == szc.nr) && (sza.nc == k) && (szb.nr == k) && (szb.nc == szc.nc) ); + + assert((sza.nr == szc.nr) && (sza.nc == k) && (szb.nr == k) && (szb.nc == szc.nc)); // call BLAS routine to perform matrix-matrix multiply - cublasDgemm(cuh, - transa, - transb, - C->nr, C->nc, k, - &alpha, - A->data, lda, - B->data, ldb, - &beta, C->data, ldc); + cublasDgemm( + cuh, transa, transb, C->nr, C->nc, k, &alpha, A->data, lda, B->data, ldb, &beta, C->data, ldc + ); // Destory the cuda handle cublasDestroy(cuh); } #endif - -void -ho_mat_mm(double alpha, double beta, - enum gkyl_mat_trans transa, const struct gkyl_mat *A, - enum gkyl_mat_trans transb, const struct gkyl_mat *B, struct gkyl_mat *C) +void ho_mat_mm( + double alpha, double beta, enum gkyl_mat_trans transa, const struct gkyl_mat *A, + enum gkyl_mat_trans transb, const struct gkyl_mat *B, struct gkyl_mat *C +) { // determine matrix sizes struct mat_sizes sza = get_mat_sizes(transa, A); @@ -159,30 +150,24 @@ ho_mat_mm(double alpha, double beta, size_t lda = transa == GKYL_NO_TRANS ? C->nr : k; size_t ldb = transb == GKYL_NO_TRANS ? k : C->nc; size_t ldc = C->nr; - - assert( (sza.nr == szc.nr) && (sza.nc == k) && (szb.nr == k) && (szb.nc == szc.nc) ); + + assert((sza.nr == szc.nr) && (sza.nc == k) && (szb.nr == k) && (szb.nc == szc.nc)); // call BLAS routine to perform matrix-matrix multiply - cblas_dgemm(CblasColMajor, - cblas_trans_flags[transa], - cblas_trans_flags[transb], - C->nr, C->nc, k, - alpha, - A->data, lda, - B->data, ldb, - beta, C->data, ldc); + cblas_dgemm( + CblasColMajor, cblas_trans_flags[transa], cblas_trans_flags[transb], C->nr, C->nc, k, alpha, + A->data, lda, B->data, ldb, beta, C->data, ldc + ); } - -struct gkyl_mat* -gkyl_mat_mm(double alpha, double beta, - enum gkyl_mat_trans transa, const struct gkyl_mat *A, - enum gkyl_mat_trans transb, const struct gkyl_mat *B, struct gkyl_mat *C, bool on_gpu) +struct gkyl_mat *gkyl_mat_mm( + double alpha, double beta, enum gkyl_mat_trans transa, const struct gkyl_mat *A, + enum gkyl_mat_trans transb, const struct gkyl_mat *B, struct gkyl_mat *C, bool on_gpu +) { - #ifdef GKYL_HAVE_CUDA // Now do the matrix multiply using either the cublas or lapack funcs. - if(on_gpu){ + if (on_gpu) { cu_mat_mm(alpha, beta, transa, A, transb, B, C); return C; } @@ -192,10 +177,10 @@ gkyl_mat_mm(double alpha, double beta, return C; } -struct gkyl_mat* -gkyl_mat_mv(double alpha, double beta, - enum gkyl_mat_trans transa, const struct gkyl_mat *A, - const struct gkyl_mat *x, struct gkyl_mat *y) +struct gkyl_mat *gkyl_mat_mv( + double alpha, double beta, enum gkyl_mat_trans transa, const struct gkyl_mat *A, + const struct gkyl_mat *x, struct gkyl_mat *y +) { // determine matrix sizes struct mat_sizes sza = get_mat_sizes(transa, A); @@ -206,29 +191,23 @@ gkyl_mat_mv(double alpha, double beta, size_t k = sza.nc; // same as szb.nr size_t lda = transa == GKYL_NO_TRANS ? A->nr : k; size_t ldc = y->nr; - - assert( (sza.nr == szy.nr) && (sza.nc == szx.nr) && (szx.nr == szy.nr) ); + + assert((sza.nr == szy.nr) && (sza.nc == szx.nr) && (szx.nr == szy.nr)); // call BLAS routine to perform matrix-matrix multiply int incx = 1; int incy = 1; - cblas_dgemv(CblasColMajor, - cblas_trans_flags[transa], - A->nr, A->nc, - alpha, - A->data, lda, - x->data, incx, - beta, y->data, incy); + cblas_dgemv( + CblasColMajor, cblas_trans_flags[transa], A->nr, A->nc, alpha, A->data, lda, x->data, incx, + beta, y->data, incy + ); return y; } - - -bool -gkyl_mat_linsolve_lu(struct gkyl_mat *A, struct gkyl_mat *x, void* ipiv) +bool gkyl_mat_linsolve_lu(struct gkyl_mat *A, struct gkyl_mat *x, void *ipiv) { - assert( A->nr == A->nc ); + assert(A->nr == A->nc); #ifdef GKYL_USING_FRAMEWORK_ACCELERATE // On Darwin need to use old clapack interface. Of course Apple has @@ -241,187 +220,180 @@ gkyl_mat_linsolve_lu(struct gkyl_mat *A, struct gkyl_mat *x, void* ipiv) dgesv_(&n, &nrhs, A->data, &lda, ipiv, x->data, &ldb, &info); #else // on non-Darwin platforms modern LAPACKE interface is available - int info = LAPACKE_dgesv(LAPACK_COL_MAJOR, - A->nr, x->nc, A->data, A->nr, ipiv, x->data, A->nr); + int info = LAPACKE_dgesv(LAPACK_COL_MAJOR, A->nr, x->nc, A->data, A->nr, ipiv, x->data, A->nr); #endif - + return info == 0 ? true : false; } -void -gkyl_mat_release(struct gkyl_mat *mat) +void gkyl_mat_release(struct gkyl_mat *mat) { - #ifdef GKYL_HAVE_CUDA - gkyl_ref_count_dec(&mat->ref_count); - #else +#ifdef GKYL_HAVE_CUDA + gkyl_ref_count_dec(&mat->ref_count); +#else if (mat) { gkyl_free(mat->data); gkyl_free(mat); } - #endif +#endif } -static void -mat_free(const struct gkyl_ref_count *ref) +static void mat_free(const struct gkyl_ref_count *ref) { struct gkyl_mat *mat = container_of(ref, struct gkyl_mat, ref_count); if (GKYL_IS_CU_ALLOC(mat->flags)) { gkyl_cu_free(mat->data); gkyl_cu_free(mat->on_dev); - } - else { + } else { gkyl_free(mat->data); } - gkyl_free(mat); + gkyl_free(mat); } -static void -nmat_free(const struct gkyl_ref_count *ref) +static void nmat_free(const struct gkyl_ref_count *ref) { struct gkyl_nmat *mat = container_of(ref, struct gkyl_nmat, ref_count); if (GKYL_IS_CU_ALLOC(mat->flags)) { gkyl_cu_free(mat->data); gkyl_cu_free(mat->mptr); gkyl_cu_free(mat->on_dev); - } - else { + } else { gkyl_free(mat->data); gkyl_free(mat->mptr); } - gkyl_free(mat); + gkyl_free(mat); } -struct gkyl_mat* -gkyl_mat_new(size_t nr, size_t nc, double val) +struct gkyl_mat *gkyl_mat_new(size_t nr, size_t nc, double val) { struct gkyl_mat *mat = gkyl_malloc(sizeof(struct gkyl_mat)); - mat->nr = nr; mat->nc = nc; + mat->nr = nr; + mat->nc = nc; mat->flags = 0; - mat->data = gkyl_malloc(sizeof(double[nr*nc])); + mat->data = gkyl_malloc(sizeof(double[nr * nc])); mat->on_dev = mat; // on CPU this is a self-reference mat->ref_count = gkyl_ref_count_init(mat_free); - for (size_t i=0; idata[i] = val; + for (size_t i = 0; i < nr * nc; ++i) { + mat->data[i] = val; + } return mat; } -struct gkyl_nmat* -gkyl_nmat_new(size_t num, size_t nr, size_t nc) +struct gkyl_nmat *gkyl_nmat_new(size_t num, size_t nr, size_t nc) { struct gkyl_nmat *mat = gkyl_malloc(sizeof(struct gkyl_nmat)); - mat->num = num; mat->nr = nr; mat->nc = nc; + mat->num = num; + mat->nr = nr; + mat->nc = nc; mat->flags = 0; - mat->data = gkyl_malloc(sizeof(double[num*nr*nc])); - mat->mptr = gkyl_malloc(num*sizeof(double*)); - for (size_t i=0; imptr[i] = mat->data+nr*nc*i; + mat->data = gkyl_malloc(sizeof(double[num * nr * nc])); + mat->mptr = gkyl_malloc(num * sizeof(double *)); + for (size_t i = 0; i < num; ++i) { + mat->mptr[i] = mat->data + nr * nc * i; + } mat->on_dev = mat; // on CPU this is a self-reference mat->ref_count = gkyl_ref_count_init(nmat_free); return mat; } -struct gkyl_nmat* -gkyl_nmat_copy(struct gkyl_nmat *dest, const struct gkyl_nmat *src) +struct gkyl_nmat *gkyl_nmat_copy(struct gkyl_nmat *dest, const struct gkyl_nmat *src) { - assert( dest->num == src->num && dest->nr == src->nr && dest->nc == src->nc ); + assert(dest->num == src->num && dest->nr == src->nr && dest->nc == src->nc); bool dest_is_cu_dev = gkyl_nmat_is_cu_dev(dest); bool src_is_cu_dev = gkyl_nmat_is_cu_dev(src); - size_t nby = src->num*src->nr*src->nc*sizeof(double); + size_t nby = src->num * src->nr * src->nc * sizeof(double); if (src_is_cu_dev) { // source is on device - if (dest_is_cu_dev) + if (dest_is_cu_dev) { gkyl_cu_memcpy(dest->data, src->data, nby, GKYL_CU_MEMCPY_D2D); - else + } else { gkyl_cu_memcpy(dest->data, src->data, nby, GKYL_CU_MEMCPY_D2H); - } - else { + } + } else { // source is on host - if (dest_is_cu_dev) + if (dest_is_cu_dev) { gkyl_cu_memcpy(dest->data, src->data, nby, GKYL_CU_MEMCPY_H2D); - else + } else { memcpy(dest->data, src->data, nby); + } } - + return dest; } -bool -gkyl_mat_is_cu_dev(const struct gkyl_mat *mat) +bool gkyl_mat_is_cu_dev(const struct gkyl_mat *mat) { return GKYL_IS_CU_ALLOC(mat->flags); } -struct gkyl_mat* -gkyl_mat_copy(struct gkyl_mat *dest, const struct gkyl_mat *src) +struct gkyl_mat *gkyl_mat_copy(struct gkyl_mat *dest, const struct gkyl_mat *src) { - assert( dest->nr == src->nr && dest->nc == src->nc ); + assert(dest->nr == src->nr && dest->nc == src->nc); bool dest_is_cu_dev = gkyl_mat_is_cu_dev(dest); bool src_is_cu_dev = gkyl_mat_is_cu_dev(src); - size_t nby = src->nr*src->nc*sizeof(double); + size_t nby = src->nr * src->nc * sizeof(double); if (src_is_cu_dev) { // source is on device - if (dest_is_cu_dev) + if (dest_is_cu_dev) { gkyl_cu_memcpy(dest->data, src->data, nby, GKYL_CU_MEMCPY_D2D); - else + } else { gkyl_cu_memcpy(dest->data, src->data, nby, GKYL_CU_MEMCPY_D2H); - } - else { + } + } else { // source is on host - if (dest_is_cu_dev) + if (dest_is_cu_dev) { gkyl_cu_memcpy(dest->data, src->data, nby, GKYL_CU_MEMCPY_H2D); - else + } else { memcpy(dest->data, src->data, nby); + } } return dest; } -bool -gkyl_nmat_is_cu_dev(const struct gkyl_nmat *mat) +bool gkyl_nmat_is_cu_dev(const struct gkyl_nmat *mat) { return GKYL_IS_CU_ALLOC(mat->flags); } -struct gkyl_nmat* -gkyl_nmat_acquire(const struct gkyl_nmat *mat) +struct gkyl_nmat *gkyl_nmat_acquire(const struct gkyl_nmat *mat) { gkyl_ref_count_inc(&mat->ref_count); - return (struct gkyl_nmat*) mat; + return (struct gkyl_nmat *)mat; } -gkyl_nmat_mem* -gkyl_nmat_linsolve_lu_new(size_t num, size_t nrow) +gkyl_nmat_mem *gkyl_nmat_linsolve_lu_new(size_t num, size_t nrow) { gkyl_nmat_mem *mem = gkyl_malloc(sizeof(*mem)); mem->on_gpu = false; mem->num = num; mem->nrows = nrow; - + mem->ipiv_ho = gkyl_malloc(sizeof(long[nrow])); #ifdef GKYL_HAVE_CUDA mem->cuh = 0; -#endif +#endif return mem; } -gkyl_nmat_mem * -gkyl_nmat_linsolve_lu_cu_dev_new(size_t num, size_t nrow) +gkyl_nmat_mem *gkyl_nmat_linsolve_lu_cu_dev_new(size_t num, size_t nrow) { gkyl_nmat_mem *mem = gkyl_malloc(sizeof(*mem)); mem->on_gpu = true; mem->num = num; mem->nrows = nrow; - - mem->ipiv_cu = gkyl_cu_malloc(num*nrow*sizeof(int)); - mem->infos_cu = gkyl_cu_malloc(num*sizeof(int)); - mem->infos_ho = gkyl_malloc(num*sizeof(int)); + + mem->ipiv_cu = gkyl_cu_malloc(num * nrow * sizeof(int)); + mem->infos_cu = gkyl_cu_malloc(num * sizeof(int)); + mem->infos_ho = gkyl_malloc(num * sizeof(int)); #ifdef GKYL_HAVE_CUDA mem->cuh = 0; @@ -431,8 +403,7 @@ gkyl_nmat_linsolve_lu_cu_dev_new(size_t num, size_t nrow) return mem; } -void -gkyl_nmat_linsolve_lu_release(gkyl_nmat_mem *mem) +void gkyl_nmat_linsolve_lu_release(gkyl_nmat_mem *mem) { if (mem->on_gpu) { gkyl_cu_free(mem->ipiv_cu); @@ -441,17 +412,17 @@ gkyl_nmat_linsolve_lu_release(gkyl_nmat_mem *mem) #ifdef GKYL_HAVE_CUDA cublasDestroy(mem->cuh); #endif - } - else { + } else { gkyl_free(mem->ipiv_ho); } - + gkyl_free(mem); } -gkyl_mat_mm_array_mem * -gkyl_mat_mm_array_mem_new(int nr, int nc, double alpha, double beta, - enum gkyl_mat_trans transa, enum gkyl_mat_trans transb, bool use_gpu) +gkyl_mat_mm_array_mem *gkyl_mat_mm_array_mem_new( + int nr, int nc, double alpha, double beta, enum gkyl_mat_trans transa, enum gkyl_mat_trans transb, + bool use_gpu +) { gkyl_mat_mm_array_mem *mem = gkyl_malloc(sizeof(*mem)); @@ -460,14 +431,14 @@ gkyl_mat_mm_array_mem_new(int nr, int nc, double alpha, double beta, mem->beta = beta; mem->transa = transa; mem->transb = transb; - if (use_gpu){ + if (use_gpu) { mem->A = gkyl_mat_cu_dev_new(nr, nc); } else { mem->A = gkyl_mat_new(nr, nc, 0.0); } #ifdef GKYL_HAVE_CUDA - if(mem->on_gpu){ + if (mem->on_gpu) { mem->cuh = 0; cublasCreate_v2(&mem->cuh); } @@ -476,33 +447,35 @@ gkyl_mat_mm_array_mem_new(int nr, int nc, double alpha, double beta, return mem; } -void -gkyl_mat_mm_array_mem_release(gkyl_mat_mm_array_mem *mem) +void gkyl_mat_mm_array_mem_release(gkyl_mat_mm_array_mem *mem) { gkyl_mat_release(mem->A); #ifdef GKYL_HAVE_CUDA - if(mem->on_gpu) + if (mem->on_gpu) { cublasDestroy(mem->cuh); + } #endif gkyl_free(mem); } -void -ho_nmat_mm(double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_nmat *A, - enum gkyl_mat_trans transb, struct gkyl_nmat *B, struct gkyl_nmat *C) +void ho_nmat_mm( + double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_nmat *A, + enum gkyl_mat_trans transb, struct gkyl_nmat *B, struct gkyl_nmat *C +) { size_t num = A->num; - for (size_t i=0; inr : k; size_t ldb = transb == GKYL_NO_TRANS ? k : C->nc; size_t ldc = C->nr; - assert( (sza.nr == szc.nr) && (sza.nc == k) && (szb.nr == k) && (szb.nc == szc.nc) ); + assert((sza.nr == szc.nr) && (sza.nc == k) && (szb.nr == k) && (szb.nc == szc.nc)); // Now do the strided batched multiply cublasStatus_t info; - info = cublasDgemmStridedBatched(cuh, transa, transb, C->nr, C->nc, k, &alpha, A->data, lda, sza.nr*sza.nc, - B->data, ldb, szb.nr*szb.nc, &beta, C->data, ldc, szc.nr*szc.nc, A->num); + info = cublasDgemmStridedBatched( + cuh, transa, transb, C->nr, C->nc, k, &alpha, A->data, lda, sza.nr * sza.nc, B->data, ldb, + szb.nr * szb.nc, &beta, C->data, ldc, szc.nr * szc.nc, A->num + ); cublasDestroy(cuh); #endif } -void -gkyl_nmat_mm(double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_nmat *A, - enum gkyl_mat_trans transb, struct gkyl_nmat *B, struct gkyl_nmat *C) +void gkyl_nmat_mm( + double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_nmat *A, + enum gkyl_mat_trans transb, struct gkyl_nmat *B, struct gkyl_nmat *C +) { - if (gkyl_nmat_is_cu_dev(A) && gkyl_nmat_is_cu_dev(B) && gkyl_nmat_is_cu_dev(C)) { cu_nmat_mm(alpha, beta, transa, A, transb, B, C); return; @@ -544,23 +519,24 @@ gkyl_nmat_mm(double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_ ho_nmat_mm(alpha, beta, transa, A, transb, B, C); } -void -ho_nmat_mv(double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_nmat *A, - struct gkyl_nmat *x, struct gkyl_nmat *y) +void ho_nmat_mv( + double alpha, double beta, enum gkyl_mat_trans transa, struct gkyl_nmat *A, struct gkyl_nmat *x, + struct gkyl_nmat *y +) { size_t num = A->num; - for (size_t i=0; inum; - assert( num <= x->num ); + assert(num <= x->num); assert(mem->on_gpu == false); assert(mem->num == A->num); assert(mem->nrows == A->nr); bool status = true; - for (size_t i=0; iipiv_ho ); - if (!status) break; + for (size_t i = 0; i < num; ++i) { + struct gkyl_mat Ai = gkyl_nmat_get(A, i); + struct gkyl_mat xi = gkyl_nmat_get(x, i); + status = gkyl_mat_linsolve_lu(&Ai, &xi, mem->ipiv_ho); + if (!status) { + break; + } } return status; } -static bool -cu_nmat_linsolve_lu(gkyl_nmat_mem *mem, struct gkyl_nmat *A, struct gkyl_nmat *x) +static bool cu_nmat_linsolve_lu(gkyl_nmat_mem *mem, struct gkyl_nmat *A, struct gkyl_nmat *x) { #ifdef GKYL_HAVE_CUDA assert(mem->on_gpu); assert(mem->num == A->num); assert(mem->nrows == A->nr); - + bool status = true; size_t num = A->num, nr = A->nr, nrhs = x->nc; size_t lda = nr, ldb = nr; - cublasStatus_t cu_stat; - + cublasStatus_t cu_stat; + int *ipiv = mem->ipiv_cu; int *infos = mem->infos_cu; int *infos_h = mem->infos_ho; @@ -619,14 +594,15 @@ cu_nmat_linsolve_lu(gkyl_nmat_mem *mem, struct gkyl_nmat *A, struct gkyl_nmat *x status = false; goto cleanup; } - + // copy info back to host and check if there were any errors - gkyl_cu_memcpy(infos_h, infos, num*sizeof(int), GKYL_CU_MEMCPY_D2H); - for (size_t i=0; icuh, CUBLAS_OP_N, nr, nrhs, (const double*const*) A->mptr, - lda, ipiv, x->mptr, ldb, &info, num); + cublasDgetrsBatched( + mem->cuh, CUBLAS_OP_N, nr, nrhs, (const double *const *)A->mptr, lda, ipiv, x->mptr, ldb, &info, + num + ); if (info != 0) { status = false; goto cleanup; } - cleanup: +cleanup: return status; -#else +#else return false; -#endif +#endif } #ifdef GKYL_HAVE_CUDA -void -cu_mat_mm_array(struct gkyl_mat_mm_array_mem *mem, const struct gkyl_array *B, struct gkyl_array *C, cublasStatus_t info) +void cu_mat_mm_array( + struct gkyl_mat_mm_array_mem *mem, const struct gkyl_array *B, struct gkyl_array *C, + cublasStatus_t info +) { - double alpha = mem->alpha; - double beta = mem->beta; + double alpha = mem->alpha; + double beta = mem->beta; enum gkyl_mat_trans transa = mem->transa; struct gkyl_mat *A = mem->A; enum gkyl_mat_trans transb = mem->transb; - struct mat_sizes sza = get_mat_sizes(transa, A); + struct mat_sizes sza = get_mat_sizes(transa, A); size_t k = sza.nc; size_t lda = transa == GKYL_NO_TRANS ? C->ncomp : k; size_t ldb = transb == GKYL_NO_TRANS ? k : C->size; size_t ldc = C->ncomp; // Do the cublas gemm - info = cublasDgemm(mem->cuh, transa, transb, A->nr, B->size, A->nc, &alpha, A->data, lda, B->data, ldb, &beta, C->data, ldc); + info = cublasDgemm( + mem->cuh, transa, transb, A->nr, B->size, A->nc, &alpha, A->data, lda, B->data, ldb, &beta, + C->data, ldc + ); } #endif - -void -ho_mat_mm_array(struct gkyl_mat_mm_array_mem *mem, const struct gkyl_array *B, struct gkyl_array *C) +void ho_mat_mm_array( + struct gkyl_mat_mm_array_mem *mem, const struct gkyl_array *B, struct gkyl_array *C +) { double alpha = mem->alpha; - double beta = mem->beta; + double beta = mem->beta; enum gkyl_mat_trans transa = mem->transa; struct gkyl_mat *A = mem->A; enum gkyl_mat_trans transb = mem->transb; - struct mat_sizes sza = get_mat_sizes(transa, A); + struct mat_sizes sza = get_mat_sizes(transa, A); size_t k = sza.nc; size_t lda = transa == GKYL_NO_TRANS ? C->ncomp : k; size_t ldb = transb == GKYL_NO_TRANS ? k : C->size; size_t ldc = C->ncomp; - assert( (sza.nr == C->ncomp) && (B->ncomp == k) && (B->size == C->size) ); + assert((sza.nr == C->ncomp) && (B->ncomp == k) && (B->size == C->size)); // For CPU side calculations - // call BLAS routine to perform matrix-matrix multiply + // call BLAS routine to perform matrix-matrix multiply // (specifically for CPU, with gkyl_array B/C) - cblas_dgemm(CblasColMajor, cblas_trans_flags[transa], cblas_trans_flags[transb], A->nr, B->size, A->nc, - alpha, A->data, lda, B->data, ldb, beta, C->data, ldc); + cblas_dgemm( + CblasColMajor, cblas_trans_flags[transa], cblas_trans_flags[transb], A->nr, B->size, A->nc, + alpha, A->data, lda, B->data, ldb, beta, C->data, ldc + ); } - -void -gkyl_mat_mm_array(struct gkyl_mat_mm_array_mem *mem, const struct gkyl_array *B, struct gkyl_array *C) +void gkyl_mat_mm_array( + struct gkyl_mat_mm_array_mem *mem, const struct gkyl_array *B, struct gkyl_array *C +) { #ifdef GKYL_HAVE_CUDA // Now do the matrix multiply using either the cublas or lapack funcs. cublasStatus_t info; - if(mem->on_gpu){ + if (mem->on_gpu) { cu_mat_mm_array(mem, B, C, info); return; } @@ -710,62 +695,61 @@ gkyl_mat_mm_array(struct gkyl_mat_mm_array_mem *mem, const struct gkyl_array *B, ho_mat_mm_array(mem, B, C); } - -bool -gkyl_nmat_linsolve_lu(struct gkyl_nmat *A, struct gkyl_nmat *x) +bool gkyl_nmat_linsolve_lu(struct gkyl_nmat *A, struct gkyl_nmat *x) { bool status = false; - + if (!gkyl_nmat_is_cu_dev(A) && !gkyl_nmat_is_cu_dev(x)) { gkyl_nmat_mem *mem = gkyl_nmat_linsolve_lu_new(A->num, A->nr); status = ho_nmat_linsolve_lu(mem, A, x); gkyl_nmat_linsolve_lu_release(mem); } - + if (gkyl_nmat_is_cu_dev(A) && gkyl_nmat_is_cu_dev(x)) { gkyl_nmat_mem *mem = gkyl_nmat_linsolve_lu_cu_dev_new(A->num, A->nr); status = cu_nmat_linsolve_lu(mem, A, x); gkyl_nmat_linsolve_lu_release(mem); } - + return status; } -bool -gkyl_nmat_linsolve_lu_pa(gkyl_nmat_mem *mem, struct gkyl_nmat *A, struct gkyl_nmat *x) +bool gkyl_nmat_linsolve_lu_pa(gkyl_nmat_mem *mem, struct gkyl_nmat *A, struct gkyl_nmat *x) { bool status = false; - - if (!gkyl_nmat_is_cu_dev(A) && !gkyl_nmat_is_cu_dev(x)) + + if (!gkyl_nmat_is_cu_dev(A) && !gkyl_nmat_is_cu_dev(x)) { status = ho_nmat_linsolve_lu(mem, A, x); - - if (gkyl_nmat_is_cu_dev(A) && gkyl_nmat_is_cu_dev(x)) + } + + if (gkyl_nmat_is_cu_dev(A) && gkyl_nmat_is_cu_dev(x)) { status = cu_nmat_linsolve_lu(mem, A, x); - - return status; + } + + return status; } -void -gkyl_nmat_release(struct gkyl_nmat *mat) +void gkyl_nmat_release(struct gkyl_nmat *mat) { - if (mat) + if (mat) { gkyl_ref_count_dec(&mat->ref_count); + } } // CUDA specific code #ifdef GKYL_HAVE_CUDA -struct gkyl_mat* -gkyl_mat_cu_dev_new(size_t nr, size_t nc) +struct gkyl_mat *gkyl_mat_cu_dev_new(size_t nr, size_t nc) { struct gkyl_mat *mat = gkyl_malloc(sizeof(struct gkyl_mat)); - mat->nr = nr; mat->nc = nc; + mat->nr = nr; + mat->nc = nc; mat->flags = 0; GKYL_SET_CU_ALLOC(mat->flags); - mat->data = gkyl_cu_malloc(sizeof(double[nr*nc])); + mat->data = gkyl_cu_malloc(sizeof(double[nr * nc])); mat->ref_count = gkyl_ref_count_init(mat_free); // create a clone of struct mat->on_dev that lives on device, so @@ -773,62 +757,61 @@ gkyl_mat_cu_dev_new(size_t nr, size_t nc) // kernel mat->on_dev = gkyl_cu_malloc(sizeof(struct gkyl_mat)); gkyl_cu_memcpy(mat->on_dev, mat, sizeof(struct gkyl_mat), GKYL_CU_MEMCPY_H2D); - - // set device-side data pointer in mat->on_dev to mat->data + + // set device-side data pointer in mat->on_dev to mat->data // (which is the host-side pointer to the device data) - gkyl_cu_memcpy(&((mat->on_dev)->data), &mat->data, sizeof(double*), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(&((mat->on_dev)->data), &mat->data, sizeof(double *), GKYL_CU_MEMCPY_H2D); return mat; } -struct gkyl_nmat* -gkyl_nmat_cu_dev_new(size_t num, size_t nr, size_t nc) +struct gkyl_nmat *gkyl_nmat_cu_dev_new(size_t num, size_t nr, size_t nc) { struct gkyl_nmat *mat = gkyl_malloc(sizeof(struct gkyl_nmat)); - mat->num = num; mat->nr = nr; mat->nc = nc; + mat->num = num; + mat->nr = nr; + mat->nc = nc; mat->flags = 0; GKYL_SET_CU_ALLOC(mat->flags); - mat->data = gkyl_cu_malloc(sizeof(double[num*nr*nc])); - mat->mptr = gkyl_cu_malloc(num*sizeof(double*)); + mat->data = gkyl_cu_malloc(sizeof(double[num * nr * nc])); + mat->mptr = gkyl_cu_malloc(num * sizeof(double *)); mat->ref_count = gkyl_ref_count_init(nmat_free); - double **mptr_h = gkyl_malloc(num*sizeof(double*)); + double **mptr_h = gkyl_malloc(num * sizeof(double *)); // create pointers to various matrices and copy to device - for (size_t i=0; idata+nr*nc*i; - gkyl_cu_memcpy(mat->mptr, mptr_h, num*sizeof(double*), GKYL_CU_MEMCPY_H2D); - gkyl_free(mptr_h); + for (size_t i = 0; i < num; ++i) { + mptr_h[i] = mat->data + nr * nc * i; + } + gkyl_cu_memcpy(mat->mptr, mptr_h, num * sizeof(double *), GKYL_CU_MEMCPY_H2D); + gkyl_free(mptr_h); // create a clone of struct mat->on_dev that lives on device, so // that the whole mat->on_dev struct can be passed to a device // kernel mat->on_dev = gkyl_cu_malloc(sizeof(struct gkyl_nmat)); gkyl_cu_memcpy(mat->on_dev, mat, sizeof(struct gkyl_nmat), GKYL_CU_MEMCPY_H2D); - - // set device-side data pointer in mat->on_dev to mat->data + + // set device-side data pointer in mat->on_dev to mat->data // (which is the host-side pointer to the device data) - gkyl_cu_memcpy(&((mat->on_dev)->data), &mat->data, sizeof(double*), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(&((mat->on_dev)->data), &mat->data, sizeof(double *), GKYL_CU_MEMCPY_H2D); - // set device-side mptr pointer in mat->on_dev to mat->mptr + // set device-side mptr pointer in mat->on_dev to mat->mptr // (which is the host-side pointer to the device mptr) - gkyl_cu_memcpy(&((mat->on_dev)->mptr), &mat->mptr, sizeof(double**), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(&((mat->on_dev)->mptr), &mat->mptr, sizeof(double **), GKYL_CU_MEMCPY_H2D); return mat; } - #else -struct gkyl_mat* -gkyl_mat_cu_dev_new(size_t nr, size_t nc) +struct gkyl_mat *gkyl_mat_cu_dev_new(size_t nr, size_t nc) { assert(false); return 0; } -struct gkyl_nmat* -gkyl_nmat_cu_dev_new(size_t num, size_t nr, size_t nc) +struct gkyl_nmat *gkyl_nmat_cu_dev_new(size_t num, size_t nr, size_t nc) { assert(false); return 0; diff --git a/core/zero/mat_triples.c b/core/zero/mat_triples.c index bc520b743f..b612769f96 100644 --- a/core/zero/mat_triples.c +++ b/core/zero/mat_triples.c @@ -3,29 +3,27 @@ #include // Index into matrix -struct mat_idx { size_t row, col; }; +struct mat_idx { + size_t row, col; +}; -static inline int -cmp_long(long a, long b) +static inline int cmp_long(long a, long b) { - return a==b ? 0 : arow, mib->row) == 0 ? cmp_long(mia->col, mib->col) : - cmp_long(mia->row, mib->row); + cmp_long(mia->row, mib->row); } -static inline int -mat_idx_cmp_col(const struct mat_idx *mia, const struct mat_idx *mib) +static inline int mat_idx_cmp_col(const struct mat_idx *mia, const struct mat_idx *mib) { return cmp_long(mia->col, mib->col) == 0 ? cmp_long(mia->row, mib->row) : - cmp_long(mia->col, mib->col); + cmp_long(mia->col, mib->col); } // define map of mat_idx -> gkyl_mtriple: this is a sorted map, in @@ -50,12 +48,11 @@ struct gkyl_mat_triples_iter { csmap_triple_iter it_curr, it_end; // iterator to start, end of map }; -gkyl_mat_triples* -gkyl_mat_triples_new(size_t nr, size_t nc) +gkyl_mat_triples *gkyl_mat_triples_new(size_t nr, size_t nc) { struct gkyl_mat_triples *tri = gkyl_malloc(sizeof(struct gkyl_mat_triples)); - gkyl_range_init_from_shape(&tri->range, 2, (const int[]) { nr, nc} ); + gkyl_range_init_from_shape(&tri->range, 2, (const int[]){nr, nc}); // set column-major order by default tri->ordering = COLMAJOR; @@ -74,98 +71,94 @@ void gkyl_mat_triples_set_colmaj_order(gkyl_mat_triples *tri) tri->ordering = COLMAJOR; } -bool gkyl_mat_triples_is_rowmaj(gkyl_mat_triples *tri) { +bool gkyl_mat_triples_is_rowmaj(gkyl_mat_triples *tri) +{ return tri->ordering == ROWMAJOR; } -bool gkyl_mat_triples_is_colmaj(gkyl_mat_triples *tri) { +bool gkyl_mat_triples_is_colmaj(gkyl_mat_triples *tri) +{ return tri->ordering == COLMAJOR; } -GKYL_CU_DH double -gkyl_mat_triples_insert(gkyl_mat_triples *tri, size_t i, size_t j, double val) +GKYL_CU_DH double gkyl_mat_triples_insert(gkyl_mat_triples *tri, size_t i, size_t j, double val) { - assert(irange, 0) && jrange, 1)); - if(tri->ordering == COLMAJOR) + assert(i < gkyl_range_shape(&tri->range, 0) && j < gkyl_range_shape(&tri->range, 1)); + if (tri->ordering == COLMAJOR) { mat_idx_cmp = mat_idx_cmp_col; - else + } else { mat_idx_cmp = mat_idx_cmp_row; - + } + long loc = gkyl_ridx(tri->range, i, j); - csmap_triple_put(&tri->triples, (struct mat_idx) { .row = i, .col = j }, - (struct gkyl_mtriple) { .row = i, .col = j, .val = val } + csmap_triple_put( + &tri->triples, (struct mat_idx){.row = i, .col = j}, + (struct gkyl_mtriple){.row = i, .col = j, .val = val} ); return val; } -GKYL_CU_DH double -gkyl_mat_triples_accum(gkyl_mat_triples *tri, size_t i, size_t j, double val) +GKYL_CU_DH double gkyl_mat_triples_accum(gkyl_mat_triples *tri, size_t i, size_t j, double val) { - assert(irange, 0) && jrange, 1)); - if(tri->ordering == COLMAJOR) + assert(i < gkyl_range_shape(&tri->range, 0) && j < gkyl_range_shape(&tri->range, 1)); + if (tri->ordering == COLMAJOR) { mat_idx_cmp = mat_idx_cmp_col; - else + } else { mat_idx_cmp = mat_idx_cmp_row; - + } + long loc = gkyl_ridx(tri->range, i, j); - struct csmap_triple_value *mt = csmap_triple_get_mut(&tri->triples, - (struct mat_idx) { .row = i, .col = j } - ); + struct csmap_triple_value *mt = + csmap_triple_get_mut(&tri->triples, (struct mat_idx){.row = i, .col = j}); double tot_val = val; if (mt) { // element exists, add to its current value tot_val = (mt->second.val += val); - } - else { - csmap_triple_put(&tri->triples, (struct mat_idx) { .row = i, .col = j }, - (struct gkyl_mtriple) { .row = i, .col = j, .val = val } + } else { + csmap_triple_put( + &tri->triples, (struct mat_idx){.row = i, .col = j}, + (struct gkyl_mtriple){.row = i, .col = j, .val = val} ); } - + return tot_val; } -double -gkyl_mat_triples_get(const gkyl_mat_triples *tri, size_t i, size_t j) +double gkyl_mat_triples_get(const gkyl_mat_triples *tri, size_t i, size_t j) { long loc = gkyl_ridx(tri->range, i, j); - const struct csmap_triple_value *mt = csmap_triple_get(&tri->triples, - (struct mat_idx) { .row = i, .col = j } - ); + const struct csmap_triple_value *mt = + csmap_triple_get(&tri->triples, (struct mat_idx){.row = i, .col = j}); return mt ? mt->second.val : 0.0; } -size_t -gkyl_mat_triples_size(const gkyl_mat_triples *tri) +size_t gkyl_mat_triples_size(const gkyl_mat_triples *tri) { return csmap_triple_size(tri->triples); } -gkyl_mat_triples_iter* -gkyl_mat_triples_iter_new(const gkyl_mat_triples *tri) +gkyl_mat_triples_iter *gkyl_mat_triples_iter_new(const gkyl_mat_triples *tri) { struct gkyl_mat_triples_iter *iter = gkyl_malloc(sizeof(*iter)); iter->parent = &tri->triples; - + iter->is_first = true; iter->nrem = csmap_triple_size(tri->triples); iter->it_curr = csmap_triple_begin(&tri->triples); iter->it_end = csmap_triple_end(&tri->triples); - + return iter; } -void -gkyl_mat_triples_iter_init(struct gkyl_mat_triples_iter *iter, const gkyl_mat_triples *tri) +void gkyl_mat_triples_iter_init(struct gkyl_mat_triples_iter *iter, const gkyl_mat_triples *tri) { iter->is_first = true; iter->nrem = csmap_triple_size(tri->triples); iter->it_curr = csmap_triple_begin(&tri->triples); } -bool -gkyl_mat_triples_iter_next(gkyl_mat_triples_iter *iter) +bool gkyl_mat_triples_iter_next(gkyl_mat_triples_iter *iter) { if (iter->is_first) { iter->is_first = false; @@ -178,34 +171,30 @@ gkyl_mat_triples_iter_next(gkyl_mat_triples_iter *iter) return false; } -struct gkyl_mtriple -gkyl_mat_triples_iter_at(const gkyl_mat_triples_iter *iter) +struct gkyl_mtriple gkyl_mat_triples_iter_at(const gkyl_mat_triples_iter *iter) { return iter->it_curr.ref->second; } -void -gkyl_mat_triples_clear(struct gkyl_mat_triples *tri, double val) +void gkyl_mat_triples_clear(struct gkyl_mat_triples *tri, double val) { gkyl_mat_triples_iter *iter = gkyl_mat_triples_iter_new(tri); while (gkyl_mat_triples_iter_next(iter)) { struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); - struct csmap_triple_value *mtm = csmap_triple_get_mut(&tri->triples, - (struct mat_idx) { .row = mt.row, .col = mt.col }); + struct csmap_triple_value *mtm = + csmap_triple_get_mut(&tri->triples, (struct mat_idx){.row = mt.row, .col = mt.col}); mtm->second.val = val; } gkyl_mat_triples_iter_release(iter); } -void -gkyl_mat_triples_iter_release(gkyl_mat_triples_iter *iter) +void gkyl_mat_triples_iter_release(gkyl_mat_triples_iter *iter) { gkyl_free(iter); } -void -gkyl_mat_triples_release(gkyl_mat_triples *tri) +void gkyl_mat_triples_release(gkyl_mat_triples *tri) { csmap_triple_drop(&tri->triples); gkyl_free(tri); diff --git a/core/zero/math.c b/core/zero/math.c index 2e94c8427d..f3b51b2132 100644 --- a/core/zero/math.c +++ b/core/zero/math.c @@ -19,152 +19,145 @@ static double ROOT_EPS = 1e-14; // implementation in Appendix B of the note. struct gkyl_qr_res -gkyl_dbl_exp(double (*func)(double, void *), void *ctx, - double a, double b, int n, double eps) +gkyl_dbl_exp(double (*func)(double, void *), void *ctx, double a, double b, int n, double eps) { - int nev = 0; - double thr = 10*sqrt(eps); // too generous for larger eps, e.g. eps=1e-9 + int nev = 0; + double thr = 10 * sqrt(eps); // too generous for larger eps, e.g. eps=1e-9 //double thr = eps; // too generous for larger eps, e.g. eps=1e-9 - double c = (a+b)/2; // center (mean) - double d = (b-a)/2; // half distance - double s = func(c, ctx); nev += 1; + double c = (a + b) / 2; // center (mean) + double d = (b - a) / 2; // half distance + double s = func(c, ctx); + nev += 1; double fp = 0, fm = 0; double p, e, v, h = 2; - double tmax = log(2/M_PI * log((d < 1 ? 2*d : 2) / eps)); + double tmax = log(2 / M_PI * log((d < 1 ? 2 * d : 2) / eps)); int k = 0; // level do { double q, t; int j = 1; - v = s*d*M_PI/2*h; // last sum + v = s * d * M_PI / 2 * h; // last sum p = 0; h /= 2; t = h; do { double ch = cosh(t); - double ecs = cosh(M_PI/2 * sqrt(ch*ch - 1)); // = cosh(pi/2*sinh(t)) - double w = 1/(ecs*ecs); - double r = sqrt(ecs*ecs - 1)/ecs; - double x = d*r; - if (c+x > a) { - double y = func(c+x, ctx); nev += 1; - if (isfinite(y)) + double ecs = cosh(M_PI / 2 * sqrt(ch * ch - 1)); // = cosh(pi/2*sinh(t)) + double w = 1 / (ecs * ecs); + double r = sqrt(ecs * ecs - 1) / ecs; + double x = d * r; + if (c + x > a) { + double y = func(c + x, ctx); + nev += 1; + if (isfinite(y)) { fp = y; + } } - if (c-x < b) { - double y = func(c-x, ctx); nev += 1; - if (isfinite(y)) + if (c - x < b) { + double y = func(c - x, ctx); + nev += 1; + if (isfinite(y)) { fm = y; + } } - q = ch*w*(fp+fm); + q = ch * w * (fp + fm); p += q; - j += 1+(k>0); - t = j*h; - } while (t <= tmax && fabs(q) > eps*fabs(p)); + j += 1 + (k > 0); + t = j * h; + } while (t <= tmax && fabs(q) > eps * fabs(p)); s += p; ++k; - } while (s && fabs(2*fabs(p) - fabs(s)) >= fabs(thr*s) && k <= n); - s *= d*M_PI/2*h; - e = fabs(v-s); - if (10*e >= fabs(s)) { + } while (s && fabs(2 * fabs(p) - fabs(s)) >= fabs(thr * s) && k <= n); + s *= d * M_PI / 2 * h; + e = fabs(v - s); + if (10 * e >= fabs(s)) { e += fabs(s); s = 0; } - - return (struct gkyl_qr_res) { - .error = e, - .res = s, - .nevals = nev, - .status = k>n ? 1 : 0, - .nlevels = k - }; + + return (struct gkyl_qr_res + ){.error = e, .res = s, .nevals = nev, .status = k > n ? 1 : 0, .nlevels = k}; } // Helper functions for ridders -static inline double dsign(double x) { return x >= 0 ? 1 : -1; } +static inline double dsign(double x) +{ + return x >= 0 ? 1 : -1; +} // See IEEE Tran. Circuit and Systems, vol CAS-26 No 11, Pg 976 // 1976. The following is almost direct implementation from the // original paper -struct gkyl_qr_res -gkyl_ridders(double (*func)(double,void*), void *ctx, - double xl, double xr, double fl, double fr, int max_iter, double eps) +struct gkyl_qr_res gkyl_ridders( + double (*func)(double, void *), void *ctx, double xl, double xr, double fl, double fr, + int max_iter, double eps +) { double x0 = xl, x2 = xr, f0 = fl, f2 = fr; double res = DBL_MAX, err = DBL_MAX; int nev = 0, nitr = 0, iterating = 1; while (iterating && nitr <= max_iter) { - double x1 = 0.5*(x0+x2); - double f1 = func(x1, ctx); nev += 1; - double W = f1*f1 - f0*f2; - - double d = x2-x1; - double x3 = x1 + dsign(f0)*f1*d/sqrt(W); - double f3 = func(x3, ctx); nev += 1; - - if (fabs(res-x3) < eps) { - err = fabs(res-x3); + double x1 = 0.5 * (x0 + x2); + double f1 = func(x1, ctx); + nev += 1; + double W = f1 * f1 - f0 * f2; + + double d = x2 - x1; + double x3 = x1 + dsign(f0) * f1 * d / sqrt(W); + double f3 = func(x3, ctx); + nev += 1; + + if (fabs(res - x3) < eps) { + err = fabs(res - x3); iterating = 0; } res = x3; - if (f3*f0 < 0) { + if (f3 * f0 < 0) { x2 = x3; f2 = f3; - } - else if (f3*f1 < 0) { + } else if (f3 * f1 < 0) { x0 = x1 < x3 ? x1 : x3; f0 = x1 < x3 ? f1 : f3; x2 = x1 < x3 ? x3 : x1; f2 = x1 < x3 ? f3 : f1; - } - else if (f3*f2 < 0 ) { + } else if (f3 * f2 < 0) { x0 = x3; f0 = f3; } nitr++; } - - return (struct gkyl_qr_res) { - .error = err, - .res = res, - .nevals = nev, - .status = nitr>max_iter ? 1 : 0, - }; + + return (struct gkyl_qr_res + ){.error = err, .res = res, .nevals = nev, .status = nitr > max_iter ? 1 : 0}; } /////// roots of a quadratic polynomial -static struct gkyl_lo_poly_roots -quad_poly_roots(double coeff[4]) +static struct gkyl_lo_poly_roots quad_poly_roots(double coeff[4]) { double c = coeff[0], b = coeff[1], a = 1.0; double complex x1 = 0.0, x2 = 0.0; - if (b>=0.0) { - x1 = (-b-csqrt(b*b-4*a*c))/(2*a); - x2 = 2*c/(-b-csqrt(b*b-4*a*c)); - } - else { - x1 = 2*c/(-b+csqrt(b*b-4*a*c)); - x2 = (-b+csqrt(b*b-4*a*c))/(2*a); + if (b >= 0.0) { + x1 = (-b - csqrt(b * b - 4 * a * c)) / (2 * a); + x2 = 2 * c / (-b - csqrt(b * b - 4 * a * c)); + } else { + x1 = 2 * c / (-b + csqrt(b * b - 4 * a * c)); + x2 = (-b + csqrt(b * b - 4 * a * c)) / (2 * a); } - - return (struct gkyl_lo_poly_roots) { - .niter = 0, - .err = { 0.0, 0.0 }, - .rpart = { creal(x1), creal(x2) }, - .impart = { cimag(x1), cimag(x2) } + + return (struct gkyl_lo_poly_roots + ){.niter = 0, .err = {0.0, 0.0}, .rpart = {creal(x1), creal(x2)}, .impart = {cimag(x1), cimag(x2)} }; } /////// roots of a cubic -static inline double complex -eval_poly3(const double coeff[4], double complex x) +static inline double complex eval_poly3(const double coeff[4], double complex x) { - double complex x2 = x*x; - double complex x3 = x2*x; - return coeff[0] + coeff[1]*x + coeff[2]*x2 + x3; + double complex x2 = x * x; + double complex x3 = x2 * x; + return coeff[0] + coeff[1] * x + coeff[2] * x2 + x3; } static inline bool @@ -174,211 +167,197 @@ check_converged3(double complex c1, double complex c2, double complex c3, double err[0] = cabs(c1); err[1] = cabs(c2); err[2] = cabs(c3); - - return (err[0]+err[1]+err[2])/3.0 < eps; + + return (err[0] + err[1] + err[2]) / 3.0 < eps; } // roots of a cubic polynomial (Durand-Kerner method) -static struct gkyl_lo_poly_roots -cubic_poly_roots(double coeff[4]) +static struct gkyl_lo_poly_roots cubic_poly_roots(double coeff[4]) { - double complex r1 = 0.4+0.9*I; // arbitrary complex number, not a root of unity + double complex r1 = 0.4 + 0.9 * I; // arbitrary complex number, not a root of unity double complex pn1 = r1; - double complex qn1 = pn1*r1; - double complex rn1 = qn1*r1; + double complex qn1 = pn1 * r1; + double complex rn1 = qn1 * r1; double complex pn = 0.0, qn = 0.0, rn = 0.0; - double err[3] = { 0.0 }; + double err[3] = {0.0}; int max_iter = 100; int niter = 0; do { - pn = pn1; qn = qn1; rn = rn1; - - pn1 = pn1 - eval_poly3(coeff, pn1)/( (pn1-qn1)*(pn1-rn1) ); - qn1 = qn1 - eval_poly3(coeff, qn1)/( (qn1-pn1)*(qn1-rn1) ); - rn1 = rn1 - eval_poly3(coeff, rn1)/( (rn1-pn1)*(rn1-qn1) ); + pn = pn1; + qn = qn1; + rn = rn1; + + pn1 = pn1 - eval_poly3(coeff, pn1) / ((pn1 - qn1) * (pn1 - rn1)); + qn1 = qn1 - eval_poly3(coeff, qn1) / ((qn1 - pn1) * (qn1 - rn1)); + rn1 = rn1 - eval_poly3(coeff, rn1) / ((rn1 - pn1) * (rn1 - qn1)); niter += 1; - - } while( !check_converged3(pn-pn1, qn-qn1, rn-rn1, err) && niter < max_iter ); - return (struct gkyl_lo_poly_roots) { - .niter = niter, - .err = { err[0], err[1], err[2] }, - .rpart = { creal(pn1), creal(qn1), creal(rn1) }, - .impart = { cimag(pn1), cimag(qn1), cimag(rn1) } - }; + } while (!check_converged3(pn - pn1, qn - qn1, rn - rn1, err) && niter < max_iter); + + return (struct gkyl_lo_poly_roots + ){.niter = niter, + .err = {err[0], err[1], err[2]}, + .rpart = {creal(pn1), creal(qn1), creal(rn1)}, + .impart = {cimag(pn1), cimag(qn1), cimag(rn1)}}; } /////// roots of a quartic -static inline double complex -eval_poly4(const double coeff[4], double complex x) +static inline double complex eval_poly4(const double coeff[4], double complex x) { - double complex x2 = x*x; - double complex x3 = x2*x; - double complex x4 = x2*x2; - return coeff[0] + coeff[1]*x + coeff[2]*x2 + coeff[3]*x3 + x4; + double complex x2 = x * x; + double complex x3 = x2 * x; + double complex x4 = x2 * x2; + return coeff[0] + coeff[1] * x + coeff[2] * x2 + coeff[3] * x3 + x4; } -static inline bool -check_converged4(double complex c1, double complex c2, double complex c3, double complex c4, - double err[4]) +static inline bool check_converged4( + double complex c1, double complex c2, double complex c3, double complex c4, double err[4] +) { double eps = ROOT_EPS; err[0] = cabs(c1); err[1] = cabs(c2); err[2] = cabs(c3); - err[3] = cabs(c4); - - return (err[0]+err[1]+err[2]+err[3])/4.0 < eps; + err[3] = cabs(c4); + + return (err[0] + err[1] + err[2] + err[3]) / 4.0 < eps; } // roots of a quartic polynomial (Durand-Kerner method) -static struct gkyl_lo_poly_roots -quart_poly_roots(double coeff[4]) +static struct gkyl_lo_poly_roots quart_poly_roots(double coeff[4]) { - double complex r1 = 0.4+0.9*I; // arbitrary complex number, not a root of unity + double complex r1 = 0.4 + 0.9 * I; // arbitrary complex number, not a root of unity double complex pn1 = r1; - double complex qn1 = pn1*r1; - double complex rn1 = qn1*r1; - double complex sn1 = rn1*r1; + double complex qn1 = pn1 * r1; + double complex rn1 = qn1 * r1; + double complex sn1 = rn1 * r1; double complex pn = 0.0, qn = 0.0, rn = 0.0, sn = 0.0; - double err[4] = { 0.0 }; + double err[4] = {0.0}; int max_iter = 100; int niter = 0; do { - pn = pn1; qn = qn1; rn = rn1; sn = sn1; - - pn1 = pn1 - eval_poly4(coeff, pn1)/( (pn1-qn1)*(pn1-rn1)*(pn1-sn1) ); - qn1 = qn1 - eval_poly4(coeff, qn1)/( (qn1-pn1)*(qn1-rn1)*(qn1-sn1) ); - rn1 = rn1 - eval_poly4(coeff, rn1)/( (rn1-pn1)*(rn1-qn1)*(rn1-sn1) ); - sn1 = sn1 - eval_poly4(coeff, sn1)/( (sn1-pn1)*(sn1-qn1)*(sn1-rn1) ); + pn = pn1; + qn = qn1; + rn = rn1; + sn = sn1; + + pn1 = pn1 - eval_poly4(coeff, pn1) / ((pn1 - qn1) * (pn1 - rn1) * (pn1 - sn1)); + qn1 = qn1 - eval_poly4(coeff, qn1) / ((qn1 - pn1) * (qn1 - rn1) * (qn1 - sn1)); + rn1 = rn1 - eval_poly4(coeff, rn1) / ((rn1 - pn1) * (rn1 - qn1) * (rn1 - sn1)); + sn1 = sn1 - eval_poly4(coeff, sn1) / ((sn1 - pn1) * (sn1 - qn1) * (sn1 - rn1)); niter += 1; - - } while( !check_converged4(pn-pn1, qn-qn1, rn-rn1, sn-sn1, err) && niter < max_iter ); - return (struct gkyl_lo_poly_roots) { - .niter = niter, - .err = { err[0], err[1], err[2], err[3] }, - .rpart = { creal(pn1), creal(qn1), creal(rn1), creal(sn1) }, - .impart = { cimag(pn1), cimag(qn1), cimag(rn1), cimag(sn1) } - }; + } while (!check_converged4(pn - pn1, qn - qn1, rn - rn1, sn - sn1, err) && niter < max_iter); + + return (struct gkyl_lo_poly_roots + ){.niter = niter, + .err = {err[0], err[1], err[2], err[3]}, + .rpart = {creal(pn1), creal(qn1), creal(rn1), creal(sn1)}, + .impart = {cimag(pn1), cimag(qn1), cimag(rn1), cimag(sn1)}}; } -struct gkyl_lo_poly_roots -gkyl_calc_lo_poly_roots(enum gkyl_lo_poly_order order, double coeff[4]) +struct gkyl_lo_poly_roots gkyl_calc_lo_poly_roots(enum gkyl_lo_poly_order order, double coeff[4]) { - struct gkyl_lo_poly_roots proots = { }; - switch(order) { - case GKYL_LO_POLY_2: - proots = quad_poly_roots(coeff); - break; - case GKYL_LO_POLY_3: - proots = cubic_poly_roots(coeff); - break; - case GKYL_LO_POLY_4: - proots = quart_poly_roots(coeff); - break; + struct gkyl_lo_poly_roots proots = {}; + switch (order) { + case GKYL_LO_POLY_2: + proots = quad_poly_roots(coeff); + break; + case GKYL_LO_POLY_3: + proots = cubic_poly_roots(coeff); + break; + case GKYL_LO_POLY_4: + proots = quart_poly_roots(coeff); + break; } return proots; } -static inline double -eval_poly_lo(double *p, double x) +static inline double eval_poly_lo(double *p, double x) { - // eval_poly_lo() assumes a fourth order quartic form with 1.0*x^4 leading term is 0 //compute the polynomial evaluated at x double res = 0.0; - for (int i=0; i<=3; ++i) { - res = res + p[i]*pow(x,i); + for (int i = 0; i <= 3; ++i) { + res = res + p[i] * pow(x, i); } // return the resulted evalued polynomial return res; } - -static inline double -eval_poly(double x, void *ctx) +static inline double eval_poly(double x, void *ctx) { - // eval_poly() assumes a fourth order quartic form with 1.0*x^4 leading term, // bounds must be finite - double *p = (double*)ctx; + double *p = (double *)ctx; //compute the polynomial evaluated at x double res = 0.0; - for (int i=0; i<=3; ++i) { - res = res + p[i]*pow(x,i); + for (int i = 0; i <= 3; ++i) { + res = res + p[i] * pow(x, i); } - res = res + pow(x,4); + res = res + pow(x, 4); // return the resulted evalued polynomial return res; } - -static inline int -sign_changes(int *signs) +static inline int sign_changes(int *signs) { int res = 0; - for (int i=0; i<=3; ++i) { - if (signs[i]*signs[i+1] < 0.0){ + for (int i = 0; i <= 3; ++i) { + if (signs[i] * signs[i + 1] < 0.0) { res = res + 1; } } return res; } - -static void -signs_strum_chain(double *eval_sturn_chain, int *signs) +static void signs_strum_chain(double *eval_sturn_chain, int *signs) { int iter = 0; - for (int i=0; i<=4; ++i) { + for (int i = 0; i <= 4; ++i) { signs[i] = 0; - if (eval_sturn_chain[i] > 0.0){ + if (eval_sturn_chain[i] > 0.0) { signs[iter] = 1; iter = iter + 1; - } else if (eval_sturn_chain[i] < 0.0){ + } else if (eval_sturn_chain[i] < 0.0) { signs[iter] = -1; iter = iter + 1; } } } - -static void -eval_strum_chain(struct gkyl_sturm_polynomials *sturn_chain, double x, double *eval) +static void eval_strum_chain(struct gkyl_sturm_polynomials *sturn_chain, double x, double *eval) { - eval[0] = eval_poly(x,sturn_chain->p0); - eval[1] = eval_poly_lo(sturn_chain->p1,x); - eval[2] = eval_poly_lo(sturn_chain->p2,x); - eval[3] = eval_poly_lo(sturn_chain->p3,x); - eval[4] = eval_poly_lo(sturn_chain->p4,x); + eval[0] = eval_poly(x, sturn_chain->p0); + eval[1] = eval_poly_lo(sturn_chain->p1, x); + eval[2] = eval_poly_lo(sturn_chain->p2, x); + eval[3] = eval_poly_lo(sturn_chain->p3, x); + eval[4] = eval_poly_lo(sturn_chain->p4, x); } - -static double -eval_num_roots(struct gkyl_sturm_polynomials *sturn_chain, double domain[2]) +static double eval_num_roots(struct gkyl_sturm_polynomials *sturn_chain, double domain[2]) { // Evaluate the sturn chain double eval_sturn_chain_l[5]; double eval_sturn_chain_r[5]; - eval_strum_chain(sturn_chain,domain[0],eval_sturn_chain_l); - eval_strum_chain(sturn_chain,domain[1],eval_sturn_chain_r); + eval_strum_chain(sturn_chain, domain[0], eval_sturn_chain_l); + eval_strum_chain(sturn_chain, domain[1], eval_sturn_chain_r); - // Compute the signs + // Compute the signs int signs_l[5]; int signs_r[5]; - signs_strum_chain(eval_sturn_chain_l,signs_l); - signs_strum_chain(eval_sturn_chain_r,signs_r); + signs_strum_chain(eval_sturn_chain_l, signs_l); + signs_strum_chain(eval_sturn_chain_r, signs_r); // Compute the number of roots int num_roots = sign_changes(signs_l) - sign_changes(signs_r); @@ -387,67 +366,63 @@ eval_num_roots(struct gkyl_sturm_polynomials *sturn_chain, double domain[2]) return num_roots; } - -static void -check_poly_full_domain(double *p, double *domain, double tol) +static void check_poly_full_domain(double *p, double *domain, double tol) { double left_bound = domain[0]; double right_bound = domain[1]; - double eval_left_bound = eval_poly(left_bound,p); - double eval_right_bound = eval_poly(right_bound,p); + double eval_left_bound = eval_poly(left_bound, p); + double eval_right_bound = eval_poly(right_bound, p); // If the edges are zero, then shift the boundary int iter = 0; - while(eval_left_bound == 0.0 && iter <= 3){ + while (eval_left_bound == 0.0 && iter <= 3) { left_bound = left_bound - tol; - eval_left_bound = eval_poly(left_bound,p); + eval_left_bound = eval_poly(left_bound, p); iter = iter + 1; } iter = 0; - while(eval_right_bound == 0.0 && iter <= 3){ + while (eval_right_bound == 0.0 && iter <= 3) { right_bound = right_bound + tol; - eval_right_bound = eval_poly(right_bound,p); + eval_right_bound = eval_poly(right_bound, p); iter = iter + 1; } // Update the boundaries domain[0] = left_bound; - domain[1] = right_bound;; + domain[1] = right_bound; + ; } - -static double +static double check_poly_bounded(double *p, double left_bound, double middle_bound, double right_bound) { - - // Compute the updated middle bound in the polynomial evaluation falls directly on + // Compute the updated middle bound in the polynomial evaluation falls directly on // p(x) = 0 double updated_middle_bound = middle_bound; - double eval_middle_bound = eval_poly(middle_bound,p); + double eval_middle_bound = eval_poly(middle_bound, p); int iter = 0; - while(eval_middle_bound == 0.0 && iter <= 3){ - updated_middle_bound = (right_bound+left_bound)/2.0 + (right_bound-left_bound)*(0.1*(iter+1)); - eval_middle_bound = eval_poly(updated_middle_bound,p); - iter = iter + 1; + while (eval_middle_bound == 0.0 && iter <= 3) { + updated_middle_bound = + (right_bound + left_bound) / 2.0 + (right_bound - left_bound) * (0.1 * (iter + 1)); + eval_middle_bound = eval_poly(updated_middle_bound, p); + iter = iter + 1; } // Check the new V bool bounded = (left_bound < updated_middle_bound && updated_middle_bound < right_bound); - if (bounded != 1){ - // return original boundary + if (bounded != 1) { + // return original boundary updated_middle_bound = middle_bound; } return updated_middle_bound; } - static struct gkyl_root_intervals bisection_root_search(struct gkyl_sturm_polynomials *sturn_chain, double domain[2], double tol) { - - // Initialize + // Initialize int status = 0; int niter = 0; double lower_bound[4] = {0.0, 0.0, 0.0, 0.0}; @@ -457,30 +432,27 @@ bisection_root_search(struct gkyl_sturm_polynomials *sturn_chain, double domain[ check_poly_full_domain(sturn_chain->p0, domain, tol); // Compute number of real-distinct-roots - int total_roots = eval_num_roots(sturn_chain,domain); + int total_roots = eval_num_roots(sturn_chain, domain); // Check cases where there are no roots/only one root - if (total_roots == 1){ - + if (total_roots == 1) { // Complete lower_bound[0] = domain[0]; upper_bound[0] = domain[1]; - } else if (total_roots == 0){ - + } else if (total_roots == 0) { // Complete - // Bisection search begins - } else if (total_roots > 1){ - + // Bisection search begins + } else if (total_roots > 1) { // Initialize additional variables needed in the search int roots_isolated = 0; - double return_to_this_domain[2] = {0.0,0.0}; + double return_to_this_domain[2] = {0.0, 0.0}; // Break the domain into two parts double left_bound = domain[0]; double right_bound = domain[1]; - double middle_bound = (left_bound+right_bound)/2.0; + double middle_bound = (left_bound + right_bound) / 2.0; middle_bound = check_poly_bounded(sturn_chain->p0, left_bound, middle_bound, right_bound); int not_all_roots_are_isolated = 1; int isolated_num_roots = 0; @@ -489,8 +461,7 @@ bisection_root_search(struct gkyl_sturm_polynomials *sturn_chain, double domain[ int left_num_roots, right_num_roots; // Iterate while not all roots are isolated - while(not_all_roots_are_isolated && niter < 1000){ - + while (not_all_roots_are_isolated && niter < 1000) { // update niter niter = niter + 1; @@ -504,36 +475,31 @@ bisection_root_search(struct gkyl_sturm_polynomials *sturn_chain, double domain[ domain_right[1] = right_bound; right_num_roots = eval_num_roots(sturn_chain, domain_right); - //Cases of different number of roots in each side - if (left_num_roots == total_roots - isolated_num_roots){ - + if (left_num_roots == total_roots - isolated_num_roots) { // update to the left domain right_bound = middle_bound; - middle_bound = (left_bound+right_bound)/2.0; + middle_bound = (left_bound + right_bound) / 2.0; middle_bound = check_poly_bounded(sturn_chain->p0, left_bound, middle_bound, right_bound); - } else if (right_num_roots == total_roots - isolated_num_roots){ - + } else if (right_num_roots == total_roots - isolated_num_roots) { // update to the right domain left_bound = middle_bound; - middle_bound = (left_bound+right_bound)/2.0; + middle_bound = (left_bound + right_bound) / 2.0; middle_bound = check_poly_bounded(sturn_chain->p0, left_bound, middle_bound, right_bound); - // We succussfully split the domain to some degree - } else { - + // We succussfully split the domain to some degree + } else { //if the left or right is 1 then we can add a domain to our result - if (left_num_roots == 1 || right_num_roots == 1){ - - if (left_num_roots == 1){ + if (left_num_roots == 1 || right_num_roots == 1) { + if (left_num_roots == 1) { lower_bound[roots_isolated] = left_bound; upper_bound[roots_isolated] = middle_bound; roots_isolated = roots_isolated + 1; isolated_num_roots = roots_isolated; } - if (right_num_roots == 1){ + if (right_num_roots == 1) { lower_bound[roots_isolated] = middle_bound; upper_bound[roots_isolated] = right_bound; roots_isolated = roots_isolated + 1; @@ -541,31 +507,32 @@ bisection_root_search(struct gkyl_sturm_polynomials *sturn_chain, double domain[ } //update to the right-side of the domain - if (left_num_roots == 1){ + if (left_num_roots == 1) { left_bound = middle_bound; - middle_bound = (left_bound+right_bound)/2.0; - middle_bound = check_poly_bounded(sturn_chain->p0, left_bound, middle_bound, right_bound); + middle_bound = (left_bound + right_bound) / 2.0; + middle_bound = + check_poly_bounded(sturn_chain->p0, left_bound, middle_bound, right_bound); } // update to the left-side of the domain - if (right_num_roots == 1){ + if (right_num_roots == 1) { right_bound = middle_bound; - middle_bound = (left_bound+right_bound)/2.0; - middle_bound = check_poly_bounded(sturn_chain->p0, left_bound, middle_bound, right_bound); + middle_bound = (left_bound + right_bound) / 2.0; + middle_bound = + check_poly_bounded(sturn_chain->p0, left_bound, middle_bound, right_bound); } - if (right_num_roots == 1 && left_num_roots == 1){ - + if (right_num_roots == 1 && left_num_roots == 1) { // Complete if all roots are isolated - if (total_roots == roots_isolated){ + if (total_roots == roots_isolated) { not_all_roots_are_isolated = 0; } else { - // Otherwise, load the second domain left_bound = return_to_this_domain[0]; right_bound = return_to_this_domain[1]; - middle_bound = (left_bound+right_bound)/2.0; - middle_bound = check_poly_bounded(sturn_chain->p0, left_bound, middle_bound, right_bound); + middle_bound = (left_bound + right_bound) / 2.0; + middle_bound = + check_poly_bounded(sturn_chain->p0, left_bound, middle_bound, right_bound); isolated_num_roots = roots_isolated; } // end returning to isolated domain @@ -573,8 +540,7 @@ bisection_root_search(struct gkyl_sturm_polynomials *sturn_chain, double domain[ } else { // we've exactly split 2v2 in the domains - if (right_num_roots == 2 && left_num_roots == 2){ - + if (right_num_roots == 2 && left_num_roots == 2) { // Save a domain to return to then return_to_this_domain[0] = middle_bound; return_to_this_domain[1] = right_bound; @@ -582,8 +548,9 @@ bisection_root_search(struct gkyl_sturm_polynomials *sturn_chain, double domain[ // update to the left domain right_bound = middle_bound; - middle_bound = (left_bound+right_bound)/2.0; - middle_bound = check_poly_bounded(sturn_chain->p0, left_bound, middle_bound, right_bound); + middle_bound = (left_bound + right_bound) / 2.0; + middle_bound = + check_poly_bounded(sturn_chain->p0, left_bound, middle_bound, right_bound); } else { status = 1; @@ -598,45 +565,42 @@ bisection_root_search(struct gkyl_sturm_polynomials *sturn_chain, double domain[ } //end roots conditions // Throw an error if the while loop stopped due to unending iterations - if (niter == 1000){ - printf("Couldn't isolate the root intervals: Total_roots: %d!\n",total_roots); + if (niter == 1000) { + printf("Couldn't isolate the root intervals: Total_roots: %d!\n", total_roots); } - return (struct gkyl_root_intervals) { - .status = status, + return (struct gkyl_root_intervals + ){.status = status, .niter = niter, .nroots = total_roots, - .root_bound_lower = { lower_bound[0], lower_bound[1], lower_bound[2], lower_bound[3] }, - .root_bound_upper = { upper_bound[0], upper_bound[1], upper_bound[2], upper_bound[3] }, - .sturn_chain = *sturn_chain - }; + .root_bound_lower = {lower_bound[0], lower_bound[1], lower_bound[2], lower_bound[3]}, + .root_bound_upper = {upper_bound[0], upper_bound[1], upper_bound[2], upper_bound[3]}, + .sturn_chain = *sturn_chain}; } -static inline int -deg_modified(double *p) +static inline int deg_modified(double *p) { // If everything is zero, the degree is zero int res = 0; // Compute the degree - for (int i=0; i<=3; ++i){ - if (p[i] != 0.0){ - res = i; + for (int i = 0; i <= 3; ++i) { + if (p[i] != 0.0) { + res = i; } } - + // return the result return res; } - -static void -minus_euclidean_division_rem(double *p0, double *p1, int p0_deg, double *res) +static void minus_euclidean_division_rem(double *p0, double *p1, int p0_deg, double *res) { - - // Initialize the problem + // Initialize the problem double r[4]; - for (int i=0; i<=3; ++i) r[i] = p0[i]; + for (int i = 0; i <= 3; ++i) { + r[i] = p0[i]; + } int r_deg = p0_deg; double rmax; if (p0_deg < 4) { @@ -647,32 +611,32 @@ minus_euclidean_division_rem(double *p0, double *p1, int p0_deg, double *res) rmax = 1.0; } int p1_deg = deg_modified(p1); - int iter_max = r_deg-p1_deg; // TODO: check index + int iter_max = r_deg - p1_deg; // TODO: check index double q[iter_max]; - double p1g[r_deg+1]; - for (int i=0; i<=r_deg; ++i) p1g[i] = 0.0; + double p1g[r_deg + 1]; + for (int i = 0; i <= r_deg; ++i) { + p1g[i] = 0.0; + } int iter = 0; // Iterate while the degree is still higher the the divisor - while(r_deg >= p1_deg) { - + while (r_deg >= p1_deg) { // compute the quotient - q[iter_max - iter] = rmax/p1[p1_deg]; - + q[iter_max - iter] = rmax / p1[p1_deg]; + // Multiply p1 by q - for (int i=0; i<=p1_deg; ++i) { - p1g[i+(iter_max - iter)] = p1[i]*q[iter_max - iter]; + for (int i = 0; i <= p1_deg; ++i) { + p1g[i + (iter_max - iter)] = p1[i] * q[iter_max - iter]; } // Subtract p1g from r - for (int i=0; i<=fmin(r_deg,3); ++i) { + for (int i = 0; i <= fmin(r_deg, 3); ++i) { if (i != r_deg) { r[i] = r[i] - p1g[i]; - } - else { + } else { r[i] = 0.0; } - } + } // update the iter, degree of the remaining poly iter = iter + 1; @@ -680,53 +644,51 @@ minus_euclidean_division_rem(double *p0, double *p1, int p0_deg, double *res) rmax = r[r_deg]; // set p1g to zero - for (int i=0; i<=r_deg+1; ++i) p1g[i] = 0.0*p1g[i]; + for (int i = 0; i <= r_deg + 1; ++i) { + p1g[i] = 0.0 * p1g[i]; + } } // We require the minus of the returned remainder - for (int i=0; i<=3; ++i) res[i] = -r[i]; + for (int i = 0; i <= 3; ++i) { + res[i] = -r[i]; + } } - -static struct gkyl_sturm_polynomials -compute_sturn_chain(double p0[4]) +static struct gkyl_sturm_polynomials compute_sturn_chain(double p0[4]) { - // Compute the first derivative of p0 to get p1 - double p1[4] = { p0[1], 2.0*p0[2], 3.0*p0[3], 4.0*1.0 }; + double p1[4] = {p0[1], 2.0 * p0[2], 3.0 * p0[3], 4.0 * 1.0}; // Compute the Euclidean division of p0 by p1, return the -remainder double p2[4], p3[4], p4[4]; - minus_euclidean_division_rem(p0,p1,4,p2); + minus_euclidean_division_rem(p0, p1, 4, p2); // Compute the next division p1 by p2 - minus_euclidean_division_rem(p1,p2,0,p3); + minus_euclidean_division_rem(p1, p2, 0, p3); // Compute the next division p2 by p3 - minus_euclidean_division_rem(p2,p3,0,p4); - - return (struct gkyl_sturm_polynomials) { - .p0 = { p0[0], p0[1], p0[2], p0[3] }, - .p1 = { p1[0], p1[1], p1[2], p1[3] }, - .p2 = { p2[0], p2[1], p2[2], p2[3] }, - .p3 = { p3[0], p3[1], p3[2], p3[3] }, - .p4 = { p4[0], p4[1], p4[2], p4[3] } - }; + minus_euclidean_division_rem(p2, p3, 0, p4); + + return (struct gkyl_sturm_polynomials + ){.p0 = {p0[0], p0[1], p0[2], p0[3]}, + .p1 = {p1[0], p1[1], p1[2], p1[3]}, + .p2 = {p2[0], p2[1], p2[2], p2[3]}, + .p3 = {p3[0], p3[1], p3[2], p3[3]}, + .p4 = {p4[0], p4[1], p4[2], p4[3]}}; } -void -gkyl_refine_root_intervals_bisection(struct gkyl_root_intervals *root_intervals, double tol) +void gkyl_refine_root_intervals_bisection(struct gkyl_root_intervals *root_intervals, double tol) { // Compute the number of domains to refine - int nroots = root_intervals->nroots; + int nroots = root_intervals->nroots; // For all domains, refine the result - for (int i=0; iroot_bound_lower[i]; double right_bound = root_intervals->root_bound_upper[i]; - double error = 2.0*tol; + double error = 2.0 * tol; int iter = 0; double middle_bound; double domain_left[2]; @@ -735,11 +697,11 @@ gkyl_refine_root_intervals_bisection(struct gkyl_root_intervals *root_intervals, int status = 0; // Iterate on the domain for some tolerance - while(error > tol && iter < 100){ - + while (error > tol && iter < 100) { // Grab middle location in the domain - middle_bound = (left_bound+right_bound)/2.0; - middle_bound = check_poly_bounded(root_intervals->sturn_chain.p0, left_bound, middle_bound, right_bound); + middle_bound = (left_bound + right_bound) / 2.0; + middle_bound = + check_poly_bounded(root_intervals->sturn_chain.p0, left_bound, middle_bound, right_bound); // Compute the roots (L) domain_left[0] = left_bound; @@ -751,55 +713,50 @@ gkyl_refine_root_intervals_bisection(struct gkyl_root_intervals *root_intervals, domain_right[1] = right_bound; right_num_roots = eval_num_roots(&root_intervals->sturn_chain, domain_right); - // Cases of different number of roots in each side - if (left_num_roots == 1){ - - // update to the left domain - right_bound = middle_bound; - - } else if (right_num_roots == 1){ + if (left_num_roots == 1) { + // update to the left domain + right_bound = middle_bound; - // update to the right domain - left_bound = middle_bound; + } else if (right_num_roots == 1) { + // update to the right domain + left_bound = middle_bound; } else { - status = 1; - } // update the error error = fabs(left_bound - right_bound); iter = iter + 1; } - + // Save the restricted domain root_intervals->root_bound_lower[i] = left_bound; root_intervals->root_bound_upper[i] = right_bound; root_intervals->status_refinement[i] = status; root_intervals->niter_refinement[i] = iter; } -} +} -void -gkyl_root_isolation_from_intervals_via_ridders(struct gkyl_root_intervals *root_intervals, double tol) +void gkyl_root_isolation_from_intervals_via_ridders( + struct gkyl_root_intervals *root_intervals, double tol +) { - // Compute the number of domains to compute roots on - int nroots = root_intervals->nroots; + int nroots = root_intervals->nroots; double root; int status; // For all domains, refine the result - for (int i=0; iroot_bound_lower[i]; double x2 = root_intervals->root_bound_upper[i]; - double f1 = eval_poly(x1,root_intervals->sturn_chain.p0); - double f2 = eval_poly(x2,root_intervals->sturn_chain.p0); - struct gkyl_qr_res res = gkyl_ridders(eval_poly, root_intervals->sturn_chain.p0, x1, x2, f1, f2, 100, tol); + double f1 = eval_poly(x1, root_intervals->sturn_chain.p0); + double f2 = eval_poly(x2, root_intervals->sturn_chain.p0); + struct gkyl_qr_res res = + gkyl_ridders(eval_poly, root_intervals->sturn_chain.p0, x1, x2, f1, f2, 100, tol); // Save the roots root_intervals->real_roots_ridders[i] = res.res; @@ -807,96 +764,91 @@ gkyl_root_isolation_from_intervals_via_ridders(struct gkyl_root_intervals *root_ } } - -struct gkyl_root_intervals +struct gkyl_root_intervals gkyl_calc_quartic_root_intervals(double coeff[4], double domain[2], double tol) { - // Compute the sturn chain struct gkyl_sturm_polynomials sturn_chain = compute_sturn_chain(coeff); // Isolate the intervals - struct gkyl_root_intervals root_intervals = bisection_root_search(&sturn_chain,domain, tol); + struct gkyl_root_intervals root_intervals = bisection_root_search(&sturn_chain, domain, tol); // Retrun the structure return root_intervals; - -} -struct gkyl_poly_roots* -gkyl_poly_roots_new(int poly_order) +} +struct gkyl_poly_roots *gkyl_poly_roots_new(int poly_order) { struct gkyl_poly_roots *pr = gkyl_malloc(sizeof *pr); pr->impart = gkyl_malloc(sizeof(double[poly_order])); pr->rpart = gkyl_malloc(sizeof(double[poly_order])); pr->err = gkyl_malloc(sizeof(double[poly_order])); - pr->work = gkyl_malloc(sizeof(double complex[2*poly_order])); + pr->work = gkyl_malloc(sizeof(double complex[2 * poly_order])); pr->poly_order = poly_order; return pr; } -static inline double complex -eval_poly2(int poly_order, const double *coeff, double complex x) +static inline double complex eval_poly2(int poly_order, const double *coeff, double complex x) { double complex xn = x; double complex res = coeff[0]; - for (int i=1; ipoly_order; double complex *pn1 = pr->work; double complex *pn = pn1 + poly_order; - double complex r1 = 0.4+0.9*I; // arbitrary complex number, not a root of unity + double complex r1 = 0.4 + 0.9 * I; // arbitrary complex number, not a root of unity pn1[0] = r1; - for (int i=1; ierr) && niter < max_iter); pr->niter = niter; - for (int i=0; irpart[i] = creal(pn1[i]); pr->impart[i] = cimag(pn1[i]); } } -void -gkyl_poly_roots_release(struct gkyl_poly_roots *pr) +void gkyl_poly_roots_release(struct gkyl_poly_roots *pr) { gkyl_free(pr->impart); gkyl_free(pr->rpart); diff --git a/core/zero/mom_type.c b/core/zero/mom_type.c index 4b4ad8da63..7babbe3f52 100644 --- a/core/zero/mom_type.c +++ b/core/zero/mom_type.c @@ -1,35 +1,31 @@ #include #include -bool -gkyl_mom_type_is_cu_dev(const struct gkyl_mom_type* momt) +bool gkyl_mom_type_is_cu_dev(const struct gkyl_mom_type *momt) { return GKYL_IS_CU_ALLOC(momt->flags); } -struct gkyl_mom_type* -gkyl_mom_type_acquire(const struct gkyl_mom_type* momt) +struct gkyl_mom_type *gkyl_mom_type_acquire(const struct gkyl_mom_type *momt) { gkyl_ref_count_inc(&momt->ref_count); - return (struct gkyl_mom_type*) momt; + return (struct gkyl_mom_type *)momt; } -void -gkyl_mom_type_release(const struct gkyl_mom_type* momt) +void gkyl_mom_type_release(const struct gkyl_mom_type *momt) { gkyl_ref_count_dec(&momt->ref_count); } -void -gkyl_mom_type_calc(const struct gkyl_mom_type* momt, - const double *xc, const double *dx, const int *idx, - const double *f, double* GKYL_RESTRICT out, void *param) +void gkyl_mom_type_calc( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *GKYL_RESTRICT out, void *param +) { momt->kernel(momt, xc, dx, idx, f, out, param); } -int -gkyl_mom_type_num_mom(const struct gkyl_mom_type* momt) +int gkyl_mom_type_num_mom(const struct gkyl_mom_type *momt) { return momt->num_mom; } diff --git a/core/zero/mpi_comm.c b/core/zero/mpi_comm.c index 6f020a3f3c..d592b2e7a4 100644 --- a/core/zero/mpi_comm.c +++ b/core/zero/mpi_comm.c @@ -15,19 +15,12 @@ #include // Mapping of Gkeyll type to MPI_Datatype -static MPI_Datatype g2_mpi_datatype[] = { - [GKYL_INT] = MPI_INT, - [GKYL_INT_64] = MPI_INT64_T, - [GKYL_FLOAT] = MPI_FLOAT, - [GKYL_DOUBLE] = MPI_DOUBLE +static MPI_Datatype g2_mpi_datatype[] = + {[GKYL_INT] = MPI_INT, [GKYL_INT_64] = MPI_INT64_T, [GKYL_FLOAT] = MPI_FLOAT, [GKYL_DOUBLE] = MPI_DOUBLE }; // Mapping of Gkeyll ops to MPI_Op -static MPI_Op g2_mpi_op[] = { - [GKYL_MIN] = MPI_MIN, - [GKYL_MAX] = MPI_MAX, - [GKYL_SUM] = MPI_SUM -}; +static MPI_Op g2_mpi_op[] = {[GKYL_MIN] = MPI_MIN, [GKYL_MAX] = MPI_MAX, [GKYL_SUM] = MPI_SUM}; struct gkyl_comm_state { MPI_Request req; @@ -39,11 +32,10 @@ struct extra_mpi_comm_inp { }; // Internal method to create a new MPI communicator -static struct gkyl_comm* mpi_comm_new( - const struct gkyl_mpi_comm_inp *inp, const struct extra_mpi_comm_inp *extra_inp); +static struct gkyl_comm * +mpi_comm_new(const struct gkyl_mpi_comm_inp *inp, const struct extra_mpi_comm_inp *extra_inp); -static void -comm_free(const struct gkyl_ref_count *ref) +static void comm_free(const struct gkyl_ref_count *ref) { struct gkyl_comm *comm = container_of(ref, struct gkyl_comm, ref_count); struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); @@ -52,92 +44,93 @@ comm_free(const struct gkyl_ref_count *ref) gkyl_rect_decomp_release(mpi->decomp); gkyl_rect_decomp_neigh_release(mpi->neigh); - for (int d=0; dper_neigh[d]); - - for (int i=0; irecv[i].buff); - - for (int i=0; isend[i].buff); - + } + gkyl_mem_buff_release(mpi->allgather_buff_local.buff); gkyl_mem_buff_release(mpi->allgather_buff_global.buff); - if (mpi->is_mcomm_allocated) + if (mpi->is_mcomm_allocated) { MPI_Comm_free(&mpi->mcomm); + } gkyl_free(mpi); } -static int -get_rank(struct gkyl_comm *comm, int *rank) +static int get_rank(struct gkyl_comm *comm, int *rank) { struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); MPI_Comm_rank(mpi->mcomm, rank); return 0; } -static int -get_size(struct gkyl_comm *comm, int *sz) +static int get_size(struct gkyl_comm *comm, int *sz) { struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); MPI_Comm_size(mpi->mcomm, sz); return 0; } -static int -array_send(struct gkyl_array *array, int dest, int tag, struct gkyl_comm *comm) +static int array_send(struct gkyl_array *array, int dest, int tag, struct gkyl_comm *comm) { - size_t vol = array->esznc*array->size; - struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); - int ret = MPI_Send(array->data, vol, MPI_CHAR, dest, tag, mpi->mcomm); + size_t vol = array->esznc * array->size; + struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); + int ret = MPI_Send(array->data, vol, MPI_CHAR, dest, tag, mpi->mcomm); return ret == MPI_SUCCESS ? 0 : 1; } -static int -array_isend(struct gkyl_array *array, int dest, int tag, struct gkyl_comm *comm, struct gkyl_comm_state *state) +static int array_isend( + struct gkyl_array *array, int dest, int tag, struct gkyl_comm *comm, struct gkyl_comm_state *state +) { - size_t vol = array->esznc*array->size; - struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); - int ret = MPI_Isend(array->data, vol, MPI_CHAR, dest, tag, mpi->mcomm, &state->req); + size_t vol = array->esznc * array->size; + struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); + int ret = MPI_Isend(array->data, vol, MPI_CHAR, dest, tag, mpi->mcomm, &state->req); return ret == MPI_SUCCESS ? 0 : 1; } -static int -array_recv(struct gkyl_array *array, int src, int tag, struct gkyl_comm *comm) +static int array_recv(struct gkyl_array *array, int src, int tag, struct gkyl_comm *comm) { - size_t vol = array->esznc*array->size; - struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); + size_t vol = array->esznc * array->size; + struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); MPI_Status stat; - int ret = MPI_Recv(array->data, vol, MPI_CHAR, src, tag, mpi->mcomm, &stat); + int ret = MPI_Recv(array->data, vol, MPI_CHAR, src, tag, mpi->mcomm, &stat); return ret == MPI_SUCCESS ? 0 : 1; } -static int -array_irecv(struct gkyl_array *array, int src, int tag, struct gkyl_comm *comm, struct gkyl_comm_state *state) +static int array_irecv( + struct gkyl_array *array, int src, int tag, struct gkyl_comm *comm, struct gkyl_comm_state *state +) { - size_t vol = array->esznc*array->size; - struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); - int ret = MPI_Irecv(array->data, vol, MPI_CHAR, src, tag, mpi->mcomm, &state->req); + size_t vol = array->esznc * array->size; + struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); + int ret = MPI_Irecv(array->data, vol, MPI_CHAR, src, tag, mpi->mcomm, &state->req); return ret == MPI_SUCCESS ? 0 : 1; } -static int -allreduce(struct gkyl_comm *comm, enum gkyl_elem_type type, - enum gkyl_array_op op, int nelem, const void *inp, - void *out) +static int allreduce( + struct gkyl_comm *comm, enum gkyl_elem_type type, enum gkyl_array_op op, int nelem, + const void *inp, void *out +) { - struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); - int ret = - MPI_Allreduce(inp, out, nelem, g2_mpi_datatype[type], g2_mpi_op[op], mpi->mcomm); + struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); + int ret = MPI_Allreduce(inp, out, nelem, g2_mpi_datatype[type], g2_mpi_op[op], mpi->mcomm); return ret == MPI_SUCCESS ? 0 : 1; } -static int -array_allgather(struct gkyl_comm *comm, - const struct gkyl_range *local, const struct gkyl_range *global, - const struct gkyl_array *array_local, struct gkyl_array *array_global) +static int array_allgather( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *global, + const struct gkyl_array *array_local, struct gkyl_array *array_global +) { assert(array_global->esznc == array_local->esznc); @@ -152,225 +145,242 @@ array_allgather(struct gkyl_comm *comm, assert(global->volume == mpi->decomp->parent_range.volume); // potentially re-size local buffer volume - size_t send_vol = array_local->esznc*mpi->decomp->ranges[rank].volume; - if (gkyl_mem_buff_size(mpi->allgather_buff_local.buff) < send_vol) + size_t send_vol = array_local->esznc * mpi->decomp->ranges[rank].volume; + if (gkyl_mem_buff_size(mpi->allgather_buff_local.buff) < send_vol) { gkyl_mem_buff_resize(mpi->allgather_buff_local.buff, send_vol); + } // potentially re-size global buffer volume - size_t buff_global_vol = array_local->esznc*mpi->decomp->parent_range.volume; - if (gkyl_mem_buff_size(mpi->allgather_buff_global.buff) < buff_global_vol) + size_t buff_global_vol = array_local->esznc * mpi->decomp->parent_range.volume; + if (gkyl_mem_buff_size(mpi->allgather_buff_global.buff) < buff_global_vol) { gkyl_mem_buff_resize(mpi->allgather_buff_global.buff, buff_global_vol); + } // copy data to local buffer - gkyl_array_copy_to_buffer(gkyl_mem_buff_data(mpi->allgather_buff_local.buff), - array_local, local); + gkyl_array_copy_to_buffer(gkyl_mem_buff_data(mpi->allgather_buff_local.buff), array_local, local); - size_t nelem = array_local->esznc*mpi->decomp->ranges[rank].volume; + size_t nelem = array_local->esznc * mpi->decomp->ranges[rank].volume; // gather data into global buffer - int ret = - MPI_Allgather(gkyl_mem_buff_data(mpi->allgather_buff_local.buff), nelem, MPI_CHAR, - gkyl_mem_buff_data(mpi->allgather_buff_global.buff), nelem, MPI_CHAR, mpi->mcomm); + int ret = MPI_Allgather( + gkyl_mem_buff_data(mpi->allgather_buff_local.buff), nelem, MPI_CHAR, + gkyl_mem_buff_data(mpi->allgather_buff_global.buff), nelem, MPI_CHAR, mpi->mcomm + ); // copy data to global array int idx = 0; - for (int r=0; rdecomp->ndecomp; ++r) { - int isrecv = gkyl_sub_range_intersect( - &gather_range, global, &mpi->decomp->ranges[r]); - gkyl_array_copy_from_buffer(array_global, - gkyl_mem_buff_data(mpi->allgather_buff_global.buff) + idx, &gather_range); - idx += array_local->esznc*gather_range.volume; + for (int r = 0; r < mpi->decomp->ndecomp; ++r) { + int isrecv = gkyl_sub_range_intersect(&gather_range, global, &mpi->decomp->ranges[r]); + gkyl_array_copy_from_buffer( + array_global, gkyl_mem_buff_data(mpi->allgather_buff_global.buff) + idx, &gather_range + ); + idx += array_local->esznc * gather_range.volume; } return 0; } -static int -array_bcast(struct gkyl_comm *comm, const struct gkyl_array *asend, - struct gkyl_array *arecv, int root) +static int array_bcast( + struct gkyl_comm *comm, const struct gkyl_array *asend, struct gkyl_array *arecv, int root +) { assert(asend->esznc == arecv->esznc); assert(asend->size == arecv->size); struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); - size_t nelem = asend->esznc*asend->size; - int ret = - MPI_Bcast(asend->data, nelem, MPI_CHAR, root, mpi->mcomm); + size_t nelem = asend->esznc * asend->size; + int ret = MPI_Bcast(asend->data, nelem, MPI_CHAR, root, mpi->mcomm); return 0; } -static int -sync(struct gkyl_comm *comm, - const struct gkyl_range *local, const struct gkyl_range *local_ext, - struct gkyl_array *array, bool use_corners) +static int sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + struct gkyl_array *array, bool use_corners +) { struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); - int rank; gkyl_comm_get_rank(comm, &rank); + int rank; + gkyl_comm_get_rank(comm, &rank); - int nghost[GKYL_MAX_DIM] = { 0 }; - for (int i=0; idecomp->ndim; ++i) - nghost[i] = local_ext->upper[i]-local->upper[i]; + int nghost[GKYL_MAX_DIM] = {0}; + for (int i = 0; i < mpi->decomp->ndim; ++i) { + nghost[i] = local_ext->upper[i] - local->upper[i]; + } int nridx = 0; int tag = MPI_BASE_TAG; - // post nonblocking recv to get data into ghost-cells - for (int n=0; nneigh->num_neigh; ++n) { + // post nonblocking recv to get data into ghost-cells + for (int n = 0; n < mpi->neigh->num_neigh; ++n) { int nid = mpi->neigh->neigh[n]; int n_dir = mpi->neigh->dir[n]; int n_edge = mpi->neigh->edge[n]; - + struct gkyl_range skin; - if (use_corners) - gkyl_skin_ghost_with_corners_ranges(&skin, &mpi->recv[nridx].range, n_dir, n_edge, - local_ext, nghost); - else - gkyl_skin_ghost_ranges(&skin, &mpi->recv[nridx].range, n_dir, n_edge, - local_ext, nghost); - - size_t recv_vol = array->esznc*mpi->recv[nridx].range.volume; - - if (recv_vol>0) { - if (gkyl_mem_buff_size(mpi->recv[nridx].buff) < recv_vol) + if (use_corners) { + gkyl_skin_ghost_with_corners_ranges( + &skin, &mpi->recv[nridx].range, n_dir, n_edge, local_ext, nghost + ); + } else { + gkyl_skin_ghost_ranges(&skin, &mpi->recv[nridx].range, n_dir, n_edge, local_ext, nghost); + } + + size_t recv_vol = array->esznc * mpi->recv[nridx].range.volume; + + if (recv_vol > 0) { + if (gkyl_mem_buff_size(mpi->recv[nridx].buff) < recv_vol) { gkyl_mem_buff_resize(mpi->recv[nridx].buff, recv_vol); + } - MPI_Irecv(gkyl_mem_buff_data(mpi->recv[nridx].buff), - recv_vol, MPI_CHAR, nid, tag, mpi->mcomm, &mpi->recv[nridx].status); + MPI_Irecv( + gkyl_mem_buff_data(mpi->recv[nridx].buff), recv_vol, MPI_CHAR, nid, tag, mpi->mcomm, + &mpi->recv[nridx].status + ); nridx += 1; } } int nsidx = 0; - + // post non-blocking sends of skin-cell data to neighbors - for (int n=0; nneigh->num_neigh; ++n) { + for (int n = 0; n < mpi->neigh->num_neigh; ++n) { int nid = mpi->neigh->neigh[n]; int n_dir = mpi->neigh->dir[n]; - int n_edge = mpi->neigh->edge[n]; - + int n_edge = mpi->neigh->edge[n]; + struct gkyl_range ghost; - if (use_corners) - gkyl_skin_ghost_with_corners_ranges(&mpi->send[nsidx].range, &ghost, n_dir, n_edge, - local_ext, nghost); - else - gkyl_skin_ghost_ranges(&mpi->send[nsidx].range, &ghost, n_dir, n_edge, - local_ext, nghost); - - size_t send_vol = array->esznc*mpi->send[nsidx].range.volume; - - if (send_vol>0) { - if (gkyl_mem_buff_size(mpi->send[nsidx].buff) < send_vol) + if (use_corners) { + gkyl_skin_ghost_with_corners_ranges( + &mpi->send[nsidx].range, &ghost, n_dir, n_edge, local_ext, nghost + ); + } else { + gkyl_skin_ghost_ranges(&mpi->send[nsidx].range, &ghost, n_dir, n_edge, local_ext, nghost); + } + + size_t send_vol = array->esznc * mpi->send[nsidx].range.volume; + + if (send_vol > 0) { + if (gkyl_mem_buff_size(mpi->send[nsidx].buff) < send_vol) { gkyl_mem_buff_resize(mpi->send[nsidx].buff, send_vol); - - gkyl_array_copy_to_buffer(gkyl_mem_buff_data(mpi->send[nsidx].buff), - array, &(mpi->send[nsidx].range)); + } - MPI_Isend(gkyl_mem_buff_data(mpi->send[nsidx].buff), - send_vol, MPI_CHAR, nid, tag, mpi->mcomm, &mpi->send[nsidx].status); + gkyl_array_copy_to_buffer( + gkyl_mem_buff_data(mpi->send[nsidx].buff), array, &(mpi->send[nsidx].range) + ); + + MPI_Isend( + gkyl_mem_buff_data(mpi->send[nsidx].buff), send_vol, MPI_CHAR, nid, tag, mpi->mcomm, + &mpi->send[nsidx].status + ); nsidx += 1; } } // complete send - for (int s=0; ssend[s].range.volume; - if (issend) + if (issend) { MPI_Wait(&mpi->send[s].status, MPI_STATUS_IGNORE); + } } // complete recv, copying data into ghost-cells - for (int r=0; rrecv[r].range.volume; if (isrecv) { MPI_Wait(&mpi->recv[r].status, MPI_STATUS_IGNORE); - - gkyl_array_copy_from_buffer(array, - gkyl_mem_buff_data(mpi->recv[r].buff), - &(mpi->recv[r].range) + + gkyl_array_copy_from_buffer( + array, gkyl_mem_buff_data(mpi->recv[r].buff), &(mpi->recv[r].range) ); } } - + return 0; } -static int -array_sync(struct gkyl_comm *comm, - const struct gkyl_range *local, const struct gkyl_range *local_ext, - struct gkyl_array *array) +static int array_sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + struct gkyl_array *array +) { - struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); + struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); sync(comm, local, local_ext, array, false); if (mpi->sync_corners) { - for (int i=1; idecomp->ndim; ++i) + for (int i = 1; i < mpi->decomp->ndim; ++i) { sync(comm, local, local_ext, array, true); + } } - + return 0; } -static int -per_send_tag(const struct gkyl_range *dir_edge, - int dir, int e) +static int per_send_tag(const struct gkyl_range *dir_edge, int dir, int e) { int base_tag = MPI_BASE_PER_TAG; - return base_tag + gkyl_range_idx(dir_edge, (int[]) { dir, e }); + return base_tag + gkyl_range_idx(dir_edge, (int[]){dir, e}); } -static int -per_recv_tag(const struct gkyl_range *dir_edge, - int dir, int e) +static int per_recv_tag(const struct gkyl_range *dir_edge, int dir, int e) { int base_tag = MPI_BASE_PER_TAG; - return base_tag + gkyl_range_idx(dir_edge, (int[]) { dir, (e+1)%2 }); + return base_tag + gkyl_range_idx(dir_edge, (int[]){dir, (e + 1) % 2}); } -static int -per_sync(struct gkyl_comm *comm, const struct gkyl_range *local, - const struct gkyl_range *local_ext, - int nper_dirs, const int *per_dirs, struct gkyl_array *array, bool use_corners) +static int per_sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + int nper_dirs, const int *per_dirs, struct gkyl_array *array, bool use_corners +) { struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); - if (!mpi->touches_any_edge) return 0; // nothing to sync + if (!mpi->touches_any_edge) { + return 0; // nothing to sync + } int nghost[GKYL_MAX_DIM]; - for (int i=0; idecomp->ndim; ++i) - nghost[i] = local_ext->upper[i]-local->upper[i]; + for (int i = 0; i < mpi->decomp->ndim; ++i) { + nghost[i] = local_ext->upper[i] - local->upper[i]; + } int nridx = 0; - int edge_type[] = { GKYL_LOWER_EDGE, GKYL_UPPER_EDGE }; + int edge_type[] = {GKYL_LOWER_EDGE, GKYL_UPPER_EDGE}; // post nonblocking recv to get data into ghost-cells - for (int i=0; iis_on_edge[e][dir]) { - - for (int pn=0; pnper_neigh[dir]->num_neigh; ++pn) { + for (int pn = 0; pn < mpi->per_neigh[dir]->num_neigh; ++pn) { int nid = mpi->per_neigh[dir]->neigh[pn]; struct gkyl_range skin; - if (use_corners) - gkyl_skin_ghost_with_corners_ranges(&skin, &mpi->recv[nridx].range, dir, edge_type[e], - local_ext, nghost); - else - gkyl_skin_ghost_ranges(&skin, &mpi->recv[nridx].range, dir, edge_type[e], - local_ext, nghost); + if (use_corners) { + gkyl_skin_ghost_with_corners_ranges( + &skin, &mpi->recv[nridx].range, dir, edge_type[e], local_ext, nghost + ); + } else { + gkyl_skin_ghost_ranges( + &skin, &mpi->recv[nridx].range, dir, edge_type[e], local_ext, nghost + ); + } - size_t recv_vol = array->esznc*mpi->recv[nridx].range.volume; + size_t recv_vol = array->esznc * mpi->recv[nridx].range.volume; - if (recv_vol>0) { - if (gkyl_mem_buff_size(mpi->recv[nridx].buff) < recv_vol) + if (recv_vol > 0) { + if (gkyl_mem_buff_size(mpi->recv[nridx].buff) < recv_vol) { gkyl_mem_buff_resize(mpi->recv[nridx].buff, recv_vol); + } int tag = per_recv_tag(&mpi->dir_edge, dir, e); - MPI_Irecv(gkyl_mem_buff_data(mpi->recv[nridx].buff), - recv_vol, MPI_CHAR, nid, tag, mpi->mcomm, &mpi->recv[nridx].status); + MPI_Irecv( + gkyl_mem_buff_data(mpi->recv[nridx].buff), recv_vol, MPI_CHAR, nid, tag, mpi->mcomm, + &mpi->recv[nridx].status + ); nridx += 1; } @@ -379,38 +389,44 @@ per_sync(struct gkyl_comm *comm, const struct gkyl_range *local, } } - int nsidx = 0; + int nsidx = 0; // post non-blocking send skin-cell data to neighbors - for (int i=0; iis_on_edge[e][dir]) { - - for (int pn=0; pnper_neigh[dir]->num_neigh; ++pn) { + for (int pn = 0; pn < mpi->per_neigh[dir]->num_neigh; ++pn) { int nid = mpi->per_neigh[dir]->neigh[pn]; struct gkyl_range ghost; - if (use_corners) - gkyl_skin_ghost_with_corners_ranges(&mpi->send[nsidx].range, &ghost, dir, edge_type[e], - local_ext, nghost); - else - gkyl_skin_ghost_ranges(&mpi->send[nsidx].range, &ghost, dir, edge_type[e], - local_ext, nghost); + if (use_corners) { + gkyl_skin_ghost_with_corners_ranges( + &mpi->send[nsidx].range, &ghost, dir, edge_type[e], local_ext, nghost + ); + } else { + gkyl_skin_ghost_ranges( + &mpi->send[nsidx].range, &ghost, dir, edge_type[e], local_ext, nghost + ); + } - size_t send_vol = array->esznc*mpi->send[nsidx].range.volume; + size_t send_vol = array->esznc * mpi->send[nsidx].range.volume; - if (send_vol>0) { - if (gkyl_mem_buff_size(mpi->send[nsidx].buff) < send_vol) + if (send_vol > 0) { + if (gkyl_mem_buff_size(mpi->send[nsidx].buff) < send_vol) { gkyl_mem_buff_resize(mpi->send[nsidx].buff, send_vol); - - gkyl_array_copy_to_buffer(gkyl_mem_buff_data(mpi->send[nsidx].buff), - array, &(mpi->send[nsidx].range)); + } + + gkyl_array_copy_to_buffer( + gkyl_mem_buff_data(mpi->send[nsidx].buff), array, &(mpi->send[nsidx].range) + ); int tag = per_send_tag(&mpi->dir_edge, dir, e); - MPI_Isend(gkyl_mem_buff_data(mpi->send[nsidx].buff), - send_vol, MPI_CHAR, nid, tag, mpi->mcomm, &mpi->send[nsidx].status); + MPI_Isend( + gkyl_mem_buff_data(mpi->send[nsidx].buff), send_vol, MPI_CHAR, nid, tag, mpi->mcomm, + &mpi->send[nsidx].status + ); nsidx += 1; } @@ -420,47 +436,47 @@ per_sync(struct gkyl_comm *comm, const struct gkyl_range *local, } // complete send - for (int s=0; ssend[s].range.volume; - if (issend) + if (issend) { MPI_Wait(&mpi->send[s].status, MPI_STATUS_IGNORE); + } } // complete recv, copying data into ghost-cells - for (int r=0; rrecv[r].range.volume; if (isrecv) { MPI_Wait(&mpi->recv[r].status, MPI_STATUS_IGNORE); - - gkyl_array_copy_from_buffer(array, - gkyl_mem_buff_data(mpi->recv[r].buff), - &(mpi->recv[r].range) + + gkyl_array_copy_from_buffer( + array, gkyl_mem_buff_data(mpi->recv[r].buff), &(mpi->recv[r].range) ); } } mpi->nrecv = nridx > mpi->nrecv ? nridx : mpi->nrecv; - + return 0; } -static int -array_per_sync(struct gkyl_comm *comm, const struct gkyl_range *local, - const struct gkyl_range *local_ext, - int nper_dirs, const int *per_dirs, struct gkyl_array *array) +static int array_per_sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + int nper_dirs, const int *per_dirs, struct gkyl_array *array +) { - struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); + struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); per_sync(comm, local, local_ext, nper_dirs, per_dirs, array, false); if (mpi->sync_corners) { - for (int i=1; idecomp->ndim; ++i) + for (int i = 1; i < mpi->decomp->ndim; ++i) { per_sync(comm, local, local_ext, nper_dirs, per_dirs, array, true); + } } - + return 0; } -static int -barrier(struct gkyl_comm *comm) +static int barrier(struct gkyl_comm *comm) { struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); MPI_Barrier(mpi->mcomm); @@ -468,12 +484,10 @@ barrier(struct gkyl_comm *comm) } // set of functions to help with parallel array output using MPI-IO -static void -sub_array_decomp_write(struct mpi_comm *comm, - const struct gkyl_rect_decomp *decomp, - const struct gkyl_range *range, - const struct gkyl_msgpack_data *meta, - const struct gkyl_array *arr, MPI_File fp) +static void sub_array_decomp_write( + struct mpi_comm *comm, const struct gkyl_rect_decomp *decomp, const struct gkyl_range *range, + const struct gkyl_msgpack_data *meta, const struct gkyl_array *arr, MPI_File fp +) { #define _F(loc) gkyl_array_cfetch(arr, loc) @@ -482,23 +496,23 @@ sub_array_decomp_write(struct mpi_comm *comm, // seek to appropriate place in the file, depending on rank size_t hdr_sz = gkyl_base_hdr_size(meta->meta_sz) + gkyl_file_type_3_hrd_size(range->ndim); - size_t file_loc = hdr_sz + - arr->esznc*comm->local_range_offset + - rank*gkyl_file_type_3_range_hrd_size(range->ndim); + size_t file_loc = hdr_sz + arr->esznc * comm->local_range_offset + + rank * gkyl_file_type_3_range_hrd_size(range->ndim); MPI_Offset fp_offset = file_loc; MPI_File_seek(fp, fp_offset, MPI_SEEK_SET); do { - char *buff; size_t buff_sz; + char *buff; + size_t buff_sz; FILE *fbuff = open_memstream(&buff, &buff_sz); - + uint64_t loidx[GKYL_MAX_DIM] = {0}, upidx[GKYL_MAX_DIM] = {0}; for (int d = 0; d < range->ndim; ++d) { loidx[d] = range->lower[d]; upidx[d] = range->upper[d]; } - + fwrite(loidx, sizeof(uint64_t), range->ndim, fbuff); fwrite(upidx, sizeof(uint64_t), range->ndim, fbuff); uint64_t sz = range->volume; @@ -510,7 +524,7 @@ sub_array_decomp_write(struct mpi_comm *comm, MPI_File_write(fp, buff, buff_sz, MPI_CHAR, &status); free(buff); - + } while (0); // construct skip iterator to allow writing (potentially) in chunks @@ -527,33 +541,32 @@ sub_array_decomp_write(struct mpi_comm *comm, MPI_Status status; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&skip.range, iter.idx); - MPI_File_write(fp, _F(start), arr->esznc*skip.delta, MPI_CHAR, &status); + MPI_File_write(fp, _F(start), arr->esznc * skip.delta, MPI_CHAR, &status); } #undef _F } -static int -grid_sub_array_decomp_write_fp(struct mpi_comm *comm, - const struct gkyl_rect_grid *grid, - const struct gkyl_rect_decomp *decomp, - const struct gkyl_range *range, - const struct gkyl_msgpack_data *meta, - const struct gkyl_array *arr, MPI_File fp) +static int grid_sub_array_decomp_write_fp( + struct mpi_comm *comm, const struct gkyl_rect_grid *grid, const struct gkyl_rect_decomp *decomp, + const struct gkyl_range *range, const struct gkyl_msgpack_data *meta, + const struct gkyl_array *arr, MPI_File fp +) { - char *buff; size_t buff_sz; + char *buff; + size_t buff_sz; FILE *fbuff = open_memstream(&buff, &buff_sz); // write header to a char buffer - gkyl_grid_sub_array_header_write_fp(grid, - &(struct gkyl_array_header_info) { - .file_type = gkyl_file_type_int[GKYL_MULTI_RANGE_DATA_FILE], + gkyl_grid_sub_array_header_write_fp( + grid, + &(struct gkyl_array_header_info + ){.file_type = gkyl_file_type_int[GKYL_MULTI_RANGE_DATA_FILE], .etype = arr->type, .esznc = arr->esznc, .tot_cells = decomp->parent_range.volume, .meta_size = meta ? meta->meta_sz : 0, - .meta = meta ? meta->meta : 0 - }, + .meta = meta ? meta->meta : 0}, fbuff ); uint64_t nrange = decomp->ndecomp; @@ -569,66 +582,57 @@ grid_sub_array_decomp_write_fp(struct mpi_comm *comm, } free(buff); - struct gkyl_msgpack_data zero_meta = (struct gkyl_msgpack_data) { - .meta_sz = 0, - .meta = 0 - }; - + struct gkyl_msgpack_data zero_meta = (struct gkyl_msgpack_data){.meta_sz = 0, .meta = 0}; + // write data in array - sub_array_decomp_write(comm, decomp, range, - meta ? meta : &zero_meta, - arr, fp); + sub_array_decomp_write(comm, decomp, range, meta ? meta : &zero_meta, arr, fp); return errno; } -static int array_write(struct gkyl_comm *comm, - const struct gkyl_rect_grid *grid, - const struct gkyl_range *range, - const struct gkyl_msgpack_data *meta, - const struct gkyl_array *arr, const char *fname) +static int array_write( + struct gkyl_comm *comm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + const struct gkyl_msgpack_data *meta, const struct gkyl_array *arr, const char *fname +) { struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); MPI_File fp; - int err = - MPI_File_open(mpi->mcomm, fname, MPI_MODE_CREATE|MPI_MODE_WRONLY, MPI_INFO_NULL, &fp); - if (err != MPI_SUCCESS) + int err = MPI_File_open(mpi->mcomm, fname, MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &fp); + if (err != MPI_SUCCESS) { return err; + } err = grid_sub_array_decomp_write_fp(mpi, grid, mpi->decomp, range, meta, arr, fp); MPI_File_close(&fp); return err; } -static int -array_read(struct gkyl_comm *comm, - const struct gkyl_rect_grid *grid, const struct gkyl_range *range, - struct gkyl_array *arr, const char *fname) +static int array_read( + struct gkyl_comm *comm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + struct gkyl_array *arr, const char *fname +) { struct gkyl_rect_grid fgrid; int status = gkyl_grid_sub_array_read(&fgrid, range, arr, fname); if (status == 0) { - if (!gkyl_rect_grid_cmp(grid, &fgrid)) + if (!gkyl_rect_grid_cmp(grid, &fgrid)) { status = 1; + } } return status; } -static struct gkyl_comm* -extend_comm(const struct gkyl_comm *comm, const struct gkyl_range *erange) +static struct gkyl_comm *extend_comm(const struct gkyl_comm *comm, const struct gkyl_range *erange) { struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); // extend internal decomp object and create a new communicator struct gkyl_rect_decomp *ext_decomp = gkyl_rect_decomp_extended_new(erange, mpi->decomp); - struct gkyl_comm *ext_comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = mpi->mcomm, - .decomp = ext_decomp - } - ); + struct gkyl_comm *ext_comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = mpi->mcomm, .decomp = ext_decomp}); gkyl_rect_decomp_release(ext_decomp); return ext_comm; } -static struct gkyl_comm* +static struct gkyl_comm * split_comm(const struct gkyl_comm *comm, int color, struct gkyl_rect_decomp *new_decomp) { struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); @@ -638,18 +642,14 @@ split_comm(const struct gkyl_comm *comm, int color, struct gkyl_rect_decomp *new int ret = MPI_Comm_split(mpi->mcomm, color, rank, &new_mcomm); assert(ret == MPI_SUCCESS); - return gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = new_mcomm, - .sync_corners = mpi->sync_corners, - .decomp = new_decomp, - } - ); + return gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = new_mcomm, .sync_corners = mpi->sync_corners, .decomp = new_decomp}); } -static struct gkyl_comm* -create_comm_from_ranks(const struct gkyl_comm *comm, - int nranks, const int *ranks, struct gkyl_rect_decomp *new_decomp, - bool *is_valid) +static struct gkyl_comm *create_comm_from_ranks( + const struct gkyl_comm *comm, int nranks, const int *ranks, struct gkyl_rect_decomp *new_decomp, + bool *is_valid +) { struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); @@ -667,45 +667,37 @@ create_comm_from_ranks(const struct gkyl_comm *comm, if (MPI_COMM_NULL != new_mcomm) { *is_valid = true; - new_comm = mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = new_mcomm, - .sync_corners = mpi->sync_corners, - .decomp = new_decomp, - }, - &(struct extra_mpi_comm_inp) { - .is_comm_allocated = true - } + new_comm = mpi_comm_new( + &(struct gkyl_mpi_comm_inp + ){.mpi_comm = new_mcomm, .sync_corners = mpi->sync_corners, .decomp = new_decomp}, + &(struct extra_mpi_comm_inp){.is_comm_allocated = true} ); } MPI_Group_free(&group); MPI_Group_free(&new_group); - + return new_comm; } -static struct gkyl_comm_state * -comm_state_new(struct gkyl_comm *comm) +static struct gkyl_comm_state *comm_state_new(struct gkyl_comm *comm) { struct gkyl_comm_state *state = gkyl_malloc(sizeof *state); return state; } -static void -comm_state_release(struct gkyl_comm_state *state) +static void comm_state_release(struct gkyl_comm_state *state) { gkyl_free(state); } -static void -comm_state_wait(struct gkyl_comm_state *state) +static void comm_state_wait(struct gkyl_comm_state *state) { MPI_Wait(&state->req, &state->stat); } -static struct gkyl_comm* -mpi_comm_new(const struct gkyl_mpi_comm_inp *inp, - const struct extra_mpi_comm_inp *extra_inp) +static struct gkyl_comm * +mpi_comm_new(const struct gkyl_mpi_comm_inp *inp, const struct extra_mpi_comm_inp *extra_inp) { struct mpi_comm *mpi = gkyl_malloc(sizeof *mpi); strcpy(mpi->priv_comm.pub_comm.id, "mpi_comm"); @@ -720,13 +712,11 @@ mpi_comm_new(const struct gkyl_mpi_comm_inp *inp, mpi->priv_comm.pub_comm.has_decomp = true; if (0 == inp->decomp) { mpi->priv_comm.pub_comm.has_decomp = false; - + // construct a dummy decomposition mpi->decomp = - gkyl_rect_decomp_new_from_cuts_and_cells(1, - (int[]) { comm_size }, (int[]) { comm_size }); - } - else { + gkyl_rect_decomp_new_from_cuts_and_cells(1, (int[]){comm_size}, (int[]){comm_size}); + } else { mpi->decomp = gkyl_rect_decomp_acquire(inp->decomp); } @@ -738,44 +728,46 @@ mpi_comm_new(const struct gkyl_mpi_comm_inp *inp, // NOTE: we are not computing corner neighbors as the corner syncs // are handled by two calls to sync method instead mpi->neigh = gkyl_rect_decomp_calc_neigh(mpi->decomp, false, rank); - - for (int d=0; ddecomp->ndim; ++d) + + for (int d = 0; d < mpi->decomp->ndim; ++d) { // NOTE: we are not computing corner periodic neighbors as the // corner syncs are handled by two calls to periodic sync method // instead - mpi->per_neigh[d] = - gkyl_rect_decomp_calc_periodic_neigh(mpi->decomp, d, false, rank); - - gkyl_range_init(&mpi->dir_edge, 2, (int[]) { 0, 0 }, (int[]) { GKYL_MAX_DIM, 2 }); - + mpi->per_neigh[d] = gkyl_rect_decomp_calc_periodic_neigh(mpi->decomp, d, false, rank); + } + + gkyl_range_init(&mpi->dir_edge, 2, (int[]){0, 0}, (int[]){GKYL_MAX_DIM, 2}); + int num_touches = 0; - for (int d=0; ddecomp->ndim; ++d) { - mpi->is_on_edge[0][d] = gkyl_range_is_on_lower_edge( - d, &mpi->decomp->ranges[rank], &mpi->decomp->parent_range); - mpi->is_on_edge[1][d] = gkyl_range_is_on_upper_edge( - d, &mpi->decomp->ranges[rank], &mpi->decomp->parent_range); + for (int d = 0; d < mpi->decomp->ndim; ++d) { + mpi->is_on_edge[0][d] = + gkyl_range_is_on_lower_edge(d, &mpi->decomp->ranges[rank], &mpi->decomp->parent_range); + mpi->is_on_edge[1][d] = + gkyl_range_is_on_upper_edge(d, &mpi->decomp->ranges[rank], &mpi->decomp->parent_range); num_touches += mpi->is_on_edge[0][d] + mpi->is_on_edge[1][d]; } mpi->touches_any_edge = num_touches > 0 ? true : false; - + mpi->nrecv = 0; - for (int i=0; irecv[i].buff = gkyl_mem_buff_new(16); - + } + mpi->nsend = 0; - for (int i=0; isend[i].buff = gkyl_mem_buff_new(16); - + } + mpi->allgather_buff_local.buff = gkyl_mem_buff_new(16); mpi->allgather_buff_global.buff = gkyl_mem_buff_new(16); - + mpi->priv_comm.gkyl_array_sync = array_sync; mpi->priv_comm.gkyl_array_per_sync = array_per_sync; mpi->priv_comm.gkyl_array_write = array_write; mpi->priv_comm.gkyl_array_read = array_read; mpi->priv_comm.gkyl_array_allgather = array_allgather; mpi->priv_comm.gkyl_array_allgather_host = array_allgather; - + mpi->priv_comm.get_rank = get_rank; mpi->priv_comm.get_size = get_size; mpi->priv_comm.barrier = barrier; @@ -786,19 +778,15 @@ mpi_comm_new(const struct gkyl_mpi_comm_inp *inp, mpi->priv_comm.extend_comm = extend_comm; mpi->priv_comm.split_comm = split_comm; mpi->priv_comm.create_comm_from_ranks = create_comm_from_ranks; - + mpi->priv_comm.pub_comm.ref_count = gkyl_ref_count_init(comm_free); return &mpi->priv_comm.pub_comm; } -struct gkyl_comm* -gkyl_mpi_comm_new(const struct gkyl_mpi_comm_inp *inp) +struct gkyl_comm *gkyl_mpi_comm_new(const struct gkyl_mpi_comm_inp *inp) { - return mpi_comm_new(inp, &(struct extra_mpi_comm_inp) { - .is_comm_allocated = false - } - ); + return mpi_comm_new(inp, &(struct extra_mpi_comm_inp){.is_comm_allocated = false}); } #endif diff --git a/core/zero/multib_comm_conn.c b/core/zero/multib_comm_conn.c index e6067065c6..d08e349717 100644 --- a/core/zero/multib_comm_conn.c +++ b/core/zero/multib_comm_conn.c @@ -10,14 +10,14 @@ struct multib_comm_conn { struct gkyl_multib_comm_conn mcc; }; -static void -multib_comm_conn_free(const struct gkyl_ref_count *ref) +static void multib_comm_conn_free(const struct gkyl_ref_count *ref) { struct gkyl_multib_comm_conn *mcc = container_of(ref, struct gkyl_multib_comm_conn, ref_count); struct multib_comm_conn *cconn = container_of(mcc, struct multib_comm_conn, mcc); - if (cconn->mcc.num_comm_conn > 0) + if (cconn->mcc.num_comm_conn > 0) { gkyl_free(cconn->mcc.comm_conn); + } gkyl_free(cconn); } @@ -28,30 +28,30 @@ gkyl_multib_comm_conn_new(int num, const struct gkyl_comm_conn *comm_conn) cconn->mcc.num_comm_conn = num; cconn->mcc.comm_conn = 0; - if (num > 0) + if (num > 0) { cconn->mcc.comm_conn = gkyl_malloc(sizeof(struct gkyl_comm_conn[num])); + } - for (int i=0; imcc.comm_conn[i], &comm_conn[i], sizeof(struct gkyl_comm_conn)); + } cconn->mcc.ref_count = gkyl_ref_count_init(multib_comm_conn_free); return &cconn->mcc; } - // private method to compute send/recv connections -static struct gkyl_multib_comm_conn * -multib_comm_conn_new_sr(enum multib_send_recv sr, - int block_id, int block_rank, const int *nghost, - const struct gkyl_block_connections *block_conn, struct gkyl_rect_decomp **decomp) +static struct gkyl_multib_comm_conn *multib_comm_conn_new_sr( + enum multib_send_recv sr, int block_id, int block_rank, const int *nghost, + const struct gkyl_block_connections *block_conn, struct gkyl_rect_decomp **decomp +) { int ndim = decomp[0]->ndim; - // determine maximum number of ranks we can send/recv data + // determine maximum number of ranks we can send/recv data int max_sr_ranks = 0; - for (int d=0; dconnections[d][e].edge != GKYL_PHYSICAL) { int nranks = decomp[block_conn->connections[d][e].bid]->ndecomp; max_sr_ranks += nranks; @@ -60,21 +60,19 @@ multib_comm_conn_new_sr(enum multib_send_recv sr, } int comm_conn_idx = 0; - struct gkyl_comm_conn *comm_conn - = gkyl_malloc(sizeof(struct gkyl_comm_conn[max_sr_ranks])); + struct gkyl_comm_conn *comm_conn = gkyl_malloc(sizeof(struct gkyl_comm_conn[max_sr_ranks])); const struct gkyl_range *src_pr = &decomp[block_id]->parent_range; const struct gkyl_range *src_br = &decomp[block_id]->ranges[block_rank]; - for (int dir=0; dirconnections[dir][e].bid; int tar_dir = block_conn->connections[dir][e].dir; enum gkyl_oriented_edge tar_edge = block_conn->connections[dir][e].edge; - enum gkyl_oriented_edge src_edge = e == 0? GKYL_LOWER_POSITIVE : GKYL_UPPER_POSITIVE; + enum gkyl_oriented_edge src_edge = e == 0 ? GKYL_LOWER_POSITIVE : GKYL_UPPER_POSITIVE; if (block_conn->connections[dir][e].edge != GKYL_PHYSICAL) { - const struct gkyl_rect_decomp *tar_decomp = decomp[tar_bid]; // to find intersection with the neighbor we first need to get // the neigbor block into the index-space to source block: we @@ -83,50 +81,56 @@ multib_comm_conn_new_sr(enum multib_send_recv sr, const struct gkyl_range *tar_pr = &tar_decomp->parent_range; int new_lower[GKYL_MAX_DIM]; - for (int d=0; dlower[d]; + } - if (GKYL_UPPER_EDGE == e) + if (GKYL_UPPER_EDGE == e) { new_lower[dir] += gkyl_range_shape(src_pr, dir); - else + } else { new_lower[dir] -= gkyl_range_shape(tar_pr, dir); - + } + struct gkyl_range reset_tar_pr; gkyl_range_reset_lower(&reset_tar_pr, tar_pr, new_lower); - int delta[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dlower[d]; + } - int minus_delta[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndecomp; ++nn) { + for (int nn = 0; nn < tar_decomp->ndecomp; ++nn) { struct gkyl_range sub_range; gkyl_range_shift(&sub_range, &tar_decomp->ranges[nn], delta); - int elo[GKYL_MAX_DIM] = { 0 }, eup[GKYL_MAX_DIM] = { 0 }; - elo[dir] = eup[dir] = nghost[dir]; // only extend in 1 direction + int elo[GKYL_MAX_DIM] = {0}, eup[GKYL_MAX_DIM] = {0}; + elo[dir] = eup[dir] = nghost[dir]; // only extend in 1 direction struct gkyl_range range_ext; - if (GKYL_COMM_CONN_SEND == sr) + if (GKYL_COMM_CONN_SEND == sr) { gkyl_range_extend(&range_ext, &sub_range, elo, eup); - else + } else { gkyl_range_extend(&range_ext, src_br, elo, eup); + } int is_inter; struct gkyl_range irng; - if (GKYL_COMM_CONN_SEND == sr) + if (GKYL_COMM_CONN_SEND == sr) { is_inter = gkyl_range_intersect(&irng, &range_ext, src_br); - else + } else { is_inter = gkyl_range_intersect(&irng, &range_ext, &sub_range); - + } + if (is_inter) { comm_conn[comm_conn_idx].sr = sr; comm_conn[comm_conn_idx].rank = nn; @@ -138,23 +142,22 @@ multib_comm_conn_new_sr(enum multib_send_recv sr, comm_conn_idx += 1; } } - } } } } - struct gkyl_multib_comm_conn *mbcc = - gkyl_multib_comm_conn_new(comm_conn_idx, comm_conn); + struct gkyl_multib_comm_conn *mbcc = gkyl_multib_comm_conn_new(comm_conn_idx, comm_conn); gkyl_free(comm_conn); - + return mbcc; } -void -gkyl_multib_comm_conn_create_multib_ranges_in_dir(struct gkyl_range *multib_range_ext, struct gkyl_range *multib_range, - const int *nghost, int nconnected, int* block_list, int dir, struct gkyl_rect_decomp **decomp) +void gkyl_multib_comm_conn_create_multib_ranges_in_dir( + struct gkyl_range *multib_range_ext, struct gkyl_range *multib_range, const int *nghost, + int nconnected, int *block_list, int dir, struct gkyl_rect_decomp **decomp +) { // Construct the multib range which spans all the parent ranges // Block list is always in order in dir @@ -162,11 +165,11 @@ gkyl_multib_comm_conn_create_multib_ranges_in_dir(struct gkyl_range *multib_rang int ndim = decomp[0]->ndim; int multib_lower[GKYL_MAX_DIM]; int multib_upper[GKYL_MAX_DIM]; - for (int i =0; iparent_range.lower[i]; multib_upper[i] = decomp[block_list[0]]->parent_range.upper[i]; } - for (int i=1; iparent_range, dir); } struct gkyl_range multib_rng; @@ -175,51 +178,58 @@ gkyl_multib_comm_conn_create_multib_ranges_in_dir(struct gkyl_range *multib_rang } // public method to compute send connections from block list -struct gkyl_multib_comm_conn * -gkyl_multib_comm_conn_new_send_from_connections( - int block_id, int block_rank, const int *nghost, - int nconnected, int* block_list, int dir, - struct gkyl_rect_decomp **decomp) +struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new_send_from_connections( + int block_id, int block_rank, const int *nghost, int nconnected, int *block_list, int dir, + struct gkyl_rect_decomp **decomp +) { int ndim = decomp[0]->ndim; - // determine maximum number of ranks we can send/recv data + // determine maximum number of ranks we can send/recv data int max_sr_ranks = 0; - for (int i=0; indecomp; max_sr_ranks += nranks; } int comm_conn_idx = 0; - struct gkyl_comm_conn *comm_conn - = gkyl_malloc(sizeof(struct gkyl_comm_conn[max_sr_ranks])); + struct gkyl_comm_conn *comm_conn = gkyl_malloc(sizeof(struct gkyl_comm_conn[max_sr_ranks])); const struct gkyl_range *src_parent_range = &decomp[block_id]->parent_range; const struct gkyl_range *src_block_range = &decomp[block_id]->ranges[block_rank]; struct gkyl_range cross_range, cross_range_ext; - gkyl_multib_comm_conn_create_multib_ranges_in_dir(&cross_range_ext, &cross_range, nghost, nconnected, block_list, dir, decomp); + gkyl_multib_comm_conn_create_multib_ranges_in_dir( + &cross_range_ext, &cross_range, nghost, nconnected, block_list, dir, decomp + ); // Get block indices into the index space of the cross range int new_lower[GKYL_MAX_DIM]; - for (int d=0; dlower[d]; + } int source_idx = -1; - for(int i=0; iparent_range, dir); } - + struct gkyl_range reset_src_parent_range; gkyl_range_reset_lower(&reset_src_parent_range, src_parent_range, new_lower); - int delta[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dlower[d]; + } - int minus_delta[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndecomp; - for (int ir=0; irndim; - // determine maximum number of ranks we can send/recv data + // determine maximum number of ranks we can send/recv data int max_sr_ranks = 0; - for (int i=0; indecomp; max_sr_ranks += nranks; } int comm_conn_idx = 0; - struct gkyl_comm_conn *comm_conn - = gkyl_malloc(sizeof(struct gkyl_comm_conn[max_sr_ranks])); + struct gkyl_comm_conn *comm_conn = gkyl_malloc(sizeof(struct gkyl_comm_conn[max_sr_ranks])); const struct gkyl_range *src_parent_range = &decomp[block_id]->parent_range; const struct gkyl_range *src_block_range = &decomp[block_id]->ranges[block_rank]; struct gkyl_range cross_range, cross_range_ext; - gkyl_multib_comm_conn_create_multib_ranges_in_dir(&cross_range_ext, &cross_range, nghost, nconnected, block_list, dir, decomp); + gkyl_multib_comm_conn_create_multib_ranges_in_dir( + &cross_range_ext, &cross_range, nghost, nconnected, block_list, dir, decomp + ); // Need to get other block indices into the index space of the cross range - for (int ib=0; ibparent_range; int new_lower[GKYL_MAX_DIM]; - for (int d=0; dlower[d]; + } int tar_idx = -1; - for(int i=0; iparent_range, dir); } - + struct gkyl_range reset_tar_parent_range; gkyl_range_reset_lower(&reset_tar_parent_range, tar_parent_range, new_lower); - int delta[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dlower[d]; + } - int minus_delta[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndecomp; - for (int ir=0; irranges[ir]; struct gkyl_range sub_range; gkyl_range_shift(&sub_range, tar_block_range, delta); @@ -324,115 +340,120 @@ gkyl_multib_comm_conn_new_recv_from_connections( } } } - struct gkyl_multib_comm_conn *mbcc = - gkyl_multib_comm_conn_new(comm_conn_idx, comm_conn); + struct gkyl_multib_comm_conn *mbcc = gkyl_multib_comm_conn_new(comm_conn_idx, comm_conn); gkyl_free(comm_conn); - + return mbcc; } -struct gkyl_multib_comm_conn * -gkyl_multib_comm_conn_new_send( - int block_id, int block_rank, const int *nghost, - const struct gkyl_block_connections *block_conn, struct gkyl_rect_decomp **decomp) +struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new_send( + int block_id, int block_rank, const int *nghost, const struct gkyl_block_connections *block_conn, + struct gkyl_rect_decomp **decomp +) { - return multib_comm_conn_new_sr(GKYL_COMM_CONN_SEND, block_id, block_rank, nghost, block_conn, decomp); + return multib_comm_conn_new_sr( + GKYL_COMM_CONN_SEND, block_id, block_rank, nghost, block_conn, decomp + ); } -struct gkyl_multib_comm_conn * -gkyl_multib_comm_conn_new_recv( - int block_id, int block_rank, const int *nghost, - const struct gkyl_block_connections *block_conn, struct gkyl_rect_decomp **decomp) +struct gkyl_multib_comm_conn *gkyl_multib_comm_conn_new_recv( + int block_id, int block_rank, const int *nghost, const struct gkyl_block_connections *block_conn, + struct gkyl_rect_decomp **decomp +) { - return multib_comm_conn_new_sr(GKYL_COMM_CONN_RECV, block_id, block_rank, nghost, block_conn, decomp); + return multib_comm_conn_new_sr( + GKYL_COMM_CONN_RECV, block_id, block_rank, nghost, block_conn, decomp + ); } -int -gkyl_multib_comm_conn_array_transfer(struct gkyl_comm *comm, int num_blocks_local, const int *blocks_local, +int gkyl_multib_comm_conn_array_transfer( + struct gkyl_comm *comm, int num_blocks_local, const int *blocks_local, struct gkyl_multib_comm_conn **mbcc_send, struct gkyl_multib_comm_conn **mbcc_recv, - struct gkyl_array **arr_send, struct gkyl_array **arr_recv) + struct gkyl_array **arr_send, struct gkyl_array **arr_recv +) { int err; if (strcmp(comm->id, "null_comm") == 0) { - err = gkyl_multib_comm_conn_array_transfer_null(comm, num_blocks_local, blocks_local, - mbcc_send, mbcc_recv, arr_send, arr_recv); - } - else if (strcmp(comm->id, "mpi_comm") == 0) { - err = gkyl_multib_comm_conn_array_transfer_mpi(comm, num_blocks_local, blocks_local, - mbcc_send, mbcc_recv, arr_send, arr_recv); - } - else if (strcmp(comm->id, "nccl_comm") == 0) { - err = gkyl_multib_comm_conn_array_transfer_nccl(comm, num_blocks_local, blocks_local, - mbcc_send, mbcc_recv, arr_send, arr_recv); - } - else + err = gkyl_multib_comm_conn_array_transfer_null( + comm, num_blocks_local, blocks_local, mbcc_send, mbcc_recv, arr_send, arr_recv + ); + } else if (strcmp(comm->id, "mpi_comm") == 0) { + err = gkyl_multib_comm_conn_array_transfer_mpi( + comm, num_blocks_local, blocks_local, mbcc_send, mbcc_recv, arr_send, arr_recv + ); + } else if (strcmp(comm->id, "nccl_comm") == 0) { + err = gkyl_multib_comm_conn_array_transfer_nccl( + comm, num_blocks_local, blocks_local, mbcc_send, mbcc_recv, arr_send, arr_recv + ); + } else { assert(false); + } return err; } -static void -swap_comm_conns(struct gkyl_comm_conn *ccj, struct gkyl_comm_conn *cck) +static void swap_comm_conns(struct gkyl_comm_conn *ccj, struct gkyl_comm_conn *cck) { struct gkyl_comm_conn cc_tmp = *ccj; *ccj = *cck; *cck = cc_tmp; } -void -gkyl_multib_comm_conn_sort(struct gkyl_multib_comm_conn *mbcc) +void gkyl_multib_comm_conn_sort(struct gkyl_multib_comm_conn *mbcc) { int num_conn = mbcc->num_comm_conn; // First sort connections in ascending rank (w/ bubble sort). - for (int i=0; icomm_conn[j], *cjp1 = &mbcc->comm_conn[j+1]; + for (int j = 0; j < num_conn - i - 1; j++) { + struct gkyl_comm_conn *cj = &mbcc->comm_conn[j], *cjp1 = &mbcc->comm_conn[j + 1]; if (cj->rank > cjp1->rank) { swap_comm_conns(cj, cjp1); swapped = true; } } - if (swapped == false) + if (swapped == false) { break; // Stop if no swaps happened. + } } // Now sort connections in ascending block ID. - for (int i=0; icomm_conn[j], *cjp1 = &mbcc->comm_conn[j+1]; + for (int j = 0; j < num_conn - i - 1; j++) { + struct gkyl_comm_conn *cj = &mbcc->comm_conn[j], *cjp1 = &mbcc->comm_conn[j + 1]; if ((cj->rank == cjp1->rank) && (cj->block_id > cjp1->block_id)) { swap_comm_conns(cj, cjp1); swapped = true; } } - if (swapped == false) + if (swapped == false) { break; // Stop if no swaps happened. + } } // Now sort connections in ascending tar/src edge if receiver/sender - for (int i=0; icomm_conn[j], *cjp1 = &mbcc->comm_conn[j+1]; + for (int j = 0; j < num_conn - i - 1; j++) { + struct gkyl_comm_conn *cj = &mbcc->comm_conn[j], *cjp1 = &mbcc->comm_conn[j + 1]; int edge = cj->sr == GKYL_COMM_CONN_SEND ? cj->src_edge : cj->tar_edge; int edgep1 = cjp1->sr == GKYL_COMM_CONN_SEND ? cjp1->src_edge : cjp1->tar_edge; - if ((cj->rank == cjp1->rank) && (cj->block_id == cjp1->block_id) && (edge > edgep1) ) { + if ((cj->rank == cjp1->rank) && (cj->block_id == cjp1->block_id) && (edge > edgep1)) { swap_comm_conns(cj, cjp1); swapped = true; } } - if (swapped == false) + if (swapped == false) { break; // Stop if no swaps happened. + } } - } -void -gkyl_multib_comm_conn_release(const struct gkyl_multib_comm_conn *cconn) +void gkyl_multib_comm_conn_release(const struct gkyl_multib_comm_conn *cconn) { - if (cconn) + if (cconn) { gkyl_ref_count_dec(&cconn->ref_count); + } } diff --git a/core/zero/multib_comm_conn_mpi.c b/core/zero/multib_comm_conn_mpi.c index 69a6825ac1..ec9d2ee63c 100644 --- a/core/zero/multib_comm_conn_mpi.c +++ b/core/zero/multib_comm_conn_mpi.c @@ -5,10 +5,11 @@ #include -int -gkyl_multib_comm_conn_array_transfer_mpi(struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, +int gkyl_multib_comm_conn_array_transfer_mpi( + struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, struct gkyl_multib_comm_conn **mbcc_send, struct gkyl_multib_comm_conn **mbcc_recv, - struct gkyl_array **arr_send, struct gkyl_array **arr_recv) + struct gkyl_array **arr_send, struct gkyl_array **arr_recv +) { struct mpi_comm *mpi = container_of(comm, struct mpi_comm, priv_comm.pub_comm); @@ -17,26 +18,29 @@ gkyl_multib_comm_conn_array_transfer_mpi(struct gkyl_comm *comm, int num_blocks_ int tag = MPI_BASE_TAG; - // post nonblocking recv to get data into ghost-cells + // post nonblocking recv to get data into ghost-cells int nridx = 0; - for (int bI=0; bInum_comm_conn; ++n) { + for (int n = 0; n < mbcc_r->num_comm_conn; ++n) { int nid = mbcc_r->comm_conn[n].rank; int bid = mbcc_r->comm_conn[n].block_id; int e = mbcc_r->comm_conn[n].tar_edge; - - size_t recv_vol = arr_recv[bI]->esznc*mbcc_r->comm_conn[n].range.volume; - if (recv_vol>0) { - if (gkyl_mem_buff_size(mpi->recv[nridx].buff) < recv_vol) + size_t recv_vol = arr_recv[bI]->esznc * mbcc_r->comm_conn[n].range.volume; + + if (recv_vol > 0) { + if (gkyl_mem_buff_size(mpi->recv[nridx].buff) < recv_vol) { gkyl_mem_buff_resize(mpi->recv[nridx].buff, recv_vol); + } - int rtag = tag + 1000*nid + 100*e + bid; + int rtag = tag + 1000 * nid + 100 * e + bid; - MPI_Irecv(gkyl_mem_buff_data(mpi->recv[nridx].buff), - recv_vol, MPI_CHAR, nid, rtag, mpi->mcomm, &mpi->recv[nridx].status); + MPI_Irecv( + gkyl_mem_buff_data(mpi->recv[nridx].buff), recv_vol, MPI_CHAR, nid, rtag, mpi->mcomm, + &mpi->recv[nridx].status + ); nridx += 1; } @@ -45,26 +49,30 @@ gkyl_multib_comm_conn_array_transfer_mpi(struct gkyl_comm *comm, int num_blocks_ // post non-blocking sends of skin-cell data to neighbors int nsidx = 0; - for (int bI=0; bInum_comm_conn; ++n) { + for (int n = 0; n < mbcc_s->num_comm_conn; ++n) { int nid = mbcc_s->comm_conn[n].rank; int e = mbcc_s->comm_conn[n].src_edge; - - size_t send_vol = arr_send[bI]->esznc*mbcc_s->comm_conn[n].range.volume; - if (send_vol>0) { - if (gkyl_mem_buff_size(mpi->send[nsidx].buff) < send_vol) + size_t send_vol = arr_send[bI]->esznc * mbcc_s->comm_conn[n].range.volume; + + if (send_vol > 0) { + if (gkyl_mem_buff_size(mpi->send[nsidx].buff) < send_vol) { gkyl_mem_buff_resize(mpi->send[nsidx].buff, send_vol); - - gkyl_array_copy_to_buffer(gkyl_mem_buff_data(mpi->send[nsidx].buff), - arr_send[bI], &mbcc_s->comm_conn[n].range); + } + + gkyl_array_copy_to_buffer( + gkyl_mem_buff_data(mpi->send[nsidx].buff), arr_send[bI], &mbcc_s->comm_conn[n].range + ); - int stag = tag + 1000*my_rank + 100*e + local_blocks[bI]; + int stag = tag + 1000 * my_rank + 100 * e + local_blocks[bI]; - MPI_Isend(gkyl_mem_buff_data(mpi->send[nsidx].buff), - send_vol, MPI_CHAR, nid, stag, mpi->mcomm, &mpi->send[nsidx].status); + MPI_Isend( + gkyl_mem_buff_data(mpi->send[nsidx].buff), send_vol, MPI_CHAR, nid, stag, mpi->mcomm, + &mpi->send[nsidx].status + ); nsidx += 1; } @@ -73,9 +81,9 @@ gkyl_multib_comm_conn_array_transfer_mpi(struct gkyl_comm *comm, int num_blocks_ // complete send nsidx = 0; - for (int bI=0; bInum_comm_conn; ++n) { + for (int n = 0; n < mbcc_s->num_comm_conn; ++n) { int issend = mbcc_s->comm_conn[n].range.volume; if (issend) { MPI_Wait(&mpi->send[nsidx].status, MPI_STATUS_IGNORE); @@ -86,32 +94,32 @@ gkyl_multib_comm_conn_array_transfer_mpi(struct gkyl_comm *comm, int num_blocks_ // complete recv, copying data into ghost-cells nridx = 0; - for (int bI=0; bInum_comm_conn; ++n) { + for (int n = 0; n < mbcc_r->num_comm_conn; ++n) { int isrecv = mbcc_r->comm_conn[n].range.volume; if (isrecv) { MPI_Wait(&mpi->recv[nridx].status, MPI_STATUS_IGNORE); - - gkyl_array_copy_from_buffer(arr_recv[bI], - gkyl_mem_buff_data(mpi->recv[nridx].buff), - &(mbcc_r->comm_conn[n].range) + + gkyl_array_copy_from_buffer( + arr_recv[bI], gkyl_mem_buff_data(mpi->recv[nridx].buff), &(mbcc_r->comm_conn[n].range) ); nridx += 1; } } } - + return 0; } -#else +#else -int -gkyl_multib_comm_conn_array_transfer_mpi(struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, +int gkyl_multib_comm_conn_array_transfer_mpi( + struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, struct gkyl_multib_comm_conn **mbcc_send, struct gkyl_multib_comm_conn **mbcc_recv, - struct gkyl_array **arr_send, struct gkyl_array **arr_recv) + struct gkyl_array **arr_send, struct gkyl_array **arr_recv +) { return 1; } diff --git a/core/zero/multib_comm_conn_nccl.c b/core/zero/multib_comm_conn_nccl.c index 912ea30a93..bc90719388 100644 --- a/core/zero/multib_comm_conn_nccl.c +++ b/core/zero/multib_comm_conn_nccl.c @@ -5,10 +5,11 @@ #include -int -gkyl_multib_comm_conn_array_transfer_nccl(struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, +int gkyl_multib_comm_conn_array_transfer_nccl( + struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, struct gkyl_multib_comm_conn **mbcc_send, struct gkyl_multib_comm_conn **mbcc_recv, - struct gkyl_array **arr_send, struct gkyl_array **arr_recv) + struct gkyl_array **arr_send, struct gkyl_array **arr_recv +) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); @@ -17,26 +18,29 @@ gkyl_multib_comm_conn_array_transfer_nccl(struct gkyl_comm *comm, int num_blocks checkNCCL(ncclGroupStart()); - // post nonblocking recv to get data into ghost-cells + // post nonblocking recv to get data into ghost-cells int nridx = 0; - for (int bI=0; bInum_comm_conn; ++nr) { + for (int nr = 0; nr < mbcc_r->num_comm_conn; ++nr) { int nid = mbcc_r->comm_conn[nr].rank; if (nid != my_rank) { int bid = mbcc_r->comm_conn[nr].block_id; - - size_t recv_vol = arr_recv[bI]->esznc*mbcc_r->comm_conn[nr].range.volume; - - if (recv_vol>0) { - if (gkyl_mem_buff_size(nccl->recv[nridx].buff) < recv_vol) + + size_t recv_vol = arr_recv[bI]->esznc * mbcc_r->comm_conn[nr].range.volume; + + if (recv_vol > 0) { + if (gkyl_mem_buff_size(nccl->recv[nridx].buff) < recv_vol) { gkyl_mem_buff_resize(nccl->recv[nridx].buff, recv_vol); - - checkNCCL(ncclRecv(gkyl_mem_buff_data(nccl->recv[nridx].buff), - recv_vol, ncclChar, nid, nccl->ncomm, nccl->custream)); - + } + + checkNCCL(ncclRecv( + gkyl_mem_buff_data(nccl->recv[nridx].buff), recv_vol, ncclChar, nid, nccl->ncomm, + nccl->custream + )); + nridx += 1; } } @@ -45,24 +49,28 @@ gkyl_multib_comm_conn_array_transfer_nccl(struct gkyl_comm *comm, int num_blocks // post non-blocking sends of skin-cell data to neighbors int nsidx = 0; - for (int bI=0; bInum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_s->num_comm_conn; ++ns) { int nid = mbcc_s->comm_conn[ns].rank; if (nid != my_rank) { - size_t send_vol = arr_send[bI]->esznc*mbcc_s->comm_conn[ns].range.volume; + size_t send_vol = arr_send[bI]->esznc * mbcc_s->comm_conn[ns].range.volume; - if (send_vol>0) { - if (gkyl_mem_buff_size(nccl->send[nsidx].buff) < send_vol) + if (send_vol > 0) { + if (gkyl_mem_buff_size(nccl->send[nsidx].buff) < send_vol) { gkyl_mem_buff_resize(nccl->send[nsidx].buff, send_vol); - - gkyl_array_copy_to_buffer(gkyl_mem_buff_data(nccl->send[nsidx].buff), - arr_send[bI], &mbcc_s->comm_conn[ns].range); + } + + gkyl_array_copy_to_buffer( + gkyl_mem_buff_data(nccl->send[nsidx].buff), arr_send[bI], &mbcc_s->comm_conn[ns].range + ); - checkNCCL(ncclSend(gkyl_mem_buff_data(nccl->send[nsidx].buff), - send_vol, ncclChar, nid, nccl->ncomm, nccl->custream)); + checkNCCL(ncclSend( + gkyl_mem_buff_data(nccl->send[nsidx].buff), send_vol, ncclChar, nid, nccl->ncomm, + nccl->custream + )); nsidx += 1; } @@ -74,11 +82,11 @@ gkyl_multib_comm_conn_array_transfer_nccl(struct gkyl_comm *comm, int num_blocks // Simply do a copy for the connections whose rank is the same as my rank. // This is the same code in gkyl_multib_comm_conn_array_transfer_null. - for (int bI=0; bInum_comm_conn; ++nr) { + for (int nr = 0; nr < mbcc_r->num_comm_conn; ++nr) { int nid = mbcc_r->comm_conn[nr].rank; if (nid == my_rank) { @@ -89,7 +97,7 @@ gkyl_multib_comm_conn_array_transfer_nccl(struct gkyl_comm *comm, int num_blocks // The send connections may not be ordered in the same way as the recvs. // Loop over the send connections and find the one from the same block. int bid_src_idx = -1; - for (int cI=0; cInum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_s->num_comm_conn; ++ns) { if (mbcc_s->comm_conn[ns].block_id == bid && mbcc_s->comm_conn[ns].src_edge == e) { conn_src_idx = ns; break; @@ -115,21 +123,20 @@ gkyl_multib_comm_conn_array_transfer_nccl(struct gkyl_comm *comm, int num_blocks ncclResult_t nstat; do { checkNCCL(ncclCommGetAsyncError(nccl->ncomm, &nstat)); - } while(nstat == ncclInProgress); + } while (nstat == ncclInProgress); checkCuda(cudaStreamSynchronize(nccl->custream)); // Copy data into ghost-cells. nridx = 0; - for (int bI=0; bInum_comm_conn; ++nr) { + for (int nr = 0; nr < mbcc_r->num_comm_conn; ++nr) { int nid = mbcc_r->comm_conn[nr].rank; if (nid != my_rank) { int isrecv = mbcc_r->comm_conn[nr].range.volume; if (isrecv) { - gkyl_array_copy_from_buffer(arr_recv[bI], - gkyl_mem_buff_data(nccl->recv[nridx].buff), - &(mbcc_r->comm_conn[nr].range) + gkyl_array_copy_from_buffer( + arr_recv[bI], gkyl_mem_buff_data(nccl->recv[nridx].buff), &(mbcc_r->comm_conn[nr].range) ); nridx += 1; } @@ -142,10 +149,11 @@ gkyl_multib_comm_conn_array_transfer_nccl(struct gkyl_comm *comm, int num_blocks #else -int -gkyl_multib_comm_conn_array_transfer_nccl(struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, +int gkyl_multib_comm_conn_array_transfer_nccl( + struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, struct gkyl_multib_comm_conn **mbcc_send, struct gkyl_multib_comm_conn **mbcc_recv, - struct gkyl_array **arr_send, struct gkyl_array **arr_recv) + struct gkyl_array **arr_send, struct gkyl_array **arr_recv +) { return 1; } diff --git a/core/zero/multib_comm_conn_null.c b/core/zero/multib_comm_conn_null.c index c2805f2221..9a42d5d012 100644 --- a/core/zero/multib_comm_conn_null.c +++ b/core/zero/multib_comm_conn_null.c @@ -2,20 +2,21 @@ #include #include -int -gkyl_multib_comm_conn_array_transfer_null(struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, +int gkyl_multib_comm_conn_array_transfer_null( + struct gkyl_comm *comm, int num_blocks_local, const int *local_blocks, struct gkyl_multib_comm_conn **mbcc_send, struct gkyl_multib_comm_conn **mbcc_recv, - struct gkyl_array **arr_send, struct gkyl_array **arr_recv) + struct gkyl_array **arr_send, struct gkyl_array **arr_recv +) { struct null_comm *null = container_of(comm, struct null_comm, priv_comm.pub_comm); - // post nonblocking recv to get data into ghost-cells + // post nonblocking recv to get data into ghost-cells int nridx = 0; - for (int bI=0; bInum_comm_conn; ++nr) { + for (int nr = 0; nr < mbcc_r->num_comm_conn; ++nr) { int bid_src = mbcc_r->comm_conn[nr].block_id; struct gkyl_range *range_dest = &mbcc_r->comm_conn[nr].range; int e = mbcc_r->comm_conn[nr].tar_edge; @@ -23,7 +24,7 @@ gkyl_multib_comm_conn_array_transfer_null(struct gkyl_comm *comm, int num_blocks // The send connections may not be ordered in the same way as the recvs. // Loop over the send connections and find the one from the same block. int bid_src_idx = -1; - for (int cI=0; cInum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_s->num_comm_conn; ++ns) { if (mbcc_s->comm_conn[ns].block_id == bid && mbcc_s->comm_conn[ns].src_edge == e) { conn_src_idx = ns; break; @@ -40,8 +41,7 @@ gkyl_multib_comm_conn_array_transfer_null(struct gkyl_comm *comm, int num_blocks struct gkyl_range *range_src = &mbcc_s->comm_conn[conn_src_idx].range; - gkyl_array_copy_range_to_range(arr_recv[bI], arr_send[bid_src_idx], range_dest, range_src); - + gkyl_array_copy_range_to_range(arr_recv[bI], arr_send[bid_src_idx], range_dest, range_src); } } diff --git a/core/zero/nccl_comm.c b/core/zero/nccl_comm.c index 64820bfe88..b7151b5406 100644 --- a/core/zero/nccl_comm.c +++ b/core/zero/nccl_comm.c @@ -18,42 +18,28 @@ #include // Mapping of Gkeyll type to ncclDataType_t -static ncclDataType_t g2_nccl_datatype[] = { - [GKYL_INT] = ncclInt, - [GKYL_INT_64] = ncclInt64, - [GKYL_FLOAT] = ncclFloat, - [GKYL_DOUBLE] = ncclDouble, +static ncclDataType_t g2_nccl_datatype[] = + {[GKYL_INT] = ncclInt, [GKYL_INT_64] = ncclInt64, [GKYL_FLOAT] = ncclFloat, [GKYL_DOUBLE] = ncclDouble }; // Mapping of Gkeyll ops to ncclRedOp_t. -static ncclRedOp_t g2_nccl_op[] = { - [GKYL_MIN] = ncclMin, - [GKYL_MAX] = ncclMax, - [GKYL_SUM] = ncclSum, -}; +static ncclRedOp_t g2_nccl_op[] = {[GKYL_MIN] = ncclMin, [GKYL_MAX] = ncclMax, [GKYL_SUM] = ncclSum}; // Mapping of Gkeyll type to MPI_Datatype -static MPI_Datatype g2_mpi_datatype[] = { - [GKYL_INT] = MPI_INT, - [GKYL_INT_64] = MPI_INT64_T, - [GKYL_FLOAT] = MPI_FLOAT, - [GKYL_DOUBLE] = MPI_DOUBLE +static MPI_Datatype g2_mpi_datatype[] = + {[GKYL_INT] = MPI_INT, [GKYL_INT_64] = MPI_INT64_T, [GKYL_FLOAT] = MPI_FLOAT, [GKYL_DOUBLE] = MPI_DOUBLE }; // Mapping of Gkeyll ops to MPI_Op -static MPI_Op g2_mpi_op[] = { - [GKYL_MIN] = MPI_MIN, - [GKYL_MAX] = MPI_MAX, - [GKYL_SUM] = MPI_SUM -}; +static MPI_Op g2_mpi_op[] = {[GKYL_MIN] = MPI_MIN, [GKYL_MAX] = MPI_MAX, [GKYL_SUM] = MPI_SUM}; struct extra_nccl_comm_inp { bool is_comm_allocated; // is MPI_Comm allocated? }; // Internal method to create a new NCCL communicator -static struct gkyl_comm* nccl_comm_new( - const struct gkyl_nccl_comm_inp *inp, const struct extra_nccl_comm_inp *extra_inp); +static struct gkyl_comm * +nccl_comm_new(const struct gkyl_nccl_comm_inp *inp, const struct extra_nccl_comm_inp *extra_inp); struct gkyl_comm_state { ncclComm_t *ncomm; @@ -62,8 +48,7 @@ struct gkyl_comm_state { int peer; }; -static struct gkyl_comm_state * -comm_state_new(struct gkyl_comm *comm) +static struct gkyl_comm_state *comm_state_new(struct gkyl_comm *comm) { struct gkyl_comm_state *state = gkyl_malloc(sizeof *state); @@ -74,28 +59,24 @@ comm_state_new(struct gkyl_comm *comm) return state; } -static void -comm_state_release(struct gkyl_comm_state *state) +static void comm_state_release(struct gkyl_comm_state *state) { gkyl_free(state); } -static void -comm_state_wait(struct gkyl_comm_state *state) +static void comm_state_wait(struct gkyl_comm_state *state) { checkCuda(cudaStreamSynchronize(*(state->custream))); } // Ensure completion of NCCL collectives that are expected to behave synchronously. -static inline void -wait_for_nccl_collective(struct nccl_comm *nccl, ncclResult_t status) +static inline void wait_for_nccl_collective(struct nccl_comm *nccl, ncclResult_t status) { checkNCCL(status); checkCuda(cudaStreamSynchronize(nccl->custream)); } -static void -comm_free(const struct gkyl_ref_count *ref) +static void comm_free(const struct gkyl_ref_count *ref) { struct gkyl_comm *comm = container_of(ref, struct gkyl_comm, ref_count); struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); @@ -104,14 +85,17 @@ comm_free(const struct gkyl_ref_count *ref) gkyl_rect_decomp_release(nccl->decomp); gkyl_rect_decomp_neigh_release(nccl->neigh); - for (int d=0; dper_neigh[d]); + } - for (int i=0; irecv[i].buff); + } - for (int i=0; isend[i].buff); + } gkyl_mem_buff_release(nccl->allgather_buff_local.buff); gkyl_mem_buff_release(nccl->allgather_buff_global.buff); @@ -121,31 +105,29 @@ comm_free(const struct gkyl_ref_count *ref) checkCuda(cudaDeviceSynchronize()); ncclCommDestroy(nccl->ncomm); - if (nccl->is_mcomm_allocated) + if (nccl->is_mcomm_allocated) { MPI_Comm_free(&nccl->mcomm); + } gkyl_comm_release(nccl->mpi_comm); gkyl_free(nccl); } -static int -get_rank(struct gkyl_comm *comm, int *rank) +static int get_rank(struct gkyl_comm *comm, int *rank) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); *rank = nccl->rank; return 0; } -static int -get_size(struct gkyl_comm *comm, int *sz) +static int get_size(struct gkyl_comm *comm, int *sz) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); *sz = nccl->size; return 0; } -static int -barrier(struct gkyl_comm *comm) +static int barrier(struct gkyl_comm *comm) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); checkCuda(cudaStreamSynchronize(nccl->custream)); @@ -153,93 +135,100 @@ barrier(struct gkyl_comm *comm) return 0; } -static int -array_write(struct gkyl_comm *comm, - const struct gkyl_rect_grid *grid, - const struct gkyl_range *range, - const struct gkyl_msgpack_data *meta, - const struct gkyl_array *arr, const char *fname) +static int array_write( + struct gkyl_comm *comm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + const struct gkyl_msgpack_data *meta, const struct gkyl_array *arr, const char *fname +) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); return gkyl_comm_array_write(nccl->mpi_comm, grid, range, meta, arr, fname); } -static int -array_read(struct gkyl_comm *comm, - const struct gkyl_rect_grid *grid, const struct gkyl_range *range, - struct gkyl_array *arr, const char *fname) +static int array_read( + struct gkyl_comm *comm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + struct gkyl_array *arr, const char *fname +) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); return gkyl_comm_array_read(nccl->mpi_comm, grid, range, arr, fname); } -static int -array_send(struct gkyl_array *array, int dest, int tag, struct gkyl_comm *comm) +static int array_send(struct gkyl_array *array, int dest, int tag, struct gkyl_comm *comm) { - size_t vol = array->ncomp*array->size; + size_t vol = array->ncomp * array->size; struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); - checkNCCL(ncclSend(array->data, vol, g2_nccl_datatype[array->type], dest, nccl->ncomm, nccl->custream)); + checkNCCL( + ncclSend(array->data, vol, g2_nccl_datatype[array->type], dest, nccl->ncomm, nccl->custream) + ); checkCuda(cudaStreamSynchronize(nccl->custream)); return 0; } -static int -array_recv(struct gkyl_array *array, int src, int tag, struct gkyl_comm *comm) +static int array_recv(struct gkyl_array *array, int src, int tag, struct gkyl_comm *comm) { - size_t vol = array->ncomp*array->size; + size_t vol = array->ncomp * array->size; struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); - checkNCCL(ncclRecv(array->data, vol, g2_nccl_datatype[array->type], src, nccl->ncomm, nccl->custream)); + checkNCCL( + ncclRecv(array->data, vol, g2_nccl_datatype[array->type], src, nccl->ncomm, nccl->custream) + ); checkCuda(cudaStreamSynchronize(nccl->custream)); return 0; } -static int -array_isend(struct gkyl_array *array, int dest, int tag, struct gkyl_comm *comm, struct gkyl_comm_state *state) +static int array_isend( + struct gkyl_array *array, int dest, int tag, struct gkyl_comm *comm, struct gkyl_comm_state *state +) { - size_t vol = array->ncomp*array->size; + size_t vol = array->ncomp * array->size; struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); - checkNCCL(ncclSend(array->data, vol, g2_nccl_datatype[array->type], dest, nccl->ncomm, nccl->custream)); + checkNCCL( + ncclSend(array->data, vol, g2_nccl_datatype[array->type], dest, nccl->ncomm, nccl->custream) + ); state->tag = tag; state->peer = dest; return 0; } -static int -array_irecv(struct gkyl_array *array, int src, int tag, struct gkyl_comm *comm, struct gkyl_comm_state *state) +static int array_irecv( + struct gkyl_array *array, int src, int tag, struct gkyl_comm *comm, struct gkyl_comm_state *state +) { - size_t vol = array->ncomp*array->size; + size_t vol = array->ncomp * array->size; struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); - checkNCCL(ncclRecv(array->data, vol, g2_nccl_datatype[array->type], src, nccl->ncomm, nccl->custream)); + checkNCCL( + ncclRecv(array->data, vol, g2_nccl_datatype[array->type], src, nccl->ncomm, nccl->custream) + ); state->tag = tag; state->peer = src; return 0; } -static int -allreduce(struct gkyl_comm *comm, enum gkyl_elem_type type, - enum gkyl_array_op op, int nelem, const void *inp, - void *out) +static int allreduce( + struct gkyl_comm *comm, enum gkyl_elem_type type, enum gkyl_array_op op, int nelem, + const void *inp, void *out +) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); - ncclResult_t status = ncclAllReduce(inp, out, nelem, - g2_nccl_datatype[type], g2_nccl_op[op], nccl->ncomm, nccl->custream); + ncclResult_t status = ncclAllReduce( + inp, out, nelem, g2_nccl_datatype[type], g2_nccl_op[op], nccl->ncomm, nccl->custream + ); wait_for_nccl_collective(nccl, status); return 0; } -static int -allreduce_host(struct gkyl_comm *comm, enum gkyl_elem_type type, - enum gkyl_array_op op, int nelem, const void *inp, - void *out) +static int allreduce_host( + struct gkyl_comm *comm, enum gkyl_elem_type type, enum gkyl_array_op op, int nelem, + const void *inp, void *out +) { - struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); + struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); return gkyl_comm_allreduce(nccl->mpi_comm, type, op, nelem, inp, out); } -static int -array_allgather(struct gkyl_comm *comm, - const struct gkyl_range *local, const struct gkyl_range *global, - const struct gkyl_array *array_local, struct gkyl_array *array_global) +static int array_allgather( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *global, + const struct gkyl_array *array_local, struct gkyl_array *array_global +) { assert(array_global->esznc == array_local->esznc); @@ -253,110 +242,115 @@ array_allgather(struct gkyl_comm *comm, assert(global->volume == nccl->decomp->parent_range.volume); // potentially re-size local buffer volume - size_t send_vol = array_local->esznc*nccl->decomp->ranges[rank].volume; - if (gkyl_mem_buff_size(nccl->allgather_buff_local.buff) < send_vol) + size_t send_vol = array_local->esznc * nccl->decomp->ranges[rank].volume; + if (gkyl_mem_buff_size(nccl->allgather_buff_local.buff) < send_vol) { gkyl_mem_buff_resize(nccl->allgather_buff_local.buff, send_vol); + } // potentially re-size global buffer volume - size_t buff_global_vol = array_local->esznc*nccl->decomp->parent_range.volume; - if (gkyl_mem_buff_size(nccl->allgather_buff_global.buff) < buff_global_vol) + size_t buff_global_vol = array_local->esznc * nccl->decomp->parent_range.volume; + if (gkyl_mem_buff_size(nccl->allgather_buff_global.buff) < buff_global_vol) { gkyl_mem_buff_resize(nccl->allgather_buff_global.buff, buff_global_vol); + } // copy data to local buffer - gkyl_array_copy_to_buffer(gkyl_mem_buff_data(nccl->allgather_buff_local.buff), - array_local, local); + gkyl_array_copy_to_buffer(gkyl_mem_buff_data(nccl->allgather_buff_local.buff), array_local, local); - size_t nelem = array_local->esznc*nccl->decomp->ranges[rank].volume; + size_t nelem = array_local->esznc * nccl->decomp->ranges[rank].volume; // gather data into global buffer ncclResult_t status = ncclAllGather( gkyl_mem_buff_data(nccl->allgather_buff_local.buff), - gkyl_mem_buff_data(nccl->allgather_buff_global.buff), - nelem, ncclChar, nccl->ncomm, nccl->custream); + gkyl_mem_buff_data(nccl->allgather_buff_global.buff), nelem, ncclChar, nccl->ncomm, + nccl->custream + ); wait_for_nccl_collective(nccl, status); // copy data to global array int idx = 0; - for (int r=0; rdecomp->ndecomp; ++r) { - int isrecv = gkyl_sub_range_intersect( - &gather_range, global, &nccl->decomp->ranges[r]); - gkyl_array_copy_from_buffer(array_global, - gkyl_mem_buff_data(nccl->allgather_buff_global.buff) + idx, &gather_range); - idx += array_local->esznc*gather_range.volume; + for (int r = 0; r < nccl->decomp->ndecomp; ++r) { + int isrecv = gkyl_sub_range_intersect(&gather_range, global, &nccl->decomp->ranges[r]); + gkyl_array_copy_from_buffer( + array_global, gkyl_mem_buff_data(nccl->allgather_buff_global.buff) + idx, &gather_range + ); + idx += array_local->esznc * gather_range.volume; } return 0; } -static int -array_allgather_host(struct gkyl_comm *comm, - const struct gkyl_range *local, const struct gkyl_range *global, - const struct gkyl_array *array_local, struct gkyl_array *array_global) +static int array_allgather_host( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *global, + const struct gkyl_array *array_local, struct gkyl_array *array_global +) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); return gkyl_comm_array_allgather_host(nccl->mpi_comm, local, global, array_local, array_global); } -static int -array_bcast(struct gkyl_comm *comm, const struct gkyl_array *asend, - struct gkyl_array *arecv, int root) +static int array_bcast( + struct gkyl_comm *comm, const struct gkyl_array *asend, struct gkyl_array *arecv, int root +) { assert(asend->esznc == arecv->esznc); assert(asend->size == arecv->size); struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); - size_t nelem = asend->ncomp*asend->size; + size_t nelem = asend->ncomp * asend->size; - ncclResult_t status = ncclBroadcast(asend->data, arecv->data, nelem, - g2_nccl_datatype[asend->type], root, nccl->ncomm, nccl->custream); + ncclResult_t status = ncclBroadcast( + asend->data, arecv->data, nelem, g2_nccl_datatype[asend->type], root, nccl->ncomm, + nccl->custream + ); wait_for_nccl_collective(nccl, status); return 0; } -static int -array_bcast_host(struct gkyl_comm *comm, const struct gkyl_array *asend, - struct gkyl_array *arecv, int root) +static int array_bcast_host( + struct gkyl_comm *comm, const struct gkyl_array *asend, struct gkyl_array *arecv, int root +) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); return gkyl_comm_array_bcast_host(nccl->mpi_comm, asend, arecv, root); } -static void -group_call_start() +static void group_call_start() { checkNCCL(ncclGroupStart()); } -static void -group_call_end() +static void group_call_end() { checkNCCL(ncclGroupEnd()); } -static int -array_sync(struct gkyl_comm *comm, const struct gkyl_range *local, - const struct gkyl_range *local_ext, struct gkyl_array *array) +static int array_sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + struct gkyl_array *array +) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); int elo[GKYL_MAX_DIM], eup[GKYL_MAX_DIM]; - for (int i=0; idecomp->ndim; ++i) - elo[i] = eup[i] = local_ext->upper[i]-local->upper[i]; + for (int i = 0; i < nccl->decomp->ndim; ++i) { + elo[i] = eup[i] = local_ext->upper[i] - local->upper[i]; + } // Phase 1: Prepare recv ranges and buffers before the NCCL group. int recv_nids[MAX_RECV_NEIGH]; int nridx = 0; - for (int n=0; nneigh->num_neigh; ++n) { + for (int n = 0; n < nccl->neigh->num_neigh; ++n) { int nid = nccl->neigh->neigh[n]; - int isrecv = gkyl_sub_range_intersect( - &nccl->recv[nridx].range, local_ext, &nccl->decomp->ranges[nid]); - size_t recv_vol = array->esznc*nccl->recv[nridx].range.volume; + int isrecv = + gkyl_sub_range_intersect(&nccl->recv[nridx].range, local_ext, &nccl->decomp->ranges[nid]); + size_t recv_vol = array->esznc * nccl->recv[nridx].range.volume; if (isrecv) { - if (gkyl_mem_buff_size(nccl->recv[nridx].buff) < recv_vol) + if (gkyl_mem_buff_size(nccl->recv[nridx].buff) < recv_vol) { gkyl_mem_buff_resize(nccl->recv[nridx].buff, recv_vol); + } recv_nids[nridx] = nid; nridx += 1; @@ -367,22 +361,23 @@ array_sync(struct gkyl_comm *comm, const struct gkyl_range *local, // into send buffers before the NCCL group. int send_nids[MAX_RECV_NEIGH]; int nsidx = 0; - for (int n=0; nneigh->num_neigh; ++n) { + for (int n = 0; n < nccl->neigh->num_neigh; ++n) { int nid = nccl->neigh->neigh[n]; struct gkyl_range neigh_ext; gkyl_range_extend(&neigh_ext, &nccl->decomp->ranges[nid], elo, eup); - int issend = gkyl_sub_range_intersect( - &nccl->send[nsidx].range, local, &neigh_ext); - size_t send_vol = array->esznc*nccl->send[nsidx].range.volume; + int issend = gkyl_sub_range_intersect(&nccl->send[nsidx].range, local, &neigh_ext); + size_t send_vol = array->esznc * nccl->send[nsidx].range.volume; if (issend) { - if (gkyl_mem_buff_size(nccl->send[nsidx].buff) < send_vol) + if (gkyl_mem_buff_size(nccl->send[nsidx].buff) < send_vol) { gkyl_mem_buff_resize(nccl->send[nsidx].buff, send_vol); + } - gkyl_array_copy_to_buffer(gkyl_mem_buff_data(nccl->send[nsidx].buff), - array, &(nccl->send[nsidx].range)); + gkyl_array_copy_to_buffer( + gkyl_mem_buff_data(nccl->send[nsidx].buff), array, &(nccl->send[nsidx].range) + ); send_nids[nsidx] = nid; nsidx += 1; @@ -395,16 +390,20 @@ array_sync(struct gkyl_comm *comm, const struct gkyl_range *local, // No CUDA memory operations or kernel launches between group start/end. checkNCCL(ncclGroupStart()); - for (int r=0; resznc*nccl->recv[r].range.volume; - checkNCCL(ncclRecv(gkyl_mem_buff_data(nccl->recv[r].buff), - recv_vol, ncclChar, recv_nids[r], nccl->ncomm, nccl->custream)); + for (int r = 0; r < nridx; ++r) { + size_t recv_vol = array->esznc * nccl->recv[r].range.volume; + checkNCCL(ncclRecv( + gkyl_mem_buff_data(nccl->recv[r].buff), recv_vol, ncclChar, recv_nids[r], nccl->ncomm, + nccl->custream + )); } - for (int s=0; sesznc*nccl->send[s].range.volume; - checkNCCL(ncclSend(gkyl_mem_buff_data(nccl->send[s].buff), - send_vol, ncclChar, send_nids[s], nccl->ncomm, nccl->custream)); + for (int s = 0; s < nsidx; ++s) { + size_t send_vol = array->esznc * nccl->send[s].range.volume; + checkNCCL(ncclSend( + gkyl_mem_buff_data(nccl->send[s].buff), send_vol, ncclChar, send_nids[s], nccl->ncomm, + nccl->custream + )); } checkNCCL(ncclGroupEnd()); @@ -414,63 +413,68 @@ array_sync(struct gkyl_comm *comm, const struct gkyl_range *local, } // Phase 5: Copy received data into ghost-cells. - for (int r=0; rrecv[r].buff), - &(nccl->recv[r].range) + for (int r = 0; r < nridx; ++r) { + gkyl_array_copy_from_buffer( + array, gkyl_mem_buff_data(nccl->recv[r].buff), &(nccl->recv[r].range) ); } return 0; } -static int -array_per_sync(struct gkyl_comm *comm, const struct gkyl_range *local, - const struct gkyl_range *local_ext, - int nper_dirs, const int *per_dirs, struct gkyl_array *array) +static int array_per_sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + int nper_dirs, const int *per_dirs, struct gkyl_array *array +) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); - if (!nccl->touches_any_edge) return 0; // nothing to sync + if (!nccl->touches_any_edge) { + return 0; // nothing to sync + } int elo[GKYL_MAX_DIM], eup[GKYL_MAX_DIM]; - for (int i=0; idecomp->ndim; ++i) - elo[i] = eup[i] = local_ext->upper[i]-local->upper[i]; + for (int i = 0; i < nccl->decomp->ndim; ++i) { + elo[i] = eup[i] = local_ext->upper[i] - local->upper[i]; + } int nridx = 0; int nsidx = 0; - int shift_sign[] = { -1, 1 }; + int shift_sign[] = {-1, 1}; // Handle self-periodic cases first (local copies, no NCCL communication). - for (int i=0; iis_on_edge[e][dir]) { int nid = nccl->per_neigh[dir]->neigh[0]; if (nid == nccl->rank) { - int delta[GKYL_MAX_DIM] = { 0 }; - delta[dir] = shift_sign[e]*gkyl_range_shape(&nccl->decomp->parent_range, dir); + int delta[GKYL_MAX_DIM] = {0}; + delta[dir] = shift_sign[e] * gkyl_range_shape(&nccl->decomp->parent_range, dir); struct gkyl_range neigh_shift, neigh_shift_ext; gkyl_range_shift(&neigh_shift, &nccl->decomp->ranges[nid], delta); - int isrecv = gkyl_sub_range_intersect( - &nccl->recv[nridx].range, local_ext, &neigh_shift); + int isrecv = gkyl_sub_range_intersect(&nccl->recv[nridx].range, local_ext, &neigh_shift); delta[dir] *= -1; gkyl_range_shift(&neigh_shift, &nccl->decomp->ranges[nid], delta); gkyl_range_extend(&neigh_shift_ext, &neigh_shift, elo, eup); - int issend = gkyl_sub_range_intersect( - &nccl->send[nsidx].range, local, &neigh_shift_ext); + int issend = gkyl_sub_range_intersect(&nccl->send[nsidx].range, local, &neigh_shift_ext); - size_t recv_vol = array->esznc*nccl->recv[nridx].range.volume; - if (gkyl_mem_buff_size(nccl->recv[nridx].buff) < recv_vol) + size_t recv_vol = array->esznc * nccl->recv[nridx].range.volume; + if (gkyl_mem_buff_size(nccl->recv[nridx].buff) < recv_vol) { gkyl_mem_buff_resize(nccl->recv[nridx].buff, recv_vol); + } - gkyl_array_copy_to_buffer(gkyl_mem_buff_data(nccl->recv[nridx].buff), array, &(nccl->send[nsidx].range)); - gkyl_array_copy_from_buffer(array, gkyl_mem_buff_data(nccl->recv[nridx].buff), &(nccl->recv[nridx].range)); + gkyl_array_copy_to_buffer( + gkyl_mem_buff_data(nccl->recv[nridx].buff), array, &(nccl->send[nsidx].range) + ); + gkyl_array_copy_from_buffer( + array, gkyl_mem_buff_data(nccl->recv[nridx].buff), &(nccl->recv[nridx].range) + ); nridx += 1; nsidx += 1; @@ -486,28 +490,28 @@ array_per_sync(struct gkyl_comm *comm, const struct gkyl_range *local, int recv_nids[MAX_RECV_NEIGH]; int send_nids[MAX_RECV_NEIGH]; - for (int i=0; iis_on_edge[e][dir]) { int nid = nccl->per_neigh[dir]->neigh[0]; if (nid != nccl->rank) { - int delta[GKYL_MAX_DIM] = { 0 }; - delta[dir] = shift_sign[e]*gkyl_range_shape(&nccl->decomp->parent_range, dir); + int delta[GKYL_MAX_DIM] = {0}; + delta[dir] = shift_sign[e] * gkyl_range_shape(&nccl->decomp->parent_range, dir); if (nccl->per_neigh[dir]->num_neigh == 1) { - struct gkyl_range neigh_shift; gkyl_range_shift(&neigh_shift, &nccl->decomp->ranges[nid], delta); - int isrecv = gkyl_sub_range_intersect( - &nccl->recv[nridx].range, local_ext, &neigh_shift); - size_t recv_vol = array->esznc*nccl->recv[nridx].range.volume; + int isrecv = + gkyl_sub_range_intersect(&nccl->recv[nridx].range, local_ext, &neigh_shift); + size_t recv_vol = array->esznc * nccl->recv[nridx].range.volume; if (isrecv) { - if (gkyl_mem_buff_size(nccl->recv[nridx].buff) < recv_vol) + if (gkyl_mem_buff_size(nccl->recv[nridx].buff) < recv_vol) { gkyl_mem_buff_resize(nccl->recv[nridx].buff, recv_vol); + } recv_nids[nridx] = nid; nridx += 1; @@ -517,16 +521,18 @@ array_per_sync(struct gkyl_comm *comm, const struct gkyl_range *local, gkyl_range_shift(&neigh_shift, &nccl->decomp->ranges[nid], delta); gkyl_range_extend(&neigh_shift_ext, &neigh_shift, elo, eup); - int issend = gkyl_sub_range_intersect( - &nccl->send[nsidx].range, local, &neigh_shift_ext); - size_t send_vol = array->esznc*nccl->send[nsidx].range.volume; + int issend = + gkyl_sub_range_intersect(&nccl->send[nsidx].range, local, &neigh_shift_ext); + size_t send_vol = array->esznc * nccl->send[nsidx].range.volume; if (issend) { - if (gkyl_mem_buff_size(nccl->send[nsidx].buff) < send_vol) + if (gkyl_mem_buff_size(nccl->send[nsidx].buff) < send_vol) { gkyl_mem_buff_resize(nccl->send[nsidx].buff, send_vol); + } - gkyl_array_copy_to_buffer(gkyl_mem_buff_data(nccl->send[nsidx].buff), - array, &(nccl->send[nsidx].range)); + gkyl_array_copy_to_buffer( + gkyl_mem_buff_data(nccl->send[nsidx].buff), array, &(nccl->send[nsidx].range) + ); send_nids[nsidx] = nid; nsidx += 1; @@ -548,16 +554,20 @@ array_per_sync(struct gkyl_comm *comm, const struct gkyl_range *local, if (has_nccl_ops) { checkNCCL(ncclGroupStart()); - for (int r=nridx_nccl_start; resznc*nccl->recv[r].range.volume; - checkNCCL(ncclRecv(gkyl_mem_buff_data(nccl->recv[r].buff), - recv_vol, ncclChar, recv_nids[r], nccl->ncomm, nccl->custream)); + for (int r = nridx_nccl_start; r < nridx; ++r) { + size_t recv_vol = array->esznc * nccl->recv[r].range.volume; + checkNCCL(ncclRecv( + gkyl_mem_buff_data(nccl->recv[r].buff), recv_vol, ncclChar, recv_nids[r], nccl->ncomm, + nccl->custream + )); } - for (int s=nsidx_nccl_start; sesznc*nccl->send[s].range.volume; - checkNCCL(ncclSend(gkyl_mem_buff_data(nccl->send[s].buff), - send_vol, ncclChar, send_nids[s], nccl->ncomm, nccl->custream)); + for (int s = nsidx_nccl_start; s < nsidx; ++s) { + size_t send_vol = array->esznc * nccl->send[s].range.volume; + checkNCCL(ncclSend( + gkyl_mem_buff_data(nccl->send[s].buff), send_vol, ncclChar, send_nids[s], nccl->ncomm, + nccl->custream + )); } checkNCCL(ncclGroupEnd()); @@ -567,10 +577,9 @@ array_per_sync(struct gkyl_comm *comm, const struct gkyl_range *local, } // Phase 4: Copy received data into ghost-cells. - for (int r=nridx_nccl_start; rrecv[r].buff), - &(nccl->recv[r].range) + for (int r = nridx_nccl_start; r < nridx; ++r) { + gkyl_array_copy_from_buffer( + array, gkyl_mem_buff_data(nccl->recv[r].buff), &(nccl->recv[r].range) ); } @@ -579,26 +588,23 @@ array_per_sync(struct gkyl_comm *comm, const struct gkyl_range *local, return 0; } -static struct gkyl_comm* -extend_comm(const struct gkyl_comm *comm, const struct gkyl_range *erange) +static struct gkyl_comm *extend_comm(const struct gkyl_comm *comm, const struct gkyl_range *erange) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); // extend internal decomp object and create a new communicator struct gkyl_rect_decomp *ext_decomp = gkyl_rect_decomp_extended_new(erange, nccl->decomp); - struct gkyl_comm *ext_comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = nccl->mcomm, - .decomp = ext_decomp, - .sync_corners = nccl->sync_corners, - .device_set = 1, - .custream = nccl->custream, - } - ); + struct gkyl_comm *ext_comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp + ){.mpi_comm = nccl->mcomm, + .decomp = ext_decomp, + .sync_corners = nccl->sync_corners, + .device_set = 1, + .custream = nccl->custream}); gkyl_rect_decomp_release(ext_decomp); return ext_comm; } -static struct gkyl_comm* +static struct gkyl_comm * split_comm(const struct gkyl_comm *comm, int color, struct gkyl_rect_decomp *new_decomp) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); @@ -606,20 +612,15 @@ split_comm(const struct gkyl_comm *comm, int color, struct gkyl_rect_decomp *new int ret = MPI_Comm_split(nccl->mcomm, color, nccl->rank, &new_mcomm); assert(ret == MPI_SUCCESS); - struct gkyl_comm *newcomm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = new_mcomm, - .decomp = new_decomp, - .device_set = 1, - .custream = nccl->custream, - } - ); + struct gkyl_comm *newcomm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp + ){.mpi_comm = new_mcomm, .decomp = new_decomp, .device_set = 1, .custream = nccl->custream}); return newcomm; } -static struct gkyl_comm* -create_comm_from_ranks(const struct gkyl_comm *comm, - int nranks, const int *ranks, struct gkyl_rect_decomp *new_decomp, - bool *is_valid) +static struct gkyl_comm *create_comm_from_ranks( + const struct gkyl_comm *comm, int nranks, const int *ranks, struct gkyl_rect_decomp *new_decomp, + bool *is_valid +) { struct nccl_comm *nccl = container_of(comm, struct nccl_comm, priv_comm.pub_comm); @@ -637,16 +638,14 @@ create_comm_from_ranks(const struct gkyl_comm *comm, if (MPI_COMM_NULL != new_mcomm) { *is_valid = true; - new_comm = nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = new_mcomm, + new_comm = nccl_comm_new( + &(struct gkyl_nccl_comm_inp + ){.mpi_comm = new_mcomm, .sync_corners = nccl->sync_corners, .decomp = new_decomp, .device_set = 1, - .custream = nccl->custream, - }, - &(struct extra_nccl_comm_inp) { - .is_comm_allocated = true - } + .custream = nccl->custream}, + &(struct extra_nccl_comm_inp){.is_comm_allocated = true} ); } @@ -656,41 +655,39 @@ create_comm_from_ranks(const struct gkyl_comm *comm, return new_comm; } -struct gkyl_comm* -nccl_comm_new(const struct gkyl_nccl_comm_inp *inp, - const struct extra_nccl_comm_inp *extra_inp) +struct gkyl_comm * +nccl_comm_new(const struct gkyl_nccl_comm_inp *inp, const struct extra_nccl_comm_inp *extra_inp) { struct nccl_comm *nccl = gkyl_malloc(sizeof *nccl); strcpy(nccl->priv_comm.pub_comm.id, "nccl_comm"); - + nccl->is_mcomm_allocated = extra_inp->is_comm_allocated; nccl->mcomm = inp->mpi_comm; - nccl->mpi_comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = nccl->mcomm, - .decomp = inp->decomp, - .sync_corners = inp->sync_corners, - } - ); + nccl->mpi_comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = nccl->mcomm, .decomp = inp->decomp, .sync_corners = inp->sync_corners}); MPI_Comm_rank(nccl->mcomm, &nccl->rank); MPI_Comm_size(nccl->mcomm, &nccl->size); if (inp->device_set == 0) { int num_devices[1]; checkCuda(cudaGetDeviceCount(num_devices)); - + int local_rank = nccl->rank % num_devices[0]; checkCuda(cudaSetDevice(local_rank)); } ncclUniqueId nId; - if (nccl->rank == 0) ncclGetUniqueId(&nId); + if (nccl->rank == 0) { + ncclGetUniqueId(&nId); + } MPI_Bcast((void *)&nId, sizeof(nId), MPI_BYTE, 0, nccl->mcomm); - if (inp->custream == 0) + if (inp->custream == 0) { checkCuda(cudaStreamCreate(&nccl->custream)); - else + } else { nccl->custream = inp->custream; + } // Initialize NCCL comm in blocking mode. Nonblocking only defers host-side // enqueue (forcing ncclCommGetAsyncError polling) and does NOT enable @@ -707,62 +704,64 @@ nccl_comm_new(const struct gkyl_nccl_comm_inp *inp, nccl->priv_comm.pub_comm.has_decomp = false; // Construct a dummy decomposition. - nccl->decomp = gkyl_rect_decomp_new_from_cuts_and_cells(1, - (int[]) { nccl->size }, (int[]) { nccl->size }); - } - else { + nccl->decomp = + gkyl_rect_decomp_new_from_cuts_and_cells(1, (int[]){nccl->size}, (int[]){nccl->size}); + } else { nccl->decomp = gkyl_rect_decomp_acquire(inp->decomp); } nccl->neigh = gkyl_rect_decomp_calc_neigh(nccl->decomp, inp->sync_corners, nccl->rank); - for (int d=0; ddecomp->ndim; ++d) - nccl->per_neigh[d] = - gkyl_rect_decomp_calc_periodic_neigh(nccl->decomp, d, false, nccl->rank); - + for (int d = 0; d < nccl->decomp->ndim; ++d) { + nccl->per_neigh[d] = gkyl_rect_decomp_calc_periodic_neigh(nccl->decomp, d, false, nccl->rank); + } + nccl->nrecv = 0; - for (int i=0; irecv[i].buff = gkyl_mem_buff_cu_new(16); - + } + nccl->nsend = 0; - for (int i=0; isend[i].buff = gkyl_mem_buff_cu_new(16); + } nccl->allgather_buff_local.buff = gkyl_mem_buff_cu_new(16); nccl->allgather_buff_global.buff = gkyl_mem_buff_cu_new(16); - gkyl_range_init(&nccl->dir_edge, 2, (int[]) { 0, 0 }, (int[]) { GKYL_MAX_DIM, 2 }); + gkyl_range_init(&nccl->dir_edge, 2, (int[]){0, 0}, (int[]){GKYL_MAX_DIM, 2}); int num_touches = 0; - for (int d=0; ddecomp->ndim; ++d) { + for (int d = 0; d < nccl->decomp->ndim; ++d) { nccl->is_on_edge[0][d] = gkyl_range_is_on_lower_edge( - d, &nccl->decomp->ranges[nccl->rank], &nccl->decomp->parent_range); + d, &nccl->decomp->ranges[nccl->rank], &nccl->decomp->parent_range + ); nccl->is_on_edge[1][d] = gkyl_range_is_on_upper_edge( - d, &nccl->decomp->ranges[nccl->rank], &nccl->decomp->parent_range); + d, &nccl->decomp->ranges[nccl->rank], &nccl->decomp->parent_range + ); num_touches += nccl->is_on_edge[0][d] + nccl->is_on_edge[1][d]; } nccl->touches_any_edge = num_touches > 0 ? true : false; - + nccl->local_range_offset = gkyl_rect_decomp_calc_offset(nccl->decomp, nccl->rank); - nccl->priv_comm.gkyl_array_sync = array_sync; nccl->priv_comm.gkyl_array_per_sync = array_per_sync; nccl->priv_comm.gkyl_array_write = array_write; nccl->priv_comm.gkyl_array_read = array_read; - + nccl->priv_comm.get_rank = get_rank; nccl->priv_comm.get_size = get_size; nccl->priv_comm.barrier = barrier; nccl->priv_comm.allreduce = allreduce; nccl->priv_comm.allreduce_host = allreduce_host; -// MF 2024/09/12: disable these for now per 498b7d1569eaa9285ae59581bd22dab124672f7b. -// nccl->priv_comm.gkyl_array_send = array_send; -// nccl->priv_comm.gkyl_array_isend = array_isend; -// nccl->priv_comm.gkyl_array_recv = array_recv; -// nccl->priv_comm.gkyl_array_irecv = array_irecv; -// nccl->priv_comm.comm_state_new = comm_state_new; -// nccl->priv_comm.comm_state_release = comm_state_release; -// nccl->priv_comm.comm_state_wait = comm_state_wait; + // MF 2024/09/12: disable these for now per 498b7d1569eaa9285ae59581bd22dab124672f7b. + // nccl->priv_comm.gkyl_array_send = array_send; + // nccl->priv_comm.gkyl_array_isend = array_isend; + // nccl->priv_comm.gkyl_array_recv = array_recv; + // nccl->priv_comm.gkyl_array_irecv = array_irecv; + // nccl->priv_comm.comm_state_new = comm_state_new; + // nccl->priv_comm.comm_state_release = comm_state_release; + // nccl->priv_comm.comm_state_wait = comm_state_wait; nccl->priv_comm.gkyl_array_allgather = array_allgather; nccl->priv_comm.gkyl_array_allgather_host = array_allgather_host; nccl->priv_comm.gkyl_array_bcast = array_bcast; @@ -777,13 +776,9 @@ nccl_comm_new(const struct gkyl_nccl_comm_inp *inp, return &nccl->priv_comm.pub_comm; } -struct gkyl_comm* -gkyl_nccl_comm_new(const struct gkyl_nccl_comm_inp *inp) +struct gkyl_comm *gkyl_nccl_comm_new(const struct gkyl_nccl_comm_inp *inp) { - return nccl_comm_new(inp, &(struct extra_nccl_comm_inp) { - .is_comm_allocated = false - } - ); + return nccl_comm_new(inp, &(struct extra_nccl_comm_inp){.is_comm_allocated = false}); } #endif diff --git a/core/zero/nodal_ops.c b/core/zero/nodal_ops.c index abb6421058..677f48a941 100644 --- a/core/zero/nodal_ops.c +++ b/core/zero/nodal_ops.c @@ -1,7 +1,7 @@ #include #include -struct gkyl_nodal_ops* +struct gkyl_nodal_ops * gkyl_nodal_ops_new(const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, bool use_gpu) { // Allocate space for new updater. @@ -12,10 +12,11 @@ gkyl_nodal_ops_new(const struct gkyl_basis *cbasis, const struct gkyl_rect_grid struct gkyl_array *nodes = gkyl_array_new(GKYL_DOUBLE, grid->ndim, cbasis->num_basis); cbasis->node_list(gkyl_array_fetch(nodes, 0)); - if (use_gpu) + if (use_gpu) { up->nodes = gkyl_array_cu_dev_new(GKYL_DOUBLE, grid->ndim, cbasis->num_basis); - else + } else { up->nodes = gkyl_array_new(GKYL_DOUBLE, grid->ndim, cbasis->num_basis); + } // Copy the nodal values to the pre-allocated array gkyl_array_copy(up->nodes, nodes); @@ -24,19 +25,20 @@ gkyl_nodal_ops_new(const struct gkyl_basis *cbasis, const struct gkyl_rect_grid return up; } -void -gkyl_nodal_ops_n2m_corners(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - const struct gkyl_array *nodal_fld, struct gkyl_array *modal_fld) +void gkyl_nodal_ops_n2m_corners( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, const struct gkyl_array *nodal_fld, + struct gkyl_array *modal_fld +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(modal_fld)) { - return gkyl_nodal_ops_n2m_cu(nodal_ops, cbasis, grid, - nrange, update_range, num_comp, - nodal_fld, modal_fld); + return gkyl_nodal_ops_n2m_cu( + nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld + ); } -#endif +#endif double xc[GKYL_MAX_DIM]; int num_basis = cbasis->num_basis; int cpoly_order = cbasis->poly_order; @@ -46,18 +48,18 @@ gkyl_nodal_ops_n2m_corners(const struct gkyl_nodal_ops *nodal_ops, gkyl_range_iter_init(&iter, update_range); int nidx[3]; long lin_nidx[num_basis]; - + while (gkyl_range_iter_next(&iter)) { - gkyl_rect_grid_cell_center(grid, iter.idx, xc); + gkyl_rect_grid_cell_center(grid, iter.idx, xc); - for (int i=0; inodes,i); - for( int j = 0; j < grid->ndim; j++) { - if (cpoly_order==1) { - nidx[j] = (iter.idx[j]-update_range->lower[j]) + (temp[j]+1)/2 ; + for (int i = 0; i < num_basis; ++i) { + const double *temp = gkyl_array_cfetch(nodal_ops->nodes, i); + for (int j = 0; j < grid->ndim; j++) { + if (cpoly_order == 1) { + nidx[j] = (iter.idx[j] - update_range->lower[j]) + (temp[j] + 1) / 2; } - if (cpoly_order==2) { - nidx[j] = 2*(iter.idx[j]-update_range->lower[j]) + (temp[j]+1) ; + if (cpoly_order == 2) { + nidx[j] = 2 * (iter.idx[j] - update_range->lower[j]) + (temp[j] + 1); } } lin_nidx[i] = gkyl_range_idx(nrange, nidx); @@ -65,33 +67,34 @@ gkyl_nodal_ops_n2m_corners(const struct gkyl_nodal_ops *nodal_ops, long lidx = gkyl_range_idx(update_range, iter.idx); double *arr_p = gkyl_array_fetch(modal_fld, lidx); - double fao[num_basis*num_comp]; - - for (int i=0; inodal_to_modal(fnodal, &arr_p[num_basis*i]); + cbasis->nodal_to_modal(fnodal, &arr_p[num_basis * i]); } } } -void -gkyl_nodal_ops_n2m_interior(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - const struct gkyl_array *nodal_fld, struct gkyl_array *modal_fld) +void gkyl_nodal_ops_n2m_interior( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, const struct gkyl_array *nodal_fld, + struct gkyl_array *modal_fld +) { - int num_basis = cbasis->num_basis; int cpoly_order = cbasis->poly_order; double fnodal[num_basis]; // to store nodal function values @@ -100,52 +103,53 @@ gkyl_nodal_ops_n2m_interior(const struct gkyl_nodal_ops *nodal_ops, gkyl_range_iter_init(&iter, update_range); int nidx[3]; long lin_nidx[num_basis]; - - while (gkyl_range_iter_next(&iter)) { - for (int i=0; inodes,i); - for( int j = 0; j < grid->ndim; j++) { - int mod = (j==1 && grid->ndim==3) ? 2 * (i/4) : 0; - if (j < grid->ndim-1) - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i/((int) pow(2,grid->ndim-1-j)) - mod; - else - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i%2 ; + while (gkyl_range_iter_next(&iter)) { + for (int i = 0; i < num_basis; ++i) { + const double *temp = gkyl_array_cfetch(nodal_ops->nodes, i); + for (int j = 0; j < grid->ndim; j++) { + int mod = (j == 1 && grid->ndim == 3) ? 2 * (i / 4) : 0; + if (j < grid->ndim - 1) { + nidx[j] = (iter.idx[j] - update_range->lower[j]) * 2 + + i / ((int)pow(2, grid->ndim - 1 - j)) - mod; + } else { + nidx[j] = (iter.idx[j] - update_range->lower[j]) * 2 + i % 2; + } } lin_nidx[i] = gkyl_range_idx(nrange, nidx); } long lidx = gkyl_range_idx(update_range, iter.idx); double *arr_p = gkyl_array_fetch(modal_fld, lidx); - double fao[num_basis*num_comp]; - - for (int i=0; iquad_nodal_to_modal(fnodal, &arr_p[num_basis*i],k); + for (int k = 0; k < num_basis; ++k) { + cbasis->quad_nodal_to_modal(fnodal, &arr_p[num_basis * i], k); + } } } } -void -gkyl_nodal_ops_n2m_surface_1x(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - const struct gkyl_array *nodal_fld, struct gkyl_array *modal_fld, int dir) +void gkyl_nodal_ops_n2m_surface_1x( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_rect_grid *grid, + const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, + const struct gkyl_array *nodal_fld, struct gkyl_array *modal_fld, int dir +) { - int num_basis = 1; double fnodal[num_basis]; // to store nodal function values @@ -153,48 +157,53 @@ gkyl_nodal_ops_n2m_surface_1x(const struct gkyl_nodal_ops *nodal_ops, gkyl_range_iter_init(&iter, update_range); int nidx[3]; long lin_nidx[num_basis]; - + while (gkyl_range_iter_next(&iter)) { - for (int i=0; inodes,i); - for( int j = 0; j < grid->ndim; j++) { - nidx[j] = (iter.idx[j]-update_range->lower[j]) ; + for (int i = 0; i < num_basis; ++i) { + const double *temp = gkyl_array_cfetch(nodal_ops->nodes, i); + for (int j = 0; j < grid->ndim; j++) { + nidx[j] = (iter.idx[j] - update_range->lower[j]); } lin_nidx[i] = gkyl_range_idx(nrange, nidx); } long lidx = gkyl_range_idx(update_range, iter.idx); double *arr_p = gkyl_array_fetch(modal_fld, lidx); - double fao[num_basis*num_comp]; - - for (int i=0; indim==1) - return gkyl_nodal_ops_n2m_surface_1x(nodal_ops, grid, nrange, update_range, num_comp, nodal_fld, modal_fld, dir); + if (grid->ndim == 1) { + return gkyl_nodal_ops_n2m_surface_1x( + nodal_ops, grid, nrange, update_range, num_comp, nodal_fld, modal_fld, dir + ); + } int num_basis = cbasis->num_basis; int cpoly_order = cbasis->poly_order; @@ -204,66 +213,69 @@ gkyl_nodal_ops_n2m_surface(const struct gkyl_nodal_ops *nodal_ops, gkyl_range_iter_init(&iter, update_range); int nidx[3]; long lin_nidx[num_basis]; - + while (gkyl_range_iter_next(&iter)) { - for (int i=0; inodes,i); - for( int j = 0; j < grid->ndim; j++) { - if (j !=dir) { - if (j < grid->ndim-1) { - if (dir == 0) - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i/((int) pow(2,grid->ndim-1-j)); - else if (dir == 1) - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i/((int) pow(2,grid->ndim-2+j)); - else if (dir == 2) { - if(j==0) - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i/((int) pow(2,grid->ndim-2+j)); - if(j==1) - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i%2; + for (int i = 0; i < num_basis; ++i) { + const double *temp = gkyl_array_cfetch(nodal_ops->nodes, i); + for (int j = 0; j < grid->ndim; j++) { + if (j != dir) { + if (j < grid->ndim - 1) { + if (dir == 0) { + nidx[j] = + (iter.idx[j] - update_range->lower[j]) * 2 + i / ((int)pow(2, grid->ndim - 1 - j)); + } else if (dir == 1) { + nidx[j] = + (iter.idx[j] - update_range->lower[j]) * 2 + i / ((int)pow(2, grid->ndim - 2 + j)); + } else if (dir == 2) { + if (j == 0) { + nidx[j] = (iter.idx[j] - update_range->lower[j]) * 2 + + i / ((int)pow(2, grid->ndim - 2 + j)); + } + if (j == 1) { + nidx[j] = (iter.idx[j] - update_range->lower[j]) * 2 + i % 2; } } - else - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i%2 ; - } - else { - nidx[j] = (iter.idx[j]-update_range->lower[j]) ; + } else { + nidx[j] = (iter.idx[j] - update_range->lower[j]) * 2 + i % 2; } + } else { + nidx[j] = (iter.idx[j] - update_range->lower[j]); + } } lin_nidx[i] = gkyl_range_idx(nrange, nidx); - } long lidx = gkyl_range_idx(update_range, iter.idx); double *arr_p = gkyl_array_fetch(modal_fld, lidx); - double fao[num_basis*num_comp]; - - for (int i=0; iquad_nodal_to_modal(fnodal, &arr_p[num_basis*i],k); + for (int k = 0; k < num_basis; ++k) { + cbasis->quad_nodal_to_modal(fnodal, &arr_p[num_basis * i], k); + } } } } -void -gkyl_nodal_ops_m2n_surface_1x(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *modal_fld, int dir) +void gkyl_nodal_ops_m2n_surface_1x( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_rect_grid *grid, + const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, + struct gkyl_array *nodal_fld, const struct gkyl_array *modal_fld, int dir +) { - int num_basis = 1; double fnodal[num_basis]; // to store nodal function values @@ -271,48 +283,53 @@ gkyl_nodal_ops_m2n_surface_1x(const struct gkyl_nodal_ops *nodal_ops, gkyl_range_iter_init(&iter, update_range); int nidx[3]; long lin_nidx[num_basis]; - + while (gkyl_range_iter_next(&iter)) { - for (int i=0; inodes,i); - for( int j = 0; j < grid->ndim; j++) { - nidx[j] = (iter.idx[j]-update_range->lower[j]) ; + for (int i = 0; i < num_basis; ++i) { + const double *temp = gkyl_array_cfetch(nodal_ops->nodes, i); + for (int j = 0; j < grid->ndim; j++) { + nidx[j] = (iter.idx[j] - update_range->lower[j]); } lin_nidx[i] = gkyl_range_idx(nrange, nidx); } long lidx = gkyl_range_idx(update_range, iter.idx); const double *arr_p = gkyl_array_cfetch(modal_fld, lidx); - double fao[num_basis*num_comp]; + double fao[num_basis * num_comp]; - for (int i=0; indim==1) - return gkyl_nodal_ops_m2n_surface_1x(nodal_ops, grid, nrange, update_range, num_comp, nodal_fld, modal_fld, dir); + if (grid->ndim == 1) { + return gkyl_nodal_ops_m2n_surface_1x( + nodal_ops, grid, nrange, update_range, num_comp, nodal_fld, modal_fld, dir + ); + } int num_basis = cbasis->num_basis; int cpoly_order = cbasis->poly_order; @@ -322,66 +339,69 @@ gkyl_nodal_ops_m2n_surface(const struct gkyl_nodal_ops *nodal_ops, gkyl_range_iter_init(&iter, update_range); int nidx[3]; long lin_nidx[num_basis]; - + while (gkyl_range_iter_next(&iter)) { - for (int i=0; inodes,i); - for( int j = 0; j < grid->ndim; j++) { - if (j !=dir) { - if (j < grid->ndim-1) { - if (dir == 0) - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i/((int) pow(2,grid->ndim-1-j)); - else if (dir == 1) - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i/((int) pow(2,grid->ndim-2+j)); - else if (dir == 2) { - if(j==0) - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i/((int) pow(2,grid->ndim-2+j)); - if(j==1) - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i%2; + for (int i = 0; i < num_basis; ++i) { + const double *temp = gkyl_array_cfetch(nodal_ops->nodes, i); + for (int j = 0; j < grid->ndim; j++) { + if (j != dir) { + if (j < grid->ndim - 1) { + if (dir == 0) { + nidx[j] = + (iter.idx[j] - update_range->lower[j]) * 2 + i / ((int)pow(2, grid->ndim - 1 - j)); + } else if (dir == 1) { + nidx[j] = + (iter.idx[j] - update_range->lower[j]) * 2 + i / ((int)pow(2, grid->ndim - 2 + j)); + } else if (dir == 2) { + if (j == 0) { + nidx[j] = (iter.idx[j] - update_range->lower[j]) * 2 + + i / ((int)pow(2, grid->ndim - 2 + j)); + } + if (j == 1) { + nidx[j] = (iter.idx[j] - update_range->lower[j]) * 2 + i % 2; } } - else - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i%2 ; - } - else { - nidx[j] = (iter.idx[j]-update_range->lower[j]) ; + } else { + nidx[j] = (iter.idx[j] - update_range->lower[j]) * 2 + i % 2; } + } else { + nidx[j] = (iter.idx[j] - update_range->lower[j]); + } } lin_nidx[i] = gkyl_range_idx(nrange, nidx); - } long lidx = gkyl_range_idx(update_range, iter.idx); const double *arr_p = gkyl_array_cfetch(modal_fld, lidx); - double fao[num_basis*num_comp]; + double fao[num_basis * num_comp]; - for (int i=0; inum_quad; ++k){ - cbasis->modal_to_quad_nodal(&arr_p[num_basis*i], fnodal, k); + for (int k = 0; k < cbasis->num_quad; ++k) { + cbasis->modal_to_quad_nodal(&arr_p[num_basis * i], fnodal, k); } // copy so nodal values for each return value are contiguous // (recall that function can have more than one return value) - for (int k=0; knum_basis; int cpoly_order = cbasis->poly_order; @@ -392,28 +412,28 @@ gkyl_nodal_ops_m2n_corners_p2(const struct gkyl_nodal_ops *nodal_ops, gkyl_range_iter_init(&iter, update_range); int nidx[3]; long lin_nidx[num_basis]; - + while (gkyl_range_iter_next(&iter)) { - for (int i=0; indim; j++){ - nidx[j] = 2*(iter.idx[j]-update_range->lower[j]) + (temp[j] + 1) ; + for (int i = 0; i < num_basis; ++i) { + const double *temp = gkyl_array_cfetch(nodes, i); + for (int j = 0; j < grid->ndim; j++) { + nidx[j] = 2 * (iter.idx[j] - update_range->lower[j]) + (temp[j] + 1); } lin_nidx[i] = gkyl_range_idx(nrange, nidx); } long lidx = gkyl_range_idx(update_range, iter.idx); const double *arr_p = gkyl_array_cfetch(modal_fld, lidx); - double fao[num_basis*num_comp]; + double fao[num_basis * num_comp]; // already fetched modal coeffs in arr_p // Now we are going to need to fill the nodal values // So in the loop of num_nodes/num_basis we will fetch the nodal value at lin_nidx[i] // at each place do an eval_basis at logical coords - - for (int i=0; ieval_expand(node_i, &arr_p[j*num_basis]); + + for (int i = 0; i < num_basis; ++i) { + double *temp = gkyl_array_fetch(nodal_fld, lin_nidx[i]); + const double *node_i = gkyl_array_cfetch(nodes, i); + for (int j = 0; j < num_comp; ++j) { + temp[j] = cbasis->eval_expand(node_i, &arr_p[j * num_basis]); } } } @@ -421,25 +441,29 @@ gkyl_nodal_ops_m2n_corners_p2(const struct gkyl_nodal_ops *nodal_ops, gkyl_array_release(nodes); } -void -gkyl_nodal_ops_m2n_corners(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *modal_fld) +void gkyl_nodal_ops_m2n_corners( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, struct gkyl_array *nodal_fld, + const struct gkyl_array *modal_fld +) { - #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(nodal_fld)) { - if (nodal_ops->poly_order==2) + if (nodal_ops->poly_order == 2) { assert(false); - return gkyl_nodal_ops_m2n_cu(nodal_ops, cbasis, grid, - nrange, update_range, num_comp, - nodal_fld, modal_fld); + } + return gkyl_nodal_ops_m2n_cu( + nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld + ); } -#endif +#endif - if(cbasis->poly_order == 2) - return gkyl_nodal_ops_m2n_corners_p2(nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld); + if (cbasis->poly_order == 2) { + return gkyl_nodal_ops_m2n_corners_p2( + nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld + ); + } int num_basis = cbasis->num_basis; struct gkyl_range_iter iter; @@ -450,13 +474,12 @@ gkyl_nodal_ops_m2n_corners(const struct gkyl_nodal_ops *nodal_ops, while (gkyl_range_iter_next(&iter)) { // iter.idx = nidx lin_nidx = gkyl_range_idx(nrange, idx); int node_idx = 0; - for( int j = 0; j < grid->ndim; j++){ - int mod = j==0 ? 1 : 0; + for (int j = 0; j < grid->ndim; j++) { + int mod = j == 0 ? 1 : 0; if (iter.idx[j] == nrange->upper[j]) { - idx[j] = iter.idx[j] + update_range->lower[j]-1; - node_idx += 2*j + mod; - } - else { + idx[j] = iter.idx[j] + update_range->lower[j] - 1; + node_idx += 2 * j + mod; + } else { idx[j] = iter.idx[j] + update_range->lower[j]; } } @@ -465,23 +488,20 @@ gkyl_nodal_ops_m2n_corners(const struct gkyl_nodal_ops *nodal_ops, const double *arr_p = gkyl_array_cfetch(modal_fld, lidx); double *temp = gkyl_array_fetch(nodal_fld, lin_nidx); - - const double *node_i = gkyl_array_cfetch(nodal_ops->nodes, node_idx); - for (int j=0; jeval_expand(node_i, &arr_p[j*num_basis]); + const double *node_i = gkyl_array_cfetch(nodal_ops->nodes, node_idx); + for (int j = 0; j < num_comp; ++j) { + temp[j] = cbasis->eval_expand(node_i, &arr_p[j * num_basis]); } - - } } -void -gkyl_nodal_ops_m2n_interior(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *modal_fld) +void gkyl_nodal_ops_m2n_interior( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, struct gkyl_array *nodal_fld, + const struct gkyl_array *modal_fld +) { - int num_basis = cbasis->num_basis; int cpoly_order = cbasis->poly_order; double fnodal[num_basis]; // to store nodal function values @@ -490,122 +510,128 @@ gkyl_nodal_ops_m2n_interior(const struct gkyl_nodal_ops *nodal_ops, gkyl_range_iter_init(&iter, update_range); int nidx[3]; long lin_nidx[num_basis]; - - while (gkyl_range_iter_next(&iter)) { - for (int i=0; inodes,i); - for( int j = 0; j < grid->ndim; j++) { - int mod = (j==1 && grid->ndim==3) ? 2 * (i/4) : 0; - if (j < grid->ndim-1) - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i/((int) pow(2,grid->ndim-1-j)) - mod; - else - nidx[j] = (iter.idx[j]-update_range->lower[j])*2 + i%2 ; + while (gkyl_range_iter_next(&iter)) { + for (int i = 0; i < num_basis; ++i) { + const double *temp = gkyl_array_cfetch(nodal_ops->nodes, i); + for (int j = 0; j < grid->ndim; j++) { + int mod = (j == 1 && grid->ndim == 3) ? 2 * (i / 4) : 0; + if (j < grid->ndim - 1) { + nidx[j] = (iter.idx[j] - update_range->lower[j]) * 2 + + i / ((int)pow(2, grid->ndim - 1 - j)) - mod; + } else { + nidx[j] = (iter.idx[j] - update_range->lower[j]) * 2 + i % 2; + } } lin_nidx[i] = gkyl_range_idx(nrange, nidx); } long lidx = gkyl_range_idx(update_range, iter.idx); const double *arr_p = gkyl_array_cfetch(modal_fld, lidx); - double fao[num_basis*num_comp]; - - + double fao[num_basis * num_comp]; - for (int i=0; inum_quad; ++k){ - cbasis->modal_to_quad_nodal(&arr_p[num_basis*i], fnodal, k); + for (int k = 0; k < cbasis->num_quad; ++k) { + cbasis->modal_to_quad_nodal(&arr_p[num_basis * i], fnodal, k); } // copy so nodal values for each return value are contiguous // (recall that function can have more than one return value) - for (int k=0; knum_basis; int idx[3]; int midx[3]; idx[deflated_grid->ndim] = extra_idx; //while (gkyl_range_iter_next(&iter)) { // iter.idx = nidx - for(int linc1 = 0; linc1 < deflated_nrange->volume; linc1++){ + for (int linc1 = 0; linc1 < deflated_nrange->volume; linc1++) { gkyl_sub_range_inv_idx(deflated_nrange, linc1, idx); long linc = gkyl_range_idx(nrange, idx); int node_idx = 0; - for( int j = 0; j < deflated_grid->ndim; j++){ - int mod = j==0 ? 1 : 0; + for (int j = 0; j < deflated_grid->ndim; j++) { + int mod = j == 0 ? 1 : 0; if (idx[j] == deflated_nrange->upper[j]) { - midx[j] = idx[j] + deflated_update_range->lower[j]-1; - node_idx += 2*j + mod; - } - else { + midx[j] = idx[j] + deflated_update_range->lower[j] - 1; + node_idx += 2 * j + mod; + } else { midx[j] = idx[j] + deflated_update_range->lower[j]; } } long lidx = gkyl_range_idx(deflated_update_range, midx); const double *arr_p = gkyl_array_cfetch(deflated_modal_fld, lidx); double *temp = gkyl_array_fetch(nodal_fld, linc); - const double *node_i = gkyl_array_cfetch(nodal_ops->nodes, node_idx); - for (int j=0; jeval_expand(node_i, &arr_p[j*num_basis]); + const double *node_i = gkyl_array_cfetch(nodal_ops->nodes, node_idx); + for (int j = 0; j < num_comp; ++j) { + temp[j] = deflated_cbasis->eval_expand(node_i, &arr_p[j * num_basis]); } } } - -void -gkyl_nodal_ops_n2m(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - const struct gkyl_array *nodal_fld, struct gkyl_array *modal_fld, bool use_quad) +void gkyl_nodal_ops_n2m( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, const struct gkyl_array *nodal_fld, + struct gkyl_array *modal_fld, bool use_quad +) { - if (use_quad) - return gkyl_nodal_ops_n2m_interior(nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld); - else - return gkyl_nodal_ops_n2m_corners(nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld); + if (use_quad) { + return gkyl_nodal_ops_n2m_interior( + nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld + ); + } else { + return gkyl_nodal_ops_n2m_corners( + nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld + ); + } } -void -gkyl_nodal_ops_m2n(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *modal_fld, bool use_quad) +void gkyl_nodal_ops_m2n( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, struct gkyl_array *nodal_fld, + const struct gkyl_array *modal_fld, bool use_quad +) { - if (use_quad) - return gkyl_nodal_ops_m2n_interior(nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld); - else - return gkyl_nodal_ops_m2n_corners(nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld); + if (use_quad) { + return gkyl_nodal_ops_m2n_interior( + nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld + ); + } else { + return gkyl_nodal_ops_m2n_corners( + nodal_ops, cbasis, grid, nrange, update_range, num_comp, nodal_fld, modal_fld + ); + } } - -void -gkyl_nodal_ops_release(struct gkyl_nodal_ops *up) +void gkyl_nodal_ops_release(struct gkyl_nodal_ops *up) { gkyl_array_release(up->nodes); gkyl_free(up); diff --git a/core/zero/nodal_ops_cu.cu b/core/zero/nodal_ops_cu.cu index b2483ad466..4ba06f38e6 100644 --- a/core/zero/nodal_ops_cu.cu +++ b/core/zero/nodal_ops_cu.cu @@ -10,11 +10,11 @@ extern "C" { #include } -__global__ static void -gkyl_nodal_ops_n2m_cu_kernel(const struct gkyl_basis *cbasis, - struct gkyl_rect_grid grid, struct gkyl_range nrange, struct gkyl_range update_range, - const struct gkyl_array *nodes, int num_comp, - const struct gkyl_array *nodal_fld, struct gkyl_array *modal_fld) +__global__ static void gkyl_nodal_ops_n2m_cu_kernel( + const struct gkyl_basis *cbasis, struct gkyl_rect_grid grid, struct gkyl_range nrange, + struct gkyl_range update_range, const struct gkyl_array *nodes, int num_comp, + const struct gkyl_array *nodal_fld, struct gkyl_array *modal_fld +) { double xc[GKYL_MAX_DIM]; int idx[GKYL_MAX_DIM]; @@ -25,8 +25,8 @@ gkyl_nodal_ops_n2m_cu_kernel(const struct gkyl_basis *cbasis, int nidx[3]; long lin_nidx[20]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < update_range.volume; linc1 += blockDim.x*gridDim.x) { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < update_range.volume; + linc1 += blockDim.x * gridDim.x) { // inverse index from linc1 to idxc // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idxc={1,1,...} // since update_range is a subrange @@ -37,66 +37,69 @@ gkyl_nodal_ops_n2m_cu_kernel(const struct gkyl_basis *cbasis, // linc will have jumps in it to jump over ghost cells long linc = gkyl_range_idx(&update_range, idx); - for (int i=0; inodal_to_modal(fnodal, &arr_p[num_basis*i]); + cbasis->nodal_to_modal(fnodal, &arr_p[num_basis * i]); } } } -void -gkyl_nodal_ops_n2m_cu(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - const struct gkyl_array *nodal_fld, struct gkyl_array *modal_fld) +void gkyl_nodal_ops_n2m_cu( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, const struct gkyl_array *nodal_fld, + struct gkyl_array *modal_fld +) { int nblocks = update_range->nblocks; int nthreads = update_range->nthreads; - gkyl_nodal_ops_n2m_cu_kernel<<>>(cbasis, *grid, - *nrange, *update_range, nodal_ops->nodes->on_dev, num_comp, - nodal_fld->on_dev, modal_fld->on_dev); + gkyl_nodal_ops_n2m_cu_kernel<< > >( + cbasis, *grid, *nrange, *update_range, nodal_ops->nodes->on_dev, num_comp, nodal_fld->on_dev, + modal_fld->on_dev + ); } -__global__ static void -gkyl_nodal_ops_m2n_cu_kernel(const struct gkyl_basis *cbasis, - struct gkyl_rect_grid grid, struct gkyl_range nrange, struct gkyl_range update_range, - const struct gkyl_array *nodes, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *modal_fld) +__global__ static void gkyl_nodal_ops_m2n_cu_kernel( + const struct gkyl_basis *cbasis, struct gkyl_rect_grid grid, struct gkyl_range nrange, + struct gkyl_range update_range, const struct gkyl_array *nodes, int num_comp, + struct gkyl_array *nodal_fld, const struct gkyl_array *modal_fld +) { int idx[GKYL_MAX_DIM]; int midx[GKYL_MAX_DIM]; int num_basis = cbasis->num_basis; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < nrange.volume; linc1 += blockDim.x*gridDim.x) { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < nrange.volume; + linc1 += blockDim.x * gridDim.x) { // inverse index from linc1 to idxc // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idxc={1,1,...} // since update_range is a subrange @@ -105,53 +108,55 @@ gkyl_nodal_ops_m2n_cu_kernel(const struct gkyl_basis *cbasis, // linc will have jumps in it to jump over ghost cells long linc = gkyl_range_idx(&nrange, idx); int node_idx = 0; - for( int j = 0; j < grid.ndim; j++){ - int mod = j==0 ? 1 : 0; + for (int j = 0; j < grid.ndim; j++) { + int mod = j == 0 ? 1 : 0; if (idx[j] == nrange.upper[j]) { - midx[j] = idx[j] + update_range.lower[j]-1; - node_idx += 2*j + mod; - } - else { + midx[j] = idx[j] + update_range.lower[j] - 1; + node_idx += 2 * j + mod; + } else { midx[j] = idx[j] + update_range.lower[j]; } } long lidx = gkyl_range_idx(&update_range, midx); - const double *arr_p = (const double *) gkyl_array_cfetch(modal_fld, lidx); - double *temp = (double *) gkyl_array_fetch(nodal_fld, linc); - const double *node_i = (const double *) gkyl_array_cfetch(nodes, node_idx); - for (int j=0; jeval_expand(node_i, &arr_p[j*num_basis]); + const double *arr_p = (const double *)gkyl_array_cfetch(modal_fld, lidx); + double *temp = (double *)gkyl_array_fetch(nodal_fld, linc); + const double *node_i = (const double *)gkyl_array_cfetch(nodes, node_idx); + for (int j = 0; j < num_comp; ++j) { + temp[j] = cbasis->eval_expand(node_i, &arr_p[j * num_basis]); } } } -void -gkyl_nodal_ops_m2n_cu(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *nrange, const struct gkyl_range *update_range, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *modal_fld) +void gkyl_nodal_ops_m2n_cu( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_range *nrange, + const struct gkyl_range *update_range, int num_comp, struct gkyl_array *nodal_fld, + const struct gkyl_array *modal_fld +) { int nblocks = update_range->nblocks; int nthreads = update_range->nthreads; - gkyl_nodal_ops_m2n_cu_kernel<<>>(cbasis, *grid, - *nrange, *update_range, nodal_ops->nodes->on_dev, num_comp, - nodal_fld->on_dev, modal_fld->on_dev); + gkyl_nodal_ops_m2n_cu_kernel<< > >( + cbasis, *grid, *nrange, *update_range, nodal_ops->nodes->on_dev, num_comp, nodal_fld->on_dev, + modal_fld->on_dev + ); } -__global__ static void -gkyl_nodal_ops_m2n_deflated_cu_kernel(const struct gkyl_basis *deflated_cbasis, - struct gkyl_rect_grid deflated_grid, struct gkyl_range nrange, struct gkyl_range def_nrange, struct gkyl_range deflated_update_range, - const struct gkyl_array *nodes, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *deflated_modal_fld, int extra_idx) +__global__ static void gkyl_nodal_ops_m2n_deflated_cu_kernel( + const struct gkyl_basis *deflated_cbasis, struct gkyl_rect_grid deflated_grid, + struct gkyl_range nrange, struct gkyl_range def_nrange, struct gkyl_range deflated_update_range, + const struct gkyl_array *nodes, int num_comp, struct gkyl_array *nodal_fld, + const struct gkyl_array *deflated_modal_fld, int extra_idx +) { int idx[GKYL_MAX_DIM]; int midx[GKYL_MAX_DIM]; int num_basis = deflated_cbasis->num_basis; idx[deflated_grid.ndim] = extra_idx; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < def_nrange.volume; linc1 += blockDim.x*gridDim.x) { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < def_nrange.volume; + linc1 += blockDim.x * gridDim.x) { // inverse index from linc1 to idxc // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idxc={1,1,...} // since update_range is a subrange @@ -160,36 +165,38 @@ gkyl_nodal_ops_m2n_deflated_cu_kernel(const struct gkyl_basis *deflated_cbasis, // linc will have jumps in it to jump over ghost cells long linc = gkyl_range_idx(&nrange, idx); int node_idx = 0; - for( int j = 0; j < deflated_grid.ndim; j++){ - int mod = j==0 ? 1 : 0; + for (int j = 0; j < deflated_grid.ndim; j++) { + int mod = j == 0 ? 1 : 0; if (idx[j] == def_nrange.upper[j]) { - midx[j] = idx[j] + deflated_update_range.lower[j]-1; - node_idx += 2*j + mod; - } - else { + midx[j] = idx[j] + deflated_update_range.lower[j] - 1; + node_idx += 2 * j + mod; + } else { midx[j] = idx[j] + deflated_update_range.lower[j]; } } long lidx = gkyl_range_idx(&deflated_update_range, midx); - const double *arr_p = (const double *) gkyl_array_cfetch(deflated_modal_fld, lidx); - double *temp = (double *) gkyl_array_fetch(nodal_fld, linc); - const double *node_i = (const double *) gkyl_array_cfetch(nodes, node_idx); - for (int j=0; jeval_expand(node_i, &arr_p[j*num_basis]); + const double *arr_p = (const double *)gkyl_array_cfetch(deflated_modal_fld, lidx); + double *temp = (double *)gkyl_array_fetch(nodal_fld, linc); + const double *node_i = (const double *)gkyl_array_cfetch(nodes, node_idx); + for (int j = 0; j < num_comp; ++j) { + temp[j] = deflated_cbasis->eval_expand(node_i, &arr_p[j * num_basis]); } } } -void -gkyl_nodal_ops_m2n_deflated_cu(const struct gkyl_nodal_ops *nodal_ops, - const struct gkyl_basis *deflated_cbasis, const struct gkyl_rect_grid *deflated_grid, - const struct gkyl_range *nrange, const struct gkyl_range *deflated_nrange, const struct gkyl_range *deflated_update_range, int num_comp, - struct gkyl_array *nodal_fld, const struct gkyl_array *deflated_modal_fld, int extra_idx) +void gkyl_nodal_ops_m2n_deflated_cu( + const struct gkyl_nodal_ops *nodal_ops, const struct gkyl_basis *deflated_cbasis, + const struct gkyl_rect_grid *deflated_grid, const struct gkyl_range *nrange, + const struct gkyl_range *deflated_nrange, const struct gkyl_range *deflated_update_range, + int num_comp, struct gkyl_array *nodal_fld, const struct gkyl_array *deflated_modal_fld, + int extra_idx +) { int nblocks = deflated_update_range->nblocks; int nthreads = deflated_update_range->nthreads; - gkyl_nodal_ops_m2n_deflated_cu_kernel<<>>(deflated_cbasis, *deflated_grid, - *nrange, *deflated_nrange, *deflated_update_range, nodal_ops->nodes->on_dev, num_comp, - nodal_fld->on_dev, deflated_modal_fld->on_dev, extra_idx); + gkyl_nodal_ops_m2n_deflated_cu_kernel<< > >( + deflated_cbasis, *deflated_grid, *nrange, *deflated_nrange, *deflated_update_range, + nodal_ops->nodes->on_dev, num_comp, nodal_fld->on_dev, deflated_modal_fld->on_dev, extra_idx + ); } diff --git a/core/zero/null_comm.c b/core/zero/null_comm.c index e3721a5942..591582fad3 100644 --- a/core/zero/null_comm.c +++ b/core/zero/null_comm.c @@ -11,24 +11,26 @@ #include // Create ghost and skin sub-ranges given a parent range -static void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { -#define G_MAX(a,b) (a)>(b)?(a):(b) - +#define G_MAX(a, b) (a) > (b) ? (a) : (b) + int ndim = parent->ndim; long max_vol = 0; - - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); + + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); max_vol = G_MAX(max_vol, sgr->lower_skin[d].volume); max_vol = G_MAX(max_vol, sgr->lower_ghost[d].volume); - - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); max_vol = G_MAX(max_vol, sgr->upper_skin[d].volume); max_vol = G_MAX(max_vol, sgr->upper_ghost[d].volume); @@ -40,24 +42,26 @@ skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, // Create ghost and skin sub-ranges given a parent range: includes // corners -static void -skin_ghost_ranges_with_corners_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_with_corners_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { -#define G_MAX(a,b) (a)>(b)?(a):(b) - +#define G_MAX(a, b) (a) > (b) ? (a) : (b) + int ndim = parent->ndim; long max_vol = 0; - - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); + + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_with_corners_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); max_vol = G_MAX(max_vol, sgr->lower_skin[d].volume); max_vol = G_MAX(max_vol, sgr->lower_ghost[d].volume); - - gkyl_skin_ghost_with_corners_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + + gkyl_skin_ghost_with_corners_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); max_vol = G_MAX(max_vol, sgr->upper_skin[d].volume); max_vol = G_MAX(max_vol, sgr->upper_ghost[d].volume); @@ -67,10 +71,9 @@ skin_ghost_ranges_with_corners_init(struct skin_ghost_ranges *sgr, #undef G_MAX } -static void -comm_free(const struct gkyl_ref_count *ref) +static void comm_free(const struct gkyl_ref_count *ref) { - struct gkyl_comm *comm = container_of(ref, struct gkyl_comm, ref_count); + struct gkyl_comm *comm = container_of(ref, struct gkyl_comm, ref_count); struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); cmap_l2sgr_drop(&null_comm->l2sgr); @@ -80,70 +83,70 @@ comm_free(const struct gkyl_ref_count *ref) gkyl_free(null_comm); } -static int -get_rank(struct gkyl_comm *comm, int *rank) +static int get_rank(struct gkyl_comm *comm, int *rank) { *rank = 0; return 0; } -static int -get_size(struct gkyl_comm *comm, int *sz) +static int get_size(struct gkyl_comm *comm, int *sz) { *sz = 1; return 0; } -static int -allreduce(struct gkyl_comm *comm, enum gkyl_elem_type type, - enum gkyl_array_op op, int nelem, const void *inp, void *out) +static int allreduce( + struct gkyl_comm *comm, enum gkyl_elem_type type, enum gkyl_array_op op, int nelem, + const void *inp, void *out +) { struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); - if (null_comm->use_gpu) - gkyl_cu_memcpy(out, inp, gkyl_elem_type_size[type]*nelem, GKYL_CU_MEMCPY_D2D); - else - memcpy(out, inp, gkyl_elem_type_size[type]*nelem); + if (null_comm->use_gpu) { + gkyl_cu_memcpy(out, inp, gkyl_elem_type_size[type] * nelem, GKYL_CU_MEMCPY_D2D); + } else { + memcpy(out, inp, gkyl_elem_type_size[type] * nelem); + } return 0; } -static int -allreduce_host(struct gkyl_comm *comm, enum gkyl_elem_type type, - enum gkyl_array_op op, int nelem, const void *inp, void *out) +static int allreduce_host( + struct gkyl_comm *comm, enum gkyl_elem_type type, enum gkyl_array_op op, int nelem, + const void *inp, void *out +) { struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); - memcpy(out, inp, gkyl_elem_type_size[type]*nelem); + memcpy(out, inp, gkyl_elem_type_size[type] * nelem); return 0; } -static int -array_allgather(struct gkyl_comm *comm, - const struct gkyl_range *local, const struct gkyl_range *global, - const struct gkyl_array *array_local, struct gkyl_array *array_global) +static int array_allgather( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *global, + const struct gkyl_array *array_local, struct gkyl_array *array_global +) { gkyl_array_copy(array_global, array_local); return 0; } -static int -array_bcast(struct gkyl_comm *comm, const struct gkyl_array *asend, - struct gkyl_array *arecv, int root) +static int array_bcast( + struct gkyl_comm *comm, const struct gkyl_array *asend, struct gkyl_array *arecv, int root +) { gkyl_array_copy(arecv, asend); return 0; } -static int -array_sync(struct gkyl_comm *comm, - const struct gkyl_range *local, const struct gkyl_range *local_ext, - struct gkyl_array *array) +static int array_sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + struct gkyl_array *array +) { return 0; } // apply periodic BCs static void -apply_periodic_bc(const struct skin_ghost_ranges *sgr, char *data, - int dir, struct gkyl_array *f) +apply_periodic_bc(const struct skin_ghost_ranges *sgr, char *data, int dir, struct gkyl_array *f) { gkyl_array_copy_to_buffer(data, f, &(sgr->lower_skin[dir])); gkyl_array_copy_from_buffer(f, data, &(sgr->upper_ghost[dir])); @@ -152,17 +155,18 @@ apply_periodic_bc(const struct skin_ghost_ranges *sgr, char *data, gkyl_array_copy_from_buffer(f, data, &(sgr->lower_ghost[dir])); } -static int -array_per_no_corners_sync(struct gkyl_comm *comm, const struct gkyl_range *local, - const struct gkyl_range *local_ext, - int nper_dirs, const int *per_dirs, struct gkyl_array *array) +static int array_per_no_corners_sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + int nper_dirs, const int *per_dirs, struct gkyl_array *array +) { struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); int nghost[GKYL_MAX_DIM]; - for (int d=0; ddecomp->ndim; ++d) - nghost[d] = local_ext->upper[d]-local->upper[d]; - + for (int d = 0; d < null_comm->decomp->ndim; ++d) { + nghost[d] = local_ext->upper[d] - local->upper[d]; + } + long lkey = gkyl_range_idx(&null_comm->grange, nghost); if (!cmap_l2sgr_contains(&null_comm->l2sgr, lkey)) { @@ -172,30 +176,33 @@ array_per_no_corners_sync(struct gkyl_comm *comm, const struct gkyl_range *local } const cmap_l2sgr_value *val = cmap_l2sgr_get(&null_comm->l2sgr, lkey); - long max_vol_esnz = val->second.max_vol*array->esznc; - - if (max_vol_esnz > gkyl_mem_buff_size(null_comm->pbuff)) + long max_vol_esnz = val->second.max_vol * array->esznc; + + if (max_vol_esnz > gkyl_mem_buff_size(null_comm->pbuff)) { gkyl_mem_buff_resize(null_comm->pbuff, max_vol_esnz); + } char *data = gkyl_mem_buff_data(null_comm->pbuff); - for (int d=0; dsecond, data, per_dirs[d], array); + } return 0; } -static int -array_per_with_corners_sync(struct gkyl_comm *comm, const struct gkyl_range *local, - const struct gkyl_range *local_ext, - int nper_dirs, const int *per_dirs, struct gkyl_array *array) +static int array_per_with_corners_sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + int nper_dirs, const int *per_dirs, struct gkyl_array *array +) { struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); int nghost[GKYL_MAX_DIM]; - for (int d=0; ddecomp->ndim; ++d) - nghost[d] = local_ext->upper[d]-local->upper[d]; - + for (int d = 0; d < null_comm->decomp->ndim; ++d) { + nghost[d] = local_ext->upper[d] - local->upper[d]; + } + long lkey = gkyl_range_idx(&null_comm->grange, nghost); if (!cmap_l2sgr_contains(&null_comm->l2sgr_wc, lkey)) { @@ -205,135 +212,122 @@ array_per_with_corners_sync(struct gkyl_comm *comm, const struct gkyl_range *loc } const cmap_l2sgr_value *val = cmap_l2sgr_get(&null_comm->l2sgr_wc, lkey); - long max_vol_esnz = val->second.max_vol*array->esznc; - - if (max_vol_esnz > gkyl_mem_buff_size(null_comm->pbuff)) + long max_vol_esnz = val->second.max_vol * array->esznc; + + if (max_vol_esnz > gkyl_mem_buff_size(null_comm->pbuff)) { gkyl_mem_buff_resize(null_comm->pbuff, max_vol_esnz); + } char *data = gkyl_mem_buff_data(null_comm->pbuff); - for (int d=0; dsecond, data, per_dirs[d], array); + } return 0; } -static int -array_per_sync(struct gkyl_comm *comm, const struct gkyl_range *local, - const struct gkyl_range *local_ext, - int nper_dirs, const int *per_dirs, struct gkyl_array *array) +static int array_per_sync( + struct gkyl_comm *comm, const struct gkyl_range *local, const struct gkyl_range *local_ext, + int nper_dirs, const int *per_dirs, struct gkyl_array *array +) { - struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); + struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); array_per_no_corners_sync(comm, local, local_ext, nper_dirs, per_dirs, array); - if (null_comm->sync_corners) + if (null_comm->sync_corners) { array_per_with_corners_sync(comm, local, local_ext, nper_dirs, per_dirs, array); + } return 0; } -static int -barrier(struct gkyl_comm *comm) +static int barrier(struct gkyl_comm *comm) { return 0; } -static int array_write(struct gkyl_comm *comm, - const struct gkyl_rect_grid *grid, - const struct gkyl_range *range, - const struct gkyl_msgpack_data *meta, - const struct gkyl_array *arr, const char *fname) +static int array_write( + struct gkyl_comm *comm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + const struct gkyl_msgpack_data *meta, const struct gkyl_array *arr, const char *fname +) { return gkyl_grid_sub_array_write(grid, range, meta, arr, fname); } -static int -array_read(struct gkyl_comm *comm, - const struct gkyl_rect_grid *grid, const struct gkyl_range *range, - struct gkyl_array *arr, const char *fname) +static int array_read( + struct gkyl_comm *comm, const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + struct gkyl_array *arr, const char *fname +) { struct gkyl_rect_grid fgrid; int status = gkyl_grid_sub_array_read(&fgrid, range, arr, fname); if (status == 0) { - if (!gkyl_rect_grid_cmp(grid, &fgrid)) + if (!gkyl_rect_grid_cmp(grid, &fgrid)) { status = 1; + } } return status; } -static struct gkyl_comm* -extend_comm(const struct gkyl_comm *comm, const struct gkyl_range *erange) +static struct gkyl_comm *extend_comm(const struct gkyl_comm *comm, const struct gkyl_range *erange) { struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); // extend internal decomp object and create a new communicator struct gkyl_rect_decomp *ext_decomp = gkyl_rect_decomp_extended_new(erange, null_comm->decomp); - struct gkyl_comm *ext_comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = ext_decomp, - .use_gpu = null_comm->use_gpu, - .sync_corners = null_comm->sync_corners - } - ); + struct gkyl_comm *ext_comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.decomp = ext_decomp, .use_gpu = null_comm->use_gpu, .sync_corners = null_comm->sync_corners}); gkyl_rect_decomp_release(ext_decomp); - + return ext_comm; } -static struct gkyl_comm* +static struct gkyl_comm * split_comm(const struct gkyl_comm *comm, int color, struct gkyl_rect_decomp *new_decomp) { - struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); + struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); - return gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = null_comm->use_gpu, - .sync_corners = null_comm->sync_corners, - .decomp = new_decomp - } - ); + return gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = null_comm->use_gpu, .sync_corners = null_comm->sync_corners, .decomp = new_decomp}); } -static struct gkyl_comm* -create_comm_from_ranks(const struct gkyl_comm *comm, - int nranks, const int *ranks, struct gkyl_rect_decomp *new_decomp, - bool *is_valid) +static struct gkyl_comm *create_comm_from_ranks( + const struct gkyl_comm *comm, int nranks, const int *ranks, struct gkyl_rect_decomp *new_decomp, + bool *is_valid +) { if (nranks > 1) { *is_valid = false; return 0; } - + *is_valid = true; - - struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); - return gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = null_comm->use_gpu, - .sync_corners = null_comm->sync_corners, - .decomp = new_decomp - } - ); + + struct null_comm *null_comm = container_of(comm, struct null_comm, priv_comm.pub_comm); + return gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = null_comm->use_gpu, .sync_corners = null_comm->sync_corners, .decomp = new_decomp}); } -struct gkyl_comm* -gkyl_null_comm_inew(const struct gkyl_null_comm_inp *inp) +struct gkyl_comm *gkyl_null_comm_inew(const struct gkyl_null_comm_inp *inp) { struct null_comm *comm = gkyl_malloc(sizeof *comm); strcpy(comm->priv_comm.pub_comm.id, "null_comm"); - comm->priv_comm.pub_comm.has_decomp = true; + comm->priv_comm.pub_comm.has_decomp = true; if (0 == inp->decomp) { comm->priv_comm.pub_comm.has_decomp = false; - + // construct a dummy decomposition - comm->decomp = - gkyl_rect_decomp_new_from_cuts_and_cells(1, (int[]) { 1 }, (int[]) { 1 }); - } - else { + comm->decomp = gkyl_rect_decomp_new_from_cuts_and_cells(1, (int[]){1}, (int[]){1}); + } else { comm->decomp = gkyl_rect_decomp_acquire(inp->decomp); } // construct range to hash ghost layout - int lower[GKYL_MAX_DIM] = { 0 }; + int lower[GKYL_MAX_DIM] = {0}; int upper[GKYL_MAX_DIM]; - for (int d=0; ddecomp->ndim; ++d) + for (int d = 0; d < comm->decomp->ndim; ++d) { upper[d] = GKYL_MAX_NGHOST; + } gkyl_range_init(&comm->grange, comm->decomp->ndim, lower, upper); comm->use_gpu = inp->use_gpu; @@ -341,10 +335,11 @@ gkyl_null_comm_inew(const struct gkyl_null_comm_inp *inp) comm->l2sgr = cmap_l2sgr_init(); comm->l2sgr_wc = cmap_l2sgr_init(); - if (comm->use_gpu) + if (comm->use_gpu) { comm->pbuff = gkyl_mem_buff_cu_new(1024); // will be reallocated - else + } else { comm->pbuff = gkyl_mem_buff_new(1024); // will be reallocated + } comm->priv_comm.get_rank = get_rank; comm->priv_comm.get_size = get_size; diff --git a/core/zero/null_pool.c b/core/zero/null_pool.c index 3630c3fb12..89f42f7f68 100644 --- a/core/zero/null_pool.c +++ b/core/zero/null_pool.c @@ -3,36 +3,32 @@ #include -static void -null_pool_free(const struct gkyl_ref_count *ref) +static void null_pool_free(const struct gkyl_ref_count *ref) { struct gkyl_job_pool *np = container_of(ref, struct gkyl_job_pool, ref_count); gkyl_free(np); } -static bool -null_pool_add_work(const struct gkyl_job_pool *jp, jp_work_func func, void *ctx) +static bool null_pool_add_work(const struct gkyl_job_pool *jp, jp_work_func func, void *ctx) { func(ctx); // run job immediately return true; } -static void -null_pool_wait(const struct gkyl_job_pool *jp) +static void null_pool_wait(const struct gkyl_job_pool *jp) { } -struct gkyl_job_pool* -gkyl_null_pool_new(int nthreads) +struct gkyl_job_pool *gkyl_null_pool_new(int nthreads) { struct gkyl_job_pool *np = gkyl_malloc(sizeof(struct gkyl_job_pool)); np->pool_size = nthreads; np->add_work = null_pool_add_work; np->wait = null_pool_wait; - + // set reference counter np->ref_count = gkyl_ref_count_init(null_pool_free); - + return np; } diff --git a/core/zero/proj_on_basis.c b/core/zero/proj_on_basis.c index 2d23038175..641c83f27f 100644 --- a/core/zero/proj_on_basis.c +++ b/core/zero/proj_on_basis.c @@ -25,39 +25,38 @@ struct gkyl_proj_on_basis { }; // Identity comp to phys coord mapping, for when user doesn't provide a map. -static inline void -c2p_identity(const double *xcomp, double *xphys, void *ctx) +static inline void c2p_identity(const double *xcomp, double *xphys, void *ctx) { struct gkyl_rect_grid *grid = ctx; int ndim = grid->ndim; - for (int d=0; dgrid = *inp->grid; - int num_quad = up->num_quad = inp->num_quad == 0 ? inp->basis->poly_order+1 : inp->num_quad; + int num_quad = up->num_quad = inp->num_quad == 0 ? inp->basis->poly_order + 1 : inp->num_quad; int num_ret_vals = up->num_ret_vals = inp->num_ret_vals; up->eval = inp->eval; up->ctx = inp->ctx; @@ -66,8 +65,7 @@ gkyl_proj_on_basis_inew(const struct gkyl_proj_on_basis_inp *inp) if (inp->c2p_func == 0) { up->c2p = c2p_identity; up->c2p_ctx = &up->grid; // Use grid as the context since all we need is ndim. - } - else { + } else { up->c2p = inp->c2p_func; up->c2p_ctx = inp->c2p_func_ctx; } @@ -80,32 +78,31 @@ gkyl_proj_on_basis_inew(const struct gkyl_proj_on_basis_inp *inp) // than computing them on the fly) memcpy(ordinates1, gkyl_gauss_ordinates[num_quad], sizeof(double[num_quad])); memcpy(weights1, gkyl_gauss_weights[num_quad], sizeof(double[num_quad])); - } - else { + } else { gkyl_gauleg(-1, 1, ordinates1, weights1, num_quad); } - } - else if (inp->qtype == GKYL_GAUSS_LOBATTO_QUAD) { - assert( (num_quad > 1) && (num_quad <= gkyl_gauss_max) ); - + } else if (inp->qtype == GKYL_GAUSS_LOBATTO_QUAD) { + assert((num_quad > 1) && (num_quad <= gkyl_gauss_max)); + // Gauss-Lobatto quadrature memcpy(ordinates1, gkyl_gauss_lobatto_ordinates[num_quad], sizeof(double[num_quad])); memcpy(weights1, gkyl_gauss_lobatto_weights[num_quad], sizeof(double[num_quad])); - } - else { + } else { fprintf(stderr, "Quadrature type not available. Exiting... \n"); assert(false); } // create range to loop over quadrature points int qshape[GKYL_MAX_DIM]; - for (int i=0; igrid->ndim; ++i) qshape[i] = num_quad; + for (int i = 0; i < inp->grid->ndim; ++i) { + qshape[i] = num_quad; + } struct gkyl_range qrange; gkyl_range_init_from_shape(&qrange, inp->grid->ndim, qshape); int tot_quad = up->tot_quad = qrange.volume; - // create ordinates and weights for multi-D quadrature + // create ordinates and weights for multi-D quadrature up->ordinates = gkyl_array_new(GKYL_DOUBLE, inp->grid->ndim, tot_quad); up->weights = gkyl_array_new(GKYL_DOUBLE, 1, tot_quad); @@ -114,24 +111,26 @@ gkyl_proj_on_basis_inew(const struct gkyl_proj_on_basis_inp *inp) while (gkyl_range_iter_next(&iter)) { long node = gkyl_range_idx(&qrange, iter.idx); - + // set ordinates double *ord = gkyl_array_fetch(up->ordinates, node); - for (int i=0; igrid->ndim; ++i) - ord[i] = ordinates1[iter.idx[i]-qrange.lower[i]]; - + for (int i = 0; i < inp->grid->ndim; ++i) { + ord[i] = ordinates1[iter.idx[i] - qrange.lower[i]]; + } + // set weights double *wgt = gkyl_array_fetch(up->weights, node); wgt[0] = 1.0; - for (int i=0; ibasis_at_ords = gkyl_array_new(GKYL_DOUBLE, inp->basis->num_basis, tot_quad); - for (int n=0; nbasis->eval(gkyl_array_fetch(up->ordinates, n), - gkyl_array_fetch(up->basis_at_ords, n)); + for (int n = 0; n < tot_quad; ++n) { + inp->basis->eval(gkyl_array_fetch(up->ordinates, n), gkyl_array_fetch(up->basis_at_ords, n)); + } return up; } @@ -141,66 +140,72 @@ int gkyl_proj_on_basis_get_tot_quad(const struct gkyl_proj_on_basis *up) return up->tot_quad; } -double* gkyl_proj_on_basis_fetch_ordinate(const struct gkyl_proj_on_basis *up, long node) +double *gkyl_proj_on_basis_fetch_ordinate(const struct gkyl_proj_on_basis *up, long node) { return gkyl_array_fetch(up->ordinates, node); } -static inline void -log_to_comp(int ndim, const double *eta, - const double * GKYL_RESTRICT dx, const double * GKYL_RESTRICT xc, - double* GKYL_RESTRICT xout) +static inline void log_to_comp( + int ndim, const double *eta, const double *GKYL_RESTRICT dx, const double *GKYL_RESTRICT xc, + double *GKYL_RESTRICT xout +) { // Convert logical to computational coordinates. - for (int d=0; dnum_basis; int tot_quad = up->tot_quad; int num_ret_vals = up->num_ret_vals; - const double* GKYL_RESTRICT weights = up->weights->data; - const double* GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; - const double* GKYL_RESTRICT func_at_ords = fun_at_ords->data; + const double *GKYL_RESTRICT weights = up->weights->data; + const double *GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; + const double *GKYL_RESTRICT func_at_ords = fun_at_ords->data; // arrangement of f is as: // c0[0], c0[1], ... c1[0], c1[1], .... // where c0, c1, ... are components of f (num_ret_vals) int offset = 0; - for (int n=0; nnum_ret_vals; int tot_quad = up->tot_quad; struct gkyl_array *fun_at_ords = gkyl_array_new(GKYL_DOUBLE, num_ret_vals, tot_quad); - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, update_range); - + while (gkyl_range_iter_next(&iter)) { gkyl_rect_grid_cell_center(&up->grid, iter.idx, xc); - for (int i=0; igrid.ndim, gkyl_array_cfetch(up->ordinates, i), - up->grid.dx, xc, xmu); + for (int i = 0; i < tot_quad; ++i) { + log_to_comp(up->grid.ndim, gkyl_array_cfetch(up->ordinates, i), up->grid.dx, xc, xmu); up->c2p(xmu, xmu, up->c2p_ctx); up->eval(tm, xmu, gkyl_array_fetch(fun_at_ords, i), up->ctx); } @@ -212,8 +217,7 @@ gkyl_proj_on_basis_advance(const struct gkyl_proj_on_basis *up, gkyl_array_release(fun_at_ords); } -void -gkyl_proj_on_basis_release(struct gkyl_proj_on_basis* up) +void gkyl_proj_on_basis_release(struct gkyl_proj_on_basis *up) { gkyl_array_release(up->ordinates); gkyl_array_release(up->weights); diff --git a/core/zero/proj_powsqrt_on_basis.c b/core/zero/proj_powsqrt_on_basis.c index 5e9078b428..ef6894b585 100644 --- a/core/zero/proj_powsqrt_on_basis.c +++ b/core/zero/proj_powsqrt_on_basis.c @@ -10,9 +10,12 @@ #include // create range to loop over quadrature points. -static inline struct gkyl_range get_qrange(int dim, int num_quad) { +static inline struct gkyl_range get_qrange(int dim, int num_quad) +{ int qshape[GKYL_MAX_DIM]; - for (int i=0; indim; double ordinates1[num_quad], weights1[num_quad]; @@ -32,8 +36,7 @@ init_quad_values(const struct gkyl_basis *basis, int num_quad, // than computing them on the fly) memcpy(ordinates1, gkyl_gauss_ordinates[num_quad], sizeof(double[num_quad])); memcpy(weights1, gkyl_gauss_weights[num_quad], sizeof(double[num_quad])); - } - else { + } else { gkyl_gauleg(-1, 1, ordinates1, weights1, num_quad); } @@ -58,24 +61,28 @@ init_quad_values(const struct gkyl_basis *basis, int num_quad, // set ordinates double *ord = gkyl_array_fetch(ordinates_ho, node); - for (int i=0; inum_basis, tot_quad); - if (use_gpu) + if (use_gpu) { *basis_at_ords = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis->num_basis, tot_quad); - else + } else { *basis_at_ords = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, tot_quad); - for (int n=0; neval(gkyl_array_fetch(ordinates_ho, n), gkyl_array_fetch(basis_at_ords_ho, n)); + } // copy host array to device array gkyl_array_copy(*weights, weights_ho); @@ -88,7 +95,7 @@ init_quad_values(const struct gkyl_basis *basis, int num_quad, return tot_quad; } -gkyl_proj_powsqrt_on_basis* +gkyl_proj_powsqrt_on_basis * gkyl_proj_powsqrt_on_basis_new(const struct gkyl_basis *basis, int num_quad, bool use_gpu) { gkyl_proj_powsqrt_on_basis *up = gkyl_malloc(sizeof(gkyl_proj_powsqrt_on_basis)); @@ -99,44 +106,49 @@ gkyl_proj_powsqrt_on_basis_new(const struct gkyl_basis *basis, int num_quad, boo up->use_gpu = use_gpu; // initialize data needed for quadrature - up->tot_quad = init_quad_values(basis, num_quad, &up->weights, - &up->basis_at_ords, use_gpu); + up->tot_quad = init_quad_values(basis, num_quad, &up->weights, &up->basis_at_ords, use_gpu); - if (up->use_gpu) + if (up->use_gpu) { up->fun_at_ords = NULL; - else - up->fun_at_ords = gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad); // Only used in CPU implementation. + } else { + up->fun_at_ords = + gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad); // Only used in CPU implementation. + } return up; } static void -proj_on_basis(const gkyl_proj_powsqrt_on_basis *up, const struct gkyl_array *fun_at_ords, double* f) +proj_on_basis(const gkyl_proj_powsqrt_on_basis *up, const struct gkyl_array *fun_at_ords, double *f) { int num_basis = up->num_basis; int tot_quad = up->tot_quad; - const double* GKYL_RESTRICT weights = up->weights->data; - const double* GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; - const double* GKYL_RESTRICT func_at_ords = fun_at_ords->data; + const double *GKYL_RESTRICT weights = up->weights->data; + const double *GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; + const double *GKYL_RESTRICT func_at_ords = fun_at_ords->data; - for (int k=0; kuse_gpu) + if (up->use_gpu) { return gkyl_proj_powsqrt_on_basis_advance_cu(up, range, expIn, fIn, fOut); + } #endif // Create range to loop over quadrature points. @@ -152,14 +164,14 @@ gkyl_proj_powsqrt_on_basis_advance(const gkyl_proj_powsqrt_on_basis *up, struct gkyl_range_iter qiter; gkyl_range_iter_init(&qiter, &qrange); while (gkyl_range_iter_next(&qiter)) { - int qidx = gkyl_range_idx(&qrange, qiter.idx); // Evaluate input function f at quad point. const double *b_ord = gkyl_array_cfetch(up->basis_at_ords, qidx); - double fIn_q=0.; - for (int k=0; knum_basis; ++k) - fIn_q += fIn_d[k]*b_ord[k]; + double fIn_q = 0.; + for (int k = 0; k < up->num_basis; ++k) { + fIn_q += fIn_d[k] * b_ord[k]; + } double *fOut_q = gkyl_array_fetch(up->fun_at_ords, qidx); @@ -170,15 +182,14 @@ gkyl_proj_powsqrt_on_basis_advance(const gkyl_proj_powsqrt_on_basis *up, // Compute expansion coefficients. proj_on_basis(up, up->fun_at_ords, gkyl_array_fetch(fOut, linidx)); } - } -void -gkyl_proj_powsqrt_on_basis_release(gkyl_proj_powsqrt_on_basis* up) +void gkyl_proj_powsqrt_on_basis_release(gkyl_proj_powsqrt_on_basis *up) { gkyl_array_release(up->weights); gkyl_array_release(up->basis_at_ords); - if (!up->use_gpu) + if (!up->use_gpu) { gkyl_array_release(up->fun_at_ords); + } gkyl_free(up); } diff --git a/core/zero/proj_powsqrt_on_basis_cu.cu b/core/zero/proj_powsqrt_on_basis_cu.cu index 709c7c4ed7..1b7cf22807 100644 --- a/core/zero/proj_powsqrt_on_basis_cu.cu +++ b/core/zero/proj_powsqrt_on_basis_cu.cu @@ -7,60 +7,62 @@ extern "C" { #include } -__global__ static void -gkyl_proj_powsqrt_on_basis_advance_cu_ker(int num_quad, - const struct gkyl_range range, const struct gkyl_array* GKYL_RESTRICT basis_at_ords, - const struct gkyl_array* GKYL_RESTRICT weights, double expIn, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT fOut) +__global__ static void gkyl_proj_powsqrt_on_basis_advance_cu_ker( + int num_quad, const struct gkyl_range range, const struct gkyl_array *GKYL_RESTRICT basis_at_ords, + const struct gkyl_array *GKYL_RESTRICT weights, double expIn, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT fOut +) { int num_basis = basis_at_ords->ncomp; int tot_quad = basis_at_ords->size; int idx[GKYL_MAX_DIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < range.volume; tid += blockDim.x*gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&range, tid, idx); long linidx = gkyl_range_idx(&range, idx); - const double *fIn_d = (const double *) gkyl_array_cfetch(fIn, linidx); + const double *fIn_d = (const double *)gkyl_array_cfetch(fIn, linidx); - double *fOut_d = (double *) gkyl_array_fetch(fOut, linidx); - for (int k=0; kdata; - const double *bo_d = (const double *) basis_at_ords->data; + const double *w_d = (const double *)weights->data; + const double *bo_d = (const double *)basis_at_ords->data; - for (int n=0; nnblocks, nthreads = range->nthreads; - gkyl_proj_powsqrt_on_basis_advance_cu_ker<<>> - (up->num_quad, *range, up->basis_at_ords->on_dev, - up->weights->on_dev, expIn, fIn->on_dev, fOut->on_dev); + gkyl_proj_powsqrt_on_basis_advance_cu_ker<< > >( + up->num_quad, *range, up->basis_at_ords->on_dev, up->weights->on_dev, expIn, fIn->on_dev, + fOut->on_dev + ); } diff --git a/core/zero/range.c b/core/zero/range.c index 3a927fa770..41695607f2 100644 --- a/core/zero/range.c +++ b/core/zero/range.c @@ -9,8 +9,7 @@ // flags and corresponding bit-masks enum range_flags { R_IS_SUB_RANGE }; -static const uint32_t masks[] = -{ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; +static const uint32_t masks[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; // sub-range flags #define SET_SUB_RANGE(flags) (flags) |= masks[R_IS_SUB_RANGE] @@ -18,36 +17,36 @@ static const uint32_t masks[] = #define IS_SUB_RANGE(flags) (((flags) & masks[R_IS_SUB_RANGE]) != 0) // Computes coefficients for mapping indices in row-major order -static void -calc_rowmajor_ac(struct gkyl_range* range, long ac[]) +static void calc_rowmajor_ac(struct gkyl_range *range, long ac[]) { int ndim = range->ndim; ac[ndim] = 1L; - for (int i=ndim-1; i>=1; --i) - ac[i] = ac[i+1]*gkyl_range_shape(range, i); + for (int i = ndim - 1; i >= 1; --i) { + ac[i] = ac[i + 1] * gkyl_range_shape(range, i); + } long start = 0L; - for (int i=0; ilower[i]; + for (int i = 0; i < ndim; ++i) { + start += ac[i + 1] * range->lower[i]; + } ac[0] = -start; } // Computes stuff needed for "skip iterator" -static long -calc_skip_iter(const struct gkyl_range *rng, int *remDir) +static long calc_skip_iter(const struct gkyl_range *rng, int *remDir) { int up[GKYL_MAX_DIM]; - for (int d=0; dndim; ++d) { + for (int d = 0; d < rng->ndim; ++d) { remDir[d] = 1; up[d] = rng->upper[d]; } int d = 0; long vol = rng->volume; long loidx = gkyl_range_idx(rng, rng->lower); - long del = gkyl_range_idx(rng,up)-loidx+1; + long del = gkyl_range_idx(rng, up) - loidx + 1; while (del != vol) { up[d] = rng->lower[d]; vol /= gkyl_range_shape(rng, d); - del = gkyl_range_idx(rng,up)-loidx+1; + del = gkyl_range_idx(rng, up) - loidx + 1; remDir[d] = 0; d += 1; } @@ -55,44 +54,47 @@ calc_skip_iter(const struct gkyl_range *rng, int *remDir) } // compute volume, safely (for malformed ranges) -static long -calc_volume_safely(int ndim, const int *lower, const int *upper) +static long calc_volume_safely(int ndim, const int *lower, const int *upper) { int is_zero_vol = 0; long vol = 1L; - for (int i=0; indim = ndim; rng->volume = 1L; - for (int i=0; iilo[i] = rng->lower[i] = lower[i]; rng->upper[i] = upper[i]; - rng->volume *= upper[i]-lower[i]+1; + rng->volume *= upper[i] - lower[i] + 1; // need to handle case when upper[i]volume = 0; - + if (is_zero_vol) { + rng->volume = 0; + } + calc_rowmajor_ac(rng, rng->ac); - gkyl_copy_long_arr(GKYL_MAX_DIM+1, rng->ac, rng->iac); + gkyl_copy_long_arr(GKYL_MAX_DIM + 1, rng->ac, rng->iac); int idxZero[GKYL_MAX_DIM]; - for (int i=0; ilinIdxZero = gkyl_range_idx(rng, idxZero); rng->nsplit = 1; @@ -102,107 +104,103 @@ gkyl_range_init(struct gkyl_range *rng, int ndim, // for CUDA ops rng->nthreads = GKYL_DEFAULT_NUM_THREADS; - rng->nblocks = rng->volume/rng->nthreads + 1; + rng->nblocks = rng->volume / rng->nthreads + 1; } -struct gkyl_range* -gkyl_range_new(int ndim, const int *lower, const int *upper) +struct gkyl_range *gkyl_range_new(int ndim, const int *lower, const int *upper) { - struct gkyl_range* out = gkyl_calloc(1, sizeof(*out)); + struct gkyl_range *out = gkyl_calloc(1, sizeof(*out)); gkyl_range_init(out, ndim, lower, upper); return out; } -void -gkyl_range_init_from_shape(struct gkyl_range *rng, int ndim, const int *shape) +void gkyl_range_init_from_shape(struct gkyl_range *rng, int ndim, const int *shape) { int lo[GKYL_MAX_DIM], up[GKYL_MAX_DIM]; - for (int i=0; indim, bdim = b->ndim; int lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - for (int d=0; dlower[d]; upper[d] = a->upper[d]; } - for (int d=0; dlower[d]; - upper[adim+d] = b->upper[d]; + for (int d = 0; d < bdim; ++d) { + lower[adim + d] = b->lower[d]; + upper[adim + d] = b->upper[d]; } - gkyl_range_init(rng, adim+bdim, lower, upper); + gkyl_range_init(rng, adim + bdim, lower, upper); } -void -gkyl_range_shift(struct gkyl_range *rng, const struct gkyl_range *inp, - const int *delta) +void gkyl_range_shift(struct gkyl_range *rng, const struct gkyl_range *inp, const int *delta) { int lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - for (int d=0; dndim; ++d) { + for (int d = 0; d < inp->ndim; ++d) { lower[d] = inp->lower[d] + delta[d]; upper[d] = inp->upper[d] + delta[d]; } gkyl_range_init(rng, inp->ndim, lower, upper); } -void -gkyl_range_reset_lower(struct gkyl_range *rng, const struct gkyl_range *inp, - const int *new_lower) +void gkyl_range_reset_lower( + struct gkyl_range *rng, const struct gkyl_range *inp, const int *new_lower +) { int lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - for (int d=0; dndim; ++d) { + for (int d = 0; d < inp->ndim; ++d) { lower[d] = new_lower[d]; upper[d] = new_lower[d] + gkyl_range_shape(inp, d) - 1; } - gkyl_range_init(rng, inp->ndim, lower, upper); + gkyl_range_init(rng, inp->ndim, lower, upper); } -int -gkyl_range_is_sub_range(const struct gkyl_range *rng) +int gkyl_range_is_sub_range(const struct gkyl_range *rng) { return IS_SUB_RANGE(rng->flags); } -void -gkyl_sub_range_init(struct gkyl_range *rng, - const struct gkyl_range *bigrng, const int *sublower, const int *subupper) +void gkyl_sub_range_init( + struct gkyl_range *rng, const struct gkyl_range *bigrng, const int *sublower, const int *subupper +) { rng->ndim = bigrng->ndim; rng->volume = 1L; - for (int i=0; indim; ++i) { + for (int i = 0; i < rng->ndim; ++i) { rng->lower[i] = sublower[i] >= bigrng->lower[i] ? sublower[i] : bigrng->lower[i]; rng->upper[i] = subupper[i] <= bigrng->upper[i] ? subupper[i] : bigrng->upper[i]; rng->ilo[i] = bigrng->ilo[i]; // so inv indexer works correctly - rng->volume *= rng->upper[i]-rng->lower[i]+1; + rng->volume *= rng->upper[i] - rng->lower[i] + 1; } - for (int i=0; indim+1; ++i) + for (int i = 0; i < rng->ndim + 1; ++i) { rng->ac[i] = bigrng->ac[i]; + } rng->linIdxZero = bigrng->linIdxZero; rng->nsplit = bigrng->nsplit; rng->tid = bigrng->tid; - + rng->flags = bigrng->flags; SET_SUB_RANGE(rng->flags); @@ -210,15 +208,14 @@ gkyl_sub_range_init(struct gkyl_range *rng, // properly struct gkyl_range sub_range; gkyl_range_init(&sub_range, rng->ndim, rng->lower, rng->upper); - gkyl_copy_long_arr(GKYL_MAX_DIM+1, sub_range.ac, rng->iac); + gkyl_copy_long_arr(GKYL_MAX_DIM + 1, sub_range.ac, rng->iac); // for CUDA ops rng->nthreads = GKYL_DEFAULT_NUM_THREADS; - rng->nblocks = rng->volume/rng->nthreads + 1; + rng->nblocks = rng->volume / rng->nthreads + 1; } -struct gkyl_range -gkyl_range_split(struct gkyl_range *rng, int nsplit, int tid) +struct gkyl_range gkyl_range_split(struct gkyl_range *rng, int nsplit, int tid) { struct gkyl_range r = *rng; r.nsplit = nsplit; @@ -229,14 +226,13 @@ gkyl_range_split(struct gkyl_range *rng, int nsplit, int tid) // Computes split and returns number of elements handled locally and // the initial index into the range. Number of elements is returned // and start index set in 'lower' -static long -range_calc_split(const struct gkyl_range *rng, int *lower) +static long range_calc_split(const struct gkyl_range *rng, int *lower) { const int nsplit = rng->nsplit, tid = rng->tid; - long quot = rng->volume/nsplit, rem = rng->volume % nsplit; - + long quot = rng->volume / nsplit, rem = rng->volume % nsplit; + long len = gkyl_range_split_len(rng); - long start = tid < rem ? tid*(quot+1) : rem*(quot+1) + (tid-rem)*quot; + long start = tid < rem ? tid * (quot + 1) : rem * (quot + 1) + (tid - rem) * quot; if (IS_SUB_RANGE(rng->flags)) { // as 'start' in sub-range we need to use an additional @@ -244,43 +240,43 @@ range_calc_split(const struct gkyl_range *rng, int *lower) struct gkyl_range subrange; gkyl_range_init(&subrange, rng->ndim, rng->lower, rng->upper); gkyl_range_inv_idx(&subrange, start, lower); - } - else { + } else { gkyl_range_inv_idx(rng, start, lower); } return len; } -long -gkyl_range_split_len(const struct gkyl_range *rng) +long gkyl_range_split_len(const struct gkyl_range *rng) { - const long quot = rng->volume/rng->nsplit, rem = rng->volume % rng->nsplit; - return rng->tid < rem ? quot+1 : quot; + const long quot = rng->volume / rng->nsplit, rem = rng->volume % rng->nsplit; + return rng->tid < rem ? quot + 1 : quot; } -void -gkyl_range_deflate(struct gkyl_range* srng, - const struct gkyl_range* rng, const int *remDir, const int *locDir) +void gkyl_range_deflate( + struct gkyl_range *srng, const struct gkyl_range *rng, const int *remDir, const int *locDir +) { srng->linIdxZero = rng->linIdxZero; srng->ndim = 0; - srng->volume = 1; - for (int i=0, j=0; indim; ++i) { + srng->volume = 1; + for (int i = 0, j = 0; i < rng->ndim; ++i) { if (!remDir[i]) { srng->lower[j] = rng->lower[i]; srng->upper[j] = rng->upper[i]; srng->ilo[j] = rng->ilo[i]; - srng->ac[j+1] = rng->ac[i+1]; + srng->ac[j + 1] = rng->ac[i + 1]; srng->ndim += 1; srng->volume *= gkyl_range_shape(rng, i); j += 1; } } long adel = 0; // need to adjust ac[0] - for (int i=0; indim; ++i) - if (remDir[i]) - adel += locDir[i]*rng->ac[i+1]; + for (int i = 0; i < rng->ndim; ++i) { + if (remDir[i]) { + adel += locDir[i] * rng->ac[i + 1]; + } + } srng->ac[0] = rng->ac[0] + adel; srng->nsplit = rng->nsplit; @@ -292,106 +288,109 @@ gkyl_range_deflate(struct gkyl_range* srng, // for CUDA ops struct gkyl_range sub_range; gkyl_range_init(&sub_range, srng->ndim, srng->lower, srng->upper); - gkyl_copy_long_arr(GKYL_MAX_DIM+1, sub_range.ac, srng->iac); + gkyl_copy_long_arr(GKYL_MAX_DIM + 1, sub_range.ac, srng->iac); srng->nthreads = GKYL_DEFAULT_NUM_THREADS; - srng->nblocks = srng->volume/srng->nthreads + 1; + srng->nblocks = srng->volume / srng->nthreads + 1; } -void -gkyl_range_shorten_from_above(struct gkyl_range *rng, - const struct gkyl_range* range, int dir, int len) +void gkyl_range_shorten_from_above( + struct gkyl_range *rng, const struct gkyl_range *range, int dir, int len +) { int ndim = range->ndim; int lo[GKYL_MAX_DIM] = {0}, up[GKYL_MAX_DIM] = {0}; - - for (int i=0; ilower[i]; up[i] = range->upper[i]; } - up[dir] = lo[dir]+len-1; + up[dir] = lo[dir] + len - 1; gkyl_sub_range_init(rng, range, lo, up); } -void -gkyl_range_shorten_from_below(struct gkyl_range *rng, - const struct gkyl_range* range, int dir, int len) +void gkyl_range_shorten_from_below( + struct gkyl_range *rng, const struct gkyl_range *range, int dir, int len +) { int ndim = range->ndim; int lo[GKYL_MAX_DIM] = {0}, up[GKYL_MAX_DIM] = {0}; - - for (int i=0; ilower[i]; up[i] = range->upper[i]; } - lo[dir] = up[dir]-len+1; + lo[dir] = up[dir] - len + 1; gkyl_sub_range_init(rng, range, lo, up); } -void -gkyl_range_extend(struct gkyl_range *erng, - const struct gkyl_range* range, const int *elo, const int *eup) +void gkyl_range_extend( + struct gkyl_range *erng, const struct gkyl_range *range, const int *elo, const int *eup +) { int ndim = range->ndim; int lo[GKYL_MAX_DIM] = {0}, up[GKYL_MAX_DIM] = {0}; - for (int i=0; ilower[i]-elo[i]; - up[i] = range->upper[i]+eup[i]; + for (int i = 0; i < ndim; ++i) { + lo[i] = range->lower[i] - elo[i]; + up[i] = range->upper[i] + eup[i]; } gkyl_range_init(erng, ndim, lo, up); } -void -gkyl_range_perp_extend(struct gkyl_range *erng, int dir, - const struct gkyl_range* rng, const int *elo, const int *eup) +void gkyl_range_perp_extend( + struct gkyl_range *erng, int dir, const struct gkyl_range *rng, const int *elo, const int *eup +) { int ndim = rng->ndim; int elo_p[GKYL_MAX_DIM] = {0}, eup_p[GKYL_MAX_DIM] = {0}; - for (int i=0; indim; int lo[GKYL_MAX_DIM], up[GKYL_MAX_DIM]; - - for (int i=0; ilower[i]; up[i] = range->upper[i]; } - up[dir] = range->lower[dir]+nskin-1; + up[dir] = range->lower[dir] + nskin - 1; gkyl_sub_range_init(rng, range, lo, up); } -void -gkyl_range_upper_skin(struct gkyl_range *rng, - const struct gkyl_range* range, int dir, int nskin) +void gkyl_range_upper_skin( + struct gkyl_range *rng, const struct gkyl_range *range, int dir, int nskin +) { int ndim = range->ndim; int lo[GKYL_MAX_DIM], up[GKYL_MAX_DIM]; - - for (int i=0; ilower[i]; up[i] = range->upper[i]; } - lo[dir] = range->upper[dir]-nskin+1; + lo[dir] = range->upper[dir] - nskin + 1; gkyl_sub_range_init(rng, range, lo, up); } // Increment an int vector by fact*del[d] in each direction d. -static inline void -incr_int_array(int ndim, int fact, const int * GKYL_RESTRICT del, - const int * GKYL_RESTRICT inp, int *GKYL_RESTRICT out) +static inline void incr_int_array( + int ndim, int fact, const int *GKYL_RESTRICT del, const int *GKYL_RESTRICT inp, + int *GKYL_RESTRICT out +) { - for (int i=0; indim; int lo[GKYL_MAX_DIM] = {0}, up[GKYL_MAX_DIM] = {0}; if (edge == GKYL_LOWER_EDGE) { - incr_int_array(ndim, 1, nghost, parent->lower, lo); incr_int_array(ndim, -1, nghost, parent->upper, up); - - up[dir] = lo[dir]+nghost[dir]-1; + + up[dir] = lo[dir] + nghost[dir] - 1; gkyl_sub_range_init(skin, parent, lo, up); incr_int_array(ndim, 1, nghost, parent->lower, lo); incr_int_array(ndim, -1, nghost, parent->upper, up); - - lo[dir] = lo[dir]-nghost[dir]; - up[dir] = lo[dir]+nghost[dir]-1; - gkyl_sub_range_init(ghost, parent, lo, up); - } - else { + lo[dir] = lo[dir] - nghost[dir]; + up[dir] = lo[dir] + nghost[dir] - 1; + gkyl_sub_range_init(ghost, parent, lo, up); + } else { incr_int_array(ndim, 1, nghost, parent->lower, lo); incr_int_array(ndim, -1, nghost, parent->upper, up); - - lo[dir] = up[dir]-nghost[dir]+1; + + lo[dir] = up[dir] - nghost[dir] + 1; gkyl_sub_range_init(skin, parent, lo, up); incr_int_array(ndim, 1, nghost, parent->lower, lo); incr_int_array(ndim, -1, nghost, parent->upper, up); - - up[dir] = up[dir]+nghost[dir]+1; - lo[dir] = up[dir]-nghost[dir]; + + up[dir] = up[dir] + nghost[dir] + 1; + lo[dir] = up[dir] - nghost[dir]; gkyl_sub_range_init(ghost, parent, lo, up); } } -void -gkyl_skin_ghost_with_corners_ranges(struct gkyl_range *skin, struct gkyl_range *ghost, - int dir, enum gkyl_edge_loc edge, const struct gkyl_range *parent, const int *nghost) +void gkyl_skin_ghost_with_corners_ranges( + struct gkyl_range *skin, struct gkyl_range *ghost, int dir, enum gkyl_edge_loc edge, + const struct gkyl_range *parent, const int *nghost +) { int ndim = parent->ndim; int lo[GKYL_MAX_DIM] = {0}, up[GKYL_MAX_DIM] = {0}; - for (int i=0; ilower[i]; up[i] = parent->upper[i]; } if (edge == GKYL_LOWER_EDGE) { - - lo[dir] = parent->lower[dir]+nghost[dir]; - up[dir] = lo[dir]+nghost[dir]-1; - gkyl_sub_range_init(skin, parent, lo, up); + lo[dir] = parent->lower[dir] + nghost[dir]; + up[dir] = lo[dir] + nghost[dir] - 1; + gkyl_sub_range_init(skin, parent, lo, up); lo[dir] = parent->lower[dir]; - up[dir] = lo[dir]+nghost[dir]-1; + up[dir] = lo[dir] + nghost[dir] - 1; gkyl_sub_range_init(ghost, parent, lo, up); - } - else { - - up[dir] = parent->upper[dir]-nghost[dir]; - lo[dir] = up[dir]-nghost[dir]+1; + } else { + up[dir] = parent->upper[dir] - nghost[dir]; + lo[dir] = up[dir] - nghost[dir] + 1; gkyl_sub_range_init(skin, parent, lo, up); up[dir] = parent->upper[dir]; - lo[dir] = up[dir]-nghost[dir]+1; + lo[dir] = up[dir] - nghost[dir] + 1; gkyl_sub_range_init(ghost, parent, lo, up); } } -int -gkyl_range_intersect(struct gkyl_range* irng, - const struct gkyl_range *r1, const struct gkyl_range *r2) +int gkyl_range_intersect( + struct gkyl_range *irng, const struct gkyl_range *r1, const struct gkyl_range *r2 +) { int ndim = r1->ndim; int lo[GKYL_MAX_DIM], up[GKYL_MAX_DIM]; - for (int d=0; dlower[d] > r2->lower[d] ? r1->lower[d] : r2->lower[d]; up[d] = r1->upper[d] < r2->upper[d] ? r1->upper[d] : r2->upper[d]; } @@ -489,207 +484,204 @@ gkyl_range_intersect(struct gkyl_range* irng, return irng->volume > 0 ? 1 : 0; } -int -gkyl_sub_range_intersect(struct gkyl_range* irng, - const struct gkyl_range *r1, const struct gkyl_range *r2) +int gkyl_sub_range_intersect( + struct gkyl_range *irng, const struct gkyl_range *r1, const struct gkyl_range *r2 +) { int ndim = r1->ndim; int lo[GKYL_MAX_DIM], up[GKYL_MAX_DIM]; - for (int d=0; dlower[d] > r2->lower[d] ? r1->lower[d] : r2->lower[d]; up[d] = r1->upper[d] < r2->upper[d] ? r1->upper[d] : r2->upper[d]; } - + long vol = irng->volume = calc_volume_safely(ndim, lo, up); - if (vol > 0) + if (vol > 0) { gkyl_sub_range_init(irng, r1, lo, up); - else + } else { gkyl_range_init(irng, ndim, lo, up); + } return irng->volume > 0 ? 1 : 0; } -bool -gkyl_range_is_on_lower_edge(int dir, const struct gkyl_range *range, - const struct gkyl_range *parent) +bool gkyl_range_is_on_lower_edge( + int dir, const struct gkyl_range *range, const struct gkyl_range *parent +) { - if (range->lower[dir] == parent->lower[dir]) + if (range->lower[dir] == parent->lower[dir]) { return true; + } return false; - } -bool -gkyl_range_is_on_upper_edge(int dir, const struct gkyl_range *range, - const struct gkyl_range *parent) +bool gkyl_range_is_on_upper_edge( + int dir, const struct gkyl_range *range, const struct gkyl_range *parent +) { - if (range->upper[dir] == parent->upper[dir]) + if (range->upper[dir] == parent->upper[dir]) { return true; - return false; + } + return false; } struct gkyl_range_dir_edge -gkyl_range_edge_match(const struct gkyl_range *base, - const struct gkyl_range *targ) +gkyl_range_edge_match(const struct gkyl_range *base, const struct gkyl_range *targ) { - struct gkyl_range_dir_edge no_dir_ed = { - .dir = 0, - .eloc = GKYL_NO_EDGE - }; + struct gkyl_range_dir_edge no_dir_ed = {.dir = 0, .eloc = GKYL_NO_EDGE}; - if (base->ndim != targ->ndim) + if (base->ndim != targ->ndim) { return no_dir_ed; // different dimensions do not count + } struct gkyl_range irng; - if (gkyl_range_intersect(&irng, base, targ)) + if (gkyl_range_intersect(&irng, base, targ)) { return no_dir_ed; // overlapping ranges do not count + } - for (int d=0; dndim; ++d) { - + for (int d = 0; d < base->ndim; ++d) { do { - int elo[GKYL_MAX_DIM] = { 0 }, eup[GKYL_MAX_DIM] = { 0 }; + int elo[GKYL_MAX_DIM] = {0}, eup[GKYL_MAX_DIM] = {0}; // check lower-edge overlap elo[d] = 1; struct gkyl_range erng; gkyl_range_extend(&erng, base, elo, eup); - if (gkyl_range_intersect(&irng, &erng, targ)) - return (struct gkyl_range_dir_edge) { .dir = d, .eloc = GKYL_LOWER_EDGE }; + if (gkyl_range_intersect(&irng, &erng, targ)) { + return (struct gkyl_range_dir_edge){.dir = d, .eloc = GKYL_LOWER_EDGE}; + } } while (0); do { - int elo[GKYL_MAX_DIM] = { 0 }, eup[GKYL_MAX_DIM] = { 0 }; + int elo[GKYL_MAX_DIM] = {0}, eup[GKYL_MAX_DIM] = {0}; // check upper-edge overlap eup[d] = 1; struct gkyl_range erng; gkyl_range_extend(&erng, base, elo, eup); - if (gkyl_range_intersect(&irng, &erng, targ)) - return (struct gkyl_range_dir_edge) { .dir = d, .eloc = GKYL_UPPER_EDGE }; + if (gkyl_range_intersect(&irng, &erng, targ)) { + return (struct gkyl_range_dir_edge){.dir = d, .eloc = GKYL_UPPER_EDGE}; + } } while (0); } return no_dir_ed; } -void -gkyl_range_iter_init(struct gkyl_range_iter *iter, - const struct gkyl_range* range) +void gkyl_range_iter_init(struct gkyl_range_iter *iter, const struct gkyl_range *range) { iter->is_first = 1; iter->ndim = range->ndim; - iter->bumps_left = range->volume > 0? range_calc_split(range, iter->idx) : 0; - - for (int i=0; indim; ++i) { + iter->bumps_left = range->volume > 0 ? range_calc_split(range, iter->idx) : 0; + + for (int i = 0; i < range->ndim; ++i) { iter->lower[i] = range->lower[i]; iter->upper[i] = range->upper[i]; } } -void -gkyl_range_iter_no_split_init(struct gkyl_range_iter *iter, - const struct gkyl_range* range) +void gkyl_range_iter_no_split_init(struct gkyl_range_iter *iter, const struct gkyl_range *range) { iter->is_first = 1; iter->ndim = range->ndim; - iter->bumps_left = range->volume > 0? range_calc_split(range, iter->idx) : 0; - - for (int i=0; indim; ++i) { + iter->bumps_left = range->volume > 0 ? range_calc_split(range, iter->idx) : 0; + + for (int i = 0; i < range->ndim; ++i) { iter->idx[i] = iter->lower[i] = range->lower[i]; iter->upper[i] = range->upper[i]; - } + } } -int -gkyl_range_iter_next(struct gkyl_range_iter *iter) +int gkyl_range_iter_next(struct gkyl_range_iter *iter) { - if (iter->bumps_left-- < 1) return 0; - + if (iter->bumps_left-- < 1) { + return 0; + } + if (iter->is_first) { iter->is_first = 0; return 1; } - for (int dir=iter->ndim-1; dir>=0; --dir) { + for (int dir = iter->ndim - 1; dir >= 0; --dir) { iter->idx[dir] += 1; - if (iter->idx[dir] > iter->upper[dir]) + if (iter->idx[dir] > iter->upper[dir]) { iter->idx[dir] = iter->lower[dir]; - else + } else { return 1; + } } return 0; } -void -gkyl_range_skip_iter_init(struct gkyl_range_skip_iter *iter, - const struct gkyl_range* range) +void gkyl_range_skip_iter_init(struct gkyl_range_skip_iter *iter, const struct gkyl_range *range) { int remDir[GKYL_MAX_DIM]; iter->delta = calc_skip_iter(range, remDir); gkyl_range_deflate(&iter->range, range, remDir, range->lower); } -void -gkyl_print_range(const struct gkyl_range* range, const char *nm, FILE *fp) +void gkyl_print_range(const struct gkyl_range *range, const char *nm, FILE *fp) { fprintf(fp, "%s = { ndim = %d, ", nm, range->ndim); fprintf(fp, " lower = { "); - for (int d=0; dndim; ++d) - fprintf(fp, "%d%c ", range->lower[d], d==range->ndim-1 ? ' ' : ','); + for (int d = 0; d < range->ndim; ++d) { + fprintf(fp, "%d%c ", range->lower[d], d == range->ndim - 1 ? ' ' : ','); + } fprintf(fp, "}, "); fprintf(fp, "upper = { "); - for (int d=0; dndim; ++d) - fprintf(fp, "%d%c ", range->upper[d] , d==range->ndim-1 ? ' ' : ','); + for (int d = 0; d < range->ndim; ++d) { + fprintf(fp, "%d%c ", range->upper[d], d == range->ndim - 1 ? ' ' : ','); + } fprintf(fp, "}, "); - fprintf(fp, " volume = %ld, ", range->volume ); - fprintf(fp, " is_sub_range = %d", gkyl_range_is_sub_range(range) ); - + fprintf(fp, " volume = %ld, ", range->volume); + fprintf(fp, " is_sub_range = %d", gkyl_range_is_sub_range(range)); + fprintf(fp, " }\n"); fflush(fp); } -bool -gkyl_range_compare(const struct gkyl_range* r1, const struct gkyl_range* r2) +bool gkyl_range_compare(const struct gkyl_range *r1, const struct gkyl_range *r2) { - if (r1->ndim != r2->ndim) + if (r1->ndim != r2->ndim) { return false; - for (int i=0; indim; ++i) { - if (r1->lower[i] != r2->lower[i]) + } + for (int i = 0; i < r1->ndim; ++i) { + if (r1->lower[i] != r2->lower[i]) { + return false; + } + if (r1->upper[i] != r2->upper[i]) { return false; - if (r1->upper[i] != r2->upper[i]) - return false; + } } return true; } -int -gkyl_range_get_ndim(const struct gkyl_range* range) +int gkyl_range_get_ndim(const struct gkyl_range *range) { return range->ndim; } -void -gkyl_range_get_lower(const struct gkyl_range* range, int *lower) +void gkyl_range_get_lower(const struct gkyl_range *range, int *lower) { - for (int d=0; dndim; d++) + for (int d = 0; d < range->ndim; d++) { lower[d] = range->lower[d]; + } } -void -gkyl_range_get_upper(const struct gkyl_range* range, int *upper) +void gkyl_range_get_upper(const struct gkyl_range *range, int *upper) { - for (int d=0; dndim; d++) + for (int d = 0; d < range->ndim; d++) { upper[d] = range->upper[d]; + } } -long -gkyl_range_get_volume(const struct gkyl_range* range) +long gkyl_range_get_volume(const struct gkyl_range *range) { return range->volume; } -void -gkyl_range_release(struct gkyl_range* range) +void gkyl_range_release(struct gkyl_range *range) { gkyl_free(range); } diff --git a/core/zero/rect_decomp.c b/core/zero/rect_decomp.c index 21b80593e5..dbbb6d718c 100644 --- a/core/zero/rect_decomp.c +++ b/core/zero/rect_decomp.c @@ -18,48 +18,51 @@ struct rect_decomp_neigh_cont { cvec_int l_edge; }; -static void -rect_decomp_free(const struct gkyl_ref_count *ref) +static void rect_decomp_free(const struct gkyl_ref_count *ref) { struct gkyl_rect_decomp *decomp = container_of(ref, struct gkyl_rect_decomp, ref_count); gkyl_free(decomp->ranges); gkyl_free(decomp); -} +} -struct gkyl_rect_decomp* +struct gkyl_rect_decomp * gkyl_rect_decomp_new_from_cuts(int ndim, const int cuts[], const struct gkyl_range *range) { struct gkyl_rect_decomp *decomp = gkyl_malloc(sizeof(*decomp)); int ndecomp = 1; - decomp->ndim = ndim; + decomp->ndim = ndim; - for (int d=0; dndecomp = ndecomp; decomp->ranges = gkyl_malloc(sizeof(struct gkyl_range[ndecomp])); memcpy(&decomp->parent_range, range, sizeof(struct gkyl_range)); div_t qr[GKYL_MAX_DIM]; - for (int d=0; dlower[d]; - eidx[d][0] = sidx[d][0]+shape[0]-1; - for (int i=1; iranges[dnum++], range->ndim, lower, upper); } - for (int d=0; dref_count = gkyl_ref_count_init(rect_decomp_free); - + return decomp; } -struct gkyl_rect_decomp* +struct gkyl_rect_decomp * gkyl_rect_decomp_new_from_cuts_and_cells(int ndim, const int cuts[], const int cells[]) { struct gkyl_range range; @@ -102,65 +105,63 @@ gkyl_rect_decomp_new_from_cuts_and_cells(int ndim, const int cuts[], const int c return gkyl_rect_decomp_new_from_cuts(ndim, cuts, &range); } -// ext_range = a X b -static void -init_extend_range(struct gkyl_range *ext_range, - const struct gkyl_range *a, const struct gkyl_range *b) +// ext_range = a X b +static void init_extend_range( + struct gkyl_range *ext_range, const struct gkyl_range *a, const struct gkyl_range *b +) { int adim = a->ndim, bdim = b->ndim; int lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - for (int d=0; dlower[d]; upper[d] = a->upper[d]; } - for (int d=0; dlower[d]; - upper[adim+d] = b->upper[d]; + for (int d = 0; d < bdim; ++d) { + lower[adim + d] = b->lower[d]; + upper[adim + d] = b->upper[d]; } - gkyl_range_init(ext_range, adim+bdim, lower, upper); + gkyl_range_init(ext_range, adim + bdim, lower, upper); } -struct gkyl_rect_decomp* -gkyl_rect_decomp_extended_new(const struct gkyl_range *arange, - const struct gkyl_rect_decomp *decomp) +struct gkyl_rect_decomp * +gkyl_rect_decomp_extended_new(const struct gkyl_range *arange, const struct gkyl_rect_decomp *decomp) { struct gkyl_rect_decomp *extd = gkyl_malloc(sizeof(*extd)); - int ndecomp = extd->ndecomp = decomp->ndecomp; + int ndecomp = extd->ndecomp = decomp->ndecomp; int ndim = extd->ndim = arange->ndim + decomp->ndim; extd->ranges = gkyl_malloc(sizeof(struct gkyl_range[ndecomp])); gkyl_range_ten_prod(&extd->parent_range, &decomp->parent_range, arange); - for (int n=0; nranges[n], &decomp->ranges[n], arange); + } extd->ref_count = gkyl_ref_count_init(rect_decomp_free); - + return extd; } -struct gkyl_rect_decomp* -gkyl_rect_decomp_acquire(const struct gkyl_rect_decomp *decomp) +struct gkyl_rect_decomp *gkyl_rect_decomp_acquire(const struct gkyl_rect_decomp *decomp) { gkyl_ref_count_inc(&decomp->ref_count); - return (struct gkyl_rect_decomp*) decomp; + return (struct gkyl_rect_decomp *)decomp; } -bool -gkyl_rect_decomp_check_covering(const struct gkyl_rect_decomp *decomp) +bool gkyl_rect_decomp_check_covering(const struct gkyl_rect_decomp *decomp) { struct gkyl_array *arr = gkyl_array_new(GKYL_DOUBLE, 1, decomp->parent_range.volume); gkyl_array_clear(arr, 0.0); // following loops over each sub-range and increments the region it // indexes in 'arr'. Each index should be visited exactly once. - for (int i=0; indecomp; ++i) { + for (int i = 0; i < decomp->ndecomp; ++i) { // construct a sub-range so indexing into global array works fine struct gkyl_range lrange; gkyl_sub_range_intersect(&lrange, &decomp->parent_range, &decomp->ranges[i]); - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &lrange); @@ -174,39 +175,40 @@ gkyl_rect_decomp_check_covering(const struct gkyl_rect_decomp *decomp) gkyl_range_iter_init(&iter, &decomp->parent_range); while (gkyl_range_iter_next(&iter)) { const double *d = gkyl_array_cfetch(arr, gkyl_range_idx(&decomp->parent_range, iter.idx)); - if (d[0] != 1.0) + if (d[0] != 1.0) { return false; + } } gkyl_array_release(arr); - + return true; } // compute neighbors accounting for corner neighbors -static struct gkyl_rect_decomp_neigh* +static struct gkyl_rect_decomp_neigh * calc_neigh_with_corners(const struct gkyl_rect_decomp *decomp, int nidx) { struct rect_decomp_neigh_cont *cont = gkyl_malloc(sizeof(*cont)); cont->l_neigh = cvec_int_init(); cont->l_dir = cvec_int_init(); cont->l_edge = cvec_int_init(); - + int elo[GKYL_MAX_DIM], eup[GKYL_MAX_DIM]; - for (int i=0; indim; ++i) + for (int i = 0; i < decomp->ndim; ++i) { elo[i] = eup[i] = 1; - + } + struct gkyl_range erng; gkyl_range_extend(&erng, &decomp->ranges[nidx], elo, eup); - for (int i=0; indecomp; ++i) + for (int i = 0; i < decomp->ndecomp; ++i) { if (i != nidx) { struct gkyl_range irng; - int is_inter = gkyl_range_intersect(&irng, &erng, - &decomp->ranges[i]); + int is_inter = gkyl_range_intersect(&irng, &erng, &decomp->ranges[i]); if (is_inter) { cvec_int_push_back(&cont->l_neigh, i); - + struct gkyl_range_dir_edge dir_ed = gkyl_range_edge_match(&decomp->ranges[nidx], &decomp->ranges[i]); @@ -214,100 +216,101 @@ calc_neigh_with_corners(const struct gkyl_rect_decomp *decomp, int nidx) cvec_int_push_back(&cont->l_edge, dir_ed.eloc); } } + } cont->neigh.num_neigh = cvec_int_size(cont->l_neigh); cont->neigh.neigh = cvec_int_front(&cont->l_neigh); cont->neigh.dir = cvec_int_front(&cont->l_dir); cont->neigh.edge = cvec_int_front(&cont->l_edge); - + return &cont->neigh; } // compute neighbors leaving out corner neighbors: only face neighbors // are included -static struct gkyl_rect_decomp_neigh* +static struct gkyl_rect_decomp_neigh * calc_neigh_no_corners(const struct gkyl_rect_decomp *decomp, int nidx) { struct rect_decomp_neigh_cont *cont = gkyl_malloc(sizeof(*cont)); cont->l_neigh = cvec_int_init(); cont->l_dir = cvec_int_init(); - cont->l_edge = cvec_int_init(); - + cont->l_edge = cvec_int_init(); + struct gkyl_range erng; - for (int n=0; nndim; ++n) { - - int elo[GKYL_MAX_DIM] = { 0 }, eup[GKYL_MAX_DIM] = { 0 }; + for (int n = 0; n < decomp->ndim; ++n) { + int elo[GKYL_MAX_DIM] = {0}, eup[GKYL_MAX_DIM] = {0}; elo[n] = eup[n] = 1; // only extend in 1 direction gkyl_range_extend(&erng, &decomp->ranges[nidx], elo, eup); - for (int i=0; indecomp; ++i) + for (int i = 0; i < decomp->ndecomp; ++i) { if (i != nidx) { struct gkyl_range irng; - int is_inter = gkyl_range_intersect(&irng, &erng, - &decomp->ranges[i]); + int is_inter = gkyl_range_intersect(&irng, &erng, &decomp->ranges[i]); if (is_inter) { cvec_int_push_back(&cont->l_neigh, i); struct gkyl_range_dir_edge dir_ed = gkyl_range_edge_match(&decomp->ranges[nidx], &decomp->ranges[i]); - + cvec_int_push_back(&cont->l_dir, dir_ed.dir); cvec_int_push_back(&cont->l_edge, dir_ed.eloc); } } + } } - + cont->neigh.num_neigh = cvec_int_size(cont->l_neigh); cont->neigh.neigh = cvec_int_front(&cont->l_neigh); cont->neigh.dir = cvec_int_front(&cont->l_dir); - cont->neigh.edge = cvec_int_front(&cont->l_edge); - + cont->neigh.edge = cvec_int_front(&cont->l_edge); + return &cont->neigh; } -struct gkyl_rect_decomp_neigh* -gkyl_rect_decomp_calc_neigh(const struct gkyl_rect_decomp *decomp, - bool inc_corners, int nidx) +struct gkyl_rect_decomp_neigh * +gkyl_rect_decomp_calc_neigh(const struct gkyl_rect_decomp *decomp, bool inc_corners, int nidx) { - if (inc_corners) + if (inc_corners) { return calc_neigh_with_corners(decomp, nidx); + } return calc_neigh_no_corners(decomp, nidx); } -struct gkyl_rect_decomp_neigh* -gkyl_rect_decomp_calc_periodic_neigh(const struct gkyl_rect_decomp *decomp, - int dir, bool inc_corners, int nidx) +struct gkyl_rect_decomp_neigh *gkyl_rect_decomp_calc_periodic_neigh( + const struct gkyl_rect_decomp *decomp, int dir, bool inc_corners, int nidx +) { struct rect_decomp_neigh_cont *cont = gkyl_malloc(sizeof(*cont)); cont->l_neigh = cvec_int_init(); cont->l_dir = cvec_int_init(); - cont->l_edge = cvec_int_init(); + cont->l_edge = cvec_int_init(); const struct gkyl_range *curr = &decomp->ranges[nidx]; - int elo[GKYL_MAX_DIM] = { 0 }, eup[GKYL_MAX_DIM] = { 0 }; - if (inc_corners) - for (int i=0; indim; ++i) + int elo[GKYL_MAX_DIM] = {0}, eup[GKYL_MAX_DIM] = {0}; + if (inc_corners) { + for (int i = 0; i < decomp->ndim; ++i) { elo[i] = eup[i] = 1; - else + } + } else { elo[dir] = eup[dir] = 1; - + } + if (gkyl_range_is_on_lower_edge(dir, curr, &decomp->parent_range)) { - int delta[GKYL_MAX_DIM] = { 0 }; + int delta[GKYL_MAX_DIM] = {0}; delta[dir] = gkyl_range_shape(&decomp->parent_range, dir); - + struct gkyl_range curr_shift; gkyl_range_shift(&curr_shift, curr, delta); - + struct gkyl_range shift_erng; gkyl_range_extend(&shift_erng, &curr_shift, elo, eup); - for (int i=0; indecomp; ++i) + for (int i = 0; i < decomp->ndecomp; ++i) { if (gkyl_range_is_on_upper_edge(dir, &decomp->ranges[i], &decomp->parent_range)) { struct gkyl_range irng; - int is_inter = gkyl_range_intersect(&irng, &shift_erng, - &decomp->ranges[i]); + int is_inter = gkyl_range_intersect(&irng, &shift_erng, &decomp->ranges[i]); if (is_inter) { cvec_int_push_back(&cont->l_neigh, i); cvec_int_push_back(&cont->l_dir, dir); @@ -316,73 +319,69 @@ gkyl_rect_decomp_calc_periodic_neigh(const struct gkyl_rect_decomp *decomp, cvec_int_push_back(&cont->l_edge, GKYL_LOWER_EDGE); } } - } - else if (gkyl_range_is_on_upper_edge(dir, curr, &decomp->parent_range)) { - int delta[GKYL_MAX_DIM] = { 0 }; + } + } else if (gkyl_range_is_on_upper_edge(dir, curr, &decomp->parent_range)) { + int delta[GKYL_MAX_DIM] = {0}; delta[dir] = -gkyl_range_shape(&decomp->parent_range, dir); - + struct gkyl_range curr_shift; gkyl_range_shift(&curr_shift, curr, delta); - + struct gkyl_range shift_erng; gkyl_range_extend(&shift_erng, &curr_shift, elo, eup); - for (int i=0; indecomp; ++i) + for (int i = 0; i < decomp->ndecomp; ++i) { if (gkyl_range_is_on_lower_edge(dir, &decomp->ranges[i], &decomp->parent_range)) { struct gkyl_range irng; - int is_inter = gkyl_range_intersect(&irng, &shift_erng, - &decomp->ranges[i]); + int is_inter = gkyl_range_intersect(&irng, &shift_erng, &decomp->ranges[i]); if (is_inter) { cvec_int_push_back(&cont->l_neigh, i); cvec_int_push_back(&cont->l_dir, dir); // this is not exactly correct: corner neighbors should not - // be on any edge + // be on any edge cvec_int_push_back(&cont->l_edge, GKYL_UPPER_EDGE); } } + } } - cont->neigh.num_neigh = cvec_int_size(cont->l_neigh); + cont->neigh.num_neigh = cvec_int_size(cont->l_neigh); cont->neigh.neigh = cvec_int_front(&cont->l_neigh); cont->neigh.dir = cvec_int_front(&cont->l_dir); - cont->neigh.edge = cvec_int_front(&cont->l_edge); - + cont->neigh.edge = cvec_int_front(&cont->l_edge); + return &cont->neigh; } -void -gkyl_rect_decomp_neigh_release(struct gkyl_rect_decomp_neigh *ng) +void gkyl_rect_decomp_neigh_release(struct gkyl_rect_decomp_neigh *ng) { - struct rect_decomp_neigh_cont *cont = container_of(ng, - struct rect_decomp_neigh_cont, neigh); + struct rect_decomp_neigh_cont *cont = container_of(ng, struct rect_decomp_neigh_cont, neigh); cvec_int_drop(&cont->l_neigh); cvec_int_drop(&cont->l_dir); cvec_int_drop(&cont->l_edge); gkyl_free(cont); } -long -gkyl_rect_decomp_calc_offset(const struct gkyl_rect_decomp *decomp, int nidx) +long gkyl_rect_decomp_calc_offset(const struct gkyl_rect_decomp *decomp, int nidx) { long offset = 0; - for (int i=0; iranges[i].volume; + } return offset; } -void -gkyl_rect_decomp_release(struct gkyl_rect_decomp *decomp) +void gkyl_rect_decomp_release(struct gkyl_rect_decomp *decomp) { gkyl_ref_count_dec(&decomp->ref_count); } // Utility functions -void -gkyl_create_global_range(int ndim, const int *cells, struct gkyl_range *range) +void gkyl_create_global_range(int ndim, const int *cells, struct gkyl_range *range) { int lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - for (int i=0; indim; ++i) { - lower_ext[i] = 1-nghost[i]; - upper_ext[i] = grid->cells[i]+nghost[i]; + + for (int i = 0; i < grid->ndim; ++i) { + lower_ext[i] = 1 - nghost[i]; + upper_ext[i] = grid->cells[i] + nghost[i]; // this needs to be consistent with gkyl_create_global_range above lower[i] = 1; @@ -409,32 +409,34 @@ gkyl_create_grid_ranges(const struct gkyl_rect_grid *grid, gkyl_sub_range_init(range, ext_range, lower, upper); } -void -gkyl_create_ranges(const struct gkyl_range *inrange, - const int *nghost, struct gkyl_range *ext_range, struct gkyl_range *range) +void gkyl_create_ranges( + const struct gkyl_range *inrange, const int *nghost, struct gkyl_range *ext_range, + struct gkyl_range *range +) { int lower_ext[GKYL_MAX_DIM], upper_ext[GKYL_MAX_DIM]; int lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - - for (int i=0; indim; ++i) { - lower_ext[i] = inrange->lower[i]-nghost[i]; - upper_ext[i] = inrange->upper[i]+nghost[i]; + + for (int i = 0; i < inrange->ndim; ++i) { + lower_ext[i] = inrange->lower[i] - nghost[i]; + upper_ext[i] = inrange->upper[i] + nghost[i]; lower[i] = inrange->lower[i]; upper[i] = inrange->upper[i]; } gkyl_range_init(ext_range, inrange->ndim, lower_ext, upper_ext); - gkyl_sub_range_init(range, ext_range, lower, upper); + gkyl_sub_range_init(range, ext_range, lower, upper); } -void -gkyl_create_vertex_ranges(const struct gkyl_range *inrange, - const int *nghost, struct gkyl_range *ext_range, struct gkyl_range *range) +void gkyl_create_vertex_ranges( + const struct gkyl_range *inrange, const int *nghost, struct gkyl_range *ext_range, + struct gkyl_range *range +) { int lower_ext[GKYL_MAX_DIM], upper_ext[GKYL_MAX_DIM]; int lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - for (int i=0; indim; ++i) { + for (int i = 0; i < inrange->ndim; ++i) { lower_ext[i] = inrange->lower[i] - nghost[i]; upper_ext[i] = inrange->upper[i] + 1 + nghost[i]; @@ -442,17 +444,16 @@ gkyl_create_vertex_ranges(const struct gkyl_range *inrange, upper[i] = inrange->upper[i] + 1; } gkyl_range_init(ext_range, inrange->ndim, lower_ext, upper_ext); - gkyl_sub_range_init(range, ext_range, lower, upper); + gkyl_sub_range_init(range, ext_range, lower, upper); } -void -gkyl_rect_decomp_get_cuts(struct gkyl_rect_decomp* decomp, int* cuts) +void gkyl_rect_decomp_get_cuts(struct gkyl_rect_decomp *decomp, int *cuts) { int ndim = decomp->ndim; - for (int d=0; dranges[0].lower[i]; other_dim_up[i] = decomp->ranges[0].upper[i]; @@ -465,17 +466,18 @@ gkyl_rect_decomp_get_cuts(struct gkyl_rect_decomp* decomp, int* cuts) while (not_reached_upper) { struct gkyl_range range_curr = decomp->ranges[range_idx]; bool same_other_lims = true; - for (int i=0; iparent_range.upper[d]) + if (range_curr.upper[d] == decomp->parent_range.upper[d]) { not_reached_upper = false; + } } range_idx++; diff --git a/core/zero/rect_grid.c b/core/zero/rect_grid.c index 4e645015a3..eb7b17edf5 100644 --- a/core/zero/rect_grid.c +++ b/core/zero/rect_grid.c @@ -6,61 +6,64 @@ #include #include #include -void -gkyl_rect_grid_init(struct gkyl_rect_grid *grid, int ndim, - const double *lower, const double *upper, const int *cells) +void gkyl_rect_grid_init( + struct gkyl_rect_grid *grid, int ndim, const double *lower, const double *upper, const int *cells +) { -// // MF 2023/07/07: commenting this out because it causes seg faults in g2. -// *grid = (struct gkyl_rect_grid) { }; - - grid->ndim = ndim; + // // MF 2023/07/07: commenting this out because it causes seg faults in g2. + // *grid = (struct gkyl_rect_grid) { }; + + grid->ndim = ndim; grid->cellVolume = 1.0; - for (int i=0; ilower[i] = lower[i]; grid->upper[i] = upper[i]; grid->cells[i] = cells[i]; - grid->dx[i] = (upper[i]-lower[i])/cells[i]; + grid->dx[i] = (upper[i] - lower[i]) / cells[i]; grid->cellVolume *= grid->dx[i]; } } -struct gkyl_rect_grid* +struct gkyl_rect_grid * gkyl_rect_grid_new(int ndim, const double *lower, const double *upper, const int *cells) { - struct gkyl_rect_grid* out = gkyl_calloc(1, sizeof(*out)); + struct gkyl_rect_grid *out = gkyl_calloc(1, sizeof(*out)); gkyl_rect_grid_init(out, ndim, lower, upper, cells); return out; } -bool -gkyl_rect_grid_cmp(const struct gkyl_rect_grid *grid1, struct gkyl_rect_grid *grid2) +bool gkyl_rect_grid_cmp(const struct gkyl_rect_grid *grid1, struct gkyl_rect_grid *grid2) { - if (grid1->ndim != grid2->ndim) + if (grid1->ndim != grid2->ndim) { return false; + } - for (int i=0; indim; ++i) { - if (grid1->cells[i] != grid2->cells[i]) + for (int i = 0; i < grid1->ndim; ++i) { + if (grid1->cells[i] != grid2->cells[i]) { + return false; + } + if (!gkyl_compare_double(grid1->lower[i], grid2->lower[i], 1e-14)) { return false; - if (!gkyl_compare_double(grid1->lower[i], grid2->lower[i], 1e-14)) + } + if (!gkyl_compare_double(grid1->upper[i], grid2->upper[i], 1e-14)) { return false; - if (!gkyl_compare_double(grid1->upper[i], grid2->upper[i], 1e-14)) - return false; + } } return true; } -GKYL_CU_DH -void -gkyl_rect_grid_find_cell(const struct gkyl_rect_grid *grid, const double *point, - const bool *pick_lower, const int *known_index, int *cell_index){ - +GKYL_CU_DH void gkyl_rect_grid_find_cell( + const struct gkyl_rect_grid *grid, const double *point, const bool *pick_lower, + const int *known_index, int *cell_index +) +{ int nDim = grid->ndim; int search_num = 0; int search_dim[GKYL_MAX_DIM]; int dim_trans[GKYL_MAX_DIM]; double low, high; - - for (int d=0; dlower[d]+(known_index[d]-1)*grid->dx[d]; - high = grid->lower[d]+(known_index[d])*grid->dx[d]; - assert(lowpoint[d]); + low = grid->lower[d] + (known_index[d] - 1) * grid->dx[d]; + high = grid->lower[d] + (known_index[d]) * grid->dx[d]; + assert(low < point[d] && high > point[d]); } } - int start_index[GKYL_MAX_DIM], end_index[GKYL_MAX_DIM], mid_index[GKYL_MAX_DIM], new_index[GKYL_MAX_DIM]; - const int *cells = grid -> cells; - for (int d=0; dcells; + for (int d = 0; d < search_num; d++) { start_index[d] = 1; end_index[d] = cells[search_dim[d]]; mid_index[d] = 0; new_index[d] = 0; } - int plusminus[2] = {-1,1}, low_high_index[2*GKYL_MAX_DIM]; + int plusminus[2] = {-1, 1}, low_high_index[2 * GKYL_MAX_DIM]; bool all_less_eq = true; double lower_dir[nDim], upper_dir[nDim]; /* Below we use a binary search. That is, if the i-th coordinate of the point in @@ -91,89 +95,95 @@ gkyl_rect_grid_find_cell(const struct gkyl_rect_grid *grid, const double *point, * the lower(upper) half along that direction in the next iteration. */ while (all_less_eq) { - for (int d=0; d upper_dir[search_dim[d]]) { - start_index[d] = mid_index[d]+1; - } + for (int d = 0; d < search_num; d++) { + if (point[search_dim[d]] < lower_dir[search_dim[d]]) { + end_index[d] = mid_index[d] - 1; + } else if (point[search_dim[d]] > upper_dir[search_dim[d]]) { + start_index[d] = mid_index[d] + 1; + } } } - for (int d=0; dend_index[d]) { - all_less_eq = false; - break; + for (int d = 0; d < search_num; d++) { + if (start_index[d] > end_index[d]) { + all_less_eq = false; + break; } } } } -void -gkyl_rect_grid_write(const struct gkyl_rect_grid *grid, const char *nm, FILE *fp) +void gkyl_rect_grid_write(const struct gkyl_rect_grid *grid, const char *nm, FILE *fp) { if (fp == stdout || fp == stderr) { fprintf(fp, "%s = { ndim = %d, ", nm, grid->ndim); fprintf(fp, " lower = { "); - for (int d=0; dndim; ++d) - fprintf(fp, "%.9e%c ", grid->lower[d], d==grid->ndim-1 ? ' ' : ','); + for (int d = 0; d < grid->ndim; ++d) { + fprintf(fp, "%.9e%c ", grid->lower[d], d == grid->ndim - 1 ? ' ' : ','); + } fprintf(fp, "}, "); fprintf(fp, "upper = { "); - for (int d=0; dndim; ++d) - fprintf(fp, "%.9e%c ", grid->upper[d] , d==grid->ndim-1 ? ' ' : ','); + for (int d = 0; d < grid->ndim; ++d) { + fprintf(fp, "%.9e%c ", grid->upper[d], d == grid->ndim - 1 ? ' ' : ','); + } fprintf(fp, "}, "); fprintf(fp, "cells = { "); - for (int d=0; dndim; ++d) - fprintf(fp, "%d%c ", grid->cells[d] , d==grid->ndim-1 ? ' ' : ','); + for (int d = 0; d < grid->ndim; ++d) { + fprintf(fp, "%d%c ", grid->cells[d], d == grid->ndim - 1 ? ' ' : ','); + } fprintf(fp, "}, "); fprintf(fp, "dx = { "); - for (int d=0; dndim; ++d) - fprintf(fp, "%.9e%c ", grid->upper[d] , d==grid->ndim-1 ? ' ' : ','); + for (int d = 0; d < grid->ndim; ++d) { + fprintf(fp, "%.9e%c ", grid->upper[d], d == grid->ndim - 1 ? ' ' : ','); + } fprintf(fp, "}, "); - fprintf(fp, " cellVolume = %.9e, ", grid->cellVolume ); - + fprintf(fp, " cellVolume = %.9e, ", grid->cellVolume); + fprintf(fp, " }\n"); fflush(fp); - } - else { + } else { // Dimension and shape are written as 64 bit integers. uint64_t ndim = grid->ndim; uint64_t cells[GKYL_MAX_DIM]; - for (int d=0; dndim; ++d) + for (int d = 0; d < grid->ndim; ++d) { cells[d] = grid->cells[d]; - + } + fwrite(&ndim, sizeof(uint64_t), 1, fp); fwrite(cells, sizeof(uint64_t), grid->ndim, fp); fwrite(grid->lower, sizeof(double), grid->ndim, fp); @@ -181,34 +191,38 @@ gkyl_rect_grid_write(const struct gkyl_rect_grid *grid, const char *nm, FILE *fp } } -bool -gkyl_rect_grid_read(struct gkyl_rect_grid *grid, FILE *fp) +bool gkyl_rect_grid_read(struct gkyl_rect_grid *grid, FILE *fp) { uint64_t ndim = grid->ndim; uint64_t cells64[GKYL_MAX_DIM]; - if (1 != fread(&ndim, sizeof(uint64_t), 1, fp)) + if (1 != fread(&ndim, sizeof(uint64_t), 1, fp)) { return false; - if (ndim != fread(cells64, sizeof(uint64_t), ndim, fp)) + } + if (ndim != fread(cells64, sizeof(uint64_t), ndim, fp)) { return false; + } double lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - if (ndim != fread(lower, sizeof(double), ndim, fp)) + if (ndim != fread(lower, sizeof(double), ndim, fp)) { return false; - if (ndim != fread(upper, sizeof(double), ndim, fp)) + } + if (ndim != fread(upper, sizeof(double), ndim, fp)) { return false; + } // copy into regular int array int cells[GKYL_MAX_DIM]; - for (int d=0; drrobin.total_ranks = total_ranks; + rr->rrobin.total_ranks = total_ranks; rr->rrobin.nblocks = nblocks; rr->branks = gkyl_malloc(sizeof(int[nblocks])); - for (int i=0; ibranks[i] = branks[i]; - + } + int tot_branks = 0; - for (int i=0; irrobin; } -int -gkyl_rrobin_decomp_nranks(const struct gkyl_rrobin_decomp *rr, int bn) +int gkyl_rrobin_decomp_nranks(const struct gkyl_rrobin_decomp *rr, int bn) { - struct rrobin_decomp *rrd = container_of(rr, struct rrobin_decomp, rrobin); + struct rrobin_decomp *rrd = container_of(rr, struct rrobin_decomp, rrobin); return rrd->branks[bn]; } -void -gkyl_rrobin_decomp_getranks(const struct gkyl_rrobin_decomp *rr, int bn, int ranks[]) +void gkyl_rrobin_decomp_getranks(const struct gkyl_rrobin_decomp *rr, int bn, int ranks[]) { struct rrobin_decomp *rrd = container_of(rr, struct rrobin_decomp, rrobin); // ranks are distributed in a round-robin way amongst the blocks int loc = 0; - for (int i=0; ibranks[i]; + } int start = loc % rr->total_ranks; - for (int i=0; ibranks[bn]; ++i) - ranks[i] = (start+i) % rr->total_ranks; + for (int i = 0; i < rrd->branks[bn]; ++i) { + ranks[i] = (start + i) % rr->total_ranks; + } } -void -gkyl_rrobin_decomp_release(const struct gkyl_rrobin_decomp *rr) +void gkyl_rrobin_decomp_release(const struct gkyl_rrobin_decomp *rr) { struct rrobin_decomp *rrd = container_of(rr, struct rrobin_decomp, rrobin); diff --git a/core/zero/skin_surf_from_ghost.c b/core/zero/skin_surf_from_ghost.c index c77f9a2551..59771a22dd 100644 --- a/core/zero/skin_surf_from_ghost.c +++ b/core/zero/skin_surf_from_ghost.c @@ -3,11 +3,11 @@ #include #include -struct gkyl_skin_surf_from_ghost* -gkyl_skin_surf_from_ghost_new(int dir, enum gkyl_edge_loc edge, const struct gkyl_basis basis, - const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, bool use_gpu) +struct gkyl_skin_surf_from_ghost *gkyl_skin_surf_from_ghost_new( + int dir, enum gkyl_edge_loc edge, const struct gkyl_basis basis, const struct gkyl_range *skin_r, + const struct gkyl_range *ghost_r, bool use_gpu +) { - // Allocate space for new updater. struct gkyl_skin_surf_from_ghost *up = gkyl_malloc(sizeof(*up)); @@ -18,11 +18,13 @@ gkyl_skin_surf_from_ghost_new(int dir, enum gkyl_edge_loc edge, const struct gky up->ghost_r = ghost_r; // Choose the kernel that does the skin surf from ghost copy - if (!use_gpu) + if (!use_gpu) { up->kernels = gkyl_malloc(sizeof(struct gkyl_skin_surf_from_ghost_kernels)); + } #ifdef GKYL_HAVE_CUDA - if (use_gpu) + if (use_gpu) { up->kernels = gkyl_cu_malloc(sizeof(struct gkyl_skin_surf_from_ghost_kernels)); + } #endif skin_surf_from_ghost_choose_kernel(basis, edge, up->dir, use_gpu, up->kernels); @@ -30,8 +32,9 @@ gkyl_skin_surf_from_ghost_new(int dir, enum gkyl_edge_loc edge, const struct gky return up; } -void -gkyl_skin_surf_from_ghost_advance(const struct gkyl_skin_surf_from_ghost *up, struct gkyl_array *field) +void gkyl_skin_surf_from_ghost_advance( + const struct gkyl_skin_surf_from_ghost *up, struct gkyl_array *field +) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { @@ -42,37 +45,37 @@ gkyl_skin_surf_from_ghost_advance(const struct gkyl_skin_surf_from_ghost *up, st int gidx[GKYL_MAX_DIM]; // ghost index. - int ndim = up->skin_r->ndim; + int ndim = up->skin_r->ndim; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, up->skin_r); while (gkyl_range_iter_next(&iter)) { - gkyl_copy_int_arr(ndim, iter.idx, gidx); // Get ghost cell corresponding to skin cell - gidx[up->dir] = up->edge == GKYL_LOWER_EDGE? iter.idx[up->dir]-1 : iter.idx[up->dir]+1; + gidx[up->dir] = up->edge == GKYL_LOWER_EDGE ? iter.idx[up->dir] - 1 : iter.idx[up->dir] + 1; long ghost_linidx = gkyl_range_idx(up->ghost_r, gidx); - long skin_linidx = gkyl_range_idx(up->skin_r, iter.idx); + long skin_linidx = gkyl_range_idx(up->skin_r, iter.idx); - const double *inp = (const double*) gkyl_array_cfetch(field, ghost_linidx); - double *out = (double*) gkyl_array_fetch(field, skin_linidx); + const double *inp = (const double *)gkyl_array_cfetch(field, ghost_linidx); + double *out = (double *)gkyl_array_fetch(field, skin_linidx); - // Now call the kernel to ensure the nodal values to match the ghost nodal value + // Now call the kernel to ensure the nodal values to match the ghost nodal value // while ensuring that the other nodal value remains unchanged - up->kernels->ghost_to_skin(inp,out); - + up->kernels->ghost_to_skin(inp, out); } } void gkyl_skin_surf_from_ghost_release(struct gkyl_skin_surf_from_ghost *up) { // Release memory associated with this updater. - if (!up->use_gpu) + if (!up->use_gpu) { gkyl_free(up->kernels); + } #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { gkyl_cu_free(up->kernels); + } #endif gkyl_free(up); } \ No newline at end of file diff --git a/core/zero/skin_surf_from_ghost_cu.cu b/core/zero/skin_surf_from_ghost_cu.cu index 16f9e93337..d443d34673 100644 --- a/core/zero/skin_surf_from_ghost_cu.cu +++ b/core/zero/skin_surf_from_ghost_cu.cu @@ -6,9 +6,10 @@ extern "C" { } // CUDA kernel to set device pointers to the kernel that transfers ghost cell values to skin cells. -__global__ static void -skin_surf_from_ghost_set_cu_ker_ptrs(const struct gkyl_basis basis, - enum gkyl_edge_loc edge, int dir, struct gkyl_skin_surf_from_ghost_kernels *kers) +__global__ static void skin_surf_from_ghost_set_cu_ker_ptrs( + const struct gkyl_basis basis, enum gkyl_edge_loc edge, int dir, + struct gkyl_skin_surf_from_ghost_kernels *kers +) { // Get the dimension and basis type information from the provided basis object. int dim = basis.ndim; // Spatial dimension. @@ -17,30 +18,32 @@ skin_surf_from_ghost_set_cu_ker_ptrs(const struct gkyl_basis basis, // Select the appropriate kernel based on the basis type and edge location. switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Set the ghost_to_skin kernel for the chosen basis and dimensionality. - kers->ghost_to_skin = ser_skin_surf_from_ghost_list[edge].edgedlist[dim-1].dirlist[dir].kernels[poly_order-1]; - break; - default: - // If an unsupported basis type is encountered, assert failure. - assert(false); + case GKYL_BASIS_MODAL_SERENDIPITY: + // Set the ghost_to_skin kernel for the chosen basis and dimensionality. + kers->ghost_to_skin = + ser_skin_surf_from_ghost_list[edge].edgedlist[dim - 1].dirlist[dir].kernels[poly_order - 1]; + break; + default: + // If an unsupported basis type is encountered, assert failure. + assert(false); } }; // Function to launch a CUDA kernel that selects the appropriate kernel on the GPU. -void -skin_surf_from_ghost_choose_kernel_cu(const struct gkyl_basis basis, - enum gkyl_edge_loc edge, int dir, struct gkyl_skin_surf_from_ghost_kernels *kers) +void skin_surf_from_ghost_choose_kernel_cu( + const struct gkyl_basis basis, enum gkyl_edge_loc edge, int dir, + struct gkyl_skin_surf_from_ghost_kernels *kers +) { // Launch the kernel with a single thread to set the kernel pointers. - skin_surf_from_ghost_set_cu_ker_ptrs<<<1,1>>>(basis, edge, dir, kers); + skin_surf_from_ghost_set_cu_ker_ptrs<<<1, 1> > >(basis, edge, dir, kers); } // CUDA kernel to copy ghost cell values to the adjacent skin (boundary) cells on the GPU. -__global__ static void -skin_surf_from_ghost_advance_cu_ker(int dir, enum gkyl_edge_loc edge, - const struct gkyl_range skin_r, const struct gkyl_range ghost_r, - struct gkyl_array *field, struct gkyl_skin_surf_from_ghost_kernels *kers) +__global__ static void skin_surf_from_ghost_advance_cu_ker( + int dir, enum gkyl_edge_loc edge, const struct gkyl_range skin_r, const struct gkyl_range ghost_r, + struct gkyl_array *field, struct gkyl_skin_surf_from_ghost_kernels *kers +) { int sidx[GKYL_MAX_DIM]; // skin idx int gidx[GKYL_MAX_DIM]; // ghost idx @@ -48,24 +51,23 @@ skin_surf_from_ghost_advance_cu_ker(int dir, enum gkyl_edge_loc edge, int dim = skin_r.ndim; // Problem dimensionality. // Loop over all points in the skin range using CUDA threads. - for (unsigned long linc = threadIdx.x + blockIdx.x * blockDim.x; - linc < skin_r.volume; linc += blockDim.x * gridDim.x) { - + for (unsigned long linc = threadIdx.x + blockIdx.x * blockDim.x; linc < skin_r.volume; + linc += blockDim.x * gridDim.x) { // Convert the linear index to a multi-dimensional index in the skin range. gkyl_sub_range_inv_idx(&skin_r, linc, sidx); // Copy the current index. gkyl_copy_int_arr(dim, sidx, gidx); - gidx[dir] = edge == GKYL_LOWER_EDGE? sidx[dir]-1 : sidx[dir]+1; + gidx[dir] = edge == GKYL_LOWER_EDGE ? sidx[dir] - 1 : sidx[dir] + 1; // Compute the linear indices for both skin and ghost locations. long skin_loc = gkyl_range_idx(&skin_r, sidx); long ghost_loc = gkyl_range_idx(&ghost_r, gidx); // Fetch the values from the ghost region and copy them to the skin region. - const double *inp = (const double*) gkyl_array_cfetch(field, ghost_loc); - double *out = (double*) gkyl_array_fetch(field, skin_loc); + const double *inp = (const double *)gkyl_array_cfetch(field, ghost_loc); + double *out = (double *)gkyl_array_fetch(field, skin_loc); // Apply the ghost_to_skin kernel to transfer the ghost values to the skin cells. kers->ghost_to_skin(inp, out); @@ -73,15 +75,17 @@ skin_surf_from_ghost_advance_cu_ker(int dir, enum gkyl_edge_loc edge, } // Function to launch the CUDA kernel that performs the ghost-to-skin value transfer on the GPU. -void -skin_surf_from_ghost_advance_cu(const struct gkyl_skin_surf_from_ghost *up, struct gkyl_array *field) +void skin_surf_from_ghost_advance_cu( + const struct gkyl_skin_surf_from_ghost *up, struct gkyl_array *field +) { // Only proceed if the skin range has a non-zero volume (i.e., there are skin cells to update). if (up->skin_r->volume > 0) { int nblocks = up->skin_r->nblocks, nthreads = up->skin_r->nthreads; // CUDA grid configuration. // Launch the CUDA kernel to advance the ghost-to-skin update. - skin_surf_from_ghost_advance_cu_ker<<>>(up->dir, up->edge, - *up->skin_r, *up->ghost_r, field->on_dev, up->kernels); + skin_surf_from_ghost_advance_cu_ker<< > >( + up->dir, up->edge, *up->skin_r, *up->ghost_r, field->on_dev, up->kernels + ); } } diff --git a/core/zero/superlu_ops.c b/core/zero/superlu_ops.c index ffbfe2094d..df31a73110 100644 --- a/core/zero/superlu_ops.c +++ b/core/zero/superlu_ops.c @@ -7,7 +7,7 @@ struct gkyl_superlu_prob { SuperMatrix **A, **B; // matrices in A_j x_j = B_j problems. SuperMatrix **L, **U; // L and U factors in LU decomposition. - double *rhs; // right-hand side entries. + double *rhs; // right-hand side entries. int *perm_c; // column permutation vector (re-used for each problem). int **perm_r; // row permutations from partial pivoting. int mrow, ncol; // A is a mrow x ncol matrix. @@ -16,8 +16,8 @@ struct gkyl_superlu_prob { int nrhs; // number of columns of the RHS (B is an mrow x nrhs matrix). double **nzvals; // non-zero matrix elements. - int **rowinds; // row index of entries in nzval. - int **colptrs; // 1st entry of each column as index in nzval. + int **rowinds; // row index of entries in nzval. + int **colptrs; // 1st entry of each column as index in nzval. int info, permc_spec; superlu_options_t options; @@ -36,10 +36,9 @@ struct gkyl_superlu_prob { bool LU_in_work; }; -gkyl_superlu_prob* -gkyl_superlu_prob_new(int nprob, int mrow, int ncol, int nrhs) +gkyl_superlu_prob *gkyl_superlu_prob_new(int nprob, int mrow, int ncol, int nrhs) { - assert((nprob==1) || (nrhs==1)); + assert((nprob == 1) || (nrhs == 1)); struct gkyl_superlu_prob *prob = gkyl_malloc(sizeof(*prob)); @@ -48,24 +47,25 @@ gkyl_superlu_prob_new(int nprob, int mrow, int ncol, int nrhs) prob->ncol = ncol; prob->nrhs = nrhs; - prob->A = gkyl_malloc(prob->nprob*sizeof(SuperMatrix *)); - prob->B = gkyl_malloc(prob->nprob*sizeof(SuperMatrix *)); - prob->L = gkyl_malloc(prob->nprob*sizeof(SuperMatrix *)); - prob->U = gkyl_malloc(prob->nprob*sizeof(SuperMatrix *)); - for (size_t k=0; knprob; k++) { + prob->A = gkyl_malloc(prob->nprob * sizeof(SuperMatrix *)); + prob->B = gkyl_malloc(prob->nprob * sizeof(SuperMatrix *)); + prob->L = gkyl_malloc(prob->nprob * sizeof(SuperMatrix *)); + prob->U = gkyl_malloc(prob->nprob * sizeof(SuperMatrix *)); + for (size_t k = 0; k < prob->nprob; k++) { prob->A[k] = gkyl_malloc(sizeof(SuperMatrix)); prob->B[k] = gkyl_malloc(sizeof(SuperMatrix)); prob->L[k] = gkyl_malloc(sizeof(SuperMatrix)); prob->U[k] = gkyl_malloc(sizeof(SuperMatrix)); } - prob->rhs = doubleMalloc(mrow*GKYL_MAX2(nprob,nrhs)); + prob->rhs = doubleMalloc(mrow * GKYL_MAX2(nprob, nrhs)); prob->perm_c = intMalloc(ncol); - prob->perm_r = gkyl_malloc(prob->nprob*sizeof(int *)); - for (size_t k=0; knprob; k++) + prob->perm_r = gkyl_malloc(prob->nprob * sizeof(int *)); + for (size_t k = 0; k < prob->nprob; k++) { prob->perm_r[k] = intMalloc(mrow); + } - prob->Glu = gkyl_malloc(prob->nprob*sizeof(GlobalLU_t)); + prob->Glu = gkyl_malloc(prob->nprob * sizeof(GlobalLU_t)); // Set the default input options. set_default_options(&prob->options); @@ -85,30 +85,39 @@ gkyl_superlu_prob_new(int nprob, int mrow, int ncol, int nrhs) prob->trans = NOTRANS; // Create the RHS matrix B, with random data for now. - for (size_t k=0; krhs[k] = 1.0; + } + + for (size_t k = 0; k < prob->nprob; k++) { + dCreate_Dense_Matrix( + prob->B[k], prob->mrow, prob->nrhs, &prob->rhs[k * prob->mrow], prob->mrow, SLU_DN, SLU_D, + SLU_GE + ); + } - for (size_t k=0; knprob; k++) - dCreate_Dense_Matrix(prob->B[k], prob->mrow, prob->nrhs, &prob->rhs[k*prob->mrow], prob->mrow, - SLU_DN, SLU_D, SLU_GE); - // Arguments needed by the expert driver. prob->equed = 'N'; - if ( !(prob->etree = intMalloc(ncol)) ) + if (!(prob->etree = intMalloc(ncol))) { ABORT("superlu_ops: Malloc fails for etree[]."); - if ( !(prob->R = (double *) SUPERLU_MALLOC(mrow * sizeof(double))) ) + } + if (!(prob->R = (double *)SUPERLU_MALLOC(mrow * sizeof(double)))) { ABORT("superlu_ops: Malloc fails for R[]."); - if ( !(prob->C = (double *) SUPERLU_MALLOC(ncol * sizeof(double))) ) + } + if (!(prob->C = (double *)SUPERLU_MALLOC(ncol * sizeof(double)))) { ABORT("superlu_ops: Malloc fails for C[]."); - if ( !(prob->ferr = (double *) SUPERLU_MALLOC(nrhs * sizeof(double))) ) + } + if (!(prob->ferr = (double *)SUPERLU_MALLOC(nrhs * sizeof(double)))) { ABORT("superlu_ops: Malloc fails for ferr[]."); - if ( !(prob->berr = (double *) SUPERLU_MALLOC(nrhs * sizeof(double))) ) + } + if (!(prob->berr = (double *)SUPERLU_MALLOC(nrhs * sizeof(double)))) { ABORT("superlu_ops: Malloc fails for berr[]."); + } prob->LU_in_work = false; - prob->work = gkyl_malloc(prob->nprob*sizeof(void *)); - prob->lwork = gkyl_malloc(prob->nprob*sizeof(int)); - for (size_t k=0; knprob; k++) { + prob->work = gkyl_malloc(prob->nprob * sizeof(void *)); + prob->lwork = gkyl_malloc(prob->nprob * sizeof(int)); + for (size_t k = 0; k < prob->nprob; k++) { prob->work[k] = 0; prob->lwork[k] = 0; } @@ -116,44 +125,45 @@ gkyl_superlu_prob_new(int nprob, int mrow, int ncol, int nrhs) return prob; } -void -gkyl_superlu_amat_from_triples(struct gkyl_superlu_prob *prob, struct gkyl_mat_triples **tri) +void gkyl_superlu_amat_from_triples(struct gkyl_superlu_prob *prob, struct gkyl_mat_triples **tri) { prob->nnz = gkyl_mat_triples_size(tri[0]); - for (size_t k=0; knprob; k++) { - assert(gkyl_mat_triples_size(tri[k]) == prob->nnz); // No. of nonzeros must be the same for every problem. - assert(gkyl_mat_triples_is_colmaj(tri[k])); // triples must be in colmaj order for superlu. + for (size_t k = 0; k < prob->nprob; k++) { + assert( + gkyl_mat_triples_size(tri[k]) == prob->nnz + ); // No. of nonzeros must be the same for every problem. + assert(gkyl_mat_triples_is_colmaj(tri[k])); // triples must be in colmaj order for superlu. } // Allocate some memory needed in superlu. NOTE: this memory is // deleted when Destroy_CompCol_Matrix is called, and so we do not // need to do it ourselves. - prob->nzvals = gkyl_malloc(prob->nprob*sizeof(double *)); - prob->rowinds = gkyl_malloc(prob->nprob*sizeof(int *)); - prob->colptrs = gkyl_malloc(prob->nprob*sizeof(int *)); - for (size_t k=0; knprob; k++) { + prob->nzvals = gkyl_malloc(prob->nprob * sizeof(double *)); + prob->rowinds = gkyl_malloc(prob->nprob * sizeof(int *)); + prob->colptrs = gkyl_malloc(prob->nprob * sizeof(int *)); + for (size_t k = 0; k < prob->nprob; k++) { prob->nzvals[k] = doubleMalloc(prob->nnz); // non-zero matrix elements. prob->rowinds[k] = intMalloc(prob->nnz); // row index of entries in nzval. - prob->colptrs[k] = intMalloc(prob->ncol+1); // 1st entry of each column as index in nzval. + prob->colptrs[k] = intMalloc(prob->ncol + 1); // 1st entry of each column as index in nzval. } - bool *colptr_assigned = gkyl_malloc(prob->ncol*sizeof(bool)); + bool *colptr_assigned = gkyl_malloc(prob->ncol * sizeof(bool)); // Sorted (column-major order) keys (linear indices to flattened matrix). - for (size_t k=0; knprob; k++) { - + for (size_t k = 0; k < prob->nprob; k++) { double *nzval = prob->nzvals[k]; int *rowind = prob->rowinds[k]; int *colptr = prob->colptrs[k]; - for (size_t i=0; incol; i++) + for (size_t i = 0; i < prob->ncol; i++) { colptr_assigned[i] = false; + } gkyl_mat_triples_iter *iter = gkyl_mat_triples_iter_new(tri[k]); - for (size_t i=0; innz; ++i) { + for (size_t i = 0; i < prob->nnz; ++i) { gkyl_mat_triples_iter_next(iter); // bump iterator. struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); - size_t idx[2] = { mt.row, mt.col }; - + size_t idx[2] = {mt.row, mt.col}; + nzval[i] = mt.val; rowind[i] = idx[0]; if (!colptr_assigned[idx[1]]) { @@ -165,27 +175,26 @@ gkyl_superlu_amat_from_triples(struct gkyl_superlu_prob *prob, struct gkyl_mat_t gkyl_mat_triples_iter_release(iter); // Create matrix A. See SuperLU manual for definitions. - dCreate_CompCol_Matrix(prob->A[k], prob->mrow, prob->ncol, prob->nnz, - nzval, rowind, colptr, SLU_NC, SLU_D, SLU_GE); + dCreate_CompCol_Matrix( + prob->A[k], prob->mrow, prob->ncol, prob->nnz, nzval, rowind, colptr, SLU_NC, SLU_D, SLU_GE + ); } - + gkyl_free(colptr_assigned); prob->options.Fact = DOFACT; // Haven't computed LU decomp yet. } -void -gkyl_superlu_print_amat(struct gkyl_superlu_prob *prob) +void gkyl_superlu_print_amat(struct gkyl_superlu_prob *prob) { char strA[5]; - for (size_t k=0; knprob; k++) { + for (size_t k = 0; k < prob->nprob; k++) { snprintf(strA, 5, "A%zu", k); // puts string into buffer dPrint_CompCol_Matrix(strA, prob->A[k]); } } -void -gkyl_superlu_ludecomp(struct gkyl_superlu_prob *prob) +void gkyl_superlu_ludecomp(struct gkyl_superlu_prob *prob) { /* * Get column permutation vector perm_c[], according to permc_spec: @@ -194,67 +203,73 @@ gkyl_superlu_ludecomp(struct gkyl_superlu_prob *prob) * = 2: minimum degree on structure of A’+A * = 3: approximate minimum degree for unsymmetric matrices */ - int permc_spec = 0; + int permc_spec = 0; get_perm_c(permc_spec, prob->A[0], prob->perm_c); int *etree; // Column elimination tree. - if ( !(etree = intMalloc(prob->ncol)) ) ABORT("superlu_ops: Malloc fails for etree[]."); + if (!(etree = intMalloc(prob->ncol))) { + ABORT("superlu_ops: Malloc fails for etree[]."); + } SuperMatrix AC; // permutation matrix time A. sp_preorder(&prob->options, prob->A[0], prob->perm_c, etree, &AC); int panel_size = sp_ienv(1); int relax = sp_ienv(2); - dgstrf(&prob->options, &AC, relax, panel_size, etree, NULL, 0, prob->perm_c, - prob->perm_r[0], prob->L[0], prob->U[0], &prob->Glu[0], &prob->stat, &prob->info); - - prob->options.Fact = prob->nprob==1? FACTORED : SamePattern; // LU decomp done. - - for (size_t k=1; knprob; k++) { - dgstrf(&prob->options, &AC, relax, panel_size, etree, NULL, 0, prob->perm_c, - prob->perm_r[k], prob->L[k], prob->U[k], &prob->Glu[k], &prob->stat, &prob->info); + dgstrf( + &prob->options, &AC, relax, panel_size, etree, NULL, 0, prob->perm_c, prob->perm_r[0], + prob->L[0], prob->U[0], &prob->Glu[0], &prob->stat, &prob->info + ); + + prob->options.Fact = prob->nprob == 1 ? FACTORED : SamePattern; // LU decomp done. + + for (size_t k = 1; k < prob->nprob; k++) { + dgstrf( + &prob->options, &AC, relax, panel_size, etree, NULL, 0, prob->perm_c, prob->perm_r[k], + prob->L[k], prob->U[k], &prob->Glu[k], &prob->stat, &prob->info + ); } SUPERLU_FREE(etree); Destroy_CompCol_Permuted(&AC); } -void -gkyl_superlu_brhs_from_triples(struct gkyl_superlu_prob *prob, struct gkyl_mat_triples *tri) +void gkyl_superlu_brhs_from_triples(struct gkyl_superlu_prob *prob, struct gkyl_mat_triples *tri) { - long nnz_rhs = gkyl_mat_triples_size(tri); // number of non-zero entries in RHS matrix B - + long nnz_rhs = gkyl_mat_triples_size(tri); // number of non-zero entries in RHS matrix B + // sorted (column-major order) keys (linear indices to flattened matrix) gkyl_mat_triples_iter *iter = gkyl_mat_triples_iter_new(tri); - for (size_t k=0; knprob; k++) { - double *B_curr = (double*)((DNformat*)prob->B[k]->Store)->nzval; - for (size_t i=0; imrow*prob->nrhs; i++) { + for (size_t k = 0; k < prob->nprob; k++) { + double *B_curr = (double *)((DNformat *)prob->B[k]->Store)->nzval; + for (size_t i = 0; i < prob->mrow * prob->nrhs; i++) { gkyl_mat_triples_iter_next(iter); // bump iterator - struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); + struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); B_curr[i] = mt.val; } } gkyl_mat_triples_iter_release(iter); } -void -gkyl_superlu_brhs_from_array(struct gkyl_superlu_prob *prob, const double *bin) +void gkyl_superlu_brhs_from_array(struct gkyl_superlu_prob *prob, const double *bin) { - for (size_t k=0; knprob; k++) { - double *B_curr = (double*)((DNformat*)prob->B[k]->Store)->nzval; - for (size_t i=0; imrow*prob->nrhs; i++) - B_curr[i] = bin[k*prob->mrow*prob->nrhs+i]; + for (size_t k = 0; k < prob->nprob; k++) { + double *B_curr = (double *)((DNformat *)prob->B[k]->Store)->nzval; + for (size_t i = 0; i < prob->mrow * prob->nrhs; i++) { + B_curr[i] = bin[k * prob->mrow * prob->nrhs + i]; + } } } -static void -superlu_alloc_work_if_needed(struct gkyl_superlu_prob *prob, int k) +static void superlu_alloc_work_if_needed(struct gkyl_superlu_prob *prob, int k) { // MF 2026/03/19: Function generated by Opus, provided by @junoravin. // It doesn't quite match some things I see in the SuperLU source code, but it works and is valgrind free. // I also tried calling dgssvx with lwork=-1 to get the right size, but that also produced estimates lower // than neeed, and even if I increase them by 8X, it is not valgrind clean. - if (prob->lwork[k] > 0) return; // Already allocated. + if (prob->lwork[k] > 0) { + return; // Already allocated. + } // Compute work buffer size matching what dLUMemInit + dLUWorkInit need. // The buffer holds factor data (HEAD), and temporary workspace (TAIL). @@ -280,19 +295,23 @@ superlu_alloc_work_if_needed(struct gkyl_superlu_prob *prob, int k) // 1.5x margin to accommodate fill-in growth (matches SuperLU's internal // expansion factor) and alignment overhead in USER memory mode. prob->lwork[k] = (int_t)(1.5 * (glu_int_arrays + factor_storage + isize + dsize)); - if ( !(prob->work[k] = SUPERLU_MALLOC(prob->lwork[k])) ) + if (!(prob->work[k] = SUPERLU_MALLOC(prob->lwork[k]))) { ABORT("superlu_ops: Malloc fails for work[]."); + } } -void -gkyl_superlu_solve(struct gkyl_superlu_prob *prob) +void gkyl_superlu_solve(struct gkyl_superlu_prob *prob) { - if (prob->options.Fact==FACTORED) { - for (size_t k=0; knprob; k++) - dgstrs(prob->trans, prob->L[k], prob->U[k], prob->perm_c, prob->perm_r[k], prob->B[k], &prob->stat, &prob->info); + if (prob->options.Fact == FACTORED) { + for (size_t k = 0; k < prob->nprob; k++) { + dgstrs( + prob->trans, prob->L[k], prob->U[k], prob->perm_c, prob->perm_r[k], prob->B[k], &prob->stat, + &prob->info + ); + } } else { if (prob->options.Fact == SamePattern) { - for (size_t k=0; knprob; k++) { + for (size_t k = 0; k < prob->nprob; k++) { Destroy_SuperMatrix_Store(prob->L[k]); Destroy_SuperMatrix_Store(prob->U[k]); } @@ -300,18 +319,24 @@ gkyl_superlu_solve(struct gkyl_superlu_prob *prob) superlu_alloc_work_if_needed(prob, 0); - dgssvx(&prob->options, prob->A[0], prob->perm_c, prob->perm_r[0], prob->etree, &prob->equed, prob->R, prob->C, - prob->L[0], prob->U[0], prob->work[0], prob->lwork[0], prob->B[0], prob->B[0], &prob->rpg, &prob->rcond, - prob->ferr, prob->berr, &prob->Glu[0], &prob->mem_usage, &prob->stat, &prob->info); + dgssvx( + &prob->options, prob->A[0], prob->perm_c, prob->perm_r[0], prob->etree, &prob->equed, prob->R, + prob->C, prob->L[0], prob->U[0], prob->work[0], prob->lwork[0], prob->B[0], prob->B[0], + &prob->rpg, &prob->rcond, prob->ferr, prob->berr, &prob->Glu[0], &prob->mem_usage, + &prob->stat, &prob->info + ); - prob->options.Fact = prob->nprob==1? FACTORED : SamePattern; // LU decomp done. + prob->options.Fact = prob->nprob == 1 ? FACTORED : SamePattern; // LU decomp done. - for (size_t k=1; knprob; k++) { + for (size_t k = 1; k < prob->nprob; k++) { superlu_alloc_work_if_needed(prob, k); - dgssvx(&prob->options, prob->A[k], prob->perm_c, prob->perm_r[k], prob->etree, &prob->equed, prob->R, prob->C, - prob->L[k], prob->U[k], prob->work[k], prob->lwork[k], prob->B[k], prob->B[k], &prob->rpg, &prob->rcond, - prob->ferr, prob->berr, &prob->Glu[k], &prob->mem_usage, &prob->stat, &prob->info); + dgssvx( + &prob->options, prob->A[k], prob->perm_c, prob->perm_r[k], prob->etree, &prob->equed, + prob->R, prob->C, prob->L[k], prob->U[k], prob->work[k], prob->lwork[k], prob->B[k], + prob->B[k], &prob->rpg, &prob->rcond, prob->ferr, prob->berr, &prob->Glu[k], + &prob->mem_usage, &prob->stat, &prob->info + ); } prob->LU_in_work = true; @@ -319,58 +344,55 @@ gkyl_superlu_solve(struct gkyl_superlu_prob *prob) } } -void -gkyl_superlu_amat_update_from_triples(struct gkyl_superlu_prob *prob, struct gkyl_mat_triples **tri) +void gkyl_superlu_amat_update_from_triples( + struct gkyl_superlu_prob *prob, struct gkyl_mat_triples **tri +) { - for (size_t k=0; knprob; k++) { - assert(gkyl_mat_triples_size(tri[k]) == prob->nnz); // No. of nonzeros must be the same for every problem. - assert(gkyl_mat_triples_is_colmaj(tri[k])); // triples must be in colmaj order for superlu. + for (size_t k = 0; k < prob->nprob; k++) { + assert( + gkyl_mat_triples_size(tri[k]) == prob->nnz + ); // No. of nonzeros must be the same for every problem. + assert(gkyl_mat_triples_is_colmaj(tri[k])); // triples must be in colmaj order for superlu. } // Sorted (column-major order) keys (linear indices to flattened matrix). - for (size_t k=0; knprob; k++) { - - double *nzval = (double*)((NCformat*)prob->A[k]->Store)->nzval; + for (size_t k = 0; k < prob->nprob; k++) { + double *nzval = (double *)((NCformat *)prob->A[k]->Store)->nzval; gkyl_mat_triples_iter *iter = gkyl_mat_triples_iter_new(tri[k]); - for (size_t i=0; innz; ++i) { + for (size_t i = 0; i < prob->nnz; ++i) { gkyl_mat_triples_iter_next(iter); // bump iterator. struct gkyl_mtriple mt = gkyl_mat_triples_iter_at(iter); - size_t idx[2] = { mt.row, mt.col }; - + size_t idx[2] = {mt.row, mt.col}; + nzval[i] = mt.val; } gkyl_mat_triples_iter_release(iter); } - + prob->options.Fact = SamePattern; } -double -gkyl_superlu_get_rhs_ij(struct gkyl_superlu_prob *prob, long ielement, long jprob) +double gkyl_superlu_get_rhs_ij(struct gkyl_superlu_prob *prob, long ielement, long jprob) { - return prob->rhs[jprob*prob->mrow+ielement]; + return prob->rhs[jprob * prob->mrow + ielement]; } - -double -gkyl_superlu_get_rhs_lin(struct gkyl_superlu_prob *prob, long loc) +double gkyl_superlu_get_rhs_lin(struct gkyl_superlu_prob *prob, long loc) { return prob->rhs[loc]; } -double* -gkyl_superlu_get_rhs_ptr(struct gkyl_superlu_prob *prob, long loc) +double *gkyl_superlu_get_rhs_ptr(struct gkyl_superlu_prob *prob, long loc) { return &prob->rhs[loc]; } -void -gkyl_superlu_prob_release(struct gkyl_superlu_prob *prob) +void gkyl_superlu_prob_release(struct gkyl_superlu_prob *prob) { SUPERLU_FREE(prob->rhs); SUPERLU_FREE(prob->perm_c); - + // Free objects needed for the expert driver. SUPERLU_FREE(prob->etree); SUPERLU_FREE(prob->R); @@ -378,19 +400,18 @@ gkyl_superlu_prob_release(struct gkyl_superlu_prob *prob) SUPERLU_FREE(prob->ferr); SUPERLU_FREE(prob->berr); - for (size_t k=0; knprob; k++) { + for (size_t k = 0; k < prob->nprob; k++) { SUPERLU_FREE(prob->perm_r[k]); Destroy_CompCol_Matrix(prob->A[k]); Destroy_SuperMatrix_Store(prob->B[k]); gkyl_free(prob->A[k]); gkyl_free(prob->B[k]); - if (prob->options.Fact==FACTORED) { + if (prob->options.Fact == FACTORED) { if (prob->LU_in_work) { Destroy_SuperMatrix_Store(prob->L[k]); Destroy_SuperMatrix_Store(prob->U[k]); - } - else { + } else { Destroy_SuperNode_Matrix(prob->L[k]); Destroy_CompCol_Matrix(prob->U[k]); } @@ -400,9 +421,10 @@ gkyl_superlu_prob_release(struct gkyl_superlu_prob *prob) gkyl_free(prob->U[k]); } - for (size_t k=0; knprob; k++) { - if (prob->work[k]) + for (size_t k = 0; k < prob->nprob; k++) { + if (prob->work[k]) { SUPERLU_FREE(prob->work[k]); + } } gkyl_free(prob->work); gkyl_free(prob->lwork); diff --git a/core/zero/tensor_field.c b/core/zero/tensor_field.c index ec6b33ffef..587966f559 100644 --- a/core/zero/tensor_field.c +++ b/core/zero/tensor_field.c @@ -3,9 +3,8 @@ #include #include #include - -static void -tensor_field_free(const struct gkyl_ref_count *ref) + +static void tensor_field_free(const struct gkyl_ref_count *ref) { struct gkyl_tensor_field *tfld = container_of(ref, struct gkyl_tensor_field, ref_count); @@ -26,63 +25,62 @@ gkyl_tensor_field_new(size_t rank, size_t ndim, size_t size, const enum gkyl_ten size_t ncomp = 1; int shape[rank]; - for (int i=0; iflags = 0; tfld->tdata = gkyl_array_new(GKYL_DOUBLE, ncomp, size); gkyl_range_init_from_shape(&tfld->trange, rank, shape); - for (int i=0; iiloc[i] = iloc[i]; // either upper or lower indices } tfld->ref_count = gkyl_ref_count_init(tensor_field_free); - + return tfld; } -struct gkyl_tensor_field* -gkyl_tensor_field_acquire(const struct gkyl_tensor_field* tfld) +struct gkyl_tensor_field *gkyl_tensor_field_acquire(const struct gkyl_tensor_field *tfld) { gkyl_ref_count_inc(&tfld->ref_count); - return (struct gkyl_tensor_field*) tfld; + return (struct gkyl_tensor_field *)tfld; } -struct gkyl_tensor_field* -gkyl_tensor_field_copy(struct gkyl_tensor_field* dest, const struct gkyl_tensor_field* src) +struct gkyl_tensor_field * +gkyl_tensor_field_copy(struct gkyl_tensor_field *dest, const struct gkyl_tensor_field *src) { - for (int i=0; iiloc[i] = src->iloc[i]; + } gkyl_array_copy(dest->tdata, src->tdata); return dest; } -void -gkyl_tensor_field_release(const struct gkyl_tensor_field* ten) +void gkyl_tensor_field_release(const struct gkyl_tensor_field *ten) { - if (ten) + if (ten) { gkyl_ref_count_dec(&ten->ref_count); + } } -bool -gkyl_tensor_field_is_cu_dev(const struct gkyl_tensor_field *tfld) +bool gkyl_tensor_field_is_cu_dev(const struct gkyl_tensor_field *tfld) { - return GKYL_IS_CU_ALLOC(tfld->flags); + return GKYL_IS_CU_ALLOC(tfld->flags); } - // CUDA specific code #ifdef GKYL_HAVE_CUDA -struct gkyl_tensor_field* -gkyl_tensor_field_cu_dev_new(size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc) +struct gkyl_tensor_field *gkyl_tensor_field_cu_dev_new( + size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc +) { - struct gkyl_tensor_field* tfld = gkyl_malloc(sizeof(struct gkyl_tensor_field)); + struct gkyl_tensor_field *tfld = gkyl_malloc(sizeof(struct gkyl_tensor_field)); tfld->rank = rank; tfld->ndim = ndim; @@ -90,18 +88,18 @@ gkyl_tensor_field_cu_dev_new(size_t rank, size_t ndim, size_t size, const enum g size_t ncomp = 1; int shape[rank]; - for (int i=0; itdata = gkyl_array_cu_dev_new(GKYL_DOUBLE, ncomp, size); + tfld->tdata = gkyl_array_cu_dev_new(GKYL_DOUBLE, ncomp, size); gkyl_range_init_from_shape(&tfld->trange, rank, shape); tfld->ref_count = gkyl_ref_count_init(tensor_field_free); GKYL_SET_CU_ALLOC(tfld->flags); - - for (int i=0; iiloc[i] = iloc[i]; // either upper or lower indices } @@ -111,15 +109,16 @@ gkyl_tensor_field_cu_dev_new(size_t rank, size_t ndim, size_t size, const enum g gkyl_cu_memcpy(tfld->on_dev, tfld, sizeof(struct gkyl_tensor_field), GKYL_CU_MEMCPY_H2D); // set device-side data pointer in tfld->on_dev to tfld->data->on-dev // (which is the host-side pointer to the device data) - gkyl_cu_memcpy(&((tfld->on_dev)->tdata), &tfld->tdata->on_dev, sizeof(void*), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(&((tfld->on_dev)->tdata), &tfld->tdata->on_dev, sizeof(void *), GKYL_CU_MEMCPY_H2D); return tfld; } -struct gkyl_tensor_field* -gkyl_tensor_field_cu_host_new(size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc) +struct gkyl_tensor_field *gkyl_tensor_field_cu_host_new( + size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc +) { - struct gkyl_tensor_field* tfld = gkyl_cu_malloc_host(sizeof(struct gkyl_tensor_field)); + struct gkyl_tensor_field *tfld = gkyl_cu_malloc_host(sizeof(struct gkyl_tensor_field)); tfld->rank = rank; tfld->ndim = ndim; @@ -127,38 +126,42 @@ gkyl_tensor_field_cu_host_new(size_t rank, size_t ndim, size_t size, const enum size_t ncomp = 1; int shape[rank]; - for (int i=0; itdata = gkyl_array_cu_host_new(GKYL_DOUBLE, ncomp, size); // gkyl_cu_malloc_host(tfld->size*tfld->esznc); + tfld->tdata = gkyl_array_cu_host_new( + GKYL_DOUBLE, ncomp, + size + ); // gkyl_cu_malloc_host(tfld->size*tfld->esznc); gkyl_range_init_from_shape(&tfld->trange, rank, shape); tfld->ref_count = gkyl_ref_count_init(tensor_field_free); tfld->flags = 0; - for (int i=0; iiloc[i] = iloc[i]; // either upper or lower indices } tfld->on_dev = tfld; // on_dev reference - + return tfld; } - #else -struct gkyl_tensor_field* -gkyl_tensor_field_cu_dev_new(size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc) +struct gkyl_tensor_field *gkyl_tensor_field_cu_dev_new( + size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc +) { assert(false); return 0; } -struct gkyl_tensor_field* -gkyl_tensor_field_cu_host_new(size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc) +struct gkyl_tensor_field *gkyl_tensor_field_cu_host_new( + size_t rank, size_t ndim, size_t size, const enum gkyl_tensor_index_loc *iloc +) { assert(false); return 0; diff --git a/core/zero/tensor_field_ops.c b/core/zero/tensor_field_ops.c index 390bb8f8a6..51103e98aa 100644 --- a/core/zero/tensor_field_ops.c +++ b/core/zero/tensor_field_ops.c @@ -3,51 +3,52 @@ #include - -static void -tensor_field_raise_or_lower_idx_in_place(struct gkyl_tensor_field *met, int raised_idx, - struct gkyl_tensor_field *ten, struct gkyl_tensor_field *mem) +static void tensor_field_raise_or_lower_idx_in_place( + struct gkyl_tensor_field *met, int raised_idx, struct gkyl_tensor_field *ten, + struct gkyl_tensor_field *mem +) { - #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(ten->tdata)) { + if (gkyl_array_is_cu_dev(ten->tdata)) { // make a temporary amount of memory on device enum gkyl_tensor_index_loc iloc[GKYL_MAX_DIM]; - for (int i=0; iiloc[i] = ten->iloc[i]; + } // set the input to the memory, mem - tensor_field_raise_or_lower_idx_set_cu(met, raised_idx, ten, mem); + tensor_field_raise_or_lower_idx_set_cu(met, raised_idx, ten, mem); // copy mem to ten gkyl_tensor_field_copy(ten, mem); - return; + return; } #endif // iterate over the field of tensors - for (long i=0; isize; ++i){ + for (long i = 0; i < ten->size; ++i) { const double *metric = gkyl_tensor_field_cfetch(met, i); // loop over the output tensor indices struct gkyl_range_iter iter_tf_out; gkyl_range_iter_init(&iter_tf_out, &ten->trange); while (gkyl_range_iter_next(&iter_tf_out)) { - double ten_out_elem = 0; + double ten_out_elem = 0; int index_raised = iter_tf_out.idx[raised_idx]; - + // summed over index, j - for (int j=0; jndim; ++j) { - int idx_met[GKYL_MAX_DIM] = { index_raised, j }; - + for (int j = 0; j < ten->ndim; ++j) { + int idx_met[GKYL_MAX_DIM] = {index_raised, j}; + // Get the tensor element we are indexing from int idx_tf[GKYL_MAX_DIM]; - for (int k=0; ktdata)) { tensor_field_raise_or_lower_idx_set_cu(met, raised_idx, ten, tensor_out); return; } + if (gkyl_array_is_cu_dev(ten->tdata)) { + tensor_field_raise_or_lower_idx_set_cu(met, raised_idx, ten, tensor_out); + return; + } #endif // iterate over the field of tensors - for (long i=0; isize; ++i){ + for (long i = 0; i < ten->size; ++i) { const double *metric = gkyl_tensor_field_cfetch(met, i); // loop over the output tensor indices struct gkyl_range_iter iter_tf_out; gkyl_range_iter_init(&iter_tf_out, &ten->trange); while (gkyl_range_iter_next(&iter_tf_out)) { - double ten_out_elem = 0; + double ten_out_elem = 0; int index_raised = iter_tf_out.idx[raised_idx]; - + // summed over index, j - for (int j=0; jndim; ++j) { - int idx_met[GKYL_MAX_DIM] = { index_raised, j }; - + for (int j = 0; j < ten->ndim; ++j) { + int idx_met[GKYL_MAX_DIM] = {index_raised, j}; + // Get the tensor element we are indexing from int idx_tf[GKYL_MAX_DIM]; - for (int k=0; kiloc[lowered_idx] == GKYL_TENSOR_INDEX_UPPER ); - assert( metric->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - assert( metric->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); + assert(ten->iloc[lowered_idx] == GKYL_TENSOR_INDEX_UPPER); + assert(metric->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + assert(metric->iloc[1] == GKYL_TENSOR_INDEX_LOWER); tensor_field_raise_or_lower_idx_in_place(metric, lowered_idx, ten, mem); ten->iloc[lowered_idx] = GKYL_TENSOR_INDEX_LOWER; } -void -gkyl_tensor_field_raise_idx_in_place(struct gkyl_tensor_field *metric, int raised_idx, - struct gkyl_tensor_field *ten, struct gkyl_tensor_field *mem) +void gkyl_tensor_field_raise_idx_in_place( + struct gkyl_tensor_field *metric, int raised_idx, struct gkyl_tensor_field *ten, + struct gkyl_tensor_field *mem +) { // Check that we are lowering a contravariant index - assert( ten->iloc[raised_idx] == GKYL_TENSOR_INDEX_LOWER ); - assert( metric->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - assert( metric->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); + assert(ten->iloc[raised_idx] == GKYL_TENSOR_INDEX_LOWER); + assert(metric->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + assert(metric->iloc[1] == GKYL_TENSOR_INDEX_UPPER); tensor_field_raise_or_lower_idx_in_place(metric, raised_idx, ten, mem); ten->iloc[raised_idx] = GKYL_TENSOR_INDEX_UPPER; } -void -gkyl_tensor_field_lower_idx_set(const struct gkyl_tensor_field *metric, int lowered_idx, - const struct gkyl_tensor_field *ten, struct gkyl_tensor_field *ten_out) +void gkyl_tensor_field_lower_idx_set( + const struct gkyl_tensor_field *metric, int lowered_idx, const struct gkyl_tensor_field *ten, + struct gkyl_tensor_field *ten_out +) { // Check that we are lowering a contravariant index - assert( ten->iloc[lowered_idx] == GKYL_TENSOR_INDEX_UPPER ); - assert( metric->iloc[0] == GKYL_TENSOR_INDEX_LOWER ); - assert( metric->iloc[1] == GKYL_TENSOR_INDEX_LOWER ); + assert(ten->iloc[lowered_idx] == GKYL_TENSOR_INDEX_UPPER); + assert(metric->iloc[0] == GKYL_TENSOR_INDEX_LOWER); + assert(metric->iloc[1] == GKYL_TENSOR_INDEX_LOWER); tensor_field_raise_or_lower_idx_set(metric, lowered_idx, ten, ten_out); ten_out->iloc[lowered_idx] = GKYL_TENSOR_INDEX_LOWER; } -void -gkyl_tensor_field_raise_idx_set(const struct gkyl_tensor_field *metric, int raised_idx, - const struct gkyl_tensor_field *ten, struct gkyl_tensor_field *ten_out) +void gkyl_tensor_field_raise_idx_set( + const struct gkyl_tensor_field *metric, int raised_idx, const struct gkyl_tensor_field *ten, + struct gkyl_tensor_field *ten_out +) { // Check that we are lowering a contravariant index - assert( ten->iloc[raised_idx] == GKYL_TENSOR_INDEX_LOWER ); - assert( metric->iloc[0] == GKYL_TENSOR_INDEX_UPPER ); - assert( metric->iloc[1] == GKYL_TENSOR_INDEX_UPPER ); + assert(ten->iloc[raised_idx] == GKYL_TENSOR_INDEX_LOWER); + assert(metric->iloc[0] == GKYL_TENSOR_INDEX_UPPER); + assert(metric->iloc[1] == GKYL_TENSOR_INDEX_UPPER); tensor_field_raise_or_lower_idx_set(metric, raised_idx, ten, ten_out); ten_out->iloc[raised_idx] = GKYL_TENSOR_INDEX_UPPER; } \ No newline at end of file diff --git a/core/zero/tensor_field_ops_cu.cu b/core/zero/tensor_field_ops_cu.cu index f30b5aa1f8..d4e39604aa 100644 --- a/core/zero/tensor_field_ops_cu.cu +++ b/core/zero/tensor_field_ops_cu.cu @@ -7,49 +7,50 @@ extern "C" { #include } - -static void -gkyl_get_tensor_field_range_kernel_launch_dims(dim3* dimGrid, dim3* dimBlock, gkyl_range trange, int size) +static void gkyl_get_tensor_field_range_kernel_launch_dims( + dim3 *dimGrid, dim3 *dimBlock, gkyl_range trange, int size +) { - // Create a 2D thread grid so we launch size*trange.volume number of threads + // Create a 2D thread grid so we launch size*trange.volume number of threads // so we can parallelize over tensor components too dimBlock->y = trange.volume; // ncomp *must* be less than 256 dimGrid->y = 1; - dimBlock->x = GKYL_DEFAULT_NUM_THREADS/trange.volume; + dimBlock->x = GKYL_DEFAULT_NUM_THREADS / trange.volume; dimGrid->x = gkyl_int_div_up(size, dimBlock->x); } -__global__ static void -tensor_field_raise_or_lower_idx_set_cu_kernel(const struct gkyl_tensor_field *met, int raised_idx, - const struct gkyl_tensor_field *ten, struct gkyl_tensor_field *tensor_out) +__global__ static void tensor_field_raise_or_lower_idx_set_cu_kernel( + const struct gkyl_tensor_field *met, int raised_idx, const struct gkyl_tensor_field *ten, + struct gkyl_tensor_field *tensor_out +) { - // iterate over the components of the tensor - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; int iter_tf_out_idx[GKYL_MAX_DIM]; - gkyl_range_inv_idx(&tensor_out->trange, linc2, iter_tf_out_idx); + gkyl_range_inv_idx(&tensor_out->trange, linc2, iter_tf_out_idx); // iterate over the indices of the tensor - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < tensor_out->size; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < tensor_out->size; + tid += blockDim.x * gridDim.x) { const double *metric = gkyl_tensor_field_cfetch(met, tid); // loop over the output tensor indices - double ten_out_elem = 0; + double ten_out_elem = 0; int index_raised = iter_tf_out_idx[raised_idx]; - + // summed over index, j - for (int j=0; jndim; ++j) { - int idx_met[GKYL_MAX_DIM] = { index_raised, j }; - + for (int j = 0; j < ten->ndim; ++j) { + int idx_met[GKYL_MAX_DIM] = {index_raised, j}; + // Get the tensor element we are indexing from int idx_tf[GKYL_MAX_DIM]; - for (int k=0; ktrange, ten->size); // ?? There is no met/tensor_out->on_dev at present - tensor_field_raise_or_lower_idx_set_cu_kernel<<>>(met->on_dev, raised_idx, ten->on_dev, tensor_out->on_dev); + tensor_field_raise_or_lower_idx_set_cu_kernel<< > >( + met->on_dev, raised_idx, ten->on_dev, tensor_out->on_dev + ); } \ No newline at end of file diff --git a/core/zero/thread_pool.c b/core/zero/thread_pool.c index 0fb2e062a0..dc026a0f0c 100644 --- a/core/zero/thread_pool.c +++ b/core/zero/thread_pool.c @@ -8,8 +8,7 @@ struct jp_thread_pool { threadpool thpool; // thread-pool object }; -static void -thread_pool_free(const struct gkyl_ref_count *ref) +static void thread_pool_free(const struct gkyl_ref_count *ref) { struct gkyl_job_pool *base = container_of(ref, struct gkyl_job_pool, ref_count); struct jp_thread_pool *th = container_of(base, struct jp_thread_pool, jp); @@ -17,27 +16,24 @@ thread_pool_free(const struct gkyl_ref_count *ref) gkyl_free(th); } -static bool -thread_pool_add_work(const struct gkyl_job_pool *jp, jp_work_func func, void *ctx) +static bool thread_pool_add_work(const struct gkyl_job_pool *jp, jp_work_func func, void *ctx) { struct jp_thread_pool *th = container_of(jp, struct jp_thread_pool, jp); int status = thpool_add_work(th->thpool, func, ctx); return status == 0 ? true : false; } -static void -thread_pool_wait(const struct gkyl_job_pool *jp) +static void thread_pool_wait(const struct gkyl_job_pool *jp) { struct jp_thread_pool *th = container_of(jp, struct jp_thread_pool, jp); thpool_wait(th->thpool); } -struct gkyl_job_pool* -gkyl_thread_pool_new(int nthreads) +struct gkyl_job_pool *gkyl_thread_pool_new(int nthreads) { struct jp_thread_pool *th = gkyl_malloc(sizeof(struct jp_thread_pool)); // initialize the actual pool object - th->thpool = thpool_init(nthreads); + th->thpool = thpool_init(nthreads); th->jp.pool_size = nthreads; th->jp.add_work = thread_pool_add_work; @@ -45,6 +41,6 @@ gkyl_thread_pool_new(int nthreads) // set reference counter th->jp.ref_count = gkyl_ref_count_init(thread_pool_free); - + return &th->jp; } diff --git a/core/zero/util.c b/core/zero/util.c index 2bcc40cf02..9fe63a21f0 100644 --- a/core/zero/util.c +++ b/core/zero/util.c @@ -13,28 +13,28 @@ #include #include -int -gkyl_search_str_int_pair_by_str(const struct gkyl_str_int_pair pairs[], const char *str, int def) +int gkyl_search_str_int_pair_by_str(const struct gkyl_str_int_pair pairs[], const char *str, int def) { - for (int i=0; pairs[i].str != 0; ++i) { - if (strcmp(pairs[i].str, str) == 0) + for (int i = 0; pairs[i].str != 0; ++i) { + if (strcmp(pairs[i].str, str) == 0) { return pairs[i].val; + } } - return def; + return def; } const char * gkyl_search_str_int_pair_by_int(const struct gkyl_str_int_pair pairs[], int val, const char *def) { - for (int i=0; pairs[i].str != 0; ++i) { - if (pairs[i].val == val) + for (int i = 0; pairs[i].str != 0; ++i) { + if (pairs[i].val == val) { return pairs[i].str; + } } - return def; + return def; } -int -gkyl_tm_trigger_check_and_bump(struct gkyl_tm_trigger *tmt, double tcurr) +int gkyl_tm_trigger_check_and_bump(struct gkyl_tm_trigger *tmt, double tcurr) { int status = 0; if (tcurr >= tmt->tcurr) { @@ -45,44 +45,58 @@ gkyl_tm_trigger_check_and_bump(struct gkyl_tm_trigger *tmt, double tcurr) return status; } -void -gkyl_exit(const char* msg) +void gkyl_exit(const char *msg) { fprintf(stderr, "Error: %s\n", msg); exit(EXIT_FAILURE); } -int -gkyl_compare_float(float a, float b, float eps) +int gkyl_compare_float(float a, float b, float eps) { //if (isnanf(a) || isnanf(b)) return 0; - - float absa = fabs(a), absb = fabs(b), diff = fabs(a-b); - if (a == b) return 1; - if (a == 0 || b == 0 || (absa+absb < FLT_MIN)) return diff < eps; - if (absa < eps) return diff < eps; - if (absb < eps) return diff < eps; - return diff/fminf(absa+absb, FLT_MAX) < eps; + float absa = fabs(a), absb = fabs(b), diff = fabs(a - b); + + if (a == b) { + return 1; + } + if (a == 0 || b == 0 || (absa + absb < FLT_MIN)) { + return diff < eps; + } + if (absa < eps) { + return diff < eps; + } + if (absb < eps) { + return diff < eps; + } + return diff / fminf(absa + absb, FLT_MAX) < eps; } -int -gkyl_compare_double(double a, double b, double eps) +int gkyl_compare_double(double a, double b, double eps) { - if (isnan(a) || isnan(b)) return 0; - - double absa = fabs(a), absb = fabs(b), diff = fabs(a-b); - if (a == b) return 1; - if (a == 0 || b == 0 || (absa+absb < DBL_MIN)) return diff < eps; - if (absa < eps) return diff < eps; - if (absb < eps) return diff < eps; - return diff/fmin(absa+absb, DBL_MAX) < eps; + if (isnan(a) || isnan(b)) { + return 0; + } + + double absa = fabs(a), absb = fabs(b), diff = fabs(a - b); + if (a == b) { + return 1; + } + if (a == 0 || b == 0 || (absa + absb < DBL_MIN)) { + return diff < eps; + } + if (absa < eps) { + return diff < eps; + } + if (absb < eps) { + return diff < eps; + } + return diff / fmin(absa + absb, DBL_MAX) < eps; } -struct timespec -gkyl_wall_clock(void) +struct timespec gkyl_wall_clock(void) { - struct timespec tm = { 0 }; + struct timespec tm = {0}; #ifdef GKYL_HAVE_CUDA cudaDeviceSynchronize(); #endif @@ -91,127 +105,115 @@ gkyl_wall_clock(void) return tm; } -struct timespec -gkyl_time_diff(struct timespec start, struct timespec end) +struct timespec gkyl_time_diff(struct timespec start, struct timespec end) { struct timespec tm; - if ((end.tv_nsec-start.tv_nsec)<0) { - tm.tv_sec = end.tv_sec-start.tv_sec-1; - tm.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; - } - else { - tm.tv_sec = end.tv_sec-start.tv_sec; - tm.tv_nsec = end.tv_nsec-start.tv_nsec; + if ((end.tv_nsec - start.tv_nsec) < 0) { + tm.tv_sec = end.tv_sec - start.tv_sec - 1; + tm.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec; + } else { + tm.tv_sec = end.tv_sec - start.tv_sec; + tm.tv_nsec = end.tv_nsec - start.tv_nsec; } - return tm; + return tm; } -double -gkyl_time_diff_now_sec(struct timespec tm) +double gkyl_time_diff_now_sec(struct timespec tm) { return gkyl_time_sec(gkyl_time_diff(tm, gkyl_wall_clock())); } - -double -gkyl_time_sec(struct timespec tm) + +double gkyl_time_sec(struct timespec tm) { - return tm.tv_sec + 1e-9*tm.tv_nsec; + return tm.tv_sec + 1e-9 * tm.tv_nsec; } -double -gkyl_time_now(void) +double gkyl_time_now(void) { - return gkyl_time_sec( gkyl_wall_clock() ); + return gkyl_time_sec(gkyl_wall_clock()); } -pcg32_random_t -gkyl_pcg32_init(bool nd_seed) +pcg32_random_t gkyl_pcg32_init(bool nd_seed) { pcg32_random_t rng; int rounds = 5; - if (nd_seed) + if (nd_seed) { // seed with external entropy -- the time and some program addresses // (which will actually be somewhat random on most modern systems). - pcg32_srandom_r(&rng, time(NULL) ^ (intptr_t)&printf, - (intptr_t)&rounds); - else + pcg32_srandom_r(&rng, time(NULL) ^ (intptr_t)&printf, (intptr_t)&rounds); + } else { // seed with a fixed constant pcg32_srandom_r(&rng, 42u, 54u); + } return rng; } -uint32_t -gkyl_pcg32_rand_uint32(pcg32_random_t* rng) +uint32_t gkyl_pcg32_rand_uint32(pcg32_random_t *rng) { return pcg32_random_r(rng); } -double -gkyl_pcg32_rand_double(pcg32_random_t* rng) +double gkyl_pcg32_rand_double(pcg32_random_t *rng) { return ldexp(pcg32_random_r(rng), -32); } static void -pcg64_srandom_r(pcg64_random_t* rng, uint64_t seed1, uint64_t seed2, - uint64_t seq1, uint64_t seq2) +pcg64_srandom_r(pcg64_random_t *rng, uint64_t seed1, uint64_t seed2, uint64_t seq1, uint64_t seq2) { uint64_t mask = ~0ull >> 1; // stream for each generators *must* be distinct - if ((seq1 & mask) == (seq2 & mask)) + if ((seq1 & mask) == (seq2 & mask)) { seq2 = ~seq2; - pcg32_srandom_r(rng->gen, seed1, seq1); - pcg32_srandom_r(rng->gen+1, seed2, seq2); + } + pcg32_srandom_r(rng->gen, seed1, seq1); + pcg32_srandom_r(rng->gen + 1, seed2, seq2); } static int _dummy_global = 0; // just to provide address for use in seed -pcg64_random_t -gkyl_pcg64_init(bool nd_seed) +pcg64_random_t gkyl_pcg64_init(bool nd_seed) { pcg64_random_t rng; int rounds = 5; - if (nd_seed) - pcg64_srandom_r(&rng, - time(NULL) ^ (intptr_t)&printf, ~time(NULL) ^ (intptr_t)&pcg32_random_r, - (intptr_t)&rounds, (intptr_t)&_dummy_global); - else + if (nd_seed) { + pcg64_srandom_r( + &rng, time(NULL) ^ (intptr_t)&printf, ~time(NULL) ^ (intptr_t)&pcg32_random_r, + (intptr_t)&rounds, (intptr_t)&_dummy_global + ); + } else { pcg64_srandom_r(&rng, 42u, 42u, 54u, 54u); + } return rng; } -uint64_t -gkyl_pcg64_rand_uint64(pcg64_random_t* rng) +uint64_t gkyl_pcg64_rand_uint64(pcg64_random_t *rng) { - return ((uint64_t)(pcg32_random_r(rng->gen)) << 32) | pcg32_random_r(rng->gen+1); + return ((uint64_t)(pcg32_random_r(rng->gen)) << 32) | pcg32_random_r(rng->gen + 1); } -double -gkyl_pcg64_rand_double(pcg64_random_t* rng) +double gkyl_pcg64_rand_double(pcg64_random_t *rng) { return ldexp(gkyl_pcg64_rand_uint64(rng), -64); } -bool -gkyl_check_file_exists(const char *fname) +bool gkyl_check_file_exists(const char *fname) { return access(fname, F_OK) == 0; } -int64_t -gkyl_file_size(const char *fname) +int64_t gkyl_file_size(const char *fname) { struct stat st; stat(fname, &st); return st.st_size; } -char* -gkyl_load_file(const char *fname, int64_t *sz) +char *gkyl_load_file(const char *fname, int64_t *sz) { int64_t msz = gkyl_file_size(fname); char *buff = gkyl_malloc(msz); @@ -222,12 +224,12 @@ gkyl_load_file(const char *fname, int64_t *sz) return buff; } -bool -gkyl_msgpack_map_elem_has_key(int nvals, const struct gkyl_msgpack_map_elem *elist, - const char *key) +bool gkyl_msgpack_map_elem_has_key( + int nvals, const struct gkyl_msgpack_map_elem *elist, const char *key +) { bool has_key = false; - for (int i=0; i 0); elist_out_len[0] = nvals_tot; - struct gkyl_msgpack_map_elem *elist_out = gkyl_malloc(elist_out_len[0]*sizeof(struct gkyl_msgpack_map_elem)); + struct gkyl_msgpack_map_elem *elist_out = + gkyl_malloc(elist_out_len[0] * sizeof(struct gkyl_msgpack_map_elem)); int eidx = 0; - for (int j=0; jmeta_sz = 0; @@ -456,38 +457,38 @@ gkyl_msgpack_create(int nvals, const struct gkyl_msgpack_map_elem *elist) mpack_writer_t writer; mpack_writer_init_growable(&writer, &mdata->meta, &mdata->meta_sz); - mpack_build_map(&writer); - for (int i=0; imeta_sz = 0; @@ -514,44 +516,43 @@ gkyl_msgpack_create_union(int numlist_union, int *nvals_union, const struct gkyl mpack_writer_t writer; mpack_writer_init_growable(&writer, &mdata->meta, &mdata->meta_sz); - mpack_build_map(&writer); - - for (int j=0; j 0) { - uint32_t chunk = remaining > sizeof(buffer)? sizeof(buffer) : remaining; - mpack_read_bytes(r, buffer, chunk); - mpack_write_bytes(w, buffer, chunk); - remaining -= chunk; - } - - mpack_done_str(r); - mpack_finish_str(w); - break; + case mpack_type_nil: + mpack_write_nil(w); + break; + case mpack_type_bool: + mpack_write_bool(w, mpack_tag_bool_value(&tag)); + break; + case mpack_type_int: + mpack_write_int(w, mpack_tag_int_value(&tag)); + break; + case mpack_type_uint: + mpack_write_uint(w, mpack_tag_uint_value(&tag)); + break; + case mpack_type_float: + mpack_write_float(w, mpack_tag_float_value(&tag)); + break; + case mpack_type_double: + mpack_write_double(w, mpack_tag_double_value(&tag)); + break; + case mpack_type_str: { + uint32_t len = mpack_tag_str_length(&tag); + mpack_start_str(w, len); + + char buffer[64]; + uint32_t remaining = len; + while (remaining > 0) { + uint32_t chunk = remaining > sizeof(buffer) ? sizeof(buffer) : remaining; + mpack_read_bytes(r, buffer, chunk); + mpack_write_bytes(w, buffer, chunk); + remaining -= chunk; } - case mpack_type_map: { - uint32_t count = mpack_tag_map_count(&tag); - mpack_start_map(w, count); - for (uint32_t i=0; imeta_sz = 0; @@ -655,10 +654,11 @@ gkyl_msgpack_clone(struct gkyl_msgpack_data *mdata_in) msgpack_copy_value(&reader, &writer); // Check copy was successful. - if ( - (mpack_reader_destroy(&reader) != mpack_ok || mpack_writer_destroy(&writer) != mpack_ok) || - (!(mdata_in->meta_sz == mdata_out->meta_sz && memcmp(mdata_in->meta, mdata_out->meta, mdata_in->meta_sz) == 0)) - ) { + if ((mpack_reader_destroy(&reader) != mpack_ok || mpack_writer_destroy(&writer) != mpack_ok) || + (!( + mdata_in->meta_sz == mdata_out->meta_sz && + memcmp(mdata_in->meta, mdata_out->meta, mdata_in->meta_sz) == 0 + ))) { fprintf(stderr, "gkyl_msgpack_clone: error copying MessagePack.\n"); MPACK_FREE(mdata_out->meta); // we need to use free here as mpack does its own malloc gkyl_free(mdata_out); @@ -668,58 +668,59 @@ gkyl_msgpack_clone(struct gkyl_msgpack_data *mdata_in) return mdata_out; } -void -gkyl_msgpack_to_map_elem_list(struct gkyl_msgpack_data* mpack_in, int nvals, - struct gkyl_msgpack_map_elem *elist) +void gkyl_msgpack_to_map_elem_list( + struct gkyl_msgpack_data *mpack_in, int nvals, struct gkyl_msgpack_map_elem *elist +) { mpack_tree_t tree; mpack_tree_init_data(&tree, mpack_in->meta, mpack_in->meta_sz); mpack_tree_parse(&tree); mpack_node_t root = mpack_tree_root(&tree); - for (int i=0; imeta_sz > 0) + if (!mdata) { + return; + } + if (mdata->meta_sz > 0) { MPACK_FREE(mdata->meta); + } gkyl_free(mdata); } - diff --git a/gkeyll/gkeyll.c b/gkeyll/gkeyll.c index 9f6d829207..517fce55f4 100644 --- a/gkeyll/gkeyll.c +++ b/gkeyll/gkeyll.c @@ -29,7 +29,6 @@ #include #include - #include #include @@ -53,10 +52,8 @@ #include #endif -#define STRINGIFY_(x) #x -#define STRINGIFY(x) STRINGIFY_(x) - - +#define STRINGIFY_(x) #x +#define STRINGIFY(x) STRINGIFY_(x) // Tool description struct struct tool_description { @@ -73,72 +70,72 @@ static struct tool_description tool_list[] = { {"exacteulerrp", "exacteulerrp.lua", "Exact Euler Riemann problem solver"}, {"runregression", "runregression.lua", "Run regression/unit tests"}, {"multimomlinear", "multimomlinear.lua", - "Linear dispersion solver for multi-moment, multifluid equations"}, + "Linear dispersion solver for multi-moment, multifluid equations"}, {"eqdskreader", "eqdskreader.lua", "Read eqdsk file, writing data to files"}, {0, 0} }; -static int max2(int a, int b) { return a>b ? a : b; } +static int max2(int a, int b) +{ + return a > b ? a : b; +} // Show list of available Tools -static void -show_tool_list(void) +static void show_tool_list(void) { fprintf(stdout, "Following tools are available. Query tool help for more information.\n\n"); int mlen = 0; - for (int i=0; tool_list[i].tool_name != 0; ++i) { + for (int i = 0; tool_list[i].tool_name != 0; ++i) { int len = strlen(tool_list[i].tool_name); mlen = len > mlen ? len : mlen; } - - for (int i=0; tool_list[i].tool_name != 0; ++i) - fprintf(stdout, "%*s %s\n", mlen+2, tool_list[i].tool_name, tool_list[i].tool_help); + + for (int i = 0; tool_list[i].tool_name != 0; ++i) { + fprintf(stdout, "%*s %s\n", mlen + 2, tool_list[i].tool_name, tool_list[i].tool_help); + } fprintf(stdout, "\n"); } // Returns tool Lua script name given tool name. Returns 0 if Tool // does no exist -static const char * -get_tool_from_name(const char *nm) +static const char *get_tool_from_name(const char *nm) { - for (int i=0; tool_list[i].tool_name != 0; ++i) - if (strcmp(tool_list[i].tool_name, nm) == 0) + for (int i = 0; tool_list[i].tool_name != 0; ++i) { + if (strcmp(tool_list[i].tool_name, nm) == 0) { return tool_list[i].tool_lua; + } + } return 0; } -static char * -find_exec_path(void) +static char *find_exec_path(void) { int len = wai_getExecutablePath(NULL, 0, NULL); - char *path = gkyl_malloc(len+1); - int dirname_len; wai_getExecutablePath(path, len, &dirname_len); + char *path = gkyl_malloc(len + 1); + int dirname_len; + wai_getExecutablePath(path, len, &dirname_len); path[dirname_len] = '\0'; // only directory path is returned return path; } -static int -calc_output_prefix_len(const char *fn) +static int calc_output_prefix_len(const char *fn) { const char *suff = strrchr(fn, '.'); return strlen(fn) - (suff ? strlen(suff) : 0); } -static const char* -get_fname(const char *fn) +static const char *get_fname(const char *fn) { return strrchr(fn, '/'); } -static const char* -get_fname_with_dir(const char *fn) +static const char *get_fname_with_dir(const char *fn) { return fn; } -static void -show_banner(FILE *fp) +static void show_banner(FILE *fp) { if (fp) { fprintf(fp, "Gkeyll built with Git changeset %s\n", STRINGIFY(GKYL_GIT_CHANGESET)); @@ -176,15 +173,15 @@ show_banner(FILE *fp) fprintf(fp, "PKPM App enabled\n"); num_apps += 1; #endif - if (0 == num_apps) + if (0 == num_apps) { fprintf(fp, "Built without any Apps! Core library only.\n"); + } fprintf(fp, "\n"); } } // show usage -static void -show_usage() +static void show_usage() { fprintf(stdout, "This is the Gkeyll code. See gkeyll.rtfd.io for details.\n"); fprintf(stdout, "Type 'gkeyll man' for help.\n\n"); @@ -196,7 +193,7 @@ show_usage() fprintf(stdout, " -e chunk Execute string 'chunk'\n"); fprintf(stdout, " -t Show list of registered tools\n"); fprintf(stdout, " -v Show version information\n"); - fprintf(stdout, " -d Write output to same directory as input file\n"); + fprintf(stdout, " -d Write output to same directory as input file\n"); fprintf(stdout, " -g Run on NVIDIA GPU (if available and built with CUDA)\n\n"); fprintf(stdout, " -m Run memory tracer\n"); fprintf(stdout, " -S Do not initialize MPI\n"); @@ -207,15 +204,16 @@ show_usage() fprintf(stdout, " restart Restart simulation \n"); fprintf(stdout, "To get help for commands type command name followed by -h\n\n"); - fprintf(stdout, "Individual tools may take other options and commands. See their specific help.\n"); + fprintf( + stdout, "Individual tools may take other options and commands. See their specific help.\n" + ); } -static void -show_version() +static void show_version() { fprintf(stdout, "This is the Gkeyll code. See gkeyll.rtfd.io for details.\n"); fprintf(stdout, "Type 'gkyl -h' for help.\n\n"); -#ifdef GKYL_GIT_CHANGESET +#ifdef GKYL_GIT_CHANGESET fprintf(stdout, "Built with git changeset %s\n", STRINGIFY(GKYL_GIT_CHANGESET)); #endif #ifdef GKYL_BUILD_DATE @@ -241,43 +239,43 @@ struct app_args { int restart_frame; // Which frame to restart simulation from. bool use_dir_path; /// should we use full directory path - + char *echunk; // chunk of lua code to execute - + int num_opt_args; // number of optional arguments char **opt_args; // optional arguments char *exec_path; // location of executable }; -static void -release_opt_args(struct app_args *args) +static void release_opt_args(struct app_args *args) { - for (int i=0; inum_opt_args; ++i) + for (int i = 0; i < args->num_opt_args; ++i) { gkyl_free(args->opt_args[i]); + } gkyl_free(args->opt_args); - - if (args->echunk) + + if (args->echunk) { gkyl_free(args->echunk); + } gkyl_free(args->exec_path); gkyl_free(args); } -static struct app_args* -parse_app_args(int argc, char **argv) +static struct app_args *parse_app_args(int argc, char **argv) { struct app_args *args = gkyl_malloc(sizeof(*args)); args->use_gpu = false; args->step_mode = false; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI args->use_mpi = true; #else args->use_mpi = false; #endif - + args->trace_mem = false; args->num_opt_args = 0; args->echunk = 0; @@ -291,85 +289,84 @@ parse_app_args(int argc, char **argv) int c; while ((c = getopt(argc, argv, "+hvtmdSe:gV")) != -1) { - switch (c) - { - case 'h': - show_usage(); - exit(-1); - break; - - case 'v': - show_version(); - exit(-1); - break; - - case 't': - show_tool_list(); - exit(1); - break; - - case 'e': - args->echunk = gkyl_malloc(strlen(optarg)+1); - strcpy(args->echunk, optarg); - break; - - case 'g': - args->use_gpu = true; - break; - - case 'd': - args->use_dir_path = true; - break; - - case 'S': - args->use_mpi = false; - break; - - case 'm': - args->trace_mem = true; - break; - - case 'V': - args->use_verbose = true; - break; - - case '?': - break; + switch (c) { + case 'h': + show_usage(); + exit(-1); + break; + + case 'v': + show_version(); + exit(-1); + break; + + case 't': + show_tool_list(); + exit(1); + break; + + case 'e': + args->echunk = gkyl_malloc(strlen(optarg) + 1); + strcpy(args->echunk, optarg); + break; + + case 'g': + args->use_gpu = true; + break; + + case 'd': + args->use_dir_path = true; + break; + + case 'S': + args->use_mpi = false; + break; + + case 'm': + args->trace_mem = true; + break; + + case 'V': + args->use_verbose = true; + break; + + case '?': + break; } } args->num_opt_args = 0; // collect remaining options into a list - for (int oind=optind; oind < argc; ++oind) args->num_opt_args += 1; - args->opt_args = gkyl_malloc(sizeof(char*)*args->num_opt_args); + for (int oind = optind; oind < argc; ++oind) { + args->num_opt_args += 1; + } + args->opt_args = gkyl_malloc(sizeof(char *) * args->num_opt_args); - for (int i=0, oind=optind; oind < argc; ++oind, ++i) { - args->opt_args[i] = gkyl_malloc(strlen(argv[oind])+1); + for (int i = 0, oind = optind; oind < argc; ++oind, ++i) { + args->opt_args[i] = gkyl_malloc(strlen(argv[oind]) + 1); strcpy(args->opt_args[i], argv[oind]); } args->exec_path = find_exec_path(); - + return args; } - - -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct app_args *app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args->use_mpi) + if (app_args->use_mpi) { MPI_Init(&argc, &argv); + } #endif if (app_args->trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } - + lua_State *L = luaL_newstate(); lua_gc(L, LUA_GCSTOP, 0); luaL_openlibs(L); @@ -377,26 +374,26 @@ main(int argc, char **argv) // G0 librararies gkyl_zero_lw_openlibs(L); -#ifdef GKYL_HAVE_MOMENTS +#ifdef GKYL_HAVE_MOMENTS gkyl_moment_lw_openlibs(L); #endif #ifdef GKYL_HAVE_VLASOV gkyl_vlasov_lw_openlibs(L); #endif -#ifdef GKYL_HAVE_GYROKINETIC +#ifdef GKYL_HAVE_GYROKINETIC gkyl_gyrokinetic_lw_openlibs(L); #endif -#ifdef GKYL_HAVE_PKPM +#ifdef GKYL_HAVE_PKPM gkyl_pkpm_lw_openlibs(L); -#endif +#endif lua_gc(L, LUA_GCRESTART, -1); #ifdef GKYL_HAVE_MPI struct { MPI_Comm comm; - } lw_mpi_comm_world = { .comm = MPI_COMM_WORLD }; + } lw_mpi_comm_world = {.comm = MPI_COMM_WORLD}; #endif - + if (app_args->use_mpi) { lua_pushboolean(L, true); lua_setglobal(L, "GKYL_HAVE_MPI"); @@ -407,11 +404,10 @@ main(int argc, char **argv) lua_pushlightuserdata(L, false); #endif lua_setglobal(L, "GKYL_MPI_COMM"); - } - else { + } else { lua_pushboolean(L, false); lua_setglobal(L, "GKYL_HAVE_MPI"); - + lua_pushboolean(L, false); lua_setglobal(L, "GKYL_MPI_COMM"); } @@ -429,13 +425,12 @@ main(int argc, char **argv) lua_setglobal(L, "GKYL_HAVE_CUDA"); lua_pushboolean(L, false); - lua_setglobal(L, "GKYL_USE_GPU"); + lua_setglobal(L, "GKYL_USE_GPU"); #endif if (app_args->use_verbose) { lua_pushboolean(L, true); - } - else { + } else { lua_pushboolean(L, false); } lua_setglobal(L, "GKYL_USE_VERBOSE"); @@ -445,8 +440,7 @@ main(int argc, char **argv) if (app_args->is_restart) { lua_pushboolean(L, true); - } - else { + } else { lua_pushboolean(L, false); } lua_setglobal(L, "GKYL_IS_RESTART"); @@ -481,47 +475,47 @@ main(int argc, char **argv) lua_pushnumber(L, DBL_EPSILON); lua_setglobal(L, "GKYL_EPSILON"); - + lua_pushinteger(L, INT16_MAX); lua_setglobal(L, "GKYL_MAX_INT16"); lua_pushstring(L, app_args->exec_path); lua_setglobal(L, "GKYL_EXEC_PATH"); - + do { const char *fmt = "%s/gkyl"; size_t len = gkyl_calc_strlen(fmt, app_args->exec_path); - char *str = gkyl_malloc(len+1); - snprintf(str, len+1, fmt, app_args->exec_path); + char *str = gkyl_malloc(len + 1); + snprintf(str, len + 1, fmt, app_args->exec_path); lua_pushstring(L, str); lua_setglobal(L, "GKYL_EXEC"); gkyl_free(str); - } while (0); + } while (0); #ifdef GKYL_GIT_CHANGESET lua_pushstring(L, STRINGIFY(GKYL_GIT_CHANGESET)); lua_setglobal(L, "GKYL_GIT_CHANGESET"); -#endif +#endif #ifdef GKYL_BUILD_DATE lua_pushstring(L, STRINGIFY(GKYL_BUILD_DATE)); lua_setglobal(L, "GKYL_BUILD_DATE"); -#endif +#endif // push extra arguments into a Lua table to Tools and App can get // them lua_newtable(L); - if (app_args->num_opt_args > 0) { + if (app_args->num_opt_args > 0) { lua_pushinteger(L, 1); lua_pushstring(L, app_args->opt_args[0]); - lua_rawset(L, -3); + lua_rawset(L, -3); } - - for (int i=1; inum_opt_args; ++i) { - lua_pushinteger(L, i+1); + + for (int i = 1; i < app_args->num_opt_args; ++i) { + lua_pushinteger(L, i + 1); lua_pushstring(L, app_args->opt_args[i]); lua_rawset(L, -3); } @@ -531,8 +525,8 @@ main(int argc, char **argv) // needed for various tools CLI parsers. For some reason they do not // allow the script name in the args lua_newtable(L); - - for (int i=1; inum_opt_args; ++i) { + + for (int i = 1; i < app_args->num_opt_args; ++i) { lua_pushinteger(L, i); lua_pushstring(L, app_args->opt_args[i]); lua_rawset(L, -3); @@ -541,32 +535,35 @@ main(int argc, char **argv) // set package paths so we find installed libraries do { - const char *fmt = "package.path = package.path .. \";%s/lua/?.lua;%s/lua/Lib/?.lua;%s/lua/?/init.lua\""; - size_t len = gkyl_calc_strlen(fmt, app_args->exec_path, app_args->exec_path, app_args->exec_path); + const char *fmt = + "package.path = package.path .. \";%s/lua/?.lua;%s/lua/Lib/?.lua;%s/lua/?/init.lua\""; + size_t len = + gkyl_calc_strlen(fmt, app_args->exec_path, app_args->exec_path, app_args->exec_path); - char *str = gkyl_malloc(len+1); - snprintf(str, len+1, fmt, app_args->exec_path, app_args->exec_path, app_args->exec_path); + char *str = gkyl_malloc(len + 1); + snprintf(str, len + 1, fmt, app_args->exec_path, app_args->exec_path, app_args->exec_path); glua_run_lua(L, str, strlen(str), 0); - + gkyl_free(str); } while (0); // run Lua code (if it exists) before running input file - if (app_args->echunk) + if (app_args->echunk) { glua_run_lua(L, app_args->echunk, strlen(app_args->echunk), 0); + } int rank = 0; #ifdef GKYL_HAVE_MPI - if (app_args->use_mpi) + if (app_args->use_mpi) { MPI_Comm_rank(MPI_COMM_WORLD, &rank); + } #endif - + if (app_args->num_opt_args > 0) { bool something_run = false; const char *inp_name = app_args->opt_args[0]; if (gkyl_check_file_exists(inp_name)) { - show_banner(rank == 0 ? stdout : 0); const char *suff = 0, suff1 = 0; @@ -575,60 +572,58 @@ main(int argc, char **argv) const char *suff1 = suff; lua_pushlstring(L, suff1, calc_output_prefix_len(suff1)); lua_setglobal(L, "GKYL_OUT_PREFIX"); - - } - else { + + } else { const char *suff = get_fname(inp_name); - const char *suff1 = suff ? suff+1 : inp_name; + const char *suff1 = suff ? suff + 1 : inp_name; lua_pushlstring(L, suff1, calc_output_prefix_len(suff1)); lua_setglobal(L, "GKYL_OUT_PREFIX"); } - + int64_t sz = 0; char *buff = gkyl_load_file(inp_name, &sz); glua_run_lua(L, buff, sz, stderr); gkyl_free(buff); something_run = true; - } - else { + } else { // check if it is a Tool, and run it if so const char *tlua = get_tool_from_name(app_args->opt_args[0]); if (tlua) { const char *fmt = "%s/lua/Tool/%s"; size_t len = gkyl_calc_strlen(fmt, app_args->exec_path, tlua); - char *tool_name = gkyl_malloc(len+1); - snprintf(tool_name, len+1, fmt, app_args->exec_path, tlua); - + char *tool_name = gkyl_malloc(len + 1); + snprintf(tool_name, len + 1, fmt, app_args->exec_path, tlua); + int64_t sz = 0; char *buff = gkyl_load_file(tool_name, &sz); glua_run_lua(L, buff, sz, stderr); gkyl_free(buff); - + gkyl_free(tool_name); something_run = true; } } - if (!something_run) + if (!something_run) { fprintf(stderr, "No Lua code was run!\n"); + } } - - lua_close(L); + + lua_close(L); #ifdef GKYL_HAVE_MPI - if (app_args->use_mpi) + if (app_args->use_mpi) { MPI_Finalize(); + } #endif release_opt_args(app_args); - } #else #include -int -main(int argc, char **argv) +int main(int argc, char **argv) { fprintf(stderr, "Gkeyll built without Lua support!\n"); return 0; diff --git a/gkeyll/lua/Comm/gkyl_mpi_funcs.c b/gkeyll/lua/Comm/gkyl_mpi_funcs.c index 4c495edfd9..089461f49f 100644 --- a/gkeyll/lua/Comm/gkyl_mpi_funcs.c +++ b/gkeyll/lua/Comm/gkyl_mpi_funcs.c @@ -78,42 +78,52 @@ GET_INT_OBJECT_PTR(MPI_UNWEIGHTED); GET_VOID_OBJECT_PTR(MPI_BOTTOM); // Functions to allocate and free structs holding requests and statuses. -void gkyl_MPI_Request_alloc(gkyl_MPI_Request *rs, int num) { - rs->req = (MPI_Request *) malloc(num*sizeof(MPI_Request)); +void gkyl_MPI_Request_alloc(gkyl_MPI_Request *rs, int num) +{ + rs->req = (MPI_Request *)malloc(num * sizeof(MPI_Request)); } -void gkyl_MPI_Request_release(gkyl_MPI_Request *rs) { +void gkyl_MPI_Request_release(gkyl_MPI_Request *rs) +{ free(rs->req); } -void gkyl_MPI_Status_alloc(gkyl_MPI_Status *ss, int num) { - ss->stat = (MPI_Status *) malloc(num*sizeof(MPI_Status)); +void gkyl_MPI_Status_alloc(gkyl_MPI_Status *ss, int num) +{ + ss->stat = (MPI_Status *)malloc(num * sizeof(MPI_Status)); } -void gkyl_MPI_Status_release(gkyl_MPI_Status *ss) { +void gkyl_MPI_Status_release(gkyl_MPI_Status *ss) +{ free(ss->stat); } -void gkyl_MPI_Request_Status_alloc(gkyl_MPI_Request_Status *rss, int num) { - rss->req = (MPI_Request *) malloc(num*sizeof(MPI_Request)); - rss->stat = (MPI_Status *) malloc(num*sizeof(MPI_Status)); +void gkyl_MPI_Request_Status_alloc(gkyl_MPI_Request_Status *rss, int num) +{ + rss->req = (MPI_Request *)malloc(num * sizeof(MPI_Request)); + rss->stat = (MPI_Status *)malloc(num * sizeof(MPI_Status)); } -void gkyl_MPI_Request_Status_release(gkyl_MPI_Request_Status *rss) { +void gkyl_MPI_Request_Status_release(gkyl_MPI_Request_Status *rss) +{ free(rss->req); free(rss->stat); } // Functions to fetch members of status. -int gkyl_mpi_get_status_SOURCE(const MPI_Status* instat, int off) { +int gkyl_mpi_get_status_SOURCE(const MPI_Status *instat, int off) +{ return instat[off].MPI_SOURCE; } -int gkyl_mpi_get_status_TAG(const MPI_Status* instat, int off) { +int gkyl_mpi_get_status_TAG(const MPI_Status *instat, int off) +{ return instat[off].MPI_TAG; } -int gkyl_mpi_get_status_ERROR(const MPI_Status* instat, int off) { +int gkyl_mpi_get_status_ERROR(const MPI_Status *instat, int off) +{ return instat[off].MPI_ERROR; } // Get count from a status (which may be one of several in an array of // statuses). -int gkyl_mpi_get_status_count(const MPI_Status *instat, MPI_Datatype datatype, int *count, int off) { - int err = MPI_Get_count(instat+off, datatype, count); +int gkyl_mpi_get_status_count(const MPI_Status *instat, MPI_Datatype datatype, int *count, int off) +{ + int err = MPI_Get_count(instat + off, datatype, count); return err; } diff --git a/gkeyll/lua/Comm/gkyl_mpi_funcs.h b/gkeyll/lua/Comm/gkyl_mpi_funcs.h index c754d6999a..39634556aa 100644 --- a/gkeyll/lua/Comm/gkyl_mpi_funcs.h +++ b/gkeyll/lua/Comm/gkyl_mpi_funcs.h @@ -15,13 +15,13 @@ DECL_GET_MPI_OBJ_SIZE(MPI_Aint); DECL_GET_MPI_OBJ_SIZE(MPI_Request); DECL_GET_MPI_OBJ_PTR_SIZE(MPI_Status); DECL_GET_MPI_OBJ_PTR_SIZE(MPI_Request); - + // Pre-defined objects and constants DECL_GET_MPI_OBJECT(Comm, MPI_COMM_WORLD); DECL_GET_MPI_OBJECT(Comm, MPI_COMM_NULL); DECL_GET_MPI_OBJECT(Comm, MPI_COMM_SELF); DECL_GET_MPI_OBJECT(Info, MPI_INFO_NULL); - + DECL_GET_MPI_OBJECT(Request, MPI_REQUEST_NULL); DECL_GET_MPI_OBJECT_PTR(Status, MPI_STATUS_IGNORE); DECL_INT_OBJECT(MPI_PROC_NULL); @@ -99,9 +99,9 @@ void gkyl_MPI_Request_Status_alloc(gkyl_MPI_Request_Status *rss, int num); void gkyl_MPI_Request_Status_release(gkyl_MPI_Request_Status *rss); // Functions to fetch members of status. -int gkyl_mpi_get_status_SOURCE(const MPI_Status* instat, int off); -int gkyl_mpi_get_status_TAG(const MPI_Status* instat, int off); -int gkyl_mpi_get_status_ERROR(const MPI_Status* instat, int off); +int gkyl_mpi_get_status_SOURCE(const MPI_Status *instat, int off); +int gkyl_mpi_get_status_TAG(const MPI_Status *instat, int off); +int gkyl_mpi_get_status_ERROR(const MPI_Status *instat, int off); // Get count from a status (which may be one of several in an array of // statuses). diff --git a/gkeyll/lua/Comm/gkyl_mpi_macros.h b/gkeyll/lua/Comm/gkyl_mpi_macros.h index 470ea4518d..f7c43aeeb4 100644 --- a/gkeyll/lua/Comm/gkyl_mpi_macros.h +++ b/gkeyll/lua/Comm/gkyl_mpi_macros.h @@ -8,23 +8,51 @@ #pragma once // Macros to declare/define functions to get MPI objects -#define GET_MPI_OBJECT(type, value) MPI_##type get_##value() { return value; } +#define GET_MPI_OBJECT(type, value) \ + MPI_##type get_##value() \ + { \ + return value; \ + } #define DECL_GET_MPI_OBJECT(type, value) MPI_##type get_##value() #define LUA_SET_MPI_OBJECT(type, value) _M.value = ffi.C.get_##value(); -#define GET_INT_OBJECT(value) int get_##value() { return value; } +#define GET_INT_OBJECT(value) \ + int get_##value() \ + { \ + return value; \ + } #define DECL_INT_OBJECT(value) int get_##value() -#define GET_INT_OBJECT_PTR(value) int *get_##value() { return value; } +#define GET_INT_OBJECT_PTR(value) \ + int *get_##value() \ + { \ + return value; \ + } #define DECL_INT_OBJECT_PTR(value) int *get_##value() #define DECL_VOID_OBJECT_PTR(value) void *get_##value() -#define GET_VOID_OBJECT_PTR(value) void *get_##value() { return value; } +#define GET_VOID_OBJECT_PTR(value) \ + void *get_##value() \ + { \ + return value; \ + } // Macros to declare/define functions to get MPI object pointers -#define GET_MPI_OBJECT_PTR(type, value) MPI_##type *getPtr_##value() { return value; } +#define GET_MPI_OBJECT_PTR(type, value) \ + MPI_##type *getPtr_##value() \ + { \ + return value; \ + } #define DECL_GET_MPI_OBJECT_PTR(type, value) MPI_##type *getPtr_##value() // Macros to declare/define functions to get sizes of various MPI objects -#define GET_MPI_OBJ_SIZE(type) int sizeof_##type() { return sizeof(type); } -#define GET_MPI_OBJ_PTR_SIZE(type) int sizeof_ptr_##type() { return sizeof(type *); } +#define GET_MPI_OBJ_SIZE(type) \ + int sizeof_##type() \ + { \ + return sizeof(type); \ + } +#define GET_MPI_OBJ_PTR_SIZE(type) \ + int sizeof_ptr_##type() \ + { \ + return sizeof(type *); \ + } #define DECL_GET_MPI_OBJ_SIZE(type) int sizeof_##type() #define DECL_GET_MPI_OBJ_PTR_SIZE(type) int sizeof_ptr_##type() diff --git a/gkeyll/lua/Tool/exact_euler_rp.c b/gkeyll/lua/Tool/exact_euler_rp.c index 7d3056e0bc..0ec9335211 100644 --- a/gkeyll/lua/Tool/exact_euler_rp.c +++ b/gkeyll/lua/Tool/exact_euler_rp.c @@ -21,23 +21,22 @@ struct ProblemState { /** Lower and upper bounds */ double lower, upper; /** Domain length, time at which solution is needed */ - double domlen, tEnd; + double domlen, tEnd; /** Ratio of specific heat */ double gas_gamma; /** Location of discontinuity */ double disLoc; int ncell; // number of cells - /** Solution arrays */ + /** Solution arrays */ struct gkyl_array *density, *velocity, *pressure, *internalEnergy; }; -static struct ProblemState* -new_ProblemState(int ncell) +static struct ProblemState *new_ProblemState(int ncell) { struct ProblemState *ps = gkyl_malloc(sizeof(*ps)); ps->ncell = ncell; - + ps->density = gkyl_array_new(GKYL_DOUBLE, 1, ncell); ps->velocity = gkyl_array_new(GKYL_DOUBLE, 1, ncell); ps->pressure = gkyl_array_new(GKYL_DOUBLE, 1, ncell); @@ -46,8 +45,7 @@ new_ProblemState(int ncell) return ps; } -static void -release_ProblemState(struct ProblemState *ps) +static void release_ProblemState(struct ProblemState *ps) { gkyl_array_release(ps->density); gkyl_array_release(ps->velocity); @@ -57,24 +55,23 @@ release_ProblemState(struct ProblemState *ps) gkyl_free(ps); } -static void -prefun(const struct ProblemState *ps, double *F, double *FD, - double P, double DK, double PK, double CK) +static void prefun( + const struct ProblemState *ps, double *F, double *FD, double P, double DK, double PK, double CK +) { - double PRATIO, QRT, AK, BK; double gas_gamma = ps->gas_gamma; double GAMMA, G1, G2, G3, G4, G5, G6, G7, G8; GAMMA = gas_gamma; - G1 = (gas_gamma - 1)/(2*gas_gamma); - G2 = (gas_gamma + 1)/(2*gas_gamma); - G3 = 2*gas_gamma/(gas_gamma - 1); - G4 = 2/(gas_gamma - 1); - G5 = 2/(gas_gamma + 1); - G6 = (gas_gamma - 1)/(gas_gamma + 1); - G7 = (gas_gamma - 1)/2; + G1 = (gas_gamma - 1) / (2 * gas_gamma); + G2 = (gas_gamma + 1) / (2 * gas_gamma); + G3 = 2 * gas_gamma / (gas_gamma - 1); + G4 = 2 / (gas_gamma - 1); + G5 = 2 / (gas_gamma + 1); + G6 = (gas_gamma - 1) / (gas_gamma + 1); + G7 = (gas_gamma - 1) / 2; G8 = gas_gamma - 1; -// left, right states + // left, right states double DL, UL, PL, CL, DR, UR, PR, CR; DL = ps->dl; UL = ps->ul; @@ -85,19 +82,18 @@ prefun(const struct ProblemState *ps, double *F, double *FD, PR = ps->pr; CR = ps->cr; - if (P<=PK) { -// rarefaction wave - PRATIO = P/PK; - *F = G4*CK*(pow(PRATIO,G1) - 1.0); - *FD = (1.0/(DK*CK))*pow(PRATIO,-G2); - } - else { -// shock wave - AK = G5/DK; - BK = G6*PK; - QRT = sqrt(AK/(BK + P)); - *F = (P - PK)*QRT; - *FD = (1.0 - 0.5*(P - PK)/(BK + P))*QRT; + if (P <= PK) { + // rarefaction wave + PRATIO = P / PK; + *F = G4 * CK * (pow(PRATIO, G1) - 1.0); + *FD = (1.0 / (DK * CK)) * pow(PRATIO, -G2); + } else { + // shock wave + AK = G5 / DK; + BK = G6 * PK; + QRT = sqrt(AK / (BK + P)); + *F = (P - PK) * QRT; + *FD = (1.0 - 0.5 * (P - PK) / (BK + P)) * QRT; } } @@ -105,21 +101,20 @@ prefun(const struct ProblemState *ps, double *F, double *FD, * @param ps Problem state * @return Guess for pressure in star region */ -static -double guessp(struct ProblemState *ps) +static double guessp(struct ProblemState *ps) { double GAMMA, G1, G2, G3, G4, G5, G6, G7, G8; double gas_gamma = ps->gas_gamma; GAMMA = gas_gamma; - G1 = (gas_gamma - 1)/(2*gas_gamma); - G2 = (gas_gamma + 1)/(2*gas_gamma); - G3 = 2*gas_gamma/(gas_gamma - 1); - G4 = 2/(gas_gamma - 1); - G5 = 2/(gas_gamma + 1); - G6 = (gas_gamma - 1)/(gas_gamma + 1); - G7 = (gas_gamma - 1)/2; + G1 = (gas_gamma - 1) / (2 * gas_gamma); + G2 = (gas_gamma + 1) / (2 * gas_gamma); + G3 = 2 * gas_gamma / (gas_gamma - 1); + G4 = 2 / (gas_gamma - 1); + G5 = 2 / (gas_gamma + 1); + G6 = (gas_gamma - 1) / (gas_gamma + 1); + G7 = (gas_gamma - 1) / 2; G8 = gas_gamma - 1; -// left, right states + // left, right states double DL, UL, PL, CL, DR, UR, PR, CR; DL = ps->dl; UL = ps->ul; @@ -130,47 +125,38 @@ double guessp(struct ProblemState *ps) PR = ps->pr; CR = ps->cr; - double CUP, GEL, GER, PM, PMAX, PMIN, PPV, PQ, - PTL, PTR, QMAX, QUSER, UM; + double CUP, GEL, GER, PM, PMAX, PMIN, PPV, PQ, PTL, PTR, QMAX, QUSER, UM; QUSER = 2.0; - CUP = 0.25*(DL + DR)*(CL + CR); - PPV = 0.5*(PL + PR) + 0.5*(UL - UR)*CUP; - PPV = fmax(0.0, PPV); - PMIN = fmin(PL, PR); - PMAX = fmax(PL, PR); - QMAX = PMAX/PMIN; + CUP = 0.25 * (DL + DR) * (CL + CR); + PPV = 0.5 * (PL + PR) + 0.5 * (UL - UR) * CUP; + PPV = fmax(0.0, PPV); + PMIN = fmin(PL, PR); + PMAX = fmax(PL, PR); + QMAX = PMAX / PMIN; - if ((QMAX <= QUSER) && ((PMIN<=PPV) && (PPV<=PMAX))) - { + if ((QMAX <= QUSER) && ((PMIN <= PPV) && (PPV <= PMAX))) { PM = PPV; - } - else - { - if (PPVgas_gamma; double GAMMA, G1, G2, G3, G4, G5, G6, G7, G8; GAMMA = gas_gamma; - G1 = (gas_gamma - 1)/(2*gas_gamma); - G2 = (gas_gamma + 1)/(2*gas_gamma); - G3 = 2*gas_gamma/(gas_gamma - 1); - G4 = 2/(gas_gamma - 1); - G5 = 2/(gas_gamma + 1); - G6 = (gas_gamma - 1)/(gas_gamma + 1); - G7 = (gas_gamma - 1)/2; + G1 = (gas_gamma - 1) / (2 * gas_gamma); + G2 = (gas_gamma + 1) / (2 * gas_gamma); + G3 = 2 * gas_gamma / (gas_gamma - 1); + G4 = 2 / (gas_gamma - 1); + G5 = 2 / (gas_gamma + 1); + G6 = (gas_gamma - 1) / (gas_gamma + 1); + G7 = (gas_gamma - 1) / 2; G8 = gas_gamma - 1; -// left, right states + // left, right states double DL, UL, PL, CL, DR, UR, PR, CR; DL = ps->dl; UL = ps->ul; @@ -198,56 +184,55 @@ starpu(struct ProblemState *ps, double *pm, double *um) CR = ps->cr; PSCALE = 1.0; -// compute initial guess + // compute initial guess PSTART = guessp(ps); //- std::cout << "Initial guess " << PSTART << std::endl; POLD = PSTART; - UDIFF = UR-UL; + UDIFF = UR - UL; bool converged = false; - for (unsigned i=1; igas_gamma; -// compute constants related to gamma + // compute constants related to gamma double GAMMA, G1, G2, G3, G4, G5, G6, G7, G8; GAMMA = gas_gamma; - G1 = (gas_gamma - 1)/(2*gas_gamma); - G2 = (gas_gamma + 1)/(2*gas_gamma); - G3 = 2*gas_gamma/(gas_gamma - 1); - G4 = 2/(gas_gamma - 1); - G5 = 2/(gas_gamma + 1); - G6 = (gas_gamma - 1)/(gas_gamma + 1); - G7 = (gas_gamma - 1)/2; + G1 = (gas_gamma - 1) / (2 * gas_gamma); + G2 = (gas_gamma + 1) / (2 * gas_gamma); + G3 = 2 * gas_gamma / (gas_gamma - 1); + G4 = 2 / (gas_gamma - 1); + G5 = 2 / (gas_gamma + 1); + G6 = (gas_gamma - 1) / (gas_gamma + 1); + G7 = (gas_gamma - 1) / 2; G8 = gas_gamma - 1; -// left, right states + // left, right states double DL, UL, PL, CL, DR, UR, PR, CR; DL = ps->dl; UL = ps->ul; @@ -257,161 +242,132 @@ sample(struct ProblemState *ps, double PM, double UM, double S, UR = ps->ur; PR = ps->pr; CR = ps->cr; - + double C, CML, CMR, PML, PMR, SHL, SHR, SL, SR, STL, STR; //std::cout << "S = " << S << std::endl; //std::cout << "UM = " << UM << std::endl; - if (S<=UM) - { -// left of contact discontinuity + if (S <= UM) { + // left of contact discontinuity //std::cout << "Left of contact .." << std::endl; - if (PM<=PL) - { + if (PM <= PL) { //std::cout << "Left rarefaction ...." << std::endl; -// left rarefaction - SHL = UL-CL; - if (S<=SHL) - { + // left rarefaction + SHL = UL - CL; + if (S <= SHL) { //std::cout << "Left data state!" << std::endl; -// left data state + // left data state *D = DL; *U = UL; *P = PL; - } - else - { - CML = CL*pow(PM/PL, G1); - STL = UM-CML; + } else { + CML = CL * pow(PM / PL, G1); + STL = UM - CML; - if (S>STL) - { + if (S > STL) { //std::cout << "Star left state!" << std::endl; -// Star left state - *D = DL*pow(PM/PL, 1/GAMMA); + // Star left state + *D = DL * pow(PM / PL, 1 / GAMMA); *U = UM; *P = PM; - } - else - { + } else { //std::cout << "Inside left fan!" << std::endl; -// inside left fan - *U = G5*(CL + G7*UL + S); - C = G5*(CL + G7*(UL - S)); - *D = DL*pow(C/CL, G4); - *P = PL*pow(C/CL, G3); + // inside left fan + *U = G5 * (CL + G7 * UL + S); + C = G5 * (CL + G7 * (UL - S)); + *D = DL * pow(C / CL, G4); + *P = PL * pow(C / CL, G3); } } - } - else - { + } else { //std::cout << "Left shock ..." << std::endl; -// left shock - PML = PM/PL; - SL = UL - CL*sqrt(G2*PML + G1); + // left shock + PML = PM / PL; + SL = UL - CL * sqrt(G2 * PML + G1); - if (S<=SL) - { + if (S <= SL) { //std::cout << "Left data state!" << std::endl; -// point is left data state + // point is left data state *D = DL; *U = UL; *P = PL; - } - else - { + } else { //std::cout << "Star left state!" << std::endl; -// point is star left state - *D = DL*(PML + G6)/(PML*G6 + 1.0); + // point is star left state + *D = DL * (PML + G6) / (PML * G6 + 1.0); *U = UM; *P = PM; } } - } - else - { -// right of contact discontinuity - if (PM>PR) - { -// right shock - - PMR = PM/PR; - SR = UR + CR*sqrt(G2*PMR + G1); - - if (S>=SR) - { -// right data state + } else { + // right of contact discontinuity + if (PM > PR) { + // right shock + + PMR = PM / PR; + SR = UR + CR * sqrt(G2 * PMR + G1); + + if (S >= SR) { + // right data state *D = DR; *U = UR; *P = PR; - } - else - { -// right star state - *D = DR*(PMR + G6)/(PMR*G6 + 1.0); + } else { + // right star state + *D = DR * (PMR + G6) / (PMR * G6 + 1.0); *U = UM; *P = PM; } - } - else - { + } else { //std::cout << "Right rarefaction ..." << std::endl; -// right rarefaction - SHR = UR+CR; + // right rarefaction + SHR = UR + CR; - if (S>=SHR) - { -// right data state + if (S >= SHR) { + // right data state *D = DR; *U = UR; *P = PR; - } - else - { - CMR = CR*pow(PM/PR, G1); + } else { + CMR = CR * pow(PM / PR, G1); STR = UM + CMR; - if (S<=STR) - { -// star right state - *D = DR*pow(PM/PR, 1.0/GAMMA); + if (S <= STR) { + // star right state + *D = DR * pow(PM / PR, 1.0 / GAMMA); *U = UM; *P = PM; - } - else - { -// inside left fan - *U = G5*(-CR + G7*UR + S); - C = G5*(CR - G7*(UR - S)); - *D = DR*pow(C/CR, G4); - *P = PR*pow(C/CR, G3); + } else { + // inside left fan + *U = G5 * (-CR + G7 * UR + S); + C = G5 * (CR - G7 * (UR - S)); + *D = DR * pow(C / CR, G4); + *P = PR * pow(C / CR, G3); } } } } } -static void -sampleWithVacuum(struct ProblemState *ps, double S, double *D, - double *U, double *P) +static void sampleWithVacuum(struct ProblemState *ps, double S, double *D, double *U, double *P) { double gas_gamma = ps->gas_gamma; -// compute constants related to gamma + // compute constants related to gamma double GAMMA, G1, G2, G3, G4, G5, G6, G7, G8; GAMMA = gas_gamma; - G1 = (gas_gamma - 1)/(2*gas_gamma); - G2 = (gas_gamma + 1)/(2*gas_gamma); - G3 = 2*gas_gamma/(gas_gamma - 1); - G4 = 2/(gas_gamma - 1); - G5 = 2/(gas_gamma + 1); - G6 = (gas_gamma - 1)/(gas_gamma + 1); - G7 = (gas_gamma - 1)/2; + G1 = (gas_gamma - 1) / (2 * gas_gamma); + G2 = (gas_gamma + 1) / (2 * gas_gamma); + G3 = 2 * gas_gamma / (gas_gamma - 1); + G4 = 2 / (gas_gamma - 1); + G5 = 2 / (gas_gamma + 1); + G6 = (gas_gamma - 1) / (gas_gamma + 1); + G7 = (gas_gamma - 1) / 2; G8 = gas_gamma - 1; -// left, right states + // left, right states double DL, UL, PL, CL, DR, UR, PR, CR; DL = ps->dl; UL = ps->ul; @@ -422,28 +378,22 @@ sampleWithVacuum(struct ProblemState *ps, double S, double *D, PR = ps->pr; CR = ps->cr; -// assume vacuum is to the right (JUST FOR NOW) - double sstar = UL + 2*CL/G8; - double relVel = UL-CL; - if (S<=relVel) - { -// left of rarefaction + // assume vacuum is to the right (JUST FOR NOW) + double sstar = UL + 2 * CL / G8; + double relVel = UL - CL; + if (S <= relVel) { + // left of rarefaction *D = DL; *U = UL; *P = PL; - } - else - { - if ((relVelgas_gamma; -// compute constants related to gamma - g1 = (gas_gamma - 1)/(2*gas_gamma); - g2 = (gas_gamma + 1)/(2*gas_gamma); - g3 = 2*gas_gamma/(gas_gamma - 1); - g4 = 2/(gas_gamma - 1); - g5 = 2/(gas_gamma + 1); - g6 = (gas_gamma - 1)/(gas_gamma + 1); - g7 = (gas_gamma - 1)/2; + // compute constants related to gamma + g1 = (gas_gamma - 1) / (2 * gas_gamma); + g2 = (gas_gamma + 1) / (2 * gas_gamma); + g3 = 2 * gas_gamma / (gas_gamma - 1); + g4 = 2 / (gas_gamma - 1); + g5 = 2 / (gas_gamma + 1); + g6 = (gas_gamma - 1) / (gas_gamma + 1); + g7 = (gas_gamma - 1) / 2; g8 = gas_gamma - 1; -// check if a vacuum is generated - if (g4*(ps->cl+ps->cr) <= (ps->ur-ps->ul)) { + // check if a vacuum is generated + if (g4 * (ps->cl + ps->cr) <= (ps->ur - ps->ul)) { printf("Initial conditions will lead to vacuum. Aborting ...\n"); exit(1); } -// compute pressure and velocity in "star" region + // compute pressure and velocity in "star" region double pm, um; starpu(ps, &pm, &um); -// cell spacing - double dx = ps->domlen/ps->ncell; -// compute solution at each grid point - for (unsigned i=0; incell; ++i) { - double xpos = ps->lower + (i+0.5)*dx; - double s = (xpos-ps->disLoc)/ps->tEnd; -// compute solution at (x,t) = (xpos-ps->disLoc, ps->tEnd) + // cell spacing + double dx = ps->domlen / ps->ncell; + // compute solution at each grid point + for (unsigned i = 0; i < ps->ncell; ++i) { + double xpos = ps->lower + (i + 0.5) * dx; + double s = (xpos - ps->disLoc) / ps->tEnd; + // compute solution at (x,t) = (xpos-ps->disLoc, ps->tEnd) double dsol, usol, psol; sample(ps, pm, um, s, &dsol, &usol, &psol); -// copy solution into array + // copy solution into array double *d = gkyl_array_fetch(ps->density, i); d[0] = dsol; @@ -498,30 +447,28 @@ exactEulerRp(struct ProblemState *ps) pr[0] = psol; double *iE = gkyl_array_fetch(ps->internalEnergy, i); - iE[i] = psol/dsol/g8; + iE[i] = psol / dsol / g8; } } -static void -exactEulerRpWithVacuum(struct ProblemState *ps) +static void exactEulerRpWithVacuum(struct ProblemState *ps) { - double gas_gamma = ps->gas_gamma; double g8 = gas_gamma - 1; -// cell spacing - double dx = ps->domlen/ps->ncell; -// compute solution at each grid point - for (unsigned i=0; incell; ++i) { - double xpos = ps->lower + (i+0.5)*dx; - double s = (xpos-ps->disLoc)/ps->tEnd; -// compute solution at (x,t) = (xpos-ps->disLoc, ps->tEnd) + // cell spacing + double dx = ps->domlen / ps->ncell; + // compute solution at each grid point + for (unsigned i = 0; i < ps->ncell; ++i) { + double xpos = ps->lower + (i + 0.5) * dx; + double s = (xpos - ps->disLoc) / ps->tEnd; + // compute solution at (x,t) = (xpos-ps->disLoc, ps->tEnd) double dsol, usol, psol; sampleWithVacuum(ps, s, &dsol, &usol, &psol); // copy solution into array -// copy solution into array + // copy solution into array double *d = gkyl_array_fetch(ps->density, i); d[0] = dsol; @@ -531,59 +478,67 @@ exactEulerRpWithVacuum(struct ProblemState *ps) double *pr = gkyl_array_fetch(ps->pressure, i); pr[0] = psol; - double *iE = gkyl_array_fetch(ps->internalEnergy, i); - if (dsol < DBL_EPSILON) + double *iE = gkyl_array_fetch(ps->internalEnergy, i); + if (dsol < DBL_EPSILON) { iE[0] = 0.0; - else - iE[0] = psol/dsol/g8; + } else { + iE[0] = psol / dsol / g8; + } } } -void -solveRiemannProblem(struct _ProblemState _ps, const char *out_prefix) +void solveRiemannProblem(struct _ProblemState _ps, const char *out_prefix) { struct ProblemState *ps = new_ProblemState(_ps.ncell); - - ps->dl = _ps.dl; ps->ul = _ps.ul; ps->pl = _ps.pl; - ps->dr = _ps.dr; ps->ur = _ps.ur; ps->pr = _ps.pr; - ps->lower = _ps.lower; ps->upper = _ps.upper; + + ps->dl = _ps.dl; + ps->ul = _ps.ul; + ps->pl = _ps.pl; + ps->dr = _ps.dr; + ps->ur = _ps.ur; + ps->pr = _ps.pr; + ps->lower = _ps.lower; + ps->upper = _ps.upper; ps->gas_gamma = _ps.gas_gamma; ps->tEnd = _ps.tEnd; ps->disLoc = _ps.disLoc; - ps->domlen = ps->upper-ps->lower; + ps->domlen = ps->upper - ps->lower; unsigned ncell = _ps.ncell; // compute sound speeds in each region - if (ps->dl != 0) - ps->cl = sqrt(ps->gas_gamma*ps->pl/ps->dl); - else + if (ps->dl != 0) { + ps->cl = sqrt(ps->gas_gamma * ps->pl / ps->dl); + } else { ps->cl = 0.0; + } - if (ps->dr != 0) - ps->cr = sqrt(ps->gas_gamma*ps->pr/ps->dr); - else + if (ps->dr != 0) { + ps->cr = sqrt(ps->gas_gamma * ps->pr / ps->dr); + } else { ps->cr = 0.0; + } fprintf(stdout, "Solving Exact Euler Riemann Problem ...\n"); -// compute solution - if ((ps->dl != 0.0) && (ps->dr != 0.0)) + // compute solution + if ((ps->dl != 0.0) && (ps->dr != 0.0)) { exactEulerRp(ps); - else if (ps->dr == 0) + } else if (ps->dr == 0) { exactEulerRpWithVacuum(ps); - else + } else { exactEulerRpWithVacuum(ps); + } fprintf(stdout, "... done!\n"); struct gkyl_rect_grid grid; - gkyl_rect_grid_init(&grid, 1, (double[]) { _ps.lower }, (double[]) { _ps.upper }, (int[]) { _ps.ncell }); + gkyl_rect_grid_init(&grid, 1, (double[]){_ps.lower}, (double[]){_ps.upper}, (int[]){_ps.ncell}); struct gkyl_range range; - gkyl_range_init_from_shape(&range, 1, (int[]) { _ps.ncell } ); + gkyl_range_init_from_shape(&range, 1, (int[]){_ps.ncell}); - char *fname = gkyl_malloc(strlen(out_prefix)+128); + char *fname = gkyl_malloc(strlen(out_prefix) + 128); sprintf(fname, "%s_density.gkyl", out_prefix); gkyl_grid_sub_array_write(&grid, &range, 0, ps->density, fname); diff --git a/gkeyll/lua/Tool/gkyl_multi_mom_linear.h b/gkeyll/lua/Tool/gkyl_multi_mom_linear.h index cf425e6143..2b19241e40 100644 --- a/gkeyll/lua/Tool/gkyl_multi_mom_linear.h +++ b/gkeyll/lua/Tool/gkyl_multi_mom_linear.h @@ -2,7 +2,7 @@ // // C back-end for use in multimomlinear Tool. This code computes // eigenvalues and eigenvectors of the complex matrix supplied to it. -// +// // _______ ___ // + 6 @ |||| # P ||| + //------------------------------------------------------------------------------ @@ -11,4 +11,7 @@ #include #include -bool gkyl_multi_mom_eigensolve(double _Complex *A, double _Complex *x, double _Complex *vl, double _Complex *vr, int N, int eig_vec); +bool gkyl_multi_mom_eigensolve( + double _Complex *A, double _Complex *x, double _Complex *vl, double _Complex *vr, int N, + int eig_vec +); diff --git a/gkeyll/lua/Tool/multi_mom_linear.c b/gkeyll/lua/Tool/multi_mom_linear.c index 0badcac022..3cd1e72eed 100644 --- a/gkeyll/lua/Tool/multi_mom_linear.c +++ b/gkeyll/lua/Tool/multi_mom_linear.c @@ -2,7 +2,7 @@ // // C back-end for use in multimomlinear Tool. This code computes // eigenvalues and eigenvectors of the complex matrix supplied to it. -// +// // _______ ___ // + 6 @ |||| # P ||| + //------------------------------------------------------------------------------ @@ -12,23 +12,24 @@ // BLAS and LAPACKE includes #ifdef GKYL_USING_FRAMEWORK_ACCELERATE -# include +#include #else // On non-Darwin platforms use OpenBLAS -# include -# include +#include +#include #endif -bool -gkyl_multi_mom_eigensolve(double _Complex *A, double _Complex *x, double _Complex *vl, double _Complex *vr, int N, int eig_vec) +bool gkyl_multi_mom_eigensolve( + double _Complex *A, double _Complex *x, double _Complex *vl, double _Complex *vr, int N, + int eig_vec +) { char calc_vec = 'N'; calc_vec = (eig_vec == 1) ? 'V' : 'N'; -#ifdef GKYL_USING_FRAMEWORK_ACCELERATE +#ifdef GKYL_USING_FRAMEWORK_ACCELERATE int info = 1; -#else - int info = LAPACKE_zgeev(LAPACK_COL_MAJOR, calc_vec, calc_vec, N, A, - N, x, vl, N, vr, N); +#else + int info = LAPACKE_zgeev(LAPACK_COL_MAJOR, calc_vec, calc_vec, N, A, N, x, vl, N, vr, N); #endif return info == 0 ? true : false; } diff --git a/gyrokinetic/apps/block_gk_geom.c b/gyrokinetic/apps/block_gk_geom.c index f95576a0a3..fffb852fd4 100644 --- a/gyrokinetic/apps/block_gk_geom.c +++ b/gyrokinetic/apps/block_gk_geom.c @@ -9,12 +9,11 @@ struct gkyl_gk_block_geom { int num_blocks; // total number of blocks struct gkyl_gk_block_geom_info *blocks; // info for each block struct gkyl_block_topo *btopo; // topology of blocks - + struct gkyl_ref_count ref_count; }; -static void -gk_block_geom_free(const struct gkyl_ref_count *ref) +static void gk_block_geom_free(const struct gkyl_ref_count *ref) { struct gkyl_gk_block_geom *bgeom = container_of(ref, struct gkyl_gk_block_geom, ref_count); gkyl_free(bgeom->blocks); @@ -22,8 +21,7 @@ gk_block_geom_free(const struct gkyl_ref_count *ref) gkyl_free(bgeom); } -struct gkyl_gk_block_geom* -gkyl_gk_block_geom_new(int ndim, int nblocks) +struct gkyl_gk_block_geom *gkyl_gk_block_geom_new(int ndim, int nblocks) { struct gkyl_gk_block_geom *bgeom = gkyl_malloc(sizeof(struct gkyl_gk_block_geom)); bgeom->ndim = ndim; @@ -37,35 +35,37 @@ gkyl_gk_block_geom_new(int ndim, int nblocks) return bgeom; } -int -gkyl_gk_block_geom_ndim(const struct gkyl_gk_block_geom *bgeom) +int gkyl_gk_block_geom_ndim(const struct gkyl_gk_block_geom *bgeom) { return bgeom->ndim; } -int -gkyl_gk_block_geom_num_blocks(const struct gkyl_gk_block_geom *bgeom) +int gkyl_gk_block_geom_num_blocks(const struct gkyl_gk_block_geom *bgeom) { return bgeom->num_blocks; } -void -gkyl_gk_block_geom_set_block(struct gkyl_gk_block_geom *bgeom, int bidx, - const struct gkyl_gk_block_geom_info *info) +void gkyl_gk_block_geom_set_block( + struct gkyl_gk_block_geom *bgeom, int bidx, const struct gkyl_gk_block_geom_info *info +) { memcpy(&bgeom->blocks[bidx], info, sizeof(struct gkyl_gk_block_geom_info)); - - for (int d=0; dndim; ++d) + + for (int d = 0; d < bgeom->ndim; ++d) { bgeom->blocks[bidx].cuts[d] = info->cuts[d] > 0 ? info->cuts[d] : 1; - + } + // set topology information - for (int i=0; indim; ++i) - for (int e=0; e<2; ++e) - bgeom->btopo->conn[bidx].connections[i][e] = info->connections[i][e]; + for (int i = 0; i < bgeom->ndim; ++i) { + for (int e = 0; e < 2; ++e) { + bgeom->btopo->conn[bidx].connections[i][e] = info->connections[i][e]; + } + } } -void -gkyl_gk_block_geom_reset_block_extents(struct gkyl_gk_block_geom *bgeom, int bidx, double *lower, double *upper) +void gkyl_gk_block_geom_reset_block_extents( + struct gkyl_gk_block_geom *bgeom, int bidx, double *lower, double *upper +) { struct gkyl_gk_block_geom_info *bgi = &bgeom->blocks[bidx]; for (int i = 0; i < bgeom->ndim; ++i) { @@ -74,34 +74,30 @@ gkyl_gk_block_geom_reset_block_extents(struct gkyl_gk_block_geom *bgeom, int bid } } -const struct gkyl_gk_block_geom_info* +const struct gkyl_gk_block_geom_info * gkyl_gk_block_geom_get_block(const struct gkyl_gk_block_geom *bgeom, int bidx) { return &bgeom->blocks[bidx]; } -int -gkyl_gk_block_geom_check_consistency(const struct gkyl_gk_block_geom *bgeom) +int gkyl_gk_block_geom_check_consistency(const struct gkyl_gk_block_geom *bgeom) { // MORE TESTS ARE NEEDED HERE return gkyl_block_topo_check_consistency(bgeom->btopo); } -struct gkyl_gk_block_geom * -gkyl_gk_block_geom_acquire(const struct gkyl_gk_block_geom* bgeom) +struct gkyl_gk_block_geom *gkyl_gk_block_geom_acquire(const struct gkyl_gk_block_geom *bgeom) { gkyl_ref_count_inc(&bgeom->ref_count); - return (struct gkyl_gk_block_geom*) bgeom; + return (struct gkyl_gk_block_geom *)bgeom; } -struct gkyl_block_topo* -gkyl_gk_block_geom_topo(const struct gkyl_gk_block_geom *bgeom) +struct gkyl_block_topo *gkyl_gk_block_geom_topo(const struct gkyl_gk_block_geom *bgeom) { return gkyl_block_topo_acquire(bgeom->btopo); } -void -gkyl_gk_block_geom_release(struct gkyl_gk_block_geom* bgeom) +void gkyl_gk_block_geom_release(struct gkyl_gk_block_geom *bgeom) { gkyl_ref_count_dec(&bgeom->ref_count); } diff --git a/gyrokinetic/apps/eirene.c b/gyrokinetic/apps/eirene.c index 57bca38122..d30ad774b5 100644 --- a/gyrokinetic/apps/eirene.c +++ b/gyrokinetic/apps/eirene.c @@ -14,7 +14,8 @@ // Function to check whether we are in blocks 6 or 7 // which are core blocks for half domain -static bool gk_eirene_gyrokinetic_str_ends_in_b67(char *name){ +static bool gk_eirene_gyrokinetic_str_ends_in_b67(char *name) +{ size_t len = strlen(name); int i = len - 1; int digit_count = 0; @@ -22,24 +23,25 @@ static bool gk_eirene_gyrokinetic_str_ends_in_b67(char *name){ i--; digit_count++; } - if (digit_count > 0 && i >= 1 && name[i] == 'b' && name[i-1] == '_') { + if (digit_count > 0 && i >= 1 && name[i] == 'b' && name[i - 1] == '_') { const char *num_str = &name[i + 1]; int num = atoi(num_str); - if ( num == 6) + if (num == 6) { return true; - else if ( num == 7) + } else if (num == 7) { return true; - else + } else { return false; - } - else { + } + } else { return false; } } // Function to check whether we are in blocks 10 or 11 // which are core blocks for full domain -static bool gk_eirene_gyrokinetic_str_ends_in_b1011(char *name){ +static bool gk_eirene_gyrokinetic_str_ends_in_b1011(char *name) +{ size_t len = strlen(name); int i = len - 1; int digit_count = 0; @@ -49,28 +51,29 @@ static bool gk_eirene_gyrokinetic_str_ends_in_b1011(char *name){ digit_count++; } - if (digit_count > 0 && i >= 1 && name[i] == 'b' && name[i-1] == '_') { + if (digit_count > 0 && i >= 1 && name[i] == 'b' && name[i - 1] == '_') { const char *num_str = &name[i + 1]; int num = atoi(num_str); // Changed the checks to 10 and 11 - if ( num == 10) + if (num == 10) { return true; - else if ( num == 11) + } else if (num == 11) { return true; - else + } else { return false; - } - else { + } + } else { return false; } } -void -gk_eirene_rhs(gkyl_gyrokinetic_app *app, const struct gkyl_array *fin[], struct gkyl_array *rhs[]) +void gk_eirene_rhs( + gkyl_gyrokinetic_app *app, const struct gkyl_array *fin[], struct gkyl_array *rhs[] +) { struct gk_eirene *eirene = app->eirene; - for (int i=0; iinfo.num_coupling_species; ++i) { + for (int i = 0; i < eirene->info.num_coupling_species; ++i) { struct gk_species *gks = eirene->coupling_species[i]; struct gk_source_bgk *bgk_src = &eirene->bgk_src[i]; int sidx = gk_find_species_idx(app, gks->info.name); @@ -78,54 +81,60 @@ gk_eirene_rhs(gkyl_gyrokinetic_app *app, const struct gkyl_array *fin[], struct } } -void -gk_eirene_read(struct gkyl_gyrokinetic_app *app, struct gkyl_array *out, cstr fileNm) +void gk_eirene_read(struct gkyl_gyrokinetic_app *app, struct gkyl_array *out, cstr fileNm) { - struct gkyl_array* nnodal = mkarr(false, 1, app->gk_geom->nrange_int.volume); + struct gkyl_array *nnodal = mkarr(false, 1, app->gk_geom->nrange_int.volume); - FILE *ptr = fopen(fileNm.str,"r"); + FILE *ptr = fopen(fileNm.str, "r"); size_t status; int nr = gkyl_range_shape(&app->gk_geom->nrange_int, 0); int nz = gkyl_range_shape(&app->gk_geom->nrange_int, 1); int idx[2]; - for(int ir = 0; ir < nr; ir++){ + for (int ir = 0; ir < nr; ir++) { idx[0] = ir; - for(int iz = 0; iz < nz; iz++){ + for (int iz = 0; iz < nz; iz++) { idx[1] = iz; double *nnodal_n = gkyl_array_fetch(nnodal, gkyl_range_idx(&app->gk_geom->nrange_int, idx)); - status = fscanf(ptr,"%lf", nnodal_n); + status = fscanf(ptr, "%lf", nnodal_n); } } fclose(ptr); struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&app->basis, &app->grid, false); - gkyl_nodal_ops_n2m(n2m, &app->basis, &app->grid, &app->gk_geom->nrange_int, &app->local, 1, nnodal, out, true); + gkyl_nodal_ops_n2m( + n2m, &app->basis, &app->grid, &app->gk_geom->nrange_int, &app->local, 1, nnodal, out, true + ); gkyl_array_release(nnodal); gkyl_nodal_ops_release(n2m); } -void -gk_eirene_write(struct gkyl_gyrokinetic_app *app, double tm, int frame) +void gk_eirene_write(struct gkyl_gyrokinetic_app *app, double tm, int frame) { struct gk_eirene *eirene = app->eirene; // Read new EIRENE data. - for (int i=0; iinfo.num_coupling_species; ++i) { + for (int i = 0; i < eirene->info.num_coupling_species; ++i) { struct gk_species *gks = eirene->coupling_species[i]; struct gk_source_bgk *bgk_src = &eirene->bgk_src[i]; - cstr fileNm = cstr_from_fmt("%s%s-%s_M0source.txt", eirene->info.input_data_path, app->name, gks->info.name); + cstr fileNm = cstr_from_fmt( + "%s%s-%s_M0source.txt", eirene->info.input_data_path, app->name, gks->info.name + ); gk_eirene_read(app, bgk_src->M0dot_host, fileNm); cstr_drop(&fileNm); - fileNm = cstr_from_fmt("%s%s-%s_M1source.txt", eirene->info.input_data_path, app->name, gks->info.name); + fileNm = cstr_from_fmt( + "%s%s-%s_M1source.txt", eirene->info.input_data_path, app->name, gks->info.name + ); gk_eirene_read(app, bgk_src->M1dot_host, fileNm); cstr_drop(&fileNm); - fileNm = cstr_from_fmt("%s%s-%s_M2source.txt", eirene->info.input_data_path, app->name, gks->info.name); + fileNm = cstr_from_fmt( + "%s%s-%s_M2source.txt", eirene->info.input_data_path, app->name, gks->info.name + ); gk_eirene_read(app, bgk_src->M2dot_host, fileNm); cstr_drop(&fileNm); - if(app->use_gpu) { + if (app->use_gpu) { gkyl_array_copy(bgk_src->M0dot, bgk_src->M0dot_host); gkyl_array_copy(bgk_src->M1dot, bgk_src->M1dot_host); gkyl_array_copy(bgk_src->M2dot, bgk_src->M2dot_host); @@ -133,58 +142,52 @@ gk_eirene_write(struct gkyl_gyrokinetic_app *app, double tm, int frame) } // Write out the source moments - for (int i=0; iinfo.num_coupling_species; ++i) { + for (int i = 0; i < eirene->info.num_coupling_species; ++i) { struct gk_species *gks = eirene->coupling_species[i]; struct gk_source_bgk *bgk_src = &eirene->bgk_src[i]; gk_species_source_bgk_write_diags(app, gks, bgk_src, tm, frame); } - } -void -gk_eirene_calc_integrated_diagnostics(struct gkyl_gyrokinetic_app *app, double tm) +void gk_eirene_calc_integrated_diagnostics(struct gkyl_gyrokinetic_app *app, double tm) { struct gk_eirene *eirene = app->eirene; - for (int i=0; iinfo.num_coupling_species; ++i) { + for (int i = 0; i < eirene->info.num_coupling_species; ++i) { struct gk_species *gks = eirene->coupling_species[i]; struct gk_source_bgk *bgk_src = &eirene->bgk_src[i]; bgk_src->calc_integrated_diags_func(app, gks, bgk_src, tm); } } -void -gk_eirene_write_integrated_diagnostics(struct gkyl_gyrokinetic_app *app) +void gk_eirene_write_integrated_diagnostics(struct gkyl_gyrokinetic_app *app) { struct gk_eirene *eirene = app->eirene; - for (int i=0; iinfo.num_coupling_species; ++i) { + for (int i = 0; i < eirene->info.num_coupling_species; ++i) { struct gk_species *gks = eirene->coupling_species[i]; struct gk_source_bgk *bgk_src = &eirene->bgk_src[i]; bgk_src->write_integrated_diags_func(app, gks, bgk_src); } } -struct gk_eirene* -gk_eirene_init(struct gkyl_gyrokinetic_app *app, struct gkyl_gk *gk) +struct gk_eirene *gk_eirene_init(struct gkyl_gyrokinetic_app *app, struct gkyl_gk *gk) { - struct gk_eirene *eirene = gkyl_malloc(sizeof(struct gk_eirene)); eirene->info = gk->eirene; - for (int i=0; iinfo.num_coupling_species; ++i) { + for (int i = 0; i < eirene->info.num_coupling_species; ++i) { eirene->coupling_species[i] = gk_find_species(app, eirene->info.coupling_species[i]); } - for (int i=0; iinfo.num_coupling_species; ++i) { + for (int i = 0; i < eirene->info.num_coupling_species; ++i) { struct gk_species *gks = eirene->coupling_species[i]; double coll_factor = 1.0; if (gk_eirene_gyrokinetic_str_ends_in_b67(app->name) && app->gk_geom->half_domain) { coll_factor = eirene->info.core_coll_factor[i]; - } - else if (gk_eirene_gyrokinetic_str_ends_in_b1011(app->name)) { + } else if (gk_eirene_gyrokinetic_str_ends_in_b1011(app->name)) { coll_factor = eirene->info.core_coll_factor[i]; } - eirene->bgk_src[i].injection_time = eirene->info.injection_time[i]/coll_factor; + eirene->bgk_src[i].injection_time = eirene->info.injection_time[i] / coll_factor; eirene->bgk_src[i].damping_factor = eirene->info.damping_factor[i]; eirene->bgk_src[i].source_bgk_id = GKYL_SOURCE_BGK_EXTERNAL; eirene->bgk_src[i].write_diagnostics = true; @@ -192,33 +195,38 @@ gk_eirene_init(struct gkyl_gyrokinetic_app *app, struct gkyl_gk *gk) } // Read initial EIRENE data. - for (int i=0; iinfo.num_coupling_species; ++i) { + for (int i = 0; i < eirene->info.num_coupling_species; ++i) { struct gk_species *gks = eirene->coupling_species[i]; struct gk_source_bgk *bgk_src = &eirene->bgk_src[i]; - cstr fileNm = cstr_from_fmt("%s%s-%s_M0source.txt", eirene->info.input_data_path, app->name, gks->info.name); + cstr fileNm = cstr_from_fmt( + "%s%s-%s_M0source.txt", eirene->info.input_data_path, app->name, gks->info.name + ); gk_eirene_read(app, bgk_src->M0dot_host, fileNm); cstr_drop(&fileNm); - fileNm = cstr_from_fmt("%s%s-%s_M1source.txt", eirene->info.input_data_path, app->name, gks->info.name); + fileNm = cstr_from_fmt( + "%s%s-%s_M1source.txt", eirene->info.input_data_path, app->name, gks->info.name + ); gk_eirene_read(app, bgk_src->M1dot_host, fileNm); cstr_drop(&fileNm); - fileNm = cstr_from_fmt("%s%s-%s_M2source.txt", eirene->info.input_data_path, app->name, gks->info.name); + fileNm = cstr_from_fmt( + "%s%s-%s_M2source.txt", eirene->info.input_data_path, app->name, gks->info.name + ); gk_eirene_read(app, bgk_src->M2dot_host, fileNm); cstr_drop(&fileNm); - if(app->use_gpu) { + if (app->use_gpu) { gkyl_array_copy(bgk_src->M0dot, bgk_src->M0dot_host); gkyl_array_copy(bgk_src->M1dot, bgk_src->M1dot_host); gkyl_array_copy(bgk_src->M2dot, bgk_src->M2dot_host); } } - return eirene; } -void -gk_eirene_release(struct gkyl_gyrokinetic_app *app, struct gk_eirene *eirene) +void gk_eirene_release(struct gkyl_gyrokinetic_app *app, struct gk_eirene *eirene) { - for (int i=0; iinfo.num_coupling_species; ++i) + for (int i = 0; i < eirene->info.num_coupling_species; ++i) { gk_species_source_bgk_release(app, &eirene->bgk_src[i]); + } gkyl_free(eirene); } diff --git a/gyrokinetic/apps/gk_field.c b/gyrokinetic/apps/gk_field.c index 8e81b86f67..3c5c4c27fb 100644 --- a/gyrokinetic/apps/gk_field.c +++ b/gyrokinetic/apps/gk_field.c @@ -13,45 +13,45 @@ #include // Functions related to setting the potential by adjusting the polarization density -static void -eval_on_nodes_c2p_position_func(const double *xcomp, double *xphys, void *ctx) +static void eval_on_nodes_c2p_position_func(const double *xcomp, double *xphys, void *ctx) { struct gkyl_position_map *gpm = ctx; gkyl_position_map_eval_mc2nu(gpm, xcomp, xphys); } -static struct gkyl_app_restart_status -header_from_file(gkyl_gyrokinetic_app *app, const char *fname) +static struct gkyl_app_restart_status header_from_file(gkyl_gyrokinetic_app *app, const char *fname) { - struct gkyl_app_restart_status rstat = { .io_status = GKYL_ARRAY_RIO_FOPEN_FAILED }; - + struct gkyl_app_restart_status rstat = {.io_status = GKYL_ARRAY_RIO_FOPEN_FAILED}; + FILE *fp = 0; - with_file(fp, fname, "r") { + with_file(fp, fname, "r") + { struct gkyl_rect_grid grid; struct gkyl_array_header_info hdr; rstat.io_status = gkyl_grid_sub_array_header_read_fp(&grid, &hdr, fp); if (GKYL_ARRAY_RIO_SUCCESS == rstat.io_status) { - if (hdr.etype != GKYL_DOUBLE) + if (hdr.etype != GKYL_DOUBLE) { rstat.io_status = GKYL_ARRAY_RIO_DATA_MISMATCH; + } } struct gkyl_msgpack_map_elem elem_list[] = { - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .cval = 0 }, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0}, + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .cval = 0} }; - int elem_list_len = sizeof(elem_list)/sizeof(elem_list[0]); - gkyl_msgpack_to_map_elem_list(&(struct gkyl_msgpack_data) { - .meta = hdr.meta, - .meta_sz = hdr.meta_size - }, elem_list_len, elem_list); + int elem_list_len = sizeof(elem_list) / sizeof(elem_list[0]); + gkyl_msgpack_to_map_elem_list( + &(struct gkyl_msgpack_data){.meta = hdr.meta, .meta_sz = hdr.meta_size}, elem_list_len, + elem_list + ); rstat.frame = gkyl_msgpack_map_elem_get_uint(elem_list_len, elem_list, "frame"); rstat.stime = gkyl_msgpack_map_elem_get_double(elem_list_len, elem_list, "time"); gkyl_grid_sub_array_header_release(&hdr); } - + return rstat; } @@ -65,18 +65,17 @@ gk_field_polarization_potential_new(struct gk_field *f, struct gkyl_gyrokinetic_ gkyl_cart_modal_tensor(&phi_pol_basis, app->cdim, app->poly_order + 1); f->phi_pol = mkarr(app->use_gpu, phi_pol_basis.num_basis, app->local_ext.volume); - struct gkyl_array *phi_pol_ho = app->use_gpu ? mkarr(false, f->phi_pol->ncomp, f->phi_pol->size) - : gkyl_array_acquire(f->phi_pol); - - struct gkyl_eval_on_nodes *phi_pol_proj = gkyl_eval_on_nodes_inew(&(struct gkyl_eval_on_nodes_inp){ - .grid = &app->grid, - .basis = &phi_pol_basis, - .num_ret_vals = 1, - .eval = f->info.polarization_potential, - .ctx = f->info.polarization_potential_ctx, - .c2p_func = eval_on_nodes_c2p_position_func, - .c2p_func_ctx = app->position_map, - }); + struct gkyl_array *phi_pol_ho = app->use_gpu ? mkarr(false, f->phi_pol->ncomp, f->phi_pol->size) : + gkyl_array_acquire(f->phi_pol); + + struct gkyl_eval_on_nodes *phi_pol_proj = gkyl_eval_on_nodes_inew(&(struct gkyl_eval_on_nodes_inp + ){.grid = &app->grid, + .basis = &phi_pol_basis, + .num_ret_vals = 1, + .eval = f->info.polarization_potential, + .ctx = f->info.polarization_potential_ctx, + .c2p_func = eval_on_nodes_c2p_position_func, + .c2p_func_ctx = app->position_map}); gkyl_eval_on_nodes_advance(phi_pol_proj, 0.0, &app->local, phi_pol_ho); gkyl_array_copy(f->phi_pol, phi_pol_ho); @@ -85,64 +84,74 @@ gk_field_polarization_potential_new(struct gk_field *f, struct gkyl_gyrokinetic_ gkyl_array_release(phi_pol_ho); } -static void -gk_field_polarization_potential_from_file_new(struct gk_field *f, struct gkyl_gyrokinetic_app *app, - struct gkyl_gyrokinetic_ic_import inp) +static void gk_field_polarization_potential_from_file_new( + struct gk_field *f, struct gkyl_gyrokinetic_app *app, struct gkyl_gyrokinetic_ic_import inp +) { f->init_phi_pol = true; struct gkyl_basis phi_pol_basis; gkyl_cart_modal_tensor(&phi_pol_basis, app->cdim, app->poly_order + 1); f->phi_pol = mkarr(app->use_gpu, phi_pol_basis.num_basis, app->local_ext.volume); - struct gkyl_array *phi_pol_ho = app->use_gpu ? mkarr(false, f->phi_pol->ncomp, f->phi_pol->size) - : gkyl_array_acquire(f->phi_pol); + struct gkyl_array *phi_pol_ho = app->use_gpu ? mkarr(false, f->phi_pol->ncomp, f->phi_pol->size) : + gkyl_array_acquire(f->phi_pol); struct gkyl_app_restart_status rstat = header_from_file(app, inp.file_name); if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { - rstat.io_status = gkyl_comm_array_read(app->comm, &app->grid, &app->local, phi_pol_ho, inp.file_name); + rstat.io_status = + gkyl_comm_array_read(app->comm, &app->grid, &app->local, phi_pol_ho, inp.file_name); assert(rstat.io_status == GKYL_ARRAY_RIO_SUCCESS); gkyl_array_copy(f->phi_pol, phi_pol_ho); - } - else { + } else { assert(false); } gkyl_array_release(phi_pol_ho); } -static void -gk_field_polarization_potential_release(struct gk_field *f) +static void gk_field_polarization_potential_release(struct gk_field *f) { gkyl_array_release(f->phi_pol); } // Functions related to the field energy allocations, diagnostics, and release -static void -gk_field_calc_energy_dt_active(gkyl_gyrokinetic_app *app, const struct gk_field *field, double dt, double *energy_reduced) +static void gk_field_calc_energy_dt_active( + gkyl_gyrokinetic_app *app, const struct gk_field *field, double dt, double *energy_reduced +) { struct timespec wst = gkyl_wall_clock(); - gkyl_array_integrate_advance(field->calc_em_energy, field->phi_smooth, - 1.0/dt, field->es_energy_fac, &app->local, &app->local, energy_reduced); + gkyl_array_integrate_advance( + field->calc_em_energy, field->phi_smooth, 1.0 / dt, field->es_energy_fac, &app->local, + &app->local, energy_reduced + ); app->stat.phidot_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_field_calc_energy_dt_none(gkyl_gyrokinetic_app *app, const struct gk_field *field, double dt, double *energy_reduced) +static void gk_field_calc_energy_dt_none( + gkyl_gyrokinetic_app *app, const struct gk_field *field, double dt, double *energy_reduced +) { } -static void -gk_field_calc_energy_enabled(struct gkyl_gyrokinetic_app *app, const struct gk_field *field, double tm) +static void gk_field_calc_energy_enabled( + struct gkyl_gyrokinetic_app *app, const struct gk_field *field, double tm +) { - gkyl_array_integrate_advance(field->calc_em_energy, field->phi_smooth, - 1.0, field->es_energy_fac, &app->local, &app->local, field->em_energy_red); + gkyl_array_integrate_advance( + field->calc_em_energy, field->phi_smooth, 1.0, field->es_energy_fac, &app->local, &app->local, + field->em_energy_red + ); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, field->em_energy_red, field->em_energy_red_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, 1, field->em_energy_red, field->em_energy_red_global + ); double energy_global[1] = {0.0}; if (app->use_gpu) { - gkyl_cu_memcpy(energy_global, field->em_energy_red_global, sizeof(double[1]), GKYL_CU_MEMCPY_D2H); + gkyl_cu_memcpy( + energy_global, field->em_energy_red_global, sizeof(double[1]), GKYL_CU_MEMCPY_D2H + ); } else { energy_global[0] = field->em_energy_red_global[0]; } @@ -154,10 +163,14 @@ gk_field_calc_energy_enabled(struct gkyl_gyrokinetic_app *app, const struct gk_f gkyl_dynvec_append(field->integ_energy, tm, energy_global); if (field->info.time_rate_diagnostics) { - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, field->em_energy_red_old, field->em_energy_red_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, 1, field->em_energy_red_old, field->em_energy_red_global + ); double energy_dot_global_old[1] = {0.0}; if (app->use_gpu) { - gkyl_cu_memcpy(energy_dot_global_old, field->em_energy_red_global, sizeof(double[1]), GKYL_CU_MEMCPY_D2H); + gkyl_cu_memcpy( + energy_dot_global_old, field->em_energy_red_global, sizeof(double[1]), GKYL_CU_MEMCPY_D2H + ); } else { energy_dot_global_old[0] = field->em_energy_red_global[0]; } @@ -165,10 +178,14 @@ gk_field_calc_energy_enabled(struct gkyl_gyrokinetic_app *app, const struct gk_f energy_dot_global_old[0] *= field->es_energy_fac_1d; } - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, field->em_energy_red_new, field->em_energy_red_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, 1, field->em_energy_red_new, field->em_energy_red_global + ); double energy_dot_global_new[1] = {0.0}; if (app->use_gpu) { - gkyl_cu_memcpy(energy_dot_global_new, field->em_energy_red_global, sizeof(double[1]), GKYL_CU_MEMCPY_D2H); + gkyl_cu_memcpy( + energy_dot_global_new, field->em_energy_red_global, sizeof(double[1]), GKYL_CU_MEMCPY_D2H + ); } else { energy_dot_global_new[0] = field->em_energy_red_global[0]; } @@ -183,14 +200,14 @@ gk_field_calc_energy_enabled(struct gkyl_gyrokinetic_app *app, const struct gk_f } } -static void -gk_field_calc_energy_disabled(struct gkyl_gyrokinetic_app *app, const struct gk_field *field, double tm) +static void gk_field_calc_energy_disabled( + struct gkyl_gyrokinetic_app *app, const struct gk_field *field, double tm +) { // Do nothing. } -static void -gk_field_time_rate_diags_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) +static void gk_field_time_rate_diags_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) { f->calc_energy_dt_func = gk_field_calc_energy_dt_active; if (app->use_gpu) { @@ -208,8 +225,7 @@ gk_field_time_rate_diags_new(struct gkyl_gyrokinetic_app *app, struct gk_field * f->is_first_energy_dot_write_call = true; } -static void -gk_field_energy_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) +static void gk_field_energy_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) { // Allocate energy reduction arrays. if (app->use_gpu) { @@ -225,13 +241,14 @@ gk_field_energy_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) f->calc_energy_func = gk_field_calc_energy_enabled; f->calc_energy_dt_func = gk_field_calc_energy_dt_none; - + if (f->info.time_rate_diagnostics) { gk_field_time_rate_diags_new(app, f); } // Factors for ES energy. - f->es_energy_fac = mkarr(app->use_gpu, (2*(app->cdim/3)+1)*app->basis.num_basis, app->local_ext.volume); + f->es_energy_fac = + mkarr(app->use_gpu, (2 * (app->cdim / 3) + 1) * app->basis.num_basis, app->local_ext.volume); f->es_energy_fac_1d = 0.0; } @@ -249,8 +266,7 @@ gk_field_time_rate_diags_release(const struct gkyl_gyrokinetic_app *app, struct gkyl_dynvec_release(f->integ_energy_dot); } -static void -gk_field_energy_release(const struct gkyl_gyrokinetic_app *app, struct gk_field *f) +static void gk_field_energy_release(const struct gkyl_gyrokinetic_app *app, struct gk_field *f) { gkyl_dynvec_release(f->integ_energy); @@ -270,8 +286,7 @@ gk_field_energy_release(const struct gkyl_gyrokinetic_app *app, struct gk_field } // Initialize field object. -struct gk_field* -gk_field_new(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app) +struct gk_field *gk_field_new(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app) { struct gk_field *f = gkyl_malloc(sizeof(struct gk_field)); @@ -291,7 +306,7 @@ gk_field_new(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app) } else if (f->info.polarization_potential_import.type != GKYL_IC_IMPORT_NONE) { gk_field_polarization_potential_from_file_new(f, app, f->info.polarization_potential_import); } - + // Initialize energy diagnostics. gk_field_energy_new(app, f); @@ -314,8 +329,7 @@ gk_field_new(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app) // RHS functions for calculations -void -gk_field_rhs(gkyl_gyrokinetic_app *app, struct gk_field *field) +void gk_field_rhs(gkyl_gyrokinetic_app *app, struct gk_field *field) { // Compute the electrostatic potential. struct timespec wst = gkyl_wall_clock(); @@ -323,22 +337,23 @@ gk_field_rhs(gkyl_gyrokinetic_app *app, struct gk_field *field) app->stat.field_phi_solve_tm += gkyl_time_diff_now_sec(wst); } -void -gk_field_calc_energy(gkyl_gyrokinetic_app *app, double tm, const struct gk_field *field) +void gk_field_calc_energy(gkyl_gyrokinetic_app *app, double tm, const struct gk_field *field) { struct timespec wst = gkyl_wall_clock(); field->calc_energy_func(app, field, tm); app->stat.field_diag_calc_tm += gkyl_time_diff_now_sec(wst); } -void -gk_field_calc_energy_dt(gkyl_gyrokinetic_app *app, const struct gk_field *field, double dt, double *energy_reduced) +void gk_field_calc_energy_dt( + gkyl_gyrokinetic_app *app, const struct gk_field *field, double dt, double *energy_reduced +) { field->calc_energy_dt_func(app, field, dt, energy_reduced); } -void gk_field_accumulate_rho_c_adiabatic(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gk_species *s, struct gkyl_array **bflux) +void gk_field_accumulate_rho_c_adiabatic( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gk_species *s, struct gkyl_array **bflux +) { // Gyroaverage the density if needed. s->gyroaverage(app, s, s->m0.marr, s->m0_gyroavg); @@ -350,17 +365,19 @@ void gk_field_accumulate_rho_c_adiabatic(gkyl_gyrokinetic_app *app, struct gk_fi gkyl_array_shiftc_range(field->rho_c, q_s * n_s0 * dg_norm, 0, &app->local); } -void gk_field_accumulate_rho_c_poisson(gkyl_gyrokinetic_app *app, - struct gk_field *field, struct gk_species *s, struct gkyl_array **bflux) +void gk_field_accumulate_rho_c_poisson( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gk_species *s, struct gkyl_array **bflux +) { // Gyroaverage the density if needed. s->gyroaverage(app, s, s->m0.marr, s->m0_gyroavg); gkyl_array_accumulate_range(field->rho_c, s->info.charge, s->m0_gyroavg, &app->local); } -void -gk_field_accumulate_rho_c(gkyl_gyrokinetic_app *app, struct gk_field *field, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]) +void gk_field_accumulate_rho_c( + gkyl_gyrokinetic_app *app, struct gk_field *field, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +) { struct timespec wst = gkyl_wall_clock(); gkyl_array_clear(field->rho_c, 0.0); @@ -368,12 +385,14 @@ gk_field_accumulate_rho_c(gkyl_gyrokinetic_app *app, struct gk_field *field, struct gk_species *s = &app->species[i]; gk_species_moment_calc(&s->m0, s->local, app->local, fin[i]); field->accumulate_rhoc_func(app, field, s, bflux[i]); - } + } app->stat.field_phi_rhs_tm += gkyl_time_diff_now_sec(wst); } -void -gk_field_fem_projection_par(gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *arr_dg, struct gkyl_array *arr_fem) +void gk_field_fem_projection_par( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *arr_dg, + struct gkyl_array *arr_fem +) { // Project a DG field onto the parallel FEM basis to make it // continuous along z (or to solve a Poisson equation in 1x). @@ -389,37 +408,37 @@ gk_field_fem_projection_par(gkyl_gyrokinetic_app *app, struct gk_field *field, s gkyl_array_copy_range_to_range(arr_fem, field->phi_fem, &app->local, &field->global_sub_range); } -void -gk_field_file_import_init(struct gkyl_gyrokinetic_app *app, struct gkyl_gyrokinetic_ic_import inp) +void gk_field_file_import_init( + struct gkyl_gyrokinetic_app *app, struct gkyl_gyrokinetic_ic_import inp +) { // Import initial condition from a file. struct gkyl_app_restart_status rstat = header_from_file(app, inp.file_name); if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { struct gkyl_app_restart_status rstat; - rstat.io_status = gkyl_comm_array_read(app->comm, &app->grid, &app->local, app->field->phi_host, inp.file_name); + rstat.io_status = + gkyl_comm_array_read(app->comm, &app->grid, &app->local, app->field->phi_host, inp.file_name); gkyl_array_copy(app->field->phi_smooth, app->field->phi_host); - } - else { + } else { assert(false); } } -void -gk_field_project_init(struct gkyl_gyrokinetic_app *app) +void gk_field_project_init(struct gkyl_gyrokinetic_app *app) { // Project the initial field. - struct gkyl_eval_on_nodes *phi_proj = gkyl_eval_on_nodes_new(&app->grid, &app->basis, - 1, app->field->info.init_field_profile, app->field->info.init_field_profile_ctx); + struct gkyl_eval_on_nodes *phi_proj = gkyl_eval_on_nodes_new( + &app->grid, &app->basis, 1, app->field->info.init_field_profile, + app->field->info.init_field_profile_ctx + ); gkyl_eval_on_nodes_advance(phi_proj, 0.0, &app->local, app->field->phi_host); gkyl_eval_on_nodes_release(phi_proj); gkyl_array_copy(app->field->phi_smooth, app->field->phi_host); } - // Release resources for field. -void -gk_field_release(const gkyl_gyrokinetic_app* app, struct gk_field *f) +void gk_field_release(const gkyl_gyrokinetic_app *app, struct gk_field *f) { // Release polarization potential if used. if (f->init_phi_pol) { diff --git a/gyrokinetic/apps/gk_field_1x.c b/gyrokinetic/apps/gk_field_1x.c index 2d91e55a4e..ec90599f55 100644 --- a/gyrokinetic/apps/gk_field_1x.c +++ b/gyrokinetic/apps/gk_field_1x.c @@ -12,15 +12,13 @@ #include #include -static void -gk_field_rhs_phi_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *field) +static void gk_field_rhs_phi_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *field) { // Solve the Poisson equation in 1x with the parallel FEM projection. gk_field_fem_projection_par(app, field, field->rho_c, field->phi_smooth); } -static void -gk_field_fem_release_1x(const gkyl_gyrokinetic_app *app, struct gk_field *f) +static void gk_field_fem_release_1x(const gkyl_gyrokinetic_app *app, struct gk_field *f) { gkyl_array_release(f->rho_c); gkyl_array_release(f->rho_c_global_dg); @@ -37,14 +35,13 @@ gk_field_fem_release_1x(const gkyl_gyrokinetic_app *app, struct gk_field *f) } gkyl_array_release(f->epsilon); - + gkyl_fem_parproj_release(f->fem_parproj); gkyl_array_integrate_release(f->calc_em_energy); } -void -gk_field_fem_new_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) +void gk_field_fem_new_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) { // Create global subrange we'll copy the field solver solution from (into local). gkyl_sub_range_intersect(&f->global_sub_range, &app->global, &app->local); @@ -52,7 +49,7 @@ gk_field_fem_new_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) // Allocate arrays for charge density. f->rho_c = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); f->rho_c_global_dg = mkarr(app->use_gpu, app->basis.num_basis, app->global_ext.volume); - + // Allocate arrays for electrostatic potential. f->phi_fem = mkarr(app->use_gpu, app->basis.num_basis, app->global_ext.volume); f->phi_smooth = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); @@ -62,7 +59,7 @@ gk_field_fem_new_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) f->apar_fem = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); f->apardot_fem = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); } - + // Allocate phi_host for I/O. f->phi_host = f->phi_smooth; if (app->use_gpu) { @@ -72,14 +69,15 @@ gk_field_fem_new_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) f->rhs_phi_func = gk_field_rhs_phi_1x; // Allocate array for the polarization weight times geometric coefficients. - f->epsilon = mkarr(app->use_gpu, (2*(app->cdim/3)+1)*app->basis.num_basis, app->local_ext.volume); + f->epsilon = + mkarr(app->use_gpu, (2 * (app->cdim / 3) + 1) * app->basis.num_basis, app->local_ext.volume); double polarization_weight = 0.0; double polarization_bmag = f->info.polarization_bmag ? f->info.polarization_bmag : app->bmag_ref; // Linearized polarization density - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *s = &app->species[i]; - polarization_weight += s->info.polarization_density*s->info.mass/pow(polarization_bmag,2); + polarization_weight += s->info.polarization_density * s->info.mass / pow(polarization_bmag, 2); } // Need to set weight to kperpsq*polarizationWeight for use in potential smoothing. gkyl_array_copy(f->epsilon, app->gk_geom->geo_int.jacobgeo); @@ -93,9 +91,9 @@ gk_field_fem_new_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) double n_s0 = f->info.electron_density; double q_s = f->info.electron_charge; double T_s = f->info.electron_temp; - double quasineut_contr = q_s*n_s0*q_s/T_s; - es_energy_fac_1d_adiabatic = 0.5*quasineut_contr; - + double quasineut_contr = q_s * n_s0 * q_s / T_s; + es_energy_fac_1d_adiabatic = 0.5 * quasineut_contr; + struct gkyl_array *epsilon_adiab = mkarr(app->use_gpu, f->epsilon->ncomp, f->epsilon->size); gkyl_array_copy(epsilon_adiab, app->gk_geom->geo_int.jacobgeo); gkyl_array_scale(epsilon_adiab, quasineut_contr); @@ -106,31 +104,35 @@ gk_field_fem_new_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) } // Gather epsilon for (global) smoothing in z. - struct gkyl_array *epsilon_global = mkarr(app->use_gpu, f->epsilon->ncomp, app->global_ext.volume); + struct gkyl_array *epsilon_global = + mkarr(app->use_gpu, f->epsilon->ncomp, app->global_ext.volume); gkyl_comm_array_allgather(app->comm, &app->local, &app->global, f->epsilon, epsilon_global); // Potential smoothing (in z) updater enum gkyl_fem_parproj_bc_type fem_parproj_bc = GKYL_FEM_PARPROJ_NONE; - for (int d=0; dnum_periodic_dir; ++d) - if (app->periodic_dirs[d] == app->cdim-1) { + for (int d = 0; d < app->num_periodic_dir; ++d) { + if (app->periodic_dirs[d] == app->cdim - 1) { fem_parproj_bc = GKYL_FEM_PARPROJ_PERIODIC; } + } - f->fem_parproj = gkyl_fem_parproj_new(&app->global, &app->grid, &app->basis, - fem_parproj_bc, 0, epsilon_global, 0, app->use_gpu); + f->fem_parproj = gkyl_fem_parproj_new( + &app->global, &app->grid, &app->basis, fem_parproj_bc, 0, epsilon_global, 0, app->use_gpu + ); - f->es_energy_fac_1d = 0.5*polarization_weight*f->info.kperpSq + es_energy_fac_1d_adiabatic; + f->es_energy_fac_1d = 0.5 * polarization_weight * f->info.kperpSq + es_energy_fac_1d_adiabatic; - f->calc_em_energy = gkyl_array_integrate_new(&app->grid, &app->basis, - 1, GKYL_ARRAY_INTEGRATE_OP_SQ, app->use_gpu); + f->calc_em_energy = + gkyl_array_integrate_new(&app->grid, &app->basis, 1, GKYL_ARRAY_INTEGRATE_OP_SQ, app->use_gpu); // Create operator needed for FLR effects. f->use_flr = false; f->invert_flr = gk_field_invert_flr_none; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *s = &app->species[i]; - if (s->info.flr.type) + if (s->info.flr.type) { f->use_flr = f->use_flr || s->info.flr.type; + } } gkyl_array_release(epsilon_global); diff --git a/gyrokinetic/apps/gk_field_2x3x.c b/gyrokinetic/apps/gk_field_2x3x.c index b8cb19dcf0..7f0f51b11d 100644 --- a/gyrokinetic/apps/gk_field_2x3x.c +++ b/gyrokinetic/apps/gk_field_2x3x.c @@ -12,9 +12,10 @@ #include #include -static void -gk_field_fem_projection_par_rho_ts_2x(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gkyl_array *arr_dg, struct gkyl_array *arr_fem) +static void gk_field_fem_projection_par_rho_ts_2x( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *arr_dg, + struct gkyl_array *arr_fem +) { // Project a DG charge density onto the parallel FEM basis to make it // continuous along z using different BCs in the core and SOL. @@ -23,16 +24,19 @@ gk_field_fem_projection_par_rho_ts_2x(gkyl_gyrokinetic_app *app, struct gk_field gkyl_comm_array_allgather(app->comm, &app->local, &app->global, arr_dg, field->rho_c_global_dg); // Smooth the DG array. - gkyl_fem_parproj_set_rhs(field->fem_parproj_rho_core, field->rho_c_global_dg, field->rho_c_global_dg); + gkyl_fem_parproj_set_rhs( + field->fem_parproj_rho_core, field->rho_c_global_dg, field->rho_c_global_dg + ); gkyl_fem_parproj_solve(field->fem_parproj_rho_core, field->phi_fem); // Copy global, continuous FEM array to a local array. gkyl_array_copy_range_to_range(arr_fem, field->phi_fem, &app->local, &field->global_sub_range); } -static void -gk_field_fem_projection_par_phi_ts_2x(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gkyl_array *arr_dg, struct gkyl_array *arr_fem) +static void gk_field_fem_projection_par_phi_ts_2x( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *arr_dg, + struct gkyl_array *arr_fem +) { // Project a DG potential onto the parallel FEM basis to make it // continuous along z using different BCs in the core and SOL. @@ -41,16 +45,19 @@ gk_field_fem_projection_par_phi_ts_2x(gkyl_gyrokinetic_app *app, struct gk_field gkyl_comm_array_allgather(app->comm, &app->local, &app->global, arr_dg, field->rho_c_global_dg); // Smooth the the DG array. - gkyl_fem_parproj_set_rhs(field->fem_parproj_phi_core, field->rho_c_global_dg, field->rho_c_global_dg); + gkyl_fem_parproj_set_rhs( + field->fem_parproj_phi_core, field->rho_c_global_dg, field->rho_c_global_dg + ); gkyl_fem_parproj_solve(field->fem_parproj_phi_core, field->phi_fem); // Copy global, continuous FEM array to a local array. gkyl_array_copy_range_to_range(arr_fem, field->phi_fem, &app->local, &field->global_sub_range); } -static void -gk_field_fem_projection_par_phi_ts_3x(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gkyl_array *arr_dg, struct gkyl_array *arr_fem) +static void gk_field_fem_projection_par_phi_ts_3x( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *arr_dg, + struct gkyl_array *arr_fem +) { // Project a DG field onto the parallel FEM basis to make it // continuous along z (or to solve a Poisson equation in 1x), @@ -61,23 +68,30 @@ gk_field_fem_projection_par_phi_ts_3x(gkyl_gyrokinetic_app *app, struct gk_field // Apply TS BC in the core lower parallel boundary, and // fill core upper parallel boundary ghost with skin boundary value. - int par_dir = app->cdim-1; // Parallel direction index. - gkyl_array_copy_range_to_range(field->rho_c_global_dg, field->rho_c_global_dg, - &app->global_lower_ghost[par_dir], &app->global_upper_skin[par_dir]); + int par_dir = app->cdim - 1; // Parallel direction index. + gkyl_array_copy_range_to_range( + field->rho_c_global_dg, field->rho_c_global_dg, &app->global_lower_ghost[par_dir], + &app->global_upper_skin[par_dir] + ); gkyl_bc_twistshift_advance(field->bc_ts_lo, field->rho_c_global_dg, field->rho_c_global_dg); - gkyl_bc_basic_gyrokinetic_advance(field->gfss_bc_op_core_up, field->bc_buffer, field->rho_c_global_dg); + gkyl_bc_basic_gyrokinetic_advance( + field->gfss_bc_op_core_up, field->bc_buffer, field->rho_c_global_dg + ); // Smooth the the DG array. - gkyl_fem_parproj_set_rhs(field->fem_parproj_phi_core, field->rho_c_global_dg, field->rho_c_global_dg); + gkyl_fem_parproj_set_rhs( + field->fem_parproj_phi_core, field->rho_c_global_dg, field->rho_c_global_dg + ); gkyl_fem_parproj_solve(field->fem_parproj_phi_core, field->phi_fem); // Copy global, continuous FEM array to a local array. gkyl_array_copy_range_to_range(arr_fem, field->phi_fem, &app->local, &field->global_sub_range); } -static void -gk_field_fem_projection_par_rho_iwl_2x(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gkyl_array *arr_dg, struct gkyl_array *arr_fem) +static void gk_field_fem_projection_par_rho_iwl_2x( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *arr_dg, + struct gkyl_array *arr_fem +) { // Project a DG charge density onto the parallel FEM basis to make it // continuous along z using different BCs in the core and SOL. @@ -86,18 +100,23 @@ gk_field_fem_projection_par_rho_iwl_2x(gkyl_gyrokinetic_app *app, struct gk_fiel gkyl_comm_array_allgather(app->comm, &app->local, &app->global, arr_dg, field->rho_c_global_dg); // Smooth the DG array. - gkyl_fem_parproj_set_rhs(field->fem_parproj_rho_core, field->rho_c_global_dg, field->rho_c_global_dg); + gkyl_fem_parproj_set_rhs( + field->fem_parproj_rho_core, field->rho_c_global_dg, field->rho_c_global_dg + ); gkyl_fem_parproj_solve(field->fem_parproj_rho_core, field->phi_fem); - gkyl_fem_parproj_set_rhs(field->fem_parproj_rho_sol, field->rho_c_global_dg, field->rho_c_global_dg); + gkyl_fem_parproj_set_rhs( + field->fem_parproj_rho_sol, field->rho_c_global_dg, field->rho_c_global_dg + ); gkyl_fem_parproj_solve(field->fem_parproj_rho_sol, field->phi_fem); // Copy global, continuous FEM array to a local array. gkyl_array_copy_range_to_range(arr_fem, field->phi_fem, &app->local, &field->global_sub_range); } -static void -gk_field_fem_projection_par_phi_iwl_2x(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gkyl_array *arr_dg, struct gkyl_array *arr_fem) +static void gk_field_fem_projection_par_phi_iwl_2x( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *arr_dg, + struct gkyl_array *arr_fem +) { // Project a DG potential onto the parallel FEM basis to make it // continuous along z using different BCs in the core and SOL. @@ -106,18 +125,23 @@ gk_field_fem_projection_par_phi_iwl_2x(gkyl_gyrokinetic_app *app, struct gk_fiel gkyl_comm_array_allgather(app->comm, &app->local, &app->global, arr_dg, field->rho_c_global_dg); // Smooth the the DG array. - gkyl_fem_parproj_set_rhs(field->fem_parproj_phi_core, field->rho_c_global_dg, field->rho_c_global_dg); + gkyl_fem_parproj_set_rhs( + field->fem_parproj_phi_core, field->rho_c_global_dg, field->rho_c_global_dg + ); gkyl_fem_parproj_solve(field->fem_parproj_phi_core, field->phi_fem); - gkyl_fem_parproj_set_rhs(field->fem_parproj_phi_sol, field->rho_c_global_dg, field->rho_c_global_dg); + gkyl_fem_parproj_set_rhs( + field->fem_parproj_phi_sol, field->rho_c_global_dg, field->rho_c_global_dg + ); gkyl_fem_parproj_solve(field->fem_parproj_phi_sol, field->phi_fem); // Copy global, continuous FEM array to a local array. gkyl_array_copy_range_to_range(arr_fem, field->phi_fem, &app->local, &field->global_sub_range); } -static void -gk_field_fem_projection_par_phi_iwl_3x(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gkyl_array *arr_dg, struct gkyl_array *arr_fem) +static void gk_field_fem_projection_par_phi_iwl_3x( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *arr_dg, + struct gkyl_array *arr_fem +) { // Project a DG field onto the parallel FEM basis to make it // continuous along z (or to solve a Poisson equation in 1x), @@ -128,37 +152,47 @@ gk_field_fem_projection_par_phi_iwl_3x(gkyl_gyrokinetic_app *app, struct gk_fiel // Apply TS BC in the core lower parallel boundary, and // fill core upper parallel boundary ghost with skin boundary value. - gkyl_array_copy_range_to_range(field->rho_c_global_dg, field->rho_c_global_dg, - &app->global_lower_ghost_par_core, &app->global_upper_skin_par_core); + gkyl_array_copy_range_to_range( + field->rho_c_global_dg, field->rho_c_global_dg, &app->global_lower_ghost_par_core, + &app->global_upper_skin_par_core + ); gkyl_bc_twistshift_advance(field->bc_ts_lo, field->rho_c_global_dg, field->rho_c_global_dg); - gkyl_bc_basic_gyrokinetic_advance(field->gfss_bc_op_core_up, field->bc_buffer, field->rho_c_global_dg); + gkyl_bc_basic_gyrokinetic_advance( + field->gfss_bc_op_core_up, field->bc_buffer, field->rho_c_global_dg + ); // Smooth the the DG array. - gkyl_fem_parproj_set_rhs(field->fem_parproj_phi_core, field->rho_c_global_dg, field->rho_c_global_dg); + gkyl_fem_parproj_set_rhs( + field->fem_parproj_phi_core, field->rho_c_global_dg, field->rho_c_global_dg + ); gkyl_fem_parproj_solve(field->fem_parproj_phi_core, field->phi_fem); - gkyl_fem_parproj_set_rhs(field->fem_parproj_phi_sol, field->rho_c_global_dg, field->rho_c_global_dg); + gkyl_fem_parproj_set_rhs( + field->fem_parproj_phi_sol, field->rho_c_global_dg, field->rho_c_global_dg + ); gkyl_fem_parproj_solve(field->fem_parproj_phi_sol, field->phi_fem); // Copy global, continuous FEM array to a local array. gkyl_array_copy_range_to_range(arr_fem, field->phi_fem, &app->local, &field->global_sub_range); } -static void -gk_field_2x3x_fill_fem_parproj_bias_lines(struct gkyl_gyrokinetic_app *app, struct gk_field *f, struct gkyl_poisson_bc *poisson_bcs) +static void gk_field_2x3x_fill_fem_parproj_bias_lines( + struct gkyl_gyrokinetic_app *app, struct gk_field *f, struct gkyl_poisson_bc *poisson_bcs +) { // Create a bias line list that includes the perpendicular BCs if // they are Dirichlet, and the bias lines from the input file. - + // Create a temporary biased line list. - int par_dir = app->cdim-1; // Parallel direction index. + int par_dir = app->cdim - 1; // Parallel direction index. int num_bias_line = 0; int bl_idx = 0; int num_bias_line_in = 0; - if (f->info.bias_line_list) + if (f->info.bias_line_list) { num_bias_line_in = f->info.bias_line_list->num_bias_line; + } int num_bc_bias = 4; // Number of biases for Dirichlet BCs below. - size_t bl_sz = (num_bc_bias+num_bias_line_in) * sizeof(struct gkyl_poisson_bias_line); + size_t bl_sz = (num_bc_bias + num_bias_line_in) * sizeof(struct gkyl_poisson_bias_line); struct gkyl_poisson_bias_line *bias_lines_buff = gkyl_malloc(bl_sz); if (poisson_bcs->lo_type[0] == GKYL_POISSON_DIRICHLET) { // psi increases towards SOL. @@ -181,7 +215,7 @@ gk_field_2x3x_fill_fem_parproj_bias_lines(struct gkyl_gyrokinetic_app *app, stru bl->val = poisson_bcs->lo_value[0].v[0]; num_bias_line++; bl_idx++; - } + } if (poisson_bcs->up_type[0] == GKYL_POISSON_DIRICHLET) { // psi increases towards core. struct gkyl_poisson_bias_line *bl; @@ -203,31 +237,34 @@ gk_field_2x3x_fill_fem_parproj_bias_lines(struct gkyl_gyrokinetic_app *app, stru bl->val = poisson_bcs->up_value[0].v[0]; num_bias_line++; bl_idx++; - } - for (int i=0; iinfo.bias_line_list->bl[i]); - bl->perp_dirs[0] = bl_inp->perp_dirs[0] ; - bl->perp_dirs[1] = bl_inp->perp_dirs[1] ; + bl->perp_dirs[0] = bl_inp->perp_dirs[0]; + bl->perp_dirs[1] = bl_inp->perp_dirs[1]; bl->perp_coords[0] = bl_inp->perp_coords[0]; bl->perp_coords[1] = bl_inp->perp_coords[1]; bl->val = bl_inp->val; num_bias_line++; bl_idx++; } - + // Copy temporary bias line list into app. - bl_sz = GKYL_MAX2(1,num_bias_line) * sizeof(struct gkyl_poisson_bias_line); // max avoids allocating 0 memory. + bl_sz = GKYL_MAX2(1, num_bias_line) * + sizeof(struct gkyl_poisson_bias_line); // max avoids allocating 0 memory. f->fem_parproj_bias_line_list.num_bias_line = num_bias_line; f->fem_parproj_bias_line_list.bl = gkyl_malloc(bl_sz); - if (num_bias_line) + if (num_bias_line) { memcpy(f->fem_parproj_bias_line_list.bl, bias_lines_buff, bl_sz); + } gkyl_free(bias_lines_buff); } -static void -gk_field_2x3x_add_TS_updaters(struct gkyl_gyrokinetic_app *app, struct gk_field *f, struct gkyl_poisson_bc *poisson_bcs) +static void gk_field_2x3x_add_TS_updaters( + struct gkyl_gyrokinetic_app *app, struct gk_field *f, struct gkyl_poisson_bc *poisson_bcs +) { // Allocation ranges and updaters for TS field solve. @@ -241,8 +278,7 @@ gk_field_2x3x_add_TS_updaters(struct gkyl_gyrokinetic_app *app, struct gk_field f->fem_projection_par_rho_func = gk_field_fem_projection_par_rho_ts_2x; f->fem_projection_par_phi_func = gk_field_fem_projection_par_phi_ts_2x; - } - else if (app->cdim == 3) { + } else if (app->cdim == 3) { // Here fem_parproj_bc_rho is not actually relevant because we don't use f->fem_parproj_rho. fem_parproj_bc_rho_core = 0; fem_parproj_bc_phi_core = GKYL_FEM_PARPROJ_DIRICHLET_GHOST; @@ -250,7 +286,7 @@ gk_field_2x3x_add_TS_updaters(struct gkyl_gyrokinetic_app *app, struct gk_field f->fem_projection_par_rho_func = gk_field_fem_projection_par; f->fem_projection_par_phi_func = gk_field_fem_projection_par_phi_ts_3x; - int par_dir = app->cdim-1; // Parallel direction index. + int par_dir = app->cdim - 1; // Parallel direction index. int ghost[] = {1, 1, 1}; // TS BC updater for lower edge. struct gkyl_bc_twistshift_inp T_LU_lo = { @@ -263,12 +299,12 @@ gk_field_2x3x_add_TS_updaters(struct gkyl_gyrokinetic_app *app, struct gk_field .num_ghost = ghost, // one ghost per config direction .basis = &app->basis, .grid = &app->grid, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) + if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) { T_LU_lo.shift_dg = app->delta_ts_x_lo; - else { - T_LU_lo.shift_func = app->gk_geom->parallel_lower_bc_shift_func; + } else { + T_LU_lo.shift_func = app->gk_geom->parallel_lower_bc_shift_func; T_LU_lo.shift_func_ctx = app->gk_geom->parallel_lower_bc_shift_ctx; } f->bc_ts_lo = gkyl_bc_twistshift_inew(&T_LU_lo); @@ -284,12 +320,12 @@ gk_field_2x3x_add_TS_updaters(struct gkyl_gyrokinetic_app *app, struct gk_field .num_ghost = ghost, // one ghost per config direction .basis = &app->basis, .grid = &app->grid, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) + if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) { T_UL_up.shift_dg = app->delta_ts_x_up; - else { - T_UL_up.shift_func = app->gk_geom->parallel_upper_bc_shift_func; + } else { + T_UL_up.shift_func = app->gk_geom->parallel_upper_bc_shift_func; T_UL_up.shift_func_ctx = app->gk_geom->parallel_upper_bc_shift_ctx; } f->bc_ts_up = gkyl_bc_twistshift_inew(&T_UL_up); @@ -297,30 +333,37 @@ gk_field_2x3x_add_TS_updaters(struct gkyl_gyrokinetic_app *app, struct gk_field long buff_sz = app->global_lower_ghost[par_dir].volume; f->bc_buffer = mkarr(app->use_gpu, app->basis.num_basis, buff_sz); - f->gfss_bc_op_core_up = gkyl_bc_basic_gyrokinetic_new(par_dir, GKYL_UPPER_EDGE, GKYL_BC_GK_FIELD_BOUNDARY_VALUE, - app->basis_on_dev, &app->global_upper_skin[par_dir], &app->global_upper_ghost[par_dir], - app->basis.num_basis, app->cdim, app->use_gpu); - - f->gfss_bc_op_core_lo = gkyl_bc_basic_gyrokinetic_new(par_dir, GKYL_LOWER_EDGE, GKYL_BC_GK_FIELD_BOUNDARY_VALUE, - app->basis_on_dev, &app->global_lower_skin[par_dir], &app->global_lower_ghost[par_dir], - app->basis.num_basis, app->cdim, app->use_gpu); - + f->gfss_bc_op_core_up = gkyl_bc_basic_gyrokinetic_new( + par_dir, GKYL_UPPER_EDGE, GKYL_BC_GK_FIELD_BOUNDARY_VALUE, app->basis_on_dev, + &app->global_upper_skin[par_dir], &app->global_upper_ghost[par_dir], app->basis.num_basis, + app->cdim, app->use_gpu + ); + + f->gfss_bc_op_core_lo = gkyl_bc_basic_gyrokinetic_new( + par_dir, GKYL_LOWER_EDGE, GKYL_BC_GK_FIELD_BOUNDARY_VALUE, app->basis_on_dev, + &app->global_lower_skin[par_dir], &app->global_lower_ghost[par_dir], app->basis.num_basis, + app->cdim, app->use_gpu + ); } // Parallel smoother for the charge density. - f->fem_parproj_rho_core = gkyl_fem_parproj_new(&app->global, &app->grid, &app->basis, - fem_parproj_bc_rho_core, 0, 0, 0, app->use_gpu); + f->fem_parproj_rho_core = gkyl_fem_parproj_new( + &app->global, &app->grid, &app->basis, fem_parproj_bc_rho_core, 0, 0, 0, app->use_gpu + ); // Fill bias line list for fem_parproj_phi. gk_field_2x3x_fill_fem_parproj_bias_lines(app, f, poisson_bcs); - + // Parallel smoother for the potential. - f->fem_parproj_phi_core = gkyl_fem_parproj_new(&app->global, &app->grid, &app->basis, - fem_parproj_bc_phi_core, &f->fem_parproj_bias_line_list, 0, 0, app->use_gpu); + f->fem_parproj_phi_core = gkyl_fem_parproj_new( + &app->global, &app->grid, &app->basis, fem_parproj_bc_phi_core, &f->fem_parproj_bias_line_list, + 0, 0, app->use_gpu + ); } -static void -gk_field_2x3x_add_IWL_updaters(struct gkyl_gyrokinetic_app *app, struct gk_field *f, struct gkyl_poisson_bc *poisson_bcs) +static void gk_field_2x3x_add_IWL_updaters( + struct gkyl_gyrokinetic_app *app, struct gk_field *f, struct gkyl_poisson_bc *poisson_bcs +) { // Allocation ranges and updaters for IWL field solve. @@ -330,24 +373,23 @@ gk_field_2x3x_add_IWL_updaters(struct gkyl_gyrokinetic_app *app, struct gk_field if (app->cdim == 2) { fem_parproj_bc_rho_core = GKYL_FEM_PARPROJ_PERIODIC; - fem_parproj_bc_rho_sol = GKYL_FEM_PARPROJ_NONE; + fem_parproj_bc_rho_sol = GKYL_FEM_PARPROJ_NONE; fem_parproj_bc_phi_core = GKYL_FEM_PARPROJ_PERIODIC; - fem_parproj_bc_phi_sol = GKYL_FEM_PARPROJ_NONE; + fem_parproj_bc_phi_sol = GKYL_FEM_PARPROJ_NONE; f->fem_projection_par_rho_func = gk_field_fem_projection_par_rho_iwl_2x; f->fem_projection_par_phi_func = gk_field_fem_projection_par_phi_iwl_2x; - } - else if (app->cdim == 3) { + } else if (app->cdim == 3) { // Here fem_parproj_bc_rho is not actually relevant because we don't use f->fem_parproj_rho. fem_parproj_bc_rho_core = 0; - fem_parproj_bc_rho_sol = 0; + fem_parproj_bc_rho_sol = 0; fem_parproj_bc_phi_core = GKYL_FEM_PARPROJ_DIRICHLET_GHOST; - fem_parproj_bc_phi_sol = GKYL_FEM_PARPROJ_DIRICHLET_SKIN; + fem_parproj_bc_phi_sol = GKYL_FEM_PARPROJ_DIRICHLET_SKIN; f->fem_projection_par_rho_func = gk_field_fem_projection_par; f->fem_projection_par_phi_func = gk_field_fem_projection_par_phi_iwl_3x; - int par_dir = app->cdim-1; // Parallel direction index. + int par_dir = app->cdim - 1; // Parallel direction index. // TS BC updater for up to low TS for the lower edge. This sets ghost_L = T_LU(ghost_L). int ghost[] = {1, 1, 1}; struct gkyl_bc_twistshift_inp T_LU_lo = { @@ -360,43 +402,50 @@ gk_field_2x3x_add_IWL_updaters(struct gkyl_gyrokinetic_app *app, struct gk_field .num_ghost = ghost, // one ghost per config direction .basis = &app->basis, .grid = &app->grid, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) + if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) { T_LU_lo.shift_dg = app->delta_ts_x_lo; - else { - T_LU_lo.shift_func = app->gk_geom->parallel_lower_bc_shift_func; + } else { + T_LU_lo.shift_func = app->gk_geom->parallel_lower_bc_shift_func; T_LU_lo.shift_func_ctx = app->gk_geom->parallel_lower_bc_shift_ctx; } f->bc_ts_lo = gkyl_bc_twistshift_inew(&T_LU_lo); - long buff_sz = GKYL_MAX2(app->global_lower_ghost_par_sol.volume, app->global_lower_ghost_par_core.volume); + long buff_sz = + GKYL_MAX2(app->global_lower_ghost_par_sol.volume, app->global_lower_ghost_par_core.volume); f->bc_buffer = mkarr(app->use_gpu, app->basis.num_basis, buff_sz); - f->gfss_bc_op_core_up = gkyl_bc_basic_gyrokinetic_new(par_dir, GKYL_UPPER_EDGE, GKYL_BC_GK_FIELD_BOUNDARY_VALUE, - app->basis_on_dev, &app->global_upper_skin_par_core, &app->global_upper_ghost_par_core, - app->basis.num_basis, app->cdim, app->use_gpu); + f->gfss_bc_op_core_up = gkyl_bc_basic_gyrokinetic_new( + par_dir, GKYL_UPPER_EDGE, GKYL_BC_GK_FIELD_BOUNDARY_VALUE, app->basis_on_dev, + &app->global_upper_skin_par_core, &app->global_upper_ghost_par_core, app->basis.num_basis, + app->cdim, app->use_gpu + ); } // Parallel smoother for the charge density. - f->fem_parproj_rho_core = gkyl_fem_parproj_new(&app->global_core, &app->grid, &app->basis, - fem_parproj_bc_rho_core, 0, 0, 0, app->use_gpu); - f->fem_parproj_rho_sol = gkyl_fem_parproj_new(&app->global_sol, &app->grid, &app->basis, - fem_parproj_bc_rho_sol, 0, 0, 0, app->use_gpu); + f->fem_parproj_rho_core = gkyl_fem_parproj_new( + &app->global_core, &app->grid, &app->basis, fem_parproj_bc_rho_core, 0, 0, 0, app->use_gpu + ); + f->fem_parproj_rho_sol = gkyl_fem_parproj_new( + &app->global_sol, &app->grid, &app->basis, fem_parproj_bc_rho_sol, 0, 0, 0, app->use_gpu + ); // Fill bias line list for fem_parproj_phi. gk_field_2x3x_fill_fem_parproj_bias_lines(app, f, poisson_bcs); - + // Parallel smoother for the potential. - f->fem_parproj_phi_core = gkyl_fem_parproj_new(&app->global_core, &app->grid, &app->basis, - fem_parproj_bc_phi_core, &f->fem_parproj_bias_line_list, 0, 0, app->use_gpu); - f->fem_parproj_phi_sol = gkyl_fem_parproj_new(&app->global_sol, &app->grid, &app->basis, - fem_parproj_bc_phi_sol, &f->fem_parproj_bias_line_list, 0, 0, app->use_gpu); - + f->fem_parproj_phi_core = gkyl_fem_parproj_new( + &app->global_core, &app->grid, &app->basis, fem_parproj_bc_phi_core, + &f->fem_parproj_bias_line_list, 0, 0, app->use_gpu + ); + f->fem_parproj_phi_sol = gkyl_fem_parproj_new( + &app->global_sol, &app->grid, &app->basis, fem_parproj_bc_phi_sol, + &f->fem_parproj_bias_line_list, 0, 0, app->use_gpu + ); } -static void -gk_field_rhs_poisson_perp_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field *field) +static void gk_field_rhs_poisson_perp_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field *field) { // Smooth the charge density along z. field->fem_projection_par_rho_func(app, field, field->rho_c, field->rho_c); @@ -412,8 +461,7 @@ gk_field_rhs_poisson_perp_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field field->invert_flr(app, field, field->phi_smooth); } -static void -gk_field_fem_release_2x3x(const gkyl_gyrokinetic_app *app, struct gk_field *f) +static void gk_field_fem_release_2x3x(const gkyl_gyrokinetic_app *app, struct gk_field *f) { gkyl_array_release(f->rho_c); gkyl_array_release(f->rho_c_global_dg); @@ -436,7 +484,7 @@ gk_field_fem_release_2x3x(const gkyl_gyrokinetic_app *app, struct gk_field *f) if (f->is_dirichletvar) { gkyl_array_release(f->phi_bc); } - + gkyl_fem_parproj_release(f->fem_parproj); gkyl_array_integrate_release(f->calc_em_energy); @@ -454,8 +502,7 @@ gk_field_fem_release_2x3x(const gkyl_gyrokinetic_app *app, struct gk_field *f) gkyl_bc_basic_gyrokinetic_release(f->gfss_bc_op_core_up); gkyl_array_release(f->bc_buffer); } - } - else if (f->bc_par_phi == GKYL_BC_GK_FIELD_TWISTSHIFT) { + } else if (f->bc_par_phi == GKYL_BC_GK_FIELD_TWISTSHIFT) { // Release TS updaters. gkyl_free(f->fem_parproj_bias_line_list.bl); gkyl_fem_parproj_release(f->fem_parproj_rho_core); @@ -469,15 +516,13 @@ gk_field_fem_release_2x3x(const gkyl_gyrokinetic_app *app, struct gk_field *f) gkyl_array_release(f->bc_buffer); } } - - + if (f->use_flr) { gk_field_flr_release(app, f); } } -void -gk_field_fem_new_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) +void gk_field_fem_new_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) { // Create global subrange we'll copy the field solver solution from (into local). gkyl_sub_range_intersect(&f->global_sub_range, &app->global, &app->local); @@ -512,60 +557,71 @@ gk_field_fem_new_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) double polarization_weight = 0.0; double polarization_bmag = f->info.polarization_bmag ? f->info.polarization_bmag : app->bmag_ref; // Linearized polarization density - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *s = &app->species[i]; - polarization_weight += s->info.polarization_density*s->info.mass/pow(polarization_bmag,2); + polarization_weight += s->info.polarization_density * s->info.mass / pow(polarization_bmag, 2); } // Allocate array for the polarization weight times geometric coefficients. - f->epsilon = mkarr(app->use_gpu, (2*(app->cdim/3)+1)*app->basis.num_basis, app->local_ext.volume); - + f->epsilon = + mkarr(app->use_gpu, (2 * (app->cdim / 3) + 1) * app->basis.num_basis, app->local_ext.volume); + // Initialize the polarization weight. - struct gkyl_array *Jgij[3] = {app->gk_geom->geo_int.gxxj, app->gk_geom->geo_int.gxyj, app->gk_geom->geo_int.gyyj}; - for (int i=0; icdim-2/app->cdim; i++) { - gkyl_array_set_offset(f->epsilon, polarization_weight, Jgij[i], i*app->basis.num_basis); + struct gkyl_array *Jgij[3] = { + app->gk_geom->geo_int.gxxj, app->gk_geom->geo_int.gxyj, app->gk_geom->geo_int.gyyj + }; + for (int i = 0; i < app->cdim - 2 / app->cdim; i++) { + gkyl_array_set_offset(f->epsilon, polarization_weight, Jgij[i], i * app->basis.num_basis); } bool bc_is_np[GKYL_MAX_CDIM]; // Is the BC in this direction non-periodic? - for (int d=0; dcdim; ++d) bc_is_np[d] = true; - for (int d=0; dnum_periodic_dir; ++d) { + for (int d = 0; d < app->cdim; ++d) { + bc_is_np[d] = true; + } + for (int d = 0; d < app->num_periodic_dir; ++d) { bc_is_np[app->periodic_dirs[d]] = false; } // Translate input file BCs into Poisson BCs. - struct gkyl_poisson_bc poisson_bcs = { }; - for (int d=0; dcdim-1; d++) { + struct gkyl_poisson_bc poisson_bcs = {}; + for (int d = 0; d < app->cdim - 1; d++) { if (bc_is_np[d]) { - struct gkyl_gyrokinetic_bc *bc_lo = gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2*app->cdim, d, GKYL_LOWER_EDGE); + struct gkyl_gyrokinetic_bc *bc_lo = + gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2 * app->cdim, d, GKYL_LOWER_EDGE); if (bc_lo != 0) { poisson_bcs.lo_type[d] = gkyl_gyrokinetic_translate_poisson_bc_type(bc_lo->type); - for (int i=0; i<3; i++) { + for (int i = 0; i < 3; i++) { poisson_bcs.lo_value[d].v[i] = bc_lo->value[i]; } } - struct gkyl_gyrokinetic_bc *bc_up = gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2*app->cdim, d, GKYL_UPPER_EDGE); + struct gkyl_gyrokinetic_bc *bc_up = + gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2 * app->cdim, d, GKYL_UPPER_EDGE); if (bc_up != 0) { poisson_bcs.up_type[d] = gkyl_gyrokinetic_translate_poisson_bc_type(bc_up->type); - for (int i=0; i<3; i++) { + for (int i = 0; i < 3; i++) { poisson_bcs.up_value[d].v[i] = bc_up->value[i]; } } } else { - poisson_bcs.lo_type[d] = gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_PERIODIC); - poisson_bcs.up_type[d] = gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_PERIODIC); + poisson_bcs.lo_type[d] = + gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_PERIODIC); + poisson_bcs.up_type[d] = + gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_PERIODIC); } } // Initialize the Poisson solver. - f->fem_poisson_perp = gkyl_fem_poisson_perp_new(&app->local, &app->grid, app->basis, - &poisson_bcs, f->info.bias_line_list, f->epsilon, NULL, app->use_gpu); + f->fem_poisson_perp = gkyl_fem_poisson_perp_new( + &app->local, &app->grid, app->basis, &poisson_bcs, f->info.bias_line_list, f->epsilon, NULL, + app->use_gpu + ); f->phi_bc = 0; f->is_dirichletvar = false; - for (int i=0; i<2*app->cdim; i++) { + for (int i = 0; i < 2 * app->cdim; i++) { f->is_dirichletvar = f->is_dirichletvar || - (f->info.poisson_bcs[i].type == GKYL_BC_GK_FIELD_DIRICHLET_VARYING || - f->info.poisson_bcs[i].type == GKYL_BC_GK_FIELD_DIRICHLET_VARYING); + (f->info.poisson_bcs[i].type == GKYL_BC_GK_FIELD_DIRICHLET_VARYING || + f->info.poisson_bcs[i].type == GKYL_BC_GK_FIELD_DIRICHLET_VARYING); } if (f->is_dirichletvar) { @@ -573,21 +629,23 @@ gk_field_fem_new_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) f->phi_bc = mkarr(app->use_gpu, app->basis.num_basis, app->global_ext.volume); struct gkyl_array *phi_bc_ho = mkarr(false, f->phi_bc->ncomp, f->phi_bc->size); - for (int d=0; dcdim; d++) { - struct gkyl_gyrokinetic_bc *bc_lo = gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2*app->cdim, d, GKYL_LOWER_EDGE); + for (int d = 0; d < app->cdim; d++) { + struct gkyl_gyrokinetic_bc *bc_lo = + gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2 * app->cdim, d, GKYL_LOWER_EDGE); if (bc_lo != 0) { if (bc_lo->type == GKYL_BC_GK_FIELD_DIRICHLET_VARYING) { - gkyl_eval_on_nodes *phibc_proj = gkyl_eval_on_nodes_new(&app->grid, &app->basis, - 1, bc_lo->aux_profile, bc_lo->aux_ctx); + gkyl_eval_on_nodes *phibc_proj = + gkyl_eval_on_nodes_new(&app->grid, &app->basis, 1, bc_lo->aux_profile, bc_lo->aux_ctx); gkyl_eval_on_nodes_advance(phibc_proj, 0.0, &app->local_lower_skin[d], phi_bc_ho); gkyl_eval_on_nodes_release(phibc_proj); } } - struct gkyl_gyrokinetic_bc *bc_up = gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2*app->cdim, d, GKYL_UPPER_EDGE); + struct gkyl_gyrokinetic_bc *bc_up = + gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2 * app->cdim, d, GKYL_UPPER_EDGE); if (bc_up != 0) { if (bc_up->type == GKYL_BC_GK_FIELD_DIRICHLET_VARYING) { - gkyl_eval_on_nodes *phibc_proj = gkyl_eval_on_nodes_new(&app->grid, &app->basis, - 1, bc_up->aux_profile, bc_up->aux_ctx); + gkyl_eval_on_nodes *phibc_proj = + gkyl_eval_on_nodes_new(&app->grid, &app->basis, 1, bc_up->aux_profile, bc_up->aux_ctx); gkyl_eval_on_nodes_advance(phibc_proj, 0.0, &app->local_lower_skin[d], phi_bc_ho); gkyl_eval_on_nodes_release(phibc_proj); } @@ -599,24 +657,29 @@ gk_field_fem_new_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) // Potential smoothing (in z) updater enum gkyl_fem_parproj_bc_type fem_parproj_bc = GKYL_FEM_PARPROJ_NONE; - for (int d=0; dnum_periodic_dir; ++d) - if (app->periodic_dirs[d] == app->cdim-1) fem_parproj_bc = GKYL_FEM_PARPROJ_PERIODIC; + for (int d = 0; d < app->num_periodic_dir; ++d) { + if (app->periodic_dirs[d] == app->cdim - 1) { + fem_parproj_bc = GKYL_FEM_PARPROJ_PERIODIC; + } + } - f->fem_parproj = gkyl_fem_parproj_new(&app->global, &app->grid, &app->basis, - fem_parproj_bc, 0, 0, 0, app->use_gpu); + f->fem_parproj = gkyl_fem_parproj_new( + &app->global, &app->grid, &app->basis, fem_parproj_bc, 0, 0, 0, app->use_gpu + ); f->fem_projection_par_rho_func = gk_field_fem_projection_par; f->fem_projection_par_phi_func = gk_field_fem_projection_par; // Updater for field energy calculation. gkyl_array_set(f->es_energy_fac, 0.5, f->epsilon); - f->calc_em_energy = gkyl_array_integrate_new(&app->grid, &app->basis, - 1, GKYL_ARRAY_INTEGRATE_OP_EPS_GRADPERP_SQ, app->use_gpu); + f->calc_em_energy = gkyl_array_integrate_new( + &app->grid, &app->basis, 1, GKYL_ARRAY_INTEGRATE_OP_EPS_GRADPERP_SQ, app->use_gpu + ); // Create operator needed for FLR effects. f->use_flr = false; f->invert_flr = gk_field_invert_flr_none; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *s = &app->species[i]; if (s->info.flr.type) { f->use_flr = f->use_flr || s->info.flr.type; @@ -628,23 +691,24 @@ gk_field_fem_new_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field *f) f->bc_par_phi = 0; // Deterime if we need IWL or TWISTSHIFT BCs on phi fro the species BCs. - for (int s=0; snum_species; s++) { + for (int s = 0; s < app->num_species; s++) { struct gk_species *gks = &app->species[s]; - for (int i = 0; i < 2*app->cdim; i++) { - if ( gks->info.bcs[i].dir == app->cdim-1 && gks->info.bcs[i].type == GKYL_BC_GK_SPECIES_TWISTSHIFT ) { + for (int i = 0; i < 2 * app->cdim; i++) { + if (gks->info.bcs[i].dir == app->cdim - 1 && + gks->info.bcs[i].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) { f->bc_par_phi = GKYL_BC_GK_FIELD_TWISTSHIFT; break; } } - if (f->bc_par_phi) + if (f->bc_par_phi) { break; + } } if (app->gk_geom->has_LCFS) { // Updaters to enforce twist-and-shift and sheath BCs. gk_field_2x3x_add_IWL_updaters(app, f, &poisson_bcs); - } - else if (f->bc_par_phi == GKYL_BC_GK_FIELD_TWISTSHIFT) { + } else if (f->bc_par_phi == GKYL_BC_GK_FIELD_TWISTSHIFT) { // Updaters to enforce twist-and-shift BCs. gk_field_2x3x_add_TS_updaters(app, f, &poisson_bcs); } diff --git a/gyrokinetic/apps/gk_field_biased_wall.c b/gyrokinetic/apps/gk_field_biased_wall.c index 3658b29a71..06828fd8fd 100644 --- a/gyrokinetic/apps/gk_field_biased_wall.c +++ b/gyrokinetic/apps/gk_field_biased_wall.c @@ -3,14 +3,12 @@ #include #include -void -gk_field_biased_wall_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) +void gk_field_biased_wall_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) { f->phi_wall_lo = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); f->has_phi_wall_lo = false; f->phi_wall_lo_evolve = false; - if (f->info.phi_wall_lo) - { + if (f->info.phi_wall_lo) { f->has_phi_wall_lo = true; if (f->info.phi_wall_lo_evolve) { f->phi_wall_lo_evolve = f->info.phi_wall_lo_evolve; @@ -21,8 +19,9 @@ gk_field_biased_wall_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) f->phi_wall_lo_host = mkarr(false, f->phi_wall_lo->ncomp, f->phi_wall_lo->size); } - f->phi_wall_lo_proj = gkyl_eval_on_nodes_new(&app->grid, &app->basis, - 1, f->info.phi_wall_lo, f->info.phi_wall_lo_ctx); + f->phi_wall_lo_proj = gkyl_eval_on_nodes_new( + &app->grid, &app->basis, 1, f->info.phi_wall_lo, f->info.phi_wall_lo_ctx + ); // Compute phi_wall_lo at t = 0 gkyl_eval_on_nodes_advance(f->phi_wall_lo_proj, 0.0, &app->local_ext, f->phi_wall_lo_host); @@ -35,8 +34,7 @@ gk_field_biased_wall_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) f->phi_wall_up = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); f->has_phi_wall_up = false; f->phi_wall_up_evolve = false; - if (f->info.phi_wall_up) - { + if (f->info.phi_wall_up) { f->has_phi_wall_up = true; if (f->info.phi_wall_up_evolve) { f->phi_wall_up_evolve = f->info.phi_wall_up_evolve; @@ -47,8 +45,9 @@ gk_field_biased_wall_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) f->phi_wall_up_host = mkarr(false, f->phi_wall_up->ncomp, f->phi_wall_up->size); } - f->phi_wall_up_proj = gkyl_eval_on_nodes_new(&app->grid, &app->basis, - 1, f->info.phi_wall_up, f->info.phi_wall_up_ctx); + f->phi_wall_up_proj = gkyl_eval_on_nodes_new( + &app->grid, &app->basis, 1, f->info.phi_wall_up, f->info.phi_wall_up_ctx + ); // Compute phi_wall_up at t = 0. gkyl_eval_on_nodes_advance(f->phi_wall_up_proj, 0.0, &app->local_ext, f->phi_wall_up_host); @@ -58,25 +57,27 @@ gk_field_biased_wall_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) } } -void -gk_field_calc_phi_wall(gkyl_gyrokinetic_app *app, struct gk_field *field, double tm) +void gk_field_calc_phi_wall(gkyl_gyrokinetic_app *app, struct gk_field *field, double tm) { if (field->has_phi_wall_lo && field->phi_wall_lo_evolve) { - gkyl_eval_on_nodes_advance(field->phi_wall_lo_proj, tm, &app->local_ext, field->phi_wall_lo_host); + gkyl_eval_on_nodes_advance( + field->phi_wall_lo_proj, tm, &app->local_ext, field->phi_wall_lo_host + ); if (app->use_gpu) { gkyl_array_copy(field->phi_wall_lo, field->phi_wall_lo_host); } } if (field->has_phi_wall_up && field->phi_wall_up_evolve) { - gkyl_eval_on_nodes_advance(field->phi_wall_up_proj, tm, &app->local_ext, field->phi_wall_up_host); + gkyl_eval_on_nodes_advance( + field->phi_wall_up_proj, tm, &app->local_ext, field->phi_wall_up_host + ); if (app->use_gpu) { gkyl_array_copy(field->phi_wall_up, field->phi_wall_up_host); } } } -void -gk_field_biased_wall_release(const struct gkyl_gyrokinetic_app *app, struct gk_field *f) +void gk_field_biased_wall_release(const struct gkyl_gyrokinetic_app *app, struct gk_field *f) { gkyl_array_release(f->phi_wall_lo); if (f->has_phi_wall_lo) { @@ -87,7 +88,7 @@ gk_field_biased_wall_release(const struct gkyl_gyrokinetic_app *app, struct gk_f } gkyl_array_release(f->phi_wall_up); - if (f->has_phi_wall_up) { + if (f->has_phi_wall_up) { gkyl_eval_on_nodes_release(f->phi_wall_up_proj); if (app->use_gpu) { gkyl_array_release(f->phi_wall_up_host); diff --git a/gyrokinetic/apps/gk_field_boltzmann.c b/gyrokinetic/apps/gk_field_boltzmann.c index e4b4a9637b..63a663eb4f 100644 --- a/gyrokinetic/apps/gk_field_boltzmann.c +++ b/gyrokinetic/apps/gk_field_boltzmann.c @@ -12,79 +12,95 @@ #include #include -static void gk_field_accumulate_rho_c_boltzmann(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gk_species *s, struct gkyl_array **bflux) +static void gk_field_accumulate_rho_c_boltzmann( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gk_species *s, struct gkyl_array **bflux +) { if (s->info.charge > 0.0) { // For Boltzmann electrons, we only need ion density (and the ion density // times the conf-space Jacobian), not charge density. // Rescale moment by inverse of Jacobian. - gkyl_dg_div_op_range(s->m0.mem_geo, &app->basis, 0, field->rho_c, 0, s->m0.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + s->m0.mem_geo, &app->basis, 0, field->rho_c, 0, s->m0.marr, 0, app->gk_geom->geo_int.jacobgeo, + &app->local + ); // We also need the M0 flux of the boundary flux through the z // boundaries. Put it in the ghost cells of s->m0.marr. - gk_species_bflux_get_flux_mom(&s->bflux, app->cdim-1, GKYL_LOWER_EDGE, - GKYL_F_MOMENT_M0, bflux, s->m0.marr, &app->local_lower_ghost[app->cdim-1]); - gk_species_bflux_get_flux_mom(&s->bflux, app->cdim-1, GKYL_UPPER_EDGE, - GKYL_F_MOMENT_M0, bflux, s->m0.marr, &app->local_upper_ghost[app->cdim-1]); + gk_species_bflux_get_flux_mom( + &s->bflux, app->cdim - 1, GKYL_LOWER_EDGE, GKYL_F_MOMENT_M0, bflux, s->m0.marr, + &app->local_lower_ghost[app->cdim - 1] + ); + gk_species_bflux_get_flux_mom( + &s->bflux, app->cdim - 1, GKYL_UPPER_EDGE, GKYL_F_MOMENT_M0, bflux, s->m0.marr, + &app->local_upper_ghost[app->cdim - 1] + ); } } -static void -gk_field_calc_ambi_pot_sheath_vals(gkyl_gyrokinetic_app *app, struct gk_field *field) +static void gk_field_calc_ambi_pot_sheath_vals(gkyl_gyrokinetic_app *app, struct gk_field *field) { // Note that the M0 moment of boundary fluxes along z should // be stored in the ghost cells of m0.marr at this point. - int idx_par = app->cdim-1; - int off = 2*idx_par; + int idx_par = app->cdim - 1; + int off = 2 * idx_par; int comm_sz; gkyl_comm_get_size(app->comm, &comm_sz); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *s = &app->species[i]; if (s->info.charge > 0.0) { // Assumes symmetric sheath BCs for now only in 1D // NOTE: this relies on the accumulate_rho_c calling gk_species_moment_calc(s->m0) // to calculate the particle flux and place it in the ghost cells of s->m0.marr. - gkyl_ambi_bolt_potential_sheath_calc(field->ambi_pot, GKYL_LOWER_EDGE, - &app->local_lower_skin[idx_par], &app->local_lower_ghost[idx_par], app->gk_geom->geo_int.cmag, - app->gk_geom->geo_int.jacobtot_inv, s->m0.marr, field->rho_c, s->m0.marr, field->sheath_vals[off]); - gkyl_ambi_bolt_potential_sheath_calc(field->ambi_pot, GKYL_UPPER_EDGE, - &app->local_upper_skin[idx_par], &app->local_upper_ghost[idx_par], app->gk_geom->geo_int.cmag, - app->gk_geom->geo_int.jacobtot_inv, s->m0.marr, field->rho_c, s->m0.marr, field->sheath_vals[off+1]); + gkyl_ambi_bolt_potential_sheath_calc( + field->ambi_pot, GKYL_LOWER_EDGE, &app->local_lower_skin[idx_par], + &app->local_lower_ghost[idx_par], app->gk_geom->geo_int.cmag, + app->gk_geom->geo_int.jacobtot_inv, s->m0.marr, field->rho_c, s->m0.marr, + field->sheath_vals[off] + ); + gkyl_ambi_bolt_potential_sheath_calc( + field->ambi_pot, GKYL_UPPER_EDGE, &app->local_upper_skin[idx_par], + &app->local_upper_ghost[idx_par], app->gk_geom->geo_int.cmag, + app->gk_geom->geo_int.jacobtot_inv, s->m0.marr, field->rho_c, s->m0.marr, + field->sheath_vals[off + 1] + ); // Broadcast the sheath values from skin processes to other processes. - gkyl_comm_array_bcast(app->comm, field->sheath_vals[off] , field->sheath_vals[off], 0); - gkyl_comm_array_bcast(app->comm, field->sheath_vals[off+1], field->sheath_vals[off+1], comm_sz-1); + gkyl_comm_array_bcast(app->comm, field->sheath_vals[off], field->sheath_vals[off], 0); + gkyl_comm_array_bcast( + app->comm, field->sheath_vals[off + 1], field->sheath_vals[off + 1], comm_sz - 1 + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - gkyl_array_copy_range_to_range(field->sheath_vals[off+1], field->sheath_vals[off+1], - &app->local_lower_ghost[idx_par], &app->local_upper_ghost[idx_par]); - gkyl_array_accumulate(field->sheath_vals[off], 1., field->sheath_vals[off+1]); + gkyl_array_copy_range_to_range( + field->sheath_vals[off + 1], field->sheath_vals[off + 1], &app->local_lower_ghost[idx_par], + &app->local_upper_ghost[idx_par] + ); + gkyl_array_accumulate(field->sheath_vals[off], 1., field->sheath_vals[off + 1]); gkyl_array_scale(field->sheath_vals[off], 0.5); } } } -static void -gk_field_rhs_boltzmann(struct gkyl_gyrokinetic_app *app, struct gk_field *field) +static void gk_field_rhs_boltzmann(struct gkyl_gyrokinetic_app *app, struct gk_field *field) { // Compute sheath density n_i,s and potential phi_s = (Te/e)*ln(n_i,s*v_te/(sqrt(2*pi)*Gamma_i)). gk_field_calc_ambi_pot_sheath_vals(app, app->field); // Solve phi = phi_s + (Te/e)*ln(n_i/n_i,s). - gkyl_ambi_bolt_potential_phi_calc(field->ambi_pot, &app->local, &app->local_ext, - field->rho_c, field->sheath_vals[2*(app->cdim-1)], field->phi_smooth); + gkyl_ambi_bolt_potential_phi_calc( + field->ambi_pot, &app->local, &app->local_ext, field->rho_c, + field->sheath_vals[2 * (app->cdim - 1)], field->phi_smooth + ); // Smooth the potential along z. gk_field_fem_projection_par(app, field, field->phi_smooth, field->phi_smooth); } -static void -gk_field_fem_release_boltzmann(const gkyl_gyrokinetic_app *app, struct gk_field *f) +static void gk_field_fem_release_boltzmann(const gkyl_gyrokinetic_app *app, struct gk_field *f) { gkyl_array_release(f->rho_c); gkyl_array_release(f->rho_c_global_dg); @@ -96,15 +112,14 @@ gk_field_fem_release_boltzmann(const gkyl_gyrokinetic_app *app, struct gk_field } gkyl_ambi_bolt_potential_release(f->ambi_pot); - for (int i = 0; i < 2*app->cdim; ++i) { + for (int i = 0; i < 2 * app->cdim; ++i) { gkyl_array_release(f->sheath_vals[i]); } gkyl_fem_parproj_release(f->fem_parproj); gkyl_array_integrate_release(f->calc_em_energy); } -void -gk_field_fem_new_boltzmann(struct gkyl_gyrokinetic_app *app, struct gk_field *f) +void gk_field_fem_new_boltzmann(struct gkyl_gyrokinetic_app *app, struct gk_field *f) { // Create global subrange we'll copy the field solver solution from (into local). gkyl_sub_range_intersect(&f->global_sub_range, &app->global, &app->local); @@ -127,38 +142,44 @@ gk_field_fem_new_boltzmann(struct gkyl_gyrokinetic_app *app, struct gk_field *f) f->rhs_phi_func = gk_field_rhs_boltzmann; f->accumulate_rhoc_func = gk_field_accumulate_rho_c_boltzmann; - f->ambi_pot = gkyl_ambi_bolt_potential_new(&app->grid, &app->basis, - f->info.electron_mass, f->info.electron_charge, f->info.electron_temp, app->use_gpu); - + f->ambi_pot = gkyl_ambi_bolt_potential_new( + &app->grid, &app->basis, f->info.electron_mass, f->info.electron_charge, f->info.electron_temp, + app->use_gpu + ); + // Sheath_vals contains both the density and potential sheath values. - for (int j=0; jcdim; ++j) { - f->sheath_vals[2*j] = mkarr(app->use_gpu, 2*app->basis.num_basis, app->local_ext.volume); - f->sheath_vals[2*j+1] = mkarr(app->use_gpu, 2*app->basis.num_basis, app->local_ext.volume); + for (int j = 0; j < app->cdim; ++j) { + f->sheath_vals[2 * j] = mkarr(app->use_gpu, 2 * app->basis.num_basis, app->local_ext.volume); + f->sheath_vals[2 * j + 1] = + mkarr(app->use_gpu, 2 * app->basis.num_basis, app->local_ext.volume); } enum gkyl_fem_parproj_bc_type fem_parproj_bc = GKYL_FEM_PARPROJ_NONE; - for (int d=0; dnum_periodic_dir; ++d) { - if (app->periodic_dirs[d] == app->cdim-1) { + for (int d = 0; d < app->num_periodic_dir; ++d) { + if (app->periodic_dirs[d] == app->cdim - 1) { fem_parproj_bc = GKYL_FEM_PARPROJ_PERIODIC; } } - f->fem_parproj = gkyl_fem_parproj_new(&app->global, &app->grid, &app->basis, - fem_parproj_bc, 0, 0, 0, app->use_gpu); + f->fem_parproj = gkyl_fem_parproj_new( + &app->global, &app->grid, &app->basis, fem_parproj_bc, 0, 0, 0, app->use_gpu + ); if (app->cdim == 1) { f->es_energy_fac_1d = polarization_weight; - f->calc_em_energy = gkyl_array_integrate_new(&app->grid, &app->basis, - 1, GKYL_ARRAY_INTEGRATE_OP_SQ, app->use_gpu); + f->calc_em_energy = gkyl_array_integrate_new( + &app->grid, &app->basis, 1, GKYL_ARRAY_INTEGRATE_OP_SQ, app->use_gpu + ); } else { - f->calc_em_energy = gkyl_array_integrate_new(&app->grid, &app->basis, - 1, GKYL_ARRAY_INTEGRATE_OP_EPS_GRADPERP_SQ, app->use_gpu); + f->calc_em_energy = gkyl_array_integrate_new( + &app->grid, &app->basis, 1, GKYL_ARRAY_INTEGRATE_OP_EPS_GRADPERP_SQ, app->use_gpu + ); } // Create operator needed for FLR effects. f->use_flr = false; f->invert_flr = gk_field_invert_flr_none; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *s = &app->species[i]; if (s->info.flr.type) { f->use_flr = f->use_flr || s->info.flr.type; diff --git a/gyrokinetic/apps/gk_field_flr.c b/gyrokinetic/apps/gk_field_flr.c index 10c068fb05..a9f7c66fdd 100644 --- a/gyrokinetic/apps/gk_field_flr.c +++ b/gyrokinetic/apps/gk_field_flr.c @@ -6,24 +6,30 @@ #include #include -void -gk_field_flr_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) +void gk_field_flr_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) { assert(app->cdim > 1); f->invert_flr = gk_field_invert_flr; double flr_weight = 0.0; - for (int i = 0; i < app->num_species; ++i){ + for (int i = 0; i < app->num_species; ++i) { struct gk_species *s = &app->species[i]; double gyroradius_bmag = s->info.flr.bmag ? s->info.flr.bmag : app->bmag_ref; flr_weight += s->info.flr.Tperp * s->info.mass / (pow(s->info.charge * gyroradius_bmag, 2.0)); } // Initialize the weight in the Laplacian operator. - f->flr_rhoSq_sum = mkarr(app->use_gpu, (2 * (app->cdim - 1) - 1) * app->basis.num_basis, app->local_ext.volume); - gkyl_array_set_offset(f->flr_rhoSq_sum, flr_weight, app->gk_geom->geo_int.gxxj, 0 * app->basis.num_basis); + f->flr_rhoSq_sum = + mkarr(app->use_gpu, (2 * (app->cdim - 1) - 1) * app->basis.num_basis, app->local_ext.volume); + gkyl_array_set_offset( + f->flr_rhoSq_sum, flr_weight, app->gk_geom->geo_int.gxxj, 0 * app->basis.num_basis + ); if (app->cdim > 2) { - gkyl_array_set_offset(f->flr_rhoSq_sum, flr_weight, app->gk_geom->geo_int.gxyj, 1 * app->basis.num_basis); - gkyl_array_set_offset(f->flr_rhoSq_sum, flr_weight, app->gk_geom->geo_int.gyyj, 2 * app->basis.num_basis); + gkyl_array_set_offset( + f->flr_rhoSq_sum, flr_weight, app->gk_geom->geo_int.gxyj, 1 * app->basis.num_basis + ); + gkyl_array_set_offset( + f->flr_rhoSq_sum, flr_weight, app->gk_geom->geo_int.gyyj, 2 * app->basis.num_basis + ); } // Initialize the factor multiplying the field in the FLR operator. f->flr_kSq = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); @@ -42,14 +48,18 @@ gk_field_flr_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) for (int d = 0; d < app->cdim - 1; d++) { if (bc_is_np[d]) { - struct gkyl_gyrokinetic_bc *bc_lo = gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2 * app->cdim, d, GKYL_LOWER_EDGE); + struct gkyl_gyrokinetic_bc *bc_lo = + gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2 * app->cdim, d, GKYL_LOWER_EDGE); if (bc_lo != 0) { - flr_bc.lo_type[d] = gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_DIRICHLET_VARYING); + flr_bc.lo_type[d] = + gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_DIRICHLET_VARYING); } - struct gkyl_gyrokinetic_bc *bc_up = gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2 * app->cdim, d, GKYL_UPPER_EDGE); + struct gkyl_gyrokinetic_bc *bc_up = + gk_fetch_bc_with_dir_edge(f->info.poisson_bcs, 2 * app->cdim, d, GKYL_UPPER_EDGE); if (bc_up != 0) { - flr_bc.up_type[d] = gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_DIRICHLET_VARYING); + flr_bc.up_type[d] = + gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_DIRICHLET_VARYING); } } else { flr_bc.lo_type[d] = gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_PERIODIC); @@ -57,23 +67,24 @@ gk_field_flr_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f) } } // Deflated Poisson solve is performed on range assuming decomposition is *only* in z. - f->flr_op = gkyl_deflated_fem_poisson_new(app->grid, app->basis_on_dev, app->basis, - app->local, app->local, f->flr_rhoSq_sum, f->flr_kSq, flr_bc, NULL, app->use_gpu); + f->flr_op = gkyl_deflated_fem_poisson_new( + app->grid, app->basis_on_dev, app->basis, app->local, app->local, f->flr_rhoSq_sum, f->flr_kSq, + flr_bc, NULL, app->use_gpu + ); } -void -gk_field_invert_flr(gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *phi) +void gk_field_invert_flr(gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *phi) { gkyl_deflated_fem_poisson_advance(field->flr_op, phi, phi, phi); } -void -gk_field_invert_flr_none(gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *phi) +void gk_field_invert_flr_none( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *phi +) { } -void -gk_field_flr_release(const struct gkyl_gyrokinetic_app *app, struct gk_field *f) +void gk_field_flr_release(const struct gkyl_gyrokinetic_app *app, struct gk_field *f) { gkyl_array_release(f->flr_rhoSq_sum); gkyl_array_release(f->flr_kSq); diff --git a/gyrokinetic/apps/gk_multib_field.c b/gyrokinetic/apps/gk_multib_field.c index 384da3fd15..b881e1960b 100644 --- a/gyrokinetic/apps/gk_multib_field.c +++ b/gyrokinetic/apps/gk_multib_field.c @@ -11,40 +11,47 @@ #include // compute total number of ranges specified by cuts -static inline int -calc_cuts(int ndim, const int *cuts) +static inline int calc_cuts(int ndim, const int *cuts) { int tc = 1; - for (int d=0; dvolume); - else + } else { arr[i] = gkyl_array_new(GKYL_DOUBLE, nc, ranges[i]->volume); + } } return arr; } -static int** -gk_multib_field_new_connected_list(struct gkyl_gyrokinetic_multib_app *mbapp, int dir, int *nconnected) +static int **gk_multib_field_new_connected_list( + struct gkyl_gyrokinetic_multib_app *mbapp, int dir, int *nconnected +) { // Obtain a list of blocks connected along the specified direction. int num_blocks = mbapp->block_topo->num_blocks; - int **block_list = gkyl_malloc(num_blocks*sizeof(int*)); - for (int bidx=0; bidxblock_topo, bidx, dir, 0, GKYL_CONN_ALL); - block_list[bidx] = gkyl_malloc(nconnected[bidx]*sizeof(int)); - gkyl_multib_conn_get_connection(mbapp->block_topo, bidx, dir, 0, GKYL_CONN_ALL, block_list[bidx]); + int **block_list = gkyl_malloc(num_blocks * sizeof(int *)); + for (int bidx = 0; bidx < num_blocks; ++bidx) { + nconnected[bidx] = + gkyl_multib_conn_get_num_connected(mbapp->block_topo, bidx, dir, 0, GKYL_CONN_ALL); + block_list[bidx] = gkyl_malloc(nconnected[bidx] * sizeof(int)); + gkyl_multib_conn_get_connection( + mbapp->block_topo, bidx, dir, 0, GKYL_CONN_ALL, block_list[bidx] + ); } return block_list; @@ -55,14 +62,16 @@ gk_multib_field_release_connected_list(struct gkyl_gyrokinetic_multib_app *mbapp { // Release the list of connected blocks. int num_blocks = mbapp->block_topo->num_blocks; - for (int bidx=0; bidxlocal_blocks; - for (int bI= 0; bInum_local_blocks; bI++) { + for (int bI = 0; bI < mbf->num_local_blocks; bI++) { int bid = local_blocks[bI]; multibz_ranges[bI] = gkyl_malloc(sizeof(struct gkyl_range)); multibz_ranges_ext[bI] = gkyl_malloc(sizeof(struct gkyl_range)); - gkyl_multib_comm_conn_create_multib_ranges_in_dir(multibz_ranges_ext[bI], - multibz_ranges[bI], nghost, nconnected[bid], block_list[bid], dir, mbapp->decomp); + gkyl_multib_comm_conn_create_multib_ranges_in_dir( + multibz_ranges_ext[bI], multibz_ranges[bI], nghost, nconnected[bid], block_list[bid], dir, + mbapp->decomp + ); } gk_multib_field_release_connected_list(mbapp, block_list); } -static void -gk_multib_field_new_allgather_comm_conns(struct gk_multib_field *mbf, struct gkyl_gyrokinetic_multib_app *mbapp, int dir, +static void gk_multib_field_new_allgather_comm_conns( + struct gk_multib_field *mbf, struct gkyl_gyrokinetic_multib_app *mbapp, int dir, struct gkyl_range **multib_ranges_ext, struct gkyl_multib_comm_conn **mbcc_allgather_send, - struct gkyl_multib_comm_conn **mbcc_allgather_recv) + struct gkyl_multib_comm_conn **mbcc_allgather_recv +) { // Construct the comm_conns for the allgather in a given direction. @@ -100,49 +112,59 @@ gk_multib_field_new_allgather_comm_conns(struct gk_multib_field *mbf, struct gky // Get branks (number of cuts per block) int num_blocks = mbapp->block_topo->num_blocks; int *branks = gkyl_malloc(sizeof(int[num_blocks])); - for (int i=0; igk_block_geom, i); + for (int i = 0; i < num_blocks; ++i) { + const struct gkyl_gk_block_geom_info *bgi = + gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, i); branks[i] = calc_cuts(mbf->cdim, bgi->cuts); } - + // Get blocks connected along the specified direction. int nconnected[num_blocks]; int **block_list = gk_multib_field_new_connected_list(mbapp, dir, nconnected); // Construct the comm_conns for the allgather - int nghost[] = {1, 1 ,1}; + int nghost[] = {1, 1, 1}; int rank_list[num_ranks]; - for (int bI= 0; bInum_local_blocks; bI++) { + for (int bI = 0; bI < mbf->num_local_blocks; bI++) { int bid = mbapp->local_blocks[bI]; gkyl_rrobin_decomp_getranks(mbapp->round_robin, bid, rank_list); int brank = -1; - for (int i=0; idecomp); - mbcc_allgather_recv[bI] = gkyl_multib_comm_conn_new_recv_from_connections(bid, brank, - nghost, nconnected[bid], block_list[bid], dir, mbapp->decomp); + mbcc_allgather_send[bI] = gkyl_multib_comm_conn_new_send_from_connections( + bid, brank, nghost, nconnected[bid], block_list[bid], dir, mbapp->decomp + ); + mbcc_allgather_recv[bI] = gkyl_multib_comm_conn_new_recv_from_connections( + bid, brank, nghost, nconnected[bid], block_list[bid], dir, mbapp->decomp + ); - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_allgather_send[bI]->num_comm_conn; ++ns) { // Need to get the actual rank that owns this cut. int rank_idx = mbcc_allgather_send[bI]->comm_conn[ns].rank; - gkyl_rrobin_decomp_getranks(mbapp->round_robin, - mbcc_allgather_send[bI]->comm_conn[ns].block_id, rank_list); + gkyl_rrobin_decomp_getranks( + mbapp->round_robin, mbcc_allgather_send[bI]->comm_conn[ns].block_id, rank_list + ); mbcc_allgather_send[bI]->comm_conn[ns].rank = rank_list[rank_idx]; // Make range the local range (a subrange of local_ext). mbcc_allgather_send[bI]->comm_conn[ns].range = mbapp->singleb_apps[bI]->local; } - for (int nr=0; nrnum_comm_conn; ++nr) { + for (int nr = 0; nr < mbcc_allgather_recv[bI]->num_comm_conn; ++nr) { // Need to get the actual rank that owns this cut. int rank_idx = mbcc_allgather_recv[bI]->comm_conn[nr].rank; - gkyl_rrobin_decomp_getranks(mbapp->round_robin, - mbcc_allgather_recv[bI]->comm_conn[nr].block_id, rank_list); + gkyl_rrobin_decomp_getranks( + mbapp->round_robin, mbcc_allgather_recv[bI]->comm_conn[nr].block_id, rank_list + ); mbcc_allgather_recv[bI]->comm_conn[nr].rank = rank_list[rank_idx]; // Make range a subrange. - gkyl_sub_range_init(&mbcc_allgather_recv[bI]->comm_conn[nr].range, - multib_ranges_ext[bI], mbcc_allgather_recv[bI]->comm_conn[nr].range.lower, - mbcc_allgather_recv[bI]->comm_conn[nr].range.upper); + gkyl_sub_range_init( + &mbcc_allgather_recv[bI]->comm_conn[nr].range, multib_ranges_ext[bI], + mbcc_allgather_recv[bI]->comm_conn[nr].range.lower, + mbcc_allgather_recv[bI]->comm_conn[nr].range.upper + ); } // Sort connections according to rank and block ID (needed by NCCL). @@ -154,9 +176,10 @@ gk_multib_field_new_allgather_comm_conns(struct gk_multib_field *mbf, struct gky gkyl_free(branks); } -static struct gkyl_range ** -gk_multib_field_new_multib_to_global_ranges(struct gk_multib_field *mbf, - struct gkyl_gyrokinetic_multib_app *mbapp, int dir, struct gkyl_range **multib_ranges) +static struct gkyl_range **gk_multib_field_new_multib_to_global_ranges( + struct gk_multib_field *mbf, struct gkyl_gyrokinetic_multib_app *mbapp, int dir, + struct gkyl_range **multib_ranges +) { // Create ranges for copying smoothed quantity from multib to global after smoothing. @@ -164,21 +187,23 @@ gk_multib_field_new_multib_to_global_ranges(struct gk_multib_field *mbf, int nconnected[mbapp->block_topo->num_blocks]; int **block_list = gk_multib_field_new_connected_list(mbapp, dir, nconnected); - struct gkyl_range **parent_subranges = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_range *)); - for (int bI=0; bInum_local_blocks; ++bI) { + struct gkyl_range **parent_subranges = + gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_range *)); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { int bid = mbapp->local_blocks[bI]; int shift[GKYL_MAX_DIM] = {0}; - for (int i=0; idecomp[block_list[bid][i]]->parent_range, dir); + } } struct gkyl_range shifted_parent_range; gkyl_range_shift(&shifted_parent_range, &mbapp->singleb_apps[bI]->global, shift); parent_subranges[bI] = gkyl_malloc(sizeof(struct gkyl_range)); - int inter = gkyl_sub_range_intersect(parent_subranges[bI], - multib_ranges[bI], &shifted_parent_range); + int inter = + gkyl_sub_range_intersect(parent_subranges[bI], multib_ranges[bI], &shifted_parent_range); } gk_multib_field_release_connected_list(mbapp, block_list); @@ -186,9 +211,10 @@ gk_multib_field_new_multib_to_global_ranges(struct gk_multib_field *mbf, return parent_subranges; } -static struct gkyl_range ** -gk_multib_field_new_multib_to_local_ranges(struct gk_multib_field *mbf, - struct gkyl_gyrokinetic_multib_app *mbapp, int dir, struct gkyl_range **multib_ranges) +static struct gkyl_range **gk_multib_field_new_multib_to_local_ranges( + struct gk_multib_field *mbf, struct gkyl_gyrokinetic_multib_app *mbapp, int dir, + struct gkyl_range **multib_ranges +) { // Create ranges for copying smoothed quantity from multib to local after smoothing. @@ -196,92 +222,118 @@ gk_multib_field_new_multib_to_local_ranges(struct gk_multib_field *mbf, int nconnected[mbapp->block_topo->num_blocks]; int **block_list = gk_multib_field_new_connected_list(mbapp, dir, nconnected); - struct gkyl_range **block_subranges = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_range *)); - for (int bI=0; bInum_local_blocks; ++bI) { + struct gkyl_range **block_subranges = + gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_range *)); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { int bid = mbapp->local_blocks[bI]; int shift[GKYL_MAX_DIM] = {0}; - for (int i=0; idecomp[block_list[bid][i]]->parent_range, dir); + } } struct gkyl_range shifted_block_range; gkyl_range_shift(&shifted_block_range, &mbapp->singleb_apps[bI]->local, shift); block_subranges[bI] = gkyl_malloc(sizeof(struct gkyl_range)); - int inter = gkyl_sub_range_intersect(block_subranges[bI], - multib_ranges[bI], &shifted_block_range); + int inter = + gkyl_sub_range_intersect(block_subranges[bI], multib_ranges[bI], &shifted_block_range); } gk_multib_field_release_connected_list(mbapp, block_list); - return block_subranges; + return block_subranges; } -static void -gk_multib_field_new_par_smooth(const struct gkyl_gyrokinetic_multib *mbinp, - struct gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf) +static void gk_multib_field_new_par_smooth( + const struct gkyl_gyrokinetic_multib *mbinp, struct gkyl_gyrokinetic_multib_app *mbapp, + struct gk_multib_field *mbf +) { // Initialize objects needed for the multiblock parallel smoothing. - int dir = mbf->cdim-1; - + int dir = mbf->cdim - 1; + // Construct the local and global ranges for the allgather along z. - mbf->multibz_ranges = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_range *)); - mbf->multibz_ranges_ext = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_range *)); - gk_multib_field_new_allgather_ranges(mbf, mbapp, dir, mbf->multibz_ranges, mbf->multibz_ranges_ext); + mbf->multibz_ranges = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_range *)); + mbf->multibz_ranges_ext = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_range *)); + gk_multib_field_new_allgather_ranges( + mbf, mbapp, dir, mbf->multibz_ranges, mbf->multibz_ranges_ext + ); // Allocate global-in-z arrays for charge density and potential. int num_basis = mbapp->singleb_apps[0]->basis.num_basis; - mbf->phi_multibz_dg = gk_multib_field_mkarr(mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks); - mbf->phi_multibz_smooth = gk_multib_field_mkarr(mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks); - mbf->rho_c_multibz_dg = gk_multib_field_mkarr(mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks); - mbf->rho_c_multibz_smooth = gk_multib_field_mkarr(mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks); + mbf->phi_multibz_dg = gk_multib_field_mkarr( + mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks + ); + mbf->phi_multibz_smooth = gk_multib_field_mkarr( + mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks + ); + mbf->rho_c_multibz_dg = gk_multib_field_mkarr( + mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks + ); + mbf->rho_c_multibz_smooth = gk_multib_field_mkarr( + mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks + ); // Construct the comm_conns for the allgather along z. - mbf->mbcc_allgatherz_send = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - mbf->mbcc_allgatherz_recv = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - gk_multib_field_new_allgather_comm_conns(mbf, mbapp, dir, mbf->multibz_ranges_ext, - mbf->mbcc_allgatherz_send, mbf->mbcc_allgatherz_recv); - + mbf->mbcc_allgatherz_send = + gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + mbf->mbcc_allgatherz_recv = + gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + gk_multib_field_new_allgather_comm_conns( + mbf, mbapp, dir, mbf->multibz_ranges_ext, mbf->mbcc_allgatherz_send, mbf->mbcc_allgatherz_recv + ); + // Create ranges for copying smoothed quantity from multib to global after smoothing. - mbf->parent_subrangesz = gk_multib_field_new_multib_to_global_ranges(mbf, mbapp, dir, mbf->multibz_ranges); + mbf->parent_subrangesz = + gk_multib_field_new_multib_to_global_ranges(mbf, mbapp, dir, mbf->multibz_ranges); // Create ranges for copying smoothed quantity from multib to local after smoothing. - mbf->block_subrangesz = gk_multib_field_new_multib_to_local_ranges(mbf, mbapp, dir, mbf->multibz_ranges); + mbf->block_subrangesz = + gk_multib_field_new_multib_to_local_ranges(mbf, mbapp, dir, mbf->multibz_ranges); // Allocate the weights used for the parallel smoother. - struct gkyl_array **lhs_weight_local = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_array*)); - struct gkyl_array **rhs_weight_local = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_array*)); - for (int bI=0; bInum_local_blocks; ++bI) { + struct gkyl_array **lhs_weight_local = + gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_array *)); + struct gkyl_array **rhs_weight_local = + gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_array *)); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; rhs_weight_local[bI] = mkarr(mbapp->use_gpu, sbapp->basis.num_basis, sbapp->local_ext.volume); if (mbf->cdim == 1) { lhs_weight_local[bI] = gkyl_array_acquire(sbapp->field->epsilon); - } - else { + } else { lhs_weight_local[bI] = mkarr(mbapp->use_gpu, sbapp->basis.num_basis, sbapp->local_ext.volume); } } // Set the smoothing local RHS weight to 1, and the LHS weight to 1 if cdim>1, // and gather them along the magnetic field. - for (int bI=0; bInum_local_blocks; ++bI) { + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; - gkyl_array_shiftc(rhs_weight_local[bI], sqrt(pow(2,mbf->cdim)), 0); - if (mbf->cdim > 1) - gkyl_array_shiftc(lhs_weight_local[bI], sqrt(pow(2,mbf->cdim)), 0); + gkyl_array_shiftc(rhs_weight_local[bI], sqrt(pow(2, mbf->cdim)), 0); + if (mbf->cdim > 1) { + gkyl_array_shiftc(lhs_weight_local[bI], sqrt(pow(2, mbf->cdim)), 0); + } } - mbf->lhs_weight_multibz = gk_multib_field_mkarr(mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks); - mbf->rhs_weight_multibz = gk_multib_field_mkarr(mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks); + mbf->lhs_weight_multibz = gk_multib_field_mkarr( + mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks + ); + mbf->rhs_weight_multibz = gk_multib_field_mkarr( + mbapp->use_gpu, num_basis, mbf->multibz_ranges_ext, mbf->num_local_blocks + ); int stat; - stat = gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbf->num_local_blocks, - mbapp->local_blocks, mbf->mbcc_allgatherz_send, mbf->mbcc_allgatherz_recv, lhs_weight_local, - mbf->lhs_weight_multibz); - stat = gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbf->num_local_blocks, - mbapp->local_blocks, mbf->mbcc_allgatherz_send, mbf->mbcc_allgatherz_recv, rhs_weight_local, - mbf->rhs_weight_multibz); - - for (int bI= 0; bInum_local_blocks; bI++) { + stat = gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, mbf->mbcc_allgatherz_send, + mbf->mbcc_allgatherz_recv, lhs_weight_local, mbf->lhs_weight_multibz + ); + stat = gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, mbf->mbcc_allgatherz_send, + mbf->mbcc_allgatherz_recv, rhs_weight_local, mbf->rhs_weight_multibz + ); + + for (int bI = 0; bI < mbf->num_local_blocks; bI++) { gkyl_array_release(lhs_weight_local[bI]); gkyl_array_release(rhs_weight_local[bI]); } @@ -289,30 +341,36 @@ gk_multib_field_new_par_smooth(const struct gkyl_gyrokinetic_multib *mbinp, gkyl_free(rhs_weight_local); // Create the parallel smoother. - mbf->fem_parproj = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_fem_parproj*)); - for (int bI=0; bInum_local_blocks; ++bI) { + mbf->fem_parproj = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_fem_parproj *)); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { int bid = mbapp->local_blocks[bI]; struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; // Choose no BC for the parallel smoother, unless we are in the core in 2x // in which case periodic BCs are needed. enum gkyl_fem_parproj_bc_type fem_parbc = GKYL_FEM_PARPROJ_NONE; - const struct gkyl_gk_block_geom_info *bgi = gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, bid); + const struct gkyl_gk_block_geom_info *bgi = + gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, bid); enum gkyl_tok_geo_type ftype = bgi->geometry.tok_grid_info.ftype; - if (mbf->cdim == 2 && (ftype == GKYL_GEOMETRY_TOKAMAK_CORE || ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L) && !mbf->info.half_domain) + if (mbf->cdim == 2 && + (ftype == GKYL_GEOMETRY_TOKAMAK_CORE || ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || + ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L) && + !mbf->info.half_domain) { fem_parbc = GKYL_FEM_PARPROJ_PERIODIC; + } - mbf->fem_parproj[bI] = gkyl_fem_parproj_new(mbf->multibz_ranges[bI], &sbapp->grid, - &sbapp->basis, fem_parbc, 0, mbf->lhs_weight_multibz[bI], mbf->rhs_weight_multibz[bI], mbapp->use_gpu); + mbf->fem_parproj[bI] = gkyl_fem_parproj_new( + mbf->multibz_ranges[bI], &sbapp->grid, &sbapp->basis, fem_parbc, 0, + mbf->lhs_weight_multibz[bI], mbf->rhs_weight_multibz[bI], mbapp->use_gpu + ); } } -static bool -in_array_int(int inp, const int *arr, int num_elements) +static bool in_array_int(int inp, const int *arr, int num_elements) { // Check if 'inp' is in the array 'arr' which has 'num_elements'. bool found = false; - for (int i=0; iblock_topo->num_blocks]; @@ -334,97 +393,118 @@ gk_multib_is_bid_connected_in_dir(int bidx, struct gkyl_gyrokinetic_multib_app * return is_in_conn_dir; } -static void -gk_multib_field_new_perp_solve(const struct gkyl_gyrokinetic_multib *mbinp, - struct gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf) +static void gk_multib_field_new_perp_solve( + const struct gkyl_gyrokinetic_multib *mbinp, struct gkyl_gyrokinetic_multib_app *mbapp, + struct gk_multib_field *mbf +) { // Initialize objects needed for the multiblock perpendicular Poisson solve. int dir = 0; // Note that for cdim=3 we here assume there are is everywhere a - // single block along y. - + // single block along y. + // Construct the local and global ranges for the perpendicular allgather. - mbf->multib_perp_ranges = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_range *)); - mbf->multib_perp_ranges_ext = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_range *)); - gk_multib_field_new_allgather_ranges(mbf, mbapp, dir, mbf->multib_perp_ranges, mbf->multib_perp_ranges_ext); + mbf->multib_perp_ranges = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_range *)); + mbf->multib_perp_ranges_ext = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_range *)); + gk_multib_field_new_allgather_ranges( + mbf, mbapp, dir, mbf->multib_perp_ranges, mbf->multib_perp_ranges_ext + ); // Allocate global-in-x arrays for charge density and potential. int num_basis = mbapp->singleb_apps[0]->basis.num_basis; - mbf->phi_multib_perp = gk_multib_field_mkarr(mbapp->use_gpu, num_basis, mbf->multib_perp_ranges_ext, mbf->num_local_blocks); - mbf->rho_c_multib_perp = gk_multib_field_mkarr(mbapp->use_gpu, num_basis, mbf->multib_perp_ranges_ext, mbf->num_local_blocks); + mbf->phi_multib_perp = gk_multib_field_mkarr( + mbapp->use_gpu, num_basis, mbf->multib_perp_ranges_ext, mbf->num_local_blocks + ); + mbf->rho_c_multib_perp = gk_multib_field_mkarr( + mbapp->use_gpu, num_basis, mbf->multib_perp_ranges_ext, mbf->num_local_blocks + ); // Construct the comm_conns for the allgather along z. - mbf->mbcc_allgather_perp_send = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - mbf->mbcc_allgather_perp_recv = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - gk_multib_field_new_allgather_comm_conns(mbf, mbapp, dir, mbf->multib_perp_ranges_ext, - mbf->mbcc_allgather_perp_send, mbf->mbcc_allgather_perp_recv); - + mbf->mbcc_allgather_perp_send = + gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + mbf->mbcc_allgather_perp_recv = + gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + gk_multib_field_new_allgather_comm_conns( + mbf, mbapp, dir, mbf->multib_perp_ranges_ext, mbf->mbcc_allgather_perp_send, + mbf->mbcc_allgather_perp_recv + ); + // Create ranges for copying smoothed quantity from multib to global. - mbf->parent_subranges_perp = gk_multib_field_new_multib_to_global_ranges(mbf, mbapp, dir, mbf->multib_perp_ranges); + mbf->parent_subranges_perp = + gk_multib_field_new_multib_to_global_ranges(mbf, mbapp, dir, mbf->multib_perp_ranges); // Create ranges for copying smoothed quantity from multib to local. - mbf->block_subranges_perp = gk_multib_field_new_multib_to_local_ranges(mbf, mbapp, dir, mbf->multib_perp_ranges); + mbf->block_subranges_perp = + gk_multib_field_new_multib_to_local_ranges(mbf, mbapp, dir, mbf->multib_perp_ranges); // Allocate and gather the polarization weights. - struct gkyl_array **epsilon_local = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_array*)); - for (int bI=0; bInum_local_blocks; ++bI) { + struct gkyl_array **epsilon_local = + gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_array *)); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; epsilon_local[bI] = gkyl_array_acquire(sbapp->field->epsilon); } - mbf->epsilon_multib_perp = gk_multib_field_mkarr(mbapp->use_gpu, mbapp->singleb_apps[0]->field->epsilon->ncomp, - mbf->multib_perp_ranges_ext, mbf->num_local_blocks); - int stat = gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbf->num_local_blocks, - mbapp->local_blocks, mbf->mbcc_allgather_perp_send, mbf->mbcc_allgather_perp_recv, epsilon_local, - mbf->epsilon_multib_perp); - for (int bI= 0; bInum_local_blocks; bI++) + mbf->epsilon_multib_perp = gk_multib_field_mkarr( + mbapp->use_gpu, mbapp->singleb_apps[0]->field->epsilon->ncomp, mbf->multib_perp_ranges_ext, + mbf->num_local_blocks + ); + int stat = gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, mbf->mbcc_allgather_perp_send, + mbf->mbcc_allgather_perp_recv, epsilon_local, mbf->epsilon_multib_perp + ); + for (int bI = 0; bI < mbf->num_local_blocks; bI++) { gkyl_array_release(epsilon_local[bI]); + } gkyl_free(epsilon_local); // Create the perpendicular solve. - mbf->fem_poisson = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_fem_poisson_perp*)); - for (int bI=0; bInum_local_blocks; ++bI) { + mbf->fem_poisson = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_fem_poisson_perp *)); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { int bid = mbapp->local_blocks[bI]; struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; // Obtain the BCs for connected blocks. // Loop through input BCs and find those for the current connnected blocks. - struct gkyl_poisson_bc bcs = { }; - for (int i=0; ifield.num_physical_bcs; i++) { + struct gkyl_poisson_bc bcs = {}; + for (int i = 0; i < mbinp->field.num_physical_bcs; i++) { const struct gkyl_gyrokinetic_bc *bc_curr = &mbinp->field.bcs[i]; if (gk_multib_is_bid_connected_in_dir(bc_curr->bidx, mbapp, bid, dir)) { if (bc_curr->edge == GKYL_LOWER_EDGE) { bcs.lo_type[bc_curr->dir] = gkyl_gyrokinetic_translate_poisson_bc_type(bc_curr->type); - for (int k=0; k<3; k++) + for (int k = 0; k < 3; k++) { bcs.lo_value[bc_curr->dir].v[k] = bc_curr->value[k]; - } - else { + } + } else { bcs.up_type[bc_curr->dir] = gkyl_gyrokinetic_translate_poisson_bc_type(bc_curr->type); - for (int k=0; k<3; k++) + for (int k = 0; k < 3; k++) { bcs.up_value[bc_curr->dir].v[k] = bc_curr->value[k]; + } } } } - mbf->fem_poisson[bI] = gkyl_fem_poisson_perp_new(mbf->multib_perp_ranges[bI], &sbapp->grid, sbapp->basis, - &bcs, mbf->info.bias_line_list, mbf->epsilon_multib_perp[bI], NULL, mbapp->use_gpu); + mbf->fem_poisson[bI] = gkyl_fem_poisson_perp_new( + mbf->multib_perp_ranges[bI], &sbapp->grid, sbapp->basis, &bcs, mbf->info.bias_line_list, + mbf->epsilon_multib_perp[bI], NULL, mbapp->use_gpu + ); } - } // Compute the electrostatic potential. -static void -gk_multib_field_1x_rhs(gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]) +static void gk_multib_field_1x_rhs( + gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +) { // Every local block calculates its charge density. - for (int bI=0; bInum_local_blocks; bI++) { + for (int bI = 0; bI < mbf->num_local_blocks; bI++) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; // Construct fin for the local block. const struct gkyl_array *fin_local_block[mbapp->num_species]; struct gkyl_array **bflux_local_block[mbapp->num_species]; int lin_idx = bI * mbapp->num_species; - for (int i=0; inum_species; ++i) { - fin_local_block[i] = fin[lin_idx+i]; - bflux_local_block[i] = bflux[lin_idx+i]; + for (int i = 0; i < mbapp->num_species; ++i) { + fin_local_block[i] = fin[lin_idx + i]; + bflux_local_block[i] = bflux[lin_idx + i]; } // Accumulate rho_c in local block. gk_field_accumulate_rho_c(sbapp, sbapp->field, fin_local_block, bflux_local_block); @@ -433,38 +513,45 @@ gk_multib_field_1x_rhs(gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_fiel struct timespec wst = gkyl_wall_clock(); // Gather the charge density along the magnetic field. - int stat_par_rho = gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, - mbf->mbcc_allgatherz_send, mbf->mbcc_allgatherz_recv, mbf->rho_c_local, mbf->rho_c_multibz_dg); + int stat_par_rho = gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, mbf->mbcc_allgatherz_send, + mbf->mbcc_allgatherz_recv, mbf->rho_c_local, mbf->rho_c_multibz_dg + ); // Make charge density continuous on the multibz range. - for (int bI=0; bInum_local_blocks; ++bI) { - gkyl_fem_parproj_set_rhs(mbf->fem_parproj[bI], mbf->rho_c_multibz_dg[bI], mbf->rho_c_multibz_dg[bI]); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { + gkyl_fem_parproj_set_rhs( + mbf->fem_parproj[bI], mbf->rho_c_multibz_dg[bI], mbf->rho_c_multibz_dg[bI] + ); gkyl_fem_parproj_solve(mbf->fem_parproj[bI], mbf->rho_c_multibz_smooth[bI]); } // Copy continuous charge density back to apps. - for (int bI=0; bInum_local_blocks; ++bI) { - gkyl_array_copy_range_to_range(mbapp->singleb_apps[bI]->field->phi_smooth, mbf->rho_c_multibz_smooth[bI], - &mbapp->singleb_apps[bI]->local, mbf->block_subrangesz[bI]); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { + gkyl_array_copy_range_to_range( + mbapp->singleb_apps[bI]->field->phi_smooth, mbf->rho_c_multibz_smooth[bI], + &mbapp->singleb_apps[bI]->local, mbf->block_subrangesz[bI] + ); } mbapp->stat.field_phi_solve_tm += gkyl_time_diff_now_sec(wst); } // Compute the electrostatic potential. -static void -gk_multib_field_2x_rhs(gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]) +static void gk_multib_field_2x_rhs( + gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +) { // Every local block calculates its charge density. - for (int bI=0; bInum_local_blocks; bI++) { + for (int bI = 0; bI < mbf->num_local_blocks; bI++) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; // Construct fin for the local block. const struct gkyl_array *fin_local_block[mbapp->num_species]; struct gkyl_array **bflux_local_block[mbapp->num_species]; int lin_idx = bI * mbapp->num_species; - for (int i=0; inum_species; ++i) { - fin_local_block[i] = fin[lin_idx+i]; - bflux_local_block[i] = bflux[lin_idx+i]; + for (int i = 0; i < mbapp->num_species; ++i) { + fin_local_block[i] = fin[lin_idx + i]; + bflux_local_block[i] = bflux[lin_idx + i]; } // Accumulate rho_c in local block. gk_field_accumulate_rho_c(sbapp, sbapp->field, fin_local_block, bflux_local_block); @@ -473,98 +560,119 @@ gk_multib_field_2x_rhs(gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_fiel struct timespec wst = gkyl_wall_clock(); // Gather the charge density along the magnetic field. - int stat_par_rho = gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, - mbf->mbcc_allgatherz_send, mbf->mbcc_allgatherz_recv, mbf->rho_c_local, mbf->rho_c_multibz_dg); + int stat_par_rho = gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, mbf->mbcc_allgatherz_send, + mbf->mbcc_allgatherz_recv, mbf->rho_c_local, mbf->rho_c_multibz_dg + ); // Make charge density continuous on the multibz range. - for (int bI=0; bInum_local_blocks; ++bI) { - gkyl_fem_parproj_set_rhs(mbf->fem_parproj[bI], mbf->rho_c_multibz_dg[bI], mbf->rho_c_multibz_dg[bI]); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { + gkyl_fem_parproj_set_rhs( + mbf->fem_parproj[bI], mbf->rho_c_multibz_dg[bI], mbf->rho_c_multibz_dg[bI] + ); gkyl_fem_parproj_solve(mbf->fem_parproj[bI], mbf->rho_c_multibz_smooth[bI]); } - for (int bI=0; bInum_local_blocks; ++bI) { + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; // Copy continuous charge density back to apps. - gkyl_array_copy_range_to_range(sbapp->field->rho_c_global_smooth, - mbf->rho_c_multibz_smooth[bI], &sbapp->global, mbf->parent_subrangesz[bI]); + gkyl_array_copy_range_to_range( + sbapp->field->rho_c_global_smooth, mbf->rho_c_multibz_smooth[bI], &sbapp->global, + mbf->parent_subrangesz[bI] + ); // Copy from block-global to block local. - gkyl_array_copy_range_to_range(sbapp->field->rho_c, sbapp->field->rho_c_global_smooth, - &sbapp->local, &sbapp->field->global_sub_range); + gkyl_array_copy_range_to_range( + sbapp->field->rho_c, sbapp->field->rho_c_global_smooth, &sbapp->local, + &sbapp->field->global_sub_range + ); } // // Solve the perpendicular Poisson problem. // // Gather the charge density in the perpendicular direction. - int stat_perp = gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, - mbf->mbcc_allgather_perp_send, mbf->mbcc_allgather_perp_recv, mbf->rho_c_local, mbf->rho_c_multib_perp); - for (int bI=0; bInum_local_blocks; ++bI) { + int stat_perp = gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, mbf->mbcc_allgather_perp_send, + mbf->mbcc_allgather_perp_recv, mbf->rho_c_local, mbf->rho_c_multib_perp + ); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; // Solve the perp problem. gkyl_fem_poisson_perp_set_rhs(mbf->fem_poisson[bI], mbf->rho_c_multib_perp[bI]); gkyl_fem_poisson_perp_solve(mbf->fem_poisson[bI], mbf->phi_multib_perp[bI]); // Copy the potential from the mulib range to local. - gkyl_array_copy_range_to_range(mbapp->singleb_apps[bI]->field->phi_smooth, mbf->phi_multib_perp[bI], - &mbapp->singleb_apps[bI]->local, mbf->block_subranges_perp[bI]); + gkyl_array_copy_range_to_range( + mbapp->singleb_apps[bI]->field->phi_smooth, mbf->phi_multib_perp[bI], + &mbapp->singleb_apps[bI]->local, mbf->block_subranges_perp[bI] + ); } // // Finished solving the perpendicular Poisson problem. // // Gather the potential along the magnetic field. - int stat_par_phi = gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, - mbf->mbcc_allgatherz_send, mbf->mbcc_allgatherz_recv, mbf->phi_local, mbf->phi_multibz_dg); + int stat_par_phi = gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, mbf->mbcc_allgatherz_send, + mbf->mbcc_allgatherz_recv, mbf->phi_local, mbf->phi_multibz_dg + ); // Make the potential continuous along B on the multibz range. - for (int bI=0; bInum_local_blocks; ++bI) { + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { gkyl_fem_parproj_set_rhs(mbf->fem_parproj[bI], mbf->phi_multibz_dg[bI], mbf->phi_multibz_dg[bI]); gkyl_fem_parproj_solve(mbf->fem_parproj[bI], mbf->phi_multibz_smooth[bI]); } // Copy continuous potential back to apps. - for (int bI=0; bInum_local_blocks; ++bI) { + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; // Copy from multib to block global. - gkyl_array_copy_range_to_range(sbapp->field->rho_c_global_smooth, - mbf->phi_multibz_smooth[bI], &sbapp->global, mbf->parent_subrangesz[bI]); + gkyl_array_copy_range_to_range( + sbapp->field->rho_c_global_smooth, mbf->phi_multibz_smooth[bI], &sbapp->global, + mbf->parent_subrangesz[bI] + ); // Copy from block-global to block local. - gkyl_array_copy_range_to_range(sbapp->field->phi_smooth, sbapp->field->rho_c_global_smooth, - &sbapp->local, &sbapp->field->global_sub_range); + gkyl_array_copy_range_to_range( + sbapp->field->phi_smooth, sbapp->field->rho_c_global_smooth, &sbapp->local, + &sbapp->field->global_sub_range + ); } mbapp->stat.field_phi_solve_tm += gkyl_time_diff_now_sec(wst); } - -void -gk_multib_field_twistshift_and_smooth(gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, - struct gkyl_array **arr_local, struct gkyl_array **arr_global_dg, struct gkyl_array **arr_global_smooth) +void gk_multib_field_twistshift_and_smooth( + gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, struct gkyl_array **arr_local, + struct gkyl_array **arr_global_dg, struct gkyl_array **arr_global_smooth +) { // There are three arrays: // 1) The local one (field->rho_c = rho_c_local[bI]) // 2) The global non-smooth one (field->rho_c_global_dg) needs an mb equivalent // 3) The global smooth one // Now apply TS in place on rho for each block - int par_dir = mbf->cdim-1; // Parallel direction index. - for (int bI=0; bInum_local_blocks; bI++) { + int par_dir = mbf->cdim - 1; // Parallel direction index. + for (int bI = 0; bI < mbapp->num_local_blocks; bI++) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; struct gk_field *field = sbapp->field; - gkyl_comm_array_allgather(sbapp->comm, &sbapp->local, &sbapp->global, - arr_local[bI], arr_global_dg[bI]); + gkyl_comm_array_allgather( + sbapp->comm, &sbapp->local, &sbapp->global, arr_local[bI], arr_global_dg[bI] + ); // Apply TS BC in the lower parallel boundary, and // fill upper parallel boundary ghost with skin boundary value. if (mbf->num_blocks_below[bI] > 0) { gkyl_bc_twistshift_advance(field->bc_ts_lo, arr_global_dg[bI], arr_global_dg[bI]); + } else { + gkyl_bc_basic_gyrokinetic_advance( + field->gfss_bc_op_core_lo, field->bc_buffer, arr_global_dg[bI] + ); } - else{ - gkyl_bc_basic_gyrokinetic_advance(field->gfss_bc_op_core_lo, field->bc_buffer, arr_global_dg[bI]); - } - + // Apply TS BC in the upper parallel boundary, and // fill lower parallel boundary ghost with skin boundary value. if (mbf->num_blocks_above[bI] > 0) { gkyl_bc_twistshift_advance(field->bc_ts_up, arr_global_dg[bI], arr_global_dg[bI]); - } - else { - gkyl_bc_basic_gyrokinetic_advance(field->gfss_bc_op_core_up, field->bc_buffer, arr_global_dg[bI]); + } else { + gkyl_bc_basic_gyrokinetic_advance( + field->gfss_bc_op_core_up, field->bc_buffer, arr_global_dg[bI] + ); } // Smooth the the DG array. @@ -572,25 +680,28 @@ gk_multib_field_twistshift_and_smooth(gkyl_gyrokinetic_multib_app *mbapp, struct gkyl_fem_parproj_solve(field->fem_parproj_phi_core, arr_global_smooth[bI]); // Copy global, continuous FEM array to a local array. - gkyl_array_copy_range_to_range(arr_local[bI], arr_global_smooth[bI], &sbapp->local, &field->global_sub_range); + gkyl_array_copy_range_to_range( + arr_local[bI], arr_global_smooth[bI], &sbapp->local, &field->global_sub_range + ); } } // Compute the electrostatic potential. -static void -gk_multib_field_3x_rhs(gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]) +static void gk_multib_field_3x_rhs( + gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +) { // Every local block calculates its charge density. - for (int bI=0; bInum_local_blocks; bI++) { + for (int bI = 0; bI < mbf->num_local_blocks; bI++) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; // Construct fin for the local block. const struct gkyl_array *fin_local_block[mbapp->num_species]; struct gkyl_array **bflux_local_block[mbapp->num_species]; int lin_idx = bI * mbapp->num_species; - for (int i=0; inum_species; ++i) { - fin_local_block[i] = fin[lin_idx+i]; - bflux_local_block[i] = bflux[lin_idx+i]; + for (int i = 0; i < mbapp->num_species; ++i) { + fin_local_block[i] = fin[lin_idx + i]; + bflux_local_block[i] = bflux[lin_idx + i]; } // Accumulate rho_c in local block. gk_field_accumulate_rho_c(sbapp, sbapp->field, fin_local_block, bflux_local_block); @@ -598,31 +709,39 @@ gk_multib_field_3x_rhs(gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_fiel // Now sync the charge density struct gkyl_array *rhos[mbapp->num_local_blocks]; - for (int bI=0; bInum_local_blocks; bI++) { + for (int bI = 0; bI < mbapp->num_local_blocks; bI++) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; rhos[bI] = sbapp->field->rho_c; } - gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, - mbapp->mbcc_sync_conf->send, mbapp->mbcc_sync_conf->recv, rhos, rhos); + gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, mbapp->mbcc_sync_conf->send, + mbapp->mbcc_sync_conf->recv, rhos, rhos + ); // Now apply TS in place on rho for each block - gk_multib_field_twistshift_and_smooth(mbapp, mbf, mbf->rho_c_local, mbf->rho_c_global_dg, mbf->rho_c_global_smooth); + gk_multib_field_twistshift_and_smooth( + mbapp, mbf, mbf->rho_c_local, mbf->rho_c_global_dg, mbf->rho_c_global_smooth + ); // Done applying TS now we need to solve the field // // Solve the perpendicular Poisson problem. // // Gather the charge density in the perpendicular direction. - int stat_perp = gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, - mbf->mbcc_allgather_perp_send, mbf->mbcc_allgather_perp_recv, mbf->rho_c_local, mbf->rho_c_multib_perp); - for (int bI=0; bInum_local_blocks; ++bI) { + int stat_perp = gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbf->num_local_blocks, mbapp->local_blocks, mbf->mbcc_allgather_perp_send, + mbf->mbcc_allgather_perp_recv, mbf->rho_c_local, mbf->rho_c_multib_perp + ); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; // Solve the perp problem. gkyl_fem_poisson_perp_set_rhs(mbf->fem_poisson[bI], mbf->rho_c_multib_perp[bI]); gkyl_fem_poisson_perp_solve(mbf->fem_poisson[bI], mbf->phi_multib_perp[bI]); // Copy the potential from the mulib range to local. - gkyl_array_copy_range_to_range(mbapp->singleb_apps[bI]->field->phi_smooth, mbf->phi_multib_perp[bI], - &mbapp->singleb_apps[bI]->local, mbf->block_subranges_perp[bI]); + gkyl_array_copy_range_to_range( + mbapp->singleb_apps[bI]->field->phi_smooth, mbf->phi_multib_perp[bI], + &mbapp->singleb_apps[bI]->local, mbf->block_subranges_perp[bI] + ); } // // Finished solving the perpendicular Poisson problem. @@ -630,37 +749,42 @@ gk_multib_field_3x_rhs(gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_fiel // Now sync the charge density struct gkyl_array *phis[mbapp->num_local_blocks]; - for (int bI=0; bInum_local_blocks; bI++) { + for (int bI = 0; bI < mbapp->num_local_blocks; bI++) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; phis[bI] = sbapp->field->phi_smooth; } - gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, - mbapp->mbcc_sync_conf->send, mbapp->mbcc_sync_conf->recv, phis, phis); + gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, mbapp->mbcc_sync_conf->send, + mbapp->mbcc_sync_conf->recv, phis, phis + ); // Now apply TS in place on phi for each block - gk_multib_field_twistshift_and_smooth(mbapp, mbf, mbf->phi_local, mbf->rho_c_global_dg, mbf->phi_global_smooth); + gk_multib_field_twistshift_and_smooth( + mbapp, mbf, mbf->phi_local, mbf->rho_c_global_dg, mbf->phi_global_smooth + ); // Done with TS and smooth of phi } // Initialize multib field object -struct gk_multib_field* -gk_multib_field_new(const struct gkyl_gyrokinetic_multib *mbinp, struct gkyl_gyrokinetic_multib_app *mbapp) +struct gk_multib_field *gk_multib_field_new( + const struct gkyl_gyrokinetic_multib *mbinp, struct gkyl_gyrokinetic_multib_app *mbapp +) { struct gk_multib_field *mbf = gkyl_malloc(sizeof(struct gk_multib_field)); mbf->info = mbinp->field; - mbf->gkfield_id = mbf->info.gkfield_id? mbf->info.gkfield_id : GKYL_GK_FIELD_ES; + mbf->gkfield_id = mbf->info.gkfield_id ? mbf->info.gkfield_id : GKYL_GK_FIELD_ES; mbf->num_local_blocks = mbapp->num_local_blocks; mbf->cdim = mbapp->block_topo->ndim; mbf->half_domain = mbf->info.half_domain ? mbf->info.half_domain : false; // Allocate local arrays for charge density and potential. - mbf->phi_local = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_array*)); - mbf->rho_c_local = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_array*)); - mbf->rho_c_global_dg = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_array*)); - mbf->phi_global_smooth = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_array*)); - mbf->rho_c_global_smooth = gkyl_malloc(mbf->num_local_blocks* sizeof(struct gkyl_array*)); - for (int bI=0; bInum_local_blocks; ++bI) { + mbf->phi_local = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_array *)); + mbf->rho_c_local = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_array *)); + mbf->rho_c_global_dg = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_array *)); + mbf->phi_global_smooth = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_array *)); + mbf->rho_c_global_smooth = gkyl_malloc(mbf->num_local_blocks * sizeof(struct gkyl_array *)); + for (int bI = 0; bI < mbf->num_local_blocks; ++bI) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; mbf->phi_local[bI] = gkyl_array_acquire(sbapp->field->phi_smooth); mbf->rho_c_local[bI] = gkyl_array_acquire(sbapp->field->rho_c); @@ -678,36 +802,41 @@ gk_multib_field_new(const struct gkyl_gyrokinetic_multib *mbinp, struct gkyl_gyr } for (int bI = 0; bI < mbapp->num_local_blocks; bI++) { - int dir = mbf->cdim-1; - mbf->num_blocks_below[bI] = gkyl_multib_conn_get_num_connected(mbapp->block_topo, - mbapp->local_blocks[bI], dir, 0, GKYL_CONN_BELOW); - mbf->num_blocks_above[bI] = gkyl_multib_conn_get_num_connected(mbapp->block_topo, - mbapp->local_blocks[bI], dir, 0, GKYL_CONN_ABOVE); + int dir = mbf->cdim - 1; + mbf->num_blocks_below[bI] = gkyl_multib_conn_get_num_connected( + mbapp->block_topo, mbapp->local_blocks[bI], dir, 0, GKYL_CONN_BELOW + ); + mbf->num_blocks_above[bI] = gkyl_multib_conn_get_num_connected( + mbapp->block_topo, mbapp->local_blocks[bI], dir, 0, GKYL_CONN_ABOVE + ); } - if (mbf->cdim == 1) + if (mbf->cdim == 1) { mbf->rhs_func = gk_multib_field_1x_rhs; - if (mbf->cdim == 2) + } + if (mbf->cdim == 2) { mbf->rhs_func = gk_multib_field_2x_rhs; - if (mbf->cdim == 3) + } + if (mbf->cdim == 3) { mbf->rhs_func = gk_multib_field_3x_rhs; + } return mbf; } -void -gk_multib_field_rhs(gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]) +void gk_multib_field_rhs( + gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +) { // Compute the electrostatic potential. mbf->rhs_func(mbapp, mbf, fin, bflux); } // Release resources for multib field. -void -gk_multib_field_release(struct gk_multib_field *mbf) +void gk_multib_field_release(struct gk_multib_field *mbf) { - for (int bI= 0; bInum_local_blocks; bI++) { + for (int bI = 0; bI < mbf->num_local_blocks; bI++) { gkyl_array_release(mbf->phi_local[bI]); gkyl_array_release(mbf->rho_c_local[bI]); gkyl_array_release(mbf->rho_c_global_dg[bI]); @@ -721,7 +850,7 @@ gk_multib_field_release(struct gk_multib_field *mbf) gkyl_free(mbf->rho_c_global_smooth); // Free memory allocated for parallel smoothing. - for (int bI= 0; bInum_local_blocks; bI++) { + for (int bI = 0; bI < mbf->num_local_blocks; bI++) { gkyl_free(mbf->multibz_ranges[bI]); gkyl_free(mbf->multibz_ranges_ext[bI]); gkyl_free(mbf->parent_subrangesz[bI]); @@ -752,7 +881,7 @@ gk_multib_field_release(struct gk_multib_field *mbf) if (mbf->cdim > 1) { // Free memory allocated for perp solve. - for (int bI= 0; bInum_local_blocks; bI++) { + for (int bI = 0; bI < mbf->num_local_blocks; bI++) { gkyl_free(mbf->multib_perp_ranges[bI]); gkyl_free(mbf->multib_perp_ranges_ext[bI]); gkyl_free(mbf->parent_subranges_perp[bI]); diff --git a/gyrokinetic/apps/gk_neut_species.c b/gyrokinetic/apps/gk_neut_species.c index c5708cf059..689603804f 100644 --- a/gyrokinetic/apps/gk_neut_species.c +++ b/gyrokinetic/apps/gk_neut_species.c @@ -1,114 +1,121 @@ #include -void -gk_neut_species_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns) +void gk_neut_species_init( + struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns +) { if (ns->info.cells[0] == 0) { // Fluid neutrals. gk_neut_species_fluid_init(gk, app, ns); - } - else { + } else { // Kinetic neutrals. gk_neut_species_kinetic_init(gk, app, ns); } } -void -gk_neut_species_apply_ic(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, double t0) +void gk_neut_species_apply_ic(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, double t0) { - if (species->info.init_from_file.type == 0) + if (species->info.init_from_file.type == 0) { gk_neut_species_projection_calc(app, species, &species->proj_init, species->f, t0); + } // We are pre-computing source for now as it is time-independent. gk_neut_species_source_calc(app, species, &species->src, species->lte.f_lte, t0); } -void -gk_neut_species_apply_ic_cross(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns_self, double t0) +void gk_neut_species_apply_ic_cross( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns_self, double t0 +) { // Store initial density in scaling operator. gk_neut_species_scaling_apply_ic_cross(app, gkns_self, &gkns_self->sca); } -double -gk_neut_species_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +double gk_neut_species_rhs( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms +) { // Compute the RHS for species update, returning maximum stable time-step. return species->rhs_func(app, species, fin, rhs, bflux_moms); } -double -gk_neut_species_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt) +double gk_neut_species_rhs_implicit( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt +) { // Compute the implicit RHS for species update, returning maximum stable time-step. return species->rhs_implicit_func(app, species, fin, rhs, bflux_moms, dt); } -void -gk_neut_species_step_f(struct gk_neut_species *species, struct gkyl_array* out, double a, - const struct gkyl_array* inp) +void gk_neut_species_step_f( + struct gk_neut_species *species, struct gkyl_array *out, double a, const struct gkyl_array *inp +) { // Accummulate function for forward euler method. species->step_f_func(out, a, inp); } -void -gk_neut_species_combine(struct gk_neut_species *species, struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng) +void gk_neut_species_combine( + struct gk_neut_species *species, struct gkyl_array *out, double c1, const struct gkyl_array *arr1, + double c2, const struct gkyl_array *arr2, const struct gkyl_range *rng +) { // Combine function for rk3 updates. species->combine_func(out, c1, arr1, c2, arr2, rng); } -void -gk_neut_species_copy_range(struct gk_neut_species *species, struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range) +void gk_neut_species_copy_range( + struct gk_neut_species *species, struct gkyl_array *out, const struct gkyl_array *inp, + const struct gkyl_range *range +) { // Copy function for rk3 updates. species->copy_func(out, inp, range); } -void -gk_neut_species_apply_bc(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gkyl_array *f) +void gk_neut_species_apply_bc( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gkyl_array *f +) { species->bc_func(app, species, f); } -void -gk_neut_species_write(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +void gk_neut_species_write( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { gkns->write_func(app, gkns, tm, frame); } -void -gk_neut_species_write_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +void gk_neut_species_write_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { gkns->write_mom_func(app, gkns, tm, frame); } -void -gk_neut_species_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm) +void gk_neut_species_calc_integrated_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm +) { gkns->calc_integrated_mom_func(app, gkns, tm); } -void -gk_neut_species_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns) +void gk_neut_species_write_integrated_mom(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns) { gkns->write_integrated_mom_func(app, gkns); } -void -gk_neut_species_n_iter_corr(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx) +void gk_neut_species_n_iter_corr( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx +) { gkns->report_n_iter_corr_func(app, gkns, sidx); } -void -gk_neut_species_release(const gkyl_gyrokinetic_app* app, const struct gk_neut_species *gkns) +void gk_neut_species_release(const gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns) { gkns->release_func(app, gkns); } @@ -119,166 +126,184 @@ gk_neut_species_release(const gkyl_gyrokinetic_app* app, const struct gk_neut_sp * */ -double -gk_neut_species_rhs_static(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +double gk_neut_species_rhs_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms +) { - double omega_cfl = 1/DBL_MAX; - return app->cfl/omega_cfl; + double omega_cfl = 1 / DBL_MAX; + return app->cfl / omega_cfl; } -double -gk_neut_species_rhs_implicit_static(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt) +double gk_neut_species_rhs_implicit_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt +) { - double omega_cfl = 1/DBL_MAX; - return app->cfl/omega_cfl; + double omega_cfl = 1 / DBL_MAX; + return app->cfl / omega_cfl; } -void -gk_neut_species_apply_bc_static(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gkyl_array *f) +void gk_neut_species_apply_bc_static( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gkyl_array *f +) { // empty function } -void -gk_neut_species_step_f_dynamic(struct gkyl_array* out, double dt, - const struct gkyl_array* inp) +void gk_neut_species_step_f_dynamic(struct gkyl_array *out, double dt, const struct gkyl_array *inp) { gkyl_array_accumulate(gkyl_array_scale(out, dt), 1.0, inp); } -void -gk_neut_species_step_f_static(struct gkyl_array* out, double dt, - const struct gkyl_array* inp) +void gk_neut_species_step_f_static(struct gkyl_array *out, double dt, const struct gkyl_array *inp) { // Do nothing. } -void -gk_neut_species_combine_dynamic(struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng) +void gk_neut_species_combine_dynamic( + struct gkyl_array *out, double c1, const struct gkyl_array *arr1, double c2, + const struct gkyl_array *arr2, const struct gkyl_range *rng +) { - gkyl_array_accumulate_range(gkyl_array_set_range(out, c1, arr1, rng), - c2, arr2, rng); + gkyl_array_accumulate_range(gkyl_array_set_range(out, c1, arr1, rng), c2, arr2, rng); } -void -gk_neut_species_combine_static(struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng) +void gk_neut_species_combine_static( + struct gkyl_array *out, double c1, const struct gkyl_array *arr1, double c2, + const struct gkyl_array *arr2, const struct gkyl_range *rng +) { // Do nothing. } -void -gk_neut_species_copy_range_dynamic(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range) +void gk_neut_species_copy_range_dynamic( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +) { gkyl_array_copy_range(out, inp, range); } -void -gk_neut_species_copy_range_static(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range) +void gk_neut_species_copy_range_static( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +) { // Do nothing. } -void -gk_neut_species_write_dynamic(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +void gk_neut_species_write_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { struct timespec wst = gkyl_wall_clock(); // Package metadata. gkyl_msgpack_map_elem_set_double(gkns->io_meta_phase_len, gkns->io_meta_phase, "time", tm); gkyl_msgpack_map_elem_set_uint(gkns->io_meta_phase_len, gkns->io_meta_phase, "frame", frame); struct gkyl_msgpack_map_elem desc_f[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Neutral species distribution times Jacobians." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Neutral species distribution times Jacobians."} }; int io_meta_len[] = {gkns->io_meta_phase_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_phase, app->gk_geom->io_meta_basic, desc_f}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_phase, app->gk_geom->io_meta_basic, desc_f + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); const char *fmt = "%s-%s_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, frame); - char fileNm[sz+1]; // Ensures no buffer overflow. + char fileNm[sz + 1]; // Ensures no buffer overflow. snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, frame); - + // Copy data from device to host before writing it out. if (app->use_gpu) { gkyl_array_copy(gkns->f_host, gkns->f); } - + struct timespec wtm = gkyl_wall_clock(); gkyl_comm_array_write(gkns->comm, &gkns->grid, &gkns->local, mt, gkns->f_host, fileNm); app->stat.neut_species_io_tm += gkyl_time_diff_now_sec(wtm); app->stat.n_neut_io += 1; - - gkyl_msgpack_data_release(mt); + + gkyl_msgpack_data_release(mt); } -void -gk_neut_species_write_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +void gk_neut_species_write_mom_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { // Package metadata. gkyl_msgpack_map_elem_set_double(gkns->io_meta_phase_len, gkns->io_meta_phase, "time", tm); gkyl_msgpack_map_elem_set_uint(gkns->io_meta_phase_len, gkns->io_meta_phase, "frame", frame); - for (int m=0; minfo.num_diag_moments; ++m) { + for (int m = 0; m < gkns->info.num_diag_moments; ++m) { struct timespec wst = gkyl_wall_clock(); gk_neut_species_moment_calc(&gkns->moms[m], gkns->local, app->local, gkns->f); app->stat.n_neut_mom += 1; - // Rescale moment by inverse of Jacobian if necessary. - gk_neut_species_moment_diag_jacobgeo_div(app, &gkns->moms[m], gkns->moms[m].marr, gkns->moms[m].marr); + // Rescale moment by inverse of Jacobian if necessary. + gk_neut_species_moment_diag_jacobgeo_div( + app, &gkns->moms[m], gkns->moms[m].marr, gkns->moms[m].marr + ); app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); struct timespec wtm = gkyl_wall_clock(); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(gkns->moms[m].marr_host, gkns->moms[m].marr); + } struct gkyl_msgpack_map_elem desc_mom[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, - .cval = (char*)gkyl_distribution_moments_descriptions[gkns->info.diag_moments[m]] } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = (char *)gkyl_distribution_moments_descriptions[gkns->info.diag_moments[m]]} }; int io_meta_len[] = {gkns->io_meta_phase_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_phase, app->gk_geom->io_meta_basic, desc_mom}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_phase, app->gk_geom->io_meta_basic, desc_mom + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); const char *fmt = "%s-%s_%s_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, - gkyl_distribution_moments_strs[gkns->info.diag_moments[m]], frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, - gkyl_distribution_moments_strs[gkns->info.diag_moments[m]], frame); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, - gkns->moms[m].marr_host, fileNm); - gkyl_msgpack_data_release(mt); + int sz = gkyl_calc_strlen( + fmt, app->name, gkns->info.name, gkyl_distribution_moments_strs[gkns->info.diag_moments[m]], + frame + ); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, + gkyl_distribution_moments_strs[gkns->info.diag_moments[m]], frame + ); + + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, gkns->moms[m].marr_host, fileNm); + gkyl_msgpack_data_release(mt); app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wtm); app->stat.n_neut_diag_io += 1; } } -void -gk_neut_species_calc_integrated_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm) +void gk_neut_species_calc_integrated_mom_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm +) { struct timespec wst = gkyl_wall_clock(); int num_mom = gkns->integ_moms.num_mom; double avals_global[num_mom]; - - gk_neut_species_moment_calc(&gkns->integ_moms, gkns->local, app->local, gkns->f); + + gk_neut_species_moment_calc(&gkns->integ_moms, gkns->local, app->local, gkns->f); app->stat.n_neut_mom += 1; // Reduce to compute sum over whole domain, append to diagnostics. gkyl_array_reduce_range(gkns->red_integ_diag, gkns->integ_moms.marr, GKYL_SUM, &app->local); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, - gkns->red_integ_diag, gkns->red_integ_diag_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, gkns->red_integ_diag, gkns->red_integ_diag_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, gkns->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, gkns->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, gkns->red_integ_diag_global, sizeof(double[num_mom])); } gkyl_dynvec_append(gkns->integ_diag, tm, avals_global); @@ -287,33 +312,38 @@ gk_neut_species_calc_integrated_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk app->stat.n_neut_diag += 1; } -void -gk_neut_species_write_integrated_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns) +void gk_neut_species_write_integrated_mom_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns +) { struct timespec wst = gkyl_wall_clock(); - + int rank; gkyl_comm_get_rank(app->comm, &rank); if (rank == 0) { // Write integrated diagnostic moments. const char *fmt = "%s-%s_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, "integrated_moms"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, "integrated_moms"); - + if (gkns->is_first_integ_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated moments of neutral species." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Volume integrated moments of neutral species."} }; int io_meta_len[] = {gkns->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(gkns->integ_diag, fileNm, mt); gkns->is_first_integ_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(gkns->integ_diag, fileNm); } } @@ -323,58 +353,65 @@ gk_neut_species_write_integrated_mom_dynamic(gkyl_gyrokinetic_app* app, struct g app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wst); } -void -gk_neut_species_write_static(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +void gk_neut_species_write_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { // Do nothing. } -void -gk_neut_species_write_init_only(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +void gk_neut_species_write_init_only( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { gk_neut_species_write_dynamic(app, gkns, tm, frame); gkns->write_func = gk_neut_species_write_static; } -void -gk_neut_species_write_mom_static(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +void gk_neut_species_write_mom_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { // Do nothing. } -void -gk_neut_species_write_mom_init_only(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +void gk_neut_species_write_mom_init_only( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { gk_neut_species_write_mom_dynamic(app, gkns, tm, frame); gkns->write_mom_func = gk_neut_species_write_mom_static; } -void -gk_neut_species_calc_integrated_mom_static(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm) +void gk_neut_species_calc_integrated_mom_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm +) { // Do nothing. } -void -gk_neut_species_write_integrated_mom_static(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns) +void gk_neut_species_write_integrated_mom_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns +) { // Do nothing. } -void -gk_neut_species_n_iter_corr_enabled(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx) +void gk_neut_species_n_iter_corr_enabled( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx +) { app->stat.neut_num_corr[sidx] = gkns->lte.num_corr; app->stat.neut_n_iter_corr[sidx] = gkns->lte.n_iter; } -void -gk_neut_species_n_iter_corr_disabled(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx) +void gk_neut_species_n_iter_corr_disabled( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx +) { } -void -gk_neut_species_release_static(const gkyl_gyrokinetic_app* app, const struct gk_neut_species *s) -{ +void gk_neut_species_release_static(const gkyl_gyrokinetic_app *app, const struct gk_neut_species *s) +{ // Do nothing. } diff --git a/gyrokinetic/apps/gk_neut_species_bflux.c b/gyrokinetic/apps/gk_neut_species_bflux.c index f7750e4c2f..7668ff08d1 100644 --- a/gyrokinetic/apps/gk_neut_species_bflux.c +++ b/gyrokinetic/apps/gk_neut_species_bflux.c @@ -3,402 +3,489 @@ #include static int -gk_neut_species_bflux_idx(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge) { +gk_neut_species_bflux_idx(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge) +{ // Given a direction 'dir' and an edge 'edge' return the boundary index. - for (int b=0; bnum_boundaries; ++b) { - if (dir == bflux->boundaries_dir[b] && edge == bflux->boundaries_edge[b]) + for (int b = 0; b < bflux->num_boundaries; ++b) { + if (dir == bflux->boundaries_dir[b] && edge == bflux->boundaries_edge[b]) { return b; + } } return -1; } -static void -gk_neut_species_bflux_clear_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +static void gk_neut_species_bflux_clear_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_clear_range(fin[b*bflux->num_calc_moms+m], val, bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_clear_range( + fin[b * bflux->num_calc_moms + m], val, bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_neut_species_bflux_clear_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +static void gk_neut_species_bflux_clear_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { // Do nothing. } -void -gk_neut_species_bflux_clear(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +void gk_neut_species_bflux_clear( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { bflux->bflux_clear_func(app, bflux, fin, val); } -static void -gk_neut_species_bflux_scale_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +static void gk_neut_species_bflux_scale_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_scale_range(fin[b*bflux->num_calc_moms+m], val, bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_scale_range( + fin[b * bflux->num_calc_moms + m], val, bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_neut_species_bflux_scale_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +static void gk_neut_species_bflux_scale_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { // Do nothing. } -void -gk_neut_species_bflux_scale(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +void gk_neut_species_bflux_scale( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { bflux->bflux_scale_func(app, bflux, fin, val); } -static void -gk_neut_species_bflux_step_f_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double dt, struct gkyl_array **fin) +static void gk_neut_species_bflux_step_f_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double dt, + struct gkyl_array **fin +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_accumulate_range(gkyl_array_scale_range(fout[b*bflux->num_calc_moms+m], dt, bflux->boundaries_conf_ghost[b]), - 1.0, fin[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_accumulate_range( + gkyl_array_scale_range( + fout[b * bflux->num_calc_moms + m], dt, bflux->boundaries_conf_ghost[b] + ), + 1.0, fin[b * bflux->num_calc_moms + m], bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_neut_species_bflux_step_f_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double dt, struct gkyl_array **fin) +static void gk_neut_species_bflux_step_f_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double dt, + struct gkyl_array **fin +) { // Do nothing. } -void -gk_neut_species_bflux_step_f(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double dt, struct gkyl_array **fin) +void gk_neut_species_bflux_step_f( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double dt, + struct gkyl_array **fin +) { bflux->bflux_step_f_func(app, bflux, fout, dt, fin); } -static void -gk_neut_species_bflux_set_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +static void gk_neut_species_bflux_set_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_set_range(fout[b*bflux->num_calc_moms+m], - fac, fin[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_set_range( + fout[b * bflux->num_calc_moms + m], fac, fin[b * bflux->num_calc_moms + m], + bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_neut_species_bflux_set_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +static void gk_neut_species_bflux_set_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { } -void -gk_neut_species_bflux_set(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +void gk_neut_species_bflux_set( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { bflux->bflux_set_func(app, bflux, fout, fac, fin); } -static void -gk_neut_species_bflux_accumulate_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +static void gk_neut_species_bflux_accumulate_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_accumulate_range(fout[b*bflux->num_calc_moms+m], - fac, fin[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_accumulate_range( + fout[b * bflux->num_calc_moms + m], fac, fin[b * bflux->num_calc_moms + m], + bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_neut_species_bflux_accumulate_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +static void gk_neut_species_bflux_accumulate_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { } -void -gk_neut_species_bflux_accumulate(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +void gk_neut_species_bflux_accumulate( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { bflux->bflux_accumulate_func(app, bflux, fout, fac, fin); } -static void -gk_neut_species_bflux_combine_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2) +static void gk_neut_species_bflux_combine_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2 +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_accumulate_range(gkyl_array_set_range(fout[b*bflux->num_calc_moms+m], - fac1, fin1[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]), - fac2, fin2[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_accumulate_range( + gkyl_array_set_range( + fout[b * bflux->num_calc_moms + m], fac1, fin1[b * bflux->num_calc_moms + m], + bflux->boundaries_conf_ghost[b] + ), + fac2, fin2[b * bflux->num_calc_moms + m], bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_neut_species_bflux_combine_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2) +static void gk_neut_species_bflux_combine_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2 +) { } -void -gk_neut_species_bflux_combine(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2) +void gk_neut_species_bflux_combine( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2 +) { bflux->bflux_combine_func(app, bflux, fout, fac1, fin1, fac2, fin2); } -static void -gk_neut_species_bflux_copy_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, struct gkyl_array **fin) +static void gk_neut_species_bflux_copy_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + struct gkyl_array **fin +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_copy_range(fout[b*bflux->num_calc_moms+m], fin[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_copy_range( + fout[b * bflux->num_calc_moms + m], fin[b * bflux->num_calc_moms + m], + bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_neut_species_bflux_copy_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, struct gkyl_array **fin) +static void gk_neut_species_bflux_copy_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + struct gkyl_array **fin +) { } -void -gk_neut_species_bflux_copy(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, struct gkyl_array **fin) +void gk_neut_species_bflux_copy( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + struct gkyl_array **fin +) { bflux->bflux_copy_func(app, bflux, fout, fin); } -void -gk_neut_species_bflux_rhs_calc(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_neut_species_bflux_rhs_calc( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *fin, + struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { // Ghost cells of the rhs array are filled with the bflux. This is overwritten // by the boundary conditions, but it is used before that happens. gkyl_array_clear_range(rhs, 0.0, bflux->boundaries_phase_ghost[b]); gkyl_boundary_flux_advance(bflux->flux_slvr[b], fin, rhs); - gkyl_array_copy_range_to_range(bflux->flux[b], rhs, &bflux->boundaries_phase_ghost_nosub[b], bflux->boundaries_phase_ghost[b]); + gkyl_array_copy_range_to_range( + bflux->flux[b], rhs, &bflux->boundaries_phase_ghost_nosub[b], bflux->boundaries_phase_ghost[b] + ); } app->stat.neut_species_bflux_calc_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_neut_species_bflux_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_neut_species_bflux_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *fin, + struct gkyl_array *rhs +) { } -void -gk_neut_species_bflux_rhs(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_neut_species_bflux_rhs( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *fin, + struct gkyl_array *rhs +) { bflux->bflux_rhs_func(app, bflux, fin, rhs); } -static void -gk_neut_species_bflux_calc_moms_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +static void gk_neut_species_bflux_calc_moms_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *rhs, + struct gkyl_array **bflux_moms +) { struct timespec wst = gkyl_wall_clock(); // Compute moments of boundary fluxes. - for (int b=0; bnum_boundaries; ++b) { - for (int m=0; mnum_calc_moms; m++) { - gk_neut_species_moment_calc(&bflux->moms_op[m], *bflux->boundaries_phase_ghost[b], *bflux->boundaries_conf_ghost[b], rhs); - - gkyl_array_copy_range(bflux_moms[b*bflux->num_calc_moms+m], bflux->moms_op[m].marr, bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gk_neut_species_moment_calc( + &bflux->moms_op[m], *bflux->boundaries_phase_ghost[b], *bflux->boundaries_conf_ghost[b], rhs + ); + + gkyl_array_copy_range( + bflux_moms[b * bflux->num_calc_moms + m], bflux->moms_op[m].marr, + bflux->boundaries_conf_ghost[b] + ); } } app->stat.neut_species_bflux_moms_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_neut_species_bflux_calc_moms_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +static void gk_neut_species_bflux_calc_moms_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *rhs, + struct gkyl_array **bflux_moms +) { // Do nothing. } -void -gk_neut_species_bflux_calc_moms(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +void gk_neut_species_bflux_calc_moms( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *rhs, + struct gkyl_array **bflux_moms +) { bflux->bflux_calc_moms_func(app, bflux, rhs, bflux_moms); } -static void -gk_neut_species_bflux_get_flux_mom_enabled(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, const struct gkyl_range *out_rng) +static void gk_neut_species_bflux_get_flux_mom_enabled( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, + enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { int b = gk_neut_species_bflux_idx(bflux, dir, edge); int mom_idx = -1; - for (int m=0; mnum_calc_moms; m++) { + for (int m = 0; m < bflux->num_calc_moms; m++) { if (bflux->calc_mom_names[m] == mom_type) { mom_idx = m; break; } } - gkyl_array_copy_range_to_range(out, bflux_moms[b*bflux->num_calc_moms+mom_idx], out_rng, bflux->boundaries_conf_ghost[b]); + gkyl_array_copy_range_to_range( + out, bflux_moms[b * bflux->num_calc_moms + mom_idx], out_rng, bflux->boundaries_conf_ghost[b] + ); } -static void -gk_neut_species_bflux_get_flux_mom_disabled(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, const struct gkyl_range *out_rng) +static void gk_neut_species_bflux_get_flux_mom_disabled( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, + enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { // Do nothing. } -void -gk_neut_species_bflux_get_flux_mom(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, const struct gkyl_range *out_rng) +void gk_neut_species_bflux_get_flux_mom( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, + enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { bflux->bflux_get_flux_mom_func(bflux, dir, edge, mom_type, bflux_moms, out, out_rng); } -static void -gk_neut_species_bflux_get_flux_enabled(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - struct gkyl_array *out, const struct gkyl_range *out_rng) +static void gk_neut_species_bflux_get_flux_enabled( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { int b = gk_neut_species_bflux_idx(bflux, dir, edge); gkyl_array_copy_range_to_range(out, bflux->flux[b], out_rng, bflux->boundaries_phase_ghost[b]); } -static void -gk_neut_species_bflux_get_flux_disabled(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - struct gkyl_array *out, const struct gkyl_range *out_rng) +static void gk_neut_species_bflux_get_flux_disabled( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { } -void -gk_neut_species_bflux_get_flux(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - struct gkyl_array *out, const struct gkyl_range *out_rng) +void gk_neut_species_bflux_get_flux( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { bflux->bflux_get_flux_func(bflux, dir, edge, out, out_rng); } -void -gk_neut_species_bflux_calc_integrated_mom_enabled(gkyl_gyrokinetic_app* app, - void *spec_in, struct gk_boundary_fluxes *bflux, double tm) +void gk_neut_species_bflux_calc_integrated_mom_enabled( + gkyl_gyrokinetic_app *app, void *spec_in, struct gk_boundary_fluxes *bflux, double tm +) { struct timespec wst = gkyl_wall_clock(); const struct gk_neut_species *gkns = spec_in; int num_diag_int_mom = gkns->info.boundary_flux_diagnostics.num_integrated_diag_moments; - for (int m=0; mdiag_int_mom_idx[m]; - int num_mom_comp = bflux->moms_op[int_mom_idx].num_mom; + int num_mom_comp = bflux->moms_op[int_mom_idx].num_mom; double avals_global[num_mom_comp]; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { // Integrated moment of the boundary flux. int dir = bflux->boundaries_dir[b]; - gkyl_array_integrate_advance(bflux->integ_op[m], bflux->f[b*bflux->num_calc_moms+int_mom_idx], 1.0, 0, - bflux->boundaries_conf_ghost[b], 0, bflux->int_moms_local); - - gkyl_comm_allreduce(app->comm_plane[dir], GKYL_DOUBLE, GKYL_SUM, num_mom_comp, - bflux->int_moms_local, bflux->int_moms_global); + gkyl_array_integrate_advance( + bflux->integ_op[m], bflux->f[b * bflux->num_calc_moms + int_mom_idx], 1.0, 0, + bflux->boundaries_conf_ghost[b], 0, bflux->int_moms_local + ); + + gkyl_comm_allreduce( + app->comm_plane[dir], GKYL_DOUBLE, GKYL_SUM, num_mom_comp, bflux->int_moms_local, + bflux->int_moms_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp])); } - gkyl_dynvec_append(bflux->intmom[b*num_diag_int_mom+m], tm, avals_global); - - } - } + gkyl_dynvec_append(bflux->intmom[b * num_diag_int_mom + m], tm, avals_global); + } + } app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_neut_species_bflux_calc_voltime_integrated_mom_enabled(gkyl_gyrokinetic_app* app, - void *spec_in, struct gk_boundary_fluxes *bflux, double tm) +static void gk_neut_species_bflux_calc_voltime_integrated_mom_enabled( + gkyl_gyrokinetic_app *app, void *spec_in, struct gk_boundary_fluxes *bflux, double tm +) { const struct gk_neut_species *gkns = spec_in; int num_diag_int_mom = gkns->info.boundary_flux_diagnostics.num_integrated_diag_moments; - for (int m=0; mdiag_int_mom_idx[m]; - int num_mom_comp = bflux->moms_op[int_mom_idx].num_mom; + int num_mom_comp = bflux->moms_op[int_mom_idx].num_mom; double avals_global[num_mom_comp]; double *intmom_cumm_buff = bflux->intmom_cumm_buff[m]; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { // Integrated moment of the boundary flux. int dir = bflux->boundaries_dir[b]; - gkyl_array_integrate_advance(bflux->integ_op[m], bflux->f[b*bflux->num_calc_moms+int_mom_idx], 1., 0, - bflux->boundaries_conf_ghost[b], 0, bflux->int_moms_local); - - gkyl_comm_allreduce(app->comm_plane[dir], GKYL_DOUBLE, GKYL_SUM, num_mom_comp, - bflux->int_moms_local, bflux->int_moms_global); + gkyl_array_integrate_advance( + bflux->integ_op[m], bflux->f[b * bflux->num_calc_moms + int_mom_idx], 1., 0, + bflux->boundaries_conf_ghost[b], 0, bflux->int_moms_local + ); + + gkyl_comm_allreduce( + app->comm_plane[dir], GKYL_DOUBLE, GKYL_SUM, num_mom_comp, bflux->int_moms_local, + bflux->int_moms_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp])); } - for (int k=0; kbflux_calc_voltime_int_mom_func(app, species, bflux, tm); } -static void -gk_neut_species_bflux_append_integrated_mom(gkyl_gyrokinetic_app* app, - void *species, struct gk_boundary_fluxes *bflux, double tm) +static void gk_neut_species_bflux_append_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm +) { struct timespec wst = gkyl_wall_clock(); // Append the time integrated moment of the boundary flux. const struct gk_neut_species *gkns = species; int num_diag_int_mom = gkns->info.boundary_flux_diagnostics.num_integrated_diag_moments; - for (int m=0; mdiag_int_mom_idx[m]; int num_mom_comp = bflux->moms_op[int_mom_idx].num_mom; double *intmom_cumm_buff = bflux->intmom_cumm_buff[m]; - for (int b=0; bnum_boundaries; ++b) - gkyl_dynvec_append(bflux->intmom[b*num_diag_int_mom+m], tm, &intmom_cumm_buff[b*num_mom_comp]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + gkyl_dynvec_append( + bflux->intmom[b * num_diag_int_mom + m], tm, &intmom_cumm_buff[b * num_mom_comp] + ); + } } app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_neut_species_bflux_calc_integrated_mom_disabled(gkyl_gyrokinetic_app* app, - void *species, struct gk_boundary_fluxes *bflux, double tm) +static void gk_neut_species_bflux_calc_integrated_mom_disabled( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm +) { } -void -gk_neut_species_bflux_calc_integrated_mom(gkyl_gyrokinetic_app* app, - void *species, struct gk_boundary_fluxes *bflux, double tm) +void gk_neut_species_bflux_calc_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm +) { bflux->bflux_calc_integrated_mom_func(app, species, bflux, tm); } - -static void -gk_neut_species_bflux_write_integrated_mom_enabled(gkyl_gyrokinetic_app *app, - void *species, struct gk_boundary_fluxes *bflux) + +static void gk_neut_species_bflux_write_integrated_mom_enabled( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux +) { struct timespec wtm = gkyl_wall_clock(); const struct gk_neut_species *gkns = species; @@ -407,68 +494,76 @@ gk_neut_species_bflux_write_integrated_mom_enabled(gkyl_gyrokinetic_app *app, gkyl_comm_get_rank(app->comm, &rank); gkyl_comm_get_size(app->comm, &comm_size); - const char *vars[] = {"x","y","z"}; - const char *edge[] = {"lower","upper"}; + const char *vars[] = {"x", "y", "z"}; + const char *edge[] = {"lower", "upper"}; int num_diag_int_mom = gkns->info.boundary_flux_diagnostics.num_integrated_diag_moments; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; - int edi = bflux->boundaries_edge[b]==GKYL_LOWER_EDGE? 0 : 1; + int edi = bflux->boundaries_edge[b] == GKYL_LOWER_EDGE ? 0 : 1; - if ((edi == 0 && rank == 0) || (edi == 1 && rank == comm_size-1)) { - for (int m=0; minfo.boundary_flux_diagnostics.integrated_diag_moments[m]]; + const char *mom_name = gkyl_distribution_moments_strs[gkns->info.boundary_flux_diagnostics + .integrated_diag_moments[m]]; int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, vars[dir], edge[edi], mom_name); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, vars[dir], edge[edi], mom_name); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, vars[dir], edge[edi], mom_name + ); struct timespec wtm = gkyl_wall_clock(); if (bflux->is_first_intmom_write_call[b]) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated moments of the boundary flux." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Volume integrated moments of the boundary flux."} }; int io_meta_len[] = {gkns->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); - gkyl_dynvec_write_wmeta(bflux->intmom[b*num_diag_int_mom+m], fileNm, mt); + gkyl_dynvec_write_wmeta(bflux->intmom[b * num_diag_int_mom + m], fileNm, mt); gkyl_msgpack_data_release(mt); - } - else { - gkyl_dynvec_awrite(bflux->intmom[b*num_diag_int_mom+m], fileNm); + } else { + gkyl_dynvec_awrite(bflux->intmom[b * num_diag_int_mom + m], fileNm); } app->stat.n_diag_io += 1; - gkyl_dynvec_clear(bflux->intmom[b*num_diag_int_mom+m]); - - if (bflux->is_first_intmom_write_call[b]) + gkyl_dynvec_clear(bflux->intmom[b * num_diag_int_mom + m]); + + if (bflux->is_first_intmom_write_call[b]) { bflux->is_first_intmom_write_call[b] = false; + } } } } app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wtm); } -static void -gk_neut_species_bflux_write_integrated_mom_disabled(gkyl_gyrokinetic_app *app, - void *species, struct gk_boundary_fluxes *bflux) +static void gk_neut_species_bflux_write_integrated_mom_disabled( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux +) { } -void -gk_neut_species_bflux_write_integrated_mom(gkyl_gyrokinetic_app *app, - void *species, struct gk_boundary_fluxes *bflux) +void gk_neut_species_bflux_write_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux +) { bflux->bflux_write_integrated_mom_func(app, species, bflux); } -static void -gk_neut_species_bflux_write_mom_enabled(gkyl_gyrokinetic_app* app, void *species, - struct gk_boundary_fluxes *bflux, double tm, int frame) +static void gk_neut_species_bflux_write_mom_enabled( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm, int frame +) { const struct gk_neut_species *gkns = species; @@ -476,109 +571,129 @@ gk_neut_species_bflux_write_mom_enabled(gkyl_gyrokinetic_app* app, void *species gkyl_msgpack_map_elem_set_double(gkns->io_meta_conf_len, gkns->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gkns->io_meta_conf_len, gkns->io_meta_conf, "frame", frame); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Velocity-space moment of the boundary flux." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Velocity-space moment of the boundary flux."} }; int io_meta_len[] = {gkns->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); int rank, comm_size; gkyl_comm_get_rank(app->comm, &rank); gkyl_comm_get_size(app->comm, &comm_size); - const char *vars[] = {"x","y","z"}; - const char *edge[] = {"lower","upper"}; + const char *vars[] = {"x", "y", "z"}; + const char *edge[] = {"lower", "upper"}; int num_diag_mom = gkns->info.boundary_flux_diagnostics.num_diag_moments; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; - int edi = bflux->boundaries_edge[b]==GKYL_LOWER_EDGE? 0 : 1; + int edi = bflux->boundaries_edge[b] == GKYL_LOWER_EDGE ? 0 : 1; - if ((edi == 0 && rank == 0) || (edi == 1 && rank == comm_size-1)) { - for (int m=0; mdiag_mom_idx[m]; - struct gkyl_array *mom_arr = bflux->f[b*bflux->num_calc_moms+mom_idx]; + struct gkyl_array *mom_arr = bflux->f[b * bflux->num_calc_moms + mom_idx]; // For now copy the moment to the skin ghost and write it out. - gkyl_array_copy_range_to_range(mom_arr, mom_arr, - bflux->boundaries_conf_skin[b], bflux->boundaries_conf_ghost[b]); + gkyl_array_copy_range_to_range( + mom_arr, mom_arr, bflux->boundaries_conf_skin[b], bflux->boundaries_conf_ghost[b] + ); // Rescale by dx/2 in the direction of the boundary to account for the // normalization in the boundary surf kernels. - gkyl_array_scale_range(mom_arr, 0.5*app->grid.dx[dir], bflux->boundaries_conf_skin[b]); + gkyl_array_scale_range(mom_arr, 0.5 * app->grid.dx[dir], bflux->boundaries_conf_skin[b]); app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); - + const char *fmt = "%s-%s_bflux_%s%s_%s_%d.gkyl"; - const char *mom_name = gkyl_distribution_moments_strs[gkns->info.boundary_flux_diagnostics.diag_moments[mom_idx]]; - int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, vars[dir], edge[edi], mom_name, frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, vars[dir], edge[edi], mom_name, frame); - + const char *mom_name = + gkyl_distribution_moments_strs[gkns->info.boundary_flux_diagnostics.diag_moments[mom_idx]]; + int sz = + gkyl_calc_strlen(fmt, app->name, gkns->info.name, vars[dir], edge[edi], mom_name, frame); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, vars[dir], edge[edi], mom_name, + frame + ); + struct timespec wtm = gkyl_wall_clock(); if (app->cdim > 1) { struct timespec wst = gkyl_wall_clock(); // Project the moment down to lower dimensions. int num_mom_comp = bflux->moms_op[mom_idx].num_mom; - gkyl_translate_dim_advance(bflux->transdim[b], bflux->boundaries_conf_skin_fullx[b], &bflux->surf_local[dir], - mom_arr, num_mom_comp, bflux->mom_surf[b*num_diag_mom+m]); + gkyl_translate_dim_advance( + bflux->transdim[b], bflux->boundaries_conf_skin_fullx[b], &bflux->surf_local[dir], + mom_arr, num_mom_comp, bflux->mom_surf[b * num_diag_mom + m] + ); app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); struct timespec wtm = gkyl_wall_clock(); - if (app->use_gpu) - gkyl_array_copy(bflux->mom_surf_ho[b*num_diag_mom+m], bflux->mom_surf[b*num_diag_mom+m]); - - gkyl_comm_array_write(bflux->comm_surf[dir], &bflux->grid_surf[dir], &bflux->surf_local[dir], mt, - bflux->mom_surf_ho[b*num_diag_mom+m], fileNm); + if (app->use_gpu) { + gkyl_array_copy( + bflux->mom_surf_ho[b * num_diag_mom + m], bflux->mom_surf[b * num_diag_mom + m] + ); + } + + gkyl_comm_array_write( + bflux->comm_surf[dir], &bflux->grid_surf[dir], &bflux->surf_local[dir], mt, + bflux->mom_surf_ho[b * num_diag_mom + m], fileNm + ); app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wtm); - } - else { + } else { // Don't project down to 0D; the infrastructure doesn't make it easy to do so. struct timespec wtm = gkyl_wall_clock(); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(bflux->moms_op[mom_idx].marr_host, mom_arr); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, - bflux->moms_op[mom_idx].marr_host, fileNm); + } + + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, bflux->moms_op[mom_idx].marr_host, fileNm + ); app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wtm); } - + app->stat.n_diag_io += 1; } } } - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); } -static void -gk_neut_species_bflux_write_mom_disabled(gkyl_gyrokinetic_app* app, void *species, - struct gk_boundary_fluxes *bflux, double tm, int frame) +static void gk_neut_species_bflux_write_mom_disabled( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm, int frame +) { } -void -gk_neut_species_bflux_write_mom(gkyl_gyrokinetic_app* app, void *species, - struct gk_boundary_fluxes *bflux, double tm, int frame) +void gk_neut_species_bflux_write_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm, int frame +) { bflux->bflux_write_mom_func(app, species, bflux, tm, frame); } -static int * -bflux_unionize_moms(int num_add_moms, enum gkyl_distribution_moments add_moms[BFLUX_MAX_MOM_NAMES], - int *num_moms, enum gkyl_distribution_moments moms[BFLUX_MAX_MOM_NAMES]) +static int *bflux_unionize_moms( + int num_add_moms, enum gkyl_distribution_moments add_moms[BFLUX_MAX_MOM_NAMES], int *num_moms, + enum gkyl_distribution_moments moms[BFLUX_MAX_MOM_NAMES] +) { // Check if each of the num_add_moms moments in add_moms is included in the // moms list of num_moms moments. If it's not, include it and increment // num_moms. Return a list of the indices of each add_moms in the moms list. - int *add_mom_idx = gkyl_malloc(num_add_moms*sizeof(int)); + int *add_mom_idx = gkyl_malloc(num_add_moms * sizeof(int)); int num_moms_base = num_moms[0]; - for (int i=0; iallocated_solver = false; @@ -620,74 +735,88 @@ gk_neut_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, bflux->bflux_copy_func = gk_neut_species_bflux_copy_disabled; bflux->bflux_calc_integrated_mom_func = gk_neut_species_bflux_calc_integrated_mom_disabled; bflux->bflux_write_integrated_mom_func = gk_neut_species_bflux_write_integrated_mom_disabled; - bflux->bflux_calc_voltime_int_mom_func = gk_neut_species_bflux_calc_voltime_integrated_mom_disabled; + bflux->bflux_calc_voltime_int_mom_func = + gk_neut_species_bflux_calc_voltime_integrated_mom_disabled; bflux->bflux_write_mom_func = gk_neut_species_bflux_write_mom_disabled; if (bflux_type != GK_SPECIES_BFLUX_NONE) { bflux->allocated_solver = true; // Set function pointer to compute bfluxes. - bflux->bflux_rhs_func = gk_neut_species_bflux_rhs_calc; + bflux->bflux_rhs_func = gk_neut_species_bflux_rhs_calc; bflux->bflux_get_flux_func = gk_neut_species_bflux_get_flux_enabled; // Identify the non-periodic, non-zero-flux boundaries to compute boundary fluxes at. bflux->num_boundaries = 0; - for (int d=0; dcdim; ++d) { - for (int e=0; e<2; ++e) { - if ( gkns->bc_is_np[d] && - ((e == 0 && gkns->lower_bc[d].type != GKYL_BC_GK_SPECIES_ZERO_FLUX) || - (e == 1 && gkns->upper_bc[d].type != GKYL_BC_GK_SPECIES_ZERO_FLUX)) ) { + for (int d = 0; d < app->cdim; ++d) { + for (int e = 0; e < 2; ++e) { + if (gkns->bc_is_np[d] && + ((e == 0 && gkns->lower_bc[d].type != GKYL_BC_GK_SPECIES_ZERO_FLUX) || + (e == 1 && gkns->upper_bc[d].type != GKYL_BC_GK_SPECIES_ZERO_FLUX))) { bflux->boundaries_dir[bflux->num_boundaries] = d; - bflux->boundaries_edge[bflux->num_boundaries] = e==0? GKYL_LOWER_EDGE : GKYL_UPPER_EDGE; - bflux->boundaries_conf_skin[bflux->num_boundaries] = e==0? &app->local_lower_skin[d] : &app->local_upper_skin[d]; - bflux->boundaries_conf_ghost[bflux->num_boundaries] = e==0? &app->local_lower_ghost[d] : &app->local_upper_ghost[d]; - bflux->boundaries_phase_ghost[bflux->num_boundaries] = e==0? &gkns->local_lower_ghost[d] : &gkns->local_upper_ghost[d]; + bflux->boundaries_edge[bflux->num_boundaries] = e == 0 ? GKYL_LOWER_EDGE : + GKYL_UPPER_EDGE; + bflux->boundaries_conf_skin[bflux->num_boundaries] = e == 0 ? &app->local_lower_skin[d] : + &app->local_upper_skin[d]; + bflux->boundaries_conf_ghost[bflux->num_boundaries] = + e == 0 ? &app->local_lower_ghost[d] : &app->local_upper_ghost[d]; + bflux->boundaries_phase_ghost[bflux->num_boundaries] = + e == 0 ? &gkns->local_lower_ghost[d] : &gkns->local_upper_ghost[d]; bflux->num_boundaries++; } } } - + // Create an array of equation objects with terms that produce boundary fluxes. bflux->num_eqns = 0; - if (gkns->collisionless.collisionless_id == GKYL_GK_COLLISIONLESS_NEUTRAL) + if (gkns->collisionless.collisionless_id == GKYL_GK_COLLISIONLESS_NEUTRAL) { bflux->num_eqns += 1; // Collisionless terms. + } - bflux->eqns = gkyl_malloc(bflux->num_eqns*sizeof(struct gkyl_dg_eqn *)); + bflux->eqns = gkyl_malloc(bflux->num_eqns * sizeof(struct gkyl_dg_eqn *)); int eqc = 0; - if (gkns->collisionless.collisionless_id == GKYL_GK_COLLISIONLESS_NEUTRAL) + if (gkns->collisionless.collisionless_id == GKYL_GK_COLLISIONLESS_NEUTRAL) { bflux->eqns[eqc++] = gkyl_dg_updater_vlasov_acquire_eqn(gkns->collisionless.vlasov_slvr); - + } + // Allocate updater that computes boundary fluxes. - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; - struct gkyl_range *skin_r = bflux->boundaries_edge[b]==GKYL_LOWER_EDGE? &gkns->local_lower_skin[dir] - : &gkns->local_upper_skin[dir]; - struct gkyl_range *ghost_r = bflux->boundaries_edge[b]==GKYL_LOWER_EDGE? &gkns->local_lower_ghost[dir] - : &gkns->local_upper_ghost[dir]; - bflux->flux_slvr[b] = gkyl_boundary_flux_new(dir, bflux->boundaries_edge[b], &gkns->grid, - skin_r, ghost_r, bflux->num_eqns, bflux->eqns, app->use_gpu); + struct gkyl_range *skin_r = bflux->boundaries_edge[b] == GKYL_LOWER_EDGE ? + &gkns->local_lower_skin[dir] : + &gkns->local_upper_skin[dir]; + struct gkyl_range *ghost_r = bflux->boundaries_edge[b] == GKYL_LOWER_EDGE ? + &gkns->local_lower_ghost[dir] : + &gkns->local_upper_ghost[dir]; + bflux->flux_slvr[b] = gkyl_boundary_flux_new( + dir, bflux->boundaries_edge[b], &gkns->grid, skin_r, ghost_r, bflux->num_eqns, bflux->eqns, + app->use_gpu + ); } // Create a ghost range that the flux lives on, and allocate the array that stores the flux. int ndim = gkns->local.ndim; - bflux->boundaries_phase_ghost_nosub = gkyl_malloc(bflux->num_boundaries*sizeof(struct gkyl_range)); - bflux->flux = gkyl_malloc(bflux->num_boundaries*sizeof(struct gkyl_array *)); - for (int b=0; bnum_boundaries; ++b) { + bflux->boundaries_phase_ghost_nosub = + gkyl_malloc(bflux->num_boundaries * sizeof(struct gkyl_range)); + bflux->flux = gkyl_malloc(bflux->num_boundaries * sizeof(struct gkyl_array *)); + for (int b = 0; b < bflux->num_boundaries; ++b) { int rlower[ndim], rupper[ndim]; - for (int d=0; dboundaries_phase_ghost[b]->lower[d]; rupper[d] = bflux->boundaries_phase_ghost[b]->upper[d]; } gkyl_range_init(&bflux->boundaries_phase_ghost_nosub[b], ndim, rlower, rupper); - bflux->flux[b] = mkarr(app->use_gpu, gkns->basis.num_basis, bflux->boundaries_phase_ghost_nosub[b].volume); + bflux->flux[b] = + mkarr(app->use_gpu, gkns->basis.num_basis, bflux->boundaries_phase_ghost_nosub[b].volume); } } int num_diag_mom = gkns->info.boundary_flux_diagnostics.num_diag_moments; int num_diag_int_mom = gkns->info.boundary_flux_diagnostics.num_integrated_diag_moments; - - if (bflux_type == GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS || bflux_type == GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS_DIAGS) { + + if (bflux_type == GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS || + bflux_type == GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS_DIAGS) { bflux->allocated_moms = true; // Set methods for time-stepping boundary fluxes needed for diagnostics. @@ -704,88 +833,106 @@ gk_neut_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, // Create a union of the diag_moms, int_diag_moms and add_moms lists. Also store // the index of each mom in this union list. int num_add_mom = add_moms_inp.num_diag_moments; - assert(num_add_mom+num_diag_mom+num_diag_int_mom < BFLUX_MAX_MOM_NAMES+1); + assert(num_add_mom + num_diag_mom + num_diag_int_mom < BFLUX_MAX_MOM_NAMES + 1); bflux->num_calc_moms = 0; - if (num_diag_mom > 0) - bflux->diag_mom_idx = bflux_unionize_moms(num_diag_mom, - gkns->info.boundary_flux_diagnostics.diag_moments, &bflux->num_calc_moms, bflux->calc_mom_names); + if (num_diag_mom > 0) { + bflux->diag_mom_idx = bflux_unionize_moms( + num_diag_mom, gkns->info.boundary_flux_diagnostics.diag_moments, &bflux->num_calc_moms, + bflux->calc_mom_names + ); + } - if (num_diag_int_mom > 0) - bflux->diag_int_mom_idx = bflux_unionize_moms(num_diag_int_mom, - gkns->info.boundary_flux_diagnostics.integrated_diag_moments, &bflux->num_calc_moms, bflux->calc_mom_names); + if (num_diag_int_mom > 0) { + bflux->diag_int_mom_idx = bflux_unionize_moms( + num_diag_int_mom, gkns->info.boundary_flux_diagnostics.integrated_diag_moments, + &bflux->num_calc_moms, bflux->calc_mom_names + ); + } if (num_add_mom > 0) { - int *add_mom_idx = bflux_unionize_moms(num_add_mom, - add_moms_inp.diag_moments, &bflux->num_calc_moms, bflux->calc_mom_names); + int *add_mom_idx = bflux_unionize_moms( + num_add_mom, add_moms_inp.diag_moments, &bflux->num_calc_moms, bflux->calc_mom_names + ); gkyl_free(add_mom_idx); } // Create a moments app for each mom needed. bflux->moms_op = gkyl_malloc(sizeof(struct gk_species_moment[bflux->num_calc_moms])); bool need_hamil_ghost = false; - for (int m=0; mnum_calc_moms; m++) { + for (int m = 0; m < bflux->num_calc_moms; m++) { gk_neut_species_moment_init(app, gkns, &bflux->moms_op[m], bflux->calc_mom_names[m], false); - need_hamil_ghost = (bflux->calc_mom_names[m] == GKYL_F_MOMENT_M1_FROM_H) - || (bflux->calc_mom_names[m] == GKYL_F_MOMENT_ENERGY); + need_hamil_ghost = (bflux->calc_mom_names[m] == GKYL_F_MOMENT_M1_FROM_H) || + (bflux->calc_mom_names[m] == GKYL_F_MOMENT_ENERGY); } if (need_hamil_ghost) { // For moments that use the Hamiltonian, we must fill the ghost cell of H. Use an option // in bc_basic that fills the ghost cells keeping the value at the skin-ghost boundary the same. long buff_sz = 0; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; - struct gkyl_range *skin_r = bflux->boundaries_edge[b]==GKYL_LOWER_EDGE? &gkns->local_lower_skin[dir] - : &gkns->local_upper_skin[dir]; - + struct gkyl_range *skin_r = bflux->boundaries_edge[b] == GKYL_LOWER_EDGE ? + &gkns->local_lower_skin[dir] : + &gkns->local_upper_skin[dir]; + // MF 2025/09/29: The option `GKYL_BC_GK_SPECIES_REFLECT` here is a // just a place holder and almost certainly wrong. Currently REFLECT is // meant to reflect particles. Need something that mirrors the // Hamiltonian into the ghost cell. - bflux->gfss_bc_op[b] = gkyl_bc_basic_gyrokinetic_new(bflux->boundaries_dir[b], bflux->boundaries_edge[b], - GKYL_BC_GK_SPECIES_REFLECT, &gkns->basis, skin_r, bflux->boundaries_phase_ghost[b], 1, app->cdim, app->use_gpu); - + bflux->gfss_bc_op[b] = gkyl_bc_basic_gyrokinetic_new( + bflux->boundaries_dir[b], bflux->boundaries_edge[b], GKYL_BC_GK_SPECIES_REFLECT, + &gkns->basis, skin_r, bflux->boundaries_phase_ghost[b], 1, app->cdim, app->use_gpu + ); + long vol = skin_r->volume; buff_sz = buff_sz > vol ? buff_sz : vol; } bflux->bc_buffer = mkarr(app->use_gpu, gkns->basis.num_basis, buff_sz); - + // Fill ghost cell of H. - for (int b=0; bnum_boundaries; ++b) + for (int b = 0; b < bflux->num_boundaries; ++b) { gkyl_bc_basic_gyrokinetic_advance(bflux->gfss_bc_op[b], bflux->bc_buffer, gkns->hamil); + } gkyl_array_release(bflux->bc_buffer); - for (int b=0; bnum_boundaries; ++b) + for (int b = 0; b < bflux->num_boundaries; ++b) { gkyl_bc_basic_gyrokinetic_release(bflux->gfss_bc_op[b]); + } } - - bflux->f = gkyl_malloc(bflux->num_boundaries*bflux->num_calc_moms*sizeof(struct gkyl_array *)); - bflux->f1 = gkyl_malloc(bflux->num_boundaries*bflux->num_calc_moms*sizeof(struct gkyl_array *)); - bflux->fnew = gkyl_malloc(bflux->num_boundaries*bflux->num_calc_moms*sizeof(struct gkyl_array *)); - for (int b=0; bnum_boundaries; ++b) { - for (int m=0; mnum_calc_moms; m++) { + + bflux->f = + gkyl_malloc(bflux->num_boundaries * bflux->num_calc_moms * sizeof(struct gkyl_array *)); + bflux->f1 = + gkyl_malloc(bflux->num_boundaries * bflux->num_calc_moms * sizeof(struct gkyl_array *)); + bflux->fnew = + gkyl_malloc(bflux->num_boundaries * bflux->num_calc_moms * sizeof(struct gkyl_array *)); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { // Allocate arrays storing moments of the boundary flux. int num_mom_comp = bflux->moms_op[m].num_mom; - bflux->f[b*bflux->num_calc_moms+m] = mkarr(app->use_gpu, num_mom_comp*app->basis.num_basis, app->local_ext.volume); - bflux->f1[b*bflux->num_calc_moms+m] = mkarr(app->use_gpu, num_mom_comp*app->basis.num_basis, app->local_ext.volume); - bflux->fnew[b*bflux->num_calc_moms+m] = mkarr(app->use_gpu, num_mom_comp*app->basis.num_basis, app->local_ext.volume); + bflux->f[b * bflux->num_calc_moms + m] = + mkarr(app->use_gpu, num_mom_comp * app->basis.num_basis, app->local_ext.volume); + bflux->f1[b * bflux->num_calc_moms + m] = + mkarr(app->use_gpu, num_mom_comp * app->basis.num_basis, app->local_ext.volume); + bflux->fnew[b * bflux->num_calc_moms + m] = + mkarr(app->use_gpu, num_mom_comp * app->basis.num_basis, app->local_ext.volume); } } } - + if (bflux_type == GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS_DIAGS) { assert(num_diag_mom > 0 || num_diag_int_mom > 0); bflux->allocated_diags = true; - + // Set methods for time-stepping boundary fluxes needed for diagnostics. if (gkns->info.boundary_flux_diagnostics.time_integrated) { bflux->bflux_calc_integrated_mom_func = gk_neut_species_bflux_append_integrated_mom; - bflux->bflux_calc_voltime_int_mom_func = gk_neut_species_bflux_calc_voltime_integrated_mom_enabled; - } - else { + bflux->bflux_calc_voltime_int_mom_func = + gk_neut_species_bflux_calc_voltime_integrated_mom_enabled; + } else { bflux->bflux_calc_integrated_mom_func = gk_neut_species_bflux_calc_integrated_mom_enabled; } bflux->bflux_write_integrated_mom_func = gk_neut_species_bflux_write_integrated_mom_enabled; @@ -796,40 +943,41 @@ gk_neut_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, if (app->cdim > 1) { struct gkyl_basis basis_conf_surf; switch (app->basis.b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - gkyl_cart_modal_serendip(&basis_conf_surf, app->cdim-1, app->basis.poly_order); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + gkyl_cart_modal_serendip(&basis_conf_surf, app->cdim - 1, app->basis.poly_order); + break; + default: + assert(false); + break; } - bflux->transdim = gkyl_malloc(bflux->num_boundaries*sizeof(struct gkyl_translate_dim *)); + bflux->transdim = gkyl_malloc(bflux->num_boundaries * sizeof(struct gkyl_translate_dim *)); bool diag_in_dir[GKYL_MAX_CDIM] = {0}; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; enum gkyl_edge_loc edge = bflux->boundaries_edge[b]; // Updater that projects to lower dim. - bflux->transdim[b] = gkyl_translate_dim_new(app->cdim, app->basis, app->cdim-1, - basis_conf_surf, dir, edge==GKYL_LOWER_EDGE? GKYL_UPPER_EDGE : GKYL_LOWER_EDGE, app->use_gpu); + bflux->transdim[b] = gkyl_translate_dim_new( + app->cdim, app->basis, app->cdim - 1, basis_conf_surf, dir, + edge == GKYL_LOWER_EDGE ? GKYL_UPPER_EDGE : GKYL_LOWER_EDGE, app->use_gpu + ); if (!diag_in_dir[dir]) { - // Create a communicator associated with a lower dimensional surface range. // Identify ranks on the same plane as this one. int num_ranks_surf = 0; - int ranks_surf[app->decomp->ndecomp]; - for (int i=0; idecomp->ndecomp; i++) { + int ranks_surf[app->decomp->ndecomp]; + for (int i = 0; i < app->decomp->ndecomp; i++) { if (app->decomp->ranges[i].lower[dir] == app->local.lower[dir]) { ranks_surf[num_ranks_surf] = i; num_ranks_surf++; } } // Create a range tangentially global. - int surf_dim = app->cdim-1; + int surf_dim = app->cdim - 1; int lower_surf[surf_dim], upper_surf[surf_dim]; int c = 0; - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { if (d != dir) { lower_surf[c] = app->global.lower[d]; upper_surf[c] = app->global.upper[d]; @@ -838,36 +986,41 @@ gk_neut_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, } struct gkyl_range range_surf; gkyl_range_init(&range_surf, surf_dim, lower_surf, upper_surf); - + // Create decomp. int cuts_plane[GKYL_MAX_CDIM], cuts_surf[surf_dim]; gkyl_rect_decomp_get_cuts(app->decomp_plane[dir], cuts_plane); c = 0; - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { if (d != dir) { cuts_surf[c] = cuts_plane[d]; c++; } } - bflux->decomp_surf[dir] = gkyl_rect_decomp_new_from_cuts(surf_dim, cuts_surf, &range_surf); - + bflux->decomp_surf[dir] = + gkyl_rect_decomp_new_from_cuts(surf_dim, cuts_surf, &range_surf); + // Create a new communicator with ranks on surf. bool is_comm_valid; - bflux->comm_surf[dir] = gkyl_comm_create_comm_from_ranks(app->comm, num_ranks_surf, - ranks_surf, bflux->decomp_surf[dir], &is_comm_valid); + bflux->comm_surf[dir] = gkyl_comm_create_comm_from_ranks( + app->comm, num_ranks_surf, ranks_surf, bflux->decomp_surf[dir], &is_comm_valid + ); assert(is_comm_valid); // Local and local extended surface range. int rank; gkyl_comm_get_rank(bflux->comm_surf[dir], &rank); - int ghost[] = { 1, 1, 1 }; - gkyl_create_ranges(&bflux->decomp_surf[dir]->ranges[rank], ghost, &bflux->surf_local_ext[dir], &bflux->surf_local[dir]); + int ghost[] = {1, 1, 1}; + gkyl_create_ranges( + &bflux->decomp_surf[dir]->ranges[rank], ghost, &bflux->surf_local_ext[dir], + &bflux->surf_local[dir] + ); // Create a surface grid. double grid_surf_lower[surf_dim], grid_surf_upper[surf_dim]; int grid_surf_cells[surf_dim]; c = 0; - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { if (d != dir) { grid_surf_lower[c] = app->grid.lower[d]; grid_surf_upper[c] = app->grid.upper[d]; @@ -875,25 +1028,35 @@ gk_neut_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, c++; } } - gkyl_rect_grid_init(&bflux->grid_surf[dir], surf_dim, grid_surf_lower, grid_surf_upper, grid_surf_cells); + gkyl_rect_grid_init( + &bflux->grid_surf[dir], surf_dim, grid_surf_lower, grid_surf_upper, grid_surf_cells + ); diag_in_dir[dir] = true; } } // Allocate a lower dimensional array for each moment. - bflux->mom_surf = gkyl_malloc(bflux->num_boundaries*num_diag_mom*sizeof(struct gkyl_array *)); - bflux->mom_surf_ho = gkyl_malloc(bflux->num_boundaries*num_diag_mom*sizeof(struct gkyl_array *)); - for (int b=0; bnum_boundaries; ++b) { + bflux->mom_surf = + gkyl_malloc(bflux->num_boundaries * num_diag_mom * sizeof(struct gkyl_array *)); + bflux->mom_surf_ho = + gkyl_malloc(bflux->num_boundaries * num_diag_mom * sizeof(struct gkyl_array *)); + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; - for (int m=0; mdiag_mom_idx[m]; int num_mom_comp = bflux->moms_op[mom_idx].num_mom; - bflux->mom_surf[b*num_diag_mom+m] = mkarr(app->use_gpu, num_mom_comp*basis_conf_surf.num_basis, bflux->surf_local_ext[dir].volume); - bflux->mom_surf_ho[b*num_diag_mom+m] = app->use_gpu? - mkarr(false, num_mom_comp*basis_conf_surf.num_basis, bflux->surf_local_ext[dir].volume) : - gkyl_array_acquire(bflux->mom_surf[b*num_diag_mom+m]); + bflux->mom_surf[b * num_diag_mom + m] = mkarr( + app->use_gpu, num_mom_comp * basis_conf_surf.num_basis, + bflux->surf_local_ext[dir].volume + ); + bflux->mom_surf_ho[b * num_diag_mom + m] = + app->use_gpu ? + mkarr( + false, num_mom_comp * basis_conf_surf.num_basis, bflux->surf_local_ext[dir].volume + ) : + gkyl_array_acquire(bflux->mom_surf[b * num_diag_mom + m]); } } } @@ -901,54 +1064,56 @@ gk_neut_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, if (num_diag_int_mom > 0) { // Object to integrate moments of the bflux and dynvectors to store them. - bflux->integ_op = gkyl_malloc(num_diag_int_mom*sizeof(struct gkyl_array_integrate *)); - bflux->intmom = gkyl_malloc(num_diag_int_mom*bflux->num_boundaries*sizeof(gkyl_dynvec)); + bflux->integ_op = gkyl_malloc(num_diag_int_mom * sizeof(struct gkyl_array_integrate *)); + bflux->intmom = gkyl_malloc(num_diag_int_mom * bflux->num_boundaries * sizeof(gkyl_dynvec)); int num_mom_comp_max = 1; - for (int m=0; mmoms_op[bflux->diag_int_mom_idx[m]].num_mom; num_mom_comp_max = GKYL_MAX2(num_mom_comp_max, num_mom_comp); // Updater to compute the volume integral of the boundary flux moments. - bflux->integ_op[m] = gkyl_array_integrate_new(&app->grid, &app->basis, - num_mom_comp, GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu); + bflux->integ_op[m] = gkyl_array_integrate_new( + &app->grid, &app->basis, num_mom_comp, GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu + ); // Allocate a dynvector for each moment. - for (int b=0; bnum_boundaries; ++b) - bflux->intmom[b*bflux->num_calc_moms+m] = gkyl_dynvec_new(GKYL_DOUBLE, num_mom_comp); + for (int b = 0; b < bflux->num_boundaries; ++b) { + bflux->intmom[b * bflux->num_calc_moms + m] = gkyl_dynvec_new(GKYL_DOUBLE, num_mom_comp); + } } - + if (app->use_gpu) { - bflux->int_moms_local = gkyl_cu_malloc(num_mom_comp_max*sizeof(double)); - bflux->int_moms_global = gkyl_cu_malloc(num_mom_comp_max*sizeof(double)); - } - else { - bflux->int_moms_local = gkyl_malloc(num_mom_comp_max*sizeof(double)); - bflux->int_moms_global = gkyl_malloc(num_mom_comp_max*sizeof(double)); + bflux->int_moms_local = gkyl_cu_malloc(num_mom_comp_max * sizeof(double)); + bflux->int_moms_global = gkyl_cu_malloc(num_mom_comp_max * sizeof(double)); + } else { + bflux->int_moms_local = gkyl_malloc(num_mom_comp_max * sizeof(double)); + bflux->int_moms_global = gkyl_malloc(num_mom_comp_max * sizeof(double)); } - - for (int b=0; bnum_boundaries; ++b) + + for (int b = 0; b < bflux->num_boundaries; ++b) { bflux->is_first_intmom_write_call[b] = true; - + } + if (gkns->info.boundary_flux_diagnostics.time_integrated) { // Cummulative integrated moments of boundary fluxes. - bflux->intmom_cumm_buff = gkyl_malloc(num_diag_int_mom*sizeof(double *)); - for (int m=0; mintmom_cumm_buff = gkyl_malloc(num_diag_int_mom * sizeof(double *)); + for (int m = 0; m < num_diag_int_mom; m++) { int num_mom_comp = bflux->moms_op[bflux->diag_int_mom_idx[m]].num_mom; - bflux->intmom_cumm_buff[m] = gkyl_malloc(bflux->num_boundaries*num_mom_comp*sizeof(double)); + bflux->intmom_cumm_buff[m] = + gkyl_malloc(bflux->num_boundaries * num_mom_comp * sizeof(double)); double *buff = bflux->intmom_cumm_buff[m]; - for (int b=0; bnum_boundaries; ++b) { - for (int k=0; knum_boundaries; ++b) { + for (int k = 0; k < num_mom_comp; k++) { + buff[b * num_mom_comp + k] = 0.0; + } } } } - } } - } -void -gk_neut_species_bflux_read_voltime_integrated_mom(gkyl_gyrokinetic_app *app, - void *species, struct gk_boundary_fluxes *bflux) +void gk_neut_species_bflux_read_voltime_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux +) { const struct gk_neut_species *gkns = species; @@ -957,59 +1122,64 @@ gk_neut_species_bflux_read_voltime_integrated_mom(gkyl_gyrokinetic_app *app, gkyl_comm_get_rank(app->comm, &rank); gkyl_comm_get_size(app->comm, &comm_size); - const char *vars[] = {"x","y","z"}; - const char *edge[] = {"lower","upper"}; + const char *vars[] = {"x", "y", "z"}; + const char *edge[] = {"lower", "upper"}; int num_diag_int_mom = gkns->info.boundary_flux_diagnostics.num_integrated_diag_moments; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; - int edi = bflux->boundaries_edge[b]==GKYL_LOWER_EDGE? 0 : 1; + int edi = bflux->boundaries_edge[b] == GKYL_LOWER_EDGE ? 0 : 1; - if ((edi == 0 && rank == 0) || (edi == 1 && rank == comm_size-1)) { - for (int m=0; minfo.boundary_flux_diagnostics.integrated_diag_moments[m]]; + const char *mom_name = gkyl_distribution_moments_strs[gkns->info.boundary_flux_diagnostics + .integrated_diag_moments[m]]; - int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, vars[dir], edge[edi], mom_name); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, vars[dir], edge[edi], mom_name); + int sz = + gkyl_calc_strlen(fmt, app->name, gkns->info.name, vars[dir], edge[edi], mom_name); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, vars[dir], edge[edi], mom_name + ); // We didn't calculate int_mom at restart, so read the value from the previous sim // and append it. This is the best solution given the flow in present input files. - bool res = gkyl_dynvec_read(bflux->intmom[b*num_diag_int_mom+m], fileNm); - int num_mom_comp = gkyl_dynvec_ncomp(bflux->intmom[b*num_diag_int_mom+m]); + bool res = gkyl_dynvec_read(bflux->intmom[b * num_diag_int_mom + m], fileNm); + int num_mom_comp = gkyl_dynvec_ncomp(bflux->intmom[b * num_diag_int_mom + m]); double vals_prev[num_mom_comp]; - gkyl_dynvec_getlast(bflux->intmom[b*num_diag_int_mom+m], vals_prev); - gkyl_dynvec_clear(bflux->intmom[b*num_diag_int_mom+m]); + gkyl_dynvec_getlast(bflux->intmom[b * num_diag_int_mom + m], vals_prev); + gkyl_dynvec_clear(bflux->intmom[b * num_diag_int_mom + m]); double *intmom_cumm_buff = bflux->intmom_cumm_buff[m]; - for (int k=0; kallocated_solver) { - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { gkyl_boundary_flux_release(bflux->flux_slvr[b]); } - for (int i=0; inum_eqns; i++) { + for (int i = 0; i < bflux->num_eqns; i++) { gkyl_dg_eqn_release(bflux->eqns[i]); } gkyl_free(bflux->eqns); - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { gkyl_array_release(bflux->flux[b]); } gkyl_free(bflux->flux); @@ -1020,27 +1190,31 @@ gk_neut_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const void int num_diag_int_mom = gkns->info.boundary_flux_diagnostics.num_integrated_diag_moments; if (bflux->allocated_moms) { - if (num_diag_mom > 0) + if (num_diag_mom > 0) { gkyl_free(bflux->diag_mom_idx); + } - if (num_diag_int_mom > 0) + if (num_diag_int_mom > 0) { gkyl_free(bflux->diag_int_mom_idx); + } - for (int m=0; mnum_calc_moms; m++) - gk_neut_species_moment_release(app, &bflux->moms_op[m]); + for (int m = 0; m < bflux->num_calc_moms; m++) { + gk_neut_species_moment_release(app, &bflux->moms_op[m]); + } gkyl_free(bflux->moms_op); gkyl_free(bflux->is_hamiltonian_mom); if (bflux->a_hamiltonian_mom) { gkyl_array_release(bflux->bc_buffer); - for (int b=0; bnum_boundaries; ++b) + for (int b = 0; b < bflux->num_boundaries; ++b) { gkyl_bc_basic_gyrokinetic_release(bflux->gfss_bc_op[b]); + } } - for (int b=0; bnum_boundaries; ++b) { - for (int m=0; mnum_calc_moms; m++) { - gkyl_array_release(bflux->f[b*bflux->num_calc_moms+m]); - gkyl_array_release(bflux->f1[b*bflux->num_calc_moms+m]); - gkyl_array_release(bflux->fnew[b*bflux->num_calc_moms+m]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_release(bflux->f[b * bflux->num_calc_moms + m]); + gkyl_array_release(bflux->f1[b * bflux->num_calc_moms + m]); + gkyl_array_release(bflux->fnew[b * bflux->num_calc_moms + m]); } } gkyl_free(bflux->f); @@ -1052,13 +1226,14 @@ gk_neut_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const void if (num_diag_mom > 0) { if (app->cdim > 1) { // Objects needed to output lower dimensional moments. - for (int b=0; bnum_boundaries; ++b) + for (int b = 0; b < bflux->num_boundaries; ++b) { gkyl_translate_dim_release(bflux->transdim[b]); + } gkyl_free(bflux->transdim); bool diag_in_dir[GKYL_MAX_CDIM] = {0}; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; if (!diag_in_dir[dir]) { gkyl_rect_decomp_release(bflux->decomp_surf[dir]); @@ -1067,10 +1242,10 @@ gk_neut_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const void } } - for (int b=0; bnum_boundaries; ++b) { - for (int m=0; mmom_surf[b*num_diag_mom+m]); - gkyl_array_release(bflux->mom_surf_ho[b*num_diag_mom+m]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < num_diag_mom; m++) { + gkyl_array_release(bflux->mom_surf[b * num_diag_mom + m]); + gkyl_array_release(bflux->mom_surf_ho[b * num_diag_mom + m]); } } gkyl_free(bflux->mom_surf); @@ -1079,25 +1254,26 @@ gk_neut_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const void } if (num_diag_int_mom > 0) { - for (int m=0; minteg_op[m]); - for (int b=0; bnum_boundaries; ++b) - gkyl_dynvec_release(bflux->intmom[b*bflux->num_calc_moms+m]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + gkyl_dynvec_release(bflux->intmom[b * bflux->num_calc_moms + m]); + } } gkyl_free(bflux->integ_op); gkyl_free(bflux->intmom); if (app->use_gpu) { gkyl_cu_free(bflux->int_moms_local); gkyl_cu_free(bflux->int_moms_global); - } - else { + } else { gkyl_free(bflux->int_moms_local); gkyl_free(bflux->int_moms_global); } - + if (gkns->info.boundary_flux_diagnostics.time_integrated) { - for (int m=0; mintmom_cumm_buff[m]); + } gkyl_free(bflux->intmom_cumm_buff); } } diff --git a/gyrokinetic/apps/gk_neut_species_bgk.c b/gyrokinetic/apps/gk_neut_species_bgk.c index 28c58a30b6..b81bb15084 100644 --- a/gyrokinetic/apps/gk_neut_species_bgk.c +++ b/gyrokinetic/apps/gk_neut_species_bgk.c @@ -2,109 +2,128 @@ #include #include -static void -gkbgk_moms_disabled(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +static void gkbgk_moms_disabled( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { // Empty method. } -static void -gkbgk_moms_enabled(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +static void gkbgk_moms_enabled( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { struct timespec wst = gkyl_wall_clock(); // Compute Maxwellian moments (n, u_par, T/m). gk_neut_species_moment_calc(&gkns->lte.moms, gkns->local, app->local, fin); - gkyl_dg_div_op_range(gkns->lte.moms.mem_geo, &app->basis, 0, gkns->lte.moms.marr, - 0, gkns->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local); - + gkyl_dg_div_op_range( + gkns->lte.moms.mem_geo, &app->basis, 0, gkns->lte.moms.marr, 0, gkns->lte.moms.marr, 0, + app->gk_geom->geo_int.jacobgeo, &app->local + ); + // Calculate nu_ss. bgk->self_nu_func_neut(app, gkns, bgk); - app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); + app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); } -static void -gkbgk_self_nu_calc_constNu(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk) +static void gkbgk_self_nu_calc_constNu( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk +) { // Empty method. } -static void -gkbgk_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs) +static void gkbgk_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs +) { // Empty method. } -static void -gkbgk_rhs_enabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs) +static void gkbgk_rhs_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - + // Compute the self-collisions Maxwellian. struct gk_lte *lte = &gkns->lte; gk_neut_species_lte_from_moms(app, gkns, lte, lte->moms.marr); // Multiply the Maxwellian by self-species collision frequency. - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gkns->basis, bgk->nu_fmax, - bgk->self_nu, lte->f_lte, &app->local, &gkns->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gkns->basis, bgk->nu_fmax, bgk->self_nu, lte->f_lte, &app->local, &gkns->local + ); // Multiply the Maxwellian by the configuration-space Jacobian. - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gkns->basis, bgk->nu_fmax, - app->gk_geom->geo_int.jacobgeo, bgk->nu_fmax, &app->local, &gkns->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gkns->basis, bgk->nu_fmax, app->gk_geom->geo_int.jacobgeo, bgk->nu_fmax, + &app->local, &gkns->local + ); // Apply BGK collisions. - gkyl_bgk_collisions_advance(bgk->up_bgk, &app->local, &gkns->local, - bgk->nu_sum, bgk->nu_fmax, fin, bgk->implicit_step, dt, rhs, gkns->cflrate); - + gkyl_bgk_collisions_advance( + bgk->up_bgk, &app->local, &gkns->local, bgk->nu_sum, bgk->nu_fmax, fin, bgk->implicit_step, dt, + rhs, gkns->cflrate + ); + app->stat.species_coll_tm += gkyl_time_diff_now_sec(wst); } -static void -gkbgk_write_mom_disabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +static void gkbgk_write_mom_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { // Empty method. } -static void -gkbgk_write_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +static void gkbgk_write_mom_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { struct timespec wtm = gkyl_wall_clock(); // Package metadata. gkyl_msgpack_map_elem_set_double(gkns->io_meta_conf_len, gkns->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gkns->io_meta_conf_len, gkns->io_meta_conf, "frame", frame); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Sum of collision frequencies for BGK collisions." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Sum of collision frequencies for BGK collisions."} }; int io_meta_len[] = {gkns->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); // Write out nu_sum. const char *fmt = "%s-%s_nu_sum_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, frame); - + // Copy data from device to host before writing it out. if (app->use_gpu) { gkyl_array_copy(gkns->bgk.nu_sum_host, gkns->bgk.nu_sum); } - + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, gkns->bgk.nu_sum_host, fileNm); app->stat.n_diag_io += 2; - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); } -void -gk_neut_species_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk) +void gk_neut_species_bgk_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk +) { bgk->collision_id = gkns->info.collisions.collision_id; bgk->write_diagnostics = gkns->info.collisions.write_diagnostics; @@ -120,48 +139,48 @@ gk_neut_species_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_specie bgk->implicit_step = gkns->info.collisions.is_implicit; bgk->num_cross_collisions = gkns->info.collisions.num_cross_collisions; assert(bgk->num_cross_collisions == 0); // NYI. - + int cdim = app->cdim, vdim = gkns->info.vdim; - + // Allocate self-species collision frequency and sum of collision frequencies. bgk->self_nu = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); bgk->nu_sum = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - + double nu_frac = gkns->info.collisions.nu_frac ? gkns->info.collisions.nu_frac : 1.0; - + if (gkns->info.collisions.self_nu) { // Project user's self-species collision frequency. bgk->norm_nu_self = false; - + struct gkyl_array *self_nu_ho = mkarr(false, app->basis.num_basis, app->local_ext.volume); - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(&app->grid, &app->basis, - app->poly_order+1, 1, gkns->info.collisions.self_nu, gkns->info.collisions.self_nu_ctx); + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + &app->grid, &app->basis, app->poly_order + 1, 1, gkns->info.collisions.self_nu, + gkns->info.collisions.self_nu_ctx + ); gkyl_proj_on_basis_advance(proj, 0.0, &app->local, self_nu_ho); gkyl_proj_on_basis_release(proj); gkyl_array_copy(bgk->self_nu, self_nu_ho); gkyl_array_release(self_nu_ho); - + gkyl_array_scale(bgk->self_nu, nu_frac); gkyl_array_set(bgk->nu_sum, 1.0, bgk->self_nu); - + // Set pointers to functions chosen at runtime. bgk->self_nu_func_neut = gkbgk_self_nu_calc_constNu; - } - else { + } else { // Self-collision frequency computed in time. assert(false); // NYI } - + // Host-side copy for I/O. if (bgk->write_diagnostics) { if (app->use_gpu) { bgk->nu_sum_host = mkarr(false, app->basis.num_basis, app->local_ext.volume); - } - else { + } else { bgk->nu_sum_host = bgk->nu_sum; } } - + // Collision frequency times Maxwellian. bgk->nu_fmax = mkarr(app->use_gpu, gkns->basis.num_basis, gkns->local_ext.volume); @@ -174,73 +193,82 @@ gk_neut_species_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_specie bgk->rhs_func_neut = gkbgk_rhs_enabled; bgk->moms_func_implicit_neut = gkbgk_moms_disabled; bgk->rhs_func_implicit_neut = gkbgk_rhs_disabled; - } - else { + } else { bgk->moms_func_neut = gkbgk_moms_disabled; bgk->rhs_func_neut = gkbgk_rhs_disabled; bgk->moms_func_implicit_neut = gkbgk_moms_enabled; bgk->rhs_func_implicit_neut = gkbgk_rhs_enabled; } - if (bgk->write_diagnostics) + if (bgk->write_diagnostics) { bgk->write_mom_func_neut = gkbgk_write_mom_enabled; + } } } -void -gk_neut_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk) -{ +void gk_neut_species_bgk_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk +) +{ } -void -gk_neut_species_bgk_moms(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +void gk_neut_species_bgk_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { bgk->moms_func_neut(app, gkns, bgk, fin); } -void -gk_neut_species_bgk_moms_implicit(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +void gk_neut_species_bgk_moms_implicit( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { bgk->moms_func_implicit_neut(app, gkns, bgk, fin); } -void -gk_neut_species_bgk_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +void gk_neut_species_bgk_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { // Compute this in bgk_rhs } -void -gk_neut_species_bgk_cross_moms_implicit(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +void gk_neut_species_bgk_cross_moms_implicit( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { // Compute this in bgk_rhs } -void -gk_neut_species_bgk_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_neut_species_bgk_rhs( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { bgk->rhs_func_neut(app, gkns, bgk, fin, 0.0, rhs); } -void -gk_neut_species_bgk_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs) +void gk_neut_species_bgk_rhs_implicit( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs +) { bgk->rhs_func_implicit_neut(app, gkns, bgk, fin, dt, rhs); } -void -gk_neut_species_bgk_write_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +void gk_neut_species_bgk_write_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { gkns->bgk.write_mom_func_neut(app, gkns, tm, frame); } -void -gk_neut_species_bgk_release(const struct gkyl_gyrokinetic_app *app, const struct gk_bgk_collisions *bgk) +void gk_neut_species_bgk_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_bgk_collisions *bgk +) { if (bgk->collision_id == GKYL_BGK_COLLISIONS) { gkyl_array_release(bgk->nu_fmax); diff --git a/gyrokinetic/apps/gk_neut_species_collisionless.c b/gyrokinetic/apps/gk_neut_species_collisionless.c index b5d6972750..577b27e251 100644 --- a/gyrokinetic/apps/gk_neut_species_collisionless.c +++ b/gyrokinetic/apps/gk_neut_species_collisionless.c @@ -1,42 +1,45 @@ #include #include -static void -gk_neut_species_collisionless_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_neut_species_collisionless_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { } -static void -gk_neut_species_collisionless_rhs_enabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_neut_species_collisionless_rhs_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - gkyl_dg_updater_vlasov_advance(gkcls->vlasov_slvr, &species->local, - fin, species->cflrate, rhs); + gkyl_dg_updater_vlasov_advance(gkcls->vlasov_slvr, &species->local, fin, species->cflrate, rhs); app->stat.neut_species_collisionless_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_neut_species_collisionless_write_diags_disabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_collisionless *gkcls, double tm, int frame) +static void gk_neut_species_collisionless_write_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_collisionless *gkcls, + double tm, int frame +) { } -static void -gk_neut_species_collisionless_write_diags_enabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_collisionless *gkcls, double tm, int frame) +static void gk_neut_species_collisionless_write_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_collisionless *gkcls, + double tm, int frame +) { struct timespec wst = gkyl_wall_clock(); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); } -void -gk_neut_species_collisionless_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_collisionless *gkcls) +void gk_neut_species_collisionless_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_collisionless *gkcls +) { gkcls->collisionless_id = gkns->info.collisionless.type; gkcls->write_diagnostics = gkns->info.collisionless.write_diagnostics; @@ -45,48 +48,58 @@ gk_neut_species_collisionless_init(struct gkyl_gyrokinetic_app *app, struct gk_n gkcls->rhs_func_neut = gk_neut_species_collisionless_rhs_disabled; if (gkcls->collisionless_id == GKYL_GK_COLLISIONLESS_NEUTRAL) { - int cdim = app->cdim, vdim = gkns->info.vdim; - int pdim = cdim+vdim; + int pdim = cdim + vdim; // Determine which directions are zero-flux. By default // we do not have zero-flux boundary conditions in any direction. - bool is_zero_flux[2*GKYL_MAX_DIM] = {false}; - for (int dir=0; dircdim; ++dir) { - if (gkns->lower_bc[dir].type == GKYL_BC_GK_SPECIES_ZERO_FLUX) + bool is_zero_flux[2 * GKYL_MAX_DIM] = {false}; + for (int dir = 0; dir < app->cdim; ++dir) { + if (gkns->lower_bc[dir].type == GKYL_BC_GK_SPECIES_ZERO_FLUX) { is_zero_flux[dir] = true; - if (gkns->upper_bc[dir].type == GKYL_BC_GK_SPECIES_ZERO_FLUX) - is_zero_flux[dir+pdim] = true; + } + if (gkns->upper_bc[dir].type == GKYL_BC_GK_SPECIES_ZERO_FLUX) { + is_zero_flux[dir + pdim] = true; + } } - // Need to figure out size of alpha_surf and sgn_alpha_surf by finding size of surface basis set + // Need to figure out size of alpha_surf and sgn_alpha_surf by finding size of surface basis set struct gkyl_basis surf_basis, surf_quad_basis; - gkyl_cart_modal_serendip(&surf_basis, pdim-1, app->poly_order); - gkyl_cart_modal_tensor(&surf_quad_basis, pdim-1, app->poly_order); - - int alpha_surf_sz = (cdim+vdim)*surf_basis.num_basis; - int sgn_alpha_surf_sz = (cdim+vdim)*surf_quad_basis.num_basis; // sign(alpha) is store at quadrature points - + gkyl_cart_modal_serendip(&surf_basis, pdim - 1, app->poly_order); + gkyl_cart_modal_tensor(&surf_quad_basis, pdim - 1, app->poly_order); + + int alpha_surf_sz = (cdim + vdim) * surf_basis.num_basis; + int sgn_alpha_surf_sz = + (cdim + vdim) * surf_quad_basis.num_basis; // sign(alpha) is store at quadrature points + // Allocate arrays to store fields: // 1. alpha_surf (surface phase space velocity) // 2. sgn_alpha_surf (sign(alpha_surf) at quadrature points) // 3. const_sgn_alpha (boolean for if sign(alpha_surf) is a constant, either +1 or -1) gkcls->alpha_surf = mkarr(app->use_gpu, alpha_surf_sz, gkns->local_ext.volume); gkcls->sgn_alpha_surf = mkarr(app->use_gpu, sgn_alpha_surf_sz, gkns->local_ext.volume); - gkcls->const_sgn_alpha = mk_int_arr(app->use_gpu, cdim+vdim, gkns->local_ext.volume); - + gkcls->const_sgn_alpha = mk_int_arr(app->use_gpu, cdim + vdim, gkns->local_ext.volume); + // Pre-compute alpha_surf, sgn_alpha_surf, const_sgn_alpha, and cot_vec since they are time-independent - struct gkyl_dg_calc_canonical_pb_vars *calc_vars = gkyl_dg_calc_canonical_pb_vars_new(&gkns->grid, - &app->basis, &gkns->basis, app->use_gpu); - gkyl_dg_calc_canonical_pb_vars_alpha_surf(calc_vars, &app->local, &gkns->local, &gkns->local_ext, gkns->hamil, - gkcls->alpha_surf, gkcls->sgn_alpha_surf, gkcls->const_sgn_alpha); + struct gkyl_dg_calc_canonical_pb_vars *calc_vars = + gkyl_dg_calc_canonical_pb_vars_new(&gkns->grid, &app->basis, &gkns->basis, app->use_gpu); + gkyl_dg_calc_canonical_pb_vars_alpha_surf( + calc_vars, &app->local, &gkns->local, &gkns->local_ext, gkns->hamil, gkcls->alpha_surf, + gkcls->sgn_alpha_surf, gkcls->const_sgn_alpha + ); gkyl_dg_calc_canonical_pb_vars_release(calc_vars); - - struct gkyl_dg_canonical_pb_auxfields aux_inp = {.hamil = gkns->hamil, .alpha_surf = gkcls->alpha_surf, - .sgn_alpha_surf = gkcls->sgn_alpha_surf, .const_sgn_alpha = gkcls->const_sgn_alpha}; - - gkcls->vlasov_slvr = gkyl_dg_updater_vlasov_new(&gkns->grid, &app->basis, &gkns->basis, - &app->local, &gkns->local_vel, &gkns->local, is_zero_flux, gkns->model_id, gkns->field_id, &aux_inp, app->use_gpu); + + struct gkyl_dg_canonical_pb_auxfields aux_inp = { + .hamil = gkns->hamil, + .alpha_surf = gkcls->alpha_surf, + .sgn_alpha_surf = gkcls->sgn_alpha_surf, + .const_sgn_alpha = gkcls->const_sgn_alpha + }; + + gkcls->vlasov_slvr = gkyl_dg_updater_vlasov_new( + &gkns->grid, &app->basis, &gkns->basis, &app->local, &gkns->local_vel, &gkns->local, + is_zero_flux, gkns->model_id, gkns->field_id, &aux_inp, app->use_gpu + ); // Methods chosen at runtime. gkcls->rhs_func_neut = gk_neut_species_collisionless_rhs_enabled; @@ -96,22 +109,25 @@ gk_neut_species_collisionless_init(struct gkyl_gyrokinetic_app *app, struct gk_n } } -void -gk_neut_species_collisionless_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_neut_species_collisionless_rhs( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { gkcls->rhs_func_neut(app, species, gkcls, fin, rhs); } -void -gk_neut_species_collisionless_write_diags(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_collisionless *gkcls, double tm, int frame) +void gk_neut_species_collisionless_write_diags( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_collisionless *gkcls, + double tm, int frame +) { gkcls->write_diags_func_neut(app, gkns, gkcls, tm, frame); } -void -gk_neut_species_collisionless_release(const struct gkyl_gyrokinetic_app *app, const struct gk_collisionless *gkcls) +void gk_neut_species_collisionless_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_collisionless *gkcls +) { if (gkcls->collisionless_id == GKYL_GK_COLLISIONLESS_NEUTRAL) { gkyl_array_release(gkcls->alpha_surf); diff --git a/gyrokinetic/apps/gk_neut_species_fluid.c b/gyrokinetic/apps/gk_neut_species_fluid.c index 34c0852bfc..9cad7449f7 100644 --- a/gyrokinetic/apps/gk_neut_species_fluid.c +++ b/gyrokinetic/apps/gk_neut_species_fluid.c @@ -1,13 +1,14 @@ #include -static double -gk_neut_species_fluid_rhs_dynamic(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +static double gk_neut_species_fluid_rhs_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms +) { - double omega_cfl = 1/DBL_MAX; + double omega_cfl = 1 / DBL_MAX; gkyl_array_clear(species->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); - + // Collisionless terms. struct timespec wst = gkyl_wall_clock(); // Not ready. @@ -16,86 +17,86 @@ gk_neut_species_fluid_rhs_dynamic(gkyl_gyrokinetic_app *app, struct gk_neut_spec // Compute volume-integrated reactions in sca. gk_neut_species_scaling_rhs(app, species, &species->sca, fin, rhs); - app->stat.n_neut_species_omega_cfl +=1; + app->stat.n_neut_species_omega_cfl += 1; struct timespec tm = gkyl_wall_clock(); gkyl_array_reduce_range(species->omega_cfl, species->cflrate, GKYL_MAX, &species->local); - + double omega_cfl_ho[1]; - if (app->use_gpu) + if (app->use_gpu) { gkyl_cu_memcpy(omega_cfl_ho, species->omega_cfl, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { omega_cfl_ho[0] = species->omega_cfl[0]; + } omega_cfl = omega_cfl_ho[0]; - + app->stat.neut_species_omega_cfl_tm += gkyl_time_diff_now_sec(tm); - return app->cfl/omega_cfl; + return app->cfl / omega_cfl; } -static double -gk_neut_species_fluid_rhs_implicit_dynamic(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt) -{ - double omega_cfl = 1/DBL_MAX; +static double gk_neut_species_fluid_rhs_implicit_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt +) +{ + double omega_cfl = 1 / DBL_MAX; gkyl_array_clear(species->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); // No implicit terms yet. gkyl_array_accumulate(gkyl_array_scale(rhs, dt), 1.0, fin); - - app->stat.n_neut_species_omega_cfl +=1; + + app->stat.n_neut_species_omega_cfl += 1; struct timespec tm = gkyl_wall_clock(); gkyl_array_reduce_range(species->omega_cfl, species->cflrate, GKYL_MAX, &species->local); - + double omega_cfl_ho[1]; if (app->use_gpu) { gkyl_cu_memcpy(omega_cfl_ho, species->omega_cfl, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { omega_cfl_ho[0] = species->omega_cfl[0]; } omega_cfl = omega_cfl_ho[0]; - + app->stat.neut_species_omega_cfl_tm += gkyl_time_diff_now_sec(tm); - return app->cfl/omega_cfl; + return app->cfl / omega_cfl; } -static void -gk_neut_species_fluid_release_dynamic(const gkyl_gyrokinetic_app* app, const struct gk_neut_species *ns) +static void gk_neut_species_fluid_release_dynamic( + const gkyl_gyrokinetic_app *app, const struct gk_neut_species *ns +) { // Release memory allocated for dynamic neutrals. gkyl_array_release(ns->cflrate); - + if (app->use_gpu) { gkyl_cu_free(ns->omega_cfl); - } - else { + } else { gkyl_free(ns->omega_cfl); } // Release integrated mom data. - gk_neut_species_moment_release(app, &ns->integ_moms); + gk_neut_species_moment_release(app, &ns->integ_moms); // Release integrated mom diag data. gkyl_dynvec_release(ns->integ_diag); - + if (app->use_gpu) { gkyl_cu_free(ns->red_integ_diag); gkyl_cu_free(ns->red_integ_diag_global); - } - else { + } else { gkyl_free(ns->red_integ_diag); gkyl_free(ns->red_integ_diag_global); } } static void -gk_neut_species_fluid_release(const gkyl_gyrokinetic_app* app, const struct gk_neut_species *ns) +gk_neut_species_fluid_release(const gkyl_gyrokinetic_app *app, const struct gk_neut_species *ns) { // Release resources for fluid neutral species. gkyl_msgpack_map_elem_release(ns->io_meta_basic_len, ns->io_meta_basic); - gkyl_msgpack_map_elem_release(ns->io_meta_conf_len , ns->io_meta_conf ); + gkyl_msgpack_map_elem_release(ns->io_meta_conf_len, ns->io_meta_conf); gkyl_array_release(ns->f); gkyl_array_release(ns->f1); @@ -107,8 +108,9 @@ gk_neut_species_fluid_release(const gkyl_gyrokinetic_app* app, const struct gk_n } gkyl_comm_release(ns->comm); - for (int i=0; iinfo.num_diag_moments; ++i) + for (int i = 0; i < ns->info.num_diag_moments; ++i) { gk_neut_species_moment_release(app, &ns->moms[i]); + } gkyl_free(ns->moms); gk_neut_species_bgk_release(app, &ns->bgk); @@ -129,20 +131,20 @@ gk_neut_species_fluid_release(const gkyl_gyrokinetic_app* app, const struct gk_n ns->release_is_static_func(app, ns); } -static void -gk_neut_species_fluid_init_dynamic(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns) +static void gk_neut_species_fluid_init_dynamic( + struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns +) { int cdim = app->cdim; - + // Allocate additional moment arrays for time stepping. ns->f1 = mkarr(app->use_gpu, ns->f->ncomp, ns->f->size); ns->fnew = mkarr(app->use_gpu, ns->f->ncomp, ns->f->size); - + // Allocate cflrate (scalar array). ns->cflrate = mkarr(app->use_gpu, 1, ns->local_ext.volume); - ns->omega_cfl = app->use_gpu? gkyl_cu_malloc(sizeof(double)) - : gkyl_malloc(sizeof(double)); + ns->omega_cfl = app->use_gpu ? gkyl_cu_malloc(sizeof(double)) : gkyl_malloc(sizeof(double)); // Allocate data for integrated moments. gk_neut_species_moment_init(app, ns, &ns->integ_moms, GKYL_F_MOMENT_M0M1M2, true); @@ -169,14 +171,18 @@ gk_neut_species_fluid_init_dynamic(struct gkyl_gk *gk, struct gkyl_gyrokinetic_a ns->combine_func = gk_neut_species_combine_dynamic; ns->copy_func = gk_neut_species_copy_range_dynamic; ns->write_func = gk_neut_species_write_dynamic; - ns->write_mom_func = gk_neut_species_write_mom_dynamic; // MF 2025/07/18: currently works for fluid too. - ns->calc_integrated_mom_func = gk_neut_species_calc_integrated_mom_dynamic; // MF 2025/07/18: currently works for fluid too. - ns->write_integrated_mom_func = gk_neut_species_write_integrated_mom_dynamic; // MF 2025/07/18: currently works for fluid too. + ns->write_mom_func = + gk_neut_species_write_mom_dynamic; // MF 2025/07/18: currently works for fluid too. + ns->calc_integrated_mom_func = + gk_neut_species_calc_integrated_mom_dynamic; // MF 2025/07/18: currently works for fluid too. + ns->write_integrated_mom_func = + gk_neut_species_write_integrated_mom_dynamic; // MF 2025/07/18: currently works for fluid too. ns->report_n_iter_corr_func = gk_neut_species_n_iter_corr_disabled; } -static void -gk_neut_species_fluid_init_static(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s) +static void gk_neut_species_fluid_init_static( + struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s +) { // Set pointers for RK methods. s->f1 = gkyl_array_acquire(s->f); @@ -198,11 +204,14 @@ gk_neut_species_fluid_init_static(struct gkyl_gk *gk, struct gkyl_gyrokinetic_ap s->report_n_iter_corr_func = gk_neut_species_n_iter_corr_disabled; } -void -gk_neut_species_fluid_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns) +void gk_neut_species_fluid_init( + struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns +) { ns->is_fluid = true; // Fluid neutrals. - assert(ns->info.vdim == 0); // Ensure user provided vdim=0 in input file, or didn't provide it at all. + assert( + ns->info.vdim == 0 + ); // Ensure user provided vdim=0 in input file, or didn't provide it at all. ns->model_id = GKYL_MODEL_DEFAULT; ns->field_id = GKYL_FIELD_NULL; @@ -215,12 +224,12 @@ gk_neut_species_fluid_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, // Use the same basis as conf-space. ns->basis = app->basis; ns->basis_on_dev = app->basis_on_dev; - + // Use the same grid as conf-space. ns->grid = app->grid; ns->global_ext = app->global_ext; ns->global = app->global; - + // Use the same communicator as conf-space. ns->comm = gkyl_comm_acquire(app->comm); @@ -231,80 +240,106 @@ gk_neut_species_fluid_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, // Keep a copy of num_periodic_dir and periodic_dirs in species so we can // add the parallel direction in case TS BCs are needed. ns->num_periodic_dir = app->num_periodic_dir; - for (int d=0; dnum_periodic_dir; ++d) + for (int d = 0; d < ns->num_periodic_dir; ++d) { ns->periodic_dirs[d] = app->periodic_dirs[d]; + } - for (int d=0; dcdim; ++d) ns->bc_is_np[d] = true; - for (int d=0; dnum_periodic_dir; ++d) + for (int d = 0; d < app->cdim; ++d) { + ns->bc_is_np[d] = true; + } + for (int d = 0; d < ns->num_periodic_dir; ++d) { ns->bc_is_np[ns->periodic_dirs[d]] = false; + } // Store the BCs from the input file. - for (int d=0; dcdim; ++d) { - struct gkyl_gyrokinetic_bc *bc_lo = gk_fetch_bc_with_dir_edge(ns->info.bcs, 2*app->cdim, d, GKYL_LOWER_EDGE); - if (bc_lo != 0) + for (int d = 0; d < app->cdim; ++d) { + struct gkyl_gyrokinetic_bc *bc_lo = + gk_fetch_bc_with_dir_edge(ns->info.bcs, 2 * app->cdim, d, GKYL_LOWER_EDGE); + if (bc_lo != 0) { ns->lower_bc[d] = *bc_lo; - else + } else { ns->lower_bc[d].type = GKYL_BC_GK_SKIP; + } - struct gkyl_gyrokinetic_bc *bc_up = gk_fetch_bc_with_dir_edge(ns->info.bcs, 2*app->cdim, d, GKYL_UPPER_EDGE); - if (bc_up != 0) + struct gkyl_gyrokinetic_bc *bc_up = + gk_fetch_bc_with_dir_edge(ns->info.bcs, 2 * app->cdim, d, GKYL_UPPER_EDGE); + if (bc_up != 0) { ns->upper_bc[d] = *bc_up; - else + } else { ns->upper_bc[d].type = GKYL_BC_GK_SKIP; + } } // Species properties metadata. struct gkyl_msgpack_map_elem io_meta_sprop[] = { - { .key = "mass", .elem_type = GKYL_MP_DOUBLE, .dval = ns->info.mass }, - { .key = "charge", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0 }, - { .key = "gas_gamma", .elem_type = GKYL_MP_DOUBLE, .dval = ns->info.gas_gamma }, - { .key = "vdim", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = ns->info.vdim }, + {.key = "mass", .elem_type = GKYL_MP_DOUBLE, .dval = ns->info.mass}, + {.key = "charge", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0}, + {.key = "gas_gamma", .elem_type = GKYL_MP_DOUBLE, .dval = ns->info.gas_gamma}, + {.key = "vdim", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = ns->info.vdim} }; // Metadata for integrated quantities. const struct gkyl_msgpack_map_elem *io_meta_basic_union[] = {app->io_meta_basic, io_meta_sprop}; - int io_meta_basic_union_len[] = {app->io_meta_basic_len, sizeof(io_meta_sprop)/sizeof(io_meta_sprop[0])}; - ns->io_meta_basic = gkyl_msgpack_map_elem_union(sizeof(io_meta_basic_union)/sizeof(io_meta_basic_union[0]), - io_meta_basic_union_len, io_meta_basic_union, &ns->io_meta_basic_len); + int io_meta_basic_union_len[] = { + app->io_meta_basic_len, sizeof(io_meta_sprop) / sizeof(io_meta_sprop[0]) + }; + ns->io_meta_basic = gkyl_msgpack_map_elem_union( + sizeof(io_meta_basic_union) / sizeof(io_meta_basic_union[0]), io_meta_basic_union_len, + io_meta_basic_union, &ns->io_meta_basic_len + ); // Metadata for conf-space quantities. struct gkyl_msgpack_map_elem io_meta_conf[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = app->basis.poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->basis.id }, - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0 }, - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = app->basis.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->basis.id}, + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0}, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0} + }; + const struct gkyl_msgpack_map_elem *io_meta_conf_union[] = { + app->io_meta_basic, io_meta_sprop, io_meta_conf + }; + int io_meta_conf_union_len[] = { + app->io_meta_basic_len, sizeof(io_meta_sprop) / sizeof(io_meta_sprop[0]), + sizeof(io_meta_conf) / sizeof(io_meta_conf[0]) }; - const struct gkyl_msgpack_map_elem *io_meta_conf_union[] = {app->io_meta_basic, io_meta_sprop, io_meta_conf}; - int io_meta_conf_union_len[] = {app->io_meta_basic_len, sizeof(io_meta_sprop)/sizeof(io_meta_sprop[0]), - sizeof(io_meta_conf)/sizeof(io_meta_conf[0])}; - ns->io_meta_conf = gkyl_msgpack_map_elem_union(sizeof(io_meta_conf_union)/sizeof(io_meta_conf_union[0]), - io_meta_conf_union_len, io_meta_conf_union, &ns->io_meta_conf_len); + ns->io_meta_conf = gkyl_msgpack_map_elem_union( + sizeof(io_meta_conf_union) / sizeof(io_meta_conf_union[0]), io_meta_conf_union_len, + io_meta_conf_union, &ns->io_meta_conf_len + ); // Metadata for phase-space quantities. ns->io_meta_phase = ns->io_meta_conf; ns->io_meta_phase_len = ns->io_meta_conf_len; // Allocate distribution function array for initialization and I/O. - ns->f = mkarr(app->use_gpu, ns->num_moments*ns->basis.num_basis, ns->local_ext.volume); - ns->f_host = app->use_gpu? mkarr(false, ns->f->ncomp, ns->f->size) - : gkyl_array_acquire(ns->f); + ns->f = mkarr(app->use_gpu, ns->num_moments * ns->basis.num_basis, ns->local_ext.volume); + ns->f_host = app->use_gpu ? mkarr(false, ns->f->ncomp, ns->f->size) : gkyl_array_acquire(ns->f); // Create skin/ghost ranges fir applying BCs. Only used for dynamic neutrals but included here to avoid // code duplication since the "ghost" array is needed. int ghost[GKYL_MAX_DIM]; - for (int d=0; dlocal_lower_skin[dir], &ns->local_lower_ghost[dir], - dir, GKYL_LOWER_EDGE, &ns->local_ext, ghost); - gkyl_skin_ghost_ranges(&ns->local_upper_skin[dir], &ns->local_upper_ghost[dir], - dir, GKYL_UPPER_EDGE, &ns->local_ext, ghost); - gkyl_skin_ghost_ranges(&ns->global_lower_skin[dir], &ns->global_lower_ghost[dir], - dir, GKYL_LOWER_EDGE, &ns->global_ext, ghost); - gkyl_skin_ghost_ranges(&ns->global_upper_skin[dir], &ns->global_upper_ghost[dir], - dir, GKYL_UPPER_EDGE, &ns->local_ext, ghost); + for (int dir = 0; dir < cdim; ++dir) { + gkyl_skin_ghost_ranges( + &ns->local_lower_skin[dir], &ns->local_lower_ghost[dir], dir, GKYL_LOWER_EDGE, &ns->local_ext, + ghost + ); + gkyl_skin_ghost_ranges( + &ns->local_upper_skin[dir], &ns->local_upper_ghost[dir], dir, GKYL_UPPER_EDGE, &ns->local_ext, + ghost + ); + gkyl_skin_ghost_ranges( + &ns->global_lower_skin[dir], &ns->global_lower_ghost[dir], dir, GKYL_LOWER_EDGE, + &ns->global_ext, ghost + ); + gkyl_skin_ghost_ranges( + &ns->global_upper_skin[dir], &ns->global_upper_ghost[dir], dir, GKYL_UPPER_EDGE, + &ns->local_ext, ghost + ); } // Initialize projection routine for initial conditions. @@ -315,13 +350,14 @@ gk_neut_species_fluid_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, // Allocate objects for computing diagnostic moments. int ndm = ns->info.num_diag_moments; ns->moms = gkyl_malloc(sizeof(struct gk_species_moment[ndm])); - for (int m=0; mmoms[m], ns->info.diag_moments[m], false); + } // Initialize boundary fluxes. - ns->bflux = (struct gk_boundary_fluxes) { }; + ns->bflux = (struct gk_boundary_fluxes){}; // Additional bflux moments to step in time. - struct gkyl_phase_diagnostics_inp add_bflux_moms_inp = (struct gkyl_phase_diagnostics_inp) { }; + struct gkyl_phase_diagnostics_inp add_bflux_moms_inp = (struct gkyl_phase_diagnostics_inp){}; // Set the operation type for the bflux app. enum gkyl_species_bflux_type bflux_type = GK_SPECIES_BFLUX_NONE; gk_neut_species_bflux_init(app, ns, &ns->bflux, bflux_type, add_bflux_moms_inp); @@ -329,36 +365,35 @@ gk_neut_species_fluid_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, // Initialize a Maxwellian/LTE (local thermodynamic equilibrium) projection routine // Projection routine optionally corrects all the Maxwellian/LTE moments // This routine is utilized by both reactions and BGK collisions - ns->lte = (struct gk_lte) { }; - struct correct_all_moms_inp corr_inp = { .correct_all_moms = false, - .max_iter = 0, .iter_eps = 10, .use_last_converged = false }; + ns->lte = (struct gk_lte){}; + struct correct_all_moms_inp corr_inp = { + .correct_all_moms = false, .max_iter = 0, .iter_eps = 10, .use_last_converged = false + }; gk_neut_species_lte_init(app, ns, &ns->lte, corr_inp); // Initialize the object that scales the species according to a balance // between recycling and reactions. - ns->sca = (struct gk_scaling) { }; + ns->sca = (struct gk_scaling){}; gk_neut_species_scaling_init(app, ns, &ns->sca); // Initialize BGK collisions with null type (not applicable to fluids). - ns->bgk = (struct gk_bgk_collisions) { }; + ns->bgk = (struct gk_bgk_collisions){}; ns->info.collisions.collision_id = 0; gk_neut_species_bgk_init(app, ns, &ns->bgk); // Initialize positivity enforcing operator with null type (NYI for fluids). - ns->positivity = (struct gk_positivity) { }; + ns->positivity = (struct gk_positivity){}; gk_neut_species_positivity_init(app, ns, &ns->positivity); // Initialize reactions with charged species (NYI for fluids). - ns->react_neut = (struct gk_react) { }; + ns->react_neut = (struct gk_react){}; ns->info.react_neut.num_react = 0; gk_neut_species_react_init(app, ns, ns->info.react_neut, &ns->react_neut); - ns->src = (struct gk_source) { }; + ns->src = (struct gk_source){}; if (!ns->info.is_static) { gk_neut_species_fluid_init_dynamic(gk, app, ns); - } - else { + } else { gk_neut_species_fluid_init_static(gk, app, ns); } } - diff --git a/gyrokinetic/apps/gk_neut_species_kinetic.c b/gyrokinetic/apps/gk_neut_species_kinetic.c index 8e08e57bad..06355edc6e 100644 --- a/gyrokinetic/apps/gk_neut_species_kinetic.c +++ b/gyrokinetic/apps/gk_neut_species_kinetic.c @@ -1,13 +1,14 @@ #include -static double -gk_neut_species_kinetic_rhs_dynamic(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +static double gk_neut_species_kinetic_rhs_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms +) { - double omega_cfl = 1/DBL_MAX; + double omega_cfl = 1 / DBL_MAX; gkyl_array_clear(species->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); - + // Collisionless terms. gk_neut_species_collisionless_rhs(app, species, &species->collisionless, fin, rhs); @@ -16,35 +17,35 @@ gk_neut_species_kinetic_rhs_dynamic(gkyl_gyrokinetic_app *app, struct gk_neut_sp // Reactions with charged species. gk_neut_species_react_rhs(app, species, &species->react_neut, fin, rhs); - + // Compute and store (in the ghost cell of rhs) the boundary fluxes. gk_neut_species_bflux_rhs(app, &species->bflux, fin, rhs); // Compute diagnostic moments of the boundary fluxes. gk_neut_species_bflux_calc_moms(app, &species->bflux, rhs, bflux_moms); - - app->stat.n_neut_species_omega_cfl +=1; + + app->stat.n_neut_species_omega_cfl += 1; struct timespec tm = gkyl_wall_clock(); gkyl_array_reduce_range(species->omega_cfl, species->cflrate, GKYL_MAX, &species->local); - + double omega_cfl_ho[1]; if (app->use_gpu) { gkyl_cu_memcpy(omega_cfl_ho, species->omega_cfl, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { omega_cfl_ho[0] = species->omega_cfl[0]; } omega_cfl = omega_cfl_ho[0]; - + app->stat.neut_species_omega_cfl_tm += gkyl_time_diff_now_sec(tm); - return app->cfl/omega_cfl; + return app->cfl / omega_cfl; } -static double -gk_neut_species_kinetic_rhs_implicit_dynamic(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt) -{ - double omega_cfl = 1/DBL_MAX; +static double gk_neut_species_kinetic_rhs_implicit_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt +) +{ + double omega_cfl = 1 / DBL_MAX; gkyl_array_clear(species->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); @@ -52,71 +53,71 @@ gk_neut_species_kinetic_rhs_implicit_dynamic(gkyl_gyrokinetic_app *app, struct g gk_neut_species_bgk_rhs_implicit(app, species, &species->bgk, fin, dt, rhs); gkyl_array_accumulate(gkyl_array_scale(rhs, dt), 1.0, fin); - - app->stat.n_neut_species_omega_cfl +=1; + + app->stat.n_neut_species_omega_cfl += 1; struct timespec tm = gkyl_wall_clock(); gkyl_array_reduce_range(species->omega_cfl, species->cflrate, GKYL_MAX, &species->local); - + double omega_cfl_ho[1]; if (app->use_gpu) { gkyl_cu_memcpy(omega_cfl_ho, species->omega_cfl, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { omega_cfl_ho[0] = species->omega_cfl[0]; } omega_cfl = omega_cfl_ho[0]; - + app->stat.neut_species_omega_cfl_tm += gkyl_time_diff_now_sec(tm); - return app->cfl/omega_cfl; + return app->cfl / omega_cfl; } -static void -gk_neut_species_kinetic_apply_bc_dynamic(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gkyl_array *f) +static void gk_neut_species_kinetic_apply_bc_dynamic( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gkyl_array *f +) { struct timespec wst = gkyl_wall_clock(); - + int num_periodic_dir = app->num_periodic_dir, cdim = app->cdim; - gkyl_comm_array_per_sync(species->comm, &species->local, &species->local_ext, - num_periodic_dir, app->periodic_dirs, f); - - for (int d=0; dbc_is_np[d]) { + gkyl_comm_array_per_sync( + species->comm, &species->local, &species->local_ext, num_periodic_dir, app->periodic_dirs, f + ); + for (int d = 0; d < cdim; ++d) { + if (species->bc_is_np[d]) { switch (species->lower_bc[d].type) { - case GKYL_BC_GK_SPECIES_RECYCLE: - gk_neut_species_recycle_apply_bc(app, &species->bc_recycle_lo, species, f); - break; - case GKYL_BC_GK_SPECIES_COPY: - case GKYL_BC_GK_SPECIES_REFLECT: - case GKYL_BC_GK_SPECIES_ABSORB: - gkyl_bc_basic_advance(species->bc_lo[d], species->bc_buffer, f); - break; - case GKYL_BC_GK_SPECIES_FIXED_FUNC: - gkyl_bc_basic_advance(species->bc_lo[d], species->bc_buffer_lo_fixed, f); - break; - case GKYL_BC_GK_SPECIES_ZERO_FLUX: - break; // do nothing, BCs already applied in hyper_dg loop by not updating flux - default: - break; + case GKYL_BC_GK_SPECIES_RECYCLE: + gk_neut_species_recycle_apply_bc(app, &species->bc_recycle_lo, species, f); + break; + case GKYL_BC_GK_SPECIES_COPY: + case GKYL_BC_GK_SPECIES_REFLECT: + case GKYL_BC_GK_SPECIES_ABSORB: + gkyl_bc_basic_advance(species->bc_lo[d], species->bc_buffer, f); + break; + case GKYL_BC_GK_SPECIES_FIXED_FUNC: + gkyl_bc_basic_advance(species->bc_lo[d], species->bc_buffer_lo_fixed, f); + break; + case GKYL_BC_GK_SPECIES_ZERO_FLUX: + break; // do nothing, BCs already applied in hyper_dg loop by not updating flux + default: + break; } switch (species->upper_bc[d].type) { - case GKYL_BC_GK_SPECIES_RECYCLE: - gk_neut_species_recycle_apply_bc(app, &species->bc_recycle_up, species, f); - break; - case GKYL_BC_GK_SPECIES_COPY: - case GKYL_BC_GK_SPECIES_REFLECT: - case GKYL_BC_GK_SPECIES_ABSORB: - gkyl_bc_basic_advance(species->bc_up[d], species->bc_buffer, f); - break; - case GKYL_BC_GK_SPECIES_FIXED_FUNC: - gkyl_bc_basic_advance(species->bc_up[d], species->bc_buffer_up_fixed, f); - break; - case GKYL_BC_GK_SPECIES_ZERO_FLUX: - break; // do nothing, BCs already applied in hyper_dg loop by not updating flux - default: - break; - } + case GKYL_BC_GK_SPECIES_RECYCLE: + gk_neut_species_recycle_apply_bc(app, &species->bc_recycle_up, species, f); + break; + case GKYL_BC_GK_SPECIES_COPY: + case GKYL_BC_GK_SPECIES_REFLECT: + case GKYL_BC_GK_SPECIES_ABSORB: + gkyl_bc_basic_advance(species->bc_up[d], species->bc_buffer, f); + break; + case GKYL_BC_GK_SPECIES_FIXED_FUNC: + gkyl_bc_basic_advance(species->bc_up[d], species->bc_buffer_up_fixed, f); + break; + case GKYL_BC_GK_SPECIES_ZERO_FLUX: + break; // do nothing, BCs already applied in hyper_dg loop by not updating flux + default: + break; + } } } @@ -126,8 +127,9 @@ gk_neut_species_kinetic_apply_bc_dynamic(gkyl_gyrokinetic_app *app, const struct } // release all resources for dynamic species -static void -gk_neut_species_kinetic_release_dynamic(const gkyl_gyrokinetic_app* app, const struct gk_neut_species *s) +static void gk_neut_species_kinetic_release_dynamic( + const gkyl_gyrokinetic_app *app, const struct gk_neut_species *s +) { // release various arrays gkyl_array_release(s->bc_buffer); @@ -137,59 +139,56 @@ gk_neut_species_kinetic_release_dynamic(const gkyl_gyrokinetic_app* app, const s gkyl_array_release(s->f1); gkyl_array_release(s->fnew); gkyl_array_release(s->cflrate); - - if (app->use_gpu) + + if (app->use_gpu) { gkyl_cu_free(s->omega_cfl); - else + } else { gkyl_free(s->omega_cfl); + } gk_neut_species_source_release(app, &s->src); // Release integrated mom data. - gk_neut_species_moment_release(app, &s->integ_moms); + gk_neut_species_moment_release(app, &s->integ_moms); // Release integrated mom diag data. gkyl_dynvec_release(s->integ_diag); - + if (app->use_gpu) { gkyl_cu_free(s->red_integ_diag); gkyl_cu_free(s->red_integ_diag_global); - } - else { + } else { gkyl_free(s->red_integ_diag); gkyl_free(s->red_integ_diag_global); } // Copy BCs are allocated by default. Need to free. - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { if (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_RECYCLE) { gk_neut_species_recycle_release(app, &s->bc_recycle_lo); - } - else if ( (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || - (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || - (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || - (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) ) { + } else if ((s->lower_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || + (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || + (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || + (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { gkyl_bc_basic_release(s->bc_lo[d]); } if (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_RECYCLE) { gk_neut_species_recycle_release(app, &s->bc_recycle_up); - } - else if ( (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || - (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || - (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || - (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) ) { + } else if ((s->upper_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || + (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || + (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || + (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { gkyl_bc_basic_release(s->bc_up[d]); } } - } static void -gk_neut_species_kinetic_release(const gkyl_gyrokinetic_app* app, const struct gk_neut_species *ns) +gk_neut_species_kinetic_release(const gkyl_gyrokinetic_app *app, const struct gk_neut_species *ns) { // Release resources for kinetic neutral species. gkyl_msgpack_map_elem_release(ns->io_meta_basic_len, ns->io_meta_basic); - gkyl_msgpack_map_elem_release(ns->io_meta_conf_len , ns->io_meta_conf ); + gkyl_msgpack_map_elem_release(ns->io_meta_conf_len, ns->io_meta_conf); gkyl_msgpack_map_elem_release(ns->io_meta_phase_len, ns->io_meta_phase); gkyl_array_release(ns->f); @@ -207,8 +206,9 @@ gk_neut_species_kinetic_release(const gkyl_gyrokinetic_app* app, const struct gk // Release moment data. gk_neut_species_moment_release(app, &ns->m0); - for (int i=0; iinfo.num_diag_moments; ++i) + for (int i = 0; i < ns->info.num_diag_moments; ++i) { gk_neut_species_moment_release(app, &ns->moms[i]); + } gkyl_free(ns->moms); gk_neut_species_bgk_release(app, &ns->bgk); @@ -217,7 +217,7 @@ gk_neut_species_kinetic_release(const gkyl_gyrokinetic_app* app, const struct gk // Free boundary flux memory. gk_neut_species_bflux_release(app, ns, &ns->bflux); - + gk_neut_species_lte_release(app, &ns->lte); gk_neut_species_react_release(app, &ns->react_neut); @@ -226,8 +226,9 @@ gk_neut_species_kinetic_release(const gkyl_gyrokinetic_app* app, const struct gk gkyl_array_release(ns->g_ij); gkyl_array_release(ns->hamil); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_release(ns->hamil_host); + } gk_neut_species_collisionless_release(app, &ns->collisionless); @@ -237,23 +238,23 @@ gk_neut_species_kinetic_release(const gkyl_gyrokinetic_app* app, const struct gk ns->release_is_static_func(app, ns); } -void -gk_neut_species_kinetic_init_dynamic(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s) +void gk_neut_species_kinetic_init_dynamic( + struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s +) { int cdim = app->cdim, vdim = s->info.vdim; - int pdim = cdim+vdim; - + int pdim = cdim + vdim; + // allocate additional distribution function arrays for time stepping s->f1 = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); s->fnew = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); - + // Allocate cflrate (scalar array). s->cflrate = mkarr(app->use_gpu, 1, s->local_ext.volume); if (app->use_gpu) { s->omega_cfl = gkyl_cu_malloc(sizeof(double)); - } - else { + } else { s->omega_cfl = gkyl_malloc(sizeof(double)); } @@ -274,7 +275,7 @@ gk_neut_species_kinetic_init_dynamic(struct gkyl_gk *gk, struct gkyl_gyrokinetic // Allocate buffer needed for BCs. long buff_sz = 0; - for (int dir=0; dirlocal_lower_skin[dir].volume, s->local_upper_skin[dir].volume); buff_sz = buff_sz > vol ? buff_sz : vol; } @@ -282,22 +283,26 @@ gk_neut_species_kinetic_init_dynamic(struct gkyl_gk *gk, struct gkyl_gyrokinetic // Buffer arrays for fixed function boundary conditions on distribution function. s->bc_buffer_lo_fixed = mkarr(app->use_gpu, s->basis.num_basis, buff_sz); s->bc_buffer_up_fixed = mkarr(app->use_gpu, s->basis.num_basis, buff_sz); - - s->bc_recycle_lo = (struct gk_recycle_wall) {}; - s->bc_recycle_up = (struct gk_recycle_wall) {}; - for (int d=0; dbc_recycle_lo = (struct gk_recycle_wall){}; + s->bc_recycle_up = (struct gk_recycle_wall){}; + for (int d = 0; d < cdim; ++d) { // Copy BCs by default. if (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_RECYCLE) { - // Initialize recycling object. - gk_neut_species_recycle_init(app, &s->bc_recycle_lo, d, GKYL_LOWER_EDGE, &s->lower_bc[d].emission, s, app->use_gpu); - } - else if ( (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || - (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || - (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || - (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) ) { - enum gkyl_bc_basic_type bctype = gkyl_gyrokinetic_translate_bc_basic_type(s->lower_bc[d].type); - s->bc_lo[d] = gkyl_bc_basic_new(d, GKYL_LOWER_EDGE, bctype, s->basis_on_dev, - &s->local_lower_skin[d], &s->local_lower_ghost[d], s->f->ncomp, app->cdim, app->use_gpu); + // Initialize recycling object. + gk_neut_species_recycle_init( + app, &s->bc_recycle_lo, d, GKYL_LOWER_EDGE, &s->lower_bc[d].emission, s, app->use_gpu + ); + } else if ((s->lower_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || + (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || + (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || + (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { + enum gkyl_bc_basic_type bctype = + gkyl_gyrokinetic_translate_bc_basic_type(s->lower_bc[d].type); + s->bc_lo[d] = gkyl_bc_basic_new( + d, GKYL_LOWER_EDGE, bctype, s->basis_on_dev, &s->local_lower_skin[d], + &s->local_lower_ghost[d], s->f->ncomp, app->cdim, app->use_gpu + ); if (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) { // Fill the buffer used for BCs. @@ -311,17 +316,21 @@ gk_neut_species_kinetic_init_dynamic(struct gkyl_gk *gk, struct gkyl_gyrokinetic } if (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_RECYCLE) { - // Initialize recycling object. - gk_neut_species_recycle_init(app, &s->bc_recycle_up, d, GKYL_UPPER_EDGE, &s->upper_bc[d].emission, s, app->use_gpu); - } - else if ( (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || - (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || - (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || - (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) ) { + // Initialize recycling object. + gk_neut_species_recycle_init( + app, &s->bc_recycle_up, d, GKYL_UPPER_EDGE, &s->upper_bc[d].emission, s, app->use_gpu + ); + } else if ((s->upper_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || + (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || + (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || + (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { // Upper BC updater. Copy BCs by default. - enum gkyl_bc_basic_type bctype = gkyl_gyrokinetic_translate_bc_basic_type(s->upper_bc[d].type); - s->bc_up[d] = gkyl_bc_basic_new(d, GKYL_UPPER_EDGE, bctype, s->basis_on_dev, - &s->local_upper_skin[d], &s->local_upper_ghost[d], s->f->ncomp, app->cdim, app->use_gpu); + enum gkyl_bc_basic_type bctype = + gkyl_gyrokinetic_translate_bc_basic_type(s->upper_bc[d].type); + s->bc_up[d] = gkyl_bc_basic_new( + d, GKYL_UPPER_EDGE, bctype, s->basis_on_dev, &s->local_upper_skin[d], + &s->local_upper_ghost[d], s->f->ncomp, app->cdim, app->use_gpu + ); if (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) { // Fill the buffer used for BCs. @@ -351,8 +360,9 @@ gk_neut_species_kinetic_init_dynamic(struct gkyl_gk *gk, struct gkyl_gyrokinetic s->report_n_iter_corr_func = gk_neut_species_n_iter_corr_enabled; } -static void -gk_neut_species_kinetic_init_static(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s) +static void gk_neut_species_kinetic_init_static( + struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s +) { // Set pointers for RK methods. s->f1 = s->f; @@ -374,9 +384,9 @@ gk_neut_species_kinetic_init_static(struct gkyl_gk *gk, struct gkyl_gyrokinetic_ s->report_n_iter_corr_func = gk_neut_species_n_iter_corr_disabled; } -void -gk_neut_species_kinetic_file_import_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gkyl_gyrokinetic_ic_import inp) +void gk_neut_species_kinetic_file_import_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gkyl_gyrokinetic_ic_import inp +) { // Import initial condition from a file. Intended options include importing: // 1) ICs with same grid. @@ -397,8 +407,8 @@ gk_neut_species_kinetic_file_import_init(struct gkyl_gyrokinetic_app *app, struc // Read the header of the input file, extract needed info an create a grid // and other things needed. FILE *fp; - with_file(fp, inp.file_name, "r") { - + with_file(fp, inp.file_name, "r") + { int status = gkyl_grid_sub_array_header_read_fp(&grid_do, &hdr, fp); pdim_do = grid_do.ndim; @@ -408,45 +418,49 @@ gk_neut_species_kinetic_file_import_init(struct gkyl_gyrokinetic_app *app, struc // Perform some basic checks. if (pdim_do == pdim) { // Check if the grid resolution is the same. - for (int d=0; dbasis.id, gkyl_msgpack_map_elem_get_string(elem_list_len, elem_list, "basis_type")) == 0); + int elem_list_len = sizeof(elem_list) / sizeof(elem_list[0]); + gkyl_msgpack_to_map_elem_list( + &(struct gkyl_msgpack_data){.meta = hdr.meta, .meta_sz = hdr.meta_size}, elem_list_len, + elem_list + ); + assert( + strcmp( + s->basis.id, gkyl_msgpack_map_elem_get_string(elem_list_len, elem_list, "basis_type") + ) == 0 + ); assert(poly_order == gkyl_msgpack_map_elem_get_uint(elem_list_len, elem_list, "poly_order")); gkyl_msgpack_map_elem_release_string(elem_list_len, elem_list, "basis_type"); @@ -458,39 +472,41 @@ gk_neut_species_kinetic_file_import_init(struct gkyl_gyrokinetic_app *app, struc // Basis is tensor for p=1 and ser for p>1 if (poly_order > 1) { gkyl_cart_modal_serendip(&basis_do, pdim_do, poly_order); - } - else if (poly_order == 1) { + } else if (poly_order == 1) { gkyl_cart_modal_tensor(&basis_do, pdim_do, poly_order); // for canonical PB } // Donor global range. int ghost_do[pdim_do]; - for (int d=0; ddecomp, cuts_tar); - if (cdim_do == cdim-1) { - for (int d=0; dcomm, 0, decomp_do); + struct gkyl_comm *comm_do = gkyl_comm_split_comm(s->comm, 0, decomp_do); // Donor local range. int my_rank = 0; @@ -501,15 +517,16 @@ gk_neut_species_kinetic_file_import_init(struct gkyl_gyrokinetic_app *app, struc // Donor array. struct gkyl_array *fdo = mkarr(app->use_gpu, basis_do.num_basis, local_ext_do.volume); - struct gkyl_array *fdo_host = app->use_gpu? mkarr(false, basis_do.num_basis, local_ext_do.volume) - : gkyl_array_acquire(fdo); + struct gkyl_array *fdo_host = + app->use_gpu ? mkarr(false, basis_do.num_basis, local_ext_do.volume) : gkyl_array_acquire(fdo); // Read donor distribution function and Jacobian inverse. struct gkyl_app_restart_status rstat; rstat.io_status = gkyl_comm_array_read(comm_do, &grid_do, &local_do, fdo_host, inp.file_name); bool scale_by_jacobgeo = false; - with_file(fp, inp.jacobtot_inv_file_name, "r") { + with_file(fp, inp.jacobtot_inv_file_name, "r") + { // Set up configuration space donor grid and basis struct gkyl_rect_grid conf_grid_do; gkyl_rect_grid_init(&conf_grid_do, cdim_do, grid_do.lower, grid_do.upper, grid_do.cells); @@ -517,15 +534,24 @@ gk_neut_species_kinetic_file_import_init(struct gkyl_gyrokinetic_app *app, struc struct gkyl_range conf_local_ext_do, conf_local_do, conf_global_ext_do, conf_global_do; gkyl_create_grid_ranges(&conf_grid_do, ghost_do, &conf_global_ext_do, &conf_global_do); // Create configuration space local ranges - struct gkyl_rect_decomp *conf_decomp_do = gkyl_rect_decomp_new_from_cuts(cdim_do, cuts_do, &conf_global_do); - gkyl_create_ranges(&conf_decomp_do->ranges[my_rank], ghost_do, &conf_local_ext_do, &conf_local_do); + struct gkyl_rect_decomp *conf_decomp_do = + gkyl_rect_decomp_new_from_cuts(cdim_do, cuts_do, &conf_global_do); + gkyl_create_ranges( + &conf_decomp_do->ranges[my_rank], ghost_do, &conf_local_ext_do, &conf_local_do + ); // Create a configuration space basis. struct gkyl_basis conf_basis_do; gkyl_cart_modal_serendip(&conf_basis_do, cdim_do, poly_order); // Array for Jacobian inverse - struct gkyl_array *jacobgeo_inv_do_host = mkarr(false, conf_basis_do.num_basis, conf_local_ext_do.volume); - rstat.io_status = gkyl_comm_array_read(comm_do, &conf_grid_do, &conf_local_do, jacobgeo_inv_do_host, inp.jacobtot_inv_file_name); - gkyl_dg_mul_conf_phase_op_range(&conf_basis_do, &basis_do, fdo_host, jacobgeo_inv_do_host, fdo_host, &conf_local_ext_do, &local_ext_do); + struct gkyl_array *jacobgeo_inv_do_host = + mkarr(false, conf_basis_do.num_basis, conf_local_ext_do.volume); + rstat.io_status = gkyl_comm_array_read( + comm_do, &conf_grid_do, &conf_local_do, jacobgeo_inv_do_host, inp.jacobtot_inv_file_name + ); + gkyl_dg_mul_conf_phase_op_range( + &conf_basis_do, &basis_do, fdo_host, jacobgeo_inv_do_host, fdo_host, &conf_local_ext_do, + &local_ext_do + ); gkyl_array_release(jacobgeo_inv_do_host); gkyl_rect_decomp_release(conf_decomp_do); scale_by_jacobgeo = true; @@ -535,20 +561,19 @@ gk_neut_species_kinetic_file_import_init(struct gkyl_gyrokinetic_app *app, struc gkyl_array_copy(fdo, fdo_host); } - if (pdim_do == pdim-1) { - struct gkyl_translate_dim* transdim = gkyl_translate_dim_new(cdim_do, - basis_do, cdim, s->basis, -1, GKYL_NO_EDGE, app->use_gpu); + if (pdim_do == pdim - 1) { + struct gkyl_translate_dim *transdim = + gkyl_translate_dim_new(cdim_do, basis_do, cdim, s->basis, -1, GKYL_NO_EDGE, app->use_gpu); gkyl_translate_dim_advance(transdim, &local_do, &s->local, fdo, 1, s->f); gkyl_translate_dim_release(transdim); - } - else { + } else { if (same_res) { gkyl_array_copy(s->f, fdo); - } - else { + } else { // Interpolate the donor distribution to the target grid. - struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new(app->cdim, &s->basis, - &grid_do, &grid, &local_do, &s->local, ghost_do, app->use_gpu); + struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new( + app->cdim, &s->basis, &grid_do, &grid, &local_do, &s->local, ghost_do, app->use_gpu + ); gkyl_dg_interpolate_advance(interp, fdo, s->f); gkyl_dg_interpolate_release(interp); } @@ -556,22 +581,29 @@ gk_neut_species_kinetic_file_import_init(struct gkyl_gyrokinetic_app *app, struc if (inp.type == GKYL_IC_IMPORT_AF) { // Scale f by a conf-space factor. - gkyl_proj_on_basis *proj_conf_scale = gkyl_proj_on_basis_new(&app->grid, &app->basis, - poly_order+1, 1, inp.conf_scale, inp.conf_scale_ctx); + gkyl_proj_on_basis *proj_conf_scale = gkyl_proj_on_basis_new( + &app->grid, &app->basis, poly_order + 1, 1, inp.conf_scale, inp.conf_scale_ctx + ); struct gkyl_array *xfac = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - struct gkyl_array *xfac_ho = app->use_gpu? mkarr(false, app->basis.num_basis, app->local_ext.volume) - : gkyl_array_acquire(xfac_ho); + struct gkyl_array *xfac_ho = app->use_gpu ? + mkarr(false, app->basis.num_basis, app->local_ext.volume) : + gkyl_array_acquire(xfac_ho); gkyl_proj_on_basis_advance(proj_conf_scale, 0.0, &app->local, xfac_ho); gkyl_array_copy(xfac, xfac_ho); - gkyl_dg_mul_conf_phase_op_range(&app->basis, &s->basis, s->f, xfac, s->f, &app->local, &s->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &s->basis, s->f, xfac, s->f, &app->local, &s->local + ); gkyl_proj_on_basis_release(proj_conf_scale); gkyl_array_release(xfac_ho); gkyl_array_release(xfac); } // Multiply f by the Jacobian. - if (scale_by_jacobgeo) - gkyl_dg_mul_conf_phase_op_range(&app->basis, &s->basis, s->f, app->gk_geom->geo_int.jacobgeo, s->f, &app->local, &s->local); + if (scale_by_jacobgeo) { + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &s->basis, s->f, app->gk_geom->geo_int.jacobgeo, s->f, &app->local, &s->local + ); + } gkyl_rect_decomp_release(decomp_do); gkyl_comm_release(comm_do); @@ -579,25 +611,27 @@ gk_neut_species_kinetic_file_import_init(struct gkyl_gyrokinetic_app *app, struc gkyl_array_release(fdo_host); } -static void -gkyl_array_move_comp(struct gkyl_array *out, int cout, struct gkyl_array *in, int cin, struct gkyl_array *tmp) +static void gkyl_array_move_comp( + struct gkyl_array *out, int cout, struct gkyl_array *in, int cin, struct gkyl_array *tmp +) { // Move the 'cin' scalar field from the multi-component (multi-scalar field) array // 'in' to 'cin' component of the the multi-component 'out'. This requires a // temporary array 'tmp'. This is really a work around for the fact that some // of our array offset ops don't work as we'd like for multi-component arrays // with the same number of components. - gkyl_array_set_offset(tmp, 1.0, in, cin); + gkyl_array_set_offset(tmp, 1.0, in, cin); gkyl_array_set_offset(out, 1.0, tmp, cout); } -void -gk_neut_species_kinetic_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s) +void gk_neut_species_kinetic_init( + struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s +) { s->is_fluid = false; // Kinetic neutrals. int cdim = app->cdim, vdim = s->info.vdim; - int pdim = cdim+vdim; + int pdim = cdim + vdim; assert(vdim > 0); // Ensure user provided vdim in input file. @@ -607,18 +641,18 @@ gk_neut_species_kinetic_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *ap int cells_vel[GKYL_MAX_DIM], ghost_vel[GKYL_MAX_DIM]; double lower_vel[GKYL_MAX_DIM], upper_vel[GKYL_MAX_DIM]; - for (int d=0; dcells[d]; lower[d] = gk->lower[d]; upper[d] = gk->upper[d]; ghost[d] = 1; } - for (int d=0; dinfo.cells[d]; - lower[cdim+d] = s->info.lower[d]; - upper[cdim+d] = s->info.upper[d]; - ghost[cdim+d] = 0; // no ghost-cells in velocity space + cells[cdim + d] = s->info.cells[d]; + lower[cdim + d] = s->info.lower[d]; + upper[cdim + d] = s->info.upper[d]; + ghost[cdim + d] = 0; // no ghost-cells in velocity space // only velocity space cells_vel[d] = s->info.cells[d]; @@ -630,8 +664,7 @@ gk_neut_species_kinetic_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *ap // Basis is tensor for p=1 and ser for p>1 if (app->poly_order > 1) { gkyl_cart_modal_serendip(&s->basis, pdim, app->poly_order); - } - else if (app->poly_order == 1) { + } else if (app->poly_order == 1) { gkyl_cart_modal_tensor(&s->basis, pdim, app->poly_order); // for canonical PB } @@ -640,19 +673,17 @@ gk_neut_species_kinetic_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *ap s->basis_on_dev = gkyl_cu_malloc(sizeof(struct gkyl_basis)); if (app->poly_order > 1) { gkyl_cart_modal_serendip_cu_dev(s->basis_on_dev, pdim, app->poly_order); - } - else if (app->poly_order == 1) { + } else if (app->poly_order == 1) { gkyl_cart_modal_tensor_cu_dev(s->basis_on_dev, pdim, app->poly_order); // for canonical PB } - } - else { + } else { s->basis_on_dev = &s->basis; } - + // Full phase space grid. gkyl_rect_grid_init(&s->grid, pdim, lower, upper, cells); gkyl_create_grid_ranges(&s->grid, ghost, &s->global_ext, &s->global); - + // Velocity space grid. gkyl_rect_grid_init(&s->grid_vel, vdim, lower_vel, upper_vel, cells_vel); gkyl_create_grid_ranges(&s->grid_vel, ghost_vel, &s->local_ext_vel, &s->local_vel); @@ -673,35 +704,44 @@ gk_neut_species_kinetic_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *ap // Velocity space mapping. assert(s->info.mapc2p.mapping == 0); // mapped v-space not implemented for neutrals yet. - s->vel_map = gkyl_velocity_map_new(s->info.mapc2p, s->grid, s->grid_vel, - s->local, s->local_ext, s->local_vel, s->local_ext_vel, app->use_gpu); + s->vel_map = gkyl_velocity_map_new( + s->info.mapc2p, s->grid, s->grid_vel, s->local, s->local_ext, s->local_vel, s->local_ext_vel, + app->use_gpu + ); // Keep a copy of num_periodic_dir and periodic_dirs in species so we can // add the parallel direction in case TS BCs are needed. s->num_periodic_dir = app->num_periodic_dir; - for (int d=0; dnum_periodic_dir; ++d) + for (int d = 0; d < s->num_periodic_dir; ++d) { s->periodic_dirs[d] = app->periodic_dirs[d]; + } - for (int d=0; dcdim; ++d) s->bc_is_np[d] = true; - for (int d=0; dnum_periodic_dir; ++d) + for (int d = 0; d < app->cdim; ++d) { + s->bc_is_np[d] = true; + } + for (int d = 0; d < s->num_periodic_dir; ++d) { s->bc_is_np[s->periodic_dirs[d]] = false; + } // Store the BCs from the input file. - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { if (s->bc_is_np[d]) { - struct gkyl_gyrokinetic_bc *bc_lo = gk_fetch_bc_with_dir_edge(s->info.bcs, 2*app->cdim, d, GKYL_LOWER_EDGE); - if (bc_lo != 0) + struct gkyl_gyrokinetic_bc *bc_lo = + gk_fetch_bc_with_dir_edge(s->info.bcs, 2 * app->cdim, d, GKYL_LOWER_EDGE); + if (bc_lo != 0) { s->lower_bc[d] = *bc_lo; - else + } else { s->lower_bc[d].type = GKYL_BC_GK_SKIP; - - struct gkyl_gyrokinetic_bc *bc_up = gk_fetch_bc_with_dir_edge(s->info.bcs, 2*app->cdim, d, GKYL_UPPER_EDGE); - if (bc_up != 0) + } + + struct gkyl_gyrokinetic_bc *bc_up = + gk_fetch_bc_with_dir_edge(s->info.bcs, 2 * app->cdim, d, GKYL_UPPER_EDGE); + if (bc_up != 0) { s->upper_bc[d] = *bc_up; - else + } else { s->upper_bc[d].type = GKYL_BC_GK_SKIP; - } - else { + } + } else { s->lower_bc[d].type = GKYL_BC_GK_SPECIES_PERIODIC; s->upper_bc[d].type = GKYL_BC_GK_SPECIES_PERIODIC; } @@ -709,81 +749,109 @@ gk_neut_species_kinetic_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *ap // Species properties metadata. struct gkyl_msgpack_map_elem io_meta_sprop[] = { - { .key = "mass", .elem_type = GKYL_MP_DOUBLE, .dval = s->info.mass }, - { .key = "charge", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0 }, - { .key = "vdim", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = s->info.vdim }, + {.key = "mass", .elem_type = GKYL_MP_DOUBLE, .dval = s->info.mass}, + {.key = "charge", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0}, + {.key = "vdim", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = s->info.vdim} }; // Metadata for integrated quantities. const struct gkyl_msgpack_map_elem *io_meta_basic_union[] = {app->io_meta_basic, io_meta_sprop}; - int io_meta_basic_union_len[] = {app->io_meta_basic_len, sizeof(io_meta_sprop)/sizeof(io_meta_sprop[0])}; - s->io_meta_basic = gkyl_msgpack_map_elem_union(sizeof(io_meta_basic_union)/sizeof(io_meta_basic_union[0]), - io_meta_basic_union_len, io_meta_basic_union, &s->io_meta_basic_len); + int io_meta_basic_union_len[] = { + app->io_meta_basic_len, sizeof(io_meta_sprop) / sizeof(io_meta_sprop[0]) + }; + s->io_meta_basic = gkyl_msgpack_map_elem_union( + sizeof(io_meta_basic_union) / sizeof(io_meta_basic_union[0]), io_meta_basic_union_len, + io_meta_basic_union, &s->io_meta_basic_len + ); // Metadata for conf-space quantities. struct gkyl_msgpack_map_elem io_meta_conf[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = app->basis.poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->basis.id }, - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0 }, - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = app->basis.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->basis.id}, + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0}, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0} + }; + const struct gkyl_msgpack_map_elem *io_meta_conf_union[] = { + app->io_meta_basic, io_meta_sprop, io_meta_conf }; - const struct gkyl_msgpack_map_elem *io_meta_conf_union[] = {app->io_meta_basic, io_meta_sprop, io_meta_conf}; - int io_meta_conf_union_len[] = {app->io_meta_basic_len, sizeof(io_meta_sprop)/sizeof(io_meta_sprop[0]), - sizeof(io_meta_conf)/sizeof(io_meta_conf[0])}; - s->io_meta_conf = gkyl_msgpack_map_elem_union(sizeof(io_meta_conf_union)/sizeof(io_meta_conf_union[0]), - io_meta_conf_union_len, io_meta_conf_union, &s->io_meta_conf_len); + int io_meta_conf_union_len[] = { + app->io_meta_basic_len, sizeof(io_meta_sprop) / sizeof(io_meta_sprop[0]), + sizeof(io_meta_conf) / sizeof(io_meta_conf[0]) + }; + s->io_meta_conf = gkyl_msgpack_map_elem_union( + sizeof(io_meta_conf_union) / sizeof(io_meta_conf_union[0]), io_meta_conf_union_len, + io_meta_conf_union, &s->io_meta_conf_len + ); // Metadata for phase-space quantities. struct gkyl_msgpack_map_elem io_meta_phase[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = s->basis.poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = s->basis.id }, - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0 }, - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = s->basis.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = s->basis.id}, + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0}, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0} + }; + const struct gkyl_msgpack_map_elem *io_meta_phase_union[] = { + app->io_meta_basic, io_meta_sprop, io_meta_phase + }; + int io_meta_phase_union_len[] = { + app->io_meta_basic_len, sizeof(io_meta_sprop) / sizeof(io_meta_sprop[0]), + sizeof(io_meta_phase) / sizeof(io_meta_phase[0]) }; - const struct gkyl_msgpack_map_elem *io_meta_phase_union[] = {app->io_meta_basic, io_meta_sprop, io_meta_phase}; - int io_meta_phase_union_len[] = {app->io_meta_basic_len, sizeof(io_meta_sprop)/sizeof(io_meta_sprop[0]), - sizeof(io_meta_phase)/sizeof(io_meta_phase[0])}; - s->io_meta_phase = gkyl_msgpack_map_elem_union(sizeof(io_meta_phase_union)/sizeof(io_meta_phase_union[0]), - io_meta_phase_union_len, io_meta_phase_union, &s->io_meta_phase_len); + s->io_meta_phase = gkyl_msgpack_map_elem_union( + sizeof(io_meta_phase_union) / sizeof(io_meta_phase_union[0]), io_meta_phase_union_len, + io_meta_phase_union, &s->io_meta_phase_len + ); // Allocate distribution function array for initialization and I/O. s->f = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); s->f_host = s->f; - if (app->use_gpu) + if (app->use_gpu) { s->f_host = mkarr(false, s->basis.num_basis, s->local_ext.volume); + } if (app->cdim < 3) { // Reorganize g_ij and gij as done in calculation of Hamiltonian to // compute momentum and temperature. - s->gij = mkarr(app->use_gpu, app->gk_geom->geo_int.gij_neut->ncomp, app->gk_geom->geo_int.gij_neut->size); - s->g_ij = mkarr(app->use_gpu, app->gk_geom->geo_int.g_ij_neut->ncomp, app->gk_geom->geo_int.g_ij_neut->size); + s->gij = mkarr( + app->use_gpu, app->gk_geom->geo_int.gij_neut->ncomp, app->gk_geom->geo_int.gij_neut->size + ); + s->g_ij = mkarr( + app->use_gpu, app->gk_geom->geo_int.g_ij_neut->ncomp, app->gk_geom->geo_int.g_ij_neut->size + ); // Reorganize the metric tensor so ignorable coordinates are last. int metric_reorg_idxs_1x[] = {5, 2, 4, 0, 1, 3}; int metric_reorg_idxs_2x[] = {0, 2, 1, 5, 4, 3}; - int *metric_reorg_idxs = app->cdim == 1? metric_reorg_idxs_1x : metric_reorg_idxs_2x; + int *metric_reorg_idxs = app->cdim == 1 ? metric_reorg_idxs_1x : metric_reorg_idxs_2x; int num_basis_conf = app->basis.num_basis; - struct gkyl_array *tmp_arr = mkarr(app->use_gpu, num_basis_conf, app->gk_geom->geo_int.gij_neut->size); - for (int i=0; i<6; i++) { - gkyl_array_move_comp(s->gij, i*num_basis_conf, app->gk_geom->geo_int.gij_neut, metric_reorg_idxs[i]*num_basis_conf, tmp_arr); - gkyl_array_move_comp(s->g_ij, i*num_basis_conf, app->gk_geom->geo_int.g_ij_neut, metric_reorg_idxs[i]*num_basis_conf, tmp_arr); + struct gkyl_array *tmp_arr = + mkarr(app->use_gpu, num_basis_conf, app->gk_geom->geo_int.gij_neut->size); + for (int i = 0; i < 6; i++) { + gkyl_array_move_comp( + s->gij, i * num_basis_conf, app->gk_geom->geo_int.gij_neut, + metric_reorg_idxs[i] * num_basis_conf, tmp_arr + ); + gkyl_array_move_comp( + s->g_ij, i * num_basis_conf, app->gk_geom->geo_int.g_ij_neut, + metric_reorg_idxs[i] * num_basis_conf, tmp_arr + ); } gkyl_array_release(tmp_arr); - } - else { + } else { s->gij = gkyl_array_acquire(app->gk_geom->geo_int.gij); s->g_ij = gkyl_array_acquire(app->gk_geom->geo_int.g_ij); } // Allocate array for the Hamiltonian. s->hamil = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); - + // Call updater to evaluate hamiltonian - struct gkyl_dg_calc_gk_neut_hamil* hamil_calc = gkyl_dg_calc_gk_neut_hamil_new(&s->grid, &s->basis, app->cdim, app->use_gpu); + struct gkyl_dg_calc_gk_neut_hamil *hamil_calc = + gkyl_dg_calc_gk_neut_hamil_new(&s->grid, &s->basis, app->cdim, app->use_gpu); gkyl_dg_calc_gk_neut_hamil_calc(hamil_calc, &app->local, &s->local, s->gij, s->hamil); gkyl_dg_calc_gk_neut_hamil_release(hamil_calc); - + s->hamil_host = s->hamil; if (app->use_gpu) { s->hamil_host = mkarr(false, s->basis.num_basis, s->local_ext.volume); @@ -791,95 +859,104 @@ gk_neut_species_kinetic_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *ap } // Initialize the collisionless solver. - s->collisionless = (struct gk_collisionless) { }; + s->collisionless = (struct gk_collisionless){}; gk_neut_species_collisionless_init(app, s, &s->collisionless); // Create skin/ghost ranges. - for (int dir=0; dirlocal_lower_skin[dir], &s->local_lower_ghost[dir], - dir, GKYL_LOWER_EDGE, &s->local_ext, ghost); - gkyl_skin_ghost_ranges(&s->local_upper_skin[dir], &s->local_upper_ghost[dir], - dir, GKYL_UPPER_EDGE, &s->local_ext, ghost); - gkyl_skin_ghost_ranges(&s->global_lower_skin[dir], &s->global_lower_ghost[dir], - dir, GKYL_LOWER_EDGE, &s->global_ext, ghost); - gkyl_skin_ghost_ranges(&s->global_upper_skin[dir], &s->global_upper_ghost[dir], - dir, GKYL_UPPER_EDGE, &s->local_ext, ghost); + for (int dir = 0; dir < cdim; ++dir) { + gkyl_skin_ghost_ranges( + &s->local_lower_skin[dir], &s->local_lower_ghost[dir], dir, GKYL_LOWER_EDGE, &s->local_ext, + ghost + ); + gkyl_skin_ghost_ranges( + &s->local_upper_skin[dir], &s->local_upper_ghost[dir], dir, GKYL_UPPER_EDGE, &s->local_ext, + ghost + ); + gkyl_skin_ghost_ranges( + &s->global_lower_skin[dir], &s->global_lower_ghost[dir], dir, GKYL_LOWER_EDGE, &s->global_ext, + ghost + ); + gkyl_skin_ghost_ranges( + &s->global_upper_skin[dir], &s->global_upper_ghost[dir], dir, GKYL_UPPER_EDGE, &s->local_ext, + ghost + ); } if (s->info.init_from_file.type == 0) { // Initialize projection routine for initial conditions. gk_neut_species_projection_init(app, s, s->info.projection, &s->proj_init); - } - else { + } else { // Read initial condition from file. gk_neut_species_kinetic_file_import_init(app, s, s->info.init_from_file); } - - // Allocate object for computing number .density + + // Allocate object for computing number .density gk_neut_species_moment_init(app, s, &s->m0, GKYL_F_MOMENT_M0, false); // Allocate objects for computing diagnostic moments. int ndm = s->info.num_diag_moments; s->moms = gkyl_malloc(sizeof(struct gk_species_moment[ndm])); - for (int m=0; mmoms[m], s->info.diag_moments[m], false); + } // Initialize boundary fluxes. - s->bflux = (struct gk_boundary_fluxes) { }; + s->bflux = (struct gk_boundary_fluxes){}; // Additional bflux moments to step in time. - struct gkyl_phase_diagnostics_inp add_bflux_moms_inp = (struct gkyl_phase_diagnostics_inp) { }; + struct gkyl_phase_diagnostics_inp add_bflux_moms_inp = (struct gkyl_phase_diagnostics_inp){}; // Set the operation type for the bflux app. enum gkyl_species_bflux_type bflux_type = GK_SPECIES_BFLUX_NONE; if (s->info.boundary_flux_diagnostics.num_diag_moments > 0 || s->info.boundary_flux_diagnostics.num_integrated_diag_moments > 0) { bflux_type = GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS_DIAGS; - } - else { - // Set bflux_type to + } else { + // Set bflux_type to // - GK_SPECIES_BFLUX_CALC_FLUX to only put bfluxes in ghost cells of rhs. // - GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS to calc bfluxes and step its moments. // The latter also requires that you place the moment you desire in add_bflux_moms_inp below. } // Introduce new moments into moms_inp if needed. gk_neut_species_bflux_init(app, s, &s->bflux, bflux_type, add_bflux_moms_inp); - + // Initialize a Maxwellian/LTE (local thermodynamic equilibrium) projection routine // Projection routine optionally corrects all the Maxwellian/LTE moments // This routine is utilized by both reactions and BGK collisions - s->lte = (struct gk_lte) { }; + s->lte = (struct gk_lte){}; bool correct_all_moms = s->info.correct.correct_all_moms; int max_iter = s->info.correct.max_iter > 0 ? s->info.correct.max_iter : 50; - double iter_eps = s->info.correct.iter_eps > 0 ? s->info.correct.iter_eps : 1e-10; + double iter_eps = s->info.correct.iter_eps > 0 ? s->info.correct.iter_eps : 1e-10; bool use_last_converged = s->info.correct.use_last_converged; - struct correct_all_moms_inp corr_inp = { .correct_all_moms = correct_all_moms, - .max_iter = max_iter, .iter_eps = iter_eps, - .use_last_converged = use_last_converged }; + struct correct_all_moms_inp corr_inp = { + .correct_all_moms = correct_all_moms, + .max_iter = max_iter, + .iter_eps = iter_eps, + .use_last_converged = use_last_converged + }; gk_neut_species_lte_init(app, s, &s->lte, corr_inp); // Initialize elastic collisions. - s->bgk = (struct gk_bgk_collisions) { }; + s->bgk = (struct gk_bgk_collisions){}; gk_neut_species_bgk_init(app, s, &s->bgk); // Initialize positivity enforcing operator. - s->positivity = (struct gk_positivity) { }; + s->positivity = (struct gk_positivity){}; gk_neut_species_positivity_init(app, s, &s->positivity); // Initialize the object that scales the species according to a balance // between recycling and reactions (meant for fluid neutrals for now). - s->sca = (struct gk_scaling) { }; + s->sca = (struct gk_scaling){}; gk_neut_species_scaling_init(app, s, &s->sca); // Initialize reactions with charged species. - s->react_neut = (struct gk_react) { }; + s->react_neut = (struct gk_react){}; gk_neut_species_react_init(app, s, s->info.react_neut, &s->react_neut); // Initialize empty structs. New methods will fill them if specified. - s->src = (struct gk_source) { }; + s->src = (struct gk_source){}; if (s->info.is_static) { gk_neut_species_kinetic_init_static(gk, app, s); - } - else { + } else { gk_neut_species_kinetic_init_dynamic(gk, app, s); } } diff --git a/gyrokinetic/apps/gk_neut_species_lte.c b/gyrokinetic/apps/gk_neut_species_lte.c index b401bc4d8d..1f6d306a63 100644 --- a/gyrokinetic/apps/gk_neut_species_lte.c +++ b/gyrokinetic/apps/gk_neut_species_lte.c @@ -1,16 +1,18 @@ #include #include -void -gk_neut_species_lte_fluid_from_moms(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_lte *lte, const struct gkyl_array *moms_lte) +void gk_neut_species_lte_fluid_from_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_lte *lte, + const struct gkyl_array *moms_lte +) { // Do nothing. } -void -gk_neut_species_lte_kinetic_from_moms(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_lte *lte, const struct gkyl_array *moms_lte) +void gk_neut_species_lte_kinetic_from_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_lte *lte, + const struct gkyl_array *moms_lte +) { // Compute f_lte from input LTE moments. struct timespec wst = gkyl_wall_clock(); @@ -19,62 +21,69 @@ gk_neut_species_lte_kinetic_from_moms(gkyl_gyrokinetic_app *app, const struct gk // Project the LTE distribution function to obtain f_lte. // Projection routine also corrects the density of the projected distribution function. - gkyl_vlasov_lte_proj_on_basis_advance(lte->proj_lte, &species->local, &app->local, - moms_lte, lte->f_lte); + gkyl_vlasov_lte_proj_on_basis_advance( + lte->proj_lte, &species->local, &app->local, moms_lte, lte->f_lte + ); // Correct all the moments of the projected LTE distribution function. if (lte->correct_all_moms) { struct gkyl_vlasov_lte_correct_status status_corr; - status_corr = gkyl_vlasov_lte_correct_all_moments(lte->corr_lte, lte->f_lte, moms_lte, - &species->local, &app->local); - double corr_vec[7] = { 0.0 }; + status_corr = gkyl_vlasov_lte_correct_all_moments( + lte->corr_lte, lte->f_lte, moms_lte, &species->local, &app->local + ); + double corr_vec[7] = {0.0}; corr_vec[0] = status_corr.num_iter; corr_vec[1] = status_corr.iter_converged; - for (int i=0; i<5; ++i) { - corr_vec[2+i] = status_corr.error[i]; + for (int i = 0; i < 5; ++i) { + corr_vec[2 + i] = status_corr.error[i]; } - double corr_vec_global[7] = { 0.0 }; - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 7, corr_vec, corr_vec_global); + double corr_vec_global[7] = {0.0}; + gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 7, corr_vec, corr_vec_global); gkyl_dynvec_append(lte->corr_stat, app->tcurr, corr_vec_global); lte->n_iter += status_corr.num_iter; - } + } - app->stat.neut_species_lte_tm += gkyl_time_diff_now_sec(wst); + app->stat.neut_species_lte_tm += gkyl_time_diff_now_sec(wst); } -void -gk_neut_species_lte_fluid(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_lte *lte, const struct gkyl_array *fin) +void gk_neut_species_lte_fluid( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_lte *lte, + const struct gkyl_array *fin +) { // Do nothing. } -void -gk_neut_species_lte_kinetic(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_lte *lte, const struct gkyl_array *fin) +void gk_neut_species_lte_kinetic( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_lte *lte, + const struct gkyl_array *fin +) { // Compute equivalent f_lte from fin. struct timespec wst = gkyl_wall_clock(); gk_neut_species_moment_calc(<e->moms, species->local, app->local, fin); // Divide the density by the Jacobian. - gkyl_dg_div_op_range(lte->moms.mem_geo, &app->basis, - 0, lte->moms.marr, 0, lte->moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); - app->stat.neut_species_lte_tm += gkyl_time_diff_now_sec(wst); + gkyl_dg_div_op_range( + lte->moms.mem_geo, &app->basis, 0, lte->moms.marr, 0, lte->moms.marr, 0, + app->gk_geom->geo_int.jacobgeo, &app->local + ); + app->stat.neut_species_lte_tm += gkyl_time_diff_now_sec(wst); gk_neut_species_lte_from_moms(app, species, lte, lte->moms.marr); } -void -gk_neut_species_lte_fluid_write_max_corr_status(gkyl_gyrokinetic_app* app, struct gk_neut_species *gk_ns) +void gk_neut_species_lte_fluid_write_max_corr_status( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gk_ns +) { // Do nothing. } -void -gk_neut_species_lte_kinetic_write_max_corr_status(gkyl_gyrokinetic_app* app, struct gk_neut_species *gk_ns) +void gk_neut_species_lte_kinetic_write_max_corr_status( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gk_ns +) { if (gk_ns->lte.correct_all_moms) { struct timespec wst = gkyl_wall_clock(); @@ -82,26 +91,30 @@ gk_neut_species_lte_kinetic_write_max_corr_status(gkyl_gyrokinetic_app* app, str int rank; gkyl_comm_get_rank(app->comm, &rank); if (rank == 0) { - // Write out correction status. + // Write out correction status. const char *fmt = "%s-%s_lte_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gk_ns->info.name, "corr_max_stat"); - char fileNm[sz+1]; // Ensures no buffer overflow. + char fileNm[sz + 1]; // Ensures no buffer overflow. snprintf(fileNm, sizeof fileNm, fmt, app->name, gk_ns->info.name, "corr_max_stat"); if (gk_ns->lte.is_first_corr_status_write_call) { // Write to a new file (this ensure previous output is removed). struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Statistics on Maxwellian correction." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Statistics on Maxwellian correction."} }; int io_meta_len[] = {gk_ns->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gk_ns->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gk_ns->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(gk_ns->lte.corr_stat, fileNm, mt); gk_ns->lte.is_first_corr_status_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { // Append to existing file. gkyl_dynvec_awrite(gk_ns->lte.corr_stat, fileNm); } @@ -113,14 +126,16 @@ gk_neut_species_lte_kinetic_write_max_corr_status(gkyl_gyrokinetic_app* app, str } } -void -gk_neut_species_lte_fluid_release(const struct gkyl_gyrokinetic_app *app, const struct gk_lte *lte) +void gk_neut_species_lte_fluid_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_lte *lte +) { gk_neut_species_moment_release(app, <e->moms); } -void -gk_neut_species_lte_kinetic_release(const struct gkyl_gyrokinetic_app *app, const struct gk_lte *lte) +void gk_neut_species_lte_kinetic_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_lte *lte +) { gkyl_array_release(lte->f_lte); @@ -133,9 +148,10 @@ gk_neut_species_lte_kinetic_release(const struct gkyl_gyrokinetic_app *app, cons } } -static void -gk_neut_species_lte_fluid_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_lte *lte, - struct correct_all_moms_inp corr_inp) +static void gk_neut_species_lte_fluid_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_lte *lte, + struct correct_all_moms_inp corr_inp +) { // Allocate moments needed for LTE update. gk_neut_species_moment_init(app, s, <e->moms, GKYL_F_MOMENT_LTE, false); @@ -146,19 +162,20 @@ gk_neut_species_lte_fluid_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_ lte->release_func = gk_neut_species_lte_fluid_release; } -static void -gk_neut_species_lte_kinetic_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_lte *lte, - struct correct_all_moms_inp corr_inp) +static void gk_neut_species_lte_kinetic_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_lte *lte, + struct correct_all_moms_inp corr_inp +) { // Allocate moments needed for LTE update. gk_neut_species_moment_init(app, s, <e->moms, GKYL_F_MOMENT_LTE, false); struct gkyl_vlasov_lte_proj_on_basis_inp inp_proj = { .phase_grid = &s->grid, - .vel_grid = &s->grid_vel, + .vel_grid = &s->grid_vel, .conf_basis = &app->basis, .phase_basis = &s->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .vel_range = &s->local_vel, .phase_range = &s->local, @@ -167,22 +184,22 @@ gk_neut_species_lte_kinetic_init(struct gkyl_gyrokinetic_app *app, struct gk_neu .det_h = app->gk_geom->geo_int.jacobgeo, .hamil = s->hamil, .model_id = s->model_id, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - lte->proj_lte = gkyl_vlasov_lte_proj_on_basis_inew( &inp_proj ); + lte->proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_proj); lte->correct_all_moms = corr_inp.correct_all_moms; int max_iter = corr_inp.max_iter > 0 ? corr_inp.max_iter : 50; - double iter_eps = corr_inp.iter_eps > 0 ? corr_inp.iter_eps : 1e-10; + double iter_eps = corr_inp.iter_eps > 0 ? corr_inp.iter_eps : 1e-10; bool use_last_converged = corr_inp.use_last_converged; - + if (lte->correct_all_moms) { struct gkyl_vlasov_lte_correct_inp inp_corr = { .phase_grid = &s->grid, - .vel_grid = &s->grid_vel, + .vel_grid = &s->grid_vel, .conf_basis = &app->basis, .phase_basis = &s->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .vel_range = &s->local_vel, .phase_range = &s->local, @@ -194,10 +211,10 @@ gk_neut_species_lte_kinetic_init(struct gkyl_gyrokinetic_app *app, struct gk_neu .use_gpu = app->use_gpu, .max_iter = max_iter, .eps = iter_eps, - .use_last_converged = use_last_converged, + .use_last_converged = use_last_converged }; lte->n_iter = 0; - lte->corr_lte = gkyl_vlasov_lte_correct_inew( &inp_corr ); + lte->corr_lte = gkyl_vlasov_lte_correct_inew(&inp_corr); lte->corr_stat = gkyl_dynvec_new(GKYL_DOUBLE, 7); lte->is_first_corr_status_write_call = true; @@ -211,38 +228,42 @@ gk_neut_species_lte_kinetic_init(struct gkyl_gyrokinetic_app *app, struct gk_neu lte->release_func = gk_neut_species_lte_kinetic_release; } -void -gk_neut_species_lte_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_lte *lte, - struct correct_all_moms_inp corr_inp) +void gk_neut_species_lte_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_lte *lte, + struct correct_all_moms_inp corr_inp +) { - if (s->is_fluid) + if (s->is_fluid) { gk_neut_species_lte_fluid_init(app, s, lte, corr_inp); - else + } else { gk_neut_species_lte_kinetic_init(app, s, lte, corr_inp); + } } -void -gk_neut_species_lte_from_moms(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_lte *lte, const struct gkyl_array *moms_lte) +void gk_neut_species_lte_from_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_lte *lte, + const struct gkyl_array *moms_lte +) { lte->from_moms_func(app, species, lte, moms_lte); } -void -gk_neut_species_lte(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_lte *lte, const struct gkyl_array *fin) +void gk_neut_species_lte( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_lte *lte, + const struct gkyl_array *fin +) { lte->from_f_func(app, species, lte, fin); } -void -gk_neut_species_lte_write_max_corr_status(gkyl_gyrokinetic_app* app, struct gk_neut_species *gk_ns) +void gk_neut_species_lte_write_max_corr_status( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gk_ns +) { gk_ns->lte.write_max_corr_status_func(app, gk_ns); } -void -gk_neut_species_lte_release(const struct gkyl_gyrokinetic_app *app, const struct gk_lte *lte) +void gk_neut_species_lte_release(const struct gkyl_gyrokinetic_app *app, const struct gk_lte *lte) { lte->release_func(app, lte); } diff --git a/gyrokinetic/apps/gk_neut_species_moment.c b/gyrokinetic/apps/gk_neut_species_moment.c index 3c4ed271a0..ee1abaeb29 100644 --- a/gyrokinetic/apps/gk_neut_species_moment.c +++ b/gyrokinetic/apps/gk_neut_species_moment.c @@ -1,62 +1,66 @@ #include #include -static void -gk_neut_species_moment_diag_jacobgeo_div_disabled(const struct gkyl_gyrokinetic_app *app, - struct gk_species_moment *sm, struct gkyl_array *Jmom_in, struct gkyl_array *mom_out) +static void gk_neut_species_moment_diag_jacobgeo_div_disabled( + const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, struct gkyl_array *Jmom_in, + struct gkyl_array *mom_out +) { // Do nothing. } -static void -gk_neut_species_moment_diag_jacobgeo_div_enabled_1st_comp(const struct gkyl_gyrokinetic_app *app, - struct gk_species_moment *sm, struct gkyl_array *Jmom_in, struct gkyl_array *mom_out) +static void gk_neut_species_moment_diag_jacobgeo_div_enabled_1st_comp( + const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, struct gkyl_array *Jmom_in, + struct gkyl_array *mom_out +) { // Only divide the first component. - gkyl_dg_div_op_range(sm->mem_geo, &app->basis, 0, mom_out, 0, Jmom_in, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + sm->mem_geo, &app->basis, 0, mom_out, 0, Jmom_in, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); } -static void -gk_neut_species_moment_diag_jacobgeo_div_enabled_all_comp(const struct gkyl_gyrokinetic_app *app, - struct gk_species_moment *sm, struct gkyl_array *Jmom_in, struct gkyl_array *mom_out) +static void gk_neut_species_moment_diag_jacobgeo_div_enabled_all_comp( + const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, struct gkyl_array *Jmom_in, + struct gkyl_array *mom_out +) { // Divide all components. - for (int k=0; knum_mom; k++) - gkyl_dg_div_op_range(sm->mem_geo, &app->basis, k, mom_out, k, Jmom_in, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + for (int k = 0; k < sm->num_mom; k++) { + gkyl_dg_div_op_range( + sm->mem_geo, &app->basis, k, mom_out, k, Jmom_in, 0, app->gk_geom->geo_int.jacobgeo, + &app->local + ); + } } -static void -gk_neut_species_kinetic_moment_calc(const struct gk_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin) +static void gk_neut_species_kinetic_moment_calc( + const struct gk_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +) { if (sm->is_maxwellian_moms) { - gkyl_vlasov_lte_moments_advance(sm->vlasov_lte_moms, - &phase_rng, &conf_rng, fin, sm->marr); + gkyl_vlasov_lte_moments_advance(sm->vlasov_lte_moms, &phase_rng, &conf_rng, fin, sm->marr); + } else { + gkyl_dg_updater_moment_advance(sm->mcalc, &phase_rng, &conf_rng, fin, sm->marr); } - else { - gkyl_dg_updater_moment_advance(sm->mcalc, - &phase_rng, &conf_rng, fin, sm->marr); - } } -static void -gk_neut_species_kinetic_moment_release(const struct gkyl_gyrokinetic_app *app, const struct gk_species_moment *sm) +static void gk_neut_species_kinetic_moment_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_species_moment *sm +) { gkyl_array_release(sm->marr); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_release(sm->marr_host); + } if (sm->is_integrated) { gkyl_dg_updater_moment_release(sm->mcalc); - } - else { + } else { if (sm->is_maxwellian_moms) { gkyl_vlasov_lte_moments_release(sm->vlasov_lte_moms); - } - else { + } else { gkyl_dg_updater_moment_release(sm->mcalc); } @@ -65,9 +69,10 @@ gk_neut_species_kinetic_moment_release(const struct gkyl_gyrokinetic_app *app, c } } -static void -gk_neut_species_kinetic_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_species_moment *sm, enum gkyl_distribution_moments mom_type, bool is_integrated) +static void gk_neut_species_kinetic_moment_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_species_moment *sm, + enum gkyl_distribution_moments mom_type, bool is_integrated +) { sm->diag_jacobgeo_div_func = gk_neut_species_moment_diag_jacobgeo_div_disabled; @@ -75,9 +80,10 @@ gk_neut_species_kinetic_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_ if (sm->is_integrated) { // Create moment operator. struct gkyl_mom_canonical_pb_auxfields can_pb_inp = {.hamil = s->hamil}; - sm->mcalc = gkyl_dg_updater_moment_new(&s->grid, &app->basis, - &s->basis, &app->local, &s->local_vel, &s->local, s->model_id, &can_pb_inp, - mom_type, sm->is_integrated, app->use_gpu); + sm->mcalc = gkyl_dg_updater_moment_new( + &s->grid, &app->basis, &s->basis, &app->local, &s->local_vel, &s->local, s->model_id, + &can_pb_inp, mom_type, sm->is_integrated, app->use_gpu + ); sm->num_mom = gkyl_dg_updater_moment_num_mom(sm->mcalc); @@ -85,18 +91,17 @@ gk_neut_species_kinetic_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_ sm->marr = mkarr(app->use_gpu, sm->num_mom, app->local_ext.volume); sm->marr_host = sm->marr; if (app->use_gpu) { - sm->marr_host = mkarr(false, sm->num_mom, app->local_ext.volume); + sm->marr_host = mkarr(false, sm->num_mom, app->local_ext.volume); } - } - else { + } else { // Create moment operator. if (sm->is_maxwellian_moms) { struct gkyl_vlasov_lte_moments_inp inp_mom = { .phase_grid = &s->grid, - .vel_grid = &s->grid_vel, + .vel_grid = &s->grid_vel, .conf_basis = &app->basis, .phase_basis = &s->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .vel_range = &s->local_vel, .phase_range = &s->local, @@ -105,33 +110,33 @@ gk_neut_species_kinetic_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_ .det_h = app->gk_geom->geo_int.jacobgeo, .hamil = s->hamil, .model_id = s->model_id, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; sm->vlasov_lte_moms = gkyl_vlasov_lte_moments_inew(&inp_mom); sm->num_mom = 5; // (n, ux, uy, uz, T/m). sm->diag_jacobgeo_div_func = gk_neut_species_moment_diag_jacobgeo_div_enabled_1st_comp; - } - else { + } else { struct gkyl_mom_canonical_pb_auxfields can_pb_inp = {.hamil = s->hamil}; - sm->mcalc = gkyl_dg_updater_moment_new(&s->grid, &app->basis, - &s->basis, &app->local, &s->local_vel, &s->local, s->model_id, &can_pb_inp, - mom_type, sm->is_integrated, app->use_gpu); + sm->mcalc = gkyl_dg_updater_moment_new( + &s->grid, &app->basis, &s->basis, &app->local, &s->local_vel, &s->local, s->model_id, + &can_pb_inp, mom_type, sm->is_integrated, app->use_gpu + ); sm->num_mom = gkyl_dg_updater_moment_num_mom(sm->mcalc); sm->diag_jacobgeo_div_func = gk_neut_species_moment_diag_jacobgeo_div_enabled_all_comp; } // Allocate arrays to hold moments. - sm->marr = mkarr(app->use_gpu, sm->num_mom*app->basis.num_basis, app->local_ext.volume); + sm->marr = mkarr(app->use_gpu, sm->num_mom * app->basis.num_basis, app->local_ext.volume); sm->marr_host = sm->marr; - if (app->use_gpu) - sm->marr_host = mkarr(false, sm->num_mom*app->basis.num_basis, app->local_ext.volume); + if (app->use_gpu) { + sm->marr_host = mkarr(false, sm->num_mom * app->basis.num_basis, app->local_ext.volume); + } // Bin Op memory for rescaling moment by inverse of Jacobian if (app->use_gpu) { sm->mem_geo = gkyl_dg_bin_op_mem_cu_dev_new(app->local.volume, app->basis.num_basis); - } - else { + } else { sm->mem_geo = gkyl_dg_bin_op_mem_new(app->local.volume, app->basis.num_basis); } } @@ -140,64 +145,64 @@ gk_neut_species_kinetic_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_ sm->release_func = gk_neut_species_kinetic_moment_release; } -static void -gk_neut_species_fluid_moment_calc_m0(const struct gk_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin) +static void gk_neut_species_fluid_moment_calc_m0( + const struct gk_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +) { - gkyl_array_set_offset(sm->marr, 1.0/sm->mass, fin, 0); + gkyl_array_set_offset(sm->marr, 1.0 / sm->mass, fin, 0); } -static void -gk_neut_species_fluid_moment_calc_m1(const struct gk_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin) +static void gk_neut_species_fluid_moment_calc_m1( + const struct gk_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +) { - gkyl_array_set_offset(sm->marr, 1.0/sm->mass, fin, 1*sm->num_basis_conf); + gkyl_array_set_offset(sm->marr, 1.0 / sm->mass, fin, 1 * sm->num_basis_conf); } -static void -gk_neut_species_fluid_moment_calc_m2(const struct gk_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin) +static void gk_neut_species_fluid_moment_calc_m2( + const struct gk_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +) { - gkyl_array_set_offset(sm->marr, 2.0/sm->mass, fin, 4*sm->num_basis_conf); + gkyl_array_set_offset(sm->marr, 2.0 / sm->mass, fin, 4 * sm->num_basis_conf); } -static void -gk_neut_species_fluid_moment_calc(const struct gk_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin) +static void gk_neut_species_fluid_moment_calc( + const struct gk_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +) { if (sm->is_integrated) { - gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_advance(sm->nf_prim_vars, fin, sm->marr, 0); - } - else { + gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_advance( + sm->nf_prim_vars, fin, sm->marr, 0 + ); + } else { if (sm->is_maxwellian_moms) { // Get LTE moments. gkyl_gk_neut_fluid_prim_vars_lte_advance(sm->nf_prim_vars, fin, sm->marr, 0); - } - else { + } else { sm->fluid_calc_M(sm, phase_rng, conf_rng, fin); - } - } + } + } } -static void -gk_neut_species_fluid_moment_release(const struct gkyl_gyrokinetic_app *app, const struct gk_species_moment *sm) +static void gk_neut_species_fluid_moment_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_species_moment *sm +) { gkyl_array_release(sm->marr); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_release(sm->marr_host); + } if (sm->is_integrated) { gkyl_gk_neut_fluid_prim_vars_release(sm->nf_prim_vars); - } - else { + } else { if (sm->is_maxwellian_moms) { gkyl_gk_neut_fluid_prim_vars_release(sm->nf_prim_vars); - } - else { + } else { // Nothing to release. } @@ -206,9 +211,10 @@ gk_neut_species_fluid_moment_release(const struct gkyl_gyrokinetic_app *app, con } } -static void -gk_neut_species_fluid_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_species_moment *sm, enum gkyl_distribution_moments mom_type, bool is_integrated) +static void gk_neut_species_fluid_moment_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_species_moment *sm, + enum gkyl_distribution_moments mom_type, bool is_integrated +) { sm->diag_jacobgeo_div_func = gk_neut_species_moment_diag_jacobgeo_div_disabled; @@ -220,38 +226,36 @@ gk_neut_species_fluid_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_ne sm->marr = mkarr(app->use_gpu, sm->num_mom, app->local_ext.volume); sm->marr_host = sm->marr; if (app->use_gpu) { - sm->marr_host = mkarr(false, sm->num_mom, app->local_ext.volume); + sm->marr_host = mkarr(false, sm->num_mom, app->local_ext.volume); } - sm->nf_prim_vars = gkyl_gk_neut_fluid_prim_vars_new(s->info.gas_gamma, s->info.mass, &app->basis, - &app->grid, &app->local_ext, GKYL_GK_NEUT_FLUID_PRIM_VARS_MASS_MOMENTUM_FLOW_THERMAL_ENERGY, - true, app->use_gpu); - } - else { + sm->nf_prim_vars = gkyl_gk_neut_fluid_prim_vars_new( + s->info.gas_gamma, s->info.mass, &app->basis, &app->grid, &app->local_ext, + GKYL_GK_NEUT_FLUID_PRIM_VARS_MASS_MOMENTUM_FLOW_THERMAL_ENERGY, true, app->use_gpu + ); + } else { if (sm->is_maxwellian_moms) { // Compute (n, ux, uy, uz, T/m) moments. sm->num_mom = 5; - sm->nf_prim_vars = gkyl_gk_neut_fluid_prim_vars_new(s->info.gas_gamma, s->info.mass, - &app->basis, &app->grid, &app->local_ext, GKYL_GK_NEUT_FLUID_PRIM_VARS_LTE, false, app->use_gpu); + sm->nf_prim_vars = gkyl_gk_neut_fluid_prim_vars_new( + s->info.gas_gamma, s->info.mass, &app->basis, &app->grid, &app->local_ext, + GKYL_GK_NEUT_FLUID_PRIM_VARS_LTE, false, app->use_gpu + ); sm->diag_jacobgeo_div_func = gk_neut_species_moment_diag_jacobgeo_div_enabled_1st_comp; - } - else { + } else { sm->mass = s->info.mass; sm->num_basis_conf = app->basis.num_basis; if (mom_type == GKYL_F_MOMENT_M0) { sm->num_mom = 1; sm->fluid_calc_M = gk_neut_species_fluid_moment_calc_m0; - } - else if (mom_type == GKYL_F_MOMENT_M1) { + } else if (mom_type == GKYL_F_MOMENT_M1) { sm->num_mom = 3; sm->fluid_calc_M = gk_neut_species_fluid_moment_calc_m1; - } - else if (mom_type == GKYL_F_MOMENT_M2) { + } else if (mom_type == GKYL_F_MOMENT_M2) { sm->num_mom = 1; sm->fluid_calc_M = gk_neut_species_fluid_moment_calc_m2; - } - else { + } else { // Not yet implemented. assert(false); } @@ -260,16 +264,16 @@ gk_neut_species_fluid_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_ne } // Allocate arrays to hold moments. - sm->marr = mkarr(app->use_gpu, sm->num_mom*app->basis.num_basis, app->local_ext.volume); + sm->marr = mkarr(app->use_gpu, sm->num_mom * app->basis.num_basis, app->local_ext.volume); sm->marr_host = sm->marr; - if (app->use_gpu) + if (app->use_gpu) { sm->marr_host = mkarr(false, sm->marr->ncomp, sm->marr->size); + } // Bin Op memory for rescaling moment by inverse of Jacobian if (app->use_gpu) { sm->mem_geo = gkyl_dg_bin_op_mem_cu_dev_new(app->local.volume, app->basis.num_basis); - } - else { + } else { sm->mem_geo = gkyl_dg_bin_op_mem_new(app->local.volume, app->basis.num_basis); } } @@ -278,9 +282,10 @@ gk_neut_species_fluid_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_ne sm->release_func = gk_neut_species_fluid_moment_release; } -void -gk_neut_species_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_species_moment *sm, enum gkyl_distribution_moments mom_type, bool is_integrated) +void gk_neut_species_moment_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_species_moment *sm, + enum gkyl_distribution_moments mom_type, bool is_integrated +) { // Initialize neutral species moment object. sm->is_integrated = is_integrated; @@ -288,29 +293,30 @@ gk_neut_species_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_spe if (s->is_fluid) { gk_neut_species_fluid_moment_init(app, s, sm, mom_type, is_integrated); - } - else { + } else { gk_neut_species_kinetic_moment_init(app, s, sm, mom_type, is_integrated); } } -void -gk_neut_species_moment_calc(const struct gk_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin) +void gk_neut_species_moment_calc( + const struct gk_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +) { sm->calc_func(sm, phase_rng, conf_rng, fin); } -void -gk_neut_species_moment_diag_jacobgeo_div(const struct gkyl_gyrokinetic_app *app, - struct gk_species_moment *sm, struct gkyl_array *Jmom_in, struct gkyl_array *mom_out) +void gk_neut_species_moment_diag_jacobgeo_div( + const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, struct gkyl_array *Jmom_in, + struct gkyl_array *mom_out +) { sm->diag_jacobgeo_div_func(app, sm, Jmom_in, mom_out); } -void -gk_neut_species_moment_release(const struct gkyl_gyrokinetic_app *app, const struct gk_species_moment *sm) +void gk_neut_species_moment_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_species_moment *sm +) { sm->release_func(app, sm); } diff --git a/gyrokinetic/apps/gk_neut_species_positivity.c b/gyrokinetic/apps/gk_neut_species_positivity.c index ce8f68760c..310f2ad91f 100644 --- a/gyrokinetic/apps/gk_neut_species_positivity.c +++ b/gyrokinetic/apps/gk_neut_species_positivity.c @@ -1,16 +1,17 @@ #include #include -static void -gkns_pos_write_diags_disabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos, double tm, int frame) +static void gkns_pos_write_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, double tm, + int frame +) { // Empty. } -static void -gkns_pos_deltaf_moms_calc(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos) +static void gkns_pos_deltaf_moms_calc( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos +) { gk_neut_species_moment_calc(&pos->moms, gkns->local, app->local, pos->fbuffer_ptr); @@ -18,116 +19,126 @@ gkns_pos_deltaf_moms_calc(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkn gk_species_moment_diag_jacobgeo_div(app, &pos->moms, pos->moms.marr, pos->moms.marr); } -static void -gkns_pos_deltaf_moms_clear(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos) +static void gkns_pos_deltaf_moms_clear( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos +) { gkyl_array_clear(pos->moms.marr, 0.0); pos->deltaf_moms_func_neut = gkns_pos_deltaf_moms_calc; } -static void -gkns_pos_write_diags_enabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos, double tm, int frame) +static void gkns_pos_write_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, double tm, + int frame +) { // Package metadata. gkyl_msgpack_map_elem_set_double(gkns->io_meta_conf_len, gkns->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gkns->io_meta_conf_len, gkns->io_meta_conf, "frame", frame); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, - .cval = "M0M1M2 moments of the change in the distribution by the positivity shift." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "M0M1M2 moments of the change in the distribution by the positivity shift."} }; int io_meta_len[] = {gkns->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); struct timespec wst = gkyl_wall_clock(); // We placed the change in f in fbuffer_ptr. pos->deltaf_moms_func_neut(app, gkns, pos); app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(pos->moms.marr_host, pos->moms.marr); + } const char *fmt = "%s-%s_positivity_%s_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, - gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2], frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, - gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2], frame); - + int sz = gkyl_calc_strlen( + fmt, app->name, gkns->info.name, gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2], frame + ); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, + gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2], frame + ); + struct timespec wtm = gkyl_wall_clock(); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, - pos->moms.marr_host, fileNm); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, pos->moms.marr_host, fileNm); app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wtm); app->stat.n_neut_diag_io += 1; - - gkyl_msgpack_data_release(mt); + + gkyl_msgpack_data_release(mt); app->stat.n_neut_diag += 1; } -static void -gkns_pos_calc_integrated_diags_disabled(gkyl_gyrokinetic_app* app, - struct gk_neut_species *gkns, struct gk_positivity *pos, double tm) +static void gkns_pos_calc_integrated_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, double tm +) { // Empty. } -static void -gkns_pos_deltaf_integ_moms_calc(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos) +static void gkns_pos_deltaf_integ_moms_calc( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos +) { - gk_neut_species_moment_calc(&pos->integ_moms, gkns->local, app->local, pos->fbuffer_ptr); + gk_neut_species_moment_calc(&pos->integ_moms, gkns->local, app->local, pos->fbuffer_ptr); } -static void -gkns_pos_deltaf_integ_moms_clear(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos) +static void gkns_pos_deltaf_integ_moms_clear( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos +) { gkyl_array_clear(pos->integ_moms.marr, 0.0); pos->deltaf_integ_moms_func_neut = gkns_pos_deltaf_integ_moms_calc; } -static void -gkns_pos_calc_integrated_diags_enabled(gkyl_gyrokinetic_app* app, - struct gk_neut_species *gkns, struct gk_positivity *pos, double tm) +static void gkns_pos_calc_integrated_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, double tm +) { struct timespec wst = gkyl_wall_clock(); int num_mom = pos->integ_moms.num_mom; double avals_global[num_mom]; - + // The change in f after the positivity operation is stored in fbuffer_ptr. pos->deltaf_integ_moms_func_neut(app, gkns, pos); app->stat.n_mom += 1; // Reduce (sum) over whole domain, append to diagnostics. gkyl_array_reduce_range(pos->red_integ_diag, pos->integ_moms.marr, GKYL_SUM, &app->local); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, - pos->red_integ_diag, pos->red_integ_diag_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, pos->red_integ_diag, pos->red_integ_diag_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, pos->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, pos->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, pos->red_integ_diag_global, sizeof(double[num_mom])); } gkyl_dynvec_append(pos->integ_diag, tm, avals_global); - + app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); app->stat.n_neut_diag += 1; } -static void -gkns_pos_write_integrated_diags_disabled(gkyl_gyrokinetic_app *app, - struct gk_neut_species *gkns, struct gk_positivity *pos) +static void gkns_pos_write_integrated_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos +) { // Empty. } -static void -gkns_pos_write_integrated_diags_enabled(gkyl_gyrokinetic_app *app, - struct gk_neut_species *gkns, struct gk_positivity *pos) +static void gkns_pos_write_integrated_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos +) { struct timespec wst = gkyl_wall_clock(); @@ -138,23 +149,27 @@ gkns_pos_write_integrated_diags_enabled(gkyl_gyrokinetic_app *app, // Write integrated diagnostic moments. const char *fmt = "%s-%s_positivity_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, "integrated_moms"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, "integrated_moms"); if (pos->is_first_integ_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated moments of change in distribution due to positivity shift." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Volume integrated moments of change in distribution due to positivity shift."} }; int io_meta_len[] = {gkns->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(pos->integ_diag, fileNm, mt); pos->is_first_integ_write_call = false; pos->integ_diag_file_exists = true; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(pos->integ_diag, fileNm); } } @@ -164,32 +179,35 @@ gkns_pos_write_integrated_diags_enabled(gkyl_gyrokinetic_app *app, app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wst); } -void -gkns_pos_apply_disabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - struct gk_positivity *pos, struct gkyl_array *fbuffer, struct gkyl_array *fout) +void gkns_pos_apply_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, struct gk_positivity *pos, + struct gkyl_array *fbuffer, struct gkyl_array *fout +) { // Do nothing. } -void -gkns_pos_apply_enabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_positivity *pos, struct gkyl_array *fbuffer, struct gkyl_array *fout) +void gkns_pos_apply_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, + struct gkyl_array *fbuffer, struct gkyl_array *fout +) { struct timespec wtm = gkyl_wall_clock(); - // Copy f so we can calculate the moments of delta f later. + // Copy f so we can calculate the moments of delta f later. pos->fbuffer_ptr = fbuffer; gkyl_array_set(pos->fbuffer_ptr, -1.0, fout); // Shift each species. - gkyl_positivity_shift_vlasov_advance(pos->shift_op_vlasov, &app->local, &gkns->local, - fout, gkns->m0.marr, pos->delta_m0); + gkyl_positivity_shift_vlasov_advance( + pos->shift_op_vlasov, &app->local, &gkns->local, fout, gkns->m0.marr, pos->delta_m0 + ); app->stat.species_pos_shift_tm += gkyl_time_diff_now_sec(wtm); } -void -gk_neut_species_positivity_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_positivity *pos) +void gk_neut_species_positivity_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos +) { pos->type = gkns->info.positivity.type; pos->write_diagnostics = gkns->info.positivity.write_diagnostics; @@ -201,12 +219,12 @@ gk_neut_species_positivity_init(struct gkyl_gyrokinetic_app *app, struct gk_neut pos->write_integrated_diags_func_neut = gkns_pos_write_integrated_diags_disabled; if (pos->type) { - pos->delta_m0 = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); // Positivity shift updater. - pos->shift_op_vlasov = gkyl_positivity_shift_vlasov_new(app->basis, gkns->basis, - gkns->grid, &app->local_ext, app->use_gpu); + pos->shift_op_vlasov = gkyl_positivity_shift_vlasov_new( + app->basis, gkns->basis, gkns->grid, &app->local_ext, app->use_gpu + ); // Methods chosen at runtime. pos->apply_func_neut = gkns_pos_apply_enabled; @@ -221,8 +239,7 @@ gk_neut_species_positivity_init(struct gkyl_gyrokinetic_app *app, struct gk_neut if (app->use_gpu) { pos->red_integ_diag = gkyl_cu_malloc(sizeof(double[pos->integ_moms.num_mom])); pos->red_integ_diag_global = gkyl_cu_malloc(sizeof(double[pos->integ_moms.num_mom])); - } - else { + } else { pos->red_integ_diag = gkyl_malloc(sizeof(double[pos->integ_moms.num_mom])); pos->red_integ_diag_global = gkyl_malloc(sizeof(double[pos->integ_moms.num_mom])); } @@ -236,66 +253,66 @@ gk_neut_species_positivity_init(struct gkyl_gyrokinetic_app *app, struct gk_neut pos->calc_integrated_diags_func_neut = gkns_pos_calc_integrated_diags_enabled; pos->write_integrated_diags_func_neut = gkns_pos_write_integrated_diags_enabled; } - } } -void -gk_neut_species_positivity_apply(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_positivity *pos, struct gkyl_array *fbuffer, struct gkyl_array *fout) +void gk_neut_species_positivity_apply( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, + struct gkyl_array *fbuffer, struct gkyl_array *fout +) { pos->apply_func_neut(app, gkns, pos, fbuffer, fout); } -void -gk_neut_species_positivity_write_diags(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos, double tm, int frame) +void gk_neut_species_positivity_write_diags( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, double tm, + int frame +) { pos->write_diags_func_neut(app, gkns, pos, tm, frame); } -void -gk_neut_species_positivity_calc_integrated_diags(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos, double tm) +void gk_neut_species_positivity_calc_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, double tm +) { pos->calc_integrated_diags_func_neut(app, gkns, pos, tm); } -void -gk_neut_species_positivity_write_integrated_diags(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_positivity *pos) +void gk_neut_species_positivity_write_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos +) { pos->write_integrated_diags_func_neut(app, gkns, pos); } -void -gk_neut_species_positivity_release(const struct gkyl_gyrokinetic_app *app, const struct gk_positivity *pos) +void gk_neut_species_positivity_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_positivity *pos +) { if (pos->type) { - gkyl_array_release(pos->delta_m0); gkyl_positivity_shift_vlasov_release(pos->shift_op_vlasov); if (pos->write_diagnostics) { gk_neut_species_moment_release(app, &pos->moms); - gk_neut_species_moment_release(app, &pos->integ_moms); + gk_neut_species_moment_release(app, &pos->integ_moms); gkyl_dynvec_release(pos->integ_diag); if (app->use_gpu) { gkyl_cu_free(pos->red_integ_diag); gkyl_cu_free(pos->red_integ_diag_global); - } - else { + } else { gkyl_free(pos->red_integ_diag); gkyl_free(pos->red_integ_diag_global); } } - } } -void -gk_neut_species_positivity_reset(gkyl_gyrokinetic_app* app, double tm, - struct gk_neut_species *gkns, struct gk_positivity *pos, struct gkyl_gyrokinetic_positivity pos_inp) +void gk_neut_species_positivity_reset( + gkyl_gyrokinetic_app *app, double tm, struct gk_neut_species *gkns, struct gk_positivity *pos, + struct gkyl_gyrokinetic_positivity pos_inp +) { gk_neut_species_positivity_release(app, pos); diff --git a/gyrokinetic/apps/gk_neut_species_projection.c b/gyrokinetic/apps/gk_neut_species_projection.c index 0393a0f86a..d87ccb3aec 100644 --- a/gyrokinetic/apps/gk_neut_species_projection.c +++ b/gyrokinetic/apps/gk_neut_species_projection.c @@ -1,63 +1,66 @@ #include #include -static void -gk_neut_species_projection_kinetic_calc(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm) +static void gk_neut_species_projection_kinetic_calc( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm +) { if (proj->proj_id == GKYL_PROJ_FUNC) { if (app->use_gpu) { gkyl_proj_on_basis_advance(proj->proj_func, tm, &s->local_ext, proj->proj_host); gkyl_array_copy(f, proj->proj_host); - } - else { + } else { gkyl_proj_on_basis_advance(proj->proj_func, tm, &s->local_ext, f); } - } - else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { + } else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { int vdim = s->info.vdim; - gkyl_proj_on_basis_advance(proj->proj_dens, tm, &app->local, proj->dens); + gkyl_proj_on_basis_advance(proj->proj_dens, tm, &app->local, proj->dens); gkyl_proj_on_basis_advance(proj->proj_udrift, tm, &app->local, proj->udrift); gkyl_proj_on_basis_advance(proj->proj_temp, tm, &app->local, proj->vtsq); - gkyl_array_scale(proj->vtsq, 1/s->info.mass); + gkyl_array_scale(proj->vtsq, 1 / s->info.mass); // Projection routines expect the LTE moments as a single array. - gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->dens, 0*app->basis.num_basis); - gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->udrift, 1*app->basis.num_basis); - gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->vtsq, (vdim+1)*app->basis.num_basis); + gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->dens, 0 * app->basis.num_basis); + gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->udrift, 1 * app->basis.num_basis); + gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->vtsq, (vdim + 1) * app->basis.num_basis); // Copy the contents into the array we will use (potentially on GPUs). gkyl_array_copy(proj->prim_moms, proj->prim_moms_host); // Multiply density by the conf-space jacobian. - gkyl_dg_mul_op_range(&app->basis, 0, proj->prim_moms, - 0, app->gk_geom->geo_int.jacobgeo, 0, proj->prim_moms, &app->local); + gkyl_dg_mul_op_range( + &app->basis, 0, proj->prim_moms, 0, app->gk_geom->geo_int.jacobgeo, 0, proj->prim_moms, + &app->local + ); // Project the Maxwellian distribution function. // Projection routine also corrects the density of the projected distribution function. - gkyl_vlasov_lte_proj_on_basis_advance(proj->proj_lte, &s->local, &app->local, - proj->prim_moms, f); + gkyl_vlasov_lte_proj_on_basis_advance( + proj->proj_lte, &s->local, &app->local, proj->prim_moms, f + ); // Correct all the moments of the projected Maxwellian distribution function. if (proj->correct_all_moms) { - struct gkyl_vlasov_lte_correct_status status_corr = gkyl_vlasov_lte_correct_all_moments(proj->corr_lte, - f, proj->prim_moms, &s->local, &app->local); - } + struct gkyl_vlasov_lte_correct_status status_corr = gkyl_vlasov_lte_correct_all_moments( + proj->corr_lte, f, proj->prim_moms, &s->local, &app->local + ); + } } } -static void -gk_neut_species_projection_kinetic_release(const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj) +static void gk_neut_species_projection_kinetic_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj +) { if (proj->proj_id == GKYL_PROJ_FUNC) { gkyl_proj_on_basis_release(proj->proj_func); if (app->use_gpu) { gkyl_array_release(proj->proj_host); } - } - else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { + } else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { gkyl_array_release(proj->dens); - gkyl_array_release(proj->udrift); + gkyl_array_release(proj->udrift); gkyl_array_release(proj->vtsq); gkyl_array_release(proj->prim_moms_host); gkyl_array_release(proj->prim_moms); @@ -65,55 +68,55 @@ gk_neut_species_projection_kinetic_release(const struct gkyl_gyrokinetic_app *ap gkyl_proj_on_basis_release(proj->proj_dens); gkyl_proj_on_basis_release(proj->proj_udrift); gkyl_proj_on_basis_release(proj->proj_temp); - + gkyl_vlasov_lte_proj_on_basis_release(proj->proj_lte); if (proj->correct_all_moms) { gkyl_vlasov_lte_correct_release(proj->corr_lte); } - } + } } -static void -gk_neut_species_projection_kinetic_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj) +static void gk_neut_species_projection_kinetic_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, + struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj +) { proj->proj_id = inp.proj_id; if (proj->proj_id == GKYL_PROJ_FUNC) { - proj->proj_func = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &s->grid, - .basis = &s->basis, - .qtype = GKYL_GAUSS_QUAD, - .num_quad = s->basis.poly_order+1, - .num_ret_vals = 1, - .eval = inp.func, - .ctx = inp.ctx_func, - } - ); + proj->proj_func = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &s->grid, + .basis = &s->basis, + .qtype = GKYL_GAUSS_QUAD, + .num_quad = s->basis.poly_order + 1, + .num_ret_vals = 1, + .eval = inp.func, + .ctx = inp.ctx_func}); if (app->use_gpu) { proj->proj_host = mkarr(false, s->basis.num_basis, s->local_ext.volume); } - } - else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { + } else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { int vdim = s->info.vdim; proj->dens = mkarr(false, app->basis.num_basis, app->local_ext.volume); - proj->udrift = mkarr(false, vdim*app->basis.num_basis, app->local_ext.volume); + proj->udrift = mkarr(false, vdim * app->basis.num_basis, app->local_ext.volume); proj->vtsq = mkarr(false, app->basis.num_basis, app->local_ext.volume); - proj->prim_moms_host = mkarr(false, (2+vdim)*app->basis.num_basis, app->local_ext.volume); - proj->prim_moms = mkarr(app->use_gpu, (2+vdim)*app->basis.num_basis, app->local_ext.volume); - - proj->proj_dens = gkyl_proj_on_basis_new(&app->grid, &app->basis, - s->basis.poly_order+1, 1, inp.density, inp.ctx_density); - proj->proj_udrift = gkyl_proj_on_basis_new(&app->grid, &app->basis, - s->basis.poly_order+1, vdim, inp.udrift, inp.ctx_udrift); - proj->proj_temp = gkyl_proj_on_basis_new(&app->grid, &app->basis, - s->basis.poly_order+1, 1, inp.temp, inp.ctx_temp); + proj->prim_moms_host = mkarr(false, (2 + vdim) * app->basis.num_basis, app->local_ext.volume); + proj->prim_moms = mkarr(app->use_gpu, (2 + vdim) * app->basis.num_basis, app->local_ext.volume); + proj->proj_dens = gkyl_proj_on_basis_new( + &app->grid, &app->basis, s->basis.poly_order + 1, 1, inp.density, inp.ctx_density + ); + proj->proj_udrift = gkyl_proj_on_basis_new( + &app->grid, &app->basis, s->basis.poly_order + 1, vdim, inp.udrift, inp.ctx_udrift + ); + proj->proj_temp = gkyl_proj_on_basis_new( + &app->grid, &app->basis, s->basis.poly_order + 1, 1, inp.temp, inp.ctx_temp + ); struct gkyl_vlasov_lte_proj_on_basis_inp inp_proj = { .phase_grid = &s->grid, .conf_basis = &app->basis, .phase_basis = &s->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .vel_range = &s->local_vel, .vel_map = s->vel_map, @@ -123,11 +126,11 @@ gk_neut_species_projection_kinetic_init(struct gkyl_gyrokinetic_app *app, struct .det_h = app->gk_geom->geo_int.jacobgeo, .hamil = s->hamil, .model_id = s->model_id, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - proj->proj_lte = gkyl_vlasov_lte_proj_on_basis_inew( &inp_proj ); + proj->proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_proj); - proj->correct_all_moms = false; + proj->correct_all_moms = false; if (inp.correct_all_moms) { proj->correct_all_moms = true; @@ -135,7 +138,7 @@ gk_neut_species_projection_kinetic_init(struct gkyl_gyrokinetic_app *app, struct .phase_grid = &s->grid, .conf_basis = &app->basis, .phase_basis = &s->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .vel_range = &s->local_vel, .vel_map = s->vel_map, @@ -143,13 +146,13 @@ gk_neut_species_projection_kinetic_init(struct gkyl_gyrokinetic_app *app, struct .h_ij = s->g_ij, .h_ij_inv = s->gij, .det_h = app->gk_geom->geo_int.jacobgeo, - .hamil = s->hamil, + .hamil = s->hamil, .model_id = s->model_id, .use_gpu = app->use_gpu, .max_iter = 100, - .eps = 1e-12, + .eps = 1e-12 }; - proj->corr_lte = gkyl_vlasov_lte_correct_inew( &inp_corr ); + proj->corr_lte = gkyl_vlasov_lte_correct_inew(&inp_corr); } } @@ -157,21 +160,20 @@ gk_neut_species_projection_kinetic_init(struct gkyl_gyrokinetic_app *app, struct proj->release_func = gk_neut_species_projection_kinetic_release; } -static void -gk_neut_species_projection_fluid_calc(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm) +static void gk_neut_species_projection_fluid_calc( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm +) { if (proj->proj_id == GKYL_PROJ_FUNC) { if (app->use_gpu) { gkyl_proj_on_basis_advance(proj->proj_func, tm, &s->local_ext, proj->proj_host); gkyl_array_copy(f, proj->proj_host); - } - else { + } else { gkyl_proj_on_basis_advance(proj->proj_func, tm, &s->local_ext, f); } - } - else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { - gkyl_proj_on_basis_advance(proj->proj_dens, tm, &app->local, proj->dens); + } else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { + gkyl_proj_on_basis_advance(proj->proj_dens, tm, &app->local, proj->dens); gkyl_proj_on_basis_advance(proj->proj_udrift, tm, &app->local, proj->udrift); gkyl_proj_on_basis_advance(proj->proj_temp, tm, &app->local, proj->vtsq); @@ -181,110 +183,123 @@ gk_neut_species_projection_fluid_calc(gkyl_gyrokinetic_app *app, struct gk_neut_ // f[1] = f[0]*udrift[0] // f[2] = f[0]*udrift[1] // f[3] = f[0]*udrift[2] - for (int d=0; d<3; d++) { - gkyl_dg_mul_op_range(&app->basis, d+1, proj->proj_host, 0, proj->proj_host, d, proj->udrift, &app->local); + for (int d = 0; d < 3; d++) { + gkyl_dg_mul_op_range( + &app->basis, d + 1, proj->proj_host, 0, proj->proj_host, d, proj->udrift, &app->local + ); } // f[4] = 0.5*rho*u^2 + p/(gas_gamma-1) // = 0.5*(rho*ux^2+rho*uy^2+rho*uz^2) + dens*temp/(gas_gamma-1) // = 0.5*(f[1].udrift[0]+f[2].udrift[1]+f[3].udrift[2]) + dens*temp/(gas_gamma-1) gkyl_dg_mul_op_range(&app->basis, 0, proj->vtsq, 0, proj->dens, 0, proj->vtsq, &app->local); - gkyl_array_set_offset_range(proj->proj_host, 1.0/(s->info.gas_gamma-1.0), proj->vtsq, 4*app->basis.num_basis, &app->local); - for (int d=0; d<3; d++) { - gkyl_dg_mul_op_range(&app->basis, 0, proj->dens, d+1, proj->proj_host, d, proj->udrift, &app->local); - gkyl_array_accumulate_offset_range(proj->proj_host, 0.5, proj->dens, 4*app->basis.num_basis, &app->local); + gkyl_array_set_offset_range( + proj->proj_host, 1.0 / (s->info.gas_gamma - 1.0), proj->vtsq, 4 * app->basis.num_basis, + &app->local + ); + for (int d = 0; d < 3; d++) { + gkyl_dg_mul_op_range( + &app->basis, 0, proj->dens, d + 1, proj->proj_host, d, proj->udrift, &app->local + ); + gkyl_array_accumulate_offset_range( + proj->proj_host, 0.5, proj->dens, 4 * app->basis.num_basis, &app->local + ); } // Copy the contents into the array we will use (potentially on GPUs). gkyl_array_copy(f, proj->proj_host); // Multiply moments by the conf-space Jacobian. - for (int d=0; dnum_moments; d++) { + for (int d = 0; d < s->num_moments; d++) { gkyl_dg_mul_op_range(&app->basis, d, f, 0, app->gk_geom->geo_int.jacobgeo, d, f, &app->local); } - } } -static void -gk_neut_species_projection_fluid_release(const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj) +static void gk_neut_species_projection_fluid_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj +) { if (proj->proj_id == GKYL_PROJ_FUNC) { gkyl_proj_on_basis_release(proj->proj_func); if (app->use_gpu) { gkyl_array_release(proj->proj_host); } - } - else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { + } else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { gkyl_array_release(proj->dens); - gkyl_array_release(proj->udrift); + gkyl_array_release(proj->udrift); gkyl_array_release(proj->vtsq); gkyl_array_release(proj->proj_host); gkyl_proj_on_basis_release(proj->proj_dens); gkyl_proj_on_basis_release(proj->proj_udrift); gkyl_proj_on_basis_release(proj->proj_temp); - } + } } -static void -gk_neut_species_projection_fluid_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj) +static void gk_neut_species_projection_fluid_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, + struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj +) { proj->proj_id = inp.proj_id; if (proj->proj_id == GKYL_PROJ_FUNC) { - proj->proj_func = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &ns->grid, - .basis = &ns->basis, - .qtype = GKYL_GAUSS_QUAD, - .num_quad = ns->basis.poly_order+1, - .num_ret_vals = ns->num_moments, - .eval = inp.func, - .ctx = inp.ctx_func, - } - ); + proj->proj_func = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &ns->grid, + .basis = &ns->basis, + .qtype = GKYL_GAUSS_QUAD, + .num_quad = ns->basis.poly_order + 1, + .num_ret_vals = ns->num_moments, + .eval = inp.func, + .ctx = inp.ctx_func}); if (app->use_gpu) { - proj->proj_host = mkarr(false, ns->num_moments*ns->basis.num_basis, ns->local_ext.volume); + proj->proj_host = mkarr(false, ns->num_moments * ns->basis.num_basis, ns->local_ext.volume); } - } - else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { - int udim = ns->num_moments-2; + } else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { + int udim = ns->num_moments - 2; proj->dens = mkarr(false, app->basis.num_basis, app->local_ext.volume); - proj->udrift = mkarr(false, udim*app->basis.num_basis, app->local_ext.volume); + proj->udrift = mkarr(false, udim * app->basis.num_basis, app->local_ext.volume); proj->vtsq = mkarr(false, app->basis.num_basis, app->local_ext.volume); proj->proj_host = mkarr(false, ns->f->ncomp, ns->f->size); - proj->proj_dens = gkyl_proj_on_basis_new(&app->grid, &app->basis, - ns->basis.poly_order+1, 1, inp.density, inp.ctx_density); - proj->proj_udrift = gkyl_proj_on_basis_new(&app->grid, &app->basis, - ns->basis.poly_order+1, udim, inp.udrift, inp.ctx_udrift); - proj->proj_temp = gkyl_proj_on_basis_new(&app->grid, &app->basis, - ns->basis.poly_order+1, 1, inp.temp, inp.ctx_temp); + proj->proj_dens = gkyl_proj_on_basis_new( + &app->grid, &app->basis, ns->basis.poly_order + 1, 1, inp.density, inp.ctx_density + ); + proj->proj_udrift = gkyl_proj_on_basis_new( + &app->grid, &app->basis, ns->basis.poly_order + 1, udim, inp.udrift, inp.ctx_udrift + ); + proj->proj_temp = gkyl_proj_on_basis_new( + &app->grid, &app->basis, ns->basis.poly_order + 1, 1, inp.temp, inp.ctx_temp + ); } proj->neut_calc_func = gk_neut_species_projection_fluid_calc; proj->release_func = gk_neut_species_projection_fluid_release; } -void -gk_neut_species_projection_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj) +void gk_neut_species_projection_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, + struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj +) { - if (s->is_fluid) + if (s->is_fluid) { gk_neut_species_projection_fluid_init(app, s, inp, proj); - else + } else { gk_neut_species_projection_kinetic_init(app, s, inp, proj); + } } -void -gk_neut_species_projection_calc(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm) +void gk_neut_species_projection_calc( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm +) { proj->neut_calc_func(app, s, proj, f, tm); } -void -gk_neut_species_projection_release(const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj) +void gk_neut_species_projection_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj +) { proj->release_func(app, proj); } diff --git a/gyrokinetic/apps/gk_neut_species_react.c b/gyrokinetic/apps/gk_neut_species_react.c index c4268d05f8..70abaefda2 100644 --- a/gyrokinetic/apps/gk_neut_species_react.c +++ b/gyrokinetic/apps/gk_neut_species_react.c @@ -1,126 +1,145 @@ #include #include -static void -gkns_react_cross_moms_disabled(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_react *react, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +static void gkns_react_cross_moms_disabled( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_react *react, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { // Do nothing. } -static void -gkns_react_cross_moms_enabled(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_react *react, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +static void gkns_react_cross_moms_enabled( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_react *react, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { - struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_react; ++i) { - struct gk_species *gks_elc = &app->species[react->elc_idx[i]]; - struct gk_species *gks_ion = &app->species[react->ion_idx[i]]; + struct timespec wst = gkyl_wall_clock(); + for (int i = 0; i < react->num_react; ++i) { + struct gk_species *gks_elc = &app->species[react->elc_idx[i]]; + struct gk_species *gks_ion = &app->species[react->ion_idx[i]]; if (react->react_id[i] == GKYL_REACT_IZ) { - // compute needed electron Maxwellian moments (J*n, u_par, T/m) - gk_species_moment_calc(&gks_elc->lte.moms, - gks_elc->local, app->local, fin[react->elc_idx[i]]); + // compute needed electron Maxwellian moments (J*n, u_par, T/m) + gk_species_moment_calc(&gks_elc->lte.moms, gks_elc->local, app->local, fin[react->elc_idx[i]]); // divide out the Jacobian from the electron density for computing reaction rates - gkyl_dg_div_op_range(gks_elc->lte.moms.mem_geo, &app->basis, - 0, gks_elc->lte.moms.marr, 0, gks_elc->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gks_elc->lte.moms.mem_geo, &app->basis, 0, gks_elc->lte.moms.marr, 0, + gks_elc->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); // compute ionization reaction rate from input electron primitive moments - gkyl_dg_iz_coll(react->iz[i], gks_elc->lte.moms.marr, - react->vt_sq_iz1[i], react->vt_sq_iz2[i], react->coeff_react[i], 0); - } - else if (react->react_id[i] == GKYL_REACT_RECOMB) { - // compute needed electron Maxwellian moments (J*n, u_par, T/m) - gk_species_moment_calc(&gks_elc->lte.moms, - gks_elc->local, app->local, fin[react->elc_idx[i]]); + gkyl_dg_iz_coll( + react->iz[i], gks_elc->lte.moms.marr, react->vt_sq_iz1[i], react->vt_sq_iz2[i], + react->coeff_react[i], 0 + ); + } else if (react->react_id[i] == GKYL_REACT_RECOMB) { + // compute needed electron Maxwellian moments (J*n, u_par, T/m) + gk_species_moment_calc(&gks_elc->lte.moms, gks_elc->local, app->local, fin[react->elc_idx[i]]); // Copy J*n for use in final update gkyl_array_set_range(react->Jm0_elc[i], 1.0, gks_elc->lte.moms.marr, &app->local); // divide out the Jacobian from the electron density for computing reaction rates - gkyl_dg_div_op_range(gks_elc->lte.moms.mem_geo, &app->basis, - 0, gks_elc->lte.moms.marr, 0, gks_elc->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gks_elc->lte.moms.mem_geo, &app->basis, 0, gks_elc->lte.moms.marr, 0, + gks_elc->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); - // compute needed ion Maxwellian moments (J*n, u_par, T/m) - gk_species_moment_calc(&gks_ion->lte.moms, - gks_ion->local, app->local, fin[react->ion_idx[i]]); + // compute needed ion Maxwellian moments (J*n, u_par, T/m) + gk_species_moment_calc(&gks_ion->lte.moms, gks_ion->local, app->local, fin[react->ion_idx[i]]); // divide out the Jacobian from the ion density for use in Maxwellian projection - gkyl_dg_div_op_range(gks_ion->lte.moms.mem_geo, &app->basis, - 0, gks_ion->lte.moms.marr, 0, gks_ion->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gks_ion->lte.moms.mem_geo, &app->basis, 0, gks_ion->lte.moms.marr, 0, + gks_ion->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); // Construct ion vector velocity upar b_i // if cdim = 1, u0 = upar, if cdim = 2, u1 = upar, if cdim = 3, u2 = upar gkyl_array_clear(react->upar_ion[i], 0.0); - gkyl_array_set_offset(react->u_i_dot_b_i[i], 1.0, gks_ion->lte.moms.marr, 1*app->basis.num_basis); - gkyl_array_set_offset(react->upar_ion[i], 1.0, react->u_i_dot_b_i[i], (app->cdim-1)*app->basis.num_basis); + gkyl_array_set_offset( + react->u_i_dot_b_i[i], 1.0, gks_ion->lte.moms.marr, 1 * app->basis.num_basis + ); + gkyl_array_set_offset( + react->upar_ion[i], 1.0, react->u_i_dot_b_i[i], (app->cdim - 1) * app->basis.num_basis + ); gkyl_array_clear(react->u_i_dot_b_i[i], 0.0); // Copy vt^2 = T/m of the ions - gkyl_array_set_offset(react->vt_sq_ion[i], 1.0, gks_ion->lte.moms.marr, 2*app->basis.num_basis); - + gkyl_array_set_offset( + react->vt_sq_ion[i], 1.0, gks_ion->lte.moms.marr, 2 * app->basis.num_basis + ); + // compute recombination reaction rate - gkyl_dg_recomb_coll(react->recomb[i], gks_elc->lte.moms.marr, - react->coeff_react[i], 0); - } - else if (react->react_id[i] == GKYL_REACT_CX) { - // compute needed ion Maxwellian moments (J*n, u_par, T/m) - gk_species_moment_calc(&gks_ion->lte.moms, - gks_ion->local, app->local, fin[react->ion_idx[i]]); + gkyl_dg_recomb_coll(react->recomb[i], gks_elc->lte.moms.marr, react->coeff_react[i], 0); + } else if (react->react_id[i] == GKYL_REACT_CX) { + // compute needed ion Maxwellian moments (J*n, u_par, T/m) + gk_species_moment_calc(&gks_ion->lte.moms, gks_ion->local, app->local, fin[react->ion_idx[i]]); // divide out the Jacobian from the ion density - gkyl_dg_div_op_range(gks_ion->lte.moms.mem_geo, &app->basis, - 0, gks_ion->lte.moms.marr, 0, gks_ion->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gks_ion->lte.moms.mem_geo, &app->basis, 0, gks_ion->lte.moms.marr, 0, + gks_ion->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); // Construct ion vector velocity upar b_i // if cdim = 1, u0 = upar, if cdim = 2, u1 = upar, if cdim = 3, u2 = upar gkyl_array_clear(react->upar_ion[i], 0.0); - gkyl_array_set_offset(react->u_i_dot_b_i[i], 1.0, gks_ion->lte.moms.marr, 1*app->basis.num_basis); - gkyl_array_set_offset(react->upar_ion[i], 1.0, react->u_i_dot_b_i[i], (app->cdim-1)*app->basis.num_basis); + gkyl_array_set_offset( + react->u_i_dot_b_i[i], 1.0, gks_ion->lte.moms.marr, 1 * app->basis.num_basis + ); + gkyl_array_set_offset( + react->upar_ion[i], 1.0, react->u_i_dot_b_i[i], (app->cdim - 1) * app->basis.num_basis + ); gkyl_array_clear(react->u_i_dot_b_i[i], 0.0); // Copy vt^2 = T/m of the ions (partner of the neutrals) - gkyl_array_set_offset(react->vt_sq_ion[i], 1.0, gks_ion->lte.moms.marr, 2*app->basis.num_basis); + gkyl_array_set_offset( + react->vt_sq_ion[i], 1.0, gks_ion->lte.moms.marr, 2 * app->basis.num_basis + ); - // compute needed partner (neutral) Maxwellian moments (J*n, ux, uy, uz, T/m) + // compute needed partner (neutral) Maxwellian moments (J*n, ux, uy, uz, T/m) struct gk_neut_species *gkns_partner = &app->neut_species[react->partner_idx[i]]; - gk_neut_species_moment_calc(&gkns_partner->lte.moms, - gkns_partner->local, app->local, fin_neut[react->partner_idx[i]]); + gk_neut_species_moment_calc( + &gkns_partner->lte.moms, gkns_partner->local, app->local, fin_neut[react->partner_idx[i]] + ); // Copy J*n for use in final update gkyl_array_set_range(react->Jm0_partner[i], 1.0, gkns_partner->lte.moms.marr, &app->local); // Divide out the Jacobian from the partner density. - gkyl_dg_div_op_range(gkns_partner->lte.moms.mem_geo, &app->basis, - 0, gkns_partner->lte.moms.marr, 0, gkns_partner->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gkns_partner->lte.moms.mem_geo, &app->basis, 0, gkns_partner->lte.moms.marr, 0, + gkns_partner->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); // prim_vars_neut_gk is returned to prim_vars[i] here. - gkyl_dg_cx_coll(react->cx[i], gks_ion->lte.moms.marr, gkns_partner->lte.moms.marr, - react->upar_ion[i], react->coeff_react[i], 0); + gkyl_dg_cx_coll( + react->cx[i], gks_ion->lte.moms.marr, gkns_partner->lte.moms.marr, react->upar_ion[i], + react->coeff_react[i], 0 + ); } } app->stat.neut_species_react_mom_tm += gkyl_time_diff_now_sec(wst); } -static void -gkns_react_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_react *react, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gkns_react_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_react *react, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { // Do nothing. } -static void -gkns_react_rhs_enabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_react *react, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gkns_react_rhs_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_react *react, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { - struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_react; ++i) { + struct timespec wst = gkyl_wall_clock(); + for (int i = 0; i < react->num_react; ++i) { gkyl_array_clear(react->f_react, 0.0); gkyl_array_clear(react->react_lte_moms[i], 0.0); @@ -132,56 +151,78 @@ gkns_react_rhs_enabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, // donor update is -n_elc*coeff_react*f_donor // Accumulate -n_elc*(J*f_donor) (*note* Jacobian factor already included in fin) - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - -1.0, gks_elc->lte.moms.marr, fin, &app->local, &s->local); - } - else if (react->react_id[i] == GKYL_REACT_RECOMB) { - // Copy components of partner ions into reaction moments - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, gks_ion->lte.moms.marr, 0*app->basis.num_basis); + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, -1.0, gks_elc->lte.moms.marr, fin, &app->local, + &s->local + ); + } else if (react->react_id[i] == GKYL_REACT_RECOMB) { + // Copy components of partner ions into reaction moments + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, gks_ion->lte.moms.marr, 0 * app->basis.num_basis + ); // Overwrite flow velocity and vt^2 to be upar b_i (vector) and vt^2 of the ions - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, react->upar_ion[i], 1*app->basis.num_basis); - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, react->vt_sq_ion[i], 4*app->basis.num_basis); + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, react->upar_ion[i], 1 * app->basis.num_basis + ); + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, react->vt_sq_ion[i], 4 * app->basis.num_basis + ); gk_neut_species_lte_from_moms(app, s, &s->lte, react->react_lte_moms[i]); // Accumulate J*n_elc*fmax(n_ion, upar bx, upar by, upar bz, vt_ion^2) onto f_react - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - 1.0, react->Jm0_elc[i], s->lte.f_lte, &app->local, &s->local); - } - else if (react->react_id[i] == GKYL_REACT_CX) { + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, 1.0, react->Jm0_elc[i], s->lte.f_lte, &app->local, + &s->local + ); + } else if (react->react_id[i] == GKYL_REACT_CX) { // neutral update is coeff_react*(n_partner*fmax(n_ion, upar bx, upar by, upar bz, vt_ion^2) - n_ion*f_partner) - // Copy components of partner ions into reaction moments - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, gks_ion->lte.moms.marr, 0*app->basis.num_basis); + // Copy components of partner ions into reaction moments + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, gks_ion->lte.moms.marr, 0 * app->basis.num_basis + ); // Overwrite flow velocity and vt^2 to be upar b_i (vector) and vt^2 of the ions - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, react->upar_ion[i], 1*app->basis.num_basis); - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, react->vt_sq_ion[i], 4*app->basis.num_basis); + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, react->upar_ion[i], 1 * app->basis.num_basis + ); + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, react->vt_sq_ion[i], 4 * app->basis.num_basis + ); gk_neut_species_lte_from_moms(app, s, &s->lte, react->react_lte_moms[i]); // Accumulate J*n_partner*fmax(n_ion, upar bx, upar by, upar bz, vt_ion^2) onto f_react - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - 1.0, react->Jm0_partner[i], s->lte.f_lte, &app->local, &s->local); + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, 1.0, react->Jm0_partner[i], s->lte.f_lte, + &app->local, &s->local + ); // Accumulate -n_ion*(J*f_partner) (*note* Jacobian factor already included in fin) - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - -1.0, gks_ion->lte.moms.marr, fin, &app->local, &s->local); + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, -1.0, gks_ion->lte.moms.marr, fin, &app->local, + &s->local + ); } - // Accumulate reaction update to rhs - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, rhs, - 1.0, react->coeff_react[i], react->f_react, &app->local, &s->local); + // Accumulate reaction update to rhs + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, rhs, 1.0, react->coeff_react[i], react->f_react, &app->local, + &s->local + ); } app->stat.neut_species_react_tm += gkyl_time_diff_now_sec(wst); } -static void -gkns_react_write_disabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, struct gk_react *gkr, - int ridx, double tm, int frame) +static void gkns_react_write_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_react *gkr, int ridx, + double tm, int frame +) { // Do nothing. } -void -gkns_react_write_enabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, struct gk_react *gkr, - int ridx, double tm, int frame) +void gkns_react_write_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_react *gkr, int ridx, + double tm, int frame +) { // React diagnostics usually written from gk_species. // In the case of static gk_species, write_diagnostics flag @@ -190,15 +231,15 @@ gkns_react_write_enabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns // Compute reaction rate const struct gkyl_array *fin[app->num_species]; const struct gkyl_array *fin_neut[app->num_neut_species]; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { fin[i] = app->species[i].f; } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { fin_neut[i] = app->neut_species[i].f; } gk_neut_species_react_cross_moms(app, gkns, gkr, fin, fin_neut); app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); - + struct timespec wtm = gkyl_wall_clock(); // Package metadata. @@ -207,71 +248,90 @@ gkns_react_write_enabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns int io_meta_len[] = {gkns->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; struct gkyl_msgpack_data *mt; - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(gkr->coeff_react_host[ridx], gkr->coeff_react[ridx]); + } if (gkr->react_id[ridx] == GKYL_REACT_IZ) { const char *fmt = "%s-%s_%s_%s_iz_react_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, - gkr->react_type[ridx].elc_nm, gkr->react_type[ridx].ion_nm, frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, - gkr->react_type[ridx].elc_nm, gkr->react_type[ridx].ion_nm, frame); + int sz = gkyl_calc_strlen( + fmt, app->name, gkns->info.name, gkr->react_type[ridx].elc_nm, gkr->react_type[ridx].ion_nm, + frame + ); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, gkr->react_type[ridx].elc_nm, + gkr->react_type[ridx].ion_nm, frame + ); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Ionization reaction rate." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Ionization reaction rate."} + }; + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc }; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, - gkr->coeff_react_host[ridx], fileNm); + mt = gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); + + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, gkr->coeff_react_host[ridx], fileNm + ); } if (gkr->react_id[ridx] == GKYL_REACT_RECOMB) { const char *fmt = "%s-%s_%s_%s_recomb_react_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, - gkr->react_type[ridx].elc_nm, gkr->react_type[ridx].ion_nm, frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, - gkr->react_type[ridx].elc_nm, gkr->react_type[ridx].ion_nm, frame); - + int sz = gkyl_calc_strlen( + fmt, app->name, gkns->info.name, gkr->react_type[ridx].elc_nm, gkr->react_type[ridx].ion_nm, + frame + ); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, gkr->react_type[ridx].elc_nm, + gkr->react_type[ridx].ion_nm, frame + ); + struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Recombination reaction rate." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Recombination reaction rate."} }; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, - gkr->coeff_react_host[ridx], fileNm); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc + }; + mt = gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); + + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, gkr->coeff_react_host[ridx], fileNm + ); } if (gkr->react_id[ridx] == GKYL_REACT_CX) { const char *fmt = "%s-%s_%s_cx_react_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, - gkr->react_type[ridx].ion_nm, frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, - gkr->react_type[ridx].ion_nm, frame); - + int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, gkr->react_type[ridx].ion_nm, frame); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, gkr->react_type[ridx].ion_nm, frame + ); + struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Charge exchange reaction rate." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Charge exchange reaction rate."} + }; + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc }; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, - gkr->coeff_react_host[ridx], fileNm); + mt = gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); + + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, gkr->coeff_react_host[ridx], fileNm + ); } app->stat.n_neut_diag_io += 1; - - gkyl_msgpack_data_release(mt); + + gkyl_msgpack_data_release(mt); app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wtm); } -void -gk_neut_species_react_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gkyl_gyrokinetic_react inp, struct gk_react *react) +void gk_neut_species_react_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gkyl_gyrokinetic_react inp, + struct gk_react *react +) { - react->num_react = inp.num_react; + react->num_react = inp.num_react; react->write_diagnostics = inp.write_diagnostics; react->cross_moms_func_neut = gkns_react_cross_moms_disabled; @@ -280,19 +340,20 @@ gk_neut_species_react_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_spec if (react->num_react) { // Initialize information about reactions from input struct. - for (int i=0; inum_react; ++i) + for (int i = 0; i < react->num_react; ++i) { react->react_type[i] = inp.react_type[i]; + } // Methods chosen at runtime: react->cross_moms_func_neut = gkns_react_cross_moms_enabled; react->rhs_func_neut = gkns_react_rhs_enabled; - if (react->write_diagnostics) + if (react->write_diagnostics) { react->write_func_neut = gkns_react_write_enabled; + } } } -static double -gk_species_react_get_vt_sq_min(struct gkyl_gyrokinetic_app *app, struct gk_species *s) +static double gk_species_react_get_vt_sq_min(struct gkyl_gyrokinetic_app *app, struct gk_species *s) { double bmag_mid = app->bmag_ref; @@ -300,9 +361,9 @@ gk_species_react_get_vt_sq_min(struct gkyl_gyrokinetic_app *app, struct gk_speci double dv_min[vdim]; gkyl_velocity_map_reduce_dv_range(s->vel_map, GKYL_MIN, dv_min, s->vel_map->local_vel); - double tpar_min = (s->info.mass/6.0)*pow(dv_min[0],2); - double tperp_min = vdim>1 ? (bmag_mid/3.0)*dv_min[1] : tpar_min; - return (tpar_min + 2.0*tperp_min)/(3.0*s->info.mass); + double tpar_min = (s->info.mass / 6.0) * pow(dv_min[0], 2); + double tperp_min = vdim > 1 ? (bmag_mid / 3.0) * dv_min[1] : tpar_min; + return (tpar_min + 2.0 * tperp_min) / (3.0 * s->info.mass); } static double @@ -315,13 +376,15 @@ gk_neut_species_react_get_vt_sq_min(struct gkyl_gyrokinetic_app *app, struct gk_ gkyl_velocity_map_reduce_dv_range(s->vel_map, GKYL_MIN, dv_min, s->vel_map->local_vel); double t_min = 0.0; - for (int i=0; iinfo.mass/6.0)*pow(dv_min[0],2); - return t_min/(3.0*s->info.mass); + for (int i = 0; i < vdim; i++) { + t_min += (s->info.mass / 6.0) * pow(dv_min[0], 2); + } + return t_min / (3.0 * s->info.mass); } -void -gk_neut_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_react *react) +void gk_neut_species_react_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_react *react +) { if (react->num_react) { // Distribution function which holds update for each reaction @@ -329,7 +392,7 @@ gk_neut_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_neu // react->f_react = n_elc*coeff_react*fmax(n_ion, upar_ion b_i, vt_ion^2) react->f_react = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); - for (int i=0; inum_react; ++i) { + for (int i = 0; i < react->num_react; ++i) { react->react_id[i] = react->react_type[i].react_id; react->type_self[i] = react->react_type[i].type_self; // Fetch pointers to species objects @@ -340,20 +403,21 @@ gk_neut_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_neu react->ion_idx[i] = gk_find_species_idx(app, react->react_type[i].ion_nm); // Compute a minimum representable temperature based on the smallest dv in the grid. - double ion_vt_sq_min = gk_species_react_get_vt_sq_min(app, &app->species[react->ion_idx[i]]); - double neut_vt_sq_min; + double ion_vt_sq_min = gk_species_react_get_vt_sq_min(app, &app->species[react->ion_idx[i]]); + double neut_vt_sq_min; if (gk_find_neut_species(app, react->react_type[i].donor_nm)) { react->donor_idx[i] = gk_find_neut_species_idx(app, react->react_type[i].donor_nm); - } - else if (gk_find_neut_species(app, react->react_type[i].partner_nm)) { + } else if (gk_find_neut_species(app, react->react_type[i].partner_nm)) { react->partner_idx[i] = gk_find_neut_species_idx(app, react->react_type[i].partner_nm); - neut_vt_sq_min = gk_neut_species_react_get_vt_sq_min(app, &app->neut_species[react->partner_idx[i]]); + neut_vt_sq_min = + gk_neut_species_react_get_vt_sq_min(app, &app->neut_species[react->partner_idx[i]]); } react->coeff_react[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); // Reaction LTE moments needed for projecting LTE distribution functions - react->react_lte_moms[i] = mkarr(app->use_gpu, 5*app->basis.num_basis, app->local_ext.volume); + react->react_lte_moms[i] = + mkarr(app->use_gpu, 5 * app->basis.num_basis, app->local_ext.volume); react->vt_sq_iz1[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); react->vt_sq_iz2[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); @@ -365,82 +429,85 @@ gk_neut_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_neu react->Jm0_partner[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); // Ion flow velocity (upar b_i), ion vt^2 for projecting LTE distribution functions - react->upar_ion[i] = mkarr(app->use_gpu, 3*app->basis.num_basis, app->local_ext.volume); + react->upar_ion[i] = mkarr(app->use_gpu, 3 * app->basis.num_basis, app->local_ext.volume); react->vt_sq_ion[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); if (react->react_id[i] == GKYL_REACT_IZ) { struct gkyl_dg_iz_inp iz_inp = { - .cbasis = &app->basis, - .conf_rng = &app->local, - .type_ion = react->react_type[i].ion_id, - .charge_state = react->react_type[i].charge_state, - .type_self = react->type_self[i], + .cbasis = &app->basis, + .conf_rng = &app->local, + .type_ion = react->react_type[i].ion_id, + .charge_state = react->react_type[i].charge_state, + .type_self = react->type_self[i] }; - react->iz[i] = gkyl_dg_iz_new(&iz_inp, app->use_gpu); - } - else if (react->react_id[i] == GKYL_REACT_RECOMB) { + react->iz[i] = gkyl_dg_iz_new(&iz_inp, app->use_gpu); + } else if (react->react_id[i] == GKYL_REACT_RECOMB) { struct gkyl_dg_recomb_inp recomb_inp = { .grid = &s->grid, - .cbasis = &app->basis, - .pbasis = &s->basis, - .conf_rng = &app->local, + .cbasis = &app->basis, + .pbasis = &s->basis, + .conf_rng = &app->local, .conf_rng_ext = &app->local_ext, - .phase_rng = &s->local, - .mass_self = s->info.mass, - .type_ion = react->react_type[i].ion_id, - .charge_state = react->react_type[i].charge_state, - .type_self = react->type_self[i], + .phase_rng = &s->local, + .mass_self = s->info.mass, + .type_ion = react->react_type[i].ion_id, + .charge_state = react->react_type[i].charge_state, + .type_self = react->type_self[i] }; - react->recomb[i] = gkyl_dg_recomb_new(&recomb_inp, app->use_gpu); - } - else if (react->react_id[i] == GKYL_REACT_CX) { + react->recomb[i] = gkyl_dg_recomb_new(&recomb_inp, app->use_gpu); + } else if (react->react_id[i] == GKYL_REACT_CX) { struct gk_species *gks = &app->species[react->ion_idx[i]]; struct gkyl_dg_cx_inp cx_inp = { .cbasis = &app->basis, .conf_rng = &app->local, - .vt_sq_ion_min = ion_vt_sq_min, - .vt_sq_neut_min = neut_vt_sq_min, - .type_ion = react->react_type[i].ion_id, + .vt_sq_ion_min = ion_vt_sq_min, + .vt_sq_neut_min = neut_vt_sq_min, + .type_ion = react->react_type[i].ion_id }; react->cx[i] = gkyl_dg_cx_new(&cx_inp, app->use_gpu); } if (react->write_diagnostics) { - react->coeff_react_host[i] = app->use_gpu? mkarr(false, react->coeff_react[i]->ncomp, react->coeff_react[i]->size) - : gkyl_array_acquire(react->coeff_react[i]); + react->coeff_react_host[i] = + app->use_gpu ? mkarr(false, react->coeff_react[i]->ncomp, react->coeff_react[i]->size) : + gkyl_array_acquire(react->coeff_react[i]); } } } } -void -gk_neut_species_react_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_react *react, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +void gk_neut_species_react_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_react *react, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { react->cross_moms_func_neut(app, species, react, fin, fin_neut); } -void -gk_neut_species_react_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_react *react, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_neut_species_react_rhs( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_react *react, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { react->rhs_func_neut(app, s, react, fin, rhs); } -void -gk_neut_species_react_write(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, struct gk_react *gkr, - int ridx, double tm, int frame) +void gk_neut_species_react_write( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_react *gkr, int ridx, + double tm, int frame +) { gkr->write_func_neut(app, gkns, gkr, ridx, tm, frame); } -void -gk_neut_species_react_release(const struct gkyl_gyrokinetic_app *app, const struct gk_react *react) +void gk_neut_species_react_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_react *react +) { if (react->num_react) { gkyl_array_release(react->f_react); - for (int i=0; inum_react; ++i) { + for (int i = 0; i < react->num_react; ++i) { gkyl_array_release(react->coeff_react[i]); if (react->write_diagnostics) { gkyl_array_release(react->coeff_react_host[i]); @@ -450,17 +517,15 @@ gk_neut_species_react_release(const struct gkyl_gyrokinetic_app *app, const stru gkyl_array_release(react->vt_sq_iz2[i]); gkyl_array_release(react->Jm0_elc[i]); gkyl_array_release(react->Jm0_partner[i]); - gkyl_array_release(react->upar_ion[i]); + gkyl_array_release(react->upar_ion[i]); gkyl_array_release(react->vt_sq_ion[i]); gkyl_array_release(react->u_i_dot_b_i[i]); if (react->react_id[i] == GKYL_REACT_IZ) { gkyl_dg_iz_release(react->iz[i]); - } - else if (react->react_id[i] == GKYL_REACT_RECOMB) { + } else if (react->react_id[i] == GKYL_REACT_RECOMB) { gkyl_dg_recomb_release(react->recomb[i]); - } - else if (react->react_id[i] == GKYL_REACT_CX) { + } else if (react->react_id[i] == GKYL_REACT_CX) { gkyl_dg_cx_release(react->cx[i]); } } diff --git a/gyrokinetic/apps/gk_neut_species_recycle.c b/gyrokinetic/apps/gk_neut_species_recycle.c index 553715be72..084b2d8acc 100644 --- a/gyrokinetic/apps/gk_neut_species_recycle.c +++ b/gyrokinetic/apps/gk_neut_species_recycle.c @@ -1,370 +1,445 @@ -#include -#include -#include - -static void -gk_neut_species_recycle_write_flux_enabled(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_recycle_wall *recyc, double tm, int frame) -{ - // Output boundary flux from ions and neutral ghost cells - - // Package metadata. - gkyl_msgpack_map_elem_set_double(s->io_meta_conf_len, s->io_meta_conf, "time", tm); - gkyl_msgpack_map_elem_set_uint(s->io_meta_conf_len, s->io_meta_conf, "frame", frame); - int io_meta_len[] = {s->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - - const char *vars[] = {"x","y","z"}; - const char *edge[] = {"lower","upper"}; - - int dir = recyc->dir; - int edi = recyc->edge == GKYL_LOWER_EDGE? 0 : 1; - - struct gkyl_range *cskin_r = edi ==0 ? &app->local_lower_skin[recyc->dir] : &app->local_upper_skin[recyc->dir]; - - for (int i=0; inum_species; ++i) { - struct timespec wst = gkyl_wall_clock(); - // Write out the particle flux of the impacting species. - struct gk_species *gks = recyc->impact_species[i]; - - gk_species_bflux_get_flux(&gks->bflux, recyc->dir, recyc->edge, recyc->phase_flux_gk[i], &recyc->impact_buff_r[i]); - gkyl_dg_updater_moment_gyrokinetic_advance(recyc->m0op_gk[i], &recyc->impact_normal_r[i], - &recyc->impact_cbuff_r[i], recyc->phase_flux_gk[i], recyc->m0_flux_gk[i]); - app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); - - struct timespec wtm = gkyl_wall_clock(); - // Copy to skin to write it out. - gkyl_array_clear(recyc->diag_out, 0.0); - gkyl_array_copy_range_to_range(recyc->diag_out, recyc->m0_flux_gk[i], cskin_r, &recyc->impact_cbuff_r[i]); - - if (app->use_gpu) - gkyl_array_copy(recyc->diag_out_ho, recyc->diag_out); - - struct gkyl_msgpack_map_elem desc0[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Impacting boundary particle flux." } - }; - const struct gkyl_msgpack_map_elem* io_meta[] = {s->io_meta_conf, app->gk_geom->io_meta_basic, desc0}; - struct gkyl_msgpack_data *mt0 = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); - - const char *fmt = "%s-%s_recycling_%s%s_%s_flux_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, vars[dir], edge[edi], gks->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, vars[dir], edge[edi], gks->info.name, frame); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt0, recyc->diag_out_ho, fileNm); - app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); - - gkyl_msgpack_data_release(mt0); - } - - struct timespec wst = gkyl_wall_clock(); - // Write out the particle flux of the emitting neutral species. - gkyl_array_clear(recyc->f_diag, 0.0); - gkyl_array_copy_range_to_range(recyc->f_diag, recyc->f_emit, recyc->emit_skin_r, &recyc->emit_buff_r); - gkyl_boundary_flux_advance(recyc->f0_flux_slvr, recyc->f_diag, recyc->f_diag); - gkyl_array_copy_range_to_range(recyc->unit_phase_flux_neut, recyc->f_diag, &recyc->emit_buff_r, recyc->emit_ghost_r); - gkyl_dg_updater_moment_advance(recyc->m0op_neut, &recyc->emit_normal_r, &recyc->emit_cbuff_r, - recyc->unit_phase_flux_neut, recyc->emit_flux); - app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); - - struct timespec wtm = gkyl_wall_clock(); - // Copy to skin to write it out. - gkyl_array_clear(recyc->diag_out, 0.0); - gkyl_array_copy_range_to_range(recyc->diag_out, recyc->emit_flux, cskin_r, &recyc->emit_cbuff_r); - if (app->use_gpu) - gkyl_array_copy(recyc->diag_out_ho, recyc->diag_out); - - struct gkyl_msgpack_map_elem desc1[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Emitted boundary particle flux." } - }; - const struct gkyl_msgpack_map_elem* io_meta[] = {s->io_meta_conf, app->gk_geom->io_meta_basic, desc1}; - struct gkyl_msgpack_data *mt1 = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); - - const char *fmt = "%s-%s_recycling_%s%s_%s_flux_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, s->info.name, vars[dir], edge[edi], s->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, s->info.name, vars[dir], edge[edi], s->info.name, frame); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt1, recyc->diag_out_ho, fileNm); - app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wtm); - app->stat.n_diag_io += 1; - - gkyl_msgpack_data_release(mt1); -} - -static void -gk_neut_species_recycle_write_flux_disabled(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_recycle_wall *recyc, double tm, int frame) -{ -} - -void -gk_neut_species_recycle_write_flux(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_recycle_wall *recyc, double tm, int frame) -{ - recyc->write_flux_func(app, s, recyc, tm, frame); -} - -struct gk_neut_recycling_maxwellian_params { - double temp; // Temperature of the neutral species emitted during recycling. -}; - -static void -gk_neut_recycling_maxwellian_den(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) -{ - fout[0] = 1.0; -} - -static void -gk_neut_recycling_maxwellian_udrift(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) -{ - fout[0] = 0.0; - fout[1] = 0.0; - fout[2] = 0.0; -} - -static void -gk_neut_recycling_maxwellian_temp(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) -{ - struct gk_neut_recycling_maxwellian_params *params = ctx; - fout[0] = params->temp; -} - -void -gk_neut_species_recycle_init(struct gkyl_gyrokinetic_app *app, struct gk_recycle_wall *recyc, - int dir, enum gkyl_edge_loc edge, struct gkyl_gyrokinetic_emission_inp *params, - struct gk_neut_species *s, bool use_gpu) -{ - recyc->params = params; - recyc->num_species = params->num_species; - recyc->edge = edge; - recyc->dir = dir; - recyc->write_diagnostics = edge == GKYL_LOWER_EDGE? s->lower_bc[dir].write_diagnostics : s->upper_bc[dir].write_diagnostics; - - int cdim = app->cdim; - int ndim = app->cdim + s->info.vdim; - - int e = recyc->edge == GKYL_LOWER_EDGE? 0 : 1; - - // Create boundary grids and ranges. - int cells[GKYL_MAX_DIM]; - double lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - for (int i=0; igrid.cells[i]; - lower[i] = s->grid.lower[i]; - upper[i] = s->grid.upper[i]; - } - cells[dir] = 1; - lower[dir] = e==0? s->grid.lower[dir] - s->grid.dx[dir] : s->grid.upper[dir]; - upper[dir] = e==0? s->grid.lower[dir] : s->grid.upper[dir] + s->grid.dx[dir]; - gkyl_rect_grid_init(&recyc->emit_grid, ndim, lower, upper, cells); - - recyc->emit_ghost_r = e==0? &s->local_lower_ghost[dir] : &s->local_upper_ghost[dir]; - recyc->emit_skin_r = e==0? &s->local_lower_skin[dir] : &s->local_upper_skin[dir]; - gkyl_range_init(&recyc->emit_buff_r, ndim, recyc->emit_ghost_r->lower, recyc->emit_ghost_r->upper); - gkyl_range_init(&recyc->emit_cbuff_r, cdim, recyc->emit_ghost_r->lower, recyc->emit_ghost_r->upper); - - // Buffer for scaled Maxwellian in ghost. - recyc->bc_buffer = mkarr(app->use_gpu, s->basis.num_basis, recyc->emit_skin_r->volume); - // Initialize fixed func bc object to project the unit Maxwellian in ghost - struct gkyl_bc_basic *bc_basic_op = gkyl_bc_basic_new(dir, edge, GKYL_BC_FIXED_FUNC, s->basis_on_dev, - recyc->emit_skin_r, recyc->emit_ghost_r, s->f->ncomp, app->cdim, app->use_gpu); - // Project unit Maxwellian. - struct gk_neut_recycling_maxwellian_params neut_max_pars = { - .temp = e==0? s->lower_bc[dir].emission.emission_temp : s->upper_bc[dir].emission.emission_temp, - }; - struct gkyl_gyrokinetic_projection recyc_proj_inp = { - .proj_id = GKYL_PROJ_MAXWELLIAN_PRIM, - .ctx_density = &neut_max_pars, - .density = gk_neut_recycling_maxwellian_den, - .ctx_upar = &neut_max_pars, - .udrift = gk_neut_recycling_maxwellian_udrift, - .ctx_temp = &neut_max_pars, - .temp = gk_neut_recycling_maxwellian_temp, - }; - struct gk_proj proj_unit_maxwellian; - gk_neut_species_projection_init(app, s, recyc_proj_inp, &proj_unit_maxwellian); - gk_neut_species_projection_calc(app, s, &proj_unit_maxwellian, s->f1, 0.0); // Temporarily use f1. - - // Calculate flux associated with unit Maxwellian projected in f0. - int num_eqns = 0; - if (s->collisionless.collisionless_id == GKYL_GK_COLLISIONLESS_NEUTRAL) - num_eqns += 1; // Collisionless terms. - - const struct gkyl_dg_eqn **eqns = gkyl_malloc(num_eqns*sizeof(struct gkyl_dg_eqn *)); - - int eqc = 0; - if (s->collisionless.collisionless_id == GKYL_GK_COLLISIONLESS_NEUTRAL) - eqns[eqc++] = gkyl_dg_updater_vlasov_acquire_eqn(s->collisionless.vlasov_slvr); - - recyc->f0_flux_slvr = gkyl_boundary_flux_new(recyc->dir, recyc->edge, &s->grid, - recyc->emit_skin_r, recyc->emit_ghost_r, num_eqns, eqns, app->use_gpu); - - for (int i=0; if0_flux_slvr, s->f1, s->f1); - recyc->unit_phase_flux_neut = mkarr(app->use_gpu, s->basis.num_basis, recyc->emit_buff_r.volume); - gkyl_array_copy_range_to_range(recyc->unit_phase_flux_neut, s->f1, &recyc->emit_buff_r, - recyc->emit_ghost_r); - - recyc->write_flux_func = gk_neut_species_recycle_write_flux_disabled; - if (recyc->write_diagnostics) { - recyc->write_flux_func = gk_neut_species_recycle_write_flux_enabled; - } - - gkyl_bc_basic_buffer_fixed_func(bc_basic_op, recyc->bc_buffer, s->f1); - gkyl_array_clear(s->f1, 0.0); - - gkyl_bc_basic_release(bc_basic_op); - gk_neut_species_projection_release(app, &proj_unit_maxwellian); -} - -void -gk_neut_species_recycle_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_recycle_wall *recyc) -{ - int cdim = app->cdim; - int vdim = s->info.vdim; - - // Define necessary grid, ranges, and array for calculating the desired Maxwellian for ghost. - recyc->f_emit = mkarr(app->use_gpu, s->basis.num_basis, recyc->emit_buff_r.volume); - - int ghost[GKYL_MAX_DIM]; // Number of ghost cells in each direction. - for (int d=0; demit_normal_r, recyc->dir + cdim, &recyc->emit_buff_r, - ghost, recyc->edge); - - recyc->unit_m0_flux_neut = mkarr(app->use_gpu, app->basis.num_basis, recyc->emit_cbuff_r.volume); - - struct gkyl_mom_canonical_pb_auxfields can_pb_inp = {.hamil = s->hamil}; - recyc->m0op_neut = gkyl_dg_updater_moment_new(&recyc->emit_grid, &app->basis, - &s->basis, &recyc->emit_cbuff_r, &s->local_vel, &recyc->emit_buff_r, s->model_id, - &can_pb_inp, GKYL_F_MOMENT_M0, false, app->use_gpu); - - gkyl_dg_updater_moment_advance(recyc->m0op_neut, &recyc->emit_normal_r, - &recyc->emit_cbuff_r, recyc->unit_phase_flux_neut, recyc->unit_m0_flux_neut); - - // Define memory for div bin op for calculating correct scaling factor. - if (app->use_gpu) - recyc->mem_geo = gkyl_dg_bin_op_mem_cu_dev_new(recyc->emit_cbuff_r.volume, app->basis.num_basis); - else - recyc->mem_geo = gkyl_dg_bin_op_mem_new(recyc->emit_cbuff_r.volume, app->basis.num_basis); - - for (int i=0; inum_species; ++i) { - recyc->impact_species[i] = gk_find_species(app, recyc->params->in_species[i]); - struct gk_species *gks = recyc->impact_species[i]; - - int e = recyc->edge == GKYL_LOWER_EDGE? 0 : 1; - - // Create boundary grids and ranges for impacting species. - int cells[GKYL_MAX_DIM]; - double lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - for (int i=0; iinfo.vdim; ++i) { - cells[i] = gks->grid.cells[i]; - lower[i] = gks->grid.lower[i]; - upper[i] = gks->grid.upper[i]; - } - cells[recyc->dir] = 1; - lower[recyc->dir] = e==0? gks->grid.lower[recyc->dir] - gks->grid.dx[recyc->dir] : gks->grid.upper[recyc->dir]; - upper[recyc->dir] = e==0? gks->grid.lower[recyc->dir] : gks->grid.upper[recyc->dir] + gks->grid.dx[recyc->dir]; - gkyl_rect_grid_init(&recyc->impact_grid[i], cdim+gks->info.vdim, lower, upper, cells); - - struct gkyl_range *phase_skin_r = e==0? &gks->local_lower_skin[recyc->dir] : &gks->local_upper_skin[recyc->dir]; - struct gkyl_range *phase_ghost_r = e==0? &gks->local_lower_ghost[recyc->dir] : &gks->local_upper_ghost[recyc->dir]; - recyc->impact_ghost_r[i] = phase_ghost_r; - gkyl_range_init(&recyc->impact_buff_r[i], cdim+gks->info.vdim, phase_ghost_r->lower, phase_ghost_r->upper); - gkyl_range_init(&recyc->impact_cbuff_r[i], cdim, phase_ghost_r->lower, phase_ghost_r->upper); - - recyc->phase_flux_gk[i] = mkarr(app->use_gpu, gks->basis.num_basis, phase_ghost_r->volume); - recyc->m0_flux_gk[i] = mkarr(app->use_gpu, app->basis.num_basis, recyc->impact_cbuff_r[i].volume); - - recyc->spectrum[i] = mkarr(app->use_gpu, s->basis.num_basis, recyc->emit_buff_r.volume); - - recyc->m0op_gk[i] = gkyl_dg_updater_moment_gyrokinetic_new(&recyc->impact_grid[i], &app->basis, - &gks->basis, &recyc->emit_cbuff_r, gks->info.mass, gks->info.charge, gks->vel_map, - app->gk_geom, 0, GKYL_F_MOMENT_M0, false, app->use_gpu); - - // Create a phase-space range that only includes velocities towards the boundary. - gkyl_bc_emission_flux_ranges(&recyc->impact_normal_r[i], recyc->dir + cdim, &recyc->impact_buff_r[i], - ghost, recyc->edge); - } - - // For writing diagnostics, if needed. - if (recyc->write_diagnostics) { - recyc->f_diag = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); - recyc->emit_flux = mkarr(app->use_gpu, app->basis.num_basis, recyc->emit_cbuff_r.volume); - recyc->diag_out = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - recyc->diag_out_ho = recyc->diag_out; - if (app->use_gpu) - recyc->diag_out_ho = mkarr(false, app->basis.num_basis, app->local_ext.volume); - } - -} - -void -gk_neut_species_recycle_apply_bc(struct gkyl_gyrokinetic_app *app, const struct gk_recycle_wall *recyc, - const struct gk_neut_species *s, struct gkyl_array *fout) -{ - gkyl_array_clear(recyc->f_emit, 0.0); // Zero emitted distribution before beginning accumulate - - // Inelastic emission contribution. - // This relies on the calculation of the ion flux (phase_flux_gk). - // from gk_species_bflux_rhs_solver. - for (int i=0; inum_species; ++i) { - // Copy unit-density Maxwellian from buffer. - gkyl_array_set(recyc->spectrum[i], recyc->params->recycling_frac, recyc->bc_buffer); - - struct gk_species *gks = recyc->impact_species[i]; - - // Calculate M0 moment of ion flux. - gk_species_bflux_get_flux(&gks->bflux, recyc->dir, recyc->edge, recyc->phase_flux_gk[i], &recyc->impact_buff_r[i]); - gkyl_dg_updater_moment_gyrokinetic_advance(recyc->m0op_gk[i], &recyc->impact_normal_r[i], - &recyc->impact_cbuff_r[i], recyc->phase_flux_gk[i], recyc->m0_flux_gk[i]); - - // Calculate scaling factor from ratio of ion flux to unit-density flux. - gkyl_dg_div_op_range(recyc->mem_geo, &app->basis, 0, recyc->m0_flux_gk[i], 0, recyc->m0_flux_gk[i], - 0, recyc->unit_m0_flux_neut, &recyc->emit_cbuff_r); - - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, recyc->f_emit, 1.0, - recyc->m0_flux_gk[i], recyc->spectrum[i], &recyc->impact_cbuff_r[i], &recyc->emit_buff_r); - } - - gkyl_array_set_range_to_range(fout, 1.0, recyc->f_emit, recyc->emit_ghost_r, - &recyc->emit_buff_r); -} - -void -gk_neut_species_recycle_release(const struct gkyl_gyrokinetic_app *app, const struct gk_recycle_wall *recyc) -{ - gkyl_boundary_flux_release(recyc->f0_flux_slvr); - gkyl_array_release(recyc->unit_phase_flux_neut); - gkyl_array_release(recyc->f_emit); - - if (recyc->write_diagnostics) { - gkyl_array_release(recyc->f_diag); - gkyl_array_release(recyc->emit_flux); - gkyl_array_release(recyc->diag_out); - if (app->use_gpu) - gkyl_array_release(recyc->diag_out_ho); - } - - gkyl_array_release(recyc->unit_m0_flux_neut); - gkyl_dg_updater_moment_release(recyc->m0op_neut); - gkyl_dg_bin_op_mem_release(recyc->mem_geo); - - for (int i=0; inum_species; ++i) { - gkyl_array_release(recyc->phase_flux_gk[i]); - gkyl_array_release(recyc->m0_flux_gk[i]); - gkyl_array_release(recyc->spectrum[i]); - gkyl_dg_updater_moment_gyrokinetic_release(recyc->m0op_gk[i]); - } - - gkyl_array_release(recyc->bc_buffer); -} +#include +#include +#include + +static void gk_neut_species_recycle_write_flux_enabled( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_recycle_wall *recyc, + double tm, int frame +) +{ + // Output boundary flux from ions and neutral ghost cells + + // Package metadata. + gkyl_msgpack_map_elem_set_double(s->io_meta_conf_len, s->io_meta_conf, "time", tm); + gkyl_msgpack_map_elem_set_uint(s->io_meta_conf_len, s->io_meta_conf, "frame", frame); + int io_meta_len[] = {s->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; + + const char *vars[] = {"x", "y", "z"}; + const char *edge[] = {"lower", "upper"}; + + int dir = recyc->dir; + int edi = recyc->edge == GKYL_LOWER_EDGE ? 0 : 1; + + struct gkyl_range *cskin_r = edi == 0 ? &app->local_lower_skin[recyc->dir] : + &app->local_upper_skin[recyc->dir]; + + for (int i = 0; i < recyc->num_species; ++i) { + struct timespec wst = gkyl_wall_clock(); + // Write out the particle flux of the impacting species. + struct gk_species *gks = recyc->impact_species[i]; + + gk_species_bflux_get_flux( + &gks->bflux, recyc->dir, recyc->edge, recyc->phase_flux_gk[i], &recyc->impact_buff_r[i] + ); + gkyl_dg_updater_moment_gyrokinetic_advance( + recyc->m0op_gk[i], &recyc->impact_normal_r[i], &recyc->impact_cbuff_r[i], + recyc->phase_flux_gk[i], recyc->m0_flux_gk[i] + ); + app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); + + struct timespec wtm = gkyl_wall_clock(); + // Copy to skin to write it out. + gkyl_array_clear(recyc->diag_out, 0.0); + gkyl_array_copy_range_to_range( + recyc->diag_out, recyc->m0_flux_gk[i], cskin_r, &recyc->impact_cbuff_r[i] + ); + + if (app->use_gpu) { + gkyl_array_copy(recyc->diag_out_ho, recyc->diag_out); + } + + struct gkyl_msgpack_map_elem desc0[] = { + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Impacting boundary particle flux."} + }; + const struct gkyl_msgpack_map_elem *io_meta[] = { + s->io_meta_conf, app->gk_geom->io_meta_basic, desc0 + }; + struct gkyl_msgpack_data *mt0 = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); + + const char *fmt = "%s-%s_recycling_%s%s_%s_flux_%d.gkyl"; + int sz = + gkyl_calc_strlen(fmt, app->name, gks->info.name, vars[dir], edge[edi], gks->info.name, frame); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gks->info.name, vars[dir], edge[edi], gks->info.name, + frame + ); + + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt0, recyc->diag_out_ho, fileNm); + app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); + + gkyl_msgpack_data_release(mt0); + } + + struct timespec wst = gkyl_wall_clock(); + // Write out the particle flux of the emitting neutral species. + gkyl_array_clear(recyc->f_diag, 0.0); + gkyl_array_copy_range_to_range( + recyc->f_diag, recyc->f_emit, recyc->emit_skin_r, &recyc->emit_buff_r + ); + gkyl_boundary_flux_advance(recyc->f0_flux_slvr, recyc->f_diag, recyc->f_diag); + gkyl_array_copy_range_to_range( + recyc->unit_phase_flux_neut, recyc->f_diag, &recyc->emit_buff_r, recyc->emit_ghost_r + ); + gkyl_dg_updater_moment_advance( + recyc->m0op_neut, &recyc->emit_normal_r, &recyc->emit_cbuff_r, recyc->unit_phase_flux_neut, + recyc->emit_flux + ); + app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); + + struct timespec wtm = gkyl_wall_clock(); + // Copy to skin to write it out. + gkyl_array_clear(recyc->diag_out, 0.0); + gkyl_array_copy_range_to_range(recyc->diag_out, recyc->emit_flux, cskin_r, &recyc->emit_cbuff_r); + if (app->use_gpu) { + gkyl_array_copy(recyc->diag_out_ho, recyc->diag_out); + } + + struct gkyl_msgpack_map_elem desc1[] = { + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Emitted boundary particle flux."} + }; + const struct gkyl_msgpack_map_elem *io_meta[] = { + s->io_meta_conf, app->gk_geom->io_meta_basic, desc1 + }; + struct gkyl_msgpack_data *mt1 = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); + + const char *fmt = "%s-%s_recycling_%s%s_%s_flux_%d.gkyl"; + int sz = + gkyl_calc_strlen(fmt, app->name, s->info.name, vars[dir], edge[edi], s->info.name, frame); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, s->info.name, vars[dir], edge[edi], s->info.name, frame + ); + + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt1, recyc->diag_out_ho, fileNm); + app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wtm); + app->stat.n_diag_io += 1; + + gkyl_msgpack_data_release(mt1); +} + +static void gk_neut_species_recycle_write_flux_disabled( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_recycle_wall *recyc, + double tm, int frame +) +{ +} + +void gk_neut_species_recycle_write_flux( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_recycle_wall *recyc, + double tm, int frame +) +{ + recyc->write_flux_func(app, s, recyc, tm, frame); +} + +struct gk_neut_recycling_maxwellian_params { + double temp; // Temperature of the neutral species emitted during recycling. +}; + +static void gk_neut_recycling_maxwellian_den( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) +{ + fout[0] = 1.0; +} + +static void gk_neut_recycling_maxwellian_udrift( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) +{ + fout[0] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; +} + +static void gk_neut_recycling_maxwellian_temp( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) +{ + struct gk_neut_recycling_maxwellian_params *params = ctx; + fout[0] = params->temp; +} + +void gk_neut_species_recycle_init( + struct gkyl_gyrokinetic_app *app, struct gk_recycle_wall *recyc, int dir, enum gkyl_edge_loc edge, + struct gkyl_gyrokinetic_emission_inp *params, struct gk_neut_species *s, bool use_gpu +) +{ + recyc->params = params; + recyc->num_species = params->num_species; + recyc->edge = edge; + recyc->dir = dir; + recyc->write_diagnostics = edge == GKYL_LOWER_EDGE ? s->lower_bc[dir].write_diagnostics : + s->upper_bc[dir].write_diagnostics; + + int cdim = app->cdim; + int ndim = app->cdim + s->info.vdim; + + int e = recyc->edge == GKYL_LOWER_EDGE ? 0 : 1; + + // Create boundary grids and ranges. + int cells[GKYL_MAX_DIM]; + double lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; + for (int i = 0; i < ndim; ++i) { + cells[i] = s->grid.cells[i]; + lower[i] = s->grid.lower[i]; + upper[i] = s->grid.upper[i]; + } + cells[dir] = 1; + lower[dir] = e == 0 ? s->grid.lower[dir] - s->grid.dx[dir] : s->grid.upper[dir]; + upper[dir] = e == 0 ? s->grid.lower[dir] : s->grid.upper[dir] + s->grid.dx[dir]; + gkyl_rect_grid_init(&recyc->emit_grid, ndim, lower, upper, cells); + + recyc->emit_ghost_r = e == 0 ? &s->local_lower_ghost[dir] : &s->local_upper_ghost[dir]; + recyc->emit_skin_r = e == 0 ? &s->local_lower_skin[dir] : &s->local_upper_skin[dir]; + gkyl_range_init(&recyc->emit_buff_r, ndim, recyc->emit_ghost_r->lower, recyc->emit_ghost_r->upper); + gkyl_range_init( + &recyc->emit_cbuff_r, cdim, recyc->emit_ghost_r->lower, recyc->emit_ghost_r->upper + ); + + // Buffer for scaled Maxwellian in ghost. + recyc->bc_buffer = mkarr(app->use_gpu, s->basis.num_basis, recyc->emit_skin_r->volume); + // Initialize fixed func bc object to project the unit Maxwellian in ghost + struct gkyl_bc_basic *bc_basic_op = gkyl_bc_basic_new( + dir, edge, GKYL_BC_FIXED_FUNC, s->basis_on_dev, recyc->emit_skin_r, recyc->emit_ghost_r, + s->f->ncomp, app->cdim, app->use_gpu + ); + // Project unit Maxwellian. + struct gk_neut_recycling_maxwellian_params neut_max_pars = { + .temp = e == 0 ? s->lower_bc[dir].emission.emission_temp : + s->upper_bc[dir].emission.emission_temp + }; + struct gkyl_gyrokinetic_projection recyc_proj_inp = { + .proj_id = GKYL_PROJ_MAXWELLIAN_PRIM, + .ctx_density = &neut_max_pars, + .density = gk_neut_recycling_maxwellian_den, + .ctx_upar = &neut_max_pars, + .udrift = gk_neut_recycling_maxwellian_udrift, + .ctx_temp = &neut_max_pars, + .temp = gk_neut_recycling_maxwellian_temp + }; + struct gk_proj proj_unit_maxwellian; + gk_neut_species_projection_init(app, s, recyc_proj_inp, &proj_unit_maxwellian); + gk_neut_species_projection_calc(app, s, &proj_unit_maxwellian, s->f1, 0.0); // Temporarily use f1. + + // Calculate flux associated with unit Maxwellian projected in f0. + int num_eqns = 0; + if (s->collisionless.collisionless_id == GKYL_GK_COLLISIONLESS_NEUTRAL) { + num_eqns += 1; // Collisionless terms. + } + + const struct gkyl_dg_eqn **eqns = gkyl_malloc(num_eqns * sizeof(struct gkyl_dg_eqn *)); + + int eqc = 0; + if (s->collisionless.collisionless_id == GKYL_GK_COLLISIONLESS_NEUTRAL) { + eqns[eqc++] = gkyl_dg_updater_vlasov_acquire_eqn(s->collisionless.vlasov_slvr); + } + + recyc->f0_flux_slvr = gkyl_boundary_flux_new( + recyc->dir, recyc->edge, &s->grid, recyc->emit_skin_r, recyc->emit_ghost_r, num_eqns, eqns, + app->use_gpu + ); + + for (int i = 0; i < num_eqns; i++) { + gkyl_dg_eqn_release(eqns[i]); + } + + gkyl_free(eqns); + + gkyl_boundary_flux_advance(recyc->f0_flux_slvr, s->f1, s->f1); + recyc->unit_phase_flux_neut = mkarr(app->use_gpu, s->basis.num_basis, recyc->emit_buff_r.volume); + gkyl_array_copy_range_to_range( + recyc->unit_phase_flux_neut, s->f1, &recyc->emit_buff_r, recyc->emit_ghost_r + ); + + recyc->write_flux_func = gk_neut_species_recycle_write_flux_disabled; + if (recyc->write_diagnostics) { + recyc->write_flux_func = gk_neut_species_recycle_write_flux_enabled; + } + + gkyl_bc_basic_buffer_fixed_func(bc_basic_op, recyc->bc_buffer, s->f1); + gkyl_array_clear(s->f1, 0.0); + + gkyl_bc_basic_release(bc_basic_op); + gk_neut_species_projection_release(app, &proj_unit_maxwellian); +} + +void gk_neut_species_recycle_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_recycle_wall *recyc +) +{ + int cdim = app->cdim; + int vdim = s->info.vdim; + + // Define necessary grid, ranges, and array for calculating the desired Maxwellian for ghost. + recyc->f_emit = mkarr(app->use_gpu, s->basis.num_basis, recyc->emit_buff_r.volume); + + int ghost[GKYL_MAX_DIM]; // Number of ghost cells in each direction. + for (int d = 0; d < cdim; ++d) { + ghost[d] = 1; + } + for (int d = 0; d < vdim; ++d) { + ghost[cdim + d] = 0; + } + + // Calculate the flux associated with unit-density Maxwellian. + gkyl_bc_emission_flux_ranges( + &recyc->emit_normal_r, recyc->dir + cdim, &recyc->emit_buff_r, ghost, recyc->edge + ); + + recyc->unit_m0_flux_neut = mkarr(app->use_gpu, app->basis.num_basis, recyc->emit_cbuff_r.volume); + + struct gkyl_mom_canonical_pb_auxfields can_pb_inp = {.hamil = s->hamil}; + recyc->m0op_neut = gkyl_dg_updater_moment_new( + &recyc->emit_grid, &app->basis, &s->basis, &recyc->emit_cbuff_r, &s->local_vel, + &recyc->emit_buff_r, s->model_id, &can_pb_inp, GKYL_F_MOMENT_M0, false, app->use_gpu + ); + + gkyl_dg_updater_moment_advance( + recyc->m0op_neut, &recyc->emit_normal_r, &recyc->emit_cbuff_r, recyc->unit_phase_flux_neut, + recyc->unit_m0_flux_neut + ); + + // Define memory for div bin op for calculating correct scaling factor. + if (app->use_gpu) { + recyc->mem_geo = + gkyl_dg_bin_op_mem_cu_dev_new(recyc->emit_cbuff_r.volume, app->basis.num_basis); + } else { + recyc->mem_geo = gkyl_dg_bin_op_mem_new(recyc->emit_cbuff_r.volume, app->basis.num_basis); + } + + for (int i = 0; i < recyc->num_species; ++i) { + recyc->impact_species[i] = gk_find_species(app, recyc->params->in_species[i]); + struct gk_species *gks = recyc->impact_species[i]; + + int e = recyc->edge == GKYL_LOWER_EDGE ? 0 : 1; + + // Create boundary grids and ranges for impacting species. + int cells[GKYL_MAX_DIM]; + double lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; + for (int i = 0; i < cdim + gks->info.vdim; ++i) { + cells[i] = gks->grid.cells[i]; + lower[i] = gks->grid.lower[i]; + upper[i] = gks->grid.upper[i]; + } + cells[recyc->dir] = 1; + lower[recyc->dir] = e == 0 ? gks->grid.lower[recyc->dir] - gks->grid.dx[recyc->dir] : + gks->grid.upper[recyc->dir]; + upper[recyc->dir] = e == 0 ? gks->grid.lower[recyc->dir] : + gks->grid.upper[recyc->dir] + gks->grid.dx[recyc->dir]; + gkyl_rect_grid_init(&recyc->impact_grid[i], cdim + gks->info.vdim, lower, upper, cells); + + struct gkyl_range *phase_skin_r = e == 0 ? &gks->local_lower_skin[recyc->dir] : + &gks->local_upper_skin[recyc->dir]; + struct gkyl_range *phase_ghost_r = e == 0 ? &gks->local_lower_ghost[recyc->dir] : + &gks->local_upper_ghost[recyc->dir]; + recyc->impact_ghost_r[i] = phase_ghost_r; + gkyl_range_init( + &recyc->impact_buff_r[i], cdim + gks->info.vdim, phase_ghost_r->lower, phase_ghost_r->upper + ); + gkyl_range_init(&recyc->impact_cbuff_r[i], cdim, phase_ghost_r->lower, phase_ghost_r->upper); + + recyc->phase_flux_gk[i] = mkarr(app->use_gpu, gks->basis.num_basis, phase_ghost_r->volume); + recyc->m0_flux_gk[i] = + mkarr(app->use_gpu, app->basis.num_basis, recyc->impact_cbuff_r[i].volume); + + recyc->spectrum[i] = mkarr(app->use_gpu, s->basis.num_basis, recyc->emit_buff_r.volume); + + recyc->m0op_gk[i] = gkyl_dg_updater_moment_gyrokinetic_new( + &recyc->impact_grid[i], &app->basis, &gks->basis, &recyc->emit_cbuff_r, gks->info.mass, + gks->info.charge, gks->vel_map, app->gk_geom, 0, GKYL_F_MOMENT_M0, false, app->use_gpu + ); + + // Create a phase-space range that only includes velocities towards the boundary. + gkyl_bc_emission_flux_ranges( + &recyc->impact_normal_r[i], recyc->dir + cdim, &recyc->impact_buff_r[i], ghost, recyc->edge + ); + } + + // For writing diagnostics, if needed. + if (recyc->write_diagnostics) { + recyc->f_diag = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); + recyc->emit_flux = mkarr(app->use_gpu, app->basis.num_basis, recyc->emit_cbuff_r.volume); + recyc->diag_out = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); + recyc->diag_out_ho = recyc->diag_out; + if (app->use_gpu) { + recyc->diag_out_ho = mkarr(false, app->basis.num_basis, app->local_ext.volume); + } + } +} + +void gk_neut_species_recycle_apply_bc( + struct gkyl_gyrokinetic_app *app, const struct gk_recycle_wall *recyc, + const struct gk_neut_species *s, struct gkyl_array *fout +) +{ + gkyl_array_clear(recyc->f_emit, 0.0); // Zero emitted distribution before beginning accumulate + + // Inelastic emission contribution. + // This relies on the calculation of the ion flux (phase_flux_gk). + // from gk_species_bflux_rhs_solver. + for (int i = 0; i < recyc->num_species; ++i) { + // Copy unit-density Maxwellian from buffer. + gkyl_array_set(recyc->spectrum[i], recyc->params->recycling_frac, recyc->bc_buffer); + + struct gk_species *gks = recyc->impact_species[i]; + + // Calculate M0 moment of ion flux. + gk_species_bflux_get_flux( + &gks->bflux, recyc->dir, recyc->edge, recyc->phase_flux_gk[i], &recyc->impact_buff_r[i] + ); + gkyl_dg_updater_moment_gyrokinetic_advance( + recyc->m0op_gk[i], &recyc->impact_normal_r[i], &recyc->impact_cbuff_r[i], + recyc->phase_flux_gk[i], recyc->m0_flux_gk[i] + ); + + // Calculate scaling factor from ratio of ion flux to unit-density flux. + gkyl_dg_div_op_range( + recyc->mem_geo, &app->basis, 0, recyc->m0_flux_gk[i], 0, recyc->m0_flux_gk[i], 0, + recyc->unit_m0_flux_neut, &recyc->emit_cbuff_r + ); + + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, recyc->f_emit, 1.0, recyc->m0_flux_gk[i], recyc->spectrum[i], + &recyc->impact_cbuff_r[i], &recyc->emit_buff_r + ); + } + + gkyl_array_set_range_to_range(fout, 1.0, recyc->f_emit, recyc->emit_ghost_r, &recyc->emit_buff_r); +} + +void gk_neut_species_recycle_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_recycle_wall *recyc +) +{ + gkyl_boundary_flux_release(recyc->f0_flux_slvr); + gkyl_array_release(recyc->unit_phase_flux_neut); + gkyl_array_release(recyc->f_emit); + + if (recyc->write_diagnostics) { + gkyl_array_release(recyc->f_diag); + gkyl_array_release(recyc->emit_flux); + gkyl_array_release(recyc->diag_out); + if (app->use_gpu) { + gkyl_array_release(recyc->diag_out_ho); + } + } + + gkyl_array_release(recyc->unit_m0_flux_neut); + gkyl_dg_updater_moment_release(recyc->m0op_neut); + gkyl_dg_bin_op_mem_release(recyc->mem_geo); + + for (int i = 0; i < recyc->num_species; ++i) { + gkyl_array_release(recyc->phase_flux_gk[i]); + gkyl_array_release(recyc->m0_flux_gk[i]); + gkyl_array_release(recyc->spectrum[i]); + gkyl_dg_updater_moment_gyrokinetic_release(recyc->m0op_gk[i]); + } + + gkyl_array_release(recyc->bc_buffer); +} diff --git a/gyrokinetic/apps/gk_neut_species_scaling.c b/gyrokinetic/apps/gk_neut_species_scaling.c index 6f4ef2d5c1..94819af315 100644 --- a/gyrokinetic/apps/gk_neut_species_scaling.c +++ b/gyrokinetic/apps/gk_neut_species_scaling.c @@ -1,73 +1,88 @@ #include #include -static void -gk_neut_species_scaling_cross_moms_enabled(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_scaling *sca, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +static void gk_neut_species_scaling_cross_moms_enabled( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_scaling *sca, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { - struct timespec wst = gkyl_wall_clock(); + struct timespec wst = gkyl_wall_clock(); - struct gk_species *gks_elc = &app->species[sca->elc_idx]; + struct gk_species *gks_elc = &app->species[sca->elc_idx]; // Compute electron Maxwellian moments (J*n, u_par, T/m). - gk_species_moment_calc(&gks_elc->lte.moms, - gks_elc->local, app->local, fin[sca->elc_idx]); + gk_species_moment_calc(&gks_elc->lte.moms, gks_elc->local, app->local, fin[sca->elc_idx]); // Divide the electron density by the Jacobian. - gkyl_dg_div_op_range(gks_elc->lte.moms.mem_geo, &app->basis, 0, gks_elc->lte.moms.marr, - 0, gks_elc->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gks_elc->lte.moms.mem_geo, &app->basis, 0, gks_elc->lte.moms.marr, 0, gks_elc->lte.moms.marr, 0, + app->gk_geom->geo_int.jacobgeo, &app->local + ); // Compute ionization reactivity _iz. - gkyl_dg_iz_coll(sca->iz_react_calc, gks_elc->lte.moms.marr, - sca->dndt_react, sca->dndt_react, sca->reactivity, 0); - + gkyl_dg_iz_coll( + sca->iz_react_calc, gks_elc->lte.moms.marr, sca->dndt_react, sca->dndt_react, sca->reactivity, 0 + ); + app->stat.neut_species_react_mom_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_neut_species_scaling_cross_moms_disabled(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_scaling *sca, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +static void gk_neut_species_scaling_cross_moms_disabled( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_scaling *sca, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { // Do nothing. } -static void -gk_neut_species_scaling_rhs_enabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_scaling *sca, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_neut_species_scaling_rhs_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_scaling *sca, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { - struct timespec wst = gkyl_wall_clock(); + struct timespec wst = gkyl_wall_clock(); struct gk_species *gks_elc = &app->species[sca->elc_idx]; // Compute (J*n_neut)*n_elc*_iz. - gkyl_dg_mul_op_range(&app->basis, 0, sca->dndt_react, - 0, sca->Jm0_init, 0, sca->reactivity, &app->local); - gkyl_dg_mul_op_range(&app->basis, 0, sca->dndt_react, - 0, gks_elc->lte.moms.marr, 0, sca->dndt_react, &app->local); + gkyl_dg_mul_op_range( + &app->basis, 0, sca->dndt_react, 0, sca->Jm0_init, 0, sca->reactivity, &app->local + ); + gkyl_dg_mul_op_range( + &app->basis, 0, sca->dndt_react, 0, gks_elc->lte.moms.marr, 0, sca->dndt_react, &app->local + ); // Volume integrate the reaction contribution. - gkyl_array_integrate_advance(sca->integrate_op, sca->dndt_react, 1.0, 0, &app->local, 0, sca->react_vol_integ_local); + gkyl_array_integrate_advance( + sca->integrate_op, sca->dndt_react, 1.0, 0, &app->local, 0, sca->react_vol_integ_local + ); // Reduce over MPI processes. - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, - sca->react_vol_integ_local, sca->react_vol_integ_global); - if (app->use_gpu) - gkyl_cu_memcpy(&sca->react_vol_integ, sca->react_vol_integ_global, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, 1, sca->react_vol_integ_local, sca->react_vol_integ_global + ); + if (app->use_gpu) { + gkyl_cu_memcpy( + &sca->react_vol_integ, sca->react_vol_integ_global, sizeof(double), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(&sca->react_vol_integ, sca->react_vol_integ_global, sizeof(double)); + } app->stat.neut_species_react_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_neut_species_scaling_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_scaling *sca, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_neut_species_scaling_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_scaling *sca, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { // Do nothing. } -static void -gk_neut_species_scaling_apply_enabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca, struct gkyl_array *fin, struct gkyl_array **bflux[]) +static void gk_neut_species_scaling_apply_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca, + struct gkyl_array *fin, struct gkyl_array **bflux[] +) { struct gk_species *gks_ion = &app->species[sca->ion_idx]; struct gkyl_array **bflux_ion = bflux[sca->ion_idx]; @@ -76,82 +91,97 @@ gk_neut_species_scaling_apply_enabled(gkyl_gyrokinetic_app *app, struct gk_neut_ gkyl_array_clear(sca->dndt_react, 0.0); double bflux_intm0_local_ho = 0.0; - for (int j=0; jnum_boundaries; ++j) { + for (int j = 0; j < sca->num_boundaries; ++j) { // Add integrated M0 moments of boundary fluxes. - gk_species_bflux_get_flux_mom(&gks_ion->bflux, sca->boundaries_dir[j], sca->boundaries_edge[j], - GKYL_F_MOMENT_M0, bflux_ion, sca->dndt_react, &sca->boundaries_conf_ghost[j]); - gkyl_array_integrate_advance(sca->integrate_op, sca->dndt_react, 1.0, 0, - &sca->boundaries_conf_ghost[j], 0, sca->bflux_m0_vol_integ_local); + gk_species_bflux_get_flux_mom( + &gks_ion->bflux, sca->boundaries_dir[j], sca->boundaries_edge[j], GKYL_F_MOMENT_M0, + bflux_ion, sca->dndt_react, &sca->boundaries_conf_ghost[j] + ); + gkyl_array_integrate_advance( + sca->integrate_op, sca->dndt_react, 1.0, 0, &sca->boundaries_conf_ghost[j], 0, + sca->bflux_m0_vol_integ_local + ); double bflux_m0_vol_integ_local_ho; - if (app->use_gpu) - gkyl_cu_memcpy(&bflux_m0_vol_integ_local_ho, sca->bflux_m0_vol_integ_local, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + if (app->use_gpu) { + gkyl_cu_memcpy( + &bflux_m0_vol_integ_local_ho, sca->bflux_m0_vol_integ_local, sizeof(double), + GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(&bflux_m0_vol_integ_local_ho, sca->bflux_m0_vol_integ_local, sizeof(double)); + } bflux_intm0_local_ho += bflux_m0_vol_integ_local_ho; } double bflux_intm0_global_ho; - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, &bflux_intm0_local_ho, &bflux_intm0_global_ho); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_SUM, 1, &bflux_intm0_local_ho, &bflux_intm0_global_ho + ); double neut_scaling_fac = sca->recycling_coeff * bflux_intm0_global_ho / sca->react_vol_integ; // Divide by the present J*rho, and multiply by neut_scaling_fac*mass*Jm0_init. gkyl_array_set_offset_range(sca->dndt_react, 1.0, fin, 0, &app->local); - for (int i=0; inum_moments; ++i) - gkyl_dg_div_op_range(gks_ion->lte.moms.mem_geo, &app->basis, i, fin, - i, fin, 0, sca->dndt_react, &app->local); - - for (int i=0; inum_moments; ++i) - gkyl_dg_mul_op_range(&app->basis, i, fin, - i, fin, 0, sca->Jm0_init, &app->local); - - gkyl_array_scale(fin, neut_scaling_fac*ns->info.mass); + for (int i = 0; i < ns->num_moments; ++i) { + gkyl_dg_div_op_range( + gks_ion->lte.moms.mem_geo, &app->basis, i, fin, i, fin, 0, sca->dndt_react, &app->local + ); + } + + for (int i = 0; i < ns->num_moments; ++i) { + gkyl_dg_mul_op_range(&app->basis, i, fin, i, fin, 0, sca->Jm0_init, &app->local); + } + + gkyl_array_scale(fin, neut_scaling_fac * ns->info.mass); } } -static void -gk_neut_species_scaling_apply_disabled(gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca, struct gkyl_array *fin, struct gkyl_array **bflux[]) +static void gk_neut_species_scaling_apply_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca, + struct gkyl_array *fin, struct gkyl_array **bflux[] +) { // Do nothing. } -static void -gk_neut_species_scaling_write_enabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_scaling *sca, int ridx, double tm, int frame) +static void gk_neut_species_scaling_write_enabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_scaling *sca, int ridx, + double tm, int frame +) { // React diagnostics usually written from gk_species. // In the case of static gk_species, write_diagnostics flag // can be used to check reaction rates from gk_neut_species. struct timespec wst = gkyl_wall_clock(); -// // Compute reaction rate -// const struct gkyl_array *fin[app->num_species]; -// const struct gkyl_array *fin_neut[app->num_neut_species]; -// for (int i=0; inum_species; ++i) { -// fin[i] = app->species[i].f; -// } -// for (int i=0; inum_neut_species; ++i) { -// fin_neut[i] = app->neut_species[i].f; -// } -// gk_neut_species_scaling_cross_moms(app, gkns, gkr, fin, fin_neut); + // // Compute reaction rate + // const struct gkyl_array *fin[app->num_species]; + // const struct gkyl_array *fin_neut[app->num_neut_species]; + // for (int i=0; inum_species; ++i) { + // fin[i] = app->species[i].f; + // } + // for (int i=0; inum_neut_species; ++i) { + // fin_neut[i] = app->neut_species[i].f; + // } + // gk_neut_species_scaling_cross_moms(app, gkns, gkr, fin, fin_neut); app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); - + struct timespec wtm = gkyl_wall_clock(); app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wtm); } -static void -gk_neut_species_scaling_write_disabled(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_scaling *sca, int ridx, double tm, int frame) +static void gk_neut_species_scaling_write_disabled( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_scaling *sca, int ridx, + double tm, int frame +) { // Do nothing } -void -gk_neut_species_scaling_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca) +void gk_neut_species_scaling_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca +) { struct gkyl_gyrokinetic_scaling_inp *sca_inp = &ns->info.scaling; @@ -174,15 +204,16 @@ gk_neut_species_scaling_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_sp sca->Jm0_init = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); // Create an updater that integrates an array. - sca->integrate_op = gkyl_array_integrate_new(&app->grid, &app->basis, 1, GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu); + sca->integrate_op = gkyl_array_integrate_new( + &app->grid, &app->basis, 1, GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu + ); int num_mom = 1; - if (app->use_gpu){ - sca->react_vol_integ_local = gkyl_cu_malloc(sizeof(double[num_mom])); + if (app->use_gpu) { + sca->react_vol_integ_local = gkyl_cu_malloc(sizeof(double[num_mom])); sca->react_vol_integ_global = gkyl_cu_malloc(sizeof(double[num_mom])); sca->bflux_m0_vol_integ_local = gkyl_cu_malloc(sizeof(double)); - } - else { - sca->react_vol_integ_local = gkyl_malloc(sizeof(double[num_mom])); + } else { + sca->react_vol_integ_local = gkyl_malloc(sizeof(double[num_mom])); sca->react_vol_integ_global = gkyl_malloc(sizeof(double[num_mom])); sca->bflux_m0_vol_integ_local = gkyl_malloc(sizeof(double)); } @@ -190,16 +221,17 @@ gk_neut_species_scaling_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_sp sca->cross_moms_func_neut = gk_neut_species_scaling_cross_moms_enabled; sca->rhs_func_neut = gk_neut_species_scaling_rhs_enabled; sca->apply_func_neut = gk_neut_species_scaling_apply_enabled; - if (sca->write_diagnostics) + if (sca->write_diagnostics) { sca->write_func_neut = gk_neut_species_scaling_write_enabled; - else + } else { sca->write_func_neut = gk_neut_species_scaling_write_disabled; + } } } -void -gk_neut_species_scaling_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca) +void gk_neut_species_scaling_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca +) { if (sca->type == GKYL_GK_SPECIES_SCALING_RECYCLING_IZ_BALANCE) { struct gkyl_gyrokinetic_scaling_inp *sca_inp = &ns->info.scaling; @@ -210,10 +242,10 @@ gk_neut_species_scaling_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_n struct gk_species *gks_ion = &app->species[sca->ion_idx]; - for (int j=0; jnum_boundaries; ++j) { - int dir = sca_inp->boundaries_dir[j]; + for (int j = 0; j < sca->num_boundaries; ++j) { + int dir = sca_inp->boundaries_dir[j]; int edge = sca_inp->boundaries_edge[j]; - + // Source adaptation on periodic, zero flux, or reflect boundary is not allowed. assert(gks_ion->bc_is_np[dir]); if (edge == GKYL_LOWER_EDGE) { @@ -223,27 +255,28 @@ gk_neut_species_scaling_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_n assert(gks_ion->upper_bc[dir].type != GKYL_BC_GK_SPECIES_ZERO_FLUX); assert(gks_ion->upper_bc[dir].type != GKYL_BC_GK_SPECIES_REFLECT); } - + // Default scenario: we set the ranges to the full range of the ghost cells. - sca->boundaries_conf_ghost[j] = edge == GKYL_LOWER_EDGE ? app->local_lower_ghost[dir] : app->local_upper_ghost[dir]; - sca->boundaries_dir[j] = dir; + sca->boundaries_conf_ghost[j] = edge == GKYL_LOWER_EDGE ? app->local_lower_ghost[dir] : + app->local_upper_ghost[dir]; + sca->boundaries_dir[j] = dir; sca->boundaries_edge[j] = edge; - + // Specific scenario if we are in a inner wall limited case. We select only SOL range in parallel direction. - if (dir == app->cdim-1 && app->gk_geom->has_LCFS) { - sca->boundaries_conf_ghost[j] = edge == GKYL_LOWER_EDGE? app->local_lower_ghost_par_sol - : app->local_upper_ghost_par_sol; + if (dir == app->cdim - 1 && app->gk_geom->has_LCFS) { + sca->boundaries_conf_ghost[j] = edge == GKYL_LOWER_EDGE ? app->local_lower_ghost_par_sol : + app->local_upper_ghost_par_sol; } } struct gkyl_dg_iz_inp iz_inp = { - .cbasis = &app->basis, - .conf_rng = &app->local, - .type_ion = sca_inp->impacting_ion_id, + .cbasis = &app->basis, + .conf_rng = &app->local, + .type_ion = sca_inp->impacting_ion_id, .charge_state = 0, - .type_self = GKYL_SELF_ION, // Could be GKYL_SELF_DONOR. It just can't be - // GKYL_SELF_ELC because we don't need to - // compute the ionization temperatures. + .type_self = GKYL_SELF_ION // Could be GKYL_SELF_DONOR. It just can't be + // GKYL_SELF_ELC because we don't need to + // compute the ionization temperatures. }; sca->iz_react_calc = gkyl_dg_iz_new(&iz_inp, app->use_gpu); @@ -253,64 +286,69 @@ gk_neut_species_scaling_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_n } } -void -gk_neut_species_scaling_apply_ic_cross(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca) +void gk_neut_species_scaling_apply_ic_cross( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca +) { if (sca->type == GKYL_GK_SPECIES_SCALING_RECYCLING_IZ_BALANCE) { // Project and store the initial state. Need to re-project so that restarts use this as the state at t=0. - if (ns->info.init_from_file.type == 0) + if (ns->info.init_from_file.type == 0) { gk_neut_species_projection_calc(app, ns, &ns->proj_init, ns->f1, 0.0); + } - gkyl_array_set_offset(sca->Jm0_init, 1.0/ns->info.mass, ns->f1, 0); + gkyl_array_set_offset(sca->Jm0_init, 1.0 / ns->info.mass, ns->f1, 0); - if (ns->info.init_from_file.type == 0) + if (ns->info.init_from_file.type == 0) { gkyl_array_clear(ns->f1, 0.0); + } } } -void -gk_neut_species_scaling_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_neut_species *ns, - struct gk_scaling *sca, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +void gk_neut_species_scaling_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *ns, struct gk_scaling *sca, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { sca->cross_moms_func_neut(app, ns, sca, fin, fin_neut); } -void -gk_neut_species_scaling_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_neut_species_scaling_rhs( + gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { sca->rhs_func_neut(app, ns, sca, fin, rhs); } -void -gk_neut_species_scaling_apply(gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca, struct gkyl_array *fin, struct gkyl_array **bflux[]) +void gk_neut_species_scaling_apply( + gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca, + struct gkyl_array *fin, struct gkyl_array **bflux[] +) { sca->apply_func_neut(app, ns, sca, fin, bflux); } -void -gk_neut_species_scaling_write(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_scaling *sca, int ridx, double tm, int frame) +void gk_neut_species_scaling_write( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_scaling *sca, int ridx, + double tm, int frame +) { sca->write_func_neut(app, gkns, sca, ridx, tm, frame); } -void -gk_neut_species_scaling_release(const struct gkyl_gyrokinetic_app *app, - const struct gk_scaling *sca) +void gk_neut_species_scaling_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_scaling *sca +) { if (sca->type == GKYL_GK_SPECIES_SCALING_RECYCLING_IZ_BALANCE) { gkyl_array_release(sca->Jm0_init); gkyl_array_integrate_release(sca->integrate_op); - if (app->use_gpu){ - gkyl_cu_free(sca->react_vol_integ_local ); + if (app->use_gpu) { + gkyl_cu_free(sca->react_vol_integ_local); gkyl_cu_free(sca->react_vol_integ_global); gkyl_cu_free(sca->bflux_m0_vol_integ_local); - } - else { + } else { gkyl_free(sca->react_vol_integ_local); gkyl_free(sca->react_vol_integ_global); gkyl_free(sca->bflux_m0_vol_integ_local); @@ -319,5 +357,5 @@ gk_neut_species_scaling_release(const struct gkyl_gyrokinetic_app *app, gkyl_array_release(sca->dndt_react); gkyl_dg_iz_release(sca->iz_react_calc); - } + } } diff --git a/gyrokinetic/apps/gk_neut_species_source.c b/gyrokinetic/apps/gk_neut_species_source.c index 57f88777d0..99b15507a8 100644 --- a/gyrokinetic/apps/gk_neut_species_source.c +++ b/gyrokinetic/apps/gk_neut_species_source.c @@ -1,9 +1,9 @@ #include #include -void -gk_neut_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_source *src) +void gk_neut_species_source_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_source *src +) { src->source_id = s->info.source.source_id; @@ -12,20 +12,23 @@ gk_neut_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_spe // we need to ensure source has same shape as distribution function src->source = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); src->source_host = src->source; - if (app->use_gpu) + if (app->use_gpu) { src->source_host = mkarr(false, s->basis.num_basis, s->local_ext.volume); + } src->evolve = s->info.source.evolve; // Whether the source is time dependent. src->num_sources = s->info.source.num_sources; - for (int k=0; kinfo.source.num_sources; k++) + for (int k = 0; k < s->info.source.num_sources; k++) { gk_neut_species_projection_init(app, s, s->info.source.projection[k], &src->proj_source[k]); + } // Allocate data and updaters for diagnostic moments. src->num_diag_mom = s->info.num_diag_moments; s->src.moms = gkyl_malloc(sizeof(struct gk_species_moment[src->num_diag_mom])); - for (int m=0; mnum_diag_mom; ++m) + for (int m = 0; m < src->num_diag_mom; ++m) { gk_neut_species_moment_init(app, s, &s->src.moms[m], s->info.diag_moments[m], false); + } // Allocate data and updaters for integrated moments. gk_neut_species_moment_init(app, s, &s->src.integ_moms, GKYL_F_MOMENT_M0M1M2, true); @@ -33,23 +36,23 @@ gk_neut_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_spe if (app->use_gpu) { s->src.red_integ_diag = gkyl_cu_malloc(sizeof(double[num_mom])); s->src.red_integ_diag_global = gkyl_cu_malloc(sizeof(double[num_mom])); - } - else { + } else { s->src.red_integ_diag = gkyl_malloc(sizeof(double[num_mom])); s->src.red_integ_diag_global = gkyl_malloc(sizeof(double[num_mom])); } - // allocate dynamic-vector to store all-reduced integrated moments + // allocate dynamic-vector to store all-reduced integrated moments s->src.integ_diag = gkyl_dynvec_new(GKYL_DOUBLE, num_mom); s->src.is_first_integ_write_call = true; } } -void -gk_neut_species_source_calc(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_source *src, struct gkyl_array *f_buffer, double tm) +void gk_neut_species_source_calc( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_source *src, + struct gkyl_array *f_buffer, double tm +) { if (src->source_id) { - for (int k=0; kinfo.source.num_sources; k++) { + for (int k = 0; k < s->info.source.num_sources; k++) { gk_neut_species_projection_calc(app, s, &src->proj_source[k], f_buffer, tm); gkyl_array_accumulate(src->source, 1., f_buffer); } @@ -57,9 +60,10 @@ gk_neut_species_source_calc(gkyl_gyrokinetic_app *app, struct gk_neut_species *s } // Compute rhs of the source -void -gk_neut_species_source_rhs(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_source *src, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_neut_species_source_rhs( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_source *src, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); if (src->source_id) { @@ -69,8 +73,9 @@ gk_neut_species_source_rhs(gkyl_gyrokinetic_app *app, const struct gk_neut_speci } // Write functions -void -gk_neut_species_source_write(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +void gk_neut_species_source_write( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { if (gkns->src.source_id && (gkns->src.evolve || frame == 0)) { struct timespec wtm = gkyl_wall_clock(); @@ -79,78 +84,98 @@ gk_neut_species_source_write(gkyl_gyrokinetic_app* app, struct gk_neut_species * gkyl_msgpack_map_elem_set_double(gkns->io_meta_phase_len, gkns->io_meta_phase, "time", tm); gkyl_msgpack_map_elem_set_uint(gkns->io_meta_phase_len, gkns->io_meta_phase, "frame", frame); struct gkyl_msgpack_map_elem desc_src[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Neutral species source." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Neutral species source."} + }; + int io_meta_len[] = { + gkns->io_meta_phase_len, gkns->io_meta_phase_len, app->gk_geom->io_meta_basic_len, 1 }; - int io_meta_len[] = {gkns->io_meta_phase_len, gkns->io_meta_phase_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_phase, gkns->io_meta_phase, app->gk_geom->io_meta_basic, desc_src}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_phase, gkns->io_meta_phase, app->gk_geom->io_meta_basic, desc_src + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); // Write out the source distribution function const char *fmt = "%s-%s_source_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, frame); // copy data from device to host before writing it out - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(gkns->src.source_host, gkns->src.source); + } gkyl_comm_array_write(gkns->comm, &gkns->grid, &gkns->local, mt, gkns->src.source_host, fileNm); app->stat.n_neut_io += 1; - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); app->stat.neut_species_io_tm += gkyl_time_diff_now_sec(wtm); } } -void -gk_neut_species_source_write_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame) +void gk_neut_species_source_write_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +) { if (gkns->src.source_id && (gkns->src.evolve || frame == 0)) { - // Package metadata. gkyl_msgpack_map_elem_set_double(gkns->io_meta_conf_len, gkns->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gkns->io_meta_conf_len, gkns->io_meta_conf, "frame", frame); struct gkyl_msgpack_map_elem desc_src_mom[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Velocity-space moment of the neutral species source." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Velocity-space moment of the neutral species source."} }; int io_meta_len[] = {gkns->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc_src_mom}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_conf, app->gk_geom->io_meta_basic, desc_src_mom + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); - for (int m=0; minfo.num_diag_moments; ++m) { + for (int m = 0; m < gkns->info.num_diag_moments; ++m) { struct timespec wst = gkyl_wall_clock(); gk_neut_species_moment_calc(&gkns->src.moms[m], gkns->local, app->local, gkns->src.source); app->stat.n_neut_mom += 1; // Rescale moment by inverse of Jacobian if needed. - gk_species_moment_diag_jacobgeo_div(app, &gkns->src.moms[m], gkns->src.moms[m].marr, gkns->src.moms[m].marr); + gk_species_moment_diag_jacobgeo_div( + app, &gkns->src.moms[m], gkns->src.moms[m].marr, gkns->src.moms[m].marr + ); app->stat.neut_species_diag_calc_tm += gkyl_time_diff_now_sec(wst); struct timespec wtm = gkyl_wall_clock(); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(gkns->src.moms[m].marr_host, gkns->src.moms[m].marr); + } const char *fmt = "%s-%s_source_%s_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, - gkyl_distribution_moments_strs[gkns->info.source.diagnostics.diag_moments[m]], frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, - gkyl_distribution_moments_strs[gkns->info.source.diagnostics.diag_moments[m]], frame); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, - gkns->src.moms[m].marr_host, fileNm); + int sz = gkyl_calc_strlen( + fmt, app->name, gkns->info.name, + gkyl_distribution_moments_strs[gkns->info.source.diagnostics.diag_moments[m]], frame + ); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, + gkyl_distribution_moments_strs[gkns->info.source.diagnostics.diag_moments[m]], frame + ); + + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, gkns->src.moms[m].marr_host, fileNm + ); app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wtm); app->stat.n_neut_diag_io += 1; } - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); app->stat.n_neut_diag += 1; } } -void -gk_neut_species_source_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm) +void gk_neut_species_source_calc_integrated_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm +) { if (gkns->src.source_id && gkns->src.evolve) { struct timespec wst = gkyl_wall_clock(); @@ -159,16 +184,21 @@ gk_neut_species_source_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_ int num_mom = gkns->src.integ_moms.num_mom; double avals_global[num_mom]; gk_neut_species_moment_calc(&gkns->src.integ_moms, gkns->local, app->local, gkns->src.source); - app->stat.n_neut_mom += 1; + app->stat.n_neut_mom += 1; // reduce to compute sum over whole domain, append to diagnostics - gkyl_array_reduce_range(gkns->src.red_integ_diag, gkns->src.integ_moms.marr, GKYL_SUM, &app->local); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, - gkns->src.red_integ_diag, gkns->src.red_integ_diag_global); + gkyl_array_reduce_range( + gkns->src.red_integ_diag, gkns->src.integ_moms.marr, GKYL_SUM, &app->local + ); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, gkns->src.red_integ_diag, + gkns->src.red_integ_diag_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, gkns->src.red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, gkns->src.red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, gkns->src.red_integ_diag_global, sizeof(double[num_mom])); } gkyl_dynvec_append(gkns->src.integ_diag, tm, avals_global); @@ -178,8 +208,9 @@ gk_neut_species_source_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_ } } -void -gk_neut_species_source_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns) +void gk_neut_species_source_write_integrated_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns +) { if (gkns->src.source_id && gkns->src.evolve) { struct timespec wst = gkyl_wall_clock(); @@ -190,22 +221,26 @@ gk_neut_species_source_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk // write out integrated diagnostic moments const char *fmt = "%s-%s_source_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gkns->info.name, "integrated_moms"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gkns->info.name, "integrated_moms"); if (gkns->src.is_first_integ_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated moments of the neutral source." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Volume integrated moments of the neutral source."} }; int io_meta_len[] = {gkns->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gkns->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); - + const struct gkyl_msgpack_map_elem *io_meta[] = { + gkns->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); + gkyl_dynvec_write_wmeta(gkns->src.integ_diag, fileNm, mt); gkns->src.is_first_integ_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(gkns->src.integ_diag, fileNm); } } @@ -217,32 +252,32 @@ gk_neut_species_source_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk } // Release function -void -gk_neut_species_source_release(const struct gkyl_gyrokinetic_app *app, const struct gk_source *src) +void gk_neut_species_source_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_source *src +) { if (src->source_id) { gkyl_array_release(src->source); if (app->use_gpu) { gkyl_array_release(src->source_host); } - for (int k=0; knum_sources; k++) { + for (int k = 0; k < src->num_sources; k++) { gk_neut_species_projection_release(app, &src->proj_source[k]); } // Release moment data. - for (int i=0; inum_diag_mom; ++i) { + for (int i = 0; i < src->num_diag_mom; ++i) { gk_neut_species_moment_release(app, &src->moms[i]); } gkyl_free(src->moms); - gk_neut_species_moment_release(app, &src->integ_moms); + gk_neut_species_moment_release(app, &src->integ_moms); if (app->use_gpu) { gkyl_cu_free(src->red_integ_diag); gkyl_cu_free(src->red_integ_diag_global); - } - else { + } else { gkyl_free(src->red_integ_diag); gkyl_free(src->red_integ_diag_global); - } + } gkyl_dynvec_release(src->integ_diag); } } diff --git a/gyrokinetic/apps/gk_species.c b/gyrokinetic/apps/gk_species.c index 873236eda2..19c7177128 100644 --- a/gyrokinetic/apps/gk_species.c +++ b/gyrokinetic/apps/gk_species.c @@ -16,18 +16,20 @@ #include #include -void -gk_species_gyroaverage_disabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gkyl_array *field_in, struct gkyl_array *field_gyroavg) +void gk_species_gyroaverage_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gkyl_array *field_in, + struct gkyl_array *field_gyroavg +) { struct timespec wst = gkyl_wall_clock(); // Don't perform gyroaveraging. app->stat.species_gyroavg_tm += gkyl_time_diff_now_sec(wst); } -void -gk_species_gyroaverage_enabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gkyl_array *field_in, struct gkyl_array *field_gyroavg) +void gk_species_gyroaverage_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gkyl_array *field_in, + struct gkyl_array *field_gyroavg +) { struct timespec wst = gkyl_wall_clock(); // Gyroaverage input field. @@ -45,41 +47,41 @@ gk_species_omegaH_dt(gkyl_gyrokinetic_app *app, struct gk_species *gks, const st // omega_H = q_e*sqrt(jacobgeo*n_{s0}/m_s) * omegaH_gf // where // - n_{s0} is either a reference, average or max density. - // - omegaH_gf = (cmag/(jacobgeo*B^_\parallel))*kpar_max / + // - omegaH_gf = (cmag/(jacobgeo*B^_\parallel))*kpar_max / // min(sqrt(k_x^2*eps_xx+k_x*k_y*eps_xy+k_y^2*eps_yy+)). // and k_x,k_y,k_par are wavenumbers in computational space, and eps_ij is // the polarization weight in our field equation. - - if (!(app->field->gkfield_id == GKYL_GK_FIELD_BOLTZMANN || app->field->gkfield_id == GKYL_GK_FIELD_ADIABATIC)) { + + if (!(app->field->gkfield_id == GKYL_GK_FIELD_BOLTZMANN || + app->field->gkfield_id == GKYL_GK_FIELD_ADIABATIC)) { // Obtain the maximum density (using cell centers). gk_species_moment_calc(&gks->m0, gks->local, app->local, fin); gkyl_array_reduce_range(gks->m0_max, gks->m0.marr, GKYL_MAX, &app->local); - + double m0_max[1]; if (app->use_gpu) { gkyl_cu_memcpy(m0_max, gks->m0_max, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { m0_max[0] = gks->m0_max[0]; } - m0_max[0] *= 1.0/pow(sqrt(2.0),app->cdim); + m0_max[0] *= 1.0 / pow(sqrt(2.0), app->cdim); double time_dilation_scale_const = gk_fdot_multiplier_get_time_dilation_scale_const(app, &gks->fdot_mult); - double omegaH = fabs(gks->info.charge)*sqrt(GKYL_MAX2(0.0,m0_max[0])/gks->info.mass)*app->omegaH_gf - * time_dilation_scale_const; + double omegaH = fabs(gks->info.charge) * sqrt(GKYL_MAX2(0.0, m0_max[0]) / gks->info.mass) * + app->omegaH_gf * time_dilation_scale_const; - return omegaH > 1e-20? app->cfl_omegaH/omegaH : DBL_MAX; - } - else { + return omegaH > 1e-20 ? app->cfl_omegaH / omegaH : DBL_MAX; + } else { return DBL_MAX; } } -static double -gk_species_rhs_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +static double gk_species_rhs_dynamic( + gkyl_gyrokinetic_app *app, struct gk_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms +) { // Gyroaverage the potential if needed. species->gyroaverage(app, species, app->field->phi_smooth, species->gyro_phi); @@ -91,15 +93,17 @@ gk_species_rhs_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *species, gk_species_collisionless_rhs(app, species, &species->collisionless, fin, rhs); // Damping term. - gk_species_damping_advance(app, species, &species->damping, app->field->phi_smooth, fin, - species->lte.f_lte, rhs, species->cflrate); + gk_species_damping_advance( + app, species, &species->damping, app->field->phi_smooth, fin, species->lte.f_lte, rhs, + species->cflrate + ); // LBO Collisions. gk_species_lbo_rhs(app, species, &species->lbo, fin, rhs); // BGK collisions. gk_species_bgk_rhs(app, species, &species->bgk, fin, rhs); - + // Anomalous diffusion. gk_species_anomalous_diff_rhs(app, species, &species->anom_diff, fin, rhs); @@ -122,24 +126,24 @@ gk_species_rhs_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *species, gk_species_bflux_calc_moms(app, &species->bflux, rhs, bflux_moms); // Multiply CFL rate by the df/dt multiplier. - gk_species_fdot_multiplier_advance_times_cfl(app, species, &species->fdot_mult, - app->field->phi_smooth, fin, species->cflrate); + gk_species_fdot_multiplier_advance_times_cfl( + app, species, &species->fdot_mult, app->field->phi_smooth, fin, species->cflrate + ); // Reduce the CFL frequency and compute stable dt needed by this species. - app->stat.n_species_omega_cfl +=1; + app->stat.n_species_omega_cfl += 1; struct timespec tm = gkyl_wall_clock(); gkyl_array_reduce_range(species->omega_cfl, species->cflrate, GKYL_MAX, &species->local); double omega_cfl_ho[1]; if (app->use_gpu) { gkyl_cu_memcpy(omega_cfl_ho, species->omega_cfl, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { omega_cfl_ho[0] = species->omega_cfl[0]; } - double dt_out = app->cfl/omega_cfl_ho[0]; - + double dt_out = app->cfl / omega_cfl_ho[0]; + // Apply omega_H constraint on dt. species->dt_omegaH = gk_species_omegaH_dt(app, species, fin); dt_out = fmin(dt_out, species->dt_omegaH); @@ -150,11 +154,12 @@ gk_species_rhs_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *species, return dt_out; } -static double -gk_species_rhs_implicit_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt) +static double gk_species_rhs_implicit_dynamic( + gkyl_gyrokinetic_app *app, struct gk_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt +) { - double omega_cfl = 1/DBL_MAX; + double omega_cfl = 1 / DBL_MAX; gkyl_array_clear(species->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); @@ -163,94 +168,98 @@ gk_species_rhs_implicit_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *sp gkyl_array_accumulate(gkyl_array_scale(rhs, dt), 1.0, fin); - app->stat.n_species_omega_cfl +=1; + app->stat.n_species_omega_cfl += 1; struct timespec tm = gkyl_wall_clock(); gkyl_array_reduce_range(species->omega_cfl, species->cflrate, GKYL_MAX, &species->local); double omega_cfl_ho[1]; if (app->use_gpu) { gkyl_cu_memcpy(omega_cfl_ho, species->omega_cfl, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { omega_cfl_ho[0] = species->omega_cfl[0]; } omega_cfl = omega_cfl_ho[0]; app->stat.species_omega_cfl_tm += gkyl_time_diff_now_sec(tm); - return app->cfl/omega_cfl; + return app->cfl / omega_cfl; } -static double -gk_species_rhs_static(gkyl_gyrokinetic_app *app, struct gk_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +static double gk_species_rhs_static( + gkyl_gyrokinetic_app *app, struct gk_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms +) { - double omega_cfl = 1/DBL_MAX; - return app->cfl/omega_cfl; + double omega_cfl = 1 / DBL_MAX; + return app->cfl / omega_cfl; } -static double -gk_species_rhs_implicit_static(gkyl_gyrokinetic_app *app, struct gk_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt) +static double gk_species_rhs_implicit_static( + gkyl_gyrokinetic_app *app, struct gk_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt +) { - double omega_cfl = 1/DBL_MAX; - return app->cfl/omega_cfl; + double omega_cfl = 1 / DBL_MAX; + return app->cfl / omega_cfl; } -static void -gk_species_apply_bc_dynamic(gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f) +static void gk_species_apply_bc_dynamic( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f +) { struct timespec wst = gkyl_wall_clock(); - + int num_periodic_dir = species->num_periodic_dir, cdim = app->cdim; - gkyl_comm_array_per_sync(species->comm, &species->local, &species->local_ext, - num_periodic_dir, species->periodic_dirs, f); - - for (int d=0; dbc_is_np[d]) { + gkyl_comm_array_per_sync( + species->comm, &species->local, &species->local_ext, num_periodic_dir, species->periodic_dirs, f + ); + for (int d = 0; d < cdim; ++d) { + if (species->bc_is_np[d]) { switch (species->lower_bc[d].type) { - case GKYL_BC_GK_SPECIES_SHEATH: - gkyl_bc_sheath_gyrokinetic_advance(species->bc_sheath_lo, app->field->phi_smooth, - app->field->phi_wall_lo, f, &app->local); - break; - case GKYL_BC_GK_SPECIES_TWISTSHIFT: - gkyl_bc_twistshift_advance(species->bc_ts_lo, f, f); - break; - case GKYL_BC_GK_SPECIES_COPY: - case GKYL_BC_GK_SPECIES_REFLECT: - case GKYL_BC_GK_SPECIES_ABSORB: - gkyl_bc_basic_gyrokinetic_advance(species->bc_lo[d], species->bc_buffer, f); - break; - case GKYL_BC_GK_SPECIES_FIXED_FUNC: - gkyl_bc_basic_gyrokinetic_advance(species->bc_lo[d], species->bc_buffer_lo_fixed, f); - break; - case GKYL_BC_GK_SPECIES_ZERO_FLUX: - break; // do nothing, BCs already applied in hyper_dg loop by not updating flux - default: - break; + case GKYL_BC_GK_SPECIES_SHEATH: + gkyl_bc_sheath_gyrokinetic_advance( + species->bc_sheath_lo, app->field->phi_smooth, app->field->phi_wall_lo, f, &app->local + ); + break; + case GKYL_BC_GK_SPECIES_TWISTSHIFT: + gkyl_bc_twistshift_advance(species->bc_ts_lo, f, f); + break; + case GKYL_BC_GK_SPECIES_COPY: + case GKYL_BC_GK_SPECIES_REFLECT: + case GKYL_BC_GK_SPECIES_ABSORB: + gkyl_bc_basic_gyrokinetic_advance(species->bc_lo[d], species->bc_buffer, f); + break; + case GKYL_BC_GK_SPECIES_FIXED_FUNC: + gkyl_bc_basic_gyrokinetic_advance(species->bc_lo[d], species->bc_buffer_lo_fixed, f); + break; + case GKYL_BC_GK_SPECIES_ZERO_FLUX: + break; // do nothing, BCs already applied in hyper_dg loop by not updating flux + default: + break; } switch (species->upper_bc[d].type) { - case GKYL_BC_GK_SPECIES_SHEATH: - gkyl_bc_sheath_gyrokinetic_advance(species->bc_sheath_up, app->field->phi_smooth, - app->field->phi_wall_up, f, &app->local); - break; - case GKYL_BC_GK_SPECIES_TWISTSHIFT: - gkyl_bc_twistshift_advance(species->bc_ts_up, f, f); - break; - case GKYL_BC_GK_SPECIES_COPY: - case GKYL_BC_GK_SPECIES_REFLECT: - case GKYL_BC_GK_SPECIES_ABSORB: - gkyl_bc_basic_gyrokinetic_advance(species->bc_up[d], species->bc_buffer, f); - break; - case GKYL_BC_GK_SPECIES_FIXED_FUNC: - gkyl_bc_basic_gyrokinetic_advance(species->bc_up[d], species->bc_buffer_up_fixed, f); - break; - case GKYL_BC_GK_SPECIES_ZERO_FLUX: - break; // do nothing, BCs already applied in hyper_dg loop by not updating flux - default: - break; - } + case GKYL_BC_GK_SPECIES_SHEATH: + gkyl_bc_sheath_gyrokinetic_advance( + species->bc_sheath_up, app->field->phi_smooth, app->field->phi_wall_up, f, &app->local + ); + break; + case GKYL_BC_GK_SPECIES_TWISTSHIFT: + gkyl_bc_twistshift_advance(species->bc_ts_up, f, f); + break; + case GKYL_BC_GK_SPECIES_COPY: + case GKYL_BC_GK_SPECIES_REFLECT: + case GKYL_BC_GK_SPECIES_ABSORB: + gkyl_bc_basic_gyrokinetic_advance(species->bc_up[d], species->bc_buffer, f); + break; + case GKYL_BC_GK_SPECIES_FIXED_FUNC: + gkyl_bc_basic_gyrokinetic_advance(species->bc_up[d], species->bc_buffer_up_fixed, f); + break; + case GKYL_BC_GK_SPECIES_ZERO_FLUX: + break; // do nothing, BCs already applied in hyper_dg loop by not updating flux + default: + break; + } } } @@ -265,59 +274,57 @@ gk_species_apply_bc_dynamic(gkyl_gyrokinetic_app *app, const struct gk_species * app->stat.species_bc_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_apply_bc_static(gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f) +static void gk_species_apply_bc_static( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f +) { // do nothing } static void -gk_species_step_f_dynamic(struct gkyl_array* out, double dt, - const struct gkyl_array* inp) +gk_species_step_f_dynamic(struct gkyl_array *out, double dt, const struct gkyl_array *inp) { gkyl_array_accumulate(gkyl_array_scale(out, dt), 1.0, inp); } static void -gk_species_step_f_static(struct gkyl_array* out, double dt, - const struct gkyl_array* inp) +gk_species_step_f_static(struct gkyl_array *out, double dt, const struct gkyl_array *inp) { // do nothing } -static void -gk_species_combine_dynamic(struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng) +static void gk_species_combine_dynamic( + struct gkyl_array *out, double c1, const struct gkyl_array *arr1, double c2, + const struct gkyl_array *arr2, const struct gkyl_range *rng +) { - gkyl_array_accumulate_range(gkyl_array_set_range(out, c1, arr1, rng), - c2, arr2, rng); + gkyl_array_accumulate_range(gkyl_array_set_range(out, c1, arr1, rng), c2, arr2, rng); } -static void -gk_species_combine_static(struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng) +static void gk_species_combine_static( + struct gkyl_array *out, double c1, const struct gkyl_array *arr1, double c2, + const struct gkyl_array *arr2, const struct gkyl_range *rng +) { // do nothing } -static void -gk_species_copy_range_dynamic(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range) +static void gk_species_copy_range_dynamic( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +) { gkyl_array_copy_range(out, inp, range); } -static void -gk_species_copy_range_static(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range) +static void gk_species_copy_range_static( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +) { // do nothing } static void -gk_species_write_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +gk_species_write_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { struct timespec wst = gkyl_wall_clock(); gks->write_cfl_func(app, gks, tm, frame); @@ -326,85 +333,93 @@ gk_species_write_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gks, doub gkyl_msgpack_map_elem_set_double(gks->io_meta_phase_len, gks->io_meta_phase, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_phase_len, gks->io_meta_phase, "frame", frame); struct gkyl_msgpack_map_elem io_meta_f[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Distribution function times Jacobians." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Distribution function times Jacobians."} }; - int io_meta_f_len = sizeof(io_meta_f)/sizeof(io_meta_f[0]); + int io_meta_f_len = sizeof(io_meta_f) / sizeof(io_meta_f[0]); int io_meta_len[] = {gks->io_meta_phase_len, app->gk_geom->io_meta_basic_len, io_meta_f_len}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_phase, app->gk_geom->io_meta_basic, io_meta_f}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_phase, app->gk_geom->io_meta_basic, io_meta_f + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); const char *fmt = "%s-%s_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, frame); - + // copy data from device to host before writing it out if (app->use_gpu) { gkyl_array_copy(gks->f_host, gks->f); } gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt, gks->f_host, fileNm); - - gkyl_msgpack_data_release(mt); + + gkyl_msgpack_data_release(mt); app->stat.species_io_tm += gkyl_time_diff_now_sec(wst); app->stat.n_io += 1; } static void -gk_species_write_static(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +gk_species_write_static(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { // do nothing } static void -gk_species_write_cfl_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +gk_species_write_cfl_enabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { // The 0th frame is often wrong for this diagnostic because cflrate is computed AFTER // the first time step struct timespec wst = gkyl_wall_clock(); // DG metadata for cflrate. struct gkyl_msgpack_map_elem mpe_cfl[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = "serendipity" }, - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "CFL frequency." } + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = "serendipity"}, + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "CFL frequency."} }; - int mpe_cfl_len = sizeof(mpe_cfl)/sizeof(mpe_cfl[0]); + int mpe_cfl_len = sizeof(mpe_cfl) / sizeof(mpe_cfl[0]); // Update app basic metada with time/frame. gkyl_msgpack_map_elem_set_double(gks->io_meta_phase_len, gks->io_meta_phase, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_phase_len, gks->io_meta_phase, "frame", frame); // Unionize metadata. int io_meta_len[] = {gks->io_meta_phase_len, mpe_cfl_len, app->gk_geom->io_meta_basic_len}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_phase, mpe_cfl, app->gk_geom->io_meta_basic}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_phase, mpe_cfl, app->gk_geom->io_meta_basic + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); const char *fmt = "%s-%s_cflrate_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, frame); gkyl_array_copy(gks->cflrate_ho, gks->cflrate); - gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt, - gks->cflrate_ho, fileNm); + gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt, gks->cflrate_ho, fileNm); - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); app->stat.n_io += 1; } -static void -gk_species_write_cfl_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +static void gk_species_write_cfl_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { // do nothing } static void -gk_species_write_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +gk_species_write_mom_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { // Update time/frame metadata (shared fields, set once before the loop). gkyl_msgpack_map_elem_set_double(gks->io_meta_conf_len, gks->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_conf_len, gks->io_meta_conf, "frame", frame); - for (int m=0; minfo.num_diag_moments; ++m) { + for (int m = 0; m < gks->info.num_diag_moments; ++m) { struct timespec wtm = gkyl_wall_clock(); gk_species_moment_calc(&gks->moms[m], gks->local, app->local, gks->f); app->stat.n_mom += 1; @@ -419,22 +434,29 @@ gk_species_write_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gks, } struct gkyl_msgpack_map_elem io_meta_mom[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, - .cval = (char*)gkyl_distribution_moments_descriptions[gks->info.diag_moments[m]] } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = (char *)gkyl_distribution_moments_descriptions[gks->info.diag_moments[m]]} }; int io_meta_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, io_meta_mom}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, io_meta_mom + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); const char *fmt = "%s-%s_%s_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, - gkyl_distribution_moments_strs[gks->info.diag_moments[m]], frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, - gkyl_distribution_moments_strs[gks->info.diag_moments[m]], frame); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, - gks->moms[m].marr_host, fileNm); + int sz = gkyl_calc_strlen( + fmt, app->name, gks->info.name, gkyl_distribution_moments_strs[gks->info.diag_moments[m]], + frame + ); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gks->info.name, + gkyl_distribution_moments_strs[gks->info.diag_moments[m]], frame + ); + + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, gks->moms[m].marr_host, fileNm); gkyl_msgpack_data_release(mt); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); app->stat.n_diag_io += 1; @@ -444,52 +466,57 @@ gk_species_write_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gks, } static void -gk_species_write_mom_static(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +gk_species_write_mom_static(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { // do nothing } -static void -gk_species_calc_int_mom_dt_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double dt, struct gkyl_array *fdot_int_mom) +static void gk_species_calc_int_mom_dt_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double dt, struct gkyl_array *fdot_int_mom +) { struct timespec wst = gkyl_wall_clock(); // Compute moment of f_new to compute moment of df/dt. // Need to do it after the fields are updated. - gk_species_moment_calc(&gks->integ_moms, gks->local, app->local, gks->f); - gkyl_array_set(fdot_int_mom, 1.0/dt, gks->integ_moms.marr); + gk_species_moment_calc(&gks->integ_moms, gks->local, app->local, gks->f); + gkyl_array_set(fdot_int_mom, 1.0 / dt, gks->integ_moms.marr); app->stat.fdot_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_calc_int_mom_dt_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double dt, struct gkyl_array *fdot_int_mom) +static void gk_species_calc_int_mom_dt_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double dt, struct gkyl_array *fdot_int_mom +) { } -void -gk_species_calc_int_mom_dt(gkyl_gyrokinetic_app* app, struct gk_species *gks, double dt, struct gkyl_array *fdot_int_mom) +void gk_species_calc_int_mom_dt( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double dt, struct gkyl_array *fdot_int_mom +) { gks->calc_int_mom_dt_func(app, gks, dt, fdot_int_mom); } static void -gk_species_calc_integrated_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +gk_species_calc_integrated_mom_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm) { struct timespec wst = gkyl_wall_clock(); int num_mom = gks->integ_moms.num_mom; double avals_global[num_mom]; - - gk_species_moment_calc(&gks->integ_moms, gks->local, app->local, gks->f); + + gk_species_moment_calc(&gks->integ_moms, gks->local, app->local, gks->f); app->stat.n_mom += 1; // Reduce (sum) over whole domain, append to diagnostics. gkyl_array_reduce_range(gks->red_integ_diag, gks->integ_moms.marr, GKYL_SUM, &app->local); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, - gks->red_integ_diag, gks->red_integ_diag_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, gks->red_integ_diag, gks->red_integ_diag_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, gks->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, gks->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, gks->red_integ_diag_global, sizeof(double[num_mom])); } gkyl_dynvec_append(gks->integ_diag, tm, avals_global); @@ -498,12 +525,14 @@ gk_species_calc_integrated_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_spec // Reduce (sum) over whole domain, append to diagnostics. gkyl_array_accumulate(gks->fdot_mom_new, -1.0, gks->fdot_mom_old); gkyl_array_reduce_range(gks->red_integ_diag, gks->fdot_mom_new, GKYL_SUM, &app->local); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, - gks->red_integ_diag, gks->red_integ_diag_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, gks->red_integ_diag, gks->red_integ_diag_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, gks->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, gks->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, gks->red_integ_diag_global, sizeof(double[num_mom])); } gkyl_dynvec_append(gks->fdot_integ_diag, tm, avals_global); @@ -514,7 +543,7 @@ gk_species_calc_integrated_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_spec } static void -gk_species_calc_integrated_mom_static(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +gk_species_calc_integrated_mom_static(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm) { // do nothing } @@ -530,49 +559,55 @@ gk_species_write_integrated_mom_dynamic(gkyl_gyrokinetic_app *app, struct gk_spe // Write integrated diagnostic moments. const char *fmt = "%s-%s_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, "integrated_moms"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, "integrated_moms"); - + if (gks->is_first_integ_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated moments." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated moments."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(gks->integ_diag, fileNm, mt); gks->is_first_integ_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(gks->integ_diag, fileNm); } } gkyl_dynvec_clear(gks->integ_diag); app->stat.n_diag_io += 1; - + if (gks->info.time_rate_diagnostics) { if (rank == 0) { // Write integrated diagnostic moments. const char *fmt = "%s-%s_fdot_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, "integrated_moms"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, "integrated_moms"); if (gks->is_first_fdot_integ_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated moments of time rate of change." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Volume integrated moments of time rate of change."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(gks->fdot_integ_diag, fileNm, mt); gks->is_first_fdot_integ_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(gks->fdot_integ_diag, fileNm); } } @@ -584,41 +619,41 @@ gk_species_write_integrated_mom_dynamic(gkyl_gyrokinetic_app *app, struct gk_spe } static void -gk_species_write_integrated_mom_static(gkyl_gyrokinetic_app* app, struct gk_species *gks) +gk_species_write_integrated_mom_static(gkyl_gyrokinetic_app *app, struct gk_species *gks) { // do nothing } static void -gk_species_calc_L2norm_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +gk_species_calc_L2norm_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm) { struct timespec wst = gkyl_wall_clock(); - gkyl_array_integrate_advance(gks->integ_wfsq_op, gks->f, (2.0*M_PI)/gks->info.mass, - app->jacobtot_inv_weak, &gks->local, &app->local, gks->L2norm_local); + gkyl_array_integrate_advance( + gks->integ_wfsq_op, gks->f, (2.0 * M_PI) / gks->info.mass, app->jacobtot_inv_weak, &gks->local, + &app->local, gks->L2norm_local + ); gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, gks->L2norm_local, gks->L2norm_global); double L2norm_global[] = {0.0}; if (app->use_gpu) { gkyl_cu_memcpy(L2norm_global, gks->L2norm_global, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { memcpy(L2norm_global, gks->L2norm_global, sizeof(double)); } - gkyl_dynvec_append(gks->L2norm, tm, L2norm_global); + gkyl_dynvec_append(gks->L2norm, tm, L2norm_global); app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); app->stat.n_diag += 1; } static void -gk_species_calc_L2norm_static(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +gk_species_calc_L2norm_static(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm) { // do nothing } -static void -gk_species_write_L2norm_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gks) +static void gk_species_write_L2norm_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *gks) { struct timespec wst = gkyl_wall_clock(); @@ -628,22 +663,24 @@ gk_species_write_L2norm_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gk // Write the L2 norm. const char *fmt = "%s-%s_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, "L2norm"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, "L2norm"); if (gks->is_first_L2norm_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "L2 norm of the distribution." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "L2 norm of the distribution."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(gks->L2norm, fileNm, mt); gks->is_first_L2norm_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(gks->L2norm, fileNm); } } @@ -653,14 +690,12 @@ gk_species_write_L2norm_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gk app->stat.n_diag_io += 1; } -static void -gk_species_write_L2norm_static(gkyl_gyrokinetic_app* app, struct gk_species *gks) +static void gk_species_write_L2norm_static(gkyl_gyrokinetic_app *app, struct gk_species *gks) { // do nothing } -static void -gk_species_release_dynamic(const gkyl_gyrokinetic_app* app, const struct gk_species *s) +static void gk_species_release_dynamic(const gkyl_gyrokinetic_app *app, const struct gk_species *s) { // Release various arrays and objects for a dynamic species. gkyl_array_release(s->f1); @@ -674,30 +709,26 @@ gk_species_release_dynamic(const gkyl_gyrokinetic_app* app, const struct gk_spec } // Copy BCs are allocated by default. Need to free. - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { if (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH) { gkyl_bc_sheath_gyrokinetic_release(s->bc_sheath_lo); - } - else if (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) { + } else if (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) { gkyl_bc_twistshift_release(s->bc_ts_lo); - } - else if ( (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || - (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || - (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || - (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) ) { + } else if ((s->lower_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || + (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || + (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || + (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { gkyl_bc_basic_gyrokinetic_release(s->bc_lo[d]); } - + if (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH) { gkyl_bc_sheath_gyrokinetic_release(s->bc_sheath_up); - } - else if (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) { + } else if (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) { gkyl_bc_twistshift_release(s->bc_ts_up); - } - else if ( (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || - (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || - (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || - (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) ) { + } else if ((s->upper_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || + (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || + (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || + (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { gkyl_bc_basic_gyrokinetic_release(s->bc_up[d]); } } @@ -707,26 +738,24 @@ gk_species_release_dynamic(const gkyl_gyrokinetic_app* app, const struct gk_spec gkyl_bc_twistshift_release(s->bc_ts_lo); gkyl_bc_twistshift_release(s->bc_ts_up); } - + if (app->use_gpu) { gkyl_cu_free(s->omega_cfl); gkyl_cu_free(s->m0_max); - } - else { + } else { gkyl_free(s->omega_cfl); gkyl_free(s->m0_max); } // Release integrated moment memory. - gk_species_moment_release(app, &s->integ_moms); + gk_species_moment_release(app, &s->integ_moms); // Release integrated diag memory. gkyl_dynvec_release(s->integ_diag); if (app->use_gpu) { gkyl_cu_free(s->red_integ_diag); gkyl_cu_free(s->red_integ_diag_global); - } - else { + } else { gkyl_free(s->red_integ_diag); gkyl_free(s->red_integ_diag_global); } @@ -737,8 +766,7 @@ gk_species_release_dynamic(const gkyl_gyrokinetic_app* app, const struct gk_spec if (app->use_gpu) { gkyl_cu_free(s->L2norm_local); gkyl_cu_free(s->L2norm_global); - } - else { + } else { gkyl_free(s->L2norm_local); gkyl_free(s->L2norm_global); } @@ -751,26 +779,26 @@ gk_species_release_dynamic(const gkyl_gyrokinetic_app* app, const struct gk_spec } } -static void -gk_species_release_static(const gkyl_gyrokinetic_app* app, const struct gk_species *s) +static void gk_species_release_static(const gkyl_gyrokinetic_app *app, const struct gk_species *s) { } // Initialize species object. -static void -gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, struct gk_species *gks) +static void gk_species_init_dynamic( + struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, struct gk_species *gks +) { int cdim = app->cdim, vdim = gks->info.vdim; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int ghost[GKYL_MAX_DIM]; - for (int d=0; ddt_omegaH = DBL_MIN; @@ -780,24 +808,25 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app if (app->use_gpu) { gks->omega_cfl = gkyl_cu_malloc(sizeof(double)); - gks->m0_max = gkyl_cu_malloc(app->basis.num_basis*sizeof(double)); - } - else { + gks->m0_max = gkyl_cu_malloc(app->basis.num_basis * sizeof(double)); + } else { gks->omega_cfl = gkyl_malloc(sizeof(double)); - gks->m0_max = gkyl_malloc(app->basis.num_basis*sizeof(double)); + gks->m0_max = gkyl_malloc(app->basis.num_basis * sizeof(double)); } // Allocate data for integrated moments. int num_diag_int_moms = gks->info.num_integrated_diag_moments; assert(num_diag_int_moms < 2); // 1 int moment allowed now. - gk_species_moment_init(app, gks, &gks->integ_moms, - num_diag_int_moms == 0? GKYL_F_MOMENT_M0M1M2PARM2PERP : gks->info.integrated_diag_moments[0], true); + gk_species_moment_init( + app, gks, &gks->integ_moms, + num_diag_int_moms == 0 ? GKYL_F_MOMENT_M0M1M2PARM2PERP : gks->info.integrated_diag_moments[0], + true + ); if (app->use_gpu) { gks->red_integ_diag = gkyl_cu_malloc(sizeof(double[gks->integ_moms.num_mom])); gks->red_integ_diag_global = gkyl_cu_malloc(sizeof(double[gks->integ_moms.num_mom])); - } - else { + } else { gks->red_integ_diag = gkyl_malloc(sizeof(double[gks->integ_moms.num_mom])); gks->red_integ_diag_global = gkyl_malloc(sizeof(double[gks->integ_moms.num_mom])); } @@ -807,45 +836,49 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app // Allocate dynamic-vector to store Delta f integrated moments. if (gks->info.time_rate_diagnostics) { - gks->fdot_mom_old = mkarr(app->use_gpu, gks->integ_moms.marr->ncomp, gks->integ_moms.marr->size); - gks->fdot_mom_new = mkarr(app->use_gpu, gks->integ_moms.marr->ncomp, gks->integ_moms.marr->size); + gks->fdot_mom_old = + mkarr(app->use_gpu, gks->integ_moms.marr->ncomp, gks->integ_moms.marr->size); + gks->fdot_mom_new = + mkarr(app->use_gpu, gks->integ_moms.marr->ncomp, gks->integ_moms.marr->size); gks->fdot_integ_diag = gkyl_dynvec_new(GKYL_DOUBLE, gks->integ_moms.num_mom); gks->is_first_fdot_integ_write_call = true; } // Objects for L2 norm diagnostic. - gks->integ_wfsq_op = gkyl_array_integrate_new(&gks->grid, &gks->basis, 1, GKYL_ARRAY_INTEGRATE_OP_SQ_WEIGHTED, app->use_gpu); + gks->integ_wfsq_op = gkyl_array_integrate_new( + &gks->grid, &gks->basis, 1, GKYL_ARRAY_INTEGRATE_OP_SQ_WEIGHTED, app->use_gpu + ); if (app->use_gpu) { gks->L2norm_local = gkyl_cu_malloc(sizeof(double)); gks->L2norm_global = gkyl_cu_malloc(sizeof(double)); - } - else { + } else { gks->L2norm_local = gkyl_malloc(sizeof(double)); gks->L2norm_global = gkyl_malloc(sizeof(double)); } gks->L2norm = gkyl_dynvec_new(GKYL_DOUBLE, 1); // L2 norm. gks->is_first_L2norm_write_call = true; - - int par_dir = app->cdim-1; // The last direction is the parallel one. + + int par_dir = app->cdim - 1; // The last direction is the parallel one. if (gk_app_inp->geometry.has_LCFS || - (gks->lower_bc[par_dir].type == GKYL_BC_GK_SPECIES_TWISTSHIFT || gks->upper_bc[par_dir].type == GKYL_BC_GK_SPECIES_TWISTSHIFT)) { + (gks->lower_bc[par_dir].type == GKYL_BC_GK_SPECIES_TWISTSHIFT || + gks->upper_bc[par_dir].type == GKYL_BC_GK_SPECIES_TWISTSHIFT)) { // Make the parallel direction periodic so that we sync before applying TS BC. gks->periodic_dirs[gks->num_periodic_dir] = par_dir; gks->num_periodic_dir += 1; } - + // Allocate buffer needed for BCs. bool need_bc_buffer = false; bool need_bc_buffer_lo_fixed = false; bool need_bc_buffer_up_fixed = false; - for (int d=0; dbc_is_np[d]) { - if ( (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_COPY ) || - (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || - (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB ) || - (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_COPY ) || - (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || - (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB ) ) { + if ((gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || + (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || + (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || + (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || + (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || + (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB)) { need_bc_buffer = true; } if (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) { @@ -858,27 +891,33 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app } long buff_sz = 1; - for (int dir=0; dirlocal_lower_skin[dir].volume, gks->local_upper_skin[dir].volume); buff_sz = buff_sz > vol ? buff_sz : vol; } - gks->bc_buffer = need_bc_buffer? mkarr(app->use_gpu, gks->basis.num_basis, buff_sz) - : mkarr(app->use_gpu, 1, 1); + gks->bc_buffer = need_bc_buffer ? mkarr(app->use_gpu, gks->basis.num_basis, buff_sz) : + mkarr(app->use_gpu, 1, 1); // Buffer arrays for fixed function BCs on distribution function. - gks->bc_buffer_lo_fixed = need_bc_buffer_lo_fixed? mkarr(app->use_gpu, gks->basis.num_basis, buff_sz) - : mkarr(app->use_gpu, 1, 1); - gks->bc_buffer_up_fixed = need_bc_buffer_up_fixed? mkarr(app->use_gpu, gks->basis.num_basis, buff_sz) - : mkarr(app->use_gpu, 1, 1); - - for (int d=0; dbc_buffer_lo_fixed = need_bc_buffer_lo_fixed ? + mkarr(app->use_gpu, gks->basis.num_basis, buff_sz) : + mkarr(app->use_gpu, 1, 1); + gks->bc_buffer_up_fixed = need_bc_buffer_up_fixed ? + mkarr(app->use_gpu, gks->basis.num_basis, buff_sz) : + mkarr(app->use_gpu, 1, 1); + + for (int d = 0; d < cdim; ++d) { // Lower BC. if (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH) { - struct gkyl_range *sol_skin = gk_app_inp->geometry.has_LCFS? &gks->local_lower_skin_par_sol : &gks->local_lower_skin[d]; - struct gkyl_range *sol_ghost = gk_app_inp->geometry.has_LCFS? &gks->local_lower_ghost_par_sol : &gks->local_lower_ghost[d]; - gks->bc_sheath_lo = gkyl_bc_sheath_gyrokinetic_new(d, GKYL_LOWER_EDGE, gks->basis_on_dev, - sol_skin, sol_ghost, gks->vel_map, cdim, 2.0*(gks->info.charge/gks->info.mass), app->use_gpu); - } - else if (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) { + struct gkyl_range *sol_skin = gk_app_inp->geometry.has_LCFS ? &gks->local_lower_skin_par_sol : + &gks->local_lower_skin[d]; + struct gkyl_range *sol_ghost = gk_app_inp->geometry.has_LCFS ? + &gks->local_lower_ghost_par_sol : + &gks->local_lower_ghost[d]; + gks->bc_sheath_lo = gkyl_bc_sheath_gyrokinetic_new( + d, GKYL_LOWER_EDGE, gks->basis_on_dev, sol_skin, sol_ghost, gks->vel_map, cdim, + 2.0 * (gks->info.charge / gks->info.mass), app->use_gpu + ); + } else if (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) { assert(cdim == 3); struct gkyl_bc_twistshift_inp tsinp = { .bc_dir = d, @@ -890,28 +929,31 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app .num_ghost = ghost, .basis = &gks->basis, .grid = &gks->grid, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) + if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) { tsinp.shift_dg = app->delta_ts_x_lo; - else { - tsinp.shift_func = app->gk_geom->parallel_lower_bc_shift_func; + } else { + tsinp.shift_func = app->gk_geom->parallel_lower_bc_shift_func; tsinp.shift_func_ctx = app->gk_geom->parallel_lower_bc_shift_ctx; } gks->bc_ts_lo = gkyl_bc_twistshift_inew(&tsinp); - - } - else if ( (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || - (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || - (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || - (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) ) { - if (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) - assert(d == cdim-1); // MF 2025/09/25: Reflecting BCs only allowed in the parallel direction. + } else if ((gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || + (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || + (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || + (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { + if (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) { + assert( + d == cdim - 1 + ); // MF 2025/09/25: Reflecting BCs only allowed in the parallel direction. + } - gks->bc_lo[d] = gkyl_bc_basic_gyrokinetic_new(d, GKYL_LOWER_EDGE, gks->lower_bc[d].type, gks->basis_on_dev, - &gks->local_lower_skin[d], &gks->local_lower_ghost[d], gks->f->ncomp, app->cdim, app->use_gpu); + gks->bc_lo[d] = gkyl_bc_basic_gyrokinetic_new( + d, GKYL_LOWER_EDGE, gks->lower_bc[d].type, gks->basis_on_dev, &gks->local_lower_skin[d], + &gks->local_lower_ghost[d], gks->f->ncomp, app->cdim, app->use_gpu + ); if (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) { // Project distribution desired in the ghost cell. @@ -919,12 +961,14 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app gk_species_projection_init(app, gks, gks->lower_bc[d].projection, &gk_proj_bc_lo); gk_species_projection_calc(app, gks, &gk_proj_bc_lo, gks->f1, 0.0); // Temporarily use f1. // Fill ghost cell with the boundary value. - struct gkyl_bc_basic_gyrokinetic *gfss_bc_op = gkyl_bc_basic_gyrokinetic_new(d, GKYL_LOWER_EDGE, - GKYL_BC_GK_SPECIES_BOUNDARY_VALUE, gks->basis_on_dev, &gks->local_lower_skin[d], &gks->local_lower_ghost[d], - gks->f->ncomp, app->cdim, app->use_gpu); + struct gkyl_bc_basic_gyrokinetic *gfss_bc_op = gkyl_bc_basic_gyrokinetic_new( + d, GKYL_LOWER_EDGE, GKYL_BC_GK_SPECIES_BOUNDARY_VALUE, gks->basis_on_dev, + &gks->local_lower_skin[d], &gks->local_lower_ghost[d], gks->f->ncomp, app->cdim, + app->use_gpu + ); gkyl_bc_basic_gyrokinetic_advance(gfss_bc_op, gks->bc_buffer_lo_fixed, gks->f1); gkyl_bc_basic_gyrokinetic_release(gfss_bc_op); - // Copy ghost range into buffer. + // Copy ghost range into buffer. gkyl_bc_basic_gyrokinetic_buffer_fixed_func(gks->bc_lo[d], gks->bc_buffer_lo_fixed, gks->f1); gkyl_array_clear(gks->f1, 0.0); gk_species_projection_release(app, &gk_proj_bc_lo); @@ -933,12 +977,16 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app // Upper BC. if (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH) { - struct gkyl_range *sol_skin = gk_app_inp->geometry.has_LCFS? &gks->local_upper_skin_par_sol : &gks->local_upper_skin[d]; - struct gkyl_range *sol_ghost = gk_app_inp->geometry.has_LCFS? &gks->local_upper_ghost_par_sol : &gks->local_upper_ghost[d]; - gks->bc_sheath_up = gkyl_bc_sheath_gyrokinetic_new(d, GKYL_UPPER_EDGE, gks->basis_on_dev, - sol_skin, sol_ghost, gks->vel_map, cdim, 2.0*(gks->info.charge/gks->info.mass), app->use_gpu); - } - else if (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) { + struct gkyl_range *sol_skin = gk_app_inp->geometry.has_LCFS ? &gks->local_upper_skin_par_sol : + &gks->local_upper_skin[d]; + struct gkyl_range *sol_ghost = gk_app_inp->geometry.has_LCFS ? + &gks->local_upper_ghost_par_sol : + &gks->local_upper_ghost[d]; + gks->bc_sheath_up = gkyl_bc_sheath_gyrokinetic_new( + d, GKYL_UPPER_EDGE, gks->basis_on_dev, sol_skin, sol_ghost, gks->vel_map, cdim, + 2.0 * (gks->info.charge / gks->info.mass), app->use_gpu + ); + } else if (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) { assert(cdim == 3); struct gkyl_bc_twistshift_inp tsinp = { .bc_dir = d, @@ -950,27 +998,30 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app .num_ghost = ghost, .basis = &gks->basis, .grid = &gks->grid, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) + if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) { tsinp.shift_dg = app->delta_ts_x_up; - else { - tsinp.shift_func = app->gk_geom->parallel_upper_bc_shift_func; + } else { + tsinp.shift_func = app->gk_geom->parallel_upper_bc_shift_func; tsinp.shift_func_ctx = app->gk_geom->parallel_upper_bc_shift_ctx; } gks->bc_ts_up = gkyl_bc_twistshift_inew(&tsinp); - } - else if ( (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || - (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || - (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || - (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) ) { - - if (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) - assert(d == cdim-1); // MF 2025/09/25: Reflecting BCs only allowed in the parallel direction. + } else if ((gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_COPY) || + (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_ABSORB) || + (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) || + (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { + if (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_REFLECT) { + assert( + d == cdim - 1 + ); // MF 2025/09/25: Reflecting BCs only allowed in the parallel direction. + } - gks->bc_up[d] = gkyl_bc_basic_gyrokinetic_new(d, GKYL_UPPER_EDGE, gks->upper_bc[d].type, gks->basis_on_dev, - &gks->local_upper_skin[d], &gks->local_upper_ghost[d], gks->f->ncomp, app->cdim, app->use_gpu); + gks->bc_up[d] = gkyl_bc_basic_gyrokinetic_new( + d, GKYL_UPPER_EDGE, gks->upper_bc[d].type, gks->basis_on_dev, &gks->local_upper_skin[d], + &gks->local_upper_ghost[d], gks->f->ncomp, app->cdim, app->use_gpu + ); if (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) { // Project distribution desired in the ghost cell. @@ -978,12 +1029,14 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app gk_species_projection_init(app, gks, gks->upper_bc[d].projection, &gk_proj_bc_up); gk_species_projection_calc(app, gks, &gk_proj_bc_up, gks->f1, 0.0); // Temporarily use f1. // Fill ghost cell with the boundary value. - struct gkyl_bc_basic_gyrokinetic *gfss_bc_op = gkyl_bc_basic_gyrokinetic_new(d, GKYL_UPPER_EDGE, - GKYL_BC_GK_SPECIES_BOUNDARY_VALUE, gks->basis_on_dev, &gks->local_upper_skin[d], &gks->local_upper_ghost[d], - gks->f->ncomp, app->cdim, app->use_gpu); + struct gkyl_bc_basic_gyrokinetic *gfss_bc_op = gkyl_bc_basic_gyrokinetic_new( + d, GKYL_UPPER_EDGE, GKYL_BC_GK_SPECIES_BOUNDARY_VALUE, gks->basis_on_dev, + &gks->local_upper_skin[d], &gks->local_upper_ghost[d], gks->f->ncomp, app->cdim, + app->use_gpu + ); gkyl_bc_basic_gyrokinetic_advance(gfss_bc_op, gks->bc_buffer_up_fixed, gks->f1); gkyl_bc_basic_gyrokinetic_release(gfss_bc_op); - // Copy ghost range into buffer. + // Copy ghost range into buffer. gkyl_bc_basic_gyrokinetic_buffer_fixed_func(gks->bc_up[d], gks->bc_buffer_up_fixed, gks->f1); gkyl_array_clear(gks->f1, 0.0); gk_species_projection_release(app, &gk_proj_bc_up); @@ -1003,16 +1056,16 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app .num_ghost = ghost, .basis = &gks->basis, .grid = &gks->grid, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) + if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) { tsinp_lo.shift_dg = app->delta_ts_x_lo; - else { - tsinp_lo.shift_func = app->gk_geom->parallel_lower_bc_shift_func; + } else { + tsinp_lo.shift_func = app->gk_geom->parallel_lower_bc_shift_func; tsinp_lo.shift_func_ctx = app->gk_geom->parallel_lower_bc_shift_ctx; } gks->bc_ts_lo = gkyl_bc_twistshift_inew(&tsinp_lo); - + struct gkyl_bc_twistshift_inp tsinp_up = { .bc_dir = par_dir, .shift_dir = 1, // y shift. @@ -1023,12 +1076,12 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app .num_ghost = ghost, .basis = &gks->basis, .grid = &gks->grid, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) + if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) { tsinp_up.shift_dg = app->delta_ts_x_up; - else { - tsinp_up.shift_func = app->gk_geom->parallel_upper_bc_shift_func; + } else { + tsinp_up.shift_func = app->gk_geom->parallel_upper_bc_shift_func; tsinp_up.shift_func_ctx = app->gk_geom->parallel_upper_bc_shift_ctx; } gks->bc_ts_up = gkyl_bc_twistshift_inew(&tsinp_up); @@ -1046,8 +1099,7 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app if (gks->info.write_omega_cfl) { gks->cflrate_ho = mkarr(false, gks->cflrate->ncomp, gks->cflrate->size); gks->write_cfl_func = gk_species_write_cfl_enabled; - } - else { + } else { gks->write_cfl_func = gk_species_write_cfl_disabled; } gks->write_mom_func = gk_species_write_mom_dynamic; @@ -1055,20 +1107,22 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app gks->write_integrated_mom_func = gk_species_write_integrated_mom_dynamic; gks->calc_L2norm_func = gk_species_calc_L2norm_dynamic; gks->write_L2norm_func = gk_species_write_L2norm_dynamic; - if (gks->info.time_rate_diagnostics) + if (gks->info.time_rate_diagnostics) { gks->calc_int_mom_dt_func = gk_species_calc_int_mom_dt_enabled; - else + } else { gks->calc_int_mom_dt_func = gk_species_calc_int_mom_dt_disabled; + } } // Initialize static species object. -static void -gk_species_init_static(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, struct gk_species *gks) +static void gk_species_init_static( + struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, struct gk_species *gks +) { // Allocate distribution function arrays. gks->f1 = gks->f; gks->fnew = gks->f; - + // Set function pointers. gks->rhs_func = gk_species_rhs_static; gks->rhs_implicit_func = gk_species_rhs_implicit_static; @@ -1087,9 +1141,9 @@ gk_species_init_static(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app * gks->calc_int_mom_dt_func = gk_species_calc_int_mom_dt_disabled; } -void -gk_species_file_import_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gkyl_gyrokinetic_ic_import inp) +void gk_species_file_import_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gkyl_gyrokinetic_ic_import inp +) { // Import initial condition from a file. Intended options include importing: // 1) ICs with same grid. @@ -1110,8 +1164,8 @@ gk_species_file_import_init(struct gkyl_gyrokinetic_app *app, struct gk_species // Read the header of the input file, extract needed info an create a grid // and other things needed. FILE *fp; - with_file(fp, inp.file_name, "r") { - + with_file(fp, inp.file_name, "r") + { int status = gkyl_grid_sub_array_header_read_fp(&grid_do, &hdr, fp); pdim_do = grid_do.ndim; @@ -1121,45 +1175,49 @@ gk_species_file_import_init(struct gkyl_gyrokinetic_app *app, struct gk_species // Perform some basic checks. if (pdim_do == pdim) { // Check if the grid resolution is the same. - for (int d=0; dbasis.id, gkyl_msgpack_map_elem_get_string(elem_list_len, elem_list, "basis_type")) == 0); + int elem_list_len = sizeof(elem_list) / sizeof(elem_list[0]); + gkyl_msgpack_to_map_elem_list( + &(struct gkyl_msgpack_data){.meta = hdr.meta, .meta_sz = hdr.meta_size}, elem_list_len, + elem_list + ); + assert( + strcmp( + gks->basis.id, gkyl_msgpack_map_elem_get_string(elem_list_len, elem_list, "basis_type") + ) == 0 + ); assert(poly_order == gkyl_msgpack_map_elem_get_uint(elem_list_len, elem_list, "poly_order")); gkyl_msgpack_map_elem_release_string(elem_list_len, elem_list, "basis_type"); @@ -1169,49 +1227,51 @@ gk_species_file_import_init(struct gkyl_gyrokinetic_app *app, struct gk_species // Donor basis. struct gkyl_basis basis_do; switch (gks->basis.b_type) { - case GKYL_BASIS_MODAL_GKHYBRID: - case GKYL_BASIS_MODAL_SERENDIPITY: - if (poly_order > 1) { - gkyl_cart_modal_serendip(&basis_do, pdim_do, poly_order); - } - else if (poly_order == 1) { - // p=2 in vparallel - gkyl_cart_modal_gkhybrid(&basis_do, cdim_do, vdim_do); - } - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_GKHYBRID: + case GKYL_BASIS_MODAL_SERENDIPITY: + if (poly_order > 1) { + gkyl_cart_modal_serendip(&basis_do, pdim_do, poly_order); + } else if (poly_order == 1) { + // p=2 in vparallel + gkyl_cart_modal_gkhybrid(&basis_do, cdim_do, vdim_do); + } + break; + default: + assert(false); + break; } // Donor global range. int ghost_do[pdim_do]; - for (int d=0; ddecomp, cuts_tar); - if (cdim_do == cdim-1) { - for (int d=0; dcomm, 0, decomp_do); + struct gkyl_comm *comm_do = gkyl_comm_split_comm(gks->comm, 0, decomp_do); // Donor local range. int my_rank = 0; @@ -1222,15 +1282,16 @@ gk_species_file_import_init(struct gkyl_gyrokinetic_app *app, struct gk_species // Donor array. struct gkyl_array *fdo = mkarr(app->use_gpu, basis_do.num_basis, local_ext_do.volume); - struct gkyl_array *fdo_host = app->use_gpu? mkarr(false, basis_do.num_basis, local_ext_do.volume) - : gkyl_array_acquire(fdo); + struct gkyl_array *fdo_host = + app->use_gpu ? mkarr(false, basis_do.num_basis, local_ext_do.volume) : gkyl_array_acquire(fdo); // Read donor distribution function and Jacobian inverse. struct gkyl_app_restart_status rstat; rstat.io_status = gkyl_comm_array_read(comm_do, &grid_do, &local_do, fdo_host, inp.file_name); bool scale_by_jacobtot = false; - with_file(fp, inp.jacobtot_inv_file_name, "r") { + with_file(fp, inp.jacobtot_inv_file_name, "r") + { // Configuration space donor grid and basis struct gkyl_rect_grid conf_grid_do; gkyl_rect_grid_init(&conf_grid_do, cdim_do, grid_do.lower, grid_do.upper, grid_do.cells); @@ -1239,22 +1300,33 @@ gk_species_file_import_init(struct gkyl_gyrokinetic_app *app, struct gk_species // Configuration space donor ranges and decomposition. struct gkyl_range conf_local_ext_do, conf_local_do, conf_global_ext_do, conf_global_do; gkyl_create_grid_ranges(&conf_grid_do, ghost_do, &conf_global_ext_do, &conf_global_do); - struct gkyl_rect_decomp *conf_decomp_do = gkyl_rect_decomp_new_from_cuts(cdim_do, cuts_do, &conf_global_do); - gkyl_create_ranges(&conf_decomp_do->ranges[my_rank], ghost_do, &conf_local_ext_do, &conf_local_do); + struct gkyl_rect_decomp *conf_decomp_do = + gkyl_rect_decomp_new_from_cuts(cdim_do, cuts_do, &conf_global_do); + gkyl_create_ranges( + &conf_decomp_do->ranges[my_rank], ghost_do, &conf_local_ext_do, &conf_local_do + ); // Read and multiply by the reciprocal of jacobtot. - struct gkyl_array *jacobtot_inv_do_host = mkarr(false, conf_basis_do.num_basis, conf_local_ext_do.volume); - rstat.io_status = gkyl_comm_array_read(comm_do, &conf_grid_do, &conf_local_do, jacobtot_inv_do_host, inp.jacobtot_inv_file_name); - gkyl_dg_mul_conf_phase_op_range(&conf_basis_do, &basis_do, fdo_host, jacobtot_inv_do_host, fdo_host, &conf_local_ext_do, &local_ext_do); + struct gkyl_array *jacobtot_inv_do_host = + mkarr(false, conf_basis_do.num_basis, conf_local_ext_do.volume); + rstat.io_status = gkyl_comm_array_read( + comm_do, &conf_grid_do, &conf_local_do, jacobtot_inv_do_host, inp.jacobtot_inv_file_name + ); + gkyl_dg_mul_conf_phase_op_range( + &conf_basis_do, &basis_do, fdo_host, jacobtot_inv_do_host, fdo_host, &conf_local_ext_do, + &local_ext_do + ); gkyl_array_release(jacobtot_inv_do_host); gkyl_rect_decomp_release(conf_decomp_do); scale_by_jacobtot = true; } bool scale_by_jacobvel = false; - with_file(fp, inp.jacobvel_file_name, "r") { + with_file(fp, inp.jacobvel_file_name, "r") + { // Read and multiply by the reciprocal of jacobvel. struct gkyl_array *jacobvel_do_host = mkarr(false, 1, local_ext_do.volume); - rstat.io_status = gkyl_comm_array_read(comm_do, &grid_do, &local_do, jacobvel_do_host, inp.jacobvel_file_name); + rstat.io_status = + gkyl_comm_array_read(comm_do, &grid_do, &local_do, jacobvel_do_host, inp.jacobvel_file_name); gkyl_array_divide_by_cell(fdo_host, jacobvel_do_host); gkyl_array_release(jacobvel_do_host); scale_by_jacobvel = true; @@ -1264,20 +1336,19 @@ gk_species_file_import_init(struct gkyl_gyrokinetic_app *app, struct gk_species gkyl_array_copy(fdo, fdo_host); } - if (pdim_do == pdim-1) { - struct gkyl_translate_dim* transdim = gkyl_translate_dim_new(cdim_do, - basis_do, cdim, gks->basis, -1, GKYL_NO_EDGE, app->use_gpu); + if (pdim_do == pdim - 1) { + struct gkyl_translate_dim *transdim = + gkyl_translate_dim_new(cdim_do, basis_do, cdim, gks->basis, -1, GKYL_NO_EDGE, app->use_gpu); gkyl_translate_dim_advance(transdim, &local_do, &gks->local, fdo, 1, gks->f); gkyl_translate_dim_release(transdim); - } - else { + } else { if (same_res) { gkyl_array_copy(gks->f, fdo); - } - else { + } else { // Interpolate the donor distribution to the target grid. - struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new(app->cdim, &gks->basis, - &grid_do, &grid, &local_do, &gks->local, ghost_do, app->use_gpu); + struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new( + app->cdim, &gks->basis, &grid_do, &grid, &local_do, &gks->local, ghost_do, app->use_gpu + ); gkyl_dg_interpolate_advance(interp, fdo, gks->f); gkyl_dg_interpolate_release(interp); } @@ -1285,34 +1356,46 @@ gk_species_file_import_init(struct gkyl_gyrokinetic_app *app, struct gk_species if (inp.type == GKYL_IC_IMPORT_AF) { // Scale f by a conf-space factor. - gkyl_proj_on_basis *proj_conf_scale = gkyl_proj_on_basis_new(&app->grid, &app->basis, - poly_order+1, 1, inp.conf_scale, inp.conf_scale_ctx); + gkyl_proj_on_basis *proj_conf_scale = gkyl_proj_on_basis_new( + &app->grid, &app->basis, poly_order + 1, 1, inp.conf_scale, inp.conf_scale_ctx + ); struct gkyl_array *xfac = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - struct gkyl_array *xfac_ho = app->use_gpu? mkarr(false, app->basis.num_basis, app->local_ext.volume) - : gkyl_array_acquire(xfac); + struct gkyl_array *xfac_ho = app->use_gpu ? + mkarr(false, app->basis.num_basis, app->local_ext.volume) : + gkyl_array_acquire(xfac); gkyl_proj_on_basis_advance(proj_conf_scale, 0.0, &app->local, xfac_ho); gkyl_array_copy(xfac, xfac_ho); - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gks->basis, gks->f, xfac, gks->f, &app->local, &gks->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gks->basis, gks->f, xfac, gks->f, &app->local, &gks->local + ); gkyl_proj_on_basis_release(proj_conf_scale); gkyl_array_release(xfac_ho); gkyl_array_release(xfac); } // Multiply f by the Jacobian. - if (scale_by_jacobtot) - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gks->basis, gks->f, app->gk_geom->geo_int.jacobtot, gks->f, &app->local, &gks->local); + if (scale_by_jacobtot) { + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gks->basis, gks->f, app->gk_geom->geo_int.jacobtot, gks->f, &app->local, + &gks->local + ); + } // Multiply f by the velocity space Jacobian. - if (scale_by_jacobvel) + if (scale_by_jacobvel) { gkyl_array_scale_by_cell(gks->f, gks->vel_map->jacobvel); + } if (inp.enforce_positivity) { // Positivity enforcing by shifting f (ps=positivity shift). - struct gkyl_positivity_shift_gyrokinetic *pos_shift_op = gkyl_positivity_shift_gyrokinetic_new(app->basis, - gks->basis, gks->grid, gks->info.mass, app->gk_geom, gks->vel_map, &app->local_ext, app->use_gpu); + struct gkyl_positivity_shift_gyrokinetic *pos_shift_op = gkyl_positivity_shift_gyrokinetic_new( + app->basis, gks->basis, gks->grid, gks->info.mass, app->gk_geom, gks->vel_map, + &app->local_ext, app->use_gpu + ); - gkyl_positivity_shift_gyrokinetic_advance(pos_shift_op, &app->local, &gks->local, - gks->f, gks->m0.marr, gks->m0.marr); + gkyl_positivity_shift_gyrokinetic_advance( + pos_shift_op, &app->local, &gks->local, gks->f, gks->m0.marr, gks->m0.marr + ); gkyl_positivity_shift_gyrokinetic_release(pos_shift_op); } @@ -1323,19 +1406,19 @@ gk_species_file_import_init(struct gkyl_gyrokinetic_app *app, struct gk_species gkyl_array_release(fdo_host); } -static bool -gk_species_do_I_recycle(struct gkyl_gyrokinetic_app *app, struct gk_species *gks) +static bool gk_species_do_I_recycle(struct gkyl_gyrokinetic_app *app, struct gk_species *gks) { // Check whether one of the neutral species has recycling BCs that depend on // this gyrokinetic species. bool recycling_bcs = false; int neuts = app->num_neut_species; - for (int i=0; icdim; k++) { + for (int i = 0; i < neuts; ++i) { + for (int k = 0; k < 2 * app->cdim; k++) { const struct gkyl_gyrokinetic_bc *bc = &app->neut_species[i].info.bcs[k]; if (bc->type == GKYL_BC_GK_SPECIES_RECYCLE) { - for (int j=0; jemission.num_species; j++) + for (int j = 0; j < bc->emission.num_species; j++) { recycling_bcs = recycling_bcs || 0 == strcmp(gks->info.name, bc->emission.in_species[j]); + } } } } @@ -1349,10 +1432,11 @@ gk_species_do_I_recycle_react_scale(struct gkyl_gyrokinetic_app *app, struct gk_ // operation thats depend on this gyrokinetic species. bool has_sca = false; int neuts = app->num_neut_species; - for (int i=0; ineut_species[i]; struct gkyl_gyrokinetic_scaling_inp *sca_inp = &ns->info.scaling; - if ((sca_inp->num_boundaries > 0) && (0 == strcmp(gks->info.name, sca_inp->impacting_ion_name))) { + if ((sca_inp->num_boundaries > 0) && + (0 == strcmp(gks->info.name, sca_inp->impacting_ion_name))) { has_sca = true; break; } @@ -1360,27 +1444,28 @@ gk_species_do_I_recycle_react_scale(struct gkyl_gyrokinetic_app *app, struct gk_ return has_sca; } -static bool -gk_species_do_I_adapt_src(struct gkyl_gyrokinetic_app *app, struct gk_species *gks) +static bool gk_species_do_I_adapt_src(struct gkyl_gyrokinetic_app *app, struct gk_species *gks) { // Check whether one of the species adapts its source depending on // this gyrokinetic species. bool adapt_src = false; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gkyl_gyrokinetic_source *source = &app->species[i].info.source; if (source->num_adapt_sources > 0) { - for (int j=0; jnum_adapt_sources; j++) + for (int j = 0; j < source->num_adapt_sources; j++) { adapt_src = adapt_src || 0 == strcmp(gks->info.name, source->adapt[j].adapt_to_species); + } } } return adapt_src; } -void -gk_species_init(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, struct gk_species *gks) +void gk_species_init( + struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, struct gk_species *gks +) { int cdim = app->cdim, vdim = gks->info.vdim; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int cells[GKYL_MAX_DIM], ghost[GKYL_MAX_DIM]; double lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; @@ -1390,17 +1475,17 @@ gk_species_init(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, st assert(vdim > 0); // Ensure user provided vdim in input file. - for (int d=0; dcells[d]; lower[d] = gk_app_inp->lower[d]; upper[d] = gk_app_inp->upper[d]; ghost[d] = 1; } - for (int d=0; dinfo.cells[d]; - lower[cdim+d] = gks->info.lower[d]; - upper[cdim+d] = gks->info.upper[d]; - ghost[cdim+d] = 0; // No ghost-cells in velocity space. + for (int d = 0; d < vdim; ++d) { + cells[cdim + d] = gks->info.cells[d]; + lower[cdim + d] = gks->info.lower[d]; + upper[cdim + d] = gks->info.upper[d]; + ghost[cdim + d] = 0; // No ghost-cells in velocity space. cells_vel[d] = gks->info.cells[d]; lower_vel[d] = gks->info.lower[d]; @@ -1412,8 +1497,7 @@ gk_species_init(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, st if (app->use_gpu) { // allocate device basis if we are using GPUs gks->basis_on_dev = gkyl_cu_malloc(sizeof(struct gkyl_basis)); - } - else { + } else { gks->basis_on_dev = &gks->basis; } @@ -1421,32 +1505,30 @@ gk_species_init(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, st // basis functions switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (app->poly_order > 1) { - gkyl_cart_modal_serendip(&gks->basis, pdim, app->poly_order); - } - else if (app->poly_order == 1) { - gkyl_cart_modal_gkhybrid(&gks->basis, cdim, vdim); // p=2 in vparallel - } + case GKYL_BASIS_MODAL_SERENDIPITY: + if (app->poly_order > 1) { + gkyl_cart_modal_serendip(&gks->basis, pdim, app->poly_order); + } else if (app->poly_order == 1) { + gkyl_cart_modal_gkhybrid(&gks->basis, cdim, vdim); // p=2 in vparallel + } - if (app->use_gpu) { - if (app->poly_order > 1) { - gkyl_cart_modal_serendip_cu_dev(gks->basis_on_dev, pdim, app->poly_order); - } - else if (app->poly_order == 1) { - gkyl_cart_modal_gkhybrid_cu_dev(gks->basis_on_dev, cdim, vdim); // p=2 in vparallel - } + if (app->use_gpu) { + if (app->poly_order > 1) { + gkyl_cart_modal_serendip_cu_dev(gks->basis_on_dev, pdim, app->poly_order); + } else if (app->poly_order == 1) { + gkyl_cart_modal_gkhybrid_cu_dev(gks->basis_on_dev, cdim, vdim); // p=2 in vparallel } - break; - default: - assert(false); - break; + } + break; + default: + assert(false); + break; } - + // Full phase space grid. gkyl_rect_grid_init(&gks->grid, pdim, lower, upper, cells); gkyl_create_grid_ranges(&gks->grid, ghost, &gks->global_ext, &gks->global); - + // Velocity space grid. gkyl_rect_grid_init(&gks->grid_vel, vdim, lower_vel, upper_vel, cells_vel); gkyl_create_grid_ranges(&gks->grid_vel, ghost_vel, &gks->local_ext_vel, &gks->local_vel); @@ -1461,88 +1543,114 @@ gk_species_init(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, st gkyl_create_ranges(&local, ghost, &gks->local_ext, &gks->local); // Velocity space mapping. - gks->vel_map = gkyl_velocity_map_new(gks->info.mapc2p, gks->grid, gks->grid_vel, - gks->local, gks->local_ext, gks->local_vel, gks->local_ext_vel, app->use_gpu); + gks->vel_map = gkyl_velocity_map_new( + gks->info.mapc2p, gks->grid, gks->grid_vel, gks->local, gks->local_ext, gks->local_vel, + gks->local_ext_vel, app->use_gpu + ); // Write out the velocity space mapping and its Jacobian. gkyl_velocity_map_write(gks->vel_map, gks->comm, app->name, gks->info.name); - + // Keep a copy of num_periodic_dir and periodic_dirs in species so we can // add the parallel direction in case TS BCs are needed. gks->num_periodic_dir = app->num_periodic_dir; - for (int d=0; dnum_periodic_dir; ++d) + for (int d = 0; d < gks->num_periodic_dir; ++d) { gks->periodic_dirs[d] = app->periodic_dirs[d]; + } - for (int d=0; dcdim; ++d) gks->bc_is_np[d] = true; - for (int d=0; dnum_periodic_dir; ++d) + for (int d = 0; d < app->cdim; ++d) { + gks->bc_is_np[d] = true; + } + for (int d = 0; d < gks->num_periodic_dir; ++d) { gks->bc_is_np[gks->periodic_dirs[d]] = false; + } // Store the BCs from the input file. - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { if (gks->bc_is_np[d]) { - struct gkyl_gyrokinetic_bc *bc_lo = gk_fetch_bc_with_dir_edge(gks->info.bcs, 2*app->cdim, d, GKYL_LOWER_EDGE); - if (bc_lo != 0) + struct gkyl_gyrokinetic_bc *bc_lo = + gk_fetch_bc_with_dir_edge(gks->info.bcs, 2 * app->cdim, d, GKYL_LOWER_EDGE); + if (bc_lo != 0) { gks->lower_bc[d] = *bc_lo; - else + } else { gks->lower_bc[d].type = GKYL_BC_GK_SKIP; - - struct gkyl_gyrokinetic_bc *bc_up = gk_fetch_bc_with_dir_edge(gks->info.bcs, 2*app->cdim, d, GKYL_UPPER_EDGE); - if (bc_up != 0) + } + + struct gkyl_gyrokinetic_bc *bc_up = + gk_fetch_bc_with_dir_edge(gks->info.bcs, 2 * app->cdim, d, GKYL_UPPER_EDGE); + if (bc_up != 0) { gks->upper_bc[d] = *bc_up; - else + } else { gks->upper_bc[d].type = GKYL_BC_GK_SKIP; - } - else { + } + } else { gks->lower_bc[d].type = GKYL_BC_GK_SPECIES_PERIODIC; gks->upper_bc[d].type = GKYL_BC_GK_SPECIES_PERIODIC; } } - + // Species properties metadata. struct gkyl_msgpack_map_elem io_meta_sprop[] = { - { .key = "mass", .elem_type = GKYL_MP_DOUBLE, .dval = gks->info.mass }, - { .key = "charge", .elem_type = GKYL_MP_DOUBLE, .dval = gks->info.charge }, - { .key = "vdim", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = gks->info.vdim }, + {.key = "mass", .elem_type = GKYL_MP_DOUBLE, .dval = gks->info.mass}, + {.key = "charge", .elem_type = GKYL_MP_DOUBLE, .dval = gks->info.charge}, + {.key = "vdim", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = gks->info.vdim} }; // Metadata for integrated quantities. const struct gkyl_msgpack_map_elem *io_meta_basic_union[] = {app->io_meta_basic, io_meta_sprop}; - int io_meta_basic_union_len[] = {app->io_meta_basic_len, sizeof(io_meta_sprop)/sizeof(io_meta_sprop[0])}; - gks->io_meta_basic = gkyl_msgpack_map_elem_union(sizeof(io_meta_basic_union)/sizeof(io_meta_basic_union[0]), - io_meta_basic_union_len, io_meta_basic_union, &gks->io_meta_basic_len); + int io_meta_basic_union_len[] = { + app->io_meta_basic_len, sizeof(io_meta_sprop) / sizeof(io_meta_sprop[0]) + }; + gks->io_meta_basic = gkyl_msgpack_map_elem_union( + sizeof(io_meta_basic_union) / sizeof(io_meta_basic_union[0]), io_meta_basic_union_len, + io_meta_basic_union, &gks->io_meta_basic_len + ); // Metadata for conf-space quantities. struct gkyl_msgpack_map_elem io_meta_conf[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = app->basis.poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->basis.id }, - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0 }, - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = app->basis.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->basis.id}, + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0}, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0} + }; + const struct gkyl_msgpack_map_elem *io_meta_conf_union[] = { + app->io_meta_basic, io_meta_sprop, io_meta_conf + }; + int io_meta_conf_union_len[] = { + app->io_meta_basic_len, sizeof(io_meta_sprop) / sizeof(io_meta_sprop[0]), + sizeof(io_meta_conf) / sizeof(io_meta_conf[0]) }; - const struct gkyl_msgpack_map_elem *io_meta_conf_union[] = {app->io_meta_basic, io_meta_sprop, io_meta_conf}; - int io_meta_conf_union_len[] = {app->io_meta_basic_len, sizeof(io_meta_sprop)/sizeof(io_meta_sprop[0]), - sizeof(io_meta_conf)/sizeof(io_meta_conf[0])}; - gks->io_meta_conf = gkyl_msgpack_map_elem_union(sizeof(io_meta_conf_union)/sizeof(io_meta_conf_union[0]), - io_meta_conf_union_len, io_meta_conf_union, &gks->io_meta_conf_len); + gks->io_meta_conf = gkyl_msgpack_map_elem_union( + sizeof(io_meta_conf_union) / sizeof(io_meta_conf_union[0]), io_meta_conf_union_len, + io_meta_conf_union, &gks->io_meta_conf_len + ); // Metadata for phase-space quantities. struct gkyl_msgpack_map_elem io_meta_phase[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = gks->basis.poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = gks->basis.id }, - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0 }, - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = gks->basis.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = gks->basis.id}, + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0}, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0} }; - const struct gkyl_msgpack_map_elem *io_meta_phase_union[] = {app->io_meta_basic, io_meta_sprop, io_meta_phase}; - int io_meta_phase_union_len[] = {app->io_meta_basic_len, sizeof(io_meta_sprop)/sizeof(io_meta_sprop[0]), - sizeof(io_meta_phase)/sizeof(io_meta_phase[0])}; - gks->io_meta_phase = gkyl_msgpack_map_elem_union(sizeof(io_meta_phase_union)/sizeof(io_meta_phase_union[0]), - io_meta_phase_union_len, io_meta_phase_union, &gks->io_meta_phase_len); + const struct gkyl_msgpack_map_elem *io_meta_phase_union[] = { + app->io_meta_basic, io_meta_sprop, io_meta_phase + }; + int io_meta_phase_union_len[] = { + app->io_meta_basic_len, sizeof(io_meta_sprop) / sizeof(io_meta_sprop[0]), + sizeof(io_meta_phase) / sizeof(io_meta_phase[0]) + }; + gks->io_meta_phase = gkyl_msgpack_map_elem_union( + sizeof(io_meta_phase_union) / sizeof(io_meta_phase_union[0]), io_meta_phase_union_len, + io_meta_phase_union, &gks->io_meta_phase_len + ); // Allocate distribution function arrays. gks->f = mkarr(app->use_gpu, gks->basis.num_basis, gks->local_ext.volume); gks->f_host = gks->f; - if (app->use_gpu) + if (app->use_gpu) { gks->f_host = mkarr(false, gks->basis.num_basis, gks->local_ext.volume); + } // Allocate cflrate (scalar array). gks->cflrate = mkarr(app->use_gpu, 1, gks->local_ext.volume); @@ -1561,53 +1669,68 @@ gk_species_init(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, st double gyroradius_bmag = gks->info.flr.bmag ? gks->info.flr.bmag : app->bmag_ref; - double flr_weight = gks->info.flr.Tperp*gks->info.mass/(pow(gks->info.charge*gyroradius_bmag,2.0)); + double flr_weight = + gks->info.flr.Tperp * gks->info.mass / (pow(gks->info.charge * gyroradius_bmag, 2.0)); // Initialize the weight in the Laplacian operator. - gks->flr_rhoSqD2 = mkarr(app->use_gpu, (2*(app->cdim-1)-1)*app->basis.num_basis, app->local_ext.volume); - gkyl_array_set_offset(gks->flr_rhoSqD2, flr_weight, app->gk_geom->geo_int.gxxj, 0*app->basis.num_basis); + gks->flr_rhoSqD2 = + mkarr(app->use_gpu, (2 * (app->cdim - 1) - 1) * app->basis.num_basis, app->local_ext.volume); + gkyl_array_set_offset( + gks->flr_rhoSqD2, flr_weight, app->gk_geom->geo_int.gxxj, 0 * app->basis.num_basis + ); if (app->cdim > 2) { - gkyl_array_set_offset(gks->flr_rhoSqD2, flr_weight, app->gk_geom->geo_int.gxyj, 1*app->basis.num_basis); - gkyl_array_set_offset(gks->flr_rhoSqD2, flr_weight, app->gk_geom->geo_int.gyyj, 2*app->basis.num_basis); + gkyl_array_set_offset( + gks->flr_rhoSqD2, flr_weight, app->gk_geom->geo_int.gxyj, 1 * app->basis.num_basis + ); + gkyl_array_set_offset( + gks->flr_rhoSqD2, flr_weight, app->gk_geom->geo_int.gyyj, 2 * app->basis.num_basis + ); } // Initialize the factor multiplying the field in the FLR operator. gks->flr_kSq = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - gkyl_array_shiftc(gks->flr_kSq, -pow(sqrt(2.0),app->cdim), 0); // Sets kSq=-1. + gkyl_array_shiftc(gks->flr_kSq, -pow(sqrt(2.0), app->cdim), 0); // Sets kSq=-1. // If domain is not periodic use Dirichlet BCs. struct gkyl_poisson_bc flr_bc; - for (int d=0; dcdim-1; d++) { - struct gkyl_gyrokinetic_bc *bc_lo = gk_fetch_bc_with_dir_edge(app->field->info.poisson_bcs, 2*app->cdim, d, GKYL_LOWER_EDGE); + for (int d = 0; d < app->cdim - 1; d++) { + struct gkyl_gyrokinetic_bc *bc_lo = + gk_fetch_bc_with_dir_edge(app->field->info.poisson_bcs, 2 * app->cdim, d, GKYL_LOWER_EDGE); if (bc_lo != 0) { - if (bc_lo->type == GKYL_BC_GK_FIELD_PERIODIC) + if (bc_lo->type == GKYL_BC_GK_FIELD_PERIODIC) { flr_bc.lo_type[d] = gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_PERIODIC); - else - flr_bc.lo_type[d] = gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_DIRICHLET_VARYING); + } else { + flr_bc.lo_type[d] = + gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_DIRICHLET_VARYING); + } } - struct gkyl_gyrokinetic_bc *bc_up = gk_fetch_bc_with_dir_edge(app->field->info.poisson_bcs, 2*app->cdim, d, GKYL_UPPER_EDGE); + struct gkyl_gyrokinetic_bc *bc_up = + gk_fetch_bc_with_dir_edge(app->field->info.poisson_bcs, 2 * app->cdim, d, GKYL_UPPER_EDGE); if (bc_up != 0) { - if (bc_up->type == GKYL_BC_GK_FIELD_PERIODIC) + if (bc_up->type == GKYL_BC_GK_FIELD_PERIODIC) { flr_bc.up_type[d] = gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_PERIODIC); - else - flr_bc.up_type[d] = gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_DIRICHLET_VARYING); + } else { + flr_bc.up_type[d] = + gkyl_gyrokinetic_translate_poisson_bc_type(GKYL_BC_GK_FIELD_DIRICHLET_VARYING); + } } } // Deflated Poisson solve is performed on range assuming decomposition is *only* in z. - gks->flr_op = gkyl_deflated_fem_poisson_new(app->grid, app->basis_on_dev, app->basis, - app->local, app->local, gks->flr_rhoSqD2, gks->flr_kSq, flr_bc, NULL, app->use_gpu); - } - else { + gks->flr_op = gkyl_deflated_fem_poisson_new( + app->grid, app->basis_on_dev, app->basis, app->local, app->local, gks->flr_rhoSqD2, + gks->flr_kSq, flr_bc, NULL, app->use_gpu + ); + } else { gks->gyroaverage = gk_species_gyroaverage_disabled; gks->m0_gyroavg = gkyl_array_acquire(gks->m0.marr); gks->gyro_phi = gkyl_array_acquire(app->field->phi_smooth); } // Initialize the collisionless solver. - gks->collisionless = (struct gk_collisionless) { }; + gks->collisionless = (struct gk_collisionless){}; gk_species_collisionless_init(app, gks, &gks->collisionless); // Initialize an anomalous diffusion term. - gks->anom_diff = (struct gk_anomalous_diff) { }; + gks->anom_diff = (struct gk_anomalous_diff){}; gk_species_anomalous_diff_init(app, gks, &gks->anom_diff); // Damping term -nu*f on RHS. @@ -1619,34 +1742,42 @@ gk_species_init(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, st // Allocate data for diagnostic moments. int ndm = gks->info.num_diag_moments; gks->moms = gkyl_malloc(sizeof(struct gk_species_moment[ndm])); - for (int m=0; mmoms[m], gks->info.diag_moments[m], false); + } // Initialize projection routine for initial conditions. if (gks->info.init_from_file.type == 0) { gk_species_projection_init(app, gks, gks->info.projection, &gks->proj_init); - } - else { + } else { gk_species_file_import_init(app, gks, gks->info.init_from_file); } // Create skin/ghost ranges. - for (int dir=0; dirlocal_lower_skin[dir], &gks->local_lower_ghost[dir], - dir, GKYL_LOWER_EDGE, &gks->local_ext, ghost); - gkyl_skin_ghost_ranges(&gks->local_upper_skin[dir], &gks->local_upper_ghost[dir], - dir, GKYL_UPPER_EDGE, &gks->local_ext, ghost); - gkyl_skin_ghost_ranges(&gks->global_lower_skin[dir], &gks->global_lower_ghost[dir], - dir, GKYL_LOWER_EDGE, &gks->global_ext, ghost); - gkyl_skin_ghost_ranges(&gks->global_upper_skin[dir], &gks->global_upper_ghost[dir], - dir, GKYL_UPPER_EDGE, &gks->global_ext, ghost); + for (int dir = 0; dir < cdim; ++dir) { + gkyl_skin_ghost_ranges( + &gks->local_lower_skin[dir], &gks->local_lower_ghost[dir], dir, GKYL_LOWER_EDGE, + &gks->local_ext, ghost + ); + gkyl_skin_ghost_ranges( + &gks->local_upper_skin[dir], &gks->local_upper_ghost[dir], dir, GKYL_UPPER_EDGE, + &gks->local_ext, ghost + ); + gkyl_skin_ghost_ranges( + &gks->global_lower_skin[dir], &gks->global_lower_ghost[dir], dir, GKYL_LOWER_EDGE, + &gks->global_ext, ghost + ); + gkyl_skin_ghost_ranges( + &gks->global_upper_skin[dir], &gks->global_upper_ghost[dir], dir, GKYL_UPPER_EDGE, + &gks->global_ext, ghost + ); } // Create a local range extended in the BC dir (for TS BCs). - int par_dir = app->cdim-1; + int par_dir = app->cdim - 1; int ndim = gks->local.ndim; int lower_bcdir_ext[ndim], upper_bcdir_ext[ndim]; - for (int i=0; ilocal.lower[i]; upper_bcdir_ext[i] = gks->local.upper[i]; } @@ -1659,49 +1790,48 @@ gk_species_init(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, st int idx_LCFS_lo = app->gk_geom->idx_LCFS_lo; // Length of lower and upper x ranges (one is core, the other SOL). int len_lo = idx_LCFS_lo; - int len_up = gks->global.upper[0]-len_lo; + int len_up = gks->global.upper[0] - len_lo; // Lower and upper x ranges. struct gkyl_range *global_lo_r, *global_ext_lo_r, *global_up_r, *global_ext_up_r; struct gkyl_range *local_lo_r, *local_ext_lo_r, *local_up_r, *local_ext_up_r; struct gkyl_range *local_lower_skin_par_lo_r, *local_upper_skin_par_lo_r, - *local_lower_ghost_par_lo_r, *local_upper_ghost_par_lo_r; + *local_lower_ghost_par_lo_r, *local_upper_ghost_par_lo_r; struct gkyl_range *local_lower_skin_par_up_r, *local_upper_skin_par_up_r, - *local_lower_ghost_par_up_r, *local_upper_ghost_par_up_r; + *local_lower_ghost_par_up_r, *local_upper_ghost_par_up_r; if (app->gk_geom->geqdsk_sign_convention == 0) { // x increases towards SOL. - global_lo_r = &gks->global_core; - global_up_r = &gks->global_sol; - global_ext_lo_r = &gks->global_ext_core; - global_ext_up_r = &gks->global_ext_sol; - local_lo_r = &gks->local_core; - local_up_r = &gks->local_sol; - local_ext_lo_r = &gks->local_ext_core; - local_ext_up_r = &gks->local_ext_sol; - local_lower_skin_par_lo_r = &gks->local_lower_skin_par_core; + global_lo_r = &gks->global_core; + global_up_r = &gks->global_sol; + global_ext_lo_r = &gks->global_ext_core; + global_ext_up_r = &gks->global_ext_sol; + local_lo_r = &gks->local_core; + local_up_r = &gks->local_sol; + local_ext_lo_r = &gks->local_ext_core; + local_ext_up_r = &gks->local_ext_sol; + local_lower_skin_par_lo_r = &gks->local_lower_skin_par_core; local_lower_ghost_par_lo_r = &gks->local_lower_ghost_par_core; - local_lower_skin_par_up_r = &gks->local_lower_skin_par_sol; + local_lower_skin_par_up_r = &gks->local_lower_skin_par_sol; local_lower_ghost_par_up_r = &gks->local_lower_ghost_par_sol; - local_upper_skin_par_lo_r = &gks->local_upper_skin_par_core; + local_upper_skin_par_lo_r = &gks->local_upper_skin_par_core; local_upper_ghost_par_lo_r = &gks->local_upper_ghost_par_core; - local_upper_skin_par_up_r = &gks->local_upper_skin_par_sol; + local_upper_skin_par_up_r = &gks->local_upper_skin_par_sol; local_upper_ghost_par_up_r = &gks->local_upper_ghost_par_sol; - } - else { + } else { // x increases towards core. - global_lo_r = &gks->global_sol; - global_ext_lo_r = &gks->global_ext_sol; - global_up_r = &gks->global_core; - global_ext_up_r = &gks->global_ext_core; - local_lo_r = &gks->local_sol; - local_up_r = &gks->local_core; - local_ext_lo_r = &gks->local_ext_sol; - local_ext_up_r = &gks->local_ext_core; - local_lower_skin_par_lo_r = &gks->local_lower_skin_par_sol; - local_upper_skin_par_lo_r = &gks->local_upper_skin_par_sol; + global_lo_r = &gks->global_sol; + global_ext_lo_r = &gks->global_ext_sol; + global_up_r = &gks->global_core; + global_ext_up_r = &gks->global_ext_core; + local_lo_r = &gks->local_sol; + local_up_r = &gks->local_core; + local_ext_lo_r = &gks->local_ext_sol; + local_ext_up_r = &gks->local_ext_core; + local_lower_skin_par_lo_r = &gks->local_lower_skin_par_sol; + local_upper_skin_par_lo_r = &gks->local_upper_skin_par_sol; local_lower_ghost_par_lo_r = &gks->local_lower_ghost_par_sol; local_upper_ghost_par_lo_r = &gks->local_upper_ghost_par_sol; - local_lower_skin_par_up_r = &gks->local_lower_skin_par_core; - local_upper_skin_par_up_r = &gks->local_upper_skin_par_core; + local_lower_skin_par_up_r = &gks->local_lower_skin_par_core; + local_upper_skin_par_up_r = &gks->local_upper_skin_par_core; local_lower_ghost_par_up_r = &gks->local_lower_ghost_par_core; local_upper_ghost_par_up_r = &gks->local_upper_ghost_par_core; } @@ -1713,46 +1843,56 @@ gk_species_init(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, st gkyl_range_shorten_from_below(local_up_r, &gks->local, 0, len_up); // Extended lower and upper x ranges. - int len_lo_ext = idx_LCFS_lo+1; - int len_up_ext = gks->global_ext.upper[0]-len_lo; + int len_lo_ext = idx_LCFS_lo + 1; + int len_up_ext = gks->global_ext.upper[0] - len_lo; gkyl_range_shorten_from_above(global_ext_lo_r, &gks->global_ext, 0, len_lo_ext); gkyl_range_shorten_from_below(global_ext_up_r, &gks->global_ext, 0, len_up_ext); gkyl_range_shorten_from_above(local_ext_lo_r, &gks->local_ext, 0, len_lo_ext); gkyl_range_shorten_from_below(local_ext_up_r, &gks->local_ext, 0, len_up_ext); // Parallel skin and ghost ranges, limited to the lower and upper x range. - int par_dir = app->cdim-1; - for (int e=0; e<2; e++) { - gkyl_range_shorten_from_above(e==0? local_lower_skin_par_lo_r : local_upper_skin_par_lo_r, - e==0? &gks->local_lower_skin[par_dir] : &gks->local_upper_skin[par_dir], 0, len_lo); - gkyl_range_shorten_from_above(e==0? local_lower_ghost_par_lo_r : local_upper_ghost_par_lo_r, - e==0? &gks->local_lower_ghost[par_dir] : &gks->local_upper_ghost[par_dir], 0, len_lo); - gkyl_range_shorten_from_below(e==0? local_lower_skin_par_up_r : local_upper_skin_par_up_r, - e==0? &gks->local_lower_skin[par_dir] : &gks->local_upper_skin[par_dir], 0, len_up); - gkyl_range_shorten_from_below(e==0? local_lower_ghost_par_up_r : local_upper_ghost_par_up_r, - e==0? &gks->local_lower_ghost[par_dir] : &gks->local_upper_ghost[par_dir], 0, len_up); + int par_dir = app->cdim - 1; + for (int e = 0; e < 2; e++) { + gkyl_range_shorten_from_above( + e == 0 ? local_lower_skin_par_lo_r : local_upper_skin_par_lo_r, + e == 0 ? &gks->local_lower_skin[par_dir] : &gks->local_upper_skin[par_dir], 0, len_lo + ); + gkyl_range_shorten_from_above( + e == 0 ? local_lower_ghost_par_lo_r : local_upper_ghost_par_lo_r, + e == 0 ? &gks->local_lower_ghost[par_dir] : &gks->local_upper_ghost[par_dir], 0, len_lo + ); + gkyl_range_shorten_from_below( + e == 0 ? local_lower_skin_par_up_r : local_upper_skin_par_up_r, + e == 0 ? &gks->local_lower_skin[par_dir] : &gks->local_upper_skin[par_dir], 0, len_up + ); + gkyl_range_shorten_from_below( + e == 0 ? local_lower_ghost_par_up_r : local_upper_ghost_par_up_r, + e == 0 ? &gks->local_lower_ghost[par_dir] : &gks->local_upper_ghost[par_dir], 0, len_up + ); } // Core range extended in the parallel direction. int ndim = gks->local.ndim; int lower_bcdir_ext[ndim], upper_bcdir_ext[ndim]; - for (int i=0; ilocal_core.lower[i]; upper_bcdir_ext[i] = gks->local_core.upper[i]; } lower_bcdir_ext[par_dir] = gks->local_ext_core.lower[par_dir]; upper_bcdir_ext[par_dir] = gks->local_ext_core.upper[par_dir]; - gkyl_sub_range_init(&gks->local_par_ext_core, &gks->local_ext_core, lower_bcdir_ext, upper_bcdir_ext); + gkyl_sub_range_init( + &gks->local_par_ext_core, &gks->local_ext_core, lower_bcdir_ext, upper_bcdir_ext + ); } // Initialize boundary fluxes. - gks->bflux = (struct gk_boundary_fluxes) { }; + gks->bflux = (struct gk_boundary_fluxes){}; // Additional bflux moments to step in time. - struct gkyl_phase_diagnostics_inp add_bflux_moms_inp = (struct gkyl_phase_diagnostics_inp) { }; + struct gkyl_phase_diagnostics_inp add_bflux_moms_inp = (struct gkyl_phase_diagnostics_inp){}; enum gkyl_species_bflux_type bflux_type = GK_SPECIES_BFLUX_NONE; // Check if using Boltzmann elc. - bool ion_in_boltz_elc_field = (gks->info.charge > 0.0) && - app->field->update_field && (app->field->gkfield_id == GKYL_GK_FIELD_BOLTZMANN); + bool ion_in_boltz_elc_field = (gks->info.charge > 0.0) && app->field->update_field && + (app->field->gkfield_id == GKYL_GK_FIELD_BOLTZMANN); // Check if sources are adaptive. bool adaptive_sources = gk_species_do_I_adapt_src(app, gks); // Check if other species use the recycle_react_scale operation. @@ -1762,13 +1902,12 @@ gk_species_init(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, st if (gks->info.boundary_flux_diagnostics.num_diag_moments > 0 || gks->info.boundary_flux_diagnostics.num_integrated_diag_moments > 0) { bflux_type = GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS_DIAGS; - } - else { - // Set bflux_type to + } else { + // Set bflux_type to // - GK_SPECIES_BFLUX_CALC_FLUX to only put bfluxes in ghost cells of rhs. // - GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS to calc bfluxes and step its moments. // The latter also requires that you place the moment you desire in add_bflux_moms_inp below. - + if (recycling_bcs) { bflux_type = GK_SPECIES_BFLUX_CALC_FLUX; } @@ -1787,75 +1926,73 @@ gk_species_init(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app *app, st } // Introduce new moments into moms_inp if needed. gk_species_bflux_init(app, gks, &gks->bflux, bflux_type, add_bflux_moms_inp); - + // Initialize empty structs. New methods will fill them if specified. - gks->src = (struct gk_source) { }; - gks->rad = (struct gk_rad_drag) { }; + gks->src = (struct gk_source){}; + gks->rad = (struct gk_rad_drag){}; // Initialize a Maxwellian/LTE (local thermodynamic equilibrium) projection routine // Projection routine optionally corrects all the Maxwellian/LTE moments // This routine is utilized by both reactions and BGK collisions - gks->lte = (struct gk_lte) { }; + gks->lte = (struct gk_lte){}; bool correct_all_moms = gks->info.correct.correct_all_moms; int max_iter = gks->info.correct.max_iter > 0 ? gks->info.correct.max_iter : 50; double iter_eps = gks->info.correct.iter_eps > 0 ? gks->info.correct.iter_eps : 1e-10; bool use_last_converged = gks->info.correct.use_last_converged; struct correct_all_moms_inp corr_inp = { - .correct_all_moms = correct_all_moms, + .correct_all_moms = correct_all_moms, .max_iter = max_iter, - .iter_eps = iter_eps, + .iter_eps = iter_eps, .use_last_converged = use_last_converged }; gk_species_lte_init(app, gks, &gks->lte, corr_inp); // Initialize the object that scales the species (meant for fluid neutrals for now). - gks->sca = (struct gk_scaling) { }; + gks->sca = (struct gk_scaling){}; gk_species_scaling_init(app, gks, &gks->sca); // Initialize reactions with charged species. - gks->react = (struct gk_react) { }; + gks->react = (struct gk_react){}; gk_species_react_init(app, gks, gks->info.react, &gks->react, true); // Initialize reactions with neutral species. - gks->react_neut = (struct gk_react) { }; + gks->react_neut = (struct gk_react){}; gk_species_react_init(app, gks, gks->info.react_neut, &gks->react_neut, false); // Initialize LBO collisions. - gks->lbo = (struct gk_lbo_collisions) { }; + gks->lbo = (struct gk_lbo_collisions){}; gk_species_lbo_init(app, gks, &gks->lbo); // Initialize BGK collisions. - gks->bgk = (struct gk_bgk_collisions) { }; + gks->bgk = (struct gk_bgk_collisions){}; gk_species_bgk_init(app, gks, &gks->bgk); // Initialize a BGK source. - gks->bgk_src = (struct gk_source_bgk) { }; + gks->bgk_src = (struct gk_source_bgk){}; gk_species_source_bgk_init(app, gks, &gks->bgk_src); // Initialize positivity enforcing operator. - gks->positivity = (struct gk_positivity) { }; + gks->positivity = (struct gk_positivity){}; gk_species_positivity_init(app, gks, &gks->positivity); if (gks->info.is_static) { gk_species_init_static(gk_app_inp, app, gks); - } - else { + } else { gk_species_init_dynamic(gk_app_inp, app, gks); } } -void -gk_species_apply_ic(gkyl_gyrokinetic_app *app, struct gk_species *gks, double t0) +void gk_species_apply_ic(gkyl_gyrokinetic_app *app, struct gk_species *gks, double t0) { - if (gks->info.init_from_file.type == 0) + if (gks->info.init_from_file.type == 0) { gk_species_projection_calc(app, gks, &gks->proj_init, gks->f, t0); + } // We are pre-computing source for now as it is time-independent. gk_species_source_calc(app, gks, &gks->src, gks->lte.f_lte, t0); } -void -gk_species_apply_ic_cross(gkyl_gyrokinetic_app *app, struct gk_species *gks_self, double t0) +void gk_species_apply_ic_cross(gkyl_gyrokinetic_app *app, struct gk_species *gks_self, double t0) { // IC setup step that depends on the IC of other species. if (app->field->init_phi_pol && gks_self->info.scale_with_polarization) { @@ -1865,29 +2002,36 @@ gk_species_apply_ic_cross(gkyl_gyrokinetic_app *app, struct gk_species *gks_self // Compute the polarization density. struct gkyl_array *npol = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - struct gkyl_gyrokinetic_pol_density* npol_op = gkyl_gyrokinetic_pol_density_new(app->basis, app->grid, app->use_gpu); - gkyl_gyrokinetic_pol_density_advance(npol_op, &app->local, app->field->epsilon, app->field->phi_pol, npol); + struct gkyl_gyrokinetic_pol_density *npol_op = + gkyl_gyrokinetic_pol_density_new(app->basis, app->grid, app->use_gpu); + gkyl_gyrokinetic_pol_density_advance( + npol_op, &app->local, app->field->epsilon, app->field->phi_pol, npol + ); gkyl_gyrokinetic_pol_density_release(npol_op); // Calculate the guiding center density of this species: (npol - q_other*n^G_other)/q_self. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gks = &app->species[i]; gk_species_moment_calc(&gks->m0, gks->local, app->local, gks->f); if (strcmp(gks->info.name, gks_self->info.name)) { gkyl_array_accumulate(npol, -gks->info.charge, gks->m0.marr); } } - gkyl_array_scale(npol, 1./gks_self->info.charge); + gkyl_array_scale(npol, 1. / gks_self->info.charge); // Scale the distribution function so it has this guiding center density. - struct gkyl_dg_bin_op_mem *div_mem = app->use_gpu? gkyl_dg_bin_op_mem_cu_dev_new(app->local.volume, app->basis.num_basis) - : gkyl_dg_bin_op_mem_new(app->local.volume, app->basis.num_basis); + struct gkyl_dg_bin_op_mem *div_mem = + app->use_gpu ? gkyl_dg_bin_op_mem_cu_dev_new(app->local.volume, app->basis.num_basis) : + gkyl_dg_bin_op_mem_new(app->local.volume, app->basis.num_basis); struct gkyl_array *den_mod = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - gkyl_dg_div_op_range(div_mem, &app->basis, - 0, den_mod, 0, npol, 0, gks_self->m0.marr, &app->local); - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gks_self->basis, gks_self->f, - den_mod, gks_self->f, &app->local_ext, &gks_self->local_ext); + gkyl_dg_div_op_range( + div_mem, &app->basis, 0, den_mod, 0, npol, 0, gks_self->m0.marr, &app->local + ); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gks_self->basis, gks_self->f, den_mod, gks_self->f, &app->local_ext, + &gks_self->local_ext + ); gkyl_array_release(den_mod); gkyl_dg_bin_op_mem_release(div_mem); @@ -1898,102 +2042,98 @@ gk_species_apply_ic_cross(gkyl_gyrokinetic_app *app, struct gk_species *gks_self gk_species_scaling_apply_ic_cross(app, gks_self, &gks_self->sca); } -double -gk_species_rhs(gkyl_gyrokinetic_app *app, struct gk_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +double gk_species_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms +) { return species->rhs_func(app, species, fin, rhs, bflux_moms); } -double -gk_species_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt) +double gk_species_rhs_implicit( + gkyl_gyrokinetic_app *app, struct gk_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt +) { return species->rhs_implicit_func(app, species, fin, rhs, bflux_moms, dt); } -void -gk_species_step_f(struct gk_species *species, struct gkyl_array* out, double a, - const struct gkyl_array* inp) +void gk_species_step_f( + struct gk_species *species, struct gkyl_array *out, double a, const struct gkyl_array *inp +) { species->step_f_func(out, a, inp); } -void -gk_species_combine(struct gk_species *species, struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng) +void gk_species_combine( + struct gk_species *species, struct gkyl_array *out, double c1, const struct gkyl_array *arr1, + double c2, const struct gkyl_array *arr2, const struct gkyl_range *rng +) { species->combine_func(out, c1, arr1, c2, arr2, rng); } -void -gk_species_copy_range(struct gk_species *species, struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range) +void gk_species_copy_range( + struct gk_species *species, struct gkyl_array *out, const struct gkyl_array *inp, + const struct gkyl_range *range +) { species->copy_func(out, inp, range); } -void -gk_species_apply_bc(gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f) +void gk_species_apply_bc( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f +) { species->bc_func(app, species, f); } -void -gk_species_n_iter_corr(gkyl_gyrokinetic_app *app, const struct gk_species *s, int sidx) +void gk_species_n_iter_corr(gkyl_gyrokinetic_app *app, const struct gk_species *s, int sidx) { app->stat.num_corr[sidx] = s->lte.num_corr; app->stat.n_iter_corr[sidx] = s->lte.n_iter; } // write functions -void -gk_species_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_write(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { if (frame == 0) { gk_species_write_dynamic(app, gks, tm, frame); - } - else + } else { gks->write_func(app, gks, tm, frame); + } } -void -gk_species_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_write_mom(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { if (frame == 0) { gk_species_write_mom_dynamic(app, gks, tm, frame); - } - else + } else { gks->write_mom_func(app, gks, tm, frame); + } } -void -gk_species_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +void gk_species_calc_integrated_mom(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm) { gks->calc_integrated_mom_func(app, gks, tm); } -void -gk_species_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks) +void gk_species_write_integrated_mom(gkyl_gyrokinetic_app *app, struct gk_species *gks) { gks->write_integrated_mom_func(app, gks); } -void -gk_species_calc_L2norm(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +void gk_species_calc_L2norm(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm) { gks->calc_L2norm_func(app, gks, tm); } -void -gk_species_write_L2norm(gkyl_gyrokinetic_app* app, struct gk_species *gks) +void gk_species_write_L2norm(gkyl_gyrokinetic_app *app, struct gk_species *gks) { gks->write_L2norm_func(app, gks); } -void -gk_species_release(const gkyl_gyrokinetic_app* app, const struct gk_species *gks) +void gk_species_release(const gkyl_gyrokinetic_app *app, const struct gk_species *gks) { // Release resources for charged species. gkyl_array_release(gks->f); @@ -2007,7 +2147,7 @@ gk_species_release(const gkyl_gyrokinetic_app* app, const struct gk_species *gks gkyl_comm_release(gks->comm); gkyl_msgpack_map_elem_release(gks->io_meta_basic_len, gks->io_meta_basic); - gkyl_msgpack_map_elem_release(gks->io_meta_conf_len , gks->io_meta_conf ); + gkyl_msgpack_map_elem_release(gks->io_meta_conf_len, gks->io_meta_conf); gkyl_msgpack_map_elem_release(gks->io_meta_phase_len, gks->io_meta_phase); if (app->use_gpu) { @@ -2025,7 +2165,7 @@ gk_species_release(const gkyl_gyrokinetic_app* app, const struct gk_species *gks // Release moment data. gk_species_moment_release(app, &gks->m0); - for (int i=0; iinfo.num_diag_moments; ++i) { + for (int i = 0; i < gks->info.num_diag_moments; ++i) { gk_species_moment_release(app, &gks->moms[i]); } gkyl_free(gks->moms); @@ -2048,11 +2188,11 @@ gk_species_release(const gkyl_gyrokinetic_app* app, const struct gk_species *gks gk_species_react_release(app, &gks->react); - gk_species_react_release(app, &gks->react_neut); + gk_species_react_release(app, &gks->react_neut); // Free boundary flux memory. gk_species_bflux_release(app, gks, &gks->bflux); - + gk_species_lte_release(app, &gks->lte); gkyl_array_release(gks->m0_gyroavg); diff --git a/gyrokinetic/apps/gk_species_anomalous_diff.c b/gyrokinetic/apps/gk_species_anomalous_diff.c index 4f466d00de..63141c430e 100644 --- a/gyrokinetic/apps/gk_species_anomalous_diff.c +++ b/gyrokinetic/apps/gk_species_anomalous_diff.c @@ -1,94 +1,102 @@ #include #include -static void -gk_species_anomalous_diff_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_anomalous_diff *gkad, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_species_anomalous_diff_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_anomalous_diff *gkad, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { } -static void -gk_species_anomalous_diff_rhs_enabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_anomalous_diff *gkad, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_species_anomalous_diff_rhs_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_anomalous_diff *gkad, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - gkyl_dg_updater_gk_anomalous_diffusion_advance(gkad->slvr, &species->local, - fin, species->cflrate, rhs); + gkyl_dg_updater_gk_anomalous_diffusion_advance( + gkad->slvr, &species->local, fin, species->cflrate, rhs + ); app->stat.species_diffusion_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_anomalous_diff_write_diags_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_anomalous_diff *gkad, double tm, int frame) +static void gk_species_anomalous_diff_write_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_anomalous_diff *gkad, double tm, + int frame +) { } -static void -gk_species_anomalous_diff_write_diags_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_anomalous_diff *gkad, double tm, int frame) +static void gk_species_anomalous_diff_write_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_anomalous_diff *gkad, double tm, + int frame +) { struct timespec wst = gkyl_wall_clock(); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_anomalous_diff_write_conf_array(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_anomalous_diff *gkad, int frame, double stime, char* file_suffix, char* description, - struct gkyl_array *arrout, struct gkyl_array *arrout_host) +static void gk_anomalous_diff_write_conf_array( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_anomalous_diff *gkad, int frame, + double stime, char *file_suffix, char *description, struct gkyl_array *arrout, + struct gkyl_array *arrout_host +) { // Write out a conf-space array. - + // Package metadata. gkyl_msgpack_map_elem_set_double(gks->io_meta_conf_len, gks->io_meta_conf, "time", stime); gkyl_msgpack_map_elem_set_uint(gks->io_meta_conf_len, gks->io_meta_conf, "frame", frame); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = description } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = description} }; int io_meta_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); // Construct the file handles for collision frequency and primitive moments. const char *fmt = "%s-%s_%s_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, file_suffix, frame); - char fileNm[sz+1]; // Ensures no buffer overflow. + char fileNm[sz + 1]; // Ensures no buffer overflow. snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, file_suffix, frame); struct gkyl_array *arr_ho; - if (app->use_gpu) { - if (arrout_host) + if (app->use_gpu) { + if (arrout_host) { arr_ho = gkyl_array_acquire(arrout_host); - else { + } else { arr_ho = mkarr(false, arrout->ncomp, arrout->size); } // Copy data from device to host before writing it out. gkyl_array_copy(arr_ho, arrout); - } - else { - if (arrout_host) + } else { + if (arrout_host) { arr_ho = gkyl_array_acquire(arrout_host); - else + } else { arr_ho = gkyl_array_acquire(arrout); + } } gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, arr_ho, fileNm); - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); gkyl_array_release(arr_ho); } -static void -eval_on_nodes_c2p_position_func(const double *xcomp, double *xphys, void *ctx) +static void eval_on_nodes_c2p_position_func(const double *xcomp, double *xphys, void *ctx) { struct gkyl_position_map *gpm = ctx; gkyl_position_map_eval_mc2nu(gpm, xcomp, xphys); } -void -gk_species_anomalous_diff_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_anomalous_diff *gkad) +void gk_species_anomalous_diff_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_anomalous_diff *gkad +) { gkad->anom_diff_id = gks->info.anomalous_diffusion.anomalous_diff_id; gkad->write_diagnostics = gks->info.anomalous_diffusion.write_diagnostics; @@ -97,20 +105,19 @@ gk_species_anomalous_diff_init(struct gkyl_gyrokinetic_app *app, struct gk_speci gkad->rhs_func = gk_species_anomalous_diff_rhs_disabled; if (gkad->anom_diff_id) { - // Project the diffusivity. gkad->diffD = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - struct gkyl_array *diffD_ho = app->use_gpu? mkarr(false, gkad->diffD->ncomp, gkad->diffD->size) - : gkyl_array_acquire(gkad->diffD); - struct gkyl_eval_on_nodes *diffDproj = gkyl_eval_on_nodes_inew( &(struct gkyl_eval_on_nodes_inp){ - .grid = &app->grid, + struct gkyl_array *diffD_ho = app->use_gpu ? + mkarr(false, gkad->diffD->ncomp, gkad->diffD->size) : + gkyl_array_acquire(gkad->diffD); + struct gkyl_eval_on_nodes *diffDproj = gkyl_eval_on_nodes_inew(&(struct gkyl_eval_on_nodes_inp + ){.grid = &app->grid, .basis = &app->basis, .num_ret_vals = 1, .eval = gks->info.anomalous_diffusion.D_profile, .ctx = gks->info.anomalous_diffusion.D_profile_ctx, .c2p_func = eval_on_nodes_c2p_position_func, - .c2p_func_ctx = app->position_map, - }); + .c2p_func_ctx = app->position_map}); gkyl_eval_on_nodes_advance(diffDproj, 0.0, &app->local, diffD_ho); gkyl_array_copy(gkad->diffD, diffD_ho); @@ -122,26 +129,33 @@ gk_species_anomalous_diff_init(struct gkyl_gyrokinetic_app *app, struct gk_speci // Sync diffusivity. int num_periodic_dir = app->num_periodic_dir; - gkyl_comm_array_per_sync(app->comm, &app->local, &app->local_ext, - num_periodic_dir, app->periodic_dirs, gkad->diffD); + gkyl_comm_array_per_sync( + app->comm, &app->local, &app->local_ext, num_periodic_dir, app->periodic_dirs, gkad->diffD + ); // ABSORB and FIXED_FUNC BCs need to fill the ghost cell. MF 2025/11/03: The // only sensible way to fill the ghost cell is to use the value at the // boundary. - for (int b=0; b<2; ++b) { - if ((b == 0 && ((gks->lower_bc[0].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) || (gks->lower_bc[0].type == GKYL_BC_GK_SPECIES_ABSORB))) || - (b == 1 && ((gks->upper_bc[0].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) || (gks->upper_bc[0].type == GKYL_BC_GK_SPECIES_ABSORB))) ) { + for (int b = 0; b < 2; ++b) { + if ((b == 0 && ((gks->lower_bc[0].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) || + (gks->lower_bc[0].type == GKYL_BC_GK_SPECIES_ABSORB))) || + (b == 1 && ((gks->upper_bc[0].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) || + (gks->upper_bc[0].type == GKYL_BC_GK_SPECIES_ABSORB)))) { int dir = 0; - enum gkyl_edge_loc edge = b==0? GKYL_LOWER_EDGE : GKYL_UPPER_EDGE; - struct gkyl_range *skin_r = b==0? &app->local_lower_skin[dir] : &app->local_upper_skin[dir]; - struct gkyl_range *ghost_r = b==0? &app->local_lower_ghost[dir] : &app->local_upper_ghost[dir]; + enum gkyl_edge_loc edge = b == 0 ? GKYL_LOWER_EDGE : GKYL_UPPER_EDGE; + struct gkyl_range *skin_r = b == 0 ? &app->local_lower_skin[dir] : + &app->local_upper_skin[dir]; + struct gkyl_range *ghost_r = b == 0 ? &app->local_lower_ghost[dir] : + &app->local_upper_ghost[dir]; long vol = skin_r->volume; long buff_sz = 1; buff_sz = buff_sz > vol ? buff_sz : vol; struct gkyl_array *bc_buffer = mkarr(app->use_gpu, app->basis.num_basis, buff_sz); - struct gkyl_bc_basic_gyrokinetic *gfss_bc_op = gkyl_bc_basic_gyrokinetic_new(dir, edge, - GKYL_BC_GK_FIELD_BOUNDARY_VALUE, app->basis_on_dev, skin_r, ghost_r, app->basis.num_basis, app->cdim, app->use_gpu); + struct gkyl_bc_basic_gyrokinetic *gfss_bc_op = gkyl_bc_basic_gyrokinetic_new( + dir, edge, GKYL_BC_GK_FIELD_BOUNDARY_VALUE, app->basis_on_dev, skin_r, ghost_r, + app->basis.num_basis, app->cdim, app->use_gpu + ); gkyl_bc_basic_gyrokinetic_advance(gfss_bc_op, bc_buffer, gkad->diffD); gkyl_bc_basic_gyrokinetic_advance(gfss_bc_op, bc_buffer, app->gk_geom->geo_int.jacobgeo_inv); @@ -152,13 +166,16 @@ gk_species_anomalous_diff_init(struct gkyl_gyrokinetic_app *app, struct gk_speci gkyl_comm_array_sync(app->comm, &app->local, &app->local_ext, gkad->diffD); // Create solver. - gkad->slvr = gkyl_dg_updater_gk_anomalous_diffusion_new(&gks->grid, &gks->basis, &app->basis, - &app->local, gks->lower_bc[0].type, gks->upper_bc[0].type, - gkad->diffD, app->gk_geom->geo_int.jacobgeo_inv, app->use_gpu); + gkad->slvr = gkyl_dg_updater_gk_anomalous_diffusion_new( + &gks->grid, &gks->basis, &app->basis, &app->local, gks->lower_bc[0].type, + gks->upper_bc[0].type, gkad->diffD, app->gk_geom->geo_int.jacobgeo_inv, app->use_gpu + ); if (gkad->write_diagnostics) { // Write out the diffusivity. - gk_anomalous_diff_write_conf_array(app, gks, gkad, 0, 0.0, "anom_diff", "Anomalous diffusivity.", gkad->diffD, 0); + gk_anomalous_diff_write_conf_array( + app, gks, gkad, 0, 0.0, "anom_diff", "Anomalous diffusivity.", gkad->diffD, 0 + ); } // Methods chosen at runtime. @@ -169,29 +186,31 @@ gk_species_anomalous_diff_init(struct gkyl_gyrokinetic_app *app, struct gk_speci } } -void -gk_species_anomalous_diff_rhs(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_anomalous_diff *gkad, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_species_anomalous_diff_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_anomalous_diff *gkad, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { gkad->rhs_func(app, species, gkad, fin, rhs); } -void -gk_species_anomalous_diff_write_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_anomalous_diff *gkad, double tm, int frame) +void gk_species_anomalous_diff_write_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_anomalous_diff *gkad, double tm, + int frame +) { gkad->write_diags_func(app, gks, gkad, tm, frame); } -void -gk_species_anomalous_diff_release(const struct gkyl_gyrokinetic_app *app, const struct gk_anomalous_diff *gkad) +void gk_species_anomalous_diff_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_anomalous_diff *gkad +) { if (gkad->anom_diff_id) { - gkyl_array_release(gkad->diffD); gkyl_dg_updater_gk_anomalous_diffusion_release(gkad->slvr); -// if (gkad->write_diagnostics) { -// } + // if (gkad->write_diagnostics) { + // } } } diff --git a/gyrokinetic/apps/gk_species_bflux.c b/gyrokinetic/apps/gk_species_bflux.c index 689ecb4320..b22157f451 100644 --- a/gyrokinetic/apps/gk_species_bflux.c +++ b/gyrokinetic/apps/gk_species_bflux.c @@ -6,419 +6,508 @@ static int gk_species_bflux_boundary_idx(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge) { // Given a direction 'dir' and an edge 'edge' return the boundary index. - for (int b=0; bnum_boundaries; ++b) { - if (dir == bflux->boundaries_dir[b] && edge == bflux->boundaries_edge[b]) + for (int b = 0; b < bflux->num_boundaries; ++b) { + if (dir == bflux->boundaries_dir[b] && edge == bflux->boundaries_edge[b]) { return b; + } } assert(false); return -1; } -static int -gk_species_bflux_mom_idx(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - enum gkyl_distribution_moments mom_type) +static int gk_species_bflux_mom_idx( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, + enum gkyl_distribution_moments mom_type +) { // Given a direction 'dir', the edge 'edge', and the name of a moment // `mom_type, return the moment index index. int b = gk_species_bflux_boundary_idx(bflux, dir, edge); int mom_idx = -1; - for (int m=0; mnum_calc_moms; m++) { + for (int m = 0; m < bflux->num_calc_moms; m++) { if (bflux->calc_mom_names[m] == mom_type) { mom_idx = m; break; } } assert(mom_idx > -1); - return b*bflux->num_calc_moms+mom_idx; + return b * bflux->num_calc_moms + mom_idx; } -static void -gk_species_bflux_clear_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +static void gk_species_bflux_clear_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_clear_range(fin[b*bflux->num_calc_moms+m], val, bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_clear_range( + fin[b * bflux->num_calc_moms + m], val, bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_species_bflux_clear_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +static void gk_species_bflux_clear_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { } -void -gk_species_bflux_clear(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +void gk_species_bflux_clear( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { bflux->bflux_clear_func(app, bflux, fin, val); } -static void -gk_species_bflux_scale_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +static void gk_species_bflux_scale_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_scale_range(fin[b*bflux->num_calc_moms+m], val, bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_scale_range( + fin[b * bflux->num_calc_moms + m], val, bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_species_bflux_scale_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +static void gk_species_bflux_scale_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { } -void -gk_species_bflux_scale(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fin, double val) +void gk_species_bflux_scale( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val +) { bflux->bflux_scale_func(app, bflux, fin, val); } -static void -gk_species_bflux_step_f_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double dt, struct gkyl_array **fin) +static void gk_species_bflux_step_f_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double dt, + struct gkyl_array **fin +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_accumulate_range(gkyl_array_scale_range(fout[b*bflux->num_calc_moms+m], dt, bflux->boundaries_conf_ghost[b]), - 1.0, fin[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_accumulate_range( + gkyl_array_scale_range( + fout[b * bflux->num_calc_moms + m], dt, bflux->boundaries_conf_ghost[b] + ), + 1.0, fin[b * bflux->num_calc_moms + m], bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_species_bflux_step_f_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double dt, struct gkyl_array **fin) +static void gk_species_bflux_step_f_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double dt, + struct gkyl_array **fin +) { // Do nothing. } -void -gk_species_bflux_step_f(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double dt, struct gkyl_array **fin) +void gk_species_bflux_step_f( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double dt, + struct gkyl_array **fin +) { bflux->bflux_step_f_func(app, bflux, fout, dt, fin); } -static void -gk_species_bflux_set_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +static void gk_species_bflux_set_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_set_range(fout[b*bflux->num_calc_moms+m], - fac, fin[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_set_range( + fout[b * bflux->num_calc_moms + m], fac, fin[b * bflux->num_calc_moms + m], + bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_species_bflux_set_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +static void gk_species_bflux_set_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { // Do nothing. } -void -gk_species_bflux_set(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +void gk_species_bflux_set( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { bflux->bflux_set_func(app, bflux, fout, fac, fin); } -static void -gk_species_bflux_accumulate_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +static void gk_species_bflux_accumulate_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_accumulate_range(fout[b*bflux->num_calc_moms+m], - fac, fin[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_accumulate_range( + fout[b * bflux->num_calc_moms + m], fac, fin[b * bflux->num_calc_moms + m], + bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_species_bflux_accumulate_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +static void gk_species_bflux_accumulate_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { // Do nothing. } -void -gk_species_bflux_accumulate(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac, struct gkyl_array **fin) +void gk_species_bflux_accumulate( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, double fac, + struct gkyl_array **fin +) { bflux->bflux_accumulate_func(app, bflux, fout, fac, fin); } -static void -gk_species_bflux_combine_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2) +static void gk_species_bflux_combine_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2 +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_accumulate_range(gkyl_array_set_range(fout[b*bflux->num_calc_moms+m], - fac1, fin1[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]), - fac2, fin2[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_accumulate_range( + gkyl_array_set_range( + fout[b * bflux->num_calc_moms + m], fac1, fin1[b * bflux->num_calc_moms + m], + bflux->boundaries_conf_ghost[b] + ), + fac2, fin2[b * bflux->num_calc_moms + m], bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_species_bflux_combine_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2) +static void gk_species_bflux_combine_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2 +) { // Do nothing. } -void -gk_species_bflux_combine(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2) +void gk_species_bflux_combine( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2 +) { bflux->bflux_combine_func(app, bflux, fout, fac1, fin1, fac2, fin2); } -static void -gk_species_bflux_copy_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, struct gkyl_array **fin) +static void gk_species_bflux_copy_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + struct gkyl_array **fin +) { - for (int b=0; bnum_boundaries; ++b) - for (int m=0; mnum_calc_moms; m++) - gkyl_array_copy_range(fout[b*bflux->num_calc_moms+m], fin[b*bflux->num_calc_moms+m], bflux->boundaries_conf_ghost[b]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_copy_range( + fout[b * bflux->num_calc_moms + m], fin[b * bflux->num_calc_moms + m], + bflux->boundaries_conf_ghost[b] + ); + } + } } -static void -gk_species_bflux_copy_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, struct gkyl_array **fin) +static void gk_species_bflux_copy_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + struct gkyl_array **fin +) { } -void -gk_species_bflux_copy(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, struct gkyl_array **fin) +void gk_species_bflux_copy( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + struct gkyl_array **fin +) { bflux->bflux_copy_func(app, bflux, fout, fin); } -void -gk_species_bflux_rhs_calc(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_species_bflux_rhs_calc( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *fin, + struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { // Ghost cells of the rhs array are filled with the bflux. This is overwritten // by the boundary conditions, but it is used before that happens. gkyl_array_clear_range(rhs, 0.0, bflux->boundaries_phase_ghost[b]); gkyl_boundary_flux_advance(bflux->flux_slvr[b], fin, rhs); - gkyl_array_copy_range_to_range(bflux->flux[b], rhs, &bflux->boundaries_phase_ghost_nosub[b], bflux->boundaries_phase_ghost[b]); + gkyl_array_copy_range_to_range( + bflux->flux[b], rhs, &bflux->boundaries_phase_ghost_nosub[b], bflux->boundaries_phase_ghost[b] + ); } app->stat.species_bflux_calc_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_bflux_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_species_bflux_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *fin, + struct gkyl_array *rhs +) { } -void -gk_species_bflux_rhs(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_species_bflux_rhs( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *fin, + struct gkyl_array *rhs +) { bflux->bflux_rhs_func(app, bflux, fin, rhs); } -static void -gk_species_bflux_calc_moms_enabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +static void gk_species_bflux_calc_moms_enabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *rhs, + struct gkyl_array **bflux_moms +) { // Compute moments of boundary fluxes. struct timespec wst = gkyl_wall_clock(); - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { if (bflux->a_hamiltonian_mom) { // Apply BC to phi so it is defined in the ghost cell. // Fill the ghost with the skin evaluated at the boundary. - gkyl_bc_basic_gyrokinetic_advance(bflux->gfss_bc_op[b], bflux->bc_buffer, app->field->phi_smooth); + gkyl_bc_basic_gyrokinetic_advance( + bflux->gfss_bc_op[b], bflux->bc_buffer, app->field->phi_smooth + ); } - for (int m=0; mnum_calc_moms; m++) { - gk_species_moment_calc(&bflux->moms_op[m], *bflux->boundaries_phase_ghost[b], *bflux->boundaries_conf_ghost[b], rhs); + for (int m = 0; m < bflux->num_calc_moms; m++) { + gk_species_moment_calc( + &bflux->moms_op[m], *bflux->boundaries_phase_ghost[b], *bflux->boundaries_conf_ghost[b], rhs + ); - gkyl_array_copy_range(bflux_moms[b*bflux->num_calc_moms+m], bflux->moms_op[m].marr, bflux->boundaries_conf_ghost[b]); + gkyl_array_copy_range( + bflux_moms[b * bflux->num_calc_moms + m], bflux->moms_op[m].marr, + bflux->boundaries_conf_ghost[b] + ); } } app->stat.species_bflux_moms_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_bflux_calc_moms_disabled(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +static void gk_species_bflux_calc_moms_disabled( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *rhs, + struct gkyl_array **bflux_moms +) { // Do nothing. } -void -gk_species_bflux_calc_moms(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *rhs, struct gkyl_array **bflux_moms) +void gk_species_bflux_calc_moms( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *rhs, + struct gkyl_array **bflux_moms +) { bflux->bflux_calc_moms_func(app, bflux, rhs, bflux_moms); } -static void -gk_species_bflux_get_flux_mom_enabled(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, const struct gkyl_range *out_rng) +static void gk_species_bflux_get_flux_mom_enabled( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, + enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { int b = gk_species_bflux_boundary_idx(bflux, dir, edge); int mom_idx = gk_species_bflux_mom_idx(bflux, dir, edge, mom_type); gkyl_array_copy_range_to_range(out, bflux_moms[mom_idx], out_rng, bflux->boundaries_conf_ghost[b]); } -static void -gk_species_bflux_get_flux_mom_disabled(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, const struct gkyl_range *out_rng) +static void gk_species_bflux_get_flux_mom_disabled( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, + enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { // Do nothing. } -void -gk_species_bflux_get_flux_mom(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, const struct gkyl_range *out_rng) +void gk_species_bflux_get_flux_mom( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, + enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { bflux->bflux_get_flux_mom_func(bflux, dir, edge, mom_type, bflux_moms, out, out_rng); } -static void -gk_species_bflux_get_flux_enabled(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - struct gkyl_array *out, const struct gkyl_range *out_rng) +static void gk_species_bflux_get_flux_enabled( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { int b = gk_species_bflux_boundary_idx(bflux, dir, edge); - gkyl_array_copy_range_to_range(out, bflux->flux[b], out_rng, &bflux->boundaries_phase_ghost_nosub[b]); + gkyl_array_copy_range_to_range( + out, bflux->flux[b], out_rng, &bflux->boundaries_phase_ghost_nosub[b] + ); } -static void -gk_species_bflux_get_flux_disabled(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - struct gkyl_array *out, const struct gkyl_range *out_rng) +static void gk_species_bflux_get_flux_disabled( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { } -void -gk_species_bflux_get_flux(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - struct gkyl_array *out, const struct gkyl_range *out_rng) +void gk_species_bflux_get_flux( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, struct gkyl_array *out, + const struct gkyl_range *out_rng +) { bflux->bflux_get_flux_func(bflux, dir, edge, out, out_rng); } -static void -gk_species_bflux_calc_integrated_mom_enabled(gkyl_gyrokinetic_app* app, - void *spec_in, struct gk_boundary_fluxes *bflux, double tm) +static void gk_species_bflux_calc_integrated_mom_enabled( + gkyl_gyrokinetic_app *app, void *spec_in, struct gk_boundary_fluxes *bflux, double tm +) { struct timespec wst = gkyl_wall_clock(); const struct gk_species *gk_s = spec_in; int num_diag_int_mom = gk_s->info.boundary_flux_diagnostics.num_integrated_diag_moments; - for (int m=0; mdiag_int_mom_idx[m]; - int num_mom_comp = bflux->moms_op[int_mom_idx].num_mom; + int num_mom_comp = bflux->moms_op[int_mom_idx].num_mom; double avals_global[num_mom_comp]; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { // Integrated moment of the boundary flux. int dir = bflux->boundaries_dir[b]; - gkyl_array_integrate_advance(bflux->integ_op[m], bflux->f[b*bflux->num_calc_moms+int_mom_idx], 1.0, 0, - bflux->boundaries_conf_ghost[b], 0, bflux->int_moms_local); - - gkyl_comm_allreduce(app->comm_plane[dir], GKYL_DOUBLE, GKYL_SUM, num_mom_comp, - bflux->int_moms_local, bflux->int_moms_global); + gkyl_array_integrate_advance( + bflux->integ_op[m], bflux->f[b * bflux->num_calc_moms + int_mom_idx], 1.0, 0, + bflux->boundaries_conf_ghost[b], 0, bflux->int_moms_local + ); + + gkyl_comm_allreduce( + app->comm_plane[dir], GKYL_DOUBLE, GKYL_SUM, num_mom_comp, bflux->int_moms_local, + bflux->int_moms_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp])); } - gkyl_dynvec_append(bflux->intmom[b*num_diag_int_mom+m], tm, avals_global); - - } - } + gkyl_dynvec_append(bflux->intmom[b * num_diag_int_mom + m], tm, avals_global); + } + } app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_bflux_calc_voltime_integrated_mom_enabled(gkyl_gyrokinetic_app* app, - void *spec_in, struct gk_boundary_fluxes *bflux, double tm) +static void gk_species_bflux_calc_voltime_integrated_mom_enabled( + gkyl_gyrokinetic_app *app, void *spec_in, struct gk_boundary_fluxes *bflux, double tm +) { const struct gk_species *gk_s = spec_in; int num_diag_int_mom = gk_s->info.boundary_flux_diagnostics.num_integrated_diag_moments; - for (int m=0; mdiag_int_mom_idx[m]; - int num_mom_comp = bflux->moms_op[int_mom_idx].num_mom; + int num_mom_comp = bflux->moms_op[int_mom_idx].num_mom; double avals_global[num_mom_comp]; double *intmom_cumm_buff = bflux->intmom_cumm_buff[m]; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { // Integrated moment of the boundary flux. int dir = bflux->boundaries_dir[b]; - gkyl_array_integrate_advance(bflux->integ_op[m], bflux->f[b*bflux->num_calc_moms+int_mom_idx], 1., 0, - bflux->boundaries_conf_ghost[b], 0, bflux->int_moms_local); - - gkyl_comm_allreduce(app->comm_plane[dir], GKYL_DOUBLE, GKYL_SUM, num_mom_comp, - bflux->int_moms_local, bflux->int_moms_global); + gkyl_array_integrate_advance( + bflux->integ_op[m], bflux->f[b * bflux->num_calc_moms + int_mom_idx], 1., 0, + bflux->boundaries_conf_ghost[b], 0, bflux->int_moms_local + ); + + gkyl_comm_allreduce( + app->comm_plane[dir], GKYL_DOUBLE, GKYL_SUM, num_mom_comp, bflux->int_moms_local, + bflux->int_moms_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, bflux->int_moms_global, sizeof(double[num_mom_comp])); } - for (int k=0; kbflux_calc_voltime_int_mom_func(app, species, bflux, tm); } -static void -gk_species_bflux_append_integrated_mom(gkyl_gyrokinetic_app* app, - void *spec_in, struct gk_boundary_fluxes *bflux, double tm) +static void gk_species_bflux_append_integrated_mom( + gkyl_gyrokinetic_app *app, void *spec_in, struct gk_boundary_fluxes *bflux, double tm +) { struct timespec wst = gkyl_wall_clock(); // Append the time integrated moment of the boundary flux. const struct gk_species *gk_s = spec_in; int num_diag_int_mom = gk_s->info.boundary_flux_diagnostics.num_integrated_diag_moments; - for (int m=0; mdiag_int_mom_idx[m]; int num_mom_comp = bflux->moms_op[int_mom_idx].num_mom; double *intmom_cumm_buff = bflux->intmom_cumm_buff[m]; - for (int b=0; bnum_boundaries; ++b) - gkyl_dynvec_append(bflux->intmom[b*num_diag_int_mom+m], tm, &intmom_cumm_buff[b*num_mom_comp]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + gkyl_dynvec_append( + bflux->intmom[b * num_diag_int_mom + m], tm, &intmom_cumm_buff[b * num_mom_comp] + ); + } } app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_bflux_calc_integrated_mom_disabled(gkyl_gyrokinetic_app* app, - void *spec_in, struct gk_boundary_fluxes *bflux, double tm) +static void gk_species_bflux_calc_integrated_mom_disabled( + gkyl_gyrokinetic_app *app, void *spec_in, struct gk_boundary_fluxes *bflux, double tm +) { } -void -gk_species_bflux_calc_integrated_mom(gkyl_gyrokinetic_app* app, - void *species, struct gk_boundary_fluxes *bflux, double tm) +void gk_species_bflux_calc_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm +) { bflux->bflux_calc_integrated_mom_func(app, species, bflux, tm); } - -static void -gk_species_bflux_write_integrated_mom_enabled(gkyl_gyrokinetic_app *app, - void *spec_in, struct gk_boundary_fluxes *bflux) + +static void gk_species_bflux_write_integrated_mom_enabled( + gkyl_gyrokinetic_app *app, void *spec_in, struct gk_boundary_fluxes *bflux +) { struct timespec wst = gkyl_wall_clock(); const struct gk_species *gks = spec_in; @@ -427,67 +516,75 @@ gk_species_bflux_write_integrated_mom_enabled(gkyl_gyrokinetic_app *app, gkyl_comm_get_rank(app->comm, &rank); gkyl_comm_get_size(app->comm, &comm_size); - const char *vars[] = {"x","y","z"}; - const char *edge[] = {"lower","upper"}; + const char *vars[] = {"x", "y", "z"}; + const char *edge[] = {"lower", "upper"}; int num_diag_int_mom = gks->info.boundary_flux_diagnostics.num_integrated_diag_moments; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; - int edi = bflux->boundaries_edge[b]==GKYL_LOWER_EDGE? 0 : 1; + int edi = bflux->boundaries_edge[b] == GKYL_LOWER_EDGE ? 0 : 1; - if ((edi == 0 && rank == 0) || (edi == 1 && rank == comm_size-1)) { - for (int m=0; minfo.boundary_flux_diagnostics.integrated_diag_moments[m]]; + const char *mom_name = gkyl_distribution_moments_strs[gks->info.boundary_flux_diagnostics + .integrated_diag_moments[m]]; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, vars[dir], edge[edi], mom_name); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, vars[dir], edge[edi], mom_name); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gks->info.name, vars[dir], edge[edi], mom_name + ); if (bflux->is_first_intmom_write_call[b]) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated moments of the boundary flux." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Volume integrated moments of the boundary flux."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); - - gkyl_dynvec_write_wmeta(bflux->intmom[b*num_diag_int_mom+m], fileNm, mt); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); + + gkyl_dynvec_write_wmeta(bflux->intmom[b * num_diag_int_mom + m], fileNm, mt); gkyl_msgpack_data_release(mt); - } - else { - gkyl_dynvec_awrite(bflux->intmom[b*num_diag_int_mom+m], fileNm); + } else { + gkyl_dynvec_awrite(bflux->intmom[b * num_diag_int_mom + m], fileNm); } app->stat.n_diag_io += 1; - gkyl_dynvec_clear(bflux->intmom[b*num_diag_int_mom+m]); - - if (bflux->is_first_intmom_write_call[b]) + gkyl_dynvec_clear(bflux->intmom[b * num_diag_int_mom + m]); + + if (bflux->is_first_intmom_write_call[b]) { bflux->is_first_intmom_write_call[b] = false; + } } } } app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_bflux_write_integrated_mom_disabled(gkyl_gyrokinetic_app *app, - void *species, struct gk_boundary_fluxes *bflux) +static void gk_species_bflux_write_integrated_mom_disabled( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux +) { } -void -gk_species_bflux_write_integrated_mom(gkyl_gyrokinetic_app *app, - void *species, struct gk_boundary_fluxes *bflux) +void gk_species_bflux_write_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux +) { bflux->bflux_write_integrated_mom_func(app, species, bflux); } -static void -gk_species_bflux_write_mom_enabled(gkyl_gyrokinetic_app* app, void *spec_in, - struct gk_boundary_fluxes *bflux, double tm, int frame) +static void gk_species_bflux_write_mom_enabled( + gkyl_gyrokinetic_app *app, void *spec_in, struct gk_boundary_fluxes *bflux, double tm, int frame +) { const struct gk_species *gks = spec_in; @@ -495,109 +592,129 @@ gk_species_bflux_write_mom_enabled(gkyl_gyrokinetic_app* app, void *spec_in, gkyl_msgpack_map_elem_set_double(gks->io_meta_conf_len, gks->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_conf_len, gks->io_meta_conf, "frame", frame); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Velocity-space moment of the boundary flux." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Velocity-space moment of the boundary flux."} }; int io_meta_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); int rank, comm_size; gkyl_comm_get_rank(app->comm, &rank); gkyl_comm_get_size(app->comm, &comm_size); - const char *vars[] = {"x","y","z"}; - const char *edge[] = {"lower","upper"}; + const char *vars[] = {"x", "y", "z"}; + const char *edge[] = {"lower", "upper"}; int num_diag_mom = gks->info.boundary_flux_diagnostics.num_diag_moments; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; - int edi = bflux->boundaries_edge[b]==GKYL_LOWER_EDGE? 0 : 1; + int edi = bflux->boundaries_edge[b] == GKYL_LOWER_EDGE ? 0 : 1; // MF 2025/05/22: Note that this if-statement assumes MPI decomposition only along z. - if (dir < app->cdim-1 || ((edi == 0 && rank == 0) || (edi == 1 && rank == comm_size-1))) { - for (int m=0; mcdim - 1 || ((edi == 0 && rank == 0) || (edi == 1 && rank == comm_size - 1))) { + for (int m = 0; m < num_diag_mom; ++m) { struct timespec wst = gkyl_wall_clock(); int mom_idx = bflux->diag_mom_idx[m]; - struct gkyl_array *mom_arr = bflux->f[b*bflux->num_calc_moms+mom_idx]; - + struct gkyl_array *mom_arr = bflux->f[b * bflux->num_calc_moms + mom_idx]; + // For now copy the moment to the skin ghost and write it out. - gkyl_array_copy_range_to_range(mom_arr, mom_arr, - bflux->boundaries_conf_skin[b], bflux->boundaries_conf_ghost[b]); + gkyl_array_copy_range_to_range( + mom_arr, mom_arr, bflux->boundaries_conf_skin[b], bflux->boundaries_conf_ghost[b] + ); // Rescale by dx/2 in the direction of the boundary to account for the // normalization in the boundary surf kernels. - gkyl_array_scale_range(mom_arr, 0.5*app->grid.dx[dir], bflux->boundaries_conf_skin[b]); + gkyl_array_scale_range(mom_arr, 0.5 * app->grid.dx[dir], bflux->boundaries_conf_skin[b]); app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); - + const char *fmt = "%s-%s_bflux_%s%s_%s_%d.gkyl"; - const char *mom_name = gkyl_distribution_moments_strs[gks->info.boundary_flux_diagnostics.diag_moments[mom_idx]]; - int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, vars[dir], edge[edi], mom_name, frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, vars[dir], edge[edi], mom_name, frame); - + const char *mom_name = + gkyl_distribution_moments_strs[gks->info.boundary_flux_diagnostics.diag_moments[mom_idx]]; + int sz = + gkyl_calc_strlen(fmt, app->name, gks->info.name, vars[dir], edge[edi], mom_name, frame); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gks->info.name, vars[dir], edge[edi], mom_name, + frame + ); + if (app->cdim > 1) { struct timespec wst = gkyl_wall_clock(); // Project the moment down to lower dimensions. int num_mom_comp = bflux->moms_op[mom_idx].num_mom; - gkyl_translate_dim_advance(bflux->transdim[b], bflux->boundaries_conf_skin_fullx[b], &bflux->surf_local[dir], - mom_arr, num_mom_comp, bflux->mom_surf[b*num_diag_mom+m]); + gkyl_translate_dim_advance( + bflux->transdim[b], bflux->boundaries_conf_skin_fullx[b], &bflux->surf_local[dir], + mom_arr, num_mom_comp, bflux->mom_surf[b * num_diag_mom + m] + ); app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); struct timespec wtm = gkyl_wall_clock(); - if (app->use_gpu) - gkyl_array_copy(bflux->mom_surf_ho[b*num_diag_mom+m], bflux->mom_surf[b*num_diag_mom+m]); - - gkyl_comm_array_write(bflux->comm_surf[dir], &bflux->grid_surf[dir], &bflux->surf_local[dir], mt, - bflux->mom_surf_ho[b*num_diag_mom+m], fileNm); + if (app->use_gpu) { + gkyl_array_copy( + bflux->mom_surf_ho[b * num_diag_mom + m], bflux->mom_surf[b * num_diag_mom + m] + ); + } + + gkyl_comm_array_write( + bflux->comm_surf[dir], &bflux->grid_surf[dir], &bflux->surf_local[dir], mt, + bflux->mom_surf_ho[b * num_diag_mom + m], fileNm + ); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); - } - else { + } else { // Don't project down to 0D; the infrastructure doesn't make it easy to do so. struct timespec wtm = gkyl_wall_clock(); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(bflux->moms_op[mom_idx].marr_host, mom_arr); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, - bflux->moms_op[mom_idx].marr_host, fileNm); + } + + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, bflux->moms_op[mom_idx].marr_host, fileNm + ); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); } - + app->stat.n_diag_io += 1; } } } - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); } -static void -gk_species_bflux_write_mom_disabled(gkyl_gyrokinetic_app* app, void *species, - struct gk_boundary_fluxes *bflux, double tm, int frame) +static void gk_species_bflux_write_mom_disabled( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm, int frame +) { } -void -gk_species_bflux_write_mom(gkyl_gyrokinetic_app* app, void *species, - struct gk_boundary_fluxes *bflux, double tm, int frame) +void gk_species_bflux_write_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm, int frame +) { bflux->bflux_write_mom_func(app, species, bflux, tm, frame); } -static int * -bflux_unionize_moms(int num_add_moms, enum gkyl_distribution_moments add_moms[BFLUX_MAX_MOM_NAMES], - int *num_moms, enum gkyl_distribution_moments moms[BFLUX_MAX_MOM_NAMES]) +static int *bflux_unionize_moms( + int num_add_moms, enum gkyl_distribution_moments add_moms[BFLUX_MAX_MOM_NAMES], int *num_moms, + enum gkyl_distribution_moments moms[BFLUX_MAX_MOM_NAMES] +) { // Check if each of the num_add_moms moments in add_moms is included in the // moms list of num_moms moments. If it's not, include it and increment // num_moms. Return a list of the indices of each add_moms in the moms list. - int *add_mom_idx = gkyl_malloc(num_add_moms*sizeof(int)); + int *add_mom_idx = gkyl_malloc(num_add_moms * sizeof(int)); int num_moms_base = num_moms[0]; - for (int i=0; iallocated_solver = false; @@ -646,30 +763,38 @@ gk_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, bflux->allocated_solver = true; // Set function pointer to compute bfluxes. - bflux->bflux_rhs_func = gk_species_bflux_rhs_calc; + bflux->bflux_rhs_func = gk_species_bflux_rhs_calc; bflux->bflux_get_flux_func = gk_species_bflux_get_flux_enabled; // Identify the non-periodic, non-zero-flux boundaries to compute boundary fluxes at. int num_bound = 0; - for (int d=0; dcdim; ++d) { - for (int e=0; e<2; ++e) { - if ( gk_s->bc_is_np[d] && - ((e == 0 && gk_s->lower_bc[d].type != GKYL_BC_GK_SPECIES_ZERO_FLUX) || - (e == 1 && gk_s->upper_bc[d].type != GKYL_BC_GK_SPECIES_ZERO_FLUX)) ) { + for (int d = 0; d < app->cdim; ++d) { + for (int e = 0; e < 2; ++e) { + if (gk_s->bc_is_np[d] && + ((e == 0 && gk_s->lower_bc[d].type != GKYL_BC_GK_SPECIES_ZERO_FLUX) || + (e == 1 && gk_s->upper_bc[d].type != GKYL_BC_GK_SPECIES_ZERO_FLUX))) { bflux->boundaries_dir[num_bound] = d; - bflux->boundaries_edge[num_bound] = e==0? GKYL_LOWER_EDGE : GKYL_UPPER_EDGE; - - bflux->boundaries_conf_skin[num_bound] = e==0? &app->local_lower_skin[d] : &app->local_upper_skin[d]; - bflux->boundaries_conf_ghost[num_bound] = e==0? &app->local_lower_ghost[d] : &app->local_upper_ghost[d]; - bflux->boundaries_phase_skin[num_bound] = e==0? &gk_s->local_lower_skin[d] : &gk_s->local_upper_skin[d]; - bflux->boundaries_phase_ghost[num_bound] = e==0? &gk_s->local_lower_ghost[d] : &gk_s->local_upper_ghost[d]; + bflux->boundaries_edge[num_bound] = e == 0 ? GKYL_LOWER_EDGE : GKYL_UPPER_EDGE; + + bflux->boundaries_conf_skin[num_bound] = e == 0 ? &app->local_lower_skin[d] : + &app->local_upper_skin[d]; + bflux->boundaries_conf_ghost[num_bound] = e == 0 ? &app->local_lower_ghost[d] : + &app->local_upper_ghost[d]; + bflux->boundaries_phase_skin[num_bound] = e == 0 ? &gk_s->local_lower_skin[d] : + &gk_s->local_upper_skin[d]; + bflux->boundaries_phase_ghost[num_bound] = e == 0 ? &gk_s->local_lower_ghost[d] : + &gk_s->local_upper_ghost[d]; bflux->boundaries_conf_skin_fullx[num_bound] = bflux->boundaries_conf_skin[num_bound]; - if (d == app->cdim-1 && app->gk_geom->has_LCFS) { + if (d == app->cdim - 1 && app->gk_geom->has_LCFS) { // Use SOL ranges only for parallel boundary fluxes. - bflux->boundaries_conf_skin[num_bound] = e==0? &app->local_lower_skin_par_sol : &app->local_upper_skin_par_sol; - bflux->boundaries_conf_ghost[num_bound] = e==0? &app->local_lower_ghost_par_sol : &app->local_upper_ghost_par_sol; - bflux->boundaries_phase_skin[num_bound] = e==0? &gk_s->local_lower_skin_par_sol : &gk_s->local_upper_skin_par_sol; - bflux->boundaries_phase_ghost[num_bound] = e==0? &gk_s->local_lower_ghost_par_sol : &gk_s->local_upper_ghost_par_sol; + bflux->boundaries_conf_skin[num_bound] = e == 0 ? &app->local_lower_skin_par_sol : + &app->local_upper_skin_par_sol; + bflux->boundaries_conf_ghost[num_bound] = e == 0 ? &app->local_lower_ghost_par_sol : + &app->local_upper_ghost_par_sol; + bflux->boundaries_phase_skin[num_bound] = e == 0 ? &gk_s->local_lower_skin_par_sol : + &gk_s->local_upper_skin_par_sol; + bflux->boundaries_phase_ghost[num_bound] = e == 0 ? &gk_s->local_lower_ghost_par_sol : + &gk_s->local_upper_ghost_par_sol; } num_bound++; @@ -680,44 +805,56 @@ gk_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, // Create an array of equation objects with terms that produce boundary fluxes. bflux->num_eqns = 0; - if (gk_s->collisionless.collisionless_id) + if (gk_s->collisionless.collisionless_id) { bflux->num_eqns += 1; // Collisionless terms. - if (gk_s->anom_diff.anom_diff_id) + } + if (gk_s->anom_diff.anom_diff_id) { bflux->num_eqns += 1; // Diffusion term. - - bflux->eqns = gkyl_malloc(bflux->num_eqns*sizeof(struct gkyl_dg_eqn *)); + } + + bflux->eqns = gkyl_malloc(bflux->num_eqns * sizeof(struct gkyl_dg_eqn *)); int eqc = 0; - if (gk_s->collisionless.collisionless_id == GKYL_GK_COLLISIONLESS_PASSIVE) - bflux->eqns[eqc++] = gkyl_dg_updater_gyrokinetic_passive_acquire_eqn(gk_s->collisionless.passive_slvr); - else if (gk_s->collisionless.collisionless_id) + if (gk_s->collisionless.collisionless_id == GKYL_GK_COLLISIONLESS_PASSIVE) { + bflux->eqns[eqc++] = + gkyl_dg_updater_gyrokinetic_passive_acquire_eqn(gk_s->collisionless.passive_slvr); + } else if (gk_s->collisionless.collisionless_id) { bflux->eqns[eqc++] = gkyl_dg_updater_gyrokinetic_acquire_eqn(gk_s->collisionless.slvr); + } - if (gk_s->anom_diff.anom_diff_id) + if (gk_s->anom_diff.anom_diff_id) { bflux->eqns[eqc++] = gkyl_dg_updater_gk_anomalous_diffusion_acquire_eqn(gk_s->anom_diff.slvr); - + } + // Allocate updater that computes boundary fluxes. - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; - bflux->flux_slvr[b] = gkyl_boundary_flux_new(dir, bflux->boundaries_edge[b], &gk_s->grid, - bflux->boundaries_phase_skin[b], bflux->boundaries_phase_ghost[b], bflux->num_eqns, - bflux->eqns, app->use_gpu); + bflux->flux_slvr[b] = gkyl_boundary_flux_new( + dir, bflux->boundaries_edge[b], &gk_s->grid, bflux->boundaries_phase_skin[b], + bflux->boundaries_phase_ghost[b], bflux->num_eqns, bflux->eqns, app->use_gpu + ); } // Create a ghost range that the flux lives on, and allocate the array that stores the flux. int ndim = gk_s->local.ndim; - bflux->boundaries_phase_ghost_nosub = gkyl_malloc(bflux->num_boundaries*sizeof(struct gkyl_range)); - bflux->flux = gkyl_malloc(bflux->num_boundaries*sizeof(struct gkyl_array *)); - for (int b=0; bnum_boundaries; ++b) { - gkyl_range_init(&bflux->boundaries_phase_ghost_nosub[b], ndim, bflux->boundaries_phase_ghost[b]->lower, bflux->boundaries_phase_ghost[b]->upper); - bflux->flux[b] = mkarr(app->use_gpu, gk_s->basis.num_basis, bflux->boundaries_phase_ghost_nosub[b].volume); + bflux->boundaries_phase_ghost_nosub = + gkyl_malloc(bflux->num_boundaries * sizeof(struct gkyl_range)); + bflux->flux = gkyl_malloc(bflux->num_boundaries * sizeof(struct gkyl_array *)); + for (int b = 0; b < bflux->num_boundaries; ++b) { + gkyl_range_init( + &bflux->boundaries_phase_ghost_nosub[b], ndim, bflux->boundaries_phase_ghost[b]->lower, + bflux->boundaries_phase_ghost[b]->upper + ); + bflux->flux[b] = + mkarr(app->use_gpu, gk_s->basis.num_basis, bflux->boundaries_phase_ghost_nosub[b].volume); } } int num_diag_mom = gk_s->info.boundary_flux_diagnostics.num_diag_moments; int num_diag_int_mom = gk_s->info.boundary_flux_diagnostics.num_integrated_diag_moments; - - if (bflux_type == GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS || bflux_type == GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS_DIAGS) { + + if (bflux_type == GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS || + bflux_type == GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS_DIAGS) { bflux->allocated_moms = true; // Set methods for time-stepping boundary fluxes needed for diagnostics. @@ -734,20 +871,27 @@ gk_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, // Create a union of the diag_moms, int_diag_moms and add_moms lists. Also store // the index of each mom in this union list. int num_add_mom = add_moms_inp.num_diag_moments; - assert(num_add_mom+num_diag_mom+num_diag_int_mom < BFLUX_MAX_MOM_NAMES+1); + assert(num_add_mom + num_diag_mom + num_diag_int_mom < BFLUX_MAX_MOM_NAMES + 1); bflux->num_calc_moms = 0; - if (num_diag_mom > 0) - bflux->diag_mom_idx = bflux_unionize_moms(num_diag_mom, - gk_s->info.boundary_flux_diagnostics.diag_moments, &bflux->num_calc_moms, bflux->calc_mom_names); + if (num_diag_mom > 0) { + bflux->diag_mom_idx = bflux_unionize_moms( + num_diag_mom, gk_s->info.boundary_flux_diagnostics.diag_moments, &bflux->num_calc_moms, + bflux->calc_mom_names + ); + } - if (num_diag_int_mom > 0) - bflux->diag_int_mom_idx = bflux_unionize_moms(num_diag_int_mom, - gk_s->info.boundary_flux_diagnostics.integrated_diag_moments, &bflux->num_calc_moms, bflux->calc_mom_names); + if (num_diag_int_mom > 0) { + bflux->diag_int_mom_idx = bflux_unionize_moms( + num_diag_int_mom, gk_s->info.boundary_flux_diagnostics.integrated_diag_moments, + &bflux->num_calc_moms, bflux->calc_mom_names + ); + } if (num_add_mom > 0) { - int *add_mom_idx = bflux_unionize_moms(num_add_mom, - add_moms_inp.diag_moments, &bflux->num_calc_moms, bflux->calc_mom_names); + int *add_mom_idx = bflux_unionize_moms( + num_add_mom, add_moms_inp.diag_moments, &bflux->num_calc_moms, bflux->calc_mom_names + ); gkyl_free(add_mom_idx); } @@ -756,16 +900,14 @@ gk_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, bflux->is_hamiltonian_mom = gkyl_malloc(sizeof(bool[bflux->num_calc_moms])); bool need_m2perp = false; bflux->a_hamiltonian_mom = false; - for (int m=0; mnum_calc_moms; m++) { + for (int m = 0; m < bflux->num_calc_moms; m++) { gk_species_moment_init(app, gk_s, &bflux->moms_op[m], bflux->calc_mom_names[m], false); - need_m2perp = need_m2perp || ( - (bflux->calc_mom_names[m] == GKYL_F_MOMENT_M2PERP) - || (bflux->calc_mom_names[m] == GKYL_F_MOMENT_M2) - || (bflux->calc_mom_names[m] == GKYL_F_MOMENT_M0M1M2) - || (bflux->calc_mom_names[m] == GKYL_F_MOMENT_M0M1M2PARM2PERP) - || (bflux->calc_mom_names[m] == GKYL_F_MOMENT_HAMILTONIAN) - ); + need_m2perp = need_m2perp || ((bflux->calc_mom_names[m] == GKYL_F_MOMENT_M2PERP) || + (bflux->calc_mom_names[m] == GKYL_F_MOMENT_M2) || + (bflux->calc_mom_names[m] == GKYL_F_MOMENT_M0M1M2) || + (bflux->calc_mom_names[m] == GKYL_F_MOMENT_M0M1M2PARM2PERP) || + (bflux->calc_mom_names[m] == GKYL_F_MOMENT_HAMILTONIAN)); bflux->is_hamiltonian_mom[m] = bflux->calc_mom_names[m] == GKYL_F_MOMENT_HAMILTONIAN; bflux->a_hamiltonian_mom = bflux->a_hamiltonian_mom || bflux->is_hamiltonian_mom[m]; } @@ -774,55 +916,66 @@ gk_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, // For moments that contain M2perp=2*mu*B/m we must fill the ghost cell of B. Use the option // in bc_basic that fills the ghost cell by evaluating the skin cell at the boundary. long buff_sz = 1; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; struct gkyl_range *skin_r = bflux->boundaries_conf_skin[b]; - - bflux->gfss_bc_op[b] = gkyl_bc_basic_gyrokinetic_new(bflux->boundaries_dir[b], bflux->boundaries_edge[b], - GKYL_BC_GK_FIELD_BOUNDARY_VALUE, app->basis_on_dev, skin_r, bflux->boundaries_conf_ghost[b], - app->basis.num_basis, app->cdim, app->use_gpu); - + + bflux->gfss_bc_op[b] = gkyl_bc_basic_gyrokinetic_new( + bflux->boundaries_dir[b], bflux->boundaries_edge[b], GKYL_BC_GK_FIELD_BOUNDARY_VALUE, + app->basis_on_dev, skin_r, bflux->boundaries_conf_ghost[b], app->basis.num_basis, + app->cdim, app->use_gpu + ); + long vol = skin_r->volume; buff_sz = buff_sz > vol ? buff_sz : vol; } bflux->bc_buffer = mkarr(app->use_gpu, app->basis.num_basis, buff_sz); - + // Fill ghost cell of bmag. - for (int b=0; bnum_boundaries; ++b) - gkyl_bc_basic_gyrokinetic_advance(bflux->gfss_bc_op[b], bflux->bc_buffer, app->gk_geom->geo_corn.bmag); + for (int b = 0; b < bflux->num_boundaries; ++b) { + gkyl_bc_basic_gyrokinetic_advance( + bflux->gfss_bc_op[b], bflux->bc_buffer, app->gk_geom->geo_corn.bmag + ); + } if (!bflux->a_hamiltonian_mom) { gkyl_array_release(bflux->bc_buffer); - for (int b=0; bnum_boundaries; ++b) + for (int b = 0; b < bflux->num_boundaries; ++b) { gkyl_bc_basic_gyrokinetic_release(bflux->gfss_bc_op[b]); + } } } - - bflux->f = gkyl_malloc(bflux->num_boundaries*bflux->num_calc_moms*sizeof(struct gkyl_array *)); - bflux->f1 = gkyl_malloc(bflux->num_boundaries*bflux->num_calc_moms*sizeof(struct gkyl_array *)); - bflux->fnew = gkyl_malloc(bflux->num_boundaries*bflux->num_calc_moms*sizeof(struct gkyl_array *)); - for (int b=0; bnum_boundaries; ++b) { - for (int m=0; mnum_calc_moms; m++) { + + bflux->f = + gkyl_malloc(bflux->num_boundaries * bflux->num_calc_moms * sizeof(struct gkyl_array *)); + bflux->f1 = + gkyl_malloc(bflux->num_boundaries * bflux->num_calc_moms * sizeof(struct gkyl_array *)); + bflux->fnew = + gkyl_malloc(bflux->num_boundaries * bflux->num_calc_moms * sizeof(struct gkyl_array *)); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { // Allocate arrays storing moments of the boundary flux. int num_mom_comp = bflux->moms_op[m].num_mom; - bflux->f[b*bflux->num_calc_moms+m] = mkarr(app->use_gpu, num_mom_comp*app->basis.num_basis, app->local_ext.volume); - bflux->f1[b*bflux->num_calc_moms+m] = mkarr(app->use_gpu, num_mom_comp*app->basis.num_basis, app->local_ext.volume); - bflux->fnew[b*bflux->num_calc_moms+m] = mkarr(app->use_gpu, num_mom_comp*app->basis.num_basis, app->local_ext.volume); + bflux->f[b * bflux->num_calc_moms + m] = + mkarr(app->use_gpu, num_mom_comp * app->basis.num_basis, app->local_ext.volume); + bflux->f1[b * bflux->num_calc_moms + m] = + mkarr(app->use_gpu, num_mom_comp * app->basis.num_basis, app->local_ext.volume); + bflux->fnew[b * bflux->num_calc_moms + m] = + mkarr(app->use_gpu, num_mom_comp * app->basis.num_basis, app->local_ext.volume); } } } - + if (bflux_type == GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS_DIAGS) { assert(num_diag_mom > 0 || num_diag_int_mom > 0); bflux->allocated_diags = true; - + // Set methods for time-stepping boundary fluxes needed for diagnostics. if (gk_s->info.boundary_flux_diagnostics.time_integrated) { bflux->bflux_calc_integrated_mom_func = gk_species_bflux_append_integrated_mom; bflux->bflux_calc_voltime_int_mom_func = gk_species_bflux_calc_voltime_integrated_mom_enabled; - } - else { + } else { bflux->bflux_calc_integrated_mom_func = gk_species_bflux_calc_integrated_mom_enabled; } bflux->bflux_write_integrated_mom_func = gk_species_bflux_write_integrated_mom_enabled; @@ -833,40 +986,41 @@ gk_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, if (app->cdim > 1) { struct gkyl_basis basis_conf_surf; switch (app->basis.b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - gkyl_cart_modal_serendip(&basis_conf_surf, app->cdim-1, app->basis.poly_order); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + gkyl_cart_modal_serendip(&basis_conf_surf, app->cdim - 1, app->basis.poly_order); + break; + default: + assert(false); + break; } - bflux->transdim = gkyl_malloc(bflux->num_boundaries*sizeof(struct gkyl_translate_dim *)); + bflux->transdim = gkyl_malloc(bflux->num_boundaries * sizeof(struct gkyl_translate_dim *)); bool diag_in_dir[GKYL_MAX_CDIM] = {0}; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; enum gkyl_edge_loc edge = bflux->boundaries_edge[b]; // Updater that projects to lower dim. - bflux->transdim[b] = gkyl_translate_dim_new(app->cdim, app->basis, app->cdim-1, - basis_conf_surf, dir, edge==GKYL_LOWER_EDGE? GKYL_UPPER_EDGE : GKYL_LOWER_EDGE, app->use_gpu); + bflux->transdim[b] = gkyl_translate_dim_new( + app->cdim, app->basis, app->cdim - 1, basis_conf_surf, dir, + edge == GKYL_LOWER_EDGE ? GKYL_UPPER_EDGE : GKYL_LOWER_EDGE, app->use_gpu + ); if (!diag_in_dir[dir]) { - // Create a communicator associated with a lower dimensional surface range. // Identify ranks on the same plane as this one. int num_ranks_surf = 0; - int ranks_surf[app->decomp->ndecomp]; - for (int i=0; idecomp->ndecomp; i++) { + int ranks_surf[app->decomp->ndecomp]; + for (int i = 0; i < app->decomp->ndecomp; i++) { if (app->decomp->ranges[i].lower[dir] == app->local.lower[dir]) { ranks_surf[num_ranks_surf] = i; num_ranks_surf++; } } // Create a range tangentially global. - int surf_dim = app->cdim-1; + int surf_dim = app->cdim - 1; int lower_surf[surf_dim], upper_surf[surf_dim]; int c = 0; - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { if (d != dir) { lower_surf[c] = app->global.lower[d]; upper_surf[c] = app->global.upper[d]; @@ -875,36 +1029,41 @@ gk_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, } struct gkyl_range range_surf; gkyl_range_init(&range_surf, surf_dim, lower_surf, upper_surf); - + // Create decomp. int cuts_plane[GKYL_MAX_CDIM], cuts_surf[surf_dim]; gkyl_rect_decomp_get_cuts(app->decomp_plane[dir], cuts_plane); c = 0; - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { if (d != dir) { cuts_surf[c] = cuts_plane[d]; c++; } } - bflux->decomp_surf[dir] = gkyl_rect_decomp_new_from_cuts(surf_dim, cuts_surf, &range_surf); - + bflux->decomp_surf[dir] = + gkyl_rect_decomp_new_from_cuts(surf_dim, cuts_surf, &range_surf); + // Create a new communicator with ranks on surf. bool is_comm_valid; - bflux->comm_surf[dir] = gkyl_comm_create_comm_from_ranks(app->comm, num_ranks_surf, - ranks_surf, bflux->decomp_surf[dir], &is_comm_valid); + bflux->comm_surf[dir] = gkyl_comm_create_comm_from_ranks( + app->comm, num_ranks_surf, ranks_surf, bflux->decomp_surf[dir], &is_comm_valid + ); assert(is_comm_valid); // Local and local extended surface range. int rank; gkyl_comm_get_rank(bflux->comm_surf[dir], &rank); - int ghost[] = { 1, 1, 1 }; - gkyl_create_ranges(&bflux->decomp_surf[dir]->ranges[rank], ghost, &bflux->surf_local_ext[dir], &bflux->surf_local[dir]); + int ghost[] = {1, 1, 1}; + gkyl_create_ranges( + &bflux->decomp_surf[dir]->ranges[rank], ghost, &bflux->surf_local_ext[dir], + &bflux->surf_local[dir] + ); // Create a surface grid. double grid_surf_lower[surf_dim], grid_surf_upper[surf_dim]; int grid_surf_cells[surf_dim]; c = 0; - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { if (d != dir) { grid_surf_lower[c] = app->grid.lower[d]; grid_surf_upper[c] = app->grid.upper[d]; @@ -912,25 +1071,35 @@ gk_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, c++; } } - gkyl_rect_grid_init(&bflux->grid_surf[dir], surf_dim, grid_surf_lower, grid_surf_upper, grid_surf_cells); + gkyl_rect_grid_init( + &bflux->grid_surf[dir], surf_dim, grid_surf_lower, grid_surf_upper, grid_surf_cells + ); diag_in_dir[dir] = true; } } // Allocate a lower dimensional array for each moment. - bflux->mom_surf = gkyl_malloc(bflux->num_boundaries*num_diag_mom*sizeof(struct gkyl_array *)); - bflux->mom_surf_ho = gkyl_malloc(bflux->num_boundaries*num_diag_mom*sizeof(struct gkyl_array *)); - for (int b=0; bnum_boundaries; ++b) { + bflux->mom_surf = + gkyl_malloc(bflux->num_boundaries * num_diag_mom * sizeof(struct gkyl_array *)); + bflux->mom_surf_ho = + gkyl_malloc(bflux->num_boundaries * num_diag_mom * sizeof(struct gkyl_array *)); + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; - for (int m=0; mdiag_mom_idx[m]; int num_mom_comp = bflux->moms_op[mom_idx].num_mom; - bflux->mom_surf[b*num_diag_mom+m] = mkarr(app->use_gpu, num_mom_comp*basis_conf_surf.num_basis, bflux->surf_local_ext[dir].volume); - bflux->mom_surf_ho[b*num_diag_mom+m] = app->use_gpu? - mkarr(false, num_mom_comp*basis_conf_surf.num_basis, bflux->surf_local_ext[dir].volume) : - gkyl_array_acquire(bflux->mom_surf[b*num_diag_mom+m]); + bflux->mom_surf[b * num_diag_mom + m] = mkarr( + app->use_gpu, num_mom_comp * basis_conf_surf.num_basis, + bflux->surf_local_ext[dir].volume + ); + bflux->mom_surf_ho[b * num_diag_mom + m] = + app->use_gpu ? + mkarr( + false, num_mom_comp * basis_conf_surf.num_basis, bflux->surf_local_ext[dir].volume + ) : + gkyl_array_acquire(bflux->mom_surf[b * num_diag_mom + m]); } } } @@ -938,54 +1107,56 @@ gk_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, if (num_diag_int_mom > 0) { // Object to integrate moments of the bflux and dynvectors to store them. - bflux->integ_op = gkyl_malloc(num_diag_int_mom*sizeof(struct gkyl_array_integrate *)); - bflux->intmom = gkyl_malloc(num_diag_int_mom*bflux->num_boundaries*sizeof(gkyl_dynvec)); + bflux->integ_op = gkyl_malloc(num_diag_int_mom * sizeof(struct gkyl_array_integrate *)); + bflux->intmom = gkyl_malloc(num_diag_int_mom * bflux->num_boundaries * sizeof(gkyl_dynvec)); int num_mom_comp_max = 1; - for (int m=0; mmoms_op[bflux->diag_int_mom_idx[m]].num_mom; num_mom_comp_max = GKYL_MAX2(num_mom_comp_max, num_mom_comp); // Updater to compute the volume integral of the boundary flux moments. - bflux->integ_op[m] = gkyl_array_integrate_new(&app->grid, &app->basis, - num_mom_comp, GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu); + bflux->integ_op[m] = gkyl_array_integrate_new( + &app->grid, &app->basis, num_mom_comp, GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu + ); // Allocate a dynvector for each moment. - for (int b=0; bnum_boundaries; ++b) - bflux->intmom[b*num_diag_int_mom+m] = gkyl_dynvec_new(GKYL_DOUBLE, num_mom_comp); + for (int b = 0; b < bflux->num_boundaries; ++b) { + bflux->intmom[b * num_diag_int_mom + m] = gkyl_dynvec_new(GKYL_DOUBLE, num_mom_comp); + } } - + if (app->use_gpu) { - bflux->int_moms_local = gkyl_cu_malloc(num_mom_comp_max*sizeof(double)); - bflux->int_moms_global = gkyl_cu_malloc(num_mom_comp_max*sizeof(double)); - } - else { - bflux->int_moms_local = gkyl_malloc(num_mom_comp_max*sizeof(double)); - bflux->int_moms_global = gkyl_malloc(num_mom_comp_max*sizeof(double)); + bflux->int_moms_local = gkyl_cu_malloc(num_mom_comp_max * sizeof(double)); + bflux->int_moms_global = gkyl_cu_malloc(num_mom_comp_max * sizeof(double)); + } else { + bflux->int_moms_local = gkyl_malloc(num_mom_comp_max * sizeof(double)); + bflux->int_moms_global = gkyl_malloc(num_mom_comp_max * sizeof(double)); } - - for (int b=0; bnum_boundaries; ++b) + + for (int b = 0; b < bflux->num_boundaries; ++b) { bflux->is_first_intmom_write_call[b] = true; - + } + if (gk_s->info.boundary_flux_diagnostics.time_integrated) { // Cummulative integrated moments of boundary fluxes. - bflux->intmom_cumm_buff = gkyl_malloc(num_diag_int_mom*sizeof(double *)); - for (int m=0; mintmom_cumm_buff = gkyl_malloc(num_diag_int_mom * sizeof(double *)); + for (int m = 0; m < num_diag_int_mom; m++) { int num_mom_comp = bflux->moms_op[bflux->diag_int_mom_idx[m]].num_mom; - bflux->intmom_cumm_buff[m] = gkyl_malloc(bflux->num_boundaries*num_mom_comp*sizeof(double)); + bflux->intmom_cumm_buff[m] = + gkyl_malloc(bflux->num_boundaries * num_mom_comp * sizeof(double)); double *intmom_cumm_buff = bflux->intmom_cumm_buff[m]; - for (int b=0; bnum_boundaries; ++b) { - for (int k=0; knum_boundaries; ++b) { + for (int k = 0; k < num_mom_comp; k++) { + intmom_cumm_buff[b * num_mom_comp + k] = 0.0; + } } } } - } } - } -void -gk_species_bflux_read_voltime_integrated_mom(gkyl_gyrokinetic_app *app, - void *species, struct gk_boundary_fluxes *bflux) +void gk_species_bflux_read_voltime_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux +) { const struct gk_species *gks = species; @@ -994,59 +1165,63 @@ gk_species_bflux_read_voltime_integrated_mom(gkyl_gyrokinetic_app *app, gkyl_comm_get_rank(app->comm, &rank); gkyl_comm_get_size(app->comm, &comm_size); - const char *vars[] = {"x","y","z"}; - const char *edge[] = {"lower","upper"}; + const char *vars[] = {"x", "y", "z"}; + const char *edge[] = {"lower", "upper"}; int num_diag_int_mom = gks->info.boundary_flux_diagnostics.num_integrated_diag_moments; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; - int edi = bflux->boundaries_edge[b]==GKYL_LOWER_EDGE? 0 : 1; + int edi = bflux->boundaries_edge[b] == GKYL_LOWER_EDGE ? 0 : 1; - if ((edi == 0 && rank == 0) || (edi == 1 && rank == comm_size-1)) { - for (int m=0; minfo.boundary_flux_diagnostics.integrated_diag_moments[m]]; + const char *mom_name = gkyl_distribution_moments_strs[gks->info.boundary_flux_diagnostics + .integrated_diag_moments[m]]; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, vars[dir], edge[edi], mom_name); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, vars[dir], edge[edi], mom_name); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gks->info.name, vars[dir], edge[edi], mom_name + ); // We didn't calculate int_mom at restart, so read the value from the previous sim // and append it. This is the best solution given the flow in present input files. - bool res = gkyl_dynvec_read(bflux->intmom[b*num_diag_int_mom+m], fileNm); - int num_mom_comp = gkyl_dynvec_ncomp(bflux->intmom[b*num_diag_int_mom+m]); + bool res = gkyl_dynvec_read(bflux->intmom[b * num_diag_int_mom + m], fileNm); + int num_mom_comp = gkyl_dynvec_ncomp(bflux->intmom[b * num_diag_int_mom + m]); double vals_prev[num_mom_comp]; - gkyl_dynvec_getlast(bflux->intmom[b*num_diag_int_mom+m], vals_prev); - gkyl_dynvec_clear(bflux->intmom[b*num_diag_int_mom+m]); + gkyl_dynvec_getlast(bflux->intmom[b * num_diag_int_mom + m], vals_prev); + gkyl_dynvec_clear(bflux->intmom[b * num_diag_int_mom + m]); double *intmom_cumm_buff = bflux->intmom_cumm_buff[m]; - for (int k=0; kallocated_solver) { - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { gkyl_boundary_flux_release(bflux->flux_slvr[b]); } - for (int i=0; inum_eqns; i++) { + for (int i = 0; i < bflux->num_eqns; i++) { gkyl_dg_eqn_release(bflux->eqns[i]); } gkyl_free(bflux->eqns); - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { gkyl_array_release(bflux->flux[b]); } gkyl_free(bflux->flux); @@ -1057,27 +1232,31 @@ gk_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const void *spe int num_diag_int_mom = gk_s->info.boundary_flux_diagnostics.num_integrated_diag_moments; if (bflux->allocated_moms) { - if (num_diag_mom > 0) + if (num_diag_mom > 0) { gkyl_free(bflux->diag_mom_idx); + } - if (num_diag_int_mom > 0) + if (num_diag_int_mom > 0) { gkyl_free(bflux->diag_int_mom_idx); + } - for (int m=0; mnum_calc_moms; m++) - gk_species_moment_release(app, &bflux->moms_op[m]); + for (int m = 0; m < bflux->num_calc_moms; m++) { + gk_species_moment_release(app, &bflux->moms_op[m]); + } gkyl_free(bflux->moms_op); gkyl_free(bflux->is_hamiltonian_mom); if (bflux->a_hamiltonian_mom) { gkyl_array_release(bflux->bc_buffer); - for (int b=0; bnum_boundaries; ++b) + for (int b = 0; b < bflux->num_boundaries; ++b) { gkyl_bc_basic_gyrokinetic_release(bflux->gfss_bc_op[b]); + } } - for (int b=0; bnum_boundaries; ++b) { - for (int m=0; mnum_calc_moms; m++) { - gkyl_array_release(bflux->f[b*bflux->num_calc_moms+m]); - gkyl_array_release(bflux->f1[b*bflux->num_calc_moms+m]); - gkyl_array_release(bflux->fnew[b*bflux->num_calc_moms+m]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < bflux->num_calc_moms; m++) { + gkyl_array_release(bflux->f[b * bflux->num_calc_moms + m]); + gkyl_array_release(bflux->f1[b * bflux->num_calc_moms + m]); + gkyl_array_release(bflux->fnew[b * bflux->num_calc_moms + m]); } } gkyl_free(bflux->f); @@ -1089,13 +1268,14 @@ gk_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const void *spe if (num_diag_mom > 0) { if (app->cdim > 1) { // Objects needed to output lower dimensional moments. - for (int b=0; bnum_boundaries; ++b) + for (int b = 0; b < bflux->num_boundaries; ++b) { gkyl_translate_dim_release(bflux->transdim[b]); + } gkyl_free(bflux->transdim); bool diag_in_dir[GKYL_MAX_CDIM] = {0}; - for (int b=0; bnum_boundaries; ++b) { + for (int b = 0; b < bflux->num_boundaries; ++b) { int dir = bflux->boundaries_dir[b]; if (!diag_in_dir[dir]) { gkyl_rect_decomp_release(bflux->decomp_surf[dir]); @@ -1104,10 +1284,10 @@ gk_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const void *spe } } - for (int b=0; bnum_boundaries; ++b) { - for (int m=0; mmom_surf[b*num_diag_mom+m]); - gkyl_array_release(bflux->mom_surf_ho[b*num_diag_mom+m]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + for (int m = 0; m < num_diag_mom; m++) { + gkyl_array_release(bflux->mom_surf[b * num_diag_mom + m]); + gkyl_array_release(bflux->mom_surf_ho[b * num_diag_mom + m]); } } gkyl_free(bflux->mom_surf); @@ -1116,25 +1296,26 @@ gk_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const void *spe } if (num_diag_int_mom > 0) { - for (int m=0; minteg_op[m]); - for (int b=0; bnum_boundaries; ++b) - gkyl_dynvec_release(bflux->intmom[b*num_diag_int_mom+m]); + for (int b = 0; b < bflux->num_boundaries; ++b) { + gkyl_dynvec_release(bflux->intmom[b * num_diag_int_mom + m]); + } } gkyl_free(bflux->integ_op); gkyl_free(bflux->intmom); if (app->use_gpu) { gkyl_cu_free(bflux->int_moms_local); gkyl_cu_free(bflux->int_moms_global); - } - else { + } else { gkyl_free(bflux->int_moms_local); gkyl_free(bflux->int_moms_global); } - + if (gk_s->info.boundary_flux_diagnostics.time_integrated) { - for (int m=0; mintmom_cumm_buff[m]); + } gkyl_free(bflux->intmom_cumm_buff); } } diff --git a/gyrokinetic/apps/gk_species_bgk.c b/gyrokinetic/apps/gk_species_bgk.c index 74214824fb..d890af32a4 100644 --- a/gyrokinetic/apps/gk_species_bgk.c +++ b/gyrokinetic/apps/gk_species_bgk.c @@ -2,97 +2,109 @@ #include #include -static void -gkbgk_moms_disabled(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +static void gkbgk_moms_disabled( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { // Empty method. } -static void -gkbgk_moms_enabled(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +static void gkbgk_moms_enabled( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { struct timespec wst = gkyl_wall_clock(); // Compute Maxwellian moments (n, u_par, T/m). gk_species_moment_calc(&species->lte.moms, species->local, app->local, fin); - gkyl_dg_div_op_range(species->lte.moms.mem_geo, &app->basis, 0, species->lte.moms.marr, - 0, species->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local); - + gkyl_dg_div_op_range( + species->lte.moms.mem_geo, &app->basis, 0, species->lte.moms.marr, 0, species->lte.moms.marr, 0, + app->gk_geom->geo_int.jacobgeo, &app->local + ); + // Calculate nu_ss. bgk->self_nu_func(app, species, bgk); - app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); + app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); } -static void -gkbgk_self_nu_calc_constNu(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_bgk_collisions *bgk) +static void gkbgk_self_nu_calc_constNu( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_bgk_collisions *bgk +) { // Empty method. } -static void -gkbgk_self_nu_calc_normNu(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_bgk_collisions *bgk) +static void gkbgk_self_nu_calc_normNu( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_bgk_collisions *bgk +) { // Calculate nu_ss(x,t). - gkyl_spitzer_coll_freq_advance_normnu(bgk->spitzer_calc, &app->local, species->lte.moms.marr, bgk->vtsq_min, - species->lte.moms.marr, bgk->vtsq_min, bgk->norm_nu_fac_self, bgk->self_nu); + gkyl_spitzer_coll_freq_advance_normnu( + bgk->spitzer_calc, &app->local, species->lte.moms.marr, bgk->vtsq_min, species->lte.moms.marr, + bgk->vtsq_min, bgk->norm_nu_fac_self, bgk->self_nu + ); gkyl_array_set(bgk->nu_sum, 1.0, bgk->self_nu); } -static void -gkbgk_cross_nu_calc_constNu(gkyl_gyrokinetic_app *app, const struct gk_species *s, - struct gk_bgk_collisions *bgk, int coll_idx) +static void gkbgk_cross_nu_calc_constNu( + gkyl_gyrokinetic_app *app, const struct gk_species *s, struct gk_bgk_collisions *bgk, int coll_idx +) { // Empty method. } -static void -gkbgk_cross_nu_calc_normNu(gkyl_gyrokinetic_app *app, const struct gk_species *s, - struct gk_bgk_collisions *bgk, int coll_idx) +static void gkbgk_cross_nu_calc_normNu( + gkyl_gyrokinetic_app *app, const struct gk_species *s, struct gk_bgk_collisions *bgk, int coll_idx +) { // Calculate nu_sr(x,t). - gkyl_spitzer_coll_freq_advance_normnu(bgk->spitzer_calc, &app->local, s->lte.moms.marr, bgk->vtsq_min, + gkyl_spitzer_coll_freq_advance_normnu( + bgk->spitzer_calc, &app->local, s->lte.moms.marr, bgk->vtsq_min, bgk->collide_with[coll_idx]->lte.moms.marr, bgk->collide_with[coll_idx]->bgk.vtsq_min, - bgk->norm_nu_fac_cross[coll_idx], bgk->cross_nu[coll_idx]); + bgk->norm_nu_fac_cross[coll_idx], bgk->cross_nu[coll_idx] + ); gkyl_array_accumulate(bgk->nu_sum, 1.0, bgk->cross_nu[coll_idx]); } -static void -gkbgk_alpha_E_constNu(gkyl_gyrokinetic_app *app, const struct gk_species *s, - struct gk_bgk_collisions *bgk, int coll_idx) +static void gkbgk_alpha_E_constNu( + gkyl_gyrokinetic_app *app, const struct gk_species *s, struct gk_bgk_collisions *bgk, int coll_idx +) { gkyl_array_clear(bgk->alpha_E, 0.0); gkyl_array_shiftc(bgk->alpha_E, bgk->alpha_E_fac[coll_idx], 0); } -static void -gkbgk_alpha_E_normNu(gkyl_gyrokinetic_app *app, const struct gk_species *s, - struct gk_bgk_collisions *bgk, int coll_idx) +static void gkbgk_alpha_E_normNu( + gkyl_gyrokinetic_app *app, const struct gk_species *s, struct gk_bgk_collisions *bgk, int coll_idx +) { - gkyl_dg_mul_op_range(&app->basis, 0, bgk->alpha_E, 0, bgk->cross_nu[coll_idx], 0, s->lte.moms.marr, &app->local); + gkyl_dg_mul_op_range( + &app->basis, 0, bgk->alpha_E, 0, bgk->cross_nu[coll_idx], 0, s->lte.moms.marr, &app->local + ); gkyl_array_scale_range(bgk->alpha_E, bgk->alpha_E_fac[coll_idx], &app->local); } -static void -gkbgk_cross_moms_disabled(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk, int coll_idx) +static void gkbgk_cross_moms_disabled( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk, + int coll_idx +) { // Empty method. } -static void -gkbgk_cross_moms_enabled(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk, int coll_idx) +static void gkbgk_cross_moms_enabled( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk, + int coll_idx +) { // Compute primitive moments for cross-species collisions. struct timespec wst = gkyl_wall_clock(); - + // Compute the cross-species collision frequency. bgk->cross_nu_func(app, gks, bgk, coll_idx); @@ -100,36 +112,40 @@ gkbgk_cross_moms_enabled(gkyl_gyrokinetic_app *app, const struct gk_species *gks bgk->alpha_E_func(app, gks, bgk, coll_idx); // Compute cross primitive moments. - gkyl_gyrokinetic_cross_prim_moms_bgk_advance(bgk->cross_calc, &app->local, bgk->delta_sr, bgk->betaGreenep1, - gks->info.mass, gks->lte.moms.marr, bgk->other_m[coll_idx], bgk->other_prim_moms[coll_idx], - bgk->cross_prim_moms); + gkyl_gyrokinetic_cross_prim_moms_bgk_advance( + bgk->cross_calc, &app->local, bgk->delta_sr, bgk->betaGreenep1, gks->info.mass, + gks->lte.moms.marr, bgk->other_m[coll_idx], bgk->other_prim_moms[coll_idx], bgk->cross_prim_moms + ); - app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); + app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); } -static void -gkbgk_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs) +static void gkbgk_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs +) { // Empty method. } -static void -gkbgk_rhs_enabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs) +static void gkbgk_rhs_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - + // Compute the self-collisions Maxwellian. struct gk_lte *lte = &gks->lte; gk_species_lte_from_moms(app, gks, lte, lte->moms.marr); // Multiply the Maxwellian by self-species collision frequency. - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gks->basis, bgk->nu_fmax, - bgk->self_nu, lte->f_lte, &app->local, &gks->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gks->basis, bgk->nu_fmax, bgk->self_nu, lte->f_lte, &app->local, &gks->local + ); // Cross-collisions nu*fmax. - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < bgk->num_cross_collisions; ++i) { // Compute cross-primitive moments bgk->cross_moms_func(app, gks, bgk, i); @@ -137,62 +153,71 @@ gkbgk_rhs_enabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, gk_species_lte_from_moms(app, gks, lte, bgk->cross_prim_moms); // Compute and accumulate nu*fmax. - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gks->basis, lte->f_lte, - bgk->cross_nu[i], lte->f_lte, &app->local, &gks->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gks->basis, lte->f_lte, bgk->cross_nu[i], lte->f_lte, &app->local, &gks->local + ); gkyl_array_accumulate(bgk->nu_fmax, 1.0, lte->f_lte); } // Multiply the Maxwellian by the configuration-space Jacobian. - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gks->basis, bgk->nu_fmax, - app->gk_geom->geo_int.jacobgeo, bgk->nu_fmax, &app->local, &gks->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gks->basis, bgk->nu_fmax, app->gk_geom->geo_int.jacobgeo, bgk->nu_fmax, + &app->local, &gks->local + ); // Apply BGK collisions. - gkyl_bgk_collisions_advance(bgk->up_bgk, &app->local, &gks->local, - bgk->nu_sum, bgk->nu_fmax, fin, bgk->implicit_step, dt, rhs, gks->cflrate); - + gkyl_bgk_collisions_advance( + bgk->up_bgk, &app->local, &gks->local, bgk->nu_sum, bgk->nu_fmax, fin, bgk->implicit_step, dt, + rhs, gks->cflrate + ); + app->stat.species_coll_tm += gkyl_time_diff_now_sec(wst); } static void -gkbgk_write_mom_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +gkbgk_write_mom_disabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { // Empty method. } static void -gkbgk_write_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +gkbgk_write_mom_enabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { struct timespec wtm = gkyl_wall_clock(); // Package metadata. gkyl_msgpack_map_elem_set_double(gks->io_meta_conf_len, gks->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_conf_len, gks->io_meta_conf, "frame", frame); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Sum of collision frequencies." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Sum of collision frequencies."} }; int io_meta_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); // Write out nu_sum. const char *fmt = "%s-%s_bgk_nu_sum_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, frame); - + // Copy data from device to host before writing it out. if (app->use_gpu) { gkyl_array_copy(gks->bgk.nu_sum_host, gks->bgk.nu_sum); } - + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, gks->bgk.nu_sum_host, fileNm); app->stat.n_diag_io += 2; - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); } -void -gk_species_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk) +void gk_species_bgk_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk +) { bgk->collision_id = gks->info.collisions.collision_id; bgk->write_diagnostics = gks->info.collisions.write_diagnostics; @@ -207,75 +232,80 @@ gk_species_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, st if (bgk->collision_id == GKYL_BGK_COLLISIONS) { bgk->implicit_step = gks->info.collisions.is_implicit; bgk->num_cross_collisions = gks->info.collisions.num_cross_collisions; - + int cdim = app->cdim, vdim = gks->info.vdim; - + // Allocate self-species collision frequency and sum of collision frequencies. bgk->self_nu = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); bgk->nu_sum = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - + double nu_frac = gks->info.collisions.nu_frac ? gks->info.collisions.nu_frac : 1.0; - + if (gks->info.collisions.self_nu) { // Project user's self-species collision frequency. bgk->norm_nu_self = false; - + struct gkyl_array *self_nu_ho = mkarr(false, app->basis.num_basis, app->local_ext.volume); - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(&app->grid, &app->basis, - app->poly_order+1, 1, gks->info.collisions.self_nu, gks->info.collisions.self_nu_ctx); + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + &app->grid, &app->basis, app->poly_order + 1, 1, gks->info.collisions.self_nu, + gks->info.collisions.self_nu_ctx + ); gkyl_proj_on_basis_advance(proj, 0.0, &app->local, self_nu_ho); gkyl_proj_on_basis_release(proj); gkyl_array_copy(bgk->self_nu, self_nu_ho); gkyl_array_release(self_nu_ho); - + gkyl_array_scale(bgk->self_nu, nu_frac); gkyl_array_set(bgk->nu_sum, 1.0, bgk->self_nu); - + // Set pointers to functions chosen at runtime. bgk->self_nu_func = gkbgk_self_nu_calc_constNu; - } - else { + } else { // Self-collision frequency computed in time. bgk->norm_nu_self = true; - + double eps0 = gks->info.collisions.eps0 ? gks->info.collisions.eps0 : GKYL_EPSILON0; - double hbar = gks->info.collisions.hbar ? gks->info.collisions.hbar : GKYL_PLANCKS_CONSTANT_H/2/M_PI; + double hbar = gks->info.collisions.hbar ? gks->info.collisions.hbar : + GKYL_PLANCKS_CONSTANT_H / 2 / M_PI; double eV = gks->info.collisions.eV ? gks->info.collisions.eV : GKYL_ELEMENTARY_CHARGE; - double bmag_ref = gks->info.collisions.bmag_ref ? gks->info.collisions.bmag_ref : app->bmag_ref; - + double bmag_ref = gks->info.collisions.bmag_ref ? gks->info.collisions.bmag_ref : + app->bmag_ref; + // Compute a minimum representable temperature based on the smallest dv in the grid. double dv_min[vdim]; gkyl_velocity_map_reduce_dv_range(gks->vel_map, GKYL_MIN, dv_min, gks->vel_map->local_vel); - - double tpar_min = (gks->info.mass/6.0)*pow(dv_min[0],2); - double tperp_min = vdim>1 ? (bmag_ref/3.0)*dv_min[1] : tpar_min; - bgk->vtsq_min = (tpar_min + 2.0*tperp_min)/(3.0*gks->info.mass); - - bgk->spitzer_calc = gkyl_spitzer_coll_freq_new(&app->basis, app->poly_order+1, - 1.0, 1.0, 1.0, app->use_gpu); + + double tpar_min = (gks->info.mass / 6.0) * pow(dv_min[0], 2); + double tperp_min = vdim > 1 ? (bmag_ref / 3.0) * dv_min[1] : tpar_min; + bgk->vtsq_min = (tpar_min + 2.0 * tperp_min) / (3.0 * gks->info.mass); + + bgk->spitzer_calc = + gkyl_spitzer_coll_freq_new(&app->basis, app->poly_order + 1, 1.0, 1.0, 1.0, app->use_gpu); // We define nu_ss = nu_sr(r=s) = alpha_E/((delta_ss * (1+beta))*n_s), with delta_ss = 2, // beta = 0. This gives a nu_ss that is arguably 2X smaller than it should be, but it's // cheaper and yields an electron isotropization rate that agrees better with the FPO's. bgk->norm_nu_fac_self = nu_frac * gkyl_calc_Morse_alpha_E_const( - gks->info.collisions.den_ref, gks->info.collisions.den_ref, - gks->info.mass, gks->info.mass, gks->info.charge, gks->info.charge, - gks->info.collisions.temp_ref, gks->info.collisions.temp_ref, bmag_ref, eps0, hbar, eV); - + gks->info.collisions.den_ref, + gks->info.collisions.den_ref, gks->info.mass, + gks->info.mass, gks->info.charge, gks->info.charge, + gks->info.collisions.temp_ref, + gks->info.collisions.temp_ref, bmag_ref, eps0, hbar, eV + ); + // Set pointers to functions chosen at runtime. bgk->self_nu_func = gkbgk_self_nu_calc_normNu; } - + // Host-side copy for I/O. if (bgk->write_diagnostics) { if (app->use_gpu) { bgk->nu_sum_host = mkarr(false, app->basis.num_basis, app->local_ext.volume); - } - else { + } else { bgk->nu_sum_host = bgk->nu_sum; } } - + // Collision frequency times Maxwellian. bgk->nu_fmax = mkarr(app->use_gpu, gks->basis.num_basis, gks->local_ext.volume); @@ -290,8 +320,7 @@ gk_species_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, st if (!gks->info.collisions.not_in_dfdt) { bgk->rhs_func_implicit = gkbgk_rhs_enabled; } - } - else { + } else { bgk->moms_func = gkbgk_moms_enabled; if (!gks->info.collisions.not_in_dfdt) { bgk->rhs_func = gkbgk_rhs_enabled; @@ -299,14 +328,16 @@ gk_species_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, st bgk->moms_func_implicit = gkbgk_moms_disabled; bgk->rhs_func_implicit = gkbgk_rhs_disabled; } - if (bgk->write_diagnostics) + if (bgk->write_diagnostics) { bgk->write_mom_func = gkbgk_write_mom_enabled; + } } } -void -gk_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk) -{ +void gk_species_bgk_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk +) +{ // Empty methods. bgk->cross_nu_func = gkbgk_cross_nu_calc_constNu; bgk->cross_moms_func = gkbgk_cross_moms_disabled; @@ -315,13 +346,13 @@ gk_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g if (gks->bgk.num_cross_collisions) { bgk->betaGreenep1 = 1.0; // Greene's beta factor + 1. bgk->delta_sr = 2.0; // delta_sr free parameter. - + // Set pointers to species we cross-collide with. int my_idx_in_other[GKYL_MAX_SPECIES]; - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < bgk->num_cross_collisions; ++i) { bgk->collide_with[i] = gk_find_species(app, gks->info.collisions.collide_with[i]); my_idx_in_other[i] = -1; - for (int j=0; jcollide_with[i]->bgk.num_cross_collisions; ++j) { + for (int j = 0; j < bgk->collide_with[i]->bgk.num_cross_collisions; ++j) { if (0 == strcmp(gks->info.name, bgk->collide_with[i]->info.collisions.collide_with[j])) { my_idx_in_other[i] = j; break; @@ -332,8 +363,8 @@ gk_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g // Morse's alpha_E. bgk->alpha_E = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); // Cross primitive moments (n_sr, u_{parallel sr}, v_{t,sr}^2). - bgk->cross_prim_moms = mkarr(app->use_gpu, 3*app->basis.num_basis, app->local_ext.volume); - for (int i=0; inum_cross_collisions; ++i) { + bgk->cross_prim_moms = mkarr(app->use_gpu, 3 * app->basis.num_basis, app->local_ext.volume); + for (int i = 0; i < bgk->num_cross_collisions; ++i) { // Cross-species collision frequency, nu_sr. bgk->cross_nu[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); bgk->other_m[i] = bgk->collide_with[i]->info.mass; @@ -344,17 +375,22 @@ gk_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g // Compute the time-independent part of alpha_E. double alpha_E_norm[GKYL_MAX_SPECIES] = {0.0}; - for (int i=0; inum_cross_collisions; ++i) { - double eps0 = gks->info.collisions.eps0 ? gks->info.collisions.eps0: GKYL_EPSILON0; - double hbar = gks->info.collisions.hbar ? gks->info.collisions.hbar: GKYL_PLANCKS_CONSTANT_H/2/M_PI; - double eV = gks->info.collisions.eV ? gks->info.collisions.eV: GKYL_ELEMENTARY_CHARGE; - double bmag_ref = gks->info.collisions.bmag_ref ? gks->info.collisions.bmag_ref : app->bmag_ref; + for (int i = 0; i < bgk->num_cross_collisions; ++i) { + double eps0 = gks->info.collisions.eps0 ? gks->info.collisions.eps0 : GKYL_EPSILON0; + double hbar = gks->info.collisions.hbar ? gks->info.collisions.hbar : + GKYL_PLANCKS_CONSTANT_H / 2 / M_PI; + double eV = gks->info.collisions.eV ? gks->info.collisions.eV : GKYL_ELEMENTARY_CHARGE; + double bmag_ref = gks->info.collisions.bmag_ref ? gks->info.collisions.bmag_ref : + app->bmag_ref; double mass_self = gks->info.mass, mass_other = bgk->collide_with[i]->info.mass; - alpha_E_norm[i] = nu_frac * gkyl_calc_Morse_alpha_E_const( - gks->info.collisions.den_ref, bgk->collide_with[i]->info.collisions.den_ref, - mass_self, mass_other, gks->info.charge, bgk->collide_with[i]->info.charge, - gks->info.collisions.temp_ref, bgk->collide_with[i]->info.collisions.temp_ref, bmag_ref, eps0, hbar, eV); + alpha_E_norm[i] = + nu_frac * gkyl_calc_Morse_alpha_E_const( + gks->info.collisions.den_ref, bgk->collide_with[i]->info.collisions.den_ref, + mass_self, mass_other, gks->info.charge, bgk->collide_with[i]->info.charge, + gks->info.collisions.temp_ref, bgk->collide_with[i]->info.collisions.temp_ref, + bmag_ref, eps0, hbar, eV + ); } if (gks->info.collisions.cross_nu[0]) { @@ -362,15 +398,17 @@ gk_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g bgk->norm_nu_cross = false; // Ensure the other species this collides with also provided self_nu and cross_nu. - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < bgk->num_cross_collisions; ++i) { assert(bgk->collide_with[i]->info.collisions.self_nu); assert(bgk->collide_with[i]->info.collisions.cross_nu[my_idx_in_other[i]]); } struct gkyl_array *cross_nu_ho = mkarr(false, app->basis.num_basis, app->local_ext.volume); - for (int i=0; inum_cross_collisions; ++i) { - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(&app->grid, &app->basis, - app->poly_order+1, 1, gks->info.collisions.cross_nu[i], gks->info.collisions.cross_nu_ctx); + for (int i = 0; i < bgk->num_cross_collisions; ++i) { + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + &app->grid, &app->basis, app->poly_order + 1, 1, gks->info.collisions.cross_nu[i], + gks->info.collisions.cross_nu_ctx + ); gkyl_proj_on_basis_advance(proj, 0.0, &app->local, cross_nu_ho); gkyl_proj_on_basis_release(proj); gkyl_array_copy(bgk->cross_nu[i], cross_nu_ho); @@ -386,34 +424,36 @@ gk_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g double mass_self = gks->info.mass, mass_other = bgk->collide_with[i]->info.mass; double den_s = gks->info.collisions.den_ref; double den_r = bgk->collide_with[i]->info.collisions.den_ref; - double vtsq_s = gks->info.collisions.temp_ref/mass_self; - double vtsq_r = bgk->collide_with[i]->info.collisions.temp_ref/mass_other; + double vtsq_s = gks->info.collisions.temp_ref / mass_self; + double vtsq_r = bgk->collide_with[i]->info.collisions.temp_ref / mass_other; - bgk->alpha_E_fac[i] = ( alpha_E_norm[i] * den_s * den_r / pow(sqrt(vtsq_s+vtsq_r),3.0) ) * pow(sqrt(2.0),app->cdim); + bgk->alpha_E_fac[i] = + (alpha_E_norm[i] * den_s * den_r / pow(sqrt(vtsq_s + vtsq_r), 3.0)) * + pow(sqrt(2.0), app->cdim); } gkyl_array_release(cross_nu_ho); // Set pointers to functions chosen at runtime. bgk->cross_nu_func = gkbgk_cross_nu_calc_constNu; bgk->alpha_E_func = gkbgk_alpha_E_constNu; - } - else { + } else { // Cross-collision frequency computed in time. bgk->norm_nu_cross = true; // Ensure the other species this collides with didn't provide self_nu nor cross_nu. - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < bgk->num_cross_collisions; ++i) { assert(!(bgk->collide_with[i]->info.collisions.self_nu)); assert(!(bgk->collide_with[i]->info.collisions.cross_nu[my_idx_in_other[i]])); } - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < bgk->num_cross_collisions; ++i) { double mass_self = gks->info.mass, mass_other = bgk->collide_with[i]->info.mass; - bgk->norm_nu_fac_cross[i] = alpha_E_norm[i] - * (mass_self+mass_other)/(bgk->delta_sr*bgk->betaGreenep1*mass_self); + bgk->norm_nu_fac_cross[i] = alpha_E_norm[i] * (mass_self + mass_other) / + (bgk->delta_sr * bgk->betaGreenep1 * mass_self); - bgk->alpha_E_fac[i] = (bgk->delta_sr*bgk->betaGreenep1*mass_self)/(mass_self+mass_other); + bgk->alpha_E_fac[i] = + (bgk->delta_sr * bgk->betaGreenep1 * mass_self) / (mass_self + mass_other); } // Set pointers to functions chosen at runtime. @@ -422,7 +462,8 @@ gk_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g } // Cross-primitive moment calculator. - bgk->cross_calc = gkyl_gyrokinetic_cross_prim_moms_bgk_new(&gks->basis, &app->basis, app->use_gpu); + bgk->cross_calc = + gkyl_gyrokinetic_cross_prim_moms_bgk_new(&gks->basis, &app->basis, app->use_gpu); // Methods chosen at runtime. bgk->cross_moms_func = gkbgk_cross_moms_enabled; @@ -430,62 +471,70 @@ gk_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g } } -void -gk_species_bgk_moms(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +void gk_species_bgk_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { bgk->moms_func(app, species, bgk, fin); } -void -gk_species_bgk_moms_implicit(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +void gk_species_bgk_moms_implicit( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { bgk->moms_func_implicit(app, species, bgk, fin); } -void -gk_species_bgk_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +void gk_species_bgk_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { // Compute this in bgk_rhs } -void -gk_species_bgk_cross_moms_implicit(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin) +void gk_species_bgk_cross_moms_implicit( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +) { // Compute this in bgk_rhs } -void -gk_species_bgk_rhs(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_species_bgk_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { bgk->rhs_func(app, gks, bgk, fin, 0.0, rhs); } -void -gk_species_bgk_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs) +void gk_species_bgk_rhs_implicit( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs +) { bgk->rhs_func_implicit(app, gks, bgk, fin, dt, rhs); } -void -gk_species_bgk_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_bgk_write_mom( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { gks->bgk.write_mom_func(app, gks, tm, frame); } -void -gk_species_bgk_release(const struct gkyl_gyrokinetic_app *app, const struct gk_bgk_collisions *bgk) +void gk_species_bgk_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_bgk_collisions *bgk +) { if (bgk->collision_id == GKYL_BGK_COLLISIONS) { if (bgk->num_cross_collisions) { gkyl_gyrokinetic_cross_prim_moms_bgk_release(bgk->cross_calc); - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < bgk->num_cross_collisions; ++i) { gkyl_array_release(bgk->cross_nu[i]); } gkyl_array_release(bgk->alpha_E); @@ -501,8 +550,9 @@ gk_species_bgk_release(const struct gkyl_gyrokinetic_app *app, const struct gk_b } } - if (bgk->norm_nu_self) + if (bgk->norm_nu_self) { gkyl_spitzer_coll_freq_release(bgk->spitzer_calc); + } gkyl_array_release(bgk->nu_sum); gkyl_array_release(bgk->self_nu); diff --git a/gyrokinetic/apps/gk_species_collisionless.c b/gyrokinetic/apps/gk_species_collisionless.c index 10fffe3592..85aa5afd21 100644 --- a/gyrokinetic/apps/gk_species_collisionless.c +++ b/gyrokinetic/apps/gk_species_collisionless.c @@ -1,107 +1,118 @@ #include #include -static void -eval_on_nodes_c2p_position_func(const double *xcomp, double *xphys, void *ctx) +static void eval_on_nodes_c2p_position_func(const double *xcomp, double *xphys, void *ctx) { struct gkyl_position_map *gpm = ctx; gkyl_position_map_eval_mc2nu(gpm, xcomp, xphys); } -static void -gk_species_collisionless_flux_disabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin) +static void gk_species_collisionless_flux_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin +) { // Do nothing. } -static void -gk_species_collisionless_flux_enabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin) +static void gk_species_collisionless_flux_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin +) { // Compute the surface expansion of the phase space flux - // Note: Each cell stores the *lower* surface expansions of the + // Note: Each cell stores the *lower* surface expansions of the // phase space flux, so local_ext range needed to index the output // values of flux_surf even though we only loop over local ranges // to avoid evaluating quantities such as geometry in ghost cells // where they are not defined. - gkyl_gk_collisionless_flux_surf(gkcls->surf_flux_op, - &app->local, &species->local, &app->local_ext, &species->local_ext, - species->gyro_phi, fin, gkcls->flux_surf, species->cflrate); + gkyl_gk_collisionless_flux_surf( + gkcls->surf_flux_op, &app->local, &species->local, &app->local_ext, &species->local_ext, + species->gyro_phi, fin, gkcls->flux_surf, species->cflrate + ); } -static void -gk_species_collisionless_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_species_collisionless_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { } -static void -gk_species_collisionless_rhs_enabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_species_collisionless_rhs_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); gkcls->flux_func(app, species, gkcls, fin); - gkyl_dg_updater_gyrokinetic_advance(gkcls->slvr, &species->local, - fin, species->cflrate, rhs); + gkyl_dg_updater_gyrokinetic_advance(gkcls->slvr, &species->local, fin, species->cflrate, rhs); gkcls->fdot_scaling(app, species, gkcls, rhs, species->cflrate, &species->local); app->stat.species_collisionless_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_collisionless_passive_flux(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin) +static void gk_species_collisionless_passive_flux( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin +) { - gkyl_gk_collisionless_passive_flux_surf(gkcls->passive_surf_flux_op, - &app->local, &species->local, &app->local_ext, &species->local_ext, - fin, gkcls->flux_surf, species->cflrate); + gkyl_gk_collisionless_passive_flux_surf( + gkcls->passive_surf_flux_op, &app->local, &species->local, &app->local_ext, &species->local_ext, + fin, gkcls->flux_surf, species->cflrate + ); } -static void -gk_species_collisionless_passive_rhs(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_species_collisionless_passive_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); gkcls->flux_func(app, species, gkcls, fin); - gkyl_dg_updater_gyrokinetic_passive_advance(gkcls->passive_slvr, &species->local, - fin, species->cflrate, rhs); + gkyl_dg_updater_gyrokinetic_passive_advance( + gkcls->passive_slvr, &species->local, fin, species->cflrate, rhs + ); gkcls->fdot_scaling(app, species, gkcls, rhs, species->cflrate, &species->local); app->stat.species_collisionless_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_collisionless_fdot_scaling_disabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_collisionless *gkcls, struct gkyl_array *rhs, struct gkyl_array *cflrate, struct gkyl_range *rng) +static void gk_species_collisionless_fdot_scaling_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls, + struct gkyl_array *rhs, struct gkyl_array *cflrate, struct gkyl_range *rng +) { // Do nothing. } -static void -gk_species_collisionless_fdot_scaling_enabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_collisionless *gkcls, struct gkyl_array *rhs, struct gkyl_array *cflrate, struct gkyl_range *rng) +static void gk_species_collisionless_fdot_scaling_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls, + struct gkyl_array *rhs, struct gkyl_array *cflrate, struct gkyl_range *rng +) { gkyl_array_scale_range(rhs, gkcls->scale_fac, rng); gkyl_array_scale_range(cflrate, gkcls->scale_fac, rng); } -static void -gk_species_collisionless_write_diags_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_collisionless *gkcls, double tm, int frame) +static void gk_species_collisionless_write_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls, double tm, + int frame +) { // Do nothing. } -static void -gk_species_collisionless_write_diags_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_collisionless *gkcls, double tm, int frame) +static void gk_species_collisionless_write_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls, double tm, + int frame +) { struct timespec wst = gkyl_wall_clock(); @@ -109,83 +120,96 @@ gk_species_collisionless_write_diags_enabled(gkyl_gyrokinetic_app* app, struct g gkyl_msgpack_map_elem_set_double(gks->io_meta_phase_len, gks->io_meta_phase, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_phase_len, gks->io_meta_phase, "frame", frame); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Collisionless flux at cell surface." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Collisionless flux at cell surface."} }; int io_meta_len[] = {gks->io_meta_phase_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_phase, app->gk_geom->io_meta_basic, desc}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_phase, app->gk_geom->io_meta_basic, desc + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); // Write gkcls->flux_surf const char *fmt = "%s-%s_collisionless_surf_flux_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, frame); gkyl_array_copy(gkcls->flux_surf_ho, gkcls->flux_surf); - gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt, - gkcls->flux_surf_ho, fileNm); + gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt, gkcls->flux_surf_ho, fileNm); gkyl_msgpack_data_release(mt); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); app->stat.n_io += 1; } -static void -gk_species_collisionless_init_passive(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_collisionless *gkcls, const bool *is_zero_flux, - const enum gkyl_gyrokinetic_bc_type *bctype_conf, const struct gkyl_basis *surf_basis) +static void gk_species_collisionless_init_passive( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls, + const bool *is_zero_flux, const enum gkyl_gyrokinetic_bc_type *bctype_conf, + const struct gkyl_basis *surf_basis +) { int cdim = app->cdim; gkcls->flux_surf = mkarr(app->use_gpu, cdim * surf_basis->num_basis, gks->local_ext.volume); gkcls->passive_speeds = mkarr(app->use_gpu, cdim * app->basis.num_basis, app->local_ext.volume); - gkcls->passive_speeds_ho = app->use_gpu? mkarr(false, gkcls->passive_speeds->ncomp, gkcls->passive_speeds->size) - : gkyl_array_acquire(gkcls->passive_speeds); + gkcls->passive_speeds_ho = + app->use_gpu ? mkarr(false, gkcls->passive_speeds->ncomp, gkcls->passive_speeds->size) : + gkyl_array_acquire(gkcls->passive_speeds); - struct gkyl_eval_on_nodes *speeds_proj = gkyl_eval_on_nodes_inew(&(struct gkyl_eval_on_nodes_inp){ - .grid = &app->grid, + struct gkyl_eval_on_nodes *speeds_proj = gkyl_eval_on_nodes_inew(&(struct gkyl_eval_on_nodes_inp + ){.grid = &app->grid, .basis = &app->basis, .num_ret_vals = cdim, .eval = gks->info.collisionless.passive_speeds, .ctx = gks->info.collisionless.passive_speeds_ctx, .c2p_func = eval_on_nodes_c2p_position_func, - .c2p_func_ctx = app->position_map, - }); + .c2p_func_ctx = app->position_map}); gkyl_eval_on_nodes_advance(speeds_proj, 0.0, &app->local, gkcls->passive_speeds_ho); gkyl_eval_on_nodes_release(speeds_proj); gkyl_array_copy(gkcls->passive_speeds, gkcls->passive_speeds_ho); // Sync speeds. int num_periodic_dir = app->num_periodic_dir; - gkyl_comm_array_per_sync(app->comm, &app->local, &app->local_ext, - num_periodic_dir, app->periodic_dirs, gkcls->passive_speeds); + gkyl_comm_array_per_sync( + app->comm, &app->local, &app->local_ext, num_periodic_dir, app->periodic_dirs, + gkcls->passive_speeds + ); gkyl_comm_array_sync(app->comm, &app->local, &app->local_ext, gkcls->passive_speeds); - gkcls->passive_surf_flux_op = gkyl_gk_collisionless_passive_flux_new(&gks->grid, &app->basis, &gks->basis, - gkcls->passive_speeds, gks->info.charge, gks->info.mass, - app->gk_geom, app->dg_geom, app->gk_dg_geom, gks->vel_map, bctype_conf, app->use_gpu); + gkcls->passive_surf_flux_op = gkyl_gk_collisionless_passive_flux_new( + &gks->grid, &app->basis, &gks->basis, gkcls->passive_speeds, gks->info.charge, gks->info.mass, + app->gk_geom, app->dg_geom, app->gk_dg_geom, gks->vel_map, bctype_conf, app->use_gpu + ); struct gkyl_dg_gyrokinetic_passive_auxfields passive_aux = { - .flux_surf = gkcls->flux_surf, - .speeds = gkcls->passive_speeds, + .flux_surf = gkcls->flux_surf, .speeds = gkcls->passive_speeds }; - gkcls->passive_slvr = gkyl_dg_updater_gyrokinetic_passive_new(&gks->grid, &app->basis, &gks->basis, - &app->local, &gks->local, is_zero_flux, gks->info.charge, gks->info.mass, - app->gk_geom, gks->vel_map, &passive_aux, app->use_gpu); + gkcls->passive_slvr = gkyl_dg_updater_gyrokinetic_passive_new( + &gks->grid, &app->basis, &gks->basis, &app->local, &gks->local, is_zero_flux, gks->info.charge, + gks->info.mass, app->gk_geom, gks->vel_map, &passive_aux, app->use_gpu + ); if (gkcls->write_diagnostics) { gkyl_msgpack_map_elem_set_double(gks->io_meta_conf_len, gks->io_meta_conf, "time", 0.0); gkyl_msgpack_map_elem_set_uint(gks->io_meta_conf_len, gks->io_meta_conf, "frame", 0); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Conf-space passive advection speeds." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Conf-space passive advection speeds."} }; int io_meta_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); const char *fmt = "%s-%s_passive_speeds_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, 0); - char fileNm[sz+1]; + char fileNm[sz + 1]; snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, 0); gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, gkcls->passive_speeds_ho, fileNm); @@ -193,12 +217,12 @@ gk_species_collisionless_init_passive(struct gkyl_gyrokinetic_app *app, struct g } gkcls->flux_func = gk_species_collisionless_passive_flux; - gkcls->rhs_func = gk_species_collisionless_passive_rhs; + gkcls->rhs_func = gk_species_collisionless_passive_rhs; } -void -gk_species_collisionless_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_collisionless *gkcls) +void gk_species_collisionless_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls +) { gkcls->collisionless_id = gks->info.collisionless.type; gkcls->write_diagnostics = gks->info.collisionless.write_diagnostics; @@ -208,18 +232,19 @@ gk_species_collisionless_init(struct gkyl_gyrokinetic_app *app, struct gk_specie gkcls->rhs_func = gk_species_collisionless_rhs_disabled; if (gkcls->collisionless_id) { - int cdim = app->cdim, vdim = gks->info.vdim; - int pdim = cdim+vdim; + int pdim = cdim + vdim; // Determine which directions are zero-flux. By default // we do not have zero-flux boundary conditions in any direction. - bool is_zero_flux[2*GKYL_MAX_DIM] = {false}; - for (int dir=0; dircdim; ++dir) { - if (gks->lower_bc[dir].type == GKYL_BC_GK_SPECIES_ZERO_FLUX) + bool is_zero_flux[2 * GKYL_MAX_DIM] = {false}; + for (int dir = 0; dir < app->cdim; ++dir) { + if (gks->lower_bc[dir].type == GKYL_BC_GK_SPECIES_ZERO_FLUX) { is_zero_flux[dir] = true; - if (gks->upper_bc[dir].type == GKYL_BC_GK_SPECIES_ZERO_FLUX) - is_zero_flux[dir+pdim] = true; + } + if (gks->upper_bc[dir].type == GKYL_BC_GK_SPECIES_ZERO_FLUX) { + is_zero_flux[dir + pdim] = true; + } } // Need to figure out size of flux_surf by finding size of surface basis set @@ -227,53 +252,57 @@ gk_species_collisionless_init(struct gkyl_gyrokinetic_app *app, struct gk_specie struct gkyl_basis surf_vpar_basis; // Define surface bases if (app->poly_order > 1) { - gkyl_cart_modal_serendip(&surf_basis, pdim-1, app->poly_order); - } - else { - gkyl_cart_modal_serendip(&surf_vpar_basis, pdim-1, app->poly_order); - if (vdim>1) { - gkyl_cart_modal_gkhybrid(&surf_basis, cdim-1, vdim); // p=2 in vparallel - } - else { - gkyl_cart_modal_serendip(&surf_basis, pdim-1, 2); // p=2 in vparallel + gkyl_cart_modal_serendip(&surf_basis, pdim - 1, app->poly_order); + } else { + gkyl_cart_modal_serendip(&surf_vpar_basis, pdim - 1, app->poly_order); + if (vdim > 1) { + gkyl_cart_modal_gkhybrid(&surf_basis, cdim - 1, vdim); // p=2 in vparallel + } else { + gkyl_cart_modal_serendip(&surf_basis, pdim - 1, 2); // p=2 in vparallel } } - enum gkyl_gyrokinetic_bc_type bctype_conf[2*GKYL_MAX_CDIM]; - for (int d=0; dcdim; d++) { + enum gkyl_gyrokinetic_bc_type bctype_conf[2 * GKYL_MAX_CDIM]; + for (int d = 0; d < app->cdim; d++) { bctype_conf[d] = gks->lower_bc[d].type; - bctype_conf[GKYL_MAX_CDIM+d] = gks->upper_bc[d].type; + bctype_conf[GKYL_MAX_CDIM + d] = gks->upper_bc[d].type; } if (gkcls->collisionless_id == GKYL_GK_COLLISIONLESS_PASSIVE) { gk_species_collisionless_init_passive(app, gks, gkcls, is_zero_flux, bctype_conf, &surf_basis); } else { // Allocate arrays to store surface phase space flux. - gkcls->flux_surf = mkarr(app->use_gpu, - cdim*surf_basis.num_basis + surf_vpar_basis.num_basis, gks->local_ext.volume); + gkcls->flux_surf = mkarr( + app->use_gpu, cdim * surf_basis.num_basis + surf_vpar_basis.num_basis, gks->local_ext.volume + ); if (gkcls->collisionless_id == GKYL_GK_COLLISIONLESS_EM_BPERP) { // Parallel component of magnetic vector potential. gkcls->apar = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); gkcls->apardot = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - } - else { - gkcls->apar = gkyl_array_acquire(app->field->phi_smooth); // Not used. + } else { + gkcls->apar = gkyl_array_acquire(app->field->phi_smooth); // Not used. gkcls->apardot = gkyl_array_acquire(app->field->phi_smooth); // Not used. } - gkcls->surf_flux_op = gkyl_gk_collisionless_flux_new(&gks->grid, &app->basis, &gks->basis, - gks->info.charge, gks->info.mass, - gkcls->collisionless_id, app->gk_geom, - app->dg_geom, app->gk_dg_geom, gks->vel_map, bctype_conf, app->use_gpu); - - struct gkyl_dg_gyrokinetic_auxfields aux_inp = { .flux_surf = gkcls->flux_surf, - .phi = gks->gyro_phi, .apar = gkcls->apar, .apardot = gkcls->apardot }; + gkcls->surf_flux_op = gkyl_gk_collisionless_flux_new( + &gks->grid, &app->basis, &gks->basis, gks->info.charge, gks->info.mass, + gkcls->collisionless_id, app->gk_geom, app->dg_geom, app->gk_dg_geom, gks->vel_map, + bctype_conf, app->use_gpu + ); + + struct gkyl_dg_gyrokinetic_auxfields aux_inp = { + .flux_surf = gkcls->flux_surf, + .phi = gks->gyro_phi, + .apar = gkcls->apar, + .apardot = gkcls->apardot + }; // Create solver. - gkcls->slvr = gkyl_dg_updater_gyrokinetic_new(&gks->grid, &app->basis, &gks->basis, - &app->local, &gks->local, is_zero_flux, gks->info.charge, gks->info.mass, - gkcls->collisionless_id, app->gk_geom, gks->vel_map, - &aux_inp, app->use_gpu); + gkcls->slvr = gkyl_dg_updater_gyrokinetic_new( + &gks->grid, &app->basis, &gks->basis, &app->local, &gks->local, is_zero_flux, + gks->info.charge, gks->info.mass, gkcls->collisionless_id, app->gk_geom, gks->vel_map, + &aux_inp, app->use_gpu + ); gkcls->flux_func = gk_species_collisionless_flux_enabled; gkcls->rhs_func = gk_species_collisionless_rhs_enabled; @@ -293,32 +322,35 @@ gk_species_collisionless_init(struct gkyl_gyrokinetic_app *app, struct gk_specie } } -void -gk_species_collisionless_flux(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin) +void gk_species_collisionless_flux( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin +) { gkcls->flux_func(app, species, gkcls, fin); } -void -gk_species_collisionless_rhs(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_species_collisionless_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { gkcls->rhs_func(app, species, gkcls, fin, rhs); } -void -gk_species_collisionless_write_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_collisionless *gkcls, double tm, int frame) +void gk_species_collisionless_write_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls, double tm, + int frame +) { gkcls->write_diags_func(app, gks, gkcls, tm, frame); } -void -gk_species_collisionless_release(const struct gkyl_gyrokinetic_app *app, const struct gk_collisionless *gkcls) +void gk_species_collisionless_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_collisionless *gkcls +) { if (gkcls->collisionless_id) { - gkyl_array_release(gkcls->flux_surf); if (gkcls->collisionless_id == GKYL_GK_COLLISIONLESS_PASSIVE) { @@ -339,9 +371,10 @@ gk_species_collisionless_release(const struct gkyl_gyrokinetic_app *app, const s } } -void -gk_species_collisionless_reset(gkyl_gyrokinetic_app* app, double tm, struct gk_species *gks, - struct gk_collisionless *gkcls, struct gkyl_gyrokinetic_collisionless gkcls_inp) +void gk_species_collisionless_reset( + gkyl_gyrokinetic_app *app, double tm, struct gk_species *gks, struct gk_collisionless *gkcls, + struct gkyl_gyrokinetic_collisionless gkcls_inp +) { gkcls->scale_fac = 1.0; gkcls->fdot_scaling = gk_species_collisionless_fdot_scaling_disabled; diff --git a/gyrokinetic/apps/gk_species_damping.c b/gyrokinetic/apps/gk_species_damping.c index 16669672d2..f1347a8ba0 100644 --- a/gyrokinetic/apps/gk_species_damping.c +++ b/gyrokinetic/apps/gk_species_damping.c @@ -4,69 +4,76 @@ #include #include -void -gk_species_damping_write_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_damping_write_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { } -void -gk_species_damping_write_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_damping_write_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { struct timespec wst = gkyl_wall_clock(); // DG metadata for damping rate. struct gkyl_msgpack_map_elem mpe_drate[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = "serendipity" }, - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Rate of the damping term." }, - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = tm }, - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = frame }, + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = "serendipity"}, + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Rate of the damping term."}, + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = tm}, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = frame} }; - int mpe_drate_len = sizeof(mpe_drate)/sizeof(mpe_drate[0]); + int mpe_drate_len = sizeof(mpe_drate) / sizeof(mpe_drate[0]); // Package metadata. int io_meta_len[] = {gks->io_meta_basic_len, mpe_drate_len, app->gk_geom->io_meta_basic_len}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, mpe_drate, app->gk_geom->io_meta_basic}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, mpe_drate, app->gk_geom->io_meta_basic + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); // Write out the damping rate. const char *fmt = "%s-%s_damping_rate_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, frame); // Copy data from device to host before writing it out. - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(gks->damping.rate_host, gks->damping.rate); + } gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt, gks->damping.rate_host, fileNm); app->stat.n_io += 1; - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); } -void -gk_species_damping_write_init_only(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_damping_write_init_only( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { gk_species_damping_write_enabled(app, gks, tm, frame); gks->damping.write_func = gk_species_damping_write_disabled; } -static void -proj_on_basis_c2p_phase_func(const double *xcomp, double *xphys, void *ctx) +static void proj_on_basis_c2p_phase_func(const double *xcomp, double *xphys, void *ctx) { struct gk_proj_on_basis_c2p_func_ctx *c2p_ctx = ctx; int cdim = c2p_ctx->cdim; // Assumes update range is a phase range. gkyl_velocity_map_eval_c2p(c2p_ctx->vel_map, &xcomp[cdim], &xphys[cdim]); } -void -gk_species_damping_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_damping *damp) +void gk_species_damping_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_damping *damp +) { damp->type = gks->info.damping.type; damp->evolve = false; // Whether the rate is time dependent. - int num_quad = gks->info.damping.num_quad? gks->info.damping.num_quad : 1; // Default is a p=0 mask. + int num_quad = gks->info.damping.num_quad ? gks->info.damping.num_quad : + 1; // Default is a p=0 mask. assert(num_quad == 1); // MF 2025/06/11: Limited to this for now. // Default function pointers. @@ -74,75 +81,81 @@ gk_species_damping_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks if (damp->type) { // Allocate rate array. - damp->rate = mkarr(app->use_gpu, num_quad==1? 1 : gks->basis.num_basis, gks->local_ext.volume); + damp->rate = + mkarr(app->use_gpu, num_quad == 1 ? 1 : gks->basis.num_basis, gks->local_ext.volume); damp->rate_host = damp->rate; - if (app->use_gpu) - damp->rate_host = mkarr(false, damp->rate->ncomp, damp->rate->size); + if (app->use_gpu) { + damp->rate_host = mkarr(false, damp->rate->ncomp, damp->rate->size); + } if (damp->type == GKYL_GK_DAMPING_USER_INPUT) { struct gk_proj_on_basis_c2p_func_ctx proj_on_basis_c2p_ctx; // c2p function context. proj_on_basis_c2p_ctx.cdim = app->cdim; proj_on_basis_c2p_ctx.vdim = gks->local_vel.ndim; proj_on_basis_c2p_ctx.vel_map = gks->vel_map; - gkyl_proj_on_basis *projup = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &gks->grid, - .basis = &gks->basis, - .num_quad = num_quad, - .num_ret_vals = 1, - .eval = gks->info.damping.rate_profile, - .ctx = gks->info.damping.rate_profile_ctx, - .c2p_func = proj_on_basis_c2p_phase_func, - .c2p_func_ctx = &proj_on_basis_c2p_ctx, - } - ); + gkyl_proj_on_basis *projup = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &gks->grid, + .basis = &gks->basis, + .num_quad = num_quad, + .num_ret_vals = 1, + .eval = gks->info.damping.rate_profile, + .ctx = gks->info.damping.rate_profile_ctx, + .c2p_func = proj_on_basis_c2p_phase_func, + .c2p_func_ctx = &proj_on_basis_c2p_ctx}); gkyl_proj_on_basis_advance(projup, 0.0, &gks->local, damp->rate_host); gkyl_proj_on_basis_release(projup); gkyl_array_copy(damp->rate, damp->rate_host); - if (num_quad == 1) - gkyl_array_scale_range(damp->rate, 1.0/pow(sqrt(2.0),gks->grid.ndim), &gks->local); - } - else if (damp->type == GKYL_GK_DAMPING_LOSS_CONE) { + if (num_quad == 1) { + gkyl_array_scale_range(damp->rate, 1.0 / pow(sqrt(2.0), gks->grid.ndim), &gks->local); + } + } else if (damp->type == GKYL_GK_DAMPING_LOSS_CONE) { damp->evolve = true; // Since the loss cone boundary is proportional to phi(t). // Maximum bmag and its location. // NOTE: if the same max bmag occurs at multiple locations, // bmag_max_coord may have different values on different MPI processes. double bmag_max_coord_ho[GKYL_MAX_CDIM]; - double bmag_max_ho = gkyl_gk_geometry_reduce_arg_bmag(app->gk_geom, GKYL_MAX, bmag_max_coord_ho); + double bmag_max_ho = + gkyl_gk_geometry_reduce_arg_bmag(app->gk_geom, GKYL_MAX, bmag_max_coord_ho); double bmag_max_local = bmag_max_ho; double bmag_max_global; - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 1, &bmag_max_local, &bmag_max_global); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, 1, &bmag_max_local, &bmag_max_global + ); double bmag_max_coord_local[app->cdim], bmag_max_coord_global[app->cdim]; if (fabs(bmag_max_ho - bmag_max_global) < 1e-16) { - for (int d=0; dcdim; d++) + for (int d = 0; d < app->cdim; d++) { bmag_max_coord_local[d] = bmag_max_coord_ho[d]; - } - else { - for (int d=0; dcdim; d++) + } + } else { + for (int d = 0; d < app->cdim; d++) { bmag_max_coord_local[d] = -DBL_MAX; + } } - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, app->cdim, bmag_max_coord_local, bmag_max_coord_global); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, app->cdim, bmag_max_coord_local, bmag_max_coord_global + ); if (app->use_gpu) { damp->bmag_max = gkyl_cu_malloc(sizeof(double)); - damp->bmag_max_coord = gkyl_cu_malloc(app->cdim*sizeof(double)); - gkyl_cu_memcpy(damp->bmag_max, &bmag_max_global, sizeof(double), GKYL_CU_MEMCPY_H2D); - gkyl_cu_memcpy(damp->bmag_max_coord, bmag_max_coord_ho, app->cdim*sizeof(double), GKYL_CU_MEMCPY_H2D); - } - else { + damp->bmag_max_coord = gkyl_cu_malloc(app->cdim * sizeof(double)); + gkyl_cu_memcpy(damp->bmag_max, &bmag_max_global, sizeof(double), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + damp->bmag_max_coord, bmag_max_coord_ho, app->cdim * sizeof(double), GKYL_CU_MEMCPY_H2D + ); + } else { damp->bmag_max = gkyl_malloc(sizeof(double)); - damp->bmag_max_coord = gkyl_malloc(app->cdim*sizeof(double)); - memcpy(damp->bmag_max, &bmag_max_global, sizeof(double)); - memcpy(damp->bmag_max_coord, bmag_max_coord_ho, app->cdim*sizeof(double)); + damp->bmag_max_coord = gkyl_malloc(app->cdim * sizeof(double)); + memcpy(damp->bmag_max, &bmag_max_global, sizeof(double)); + memcpy(damp->bmag_max_coord, bmag_max_coord_ho, app->cdim * sizeof(double)); } // Electrostatic potential at bmag_max_coord. if (app->use_gpu) { damp->phi_m = gkyl_cu_malloc(sizeof(double)); damp->phi_m_global = gkyl_cu_malloc(sizeof(double)); - } - else { + } else { damp->phi_m = gkyl_malloc(sizeof(double)); damp->phi_m_global = gkyl_malloc(sizeof(double)); } @@ -152,9 +165,9 @@ gk_species_damping_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks .phase_grid = &gks->grid, .conf_basis = &app->basis, .phase_basis = &gks->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, - .vel_range = &gks->local_vel, + .vel_range = &gks->local_vel, .vel_map = gks->vel_map, .bmag = app->gk_geom->geo_int.bmag, .bmag_max = damp->bmag_max, @@ -162,35 +175,46 @@ gk_species_damping_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks .mass = gks->info.mass, .charge = gks->info.charge, .num_quad = num_quad, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - damp->lcm_proj_op = gkyl_loss_cone_mask_gyrokinetic_inew( &inp_proj ); + damp->lcm_proj_op = gkyl_loss_cone_mask_gyrokinetic_inew(&inp_proj); // Project the conf-space rate profile provided. - struct gkyl_array *scale_prof_high_order = mkarr(app->use_gpu, gks->basis.num_basis, gks->local_ext.volume); - struct gkyl_array *scale_prof_high_order_ho = app->use_gpu? mkarr(false, scale_prof_high_order->ncomp, scale_prof_high_order->size) - : gkyl_array_acquire(scale_prof_high_order); - - gkyl_proj_on_basis *projup = gkyl_proj_on_basis_new(&gks->grid, &gks->basis, num_quad, 1, - gks->info.damping.rate_profile, gks->info.damping.rate_profile_ctx); + struct gkyl_array *scale_prof_high_order = + mkarr(app->use_gpu, gks->basis.num_basis, gks->local_ext.volume); + struct gkyl_array *scale_prof_high_order_ho = + app->use_gpu ? mkarr(false, scale_prof_high_order->ncomp, scale_prof_high_order->size) : + gkyl_array_acquire(scale_prof_high_order); + + gkyl_proj_on_basis *projup = gkyl_proj_on_basis_new( + &gks->grid, &gks->basis, num_quad, 1, gks->info.damping.rate_profile, + gks->info.damping.rate_profile_ctx + ); gkyl_proj_on_basis_advance(projup, 0.0, &gks->local, scale_prof_high_order_ho); gkyl_proj_on_basis_release(projup); gkyl_array_copy(scale_prof_high_order, scale_prof_high_order_ho); - damp->scale_prof = mkarr(app->use_gpu, num_quad == 1? 1 : gks->basis.num_basis, gks->local_ext.volume); - gkyl_array_set_offset(damp->scale_prof, pow(sqrt(2.0),gks->grid.ndim), scale_prof_high_order, 0); + damp->scale_prof = + mkarr(app->use_gpu, num_quad == 1 ? 1 : gks->basis.num_basis, gks->local_ext.volume); + gkyl_array_set_offset( + damp->scale_prof, pow(sqrt(2.0), gks->grid.ndim), scale_prof_high_order, 0 + ); gkyl_array_release(scale_prof_high_order_ho); gkyl_array_release(scale_prof_high_order); // Compute the initial damping rate (assuming phi=0 because phi hasn't been computed). // Find the potential at the mirror throat. - gkyl_dg_basis_ops_eval_array_at_coord_comp(app->field->phi_smooth, damp->bmag_max_coord, - app->basis_on_dev, &app->grid, &app->local, damp->phi_m); + gkyl_dg_basis_ops_eval_array_at_coord_comp( + app->field->phi_smooth, damp->bmag_max_coord, app->basis_on_dev, &app->grid, &app->local, + damp->phi_m + ); gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_MAX, 1, damp->phi_m, damp->phi_m_global); // Project the loss cone mask. - gkyl_loss_cone_mask_gyrokinetic_advance(damp->lcm_proj_op, &gks->local, &app->local, - app->field->phi_smooth, damp->phi_m_global, damp->rate); + gkyl_loss_cone_mask_gyrokinetic_advance( + damp->lcm_proj_op, &gks->local, &app->local, app->field->phi_smooth, damp->phi_m_global, + damp->rate + ); // Multiply by the user's scaling profile. gkyl_array_scale_by_cell(damp->rate, damp->scale_prof); } @@ -198,17 +222,17 @@ gk_species_damping_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks // Set function pointers chosen at runtime. if (damp->evolve) { damp->write_func = gk_species_damping_write_enabled; - } - else { + } else { damp->write_func = gk_species_damping_write_init_only; } } } -void -gk_species_damping_advance(gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_damping *damp, +void gk_species_damping_advance( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_damping *damp, const struct gkyl_array *phi, const struct gkyl_array *fin, struct gkyl_array *f_buffer, - struct gkyl_array *rhs, struct gkyl_array *cflrate) + struct gkyl_array *rhs, struct gkyl_array *cflrate +) { if (damp->type) { struct timespec wst = gkyl_wall_clock(); @@ -216,23 +240,23 @@ gk_species_damping_advance(gkyl_gyrokinetic_app *app, const struct gk_species *g gkyl_array_set(f_buffer, 1.0, fin); gkyl_array_scale_by_cell(f_buffer, damp->rate); gkyl_array_accumulate(rhs, -1.0, f_buffer); - } - else if (damp->type == GKYL_GK_DAMPING_LOSS_CONE) { + } else if (damp->type == GKYL_GK_DAMPING_LOSS_CONE) { // Find the potential at the mirror throat. - gkyl_dg_basis_ops_eval_array_at_coord_comp(phi, damp->bmag_max_coord, - app->basis_on_dev, &app->grid, &app->local, damp->phi_m); + gkyl_dg_basis_ops_eval_array_at_coord_comp( + phi, damp->bmag_max_coord, app->basis_on_dev, &app->grid, &app->local, damp->phi_m + ); gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_MAX, 1, damp->phi_m, damp->phi_m_global); // Project the loss cone mask. - gkyl_loss_cone_mask_gyrokinetic_advance(damp->lcm_proj_op, &gks->local, &app->local, - phi, damp->phi_m_global, damp->rate); + gkyl_loss_cone_mask_gyrokinetic_advance( + damp->lcm_proj_op, &gks->local, &app->local, phi, damp->phi_m_global, damp->rate + ); // Assemble the damping term -scale_prof * mask * f. gkyl_array_set(f_buffer, 1.0, fin); gkyl_array_scale_by_cell(damp->rate, damp->scale_prof); gkyl_array_scale_by_cell(f_buffer, damp->rate); gkyl_array_accumulate(rhs, -1.0, f_buffer); - } // Add the frequency to the CFL frequency. @@ -242,31 +266,32 @@ gk_species_damping_advance(gkyl_gyrokinetic_app *app, const struct gk_species *g } } -void -gk_species_damping_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_damping_write( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { gks->damping.write_func(app, gks, tm, frame); } -void -gk_species_damping_release(const struct gkyl_gyrokinetic_app *app, const struct gk_damping *damp) +void gk_species_damping_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_damping *damp +) { if (damp->type) { gkyl_array_release(damp->rate); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_release(damp->rate_host); + } if (damp->type == GKYL_GK_DAMPING_USER_INPUT) { // Nothing to release. - } - else if (damp->type == GKYL_GK_DAMPING_LOSS_CONE) { + } else if (damp->type == GKYL_GK_DAMPING_LOSS_CONE) { if (app->use_gpu) { gkyl_cu_free(damp->bmag_max); gkyl_cu_free(damp->bmag_max_coord); gkyl_cu_free(damp->phi_m); gkyl_cu_free(damp->phi_m_global); - } - else { + } else { gkyl_free(damp->bmag_max); gkyl_free(damp->bmag_max_coord); gkyl_free(damp->phi_m); diff --git a/gyrokinetic/apps/gk_species_fdot_multiplier.c b/gyrokinetic/apps/gk_species_fdot_multiplier.c index c24e77bfd5..f71d5611d8 100644 --- a/gyrokinetic/apps/gk_species_fdot_multiplier.c +++ b/gyrokinetic/apps/gk_species_fdot_multiplier.c @@ -4,32 +4,37 @@ #include #include -static void -gk_species_fdot_multiplier_write_disabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult, double tm, int frame) +static void gk_species_fdot_multiplier_write_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + double tm, int frame +) { } -static void -gk_species_fdot_multiplier_write_enabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult, double tm, int frame) +static void gk_species_fdot_multiplier_write_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + double tm, int frame +) { struct timespec wst = gkyl_wall_clock(); // DG metadata for multiplier. struct gkyl_msgpack_map_elem mpe_mult[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = "serendipity" }, - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Function multiplying the distribution time derivative." }, - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = tm }, - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = frame }, + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = "serendipity"}, + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Function multiplying the distribution time derivative."}, + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = tm}, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = frame} }; int mpe_mult_len = sizeof(mpe_mult) / sizeof(mpe_mult[0]); // Package metadata. - int io_meta_len[] = { gks->io_meta_basic_len, mpe_mult_len, app->gk_geom->io_meta_basic_len }; - const struct gkyl_msgpack_map_elem *io_meta[] = { gks->io_meta_basic, mpe_mult, - app->gk_geom->io_meta_basic }; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), - io_meta_len, io_meta); + int io_meta_len[] = {gks->io_meta_basic_len, mpe_mult_len, app->gk_geom->io_meta_basic_len}; + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, mpe_mult, app->gk_geom->io_meta_basic + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); // Write out the combined multiplier. const char *fmt = "%s-%s_fdot_multiplier_%d.gkyl"; @@ -42,8 +47,7 @@ gk_species_fdot_multiplier_write_enabled(gkyl_gyrokinetic_app *app, struct gk_sp gkyl_array_copy(fdot_mult->multiplier_host, fdot_mult->multiplier); } - gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt, fdot_mult->multiplier_host, - fileNm); + gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt, fdot_mult->multiplier_host, fileNm); app->stat.n_io += 1; gkyl_msgpack_data_release(mt); @@ -51,17 +55,17 @@ gk_species_fdot_multiplier_write_enabled(gkyl_gyrokinetic_app *app, struct gk_sp app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_fdot_multiplier_advance_times_cfl_disabled(gkyl_gyrokinetic_app *app, - struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, - const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *cflrate) +static void gk_fdot_multiplier_advance_times_cfl_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *cflrate +) { } -static void -gk_fdot_multiplier_advance_times_cfl_enabled(gkyl_gyrokinetic_app *app, - struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, - const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *cflrate) +static void gk_fdot_multiplier_advance_times_cfl_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *cflrate +) { struct timespec wst = gkyl_wall_clock(); @@ -76,17 +80,17 @@ gk_fdot_multiplier_advance_times_cfl_enabled(gkyl_gyrokinetic_app *app, app->stat.species_fdot_mult_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_fdot_multiplier_advance_times_rate_disabled(gkyl_gyrokinetic_app *app, - struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, - const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *rhs) +static void gk_fdot_multiplier_advance_times_rate_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *rhs +) { } -static void -gk_fdot_multiplier_advance_times_rate_enabled(gkyl_gyrokinetic_app *app, - struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, - const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *rhs) +static void gk_fdot_multiplier_advance_times_rate_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); @@ -95,45 +99,50 @@ gk_fdot_multiplier_advance_times_rate_enabled(gkyl_gyrokinetic_app *app, app->stat.species_fdot_mult_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_fdot_multiplier_advance_disabled(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *phi, const struct gkyl_array *f, - const struct gkyl_array *cflrate, struct gkyl_array *combined_multiplier) +static void gk_species_fdot_multiplier_advance_disabled( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_array *phi, const struct gkyl_array *f, const struct gkyl_array *cflrate, + struct gkyl_array *combined_multiplier +) { } // Advance: multiply combined_multiplier by this component's precomputed buffer array. -static void -gk_species_fdot_multiplier_advance_mult(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *phi, const struct gkyl_array *f, - const struct gkyl_array *cflrate, struct gkyl_array *combined_multiplier) +static void gk_species_fdot_multiplier_advance_mult( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_array *phi, const struct gkyl_array *f, const struct gkyl_array *cflrate, + struct gkyl_array *combined_multiplier +) { gkyl_array_scale_by_cell(combined_multiplier, fdmul->buffer); } // Advance: apply constant scale to combined_multiplier. -static void -gk_species_fdot_multiplier_advance_const(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *phi, const struct gkyl_array *f, - const struct gkyl_array *cflrate, struct gkyl_array *combined_multiplier) +static void gk_species_fdot_multiplier_advance_const( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_array *phi, const struct gkyl_array *f, const struct gkyl_array *cflrate, + struct gkyl_array *combined_multiplier +) { gkyl_array_scale(combined_multiplier, fdmul->time_dilation_scale_const); } -static void -gk_species_fdot_multiplier_advance_loss_cone_mult(gkyl_gyrokinetic_app *app, - const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *phi, - const struct gkyl_array *f, const struct gkyl_array *cflrate, - struct gkyl_array *combined_multiplier) +static void gk_species_fdot_multiplier_advance_loss_cone_mult( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_array *phi, const struct gkyl_array *f, const struct gkyl_array *cflrate, + struct gkyl_array *combined_multiplier +) { // Find the potential at the mirror throat. - gkyl_dg_basis_ops_eval_array_at_coord_comp(phi, fdmul->bmag_max_coord, - app->basis_on_dev, &app->grid, &app->local, fdmul->phi_m); + gkyl_dg_basis_ops_eval_array_at_coord_comp( + phi, fdmul->bmag_max_coord, app->basis_on_dev, &app->grid, &app->local, fdmul->phi_m + ); gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_MAX, 1, fdmul->phi_m, fdmul->phi_m_global); // Project the loss cone mask into buffer. - gkyl_loss_cone_mask_gyrokinetic_advance(fdmul->lcm_proj_op, &gks->local, &app->local, - phi, fdmul->phi_m_global, fdmul->buffer); + gkyl_loss_cone_mask_gyrokinetic_advance( + fdmul->lcm_proj_op, &gks->local, &app->local, phi, fdmul->phi_m_global, fdmul->buffer + ); // Apply constant scale factor. gkyl_array_scale(fdmul->buffer, fdmul->time_dilation_scale_const); @@ -144,9 +153,10 @@ gk_species_fdot_multiplier_advance_loss_cone_mult(gkyl_gyrokinetic_app *app, // Compute cell-wise clamp factor min(1, omega_max/cflrate)*scale into combined_multiplier. // Hopkins, P. F., & Most, E. R. (2025). Time-Dilation Methods for Extreme Multiscale Timestepping Problems. arXiv:2510.09756. -static double -compute_global_array_max(const gkyl_gyrokinetic_app *app, - const struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *array) +static double compute_global_array_max( + const gkyl_gyrokinetic_app *app, const struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_array *array +) { double local_max; if (app->use_gpu) { @@ -154,8 +164,7 @@ compute_global_array_max(const gkyl_gyrokinetic_app *app, gkyl_array_reduce(fdmul->omega_max_local_cu, array, GKYL_MAX); gkyl_cu_memcpy(&local_max, fdmul->omega_max_local_cu, sizeof(double), GKYL_CU_MEMCPY_D2H); #endif - } - else { + } else { gkyl_array_reduce(&local_max, array, GKYL_MAX); } double global_max = DBL_MAX; @@ -163,9 +172,10 @@ compute_global_array_max(const gkyl_gyrokinetic_app *app, return global_max; } -static void -clamp_cflrate_by_omega_max(const struct gk_fdot_multiplier_comp *fdmul, const double omega_max, - const struct gkyl_array *cflrate, struct gkyl_array *combined_multiplier) +static void clamp_cflrate_by_omega_max( + const struct gk_fdot_multiplier_comp *fdmul, const double omega_max, + const struct gkyl_array *cflrate, struct gkyl_array *combined_multiplier +) { // buffer = min(1, omega_max/cflrate) * time_dilation_scale_const gkyl_array_invert_by_cell(fdmul->buffer, cflrate); @@ -175,56 +185,57 @@ clamp_cflrate_by_omega_max(const struct gk_fdot_multiplier_comp *fdmul, const do gkyl_array_scale_by_cell(combined_multiplier, fdmul->buffer); } -static void -gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_omegaH(gkyl_gyrokinetic_app *app, - const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *phi, - const struct gkyl_array *f, const struct gkyl_array *cflrate, - struct gkyl_array *combined_multiplier) +static void gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_omegaH( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_array *phi, const struct gkyl_array *f, const struct gkyl_array *cflrate, + struct gkyl_array *combined_multiplier +) { double omega_max = 1.0 / gks->dt_omegaH; clamp_cflrate_by_omega_max(fdmul, omega_max, cflrate, combined_multiplier); } -static void -gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_user_specified(gkyl_gyrokinetic_app *app, - const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *phi, - const struct gkyl_array *f, const struct gkyl_array *cflrate, - struct gkyl_array *combined_multiplier) +static void gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_user_specified( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_array *phi, const struct gkyl_array *f, const struct gkyl_array *cflrate, + struct gkyl_array *combined_multiplier +) { double omega_max = 1.0 / fdmul->cfl_dt_min_value; clamp_cflrate_by_omega_max(fdmul, omega_max, cflrate, combined_multiplier); } -static void -gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_set_by_species(gkyl_gyrokinetic_app *app, - const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *phi, - const struct gkyl_array *f, const struct gkyl_array *cflrate, - struct gkyl_array *combined_multiplier) +static void gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_set_by_species( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_array *phi, const struct gkyl_array *f, const struct gkyl_array *cflrate, + struct gkyl_array *combined_multiplier +) { double omega_max = 1.0 / fdmul->species_dt_is_set_from->dt_cfl_global_ho; clamp_cflrate_by_omega_max(fdmul, omega_max, cflrate, combined_multiplier); } -static void -gk_species_fdot_multiplier_advance_time_dilation_cfl_factor_user_specified( +static void gk_species_fdot_multiplier_advance_time_dilation_cfl_factor_user_specified( gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *phi, const struct gkyl_array *f, const struct gkyl_array *cflrate, - struct gkyl_array *combined_multiplier) + struct gkyl_array *combined_multiplier +) { double omega_max = compute_global_array_max(app, fdmul, cflrate); omega_max = fdmul->cfl_factor_times_omega_max * omega_max; clamp_cflrate_by_omega_max(fdmul, omega_max, cflrate, combined_multiplier); } -static void -gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_global(gkyl_gyrokinetic_app *app, - const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *phi, - const struct gkyl_array *f, const struct gkyl_array *cflrate, - struct gkyl_array *combined_multiplier) +static void gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_global( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_array *phi, const struct gkyl_array *f, const struct gkyl_array *cflrate, + struct gkyl_array *combined_multiplier +) { gkyl_array_reduce(fdmul->local_max_f, f, GKYL_MAX); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_MAX, app->basis.num_basis, - fdmul->local_max_f, fdmul->global_max_f); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_MAX, app->basis.num_basis, fdmul->local_max_f, fdmul->global_max_f + ); gkyl_dg_array_mask_advance_threshold(fdmul->cfl_mask, fdmul->global_max_f[0]); gkyl_dg_array_mask_advance(fdmul->cfl_mask, f); @@ -234,11 +245,11 @@ gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_global(gkyl_gyrokine clamp_cflrate_by_omega_max(fdmul, omega_max, cflrate, combined_multiplier); } -static void -gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_local(gkyl_gyrokinetic_app *app, - const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *phi, - const struct gkyl_array *f, const struct gkyl_array *cflrate, - struct gkyl_array *combined_multiplier) +static void gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_local( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_array *phi, const struct gkyl_array *f, const struct gkyl_array *cflrate, + struct gkyl_array *combined_multiplier +) { gkyl_dg_array_mask_advance(fdmul->cfl_mask, f); gkyl_dg_array_mask_scale_by_cell(fdmul->cfl_mask, cflrate); @@ -247,8 +258,7 @@ gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_local(gkyl_gyrokinet clamp_cflrate_by_omega_max(fdmul, omega_max, cflrate, combined_multiplier); } -static void -proj_on_basis_c2p_phase_func(const double *xcomp, double *xphys, void *ctx) +static void proj_on_basis_c2p_phase_func(const double *xcomp, double *xphys, void *ctx) { struct gk_proj_on_basis_c2p_func_ctx *c2p_ctx = ctx; int cdim = c2p_ctx->cdim; // Assumes update range is a phase range. @@ -256,17 +266,16 @@ proj_on_basis_c2p_phase_func(const double *xcomp, double *xphys, void *ctx) gkyl_velocity_map_eval_c2p(c2p_ctx->vel_map, &xcomp[cdim], &xphys[cdim]); } -static void -proj_on_basis_c2p_position_func(const double *xcomp, double *xphys, void *ctx) +static void proj_on_basis_c2p_position_func(const double *xcomp, double *xphys, void *ctx) { struct gk_proj_on_basis_c2p_func_ctx *c2p_ctx = ctx; gkyl_position_map_eval_mc2nu(c2p_ctx->pos_map, xcomp, xphys); } -static void -gk_species_fdot_multiplier_init_comp(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_fdot_multiplier_comp *fdmul, - const struct gkyl_gyrokinetic_fdot_multiplier_comp *fdot_mult_inp) +static void gk_species_fdot_multiplier_init_comp( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_gyrokinetic_fdot_multiplier_comp *fdot_mult_inp +) { fdmul->type = fdot_mult_inp->type; @@ -280,8 +289,7 @@ gk_species_fdot_multiplier_init_comp(gkyl_gyrokinetic_app *app, struct gk_specie struct gkyl_basis basis_mult; if (cellwise_const) { gkyl_cart_modal_serendip(&basis_mult, gks->basis.ndim, 0); - } - else { + } else { basis_mult = gks->basis; } @@ -299,16 +307,15 @@ gk_species_fdot_multiplier_init_comp(gkyl_gyrokinetic_app *app, struct gk_specie fdmul->buffer = mkarr(app->use_gpu, basis_mult.num_basis, gks->local_ext.volume); struct gkyl_array *buffer_ho = mkarr(false, basis_mult.num_basis, gks->local_ext.volume); - gkyl_proj_on_basis *projup = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp) { - .grid = &gks->grid, + gkyl_proj_on_basis *projup = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &gks->grid, .basis = &basis_mult, .num_quad = basis_mult.poly_order + 1, .num_ret_vals = 1, .eval = fdot_mult_inp->profile, .ctx = fdot_mult_inp->profile_ctx, .c2p_func = proj_on_basis_c2p_phase_func, - .c2p_func_ctx = &fdmul->proj_on_basis_c2p_ctx, - }); + .c2p_func_ctx = &fdmul->proj_on_basis_c2p_ctx}); gkyl_proj_on_basis_advance(projup, 0.0, &gks->local, buffer_ho); gkyl_proj_on_basis_release(projup); @@ -320,42 +327,42 @@ gk_species_fdot_multiplier_init_comp(gkyl_gyrokinetic_app *app, struct gk_specie gkyl_array_release(buffer_ho); fdmul->advance_func = gk_species_fdot_multiplier_advance_mult; - } - else if (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_LOSS_CONE) { + } else if (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_LOSS_CONE) { fdmul->buffer = mkarr(app->use_gpu, basis_mult.num_basis, gks->local_ext.volume); enum gkyl_quad_type qtype = GKYL_GAUSS_LOBATTO_QUAD; int num_quad = gks->basis.poly_order + 1; double bmag_max_coord_ho[GKYL_MAX_CDIM]; - double bmag_max_ho = gkyl_gk_geometry_reduce_arg_bmag(app->gk_geom, GKYL_MAX, - bmag_max_coord_ho); + double bmag_max_ho = + gkyl_gk_geometry_reduce_arg_bmag(app->gk_geom, GKYL_MAX, bmag_max_coord_ho); double bmag_max_local = bmag_max_ho; double bmag_max_global; - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 1, &bmag_max_local, - &bmag_max_global); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, 1, &bmag_max_local, &bmag_max_global + ); double bmag_max_coord_local[app->cdim], bmag_max_coord_global[app->cdim]; if (fabs(bmag_max_ho - bmag_max_global) < 1e-16) { for (int d = 0; d < app->cdim; d++) { bmag_max_coord_local[d] = bmag_max_coord_ho[d]; } - } - else { + } else { for (int d = 0; d < app->cdim; d++) { bmag_max_coord_local[d] = -DBL_MAX; } } - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, app->cdim, bmag_max_coord_local, - bmag_max_coord_global); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, app->cdim, bmag_max_coord_local, bmag_max_coord_global + ); if (app->use_gpu) { fdmul->bmag_max = gkyl_cu_malloc(sizeof(double)); fdmul->bmag_max_coord = gkyl_cu_malloc(app->cdim * sizeof(double)); gkyl_cu_memcpy(fdmul->bmag_max, &bmag_max_global, sizeof(double), GKYL_CU_MEMCPY_H2D); - gkyl_cu_memcpy(fdmul->bmag_max_coord, bmag_max_coord_ho, app->cdim * sizeof(double), - GKYL_CU_MEMCPY_H2D); - } - else { + gkyl_cu_memcpy( + fdmul->bmag_max_coord, bmag_max_coord_ho, app->cdim * sizeof(double), GKYL_CU_MEMCPY_H2D + ); + } else { fdmul->bmag_max = gkyl_malloc(sizeof(double)); fdmul->bmag_max_coord = gkyl_malloc(app->cdim * sizeof(double)); memcpy(fdmul->bmag_max, &bmag_max_global, sizeof(double)); @@ -365,8 +372,7 @@ gk_species_fdot_multiplier_init_comp(gkyl_gyrokinetic_app *app, struct gk_specie if (app->use_gpu) { fdmul->phi_m = gkyl_cu_malloc(sizeof(double)); fdmul->phi_m_global = gkyl_cu_malloc(sizeof(double)); - } - else { + } else { fdmul->phi_m = gkyl_malloc(sizeof(double)); fdmul->phi_m_global = gkyl_malloc(sizeof(double)); } @@ -389,29 +395,26 @@ gk_species_fdot_multiplier_init_comp(gkyl_gyrokinetic_app *app, struct gk_specie .cellwise_trap_loss = cellwise_const, .c2p_pos_func = proj_on_basis_c2p_position_func, .c2p_pos_func_ctx = &fdmul->proj_on_basis_c2p_ctx, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; fdmul->lcm_proj_op = gkyl_loss_cone_mask_gyrokinetic_inew(&inp_proj); fdmul->advance_func = gk_species_fdot_multiplier_advance_loss_cone_mult; - } - else if ((fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_DT) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_FACTOR_TIMES_OMEGA_MAX) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_DT_OMEGAH) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_DT_SET_BY_SPECIES) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_THRESHOLD) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_LOCAL) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_GLOBAL) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_CONSTANT)) { - + } else if ((fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_DT) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_FACTOR_TIMES_OMEGA_MAX) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_DT_OMEGAH) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_DT_SET_BY_SPECIES) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_THRESHOLD) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_LOCAL) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_GLOBAL) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_CONSTANT)) { fdmul->cfl_dt_min_value = fdot_mult_inp->cfl_dt_min_value; fdmul->f_threshold = fdot_mult_inp->f_threshold; fdmul->cfl_factor_times_omega_max = fdot_mult_inp->cfl_factor_times_omega_max; if (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_CONSTANT) { fdmul->advance_func = gk_species_fdot_multiplier_advance_const; - } - else { + } else { fdmul->buffer = mkarr(app->use_gpu, basis_mult.num_basis, gks->local_ext.volume); if (app->use_gpu) { @@ -420,53 +423,48 @@ gk_species_fdot_multiplier_init_comp(gkyl_gyrokinetic_app *app, struct gk_specie fdmul->local_max_f = (double *)gkyl_cu_malloc(sizeof(double) * gks->basis.num_basis); fdmul->global_max_f = (double *)gkyl_cu_malloc(sizeof(double) * gks->basis.num_basis); #endif - } - else { + } else { fdmul->local_max_f = gkyl_malloc(sizeof(double) * gks->basis.num_basis); fdmul->global_max_f = gkyl_malloc(sizeof(double) * gks->basis.num_basis); } enum gkyl_dg_array_mask_types mask_type = GKYL_DG_ARRAY_MASK_NONE; switch (fdmul->type) { - case GKYL_GK_FDOT_MULTIPLIER_FIXED_DT: - mask_type = GKYL_DG_ARRAY_MASK_NONE; - fdmul->advance_func = - gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_user_specified; - break; - case GKYL_GK_FDOT_MULTIPLIER_FIXED_FACTOR_TIMES_OMEGA_MAX: - mask_type = GKYL_DG_ARRAY_MASK_NONE; - fdmul->advance_func = - gk_species_fdot_multiplier_advance_time_dilation_cfl_factor_user_specified; - break; - case GKYL_GK_FDOT_MULTIPLIER_FIXED_DT_OMEGAH: - mask_type = GKYL_DG_ARRAY_MASK_NONE; - fdmul->advance_func = - gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_omegaH; - break; - case GKYL_GK_FDOT_MULTIPLIER_DT_SET_BY_SPECIES: - mask_type = GKYL_DG_ARRAY_MASK_NONE; - fdmul->species_dt_is_set_from = gk_find_species(app, fdot_mult_inp->dt_set_by_species); - fdmul->advance_func = - gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_set_by_species; - break; - case GKYL_GK_FDOT_MULTIPLIER_MASK_F_THRESHOLD: - mask_type = GKYL_DG_ARRAY_MASK_C0_GREATER; - fdmul->advance_func = - gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_local; - break; - case GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_LOCAL: - mask_type = GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF; - fdmul->advance_func = - gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_local; - break; - case GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_GLOBAL: - mask_type = GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC; - fdmul->advance_func = - gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_global; - break; - default: - assert(false); // Unknown fdot_multiplier type. - break; + case GKYL_GK_FDOT_MULTIPLIER_FIXED_DT: + mask_type = GKYL_DG_ARRAY_MASK_NONE; + fdmul->advance_func = + gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_user_specified; + break; + case GKYL_GK_FDOT_MULTIPLIER_FIXED_FACTOR_TIMES_OMEGA_MAX: + mask_type = GKYL_DG_ARRAY_MASK_NONE; + fdmul->advance_func = + gk_species_fdot_multiplier_advance_time_dilation_cfl_factor_user_specified; + break; + case GKYL_GK_FDOT_MULTIPLIER_FIXED_DT_OMEGAH: + mask_type = GKYL_DG_ARRAY_MASK_NONE; + fdmul->advance_func = gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_omegaH; + break; + case GKYL_GK_FDOT_MULTIPLIER_DT_SET_BY_SPECIES: + mask_type = GKYL_DG_ARRAY_MASK_NONE; + fdmul->species_dt_is_set_from = gk_find_species(app, fdot_mult_inp->dt_set_by_species); + fdmul->advance_func = + gk_species_fdot_multiplier_advance_time_dilation_cfl_dt_set_by_species; + break; + case GKYL_GK_FDOT_MULTIPLIER_MASK_F_THRESHOLD: + mask_type = GKYL_DG_ARRAY_MASK_C0_GREATER; + fdmul->advance_func = gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_local; + break; + case GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_LOCAL: + mask_type = GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC_CONF; + fdmul->advance_func = gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_local; + break; + case GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_GLOBAL: + mask_type = GKYL_DG_ARRAY_MASK_C0_GREATER_FRAC; + fdmul->advance_func = gk_species_fdot_multiplier_advance_time_dilation_cfl_f_frac_global; + break; + default: + assert(false); // Unknown fdot_multiplier type. + break; } struct gkyl_dg_array_mask_inp cfl_mask_inp = { @@ -477,7 +475,7 @@ gk_species_fdot_multiplier_init_comp(gkyl_gyrokinetic_app *app, struct gk_specie .conf_rng = &app->local, .conf_rng_ext = &app->local_ext, .vel_rng = &gks->local_vel, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; fdmul->cfl_mask = gkyl_dg_array_mask_new(cfl_mask_inp); } @@ -485,9 +483,9 @@ gk_species_fdot_multiplier_init_comp(gkyl_gyrokinetic_app *app, struct gk_specie } } -void -gk_species_fdot_multiplier_init(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult) +void gk_species_fdot_multiplier_init( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult +) { fdot_mult->num_multipliers = gks->info.time_rate_multiplier.num_multipliers; fdot_mult->write_func = gk_species_fdot_multiplier_write_disabled; @@ -501,8 +499,9 @@ gk_species_fdot_multiplier_init(gkyl_gyrokinetic_app *app, struct gk_species *gk // Initialize multiplier components and determine if any component requests diagnostics. fdot_mult->write_diagnostics = false; for (int i = 0; i < fdot_mult->num_multipliers; ++i) { - gk_species_fdot_multiplier_init_comp(app, gks, &fdot_mult->comp[i], - &gks->info.time_rate_multiplier.multiplier[i]); + gk_species_fdot_multiplier_init_comp( + app, gks, &fdot_mult->comp[i], &gks->info.time_rate_multiplier.multiplier[i] + ); if (gks->info.time_rate_multiplier.multiplier[i].write_diagnostics) { fdot_mult->write_diagnostics = true; } @@ -512,9 +511,9 @@ gk_species_fdot_multiplier_init(gkyl_gyrokinetic_app *app, struct gk_species *gk fdot_mult->multiplier = mkarr(app->use_gpu, 1, gks->local_ext.volume); gkyl_array_clear(fdot_mult->multiplier, 1.0); if (fdot_mult->write_diagnostics) { - fdot_mult->multiplier_host = app->use_gpu ? - mkarr(false, fdot_mult->multiplier->ncomp, fdot_mult->multiplier->size) : - gkyl_array_acquire(fdot_mult->multiplier); + fdot_mult->multiplier_host = + app->use_gpu ? mkarr(false, fdot_mult->multiplier->ncomp, fdot_mult->multiplier->size) : + gkyl_array_acquire(fdot_mult->multiplier); fdot_mult->write_func = gk_species_fdot_multiplier_write_enabled; } @@ -522,32 +521,33 @@ gk_species_fdot_multiplier_init(gkyl_gyrokinetic_app *app, struct gk_species *gk fdot_mult->advance_times_rate_func = gk_fdot_multiplier_advance_times_rate_enabled; } -void -gk_species_fdot_multiplier_advance_times_cfl(gkyl_gyrokinetic_app *app, - struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, - const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *cflrate) +void gk_species_fdot_multiplier_advance_times_cfl( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *cflrate +) { fdot_mult->advance_times_cfl_func(app, gks, fdot_mult, phi, f, cflrate); } -void -gk_species_fdot_multiplier_advance_times_rate(gkyl_gyrokinetic_app *app, - struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, - const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *rhs) +void gk_species_fdot_multiplier_advance_times_rate( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *rhs +) { fdot_mult->advance_times_rate_func(app, gks, fdot_mult, phi, f, rhs); } -void -gk_species_fdot_multiplier_write(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult, double tm, int frame) +void gk_species_fdot_multiplier_write( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + double tm, int frame +) { fdot_mult->write_func(app, gks, fdot_mult, tm, frame); } -double -gk_fdot_multiplier_get_time_dilation_scale_const(gkyl_gyrokinetic_app *app, - const struct gk_fdot_multiplier *fdot_mult) +double gk_fdot_multiplier_get_time_dilation_scale_const( + gkyl_gyrokinetic_app *app, const struct gk_fdot_multiplier *fdot_mult +) { double result = 1.0; for (int i = 0; i < fdot_mult->num_multipliers; ++i) { @@ -558,41 +558,39 @@ gk_fdot_multiplier_get_time_dilation_scale_const(gkyl_gyrokinetic_app *app, return result; } -static void -gk_species_fdot_multiplier_release_comp(const struct gkyl_gyrokinetic_app *app, - const struct gk_fdot_multiplier_comp *fdmul) +static void gk_species_fdot_multiplier_release_comp( + const struct gkyl_gyrokinetic_app *app, const struct gk_fdot_multiplier_comp *fdmul +) { - if (!fdmul->type) return; + if (!fdmul->type) { + return; + } if (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_USER_INPUT) { gkyl_array_release(fdmul->buffer); - } - else if (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_LOSS_CONE) { + } else if (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_LOSS_CONE) { gkyl_array_release(fdmul->buffer); if (app->use_gpu) { gkyl_cu_free(fdmul->bmag_max); gkyl_cu_free(fdmul->bmag_max_coord); gkyl_cu_free(fdmul->phi_m); gkyl_cu_free(fdmul->phi_m_global); - } - else { + } else { gkyl_free(fdmul->bmag_max); gkyl_free(fdmul->bmag_max_coord); gkyl_free(fdmul->phi_m); gkyl_free(fdmul->phi_m_global); } gkyl_loss_cone_mask_gyrokinetic_release(fdmul->lcm_proj_op); - } - else if (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_CONSTANT) { + } else if (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_CONSTANT) { // No allocations to free for CONSTANT type. - } - else if ((fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_DT) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_FACTOR_TIMES_OMEGA_MAX) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_DT_OMEGAH) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_DT_SET_BY_SPECIES) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_THRESHOLD) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_LOCAL) || - (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_GLOBAL)) { + } else if ((fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_DT) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_FACTOR_TIMES_OMEGA_MAX) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_FIXED_DT_OMEGAH) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_DT_SET_BY_SPECIES) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_THRESHOLD) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_LOCAL) || + (fdmul->type == GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_GLOBAL)) { gkyl_array_release(fdmul->buffer); gkyl_dg_array_mask_release(fdmul->cfl_mask); if (app->use_gpu) { @@ -601,19 +599,20 @@ gk_species_fdot_multiplier_release_comp(const struct gkyl_gyrokinetic_app *app, gkyl_cu_free(fdmul->local_max_f); gkyl_cu_free(fdmul->global_max_f); #endif - } - else { + } else { gkyl_free(fdmul->local_max_f); gkyl_free(fdmul->global_max_f); } } } -void -gk_species_fdot_multiplier_release(const struct gkyl_gyrokinetic_app *app, - const struct gk_fdot_multiplier *fdot_mult) +void gk_species_fdot_multiplier_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_fdot_multiplier *fdot_mult +) { - if (fdot_mult->num_multipliers == 0) return; + if (fdot_mult->num_multipliers == 0) { + return; + } for (int i = 0; i < fdot_mult->num_multipliers; ++i) { gk_species_fdot_multiplier_release_comp(app, &fdot_mult->comp[i]); @@ -624,10 +623,10 @@ gk_species_fdot_multiplier_release(const struct gkyl_gyrokinetic_app *app, } } -void -gk_species_fdot_multiplier_reset(gkyl_gyrokinetic_app *app, double tm, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult, - struct gkyl_gyrokinetic_fdot_multiplier fdot_mult_inp) +void gk_species_fdot_multiplier_reset( + gkyl_gyrokinetic_app *app, double tm, struct gk_species *gks, + struct gk_fdot_multiplier *fdot_mult, struct gkyl_gyrokinetic_fdot_multiplier fdot_mult_inp +) { gk_species_fdot_multiplier_release(app, fdot_mult); diff --git a/gyrokinetic/apps/gk_species_lbo.c b/gyrokinetic/apps/gk_species_lbo.c index cf78ec400c..300975f5df 100644 --- a/gyrokinetic/apps/gk_species_lbo.c +++ b/gyrokinetic/apps/gk_species_lbo.c @@ -2,120 +2,141 @@ #include #include -static void -gklbo_moms_disabled(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin) +static void gklbo_moms_disabled( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin +) { // Empty method. } -static void -gklbo_moms_enabled(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin) +static void gklbo_moms_enabled( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin +) { struct timespec wst = gkyl_wall_clock(); // Compute J*M0, J*M1, J*M2 moments and separate our M0 and M2. gk_species_moment_calc(&lbo->moms, species->local, app->local, fin); - gkyl_array_set_offset_range(lbo->m2self, 1.0, lbo->moms.marr, 2*app->basis.num_basis, &app->local); - + gkyl_array_set_offset_range( + lbo->m2self, 1.0, lbo->moms.marr, 2 * app->basis.num_basis, &app->local + ); + // Construct boundary corrections. - gkyl_mom_calc_bcorr_advance(lbo->bcorr_calc, - &species->local, &app->local, fin, lbo->boundary_corrections); + gkyl_mom_calc_bcorr_advance( + lbo->bcorr_calc, &species->local, &app->local, fin, lbo->boundary_corrections + ); // Calculate nu_ss (and multibly moms and corrections by it for norm_nu). lbo->self_nu_func(app, species, lbo, fin); // Multiply moments and boundary corrections by self nu. - for (int d=0; d<3; d++) + for (int d = 0; d < 3; d++) { gkyl_dg_mul_op(&app->basis, d, lbo->nu_moms, d, lbo->moms.marr, 0, lbo->self_nu); - for (int d=0; d<2; d++) - gkyl_dg_mul_op(&app->basis, d, lbo->nu_boundary_corrections, d, lbo->boundary_corrections, 0, lbo->self_nu); + } + for (int d = 0; d < 2; d++) { + gkyl_dg_mul_op( + &app->basis, d, lbo->nu_boundary_corrections, d, lbo->boundary_corrections, 0, lbo->self_nu + ); + } // Construct primitive moments. - gkyl_prim_lbo_calc_advance(lbo->coll_pcalc, &app->local, - lbo->nu_moms, lbo->nu_boundary_corrections, lbo->self_nu, lbo->prim_moms); + gkyl_prim_lbo_calc_advance( + lbo->coll_pcalc, &app->local, lbo->nu_moms, lbo->nu_boundary_corrections, lbo->self_nu, + lbo->prim_moms + ); // Scale upar and vtSq by self nu. - for (int d=0; d<2; d++) + for (int d = 0; d < 2; d++) { gkyl_dg_mul_op(&app->basis, d, lbo->nu_prim_moms, d, lbo->prim_moms, 0, lbo->self_nu); + } - app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); + app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); } -static void -gklbo_self_nu_calc_constNu(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin) +static void gklbo_self_nu_calc_constNu( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin +) { // Empty method. } -static void -gklbo_self_nu_calc_normNu(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin) +static void gklbo_self_nu_calc_normNu( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin +) { // Calculate nu_ss(x,t). gk_species_moment_calc(&species->lte.moms, species->local, app->local, fin); - gkyl_dg_div_op_range(species->lte.moms.mem_geo, &app->basis, 0, species->lte.moms.marr, - 0, species->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + species->lte.moms.mem_geo, &app->basis, 0, species->lte.moms.marr, 0, species->lte.moms.marr, 0, + app->gk_geom->geo_int.jacobgeo, &app->local + ); - gkyl_spitzer_coll_freq_advance_normnu(lbo->spitzer_calc, &app->local, species->lte.moms.marr, lbo->vtsq_min, - species->lte.moms.marr, lbo->vtsq_min, lbo->norm_nu_fac_self, lbo->self_nu); + gkyl_spitzer_coll_freq_advance_normnu( + lbo->spitzer_calc, &app->local, species->lte.moms.marr, lbo->vtsq_min, species->lte.moms.marr, + lbo->vtsq_min, lbo->norm_nu_fac_self, lbo->self_nu + ); gkyl_array_set(lbo->nu_sum, 1.0, lbo->self_nu); } -static void -gklbo_cross_nu_calc_constNu(gkyl_gyrokinetic_app *app, const struct gk_species *s, - struct gk_lbo_collisions *lbo, int coll_idx) +static void gklbo_cross_nu_calc_constNu( + gkyl_gyrokinetic_app *app, const struct gk_species *s, struct gk_lbo_collisions *lbo, int coll_idx +) { // Empty method. } -static void -gklbo_cross_nu_calc_normNu(gkyl_gyrokinetic_app *app, const struct gk_species *s, - struct gk_lbo_collisions *lbo, int coll_idx) +static void gklbo_cross_nu_calc_normNu( + gkyl_gyrokinetic_app *app, const struct gk_species *s, struct gk_lbo_collisions *lbo, int coll_idx +) { // Calculate nu_sr(x,t). - gkyl_spitzer_coll_freq_advance_normnu(lbo->spitzer_calc, &app->local, s->lte.moms.marr, lbo->vtsq_min, + gkyl_spitzer_coll_freq_advance_normnu( + lbo->spitzer_calc, &app->local, s->lte.moms.marr, lbo->vtsq_min, lbo->collide_with[coll_idx]->lte.moms.marr, lbo->collide_with[coll_idx]->lbo.vtsq_min, - lbo->norm_nu_fac_cross[coll_idx], lbo->cross_nu[coll_idx]); + lbo->norm_nu_fac_cross[coll_idx], lbo->cross_nu[coll_idx] + ); gkyl_array_accumulate(lbo->nu_sum, 1.0, lbo->cross_nu[coll_idx]); } -static void -gklbo_alpha_E_constNu(gkyl_gyrokinetic_app *app, const struct gk_species *s, - struct gk_lbo_collisions *lbo, int coll_idx) +static void gklbo_alpha_E_constNu( + gkyl_gyrokinetic_app *app, const struct gk_species *s, struct gk_lbo_collisions *lbo, int coll_idx +) { gkyl_array_clear(lbo->alpha_E, 0.0); gkyl_array_shiftc(lbo->alpha_E, lbo->alpha_E_fac[coll_idx], 0); } -static void -gklbo_alpha_E_normNu(gkyl_gyrokinetic_app *app, const struct gk_species *s, - struct gk_lbo_collisions *lbo, int coll_idx) +static void gklbo_alpha_E_normNu( + gkyl_gyrokinetic_app *app, const struct gk_species *s, struct gk_lbo_collisions *lbo, int coll_idx +) { - gkyl_dg_mul_op_range(&app->basis, 0, lbo->alpha_E, 0, lbo->cross_nu[coll_idx], 0, s->lte.moms.marr, &app->local); + gkyl_dg_mul_op_range( + &app->basis, 0, lbo->alpha_E, 0, lbo->cross_nu[coll_idx], 0, s->lte.moms.marr, &app->local + ); gkyl_array_scale_range(lbo->alpha_E, lbo->alpha_E_fac[coll_idx], &app->local); } -static void -gklbo_cross_moms_disabled(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_lbo_collisions *lbo) +static void gklbo_cross_moms_disabled( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_lbo_collisions *lbo +) { // Empty method. } -static void -gklbo_cross_moms_enabled(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_lbo_collisions *lbo) +static void gklbo_cross_moms_enabled( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_lbo_collisions *lbo +) { // Compute primitive moments for cross-species collisions. struct timespec wst = gkyl_wall_clock(); - - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < lbo->num_cross_collisions; ++i) { // Compute the cross-species collision frequency. lbo->cross_nu_func(app, gks, lbo, i); @@ -123,86 +144,103 @@ gklbo_cross_moms_enabled(gkyl_gyrokinetic_app *app, const struct gk_species *gks lbo->alpha_E_func(app, gks, lbo, i); // Multiply moments and boundary corrections by cross nu. - for (int d=0; d<3; d++) + for (int d = 0; d < 3; d++) { gkyl_dg_mul_op(&app->basis, d, lbo->nu_moms, d, lbo->moms.marr, 0, lbo->cross_nu[i]); - for (int d=0; d<2; d++) - gkyl_dg_mul_op(&app->basis, d, lbo->nu_boundary_corrections, d, lbo->boundary_corrections, 0, lbo->cross_nu[i]); + } + for (int d = 0; d < 2; d++) { + gkyl_dg_mul_op( + &app->basis, d, lbo->nu_boundary_corrections, d, lbo->boundary_corrections, 0, + lbo->cross_nu[i] + ); + } // Compute cross primitive moments. // Recycle the boundary_corrections array because we don't need those anymore. struct gkyl_array *cross_prim_moms = lbo->nu_boundary_corrections; - gkyl_prim_lbo_cross_calc_advance(lbo->cross_calc, &app->local, lbo->alpha_E, - gks->info.mass, lbo->nu_moms, lbo->prim_moms, + gkyl_prim_lbo_cross_calc_advance( + lbo->cross_calc, &app->local, lbo->alpha_E, gks->info.mass, lbo->nu_moms, lbo->prim_moms, lbo->other_m[i], lbo->collide_with[i]->lbo.moms.marr, lbo->other_prim_moms[i], - lbo->nu_boundary_corrections, lbo->cross_nu[i], cross_prim_moms); + lbo->nu_boundary_corrections, lbo->cross_nu[i], cross_prim_moms + ); // Scale upar_{sr} and vtSq_{sr} by nu_{sr}. - for (int d=0; d<2; d++) + for (int d = 0; d < 2; d++) { gkyl_dg_mul_op(&app->basis, d, cross_prim_moms, d, cross_prim_moms, 0, lbo->cross_nu[i]); + } gkyl_array_accumulate(lbo->nu_prim_moms, 1.0, cross_prim_moms); - } - app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); + app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); } -static void -gklbo_rhs_disabled(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gklbo_rhs_disabled( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { // Empty method. } -static void -gklbo_rhs_enabled(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gklbo_rhs_enabled( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - + // Accumulate update due to collisions onto rhs. - gkyl_dg_updater_lbo_gyrokinetic_advance(lbo->coll_slvr, &gks->local, - fin, gks->cflrate, rhs); - + gkyl_dg_updater_lbo_gyrokinetic_advance(lbo->coll_slvr, &gks->local, fin, gks->cflrate, rhs); + app->stat.species_coll_tm += gkyl_time_diff_now_sec(wst); } static void -gklbo_write_mom_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +gklbo_write_mom_disabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { // Empty method. } static void -gklbo_write_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +gklbo_write_mom_enabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { struct timespec wtm = gkyl_wall_clock(); // Package metadata. gkyl_msgpack_map_elem_set_double(gks->io_meta_conf_len, gks->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_conf_len, gks->io_meta_conf, "frame", frame); struct gkyl_msgpack_map_elem desc_nu_sum[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Sum of collision frequencies." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Sum of collision frequencies."} }; int io_meta_nu_sum_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta_nu_sum[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc_nu_sum}; - struct gkyl_msgpack_data *mt_nu_sum = gkyl_msgpack_create_union(sizeof(io_meta_nu_sum_len)/sizeof(int), io_meta_nu_sum_len, io_meta_nu_sum); + const struct gkyl_msgpack_map_elem *io_meta_nu_sum[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc_nu_sum + }; + struct gkyl_msgpack_data *mt_nu_sum = gkyl_msgpack_create_union( + sizeof(io_meta_nu_sum_len) / sizeof(int), io_meta_nu_sum_len, io_meta_nu_sum + ); struct gkyl_msgpack_map_elem desc_nu_prim[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, - .cval = "Drift velocity and thermal speed squared, times collision frequency, summed over colliding species." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Drift velocity and thermal speed squared, times collision frequency, summed over " + "colliding species."} }; int io_meta_nu_prim_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta_nu_prim[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc_nu_prim}; - struct gkyl_msgpack_data *mt_nu_prim = gkyl_msgpack_create_union(sizeof(io_meta_nu_prim_len)/sizeof(int), io_meta_nu_prim_len, io_meta_nu_prim); + const struct gkyl_msgpack_map_elem *io_meta_nu_prim[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc_nu_prim + }; + struct gkyl_msgpack_data *mt_nu_prim = gkyl_msgpack_create_union( + sizeof(io_meta_nu_prim_len) / sizeof(int), io_meta_nu_prim_len, io_meta_nu_prim + ); // Write out nu_sum and nu_prim_moms. const char *fmt = "%s-%s_lbo_nu_sum_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, frame); const char *fmt_nu_prim = "%s-%s_lbo_nu_prim_moms_%d.gkyl"; int sz_nu_prim = gkyl_calc_strlen(fmt_nu_prim, app->name, gks->info.name, frame); - char fileNm_nu_prim[sz_nu_prim+1]; // ensures no buffer overflow + char fileNm_nu_prim[sz_nu_prim + 1]; // ensures no buffer overflow snprintf(fileNm_nu_prim, sizeof fileNm_nu_prim, fmt_nu_prim, app->name, gks->info.name, frame); // Copy data from device to host before writing it out. @@ -212,7 +250,9 @@ gklbo_write_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, doubl } gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt_nu_sum, gks->lbo.nu_sum_host, fileNm); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt_nu_prim, gks->lbo.nu_prim_moms_host, fileNm_nu_prim); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt_nu_prim, gks->lbo.nu_prim_moms_host, fileNm_nu_prim + ); app->stat.n_diag_io += 2; gkyl_msgpack_data_release(mt_nu_sum); @@ -220,8 +260,9 @@ gklbo_write_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, doubl app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); } -void -gk_species_lbo_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_lbo_collisions *lbo) +void gk_species_lbo_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_lbo_collisions *lbo +) { lbo->collision_id = gks->info.collisions.collision_id; lbo->write_diagnostics = gks->info.collisions.write_diagnostics; @@ -233,121 +274,136 @@ gk_species_lbo_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, st if (lbo->collision_id == GKYL_LBO_COLLISIONS) { lbo->num_cross_collisions = gks->info.collisions.num_cross_collisions; - + int cdim = app->cdim, vdim = gks->info.vdim; - + // Allocate self-species collision frequency and sum of collision frequencies. lbo->self_nu = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); lbo->nu_sum = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - + double nu_frac = gks->info.collisions.nu_frac ? gks->info.collisions.nu_frac : 1.0; - + if (gks->info.collisions.self_nu) { // Project user's self-species collision frequency. lbo->norm_nu_self = false; - + struct gkyl_array *self_nu_ho = mkarr(false, app->basis.num_basis, app->local_ext.volume); - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(&app->grid, &app->basis, - app->poly_order+1, 1, gks->info.collisions.self_nu, gks->info.collisions.self_nu_ctx); + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + &app->grid, &app->basis, app->poly_order + 1, 1, gks->info.collisions.self_nu, + gks->info.collisions.self_nu_ctx + ); gkyl_proj_on_basis_advance(proj, 0.0, &app->local, self_nu_ho); gkyl_proj_on_basis_release(proj); gkyl_array_copy(lbo->self_nu, self_nu_ho); gkyl_array_release(self_nu_ho); - + gkyl_array_scale(lbo->self_nu, nu_frac); gkyl_array_set(lbo->nu_sum, 1.0, lbo->self_nu); - + // Set pointers to functions chosen at runtime. lbo->self_nu_func = gklbo_self_nu_calc_constNu; - } - else { + } else { // Self-collision frequency computed in time. lbo->norm_nu_self = true; - + double eps0 = gks->info.collisions.eps0 ? gks->info.collisions.eps0 : GKYL_EPSILON0; - double hbar = gks->info.collisions.hbar ? gks->info.collisions.hbar : GKYL_PLANCKS_CONSTANT_H/2/M_PI; + double hbar = gks->info.collisions.hbar ? gks->info.collisions.hbar : + GKYL_PLANCKS_CONSTANT_H / 2 / M_PI; double eV = gks->info.collisions.eV ? gks->info.collisions.eV : GKYL_ELEMENTARY_CHARGE; - double bmag_ref = gks->info.collisions.bmag_ref ? gks->info.collisions.bmag_ref : app->bmag_ref; - + double bmag_ref = gks->info.collisions.bmag_ref ? gks->info.collisions.bmag_ref : + app->bmag_ref; + // Compute a minimum representable temperature based on the smallest dv in the grid. double dv_min[vdim]; gkyl_velocity_map_reduce_dv_range(gks->vel_map, GKYL_MIN, dv_min, gks->vel_map->local_vel); - - double tpar_min = (gks->info.mass/6.0)*pow(dv_min[0],2); - double tperp_min = vdim>1 ? (bmag_ref/3.0)*dv_min[1] : tpar_min; - lbo->vtsq_min = (tpar_min + 2.0*tperp_min)/(3.0*gks->info.mass); - - lbo->spitzer_calc = gkyl_spitzer_coll_freq_new(&app->basis, app->poly_order+1, - 1.0, 1.0, 1.0, app->use_gpu); - - // We define nu_ss = nu_sr(r=s) = alpha_E/((delta_ss * (1+beta))*n_s), with delta_ss = 2, + + double tpar_min = (gks->info.mass / 6.0) * pow(dv_min[0], 2); + double tperp_min = vdim > 1 ? (bmag_ref / 3.0) * dv_min[1] : tpar_min; + lbo->vtsq_min = (tpar_min + 2.0 * tperp_min) / (3.0 * gks->info.mass); + + lbo->spitzer_calc = + gkyl_spitzer_coll_freq_new(&app->basis, app->poly_order + 1, 1.0, 1.0, 1.0, app->use_gpu); + + // We define nu_ss = nu_sr(r=s) = alpha_E/((delta_ss * (1+beta))*n_s), with delta_ss = 2, // beta = 0. This gives a nu_ss that is arguably 2X smaller than it should be, but it's // cheaper and yields an electron isotropization rate that agrees better with the FPO's. lbo->norm_nu_fac_self = nu_frac * gkyl_calc_Morse_alpha_E_const( - gks->info.collisions.den_ref, gks->info.collisions.den_ref, - gks->info.mass, gks->info.mass, gks->info.charge, gks->info.charge, - gks->info.collisions.temp_ref, gks->info.collisions.temp_ref, bmag_ref, eps0, hbar, eV); - + gks->info.collisions.den_ref, + gks->info.collisions.den_ref, gks->info.mass, + gks->info.mass, gks->info.charge, gks->info.charge, + gks->info.collisions.temp_ref, + gks->info.collisions.temp_ref, bmag_ref, eps0, hbar, eV + ); + // Set pointers to functions chosen at runtime. lbo->self_nu_func = gklbo_self_nu_calc_normNu; } - + // Create moment calculator to get M0, M1, M2 for primitive moments. gk_species_moment_init(app, gks, &lbo->moms, GKYL_F_MOMENT_M0M1M2, false); lbo->nu_moms = mkarr(app->use_gpu, lbo->moms.marr->ncomp, lbo->moms.marr->size); - + // Edge of velocity space corrections to momentum and energy. - lbo->bcorr_calc = gkyl_mom_calc_bcorr_lbo_gyrokinetic_new(&gks->grid, - &app->basis, &gks->basis, gks->info.mass, gks->vel_map, app->use_gpu); - + lbo->bcorr_calc = gkyl_mom_calc_bcorr_lbo_gyrokinetic_new( + &gks->grid, &app->basis, &gks->basis, gks->info.mass, gks->vel_map, app->use_gpu + ); + // Primitive moment calculator. - lbo->coll_pcalc = gkyl_prim_lbo_gyrokinetic_calc_new(&gks->grid, - &app->basis, &gks->basis, &app->local, app->use_gpu); - + lbo->coll_pcalc = gkyl_prim_lbo_gyrokinetic_calc_new( + &gks->grid, &app->basis, &gks->basis, &app->local, app->use_gpu + ); + // Allocate boundary corrections for primitive mom calculation. - lbo->boundary_corrections = mkarr(app->use_gpu, 2*app->basis.num_basis, app->local_ext.volume); - lbo->nu_boundary_corrections = mkarr(app->use_gpu, lbo->boundary_corrections->ncomp, lbo->boundary_corrections->size); - + lbo->boundary_corrections = + mkarr(app->use_gpu, 2 * app->basis.num_basis, app->local_ext.volume); + lbo->nu_boundary_corrections = + mkarr(app->use_gpu, lbo->boundary_corrections->ncomp, lbo->boundary_corrections->size); + // Primitive moments. - lbo->prim_moms = mkarr(app->use_gpu, 2*app->basis.num_basis, app->local_ext.volume); + lbo->prim_moms = mkarr(app->use_gpu, 2 * app->basis.num_basis, app->local_ext.volume); lbo->nu_prim_moms = mkarr(app->use_gpu, lbo->prim_moms->ncomp, lbo->prim_moms->size); // M2 of this species. lbo->m2self = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - + // Host-side copy for I/O. if (lbo->write_diagnostics) { if (app->use_gpu) { lbo->nu_sum_host = mkarr(false, lbo->nu_sum->ncomp, lbo->nu_sum->size); lbo->nu_prim_moms_host = mkarr(false, lbo->nu_prim_moms->ncomp, lbo->nu_prim_moms->size); - } - else { + } else { lbo->nu_sum_host = lbo->nu_sum; lbo->nu_prim_moms_host = lbo->nu_prim_moms; } } - + // LBO updater. - struct gkyl_dg_lbo_gyrokinetic_drag_auxfields drag_inp = { .nuSum = lbo->nu_sum, - .nuPrimMomsSum = lbo->nu_prim_moms, .m2self = lbo->m2self }; - struct gkyl_dg_lbo_gyrokinetic_diff_auxfields diff_inp = { .nuSum = lbo->nu_sum, - .nuPrimMomsSum = lbo->nu_prim_moms, .m2self = lbo->m2self }; - lbo->coll_slvr = gkyl_dg_updater_lbo_gyrokinetic_new(&gks->grid, - &app->basis, &gks->basis, &app->local, &drag_inp, &diff_inp, gks->info.mass, - app->gk_geom, gks->vel_map, app->use_gpu); + struct gkyl_dg_lbo_gyrokinetic_drag_auxfields drag_inp = { + .nuSum = lbo->nu_sum, .nuPrimMomsSum = lbo->nu_prim_moms, .m2self = lbo->m2self + }; + struct gkyl_dg_lbo_gyrokinetic_diff_auxfields diff_inp = { + .nuSum = lbo->nu_sum, .nuPrimMomsSum = lbo->nu_prim_moms, .m2self = lbo->m2self + }; + lbo->coll_slvr = gkyl_dg_updater_lbo_gyrokinetic_new( + &gks->grid, &app->basis, &gks->basis, &app->local, &drag_inp, &diff_inp, gks->info.mass, + app->gk_geom, gks->vel_map, app->use_gpu + ); // Methods chosen at runtime. lbo->moms_func = gklbo_moms_enabled; - if (! gks->info.collisions.not_in_dfdt) {; + if (!gks->info.collisions.not_in_dfdt) { + ; lbo->rhs_func = gklbo_rhs_enabled; } - if (lbo->write_diagnostics) + if (lbo->write_diagnostics) { lbo->write_mom_func = gklbo_write_mom_enabled; + } } } -void -gk_species_lbo_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_lbo_collisions *lbo) +void gk_species_lbo_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_lbo_collisions *lbo +) { // Empty methods. lbo->cross_nu_func = gklbo_cross_nu_calc_constNu; @@ -357,13 +413,13 @@ gk_species_lbo_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g if (gks->lbo.num_cross_collisions) { lbo->betaGreenep1 = 1.0; // Greene's beta factor + 1. lbo->delta_sr = 2.0; // delta_sr free parameter. - + // Set pointers to species we cross-collide with. int my_idx_in_other[GKYL_MAX_SPECIES]; - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < lbo->num_cross_collisions; ++i) { lbo->collide_with[i] = gk_find_species(app, gks->info.collisions.collide_with[i]); my_idx_in_other[i] = -1; - for (int j=0; jcollide_with[i]->lbo.num_cross_collisions; ++j) { + for (int j = 0; j < lbo->collide_with[i]->lbo.num_cross_collisions; ++j) { if (0 == strcmp(gks->info.name, lbo->collide_with[i]->info.collisions.collide_with[j])) { my_idx_in_other[i] = j; break; @@ -373,7 +429,7 @@ gk_species_lbo_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g // Morse's alpha_E. lbo->alpha_E = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < lbo->num_cross_collisions; ++i) { // Cross-species collision frequency, nu_sr. lbo->cross_nu[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); lbo->other_m[i] = lbo->collide_with[i]->info.mass; @@ -384,17 +440,22 @@ gk_species_lbo_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g // Compute the time-independent part of alpha_E. double alpha_E_norm[GKYL_MAX_SPECIES] = {0.0}; - for (int i=0; inum_cross_collisions; ++i) { - double eps0 = gks->info.collisions.eps0 ? gks->info.collisions.eps0: GKYL_EPSILON0; - double hbar = gks->info.collisions.hbar ? gks->info.collisions.hbar: GKYL_PLANCKS_CONSTANT_H/2/M_PI; - double eV = gks->info.collisions.eV ? gks->info.collisions.eV: GKYL_ELEMENTARY_CHARGE; - double bmag_ref = gks->info.collisions.bmag_ref ? gks->info.collisions.bmag_ref : app->bmag_ref; + for (int i = 0; i < lbo->num_cross_collisions; ++i) { + double eps0 = gks->info.collisions.eps0 ? gks->info.collisions.eps0 : GKYL_EPSILON0; + double hbar = gks->info.collisions.hbar ? gks->info.collisions.hbar : + GKYL_PLANCKS_CONSTANT_H / 2 / M_PI; + double eV = gks->info.collisions.eV ? gks->info.collisions.eV : GKYL_ELEMENTARY_CHARGE; + double bmag_ref = gks->info.collisions.bmag_ref ? gks->info.collisions.bmag_ref : + app->bmag_ref; double mass_self = gks->info.mass, mass_other = lbo->collide_with[i]->info.mass; - alpha_E_norm[i] = nu_frac * gkyl_calc_Morse_alpha_E_const( - gks->info.collisions.den_ref, lbo->collide_with[i]->info.collisions.den_ref, - mass_self, mass_other, gks->info.charge, lbo->collide_with[i]->info.charge, - gks->info.collisions.temp_ref, lbo->collide_with[i]->info.collisions.temp_ref, bmag_ref, eps0, hbar, eV); + alpha_E_norm[i] = + nu_frac * gkyl_calc_Morse_alpha_E_const( + gks->info.collisions.den_ref, lbo->collide_with[i]->info.collisions.den_ref, + mass_self, mass_other, gks->info.charge, lbo->collide_with[i]->info.charge, + gks->info.collisions.temp_ref, lbo->collide_with[i]->info.collisions.temp_ref, + bmag_ref, eps0, hbar, eV + ); } if (gks->info.collisions.cross_nu[0]) { @@ -402,15 +463,17 @@ gk_species_lbo_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g lbo->norm_nu_cross = false; // Ensure the other species this collides with also provided self_nu and cross_nu. - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < lbo->num_cross_collisions; ++i) { assert(lbo->collide_with[i]->info.collisions.self_nu); assert(lbo->collide_with[i]->info.collisions.cross_nu[my_idx_in_other[i]]); } struct gkyl_array *cross_nu_ho = mkarr(false, app->basis.num_basis, app->local_ext.volume); - for (int i=0; inum_cross_collisions; ++i) { - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(&app->grid, &app->basis, - app->poly_order+1, 1, gks->info.collisions.cross_nu[i], gks->info.collisions.cross_nu_ctx); + for (int i = 0; i < lbo->num_cross_collisions; ++i) { + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + &app->grid, &app->basis, app->poly_order + 1, 1, gks->info.collisions.cross_nu[i], + gks->info.collisions.cross_nu_ctx + ); gkyl_proj_on_basis_advance(proj, 0.0, &app->local, cross_nu_ho); gkyl_proj_on_basis_release(proj); gkyl_array_copy(lbo->cross_nu[i], cross_nu_ho); @@ -426,44 +489,47 @@ gk_species_lbo_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g double mass_self = gks->info.mass, mass_other = lbo->collide_with[i]->info.mass; double den_s = gks->info.collisions.den_ref; double den_r = lbo->collide_with[i]->info.collisions.den_ref; - double vtsq_s = gks->info.collisions.temp_ref/mass_self; - double vtsq_r = lbo->collide_with[i]->info.collisions.temp_ref/mass_other; + double vtsq_s = gks->info.collisions.temp_ref / mass_self; + double vtsq_r = lbo->collide_with[i]->info.collisions.temp_ref / mass_other; - lbo->alpha_E_fac[i] = ( alpha_E_norm[i] * den_s * den_r / pow(sqrt(vtsq_s+vtsq_r),3.0) ) * pow(sqrt(2.0),app->cdim); + lbo->alpha_E_fac[i] = + (alpha_E_norm[i] * den_s * den_r / pow(sqrt(vtsq_s + vtsq_r), 3.0)) * + pow(sqrt(2.0), app->cdim); } gkyl_array_release(cross_nu_ho); // Set pointers to functions chosen at runtime. lbo->cross_nu_func = gklbo_cross_nu_calc_constNu; lbo->alpha_E_func = gklbo_alpha_E_constNu; - } - else { + } else { // Cross-collision frequency computed in time. lbo->norm_nu_cross = true; // Ensure the other species this collides with didn't provide self_nu nor cross_nu. - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < lbo->num_cross_collisions; ++i) { assert(!(lbo->collide_with[i]->info.collisions.self_nu)); assert(!(lbo->collide_with[i]->info.collisions.cross_nu[my_idx_in_other[i]])); } - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < lbo->num_cross_collisions; ++i) { double mass_self = gks->info.mass, mass_other = lbo->collide_with[i]->info.mass; - lbo->norm_nu_fac_cross[i] = alpha_E_norm[i] - * (mass_self+mass_other)/(lbo->delta_sr*lbo->betaGreenep1*mass_self); + lbo->norm_nu_fac_cross[i] = alpha_E_norm[i] * (mass_self + mass_other) / + (lbo->delta_sr * lbo->betaGreenep1 * mass_self); - lbo->alpha_E_fac[i] = (lbo->delta_sr*lbo->betaGreenep1*mass_self)/(mass_self+mass_other); + lbo->alpha_E_fac[i] = + (lbo->delta_sr * lbo->betaGreenep1 * mass_self) / (mass_self + mass_other); } - + // Set pointers to functions chosen at runtime. lbo->cross_nu_func = gklbo_cross_nu_calc_normNu; lbo->alpha_E_func = gklbo_alpha_E_normNu; } // Cross-primitive moment calculator. - lbo->cross_calc = gkyl_prim_lbo_gyrokinetic_cross_calc_new(&gks->grid, - &app->basis, &gks->basis, &app->local, app->use_gpu); + lbo->cross_calc = gkyl_prim_lbo_gyrokinetic_cross_calc_new( + &gks->grid, &app->basis, &gks->basis, &app->local, app->use_gpu + ); // Methods chosen at runtime. lbo->cross_moms_func = gklbo_cross_moms_enabled; @@ -471,42 +537,48 @@ gk_species_lbo_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *g } } -void -gk_species_lbo_moms(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin) +void gk_species_lbo_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin +) { lbo->moms_func(app, species, lbo, fin); } -void -gk_species_lbo_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin) +void gk_species_lbo_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin +) { lbo->cross_moms_func(app, species, lbo); } -void -gk_species_lbo_rhs(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_species_lbo_rhs( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { lbo->rhs_func(app, gks, lbo, fin, rhs); } -void -gk_species_lbo_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_lbo_write_mom( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { gks->lbo.write_mom_func(app, gks, tm, frame); } -void -gk_species_lbo_release(const struct gkyl_gyrokinetic_app *app, const struct gk_lbo_collisions *lbo) +void gk_species_lbo_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_lbo_collisions *lbo +) { if (lbo->collision_id == GKYL_LBO_COLLISIONS) { if (lbo->num_cross_collisions) { gkyl_prim_lbo_cross_calc_release(lbo->cross_calc); - for (int i=0; inum_cross_collisions; ++i) + for (int i = 0; i < lbo->num_cross_collisions; ++i) { gkyl_array_release(lbo->cross_nu[i]); + } gkyl_array_release(lbo->alpha_E); } @@ -516,7 +588,7 @@ gk_species_lbo_release(const struct gkyl_gyrokinetic_app *app, const struct gk_l if (lbo->write_diagnostics) { if (app->use_gpu) { gkyl_array_release(lbo->nu_sum_host); - gkyl_array_release(lbo->nu_prim_moms_host); + gkyl_array_release(lbo->nu_prim_moms_host); } } @@ -534,8 +606,9 @@ gk_species_lbo_release(const struct gkyl_gyrokinetic_app *app, const struct gk_l gkyl_array_release(lbo->nu_moms); gk_species_moment_release(app, &lbo->moms); - if (lbo->norm_nu_self) + if (lbo->norm_nu_self) { gkyl_spitzer_coll_freq_release(lbo->spitzer_calc); + } gkyl_array_release(lbo->nu_sum); gkyl_array_release(lbo->self_nu); diff --git a/gyrokinetic/apps/gk_species_lte.c b/gyrokinetic/apps/gk_species_lte.c index 8d9f42bcfc..9e80b8c40a 100644 --- a/gyrokinetic/apps/gk_species_lte.c +++ b/gyrokinetic/apps/gk_species_lte.c @@ -1,9 +1,10 @@ #include #include -void -gk_species_lte_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_lte *lte, - struct correct_all_moms_inp corr_inp) +void gk_species_lte_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_lte *lte, + struct correct_all_moms_inp corr_inp +) { int cdim = app->cdim; @@ -14,40 +15,40 @@ gk_species_lte_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, stru .phase_grid = &s->grid, .conf_basis = &app->basis, .phase_basis = &s->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .vel_range = &s->local_vel, .gk_geom = app->gk_geom, .vel_map = s->vel_map, .mass = s->info.mass, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - lte->proj_max = gkyl_gk_maxwellian_proj_on_basis_inew( &inp_proj ); + lte->proj_max = gkyl_gk_maxwellian_proj_on_basis_inew(&inp_proj); lte->correct_all_moms = corr_inp.correct_all_moms; int max_iter = corr_inp.max_iter > 0 ? corr_inp.max_iter : 50; - double iter_eps = corr_inp.iter_eps > 0 ? corr_inp.iter_eps : 1e-10; + double iter_eps = corr_inp.iter_eps > 0 ? corr_inp.iter_eps : 1e-10; bool use_last_converged = corr_inp.use_last_converged; - + if (lte->correct_all_moms) { struct gkyl_gk_maxwellian_correct_inp inp_corr = { .phase_grid = &s->grid, .conf_basis = &app->basis, .phase_basis = &s->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, - .vel_range = &s->local_vel, + .vel_range = &s->local_vel, .gk_geom = app->gk_geom, .vel_map = s->vel_map, .mass = s->info.mass, .max_iter = max_iter, .eps = iter_eps, - .use_last_converged = use_last_converged, - .use_gpu = app->use_gpu, + .use_last_converged = use_last_converged, + .use_gpu = app->use_gpu }; lte->n_iter = 0; // Total number of iterations from correcting moments. lte->num_corr = 0; // Total number of times the correction updater is called. - lte->corr_max = gkyl_gk_maxwellian_correct_inew( &inp_corr ); + lte->corr_max = gkyl_gk_maxwellian_correct_inew(&inp_corr); lte->corr_stat = gkyl_dynvec_new(GKYL_DOUBLE, 5); lte->is_first_corr_status_write_call = true; @@ -57,9 +58,10 @@ gk_species_lte_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, stru } // Compute f_lte from input Maxwellian (LTE=local thermodynamic equilibrium) moments -void -gk_species_lte_from_moms(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lte *lte, const struct gkyl_array *moms_lte) +void gk_species_lte_from_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lte *lte, + const struct gkyl_array *moms_lte +) { struct timespec wst = gkyl_wall_clock(); @@ -67,50 +69,53 @@ gk_species_lte_from_moms(gkyl_gyrokinetic_app *app, const struct gk_species *spe // Project the Maxwellian distribution function to obtain f_lte. // Projection routine also corrects the density of the projected distribution function. - gkyl_gk_maxwellian_proj_on_basis_advance(lte->proj_max, &species->local, &app->local, - moms_lte, false, lte->f_lte); + gkyl_gk_maxwellian_proj_on_basis_advance( + lte->proj_max, &species->local, &app->local, moms_lte, false, lte->f_lte + ); // Correct all the moments of the projected Maxwellian distribution function. if (lte->correct_all_moms) { struct gkyl_gk_maxwellian_correct_status status_corr; - status_corr = gkyl_gk_maxwellian_correct_all_moments(lte->corr_max, lte->f_lte, moms_lte, - &species->local, &app->local); - double corr_vec[5] = { 0.0 }; + status_corr = gkyl_gk_maxwellian_correct_all_moments( + lte->corr_max, lte->f_lte, moms_lte, &species->local, &app->local + ); + double corr_vec[5] = {0.0}; corr_vec[0] = status_corr.num_iter; corr_vec[1] = status_corr.iter_converged; corr_vec[2] = status_corr.error[0]; corr_vec[3] = status_corr.error[1]; corr_vec[4] = status_corr.error[2]; - double corr_vec_global[5] = { 0.0 }; - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 5, corr_vec, corr_vec_global); + double corr_vec_global[5] = {0.0}; + gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 5, corr_vec, corr_vec_global); gkyl_dynvec_append(lte->corr_stat, app->tcurr, corr_vec_global); lte->n_iter += status_corr.num_iter; lte->num_corr += 1; - } + } - app->stat.species_lte_tm += gkyl_time_diff_now_sec(wst); + app->stat.species_lte_tm += gkyl_time_diff_now_sec(wst); } -void -gk_species_lte(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lte *lte, const struct gkyl_array *fin) +void gk_species_lte( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lte *lte, + const struct gkyl_array *fin +) { struct timespec wst = gkyl_wall_clock(); // Compute needed Maxwellian moments (J*n, u_par, T/m). gk_species_moment_calc(<e->moms, species->local, app->local, fin); - + // Divide out the Jacobian from the density. - gkyl_dg_div_op_range(lte->moms.mem_geo, &app->basis, - 0, lte->moms.marr, 0, lte->moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); - app->stat.species_lte_tm += gkyl_time_diff_now_sec(wst); + gkyl_dg_div_op_range( + lte->moms.mem_geo, &app->basis, 0, lte->moms.marr, 0, lte->moms.marr, 0, + app->gk_geom->geo_int.jacobgeo, &app->local + ); + app->stat.species_lte_tm += gkyl_time_diff_now_sec(wst); gk_species_lte_from_moms(app, species, lte, lte->moms.marr); } -void -gk_species_lte_write_max_corr_status(gkyl_gyrokinetic_app* app, struct gk_species *gks) +void gk_species_lte_write_max_corr_status(gkyl_gyrokinetic_app *app, struct gk_species *gks) { if (gks->lte.correct_all_moms) { struct timespec wst = gkyl_wall_clock(); @@ -121,23 +126,27 @@ gk_species_lte_write_max_corr_status(gkyl_gyrokinetic_app* app, struct gk_specie // Write out correction status. const char *fmt = "%s-%s_lte_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, "corr_max_stat"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, "corr_max_stat"); if (gks->lte.is_first_corr_status_write_call) { // Write to a new file (this ensure previous output is removed). struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Statistics on the Maxwellian correction." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Statistics on the Maxwellian correction."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(gks->lte.corr_stat, fileNm, mt); gks->lte.is_first_corr_status_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { // Append to existing file. gkyl_dynvec_awrite(gks->lte.corr_stat, fileNm); } @@ -145,12 +154,11 @@ gk_species_lte_write_max_corr_status(gkyl_gyrokinetic_app* app, struct gk_specie gkyl_dynvec_clear(gks->lte.corr_stat); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); - app->stat.n_diag_io += 1; + app->stat.n_diag_io += 1; } } -void -gk_species_lte_release(const struct gkyl_gyrokinetic_app *app, const struct gk_lte *lte) +void gk_species_lte_release(const struct gkyl_gyrokinetic_app *app, const struct gk_lte *lte) { gkyl_array_release(lte->f_lte); diff --git a/gyrokinetic/apps/gk_species_moment.c b/gyrokinetic/apps/gk_species_moment.c index c725488b73..e413c397d5 100644 --- a/gyrokinetic/apps/gk_species_moment.c +++ b/gyrokinetic/apps/gk_species_moment.c @@ -1,35 +1,43 @@ #include #include -static void -gk_species_moment_diag_jacobgeo_div_disabled(const struct gkyl_gyrokinetic_app *app, - struct gk_species_moment *sm, struct gkyl_array *Jmom_in, struct gkyl_array *mom_out) +static void gk_species_moment_diag_jacobgeo_div_disabled( + const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, struct gkyl_array *Jmom_in, + struct gkyl_array *mom_out +) { // Do nothing. } -static void -gk_species_moment_diag_jacobgeo_div_enabled_1st_comp(const struct gkyl_gyrokinetic_app *app, - struct gk_species_moment *sm, struct gkyl_array *Jmom_in, struct gkyl_array *mom_out) +static void gk_species_moment_diag_jacobgeo_div_enabled_1st_comp( + const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, struct gkyl_array *Jmom_in, + struct gkyl_array *mom_out +) { // Only divide the first component. - gkyl_dg_div_op_range(sm->mem_geo, &app->basis, 0, mom_out, 0, Jmom_in, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + sm->mem_geo, &app->basis, 0, mom_out, 0, Jmom_in, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); } -static void -gk_species_moment_diag_jacobgeo_div_enabled_all_comp(const struct gkyl_gyrokinetic_app *app, - struct gk_species_moment *sm, struct gkyl_array *Jmom_in, struct gkyl_array *mom_out) +static void gk_species_moment_diag_jacobgeo_div_enabled_all_comp( + const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, struct gkyl_array *Jmom_in, + struct gkyl_array *mom_out +) { // Divide all components. - for (int k=0; knum_mom; k++) - gkyl_dg_div_op_range(sm->mem_geo, &app->basis, k, mom_out, k, Jmom_in, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + for (int k = 0; k < sm->num_mom; k++) { + gkyl_dg_div_op_range( + sm->mem_geo, &app->basis, k, mom_out, k, Jmom_in, 0, app->gk_geom->geo_int.jacobgeo, + &app->local + ); + } } -void -gk_species_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_species_moment *sm, enum gkyl_distribution_moments mom_type, bool is_integrated) +void gk_species_moment_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_species_moment *sm, + enum gkyl_distribution_moments mom_type, bool is_integrated +) { sm->is_integrated = is_integrated; sm->is_maxwellian_moms = mom_type == GKYL_F_MOMENT_MAXWELLIAN; @@ -38,9 +46,10 @@ gk_species_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, if (sm->is_integrated) { // Create moment operator. - sm->mcalc = gkyl_dg_updater_moment_gyrokinetic_new(&s->grid, &app->basis, - &s->basis, &app->local_ext, s->info.mass, s->info.charge, s->vel_map, app->gk_geom, - app->field->phi_smooth, mom_type, sm->is_integrated, app->use_gpu); + sm->mcalc = gkyl_dg_updater_moment_gyrokinetic_new( + &s->grid, &app->basis, &s->basis, &app->local_ext, s->info.mass, s->info.charge, s->vel_map, + app->gk_geom, app->field->phi_smooth, mom_type, sm->is_integrated, app->use_gpu + ); sm->num_mom = gkyl_dg_updater_moment_gyrokinetic_num_mom(sm->mcalc); @@ -48,105 +57,100 @@ gk_species_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, sm->marr = mkarr(app->use_gpu, sm->num_mom, app->local_ext.volume); sm->marr_host = sm->marr; if (app->use_gpu) { - sm->marr_host = mkarr(false, sm->num_mom, app->local_ext.volume); + sm->marr_host = mkarr(false, sm->num_mom, app->local_ext.volume); } - } - else { + } else { // Create moment operator. if (sm->is_maxwellian_moms || sm->is_bimaxwellian_moms) { struct gkyl_gk_maxwellian_moments_inp inp_mom = { .phase_grid = &s->grid, .conf_basis = &app->basis, .phase_basis = &s->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .gk_geom = app->gk_geom, .vel_map = s->vel_map, - .divide_jacobgeo = false, + .divide_jacobgeo = false, .mass = s->info.mass, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - sm->gyrokinetic_maxwellian_moms = gkyl_gk_maxwellian_moments_inew( &inp_mom ); + sm->gyrokinetic_maxwellian_moms = gkyl_gk_maxwellian_moments_inew(&inp_mom); if (sm->is_maxwellian_moms) { sm->num_mom = 3; // (n, u_par, T/m) - } - else { + } else { sm->num_mom = 4; // (n, u_par, T_par/m, T_perp/m) - } + } sm->diag_jacobgeo_div_func = gk_species_moment_diag_jacobgeo_div_enabled_1st_comp; - } - else { - sm->mcalc = gkyl_dg_updater_moment_gyrokinetic_new(&s->grid, &app->basis, - &s->basis, &app->local_ext, s->info.mass, s->info.charge, s->vel_map, app->gk_geom, - app->field->phi_smooth, mom_type, sm->is_integrated, app->use_gpu); + } else { + sm->mcalc = gkyl_dg_updater_moment_gyrokinetic_new( + &s->grid, &app->basis, &s->basis, &app->local_ext, s->info.mass, s->info.charge, s->vel_map, + app->gk_geom, app->field->phi_smooth, mom_type, sm->is_integrated, app->use_gpu + ); sm->num_mom = gkyl_dg_updater_moment_gyrokinetic_num_mom(sm->mcalc); sm->diag_jacobgeo_div_func = gk_species_moment_diag_jacobgeo_div_enabled_all_comp; } // Allocate arrays to hold moments. - sm->marr = mkarr(app->use_gpu, sm->num_mom*app->basis.num_basis, app->local_ext.volume); + sm->marr = mkarr(app->use_gpu, sm->num_mom * app->basis.num_basis, app->local_ext.volume); sm->marr_host = sm->marr; if (app->use_gpu) { - sm->marr_host = mkarr(false, sm->num_mom*app->basis.num_basis, app->local_ext.volume); + sm->marr_host = mkarr(false, sm->num_mom * app->basis.num_basis, app->local_ext.volume); } // Bin Op memory for rescaling moment by inverse of Jacobian if (app->use_gpu) { sm->mem_geo = gkyl_dg_bin_op_mem_cu_dev_new(app->local.volume, app->basis.num_basis); - } - else { + } else { sm->mem_geo = gkyl_dg_bin_op_mem_new(app->local.volume, app->basis.num_basis); } } } -void -gk_species_moment_calc(const struct gk_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin) +void gk_species_moment_calc( + const struct gk_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +) { if (sm->is_integrated) { - gkyl_dg_updater_moment_gyrokinetic_advance(sm->mcalc, - &phase_rng, &conf_rng, fin, sm->marr); - } - else { + gkyl_dg_updater_moment_gyrokinetic_advance(sm->mcalc, &phase_rng, &conf_rng, fin, sm->marr); + } else { if (sm->is_maxwellian_moms) { - gkyl_gk_maxwellian_moments_advance(sm->gyrokinetic_maxwellian_moms, - &phase_rng, &conf_rng, fin, sm->marr); - } - else if (sm->is_bimaxwellian_moms) { - gkyl_gk_bimaxwellian_moments_advance(sm->gyrokinetic_maxwellian_moms, - &phase_rng, &conf_rng, fin, sm->marr); - } - else { - gkyl_dg_updater_moment_gyrokinetic_advance(sm->mcalc, - &phase_rng, &conf_rng, fin, sm->marr); + gkyl_gk_maxwellian_moments_advance( + sm->gyrokinetic_maxwellian_moms, &phase_rng, &conf_rng, fin, sm->marr + ); + } else if (sm->is_bimaxwellian_moms) { + gkyl_gk_bimaxwellian_moments_advance( + sm->gyrokinetic_maxwellian_moms, &phase_rng, &conf_rng, fin, sm->marr + ); + } else { + gkyl_dg_updater_moment_gyrokinetic_advance(sm->mcalc, &phase_rng, &conf_rng, fin, sm->marr); } } } -void -gk_species_moment_diag_jacobgeo_div(const struct gkyl_gyrokinetic_app *app, - struct gk_species_moment *sm, struct gkyl_array *Jmom_in, struct gkyl_array *mom_out) +void gk_species_moment_diag_jacobgeo_div( + const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, struct gkyl_array *Jmom_in, + struct gkyl_array *mom_out +) { sm->diag_jacobgeo_div_func(app, sm, Jmom_in, mom_out); } -void -gk_species_moment_release(const struct gkyl_gyrokinetic_app *app, const struct gk_species_moment *sm) +void gk_species_moment_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_species_moment *sm +) { gkyl_array_release(sm->marr); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_release(sm->marr_host); + } if (sm->is_integrated) { gkyl_dg_updater_moment_gyrokinetic_release(sm->mcalc); - } - else { + } else { if (sm->is_maxwellian_moms || sm->is_bimaxwellian_moms) { gkyl_gk_maxwellian_moments_release(sm->gyrokinetic_maxwellian_moms); - } - else { + } else { gkyl_dg_updater_moment_gyrokinetic_release(sm->mcalc); } diff --git a/gyrokinetic/apps/gk_species_positivity.c b/gyrokinetic/apps/gk_species_positivity.c index 8304c24d05..f25c34de3d 100644 --- a/gyrokinetic/apps/gk_species_positivity.c +++ b/gyrokinetic/apps/gk_species_positivity.c @@ -1,28 +1,28 @@ #include #include -int -gk_species_positivity_num_species_in_quasineut(gkyl_gyrokinetic_app* app) +int gk_species_positivity_num_species_in_quasineut(gkyl_gyrokinetic_app *app) { int num_quasineut_rescale = 0; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *s = &app->species[i]; - if (s->info.positivity.type && s->info.positivity.quasineutrality_rescale) + if (s->info.positivity.type && s->info.positivity.quasineutrality_rescale) { num_quasineut_rescale += 1; + } } return num_quasineut_rescale; } -static void -gks_pos_write_diags_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos, double tm, int frame) +static void gks_pos_write_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, double tm, int frame +) { // Empty. } -static void -gks_pos_deltaf_moms_calc(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos) +static void gks_pos_deltaf_moms_calc( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos +) { gk_species_moment_calc(&pos->moms, gks->local, app->local, pos->fbuffer_ptr); @@ -30,28 +30,32 @@ gks_pos_deltaf_moms_calc(gkyl_gyrokinetic_app* app, struct gk_species *gks, gk_species_moment_diag_jacobgeo_div(app, &pos->moms, pos->moms.marr, pos->moms.marr); } -static void -gks_pos_deltaf_moms_clear(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos) +static void gks_pos_deltaf_moms_clear( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos +) { gkyl_array_clear(pos->moms.marr, 0.0); pos->deltaf_moms_func = gks_pos_deltaf_moms_calc; } -static void -gks_pos_write_diags_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos, double tm, int frame) +static void gks_pos_write_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, double tm, int frame +) { // Package metadata. gkyl_msgpack_map_elem_set_double(gks->io_meta_conf_len, gks->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_conf_len, gks->io_meta_conf, "frame", frame); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, - .cval = "M0M1M2PARM2PERP moments of the change in the distribution by the positivity shift." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "M0M1M2PARM2PERP moments of the change in the distribution by the positivity shift."} }; int io_meta_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); struct timespec wst = gkyl_wall_clock(); // We placed the change in f in fbuffer_ptr. @@ -59,88 +63,94 @@ gks_pos_write_diags_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); app->stat.n_mom += 1; - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(pos->moms.marr_host, pos->moms.marr); + } const char *fmt = "%s-%s_positivity_%s_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, - gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2PARM2PERP], frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, - gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2PARM2PERP], frame); - + int sz = gkyl_calc_strlen( + fmt, app->name, gks->info.name, gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2PARM2PERP], + frame + ); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gks->info.name, + gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2PARM2PERP], frame + ); + struct timespec wtm = gkyl_wall_clock(); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, - pos->moms.marr_host, fileNm); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, pos->moms.marr_host, fileNm); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); app->stat.n_diag_io += 1; - - gkyl_msgpack_data_release(mt); + + gkyl_msgpack_data_release(mt); app->stat.n_diag += 1; } -static void -gks_pos_calc_integrated_diags_disabled(gkyl_gyrokinetic_app* app, - struct gk_species *gks, struct gk_positivity *pos, double tm) +static void gks_pos_calc_integrated_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, double tm +) { // Empty. } -static void -gks_pos_deltaf_integ_moms_calc(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos) +static void gks_pos_deltaf_integ_moms_calc( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos +) { - gk_species_moment_calc(&pos->integ_moms, gks->local, app->local, pos->fbuffer_ptr); + gk_species_moment_calc(&pos->integ_moms, gks->local, app->local, pos->fbuffer_ptr); } -static void -gks_pos_deltaf_integ_moms_clear(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos) +static void gks_pos_deltaf_integ_moms_clear( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos +) { gkyl_array_clear(pos->integ_moms.marr, 0.0); pos->deltaf_integ_moms_func = gks_pos_deltaf_integ_moms_calc; } -static void -gks_pos_calc_integrated_diags_enabled(gkyl_gyrokinetic_app* app, - struct gk_species *gks, struct gk_positivity *pos, double tm) +static void gks_pos_calc_integrated_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, double tm +) { struct timespec wst = gkyl_wall_clock(); int num_mom = pos->integ_moms.num_mom; double avals_global[num_mom]; - + // The change in f after the positivity operation is stored in fbuffer_ptr. pos->deltaf_integ_moms_func(app, gks, pos); app->stat.n_mom += 1; // Reduce (sum) over whole domain, append to diagnostics. gkyl_array_reduce_range(pos->red_integ_diag, pos->integ_moms.marr, GKYL_SUM, &app->local); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, - pos->red_integ_diag, pos->red_integ_diag_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, pos->red_integ_diag, pos->red_integ_diag_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, pos->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, pos->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, pos->red_integ_diag_global, sizeof(double[num_mom])); } gkyl_dynvec_append(pos->integ_diag, tm, avals_global); - + app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); app->stat.n_diag += 1; } -static void -gks_pos_write_integrated_diags_disabled(gkyl_gyrokinetic_app *app, - struct gk_species *gks, struct gk_positivity *pos) +static void gks_pos_write_integrated_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos +) { // Empty. } -static void -gks_pos_write_integrated_diags_enabled(gkyl_gyrokinetic_app *app, - struct gk_species *gks, struct gk_positivity *pos) +static void gks_pos_write_integrated_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos +) { struct timespec wst = gkyl_wall_clock(); @@ -151,58 +161,65 @@ gks_pos_write_integrated_diags_enabled(gkyl_gyrokinetic_app *app, // Write integrated diagnostic moments. const char *fmt = "%s-%s_positivity_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, "integrated_moms"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, "integrated_moms"); if (pos->is_first_integ_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated moments of change in distribution due to positivity shift." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Volume integrated moments of change in distribution due to positivity shift."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(pos->integ_diag, fileNm, mt); pos->is_first_integ_write_call = false; pos->integ_diag_file_exists = true; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(pos->integ_diag, fileNm); } } gkyl_dynvec_clear(pos->integ_diag); app->stat.n_diag_io += 1; - + app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); } -void -gks_pos_apply_disabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_positivity *pos, struct gkyl_array *fbuffer, struct gkyl_array *fout) +void gks_pos_apply_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_positivity *pos, + struct gkyl_array *fbuffer, struct gkyl_array *fout +) { // Do nothing. } -void -gks_pos_apply_enabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_positivity *pos, struct gkyl_array *fbuffer, struct gkyl_array *fout) +void gks_pos_apply_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, + struct gkyl_array *fbuffer, struct gkyl_array *fout +) { struct timespec wtm = gkyl_wall_clock(); - // Copy f so we can calculate the moments of delta f later. + // Copy f so we can calculate the moments of delta f later. pos->fbuffer_ptr = fbuffer; gkyl_array_set(pos->fbuffer_ptr, -1.0, fout); // Shift each species. - gkyl_positivity_shift_gyrokinetic_advance(pos->shift_op_gk, &app->local, &gks->local, - fout, gks->m0.marr, pos->delta_m0); + gkyl_positivity_shift_gyrokinetic_advance( + pos->shift_op_gk, &app->local, &gks->local, fout, gks->m0.marr, pos->delta_m0 + ); app->stat.species_pos_shift_tm += gkyl_time_diff_now_sec(wtm); } -void -gk_species_positivity_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_positivity *pos) +void gk_species_positivity_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos +) { pos->type = gks->info.positivity.type; pos->write_diagnostics = gks->info.positivity.write_diagnostics; @@ -214,12 +231,13 @@ gk_species_positivity_init(struct gkyl_gyrokinetic_app *app, struct gk_species * pos->write_integrated_diags_func = gks_pos_write_integrated_diags_disabled; if (pos->type) { - pos->delta_m0 = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); // Positivity shift updater. - pos->shift_op_gk = gkyl_positivity_shift_gyrokinetic_new(app->basis, gks->basis, - gks->grid, gks->info.mass, app->gk_geom, gks->vel_map, &app->local_ext, app->use_gpu); + pos->shift_op_gk = gkyl_positivity_shift_gyrokinetic_new( + app->basis, gks->basis, gks->grid, gks->info.mass, app->gk_geom, gks->vel_map, + &app->local_ext, app->use_gpu + ); // Methods chosen at runtime. pos->apply_func = gks_pos_apply_enabled; @@ -234,8 +252,7 @@ gk_species_positivity_init(struct gkyl_gyrokinetic_app *app, struct gk_species * if (app->use_gpu) { pos->red_integ_diag = gkyl_cu_malloc(sizeof(double[pos->integ_moms.num_mom])); pos->red_integ_diag_global = gkyl_cu_malloc(sizeof(double[pos->integ_moms.num_mom])); - } - else { + } else { pos->red_integ_diag = gkyl_malloc(sizeof(double[pos->integ_moms.num_mom])); pos->red_integ_diag_global = gkyl_malloc(sizeof(double[pos->integ_moms.num_mom])); } @@ -255,49 +272,48 @@ gk_species_positivity_init(struct gkyl_gyrokinetic_app *app, struct gk_species * if (gks->info.charge > 0.0) { pos->delta_m0s_tot = gkyl_array_acquire(app->ps_delta_m0_ions); pos->delta_m0r_tot = gkyl_array_acquire(app->ps_delta_m0_elcs); - } - else { + } else { pos->delta_m0s_tot = gkyl_array_acquire(app->ps_delta_m0_elcs); pos->delta_m0r_tot = gkyl_array_acquire(app->ps_delta_m0_ions); } } - } } -void -gk_species_positivity_apply(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_positivity *pos, struct gkyl_array *fbuffer, struct gkyl_array *fout) +void gk_species_positivity_apply( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, + struct gkyl_array *fbuffer, struct gkyl_array *fout +) { pos->apply_func(app, gks, pos, fbuffer, fout); } -void -gk_species_positivity_write_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos, double tm, int frame) +void gk_species_positivity_write_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, double tm, int frame +) { pos->write_diags_func(app, gks, pos, tm, frame); } -void -gk_species_positivity_calc_integrated_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos, double tm) +void gk_species_positivity_calc_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, double tm +) { pos->calc_integrated_diags_func(app, gks, pos, tm); } -void -gk_species_positivity_write_integrated_diags(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_positivity *pos) +void gk_species_positivity_write_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos +) { pos->write_integrated_diags_func(app, gks, pos); } -void -gk_species_positivity_release(const struct gkyl_gyrokinetic_app *app, const struct gk_positivity *pos) +void gk_species_positivity_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_positivity *pos +) { if (pos->type) { - gkyl_array_release(pos->delta_m0); gkyl_positivity_shift_gyrokinetic_release(pos->shift_op_gk); if (app->post_positivity_quasineut) { @@ -307,24 +323,23 @@ gk_species_positivity_release(const struct gkyl_gyrokinetic_app *app, const stru if (pos->write_diagnostics) { gk_species_moment_release(app, &pos->moms); - gk_species_moment_release(app, &pos->integ_moms); + gk_species_moment_release(app, &pos->integ_moms); gkyl_dynvec_release(pos->integ_diag); if (app->use_gpu) { gkyl_cu_free(pos->red_integ_diag); gkyl_cu_free(pos->red_integ_diag_global); - } - else { + } else { gkyl_free(pos->red_integ_diag); gkyl_free(pos->red_integ_diag_global); } } - } } -void -gk_species_positivity_reset(gkyl_gyrokinetic_app* app, double tm, - struct gk_species *gks, struct gk_positivity *pos, struct gkyl_gyrokinetic_positivity pos_inp) +void gk_species_positivity_reset( + gkyl_gyrokinetic_app *app, double tm, struct gk_species *gks, struct gk_positivity *pos, + struct gkyl_gyrokinetic_positivity pos_inp +) { gk_species_positivity_release(app, pos); @@ -332,11 +347,12 @@ gk_species_positivity_reset(gkyl_gyrokinetic_app* app, double tm, int num_quasineut_rescale = gk_species_positivity_num_species_in_quasineut(app); if (app->post_positivity_quasineut) { - if (num_quasineut_rescale < 2) + if (num_quasineut_rescale < 2) { gyrokinetic_post_positivity_quasineut_release(app); - } - else + } + } else { gyrokinetic_post_positivity_quasineut_init(app); + } gk_species_positivity_init(app, gks, pos); diff --git a/gyrokinetic/apps/gk_species_projection.c b/gyrokinetic/apps/gk_species_projection.c index 843e0601e8..749f396fa8 100644 --- a/gyrokinetic/apps/gk_species_projection.c +++ b/gyrokinetic/apps/gk_species_projection.c @@ -2,27 +2,28 @@ #include #include -static void -load_projection_moment_from_file(struct gkyl_gyrokinetic_app *app, struct gkyl_array *arr, - const struct gkyl_gyrokinetic_ic_import *inp) +static void load_projection_moment_from_file( + struct gkyl_gyrokinetic_app *app, struct gkyl_array *arr, + const struct gkyl_gyrokinetic_ic_import *inp +) { if (inp == NULL || inp->type == GKYL_IC_IMPORT_NONE) { return; } - struct gkyl_array *arr_host = app->use_gpu ? mkarr(false, arr->ncomp, arr->size) - : gkyl_array_acquire(arr); + struct gkyl_array *arr_host = app->use_gpu ? mkarr(false, arr->ncomp, arr->size) : + gkyl_array_acquire(arr); - struct gkyl_app_restart_status rstat = { .io_status = GKYL_ARRAY_RIO_FOPEN_FAILED }; - rstat.io_status = gkyl_comm_array_read(app->comm, &app->grid, &app->local, arr_host, inp->file_name); + struct gkyl_app_restart_status rstat = {.io_status = GKYL_ARRAY_RIO_FOPEN_FAILED}; + rstat.io_status = + gkyl_comm_array_read(app->comm, &app->grid, &app->local, arr_host, inp->file_name); assert(rstat.io_status == GKYL_ARRAY_RIO_SUCCESS); gkyl_array_copy(arr, arr_host); gkyl_array_release(arr_host); } -static void -proj_on_basis_c2p_phase_func(const double *xcomp, double *xphys, void *ctx) +static void proj_on_basis_c2p_phase_func(const double *xcomp, double *xphys, void *ctx) { struct gk_proj_on_basis_c2p_func_ctx *c2p_ctx = ctx; int cdim = c2p_ctx->cdim; // Assumes update range is a phase range. @@ -30,8 +31,7 @@ proj_on_basis_c2p_phase_func(const double *xcomp, double *xphys, void *ctx) gkyl_velocity_map_eval_c2p(c2p_ctx->vel_map, &xcomp[cdim], &xphys[cdim]); } -static void -proj_on_basis_c2p_position_func(const double *xcomp, double *xphys, void *ctx) +static void proj_on_basis_c2p_position_func(const double *xcomp, double *xphys, void *ctx) { struct gk_proj_on_basis_c2p_func_ctx *c2p_ctx = ctx; gkyl_position_map_eval_mc2nu(c2p_ctx->pos_map, xcomp, xphys); @@ -42,11 +42,11 @@ struct func_gaussian_ctx { bool is_dir_periodic[GKYL_MAX_CDIM]; // Periodicity in configuration space. double box_size[GKYL_MAX_CDIM]; // Size of the box in each direction double gaussian_mean[GKYL_MAX_CDIM]; // Center in configuration space. - double gaussian_std_dev[GKYL_MAX_CDIM]; // Sigma in configuration space, function is constant if sigma is 0. + double gaussian_std_dev + [GKYL_MAX_CDIM]; // Sigma in configuration space, function is constant if sigma is 0. double f_floor; // Floor value of the distribution. }; -static void -func_gaussian(double t, const double* xn, double* GKYL_RESTRICT fout, void *ctx) +static void func_gaussian(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { struct func_gaussian_ctx *inp = ctx; double envelope = 1.0; @@ -54,39 +54,44 @@ func_gaussian(double t, const double* xn, double* GKYL_RESTRICT fout, void *ctx) double dx = xn[dir] - inp->gaussian_mean[dir]; double sigma = inp->gaussian_std_dev[dir]; double L = inp->box_size[dir]; - if (inp->is_dir_periodic[dir]) { + if (inp->is_dir_periodic[dir]) { // Periodic wrapping - dx = fmod(dx + L/2.0, L); - if (dx < 0) dx += L; - dx -= L/2.0; + dx = fmod(dx + L / 2.0, L); + if (dx < 0) { + dx += L; + } + dx -= L / 2.0; + } + if (sigma > 0.0) { + envelope *= exp(-dx * dx / (2.0 * sigma * sigma)); } - if (sigma > 0.0) - envelope *= exp(-dx*dx/(2.0*sigma*sigma)); } fout[0] = envelope + inp->f_floor; } -static void -gk_species_projection_calc_proj_func(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm) +static void gk_species_projection_calc_proj_func( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm +) { if (app->use_gpu) { gkyl_proj_on_basis_advance(proj->proj_func, tm, &s->local, proj->proj_host); gkyl_array_copy(f, proj->proj_host); - } - else { + } else { gkyl_proj_on_basis_advance(proj->proj_func, tm, &s->local, f); } // Multiply by the gyrocenter coord jacobian (bmag). - gkyl_dg_mul_conf_phase_op_range(&app->basis, &s->basis, f, - app->gk_geom->geo_corn.bmag, f, &app->local, &s->local); - // Multiply by the velocity-space jacobian. + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &s->basis, f, app->gk_geom->geo_corn.bmag, f, &app->local, &s->local + ); + // Multiply by the velocity-space jacobian. gkyl_array_scale_by_cell(f, s->vel_map->jacobvel); } -static void -project_moment_if_needed(bool from_file, struct gkyl_proj_on_basis *proj_op, - double tm, const struct gkyl_range *conf_range, struct gkyl_array *arr, double scale_fac) +static void project_moment_if_needed( + bool from_file, struct gkyl_proj_on_basis *proj_op, double tm, + const struct gkyl_range *conf_range, struct gkyl_array *arr, double scale_fac +) { if (from_file) { return; @@ -98,10 +103,11 @@ project_moment_if_needed(bool from_file, struct gkyl_proj_on_basis *proj_op, } } -static void -init_moment_from_import_or_proj(struct gkyl_gyrokinetic_app *app, struct gk_proj *proj, - bool from_file, struct gkyl_array *arr, const struct gkyl_gyrokinetic_ic_import *import_inp, - evalf_t eval, void *ctx, double scale_fac, struct gkyl_proj_on_basis **proj_on_basis) +static void init_moment_from_import_or_proj( + struct gkyl_gyrokinetic_app *app, struct gk_proj *proj, bool from_file, struct gkyl_array *arr, + const struct gkyl_gyrokinetic_ic_import *import_inp, evalf_t eval, void *ctx, double scale_fac, + struct gkyl_proj_on_basis **proj_on_basis +) { if (from_file) { load_projection_moment_from_file(app, arr, import_inp); @@ -111,84 +117,89 @@ init_moment_from_import_or_proj(struct gkyl_gyrokinetic_app *app, struct gk_proj return; } - *proj_on_basis = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp) { - .grid = &app->grid, - .basis = &app->basis, - .qtype = GKYL_GAUSS_QUAD, - .num_quad = app->basis.poly_order+1, - .num_ret_vals = 1, - .eval = eval, - .ctx = ctx, - .c2p_func = proj_on_basis_c2p_position_func, - .c2p_func_ctx = &proj->proj_on_basis_c2p_ctx, - } - ); + *proj_on_basis = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &app->grid, + .basis = &app->basis, + .qtype = GKYL_GAUSS_QUAD, + .num_quad = app->basis.poly_order + 1, + .num_ret_vals = 1, + .eval = eval, + .ctx = ctx, + .c2p_func = proj_on_basis_c2p_position_func, + .c2p_func_ctx = &proj->proj_on_basis_c2p_ctx}); } -static void -gk_species_projection_calc_max_prim(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm) +static void gk_species_projection_calc_max_prim( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm +) { if (proj->maxwellian_moms_from_file) { gkyl_array_copy(proj->prim_moms, proj->prim_moms_host); - gkyl_gk_maxwellian_proj_on_basis_advance(proj->proj_max, - &s->local, &app->local, proj->prim_moms, false, f); + gkyl_gk_maxwellian_proj_on_basis_advance( + proj->proj_max, &s->local, &app->local, proj->prim_moms, false, f + ); return; } - project_moment_if_needed(proj->dens_from_file, proj->proj_dens, - tm, &app->local, proj->dens, 1.0); - project_moment_if_needed(proj->upar_from_file, proj->proj_upar, - tm, &app->local, proj->upar, 1.0); - project_moment_if_needed(proj->temp_from_file, proj->proj_temp, - tm, &app->local, proj->vtsq, 1.0/s->info.mass); + project_moment_if_needed(proj->dens_from_file, proj->proj_dens, tm, &app->local, proj->dens, 1.0); + project_moment_if_needed(proj->upar_from_file, proj->proj_upar, tm, &app->local, proj->upar, 1.0); + project_moment_if_needed( + proj->temp_from_file, proj->proj_temp, tm, &app->local, proj->vtsq, 1.0 / s->info.mass + ); // proj_maxwellian expects the primitive moments as a single array. - gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->dens, 0*app->basis.num_basis); - gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->upar, 1*app->basis.num_basis); - gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->vtsq, 2*app->basis.num_basis); + gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->dens, 0 * app->basis.num_basis); + gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->upar, 1 * app->basis.num_basis); + gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->vtsq, 2 * app->basis.num_basis); // Copy the contents into the array we will use (potentially on GPUs). gkyl_array_copy(proj->prim_moms, proj->prim_moms_host); - gkyl_gk_maxwellian_proj_on_basis_advance(proj->proj_max, - &s->local, &app->local, proj->prim_moms, false, f); + gkyl_gk_maxwellian_proj_on_basis_advance( + proj->proj_max, &s->local, &app->local, proj->prim_moms, false, f + ); } -static void -gk_species_projection_calc_bimax(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm) +static void gk_species_projection_calc_bimax( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm +) { if (proj->bimaxwellian_moms_from_file) { gkyl_array_copy(proj->prim_moms, proj->prim_moms_host); - gkyl_gk_maxwellian_proj_on_basis_advance(proj->proj_max, - &s->local, &app->local, proj->prim_moms, false, f); + gkyl_gk_maxwellian_proj_on_basis_advance( + proj->proj_max, &s->local, &app->local, proj->prim_moms, false, f + ); return; } - project_moment_if_needed(proj->dens_from_file, proj->proj_dens, - tm, &app->local, proj->dens, 1.0); - project_moment_if_needed(proj->upar_from_file, proj->proj_upar, - tm, &app->local, proj->upar, 1.0); - project_moment_if_needed(proj->temppar_from_file, proj->proj_temppar, - tm, &app->local, proj->vtsqpar, 1.0/s->info.mass); - project_moment_if_needed(proj->tempperp_from_file, proj->proj_tempperp, - tm, &app->local, proj->vtsqperp, 1.0/s->info.mass); + project_moment_if_needed(proj->dens_from_file, proj->proj_dens, tm, &app->local, proj->dens, 1.0); + project_moment_if_needed(proj->upar_from_file, proj->proj_upar, tm, &app->local, proj->upar, 1.0); + project_moment_if_needed( + proj->temppar_from_file, proj->proj_temppar, tm, &app->local, proj->vtsqpar, 1.0 / s->info.mass + ); + project_moment_if_needed( + proj->tempperp_from_file, proj->proj_tempperp, tm, &app->local, proj->vtsqperp, + 1.0 / s->info.mass + ); // proj_bimaxwellian expects the primitive moments as a single array. - gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->dens, 0*app->basis.num_basis); - gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->upar, 1*app->basis.num_basis); - gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->vtsqpar , 2*app->basis.num_basis); - gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->vtsqperp , 3*app->basis.num_basis); + gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->dens, 0 * app->basis.num_basis); + gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->upar, 1 * app->basis.num_basis); + gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->vtsqpar, 2 * app->basis.num_basis); + gkyl_array_set_offset(proj->prim_moms_host, 1.0, proj->vtsqperp, 3 * app->basis.num_basis); // Copy the contents into the array we will use (potentially on GPUs). gkyl_array_copy(proj->prim_moms, proj->prim_moms_host); - gkyl_gk_maxwellian_proj_on_basis_advance(proj->proj_max, - &s->local, &app->local, proj->prim_moms, false, f); + gkyl_gk_maxwellian_proj_on_basis_advance( + proj->proj_max, &s->local, &app->local, proj->prim_moms, false, f + ); } -static void -gk_species_projection_calc_max_gauss(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm) +static void gk_species_projection_calc_max_gauss( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm +) { bool correct_mom_setting = s->lte.correct_all_moms; s->lte.correct_all_moms = false; // Turn off moment correction for the max gauss projection. @@ -197,32 +208,41 @@ gk_species_projection_calc_max_gauss(gkyl_gyrokinetic_app *app, struct gk_specie s->lte.correct_all_moms = correct_mom_setting; // Reset to original setting. } -static void -gk_species_projection_calc_none(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm) {} +static void gk_species_projection_calc_none( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm +) +{ +} -static void -gk_species_projection_correct_all_moms(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm) +static void gk_species_projection_correct_all_moms( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm +) { struct gkyl_gk_maxwellian_correct_status status_corr; - status_corr = gkyl_gk_maxwellian_correct_all_moments(proj->corr_max, - f, proj->prim_moms, &s->local, &app->local); + status_corr = gkyl_gk_maxwellian_correct_all_moments( + proj->corr_max, f, proj->prim_moms, &s->local, &app->local + ); } -static void -gk_species_projection_correct_all_moms_none(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm) {} +static void gk_species_projection_correct_all_moms_none( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm +) +{ +} -static void -init_maxwellian_bimaxwellian(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj) - { +static void init_maxwellian_bimaxwellian( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gkyl_gyrokinetic_projection inp, + struct gk_proj *proj +) +{ bool maxwellian_moms_from_file = proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM && - inp.maxwellian_moms_import.type != GKYL_IC_IMPORT_NONE; + inp.maxwellian_moms_import.type != GKYL_IC_IMPORT_NONE; proj->maxwellian_moms_from_file = maxwellian_moms_from_file; bool bimaxwellian_moms_from_file = proj->proj_id == GKYL_PROJ_BIMAXWELLIAN && - inp.bimaxwellian_moms_import.type != GKYL_IC_IMPORT_NONE; + inp.bimaxwellian_moms_import.type != GKYL_IC_IMPORT_NONE; proj->bimaxwellian_moms_from_file = bimaxwellian_moms_from_file; // Determine whether we import the primitive moments from files or compute them from functions. @@ -236,8 +256,7 @@ init_maxwellian_bimaxwellian(struct gkyl_gyrokinetic_app *app, struct gk_species proj->dens_from_file = true; proj->upar_from_file = true; proj->temp_from_file = true; - } - else if (bimaxwellian_moms_from_file) { + } else if (bimaxwellian_moms_from_file) { proj->dens_from_file = true; proj->upar_from_file = true; proj->temppar_from_file = true; @@ -246,15 +265,15 @@ init_maxwellian_bimaxwellian(struct gkyl_gyrokinetic_app *app, struct gk_species // prim_moms_host is a combined array of all the projected moments int prim_moms_ncomp = proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM ? 3 : 4; - proj->prim_moms_host = mkarr(false, prim_moms_ncomp*app->basis.num_basis, app->local_ext.volume); + proj->prim_moms_host = + mkarr(false, prim_moms_ncomp * app->basis.num_basis, app->local_ext.volume); proj->prim_moms = mkarr(app->use_gpu, proj->prim_moms_host->ncomp, proj->prim_moms_host->size); proj->dens = mkarr(false, app->basis.num_basis, app->local_ext.volume); proj->upar = mkarr(false, app->basis.num_basis, app->local_ext.volume); if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { proj->vtsq = mkarr(false, app->basis.num_basis, app->local_ext.volume); - } - else if (proj->proj_id == GKYL_PROJ_BIMAXWELLIAN) { + } else if (proj->proj_id == GKYL_PROJ_BIMAXWELLIAN) { proj->vtsqpar = mkarr(false, app->basis.num_basis, app->local_ext.volume); proj->vtsqperp = mkarr(false, app->basis.num_basis, app->local_ext.volume); } @@ -262,28 +281,33 @@ init_maxwellian_bimaxwellian(struct gkyl_gyrokinetic_app *app, struct gk_species bool bimaxwellian = false; if (maxwellian_moms_from_file) { load_projection_moment_from_file(app, proj->prim_moms_host, &inp.maxwellian_moms_import); - } - else if (bimaxwellian_moms_from_file) { + } else if (bimaxwellian_moms_from_file) { bimaxwellian = true; load_projection_moment_from_file(app, proj->prim_moms_host, &inp.bimaxwellian_moms_import); - } - else { - init_moment_from_import_or_proj(app, proj, proj->dens_from_file, proj->dens, - &inp.density_import, inp.density, inp.ctx_density, 1.0, &proj->proj_dens); - init_moment_from_import_or_proj(app, proj, proj->upar_from_file, proj->upar, - &inp.upar_import, inp.upar, inp.ctx_upar, 1.0, &proj->proj_upar); + } else { + init_moment_from_import_or_proj( + app, proj, proj->dens_from_file, proj->dens, &inp.density_import, inp.density, + inp.ctx_density, 1.0, &proj->proj_dens + ); + init_moment_from_import_or_proj( + app, proj, proj->upar_from_file, proj->upar, &inp.upar_import, inp.upar, inp.ctx_upar, 1.0, + &proj->proj_upar + ); if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM) { - init_moment_from_import_or_proj(app, proj, proj->temp_from_file, proj->vtsq, - &inp.temp_import, inp.temp, inp.ctx_temp, 1.0/s->info.mass, &proj->proj_temp); - } - else { + init_moment_from_import_or_proj( + app, proj, proj->temp_from_file, proj->vtsq, &inp.temp_import, inp.temp, inp.ctx_temp, + 1.0 / s->info.mass, &proj->proj_temp + ); + } else { bimaxwellian = true; - init_moment_from_import_or_proj(app, proj, - proj->temppar_from_file, proj->vtsqpar, &inp.temppar_import, - inp.temppar, inp.ctx_temppar, 1.0/s->info.mass, &proj->proj_temppar); - init_moment_from_import_or_proj(app, proj, - proj->tempperp_from_file, proj->vtsqperp, &inp.tempperp_import, - inp.tempperp, inp.ctx_tempperp, 1.0/s->info.mass, &proj->proj_tempperp); + init_moment_from_import_or_proj( + app, proj, proj->temppar_from_file, proj->vtsqpar, &inp.temppar_import, inp.temppar, + inp.ctx_temppar, 1.0 / s->info.mass, &proj->proj_temppar + ); + init_moment_from_import_or_proj( + app, proj, proj->tempperp_from_file, proj->vtsqperp, &inp.tempperp_import, inp.tempperp, + inp.ctx_tempperp, 1.0 / s->info.mass, &proj->proj_tempperp + ); } } @@ -292,53 +316,53 @@ init_maxwellian_bimaxwellian(struct gkyl_gyrokinetic_app *app, struct gk_species .phase_grid = &s->grid, .conf_basis = &app->basis, .phase_basis = &s->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, - .vel_range = &s->local_vel, + .vel_range = &s->local_vel, .gk_geom = app->gk_geom, .vel_map = s->vel_map, .quad_type = inp.quad_type, .mass = s->info.mass, - .bimaxwellian = bimaxwellian, + .bimaxwellian = bimaxwellian, .divide_jacobgeo = false, // final Jacobian multiplication will be handled in advance - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - proj->proj_max = gkyl_gk_maxwellian_proj_on_basis_inew( &inp_proj ); + proj->proj_max = gkyl_gk_maxwellian_proj_on_basis_inew(&inp_proj); - proj->correct_all_moms = false; + proj->correct_all_moms = false; if (inp.correct_all_moms) { proj->correct_all_moms = true; int max_iter = inp.max_iter > 0 ? inp.max_iter : 100; - double iter_eps = inp.iter_eps > 0 ? inp.iter_eps : 1e-12; - bool use_last_converged = inp.use_last_converged; + double iter_eps = inp.iter_eps > 0 ? inp.iter_eps : 1e-12; + bool use_last_converged = inp.use_last_converged; // Maxwellian correction updater struct gkyl_gk_maxwellian_correct_inp inp_corr = { .phase_grid = &s->grid, .conf_basis = &app->basis, .phase_basis = &s->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, - .vel_range = &s->local_vel, + .vel_range = &s->local_vel, .gk_geom = app->gk_geom, .vel_map = s->vel_map, .mass = s->info.mass, - .bimaxwellian = bimaxwellian, + .bimaxwellian = bimaxwellian, .divide_jacobgeo = false, // final Jacobian multiplication will be handled in advance .max_iter = max_iter, .eps = iter_eps, - .use_last_converged = use_last_converged, - .use_gpu = app->use_gpu, + .use_last_converged = use_last_converged, + .use_gpu = app->use_gpu }; - proj->corr_max = gkyl_gk_maxwellian_correct_inew( &inp_corr ); + proj->corr_max = gkyl_gk_maxwellian_correct_inew(&inp_corr); } - } -static void -init_maxwellian_gaussian(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj) +static void init_maxwellian_gaussian( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gkyl_gyrokinetic_projection inp, + struct gk_proj *proj +) { // Fill the box_size attribute of the projection (used for periodicity). struct func_gaussian_ctx fg_ctx; @@ -350,25 +374,31 @@ init_maxwellian_gaussian(struct gkyl_gyrokinetic_app *app, struct gk_species *s, fg_ctx.box_size[dir] = app->grid.upper[dir] - app->grid.lower[dir]; } // By default, set all directions to non-periodic. - for (int dir = 0; dir < GKYL_MAX_CDIM; ++dir) + for (int dir = 0; dir < GKYL_MAX_CDIM; ++dir) { fg_ctx.is_dir_periodic[dir] = false; + } // Set periodicity for last dim if we are in IWL, and all other directions defined by the user. // First recover the BCs of the last config. space dimension for this species from the user input. - struct gkyl_gyrokinetic_bc *bc_lo = gk_fetch_bc_with_dir_edge(s->info.bcs, 2*app->cdim, app->cdim-1, GKYL_LOWER_EDGE); - struct gkyl_gyrokinetic_bc *bc_up = gk_fetch_bc_with_dir_edge(s->info.bcs, 2*app->cdim, app->cdim-1, GKYL_UPPER_EDGE); + struct gkyl_gyrokinetic_bc *bc_lo = + gk_fetch_bc_with_dir_edge(s->info.bcs, 2 * app->cdim, app->cdim - 1, GKYL_LOWER_EDGE); + struct gkyl_gyrokinetic_bc *bc_up = + gk_fetch_bc_with_dir_edge(s->info.bcs, 2 * app->cdim, app->cdim - 1, GKYL_UPPER_EDGE); if (bc_lo != 0 && bc_up != 0) { // Apply periodicity condition if both edges are IWL. - fg_ctx.is_dir_periodic[app->cdim-1] = app->gk_geom->has_LCFS || - (bc_lo->type == GKYL_BC_GK_SPECIES_TWISTSHIFT && bc_up->type == GKYL_BC_GK_SPECIES_TWISTSHIFT); + fg_ctx.is_dir_periodic[app->cdim - 1] = app->gk_geom->has_LCFS || + (bc_lo->type == GKYL_BC_GK_SPECIES_TWISTSHIFT && + bc_up->type == GKYL_BC_GK_SPECIES_TWISTSHIFT); } // Set periodicity also according to the global app settings. - for (int i=0; i < app->num_periodic_dir; ++i) + for (int i = 0; i < app->num_periodic_dir; ++i) { fg_ctx.is_dir_periodic[app->periodic_dirs[i]] = true; + } struct gkyl_array *shape_ho = mkarr(false, app->basis.num_basis, app->local_ext.volume); - struct gkyl_proj_on_basis *proj_gaussian = gkyl_proj_on_basis_new(&app->grid, &app->basis, app->poly_order + 1, 1, func_gaussian, &fg_ctx); + struct gkyl_proj_on_basis *proj_gaussian = + gkyl_proj_on_basis_new(&app->grid, &app->basis, app->poly_order + 1, 1, func_gaussian, &fg_ctx); proj->gaussian_profile = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); gkyl_proj_on_basis_advance(proj_gaussian, 0, &app->local, shape_ho); @@ -379,16 +409,21 @@ init_maxwellian_gaussian(struct gkyl_gyrokinetic_app *app, struct gk_species *s, // Build the integrant Jacobian * s(x), to normalize the shape function, and integrate it. struct gkyl_array *integrant = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - double *integral = app->use_gpu? gkyl_cu_malloc(sizeof(double)) : gkyl_malloc(sizeof(double)); - double *red_integral = app->use_gpu? gkyl_cu_malloc(sizeof(double)) : gkyl_malloc(sizeof(double)); - struct gkyl_array_integrate *int_op = gkyl_array_integrate_new(&app->grid, &app->basis, 1, - GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu); + double *integral = app->use_gpu ? gkyl_cu_malloc(sizeof(double)) : gkyl_malloc(sizeof(double)); + double *red_integral = app->use_gpu ? gkyl_cu_malloc(sizeof(double)) : + gkyl_malloc(sizeof(double)); + struct gkyl_array_integrate *int_op = gkyl_array_integrate_new( + &app->grid, &app->basis, 1, GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu + ); double red_integral_ho[1]; - gkyl_dg_mul_op_range(&app->basis, 0, integrant, 0, app->gk_geom->geo_int.jacobgeo, 0, proj->gaussian_profile, &app->local); + gkyl_dg_mul_op_range( + &app->basis, 0, integrant, 0, app->gk_geom->geo_int.jacobgeo, 0, proj->gaussian_profile, + &app->local + ); gkyl_array_integrate_advance(int_op, integrant, 1.0, NULL, &app->local, NULL, integral); gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, integral, red_integral); - + if (app->use_gpu) { gkyl_cu_memcpy(red_integral_ho, red_integral, sizeof(double), GKYL_CU_MEMCPY_D2H); gkyl_cu_free(integral); @@ -401,27 +436,33 @@ init_maxwellian_gaussian(struct gkyl_gyrokinetic_app *app, struct gk_species *s, gkyl_array_release(integrant); gkyl_array_integrate_release(int_op); // Scale the shape configuration function - gkyl_array_scale(proj->gaussian_profile, 1.0/red_integral_ho[0]); + gkyl_array_scale(proj->gaussian_profile, 1.0 / red_integral_ho[0]); // We can now build the moments of the projection. - proj->prim_moms = mkarr(app->use_gpu, 4*app->basis.num_basis, app->local_ext.volume); + proj->prim_moms = mkarr(app->use_gpu, 4 * app->basis.num_basis, app->local_ext.volume); // Density - gkyl_array_set_offset(proj->prim_moms, inp.total_num_particles + inp.f_floor, proj->gaussian_profile, 0*app->basis.num_basis); + gkyl_array_set_offset( + proj->prim_moms, inp.total_num_particles + inp.f_floor, proj->gaussian_profile, + 0 * app->basis.num_basis + ); // Parallel velocity - gkyl_array_set_offset(proj->prim_moms, 0.0, proj->gaussian_profile, 1*app->basis.num_basis); + gkyl_array_set_offset(proj->prim_moms, 0.0, proj->gaussian_profile, 1 * app->basis.num_basis); // Temperature assert(inp.temp_max > 0); - double vdim_phys = s->info.vdim == 1? 1.0 : 3.0; - double temp = inp.total_num_particles == 0 ? inp.temp_max/2.0 : 2./vdim_phys * inp.total_kin_energy/inp.total_num_particles; + double vdim_phys = s->info.vdim == 1 ? 1.0 : 3.0; + double temp = inp.total_num_particles == 0 ? + inp.temp_max / 2.0 : + 2. / vdim_phys * inp.total_kin_energy / inp.total_num_particles; temp = temp > inp.temp_max ? inp.temp_max : temp; // saturate to max temperature. double dg_norm = pow(sqrt(2.0), app->cdim); - gkyl_array_shiftc(proj->prim_moms, dg_norm * temp/s->info.mass, 2*app->basis.num_basis); + gkyl_array_shiftc(proj->prim_moms, dg_norm * temp / s->info.mass, 2 * app->basis.num_basis); // Moment correction proj->correct_all_moms = inp.correct_all_moms; } -void -gk_species_projection_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj) +void gk_species_projection_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gkyl_gyrokinetic_projection inp, + struct gk_proj *proj +) { proj->proj_id = inp.proj_id; // Context for c2p function passed to proj_on_basis. @@ -430,61 +471,63 @@ gk_species_projection_init(struct gkyl_gyrokinetic_app *app, struct gk_species * proj->proj_on_basis_c2p_ctx.vel_map = s->vel_map; proj->proj_on_basis_c2p_ctx.pos_map = app->position_map; if (proj->proj_id == GKYL_PROJ_FUNC) { - proj->proj_func = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &s->grid, - .basis = &s->basis, - .qtype = GKYL_GAUSS_QUAD, - .num_quad = app->basis.poly_order+1, - .num_ret_vals = 1, - .eval = inp.func, - .ctx = inp.ctx_func, - .c2p_func = proj_on_basis_c2p_phase_func, - .c2p_func_ctx = &proj->proj_on_basis_c2p_ctx, - } - ); - if (app->use_gpu) + proj->proj_func = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &s->grid, + .basis = &s->basis, + .qtype = GKYL_GAUSS_QUAD, + .num_quad = app->basis.poly_order + 1, + .num_ret_vals = 1, + .eval = inp.func, + .ctx = inp.ctx_func, + .c2p_func = proj_on_basis_c2p_phase_func, + .c2p_func_ctx = &proj->proj_on_basis_c2p_ctx}); + if (app->use_gpu) { proj->proj_host = mkarr(false, s->basis.num_basis, s->local_ext.volume); + } proj->projection_calc = gk_species_projection_calc_proj_func; proj->moms_correct = gk_species_projection_correct_all_moms_none; - } - else { + } else { if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM || proj->proj_id == GKYL_PROJ_BIMAXWELLIAN) { init_maxwellian_bimaxwellian(app, s, inp, proj); proj->projection_calc = proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM ? - gk_species_projection_calc_max_prim : gk_species_projection_calc_bimax; + gk_species_projection_calc_max_prim : + gk_species_projection_calc_bimax; } else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_GAUSSIAN) { init_maxwellian_gaussian(app, s, inp, proj); proj->projection_calc = gk_species_projection_calc_max_gauss; } - proj->moms_correct = proj->correct_all_moms ? - gk_species_projection_correct_all_moms : gk_species_projection_correct_all_moms_none; + proj->moms_correct = proj->correct_all_moms ? gk_species_projection_correct_all_moms : + gk_species_projection_correct_all_moms_none; } } -void -gk_species_projection_calc(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm) +void gk_species_projection_calc( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm +) { proj->projection_calc(app, s, proj, f, tm); - proj->moms_correct(app, s, proj, f, tm); + proj->moms_correct(app, s, proj, f, tm); // Multiply by the configuration space jacobian. - gkyl_dg_mul_conf_phase_op_range(&app->basis, &s->basis, f, - app->gk_geom->geo_int.jacobgeo, f, &app->local, &s->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &s->basis, f, app->gk_geom->geo_int.jacobgeo, f, &app->local, &s->local + ); } -void -gk_species_projection_release(const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj) +void gk_species_projection_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj +) { if (proj->proj_id == GKYL_PROJ_FUNC) { gkyl_proj_on_basis_release(proj->proj_func); if (app->use_gpu) { gkyl_array_release(proj->proj_host); } - } - else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM || proj->proj_id == GKYL_PROJ_BIMAXWELLIAN) { + } else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_PRIM || + proj->proj_id == GKYL_PROJ_BIMAXWELLIAN) { gkyl_array_release(proj->dens); - gkyl_array_release(proj->upar); + gkyl_array_release(proj->upar); gkyl_array_release(proj->prim_moms_host); gkyl_array_release(proj->prim_moms); if (!proj->dens_from_file) { @@ -500,8 +543,7 @@ gk_species_projection_release(const struct gkyl_gyrokinetic_app *app, const stru if (!proj->temp_from_file) { gkyl_proj_on_basis_release(proj->proj_temp); } - } - else if (proj->proj_id == GKYL_PROJ_BIMAXWELLIAN) { + } else if (proj->proj_id == GKYL_PROJ_BIMAXWELLIAN) { gkyl_array_release(proj->vtsqpar); gkyl_array_release(proj->vtsqperp); if (!proj->temppar_from_file) { @@ -513,10 +555,9 @@ gk_species_projection_release(const struct gkyl_gyrokinetic_app *app, const stru } if (proj->correct_all_moms) { - gkyl_gk_maxwellian_correct_release(proj->corr_max); + gkyl_gk_maxwellian_correct_release(proj->corr_max); } - } - else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_GAUSSIAN) { + } else if (proj->proj_id == GKYL_PROJ_MAXWELLIAN_GAUSSIAN) { gkyl_array_release(proj->gaussian_profile); gkyl_array_release(proj->prim_moms); } diff --git a/gyrokinetic/apps/gk_species_radiation.c b/gyrokinetic/apps/gk_species_radiation.c index e4c563d6ac..d65c0c6451 100644 --- a/gyrokinetic/apps/gk_species_radiation.c +++ b/gyrokinetic/apps/gk_species_radiation.c @@ -4,89 +4,102 @@ #include -static void -gks_rad_moms_disabled(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +static void gks_rad_moms_disabled( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { // Do nothing. } -static void -gks_rad_moms_enabled(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +static void gks_rad_moms_enabled( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { - struct timespec wst = gkyl_wall_clock(); + struct timespec wst = gkyl_wall_clock(); // Compute Maxwellian moments (n, u_par, T/m) (without Jacobian). gk_species_moment_calc(&rad->prim_moms, species->local, app->local, species->f); - gkyl_array_set_offset(rad->m0, 1.0, rad->prim_moms.marr, 0*app->basis.num_basis); - gkyl_array_set_offset(rad->vtsq, 1.0, rad->prim_moms.marr, 2*app->basis.num_basis); + gkyl_array_set_offset(rad->m0, 1.0, rad->prim_moms.marr, 0 * app->basis.num_basis); + gkyl_array_set_offset(rad->vtsq, 1.0, rad->prim_moms.marr, 2 * app->basis.num_basis); gkyl_array_clear(rad->nvnu_surf, 0.0); gkyl_array_clear(rad->nvnu, 0.0); gkyl_array_clear(rad->nvsqnu_surf, 0.0); gkyl_array_clear(rad->nvsqnu, 0.0); - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < rad->num_cross_collisions; ++i) { // Compute needed moments. if (rad->is_neut_species[i]) { - gk_neut_species_moment_calc(&rad->moms[i], rad->collide_with_neut[i]->local, - app->local, fin_neut[rad->collide_with_idx[i]]); + gk_neut_species_moment_calc( + &rad->moms[i], rad->collide_with_neut[i]->local, app->local, + fin_neut[rad->collide_with_idx[i]] + ); + } else { + gk_species_moment_calc( + &rad->moms[i], rad->collide_with[i]->local, app->local, fin[rad->collide_with_idx[i]] + ); } - else - gk_species_moment_calc(&rad->moms[i], rad->collide_with[i]->local, app->local, fin[rad->collide_with_idx[i]]); // Divide out Jacobian from ion density before computation of final dragcoefficient. - gkyl_dg_div_op_range(rad->moms[i].mem_geo, &app->basis, 0, rad->moms[i].marr, 0, - rad->moms[i].marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local); - - gkyl_dg_calc_gk_rad_vars_nI_nu_advance(rad->calc_gk_rad_vars, &app->local, &species->local, - &rad->vnu_surf[i], &rad->vnu[i], &rad->vsqnu_surf[i], &rad->vsqnu[i], rad->rad_fit_ne[i], - rad->m0, rad->moms[i].marr, rad->nvnu_surf, rad->nvnu, rad->nvsqnu_surf, rad->nvsqnu, - rad->vtsq_min_per_species[i], rad->vtsq); + gkyl_dg_div_op_range( + rad->moms[i].mem_geo, &app->basis, 0, rad->moms[i].marr, 0, rad->moms[i].marr, 0, + app->gk_geom->geo_int.jacobgeo, &app->local + ); + + gkyl_dg_calc_gk_rad_vars_nI_nu_advance( + rad->calc_gk_rad_vars, &app->local, &species->local, &rad->vnu_surf[i], &rad->vnu[i], + &rad->vsqnu_surf[i], &rad->vsqnu[i], rad->rad_fit_ne[i], rad->m0, rad->moms[i].marr, + rad->nvnu_surf, rad->nvnu, rad->nvsqnu_surf, rad->nvsqnu, rad->vtsq_min_per_species[i], + rad->vtsq + ); } app->stat.species_rad_mom_tm += gkyl_time_diff_now_sec(wst); } -static void -gks_rad_rhs_disabled(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gks_rad_rhs_disabled( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { // Do nothing. } -static void -gks_rad_rhs_enabled(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gks_rad_rhs_enabled( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - + // Accumulate update due to collisions onto rhs. - gkyl_dg_updater_rad_gyrokinetic_advance(rad->drag_slvr, &species->local, - fin, species->cflrate, rhs); - + gkyl_dg_updater_rad_gyrokinetic_advance( + rad->drag_slvr, &species->local, fin, species->cflrate, rhs + ); + app->stat.species_rad_tm += gkyl_time_diff_now_sec(wst); } static void -gks_rad_write_drag_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +gks_rad_write_drag_disabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { // Do nothing. } static void -gks_rad_write_drag_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +gks_rad_write_drag_enabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { struct timespec wst = gkyl_wall_clock(); // Compute radiation drag coefficients const struct gkyl_array *fin_neut[app->num_neut_species]; const struct gkyl_array *fin[app->num_species]; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { fin[i] = app->species[i].f; } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { fin_neut[i] = app->neut_species[i].f; } @@ -100,95 +113,126 @@ gks_rad_write_drag_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, do gkyl_msgpack_map_elem_set_double(rad->io_meta_surfvpar_len, rad->io_meta_surfvpar, "time", tm); gkyl_msgpack_map_elem_set_uint(rad->io_meta_surfvpar_len, rad->io_meta_surfvpar, "frame", frame); struct gkyl_msgpack_map_elem desc_nvnu_surf[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "vpar surface drag coefficient." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "vpar surface drag coefficient."} + }; + int io_meta_surfvpar_len[] = { + gks->io_meta_basic_len, rad->io_meta_surfvpar_len, app->gk_geom->io_meta_basic_len, 1 + }; + const struct gkyl_msgpack_map_elem *io_meta_surfvpar[] = { + gks->io_meta_basic, rad->io_meta_surfvpar, app->gk_geom->io_meta_basic, desc_nvnu_surf }; - int io_meta_surfvpar_len[] = {gks->io_meta_basic_len, rad->io_meta_surfvpar_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta_surfvpar[] = {gks->io_meta_basic, rad->io_meta_surfvpar, app->gk_geom->io_meta_basic, desc_nvnu_surf}; - struct gkyl_msgpack_data *mt_surfvpar = gkyl_msgpack_create_union(sizeof(io_meta_surfvpar_len)/sizeof(int), io_meta_surfvpar_len, io_meta_surfvpar); + struct gkyl_msgpack_data *mt_surfvpar = gkyl_msgpack_create_union( + sizeof(io_meta_surfvpar_len) / sizeof(int), io_meta_surfvpar_len, io_meta_surfvpar + ); gkyl_msgpack_map_elem_set_double(rad->io_meta_surfmu_len, rad->io_meta_surfmu, "time", tm); gkyl_msgpack_map_elem_set_uint(rad->io_meta_surfmu_len, rad->io_meta_surfmu, "frame", frame); struct gkyl_msgpack_map_elem desc_nvsqnu_surf[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "mu surface drag coefficient." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "mu surface drag coefficient."} }; - int io_meta_surfmu_len[] = {gks->io_meta_basic_len, rad->io_meta_surfmu_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta_surfmu[] = {gks->io_meta_basic, rad->io_meta_surfmu, app->gk_geom->io_meta_basic, desc_nvsqnu_surf}; - struct gkyl_msgpack_data *mt_surfmu = gkyl_msgpack_create_union(sizeof(io_meta_surfmu_len)/sizeof(int), io_meta_surfmu_len, io_meta_surfmu); + int io_meta_surfmu_len[] = { + gks->io_meta_basic_len, rad->io_meta_surfmu_len, app->gk_geom->io_meta_basic_len, 1 + }; + const struct gkyl_msgpack_map_elem *io_meta_surfmu[] = { + gks->io_meta_basic, rad->io_meta_surfmu, app->gk_geom->io_meta_basic, desc_nvsqnu_surf + }; + struct gkyl_msgpack_data *mt_surfmu = gkyl_msgpack_create_union( + sizeof(io_meta_surfmu_len) / sizeof(int), io_meta_surfmu_len, io_meta_surfmu + ); gkyl_msgpack_map_elem_set_double(gks->io_meta_phase_len, gks->io_meta_phase, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_phase_len, gks->io_meta_phase, "frame", frame); struct gkyl_msgpack_map_elem desc_nvnu[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "vpar volume drag coefficient." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "vpar volume drag coefficient."} }; int io_meta_nvnu_len[] = {gks->io_meta_phase_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta_nvnu[] = {gks->io_meta_phase, app->gk_geom->io_meta_basic, desc_nvnu}; - struct gkyl_msgpack_data *mt_nvnu = gkyl_msgpack_create_union(sizeof(io_meta_nvnu_len)/sizeof(int), io_meta_nvnu_len, io_meta_nvnu); + const struct gkyl_msgpack_map_elem *io_meta_nvnu[] = { + gks->io_meta_phase, app->gk_geom->io_meta_basic, desc_nvnu + }; + struct gkyl_msgpack_data *mt_nvnu = gkyl_msgpack_create_union( + sizeof(io_meta_nvnu_len) / sizeof(int), io_meta_nvnu_len, io_meta_nvnu + ); struct gkyl_msgpack_map_elem desc_nvsqnu[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "mu volume drag coefficient." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "mu volume drag coefficient."} }; int io_meta_nvsqnu_len[] = {gks->io_meta_phase_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta_nvsqnu[] = {gks->io_meta_phase, app->gk_geom->io_meta_basic, desc_nvsqnu}; - struct gkyl_msgpack_data *mt_nvsqnu = gkyl_msgpack_create_union(sizeof(io_meta_nvsqnu_len)/sizeof(int), io_meta_nvsqnu_len, io_meta_nvsqnu); + const struct gkyl_msgpack_map_elem *io_meta_nvsqnu[] = { + gks->io_meta_phase, app->gk_geom->io_meta_basic, desc_nvsqnu + }; + struct gkyl_msgpack_data *mt_nvsqnu = gkyl_msgpack_create_union( + sizeof(io_meta_nvsqnu_len) / sizeof(int), io_meta_nvsqnu_len, io_meta_nvsqnu + ); // Construct the file handles for vparallel and mu drag const char *fmt_nvnu_surf = "%s-%s_radiation_nvnu_surf_%d.gkyl"; int sz_nvnu_surf = gkyl_calc_strlen(fmt_nvnu_surf, app->name, gks->info.name, frame); - char fileNm_nvnu_surf[sz_nvnu_surf+1]; // ensures no buffer overflow - snprintf(fileNm_nvnu_surf, sizeof fileNm_nvnu_surf, fmt_nvnu_surf, app->name, gks->info.name, frame); + char fileNm_nvnu_surf[sz_nvnu_surf + 1]; // ensures no buffer overflow + snprintf( + fileNm_nvnu_surf, sizeof fileNm_nvnu_surf, fmt_nvnu_surf, app->name, gks->info.name, frame + ); const char *fmt_nvsqnu_surf = "%s-%s_radiation_nvsqnu_surf_%d.gkyl"; int sz_nvsqnu_surf = gkyl_calc_strlen(fmt_nvsqnu_surf, app->name, gks->info.name, frame); - char fileNm_nvsqnu_surf[sz_nvsqnu_surf+1]; // ensures no buffer overflow - snprintf(fileNm_nvsqnu_surf, sizeof fileNm_nvsqnu_surf, fmt_nvsqnu_surf, app->name, gks->info.name, frame); + char fileNm_nvsqnu_surf[sz_nvsqnu_surf + 1]; // ensures no buffer overflow + snprintf( + fileNm_nvsqnu_surf, sizeof fileNm_nvsqnu_surf, fmt_nvsqnu_surf, app->name, gks->info.name, frame + ); const char *fmt_nvnu = "%s-%s_radiation_nvnu_%d.gkyl"; int sz_nvnu = gkyl_calc_strlen(fmt_nvnu, app->name, gks->info.name, frame); - char fileNm_nvnu[sz_nvnu+1]; // ensures no buffer overflow + char fileNm_nvnu[sz_nvnu + 1]; // ensures no buffer overflow snprintf(fileNm_nvnu, sizeof fileNm_nvnu, fmt_nvnu, app->name, gks->info.name, frame); const char *fmt_nvsqnu = "%s-%s_radiation_nvsqnu_%d.gkyl"; int sz_nvsqnu = gkyl_calc_strlen(fmt_nvsqnu, app->name, gks->info.name, frame); - char fileNm_nvsqnu[sz_nvsqnu+1]; // ensures no buffer overflow + char fileNm_nvsqnu[sz_nvsqnu + 1]; // ensures no buffer overflow snprintf(fileNm_nvsqnu, sizeof fileNm_nvsqnu, fmt_nvsqnu, app->name, gks->info.name, frame); // copy data from device to host before writing it out if (app->use_gpu) { - gkyl_array_copy(rad->nvnu_surf_host , rad->nvnu_surf ); + gkyl_array_copy(rad->nvnu_surf_host, rad->nvnu_surf); gkyl_array_copy(rad->nvsqnu_surf_host, rad->nvsqnu_surf); - gkyl_array_copy(rad->nvnu_host , rad->nvnu ); - gkyl_array_copy(rad->nvsqnu_host , rad->nvsqnu ); + gkyl_array_copy(rad->nvnu_host, rad->nvnu); + gkyl_array_copy(rad->nvsqnu_host, rad->nvsqnu); } - gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt_surfvpar, rad->nvnu_surf_host , fileNm_nvnu_surf ); - gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt_surfmu , rad->nvsqnu_surf_host, fileNm_nvsqnu_surf); - gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt_nvnu , rad->nvnu_host , fileNm_nvnu ); - gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt_nvsqnu , rad->nvsqnu_host , fileNm_nvsqnu ); + gkyl_comm_array_write( + gks->comm, &gks->grid, &gks->local, mt_surfvpar, rad->nvnu_surf_host, fileNm_nvnu_surf + ); + gkyl_comm_array_write( + gks->comm, &gks->grid, &gks->local, mt_surfmu, rad->nvsqnu_surf_host, fileNm_nvsqnu_surf + ); + gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt_nvnu, rad->nvnu_host, fileNm_nvnu); + gkyl_comm_array_write( + gks->comm, &gks->grid, &gks->local, mt_nvsqnu, rad->nvsqnu_host, fileNm_nvsqnu + ); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); app->stat.n_diag_io += 4; - gkyl_msgpack_data_release(mt_nvnu ); - gkyl_msgpack_data_release(mt_nvsqnu ); + gkyl_msgpack_data_release(mt_nvnu); + gkyl_msgpack_data_release(mt_nvsqnu); gkyl_msgpack_data_release(mt_surfvpar); - gkyl_msgpack_data_release(mt_surfmu ); + gkyl_msgpack_data_release(mt_surfmu); } -static void -gk_species_radiation_emissivity(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +static void gk_species_radiation_emissivity( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { - // Compute emissivities. - struct timespec wst = gkyl_wall_clock(); + // Compute emissivities. + struct timespec wst = gkyl_wall_clock(); // Compute Maxwellian moments (n, u_par, T/m) (without Jacobian). gk_species_moment_calc(&rad->prim_moms, species->local, app->local, species->f); - gkyl_array_set_offset(rad->m0, 1.0, rad->prim_moms.marr, 0*app->basis.num_basis); - gkyl_array_set_offset(rad->vtsq, 1.0, rad->prim_moms.marr, 2*app->basis.num_basis); + gkyl_array_set_offset(rad->m0, 1.0, rad->prim_moms.marr, 0 * app->basis.num_basis); + gkyl_array_set_offset(rad->vtsq, 1.0, rad->prim_moms.marr, 2 * app->basis.num_basis); // Calculate m2. - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < rad->num_cross_collisions; ++i) { gkyl_array_clear(rad->nvnu_surf, 0.0); gkyl_array_clear(rad->nvnu, 0.0); gkyl_array_clear(rad->nvsqnu_surf, 0.0); @@ -196,59 +240,81 @@ gk_species_radiation_emissivity(gkyl_gyrokinetic_app *app, struct gk_species *sp gkyl_array_clear(rad->emissivity_rhs, 0.0); gkyl_array_clear(rad->emissivity_denominator, 0.0); - if (rad->is_neut_species[i]) - gk_neut_species_moment_calc(&rad->moms[i], rad->collide_with_neut[i]->local, app->local, fin_neut[rad->collide_with_idx[i]]); - else - gk_species_moment_calc(&rad->moms[i], rad->collide_with[i]->local, app->local, fin[rad->collide_with_idx[i]]); + if (rad->is_neut_species[i]) { + gk_neut_species_moment_calc( + &rad->moms[i], rad->collide_with_neut[i]->local, app->local, + fin_neut[rad->collide_with_idx[i]] + ); + } else { + gk_species_moment_calc( + &rad->moms[i], rad->collide_with[i]->local, app->local, fin[rad->collide_with_idx[i]] + ); + } // Divide out Jacobian from ion density before computation of final drag coefficient. - gkyl_dg_div_op_range(rad->moms[i].mem_geo, &app->basis, 0, rad->moms[i].marr, 0, - rad->moms[i].marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local); - - gkyl_dg_calc_gk_rad_vars_nI_nu_advance(rad->calc_gk_rad_vars, &app->local, &species->local, - &rad->vnu_surf[i], &rad->vnu[i], &rad->vsqnu_surf[i], &rad->vsqnu[i], rad->rad_fit_ne[i], - rad->m0, rad->moms[i].marr, rad->nvnu_surf, rad->nvnu, rad->nvsqnu_surf, rad->nvsqnu, - rad->vtsq_min_per_species[i], rad->vtsq); - - gkyl_dg_updater_rad_gyrokinetic_advance(rad->drag_slvr, &species->local, - species->f, species->cflrate, rad->emissivity_rhs); + gkyl_dg_div_op_range( + rad->moms[i].mem_geo, &app->basis, 0, rad->moms[i].marr, 0, rad->moms[i].marr, 0, + app->gk_geom->geo_int.jacobgeo, &app->local + ); + + gkyl_dg_calc_gk_rad_vars_nI_nu_advance( + rad->calc_gk_rad_vars, &app->local, &species->local, &rad->vnu_surf[i], &rad->vnu[i], + &rad->vsqnu_surf[i], &rad->vsqnu[i], rad->rad_fit_ne[i], rad->m0, rad->moms[i].marr, + rad->nvnu_surf, rad->nvnu, rad->nvsqnu_surf, rad->nvsqnu, rad->vtsq_min_per_species[i], + rad->vtsq + ); + + gkyl_dg_updater_rad_gyrokinetic_advance( + rad->drag_slvr, &species->local, species->f, species->cflrate, rad->emissivity_rhs + ); gk_species_moment_calc(&rad->m2, species->local, app->local, rad->emissivity_rhs); gkyl_dg_mul_op(&app->basis, 0, rad->emissivity_denominator, 0, rad->m0, 0, rad->moms[i].marr); - gkyl_dg_mul_op(&app->basis, 0, rad->emissivity_denominator, 0, rad->emissivity_denominator, 0, app->gk_geom->geo_int.jacobgeo); - gkyl_dg_div_op_range(rad->m2.mem_geo ,&app->basis, 0, rad->emissivity[i], 0, rad->m2.marr, 0, rad->emissivity_denominator, &app->local); - - rad->emissivity[i] = gkyl_array_scale(rad->emissivity[i], -species->info.mass/2.0); - } + gkyl_dg_mul_op( + &app->basis, 0, rad->emissivity_denominator, 0, rad->emissivity_denominator, 0, + app->gk_geom->geo_int.jacobgeo + ); + gkyl_dg_div_op_range( + rad->m2.mem_geo, &app->basis, 0, rad->emissivity[i], 0, rad->m2.marr, 0, + rad->emissivity_denominator, &app->local + ); + + rad->emissivity[i] = gkyl_array_scale(rad->emissivity[i], -species->info.mass / 2.0); + } app->stat.species_rad_mom_tm += gkyl_time_diff_now_sec(wst); } -static void -gks_rad_write_emissivity_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +static void gks_rad_write_emissivity_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { // Do nothing. } -static void -gks_rad_write_emissivity_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +static void gks_rad_write_emissivity_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { // Package metadata. gkyl_msgpack_map_elem_set_double(gks->io_meta_conf_len, gks->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_conf_len, gks->io_meta_conf, "frame", frame); struct gkyl_msgpack_map_elem desc_emissivity[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Emissivity density." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Emissivity density."} }; int io_meta_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc_emissivity}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc_emissivity + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); struct timespec wst = gkyl_wall_clock(); const struct gkyl_array *fin_neut[app->num_neut_species]; const struct gkyl_array *fin[app->num_species]; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { fin[i] = app->species[i].f; } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { fin_neut[i] = app->neut_species[i].f; } @@ -257,66 +323,82 @@ gks_rad_write_emissivity_enabled(gkyl_gyrokinetic_app* app, struct gk_species *g int num_charged_species = 0; int num_neut_species = 0; - for (int i=0; irad.num_cross_collisions; i++) { + for (int i = 0; i < gks->rad.num_cross_collisions; i++) { struct timespec wtm = gkyl_wall_clock(); // copy data from device to host before writing it out - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(gks->rad.emissivity_host[i], gks->rad.emissivity[i]); + } // Construct the file handles for vparallel and mu drag - const char *fmt_emissivity = "%s-%s_radiation_emissivity_%s_%d.gkyl"; + const char *fmt_emissivity = "%s-%s_radiation_emissivity_%s_%d.gkyl"; if (gks->rad.is_neut_species[i]) { - int sz_emissivity = gkyl_calc_strlen(fmt_emissivity, app->name, gks->info.name, - app->neut_species[gks->rad.collide_with_idx[i]].info.name, frame); - char fileNm_emissivity[sz_emissivity+1]; // ensures no buffer overflow - snprintf(fileNm_emissivity, sizeof fileNm_emissivity, fmt_emissivity, app->name, - gks->info.name, app->neut_species[gks->rad.collide_with_idx[i]].info.name, frame); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, gks->rad.emissivity_host[i], fileNm_emissivity); + int sz_emissivity = gkyl_calc_strlen( + fmt_emissivity, app->name, gks->info.name, + app->neut_species[gks->rad.collide_with_idx[i]].info.name, frame + ); + char fileNm_emissivity[sz_emissivity + 1]; // ensures no buffer overflow + snprintf( + fileNm_emissivity, sizeof fileNm_emissivity, fmt_emissivity, app->name, gks->info.name, + app->neut_species[gks->rad.collide_with_idx[i]].info.name, frame + ); + + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, gks->rad.emissivity_host[i], fileNm_emissivity + ); app->stat.neut_species_diag_io_tm += gkyl_time_diff_now_sec(wtm); num_neut_species++; - } - else { - int sz_emissivity = gkyl_calc_strlen(fmt_emissivity, app->name, gks->info.name, - app->species[gks->rad.collide_with_idx[i]].info.name, frame); - char fileNm_emissivity[sz_emissivity+1]; // ensures no buffer overflow - snprintf(fileNm_emissivity, sizeof fileNm_emissivity, fmt_emissivity, app->name, - gks->info.name, app->species[gks->rad.collide_with_idx[i]].info.name, frame); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, gks->rad.emissivity_host[i], fileNm_emissivity); + } else { + int sz_emissivity = gkyl_calc_strlen( + fmt_emissivity, app->name, gks->info.name, + app->species[gks->rad.collide_with_idx[i]].info.name, frame + ); + char fileNm_emissivity[sz_emissivity + 1]; // ensures no buffer overflow + snprintf( + fileNm_emissivity, sizeof fileNm_emissivity, fmt_emissivity, app->name, gks->info.name, + app->species[gks->rad.collide_with_idx[i]].info.name, frame + ); + + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, gks->rad.emissivity_host[i], fileNm_emissivity + ); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); num_charged_species++; - } + } app->stat.n_diag_io += 1; } - app->stat.species_diag_calc_tm += (diag_calc_tm * num_charged_species) / gks->rad.num_cross_collisions; - app->stat.neut_species_diag_calc_tm += (diag_calc_tm * num_neut_species) / gks->rad.num_cross_collisions; + app->stat.species_diag_calc_tm += + (diag_calc_tm * num_charged_species) / gks->rad.num_cross_collisions; + app->stat.neut_species_diag_calc_tm += + (diag_calc_tm * num_neut_species) / gks->rad.num_cross_collisions; - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); } -static inline void -gk_species_radiation_integrated_moms(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +static inline void gk_species_radiation_integrated_moms( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { // Compute integrated moments of radiation drag object. gkyl_array_clear(rad->emissivity_rhs, 0.0); - gkyl_dg_updater_rad_gyrokinetic_advance(rad->drag_slvr, &species->local, - species->f, species->cflrate, rad->emissivity_rhs); + gkyl_dg_updater_rad_gyrokinetic_advance( + rad->drag_slvr, &species->local, species->f, species->cflrate, rad->emissivity_rhs + ); gk_species_moment_calc(&rad->integ_moms, species->local, app->local, rad->emissivity_rhs); } static void -gks_rad_calc_integrated_mom_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +gks_rad_calc_integrated_mom_disabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm) { // Do nothing. } static void -gks_rad_calc_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +gks_rad_calc_integrated_mom_enabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm) { - struct timespec wst = gkyl_wall_clock(); + struct timespec wst = gkyl_wall_clock(); int num_mom = gks->rad.integ_moms.num_mom; double avals_global[num_mom]; @@ -324,38 +406,39 @@ gks_rad_calc_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species // Compute radiation drag coefficients const struct gkyl_array *fin_neut[app->num_neut_species]; const struct gkyl_array *fin[app->num_species]; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { fin[i] = app->species[i].f; } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { fin_neut[i] = app->neut_species[i].f; } gk_species_radiation_moms(app, gks, &gks->rad, fin, fin_neut); gk_species_radiation_integrated_moms(app, gks, &gks->rad, fin, fin_neut); - + // reduce to compute sum over whole domain, append to diagnostics gkyl_array_reduce_range(gks->rad.red_integ_diag, gks->rad.integ_moms.marr, GKYL_SUM, &app->local); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, - gks->rad.red_integ_diag, gks->rad.red_integ_diag_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, gks->rad.red_integ_diag, + gks->rad.red_integ_diag_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, gks->rad.red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, gks->rad.red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, gks->rad.red_integ_diag_global, sizeof(double[num_mom])); } gkyl_dynvec_append(gks->rad.integ_diag, tm, avals_global); - - app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); + + app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); } -static void -gks_rad_write_integrated_mom_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks) +static void gks_rad_write_integrated_mom_disabled(gkyl_gyrokinetic_app *app, struct gk_species *gks) { // Do nothing. } -static void -gks_rad_write_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks) +static void gks_rad_write_integrated_mom_enabled(gkyl_gyrokinetic_app *app, struct gk_species *gks) { struct timespec wst = gkyl_wall_clock(); @@ -365,22 +448,26 @@ gks_rad_write_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_specie // write out integrated diagnostic moments const char *fmt = "%s-%s_radiation_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, "integrated_moms"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, "integrated_moms"); if (gks->rad.is_first_integ_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated M0M1M2PARM2PERP of the radiation drag." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Volume integrated M0M1M2PARM2PERP of the radiation drag."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(gks->rad.integ_diag, fileNm, mt); gks->rad.is_first_integ_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(gks->rad.integ_diag, fileNm); } } @@ -389,9 +476,10 @@ gks_rad_write_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_specie app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); app->stat.n_diag_io += 1; } - -void -gk_species_radiation_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_rad_drag *rad) + +void gk_species_radiation_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_rad_drag *rad +) { rad->radiation_id = s->info.radiation.radiation_id; rad->write_diagnostics = s->info.radiation.write_diagnostics; @@ -405,109 +493,127 @@ gk_species_radiation_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s if (s->info.radiation.radiation_id == GKYL_GK_RADIATION) { int cdim = app->cdim, vdim = s->info.vdim; - int pdim = cdim+vdim; + int pdim = cdim + vdim; // Reduced bases and surface bases for radiation variables. - struct gkyl_basis rad_basis, surf_rad_vpar_basis, surf_rad_mu_basis, surf_vpar_basis, surf_mu_basis; + struct gkyl_basis rad_basis, surf_rad_vpar_basis, surf_rad_mu_basis, surf_vpar_basis, + surf_mu_basis; if (app->poly_order > 1) { // radiation variables have no dependence on y since B = B(x,z) if (cdim == 3) { - gkyl_cart_modal_serendip(&rad_basis, pdim-1, app->poly_order); - gkyl_cart_modal_serendip(&surf_rad_vpar_basis, pdim-2, app->poly_order); - gkyl_cart_modal_serendip(&surf_rad_mu_basis, pdim-2, app->poly_order); - } - else { + gkyl_cart_modal_serendip(&rad_basis, pdim - 1, app->poly_order); + gkyl_cart_modal_serendip(&surf_rad_vpar_basis, pdim - 2, app->poly_order); + gkyl_cart_modal_serendip(&surf_rad_mu_basis, pdim - 2, app->poly_order); + } else { gkyl_cart_modal_serendip(&rad_basis, pdim, app->poly_order); - gkyl_cart_modal_serendip(&surf_rad_vpar_basis, pdim-1, app->poly_order); - gkyl_cart_modal_serendip(&surf_rad_mu_basis, pdim-1, app->poly_order); + gkyl_cart_modal_serendip(&surf_rad_vpar_basis, pdim - 1, app->poly_order); + gkyl_cart_modal_serendip(&surf_rad_mu_basis, pdim - 1, app->poly_order); } - gkyl_cart_modal_serendip(&surf_vpar_basis, pdim-1, app->poly_order); - gkyl_cart_modal_serendip(&surf_mu_basis, pdim-1, app->poly_order); - } - else { + gkyl_cart_modal_serendip(&surf_vpar_basis, pdim - 1, app->poly_order); + gkyl_cart_modal_serendip(&surf_mu_basis, pdim - 1, app->poly_order); + } else { // radiation variables have no dependence on y since B = B(x,z) if (cdim == 3) { - gkyl_cart_modal_gkhybrid(&rad_basis, cdim-1, vdim); + gkyl_cart_modal_gkhybrid(&rad_basis, cdim - 1, vdim); // constant vparallel surface, only depends on (x,z,mu) - gkyl_cart_modal_serendip(&surf_rad_vpar_basis, pdim-2, app->poly_order); + gkyl_cart_modal_serendip(&surf_rad_vpar_basis, pdim - 2, app->poly_order); // constant mu surface, only depends on (x,z,vpar), vpar is poly_order = 2 - gkyl_cart_modal_gkhybrid(&surf_rad_mu_basis, cdim-1, 1); - } - else { + gkyl_cart_modal_gkhybrid(&surf_rad_mu_basis, cdim - 1, 1); + } else { gkyl_cart_modal_gkhybrid(&rad_basis, cdim, vdim); - gkyl_cart_modal_serendip(&surf_rad_vpar_basis, pdim-1, app->poly_order); + gkyl_cart_modal_serendip(&surf_rad_vpar_basis, pdim - 1, app->poly_order); gkyl_cart_modal_gkhybrid(&surf_rad_mu_basis, cdim, 1); } - gkyl_cart_modal_serendip(&surf_vpar_basis, pdim-1, app->poly_order); - gkyl_cart_modal_gkhybrid(&surf_mu_basis, cdim, 1); + gkyl_cart_modal_serendip(&surf_vpar_basis, pdim - 1, app->poly_order); + gkyl_cart_modal_gkhybrid(&surf_mu_basis, cdim, 1); } // Metadata for radiation app. struct gkyl_msgpack_map_elem io_meta_surfvpar[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = surf_vpar_basis.poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = surf_vpar_basis.id }, - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0 }, - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = surf_vpar_basis.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = surf_vpar_basis.id}, + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0}, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0} }; - rad->io_meta_surfvpar_len = sizeof(io_meta_surfvpar)/sizeof(io_meta_surfvpar[0]); - rad->io_meta_surfvpar = gkyl_msgpack_map_elem_clone(rad->io_meta_surfvpar_len, io_meta_surfvpar); + rad->io_meta_surfvpar_len = sizeof(io_meta_surfvpar) / sizeof(io_meta_surfvpar[0]); + rad->io_meta_surfvpar = + gkyl_msgpack_map_elem_clone(rad->io_meta_surfvpar_len, io_meta_surfvpar); struct gkyl_msgpack_map_elem io_meta_surfmu[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = surf_mu_basis.poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = surf_mu_basis.id }, - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0 }, - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = surf_mu_basis.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = surf_mu_basis.id}, + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0}, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0} }; - rad->io_meta_surfmu_len = sizeof(io_meta_surfmu)/sizeof(io_meta_surfmu[0]); + rad->io_meta_surfmu_len = sizeof(io_meta_surfmu) / sizeof(io_meta_surfmu[0]); rad->io_meta_surfmu = gkyl_msgpack_map_elem_clone(rad->io_meta_surfmu_len, io_meta_surfmu); // Updater to compute drag coefficients. - rad->calc_gk_rad_vars = gkyl_dg_calc_gk_rad_vars_new(&s->grid, &app->basis, - &s->basis, s->info.charge, s->info.mass, app->gk_geom, s->vel_map, app->use_gpu); + rad->calc_gk_rad_vars = gkyl_dg_calc_gk_rad_vars_new( + &s->grid, &app->basis, &s->basis, s->info.charge, s->info.mass, app->gk_geom, s->vel_map, + app->use_gpu + ); // Fitting parameters - double rad_fit_a[GKYL_MAX_RAD_DENSITIES], rad_fit_alpha[GKYL_MAX_RAD_DENSITIES], rad_fit_beta[GKYL_MAX_RAD_DENSITIES], - rad_fit_gamma[GKYL_MAX_RAD_DENSITIES], rad_fit_v0[GKYL_MAX_RAD_DENSITIES], rad_fit_ne[GKYL_MAX_RAD_DENSITIES]; + double rad_fit_a[GKYL_MAX_RAD_DENSITIES], rad_fit_alpha[GKYL_MAX_RAD_DENSITIES], + rad_fit_beta[GKYL_MAX_RAD_DENSITIES], rad_fit_gamma[GKYL_MAX_RAD_DENSITIES], + rad_fit_v0[GKYL_MAX_RAD_DENSITIES], rad_fit_ne[GKYL_MAX_RAD_DENSITIES]; struct all_radiation_states *rad_data = gkyl_radiation_read_rad_fit_params(); rad->num_cross_collisions = s->info.radiation.num_cross_collisions; int num_dens_per_coll[rad->num_cross_collisions]; - for (int i=0; inum_cross_collisions; ++i) { - num_dens_per_coll[i] = s->info.radiation.num_of_densities[i] ? s->info.radiation.num_of_densities[i] : 1; - int status = gkyl_radiation_read_get_num_densities(*rad_data, s->info.radiation.atomic_Z[i], - s->info.radiation.charge_state[i], s->info.radiation.min_ne, s->info.radiation.max_ne, &num_dens_per_coll[i]); + for (int i = 0; i < rad->num_cross_collisions; ++i) { + num_dens_per_coll[i] = + s->info.radiation.num_of_densities[i] ? s->info.radiation.num_of_densities[i] : 1; + int status = gkyl_radiation_read_get_num_densities( + *rad_data, s->info.radiation.atomic_Z[i], s->info.radiation.charge_state[i], + s->info.radiation.min_ne, s->info.radiation.max_ne, &num_dens_per_coll[i] + ); } // Allocate drag coefificents. - rad->vnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new(rad->num_cross_collisions, num_dens_per_coll, - surf_rad_vpar_basis.num_basis, s->local_ext.volume, app->use_gpu); - rad->vnu = gkyl_dg_calc_gk_rad_vars_drag_new(rad->num_cross_collisions, num_dens_per_coll, - rad_basis.num_basis, s->local_ext.volume, app->use_gpu); - rad->vsqnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new(rad->num_cross_collisions, num_dens_per_coll, - surf_rad_mu_basis.num_basis, s->local_ext.volume, app->use_gpu); - rad->vsqnu = gkyl_dg_calc_gk_rad_vars_drag_new(rad->num_cross_collisions, num_dens_per_coll, - rad_basis.num_basis, s->local_ext.volume, app->use_gpu); + rad->vnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new( + rad->num_cross_collisions, num_dens_per_coll, surf_rad_vpar_basis.num_basis, + s->local_ext.volume, app->use_gpu + ); + rad->vnu = gkyl_dg_calc_gk_rad_vars_drag_new( + rad->num_cross_collisions, num_dens_per_coll, rad_basis.num_basis, s->local_ext.volume, + app->use_gpu + ); + rad->vsqnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new( + rad->num_cross_collisions, num_dens_per_coll, surf_rad_mu_basis.num_basis, + s->local_ext.volume, app->use_gpu + ); + rad->vsqnu = gkyl_dg_calc_gk_rad_vars_drag_new( + rad->num_cross_collisions, num_dens_per_coll, rad_basis.num_basis, s->local_ext.volume, + app->use_gpu + ); int max_num_densities = num_dens_per_coll[0]; - for (int i=1; inum_cross_collisions; i++) { - if (num_dens_per_coll[i] > max_num_densities) + for (int i = 1; i < rad->num_cross_collisions; i++) { + if (num_dens_per_coll[i] > max_num_densities) { max_num_densities = num_dens_per_coll[i]; + } } - + // Make array for cutoff below which radiation is set to 0. Keep the radiation from driving Te negative. - rad->vtsq_min_per_species = gkyl_malloc(rad->num_cross_collisions*sizeof(struct gkyl_array*)); - + rad->vtsq_min_per_species = + gkyl_malloc(rad->num_cross_collisions * sizeof(struct gkyl_array *)); + // Initialize drag coefficients. - for (int i=0; inum_cross_collisions; ++i) { - int num_densities = s->info.radiation.num_of_densities[i] ? s->info.radiation.num_of_densities[i] : 1; - int status = gkyl_radiation_read_get_fit_params(*rad_data, s->info.radiation.atomic_Z[i], s->info.radiation.charge_state[i], - rad_fit_a, rad_fit_alpha, rad_fit_beta, rad_fit_gamma, rad_fit_v0, &num_densities, rad_fit_ne, - s->info.radiation.reference_ne, s->info.radiation.min_ne, s->info.radiation.max_ne); + for (int i = 0; i < rad->num_cross_collisions; ++i) { + int num_densities = + s->info.radiation.num_of_densities[i] ? s->info.radiation.num_of_densities[i] : 1; + int status = gkyl_radiation_read_get_fit_params( + *rad_data, s->info.radiation.atomic_Z[i], s->info.radiation.charge_state[i], rad_fit_a, + rad_fit_alpha, rad_fit_beta, rad_fit_gamma, rad_fit_v0, &num_densities, rad_fit_ne, + s->info.radiation.reference_ne, s->info.radiation.min_ne, s->info.radiation.max_ne + ); assert(num_densities == num_dens_per_coll[i]); // Consistency check. rad->vtsq_min_per_species[i] = mkarr(app->use_gpu, 1, num_densities); rad->rad_fit_ne[i] = mkarr(app->use_gpu, 1, num_densities); struct gkyl_array *rad_fit_ne_host = mkarr(false, 1, num_densities); struct gkyl_array *vtsq_min_host = mkarr(false, 1, num_densities); - memcpy(rad_fit_ne_host->data, rad_fit_ne, num_densities*sizeof(double)); + memcpy(rad_fit_ne_host->data, rad_fit_ne, num_densities * sizeof(double)); gkyl_array_copy(rad->rad_fit_ne[i], rad_fit_ne_host); gkyl_array_release(rad_fit_ne_host); @@ -517,9 +623,10 @@ gk_species_radiation_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s rad->collide_with_idx[i] = gk_find_neut_species_idx(app, s->info.radiation.collide_with[i]); rad->collide_with_neut[i] = gk_find_neut_species(app, s->info.radiation.collide_with[i]); rad->is_neut_species[i] = true; - gk_neut_species_moment_init(app, rad->collide_with_neut[i], &rad->moms[i], GKYL_F_MOMENT_M0, false); - } - else { + gk_neut_species_moment_init( + app, rad->collide_with_neut[i], &rad->moms[i], GKYL_F_MOMENT_M0, false + ); + } else { rad->collide_with[i] = gk_find_species(app, s->info.radiation.collide_with[i]); rad->is_neut_species[i] = false; // allocate density calculation needed for radiation update @@ -528,91 +635,100 @@ gk_species_radiation_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s if (status == 1) { char msg[100]; - sprintf(msg, "No radiation fits exist for z=%d, charge state=%d\n",s->info.radiation.atomic_Z[i], s->info.radiation.charge_state[i]); + sprintf( + msg, "No radiation fits exist for z=%d, charge state=%d\n", s->info.radiation.atomic_Z[i], + s->info.radiation.charge_state[i] + ); gkyl_gyrokinetic_app_cout(app, stderr, msg); exit(EXIT_FAILURE); } - for (int n=0; ncalc_gk_rad_vars, &app->local, &s->local, - rad_fit_a[n], rad_fit_alpha[n], rad_fit_beta[n], rad_fit_gamma[n], rad_fit_v0[n], - rad->vnu_surf[i].data[n].arr, rad->vnu[i].data[n].arr, - rad->vsqnu_surf[i].data[n].arr, rad->vsqnu[i].data[n].arr); + gkyl_dg_calc_gk_rad_vars_nu_advance( + rad->calc_gk_rad_vars, &app->local, &s->local, rad_fit_a[n], rad_fit_alpha[n], + rad_fit_beta[n], rad_fit_gamma[n], rad_fit_v0[n], rad->vnu_surf[i].data[n].arr, + rad->vnu[i].data[n].arr, rad->vsqnu_surf[i].data[n].arr, rad->vsqnu[i].data[n].arr + ); double Te_min_eV; if (s->info.radiation.te_min_model == GKYL_CONST_TE && s->info.radiation.Te_min) { // Turn off radiation below a constant temperature Te_min_eV = s->info.radiation.Te_min / GKYL_ELEMENTARY_CHARGE; - } - else if (s->info.radiation.te_min_model == GKYL_VARY_TE_AGGRESSIVE) { + } else if (s->info.radiation.te_min_model == GKYL_VARY_TE_AGGRESSIVE) { // Turn off radiation below 10^-4*max(Lz) Te_min_eV = 0.1372 * pow(rad_fit_v0[n], 1.867); - } - else { + } else { // (s->info.radiation.te_min_model == GKYL_VARY_TE_CONSERVATIVE) i.e. Turn off radiation below 3.16*10^-3*max(Lz) Te_min_eV = 0.2815 * pow(rad_fit_v0[n], 1.768); } - double *vtsq_min_host_d = (double*) gkyl_array_fetch(vtsq_min_host, n); - vtsq_min_host_d[0] = Te_min_eV * fabs(s->info.charge)/s->info.mass * pow(sqrt(2.0), cdim); + double *vtsq_min_host_d = (double *)gkyl_array_fetch(vtsq_min_host, n); + vtsq_min_host_d[0] = Te_min_eV * fabs(s->info.charge) / s->info.mass * pow(sqrt(2.0), cdim); } gkyl_array_copy(rad->vtsq_min_per_species[i], vtsq_min_host); gkyl_array_release(vtsq_min_host); // Allocate emissivity. rad->emissivity[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - rad->emissivity_host[i] = app->use_gpu? mkarr(false, rad->emissivity[i]->ncomp, rad->emissivity[i]->size) - : gkyl_array_acquire(rad->emissivity[i]); + rad->emissivity_host[i] = + app->use_gpu ? mkarr(false, rad->emissivity[i]->ncomp, rad->emissivity[i]->size) : + gkyl_array_acquire(rad->emissivity[i]); } gkyl_radiation_read_release_fit_params(rad_data); // Total vparallel and mu radiation drag including density scaling - rad->nvnu_surf = mkarr(app->use_gpu, surf_vpar_basis.num_basis, s->local_ext.volume); - rad->nvnu = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); + rad->nvnu_surf = mkarr(app->use_gpu, surf_vpar_basis.num_basis, s->local_ext.volume); + rad->nvnu = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); rad->nvsqnu_surf = mkarr(app->use_gpu, surf_mu_basis.num_basis, s->local_ext.volume); - rad->nvsqnu = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); + rad->nvsqnu = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); // Allocate moments needed for temperature update. gk_species_moment_init(app, s, &rad->prim_moms, GKYL_F_MOMENT_MAXWELLIAN, false); rad->vtsq = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); rad->m0 = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - + // Radiation updater. - struct gkyl_dg_rad_gyrokinetic_auxfields drag_inp = { .nvnu_surf = rad->nvnu_surf, - .nvnu = rad->nvnu, .nvsqnu_surf = rad->nvsqnu_surf, .nvsqnu = rad->nvsqnu}; - rad->drag_slvr = gkyl_dg_updater_rad_gyrokinetic_new(&s->grid, - &app->basis, &s->basis, &s->local, &app->local, s->vel_map, &drag_inp, app->use_gpu); + struct gkyl_dg_rad_gyrokinetic_auxfields drag_inp = { + .nvnu_surf = rad->nvnu_surf, + .nvnu = rad->nvnu, + .nvsqnu_surf = rad->nvsqnu_surf, + .nvsqnu = rad->nvsqnu + }; + rad->drag_slvr = gkyl_dg_updater_rad_gyrokinetic_new( + &s->grid, &app->basis, &s->basis, &s->local, &app->local, s->vel_map, &drag_inp, app->use_gpu + ); if (rad->write_diagnostics) { // Drag coefficients diagnotic. if (app->use_gpu) { - rad->nvnu_surf_host = mkarr(false, rad->nvnu_surf ->ncomp, rad->nvnu_surf ->size); - rad->nvnu_host = mkarr(false, rad->nvnu ->ncomp, rad->nvnu ->size); - rad->nvsqnu_surf_host = mkarr(false, rad->nvsqnu_surf->ncomp, rad->nvsqnu_surf->size); - rad->nvsqnu_host = mkarr(false, rad->nvsqnu ->ncomp, rad->nvsqnu ->size); - } - else { - rad->nvnu_surf_host = gkyl_array_acquire(rad->nvnu_surf); - rad->nvnu_host = gkyl_array_acquire(rad->nvnu); + rad->nvnu_surf_host = mkarr(false, rad->nvnu_surf->ncomp, rad->nvnu_surf->size); + rad->nvnu_host = mkarr(false, rad->nvnu->ncomp, rad->nvnu->size); + rad->nvsqnu_surf_host = mkarr(false, rad->nvsqnu_surf->ncomp, rad->nvsqnu_surf->size); + rad->nvsqnu_host = mkarr(false, rad->nvsqnu->ncomp, rad->nvsqnu->size); + } else { + rad->nvnu_surf_host = gkyl_array_acquire(rad->nvnu_surf); + rad->nvnu_host = gkyl_array_acquire(rad->nvnu); rad->nvsqnu_surf_host = gkyl_array_acquire(rad->nvsqnu_surf); - rad->nvsqnu_host = gkyl_array_acquire(rad->nvsqnu); + rad->nvsqnu_host = gkyl_array_acquire(rad->nvsqnu); } // Emissivity diagnostic. rad->emissivity_rhs = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); - rad->emissivity_denominator = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); + rad->emissivity_denominator = + mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); gk_species_moment_init(app, s, &rad->m2, GKYL_F_MOMENT_M2, false); - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < rad->num_cross_collisions; ++i) { // Allocate emissivity. rad->emissivity[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - rad->emissivity_host[i] = app->use_gpu? mkarr(false, rad->emissivity[i]->ncomp, rad->emissivity[i]->size) - : gkyl_array_acquire(rad->emissivity[i]); + rad->emissivity_host[i] = + app->use_gpu ? mkarr(false, rad->emissivity[i]->ncomp, rad->emissivity[i]->size) : + gkyl_array_acquire(rad->emissivity[i]); } // Allocate data and updaters for integrated moments. @@ -621,8 +737,7 @@ gk_species_radiation_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s if (app->use_gpu) { rad->red_integ_diag = gkyl_cu_malloc(sizeof(double[num_mom])); rad->red_integ_diag_global = gkyl_cu_malloc(sizeof(double[num_mom])); - } - else { + } else { rad->red_integ_diag = gkyl_malloc(sizeof(double[num_mom])); rad->red_integ_diag_global = gkyl_malloc(sizeof(double[num_mom])); } @@ -644,55 +759,61 @@ gk_species_radiation_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s } } -void -gk_species_radiation_moms(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +void gk_species_radiation_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { rad->moms_func(app, species, rad, fin, fin_neut); } -void -gk_species_radiation_rhs(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_species_radiation_rhs( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { rad->rhs_func(app, species, rad, fin, rhs); } -void -gk_species_radiation_write_drag(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_radiation_write_drag( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { gks->rad.write_drag_func(app, gks, tm, frame); } -void -gk_species_radiation_write_emissivity(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_radiation_write_emissivity( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { gks->rad.write_emissivity_func(app, gks, tm, frame); } -void -gk_species_radiation_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +void gk_species_radiation_calc_integrated_mom( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm +) { gks->rad.calc_integrated_mom_func(app, gks, tm); } -void -gk_species_radiation_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks) +void gk_species_radiation_write_integrated_mom(gkyl_gyrokinetic_app *app, struct gk_species *gks) { gks->rad.write_integrated_mom_func(app, gks); } -void -gk_species_radiation_release(const struct gkyl_gyrokinetic_app *app, const struct gk_rad_drag *rad) +void gk_species_radiation_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_rad_drag *rad +) { if (rad->radiation_id == GKYL_GK_RADIATION) { - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < rad->num_cross_collisions; ++i) { gkyl_array_release(rad->rad_fit_ne[i]); gkyl_array_release(rad->vtsq_min_per_species[i]); - if (rad->is_neut_species[i]) + if (rad->is_neut_species[i]) { gk_neut_species_moment_release(app, &rad->moms[i]); - else + } else { gk_species_moment_release(app, &rad->moms[i]); + } } gkyl_dg_calc_gk_rad_vars_release(rad->calc_gk_rad_vars); @@ -719,21 +840,20 @@ gk_species_radiation_release(const struct gkyl_gyrokinetic_app *app, const struc gkyl_array_release(rad->nvnu_surf_host); gkyl_array_release(rad->nvnu_host); gkyl_array_release(rad->nvsqnu_surf_host); - gkyl_array_release(rad->nvsqnu_host); + gkyl_array_release(rad->nvsqnu_host); gkyl_array_release(rad->emissivity_denominator); gkyl_array_release(rad->emissivity_rhs); gk_species_moment_release(app, &rad->m2); - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < rad->num_cross_collisions; ++i) { gkyl_array_release(rad->emissivity[i]); gkyl_array_release(rad->emissivity_host[i]); } - gk_species_moment_release(app, &rad->integ_moms); + gk_species_moment_release(app, &rad->integ_moms); if (app->use_gpu) { gkyl_cu_free(rad->red_integ_diag); gkyl_cu_free(rad->red_integ_diag_global); - } - else { + } else { gkyl_free(rad->red_integ_diag); gkyl_free(rad->red_integ_diag_global); } diff --git a/gyrokinetic/apps/gk_species_react.c b/gyrokinetic/apps/gk_species_react.c index c1cf5f831e..27297f9e51 100644 --- a/gyrokinetic/apps/gk_species_react.c +++ b/gyrokinetic/apps/gk_species_react.c @@ -1,162 +1,186 @@ #include #include -static void -gks_react_cross_moms_disabled(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_react *react, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +static void gks_react_cross_moms_disabled( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_react *react, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { // Do nothing. } -static void -gks_react_cross_moms_enabled(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_react *react, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +static void gks_react_cross_moms_enabled( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_react *react, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { - struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_react; ++i) { - struct gk_species *gks_elc = &app->species[react->elc_idx[i]]; - struct gk_species *gks_ion = &app->species[react->ion_idx[i]]; + struct timespec wst = gkyl_wall_clock(); + for (int i = 0; i < react->num_react; ++i) { + struct gk_species *gks_elc = &app->species[react->elc_idx[i]]; + struct gk_species *gks_ion = &app->species[react->ion_idx[i]]; if (react->react_id[i] == GKYL_REACT_IZ) { // Compute needed electron Maxwellian moments (J*n, u_par, T/m). - gk_species_moment_calc(&gks_elc->lte.moms, - gks_elc->local, app->local, fin[react->elc_idx[i]]); + gk_species_moment_calc(&gks_elc->lte.moms, gks_elc->local, app->local, fin[react->elc_idx[i]]); // Copy J*n for use in final update gkyl_array_set_range(react->Jm0_elc[i], 1.0, gks_elc->lte.moms.marr, &app->local); // Divide the electron density by the Jacobian for reaction rates. - gkyl_dg_div_op_range(gks_elc->lte.moms.mem_geo, &app->basis, - 0, gks_elc->lte.moms.marr, 0, gks_elc->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gks_elc->lte.moms.mem_geo, &app->basis, 0, gks_elc->lte.moms.marr, 0, + gks_elc->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); if (react->all_gk) { struct gk_species *gks_donor = &app->species[react->donor_idx[i]]; - gk_species_moment_calc(&gks_donor->lte.moms, - gks_donor->local, app->local, fin[react->donor_idx[i]]); + gk_species_moment_calc( + &gks_donor->lte.moms, gks_donor->local, app->local, fin[react->donor_idx[i]] + ); // Copy J*n for use in final update gkyl_array_set_range(react->Jm0_donor[i], 1.0, gks_donor->lte.moms.marr, &app->local); // Divide the donor density by the Jacobian for Maxwellian projection. - gkyl_dg_div_op_range(gks_donor->lte.moms.mem_geo, &app->basis, - 0, gks_donor->lte.moms.marr, 0, gks_donor->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gks_donor->lte.moms.mem_geo, &app->basis, 0, gks_donor->lte.moms.marr, 0, + gks_donor->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); // If all interacting species are GK, u_i . b_i is simply upar of the donor species - gkyl_array_set_offset(react->u_i_dot_b_i[i], 1.0, gks_donor->lte.moms.marr, 1*app->basis.num_basis); - } - else { + gkyl_array_set_offset( + react->u_i_dot_b_i[i], 1.0, gks_donor->lte.moms.marr, 1 * app->basis.num_basis + ); + } else { struct gk_neut_species *gkns_donor = &app->neut_species[react->donor_idx[i]]; - gk_neut_species_moment_calc(&gkns_donor->lte.moms, - gkns_donor->local, app->local, fin_neut[react->donor_idx[i]]); + gk_neut_species_moment_calc( + &gkns_donor->lte.moms, gkns_donor->local, app->local, fin_neut[react->donor_idx[i]] + ); // Copy J*n for use in final update gkyl_array_set_range(react->Jm0_donor[i], 1.0, gkns_donor->lte.moms.marr, &app->local); // Divide the donor density by the Jacobian for Maxwellian projection. - gkyl_dg_div_op_range(gkns_donor->lte.moms.mem_geo, &app->basis, - 0, gkns_donor->lte.moms.marr, 0, gkns_donor->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gkns_donor->lte.moms.mem_geo, &app->basis, 0, gkns_donor->lte.moms.marr, 0, + gkns_donor->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); // Select component parallel to b. // If cdim = 1, uidx = 1, if cdim = 2, udix = 2, if cdim = 3, udix = 3. - gkyl_array_set_offset(react->u_i_dot_b_i[i], 1.0, gkns_donor->lte.moms.marr, app->cdim*app->basis.num_basis); + gkyl_array_set_offset( + react->u_i_dot_b_i[i], 1.0, gkns_donor->lte.moms.marr, app->cdim * app->basis.num_basis + ); - gkyl_array_set_offset(react->vt_sq_donor[i], 1.0, gkns_donor->lte.moms.marr, 4*app->basis.num_basis); + gkyl_array_set_offset( + react->vt_sq_donor[i], 1.0, gkns_donor->lte.moms.marr, 4 * app->basis.num_basis + ); } // Compute ionization reaction rate from electron primitive moments. - gkyl_dg_iz_coll(react->iz[i], gks_elc->lte.moms.marr, - react->vt_sq_iz1[i], react->vt_sq_iz2[i], react->coeff_react[i], 0); - } - else if (react->react_id[i] == GKYL_REACT_RECOMB) { + gkyl_dg_iz_coll( + react->iz[i], gks_elc->lte.moms.marr, react->vt_sq_iz1[i], react->vt_sq_iz2[i], + react->coeff_react[i], 0 + ); + } else if (react->react_id[i] == GKYL_REACT_RECOMB) { // Compute needed electron Maxwellian moments (J*n, u_par, T/m). - gk_species_moment_calc(&gks_elc->lte.moms, - gks_elc->local, app->local, fin[react->elc_idx[i]]); + gk_species_moment_calc(&gks_elc->lte.moms, gks_elc->local, app->local, fin[react->elc_idx[i]]); // Copy J*n for use in final update gkyl_array_set_range(react->Jm0_elc[i], 1.0, gks_elc->lte.moms.marr, &app->local); // Divide the electron density by the Jacobian for reaction rates. - gkyl_dg_div_op_range(gks_elc->lte.moms.mem_geo, &app->basis, - 0, gks_elc->lte.moms.marr, 0, gks_elc->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gks_elc->lte.moms.mem_geo, &app->basis, 0, gks_elc->lte.moms.marr, 0, + gks_elc->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); // Compute needed ion Maxwellian moments (J*n, u_par, T/m). - gk_species_moment_calc(&gks_ion->lte.moms, - gks_ion->local, app->local, fin[react->ion_idx[i]]); + gk_species_moment_calc(&gks_ion->lte.moms, gks_ion->local, app->local, fin[react->ion_idx[i]]); // Copy J*n for use in final update gkyl_array_set_range(react->Jm0_ion[i], 1.0, gks_ion->lte.moms.marr, &app->local); // Divide the ion density by the Jacobian for Maxwellian projection. - gkyl_dg_div_op_range(gks_ion->lte.moms.mem_geo, &app->basis, - 0, gks_ion->lte.moms.marr, 0, gks_ion->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); - + gkyl_dg_div_op_range( + gks_ion->lte.moms.mem_geo, &app->basis, 0, gks_ion->lte.moms.marr, 0, + gks_ion->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); + // Compute recombination reaction rate. - gkyl_dg_recomb_coll(react->recomb[i], gks_elc->lte.moms.marr, - react->coeff_react[i], 0); - } - else if (react->react_id[i] == GKYL_REACT_CX) { + gkyl_dg_recomb_coll(react->recomb[i], gks_elc->lte.moms.marr, react->coeff_react[i], 0); + } else if (react->react_id[i] == GKYL_REACT_CX) { // Compute needed ion Maxwellian moments (J*n, u_par, T/m). - gk_species_moment_calc(&gks_ion->lte.moms, - gks_ion->local, app->local, fin[react->ion_idx[i]]); + gk_species_moment_calc(&gks_ion->lte.moms, gks_ion->local, app->local, fin[react->ion_idx[i]]); // Copy J*n for use in final update gkyl_array_set_range(react->Jm0_ion[i], 1.0, gks_ion->lte.moms.marr, &app->local); // Divide the ion density by the Jacobian. - gkyl_dg_div_op_range(gks_ion->lte.moms.mem_geo, &app->basis, - 0, gks_ion->lte.moms.marr, 0, gks_ion->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gks_ion->lte.moms.mem_geo, &app->basis, 0, gks_ion->lte.moms.marr, 0, + gks_ion->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); // Construct ion vector velocity upar b_i with same order as can pb. // if cdim = 1, u0 = upar, if cdim = 2, u1 = upar, if cdim = 3, u2 = upar gkyl_array_clear(react->upar_ion[i], 0.0); - gkyl_array_set_offset(react->u_i_dot_b_i[i], 1.0, gks_ion->lte.moms.marr, 1*app->basis.num_basis); - gkyl_array_set_offset(react->upar_ion[i], 1.0, react->u_i_dot_b_i[i], (app->cdim-1)*app->basis.num_basis); + gkyl_array_set_offset( + react->u_i_dot_b_i[i], 1.0, gks_ion->lte.moms.marr, 1 * app->basis.num_basis + ); + gkyl_array_set_offset( + react->upar_ion[i], 1.0, react->u_i_dot_b_i[i], (app->cdim - 1) * app->basis.num_basis + ); gkyl_array_clear(react->u_i_dot_b_i[i], 0.0); // Compute needed partner (neutral) Maxwellian moments (J*n, ux, uy, uz, T/m) . struct gk_neut_species *gkns_partner = &app->neut_species[react->partner_idx[i]]; - gk_neut_species_moment_calc(&gkns_partner->lte.moms, - gkns_partner->local, app->local, fin_neut[react->partner_idx[i]]); + gk_neut_species_moment_calc( + &gkns_partner->lte.moms, gkns_partner->local, app->local, fin_neut[react->partner_idx[i]] + ); // Divide the partner density by the Jacobian. - gkyl_dg_div_op_range(gkns_partner->lte.moms.mem_geo, &app->basis, - 0, gkns_partner->lte.moms.marr, 0, gkns_partner->lte.moms.marr, 0, - app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gkns_partner->lte.moms.mem_geo, &app->basis, 0, gkns_partner->lte.moms.marr, 0, + gkns_partner->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local + ); // Copy ux, uy, uz for computing dot product u_i . b_i (Cartesian components of b_i). // If cdim = 1, uidx = 1, if cdim = 2, udix = 2, if cdim = 3, udix = 3 - gkyl_array_set_offset(react->u_i_dot_b_i[i], 1.0, gkns_partner->lte.moms.marr, app->cdim*app->basis.num_basis); + gkyl_array_set_offset( + react->u_i_dot_b_i[i], 1.0, gkns_partner->lte.moms.marr, app->cdim * app->basis.num_basis + ); // Copy vt^2 = T/m of the neutrals (partner of the ions). - gkyl_array_set_offset(react->vt_sq_partner[i], 1.0, gkns_partner->lte.moms.marr, 4*app->basis.num_basis); + gkyl_array_set_offset( + react->vt_sq_partner[i], 1.0, gkns_partner->lte.moms.marr, 4 * app->basis.num_basis + ); // Calculate CX reaction rate. - gkyl_dg_cx_coll(react->cx[i], gks_ion->lte.moms.marr, gkns_partner->lte.moms.marr, - react->upar_ion[i], react->coeff_react[i], 0); + gkyl_dg_cx_coll( + react->cx[i], gks_ion->lte.moms.marr, gkns_partner->lte.moms.marr, react->upar_ion[i], + react->coeff_react[i], 0 + ); } } app->stat.species_react_mom_tm += gkyl_time_diff_now_sec(wst); } -static void -gks_react_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_react *react, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gks_react_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_react *react, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { // Do nothing. } -void -gks_react_rhs_enabled(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_react *react, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gks_react_rhs_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_react *react, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_react; ++i) { + for (int i = 0; i < react->num_react; ++i) { gkyl_array_clear(react->f_react, 0.0); gkyl_array_clear(react->react_lte_moms[i], 0.0); @@ -169,138 +193,178 @@ gks_react_rhs_enabled(gkyl_gyrokinetic_app *app, struct gk_species *s, // (fmax1(n_elc, upar_elc, vtiz1^2) + fmax2(n_elc, upar_donor, vtiz2^2) - f_elc) // primary electron; first copy all components (n_elc, upar_elc, Telc/m) - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, gks_elc->lte.moms.marr, 0*app->basis.num_basis); + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, gks_elc->lte.moms.marr, 0 * app->basis.num_basis + ); // overwrite thermal velocity to be first ionization energy vtiz1^2 - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, react->vt_sq_iz1[i], 2*app->basis.num_basis); + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, react->vt_sq_iz1[i], 2 * app->basis.num_basis + ); gk_species_lte_from_moms(app, gks_elc, &gks_elc->lte, react->react_lte_moms[i]); // Accumulate J*n_donor*fmax1(n_elc, upar_elc, vtiz1^2) onto f_react - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - 1.0, react->Jm0_donor[i], gks_elc->lte.f_lte, &app->local, &s->local); + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, 1.0, react->Jm0_donor[i], gks_elc->lte.f_lte, + &app->local, &s->local + ); - // secondary electron + // secondary electron // density unchanged but now we use the donor parallel velocity and second ionization energy vtiz2^2 - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, react->u_i_dot_b_i[i], 1*app->basis.num_basis); - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, react->vt_sq_iz2[i], 2*app->basis.num_basis); + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, react->u_i_dot_b_i[i], 1 * app->basis.num_basis + ); + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, react->vt_sq_iz2[i], 2 * app->basis.num_basis + ); gk_species_lte_from_moms(app, gks_elc, &gks_elc->lte, react->react_lte_moms[i]); // Accumulate J*n_donor*fmax2(n_elc, upar_donor, vtiz2^2) onto f_react - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - 1.0, react->Jm0_donor[i], gks_elc->lte.f_lte, &app->local, &s->local); + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, 1.0, react->Jm0_donor[i], gks_elc->lte.f_lte, + &app->local, &s->local + ); // Accumulate -n_donor*(J*f_elc) (*note* Jacobian factor already included in fin) if (react->all_gk) { struct gk_species *gks_donor = &app->species[react->donor_idx[i]]; - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - -1.0, gks_donor->lte.moms.marr, fin, &app->local, &s->local); - } - else { + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, -1.0, gks_donor->lte.moms.marr, fin, + &app->local, &s->local + ); + } else { struct gk_neut_species *gkns_donor = &app->neut_species[react->donor_idx[i]]; - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - -1.0, gkns_donor->lte.moms.marr, fin, &app->local, &s->local); - } - } - else if (react->type_self[i] == GKYL_SELF_ION) { + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, -1.0, gkns_donor->lte.moms.marr, fin, + &app->local, &s->local + ); + } + } else if (react->type_self[i] == GKYL_SELF_ION) { // ion update is n_elc*coeff_react*fmax(n_donor, upar_donor, vt_donor^2) if (react->all_gk) { struct gk_species *gks_donor = &app->species[react->donor_idx[i]]; - // Copy components of donor plasma into reaction moments - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, gks_donor->lte.moms.marr, 0*app->basis.num_basis); - } - else { + // Copy components of donor plasma into reaction moments + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, gks_donor->lte.moms.marr, 0 * app->basis.num_basis + ); + } else { struct gk_neut_species *gkns_donor = &app->neut_species[react->donor_idx[i]]; - // Copy components of donor neutrals into reaction moments - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, gkns_donor->lte.moms.marr, 0*app->basis.num_basis); + // Copy components of donor neutrals into reaction moments + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, gkns_donor->lte.moms.marr, 0 * app->basis.num_basis + ); // Overwrite parallel velocity and vt^2 to be u_i . b_i and vt^2 of the neutrals - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, react->u_i_dot_b_i[i], 1*app->basis.num_basis); - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, react->vt_sq_donor[i], 2*app->basis.num_basis); - } + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, react->u_i_dot_b_i[i], 1 * app->basis.num_basis + ); + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, react->vt_sq_donor[i], 2 * app->basis.num_basis + ); + } gk_species_lte_from_moms(app, gks_ion, &gks_ion->lte, react->react_lte_moms[i]); // Accumulate J*n_elc*fmax(n_donor, upar_donor, vt_donor^2) onto f_react - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - 1.0, react->Jm0_elc[i], gks_ion->lte.f_lte, &app->local, &s->local); - } - else { + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, 1.0, react->Jm0_elc[i], gks_ion->lte.f_lte, + &app->local, &s->local + ); + } else { // donor update is -n_elc*coeff_react*f_donor // Accumulate -n_elc*(J*f_donor) (*note* Jacobian factor already included in fin) - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - -1.0, gks_elc->lte.moms.marr, fin, &app->local, &s->local); + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, -1.0, gks_elc->lte.moms.marr, fin, &app->local, + &s->local + ); } - } - else if (react->react_id[i] == GKYL_REACT_RECOMB) { + } else if (react->react_id[i] == GKYL_REACT_RECOMB) { if (react->type_self[i] == GKYL_SELF_ELC) { // electron update is -n_ion*coeff_react*f_elc // Accumulate -n_ion*(J*f_elc) (*note* Jacobian factor already included in fin) - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - -1.0, gks_ion->lte.moms.marr, fin, &app->local, &s->local); - } - else if (react->type_self[i] == GKYL_SELF_ION) { + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, -1.0, gks_ion->lte.moms.marr, fin, &app->local, + &s->local + ); + } else if (react->type_self[i] == GKYL_SELF_ION) { // ion update is -n_elc*coeff_react*f_ion // Accumulate -n_elc*(J*f_ion) (*note* Jacobian factor already included in fin) - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - -1.0, gks_elc->lte.moms.marr, fin, &app->local, &s->local); - } - else { + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, -1.0, gks_elc->lte.moms.marr, fin, &app->local, + &s->local + ); + } else { // receiver update is n_elc*coeff_react*fmax(n_ion, upar_ion, vt_ion^2) gk_species_lte_from_moms(app, s, &s->lte, gks_ion->lte.moms.marr); // Accumulate J*n_elc*fmax(n_ion, upar_ion, vt_ion^2) onto f_react - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - 1.0, react->Jm0_elc[i], s->lte.f_lte, &app->local, &s->local); + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, 1.0, react->Jm0_elc[i], s->lte.f_lte, &app->local, + &s->local + ); } - } - else if (react->react_id[i] == GKYL_REACT_CX) { + } else if (react->react_id[i] == GKYL_REACT_CX) { // ion update is coeff_react*(n_ion*fmax(n_partner, upar_partner, vt_partner^2) - n_partner*f_ion) struct gk_neut_species *gkns_partner = &app->neut_species[react->donor_idx[i]]; - // Copy components of partner neutrals into reaction moments - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, gkns_partner->lte.moms.marr, 0*app->basis.num_basis); + // Copy components of partner neutrals into reaction moments + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, gkns_partner->lte.moms.marr, 0 * app->basis.num_basis + ); // Overwrite parallel velocity and vt^2 to be u_i . b_i and vt^2 of the neutrals - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, react->u_i_dot_b_i[i], 1*app->basis.num_basis); - gkyl_array_set_offset(react->react_lte_moms[i], 1.0, react->vt_sq_partner[i], 2*app->basis.num_basis); + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, react->u_i_dot_b_i[i], 1 * app->basis.num_basis + ); + gkyl_array_set_offset( + react->react_lte_moms[i], 1.0, react->vt_sq_partner[i], 2 * app->basis.num_basis + ); gk_species_lte_from_moms(app, s, &s->lte, react->react_lte_moms[i]); // Accumulate J*n_ion*fmax(n_partner, upar_partner, vt_partner^2) onto f_react - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - 1.0, react->Jm0_ion[i], s->lte.f_lte, &app->local, &s->local); + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, 1.0, react->Jm0_ion[i], s->lte.f_lte, &app->local, + &s->local + ); // Accumulate -n_partner*(J*f_ion) (*note* Jacobian factor already included in fin) - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, react->f_react, - -1.0, react->react_lte_moms[i], fin, &app->local, &s->local); + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, react->f_react, -1.0, react->react_lte_moms[i], fin, &app->local, + &s->local + ); } - // Accumulate reaction update to rhs - gkyl_dg_mul_conf_phase_op_accumulate_range(&app->basis, &s->basis, rhs, - 1.0, react->coeff_react[i], react->f_react, &app->local, &s->local); + // Accumulate reaction update to rhs + gkyl_dg_mul_conf_phase_op_accumulate_range( + &app->basis, &s->basis, rhs, 1.0, react->coeff_react[i], react->f_react, &app->local, + &s->local + ); } app->stat.species_react_tm += gkyl_time_diff_now_sec(wst); } -static void -gks_react_write_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, struct gk_react *gkr, - int ridx, double tm, int frame) +static void gks_react_write_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_react *gkr, int ridx, double tm, + int frame +) { } -static void -gks_react_write_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, struct gk_react *gkr, - int ridx, double tm, int frame) +static void gks_react_write_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_react *gkr, int ridx, double tm, + int frame +) { if (gkr->type_self[ridx] == GKYL_SELF_ION) { struct timespec wst = gkyl_wall_clock(); // Compute reaction rate const struct gkyl_array *fin[app->num_species]; const struct gkyl_array *fin_neut[app->num_neut_species]; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { fin[i] = app->species[i].f; } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { fin_neut[i] = app->neut_species[i].f; } gk_species_react_cross_moms(app, gks, gkr, fin, fin_neut); app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); - + struct timespec wtm = gkyl_wall_clock(); // Package metadata. @@ -309,69 +373,94 @@ gks_react_write_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, struc int io_meta_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; struct gkyl_msgpack_data *mt; - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(gkr->coeff_react_host[ridx], gkr->coeff_react[ridx]); + } if (gkr->react_id[ridx] == GKYL_REACT_IZ) { const char *fmt = "%s-%s_%s_react_iz_%s_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gkr->react_type[ridx].ion_nm, - gkr->react_type[ridx].elc_nm, gkr->react_type[ridx].donor_nm, frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gkr->react_type[ridx].ion_nm, - gkr->react_type[ridx].elc_nm, gkr->react_type[ridx].donor_nm, frame); - + int sz = gkyl_calc_strlen( + fmt, app->name, gkr->react_type[ridx].ion_nm, gkr->react_type[ridx].elc_nm, + gkr->react_type[ridx].donor_nm, frame + ); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gkr->react_type[ridx].ion_nm, + gkr->react_type[ridx].elc_nm, gkr->react_type[ridx].donor_nm, frame + ); + struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Ionization reaction rate." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Ionization reaction rate."} + }; + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc }; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + mt = gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, gkr->coeff_react_host[ridx], fileNm); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, gkr->coeff_react_host[ridx], fileNm + ); } if (gkr->react_id[ridx] == GKYL_REACT_RECOMB) { const char *fmt = "%s-%s_%s_react_recomb_%s_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, - gkr->react_type[ridx].elc_nm, gkr->react_type[ridx].recvr_nm, frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, - gkr->react_type[ridx].elc_nm, gkr->react_type[ridx].recvr_nm, frame); + int sz = gkyl_calc_strlen( + fmt, app->name, gks->info.name, gkr->react_type[ridx].elc_nm, + gkr->react_type[ridx].recvr_nm, frame + ); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gks->info.name, gkr->react_type[ridx].elc_nm, + gkr->react_type[ridx].recvr_nm, frame + ); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Recombination reaction rate." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Recombination reaction rate."} }; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc + }; + mt = gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, gkr->coeff_react_host[ridx], fileNm); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, gkr->coeff_react_host[ridx], fileNm + ); } if (gkr->react_id[ridx] == GKYL_REACT_CX) { const char *fmt = "%s-%s_react_cx_%s_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, - gkr->react_type[ridx].partner_nm, frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, - gkr->react_type[ridx].partner_nm, frame); + int sz = + gkyl_calc_strlen(fmt, app->name, gks->info.name, gkr->react_type[ridx].partner_nm, frame); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gks->info.name, gkr->react_type[ridx].partner_nm, + frame + ); struct gkyl_msgpack_map_elem desc[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Charge exchange reaction rate." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Charge exchange reaction rate." + } + }; + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc }; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc}; - mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + mt = gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, gkr->coeff_react_host[ridx], fileNm); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, gkr->coeff_react_host[ridx], fileNm + ); } app->stat.n_diag_io += 1; - - gkyl_msgpack_data_release(mt); + + gkyl_msgpack_data_release(mt); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); } } -void -gk_species_react_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gkyl_gyrokinetic_react inp, struct gk_react *react, bool all_gk) +void gk_species_react_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gkyl_gyrokinetic_react inp, + struct gk_react *react, bool all_gk +) { - react->num_react = inp.num_react; + react->num_react = inp.num_react; react->write_diagnostics = inp.write_diagnostics; react->cross_moms_func = gks_react_cross_moms_disabled; @@ -381,19 +470,20 @@ gk_species_react_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, if (react->num_react) { react->all_gk = all_gk; // Initialize information about reactions from input struct. - for (int i=0; inum_react; ++i) + for (int i = 0; i < react->num_react; ++i) { react->react_type[i] = inp.react_type[i]; + } // Methods chosen at runtime: react->cross_moms_func = gks_react_cross_moms_enabled; react->rhs_func = gks_react_rhs_enabled; - if (react->write_diagnostics) + if (react->write_diagnostics) { react->write_func = gks_react_write_enabled; + } } } -static double -gk_species_react_get_vt_sq_min(struct gkyl_gyrokinetic_app *app, struct gk_species *s) +static double gk_species_react_get_vt_sq_min(struct gkyl_gyrokinetic_app *app, struct gk_species *s) { double bmag_mid = app->bmag_ref; @@ -401,9 +491,9 @@ gk_species_react_get_vt_sq_min(struct gkyl_gyrokinetic_app *app, struct gk_speci double dv_min[vdim]; gkyl_velocity_map_reduce_dv_range(s->vel_map, GKYL_MIN, dv_min, s->vel_map->local_vel); - double tpar_min = (s->info.mass/6.0)*pow(dv_min[0],2); - double tperp_min = vdim>1 ? (bmag_mid/3.0)*dv_min[1] : tpar_min; - return (tpar_min + 2.0*tperp_min)/(3.0*s->info.mass); + double tpar_min = (s->info.mass / 6.0) * pow(dv_min[0], 2); + double tperp_min = vdim > 1 ? (bmag_mid / 3.0) * dv_min[1] : tpar_min; + return (tpar_min + 2.0 * tperp_min) / (3.0 * s->info.mass); } static double @@ -411,23 +501,24 @@ gk_neut_species_react_get_vt_sq_min(struct gkyl_gyrokinetic_app *app, struct gk_ { if (s->is_fluid) { return 0.0; - } - else { + } else { double bmag_mid = app->bmag_ref; - + int vdim = s->info.vdim; double dv_min[vdim]; gkyl_velocity_map_reduce_dv_range(s->vel_map, GKYL_MIN, dv_min, s->vel_map->local_vel); - + double t_min = 0.0; - for (int i=0; iinfo.mass/6.0)*pow(dv_min[0],2); - return t_min/(3.0*s->info.mass); + for (int i = 0; i < vdim; i++) { + t_min += (s->info.mass / 6.0) * pow(dv_min[0], 2); + } + return t_min / (3.0 * s->info.mass); } } -void -gk_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_react *react) +void gk_species_react_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_react *react +) { if (react->num_react) { // Distribution function which holds update for each reaction @@ -436,7 +527,7 @@ gk_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species // RHS update is then obtained by incrementing rhs += coeff_react*f_react react->f_react = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); - for (int i=0; inum_react; ++i) { + for (int i = 0; i < react->num_react; ++i) { react->react_id[i] = react->react_type[i].react_id; react->type_self[i] = react->react_type[i].type_self; @@ -449,27 +540,27 @@ gk_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species react->ion_idx[i] = gk_find_species_idx(app, react->react_type[i].ion_nm); // Compute a minimum representable temperature based on the smallest dv in the grid. - double ion_vt_sq_min = gk_species_react_get_vt_sq_min(app, &app->species[react->ion_idx[i]]); - double neut_vt_sq_min; + double ion_vt_sq_min = gk_species_react_get_vt_sq_min(app, &app->species[react->ion_idx[i]]); + double neut_vt_sq_min; - // If all the reacting species are gyrokinetic species, need to use + // If all the reacting species are gyrokinetic species, need to use // gk methods to fetch pointers and indices, otherwise use gk_neut methods // to get the necessary neutral species information if (react->all_gk && gk_find_species(app, react->react_type[i].donor_nm)) { react->donor_idx[i] = gk_find_species_idx(app, react->react_type[i].donor_nm); - } - else if (gk_find_neut_species(app, react->react_type[i].donor_nm)) { + } else if (gk_find_neut_species(app, react->react_type[i].donor_nm)) { react->donor_idx[i] = gk_find_neut_species_idx(app, react->react_type[i].donor_nm); - } - else if (gk_find_neut_species(app, react->react_type[i].partner_nm)) { + } else if (gk_find_neut_species(app, react->react_type[i].partner_nm)) { react->partner_idx[i] = gk_find_neut_species_idx(app, react->react_type[i].partner_nm); - neut_vt_sq_min = gk_neut_species_react_get_vt_sq_min(app, &app->neut_species[react->partner_idx[i]]); + neut_vt_sq_min = + gk_neut_species_react_get_vt_sq_min(app, &app->neut_species[react->partner_idx[i]]); } react->coeff_react[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); // Reaction LTE moments needed for projecting LTE distribution functions - react->react_lte_moms[i] = mkarr(app->use_gpu, 3*app->basis.num_basis, app->local_ext.volume); + react->react_lte_moms[i] = + mkarr(app->use_gpu, 3 * app->basis.num_basis, app->local_ext.volume); // Thermal velocities for LTE projection in ionization terms. react->vt_sq_iz1[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); @@ -482,25 +573,24 @@ gk_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species // Vector flow velocity, donor velocity, and donor vt^2 for projecting LTE distribution functions // donor velocity is simply upar when reacting with plasma, and u_i . b_i when reacting with neutrals - react->u_i[i] = mkarr(app->use_gpu, 3*app->basis.num_basis, app->local_ext.volume); + react->u_i[i] = mkarr(app->use_gpu, 3 * app->basis.num_basis, app->local_ext.volume); react->u_i_dot_b_i[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); react->vt_sq_donor[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); // Partner flow velocity (upar b_i), partner vt^2 for projecting LTE distribution functions - react->upar_ion[i] = mkarr(app->use_gpu, 3*app->basis.num_basis, app->local_ext.volume); + react->upar_ion[i] = mkarr(app->use_gpu, 3 * app->basis.num_basis, app->local_ext.volume); react->vt_sq_partner[i] = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - + if (react->react_id[i] == GKYL_REACT_IZ) { struct gkyl_dg_iz_inp iz_inp = { .cbasis = &app->basis, .conf_rng = &app->local, .type_ion = react->react_type[i].ion_id, .charge_state = react->react_type[i].charge_state, - .type_self = react->type_self[i], + .type_self = react->type_self[i] }; react->iz[i] = gkyl_dg_iz_new(&iz_inp, app->use_gpu); - } - else if (react->react_id[i] == GKYL_REACT_RECOMB) { + } else if (react->react_id[i] == GKYL_REACT_RECOMB) { struct gkyl_dg_recomb_inp recomb_inp = { .grid = &s->grid, .cbasis = &app->basis, @@ -511,59 +601,62 @@ gk_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species .mass_self = s->info.mass, .type_ion = react->react_type[i].ion_id, .charge_state = react->react_type[i].charge_state, - .type_self = react->type_self[i], + .type_self = react->type_self[i] }; react->recomb[i] = gkyl_dg_recomb_new(&recomb_inp, app->use_gpu); - } - else if (react->react_id[i] == GKYL_REACT_CX) { + } else if (react->react_id[i] == GKYL_REACT_CX) { struct gkyl_dg_cx_inp cx_inp = { .cbasis = &app->basis, .conf_rng = &app->local, - .vt_sq_ion_min = ion_vt_sq_min, - .vt_sq_neut_min = neut_vt_sq_min, - .type_ion = react->react_type[i].ion_id, + .vt_sq_ion_min = ion_vt_sq_min, + .vt_sq_neut_min = neut_vt_sq_min, + .type_ion = react->react_type[i].ion_id }; react->cx[i] = gkyl_dg_cx_new(&cx_inp, app->use_gpu); } if (react->write_diagnostics) { - react->coeff_react_host[i] = app->use_gpu? mkarr(false, react->coeff_react[i]->ncomp, react->coeff_react[i]->size) - : gkyl_array_acquire(react->coeff_react[i]); + react->coeff_react_host[i] = + app->use_gpu ? mkarr(false, react->coeff_react[i]->ncomp, react->coeff_react[i]->size) : + gkyl_array_acquire(react->coeff_react[i]); } } } } -void -gk_species_react_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_react *react, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +void gk_species_react_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_react *react, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { react->cross_moms_func(app, species, react, fin, fin_neut); } -void -gk_species_react_rhs(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_react *react, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_species_react_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_react *react, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { react->rhs_func(app, s, react, fin, rhs); } -void -gk_species_react_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, struct gk_react *gkr, - int ridx, double tm, int frame) +void gk_species_react_write( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_react *gkr, int ridx, double tm, + int frame +) { gkr->write_func(app, gks, gkr, ridx, tm, frame); } -void -gk_species_react_release(const struct gkyl_gyrokinetic_app *app, const struct gk_react *react) +void gk_species_react_release(const struct gkyl_gyrokinetic_app *app, const struct gk_react *react) { if (react->num_react) { gkyl_array_release(react->f_react); - for (int i=0; inum_react; ++i) { + for (int i = 0; i < react->num_react; ++i) { gkyl_array_release(react->coeff_react[i]); - if (react->write_diagnostics) + if (react->write_diagnostics) { gkyl_array_release(react->coeff_react_host[i]); + } gkyl_array_release(react->react_lte_moms[i]); gkyl_array_release(react->vt_sq_iz1[i]); @@ -571,19 +664,17 @@ gk_species_react_release(const struct gkyl_gyrokinetic_app *app, const struct gk gkyl_array_release(react->Jm0_elc[i]); gkyl_array_release(react->Jm0_ion[i]); gkyl_array_release(react->Jm0_donor[i]); - gkyl_array_release(react->u_i[i]); + gkyl_array_release(react->u_i[i]); gkyl_array_release(react->u_i_dot_b_i[i]); gkyl_array_release(react->vt_sq_donor[i]); - gkyl_array_release(react->upar_ion[i]); - gkyl_array_release(react->vt_sq_partner[i]); + gkyl_array_release(react->upar_ion[i]); + gkyl_array_release(react->vt_sq_partner[i]); if (react->react_id[i] == GKYL_REACT_IZ) { gkyl_dg_iz_release(react->iz[i]); - } - else if (react->react_id[i] == GKYL_REACT_RECOMB) { + } else if (react->react_id[i] == GKYL_REACT_RECOMB) { gkyl_dg_recomb_release(react->recomb[i]); - } - else if (react->react_id[i] == GKYL_REACT_CX) { + } else if (react->react_id[i] == GKYL_REACT_CX) { gkyl_dg_cx_release(react->cx[i]); } } diff --git a/gyrokinetic/apps/gk_species_scaling.c b/gyrokinetic/apps/gk_species_scaling.c index 0e29be649c..66964ab231 100644 --- a/gyrokinetic/apps/gk_species_scaling.c +++ b/gyrokinetic/apps/gk_species_scaling.c @@ -1,23 +1,26 @@ #include #include -static void -gk_species_scaling_cross_moms_disabled(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_scaling *sca, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +static void gk_species_scaling_cross_moms_disabled( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_scaling *sca, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { // Do nothing. } -static void -gk_species_scaling_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_species_scaling_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { // Do nothing. } -static void -gk_species_scaling_apply_fixed_fraction(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca, struct gkyl_array *fin, struct gkyl_array **bflux[]) +static void gk_species_scaling_apply_fixed_fraction( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, struct gkyl_array *fin, + struct gkyl_array **bflux[] +) { struct gk_species *gks_ref = &app->species[sca->ref_species_idx]; @@ -36,71 +39,85 @@ gk_species_scaling_apply_fixed_fraction(gkyl_gyrokinetic_app *app, struct gk_spe // Multiply this species by ratio of densities times fixed_fraction. gkyl_array_scale_range(m0ratio, sca->fixed_fraction, &app->local); - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gks->basis, fin, m0ratio, fin, &app->local, &gks->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gks->basis, fin, m0ratio, fin, &app->local, &gks->local + ); } -static void -copy_lower_z_ghost_to_all_z_conf(gkyl_gyrokinetic_app *app, struct gkyl_array *arr_out, - struct gkyl_array *arr_in, int comp_in, struct gkyl_array *buff) +static void copy_lower_z_ghost_to_all_z_conf( + gkyl_gyrokinetic_app *app, struct gkyl_array *arr_out, struct gkyl_array *arr_in, int comp_in, + struct gkyl_array *buff +) { // Copy the component 'comp_in' of the lower ghost cell of 'arr_in' into the // interior cells of 'arr_out' for configuration-space ranges and arrays. int cdim = app->cdim; - int idx_par = cdim-1; + int idx_par = cdim - 1; // Copy lower ghost of input field into buffer. - struct gkyl_range* lower_ghost = &app->local_lower_ghost[idx_par]; - gkyl_array_set_offset_range(buff, 1.0, arr_in, comp_in, lower_ghost); + struct gkyl_range *lower_ghost = &app->local_lower_ghost[idx_par]; + gkyl_array_set_offset_range(buff, 1.0, arr_in, comp_in, lower_ghost); // Create a range for each z cell, and copy from buffer into that range. - int num_cells_z = app->local.upper[idx_par]-app->local.lower[idx_par]+1; + int num_cells_z = app->local.upper[idx_par] - app->local.lower[idx_par] + 1; int lower[GKYL_MAX_CDIM], upper[GKYL_MAX_CDIM]; - for (int d=0; dlocal.lower[d]; upper[d] = app->local.upper[d]; } struct gkyl_range rng_curr; - for (int i=0; ilocal.lower[idx_par]+i; + for (int i = 0; i < num_cells_z; ++i) { + lower[idx_par] = app->local.lower[idx_par] + i; upper[idx_par] = lower[idx_par]; gkyl_sub_range_init(&rng_curr, &app->local_ext, lower, upper); - gkyl_array_copy_range_to_range(arr_out, buff, &rng_curr, lower_ghost); + gkyl_array_copy_range_to_range(arr_out, buff, &rng_curr, lower_ghost); } } -static void -gk_species_scaling_apply_boltzmann(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca, struct gkyl_array *fin, struct gkyl_array **bflux[]) +static void gk_species_scaling_apply_boltzmann( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, struct gkyl_array *fin, + struct gkyl_array **bflux[] +) { struct gk_species *gks_ref = &app->species[sca->ref_species_idx]; // Compute density and temperature. gk_species_moment_calc(&gks->lte.moms, gks->local, app->local, fin); - gkyl_dg_div_op_range(gks->lte.moms.mem_geo, &app->basis, 0, gks->lte.moms.marr, - 0, gks->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + gks->lte.moms.mem_geo, &app->basis, 0, gks->lte.moms.marr, 0, gks->lte.moms.marr, 0, + app->gk_geom->geo_int.jacobgeo, &app->local + ); // Boltzmann density = n_sheath * exp(-q * (phi-phi_sheath)/T ). // Copy the sheath potential from the lower ghost cell to the interior cells. - int idx_par = app->cdim-1; - int off = 2*idx_par; - copy_lower_z_ghost_to_all_z_conf(app, sca->sheath_val, app->field->sheath_vals[off], 1*app->basis.num_basis, sca->buffer_conf); + int idx_par = app->cdim - 1; + int off = 2 * idx_par; + copy_lower_z_ghost_to_all_z_conf( + app, sca->sheath_val, app->field->sheath_vals[off], 1 * app->basis.num_basis, sca->buffer_conf + ); // Compute ( phi-phi_sheath)/(T/m) ). gkyl_array_copy_range(sca->buffer_conf, app->field->phi_smooth, &app->local); gkyl_array_accumulate_range(sca->buffer_conf, -1.0, sca->sheath_val, &app->local); - gkyl_dg_div_op_range(gks->lte.moms.mem_geo, &app->basis, 0, sca->buffer_conf, - 0, sca->buffer_conf, 2, gks->lte.moms.marr, &app->local); + gkyl_dg_div_op_range( + gks->lte.moms.mem_geo, &app->basis, 0, sca->buffer_conf, 0, sca->buffer_conf, 2, + gks->lte.moms.marr, &app->local + ); // Compute exp(-q * (phi-phi_sheath)/T ). - double qDm = gks->info.charge/gks->info.mass; + double qDm = gks->info.charge / gks->info.mass; struct gkyl_array *m0_boltz = gks->m0.marr; gkyl_proj_exp_on_basis_advance(sca->proj_exp, &app->local, 1.0, -qDm, sca->buffer_conf, m0_boltz); // Copy the sheath density from the lower ghost cell to the interior cells. - copy_lower_z_ghost_to_all_z_conf(app, sca->sheath_val, app->field->sheath_vals[off], 0*app->basis.num_basis, sca->buffer_conf); + copy_lower_z_ghost_to_all_z_conf( + app, sca->sheath_val, app->field->sheath_vals[off], 0 * app->basis.num_basis, sca->buffer_conf + ); // Compute n_sheath * exp(-q * (phi-phi_sheath)/T ). - gkyl_dg_mul_op_range(&app->basis, 0, sca->buffer_conf, 0, sca->sheath_val, 0, m0_boltz, &app->local); + gkyl_dg_mul_op_range( + &app->basis, 0, sca->buffer_conf, 0, sca->sheath_val, 0, m0_boltz, &app->local + ); // Reciprocal of the density. struct gkyl_array *m0_inv = gks->m0.marr; @@ -111,50 +128,55 @@ gk_species_scaling_apply_boltzmann(gkyl_gyrokinetic_app *app, struct gk_species gkyl_dg_mul_op_range(&app->basis, 0, m0ratio, 0, m0_inv, 0, sca->buffer_conf, &app->local); // Multiply this species by ratio of densities times fixed_fraction. - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gks->basis, fin, m0ratio, fin, &app->local, &gks->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gks->basis, fin, m0ratio, fin, &app->local, &gks->local + ); } -static void -gk_species_scaling_apply_disabled(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca, struct gkyl_array *fin, struct gkyl_array **bflux[]) +static void gk_species_scaling_apply_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, struct gkyl_array *fin, + struct gkyl_array **bflux[] +) { // Do nothing. } -static void -gk_species_scaling_write_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_scaling *sca, int ridx, double tm, int frame) +static void gk_species_scaling_write_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, int ridx, double tm, + int frame +) { // React diagnostics usually written from gk_species. // In the case of static gk_species, write_diagnostics flag // can be used to check reaction rates from gk_species. struct timespec wst = gkyl_wall_clock(); -// // Compute reaction rate -// const struct gkyl_array *fin[app->num_species]; -// const struct gkyl_array *fin_neut[app->num_species]; -// for (int i=0; inum_species; ++i) { -// fin[i] = app->species[i].f; -// } -// for (int i=0; inum_species; ++i) { -// fin_neut[i] = app->species[i].f; -// } -// gk_species_scaling_cross_moms(app, gks, gkr, fin, fin_neut); + // // Compute reaction rate + // const struct gkyl_array *fin[app->num_species]; + // const struct gkyl_array *fin_neut[app->num_species]; + // for (int i=0; inum_species; ++i) { + // fin[i] = app->species[i].f; + // } + // for (int i=0; inum_species; ++i) { + // fin_neut[i] = app->species[i].f; + // } + // gk_species_scaling_cross_moms(app, gks, gkr, fin, fin_neut); app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); - + struct timespec wtm = gkyl_wall_clock(); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); } -static void -gk_species_scaling_write_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_scaling *sca, int ridx, double tm, int frame) +static void gk_species_scaling_write_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, int ridx, double tm, + int frame +) { // Do nothing } -void -gk_species_scaling_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca) +void gk_species_scaling_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca +) { struct gkyl_gyrokinetic_scaling_inp *sca_inp = &gks->info.scaling; @@ -171,29 +193,30 @@ gk_species_scaling_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks sca->fixed_fraction = sca_inp->fixed_fraction; sca->apply_func = gk_species_scaling_apply_fixed_fraction; - if (sca->write_diagnostics) + if (sca->write_diagnostics) { sca->write_func = gk_species_scaling_write_enabled; - else + } else { sca->write_func = gk_species_scaling_write_disabled; - } - else if (sca_inp->type == GKYL_GK_SPECIES_SCALING_BOLTZMANN) { - + } + } else if (sca_inp->type == GKYL_GK_SPECIES_SCALING_BOLTZMANN) { sca->type = sca_inp->type; sca->sheath_val = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); sca->buffer_conf = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - sca->proj_exp = gkyl_proj_exp_on_basis_new(&app->basis, app->basis.poly_order+1, app->use_gpu); + sca->proj_exp = + gkyl_proj_exp_on_basis_new(&app->basis, app->basis.poly_order + 1, app->use_gpu); sca->apply_func = gk_species_scaling_apply_boltzmann; - if (sca->write_diagnostics) + if (sca->write_diagnostics) { sca->write_func = gk_species_scaling_write_enabled; - else + } else { sca->write_func = gk_species_scaling_write_disabled; + } } } -void -gk_species_scaling_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca) +void gk_species_scaling_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca +) { if (sca->type == GKYL_GK_SPECIES_SCALING_FIXED_FRACTION) { struct gkyl_gyrokinetic_scaling_inp *sca_inp = &gks->info.scaling; @@ -203,49 +226,50 @@ gk_species_scaling_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_specie } } -void -gk_species_scaling_apply_ic_cross(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca) +void gk_species_scaling_apply_ic_cross( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca +) { if (sca->type == GKYL_GK_SPECIES_SCALING_FIXED_FRACTION) { } } -void -gk_species_scaling_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_scaling *sca, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]) +void gk_species_scaling_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_scaling *sca, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +) { sca->cross_moms_func(app, gks, sca, fin, fin_neut); } -void -gk_species_scaling_rhs(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_species_scaling_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { sca->rhs_func(app, gks, sca, fin, rhs); } -void -gk_species_scaling_apply(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca, struct gkyl_array *fin, struct gkyl_array **bflux[]) +void gk_species_scaling_apply( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, struct gkyl_array *fin, + struct gkyl_array **bflux[] +) { sca->apply_func(app, gks, sca, fin, bflux); } -void -gk_species_scaling_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_scaling *sca, int ridx, double tm, int frame) +void gk_species_scaling_write( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, int ridx, double tm, + int frame +) { sca->write_func(app, gks, sca, ridx, tm, frame); } -void -gk_species_scaling_release(const struct gkyl_gyrokinetic_app *app, - const struct gk_scaling *sca) +void gk_species_scaling_release(const struct gkyl_gyrokinetic_app *app, const struct gk_scaling *sca) { if (sca->type == GKYL_GK_SPECIES_SCALING_FIXED_FRACTION) { - } - else if (sca->type == GKYL_GK_SPECIES_SCALING_BOLTZMANN) { + } else if (sca->type == GKYL_GK_SPECIES_SCALING_BOLTZMANN) { gkyl_proj_exp_on_basis_release(sca->proj_exp); gkyl_array_release(sca->sheath_val); gkyl_array_release(sca->buffer_conf); diff --git a/gyrokinetic/apps/gk_species_source.c b/gyrokinetic/apps/gk_species_source.c index 9a28277aa2..71f5ce15ed 100644 --- a/gyrokinetic/apps/gk_species_source.c +++ b/gyrokinetic/apps/gk_species_source.c @@ -1,58 +1,67 @@ #include #include -void -gk_species_source_write_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_source_write_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { // Empty. } -void -gk_species_source_write_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_source_write_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { struct timespec wst = gkyl_wall_clock(); // Package metadata. gkyl_msgpack_map_elem_set_double(gks->io_meta_phase_len, gks->io_meta_phase, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_phase_len, gks->io_meta_phase, "frame", frame); struct gkyl_msgpack_map_elem io_meta_source[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Source." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Source."} }; int io_meta_len[] = {gks->io_meta_phase_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_phase, app->gk_geom->io_meta_basic, io_meta_source}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_phase, app->gk_geom->io_meta_basic, io_meta_source + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); // Write out the source distribution function const char *fmt = "%s-%s_source_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, frame); // Copy data from device to host before writing it out. - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(gks->src.source_host, gks->src.source); + } gkyl_comm_array_write(gks->comm, &gks->grid, &gks->local, mt, gks->src.source_host, fileNm); app->stat.n_io += 1; - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); } -void -gk_species_source_write_init_only(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_source_write_init_only( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { gk_species_source_write_enabled(app, gks, tm, frame); gks->src.write_func = gk_species_source_write_disabled; } -void -gk_species_source_write_mom_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_source_write_mom_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { // Empty. } -void -gk_species_source_write_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_source_write_mom_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { struct timespec wst = gkyl_wall_clock(); @@ -60,36 +69,49 @@ gk_species_source_write_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species gkyl_msgpack_map_elem_set_double(gks->io_meta_conf_len, gks->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_conf_len, gks->io_meta_conf, "frame", frame); - for (int m=0; msrc.num_diag_mom; ++m) { + for (int m = 0; m < gks->src.num_diag_mom; ++m) { struct timespec wst = gkyl_wall_clock(); gk_species_moment_calc(&gks->src.moms[m], gks->local, app->local, gks->src.source); app->stat.n_mom += 1; // Rescale moment by inverse of Jacobian if needed. - gk_species_moment_diag_jacobgeo_div(app, &gks->src.moms[m], gks->src.moms[m].marr, gks->src.moms[m].marr); + gk_species_moment_diag_jacobgeo_div( + app, &gks->src.moms[m], gks->src.moms[m].marr, gks->src.moms[m].marr + ); app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); struct timespec wtm = gkyl_wall_clock(); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(gks->src.moms[m].marr_host, gks->src.moms[m].marr); + } struct gkyl_msgpack_map_elem io_meta_mom[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, - .cval = (char*)gkyl_distribution_moments_descriptions[gks->info.source.diagnostics.diag_moments[m]] } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = (char *) + gkyl_distribution_moments_descriptions[gks->info.source.diagnostics.diag_moments[m]]} }; int io_meta_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, io_meta_mom}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, io_meta_mom + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); const char *fmt = "%s-%s_source_%s_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, - gkyl_distribution_moments_strs[gks->info.source.diagnostics.diag_moments[m]], frame); - char fileNm[sz+1]; // Ensures no buffer overflow. - snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, - gkyl_distribution_moments_strs[gks->info.source.diagnostics.diag_moments[m]], frame); - - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, - gks->src.moms[m].marr_host, fileNm); + int sz = gkyl_calc_strlen( + fmt, app->name, gks->info.name, + gkyl_distribution_moments_strs[gks->info.source.diagnostics.diag_moments[m]], frame + ); + char fileNm[sz + 1]; // Ensures no buffer overflow. + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gks->info.name, + gkyl_distribution_moments_strs[gks->info.source.diagnostics.diag_moments[m]], frame + ); + + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, gks->src.moms[m].marr_host, fileNm + ); gkyl_msgpack_data_release(mt); app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wtm); app->stat.n_diag_io += 1; @@ -98,21 +120,24 @@ gk_species_source_write_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species app->stat.n_diag += 1; } -void -gk_species_source_write_mom_init_only(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_source_write_mom_init_only( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { gk_species_source_write_mom_enabled(app, gks, tm, frame); gks->src.write_mom_func = gk_species_source_write_mom_disabled; } -void -gk_species_source_calc_integrated_mom_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +void gk_species_source_calc_integrated_mom_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm +) { // Empty. } -void -gk_species_source_calc_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +void gk_species_source_calc_integrated_mom_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm +) { struct timespec wst = gkyl_wall_clock(); @@ -121,17 +146,20 @@ gk_species_source_calc_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct int num_mom = gks->src.integ_moms.num_mom; double avals_global[num_mom]; - gk_species_moment_calc(&gks->src.integ_moms, gks->local, app->local, gks->src.source); + gk_species_moment_calc(&gks->src.integ_moms, gks->local, app->local, gks->src.source); app->stat.n_mom += 1; // Reduce to compute sum over whole domain, append to diagnostics gkyl_array_reduce_range(gks->src.red_integ_diag, gks->src.integ_moms.marr, GKYL_SUM, &app->local); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, - gks->src.red_integ_diag, gks->src.red_integ_diag_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, gks->src.red_integ_diag, + gks->src.red_integ_diag_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, gks->src.red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, gks->src.red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, gks->src.red_integ_diag_global, sizeof(double[num_mom])); } @@ -139,22 +167,23 @@ gk_species_source_calc_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct // This assumes time-independent sources. For time dependent ones // step the source contributions in RK3 like we do for boundary fluxes. double avals_global_prev[num_mom]; - for (int k=0; ksrc.integ_diag, avals_global_prev); - + double tau = tm - tm_prev; - for (int k=0; ksrc.integ_diag, tm, avals_global); if (gks->src.num_adapt_sources > 0) { - // Adaptive sources diagnostic. double temp[gks->src.num_adapt_sources]; double part[gks->src.num_adapt_sources]; - for (int k=0; k < gks->src.num_adapt_sources; ++k) { + for (int k = 0; k < gks->src.num_adapt_sources; ++k) { temp[k] = gks->src.adapt[k].temperature_curr; part[k] = gks->src.adapt[k].particle_src_curr; } @@ -166,14 +195,16 @@ gk_species_source_calc_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct app->stat.n_diag += 1; } -void -gk_species_source_write_integrated_mom_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks) +void gk_species_source_write_integrated_mom_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks +) { // empty } -void -gk_species_source_write_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks) +void gk_species_source_write_integrated_mom_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks +) { struct timespec wst = gkyl_wall_clock(); @@ -184,22 +215,26 @@ gk_species_source_write_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct const char *fmt = "%s-%s_source_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, "integrated_moms"); - char fileNm[sz+1]; // Ensures no buffer overflow. + char fileNm[sz + 1]; // Ensures no buffer overflow. snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, "integrated_moms"); if (gks->src.is_first_integ_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated moments of the source." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Volume integrated moments of the source."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(gks->src.integ_diag, fileNm, mt); gks->src.is_first_integ_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(gks->src.integ_diag, fileNm); } } @@ -211,21 +246,25 @@ gk_species_source_write_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct const char *fmt = "%s-%s_adapt_sources_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, "particle"); - char fileNm[sz+1]; // Ensures no buffer overflow. + char fileNm[sz + 1]; // Ensures no buffer overflow. snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, "particle"); if (gks->src.is_first_integ_write_call_adapt) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Source particle injection rate." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Source particle injection rate."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); - + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); + gkyl_dynvec_write_wmeta(gks->src.part_diag, fileNm, mt); gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(gks->src.part_diag, fileNm); } } @@ -236,21 +275,23 @@ gk_species_source_write_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct const char *fmt = "%s-%s_adapt_sources_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, "temperature"); - char fileNm[sz+1]; // Ensures no buffer overflow. + char fileNm[sz + 1]; // Ensures no buffer overflow. snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, "temperature"); if (gks->src.is_first_integ_write_call_adapt) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Source temperature." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Source temperature."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(gks->src.temp_diag, fileNm, mt); gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(gks->src.temp_diag, fileNm); } } @@ -262,43 +303,46 @@ gk_species_source_write_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct app->stat.n_diag_io += 1; } - -void -gk_species_source_calc(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_source *src, struct gkyl_array *f_buffer, double tm) +void gk_species_source_calc( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_source *src, + struct gkyl_array *f_buffer, double tm +) { if (src->source_id) { gkyl_array_clear(src->source, 0.0); - for (int k=0; kinfo.source.num_sources; k++) { + for (int k = 0; k < s->info.source.num_sources; k++) { gk_species_projection_calc(app, s, &src->proj_source[k], f_buffer, tm); gkyl_array_accumulate(src->source, 1., f_buffer); } } } -void -gk_species_source_adapt(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_source *src, struct gkyl_array *f_buffer, struct gkyl_array **bflux_moms[], double tm) -{ +void gk_species_source_adapt( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_source *src, + struct gkyl_array *f_buffer, struct gkyl_array **bflux_moms[], double tm +) +{ struct timespec wst = gkyl_wall_clock(); src->adapt_func(app, s, src, f_buffer, bflux_moms, tm); - + app->stat.species_src_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_source_adapt_disabled(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_source *src, struct gkyl_array *f_buffer, struct gkyl_array **bflux_moms[], double tm) +static void gk_species_source_adapt_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_source *src, + struct gkyl_array *f_buffer, struct gkyl_array **bflux_moms[], double tm +) { // Empty. } -static void -gk_species_source_adapt_enabled(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_source *src, struct gkyl_array *f_buffer, struct gkyl_array **bflux_moms[], double tm) +static void gk_species_source_adapt_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_source *src, + struct gkyl_array *f_buffer, struct gkyl_array **bflux_moms[], double tm +) { - for (int k=0; k < s->info.source.num_adapt_sources; ++k) { + for (int k = 0; k < s->info.source.num_adapt_sources; ++k) { struct gk_adapt_source *adapt_src = &src->adapt[k]; struct gk_species *s_adapt = adapt_src->adapt_species; struct gkyl_array **s_adapt_bflux_moms = bflux_moms[adapt_src->adapt_species_idx]; @@ -306,20 +350,28 @@ gk_species_source_adapt_enabled(gkyl_gyrokinetic_app *app, struct gk_species *s, // Accumulate energy and particle losses through the boundaries. double sum_particle_loss_local = 0.0; double sum_energy_loss_local = 0.0; - for (int j=0; j < adapt_src->num_boundaries; ++j) { - - double integ_m0_local_j, integ_m2_local_j; // Integrated boundary flux moments summed over boundaries. - - gk_species_bflux_get_flux_mom(&s_adapt->bflux, adapt_src->dir[j], adapt_src->edge[j], - GKYL_F_MOMENT_M0, s_adapt_bflux_moms, adapt_src->bflux_m0, &adapt_src->boundaries_conf_ghost[j]); - gk_species_bflux_get_flux_mom(&s_adapt->bflux, adapt_src->dir[j], adapt_src->edge[j], - GKYL_F_MOMENT_M2, s_adapt_bflux_moms, adapt_src->bflux_m2, &adapt_src->boundaries_conf_ghost[j]); + for (int j = 0; j < adapt_src->num_boundaries; ++j) { + double integ_m0_local_j, + integ_m2_local_j; // Integrated boundary flux moments summed over boundaries. + + gk_species_bflux_get_flux_mom( + &s_adapt->bflux, adapt_src->dir[j], adapt_src->edge[j], GKYL_F_MOMENT_M0, + s_adapt_bflux_moms, adapt_src->bflux_m0, &adapt_src->boundaries_conf_ghost[j] + ); + gk_species_bflux_get_flux_mom( + &s_adapt->bflux, adapt_src->dir[j], adapt_src->edge[j], GKYL_F_MOMENT_M2, + s_adapt_bflux_moms, adapt_src->bflux_m2, &adapt_src->boundaries_conf_ghost[j] + ); // Integrate the boundary flux moments to get the total loss through the j-th boundary. - gkyl_array_integrate_advance(adapt_src->integrate_op, adapt_src->bflux_m0, 1.0, 0, - &adapt_src->boundaries_conf_ghost[j], 0, adapt_src->integ_m0); - gkyl_array_integrate_advance(adapt_src->integrate_op, adapt_src->bflux_m2, 1.0, 0, - &adapt_src->boundaries_conf_ghost[j], 0, adapt_src->integ_m2); + gkyl_array_integrate_advance( + adapt_src->integrate_op, adapt_src->bflux_m0, 1.0, 0, &adapt_src->boundaries_conf_ghost[j], + 0, adapt_src->integ_m0 + ); + gkyl_array_integrate_advance( + adapt_src->integrate_op, adapt_src->bflux_m2, 1.0, 0, &adapt_src->boundaries_conf_ghost[j], + 0, adapt_src->integ_m2 + ); if (app->use_gpu) { gkyl_cu_memcpy(&integ_m0_local_j, adapt_src->integ_m0, sizeof(double), GKYL_CU_MEMCPY_D2H); gkyl_cu_memcpy(&integ_m2_local_j, adapt_src->integ_m2, sizeof(double), GKYL_CU_MEMCPY_D2H); @@ -332,41 +384,52 @@ gk_species_source_adapt_enabled(gkyl_gyrokinetic_app *app, struct gk_species *s, sum_energy_loss_local += 0.5 * s_adapt->info.mass * integ_m2_local_j; // 1/2 * m * v^2 } // Sum over all MPI processes. - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, &sum_particle_loss_local, &adapt_src->particle_rate_loss); - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, &sum_energy_loss_local, &adapt_src->energy_rate_loss); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_SUM, 1, &sum_particle_loss_local, &adapt_src->particle_rate_loss + ); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_SUM, 1, &sum_energy_loss_local, &adapt_src->energy_rate_loss + ); double particle_input = s->info.source.projection[k].total_num_particles; double energy_input = s->info.source.projection[k].total_kin_energy; // Particle and energy rate update. // balance = user target + loss - double density_compensation = adapt_src->adapt_particle_fraction * adapt_src->particle_rate_loss; - double particle_src_new = adapt_src->adapt_particle? - particle_input + density_compensation : particle_input; + double density_compensation = + adapt_src->adapt_particle_fraction * adapt_src->particle_rate_loss; + double particle_src_new = adapt_src->adapt_particle ? particle_input + density_compensation : + particle_input; double energy_compensation = adapt_src->adapt_energy_fraction * adapt_src->energy_rate_loss; - double energy_src_new = adapt_src->adapt_energy? - energy_input + energy_compensation : energy_input; + double energy_src_new = adapt_src->adapt_energy ? energy_input + energy_compensation : + energy_input; // Avoid negative particle source. // This is important to avoid division by zero in the temperature calculation. particle_src_new = fmax(particle_input, particle_src_new); - + // Compute the target temperature of the source following the rule: // T = 2/3 * Q/G (T: src temperature, Q: src energy rate, G: total particle rate) - const double vdim_phys = s->info.vdim == 1? 1.0 : 3.0; - double temperature_new = (2./vdim_phys) * energy_src_new/particle_src_new; + const double vdim_phys = s->info.vdim == 1 ? 1.0 : 3.0; + double temperature_new = (2. / vdim_phys) * energy_src_new / particle_src_new; - // Impose the temperature to be within the limits. + // Impose the temperature to be within the limits. temperature_new = fmin(temperature_new, s->info.source.projection[k].temp_max); temperature_new = fmax(temperature_new, s->info.source.projection[k].temp_min); // Update the density and temperature moments of the source gkyl_array_clear(src->proj_source[k].prim_moms, 0.0); - gkyl_array_set_offset(src->proj_source[k].prim_moms, particle_src_new, src->proj_source[k].gaussian_profile, 0*app->basis.num_basis); + gkyl_array_set_offset( + src->proj_source[k].prim_moms, particle_src_new, src->proj_source[k].gaussian_profile, + 0 * app->basis.num_basis + ); // The parallel velocity is left to be 0 double dg_norm = pow(sqrt(2.0), app->cdim); - gkyl_array_shiftc(src->proj_source[k].prim_moms, dg_norm * temperature_new / s->info.mass, 2*app->basis.num_basis); + gkyl_array_shiftc( + src->proj_source[k].prim_moms, dg_norm * temperature_new / s->info.mass, + 2 * app->basis.num_basis + ); // Refresh the current values of particle, energy and temperature (can be used for control). adapt_src->particle_src_curr = particle_src_new; @@ -378,18 +441,19 @@ gk_species_source_adapt_enabled(gkyl_gyrokinetic_app *app, struct gk_species *s, gk_species_source_calc(app, s, &s->src, f_buffer, tm); } -static void -gk_species_source_adapt_after_first_step(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_source *src, struct gkyl_array *f_buffer, struct gkyl_array **bflux_moms[], double tm) +static void gk_species_source_adapt_after_first_step( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_source *src, + struct gkyl_array *f_buffer, struct gkyl_array **bflux_moms[], double tm +) { // Re-point to the function that adapts the source, so it doesn't happen the // first time we call gk_species_source_adapt. src->adapt_func = gk_species_source_adapt_enabled; } -void -gk_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_source *src) +void gk_species_source_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_source *src +) { src->source_id = s->info.source.source_id; @@ -405,39 +469,48 @@ gk_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, src->source = mkarr(app->use_gpu, s->basis.num_basis, s->local_ext.volume); src->source_host = src->source; if (app->use_gpu) { - src->source_host = mkarr(false, src->source->ncomp, src->source->size); + src->source_host = mkarr(false, src->source->ncomp, src->source->size); } - src->evolve = s->info.source.evolve || s->info.source.num_adapt_sources > 0; // Whether the source is time dependent. + src->evolve = s->info.source.evolve || + s->info.source.num_adapt_sources > 0; // Whether the source is time dependent. src->num_sources = s->info.source.num_sources; - for (int k=0; kinfo.source.num_sources; k++) + for (int k = 0; k < s->info.source.num_sources; k++) { gk_species_projection_init(app, s, s->info.source.projection[k], &src->proj_source[k]); + } // Allocate data and updaters for diagnostic moments. src->num_diag_mom = s->info.source.diagnostics.num_diag_moments; if (src->num_diag_mom == 0) { src->num_diag_mom = s->info.num_diag_moments; - for (int m=0; mnum_diag_mom; ++m) + for (int m = 0; m < src->num_diag_mom; ++m) { s->info.source.diagnostics.diag_moments[m] = s->info.diag_moments[m]; + } } src->moms = gkyl_malloc(sizeof(struct gk_species_moment[src->num_diag_mom])); - for (int m=0; mnum_diag_mom; ++m) - gk_species_moment_init(app, s, &src->moms[m], s->info.source.diagnostics.diag_moments[m], false); + for (int m = 0; m < src->num_diag_mom; ++m) { + gk_species_moment_init( + app, s, &src->moms[m], s->info.source.diagnostics.diag_moments[m], false + ); + } // Allocate data and updaters for integrated moments. src->num_diag_int_mom = s->info.source.diagnostics.num_integrated_diag_moments; assert(src->num_diag_int_mom < 2); // 1 int moment allowed now. if (src->evolve || src->num_diag_int_mom > 0) { - gk_species_moment_init(app, s, &src->integ_moms, - src->num_diag_int_mom == 0? GKYL_F_MOMENT_M0M1M2PARM2PERP : s->info.source.diagnostics.integrated_diag_moments[0], true); + gk_species_moment_init( + app, s, &src->integ_moms, + src->num_diag_int_mom == 0 ? GKYL_F_MOMENT_M0M1M2PARM2PERP : + s->info.source.diagnostics.integrated_diag_moments[0], + true + ); int num_mom = src->integ_moms.num_mom; if (app->use_gpu) { src->red_integ_diag = gkyl_cu_malloc(sizeof(double[num_mom])); src->red_integ_diag_global = gkyl_cu_malloc(sizeof(double[num_mom])); - } - else { + } else { src->red_integ_diag = gkyl_malloc(sizeof(double[num_mom])); src->red_integ_diag_global = gkyl_malloc(sizeof(double[num_mom])); } @@ -445,15 +518,14 @@ gk_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, src->integ_diag = gkyl_dynvec_new(GKYL_DOUBLE, num_mom); src->is_first_integ_write_call = true; } - + // Set function pointers chosen at runtime. if (src->evolve) { src->write_func = gk_species_source_write_enabled; src->write_mom_func = gk_species_source_write_mom_enabled; src->calc_integrated_mom_func = gk_species_source_calc_integrated_mom_enabled; src->write_integrated_mom_func = gk_species_source_write_integrated_mom_enabled; - } - else { + } else { src->write_func = gk_species_source_write_init_only; src->write_mom_func = gk_species_source_write_mom_init_only; if (src->num_diag_int_mom > 0) { @@ -468,12 +540,14 @@ gk_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, // Set up the adaptive source. src->num_adapt_sources = s->info.source.num_adapt_sources; - assert(src->num_adapt_sources <= src->num_sources); // Adaptive source should be a subset of the sources. - if (src->num_adapt_sources > 0){ + assert( + src->num_adapt_sources <= src->num_sources + ); // Adaptive source should be a subset of the sources. + if (src->num_adapt_sources > 0) { assert(s->info.vdim > 1); // MF 2025/10/24: hasn't been tested in 1v. src->adapt_func = gk_species_source_adapt_after_first_step; - if (src->num_diag_int_mom > 0){ + if (src->num_diag_int_mom > 0) { // Allocate dynvecs to store the temperature and particle count diagnostics of the adaptive sources. src->temp_diag = gkyl_dynvec_new(GKYL_DOUBLE, src->num_adapt_sources); src->part_diag = gkyl_dynvec_new(GKYL_DOUBLE, src->num_adapt_sources); @@ -489,36 +563,44 @@ gk_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, adapt_src->adapt_particle = s->info.source.adapt[k].adapt_particle; adapt_src->adapt_energy = s->info.source.adapt[k].adapt_energy; adapt_src->adapt_particle_fraction = s->info.source.adapt[k].has_adapt_particle_fraction ? - s->info.source.adapt[k].adapt_particle_fraction : 1.0; // Default to full adaptation if not specified. + s->info.source.adapt[k].adapt_particle_fraction : + 1.0; // Default to full adaptation if not specified. adapt_src->adapt_energy_fraction = s->info.source.adapt[k].has_adapt_energy_fraction ? - s->info.source.adapt[k].adapt_energy_fraction : 1.0; // Default to full adaptation if not specified. + s->info.source.adapt[k].adapt_energy_fraction : + 1.0; // Default to full adaptation if not specified. adapt_src->adapt_species = gk_find_species(app, s->info.source.adapt[k].adapt_to_species); assert(adapt_src->adapt_species != NULL); // Make sure the adaptive species is found. - adapt_src->adapt_species_idx = gk_find_species_idx(app, adapt_src->adapt_species->info.name); + adapt_src->adapt_species_idx = + gk_find_species_idx(app, adapt_src->adapt_species->info.name); adapt_src->particle_src_curr = s->info.source.projection[k].total_num_particles; adapt_src->energy_src_curr = s->info.source.projection[k].total_kin_energy; // The temperature computation makes sense only if we inject particles. - const double vdim_phys = s->info.vdim == 1? 1.0 : 3.0; - adapt_src->temperature_curr = s->info.source.projection[k].total_num_particles > 0? - (2./vdim_phys) * adapt_src->energy_src_curr/adapt_src->particle_src_curr : s->info.source.projection[k].temp_min; + const double vdim_phys = s->info.vdim == 1 ? 1.0 : 3.0; + adapt_src->temperature_curr = + s->info.source.projection[k].total_num_particles > 0 ? + (2. / vdim_phys) * adapt_src->energy_src_curr / adapt_src->particle_src_curr : + s->info.source.projection[k].temp_min; - gk_species_moment_init(app, adapt_src->adapt_species, &adapt_src->integ_threemoms, GKYL_F_MOMENT_M0M1M2, true); + gk_species_moment_init( + app, adapt_src->adapt_species, &adapt_src->integ_threemoms, GKYL_F_MOMENT_M0M1M2, true + ); // Initialize the infrastructure to compute integrated moments of the boundary fluxes. adapt_src->bflux_m0 = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); adapt_src->bflux_m2 = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - adapt_src->integrate_op = gkyl_array_integrate_new(&app->grid, &app->basis, 1, GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu); + adapt_src->integrate_op = gkyl_array_integrate_new( + &app->grid, &app->basis, 1, GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu + ); int num_mom = adapt_src->integ_threemoms.num_mom; - if (app->use_gpu){ + if (app->use_gpu) { adapt_src->red_integ_mom = gkyl_cu_malloc(sizeof(double[num_mom])); adapt_src->red_integ_mom_global = gkyl_cu_malloc(sizeof(double[num_mom])); adapt_src->integ_m0 = gkyl_cu_malloc(sizeof(double)); adapt_src->integ_m2 = gkyl_cu_malloc(sizeof(double)); - } - else { + } else { adapt_src->red_integ_mom = gkyl_malloc(sizeof(double[num_mom])); adapt_src->red_integ_mom_global = gkyl_malloc(sizeof(double[num_mom])); adapt_src->integ_m0 = gkyl_malloc(sizeof(double)); @@ -527,10 +609,10 @@ gk_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, adapt_src->num_boundaries = s->info.source.adapt[k].num_boundaries; bool is_dir_periodic[GKYL_MAX_CDIM] = {0}; - for (int j=0; j < app->num_periodic_dir; ++j) { + for (int j = 0; j < app->num_periodic_dir; ++j) { is_dir_periodic[app->periodic_dirs[j]] = true; } - for (int j=0; j < adapt_src->num_boundaries; ++j) { + for (int j = 0; j < adapt_src->num_boundaries; ++j) { int dir = s->info.source.adapt[k].dir[j]; int edge = s->info.source.adapt[k].edge[j]; @@ -539,25 +621,26 @@ gk_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, if (edge == GKYL_LOWER_EDGE) { assert(s->lower_bc[dir].type != GKYL_BC_GK_SPECIES_ZERO_FLUX); assert(s->lower_bc[dir].type != GKYL_BC_GK_SPECIES_REFLECT); - } else { + } else { assert(s->upper_bc[dir].type != GKYL_BC_GK_SPECIES_ZERO_FLUX); assert(s->upper_bc[dir].type != GKYL_BC_GK_SPECIES_REFLECT); } // Default scenario: we set the ranges to the full range of the ghost cells. - adapt_src->boundaries_phase_ghost[j] = edge == GKYL_LOWER_EDGE? s->local_lower_ghost[dir] - : s->local_upper_ghost[dir]; - adapt_src->boundaries_conf_ghost[j] = edge == GKYL_LOWER_EDGE? app->local_lower_ghost[dir] - : app->local_upper_ghost[dir]; - adapt_src->dir[j] = dir; + adapt_src->boundaries_phase_ghost[j] = + edge == GKYL_LOWER_EDGE ? s->local_lower_ghost[dir] : s->local_upper_ghost[dir]; + adapt_src->boundaries_conf_ghost[j] = + edge == GKYL_LOWER_EDGE ? app->local_lower_ghost[dir] : app->local_upper_ghost[dir]; + adapt_src->dir[j] = dir; adapt_src->edge[j] = edge; // Specific scenario if we are in a inner wall limited case. We select only SOL range in parallel direction. - if (dir == app->cdim-1 && app->gk_geom->has_LCFS) { - adapt_src->boundaries_phase_ghost[j] = edge == GKYL_LOWER_EDGE? s->local_lower_ghost_par_sol - : s->local_upper_ghost_par_sol; - adapt_src->boundaries_conf_ghost[j] = edge == GKYL_LOWER_EDGE? app->local_lower_ghost_par_sol - : app->local_upper_ghost_par_sol; + if (dir == app->cdim - 1 && app->gk_geom->has_LCFS) { + adapt_src->boundaries_phase_ghost[j] = + edge == GKYL_LOWER_EDGE ? s->local_lower_ghost_par_sol : s->local_upper_ghost_par_sol; + adapt_src->boundaries_conf_ghost[j] = edge == GKYL_LOWER_EDGE ? + app->local_lower_ghost_par_sol : + app->local_upper_ghost_par_sol; } } } @@ -565,11 +648,11 @@ gk_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, } } -void -gk_species_source_rhs(gkyl_gyrokinetic_app *app, const struct gk_species *s, - struct gk_source *src, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_species_source_rhs( + gkyl_gyrokinetic_app *app, const struct gk_species *s, struct gk_source *src, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { - struct timespec wst = gkyl_wall_clock(); if (src->source_id) { gkyl_array_accumulate(rhs, 1.0, src->source); @@ -577,66 +660,64 @@ gk_species_source_rhs(gkyl_gyrokinetic_app *app, const struct gk_species *s, app->stat.species_src_tm += gkyl_time_diff_now_sec(wst); } -void -gk_species_source_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_source_write(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame) { gks->src.write_func(app, gks, tm, frame); } -void -gk_species_source_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame) +void gk_species_source_write_mom( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +) { gks->src.write_mom_func(app, gks, tm, frame); } -void -gk_species_source_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm) +void gk_species_source_calc_integrated_mom( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm +) { gks->src.calc_integrated_mom_func(app, gks, tm); } -void -gk_species_source_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks) +void gk_species_source_write_integrated_mom(gkyl_gyrokinetic_app *app, struct gk_species *gks) { gks->src.write_integrated_mom_func(app, gks); } -void -gk_species_source_release(const struct gkyl_gyrokinetic_app *app, const struct gk_source *src) +void gk_species_source_release(const struct gkyl_gyrokinetic_app *app, const struct gk_source *src) { if (src->source_id) { gkyl_array_release(src->source); if (app->use_gpu) { gkyl_array_release(src->source_host); } - for (int k=0; knum_sources; k++) { + for (int k = 0; k < src->num_sources; k++) { gk_species_projection_release(app, &src->proj_source[k]); } // Release moment data. - for (int i=0; inum_diag_mom; ++i) { + for (int i = 0; i < src->num_diag_mom; ++i) { gk_species_moment_release(app, &src->moms[i]); } gkyl_free(src->moms); if (src->evolve || src->num_diag_int_mom > 0) { - gk_species_moment_release(app, &src->integ_moms); + gk_species_moment_release(app, &src->integ_moms); if (app->use_gpu) { gkyl_cu_free(src->red_integ_diag); gkyl_cu_free(src->red_integ_diag_global); - } - else { + } else { gkyl_free(src->red_integ_diag); gkyl_free(src->red_integ_diag_global); - } + } gkyl_dynvec_release(src->integ_diag); } if (src->num_adapt_sources > 0) { - if (src->num_diag_int_mom > 0){ + if (src->num_diag_int_mom > 0) { gkyl_dynvec_release(src->part_diag); gkyl_dynvec_release(src->temp_diag); } - for (int k=0; k < src->num_adapt_sources; ++k) { + for (int k = 0; k < src->num_adapt_sources; ++k) { const struct gk_adapt_source *adapt_src = &src->adapt[k]; gk_species_moment_release(app, &adapt_src->integ_threemoms); gkyl_array_integrate_release(adapt_src->integrate_op); @@ -647,8 +728,7 @@ gk_species_source_release(const struct gkyl_gyrokinetic_app *app, const struct g gkyl_cu_free(adapt_src->red_integ_mom_global); gkyl_cu_free(adapt_src->integ_m0); gkyl_cu_free(adapt_src->integ_m2); - } - else { + } else { gkyl_free(adapt_src->red_integ_mom); gkyl_free(adapt_src->red_integ_mom_global); gkyl_free(adapt_src->integ_m0); diff --git a/gyrokinetic/apps/gk_species_source_bgk.c b/gyrokinetic/apps/gk_species_source_bgk.c index 1c812a24aa..d80c219946 100644 --- a/gyrokinetic/apps/gk_species_source_bgk.c +++ b/gyrokinetic/apps/gk_species_source_bgk.c @@ -1,8 +1,7 @@ #include #include -static void -proj_on_basis_c2p_phase_func(const double *xcomp, double *xphys, void *ctx) +static void proj_on_basis_c2p_phase_func(const double *xcomp, double *xphys, void *ctx) { struct gk_proj_on_basis_c2p_func_ctx *c2p_ctx = ctx; int cdim = c2p_ctx->cdim; // Assumes update range is a phase range. @@ -10,30 +9,33 @@ proj_on_basis_c2p_phase_func(const double *xcomp, double *xphys, void *ctx) gkyl_velocity_map_eval_c2p(c2p_ctx->vel_map, &xcomp[cdim], &xphys[cdim]); } -static double -gk_species_source_bgk_volume_integrate(gkyl_gyrokinetic_app *app, struct gk_source_bgk *src, const struct gkyl_array *arrin) +static double gk_species_source_bgk_volume_integrate( + gkyl_gyrokinetic_app *app, struct gk_source_bgk *src, const struct gkyl_array *arrin +) { // Compute the volume integral of arrin. - gkyl_array_integrate_advance(src->vol_integ_op, arrin, 1.0, - 0, &app->local, 0, src->volint_local); + gkyl_array_integrate_advance(src->vol_integ_op, arrin, 1.0, 0, &app->local, 0, src->volint_local); gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, src->volint_local, src->volint_global); double volint_global = 0.0; - if (app->use_gpu) + if (app->use_gpu) { gkyl_cu_memcpy(&volint_global, src->volint_global, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(&volint_global, src->volint_global, sizeof(double)); + } return volint_global; } -static void -gk_species_source_bgk_rhs_disabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_source_bgk *src, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_species_source_bgk_rhs_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_source_bgk *src, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { } -static void -gk_species_source_bgk_rhs_feq_enabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_source_bgk *src, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_species_source_bgk_rhs_feq_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_source_bgk *src, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { // compute -nu * (f - feq) and add to the rhs. // Use f_lte to store Jrate*feq (coming from the projection done at initialization) @@ -41,8 +43,10 @@ gk_species_source_bgk_rhs_feq_enabled(gkyl_gyrokinetic_app *app, struct gk_speci gkyl_array_accumulate(species->lte.f_lte, 1.0, src->Jrate_df); // Compute Jrate_df gkyl_array_clear(src->Jrate_df, 0.0); - gkyl_bgk_collisions_advance(src->bgk_op, &app->local, &species->local, - src->rate, species->lte.f_lte, fin, src->implicit_step, src->dt_implicit, src->Jrate_df, species->cflrate); + gkyl_bgk_collisions_advance( + src->bgk_op, &app->local, &species->local, src->rate, species->lte.f_lte, fin, + src->implicit_step, src->dt_implicit, src->Jrate_df, species->cflrate + ); // Add to the rhs. gkyl_array_accumulate(rhs, 1.0, src->Jrate_df); // Compute integrated diagnostics if needed. @@ -52,96 +56,149 @@ gk_species_source_bgk_rhs_feq_enabled(gkyl_gyrokinetic_app *app, struct gk_speci gkyl_array_accumulate(src->Jrate_df, 1.0, species->lte.f_lte); } -static void -gk_species_source_bgk_rhs_heating_enabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_source_bgk *src, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_species_source_bgk_rhs_heating_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_source_bgk *src, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { - struct timespec wst = gkyl_wall_clock(); // Compute Maxwellian moments (n, u_par, T/m). gk_species_moment_calc(&species->lte.moms, species->local, app->local, fin); - gkyl_dg_div_op_range(species->lte.moms.mem_geo, &app->basis, 0, species->lte.moms.marr, - 0, species->lte.moms.marr, 0, app->gk_geom->geo_int.jacobgeo, &app->local); + gkyl_dg_div_op_range( + species->lte.moms.mem_geo, &app->basis, 0, species->lte.moms.marr, 0, species->lte.moms.marr, 0, + app->gk_geom->geo_int.jacobgeo, &app->local + ); // Volume integrate Jrate times the thermal M2. - gkyl_dg_mul_op_range(&app->basis, 0, src->Jrate_mom, 0, src->Jrate, 0, species->lte.moms.marr, &app->local); - gkyl_dg_mul_op_range(&app->basis, 0, src->Jrate_mom, 0, src->Jrate_mom, 2, species->lte.moms.marr, &app->local); - double Jrate_M2thermal_int = GKYL_MAX2(0.0, gk_species_source_bgk_volume_integrate(app, src, src->Jrate_mom)); + gkyl_dg_mul_op_range( + &app->basis, 0, src->Jrate_mom, 0, src->Jrate, 0, species->lte.moms.marr, &app->local + ); + gkyl_dg_mul_op_range( + &app->basis, 0, src->Jrate_mom, 0, src->Jrate_mom, 2, species->lte.moms.marr, &app->local + ); + double Jrate_M2thermal_int = + GKYL_MAX2(0.0, gk_species_source_bgk_volume_integrate(app, src, src->Jrate_mom)); // Volume integrate Jrate times the vtsq_shape time M0. - gkyl_dg_mul_op_range(&app->basis, 0, src->Jrate_mom, 0, src->Jrate_vtsq_shape, 0, species->lte.moms.marr, &app->local); - double Jrate_vtsq_shape_M0_int = GKYL_MAX2(0.0, gk_species_source_bgk_volume_integrate(app, src, src->Jrate_mom)); + gkyl_dg_mul_op_range( + &app->basis, 0, src->Jrate_mom, 0, src->Jrate_vtsq_shape, 0, species->lte.moms.marr, &app->local + ); + double Jrate_vtsq_shape_M0_int = + GKYL_MAX2(0.0, gk_species_source_bgk_volume_integrate(app, src, src->Jrate_mom)); // Thermal speed squared of the Maxwellian. - src->vtsq_amplitude = (src->norm_power + Jrate_M2thermal_int)/Jrate_vtsq_shape_M0_int; - gkyl_array_set_offset_range(species->lte.moms.marr, src->vtsq_amplitude, src->vtsq_shape, 2*app->basis.num_basis, &app->local); + src->vtsq_amplitude = (src->norm_power + Jrate_M2thermal_int) / Jrate_vtsq_shape_M0_int; + gkyl_array_set_offset_range( + species->lte.moms.marr, src->vtsq_amplitude, src->vtsq_shape, 2 * app->basis.num_basis, + &app->local + ); // Compute the Maxwellian (this overwrite f_lte). gk_species_lte_from_moms(app, species, &species->lte, species->lte.moms.marr); // Multiply the Maxwellian by Jrate and keep it in lte.f_lte - gkyl_dg_mul_conf_phase_op_range(&app->basis, &species->basis, species->lte.f_lte, - src->Jrate, species->lte.f_lte, &app->local, &species->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &species->basis, species->lte.f_lte, src->Jrate, species->lte.f_lte, &app->local, + &species->local + ); // Assemble the BGK-like term and add it to rhs. gkyl_array_clear(src->Jrate_df, 0.0); - gkyl_bgk_collisions_advance(src->bgk_op, &app->local, &species->local, - src->rate, species->lte.f_lte, fin, src->implicit_step, src->dt_implicit, src->Jrate_df, species->cflrate); + gkyl_bgk_collisions_advance( + src->bgk_op, &app->local, &species->local, src->rate, species->lte.f_lte, fin, + src->implicit_step, src->dt_implicit, src->Jrate_df, species->cflrate + ); gkyl_array_accumulate(rhs, 1.0, src->Jrate_df); app->stat.species_source_bgk_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_source_bgk_rhs_accumulate_maxwellian(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_source_bgk *src, const struct gkyl_array *fin, struct gkyl_array *out) +static void gk_species_source_bgk_rhs_accumulate_maxwellian( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_source_bgk *src, + const struct gkyl_array *fin, struct gkyl_array *out +) { struct timespec wst = gkyl_wall_clock(); // Compute Maxwellian moments (n, u_par, T/m). gk_species_moment_calc(&species->lte.moms, species->local, app->local, fin); - gk_species_moment_diag_jacobgeo_div(app, &species->lte.moms, species->lte.moms.marr, species->lte.moms.marr); + gk_species_moment_diag_jacobgeo_div( + app, &species->lte.moms, species->lte.moms.marr, species->lte.moms.marr + ); // Compute M0,M1,M2 gk_species_moment_calc(&src->correct_mom_op, species->local, app->local, fin); - gk_species_moment_diag_jacobgeo_div(app, &src->correct_mom_op, src->correct_mom_op.marr, src->correct_mom_op.marr); + gk_species_moment_diag_jacobgeo_div( + app, &src->correct_mom_op, src->correct_mom_op.marr, src->correct_mom_op.marr + ); // Set a minimum on the density //gkyl_array_set_offset(src->Jrate_cap, src->damping_factor, species->lte.moms.marr, 0*app->basis.num_basis); // Divide M0dot by the rate and add M0 - gkyl_dg_div_op_range(species->lte.moms.mem_geo, &app->basis, 0, src->Jrate_mom, 0, src->M0dot, 0, src->rate, &app->local); - gkyl_array_accumulate_offset(src->Jrate_mom, 1.0, species->lte.moms.marr, 0*app->basis.num_basis); + gkyl_dg_div_op_range( + species->lte.moms.mem_geo, &app->basis, 0, src->Jrate_mom, 0, src->M0dot, 0, src->rate, + &app->local + ); + gkyl_array_accumulate_offset( + src->Jrate_mom, 1.0, species->lte.moms.marr, 0 * app->basis.num_basis + ); // Set the density - gkyl_array_set_offset(species->lte.moms.marr, 1.0, src->Jrate_mom, 0*app->basis.num_basis); + gkyl_array_set_offset(species->lte.moms.marr, 1.0, src->Jrate_mom, 0 * app->basis.num_basis); // Now do momentum // Divide M1dot by the rate, add on M1, divide by density to get upar - gkyl_dg_div_op_range(species->lte.moms.mem_geo, &app->basis, 0, src->Jrate_mom, 0, src->M1dot, 0, src->rate, &app->local); - gkyl_array_accumulate_offset(src->Jrate_mom, 1.0, src->correct_mom_op.marr, 1*app->basis.num_basis); - gkyl_dg_div_op_range(species->lte.moms.mem_geo, &app->basis, 0, src->Jrate_mom, 0, src->Jrate_mom, 0, species->lte.moms.marr, &app->local); + gkyl_dg_div_op_range( + species->lte.moms.mem_geo, &app->basis, 0, src->Jrate_mom, 0, src->M1dot, 0, src->rate, + &app->local + ); + gkyl_array_accumulate_offset( + src->Jrate_mom, 1.0, src->correct_mom_op.marr, 1 * app->basis.num_basis + ); + gkyl_dg_div_op_range( + species->lte.moms.mem_geo, &app->basis, 0, src->Jrate_mom, 0, src->Jrate_mom, 0, + species->lte.moms.marr, &app->local + ); // Set the LTE moments for projection and project - gkyl_array_set_offset(species->lte.moms.marr, 1.0, src->Jrate_mom, 1*app->basis.num_basis); + gkyl_array_set_offset(species->lte.moms.marr, 1.0, src->Jrate_mom, 1 * app->basis.num_basis); // Now Do Energy // Set a minimum on vtsq so it doesn't go negative - gkyl_array_set_offset(src->Jrate_cap, src->damping_factor, species->lte.moms.marr, 2*app->basis.num_basis); + gkyl_array_set_offset( + src->Jrate_cap, src->damping_factor, species->lte.moms.marr, 2 * app->basis.num_basis + ); // T/m = M2dot/nu + M2 - n_s upar_s^2 - gkyl_dg_div_op_range(species->lte.moms.mem_geo, &app->basis, 0, src->Jrate_mom, 0, src->M2dot, 0, src->rate, &app->local); - gkyl_array_accumulate_offset(src->Jrate_mom, 1.0, src->correct_mom_op.marr, 2*app->basis.num_basis); - - gkyl_dg_mul_op_range(&app->basis, 1, src->correct_mom_op.marr, 1, species->lte.moms.marr, 1, species->lte.moms.marr, &app->local); - gkyl_dg_mul_op_range(&app->basis, 1, src->correct_mom_op.marr, 1, src->correct_mom_op.marr, 0, species->lte.moms.marr, &app->local); - - gkyl_array_accumulate_offset(src->Jrate_mom,-1.0, src->correct_mom_op.marr, 1*app->basis.num_basis); - - gkyl_array_scale(src->Jrate_mom, 1.0/3.0); - gkyl_dg_div_op_range(species->lte.moms.mem_geo, &app->basis, 0, src->Jrate_mom, 0, src->Jrate_mom, 0, species->lte.moms.marr, &app->local); + gkyl_dg_div_op_range( + species->lte.moms.mem_geo, &app->basis, 0, src->Jrate_mom, 0, src->M2dot, 0, src->rate, + &app->local + ); + gkyl_array_accumulate_offset( + src->Jrate_mom, 1.0, src->correct_mom_op.marr, 2 * app->basis.num_basis + ); + + gkyl_dg_mul_op_range( + &app->basis, 1, src->correct_mom_op.marr, 1, species->lte.moms.marr, 1, species->lte.moms.marr, + &app->local + ); + gkyl_dg_mul_op_range( + &app->basis, 1, src->correct_mom_op.marr, 1, src->correct_mom_op.marr, 0, + species->lte.moms.marr, &app->local + ); + + gkyl_array_accumulate_offset( + src->Jrate_mom, -1.0, src->correct_mom_op.marr, 1 * app->basis.num_basis + ); + + gkyl_array_scale(src->Jrate_mom, 1.0 / 3.0); + gkyl_dg_div_op_range( + species->lte.moms.mem_geo, &app->basis, 0, src->Jrate_mom, 0, src->Jrate_mom, 0, + species->lte.moms.marr, &app->local + ); // Apply the cap so we don't drive the temperature negative gkyl_array_max_by_cell_per_cell_avg_range(src->Jrate_mom, src->Jrate_cap, &app->local); // Set the temperature - gkyl_array_set_offset(species->lte.moms.marr, 1.0, src->Jrate_mom, 2*app->basis.num_basis); + gkyl_array_set_offset(species->lte.moms.marr, 1.0, src->Jrate_mom, 2 * app->basis.num_basis); // Project with LTE moments gk_species_lte_from_moms(app, species, &species->lte, species->lte.moms.marr); @@ -152,33 +209,38 @@ gk_species_source_bgk_rhs_accumulate_maxwellian(gkyl_gyrokinetic_app *app, struc app->stat.species_source_bgk_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_source_bgk_rhs_external_enabled(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_source_bgk *src, const struct gkyl_array *fin, struct gkyl_array *rhs) +static void gk_species_source_bgk_rhs_external_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_source_bgk *src, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { gkyl_array_clear(src->Jrate_df, 0.0); gk_species_source_bgk_rhs_accumulate_maxwellian(app, species, src, fin, src->Jrate_df); // Multiply the Maxwellian by Jrate. - gkyl_dg_mul_conf_phase_op_range(&app->basis, &species->basis, species->lte.f_lte, - src->Jrate, src->Jrate_df, &app->local, &species->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &species->basis, species->lte.f_lte, src->Jrate, src->Jrate_df, &app->local, + &species->local + ); // Assemble the BGK-like term and add it to Jrate_feq to conserve -nu*(f-feq) term for use in diagnostics. gkyl_array_clear(src->Jrate_df, 0.0); - gkyl_bgk_collisions_advance(src->bgk_op, &app->local, &species->local, src->rate, species->lte.f_lte, - fin, src->implicit_step, src->dt_implicit, src->Jrate_df, species->cflrate); + gkyl_bgk_collisions_advance( + src->bgk_op, &app->local, &species->local, src->rate, species->lte.f_lte, fin, + src->implicit_step, src->dt_implicit, src->Jrate_df, species->cflrate + ); gkyl_array_accumulate(rhs, 1.0, src->Jrate_df); } -static void -gk_species_source_bgk_write_diags_disabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, double tm, int frame) +static void gk_species_source_bgk_write_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm, int frame +) { } -static void -gk_species_source_bgk_write_diags_heating_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, double tm, int frame) +static void gk_species_source_bgk_write_diags_heating_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm, int frame +) { struct timespec wst = gkyl_wall_clock(); // Write the Maxwellian square thermal speed amplitude. @@ -189,45 +251,53 @@ gk_species_source_bgk_write_diags_heating_enabled(gkyl_gyrokinetic_app* app, str if (rank == 0) { const char *fmt = "%s-%s_source_bgk_vtsq_amplitude.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name); - + if (src->is_first_diag_dynvec_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Squared thermal speed amplitude." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Squared thermal speed amplitude."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(src->vtsq_amp_diag, fileNm, mt); src->is_first_diag_dynvec_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(src->vtsq_amp_diag, fileNm); } } gkyl_dynvec_clear(src->vtsq_amp_diag); app->stat.n_diag_io += 1; - + app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_source_bgk_write_diags_external_enabled(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, double tm, int frame) +static void gk_species_source_bgk_write_diags_external_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm, int frame +) { // Package metadata. gkyl_msgpack_map_elem_set_double(gks->io_meta_conf_len, gks->io_meta_conf, "time", tm); gkyl_msgpack_map_elem_set_uint(gks->io_meta_conf_len, gks->io_meta_conf, "frame", frame); struct gkyl_msgpack_map_elem desc_bgk_moms[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, - .cval = "BGK source particle (M0), momentum (M1) or kinetic energy (M2) source/sink rate." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "BGK source particle (M0), momentum (M1) or kinetic energy (M2) source/sink rate."} }; int io_meta_len[] = {gks->io_meta_conf_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_conf, app->gk_geom->io_meta_basic, desc_bgk_moms}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_conf, app->gk_geom->io_meta_basic, desc_bgk_moms + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); if (app->use_gpu) { gkyl_array_copy(src->M0dot_host, src->M0dot); @@ -245,74 +315,76 @@ gk_species_source_bgk_write_diags_external_enabled(gkyl_gyrokinetic_app* app, st gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, src->M2dot_host, fileNm.str); cstr_drop(&fileNm); - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); } -static void -gk_species_source_bgk_update_integrated_diags_disabled(gkyl_gyrokinetic_app* app, - struct gk_species *gks, struct gk_source_bgk *src, double tm) +static void gk_species_source_bgk_update_integrated_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm +) { // Do nothing. } -static void -gk_species_source_bgk_update_integrated_diags_enabled(gkyl_gyrokinetic_app* app, - struct gk_species *gks, struct gk_source_bgk *src, double tm) +static void gk_species_source_bgk_update_integrated_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm +) { struct timespec wst = gkyl_wall_clock(); int num_mom = src->integ_mom_op.num_mom; double avals_global[num_mom]; - + // Compute integrated moments of source term. - gk_species_moment_calc(&src->integ_mom_op, gks->local, app->local, src->Jrate_df); + gk_species_moment_calc(&src->integ_mom_op, gks->local, app->local, src->Jrate_df); app->stat.n_mom += 1; // Reduce (sum) over whole domain, append to diagnostics. gkyl_array_reduce_range(src->red_integ_diag, src->integ_mom_op.marr, GKYL_SUM, &app->local); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, - src->red_integ_diag, src->red_integ_diag_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, num_mom, src->red_integ_diag, src->red_integ_diag_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_global, src->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_global, src->red_integ_diag_global, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(avals_global, src->red_integ_diag_global, sizeof(double[num_mom])); } - for (int i=0; iint_mom_global[i] = avals_global[i]; } } -static void -gk_species_source_bgk_calc_integrated_diags_disabled(gkyl_gyrokinetic_app* app, - struct gk_species *gks, struct gk_source_bgk *src, double tm) +static void gk_species_source_bgk_calc_integrated_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm +) { // Do nothing. } -static void -gk_species_source_bgk_calc_integrated_diags_enabled(gkyl_gyrokinetic_app* app, - struct gk_species *gks, struct gk_source_bgk *src, double tm) +static void gk_species_source_bgk_calc_integrated_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm +) { struct timespec wst = gkyl_wall_clock(); src->update_integrated_diags_func(app, gks, src, tm); gkyl_dynvec_append(src->integ_diag, tm, src->int_mom_global); - + app->stat.species_diag_calc_tm += gkyl_time_diff_now_sec(wst); app->stat.n_diag += 1; } -static void -gk_species_source_bgk_write_integrated_diags_disabled(gkyl_gyrokinetic_app *app, - struct gk_species *gks, struct gk_source_bgk *src) +static void gk_species_source_bgk_write_integrated_diags_disabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src +) { // Empty. } -static void -gk_species_source_bgk_write_integrated_diags_enabled(gkyl_gyrokinetic_app *app, - struct gk_species *gks, struct gk_source_bgk *src) +static void gk_species_source_bgk_write_integrated_diags_enabled( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src +) { struct timespec wst = gkyl_wall_clock(); @@ -322,37 +394,46 @@ gk_species_source_bgk_write_integrated_diags_enabled(gkyl_gyrokinetic_app *app, if (rank == 0) { // Write integrated diagnostic moments. const char *fmt = "%s-%s_source_bgk_integrated_%s.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2]); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2]); + int sz = gkyl_calc_strlen( + fmt, app->name, gks->info.name, gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2] + ); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, gks->info.name, + gkyl_distribution_moments_strs[GKYL_F_MOMENT_M0M1M2] + ); if (src->is_first_diag_dynvec_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Volume integrated moment of the BGK source." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Volume integrated moment of the BGK source."} }; int io_meta_len[] = {gks->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + gks->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(src->integ_diag, fileNm, mt); src->is_first_diag_dynvec_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(src->integ_diag, fileNm); } } gkyl_dynvec_clear(src->integ_diag); app->stat.n_diag_io += 1; - + app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst); } -static void -gk_species_source_bgk_write_array(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, int frame, double stime, char* file_suffix, char* description, - struct gkyl_msgpack_map_elem *iom, int iom_len, struct gkyl_rect_grid grid, struct gkyl_range local, - struct gkyl_array *arrout) +static void gk_species_source_bgk_write_array( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, int frame, + double stime, char *file_suffix, char *description, struct gkyl_msgpack_map_elem *iom, + int iom_len, struct gkyl_rect_grid grid, struct gkyl_range local, struct gkyl_array *arrout +) { // Write out a conf-space or a phase-space array. @@ -360,40 +441,41 @@ gk_species_source_bgk_write_array(gkyl_gyrokinetic_app* app, struct gk_species * gkyl_msgpack_map_elem_set_double(iom_len, iom, "time", stime); gkyl_msgpack_map_elem_set_uint(iom_len, iom, "frame", frame); struct gkyl_msgpack_map_elem io_meta_f[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = description}, + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = description} }; - int io_meta_f_len = sizeof(io_meta_f)/sizeof(io_meta_f[0]); + int io_meta_f_len = sizeof(io_meta_f) / sizeof(io_meta_f[0]); int io_meta_len[] = {iom_len, app->gk_geom->io_meta_basic_len, io_meta_f_len}; - const struct gkyl_msgpack_map_elem* io_meta[] = {iom, app->gk_geom->io_meta_basic, io_meta_f}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = {iom, app->gk_geom->io_meta_basic, io_meta_f}; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); // Construct the file handles for collision frequency and primitive moments. const char *fmt = "%s-%s_%s_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, file_suffix, frame); - char fileNm[sz+1]; // Ensures no buffer overflow. + char fileNm[sz + 1]; // Ensures no buffer overflow. snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, file_suffix, frame); struct gkyl_array *arr_ho; - if (app->use_gpu) { + if (app->use_gpu) { arr_ho = mkarr(false, arrout->ncomp, arrout->size); // Copy data from device to host before writing it out. gkyl_array_copy(arr_ho, arrout); - } - else { + } else { arr_ho = gkyl_array_acquire(arrout); } gkyl_comm_array_write(app->comm, &grid, &local, mt, arr_ho, fileNm); - gkyl_msgpack_data_release(mt); + gkyl_msgpack_data_release(mt); gkyl_array_release(arr_ho); } -void -gk_species_source_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_source_bgk *src) +void gk_species_source_bgk_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src +) { src->source_bgk_id = src->source_bgk_id ? src->source_bgk_id : gks->info.source_bgk.source_bgk_id; - src->write_diagnostics = src->write_diagnostics ? src->write_diagnostics : gks->info.source_bgk.write_diagnostics; + src->write_diagnostics = src->write_diagnostics ? src->write_diagnostics : + gks->info.source_bgk.write_diagnostics; src->write_diags_func = gk_species_source_bgk_write_diags_disabled; src->rhs_func = gk_species_source_bgk_rhs_disabled; @@ -402,7 +484,7 @@ gk_species_source_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species * src->calc_integrated_diags_func = gk_species_source_bgk_calc_integrated_diags_disabled; src->write_integrated_diags_func = gk_species_source_bgk_write_integrated_diags_disabled; - if (src->source_bgk_id){ + if (src->source_bgk_id) { // Collision rate src->rate = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); // Jacobian times the collision rate. @@ -422,8 +504,7 @@ gk_species_source_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species * if (app->use_gpu) { src->red_integ_diag = gkyl_cu_malloc(sizeof(double[src->integ_mom_op.num_mom])); src->red_integ_diag_global = gkyl_cu_malloc(sizeof(double[src->integ_mom_op.num_mom])); - } - else { + } else { src->red_integ_diag = gkyl_malloc(sizeof(double[src->integ_mom_op.num_mom])); src->red_integ_diag_global = gkyl_malloc(sizeof(double[src->integ_mom_op.num_mom])); } @@ -434,39 +515,43 @@ gk_species_source_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species * if (src->source_bgk_id == GKYL_SOURCE_BGK_STATIC) { // source_bgk rate. - struct gkyl_array *rate_host = app->use_gpu? mkarr(false, src->rate->ncomp, src->rate->size) - : gkyl_array_acquire(src->rate); - gkyl_proj_on_basis *proj_rate = gkyl_proj_on_basis_new(&app->grid, &app->basis, - app->poly_order+1, 1, gks->info.source_bgk.rate_profile, gks->info.source_bgk.rate_profile_ctx); + struct gkyl_array *rate_host = app->use_gpu ? + mkarr(false, src->rate->ncomp, src->rate->size) : + gkyl_array_acquire(src->rate); + gkyl_proj_on_basis *proj_rate = gkyl_proj_on_basis_new( + &app->grid, &app->basis, app->poly_order + 1, 1, gks->info.source_bgk.rate_profile, + gks->info.source_bgk.rate_profile_ctx + ); gkyl_proj_on_basis_advance(proj_rate, 0.0, &app->local, rate_host); gkyl_array_copy(src->rate, rate_host); gkyl_proj_on_basis_release(proj_rate); gkyl_array_release(rate_host); // Multiply the rate by the conf-space Jacobian. - gkyl_dg_mul_op_range(&app->basis, 0, src->Jrate, 0, app->gk_geom->geo_int.jacobgeo, 0, src->rate, &app->local); + gkyl_dg_mul_op_range( + &app->basis, 0, src->Jrate, 0, app->gk_geom->geo_int.jacobgeo, 0, src->rate, &app->local + ); // Project the user provided function (we use here Jrate_df as a temporary array). - struct gkyl_array *Jrate_fmax_host = app->use_gpu? mkarr(false, src->Jrate_df->ncomp, src->Jrate_df->size) - : gkyl_array_acquire(src->Jrate_df); + struct gkyl_array *Jrate_fmax_host = + app->use_gpu ? mkarr(false, src->Jrate_df->ncomp, src->Jrate_df->size) : + gkyl_array_acquire(src->Jrate_df); struct gk_proj_on_basis_c2p_func_ctx proj_feq_shape_c2p_ctx = { .cdim = app->cdim, .vdim = gks->local_vel.ndim, .vel_map = gks->vel_map, - .pos_map = app->position_map, + .pos_map = app->position_map }; - gkyl_proj_on_basis *proj_feq_shape = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp) { - .grid = &gks->grid, - .basis = &gks->basis, - .qtype = GKYL_GAUSS_QUAD, - .num_quad = gks->basis.poly_order+1, - .num_ret_vals = 1, - .eval = gks->info.source_bgk.feq_shape, - .ctx = gks->info.source_bgk.feq_shape_ctx, - .c2p_func = proj_on_basis_c2p_phase_func, - .c2p_func_ctx = &proj_feq_shape_c2p_ctx, - } - ); + gkyl_proj_on_basis *proj_feq_shape = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &gks->grid, + .basis = &gks->basis, + .qtype = GKYL_GAUSS_QUAD, + .num_quad = gks->basis.poly_order + 1, + .num_ret_vals = 1, + .eval = gks->info.source_bgk.feq_shape, + .ctx = gks->info.source_bgk.feq_shape_ctx, + .c2p_func = proj_on_basis_c2p_phase_func, + .c2p_func_ctx = &proj_feq_shape_c2p_ctx}); gkyl_proj_on_basis_advance(proj_feq_shape, 0.0, &gks->local, Jrate_fmax_host); gkyl_array_copy(src->Jrate_df, Jrate_fmax_host); gkyl_proj_on_basis_release(proj_feq_shape); @@ -474,52 +559,70 @@ gk_species_source_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species * // Multiply feq by the same Jacobians as the distribution function. // (Similar to gk_species_projection_calc.) - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gks->basis, src->Jrate_df, - app->gk_geom->geo_corn.bmag, src->Jrate_df, &app->local, &gks->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gks->basis, src->Jrate_df, app->gk_geom->geo_corn.bmag, src->Jrate_df, + &app->local, &gks->local + ); gkyl_array_scale_by_cell(src->Jrate_df, gks->vel_map->jacobvel); - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gks->basis, src->Jrate_df, - app->gk_geom->geo_int.jacobgeo, src->Jrate_df, &app->local, &gks->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gks->basis, src->Jrate_df, app->gk_geom->geo_int.jacobgeo, src->Jrate_df, + &app->local, &gks->local + ); // Methods chosen at runtime. src->rhs_func = gk_species_source_bgk_rhs_feq_enabled; if (src->write_diagnostics) { // Replace the update int. diags func. with the one that is called within the RHS. src->update_integrated_diags_func = gk_species_source_bgk_update_integrated_diags_disabled; - src->update_integrated_diags_rhs_func = gk_species_source_bgk_update_integrated_diags_enabled; - gk_species_source_bgk_write_array(app, gks, src, 0, 0.0, "source_bgk_rate", "BGK source relaxation rate.", - gks->io_meta_conf, gks->io_meta_conf_len, app->grid, app->local, src->rate); - gk_species_source_bgk_write_array(app, gks, src, 0, 0.0, "source_bgk_feq", "BGK source equilibrium function.", - gks->io_meta_phase, gks->io_meta_phase_len, gks->grid, gks->local, src->Jrate_df); + src->update_integrated_diags_rhs_func = + gk_species_source_bgk_update_integrated_diags_enabled; + gk_species_source_bgk_write_array( + app, gks, src, 0, 0.0, "source_bgk_rate", "BGK source relaxation rate.", + gks->io_meta_conf, gks->io_meta_conf_len, app->grid, app->local, src->rate + ); + gk_species_source_bgk_write_array( + app, gks, src, 0, 0.0, "source_bgk_feq", "BGK source equilibrium function.", + gks->io_meta_phase, gks->io_meta_phase_len, gks->grid, gks->local, src->Jrate_df + ); } // Multiply feq by the rate to get Jrate_df = nu*feq. - gkyl_dg_mul_conf_phase_op_range(&app->basis, &gks->basis, src->Jrate_df, - src->rate, src->Jrate_df, &app->local, &gks->local); + gkyl_dg_mul_conf_phase_op_range( + &app->basis, &gks->basis, src->Jrate_df, src->rate, src->Jrate_df, &app->local, &gks->local + ); } if (src->source_bgk_id == GKYL_SOURCE_BGK_HEATING) { - int vdim_phys = gks->info.vdim == 1? 1 : 3; - src->norm_power = 2.0*gks->info.source_bgk.power/(vdim_phys*gks->info.mass); + int vdim_phys = gks->info.vdim == 1 ? 1 : 3; + src->norm_power = 2.0 * gks->info.source_bgk.power / (vdim_phys * gks->info.mass); // source_bgk rate. - struct gkyl_array *rate_host = app->use_gpu? mkarr(false, src->rate->ncomp, src->rate->size) - : gkyl_array_acquire(src->rate); - gkyl_proj_on_basis *proj_rate = gkyl_proj_on_basis_new(&app->grid, &app->basis, - app->poly_order+1, 1, gks->info.source_bgk.rate_profile, gks->info.source_bgk.rate_profile_ctx); + struct gkyl_array *rate_host = app->use_gpu ? + mkarr(false, src->rate->ncomp, src->rate->size) : + gkyl_array_acquire(src->rate); + gkyl_proj_on_basis *proj_rate = gkyl_proj_on_basis_new( + &app->grid, &app->basis, app->poly_order + 1, 1, gks->info.source_bgk.rate_profile, + gks->info.source_bgk.rate_profile_ctx + ); gkyl_proj_on_basis_advance(proj_rate, 0.0, &app->local, rate_host); gkyl_array_copy(src->rate, rate_host); gkyl_proj_on_basis_release(proj_rate); gkyl_array_release(rate_host); // Multiply the rate by the conf-space Jacobian. - gkyl_dg_mul_op_range(&app->basis, 0, src->Jrate, 0, app->gk_geom->geo_int.jacobgeo, 0, src->rate, &app->local); + gkyl_dg_mul_op_range( + &app->basis, 0, src->Jrate, 0, app->gk_geom->geo_int.jacobgeo, 0, src->rate, &app->local + ); // source_bgk rate. src->vtsq_shape = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - struct gkyl_array *vtsq_shape_host = app->use_gpu? mkarr(false, src->vtsq_shape->ncomp, src->vtsq_shape->size) - : gkyl_array_acquire(src->vtsq_shape); - gkyl_proj_on_basis *proj_vtsq_shape = gkyl_proj_on_basis_new(&app->grid, &app->basis, - app->poly_order+1, 1, gks->info.source_bgk.temp_shape, gks->info.source_bgk.temp_shape_ctx); + struct gkyl_array *vtsq_shape_host = + app->use_gpu ? mkarr(false, src->vtsq_shape->ncomp, src->vtsq_shape->size) : + gkyl_array_acquire(src->vtsq_shape); + gkyl_proj_on_basis *proj_vtsq_shape = gkyl_proj_on_basis_new( + &app->grid, &app->basis, app->poly_order + 1, 1, gks->info.source_bgk.temp_shape, + gks->info.source_bgk.temp_shape_ctx + ); gkyl_proj_on_basis_advance(proj_vtsq_shape, 0.0, &app->local, vtsq_shape_host); gkyl_array_copy(src->vtsq_shape, vtsq_shape_host); gkyl_proj_on_basis_release(proj_vtsq_shape); @@ -527,18 +630,21 @@ gk_species_source_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species * // Multiply Jrate by the shape of v_t^2. src->Jrate_vtsq_shape = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - gkyl_dg_mul_op_range(&app->basis, 0, src->Jrate_vtsq_shape, 0, src->Jrate, 0, src->vtsq_shape, &app->local); + gkyl_dg_mul_op_range( + &app->basis, 0, src->Jrate_vtsq_shape, 0, src->Jrate, 0, src->vtsq_shape, &app->local + ); // Rate times a velocity moment. src->Jrate_mom = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); // Volume integrator. - src->vol_integ_op = gkyl_array_integrate_new(&app->grid, &app->basis, 1, GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu); + src->vol_integ_op = gkyl_array_integrate_new( + &app->grid, &app->basis, 1, GKYL_ARRAY_INTEGRATE_OP_NONE, app->use_gpu + ); if (app->use_gpu) { src->volint_local = gkyl_cu_malloc(sizeof(double)); src->volint_global = gkyl_cu_malloc(sizeof(double)); - } - else { + } else { src->volint_local = gkyl_malloc(sizeof(double)); src->volint_global = gkyl_malloc(sizeof(double)); } @@ -546,10 +652,14 @@ gk_species_source_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species * if (src->write_diagnostics) { src->vtsq_amp_diag = gkyl_dynvec_new(GKYL_DOUBLE, 1); // Write out the source_bgk rate and vtsq shape. - gk_species_source_bgk_write_array(app, gks, src, 0, 0.0, "source_bgk_rate", "BGK source relaxation rate.", - gks->io_meta_conf, gks->io_meta_conf_len, app->grid, app->local, src->rate); - gk_species_source_bgk_write_array(app, gks, src, 0, 0.0, "source_bgk_temp_shape", "BGK source temperature shape.", - gks->io_meta_conf, gks->io_meta_conf_len, app->grid, app->local, src->vtsq_shape); + gk_species_source_bgk_write_array( + app, gks, src, 0, 0.0, "source_bgk_rate", "BGK source relaxation rate.", + gks->io_meta_conf, gks->io_meta_conf_len, app->grid, app->local, src->rate + ); + gk_species_source_bgk_write_array( + app, gks, src, 0, 0.0, "source_bgk_temp_shape", "BGK source temperature shape.", + gks->io_meta_conf, gks->io_meta_conf_len, app->grid, app->local, src->vtsq_shape + ); } // Methods chosen at runtime. @@ -561,21 +671,26 @@ gk_species_source_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species * if (src->source_bgk_id == GKYL_SOURCE_BGK_EXTERNAL) { // source_bgk rate. - gkyl_array_shiftc(src->rate, pow(sqrt(2.0),app->cdim)/src->injection_time, 0); // Sets rate = 1/injection_time + gkyl_array_shiftc( + src->rate, pow(sqrt(2.0), app->cdim) / src->injection_time, + 0 + ); // Sets rate = 1/injection_time // Multiply the rate by the conf-space Jacobian. - gkyl_dg_mul_op_range(&app->basis, 0, src->Jrate, 0, app->gk_geom->geo_int.jacobgeo, 0, src->rate, &app->local); + gkyl_dg_mul_op_range( + &app->basis, 0, src->Jrate, 0, app->gk_geom->geo_int.jacobgeo, 0, src->rate, &app->local + ); // External source rates src->M0dot = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); src->M1dot = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); src->M2dot = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - src->M0dot_host = src->M0dot; - src->M1dot_host = src->M1dot; - src->M2dot_host = src->M2dot; + src->M0dot_host = src->M0dot; + src->M1dot_host = src->M1dot; + src->M2dot_host = src->M2dot; - if(app->use_gpu) { + if (app->use_gpu) { src->M0dot_host = mkarr(false, app->basis.num_basis, app->local_ext.volume); src->M1dot_host = mkarr(false, app->basis.num_basis, app->local_ext.volume); src->M2dot_host = mkarr(false, app->basis.num_basis, app->local_ext.volume); @@ -597,36 +712,38 @@ gk_species_source_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species * } } -void -gk_species_source_bgk_rhs(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_source_bgk *src, const struct gkyl_array *fin, struct gkyl_array *rhs) +void gk_species_source_bgk_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_source_bgk *src, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { src->rhs_func(app, species, src, fin, rhs); } -void -gk_species_source_bgk_write_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, double tm, int frame) +void gk_species_source_bgk_write_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm, int frame +) { src->write_diags_func(app, gks, src, tm, frame); } -void -gk_species_source_bgk_calc_integrated_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, double tm) +void gk_species_source_bgk_calc_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm +) { src->calc_integrated_diags_func(app, gks, src, tm); } -void -gk_species_source_bgk_write_integrated_diags(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_source_bgk *src) +void gk_species_source_bgk_write_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src +) { src->write_integrated_diags_func(app, gks, src); } -void -gk_species_source_bgk_release(const struct gkyl_gyrokinetic_app *app, const struct gk_source_bgk *src) +void gk_species_source_bgk_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_source_bgk *src +) { if (src->source_bgk_id) { gkyl_array_release(src->rate); @@ -635,13 +752,12 @@ gk_species_source_bgk_release(const struct gkyl_gyrokinetic_app *app, const stru gkyl_bgk_collisions_release(src->bgk_op); if (src->write_diagnostics) { - gk_species_moment_release(app, &src->integ_mom_op); + gk_species_moment_release(app, &src->integ_mom_op); gkyl_dynvec_release(src->integ_diag); if (app->use_gpu) { gkyl_cu_free(src->red_integ_diag); gkyl_cu_free(src->red_integ_diag_global); - } - else { + } else { gkyl_free(src->red_integ_diag); gkyl_free(src->red_integ_diag_global); } @@ -657,8 +773,7 @@ gk_species_source_bgk_release(const struct gkyl_gyrokinetic_app *app, const stru if (app->use_gpu) { gkyl_cu_free(src->volint_local); gkyl_cu_free(src->volint_global); - } - else { + } else { gkyl_free(src->volint_local); gkyl_free(src->volint_global); } @@ -666,8 +781,7 @@ gk_species_source_bgk_release(const struct gkyl_gyrokinetic_app *app, const stru if (src->write_diagnostics) { gkyl_dynvec_release(src->vtsq_amp_diag); } - } - else if (src->source_bgk_id == GKYL_SOURCE_BGK_EXTERNAL) { + } else if (src->source_bgk_id == GKYL_SOURCE_BGK_EXTERNAL) { gkyl_array_release(src->Jrate_mom); gkyl_array_release(src->Jrate_cap); @@ -680,7 +794,7 @@ gk_species_source_bgk_release(const struct gkyl_gyrokinetic_app *app, const stru gkyl_array_release(src->M2dot_host); } - gk_species_moment_release(app, &src->correct_mom_op); + gk_species_moment_release(app, &src->correct_mom_op); } } } diff --git a/gyrokinetic/apps/gkyl_gk_block_geom.h b/gyrokinetic/apps/gkyl_gk_block_geom.h index 168a9a9993..aadd94f512 100644 --- a/gyrokinetic/apps/gkyl_gk_block_geom.h +++ b/gyrokinetic/apps/gkyl_gk_block_geom.h @@ -9,7 +9,7 @@ struct gkyl_gk_block_geom_info { // lower and upper extents of blocks double lower[GKYL_MAX_CDIM], upper[GKYL_MAX_CDIM]; int cells[GKYL_MAX_CDIM]; // cells extents in each direction - int cuts[GKYL_MAX_CDIM]; // domain split to use + int cuts[GKYL_MAX_CDIM]; // domain split to use struct gkyl_gyrokinetic_geometry geometry; // GK geometry @@ -52,7 +52,7 @@ int gkyl_gk_block_geom_num_blocks(const struct gkyl_gk_block_geom *bgeom); * @param bgeom Block geometry to which reference is required * @return Pointer to acquired block-topo */ -struct gkyl_gk_block_geom* gkyl_gk_block_geom_acquire(const struct gkyl_gk_block_geom *bgeom); +struct gkyl_gk_block_geom *gkyl_gk_block_geom_acquire(const struct gkyl_gk_block_geom *bgeom); /** * Acquire a pointer to the block topology. The caller must release @@ -61,7 +61,7 @@ struct gkyl_gk_block_geom* gkyl_gk_block_geom_acquire(const struct gkyl_gk_block * @param bgeom Geometry object from which to fetch topology * @return topology object */ -struct gkyl_block_topo* gkyl_gk_block_geom_topo(const struct gkyl_gk_block_geom *bgeom); +struct gkyl_block_topo *gkyl_gk_block_geom_topo(const struct gkyl_gk_block_geom *bgeom); /** * Set geometry and connectivity information about a block. @@ -71,9 +71,9 @@ struct gkyl_block_topo* gkyl_gk_block_geom_topo(const struct gkyl_gk_block_geom * @param info Geometry info for block @a bidx * */ -void gkyl_gk_block_geom_set_block(struct gkyl_gk_block_geom *bgeom, int bidx, - const struct gkyl_gk_block_geom_info *info); - +void gkyl_gk_block_geom_set_block( + struct gkyl_gk_block_geom *bgeom, int bidx, const struct gkyl_gk_block_geom_info *info +); /** * Reset grid extents for block geometry info @@ -83,9 +83,9 @@ void gkyl_gk_block_geom_set_block(struct gkyl_gk_block_geom *bgeom, int bidx, * @param lower Lower extents * @param upper Upper extents */ -void -gkyl_gk_block_geom_reset_block_extents(struct gkyl_gk_block_geom *bgeom, int bidx, - double *lower, double *upper); +void gkyl_gk_block_geom_reset_block_extents( + struct gkyl_gk_block_geom *bgeom, int bidx, double *lower, double *upper +); /** * Get geometry and connectivity information about a block. @@ -95,9 +95,9 @@ gkyl_gk_block_geom_reset_block_extents(struct gkyl_gk_block_geom *bgeom, int bid * @return Geometry info for block @a bidx * */ -const struct gkyl_gk_block_geom_info *gkyl_gk_block_geom_get_block( - const struct gkyl_gk_block_geom *bgeom, int bidx); - +const struct gkyl_gk_block_geom_info * +gkyl_gk_block_geom_get_block(const struct gkyl_gk_block_geom *bgeom, int bidx); + /** * Check consistency of block geometry: the geometry typically has * redundant data in it. This method ensures the redundant data is @@ -114,4 +114,4 @@ int gkyl_gk_block_geom_check_consistency(const struct gkyl_gk_block_geom *bgeom) * * @return Block geometry to free */ -void gkyl_gk_block_geom_release(struct gkyl_gk_block_geom* bgeom); +void gkyl_gk_block_geom_release(struct gkyl_gk_block_geom *bgeom); diff --git a/gyrokinetic/apps/gkyl_gk_field_priv.h b/gyrokinetic/apps/gkyl_gk_field_priv.h index da502d8cd9..05766edcab 100644 --- a/gyrokinetic/apps/gkyl_gk_field_priv.h +++ b/gyrokinetic/apps/gkyl_gk_field_priv.h @@ -22,8 +22,7 @@ * @param app Gyrokinetic application object. * @param f Field object to initialize. */ -void -gk_field_fem_new_boltzmann(struct gkyl_gyrokinetic_app *app, struct gk_field *f); +void gk_field_fem_new_boltzmann(struct gkyl_gyrokinetic_app *app, struct gk_field *f); /** * Initialize the FEM object for 1D (1x) field solves. @@ -32,8 +31,7 @@ gk_field_fem_new_boltzmann(struct gkyl_gyrokinetic_app *app, struct gk_field *f) * @param app Gyrokinetic application object. * @param f Field object to initialize. */ -void -gk_field_fem_new_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *f); +void gk_field_fem_new_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *f); /** * Initialize the FEM object for 2D or 3D (2x/3x) field solves. @@ -42,8 +40,7 @@ gk_field_fem_new_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *f); * @param app Gyrokinetic application object. * @param f Field object to initialize. */ -void -gk_field_fem_new_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field *f); +void gk_field_fem_new_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field *f); /** FEM Projection Functions **/ @@ -57,9 +54,10 @@ gk_field_fem_new_2x3x(struct gkyl_gyrokinetic_app *app, struct gk_field *f); * @param arr_dg Input DG array to be projected. * @param arr_fem Output FEM array (projected result with parallel continuity). */ -void -gk_field_fem_projection_par(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gkyl_array *arr_dg, struct gkyl_array *arr_fem); +void gk_field_fem_projection_par( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *arr_dg, + struct gkyl_array *arr_fem +); /** Charge Density Accumulation Functions **/ @@ -73,9 +71,9 @@ gk_field_fem_projection_par(gkyl_gyrokinetic_app *app, struct gk_field *field, * @param s Species object providing density moments. * @param bflux Boundary flux array (for boundary contributions). */ -void -gk_field_accumulate_rho_c_adiabatic(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gk_species *s, struct gkyl_array **bflux); +void gk_field_accumulate_rho_c_adiabatic( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gk_species *s, struct gkyl_array **bflux +); /** * Accumulate charge density for a full Poisson solve. @@ -87,9 +85,9 @@ gk_field_accumulate_rho_c_adiabatic(gkyl_gyrokinetic_app *app, struct gk_field * * @param s Species object providing density moments. * @param bflux Boundary flux array (for boundary contributions). */ -void -gk_field_accumulate_rho_c_poisson(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gk_species *s, struct gkyl_array **bflux); +void gk_field_accumulate_rho_c_poisson( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gk_species *s, struct gkyl_array **bflux +); /** * No-op function for parallel boundary conditions (disabled variant). @@ -99,9 +97,9 @@ gk_field_accumulate_rho_c_poisson(gkyl_gyrokinetic_app *app, struct gk_field *fi * @param field Field object. * @param finout Array (unchanged). */ -void -gk_field_enforce_parallel_bc_disabled(const gkyl_gyrokinetic_app *app, - struct gk_field *field, struct gkyl_array *finout); +void gk_field_enforce_parallel_bc_disabled( + const gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *finout +); /** Finite Larmor Radius (FLR) Correction Functions **/ @@ -112,8 +110,7 @@ gk_field_enforce_parallel_bc_disabled(const gkyl_gyrokinetic_app *app, * @param app Gyrokinetic application object. * @param f Field object to initialize FLR corrections for. */ -void -gk_field_flr_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f); +void gk_field_flr_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f); /** * Release FLR correction resources. @@ -121,8 +118,7 @@ gk_field_flr_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f); * @param app Gyrokinetic application object. * @param f Field object whose FLR resources are to be released. */ -void -gk_field_flr_release(const struct gkyl_gyrokinetic_app *app, struct gk_field *f); +void gk_field_flr_release(const struct gkyl_gyrokinetic_app *app, struct gk_field *f); /** * Apply FLR inversion to obtain the gyroaveraged potential. @@ -132,9 +128,7 @@ gk_field_flr_release(const struct gkyl_gyrokinetic_app *app, struct gk_field *f) * @param field Field object containing solver state. * @param phi Electrostatic potential array (input/output). */ -void -gk_field_invert_flr(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gkyl_array *phi); +void gk_field_invert_flr(gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *phi); /** * No-op function for FLR inversion (when FLR corrections are disabled). @@ -144,9 +138,9 @@ gk_field_invert_flr(gkyl_gyrokinetic_app *app, struct gk_field *field, * @param field Field object. * @param phi Electrostatic potential array (unchanged). */ -void -gk_field_invert_flr_none(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gkyl_array *phi); +void gk_field_invert_flr_none( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *phi +); /** Biased Wall Functions **/ @@ -157,8 +151,7 @@ gk_field_invert_flr_none(gkyl_gyrokinetic_app *app, struct gk_field *field, * @param app Gyrokinetic application object. * @param f Field object to initialize biased wall for. */ -void -gk_field_biased_wall_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f); +void gk_field_biased_wall_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f); /** * Release biased wall resources. @@ -166,8 +159,7 @@ gk_field_biased_wall_new(struct gkyl_gyrokinetic_app *app, struct gk_field *f); * @param app Gyrokinetic application object. * @param f Field object whose biased wall resources are to be released. */ -void -gk_field_biased_wall_release(const struct gkyl_gyrokinetic_app *app, struct gk_field *f); +void gk_field_biased_wall_release(const struct gkyl_gyrokinetic_app *app, struct gk_field *f); /** * Calculate and apply the wall potential at the current simulation time. @@ -177,5 +169,4 @@ gk_field_biased_wall_release(const struct gkyl_gyrokinetic_app *app, struct gk_f * @param field Field object containing the potential. * @param tm Current simulation time. */ -void -gk_field_calc_phi_wall(gkyl_gyrokinetic_app *app, struct gk_field *field, double tm); +void gk_field_calc_phi_wall(gkyl_gyrokinetic_app *app, struct gk_field *field, double tm); diff --git a/gyrokinetic/apps/gkyl_gk_neut_species_priv.h b/gyrokinetic/apps/gkyl_gk_neut_species_priv.h index 12b411b0b1..5400fa73e4 100644 --- a/gyrokinetic/apps/gkyl_gk_neut_species_priv.h +++ b/gyrokinetic/apps/gkyl_gk_neut_species_priv.h @@ -22,9 +22,10 @@ * @param gk Input parameters from input files. * @param app Gyrokinetic app. * @param ns Neutral species to initialize. - */ -void -gk_neut_species_fluid_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns); + */ +void gk_neut_species_fluid_init( + struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns +); /** * Initialize kinetic neutral species. @@ -32,9 +33,10 @@ gk_neut_species_fluid_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, * @param gk Input parameters from input files. * @param app Gyrokinetic app. * @param ns Neutral species to initialize. - */ -void -gk_neut_species_kinetic_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns); + */ +void gk_neut_species_kinetic_init( + struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns +); /** * @@ -42,79 +44,90 @@ gk_neut_species_kinetic_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *ap * */ -double -gk_neut_species_rhs_static(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms); - -double -gk_neut_species_rhs_implicit_static(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt); +double gk_neut_species_rhs_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms +); -void -gk_neut_species_apply_bc_static(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gkyl_array *f); +double gk_neut_species_rhs_implicit_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt +); -void -gk_neut_species_step_f_dynamic(struct gkyl_array* out, double dt, - const struct gkyl_array* inp); +void gk_neut_species_apply_bc_static( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gkyl_array *f +); -void -gk_neut_species_step_f_static(struct gkyl_array* out, double dt, - const struct gkyl_array* inp); +void gk_neut_species_step_f_dynamic(struct gkyl_array *out, double dt, const struct gkyl_array *inp); -void -gk_neut_species_combine_dynamic(struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng); +void gk_neut_species_step_f_static(struct gkyl_array *out, double dt, const struct gkyl_array *inp); -void -gk_neut_species_combine_static(struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng); +void gk_neut_species_combine_dynamic( + struct gkyl_array *out, double c1, const struct gkyl_array *arr1, double c2, + const struct gkyl_array *arr2, const struct gkyl_range *rng +); -void -gk_neut_species_copy_range_dynamic(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range); +void gk_neut_species_combine_static( + struct gkyl_array *out, double c1, const struct gkyl_array *arr1, double c2, + const struct gkyl_array *arr2, const struct gkyl_range *rng +); -void -gk_neut_species_copy_range_static(struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range); +void gk_neut_species_copy_range_dynamic( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +); -void -gk_neut_species_write_dynamic(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); +void gk_neut_species_copy_range_static( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range +); -void -gk_neut_species_write_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); +void gk_neut_species_write_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +); -void -gk_neut_species_calc_integrated_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm); +void gk_neut_species_write_mom_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +); -void -gk_neut_species_write_integrated_mom_dynamic(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns); +void gk_neut_species_calc_integrated_mom_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm +); -void -gk_neut_species_write_static(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); +void gk_neut_species_write_integrated_mom_dynamic( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns +); -void -gk_neut_species_write_init_only(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); +void gk_neut_species_write_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +); -void -gk_neut_species_write_mom_static(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); +void gk_neut_species_write_init_only( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +); -void -gk_neut_species_write_mom_init_only(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); +void gk_neut_species_write_mom_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +); -void -gk_neut_species_calc_integrated_mom_static(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm); +void gk_neut_species_write_mom_init_only( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +); -void -gk_neut_species_write_integrated_mom_static(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns); +void gk_neut_species_calc_integrated_mom_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm +); -void -gk_neut_species_n_iter_corr_enabled(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx); +void gk_neut_species_write_integrated_mom_static( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns +); -void -gk_neut_species_n_iter_corr_disabled(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx); +void gk_neut_species_n_iter_corr_enabled( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx +); -void -gk_neut_species_release_static(const gkyl_gyrokinetic_app* app, const struct gk_neut_species *s); +void gk_neut_species_n_iter_corr_disabled( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx +); +void gk_neut_species_release_static( + const gkyl_gyrokinetic_app *app, const struct gk_neut_species *s +); diff --git a/gyrokinetic/apps/gkyl_gyrokinetic.h b/gyrokinetic/apps/gkyl_gyrokinetic.h index 1d137b0963..d1ccbb9eda 100644 --- a/gyrokinetic/apps/gkyl_gyrokinetic.h +++ b/gyrokinetic/apps/gkyl_gyrokinetic.h @@ -14,7 +14,6 @@ #include - // Parameters for projection struct gkyl_gyrokinetic_ic_import { // Inputs to initialize the species with the distribution from a file (f_in) @@ -38,8 +37,8 @@ struct gkyl_gyrokinetic_projection { // Distribution function to project and its context. For fluid neutrals // this function returns mass density, momentum density, and total // energy density. - void (*func)(double t, const double *xn, double *fout, void *ctx); - void *ctx_func; + void (*func)(double t, const double *xn, double *fout, void *ctx); + void *ctx_func; }; struct { // For Maxwellians (or BiMaxwellians), specify density, parallel speed @@ -72,14 +71,15 @@ struct gkyl_gyrokinetic_projection { // Options for a Maxwellian in vel-space w/ Gaussian shape in conf-space. double gaussian_mean[GKYL_MAX_CDIM]; // Center in configuration space. - double gaussian_std_dev[GKYL_MAX_CDIM]; // Sigma in configuration space, function is constant if sigma is 0. + double gaussian_std_dev + [GKYL_MAX_CDIM]; // Sigma in configuration space, function is constant if sigma is 0. double total_num_particles; // Total number of particle (M0 moment). double total_kin_energy; // Total kinetic energy (0.5*mass*M2 moment). double temp_max; // Maximum temperature of the Gaussian Maxwellian distribution. double temp_min; // Minimum temperature of the Gaussian Maxwellian distribution. - + // Boolean if we are correcting all the moments or only density. - bool correct_all_moms; + bool correct_all_moms; double iter_eps; // Error tolerance for moment fixes (density is always exact). int max_iter; // Maximum number of iteration. bool use_last_converged; // Use last iteration value regardless of convergence? @@ -91,7 +91,8 @@ struct gkyl_phase_diagnostics_inp { int num_diag_moments; // Number of diagnostic moments. enum gkyl_distribution_moments diag_moments[12]; // List of diagnostic moments. int num_integrated_diag_moments; // Number of integrated diagnostic moments. - enum gkyl_distribution_moments integrated_diag_moments[12]; // List of integrated diagnostic moments. + enum gkyl_distribution_moments + integrated_diag_moments[12]; // List of integrated diagnostic moments. bool time_integrated; // Whether to use time integrated diags. }; @@ -111,7 +112,7 @@ struct gkyl_gyrokinetic_collisions { enum gkyl_collision_id collision_id; // type of collisions (see gkyl_eqn_type.h) bool write_diagnostics; // Whether to output diagnostics. bool not_in_dfdt; // If true, the collision operator will not be added to df/dt. - // Used to ignore the collisional updates of this species, while updating cross-species collisions. + // Used to ignore the collisional updates of this species, while updating cross-species collisions. double nu_frac; // Rescales collision frequencies (default = 1). @@ -133,7 +134,7 @@ struct gkyl_gyrokinetic_collisions { double hbar, eps0, eV; // Planck's constant/2 pi, vacuum permittivity, elementary charge. // Boolean for using implicit BGK collisions (replaces rk3). - bool is_implicit; + bool is_implicit; }; // Parameters for species diffusion. @@ -148,14 +149,17 @@ struct gkyl_gyrokinetic_diffusion { struct gkyl_gyrokinetic_adapt_source { bool adapt_particle; // Whether to adapt the particle source. bool adapt_energy; // Whether to adapt the energy source. - bool has_adapt_particle_fraction; // Whether a recycling rate is provided or if we should just adapt to all the loss. - double adapt_particle_fraction; // Fraction of particle loss to adapt to (default is 1, full adaptation). + bool + has_adapt_particle_fraction; // Whether a recycling rate is provided or if we should just adapt to all the loss. + double + adapt_particle_fraction; // Fraction of particle loss to adapt to (default is 1, full adaptation). bool has_adapt_energy_fraction; // Whether to specify a fraction of the energy loss to adapt to. - double adapt_energy_fraction; // Fraction of energy loss to adapt to (default is 1, full adaptation). + double + adapt_energy_fraction; // Fraction of energy loss to adapt to (default is 1, full adaptation). char adapt_to_species[16]; // Species to adapt the particle loss to ensure quasi neutrality. int num_boundaries; // Number of boundaries to adapt. - int dir[GKYL_MAX_CDIM*2]; // Direction to adapt. - enum gkyl_edge_loc edge[GKYL_MAX_CDIM*2]; // Edge to adapt. + int dir[GKYL_MAX_CDIM * 2]; // Direction to adapt. + enum gkyl_edge_loc edge[GKYL_MAX_CDIM * 2]; // Edge to adapt. }; // Parameters for species source @@ -180,7 +184,7 @@ struct gkyl_gyrokinetic_anomalous_diffusion { }; // Parameters for species bgk source term either: -// 1. nu_Q(x)*(f_M(n,upar,T_Q(t)*s_Q(x)/m) - f) +// 1. nu_Q(x)*(f_M(n,upar,T_Q(t)*s_Q(x)/m) - f) // for default model or // 2. nu(x)*(f_M(n_S,upar,T) - f) // nu(x)*(f_M(n,upar_S,T) - f) @@ -195,11 +199,11 @@ struct gkyl_gyrokinetic_source_bgk { void (*temp_shape)(double t, const double *xn, double *fout, void *ctx); // s_Q(x,y,z). void *temp_shape_ctx; double power; // Desired heating power (sets T_Q(t)). - double injection_time; // Injection time for external source model - // nu(x) = 1/coupling time - double damping_factor; // For external source model - // n_s = max(n_s, damping factor*n) - // to prevent driving n negative + double injection_time; // Injection time for external source model + // nu(x) = 1/coupling time + double damping_factor; // For external source model + // n_s = max(n_s, damping factor*n) + // to prevent driving n negative bool write_diagnostics; // Whether to output diagnostics. }; @@ -213,14 +217,17 @@ struct gkyl_gyrokinetic_emission_inp { // Parameters for boundary conditions struct gkyl_gyrokinetic_bc { - int dir; // Direction in which BC is specified. + int dir; // Direction in which BC is specified. enum gkyl_edge_loc edge; // Which edge this BC is for. enum gkyl_gyrokinetic_bc_type type; // BC type flag. double value[3]; // Meaning depends on type. - void (*aux_profile)(double t, const double *xn, double *fout, void *ctx); // Auxiliary function (e.g. wall potential). + void (*aux_profile)( + double t, const double *xn, double *fout, + void *ctx + ); // Auxiliary function (e.g. wall potential). void *aux_ctx; // Context for aux_profile. struct gkyl_gyrokinetic_projection projection; // Projection object input (e.g. for FIXED_FUNC). - struct gkyl_gyrokinetic_emission_inp emission; + struct gkyl_gyrokinetic_emission_inp emission; bool write_diagnostics; // Whether to output diagnostics. int bidx; // Block index (for multiblock solver). }; @@ -251,10 +258,11 @@ struct gkyl_gyrokinetic_geometry { void *parallel_upper_bc_shift_ctx; // Context for parallel_upper_bc_shift_func. struct gkyl_efit_inp efit_info; // Context with RZ data such as efit file for a tokamak or mirror. - struct gkyl_tok_geo_grid_inp tok_grid_info; // Context for tokamak geometry with computational domain info. - struct gkyl_mirror_geo_grid_inp mirror_grid_info; // Context for mirror geometry with computational domain info. + struct gkyl_tok_geo_grid_inp + tok_grid_info; // Context for tokamak geometry with computational domain info. + struct gkyl_mirror_geo_grid_inp + mirror_grid_info; // Context for mirror geometry with computational domain info. struct gkyl_position_map_inp position_map_info; // Position map object. - }; // Parameters for species radiation. @@ -262,10 +270,10 @@ struct gkyl_gyrokinetic_radiation { enum gkyl_radiation_id radiation_id; // Type of radiation. int num_cross_collisions; // Number of species to cross-collide with. - char collide_with[2*GKYL_MAX_SPECIES][128]; // Names of species to cross collide with. + char collide_with[2 * GKYL_MAX_SPECIES][128]; // Names of species to cross collide with. - int atomic_Z[2*GKYL_MAX_SPECIES]; // Z of element for desired fit information. - int charge_state[2*GKYL_MAX_SPECIES]; // Charge state of element for desired fit information. + int atomic_Z[2 * GKYL_MAX_SPECIES]; // Z of element for desired fit information. + int charge_state[2 * GKYL_MAX_SPECIES]; // Charge state of element for desired fit information. int num_of_densities[GKYL_MAX_RAD_DENSITIES]; // Max number of densities to use per charge state // Reference, max and min electron densities to specify range of density fits @@ -310,7 +318,7 @@ enum gkyl_gk_species_scaling_type { GKYL_GK_SPECIES_SCALING_NONE = 0, // No scaling. GKYL_GK_SPECIES_SCALING_RECYCLING_IZ_BALANCE, // Balance between recycling and ionization. GKYL_GK_SPECIES_SCALING_FIXED_FRACTION, // Maintains fixed fraction relative to another species. - GKYL_GK_SPECIES_SCALING_BOLTZMANN, // n_s = n_{s,sheath}*exp(-q_s*(phi-phi_sheath)/T_s). + GKYL_GK_SPECIES_SCALING_BOLTZMANN // n_s = n_{s,sheath}*exp(-q_s*(phi-phi_sheath)/T_s). }; // Input parameters for scaling a species every time step. @@ -319,13 +327,13 @@ struct gkyl_gyrokinetic_scaling_inp { // Info for GKYL_GK_SPECIES_SCALING_RECYCLING_IZ_BALANCE. int num_boundaries; // Number of boundaries. - int boundaries_dir[GKYL_MAX_CDIM*2]; // Direction of boundaries. - enum gkyl_edge_loc boundaries_edge[GKYL_MAX_CDIM*2]; // Edge of boundaries. + int boundaries_dir[GKYL_MAX_CDIM * 2]; // Direction of boundaries. + enum gkyl_edge_loc boundaries_edge[GKYL_MAX_CDIM * 2]; // Edge of boundaries. char impacting_ion_name[128]; // Name of impacting species. enum gkyl_ion_type impacting_ion_id; // Type of impacting ion. char electron_name[128]; // Name of electron species. double recycling_coeff; // Recycling coefficient. - + // Info for GKYL_GK_SPECIES_SCALING_FIXED_FRACTION. char ref_species_name[128]; // Name of reference species. double fixed_fraction; // Fraction of reference species density. @@ -335,10 +343,10 @@ struct gkyl_gyrokinetic_scaling_inp { // Parameters in FLR effects. struct gkyl_gyrokinetic_flr { - enum gkyl_gk_flr_type type; - double Tperp; // Perp temperature used to evaluate gyroradius. + enum gkyl_gk_flr_type type; + double Tperp; // Perp temperature used to evaluate gyroradius. double bmag; // Magnetic field used to evaluate gyroradius. If not provided - // it'll use B in the center of the domain. + // it'll use B in the center of the domain. }; struct gkyl_gyrokinetic_correct_inp { @@ -346,25 +354,26 @@ struct gkyl_gyrokinetic_correct_inp { double iter_eps; // error tolerance for moment fixes (density is always exact) int max_iter; // maximum number of iteration bool use_last_converged; // Boolean for if we are using the results of the iterative scheme - // *even if* the scheme fails to converge. + // *even if* the scheme fails to converge. }; enum gkyl_gyrokinetic_positivity_type { GKYL_GK_POSITIVITY_NONE = 0, // Do not enforce positivity (default). GKYL_GK_POSITIVITY_SHIFT, // Shift f to zero if <0 at Gauss-Legendre nodes. - GKYL_GK_POSITIVITY_MRS_LIMITER, // Use the More-Rossmanith-Seal limiter, and shift when needed. + GKYL_GK_POSITIVITY_MRS_LIMITER // Use the More-Rossmanith-Seal limiter, and shift when needed. }; struct gkyl_gyrokinetic_positivity { enum gkyl_gyrokinetic_positivity_type type; // Type of positivity enforcement algorithm. - bool quasineutrality_rescale; // Whether to rescale this species to enforce quasineutrality in the simulation. + bool + quasineutrality_rescale; // Whether to rescale this species to enforce quasineutrality in the simulation. bool write_diagnostics; // Whether to output diagnostics. }; enum gkyl_gyrokinetic_damping_type { GKYL_GK_DAMPING_NONE = 0, GKYL_GK_DAMPING_USER_INPUT, - GKYL_GK_DAMPING_LOSS_CONE, + GKYL_GK_DAMPING_LOSS_CONE }; struct gkyl_gyrokinetic_damping { @@ -382,17 +391,17 @@ struct gkyl_gyrokinetic_damping { // Types of df/dt multipliers: M(x,v,t) modifies df/dt -> M * df/dt. enum gkyl_gyrokinetic_fdot_multiplier_type { - GKYL_GK_FDOT_MULTIPLIER_NONE = 0, // No multiplier applied. - GKYL_GK_FDOT_MULTIPLIER_USER_INPUT, // User-provided static profile M(z) via function pointer. - GKYL_GK_FDOT_MULTIPLIER_LOSS_CONE, // M=1 in loss cone, M=0 in confined region. - GKYL_GK_FDOT_MULTIPLIER_CONSTANT, // Dilates time by a fixed constant, time_dilation_scale_const. - GKYL_GK_FDOT_MULTIPLIER_FIXED_DT, // dt floor from user-specified cfl_dt_min_value. + GKYL_GK_FDOT_MULTIPLIER_NONE = 0, // No multiplier applied. + GKYL_GK_FDOT_MULTIPLIER_USER_INPUT, // User-provided static profile M(z) via function pointer. + GKYL_GK_FDOT_MULTIPLIER_LOSS_CONE, // M=1 in loss cone, M=0 in confined region. + GKYL_GK_FDOT_MULTIPLIER_CONSTANT, // Dilates time by a fixed constant, time_dilation_scale_const. + GKYL_GK_FDOT_MULTIPLIER_FIXED_DT, // dt floor from user-specified cfl_dt_min_value. GKYL_GK_FDOT_MULTIPLIER_FIXED_FACTOR_TIMES_OMEGA_MAX, // dt floor from user-specified factor times maximum characteristic frequency. Specify cfl_factor_times_omega_max. - GKYL_GK_FDOT_MULTIPLIER_FIXED_DT_OMEGAH, // dt floor from omega_H, an electrostatic GK wave. - GKYL_GK_FDOT_MULTIPLIER_DT_SET_BY_SPECIES, // Set the dt floor based on the dt from another species. - GKYL_GK_FDOT_MULTIPLIER_MASK_F_THRESHOLD, // Dilates time in cells where |J_tot*f| < threshold. Specify f_threshold - GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_LOCAL, // Dilates time in cells where |J_tot*f| < threshold * local_max. Spatially dependent mask. Specify f_threshold - GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_GLOBAL, // Dilates time in cells where |J_tot*f| < threshold * global_max. Specify f_threshold + GKYL_GK_FDOT_MULTIPLIER_FIXED_DT_OMEGAH, // dt floor from omega_H, an electrostatic GK wave. + GKYL_GK_FDOT_MULTIPLIER_DT_SET_BY_SPECIES, // Set the dt floor based on the dt from another species. + GKYL_GK_FDOT_MULTIPLIER_MASK_F_THRESHOLD, // Dilates time in cells where |J_tot*f| < threshold. Specify f_threshold + GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_LOCAL, // Dilates time in cells where |J_tot*f| < threshold * local_max. Spatially dependent mask. Specify f_threshold + GKYL_GK_FDOT_MULTIPLIER_MASK_F_FRAC_GLOBAL // Dilates time in cells where |J_tot*f| < threshold * global_max. Specify f_threshold }; // Input parameters for a single component of the df/dt multiplier chain. @@ -403,17 +412,20 @@ struct gkyl_gyrokinetic_fdot_multiplier_comp { void (*profile)(double t, const double *xn, double *fout, void *ctx); void *profile_ctx; - bool cellwise_const; // If true, multiplier is constant within each cell (p=0 basis). + bool cellwise_const; // If true, multiplier is constant within each cell (p=0 basis). bool write_diagnostics; // If true, write multiplier array to file. // Parameters for time dilation types (FIXED_DT, MASK_F_*): double cfl_dt_min_value; // For FIXED_DT: the minimum allowed dt value. double f_threshold; // For MASK_F_* types: absolute value (THRESHOLD) - // or fraction 0-1 (FRAC_LOCAL, FRAC_GLOBAL). - double time_dilation_scale_const; // A constant which multiplies all of fdot and cfl to dilate time. Small number (0,1] so that dt *= 1/time_dilation_scale_const - double cfl_factor_times_omega_max; // For FIXED_FACTOR_TIMES_OMEGA_MAX: the factor multiplied by the maximum characteristic frequency to get the minimum dt value. - - char dt_set_by_species[32]; // For DT_SET_BY_SPECIES: the name of the species whose dt we are using to set the maximum dt for this species. e.g. "elc" + // or fraction 0-1 (FRAC_LOCAL, FRAC_GLOBAL). + double + time_dilation_scale_const; // A constant which multiplies all of fdot and cfl to dilate time. Small number (0,1] so that dt *= 1/time_dilation_scale_const + double + cfl_factor_times_omega_max; // For FIXED_FACTOR_TIMES_OMEGA_MAX: the factor multiplied by the maximum characteristic frequency to get the minimum dt value. + + char dt_set_by_species + [32]; // For DT_SET_BY_SPECIES: the name of the species whose dt we are using to set the maximum dt for this species. e.g. "elc" }; // Parameters for a chain of df/dt multipliers. Components are applied in order. @@ -453,7 +465,8 @@ struct gkyl_gyrokinetic_species { int num_diag_moments; // number of diagnostic moments enum gkyl_distribution_moments diag_moments[12]; // list of diagnostic moments int num_integrated_diag_moments; // Number of integrated diagnostic moments. - enum gkyl_distribution_moments integrated_diag_moments[12]; // List of integrated diagnostic moments. + enum gkyl_distribution_moments + integrated_diag_moments[12]; // List of integrated diagnostic moments. bool time_rate_diagnostics; // Whether to ouput df/dt diagnostics. bool write_omega_cfl; // Whether to ouput dt diagnostic for the CFL constraint. @@ -466,7 +479,7 @@ struct gkyl_gyrokinetic_species { // Input quantities used by LTE (local thermodynamic equilibrium, or Maxwellian) projection // This projection operator is used by BGK collisions and all reactions. - struct gkyl_gyrokinetic_correct_inp correct; + struct gkyl_gyrokinetic_correct_inp correct; // Elastic collisions. struct gkyl_gyrokinetic_collisions collisions; @@ -475,7 +488,7 @@ struct gkyl_gyrokinetic_species { struct gkyl_gyrokinetic_source source; // A damping term -rate*f on RHS. - struct gkyl_gyrokinetic_damping damping; + struct gkyl_gyrokinetic_damping damping; // Anomalous diffusion. struct gkyl_gyrokinetic_anomalous_diffusion anomalous_diffusion; @@ -495,7 +508,7 @@ struct gkyl_gyrokinetic_species { struct gkyl_gyrokinetic_scaling_inp scaling; // Boundary conditions. - struct gkyl_gyrokinetic_bc bcs[2*GKYL_MAX_CDIM]; + struct gkyl_gyrokinetic_bc bcs[2 * GKYL_MAX_CDIM]; }; // Parameters for neutral species. @@ -512,9 +525,9 @@ struct gkyl_gyrokinetic_neut_species { bool is_static; // Set to true if neutral species does not change in time. struct gkyl_gyrokinetic_positivity positivity; // Positivity enforcement options. - + struct gkyl_gyrokinetic_ic_import init_from_file; - + // Initial conditions using projection routine. struct gkyl_gyrokinetic_projection projection; @@ -528,7 +541,7 @@ struct gkyl_gyrokinetic_neut_species { // Input quantities used by LTE (local thermodynamic equilibrium, or Maxwellian) projection // This projection operator is used by BGK collisions and all reactions. - struct gkyl_gyrokinetic_correct_inp correct; + struct gkyl_gyrokinetic_correct_inp correct; // Elastic collisions. struct gkyl_gyrokinetic_collisions collisions; @@ -540,7 +553,7 @@ struct gkyl_gyrokinetic_neut_species { struct gkyl_gyrokinetic_react react_neut; // Boundary conditions. - struct gkyl_gyrokinetic_bc bcs[2*GKYL_MAX_CDIM]; + struct gkyl_gyrokinetic_bc bcs[2 * GKYL_MAX_CDIM]; double gas_gamma; // Adiabatic index (fluid neutrals). @@ -560,7 +573,7 @@ struct gkyl_gyrokinetic_field { // parameters for adiabatic electrons simulations double electron_mass, electron_charge, electron_density, electron_temp; - struct gkyl_gyrokinetic_bc poisson_bcs[2*GKYL_MAX_CDIM]; + struct gkyl_gyrokinetic_bc poisson_bcs[2 * GKYL_MAX_CDIM]; bool time_rate_diagnostics; // Writes the time rate of change of field energy. @@ -579,12 +592,14 @@ struct gkyl_gyrokinetic_field { void *phi_wall_lo_ctx; // context for biased wall potential on lower wall // pointer to biased wall potential on lower wall function void (*phi_wall_lo)(double t, const double *xn, double *phi_wall_lo_out, void *ctx); - bool phi_wall_lo_evolve; // set to true if biased wall potential on lower wall function is time dependent + bool + phi_wall_lo_evolve; // set to true if biased wall potential on lower wall function is time dependent void *phi_wall_up_ctx; // context for biased wall potential on upper wall // pointer to biased wall potential on upper wall function void (*phi_wall_up)(double t, const double *xn, double *phi_wall_up_out, void *ctx); - bool phi_wall_up_evolve; // set to true if biased wall potential on upper wall function is time dependent + bool + phi_wall_up_evolve; // set to true if biased wall potential on upper wall function is time dependent struct gkyl_poisson_bias_line_list *bias_line_list; // Biased lines constraining the solution. }; @@ -628,7 +643,7 @@ struct gkyl_gk { int num_neut_species; // Number of species. struct gkyl_gyrokinetic_neut_species neut_species[GKYL_MAX_SPECIES]; // Species objects. - + struct gkyl_gyrokinetic_field field; // Field object. struct gkyl_gyrokinetic_eirene eirene; // EIRENE input @@ -641,16 +656,16 @@ struct gkyl_gk { // Simulation statistics struct gkyl_gyrokinetic_stat { bool use_gpu; // did this sim use GPU? - + long nup; // calls to update long nfeuler; // calls to forward-Euler method - + long nstage_2_fail; // number of failed RK stage-2s long nstage_3_fail; // number of failed RK stage-3s double stage_2_dt_diff[2]; // [min,max] rel-diff for stage-2 failure double stage_3_dt_diff[2]; // [min,max] rel-diff for stage-3 failure - + double init_species_tm; // time to initialize all species double init_neut_species_tm; // time to initialize all neutral species @@ -659,9 +674,11 @@ struct gkyl_gyrokinetic_stat { double fwd_euler_step_f_tm; // Time spent on fwd euler step_f. double dfdt_dt_reduce_tm; // Time spent on fwd euler dt reduction. - double species_collisionless_tm; // Time to compute species collisionless RHS (alpha already computed). + double + species_collisionless_tm; // Time to compute species collisionless RHS (alpha already computed). double species_gyroavg_tm; // Time to compute species collisionless RHS. - double species_lte_tm; // total time for species LTE (local thermodynamic equilibrium) projection updater + double + species_lte_tm; // total time for species LTE (local thermodynamic equilibrium) projection updater double species_bflux_calc_tm; // Time for species boundary flux calculation. double species_bflux_moms_tm; // Time for species boundary flux moments. double species_coll_mom_tm; // time needed to compute various moments needed in collisions @@ -671,19 +688,22 @@ struct gkyl_gyrokinetic_stat { double species_diffusion_tm; // Time to compute species diffusion term. double species_rad_mom_tm; // total time to compute various moments needed in radiation operator double species_rad_tm; // total time for radiation operator - double species_react_mom_tm; // total time to compute various moments needed in reactions + double species_react_mom_tm; // total time to compute various moments needed in reactions double species_react_tm; // total time for reactions updaters double species_src_tm; // Time to accumulate species source onto RHS. double species_source_bgk_tm; // Time to compute bgk source term RHS. double species_omega_cfl_tm; // time spent in all-reduce for omega-cfl double neut_species_collisionless_tm; // Time to compute neutral species collisionless RHS. - double neut_species_lte_tm; // total time for neutral species LTE (local thermodynamic equilibrium) projection updater + double + neut_species_lte_tm; // total time for neutral species LTE (local thermodynamic equilibrium) projection updater double neut_species_bflux_calc_tm; // Time for neutral species boundary flux calculation. double neut_species_bflux_moms_tm; // Time for neutral species boundary flux moments. double neut_species_coll_tm; // total time for neutral self-collisions updater (excluded moments) - double neut_species_coll_mom_tm; // time needed to compute various moments needed in neutral self-collisions - double neut_species_react_mom_tm; // total time to compute various moments needed in neutral reactions + double + neut_species_coll_mom_tm; // time needed to compute various moments needed in neutral self-collisions + double + neut_species_react_mom_tm; // total time to compute various moments needed in neutral reactions double neut_species_react_tm; // total time for neutral reactions updaters double neut_species_src_tm; // Time to accumulate neutral species source onto RHS. double neut_species_omega_cfl_tm; // time spent in all-reduce for omega-cfl for neutrals @@ -694,7 +714,7 @@ struct gkyl_gyrokinetic_stat { double field_tm; // Time to compute fields. double field_phi_rhs_tm; // Time spent on poisson eqn RHS. - double field_phi_solve_tm; // Time spent to solve poisson eqn. + double field_phi_solve_tm; // Time spent to solve poisson eqn. double bc_tm; // Time to compute BCs. double species_bc_tm; // Time to compute species BCs. @@ -731,10 +751,14 @@ struct gkyl_gyrokinetic_stat { double app_io_tm; // Time to write common diagnostics. double io_tm; // Time to write common diagnostics. - long n_iter_corr[GKYL_MAX_SPECIES]; // total number of iterations used to correct species LTE projection - long num_corr[GKYL_MAX_SPECIES]; // total number of times correction updater for species LTE projection is called - long neut_n_iter_corr[GKYL_MAX_SPECIES]; // total number of iterations used to correct neutral species LTE projection - long neut_num_corr[GKYL_MAX_SPECIES]; // total number of times correction updater for neutral species LTE projection is called + long + n_iter_corr[GKYL_MAX_SPECIES]; // total number of iterations used to correct species LTE projection + long num_corr + [GKYL_MAX_SPECIES]; // total number of times correction updater for species LTE projection is called + long neut_n_iter_corr + [GKYL_MAX_SPECIES]; // total number of iterations used to correct neutral species LTE projection + long neut_num_corr + [GKYL_MAX_SPECIES]; // total number of times correction updater for neutral species LTE projection is called long n_species_omega_cfl; // number of times CFL-omega all-reduce is called long n_mom; // total number of calls to moment updater routines @@ -763,7 +787,7 @@ typedef struct gkyl_gyrokinetic_app gkyl_gyrokinetic_app; * initialized * @return New gk app object. */ -gkyl_gyrokinetic_app* gkyl_gyrokinetic_app_new(struct gkyl_gk *gk); +gkyl_gyrokinetic_app *gkyl_gyrokinetic_app_new(struct gkyl_gk *gk); /** * Construct a new gk app (geometry only). @@ -772,7 +796,7 @@ gkyl_gyrokinetic_app* gkyl_gyrokinetic_app_new(struct gkyl_gk *gk); * initialized * @return New gk app object. */ -gkyl_gyrokinetic_app* gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk); +gkyl_gyrokinetic_app *gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk); /** * Initialize species and field by projecting initial conditions on @@ -781,14 +805,16 @@ gkyl_gyrokinetic_app* gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk); * @param app App object. * @param t0 Time for initial conditions. */ -void gkyl_gyrokinetic_app_apply_ic(gkyl_gyrokinetic_app* app, double t0); +void gkyl_gyrokinetic_app_apply_ic(gkyl_gyrokinetic_app *app, double t0); /** * Write geometry file. * * @param app App object. */ -void gkyl_gyrokinetic_app_write_geometry(gkyl_gyrokinetic_app *app, struct gkyl_gk_geometry_inp *geometry_inp); +void gkyl_gyrokinetic_app_write_geometry( + gkyl_gyrokinetic_app *app, struct gkyl_gk_geometry_inp *geometry_inp +); /** * Write field data to file. @@ -797,7 +823,7 @@ void gkyl_gyrokinetic_app_write_geometry(gkyl_gyrokinetic_app *app, struct gkyl_ * @param tm Time-stamp. * @param frame Frame number. */ -void gkyl_gyrokinetic_app_write_field(gkyl_gyrokinetic_app* app, double tm, int frame); +void gkyl_gyrokinetic_app_write_field(gkyl_gyrokinetic_app *app, double tm, int frame); /** * Calculate integrated field energy @@ -805,7 +831,7 @@ void gkyl_gyrokinetic_app_write_field(gkyl_gyrokinetic_app* app, double tm, int * @param tm Time at which integrated diagnostic are to be computed * @param app App object. */ -void gkyl_gyrokinetic_app_calc_field_energy(gkyl_gyrokinetic_app* app, double tm); +void gkyl_gyrokinetic_app_calc_field_energy(gkyl_gyrokinetic_app *app, double tm); /** * Write field energy to file. Field energy data is appended to the @@ -813,7 +839,7 @@ void gkyl_gyrokinetic_app_calc_field_energy(gkyl_gyrokinetic_app* app, double tm * * @param app App object. */ -void gkyl_gyrokinetic_app_write_field_energy(gkyl_gyrokinetic_app* app); +void gkyl_gyrokinetic_app_write_field_energy(gkyl_gyrokinetic_app *app); /** * Write eirene data to file. @@ -822,7 +848,7 @@ void gkyl_gyrokinetic_app_write_field_energy(gkyl_gyrokinetic_app* app); * @param tm Time-stamp. * @param frame Frame number. */ -void gkyl_gyrokinetic_app_write_eirene_diagnostics(gkyl_gyrokinetic_app* app, double tm, int frame); +void gkyl_gyrokinetic_app_write_eirene_diagnostics(gkyl_gyrokinetic_app *app, double tm, int frame); /** * Calculate eirene integrated diagnostics. @@ -830,14 +856,14 @@ void gkyl_gyrokinetic_app_write_eirene_diagnostics(gkyl_gyrokinetic_app* app, do * @param app App object. * @param tm Time-stamp. */ -void gkyl_gyrokinetic_app_calc_eirene_integrated_diagnostics(gkyl_gyrokinetic_app* app, double tm); +void gkyl_gyrokinetic_app_calc_eirene_integrated_diagnostics(gkyl_gyrokinetic_app *app, double tm); /** * Write eirene integrated diagnostics. * * @param app App object. */ -void gkyl_gyrokinetic_app_write_eirene_integrated_diagnostics(gkyl_gyrokinetic_app* app); +void gkyl_gyrokinetic_app_write_eirene_integrated_diagnostics(gkyl_gyrokinetic_app *app); /** * Write species data to file. @@ -847,7 +873,7 @@ void gkyl_gyrokinetic_app_write_eirene_integrated_diagnostics(gkyl_gyrokinetic_a * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame); /** * Write neutral species data to file. @@ -857,7 +883,9 @@ void gkyl_gyrokinetic_app_write_species(gkyl_gyrokinetic_app* app, int sidx, dou * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_neut_species(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_neut_species( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write diagnostic moments for species to file. @@ -867,7 +895,9 @@ void gkyl_gyrokinetic_app_write_neut_species(gkyl_gyrokinetic_app* app, int sidx * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species_mom(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write diagnostic moments for neutral species to file. @@ -877,7 +907,9 @@ void gkyl_gyrokinetic_app_write_species_mom(gkyl_gyrokinetic_app *app, int sidx, * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_neut_species_mom(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_neut_species_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Calculate integrated diagnostic moments for a plasma species. @@ -886,7 +918,9 @@ void gkyl_gyrokinetic_app_write_neut_species_mom(gkyl_gyrokinetic_app *app, int * @param sidx Index of species whose integrated moments to compute. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_app_calc_species_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm); +void gkyl_gyrokinetic_app_calc_species_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +); /** * Calculate integrated diagnostic moments for a neutral species. @@ -895,7 +929,9 @@ void gkyl_gyrokinetic_app_calc_species_integrated_mom(gkyl_gyrokinetic_app* app, * @param sidx Index of neutral species whose integrated moments to compute. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_app_calc_neut_species_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm); +void gkyl_gyrokinetic_app_calc_neut_species_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +); /** * Calculate the L2 norm of a plasma species. @@ -904,7 +940,7 @@ void gkyl_gyrokinetic_app_calc_neut_species_integrated_mom(gkyl_gyrokinetic_app* * @param sidx Index of species whose L2 norm to compute. * @param tm Time at which L2 norm is to be computed. */ -void gkyl_gyrokinetic_app_calc_species_L2norm(gkyl_gyrokinetic_app* app, int sidx, double tm); +void gkyl_gyrokinetic_app_calc_species_L2norm(gkyl_gyrokinetic_app *app, int sidx, double tm); /** * Calculate integrated diagnostic moments of the boundary fluxes for a plasma species. @@ -913,7 +949,9 @@ void gkyl_gyrokinetic_app_calc_species_L2norm(gkyl_gyrokinetic_app* app, int sid * @param sidx Index of species whose integrated moments to compute. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_app_calc_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm); +void gkyl_gyrokinetic_app_calc_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +); /** * Calculate integrated diagnostic moments of the boundary fluxes for a neutral species. @@ -922,7 +960,9 @@ void gkyl_gyrokinetic_app_calc_species_boundary_flux_integrated_mom(gkyl_gyrokin * @param sidx Index of species whose integrated moments to compute. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_app_calc_neut_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm); +void gkyl_gyrokinetic_app_calc_neut_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +); /** * Write integrated diagnostic moments for charged species to file. Integrated @@ -958,7 +998,9 @@ void gkyl_gyrokinetic_app_write_species_L2norm(gkyl_gyrokinetic_app *app, int si * @param app App object. * @param sidx Index of species whose integrated moments to write. */ -void gkyl_gyrokinetic_app_write_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_app *app, int sidx); +void gkyl_gyrokinetic_app_write_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx +); /** * Write integrated diagnostic moments of the boundary fluxes for neutral @@ -967,7 +1009,9 @@ void gkyl_gyrokinetic_app_write_species_boundary_flux_integrated_mom(gkyl_gyroki * @param app App object. * @param sidx Index of species whose integrated moments to write. */ -void gkyl_gyrokinetic_app_write_neutral_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_app *app, int sidx); +void gkyl_gyrokinetic_app_write_neutral_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx +); /** * Write species source to file. @@ -977,7 +1021,9 @@ void gkyl_gyrokinetic_app_write_neutral_species_boundary_flux_integrated_mom(gky * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species_source(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_source( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write neutral species source to file. @@ -987,7 +1033,9 @@ void gkyl_gyrokinetic_app_write_species_source(gkyl_gyrokinetic_app* app, int si * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_neut_species_source(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_neut_species_source( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write diagnostic moments for species source to file. @@ -997,7 +1045,9 @@ void gkyl_gyrokinetic_app_write_neut_species_source(gkyl_gyrokinetic_app* app, i * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species_source_mom(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_source_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write diagnostic moments for neutral species source to file. @@ -1007,7 +1057,9 @@ void gkyl_gyrokinetic_app_write_species_source_mom(gkyl_gyrokinetic_app *app, in * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_neut_species_source_mom(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_neut_species_source_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Calculate integrated diagnostic moments for a plasma species source. @@ -1016,7 +1068,9 @@ void gkyl_gyrokinetic_app_write_neut_species_source_mom(gkyl_gyrokinetic_app *ap * @param sidx Index of species whose integrated moments to write. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_app_calc_species_source_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm); +void gkyl_gyrokinetic_app_calc_species_source_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +); /** * Calculate integrated diagnostic moments for a neutral species source. @@ -1025,7 +1079,9 @@ void gkyl_gyrokinetic_app_calc_species_source_integrated_mom(gkyl_gyrokinetic_ap * @param sidx Index of neutral species whose integrated moments to write. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_app_calc_neut_species_source_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm); +void gkyl_gyrokinetic_app_calc_neut_species_source_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +); /** * Calculate integrated diagnostic moments for a plasma species BGK source. @@ -1034,7 +1090,9 @@ void gkyl_gyrokinetic_app_calc_neut_species_source_integrated_mom(gkyl_gyrokinet * @param sidx Index of species whose integrated moments to write. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_app_calc_species_source_bgk_integrated_diagnostics(gkyl_gyrokinetic_app* app, int sidx, double tm); +void gkyl_gyrokinetic_app_calc_species_source_bgk_integrated_diagnostics( + gkyl_gyrokinetic_app *app, int sidx, double tm +); /** * Write integrated diagnostic moments for charged species source to file. Integrated @@ -1052,7 +1110,9 @@ void gkyl_gyrokinetic_app_write_species_source_integrated_mom(gkyl_gyrokinetic_a * @param app App object. * @param sidx Index of species whose source integrated moments to write. */ -void gkyl_gyrokinetic_app_write_species_source_bgk_integrated_diagnostics(gkyl_gyrokinetic_app *app, int sidx); +void gkyl_gyrokinetic_app_write_species_source_bgk_integrated_diagnostics( + gkyl_gyrokinetic_app *app, int sidx +); /** * Write integrated diagnostic moments for neutral species source to file. Integrated @@ -1061,7 +1121,9 @@ void gkyl_gyrokinetic_app_write_species_source_bgk_integrated_diagnostics(gkyl_g * @param app App object. * @param sidx Index of neutral species whose source integrated moments to write. */ -void gkyl_gyrokinetic_app_write_neut_species_source_integrated_mom(gkyl_gyrokinetic_app *app, int sidx); +void gkyl_gyrokinetic_app_write_neut_species_source_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx +); /** * Write LBO collisional moments for species to file. @@ -1071,7 +1133,9 @@ void gkyl_gyrokinetic_app_write_neut_species_source_integrated_mom(gkyl_gyrokine * @param tm Time-stamp. * @param frame Frame number. */ -void gkyl_gyrokinetic_app_write_species_lbo_mom(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_lbo_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write BGK collisional moments for species to file. @@ -1081,7 +1145,9 @@ void gkyl_gyrokinetic_app_write_species_lbo_mom(gkyl_gyrokinetic_app *app, int s * @param tm Time-stamp. * @param frame Frame number. */ -void gkyl_gyrokinetic_app_write_species_bgk_mom(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_bgk_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write species integrated correct Maxwellian status of the to file. @@ -1099,7 +1165,9 @@ void gkyl_gyrokinetic_app_write_species_lte_max_corr_status(gkyl_gyrokinetic_app * @param app App object. * @param sidx Index of neutral species whose Maxwellian correction status to write. */ -void gkyl_gyrokinetic_app_write_neut_species_lte_max_corr_status(gkyl_gyrokinetic_app *app, int sidx); +void gkyl_gyrokinetic_app_write_neut_species_lte_max_corr_status( + gkyl_gyrokinetic_app *app, int sidx +); /** * Write radiation drag coefficients for species to file. @@ -1109,7 +1177,9 @@ void gkyl_gyrokinetic_app_write_neut_species_lte_max_corr_status(gkyl_gyrokineti * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species_rad_drag(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_rad_drag( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write radiation emissivity of each species that species sidx collides with @@ -1119,7 +1189,9 @@ void gkyl_gyrokinetic_app_write_species_rad_drag(gkyl_gyrokinetic_app *app, int * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species_rad_emissivity(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_rad_emissivity( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Calculate integrated diagnostic moments of the radiation model. @@ -1128,7 +1200,9 @@ void gkyl_gyrokinetic_app_write_species_rad_emissivity(gkyl_gyrokinetic_app *app * @param sidx Index of species to whose radiation int moments to compute. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_app_calc_species_rad_integrated_mom(gkyl_gyrokinetic_app *app, int sidx, double tm); +void gkyl_gyrokinetic_app_calc_species_rad_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +); /** * Write integrated moments of radiation rhs for radiating species @@ -1147,7 +1221,9 @@ void gkyl_gyrokinetic_app_write_species_rad_integrated_mom(gkyl_gyrokinetic_app * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species_iz_react(gkyl_gyrokinetic_app* app, int sidx, int ridx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_iz_react( + gkyl_gyrokinetic_app *app, int sidx, int ridx, double tm, int frame +); /** * Write iz react rate coefficients for species to file. @@ -1158,7 +1234,9 @@ void gkyl_gyrokinetic_app_write_species_iz_react(gkyl_gyrokinetic_app* app, int * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species_iz_react_neut(gkyl_gyrokinetic_app* app, int sidx, int ridx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_iz_react_neut( + gkyl_gyrokinetic_app *app, int sidx, int ridx, double tm, int frame +); /** * Write recomb react rate coefficients for species to file. @@ -1169,7 +1247,9 @@ void gkyl_gyrokinetic_app_write_species_iz_react_neut(gkyl_gyrokinetic_app* app, * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species_recomb_react(gkyl_gyrokinetic_app* app, int sidx, int ridx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_recomb_react( + gkyl_gyrokinetic_app *app, int sidx, int ridx, double tm, int frame +); /** * Write recomb react rate coefficients for species to file. @@ -1180,7 +1260,9 @@ void gkyl_gyrokinetic_app_write_species_recomb_react(gkyl_gyrokinetic_app* app, * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species_recomb_react_neut(gkyl_gyrokinetic_app* app, int sidx, int ridx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_recomb_react_neut( + gkyl_gyrokinetic_app *app, int sidx, int ridx, double tm, int frame +); /** * Write the phase-space diagnostics for a charged species. @@ -1190,7 +1272,9 @@ void gkyl_gyrokinetic_app_write_species_recomb_react_neut(gkyl_gyrokinetic_app* * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species_phase(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_phase( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write the phase-space diagnostics for a neutral species. @@ -1200,7 +1284,9 @@ void gkyl_gyrokinetic_app_write_species_phase(gkyl_gyrokinetic_app* app, int sid * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_neut_species_phase(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_neut_species_phase( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write the conf-space diagnostics for a charged species. @@ -1210,7 +1296,9 @@ void gkyl_gyrokinetic_app_write_neut_species_phase(gkyl_gyrokinetic_app* app, in * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_species_conf(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_species_conf( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write the conf-space diagnostics for a neutral species. @@ -1220,7 +1308,9 @@ void gkyl_gyrokinetic_app_write_species_conf(gkyl_gyrokinetic_app* app, int sidx * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_neut_species_conf(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_app_write_neut_species_conf( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +); /** * Write diagnostic moments for all species (including sources) to file. @@ -1237,7 +1327,7 @@ void gkyl_gyrokinetic_app_write_mom(gkyl_gyrokinetic_app *app, double tm, int fr * @param app App object. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_app_calc_integrated_mom(gkyl_gyrokinetic_app* app, double tm); +void gkyl_gyrokinetic_app_calc_integrated_mom(gkyl_gyrokinetic_app *app, double tm); /** * Calculate the L2 norm for all species. @@ -1245,7 +1335,7 @@ void gkyl_gyrokinetic_app_calc_integrated_mom(gkyl_gyrokinetic_app* app, double * @param app App object. * @param tm Time at which L2 norms are to be computed. */ -void gkyl_gyrokinetic_app_calc_L2norm(gkyl_gyrokinetic_app* app, double tm); +void gkyl_gyrokinetic_app_calc_L2norm(gkyl_gyrokinetic_app *app, double tm); /** * Write integrated diagnostic moments for all species (including sources) @@ -1270,7 +1360,7 @@ void gkyl_gyrokinetic_app_write_L2norm(gkyl_gyrokinetic_app *app); * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_phase(gkyl_gyrokinetic_app* app, double tm, int frame); +void gkyl_gyrokinetic_app_write_phase(gkyl_gyrokinetic_app *app, double tm, int frame); /** * Write configuration space diagnostics to file. @@ -1279,7 +1369,7 @@ void gkyl_gyrokinetic_app_write_phase(gkyl_gyrokinetic_app* app, double tm, int * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write_conf(gkyl_gyrokinetic_app* app, double tm, int frame); +void gkyl_gyrokinetic_app_write_conf(gkyl_gyrokinetic_app *app, double tm, int frame); /** * Write both conf and phase-space diagnostics to file. @@ -1288,14 +1378,14 @@ void gkyl_gyrokinetic_app_write_conf(gkyl_gyrokinetic_app* app, double tm, int f * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_app_write(gkyl_gyrokinetic_app* app, double tm, int frame); +void gkyl_gyrokinetic_app_write(gkyl_gyrokinetic_app *app, double tm, int frame); /** * Write stats to file. Data is written in json format. * * @param app App object. */ -void gkyl_gyrokinetic_app_stat_write(gkyl_gyrokinetic_app* app); +void gkyl_gyrokinetic_app_stat_write(gkyl_gyrokinetic_app *app); /** * Print timing of solver components to iostream. @@ -1303,8 +1393,7 @@ void gkyl_gyrokinetic_app_stat_write(gkyl_gyrokinetic_app* app); * @param app App object. * @param iostream Where to write timers to (e.g. stdout, stderr); */ -void -gkyl_gyrokinetic_app_print_timings(gkyl_gyrokinetic_app* app, FILE *iostream); +void gkyl_gyrokinetic_app_print_timings(gkyl_gyrokinetic_app *app, FILE *iostream); /** * Record the time step (in private dynvector). @@ -1313,23 +1402,23 @@ gkyl_gyrokinetic_app_print_timings(gkyl_gyrokinetic_app* app, FILE *iostream); * @param tm Time stamp. * @param dt Time step to record (e.g. provided by app's status object). */ -void -gkyl_gyrokinetic_app_save_dt(gkyl_gyrokinetic_app* app, double tm, double dt); +void gkyl_gyrokinetic_app_save_dt(gkyl_gyrokinetic_app *app, double tm, double dt); /** * Write the time step over time. * * @param app App object. */ -void -gkyl_gyrokinetic_app_write_dt(gkyl_gyrokinetic_app* app); +void gkyl_gyrokinetic_app_write_dt(gkyl_gyrokinetic_app *app); /** * Read geometry file. * * @param app App object. */ -void gkyl_gyrokinetic_app_read_geometry(gkyl_gyrokinetic_app *app, struct gkyl_gk_geometry_inp *geometry_inp); +void gkyl_gyrokinetic_app_read_geometry( + gkyl_gyrokinetic_app *app, struct gkyl_gk_geometry_inp *geometry_inp +); /** * Initialize field from file @@ -1347,9 +1436,8 @@ gkyl_gyrokinetic_app_from_file_field(gkyl_gyrokinetic_app *app, const char *fnam * @param sidx gk species index * @param fname file to read */ -struct gkyl_app_restart_status -gkyl_gyrokinetic_app_from_file_species(gkyl_gyrokinetic_app *app, int sidx, - const char *fname); +struct gkyl_app_restart_status +gkyl_gyrokinetic_app_from_file_species(gkyl_gyrokinetic_app *app, int sidx, const char *fname); /** * Initialize neutral species from file @@ -1358,9 +1446,8 @@ gkyl_gyrokinetic_app_from_file_species(gkyl_gyrokinetic_app *app, int sidx, * @param sidx neut species index * @param fname file to read */ -struct gkyl_app_restart_status -gkyl_gyrokinetic_app_from_file_neut_species(gkyl_gyrokinetic_app *app, int sidx, - const char *fname); +struct gkyl_app_restart_status +gkyl_gyrokinetic_app_from_file_neut_species(gkyl_gyrokinetic_app *app, int sidx, const char *fname); /** * Initialize the gyrokinetic app from a specific frame. @@ -1410,7 +1497,7 @@ gkyl_gyrokinetic_app_from_frame_neut_species(gkyl_gyrokinetic_app *app, int sidx * @param fmt Format string for console output * @param argp Objects to write */ -void gkyl_gyrokinetic_app_cout(const gkyl_gyrokinetic_app* app, FILE *fp, const char *fmt, ...); +void gkyl_gyrokinetic_app_cout(const gkyl_gyrokinetic_app *app, FILE *fp, const char *fmt, ...); /** * Advance simulation by a suggested time-step 'dt'. The dt may be too @@ -1428,28 +1515,28 @@ void gkyl_gyrokinetic_app_cout(const gkyl_gyrokinetic_app* app, FILE *fp, const * @param dt Suggested time-step to advance simulation * @return Status of update. */ -struct gkyl_update_status gkyl_gyrokinetic_update(gkyl_gyrokinetic_app* app, double dt); +struct gkyl_update_status gkyl_gyrokinetic_update(gkyl_gyrokinetic_app *app, double dt); /** * Return simulation statistics. * * @return Return statistics object. */ -struct gkyl_gyrokinetic_stat gkyl_gyrokinetic_app_stat(gkyl_gyrokinetic_app* app); +struct gkyl_gyrokinetic_stat gkyl_gyrokinetic_app_stat(gkyl_gyrokinetic_app *app); /** * Free gk app. * * @param app App to release. */ -void gkyl_gyrokinetic_app_release(gkyl_gyrokinetic_app* app); +void gkyl_gyrokinetic_app_release(gkyl_gyrokinetic_app *app); /** * Free gk app (geom only). * * @param app App to release. */ -void gkyl_gyrokinetic_app_release_geom(gkyl_gyrokinetic_app* app); +void gkyl_gyrokinetic_app_release_geom(gkyl_gyrokinetic_app *app); /** * Reset the CFL factor for the omega_H frequency. @@ -1458,8 +1545,9 @@ void gkyl_gyrokinetic_app_release_geom(gkyl_gyrokinetic_app* app); * @param tm Time-stamp. * @param cfl_frac_omegaH New CFL factor to use for the omega_H mode. */ -void gkyl_gyrokinetic_app_reset_cfl_frac_omegaH(gkyl_gyrokinetic_app* app, double tm, - double cfl_frac_omegaH); +void gkyl_gyrokinetic_app_reset_cfl_frac_omegaH( + gkyl_gyrokinetic_app *app, double tm, double cfl_frac_omegaH +); /** * Reset the df/dt multiplier operator for a given species. @@ -1469,8 +1557,10 @@ void gkyl_gyrokinetic_app_reset_cfl_frac_omegaH(gkyl_gyrokinetic_app* app, doubl * @param species_name Name of the species to reset. * @param fdot_mult_inp Input struct for the fdot_multiplier. */ -void gkyl_gyrokinetic_app_reset_species_fdot_multiplier(gkyl_gyrokinetic_app* app, double tm, - const char *species_name, struct gkyl_gyrokinetic_fdot_multiplier fdot_mult_inp); +void gkyl_gyrokinetic_app_reset_species_fdot_multiplier( + gkyl_gyrokinetic_app *app, double tm, const char *species_name, + struct gkyl_gyrokinetic_fdot_multiplier fdot_mult_inp +); /** * Reset the collisionless multiplier for a given species. @@ -1480,8 +1570,10 @@ void gkyl_gyrokinetic_app_reset_species_fdot_multiplier(gkyl_gyrokinetic_app* ap * @param species_name Name of the species to reset. * @param gkcls Input parameters for collisionless terms. */ -void gkyl_gyrokinetic_app_reset_species_collisionless(gkyl_gyrokinetic_app* app, double tm, - const char *species_name, struct gkyl_gyrokinetic_collisionless gkcls_inp); +void gkyl_gyrokinetic_app_reset_species_collisionless( + gkyl_gyrokinetic_app *app, double tm, const char *species_name, + struct gkyl_gyrokinetic_collisionless gkcls_inp +); /** * Reset enforce_positivity for a given species. @@ -1490,8 +1582,10 @@ void gkyl_gyrokinetic_app_reset_species_collisionless(gkyl_gyrokinetic_app* app, * @param tm Time-stamp. * @param pos_inp Positivity input parameters. */ -void gkyl_gyrokinetic_app_reset_species_positivity(gkyl_gyrokinetic_app* app, double tm, - const char *species_name, struct gkyl_gyrokinetic_positivity pos_inp); +void gkyl_gyrokinetic_app_reset_species_positivity( + gkyl_gyrokinetic_app *app, double tm, const char *species_name, + struct gkyl_gyrokinetic_positivity pos_inp +); /** * Reset the field solver. @@ -1500,5 +1594,6 @@ void gkyl_gyrokinetic_app_reset_species_positivity(gkyl_gyrokinetic_app* app, do * @param tm Time-stamp. * @param field_inp Input struct for the field object. */ -void gkyl_gyrokinetic_app_reset_field(gkyl_gyrokinetic_app* app, double tm, - struct gkyl_gyrokinetic_field field_inp); +void gkyl_gyrokinetic_app_reset_field( + gkyl_gyrokinetic_app *app, double tm, struct gkyl_gyrokinetic_field field_inp +); diff --git a/gyrokinetic/apps/gkyl_gyrokinetic_comms.h b/gyrokinetic/apps/gkyl_gyrokinetic_comms.h index 163412c1a4..0975fbed55 100644 --- a/gyrokinetic/apps/gkyl_gyrokinetic_comms.h +++ b/gyrokinetic/apps/gkyl_gyrokinetic_comms.h @@ -20,8 +20,7 @@ * @param Pointer to place where to put error messages. * @return New gkyl_comm communicator object. */ -struct gkyl_comm* -gkyl_gyrokinetic_comms_new(bool use_mpi, bool use_gpu, FILE *iostream); +struct gkyl_comm *gkyl_gyrokinetic_comms_new(bool use_mpi, bool use_gpu, FILE *iostream); /** * Free gyrokinetic app decomp and comm objects. @@ -29,5 +28,4 @@ gkyl_gyrokinetic_comms_new(bool use_mpi, bool use_gpu, FILE *iostream); * @param decomp Decomposition object. * @param comm Communicator object. */ -void -gkyl_gyrokinetic_comms_release(struct gkyl_comm *comm); +void gkyl_gyrokinetic_comms_release(struct gkyl_comm *comm); diff --git a/gyrokinetic/apps/gkyl_gyrokinetic_lw.h b/gyrokinetic/apps/gkyl_gyrokinetic_lw.h index 90bc66fcb8..6b136dfeec 100644 --- a/gyrokinetic/apps/gkyl_gyrokinetic_lw.h +++ b/gyrokinetic/apps/gkyl_gyrokinetic_lw.h @@ -12,77 +12,67 @@ */ void gkyl_gyrokinetic_lw_openlibs(lua_State *L); - /** * Add FEM boundary condition flags for gyrokinetic field initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_gyrokinetic_fem_bc_types(lua_State *L); +void gkyl_register_gyrokinetic_fem_bc_types(lua_State *L); /** * Add geometry type flags for gyrokinetic app initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_gyrokinetic_geometry_types(lua_State *L); +void gkyl_register_gyrokinetic_geometry_types(lua_State *L); /** * Add position map type flags for gyrokinetic app initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_gyrokinetic_position_map_types(lua_State *L); +void gkyl_register_gyrokinetic_position_map_types(lua_State *L); /** * Add field type flags for gyrokinetic field initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_gyrokinetic_field_types(lua_State *L); +void gkyl_register_gyrokinetic_field_types(lua_State *L); /** * Add radiation type flags for gyrokinetic species initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_gyrokinetic_radiation_types(lua_State *L); +void gkyl_register_gyrokinetic_radiation_types(lua_State *L); /** * Add Te model type flags for gyrokinetic radiation initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_gyrokinetic_radiation_Te_types(lua_State *L); +void gkyl_register_gyrokinetic_radiation_Te_types(lua_State *L); /** * Add reaction type flags for gyrokinetic species initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_gyrokinetic_reaction_types(lua_State *L); +void gkyl_register_gyrokinetic_reaction_types(lua_State *L); /** * Add ion type flags for gyrokinetic species initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_gyrokinetic_ion_types(lua_State *L); +void gkyl_register_gyrokinetic_ion_types(lua_State *L); /** * Add self-reaction type flags for gyrokinetic species initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_gyrokinetic_self_reaction_types(lua_State *L); +void gkyl_register_gyrokinetic_self_reaction_types(lua_State *L); #endif diff --git a/gyrokinetic/apps/gkyl_gyrokinetic_multib.h b/gyrokinetic/apps/gkyl_gyrokinetic_multib.h index e47288d6f1..a89accaf44 100644 --- a/gyrokinetic/apps/gkyl_gyrokinetic_multib.h +++ b/gyrokinetic/apps/gkyl_gyrokinetic_multib.h @@ -31,7 +31,8 @@ struct gkyl_gyrokinetic_multib_species { int num_diag_moments; // Number of diagnostic moments. enum gkyl_distribution_moments diag_moments[12]; // List of diagnostic moments. int num_integrated_diag_moments; // Number of integrated diagnostic moments. - enum gkyl_distribution_moments integrated_diag_moments[12]; // List of integrated diagnostic moments. + enum gkyl_distribution_moments + integrated_diag_moments[12]; // List of integrated diagnostic moments. bool time_rate_diagnostics; // Whether to ouput df/dt diagnostics. struct gkyl_phase_diagnostics_inp boundary_flux_diagnostics; @@ -92,7 +93,7 @@ struct gkyl_gyrokinetic_multib_neut_species { // Reactions with plasma species to include. struct gkyl_gyrokinetic_react react_neut; - bool duplicate_across_blocks; // set to true if all blocks are identical + bool duplicate_across_blocks; // set to true if all blocks are identical // species inputs per-block: only one is needed if duplicate_across_blocks = true const struct gkyl_gyrokinetic_multib_neut_species_pb *blocks; @@ -101,7 +102,7 @@ struct gkyl_gyrokinetic_multib_neut_species { const struct gkyl_gyrokinetic_bc *bcs; }; -// Field input per block +// Field input per block struct gkyl_gyrokinetic_multib_field_pb { int block_id; // block ID @@ -113,15 +114,17 @@ struct gkyl_gyrokinetic_multib_field_pb { void *phi_wall_lo_ctx; // context for biased wall potential on lower wall // pointer to biased wall potential on lower wall function void (*phi_wall_lo)(double t, const double *xn, double *phi_wall_lo_out, void *ctx); - bool phi_wall_lo_evolve; // set to true if biased wall potential on lower wall function is time dependent + bool + phi_wall_lo_evolve; // set to true if biased wall potential on lower wall function is time dependent void *phi_wall_up_ctx; // context for biased wall potential on upper wall // pointer to biased wall potential on upper wall function void (*phi_wall_up)(double t, const double *xn, double *phi_wall_up_out, void *ctx); - bool phi_wall_up_evolve; // set to true if biased wall potential on upper wall function is time dependent + bool + phi_wall_up_evolve; // set to true if biased wall potential on upper wall function is time dependent }; -// Field input +// Field input struct gkyl_gyrokinetic_multib_field { enum gkyl_gkfield_id gkfield_id; double kperpSq; // kperp^2 parameter for 1D field equations @@ -131,10 +134,10 @@ struct gkyl_gyrokinetic_multib_field { //struct gkyl_poisson_bc poisson_bcs; - bool duplicate_across_blocks; // set to true if all blocks are identical + bool duplicate_across_blocks; // set to true if all blocks are identical // field inputs per-block: only one is needed if duplicate_across_blocks = true - bool half_domain; // For use in double null simulations. - // If true core BCs will be set for simulation of lower half of domain (Z < 0) + bool half_domain; // For use in double null simulations. + // If true core BCs will be set for simulation of lower half of domain (Z < 0) const struct gkyl_gyrokinetic_multib_field_pb *blocks; // Physical boundary conditions @@ -142,7 +145,7 @@ struct gkyl_gyrokinetic_multib_field { const struct gkyl_gyrokinetic_bc *bcs; bool time_rate_diagnostics; // Writes the time rate of change of field energy. - + struct gkyl_poisson_bias_line_list *bias_line_list; // Biased lines constraining the solution. }; @@ -160,7 +163,7 @@ struct gkyl_gyrokinetic_multib { double cfl_frac; // CFL fraction to use (default 1.0) double cfl_frac_omegaH; // CFL fraction to use for omegaH (default 1.7) - + int num_periodic_dir; // Number of periodic directions. int periodic_dirs[3]; // List of periodic directions. @@ -179,8 +182,8 @@ struct gkyl_gyrokinetic_multib { // EIRENE inputs struct gkyl_gyrokinetic_eirene eirene; - // Communicator to use. - struct gkyl_comm *comm; + // Communicator to use. + struct gkyl_comm *comm; struct gkyl_gyrokinetic_metadata_inp metadata; // Optional metadata for output files. }; @@ -192,7 +195,8 @@ struct gkyl_gyrokinetic_multib { * initialized * @return New multi-block gk app object. */ -gkyl_gyrokinetic_multib_app* gkyl_gyrokinetic_multib_app_new(const struct gkyl_gyrokinetic_multib *mbinp); +gkyl_gyrokinetic_multib_app * +gkyl_gyrokinetic_multib_app_new(const struct gkyl_gyrokinetic_multib *mbinp); /** * Construct a new gk multi-block app (geom only). @@ -201,7 +205,8 @@ gkyl_gyrokinetic_multib_app* gkyl_gyrokinetic_multib_app_new(const struct gkyl_g * initialized * @return New multi-block gk app object. */ -gkyl_gyrokinetic_multib_app* gkyl_gyrokinetic_multib_app_new_geom(const struct gkyl_gyrokinetic_multib *mbinp); +gkyl_gyrokinetic_multib_app * +gkyl_gyrokinetic_multib_app_new_geom(const struct gkyl_gyrokinetic_multib *mbinp); /** * Initialize species by projecting initial conditions on @@ -210,7 +215,7 @@ gkyl_gyrokinetic_multib_app* gkyl_gyrokinetic_multib_app_new_geom(const struct g * @param app App object. * @param t0 Time for initial conditions. */ -void gkyl_gyrokinetic_multib_app_apply_ic(gkyl_gyrokinetic_multib_app* app, double t0); +void gkyl_gyrokinetic_multib_app_apply_ic(gkyl_gyrokinetic_multib_app *app, double t0); /** * Initialize species by projecting initial conditions on basis @@ -221,7 +226,9 @@ void gkyl_gyrokinetic_multib_app_apply_ic(gkyl_gyrokinetic_multib_app* app, doub * @param sidx Index of species to initialize. * @param t0 Time for initial conditions */ -void gkyl_gyrokinetic_multib_app_apply_ic_species(gkyl_gyrokinetic_multib_app* app, int sidx, double t0); +void gkyl_gyrokinetic_multib_app_apply_ic_species( + gkyl_gyrokinetic_multib_app *app, int sidx, double t0 +); /** * Initialize neutral species by projecting initial conditions on basis @@ -232,7 +239,9 @@ void gkyl_gyrokinetic_multib_app_apply_ic_species(gkyl_gyrokinetic_multib_app* a * @param sidx Index of neutral species to initialize. * @param t0 Time for initial conditions */ -void gkyl_gyrokinetic_multib_app_apply_ic_neut_species(gkyl_gyrokinetic_multib_app* app, int sidx, double t0); +void gkyl_gyrokinetic_multib_app_apply_ic_neut_species( + gkyl_gyrokinetic_multib_app *app, int sidx, double t0 +); /** * Initialize field from file @@ -250,9 +259,9 @@ gkyl_gyrokinetic_multib_app_from_file_field(gkyl_gyrokinetic_multib_app *app, co * @param sidx gk species index * @param fname file to read */ -struct gkyl_app_restart_status -gkyl_gyrokinetic_multib_app_from_file_species(gkyl_gyrokinetic_multib_app *app, int sidx, - const char *fname); +struct gkyl_app_restart_status gkyl_gyrokinetic_multib_app_from_file_species( + gkyl_gyrokinetic_multib_app *app, int sidx, const char *fname +); /** * Initialize neutral species from file @@ -261,9 +270,9 @@ gkyl_gyrokinetic_multib_app_from_file_species(gkyl_gyrokinetic_multib_app *app, * @param sidx neut species index * @param fname file to read */ -struct gkyl_app_restart_status -gkyl_gyrokinetic_multib_app_from_file_neut_species(gkyl_gyrokinetic_multib_app *app, int sidx, - const char *fname); +struct gkyl_app_restart_status gkyl_gyrokinetic_multib_app_from_file_neut_species( + gkyl_gyrokinetic_multib_app *app, int sidx, const char *fname +); /** * Initialize the gyrokinetic app from a specific frame. @@ -290,8 +299,9 @@ gkyl_gyrokinetic_multib_app_from_frame_field(gkyl_gyrokinetic_multib_app *app, i * @param sidx gk species index * @param frame frame to read */ -struct gkyl_app_restart_status -gkyl_gyrokinetic_multib_app_from_frame_species(gkyl_gyrokinetic_multib_app *app, int sidx, int frame); +struct gkyl_app_restart_status gkyl_gyrokinetic_multib_app_from_frame_species( + gkyl_gyrokinetic_multib_app *app, int sidx, int frame +); /** * Initialize neutral species from file @@ -300,8 +310,9 @@ gkyl_gyrokinetic_multib_app_from_frame_species(gkyl_gyrokinetic_multib_app *app, * @param sidx neut species index * @param frame frame to read */ -struct gkyl_app_restart_status -gkyl_gyrokinetic_multib_app_from_frame_neut_species(gkyl_gyrokinetic_multib_app *app, int sidx, int frame); +struct gkyl_app_restart_status gkyl_gyrokinetic_multib_app_from_frame_neut_species( + gkyl_gyrokinetic_multib_app *app, int sidx, int frame +); /** * Write output to console: this is mainly for diagnostic messages the @@ -313,14 +324,16 @@ gkyl_gyrokinetic_multib_app_from_frame_neut_species(gkyl_gyrokinetic_multib_app * @param fmt Format string for console output * @param argp Objects to write */ -void gkyl_gyrokinetic_multib_app_cout(const gkyl_gyrokinetic_multib_app* app, FILE *fp, const char *fmt, ...); +void gkyl_gyrokinetic_multib_app_cout( + const gkyl_gyrokinetic_multib_app *app, FILE *fp, const char *fmt, ... +); /** * Write block topology to file. * * @param app App object. */ -void gkyl_gyrokinetic_multib_app_write_topo(const gkyl_gyrokinetic_multib_app* app); +void gkyl_gyrokinetic_multib_app_write_topo(const gkyl_gyrokinetic_multib_app *app); /** * Write geometry file. @@ -336,7 +349,7 @@ void gkyl_gyrokinetic_multib_app_write_geometry(gkyl_gyrokinetic_multib_app *app * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_field(gkyl_gyrokinetic_multib_app* app, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_field(gkyl_gyrokinetic_multib_app *app, double tm, int frame); /** * Calculate integrated field energy @@ -344,7 +357,7 @@ void gkyl_gyrokinetic_multib_app_write_field(gkyl_gyrokinetic_multib_app* app, d * @param tm Time at which integrated diagnostic are to be computed * @param app App object. */ -void gkyl_gyrokinetic_multib_app_calc_field_energy(gkyl_gyrokinetic_multib_app* app, double tm); +void gkyl_gyrokinetic_multib_app_calc_field_energy(gkyl_gyrokinetic_multib_app *app, double tm); /** * Write field energy to file. Field energy data is appended to the @@ -352,7 +365,7 @@ void gkyl_gyrokinetic_multib_app_calc_field_energy(gkyl_gyrokinetic_multib_app* * * @param app App object. */ -void gkyl_gyrokinetic_multib_app_write_field_energy(gkyl_gyrokinetic_multib_app* app); +void gkyl_gyrokinetic_multib_app_write_field_energy(gkyl_gyrokinetic_multib_app *app); /** * Write species data to file. @@ -362,7 +375,9 @@ void gkyl_gyrokinetic_multib_app_write_field_energy(gkyl_gyrokinetic_multib_app* * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write neutral species data to file. @@ -372,7 +387,9 @@ void gkyl_gyrokinetic_multib_app_write_species(gkyl_gyrokinetic_multib_app* app, * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_neut_species(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_neut_species( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write diagnostic moments for species to file. @@ -382,7 +399,9 @@ void gkyl_gyrokinetic_multib_app_write_neut_species(gkyl_gyrokinetic_multib_app* * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species_mom(gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write diagnostic moments for neutral species to file. @@ -392,7 +411,9 @@ void gkyl_gyrokinetic_multib_app_write_species_mom(gkyl_gyrokinetic_multib_app * * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_neut_species_mom(gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_neut_species_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Calculate integrated diagnostic moments for a plasma species. @@ -401,7 +422,9 @@ void gkyl_gyrokinetic_multib_app_write_neut_species_mom(gkyl_gyrokinetic_multib_ * @param sidx Index of species to initialize. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_multib_app_calc_species_integrated_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm); +void gkyl_gyrokinetic_multib_app_calc_species_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +); /** * Calculate integrated diagnostic moments for a neutral species. @@ -410,7 +433,9 @@ void gkyl_gyrokinetic_multib_app_calc_species_integrated_mom(gkyl_gyrokinetic_mu * @param sidx Index of neutral species to initialize. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_multib_app_calc_neut_species_integrated_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm); +void gkyl_gyrokinetic_multib_app_calc_neut_species_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +); /** * Calculate integrated diagnostic moments of the boundary fluxes for a plasma species. @@ -419,7 +444,9 @@ void gkyl_gyrokinetic_multib_app_calc_neut_species_integrated_mom(gkyl_gyrokinet * @param sidx Index of species to initialize. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_multib_app_calc_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm); +void gkyl_gyrokinetic_multib_app_calc_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +); /** * Write integrated diagnostic moments for charged species to file. Integrated @@ -428,7 +455,9 @@ void gkyl_gyrokinetic_multib_app_calc_species_boundary_flux_integrated_mom(gkyl_ * @param app App object. * @param sidx Index of species to initialize. */ -void gkyl_gyrokinetic_multib_app_write_species_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx); +void gkyl_gyrokinetic_multib_app_write_species_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +); /** * Write integrated diagnostic moments for neutral species to file. Integrated @@ -437,7 +466,9 @@ void gkyl_gyrokinetic_multib_app_write_species_integrated_mom(gkyl_gyrokinetic_m * @param app App object. * @param sidx Index of neutral species to initialize. */ -void gkyl_gyrokinetic_multib_app_write_neut_species_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx); +void gkyl_gyrokinetic_multib_app_write_neut_species_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +); /** * Write integrated diagnostic moments of the boundary fluxes for charged @@ -446,7 +477,9 @@ void gkyl_gyrokinetic_multib_app_write_neut_species_integrated_mom(gkyl_gyrokine * @param app App object. * @param sidx Index of species to initialize. */ -void gkyl_gyrokinetic_multib_app_write_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx); +void gkyl_gyrokinetic_multib_app_write_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +); /** * Write species source to file. @@ -456,7 +489,9 @@ void gkyl_gyrokinetic_multib_app_write_species_boundary_flux_integrated_mom(gkyl * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species_source(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_source( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write neutral species source to file. @@ -466,7 +501,9 @@ void gkyl_gyrokinetic_multib_app_write_species_source(gkyl_gyrokinetic_multib_ap * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_neut_species_source(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_neut_species_source( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write diagnostic moments for species source to file. @@ -476,7 +513,9 @@ void gkyl_gyrokinetic_multib_app_write_neut_species_source(gkyl_gyrokinetic_mult * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species_source_mom(gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_source_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write diagnostic moments for neutral species source to file. @@ -486,7 +525,9 @@ void gkyl_gyrokinetic_multib_app_write_species_source_mom(gkyl_gyrokinetic_multi * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_neut_species_source_mom(gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_neut_species_source_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Calculate integrated diagnostic moments for a plasma species source. @@ -495,7 +536,9 @@ void gkyl_gyrokinetic_multib_app_write_neut_species_source_mom(gkyl_gyrokinetic_ * @param sidx Index of species to write. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_multib_app_calc_species_source_integrated_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm); +void gkyl_gyrokinetic_multib_app_calc_species_source_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +); /** * Calculate integrated diagnostic moments for a neutral species source. @@ -504,7 +547,9 @@ void gkyl_gyrokinetic_multib_app_calc_species_source_integrated_mom(gkyl_gyrokin * @param sidx Index of neutral species to write. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_multib_app_calc_neut_species_source_integrated_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm); +void gkyl_gyrokinetic_multib_app_calc_neut_species_source_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +); /** * Write integrated diagnostic moments for charged species source to file. Integrated @@ -513,7 +558,9 @@ void gkyl_gyrokinetic_multib_app_calc_neut_species_source_integrated_mom(gkyl_gy * @param app App object. * @param sidx Index of species to write. */ -void gkyl_gyrokinetic_multib_app_write_species_source_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx); +void gkyl_gyrokinetic_multib_app_write_species_source_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +); /** * Write integrated diagnostic moments for neutral species source to file. Integrated @@ -522,7 +569,9 @@ void gkyl_gyrokinetic_multib_app_write_species_source_integrated_mom(gkyl_gyroki * @param app App object. * @param sidx Index of neutral species to write. */ -void gkyl_gyrokinetic_multib_app_write_neut_species_source_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx); +void gkyl_gyrokinetic_multib_app_write_neut_species_source_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +); /** * Write species integrated correct Maxwellian status of the to file. @@ -531,7 +580,9 @@ void gkyl_gyrokinetic_multib_app_write_neut_species_source_integrated_mom(gkyl_g * @param app App object. * @param sidx Index of species to write. */ -void gkyl_gyrokinetic_multib_app_write_species_lte_max_corr_status(gkyl_gyrokinetic_multib_app *app, int sidx); +void gkyl_gyrokinetic_multib_app_write_species_lte_max_corr_status( + gkyl_gyrokinetic_multib_app *app, int sidx +); /** * Write neutral species integrated correct Maxwellian status of the to file. @@ -540,7 +591,9 @@ void gkyl_gyrokinetic_multib_app_write_species_lte_max_corr_status(gkyl_gyrokine * @param app App object. * @param sidx Index of species to write. */ -void gkyl_gyrokinetic_multib_app_write_neut_species_lte_max_corr_status(gkyl_gyrokinetic_multib_app *app, int sidx); +void gkyl_gyrokinetic_multib_app_write_neut_species_lte_max_corr_status( + gkyl_gyrokinetic_multib_app *app, int sidx +); /** * Write LBO collisional moments for species to file. @@ -550,7 +603,9 @@ void gkyl_gyrokinetic_multib_app_write_neut_species_lte_max_corr_status(gkyl_gyr * @param tm Time-stamp. * @param frame Frame number. */ -void gkyl_gyrokinetic_multib_app_write_species_lbo_mom(gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_lbo_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write BGK cross moments for species to file. @@ -560,7 +615,9 @@ void gkyl_gyrokinetic_multib_app_write_species_lbo_mom(gkyl_gyrokinetic_multib_a * @param tm Time-stamp. * @param frame Frame number. */ -void gkyl_gyrokinetic_multib_app_write_species_bgk_mom(gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_bgk_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write radiation drag coefficients for species to file. @@ -570,7 +627,9 @@ void gkyl_gyrokinetic_multib_app_write_species_bgk_mom(gkyl_gyrokinetic_multib_a * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species_rad_drag(gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_rad_drag( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write radiation emissivity of each species that species sidx collides with @@ -580,7 +639,9 @@ void gkyl_gyrokinetic_multib_app_write_species_rad_drag(gkyl_gyrokinetic_multib_ * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species_rad_emissivity(gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_rad_emissivity( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Calculate integrated diagnostic moments of the radiation model. @@ -589,7 +650,9 @@ void gkyl_gyrokinetic_multib_app_write_species_rad_emissivity(gkyl_gyrokinetic_m * @param sidx Index of species to write. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_multib_app_calc_species_rad_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx, double tm); +void gkyl_gyrokinetic_multib_app_calc_species_rad_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +); /** * Write integrated moments of radiation rhs for radiating species @@ -597,7 +660,9 @@ void gkyl_gyrokinetic_multib_app_calc_species_rad_integrated_mom(gkyl_gyrokineti * @param app App object. * @param sidx Index of species from which to write radiation. */ -void gkyl_gyrokinetic_multib_app_write_species_rad_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx); +void gkyl_gyrokinetic_multib_app_write_species_rad_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +); /** * Write iz react rate coefficients for species to file. @@ -608,7 +673,9 @@ void gkyl_gyrokinetic_multib_app_write_species_rad_integrated_mom(gkyl_gyrokinet * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species_iz_react(gkyl_gyrokinetic_multib_app* app, int sidx, int ridx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_iz_react( + gkyl_gyrokinetic_multib_app *app, int sidx, int ridx, double tm, int frame +); /** * Write iz react rate coefficients for species to file. @@ -619,7 +686,9 @@ void gkyl_gyrokinetic_multib_app_write_species_iz_react(gkyl_gyrokinetic_multib_ * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species_iz_react_neut(gkyl_gyrokinetic_multib_app* app, int sidx, int ridx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_iz_react_neut( + gkyl_gyrokinetic_multib_app *app, int sidx, int ridx, double tm, int frame +); /** * Write recomb react rate coefficients for species to file. @@ -630,7 +699,9 @@ void gkyl_gyrokinetic_multib_app_write_species_iz_react_neut(gkyl_gyrokinetic_mu * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species_recomb_react(gkyl_gyrokinetic_multib_app* app, int sidx, int ridx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_recomb_react( + gkyl_gyrokinetic_multib_app *app, int sidx, int ridx, double tm, int frame +); /** * Write recomb react rate coefficients for species to file. @@ -641,7 +712,9 @@ void gkyl_gyrokinetic_multib_app_write_species_recomb_react(gkyl_gyrokinetic_mul * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species_recomb_react_neut(gkyl_gyrokinetic_multib_app* app, int sidx, int ridx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_recomb_react_neut( + gkyl_gyrokinetic_multib_app *app, int sidx, int ridx, double tm, int frame +); /** * Write cx react rate coefficients for species to file. @@ -652,7 +725,9 @@ void gkyl_gyrokinetic_multib_app_write_species_recomb_react_neut(gkyl_gyrokineti * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_cx_react_neut(gkyl_gyrokinetic_multib_app* app, int sidx, int ridx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_cx_react_neut( + gkyl_gyrokinetic_multib_app *app, int sidx, int ridx, double tm, int frame +); /** * Write the phase-space diagnostics for a charged species. @@ -662,7 +737,9 @@ void gkyl_gyrokinetic_multib_app_write_cx_react_neut(gkyl_gyrokinetic_multib_app * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species_phase(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_phase( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write the phase-space diagnostics for a neutral species. @@ -672,7 +749,9 @@ void gkyl_gyrokinetic_multib_app_write_species_phase(gkyl_gyrokinetic_multib_app * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_neut_species_phase(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_neut_species_phase( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write the conf-space diagnostics for a charged species. @@ -682,7 +761,9 @@ void gkyl_gyrokinetic_multib_app_write_neut_species_phase(gkyl_gyrokinetic_multi * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_species_conf(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_species_conf( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write the conf-space diagnostics for a neutral species. @@ -692,7 +773,9 @@ void gkyl_gyrokinetic_multib_app_write_species_conf(gkyl_gyrokinetic_multib_app* * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_neut_species_conf(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_neut_species_conf( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +); /** * Write diagnostic moments for all species (including sources) to file. @@ -709,7 +792,7 @@ void gkyl_gyrokinetic_multib_app_write_mom(gkyl_gyrokinetic_multib_app *app, dou * @param app App object. * @param tm Time at which integrated diagnostics are to be computed */ -void gkyl_gyrokinetic_multib_app_calc_integrated_mom(gkyl_gyrokinetic_multib_app* app, double tm); +void gkyl_gyrokinetic_multib_app_calc_integrated_mom(gkyl_gyrokinetic_multib_app *app, double tm); /** * Write integrated diagnostic moments for all species (including sources) @@ -726,7 +809,7 @@ void gkyl_gyrokinetic_multib_app_write_integrated_mom(gkyl_gyrokinetic_multib_ap * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_phase(gkyl_gyrokinetic_multib_app* app, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_phase(gkyl_gyrokinetic_multib_app *app, double tm, int frame); /** * Write configuration space diagnostics to file. @@ -735,7 +818,7 @@ void gkyl_gyrokinetic_multib_app_write_phase(gkyl_gyrokinetic_multib_app* app, d * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write_conf(gkyl_gyrokinetic_multib_app* app, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write_conf(gkyl_gyrokinetic_multib_app *app, double tm, int frame); /** * Write both conf and phase-space diagnostics to file. @@ -744,14 +827,14 @@ void gkyl_gyrokinetic_multib_app_write_conf(gkyl_gyrokinetic_multib_app* app, do * @param tm Time-stamp * @param frame Frame number */ -void gkyl_gyrokinetic_multib_app_write(gkyl_gyrokinetic_multib_app* app, double tm, int frame); +void gkyl_gyrokinetic_multib_app_write(gkyl_gyrokinetic_multib_app *app, double tm, int frame); /** * Write stats to file. Data is written in json format. * * @param app App object. */ -void gkyl_gyrokinetic_multib_app_stat_write(gkyl_gyrokinetic_multib_app* app); +void gkyl_gyrokinetic_multib_app_stat_write(gkyl_gyrokinetic_multib_app *app); /** * Print timing of solver components to iostream. @@ -759,8 +842,7 @@ void gkyl_gyrokinetic_multib_app_stat_write(gkyl_gyrokinetic_multib_app* app); * @param app App object. * @param iostream Where to write timers to (e.g. stdout, stderr); */ -void -gkyl_gyrokinetic_multib_app_print_timings(gkyl_gyrokinetic_multib_app* app, FILE *iostream); +void gkyl_gyrokinetic_multib_app_print_timings(gkyl_gyrokinetic_multib_app *app, FILE *iostream); /** * Record the time step (in private dynvector). @@ -769,16 +851,14 @@ gkyl_gyrokinetic_multib_app_print_timings(gkyl_gyrokinetic_multib_app* app, FILE * @param tm Time stamp. * @param dt Time step to record (e.g. provided by app's status object). */ -void -gkyl_gyrokinetic_multib_app_save_dt(gkyl_gyrokinetic_multib_app* app, double tm, double dt); +void gkyl_gyrokinetic_multib_app_save_dt(gkyl_gyrokinetic_multib_app *app, double tm, double dt); /** * Write the time step over time. * * @param app App object. */ -void -gkyl_gyrokinetic_multib_app_write_dt(gkyl_gyrokinetic_multib_app* app); +void gkyl_gyrokinetic_multib_app_write_dt(gkyl_gyrokinetic_multib_app *app); /** * Read geometry file. @@ -797,7 +877,9 @@ void gkyl_gyrokinetic_multib_app_read_geometry(gkyl_gyrokinetic_multib_app *app) * @param fmt Format string for console output * @param argp Objects to write */ -void gkyl_gyrokinetic_multib_app_cout(const gkyl_gyrokinetic_multib_app* app, FILE *fp, const char *fmt, ...); +void gkyl_gyrokinetic_multib_app_cout( + const gkyl_gyrokinetic_multib_app *app, FILE *fp, const char *fmt, ... +); /** * Advance simulation by a suggested time-step 'dt'. The dt may be too @@ -815,25 +897,26 @@ void gkyl_gyrokinetic_multib_app_cout(const gkyl_gyrokinetic_multib_app* app, FI * @param dt Suggested time-step to advance simulation * @return Status of update. */ -struct gkyl_update_status gkyl_gyrokinetic_multib_update(gkyl_gyrokinetic_multib_app* app, double dt); +struct gkyl_update_status +gkyl_gyrokinetic_multib_update(gkyl_gyrokinetic_multib_app *app, double dt); /** * Return simulation statistics. * * @return Return statistics object. */ -struct gkyl_gyrokinetic_stat gkyl_gyrokinetic_multib_app_stat(gkyl_gyrokinetic_multib_app* app); +struct gkyl_gyrokinetic_stat gkyl_gyrokinetic_multib_app_stat(gkyl_gyrokinetic_multib_app *app); /** * Free gk app. * * @param app App to release. */ -void gkyl_gyrokinetic_multib_app_release(gkyl_gyrokinetic_multib_app* app); +void gkyl_gyrokinetic_multib_app_release(gkyl_gyrokinetic_multib_app *app); /** * Free gk app (geom only). * * @param app App to release. */ -void gkyl_gyrokinetic_multib_app_release_geom(gkyl_gyrokinetic_multib_app* app); +void gkyl_gyrokinetic_multib_app_release_geom(gkyl_gyrokinetic_multib_app *app); diff --git a/gyrokinetic/apps/gkyl_gyrokinetic_multib_priv.h b/gyrokinetic/apps/gkyl_gyrokinetic_multib_priv.h index 59fc205f86..500539704c 100644 --- a/gyrokinetic/apps/gkyl_gyrokinetic_multib_priv.h +++ b/gyrokinetic/apps/gkyl_gyrokinetic_multib_priv.h @@ -17,11 +17,11 @@ struct gkyl_gyrokinetic_multib_app { char name[128]; // name of app struct gkyl_comm *comm; // global communicator to use bool use_gpu; // Whether to use the GPU. - + // geometry and topology of all blocks in simulation struct gkyl_gk_block_geom *gk_block_geom; struct gkyl_block_topo *block_topo; - + double cfl_frac; // CFL fraction to use double bmag_ref; // Reference magnetic field int num_species; // number of species @@ -31,7 +31,7 @@ struct gkyl_gyrokinetic_multib_app { struct gk_multib_field *field; // Field object. char species_name[GKYL_MAX_SPECIES][128]; // name of each species - char neut_species_name[GKYL_MAX_SPECIES][128]; // name of each neutral species + char neut_species_name[GKYL_MAX_SPECIES][128]; // name of each neutral species struct gkyl_comm **block_comms; // list of block-communicators @@ -47,13 +47,13 @@ struct gkyl_gyrokinetic_multib_app { struct gkyl_mbcc_sr *mbcc_sync_neut; // Connections for neut species phase-space. double tcurr; // current time - + struct gkyl_gyrokinetic_stat stat; // statistics gkyl_dynvec dts; // Record time step over time. bool is_first_dt_write_call; // flag for integrated moments dynvec written first time - - struct gkyl_msgpack_map_elem* io_meta_basic; // Metadata for I/O. + + struct gkyl_msgpack_map_elem *io_meta_basic; // Metadata for I/O. int io_meta_basic_len; // Number of elements in io_meta. }; @@ -72,7 +72,7 @@ struct gk_multib_field { int num_local_blocks; // total number of blocks on current rank int cdim; // number of configuration space dimensions bool half_domain; // For use in double null - // Whether to set BCs for simulation of lower half (Z<0) + // Whether to set BCs for simulation of lower half (Z<0) int num_blocks_below[GKYL_MAX_BLOCKS]; int num_blocks_above[GKYL_MAX_BLOCKS]; @@ -105,7 +105,7 @@ struct gk_multib_field { struct gkyl_array **lhs_weight_multibz; struct gkyl_array **rhs_weight_multibz; struct gkyl_fem_parproj **fem_parproj; // FEM smoothing operator. - + // // Objects for perpendicular Poisson solve. // @@ -124,8 +124,10 @@ struct gk_multib_field { // Functions to advance MB field // Pointer to function to calculate the potential. - void (*rhs_func)(gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]); + void (*rhs_func)( + gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] + ); }; /** Time stepping API */ @@ -138,8 +140,10 @@ struct gk_multib_field { * @param fin Array of distribution functions (one for each species) . * @param bflux Moments of the boundary fluxes (for all blocks, all species, and all boundaries). */ -void gyrokinetic_multib_calc_field(struct gkyl_gyrokinetic_multib_app* app, double tcurr, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]); +void gyrokinetic_multib_calc_field( + struct gkyl_gyrokinetic_multib_app *app, double tcurr, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +); /** * Compute the gyrokinetic fields and apply boundary conditions. @@ -150,8 +154,10 @@ void gyrokinetic_multib_calc_field(struct gkyl_gyrokinetic_multib_app* app, doub * @param bflux Moments of the boundary fluxes (for all blocks, all species, and all boundaries). * @param distf_neut Array of distribution functions (for each neutral species). */ -void gyrokinetic_multib_calc_field_and_apply_bc(struct gkyl_gyrokinetic_multib_app* app, double tcurr, - struct gkyl_array *distf[], struct gkyl_array **bflux[], struct gkyl_array *distf_neut[]); +void gyrokinetic_multib_calc_field_and_apply_bc( + struct gkyl_gyrokinetic_multib_app *app, double tcurr, struct gkyl_array *distf[], + struct gkyl_array **bflux[], struct gkyl_array *distf_neut[] +); /** * Take time-step using the RK3 method. Also sets the status object @@ -161,7 +167,8 @@ void gyrokinetic_multib_calc_field_and_apply_bc(struct gkyl_gyrokinetic_multib_a * @param app Gyrokinetic app. * @param dt0 Suggessted time step. */ -struct gkyl_update_status gyrokinetic_multib_update_ssp_rk3(struct gkyl_gyrokinetic_multib_app* app, double dt0); +struct gkyl_update_status +gyrokinetic_multib_update_ssp_rk3(struct gkyl_gyrokinetic_multib_app *app, double dt0); /** Field API */ @@ -170,9 +177,9 @@ struct gkyl_update_status gyrokinetic_multib_update_ssp_rk3(struct gkyl_gyrokine * @param mbapp Gyrokinetic multib app. * return new multib field object */ -struct gk_multib_field* gk_multib_field_new(const struct gkyl_gyrokinetic_multib *mbinp, - struct gkyl_gyrokinetic_multib_app *mbapp); - +struct gk_multib_field *gk_multib_field_new( + const struct gkyl_gyrokinetic_multib *mbinp, struct gkyl_gyrokinetic_multib_app *mbapp +); /** Compute the electrostatic potential * @param mbapp Gyrokinetic multib app. @@ -180,8 +187,10 @@ struct gk_multib_field* gk_multib_field_new(const struct gkyl_gyrokinetic_multib * @param fin Distribution function (for all local blocks). * @param bflux Moments of the boundary fluxes (for all blocks, all species, and all boundaries). */ -void gk_multib_field_rhs(gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]); +void gk_multib_field_rhs( + gkyl_gyrokinetic_multib_app *mbapp, struct gk_multib_field *mbf, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +); /** Releas the resources for the multib field object * @param mbf Multib field object. diff --git a/gyrokinetic/apps/gkyl_gyrokinetic_priv.h b/gyrokinetic/apps/gkyl_gyrokinetic_priv.h index e8d0955901..de9340fdf4 100644 --- a/gyrokinetic/apps/gkyl_gyrokinetic_priv.h +++ b/gyrokinetic/apps/gkyl_gyrokinetic_priv.h @@ -118,10 +118,10 @@ struct correct_all_moms_inp { struct gk_species_moment { struct gk_geometry *gk_geom; // geometry struct for dividing moments by Jacobian struct gkyl_dg_bin_op_mem *mem_geo; // memory needed in dividing moments by Jacobian - bool is_integrated; // boolean for if computing integrated moments - // integrated moments do not need to divide by Jacobian since - // the inverse Jacobian is already included in the computation - int num_mom; // number of moments + bool is_integrated; // boolean for if computing integrated moments + // integrated moments do not need to divide by Jacobian since + // the inverse Jacobian is already included in the computation + int num_mom; // number of moments struct gkyl_array *marr; // array to moment data struct gkyl_array *marr_host; // host copy (same as marr if not on GPUs) @@ -136,49 +136,55 @@ struct gk_species_moment { int num_basis_conf; // Number of conf-space basis functions. double mass; // Species mass. // This method should probably be replaced by an updater. - void (*fluid_calc_M)(const struct gk_species_moment *sm, const struct gkyl_range phase_rng, - const struct gkyl_range conf_rng, const struct gkyl_array *fin); + void (*fluid_calc_M)( + const struct gk_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin + ); union { // Kinetic species .............................................. // struct { - // Options for moment calculation: + // Options for moment calculation: // 1. Compute the moment directly with dg_updater_moment_gyrokinetic // 2. Compute the moments of the equivalent Maxwellian (n, u_par, T/m) // 3. Compute the moments of the equivalent Bi-Maxwellian (n, u_par, T_par/m, T_perp/m) // Latter two options use specialized gkyl_gyrokinetic_maxwellian_moments updater union { struct { - struct gkyl_gk_maxwellian_moments *gyrokinetic_maxwellian_moms; + struct gkyl_gk_maxwellian_moments *gyrokinetic_maxwellian_moms; }; struct { struct gkyl_vlasov_lte_moments *vlasov_lte_moms; // Updater for computing LTE moments }; struct { - struct gkyl_dg_updater_moment *mcalc; + struct gkyl_dg_updater_moment *mcalc; }; }; }; // Fluid species .............................................. // struct { - struct gkyl_gk_neut_fluid_prim_vars *nf_prim_vars; + struct gkyl_gk_neut_fluid_prim_vars *nf_prim_vars; }; }; // Methods chosen at runtime. - void (*calc_func)(const struct gk_species_moment *sm, const struct gkyl_range phase_rng, - const struct gkyl_range conf_rng, const struct gkyl_array *fin); + void (*calc_func)( + const struct gk_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin + ); void (*release_func)(const struct gkyl_gyrokinetic_app *app, const struct gk_species_moment *sm); - void (*diag_jacobgeo_div_func)(const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, - struct gkyl_array *Jmom_in, struct gkyl_array *mom_out); + void (*diag_jacobgeo_div_func)( + const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, + struct gkyl_array *Jmom_in, struct gkyl_array *mom_out + ); }; // Forward declare species struct. struct gk_species; struct gk_neut_species; -struct gk_lte { +struct gk_lte { struct gkyl_array *f_lte; // Maxwellian distribution. struct gk_species_moment moms; // Computes Maxwellian moments. @@ -187,12 +193,12 @@ struct gk_lte { // also corrects the density of projected distribution function union { struct { - struct gkyl_gk_maxwellian_proj_on_basis *proj_max; - struct gkyl_gk_maxwellian_correct *corr_max; + struct gkyl_gk_maxwellian_proj_on_basis *proj_max; + struct gkyl_gk_maxwellian_correct *corr_max; }; struct { - struct gkyl_vlasov_lte_proj_on_basis *proj_lte; - struct gkyl_vlasov_lte_correct *corr_lte; + struct gkyl_vlasov_lte_proj_on_basis *proj_lte; + struct gkyl_vlasov_lte_correct *corr_lte; }; }; @@ -203,55 +209,65 @@ struct gk_lte { bool is_first_corr_status_write_call; // Methods chosen at runtime. - void (*from_moms_func)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_lte *lte, const struct gkyl_array *moms_lte); - void (*from_f_func)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_lte *lte, const struct gkyl_array *fin); - void (*write_max_corr_status_func)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gk_ns); + void (*from_moms_func)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_lte *lte, + const struct gkyl_array *moms_lte + ); + void (*from_f_func)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_lte *lte, + const struct gkyl_array *fin + ); + void (*write_max_corr_status_func)(gkyl_gyrokinetic_app *app, struct gk_neut_species *gk_ns); void (*release_func)(const struct gkyl_gyrokinetic_app *app, const struct gk_lte *lte); }; -struct gk_rad_drag { +struct gk_rad_drag { enum gkyl_radiation_id radiation_id; // Type of radiation. bool write_diagnostics; // Whether to write diagnostics out. int num_cross_collisions; // Number of species we cross-collide with. struct gk_species *collide_with[GKYL_MAX_SPECIES]; // Cross-species we collide with. - struct gk_neut_species *collide_with_neut[GKYL_MAX_SPECIES]; // Neutral cross-species we collide with. - int collide_with_idx[2*GKYL_MAX_SPECIES]; // Index of species we collide with. - bool is_neut_species[2*GKYL_MAX_SPECIES]; // Flag of whether neutral or Gk species. - + struct gk_neut_species + *collide_with_neut[GKYL_MAX_SPECIES]; // Neutral cross-species we collide with. + int collide_with_idx[2 * GKYL_MAX_SPECIES]; // Index of species we collide with. + bool is_neut_species[2 * GKYL_MAX_SPECIES]; // Flag of whether neutral or Gk species. + // Drag coefficients in vparallel and mu for each species being collided with. struct gkyl_gk_rad_drag *vnu_surf; struct gkyl_gk_rad_drag *vnu; struct gkyl_gk_rad_drag *vsqnu_surf; struct gkyl_gk_rad_drag *vsqnu; struct gkyl_dg_calc_gk_rad_vars *calc_gk_rad_vars; - struct gkyl_array *rad_fit_ne[2*GKYL_MAX_SPECIES]; + struct gkyl_array *rad_fit_ne[2 * GKYL_MAX_SPECIES]; - struct gk_species_moment moms[2*GKYL_MAX_SPECIES]; // Moments needed in radiation update (need number density). + struct gk_species_moment + moms[2 * GKYL_MAX_SPECIES]; // Moments needed in radiation update (need number density). struct gk_species_moment m2; // M2 of radiation update (needed for emissivity). - struct gkyl_array *emissivity[2*GKYL_MAX_SPECIES]; - struct gkyl_array *emissivity_host[2*GKYL_MAX_SPECIES]; + struct gkyl_array *emissivity[2 * GKYL_MAX_SPECIES]; + struct gkyl_array *emissivity_host[2 * GKYL_MAX_SPECIES]; struct gkyl_array *emissivity_rhs; struct gkyl_array *emissivity_denominator; - struct gkyl_array *nvnu_surf; // Total vparallel radiation drag surface expansion including density scaling. - struct gkyl_array *nvnu; // Total vparallel radiation drag volume expansion including density scaling. - struct gkyl_array *nvsqnu_surf; // Total mu radiation drag surface expansion including density scaling. + struct gkyl_array + *nvnu_surf; // Total vparallel radiation drag surface expansion including density scaling. + struct gkyl_array + *nvnu; // Total vparallel radiation drag volume expansion including density scaling. + struct gkyl_array + *nvsqnu_surf; // Total mu radiation drag surface expansion including density scaling. struct gkyl_array *nvsqnu; // Total mu radiation drag volume expansion including density scaling. - struct gkyl_array **vtsq_min_per_species; // Smallest vtsq that radiation is calculated (one for each - // fit), divided by configuration space normalization + struct gkyl_array * + *vtsq_min_per_species; // Smallest vtsq that radiation is calculated (one for each + // fit), divided by configuration space normalization struct gk_species_moment prim_moms; // Primitive moments. struct gkyl_array *vtsq; // Thermal speed squared. struct gkyl_array *m0; // M0 moment. // Host-side copies for I/O. - struct gkyl_array *nvnu_surf_host; - struct gkyl_array *nvnu_host; - struct gkyl_array *nvsqnu_surf_host; - struct gkyl_array *nvsqnu_host; + struct gkyl_array *nvnu_surf_host; + struct gkyl_array *nvnu_host; + struct gkyl_array *nvsqnu_surf_host; + struct gkyl_array *nvsqnu_host; gkyl_dg_updater_collisions *drag_slvr; // Radiation solver. @@ -259,21 +275,27 @@ struct gk_rad_drag { double *red_integ_diag, *red_integ_diag_global; // Reduced integrated moments. gkyl_dynvec integ_diag; // Integrated moments in time. bool is_first_integ_write_call; // Whether dynvec is being written for the 1st time. - - struct gkyl_msgpack_map_elem* io_meta_surfmu; // Metadata for I/O of mu surf array. + + struct gkyl_msgpack_map_elem *io_meta_surfmu; // Metadata for I/O of mu surf array. int io_meta_surfmu_len; // Number of elements in io_meta_surfmu. - struct gkyl_msgpack_map_elem* io_meta_surfvpar; // Metadata for I/O of vpar surf array. + struct gkyl_msgpack_map_elem *io_meta_surfvpar; // Metadata for I/O of vpar surf array. int io_meta_surfvpar_len; // Number of elements in io_meta_surfvpar. // Methods chosen at runtime: - void (*moms_func)(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]); - void (*rhs_func)(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin, struct gkyl_array *rhs); - void (*write_drag_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); - void (*write_emissivity_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); - void (*calc_integrated_mom_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm); - void (*write_integrated_mom_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks); + void (*moms_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] + ); + void (*rhs_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin, struct gkyl_array *rhs + ); + void (*write_drag_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame); + void (*write_emissivity_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame + ); + void (*calc_integrated_mom_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm); + void (*write_integrated_mom_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks); }; struct gk_collisionless { @@ -294,47 +316,60 @@ struct gk_collisionless { gkyl_dg_updater_gyrokinetic *slvr; // Collisionless solver (GK/EM cases). // Passive advection (only for GKYL_GK_COLLISIONLESS_PASSIVE). - struct gkyl_array *passive_speeds; // Conf-space passive speeds. + struct gkyl_array *passive_speeds; // Conf-space passive speeds. struct gkyl_array *passive_speeds_ho; // Host copy of passive_speeds. struct gkyl_gk_collisionless_passive_flux *passive_surf_flux_op; // Passive flux updater. gkyl_dg_updater_gyrokinetic_passive *passive_slvr; // Passive collisionless solver. // Methods chosen at runtime. - void (*flux_func)(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin); + void (*flux_func)( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin + ); }; // Neutral (Vlasov) species ............................................ // struct { struct gkyl_array *alpha_surf; // array for surface phase space flux (v^i = v . e^i) - struct gkyl_array *sgn_alpha_surf; // array for the sign of the surface phase space flux at quadrature points - // utilized for numerical flux function - // F = alpha_surf/2 ( (f^+ + f^-) - sign_alpha_surf*(f^+ - f^-) ) - struct gkyl_array *const_sgn_alpha; // boolean array for if the surface phase space flux is single signed - // if true, numerical flux function inside kernels simplifies to - // F = alpha_surf*f^- (if sign_alpha_surf = 1), - // F = alpha_surf*f^+ (if sign_alpha_surf = -1) + struct gkyl_array + *sgn_alpha_surf; // array for the sign of the surface phase space flux at quadrature points + // utilized for numerical flux function + // F = alpha_surf/2 ( (f^+ + f^-) - sign_alpha_surf*(f^+ - f^-) ) + struct gkyl_array + *const_sgn_alpha; // boolean array for if the surface phase space flux is single signed + // if true, numerical flux function inside kernels simplifies to + // F = alpha_surf*f^- (if sign_alpha_surf = 1), + // F = alpha_surf*f^+ (if sign_alpha_surf = -1) gkyl_dg_updater_vlasov *vlasov_slvr; // Vlasov solver. - }; }; - void (*rhs_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_collisionless *gkcls, const struct gkyl_array *fin, struct gkyl_array *rhs); - void (*fdot_scaling)(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_collisionless *gkcls, struct gkyl_array *rhs, struct gkyl_array *cflrate, struct gkyl_range *rng); - void (*write_diags_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_collisionless *gkcls, double tm, int frame); + void (*rhs_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls, + const struct gkyl_array *fin, struct gkyl_array *rhs + ); + void (*fdot_scaling)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls, + struct gkyl_array *rhs, struct gkyl_array *cflrate, struct gkyl_range *rng + ); + void (*write_diags_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls, double tm, + int frame + ); // Methods for neutral species. - void (*rhs_func_neut)(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_collisionless *gkcls, const struct gkyl_array *fin, struct gkyl_array *rhs); - void (*write_diags_func_neut)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_collisionless *gkcls, double tm, int frame); + void (*rhs_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_collisionless *gkcls, + const struct gkyl_array *fin, struct gkyl_array *rhs + ); + void (*write_diags_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_collisionless *gkcls, + double tm, int frame + ); }; -struct gk_lbo_collisions { +struct gk_lbo_collisions { enum gkyl_collision_id collision_id; // type of collisions bool write_diagnostics; // Whether to write diagnostics out. - bool not_in_dfdt; // Whether to not add collision contribution to df/dt + bool not_in_dfdt; // Whether to not add collision contribution to df/dt struct gkyl_array *self_nu; // Self-collision frequency. struct gkyl_array *boundary_corrections; // LBO boundary corrections. @@ -345,7 +380,8 @@ struct gk_lbo_collisions { bool norm_nu_self; // Whether to compute self-species collision frequency in space and time. double norm_nu_fac_self; // Self collision frequency without factor of n_s/(2*v_ts^2)^(3/2). double vtsq_min; // Minimum vtsq. - struct gkyl_spitzer_coll_freq* spitzer_calc; // Updater for Spitzer collisionality if computing Spitzer value. + struct gkyl_spitzer_coll_freq + *spitzer_calc; // Updater for Spitzer collisionality if computing Spitzer value. struct gkyl_array *nu_boundary_corrections; // Boundary corrections multiplied by nu. struct gkyl_array *nu_moms; // Moments multiplied by nu. struct gkyl_array *m2self; // Second velocity moment of self species. @@ -354,39 +390,53 @@ struct gk_lbo_collisions { int num_cross_collisions; // number of species we cross-collide with struct gk_species *collide_with[GKYL_MAX_SPECIES]; // pointers to cross-species we collide with bool norm_nu_cross; // Whether to compute cross-species collision frequency in space and time. - double norm_nu_fac_cross[GKYL_MAX_SPECIES]; // Cross collision frequency without factor of n_r/(v_ts^2+v_tr^2)^(3/2). + double norm_nu_fac_cross + [GKYL_MAX_SPECIES]; // Cross collision frequency without factor of n_r/(v_ts^2+v_tr^2)^(3/2). double alpha_E_fac[GKYL_MAX_SPECIES]; // Time-independent factor in alpha_E. double betaGreenep1; // Galue of Greene's factor beta + 1. double delta_sr; // Free parameter in relationship between alpha_E and nu_sr. double other_m[GKYL_MAX_SPECIES]; // Masses of species colliding with. - struct gkyl_array *other_prim_moms[GKYL_MAX_SPECIES]; // Self-primitive moments of species colliding with. + struct gkyl_array + *other_prim_moms[GKYL_MAX_SPECIES]; // Self-primitive moments of species colliding with. struct gkyl_array *cross_prim_moms[GKYL_MAX_SPECIES]; // Cross-primitive moments. struct gkyl_array *cross_nu[GKYL_MAX_SPECIES]; // Cross-species collision frequencies. - struct gkyl_array *cross_nu_prim_moms; // Weak multiplication of collision frequency and primitive moments. + struct gkyl_array + *cross_nu_prim_moms; // Weak multiplication of collision frequency and primitive moments. struct gkyl_array *alpha_E; // Morse's alpha_E factor. gkyl_prim_lbo_cross_calc *cross_calc; // LBO cross-primitive moment calculator - + struct gk_species_moment moms; // Moments needed in LBO (M0, M1, M2). gkyl_dg_updater_collisions *coll_slvr; // collision solver // Pointers to methods chosen at runtime. - void (*moms_func)(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin); - void (*self_nu_func)(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin); - void (*cross_nu_func)(gkyl_gyrokinetic_app *app, const struct gk_species *s, - struct gk_lbo_collisions *lbo, int coll_idx); - void (*alpha_E_func)(gkyl_gyrokinetic_app *app, const struct gk_species *s, - struct gk_lbo_collisions *lbo, int coll_idx); - void (*cross_moms_func)(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lbo_collisions *lbo); - void (*rhs_func)(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin, struct gkyl_array *rhs); - void (*write_mom_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); + void (*moms_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin + ); + void (*self_nu_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin + ); + void (*cross_nu_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *s, struct gk_lbo_collisions *lbo, + int coll_idx + ); + void (*alpha_E_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *s, struct gk_lbo_collisions *lbo, + int coll_idx + ); + void (*cross_moms_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lbo_collisions *lbo + ); + void (*rhs_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin, struct gkyl_array *rhs + ); + void (*write_mom_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame); }; -struct gk_bgk_collisions { +struct gk_bgk_collisions { enum gkyl_collision_id collision_id; // Type of collisions. bool write_diagnostics; // Whether to write diagnostics out. @@ -396,22 +446,25 @@ struct gk_bgk_collisions { bool norm_nu_self; // Whether to compute self-species collision frequency in space and time. double norm_nu_fac_self; // Self collision frequency without factor of n_s/(2*v_ts^2)^(3/2). double vtsq_min; // Minimum vtsq. - struct gkyl_spitzer_coll_freq* spitzer_calc; // Updater for Spitzer collisionality if computing Spitzer value + struct gkyl_spitzer_coll_freq + *spitzer_calc; // Updater for Spitzer collisionality if computing Spitzer value int num_cross_collisions; // number of species we cross-collide with struct gk_species *collide_with[GKYL_MAX_SPECIES]; // pointers to cross-species we collide with bool norm_nu_cross; // Whether to compute cross-species collision frequency in space and time. - double norm_nu_fac_cross[GKYL_MAX_SPECIES]; // Cross collision frequency without factor of n_r/(v_ts^2+v_tr^2)^(3/2). + double norm_nu_fac_cross + [GKYL_MAX_SPECIES]; // Cross collision frequency without factor of n_r/(v_ts^2+v_tr^2)^(3/2). double alpha_E_fac[GKYL_MAX_SPECIES]; // Time-independent factor in alpha_E. double betaGreenep1; // Galue of Greene's factor beta + 1. double delta_sr; // Free parameter in relationship between alpha_E and nu_sr. double other_m[GKYL_MAX_SPECIES]; // Masses of species colliding with. - struct gkyl_array *other_prim_moms[GKYL_MAX_SPECIES]; // Self-primitive moments of species colliding with. + struct gkyl_array + *other_prim_moms[GKYL_MAX_SPECIES]; // Self-primitive moments of species colliding with. struct gkyl_array *cross_prim_moms; // Cross-primitive moments. struct gkyl_array *cross_nu[GKYL_MAX_SPECIES]; // Cross-species collision frequencies. struct gkyl_array *alpha_E; // Morse's alpha_E factor. struct gkyl_gyrokinetic_cross_prim_moms_bgk *cross_calc; // Cross-species moment computation. - + struct gkyl_array *nu_fmax; // Collision frequency times Maxwellian. struct gkyl_bgk_collisions *up_bgk; // BGK updater (also computes stable timestep). @@ -419,41 +472,73 @@ struct gk_bgk_collisions { double dt_implicit; // Timestep used by the implicit collisions. // Pointers to methods chosen at runtime. - void (*moms_func)(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); - void (*moms_func_implicit)(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); - void (*self_nu_func)(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk); - void (*cross_nu_func)(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk, int coll_idx); - void (*alpha_E_func)(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk, int coll_idx); - void (*cross_moms_func)(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk, int coll_idx); - void (*rhs_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs); - void (*rhs_func_implicit)(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs); - void (*write_mom_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); + void (*moms_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin + ); + void (*moms_func_implicit)( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin + ); + void (*self_nu_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk + ); + void (*cross_nu_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk, + int coll_idx + ); + void (*alpha_E_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk, + int coll_idx + ); + void (*cross_moms_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk, + int coll_idx + ); + void (*rhs_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs + ); + void (*rhs_func_implicit)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs + ); + void (*write_mom_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame); // For neutral species (will hopefully remove when we unify species types). - void (*moms_func_neut)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); - void (*moms_func_implicit_neut)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); - void (*self_nu_func_neut)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk); - void (*cross_nu_func_neut)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, int coll_idx); - void (*alpha_E_func_neut)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, int coll_idx); - void (*cross_moms_func_neut)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, int coll_idx); - void (*rhs_func_neut)(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs); - void (*rhs_func_implicit_neut)(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs); - void (*write_mom_func_neut)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); + void (*moms_func_neut)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin + ); + void (*moms_func_implicit_neut)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin + ); + void (*self_nu_func_neut)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk + ); + void (*cross_nu_func_neut)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + int coll_idx + ); + void (*alpha_E_func_neut)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + int coll_idx + ); + void (*cross_moms_func_neut)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + int coll_idx + ); + void (*rhs_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs + ); + void (*rhs_func_implicit_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs + ); + void (*write_mom_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame + ); }; struct gk_anomalous_diff { @@ -462,17 +547,21 @@ struct gk_anomalous_diff { struct gkyl_array *diffD; // Diffusivity. struct gkyl_dg_updater_gk_anomalous_diffusion *slvr; // Anomalous diffusion equation solver. // Methods chosen at runtime. - void (*rhs_func)(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_anomalous_diff *gkad, const struct gkyl_array *fin, struct gkyl_array *rhs); - void (*write_diags_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_anomalous_diff *gkad, double tm, int frame); + void (*rhs_func)( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_anomalous_diff *gkad, + const struct gkyl_array *fin, struct gkyl_array *rhs + ); + void (*write_diags_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_anomalous_diff *gkad, double tm, + int frame + ); }; enum gkyl_species_bflux_type { GK_SPECIES_BFLUX_NONE = 0, // Do nothing. GK_SPECIES_BFLUX_CALC_FLUX, // Put boundary fluxes in ghost of rhs. GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS, // Also step the moments of bflux. - GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS_DIAGS, // Also compute/write diagnostics. + GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS_DIAGS // Also compute/write diagnostics. }; #define BFLUX_MAX_MOM_NAMES 12 @@ -481,26 +570,30 @@ struct gk_boundary_fluxes { bool allocated_solver, allocated_moms, allocated_diags; // Objects used to compute boundary fluxes. int num_boundaries; // Number of boundaries to compute bfluxes at. - int boundaries_dir[2*GKYL_MAX_CDIM]; // Direction of bflux boundaries. - enum gkyl_edge_loc boundaries_edge[2*GKYL_MAX_CDIM]; // Edge of bflux boundaries. - struct gkyl_range *boundaries_conf_skin[2*GKYL_MAX_CDIM]; // Conf-space ghost range of boundaries. - struct gkyl_range *boundaries_conf_ghost[2*GKYL_MAX_CDIM]; // Conf-space ghost range of boundaries. - struct gkyl_range *boundaries_phase_skin[2*GKYL_MAX_CDIM]; // Phase-space skin range of boundaries. - struct gkyl_range *boundaries_phase_ghost[2*GKYL_MAX_CDIM]; // Phase-space ghost range of boundaries. + int boundaries_dir[2 * GKYL_MAX_CDIM]; // Direction of bflux boundaries. + enum gkyl_edge_loc boundaries_edge[2 * GKYL_MAX_CDIM]; // Edge of bflux boundaries. + struct gkyl_range *boundaries_conf_skin[2 * GKYL_MAX_CDIM]; // Conf-space ghost range of boundaries. + struct gkyl_range + *boundaries_conf_ghost[2 * GKYL_MAX_CDIM]; // Conf-space ghost range of boundaries. + struct gkyl_range + *boundaries_phase_skin[2 * GKYL_MAX_CDIM]; // Phase-space skin range of boundaries. + struct gkyl_range + *boundaries_phase_ghost[2 * GKYL_MAX_CDIM]; // Phase-space ghost range of boundaries. struct gkyl_range *boundaries_phase_ghost_nosub; // Not a sub range of local_ext. - struct gkyl_range *boundaries_conf_skin_fullx[2*GKYL_MAX_CDIM]; // Whole x range (for IWL). + struct gkyl_range *boundaries_conf_skin_fullx[2 * GKYL_MAX_CDIM]; // Whole x range (for IWL). int num_eqns; // Number of equations with boundary fluxes. const struct gkyl_dg_eqn **eqns; // Array of equation objects with boundary fluxes. - gkyl_boundary_flux *flux_slvr[2*GKYL_MAX_CDIM]; // boundary flux solver + gkyl_boundary_flux *flux_slvr[2 * GKYL_MAX_CDIM]; // boundary flux solver struct gkyl_array **flux; // Array storing boundary fluxes. // Objects used for calculating moments. int num_calc_moms; // Number of moments of boundary fluxes to compute. enum gkyl_distribution_moments calc_mom_names[BFLUX_MAX_MOM_NAMES]; // Names of moments calculated. bool *is_hamiltonian_mom; // True if need Hamiltonian moments. bool a_hamiltonian_mom; // There is one Hamiltonian moment. - struct gkyl_bc_basic_gyrokinetic *gfss_bc_op[2*GKYL_MAX_CDIM]; // Applies BCs to bmag and phi. + struct gkyl_bc_basic_gyrokinetic *gfss_bc_op[2 * GKYL_MAX_CDIM]; // Applies BCs to bmag and phi. struct gkyl_array *bc_buffer; // Buffer used by gfss_bc_op; - struct gkyl_array **f, **f1, **fnew; // Boundary flux through each boundary (one for each RK stage). + struct gkyl_array **f, **f1, + **fnew; // Boundary flux through each boundary (one for each RK stage). struct gk_species_moment *moms_op; // Moments calculator. // Objects used for calculating diagnostics. int *diag_mom_idx; // Index of each diag mom in the array of calc moms. @@ -509,43 +602,71 @@ struct gk_boundary_fluxes { struct gkyl_translate_dim **transdim; // Updater that projects to lower dim. struct gkyl_rect_decomp *decomp_surf[GKYL_MAX_CDIM]; // Surface decomposition object. struct gkyl_comm *comm_surf[GKYL_MAX_CDIM]; // Surface communicator object. - struct gkyl_range surf_local[GKYL_MAX_CDIM], surf_local_ext[GKYL_MAX_CDIM]; // local, local-ext surface ranges. + struct gkyl_range surf_local[GKYL_MAX_CDIM], + surf_local_ext[GKYL_MAX_CDIM]; // local, local-ext surface ranges. struct gkyl_rect_grid grid_surf[GKYL_MAX_CDIM]; // Surface grid. struct gkyl_array **mom_surf, **mom_surf_ho; // Moments on the surface. struct gkyl_array_integrate **integ_op; // Operator that integrates over volume. double *int_moms_local, *int_moms_global; // Integrated moments in this time step. gkyl_dynvec *intmom; // Integrated moments of the boundary fluxes. double **intmom_cumm_buff; // Cummulative (in time) integrated moments of the boundary fluxes. - bool is_first_intmom_write_call[2*GKYL_MAX_CDIM]; // Flag 1st writing of blux_intmom. + bool is_first_intmom_write_call[2 * GKYL_MAX_CDIM]; // Flag 1st writing of blux_intmom. // Function pointers to various methods. - void (*bflux_rhs_func)(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *fin, struct gkyl_array *rhs); - void (*bflux_calc_moms_func)(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *rhs, struct gkyl_array **bflux_moms); - void (*bflux_get_flux_func)(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - struct gkyl_array *out, const struct gkyl_range *out_rng); - void (*bflux_get_flux_mom_func)(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, - enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, const struct gkyl_range *out_rng); - void (*bflux_clear_func)(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val); - void (*bflux_scale_func)(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val); - void (*bflux_step_f_func)(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, - double dt, struct gkyl_array **fin); - void (*bflux_set_func)(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, - double fac, struct gkyl_array **fin); - void (*bflux_accumulate_func)(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, - double fac, struct gkyl_array **fin); - void (*bflux_combine_func)(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2); - void (*bflux_copy_func)(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, struct gkyl_array **fin); - void (*bflux_calc_voltime_int_mom_func)(gkyl_gyrokinetic_app* app, void *species, - struct gk_boundary_fluxes *bflux, double tm); - void (*bflux_calc_integrated_mom_func)(gkyl_gyrokinetic_app* app, void *species, - struct gk_boundary_fluxes *bflux, double tm); - void (*bflux_write_integrated_mom_func)(gkyl_gyrokinetic_app *app, void *species, - struct gk_boundary_fluxes *bflux); - void (*bflux_write_mom_func)(gkyl_gyrokinetic_app* app, void *species, - struct gk_boundary_fluxes *bflux, double tm, int frame); + void (*bflux_rhs_func)( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *fin, + struct gkyl_array *rhs + ); + void (*bflux_calc_moms_func)( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *rhs, + struct gkyl_array **bflux_moms + ); + void (*bflux_get_flux_func)( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, struct gkyl_array *out, + const struct gkyl_range *out_rng + ); + void (*bflux_get_flux_mom_func)( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, + enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, + const struct gkyl_range *out_rng + ); + void (*bflux_clear_func)( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val + ); + void (*bflux_scale_func)( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fin, double val + ); + void (*bflux_step_f_func)( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double dt, struct gkyl_array **fin + ); + void (*bflux_set_func)( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double fac, struct gkyl_array **fin + ); + void (*bflux_accumulate_func)( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double fac, struct gkyl_array **fin + ); + void (*bflux_combine_func)( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2 + ); + void (*bflux_copy_func)( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + struct gkyl_array **fin + ); + void (*bflux_calc_voltime_int_mom_func)( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm + ); + void (*bflux_calc_integrated_mom_func)( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm + ); + void (*bflux_write_integrated_mom_func)( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux + ); + void (*bflux_write_mom_func)( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm, int frame + ); }; struct gk_recycle_wall { @@ -570,46 +691,53 @@ struct gk_recycle_wall { struct gk_species *impact_species[GKYL_MAX_SPECIES]; // Pointers to impacting species struct gkyl_rect_grid impact_grid[GKYL_MAX_SPECIES]; // Ghost grid of the impacting boundary. - struct gkyl_range *impact_ghost_r[GKYL_MAX_SPECIES]; // Ghost range of the impacting boundary (sub of local_ext). - struct gkyl_range impact_buff_r[GKYL_MAX_SPECIES]; // Ghost range of the impacting boundary. - struct gkyl_range impact_cbuff_r[GKYL_MAX_SPECIES]; // Conf-space ghost range of the impacting boundary. + struct gkyl_range + *impact_ghost_r[GKYL_MAX_SPECIES]; // Ghost range of the impacting boundary (sub of local_ext). + struct gkyl_range impact_buff_r[GKYL_MAX_SPECIES]; // Ghost range of the impacting boundary. + struct gkyl_range + impact_cbuff_r[GKYL_MAX_SPECIES]; // Conf-space ghost range of the impacting boundary. struct gkyl_array *bc_buffer; // Fixed buffers for recycle BCs. struct gkyl_array *phase_flux_gk[GKYL_MAX_SPECIES]; // Array to put phase-flux into. struct gkyl_array *m0_flux_gk[GKYL_MAX_SPECIES]; // M0 moment of ion flux. struct gkyl_dg_updater_moment *m0op_gk[GKYL_MAX_SPECIES]; // M0 moment solver for ion flux. - struct gkyl_array *unit_phase_flux_neut; // Unit-density neutral flux. + struct gkyl_array *unit_phase_flux_neut; // Unit-density neutral flux. struct gkyl_array *unit_m0_flux_neut; // MO moment of unit-density flux. struct gkyl_dg_updater_moment *m0op_neut; // M0 moment solver for unit-density flux. struct gkyl_array *spectrum[GKYL_MAX_SPECIES]; // Unit-density Maxwellian is copied and scaled here. - struct gkyl_range impact_normal_r[GKYL_MAX_SPECIES]; // Phase-space range w/ only velocities towards the boundary. + struct gkyl_range + impact_normal_r[GKYL_MAX_SPECIES]; // Phase-space range w/ only velocities towards the boundary. struct gkyl_array *f_emit; // Array to fill neutral ghost cell with scaled Maxwellian distf. // Objects used for diagnostics. bool write_diagnostics; struct gkyl_array *f_diag; struct gkyl_array *emit_flux; - struct gkyl_array *diag_out; + struct gkyl_array *diag_out; struct gkyl_array *diag_out_ho; // Function pointers to diagnostic functions. - void (*write_flux_func)(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_recycle_wall *recyc, double tm, int frame); + void (*write_flux_func)( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_recycle_wall *recyc, + double tm, int frame + ); }; struct gk_react { int num_react; // Number of reactions. bool all_gk; // Boolean for if reactions are only between gyrokinetic species. bool write_diagnostics; // Whether to write diagnostics out. - struct gkyl_gyrokinetic_react_type react_type[GKYL_MAX_REACT]; // Input struct for type of reactions. + struct gkyl_gyrokinetic_react_type + react_type[GKYL_MAX_REACT]; // Input struct for type of reactions. struct gkyl_array *f_react; // Distribution function array which holds update for each reaction - // form depends on type_self, e.g., for ionization and type_self == GKYL_SELF_ELC - // f_react = n_donor*(fmax1(n_elc, upar_elc, vtiz1^2) + fmax2(n_elc, upar_donor, vtiz2^2) - f_elc) - // RHS update is then obtained by incrementing rhs += coeff_react*f_react + // form depends on type_self, e.g., for ionization and type_self == GKYL_SELF_ELC + // f_react = n_donor*(fmax1(n_elc, upar_elc, vtiz1^2) + fmax2(n_elc, upar_donor, vtiz2^2) - f_elc) + // RHS update is then obtained by incrementing rhs += coeff_react*f_react - enum gkyl_react_id react_id[GKYL_MAX_REACT]; // What type of reaction (ionization, charge exchange, recombination). + enum gkyl_react_id + react_id[GKYL_MAX_REACT]; // What type of reaction (ionization, charge exchange, recombination). enum gkyl_react_self_type type_self[GKYL_MAX_REACT]; // What is the role of species in this reaction struct gk_species *species_elc[GKYL_MAX_REACT]; // Electron species being reacted with. struct gk_species *species_ion[GKYL_MAX_REACT]; // Ion species being reacted with. @@ -627,14 +755,16 @@ struct gk_react { struct gkyl_array *Jm0_donor[GKYL_MAX_REACT]; // J*donor density. struct gkyl_array *Jm0_partner[GKYL_MAX_REACT]; // J*partner density. - struct gkyl_array *react_lte_moms[GKYL_MAX_REACT]; // LTE/Maxwellian moments used for Maxwellian projection. + struct gkyl_array + *react_lte_moms[GKYL_MAX_REACT]; // LTE/Maxwellian moments used for Maxwellian projection. struct gkyl_array *u_i[GKYL_MAX_REACT]; // Vector flow velocity for neutrals (ux, uy, uz). - struct gkyl_array *u_i_dot_b_i[GKYL_MAX_REACT]; // u_i . b_i (Cartesian compoments of magnetic field unit vector). + struct gkyl_array + *u_i_dot_b_i[GKYL_MAX_REACT]; // u_i . b_i (Cartesian compoments of magnetic field unit vector). struct gkyl_array *vt_sq_donor[GKYL_MAX_REACT]; // Donor thermal velocity. struct gkyl_array *upar_ion[GKYL_MAX_REACT]; // Ion vector parallel flow velocity upar b_i. struct gkyl_array *vt_sq_ion[GKYL_MAX_REACT]; // Ion thermal velocity. struct gkyl_array *vt_sq_partner[GKYL_MAX_REACT]; // Neutral (partner) thermal velocity. - + union { // Ionization. struct { @@ -651,19 +781,31 @@ struct gk_react { }; // Methods chosen at runtime: - void (*cross_moms_func)(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_react *react, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]); - void (*rhs_func)(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_react *react, const struct gkyl_array *fin, struct gkyl_array *rhs); - void (*write_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, struct gk_react *gkr, - int ridx, double tm, int frame); + void (*cross_moms_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_react *react, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] + ); + void (*rhs_func)( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_react *react, + const struct gkyl_array *fin, struct gkyl_array *rhs + ); + void (*write_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_react *gkr, int ridx, double tm, + int frame + ); // Neutral methods (MF 2025/10/28: to get rid of by unifying species types). - void (*cross_moms_func_neut)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_react *react, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]); - void (*rhs_func_neut)(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_react *react, const struct gkyl_array *fin, struct gkyl_array *rhs); - void (*write_func_neut)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, struct gk_react *gkr, - int ridx, double tm, int frame); + void (*cross_moms_func_neut)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_react *react, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] + ); + void (*rhs_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_react *react, + const struct gkyl_array *fin, struct gkyl_array *rhs + ); + void (*write_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_react *gkr, int ridx, + double tm, int frame + ); }; struct gk_scaling { @@ -674,21 +816,23 @@ struct gk_scaling { struct { // Objects for GKYL_GK_SPECIES_SCALING_RECYCLING_IZ_BALANCE. int num_boundaries; // Number of boundaries. - int boundaries_dir[GKYL_MAX_CDIM*2]; // Direction of boundaries. - enum gkyl_edge_loc boundaries_edge[GKYL_MAX_CDIM*2]; // Edge of boundaries. + int boundaries_dir[GKYL_MAX_CDIM * 2]; // Direction of boundaries. + enum gkyl_edge_loc boundaries_edge[GKYL_MAX_CDIM * 2]; // Edge of boundaries. int elc_idx; // Index of electron species. int ion_idx; // Index of ion species. double recycling_coeff; // Recycling coefficient. - + struct gkyl_array *Jm0_init; // Initial number density times jacobgeo. struct gkyl_array *reactivity; // Reactivity. struct gkyl_array *dndt_react; // Reaction contribution. struct gkyl_dg_iz *iz_react_calc; // Operator to compute ionization rate. struct gkyl_array_integrate *integrate_op; // Operator that integrates an array. - double react_vol_integ, *react_vol_integ_local, *react_vol_integ_global; // Volume integral of reaction contribution. - - struct gkyl_range boundaries_conf_ghost[2*GKYL_MAX_CDIM]; // Ghost cells to where integrated M0 is computed. - + double react_vol_integ, *react_vol_integ_local, + *react_vol_integ_global; // Volume integral of reaction contribution. + + struct gkyl_range + boundaries_conf_ghost[2 * GKYL_MAX_CDIM]; // Ghost cells to where integrated M0 is computed. + double *bflux_m0_vol_integ_local; // Local volume integral of boundary flux M0. }; struct { @@ -705,23 +849,39 @@ struct gk_scaling { }; // Methods chosen at runtime. - void (*cross_moms_func)(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_scaling *sca, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]); - void (*rhs_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca, const struct gkyl_array *fin, struct gkyl_array *rhs); - void (*apply_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca, struct gkyl_array *fin, struct gkyl_array **bflux[]); - void (*write_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_scaling *sca, int ridx, double tm, int frame); + void (*cross_moms_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_scaling *sca, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] + ); + void (*rhs_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, + const struct gkyl_array *fin, struct gkyl_array *rhs + ); + void (*apply_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, + struct gkyl_array *fin, struct gkyl_array **bflux[] + ); + void (*write_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, int ridx, double tm, + int frame + ); // Neutral species function pointers (MF 2025/11/03: to be removed when we unify species types). - void (*cross_moms_func_neut)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *ns, - struct gk_scaling *sca, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]); - void (*rhs_func_neut)(gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca, const struct gkyl_array *fin, struct gkyl_array *rhs); - void (*apply_func_neut)(gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca, struct gkyl_array *fin, struct gkyl_array **bflux[]); - void (*write_func_neut)(gkyl_gyrokinetic_app* app, struct gk_neut_species *ns, - struct gk_scaling *sca, int ridx, double tm, int frame); + void (*cross_moms_func_neut)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *ns, struct gk_scaling *sca, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] + ); + void (*rhs_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca, + const struct gkyl_array *fin, struct gkyl_array *rhs + ); + void (*apply_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca, + struct gkyl_array *fin, struct gkyl_array **bflux[] + ); + void (*write_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca, int ridx, + double tm, int frame + ); }; // Context for c2p function passed to proj_on_basis. @@ -745,7 +905,8 @@ struct gk_proj { struct gkyl_array *dens; // Density (on device for GK Maxwellian Gaussian). struct gkyl_array *prim_moms_host; // Host-side prim_moms for initialization with proj_on_basis - struct gkyl_array *prim_moms; // Prim_moms we pass to Maxwellian projection object (potentially on device) + struct gkyl_array + *prim_moms; // Prim_moms we pass to Maxwellian projection object (potentially on device) bool maxwellian_moms_from_file; bool bimaxwellian_moms_from_file; bool dens_from_file; @@ -757,7 +918,8 @@ struct gk_proj { bool correct_all_moms; // Boolean if we are correcting all the moments. struct gkyl_proj_on_basis *proj_dens; // Projection operator for density - struct gkyl_array *vtsq; // vt^2 = T/m (temperature/mass) (on device for GK Maxwellian Gaussian). + struct gkyl_array + *vtsq; // vt^2 = T/m (temperature/mass) (on device for GK Maxwellian Gaussian). struct gkyl_proj_on_basis *proj_temp; // Projection operator for temperature. struct gkyl_array *vtsqpar; // Host-side vt_par^2 = Tpar/m (parallel temperature/mass). struct gkyl_array *vtsqperp; // Host-side vt_perp^2 = Tperp/m (perpendicular temperature/mass). @@ -765,54 +927,70 @@ struct gk_proj { struct gkyl_proj_on_basis *proj_tempperp; // Projection operator for perpendicular temperature. struct gkyl_array *gaussian_profile; // Shape of the source in configuration space (on device). - struct gkyl_proj_on_basis *proj_gaussian; // Projection operator for the shape of the source in config space. + struct gkyl_proj_on_basis + *proj_gaussian; // Projection operator for the shape of the source in config space. union { - struct { - struct gkyl_array *upar; // upar for GK Maxwellian/Bi-Maxwellian projection (on device for GK Maxwellian Gaussian) - struct gkyl_proj_on_basis *proj_upar; // Projection operator for upar for GK Maxwellian/Bi-Maxwellian projection. + struct { + struct gkyl_array * + upar; // upar for GK Maxwellian/Bi-Maxwellian projection (on device for GK Maxwellian Gaussian) + struct gkyl_proj_on_basis + *proj_upar; // Projection operator for upar for GK Maxwellian/Bi-Maxwellian projection. struct gkyl_gk_maxwellian_proj_on_basis *proj_max; // Maxwellian projection object for GK. struct gkyl_gk_maxwellian_correct *corr_max; // Maxwellian correction object for GK. }; - struct { + struct { struct gkyl_array *udrift; // Host-side udrift for Vlasov neutrals LTE projection. - struct gkyl_proj_on_basis *proj_udrift; // Projection operator for udrift for Vlasov neutrals LTE projection. - struct gkyl_vlasov_lte_proj_on_basis *proj_lte; // Maxwellian projection object for Vlasov neutrals. - struct gkyl_vlasov_lte_correct *corr_lte; // Maxwellian correction object for Vlasov neutrals. - }; - }; + struct gkyl_proj_on_basis + *proj_udrift; // Projection operator for udrift for Vlasov neutrals LTE projection. + struct gkyl_vlasov_lte_proj_on_basis + *proj_lte; // Maxwellian projection object for Vlasov neutrals. + struct gkyl_vlasov_lte_correct + *corr_lte; // Maxwellian correction object for Vlasov neutrals. + }; + }; }; }; // Functions chosen at runtime. - void (*projection_calc)(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm); - void (*neut_calc_func)(gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm); - void (*moms_correct)(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_proj *proj, struct gkyl_array *f, double tm); + void (*projection_calc)( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm + ); + void (*neut_calc_func)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_proj *proj, + struct gkyl_array *f, double tm + ); + void (*moms_correct)( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_proj *proj, struct gkyl_array *f, + double tm + ); void (*release_func)(const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj); }; struct gk_adapt_source { bool adapt_particle, adapt_energy; // Adaptation flags. - struct gk_species *adapt_species; // Non-owning pointer to the species whose particle loss is being adapted; lifetime managed elsewhere. + struct gk_species * + adapt_species; // Non-owning pointer to the species whose particle loss is being adapted; lifetime managed elsewhere. int adapt_species_idx; // Index of the species whose particle loss is being adapted. double adapt_particle_fraction; // Fraction of particle loss to adapt to. double adapt_energy_fraction; // Fraction of energy loss to adapt to. int num_boundaries; // Number of boundaries to adapt to. - int dir[2*GKYL_MAX_CDIM]; // Direction to adapt. - enum gkyl_edge_loc edge[2*GKYL_MAX_CDIM]; // Edge to adapt. - struct gkyl_range boundaries_phase_ghost[2*GKYL_MAX_CDIM]; // Range of computation of the bflux and moment (ALL phase space ghost). - struct gkyl_range boundaries_conf_ghost[2*GKYL_MAX_CDIM]; // Range of integration in each boundary (SOL config space ghost). + int dir[2 * GKYL_MAX_CDIM]; // Direction to adapt. + enum gkyl_edge_loc edge[2 * GKYL_MAX_CDIM]; // Edge to adapt. + struct gkyl_range boundaries_phase_ghost + [2 * GKYL_MAX_CDIM]; // Range of computation of the bflux and moment (ALL phase space ghost). + struct gkyl_range boundaries_conf_ghost + [2 * GKYL_MAX_CDIM]; // Range of integration in each boundary (SOL config space ghost). struct gk_species_moment integ_threemoms; // Integrated moment updater. double *red_integ_mom, *red_integ_mom_global; // For reduction. struct gkyl_array_integrate *integrate_op; // Operator that integrates an array. struct gkyl_array *bflux_m0, *bflux_m2; // Boundary flux moments. - double *integ_m0, *integ_m2; // Integrated boundary flux moments for one boundary and one mpi process. (on device) + double *integ_m0, + *integ_m2; // Integrated boundary flux moments for one boundary and one mpi process. (on device) double particle_src_curr, energy_src_curr; // current injection rates of the source. double particle_rate_loss, energy_rate_loss; // Loss rates we adapt to. @@ -839,12 +1017,14 @@ struct gk_source { struct gk_adapt_source adapt[GKYL_MAX_SOURCES]; // Adaptation source. int num_adapt_sources; // Number of adaptive sources. // Functions chosen at runtime. - void (*write_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); - void (*write_mom_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); - void (*calc_integrated_mom_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm); - void (*write_integrated_mom_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks); - void (*adapt_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, struct gk_source *src, - struct gkyl_array *f_buffer, struct gkyl_array **bflux_moms[], double tm); + void (*write_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame); + void (*write_mom_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame); + void (*calc_integrated_mom_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm); + void (*write_integrated_mom_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks); + void (*adapt_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source *src, + struct gkyl_array *f_buffer, struct gkyl_array **bflux_moms[], double tm + ); }; struct gk_damping { @@ -858,7 +1038,7 @@ struct gk_damping { double *phi_m, *phi_m_global; // Electrostatic potential at bmag_max. struct gkyl_array *scale_prof; // Conf-space scaling factor profile. // Functions chosen at runtime. - void (*write_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); + void (*write_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame); }; struct gk_fdot_multiplier_comp { @@ -874,7 +1054,8 @@ struct gk_fdot_multiplier_comp { // Time dilation parameters (from input). double cfl_dt_min_value; // User-specified minimum dt value. - double cfl_factor_times_omega_max; // User-specified factor multiplied by maximum characteristic frequency to get minimum dt. + double + cfl_factor_times_omega_max; // User-specified factor multiplied by maximum characteristic frequency to get minimum dt. double f_threshold; // Threshold for mask-based time dilation. double time_dilation_scale_const; // Constant scale applied to the time dilation multiplier. @@ -886,12 +1067,15 @@ struct gk_fdot_multiplier_comp { double *global_max_f; // Allreduced global maximum across all processes double *local_max_f; // Process specific maximum - struct gk_species *species_dt_is_set_from; // Pointer to another species which sets dt for the present species. + struct gk_species + *species_dt_is_set_from; // Pointer to another species which sets dt for the present species. // Function chosen at runtime: computes this component's contribution and multiplies it into combined_multiplier. - void (*advance_func)(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_fdot_multiplier_comp *fdmul, const struct gkyl_array *phi, const struct gkyl_array *f, - const struct gkyl_array *cflrate, struct gkyl_array *combined_multiplier); + void (*advance_func)( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_fdot_multiplier_comp *fdmul, + const struct gkyl_array *phi, const struct gkyl_array *f, const struct gkyl_array *cflrate, + struct gkyl_array *combined_multiplier + ); }; struct gk_fdot_multiplier { @@ -901,14 +1085,18 @@ struct gk_fdot_multiplier { struct gkyl_array *multiplier_host; // Host copy for I/O and projecting. bool write_diagnostics; // Whether to write the combined multiplier as a diagnostic. // Functions chosen at runtime. - void (*write_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult, double tm, int frame); - void (*advance_times_cfl_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult, const struct gkyl_array *phi, - const struct gkyl_array *f, struct gkyl_array *cflrate); - void (*advance_times_rate_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult, const struct gkyl_array *phi, - const struct gkyl_array *f, struct gkyl_array *rhs); + void (*write_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + double tm, int frame + ); + void (*advance_times_cfl_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *cflrate + ); + void (*advance_times_rate_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *rhs + ); }; struct gk_source_bgk { @@ -926,7 +1114,8 @@ struct gk_source_bgk { struct gkyl_array_integrate *vol_integ_op; // Volume integrator. double *volint_local, *volint_global; // Local and global volume integrals. struct gkyl_array *M0dot, *M1dot, *M2dot; // Source rates for external sourcing - struct gkyl_array *M0dot_host, *M1dot_host, *M2dot_host; // Host source rates for external sourcing + struct gkyl_array *M0dot_host, *M1dot_host, + *M2dot_host; // Host source rates for external sourcing double injection_time; // Injection time for external heating model double damping_factor; // Damping factor used to prevent negative densities double vtsq_amplitude; // Amplitude of squared thermal speed. @@ -941,24 +1130,33 @@ struct gk_source_bgk { gkyl_dynvec integ_diag; // Integrated moments of the source. bool is_first_diag_dynvec_write_call; // Whether dynvec is being written for the first time. // Methods chosen at runtime. - void (*rhs_func)(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_source_bgk *src, const struct gkyl_array *fin, struct gkyl_array *rhs); - void (*write_diags_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, double tm, int frame); - void (*update_integrated_diags_rhs_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, double tm); - void (*update_integrated_diags_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, double tm); - void (*calc_integrated_diags_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, double tm); - void (*write_integrated_diags_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_source_bgk *src); + void (*rhs_func)( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_source_bgk *src, + const struct gkyl_array *fin, struct gkyl_array *rhs + ); + void (*write_diags_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm, + int frame + ); + void (*update_integrated_diags_rhs_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm + ); + void (*update_integrated_diags_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm + ); + void (*calc_integrated_diags_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm + ); + void (*write_integrated_diags_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src + ); }; struct gk_positivity { // Updater that enforces positivity by shifting f. enum gkyl_gyrokinetic_positivity_type type; // Type of positivity enforcement algorithm. - bool quasineut_rescale; // Whether to rescale this species to enforce quasineutrality in the simulation. + bool + quasineut_rescale; // Whether to rescale this species to enforce quasineutrality in the simulation. bool write_diagnostics; // Whether to output diagnostics. struct gkyl_array *fbuffer_ptr; // Pointer to an array were we store delta f. @@ -973,40 +1171,56 @@ struct gk_positivity { struct gkyl_positivity_shift_vlasov *shift_op_vlasov; }; }; - + struct gk_species_moment moms; // Positivity shift diagnostic moments. struct gk_species_moment integ_moms; // Integrated moments. double *red_integ_diag, *red_integ_diag_global; // Reduced integrated moments. gkyl_dynvec integ_diag; // Integrated moments of the positivity shift. bool is_first_integ_write_call; // Flag first time writing integ_diag. bool integ_diag_file_exists; // Whether the integrated diagnostics file exists. - + // Methods chosen at runtime. - void (*apply_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_positivity *pos, struct gkyl_array *fbuffer, struct gkyl_array *fout); - void (*deltaf_moms_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos); - void (*deltaf_integ_moms_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos); - void (*write_diags_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos, double tm, int frame); - void (*calc_integrated_diags_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos, double tm); - void (*write_integrated_diags_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_positivity *pos); + void (*apply_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, + struct gkyl_array *fbuffer, struct gkyl_array *fout + ); + void (*deltaf_moms_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos + ); + void (*deltaf_integ_moms_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos + ); + void (*write_diags_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, double tm, + int frame + ); + void (*calc_integrated_diags_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, double tm + ); + void (*write_integrated_diags_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos + ); // Neutral species methods (MF 2025/10/29: to get rid of when we unify species types). - void (*apply_func_neut)(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_positivity *pos, struct gkyl_array *fbuffer, struct gkyl_array *fout); - void (*deltaf_moms_func_neut)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos); - void (*deltaf_integ_moms_func_neut)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos); - void (*write_diags_func_neut)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos, double tm, int frame); - void (*calc_integrated_diags_func_neut)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos, double tm); - void (*write_integrated_diags_func_neut)(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_positivity *pos); + void (*apply_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, + struct gkyl_array *fbuffer, struct gkyl_array *fout + ); + void (*deltaf_moms_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos + ); + void (*deltaf_integ_moms_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos + ); + void (*write_diags_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, double tm, + int frame + ); + void (*calc_integrated_diags_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, double tm + ); + void (*write_integrated_diags_func_neut)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos + ); }; // Species data. @@ -1016,14 +1230,14 @@ struct gk_species { struct gkyl_basis basis; // Phase-space basis. // Basis on device (points to host basis if running w/o GPU). - struct gkyl_basis *basis_on_dev; - + struct gkyl_basis *basis_on_dev; + struct gkyl_job_pool *job_pool; // Job pool struct gkyl_rect_grid grid; struct gkyl_range local, local_ext; // Local, local-ext phase-space ranges. struct gkyl_range global, global_ext; // Global, global-ext conf-space ranges. - struct gkyl_comm *comm; // Communicator object for phase-space arrays. + struct gkyl_comm *comm; // Communicator object for phase-space arrays. int nghost[GKYL_MAX_DIM]; // Number of ghost-cells in each direction. struct gkyl_rect_grid grid_vel; // Velocity space grid. @@ -1031,9 +1245,9 @@ struct gk_species { struct gkyl_velocity_map *vel_map; // Velocity mapping objects. - struct gkyl_msgpack_map_elem* io_meta_basic; // Basic metadata for I/O (e.g. int diags). - struct gkyl_msgpack_map_elem* io_meta_phase; // Metadata for I/O of phase grid quantities. - struct gkyl_msgpack_map_elem* io_meta_conf; // Metadata for I/O of conf grid quantities. + struct gkyl_msgpack_map_elem *io_meta_basic; // Basic metadata for I/O (e.g. int diags). + struct gkyl_msgpack_map_elem *io_meta_phase; // Metadata for I/O of phase grid quantities. + struct gkyl_msgpack_map_elem *io_meta_conf; // Metadata for I/O of conf grid quantities. int io_meta_basic_len; // Number of elements in io_meta_basic. int io_meta_phase_len; // Number of elements in io_meta_phase. int io_meta_conf_len; // Number of elements in io_meta_conf. @@ -1048,19 +1262,19 @@ struct gk_species { struct gkyl_array *f_host; // Host copy for IO and initialization. struct gkyl_array *gyro_phi; // Gyroaveraged electrostatic potential. - + struct gk_species_moment m0; // Computes charge density. struct gk_species_moment integ_moms; // Integrated moments. struct gk_species_moment *moms; // Diagnostic moments double *red_integ_diag, *red_integ_diag_global; // Reduced integrated moments. gkyl_dynvec integ_diag; // Integrated moments reduced across grid - bool is_first_integ_write_call; // Whether dynvec is being written for the first time. + bool is_first_integ_write_call; // Whether dynvec is being written for the first time. struct gkyl_array *fdot_mom_old, *fdot_mom_new; // Moments of f_old and f_new. gkyl_dynvec fdot_integ_diag; // Integrated moments of Delta f=f_new - f_old.. bool is_first_fdot_integ_write_call; // Whether dynvec is being written for the first time. - struct gkyl_array_integrate* integ_wfsq_op; // Operator to integrate w*f^2. + struct gkyl_array_integrate *integ_wfsq_op; // Operator to integrate w*f^2. double *L2norm_local, *L2norm_global; // L2norm in local MPI process and across the communicator. gkyl_dynvec L2norm; // L2 norm. bool is_first_L2norm_write_call; // Whether dynvec is being written for the first time. @@ -1093,8 +1307,8 @@ struct gk_species { struct gkyl_range local_core, local_ext_core, local_sol, local_ext_sol; struct gkyl_range local_lower_skin_par_core, local_lower_ghost_par_core; struct gkyl_range local_upper_skin_par_core, local_upper_ghost_par_core; - struct gkyl_range local_lower_skin_par_sol , local_lower_ghost_par_sol; - struct gkyl_range local_upper_skin_par_sol , local_upper_ghost_par_sol; + struct gkyl_range local_lower_skin_par_sol, local_lower_ghost_par_sol; + struct gkyl_range local_upper_skin_par_sol, local_upper_ghost_par_sol; // GK IWL sims need a core range extended in z, and a TS BC updater. struct gkyl_range local_par_ext_core; // Core range extended in parallel direction. struct gkyl_bc_twistshift *bc_ts_lo, *bc_ts_up; @@ -1110,7 +1324,7 @@ struct gk_species { struct gk_fdot_multiplier fdot_mult; // Functions multiplying df/dt. struct gk_anomalous_diff anom_diff; // Anomalous diffusion. - + struct gk_source_bgk bgk_src; // BGK source. // Boundary fluxes used for other solvers and diagnostics. @@ -1131,27 +1345,34 @@ struct gk_species { struct gk_positivity positivity; // Positivity enforcing operator. // Pointer to various functions selected at runtime. - double (*rhs_func)(gkyl_gyrokinetic_app *app, struct gk_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms); - double (*rhs_implicit_func)(gkyl_gyrokinetic_app *app, struct gk_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt); - void (*bc_func)(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gkyl_array *f); - void (*release_func)(const gkyl_gyrokinetic_app* app, const struct gk_species *s); - void (*step_f_func)(struct gkyl_array* out, double dt, const struct gkyl_array* inp); - void (*combine_func)(struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng); - void (*copy_func)(struct gkyl_array *out, const struct gkyl_array *inp, - const struct gkyl_range *range); - void (*write_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); - void (*write_cfl_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); - void (*write_mom_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); - void (*calc_integrated_mom_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm); - void (*write_integrated_mom_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks); - void (*calc_L2norm_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm); - void (*write_L2norm_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks); - void (*calc_int_mom_dt_func)(gkyl_gyrokinetic_app* app, struct gk_species *gks, double dt, struct gkyl_array *fdot_int_mom); + double (*rhs_func)( + gkyl_gyrokinetic_app *app, struct gk_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms + ); + double (*rhs_implicit_func)( + gkyl_gyrokinetic_app *app, struct gk_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt + ); + void (*bc_func)(gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f); + void (*release_func)(const gkyl_gyrokinetic_app *app, const struct gk_species *s); + void (*step_f_func)(struct gkyl_array *out, double dt, const struct gkyl_array *inp); + void (*combine_func)( + struct gkyl_array *out, double c1, const struct gkyl_array *arr1, double c2, + const struct gkyl_array *arr2, const struct gkyl_range *rng + ); + void (*copy_func)( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range + ); + void (*write_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame); + void (*write_cfl_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame); + void (*write_mom_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame); + void (*calc_integrated_mom_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm); + void (*write_integrated_mom_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks); + void (*calc_L2norm_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm); + void (*write_L2norm_func)(gkyl_gyrokinetic_app *app, struct gk_species *gks); + void (*calc_int_mom_dt_func)( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double dt, struct gkyl_array *fdot_int_mom + ); // Quantities used for FLR model: struct gkyl_array *m0_gyroavg; // Gyroaveraged particle density. @@ -1159,8 +1380,10 @@ struct gk_species { struct gkyl_array *flr_kSq; // Field multiplying phi in FLR operator. struct gkyl_deflated_fem_poisson *flr_op; // Helmholtz solver to invert FLR operator. // Pointer to function that performs the gyroaverage. - void (*gyroaverage)(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gkyl_array *field_in, struct gkyl_array *field_gyroavg); + void (*gyroaverage)( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gkyl_array *field_in, + struct gkyl_array *field_gyroavg + ); double dt_omegaH; // Recorded at the end of the rhs evaluation. double dt_cfl_global_ho; // Global maximum Omega_CFL across all MPI processes. @@ -1184,12 +1407,12 @@ struct gk_neut_species { struct gkyl_range local, local_ext; // Local, local-ext species ranges. struct gkyl_range global, global_ext; // Global, global-ext species ranges. - struct gkyl_comm *comm; // Communicator object for this species. + struct gkyl_comm *comm; // Communicator object for this species. int nghost[GKYL_MAX_DIM]; // Number of ghost-cells in each direction - struct gkyl_msgpack_map_elem* io_meta_basic; // Basic metadata for I/O (e.g. int diags). - struct gkyl_msgpack_map_elem* io_meta_phase; // Metadata for I/O of phase grid quantities. - struct gkyl_msgpack_map_elem* io_meta_conf; // Metadata for I/O of conf grid quantities. + struct gkyl_msgpack_map_elem *io_meta_basic; // Basic metadata for I/O (e.g. int diags). + struct gkyl_msgpack_map_elem *io_meta_phase; // Metadata for I/O of phase grid quantities. + struct gkyl_msgpack_map_elem *io_meta_conf; // Metadata for I/O of conf grid quantities. int io_meta_basic_len; // Number of elements in io_meta_basic. int io_meta_phase_len; // Number of elements in io_meta_phase. int io_meta_conf_len; // Number of elements in io_meta_conf. @@ -1222,13 +1445,13 @@ struct gk_neut_species { struct gk_source src; // External source. struct gk_lte lte; // Object needed for the lte equilibrium. - + struct gk_scaling sca; // Recycle react scale. int num_periodic_dir; // Number of periodic directions. int periodic_dirs[GKYL_MAX_CDIM]; // List of periodic directions. bool bc_is_np[GKYL_MAX_CDIM]; // Whether BC is nonperiodic. - + bool enforce_positivity; // Enforces positivity of f or mass/energy density. double *omega_cfl; // CFL frequency. @@ -1241,7 +1464,7 @@ struct gk_neut_species { // Boundary fluxes used for other solvers and diagnostics. struct gk_boundary_fluxes bflux; - + union { // Kinetic neutrals ............................................ // struct { @@ -1261,7 +1484,7 @@ struct gk_neut_species { // Recycling wall boundaries. struct gk_recycle_wall bc_recycle_lo, bc_recycle_up; bool recyc_lo, recyc_up; - + // Boundary conditions on lower/upper edges in each direction. struct gkyl_gyrokinetic_bc lower_bc[GKYL_MAX_CDIM], upper_bc[GKYL_MAX_CDIM]; // Pointers to updaters that apply BC. @@ -1287,26 +1510,39 @@ struct gk_neut_species { }; // Pointer to various functions selected at runtime. - double (*rhs_func)(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms); - double (*rhs_implicit_func)(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt); - void (*bc_func)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gkyl_array *f); - void (*apply_pos_shift_func)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns); - void (*step_f_func)(struct gkyl_array* out, double dt, const struct gkyl_array* inp); - void (*combine_func)(struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng); - void (*copy_func)(struct gkyl_array *out, const struct gkyl_array *inp, - const struct gkyl_range *range); - void (*write_func)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); - void (*write_mom_func)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); - void (*calc_integrated_mom_func)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm); - void (*write_integrated_mom_func)(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns); - void (*report_n_iter_corr_func)(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx); - void (*release_is_static_func)(const gkyl_gyrokinetic_app* app, const struct gk_neut_species *s); - void (*release_func)(const gkyl_gyrokinetic_app* app, const struct gk_neut_species *s); + double (*rhs_func)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms + ); + double (*rhs_implicit_func)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt + ); + void (*bc_func)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gkyl_array *f + ); + void (*apply_pos_shift_func)(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns); + void (*step_f_func)(struct gkyl_array *out, double dt, const struct gkyl_array *inp); + void (*combine_func)( + struct gkyl_array *out, double c1, const struct gkyl_array *arr1, double c2, + const struct gkyl_array *arr2, const struct gkyl_range *rng + ); + void (*copy_func)( + struct gkyl_array *out, const struct gkyl_array *inp, const struct gkyl_range *range + ); + void (*write_func)(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame); + void (*write_mom_func)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame + ); + void (*calc_integrated_mom_func)( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm + ); + void (*write_integrated_mom_func)(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns); + void (*report_n_iter_corr_func)( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx + ); + void (*release_is_static_func)(const gkyl_gyrokinetic_app *app, const struct gk_neut_species *s); + void (*release_func)(const gkyl_gyrokinetic_app *app, const struct gk_neut_species *s); }; // Field data. @@ -1322,22 +1558,22 @@ struct gk_field { // Arrays for local charge density, global charge density, and global smoothed (in z) charge density. struct gkyl_array *rho_c; struct gkyl_array *rho_c_global_dg; - struct gkyl_array *rho_c_global_smooth; + struct gkyl_array *rho_c_global_smooth; struct gkyl_array *phi_fem, *phi_smooth; // Arrays for updates. - struct gkyl_array *phi_host; // host copy for use IO and initialization + struct gkyl_array *phi_host; // host copy for use IO and initialization bool init_phi_pol; // Whether to use the initial user polarization phi. struct gkyl_array *phi_pol; // Initial polarization density potential. struct gkyl_range global_sub_range; // sub range of intersection of global range and local range - // for solving subset of Poisson solves with parallelization in z + // for solving subset of Poisson solves with parallelization in z // organization of the different equation objects and the required data and solvers union { struct { struct gkyl_ambi_bolt_potential *ambi_pot; - struct gkyl_array *sheath_vals[2*GKYL_MAX_CDIM]; + struct gkyl_array *sheath_vals[2 * GKYL_MAX_CDIM]; }; // EM GK model struct { @@ -1346,24 +1582,31 @@ struct gk_field { }; }; - double es_energy_fac_1d; - struct gkyl_array *es_energy_fac; + double es_energy_fac_1d; + struct gkyl_array *es_energy_fac; bool is_dirichletvar; // Whether user provided spatially varying phi BCs. struct gkyl_array *phi_bc; // Spatially varying BC. struct gkyl_array *epsilon; // Polarization weight including geometric factors. - struct gkyl_array *kSq; // Weight for Poisson/Helmholtz solver. + struct gkyl_array *kSq; // Weight for Poisson/Helmholtz solver. - struct gkyl_poisson_bias_line_list fem_parproj_bias_line_list; // Biased lines constraining the solution. + struct gkyl_poisson_bias_line_list + fem_parproj_bias_line_list; // Biased lines constraining the solution. - struct gkyl_fem_parproj *fem_parproj; // Projects DG function onto continuous FEM basis: weight*phi_{fem} = phi_{dg} - struct gkyl_fem_parproj *fem_parproj_rho_sol , *fem_parproj_phi_sol ; // FEM projection in the SOL. - struct gkyl_fem_parproj *fem_parproj_rho_core, *fem_parproj_phi_core; // FEM projection in the core. + struct gkyl_fem_parproj + *fem_parproj; // Projects DG function onto continuous FEM basis: weight*phi_{fem} = phi_{dg} + struct gkyl_fem_parproj *fem_parproj_rho_sol, *fem_parproj_phi_sol; // FEM projection in the SOL. + struct gkyl_fem_parproj *fem_parproj_rho_core, + *fem_parproj_phi_core; // FEM projection in the core. - struct gkyl_fem_poisson_perp *fem_poisson_perp; // Solves - nabla . (epsilon * nabla phi) - kSq * phi = rho. + struct gkyl_fem_poisson_perp + *fem_poisson_perp; // Solves - nabla . (epsilon * nabla phi) - kSq * phi = rho. // Objects needed for FLR effects. bool use_flr; // Whether to apply FLR effects. - void (*invert_flr)(gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *phi); // Function inverting FLR operator. + void (*invert_flr)( + gkyl_gyrokinetic_app *app, struct gk_field *field, + struct gkyl_array *phi + ); // Function inverting FLR operator. struct gkyl_array *flr_rhoSq_sum; // Laplacian weight in FLR operator. struct gkyl_array *flr_kSq; // Field multiplying phi in FLR operator. struct gkyl_deflated_fem_poisson *flr_op; // Helmholtz solver to invert FLR operator. @@ -1373,7 +1616,8 @@ struct gk_field { gkyl_dynvec integ_energy; // integrated energy components bool is_first_energy_write_call; // flag for energy dynvec written first time - double *em_energy_red_old, *em_energy_red_new; // memory for use in GPU reduction of old EM energy. + double *em_energy_red_old, + *em_energy_red_new; // memory for use in GPU reduction of old EM energy. gkyl_dynvec integ_energy_dot; // d/dt of integrated energy components. bool is_first_energy_dot_write_call; // flag for d(energy)/dt dynvec written first time @@ -1381,36 +1625,47 @@ struct gk_field { bool phi_wall_lo_evolve; // flag to indicate biased wall potential on lower wall is time dependent struct gkyl_array *phi_wall_lo; // biased wall potential on lower wall struct gkyl_array *phi_wall_lo_host; // host copy for use in IO and projecting - gkyl_eval_on_nodes *phi_wall_lo_proj; // projector for biased wall potential on lower wall + gkyl_eval_on_nodes *phi_wall_lo_proj; // projector for biased wall potential on lower wall bool has_phi_wall_up; // flag to indicate there is biased wall potential on upper wall bool phi_wall_up_evolve; // flag to indicate biased wall potential on upper wall is time dependent struct gkyl_array *phi_wall_up; // biased wall potential on upper wall struct gkyl_array *phi_wall_up_host; // host copy for use in IO and projecting - gkyl_eval_on_nodes *phi_wall_up_proj; // projector for biased wall potential on upper wall + gkyl_eval_on_nodes *phi_wall_up_proj; // projector for biased wall potential on upper wall // Pointer to function that computes the time rate of change of the energy. - void (*calc_energy_dt_func)(gkyl_gyrokinetic_app *app, const struct gk_field *field, double dt, double *energy_reduced); + void (*calc_energy_dt_func)( + gkyl_gyrokinetic_app *app, const struct gk_field *field, double dt, double *energy_reduced + ); // Objects used in IWL simulations and TS BCs. struct gkyl_bc_twistshift *bc_ts_lo, *bc_ts_up; - struct gkyl_bc_basic_gyrokinetic *gfss_bc_op_core_up; // Fills upper core z-ghost with skin boundary value. - struct gkyl_bc_basic_gyrokinetic *gfss_bc_op_core_lo; // Fills lower core z-ghost with skin boundary value. + struct gkyl_bc_basic_gyrokinetic + *gfss_bc_op_core_up; // Fills upper core z-ghost with skin boundary value. + struct gkyl_bc_basic_gyrokinetic + *gfss_bc_op_core_lo; // Fills lower core z-ghost with skin boundary value. struct gkyl_array *bc_buffer; // Buffer for bc_basic. - + // Pointer to functions that make phi continuous along z. - void (*fem_projection_par_rho_func)(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gkyl_array *arr_dg, struct gkyl_array *arr_fem); - void (*fem_projection_par_phi_func)(gkyl_gyrokinetic_app *app, struct gk_field *field, - struct gkyl_array *arr_dg, struct gkyl_array *arr_fem); + void (*fem_projection_par_rho_func)( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *arr_dg, + struct gkyl_array *arr_fem + ); + void (*fem_projection_par_phi_func)( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gkyl_array *arr_dg, + struct gkyl_array *arr_fem + ); // Pointer to function to calculate the potential. void (*rhs_phi_func)(struct gkyl_gyrokinetic_app *app, struct gk_field *field); // Pointer to function that calculates the field energy. void (*calc_energy_func)(gkyl_gyrokinetic_app *app, const struct gk_field *field, double tm); - // Pointer to function that accumulates the charge density. - void (*accumulate_rhoc_func)(gkyl_gyrokinetic_app *app, struct gk_field *field, struct gk_species *s, struct gkyl_array **bflux); + // Pointer to function that accumulates the charge density. + void (*accumulate_rhoc_func)( + gkyl_gyrokinetic_app *app, struct gk_field *field, struct gk_species *s, + struct gkyl_array **bflux + ); // Pointer to function that frees memory. - void (*release_func)(const struct gkyl_gyrokinetic_app* app, struct gk_field *field); + void (*release_func)(const struct gkyl_gyrokinetic_app *app, struct gk_field *field); }; // Eirene data @@ -1424,7 +1679,7 @@ struct gk_eirene { struct gkyl_gyrokinetic_app { char name[128]; // Name of app. struct gkyl_job_pool *job_pool; // Job pool. - + int cdim; // Configuration space dimensions. int poly_order; // Polynomial order. double tcurr; // Current time. @@ -1436,7 +1691,7 @@ struct gkyl_gyrokinetic_app { int num_periodic_dir; // Number of periodic directions. int periodic_dirs[3]; // List of periodic directions. - + struct gkyl_rect_grid grid; // Config-space grid. struct gkyl_range local, local_ext; // Local, local-ext conf-space ranges. struct gkyl_range global, global_ext; // Global, global-ext conf-space ranges. @@ -1458,26 +1713,27 @@ struct gkyl_gyrokinetic_app { struct gkyl_range global_par_ext_core; // Core range extended in parallel direction. struct gkyl_range global_lower_skin_par_core, global_lower_ghost_par_core; struct gkyl_range global_upper_skin_par_core, global_upper_ghost_par_core; - struct gkyl_range global_lower_skin_par_sol , global_lower_ghost_par_sol; - struct gkyl_range global_upper_skin_par_sol , global_upper_ghost_par_sol; + struct gkyl_range global_lower_skin_par_sol, global_lower_ghost_par_sol; + struct gkyl_range global_upper_skin_par_sol, global_upper_ghost_par_sol; struct gkyl_range local_core, local_ext_core, local_sol, local_ext_sol; struct gkyl_range local_par_ext_core; // Core range extended in parallel direction. struct gkyl_range local_lower_skin_par_core, local_lower_ghost_par_core; struct gkyl_range local_upper_skin_par_core, local_upper_ghost_par_core; - struct gkyl_range local_lower_skin_par_sol , local_lower_ghost_par_sol; - struct gkyl_range local_upper_skin_par_sol , local_upper_ghost_par_sol; + struct gkyl_range local_lower_skin_par_sol, local_lower_ghost_par_sol; + struct gkyl_range local_upper_skin_par_sol, local_upper_ghost_par_sol; struct gkyl_basis basis; // conf-space basis - + struct gkyl_rect_decomp *decomp; // Volume decomposition object. struct gkyl_comm *comm; // Volume communicator object for conf-space arrays. struct gkyl_rect_decomp *decomp_plane[GKYL_MAX_CDIM]; // Plane/slab decomposition object. - struct gkyl_comm *comm_plane[GKYL_MAX_CDIM]; // Plane/slab communicator object for conf-space arrays. + struct gkyl_comm + *comm_plane[GKYL_MAX_CDIM]; // Plane/slab communicator object for conf-space arrays. // pointer to basis on device // (points to host structs if not on GPU) - struct gkyl_basis *basis_on_dev; + struct gkyl_basis *basis_on_dev; struct gk_geometry *gk_geom; struct gkyl_dg_geom *dg_geom; @@ -1494,8 +1750,10 @@ struct gkyl_gyrokinetic_app { struct gk_field *field; // pointer to field object // Pointer to function that computes the fields. - void (*calc_field_func)(gkyl_gyrokinetic_app* app, double tcurr, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]); + void (*calc_field_func)( + gkyl_gyrokinetic_app *app, double tcurr, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] + ); struct gk_eirene *eirene; // EIRENE coupling object. @@ -1510,34 +1768,34 @@ struct gkyl_gyrokinetic_app { struct gkyl_array *ps_delta_m0_ions; // Number density of the total ion positivity shift. struct gkyl_array *ps_delta_m0_elcs; // Number density of the total elc positivity shift. void (*post_pos_quasineut_func)(gkyl_gyrokinetic_app *app, struct gkyl_array *fout[]); - + // pointer to function that takes a single-step of simulation struct gkyl_update_status (*update_func)(gkyl_gyrokinetic_app *app, double dt0); struct gkyl_gyrokinetic_stat stat; // Statistics. - struct gkyl_msgpack_map_elem* io_meta_basic; // Basic metadata for I/O. + struct gkyl_msgpack_map_elem *io_meta_basic; // Basic metadata for I/O. int io_meta_basic_len; // Number of elements in io_meta_basic. - struct gkyl_msgpack_map_elem* io_meta_dg; // Metadata for I/O of grid quantities. + struct gkyl_msgpack_map_elem *io_meta_dg; // Metadata for I/O of grid quantities. int io_meta_dg_len; // Number of elements in io_meta_grid. gkyl_dynvec dts; // Record time step over time. bool is_first_dt_write_call; // Flag for integrated moments dynvec written first time. - + bool is_multib; // Is this a block in a multiblock sim? }; /** gkyl_gyrokinetic_app private API */ -static inline struct gkyl_gyrokinetic_bc * -gk_fetch_bc_with_dir_edge(struct gkyl_gyrokinetic_bc *bc_list, int num_bcs, - int dir, enum gkyl_edge_loc edge) +static inline struct gkyl_gyrokinetic_bc *gk_fetch_bc_with_dir_edge( + struct gkyl_gyrokinetic_bc *bc_list, int num_bcs, int dir, enum gkyl_edge_loc edge +) { // Given a list of gyrokinetic BCs `bc_list` of length `num_bcs`, return the // entry corresponding to the BC in the `dir` direction and the `edge` edge. // It omits GKYL_BC_GK_SKIP BCs. struct gkyl_gyrokinetic_bc *out = 0; - for (int i=0; idir == dir && bc_curr->edge == edge && bc_curr->type != GKYL_BC_GK_SKIP) { out = bc_curr; @@ -1555,8 +1813,7 @@ gk_fetch_bc_with_dir_edge(struct gkyl_gyrokinetic_bc *bc_list, int num_bcs, * @param gk Gyrokinetic input struct. * @return A gyrokinetic app object. */ -gkyl_gyrokinetic_app* -gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk); +gkyl_gyrokinetic_app *gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk); /** * Initialize the rest of the gyrokinetic app solver, after having called @@ -1573,14 +1830,14 @@ void gkyl_gyrokinetic_app_new_solver(struct gkyl_gk *gk, gkyl_gyrokinetic_app *a * @param app Gyrokinetic app object. * @param delta_ts Shift in 3D array. */ -void gyrokinetic_deflate_delta_ts(struct gkyl_gyrokinetic_app* app, struct gkyl_array *delta_ts); +void gyrokinetic_deflate_delta_ts(struct gkyl_gyrokinetic_app *app, struct gkyl_array *delta_ts); /** * Write the twistshift shift. * * @param app Gyrokinetic app object. */ -void gyrokinetic_app_write_ts_shift(gkyl_gyrokinetic_app* app); +void gyrokinetic_app_write_ts_shift(gkyl_gyrokinetic_app *app); /** * Find species with given name. @@ -1589,7 +1846,7 @@ void gyrokinetic_app_write_ts_shift(gkyl_gyrokinetic_app* app); * @param nm Name of species * @return Pointer to species with given name. NULL if not found. */ -struct gk_species* gk_find_species(const gkyl_gyrokinetic_app *app, const char *nm); +struct gk_species *gk_find_species(const gkyl_gyrokinetic_app *app, const char *nm); /** * Return index of species in the order it appears in the input. @@ -1607,7 +1864,7 @@ int gk_find_species_idx(const gkyl_gyrokinetic_app *app, const char *nm); * @param nm Name of neutral species. * @return Pointer to neutral species with given name. NULL if not found. */ -struct gk_neut_species* gk_find_neut_species(const gkyl_gyrokinetic_app *app, const char *nm); +struct gk_neut_species *gk_find_neut_species(const gkyl_gyrokinetic_app *app, const char *nm); /** * Return index of neutral species in the order it appears in the input. @@ -1627,7 +1884,7 @@ int gk_find_neut_species_idx(const gkyl_gyrokinetic_app *app, const char *nm); * @param sidx Index of species to initialize. * @param t0 Time for initial conditions. */ -void gkyl_gyrokinetic_app_apply_ic_species(gkyl_gyrokinetic_app* app, int sidx, double t0); +void gkyl_gyrokinetic_app_apply_ic_species(gkyl_gyrokinetic_app *app, int sidx, double t0); /** * Initialize neutral species by projecting initial conditions on basis @@ -1638,7 +1895,7 @@ void gkyl_gyrokinetic_app_apply_ic_species(gkyl_gyrokinetic_app* app, int sidx, * @param sidx Index of neutral species to initialize. * @param t0 Time for initial conditions. */ -void gkyl_gyrokinetic_app_apply_ic_neut_species(gkyl_gyrokinetic_app* app, int sidx, double t0); +void gkyl_gyrokinetic_app_apply_ic_neut_species(gkyl_gyrokinetic_app *app, int sidx, double t0); /** * Perform part of initialization that depends on the other species being @@ -1648,7 +1905,7 @@ void gkyl_gyrokinetic_app_apply_ic_neut_species(gkyl_gyrokinetic_app* app, int s * @param sidx Index of species to initialize. * @param t0 Time for initial conditions. */ -void gkyl_gyrokinetic_app_apply_ic_cross_species(gkyl_gyrokinetic_app* app, int sidx, double t0); +void gkyl_gyrokinetic_app_apply_ic_cross_species(gkyl_gyrokinetic_app *app, int sidx, double t0); /** * Perform part of neutral species initialization that depends on the other species being @@ -1658,7 +1915,9 @@ void gkyl_gyrokinetic_app_apply_ic_cross_species(gkyl_gyrokinetic_app* app, int * @param sidx Index of neutral species to initialize. * @param t0 Time for initial conditions. */ -void gkyl_gyrokinetic_app_apply_ic_cross_neut_species(gkyl_gyrokinetic_app* app, int sidx, double t0); +void gkyl_gyrokinetic_app_apply_ic_cross_neut_species( + gkyl_gyrokinetic_app *app, int sidx, double t0 +); /** gk_species_moment API */ @@ -1671,8 +1930,10 @@ void gkyl_gyrokinetic_app_apply_ic_cross_neut_species(gkyl_gyrokinetic_app* app, * @param nm Name string indicating moment type * @param is_integrated Whether to compute the volume integrated moment. */ -void gk_species_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_species_moment *sm, enum gkyl_distribution_moments mom_type, bool is_integrated); +void gk_species_moment_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_species_moment *sm, + enum gkyl_distribution_moments mom_type, bool is_integrated +); /** * Calculate moment, given distribution function @a fin. @@ -1682,9 +1943,10 @@ void gk_species_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_species * @param conf_rng Config-space range. * @param fin Input distribution function array */ -void gk_species_moment_calc(const struct gk_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin); +void gk_species_moment_calc( + const struct gk_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +); /** * Divide the moment by the configuration-space Jacobian for diagnostic @@ -1696,8 +1958,10 @@ void gk_species_moment_calc(const struct gk_species_moment *sm, * @param Jmom_in Moment(s) to be divided by J. * @param mom_out Array in which to place the output. */ -void gk_species_moment_diag_jacobgeo_div(const struct gkyl_gyrokinetic_app *app, - struct gk_species_moment *sm, struct gkyl_array *Jmom_in, struct gkyl_array *mom_out); +void gk_species_moment_diag_jacobgeo_div( + const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, struct gkyl_array *Jmom_in, + struct gkyl_array *mom_out +); /** * Release species moment object. @@ -1705,8 +1969,9 @@ void gk_species_moment_diag_jacobgeo_div(const struct gkyl_gyrokinetic_app *app, * @param app gyrokinetic app object * @param sm Species moment object to release. */ -void gk_species_moment_release(const struct gkyl_gyrokinetic_app *app, - const struct gk_species_moment *sm); +void gk_species_moment_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_species_moment *sm +); /** gk_positivity API */ @@ -1717,11 +1982,13 @@ void gk_species_moment_release(const struct gkyl_gyrokinetic_app *app, * @param gks Species object. * @param pos Positivity object. */ -void gk_species_positivity_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_positivity *pos); +void gk_species_positivity_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos +); -void gk_neut_species_positivity_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_positivity *pos); +void gk_neut_species_positivity_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos +); /** * Determine how many species participate in the quasineutrality enforcement @@ -1729,7 +1996,7 @@ void gk_neut_species_positivity_init(struct gkyl_gyrokinetic_app *app, struct gk * * @param app Gyrokinetic app object. */ -int gk_species_positivity_num_species_in_quasineut(gkyl_gyrokinetic_app* app); +int gk_species_positivity_num_species_in_quasineut(gkyl_gyrokinetic_app *app); /** * Apply the positivity operator. @@ -1740,11 +2007,15 @@ int gk_species_positivity_num_species_in_quasineut(gkyl_gyrokinetic_app* app); * @param fbuffer Buffer array where delta f will be held. * @param fout State array to apply the positivity operation to. */ -void gk_species_positivity_apply(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_positivity *pos, struct gkyl_array *fbuffer, struct gkyl_array *fout); +void gk_species_positivity_apply( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, + struct gkyl_array *fbuffer, struct gkyl_array *fout +); -void gk_neut_species_positivity_apply(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_positivity *pos, struct gkyl_array *fbuffer, struct gkyl_array *fout); +void gk_neut_species_positivity_apply( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, + struct gkyl_array *fbuffer, struct gkyl_array *fout +); /** * Write conf-space diagnostics of the positivity operator. @@ -1755,11 +2026,14 @@ void gk_neut_species_positivity_apply(gkyl_gyrokinetic_app *app, struct gk_neut_ * @param tm Current simulation time. * @param frame Current I/O frame. */ -void gk_species_positivity_write_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos, double tm, int frame); +void gk_species_positivity_write_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, double tm, int frame +); -void gk_neut_species_positivity_write_diags(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos, double tm, int frame); +void gk_neut_species_positivity_write_diags( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, double tm, + int frame +); /** * Calculate integrated diagnostics of the positivity operator. @@ -1769,11 +2043,13 @@ void gk_neut_species_positivity_write_diags(gkyl_gyrokinetic_app* app, struct gk * @param pos Positivity object. * @param tm Current simulation time. */ -void gk_species_positivity_calc_integrated_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_positivity *pos, double tm); +void gk_species_positivity_calc_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos, double tm +); -void gk_neut_species_positivity_calc_integrated_diags(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_positivity *pos, double tm); +void gk_neut_species_positivity_calc_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos, double tm +); /** * Write integrated diagnostics of the positivity operator. @@ -1782,11 +2058,13 @@ void gk_neut_species_positivity_calc_integrated_diags(gkyl_gyrokinetic_app* app, * @param gks Species object. * @param pos Positivity object. */ -void gk_species_positivity_write_integrated_diags(gkyl_gyrokinetic_app *app, - struct gk_species *gks, struct gk_positivity *pos); +void gk_species_positivity_write_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_positivity *pos +); -void gk_neut_species_positivity_write_integrated_diags(gkyl_gyrokinetic_app *app, - struct gk_neut_species *gkns, struct gk_positivity *pos); +void gk_neut_species_positivity_write_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_positivity *pos +); /** * Release species positivity operator. @@ -1794,9 +2072,13 @@ void gk_neut_species_positivity_write_integrated_diags(gkyl_gyrokinetic_app *app * @param app Gyrokinetic app object. * @param pos Positivity object. */ -void gk_species_positivity_release(const struct gkyl_gyrokinetic_app *app, const struct gk_positivity *pos); +void gk_species_positivity_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_positivity *pos +); -void gk_neut_species_positivity_release(const struct gkyl_gyrokinetic_app *app, const struct gk_positivity *pos); +void gk_neut_species_positivity_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_positivity *pos +); /** * Reset the positivity operator. @@ -1807,11 +2089,15 @@ void gk_neut_species_positivity_release(const struct gkyl_gyrokinetic_app *app, * @param pos Positivity object. * @param pos_inp Positivity input parameters. */ -void gk_species_positivity_reset(gkyl_gyrokinetic_app* app, double tm, - struct gk_species *gks, struct gk_positivity *pos, struct gkyl_gyrokinetic_positivity pos_inp); +void gk_species_positivity_reset( + gkyl_gyrokinetic_app *app, double tm, struct gk_species *gks, struct gk_positivity *pos, + struct gkyl_gyrokinetic_positivity pos_inp +); -void gk_neut_species_positivity_reset(gkyl_gyrokinetic_app* app, double tm, - struct gk_neut_species *gkns, struct gk_positivity *pos, struct gkyl_gyrokinetic_positivity pos_inp); +void gk_neut_species_positivity_reset( + gkyl_gyrokinetic_app *app, double tm, struct gk_neut_species *gkns, struct gk_positivity *pos, + struct gkyl_gyrokinetic_positivity pos_inp +); /** gk_species_lte API */ @@ -1823,8 +2109,10 @@ void gk_neut_species_positivity_reset(gkyl_gyrokinetic_app* app, double tm, * @param lte Species lte object * @param corr_inp Input struct with moment correction inputs */ -void gk_species_lte_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_lte *lte, struct correct_all_moms_inp corr_inp); +void gk_species_lte_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_lte *lte, + struct correct_all_moms_inp corr_inp +); /** * Compute LTE distribution from input moments @@ -1834,8 +2122,10 @@ void gk_species_lte_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, * @param lte Pointer to lte object * @param moms_lte Input LTE moments */ -void gk_species_lte_from_moms(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lte *lte, const struct gkyl_array *moms_lte); +void gk_species_lte_from_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lte *lte, + const struct gkyl_array *moms_lte +); /** * Compute equivalent LTE distribution from input distribution function. @@ -1845,8 +2135,10 @@ void gk_species_lte_from_moms(gkyl_gyrokinetic_app *app, const struct gk_species * @param lte Pointer to lte * @param fin Input distribution function */ -void gk_species_lte(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_lte *lte, const struct gkyl_array *fin); +void gk_species_lte( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_lte *lte, + const struct gkyl_array *fin +); /** * Write the LTE correction status. @@ -1854,7 +2146,7 @@ void gk_species_lte(gkyl_gyrokinetic_app *app, const struct gk_species *species, * @param app Gyrokinetic app object * @param gks Pointer to species */ -void gk_species_lte_write_max_corr_status(gkyl_gyrokinetic_app* app, struct gk_species *gks); +void gk_species_lte_write_max_corr_status(gkyl_gyrokinetic_app *app, struct gk_species *gks); /** * Release species lte object. @@ -1873,8 +2165,9 @@ void gk_species_lte_release(const struct gkyl_gyrokinetic_app *app, const struct * @param gks Species object. * @param gkcls Species collisionless object. */ -void gk_species_collisionless_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_collisionless *gkcls); +void gk_species_collisionless_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls +); /** * Compute the collisionless phase-space flux. @@ -1884,8 +2177,10 @@ void gk_species_collisionless_init(struct gkyl_gyrokinetic_app *app, struct gk_s * @param gkcls Species collisionless object. * @param fin Input distribution function. */ -void gk_species_collisionless_flux(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin); +void gk_species_collisionless_flux( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin +); /** * Compute RHS contribution from collisionless terms. @@ -1896,8 +2191,10 @@ void gk_species_collisionless_flux(gkyl_gyrokinetic_app *app, struct gk_species * @param fin Input distribution function. * @param rhs collisionless contribution to df/dt. */ -void gk_species_collisionless_rhs(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_collisionless *gkcls, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_species_collisionless_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Write out diagnostics from the collisionless terms. @@ -1908,8 +2205,10 @@ void gk_species_collisionless_rhs(gkyl_gyrokinetic_app *app, struct gk_species * * @param tm Current simulation time. * @param frame Current I/O frame. */ -void gk_species_collisionless_write_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_collisionless *gkcls, double tm, int frame); +void gk_species_collisionless_write_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_collisionless *gkcls, double tm, + int frame +); /** * Release species collisionless object. @@ -1917,7 +2216,9 @@ void gk_species_collisionless_write_diags(gkyl_gyrokinetic_app* app, struct gk_s * @param app Gyrokinetic app object. * @param gkcls Species collisionless object. */ -void gk_species_collisionless_release(const struct gkyl_gyrokinetic_app *app, const struct gk_collisionless *gkcls); +void gk_species_collisionless_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_collisionless *gkcls +); /** * Reset the collisionless solver. @@ -1927,8 +2228,10 @@ void gk_species_collisionless_release(const struct gkyl_gyrokinetic_app *app, co * @param gks Species object to delete. * @param gkcls Input parameters for collisionless solver. */ -void gk_species_collisionless_reset(gkyl_gyrokinetic_app* app, double tm, struct gk_species *gks, - struct gk_collisionless *gkcls, struct gkyl_gyrokinetic_collisionless gkcls_inp); +void gk_species_collisionless_reset( + gkyl_gyrokinetic_app *app, double tm, struct gk_species *gks, struct gk_collisionless *gkcls, + struct gkyl_gyrokinetic_collisionless gkcls_inp +); /** gk_neut_species_collisionless API */ @@ -1939,8 +2242,9 @@ void gk_species_collisionless_reset(gkyl_gyrokinetic_app* app, double tm, struct * @param gkns Neutral species object. * @param gkcls Species collisionless object. */ -void gk_neut_species_collisionless_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_collisionless *gkcls); +void gk_neut_species_collisionless_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_collisionless *gkcls +); /** * Compute the collisionless phase-space flux. @@ -1950,8 +2254,10 @@ void gk_neut_species_collisionless_init(struct gkyl_gyrokinetic_app *app, struct * @param gkcls Species collisionless object. * @param fin Input distribution function. */ -void gk_neut_species_collisionless_flux(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - struct gk_collisionless *gkcls, const struct gkyl_array *fin); +void gk_neut_species_collisionless_flux( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, struct gk_collisionless *gkcls, + const struct gkyl_array *fin +); /** * Compute RHS contribution from collisionless terms. @@ -1962,8 +2268,10 @@ void gk_neut_species_collisionless_flux(gkyl_gyrokinetic_app *app, struct gk_neu * @param fin Input distribution function. * @param rhs collisionless contribution to df/dt. */ -void gk_neut_species_collisionless_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_collisionless *gkcls, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_neut_species_collisionless_rhs( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_collisionless *gkcls, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Write out diagnostics from the collisionless terms. @@ -1974,8 +2282,10 @@ void gk_neut_species_collisionless_rhs(gkyl_gyrokinetic_app *app, struct gk_neut * @param tm Current simulation time. * @param frame Current I/O frame. */ -void gk_neut_species_collisionless_write_diags(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, - struct gk_collisionless *gkcls, double tm, int frame); +void gk_neut_species_collisionless_write_diags( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_collisionless *gkcls, + double tm, int frame +); /** * Release species collisionless object. @@ -1983,7 +2293,9 @@ void gk_neut_species_collisionless_write_diags(gkyl_gyrokinetic_app* app, struct * @param app Gyrokinetic app object. * @param gkcls Species collisionless object. */ -void gk_neut_species_collisionless_release(const struct gkyl_gyrokinetic_app *app, const struct gk_collisionless *gkcls); +void gk_neut_species_collisionless_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_collisionless *gkcls +); /** gk_species_radiation API */ @@ -1994,8 +2306,9 @@ void gk_neut_species_collisionless_release(const struct gkyl_gyrokinetic_app *ap * @param s Species object * @param rad Species radiation drag object */ -void gk_species_radiation_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_rad_drag *rad); +void gk_species_radiation_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_rad_drag *rad +); /** * Compute necessary moments for radiation drag object @@ -2006,8 +2319,10 @@ void gk_species_radiation_init(struct gkyl_gyrokinetic_app *app, struct gk_speci * @param fin Input distribution functions (size num_species) * @param fin_neut Input neutral distribution functions (size num_species) */ -void gk_species_radiation_moms(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]); +void gk_species_radiation_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +); /** * Compute RHS from radiation drag object. @@ -2018,8 +2333,10 @@ void gk_species_radiation_moms(gkyl_gyrokinetic_app *app, const struct gk_specie * @param fin Input distribution function * @param rhs On output, the RHS from LBO */ -void gk_species_radiation_rhs(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_rad_drag *rad, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_species_radiation_rhs( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_rad_drag *rad, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Write species radiation drag. @@ -2029,7 +2346,9 @@ void gk_species_radiation_rhs(gkyl_gyrokinetic_app *app, const struct gk_species * @param tm Simulation time * @param frame Simulation output frame */ -void gk_species_radiation_write_drag(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); +void gk_species_radiation_write_drag( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +); /** * Write species radiation emissivity. @@ -2039,7 +2358,9 @@ void gk_species_radiation_write_drag(gkyl_gyrokinetic_app* app, struct gk_specie * @param tm Simulation time * @param frame Simulation output frame */ -void gk_species_radiation_write_emissivity(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); +void gk_species_radiation_write_emissivity( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +); /** * Calculate species radiation integrated moments. @@ -2048,7 +2369,9 @@ void gk_species_radiation_write_emissivity(gkyl_gyrokinetic_app* app, struct gk_ * @param gks Pointer to species * @param tm Simulation time */ -void gk_species_radiation_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm); +void gk_species_radiation_calc_integrated_mom( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm +); /** * Write species radiation integrated moments. @@ -2056,7 +2379,7 @@ void gk_species_radiation_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct * @param app gyrokinetic app object * @param gks Pointer to species */ -void gk_species_radiation_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks); +void gk_species_radiation_write_integrated_mom(gkyl_gyrokinetic_app *app, struct gk_species *gks); /** * Release species radiation drag object. @@ -2064,7 +2387,9 @@ void gk_species_radiation_write_integrated_mom(gkyl_gyrokinetic_app* app, struct * @param app gyrokinetic app object * @param rad Species radiation drag object to release */ -void gk_species_radiation_release(const struct gkyl_gyrokinetic_app *app, const struct gk_rad_drag *rad); +void gk_species_radiation_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_rad_drag *rad +); /** gk_species_lbo API */ @@ -2075,8 +2400,9 @@ void gk_species_radiation_release(const struct gkyl_gyrokinetic_app *app, const * @param s Species object. * @param lbo Species LBO object. */ -void gk_species_lbo_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_lbo_collisions *lbo); +void gk_species_lbo_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_lbo_collisions *lbo +); /** * Initialize species LBO cross-collisions object. @@ -2085,8 +2411,9 @@ void gk_species_lbo_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gk * @param s Species object. * @param lbo Species LBO object. */ -void gk_species_lbo_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_lbo_collisions *lbo); +void gk_species_lbo_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_lbo_collisions *lbo +); /** * Compute necessary moments and boundary @@ -2097,8 +2424,10 @@ void gk_species_lbo_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_speci * @param lbo Pointer to LBO. * @param fin Input distribution function. */ -void gk_species_lbo_moms(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin); +void gk_species_lbo_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin +); /** * Compute necessary moments for cross-species LBO collisions. @@ -2108,8 +2437,10 @@ void gk_species_lbo_moms(gkyl_gyrokinetic_app *app, const struct gk_species *gks * @param lbo Pointer to LBO. * @param fin Input distribution function. */ -void gk_species_lbo_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin); +void gk_species_lbo_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin +); /** * Compute RHS from LBO collisions. @@ -2120,8 +2451,10 @@ void gk_species_lbo_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_specie * @param fin Input distribution function. * @param rhs On output, the RHS from LBO. */ -void gk_species_lbo_rhs(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_lbo_collisions *lbo, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_species_lbo_rhs( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_lbo_collisions *lbo, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Write moments from LBO object. @@ -2131,7 +2464,9 @@ void gk_species_lbo_rhs(gkyl_gyrokinetic_app *app, const struct gk_species *gks, * @param tm Simulation time. * @param frame Simulation output frame. */ -void gk_species_lbo_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); +void gk_species_lbo_write_mom( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +); /** * Release species LBO object. @@ -2139,7 +2474,9 @@ void gk_species_lbo_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, * @param app gyrokinetic app object. * @param lbo Species LBO object to release. */ -void gk_species_lbo_release(const struct gkyl_gyrokinetic_app *app, const struct gk_lbo_collisions *lbo); +void gk_species_lbo_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_lbo_collisions *lbo +); /** gk_species_bgk API */ @@ -2150,8 +2487,9 @@ void gk_species_lbo_release(const struct gkyl_gyrokinetic_app *app, const struct * @param gks Species object. * @param bgk Species BGK object. */ -void gk_species_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_bgk_collisions *bgk); +void gk_species_bgk_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk +); /** * Initialize species BGK cross-collisions object. @@ -2160,8 +2498,9 @@ void gk_species_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gk * @param gks Species object. * @param bgk Species BGK object. */ -void gk_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_bgk_collisions *bgk); +void gk_species_bgk_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk +); /** * Compute necessary moments and boundary @@ -2172,11 +2511,15 @@ void gk_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_speci * @param bgk Pointer to BGK. * @param fin Input distribution function. */ -void gk_species_bgk_moms(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); +void gk_species_bgk_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +); -void gk_species_bgk_moms_implicit(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); +void gk_species_bgk_moms_implicit( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +); /** * Compute necessary moments for cross-species BGK collisions. @@ -2186,11 +2529,15 @@ void gk_species_bgk_moms_implicit(gkyl_gyrokinetic_app *app, const struct gk_spe * @param bgk Pointer to BGK. * @param fin Input distribution function. */ -void gk_species_bgk_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); +void gk_species_bgk_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +); -void gk_species_bgk_cross_moms_implicit(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); +void gk_species_bgk_cross_moms_implicit( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +); /** * Compute RHS from BGK collisions (explicit integrator). @@ -2201,8 +2548,10 @@ void gk_species_bgk_cross_moms_implicit(gkyl_gyrokinetic_app *app, const struct * @param fin Input distribution function. * @param rhs On output, the RHS from BGK. */ -void gk_species_bgk_rhs(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_species_bgk_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Compute RHS from BGK collisions (implicit integrator). @@ -2214,8 +2563,10 @@ void gk_species_bgk_rhs(gkyl_gyrokinetic_app *app, struct gk_species *gks, * @param dt Time step. * @param rhs On output, the RHS from BGK. */ -void gk_species_bgk_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs); +void gk_species_bgk_rhs_implicit( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs +); /** * Write moments from BGK object. @@ -2225,7 +2576,9 @@ void gk_species_bgk_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_species *g * @param tm Simulation time. * @param frame Simulation output frame. */ -void gk_species_bgk_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); +void gk_species_bgk_write_mom( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +); /** * Release species BGK object. @@ -2233,7 +2586,9 @@ void gk_species_bgk_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, * @param app gyrokinetic app object. * @param bgk Species BGK object to release. */ -void gk_species_bgk_release(const struct gkyl_gyrokinetic_app *app, const struct gk_bgk_collisions *bgk); +void gk_species_bgk_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_bgk_collisions *bgk +); /** gk_species_react API */ @@ -2246,8 +2601,10 @@ void gk_species_bgk_release(const struct gkyl_gyrokinetic_app *app, const struct * @param react Species reaction object * @param all_gk Boolean for if the reactions are between only GK species */ -void gk_species_react_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gkyl_gyrokinetic_react inp, struct gk_react *react, bool all_gk); +void gk_species_react_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gkyl_gyrokinetic_react inp, + struct gk_react *react, bool all_gk +); /** * Initialize species reactions "cross-collisions" object @@ -2257,8 +2614,9 @@ void gk_species_react_init(struct gkyl_gyrokinetic_app *app, struct gk_species * * @param s Species object * @param react Species react object */ -void gk_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_react *react); +void gk_species_react_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_react *react +); /** * Compute necessary rates and moments for reactions @@ -2270,8 +2628,10 @@ void gk_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_spe * @param fin Input distribution functions (size: num_species) * @param fin_neut Input neutral distribution functions (size: num_neut_species) */ -void gk_species_react_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_react *react, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]); +void gk_species_react_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_react *react, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +); /** * Compute RHS from reactions @@ -2283,8 +2643,10 @@ void gk_species_react_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_spec * @param fin Input distribution function * @param rhs On output, the RHS from react (df/dt) */ -void gk_species_react_rhs(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_react *react, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_species_react_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_react *react, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Write reaction rate. @@ -2296,8 +2658,10 @@ void gk_species_react_rhs(gkyl_gyrokinetic_app *app, struct gk_species *s, * @param tm Simulation time * @param frame Simulation output frame */ -void gk_species_react_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, struct gk_react *gkr, - int ridx, double tm, int frame); +void gk_species_react_write( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_react *gkr, int ridx, double tm, + int frame +); /** * Release species react object. @@ -2318,9 +2682,10 @@ void gk_species_react_release(const struct gkyl_gyrokinetic_app *app, const stru * @param bflux_type Indicate whether to compute fluxes, flux moments or diagnostics. * @param add_moms_inp Additional moments to step in time if bflux_type=GK_SPECIES_BFLUX_CALC_FLUX_STEP_MOMS. */ -void gk_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, - struct gk_boundary_fluxes *bflux, enum gkyl_species_bflux_type bflux_type, - struct gkyl_phase_diagnostics_inp add_moms_inp); +void gk_species_bflux_init( + struct gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, + enum gkyl_species_bflux_type bflux_type, struct gkyl_phase_diagnostics_inp add_moms_inp +); /** * In case time-integrated volume-integrated boundary flux diagnostics are @@ -2330,9 +2695,9 @@ void gk_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, * @param spec_in Species object. * @param bflux Species boundary flux object. */ -void -gk_species_bflux_read_voltime_integrated_mom(gkyl_gyrokinetic_app *app, - void *species, struct gk_boundary_fluxes *bflux); +void gk_species_bflux_read_voltime_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux +); /** * Compute boundary flux, either for another solver or for diagnostics. @@ -2344,8 +2709,10 @@ gk_species_bflux_read_voltime_integrated_mom(gkyl_gyrokinetic_app *app, * @param fin Input distribution function. * @param rhs On output, the boundary fluxes stored in the ghost cells of rhs. */ -void gk_species_bflux_rhs(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_species_bflux_rhs( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *fin, + struct gkyl_array *rhs +); /** * Like gk_species_bflux_rhs but actually calculates boundary fluxes, unlike @@ -2356,8 +2723,10 @@ void gk_species_bflux_rhs(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes * * @param fin Input distribution function. * @param rhs On output, the boundary fluxes stored in the ghost cells of rhs. */ -void gk_species_bflux_rhs_calc(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_species_bflux_rhs_calc( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *fin, + struct gkyl_array *rhs +); /** * Copy the boundary fluxes into a given range of a given phase-space array. @@ -2368,9 +2737,10 @@ void gk_species_bflux_rhs_calc(gkyl_gyrokinetic_app *app, struct gk_boundary_flu * @param out Array to copy the boundary flux into. * @param out_rng Range to copy the boundary flux into. */ -void -gk_species_bflux_get_flux(struct gk_boundary_fluxes *bflux, int dir, - enum gkyl_edge_loc edge, struct gkyl_array *out, const struct gkyl_range *out_rng); +void gk_species_bflux_get_flux( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, struct gkyl_array *out, + const struct gkyl_range *out_rng +); /** * Copy a boundary fluxe moment into a given range of a given conf-space array. @@ -2383,10 +2753,11 @@ gk_species_bflux_get_flux(struct gk_boundary_fluxes *bflux, int dir, * @param out Array to copy the boundary flux moment into. * @param out_rng Range to copy the boundary flux moment into. */ -void -gk_species_bflux_get_flux_mom(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, +void gk_species_bflux_get_flux_mom( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, - const struct gkyl_range *out_rng); + const struct gkyl_range *out_rng +); /** * Compute moments of the boundary fluxes. @@ -2396,8 +2767,10 @@ gk_species_bflux_get_flux_mom(struct gk_boundary_fluxes *bflux, int dir, enum gk * @param rhs On output, the boundary fluxes stored in the ghost cells of rhs. * @param bflux_moms Array of moments of boundary fluxes through every boundary. */ -void gk_species_bflux_calc_moms(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *rhs, struct gkyl_array **bflux_moms); +void gk_species_bflux_calc_moms( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *rhs, + struct gkyl_array **bflux_moms +); /** * Clear the boundary fluxes at each boundary. @@ -2407,9 +2780,10 @@ void gk_species_bflux_calc_moms(gkyl_gyrokinetic_app *app, struct gk_boundary_fl * @param bflux_in Array of boundary fluxes to clear. * @param val Value to set array to. */ -void -gk_species_bflux_clear(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_in, double val); +void gk_species_bflux_clear( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_in, + double val +); /** * Scale the boundary fluxes at each boundary. @@ -2419,9 +2793,10 @@ gk_species_bflux_clear(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bfl * @param bflux_in Array of boundary fluxes to clear. * @param val Value to scale the fluxes by. */ -void -gk_species_bflux_scale(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_in, double val); +void gk_species_bflux_scale( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_in, + double val +); /** * Step the diagnotic boundary fluxes forward once. @@ -2432,9 +2807,10 @@ gk_species_bflux_scale(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bfl * @param dt Time step. * @param bflux_in Array of input boundary fluxes. */ -void -gk_species_bflux_step_f(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_out, double dt, struct gkyl_array **bflux_in); +void gk_species_bflux_step_f( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_out, + double dt, struct gkyl_array **bflux_in +); /** * Set a stage of the boundary fluxes equal to another. @@ -2445,9 +2821,10 @@ gk_species_bflux_step_f(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bf * @param fac Multiplicative factor. * @param bflux_in Array of input boundary fluxes. */ -void -gk_species_bflux_set(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_out, double fac, struct gkyl_array **bflux_in); +void gk_species_bflux_set( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_out, + double fac, struct gkyl_array **bflux_in +); /** * Accumulate a stage of the boundary fluxes onto another. @@ -2458,9 +2835,10 @@ gk_species_bflux_set(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux * @param fac Multiplicative factor. * @param bflux_in Array of input boundary fluxes. */ -void -gk_species_bflux_accumulate(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_out, double fac, struct gkyl_array **bflux_in); +void gk_species_bflux_accumulate( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_out, + double fac, struct gkyl_array **bflux_in +); /** * Combine the diagnotic boundary fluxes for multi-stage RK stepper. @@ -2473,9 +2851,10 @@ gk_species_bflux_accumulate(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes * @param fac2 Factor to multiply bflux_in2 by. * @param bflux_in2 Array of input boundary fluxes. */ -void -gk_species_bflux_combine(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2); +void gk_species_bflux_combine( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2 +); /** * Copy diagnotic boundary fluxes. @@ -2485,9 +2864,10 @@ gk_species_bflux_combine(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *b * @param bflux_out Array of output boundary fluxes. * @param bflux_in Array of input boundary fluxes. */ -void -gk_species_bflux_copy(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_fout, struct gkyl_array **bflux_in); +void gk_species_bflux_copy( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_fout, + struct gkyl_array **bflux_in +); /** * Calculate the integrated moments of the diagnostic boundary fluxes. @@ -2496,9 +2876,9 @@ gk_species_bflux_copy(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflu * @param species Species object. * @param tm Current simulation time. */ -void -gk_species_bflux_calc_integrated_mom(gkyl_gyrokinetic_app* app, void *species, - struct gk_boundary_fluxes *bflux, double tm); +void gk_species_bflux_calc_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm +); /** * Calculate the time integrated, integrated moments @@ -2508,9 +2888,9 @@ gk_species_bflux_calc_integrated_mom(gkyl_gyrokinetic_app* app, void *species, * @param species Species object. * @param tm Current simulation time. */ -void -gk_species_bflux_calc_voltime_integrated_mom(gkyl_gyrokinetic_app* app, - void *species, struct gk_boundary_fluxes *bflux, double tm); +void gk_species_bflux_calc_voltime_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm +); /** * Write the integrated moments of the diagnostic boundary fluxes. @@ -2518,9 +2898,9 @@ gk_species_bflux_calc_voltime_integrated_mom(gkyl_gyrokinetic_app* app, * @param app Gyrokinetic app object. * @param species Species object. */ -void -gk_species_bflux_write_integrated_mom(gkyl_gyrokinetic_app *app, - void *species, struct gk_boundary_fluxes *bflux); +void gk_species_bflux_write_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux +); /** * Write the moments of the diagnostic boundary fluxes. @@ -2530,9 +2910,9 @@ gk_species_bflux_write_integrated_mom(gkyl_gyrokinetic_app *app, * @param tm Current simulation time. * @param frame Current frame. */ -void -gk_species_bflux_write_mom(gkyl_gyrokinetic_app *app, void *species, - struct gk_boundary_fluxes *bflux, double tm, int frame); +void gk_species_bflux_write_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm, int frame +); /** * Release species boundary flux object. @@ -2541,8 +2921,10 @@ gk_species_bflux_write_mom(gkyl_gyrokinetic_app *app, void *species, * @param species Species object. * @param bflux Species boundary flux object to release. */ -void gk_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const void *species, - const struct gk_boundary_fluxes *bflux); +void gk_species_bflux_release( + const struct gkyl_gyrokinetic_app *app, const void *species, + const struct gk_boundary_fluxes *bflux +); /** gk_neut_species_boundary_fluxes API */ @@ -2555,9 +2937,10 @@ void gk_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const void * @param bflux_type Indicate whether to compute fluxes, flux moments or diagnostics. * @param add_moms_inp Additional moments to step in time if bflux_type=gk_neut_species_BFLUX_CALC_FLUX_STEP_MOMS. */ -void gk_neut_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, - struct gk_boundary_fluxes *bflux, enum gkyl_species_bflux_type bflux_type, - struct gkyl_phase_diagnostics_inp add_moms_inp); +void gk_neut_species_bflux_init( + struct gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, + enum gkyl_species_bflux_type bflux_type, struct gkyl_phase_diagnostics_inp add_moms_inp +); /** * In case time-integrated volume-integrated boundary flux diagnostics are @@ -2567,9 +2950,9 @@ void gk_neut_species_bflux_init(struct gkyl_gyrokinetic_app *app, void *species, * @param spec_in Species object. * @param bflux Species boundary flux object. */ -void -gk_neut_species_bflux_read_voltime_integrated_mom(gkyl_gyrokinetic_app *app, - void *species, struct gk_boundary_fluxes *bflux); +void gk_neut_species_bflux_read_voltime_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux +); /** * Compute boundary flux, either for another solver or for diagnostics. @@ -2581,8 +2964,10 @@ gk_neut_species_bflux_read_voltime_integrated_mom(gkyl_gyrokinetic_app *app, * @param fin Input distribution function. * @param rhs On output, the boundary fluxes stored in the ghost cells of rhs. */ -void gk_neut_species_bflux_rhs(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_neut_species_bflux_rhs( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *fin, + struct gkyl_array *rhs +); /** * Like gk_neut_species_bflux_rhs but actually calculates boundary fluxes, unlike @@ -2593,8 +2978,10 @@ void gk_neut_species_bflux_rhs(gkyl_gyrokinetic_app *app, struct gk_boundary_flu * @param fin Input distribution function. * @param rhs On output, the boundary fluxes stored in the ghost cells of rhs. */ -void gk_neut_species_bflux_rhs_calc(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_neut_species_bflux_rhs_calc( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *fin, + struct gkyl_array *rhs +); /** * Copy the boundary fluxes into a given range of a given phase-space array. @@ -2605,9 +2992,10 @@ void gk_neut_species_bflux_rhs_calc(gkyl_gyrokinetic_app *app, struct gk_boundar * @param out Array to copy the boundary flux into. * @param out_rng Range to copy the boundary flux into. */ -void -gk_neut_species_bflux_get_flux(struct gk_boundary_fluxes *bflux, int dir, - enum gkyl_edge_loc edge, struct gkyl_array *out, const struct gkyl_range *out_rng); +void gk_neut_species_bflux_get_flux( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, struct gkyl_array *out, + const struct gkyl_range *out_rng +); /** * Copy a boundary fluxe moment into a given range of a given conf-space array. @@ -2620,10 +3008,11 @@ gk_neut_species_bflux_get_flux(struct gk_boundary_fluxes *bflux, int dir, * @param out Array to copy the boundary flux moment into. * @param out_rng Range to copy the boundary flux moment into. */ -void -gk_neut_species_bflux_get_flux_mom(struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, +void gk_neut_species_bflux_get_flux_mom( + struct gk_boundary_fluxes *bflux, int dir, enum gkyl_edge_loc edge, enum gkyl_distribution_moments mom_type, struct gkyl_array **bflux_moms, struct gkyl_array *out, - const struct gkyl_range *out_rng); + const struct gkyl_range *out_rng +); /** * Compute moments of the boundary fluxes. @@ -2633,8 +3022,10 @@ gk_neut_species_bflux_get_flux_mom(struct gk_boundary_fluxes *bflux, int dir, en * @param rhs On output, the boundary fluxes stored in the ghost cells of rhs. * @param bflux_out Array of moments of boundary fluxes through every boundary. */ -void gk_neut_species_bflux_calc_moms(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - const struct gkyl_array *rhs, struct gkyl_array **bflux_moms); +void gk_neut_species_bflux_calc_moms( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, const struct gkyl_array *rhs, + struct gkyl_array **bflux_moms +); /** * Clear the boundary fluxes at each boundary. @@ -2644,9 +3035,10 @@ void gk_neut_species_bflux_calc_moms(gkyl_gyrokinetic_app *app, struct gk_bounda * @param bflux_in Array of boundary fluxes to clear. * @param val Value to set array to. */ -void -gk_neut_species_bflux_clear(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_in, double val); +void gk_neut_species_bflux_clear( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_in, + double val +); /** * Scale the boundary fluxes at each boundary. @@ -2656,9 +3048,10 @@ gk_neut_species_bflux_clear(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes * @param bflux_in Array of boundary fluxes to clear. * @param val Value to scale the fluxes by. */ -void -gk_neut_species_bflux_scale(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_in, double val); +void gk_neut_species_bflux_scale( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_in, + double val +); /** * Step the diagnotic boundary fluxes forward once. @@ -2669,9 +3062,10 @@ gk_neut_species_bflux_scale(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes * @param dt Time step. * @param bflux_in Array of input boundary fluxes. */ -void -gk_neut_species_bflux_step_f(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_out, double dt, struct gkyl_array **bflux_in); +void gk_neut_species_bflux_step_f( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_out, + double dt, struct gkyl_array **bflux_in +); /** * Set a stage of the boundary fluxes equal to another. @@ -2682,9 +3076,10 @@ gk_neut_species_bflux_step_f(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxe * @param fac Multiplicative factor. * @param bflux_in Array of input boundary fluxes. */ -void -gk_neut_species_bflux_set(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_out, double fac, struct gkyl_array **bflux_in); +void gk_neut_species_bflux_set( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_out, + double fac, struct gkyl_array **bflux_in +); /** * Accumulate a stage of the boundary fluxes onto another. @@ -2695,9 +3090,10 @@ gk_neut_species_bflux_set(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes * * @param fac Multiplicative factor. * @param bflux_in Array of input boundary fluxes. */ -void -gk_neut_species_bflux_accumulate(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_out, double fac, struct gkyl_array **bflux_in); +void gk_neut_species_bflux_accumulate( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_out, + double fac, struct gkyl_array **bflux_in +); /** * Combine the diagnotic boundary fluxes for multi-stage RK stepper. @@ -2710,9 +3106,10 @@ gk_neut_species_bflux_accumulate(gkyl_gyrokinetic_app *app, struct gk_boundary_f * @param fac2 Factor to multiply bflux_in2 by. * @param bflux_in2 Array of input boundary fluxes. */ -void -gk_neut_species_bflux_combine(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **fout, double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2); +void gk_neut_species_bflux_combine( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **fout, + double fac1, struct gkyl_array **fin1, double fac2, struct gkyl_array **fin2 +); /** * Copy diagnotic boundary fluxes. @@ -2722,9 +3119,10 @@ gk_neut_species_bflux_combine(gkyl_gyrokinetic_app *app, struct gk_boundary_flux * @param bflux_out Array of output boundary fluxes. * @param bflux_in Array of input boundary fluxes. */ -void -gk_neut_species_bflux_copy(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, - struct gkyl_array **bflux_fout, struct gkyl_array **bflux_in); +void gk_neut_species_bflux_copy( + gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes *bflux, struct gkyl_array **bflux_fout, + struct gkyl_array **bflux_in +); /** * Calculate the integrated moments of the diagnostic boundary fluxes. @@ -2733,9 +3131,9 @@ gk_neut_species_bflux_copy(gkyl_gyrokinetic_app *app, struct gk_boundary_fluxes * @param species Species object. * @param tm Current simulation time. */ -void -gk_neut_species_bflux_calc_integrated_mom(gkyl_gyrokinetic_app* app, void *species, - struct gk_boundary_fluxes *bflux, double tm); +void gk_neut_species_bflux_calc_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm +); /** * Calculate the time integrated, integrated moments @@ -2745,9 +3143,9 @@ gk_neut_species_bflux_calc_integrated_mom(gkyl_gyrokinetic_app* app, void *speci * @param species Species object. * @param tm Current simulation time. */ -void -gk_neut_species_bflux_calc_voltime_integrated_mom(gkyl_gyrokinetic_app* app, - void *species, struct gk_boundary_fluxes *bflux, double tm); +void gk_neut_species_bflux_calc_voltime_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm +); /** * Write the integrated moments of the diagnostic boundary fluxes. @@ -2755,9 +3153,9 @@ gk_neut_species_bflux_calc_voltime_integrated_mom(gkyl_gyrokinetic_app* app, * @param app Gyrokinetic app object. * @param species Species object. */ -void -gk_neut_species_bflux_write_integrated_mom(gkyl_gyrokinetic_app *app, - void *species, struct gk_boundary_fluxes *bflux); +void gk_neut_species_bflux_write_integrated_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux +); /** * Write the moments of the diagnostic boundary fluxes. @@ -2767,9 +3165,9 @@ gk_neut_species_bflux_write_integrated_mom(gkyl_gyrokinetic_app *app, * @param tm Current simulation time. * @param frame Current frame. */ -void -gk_neut_species_bflux_write_mom(gkyl_gyrokinetic_app *app, void *species, - struct gk_boundary_fluxes *bflux, double tm, int frame); +void gk_neut_species_bflux_write_mom( + gkyl_gyrokinetic_app *app, void *species, struct gk_boundary_fluxes *bflux, double tm, int frame +); /** * Release species boundary flux object. @@ -2778,8 +3176,10 @@ gk_neut_species_bflux_write_mom(gkyl_gyrokinetic_app *app, void *species, * @param species Species object. * @param bflux Species boundary flux object to release. */ -void gk_neut_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const void *species, - const struct gk_boundary_fluxes *bflux); +void gk_neut_species_bflux_release( + const struct gkyl_gyrokinetic_app *app, const void *species, + const struct gk_boundary_fluxes *bflux +); /** gk_species_projection API */ @@ -2791,8 +3191,10 @@ void gk_neut_species_bflux_release(const struct gkyl_gyrokinetic_app *app, const * @param inp Input struct for projection (contains functions pointers for type of projection). * @param proj Species projection object. */ -void gk_species_projection_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj); +void gk_species_projection_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gkyl_gyrokinetic_projection inp, + struct gk_proj *proj +); /** * Compute species projection. @@ -2803,8 +3205,10 @@ void gk_species_projection_init(struct gkyl_gyrokinetic_app *app, struct gk_spec * @param f Output distribution function from projection. * @param tm Time for use in projection. */ -void gk_species_projection_calc(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_proj *proj, struct gkyl_array *f, double tm); +void gk_species_projection_calc( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_proj *proj, struct gkyl_array *f, + double tm +); /** * Release species projection object. @@ -2812,7 +3216,9 @@ void gk_species_projection_calc(gkyl_gyrokinetic_app *app, struct gk_species *sp * @param app gyrokinetic app object. * @param proj Species projection object to release. */ -void gk_species_projection_release(const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj); +void gk_species_projection_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj +); /** gk_species_source API */ @@ -2823,7 +3229,9 @@ void gk_species_projection_release(const struct gkyl_gyrokinetic_app *app, const * @param s Species object. * @param src Species source object. */ -void gk_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_source *src); +void gk_species_source_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_source *src +); /** * Compute species applied source term. @@ -2834,8 +3242,10 @@ void gk_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_species * @param f_buffer Phase-space buffer used to project the source. * @param tm Time for use in source. */ -void gk_species_source_calc(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_source *src, struct gkyl_array *f_buffer, double tm); +void gk_species_source_calc( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_source *src, + struct gkyl_array *f_buffer, double tm +); /** * Adapt source to maintain input power and/or particle content constant. @@ -2847,10 +3257,10 @@ void gk_species_source_calc(gkyl_gyrokinetic_app *app, struct gk_species *specie * @param bflux_moms Moments of boundary fluxes passed in through the gyrokinetic rhs routine. * @param tm Time for use in source. */ -void -gk_species_source_adapt(gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_source *src, struct gkyl_array *f_buffer, - struct gkyl_array **bflux_moms[], double tm); +void gk_species_source_adapt( + gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_source *src, + struct gkyl_array *f_buffer, struct gkyl_array **bflux_moms[], double tm +); /** * Compute RHS contribution from source. @@ -2861,8 +3271,10 @@ gk_species_source_adapt(gkyl_gyrokinetic_app *app, struct gk_species *s, * @param fin Input distribution function. * @param rhs Source contribution to df/dt. */ -void gk_species_source_rhs(gkyl_gyrokinetic_app *app, const struct gk_species *species, - struct gk_source *src, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_species_source_rhs( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gk_source *src, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Write source diagnostics. @@ -2872,7 +3284,9 @@ void gk_species_source_rhs(gkyl_gyrokinetic_app *app, const struct gk_species *s * @param tm Time for source diagnostic. * @param frame Output frame. */ -void gk_species_source_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); +void gk_species_source_write( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +); /** * Write source moment diagnostics. @@ -2882,7 +3296,9 @@ void gk_species_source_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, * @param tm Time for source diagnostic. * @param frame Output frame. */ -void gk_species_source_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); +void gk_species_source_write_mom( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +); /** * Calc source integrated moment diagnostics. @@ -2891,7 +3307,9 @@ void gk_species_source_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *g * @param gks Pointer to species. * @param tm Time for source diagnostic. */ -void gk_species_source_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm); +void gk_species_source_calc_integrated_mom( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm +); /** * Write source integrated moment diagnostics. @@ -2899,7 +3317,7 @@ void gk_species_source_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_ * @param app Gyrokinetic app object. * @param gks Pointer to species. */ -void gk_species_source_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks); +void gk_species_source_write_integrated_mom(gkyl_gyrokinetic_app *app, struct gk_species *gks); /** * Release species source object. @@ -2918,7 +3336,9 @@ void gk_species_source_release(const struct gkyl_gyrokinetic_app *app, const str * @param s Species object. * @param damp Species damping object. */ -void gk_species_damping_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_damping *damp); +void gk_species_damping_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_damping *damp +); /** * Compute species applied source term. @@ -2932,9 +3352,11 @@ void gk_species_damping_init(struct gkyl_gyrokinetic_app *app, struct gk_species * @param rhs df/dt damping term gets added to. * @param cflrate CFL frequency in phase space. */ -void gk_species_damping_advance(gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_damping *damp, +void gk_species_damping_advance( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_damping *damp, const struct gkyl_array *phi, const struct gkyl_array *fin, struct gkyl_array *f_buffer, - struct gkyl_array *rhs, struct gkyl_array *cflrate); + struct gkyl_array *rhs, struct gkyl_array *cflrate +); /** * Write damping diagnostics. @@ -2944,7 +3366,9 @@ void gk_species_damping_advance(gkyl_gyrokinetic_app *app, const struct gk_speci * @param tm Time for damping diagnostic. * @param frame Output frame. */ -void gk_species_damping_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); +void gk_species_damping_write( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame +); /** * Release species damping object. @@ -2952,7 +3376,9 @@ void gk_species_damping_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, * @param app gyrokinetic app object. * @param damp Species damping object to release. */ -void gk_species_damping_release(const struct gkyl_gyrokinetic_app *app, const struct gk_damping *damp); +void gk_species_damping_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_damping *damp +); /** gk_species_fdot_multiplier API */ @@ -2963,8 +3389,9 @@ void gk_species_damping_release(const struct gkyl_gyrokinetic_app *app, const st * @param s Species object. * @param fdmul Species df/dt multiplier object. */ -void gk_species_fdot_multiplier_init(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult); +void gk_species_fdot_multiplier_init( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult +); /** * Multiply the CFL rate. @@ -2976,9 +3403,10 @@ void gk_species_fdot_multiplier_init(gkyl_gyrokinetic_app *app, struct gk_specie * @param f Current distribution function. * @param out CFL rate to multiply. */ -void gk_species_fdot_multiplier_advance_times_cfl(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult, const struct gkyl_array *phi, - const struct gkyl_array *f, struct gkyl_array *out); +void gk_species_fdot_multiplier_advance_times_cfl( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *out +); /** * Multiply df/dt. @@ -2990,9 +3418,10 @@ void gk_species_fdot_multiplier_advance_times_cfl(gkyl_gyrokinetic_app *app, str * @param f Current distribution function. * @param out df/dt to multiply. */ -void gk_species_fdot_multiplier_advance_times_rate(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult, const struct gkyl_array *phi, - const struct gkyl_array *f, struct gkyl_array *out); +void gk_species_fdot_multiplier_advance_times_rate( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + const struct gkyl_array *phi, const struct gkyl_array *f, struct gkyl_array *out +); /** * Get the constant time dilation scale factor, if applicable. @@ -3001,8 +3430,9 @@ void gk_species_fdot_multiplier_advance_times_rate(gkyl_gyrokinetic_app *app, st * @param fdot_mult Species df/dt multiplier object. * @return The constant time dilation scale factor, or 1.0 if not applicable. */ -double gk_fdot_multiplier_get_time_dilation_scale_const(gkyl_gyrokinetic_app *app, - const struct gk_fdot_multiplier *fdot_mult); +double gk_fdot_multiplier_get_time_dilation_scale_const( + gkyl_gyrokinetic_app *app, const struct gk_fdot_multiplier *fdot_mult +); /** * Write damping diagnostics. @@ -3012,8 +3442,10 @@ double gk_fdot_multiplier_get_time_dilation_scale_const(gkyl_gyrokinetic_app *ap * @param tm Time for damping diagnostic. * @param frame Output frame. */ -void gk_species_fdot_multiplier_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult, double tm, int frame); +void gk_species_fdot_multiplier_write( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_fdot_multiplier *fdot_mult, + double tm, int frame +); /** * Release species damping object. @@ -3021,8 +3453,9 @@ void gk_species_fdot_multiplier_write(gkyl_gyrokinetic_app* app, struct gk_speci * @param app gyrokinetic app object. * @param fdmul Species df/dt multiplier object. */ -void gk_species_fdot_multiplier_release(const struct gkyl_gyrokinetic_app *app, - const struct gk_fdot_multiplier *fdot_mult); +void gk_species_fdot_multiplier_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_fdot_multiplier *fdot_mult +); /** * Reset the df/dt multiplier operator. @@ -3033,9 +3466,10 @@ void gk_species_fdot_multiplier_release(const struct gkyl_gyrokinetic_app *app, * @param fdmul Species df/dt multiplier object. * @param fdot_mult_inp New input struct for the fdot_multiplier. */ -void gk_species_fdot_multiplier_reset(gkyl_gyrokinetic_app* app, double tm, struct gk_species *gks, - struct gk_fdot_multiplier *fdot_mult, - struct gkyl_gyrokinetic_fdot_multiplier fdot_mult_inp); +void gk_species_fdot_multiplier_reset( + gkyl_gyrokinetic_app *app, double tm, struct gk_species *gks, + struct gk_fdot_multiplier *fdot_mult, struct gkyl_gyrokinetic_fdot_multiplier fdot_mult_inp +); /** gk_anomalous_diff API */ @@ -3046,8 +3480,9 @@ void gk_species_fdot_multiplier_reset(gkyl_gyrokinetic_app* app, double tm, stru * @param s Species object. * @param gkad Species anomalous diffusion object. */ -void gk_species_anomalous_diff_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_anomalous_diff *gkad); +void gk_species_anomalous_diff_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_anomalous_diff *gkad +); /** * Compute RHS contribution from anomalous diffusion. @@ -3058,8 +3493,10 @@ void gk_species_anomalous_diff_init(struct gkyl_gyrokinetic_app *app, struct gk_ * @param fin Input distribution function. * @param rhs Anomalous diffusion contribution to df/dt. */ -void gk_species_anomalous_diff_rhs(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_anomalous_diff *gkad, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_species_anomalous_diff_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_anomalous_diff *gkad, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Write out diagnostics from the anomalous diffusion term. @@ -3070,8 +3507,10 @@ void gk_species_anomalous_diff_rhs(gkyl_gyrokinetic_app *app, struct gk_species * @param tm Current simulation time. * @param frame Current I/O frame. */ -void gk_species_anomalous_diff_write_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_anomalous_diff *gkad, double tm, int frame); +void gk_species_anomalous_diff_write_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_anomalous_diff *gkad, double tm, + int frame +); /** * Release species anomalous diffusion object. @@ -3079,7 +3518,9 @@ void gk_species_anomalous_diff_write_diags(gkyl_gyrokinetic_app* app, struct gk_ * @param app Gyrokinetic app object. * @param gkad Species anomalous diffusion object. */ -void gk_species_anomalous_diff_release(const struct gkyl_gyrokinetic_app *app, const struct gk_anomalous_diff *gkad); +void gk_species_anomalous_diff_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_anomalous_diff *gkad +); /** gk_source_bgk API */ @@ -3090,8 +3531,9 @@ void gk_species_anomalous_diff_release(const struct gkyl_gyrokinetic_app *app, c * @param s Species object. * @param src Species source_bgk object. */ -void gk_species_source_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_species *s, - struct gk_source_bgk *src); +void gk_species_source_bgk_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *s, struct gk_source_bgk *src +); /** * Compute RHS contribution from source_bgk source. @@ -3102,8 +3544,10 @@ void gk_species_source_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_spec * @param fin Input distribution function. * @param rhs source_bgk contribution to df/dt. */ -void gk_species_source_bgk_rhs(gkyl_gyrokinetic_app *app, struct gk_species *species, - struct gk_source_bgk *src, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_species_source_bgk_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *species, struct gk_source_bgk *src, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Write out diagnostics from the source_bgk source. @@ -3114,8 +3558,9 @@ void gk_species_source_bgk_rhs(gkyl_gyrokinetic_app *app, struct gk_species *spe * @param tm Current simulation time. * @param frame Current I/O frame. */ -void gk_species_source_bgk_write_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, double tm, int frame); +void gk_species_source_bgk_write_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm, int frame +); /** * Calculate integrated diagnostics of the BGK source operator. @@ -3125,8 +3570,9 @@ void gk_species_source_bgk_write_diags(gkyl_gyrokinetic_app* app, struct gk_spec * @param src BGK source object. * @param tm Current simulation time. */ -void gk_species_source_bgk_calc_integrated_diags(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_source_bgk *src, double tm); +void gk_species_source_bgk_calc_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src, double tm +); /** * Write integrated diagnostics of the BGK source operator. @@ -3135,8 +3581,9 @@ void gk_species_source_bgk_calc_integrated_diags(gkyl_gyrokinetic_app* app, stru * @param gks Species object. * @param src BGK source object. */ -void gk_species_source_bgk_write_integrated_diags(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_source_bgk *src); +void gk_species_source_bgk_write_integrated_diags( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_source_bgk *src +); /** * Release species source_bgk object. @@ -3144,7 +3591,9 @@ void gk_species_source_bgk_write_integrated_diags(gkyl_gyrokinetic_app *app, str * @param app Gyrokinetic app object. * @param src Species source_bgk object to release. */ -void gk_species_source_bgk_release(const struct gkyl_gyrokinetic_app *app, const struct gk_source_bgk *src); +void gk_species_source_bgk_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_source_bgk *src +); /** gk_species API */ @@ -3186,8 +3635,10 @@ void gk_species_apply_ic_cross(gkyl_gyrokinetic_app *app, struct gk_species *spe * @param bflux_moms Output boundary flux moments. * @return Maximum stable time-step. */ -double gk_species_rhs(gkyl_gyrokinetic_app *app, struct gk_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms); +double gk_species_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms +); /** * Compute the *implicit* RHS from species distribution function @@ -3200,8 +3651,10 @@ double gk_species_rhs(gkyl_gyrokinetic_app *app, struct gk_species *species, * @param dt timestep size (used in the implcit coef.). * @return Maximum stable time-step. */ -double gk_species_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt); +double gk_species_rhs_implicit( + gkyl_gyrokinetic_app *app, struct gk_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt +); /** * Scale and accumulate for forward euler method. out = dt*out + inp @@ -3211,8 +3664,9 @@ double gk_species_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_species *spe * @param dt Timestep. * @param inp Input array. */ -void gk_species_step_f(struct gk_species *species, struct gkyl_array* out, double dt, - const struct gkyl_array* inp); +void gk_species_step_f( + struct gk_species *species, struct gkyl_array *out, double dt, const struct gkyl_array *inp +); /** * Combine for rk3 method. @@ -3225,9 +3679,10 @@ void gk_species_step_f(struct gk_species *species, struct gkyl_array* out, doubl * @param arr2 Input array. * @param rng Range. */ -void gk_species_combine(struct gk_species *species, struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng); +void gk_species_combine( + struct gk_species *species, struct gkyl_array *out, double c1, const struct gkyl_array *arr1, + double c2, const struct gkyl_array *arr2, const struct gkyl_range *rng +); /** * Copy for rk3 method. @@ -3237,8 +3692,10 @@ void gk_species_combine(struct gk_species *species, struct gkyl_array *out, doub * @param inp Input array. * @param range Range. */ -void gk_species_copy_range(struct gk_species *species, struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range); +void gk_species_copy_range( + struct gk_species *species, struct gkyl_array *out, const struct gkyl_array *inp, + const struct gkyl_range *range +); /** * Apply the positivity shift (to enforce f>=0) to a charged species. @@ -3246,7 +3703,7 @@ void gk_species_copy_range(struct gk_species *species, struct gkyl_array *out, * @param app Gyrokinetic app object. * @param gks Gyrokinetic species object. */ -void gk_species_apply_pos_shift(gkyl_gyrokinetic_app* app, struct gk_species *gks); +void gk_species_apply_pos_shift(gkyl_gyrokinetic_app *app, struct gk_species *gks); /** * Apply BCs to dynamic species distribution function. @@ -3255,7 +3712,9 @@ void gk_species_apply_pos_shift(gkyl_gyrokinetic_app* app, struct gk_species *gk * @param species Pointer to species. * @param f Field to apply BCs. */ -void gk_species_apply_bc(gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f); +void gk_species_apply_bc( + gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f +); /** * Fill stat object in app with collision timers. @@ -3283,7 +3742,7 @@ void gk_species_n_iter_corr(gkyl_gyrokinetic_app *app, const struct gk_species * * @param tm simulation time. * @param frame simulation frame. */ -void gk_species_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); +void gk_species_write(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame); /** * Species moment write function. @@ -3293,7 +3752,7 @@ void gk_species_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, double * @param tm simulation time. * @param frame simulation frame. */ -void gk_species_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame); +void gk_species_write_mom(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm, int frame); /** * Species calc integrated moment function. @@ -3302,7 +3761,7 @@ void gk_species_write_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, dou * @param gks Species object. * @param tm simulation time. */ -void gk_species_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm); +void gk_species_calc_integrated_mom(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm); /** * Species write integrated moment function. @@ -3310,7 +3769,7 @@ void gk_species_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species * @param app gyrokinetic app object. * @param gks Species object. */ -void gk_species_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_species *gks); +void gk_species_write_integrated_mom(gkyl_gyrokinetic_app *app, struct gk_species *gks); /** * Species calc L2norm function. @@ -3319,7 +3778,7 @@ void gk_species_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_specie * @param gks Species object. * @param tm simulation time. */ -void gk_species_calc_L2norm(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm); +void gk_species_calc_L2norm(gkyl_gyrokinetic_app *app, struct gk_species *gks, double tm); /** * Species write L2norm function. @@ -3327,7 +3786,7 @@ void gk_species_calc_L2norm(gkyl_gyrokinetic_app* app, struct gk_species *gks, d * @param app gyrokinetic app object. * @param gks Species object. */ -void gk_species_write_L2norm(gkyl_gyrokinetic_app* app, struct gk_species *gks); +void gk_species_write_L2norm(gkyl_gyrokinetic_app *app, struct gk_species *gks); /** * Calculate the integrated moments divided by dt, for particle/energy balance @@ -3338,8 +3797,9 @@ void gk_species_write_L2norm(gkyl_gyrokinetic_app* app, struct gk_species *gks); * @param dt Time step. * @param fdot_int_mom Integrated moment divided by dt (not yet reduced over comm). */ -void -gk_species_calc_int_mom_dt(gkyl_gyrokinetic_app* app, struct gk_species *gks, double dt, struct gkyl_array *fdot_int_mom); +void gk_species_calc_int_mom_dt( + gkyl_gyrokinetic_app *app, struct gk_species *gks, double dt, struct gkyl_array *fdot_int_mom +); /** * Delete resources used in species. @@ -3347,7 +3807,7 @@ gk_species_calc_int_mom_dt(gkyl_gyrokinetic_app* app, struct gk_species *gks, do * @param app gyrokinetic app object. * @param species Species object to delete. */ -void gk_species_release(const gkyl_gyrokinetic_app* app, const struct gk_species *s); +void gk_species_release(const gkyl_gyrokinetic_app *app, const struct gk_species *s); /** gk_neut_species_moment API */ @@ -3360,8 +3820,10 @@ void gk_species_release(const gkyl_gyrokinetic_app* app, const struct gk_species * @param nm Name string indicating moment type. * @param is_integrated Whether to compute the volume integrated moment. */ -void gk_neut_species_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_species_moment *sm, enum gkyl_distribution_moments mom_type, bool is_integrated); +void gk_neut_species_moment_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_species_moment *sm, + enum gkyl_distribution_moments mom_type, bool is_integrated +); /** * Calculate neutral species moment, given input neutral distribution function fin. @@ -3371,9 +3833,10 @@ void gk_neut_species_moment_init(struct gkyl_gyrokinetic_app *app, struct gk_neu * @param conf_rng Config-space range. * @param fin Input neutral distribution function array. */ -void gk_neut_species_moment_calc(const struct gk_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin); +void gk_neut_species_moment_calc( + const struct gk_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +); /** * Divide the moment by the configuration-space Jacobian for diagnostic @@ -3385,8 +3848,10 @@ void gk_neut_species_moment_calc(const struct gk_species_moment *sm, * @param Jmom_in Moment(s) to be divided by J. * @param mom_out Array in which to place the output. */ -void gk_neut_species_moment_diag_jacobgeo_div(const struct gkyl_gyrokinetic_app *app, - struct gk_species_moment *sm, struct gkyl_array *Jmom_in, struct gkyl_array *mom_out); +void gk_neut_species_moment_diag_jacobgeo_div( + const struct gkyl_gyrokinetic_app *app, struct gk_species_moment *sm, struct gkyl_array *Jmom_in, + struct gkyl_array *mom_out +); /** * Release neutral species moment object. @@ -3394,8 +3859,9 @@ void gk_neut_species_moment_diag_jacobgeo_div(const struct gkyl_gyrokinetic_app * @param app gyrokinetic app object. * @param sm Neutral species moment object to release. */ -void gk_neut_species_moment_release(const struct gkyl_gyrokinetic_app *app, - const struct gk_species_moment *sm); +void gk_neut_species_moment_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_species_moment *sm +); /** gk_neut_species_lte API */ @@ -3407,8 +3873,10 @@ void gk_neut_species_moment_release(const struct gkyl_gyrokinetic_app *app, * @param lte Neutral species lte object. * @param corr_inp Input struct with moment correction inputs. */ -void gk_neut_species_lte_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_lte *lte, struct correct_all_moms_inp corr_inp); +void gk_neut_species_lte_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_lte *lte, + struct correct_all_moms_inp corr_inp +); /** * Compute LTE distribution from input moments. @@ -3418,8 +3886,10 @@ void gk_neut_species_lte_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_s * @param lte Pointer to lte object. * @param moms_lte Input LTE moments. */ -void gk_neut_species_lte_from_moms(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_lte *lte, const struct gkyl_array *moms_lte); +void gk_neut_species_lte_from_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_lte *lte, + const struct gkyl_array *moms_lte +); /** * Compute equivalent LTE distribution from input distribution function. @@ -3429,8 +3899,10 @@ void gk_neut_species_lte_from_moms(gkyl_gyrokinetic_app *app, const struct gk_ne * @param lte Pointer to lte. * @param fin Input distribution function. */ -void gk_neut_species_lte(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_lte *lte, const struct gkyl_array *fin); +void gk_neut_species_lte( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_lte *lte, + const struct gkyl_array *fin +); /** * Write the LTE correction status for the neutral species. @@ -3438,7 +3910,9 @@ void gk_neut_species_lte(gkyl_gyrokinetic_app *app, const struct gk_neut_species * @param app Gyrokinetic app object. * @param gk_ns Pointer to neutral species. */ -void gk_neut_species_lte_write_max_corr_status(gkyl_gyrokinetic_app* app, struct gk_neut_species *gk_ns); +void gk_neut_species_lte_write_max_corr_status( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gk_ns +); /** * Release species lte object. @@ -3457,8 +3931,9 @@ void gk_neut_species_lte_release(const struct gkyl_gyrokinetic_app *app, const s * @param gkns Neutral species object. * @param bgk Species BGK object. */ -void gk_neut_species_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk); +void gk_neut_species_bgk_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk +); /** * Initialize species BGK cross-collisions object. @@ -3467,8 +3942,9 @@ void gk_neut_species_bgk_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_s * @param gkns Neutral species object. * @param bgk Species BGK object. */ -void gk_neut_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk); +void gk_neut_species_bgk_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk +); /** * Compute necessary moments and boundary @@ -3479,11 +3955,15 @@ void gk_neut_species_bgk_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_ * @param bgk Pointer to BGK. * @param fin Input distribution function. */ -void gk_neut_species_bgk_moms(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); +void gk_neut_species_bgk_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +); -void gk_neut_species_bgk_moms_implicit(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); +void gk_neut_species_bgk_moms_implicit( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +); /** * Compute necessary moments for cross-species BGK collisions. @@ -3493,11 +3973,15 @@ void gk_neut_species_bgk_moms_implicit(gkyl_gyrokinetic_app *app, const struct g * @param bgk Pointer to BGK. * @param fin Input distribution function. */ -void gk_neut_species_bgk_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); +void gk_neut_species_bgk_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +); -void gk_neut_species_bgk_cross_moms_implicit(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin); +void gk_neut_species_bgk_cross_moms_implicit( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin +); /** * Compute RHS from BGK collisions (explicit integrator). @@ -3508,8 +3992,10 @@ void gk_neut_species_bgk_cross_moms_implicit(gkyl_gyrokinetic_app *app, const st * @param fin Input distribution function. * @param rhs On output, the RHS from BGK. */ -void gk_neut_species_bgk_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_neut_species_bgk_rhs( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Compute RHS from BGK collisions (implicit integrator). @@ -3521,8 +4007,10 @@ void gk_neut_species_bgk_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_species * * @param dt Time step. * @param rhs On output, the RHS from BGK. */ -void gk_neut_species_bgk_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, - struct gk_bgk_collisions *bgk, const struct gkyl_array *fin, double dt, struct gkyl_array *rhs); +void gk_neut_species_bgk_rhs_implicit( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_bgk_collisions *bgk, + const struct gkyl_array *fin, double dt, struct gkyl_array *rhs +); /** * Write moments from BGK object. @@ -3532,7 +4020,9 @@ void gk_neut_species_bgk_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_neut_ * @param tm Simulation time. * @param frame Simulation output frame. */ -void gk_neut_species_bgk_write_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); +void gk_neut_species_bgk_write_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +); /** * Release species BGK object. @@ -3540,7 +4030,9 @@ void gk_neut_species_bgk_write_mom(gkyl_gyrokinetic_app* app, struct gk_neut_spe * @param app gyrokinetic app object. * @param bgk Species BGK object to release. */ -void gk_neut_species_bgk_release(const struct gkyl_gyrokinetic_app *app, const struct gk_bgk_collisions *bgk); +void gk_neut_species_bgk_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_bgk_collisions *bgk +); /** gk_neut_species_recycle API **/ @@ -3555,9 +4047,10 @@ void gk_neut_species_bgk_release(const struct gkyl_gyrokinetic_app *app, const s * @param s Gk_neut_species to apply BCs for. * @param use_gpu Boolean for using GPUs. */ -void gk_neut_species_recycle_init(struct gkyl_gyrokinetic_app *app, struct gk_recycle_wall *recyc, - int dir, enum gkyl_edge_loc edge, struct gkyl_gyrokinetic_emission_inp *params, - struct gk_neut_species *s, bool use_gpu); +void gk_neut_species_recycle_init( + struct gkyl_gyrokinetic_app *app, struct gk_recycle_wall *recyc, int dir, enum gkyl_edge_loc edge, + struct gkyl_gyrokinetic_emission_inp *params, struct gk_neut_species *s, bool use_gpu +); /** * Initialize recycling cross moments. @@ -3566,8 +4059,9 @@ void gk_neut_species_recycle_init(struct gkyl_gyrokinetic_app *app, struct gk_re * @param s Gk_neut_species to apply BCs for. * @param recyc Recycling bc object. */ -void gk_neut_species_recycle_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_recycle_wall *recyc); +void gk_neut_species_recycle_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_recycle_wall *recyc +); /** * Apply recycling BCs. @@ -3577,8 +4071,10 @@ void gk_neut_species_recycle_cross_init(struct gkyl_gyrokinetic_app *app, struct * @param s Gk_neut_species to apply BCs for. * @param fout Gk_neut_species distf. */ -void gk_neut_species_recycle_apply_bc(struct gkyl_gyrokinetic_app *app, const struct gk_recycle_wall *recyc, - const struct gk_neut_species *s, struct gkyl_array *fout); +void gk_neut_species_recycle_apply_bc( + struct gkyl_gyrokinetic_app *app, const struct gk_recycle_wall *recyc, + const struct gk_neut_species *s, struct gkyl_array *fout +); /** * Write recycle flux diagnostics. @@ -3589,9 +4085,10 @@ void gk_neut_species_recycle_apply_bc(struct gkyl_gyrokinetic_app *app, const st * @param tm Simulation time. * @param frame Simulation frame. */ -void -gk_neut_species_recycle_write_flux(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_recycle_wall *recyc, double tm, int frame); +void gk_neut_species_recycle_write_flux( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_recycle_wall *recyc, + double tm, int frame +); /** * Release recycle BC object. @@ -3599,7 +4096,9 @@ gk_neut_species_recycle_write_flux(struct gkyl_gyrokinetic_app *app, struct gk_n * @param app Gyrokinetic app object * @param recyc Recycling bc object */ -void gk_neut_species_recycle_release(const struct gkyl_gyrokinetic_app *app, const struct gk_recycle_wall *recyc); +void gk_neut_species_recycle_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_recycle_wall *recyc +); /** gk_neut_species_react API */ @@ -3611,8 +4110,10 @@ void gk_neut_species_recycle_release(const struct gkyl_gyrokinetic_app *app, con * @param inp Input reaction struct for determining types of reactions. * @param react Neutral species reaction object. */ -void gk_neut_species_react_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gkyl_gyrokinetic_react inp, struct gk_react *react); +void gk_neut_species_react_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gkyl_gyrokinetic_react inp, + struct gk_react *react +); /** * Initialize neutral species reactions "cross-collisions" object @@ -3622,8 +4123,9 @@ void gk_neut_species_react_init(struct gkyl_gyrokinetic_app *app, struct gk_neut * @param s Neutral species object. * @param react Neutral species react object. */ -void gk_neut_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gk_react *react); +void gk_neut_species_react_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_react *react +); /** * Compute necessary rates and moments for reactions. @@ -3634,10 +4136,10 @@ void gk_neut_species_react_cross_init(struct gkyl_gyrokinetic_app *app, struct g * @param fin Input distribution functions (size: num_species). * @param fin_neut Input neutral distribution functions (size: num_neut_species). */ -void gk_neut_species_react_cross_moms(gkyl_gyrokinetic_app *app, - const struct gk_neut_species *species, - struct gk_react *react, - const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]); +void gk_neut_species_react_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_react *react, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +); /** * Compute RHS from reactions for neutrals @@ -3649,9 +4151,10 @@ void gk_neut_species_react_cross_moms(gkyl_gyrokinetic_app *app, * @param fin Input neutral distribution function. * @param rhs On output, the neutral RHS from react (df/dt). */ -void gk_neut_species_react_rhs(gkyl_gyrokinetic_app *app, - struct gk_neut_species *s, struct gk_react *react, - const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_neut_species_react_rhs( + gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_react *react, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Write neutral reaction rate. @@ -3663,8 +4166,10 @@ void gk_neut_species_react_rhs(gkyl_gyrokinetic_app *app, * @param tm Simulation time. * @param frame Simulation output frame. */ -void gk_neut_species_react_write(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, struct gk_react *gkr, - int ridx, double tm, int frame); +void gk_neut_species_react_write( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, struct gk_react *gkr, int ridx, + double tm, int frame +); /** * Release neutral species react object. @@ -3672,7 +4177,9 @@ void gk_neut_species_react_write(gkyl_gyrokinetic_app* app, struct gk_neut_speci * @param app gyrokinetic app object. * @param react Neutral species react object to release. */ -void gk_neut_species_react_release(const struct gkyl_gyrokinetic_app *app, const struct gk_react *react); +void gk_neut_species_react_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_react *react +); /** gk_species_scaling API */ @@ -3683,8 +4190,9 @@ void gk_neut_species_react_release(const struct gkyl_gyrokinetic_app *app, const * @param gks Species object. * @param sca Recycle react scale object. */ -void gk_species_scaling_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca); +void gk_species_scaling_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca +); /** * Initialize the part of scaling that depends on other species. @@ -3693,8 +4201,9 @@ void gk_species_scaling_init(struct gkyl_gyrokinetic_app *app, struct gk_species * @param gks Species object. * @param sca Recycle react scale object. */ -void gk_species_scaling_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca); +void gk_species_scaling_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca +); /** * Store initial condition of the species. @@ -3703,8 +4212,9 @@ void gk_species_scaling_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_ * @param gks Species object. * @param sca Recycle react scale object. */ -void gk_species_scaling_apply_ic_cross(struct gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca); +void gk_species_scaling_apply_ic_cross( + struct gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca +); /** * Compute the cross-species moments needed. @@ -3715,8 +4225,10 @@ void gk_species_scaling_apply_ic_cross(struct gkyl_gyrokinetic_app *app, struct * @param fin Input distribution for charged species. * @param fin_neut Input distribution/moments for neutral species. */ -void gk_species_scaling_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_species *gks, - struct gk_scaling *sca, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]); +void gk_species_scaling_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_species *gks, struct gk_scaling *sca, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +); /** * Compute factor to scale species by. @@ -3727,8 +4239,10 @@ void gk_species_scaling_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_sp * @param fin Input distribution/moments for species. * @param rhs df/dt to add to. */ -void gk_species_scaling_rhs(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_species_scaling_rhs( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Add up the integrated boundary fluxes and scale the species. @@ -3739,8 +4253,10 @@ void gk_species_scaling_rhs(gkyl_gyrokinetic_app *app, struct gk_species *gks, * @param fin Distribution/moments to scale. * @param bflux Boundary fluxes of charged species. */ -void gk_species_scaling_apply(gkyl_gyrokinetic_app *app, struct gk_species *gks, - struct gk_scaling *sca, struct gkyl_array *fin, struct gkyl_array **bflux[]); +void gk_species_scaling_apply( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, struct gkyl_array *fin, + struct gkyl_array **bflux[] +); /** * Write scaling diagnostics. @@ -3751,8 +4267,10 @@ void gk_species_scaling_apply(gkyl_gyrokinetic_app *app, struct gk_species *gks, * @param fin Input distribution/moments for species. * @param rhs df/dt to add to. */ -void gk_species_scaling_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, - struct gk_scaling *sca, int ridx, double tm, int frame); +void gk_species_scaling_write( + gkyl_gyrokinetic_app *app, struct gk_species *gks, struct gk_scaling *sca, int ridx, double tm, + int frame +); /** * Free memory associated with the scaling operator. @@ -3760,8 +4278,9 @@ void gk_species_scaling_write(gkyl_gyrokinetic_app* app, struct gk_species *gks, * @param app gyrokinetic app object. * @param sca Recycle react scale object. */ -void gk_species_scaling_release(const struct gkyl_gyrokinetic_app *app, - const struct gk_scaling *sca); +void gk_species_scaling_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_scaling *sca +); /** gk_neut_species_scaling API */ @@ -3772,8 +4291,9 @@ void gk_species_scaling_release(const struct gkyl_gyrokinetic_app *app, * @param ns Neutral species object. * @param sca Recycle react scale object. */ -void gk_neut_species_scaling_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca); +void gk_neut_species_scaling_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca +); /** * Initialize the part of scaling that depends on other species. @@ -3782,8 +4302,9 @@ void gk_neut_species_scaling_init(struct gkyl_gyrokinetic_app *app, struct gk_ne * @param ns Neutral species object. * @param sca Recycle react scale object. */ -void gk_neut_species_scaling_cross_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca); +void gk_neut_species_scaling_cross_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca +); /** * Store initial condition of the neutral species. @@ -3792,8 +4313,9 @@ void gk_neut_species_scaling_cross_init(struct gkyl_gyrokinetic_app *app, struc * @param ns Neutral species object. * @param sca Recycle react scale object. */ -void gk_neut_species_scaling_apply_ic_cross(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca); +void gk_neut_species_scaling_apply_ic_cross( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca +); /** * Compute the cross-species moments needed. @@ -3804,8 +4326,10 @@ void gk_neut_species_scaling_apply_ic_cross(struct gkyl_gyrokinetic_app *app, st * @param fin Input distribution for charged species. * @param fin_neut Input distribution/moments for neutral species. */ -void gk_neut_species_scaling_cross_moms(gkyl_gyrokinetic_app *app, const struct gk_neut_species *ns, - struct gk_scaling *sca, const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[]); +void gk_neut_species_scaling_cross_moms( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *ns, struct gk_scaling *sca, + const struct gkyl_array *fin[], const struct gkyl_array *fin_neut[] +); /** * Compute factor to scale neutrals by. @@ -3816,8 +4340,10 @@ void gk_neut_species_scaling_cross_moms(gkyl_gyrokinetic_app *app, const struct * @param fin Input distribution/moments for neutral species. * @param rhs df/dt to add to. */ -void gk_neut_species_scaling_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_neut_species_scaling_rhs( + gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Add up the integrated boundary fluxes and scale the neutral species. @@ -3828,8 +4354,10 @@ void gk_neut_species_scaling_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_speci * @param fin Distribution/moments to scale. * @param bflux Boundary fluxes of charged species. */ -void gk_neut_species_scaling_apply(gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, - struct gk_scaling *sca, struct gkyl_array *fin, struct gkyl_array **bflux[]); +void gk_neut_species_scaling_apply( + gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca, + struct gkyl_array *fin, struct gkyl_array **bflux[] +); /** * Write scaling diagnostics. @@ -3840,8 +4368,10 @@ void gk_neut_species_scaling_apply(gkyl_gyrokinetic_app *app, struct gk_neut_spe * @param fin Input distribution/moments for neutral species. * @param rhs df/dt to add to. */ -void gk_neut_species_scaling_write(gkyl_gyrokinetic_app* app, struct gk_neut_species *ns, - struct gk_scaling *sca, int ridx, double tm, int frame); +void gk_neut_species_scaling_write( + gkyl_gyrokinetic_app *app, struct gk_neut_species *ns, struct gk_scaling *sca, int ridx, + double tm, int frame +); /** * Free memory associated with the scaling operator. @@ -3849,8 +4379,9 @@ void gk_neut_species_scaling_write(gkyl_gyrokinetic_app* app, struct gk_neut_spe * @param app gyrokinetic app object. * @param sca Recycle react scale object. */ -void gk_neut_species_scaling_release(const struct gkyl_gyrokinetic_app *app, - const struct gk_scaling *sca); +void gk_neut_species_scaling_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_scaling *sca +); /** gk_neut_species_projection API */ @@ -3862,8 +4393,10 @@ void gk_neut_species_scaling_release(const struct gkyl_gyrokinetic_app *app, * @param inp Input struct for projection (contains functions pointers for type of projection). * @param proj Neutral species projection object. */ -void gk_neut_species_projection_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, - struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj); +void gk_neut_species_projection_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, + struct gkyl_gyrokinetic_projection inp, struct gk_proj *proj +); /** * Compute neutral species projection @@ -3874,8 +4407,10 @@ void gk_neut_species_projection_init(struct gkyl_gyrokinetic_app *app, struct gk * @param f Output Neutral distribution function from projection. * @param tm Time for use in projection. */ -void gk_neut_species_projection_calc(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - struct gk_proj *proj, struct gkyl_array *f, double tm); +void gk_neut_species_projection_calc( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, struct gk_proj *proj, + struct gkyl_array *f, double tm +); /** * Release neutral species projection object. @@ -3883,7 +4418,9 @@ void gk_neut_species_projection_calc(gkyl_gyrokinetic_app *app, struct gk_neut_s * @param app gyrokinetic app object. * @param proj Neutral species projection object to release. */ -void gk_neut_species_projection_release(const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj); +void gk_neut_species_projection_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_proj *proj +); /** gk_neut_species_source API */ @@ -3894,7 +4431,9 @@ void gk_neut_species_projection_release(const struct gkyl_gyrokinetic_app *app, * @param s Neutral species object. * @param src Neutral species source object. */ -void gk_neut_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_source *src); +void gk_neut_species_source_init( + struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s, struct gk_source *src +); /** * Compute Neutral species applied source term @@ -3905,8 +4444,10 @@ void gk_neut_species_source_init(struct gkyl_gyrokinetic_app *app, struct gk_neu * @param f_buffer Phase-space buffer used to project the source. * @param tm Time for use in source. */ -void gk_neut_species_source_calc(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - struct gk_source *src, struct gkyl_array *f_buffer, double tm); +void gk_neut_species_source_calc( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, struct gk_source *src, + struct gkyl_array *f_buffer, double tm +); /** * Compute RHS contribution from source @@ -3917,8 +4458,10 @@ void gk_neut_species_source_calc(gkyl_gyrokinetic_app *app, struct gk_neut_speci * @param fin Input neutral distribution function. * @param rhs On output, the incremented rhs (df/dt). */ -void gk_neut_species_source_rhs(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, - struct gk_source *src, const struct gkyl_array *fin, struct gkyl_array *rhs); +void gk_neut_species_source_rhs( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gk_source *src, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Write neutral source diagnostics. @@ -3928,7 +4471,9 @@ void gk_neut_species_source_rhs(gkyl_gyrokinetic_app *app, const struct gk_neut_ * @param tm Time for source diagnostic. * @param frame Output frame. */ -void gk_neut_species_source_write(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); +void gk_neut_species_source_write( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +); /** * Write neutral source moment diagnostics. @@ -3938,7 +4483,9 @@ void gk_neut_species_source_write(gkyl_gyrokinetic_app* app, struct gk_neut_spec * @param tm Time for source diagnostic. * @param frame Output frame. */ -void gk_neut_species_source_write_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); +void gk_neut_species_source_write_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +); /** * Calc neutral source integrated moment diagnostics. @@ -3947,7 +4494,9 @@ void gk_neut_species_source_write_mom(gkyl_gyrokinetic_app* app, struct gk_neut_ * @param gkns Pointer to species. * @param tm Time for source diagnostic. */ -void gk_neut_species_source_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm); +void gk_neut_species_source_calc_integrated_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm +); /** * Write neutral source integrated moment diagnostics. @@ -3956,7 +4505,9 @@ void gk_neut_species_source_calc_integrated_mom(gkyl_gyrokinetic_app* app, struc * @param gkns Pointer to species. * @param tm Time for source diagnostic. */ -void gk_neut_species_source_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns); +void gk_neut_species_source_write_integrated_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns +); /** * Release Neutral species source object. @@ -3964,7 +4515,9 @@ void gk_neut_species_source_write_integrated_mom(gkyl_gyrokinetic_app* app, stru * @param app gyrokinetic app object. * @param src Neutral species source object to release. */ -void gk_neut_species_source_release(const struct gkyl_gyrokinetic_app *app, const struct gk_source *src); +void gk_neut_species_source_release( + const struct gkyl_gyrokinetic_app *app, const struct gk_source *src +); /** gk_neut_species API */ @@ -3975,7 +4528,9 @@ void gk_neut_species_source_release(const struct gkyl_gyrokinetic_app *app, cons * @param app gyrokinetic app object. * @param s On output, initialized neutral species object. */ -void gk_neut_species_init(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s); +void gk_neut_species_init( + struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app, struct gk_neut_species *s +); /** * Compute neutral species initial conditions. @@ -3994,7 +4549,9 @@ void gk_neut_species_apply_ic(gkyl_gyrokinetic_app *app, struct gk_neut_species * @param species Neutral species object. * @param t0 Time for use in ICs. */ -void gk_neut_species_apply_ic_cross(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, double t0); +void gk_neut_species_apply_ic_cross( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, double t0 +); /** * Compute RHS from neutral species distribution function. @@ -4006,8 +4563,10 @@ void gk_neut_species_apply_ic_cross(gkyl_gyrokinetic_app *app, struct gk_neut_sp * @param bflux_moms Output boundary flux moments. * @return Maximum stable time-step. */ -double gk_neut_species_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms); +double gk_neut_species_rhs( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms +); /** * Compute the *implicit* RHS from neutral species distribution function. @@ -4020,8 +4579,10 @@ double gk_neut_species_rhs(gkyl_gyrokinetic_app *app, struct gk_neut_species *sp * @param dt timestep size (used in the implcit coef). * @return Maximum stable time-step. */ -double gk_neut_species_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_neut_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt); +double gk_neut_species_rhs_implicit( + gkyl_gyrokinetic_app *app, struct gk_neut_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt +); /** * Apply BCs to neutral species distribution function. @@ -4030,7 +4591,9 @@ double gk_neut_species_rhs_implicit(gkyl_gyrokinetic_app *app, struct gk_neut_sp * @param species Pointer to neutral species. * @param f Field to apply BCs. */ -void gk_neut_species_apply_bc(gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gkyl_array *f); +void gk_neut_species_apply_bc( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *species, struct gkyl_array *f +); /** * Fill stat object in app with total number of iterations @@ -4041,7 +4604,9 @@ void gk_neut_species_apply_bc(gkyl_gyrokinetic_app *app, const struct gk_neut_sp * @param s Species object. * @param sidx Index of current species. */ -void gk_neut_species_n_iter_corr(gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx); +void gk_neut_species_n_iter_corr( + gkyl_gyrokinetic_app *app, const struct gk_neut_species *gkns, int sidx +); /** * Scale and accumulate for forward euler method. @@ -4051,8 +4616,9 @@ void gk_neut_species_n_iter_corr(gkyl_gyrokinetic_app *app, const struct gk_neut * @param dt Timestep. * @param inp Input array. */ -void gk_neut_species_step_f(struct gk_neut_species *species, struct gkyl_array* out, double dt, - const struct gkyl_array* inp); +void gk_neut_species_step_f( + struct gk_neut_species *species, struct gkyl_array *out, double dt, const struct gkyl_array *inp +); /** * Combine for rk3 method. @@ -4065,9 +4631,10 @@ void gk_neut_species_step_f(struct gk_neut_species *species, struct gkyl_array* * @param arr2 Input array. * @param rng Range. */ -void gk_neut_species_combine(struct gk_neut_species *species, struct gkyl_array *out, double c1, - const struct gkyl_array *arr1, double c2, const struct gkyl_array *arr2, - const struct gkyl_range *rng); +void gk_neut_species_combine( + struct gk_neut_species *species, struct gkyl_array *out, double c1, const struct gkyl_array *arr1, + double c2, const struct gkyl_array *arr2, const struct gkyl_range *rng +); /** * Copy for rk3 method. @@ -4077,8 +4644,10 @@ void gk_neut_species_combine(struct gk_neut_species *species, struct gkyl_array * @param inp Input array. * @param range Range. */ -void gk_neut_species_copy_range(struct gk_neut_species *species, struct gkyl_array *out, - const struct gkyl_array *inp, const struct gkyl_range *range); +void gk_neut_species_copy_range( + struct gk_neut_species *species, struct gkyl_array *out, const struct gkyl_array *inp, + const struct gkyl_range *range +); /** * Apply the positivity shift (to enforce f>=0) to a neutral species. @@ -4086,7 +4655,7 @@ void gk_neut_species_copy_range(struct gk_neut_species *species, struct gkyl_arr * @param app Gyrokinetic app object. * @param gkns Neutral species object. */ -void gk_neut_species_apply_pos_shift(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns); +void gk_neut_species_apply_pos_shift(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns); /** * Species write function. @@ -4096,7 +4665,9 @@ void gk_neut_species_apply_pos_shift(gkyl_gyrokinetic_app* app, struct gk_neut_s * @param tm simulation time. * @param frame simulation frame. */ -void gk_neut_species_write(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); +void gk_neut_species_write( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +); /** * Species moment write function. @@ -4106,7 +4677,9 @@ void gk_neut_species_write(gkyl_gyrokinetic_app* app, struct gk_neut_species *gk * @param tm simulation time. * @param frame simulation frame. */ -void gk_neut_species_write_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm, int frame); +void gk_neut_species_write_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm, int frame +); /** * Species calc integrated moment function. @@ -4115,7 +4688,9 @@ void gk_neut_species_write_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species * @param gkns Neutral species object. * @param tm simulation time. */ -void gk_neut_species_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns, double tm); +void gk_neut_species_calc_integrated_mom( + gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns, double tm +); /** * Species write integrated moment function. @@ -4123,7 +4698,7 @@ void gk_neut_species_calc_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_ne * @param app gyrokinetic app object. * @param gkns Neutral species object. */ -void gk_neut_species_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_neut_species *gkns); +void gk_neut_species_write_integrated_mom(gkyl_gyrokinetic_app *app, struct gk_neut_species *gkns); /** * Delete resources used in neutral species. @@ -4131,7 +4706,7 @@ void gk_neut_species_write_integrated_mom(gkyl_gyrokinetic_app* app, struct gk_n * @param app gyrokinetic app object. * @param species Neutral species object to delete. */ -void gk_neut_species_release(const gkyl_gyrokinetic_app* app, const struct gk_neut_species *s); +void gk_neut_species_release(const gkyl_gyrokinetic_app *app, const struct gk_neut_species *s); /** gk_field API */ @@ -4142,7 +4717,7 @@ void gk_neut_species_release(const gkyl_gyrokinetic_app* app, const struct gk_ne * @param app gyrokinetic app object. * @return Newly created field. */ -struct gk_field* gk_field_new(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app); +struct gk_field *gk_field_new(struct gkyl_gk *gk, struct gkyl_gyrokinetic_app *app); /** * Compute biased wall potentials. @@ -4161,8 +4736,10 @@ void gk_field_calc_phi_wall(gkyl_gyrokinetic_app *app, struct gk_field *field, d * @param fin[] Input distribution function (num_species size). * @param bflux Boundary fluxes of charged species. */ -void gk_field_accumulate_rho_c(gkyl_gyrokinetic_app *app, struct gk_field *field, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]); +void gk_field_accumulate_rho_c( + gkyl_gyrokinetic_app *app, struct gk_field *field, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +); /** * Compute EM field. @@ -4179,7 +4756,9 @@ void gk_field_rhs(gkyl_gyrokinetic_app *app, struct gk_field *field); * @param app Gyrokinetic app. * @param inp Input struct with importing parameters (and file name). */ -void gk_field_file_import_init(struct gkyl_gyrokinetic_app *app, struct gkyl_gyrokinetic_ic_import inp); +void gk_field_file_import_init( + struct gkyl_gyrokinetic_app *app, struct gkyl_gyrokinetic_ic_import inp +); /** * Project the initial field using a user provided function. @@ -4205,7 +4784,9 @@ void gk_field_calc_energy(gkyl_gyrokinetic_app *app, double tm, const struct gk_ * @param dt Time step. * @param energy_reduced Integrated field energy (single element double array). */ -void gk_field_calc_energy_dt(gkyl_gyrokinetic_app *app, const struct gk_field *field, double dt, double *energy_reduced); +void gk_field_calc_energy_dt( + gkyl_gyrokinetic_app *app, const struct gk_field *field, double dt, double *energy_reduced +); /** * Release resources allocated by field. @@ -4213,7 +4794,7 @@ void gk_field_calc_energy_dt(gkyl_gyrokinetic_app *app, const struct gk_field *f * @param app gyrokinetic app object. * @param f Field object to release. */ -void gk_field_release(const gkyl_gyrokinetic_app* app, struct gk_field *f); +void gk_field_release(const gkyl_gyrokinetic_app *app, struct gk_field *f); /** gk_eirene API */ @@ -4224,7 +4805,7 @@ void gk_field_release(const gkyl_gyrokinetic_app* app, struct gk_field *f); * @param gk Input gk data. * @returns Eirene object */ -struct gk_eirene* gk_eirene_init(gkyl_gyrokinetic_app *app, struct gkyl_gk *gk); +struct gk_eirene *gk_eirene_init(gkyl_gyrokinetic_app *app, struct gkyl_gk *gk); /** * Compute RHS for sources from eirene @@ -4233,7 +4814,9 @@ struct gk_eirene* gk_eirene_init(gkyl_gyrokinetic_app *app, struct gkyl_gk *gk); * @param fin Array of distribution functions (one for each species) . * @param fout Output array of distribution functions (one for each species). */ -void gk_eirene_rhs(gkyl_gyrokinetic_app *app, const struct gkyl_array *fin[], struct gkyl_array *rhs[]); +void gk_eirene_rhs( + gkyl_gyrokinetic_app *app, const struct gkyl_array *fin[], struct gkyl_array *rhs[] +); /** * Write moments of eirene sources @@ -4277,8 +4860,10 @@ void gk_eirene_release(gkyl_gyrokinetic_app *app, struct gk_eirene *eirene); * @param fin Array of distribution functions (one for each species) . * @param bflux Boundary fluxes of charged species. */ -void gyrokinetic_calc_field(gkyl_gyrokinetic_app* app, double tcurr, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]); +void gyrokinetic_calc_field( + gkyl_gyrokinetic_app *app, double tcurr, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +); /** * Compute the gyrokinetic fields and apply boundary conditions. @@ -4289,8 +4874,10 @@ void gyrokinetic_calc_field(gkyl_gyrokinetic_app* app, double tcurr, * @param bflux Boundary fluxes of charged species. * @param distf_neut Array of distribution functions (for each neutral species). */ -void gyrokinetic_calc_field_and_apply_bc(gkyl_gyrokinetic_app* app, double tcurr, - struct gkyl_array *distf[], struct gkyl_array **bflux[], struct gkyl_array *distf_neut[]); +void gyrokinetic_calc_field_and_apply_bc( + gkyl_gyrokinetic_app *app, double tcurr, struct gkyl_array *distf[], struct gkyl_array **bflux[], + struct gkyl_array *distf_neut[] +); /** * Compute the RHS of the gyrokinetic equation (df/dt) and the minimum time @@ -4307,10 +4894,12 @@ void gyrokinetic_calc_field_and_apply_bc(gkyl_gyrokinetic_app* app, double tcurr * @param bflux_out_neut Output array of neutral-species boundary fluxes. * @param st Time stepping status object. */ -void gyrokinetic_rhs(gkyl_gyrokinetic_app* app, double tcurr, double dt, - const struct gkyl_array *fin[], struct gkyl_array *fout[], struct gkyl_array **bflux_out[], - const struct gkyl_array *fin_neut[], struct gkyl_array *fout_neut[], struct gkyl_array **bflux_out_neut[], - struct gkyl_update_status *st); +void gyrokinetic_rhs( + gkyl_gyrokinetic_app *app, double tcurr, double dt, const struct gkyl_array *fin[], + struct gkyl_array *fout[], struct gkyl_array **bflux_out[], const struct gkyl_array *fin_neut[], + struct gkyl_array *fout_neut[], struct gkyl_array **bflux_out_neut[], + struct gkyl_update_status *st +); /** * Compute the RHS of the gyrokinetic equation (df/dt) due to implicit terms. @@ -4326,10 +4915,12 @@ void gyrokinetic_rhs(gkyl_gyrokinetic_app* app, double tcurr, double dt, * @param bflux_out_neut Output array of neutral-species boundary fluxes. * @param st Time stepping status object. */ -void gyrokinetic_rhs_implicit(gkyl_gyrokinetic_app* app, double tcurr, double dt, - struct gkyl_array *fin[], struct gkyl_array *fout[], struct gkyl_array **bflux_out[], - struct gkyl_array *fin_neut[], struct gkyl_array *fout_neut[], struct gkyl_array **bflux_out_neut[], - struct gkyl_update_status *st); +void gyrokinetic_rhs_implicit( + gkyl_gyrokinetic_app *app, double tcurr, double dt, struct gkyl_array *fin[], + struct gkyl_array *fout[], struct gkyl_array **bflux_out[], struct gkyl_array *fin_neut[], + struct gkyl_array *fout_neut[], struct gkyl_array **bflux_out_neut[], + struct gkyl_update_status *st +); /** * Take time-step using the RK3 method. Also sets the status object @@ -4339,7 +4930,7 @@ void gyrokinetic_rhs_implicit(gkyl_gyrokinetic_app* app, double tcurr, double dt * @param app Gyrokinetic app. * @param dt0 Suggessted time step. */ -struct gkyl_update_status gyrokinetic_update_ssp_rk3(gkyl_gyrokinetic_app* app, double dt0); +struct gkyl_update_status gyrokinetic_update_ssp_rk3(gkyl_gyrokinetic_app *app, double dt0); /** * Take time-step of the (BGK) collision operator using a first order implicit method. @@ -4347,7 +4938,7 @@ struct gkyl_update_status gyrokinetic_update_ssp_rk3(gkyl_gyrokinetic_app* app, * @param app Gyrokinetic app. * @param dt0 Suggessted time step. */ -void gyrokinetic_update_implicit_coll(gkyl_gyrokinetic_app *app, double dt0); +void gyrokinetic_update_implicit_coll(gkyl_gyrokinetic_app *app, double dt0); /** * Take time-step using a first order operator split combining @@ -4360,7 +4951,7 @@ void gyrokinetic_update_implicit_coll(gkyl_gyrokinetic_app *app, double dt0); * @param app Gyrokinetic app. * @param dt0 Suggessted time step. */ -struct gkyl_update_status gyrokinetic_update_op_split(gkyl_gyrokinetic_app *app, double dt0); +struct gkyl_update_status gyrokinetic_update_op_split(gkyl_gyrokinetic_app *app, double dt0); /** * Initialize enforcement of quasineutrality of the guiding centers after @@ -4368,7 +4959,7 @@ struct gkyl_update_status gyrokinetic_update_op_split(gkyl_gyrokinetic_app *app, * * @param app Gyrokinetic app object. */ -void gyrokinetic_post_positivity_quasineut_init(gkyl_gyrokinetic_app* app); +void gyrokinetic_post_positivity_quasineut_init(gkyl_gyrokinetic_app *app); /** * Enforce quasineutrality of the guiding centers after applying the positivity @@ -4385,4 +4976,4 @@ void gyrokinetic_post_positivity_quasineut(gkyl_gyrokinetic_app *app, struct gky * * @param app Gyrokinetic app object. */ -void gyrokinetic_post_positivity_quasineut_release(gkyl_gyrokinetic_app* app); +void gyrokinetic_post_positivity_quasineut_release(gkyl_gyrokinetic_app *app); diff --git a/gyrokinetic/apps/gkyl_gyrokinetic_run.h b/gyrokinetic/apps/gkyl_gyrokinetic_run.h index 3611d005c6..41cba14590 100644 --- a/gyrokinetic/apps/gkyl_gyrokinetic_run.h +++ b/gyrokinetic/apps/gkyl_gyrokinetic_run.h @@ -3,7 +3,8 @@ struct gkyl_gyrokinetic_time_stepping_inp { double t_end; // End time for the simulation int num_frames; // Number of output frames. Output every (t_end/num_frames) time units. - double write_phase_freq; // Frequency (in multiples of num_frames) of writing phase-space data. e.g. 0.2 means write every 5 frames. + double + write_phase_freq; // Frequency (in multiples of num_frames) of writing phase-space data. e.g. 0.2 means write every 5 frames. int int_diag_calc_num; // Number of integrated diagnostic calculations to do. 100*num_frames means 100 calculations per frame. double dt_failure_tol; // Tolerance for small time-step failures. Typical value is 1e-4 int num_failures_max; // Maximum number of consecutive small time-step failures before aborting simulation. Typical value is 20. @@ -18,17 +19,18 @@ struct gkyl_gyrokinetic_run_verbosity_inp { bool enabled; // Is verbosity enabled? Prints information every time step. Defaults false double frequency; // Print information with given frequency. Defaults to 0.1 (every 10 steps) bool estimate_completion_time; // Estimate completion time based on current progress. Defaults false - bool disable_timings; // Disable timing information output in the terminal. Defaults false, printing all timing information. This information is always output in the .json file + bool + disable_timings; // Disable timing information output in the terminal. Defaults false, printing all timing information. This information is always output in the .json file }; enum gkyl_gyrokinetic_run_app_type { GKYL_GK_SINGLEB, // Single-block simulation. Default - GKYL_GK_MULTIB, // Multi-block simulation + GKYL_GK_MULTIB // Multi-block simulation }; struct gkyl_gyrokinetic_run_inp { enum gkyl_gyrokinetic_run_app_type app_type; // Type of gyrokinetic application to run. - union{ + union { struct gkyl_gk app_inp; // Single-block application input struct. struct gkyl_gyrokinetic_multib multib_app_inp; // Multi-block application input. }; @@ -43,5 +45,4 @@ struct gkyl_gyrokinetic_run_inp { * * @param inp Input parameters for the simulation. Includes application input structs. */ -void -gkyl_gyrokinetic_run_simulation(struct gkyl_gyrokinetic_run_inp* inp); +void gkyl_gyrokinetic_run_simulation(struct gkyl_gyrokinetic_run_inp *inp); diff --git a/gyrokinetic/apps/gkyl_multib_conn.h b/gyrokinetic/apps/gkyl_multib_conn.h index 80636ff444..da05e39e7e 100644 --- a/gyrokinetic/apps/gkyl_multib_conn.h +++ b/gyrokinetic/apps/gkyl_multib_conn.h @@ -1,14 +1,13 @@ #include #include - // Identifiers for connection type enum gkyl_conn_id { GKYL_CONN_NEIGHBOR = 0, // Adjacent blocks GKYL_CONN_ALL = 1, // Blocks connected along one direction GKYL_CONN_CORNER = 2, // Blocks connected by a corner GKYL_CONN_BELOW = 3, // Block connected below - GKYL_CONN_ABOVE = 4, // Block connected above + GKYL_CONN_ABOVE = 4 // Block connected above }; /** @@ -22,9 +21,9 @@ enum gkyl_conn_id { * @param conn_id type of connection : GKYL_CONN_NEIGHBOR, _ALL, or _CORNER * return number of connected blocks */ -int gkyl_multib_conn_get_num_connected(struct gkyl_block_topo *block_topo, int bidx, int dir, - int corner_num, enum gkyl_conn_id conn_id); - +int gkyl_multib_conn_get_num_connected( + struct gkyl_block_topo *block_topo, int bidx, int dir, int corner_num, enum gkyl_conn_id conn_id +); /** * Given a block topology, connection type, block id, and direction, @@ -39,6 +38,7 @@ int gkyl_multib_conn_get_num_connected(struct gkyl_block_topo *block_topo, int b * @param block_list on output, list of connected block ids * return number of connected blocks */ -int gkyl_multib_conn_get_connection(struct gkyl_block_topo *block_topo, int bidx, int dir, - int corner_num, enum gkyl_conn_id conn_id, int *block_list); - +int gkyl_multib_conn_get_connection( + struct gkyl_block_topo *block_topo, int bidx, int dir, int corner_num, enum gkyl_conn_id conn_id, + int *block_list +); diff --git a/gyrokinetic/apps/gyrokinetic.c b/gyrokinetic/apps/gyrokinetic.c index 5cf1ff2c99..ec1bfd9459 100644 --- a/gyrokinetic/apps/gyrokinetic.c +++ b/gyrokinetic/apps/gyrokinetic.c @@ -16,8 +16,9 @@ #include -void -gyrokinetic_cuts_check(struct gkyl_gyrokinetic_app* app, struct gkyl_comm *comm, const int *cuts, FILE *iostream) +void gyrokinetic_cuts_check( + struct gkyl_gyrokinetic_app *app, struct gkyl_comm *comm, const int *cuts, FILE *iostream +) { // A temporary function that checks the consistency of the communicator and // cuts provided for a simulation (e.g at the moment we only decompose along @@ -27,10 +28,13 @@ gyrokinetic_cuts_check(struct gkyl_gyrokinetic_app* app, struct gkyl_comm *comm, // Create decomposition. int cuts_used[cdim]; #ifdef GKYL_HAVE_MPI - for (int d = 0; d < cdim; d++) + for (int d = 0; d < cdim; d++) { cuts_used[d] = cuts[d]; + } #else - for (int d = 0; d < cdim; d++) cuts_used[d] = 1; + for (int d = 0; d < cdim; d++) { + cuts_used[d] = 1; + } #endif int comm_rank, comm_size; @@ -38,34 +42,46 @@ gyrokinetic_cuts_check(struct gkyl_gyrokinetic_app* app, struct gkyl_comm *comm, gkyl_comm_get_size(comm, &comm_size); int ncuts = 1; - for (int d = 0; d < cdim; d++) ncuts *= cuts_used[d]; + for (int d = 0; d < cdim; d++) { + ncuts *= cuts_used[d]; + } if (ncuts != comm_size) { - if (comm_rank == 0) - fprintf(iostream, "\n*** Number of ranks, %d, does not match total cuts, %d!\n\n", comm_size, ncuts); + if (comm_rank == 0) { + fprintf( + iostream, "\n*** Number of ranks, %d, does not match total cuts, %d!\n\n", comm_size, ncuts + ); + } assert(false); } for (int d = 0; d < cdim - 1; d++) { if (cuts_used[d] > 1) { - if (comm_rank == 0) - fprintf(iostream, - "\n*** Parallelization only allowed in z. Number of ranks, %d, in direction %d cannot be > 1!\n\n", cuts_used[d], d); + if (comm_rank == 0) { + fprintf( + iostream, + "\n*** Parallelization only allowed in z. Number of ranks, %d, in direction %d cannot be " + "> 1!\n\n", + cuts_used[d], d + ); + } assert(false); } } if (app->grid.cells[cdim - 1] % cuts_used[cdim - 1] != 0) { - if (comm_rank == 0) - fprintf(iostream, - "\n*** Number of cells in z, %d, not divisible by number of cuts, %d!\n\n", - app->grid.cells[cdim - 1], cuts_used[cdim - 1]); + if (comm_rank == 0) { + fprintf( + iostream, "\n*** Number of cells in z, %d, not divisible by number of cuts, %d!\n\n", + app->grid.cells[cdim - 1], cuts_used[cdim - 1] + ); + } assert(false); } } -static bool -gyrokinetic_str_ends_in_b0(char *name){ +static bool gyrokinetic_str_ends_in_b0(char *name) +{ // Check if the string `name` ends in "b0". size_t len = strlen(name); int i = len - 1; @@ -74,27 +90,27 @@ gyrokinetic_str_ends_in_b0(char *name){ i--; digit_count++; } - if (digit_count > 0 && i >= 1 && name[i] == 'b' && name[i-1] == '_') { + if (digit_count > 0 && i >= 1 && name[i] == 'b' && name[i - 1] == '_') { const char *num_str = &name[i + 1]; int num = atoi(num_str); - if ( num == 0) + if (num == 0) { return true; - else + } else { return false; - } - else { + } + } else { return true; } } -static bool -gyrokinetic_str_ends_in_bnum(const char *name) +static bool gyrokinetic_str_ends_in_bnum(const char *name) { // Check whether a string ends in _b#, where # is a number. size_t len = strlen(name); - if (len < 3) + if (len < 3) { return false; + } int i = (int)len - 1; @@ -106,60 +122,66 @@ gyrokinetic_str_ends_in_bnum(const char *name) } // Must have at least one digit and end with "_b". - if (digit_count > 0 && i >= 1 && - name[i] == 'b' && name[i - 1] == '_') + if (digit_count > 0 && i >= 1 && name[i] == 'b' && name[i - 1] == '_') { return true; + } return false; } -void -gyrokinetic_deflate_delta_ts(struct gkyl_gyrokinetic_app* app, struct gkyl_array *delta_ts) +void gyrokinetic_deflate_delta_ts(struct gkyl_gyrokinetic_app *app, struct gkyl_array *delta_ts) { // Deflate the array that holds the shift for TS BCs from 3D to 1D. - if (app->cdim < 3) + if (app->cdim < 3) { return; // Nothing to deflate. - - int par_dir = app->cdim-1; + } + + int par_dir = app->cdim - 1; // First copy the surface delta_ts from its 3D array to a 2D array. struct gkyl_range local_skin_perp; struct gkyl_translate_dim *transd_2d_1d; struct gkyl_array *buffer_perp; - struct gkyl_array *delta_ts_x_dev = mkarr(app->use_gpu, app->delta_ts_x_lo->ncomp, app->delta_ts_x_lo->size); + struct gkyl_array *delta_ts_x_dev = + mkarr(app->use_gpu, app->delta_ts_x_lo->ncomp, app->delta_ts_x_lo->size); // Lower z boundary. - struct gkyl_range *local_skin_lower = app->gk_geom->has_LCFS? &app->local_lower_skin_par_core - : &app->local_lower_skin[par_dir]; - gkyl_range_init(&local_skin_perp, app->cdim-1, local_skin_lower->lower, local_skin_lower->upper); + struct gkyl_range *local_skin_lower = app->gk_geom->has_LCFS ? &app->local_lower_skin_par_core : + &app->local_lower_skin[par_dir]; + gkyl_range_init(&local_skin_perp, app->cdim - 1, local_skin_lower->lower, local_skin_lower->upper); buffer_perp = mkarr(app->use_gpu, delta_ts->ncomp, local_skin_perp.volume); gkyl_array_copy_range_to_range(buffer_perp, delta_ts, &local_skin_perp, local_skin_lower); - transd_2d_1d = gkyl_translate_dim_new(app->cdim-1, app->gk_geom->surf_basis, - 1, app->delta_ts_x_basis, 1, GKYL_NO_EDGE, app->use_gpu); - gkyl_translate_dim_advance(transd_2d_1d, &local_skin_perp, &app->delta_ts_x_rng, buffer_perp, 1, delta_ts_x_dev); + transd_2d_1d = gkyl_translate_dim_new( + app->cdim - 1, app->gk_geom->surf_basis, 1, app->delta_ts_x_basis, 1, GKYL_NO_EDGE, app->use_gpu + ); + gkyl_translate_dim_advance( + transd_2d_1d, &local_skin_perp, &app->delta_ts_x_rng, buffer_perp, 1, delta_ts_x_dev + ); gkyl_translate_dim_release(transd_2d_1d); gkyl_array_release(buffer_perp); gkyl_array_copy(app->delta_ts_x_lo, delta_ts_x_dev); // Upper z boundary. - struct gkyl_range *local_skin_upper = app->gk_geom->has_LCFS? &app->local_upper_skin_par_core - : &app->local_upper_skin[par_dir]; - gkyl_range_init(&local_skin_perp, app->cdim-1, local_skin_upper->lower, local_skin_upper->upper); + struct gkyl_range *local_skin_upper = app->gk_geom->has_LCFS ? &app->local_upper_skin_par_core : + &app->local_upper_skin[par_dir]; + gkyl_range_init(&local_skin_perp, app->cdim - 1, local_skin_upper->lower, local_skin_upper->upper); buffer_perp = mkarr(app->use_gpu, delta_ts->ncomp, local_skin_perp.volume); gkyl_array_copy_range_to_range(buffer_perp, delta_ts, &local_skin_perp, local_skin_upper); - transd_2d_1d = gkyl_translate_dim_new(app->cdim-1, app->gk_geom->surf_basis, - 1, app->delta_ts_x_basis, 1, GKYL_NO_EDGE, app->use_gpu); - gkyl_translate_dim_advance(transd_2d_1d, &local_skin_perp, &app->delta_ts_x_rng, buffer_perp, 1, delta_ts_x_dev); + transd_2d_1d = gkyl_translate_dim_new( + app->cdim - 1, app->gk_geom->surf_basis, 1, app->delta_ts_x_basis, 1, GKYL_NO_EDGE, app->use_gpu + ); + gkyl_translate_dim_advance( + transd_2d_1d, &local_skin_perp, &app->delta_ts_x_rng, buffer_perp, 1, delta_ts_x_dev + ); gkyl_translate_dim_release(transd_2d_1d); gkyl_array_release(buffer_perp); gkyl_array_copy(app->delta_ts_x_up, delta_ts_x_dev); gkyl_array_release(delta_ts_x_dev); } -gkyl_gyrokinetic_app* -gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) +gkyl_gyrokinetic_app *gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) { disable_denorm_float(); @@ -168,7 +190,9 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) gkyl_gyrokinetic_app *app = gkyl_malloc(sizeof(gkyl_gyrokinetic_app)); // Check if this is a multiblock sim from metadata. - app->is_multib = gkyl_msgpack_map_elem_get_uint(gk->metadata.num_attributes, gk->metadata.attributes, "is_multib"); + app->is_multib = gkyl_msgpack_map_elem_get_uint( + gk->metadata.num_attributes, gk->metadata.attributes, "is_multib" + ); int cdim = app->cdim = gk->cdim; int poly_order = app->poly_order = gk->poly_order; @@ -190,8 +214,9 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) #endif app->num_periodic_dir = gk->num_periodic_dir; - for (int d=0; dperiodic_dirs[d] = gk->periodic_dirs[d]; + } strcpy(app->name, gk->name); app->tcurr = 0.0; // reset on init @@ -199,44 +224,39 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) if (app->use_gpu) { // allocate device basis if we are using GPUs app->basis_on_dev = gkyl_cu_malloc(sizeof(struct gkyl_basis)); - } - else { + } else { app->basis_on_dev = &app->basis; } // basis functions switch (gk->basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - gkyl_cart_modal_serendip(&app->basis, cdim, poly_order); - if (app->use_gpu) { - gkyl_cart_modal_serendip_cu_dev(app->basis_on_dev, cdim, poly_order); - } - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + gkyl_cart_modal_serendip(&app->basis, cdim, poly_order); + if (app->use_gpu) { + gkyl_cart_modal_serendip_cu_dev(app->basis_on_dev, cdim, poly_order); + } + break; + default: + assert(false); + break; } gkyl_rect_grid_init(&app->grid, cdim, gk->lower, gk->upper, gk->cells); - int ghost[] = { 1, 1, 1 }; + int ghost[] = {1, 1, 1}; gkyl_create_grid_ranges(&app->grid, ghost, &app->global_ext, &app->global); if (gk->parallelism.comm == 0) { - int cuts[3] = { 1, 1, 1 }; + int cuts[3] = {1, 1, 1}; app->decomp = gkyl_rect_decomp_new_from_cuts(cdim, cuts, &app->global); - - app->comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = app->decomp, - .use_gpu = app->use_gpu - } - ); - + + app->comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.decomp = app->decomp, .use_gpu = app->use_gpu}); + // Global and local ranges are same, and so just copy them. memcpy(&app->local, &app->global, sizeof(struct gkyl_range)); memcpy(&app->local_ext, &app->global_ext, sizeof(struct gkyl_range)); - } - else { + } else { gyrokinetic_cuts_check(app, gk->parallelism.comm, gk->parallelism.cuts, stdout); // Create decomp. @@ -255,13 +275,12 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) if (app->cdim == 1) { app->decomp_plane[0] = gkyl_rect_decomp_acquire(app->decomp); app->comm_plane[0] = gkyl_comm_acquire(app->comm); - } - else { - for (int dir=0; dircdim; ++dir) { + } else { + for (int dir = 0; dir < app->cdim; ++dir) { // Identify ranks on the same plane as this one. int num_ranks_plane = 0; - int ranks_plane[app->decomp->ndecomp]; - for (int i=0; idecomp->ndecomp; i++) { + int ranks_plane[app->decomp->ndecomp]; + for (int i = 0; i < app->decomp->ndecomp; i++) { if (app->decomp->ranges[i].lower[dir] == app->local.lower[dir]) { ranks_plane[num_ranks_plane] = i; num_ranks_plane++; @@ -269,7 +288,7 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) } // Create a range tangentially global, and local in perp direction. int lower_plane[app->cdim], upper_plane[app->cdim]; - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { lower_plane[d] = app->global.lower[d]; upper_plane[d] = app->global.upper[d]; } @@ -277,44 +296,56 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) upper_plane[dir] = app->local.upper[dir]; struct gkyl_range range_plane; gkyl_range_init(&range_plane, app->cdim, lower_plane, upper_plane); - + // Create decomp. int cuts_plane[GKYL_MAX_CDIM]; - for (int d=0; dcdim; ++d) + for (int d = 0; d < app->cdim; ++d) { cuts_plane[d] = gk->parallelism.cuts[d]; + } cuts_plane[dir] = 1; app->decomp_plane[dir] = gkyl_rect_decomp_new_from_cuts(app->cdim, cuts_plane, &range_plane); - + // Create a new communicator with ranks on plane. bool is_comm_valid; - app->comm_plane[dir] = gkyl_comm_create_comm_from_ranks(app->comm, num_ranks_plane, - ranks_plane, app->decomp_plane[dir], &is_comm_valid); + app->comm_plane[dir] = gkyl_comm_create_comm_from_ranks( + app->comm, num_ranks_plane, ranks_plane, app->decomp_plane[dir], &is_comm_valid + ); assert(is_comm_valid); } } // Skin and ghost ranges for configuration space fields. - for (int dir=0; dirlocal_lower_skin[dir], &app->local_lower_ghost[dir], - dir, GKYL_LOWER_EDGE, &app->local_ext, ghost); - gkyl_skin_ghost_ranges(&app->local_upper_skin[dir], &app->local_upper_ghost[dir], - dir, GKYL_UPPER_EDGE, &app->local_ext, ghost); - gkyl_skin_ghost_ranges(&app->global_lower_skin[dir], &app->global_lower_ghost[dir], - dir, GKYL_LOWER_EDGE, &app->global_ext, ghost); - gkyl_skin_ghost_ranges(&app->global_upper_skin[dir], &app->global_upper_ghost[dir], - dir, GKYL_UPPER_EDGE, &app->global_ext, ghost); + for (int dir = 0; dir < cdim; ++dir) { + gkyl_skin_ghost_ranges( + &app->local_lower_skin[dir], &app->local_lower_ghost[dir], dir, GKYL_LOWER_EDGE, + &app->local_ext, ghost + ); + gkyl_skin_ghost_ranges( + &app->local_upper_skin[dir], &app->local_upper_ghost[dir], dir, GKYL_UPPER_EDGE, + &app->local_ext, ghost + ); + gkyl_skin_ghost_ranges( + &app->global_lower_skin[dir], &app->global_lower_ghost[dir], dir, GKYL_LOWER_EDGE, + &app->global_ext, ghost + ); + gkyl_skin_ghost_ranges( + &app->global_upper_skin[dir], &app->global_upper_ghost[dir], dir, GKYL_UPPER_EDGE, + &app->global_ext, ghost + ); } int comm_sz; gkyl_comm_get_size(app->comm, &comm_sz); // Configuration space geometry initialization - app->position_map = gkyl_position_map_new(gk->geometry.position_map_info, app->grid, app->local, - app->local_ext, app->global, app->global_ext, app->basis); + app->position_map = gkyl_position_map_new( + gk->geometry.position_map_info, app->grid, app->local, app->local_ext, app->global, + app->global_ext, app->basis + ); // Initialize the input struct from user side input struct struct gkyl_gk_geometry_inp geometry_inp = { - .geometry_id = gk->geometry.geometry_id, + .geometry_id = gk->geometry.geometry_id, .c2p_ctx = gk->geometry.c2p_ctx, .mapc2p = gk->geometry.mapc2p, .bfield_ctx = gk->geometry.bfield_ctx, @@ -334,37 +365,40 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) .x_LCFS = gk->geometry.x_LCFS, .parallel_lower_bc_shift_func = gk->geometry.parallel_lower_bc_shift_func, .parallel_upper_bc_shift_func = gk->geometry.parallel_upper_bc_shift_func, - .parallel_lower_bc_shift_ctx = gk->geometry.parallel_lower_bc_shift_ctx , - .parallel_upper_bc_shift_ctx = gk->geometry.parallel_upper_bc_shift_ctx , + .parallel_lower_bc_shift_ctx = gk->geometry.parallel_lower_bc_shift_ctx, + .parallel_upper_bc_shift_ctx = gk->geometry.parallel_upper_bc_shift_ctx }; strcpy(geometry_inp.geometry_path, gk->geometry.geometry_path); - for(int i = 0; i<3; i++) + for (int i = 0; i < 3; i++) { geometry_inp.world[i] = gk->geometry.world[i]; + } - if (app->cdim < 3){ + if (app->cdim < 3) { geometry_inp.geo_grid = gkyl_gk_geometry_augment_grid(app->grid, geometry_inp); switch (gk->basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - gkyl_cart_modal_serendip(&geometry_inp.geo_basis, 3, poly_order); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + gkyl_cart_modal_serendip(&geometry_inp.geo_basis, 3, poly_order); + break; + default: + assert(false); + break; } - int ghost[] = { 1, 1, 1 }; - gkyl_create_grid_ranges(&geometry_inp.geo_grid, ghost, &geometry_inp.geo_global_ext, &geometry_inp.geo_global); + int ghost[] = {1, 1, 1}; + gkyl_create_grid_ranges( + &geometry_inp.geo_grid, ghost, &geometry_inp.geo_global_ext, &geometry_inp.geo_global + ); if (comm_sz > 1) { // Create local and local_ext from user-supplied local range. - gkyl_gk_geometry_augment_local(&app->local, ghost, &geometry_inp.geo_local_ext, &geometry_inp.geo_local); - } - else { + gkyl_gk_geometry_augment_local( + &app->local, ghost, &geometry_inp.geo_local_ext, &geometry_inp.geo_local + ); + } else { // Global and local ranges are same, and so just copy. memcpy(&geometry_inp.geo_local, &geometry_inp.geo_global, sizeof(struct gkyl_range)); memcpy(&geometry_inp.geo_local_ext, &geometry_inp.geo_global_ext, sizeof(struct gkyl_range)); } - } - else { + } else { geometry_inp.geo_grid = app->grid; geometry_inp.geo_local = app->local; geometry_inp.geo_local_ext = app->local_ext; @@ -373,31 +407,31 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) geometry_inp.geo_basis = app->basis; } - struct gk_geometry* gk_geom_3d; + struct gk_geometry *gk_geom_3d; switch (geometry_inp.geometry_id) { - case GKYL_GEOMETRY_FROMFILE: - gk_geom_3d = gkyl_gk_geometry_new(app->gk_geom, &geometry_inp, false); - break; - case GKYL_GEOMETRY_TOKAMAK: - gk_geom_3d = gkyl_gk_geometry_tok_new(&geometry_inp); - break; - case GKYL_GEOMETRY_MIRROR: - gk_geom_3d = gkyl_gk_geometry_mirror_new(&geometry_inp); - break; - case GKYL_GEOMETRY_MAPC2P: - case GKYL_GEOMETRY_NONE: - gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_inp); - break; + case GKYL_GEOMETRY_FROMFILE: + gk_geom_3d = gkyl_gk_geometry_new(app->gk_geom, &geometry_inp, false); + break; + case GKYL_GEOMETRY_TOKAMAK: + gk_geom_3d = gkyl_gk_geometry_tok_new(&geometry_inp); + break; + case GKYL_GEOMETRY_MIRROR: + gk_geom_3d = gkyl_gk_geometry_mirror_new(&geometry_inp); + break; + case GKYL_GEOMETRY_MAPC2P: + case GKYL_GEOMETRY_NONE: + gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_inp); + break; } if (geometry_inp.geometry_id != GKYL_GEOMETRY_FROMFILE) { // Deflate geometry if necessary. - if (app->cdim < 3) + if (app->cdim < 3) { app->gk_geom = gkyl_gk_geometry_deflate(gk_geom_3d, &geometry_inp); - else + } else { app->gk_geom = gkyl_gk_geometry_acquire(gk_geom_3d); - } - else { + } + } else { app->gk_geom = gkyl_gk_geometry_acquire(gk_geom_3d); gkyl_gyrokinetic_app_read_geometry(app, &geometry_inp); gkyl_gk_geometry_populate_nodal(app->gk_geom); @@ -413,20 +447,16 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) bmag_max_local = gkyl_gk_geometry_reduce_bmag(app->gk_geom, GKYL_MAX); gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 1, &bmag_max_local, &bmag_max_global); - app->bmag_ref = (bmag_max_global + bmag_min_global)/2.0; + app->bmag_ref = (bmag_max_global + bmag_min_global) / 2.0; gkyl_position_map_set_mc2nu(app->position_map, app->gk_geom->geo_corn.mc2nu_pos); const struct gkyl_dg_geom_inp dg_geom_inp = { - .grid = &app->grid, - .range = &app->local_ext, - .nquad = 2, + .grid = &app->grid, .range = &app->local_ext, .nquad = 2 }; const struct gkyl_gk_dg_geom_inp gk_dg_geom_inp = { - .grid = &app->grid, - .range = &app->local_ext, - .nquad = 2, + .grid = &app->grid, .range = &app->local_ext, .nquad = 2 }; // Populate dg_geom and gk_dg_geom objects with geometric quantities @@ -438,9 +468,11 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) // If we are on the gpu, copy from host. if (app->use_gpu) { - struct gkyl_dg_geom* dg_geom_dev = gkyl_dg_geom_new_from_host(&dg_geom_inp, app->dg_geom, true); - struct gkyl_gk_dg_geom* gk_dg_geom_dev = gkyl_gk_dg_geom_new_from_host(&gk_dg_geom_inp, app->gk_dg_geom, true); - struct gk_geometry* gk_geom_dev = gkyl_gk_geometry_new(app->gk_geom, &geometry_inp, app->use_gpu); + struct gkyl_dg_geom *dg_geom_dev = gkyl_dg_geom_new_from_host(&dg_geom_inp, app->dg_geom, true); + struct gkyl_gk_dg_geom *gk_dg_geom_dev = + gkyl_gk_dg_geom_new_from_host(&gk_dg_geom_inp, app->gk_dg_geom, true); + struct gk_geometry *gk_geom_dev = + gkyl_gk_geometry_new(app->gk_geom, &geometry_inp, app->use_gpu); gkyl_gk_geometry_release(app->gk_geom); app->gk_geom = gkyl_gk_geometry_acquire(gk_geom_dev); @@ -456,47 +488,58 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) } // Basic metadata for I/O (including metadata optional from user). - const char* build_id = GIT_COMMIT_ID; - const char* build_date = GKYL_BUILD_DATE; + const char *build_id = GIT_COMMIT_ID; + const char *build_date = GKYL_BUILD_DATE; if (app->is_multib) { app->io_meta_basic_len = gk->metadata.num_attributes; - app->io_meta_basic = gkyl_msgpack_map_elem_clone(app->io_meta_basic_len, gk->metadata.attributes); - } - else { + app->io_meta_basic = + gkyl_msgpack_map_elem_clone(app->io_meta_basic_len, gk->metadata.attributes); + } else { struct gkyl_msgpack_map_elem io_meta_basic_default[] = { - { .key = "changeset", .elem_type = GKYL_MP_STRING, .cval = (char *)build_id }, - { .key = "builddate", .elem_type = GKYL_MP_STRING, .cval = (char *)build_date }, + {.key = "changeset", .elem_type = GKYL_MP_STRING, .cval = (char *)build_id}, + {.key = "builddate", .elem_type = GKYL_MP_STRING, .cval = (char *)build_date} }; - const struct gkyl_msgpack_map_elem *io_meta_basic_union[] = {io_meta_basic_default, gk->metadata.attributes}; - int io_meta_basic_union_len[] = {sizeof(io_meta_basic_default)/sizeof(io_meta_basic_default[0]), gk->metadata.num_attributes}; - app->io_meta_basic = gkyl_msgpack_map_elem_union(sizeof(io_meta_basic_union)/sizeof(io_meta_basic_union[0]), - io_meta_basic_union_len, io_meta_basic_union, &app->io_meta_basic_len); + const struct gkyl_msgpack_map_elem *io_meta_basic_union[] = { + io_meta_basic_default, gk->metadata.attributes + }; + int io_meta_basic_union_len[] = { + sizeof(io_meta_basic_default) / sizeof(io_meta_basic_default[0]), gk->metadata.num_attributes + }; + app->io_meta_basic = gkyl_msgpack_map_elem_union( + sizeof(io_meta_basic_union) / sizeof(io_meta_basic_union[0]), io_meta_basic_union_len, + io_meta_basic_union, &app->io_meta_basic_len + ); } // Metadata for grid quantities (including metadata optional from user). struct gkyl_msgpack_map_elem io_meta_dg[] = { - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0 }, - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = app->basis.poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->basis.id } + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .dval = 0.0}, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0}, + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = app->basis.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->basis.id} }; const struct gkyl_msgpack_map_elem *io_meta_dg_union[] = {app->io_meta_basic, io_meta_dg}; - int io_meta_dg_union_len[] = {app->io_meta_basic_len, sizeof(io_meta_dg)/sizeof(io_meta_dg[0])}; - app->io_meta_dg = gkyl_msgpack_map_elem_union(sizeof(io_meta_dg_union)/sizeof(io_meta_dg_union[0]), - io_meta_dg_union_len, io_meta_dg_union, &app->io_meta_dg_len); + int io_meta_dg_union_len[] = {app->io_meta_basic_len, sizeof(io_meta_dg) / sizeof(io_meta_dg[0])}; + app->io_meta_dg = gkyl_msgpack_map_elem_union( + sizeof(io_meta_dg_union) / sizeof(io_meta_dg_union[0]), io_meta_dg_union_len, io_meta_dg_union, + &app->io_meta_dg_len + ); // Allocate 1/(J.B) using weak mul/div. struct gkyl_array *tmp = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); app->jacobtot_inv_weak = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - gkyl_dg_mul_op_range(&app->basis, 0, tmp, 0, app->gk_geom->geo_int.bmag, 0, app->gk_geom->geo_int.jacobgeo, &app->local); - gkyl_dg_inv_op_range(&app->basis, 0, app->jacobtot_inv_weak, 0, tmp, &app->local); + gkyl_dg_mul_op_range( + &app->basis, 0, tmp, 0, app->gk_geom->geo_int.bmag, 0, app->gk_geom->geo_int.jacobgeo, + &app->local + ); + gkyl_dg_inv_op_range(&app->basis, 0, app->jacobtot_inv_weak, 0, tmp, &app->local); gkyl_array_release(tmp); // Create a global and local ranges, extended in the BC dir. int ndim = app->cdim; - int par_dir = ndim-1; + int par_dir = ndim - 1; int lower_bcdir_ext[ndim], upper_bcdir_ext[ndim]; - for (int i=0; iglobal.lower[i]; upper_bcdir_ext[i] = app->global.upper[i]; } @@ -504,7 +547,7 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) upper_bcdir_ext[par_dir] = app->global_ext.upper[par_dir]; gkyl_sub_range_init(&app->global_par_ext, &app->global_ext, lower_bcdir_ext, upper_bcdir_ext); - for (int i=0; ilocal.lower[i]; upper_bcdir_ext[i] = app->local.upper[i]; } @@ -517,71 +560,70 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) int idx_LCFS_lo = app->gk_geom->idx_LCFS_lo; // Length of lower and upper x ranges (one is core, the other SOL). int len_lo = idx_LCFS_lo; - int len_up = app->global.upper[0]-len_lo; + int len_up = app->global.upper[0] - len_lo; // Lower and upper x ranges. struct gkyl_range *global_lo_r, *global_up_r, *global_ext_lo_r, *global_ext_up_r; - struct gkyl_range *global_lower_skin_par_lo_r , *global_upper_skin_par_lo_r , - *global_lower_ghost_par_lo_r, *global_upper_ghost_par_lo_r; - struct gkyl_range *global_lower_skin_par_up_r , *global_upper_skin_par_up_r , - *global_lower_ghost_par_up_r, *global_upper_ghost_par_up_r; + struct gkyl_range *global_lower_skin_par_lo_r, *global_upper_skin_par_lo_r, + *global_lower_ghost_par_lo_r, *global_upper_ghost_par_lo_r; + struct gkyl_range *global_lower_skin_par_up_r, *global_upper_skin_par_up_r, + *global_lower_ghost_par_up_r, *global_upper_ghost_par_up_r; struct gkyl_range *local_lo_r, *local_up_r, *local_ext_lo_r, *local_ext_up_r; - struct gkyl_range *local_lower_skin_par_lo_r , *local_upper_skin_par_lo_r , - *local_lower_ghost_par_lo_r, *local_upper_ghost_par_lo_r; - struct gkyl_range *local_lower_skin_par_up_r , *local_upper_skin_par_up_r , - *local_lower_ghost_par_up_r, *local_upper_ghost_par_up_r; + struct gkyl_range *local_lower_skin_par_lo_r, *local_upper_skin_par_lo_r, + *local_lower_ghost_par_lo_r, *local_upper_ghost_par_lo_r; + struct gkyl_range *local_lower_skin_par_up_r, *local_upper_skin_par_up_r, + *local_lower_ghost_par_up_r, *local_upper_ghost_par_up_r; if (app->gk_geom->geqdsk_sign_convention == 0) { // x increases towards SOL. - global_lo_r = &app->global_core; - global_up_r = &app->global_sol; - global_ext_lo_r = &app->global_ext_core; - global_ext_up_r = &app->global_ext_sol; - global_lower_skin_par_lo_r = &app->global_lower_skin_par_core; + global_lo_r = &app->global_core; + global_up_r = &app->global_sol; + global_ext_lo_r = &app->global_ext_core; + global_ext_up_r = &app->global_ext_sol; + global_lower_skin_par_lo_r = &app->global_lower_skin_par_core; global_lower_ghost_par_lo_r = &app->global_lower_ghost_par_core; - global_lower_skin_par_up_r = &app->global_lower_skin_par_sol; + global_lower_skin_par_up_r = &app->global_lower_skin_par_sol; global_lower_ghost_par_up_r = &app->global_lower_ghost_par_sol; - global_upper_skin_par_lo_r = &app->global_upper_skin_par_core; + global_upper_skin_par_lo_r = &app->global_upper_skin_par_core; global_upper_ghost_par_lo_r = &app->global_upper_ghost_par_core; - global_upper_skin_par_up_r = &app->global_upper_skin_par_sol; + global_upper_skin_par_up_r = &app->global_upper_skin_par_sol; global_upper_ghost_par_up_r = &app->global_upper_ghost_par_sol; - local_lo_r = &app->local_core; - local_up_r = &app->local_sol; - local_ext_lo_r = &app->local_ext_core; - local_ext_up_r = &app->local_ext_sol; - local_lower_skin_par_lo_r = &app->local_lower_skin_par_core; - local_lower_ghost_par_lo_r = &app->local_lower_ghost_par_core; - local_lower_skin_par_up_r = &app->local_lower_skin_par_sol; - local_lower_ghost_par_up_r = &app->local_lower_ghost_par_sol; - local_upper_skin_par_lo_r = &app->local_upper_skin_par_core; - local_upper_ghost_par_lo_r = &app->local_upper_ghost_par_core; - local_upper_skin_par_up_r = &app->local_upper_skin_par_sol; - local_upper_ghost_par_up_r = &app->local_upper_ghost_par_sol; - } - else { + local_lo_r = &app->local_core; + local_up_r = &app->local_sol; + local_ext_lo_r = &app->local_ext_core; + local_ext_up_r = &app->local_ext_sol; + local_lower_skin_par_lo_r = &app->local_lower_skin_par_core; + local_lower_ghost_par_lo_r = &app->local_lower_ghost_par_core; + local_lower_skin_par_up_r = &app->local_lower_skin_par_sol; + local_lower_ghost_par_up_r = &app->local_lower_ghost_par_sol; + local_upper_skin_par_lo_r = &app->local_upper_skin_par_core; + local_upper_ghost_par_lo_r = &app->local_upper_ghost_par_core; + local_upper_skin_par_up_r = &app->local_upper_skin_par_sol; + local_upper_ghost_par_up_r = &app->local_upper_ghost_par_sol; + } else { // x increases towards core. - global_lo_r = &app->global_sol; - global_up_r = &app->global_core; - global_ext_lo_r = &app->global_ext_sol; - global_ext_up_r = &app->global_ext_core; - global_lower_skin_par_lo_r = &app->global_lower_skin_par_sol; + global_lo_r = &app->global_sol; + global_up_r = &app->global_core; + global_ext_lo_r = &app->global_ext_sol; + global_ext_up_r = &app->global_ext_core; + global_lower_skin_par_lo_r = &app->global_lower_skin_par_sol; global_lower_ghost_par_lo_r = &app->global_lower_ghost_par_sol; - global_lower_skin_par_up_r = &app->global_lower_skin_par_core; + global_lower_skin_par_up_r = &app->global_lower_skin_par_core; global_lower_ghost_par_up_r = &app->global_lower_ghost_par_core; - global_upper_skin_par_lo_r = &app->global_upper_skin_par_sol; + global_upper_skin_par_lo_r = &app->global_upper_skin_par_sol; global_upper_ghost_par_lo_r = &app->global_upper_ghost_par_sol; - global_upper_skin_par_up_r = &app->global_upper_skin_par_core; + global_upper_skin_par_up_r = &app->global_upper_skin_par_core; global_upper_ghost_par_up_r = &app->global_upper_ghost_par_core; - local_lo_r = &app->local_sol; - local_up_r = &app->local_core; - local_ext_lo_r = &app->local_ext_sol; - local_ext_up_r = &app->local_ext_core; - local_lower_skin_par_lo_r = &app->local_lower_skin_par_sol; - local_lower_ghost_par_lo_r = &app->local_lower_ghost_par_sol; - local_lower_skin_par_up_r = &app->local_lower_skin_par_core; - local_lower_ghost_par_up_r = &app->local_lower_ghost_par_core; - local_upper_skin_par_lo_r = &app->local_upper_skin_par_sol; - local_upper_ghost_par_lo_r = &app->local_upper_ghost_par_sol; - local_upper_skin_par_up_r = &app->local_upper_skin_par_core; - local_upper_ghost_par_up_r = &app->local_upper_ghost_par_core; + local_lo_r = &app->local_sol; + local_up_r = &app->local_core; + local_ext_lo_r = &app->local_ext_sol; + local_ext_up_r = &app->local_ext_core; + local_lower_skin_par_lo_r = &app->local_lower_skin_par_sol; + local_lower_ghost_par_lo_r = &app->local_lower_ghost_par_sol; + local_lower_skin_par_up_r = &app->local_lower_skin_par_core; + local_lower_ghost_par_up_r = &app->local_lower_ghost_par_core; + local_upper_skin_par_lo_r = &app->local_upper_skin_par_sol; + local_upper_ghost_par_lo_r = &app->local_upper_ghost_par_sol; + local_upper_skin_par_up_r = &app->local_upper_skin_par_core; + local_upper_ghost_par_up_r = &app->local_upper_ghost_par_core; } // Lower and upper x ranges. @@ -591,60 +633,81 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) gkyl_range_shorten_from_below(local_up_r, &app->local, 0, len_up); // Extended lower and upper x ranges. - int len_lo_ext = idx_LCFS_lo+1; - int len_up_ext = app->global_ext.upper[0]-len_lo; + int len_lo_ext = idx_LCFS_lo + 1; + int len_up_ext = app->global_ext.upper[0] - len_lo; gkyl_range_shorten_from_above(global_ext_lo_r, &app->global_ext, 0, len_lo_ext); gkyl_range_shorten_from_below(global_ext_up_r, &app->global_ext, 0, len_up_ext); gkyl_range_shorten_from_above(local_ext_lo_r, &app->local_ext, 0, len_lo_ext); gkyl_range_shorten_from_below(local_ext_up_r, &app->local_ext, 0, len_up_ext); // Parallel skin and ghost ranges, limited to the lower and upper x range. - int par_dir = app->cdim-1; - for (int e=0; e<2; e++) { - gkyl_range_shorten_from_above(e==0? global_lower_skin_par_lo_r : global_upper_skin_par_lo_r, - e==0? &app->global_lower_skin[par_dir] : &app->global_upper_skin[par_dir], 0, len_lo); - gkyl_range_shorten_from_above(e==0? global_lower_ghost_par_lo_r : global_upper_ghost_par_lo_r, - e==0? &app->global_lower_ghost[par_dir] : &app->global_upper_ghost[par_dir], 0, len_lo); - gkyl_range_shorten_from_below(e==0? global_lower_skin_par_up_r : global_upper_skin_par_up_r, - e==0? &app->global_lower_skin[par_dir] : &app->global_upper_skin[par_dir], 0, len_up); - gkyl_range_shorten_from_below(e==0? global_lower_ghost_par_up_r : global_upper_ghost_par_up_r, - e==0? &app->global_lower_ghost[par_dir] : &app->global_upper_ghost[par_dir], 0, len_up); - gkyl_range_shorten_from_above(e==0? local_lower_skin_par_lo_r : local_upper_skin_par_lo_r, - e==0? &app->local_lower_skin[par_dir] : &app->local_upper_skin[par_dir], 0, len_lo); - gkyl_range_shorten_from_above(e==0? local_lower_ghost_par_lo_r : local_upper_ghost_par_lo_r, - e==0? &app->local_lower_ghost[par_dir] : &app->local_upper_ghost[par_dir], 0, len_lo); - gkyl_range_shorten_from_below(e==0? local_lower_skin_par_up_r : local_upper_skin_par_up_r, - e==0? &app->local_lower_skin[par_dir] : &app->local_upper_skin[par_dir], 0, len_up); - gkyl_range_shorten_from_below(e==0? local_lower_ghost_par_up_r : local_upper_ghost_par_up_r, - e==0? &app->local_lower_ghost[par_dir] : &app->local_upper_ghost[par_dir], 0, len_up); + int par_dir = app->cdim - 1; + for (int e = 0; e < 2; e++) { + gkyl_range_shorten_from_above( + e == 0 ? global_lower_skin_par_lo_r : global_upper_skin_par_lo_r, + e == 0 ? &app->global_lower_skin[par_dir] : &app->global_upper_skin[par_dir], 0, len_lo + ); + gkyl_range_shorten_from_above( + e == 0 ? global_lower_ghost_par_lo_r : global_upper_ghost_par_lo_r, + e == 0 ? &app->global_lower_ghost[par_dir] : &app->global_upper_ghost[par_dir], 0, len_lo + ); + gkyl_range_shorten_from_below( + e == 0 ? global_lower_skin_par_up_r : global_upper_skin_par_up_r, + e == 0 ? &app->global_lower_skin[par_dir] : &app->global_upper_skin[par_dir], 0, len_up + ); + gkyl_range_shorten_from_below( + e == 0 ? global_lower_ghost_par_up_r : global_upper_ghost_par_up_r, + e == 0 ? &app->global_lower_ghost[par_dir] : &app->global_upper_ghost[par_dir], 0, len_up + ); + gkyl_range_shorten_from_above( + e == 0 ? local_lower_skin_par_lo_r : local_upper_skin_par_lo_r, + e == 0 ? &app->local_lower_skin[par_dir] : &app->local_upper_skin[par_dir], 0, len_lo + ); + gkyl_range_shorten_from_above( + e == 0 ? local_lower_ghost_par_lo_r : local_upper_ghost_par_lo_r, + e == 0 ? &app->local_lower_ghost[par_dir] : &app->local_upper_ghost[par_dir], 0, len_lo + ); + gkyl_range_shorten_from_below( + e == 0 ? local_lower_skin_par_up_r : local_upper_skin_par_up_r, + e == 0 ? &app->local_lower_skin[par_dir] : &app->local_upper_skin[par_dir], 0, len_up + ); + gkyl_range_shorten_from_below( + e == 0 ? local_lower_ghost_par_up_r : local_upper_ghost_par_up_r, + e == 0 ? &app->local_lower_ghost[par_dir] : &app->local_upper_ghost[par_dir], 0, len_up + ); } // Core range extended in the parallel direction. int ndim = app->cdim; int lower_bcdir_ext[ndim], upper_bcdir_ext[ndim]; - for (int i=0; iglobal_core.lower[i]; upper_bcdir_ext[i] = app->global_core.upper[i]; } lower_bcdir_ext[par_dir] = app->global_ext_core.lower[par_dir]; upper_bcdir_ext[par_dir] = app->global_ext_core.upper[par_dir]; - gkyl_sub_range_init(&app->global_par_ext_core, &app->global_ext_core, lower_bcdir_ext, upper_bcdir_ext); + gkyl_sub_range_init( + &app->global_par_ext_core, &app->global_ext_core, lower_bcdir_ext, upper_bcdir_ext + ); - for (int i=0; ilocal_core.lower[i]; upper_bcdir_ext[i] = app->local_core.upper[i]; } lower_bcdir_ext[par_dir] = app->local_ext_core.lower[par_dir]; upper_bcdir_ext[par_dir] = app->local_ext_core.upper[par_dir]; - gkyl_sub_range_init(&app->local_par_ext_core, &app->local_ext_core, lower_bcdir_ext, upper_bcdir_ext); + gkyl_sub_range_init( + &app->local_par_ext_core, &app->local_ext_core, lower_bcdir_ext, upper_bcdir_ext + ); } if (app->cdim == 3 && (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK || - (app->gk_geom->geometry_id == GKYL_GEOMETRY_MAPC2P && - app->gk_geom->parallel_lower_bc_shift_func && app->gk_geom->parallel_upper_bc_shift_func))) { + (app->gk_geom->geometry_id == GKYL_GEOMETRY_MAPC2P && + app->gk_geom->parallel_lower_bc_shift_func && + app->gk_geom->parallel_upper_bc_shift_func))) { // Create grid, range and basis on which the 1D shift will be defined. gkyl_rect_grid_init(&app->delta_ts_x_grid, 1, app->grid.lower, app->grid.upper, app->grid.cells); - struct gkyl_range *ts_s_rng = gk->geometry.has_LCFS? &app->local_core : &app->local; + struct gkyl_range *ts_s_rng = gk->geometry.has_LCFS ? &app->local_core : &app->local; gkyl_range_init(&app->delta_ts_x_rng, 1, ts_s_rng->lower, ts_s_rng->upper); gkyl_cart_modal_serendip(&app->delta_ts_x_basis, 1, app->basis.poly_order); // Here we define the deflated shift on the global/local range (not the @@ -654,21 +717,28 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) if (!gyrokinetic_str_ends_in_bnum(app->name)) { // Sync the numerical shift. - int par_dir = app->cdim-1; + int par_dir = app->cdim - 1; struct gkyl_array *delta_ts = app->gk_geom->geo_surf[par_dir].deltats; - gkyl_array_copy_range_to_range(delta_ts, delta_ts, - &app->local_upper_skin[par_dir], &app->local_upper_ghost[par_dir]); + gkyl_array_copy_range_to_range( + delta_ts, delta_ts, &app->local_upper_skin[par_dir], &app->local_upper_ghost[par_dir] + ); int shift_periodic_dirs[] = {par_dir}; int shift_num_periodic_dirs = 1; - gkyl_comm_array_per_sync(app->comm, &app->local, &app->local_ext, shift_num_periodic_dirs, - shift_periodic_dirs, delta_ts); + gkyl_comm_array_per_sync( + app->comm, &app->local, &app->local_ext, shift_num_periodic_dirs, shift_periodic_dirs, + delta_ts + ); struct gkyl_array *buffer = mkarr(app->use_gpu, delta_ts->ncomp, delta_ts->size); - gkyl_array_copy_range_to_range(buffer, delta_ts, &app->local_upper_skin[par_dir], &app->local_upper_ghost[par_dir]); + gkyl_array_copy_range_to_range( + buffer, delta_ts, &app->local_upper_skin[par_dir], &app->local_upper_ghost[par_dir] + ); gkyl_array_accumulate_range(delta_ts, -1.0, buffer, &app->local_upper_skin[par_dir]); - gkyl_array_copy_range_to_range(buffer, delta_ts, &app->local_lower_skin[par_dir], &app->local_lower_ghost[par_dir]); + gkyl_array_copy_range_to_range( + buffer, delta_ts, &app->local_lower_skin[par_dir], &app->local_lower_ghost[par_dir] + ); gkyl_array_accumulate_range(delta_ts, -1.0, buffer, &app->local_lower_skin[par_dir]); gkyl_array_release(buffer); @@ -683,90 +753,109 @@ gkyl_gyrokinetic_app_new_geom(struct gkyl_gk *gk) return app; } -static void -gyrokinetic_calc_field_enabled(gkyl_gyrokinetic_app* app, double tcurr, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]) +static void gyrokinetic_calc_field_enabled( + gkyl_gyrokinetic_app *app, double tcurr, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +) { struct timespec wtm = gkyl_wall_clock(); // Compute electrostatic potential from gyrokinetic Poisson's equation. gk_field_accumulate_rho_c(app, app->field, fin, bflux); // Compute biased wall potential if present and time-dependent. - // Note: biased wall potential use eval_on_nodes. + // Note: biased wall potential use eval_on_nodes. // so does copy to GPU every call if app->use_gpu = true. - if (app->field->phi_wall_lo_evolve || app->field->phi_wall_up_evolve) + if (app->field->phi_wall_lo_evolve || app->field->phi_wall_up_evolve) { gk_field_calc_phi_wall(app, app->field, tcurr); + } // Solve the field equation. gk_field_rhs(app, app->field); app->stat.field_tm += gkyl_time_diff_now_sec(wtm); } -static void -gyrokinetic_calc_field_disabled(gkyl_gyrokinetic_app* app, double tcurr, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]) +static void gyrokinetic_calc_field_disabled( + gkyl_gyrokinetic_app *app, double tcurr, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +) { // Do nothing. } -static void -gkyl_gyrokinetic_app_omegaH_init(gkyl_gyrokinetic_app *app) +static void gkyl_gyrokinetic_app_omegaH_init(gkyl_gyrokinetic_app *app) { // Compute the geometric and field-model dependent part of omega_H. // Each species computes its own omega_H as: // omega_H = q_e*sqrt(n_{s0}/m_s) * omegaH_gf // where // - n_{s0} is either a reference, average or max density. - // - omegaH_gf = (cmag/(jacobgeo*B^_\parallel))*kpar_max / + // - omegaH_gf = (cmag/(jacobgeo*B^_\parallel))*kpar_max / // min(sqrt(k_x^2*eps_xx+k_x*k_y*eps_xy+k_y^2*eps_yy+)). // and k_x,k_y,k_par are wavenumbers in computational space, and eps_ij is // the polarization weight in our field equation. - app->omegaH_gf = 1.0/DBL_MAX; + app->omegaH_gf = 1.0 / DBL_MAX; - if (!(app->field->gkfield_id == GKYL_GK_FIELD_BOLTZMANN || app->field->gkfield_id == GKYL_GK_FIELD_ADIABATIC)) { + if (!(app->field->gkfield_id == GKYL_GK_FIELD_BOLTZMANN || + app->field->gkfield_id == GKYL_GK_FIELD_ADIABATIC)) { // Compute parfac = (cmag/(jacobgeo*B^_\parallel))*kpar_max. struct gkyl_array *parfac = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - gkyl_dg_mul_op_range(&app->basis, 0, parfac, 0, app->gk_geom->geo_int.cmag, 0, app->gk_geom->geo_int.jacobtot_inv, &app->local); - double kpar_max = M_PI*(app->poly_order+1)/app->grid.dx[app->cdim-1]; + gkyl_dg_mul_op_range( + &app->basis, 0, parfac, 0, app->gk_geom->geo_int.cmag, 0, app->gk_geom->geo_int.jacobtot_inv, + &app->local + ); + double kpar_max = M_PI * (app->poly_order + 1) / app->grid.dx[app->cdim - 1]; gkyl_array_scale_range(parfac, kpar_max, &app->local); // Compute perpfac_inv = 1/sqrt(k_x^2*eps_xx+k_x*k_y*eps_xy+k_y^2*eps_yy+)). struct gkyl_array *perpfac = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - struct gkyl_array *perpfac_inv = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - double kx_min = M_PI/(app->grid.upper[0]-app->grid.lower[0]); - double kx_sq = app->cdim == 1? 1.0 : pow(kx_min,2); // kperp_sq included in epsilon for cdim=1. - gkyl_array_accumulate_offset_range(perpfac, kx_sq, app->field->epsilon, 0*app->basis.num_basis, &app->local); + struct gkyl_array *perpfac_inv = + mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); + double kx_min = M_PI / (app->grid.upper[0] - app->grid.lower[0]); + double kx_sq = app->cdim == 1 ? 1.0 : + pow(kx_min, 2); // kperp_sq included in epsilon for cdim=1. + gkyl_array_accumulate_offset_range( + perpfac, kx_sq, app->field->epsilon, 0 * app->basis.num_basis, &app->local + ); if (app->cdim > 2) { - double ky_min = M_PI/(app->grid.upper[1]-app->grid.lower[1]); - gkyl_array_accumulate_offset_range(perpfac, kx_min*ky_min, app->field->epsilon, 1*app->basis.num_basis, &app->local); - gkyl_array_accumulate_offset_range(perpfac, pow(ky_min,2), app->field->epsilon, 2*app->basis.num_basis, &app->local); + double ky_min = M_PI / (app->grid.upper[1] - app->grid.lower[1]); + gkyl_array_accumulate_offset_range( + perpfac, kx_min * ky_min, app->field->epsilon, 1 * app->basis.num_basis, &app->local + ); + gkyl_array_accumulate_offset_range( + perpfac, pow(ky_min, 2), app->field->epsilon, 2 * app->basis.num_basis, &app->local + ); } - gkyl_proj_powsqrt_on_basis* proj_sqrt = gkyl_proj_powsqrt_on_basis_new(&app->basis, app->poly_order+1, app->use_gpu); + gkyl_proj_powsqrt_on_basis *proj_sqrt = + gkyl_proj_powsqrt_on_basis_new(&app->basis, app->poly_order + 1, app->use_gpu); gkyl_proj_powsqrt_on_basis_advance(proj_sqrt, &app->local, -1.0, perpfac, perpfac_inv); gkyl_proj_powsqrt_on_basis_release(proj_sqrt); // Compute max(parfac*perpfac_inv) (using cell centers). - struct gkyl_array *omegaH_gf_grid = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - gkyl_dg_mul_op_range(&app->basis, 0, omegaH_gf_grid, 0, parfac, 0, perpfac_inv, &app->local); + struct gkyl_array *omegaH_gf_grid = + mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); + gkyl_dg_mul_op_range(&app->basis, 0, omegaH_gf_grid, 0, parfac, 0, perpfac_inv, &app->local); double *omegaH_gf_red; - if (app->use_gpu) - omegaH_gf_red = gkyl_cu_malloc(app->basis.num_basis*sizeof(double)); - else - omegaH_gf_red = gkyl_malloc(app->basis.num_basis*sizeof(double)); + if (app->use_gpu) { + omegaH_gf_red = gkyl_cu_malloc(app->basis.num_basis * sizeof(double)); + } else { + omegaH_gf_red = gkyl_malloc(app->basis.num_basis * sizeof(double)); + } gkyl_array_reduce_range(omegaH_gf_red, omegaH_gf_grid, GKYL_MAX, &app->local); - if (app->use_gpu) + if (app->use_gpu) { gkyl_cu_memcpy(&app->omegaH_gf, omegaH_gf_red, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { app->omegaH_gf = omegaH_gf_red[0]; - app->omegaH_gf *= 1.0/pow(sqrt(2.0),app->cdim); + } + app->omegaH_gf *= 1.0 / pow(sqrt(2.0), app->cdim); - if (app->use_gpu) + if (app->use_gpu) { gkyl_cu_free(omegaH_gf_red); - else + } else { gkyl_free(omegaH_gf_red); + } gkyl_array_release(omegaH_gf_grid); gkyl_array_release(perpfac_inv); gkyl_array_release(perpfac); @@ -787,20 +876,23 @@ gyrokinetic_post_positivity_quasineut_enabled(gkyl_gyrokinetic_app *app, struct // Enforce quasineutrality after applying positivity shift to charged species. gkyl_array_clear(app->ps_delta_m0_ions, 0.0); gkyl_array_clear(app->ps_delta_m0_elcs, 0.0); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { // Accumulate the shift density of all like-species: struct gk_species *gks = &app->species[i]; struct gk_positivity *pos = &gks->positivity; - if (pos->quasineut_rescale) + if (pos->quasineut_rescale) { gkyl_array_accumulate(pos->delta_m0s_tot, 1.0, pos->delta_m0); + } } // Rescale each species to enforce quasineutrality. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gks = &app->species[i]; struct gk_positivity *pos = &gks->positivity; if (pos->quasineut_rescale) { - gkyl_positivity_shift_gyrokinetic_quasineutrality_scale(pos->shift_op_gk, &app->local, &gks->local, - pos->delta_m0, pos->delta_m0s_tot, pos->delta_m0r_tot, gks->m0.marr, fout[i]); + gkyl_positivity_shift_gyrokinetic_quasineutrality_scale( + pos->shift_op_gk, &app->local, &gks->local, pos->delta_m0, pos->delta_m0s_tot, + pos->delta_m0r_tot, gks->m0.marr, fout[i] + ); gkyl_array_accumulate(pos->fbuffer_ptr, 1.0, fout[i]); } @@ -808,8 +900,7 @@ gyrokinetic_post_positivity_quasineut_enabled(gkyl_gyrokinetic_app *app, struct app->stat.pos_shift_quasineut_tm += gkyl_time_diff_now_sec(wst); } -void -gyrokinetic_post_positivity_quasineut_init(gkyl_gyrokinetic_app* app) +void gyrokinetic_post_positivity_quasineut_init(gkyl_gyrokinetic_app *app) { int num_quasineut_rescale = gk_species_positivity_num_species_in_quasineut(app); if (num_quasineut_rescale > 1) { @@ -819,19 +910,17 @@ gyrokinetic_post_positivity_quasineut_init(gkyl_gyrokinetic_app* app) // Needed before species_init because species store pointers to these. app->ps_delta_m0_ions = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); app->ps_delta_m0_elcs = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume); - + app->post_pos_quasineut_func = gyrokinetic_post_positivity_quasineut_enabled; } } -void -gyrokinetic_post_positivity_quasineut(gkyl_gyrokinetic_app *app, struct gkyl_array *fout[]) +void gyrokinetic_post_positivity_quasineut(gkyl_gyrokinetic_app *app, struct gkyl_array *fout[]) { app->post_pos_quasineut_func(app, fout); } -void -gyrokinetic_post_positivity_quasineut_release(gkyl_gyrokinetic_app* app) +void gyrokinetic_post_positivity_quasineut_release(gkyl_gyrokinetic_app *app) { if (app->post_positivity_quasineut) { gkyl_array_release(app->ps_delta_m0_ions); @@ -841,30 +930,32 @@ gyrokinetic_post_positivity_quasineut_release(gkyl_gyrokinetic_app* app) app->post_pos_quasineut_func = gyrokinetic_post_positivity_quasineut_disabled; } -void -gkyl_gyrokinetic_app_new_solver(struct gkyl_gk *gk, gkyl_gyrokinetic_app *app) +void gkyl_gyrokinetic_app_new_solver(struct gkyl_gk *gk, gkyl_gyrokinetic_app *app) { int ns = app->num_species = gk->num_species; int neuts = app->num_neut_species = gk->num_neut_species; // Allocate space to store species and neutral species objects - app->species = ns>0 ? gkyl_malloc(sizeof(struct gk_species[ns])) : 0; - app->neut_species = neuts>0 ? gkyl_malloc(sizeof(struct gk_neut_species[neuts])) : 0; + app->species = ns > 0 ? gkyl_malloc(sizeof(struct gk_species[ns])) : 0; + app->neut_species = neuts > 0 ? gkyl_malloc(sizeof(struct gk_neut_species[neuts])) : 0; // Copy input parameters for each species - for (int i=0; ispecies[i].info = gk->species[i]; + } - for (int i=0; ineut_species[i].info = gk->neut_species[i]; + } app->field = gk_field_new(gk, app); // Initialize field, even if we are skipping field updates. // Choose the function that updates the fields in time. - if (app->field->update_field) + if (app->field->update_field) { app->calc_field_func = gyrokinetic_calc_field_enabled; - else + } else { app->calc_field_func = gyrokinetic_calc_field_disabled; + } // Initialize the post-positivity quasineutrality enforcement. app->post_positivity_quasineut = false; @@ -872,14 +963,16 @@ gkyl_gyrokinetic_app_new_solver(struct gkyl_gk *gk, gkyl_gyrokinetic_app *app) gyrokinetic_post_positivity_quasineut_init(app); // Initialize each species. - for (int i=0; ispecies[i]); + } - for (int i=0; ineut_species[i]); + } // Initialize each species cross-collisions terms. - for (int i=0; ispecies[i]; // Initialize cross-species elastic collisions. @@ -899,44 +992,46 @@ gkyl_gyrokinetic_app_new_solver(struct gkyl_gk *gk, gkyl_gyrokinetic_app *app) gk_species_scaling_cross_init(app, gk_s, &gk_s->sca); } - for (int i=0; ineut_species[i]; + struct gk_neut_species *gkns = &app->neut_species[i]; gk_neut_species_react_cross_init(app, gkns, &gkns->react_neut); // Initialize cross-species part of the object that scales the species. gk_neut_species_scaling_cross_init(app, gkns, &gkns->sca); - + // Initialize wall emission terms. - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { if (gkns->bc_is_np[d]) { - if (gkns->lower_bc[d].type == GKYL_BC_GK_SPECIES_RECYCLE) + if (gkns->lower_bc[d].type == GKYL_BC_GK_SPECIES_RECYCLE) { gk_neut_species_recycle_cross_init(app, gkns, &gkns->bc_recycle_lo); - if (gkns->upper_bc[d].type == GKYL_BC_GK_SPECIES_RECYCLE) + } + if (gkns->upper_bc[d].type == GKYL_BC_GK_SPECIES_RECYCLE) { gk_neut_species_recycle_cross_init(app, gkns, &gkns->bc_recycle_up); + } } } } // Initialize source terms. Done here as sources may initialize // a boundary flux updater for their source species. - for (int i=0; ispecies[i], &app->species[i].src); } - for (int i=0; ineut_species[i], &app->neut_species[i].src); } // Use implicit BGK collisions if specified bool has_implicit_coll_scheme = false; - for (int i=0; ispecies[i].collisions.is_implicit){ + for (int i = 0; i < ns; ++i) { + if (gk->species[i].collisions.is_implicit) { has_implicit_coll_scheme = true; } } - for (int i=0; ineut_species[i].collisions.is_implicit){ + for (int i = 0; i < neuts; ++i) { + if (gk->neut_species[i].collisions.is_implicit) { has_implicit_coll_scheme = true; } } @@ -945,137 +1040,140 @@ gkyl_gyrokinetic_app_new_solver(struct gkyl_gk *gk, gkyl_gyrokinetic_app *app) app->eirene = gk_eirene_init(app, gk); // Set the appropriate update function for taking a single time step - // If we have implicit BGK collisions for either the gyrokinetic or neutral species, + // If we have implicit BGK collisions for either the gyrokinetic or neutral species, // we perform a first-order operator split and treat those terms implicitly. - // Otherwise, we default to an SSP-RK3 method. + // Otherwise, we default to an SSP-RK3 method. if (has_implicit_coll_scheme) { app->update_func = gyrokinetic_update_op_split; - } - else { + } else { app->update_func = gyrokinetic_update_ssp_rk3; } // Pre-compute time-independent factors in omega_H. - gkyl_gyrokinetic_app_omegaH_init(app); + gkyl_gyrokinetic_app_omegaH_init(app); // Initialize stat object. - app->stat = (struct gkyl_gyrokinetic_stat) { - .use_gpu = app->use_gpu, - .stage_2_dt_diff = { DBL_MAX, 0.0 }, - .stage_3_dt_diff = { DBL_MAX, 0.0 }, - }; + app->stat = (struct gkyl_gyrokinetic_stat + ){.use_gpu = app->use_gpu, .stage_2_dt_diff = {DBL_MAX, 0.0}, .stage_3_dt_diff = {DBL_MAX, 0.0}}; app->dts = gkyl_dynvec_new(GKYL_DOUBLE, 1); // Dynvector to store time steps. app->is_first_dt_write_call = true; } - -gkyl_gyrokinetic_app* -gkyl_gyrokinetic_app_new(struct gkyl_gk *gk) +gkyl_gyrokinetic_app *gkyl_gyrokinetic_app_new(struct gkyl_gk *gk) { - gkyl_gyrokinetic_app* app = gkyl_gyrokinetic_app_new_geom(gk); + gkyl_gyrokinetic_app *app = gkyl_gyrokinetic_app_new_geom(gk); gkyl_gyrokinetic_app_new_solver(gk, app); return app; } -void -gyrokinetic_calc_field(gkyl_gyrokinetic_app* app, double tcurr, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]) +void gyrokinetic_calc_field( + gkyl_gyrokinetic_app *app, double tcurr, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +) { app->calc_field_func(app, tcurr, fin, bflux); } -void -gyrokinetic_calc_field_and_apply_bc(gkyl_gyrokinetic_app* app, double tcurr, - struct gkyl_array *distf[], struct gkyl_array **bflux[], struct gkyl_array *distf_neut[]) +void gyrokinetic_calc_field_and_apply_bc( + gkyl_gyrokinetic_app *app, double tcurr, struct gkyl_array *distf[], struct gkyl_array **bflux[], + struct gkyl_array *distf_neut[] +) { // Compute fields and apply BCs. // Compute the field. // MF 2024/09/27/: Need the cast here for consistency. Fixing // this may require removing 'const' from a lot of places. - gyrokinetic_calc_field(app, tcurr, (const struct gkyl_array **) distf, bflux); + gyrokinetic_calc_field(app, tcurr, (const struct gkyl_array **)distf, bflux); // Apply boundary conditions. struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gk_species_apply_bc(app, &app->species[i], distf[i]); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gk_neut_species_apply_bc(app, &app->neut_species[i], distf_neut[i]); } app->stat.bc_tm += gkyl_time_diff_now_sec(wst); } -struct gk_species * -gk_find_species(const gkyl_gyrokinetic_app *app, const char *nm) +struct gk_species *gk_find_species(const gkyl_gyrokinetic_app *app, const char *nm) { - for (int i=0; inum_species; ++i) - if (strcmp(nm, app->species[i].info.name) == 0) + for (int i = 0; i < app->num_species; ++i) { + if (strcmp(nm, app->species[i].info.name) == 0) { return &app->species[i]; + } + } return 0; } -int -gk_find_species_idx(const gkyl_gyrokinetic_app *app, const char *nm) +int gk_find_species_idx(const gkyl_gyrokinetic_app *app, const char *nm) { - for (int i=0; inum_species; ++i) - if (strcmp(nm, app->species[i].info.name) == 0) + for (int i = 0; i < app->num_species; ++i) { + if (strcmp(nm, app->species[i].info.name) == 0) { return i; + } + } return -1; } -struct gk_neut_species * -gk_find_neut_species(const gkyl_gyrokinetic_app *app, const char *nm) +struct gk_neut_species *gk_find_neut_species(const gkyl_gyrokinetic_app *app, const char *nm) { - for (int i=0; inum_neut_species; ++i) - if (strcmp(nm, app->neut_species[i].info.name) == 0) + for (int i = 0; i < app->num_neut_species; ++i) { + if (strcmp(nm, app->neut_species[i].info.name) == 0) { return &app->neut_species[i]; + } + } return 0; } -int -gk_find_neut_species_idx(const gkyl_gyrokinetic_app *app, const char *nm) +int gk_find_neut_species_idx(const gkyl_gyrokinetic_app *app, const char *nm) { - for (int i=0; inum_neut_species; ++i) - if (strcmp(nm, app->neut_species[i].info.name) == 0) + for (int i = 0; i < app->num_neut_species; ++i) { + if (strcmp(nm, app->neut_species[i].info.name) == 0) { return i; + } + } return -1; } -void -gkyl_gyrokinetic_app_apply_ic(gkyl_gyrokinetic_app* app, double t0) +void gkyl_gyrokinetic_app_apply_ic(gkyl_gyrokinetic_app *app, double t0) { app->tcurr = t0; // Apply ICs that don't depend on other species. - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_app_apply_ic_species(app, i, t0); + } - for (int i=0; inum_neut_species; ++i) + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_app_apply_ic_neut_species(app, i, t0); + } // Apply ICs that depend on other species. - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_app_apply_ic_cross_species(app, i, t0); + } - for (int i=0; inum_neut_species; ++i) + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_app_apply_ic_cross_neut_species(app, i, t0); + } // Compute the fields and apply BCs. struct gkyl_array *distf[app->num_species]; struct gkyl_array **bflux[app->num_species]; struct gkyl_array *distf_neut[app->num_neut_species]; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { distf[i] = app->species[i].f; bflux[i] = app->species[i].bflux.f; } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { distf_neut[i] = app->neut_species[i].f; } if (app->field->calc_init_field) { if (app->field->gkfield_id == GKYL_GK_FIELD_BOLTZMANN) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *s = &app->species[i]; // Compute the collisionless flux so we can compute the initial boundary flux. @@ -1085,29 +1183,28 @@ gkyl_gyrokinetic_app_apply_ic(gkyl_gyrokinetic_app* app, double t0) gk_species_bflux_rhs(app, &s->bflux, distf[i], distf[i]); // Compute moments of the boundary fluxes. gk_species_bflux_calc_moms(app, &s->bflux, distf[i], bflux[i]); - } } - if (app->field->info.init_from_file.type == 0 && app->field->info.init_field_profile == 0) + if (app->field->info.init_from_file.type == 0 && app->field->info.init_field_profile == 0) { // Compute the field. // MF 2024/09/27/: Need the cast here for consistency. Fixing // this may require removing 'const' from a lot of places. - gyrokinetic_calc_field_enabled(app, t0, (const struct gkyl_array **) distf, bflux); - else { - if (app->field->info.init_field_profile == 0) + gyrokinetic_calc_field_enabled(app, t0, (const struct gkyl_array **)distf, bflux); + } else { + if (app->field->info.init_field_profile == 0) { // Read the field. gk_field_file_import_init(app, app->field->info.init_from_file); - else + } else { // Project the field. gk_field_project_init(app); + } } - } // Compute the phase-space advection speeds and boundary fluxes as t=0 // diagnostics and emission BCs may need them. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gks = &app->species[i]; gk_species_collisionless_flux(app, gks, &gks->collisionless, distf[i]); gk_species_bflux_rhs(app, &gks->bflux, gks->f, gks->f); @@ -1115,18 +1212,17 @@ gkyl_gyrokinetic_app_apply_ic(gkyl_gyrokinetic_app* app, double t0) } // Apply boundary conditions. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gk_species_apply_bc(app, &app->species[i], distf[i]); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { if (!app->neut_species[i].info.is_static) { gk_neut_species_apply_bc(app, &app->neut_species[i], distf_neut[i]); } } } -void -gkyl_gyrokinetic_app_apply_ic_species(gkyl_gyrokinetic_app* app, int sidx, double t0) +void gkyl_gyrokinetic_app_apply_ic_species(gkyl_gyrokinetic_app *app, int sidx, double t0) { assert(sidx < app->num_species); @@ -1138,8 +1234,7 @@ gkyl_gyrokinetic_app_apply_ic_species(gkyl_gyrokinetic_app* app, int sidx, doubl app->stat.init_species_tm += gkyl_time_diff_now_sec(wtm); } -void -gkyl_gyrokinetic_app_apply_ic_neut_species(gkyl_gyrokinetic_app* app, int sidx, double t0) +void gkyl_gyrokinetic_app_apply_ic_neut_species(gkyl_gyrokinetic_app *app, int sidx, double t0) { assert(sidx < app->num_neut_species); @@ -1151,8 +1246,7 @@ gkyl_gyrokinetic_app_apply_ic_neut_species(gkyl_gyrokinetic_app* app, int sidx, app->stat.init_neut_species_tm += gkyl_time_diff_now_sec(wtm); } -void -gkyl_gyrokinetic_app_apply_ic_cross_species(gkyl_gyrokinetic_app* app, int sidx, double t0) +void gkyl_gyrokinetic_app_apply_ic_cross_species(gkyl_gyrokinetic_app *app, int sidx, double t0) { assert(sidx < app->num_species); @@ -1164,8 +1258,7 @@ gkyl_gyrokinetic_app_apply_ic_cross_species(gkyl_gyrokinetic_app* app, int sidx, app->stat.init_species_tm += gkyl_time_diff_now_sec(wtm); } -void -gkyl_gyrokinetic_app_apply_ic_cross_neut_species(gkyl_gyrokinetic_app* app, int sidx, double t0) +void gkyl_gyrokinetic_app_apply_ic_cross_neut_species(gkyl_gyrokinetic_app *app, int sidx, double t0) { assert(sidx < app->num_neut_species); @@ -1179,67 +1272,76 @@ gkyl_gyrokinetic_app_apply_ic_cross_neut_species(gkyl_gyrokinetic_app* app, int // // ............. Geometry outputs ............... // -// -static void -gyrokinetic_app_geometry_copy_and_write(gkyl_gyrokinetic_app* app, struct gkyl_array *arr, - struct gkyl_array *arr_host, char *varNm, const char *description) +// +static void gyrokinetic_app_geometry_copy_and_write( + gkyl_gyrokinetic_app *app, struct gkyl_array *arr, struct gkyl_array *arr_host, char *varNm, + const char *description +) { gkyl_array_copy(arr_host, arr); const char *fmt = "%s-%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, varNm); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, varNm); struct gkyl_msgpack_map_elem desc_elem[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = (char*)description } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = (char *)description} }; int io_meta_len[] = {app->io_meta_dg_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {app->io_meta_dg, app->gk_geom->io_meta_basic, desc_elem}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + app->io_meta_dg, app->gk_geom->io_meta_basic, desc_elem + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, arr_host, fileNm); gkyl_msgpack_data_release(mt); } -static void -gyrokinetic_app_geometry_copy_and_write_surf(gkyl_gyrokinetic_app* app, struct gkyl_array *arr, - struct gkyl_array *arr_host, struct gkyl_array *arr_host_doubled, char *varNm, int dir, const char *description) +static void gyrokinetic_app_geometry_copy_and_write_surf( + gkyl_gyrokinetic_app *app, struct gkyl_array *arr, struct gkyl_array *arr_host, + struct gkyl_array *arr_host_doubled, char *varNm, int dir, const char *description +) { gkyl_array_copy(arr_host, arr); gkyl_array_set_offset(arr_host_doubled, 1.0, arr_host, 0); - gkyl_array_copy_range_to_range(arr_host, arr_host, &app->local_upper_skin[dir], &app->local_upper_ghost[dir]); + gkyl_array_copy_range_to_range( + arr_host, arr_host, &app->local_upper_skin[dir], &app->local_upper_ghost[dir] + ); gkyl_array_set_offset(arr_host_doubled, 1.0, arr_host, arr_host->ncomp); const char *fmt = "%s-geo_surf%d_%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, dir, varNm); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, dir, varNm); struct gkyl_msgpack_map_elem desc_elem[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = (char*)description } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = (char *)description} }; int io_meta_len[] = {app->io_meta_dg_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {app->io_meta_dg, app->gk_geom->io_meta_basic, desc_elem}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + app->io_meta_dg, app->gk_geom->io_meta_basic, desc_elem + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, arr_host_doubled, fileNm); gkyl_msgpack_data_release(mt); } -static void -gyrokinetic_app_write_ts_shift_mapc2p(struct gkyl_gyrokinetic_app *app) +static void gyrokinetic_app_write_ts_shift_mapc2p(struct gkyl_gyrokinetic_app *app) { // Write the discretized shift (for TS BCs) to file for mapc2p geo. - int par_dir = app->cdim-1; + int par_dir = app->cdim - 1; int comm_rank, comm_size; gkyl_comm_get_rank(app->comm, &comm_rank); gkyl_comm_get_size(app->comm, &comm_size); - const char *vars[] = {"x","y","z"}; - const char *edge[] = {"lower","upper"}; + const char *vars[] = {"x", "y", "z"}; + const char *edge[] = {"lower", "upper"}; const char *fmt = "%s-bc_%s%s_twistshift.gkyl"; for (int eI = 0; eI < 2; eI++) { @@ -1249,21 +1351,24 @@ gyrokinetic_app_write_ts_shift_mapc2p(struct gkyl_gyrokinetic_app *app) .bc_dir = par_dir, .shift_dir = 1, // y shift. .shear_dir = 0, // shift varies with x. - .edge = eI == 0? GKYL_LOWER_EDGE : GKYL_UPPER_EDGE, + .edge = eI == 0 ? GKYL_LOWER_EDGE : GKYL_UPPER_EDGE, .cdim = app->cdim, .bcdir_ext_update_r = &app->global_par_ext, .num_ghost = ghost, // one ghost per config direction .basis = &app->basis, .grid = &app->grid, - .shift_func = eI == 0? app->gk_geom->parallel_lower_bc_shift_func : app->gk_geom->parallel_upper_bc_shift_func, - .shift_func_ctx = eI == 0? app->gk_geom->parallel_lower_bc_shift_ctx : app->gk_geom->parallel_upper_bc_shift_ctx, - .use_gpu = app->use_gpu, + .shift_func = eI == 0 ? app->gk_geom->parallel_lower_bc_shift_func : + app->gk_geom->parallel_upper_bc_shift_func, + .shift_func_ctx = eI == 0 ? app->gk_geom->parallel_lower_bc_shift_ctx : + app->gk_geom->parallel_upper_bc_shift_ctx, + .use_gpu = app->use_gpu }; struct gkyl_bc_twistshift *bc_ts_op = gkyl_bc_twistshift_inew(&ts_inp); - struct gkyl_array *delta_ts_x = eI == 0? app->delta_ts_x_lo : app->delta_ts_x_up; - delta_ts_x = gkyl_bc_twistshift_get_shift_objects(bc_ts_op, - &app->delta_ts_x_grid, &app->delta_ts_x_rng, &app->delta_ts_x_basis); + struct gkyl_array *delta_ts_x = eI == 0 ? app->delta_ts_x_lo : app->delta_ts_x_up; + delta_ts_x = gkyl_bc_twistshift_get_shift_objects( + bc_ts_op, &app->delta_ts_x_grid, &app->delta_ts_x_rng, &app->delta_ts_x_basis + ); bool has_LCFS = app->gk_geom->has_LCFS; struct gkyl_rect_grid delta_ts_x_grid_core; @@ -1275,35 +1380,39 @@ gyrokinetic_app_write_ts_shift_mapc2p(struct gkyl_gyrokinetic_app *app) if (app->gk_geom->geqdsk_sign_convention == 0) { // x increases towards SOL. lower[0] = app->delta_ts_x_grid.lower[0]; - upper[0] = app->delta_ts_x_grid.lower[0] + app->delta_ts_x_grid.dx[0]*cells[0]; + upper[0] = app->delta_ts_x_grid.lower[0] + app->delta_ts_x_grid.dx[0] * cells[0]; gkyl_rect_grid_init(&delta_ts_x_grid_core, app->delta_ts_x_grid.ndim, lower, upper, cells); - } - else { + } else { // x increases towards SOL. - lower[0] = app->delta_ts_x_grid.upper[0] - app->delta_ts_x_grid.dx[0]*cells[0]; + lower[0] = app->delta_ts_x_grid.upper[0] - app->delta_ts_x_grid.dx[0] * cells[0]; upper[0] = app->delta_ts_x_grid.upper[0]; gkyl_rect_grid_init(&delta_ts_x_grid_core, app->delta_ts_x_grid.ndim, lower, upper, cells); } - } - else + } else { delta_ts_x_grid_core = app->delta_ts_x_grid; + } // Package metadata for shift file. struct gkyl_msgpack_map_elem io_meta_shift_dg[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = app->delta_ts_x_basis.poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->delta_ts_x_basis.id } + {.key = "poly_order", + .elem_type = GKYL_MP_UNSIGNED_INT, + .uval = app->delta_ts_x_basis.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->delta_ts_x_basis.id} }; - int io_meta_shift_dg_len = sizeof(io_meta_shift_dg)/sizeof(io_meta_shift_dg[0]); + int io_meta_shift_dg_len = sizeof(io_meta_shift_dg) / sizeof(io_meta_shift_dg[0]); int io_meta_shift_len[] = {app->io_meta_basic_len, io_meta_shift_dg_len}; - const struct gkyl_msgpack_map_elem* io_meta_shift[] = {app->io_meta_basic, io_meta_shift_dg}; - struct gkyl_msgpack_data *mt_shift = gkyl_msgpack_create_union(sizeof(io_meta_shift_len)/sizeof(int), - io_meta_shift_len, io_meta_shift); + const struct gkyl_msgpack_map_elem *io_meta_shift[] = {app->io_meta_basic, io_meta_shift_dg}; + struct gkyl_msgpack_data *mt_shift = gkyl_msgpack_create_union( + sizeof(io_meta_shift_len) / sizeof(int), io_meta_shift_len, io_meta_shift + ); - if ((eI == 0 && comm_rank == 0) || (eI == 1 && comm_rank == comm_size-1)) { + if ((eI == 0 && comm_rank == 0) || (eI == 1 && comm_rank == comm_size - 1)) { int sz = gkyl_calc_strlen(fmt, app->name, vars[par_dir], edge[eI]); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow sprintf(fileNm, fmt, app->name, vars[par_dir], edge[eI]); - gkyl_grid_sub_array_write(&delta_ts_x_grid_core, &app->delta_ts_x_rng, mt_shift, delta_ts_x, fileNm); + gkyl_grid_sub_array_write( + &delta_ts_x_grid_core, &app->delta_ts_x_rng, mt_shift, delta_ts_x, fileNm + ); } gkyl_array_release(delta_ts_x); @@ -1312,35 +1421,41 @@ gyrokinetic_app_write_ts_shift_mapc2p(struct gkyl_gyrokinetic_app *app) } } -void -gyrokinetic_app_write_ts_shift(gkyl_gyrokinetic_app* app) +void gyrokinetic_app_write_ts_shift(gkyl_gyrokinetic_app *app) { - int par_dir = app->cdim-1; + int par_dir = app->cdim - 1; - if (app->cdim < 3) + if (app->cdim < 3) { return; // Nothing to write. + } if (app->gk_geom->geometry_id == GKYL_GEOMETRY_MAPC2P && - (app->gk_geom->parallel_lower_bc_shift_func && app->gk_geom->parallel_upper_bc_shift_func)) + (app->gk_geom->parallel_lower_bc_shift_func && app->gk_geom->parallel_upper_bc_shift_func)) { gyrokinetic_app_write_ts_shift_mapc2p(app); - else if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) { - int comm_rank, comm_size;; + } else if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) { + int comm_rank, comm_size; + ; gkyl_comm_get_rank(app->comm, &comm_rank); gkyl_comm_get_size(app->comm, &comm_size); // Write the shift for TS BCs. struct gkyl_msgpack_map_elem io_meta_x[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = app->delta_ts_x_basis.poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->delta_ts_x_basis.id } + {.key = "poly_order", + .elem_type = GKYL_MP_UNSIGNED_INT, + .uval = app->delta_ts_x_basis.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = app->delta_ts_x_basis.id} }; - int io_meta_x_len = sizeof(io_meta_x)/sizeof(io_meta_x[0]); + int io_meta_x_len = sizeof(io_meta_x) / sizeof(io_meta_x[0]); int io_meta_ts_len[] = {app->io_meta_basic_len, io_meta_x_len, app->gk_geom->io_meta_basic_len}; - const struct gkyl_msgpack_map_elem* io_meta_ts[] = {app->io_meta_basic, io_meta_x, app->gk_geom->io_meta_basic}; - struct gkyl_msgpack_data *mt_x = gkyl_msgpack_create_union(sizeof(io_meta_ts_len)/sizeof(int), io_meta_ts_len, io_meta_ts); + const struct gkyl_msgpack_map_elem *io_meta_ts[] = { + app->io_meta_basic, io_meta_x, app->gk_geom->io_meta_basic + }; + struct gkyl_msgpack_data *mt_x = + gkyl_msgpack_create_union(sizeof(io_meta_ts_len) / sizeof(int), io_meta_ts_len, io_meta_ts); - const char *vars[] = {"x","y","z"}; - const char *edge[] = {"lower","upper"}; + const char *vars[] = {"x", "y", "z"}; + const char *edge[] = {"lower", "upper"}; const char *fmt = "%s-bc_%s%s_twistshift.gkyl"; bool has_LCFS = app->gk_geom->has_LCFS; @@ -1353,166 +1468,267 @@ gyrokinetic_app_write_ts_shift(gkyl_gyrokinetic_app* app) if (app->gk_geom->geqdsk_sign_convention == 0) { // x increases towards SOL. lower[0] = app->delta_ts_x_grid.lower[0]; - upper[0] = app->delta_ts_x_grid.lower[0] + app->delta_ts_x_grid.dx[0]*cells[0]; + upper[0] = app->delta_ts_x_grid.lower[0] + app->delta_ts_x_grid.dx[0] * cells[0]; gkyl_rect_grid_init(&delta_ts_x_grid_core, app->delta_ts_x_grid.ndim, lower, upper, cells); - } - else { + } else { // x increases towards SOL. - lower[0] = app->delta_ts_x_grid.upper[0] - app->delta_ts_x_grid.dx[0]*cells[0]; + lower[0] = app->delta_ts_x_grid.upper[0] - app->delta_ts_x_grid.dx[0] * cells[0]; upper[0] = app->delta_ts_x_grid.upper[0]; gkyl_rect_grid_init(&delta_ts_x_grid_core, app->delta_ts_x_grid.ndim, lower, upper, cells); } - } - else + } else { delta_ts_x_grid_core = app->delta_ts_x_grid; + } if (comm_rank == 0) { int sz = gkyl_calc_strlen(fmt, app->name, vars[par_dir], edge[0]); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow sprintf(fileNm, fmt, app->name, vars[par_dir], edge[0]); - gkyl_grid_sub_array_write(&delta_ts_x_grid_core, &app->delta_ts_x_rng, mt_x, app->delta_ts_x_lo, fileNm); + gkyl_grid_sub_array_write( + &delta_ts_x_grid_core, &app->delta_ts_x_rng, mt_x, app->delta_ts_x_lo, fileNm + ); } - if (comm_rank == comm_size-1) { + if (comm_rank == comm_size - 1) { int sz = gkyl_calc_strlen(fmt, app->name, vars[par_dir], edge[1]); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow sprintf(fileNm, fmt, app->name, vars[par_dir], edge[1]); - gkyl_grid_sub_array_write(&delta_ts_x_grid_core, &app->delta_ts_x_rng, mt_x, app->delta_ts_x_up, fileNm); + gkyl_grid_sub_array_write( + &delta_ts_x_grid_core, &app->delta_ts_x_rng, mt_x, app->delta_ts_x_up, fileNm + ); } gkyl_msgpack_data_release(mt_x); } - } -void -gkyl_gyrokinetic_app_write_geometry(gkyl_gyrokinetic_app* app, struct gkyl_gk_geometry_inp *geometry_inp) +void gkyl_gyrokinetic_app_write_geometry( + gkyl_gyrokinetic_app *app, struct gkyl_gk_geometry_inp *geometry_inp +) { int rank; gkyl_comm_get_rank(app->comm, &rank); if (rank == 0 && geometry_inp->geometry_id == GKYL_GEOMETRY_TOKAMAK) { - if ((!app->is_multib) || (app->is_multib && gyrokinetic_str_ends_in_b0(app->name))) + if ((!app->is_multib) || (app->is_multib && gyrokinetic_str_ends_in_b0(app->name))) { gkyl_gk_geometry_write_efit(geometry_inp, app->io_meta_basic, app->io_meta_basic_len); + } } // Gather geo into a global array - struct gkyl_array* arr_ho1 = mkarr(false, app->basis.num_basis, app->local_ext.volume); - struct gkyl_array* arr_hocdim = mkarr(false, app->cdim*app->basis.num_basis, app->local_ext.volume); - struct gkyl_array* arr_ho3 = mkarr(false, 3*app->basis.num_basis, app->local_ext.volume); - struct gkyl_array* arr_ho6 = mkarr(false, 6*app->basis.num_basis, app->local_ext.volume); - struct gkyl_array* arr_ho9 = mkarr(false, 9*app->basis.num_basis, app->local_ext.volume); - - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_corn.mc2p , arr_ho3, "geo_corn_mapc2p" , - "Coord map: 3x computational to physical."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_corn.mc2nu_pos, arr_ho3, "geo_corn_mc2nu_pos", - "Coord map: 3x computational to non-uniform position. "); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_corn.bmag , arr_ho1, "geo_corn_bmag" , - "Magnetic field magnitude. "); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_corn.bmag_inv , arr_ho1, "geo_corn_bmag_inv" , - "Reciprocal magnetic field magnitude."); + struct gkyl_array *arr_ho1 = mkarr(false, app->basis.num_basis, app->local_ext.volume); + struct gkyl_array *arr_hocdim = + mkarr(false, app->cdim * app->basis.num_basis, app->local_ext.volume); + struct gkyl_array *arr_ho3 = mkarr(false, 3 * app->basis.num_basis, app->local_ext.volume); + struct gkyl_array *arr_ho6 = mkarr(false, 6 * app->basis.num_basis, app->local_ext.volume); + struct gkyl_array *arr_ho9 = mkarr(false, 9 * app->basis.num_basis, app->local_ext.volume); + + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_corn.mc2p, arr_ho3, "geo_corn_mapc2p", + "Coord map: 3x computational to physical." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_corn.mc2nu_pos, arr_ho3, "geo_corn_mc2nu_pos", + "Coord map: 3x computational to non-uniform position. " + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_corn.bmag, arr_ho1, "geo_corn_bmag", "Magnetic field magnitude. " + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_corn.bmag_inv, arr_ho1, "geo_corn_bmag_inv", + "Reciprocal magnetic field magnitude." + ); if (app->cdim < 3) { - if (geometry_inp->geometry_id == GKYL_GEOMETRY_MIRROR || geometry_inp->geometry_id == GKYL_GEOMETRY_TOKAMAK) - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_corn.mc2p_deflated, arr_hocdim, "geo_corn_mapc2p_deflated", - "Coord map: deflated computational to physical. "); - - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_corn.mc2nu_pos_deflated, arr_hocdim, "geo_corn_mc2nu_pos_deflated", - "Coord map: deflated computational to non-uniform position."); - } - - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.mc2p , arr_ho3, "geo_int_mapc2p", - "Coord map: computational to physical."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.bmag , arr_ho1, "geo_int_bmag", - "Magnetic field magnitude."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.g_ij , arr_ho6, "geo_int_g_ij", - "Covariant metric tensor."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.g_ij_neut , arr_ho6, "geo_int_g_ij_neut", - "Covariant metric tensor for neutral species."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.dxdz , arr_ho9, "geo_int_dxdz", - "Cartesian components of tangent vectors."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.dzdx , arr_ho9, "geo_int_dzdx", - "Cartesian components of dual vectors."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.normals , arr_ho9, "geo_int_normals", - "Cartesian components of normal vectors."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.jacobgeo , arr_ho1, "geo_int_jacobgeo", - "Conf-space Jacobian."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.jacobgeo_inv , arr_ho1, "geo_int_jacobgeo_inv", - "Reciprocal of conf-space Jacobian."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.gij , arr_ho6, "geo_int_gij", - "Contravariant metric tensor."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.gij_neut , arr_ho6, "geo_int_gij_neut", - "Contravariant metric tensor for neutral species."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.b_i , arr_ho3, "geo_int_b_i", - "Covariant components of the magnetic unit vector."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.bcart , arr_ho3, "geo_int_bcart", - "Cartesian components of the magnetic unit vector."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.cmag , arr_ho1, "geo_int_cmag", - "Ratio of (Clebsch) magnetic field to the volume element."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.jacobtot , arr_ho1, "geo_int_jacobtot", - "Conf-space Jacobian times guiding center Jacobian."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.jacobtot_inv , arr_ho1, "geo_int_jacobtot_inv", - "Reciprocal of jacobtot."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.gxxj , arr_ho1, "geo_int_gxxj", - "Contravariant metric xx component times conf-space Jacobian."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.gxyj , arr_ho1, "geo_int_gxyj", - "Contravariant metric xy component times conf-space Jacobian."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.gyyj , arr_ho1, "geo_int_gyyj", - "Contravariant metric yy component times conf-space Jacobian."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.gxzj , arr_ho1, "geo_int_gxzj", - "Contravariant metric xz component times conf-space Jacobian."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.eps2 , arr_ho1, "geo_int_eps2", - "Polarization weight quasineutrality equation."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.qprofile , arr_ho1, "geo_int_qprofile", - "Safety factor."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.rtg33inv , arr_ho1, "geo_int_rtg33inv", - "Reciprocal square root of the zz covariant metric component."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.dualcurlbhatoverB, arr_ho3, "geo_int_dualcurlbhatoverB", - "Contravariant component of curl of the B-field unit vector divided by bmag."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.dualcurlbhat , arr_ho3, "geo_int_dualcurlbhat", - "Contravariant component of curl of the B-field unit vector."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.bioverJB , arr_ho3, "geo_int_bioverJB", - "Covariant components of magnetic unit vector divided by conf-space Jacobian and bmag."); - gyrokinetic_app_geometry_copy_and_write(app, app->gk_geom->geo_int.B3 , arr_ho1, "geo_int_B3", - "Contravariant z component of magnetic field. "); + if (geometry_inp->geometry_id == GKYL_GEOMETRY_MIRROR || + geometry_inp->geometry_id == GKYL_GEOMETRY_TOKAMAK) { + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_corn.mc2p_deflated, arr_hocdim, "geo_corn_mapc2p_deflated", + "Coord map: deflated computational to physical. " + ); + } + + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_corn.mc2nu_pos_deflated, arr_hocdim, "geo_corn_mc2nu_pos_deflated", + "Coord map: deflated computational to non-uniform position." + ); + } + + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.mc2p, arr_ho3, "geo_int_mapc2p", + "Coord map: computational to physical." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.bmag, arr_ho1, "geo_int_bmag", "Magnetic field magnitude." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.g_ij, arr_ho6, "geo_int_g_ij", "Covariant metric tensor." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.g_ij_neut, arr_ho6, "geo_int_g_ij_neut", + "Covariant metric tensor for neutral species." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.dxdz, arr_ho9, "geo_int_dxdz", + "Cartesian components of tangent vectors." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.dzdx, arr_ho9, "geo_int_dzdx", + "Cartesian components of dual vectors." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.normals, arr_ho9, "geo_int_normals", + "Cartesian components of normal vectors." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.jacobgeo, arr_ho1, "geo_int_jacobgeo", "Conf-space Jacobian." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.jacobgeo_inv, arr_ho1, "geo_int_jacobgeo_inv", + "Reciprocal of conf-space Jacobian." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.gij, arr_ho6, "geo_int_gij", "Contravariant metric tensor." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.gij_neut, arr_ho6, "geo_int_gij_neut", + "Contravariant metric tensor for neutral species." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.b_i, arr_ho3, "geo_int_b_i", + "Covariant components of the magnetic unit vector." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.bcart, arr_ho3, "geo_int_bcart", + "Cartesian components of the magnetic unit vector." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.cmag, arr_ho1, "geo_int_cmag", + "Ratio of (Clebsch) magnetic field to the volume element." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.jacobtot, arr_ho1, "geo_int_jacobtot", + "Conf-space Jacobian times guiding center Jacobian." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.jacobtot_inv, arr_ho1, "geo_int_jacobtot_inv", + "Reciprocal of jacobtot." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.gxxj, arr_ho1, "geo_int_gxxj", + "Contravariant metric xx component times conf-space Jacobian." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.gxyj, arr_ho1, "geo_int_gxyj", + "Contravariant metric xy component times conf-space Jacobian." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.gyyj, arr_ho1, "geo_int_gyyj", + "Contravariant metric yy component times conf-space Jacobian." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.gxzj, arr_ho1, "geo_int_gxzj", + "Contravariant metric xz component times conf-space Jacobian." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.eps2, arr_ho1, "geo_int_eps2", + "Polarization weight quasineutrality equation." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.qprofile, arr_ho1, "geo_int_qprofile", "Safety factor." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.rtg33inv, arr_ho1, "geo_int_rtg33inv", + "Reciprocal square root of the zz covariant metric component." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.dualcurlbhatoverB, arr_ho3, "geo_int_dualcurlbhatoverB", + "Contravariant component of curl of the B-field unit vector divided by bmag." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.dualcurlbhat, arr_ho3, "geo_int_dualcurlbhat", + "Contravariant component of curl of the B-field unit vector." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.bioverJB, arr_ho3, "geo_int_bioverJB", + "Covariant components of magnetic unit vector divided by conf-space Jacobian and bmag." + ); + gyrokinetic_app_geometry_copy_and_write( + app, app->gk_geom->geo_int.B3, arr_ho1, "geo_int_B3", + "Contravariant z component of magnetic field. " + ); // Write surface quantities - struct gkyl_array* arr_surf_ho1 = mkarr(false, app->gk_geom->num_surf_basis, app->local_ext.volume); - struct gkyl_array* arr_surf_ho2 = mkarr(false, 2*app->gk_geom->num_surf_basis, app->local_ext.volume); - struct gkyl_array* arr_surf_ho3 = mkarr(false, 3*app->gk_geom->num_surf_basis, app->local_ext.volume); - struct gkyl_array* arr_surf_ho6 = mkarr(false, 6*app->gk_geom->num_surf_basis, app->local_ext.volume); - struct gkyl_array* arr_surf_ho9 = mkarr(false, 9*app->gk_geom->num_surf_basis, app->local_ext.volume); - struct gkyl_array* arr_surf_ho18 = mkarr(false, 18*app->gk_geom->num_surf_basis, app->local_ext.volume); - for (int dir = 0; dircdim; dir++ ) { - gyrokinetic_app_geometry_copy_and_write_surf(app, app->gk_geom->geo_surf[dir].jacobgeo , arr_surf_ho1, arr_surf_ho2 , "jacobgeo", dir, - "Conf-space Jacobian."); - gyrokinetic_app_geometry_copy_and_write_surf(app, app->gk_geom->geo_surf[dir].jacobtot_inv, arr_surf_ho1, arr_surf_ho2 , "jacobtot_inv", dir, - "Reciprocal of conf-space Jacobian."); - gyrokinetic_app_geometry_copy_and_write_surf(app, app->gk_geom->geo_surf[dir].b_i , arr_surf_ho3, arr_surf_ho6 , "b_i", dir, - "Covariant components of the magnetic unit vector."); - gyrokinetic_app_geometry_copy_and_write_surf(app, app->gk_geom->geo_surf[dir].cmag , arr_surf_ho1, arr_surf_ho2 , "cmag", dir, - "Ratio of (Clebsch) magnetic field to the volume element."); - gyrokinetic_app_geometry_copy_and_write_surf(app, app->gk_geom->geo_surf[dir].bmag , arr_surf_ho1, arr_surf_ho2 , "bmag", dir, - "Magnetic field magnitude."); - gyrokinetic_app_geometry_copy_and_write_surf(app, app->gk_geom->geo_surf[dir].B3 , arr_surf_ho1, arr_surf_ho2 , "B3", dir, - "Contravariant z component of the magnetic field."); - gyrokinetic_app_geometry_copy_and_write_surf(app, app->gk_geom->geo_surf[dir].normcurlbhat, arr_surf_ho1, arr_surf_ho2 , "normcurlbhat", dir, - "Normal component of the curl of the magnetic unit vector. "); - gyrokinetic_app_geometry_copy_and_write_surf(app, app->gk_geom->geo_surf[dir].normals , arr_surf_ho9, arr_surf_ho18, "normals", dir, - "Unit normal vectors. "); - gyrokinetic_app_geometry_copy_and_write_surf(app, app->gk_geom->geo_surf[dir].lenr , arr_surf_ho1, arr_surf_ho2 , "lenr", dir, - "Length ratios for coordinate surface integrals. "); - gyrokinetic_app_geometry_copy_and_write_surf(app, app->gk_geom->geo_surf[dir].bimpactangle, arr_surf_ho1, arr_surf_ho2 , "bimpactangle", dir, - "Impact angle of the magnetic field."); - gyrokinetic_app_geometry_copy_and_write_surf(app, app->gk_geom->geo_surf[dir].deltats , arr_surf_ho1, arr_surf_ho2 , "deltats" , dir, - "Shift in binormal direction relative to y=varphi."); + struct gkyl_array *arr_surf_ho1 = + mkarr(false, app->gk_geom->num_surf_basis, app->local_ext.volume); + struct gkyl_array *arr_surf_ho2 = + mkarr(false, 2 * app->gk_geom->num_surf_basis, app->local_ext.volume); + struct gkyl_array *arr_surf_ho3 = + mkarr(false, 3 * app->gk_geom->num_surf_basis, app->local_ext.volume); + struct gkyl_array *arr_surf_ho6 = + mkarr(false, 6 * app->gk_geom->num_surf_basis, app->local_ext.volume); + struct gkyl_array *arr_surf_ho9 = + mkarr(false, 9 * app->gk_geom->num_surf_basis, app->local_ext.volume); + struct gkyl_array *arr_surf_ho18 = + mkarr(false, 18 * app->gk_geom->num_surf_basis, app->local_ext.volume); + for (int dir = 0; dir < app->cdim; dir++) { + gyrokinetic_app_geometry_copy_and_write_surf( + app, app->gk_geom->geo_surf[dir].jacobgeo, arr_surf_ho1, arr_surf_ho2, "jacobgeo", dir, + "Conf-space Jacobian." + ); + gyrokinetic_app_geometry_copy_and_write_surf( + app, app->gk_geom->geo_surf[dir].jacobtot_inv, arr_surf_ho1, arr_surf_ho2, "jacobtot_inv", + dir, "Reciprocal of conf-space Jacobian." + ); + gyrokinetic_app_geometry_copy_and_write_surf( + app, app->gk_geom->geo_surf[dir].b_i, arr_surf_ho3, arr_surf_ho6, "b_i", dir, + "Covariant components of the magnetic unit vector." + ); + gyrokinetic_app_geometry_copy_and_write_surf( + app, app->gk_geom->geo_surf[dir].cmag, arr_surf_ho1, arr_surf_ho2, "cmag", dir, + "Ratio of (Clebsch) magnetic field to the volume element." + ); + gyrokinetic_app_geometry_copy_and_write_surf( + app, app->gk_geom->geo_surf[dir].bmag, arr_surf_ho1, arr_surf_ho2, "bmag", dir, + "Magnetic field magnitude." + ); + gyrokinetic_app_geometry_copy_and_write_surf( + app, app->gk_geom->geo_surf[dir].B3, arr_surf_ho1, arr_surf_ho2, "B3", dir, + "Contravariant z component of the magnetic field." + ); + gyrokinetic_app_geometry_copy_and_write_surf( + app, app->gk_geom->geo_surf[dir].normcurlbhat, arr_surf_ho1, arr_surf_ho2, "normcurlbhat", + dir, "Normal component of the curl of the magnetic unit vector. " + ); + gyrokinetic_app_geometry_copy_and_write_surf( + app, app->gk_geom->geo_surf[dir].normals, arr_surf_ho9, arr_surf_ho18, "normals", dir, + "Unit normal vectors. " + ); + gyrokinetic_app_geometry_copy_and_write_surf( + app, app->gk_geom->geo_surf[dir].lenr, arr_surf_ho1, arr_surf_ho2, "lenr", dir, + "Length ratios for coordinate surface integrals. " + ); + gyrokinetic_app_geometry_copy_and_write_surf( + app, app->gk_geom->geo_surf[dir].bimpactangle, arr_surf_ho1, arr_surf_ho2, "bimpactangle", + dir, "Impact angle of the magnetic field." + ); + gyrokinetic_app_geometry_copy_and_write_surf( + app, app->gk_geom->geo_surf[dir].deltats, arr_surf_ho1, arr_surf_ho2, "deltats", dir, + "Shift in binormal direction relative to y=varphi." + ); } // Write out nodes. This has to be done from rank 0 so we need to gather mc2p. - struct gkyl_array *mc2p_global = mkarr(app->use_gpu, app->gk_geom->geo_corn.mc2p->ncomp, app->global_ext.volume); - gkyl_comm_array_allgather(app->comm, &app->local, &app->global, app->gk_geom->geo_corn.mc2p, mc2p_global); + struct gkyl_array *mc2p_global = + mkarr(app->use_gpu, app->gk_geom->geo_corn.mc2p->ncomp, app->global_ext.volume); + gkyl_comm_array_allgather( + app->comm, &app->local, &app->global, app->gk_geom->geo_corn.mc2p, mc2p_global + ); struct gkyl_array *mc2p_global_ho = mkarr(false, mc2p_global->ncomp, mc2p_global->size); gkyl_array_copy(mc2p_global_ho, mc2p_global); - struct gkyl_array *mc2pint_global = mkarr(app->use_gpu, app->gk_geom->geo_int.mc2p->ncomp, app->global_ext.volume); - gkyl_comm_array_allgather(app->comm, &app->local, &app->global, app->gk_geom->geo_int.mc2p, mc2pint_global); + struct gkyl_array *mc2pint_global = + mkarr(app->use_gpu, app->gk_geom->geo_int.mc2p->ncomp, app->global_ext.volume); + gkyl_comm_array_allgather( + app->comm, &app->local, &app->global, app->gk_geom->geo_int.mc2p, mc2pint_global + ); struct gkyl_array *mc2pint_global_ho = mkarr(false, mc2pint_global->ncomp, mc2pint_global->size); gkyl_array_copy(mc2pint_global_ho, mc2pint_global); @@ -1520,24 +1736,32 @@ gkyl_gyrokinetic_app_write_geometry(gkyl_gyrokinetic_app* app, struct gkyl_gk_ge // Create Nodal Range and Grid and Write Nodal Coordinates struct gkyl_range nrange; gkyl_gk_geometry_init_nodal_range(&nrange, &app->global, app->poly_order); - struct gkyl_array* mc2p_nodal = mkarr(false, 3, nrange.volume); + struct gkyl_array *mc2p_nodal = mkarr(false, 3, nrange.volume); struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&app->basis, &app->grid, false); - gkyl_nodal_ops_m2n(n2m, &app->basis, &app->grid, &nrange, &app->global, 3, mc2p_nodal, mc2p_global_ho, false); + gkyl_nodal_ops_m2n( + n2m, &app->basis, &app->grid, &nrange, &app->global, 3, mc2p_nodal, mc2p_global_ho, false + ); struct gkyl_rect_grid ngrid; gkyl_gk_geometry_init_nodal_grid(&ngrid, &app->grid, &nrange); const char *fmt = "%s-%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, "geo_corn_nodes"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow sprintf(fileNm, fmt, app->name, "geo_corn_nodes"); // Package metadata for node file. struct gkyl_msgpack_map_elem desc_nodes[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Physical coordinates of grid corner nodes." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Physical coordinates of grid corner nodes."} }; int io_meta_nodes_len[] = {app->io_meta_dg_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta_nodes[] = {app->io_meta_dg, app->gk_geom->io_meta_basic, desc_nodes}; - struct gkyl_msgpack_data *mt_nodes = gkyl_msgpack_create_union(sizeof(io_meta_nodes_len)/sizeof(int), io_meta_nodes_len, io_meta_nodes); + const struct gkyl_msgpack_map_elem *io_meta_nodes[] = { + app->io_meta_dg, app->gk_geom->io_meta_basic, desc_nodes + }; + struct gkyl_msgpack_data *mt_nodes = gkyl_msgpack_create_union( + sizeof(io_meta_nodes_len) / sizeof(int), io_meta_nodes_len, io_meta_nodes + ); gkyl_grid_sub_array_write(&ngrid, &nrange, mt_nodes, mc2p_nodal, fileNm); @@ -1551,28 +1775,38 @@ gkyl_gyrokinetic_app_write_geometry(gkyl_gyrokinetic_app* app, struct gkyl_gk_ge // nrange_int must be sized from app->global (not the per-rank local nrange_int) int num_quad_points_int = app->poly_order + 1; int num_nodes_int[GKYL_MAX_CDIM]; - for (int d=0; dgrid.ndim; ++d) + for (int d = 0; d < app->grid.ndim; ++d) { num_nodes_int[d] = gkyl_range_shape(&app->global, d) * num_quad_points_int; + } struct gkyl_range nrange_int_global; gkyl_range_init_from_shape(&nrange_int_global, app->grid.ndim, num_nodes_int); - struct gkyl_array* mc2pint_nodal = mkarr(false, 3, nrange_int_global.volume); + struct gkyl_array *mc2pint_nodal = mkarr(false, 3, nrange_int_global.volume); struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&app->basis, &app->grid, false); - gkyl_nodal_ops_m2n(n2m, &app->basis, &app->grid, &nrange_int_global, &app->global, 3, mc2pint_nodal, mc2pint_global_ho, true); + gkyl_nodal_ops_m2n( + n2m, &app->basis, &app->grid, &nrange_int_global, &app->global, 3, mc2pint_nodal, + mc2pint_global_ho, true + ); struct gkyl_rect_grid ngrid_quad; gkyl_gk_geometry_init_nodal_grid(&ngrid_quad, &app->grid, &nrange_int_global); const char *fmt = "%s-%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, "geo_int_nodes"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow sprintf(fileNm, fmt, app->name, "geo_int_nodes"); struct gkyl_msgpack_map_elem desc_nodesint[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Physical coordinates of grid interior nodes." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Physical coordinates of grid interior nodes."} }; int io_meta_nodesint_len[] = {app->io_meta_dg_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta_nodesint[] = {app->io_meta_dg, app->gk_geom->io_meta_basic, desc_nodesint}; - struct gkyl_msgpack_data *mt_nodesint = gkyl_msgpack_create_union(sizeof(io_meta_nodesint_len)/sizeof(int), io_meta_nodesint_len, io_meta_nodesint); + const struct gkyl_msgpack_map_elem *io_meta_nodesint[] = { + app->io_meta_dg, app->gk_geom->io_meta_basic, desc_nodesint + }; + struct gkyl_msgpack_data *mt_nodesint = gkyl_msgpack_create_union( + sizeof(io_meta_nodesint_len) / sizeof(int), io_meta_nodesint_len, io_meta_nodesint + ); gkyl_grid_sub_array_write(&ngrid_quad, &nrange_int_global, mt_nodesint, mc2pint_nodal, fileNm); gkyl_msgpack_data_release(mt_nodesint); @@ -1582,8 +1816,9 @@ gkyl_gyrokinetic_app_write_geometry(gkyl_gyrokinetic_app* app, struct gkyl_gk_ge } // Write twistshift shift. - if (!gyrokinetic_str_ends_in_bnum(app->name)) + if (!gyrokinetic_str_ends_in_bnum(app->name)) { gyrokinetic_app_write_ts_shift(app); + } gkyl_array_release(mc2p_global); gkyl_array_release(mc2p_global_ho); @@ -1600,14 +1835,12 @@ gkyl_gyrokinetic_app_write_geometry(gkyl_gyrokinetic_app* app, struct gkyl_gk_ge gkyl_array_release(arr_surf_ho6); gkyl_array_release(arr_surf_ho9); gkyl_array_release(arr_surf_ho18); - } // // ............. Field outputs ............... // -// -void -gkyl_gyrokinetic_app_write_field(gkyl_gyrokinetic_app* app, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_field(gkyl_gyrokinetic_app *app, double tm, int frame) { if (app->field->update_field || frame == 0) { struct timespec wtm = gkyl_wall_clock(); @@ -1620,15 +1853,18 @@ gkyl_gyrokinetic_app_write_field(gkyl_gyrokinetic_app* app, double tm, int frame gkyl_msgpack_map_elem_set_double(app->io_meta_dg_len, app->io_meta_dg, "time", tm); gkyl_msgpack_map_elem_set_uint(app->io_meta_dg_len, app->io_meta_dg, "frame", frame); struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Electrostatic potential." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Electrostatic potential."} }; int io_meta_len[] = {app->io_meta_dg_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {app->io_meta_dg, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + app->io_meta_dg, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); const char *fmt = "%s-field_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, frame); gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, app->field->phi_host, fileNm); @@ -1640,8 +1876,7 @@ gkyl_gyrokinetic_app_write_field(gkyl_gyrokinetic_app* app, double tm, int frame } } -void -gkyl_gyrokinetic_app_calc_field_energy(gkyl_gyrokinetic_app* app, double tm) +void gkyl_gyrokinetic_app_calc_field_energy(gkyl_gyrokinetic_app *app, double tm) { if (app->field->update_field) { struct timespec wst = gkyl_wall_clock(); @@ -1653,15 +1888,14 @@ gkyl_gyrokinetic_app_calc_field_energy(gkyl_gyrokinetic_app* app, double tm) } } -void -gkyl_gyrokinetic_app_write_field_energy(gkyl_gyrokinetic_app* app) +void gkyl_gyrokinetic_app_write_field_energy(gkyl_gyrokinetic_app *app) { if (app->field->update_field) { struct timespec wtm = gkyl_wall_clock(); // Write out the field energy. const char *fmt0 = "%s-field_energy.gkyl"; int sz0 = gkyl_calc_strlen(fmt0, app->name); - char fileNm0[sz0+1]; // ensures no buffer overflow + char fileNm0[sz0 + 1]; // ensures no buffer overflow snprintf(fileNm0, sizeof fileNm0, fmt0, app->name); int rank; @@ -1671,17 +1905,19 @@ gkyl_gyrokinetic_app_write_field_energy(gkyl_gyrokinetic_app* app) if (app->field->is_first_energy_write_call) { // Write to a new file (this ensure previous output is removed). struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Electrostatic field energy." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Electrostatic field energy."} }; int io_meta_len[] = {app->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {app->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); - + const struct gkyl_msgpack_map_elem *io_meta[] = { + app->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); + gkyl_dynvec_write_wmeta(app->field->integ_energy, fileNm0, mt); app->field->is_first_energy_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { // Append to existing file. gkyl_dynvec_awrite(app->field->integ_energy, fileNm0); } @@ -1693,25 +1929,29 @@ gkyl_gyrokinetic_app_write_field_energy(gkyl_gyrokinetic_app* app) // Write out the time rate of change of the field energy. const char *fmt1 = "%s-field_energy_dot.gkyl"; int sz1 = gkyl_calc_strlen(fmt1, app->name); - char fileNm1[sz1+1]; // ensures no buffer overflow + char fileNm1[sz1 + 1]; // ensures no buffer overflow snprintf(fileNm1, sizeof fileNm1, fmt1, app->name); if (rank == 0) { if (app->field->is_first_energy_dot_write_call) { // Write to a new file (this ensure previous output is removed). struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Electrostatic field energy rate of change." } + {.key = "Description", + .elem_type = GKYL_MP_STRING, + .cval = "Electrostatic field energy rate of change."} }; int io_meta_len[] = {app->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {app->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); - + const struct gkyl_msgpack_map_elem *io_meta[] = { + app->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); + gkyl_dynvec_write_wmeta(app->field->integ_energy_dot, fileNm1, mt); app->field->is_first_energy_dot_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { // Append to existing file. gkyl_dynvec_awrite(app->field->integ_energy_dot, fileNm1); } @@ -1726,114 +1966,118 @@ gkyl_gyrokinetic_app_write_field_energy(gkyl_gyrokinetic_app* app) // // ............. Species outputs ............... // -// -void -gkyl_gyrokinetic_app_write_species(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_species(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame) { struct gk_species *gks = &app->species[sidx]; gk_species_write(app, gks, tm, frame); } -void -gkyl_gyrokinetic_app_write_neut_species(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_neut_species( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_write(app, gkns, tm, frame); } -void -gkyl_gyrokinetic_app_write_species_mom(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_species_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_write_mom(app, gks, tm, frame); } -void -gkyl_gyrokinetic_app_write_neut_species_mom(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_neut_species_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_write_mom(app, gkns, tm, frame); } -void -gkyl_gyrokinetic_app_calc_species_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm) +void gkyl_gyrokinetic_app_calc_species_integrated_mom(gkyl_gyrokinetic_app *app, int sidx, double tm) { struct gk_species *gks = &app->species[sidx]; gk_species_calc_integrated_mom(app, gks, tm); } -void -gkyl_gyrokinetic_app_calc_neut_species_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm) +void gkyl_gyrokinetic_app_calc_neut_species_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_calc_integrated_mom(app, gkns, tm); } -void -gkyl_gyrokinetic_app_calc_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm) +void gkyl_gyrokinetic_app_calc_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +) { struct gk_species *gks = &app->species[sidx]; gk_species_bflux_calc_integrated_mom(app, gks, &gks->bflux, tm); } -void -gkyl_gyrokinetic_app_calc_neut_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm) +void gkyl_gyrokinetic_app_calc_neut_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_bflux_calc_integrated_mom(app, gkns, &gkns->bflux, tm); } -void -gkyl_gyrokinetic_app_write_species_integrated_mom(gkyl_gyrokinetic_app *app, int sidx) +void gkyl_gyrokinetic_app_write_species_integrated_mom(gkyl_gyrokinetic_app *app, int sidx) { struct gk_species *gks = &app->species[sidx]; gk_species_write_integrated_mom(app, gks); } -void -gkyl_gyrokinetic_app_write_neut_species_integrated_mom(gkyl_gyrokinetic_app *app, int sidx) +void gkyl_gyrokinetic_app_write_neut_species_integrated_mom(gkyl_gyrokinetic_app *app, int sidx) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_write_integrated_mom(app, gkns); } -void -gkyl_gyrokinetic_app_calc_species_L2norm(gkyl_gyrokinetic_app *app, int sidx, double tm) +void gkyl_gyrokinetic_app_calc_species_L2norm(gkyl_gyrokinetic_app *app, int sidx, double tm) { struct gk_species *gks = &app->species[sidx]; gk_species_calc_L2norm(app, gks, tm); } -void -gkyl_gyrokinetic_app_write_species_L2norm(gkyl_gyrokinetic_app *app, int sidx) +void gkyl_gyrokinetic_app_write_species_L2norm(gkyl_gyrokinetic_app *app, int sidx) { struct gk_species *gks = &app->species[sidx]; gk_species_write_L2norm(app, gks); } -void -gkyl_gyrokinetic_app_write_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_app *app, int sidx) +void gkyl_gyrokinetic_app_write_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx +) { struct gk_species *gks = &app->species[sidx]; gk_species_bflux_write_integrated_mom(app, gks, &gks->bflux); } -void -gkyl_gyrokinetic_app_write_species_boundary_flux_mom(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_species_boundary_flux_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_bflux_write_mom(app, gks, &gks->bflux, tm, frame); } -void -gkyl_gyrokinetic_app_write_neut_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_app *app, int sidx) +void gkyl_gyrokinetic_app_write_neut_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_bflux_write_integrated_mom(app, gkns, &gkns->bflux); } -void -gkyl_gyrokinetic_app_write_neut_species_boundary_flux_mom(gkyl_gyrokinetic_app *app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_neut_species_boundary_flux_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_bflux_write_mom(app, gkns, &gkns->bflux, tm, frame); @@ -1841,58 +2085,64 @@ gkyl_gyrokinetic_app_write_neut_species_boundary_flux_mom(gkyl_gyrokinetic_app * // // ............. Source outputs ............... // -// -void -gkyl_gyrokinetic_app_write_species_source(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_species_source( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_source_write(app, gks, tm, frame); } -void -gkyl_gyrokinetic_app_write_neut_species_source(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_neut_species_source( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_source_write(app, gkns, tm, frame); } -void -gkyl_gyrokinetic_app_write_species_source_mom(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_species_source_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_source_write_mom(app, gks, tm, frame); } -void -gkyl_gyrokinetic_app_write_neut_species_source_mom(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_neut_species_source_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_source_write_mom(app, gkns, tm, frame); } -void -gkyl_gyrokinetic_app_calc_species_source_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm) +void gkyl_gyrokinetic_app_calc_species_source_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +) { struct gk_species *gks = &app->species[sidx]; gk_species_source_calc_integrated_mom(app, gks, tm); } -void -gkyl_gyrokinetic_app_calc_neut_species_source_integrated_mom(gkyl_gyrokinetic_app* app, int sidx, double tm) +void gkyl_gyrokinetic_app_calc_neut_species_source_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_source_calc_integrated_mom(app, gkns, tm); } -void -gkyl_gyrokinetic_app_write_species_source_integrated_mom(gkyl_gyrokinetic_app *app, int sidx) +void gkyl_gyrokinetic_app_write_species_source_integrated_mom(gkyl_gyrokinetic_app *app, int sidx) { struct gk_species *gks = &app->species[sidx]; gk_species_source_write_integrated_mom(app, gks); } -void -gkyl_gyrokinetic_app_write_neut_species_source_integrated_mom(gkyl_gyrokinetic_app *app, int sidx) +void gkyl_gyrokinetic_app_write_neut_species_source_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_source_write_integrated_mom(app, gkns); @@ -1900,9 +2150,10 @@ gkyl_gyrokinetic_app_write_neut_species_source_integrated_mom(gkyl_gyrokinetic_a // // ............. Damping outputs ............... // -// -void -gkyl_gyrokinetic_app_write_species_damping(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_species_damping( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_damping_write(app, gks, tm, frame); @@ -1910,9 +2161,10 @@ gkyl_gyrokinetic_app_write_species_damping(gkyl_gyrokinetic_app* app, int sidx, // // ............. df/dt multiplier outputs ............... // -// -void -gkyl_gyrokinetic_app_write_species_fdot_multiplier(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_species_fdot_multiplier( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_fdot_multiplier_write(app, gks, &gks->fdot_mult, tm, frame); @@ -1920,23 +2172,26 @@ gkyl_gyrokinetic_app_write_species_fdot_multiplier(gkyl_gyrokinetic_app* app, in // // ............. BGK Source outputs ............... // -// -void -gkyl_gyrokinetic_app_write_species_source_bgk_diagnostics(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_species_source_bgk_diagnostics( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_source_bgk_write_diags(app, gks, &gks->bgk_src, tm, frame); } -void -gkyl_gyrokinetic_app_calc_species_source_bgk_integrated_diagnostics(gkyl_gyrokinetic_app* app, int sidx, double tm) +void gkyl_gyrokinetic_app_calc_species_source_bgk_integrated_diagnostics( + gkyl_gyrokinetic_app *app, int sidx, double tm +) { struct gk_species *gks = &app->species[sidx]; gk_species_source_bgk_calc_integrated_diags(app, gks, &gks->bgk_src, tm); } -void -gkyl_gyrokinetic_app_write_species_source_bgk_integrated_diagnostics(gkyl_gyrokinetic_app *app, int sidx) +void gkyl_gyrokinetic_app_write_species_source_bgk_integrated_diagnostics( + gkyl_gyrokinetic_app *app, int sidx +) { struct gk_species *gks = &app->species[sidx]; gk_species_source_bgk_write_integrated_diags(app, gks, &gks->bgk_src); @@ -1944,73 +2199,77 @@ gkyl_gyrokinetic_app_write_species_source_bgk_integrated_diagnostics(gkyl_gyroki // // ............. EIRENE outputs ............... // -// -void -gkyl_gyrokinetic_app_write_eirene_diagnostics(gkyl_gyrokinetic_app* app, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_eirene_diagnostics(gkyl_gyrokinetic_app *app, double tm, int frame) { gk_eirene_write(app, tm, frame); } -void -gkyl_gyrokinetic_app_calc_eirene_integrated_diagnostics(gkyl_gyrokinetic_app* app, double tm) +void gkyl_gyrokinetic_app_calc_eirene_integrated_diagnostics(gkyl_gyrokinetic_app *app, double tm) { gk_eirene_calc_integrated_diagnostics(app, tm); } -void -gkyl_gyrokinetic_app_write_eirene_integrated_diagnostics(gkyl_gyrokinetic_app* app) +void gkyl_gyrokinetic_app_write_eirene_integrated_diagnostics(gkyl_gyrokinetic_app *app) { gk_eirene_write_integrated_diagnostics(app); } // ............. Collisionless outputs ............... // -// -void -gkyl_gyrokinetic_app_write_species_collisionless_diagnostics(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_species_collisionless_diagnostics( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_collisionless_write_diags(app, gks, &gks->collisionless, tm, frame); } // ............. Positivity outputs ............... // -// -void -gkyl_gyrokinetic_app_write_species_positivity_diagnostics(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_species_positivity_diagnostics( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_positivity_write_diags(app, gks, &gks->positivity, tm, frame); } -void -gkyl_gyrokinetic_app_calc_species_positivity_integrated_diagnostics(gkyl_gyrokinetic_app* app, int sidx, double tm) +void gkyl_gyrokinetic_app_calc_species_positivity_integrated_diagnostics( + gkyl_gyrokinetic_app *app, int sidx, double tm +) { struct gk_species *gks = &app->species[sidx]; gk_species_positivity_calc_integrated_diags(app, gks, &gks->positivity, tm); } -void -gkyl_gyrokinetic_app_write_species_positivity_integrated_diagnostics(gkyl_gyrokinetic_app *app, int sidx) +void gkyl_gyrokinetic_app_write_species_positivity_integrated_diagnostics( + gkyl_gyrokinetic_app *app, int sidx +) { struct gk_species *gks = &app->species[sidx]; gk_species_positivity_write_integrated_diags(app, gks, &gks->positivity); } -void -gkyl_gyrokinetic_app_write_neut_species_positivity_diagnostics(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_neut_species_positivity_diagnostics( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_positivity_write_diags(app, gkns, &gkns->positivity, tm, frame); } -void -gkyl_gyrokinetic_app_calc_neut_species_positivity_integrated_diagnostics(gkyl_gyrokinetic_app* app, int sidx, double tm) +void gkyl_gyrokinetic_app_calc_neut_species_positivity_integrated_diagnostics( + gkyl_gyrokinetic_app *app, int sidx, double tm +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_positivity_calc_integrated_diags(app, gkns, &gkns->positivity, tm); } -void -gkyl_gyrokinetic_app_write_neut_species_positivity_integrated_diagnostics(gkyl_gyrokinetic_app *app, int sidx) +void gkyl_gyrokinetic_app_write_neut_species_positivity_integrated_diagnostics( + gkyl_gyrokinetic_app *app, int sidx +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; gk_neut_species_positivity_write_integrated_diags(app, gkns, &gkns->positivity); @@ -2018,34 +2277,34 @@ gkyl_gyrokinetic_app_write_neut_species_positivity_integrated_diagnostics(gkyl_g // // ............. LTE outputs ............... // -// +// -void -gkyl_gyrokinetic_app_write_species_lte_max_corr_status(gkyl_gyrokinetic_app* app, int sidx) +void gkyl_gyrokinetic_app_write_species_lte_max_corr_status(gkyl_gyrokinetic_app *app, int sidx) { struct gk_species *gks = &app->species[sidx]; - gk_species_lte_write_max_corr_status(app, gks); + gk_species_lte_write_max_corr_status(app, gks); } -void -gkyl_gyrokinetic_app_write_neut_species_lte_max_corr_status(gkyl_gyrokinetic_app* app, int sidx) +void gkyl_gyrokinetic_app_write_neut_species_lte_max_corr_status(gkyl_gyrokinetic_app *app, int sidx) { struct gk_neut_species *gkns = &app->neut_species[sidx]; - gk_neut_species_lte_write_max_corr_status(app, gkns); + gk_neut_species_lte_write_max_corr_status(app, gkns); } // // ............. Collision outputs ............... // -// -void -gkyl_gyrokinetic_app_write_species_lbo_mom(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_species_lbo_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_lbo_write_mom(app, gks, tm, frame); } -void -gkyl_gyrokinetic_app_write_species_bgk_mom(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_species_bgk_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_bgk_write_mom(app, gks, tm, frame); @@ -2053,30 +2312,32 @@ gkyl_gyrokinetic_app_write_species_bgk_mom(gkyl_gyrokinetic_app* app, int sidx, // // ............. Radiation outputs ............... // -// -void -gkyl_gyrokinetic_app_write_species_rad_drag(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_species_rad_drag( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_radiation_write_drag(app, gks, tm, frame); } -void -gkyl_gyrokinetic_app_write_species_rad_emissivity(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_species_rad_emissivity( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; gk_species_radiation_write_emissivity(app, gks, tm, frame); } -void -gkyl_gyrokinetic_app_calc_species_rad_integrated_mom(gkyl_gyrokinetic_app *app, int sidx, double tm) +void gkyl_gyrokinetic_app_calc_species_rad_integrated_mom( + gkyl_gyrokinetic_app *app, int sidx, double tm +) { struct gk_species *gks = &app->species[sidx]; gk_species_radiation_calc_integrated_mom(app, gks, tm); } -void -gkyl_gyrokinetic_app_write_species_rad_integrated_mom(gkyl_gyrokinetic_app *app, int sidx) +void gkyl_gyrokinetic_app_write_species_rad_integrated_mom(gkyl_gyrokinetic_app *app, int sidx) { struct gk_species *gks = &app->species[sidx]; gk_species_radiation_write_integrated_mom(app, gks); @@ -2084,25 +2345,28 @@ gkyl_gyrokinetic_app_write_species_rad_integrated_mom(gkyl_gyrokinetic_app *app, // // ............. Neutral reaction outputs ............... // -// -void -gkyl_gyrokinetic_app_write_species_react(gkyl_gyrokinetic_app* app, int sidx, int ridx, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_species_react( + gkyl_gyrokinetic_app *app, int sidx, int ridx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; struct gk_react *gkr = &gks->react; gk_species_react_write(app, gks, gkr, ridx, tm, frame); } -void -gkyl_gyrokinetic_app_write_species_react_neut(gkyl_gyrokinetic_app* app, int sidx, int ridx, double tm, int frame) +void gkyl_gyrokinetic_app_write_species_react_neut( + gkyl_gyrokinetic_app *app, int sidx, int ridx, double tm, int frame +) { struct gk_species *gks = &app->species[sidx]; struct gk_react *gkr = &gks->react_neut; gk_species_react_write(app, gks, gkr, ridx, tm, frame); } -void -gkyl_gyrokinetic_app_write_neut_species_react_neut(gkyl_gyrokinetic_app* app, int sidx, int ridx, double tm, int frame) +void gkyl_gyrokinetic_app_write_neut_species_react_neut( + gkyl_gyrokinetic_app *app, int sidx, int ridx, double tm, int frame +) { struct gk_neut_species *gkns = &app->neut_species[sidx]; struct gk_react *gkr = &gkns->react_neut; @@ -2111,9 +2375,10 @@ gkyl_gyrokinetic_app_write_neut_species_react_neut(gkyl_gyrokinetic_app* app, in // // ............. Functions that group several outputs for a single species ............... // -// -void -gkyl_gyrokinetic_app_write_species_phase(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_species_phase( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { gkyl_gyrokinetic_app_write_species(app, sidx, tm, frame); @@ -2128,16 +2393,18 @@ gkyl_gyrokinetic_app_write_species_phase(gkyl_gyrokinetic_app* app, int sidx, do gkyl_gyrokinetic_app_write_species_collisionless_diagnostics(app, sidx, tm, frame); } -void -gkyl_gyrokinetic_app_write_neut_species_phase(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_neut_species_phase( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { gkyl_gyrokinetic_app_write_neut_species(app, sidx, tm, frame); gkyl_gyrokinetic_app_write_neut_species_source(app, sidx, tm, frame); } -void -gkyl_gyrokinetic_app_write_species_conf(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_species_conf( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { gkyl_gyrokinetic_app_write_species_mom(app, sidx, tm, frame); @@ -2154,18 +2421,19 @@ gkyl_gyrokinetic_app_write_species_conf(gkyl_gyrokinetic_app* app, int sidx, dou gkyl_gyrokinetic_app_write_species_rad_emissivity(app, sidx, tm, frame); struct gk_species *gks = &app->species[sidx]; - for (int j=0; jreact.num_react; ++j) { + for (int j = 0; j < gks->react.num_react; ++j) { gkyl_gyrokinetic_app_write_species_react(app, sidx, j, tm, frame); } - for (int j=0; jreact_neut.num_react; ++j) { + for (int j = 0; j < gks->react_neut.num_react; ++j) { gkyl_gyrokinetic_app_write_species_react_neut(app, sidx, j, tm, frame); } gkyl_gyrokinetic_app_write_species_boundary_flux_mom(app, sidx, tm, frame); } -void -gkyl_gyrokinetic_app_write_neut_species_conf(gkyl_gyrokinetic_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_app_write_neut_species_conf( + gkyl_gyrokinetic_app *app, int sidx, double tm, int frame +) { gkyl_gyrokinetic_app_write_neut_species_mom(app, sidx, tm, frame); @@ -2175,25 +2443,26 @@ gkyl_gyrokinetic_app_write_neut_species_conf(gkyl_gyrokinetic_app* app, int sidx struct gk_neut_species *gkns = &app->neut_species[sidx]; - for (int j=0; jreact_neut.num_react; ++j) { + for (int j = 0; j < gkns->react_neut.num_react; ++j) { gkyl_gyrokinetic_app_write_neut_species_react_neut(app, sidx, j, tm, frame); } - if (gkns->lower_bc[app->cdim-1].type == GKYL_BC_GK_SPECIES_RECYCLE) + if (gkns->lower_bc[app->cdim - 1].type == GKYL_BC_GK_SPECIES_RECYCLE) { gk_neut_species_recycle_write_flux(app, gkns, &gkns->bc_recycle_lo, tm, frame); - if (gkns->upper_bc[app->cdim-1].type == GKYL_BC_GK_SPECIES_RECYCLE) + } + if (gkns->upper_bc[app->cdim - 1].type == GKYL_BC_GK_SPECIES_RECYCLE) { gk_neut_species_recycle_write_flux(app, gkns, &gkns->bc_recycle_up, tm, frame); + } gkyl_gyrokinetic_app_write_neut_species_boundary_flux_mom(app, sidx, tm, frame); } // // ............. Functions that group several species outputs ............... // -// -void -gkyl_gyrokinetic_app_write_mom(gkyl_gyrokinetic_app* app, double tm, int frame) +// +void gkyl_gyrokinetic_app_write_mom(gkyl_gyrokinetic_app *app, double tm, int frame) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_app_write_species_mom(app, i, tm, frame); gkyl_gyrokinetic_app_write_species_source_mom(app, i, tm, frame); gkyl_gyrokinetic_app_write_species_source_bgk_diagnostics(app, i, tm, frame); @@ -2204,7 +2473,7 @@ gkyl_gyrokinetic_app_write_mom(gkyl_gyrokinetic_app* app, double tm, int frame) gkyl_gyrokinetic_app_write_species_boundary_flux_mom(app, i, tm, frame); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_app_write_neut_species_mom(app, i, tm, frame); gkyl_gyrokinetic_app_write_neut_species_source_mom(app, i, tm, frame); gkyl_gyrokinetic_app_write_neut_species_positivity_diagnostics(app, i, tm, frame); @@ -2212,10 +2481,9 @@ gkyl_gyrokinetic_app_write_mom(gkyl_gyrokinetic_app* app, double tm, int frame) } } -void -gkyl_gyrokinetic_app_calc_integrated_mom(gkyl_gyrokinetic_app* app, double tm) +void gkyl_gyrokinetic_app_calc_integrated_mom(gkyl_gyrokinetic_app *app, double tm) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_app_calc_species_integrated_mom(app, i, tm); gkyl_gyrokinetic_app_calc_species_rad_integrated_mom(app, i, tm); gkyl_gyrokinetic_app_calc_species_boundary_flux_integrated_mom(app, i, tm); @@ -2224,7 +2492,7 @@ gkyl_gyrokinetic_app_calc_integrated_mom(gkyl_gyrokinetic_app* app, double tm) gkyl_gyrokinetic_app_calc_species_positivity_integrated_diagnostics(app, i, tm); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_app_calc_neut_species_integrated_mom(app, i, tm); gkyl_gyrokinetic_app_calc_neut_species_source_integrated_mom(app, i, tm); gkyl_gyrokinetic_app_calc_neut_species_positivity_integrated_diagnostics(app, i, tm); @@ -2234,18 +2502,16 @@ gkyl_gyrokinetic_app_calc_integrated_mom(gkyl_gyrokinetic_app* app, double tm) gkyl_gyrokinetic_app_calc_eirene_integrated_diagnostics(app, tm); } -void -gkyl_gyrokinetic_app_calc_L2norm(gkyl_gyrokinetic_app* app, double tm) +void gkyl_gyrokinetic_app_calc_L2norm(gkyl_gyrokinetic_app *app, double tm) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_app_calc_species_L2norm(app, i, tm); } } -void -gkyl_gyrokinetic_app_write_integrated_mom(gkyl_gyrokinetic_app *app) +void gkyl_gyrokinetic_app_write_integrated_mom(gkyl_gyrokinetic_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_app_write_species_integrated_mom(app, i); gkyl_gyrokinetic_app_write_species_source_integrated_mom(app, i); gkyl_gyrokinetic_app_write_species_source_bgk_integrated_diagnostics(app, i); @@ -2255,7 +2521,7 @@ gkyl_gyrokinetic_app_write_integrated_mom(gkyl_gyrokinetic_app *app) gkyl_gyrokinetic_app_write_species_boundary_flux_integrated_mom(app, i); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_app_write_neut_species_integrated_mom(app, i); gkyl_gyrokinetic_app_write_neut_species_source_integrated_mom(app, i); gkyl_gyrokinetic_app_write_neut_species_positivity_integrated_diagnostics(app, i); @@ -2266,44 +2532,40 @@ gkyl_gyrokinetic_app_write_integrated_mom(gkyl_gyrokinetic_app *app) gkyl_gyrokinetic_app_write_eirene_integrated_diagnostics(app); } -void -gkyl_gyrokinetic_app_write_L2norm(gkyl_gyrokinetic_app *app) +void gkyl_gyrokinetic_app_write_L2norm(gkyl_gyrokinetic_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_app_write_species_L2norm(app, i); } } -void -gkyl_gyrokinetic_app_write_conf(gkyl_gyrokinetic_app* app, double tm, int frame) +void gkyl_gyrokinetic_app_write_conf(gkyl_gyrokinetic_app *app, double tm, int frame) { gkyl_gyrokinetic_app_write_field(app, tm, frame); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_app_write_species_conf(app, i, tm, frame); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_app_write_neut_species_conf(app, i, tm, frame); } gkyl_gyrokinetic_app_write_eirene_diagnostics(app, tm, frame); } -void -gkyl_gyrokinetic_app_write_phase(gkyl_gyrokinetic_app* app, double tm, int frame) +void gkyl_gyrokinetic_app_write_phase(gkyl_gyrokinetic_app *app, double tm, int frame) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_app_write_species_phase(app, i, tm, frame); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_app_write_neut_species_phase(app, i, tm, frame); } } -void -gkyl_gyrokinetic_app_write(gkyl_gyrokinetic_app* app, double tm, int frame) +void gkyl_gyrokinetic_app_write(gkyl_gyrokinetic_app *app, double tm, int frame) { gkyl_gyrokinetic_app_write_phase(app, tm, frame); @@ -2311,34 +2573,35 @@ gkyl_gyrokinetic_app_write(gkyl_gyrokinetic_app* app, double tm, int frame) } // // ............. End of write functions ............... // -// +// -void -gyrokinetic_rhs(gkyl_gyrokinetic_app* app, double tcurr, double dt, - const struct gkyl_array *fin[], struct gkyl_array *fout[], struct gkyl_array **bflux_out[], - const struct gkyl_array *fin_neut[], struct gkyl_array *fout_neut[], struct gkyl_array **bflux_out_neut[], - struct gkyl_update_status *st) +void gyrokinetic_rhs( + gkyl_gyrokinetic_app *app, double tcurr, double dt, const struct gkyl_array *fin[], + struct gkyl_array *fout[], struct gkyl_array **bflux_out[], const struct gkyl_array *fin_neut[], + struct gkyl_array *fout_neut[], struct gkyl_array **bflux_out_neut[], + struct gkyl_update_status *st +) { double dtmin = DBL_MAX; // Compute moments needed by various modules. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gk_s = &app->species[i]; gk_species_lbo_moms(app, gk_s, &gk_s->lbo, fin[i]); gk_species_bgk_moms(app, gk_s, &gk_s->bgk, fin[i]); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { struct gk_neut_species *gk_ns = &app->neut_species[i]; gk_neut_species_bgk_moms(app, gk_ns, &gk_ns->bgk, fin_neut[i]); } // Compute cross-species moments needed by various modules. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gk_s = &app->species[i]; // Elastic collisions. - gk_species_lbo_cross_moms(app, gk_s, &gk_s->lbo, fin[i]); - gk_species_bgk_cross_moms(app, gk_s, &gk_s->bgk, fin[i]); + gk_species_lbo_cross_moms(app, gk_s, &gk_s->lbo, fin[i]); + gk_species_bgk_cross_moms(app, gk_s, &gk_s->bgk, fin[i]); // Reactions (e.g. ionization, recombination charge exchange). gk_species_react_cross_moms(app, gk_s, &gk_s->react, fin, fin_neut); @@ -2350,7 +2613,7 @@ gyrokinetic_rhs(gkyl_gyrokinetic_app* app, double tcurr, double dt, // Scaling. gk_species_scaling_cross_moms(app, gk_s, &gk_s->sca, fin, fin_neut); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { struct gk_neut_species *gk_ns = &app->neut_species[i]; // Reactions (e.g. ionization, recombination charge exchange). @@ -2361,12 +2624,12 @@ gyrokinetic_rhs(gkyl_gyrokinetic_app* app, double tcurr, double dt, } // Compute df/dt (not including sources). - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gk_s = &app->species[i]; double dt1 = gk_species_rhs(app, gk_s, fin[i], fout[i], bflux_out[i]); dtmin = fmin(dtmin, dt1); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { struct gk_neut_species *gk_ns = &app->neut_species[i]; double dt1 = gk_neut_species_rhs(app, gk_ns, fin_neut[i], fout_neut[i], bflux_out_neut[i]); dtmin = fmin(dtmin, dt1); @@ -2375,77 +2638,79 @@ gyrokinetic_rhs(gkyl_gyrokinetic_app* app, double tcurr, double dt, gk_eirene_rhs(app, fin, fout); // Sources. Done after df/dt in case boundary fluxes are needed. - for (int i=0; inum_species; ++i) { - gk_species_source_rhs(app, &app->species[i], - &app->species[i].src, fin[i], fout[i]); + for (int i = 0; i < app->num_species; ++i) { + gk_species_source_rhs(app, &app->species[i], &app->species[i].src, fin[i], fout[i]); } - for (int i=0; inum_neut_species; ++i) { - gk_neut_species_source_rhs(app, &app->neut_species[i], - &app->neut_species[i].src, fin_neut[i], fout_neut[i]); + for (int i = 0; i < app->num_neut_species; ++i) { + gk_neut_species_source_rhs( + app, &app->neut_species[i], &app->neut_species[i].src, fin_neut[i], fout_neut[i] + ); } // Multiply dfdt (fout) by a factor. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gks = &app->species[i]; - gk_species_fdot_multiplier_advance_times_rate(app, gks, &gks->fdot_mult, - app->field->phi_smooth, fin[i], fout[i]); + gk_species_fdot_multiplier_advance_times_rate( + app, gks, &gks->fdot_mult, app->field->phi_smooth, fin[i], fout[i] + ); } struct timespec wtm = gkyl_wall_clock(); double dt_max_rel_diff = 0.01; // Check if dtmin is slightly smaller than dt. Use dt if it is // (avoids retaking steps if dt changes are very small). - double dt_rel_diff = (dt-dtmin)/dt; - if (dt_rel_diff > 0 && dt_rel_diff < dt_max_rel_diff) + double dt_rel_diff = (dt - dtmin) / dt; + if (dt_rel_diff > 0 && dt_rel_diff < dt_max_rel_diff) { dtmin = dt; + } // Compute minimum time-step across all processors. double dtmin_local = dtmin, dtmin_global; gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MIN, 1, &dtmin_local, &dtmin_global); dtmin = dtmin_global; - + // Don't take a time-step larger that input dt. double dta = st->dt_actual = dt < dtmin ? dt : dtmin; st->dt_suggested = dtmin; app->stat.dfdt_dt_reduce_tm += gkyl_time_diff_now_sec(wtm); } -void -gyrokinetic_rhs_implicit(gkyl_gyrokinetic_app* app, double tcurr, double dt, - struct gkyl_array *fin[], struct gkyl_array *fout[], struct gkyl_array **bflux_out[], - struct gkyl_array *fin_neut[], struct gkyl_array *fout_neut[], struct gkyl_array **bflux_out_neut[], - struct gkyl_update_status *st) +void gyrokinetic_rhs_implicit( + gkyl_gyrokinetic_app *app, double tcurr, double dt, struct gkyl_array *fin[], + struct gkyl_array *fout[], struct gkyl_array **bflux_out[], struct gkyl_array *fin_neut[], + struct gkyl_array *fout_neut[], struct gkyl_array **bflux_out_neut[], + struct gkyl_update_status *st +) { // Compute moments needed by various modules. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gk_s = &app->species[i]; gk_species_bgk_moms_implicit(app, gk_s, &gk_s->bgk, fin[i]); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { struct gk_neut_species *gk_ns = &app->neut_species[i]; gk_neut_species_bgk_moms_implicit(app, gk_ns, &gk_ns->bgk, fin_neut[i]); } // Compute cross-species moments needed by various modules. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gk_s = &app->species[i]; // Elastic collisions. - gk_species_bgk_cross_moms_implicit(app, gk_s, &gk_s->bgk, fin[i]); + gk_species_bgk_cross_moms_implicit(app, gk_s, &gk_s->bgk, fin[i]); } // Compute df/dt from implicit terms (not including sources). - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gk_s = &app->species[i]; gk_species_rhs_implicit(app, gk_s, fin[i], fout[i], bflux_out[i], dt); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { struct gk_neut_species *gk_ns = &app->neut_species[i]; gk_neut_species_rhs_implicit(app, gk_ns, fin_neut[i], fout_neut[i], bflux_out_neut[i], dt); } } -struct gkyl_update_status -gkyl_gyrokinetic_update(gkyl_gyrokinetic_app* app, double dt) +struct gkyl_update_status gkyl_gyrokinetic_update(gkyl_gyrokinetic_app *app, double dt) { app->stat.nup += 1; struct timespec wst = gkyl_wall_clock(); @@ -2455,136 +2720,344 @@ gkyl_gyrokinetic_update(gkyl_gyrokinetic_app* app, double dt) app->stat.time_loop_tm += gkyl_time_diff_now_sec(wst); // Check for any CUDA errors during time step - if (app->use_gpu) + if (app->use_gpu) { checkCuda(cudaGetLastError()); + } return status; } -struct gkyl_gyrokinetic_stat -gkyl_gyrokinetic_app_stat(gkyl_gyrokinetic_app* app) +struct gkyl_gyrokinetic_stat gkyl_gyrokinetic_app_stat(gkyl_gyrokinetic_app *app) { struct gkyl_gyrokinetic_stat *stat = &app->stat; // Timers not yet computed in app directly. stat->time_rate_diags_tm = stat->fdot_tm + stat->phidot_tm; - stat->pos_shift_tm = stat->species_pos_shift_tm + stat->neut_species_pos_shift_tm + stat->pos_shift_quasineut_tm; - stat->io_tm = stat->species_io_tm + stat->species_diag_calc_tm + stat->species_diag_io_tm + stat->neut_species_io_tm - + stat->neut_species_diag_calc_tm + stat->neut_species_diag_io_tm + stat->field_io_tm + stat->field_diag_calc_tm - + stat->field_diag_io_tm + stat->app_io_tm; + stat->pos_shift_tm = + stat->species_pos_shift_tm + stat->neut_species_pos_shift_tm + stat->pos_shift_quasineut_tm; + stat->io_tm = stat->species_io_tm + stat->species_diag_calc_tm + stat->species_diag_io_tm + + stat->neut_species_io_tm + stat->neut_species_diag_calc_tm + + stat->neut_species_diag_io_tm + stat->field_io_tm + stat->field_diag_calc_tm + + stat->field_diag_io_tm + stat->app_io_tm; // Additions of several timers. - stat->fwd_euler_sum_tm = stat->species_coll_mom_tm + stat->species_react_mom_tm + stat->neut_species_coll_mom_tm - + stat->neut_species_react_mom_tm + stat->species_rad_mom_tm + stat->species_gyroavg_tm + stat->species_collisionless_tm - + stat->species_coll_tm + stat->species_damp_tm + stat->species_fdot_mult_tm + stat->species_diffusion_tm - + stat->species_rad_tm + stat->species_react_tm + stat->species_bflux_calc_tm + stat->species_bflux_moms_tm - + stat->species_omega_cfl_tm + stat->species_src_tm + stat->species_source_bgk_tm - + stat->neut_species_collisionless_tm + stat->neut_species_coll_tm + stat->neut_species_react_tm - + stat->neut_species_omega_cfl_tm + stat->neut_species_src_tm + stat->dfdt_dt_reduce_tm + stat->fwd_euler_step_f_tm; - stat->field_sum_tm = stat->field_phi_rhs_tm + stat->field_phi_solve_tm; + stat->fwd_euler_sum_tm = + stat->species_coll_mom_tm + stat->species_react_mom_tm + stat->neut_species_coll_mom_tm + + stat->neut_species_react_mom_tm + stat->species_rad_mom_tm + stat->species_gyroavg_tm + + stat->species_collisionless_tm + stat->species_coll_tm + stat->species_damp_tm + + stat->species_fdot_mult_tm + stat->species_diffusion_tm + stat->species_rad_tm + + stat->species_react_tm + stat->species_bflux_calc_tm + stat->species_bflux_moms_tm + + stat->species_omega_cfl_tm + stat->species_src_tm + stat->species_source_bgk_tm + + stat->neut_species_collisionless_tm + stat->neut_species_coll_tm + stat->neut_species_react_tm + + stat->neut_species_omega_cfl_tm + stat->neut_species_src_tm + stat->dfdt_dt_reduce_tm + + stat->fwd_euler_step_f_tm; + stat->field_sum_tm = stat->field_phi_rhs_tm + stat->field_phi_solve_tm; stat->bc_sum_tm = stat->species_bc_tm + stat->neut_species_bc_tm; stat->time_rate_diags_sum_tm = stat->fdot_tm + stat->phidot_tm; - stat->pos_shift_sum_tm = stat->species_pos_shift_tm + stat->neut_species_pos_shift_tm + stat->pos_shift_quasineut_tm; - stat->time_stepper_sum_tm = stat->fwd_euler_tm + stat->field_tm + stat->bc_tm + stat->time_rate_diags_tm - + stat->pos_shift_tm + stat->time_stepper_arithmetic_tm; - stat->io_sum_tm = stat->species_io_tm + stat->species_diag_calc_tm + stat->species_diag_io_tm + stat->neut_species_io_tm - + stat->neut_species_diag_calc_tm + stat->neut_species_diag_io_tm + stat->field_io_tm + stat->field_diag_calc_tm - + stat->field_diag_io_tm + stat->app_io_tm; + stat->pos_shift_sum_tm = + stat->species_pos_shift_tm + stat->neut_species_pos_shift_tm + stat->pos_shift_quasineut_tm; + stat->time_stepper_sum_tm = stat->fwd_euler_tm + stat->field_tm + stat->bc_tm + + stat->time_rate_diags_tm + stat->pos_shift_tm + + stat->time_stepper_arithmetic_tm; + stat->io_sum_tm = stat->species_io_tm + stat->species_diag_calc_tm + stat->species_diag_io_tm + + stat->neut_species_io_tm + stat->neut_species_diag_calc_tm + + stat->neut_species_diag_io_tm + stat->field_io_tm + stat->field_diag_calc_tm + + stat->field_diag_io_tm + stat->app_io_tm; return *stat; } -static inline -double -ratio_to_percent(double num, double den, double alt) +static inline double ratio_to_percent(double num, double den, double alt) { - return den > 1e-12 ? 100.*num/den : alt; + return den > 1e-12 ? 100. * num / den : alt; } -void -gkyl_gyrokinetic_app_print_timings(gkyl_gyrokinetic_app* app, FILE *iostream) +void gkyl_gyrokinetic_app_print_timings(gkyl_gyrokinetic_app *app, FILE *iostream) { struct gkyl_gyrokinetic_stat *stat = &app->stat; - double bflux_tm = stat->species_bflux_calc_tm+stat->species_bflux_moms_tm; + double bflux_tm = stat->species_bflux_calc_tm + stat->species_bflux_moms_tm; gkyl_gyrokinetic_app_cout(app, iostream, "Timing:\n"); - gkyl_gyrokinetic_app_cout(app, iostream, " - Time loop: %.4e sec.\n", stat->time_loop_tm); - gkyl_gyrokinetic_app_cout(app, iostream, " * Forward Euler: %.4e sec. / %4.2f %%.\n", stat->fwd_euler_tm, ratio_to_percent(stat->fwd_euler_tm,stat->time_loop_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Collision moments (charged): %.4e sec. / %4.2f %%.\n", stat->species_coll_mom_tm , ratio_to_percent(stat->species_coll_mom_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Reaction moments (charged): %.4e sec. / %4.2f %%.\n", stat->species_react_mom_tm , ratio_to_percent(stat->species_react_mom_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Collision moments (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_coll_mom_tm , ratio_to_percent(stat->neut_species_coll_mom_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Reaction moments (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_react_mom_tm , ratio_to_percent(stat->neut_species_react_mom_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Radiation moments: %.4e sec. / %4.2f %%.\n", stat->species_rad_mom_tm , ratio_to_percent(stat->species_rad_mom_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Species gyroaverage: %.4e sec. / %4.2f %%.\n", stat->species_gyroavg_tm , ratio_to_percent(stat->species_gyroavg_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Species LTE: %.4e sec. / %4.2f %%.\n", stat->species_lte_tm , ratio_to_percent(stat->species_lte_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Collisionless terms (charged): %.4e sec. / %4.2f %%.\n", stat->species_collisionless_tm , ratio_to_percent(stat->species_collisionless_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Collision terms (charged): %.4e sec. / %4.2f %%.\n", stat->species_coll_tm , ratio_to_percent(stat->species_coll_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Damping (charged): %.4e sec. / %4.2f %%.\n", stat->species_damp_tm , ratio_to_percent(stat->species_damp_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ df/dt multiplier (charged): %.4e sec. / %4.2f %%.\n", stat->species_fdot_mult_tm , ratio_to_percent(stat->species_fdot_mult_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Diffusion (charged): %.4e sec. / %4.2f %%.\n", stat->species_diffusion_tm , ratio_to_percent(stat->species_diffusion_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Radiation terms: %.4e sec. / %4.2f %%.\n", stat->species_rad_tm , ratio_to_percent(stat->species_rad_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Reaction terms (charged): %.4e sec. / %4.2f %%.\n", stat->species_react_tm , ratio_to_percent(stat->species_react_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Boundary fluxes (charged): %.4e sec. / %4.2f %%.\n", bflux_tm , ratio_to_percent(bflux_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ omega_cfl (charged): %.4e sec. / %4.2f %%.\n", stat->species_omega_cfl_tm , ratio_to_percent(stat->species_omega_cfl_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Sources (charged): %.4e sec. / %4.2f %%.\n", stat->species_src_tm , ratio_to_percent(stat->species_src_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ BGK Sources (charged): %.4e sec. / %4.2f %%.\n", stat->species_source_bgk_tm , ratio_to_percent(stat->species_source_bgk_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Collisionless terms (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_collisionless_tm, ratio_to_percent(stat->neut_species_collisionless_tm,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Species LTE (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_lte_tm , ratio_to_percent(stat->neut_species_lte_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Boundary fluxes (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_bflux_calc_tm +stat->neut_species_bflux_moms_tm, ratio_to_percent(stat->neut_species_bflux_calc_tm +stat->neut_species_bflux_moms_tm,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Collision terms (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_coll_tm , ratio_to_percent(stat->neut_species_coll_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Reaction terms (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_react_tm , ratio_to_percent(stat->neut_species_react_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ omega_cfl (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_omega_cfl_tm , ratio_to_percent(stat->neut_species_omega_cfl_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Sources (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_src_tm , ratio_to_percent(stat->neut_species_src_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Time step reduction: %.4e sec. / %4.2f %%.\n", stat->dfdt_dt_reduce_tm , ratio_to_percent(stat->dfdt_dt_reduce_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Step f: %.4e sec. / %4.2f %%.\n", stat->fwd_euler_step_f_tm , ratio_to_percent(stat->fwd_euler_step_f_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Accounted for: %4.2f %%.\n", ratio_to_percent(stat->fwd_euler_sum_tm, stat->fwd_euler_tm, 100.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Field solves: %.4e sec. / %4.2f %%.\n", stat->field_tm, ratio_to_percent(stat->field_tm,stat->time_loop_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Phi eqn RHS: %.4e sec. / %4.2f %%.\n", stat->field_phi_rhs_tm , ratio_to_percent(stat->field_phi_rhs_tm ,stat->field_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Phi eqn solve: %.4e sec. / %4.2f %%.\n", stat->field_phi_solve_tm, ratio_to_percent(stat->field_phi_solve_tm,stat->field_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Accounted for: %4.2f %%.\n", ratio_to_percent(stat->field_sum_tm, stat->field_tm, 100.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Boundary conditions:: %.4e sec. / %4.2f %%.\n", stat->bc_tm, ratio_to_percent(stat->bc_tm,stat->time_loop_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Species (charged): %.4e sec. / %4.2f %%.\n", stat->species_bc_tm , ratio_to_percent(stat->species_bc_tm ,stat->bc_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Species (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_bc_tm, ratio_to_percent(stat->neut_species_bc_tm,stat->bc_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Accounted for: %4.2f %%.\n", ratio_to_percent(stat->bc_sum_tm, stat->bc_tm, 100.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Time rate diagnostics: %.4e sec. / %4.2f %%.\n", stat->time_rate_diags_tm, ratio_to_percent(stat->time_rate_diags_tm,stat->time_loop_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Charged species: %.4e sec. / %4.2f %%.\n", stat->fdot_tm , ratio_to_percent(stat->fdot_tm ,stat->time_rate_diags_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Phi: %.4e sec. / %4.2f %%.\n", stat->phidot_tm, ratio_to_percent(stat->phidot_tm,stat->time_rate_diags_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Accounted for: %4.2f %%.\n", ratio_to_percent(stat->time_rate_diags_sum_tm, stat->time_rate_diags_tm, 100.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Positivity: %.4e sec. / %4.2f %%.\n", stat->pos_shift_tm, ratio_to_percent(stat->pos_shift_tm,stat->time_loop_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Species (charged): %.4e sec. / %4.2f %%.\n", stat->species_pos_shift_tm , ratio_to_percent(stat->species_pos_shift_tm ,stat->pos_shift_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Species (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_pos_shift_tm, ratio_to_percent(stat->neut_species_pos_shift_tm,stat->pos_shift_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Quasineutrality: %.4e sec. / %4.2f %%.\n", stat->pos_shift_quasineut_tm , ratio_to_percent(stat->pos_shift_quasineut_tm ,stat->pos_shift_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " ^ Accounted for: %4.2f %%.\n", ratio_to_percent(stat->pos_shift_sum_tm, stat->pos_shift_tm, 100.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Time stepper arithmetic: %.4e sec. / %4.2f %%.\n", stat->time_stepper_arithmetic_tm, ratio_to_percent(stat->time_stepper_arithmetic_tm,stat->time_loop_tm, 0.0)); - - gkyl_gyrokinetic_app_cout(app, iostream, " * Accounted for: %4.2f %%.\n", ratio_to_percent(stat->time_stepper_sum_tm, stat->time_loop_tm, 100.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " - I/O: %.4e sec.\n", stat->io_tm); - gkyl_gyrokinetic_app_cout(app, iostream, " * f write (charged): %.4e sec. / %4.2f %%.\n", stat->species_io_tm , ratio_to_percent(stat->species_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Species diag calc (charged): %.4e sec. / %4.2f %%.\n", stat->species_diag_calc_tm , ratio_to_percent(stat->species_diag_calc_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Species diag write (charged): %.4e sec. / %4.2f %%.\n", stat->species_diag_io_tm , ratio_to_percent(stat->species_diag_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * f write (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_io_tm , ratio_to_percent(stat->neut_species_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Species diag calc (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_diag_calc_tm, ratio_to_percent(stat->neut_species_diag_calc_tm, stat->io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Species diag write (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_diag_io_tm , ratio_to_percent(stat->neut_species_diag_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Field write: %.4e sec. / %4.2f %%.\n", stat->field_io_tm , ratio_to_percent(stat->field_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Field diag calc: %.4e sec. / %4.2f %%.\n", stat->field_diag_calc_tm , ratio_to_percent(stat->field_diag_calc_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Field diag write: %.4e sec. / %4.2f %%.\n", stat->field_diag_io_tm , ratio_to_percent(stat->field_diag_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Common write: %.4e sec. / %4.2f %%.\n", stat->app_io_tm , ratio_to_percent(stat->app_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, iostream, " * Accounted for: %4.2f %%.\n", ratio_to_percent(stat->io_sum_tm, stat->io_tm, 100.0)); + gkyl_gyrokinetic_app_cout( + app, iostream, " - Time loop: %.4e sec.\n", stat->time_loop_tm + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Forward Euler: %.4e sec. / %4.2f %%.\n", + stat->fwd_euler_tm, ratio_to_percent(stat->fwd_euler_tm, stat->time_loop_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Collision moments (charged): %.4e sec. / %4.2f %%.\n", + stat->species_coll_mom_tm, ratio_to_percent(stat->species_coll_mom_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Reaction moments (charged): %.4e sec. / %4.2f %%.\n", + stat->species_react_mom_tm, + ratio_to_percent(stat->species_react_mom_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Collision moments (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_coll_mom_tm, + ratio_to_percent(stat->neut_species_coll_mom_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Reaction moments (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_react_mom_tm, + ratio_to_percent(stat->neut_species_react_mom_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Radiation moments: %.4e sec. / %4.2f %%.\n", + stat->species_rad_mom_tm, ratio_to_percent(stat->species_rad_mom_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Species gyroaverage: %.4e sec. / %4.2f %%.\n", + stat->species_gyroavg_tm, ratio_to_percent(stat->species_gyroavg_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Species LTE: %.4e sec. / %4.2f %%.\n", + stat->species_lte_tm, ratio_to_percent(stat->species_lte_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Collisionless terms (charged): %.4e sec. / %4.2f %%.\n", + stat->species_collisionless_tm, + ratio_to_percent(stat->species_collisionless_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Collision terms (charged): %.4e sec. / %4.2f %%.\n", + stat->species_coll_tm, ratio_to_percent(stat->species_coll_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Damping (charged): %.4e sec. / %4.2f %%.\n", + stat->species_damp_tm, ratio_to_percent(stat->species_damp_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ df/dt multiplier (charged): %.4e sec. / %4.2f %%.\n", + stat->species_fdot_mult_tm, + ratio_to_percent(stat->species_fdot_mult_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Diffusion (charged): %.4e sec. / %4.2f %%.\n", + stat->species_diffusion_tm, + ratio_to_percent(stat->species_diffusion_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Radiation terms: %.4e sec. / %4.2f %%.\n", + stat->species_rad_tm, ratio_to_percent(stat->species_rad_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Reaction terms (charged): %.4e sec. / %4.2f %%.\n", + stat->species_react_tm, ratio_to_percent(stat->species_react_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Boundary fluxes (charged): %.4e sec. / %4.2f %%.\n", bflux_tm, + ratio_to_percent(bflux_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ omega_cfl (charged): %.4e sec. / %4.2f %%.\n", + stat->species_omega_cfl_tm, + ratio_to_percent(stat->species_omega_cfl_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Sources (charged): %.4e sec. / %4.2f %%.\n", + stat->species_src_tm, ratio_to_percent(stat->species_src_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ BGK Sources (charged): %.4e sec. / %4.2f %%.\n", + stat->species_source_bgk_tm, + ratio_to_percent(stat->species_source_bgk_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Collisionless terms (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_collisionless_tm, + ratio_to_percent(stat->neut_species_collisionless_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Species LTE (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_lte_tm, ratio_to_percent(stat->neut_species_lte_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Boundary fluxes (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_bflux_calc_tm + stat->neut_species_bflux_moms_tm, + ratio_to_percent( + stat->neut_species_bflux_calc_tm + stat->neut_species_bflux_moms_tm, stat->fwd_euler_tm, 0.0 + ) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Collision terms (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_coll_tm, + ratio_to_percent(stat->neut_species_coll_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Reaction terms (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_react_tm, + ratio_to_percent(stat->neut_species_react_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ omega_cfl (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_omega_cfl_tm, + ratio_to_percent(stat->neut_species_omega_cfl_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Sources (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_src_tm, ratio_to_percent(stat->neut_species_src_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Time step reduction: %.4e sec. / %4.2f %%.\n", + stat->dfdt_dt_reduce_tm, ratio_to_percent(stat->dfdt_dt_reduce_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Step f: %.4e sec. / %4.2f %%.\n", + stat->fwd_euler_step_f_tm, ratio_to_percent(stat->fwd_euler_step_f_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->fwd_euler_sum_tm, stat->fwd_euler_tm, 100.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Field solves: %.4e sec. / %4.2f %%.\n", stat->field_tm, + ratio_to_percent(stat->field_tm, stat->time_loop_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Phi eqn RHS: %.4e sec. / %4.2f %%.\n", + stat->field_phi_rhs_tm, ratio_to_percent(stat->field_phi_rhs_tm, stat->field_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Phi eqn solve: %.4e sec. / %4.2f %%.\n", + stat->field_phi_solve_tm, ratio_to_percent(stat->field_phi_solve_tm, stat->field_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->field_sum_tm, stat->field_tm, 100.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Boundary conditions:: %.4e sec. / %4.2f %%.\n", stat->bc_tm, + ratio_to_percent(stat->bc_tm, stat->time_loop_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Species (charged): %.4e sec. / %4.2f %%.\n", + stat->species_bc_tm, ratio_to_percent(stat->species_bc_tm, stat->bc_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Species (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_bc_tm, ratio_to_percent(stat->neut_species_bc_tm, stat->bc_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->bc_sum_tm, stat->bc_tm, 100.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Time rate diagnostics: %.4e sec. / %4.2f %%.\n", + stat->time_rate_diags_tm, ratio_to_percent(stat->time_rate_diags_tm, stat->time_loop_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Charged species: %.4e sec. / %4.2f %%.\n", stat->fdot_tm, + ratio_to_percent(stat->fdot_tm, stat->time_rate_diags_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Phi: %.4e sec. / %4.2f %%.\n", + stat->phidot_tm, ratio_to_percent(stat->phidot_tm, stat->time_rate_diags_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->time_rate_diags_sum_tm, stat->time_rate_diags_tm, 100.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Positivity: %.4e sec. / %4.2f %%.\n", + stat->pos_shift_tm, ratio_to_percent(stat->pos_shift_tm, stat->time_loop_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Species (charged): %.4e sec. / %4.2f %%.\n", + stat->species_pos_shift_tm, + ratio_to_percent(stat->species_pos_shift_tm, stat->pos_shift_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Species (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_pos_shift_tm, + ratio_to_percent(stat->neut_species_pos_shift_tm, stat->pos_shift_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Quasineutrality: %.4e sec. / %4.2f %%.\n", + stat->pos_shift_quasineut_tm, + ratio_to_percent(stat->pos_shift_quasineut_tm, stat->pos_shift_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " ^ Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->pos_shift_sum_tm, stat->pos_shift_tm, 100.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Time stepper arithmetic: %.4e sec. / %4.2f %%.\n", + stat->time_stepper_arithmetic_tm, + ratio_to_percent(stat->time_stepper_arithmetic_tm, stat->time_loop_tm, 0.0) + ); + + gkyl_gyrokinetic_app_cout( + app, iostream, " * Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->time_stepper_sum_tm, stat->time_loop_tm, 100.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " - I/O: %.4e sec.\n", stat->io_tm + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * f write (charged): %.4e sec. / %4.2f %%.\n", + stat->species_io_tm, ratio_to_percent(stat->species_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Species diag calc (charged): %.4e sec. / %4.2f %%.\n", + stat->species_diag_calc_tm, ratio_to_percent(stat->species_diag_calc_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Species diag write (charged): %.4e sec. / %4.2f %%.\n", + stat->species_diag_io_tm, ratio_to_percent(stat->species_diag_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * f write (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_io_tm, ratio_to_percent(stat->neut_species_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Species diag calc (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_diag_calc_tm, + ratio_to_percent(stat->neut_species_diag_calc_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Species diag write (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_diag_io_tm, ratio_to_percent(stat->neut_species_diag_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Field write: %.4e sec. / %4.2f %%.\n", + stat->field_io_tm, ratio_to_percent(stat->field_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Field diag calc: %.4e sec. / %4.2f %%.\n", + stat->field_diag_calc_tm, ratio_to_percent(stat->field_diag_calc_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Field diag write: %.4e sec. / %4.2f %%.\n", + stat->field_diag_io_tm, ratio_to_percent(stat->field_diag_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Common write: %.4e sec. / %4.2f %%.\n", + stat->app_io_tm, ratio_to_percent(stat->app_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, iostream, " * Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->io_sum_tm, stat->io_tm, 100.0) + ); } static void -range_stat_write(gkyl_gyrokinetic_app* app, const char *nm, const struct gkyl_range *r, FILE *fp) +range_stat_write(gkyl_gyrokinetic_app *app, const char *nm, const struct gkyl_range *r, FILE *fp) { gkyl_gyrokinetic_app_cout(app, fp, " %s_cells : [ ", nm); - for (int i=0; indim; ++i) + for (int i = 0; i < r->ndim; ++i) { gkyl_gyrokinetic_app_cout(app, fp, " %d, ", gkyl_range_shape(r, i)); + } gkyl_gyrokinetic_app_cout(app, fp, " ],\n"); } // ensure stats across processors are made consistent -static void -comm_reduce_app_stat(const gkyl_gyrokinetic_app* app, - const struct gkyl_gyrokinetic_stat *local, struct gkyl_gyrokinetic_stat *global) +static void comm_reduce_app_stat( + const gkyl_gyrokinetic_app *app, const struct gkyl_gyrokinetic_stat *local, + struct gkyl_gyrokinetic_stat *global +) { int comm_sz; gkyl_comm_get_size(app->comm, &comm_sz); @@ -2600,7 +3073,7 @@ comm_reduce_app_stat(const gkyl_gyrokinetic_app* app, [NUP] = local->nup, [NFEULER] = local->nfeuler, [NSTAGE_2_FAIL] = local->nstage_2_fail, - [NSTAGE_3_FAIL] = local->nstage_3_fail, + [NSTAGE_3_FAIL] = local->nstage_3_fail }; int64_t l_red_global[L_END]; @@ -2609,23 +3082,25 @@ comm_reduce_app_stat(const gkyl_gyrokinetic_app* app, global->nup = l_red_global[NUP]; global->nfeuler = l_red_global[NFEULER]; global->nstage_2_fail = l_red_global[NSTAGE_2_FAIL]; - global->nstage_3_fail = l_red_global[NSTAGE_3_FAIL]; + global->nstage_3_fail = l_red_global[NSTAGE_3_FAIL]; int64_t l_red_n_iter_corr[app->num_species]; int64_t l_red_num_corr[app->num_species]; - for (int s=0; snum_species; ++s) { + for (int s = 0; s < app->num_species; ++s) { l_red_n_iter_corr[s] = local->n_iter_corr[s]; l_red_num_corr[s] = local->num_corr[s]; } int64_t l_red_global_n_iter_corr[app->num_species]; int64_t l_red_global_num_corr[app->num_species]; - gkyl_comm_allreduce_host(app->comm, GKYL_INT_64, GKYL_MAX, app->num_species, - l_red_n_iter_corr, l_red_global_n_iter_corr); - gkyl_comm_allreduce_host(app->comm, GKYL_INT_64, GKYL_MAX, app->num_species, - l_red_num_corr, l_red_global_num_corr); - - for (int s=0; snum_species; ++s) { + gkyl_comm_allreduce_host( + app->comm, GKYL_INT_64, GKYL_MAX, app->num_species, l_red_n_iter_corr, l_red_global_n_iter_corr + ); + gkyl_comm_allreduce_host( + app->comm, GKYL_INT_64, GKYL_MAX, app->num_species, l_red_num_corr, l_red_global_num_corr + ); + + for (int s = 0; s < app->num_species; ++s) { global->n_iter_corr[s] = l_red_global_n_iter_corr[s]; global->num_corr[s] = l_red_global_num_corr[s]; } @@ -2633,42 +3108,85 @@ comm_reduce_app_stat(const gkyl_gyrokinetic_app* app, if (app->num_neut_species > 0) { int64_t l_red_neut_n_iter_corr[app->num_neut_species]; int64_t l_red_neut_num_corr[app->num_neut_species]; - for (int s=0; snum_neut_species; ++s) { + for (int s = 0; s < app->num_neut_species; ++s) { l_red_neut_n_iter_corr[s] = local->neut_n_iter_corr[s]; l_red_neut_num_corr[s] = local->neut_num_corr[s]; } int64_t l_red_global_neut_n_iter_corr[app->num_neut_species]; int64_t l_red_global_neut_num_corr[app->num_neut_species]; - gkyl_comm_allreduce_host(app->comm, GKYL_INT_64, GKYL_MAX, app->num_neut_species, - l_red_neut_n_iter_corr, l_red_global_neut_n_iter_corr); - gkyl_comm_allreduce_host(app->comm, GKYL_INT_64, GKYL_MAX, app->num_neut_species, - l_red_neut_num_corr, l_red_global_neut_num_corr); + gkyl_comm_allreduce_host( + app->comm, GKYL_INT_64, GKYL_MAX, app->num_neut_species, l_red_neut_n_iter_corr, + l_red_global_neut_n_iter_corr + ); + gkyl_comm_allreduce_host( + app->comm, GKYL_INT_64, GKYL_MAX, app->num_neut_species, l_red_neut_num_corr, + l_red_global_neut_num_corr + ); - for (int s=0; snum_neut_species; ++s) { + for (int s = 0; s < app->num_neut_species; ++s) { global->neut_n_iter_corr[s] = l_red_global_neut_n_iter_corr[s]; global->neut_num_corr[s] = l_red_global_neut_num_corr[s]; } } enum { - INIT_SPECIES_TM, INIT_NEUT_SPECIES_TM, - TIME_LOOP_TM, FWD_EULER_TM, FWD_EULER_STEP_F_TM, DFDT_DT_REDUCE_TM, - SPECIES_COLLISIONLESS_TM, SPECIES_LTE_TM, SPECIES_GYROAVG_TM, - SPECIES_BFLUX_CALC_TM, SPECIES_BFLUX_MOMS_TM, SPECIES_DAMP_TM, SPECIES_FDOT_MULT_TM, SPECIES_DIFFUSION_TM, - SPECIES_COLL_MOM_TM, SPECIES_COLL_TM, - SPECIES_RAD_MOM_TM, SPECIES_RAD_TM, SPECIES_REACT_MOM_TM, SPECIES_REACT_TM, SPECIES_SRC_TM, SPECIES_SOURCE_BGK_TM, SPECIES_OMEGA_CFL_TM, - NEUT_SPECIES_COLLISIONLESS_TM, NEUT_SPECIES_LTE_TM, NEUT_SPECIES_BFLUX_CALC_TM, NEUT_SPECIES_BFLUX_MOMS_TM, - NEUT_SPECIES_COLL_MOM_TM, NEUT_SPECIES_COLL_TM, - NEUT_SPECIES_REACT_MOM_TM, NEUT_SPECIES_REACT_TM, NEUT_SPECIES_SRC_TM, NEUT_SPECIES_OMEGA_CFL_TM, - FDOT_TM, PHIDOT_TM, FIELD_TM, FIELD_PHI_RHS_TM, FIELD_PHI_SOLVE_TM, - BC_TM, SPECIES_BC_TM, NEUT_SPECIES_BC_TM, + INIT_SPECIES_TM, + INIT_NEUT_SPECIES_TM, + TIME_LOOP_TM, + FWD_EULER_TM, + FWD_EULER_STEP_F_TM, + DFDT_DT_REDUCE_TM, + SPECIES_COLLISIONLESS_TM, + SPECIES_LTE_TM, + SPECIES_GYROAVG_TM, + SPECIES_BFLUX_CALC_TM, + SPECIES_BFLUX_MOMS_TM, + SPECIES_DAMP_TM, + SPECIES_FDOT_MULT_TM, + SPECIES_DIFFUSION_TM, + SPECIES_COLL_MOM_TM, + SPECIES_COLL_TM, + SPECIES_RAD_MOM_TM, + SPECIES_RAD_TM, + SPECIES_REACT_MOM_TM, + SPECIES_REACT_TM, + SPECIES_SRC_TM, + SPECIES_SOURCE_BGK_TM, + SPECIES_OMEGA_CFL_TM, + NEUT_SPECIES_COLLISIONLESS_TM, + NEUT_SPECIES_LTE_TM, + NEUT_SPECIES_BFLUX_CALC_TM, + NEUT_SPECIES_BFLUX_MOMS_TM, + NEUT_SPECIES_COLL_MOM_TM, + NEUT_SPECIES_COLL_TM, + NEUT_SPECIES_REACT_MOM_TM, + NEUT_SPECIES_REACT_TM, + NEUT_SPECIES_SRC_TM, + NEUT_SPECIES_OMEGA_CFL_TM, + FDOT_TM, + PHIDOT_TM, + FIELD_TM, + FIELD_PHI_RHS_TM, + FIELD_PHI_SOLVE_TM, + BC_TM, + SPECIES_BC_TM, + NEUT_SPECIES_BC_TM, TIME_STEPPER_ARITHMETIC_TM, - SPECIES_POS_SHIFT_TM, NEUT_SPECIES_POS_SHIFT_TM, POS_SHIFT_QUASINEUT_TM, - SPECIES_IO_TM, SPECIES_DIAG_CALC_TM, SPECIES_DIAG_IO_TM, - NEUT_SPECIES_IO_TM, NEUT_SPECIES_DIAG_CALC_TM, NEUT_SPECIES_DIAG_IO_TM, - FIELD_IO_TM, FIELD_DIAG_CALC_TM, FIELD_DIAG_IO_TM, - APP_IO_TM, IO_TM, + SPECIES_POS_SHIFT_TM, + NEUT_SPECIES_POS_SHIFT_TM, + POS_SHIFT_QUASINEUT_TM, + SPECIES_IO_TM, + SPECIES_DIAG_CALC_TM, + SPECIES_DIAG_IO_TM, + NEUT_SPECIES_IO_TM, + NEUT_SPECIES_DIAG_CALC_TM, + NEUT_SPECIES_DIAG_IO_TM, + FIELD_IO_TM, + FIELD_DIAG_CALC_TM, + FIELD_DIAG_IO_TM, + APP_IO_TM, + IO_TM, D_END }; @@ -2727,12 +3245,12 @@ comm_reduce_app_stat(const gkyl_gyrokinetic_app* app, [FIELD_DIAG_CALC_TM] = local->field_diag_calc_tm, [FIELD_DIAG_IO_TM] = local->field_diag_io_tm, [APP_IO_TM] = local->app_io_tm, - [IO_TM] = local->io_tm, + [IO_TM] = local->io_tm }; double d_red_global[D_END]; gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, D_END, d_red, d_red_global); - + global->init_species_tm = d_red_global[INIT_SPECIES_TM]; global->init_neut_species_tm = d_red_global[INIT_NEUT_SPECIES_TM]; @@ -2805,18 +3323,19 @@ comm_reduce_app_stat(const gkyl_gyrokinetic_app* app, // misc data needing reduction - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_2_dt_diff, - global->stage_2_dt_diff); - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_3_dt_diff, - global->stage_3_dt_diff); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_2_dt_diff, global->stage_2_dt_diff + ); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_3_dt_diff, global->stage_3_dt_diff + ); } -void -gkyl_gyrokinetic_app_stat_write(gkyl_gyrokinetic_app* app) +void gkyl_gyrokinetic_app_stat_write(gkyl_gyrokinetic_app *app) { const char *fmt = "%s-%s"; int sz = gkyl_calc_strlen(fmt, app->name, "stat.json"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, "stat.json"); int num_ranks; @@ -2826,60 +3345,64 @@ gkyl_gyrokinetic_app_stat_write(gkyl_gyrokinetic_app* app) time_t t = time(NULL); struct tm curr_tm = *localtime(&t); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gk_s = &app->species[i]; - gk_species_n_iter_corr(app, gk_s, i); + gk_species_n_iter_corr(app, gk_s, i); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { struct gk_neut_species *gk_ns = &app->neut_species[i]; gk_neut_species_n_iter_corr(app, gk_ns, i); } - struct gkyl_gyrokinetic_stat stat = { }; + struct gkyl_gyrokinetic_stat stat = {}; comm_reduce_app_stat(app, &app->stat, &stat); - + int rank; gkyl_comm_get_rank(app->comm, &rank); // append to existing file so we have a history of different runs FILE *fp = 0; - if (rank == 0) fp = fopen(fileNm, "a"); + if (rank == 0) { + fp = fopen(fileNm, "a"); + } gkyl_gyrokinetic_app_cout(app, fp, "{\n"); - if (strftime(buff, sizeof buff, "%c", &curr_tm)) + if (strftime(buff, sizeof buff, "%c", &curr_tm)) { gkyl_gyrokinetic_app_cout(app, fp, " date : %s,\n", buff); + } gkyl_gyrokinetic_app_cout(app, fp, " use_gpu : %d,\n", stat.use_gpu); - gkyl_gyrokinetic_app_cout(app, fp, " num_ranks : %d,\n", num_ranks); - - for (int s=0; snum_species; ++s) + gkyl_gyrokinetic_app_cout(app, fp, " num_ranks : %d,\n", num_ranks); + + for (int s = 0; s < app->num_species; ++s) { range_stat_write(app, app->species[s].info.name, &app->species[s].global, fp); - + } + gkyl_gyrokinetic_app_cout(app, fp, " nup : %ld,\n", stat.nup); gkyl_gyrokinetic_app_cout(app, fp, " nfeuler : %ld,\n", stat.nfeuler); gkyl_gyrokinetic_app_cout(app, fp, " nstage_2_fail : %ld,\n", stat.nstage_2_fail); gkyl_gyrokinetic_app_cout(app, fp, " nstage_3_fail : %ld,\n", stat.nstage_3_fail); - gkyl_gyrokinetic_app_cout(app, fp, " stage_2_dt_diff : [ %lg, %lg ],\n", - stat.stage_2_dt_diff[0], stat.stage_2_dt_diff[1]); - gkyl_gyrokinetic_app_cout(app, fp, " stage_3_dt_diff : [ %lg, %lg ],\n", - stat.stage_3_dt_diff[0], stat.stage_3_dt_diff[1]); + gkyl_gyrokinetic_app_cout( + app, fp, " stage_2_dt_diff : [ %lg, %lg ],\n", stat.stage_2_dt_diff[0], stat.stage_2_dt_diff[1] + ); + gkyl_gyrokinetic_app_cout( + app, fp, " stage_3_dt_diff : [ %lg, %lg ],\n", stat.stage_3_dt_diff[0], stat.stage_3_dt_diff[1] + ); gkyl_gyrokinetic_app_cout(app, fp, " init_species_tm : %lg,\n", stat.init_species_tm); gkyl_gyrokinetic_app_cout(app, fp, " init_neut_species_tm : %lg,\n", stat.init_neut_species_tm); - for (int s=0; snum_species; ++s) { - gkyl_gyrokinetic_app_cout(app, fp, " n_iter_corr[%d] : %ld,\n", s, - stat.n_iter_corr[s]); - gkyl_gyrokinetic_app_cout(app, fp, " num_corr[%d] : %ld,\n", s, - stat.num_corr[s]); + for (int s = 0; s < app->num_species; ++s) { + gkyl_gyrokinetic_app_cout(app, fp, " n_iter_corr[%d] : %ld,\n", s, stat.n_iter_corr[s]); + gkyl_gyrokinetic_app_cout(app, fp, " num_corr[%d] : %ld,\n", s, stat.num_corr[s]); } - for (int s=0; snum_neut_species; ++s) { - gkyl_gyrokinetic_app_cout(app, fp, " neut_n_iter_corr[%d] : %ld,\n", s, - stat.neut_n_iter_corr[s]); - gkyl_gyrokinetic_app_cout(app, fp, " neut_num_corr[%d] : %ld,\n", s, - stat.neut_num_corr[s]); + for (int s = 0; s < app->num_neut_species; ++s) { + gkyl_gyrokinetic_app_cout( + app, fp, " neut_n_iter_corr[%d] : %ld,\n", s, stat.neut_n_iter_corr[s] + ); + gkyl_gyrokinetic_app_cout(app, fp, " neut_num_corr[%d] : %ld,\n", s, stat.neut_num_corr[s]); } double bflux_tm = stat.species_bflux_calc_tm + stat.species_bflux_moms_tm; @@ -2887,140 +3410,333 @@ gkyl_gyrokinetic_app_stat_write(gkyl_gyrokinetic_app* app) // Timers for the time-stepping loop gkyl_gyrokinetic_app_cout(app, fp, " time_loop_tm : %.4e,\n", stat.time_loop_tm); gkyl_gyrokinetic_app_cout(app, fp, " fwd_euler_tm : %.4e,\n", stat.fwd_euler_tm); - gkyl_gyrokinetic_app_cout(app, fp, " fwd_euler_pct : %.2f,\n", ratio_to_percent(stat.fwd_euler_tm, stat.time_loop_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " fwd_euler_pct : %.2f,\n", ratio_to_percent(stat.fwd_euler_tm, stat.time_loop_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_coll_mom_tm : %.4e,\n", stat.species_coll_mom_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_coll_mom_pct : %.2f,\n", ratio_to_percent(stat.species_coll_mom_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_coll_mom_pct : %.2f,\n", + ratio_to_percent(stat.species_coll_mom_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_react_mom_tm : %.4e,\n", stat.species_react_mom_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_react_mom_pct : %.2f,\n", ratio_to_percent(stat.species_react_mom_tm, stat.fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_coll_mom_tm : %.4e,\n", stat.neut_species_coll_mom_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_coll_mom_pct : %.2f,\n", ratio_to_percent(stat.neut_species_coll_mom_tm, stat.fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_react_mom_tm : %.4e,\n", stat.neut_species_react_mom_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_react_mom_pct : %.2f,\n", ratio_to_percent(stat.neut_species_react_mom_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_react_mom_pct : %.2f,\n", + ratio_to_percent(stat.species_react_mom_tm, stat.fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_coll_mom_tm : %.4e,\n", stat.neut_species_coll_mom_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_coll_mom_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_coll_mom_tm, stat.fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_react_mom_tm : %.4e,\n", stat.neut_species_react_mom_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_react_mom_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_react_mom_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_rad_mom_tm : %.4e,\n", stat.species_rad_mom_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_rad_mom_pct : %.2f,\n", ratio_to_percent(stat.species_rad_mom_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_rad_mom_pct : %.2f,\n", + ratio_to_percent(stat.species_rad_mom_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_gyroavg_tm : %.4e,\n", stat.species_gyroavg_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_gyroavg_pct : %.2f,\n", ratio_to_percent(stat.species_gyroavg_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_gyroavg_pct : %.2f,\n", + ratio_to_percent(stat.species_gyroavg_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_lte_tm : %.4e,\n", stat.species_lte_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_lte_pct : %.2f,\n", ratio_to_percent(stat.species_lte_tm, stat.fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " species_collisionless_tm : %.4e,\n", stat.species_collisionless_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_collisionless_pct : %.2f,\n", ratio_to_percent(stat.species_collisionless_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_lte_pct : %.2f,\n", + ratio_to_percent(stat.species_lte_tm, stat.fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " species_collisionless_tm : %.4e,\n", stat.species_collisionless_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " species_collisionless_pct : %.2f,\n", + ratio_to_percent(stat.species_collisionless_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_coll_tm : %.4e,\n", stat.species_coll_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_coll_pct : %.2f,\n", ratio_to_percent(stat.species_coll_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_coll_pct : %.2f,\n", + ratio_to_percent(stat.species_coll_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_diffusion_tm : %.4e,\n", stat.species_diffusion_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_diffusion_pct : %.2f,\n", ratio_to_percent(stat.species_diffusion_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_diffusion_pct : %.2f,\n", + ratio_to_percent(stat.species_diffusion_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_rad_tm : %.4e,\n", stat.species_rad_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_rad_pct : %.2f,\n", ratio_to_percent(stat.species_rad_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_rad_pct : %.2f,\n", + ratio_to_percent(stat.species_rad_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_react_tm : %.4e,\n", stat.species_react_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_react_pct : %.2f,\n", ratio_to_percent(stat.species_react_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_react_pct : %.2f,\n", + ratio_to_percent(stat.species_react_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_damp_tm : %.4e,\n", stat.species_damp_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_damp_pct : %.2f,\n", ratio_to_percent(stat.species_damp_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_damp_pct : %.2f,\n", + ratio_to_percent(stat.species_damp_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_fdot_mult_tm : %.4e,\n", stat.species_fdot_mult_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_fdot_mult_pct : %.2f,\n", ratio_to_percent(stat.species_fdot_mult_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_fdot_mult_pct : %.2f,\n", + ratio_to_percent(stat.species_fdot_mult_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_bflux_calc_tm : %.4e,\n", stat.species_bflux_calc_tm); gkyl_gyrokinetic_app_cout(app, fp, " species_bflux_moms_tm : %.4e,\n", stat.species_bflux_moms_tm); gkyl_gyrokinetic_app_cout(app, fp, " species_bflux_tm : %.4e,\n", bflux_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_bflux_pct : %.2f,\n", ratio_to_percent(bflux_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_bflux_pct : %.2f,\n", ratio_to_percent(bflux_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_omega_cfl_tm : %.4e,\n", stat.species_omega_cfl_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_omega_cfl_pct : %.2f,\n", ratio_to_percent(stat.species_omega_cfl_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_omega_cfl_pct : %.2f,\n", + ratio_to_percent(stat.species_omega_cfl_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_src_tm : %.4e,\n", stat.species_src_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_src_pct : %.2f,\n", ratio_to_percent(stat.species_src_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_src_pct : %.2f,\n", + ratio_to_percent(stat.species_src_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_source_bgk_tm : %.4e,\n", stat.species_source_bgk_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_source_bgk_pct : %.2f,\n", ratio_to_percent(stat.species_source_bgk_tm, stat.fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_collisionless_tm : %.4e,\n", stat.neut_species_collisionless_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_collisionless_pct : %.2f,\n", ratio_to_percent(stat.neut_species_collisionless_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_source_bgk_pct : %.2f,\n", + ratio_to_percent(stat.species_source_bgk_tm, stat.fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_collisionless_tm : %.4e,\n", stat.neut_species_collisionless_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_collisionless_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_collisionless_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " neut_species_lte_tm : %.4e,\n", stat.neut_species_lte_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_lte_pct : %.2f,\n", ratio_to_percent(stat.neut_species_lte_tm, stat.fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_bflux_calc_tm : %.4e,\n", stat.neut_species_bflux_calc_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_bflux_moms_pct : %.2f,\n", ratio_to_percent(stat.neut_species_bflux_calc_tm, stat.fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_bflux_moms_tm : %.4e,\n", stat.neut_species_bflux_moms_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_bflux_moms_pct : %.2f,\n", ratio_to_percent(stat.neut_species_bflux_moms_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_lte_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_lte_tm, stat.fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_bflux_calc_tm : %.4e,\n", stat.neut_species_bflux_calc_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_bflux_moms_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_bflux_calc_tm, stat.fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_bflux_moms_tm : %.4e,\n", stat.neut_species_bflux_moms_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_bflux_moms_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_bflux_moms_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " neut_species_coll_tm : %.4e,\n", stat.neut_species_coll_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_coll_pct : %.2f,\n", ratio_to_percent(stat.neut_species_coll_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_coll_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_coll_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " neut_species_react_tm : %.4e,\n", stat.neut_species_react_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_react_pct : %.2f,\n", ratio_to_percent(stat.neut_species_react_tm, stat.fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_omega_cfl_tm : %.4e,\n", stat.neut_species_omega_cfl_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_omega_cfl_pct : %.2f,\n", ratio_to_percent(stat.neut_species_omega_cfl_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_react_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_react_tm, stat.fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_omega_cfl_tm : %.4e,\n", stat.neut_species_omega_cfl_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_omega_cfl_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_omega_cfl_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " neut_species_src_tm : %.4e,\n", stat.neut_species_src_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_src_pct : %.2f,\n", ratio_to_percent(stat.neut_species_src_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_src_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_src_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " dfdt_dt_reduce_tm : %.4e,\n", stat.dfdt_dt_reduce_tm); - gkyl_gyrokinetic_app_cout(app, fp, " dfdt_dt_reduce_pct : %.2f,\n", ratio_to_percent(stat.dfdt_dt_reduce_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " dfdt_dt_reduce_pct : %.2f,\n", + ratio_to_percent(stat.dfdt_dt_reduce_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " fwd_euler_step_f_tm : %.4e,\n", stat.fwd_euler_step_f_tm); - gkyl_gyrokinetic_app_cout(app, fp, " fwd_euler_step_f_pct : %.2f,\n", ratio_to_percent(stat.fwd_euler_step_f_tm, stat.fwd_euler_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " fwd_euler_step_f_pct : %.2f,\n", + ratio_to_percent(stat.fwd_euler_step_f_tm, stat.fwd_euler_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " fwd_euler_sum_tm : %.4e,\n", stat.fwd_euler_sum_tm); - gkyl_gyrokinetic_app_cout(app, fp, " fwd_euler_accounted_pct : %.2f,\n", ratio_to_percent(stat.fwd_euler_sum_tm, stat.fwd_euler_tm, 100.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " fwd_euler_accounted_pct : %.2f,\n", + ratio_to_percent(stat.fwd_euler_sum_tm, stat.fwd_euler_tm, 100.0) + ); // Field solve timers gkyl_gyrokinetic_app_cout(app, fp, " field_tm : %.4e,\n", stat.field_tm); - gkyl_gyrokinetic_app_cout(app, fp, " field_pct : %.2f,\n", ratio_to_percent(stat.field_tm, stat.time_loop_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " field_pct : %.2f,\n", ratio_to_percent(stat.field_tm, stat.time_loop_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " field_phi_rhs_tm : %.4e,\n", stat.field_phi_rhs_tm); - gkyl_gyrokinetic_app_cout(app, fp, " field_phi_rhs_pct : %.2f,\n", ratio_to_percent(stat.field_phi_rhs_tm, stat.field_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " field_phi_rhs_pct : %.2f,\n", + ratio_to_percent(stat.field_phi_rhs_tm, stat.field_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " field_phi_solve_tm : %.4e,\n", stat.field_phi_solve_tm); - gkyl_gyrokinetic_app_cout(app, fp, " field_phi_solve_pct : %.2f,\n", ratio_to_percent(stat.field_phi_solve_tm, stat.field_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " field_phi_solve_pct : %.2f,\n", + ratio_to_percent(stat.field_phi_solve_tm, stat.field_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " field_sum_tm : %.4e,\n", stat.field_sum_tm); - gkyl_gyrokinetic_app_cout(app, fp, " field_accounted_pct : %.2f,\n", ratio_to_percent(stat.field_sum_tm, stat.field_tm, 100.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " field_accounted_pct : %.2f,\n", + ratio_to_percent(stat.field_sum_tm, stat.field_tm, 100.0) + ); // Boundary condition timers gkyl_gyrokinetic_app_cout(app, fp, " bc_tm : %.4e,\n", stat.bc_tm); - gkyl_gyrokinetic_app_cout(app, fp, " bc_pct : %.2f,\n", ratio_to_percent(stat.bc_tm, stat.time_loop_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " bc_pct : %.2f,\n", ratio_to_percent(stat.bc_tm, stat.time_loop_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_bc_tm : %.4e,\n", stat.species_bc_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_bc_pct : %.2f,\n", ratio_to_percent(stat.species_bc_tm, stat.bc_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_bc_pct : %.2f,\n", ratio_to_percent(stat.species_bc_tm, stat.bc_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " neut_species_bc_tm : %.4e,\n", stat.neut_species_bc_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_bc_pct : %.2f,\n", ratio_to_percent(stat.neut_species_bc_tm, stat.bc_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_bc_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_bc_tm, stat.bc_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " bc_sum_tm : %.4e,\n", stat.bc_sum_tm); - gkyl_gyrokinetic_app_cout(app, fp, " bc_accounted_pct : %.2f,\n", ratio_to_percent(stat.bc_sum_tm, stat.bc_tm, 100.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " bc_accounted_pct : %.2f,\n", ratio_to_percent(stat.bc_sum_tm, stat.bc_tm, 100.0) + ); // Time rate diagnostic timers gkyl_gyrokinetic_app_cout(app, fp, " time_rate_diags_tm : %.4e,\n", stat.time_rate_diags_tm); - gkyl_gyrokinetic_app_cout(app, fp, " time_rate_diags_pct : %.2f,\n", ratio_to_percent(stat.time_rate_diags_tm, stat.time_loop_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " time_rate_diags_pct : %.2f,\n", + ratio_to_percent(stat.time_rate_diags_tm, stat.time_loop_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " fdot_tm : %.4e,\n", stat.fdot_tm); - gkyl_gyrokinetic_app_cout(app, fp, " fdot_pct : %.2f,\n", ratio_to_percent(stat.fdot_tm, stat.time_rate_diags_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " fdot_pct : %.2f,\n", ratio_to_percent(stat.fdot_tm, stat.time_rate_diags_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " phidot_tm : %.4e,\n", stat.phidot_tm); - gkyl_gyrokinetic_app_cout(app, fp, " phidot_pct : %.2f,\n", ratio_to_percent(stat.phidot_tm, stat.time_rate_diags_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " time_rate_diags_sum_tm : %.4e,\n", stat.time_rate_diags_sum_tm); - gkyl_gyrokinetic_app_cout(app, fp, " time_rate_diags_accounted_pct : %.2f,\n", ratio_to_percent(stat.time_rate_diags_sum_tm, stat.time_rate_diags_tm, 100.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " phidot_pct : %.2f,\n", ratio_to_percent(stat.phidot_tm, stat.time_rate_diags_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " time_rate_diags_sum_tm : %.4e,\n", stat.time_rate_diags_sum_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " time_rate_diags_accounted_pct : %.2f,\n", + ratio_to_percent(stat.time_rate_diags_sum_tm, stat.time_rate_diags_tm, 100.0) + ); // Position shift timers gkyl_gyrokinetic_app_cout(app, fp, " pos_shift_tm : %.4e,\n", stat.pos_shift_tm); - gkyl_gyrokinetic_app_cout(app, fp, " pos_shift_pct : %.2f,\n", ratio_to_percent(stat.pos_shift_tm, stat.time_loop_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " pos_shift_pct : %.2f,\n", ratio_to_percent(stat.pos_shift_tm, stat.time_loop_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_pos_shift_tm : %.4e,\n", stat.species_pos_shift_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_pos_shift_pct : %.2f,\n", ratio_to_percent(stat.species_pos_shift_tm, stat.pos_shift_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_pos_shift_tm : %.4e,\n", stat.neut_species_pos_shift_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_pos_shift_pct : %.2f,\n", ratio_to_percent(stat.neut_species_pos_shift_tm, stat.pos_shift_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " pos_shift_quasineut_tm : %.4e,\n", stat.pos_shift_quasineut_tm); - gkyl_gyrokinetic_app_cout(app, fp, " pos_shift_quasineut_pct : %.2f,\n", ratio_to_percent(stat.pos_shift_quasineut_tm, stat.pos_shift_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_pos_shift_pct : %.2f,\n", + ratio_to_percent(stat.species_pos_shift_tm, stat.pos_shift_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_pos_shift_tm : %.4e,\n", stat.neut_species_pos_shift_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_pos_shift_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_pos_shift_tm, stat.pos_shift_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " pos_shift_quasineut_tm : %.4e,\n", stat.pos_shift_quasineut_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " pos_shift_quasineut_pct : %.2f,\n", + ratio_to_percent(stat.pos_shift_quasineut_tm, stat.pos_shift_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " pos_shift_sum_tm : %.4e,\n", stat.pos_shift_sum_tm); - gkyl_gyrokinetic_app_cout(app, fp, " pos_shift_accounted_pct : %.2f,\n", ratio_to_percent(stat.pos_shift_sum_tm, stat.pos_shift_tm, 100.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " pos_shift_accounted_pct : %.2f,\n", + ratio_to_percent(stat.pos_shift_sum_tm, stat.pos_shift_tm, 100.0) + ); // Time stepper arithmetic timers - gkyl_gyrokinetic_app_cout(app, fp, " time_stepper_arithmetic_tm : %.4e,\n", stat.time_stepper_arithmetic_tm); - gkyl_gyrokinetic_app_cout(app, fp, " time_stepper_arithmetic_pct : %.2f,\n", ratio_to_percent(stat.time_stepper_arithmetic_tm, stat.time_loop_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " time_stepper_arithmetic_tm : %.4e,\n", stat.time_stepper_arithmetic_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " time_stepper_arithmetic_pct : %.2f,\n", + ratio_to_percent(stat.time_stepper_arithmetic_tm, stat.time_loop_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " time_stepper_sum_tm : %.4e,\n", stat.time_stepper_sum_tm); - gkyl_gyrokinetic_app_cout(app, fp, " time_stepper_accounted_pct : %.2f,\n", ratio_to_percent(stat.time_stepper_sum_tm, stat.time_loop_tm, 100.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " time_stepper_accounted_pct : %.2f,\n", + ratio_to_percent(stat.time_stepper_sum_tm, stat.time_loop_tm, 100.0) + ); // I/O timers gkyl_gyrokinetic_app_cout(app, fp, " io_tm : %.4e,\n", stat.io_tm); gkyl_gyrokinetic_app_cout(app, fp, " species_io_tm : %.4e,\n", stat.species_io_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_io_pct : %.2f,\n", ratio_to_percent(stat.species_io_tm, stat.io_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_io_pct : %.2f,\n", ratio_to_percent(stat.species_io_tm, stat.io_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_diag_calc_tm : %.4e,\n", stat.species_diag_calc_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_diag_calc_pct : %.2f,\n", ratio_to_percent(stat.species_diag_calc_tm, stat.io_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_diag_calc_pct : %.2f,\n", + ratio_to_percent(stat.species_diag_calc_tm, stat.io_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " species_diag_io_tm : %.4e,\n", stat.species_diag_io_tm); - gkyl_gyrokinetic_app_cout(app, fp, " species_diag_io_pct : %.2f,\n", ratio_to_percent(stat.species_diag_io_tm, stat.io_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " species_diag_io_pct : %.2f,\n", + ratio_to_percent(stat.species_diag_io_tm, stat.io_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " neut_species_io_tm : %.4e,\n", stat.neut_species_io_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_io_pct : %.2f,\n", ratio_to_percent(stat.neut_species_io_tm, stat.io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_diag_calc_tm : %.4e,\n", stat.neut_species_diag_calc_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_diag_calc_pct : %.2f,\n", ratio_to_percent(stat.neut_species_diag_calc_tm, stat.io_tm, 0.0)); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_diag_io_tm : %.4e,\n", stat.neut_species_diag_io_tm); - gkyl_gyrokinetic_app_cout(app, fp, " neut_species_diag_io_pct : %.2f,\n", ratio_to_percent(stat.neut_species_diag_io_tm, stat.io_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_io_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_io_tm, stat.io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_diag_calc_tm : %.4e,\n", stat.neut_species_diag_calc_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_diag_calc_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_diag_calc_tm, stat.io_tm, 0.0) + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_diag_io_tm : %.4e,\n", stat.neut_species_diag_io_tm + ); + gkyl_gyrokinetic_app_cout( + app, fp, " neut_species_diag_io_pct : %.2f,\n", + ratio_to_percent(stat.neut_species_diag_io_tm, stat.io_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " field_io_tm : %.4e,\n", stat.field_io_tm); - gkyl_gyrokinetic_app_cout(app, fp, " field_io_pct : %.2f,\n", ratio_to_percent(stat.field_io_tm, stat.io_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " field_io_pct : %.2f,\n", ratio_to_percent(stat.field_io_tm, stat.io_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " field_diag_calc_tm : %.4e,\n", stat.field_diag_calc_tm); - gkyl_gyrokinetic_app_cout(app, fp, " field_diag_calc_pct : %.2f,\n", ratio_to_percent(stat.field_diag_calc_tm, stat.io_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " field_diag_calc_pct : %.2f,\n", + ratio_to_percent(stat.field_diag_calc_tm, stat.io_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " field_diag_io_tm : %.4e,\n", stat.field_diag_io_tm); - gkyl_gyrokinetic_app_cout(app, fp, " field_diag_io_pct : %.2f,\n", ratio_to_percent(stat.field_diag_io_tm, stat.io_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " field_diag_io_pct : %.2f,\n", + ratio_to_percent(stat.field_diag_io_tm, stat.io_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " app_io_tm : %.4e,\n", stat.app_io_tm); - gkyl_gyrokinetic_app_cout(app, fp, " app_io_pct : %.2f,\n", ratio_to_percent(stat.app_io_tm, stat.io_tm, 0.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " app_io_pct : %.2f,\n", ratio_to_percent(stat.app_io_tm, stat.io_tm, 0.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " io_sum_tm : %.4e,\n", stat.io_sum_tm); - gkyl_gyrokinetic_app_cout(app, fp, " io_accounted_pct : %.2f,\n", ratio_to_percent(stat.io_sum_tm, stat.io_tm, 100.0)); + gkyl_gyrokinetic_app_cout( + app, fp, " io_accounted_pct : %.2f,\n", ratio_to_percent(stat.io_sum_tm, stat.io_tm, 100.0) + ); gkyl_gyrokinetic_app_cout(app, fp, " n_species_omega_cfl : %ld,\n", stat.n_species_omega_cfl); gkyl_gyrokinetic_app_cout(app, fp, " n_mom : %ld,\n", stat.n_mom); @@ -3028,7 +3744,9 @@ gkyl_gyrokinetic_app_stat_write(gkyl_gyrokinetic_app* app) gkyl_gyrokinetic_app_cout(app, fp, " n_io : %ld,\n", stat.n_io); gkyl_gyrokinetic_app_cout(app, fp, " n_diag_io : %ld,\n", stat.n_diag_io); - gkyl_gyrokinetic_app_cout(app, fp, " n_neut_species_omega_cfl : %ld,\n", stat.n_neut_species_omega_cfl); + gkyl_gyrokinetic_app_cout( + app, fp, " n_neut_species_omega_cfl : %ld,\n", stat.n_neut_species_omega_cfl + ); gkyl_gyrokinetic_app_cout(app, fp, " n_neut_mom : %ld,\n", stat.n_neut_mom); gkyl_gyrokinetic_app_cout(app, fp, " n_neut_diag : %ld,\n", stat.n_neut_diag); gkyl_gyrokinetic_app_cout(app, fp, " n_neut_io : %ld,\n", stat.n_neut_io); @@ -3040,19 +3758,17 @@ gkyl_gyrokinetic_app_stat_write(gkyl_gyrokinetic_app* app) gkyl_gyrokinetic_app_cout(app, fp, "}\n"); - if (rank == 0) - fclose(fp); - + if (rank == 0) { + fclose(fp); + } } -void -gkyl_gyrokinetic_app_save_dt(gkyl_gyrokinetic_app* app, double tm, double dt) +void gkyl_gyrokinetic_app_save_dt(gkyl_gyrokinetic_app *app, double tm, double dt) { gkyl_dynvec_append(app->dts, tm, &dt); } -void -gkyl_gyrokinetic_app_write_dt(gkyl_gyrokinetic_app* app) +void gkyl_gyrokinetic_app_write_dt(gkyl_gyrokinetic_app *app) { struct timespec wtm = gkyl_wall_clock(); int rank; @@ -3062,22 +3778,24 @@ gkyl_gyrokinetic_app_write_dt(gkyl_gyrokinetic_app* app) // Write integrated diagnostic moments. const char *fmt = "%s-%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, "dt"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, "dt"); if (app->is_first_dt_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Time step size." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Time step size."} }; int io_meta_len[] = {app->io_meta_basic_len, app->gk_geom->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {app->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = { + app->io_meta_basic, app->gk_geom->io_meta_basic, io_meta_phi + }; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(app->dts, fileNm, mt); app->is_first_dt_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(app->dts, fileNm); } } @@ -3087,47 +3805,49 @@ gkyl_gyrokinetic_app_write_dt(gkyl_gyrokinetic_app* app) app->stat.n_diag_io += 1; } -static struct gkyl_app_restart_status -header_from_file(gkyl_gyrokinetic_app *app, const char *fname) +static struct gkyl_app_restart_status header_from_file(gkyl_gyrokinetic_app *app, const char *fname) { - struct gkyl_app_restart_status rstat = { .io_status = GKYL_ARRAY_RIO_FOPEN_FAILED }; - + struct gkyl_app_restart_status rstat = {.io_status = GKYL_ARRAY_RIO_FOPEN_FAILED}; + FILE *fp = 0; - with_file(fp, fname, "r") { + with_file(fp, fname, "r") + { struct gkyl_rect_grid grid; struct gkyl_array_header_info hdr; rstat.io_status = gkyl_grid_sub_array_header_read_fp(&grid, &hdr, fp); if (GKYL_ARRAY_RIO_SUCCESS == rstat.io_status) { - if (hdr.etype != GKYL_DOUBLE) + if (hdr.etype != GKYL_DOUBLE) { rstat.io_status = GKYL_ARRAY_RIO_DATA_MISMATCH; + } } struct gkyl_msgpack_map_elem elem_list[] = { - { .key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, - { .key = "time", .elem_type = GKYL_MP_DOUBLE, .cval = 0 }, + {.key = "frame", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0}, + {.key = "time", .elem_type = GKYL_MP_DOUBLE, .cval = 0} }; - int elem_list_len = sizeof(elem_list)/sizeof(elem_list[0]); - gkyl_msgpack_to_map_elem_list(&(struct gkyl_msgpack_data) { - .meta = hdr.meta, - .meta_sz = hdr.meta_size - }, elem_list_len, elem_list); + int elem_list_len = sizeof(elem_list) / sizeof(elem_list[0]); + gkyl_msgpack_to_map_elem_list( + &(struct gkyl_msgpack_data){.meta = hdr.meta, .meta_sz = hdr.meta_size}, elem_list_len, + elem_list + ); rstat.frame = gkyl_msgpack_map_elem_get_uint(elem_list_len, elem_list, "frame"); rstat.stime = gkyl_msgpack_map_elem_get_double(elem_list_len, elem_list, "time"); gkyl_grid_sub_array_header_release(&hdr); } - + return rstat; } // // ............. Reading functions ............... // -// -static void -gyrokinetic_app_geometry_read_and_copy(gkyl_gyrokinetic_app* app, struct gkyl_array *arr, - struct gkyl_array *arr_host, char *path, char *varNm) +// +static void gyrokinetic_app_geometry_read_and_copy( + gkyl_gyrokinetic_app *app, struct gkyl_array *arr, struct gkyl_array *arr_host, char *path, + char *varNm +) { cstr fileNm = cstr_from_fmt("%s%s-%s.gkyl", path, app->name, varNm); @@ -3137,18 +3857,20 @@ gyrokinetic_app_geometry_read_and_copy(gkyl_gyrokinetic_app* app, struct gkyl_ar rstat.io_status = gkyl_comm_array_read(app->comm, &app->grid, &app->local, arr_host, fileNm.str); gkyl_array_copy(arr, arr_host); - } - else { - gkyl_gyrokinetic_app_cout(app, stderr, "*** Failed to read geometry file! (%s)\n", - gkyl_array_rio_status_msg(rstat.io_status)); + } else { + gkyl_gyrokinetic_app_cout( + app, stderr, "*** Failed to read geometry file! (%s)\n", + gkyl_array_rio_status_msg(rstat.io_status) + ); assert(false); } cstr_drop(&fileNm); } -static void -gyrokinetic_app_geometry_read_and_copy_surf(gkyl_gyrokinetic_app* app, struct gkyl_array *arr, - struct gkyl_array *arr_host, struct gkyl_array *arr_host_doubled, char *path, char *varNm, int dir) +static void gyrokinetic_app_geometry_read_and_copy_surf( + gkyl_gyrokinetic_app *app, struct gkyl_array *arr, struct gkyl_array *arr_host, + struct gkyl_array *arr_host_doubled, char *path, char *varNm, int dir +) { cstr fileNm = cstr_from_fmt("%s%s-geo_surf%d_%s.gkyl", path, app->name, dir, varNm); @@ -3158,73 +3880,82 @@ gyrokinetic_app_geometry_read_and_copy_surf(gkyl_gyrokinetic_app* app, struct gk rstat.io_status = gkyl_comm_array_read(app->comm, &app->grid, &app->local, arr_host_doubled, fileNm.str); gkyl_array_set_offset_range(arr_host, 1.0, arr_host_doubled, 0, &app->local); - gkyl_array_copy_range_to_range(arr_host_doubled, arr_host_doubled, - &app->local_upper_ghost[dir], &app->local_upper_skin[dir]); - gkyl_array_set_offset_range(arr_host, 1.0, arr_host_doubled, arr_host->ncomp, &app->local_upper_ghost[dir]); + gkyl_array_copy_range_to_range( + arr_host_doubled, arr_host_doubled, &app->local_upper_ghost[dir], &app->local_upper_skin[dir] + ); + gkyl_array_set_offset_range( + arr_host, 1.0, arr_host_doubled, arr_host->ncomp, &app->local_upper_ghost[dir] + ); gkyl_array_copy(arr, arr_host); - } - else { - gkyl_gyrokinetic_app_cout(app, stderr, "*** Failed to read geometry file! (%s)\n", - gkyl_array_rio_status_msg(rstat.io_status)); + } else { + gkyl_gyrokinetic_app_cout( + app, stderr, "*** Failed to read geometry file! (%s)\n", + gkyl_array_rio_status_msg(rstat.io_status) + ); assert(false); } cstr_drop(&fileNm); } -void -gkyl_gyrokinetic_app_read_geometry(gkyl_gyrokinetic_app* app, struct gkyl_gk_geometry_inp *geometry_inp) +void gkyl_gyrokinetic_app_read_geometry( + gkyl_gyrokinetic_app *app, struct gkyl_gk_geometry_inp *geometry_inp +) { - struct gkyl_array* arr_ho1 = mkarr(false, app->basis.num_basis, app->local_ext.volume); - struct gkyl_array* arr_ho3 = mkarr(false, 3*app->basis.num_basis, app->local_ext.volume); - struct gkyl_array* arr_ho6 = mkarr(false, 6*app->basis.num_basis, app->local_ext.volume); - struct gkyl_array* arr_ho9 = mkarr(false, 9*app->basis.num_basis, app->local_ext.volume); + struct gkyl_array *arr_ho1 = mkarr(false, app->basis.num_basis, app->local_ext.volume); + struct gkyl_array *arr_ho3 = mkarr(false, 3 * app->basis.num_basis, app->local_ext.volume); + struct gkyl_array *arr_ho6 = mkarr(false, 6 * app->basis.num_basis, app->local_ext.volume); + struct gkyl_array *arr_ho9 = mkarr(false, 9 * app->basis.num_basis, app->local_ext.volume); - cstr fileNm = cstr_from_fmt("%s%s-%s.gkyl", geometry_inp->geometry_path, app->name, "geo_int_jacobgeo"); + cstr fileNm = + cstr_from_fmt("%s%s-%s.gkyl", geometry_inp->geometry_path, app->name, "geo_int_jacobgeo"); struct gkyl_array_header_info hdr; FILE *fp; - with_file(fp, fileNm.str, "r") { - + with_file(fp, fileNm.str, "r") + { int status = gkyl_grid_sub_array_header_read_fp(&app->grid, &hdr, fp); // Read geometry ID from header. struct gkyl_msgpack_map_elem elem_list[] = { - { .key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, + {.key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0} }; - int elem_list_len = sizeof(elem_list)/sizeof(elem_list[0]); - gkyl_msgpack_to_map_elem_list(&(struct gkyl_msgpack_data) { - .meta = hdr.meta, - .meta_sz = hdr.meta_size - }, elem_list_len, elem_list); - app->gk_geom->geometry_id = gkyl_msgpack_map_elem_get_uint(elem_list_len, elem_list, "geometry_type"); - - if ((app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) || (app->gk_geom->geometry_id == GKYL_GEOMETRY_MIRROR)) { + int elem_list_len = sizeof(elem_list) / sizeof(elem_list[0]); + gkyl_msgpack_to_map_elem_list( + &(struct gkyl_msgpack_data){.meta = hdr.meta, .meta_sz = hdr.meta_size}, elem_list_len, + elem_list + ); + app->gk_geom->geometry_id = + gkyl_msgpack_map_elem_get_uint(elem_list_len, elem_list, "geometry_type"); + + if ((app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) || + (app->gk_geom->geometry_id == GKYL_GEOMETRY_MIRROR)) { // Read other metadata for numerical equilibrium from header. struct gkyl_msgpack_map_elem elem_list_numeq[] = { - { .key = "geqdsk_sign_convention", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, + {.key = "geqdsk_sign_convention", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0} }; - int elem_list_numeq_len = sizeof(elem_list)/sizeof(elem_list[0]); - gkyl_msgpack_to_map_elem_list(&(struct gkyl_msgpack_data) { - .meta = hdr.meta, - .meta_sz = hdr.meta_size - }, elem_list_numeq_len, elem_list_numeq); - app->gk_geom->geqdsk_sign_convention = gkyl_msgpack_map_elem_get_uint(elem_list_numeq_len, - elem_list_numeq, "geqdsk_sign_convention"); + int elem_list_numeq_len = sizeof(elem_list) / sizeof(elem_list[0]); + gkyl_msgpack_to_map_elem_list( + &(struct gkyl_msgpack_data){.meta = hdr.meta, .meta_sz = hdr.meta_size}, + elem_list_numeq_len, elem_list_numeq + ); + app->gk_geom->geqdsk_sign_convention = gkyl_msgpack_map_elem_get_uint( + elem_list_numeq_len, elem_list_numeq, "geqdsk_sign_convention" + ); } if (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK) { // Read other metadata for numerical equilibrium from header. struct gkyl_msgpack_map_elem elem_list_numeq[] = { - { .key = "half_domain", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0 }, + {.key = "half_domain", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 0} }; - int elem_list_numeq_len = sizeof(elem_list)/sizeof(elem_list[0]); - gkyl_msgpack_to_map_elem_list(&(struct gkyl_msgpack_data) { - .meta = hdr.meta, - .meta_sz = hdr.meta_size - }, elem_list_numeq_len, elem_list_numeq); - app->gk_geom->half_domain = gkyl_msgpack_map_elem_get_uint(elem_list_numeq_len, - elem_list_numeq, "half_domain"); + int elem_list_numeq_len = sizeof(elem_list) / sizeof(elem_list[0]); + gkyl_msgpack_to_map_elem_list( + &(struct gkyl_msgpack_data){.meta = hdr.meta, .meta_sz = hdr.meta_size}, + elem_list_numeq_len, elem_list_numeq + ); + app->gk_geom->half_domain = + gkyl_msgpack_map_elem_get_uint(elem_list_numeq_len, elem_list_numeq, "half_domain"); } gkyl_grid_sub_array_header_release(&hdr); @@ -3234,61 +3965,163 @@ gkyl_gyrokinetic_app_read_geometry(gkyl_gyrokinetic_app* app, struct gkyl_gk_geo gkyl_gk_geometry_reset_io_meta(app->gk_geom); // Update metadata inside geo object. // Read corner geo. - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_corn.mc2p , arr_ho3, geometry_inp->geometry_path, "geo_corn_mapc2p"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_corn.mc2nu_pos , arr_ho3, geometry_inp->geometry_path, "geo_corn_mc2nu_pos"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_corn.bmag , arr_ho1, geometry_inp->geometry_path, "geo_corn_bmag"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_corn.bmag_inv , arr_ho1, geometry_inp->geometry_path, "geo_corn_bmag_inv"); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_corn.mc2p, arr_ho3, geometry_inp->geometry_path, "geo_corn_mapc2p" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_corn.mc2nu_pos, arr_ho3, geometry_inp->geometry_path, + "geo_corn_mc2nu_pos" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_corn.bmag, arr_ho1, geometry_inp->geometry_path, "geo_corn_bmag" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_corn.bmag_inv, arr_ho1, geometry_inp->geometry_path, "geo_corn_bmag_inv" + ); // Read interior geo. - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.mc2p , arr_ho3, geometry_inp->geometry_path, "geo_int_mapc2p"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.bmag , arr_ho1, geometry_inp->geometry_path, "geo_int_bmag"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.g_ij , arr_ho6, geometry_inp->geometry_path, "geo_int_g_ij"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.dxdz , arr_ho9, geometry_inp->geometry_path, "geo_int_dxdz"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.dzdx , arr_ho9, geometry_inp->geometry_path, "geo_int_dzdx"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.normals , arr_ho9, geometry_inp->geometry_path, "geo_int_normals"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.jacobgeo , arr_ho1, geometry_inp->geometry_path, "geo_int_jacobgeo"); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.mc2p, arr_ho3, geometry_inp->geometry_path, "geo_int_mapc2p" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.bmag, arr_ho1, geometry_inp->geometry_path, "geo_int_bmag" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.g_ij, arr_ho6, geometry_inp->geometry_path, "geo_int_g_ij" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.dxdz, arr_ho9, geometry_inp->geometry_path, "geo_int_dxdz" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.dzdx, arr_ho9, geometry_inp->geometry_path, "geo_int_dzdx" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.normals, arr_ho9, geometry_inp->geometry_path, "geo_int_normals" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.jacobgeo, arr_ho1, geometry_inp->geometry_path, "geo_int_jacobgeo" + ); gkyl_array_copy(app->gk_geom->geo_int.jacobgeo_ghost, app->gk_geom->geo_int.jacobgeo); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.jacobgeo_inv , arr_ho1, geometry_inp->geometry_path, "geo_int_jacobgeo_inv"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.gij , arr_ho6, geometry_inp->geometry_path, "geo_int_gij"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.b_i , arr_ho3, geometry_inp->geometry_path, "geo_int_b_i"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.bcart , arr_ho3, geometry_inp->geometry_path, "geo_int_bcart"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.cmag , arr_ho1, geometry_inp->geometry_path, "geo_int_cmag"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.jacobtot , arr_ho1, geometry_inp->geometry_path, "geo_int_jacobtot"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.jacobtot_inv , arr_ho1, geometry_inp->geometry_path, "geo_int_jacobtot_inv"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.gxxj , arr_ho1, geometry_inp->geometry_path, "geo_int_gxxj"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.gxyj , arr_ho1, geometry_inp->geometry_path, "geo_int_gxyj"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.gyyj , arr_ho1, geometry_inp->geometry_path, "geo_int_gyyj"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.gxzj , arr_ho1, geometry_inp->geometry_path, "geo_int_gxzj"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.eps2 , arr_ho1, geometry_inp->geometry_path, "geo_int_eps2"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.qprofile , arr_ho1, geometry_inp->geometry_path, "geo_int_qprofile"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.rtg33inv , arr_ho1, geometry_inp->geometry_path, "geo_int_rtg33inv"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.dualcurlbhatoverB, arr_ho3, geometry_inp->geometry_path, "geo_int_dualcurlbhatoverB"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.dualcurlbhat , arr_ho3, geometry_inp->geometry_path, "geo_int_dualcurlbhat"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.bioverJB , arr_ho3, geometry_inp->geometry_path, "geo_int_bioverJB"); - gyrokinetic_app_geometry_read_and_copy(app, app->gk_geom->geo_int.B3 , arr_ho1, geometry_inp->geometry_path, "geo_int_B3"); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.jacobgeo_inv, arr_ho1, geometry_inp->geometry_path, + "geo_int_jacobgeo_inv" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.gij, arr_ho6, geometry_inp->geometry_path, "geo_int_gij" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.b_i, arr_ho3, geometry_inp->geometry_path, "geo_int_b_i" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.bcart, arr_ho3, geometry_inp->geometry_path, "geo_int_bcart" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.cmag, arr_ho1, geometry_inp->geometry_path, "geo_int_cmag" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.jacobtot, arr_ho1, geometry_inp->geometry_path, "geo_int_jacobtot" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.jacobtot_inv, arr_ho1, geometry_inp->geometry_path, + "geo_int_jacobtot_inv" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.gxxj, arr_ho1, geometry_inp->geometry_path, "geo_int_gxxj" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.gxyj, arr_ho1, geometry_inp->geometry_path, "geo_int_gxyj" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.gyyj, arr_ho1, geometry_inp->geometry_path, "geo_int_gyyj" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.gxzj, arr_ho1, geometry_inp->geometry_path, "geo_int_gxzj" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.eps2, arr_ho1, geometry_inp->geometry_path, "geo_int_eps2" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.qprofile, arr_ho1, geometry_inp->geometry_path, "geo_int_qprofile" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.rtg33inv, arr_ho1, geometry_inp->geometry_path, "geo_int_rtg33inv" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.dualcurlbhatoverB, arr_ho3, geometry_inp->geometry_path, + "geo_int_dualcurlbhatoverB" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.dualcurlbhat, arr_ho3, geometry_inp->geometry_path, + "geo_int_dualcurlbhat" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.bioverJB, arr_ho3, geometry_inp->geometry_path, "geo_int_bioverJB" + ); + gyrokinetic_app_geometry_read_and_copy( + app, app->gk_geom->geo_int.B3, arr_ho1, geometry_inp->geometry_path, "geo_int_B3" + ); // Read surf geo. - struct gkyl_array* arr_surf_ho1 = mkarr(false, app->gk_geom->num_surf_basis, app->local_ext.volume); - struct gkyl_array* arr_surf_ho2 = mkarr(false, 2*app->gk_geom->num_surf_basis, app->local_ext.volume); - struct gkyl_array* arr_surf_ho3 = mkarr(false, 3*app->gk_geom->num_surf_basis, app->local_ext.volume); - struct gkyl_array* arr_surf_ho6 = mkarr(false, 6*app->gk_geom->num_surf_basis, app->local_ext.volume); - struct gkyl_array* arr_surf_ho9 = mkarr(false, 9*app->gk_geom->num_surf_basis, app->local_ext.volume); - struct gkyl_array* arr_surf_ho18 = mkarr(false, 18*app->gk_geom->num_surf_basis, app->local_ext.volume); - for (int dir = 0; dircdim; dir++ ) { - gyrokinetic_app_geometry_read_and_copy_surf(app, app->gk_geom->geo_surf[dir].jacobgeo , arr_surf_ho1, arr_surf_ho2 , geometry_inp->geometry_path, "jacobgeo" , dir); - gyrokinetic_app_geometry_read_and_copy_surf(app, app->gk_geom->geo_surf[dir].jacobtot_inv, arr_surf_ho1, arr_surf_ho2 , geometry_inp->geometry_path, "jacobtot_inv", dir); - gyrokinetic_app_geometry_read_and_copy_surf(app, app->gk_geom->geo_surf[dir].b_i , arr_surf_ho3, arr_surf_ho6 , geometry_inp->geometry_path, "b_i" , dir); - gyrokinetic_app_geometry_read_and_copy_surf(app, app->gk_geom->geo_surf[dir].cmag , arr_surf_ho1, arr_surf_ho2 , geometry_inp->geometry_path, "cmag" , dir); - gyrokinetic_app_geometry_read_and_copy_surf(app, app->gk_geom->geo_surf[dir].bmag , arr_surf_ho1, arr_surf_ho2 , geometry_inp->geometry_path, "bmag" , dir); - gyrokinetic_app_geometry_read_and_copy_surf(app, app->gk_geom->geo_surf[dir].normcurlbhat, arr_surf_ho1, arr_surf_ho2 , geometry_inp->geometry_path, "normcurlbhat", dir); - gyrokinetic_app_geometry_read_and_copy_surf(app, app->gk_geom->geo_surf[dir].B3 , arr_surf_ho1, arr_surf_ho2 , geometry_inp->geometry_path, "B3" , dir); - gyrokinetic_app_geometry_read_and_copy_surf(app, app->gk_geom->geo_surf[dir].normals , arr_surf_ho9, arr_surf_ho18, geometry_inp->geometry_path, "normals" , dir); - gyrokinetic_app_geometry_read_and_copy_surf(app, app->gk_geom->geo_surf[dir].lenr , arr_surf_ho1, arr_surf_ho2 , geometry_inp->geometry_path, "lenr" , dir); - gyrokinetic_app_geometry_read_and_copy_surf(app, app->gk_geom->geo_surf[dir].bimpactangle, arr_surf_ho1, arr_surf_ho2 , geometry_inp->geometry_path, "bimpactangle", dir); - gyrokinetic_app_geometry_read_and_copy_surf(app, app->gk_geom->geo_surf[dir].deltats , arr_surf_ho1, arr_surf_ho2 , geometry_inp->geometry_path, "deltats" , dir); + struct gkyl_array *arr_surf_ho1 = + mkarr(false, app->gk_geom->num_surf_basis, app->local_ext.volume); + struct gkyl_array *arr_surf_ho2 = + mkarr(false, 2 * app->gk_geom->num_surf_basis, app->local_ext.volume); + struct gkyl_array *arr_surf_ho3 = + mkarr(false, 3 * app->gk_geom->num_surf_basis, app->local_ext.volume); + struct gkyl_array *arr_surf_ho6 = + mkarr(false, 6 * app->gk_geom->num_surf_basis, app->local_ext.volume); + struct gkyl_array *arr_surf_ho9 = + mkarr(false, 9 * app->gk_geom->num_surf_basis, app->local_ext.volume); + struct gkyl_array *arr_surf_ho18 = + mkarr(false, 18 * app->gk_geom->num_surf_basis, app->local_ext.volume); + for (int dir = 0; dir < app->cdim; dir++) { + gyrokinetic_app_geometry_read_and_copy_surf( + app, app->gk_geom->geo_surf[dir].jacobgeo, arr_surf_ho1, arr_surf_ho2, + geometry_inp->geometry_path, "jacobgeo", dir + ); + gyrokinetic_app_geometry_read_and_copy_surf( + app, app->gk_geom->geo_surf[dir].jacobtot_inv, arr_surf_ho1, arr_surf_ho2, + geometry_inp->geometry_path, "jacobtot_inv", dir + ); + gyrokinetic_app_geometry_read_and_copy_surf( + app, app->gk_geom->geo_surf[dir].b_i, arr_surf_ho3, arr_surf_ho6, geometry_inp->geometry_path, + "b_i", dir + ); + gyrokinetic_app_geometry_read_and_copy_surf( + app, app->gk_geom->geo_surf[dir].cmag, arr_surf_ho1, arr_surf_ho2, + geometry_inp->geometry_path, "cmag", dir + ); + gyrokinetic_app_geometry_read_and_copy_surf( + app, app->gk_geom->geo_surf[dir].bmag, arr_surf_ho1, arr_surf_ho2, + geometry_inp->geometry_path, "bmag", dir + ); + gyrokinetic_app_geometry_read_and_copy_surf( + app, app->gk_geom->geo_surf[dir].normcurlbhat, arr_surf_ho1, arr_surf_ho2, + geometry_inp->geometry_path, "normcurlbhat", dir + ); + gyrokinetic_app_geometry_read_and_copy_surf( + app, app->gk_geom->geo_surf[dir].B3, arr_surf_ho1, arr_surf_ho2, geometry_inp->geometry_path, + "B3", dir + ); + gyrokinetic_app_geometry_read_and_copy_surf( + app, app->gk_geom->geo_surf[dir].normals, arr_surf_ho9, arr_surf_ho18, + geometry_inp->geometry_path, "normals", dir + ); + gyrokinetic_app_geometry_read_and_copy_surf( + app, app->gk_geom->geo_surf[dir].lenr, arr_surf_ho1, arr_surf_ho2, + geometry_inp->geometry_path, "lenr", dir + ); + gyrokinetic_app_geometry_read_and_copy_surf( + app, app->gk_geom->geo_surf[dir].bimpactangle, arr_surf_ho1, arr_surf_ho2, + geometry_inp->geometry_path, "bimpactangle", dir + ); + gyrokinetic_app_geometry_read_and_copy_surf( + app, app->gk_geom->geo_surf[dir].deltats, arr_surf_ho1, arr_surf_ho2, + geometry_inp->geometry_path, "deltats", dir + ); // jacobgeo_ratio is not used in single block. gkyl_array_clear(app->gk_geom->geo_surf[dir].jacobgeo_ratio, 0.0); - gkyl_array_shiftc(app->gk_geom->geo_surf[dir].jacobgeo_ratio, pow(sqrt(2.0),app->cdim), 0); + gkyl_array_shiftc(app->gk_geom->geo_surf[dir].jacobgeo_ratio, pow(sqrt(2.0), app->cdim), 0); } gkyl_array_release(arr_ho1); @@ -3311,25 +4144,27 @@ gkyl_gyrokinetic_app_from_file_field(gkyl_gyrokinetic_app *app, const char *fnam if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { rstat.io_status = gkyl_comm_array_read(app->comm, &app->grid, &app->local, app->field->phi_host, fname); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(app->field->phi_smooth, app->field->phi_host); + } } - + return rstat; } -struct gkyl_app_restart_status -gkyl_gyrokinetic_app_from_file_species(gkyl_gyrokinetic_app *app, int sidx, - const char *fname) +struct gkyl_app_restart_status +gkyl_gyrokinetic_app_from_file_species(gkyl_gyrokinetic_app *app, int sidx, const char *fname) { struct gkyl_app_restart_status rstat = header_from_file(app, fname); struct gk_species *gk_s = &app->species[sidx]; - + if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { - rstat.io_status = gkyl_comm_array_read(gk_s->comm, &gk_s->grid, &gk_s->local, gk_s->f_host, fname); - if (app->use_gpu) + rstat.io_status = + gkyl_comm_array_read(gk_s->comm, &gk_s->grid, &gk_s->local, gk_s->f_host, fname); + if (app->use_gpu) { gkyl_array_copy(gk_s->f, gk_s->f_host); + } if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { gk_species_source_calc(app, gk_s, &gk_s->src, gk_s->lte.f_lte, 0.0); @@ -3341,18 +4176,19 @@ gkyl_gyrokinetic_app_from_file_species(gkyl_gyrokinetic_app *app, int sidx, return rstat; } -struct gkyl_app_restart_status -gkyl_gyrokinetic_app_from_file_neut_species(gkyl_gyrokinetic_app *app, int sidx, - const char *fname) +struct gkyl_app_restart_status +gkyl_gyrokinetic_app_from_file_neut_species(gkyl_gyrokinetic_app *app, int sidx, const char *fname) { struct gkyl_app_restart_status rstat = header_from_file(app, fname); struct gk_neut_species *gk_ns = &app->neut_species[sidx]; - + if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { - rstat.io_status = gkyl_comm_array_read(gk_ns->comm, &gk_ns->grid, &gk_ns->local, gk_ns->f_host, fname); - if (app->use_gpu) + rstat.io_status = + gkyl_comm_array_read(gk_ns->comm, &gk_ns->grid, &gk_ns->local, gk_ns->f_host, fname); + if (app->use_gpu) { gkyl_array_copy(gk_ns->f, gk_ns->f_host); + } if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { gk_neut_species_source_calc(app, gk_ns, &gk_ns->src, gk_ns->lte.f_lte, 0.0); @@ -3372,7 +4208,7 @@ gkyl_gyrokinetic_app_from_frame_field(gkyl_gyrokinetic_app *app, int frame) app->field->is_first_energy_write_call = false; // Append to existing diagnostic. app->field->is_first_energy_dot_write_call = false; // Append to existing diagnostic. cstr_drop(&fileNm); - + return rstat; } @@ -3382,25 +4218,32 @@ gkyl_gyrokinetic_app_from_frame_species(gkyl_gyrokinetic_app *app, int sidx, int struct gk_species *gk_s = &app->species[sidx]; cstr fileNm = cstr_from_fmt("%s-%s_%d.gkyl", app->name, gk_s->info.name, frame); - struct gkyl_app_restart_status rstat = gkyl_gyrokinetic_app_from_file_species(app, sidx, fileNm.str); + struct gkyl_app_restart_status rstat = + gkyl_gyrokinetic_app_from_file_species(app, sidx, fileNm.str); cstr_drop(&fileNm); // Append to existing integrated diagnostics. app->is_first_dt_write_call = false; gk_s->is_first_integ_write_call = false; gk_s->is_first_L2norm_write_call = false; - for (int b=0; bbflux.num_boundaries; ++b) + for (int b = 0; b < gk_s->bflux.num_boundaries; ++b) { gk_s->bflux.is_first_intmom_write_call[b] = false; - if (gk_s->info.time_rate_diagnostics) + } + if (gk_s->info.time_rate_diagnostics) { gk_s->is_first_fdot_integ_write_call = false; - if (gk_s->positivity.type) + } + if (gk_s->positivity.type) { gk_s->positivity.is_first_integ_write_call = false; - if (gk_s->rad.radiation_id == GKYL_GK_RADIATION) + } + if (gk_s->rad.radiation_id == GKYL_GK_RADIATION) { gk_s->rad.is_first_integ_write_call = false; - if (gk_s->src.source_id) + } + if (gk_s->src.source_id) { gk_s->src.is_first_integ_write_call = false; - if (gk_s->lte.correct_all_moms) + } + if (gk_s->lte.correct_all_moms) { gk_s->lte.is_first_corr_status_write_call = false; + } return rstat; } @@ -3411,17 +4254,19 @@ gkyl_gyrokinetic_app_from_frame_neut_species(gkyl_gyrokinetic_app *app, int sidx struct gk_neut_species *gk_ns = &app->neut_species[sidx]; cstr fileNm = cstr_from_fmt("%s-%s_%d.gkyl", app->name, gk_ns->info.name, frame); - struct gkyl_app_restart_status rstat = gkyl_gyrokinetic_app_from_file_neut_species(app, sidx, fileNm.str); + struct gkyl_app_restart_status rstat = + gkyl_gyrokinetic_app_from_file_neut_species(app, sidx, fileNm.str); gk_ns->is_first_integ_write_call = false; // append to existing diagnostic cstr_drop(&fileNm); - + // Append to existing integrated diagnostics. gk_ns->is_first_integ_write_call = false; if (gk_ns->src.source_id) { gk_ns->src.is_first_integ_write_call = false; } - if (gk_ns->positivity.type) + if (gk_ns->positivity.type) { gk_ns->positivity.is_first_integ_write_call = false; + } if (gk_ns->lte.correct_all_moms) { gk_ns->lte.is_first_corr_status_write_call = false; } @@ -3433,42 +4278,41 @@ struct gkyl_app_restart_status gkyl_gyrokinetic_app_read_from_frame(gkyl_gyrokinetic_app *app, int frame) { struct gkyl_app_restart_status rstat; - for (int i=0; inum_neut_species; i++) { + for (int i = 0; i < app->num_neut_species; i++) { if (app->neut_species[i].info.is_static) { gk_neut_species_apply_ic(app, &app->neut_species[i], 0.0); - } - else { + } else { rstat = gkyl_gyrokinetic_app_from_frame_neut_species(app, i, frame); } } - for (int i=0; inum_species; i++) { + for (int i = 0; i < app->num_species; i++) { if (app->species[i].info.is_static) { gk_species_apply_ic(app, &app->species[i], 0.0); - } - else { + } else { rstat = gkyl_gyrokinetic_app_from_frame_species(app, i, frame); } } // Apply ICs that depend on other species. - for (int i=0; inum_neut_species; ++i) + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_app_apply_ic_cross_neut_species(app, i, 0.0); - + } + if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { // Compute the fields and apply BCs. struct gkyl_array *distf[app->num_species]; struct gkyl_array **bflux[app->num_species]; struct gkyl_array *distf_neut[app->num_neut_species]; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { distf[i] = app->species[i].f; bflux[i] = app->species[i].bflux.f; } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { distf_neut[i] = app->neut_species[i].f; } if (app->field->update_field) { if (app->field->gkfield_id == GKYL_GK_FIELD_BOLTZMANN) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *s = &app->species[i]; // Compute the collisionless flux so we can compute the initial boundary flux. @@ -3484,15 +4328,14 @@ gkyl_gyrokinetic_app_read_from_frame(gkyl_gyrokinetic_app *app, int frame) // Compute the field. // MF 2024/09/27/: Need the cast here for consistency. Fixing // this may require removing 'const' from a lot of places. - gyrokinetic_calc_field(app, rstat.stime, (const struct gkyl_array **) distf, bflux); - } - else { + gyrokinetic_calc_field(app, rstat.stime, (const struct gkyl_array **)distf, bflux); + } else { // Read the t=0 field. gkyl_gyrokinetic_app_from_frame_field(app, 0); } // Compute boundary fluxes, for recycling and diagnostics and adapt the source. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *s = &app->species[i]; // Compute the collisionless flux so we can compute the initial boundary flux. @@ -3502,14 +4345,13 @@ gkyl_gyrokinetic_app_read_from_frame(gkyl_gyrokinetic_app *app, int frame) gk_species_bflux_rhs(app, &s->bflux, distf[i], distf[i]); // Compute moments of the boundary fluxes. gk_species_bflux_calc_moms(app, &s->bflux, distf[i], bflux[i]); - } // Apply boundary conditions. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gk_species_apply_bc(app, &app->species[i], distf[i]); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gk_neut_species_apply_bc(app, &app->neut_species[i], distf_neut[i]); } } @@ -3519,8 +4361,7 @@ gkyl_gyrokinetic_app_read_from_frame(gkyl_gyrokinetic_app *app, int frame) } // private function to handle variable argument list for printing -static void -v_gk_app_cout(const gkyl_gyrokinetic_app* app, FILE *fp, const char *fmt, va_list argp) +static void v_gk_app_cout(const gkyl_gyrokinetic_app *app, FILE *fp, const char *fmt, va_list argp) { int rank, r = 0; gkyl_comm_get_rank(app->comm, &rank); @@ -3530,8 +4371,7 @@ v_gk_app_cout(const gkyl_gyrokinetic_app* app, FILE *fp, const char *fmt, va_lis } } -void -gkyl_gyrokinetic_app_cout(const gkyl_gyrokinetic_app* app, FILE *fp, const char *fmt, ...) +void gkyl_gyrokinetic_app_cout(const gkyl_gyrokinetic_app *app, FILE *fp, const char *fmt, ...) { va_list argp; va_start(argp, fmt); @@ -3539,12 +4379,11 @@ gkyl_gyrokinetic_app_cout(const gkyl_gyrokinetic_app* app, FILE *fp, const char va_end(argp); } -void -gkyl_gyrokinetic_app_release_geom(gkyl_gyrokinetic_app* app) +void gkyl_gyrokinetic_app_release_geom(gkyl_gyrokinetic_app *app) { gkyl_gk_geometry_release(app->gk_geom); gkyl_position_map_release(app->position_map); - for (int dir=0; dircdim; ++dir) { + for (int dir = 0; dir < app->cdim; ++dir) { gkyl_rect_decomp_release(app->decomp_plane[dir]); gkyl_comm_release(app->comm_plane[dir]); } @@ -3556,8 +4395,7 @@ gkyl_gyrokinetic_app_release_geom(gkyl_gyrokinetic_app* app) } } -void -gkyl_gyrokinetic_app_release(gkyl_gyrokinetic_app* app) +void gkyl_gyrokinetic_app_release(gkyl_gyrokinetic_app *app) { gyrokinetic_post_positivity_quasineut_release(app); @@ -3567,8 +4405,9 @@ gkyl_gyrokinetic_app_release(gkyl_gyrokinetic_app* app) gkyl_gk_dg_geom_release(app->gk_dg_geom); if (app->cdim == 3 && (app->gk_geom->geometry_id == GKYL_GEOMETRY_TOKAMAK || - (app->gk_geom->geometry_id == GKYL_GEOMETRY_MAPC2P && - app->gk_geom->parallel_lower_bc_shift_func && app->gk_geom->parallel_upper_bc_shift_func))) { + (app->gk_geom->geometry_id == GKYL_GEOMETRY_MAPC2P && + app->gk_geom->parallel_lower_bc_shift_func && + app->gk_geom->parallel_upper_bc_shift_func))) { gkyl_array_release(app->delta_ts_x_lo); gkyl_array_release(app->delta_ts_x_up); } @@ -3577,17 +4416,21 @@ gkyl_gyrokinetic_app_release(gkyl_gyrokinetic_app* app) gkyl_position_map_release(app->position_map); - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { gk_species_release(app, &app->species[i]); - if (app->num_species > 0) + } + if (app->num_species > 0) { gkyl_free(app->species); + } - for (int i=0; inum_neut_species; ++i) + for (int i = 0; i < app->num_neut_species; ++i) { gk_neut_species_release(app, &app->neut_species[i]); - if (app->num_neut_species > 0) + } + if (app->num_neut_species > 0) { gkyl_free(app->neut_species); + } - for (int dir=0; dircdim; ++dir) { + for (int dir = 0; dir < app->cdim; ++dir) { gkyl_rect_decomp_release(app->decomp_plane[dir]); gkyl_comm_release(app->comm_plane[dir]); } @@ -3600,53 +4443,56 @@ gkyl_gyrokinetic_app_release(gkyl_gyrokinetic_app* app) gkyl_dynvec_release(app->dts); - gkyl_msgpack_map_elem_release(app->io_meta_basic_len, app->io_meta_basic); gkyl_msgpack_map_elem_release(app->io_meta_dg_len, app->io_meta_dg); gkyl_free(app); } -void -gkyl_gyrokinetic_app_reset_cfl_frac_omegaH(gkyl_gyrokinetic_app* app, double tm, - double cfl_frac_omegaH) +void gkyl_gyrokinetic_app_reset_cfl_frac_omegaH( + gkyl_gyrokinetic_app *app, double tm, double cfl_frac_omegaH +) { double new_cfl_frac_omegaH = fabs(cfl_frac_omegaH) < 1e-16 ? 1.7 : cfl_frac_omegaH; app->cfl_omegaH = new_cfl_frac_omegaH; } -void -gkyl_gyrokinetic_app_reset_species_fdot_multiplier(gkyl_gyrokinetic_app* app, double tm, - const char* species_name, struct gkyl_gyrokinetic_fdot_multiplier fdot_mult_inp) +void gkyl_gyrokinetic_app_reset_species_fdot_multiplier( + gkyl_gyrokinetic_app *app, double tm, const char *species_name, + struct gkyl_gyrokinetic_fdot_multiplier fdot_mult_inp +) { struct gk_species *gks = gk_find_species(app, species_name); gk_species_fdot_multiplier_reset(app, tm, gks, &gks->fdot_mult, fdot_mult_inp); } -void -gkyl_gyrokinetic_app_reset_species_collisionless(gkyl_gyrokinetic_app* app, double tm, - const char *species_name, struct gkyl_gyrokinetic_collisionless gkcls_inp) +void gkyl_gyrokinetic_app_reset_species_collisionless( + gkyl_gyrokinetic_app *app, double tm, const char *species_name, + struct gkyl_gyrokinetic_collisionless gkcls_inp +) { struct gk_species *gks = gk_find_species(app, species_name); gk_species_collisionless_reset(app, tm, gks, &gks->collisionless, gkcls_inp); } -void -gkyl_gyrokinetic_app_reset_species_positivity(gkyl_gyrokinetic_app* app, double tm, - const char *species_name, struct gkyl_gyrokinetic_positivity pos_inp) +void gkyl_gyrokinetic_app_reset_species_positivity( + gkyl_gyrokinetic_app *app, double tm, const char *species_name, + struct gkyl_gyrokinetic_positivity pos_inp +) { struct gk_species *gks = gk_find_species(app, species_name); gk_species_positivity_reset(app, tm, gks, &gks->positivity, pos_inp); } -void -gkyl_gyrokinetic_app_reset_field(gkyl_gyrokinetic_app* app, double tm, - struct gkyl_gyrokinetic_field field_inp) +void gkyl_gyrokinetic_app_reset_field( + gkyl_gyrokinetic_app *app, double tm, struct gkyl_gyrokinetic_field field_inp +) { app->field->info.is_static = field_inp.is_static; app->field->update_field = !field_inp.is_static; - if (app->field->update_field) + if (app->field->update_field) { app->calc_field_func = gyrokinetic_calc_field_enabled; - else + } else { app->calc_field_func = gyrokinetic_calc_field_disabled; + } } diff --git a/gyrokinetic/apps/gyrokinetic_comms.c b/gyrokinetic/apps/gyrokinetic_comms.c index bbb203bdbd..4444e61afd 100644 --- a/gyrokinetic/apps/gyrokinetic_comms.c +++ b/gyrokinetic/apps/gyrokinetic_comms.c @@ -1,8 +1,7 @@ #include #include -struct gkyl_comm* -gkyl_gyrokinetic_comms_new(bool use_mpi, bool use_gpu, FILE *iostream) +struct gkyl_comm *gkyl_gyrokinetic_comms_new(bool use_mpi, bool use_gpu, FILE *iostream) { // Construct communicator for use in app. struct gkyl_comm *comm = 0; @@ -10,40 +9,26 @@ gkyl_gyrokinetic_comms_new(bool use_mpi, bool use_gpu, FILE *iostream) #ifdef GKYL_HAVE_MPI if (use_gpu && use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else fprintf(iostream, " Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = use_gpu - } - ); + } else if (use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = use_gpu}); #endif return comm; } -void -gkyl_gyrokinetic_comms_release(struct gkyl_comm *comm) +void gkyl_gyrokinetic_comms_release(struct gkyl_comm *comm) { - if (comm != 0) + if (comm != 0) { gkyl_comm_release(comm); + } } diff --git a/gyrokinetic/apps/gyrokinetic_lw.c b/gyrokinetic/apps/gyrokinetic_lw.c index 7a1a1500a7..dae88349c3 100644 --- a/gyrokinetic/apps/gyrokinetic_lw.c +++ b/gyrokinetic/apps/gyrokinetic_lw.c @@ -27,192 +27,165 @@ #endif #endif - - // Gyrokinetic FEM boundary conditions -> enum map. static const struct gkyl_str_int_pair parproj_type[] = { - { "None", GKYL_FEM_PARPROJ_NONE }, - { "Periodic", GKYL_FEM_PARPROJ_PERIODIC }, - { "DirichletGhost", GKYL_FEM_PARPROJ_DIRICHLET_GHOST }, - { "DirichletSkin", GKYL_FEM_PARPROJ_DIRICHLET_SKIN }, - { 0, 0 } + {"None", GKYL_FEM_PARPROJ_NONE}, + {"Periodic", GKYL_FEM_PARPROJ_PERIODIC}, + {"DirichletGhost", GKYL_FEM_PARPROJ_DIRICHLET_GHOST}, + {"DirichletSkin", GKYL_FEM_PARPROJ_DIRICHLET_SKIN}, + {0, 0} }; // Gyrokinetic geometry type -> enum map. static const struct gkyl_str_int_pair geometry_type[] = { - { "Tokamak", GKYL_GEOMETRY_TOKAMAK }, - { "Mirror", GKYL_GEOMETRY_MIRROR }, - { "MapC2P", GKYL_GEOMETRY_MAPC2P }, - { "FromFile", GKYL_GEOMETRY_FROMFILE }, - { 0, 0 } + {"Tokamak", GKYL_GEOMETRY_TOKAMAK}, + {"Mirror", GKYL_GEOMETRY_MIRROR}, + {"MapC2P", GKYL_GEOMETRY_MAPC2P}, + {"FromFile", GKYL_GEOMETRY_FROMFILE}, + {0, 0} }; // Gyrokinetic position map type -> enum map. static const struct gkyl_str_int_pair position_map_type[] = { - { "UserInput", GKYL_PMAP_USER_INPUT }, - { "ConstantPolynomial", GKYL_PMAP_CONSTANT_DB_POLYNOMIAL }, - { "ConstantNumeric", GKYL_PMAP_CONSTANT_DB_NUMERIC }, - { 0, 0 } + {"UserInput", GKYL_PMAP_USER_INPUT}, + {"ConstantPolynomial", GKYL_PMAP_CONSTANT_DB_POLYNOMIAL}, + {"ConstantNumeric", GKYL_PMAP_CONSTANT_DB_NUMERIC}, + {0, 0} }; // Gyrokinetic collisionless type -> enum map. static const struct gkyl_str_int_pair gk_collisionless_type[] = { - { "None", GKYL_GK_COLLISIONLESS_NONE }, - { "GKCollisionlessES", GKYL_GK_COLLISIONLESS_ES }, - { "GKCollisionlessES_no_by", GKYL_GK_COLLISIONLESS_ES_NO_BY }, - { "GKCollisionlessEM_Bperp", GKYL_GK_COLLISIONLESS_EM_BPERP }, - { "GKCollisionlessEM_Bpar", GKYL_GK_COLLISIONLESS_EM_BPAR }, - { "GKCollisionlessEM", GKYL_GK_COLLISIONLESS_EM }, - { 0, 0 } + {"None", GKYL_GK_COLLISIONLESS_NONE}, + {"GKCollisionlessES", GKYL_GK_COLLISIONLESS_ES}, + {"GKCollisionlessES_no_by", GKYL_GK_COLLISIONLESS_ES_NO_BY}, + {"GKCollisionlessEM_Bperp", GKYL_GK_COLLISIONLESS_EM_BPERP}, + {"GKCollisionlessEM_Bpar", GKYL_GK_COLLISIONLESS_EM_BPAR}, + {"GKCollisionlessEM", GKYL_GK_COLLISIONLESS_EM}, + {0, 0} }; // Gyrokinetic field type -> enum map. static const struct gkyl_str_int_pair gk_field_type[] = { - { "Electrostatic", GKYL_GK_FIELD_ES }, - { "Boltzmann", GKYL_GK_FIELD_BOLTZMANN }, - { "Adiabatic", GKYL_GK_FIELD_ADIABATIC }, - { "Electromagnetic", GKYL_GK_FIELD_EM }, - { 0, 0 } + {"Electrostatic", GKYL_GK_FIELD_ES}, + {"Boltzmann", GKYL_GK_FIELD_BOLTZMANN}, + {"Adiabatic", GKYL_GK_FIELD_ADIABATIC}, + {"Electromagnetic", GKYL_GK_FIELD_EM}, + {0, 0} }; // Gyrokinetic radiation type -> enum map. static const struct gkyl_str_int_pair gk_radiation_type[] = { - { "None", GKYL_NO_RADIATION }, - { "GKRadiation", GKYL_GK_RADIATION }, - { "VMComptonRadiation", GKYL_VM_COMPTON_RADIATION }, - { 0, 0 } + {"None", GKYL_NO_RADIATION}, + {"GKRadiation", GKYL_GK_RADIATION}, + {"VMComptonRadiation", GKYL_VM_COMPTON_RADIATION}, + {0, 0} }; // Gyrokinetic radiation Te model type -> enum map. static const struct gkyl_str_int_pair gk_radiation_te_type[] = { - { "Conservative", GKYL_VARY_TE_CONSERVATIVE }, - { "Aggressive", GKYL_VARY_TE_AGGRESSIVE }, - { "Const", GKYL_CONST_TE }, - { 0, 0 } + {"Conservative", GKYL_VARY_TE_CONSERVATIVE}, + {"Aggressive", GKYL_VARY_TE_AGGRESSIVE}, + {"Const", GKYL_CONST_TE}, + {0, 0} }; // Gyrokinetic reaction type -> enum map. static const struct gkyl_str_int_pair gk_react_type[] = { - { "None", GKYL_NO_REACT }, - { "Ionization", GKYL_REACT_IZ }, - { "ChargeExchange", GKYL_REACT_CX }, - { "Recombination", GKYL_REACT_RECOMB }, - { 0, 0 } + {"None", GKYL_NO_REACT}, + {"Ionization", GKYL_REACT_IZ}, + {"ChargeExchange", GKYL_REACT_CX}, + {"Recombination", GKYL_REACT_RECOMB}, + {0, 0} }; // Gyrokinetic ion type -> enum map. static const struct gkyl_str_int_pair gk_ion_type[] = { - { "Hydrogen", GKYL_ION_H }, - { "Deuterium", GKYL_ION_D }, - { "Helium", GKYL_ION_HE }, - { "Lithium", GKYL_ION_LI }, - { "Beryllium", GKYL_ION_BE }, - { "Boron", GKYL_ION_B }, - { "Carbon", GKYL_ION_C }, - { "Nitrogen", GKYL_ION_N }, - { "Oxygen", GKYL_ION_O }, - { "Neon", GKYL_ION_NE }, - { "Argon", GKYL_ION_AR }, - { 0, 0 } + {"Hydrogen", GKYL_ION_H}, {"Deuterium", GKYL_ION_D}, {"Helium", GKYL_ION_HE}, + {"Lithium", GKYL_ION_LI}, {"Beryllium", GKYL_ION_BE}, {"Boron", GKYL_ION_B}, + {"Carbon", GKYL_ION_C}, {"Nitrogen", GKYL_ION_N}, {"Oxygen", GKYL_ION_O}, + {"Neon", GKYL_ION_NE}, {"Argon", GKYL_ION_AR}, {0, 0} }; // Gyrokinetic self-reaction type -> enum map. static const struct gkyl_str_int_pair gk_react_self_type[] = { - { "Electron", GKYL_SELF_ELC }, - { "Ion", GKYL_SELF_ION }, - { "Donor", GKYL_SELF_DONOR }, - { "Receiver", GKYL_SELF_RECVR }, - { "Partner", GKYL_SELF_PARTNER }, - { 0, 0 } + {"Electron", GKYL_SELF_ELC}, {"Ion", GKYL_SELF_ION}, {"Donor", GKYL_SELF_DONOR}, + {"Receiver", GKYL_SELF_RECVR}, {"Partner", GKYL_SELF_PARTNER}, {0, 0} }; // Species boundary conditions -> enum map. -static const struct gkyl_str_int_pair gk_bcs[] = { - // Particle BCs. - { "speciesSkip", GKYL_BC_GK_SKIP }, // Do not apply any BCs - { "speciesCopy", GKYL_BC_GK_SPECIES_COPY }, // Copy skin into ghost. - { "speciesReflect", GKYL_BC_GK_SPECIES_REFLECT }, // Reflect particles. - { "speciesAbsorb", GKYL_BC_GK_SPECIES_ABSORB }, // Absorbing BCs. - { "speciesFunc", GKYL_BC_GK_SPECIES_FUNC }, // Fill ghost cell using a user-function. - { "speciesFixedFunc", GKYL_BC_GK_SPECIES_FIXED_FUNC }, // Fixed function, time-independent. - { "speciesZeroFlux", GKYL_BC_GK_SPECIES_ZERO_FLUX }, // Zero flux. - { "speciesSheath", GKYL_BC_GK_SPECIES_SHEATH }, // Sheath. - { "speciesRecycle", GKYL_BC_GK_SPECIES_RECYCLE }, // Recycling. - { "speciesPeriodic", GKYL_BC_GK_SPECIES_PERIODIC }, // Periodic. - { "speciesTwistshift", GKYL_BC_GK_SPECIES_TWISTSHIFT }, // Twist-shift. +static const struct gkyl_str_int_pair gk_bcs[] = { // Particle BCs. + {"speciesSkip", GKYL_BC_GK_SKIP}, // Do not apply any BCs + {"speciesCopy", GKYL_BC_GK_SPECIES_COPY}, // Copy skin into ghost. + {"speciesReflect", GKYL_BC_GK_SPECIES_REFLECT}, // Reflect particles. + {"speciesAbsorb", GKYL_BC_GK_SPECIES_ABSORB}, // Absorbing BCs. + {"speciesFunc", GKYL_BC_GK_SPECIES_FUNC}, // Fill ghost cell using a user-function. + {"speciesFixedFunc", GKYL_BC_GK_SPECIES_FIXED_FUNC}, // Fixed function, time-independent. + {"speciesZeroFlux", GKYL_BC_GK_SPECIES_ZERO_FLUX}, // Zero flux. + {"speciesSheath", GKYL_BC_GK_SPECIES_SHEATH}, // Sheath. + {"speciesRecycle", GKYL_BC_GK_SPECIES_RECYCLE}, // Recycling. + {"speciesPeriodic", GKYL_BC_GK_SPECIES_PERIODIC}, // Periodic. + {"speciesTwistshift", GKYL_BC_GK_SPECIES_TWISTSHIFT}, // Twist-shift. // Field BCs. - { "fieldPeriodic", GKYL_BC_GK_FIELD_PERIODIC }, // Periodic. - { "fieldDirichlet", GKYL_BC_GK_FIELD_DIRICHLET }, // Dirichlet. - { "fieldNeumann", GKYL_BC_GK_FIELD_NEUMANN }, // Nemann. - { "fieldDirichletVarying", GKYL_BC_GK_FIELD_DIRICHLET_VARYING }, // Spatially varying Dirichlet. - { "fieldBoundaryValue", GKYL_BC_GK_FIELD_BOUNDARY_VALUE }, // Skin value at the boundary. - { "fieldTwistshift", GKYL_BC_GK_FIELD_TWISTSHIFT }, // Twist-shift. - { 0, 0 } + {"fieldPeriodic", GKYL_BC_GK_FIELD_PERIODIC}, // Periodic. + {"fieldDirichlet", GKYL_BC_GK_FIELD_DIRICHLET}, // Dirichlet. + {"fieldNeumann", GKYL_BC_GK_FIELD_NEUMANN}, // Nemann. + {"fieldDirichletVarying", GKYL_BC_GK_FIELD_DIRICHLET_VARYING}, // Spatially varying Dirichlet. + {"fieldBoundaryValue", GKYL_BC_GK_FIELD_BOUNDARY_VALUE}, // Skin value at the boundary. + {"fieldTwistshift", GKYL_BC_GK_FIELD_TWISTSHIFT}, // Twist-shift. + {0, 0} }; - -void -gkyl_register_gyrokinetic_fem_bc_types(lua_State *L) +void gkyl_register_gyrokinetic_fem_bc_types(lua_State *L) { register_types(L, parproj_type, "ParProjBc"); } -void -gkyl_register_gyrokinetic_geometry_types(lua_State *L) +void gkyl_register_gyrokinetic_geometry_types(lua_State *L) { register_types(L, geometry_type, "Geometry"); } -void -gkyl_register_gyrokinetic_position_map_types(lua_State *L) +void gkyl_register_gyrokinetic_position_map_types(lua_State *L) { register_types(L, position_map_type, "PositionMap"); } -void -gkyl_register_gyrokinetic_collisionless_types(lua_State *L) +void gkyl_register_gyrokinetic_collisionless_types(lua_State *L) { register_types(L, gk_collisionless_type, "GKCollisionless"); } -void -gkyl_register_gyrokinetic_field_types(lua_State *L) +void gkyl_register_gyrokinetic_field_types(lua_State *L) { register_types(L, gk_field_type, "GKField"); } -void -gkyl_register_gyrokinetic_radiation_types(lua_State *L) +void gkyl_register_gyrokinetic_radiation_types(lua_State *L) { register_types(L, gk_radiation_type, "Radiation"); } -void -gkyl_register_gyrokinetic_radiation_Te_types(lua_State *L) +void gkyl_register_gyrokinetic_radiation_Te_types(lua_State *L) { register_types(L, gk_radiation_te_type, "TeMinModel"); } -void -gkyl_register_gyrokinetic_reaction_types(lua_State *L) +void gkyl_register_gyrokinetic_reaction_types(lua_State *L) { register_types(L, gk_react_type, "Reaction"); } -void -gkyl_register_gyrokinetic_ion_types(lua_State *L) +void gkyl_register_gyrokinetic_ion_types(lua_State *L) { register_types(L, gk_ion_type, "Ion"); } -void -gkyl_register_gyrokinetic_self_reaction_types(lua_State *L) +void gkyl_register_gyrokinetic_self_reaction_types(lua_State *L) { register_types(L, gk_react_self_type, "Self"); } -void -gkyl_register_gyrokinetic_bc_types(lua_State *L) +void gkyl_register_gyrokinetic_bc_types(lua_State *L) { register_types(L, gk_bcs, "GyrokineticBc"); } @@ -221,7 +194,7 @@ gkyl_register_gyrokinetic_bc_types(lua_State *L) enum gyrokinetic_magic_ids { GYROKINETIC_SPECIES_DEFAULT = 100, // Standard gyrokinetic species. GYROKINETIC_NEUTRAL_SPECIES_DEFAULT, // Neutral gyrokinetic species. - GYROKINETIC_FIELD_DEFAULT, // Gyrokinetic Poisson equation. + GYROKINETIC_FIELD_DEFAULT // Gyrokinetic Poisson equation. }; /* *************** */ @@ -234,13 +207,14 @@ enum gyrokinetic_magic_ids { // Lua userdata object for constructing species input. struct gyrokinetic_species_lw { int magic; // This must be first element in the struct. - + struct gkyl_gyrokinetic_species gk_species; // Input struct to construct species. int vdim; // Velocity space dimensions. bool evolve; // Is this species evolved? bool has_mapc2p_mapping_func; // Is there a non-uniform velocity space mapping function? - struct lua_func_ctx mapc2p_mapping_func_ref; // Lua registry reference to non-uniofrm velocity space mapping function. + struct lua_func_ctx + mapc2p_mapping_func_ref; // Lua registry reference to non-uniofrm velocity space mapping function. enum gkyl_projection_id proj_id; // Projection type. @@ -248,35 +222,42 @@ struct gyrokinetic_species_lw { struct lua_func_ctx init_func_ref; // Lua registry reference to initialization function. bool has_density_init_func; // Is there a density initialization function? - struct lua_func_ctx density_init_func_ref; // Lua registry reference to density initialization function. + struct lua_func_ctx + density_init_func_ref; // Lua registry reference to density initialization function. bool has_Upar_init_func; // Is there a parallel velocity initialiation function? - struct lua_func_ctx Upar_init_func_ref; // Lua registry reference to parallel velocity initialization function. + struct lua_func_ctx + Upar_init_func_ref; // Lua registry reference to parallel velocity initialization function. bool has_temp_init_func; // Is there a temperature initialization function? - struct lua_func_ctx temp_init_func_ref; // Lua registry reference to temperature initialization function. + struct lua_func_ctx + temp_init_func_ref; // Lua registry reference to temperature initialization function. bool has_par_temp_init_func; // Is there a parallel temperature initialization function? - struct lua_func_ctx par_temp_init_func_ref; // Lua registry reference to parallel temperature initialization function. + struct lua_func_ctx + par_temp_init_func_ref; // Lua registry reference to parallel temperature initialization function. bool has_perp_temp_init_func; // Is there a perpendicular temperature initialization function? - struct lua_func_ctx perp_temp_init_func_ref; // Lua registry reference to perpendicular temperature initialization function. + struct lua_func_ctx + perp_temp_init_func_ref; // Lua registry reference to perpendicular temperature initialization function. bool proj_correct_all_moms; // Are we correcting all moments in projection, or only density? enum gkyl_gk_collisionless_type collisionless_type; // Collisionless type. enum gkyl_collision_id collision_id; // Collision type. - + bool has_self_nu_func; // Is there a self-collision frequency function? - struct lua_func_ctx self_nu_func_ref; // Lua registry reference to self-collision frequency function. + struct lua_func_ctx + self_nu_func_ref; // Lua registry reference to self-collision frequency function. int num_cross_collisions; // Number of species that we cross-collide with. char collide_with[GKYL_MAX_SPECIES][128]; // Names of species that we cross-collide with. bool collision_norm_nu; // Are we rescaling the collision frequency? double collision_den_ref; // Density used to calculate Coulomb logarithm for collision frequency. - double collision_temp_ref; // Temperature used to calculate Coulomb logarithm for collision frequency. + double + collision_temp_ref; // Temperature used to calculate Coulomb logarithm for collision frequency. double collision_hbar; // Reduced Planck's constant for calculating collision frequency. double collision_eps0; // Vacuum permittivity for calculating collision frequency. double collision_eV; // Elementary charge for calculating collision frequency. @@ -292,33 +273,46 @@ struct gyrokinetic_species_lw { enum gkyl_projection_id source_proj_id[GKYL_MAX_PROJ]; // Projection type in source. bool source_has_init_func[GKYL_MAX_PROJ]; // Is there an initialization function in source? - struct lua_func_ctx source_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to initialization function in source. + struct lua_func_ctx source_init_func_ref + [GKYL_MAX_PROJ]; // Lua registry reference to initialization function in source. - bool source_has_density_init_func[GKYL_MAX_PROJ]; // Is there a density initialization function in source? - struct lua_func_ctx source_density_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to density initialization function in source. + bool source_has_density_init_func + [GKYL_MAX_PROJ]; // Is there a density initialization function in source? + struct lua_func_ctx source_density_init_func_ref + [GKYL_MAX_PROJ]; // Lua registry reference to density initialization function in source. - bool source_has_Upar_init_func[GKYL_MAX_PROJ]; // Is there a parallel velocity initialization function in source? - struct lua_func_ctx source_Upar_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to parallel velocity initialization function in source. + bool source_has_Upar_init_func + [GKYL_MAX_PROJ]; // Is there a parallel velocity initialization function in source? + struct lua_func_ctx source_Upar_init_func_ref + [GKYL_MAX_PROJ]; // Lua registry reference to parallel velocity initialization function in source. - bool source_has_temp_init_func[GKYL_MAX_PROJ]; // Is there a temperature initialization function in source? - struct lua_func_ctx source_temp_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to temperature initialization function in source. + bool source_has_temp_init_func + [GKYL_MAX_PROJ]; // Is there a temperature initialization function in source? + struct lua_func_ctx source_temp_init_func_ref + [GKYL_MAX_PROJ]; // Lua registry reference to temperature initialization function in source. enum gkyl_radiation_id radiation_id; // Radiation type. int radiation_num_cross_collisions; // Number of radiation species that we cross-collide with. - char radiation_collide_with[GKYL_MAX_SPECIES][128]; // Names of radiation species that we cross-collide with. + char radiation_collide_with[GKYL_MAX_SPECIES] + [128]; // Names of radiation species that we cross-collide with. int radiation_z[GKYL_MAX_SPECIES]; // Atomic Z of radiation species that we are colliding with. - int radiation_charge_state[GKYL_MAX_SPECIES]; // Charge state of radiation species that we are colliding with. - int radiation_num_of_densities[GKYL_MAX_SPECIES]; // Maximum number of densities to use per charge state of radiation species that we are colliding with. + int radiation_charge_state + [GKYL_MAX_SPECIES]; // Charge state of radiation species that we are colliding with. + int radiation_num_of_densities + [GKYL_MAX_SPECIES]; // Maximum number of densities to use per charge state of radiation species that we are colliding with. - enum gkyl_te_min_model radiation_te_min_model; // How is the radiation turned off (constant, or with varying electron temperature)? + enum gkyl_te_min_model + radiation_te_min_model; // How is the radiation turned off (constant, or with varying electron temperature)? double radiation_Te_min; // Minimum temperature (in J) at which to stop radiating. int num_react; // Number of reaction types. - enum gkyl_react_id react_id[GKYL_MAX_REACT]; // What type of reaction (ionization, charge exchange, recombination)? - enum gkyl_react_self_type react_type_self[GKYL_MAX_REACT]; // What is the role of the species in this reaction? + enum gkyl_react_id + react_id[GKYL_MAX_REACT]; // What type of reaction (ionization, charge exchange, recombination)? + enum gkyl_react_self_type + react_type_self[GKYL_MAX_REACT]; // What is the role of the species in this reaction? enum gkyl_ion_type react_ion_id[GKYL_MAX_REACT]; // What type of ion is reacting? char react_elc_nm[GKYL_MAX_REACT][128]; // Name of electron species in the reaction. @@ -332,8 +326,10 @@ struct gyrokinetic_species_lw { int num_neut_react; // Number of neutral reaction types. - enum gkyl_react_id neut_react_id[GKYL_MAX_REACT]; // What type of neutral reaction (ionization, charge exchange, recombination)? - enum gkyl_react_self_type neut_react_type_self[GKYL_MAX_REACT]; // What is the role of the species in this neutral reaction? + enum gkyl_react_id neut_react_id + [GKYL_MAX_REACT]; // What type of neutral reaction (ionization, charge exchange, recombination)? + enum gkyl_react_self_type + neut_react_type_self[GKYL_MAX_REACT]; // What is the role of the species in this neutral reaction? enum gkyl_ion_type neut_react_ion_id[GKYL_MAX_REACT]; // What type of ion in the neutral reaction? char neut_react_elc_nm[GKYL_MAX_REACT][128]; // Name of electron species in the neutral reaction. @@ -347,17 +343,17 @@ struct gyrokinetic_species_lw { double neut_react_elc_mass[GKYL_MAX_REACT]; // Mass of electron species in the neutral reaction. }; -static int -gyrokinetic_species_lw_new(lua_State *L) +static int gyrokinetic_species_lw_new(lua_State *L) { int vdim = 0; - struct gkyl_gyrokinetic_species gk_species = { }; - + struct gkyl_gyrokinetic_species gk_species = {}; + gk_species.charge = glua_tbl_get_number(L, "charge", 0.0); gk_species.mass = glua_tbl_get_number(L, "mass", 1.0); gk_species.polarization_density = glua_tbl_get_number(L, "polarizationDensity", 0.0); - with_lua_tbl_tbl(L, "cells") { + with_lua_tbl_tbl(L, "cells") + { vdim = glua_objlen(L); for (int d = 0; d < vdim; d++) { @@ -365,13 +361,15 @@ gyrokinetic_species_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "lower") { + with_lua_tbl_tbl(L, "lower") + { for (int d = 0; d < vdim; d++) { gk_species.lower[d] = glua_tbl_iget_number(L, d + 1, 0.0); } } - with_lua_tbl_tbl(L, "upper") { + with_lua_tbl_tbl(L, "upper") + { for (int d = 0; d < vdim; d++) { gk_species.upper[d] = glua_tbl_iget_number(L, d + 1, 0.0); } @@ -379,26 +377,30 @@ gyrokinetic_species_lw_new(lua_State *L) bool evolve = glua_tbl_get_integer(L, "evolve", true); - with_lua_tbl_tbl(L, "diagnostics") { + with_lua_tbl_tbl(L, "diagnostics") + { int num_diag_moments = glua_objlen(L); - for (int i = 0; i < num_diag_moments; i ++) { - gk_species.diag_moments[i] = glua_tbl_iget_integer(L, i+1, 0); + for (int i = 0; i < num_diag_moments; i++) { + gk_species.diag_moments[i] = glua_tbl_iget_integer(L, i + 1, 0); } gk_species.num_diag_moments = num_diag_moments; } - with_lua_tbl_tbl(L, "bcs") { + with_lua_tbl_tbl(L, "bcs") + { int num_bcs = glua_objlen(L); for (int i = 0; i < num_bcs; i++) { gk_species.bcs[i].dir = glua_tbl_get_integer(L, "dir", 0); gk_species.bcs[i].edge = glua_tbl_get_integer(L, "edge", 0); gk_species.bcs[i].type = glua_tbl_get_integer(L, "type", 0); - with_lua_tbl_tbl(L, "value") { + with_lua_tbl_tbl(L, "value") + { int num_vals = glua_objlen(L); for (int k = 0; k < num_vals; k++) { - gk_species.bcs[i].value[k] = glua_tbl_iget_number(L, k + 1, 0.0);; + gk_species.bcs[i].value[k] = glua_tbl_iget_number(L, k + 1, 0.0); + ; } } } @@ -407,13 +409,14 @@ gyrokinetic_species_lw_new(lua_State *L) bool has_mapc2p_mapping_func = false; int mapc2p_mapping_func_ref = LUA_NOREF; - with_lua_tbl_tbl(L, "mapc2p") { + with_lua_tbl_tbl(L, "mapc2p") + { if (glua_tbl_get_func(L, "mapping")) { mapc2p_mapping_func_ref = luaL_ref(L, LUA_REGISTRYINDEX); has_mapc2p_mapping_func = true; } }; - + enum gkyl_projection_id proj_id = GKYL_PROJ_FUNC; bool has_init_func = false; @@ -436,7 +439,8 @@ gyrokinetic_species_lw_new(lua_State *L) bool proj_correct_all_moms = false; - with_lua_tbl_tbl(L, "projection") { + with_lua_tbl_tbl(L, "projection") + { proj_id = glua_tbl_get_integer(L, "projectionID", 0); if (glua_tbl_get_func(L, "init")) { @@ -474,9 +478,10 @@ gyrokinetic_species_lw_new(lua_State *L) bool correct_all_moms = false; double iter_eps = 0.0; - int max_iter = 0; - bool use_last_converged = true; - with_lua_tbl_tbl(L, "correct") { + int max_iter = 0; + bool use_last_converged = true; + with_lua_tbl_tbl(L, "correct") + { correct_all_moms = glua_tbl_get_bool(L, "correctAllMoments", false); iter_eps = glua_tbl_get_number(L, "iterationEpsilon", 0.0); max_iter = glua_tbl_get_integer(L, "maxIterations", 0); @@ -485,7 +490,8 @@ gyrokinetic_species_lw_new(lua_State *L) enum gkyl_gk_collisionless_type collisionless_type = GKYL_GK_COLLISIONLESS_NONE; - with_lua_tbl_tbl(L, "collisionless") { + with_lua_tbl_tbl(L, "collisionless") + { collisionless_type = glua_tbl_get_integer(L, "type", 0); } @@ -504,7 +510,8 @@ gyrokinetic_species_lw_new(lua_State *L) double collision_eps0 = 0.0; double collision_eV = 0.0; - with_lua_tbl_tbl(L, "collisions") { + with_lua_tbl_tbl(L, "collisions") + { collision_id = glua_tbl_get_integer(L, "collisionID", 0); if (glua_tbl_get_func(L, "selfNu")) { @@ -513,9 +520,10 @@ gyrokinetic_species_lw_new(lua_State *L) } num_cross_collisions = glua_tbl_get_integer(L, "numCrossCollisions", 0); - with_lua_tbl_tbl(L, "collideWith") { + with_lua_tbl_tbl(L, "collideWith") + { for (int i = 0; i < num_cross_collisions; i++) { - const char* collide_with_char = glua_tbl_iget_string(L, i + 1, ""); + const char *collide_with_char = glua_tbl_iget_string(L, i + 1, ""); strcpy(collide_with[i], collide_with_char); } } @@ -545,11 +553,13 @@ gyrokinetic_species_lw_new(lua_State *L) bool source_has_temp_init_func[GKYL_MAX_PROJ]; int source_temp_init_func_ref[GKYL_MAX_PROJ]; - with_lua_tbl_tbl(L, "source") { + with_lua_tbl_tbl(L, "source") + { source_id = glua_tbl_get_integer(L, "sourceID", 0); num_sources = glua_tbl_get_integer(L, "numSources", 0); - with_lua_tbl_tbl(L, "projections") { + with_lua_tbl_tbl(L, "projections") + { for (int i = 0; i < num_sources; i++) { if (glua_tbl_iget_tbl(L, i + 1)) { source_proj_id[i] = glua_tbl_get_integer(L, "projectionID", 0); @@ -600,28 +610,33 @@ gyrokinetic_species_lw_new(lua_State *L) int radiation_te_min_model = GKYL_VARY_TE_CONSERVATIVE; double radiation_Te_min = 0.0; - with_lua_tbl_tbl(L, "radiation") { + with_lua_tbl_tbl(L, "radiation") + { radiation_id = glua_tbl_get_integer(L, "radiationID", GKYL_NO_RADIATION); radiation_num_cross_collisions = glua_tbl_get_integer(L, "numCrossCollisions", 0); - with_lua_tbl_tbl(L, "collideWith") { + with_lua_tbl_tbl(L, "collideWith") + { for (int i = 0; i < radiation_num_cross_collisions; i++) { - const char* radiation_collide_with_char = glua_tbl_iget_string(L, i + 1, ""); + const char *radiation_collide_with_char = glua_tbl_iget_string(L, i + 1, ""); strcpy(radiation_collide_with[i], radiation_collide_with_char); } } - - with_lua_tbl_tbl(L, "atomicZ") { + + with_lua_tbl_tbl(L, "atomicZ") + { for (int i = 0; i < radiation_num_cross_collisions; i++) { radiation_z[i] = glua_tbl_iget_integer(L, i + 1, 0); } } - with_lua_tbl_tbl(L, "chargeState") { + with_lua_tbl_tbl(L, "chargeState") + { for (int i = 0; i < radiation_num_cross_collisions; i++) { radiation_charge_state[i] = glua_tbl_iget_integer(L, i + 1, 0); } } - with_lua_tbl_tbl(L, "numDensities") { + with_lua_tbl_tbl(L, "numDensities") + { for (int i = 0; i < radiation_num_cross_collisions; i++) { radiation_num_of_densities[i] = glua_tbl_iget_integer(L, i + 1, 0); } @@ -645,26 +660,28 @@ gyrokinetic_species_lw_new(lua_State *L) double react_ion_mass[GKYL_MAX_REACT]; double react_elc_mass[GKYL_MAX_REACT]; - with_lua_tbl_tbl(L, "reaction") { + with_lua_tbl_tbl(L, "reaction") + { num_react = glua_tbl_get_integer(L, "numReactions", 0); - with_lua_tbl_tbl(L, "reactionTypes") { + with_lua_tbl_tbl(L, "reactionTypes") + { for (int i = 0; i < num_react; i++) { if (glua_tbl_iget_tbl(L, i + 1)) { react_id[i] = glua_tbl_get_integer(L, "reactionID", GKYL_NO_REACT); react_type_self[i] = glua_tbl_get_integer(L, "selfType", GKYL_SELF_ELC); react_ion_id[i] = glua_tbl_get_integer(L, "ionType", GKYL_ION_H); - const char* react_elc_nm_char = glua_tbl_get_string(L, "electronName", ""); + const char *react_elc_nm_char = glua_tbl_get_string(L, "electronName", ""); strcpy(react_elc_nm[i], react_elc_nm_char); - const char* react_ion_nm_char = glua_tbl_get_string(L, "ionName", ""); + const char *react_ion_nm_char = glua_tbl_get_string(L, "ionName", ""); strcpy(react_ion_nm[i], react_ion_nm_char); - const char* react_donor_nm_char = glua_tbl_get_string(L, "donorName", ""); + const char *react_donor_nm_char = glua_tbl_get_string(L, "donorName", ""); strcpy(react_donor_nm[i], react_donor_nm_char); - const char* react_recvr_nm_char = glua_tbl_get_string(L, "receiverName", ""); + const char *react_recvr_nm_char = glua_tbl_get_string(L, "receiverName", ""); strcpy(react_recvr_nm[i], react_recvr_nm_char); react_charge_state[i] = glua_tbl_get_integer(L, "chargeState", 0); @@ -692,29 +709,31 @@ gyrokinetic_species_lw_new(lua_State *L) double neut_react_ion_mass[GKYL_MAX_REACT]; double neut_react_elc_mass[GKYL_MAX_REACT]; - with_lua_tbl_tbl(L, "neutralReaction") { + with_lua_tbl_tbl(L, "neutralReaction") + { num_neut_react = glua_tbl_get_integer(L, "numReactions", 0); - with_lua_tbl_tbl(L, "reactionTypes") { + with_lua_tbl_tbl(L, "reactionTypes") + { for (int i = 0; i < num_neut_react; i++) { if (glua_tbl_iget_tbl(L, i + 1)) { neut_react_id[i] = glua_tbl_get_integer(L, "reactionID", GKYL_NO_REACT); neut_react_type_self[i] = glua_tbl_get_integer(L, "selfType", GKYL_SELF_ELC); neut_react_ion_id[i] = glua_tbl_get_integer(L, "ionType", GKYL_ION_H); - const char* neut_react_elc_nm_char = glua_tbl_get_string(L, "electronName", ""); + const char *neut_react_elc_nm_char = glua_tbl_get_string(L, "electronName", ""); strcpy(neut_react_elc_nm[i], neut_react_elc_nm_char); - const char* neut_react_ion_nm_char = glua_tbl_get_string(L, "ionName", ""); + const char *neut_react_ion_nm_char = glua_tbl_get_string(L, "ionName", ""); strcpy(neut_react_ion_nm[i], neut_react_ion_nm_char); - const char* neut_react_donor_nm_char = glua_tbl_get_string(L, "donorName", ""); + const char *neut_react_donor_nm_char = glua_tbl_get_string(L, "donorName", ""); strcpy(neut_react_donor_nm[i], neut_react_donor_nm_char); - const char* neut_react_recvr_nm_char = glua_tbl_get_string(L, "receiverName", ""); + const char *neut_react_recvr_nm_char = glua_tbl_get_string(L, "receiverName", ""); strcpy(neut_react_recvr_nm[i], neut_react_recvr_nm_char); - const char* neut_react_partner_nm_char = glua_tbl_get_string(L, "partnerName", ""); + const char *neut_react_partner_nm_char = glua_tbl_get_string(L, "partnerName", ""); strcpy(neut_react_partner_nm[i], neut_react_partner_nm_char); neut_react_charge_state[i] = glua_tbl_get_integer(L, "chargeState", 0); @@ -726,7 +745,7 @@ gyrokinetic_species_lw_new(lua_State *L) } } } - + struct gyrokinetic_species_lw *gks_lw = lua_newuserdata(L, sizeof(*gks_lw)); gks_lw->magic = GYROKINETIC_SPECIES_DEFAULT; gks_lw->vdim = vdim; @@ -734,102 +753,88 @@ gyrokinetic_species_lw_new(lua_State *L) gks_lw->gk_species = gk_species; gks_lw->has_mapc2p_mapping_func = has_mapc2p_mapping_func; - gks_lw->mapc2p_mapping_func_ref = (struct lua_func_ctx) { - .func_ref = mapc2p_mapping_func_ref, - .ndim = 2, - .nret = 2, - .L = L, - }; + gks_lw->mapc2p_mapping_func_ref = + (struct lua_func_ctx){.func_ref = mapc2p_mapping_func_ref, .ndim = 2, .nret = 2, .L = L}; gks_lw->proj_id = proj_id; gks_lw->has_init_func = has_init_func; - gks_lw->init_func_ref = (struct lua_func_ctx) { - .func_ref = init_func_ref, + gks_lw->init_func_ref = (struct lua_func_ctx + ){.func_ref = init_func_ref, .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; gks_lw->has_density_init_func = has_density_init_func; - gks_lw->density_init_func_ref = (struct lua_func_ctx) { - .func_ref = density_init_func_ref, + gks_lw->density_init_func_ref = (struct lua_func_ctx + ){.func_ref = density_init_func_ref, .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; gks_lw->has_Upar_init_func = has_Upar_init_func; - gks_lw->Upar_init_func_ref = (struct lua_func_ctx) { - .func_ref = Upar_init_func_ref, + gks_lw->Upar_init_func_ref = (struct lua_func_ctx + ){.func_ref = Upar_init_func_ref, .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; gks_lw->has_temp_init_func = has_temp_init_func; - gks_lw->temp_init_func_ref = (struct lua_func_ctx) { - .func_ref = temp_init_func_ref, + gks_lw->temp_init_func_ref = (struct lua_func_ctx + ){.func_ref = temp_init_func_ref, .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; gks_lw->has_par_temp_init_func = has_par_temp_init_func; - gks_lw->par_temp_init_func_ref = (struct lua_func_ctx) { - .func_ref = par_temp_init_func_ref, + gks_lw->par_temp_init_func_ref = (struct lua_func_ctx + ){.func_ref = par_temp_init_func_ref, .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; gks_lw->has_perp_temp_init_func = has_perp_temp_init_func; - gks_lw->perp_temp_init_func_ref = (struct lua_func_ctx) { - .func_ref = perp_temp_init_func_ref, + gks_lw->perp_temp_init_func_ref = (struct lua_func_ctx + ){.func_ref = perp_temp_init_func_ref, .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; gks_lw->proj_correct_all_moms = proj_correct_all_moms; gks_lw->source_id = source_id; gks_lw->num_sources = num_sources; - + for (int i = 0; i < num_sources; i++) { gks_lw->source_proj_id[i] = source_proj_id[i]; gks_lw->source_has_init_func[i] = source_has_init_func[i]; - gks_lw->source_init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = source_init_func_ref[i], + gks_lw->source_init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = source_init_func_ref[i], .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; gks_lw->source_has_density_init_func[i] = source_has_density_init_func[i]; - gks_lw->source_density_init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = source_density_init_func_ref[i], + gks_lw->source_density_init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = source_density_init_func_ref[i], .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; gks_lw->source_has_Upar_init_func[i] = source_has_Upar_init_func[i]; - gks_lw->source_Upar_init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = source_Upar_init_func_ref[i], + gks_lw->source_Upar_init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = source_Upar_init_func_ref[i], .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; gks_lw->source_has_temp_init_func[i] = source_has_temp_init_func[i]; - gks_lw->source_temp_init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = source_temp_init_func_ref[i], + gks_lw->source_temp_init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = source_temp_init_func_ref[i], .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; } gks_lw->correct_all_moms = correct_all_moms; @@ -842,12 +847,8 @@ gyrokinetic_species_lw_new(lua_State *L) gks_lw->collision_id = collision_id; gks_lw->has_self_nu_func = has_self_nu_func; - gks_lw->self_nu_func_ref = (struct lua_func_ctx) { - .func_ref = self_nu_func_ref, - .ndim = 0, - .nret = 1, - .L = L, - }; + gks_lw->self_nu_func_ref = + (struct lua_func_ctx){.func_ref = self_nu_func_ref, .ndim = 0, .nret = 1, .L = L}; gks_lw->num_cross_collisions = num_cross_collisions; for (int i = 0; i < num_cross_collisions; i++) { @@ -909,19 +910,16 @@ gyrokinetic_species_lw_new(lua_State *L) gks_lw->neut_react_ion_mass[i] = neut_react_ion_mass[i]; gks_lw->neut_react_elc_mass[i] = neut_react_elc_mass[i]; } - + // Set metatable. luaL_getmetatable(L, GYROKINETIC_SPECIES_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Species constructor. -static struct luaL_Reg gk_species_ctor[] = { - { "new", gyrokinetic_species_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg gk_species_ctor[] = {{"new", gyrokinetic_species_lw_new}, {0, 0}}; /* *********************** */ /* Neutral Species methods */ @@ -933,73 +931,81 @@ static struct luaL_Reg gk_species_ctor[] = { // Lua userdata object for constructing neutral species input. struct gyrokinetic_neutral_species_lw { int magic; // This must be first element in the struct. - + struct gkyl_gyrokinetic_neut_species gk_neut_species; // Input struct to construct neutral species. enum gkyl_projection_id proj_id; // Projection type. bool has_density_init_func; // Is there a density initialization function? - struct lua_func_ctx density_init_func_ref; // Lua registry reference to density initialization function. + struct lua_func_ctx + density_init_func_ref; // Lua registry reference to density initialization function. bool has_Udrift_init_func; // Is there a drift velocity initialiation function? - struct lua_func_ctx Udrift_init_func_ref; // Lua registry reference to drift velocity initialization function. + struct lua_func_ctx + Udrift_init_func_ref; // Lua registry reference to drift velocity initialization function. bool has_temp_init_func; // Is there a temperature initialization function? - struct lua_func_ctx temp_init_func_ref; // Lua registry reference to temperature initialization function. + struct lua_func_ctx + temp_init_func_ref; // Lua registry reference to temperature initialization function. }; -static int -gyrokinetic_neutral_species_lw_new(lua_State *L) +static int gyrokinetic_neutral_species_lw_new(lua_State *L) { - struct gkyl_gyrokinetic_neut_species gk_neut_species = { }; - + struct gkyl_gyrokinetic_neut_species gk_neut_species = {}; + gk_neut_species.mass = glua_tbl_get_number(L, "mass", 1.0); gk_neut_species.is_static = glua_tbl_get_bool(L, "isStatic", false); - with_lua_tbl_tbl(L, "cells") { + with_lua_tbl_tbl(L, "cells") + { for (int d = 0; d < 3; d++) { gk_neut_species.cells[d] = glua_tbl_iget_integer(L, d + 1, 0); } } - with_lua_tbl_tbl(L, "lower") { + with_lua_tbl_tbl(L, "lower") + { for (int d = 0; d < 3; d++) { gk_neut_species.lower[d] = glua_tbl_iget_number(L, d + 1, 0.0); } } - with_lua_tbl_tbl(L, "upper") { + with_lua_tbl_tbl(L, "upper") + { for (int d = 0; d < 3; d++) { gk_neut_species.upper[d] = glua_tbl_iget_number(L, d + 1, 0.0); } } - with_lua_tbl_tbl(L, "diagnostics") { + with_lua_tbl_tbl(L, "diagnostics") + { int num_diag_moments = glua_objlen(L); - for (int i = 0; i < num_diag_moments; i ++) { - gk_neut_species.diag_moments[i] = glua_tbl_iget_integer(L, i+1, 0); + for (int i = 0; i < num_diag_moments; i++) { + gk_neut_species.diag_moments[i] = glua_tbl_iget_integer(L, i + 1, 0); } gk_neut_species.num_diag_moments = num_diag_moments; } - with_lua_tbl_tbl(L, "bcs") { + with_lua_tbl_tbl(L, "bcs") + { int num_bcs = glua_objlen(L); for (int i = 0; i < num_bcs; i++) { gk_neut_species.bcs[i].dir = glua_tbl_get_integer(L, "dir", 0); gk_neut_species.bcs[i].edge = glua_tbl_get_integer(L, "edge", 0); gk_neut_species.bcs[i].type = glua_tbl_get_integer(L, "type", 0); - with_lua_tbl_tbl(L, "value") { + with_lua_tbl_tbl(L, "value") + { int num_vals = glua_objlen(L); for (int k = 0; k < num_vals; k++) { - gk_neut_species.bcs[i].value[k] = glua_tbl_iget_number(L, k + 1, 0.0);; + gk_neut_species.bcs[i].value[k] = glua_tbl_iget_number(L, k + 1, 0.0); + ; } } } } - enum gkyl_projection_id proj_id = GKYL_PROJ_FUNC; bool has_density_init_func = false; @@ -1011,7 +1017,8 @@ gyrokinetic_neutral_species_lw_new(lua_State *L) bool has_temp_init_func = false; int temp_init_func_ref = LUA_NOREF; - with_lua_tbl_tbl(L, "projection") { + with_lua_tbl_tbl(L, "projection") + { proj_id = glua_tbl_get_integer(L, "projectionID", 0); if (glua_tbl_get_func(L, "densityInit")) { @@ -1029,7 +1036,7 @@ gyrokinetic_neutral_species_lw_new(lua_State *L) has_temp_init_func = true; } } - + struct gyrokinetic_neutral_species_lw *gkns_lw = lua_newuserdata(L, sizeof(*gkns_lw)); gkns_lw->magic = GYROKINETIC_NEUTRAL_SPECIES_DEFAULT; gkns_lw->gk_neut_species = gk_neut_species; @@ -1037,40 +1044,37 @@ gyrokinetic_neutral_species_lw_new(lua_State *L) gkns_lw->proj_id = proj_id; gkns_lw->has_density_init_func = has_density_init_func; - gkns_lw->density_init_func_ref = (struct lua_func_ctx) { - .func_ref = density_init_func_ref, + gkns_lw->density_init_func_ref = (struct lua_func_ctx + ){.func_ref = density_init_func_ref, .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; gkns_lw->has_Udrift_init_func = has_Udrift_init_func; - gkns_lw->Udrift_init_func_ref = (struct lua_func_ctx) { - .func_ref = Udrift_init_func_ref, + gkns_lw->Udrift_init_func_ref = (struct lua_func_ctx + ){.func_ref = Udrift_init_func_ref, .ndim = 0, // This will be set later. .nret = 3, - .L = L, - }; + .L = L}; gkns_lw->has_temp_init_func = has_temp_init_func; - gkns_lw->temp_init_func_ref = (struct lua_func_ctx) { - .func_ref = temp_init_func_ref, + gkns_lw->temp_init_func_ref = (struct lua_func_ctx + ){.func_ref = temp_init_func_ref, .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; - + .L = L}; + // Set metatable. luaL_getmetatable(L, GYROKINETIC_NEUTRAL_SPECIES_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Species constructor. static struct luaL_Reg gk_neutral_species_ctor[] = { - { "new", gyrokinetic_neutral_species_lw_new }, - { 0, 0 } + {"new", gyrokinetic_neutral_species_lw_new}, + {0, 0} }; /* ************* */ @@ -1083,15 +1087,14 @@ static struct luaL_Reg gk_neutral_species_ctor[] = { // Lua userdata object for constructing field input. struct gyrokinetic_field_lw { int magic; // This must be first element in the struct. - + struct gkyl_gyrokinetic_field gk_field; // Input struct to construct field. }; -static int -gyrokinetic_field_lw_new(lua_State *L) +static int gyrokinetic_field_lw_new(lua_State *L) { - int vdim = 0; - struct gkyl_gyrokinetic_field gk_field = { }; + int vdim = 0; + struct gkyl_gyrokinetic_field gk_field = {}; gk_field.gkfield_id = glua_tbl_get_integer(L, "fieldID", 0); gk_field.electron_mass = glua_tbl_get_number(L, "electronMass", 0.0); @@ -1104,16 +1107,19 @@ gyrokinetic_field_lw_new(lua_State *L) gk_field.zero_init_field = glua_tbl_get_bool(L, "zeroInitField", false); gk_field.is_static = glua_tbl_get_bool(L, "isStatic", false); - with_lua_tbl_tbl(L, "poissonBcs") { + with_lua_tbl_tbl(L, "poissonBcs") + { int num_bcs = glua_objlen(L); for (int i = 0; i < num_bcs; i++) { gk_field.poisson_bcs[i].dir = glua_tbl_get_integer(L, "dir", 0); gk_field.poisson_bcs[i].edge = glua_tbl_get_integer(L, "edge", 0); gk_field.poisson_bcs[i].type = glua_tbl_get_integer(L, "type", 0); - with_lua_tbl_tbl(L, "value") { + with_lua_tbl_tbl(L, "value") + { int num_vals = glua_objlen(L); for (int k = 0; k < num_vals; k++) { - gk_field.poisson_bcs[i].value[k] = glua_tbl_iget_number(L, k + 1, 0.0);; + gk_field.poisson_bcs[i].value[k] = glua_tbl_iget_number(L, k + 1, 0.0); + ; } } } @@ -1123,19 +1129,16 @@ gyrokinetic_field_lw_new(lua_State *L) gkf_lw->magic = GYROKINETIC_FIELD_DEFAULT; gkf_lw->gk_field = gk_field; - + // Set metatable. luaL_getmetatable(L, GYROKINETIC_FIELD_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Field constructor. -static struct luaL_Reg gk_field_ctor[] = { - { "new", gyrokinetic_field_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg gk_field_ctor[] = {{"new", gyrokinetic_field_lw_new}, {0, 0}}; /* *********** */ /* App methods */ @@ -1151,10 +1154,13 @@ struct gyrokinetic_app_lw { struct lua_func_ctx mapc2p_ctx; // Function context for mapc2p. struct lua_func_ctx bfield_ctx; // Function context for bmag. - struct lua_func_ctx nonuniform_position_map_ctx[3]; // Function context for nonuniform position maps. + struct lua_func_ctx + nonuniform_position_map_ctx[3]; // Function context for nonuniform position maps. - bool has_mapc2p_mapping_func[GKYL_MAX_SPECIES]; // Is there a non-uniform velocity space mapping function? - struct lua_func_ctx mapc2p_mapping_func_ctx[GKYL_MAX_SPECIES]; // Context for non-uniform velocity space mapping function. + bool has_mapc2p_mapping_func + [GKYL_MAX_SPECIES]; // Is there a non-uniform velocity space mapping function? + struct lua_func_ctx mapc2p_mapping_func_ctx + [GKYL_MAX_SPECIES]; // Context for non-uniform velocity space mapping function. enum gkyl_projection_id proj_id[GKYL_MAX_SPECIES]; // Projection type. @@ -1162,115 +1168,178 @@ struct gyrokinetic_app_lw { struct lua_func_ctx init_func_ctx[GKYL_MAX_SPECIES]; // Context for initialization function. bool has_density_init_func[GKYL_MAX_SPECIES]; // Is there a density initialization function? - struct lua_func_ctx density_init_func_ctx[GKYL_MAX_SPECIES]; // Context for density initialization function. + struct lua_func_ctx + density_init_func_ctx[GKYL_MAX_SPECIES]; // Context for density initialization function. bool has_Upar_init_func[GKYL_MAX_SPECIES]; // Is there a parallel velocity initialization function? - struct lua_func_ctx Upar_init_func_ctx[GKYL_MAX_SPECIES]; // Context for parallel velocity initialziation function. - + struct lua_func_ctx + Upar_init_func_ctx[GKYL_MAX_SPECIES]; // Context for parallel velocity initialziation function. + bool has_temp_init_func[GKYL_MAX_SPECIES]; // Is there a temperature initialization function? - struct lua_func_ctx temp_init_func_ctx[GKYL_MAX_SPECIES]; // Context for temperature initialization function. + struct lua_func_ctx + temp_init_func_ctx[GKYL_MAX_SPECIES]; // Context for temperature initialization function. - bool has_par_temp_init_func[GKYL_MAX_SPECIES]; // Is there a parallel temperature initialization function? - struct lua_func_ctx par_temp_init_func_ctx[GKYL_MAX_SPECIES]; // Context for parallel temperature initialization function. + bool has_par_temp_init_func + [GKYL_MAX_SPECIES]; // Is there a parallel temperature initialization function? + struct lua_func_ctx par_temp_init_func_ctx + [GKYL_MAX_SPECIES]; // Context for parallel temperature initialization function. - bool has_perp_temp_init_func[GKYL_MAX_SPECIES]; // Is there a perpendicular temperature initialization function? - struct lua_func_ctx perp_temp_init_func_ctx[GKYL_MAX_SPECIES]; // Context for perpendicular temperature initialization function. + bool has_perp_temp_init_func + [GKYL_MAX_SPECIES]; // Is there a perpendicular temperature initialization function? + struct lua_func_ctx perp_temp_init_func_ctx + [GKYL_MAX_SPECIES]; // Context for perpendicular temperature initialization function. - bool proj_correct_all_moms[GKYL_MAX_SPECIES]; // Are we correcting all moments in projection, or only density? + bool proj_correct_all_moms + [GKYL_MAX_SPECIES]; // Are we correcting all moments in projection, or only density? enum gkyl_gk_collisionless_type collisionless_type[GKYL_MAX_SPECIES]; // Collisionless type. - + enum gkyl_collision_id collision_id[GKYL_MAX_SPECIES]; // Collision type. bool has_self_nu_func[GKYL_MAX_SPECIES]; // Is there a self-collision frequency function? - struct lua_func_ctx self_nu_func_ctx[GKYL_MAX_SPECIES]; // Context for self-collision frequency function. + struct lua_func_ctx + self_nu_func_ctx[GKYL_MAX_SPECIES]; // Context for self-collision frequency function. int num_cross_collisions[GKYL_MAX_SPECIES]; // Number of species that we cross-collide with. - char collide_with[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES][128]; // Names of species that we cross-collide with. + char collide_with[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES] + [128]; // Names of species that we cross-collide with. bool collision_norm_nu[GKYL_MAX_SPECIES]; // Are we rescaling the collision frequency? - double collision_den_ref[GKYL_MAX_SPECIES]; // Density used to calculate Coulomb logarithm for collision frequency. - double collision_temp_ref[GKYL_MAX_SPECIES]; // Temperature used to calculate Coulomb logarithm for collision frequency. - double collision_hbar[GKYL_MAX_SPECIES]; // Reduced Planck's constant for calculating collision frequency. + double collision_den_ref + [GKYL_MAX_SPECIES]; // Density used to calculate Coulomb logarithm for collision frequency. + double collision_temp_ref + [GKYL_MAX_SPECIES]; // Temperature used to calculate Coulomb logarithm for collision frequency. + double + collision_hbar[GKYL_MAX_SPECIES]; // Reduced Planck's constant for calculating collision frequency. double collision_eps0[GKYL_MAX_SPECIES]; // Vacuum permittivity for calculating collision frequency. double collision_eV[GKYL_MAX_SPECIES]; // Elementary charge for calculating collision frequency. - bool correct_all_moms[GKYL_MAX_SPECIES]; // Are we correcting all moments in collisions, or only density? - double iter_eps[GKYL_MAX_SPECIES]; // Error tolerance for moment fixes in collision (density is always exact). + bool correct_all_moms + [GKYL_MAX_SPECIES]; // Are we correcting all moments in collisions, or only density? + double iter_eps + [GKYL_MAX_SPECIES]; // Error tolerance for moment fixes in collision (density is always exact). int max_iter[GKYL_MAX_SPECIES]; // Maximum number of iterations for moment fixes in collisions. - bool use_last_converged[GKYL_MAX_SPECIES]; // Use last iteration value in collisions regardless of convergence? + bool use_last_converged + [GKYL_MAX_SPECIES]; // Use last iteration value in collisions regardless of convergence? enum gkyl_source_id source_id[GKYL_MAX_SPECIES]; // Source type. int num_sources[GKYL_MAX_SPECIES]; // Number of projection objects in source. - enum gkyl_projection_id source_proj_id[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Projection type in source. - - bool source_has_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there an initialization function in source? - struct lua_func_ctx source_init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for initialization function in source. - - bool source_has_density_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a density initialization function in source? - struct lua_func_ctx source_density_init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for density initialization function in source. - - bool source_has_Upar_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a parallel velocity initialization function in source? - struct lua_func_ctx source_Upar_init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for parallel velocity initialization function in source. - - bool source_has_temp_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a temperature initialization function in source? - struct lua_func_ctx source_temp_init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for temperature initialization function in source. + enum gkyl_projection_id source_proj_id[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Projection type in source. + + bool source_has_init_func[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Is there an initialization function in source? + struct lua_func_ctx + source_init_func_ctx[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Context for initialization function in source. + + bool source_has_density_init_func + [GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a density initialization function in source? + struct lua_func_ctx source_density_init_func_ctx + [GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for density initialization function in source. + + bool source_has_Upar_init_func + [GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Is there a parallel velocity initialization function in source? + struct lua_func_ctx source_Upar_init_func_ctx + [GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Context for parallel velocity initialization function in source. + + bool source_has_temp_init_func + [GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a temperature initialization function in source? + struct lua_func_ctx source_temp_init_func_ctx + [GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for temperature initialization function in source. enum gkyl_radiation_id radiation_id[GKYL_MAX_SPECIES]; // Radiation type. - int radiation_num_cross_collisions[GKYL_MAX_SPECIES]; // Number of radiation species that we cross-collide with. - char radiation_collide_with[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES][128]; // Names of radiation species that we cross-collide with. - - int radiation_z[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES]; // Atomic Z of radiation species that we are colliding with. - int radiation_charge_state[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES]; // Charge state of radiation species that we are colliding with. - int radiation_num_of_densities[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES]; // Maximum number of densities to use per charge state of radiation species that we are colliding with. - - enum gkyl_te_min_model radiation_te_min_model[GKYL_MAX_SPECIES]; // How is the radiation turned off (constant, or with varying electron temperature)? + int radiation_num_cross_collisions + [GKYL_MAX_SPECIES]; // Number of radiation species that we cross-collide with. + char radiation_collide_with[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES] + [128]; // Names of radiation species that we cross-collide with. + + int radiation_z[GKYL_MAX_SPECIES] + [GKYL_MAX_SPECIES]; // Atomic Z of radiation species that we are colliding with. + int radiation_charge_state + [GKYL_MAX_SPECIES] + [GKYL_MAX_SPECIES]; // Charge state of radiation species that we are colliding with. + int radiation_num_of_densities + [GKYL_MAX_SPECIES] + [GKYL_MAX_SPECIES]; // Maximum number of densities to use per charge state of radiation species that we are colliding with. + + enum gkyl_te_min_model radiation_te_min_model + [GKYL_MAX_SPECIES]; // How is the radiation turned off (constant, or with varying electron temperature)? double radiation_Te_min[GKYL_MAX_SPECIES]; // Minimum temperature (in J) at which to stop radiating. int num_react[GKYL_MAX_SPECIES]; // Number of reaction types. - enum gkyl_react_id react_id[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // What type of reaction (ionization, charge exchange, recombination)? - enum gkyl_react_self_type react_type_self[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // What is the role of the species in this reaction? + enum gkyl_react_id + react_id[GKYL_MAX_SPECIES] + [GKYL_MAX_REACT]; // What type of reaction (ionization, charge exchange, recombination)? + enum gkyl_react_self_type + react_type_self[GKYL_MAX_SPECIES] + [GKYL_MAX_REACT]; // What is the role of the species in this reaction? enum gkyl_ion_type react_ion_id[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // What type of ion is reacting? - char react_elc_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT][128]; // Name of electron species in the reaction. + char react_elc_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT] + [128]; // Name of electron species in the reaction. char react_ion_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT][128]; // Name of ion species in the reaction. - char react_donor_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT][128]; // Name of donor species in the reaction. - char react_recvr_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT][128]; // Name of receiver species in the reaction. + char react_donor_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT] + [128]; // Name of donor species in the reaction. + char react_recvr_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT] + [128]; // Name of receiver species in the reaction. - int react_charge_state[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // Charge state of species in the reaction. + int react_charge_state[GKYL_MAX_SPECIES] + [GKYL_MAX_REACT]; // Charge state of species in the reaction. double react_ion_mass[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // Mass of ion species in the reaction. - double react_elc_mass[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // Mass of electron species in the reaction. + double react_elc_mass[GKYL_MAX_SPECIES] + [GKYL_MAX_REACT]; // Mass of electron species in the reaction. int num_neut_react[GKYL_MAX_SPECIES]; // Number of neutral reaction types. - enum gkyl_react_id neut_react_id[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // What type of neutral reaction (ionization, charge exchange, recombination)? - enum gkyl_react_self_type neut_react_type_self[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // What is the role of the species in this neutral reaction? - enum gkyl_ion_type neut_react_ion_id[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // What type of ion in the neutral reaction? + enum gkyl_react_id neut_react_id + [GKYL_MAX_SPECIES] + [GKYL_MAX_REACT]; // What type of neutral reaction (ionization, charge exchange, recombination)? + enum gkyl_react_self_type neut_react_type_self + [GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // What is the role of the species in this neutral reaction? + enum gkyl_ion_type neut_react_ion_id[GKYL_MAX_SPECIES] + [GKYL_MAX_REACT]; // What type of ion in the neutral reaction? + + char neut_react_elc_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT] + [128]; // Name of electron species in the neutral reaction. + char neut_react_ion_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT] + [128]; // Name of ion species in the neutral reaction. + char neut_react_donor_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT] + [128]; // Name of donor species in the neutral reaction. + char neut_react_recvr_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT] + [128]; // Name of receiver species in the neutral reaction. + char neut_react_partner_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT] + [128]; // Name of partner species in the neutral reaction., + + int neut_react_charge_state[GKYL_MAX_SPECIES] + [GKYL_MAX_REACT]; // Charge state of species in the neutral reaction. + double neut_react_ion_mass[GKYL_MAX_SPECIES] + [GKYL_MAX_REACT]; // Mass of ion species in the neutral reaction. + double neut_react_elc_mass[GKYL_MAX_SPECIES] + [GKYL_MAX_REACT]; // Mass of electron species in the neutral reaction. - char neut_react_elc_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT][128]; // Name of electron species in the neutral reaction. - char neut_react_ion_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT][128]; // Name of ion species in the neutral reaction. - char neut_react_donor_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT][128]; // Name of donor species in the neutral reaction. - char neut_react_recvr_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT][128]; // Name of receiver species in the neutral reaction. - char neut_react_partner_nm[GKYL_MAX_SPECIES][GKYL_MAX_REACT][128]; // Name of partner species in the neutral reaction., + enum gkyl_projection_id neut_proj_id[GKYL_MAX_SPECIES]; // Neutral projection type. - int neut_react_charge_state[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // Charge state of species in the neutral reaction. - double neut_react_ion_mass[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // Mass of ion species in the neutral reaction. - double neut_react_elc_mass[GKYL_MAX_SPECIES][GKYL_MAX_REACT]; // Mass of electron species in the neutral reaction. + bool neut_has_density_init_func + [GKYL_MAX_SPECIES]; // Is there a neutral density initialization function? + struct lua_func_ctx neut_density_init_func_ctx + [GKYL_MAX_SPECIES]; // Context for neutral density initialization function. - enum gkyl_projection_id neut_proj_id[GKYL_MAX_SPECIES]; // Neutral projection type. + bool neut_has_Udrift_init_func + [GKYL_MAX_SPECIES]; // Is there a neutral drift velocity initialization function? + struct lua_func_ctx neut_Udrift_init_func_ctx + [GKYL_MAX_SPECIES]; // Context for neutral drift velocity initialziation function. - bool neut_has_density_init_func[GKYL_MAX_SPECIES]; // Is there a neutral density initialization function? - struct lua_func_ctx neut_density_init_func_ctx[GKYL_MAX_SPECIES]; // Context for neutral density initialization function. + bool neut_has_temp_init_func + [GKYL_MAX_SPECIES]; // Is there a neutral temperature initialization function? + struct lua_func_ctx neut_temp_init_func_ctx + [GKYL_MAX_SPECIES]; // Context for neutral temperature initialization function. - bool neut_has_Udrift_init_func[GKYL_MAX_SPECIES]; // Is there a neutral drift velocity initialization function? - struct lua_func_ctx neut_Udrift_init_func_ctx[GKYL_MAX_SPECIES]; // Context for neutral drift velocity initialziation function. - - bool neut_has_temp_init_func[GKYL_MAX_SPECIES]; // Is there a neutral temperature initialization function? - struct lua_func_ctx neut_temp_init_func_ctx[GKYL_MAX_SPECIES]; // Context for neutral temperature initialization function. - double t_start, t_end; // Start and end times of simulation. int num_frames; // Number of data frames to write. int field_energy_calcs; // Number of times to calculate field energy. @@ -1286,7 +1355,7 @@ static int get_species_inp(lua_State *L, int cdim, struct gyrokinetic_species_lw *species[GKYL_MAX_SPECIES]) { enum { TKEY = -2, TVAL = -1 }; - + int curr = 0; lua_pushnil(L); // Initial key is nil. while (lua_next(L, TKEY) != 0) { @@ -1302,7 +1371,7 @@ get_species_inp(lua_State *L, int cdim, struct gyrokinetic_species_lw *species[G if (gks->has_density_init_func) { gks->density_init_func_ref.ndim = cdim; } - + if (gks->has_Upar_init_func) { gks->Upar_init_func_ref.ndim = cdim; } @@ -1340,8 +1409,8 @@ get_species_inp(lua_State *L, int cdim, struct gyrokinetic_species_lw *species[G gks->source_temp_init_func_ref[i].ndim = cdim; } } - - if (lua_type(L,TKEY) == LUA_TSTRING) { + + if (lua_type(L, TKEY) == LUA_TSTRING) { const char *key = lua_tolstring(L, TKEY, 0); strcpy(gks->gk_species.name, key); } @@ -1355,8 +1424,7 @@ get_species_inp(lua_State *L, int cdim, struct gyrokinetic_species_lw *species[G } // Comparison method to sort species array by species name. -static int -species_compare_func(const void *a, const void *b) +static int species_compare_func(const void *a, const void *b) { const struct gyrokinetic_species_lw *const *spa = a; const struct gyrokinetic_species_lw *const *spb = b; @@ -1366,11 +1434,12 @@ species_compare_func(const void *a, const void *b) // Gets all neutral species objects from the App table, which must on top of // the stack. The number of neutral species is returned and the appropriate // pointers set in the neutral species pointer array. -static int -get_neutral_species_inp(lua_State *L, int cdim, struct gyrokinetic_neutral_species_lw *neut_species[GKYL_MAX_SPECIES]) +static int get_neutral_species_inp( + lua_State *L, int cdim, struct gyrokinetic_neutral_species_lw *neut_species[GKYL_MAX_SPECIES] +) { enum { TKEY = -2, TVAL = -1 }; - + int curr = 0; lua_pushnil(L); // Initial key is nil. while (lua_next(L, TKEY) != 0) { @@ -1382,7 +1451,7 @@ get_neutral_species_inp(lua_State *L, int cdim, struct gyrokinetic_neutral_speci if (gkns->has_density_init_func) { gkns->density_init_func_ref.ndim = cdim; } - + if (gkns->has_Udrift_init_func) { gkns->Udrift_init_func_ref.ndim = cdim; } @@ -1390,8 +1459,8 @@ get_neutral_species_inp(lua_State *L, int cdim, struct gyrokinetic_neutral_speci if (gkns->has_temp_init_func) { gkns->temp_init_func_ref.ndim = cdim; } - - if (lua_type(L,TKEY) == LUA_TSTRING) { + + if (lua_type(L, TKEY) == LUA_TSTRING) { const char *key = lua_tolstring(L, TKEY, 0); strcpy(gkns->gk_neut_species.name, key); } @@ -1405,28 +1474,26 @@ get_neutral_species_inp(lua_State *L, int cdim, struct gyrokinetic_neutral_speci } // Comparison method to sort neutral species array by neutral species name. -static int -neutral_species_compare_func(const void *a, const void *b) +static int neutral_species_compare_func(const void *a, const void *b) { const struct gyrokinetic_neutral_species_lw *const *spa = a; const struct gyrokinetic_neutral_species_lw *const *spb = b; return strcmp((*spa)->gk_neut_species.name, (*spb)->gk_neut_species.name); } -static struct gkyl_tool_args * -tool_args_from_argv(int optind, int argc, char *const*argv) +static struct gkyl_tool_args *tool_args_from_argv(int optind, int argc, char *const *argv) { struct gkyl_tool_args *targs = gkyl_malloc(sizeof *targs); - - targs->argc = argc-optind; + + targs->argc = argc - optind; targs->argv = 0; if (targs->argc > 0) { - targs->argv = gkyl_malloc(targs->argc*sizeof(char *)); - for (int i = optind, j = 0; i < argc; ++i, ++j) { - targs->argv[j] = gkyl_malloc(strlen(argv[i])+1); - strcpy(targs->argv[j], argv[i]); - } + targs->argv = gkyl_malloc(targs->argc * sizeof(char *)); + for (int i = optind, j = 0; i < argc; ++i, ++j) { + targs->argv[j] = gkyl_malloc(strlen(argv[i]) + 1); + strcpy(targs->argv[j], argv[i]); + } } return targs; @@ -1442,16 +1509,15 @@ struct script_cli { bool trace_mem; // Should we trace memory allocation/deallocation? bool use_verbose; // Should we use verbose output? bool is_restart; // Is this a restarted simulation? - int restart_frame; // Which frame to restart simulation from. - + int restart_frame; // Which frame to restart simulation from. + struct gkyl_tool_args *rest; }; -static struct script_cli -gk_parse_script_cli(struct gkyl_tool_args *acv) +static struct script_cli gk_parse_script_cli(struct gkyl_tool_args *acv) { struct script_cli cli = { - .help =- false, + .help = -false, .step_mode = false, .num_steps = INT_MAX, .use_mpi = false, @@ -1459,7 +1525,7 @@ gk_parse_script_cli(struct gkyl_tool_args *acv) .trace_mem = false, .use_verbose = false, .is_restart = false, - .restart_frame = 0, + .restart_frame = 0 }; #ifdef GKYL_HAVE_MPI @@ -1468,58 +1534,55 @@ gk_parse_script_cli(struct gkyl_tool_args *acv) #ifdef GKYL_HAVE_CUDA cli.use_gpu = true; #endif - - coption_long longopts[] = { - { 0 } - }; - const char* shortopts = "+hVs:SGmr:"; + + coption_long longopts[] = {{0}}; + const char *shortopts = "+hVs:SGmr:"; coption opt = coption_init(); int c; while ((c = coption_get(&opt, acv->argc, acv->argv, shortopts, longopts)) != -1) { switch (c) { - case 'h': - cli.help = true; - break; + case 'h': + cli.help = true; + break; - case 's': - cli.num_steps = atoi(opt.arg); - break; - - case 'S': - cli.use_mpi = false; - break; - - case 'G': - cli.use_gpu = false; - break; - - case 'm': - cli.trace_mem = true; - break; - - case 'V': - cli.use_verbose = true; - break; - - case 'r': - cli.is_restart = true; - cli.restart_frame = atoi(opt.arg); - break; - - case '?': - break; + case 's': + cli.num_steps = atoi(opt.arg); + break; + + case 'S': + cli.use_mpi = false; + break; + + case 'G': + cli.use_gpu = false; + break; + + case 'm': + cli.trace_mem = true; + break; + + case 'V': + cli.use_verbose = true; + break; + + case 'r': + cli.is_restart = true; + cli.restart_frame = atoi(opt.arg); + break; + + case '?': + break; } } cli.rest = tool_args_from_argv(opt.ind, acv->argc, acv->argv); - + return cli; } // Create top-level App object. -static int -gk_app_new(lua_State *L) +static int gk_app_new(lua_State *L) { struct gyrokinetic_app_lw *app_lw = gkyl_malloc(sizeof(*app_lw)); @@ -1527,12 +1590,13 @@ gk_app_new(lua_State *L) // GKYL_OUT_PREFIX. If this is not found then "g0-gyrokinetic" is used. const char *sim_name = "g0-gyrokinetic"; - with_lua_global(L, "GKYL_OUT_PREFIX") { + with_lua_global(L, "GKYL_OUT_PREFIX") + { if (lua_isstring(L, -1)) { sim_name = lua_tostring(L, -1); } } - + // Initialize app using table inputs (table is on top of stack). app_lw->t_start = glua_tbl_get_number(L, "tStart", 0.0); @@ -1543,12 +1607,13 @@ gk_app_new(lua_State *L) app_lw->dt_failure_tol = glua_tbl_get_number(L, "dtFailureTol", 1.0e-4); app_lw->num_failures_max = glua_tbl_get_integer(L, "numFailuresMax", 20); - struct gkyl_gk gk = { }; // Input table for app. + struct gkyl_gk gk = {}; // Input table for app. strcpy(gk.name, sim_name); - + int cdim = 0; - with_lua_tbl_tbl(L, "cells") { + with_lua_tbl_tbl(L, "cells") + { gk.cdim = cdim = glua_objlen(L); for (int d = 0; d < cdim; d++) { @@ -1560,22 +1625,25 @@ gk_app_new(lua_State *L) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } - - with_lua_tbl_tbl(L, "decompCuts") { + + with_lua_tbl_tbl(L, "decompCuts") + { int ncuts = glua_objlen(L); for (int d = 0; d < ncuts; d++) { cuts[d] = glua_tbl_iget_integer(L, d + 1, 0); } - } + } - with_lua_tbl_tbl(L, "lower") { + with_lua_tbl_tbl(L, "lower") + { for (int d = 0; d < cdim; d++) { gk.lower[d] = glua_tbl_iget_number(L, d + 1, 0.0); } } - with_lua_tbl_tbl(L, "upper") { + with_lua_tbl_tbl(L, "upper") + { for (int d = 0; d < cdim; d++) { gk.upper[d] = glua_tbl_iget_number(L, d + 1, 0.0); } @@ -1584,13 +1652,12 @@ gk_app_new(lua_State *L) gk.cfl_frac = glua_tbl_get_number(L, "cflFrac", 0.95); gk.poly_order = glua_tbl_get_integer(L, "polyOrder", 1); - gk.basis_type = get_basis_type( - glua_tbl_get_string(L, "basis", "serendipity") - ); + gk.basis_type = get_basis_type(glua_tbl_get_string(L, "basis", "serendipity")); gk.num_periodic_dir = 0; if (glua_tbl_has_key(L, "periodicDirs")) { - with_lua_tbl_tbl(L, "periodicDirs") { + with_lua_tbl_tbl(L, "periodicDirs") + { gk.num_periodic_dir = glua_objlen(L); for (int d = 0; d < gk.num_periodic_dir; d++) { @@ -1600,10 +1667,12 @@ gk_app_new(lua_State *L) } } - with_lua_tbl_tbl(L, "geometry") { + with_lua_tbl_tbl(L, "geometry") + { gk.geometry.geometry_id = glua_tbl_get_integer(L, "geometryID", 0); - with_lua_tbl_tbl(L, "world") { + with_lua_tbl_tbl(L, "world") + { for (int d = 0; d < 3 - cdim; d++) { gk.geometry.world[d] = glua_tbl_iget_number(L, d + 1, 0.0); } @@ -1627,12 +1696,14 @@ gk_app_new(lua_State *L) bfield_func_ref = luaL_ref(L, LUA_REGISTRYINDEX); } - with_lua_tbl_tbl(L, "positionMap") { + with_lua_tbl_tbl(L, "positionMap") + { gk.geometry.position_map_info.id = glua_tbl_get_integer(L, "ID", 0); bool has_nonuniform_position_map[3]; int nonuniform_position_map_ref[3]; - with_lua_tbl_tbl(L, "maps") { + with_lua_tbl_tbl(L, "maps") + { for (int i = 0; i < 3; i++) { gk.geometry.position_map_info.ctxs[i] = 0; gk.geometry.position_map_info.maps[i] = 0; @@ -1648,12 +1719,8 @@ gk_app_new(lua_State *L) for (int i = 0; i < 3; i++) { if (has_nonuniform_position_map[i]) { - app_lw->nonuniform_position_map_ctx[i] = (struct lua_func_ctx) { - .func_ref = nonuniform_position_map_ref[i], - .ndim = 1, - .nret = 1, - .L = L, - }; + app_lw->nonuniform_position_map_ctx[i] = (struct lua_func_ctx + ){.func_ref = nonuniform_position_map_ref[i], .ndim = 1, .nret = 1, .L = L}; gk.geometry.position_map_info.maps[i] = gkyl_lw_eval_cb; gk.geometry.position_map_info.ctxs[i] = &app_lw->nonuniform_position_map_ctx[i]; } @@ -1661,23 +1728,15 @@ gk_app_new(lua_State *L) } if (has_mapc2p) { - app_lw->mapc2p_ctx = (struct lua_func_ctx) { - .func_ref = mapc2p_ref, - .ndim = 3, - .nret = 3, - .L = L, - }; + app_lw->mapc2p_ctx = + (struct lua_func_ctx){.func_ref = mapc2p_ref, .ndim = 3, .nret = 3, .L = L}; gk.geometry.mapc2p = gkyl_lw_eval_cb; gk.geometry.c2p_ctx = &app_lw->mapc2p_ctx; } if (has_bfield_func) { - app_lw->bfield_ctx = (struct lua_func_ctx) { - .func_ref = bfield_func_ref, - .ndim = 3, - .nret = 3, - .L = L, - }; + app_lw->bfield_ctx = + (struct lua_func_ctx){.func_ref = bfield_func_ref, .ndim = 3, .nret = 3, .L = L}; gk.geometry.bfield_func = gkyl_lw_eval_cb; gk.geometry.bfield_ctx = &app_lw->bfield_ctx; } @@ -1692,7 +1751,7 @@ gk_app_new(lua_State *L) // proceeding as there is no way to ensure that all cores loop over // Lua tables in the same order qsort(species, gk.num_species, sizeof(struct gyrokinetic_species_lw *), species_compare_func); - + for (int s = 0; s < gk.num_species; s++) { gk.species[s] = species[s]->gk_species; gk.species[s].vdim = species[s]->vdim; @@ -1710,13 +1769,13 @@ gk_app_new(lua_State *L) app_lw->has_Upar_init_func[s] = species[s]->has_Upar_init_func; app_lw->Upar_init_func_ctx[s] = species[s]->Upar_init_func_ref; - + app_lw->has_temp_init_func[s] = species[s]->has_temp_init_func; app_lw->temp_init_func_ctx[s] = species[s]->temp_init_func_ref; app_lw->has_par_temp_init_func[s] = species[s]->has_par_temp_init_func; app_lw->par_temp_init_func_ctx[s] = species[s]->par_temp_init_func_ref; - + app_lw->has_perp_temp_init_func[s] = species[s]->has_perp_temp_init_func; app_lw->perp_temp_init_func_ctx[s] = species[s]->perp_temp_init_func_ref; @@ -1842,7 +1901,8 @@ gk_app_new(lua_State *L) if (species[s]->source_has_density_init_func[i]) { gk.species[s].source.projection[i].density = gkyl_lw_eval_cb; - gk.species[s].source.projection[i].ctx_density = &app_lw->source_density_init_func_ctx[s][i]; + gk.species[s].source.projection[i].ctx_density = + &app_lw->source_density_init_func_ctx[s][i]; } if (species[s]->source_has_Upar_init_func[i]) { @@ -1963,8 +2023,11 @@ gk_app_new(lua_State *L) // need to sort the neut_species[] array by name of the neutral species before // proceeding as there is no way to ensure that all cores loop over // Lua tables in the same order - qsort(neut_species, gk.num_neut_species, sizeof(struct gyrokinetic_neutral_species_lw *), neutral_species_compare_func); - + qsort( + neut_species, gk.num_neut_species, sizeof(struct gyrokinetic_neutral_species_lw *), + neutral_species_compare_func + ); + for (int s = 0; s < gk.num_neut_species; s++) { gk.neut_species[s] = neut_species[s]->gk_neut_species; @@ -1975,7 +2038,7 @@ gk_app_new(lua_State *L) app_lw->neut_has_Udrift_init_func[s] = neut_species[s]->has_Udrift_init_func; app_lw->neut_Udrift_init_func_ctx[s] = neut_species[s]->Udrift_init_func_ref; - + app_lw->neut_has_temp_init_func[s] = neut_species[s]->has_temp_init_func; app_lw->neut_temp_init_func_ctx[s] = neut_species[s]->temp_init_func_ref; @@ -1997,7 +2060,8 @@ gk_app_new(lua_State *L) } } - with_lua_tbl_key(L, "field") { + with_lua_tbl_key(L, "field") + { if (lua_type(L, -1) == LUA_TUSERDATA) { struct gyrokinetic_field_lw *gkf = lua_touserdata(L, -1); @@ -2011,7 +2075,7 @@ gk_app_new(lua_State *L) struct gkyl_comm *comm = 0; for (int d = 0; d < cdim; d++) { - gk.parallelism.cuts[d] = cuts[d]; + gk.parallelism.cuts[d] = cuts[d]; } struct gkyl_tool_args *args = gkyl_tool_args_new(L); @@ -2020,52 +2084,44 @@ gk_app_new(lua_State *L) #ifdef GKYL_HAVE_MPI if (script_cli.use_gpu && script_cli.use_mpi) { #ifdef GKYL_HAVE_NCCL - with_lua_global(L, "GKYL_MPI_COMM") { + with_lua_global(L, "GKYL_MPI_COMM") + { if (lua_islightuserdata(L, -1)) { - struct { MPI_Comm comm; } *lw_mpi_comm_world = lua_touserdata(L, -1); + struct { + MPI_Comm comm; + } *lw_mpi_comm_world = lua_touserdata(L, -1); MPI_Comm mpi_comm = lw_mpi_comm_world->comm; int nrank = 1; // Number of processors in simulation. MPI_Comm_size(mpi_comm, &nrank); - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = mpi_comm, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = mpi_comm}); } } #else printf("Using CUDA and MPI together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (script_cli.use_mpi) { - with_lua_global(L, "GKYL_MPI_COMM") { + } else if (script_cli.use_mpi) { + with_lua_global(L, "GKYL_MPI_COMM") + { if (lua_islightuserdata(L, -1)) { - struct { MPI_Comm comm; } *lw_mpi_comm_world = lua_touserdata(L, -1); + struct { + MPI_Comm comm; + } *lw_mpi_comm_world = lua_touserdata(L, -1); MPI_Comm mpi_comm = lw_mpi_comm_world->comm; int nrank = 1; // Number of processors in simulation. MPI_Comm_size(mpi_comm, &nrank); - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = mpi_comm, - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = mpi_comm}); } } - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = script_cli.use_gpu, - } - ); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = script_cli.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = script_cli.use_gpu, - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = script_cli.use_gpu}); #endif gk.parallelism.comm = comm; @@ -2086,25 +2142,24 @@ gk_app_new(lua_State *L) printf("tot_cuts = %d (%d)\n", tot_cuts, comm_sz); luaL_error(L, "Number of ranks and cuts do not match!"); } - + app_lw->app = gkyl_gyrokinetic_app_new(&gk); gkyl_comm_release(comm); // Create Lua userdata. - struct gyrokinetic_app_lw **l_app_lw = lua_newuserdata(L, sizeof(struct gyrokinetic_app_lw*)); + struct gyrokinetic_app_lw **l_app_lw = lua_newuserdata(L, sizeof(struct gyrokinetic_app_lw *)); *l_app_lw = app_lw; // Point it to the Lua app pointer. // Set metatable. luaL_getmetatable(L, GYROKINETIC_APP_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Apply initial conditions. (time) -> bool. -static int -gk_app_apply_ic(lua_State *L) +static int gk_app_apply_ic(lua_State *L) { bool status = true; @@ -2114,13 +2169,12 @@ gk_app_apply_ic(lua_State *L) double t0 = luaL_optnumber(L, 2, app_lw->t_start); gkyl_gyrokinetic_app_apply_ic(app_lw->app, t0); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Apply initial conditions to species. (sidx, time) -> bool. -static int -gk_app_apply_ic_species(lua_State *L) +static int gk_app_apply_ic_species(lua_State *L) { bool status = true; @@ -2131,13 +2185,12 @@ gk_app_apply_ic_species(lua_State *L) double t0 = luaL_optnumber(L, 3, app_lw->t_start); gkyl_gyrokinetic_app_apply_ic_species(app_lw->app, sidx, t0); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Compute integrated moments. (tm) -> bool. -static int -gk_app_calc_integrated_mom(lua_State *L) +static int gk_app_calc_integrated_mom(lua_State *L) { bool status = true; @@ -2147,14 +2200,13 @@ gk_app_calc_integrated_mom(lua_State *L) double tm = luaL_checknumber(L, 2); gkyl_gyrokinetic_app_calc_integrated_mom(app_lw->app, tm); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Compute integrated field energy (L2 norm of each field // component). (tm) -> bool. -static int -gk_app_calc_field_energy(lua_State *L) +static int gk_app_calc_field_energy(lua_State *L) { bool status = true; @@ -2164,13 +2216,12 @@ gk_app_calc_field_energy(lua_State *L) double tm = luaL_checknumber(L, 2); gkyl_gyrokinetic_app_calc_field_energy(app_lw->app, tm); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write solution (field and species) to file (time, frame) -> bool. -static int -gk_app_write(lua_State *L) +static int gk_app_write(lua_State *L) { bool status = true; @@ -2181,13 +2232,12 @@ gk_app_write(lua_State *L) int frame = luaL_checkinteger(L, 3); gkyl_gyrokinetic_app_write(app_lw->app, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write field to file (time, frame) -> bool. -static int -gk_app_write_field(lua_State *L) +static int gk_app_write_field(lua_State *L) { bool status = true; @@ -2198,13 +2248,12 @@ gk_app_write_field(lua_State *L) int frame = luaL_checkinteger(L, 3); gkyl_gyrokinetic_app_write_field(app_lw->app, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write species solution to file (sidx, time, frame) -> bool. -static int -gk_app_write_species(lua_State *L) +static int gk_app_write_species(lua_State *L) { bool status = true; @@ -2216,13 +2265,12 @@ gk_app_write_species(lua_State *L) int frame = luaL_checkinteger(L, 4); gkyl_gyrokinetic_app_write_species(app_lw->app, sidx, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write diagnostic moments to file (time, frame) -> bool. -static int -gk_app_write_mom(lua_State *L) +static int gk_app_write_mom(lua_State *L) { bool status = true; @@ -2233,13 +2281,12 @@ gk_app_write_mom(lua_State *L) int frame = luaL_checkinteger(L, 3); gkyl_gyrokinetic_app_write_mom(app_lw->app, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write integrated moments to file () -> bool. -static int -gk_app_write_integrated_mom(lua_State *L) +static int gk_app_write_integrated_mom(lua_State *L) { bool status = true; @@ -2248,14 +2295,12 @@ gk_app_write_integrated_mom(lua_State *L) gkyl_gyrokinetic_app_write_integrated_mom(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } - // Write integrated field energy to file () -> bool. -static int -gk_app_write_field_energy(lua_State *L) +static int gk_app_write_field_energy(lua_State *L) { bool status = true; @@ -2264,13 +2309,12 @@ gk_app_write_field_energy(lua_State *L) gkyl_gyrokinetic_app_write_field_energy(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write simulation statistics to JSON. () -> bool. -static int -gk_app_stat_write(lua_State *L) +static int gk_app_stat_write(lua_State *L) { bool status = true; @@ -2280,12 +2324,12 @@ gk_app_stat_write(lua_State *L) gkyl_gyrokinetic_app_stat_write(app_lw->app); lua_pushboolean(L, status); - return 1; + return 1; } // Write data from simulation to file. static void -write_data(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_app* app, double t_curr, bool force_write) +write_data(struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -2300,8 +2344,9 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_app* app, double t_curr } // Calculate and append field energy to dynvector. -static void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_gyrokinetic_app* app, double t_curr, bool force_calc) +static void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_gyrokinetic_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_gyrokinetic_app_calc_field_energy(app, t_curr); @@ -2309,8 +2354,9 @@ calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_gyrokinetic_app* app, double } // Calculate and append integrated moments to dynvector. -static void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_gyrokinetic_app* app, double t_curr, bool force_calc) +static void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_gyrokinetic_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_gyrokinetic_app_calc_integrated_mom(app, t_curr); @@ -2320,33 +2366,36 @@ calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_gyrokinetic_app* app, doub // Step message context. struct step_message_trigs { int log_count; // Number of times logging called. - int tenth, p1c; + int tenth, p1c; struct gkyl_tm_trigger log_trig; // 10% trigger. struct gkyl_tm_trigger log_trig_1p; // 1% trigger. }; // Write log message to console. -static void -write_step_message(const struct gkyl_gyrokinetic_app *app, struct step_message_trigs *trigs, int step, double t_curr, double dt_next) +static void write_step_message( + const struct gkyl_gyrokinetic_app *app, struct step_message_trigs *trigs, int step, double t_curr, + double dt_next +) { if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig, t_curr)) { if (trigs->log_count > 0) { - gkyl_gyrokinetic_app_cout(app, stdout, " Step %d at time %#11.8g. Time-step %.6e. Completed %g%s\n", step, t_curr, dt_next, trigs->tenth * 10.0, "%"); - } - else { + gkyl_gyrokinetic_app_cout( + app, stdout, " Step %d at time %#11.8g. Time-step %.6e. Completed %g%s\n", step, t_curr, + dt_next, trigs->tenth * 10.0, "%" + ); + } else { trigs->log_count += 1; } - + trigs->tenth += 1; } if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig_1p, t_curr)) { gkyl_gyrokinetic_app_cout(app, stdout, "%d", trigs->p1c); - trigs->p1c = (trigs->p1c+1) % 10; + trigs->p1c = (trigs->p1c + 1) % 10; } } -static void -show_help(const struct gkyl_gyrokinetic_app *app) +static void show_help(const struct gkyl_gyrokinetic_app *app) { gkyl_gyrokinetic_app_cout(app, stdout, "Gyrokinetic script takes the following arguments:\n"); gkyl_gyrokinetic_app_cout(app, stdout, " -h Print this help message and exit\n"); @@ -2361,8 +2410,7 @@ show_help(const struct gkyl_gyrokinetic_app *app) } // Run simulation. (num_steps) -> bool. num_steps is optional. -static int -gk_app_run(lua_State *L) +static int gk_app_run(lua_State *L) { bool ret_status = true; @@ -2402,10 +2450,14 @@ gk_app_run(lua_State *L) int frame_curr = 0; if (is_restart) { - struct gkyl_app_restart_status status = gkyl_gyrokinetic_app_read_from_frame(app, restart_frame); + struct gkyl_app_restart_status status = + gkyl_gyrokinetic_app_read_from_frame(app, restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_gyrokinetic_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_gyrokinetic_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -2414,8 +2466,7 @@ gk_app_run(lua_State *L) gkyl_gyrokinetic_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_gyrokinetic_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_gyrokinetic_app_apply_ic(app, t_curr); } @@ -2423,16 +2474,22 @@ gk_app_run(lua_State *L) int field_energy_calcs = app_lw->field_energy_calcs; int integrated_mom_calcs = app_lw->integrated_mom_calcs; // Triggers for IO and logging. - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; struct step_message_trigs m_trig = { .log_count = 0, - .tenth = t_curr > 0.0 ? (int) floor(t_curr / t_end * 10.0) : 0.0, - .p1c = t_curr > 0.0 ? (int) floor(t_curr / t_end * 100.0) % 10 : 0.0, - .log_trig = { .dt = t_end / 10.0, .tcurr = t_curr }, - .log_trig_1p = { .dt = t_end / 100.0, .tcurr = t_curr }, + .tenth = t_curr > 0.0 ? (int)floor(t_curr / t_end * 10.0) : 0.0, + .p1c = t_curr > 0.0 ? (int)floor(t_curr / t_end * 100.0) % 10 : 0.0, + .log_trig = {.dt = t_end / 10.0, .tcurr = t_curr}, + .log_trig_1p = {.dt = t_end / 100.0, .tcurr = t_curr} }; struct timespec tm_ic0 = gkyl_wall_clock(); @@ -2441,7 +2498,9 @@ gk_app_run(lua_State *L) calc_integrated_mom(&im_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); - gkyl_gyrokinetic_app_cout(app, stdout, "Initialization completed in %g sec\n\n", gkyl_time_diff_now_sec(tm_ic0)); + gkyl_gyrokinetic_app_cout( + app, stdout, "Initialization completed in %g sec\n\n", gkyl_time_diff_now_sec(tm_ic0) + ); // Compute initial guess of maximum stable time-step. double dt = t_end - t_curr; @@ -2476,16 +2535,19 @@ gk_app_run(lua_State *L) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_gyrokinetic_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); gkyl_gyrokinetic_app_cout(app, stdout, " is below %g*dt_init ...", dt_failure_tol); gkyl_gyrokinetic_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { - gkyl_gyrokinetic_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_gyrokinetic_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_gyrokinetic_app_cout( + app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -2493,8 +2555,7 @@ gk_app_run(lua_State *L) break; } - } - else { + } else { num_failures = 0; } @@ -2517,37 +2578,74 @@ gk_app_run(lua_State *L) gkyl_gyrokinetic_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_gyrokinetic_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_gyrokinetic_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_gyrokinetic_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_gyrokinetic_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_gyrokinetic_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_gyrokinetic_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); - // Plasma species counters. - gkyl_gyrokinetic_app_cout(app, stdout, "Number of species CFL reduction calls %ld\n", stat.n_species_omega_cfl); + // Plasma species counters. + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of species CFL reduction calls %ld\n", stat.n_species_omega_cfl + ); gkyl_gyrokinetic_app_cout(app, stdout, "Number of moment updater calls %ld\n", stat.n_mom); gkyl_gyrokinetic_app_cout(app, stdout, "Number of diagnostics computed %ld\n", stat.n_diag); - gkyl_gyrokinetic_app_cout(app, stdout, "Number of write calls for phase space fields %ld\n", stat.n_io); - gkyl_gyrokinetic_app_cout(app, stdout, "Number of write calls for configuration space fields %ld\n", stat.n_diag_io); - // Neutral species counters. + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of write calls for phase space fields %ld\n", stat.n_io + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of write calls for configuration space fields %ld\n", stat.n_diag_io + ); + // Neutral species counters. if (app->num_neut_species > 0) { - - gkyl_gyrokinetic_app_cout(app, stdout, "Number of neutral species CFL reduction calls %ld\n", stat.n_neut_species_omega_cfl); - gkyl_gyrokinetic_app_cout(app, stdout, "Number of neutral moment updater calls %ld\n", stat.n_neut_mom); - gkyl_gyrokinetic_app_cout(app, stdout, "Number of neutral diagnostics computed %ld\n", stat.n_neut_diag); - gkyl_gyrokinetic_app_cout(app, stdout, "Number of write calls for neutrals' phase space fields %ld\n", stat.n_neut_io); - gkyl_gyrokinetic_app_cout(app, stdout, "Number of write calls for neutrals' configuration space fields %ld\n", stat.n_neut_diag_io); + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of neutral species CFL reduction calls %ld\n", + stat.n_neut_species_omega_cfl + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of neutral moment updater calls %ld\n", stat.n_neut_mom + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of neutral diagnostics computed %ld\n", stat.n_neut_diag + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of write calls for neutrals' phase space fields %ld\n", stat.n_neut_io + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of write calls for neutrals' configuration space fields %ld\n", + stat.n_neut_diag_io + ); } - // Field counters. + // Field counters. if (app->field->update_field > 0) { - gkyl_gyrokinetic_app_cout(app, stdout, "Number of field diagnostics computed %ld\n", stat.n_diag); - gkyl_gyrokinetic_app_cout(app, stdout, "Number of write calls for fields %ld\n", stat.n_field_io); - gkyl_gyrokinetic_app_cout(app, stdout, "Number of write calls for fields' diagnostics %ld\n", stat.n_field_diag_io); + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of field diagnostics computed %ld\n", stat.n_diag + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of write calls for fields %ld\n", stat.n_field_io + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of write calls for fields' diagnostics %ld\n", stat.n_field_diag_io + ); } // Timers. gkyl_gyrokinetic_app_print_timings(app, stdout); - gkyl_gyrokinetic_app_cout(app, stdout, "Species initial conditions took %lg secs\n", stat.init_species_tm); - gkyl_gyrokinetic_app_cout(app, stdout, "Species LTE computation, including corrections, took %lg secs\n", stat.species_lte_tm); - gkyl_gyrokinetic_app_cout(app, stdout, "Neutral species initial conditions took %lg secs\n", stat.init_neut_species_tm); - gkyl_gyrokinetic_app_cout(app, stdout, "Neutral species LTE computation, including corrections, took %lg secs\n", stat.neut_species_lte_tm); + gkyl_gyrokinetic_app_cout( + app, stdout, "Species initial conditions took %lg secs\n", stat.init_species_tm + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Species LTE computation, including corrections, took %lg secs\n", + stat.species_lte_tm + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Neutral species initial conditions took %lg secs\n", stat.init_neut_species_tm + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Neutral species LTE computation, including corrections, took %lg secs\n", + stat.neut_species_lte_tm + ); freeresources: @@ -2556,43 +2654,38 @@ gk_app_run(lua_State *L) } // Clean up memory allocated for simulation. -static int -gk_app_gc(lua_State *L) +static int gk_app_gc(lua_State *L) { struct gyrokinetic_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, GYROKINETIC_APP_METATABLE_NM); struct gyrokinetic_app_lw *app_lw = *l_app_lw; gkyl_gyrokinetic_app_release(app_lw->app); gkyl_free(*l_app_lw); - + return 0; } // App constructor. -static struct luaL_Reg gk_app_ctor[] = { - { "new", gk_app_new }, - { 0, 0 } -}; +static struct luaL_Reg gk_app_ctor[] = {{"new", gk_app_new}, {0, 0}}; // App methods. static struct luaL_Reg gk_app_funcs[] = { - { "apply_ic", gk_app_apply_ic }, - { "apply_ic_species", gk_app_apply_ic_species }, - { "calc_integrated_mom", gk_app_calc_integrated_mom }, - { "calc_field_energy", gk_app_calc_field_energy }, - { "write", gk_app_write }, - { "write_field", gk_app_write_field }, - { "write_species", gk_app_write_species }, - { "write_mom", gk_app_write_mom }, - { "write_integrated_mom", gk_app_write_integrated_mom }, - { "write_field_energy", gk_app_write_field_energy }, - { "stat_write", gk_app_stat_write }, - { "run", gk_app_run }, - { 0, 0 } + {"apply_ic", gk_app_apply_ic}, + {"apply_ic_species", gk_app_apply_ic_species}, + {"calc_integrated_mom", gk_app_calc_integrated_mom}, + {"calc_field_energy", gk_app_calc_field_energy}, + {"write", gk_app_write}, + {"write_field", gk_app_write_field}, + {"write_species", gk_app_write_species}, + {"write_mom", gk_app_write_mom}, + {"write_integrated_mom", gk_app_write_integrated_mom}, + {"write_field_energy", gk_app_write_field_energy}, + {"stat_write", gk_app_stat_write}, + {"run", gk_app_run}, + {0, 0} }; -static void -app_openlibs(lua_State *L) +static void app_openlibs(lua_State *L) { // Register top-level App. do { @@ -2605,36 +2698,31 @@ app_openlibs(lua_State *L) lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_register(L, NULL, gk_app_funcs); - + luaL_register(L, "G0.Gyrokinetic.App", gk_app_ctor); - - } - while (0); + + } while (0); // Register Species input struct. do { luaL_newmetatable(L, GYROKINETIC_SPECIES_METATABLE_NM); luaL_register(L, "G0.Gyrokinetic.Species", gk_species_ctor); - } - while (0); + } while (0); // Register Neutral Species input struct. do { luaL_newmetatable(L, GYROKINETIC_NEUTRAL_SPECIES_METATABLE_NM); luaL_register(L, "G0.Gyrokinetic.NeutralSpecies", gk_neutral_species_ctor); - } - while (0); + } while (0); // Register Field input struct. do { luaL_newmetatable(L, GYROKINETIC_FIELD_METATABLE_NM); luaL_register(L, "G0.Gyrokinetic.Field", gk_field_ctor); - } - while (0); + } while (0); } -void -gkyl_gyrokinetic_lw_openlibs(lua_State *L) +void gkyl_gyrokinetic_lw_openlibs(lua_State *L) { // Register types for gyrokinetic FEM boundary conditions, geometry type, position map type, field ID, radiation ID, Te min model type, reaction type, ion type, and self-reaction type. gkyl_register_gyrokinetic_fem_bc_types(L); @@ -2648,7 +2736,7 @@ gkyl_gyrokinetic_lw_openlibs(lua_State *L) gkyl_register_gyrokinetic_ion_types(L); gkyl_register_gyrokinetic_self_reaction_types(L); gkyl_register_gyrokinetic_bc_types(L); - + app_openlibs(L); } diff --git a/gyrokinetic/apps/gyrokinetic_multib.c b/gyrokinetic/apps/gyrokinetic_multib.c index de0352dee2..c35519dbad 100644 --- a/gyrokinetic/apps/gyrokinetic_multib.c +++ b/gyrokinetic/apps/gyrokinetic_multib.c @@ -8,33 +8,34 @@ #include // Compute total number of ranges specified by cuts. -static inline int -calc_cuts(int ndim, const int *cuts) +static inline int calc_cuts(int ndim, const int *cuts) { int tc = 1; - for (int d=0; dcuts); max_cuts = ncuts > max_cuts ? ncuts : max_cuts; @@ -45,9 +46,10 @@ calc_tot_and_max_cuts(const struct gkyl_gk_block_geom *gk_block_geom, int tot_ma } // Construct single-block App geometry for given block ID. -static struct gkyl_gyrokinetic_app * -singleb_app_new_geom(const struct gkyl_gyrokinetic_multib *mbinp, int bid, - const struct gkyl_gyrokinetic_multib_app *mbapp) +static struct gkyl_gyrokinetic_app *singleb_app_new_geom( + const struct gkyl_gyrokinetic_multib *mbinp, int bid, + const struct gkyl_gyrokinetic_multib_app *mbapp +) { // For kinetic simulations, block dimension defined configuration-space dimensionality. int cdim = gkyl_gk_block_geom_ndim(mbapp->gk_block_geom); @@ -57,7 +59,7 @@ singleb_app_new_geom(const struct gkyl_gyrokinetic_multib *mbinp, int bid, gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, bid); // Construct top-level single-block input struct. - struct gkyl_gk app_inp = { }; + struct gkyl_gk app_inp = {}; strcpy(app_inp.name, mbinp->name); if (num_blocks > 1) { @@ -68,39 +70,46 @@ singleb_app_new_geom(const struct gkyl_gyrokinetic_multib *mbinp, int bid, // Set the configuration-space extents, cells, and geometry. app_inp.cdim = cdim; - for (int i=0; ilower[i]; app_inp.upper[i] = bgi->upper[i]; app_inp.cells[i] = bgi->cells[i]; } // Set z dir grid extents based on tokamak global normalization - if (bgi->geometry.geometry_id == GKYL_GEOMETRY_TOKAMAK || bgi->geometry.geometry_id == GKYL_GEOMETRY_FROMFILE) { - gkyl_gk_geometry_tok_set_grid_extents(bgi->geometry.efit_info, bgi->geometry.tok_grid_info, &app_inp.lower[cdim-1], &app_inp.upper[cdim-1]); + if (bgi->geometry.geometry_id == GKYL_GEOMETRY_TOKAMAK || + bgi->geometry.geometry_id == GKYL_GEOMETRY_FROMFILE) { + gkyl_gk_geometry_tok_set_grid_extents( + bgi->geometry.efit_info, bgi->geometry.tok_grid_info, &app_inp.lower[cdim - 1], + &app_inp.upper[cdim - 1] + ); gkyl_gk_block_geom_reset_block_extents(mbapp->gk_block_geom, bid, app_inp.lower, app_inp.upper); } app_inp.geometry = bgi->geometry; int num_species = app_inp.num_species = mbinp->num_species; - int num_neut_species = app_inp.num_neut_species = mbinp->num_neut_species; + int num_neut_species = app_inp.num_neut_species = mbinp->num_neut_species; app_inp.poly_order = mbinp->poly_order; app_inp.basis_type = mbinp->basis_type; - app_inp.cfl_frac = mbinp->cfl_frac; - app_inp.cfl_frac_omegaH = mbinp->cfl_frac_omegaH; + app_inp.cfl_frac = mbinp->cfl_frac; + app_inp.cfl_frac_omegaH = mbinp->cfl_frac_omegaH; struct gkyl_comm *comm = mbapp->block_comms[bid]; struct gkyl_app_parallelism_inp parallel_inp = {}; parallel_inp.use_gpu = mbinp->use_gpu; - for (int d=0; dcuts[d]; + for (int d = 0; d < cdim; ++d) { + parallel_inp.cuts[d] = bgi->cuts[d]; + } parallel_inp.comm = comm; // Copy parallelism input into app input. memcpy(&app_inp.parallelism, ¶llel_inp, sizeof(struct gkyl_app_parallelism_inp)); app_inp.num_periodic_dir = mbinp->num_periodic_dir; - for(int i = 0; i < mbinp->cdim; i++) + for (int i = 0; i < mbinp->cdim; i++) { app_inp.periodic_dirs[i] = mbinp->periodic_dirs[i]; + } app_inp.metadata.num_attributes = mbapp->io_meta_basic_len; app_inp.metadata.attributes = mbapp->io_meta_basic; @@ -109,9 +118,10 @@ singleb_app_new_geom(const struct gkyl_gyrokinetic_multib *mbinp, int bid, } // Construct single-block App solver for given block ID. -static void -singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, - const struct gkyl_gyrokinetic_multib_app *mbapp, struct gkyl_gyrokinetic_app *app) +static void singleb_app_new_solver( + const struct gkyl_gyrokinetic_multib *mbinp, int bid, + const struct gkyl_gyrokinetic_multib_app *mbapp, struct gkyl_gyrokinetic_app *app +) { // For kinetic simulations, block dimension defined configuration-space dimensionality. int cdim = gkyl_gk_block_geom_ndim(mbapp->gk_block_geom); @@ -121,29 +131,29 @@ singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, bid); // Construct top-level single-block input struct. - struct gkyl_gk app_inp = { }; + struct gkyl_gk app_inp = {}; // Set the configuration-space extents, cells. app_inp.cdim = cdim; - for (int i=0; ilower[i]; app_inp.upper[i] = bgi->upper[i]; app_inp.cells[i] = bgi->cells[i]; } int num_species = app_inp.num_species = mbinp->num_species; - int num_neut_species = app_inp.num_neut_species = mbinp->num_neut_species; + int num_neut_species = app_inp.num_neut_species = mbinp->num_neut_species; app_inp.poly_order = mbinp->poly_order; app_inp.basis_type = mbinp->basis_type; - app_inp.cfl_frac = mbinp->cfl_frac; - app_inp.cfl_frac_omegaH = mbinp->cfl_frac_omegaH; + app_inp.cfl_frac = mbinp->cfl_frac; + app_inp.cfl_frac_omegaH = mbinp->cfl_frac_omegaH; app_inp.eirene = mbinp->eirene; - for (int i=0; ispecies[i]; - - struct gkyl_gyrokinetic_species species_inp = { }; + + struct gkyl_gyrokinetic_species species_inp = {}; strcpy(species_inp.name, sp->name); species_inp.charge = sp->charge; @@ -151,10 +161,10 @@ singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, // Velocity-space information int vdim = species_inp.vdim = sp->vdim; - for (int v=0; vlower[v]; species_inp.upper[v] = sp->upper[v]; - species_inp.cells[v] = sp->cells[v]; + species_inp.cells[v] = sp->cells[v]; } species_inp.mapc2p = sp->mapc2p; @@ -164,15 +174,15 @@ singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, species_inp.anomalous_diffusion = sp->anomalous_diffusion; species_inp.radiation = sp->radiation; species_inp.react = sp->react; - species_inp.react_neut = sp->react_neut; + species_inp.react_neut = sp->react_neut; // Species diagnostics species_inp.num_diag_moments = sp->num_diag_moments; - for (int n=0; ndiag_moments[n]; } species_inp.num_integrated_diag_moments = sp->num_integrated_diag_moments; - for (int n=0; nintegrated_diag_moments[n]; } species_inp.time_rate_diagnostics = sp->time_rate_diagnostics; @@ -181,7 +191,7 @@ singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, // Choose proper block-specific species input. const struct gkyl_gyrokinetic_multib_species_pb *sp_pb = &sp->blocks[0]; if (!sp->duplicate_across_blocks) { - for (int i=0; iblocks[i].block_id) { sp_pb = &sp->blocks[i]; break; @@ -190,25 +200,26 @@ singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, } species_inp.projection = sp_pb->projection; species_inp.source = sp_pb->source; - species_inp.polarization_density = sp_pb->polarization_density; + species_inp.polarization_density = sp_pb->polarization_density; // By default, skip BCs altogether. - for (int i=0; i<2*GKYL_MAX_CDIM; i++) { + for (int i = 0; i < 2 * GKYL_MAX_CDIM; i++) { species_inp.bcs[i].type = GKYL_BC_GK_SKIP; species_inp.bcs[i].type = GKYL_BC_GK_SKIP; } - int pardir = cdim-1; - int num_below = gkyl_multib_conn_get_num_connected(mbapp->block_topo, - bid, pardir, 0, GKYL_CONN_BELOW); - int num_above = gkyl_multib_conn_get_num_connected(mbapp->block_topo, - bid, pardir, 0, GKYL_CONN_ABOVE); + int pardir = cdim - 1; + int num_below = + gkyl_multib_conn_get_num_connected(mbapp->block_topo, bid, pardir, 0, GKYL_CONN_BELOW); + int num_above = + gkyl_multib_conn_get_num_connected(mbapp->block_topo, bid, pardir, 0, GKYL_CONN_ABOVE); int bc_count_sp[num_blocks]; - for (int i=0; i 0) { species_inp.bcs[bc_count_sp[bid]].dir = pardir; species_inp.bcs[bc_count_sp[bid]].edge = GKYL_LOWER_EDGE; @@ -225,7 +236,7 @@ singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, } // Set species physical BCs. - for (int i=0; inum_physical_bcs; ++i) { + for (int i = 0; i < sp->num_physical_bcs; ++i) { if (bid == sp->bcs[i].bidx) { species_inp.bcs[bc_count_sp[bid]].dir = sp->bcs[i].dir; species_inp.bcs[bc_count_sp[bid]].edge = sp->bcs[i].edge; @@ -233,8 +244,9 @@ singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, species_inp.bcs[bc_count_sp[bid]].aux_profile = sp->bcs[i].aux_profile; species_inp.bcs[bc_count_sp[bid]].aux_ctx = sp->bcs[i].aux_ctx; species_inp.bcs[bc_count_sp[bid]].projection = sp->bcs[i].projection; - for (int k=0; k<3; ++k) + for (int k = 0; k < 3; ++k) { species_inp.bcs[bc_count_sp[bid]].value[k] = sp->bcs[i].value[k]; + } bc_count_sp[bid] += 1; } @@ -244,18 +256,18 @@ singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, memcpy(&app_inp.species[i], &species_inp, sizeof(struct gkyl_gyrokinetic_species)); } - for (int i=0; ineut_species[i]; - - struct gkyl_gyrokinetic_neut_species neut_species_inp = { }; + + struct gkyl_gyrokinetic_neut_species neut_species_inp = {}; strcpy(neut_species_inp.name, nsp->name); - neut_species_inp.mass = nsp->mass; - neut_species_inp.is_static = nsp->is_static; + neut_species_inp.mass = nsp->mass; + neut_species_inp.is_static = nsp->is_static; // Velocity space information (neutrals are 3V) int vdim = neut_species_inp.vdim = nsp->vdim; - for (int v=0; vlower[v]; neut_species_inp.upper[v] = nsp->upper[v]; neut_species_inp.cells[v] = nsp->cells[v]; @@ -267,14 +279,14 @@ singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, // Neutral species diagnostics neut_species_inp.num_diag_moments = nsp->num_diag_moments; - for (int n=0; ndiag_moments[n]; } // choose proper block-specific species input const struct gkyl_gyrokinetic_multib_neut_species_pb *nsp_pb = &nsp->blocks[0]; if (!nsp->duplicate_across_blocks) { - for (int i=0; iblocks[i].block_id) { nsp_pb = &nsp->blocks[i]; break; @@ -285,17 +297,18 @@ singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, neut_species_inp.source = nsp_pb->source; // By default, skip BCs altogether. - for (int i=0; i<2*GKYL_MAX_CDIM; i++) { + for (int i = 0; i < 2 * GKYL_MAX_CDIM; i++) { neut_species_inp.bcs[i].type = GKYL_BC_GK_SKIP; neut_species_inp.bcs[i].type = GKYL_BC_GK_SKIP; } // Set species physical BCs. int bc_count_nsp[num_blocks]; - for (int i=0; inum_physical_bcs; ++i) { + for (int i = 0; i < nsp->num_physical_bcs; ++i) { if (bid == nsp->bcs[i].bidx) { neut_species_inp.bcs[bc_count_nsp[bid]].dir = nsp->bcs[i].dir; neut_species_inp.bcs[bc_count_nsp[bid]].edge = nsp->bcs[i].edge; @@ -303,94 +316,101 @@ singleb_app_new_solver(const struct gkyl_gyrokinetic_multib *mbinp, int bid, neut_species_inp.bcs[bc_count_nsp[bid]].aux_profile = nsp->bcs[i].aux_profile; neut_species_inp.bcs[bc_count_nsp[bid]].aux_ctx = nsp->bcs[i].aux_ctx; neut_species_inp.bcs[bc_count_nsp[bid]].projection = nsp->bcs[i].projection; - for (int k=0; k<3; ++k) + for (int k = 0; k < 3; ++k) { neut_species_inp.bcs[bc_count_nsp[bid]].value[k] = nsp->bcs[i].value[k]; + } bc_count_nsp[bid] += 1; } } // Copy neutral species input into app input. - memcpy(&app_inp.neut_species[i], &neut_species_inp, sizeof(struct gkyl_gyrokinetic_neut_species)); - } + memcpy( + &app_inp.neut_species[i], &neut_species_inp, sizeof(struct gkyl_gyrokinetic_neut_species) + ); + } // Initialize the single-block field solver (only used for num_blocks=1). const struct gkyl_gyrokinetic_multib_field *fld = &mbinp->field; - struct gkyl_gyrokinetic_field field_inp = { }; + struct gkyl_gyrokinetic_field field_inp = {}; field_inp.gkfield_id = fld->gkfield_id; - field_inp.kperpSq = fld->kperpSq; - field_inp.time_rate_diagnostics = fld->time_rate_diagnostics; - + field_inp.kperpSq = fld->kperpSq; + field_inp.time_rate_diagnostics = fld->time_rate_diagnostics; + // Adiabatic electron inputs. field_inp.electron_mass = fld->electron_mass; field_inp.electron_charge = fld->electron_charge; - field_inp.electron_density = fld->electron_density; - field_inp.electron_temp = fld->electron_temp; - + field_inp.electron_density = fld->electron_density; + field_inp.electron_temp = fld->electron_temp; + // BCs. - for (int d=0; dnum_physical_bcs; i++) { + + for (int i = 0; i < fld->num_physical_bcs; i++) { if (bid == fld->bcs[i].bidx) { - struct gkyl_gyrokinetic_bc *bc_curr = gk_fetch_bc_with_dir_edge(field_inp.poisson_bcs, 2*cdim, fld->bcs[i].dir, fld->bcs[i].edge); + struct gkyl_gyrokinetic_bc *bc_curr = gk_fetch_bc_with_dir_edge( + field_inp.poisson_bcs, 2 * cdim, fld->bcs[i].dir, fld->bcs[i].edge + ); bc_curr->type = fld->bcs[i].type; bc_curr->aux_profile = fld->bcs[i].aux_profile; bc_curr->aux_ctx = fld->bcs[i].aux_ctx; - for (int k=0; k<3; ++k) + for (int k = 0; k < 3; ++k) { bc_curr->value[k] = fld->bcs[i].value[k]; + } } } - + const struct gkyl_gyrokinetic_multib_field_pb *fld_pb = &fld->blocks[0]; // Choose proper block-specific field input. if (!fld->duplicate_across_blocks) { - for (int i=0; iblocks[i].block_id) { const struct gkyl_gyrokinetic_multib_field_pb *fld_pb = &fld->blocks[i]; break; } } } - + if (!fld->duplicate_across_blocks) { - for (int i=0; iblocks[i].block_id) { fld_pb = &fld->blocks[i]; break; } } } - - field_inp.polarization_bmag = fld_pb->polarization_bmag ? fld_pb->polarization_bmag : mbapp->bmag_ref; + + field_inp.polarization_bmag = fld_pb->polarization_bmag ? fld_pb->polarization_bmag : + mbapp->bmag_ref; field_inp.kperpSq = fld_pb->kperpSq; - field_inp.time_rate_diagnostics = fld_pb->time_rate_diagnostics; - - field_inp.phi_wall_lo_ctx = fld_pb->phi_wall_lo_ctx; - field_inp.phi_wall_lo = fld_pb->phi_wall_lo; - field_inp.phi_wall_lo_evolve = fld_pb->phi_wall_lo_evolve; - - field_inp.phi_wall_up_ctx = fld_pb->phi_wall_up_ctx; - field_inp.phi_wall_up = fld_pb->phi_wall_up; - field_inp.phi_wall_up_evolve = fld_pb->phi_wall_up_evolve; - + field_inp.time_rate_diagnostics = fld_pb->time_rate_diagnostics; + + field_inp.phi_wall_lo_ctx = fld_pb->phi_wall_lo_ctx; + field_inp.phi_wall_lo = fld_pb->phi_wall_lo; + field_inp.phi_wall_lo_evolve = fld_pb->phi_wall_lo_evolve; + + field_inp.phi_wall_up_ctx = fld_pb->phi_wall_up_ctx; + field_inp.phi_wall_up = fld_pb->phi_wall_up; + field_inp.phi_wall_up_evolve = fld_pb->phi_wall_up_evolve; // Copy field input into app input. - memcpy(&app_inp.field, &field_inp, sizeof(struct gkyl_gyrokinetic_field)); + memcpy(&app_inp.field, &field_inp, sizeof(struct gkyl_gyrokinetic_field)); gkyl_gyrokinetic_app_new_solver(&app_inp, app); } -gkyl_gyrokinetic_multib_app* +gkyl_gyrokinetic_multib_app * gkyl_gyrokinetic_multib_app_new_geom(const struct gkyl_gyrokinetic_multib *mbinp) { int my_rank, num_ranks; @@ -400,27 +420,31 @@ gkyl_gyrokinetic_multib_app_new_geom(const struct gkyl_gyrokinetic_multib *mbinp int tot_max[2]; calc_tot_and_max_cuts(mbinp->gk_block_geom, tot_max); if ((num_ranks > tot_max[0]) || (num_ranks < tot_max[1])) { - fprintf(stderr, "\nSpecified %d total cuts but provided %d processes, \ -and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot_max[1]); + fprintf( + stderr, "\nSpecified %d total cuts but provided %d processes, \ +and the maximum number of cuts in a block is %d\n\n", + tot_max[0], num_ranks, tot_max[1] + ); return 0; } struct gkyl_gyrokinetic_multib_app *mbapp = gkyl_malloc(sizeof(*mbapp)); strcpy(mbapp->name, mbinp->name); - mbapp->comm = gkyl_comm_acquire(mbinp->comm); + mbapp->comm = gkyl_comm_acquire(mbinp->comm); mbapp->use_gpu = mbinp->use_gpu; - + mbapp->gk_block_geom = gkyl_gk_block_geom_acquire(mbinp->gk_block_geom); mbapp->block_topo = gkyl_gk_block_geom_topo(mbinp->gk_block_geom); - + int cdim = gkyl_gk_block_geom_ndim(mbapp->gk_block_geom); int num_blocks = gkyl_gk_block_geom_num_blocks(mbapp->gk_block_geom); // Construct round-robin decomposition. int *branks = gkyl_malloc(sizeof(int[num_blocks])); - for (int i=0; igk_block_geom, i); + for (int i = 0; i < num_blocks; ++i) { + const struct gkyl_gk_block_geom_info *bgi = + gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, i); branks[i] = calc_cuts(cdim, bgi->cuts); } mbapp->round_robin = gkyl_rrobin_decomp_new(num_ranks, num_blocks, branks); @@ -431,40 +455,42 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot int lidx = 0; int *rank_list = gkyl_malloc(sizeof(int[num_ranks])); // This is larger than needed. - mbapp->decomp = gkyl_malloc(num_blocks*sizeof(struct gkyl_rect_decomp*)); - + mbapp->decomp = gkyl_malloc(num_blocks * sizeof(struct gkyl_rect_decomp *)); + // Construct list of block communicators: there are as many // communicators as blocks. Not all communicators are valid on each // rank. The total number of valid communicators is // num_local_blocks. - mbapp->block_comms = gkyl_malloc(num_blocks*sizeof(struct gkyl_comm *)); - for (int i=0; iblock_comms = gkyl_malloc(num_blocks * sizeof(struct gkyl_comm *)); + for (int i = 0; i < num_blocks; ++i) { gkyl_rrobin_decomp_getranks(mbapp->round_robin, i, rank_list); bool is_my_rank_in_decomp = has_int(branks[i], my_rank, rank_list); if (is_my_rank_in_decomp) { mbapp->local_blocks[lidx++] = i; - num_local_blocks += 1; + num_local_blocks += 1; } - const struct gkyl_gk_block_geom_info *bgi = gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, i); + const struct gkyl_gk_block_geom_info *bgi = + gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, i); struct gkyl_range block_global_range; gkyl_create_global_range(cdim, bgi->cells, &block_global_range); - mbapp->decomp[i] = gkyl_rect_decomp_new_from_cuts( - cdim, bgi->cuts, &block_global_range); + mbapp->decomp[i] = gkyl_rect_decomp_new_from_cuts(cdim, bgi->cuts, &block_global_range); bool status; - mbapp->block_comms[i] = gkyl_comm_create_comm_from_ranks(mbinp->comm, - branks[i], rank_list, mbapp->decomp[i], &status); + mbapp->block_comms[i] = gkyl_comm_create_comm_from_ranks( + mbinp->comm, branks[i], rank_list, mbapp->decomp[i], &status + ); } - mbapp->num_local_blocks = num_local_blocks; + mbapp->num_local_blocks = num_local_blocks; printf("Rank %d handles %d Apps\n", my_rank, num_local_blocks); - for (int i=0; ilocal_blocks[i]); + } mbapp->num_species = 0; mbapp->num_neut_species = 0; @@ -474,30 +500,33 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot if (num_local_blocks > 0) { mbapp->num_species = mbinp->num_species; mbapp->num_neut_species = mbinp->num_neut_species; - mbapp->update_field = !mbinp->skip_field; // Note inversion of truth value (default: update field). - + mbapp->update_field = + !mbinp->skip_field; // Note inversion of truth value (default: update field). - mbapp->singleb_apps = gkyl_malloc(num_local_blocks*sizeof(struct gkyl_gyrokinetic_app*)); + mbapp->singleb_apps = gkyl_malloc(num_local_blocks * sizeof(struct gkyl_gyrokinetic_app *)); } - for (int i=0; inum_species; ++i) + for (int i = 0; i < mbinp->num_species; ++i) { strcpy(mbapp->species_name[i], mbinp->species[i].name); + } - for (int i=0; inum_neut_species; ++i) - strcpy(mbapp->neut_species_name[i], mbinp->neut_species[i].name); + for (int i = 0; i < mbinp->num_neut_species; ++i) { + strcpy(mbapp->neut_species_name[i], mbinp->neut_species[i].name); + } // Write the block topo file. gkyl_gyrokinetic_multib_app_write_topo(mbapp); // Create single-block grids and geometries. - for (int i=0; isingleb_apps[i] = singleb_app_new_geom(mbinp, mbapp->local_blocks[i], mbapp); - + } return mbapp; } -gkyl_gyrokinetic_multib_app* gkyl_gyrokinetic_multib_app_new(const struct gkyl_gyrokinetic_multib *mbinp) +gkyl_gyrokinetic_multib_app * +gkyl_gyrokinetic_multib_app_new(const struct gkyl_gyrokinetic_multib *mbinp) { int my_rank, num_ranks; gkyl_comm_get_rank(mbinp->comm, &my_rank); @@ -506,27 +535,31 @@ gkyl_gyrokinetic_multib_app* gkyl_gyrokinetic_multib_app_new(const struct gkyl_g int tot_max[2]; calc_tot_and_max_cuts(mbinp->gk_block_geom, tot_max); if ((num_ranks > tot_max[0]) || (num_ranks < tot_max[1])) { - fprintf(stderr, "\nSpecified %d total cuts but provided %d processes, \ -and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot_max[1]); + fprintf( + stderr, "\nSpecified %d total cuts but provided %d processes, \ +and the maximum number of cuts in a block is %d\n\n", + tot_max[0], num_ranks, tot_max[1] + ); return 0; } struct gkyl_gyrokinetic_multib_app *mbapp = gkyl_malloc(sizeof(*mbapp)); strcpy(mbapp->name, mbinp->name); - mbapp->comm = gkyl_comm_acquire(mbinp->comm); + mbapp->comm = gkyl_comm_acquire(mbinp->comm); mbapp->use_gpu = mbinp->use_gpu; - + mbapp->gk_block_geom = gkyl_gk_block_geom_acquire(mbinp->gk_block_geom); mbapp->block_topo = gkyl_gk_block_geom_topo(mbinp->gk_block_geom); - + int cdim = gkyl_gk_block_geom_ndim(mbapp->gk_block_geom); int num_blocks = gkyl_gk_block_geom_num_blocks(mbapp->gk_block_geom); // Construct round-robin decomposition. int *branks = gkyl_malloc(sizeof(int[num_blocks])); - for (int i=0; igk_block_geom, i); + for (int i = 0; i < num_blocks; ++i) { + const struct gkyl_gk_block_geom_info *bgi = + gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, i); branks[i] = calc_cuts(cdim, bgi->cuts); } mbapp->round_robin = gkyl_rrobin_decomp_new(num_ranks, num_blocks, branks); @@ -537,64 +570,72 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot int lidx = 0; int *rank_list = gkyl_malloc(sizeof(int[num_ranks])); // This is larger than needed. - mbapp->decomp = gkyl_malloc(num_blocks*sizeof(struct gkyl_rect_decomp*)); - + mbapp->decomp = gkyl_malloc(num_blocks * sizeof(struct gkyl_rect_decomp *)); + // Construct list of block communicators: there are as many // communicators as blocks. Not all communicators are valid on each // rank. The total number of valid communicators is // num_local_blocks. - mbapp->block_comms = gkyl_malloc(num_blocks*sizeof(struct gkyl_comm *)); - for (int i=0; iblock_comms = gkyl_malloc(num_blocks * sizeof(struct gkyl_comm *)); + for (int i = 0; i < num_blocks; ++i) { gkyl_rrobin_decomp_getranks(mbapp->round_robin, i, rank_list); bool is_my_rank_in_decomp = has_int(branks[i], my_rank, rank_list); if (is_my_rank_in_decomp) { mbapp->local_blocks[lidx++] = i; - num_local_blocks += 1; + num_local_blocks += 1; } - const struct gkyl_gk_block_geom_info *bgi = gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, i); + const struct gkyl_gk_block_geom_info *bgi = + gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, i); struct gkyl_range block_global_range; gkyl_create_global_range(cdim, bgi->cells, &block_global_range); - mbapp->decomp[i] = gkyl_rect_decomp_new_from_cuts( - cdim, bgi->cuts, &block_global_range); + mbapp->decomp[i] = gkyl_rect_decomp_new_from_cuts(cdim, bgi->cuts, &block_global_range); bool status; - mbapp->block_comms[i] = gkyl_comm_create_comm_from_ranks(mbinp->comm, - branks[i], rank_list, mbapp->decomp[i], &status); + mbapp->block_comms[i] = gkyl_comm_create_comm_from_ranks( + mbinp->comm, branks[i], rank_list, mbapp->decomp[i], &status + ); } - mbapp->num_local_blocks = num_local_blocks; + mbapp->num_local_blocks = num_local_blocks; // Create multiblock metadata to pass to each block, and combine with user's metadata. const char *fmt_btopo = "%s-block_topo.gkyl"; int sz = gkyl_calc_strlen(fmt_btopo, mbapp->name); - char fileNm_btopo[sz+1]; // ensures no buffer overflow + char fileNm_btopo[sz + 1]; // ensures no buffer overflow snprintf(fileNm_btopo, sizeof fileNm_btopo, fmt_btopo, mbapp->name); // Basic metadata for I/O (including metadata optional from user). - const char* build_id = GIT_COMMIT_ID; - const char* build_date = GKYL_BUILD_DATE; + const char *build_id = GIT_COMMIT_ID; + const char *build_date = GKYL_BUILD_DATE; struct gkyl_msgpack_map_elem io_meta_default[] = { - { .key = "changeset", .elem_type = GKYL_MP_STRING, .cval = (char *)build_id }, - { .key = "builddate", .elem_type = GKYL_MP_STRING, .cval = (char *)build_date }, - { .key = "is_multib", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 1 }, - { .key = "topo_file", .elem_type = GKYL_MP_STRING, .cval = fileNm_btopo }, + {.key = "changeset", .elem_type = GKYL_MP_STRING, .cval = (char *)build_id}, + {.key = "builddate", .elem_type = GKYL_MP_STRING, .cval = (char *)build_date}, + {.key = "is_multib", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = 1}, + {.key = "topo_file", .elem_type = GKYL_MP_STRING, .cval = fileNm_btopo} + }; + const struct gkyl_msgpack_map_elem *io_meta_union[] = { + io_meta_default, mbinp->metadata.attributes + }; + int io_meta_union_len[] = { + sizeof(io_meta_default) / sizeof(io_meta_default[0]), mbinp->metadata.num_attributes }; - const struct gkyl_msgpack_map_elem *io_meta_union[] = {io_meta_default, mbinp->metadata.attributes}; - int io_meta_union_len[] = {sizeof(io_meta_default)/sizeof(io_meta_default[0]), mbinp->metadata.num_attributes}; - mbapp->io_meta_basic = gkyl_msgpack_map_elem_union(sizeof(io_meta_union)/sizeof(io_meta_union[0]), - io_meta_union_len, io_meta_union, &mbapp->io_meta_basic_len); + mbapp->io_meta_basic = gkyl_msgpack_map_elem_union( + sizeof(io_meta_union) / sizeof(io_meta_union[0]), io_meta_union_len, io_meta_union, + &mbapp->io_meta_basic_len + ); // Write the block topo file. gkyl_gyrokinetic_multib_app_write_topo(mbapp); printf("Rank %d handles %d Apps\n", my_rank, num_local_blocks); - for (int i=0; ilocal_blocks[i]); + } mbapp->num_species = 0; mbapp->num_neut_species = 0; @@ -604,25 +645,29 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot if (num_local_blocks > 0) { mbapp->num_species = mbinp->num_species; mbapp->num_neut_species = mbinp->num_neut_species; - mbapp->update_field = !mbinp->skip_field; // Note inversion of truth value (default: update field). + mbapp->update_field = + !mbinp->skip_field; // Note inversion of truth value (default: update field). - mbapp->singleb_apps = gkyl_malloc(num_local_blocks*sizeof(struct gkyl_gyrokinetic_app*)); + mbapp->singleb_apps = gkyl_malloc(num_local_blocks * sizeof(struct gkyl_gyrokinetic_app *)); } - for (int i=0; inum_species; ++i) + for (int i = 0; i < mbinp->num_species; ++i) { strcpy(mbapp->species_name[i], mbinp->species[i].name); + } - for (int i=0; inum_neut_species; ++i) - strcpy(mbapp->neut_species_name[i], mbinp->neut_species[i].name); + for (int i = 0; i < mbinp->num_neut_species; ++i) { + strcpy(mbapp->neut_species_name[i], mbinp->neut_species[i].name); + } // Create single-block grids and geometries. - for (int i=0; isingleb_apps[i] = singleb_app_new_geom(mbinp, mbapp->local_blocks[i], mbapp); + } // Set bmag_ref. double bmag_min_local = DBL_MAX; double bmag_min_global; - for (int i=0; isingleb_apps[i]->gk_geom, GKYL_MIN); bmag_min_local = GKYL_MIN2(bmag_min_local, bmag_min); } @@ -630,37 +675,45 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot double bmag_max_local = -DBL_MAX; double bmag_max_global; - for (int i=0; isingleb_apps[i]->gk_geom, GKYL_MAX); bmag_max_local = GKYL_MAX2(bmag_max_local, bmag_max); } gkyl_comm_allreduce_host(mbapp->comm, GKYL_DOUBLE, GKYL_MAX, 1, &bmag_max_local, &bmag_max_global); - mbapp->bmag_ref = (bmag_max_global + bmag_min_global)/2.0; + mbapp->bmag_ref = (bmag_max_global + bmag_min_global) / 2.0; // Create connections needed for conf-space syncs. - int ghost[] = { 1, 1, 1 }; + int ghost[] = {1, 1, 1}; mbapp->mbcc_sync_conf = gkyl_malloc(sizeof(struct gkyl_mbcc_sr)); - mbapp->mbcc_sync_conf->send = gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - mbapp->mbcc_sync_conf->recv = gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + mbapp->mbcc_sync_conf->send = + gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + mbapp->mbcc_sync_conf->recv = + gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - for (int bI=0; bIlocal_blocks[bI]; gkyl_rrobin_decomp_getranks(mbapp->round_robin, bid, rank_list); int brank = -1; - for (int i=0; imbcc_sync_conf->recv[bI] = gkyl_multib_comm_conn_new_recv(bid, brank, - ghost, &mbapp->block_topo->conn[bid], mbapp->decomp); - mbapp->mbcc_sync_conf->send[bI] = gkyl_multib_comm_conn_new_send(bid, brank, - ghost, &mbapp->block_topo->conn[bid], mbapp->decomp); + mbapp->mbcc_sync_conf->recv[bI] = gkyl_multib_comm_conn_new_recv( + bid, brank, ghost, &mbapp->block_topo->conn[bid], mbapp->decomp + ); + mbapp->mbcc_sync_conf->send[bI] = gkyl_multib_comm_conn_new_send( + bid, brank, ghost, &mbapp->block_topo->conn[bid], mbapp->decomp + ); - struct gkyl_multib_comm_conn *mbcc_s = mbapp->mbcc_sync_conf->send[bI], *mbcc_r = mbapp->mbcc_sync_conf->recv[bI]; + struct gkyl_multib_comm_conn *mbcc_s = mbapp->mbcc_sync_conf->send[bI], + *mbcc_r = mbapp->mbcc_sync_conf->recv[bI]; struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[bI]; - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_s->num_comm_conn; ++ns) { // Translate the "rank" in gkyl_multib_comm_conn (right now it is a rank index). struct gkyl_comm_conn *ccs = &mbcc_s->comm_conn[ns]; int rankIdx = ccs->rank; @@ -669,7 +722,7 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot // Make range a sub range. gkyl_sub_range_init(&ccs->range, &sbapp->local_ext, ccs->range.lower, ccs->range.upper); } - for (int nr=0; nrnum_comm_conn; ++nr) { + for (int nr = 0; nr < mbcc_r->num_comm_conn; ++nr) { // Translate the "rank" in gkyl_multib_comm_conn (right now it is a rank index). struct gkyl_comm_conn *ccr = &mbcc_r->comm_conn[nr]; int rankIdx = ccr->rank; @@ -687,81 +740,110 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot // Sync the conf-space volume Jacobian needed for syncing quantities that include a // jacobgeo factor in them. struct gkyl_array *jacs_vol[mbapp->num_local_blocks]; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < mbapp->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[b]; jacs_vol[b] = sbapp->gk_geom->geo_int.jacobgeo_ghost; } // Sync across blocks. - gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, - mbapp->mbcc_sync_conf->send, mbapp->mbcc_sync_conf->recv, jacs_vol, jacs_vol); + gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, mbapp->mbcc_sync_conf->send, + mbapp->mbcc_sync_conf->recv, jacs_vol, jacs_vol + ); - // Sync the surface conf-space Jacobian, compute its reciprocal, and + // Sync the surface conf-space Jacobian, compute its reciprocal, and // store its product with the Jacobian of this block (in the ghost cell). - for (int d = 0; dnum_local_blocks]; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < mbapp->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[b]; struct gk_geom_surf geo_surf = sbapp->gk_geom->geo_surf[d]; jacs[b] = geo_surf.jacobgeo_ratio; gkyl_array_copy_range(jacs[b], geo_surf.jacobgeo, &sbapp->local_lower_skin[d]); - gkyl_array_copy_range_to_range(jacs[b], geo_surf.jacobgeo, &sbapp->local_upper_skin[d], &sbapp->local_upper_ghost[d]); + gkyl_array_copy_range_to_range( + jacs[b], geo_surf.jacobgeo, &sbapp->local_upper_skin[d], &sbapp->local_upper_ghost[d] + ); } - gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, - mbapp->mbcc_sync_conf->send, mbapp->mbcc_sync_conf->recv, jacs, jacs); + gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, mbapp->mbcc_sync_conf->send, + mbapp->mbcc_sync_conf->recv, jacs, jacs + ); - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < mbapp->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[b]; struct gk_geom_surf geo_surf = sbapp->gk_geom->geo_surf[d]; - struct gkyl_array *jacgeo = mkarr(mbapp->use_gpu, geo_surf.jacobgeo_ratio->ncomp, geo_surf.jacobgeo_ratio->size); + struct gkyl_array *jacgeo = + mkarr(mbapp->use_gpu, geo_surf.jacobgeo_ratio->ncomp, geo_surf.jacobgeo_ratio->size); // Compute 1/jacobgeo in ghost cells. gkyl_array_set_range(jacgeo, 1.0, geo_surf.jacobgeo_ratio, &sbapp->local_lower_ghost[d]); gkyl_array_set_range(jacgeo, 1.0, geo_surf.jacobgeo_ratio, &sbapp->local_upper_ghost[d]); - gkyl_dg_inv_op_range(&sbapp->gk_geom->surf_basis, 0, geo_surf.jacobgeo_ratio, 0, jacgeo, &sbapp->local_lower_ghost[d]); - gkyl_dg_inv_op_range(&sbapp->gk_geom->surf_basis, 0, geo_surf.jacobgeo_ratio, 0, jacgeo, &sbapp->local_upper_ghost[d]); + gkyl_dg_inv_op_range( + &sbapp->gk_geom->surf_basis, 0, geo_surf.jacobgeo_ratio, 0, jacgeo, + &sbapp->local_lower_ghost[d] + ); + gkyl_dg_inv_op_range( + &sbapp->gk_geom->surf_basis, 0, geo_surf.jacobgeo_ratio, 0, jacgeo, + &sbapp->local_upper_ghost[d] + ); // Multiply by the Jacobian of this block. - gkyl_array_copy_range_to_range(jacgeo, geo_surf.jacobgeo, &sbapp->local_lower_ghost[d], &sbapp->local_lower_skin[d]); + gkyl_array_copy_range_to_range( + jacgeo, geo_surf.jacobgeo, &sbapp->local_lower_ghost[d], &sbapp->local_lower_skin[d] + ); gkyl_array_copy_range(jacgeo, geo_surf.jacobgeo, &sbapp->local_upper_ghost[d]); - gkyl_dg_mul_op_range(&sbapp->gk_geom->surf_basis, 0, geo_surf.jacobgeo_ratio, - 0, jacgeo, 0, geo_surf.jacobgeo_ratio, &sbapp->local_lower_ghost[d]); - gkyl_dg_mul_op_range(&sbapp->gk_geom->surf_basis, 0, geo_surf.jacobgeo_ratio, - 0, jacgeo, 0, geo_surf.jacobgeo_ratio, &sbapp->local_upper_ghost[d]); + gkyl_dg_mul_op_range( + &sbapp->gk_geom->surf_basis, 0, geo_surf.jacobgeo_ratio, 0, jacgeo, 0, + geo_surf.jacobgeo_ratio, &sbapp->local_lower_ghost[d] + ); + gkyl_dg_mul_op_range( + &sbapp->gk_geom->surf_basis, 0, geo_surf.jacobgeo_ratio, 0, jacgeo, 0, + geo_surf.jacobgeo_ratio, &sbapp->local_upper_ghost[d] + ); // Set the ratio to 1 in the interior (shouldn't be in use). gkyl_array_clear_range(geo_surf.jacobgeo_ratio, 0.0, &sbapp->local); - gkyl_array_shiftc_range(geo_surf.jacobgeo_ratio, pow(sqrt(2.0),sbapp->cdim), 0, &sbapp->local); + gkyl_array_shiftc_range( + geo_surf.jacobgeo_ratio, pow(sqrt(2.0), sbapp->cdim), 0, &sbapp->local + ); gkyl_array_release(jacgeo); } - } - const struct gkyl_gk_block_geom_info *bgi0 = gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, 0); + const struct gkyl_gk_block_geom_info *bgi0 = + gkyl_gk_block_geom_get_block(mbapp->gk_block_geom, 0); if (cdim > 1 && bgi0->geometry.geometry_id == GKYL_GEOMETRY_TOKAMAK) { // Sync the surface deltats. Need to copy the upper ghost into the upper skin before syncing. - for (int d = 0; dnum_local_blocks]; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < mbapp->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[b]; struct gk_geom_surf geo_surf = sbapp->gk_geom->geo_surf[d]; deltats[b] = geo_surf.deltats; - gkyl_array_copy_range_to_range(deltats[b], deltats[b], &sbapp->local_upper_skin[d], &sbapp->local_upper_ghost[d]); + gkyl_array_copy_range_to_range( + deltats[b], deltats[b], &sbapp->local_upper_skin[d], &sbapp->local_upper_ghost[d] + ); } - gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, - mbapp->mbcc_sync_conf->send, mbapp->mbcc_sync_conf->recv, deltats, deltats); + gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, mbapp->mbcc_sync_conf->send, + mbapp->mbcc_sync_conf->recv, deltats, deltats + ); } // Accumulate the appropriate shift - for (int b=0; bnum_local_blocks; ++b) { - int par_dir = cdim-1; + for (int b = 0; b < mbapp->num_local_blocks; ++b) { + int par_dir = cdim - 1; struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[b]; struct gkyl_array *delta_ts = sbapp->gk_geom->geo_surf[par_dir].deltats; struct gkyl_array *buffer = mkarr(sbapp->use_gpu, delta_ts->ncomp, delta_ts->size); - gkyl_array_copy_range_to_range(buffer, delta_ts, &sbapp->local_upper_skin[par_dir], &sbapp->local_upper_ghost[par_dir]); + gkyl_array_copy_range_to_range( + buffer, delta_ts, &sbapp->local_upper_skin[par_dir], &sbapp->local_upper_ghost[par_dir] + ); gkyl_array_accumulate_range(delta_ts, -1.0, buffer, &sbapp->local_upper_skin[par_dir]); - gkyl_array_copy_range_to_range(buffer, delta_ts, &sbapp->local_lower_skin[par_dir], &sbapp->local_lower_ghost[par_dir]); + gkyl_array_copy_range_to_range( + buffer, delta_ts, &sbapp->local_lower_skin[par_dir], &sbapp->local_lower_ghost[par_dir] + ); gkyl_array_accumulate_range(delta_ts, -1.0, buffer, &sbapp->local_lower_skin[par_dir]); gkyl_array_release(buffer); @@ -774,39 +856,43 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot } } - // Create the rest of the single-block solvers. - for (int i=0; ilocal_blocks[i], mbapp, mbapp->singleb_apps[i]); + } // Create the MB field app. mbapp->field = gk_multib_field_new(mbinp, mbapp); - // Create connections needed for syncing charged species phase-space quantities. mbapp->mbcc_sync_charged = gkyl_malloc(mbapp->num_species * sizeof(struct gkyl_mbcc_sr)); - for (int i=0; inum_species; ++i) { - mbapp->mbcc_sync_charged[i].send = gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - mbapp->mbcc_sync_charged[i].recv = gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + for (int i = 0; i < mbinp->num_species; ++i) { + mbapp->mbcc_sync_charged[i].send = + gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + mbapp->mbcc_sync_charged[i].recv = + gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); } - for (int bI=0; bIsingleb_apps[bI]; - struct gkyl_multib_comm_conn *mbcc_cs = mbapp->mbcc_sync_conf->send[bI], *mbcc_cr = mbapp->mbcc_sync_conf->recv[bI]; - for (int i=0; inum_species; ++i) { - mbapp->mbcc_sync_charged[i].send[bI] = gkyl_multib_comm_conn_new(mbcc_cs->num_comm_conn, mbcc_cs->comm_conn); - mbapp->mbcc_sync_charged[i].recv[bI] = gkyl_multib_comm_conn_new(mbcc_cr->num_comm_conn, mbcc_cr->comm_conn); + struct gkyl_multib_comm_conn *mbcc_cs = mbapp->mbcc_sync_conf->send[bI], + *mbcc_cr = mbapp->mbcc_sync_conf->recv[bI]; + for (int i = 0; i < mbinp->num_species; ++i) { + mbapp->mbcc_sync_charged[i].send[bI] = + gkyl_multib_comm_conn_new(mbcc_cs->num_comm_conn, mbcc_cs->comm_conn); + mbapp->mbcc_sync_charged[i].recv[bI] = + gkyl_multib_comm_conn_new(mbcc_cr->num_comm_conn, mbcc_cr->comm_conn); struct gkyl_multib_comm_conn *mbcc_ps = mbapp->mbcc_sync_charged[i].send[bI], *mbcc_pr = mbapp->mbcc_sync_charged[i].recv[bI]; // Extend ranges to include velocity space, and make them a sub range. struct gk_species *gks = &sbapp->species[i]; - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_cs->num_comm_conn; ++ns) { struct gkyl_comm_conn *ccs_conf = &mbcc_cs->comm_conn[ns]; struct gkyl_comm_conn *ccs_phase = &mbcc_ps->comm_conn[ns]; struct gkyl_range phase_r; gkyl_range_ten_prod(&phase_r, &ccs_conf->range, &gks->local_vel); gkyl_sub_range_init(&ccs_phase->range, &gks->local_ext, phase_r.lower, phase_r.upper); } - for (int nr=0; nrnum_comm_conn; ++nr) { + for (int nr = 0; nr < mbcc_cr->num_comm_conn; ++nr) { struct gkyl_comm_conn *ccs_conf = &mbcc_cr->comm_conn[nr]; struct gkyl_comm_conn *ccs_phase = &mbcc_pr->comm_conn[nr]; struct gkyl_range phase_r; @@ -818,28 +904,33 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot // Create connections needed for syncing neutral species phase-space quantities. mbapp->mbcc_sync_neut = gkyl_malloc(mbapp->num_neut_species * sizeof(struct gkyl_mbcc_sr)); - for (int i=0; inum_neut_species; ++i) { - mbapp->mbcc_sync_neut[i].send = gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - mbapp->mbcc_sync_neut[i].recv = gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + for (int i = 0; i < mbinp->num_neut_species; ++i) { + mbapp->mbcc_sync_neut[i].send = + gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + mbapp->mbcc_sync_neut[i].recv = + gkyl_malloc(mbapp->num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); } - for (int bI=0; bIsingleb_apps[bI]; - struct gkyl_multib_comm_conn *mbcc_cs = mbapp->mbcc_sync_conf->send[bI], *mbcc_cr = mbapp->mbcc_sync_conf->recv[bI]; - for (int i=0; inum_neut_species; ++i) { - mbapp->mbcc_sync_neut[i].send[bI] = gkyl_multib_comm_conn_new(mbcc_cs->num_comm_conn, mbcc_cs->comm_conn); - mbapp->mbcc_sync_neut[i].recv[bI] = gkyl_multib_comm_conn_new(mbcc_cr->num_comm_conn, mbcc_cr->comm_conn); + struct gkyl_multib_comm_conn *mbcc_cs = mbapp->mbcc_sync_conf->send[bI], + *mbcc_cr = mbapp->mbcc_sync_conf->recv[bI]; + for (int i = 0; i < mbinp->num_neut_species; ++i) { + mbapp->mbcc_sync_neut[i].send[bI] = + gkyl_multib_comm_conn_new(mbcc_cs->num_comm_conn, mbcc_cs->comm_conn); + mbapp->mbcc_sync_neut[i].recv[bI] = + gkyl_multib_comm_conn_new(mbcc_cr->num_comm_conn, mbcc_cr->comm_conn); struct gkyl_multib_comm_conn *mbcc_ps = mbapp->mbcc_sync_neut[i].send[bI], *mbcc_pr = mbapp->mbcc_sync_neut[i].recv[bI]; // Extend ranges to include velocity space, and make them a sub range. struct gk_neut_species *gkns = &sbapp->neut_species[i]; - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_cs->num_comm_conn; ++ns) { struct gkyl_comm_conn *ccs_conf = &mbcc_cs->comm_conn[ns]; struct gkyl_comm_conn *ccs_phase = &mbcc_ps->comm_conn[ns]; struct gkyl_range phase_r; gkyl_range_ten_prod(&phase_r, &ccs_conf->range, &gkns->local_vel); gkyl_sub_range_init(&ccs_phase->range, &gkns->local_ext, phase_r.lower, phase_r.upper); } - for (int nr=0; nrnum_comm_conn; ++nr) { + for (int nr = 0; nr < mbcc_cr->num_comm_conn; ++nr) { struct gkyl_comm_conn *ccs_conf = &mbcc_cr->comm_conn[nr]; struct gkyl_comm_conn *ccs_phase = &mbcc_pr->comm_conn[nr]; struct gkyl_range phase_r; @@ -852,9 +943,9 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot // Sync the effective diffusivity of the anomalous diffusion operator. // Assume they either all have anomalous diffusion or none of them do. bool any_anomalous_diff = false; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < mbapp->num_species; ++i) { bool has_anomalous_diff = true; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < mbapp->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[b]; has_anomalous_diff = has_anomalous_diff && sbapp->species[i].anom_diff.anom_diff_id; } @@ -862,43 +953,51 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot if (has_anomalous_diff) { any_anomalous_diff = true; // Divide diffD by dz before the transfer - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < mbapp->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[b]; - int d = 0; - gkyl_array_scale_range(sbapp->species[i].anom_diff.diffD, sbapp->grid.dx[sbapp->cdim-1], &sbapp->global); + int d = 0; + gkyl_array_scale_range( + sbapp->species[i].anom_diff.diffD, sbapp->grid.dx[sbapp->cdim - 1], &sbapp->global + ); } // Sync struct gkyl_array *gkad_nu[mbapp->num_local_blocks]; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < mbapp->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[b]; gkad_nu[b] = sbapp->species[i].anom_diff.diffD; } - gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, - mbapp->mbcc_sync_conf->send, mbapp->mbcc_sync_conf->recv, gkad_nu, gkad_nu); + gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, mbapp->mbcc_sync_conf->send, + mbapp->mbcc_sync_conf->recv, gkad_nu, gkad_nu + ); // Multiply by diffD dz after the transfer to achieve rescaling - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < mbapp->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[b]; - int d = 0; - gkyl_array_scale_range(sbapp->species[i].anom_diff.diffD, 1.0/sbapp->grid.dx[sbapp->cdim-1], &sbapp->global_ext); + int d = 0; + gkyl_array_scale_range( + sbapp->species[i].anom_diff.diffD, 1.0 / sbapp->grid.dx[sbapp->cdim - 1], + &sbapp->global_ext + ); } - } } if (any_anomalous_diff) { // Sync the interior conf-space reciprocal Jacobian. struct gkyl_array *jacs_inv_vol[mbapp->num_local_blocks]; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < mbapp->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = mbapp->singleb_apps[b]; jacs_inv_vol[b] = sbapp->gk_geom->geo_int.jacobgeo_inv; } - gkyl_multib_comm_conn_array_transfer(mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, - mbapp->mbcc_sync_conf->send, mbapp->mbcc_sync_conf->recv, jacs_inv_vol, jacs_inv_vol); + gkyl_multib_comm_conn_array_transfer( + mbapp->comm, mbapp->num_local_blocks, mbapp->local_blocks, mbapp->mbcc_sync_conf->send, + mbapp->mbcc_sync_conf->recv, jacs_inv_vol, jacs_inv_vol + ); } - mbapp->stat = (struct gkyl_gyrokinetic_stat) {}; + mbapp->stat = (struct gkyl_gyrokinetic_stat){}; mbapp->dts = gkyl_dynvec_new(GKYL_DOUBLE, 1); // Dynvector to store time steps. mbapp->is_first_dt_write_call = true; @@ -909,9 +1008,10 @@ and the maximum number of cuts in a block is %d\n\n", tot_max[0], num_ranks, tot return mbapp; } -void -gyrokinetic_multib_calc_field(struct gkyl_gyrokinetic_multib_app* app, double tcurr, - const struct gkyl_array *fin[], struct gkyl_array **bflux[]) +void gyrokinetic_multib_calc_field( + struct gkyl_gyrokinetic_multib_app *app, double tcurr, const struct gkyl_array *fin[], + struct gkyl_array **bflux[] +) { struct timespec wtm = gkyl_wall_clock(); // Compute fields. @@ -922,66 +1022,71 @@ gyrokinetic_multib_calc_field(struct gkyl_gyrokinetic_multib_app* app, double tc app->stat.field_tm += gkyl_time_diff_now_sec(wtm); } -static void -gyrokinetic_multib_apply_bc(struct gkyl_gyrokinetic_multib_app* app, double tcurr, - struct gkyl_array *distf[], struct gkyl_array *distf_neut[]) +static void gyrokinetic_multib_apply_bc( + struct gkyl_gyrokinetic_multib_app *app, double tcurr, struct gkyl_array *distf[], + struct gkyl_array *distf_neut[] +) { // Apply boundary conditions in each block (including intrablock sync). - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; int li_charged = b * app->num_species; int li_neut = b * app->num_neut_species; - for (int i=0; inum_species; ++i) { - gk_species_apply_bc(sbapp, &sbapp->species[i], distf[li_charged+i]); + for (int i = 0; i < app->num_species; ++i) { + gk_species_apply_bc(sbapp, &sbapp->species[i], distf[li_charged + i]); } - for (int i=0; inum_neut_species; ++i) { - gk_neut_species_apply_bc(sbapp, &sbapp->neut_species[i], distf_neut[li_neut+i]); + for (int i = 0; i < app->num_neut_species; ++i) { + gk_neut_species_apply_bc(sbapp, &sbapp->neut_species[i], distf_neut[li_neut + i]); } } // Sync blocks. struct timespec wst = gkyl_wall_clock(); int cdim = gkyl_gk_block_geom_ndim(app->gk_block_geom); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { // Sync charged species. struct gkyl_array *fs[app->num_local_blocks]; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { int li_charged = b * app->num_species; - fs[b] = distf[li_charged+i]; + fs[b] = distf[li_charged + i]; } - gkyl_multib_comm_conn_array_transfer(app->comm, app->num_local_blocks, app->local_blocks, - app->mbcc_sync_charged[i].send, app->mbcc_sync_charged[i].recv, fs, fs); + gkyl_multib_comm_conn_array_transfer( + app->comm, app->num_local_blocks, app->local_blocks, app->mbcc_sync_charged[i].send, + app->mbcc_sync_charged[i].recv, fs, fs + ); } app->stat.species_bc_tm += gkyl_time_diff_now_sec(wst); struct timespec wst_neut = gkyl_wall_clock(); struct gkyl_gyrokinetic_app *sbapp0 = app->singleb_apps[0]; - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { // Sync neutral species. if (!sbapp0->neut_species[i].info.is_static) { struct gkyl_array *fs[app->num_local_blocks]; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { int li_neut = b * app->num_neut_species; - fs[b] = distf_neut[li_neut+i]; + fs[b] = distf_neut[li_neut + i]; } - gkyl_multib_comm_conn_array_transfer(app->comm, app->num_local_blocks, app->local_blocks, - app->mbcc_sync_neut[i].send, app->mbcc_sync_neut[i].recv, fs, fs); + gkyl_multib_comm_conn_array_transfer( + app->comm, app->num_local_blocks, app->local_blocks, app->mbcc_sync_neut[i].send, + app->mbcc_sync_neut[i].recv, fs, fs + ); } } app->stat.neut_species_bc_tm += gkyl_time_diff_now_sec(wst_neut); - } -void -gyrokinetic_multib_calc_field_and_apply_bc(struct gkyl_gyrokinetic_multib_app* app, double tcurr, - struct gkyl_array *distf[], struct gkyl_array **bflux[], struct gkyl_array *distf_neut[]) +void gyrokinetic_multib_calc_field_and_apply_bc( + struct gkyl_gyrokinetic_multib_app *app, double tcurr, struct gkyl_array *distf[], + struct gkyl_array **bflux[], struct gkyl_array *distf_neut[] +) { // Compute fields and apply BCs. // Compute the field. // MF 2024/09/27/: Need the cast here for consistency. Fixing // this may require removing 'const' from a lot of places. - gyrokinetic_multib_calc_field(app, tcurr, (const struct gkyl_array **) distf, bflux); + gyrokinetic_multib_calc_field(app, tcurr, (const struct gkyl_array **)distf, bflux); // Apply boundary conditions. struct timespec wst = gkyl_wall_clock(); @@ -989,136 +1094,135 @@ gyrokinetic_multib_calc_field_and_apply_bc(struct gkyl_gyrokinetic_multib_app* a app->stat.bc_tm += gkyl_time_diff_now_sec(wst); } -void -gkyl_gyrokinetic_multib_app_apply_ic(gkyl_gyrokinetic_multib_app* app, double t0) +void gkyl_gyrokinetic_multib_app_apply_ic(gkyl_gyrokinetic_multib_app *app, double t0) { app->tcurr = t0; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_multib_app_apply_ic_species(app, i, t0); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_multib_app_apply_ic_neut_species(app, i, t0); - } + } // Compute the fields and apply BCs. struct gkyl_array *distf[app->num_species * app->num_local_blocks]; struct gkyl_array **bflux[app->num_species * app->num_local_blocks]; struct gkyl_array *distf_neut[app->num_neut_species * app->num_local_blocks]; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; int li_charged = b * app->num_species; int li_neut = b * app->num_neut_species; - for (int i=0; inum_species; ++i) { - distf[li_charged+i] = sbapp->species[i].f; - bflux[li_charged+i] = sbapp->species[i].bflux.f1; + for (int i = 0; i < app->num_species; ++i) { + distf[li_charged + i] = sbapp->species[i].f; + bflux[li_charged + i] = sbapp->species[i].bflux.f1; } - for (int i=0; inum_neut_species; ++i) { - distf_neut[li_neut+i] = sbapp->neut_species[i].f; + for (int i = 0; i < app->num_neut_species; ++i) { + distf_neut[li_neut + i] = sbapp->neut_species[i].f; } } gyrokinetic_multib_calc_field_and_apply_bc(app, t0, distf, bflux, distf_neut); } -void -gkyl_gyrokinetic_multib_app_apply_ic_species(gkyl_gyrokinetic_multib_app* app, int sidx, double t0) +void gkyl_gyrokinetic_multib_app_apply_ic_species( + gkyl_gyrokinetic_multib_app *app, int sidx, double t0 +) { app->tcurr = t0; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_apply_ic_species(app->singleb_apps[b], sidx, t0); } gkyl_comm_barrier(app->comm); } -void -gkyl_gyrokinetic_multib_app_apply_ic_neut_species(gkyl_gyrokinetic_multib_app* app, int sidx, double t0) +void gkyl_gyrokinetic_multib_app_apply_ic_neut_species( + gkyl_gyrokinetic_multib_app *app, int sidx, double t0 +) { app->tcurr = t0; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_apply_ic_neut_species(app->singleb_apps[b], sidx, t0); } gkyl_comm_barrier(app->comm); } - struct gkyl_app_restart_status gkyl_gyrokinetic_multib_app_from_file_field(gkyl_gyrokinetic_multib_app *app, const char *fname) { - // TO DO - return (struct gkyl_app_restart_status) { }; - + // TO DO + return (struct gkyl_app_restart_status){}; } -struct gkyl_app_restart_status -gkyl_gyrokinetic_multib_app_from_file_species(gkyl_gyrokinetic_multib_app *app, int sidx, - const char *fname) +struct gkyl_app_restart_status gkyl_gyrokinetic_multib_app_from_file_species( + gkyl_gyrokinetic_multib_app *app, int sidx, const char *fname +) { // TO DO - return (struct gkyl_app_restart_status) { }; + return (struct gkyl_app_restart_status){}; } -struct gkyl_app_restart_status -gkyl_gyrokinetic_multib_app_from_file_neut_species(gkyl_gyrokinetic_multib_app *app, int sidx, - const char *fname) +struct gkyl_app_restart_status gkyl_gyrokinetic_multib_app_from_file_neut_species( + gkyl_gyrokinetic_multib_app *app, int sidx, const char *fname +) { // TO DO - return (struct gkyl_app_restart_status) { }; + return (struct gkyl_app_restart_status){}; } struct gkyl_app_restart_status gkyl_gyrokinetic_multib_app_read_from_frame(gkyl_gyrokinetic_multib_app *app, int frame) { struct gkyl_app_restart_status rstat; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; - for (int i=0; inum_neut_species; i++) { + for (int i = 0; i < app->num_neut_species; i++) { int neut_frame = frame; if (sbapp->neut_species[i].info.is_static) { neut_frame = 0; } rstat = gkyl_gyrokinetic_app_from_frame_neut_species(sbapp, i, neut_frame); } - for (int i=0; inum_species; i++) { + for (int i = 0; i < app->num_species; i++) { rstat = gkyl_gyrokinetic_app_from_frame_species(sbapp, i, frame); } } - + if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { // Compute the fields and apply BCs. struct gkyl_array *distf[app->num_species * app->num_local_blocks]; struct gkyl_array **bflux[app->num_species * app->num_local_blocks]; struct gkyl_array *distf_neut[app->num_neut_species * app->num_local_blocks]; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; int li_charged = b * app->num_species; int li_neut = b * app->num_neut_species; - for (int i=0; inum_species; ++i) { - distf[li_charged+i] = sbapp->species[i].f; - bflux[li_charged+i] = sbapp->species[i].bflux.f; + for (int i = 0; i < app->num_species; ++i) { + distf[li_charged + i] = sbapp->species[i].f; + bflux[li_charged + i] = sbapp->species[i].bflux.f; } - for (int i=0; inum_neut_species; ++i) { - distf_neut[li_neut+i] = sbapp->neut_species[i].f; + for (int i = 0; i < app->num_neut_species; ++i) { + distf_neut[li_neut + i] = sbapp->neut_species[i].f; } } -// if (app->update_field && app->field->gkfield_id == GKYL_GK_FIELD_BOLTZMANN) { -// for (int i=0; inum_species; ++i) { -// struct gk_species *s = &app->species[i]; -// -// // Compute advection speeds so we can compute the initial boundary flux. -// gkyl_gk_collisionless_flux_alpha_surf(s->calc_gk_vars, -// &app->local, &s->local, &s->local_ext, app->field->phi_smooth, -// s->alpha_surf, s->sgn_alpha_surf, s->const_sgn_alpha); -// -// // Compute and store (in the ghost cell of of out) the boundary fluxes. -// // NOTE: this overwrites ghost cells that may be used for sourcing. -// gk_species_bflux_rhs(app, s, &s->bflux, distf[i], distf[i]); -// } -// } + // if (app->update_field && app->field->gkfield_id == GKYL_GK_FIELD_BOLTZMANN) { + // for (int i=0; inum_species; ++i) { + // struct gk_species *s = &app->species[i]; + // + // // Compute advection speeds so we can compute the initial boundary flux. + // gkyl_gk_collisionless_flux_alpha_surf(s->calc_gk_vars, + // &app->local, &s->local, &s->local_ext, app->field->phi_smooth, + // s->alpha_surf, s->sgn_alpha_surf, s->const_sgn_alpha); + // + // // Compute and store (in the ghost cell of of out) the boundary fluxes. + // // NOTE: this overwrites ghost cells that may be used for sourcing. + // gk_species_bflux_rhs(app, s, &s->bflux, distf[i], distf[i]); + // } + // } gyrokinetic_multib_calc_field_and_apply_bc(app, rstat.stime, distf, bflux, distf_neut); } struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[0]; sbapp->field->is_first_energy_write_call = false; // Append to existing diagnostic. - // + // app->is_first_dt_write_call = false; return rstat; @@ -1128,35 +1232,39 @@ struct gkyl_app_restart_status gkyl_gyrokinetic_multib_app_from_frame_field(gkyl_gyrokinetic_multib_app *app, int frame) { // TO DO - return (struct gkyl_app_restart_status) { }; + return (struct gkyl_app_restart_status){}; } struct gkyl_app_restart_status gkyl_gyrokinetic_multib_app_from_frame_species(gkyl_gyrokinetic_multib_app *app, int sidx, int frame) { // TO DO - return (struct gkyl_app_restart_status) { }; + return (struct gkyl_app_restart_status){}; } -struct gkyl_app_restart_status -gkyl_gyrokinetic_multib_app_from_frame_neut_species(gkyl_gyrokinetic_multib_app *app, int sidx, int frame) +struct gkyl_app_restart_status gkyl_gyrokinetic_multib_app_from_frame_neut_species( + gkyl_gyrokinetic_multib_app *app, int sidx, int frame +) { // TO DO - return (struct gkyl_app_restart_status) { }; + return (struct gkyl_app_restart_status){}; } // private function to handle variable argument list for printing -static void -v_gyrokinetic_multib_app_cout(const gkyl_gyrokinetic_multib_app* app, FILE *fp, const char *fmt, va_list argp) +static void v_gyrokinetic_multib_app_cout( + const gkyl_gyrokinetic_multib_app *app, FILE *fp, const char *fmt, va_list argp +) { int rank; gkyl_comm_get_rank(app->comm, &rank); - if ((rank == 0) && fp) + if ((rank == 0) && fp) { vfprintf(fp, fmt, argp); + } } -void -gkyl_gyrokinetic_multib_app_cout(const gkyl_gyrokinetic_multib_app* app, FILE *fp, const char *fmt, ...) +void gkyl_gyrokinetic_multib_app_cout( + const gkyl_gyrokinetic_multib_app *app, FILE *fp, const char *fmt, ... +) { va_list argp; va_start(argp, fmt); @@ -1164,8 +1272,7 @@ gkyl_gyrokinetic_multib_app_cout(const gkyl_gyrokinetic_multib_app* app, FILE *f va_end(argp); } -void -gkyl_gyrokinetic_multib_app_write_topo(const gkyl_gyrokinetic_multib_app* app) +void gkyl_gyrokinetic_multib_app_write_topo(const gkyl_gyrokinetic_multib_app *app) { int rank; gkyl_comm_get_rank(app->comm, &rank); @@ -1176,40 +1283,36 @@ gkyl_gyrokinetic_multib_app_write_topo(const gkyl_gyrokinetic_multib_app* app) } } -void -gkyl_gyrokinetic_multib_app_write_field(gkyl_gyrokinetic_multib_app *app, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_field(gkyl_gyrokinetic_multib_app *app, double tm, int frame) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_field(app->singleb_apps[b], tm, frame); } } -void -gkyl_gyrokinetic_multib_app_calc_field_energy(gkyl_gyrokinetic_multib_app* app, double tm) +void gkyl_gyrokinetic_multib_app_calc_field_energy(gkyl_gyrokinetic_multib_app *app, double tm) { if (app->update_field) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_calc_field_energy(app->singleb_apps[b], tm); } } } -void -gkyl_gyrokinetic_multib_app_write_field_energy(gkyl_gyrokinetic_multib_app* app) +void gkyl_gyrokinetic_multib_app_write_field_energy(gkyl_gyrokinetic_multib_app *app) { if (app->update_field) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_field_energy(app->singleb_apps[b]); } } } -void -gkyl_gyrokinetic_multib_app_write_eirene(gkyl_gyrokinetic_multib_app *app, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_eirene(gkyl_gyrokinetic_multib_app *app, double tm, int frame) { - - for (int b=0; bnum_local_blocks; ++b) + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_eirene_diagnostics(app->singleb_apps[b], tm, frame); + } struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[0]; cstr fileNm = cstr_from_fmt("%snew_data_flag", sbapp->eirene->info.output_data_path); @@ -1217,266 +1320,300 @@ gkyl_gyrokinetic_multib_app_write_eirene(gkyl_gyrokinetic_multib_app *app, doubl gkyl_comm_get_rank(app->comm, &rank); if (0 == rank) { FILE *fp = fopen(fileNm.str, "w"); - if (fp == NULL) - return; + if (fp == NULL) { + return; + } fprintf(fp, "%d\n", frame); fclose(fp); } cstr_drop(&fileNm); } -void -gkyl_gyrokinetic_multib_app_calc_eirene_integrated_diagnostics(gkyl_gyrokinetic_multib_app *app, double tm) +void gkyl_gyrokinetic_multib_app_calc_eirene_integrated_diagnostics( + gkyl_gyrokinetic_multib_app *app, double tm +) { - for (int b=0; bnum_local_blocks; ++b) + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_calc_eirene_integrated_diagnostics(app->singleb_apps[b], tm); + } } -void -gkyl_gyrokinetic_multib_app_write_eirene_integrated_diagnostics(gkyl_gyrokinetic_multib_app *app) +void gkyl_gyrokinetic_multib_app_write_eirene_integrated_diagnostics(gkyl_gyrokinetic_multib_app *app +) { - for (int b=0; bnum_local_blocks; ++b) + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_eirene_integrated_diagnostics(app->singleb_apps[b]); + } } // // ............. Species outputs ............... // -// -void -gkyl_gyrokinetic_multib_app_write_species(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_multib_app_write_species( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_write_neut_species(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_neut_species( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_neut_species(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_write_species_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_species_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_mom(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_write_neut_species_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_neut_species_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_neut_species_mom(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_calc_species_integrated_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm) +void gkyl_gyrokinetic_multib_app_calc_species_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_calc_species_integrated_mom(app->singleb_apps[b], sidx, tm); } } -void -gkyl_gyrokinetic_multib_app_calc_neut_species_integrated_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm) +void gkyl_gyrokinetic_multib_app_calc_neut_species_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_calc_neut_species_integrated_mom(app->singleb_apps[b], sidx, tm); } } -void -gkyl_gyrokinetic_multib_app_calc_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm) +void gkyl_gyrokinetic_multib_app_calc_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_calc_species_boundary_flux_integrated_mom(app->singleb_apps[b], sidx, tm); } } -void -gkyl_gyrokinetic_multib_app_write_species_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx) +void gkyl_gyrokinetic_multib_app_write_species_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_integrated_mom(app->singleb_apps[b], sidx); } } -void -gkyl_gyrokinetic_multib_app_write_neut_species_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx) +void gkyl_gyrokinetic_multib_app_write_neut_species_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_neut_species_integrated_mom(app->singleb_apps[b], sidx); } } -void -gkyl_gyrokinetic_multib_app_write_species_boundary_flux_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx) +void gkyl_gyrokinetic_multib_app_write_species_boundary_flux_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_boundary_flux_integrated_mom(app->singleb_apps[b], sidx); } } // // ............. Source outputs ............... // -// -void -gkyl_gyrokinetic_multib_app_write_species_source(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_multib_app_write_species_source( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_source(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_write_neut_species_source(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_neut_species_source( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_neut_species_source(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_write_species_source_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_species_source_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_source_mom(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_write_neut_species_source_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_neut_species_source_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_neut_species_source_mom(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_calc_species_source_integrated_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm) +void gkyl_gyrokinetic_multib_app_calc_species_source_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_calc_species_source_integrated_mom(app->singleb_apps[b], sidx, tm); } } -void -gkyl_gyrokinetic_multib_app_calc_neut_species_source_integrated_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm) +void gkyl_gyrokinetic_multib_app_calc_neut_species_source_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_calc_neut_species_source_integrated_mom(app->singleb_apps[b], sidx, tm); } } -void -gkyl_gyrokinetic_multib_app_write_species_source_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx) +void gkyl_gyrokinetic_multib_app_write_species_source_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_source_integrated_mom(app->singleb_apps[b], sidx); } } -void -gkyl_gyrokinetic_multib_app_write_neut_species_source_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx) +void gkyl_gyrokinetic_multib_app_write_neut_species_source_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_neut_species_source_integrated_mom(app->singleb_apps[b], sidx); } } // // ............. BGK Source outputs ............... // -// -void -gkyl_gyrokinetic_multib_app_calc_species_source_bgk_integrated_diagnostics(gkyl_gyrokinetic_multib_app* app, int sidx, double tm) +// +void gkyl_gyrokinetic_multib_app_calc_species_source_bgk_integrated_diagnostics( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +) { - for (int b=0; bnum_local_blocks; ++b) { - gkyl_gyrokinetic_app_calc_species_source_bgk_integrated_diagnostics(app->singleb_apps[b], sidx, tm); + for (int b = 0; b < app->num_local_blocks; ++b) { + gkyl_gyrokinetic_app_calc_species_source_bgk_integrated_diagnostics( + app->singleb_apps[b], sidx, tm + ); } } -void -gkyl_gyrokinetic_multib_app_write_species_source_bgk_integrated_diagnostics(gkyl_gyrokinetic_multib_app *app, int sidx) +void gkyl_gyrokinetic_multib_app_write_species_source_bgk_integrated_diagnostics( + gkyl_gyrokinetic_multib_app *app, int sidx +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_source_bgk_integrated_diagnostics(app->singleb_apps[b], sidx); } } // // ............. LTE outputs ............... // -// -void -gkyl_gyrokinetic_multib_app_write_species_lte_max_corr_status(gkyl_gyrokinetic_multib_app* app, int sidx) +// +void gkyl_gyrokinetic_multib_app_write_species_lte_max_corr_status( + gkyl_gyrokinetic_multib_app *app, int sidx +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_lte_max_corr_status(app->singleb_apps[b], sidx); } } -void -gkyl_gyrokinetic_multib_app_write_neut_species_lte_max_corr_status(gkyl_gyrokinetic_multib_app* app, int sidx) +void gkyl_gyrokinetic_multib_app_write_neut_species_lte_max_corr_status( + gkyl_gyrokinetic_multib_app *app, int sidx +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_neut_species_lte_max_corr_status(app->singleb_apps[b], sidx); } } // // ............. Collision outputs ............... // -// -void -gkyl_gyrokinetic_multib_app_write_species_lbo_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_multib_app_write_species_lbo_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_lbo_mom(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_write_species_bgk_mom(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_species_bgk_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_bgk_mom(app->singleb_apps[b], sidx, tm, frame); } } // // ............. Radiation outputs ............... // -// -void -gkyl_gyrokinetic_multib_app_write_species_rad_drag(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +// +void gkyl_gyrokinetic_multib_app_write_species_rad_drag( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_rad_drag(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_write_species_rad_emissivity(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_species_rad_emissivity( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_rad_emissivity(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_calc_species_rad_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx, double tm) +void gkyl_gyrokinetic_multib_app_calc_species_rad_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_calc_species_rad_integrated_mom(app->singleb_apps[b], sidx, tm); } } -void -gkyl_gyrokinetic_multib_app_write_species_rad_integrated_mom(gkyl_gyrokinetic_multib_app *app, int sidx) +void gkyl_gyrokinetic_multib_app_write_species_rad_integrated_mom( + gkyl_gyrokinetic_multib_app *app, int sidx +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_rad_integrated_mom(app->singleb_apps[b], sidx); } } @@ -1484,8 +1621,9 @@ gkyl_gyrokinetic_multib_app_write_species_rad_integrated_mom(gkyl_gyrokinetic_mu // // ............. Functions that group several outputs for a single species ............... // // -void -gkyl_gyrokinetic_multib_app_write_species_phase(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_species_phase( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { gkyl_gyrokinetic_multib_app_write_species(app, sidx, tm, frame); @@ -1494,37 +1632,39 @@ gkyl_gyrokinetic_multib_app_write_species_phase(gkyl_gyrokinetic_multib_app* app gkyl_gyrokinetic_multib_app_write_species_rad_drag(app, sidx, tm, frame); } -void -gkyl_gyrokinetic_multib_app_write_neut_species_phase(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_neut_species_phase( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { gkyl_gyrokinetic_multib_app_write_neut_species(app, sidx, tm, frame); gkyl_gyrokinetic_multib_app_write_neut_species_source(app, sidx, tm, frame); } -void -gkyl_gyrokinetic_multib_app_write_species_conf(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_species_conf( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_species_conf(app->singleb_apps[b], sidx, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_write_neut_species_conf(gkyl_gyrokinetic_multib_app* app, int sidx, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_neut_species_conf( + gkyl_gyrokinetic_multib_app *app, int sidx, double tm, int frame +) { - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { gkyl_gyrokinetic_app_write_neut_species_conf(app->singleb_apps[b], sidx, tm, frame); } } // // ............. Functions that group several species outputs ............... // -// -void -gkyl_gyrokinetic_multib_app_write_mom(gkyl_gyrokinetic_multib_app* app, double tm, int frame) +// +void gkyl_gyrokinetic_multib_app_write_mom(gkyl_gyrokinetic_multib_app *app, double tm, int frame) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_multib_app_write_species_mom(app, i, tm, frame); gkyl_gyrokinetic_multib_app_write_species_source_mom(app, i, tm, frame); gkyl_gyrokinetic_multib_app_write_species_lbo_mom(app, i, tm, frame); @@ -1532,16 +1672,15 @@ gkyl_gyrokinetic_multib_app_write_mom(gkyl_gyrokinetic_multib_app* app, double t gkyl_gyrokinetic_multib_app_write_species_rad_emissivity(app, i, tm, frame); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_multib_app_write_neut_species_mom(app, i, tm, frame); gkyl_gyrokinetic_multib_app_write_neut_species_source_mom(app, i, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_calc_integrated_mom(gkyl_gyrokinetic_multib_app* app, double tm) +void gkyl_gyrokinetic_multib_app_calc_integrated_mom(gkyl_gyrokinetic_multib_app *app, double tm) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_multib_app_calc_species_integrated_mom(app, i, tm); gkyl_gyrokinetic_multib_app_calc_species_source_integrated_mom(app, i, tm); gkyl_gyrokinetic_multib_app_calc_species_source_bgk_integrated_diagnostics(app, i, tm); @@ -1549,7 +1688,7 @@ gkyl_gyrokinetic_multib_app_calc_integrated_mom(gkyl_gyrokinetic_multib_app* app gkyl_gyrokinetic_multib_app_calc_species_boundary_flux_integrated_mom(app, i, tm); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_multib_app_calc_neut_species_integrated_mom(app, i, tm); gkyl_gyrokinetic_multib_app_calc_neut_species_source_integrated_mom(app, i, tm); } @@ -1557,10 +1696,9 @@ gkyl_gyrokinetic_multib_app_calc_integrated_mom(gkyl_gyrokinetic_multib_app* app gkyl_gyrokinetic_multib_app_calc_eirene_integrated_diagnostics(app, tm); } -void -gkyl_gyrokinetic_multib_app_write_integrated_mom(gkyl_gyrokinetic_multib_app *app) +void gkyl_gyrokinetic_multib_app_write_integrated_mom(gkyl_gyrokinetic_multib_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_multib_app_write_species_integrated_mom(app, i); gkyl_gyrokinetic_multib_app_write_species_source_integrated_mom(app, i); gkyl_gyrokinetic_multib_app_write_species_source_bgk_integrated_diagnostics(app, i); @@ -1569,7 +1707,7 @@ gkyl_gyrokinetic_multib_app_write_integrated_mom(gkyl_gyrokinetic_multib_app *ap gkyl_gyrokinetic_multib_app_write_species_boundary_flux_integrated_mom(app, i); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_multib_app_write_neut_species_integrated_mom(app, i); gkyl_gyrokinetic_multib_app_write_neut_species_source_integrated_mom(app, i); gkyl_gyrokinetic_multib_app_write_neut_species_lte_max_corr_status(app, i); @@ -1578,36 +1716,33 @@ gkyl_gyrokinetic_multib_app_write_integrated_mom(gkyl_gyrokinetic_multib_app *ap gkyl_gyrokinetic_multib_app_write_eirene_integrated_diagnostics(app); } -void -gkyl_gyrokinetic_multib_app_write_conf(gkyl_gyrokinetic_multib_app* app, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_conf(gkyl_gyrokinetic_multib_app *app, double tm, int frame) { gkyl_gyrokinetic_multib_app_write_field(app, tm, frame); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_multib_app_write_species_conf(app, i, tm, frame); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_multib_app_write_neut_species_conf(app, i, tm, frame); } gkyl_gyrokinetic_multib_app_write_eirene(app, tm, frame); } -void -gkyl_gyrokinetic_multib_app_write_phase(gkyl_gyrokinetic_multib_app* app, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write_phase(gkyl_gyrokinetic_multib_app *app, double tm, int frame) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_gyrokinetic_multib_app_write_species_phase(app, i, tm, frame); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { gkyl_gyrokinetic_multib_app_write_neut_species_phase(app, i, tm, frame); } } -void -gkyl_gyrokinetic_multib_app_write(gkyl_gyrokinetic_multib_app* app, double tm, int frame) +void gkyl_gyrokinetic_multib_app_write(gkyl_gyrokinetic_multib_app *app, double tm, int frame) { gkyl_gyrokinetic_multib_app_write_phase(app, tm, frame); @@ -1616,10 +1751,10 @@ gkyl_gyrokinetic_multib_app_write(gkyl_gyrokinetic_multib_app* app, double tm, i // // ............. End of write functions ............... // -// +// struct gkyl_update_status -gkyl_gyrokinetic_multib_update(gkyl_gyrokinetic_multib_app* app, double dt) +gkyl_gyrokinetic_multib_update(gkyl_gyrokinetic_multib_app *app, double dt) { app->stat.nup += 1; struct timespec wst = gkyl_wall_clock(); @@ -1630,25 +1765,25 @@ gkyl_gyrokinetic_multib_update(gkyl_gyrokinetic_multib_app* app, double dt) app->stat.time_loop_tm += gkyl_time_diff_now_sec(wst); // Check for any CUDA errors during time step - if (app->use_gpu) + if (app->use_gpu) { checkCuda(cudaGetLastError()); + } return status; } -struct gkyl_gyrokinetic_stat -gkyl_gyrokinetic_multib_app_stat(gkyl_gyrokinetic_multib_app* app) +struct gkyl_gyrokinetic_stat gkyl_gyrokinetic_multib_app_stat(gkyl_gyrokinetic_multib_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { app->stat.n_iter_corr[i] = 0; app->stat.num_corr[i] = 0; } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { app->stat.neut_n_iter_corr[i] = 0; app->stat.neut_num_corr[i] = 0; } - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { // Add time spent on various operations for each local block. struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; struct gkyl_gyrokinetic_stat sb_stat = gkyl_gyrokinetic_app_stat(sbapp); @@ -1683,144 +1818,327 @@ gkyl_gyrokinetic_multib_app_stat(gkyl_gyrokinetic_multib_app* app) app->stat.neut_species_diag_io_tm += sb_stat.neut_species_diag_io_tm; app->stat.n_species_omega_cfl += sb_stat.n_species_omega_cfl; - app->stat.n_mom += sb_stat.n_mom; + app->stat.n_mom += sb_stat.n_mom; app->stat.n_diag += sb_stat.n_diag; app->stat.n_io += sb_stat.n_io; app->stat.n_diag_io += sb_stat.n_diag_io; app->stat.n_neut_species_omega_cfl += sb_stat.n_neut_species_omega_cfl; - app->stat.n_neut_mom += sb_stat.n_neut_mom; + app->stat.n_neut_mom += sb_stat.n_neut_mom; app->stat.n_neut_diag += sb_stat.n_neut_diag; app->stat.n_neut_io += sb_stat.n_neut_io; app->stat.n_neut_diag_io += sb_stat.n_neut_diag_io; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { app->stat.n_iter_corr[i] += sb_stat.n_iter_corr[i]; app->stat.num_corr[i] += sb_stat.num_corr[i]; } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { app->stat.neut_n_iter_corr[i] += sb_stat.neut_n_iter_corr[i]; app->stat.neut_num_corr[i] += sb_stat.neut_num_corr[i]; } // Timers not yet computed in app directly. app->stat.time_rate_diags_tm += sb_stat.fdot_tm + sb_stat.phidot_tm; - app->stat.pos_shift_tm += sb_stat.species_pos_shift_tm + sb_stat.neut_species_pos_shift_tm + sb_stat.pos_shift_quasineut_tm; - app->stat.io_tm += sb_stat.species_io_tm + sb_stat.species_diag_calc_tm + sb_stat.species_diag_io_tm + sb_stat.neut_species_io_tm - + sb_stat.neut_species_diag_calc_tm + sb_stat.neut_species_diag_io_tm + sb_stat.field_io_tm + sb_stat.field_diag_calc_tm - + sb_stat.field_diag_io_tm + sb_stat.app_io_tm; - + app->stat.pos_shift_tm += sb_stat.species_pos_shift_tm + sb_stat.neut_species_pos_shift_tm + + sb_stat.pos_shift_quasineut_tm; + app->stat.io_tm += sb_stat.species_io_tm + sb_stat.species_diag_calc_tm + + sb_stat.species_diag_io_tm + sb_stat.neut_species_io_tm + + sb_stat.neut_species_diag_calc_tm + sb_stat.neut_species_diag_io_tm + + sb_stat.field_io_tm + sb_stat.field_diag_calc_tm + sb_stat.field_diag_io_tm + + sb_stat.app_io_tm; + // Additions of several timers. - app->stat.fwd_euler_sum_tm += sb_stat.species_coll_mom_tm + sb_stat.species_react_mom_tm + sb_stat.neut_species_coll_mom_tm - + sb_stat.neut_species_react_mom_tm + sb_stat.species_rad_mom_tm + sb_stat.species_gyroavg_tm + sb_stat.species_collisionless_tm - + sb_stat.species_coll_tm + sb_stat.species_diffusion_tm + sb_stat.species_rad_tm + sb_stat.species_react_tm - + sb_stat.species_bflux_calc_tm+sb_stat.species_bflux_moms_tm + sb_stat.species_omega_cfl_tm + sb_stat.species_src_tm - + sb_stat.neut_species_collisionless_tm + sb_stat.neut_species_coll_tm + sb_stat.neut_species_react_tm - + sb_stat.neut_species_omega_cfl_tm + sb_stat.neut_species_src_tm + sb_stat.dfdt_dt_reduce_tm; + app->stat.fwd_euler_sum_tm += + sb_stat.species_coll_mom_tm + sb_stat.species_react_mom_tm + + sb_stat.neut_species_coll_mom_tm + sb_stat.neut_species_react_mom_tm + + sb_stat.species_rad_mom_tm + sb_stat.species_gyroavg_tm + sb_stat.species_collisionless_tm + + sb_stat.species_coll_tm + sb_stat.species_diffusion_tm + sb_stat.species_rad_tm + + sb_stat.species_react_tm + sb_stat.species_bflux_calc_tm + sb_stat.species_bflux_moms_tm + + sb_stat.species_omega_cfl_tm + sb_stat.species_src_tm + + sb_stat.neut_species_collisionless_tm + sb_stat.neut_species_coll_tm + + sb_stat.neut_species_react_tm + sb_stat.neut_species_omega_cfl_tm + + sb_stat.neut_species_src_tm + sb_stat.dfdt_dt_reduce_tm; app->stat.time_rate_diags_sum_tm += sb_stat.fdot_tm + sb_stat.phidot_tm; - app->stat.pos_shift_sum_tm += sb_stat.species_pos_shift_tm + sb_stat.neut_species_pos_shift_tm + sb_stat.pos_shift_quasineut_tm; - - app->stat.io_sum_tm += sb_stat.species_io_tm + sb_stat.species_diag_calc_tm + sb_stat.species_diag_io_tm + sb_stat.neut_species_io_tm - + sb_stat.neut_species_diag_calc_tm + sb_stat.neut_species_diag_io_tm + sb_stat.field_io_tm + sb_stat.field_diag_calc_tm - + sb_stat.field_diag_io_tm + sb_stat.app_io_tm; + app->stat.pos_shift_sum_tm += sb_stat.species_pos_shift_tm + sb_stat.neut_species_pos_shift_tm + + sb_stat.pos_shift_quasineut_tm; + app->stat.io_sum_tm += sb_stat.species_io_tm + sb_stat.species_diag_calc_tm + + sb_stat.species_diag_io_tm + sb_stat.neut_species_io_tm + + sb_stat.neut_species_diag_calc_tm + sb_stat.neut_species_diag_io_tm + + sb_stat.field_io_tm + sb_stat.field_diag_calc_tm + + sb_stat.field_diag_io_tm + sb_stat.app_io_tm; } app->stat.fwd_euler_sum_tm += app->stat.fwd_euler_step_f_tm + app->stat.dfdt_dt_reduce_tm; app->stat.bc_sum_tm = app->stat.species_bc_tm + app->stat.neut_species_bc_tm; - app->stat.field_sum_tm = app->stat.field_phi_rhs_tm + app->stat.field_phi_solve_tm; - app->stat.time_stepper_sum_tm = app->stat.fwd_euler_tm + app->stat.field_tm + app->stat.bc_tm - + app->stat.time_rate_diags_tm + app->stat.pos_shift_tm + app->stat.time_stepper_arithmetic_tm; + app->stat.field_sum_tm = app->stat.field_phi_rhs_tm + app->stat.field_phi_solve_tm; + app->stat.time_stepper_sum_tm = app->stat.fwd_euler_tm + app->stat.field_tm + app->stat.bc_tm + + app->stat.time_rate_diags_tm + app->stat.pos_shift_tm + + app->stat.time_stepper_arithmetic_tm; return app->stat; } -static inline -double -ratio_to_percent(double num, double den, double alt) +static inline double ratio_to_percent(double num, double den, double alt) { - return den > 1e-12 ? 100.*num/den : alt; + return den > 1e-12 ? 100. * num / den : alt; } -void -gkyl_gyrokinetic_multib_app_print_timings(gkyl_gyrokinetic_multib_app* app, FILE *iostream) +void gkyl_gyrokinetic_multib_app_print_timings(gkyl_gyrokinetic_multib_app *app, FILE *iostream) { struct gkyl_gyrokinetic_stat *stat = &app->stat; - double bflux_tm = stat->species_bflux_calc_tm+stat->species_bflux_moms_tm; + double bflux_tm = stat->species_bflux_calc_tm + stat->species_bflux_moms_tm; gkyl_gyrokinetic_multib_app_cout(app, iostream, "Timing:\n"); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " - Time loop: %.4e sec.\n", stat->time_loop_tm); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Forward Euler: %.4e sec. / %4.2f %%.\n", stat->fwd_euler_tm, ratio_to_percent(stat->fwd_euler_tm,stat->time_loop_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Collision moments (charged): %.4e sec. / %4.2f %%.\n", stat->species_coll_mom_tm , ratio_to_percent(stat->species_coll_mom_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Reaction moments (charged): %.4e sec. / %4.2f %%.\n", stat->species_react_mom_tm , ratio_to_percent(stat->species_react_mom_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Collision moments (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_coll_mom_tm , ratio_to_percent(stat->neut_species_coll_mom_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Reaction moments (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_react_mom_tm , ratio_to_percent(stat->neut_species_react_mom_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Radiation moments: %.4e sec. / %4.2f %%.\n", stat->species_rad_mom_tm , ratio_to_percent(stat->species_rad_mom_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Species gyroaverage: %.4e sec. / %4.2f %%.\n", stat->species_gyroavg_tm , ratio_to_percent(stat->species_gyroavg_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Collisionless terms (charged): %.4e sec. / %4.2f %%.\n", stat->species_collisionless_tm , ratio_to_percent(stat->species_collisionless_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Collision terms (charged): %.4e sec. / %4.2f %%.\n", stat->species_coll_tm , ratio_to_percent(stat->species_coll_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Diffusion (charged): %.4e sec. / %4.2f %%.\n", stat->species_diffusion_tm , ratio_to_percent(stat->species_diffusion_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Radiation terms: %.4e sec. / %4.2f %%.\n", stat->species_rad_tm , ratio_to_percent(stat->species_rad_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Reaction terms (charged): %.4e sec. / %4.2f %%.\n", stat->species_react_tm , ratio_to_percent(stat->species_react_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Boundary fluxes (charged): %.4e sec. / %4.2f %%.\n", bflux_tm , ratio_to_percent(bflux_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ omega_cfl (charged): %.4e sec. / %4.2f %%.\n", stat->species_omega_cfl_tm , ratio_to_percent(stat->species_omega_cfl_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Sources (charged): %.4e sec. / %4.2f %%.\n", stat->species_src_tm , ratio_to_percent(stat->species_src_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Collisionless terms (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_collisionless_tm, ratio_to_percent(stat->neut_species_collisionless_tm,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Collision terms (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_coll_tm , ratio_to_percent(stat->neut_species_coll_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Reaction terms (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_react_tm , ratio_to_percent(stat->neut_species_react_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ omega_cfl (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_omega_cfl_tm , ratio_to_percent(stat->neut_species_omega_cfl_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Sources (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_src_tm , ratio_to_percent(stat->neut_species_src_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Time step reduction: %.4e sec. / %4.2f %%.\n", stat->dfdt_dt_reduce_tm , ratio_to_percent(stat->dfdt_dt_reduce_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Step f: %.4e sec. / %4.2f %%.\n", stat->fwd_euler_step_f_tm , ratio_to_percent(stat->fwd_euler_step_f_tm ,stat->fwd_euler_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Accounted for: %4.2f %%.\n", ratio_to_percent(stat->fwd_euler_sum_tm, stat->fwd_euler_tm, 100.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Field solves: %.4e sec. / %4.2f %%.\n", stat->field_tm, ratio_to_percent(stat->field_tm,stat->time_loop_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Phi eqn RHS: %.4e sec. / %4.2f %%.\n", stat->field_phi_rhs_tm , ratio_to_percent(stat->field_phi_rhs_tm ,stat->field_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Phi eqn solve: %.4e sec. / %4.2f %%.\n", stat->field_phi_solve_tm, ratio_to_percent(stat->field_phi_solve_tm,stat->field_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Accounted for: %4.2f %%.\n", ratio_to_percent(stat->field_sum_tm, stat->field_tm, 100.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Boundary conditions:: %.4e sec. / %4.2f %%.\n", stat->bc_tm, ratio_to_percent(stat->bc_tm,stat->time_loop_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Species (charged): %.4e sec. / %4.2f %%.\n", stat->species_bc_tm , ratio_to_percent(stat->species_bc_tm ,stat->bc_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Species (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_bc_tm, ratio_to_percent(stat->neut_species_bc_tm,stat->bc_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Accounted for: %4.2f %%.\n", ratio_to_percent(stat->bc_sum_tm, stat->bc_tm, 100.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Time rate diagnostics: %.4e sec. / %4.2f %%.\n", stat->time_rate_diags_tm, ratio_to_percent(stat->time_rate_diags_tm,stat->time_loop_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Charged species: %.4e sec. / %4.2f %%.\n", stat->fdot_tm , ratio_to_percent(stat->fdot_tm ,stat->time_rate_diags_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Phi: %.4e sec. / %4.2f %%.\n", stat->phidot_tm, ratio_to_percent(stat->phidot_tm,stat->time_rate_diags_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Accounted for: %4.2f %%.\n", ratio_to_percent(stat->time_rate_diags_sum_tm, stat->time_rate_diags_tm, 100.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Positivity shift: %.4e sec. / %4.2f %%.\n", stat->pos_shift_tm, ratio_to_percent(stat->pos_shift_tm,stat->time_loop_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Species (charged): %.4e sec. / %4.2f %%.\n", stat->species_pos_shift_tm , ratio_to_percent(stat->species_pos_shift_tm ,stat->pos_shift_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Species (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_pos_shift_tm, ratio_to_percent(stat->neut_species_pos_shift_tm,stat->pos_shift_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Quasineutrality: %.4e sec. / %4.2f %%.\n", stat->pos_shift_quasineut_tm , ratio_to_percent(stat->pos_shift_quasineut_tm ,stat->pos_shift_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " ^ Accounted for: %4.2f %%.\n", ratio_to_percent(stat->pos_shift_sum_tm, stat->pos_shift_tm, 100.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Time stepper arithmetic: %.4e sec. / %4.2f %%.\n", stat->time_stepper_arithmetic_tm, ratio_to_percent(stat->time_stepper_arithmetic_tm,stat->time_loop_tm, 0.0)); - - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Accounted for: %4.2f %%.\n", ratio_to_percent(stat->time_stepper_sum_tm, stat->time_loop_tm, 100.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " - I/O: %.4e sec.\n", stat->io_tm); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * f write (charged): %.4e sec. / %4.2f %%.\n", stat->species_io_tm , ratio_to_percent(stat->species_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Species diag calc (charged): %.4e sec. / %4.2f %%.\n", stat->species_diag_calc_tm , ratio_to_percent(stat->species_diag_calc_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Species diag write (charged): %.4e sec. / %4.2f %%.\n", stat->species_diag_io_tm , ratio_to_percent(stat->species_diag_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * f write (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_io_tm , ratio_to_percent(stat->neut_species_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Species diag calc (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_diag_calc_tm, ratio_to_percent(stat->neut_species_diag_calc_tm, stat->io_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Species diag write (neutral): %.4e sec. / %4.2f %%.\n", stat->neut_species_diag_io_tm , ratio_to_percent(stat->neut_species_diag_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Field write: %.4e sec. / %4.2f %%.\n", stat->field_io_tm , ratio_to_percent(stat->field_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Field diag calc: %.4e sec. / %4.2f %%.\n", stat->field_diag_calc_tm , ratio_to_percent(stat->field_diag_calc_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Field diag write: %.4e sec. / %4.2f %%.\n", stat->field_diag_io_tm , ratio_to_percent(stat->field_diag_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Common write: %.4e sec. / %4.2f %%.\n", stat->app_io_tm , ratio_to_percent(stat->app_io_tm , stat->io_tm, 0.0)); - gkyl_gyrokinetic_multib_app_cout(app, iostream, " * Accounted for: %4.2f %%.\n", ratio_to_percent(stat->io_sum_tm, stat->io_tm, 100.0)); -} - -void -gkyl_gyrokinetic_multib_app_stat_write(gkyl_gyrokinetic_multib_app* app) -{ - for (int b=0; bnum_local_blocks; ++b) { + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " - Time loop: %.4e sec.\n", stat->time_loop_tm + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Forward Euler: %.4e sec. / %4.2f %%.\n", + stat->fwd_euler_tm, ratio_to_percent(stat->fwd_euler_tm, stat->time_loop_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Collision moments (charged): %.4e sec. / %4.2f %%.\n", + stat->species_coll_mom_tm, ratio_to_percent(stat->species_coll_mom_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Reaction moments (charged): %.4e sec. / %4.2f %%.\n", + stat->species_react_mom_tm, + ratio_to_percent(stat->species_react_mom_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Collision moments (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_coll_mom_tm, + ratio_to_percent(stat->neut_species_coll_mom_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Reaction moments (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_react_mom_tm, + ratio_to_percent(stat->neut_species_react_mom_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Radiation moments: %.4e sec. / %4.2f %%.\n", + stat->species_rad_mom_tm, ratio_to_percent(stat->species_rad_mom_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Species gyroaverage: %.4e sec. / %4.2f %%.\n", + stat->species_gyroavg_tm, ratio_to_percent(stat->species_gyroavg_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Collisionless terms (charged): %.4e sec. / %4.2f %%.\n", + stat->species_collisionless_tm, + ratio_to_percent(stat->species_collisionless_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Collision terms (charged): %.4e sec. / %4.2f %%.\n", + stat->species_coll_tm, ratio_to_percent(stat->species_coll_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Diffusion (charged): %.4e sec. / %4.2f %%.\n", + stat->species_diffusion_tm, + ratio_to_percent(stat->species_diffusion_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Radiation terms: %.4e sec. / %4.2f %%.\n", + stat->species_rad_tm, ratio_to_percent(stat->species_rad_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Reaction terms (charged): %.4e sec. / %4.2f %%.\n", + stat->species_react_tm, ratio_to_percent(stat->species_react_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Boundary fluxes (charged): %.4e sec. / %4.2f %%.\n", bflux_tm, + ratio_to_percent(bflux_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ omega_cfl (charged): %.4e sec. / %4.2f %%.\n", + stat->species_omega_cfl_tm, + ratio_to_percent(stat->species_omega_cfl_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Sources (charged): %.4e sec. / %4.2f %%.\n", + stat->species_src_tm, ratio_to_percent(stat->species_src_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Collisionless terms (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_collisionless_tm, + ratio_to_percent(stat->neut_species_collisionless_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Collision terms (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_coll_tm, + ratio_to_percent(stat->neut_species_coll_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Reaction terms (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_react_tm, + ratio_to_percent(stat->neut_species_react_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ omega_cfl (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_omega_cfl_tm, + ratio_to_percent(stat->neut_species_omega_cfl_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Sources (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_src_tm, ratio_to_percent(stat->neut_species_src_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Time step reduction: %.4e sec. / %4.2f %%.\n", + stat->dfdt_dt_reduce_tm, ratio_to_percent(stat->dfdt_dt_reduce_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Step f: %.4e sec. / %4.2f %%.\n", + stat->fwd_euler_step_f_tm, ratio_to_percent(stat->fwd_euler_step_f_tm, stat->fwd_euler_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->fwd_euler_sum_tm, stat->fwd_euler_tm, 100.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Field solves: %.4e sec. / %4.2f %%.\n", stat->field_tm, + ratio_to_percent(stat->field_tm, stat->time_loop_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Phi eqn RHS: %.4e sec. / %4.2f %%.\n", + stat->field_phi_rhs_tm, ratio_to_percent(stat->field_phi_rhs_tm, stat->field_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Phi eqn solve: %.4e sec. / %4.2f %%.\n", + stat->field_phi_solve_tm, ratio_to_percent(stat->field_phi_solve_tm, stat->field_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->field_sum_tm, stat->field_tm, 100.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Boundary conditions:: %.4e sec. / %4.2f %%.\n", stat->bc_tm, + ratio_to_percent(stat->bc_tm, stat->time_loop_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Species (charged): %.4e sec. / %4.2f %%.\n", + stat->species_bc_tm, ratio_to_percent(stat->species_bc_tm, stat->bc_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Species (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_bc_tm, ratio_to_percent(stat->neut_species_bc_tm, stat->bc_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->bc_sum_tm, stat->bc_tm, 100.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Time rate diagnostics: %.4e sec. / %4.2f %%.\n", + stat->time_rate_diags_tm, ratio_to_percent(stat->time_rate_diags_tm, stat->time_loop_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Charged species: %.4e sec. / %4.2f %%.\n", stat->fdot_tm, + ratio_to_percent(stat->fdot_tm, stat->time_rate_diags_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Phi: %.4e sec. / %4.2f %%.\n", + stat->phidot_tm, ratio_to_percent(stat->phidot_tm, stat->time_rate_diags_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->time_rate_diags_sum_tm, stat->time_rate_diags_tm, 100.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Positivity shift: %.4e sec. / %4.2f %%.\n", + stat->pos_shift_tm, ratio_to_percent(stat->pos_shift_tm, stat->time_loop_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Species (charged): %.4e sec. / %4.2f %%.\n", + stat->species_pos_shift_tm, + ratio_to_percent(stat->species_pos_shift_tm, stat->pos_shift_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Species (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_pos_shift_tm, + ratio_to_percent(stat->neut_species_pos_shift_tm, stat->pos_shift_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Quasineutrality: %.4e sec. / %4.2f %%.\n", + stat->pos_shift_quasineut_tm, + ratio_to_percent(stat->pos_shift_quasineut_tm, stat->pos_shift_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " ^ Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->pos_shift_sum_tm, stat->pos_shift_tm, 100.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Time stepper arithmetic: %.4e sec. / %4.2f %%.\n", + stat->time_stepper_arithmetic_tm, + ratio_to_percent(stat->time_stepper_arithmetic_tm, stat->time_loop_tm, 0.0) + ); + + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->time_stepper_sum_tm, stat->time_loop_tm, 100.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " - I/O: %.4e sec.\n", stat->io_tm + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * f write (charged): %.4e sec. / %4.2f %%.\n", + stat->species_io_tm, ratio_to_percent(stat->species_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Species diag calc (charged): %.4e sec. / %4.2f %%.\n", + stat->species_diag_calc_tm, ratio_to_percent(stat->species_diag_calc_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Species diag write (charged): %.4e sec. / %4.2f %%.\n", + stat->species_diag_io_tm, ratio_to_percent(stat->species_diag_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * f write (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_io_tm, ratio_to_percent(stat->neut_species_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Species diag calc (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_diag_calc_tm, + ratio_to_percent(stat->neut_species_diag_calc_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Species diag write (neutral): %.4e sec. / %4.2f %%.\n", + stat->neut_species_diag_io_tm, ratio_to_percent(stat->neut_species_diag_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Field write: %.4e sec. / %4.2f %%.\n", + stat->field_io_tm, ratio_to_percent(stat->field_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Field diag calc: %.4e sec. / %4.2f %%.\n", + stat->field_diag_calc_tm, ratio_to_percent(stat->field_diag_calc_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Field diag write: %.4e sec. / %4.2f %%.\n", + stat->field_diag_io_tm, ratio_to_percent(stat->field_diag_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Common write: %.4e sec. / %4.2f %%.\n", + stat->app_io_tm, ratio_to_percent(stat->app_io_tm, stat->io_tm, 0.0) + ); + gkyl_gyrokinetic_multib_app_cout( + app, iostream, " * Accounted for: %4.2f %%.\n", + ratio_to_percent(stat->io_sum_tm, stat->io_tm, 100.0) + ); +} + +void gkyl_gyrokinetic_multib_app_stat_write(gkyl_gyrokinetic_multib_app *app) +{ + for (int b = 0; b < app->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; gkyl_gyrokinetic_app_stat_write(sbapp); } } -void -gkyl_gyrokinetic_multib_app_write_dt(gkyl_gyrokinetic_multib_app* app) +void gkyl_gyrokinetic_multib_app_write_dt(gkyl_gyrokinetic_multib_app *app) { int rank; gkyl_comm_get_rank(app->comm, &rank); @@ -1829,23 +2147,23 @@ gkyl_gyrokinetic_multib_app_write_dt(gkyl_gyrokinetic_multib_app* app) // Write integrated diagnostic moments. const char *fmt = "%s-%s.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, "dt"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, "dt"); struct timespec wtm = gkyl_wall_clock(); if (app->is_first_dt_write_call) { struct gkyl_msgpack_map_elem io_meta_phi[] = { - { .key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Time step size." } + {.key = "Description", .elem_type = GKYL_MP_STRING, .cval = "Time step size."} }; int io_meta_len[] = {app->io_meta_basic_len, 1}; - const struct gkyl_msgpack_map_elem* io_meta[] = {app->io_meta_basic, io_meta_phi}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta); + const struct gkyl_msgpack_map_elem *io_meta[] = {app->io_meta_basic, io_meta_phi}; + struct gkyl_msgpack_data *mt = + gkyl_msgpack_create_union(sizeof(io_meta_len) / sizeof(int), io_meta_len, io_meta); gkyl_dynvec_write_wmeta(app->dts, fileNm, mt); app->is_first_dt_write_call = false; gkyl_msgpack_data_release(mt); - } - else { + } else { gkyl_dynvec_awrite(app->dts, fileNm); } app->stat.app_io_tm += gkyl_time_diff_now_sec(wtm); @@ -1854,38 +2172,39 @@ gkyl_gyrokinetic_multib_app_write_dt(gkyl_gyrokinetic_multib_app* app) gkyl_dynvec_clear(app->dts); } -void -gkyl_gyrokinetic_multib_app_save_dt(gkyl_gyrokinetic_multib_app* app, double tm, double dt) +void gkyl_gyrokinetic_multib_app_save_dt(gkyl_gyrokinetic_multib_app *app, double tm, double dt) { gkyl_dynvec_append(app->dts, tm, &dt); } -void -gkyl_gyrokinetic_multib_app_release_geom(gkyl_gyrokinetic_multib_app* mbapp) +void gkyl_gyrokinetic_multib_app_release_geom(gkyl_gyrokinetic_multib_app *mbapp) { if (mbapp->singleb_apps) { - for (int i=0; inum_local_blocks; ++i) + for (int i = 0; i < mbapp->num_local_blocks; ++i) { gkyl_gyrokinetic_app_release_geom(mbapp->singleb_apps[i]); + } gkyl_free(mbapp->singleb_apps); - } + } int num_blocks = gkyl_gk_block_geom_num_blocks(mbapp->gk_block_geom); - for (int i=0; iblock_comms[i]); + } gkyl_free(mbapp->block_comms); - for (int i=0; idecomp[i]); + } gkyl_free(mbapp->decomp); - gkyl_free(mbapp->local_blocks); + gkyl_free(mbapp->local_blocks); gkyl_rrobin_decomp_release(mbapp->round_robin); - + gkyl_gk_block_geom_release(mbapp->gk_block_geom); gkyl_block_topo_release(mbapp->block_topo); - + gkyl_comm_release(mbapp->comm); gkyl_msgpack_map_elem_release(mbapp->io_meta_basic_len, mbapp->io_meta_basic); @@ -1893,11 +2212,10 @@ gkyl_gyrokinetic_multib_app_release_geom(gkyl_gyrokinetic_multib_app* mbapp) gkyl_free(mbapp); } -void -gkyl_gyrokinetic_multib_app_release(gkyl_gyrokinetic_multib_app* mbapp) +void gkyl_gyrokinetic_multib_app_release(gkyl_gyrokinetic_multib_app *mbapp) { - for (int i=0; inum_neut_species; ++i) { - for (int bI=0; bInum_local_blocks; ++bI) { + for (int i = 0; i < mbapp->num_neut_species; ++i) { + for (int bI = 0; bI < mbapp->num_local_blocks; ++bI) { gkyl_multib_comm_conn_release(mbapp->mbcc_sync_neut[i].send[bI]); gkyl_multib_comm_conn_release(mbapp->mbcc_sync_neut[i].recv[bI]); } @@ -1906,8 +2224,8 @@ gkyl_gyrokinetic_multib_app_release(gkyl_gyrokinetic_multib_app* mbapp) } gkyl_free(mbapp->mbcc_sync_neut); - for (int i=0; inum_species; ++i) { - for (int bI=0; bInum_local_blocks; ++bI) { + for (int i = 0; i < mbapp->num_species; ++i) { + for (int bI = 0; bI < mbapp->num_local_blocks; ++bI) { gkyl_multib_comm_conn_release(mbapp->mbcc_sync_charged[i].send[bI]); gkyl_multib_comm_conn_release(mbapp->mbcc_sync_charged[i].recv[bI]); } @@ -1916,7 +2234,7 @@ gkyl_gyrokinetic_multib_app_release(gkyl_gyrokinetic_multib_app* mbapp) } gkyl_free(mbapp->mbcc_sync_charged); - for (int bI=0; bInum_local_blocks; ++bI) { + for (int bI = 0; bI < mbapp->num_local_blocks; ++bI) { gkyl_multib_comm_conn_release(mbapp->mbcc_sync_conf->send[bI]); gkyl_multib_comm_conn_release(mbapp->mbcc_sync_conf->recv[bI]); } @@ -1925,30 +2243,33 @@ gkyl_gyrokinetic_multib_app_release(gkyl_gyrokinetic_multib_app* mbapp) gkyl_free(mbapp->mbcc_sync_conf); if (mbapp->singleb_apps) { - for (int i=0; inum_local_blocks; ++i) + for (int i = 0; i < mbapp->num_local_blocks; ++i) { gkyl_gyrokinetic_app_release(mbapp->singleb_apps[i]); + } gkyl_free(mbapp->singleb_apps); - } + } gk_multib_field_release(mbapp->field); int num_blocks = gkyl_gk_block_geom_num_blocks(mbapp->gk_block_geom); - for (int i=0; iblock_comms[i]); + } gkyl_free(mbapp->block_comms); - for (int i=0; idecomp[i]); + } gkyl_free(mbapp->decomp); - gkyl_free(mbapp->local_blocks); + gkyl_free(mbapp->local_blocks); gkyl_rrobin_decomp_release(mbapp->round_robin); - + gkyl_gk_block_geom_release(mbapp->gk_block_geom); gkyl_block_topo_release(mbapp->block_topo); - + gkyl_comm_release(mbapp->comm); gkyl_dynvec_release(mbapp->dts); diff --git a/gyrokinetic/apps/gyrokinetic_multib_update_ssp_rk3.c b/gyrokinetic/apps/gyrokinetic_multib_update_ssp_rk3.c index 8f079ac882..989822b356 100644 --- a/gyrokinetic/apps/gyrokinetic_multib_update_ssp_rk3.c +++ b/gyrokinetic/apps/gyrokinetic_multib_update_ssp_rk3.c @@ -1,12 +1,12 @@ #include -static void -gyrokinetic_multib_forward_euler(struct gkyl_gyrokinetic_multib_app* app, double tcurr, double dt, - const struct gkyl_array *fin[], struct gkyl_array *fout[], - struct gkyl_array **bflux_in[], struct gkyl_array **bflux_out[], - const struct gkyl_array *fin_neut[], struct gkyl_array *fout_neut[], - struct gkyl_array **bflux_in_neut[], struct gkyl_array **bflux_out_neut[], - struct gkyl_update_status *st) +static void gyrokinetic_multib_forward_euler( + struct gkyl_gyrokinetic_multib_app *app, double tcurr, double dt, const struct gkyl_array *fin[], + struct gkyl_array *fout[], struct gkyl_array **bflux_in[], struct gkyl_array **bflux_out[], + const struct gkyl_array *fin_neut[], struct gkyl_array *fout_neut[], + struct gkyl_array **bflux_in_neut[], struct gkyl_array **bflux_out_neut[], + struct gkyl_update_status *st +) { struct timespec wst_fe = gkyl_wall_clock(); // Take a forward Euler step with the suggested time-step dt. This may @@ -19,11 +19,13 @@ gyrokinetic_multib_forward_euler(struct gkyl_gyrokinetic_multib_app* app, double double dtmin = DBL_MAX; // Compute the time rate of change of the distributions, df/dt. - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { int li_charged = b * app->num_species; int li_neut = b * app->num_neut_species; - gyrokinetic_rhs(app->singleb_apps[b], tcurr, dt, &fin[li_charged], &fout[li_charged], - &bflux_out[li_charged], &fin_neut[li_neut], &fout_neut[li_neut], &bflux_out_neut[li_neut], st); + gyrokinetic_rhs( + app->singleb_apps[b], tcurr, dt, &fin[li_charged], &fout[li_charged], &bflux_out[li_charged], + &fin_neut[li_neut], &fout_neut[li_neut], &bflux_out_neut[li_neut], st + ); dtmin = fmin(dtmin, st->dt_actual); } @@ -37,19 +39,23 @@ gyrokinetic_multib_forward_euler(struct gkyl_gyrokinetic_multib_app* app, double struct timespec wst = gkyl_wall_clock(); // Complete update of distribution functions. double dta = st->dt_actual; - for (int b=0; bnum_local_blocks; ++b) { + for (int b = 0; b < app->num_local_blocks; ++b) { struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; int li_charged = b * app->num_species; int li_neut = b * app->num_neut_species; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gks = &sbapp->species[i]; - gk_species_step_f(gks, fout[li_charged+i], dta, fin[li_charged+i]); - gk_species_bflux_step_f(sbapp, &gks->bflux, bflux_out[li_charged+i], 1.0, bflux_in[li_charged+i]); + gk_species_step_f(gks, fout[li_charged + i], dta, fin[li_charged + i]); + gk_species_bflux_step_f( + sbapp, &gks->bflux, bflux_out[li_charged + i], 1.0, bflux_in[li_charged + i] + ); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { struct gk_neut_species *gkns = &sbapp->neut_species[i]; - gk_neut_species_step_f(gkns, fout_neut[li_charged+i], dta, fin_neut[li_charged+i]); - gk_neut_species_bflux_step_f(sbapp, &gkns->bflux, bflux_out_neut[li_neut+i], 1.0, bflux_in_neut[li_neut+i]); + gk_neut_species_step_f(gkns, fout_neut[li_charged + i], dta, fin_neut[li_charged + i]); + gk_neut_species_bflux_step_f( + sbapp, &gkns->bflux, bflux_out_neut[li_neut + i], 1.0, bflux_in_neut[li_neut + i] + ); } } @@ -58,7 +64,7 @@ gyrokinetic_multib_forward_euler(struct gkyl_gyrokinetic_multib_app* app, double } struct gkyl_update_status -gyrokinetic_multib_update_ssp_rk3(struct gkyl_gyrokinetic_multib_app* app, double dt0) +gyrokinetic_multib_update_ssp_rk3(struct gkyl_gyrokinetic_multib_app *app, double dt0) { // Take time-step using the RK3 method. Also sets the status object // which has the actual and suggested dts used. These can be different @@ -77,7 +83,7 @@ gyrokinetic_multib_update_ssp_rk3(struct gkyl_gyrokinetic_multib_app* app, doubl struct gkyl_array **bflux_in_neut[ns_neut * nblocks_local]; struct gkyl_array **bflux_out_neut[ns_neut * nblocks_local]; - struct gkyl_update_status st = { .success = true }; + struct gkyl_update_status st = {.success = true}; // time-stepper state enum { RK_STAGE_1, RK_STAGE_2, RK_STAGE_3, RK_COMPLETE } state = RK_STAGE_1; @@ -85,292 +91,305 @@ gyrokinetic_multib_update_ssp_rk3(struct gkyl_gyrokinetic_multib_app* app, doubl double tcurr = app->tcurr, dt = dt0; while (state != RK_COMPLETE) { switch (state) { - case RK_STAGE_1: - for (int b=0; bsingleb_apps[b]; + int li_charged = b * ns_charged; + int li_neut = b * ns_neut; + for (int i = 0; i < ns_charged; ++i) { + struct gk_species *gks = &sbapp->species[i]; + fin[li_charged + i] = gks->f; + fout[li_charged + i] = gks->f1; + // Boundary fluxes. + bflux_in[li_charged + i] = gks->bflux.f; + bflux_out[li_charged + i] = gks->bflux.f1; + } + for (int i = 0; i < ns_neut; ++i) { + struct gk_neut_species *gkns = &sbapp->neut_species[i]; + fin_neut[li_neut + i] = gkns->f; + fout_neut[li_neut + i] = gkns->f1; + // Boundary fluxes. + bflux_in_neut[li_neut + i] = gkns->bflux.f; + bflux_out_neut[li_neut + i] = gkns->bflux.f1; + } + } + + gyrokinetic_multib_forward_euler( + app, tcurr, dt, fin, fout, bflux_in, bflux_out, fin_neut, fout_neut, bflux_in_neut, + bflux_out_neut, &st + ); + dt = st.dt_actual; + + // Subtract boundary flux f from f1 so that we only step boundary + // fluxes during a given time step, not over all time. And so that the + // boundary flux in f is kept in case a later RK stage fails. + struct timespec wst = gkyl_wall_clock(); + for (int b = 0; b < nblocks_local; ++b) { + struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; + int li_charged = b * ns_charged; + int li_neut = b * ns_neut; + for (int i = 0; i < ns_charged; ++i) { + struct gk_species *gks = &sbapp->species[i]; + gk_species_bflux_accumulate( + sbapp, &gks->bflux, bflux_out[li_charged + i], -1.0, bflux_in[li_charged + i] + ); + } + for (int i = 0; i < ns_neut; ++i) { + struct gk_neut_species *gkns = &sbapp->neut_species[i]; + gk_neut_species_bflux_accumulate( + sbapp, &gkns->bflux, bflux_out_neut[li_neut + i], -1.0, bflux_in_neut[li_neut + i] + ); + } + } + app->stat.time_stepper_arithmetic_tm += gkyl_time_diff_now_sec(wst); + + for (int b = 0; b < nblocks_local; ++b) { + struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; + for (int i = 0; i < ns_charged; ++i) { + struct gk_species *gks = &sbapp->species[i]; + // Compute moment of f_old to later compute moment of df/dt. + // Do it before the fields are updated, but after dt is calculated. + gk_species_calc_int_mom_dt(sbapp, gks, dt, gks->fdot_mom_old); + } + + // Compute field energy divided by dt for energy balance diagnostics. + gk_field_calc_energy_dt(sbapp, sbapp->field, dt, sbapp->field->em_energy_red_old); + } + + // Compute the fields and apply BCs. + gyrokinetic_multib_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); + + state = RK_STAGE_2; + break; + + case RK_STAGE_2: + for (int b = 0; b < nblocks_local; ++b) { + struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; + int li_charged = b * ns_charged; + int li_neut = b * ns_neut; + for (int i = 0; i < ns_charged; ++i) { + struct gk_species *gks = &sbapp->species[i]; + fin[li_charged + i] = gks->f1; + fout[li_charged + i] = gks->fnew; + // Boundary fluxes. + bflux_in[li_charged + i] = gks->bflux.f1; + bflux_out[li_charged + i] = gks->bflux.fnew; + } + for (int i = 0; i < ns_neut; ++i) { + struct gk_neut_species *gkns = &sbapp->neut_species[i]; + fin_neut[li_neut + i] = gkns->f1; + fout_neut[li_neut + i] = gkns->fnew; + // Boundary fluxes. + bflux_in_neut[li_neut + i] = gkns->bflux.f1; + bflux_out_neut[li_neut + i] = gkns->bflux.fnew; + } + } + + gyrokinetic_multib_forward_euler( + app, tcurr + dt, dt, fin, fout, bflux_in, bflux_out, fin_neut, fout_neut, bflux_in_neut, + bflux_out_neut, &st + ); + + if (st.dt_actual < dt) { + // Recalculate the field. + for (int b = 0; b < nblocks_local; ++b) { struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; int li_charged = b * ns_charged; - int li_neut = b * ns_neut; - for (int i=0; ispecies[i]; - fin[li_charged+i] = gks->f; - fout[li_charged+i] = gks->f1; - // Boundary fluxes. - bflux_in[li_charged+i] = gks->bflux.f; - bflux_out[li_charged+i] = gks->bflux.f1; - } - for (int i=0; ineut_species[i]; - fin_neut[li_neut+i] = gkns->f; - fout_neut[li_neut+i] = gkns->f1; - // Boundary fluxes. - bflux_in_neut[li_neut+i] = gkns->bflux.f; - bflux_out_neut[li_neut+i] = gkns->bflux.f1; + fin[li_charged + i] = gks->f; + bflux_in[li_charged + i] = gks->bflux.f; } } + gyrokinetic_multib_calc_field(app, tcurr, fin, bflux_in); + + // Collect stats. + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], dt_rel_diff); + app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], dt_rel_diff); + app->stat.nstage_2_fail += 1; - gyrokinetic_multib_forward_euler(app, tcurr, dt, fin, fout, bflux_in, bflux_out, - fin_neut, fout_neut, bflux_in_neut, bflux_out_neut, &st); dt = st.dt_actual; + state = RK_STAGE_1; // Restart from stage 1. - // Subtract boundary flux f from f1 so that we only step boundary - // fluxes during a given time step, not over all time. And so that the - // boundary flux in f is kept in case a later RK stage fails. + } else { struct timespec wst = gkyl_wall_clock(); - for (int b=0; bsingleb_apps[b]; - int li_charged = b * ns_charged; - int li_neut = b * ns_neut; - for (int i=0; ispecies[i]; - gk_species_bflux_accumulate(sbapp, &gks->bflux, bflux_out[li_charged+i], -1.0, bflux_in[li_charged+i]); - } - for (int i=0; ineut_species[i]; - gk_neut_species_bflux_accumulate(sbapp, &gkns->bflux, bflux_out_neut[li_neut+i], -1.0, bflux_in_neut[li_neut+i]); + for (int i = 0; i < ns_charged; ++i) { + struct gk_species *gks = &sbapp->species[i]; + gk_species_combine( + gks, gks->f1, 3.0 / 4.0, gks->f, 1.0 / 4.0, gks->fnew, &gks->local_ext + ); + gk_species_bflux_set(sbapp, &gks->bflux, gks->bflux.f1, 1.0 / 4.0, gks->bflux.fnew); + } + for (int i = 0; i < ns_neut; ++i) { + struct gk_neut_species *gkns = &sbapp->neut_species[i]; + gk_neut_species_combine( + gkns, gkns->f1, 3.0 / 4.0, gkns->f, 1.0 / 4.0, gkns->fnew, &gkns->local_ext + ); + gk_neut_species_bflux_set( + sbapp, &gkns->bflux, gkns->bflux.f1, 1.0 / 4.0, gkns->bflux.fnew + ); } } app->stat.time_stepper_arithmetic_tm += gkyl_time_diff_now_sec(wst); - for (int b=0; bsingleb_apps[b]; - for (int i=0; ispecies[i]; - // Compute moment of f_old to later compute moment of df/dt. - // Do it before the fields are updated, but after dt is calculated. - gk_species_calc_int_mom_dt(sbapp, gks, dt, gks->fdot_mom_old); + fout[li_charged + i] = gks->f1; + bflux_out[li_charged + i] = gks->bflux.f1; + } + for (int i = 0; i < ns_neut; ++i) { + fout_neut[li_neut + i] = sbapp->neut_species[i].f1; } - - // Compute field energy divided by dt for energy balance diagnostics. - gk_field_calc_energy_dt(sbapp, sbapp->field, dt, sbapp->field->em_energy_red_old); } - - // Compute the fields and apply BCs. gyrokinetic_multib_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); - state = RK_STAGE_2; - break; + state = RK_STAGE_3; + } + break; + + case RK_STAGE_3: + for (int b = 0; b < nblocks_local; ++b) { + struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; + int li_charged = b * ns_charged; + int li_neut = b * ns_neut; + for (int i = 0; i < ns_charged; ++i) { + struct gk_species *gks = &sbapp->species[i]; + fin[li_charged + i] = gks->f1; + fout[li_charged + i] = gks->fnew; + // Boundary fluxes. + bflux_in[li_charged + i] = gks->bflux.f1; + bflux_out[li_charged + i] = gks->bflux.fnew; + } + for (int i = 0; i < ns_neut; ++i) { + struct gk_neut_species *gkns = &sbapp->neut_species[i]; + fin_neut[li_neut + i] = sbapp->neut_species[i].f1; + fout_neut[li_neut + i] = sbapp->neut_species[i].fnew; + // Boundary fluxes. + bflux_in_neut[li_neut + i] = gkns->bflux.f1; + bflux_out_neut[li_neut + i] = gkns->bflux.fnew; + } + } + + gyrokinetic_multib_forward_euler( + app, tcurr + dt / 2, dt, fin, fout, bflux_in, bflux_out, fin_neut, fout_neut, bflux_in_neut, + bflux_out_neut, &st + ); - case RK_STAGE_2: - for (int b=0; bsingleb_apps[b]; int li_charged = b * ns_charged; - int li_neut = b * ns_neut; - for (int i=0; ispecies[i]; - fin[li_charged+i] = gks->f1; - fout[li_charged+i] = gks->fnew; - // Boundary fluxes. - bflux_in[li_charged+i] = gks->bflux.f1; - bflux_out[li_charged+i] = gks->bflux.fnew; - } - for (int i=0; ineut_species[i]; - fin_neut[li_neut+i] = gkns->f1; - fout_neut[li_neut+i] = gkns->fnew; - // Boundary fluxes. - bflux_in_neut[li_neut+i] = gkns->bflux.f1; - bflux_out_neut[li_neut+i] = gkns->bflux.fnew; + fin[li_charged + i] = gks->f; + bflux_in[li_charged + i] = gks->bflux.f; } } + gyrokinetic_multib_calc_field(app, tcurr, fin, bflux_in); - gyrokinetic_multib_forward_euler(app, tcurr+dt, dt, fin, fout, bflux_in, bflux_out, - fin_neut, fout_neut, bflux_in_neut, bflux_out_neut, &st); + // Collect stats. + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], dt_rel_diff); + app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], dt_rel_diff); + app->stat.nstage_3_fail += 1; - if (st.dt_actual < dt) { + dt = st.dt_actual; + state = RK_STAGE_1; // Restart from stage 1. - // Recalculate the field. - for (int b=0; bsingleb_apps[b]; - int li_charged = b * ns_charged; - for (int i=0; ispecies[i]; - fin[li_charged+i] = gks->f; - bflux_in[li_charged+i] = gks->bflux.f; - } - } - gyrokinetic_multib_calc_field(app, tcurr, fin, bflux_in); - - // Collect stats. - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], - dt_rel_diff); - app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], - dt_rel_diff); - app->stat.nstage_2_fail += 1; - - dt = st.dt_actual; - state = RK_STAGE_1; // Restart from stage 1. - - } - else { - struct timespec wst = gkyl_wall_clock(); - for (int b=0; bsingleb_apps[b]; - for (int i=0; ispecies[i]; - gk_species_combine(gks, gks->f1, 3.0/4.0, gks->f, 1.0/4.0, gks->fnew, &gks->local_ext); - gk_species_bflux_set(sbapp, &gks->bflux, gks->bflux.f1, 1.0/4.0, gks->bflux.fnew); - } - for (int i=0; ineut_species[i]; - gk_neut_species_combine(gkns, gkns->f1, 3.0/4.0, gkns->f, 1.0/4.0, gkns->fnew, &gkns->local_ext); - gk_neut_species_bflux_set(sbapp, &gkns->bflux, gkns->bflux.f1, 1.0/4.0, gkns->bflux.fnew); - } + app->stat.nstage_2_fail += 1; + } else { + struct timespec wst = gkyl_wall_clock(); + for (int b = 0; b < nblocks_local; ++b) { + struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; + for (int i = 0; i < ns_charged; ++i) { + struct gk_species *gks = &sbapp->species[i]; + // Step f. + gk_species_combine( + gks, gks->f1, 1.0 / 3.0, gks->f, 2.0 / 3.0, gks->fnew, &gks->local_ext + ); + gk_species_copy_range(gks, gks->f, gks->f1, &gks->local_ext); + // Step boundary fluxes. + gk_species_bflux_set(sbapp, &gks->bflux, gks->bflux.f, 2.0 / 3.0, gks->bflux.fnew); + gk_species_bflux_calc_voltime_integrated_mom(sbapp, gks, &gks->bflux, tcurr); } - app->stat.time_stepper_arithmetic_tm += gkyl_time_diff_now_sec(wst); - - for (int b=0; bsingleb_apps[b]; - int li_charged = b * ns_charged; - int li_neut = b * ns_neut; - // Compute the fields and apply BCs. - for (int i=0; ispecies[i]; - fout[li_charged+i] = gks->f1; - bflux_out[li_charged+i] = gks->bflux.f1; - } - for (int i=0; ineut_species[i].f1; - } + for (int i = 0; i < ns_neut; ++i) { + struct gk_neut_species *gkns = &sbapp->neut_species[i]; + gk_neut_species_combine( + gkns, gkns->f1, 1.0 / 3.0, gkns->f, 2.0 / 3.0, gkns->fnew, &gkns->local_ext + ); + gk_neut_species_copy_range(gkns, gkns->f, gkns->f1, &gkns->local_ext); + // Step boundary fluxes. + gk_neut_species_bflux_set( + sbapp, &gkns->bflux, gkns->bflux.f, 2.0 / 3.0, gkns->bflux.fnew + ); + gk_neut_species_bflux_calc_voltime_integrated_mom(sbapp, gkns, &gkns->bflux, tcurr); } - gyrokinetic_multib_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); - - state = RK_STAGE_3; } - break; + app->stat.time_stepper_arithmetic_tm += gkyl_time_diff_now_sec(wst); - case RK_STAGE_3: - for (int b=0; bsingleb_apps[b]; - int li_charged = b * ns_charged; - int li_neut = b * ns_neut; - for (int i=0; ispecies[i]; - fin[li_charged+i] = gks->f1; - fout[li_charged+i] = gks->fnew; - // Boundary fluxes. - bflux_in[li_charged+i] = gks->bflux.f1; - bflux_out[li_charged+i] = gks->bflux.fnew; + for (int i = 0; i < ns_charged; ++i) { + struct gk_species *gks = &sbapp->species[i]; + gk_species_positivity_apply(sbapp, gks, &gks->positivity, gks->fnew, gks->f); } - for (int i=0; ineut_species[i]; - fin_neut[li_neut+i] = sbapp->neut_species[i].f1; - fout_neut[li_neut+i] = sbapp->neut_species[i].fnew; - // Boundary fluxes. - bflux_in_neut[li_neut+i] = gkns->bflux.f1; - bflux_out_neut[li_neut+i] = gkns->bflux.fnew; + gk_neut_species_positivity_apply(sbapp, gkns, &gkns->positivity, gkns->fnew, gkns->f); } } - gyrokinetic_multib_forward_euler(app, tcurr+dt/2, dt, fin, fout, bflux_in, bflux_out, - fin_neut, fout_neut, bflux_in_neut, bflux_out_neut, &st); - - if (st.dt_actual < dt) { - // Recalculate the field. - for (int b=0; bsingleb_apps[b]; - int li_charged = b * ns_charged; - for (int i=0; ispecies[i]; - fin[li_charged+i] = gks->f; - bflux_in[li_charged+i] = gks->bflux.f; - } - } - gyrokinetic_multib_calc_field(app, tcurr, fin, bflux_in); - - // Collect stats. - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], - dt_rel_diff); - app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], - dt_rel_diff); - app->stat.nstage_3_fail += 1; - - dt = st.dt_actual; - state = RK_STAGE_1; // Restart from stage 1. - - app->stat.nstage_2_fail += 1; - } - else { - struct timespec wst = gkyl_wall_clock(); - for (int b=0; bsingleb_apps[b]; - for (int i=0; ispecies[i]; - // Step f. - gk_species_combine(gks, gks->f1, 1.0/3.0, gks->f, 2.0/3.0, gks->fnew, &gks->local_ext); - gk_species_copy_range(gks, gks->f, gks->f1, &gks->local_ext); - // Step boundary fluxes. - gk_species_bflux_set(sbapp, &gks->bflux, gks->bflux.f, 2.0/3.0, gks->bflux.fnew); - gk_species_bflux_calc_voltime_integrated_mom(sbapp, gks, &gks->bflux, tcurr); - } - for (int i=0; ineut_species[i]; - gk_neut_species_combine(gkns, gkns->f1, 1.0/3.0, gkns->f, 2.0/3.0, gkns->fnew, &gkns->local_ext); - gk_neut_species_copy_range(gkns, gkns->f, gkns->f1, &gkns->local_ext); - // Step boundary fluxes. - gk_neut_species_bflux_set(sbapp, &gkns->bflux, gkns->bflux.f, 2.0/3.0, gkns->bflux.fnew); - gk_neut_species_bflux_calc_voltime_integrated_mom(sbapp, gkns, &gkns->bflux, tcurr); - } - } - app->stat.time_stepper_arithmetic_tm += gkyl_time_diff_now_sec(wst); - - // Apply positivity shift if requested. - for (int b=0; bsingleb_apps[b]; - for (int i=0; ispecies[i]; - gk_species_positivity_apply(sbapp, gks, &gks->positivity, gks->fnew, gks->f); - } - for (int i=0; ineut_species[i]; - gk_neut_species_positivity_apply(sbapp, gkns, &gkns->positivity, gkns->fnew, gkns->f); - } + for (int b = 0; b < nblocks_local; ++b) { + struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; + int li_charged = b * ns_charged; + int li_neut = b * ns_neut; + for (int i = 0; i < ns_charged; ++i) { + struct gk_species *gks = &sbapp->species[i]; + fout[li_charged + i] = gks->f; + bflux_out[li_charged + i] = gks->bflux.f; } - - for (int b=0; bsingleb_apps[b]; - int li_charged = b * ns_charged; - int li_neut = b * ns_neut; - for (int i=0; ispecies[i]; - fout[li_charged+i] = gks->f; - bflux_out[li_charged+i] = gks->bflux.f; - } - for (int i=0; ineut_species[i].f; - } + for (int i = 0; i < ns_neut; ++i) { + fout_neut[li_neut + i] = sbapp->neut_species[i].f; } + } -// // Enforce quasineutrality of the positivity shifts. -// gyrokinetic_multib_post_positivity_quasineut(app, fout); - - // Compute the fields and apply BCs - gyrokinetic_multib_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); + // // Enforce quasineutrality of the positivity shifts. + // gyrokinetic_multib_post_positivity_quasineut(app, fout); - for (int b=0; bsingleb_apps[b]; - for (int i=0; ispecies[i]; - // Compute moment of f_new to compute moment of df/dt. - // Need to do it after the fields are updated. - gk_species_calc_int_mom_dt(sbapp, gks, dt, gks->fdot_mom_new); - } + // Compute the fields and apply BCs + gyrokinetic_multib_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); - // Compute field energy divided by dt for energy balance diagnostics. - gk_field_calc_energy_dt(sbapp, sbapp->field, dt, sbapp->field->em_energy_red_new); + for (int b = 0; b < nblocks_local; ++b) { + struct gkyl_gyrokinetic_app *sbapp = app->singleb_apps[b]; + for (int i = 0; i < ns_charged; ++i) { + struct gk_species *gks = &sbapp->species[i]; + // Compute moment of f_new to compute moment of df/dt. + // Need to do it after the fields are updated. + gk_species_calc_int_mom_dt(sbapp, gks, dt, gks->fdot_mom_new); } - state = RK_COMPLETE; + // Compute field energy divided by dt for energy balance diagnostics. + gk_field_calc_energy_dt(sbapp, sbapp->field, dt, sbapp->field->em_energy_red_new); } - break; - case RK_COMPLETE: // can't happen: suppresses warning - break; + state = RK_COMPLETE; + } + break; + + case RK_COMPLETE: // can't happen: suppresses warning + break; } } return st; } - - diff --git a/gyrokinetic/apps/gyrokinetic_run.c b/gyrokinetic/apps/gyrokinetic_run.c index 8491792069..285ce0f4a5 100644 --- a/gyrokinetic/apps/gyrokinetic_run.c +++ b/gyrokinetic/apps/gyrokinetic_run.c @@ -28,36 +28,34 @@ struct message_trigs { // // ............. Single block simulations ............... // -// +// // Function pointer types for output handlers. -typedef void (*write_message_pre_update_singleb_t)(const struct gkyl_gyrokinetic_app*, long, double, - struct message_trigs*); -typedef void (*write_message_post_update_singleb_t)(const struct gkyl_gyrokinetic_app*, long, double, - double, struct message_trigs*); +typedef void (*write_message_pre_update_singleb_t)(const struct gkyl_gyrokinetic_app *, long, double, struct message_trigs *); +typedef void (*write_message_post_update_singleb_t)(const struct gkyl_gyrokinetic_app *, long, double, double, struct message_trigs *); // Write log message to console. // Verbose output functions for single-block -static void -write_message_pre_update_verbose_singleb(const struct gkyl_gyrokinetic_app *app, long step, double t_curr, - struct message_trigs *trigs) +static void write_message_pre_update_verbose_singleb( + const struct gkyl_gyrokinetic_app *app, long step, double t_curr, struct message_trigs *trigs +) { if (((step % trigs->io_period) == 0) || step == 1) { gkyl_gyrokinetic_app_cout(app, stdout, "Taking time-step %ld at t = %#11.8g ...", step, t_curr); } } -static void -write_message_post_update_verbose_singleb(const struct gkyl_gyrokinetic_app *app, long step, - double t_curr, double dt_actual, struct message_trigs *trigs) +static void write_message_post_update_verbose_singleb( + const struct gkyl_gyrokinetic_app *app, long step, double t_curr, double dt_actual, + struct message_trigs *trigs +) { if (step == 1) { gkyl_gyrokinetic_app_cout(app, stdout, "\tdt = %.6e\n", dt_actual); - } - else if ((step % trigs->io_period == 0)) { + } else if ((step % trigs->io_period == 0)) { gkyl_gyrokinetic_app_cout(app, stdout, "\tdt = %.6e ", dt_actual); double pct_complete = 100.0 * t_curr / trigs->t_end; - + if (trigs->estimate_completion_time) { double wall_time_elapsed = gkyl_time_diff_now_sec(trigs->tm_loop_start); double sim_time_progressed = t_curr - trigs->t_loop_start; @@ -66,71 +64,75 @@ write_message_post_update_verbose_singleb(const struct gkyl_gyrokinetic_app *app double wall_time_remaining = wall_time_per_sim_time * sim_time_remaining; int hours = (int)(wall_time_remaining / 3600.0); - int minutes = (int)((wall_time_remaining - hours*3600.0) / 60.0); - int seconds = (int)(wall_time_remaining - hours*3600.0 - minutes*60.0); + int minutes = (int)((wall_time_remaining - hours * 3600.0) / 60.0); + int seconds = (int)(wall_time_remaining - hours * 3600.0 - minutes * 60.0); + + gkyl_gyrokinetic_app_cout( + app, stdout, "\t(%.1f%% complete, est. %dh %dm %ds remaining)\n", pct_complete, hours, + minutes, seconds + ); - gkyl_gyrokinetic_app_cout(app, stdout, "\t(%.1f%% complete, est. %dh %dm %ds remaining)\n", - pct_complete, hours, minutes, seconds); - // Reset timing window for next batch trigs->tm_loop_start = gkyl_wall_clock(); trigs->t_loop_start = t_curr; - } - else { + } else { gkyl_gyrokinetic_app_cout(app, stdout, "\t(%.1f%% complete)\n", pct_complete); } } } -static void -write_message_pre_update_nonverbose_singleb(const struct gkyl_gyrokinetic_app *app, long step, double t_curr, - struct message_trigs *trigs) +static void write_message_pre_update_nonverbose_singleb( + const struct gkyl_gyrokinetic_app *app, long step, double t_curr, struct message_trigs *trigs +) { // No output before update in non-verbose mode } -static void -write_message_post_update_nonverbose_singleb(const struct gkyl_gyrokinetic_app *app, long step, - double t_curr, double dt_actual, struct message_trigs *trigs) +static void write_message_post_update_nonverbose_singleb( + const struct gkyl_gyrokinetic_app *app, long step, double t_curr, double dt_actual, + struct message_trigs *trigs +) { if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig, t_curr)) { if (trigs->log_count > 0) { - gkyl_gyrokinetic_app_cout(app, stdout, "\tStep %ld at time %#11.8g. Time-step %.6e. Completed %g%s\n", - step, t_curr, dt_actual, trigs->tenth * 10.0, "%"); - } - else { + gkyl_gyrokinetic_app_cout( + app, stdout, "\tStep %ld at time %#11.8g. Time-step %.6e. Completed %g%s\n", step, + t_curr, dt_actual, trigs->tenth * 10.0, "%" + ); + } else { trigs->log_count += 1; } - + trigs->tenth += 1; - } - else if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig_1p, t_curr)) { + } else if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig_1p, t_curr)) { gkyl_gyrokinetic_app_cout(app, stdout, "%d", trigs->p1c); - trigs->p1c = (trigs->p1c+1) % 10; + trigs->p1c = (trigs->p1c + 1) % 10; fflush(stdout); } } -void -calc_integrated_diagnostics_singleb(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_app* app, - double t_curr, bool is_restart_IC, bool force_calc, double dt) +void calc_integrated_diagnostics_singleb( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_app *app, double t_curr, bool is_restart_IC, + bool force_calc, double dt +) { if (!is_restart_IC && (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_calc)) { gkyl_gyrokinetic_app_calc_field_energy(app, t_curr); gkyl_gyrokinetic_app_calc_integrated_mom(app, t_curr); - if ( !(dt < 0.0) ) { + if (!(dt < 0.0)) { gkyl_gyrokinetic_app_save_dt(app, t_curr, dt); } } } -void -write_data_singleb(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot_phase, - gkyl_gyrokinetic_app* app, double t_curr, bool is_restart_IC, bool force_write) +void write_data_singleb( + struct gkyl_tm_trigger *iot_conf, struct gkyl_tm_trigger *iot_phase, gkyl_gyrokinetic_app *app, + double t_curr, bool is_restart_IC, bool force_write +) { bool trig_now_conf = gkyl_tm_trigger_check_and_bump(iot_conf, t_curr); if (trig_now_conf || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_app_write_conf(app, t_curr, frame); if (!is_restart_IC) { gkyl_gyrokinetic_app_write_field_energy(app); @@ -140,13 +142,12 @@ write_data_singleb(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot } bool trig_now_phase = gkyl_tm_trigger_check_and_bump(iot_phase, t_curr); if (trig_now_phase || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_app_write_phase(app, t_curr, frame); } } -void -gyrokinetic_run_singleb_simulation(struct gkyl_gyrokinetic_run_inp* inp) +void gyrokinetic_run_singleb_simulation(struct gkyl_gyrokinetic_run_inp *inp) { struct gkyl_gyrokinetic_time_stepping_inp time_stepping = inp->time_stepping; struct gkyl_gyrokinetic_run_verbosity_inp verbose = inp->print_verbosity; @@ -157,16 +158,19 @@ gyrokinetic_run_singleb_simulation(struct gkyl_gyrokinetic_run_inp* inp) if (verbose.enabled) { gkyl_gyrokinetic_app_cout(app, stdout, "Gyrokinetic simulation initialized...\n"); } - + double t_curr = 0.0, t_end = time_stepping.t_end; // Initial and final simulation times. int frame_curr = 0; // Initialize simulation. if (time_stepping.is_restart) { - struct gkyl_app_restart_status status = gkyl_gyrokinetic_app_read_from_frame(app, time_stepping.restart_frame); + struct gkyl_app_restart_status status = + gkyl_gyrokinetic_app_read_from_frame(app, time_stepping.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_gyrokinetic_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", - gkyl_array_rio_status_msg(status.io_status)); + gkyl_gyrokinetic_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -175,8 +179,7 @@ gyrokinetic_run_singleb_simulation(struct gkyl_gyrokinetic_run_inp* inp) gkyl_gyrokinetic_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_gyrokinetic_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_gyrokinetic_app_apply_ic(app, t_curr); } @@ -187,19 +190,30 @@ gyrokinetic_run_singleb_simulation(struct gkyl_gyrokinetic_run_inp* inp) // phase trigger -- i.e. frame_curr*(t_end/num_frames) lands on both grids -- so // the same nominal time works for trig_write_conf and trig_write_phase. int num_frames = time_stepping.num_frames, num_int_diag_calc = time_stepping.int_diag_calc_num; - struct gkyl_tm_trigger trig_write_conf = - { .dt = t_end/num_frames, .tcurr = frame_curr * (t_end/num_frames), .curr = frame_curr }; - struct gkyl_tm_trigger trig_write_phase = - { .dt = t_end/(time_stepping.write_phase_freq*num_frames), .tcurr = frame_curr * (t_end/num_frames), .curr = frame_curr}; - struct gkyl_tm_trigger trig_calc_intdiag = - { .dt = t_end/GKYL_MAX2(num_frames, num_int_diag_calc), .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger trig_write_conf = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; + struct gkyl_tm_trigger trig_write_phase = { + .dt = t_end / (time_stepping.write_phase_freq * num_frames), + .tcurr = frame_curr * (t_end / num_frames), + .curr = frame_curr + }; + struct gkyl_tm_trigger trig_calc_intdiag = { + .dt = t_end / GKYL_MAX2(num_frames, num_int_diag_calc), .tcurr = t_curr, .curr = frame_curr + }; // Write out ICs (if restart, it overwrites the restart frame). - calc_integrated_diagnostics_singleb(&trig_calc_intdiag, app, t_curr, time_stepping.is_restart, false, -1.0); - write_data_singleb(&trig_write_conf, &trig_write_phase, app, t_curr, time_stepping.is_restart, false); + calc_integrated_diagnostics_singleb( + &trig_calc_intdiag, app, t_curr, time_stepping.is_restart, false, -1.0 + ); + write_data_singleb( + &trig_write_conf, &trig_write_phase, app, t_curr, time_stepping.is_restart, false + ); if (verbose.enabled) { - gkyl_gyrokinetic_app_cout(app, stdout, "Initialization completed in %g sec\n\n", gkyl_time_diff_now_sec(tm_init)); + gkyl_gyrokinetic_app_cout( + app, stdout, "Initialization completed in %g sec\n\n", gkyl_time_diff_now_sec(tm_init) + ); } // Compute initial guess of maximum stable time-step. @@ -212,15 +226,15 @@ gyrokinetic_run_singleb_simulation(struct gkyl_gyrokinetic_run_inp* inp) // Set up function pointers based on verbosity mode struct message_trigs m_trig = { .log_count = 0, - .tenth = t_curr > 0.0 ? (int) floor(t_curr / t_end * 10.0) : 0.0, - .p1c = t_curr > 0.0 ? (int) floor(t_curr / t_end * 100.0) % 10 : 0.0, - .log_trig = { .dt = t_end / 10.0, .tcurr = t_curr }, - .log_trig_1p = { .dt = t_end / 100.0, .tcurr = t_curr }, - .io_period = (long)(1/verbose.frequency), + .tenth = t_curr > 0.0 ? (int)floor(t_curr / t_end * 10.0) : 0.0, + .p1c = t_curr > 0.0 ? (int)floor(t_curr / t_end * 100.0) % 10 : 0.0, + .log_trig = {.dt = t_end / 10.0, .tcurr = t_curr}, + .log_trig_1p = {.dt = t_end / 100.0, .tcurr = t_curr}, + .io_period = (long)(1 / verbose.frequency), .t_end = t_end, .estimate_completion_time = verbose.estimate_completion_time, .tm_loop_start = gkyl_wall_clock(), - .t_loop_start = t_curr, + .t_loop_start = t_curr }; write_message_pre_update_singleb_t write_message_pre_update; @@ -229,8 +243,7 @@ gyrokinetic_run_singleb_simulation(struct gkyl_gyrokinetic_run_inp* inp) if (verbose.enabled) { write_message_pre_update = write_message_pre_update_verbose_singleb; write_message_post_update = write_message_post_update_verbose_singleb; - } - else { + } else { write_message_pre_update = write_message_pre_update_nonverbose_singleb; write_message_post_update = write_message_post_update_nonverbose_singleb; } @@ -251,89 +264,106 @@ gyrokinetic_run_singleb_simulation(struct gkyl_gyrokinetic_run_inp* inp) write_message_post_update(app, step, t_curr, status.dt_actual, &m_trig); - calc_integrated_diagnostics_singleb(&trig_calc_intdiag, app, t_curr, false, t_curr > t_end, status.dt_actual); + calc_integrated_diagnostics_singleb( + &trig_calc_intdiag, app, t_curr, false, t_curr > t_end, status.dt_actual + ); write_data_singleb(&trig_write_conf, &trig_write_phase, app, t_curr, false, t_curr > t_end); if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_gyrokinetic_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); gkyl_gyrokinetic_app_cout(app, stdout, " is below %g*dt_init ...", dt_failure_tol); gkyl_gyrokinetic_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { - gkyl_gyrokinetic_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_gyrokinetic_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); - calc_integrated_diagnostics_singleb(&trig_calc_intdiag, app, t_curr, false, true, status.dt_actual); + gkyl_gyrokinetic_app_cout( + app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); + calc_integrated_diagnostics_singleb( + &trig_calc_intdiag, app, t_curr, false, true, status.dt_actual + ); write_data_singleb(&trig_write_conf, &trig_write_phase, app, t_curr, false, true); break; } - } - else { + } else { num_failures = 0; } step += 1; } - + gkyl_gyrokinetic_app_stat_write(app); - + // Fetch simulation statistics. struct gkyl_gyrokinetic_stat stat = gkyl_gyrokinetic_app_stat(app); if (verbose.disable_timings == true) { gkyl_gyrokinetic_app_cout(app, stdout, "\n"); - gkyl_gyrokinetic_app_cout(app, stdout, "Total simulation time: %g sec\n", gkyl_time_diff_now_sec(tm_init)); + gkyl_gyrokinetic_app_cout( + app, stdout, "Total simulation time: %g sec\n", gkyl_time_diff_now_sec(tm_init) + ); } else { gkyl_gyrokinetic_app_cout(app, stdout, "\n"); gkyl_gyrokinetic_app_cout(app, stdout, "Number of update calls %ld\n", stat.nup); gkyl_gyrokinetic_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); - gkyl_gyrokinetic_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail + ); if (stat.nstage_2_fail > 0) { - gkyl_gyrokinetic_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_gyrokinetic_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } - gkyl_gyrokinetic_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); + gkyl_gyrokinetic_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_gyrokinetic_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } + gkyl_gyrokinetic_app_cout( + app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail + ); gkyl_gyrokinetic_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_gyrokinetic_app_print_timings(app, stdout); } - freeresources: +freeresources: gkyl_gyrokinetic_app_release(app); } // // ............. Multi-block simulations ............... // -// +// -typedef void (*write_message_pre_update_multib_t)(const struct gkyl_gyrokinetic_multib_app*, - long, double, struct message_trigs*); -typedef void (*write_message_post_update_multib_t)(const struct gkyl_gyrokinetic_multib_app*, - long, double, double, struct message_trigs*); +typedef void (*write_message_pre_update_multib_t)(const struct gkyl_gyrokinetic_multib_app *, long, double, struct message_trigs *); +typedef void (*write_message_post_update_multib_t)(const struct gkyl_gyrokinetic_multib_app *, long, double, double, struct message_trigs *); // Verbose output functions for multi-block -static void -write_message_pre_update_verbose_multib(const struct gkyl_gyrokinetic_multib_app *app, long step, - double t_curr, struct message_trigs *trigs) +static void write_message_pre_update_verbose_multib( + const struct gkyl_gyrokinetic_multib_app *app, long step, double t_curr, + struct message_trigs *trigs +) { if (((step % trigs->io_period) == 0) || step == 1) { - gkyl_gyrokinetic_multib_app_cout(app, stdout, "Taking time-step %ld at t = %#11.8g ...", step, t_curr); + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "Taking time-step %ld at t = %#11.8g ...", step, t_curr + ); } } -static void -write_message_post_update_verbose_multib(const struct gkyl_gyrokinetic_multib_app *app, long step, - double t_curr, double dt_actual, struct message_trigs *trigs) +static void write_message_post_update_verbose_multib( + const struct gkyl_gyrokinetic_multib_app *app, long step, double t_curr, double dt_actual, + struct message_trigs *trigs +) { if (step == 1) { gkyl_gyrokinetic_multib_app_cout(app, stdout, "\tdt = %.6e\n", dt_actual); - } - else if ((step % trigs->io_period == 0)) { + } else if ((step % trigs->io_period == 0)) { gkyl_gyrokinetic_multib_app_cout(app, stdout, "\tdt = %.6e ", dt_actual); double pct_complete = 100.0 * t_curr / trigs->t_end; - + if (trigs->estimate_completion_time) { double wall_time_elapsed = gkyl_time_diff_now_sec(trigs->tm_loop_start); double sim_time_progressed = t_curr - trigs->t_loop_start; @@ -342,70 +372,76 @@ write_message_post_update_verbose_multib(const struct gkyl_gyrokinetic_multib_ap double wall_time_remaining = wall_time_per_sim_time * sim_time_remaining; int hours = (int)(wall_time_remaining / 3600.0); - int minutes = (int)((wall_time_remaining - hours*3600.0) / 60.0); - int seconds = (int)(wall_time_remaining - hours*3600.0 - minutes*60.0); + int minutes = (int)((wall_time_remaining - hours * 3600.0) / 60.0); + int seconds = (int)(wall_time_remaining - hours * 3600.0 - minutes * 60.0); + + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "\t(%.1f%% complete, est. %dh %dm %ds remaining)\n", pct_complete, hours, + minutes, seconds + ); - gkyl_gyrokinetic_multib_app_cout(app, stdout, "\t(%.1f%% complete, est. %dh %dm %ds remaining)\n", - pct_complete, hours, minutes, seconds); - // Reset timing window for next batch trigs->tm_loop_start = gkyl_wall_clock(); trigs->t_loop_start = t_curr; - } - else { + } else { gkyl_gyrokinetic_multib_app_cout(app, stdout, "\t(%.1f%% complete)\n", pct_complete); } } } -static void -write_message_pre_update_nonverbose_multib(const struct gkyl_gyrokinetic_multib_app *app, long step, - double t_curr, struct message_trigs *trigs) +static void write_message_pre_update_nonverbose_multib( + const struct gkyl_gyrokinetic_multib_app *app, long step, double t_curr, + struct message_trigs *trigs +) { // No output before update in non-verbose mode } -static void -write_message_post_update_nonverbose_multib(const struct gkyl_gyrokinetic_multib_app *app, long step, - double t_curr, double dt_actual, struct message_trigs *trigs) +static void write_message_post_update_nonverbose_multib( + const struct gkyl_gyrokinetic_multib_app *app, long step, double t_curr, double dt_actual, + struct message_trigs *trigs +) { if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig, t_curr)) { if (trigs->log_count > 0) { - gkyl_gyrokinetic_multib_app_cout(app, stdout, "\tStep %ld at time %#11.8g. Time-step %.6e. Completed %g%s\n", - step, t_curr, dt_actual, trigs->tenth * 10.0, "%"); - } - else { + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "\tStep %ld at time %#11.8g. Time-step %.6e. Completed %g%s\n", step, + t_curr, dt_actual, trigs->tenth * 10.0, "%" + ); + } else { trigs->log_count += 1; } - + trigs->tenth += 1; - } - else if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig_1p, t_curr)) { + } else if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig_1p, t_curr)) { gkyl_gyrokinetic_multib_app_cout(app, stdout, "%d", trigs->p1c); - trigs->p1c = (trigs->p1c+1) % 10; + trigs->p1c = (trigs->p1c + 1) % 10; fflush(stdout); } } -void -calc_integrated_diagnostics_multib(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_multib_app* app, - double t_curr, bool is_restart_IC, bool force_calc, double dt) +void calc_integrated_diagnostics_multib( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_multib_app *app, double t_curr, bool is_restart_IC, + bool force_calc, double dt +) { if (!is_restart_IC && (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_calc)) { gkyl_gyrokinetic_multib_app_calc_field_energy(app, t_curr); gkyl_gyrokinetic_multib_app_calc_integrated_mom(app, t_curr); - if ( !(dt < 0.0) ) + if (!(dt < 0.0)) { gkyl_gyrokinetic_multib_app_save_dt(app, t_curr, dt); + } } } -void -write_data_multib(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot_phase, - gkyl_gyrokinetic_multib_app* app, double t_curr, bool is_restart_IC, bool force_write) +void write_data_multib( + struct gkyl_tm_trigger *iot_conf, struct gkyl_tm_trigger *iot_phase, + gkyl_gyrokinetic_multib_app *app, double t_curr, bool is_restart_IC, bool force_write +) { bool trig_now_conf = gkyl_tm_trigger_check_and_bump(iot_conf, t_curr); if (trig_now_conf || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_multib_app_write_conf(app, t_curr, frame); if (!is_restart_IC) { gkyl_gyrokinetic_multib_app_write_field_energy(app); @@ -415,13 +451,12 @@ write_data_multib(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot_ } bool trig_now_phase = gkyl_tm_trigger_check_and_bump(iot_phase, t_curr); if (trig_now_phase || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_multib_app_write_phase(app, t_curr, frame); } } -void -gyrokinetic_run_multib_simulation(struct gkyl_gyrokinetic_run_inp* inp) +void gyrokinetic_run_multib_simulation(struct gkyl_gyrokinetic_run_inp *inp) { struct gkyl_gyrokinetic_time_stepping_inp time_stepping = inp->time_stepping; struct gkyl_gyrokinetic_run_verbosity_inp verbose = inp->print_verbosity; @@ -437,11 +472,14 @@ gyrokinetic_run_multib_simulation(struct gkyl_gyrokinetic_run_inp* inp) int frame_curr = 0; // Initialize simulation. if (time_stepping.is_restart) { - struct gkyl_app_restart_status status = gkyl_gyrokinetic_multib_app_read_from_frame(app, time_stepping.restart_frame); + struct gkyl_app_restart_status status = + gkyl_gyrokinetic_multib_app_read_from_frame(app, time_stepping.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_gyrokinetic_multib_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", - gkyl_array_rio_status_msg(status.io_status)); + gkyl_gyrokinetic_multib_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -450,8 +488,7 @@ gyrokinetic_run_multib_simulation(struct gkyl_gyrokinetic_run_inp* inp) gkyl_gyrokinetic_multib_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_gyrokinetic_multib_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_gyrokinetic_multib_app_apply_ic(app, t_curr); } @@ -462,20 +499,30 @@ gyrokinetic_run_multib_simulation(struct gkyl_gyrokinetic_run_inp* inp) // phase trigger -- i.e. frame_curr*(t_end/num_frames) lands on both grids -- so // the same nominal time works for trig_write_conf and trig_write_phase. int num_frames = time_stepping.num_frames, num_int_diag_calc = time_stepping.int_diag_calc_num; - struct gkyl_tm_trigger trig_write_conf = - { .dt = t_end/num_frames, .tcurr = frame_curr * (t_end/num_frames), .curr = frame_curr }; - struct gkyl_tm_trigger trig_write_phase = - { .dt = t_end/(time_stepping.write_phase_freq*num_frames), .tcurr = frame_curr * (t_end/num_frames), .curr = frame_curr}; - struct gkyl_tm_trigger trig_calc_intdiag = - { .dt = t_end/GKYL_MAX2(num_frames, num_int_diag_calc), .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger trig_write_conf = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; + struct gkyl_tm_trigger trig_write_phase = { + .dt = t_end / (time_stepping.write_phase_freq * num_frames), + .tcurr = frame_curr * (t_end / num_frames), + .curr = frame_curr + }; + struct gkyl_tm_trigger trig_calc_intdiag = { + .dt = t_end / GKYL_MAX2(num_frames, num_int_diag_calc), .tcurr = t_curr, .curr = frame_curr + }; // Write out ICs (if restart, it overwrites the restart frame). - calc_integrated_diagnostics_multib(&trig_calc_intdiag, app, t_curr, time_stepping.is_restart, false, -1.0); - write_data_multib(&trig_write_conf, &trig_write_phase, app, t_curr, time_stepping.is_restart, false); + calc_integrated_diagnostics_multib( + &trig_calc_intdiag, app, t_curr, time_stepping.is_restart, false, -1.0 + ); + write_data_multib( + &trig_write_conf, &trig_write_phase, app, t_curr, time_stepping.is_restart, false + ); if (verbose.enabled) { - gkyl_gyrokinetic_multib_app_cout(app, stdout, "Initialization completed in %g sec\n\n", - gkyl_time_diff_now_sec(tm_init)); + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "Initialization completed in %g sec\n\n", gkyl_time_diff_now_sec(tm_init) + ); } // Compute initial guess of maximum stable time-step. @@ -488,11 +535,11 @@ gyrokinetic_run_multib_simulation(struct gkyl_gyrokinetic_run_inp* inp) // Set up function pointers based on verbosity mode struct message_trigs m_trig = { .log_count = 0, - .tenth = t_curr > 0.0 ? (int) floor(t_curr / t_end * 10.0) : 0.0, - .p1c = t_curr > 0.0 ? (int) floor(t_curr / t_end * 100.0) % 10 : 0.0, - .log_trig = { .dt = t_end / 10.0, .tcurr = t_curr }, - .log_trig_1p = { .dt = t_end / 100.0, .tcurr = t_curr }, - .io_period = (long)(1/verbose.frequency), + .tenth = t_curr > 0.0 ? (int)floor(t_curr / t_end * 10.0) : 0.0, + .p1c = t_curr > 0.0 ? (int)floor(t_curr / t_end * 100.0) % 10 : 0.0, + .log_trig = {.dt = t_end / 10.0, .tcurr = t_curr}, + .log_trig_1p = {.dt = t_end / 100.0, .tcurr = t_curr}, + .io_period = (long)(1 / verbose.frequency), .t_end = t_end, .estimate_completion_time = verbose.estimate_completion_time, .tm_loop_start = gkyl_wall_clock(), @@ -501,12 +548,11 @@ gyrokinetic_run_multib_simulation(struct gkyl_gyrokinetic_run_inp* inp) write_message_pre_update_multib_t write_message_pre_update; write_message_post_update_multib_t write_message_post_update; - + if (verbose.enabled) { write_message_pre_update = write_message_pre_update_verbose_multib; write_message_post_update = write_message_post_update_verbose_multib; - } - else { + } else { write_message_pre_update = write_message_pre_update_nonverbose_multib; write_message_post_update = write_message_post_update_nonverbose_multib; } @@ -518,7 +564,9 @@ gyrokinetic_run_multib_simulation(struct gkyl_gyrokinetic_run_inp* inp) struct gkyl_update_status status = gkyl_gyrokinetic_multib_update(app, dt); if (!status.success) { - gkyl_gyrokinetic_multib_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "** Update method failed! Aborting simulation ....\n" + ); break; } t_curr += status.dt_actual; @@ -526,27 +574,33 @@ gyrokinetic_run_multib_simulation(struct gkyl_gyrokinetic_run_inp* inp) write_message_post_update(app, step, t_curr, status.dt_actual, &m_trig); - calc_integrated_diagnostics_multib(&trig_calc_intdiag, app, t_curr, false, t_curr > t_end, status.dt_actual); + calc_integrated_diagnostics_multib( + &trig_calc_intdiag, app, t_curr, false, t_curr > t_end, status.dt_actual + ); write_data_multib(&trig_write_conf, &trig_write_phase, app, t_curr, false, t_curr > t_end); if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_gyrokinetic_multib_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); gkyl_gyrokinetic_multib_app_cout(app, stdout, " is below %g*dt_init ...", dt_failure_tol); gkyl_gyrokinetic_multib_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { - gkyl_gyrokinetic_multib_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_gyrokinetic_multib_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); - calc_integrated_diagnostics_multib(&trig_calc_intdiag, app, t_curr, false, true, status.dt_actual); + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol + ); + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); + calc_integrated_diagnostics_multib( + &trig_calc_intdiag, app, t_curr, false, true, status.dt_actual + ); write_data_multib(&trig_write_conf, &trig_write_phase, app, t_curr, false, true); break; } - } - else { + } else { num_failures = 0; } step += 1; @@ -559,38 +613,48 @@ gyrokinetic_run_multib_simulation(struct gkyl_gyrokinetic_run_inp* inp) if (verbose.disable_timings == true) { gkyl_gyrokinetic_multib_app_cout(app, stdout, "\n"); - gkyl_gyrokinetic_multib_app_cout(app, stdout, "Total simulation time: %g sec\n", gkyl_time_diff_now_sec(tm_init)); + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "Total simulation time: %g sec\n", gkyl_time_diff_now_sec(tm_init) + ); } else { gkyl_gyrokinetic_multib_app_cout(app, stdout, "\n"); gkyl_gyrokinetic_multib_app_cout(app, stdout, "Number of update calls %ld\n", stat.nup); - gkyl_gyrokinetic_multib_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); - gkyl_gyrokinetic_multib_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler + ); + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail + ); if (stat.nstage_2_fail > 0) { - gkyl_gyrokinetic_multib_app_cout(app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_gyrokinetic_multib_app_cout(app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); } - gkyl_gyrokinetic_multib_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); + gkyl_gyrokinetic_multib_app_cout( + app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail + ); gkyl_gyrokinetic_multib_app_cout(app, stdout, "Number of write calls %ld.\n", stat.n_io); gkyl_gyrokinetic_multib_app_print_timings(app, stdout); } - freeresources: +freeresources: gkyl_gyrokinetic_multib_app_release(app); } -void -gkyl_gyrokinetic_run_simulation(struct gkyl_gyrokinetic_run_inp* inp) +void gkyl_gyrokinetic_run_simulation(struct gkyl_gyrokinetic_run_inp *inp) { - if (inp->print_verbosity.frequency == 0.0) + if (inp->print_verbosity.frequency == 0.0) { inp->print_verbosity.frequency = 0.1; // Default to logging every 10 steps. + } if (inp->app_type == GKYL_GK_SINGLEB) { gyrokinetic_run_singleb_simulation(inp); - } - else if (inp->app_type == GKYL_GK_MULTIB) { + } else if (inp->app_type == GKYL_GK_MULTIB) { gyrokinetic_run_multib_simulation(inp); - } - else { + } else { gkyl_exit("gyrokinetic_run: No valid application input provided to run simulation."); } } \ No newline at end of file diff --git a/gyrokinetic/apps/gyrokinetic_update_implicit_coll.c b/gyrokinetic/apps/gyrokinetic_update_implicit_coll.c index f5aad7898d..ab7ccb2186 100644 --- a/gyrokinetic/apps/gyrokinetic_update_implicit_coll.c +++ b/gyrokinetic/apps/gyrokinetic_update_implicit_coll.c @@ -1,36 +1,35 @@ #include // Take time-step using an implicit method for collisions. -// Use the actual timestep used to update explicit advection. -void -gyrokinetic_update_implicit_coll(gkyl_gyrokinetic_app* app, double dt0) +// Use the actual timestep used to update explicit advection. +void gyrokinetic_update_implicit_coll(gkyl_gyrokinetic_app *app, double dt0) { // Add contribution from implicit collision terms. double tcurr = app->tcurr, dt = dt0; - struct gkyl_update_status st = { .success = true }; + struct gkyl_update_status st = {.success = true}; - const int ns = app->num_species; + const int ns = app->num_species; struct gkyl_array *fin[ns]; struct gkyl_array *fout[ns]; struct gkyl_array **bflux_in[ns]; struct gkyl_array **bflux_out[ns]; - const int neuts = app->num_neut_species; + const int neuts = app->num_neut_species; struct gkyl_array *fin_neut[neuts]; struct gkyl_array *fout_neut[neuts]; struct gkyl_array **bflux_in_neut[ns]; struct gkyl_array **bflux_out_neut[ns]; // Fetch input and output arrays. - for (int i=0; ispecies[i]; fin[i] = gks->f; fout[i] = gks->f1; bflux_in[i] = gks->bflux.f; bflux_out[i] = gks->bflux.f; } - for (int i=0; ineut_species[i]; fin_neut[i] = gkns->f; fout_neut[i] = gkns->f1; @@ -39,16 +38,18 @@ gyrokinetic_update_implicit_coll(gkyl_gyrokinetic_app* app, double dt0) } // Compute df/dt from implicit terms. - gyrokinetic_rhs_implicit(app, tcurr, dt, fin, fout, bflux_out, fin_neut, fout_neut, bflux_out_neut, &st); + gyrokinetic_rhs_implicit( + app, tcurr, dt, fin, fout, bflux_out, fin_neut, fout_neut, bflux_out_neut, &st + ); // Apply boundary conditions and copy solution. gyrokinetic_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); - for (int i=0; ispecies[i]; gk_species_copy_range(gks, fin[i], fout[i], &gks->local_ext); } - for (int i=0; ineut_species[i]; gk_neut_species_copy_range(gkns, fin_neut[i], fout_neut[i], &gkns->local_ext); }; diff --git a/gyrokinetic/apps/gyrokinetic_update_op_split.c b/gyrokinetic/apps/gyrokinetic_update_op_split.c index 10cad95137..59f38a1712 100644 --- a/gyrokinetic/apps/gyrokinetic_update_op_split.c +++ b/gyrokinetic/apps/gyrokinetic_update_op_split.c @@ -3,8 +3,7 @@ // Take time-step using the SSP-RK3 method for the hyperbolic components // Then, we use the actual timestep taken with the SSP-RK3 method to update // BGK collisions implicitly. -struct gkyl_update_status -gyrokinetic_update_op_split(gkyl_gyrokinetic_app* app, double dt0) +struct gkyl_update_status gyrokinetic_update_op_split(gkyl_gyrokinetic_app *app, double dt0) { struct gkyl_update_status st = gyrokinetic_update_ssp_rk3(app, dt0); diff --git a/gyrokinetic/apps/gyrokinetic_update_ssp_rk3.c b/gyrokinetic/apps/gyrokinetic_update_ssp_rk3.c index 18a1a7e7a2..2f1f4f7fcf 100644 --- a/gyrokinetic/apps/gyrokinetic_update_ssp_rk3.c +++ b/gyrokinetic/apps/gyrokinetic_update_ssp_rk3.c @@ -1,14 +1,13 @@ #include -static void -gyrokinetic_forward_euler(gkyl_gyrokinetic_app* app, double tcurr, double dt, - const struct gkyl_array *fin[], struct gkyl_array *fout[], - struct gkyl_array **bflux_in[], struct gkyl_array **bflux_out[], - const struct gkyl_array *fin_neut[], struct gkyl_array *fout_neut[], - struct gkyl_array **bflux_in_neut[], struct gkyl_array **bflux_out_neut[], - struct gkyl_update_status *st) +static void gyrokinetic_forward_euler( + gkyl_gyrokinetic_app *app, double tcurr, double dt, const struct gkyl_array *fin[], + struct gkyl_array *fout[], struct gkyl_array **bflux_in[], struct gkyl_array **bflux_out[], + const struct gkyl_array *fin_neut[], struct gkyl_array *fout_neut[], + struct gkyl_array **bflux_in_neut[], struct gkyl_array **bflux_out_neut[], + struct gkyl_update_status *st +) { - struct timespec wst_fe = gkyl_wall_clock(); // Take a forward Euler step with the suggested time-step dt. This may // not be the actual time-step taken. However, the function will never @@ -23,23 +22,21 @@ gyrokinetic_forward_euler(gkyl_gyrokinetic_app* app, double tcurr, double dt, struct timespec wst = gkyl_wall_clock(); // Complete update of distribution functions. double dta = st->dt_actual; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gks = &app->species[i]; gk_species_step_f(gks, fout[i], dta, fin[i]); gk_species_bflux_accumulate(app, &gks->bflux, bflux_out[i], 1.0, bflux_in[i]); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { struct gk_neut_species *gkns = &app->neut_species[i]; gk_neut_species_step_f(gkns, fout_neut[i], dta, fin_neut[i]); gk_neut_species_bflux_accumulate(app, &gkns->bflux, bflux_out_neut[i], 1.0, bflux_in_neut[i]); } app->stat.fwd_euler_step_f_tm += gkyl_time_diff_now_sec(wst); app->stat.fwd_euler_tm += gkyl_time_diff_now_sec(wst_fe); - } -struct gkyl_update_status -gyrokinetic_update_ssp_rk3(gkyl_gyrokinetic_app* app, double dt0) +struct gkyl_update_status gyrokinetic_update_ssp_rk3(gkyl_gyrokinetic_app *app, double dt0) { // Take time-step using the RK3 method. Also sets the status object // which has the actual and suggested dts used. These can be different @@ -54,7 +51,7 @@ gyrokinetic_update_ssp_rk3(gkyl_gyrokinetic_app* app, double dt0) struct gkyl_array **bflux_in_neut[app->num_neut_species]; struct gkyl_array **bflux_out_neut[app->num_neut_species]; - struct gkyl_update_status st = { .success = true }; + struct gkyl_update_status st = {.success = true}; // time-stepper state enum { RK_STAGE_1, RK_STAGE_2, RK_STAGE_3, RK_COMPLETE } state = RK_STAGE_1; @@ -62,252 +59,257 @@ gyrokinetic_update_ssp_rk3(gkyl_gyrokinetic_app* app, double dt0) double tcurr = app->tcurr, dt = dt0; while (state != RK_COMPLETE) { switch (state) { - case RK_STAGE_1: - for (int i=0; inum_species; ++i) { + case RK_STAGE_1: + for (int i = 0; i < app->num_species; ++i) { + struct gk_species *gks = &app->species[i]; + fin[i] = gks->f; + fout[i] = gks->f1; + // Boundary fluxes. + bflux_in[i] = gks->bflux.f; + bflux_out[i] = gks->bflux.f1; + } + for (int i = 0; i < app->num_neut_species; ++i) { + struct gk_neut_species *gkns = &app->neut_species[i]; + fin_neut[i] = gkns->f; + fout_neut[i] = gkns->f1; + // Boundary fluxes. + bflux_in_neut[i] = gkns->bflux.f; + bflux_out_neut[i] = gkns->bflux.f1; + } + + for (int i = 0; i < app->num_species; ++i) { + struct gk_species *gks = &app->species[i]; + // Adapt sources. + gk_species_source_adapt(app, gks, &gks->src, gks->lte.f_lte, bflux_in, tcurr); + } + + gyrokinetic_forward_euler( + app, tcurr, dt, fin, fout, bflux_in, bflux_out, fin_neut, fout_neut, bflux_in_neut, + bflux_out_neut, &st + ); + dt = st.dt_actual; + + // Subtract boundary flux f from f1 so that we only step boundary + // fluxes during a given time step, not over all time. And so that the + // boundary flux in f is kept in case a later RK stage fails. + struct timespec wst = gkyl_wall_clock(); + for (int i = 0; i < app->num_species; ++i) { + struct gk_species *gks = &app->species[i]; + gk_species_bflux_accumulate(app, &gks->bflux, bflux_out[i], -1.0, bflux_in[i]); + } + for (int i = 0; i < app->num_neut_species; ++i) { + struct gk_neut_species *gkns = &app->neut_species[i]; + gk_neut_species_bflux_accumulate( + app, &gkns->bflux, bflux_out_neut[i], -1.0, bflux_in_neut[i] + ); + } + app->stat.time_stepper_arithmetic_tm += gkyl_time_diff_now_sec(wst); + + for (int i = 0; i < app->num_species; ++i) { + struct gk_species *gks = &app->species[i]; + // Compute moment of f_old to later compute moment of df/dt. + // Do it before the fields are updated, but after dt is calculated. + gk_species_calc_int_mom_dt(app, gks, dt, gks->fdot_mom_old); + } + + // Compute field energy divided by dt for energy balance diagnostics. + gk_field_calc_energy_dt(app, app->field, dt, app->field->em_energy_red_old); + + // Compute the fields and apply BCs. + gyrokinetic_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); + + state = RK_STAGE_2; + break; + + case RK_STAGE_2: + for (int i = 0; i < app->num_species; ++i) { + struct gk_species *gks = &app->species[i]; + fin[i] = gks->f1; + fout[i] = gks->fnew; + // Boundary fluxes. + bflux_in[i] = gks->bflux.f1; + bflux_out[i] = gks->bflux.fnew; + } + for (int i = 0; i < app->num_neut_species; ++i) { + struct gk_neut_species *gkns = &app->neut_species[i]; + fin_neut[i] = gkns->f1; + fout_neut[i] = gkns->fnew; + // Boundary fluxes. + bflux_in_neut[i] = gkns->bflux.f1; + bflux_out_neut[i] = gkns->bflux.fnew; + } + + gyrokinetic_forward_euler( + app, tcurr + dt, dt, fin, fout, bflux_in, bflux_out, fin_neut, fout_neut, bflux_in_neut, + bflux_out_neut, &st + ); + + if (st.dt_actual < dt) { + // Recalculate the field. + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gks = &app->species[i]; fin[i] = gks->f; - fout[i] = gks->f1; - // Boundary fluxes. bflux_in[i] = gks->bflux.f; - bflux_out[i] = gks->bflux.f1; - } - for (int i=0; inum_neut_species; ++i) { - struct gk_neut_species *gkns = &app->neut_species[i]; - fin_neut[i] = gkns->f; - fout_neut[i] = gkns->f1; - // Boundary fluxes. - bflux_in_neut[i] = gkns->bflux.f; - bflux_out_neut[i] = gkns->bflux.f1; } + gyrokinetic_calc_field(app, tcurr, fin, bflux_in); - for (int i=0; inum_species; ++i) { - struct gk_species *gks = &app->species[i]; - // Adapt sources. - gk_species_source_adapt(app, gks, &gks->src, gks->lte.f_lte, bflux_in, tcurr); - } + // Collect stats. + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], dt_rel_diff); + app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], dt_rel_diff); + app->stat.nstage_2_fail += 1; - gyrokinetic_forward_euler(app, tcurr, dt, fin, fout, bflux_in, bflux_out, - fin_neut, fout_neut, bflux_in_neut, bflux_out_neut, &st); dt = st.dt_actual; + state = RK_STAGE_1; // Restart from stage 1. - // Subtract boundary flux f from f1 so that we only step boundary - // fluxes during a given time step, not over all time. And so that the - // boundary flux in f is kept in case a later RK stage fails. + } else { struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gks = &app->species[i]; - gk_species_bflux_accumulate(app, &gks->bflux, bflux_out[i], -1.0, bflux_in[i]); + gk_species_combine(gks, gks->f1, 3.0 / 4.0, gks->f, 1.0 / 4.0, gks->fnew, &gks->local_ext); + gk_species_bflux_set(app, &gks->bflux, gks->bflux.f1, 1.0 / 4.0, gks->bflux.fnew); } - for (int i=0; inum_neut_species; ++i) { + for (int i = 0; i < app->num_neut_species; ++i) { struct gk_neut_species *gkns = &app->neut_species[i]; - gk_neut_species_bflux_accumulate(app, &gkns->bflux, bflux_out_neut[i], -1.0, bflux_in_neut[i]); + gk_neut_species_combine( + gkns, gkns->f1, 3.0 / 4.0, gkns->f, 1.0 / 4.0, gkns->fnew, &gkns->local_ext + ); + gk_neut_species_bflux_set(app, &gkns->bflux, gkns->bflux.f1, 1.0 / 4.0, gkns->bflux.fnew); } app->stat.time_stepper_arithmetic_tm += gkyl_time_diff_now_sec(wst); - for (int i=0; inum_species; ++i) { + // Compute the fields and apply BCs. + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gks = &app->species[i]; - // Compute moment of f_old to later compute moment of df/dt. - // Do it before the fields are updated, but after dt is calculated. - gk_species_calc_int_mom_dt(app, gks, dt, gks->fdot_mom_old); + fout[i] = gks->f1; + bflux_out[i] = gks->bflux.f1; + } + for (int i = 0; i < app->num_neut_species; ++i) { + fout_neut[i] = app->neut_species[i].f1; } + gyrokinetic_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); - // Compute field energy divided by dt for energy balance diagnostics. - gk_field_calc_energy_dt(app, app->field, dt, app->field->em_energy_red_old); + state = RK_STAGE_3; + } + break; + + case RK_STAGE_3: + for (int i = 0; i < app->num_species; ++i) { + struct gk_species *gks = &app->species[i]; + fin[i] = gks->f1; + fout[i] = gks->fnew; + // Boundary fluxes. + bflux_in[i] = gks->bflux.f1; + bflux_out[i] = gks->bflux.fnew; + } + for (int i = 0; i < app->num_neut_species; ++i) { + struct gk_neut_species *gkns = &app->neut_species[i]; + fin_neut[i] = gkns->f1; + fout_neut[i] = gkns->fnew; + // Boundary fluxes. + bflux_in_neut[i] = gkns->bflux.f1; + bflux_out_neut[i] = gkns->bflux.fnew; + } + + gyrokinetic_forward_euler( + app, tcurr + dt / 2, dt, fin, fout, bflux_in, bflux_out, fin_neut, fout_neut, bflux_in_neut, + bflux_out_neut, &st + ); + + if (st.dt_actual < dt) { + // Recalculate the field. + for (int i = 0; i < app->num_species; ++i) { + struct gk_species *gks = &app->species[i]; + fin[i] = gks->f; + bflux_in[i] = gks->bflux.f; + } + gyrokinetic_calc_field(app, tcurr, fin, bflux_in); - // Compute the fields and apply BCs. - gyrokinetic_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); + // Collect stats. + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], dt_rel_diff); + app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], dt_rel_diff); + app->stat.nstage_3_fail += 1; - state = RK_STAGE_2; - break; + dt = st.dt_actual; + state = RK_STAGE_1; // Restart from stage 1. - case RK_STAGE_2: - for (int i=0; inum_species; ++i) { + app->stat.nstage_2_fail += 1; + } else { + struct timespec wst = gkyl_wall_clock(); + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gks = &app->species[i]; - fin[i] = gks->f1; - fout[i] = gks->fnew; - // Boundary fluxes. - bflux_in[i] = gks->bflux.f1; - bflux_out[i] = gks->bflux.fnew; + // Step f. + gk_species_combine(gks, gks->f1, 1.0 / 3.0, gks->f, 2.0 / 3.0, gks->fnew, &gks->local_ext); + gk_species_copy_range(gks, gks->f, gks->f1, &gks->local_ext); + // Step boundary fluxes. + gk_species_bflux_set(app, &gks->bflux, gks->bflux.f, 2.0 / 3.0, gks->bflux.fnew); + gk_species_bflux_calc_voltime_integrated_mom(app, gks, &gks->bflux, tcurr); } - for (int i=0; inum_neut_species; ++i) { + + for (int i = 0; i < app->num_neut_species; ++i) { struct gk_neut_species *gkns = &app->neut_species[i]; - fin_neut[i] = gkns->f1; - fout_neut[i] = gkns->fnew; - // Boundary fluxes. - bflux_in_neut[i] = gkns->bflux.f1; - bflux_out_neut[i] = gkns->bflux.fnew; + gk_neut_species_combine( + gkns, gkns->f1, 1.0 / 3.0, gkns->f, 2.0 / 3.0, gkns->fnew, &gkns->local_ext + ); + gk_neut_species_copy_range(gkns, gkns->f, gkns->f1, &gkns->local_ext); + // Step boundary fluxes. + gk_neut_species_bflux_set(app, &gkns->bflux, gkns->bflux.f, 2.0 / 3.0, gkns->bflux.fnew); + gk_neut_species_bflux_calc_voltime_integrated_mom(app, gkns, &gkns->bflux, tcurr); } + app->stat.time_stepper_arithmetic_tm += gkyl_time_diff_now_sec(wst); - gyrokinetic_forward_euler(app, tcurr+dt, dt, fin, fout, bflux_in, bflux_out, - fin_neut, fout_neut, bflux_in_neut, bflux_out_neut, &st); - - if (st.dt_actual < dt) { - - // Recalculate the field. - for (int i=0; inum_species; ++i) { - struct gk_species *gks = &app->species[i]; - fin[i] = gks->f; - bflux_in[i] = gks->bflux.f; - } - gyrokinetic_calc_field(app, tcurr, fin, bflux_in); - - // Collect stats. - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], - dt_rel_diff); - app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], - dt_rel_diff); - app->stat.nstage_2_fail += 1; - - dt = st.dt_actual; - state = RK_STAGE_1; // Restart from stage 1. - - } - else { - struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_species; ++i) { - struct gk_species *gks = &app->species[i]; - gk_species_combine(gks, gks->f1, 3.0/4.0, gks->f, 1.0/4.0, gks->fnew, &gks->local_ext); - gk_species_bflux_set(app, &gks->bflux, gks->bflux.f1, 1.0/4.0, gks->bflux.fnew); - } - for (int i=0; inum_neut_species; ++i) { - struct gk_neut_species *gkns = &app->neut_species[i]; - gk_neut_species_combine(gkns, gkns->f1, 3.0/4.0, gkns->f, 1.0/4.0, gkns->fnew, &gkns->local_ext); - gk_neut_species_bflux_set(app, &gkns->bflux, gkns->bflux.f1, 1.0/4.0, gkns->bflux.fnew); - } - app->stat.time_stepper_arithmetic_tm += gkyl_time_diff_now_sec(wst); - - // Compute the fields and apply BCs. - for (int i=0; inum_species; ++i) { - struct gk_species *gks = &app->species[i]; - fout[i] = gks->f1; - bflux_out[i] = gks->bflux.f1; - } - for (int i=0; inum_neut_species; ++i) { - fout_neut[i] = app->neut_species[i].f1; - } - gyrokinetic_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); - - state = RK_STAGE_3; + // Apply positivity shift if requested. + for (int i = 0; i < app->num_species; ++i) { + struct gk_species *gks = &app->species[i]; + gk_species_positivity_apply(app, gks, &gks->positivity, gks->fnew, gks->f); + } + for (int i = 0; i < app->num_neut_species; ++i) { + struct gk_neut_species *gkns = &app->neut_species[i]; + gk_neut_species_positivity_apply(app, gkns, &gkns->positivity, gkns->fnew, gkns->f); } - break; - case RK_STAGE_3: - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct gk_species *gks = &app->species[i]; - fin[i] = gks->f1; - fout[i] = gks->fnew; - // Boundary fluxes. - bflux_in[i] = gks->bflux.f1; - bflux_out[i] = gks->bflux.fnew; + fout[i] = gks->f; + bflux_out[i] = gks->bflux.f; } - for (int i=0; inum_neut_species; ++i) { - struct gk_neut_species *gkns = &app->neut_species[i]; - fin_neut[i] = gkns->f1; - fout_neut[i] = gkns->fnew; - // Boundary fluxes. - bflux_in_neut[i] = gkns->bflux.f1; - bflux_out_neut[i] = gkns->bflux.fnew; + for (int i = 0; i < app->num_neut_species; ++i) { + fout_neut[i] = app->neut_species[i].f; } - gyrokinetic_forward_euler(app, tcurr+dt/2, dt, fin, fout, bflux_in, bflux_out, - fin_neut, fout_neut, bflux_in_neut, bflux_out_neut, &st); - - if (st.dt_actual < dt) { - // Recalculate the field. - for (int i=0; inum_species; ++i) { - struct gk_species *gks = &app->species[i]; - fin[i] = gks->f; - bflux_in[i] = gks->bflux.f; - } - gyrokinetic_calc_field(app, tcurr, fin, bflux_in); - - // Collect stats. - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], - dt_rel_diff); - app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], - dt_rel_diff); - app->stat.nstage_3_fail += 1; - - dt = st.dt_actual; - state = RK_STAGE_1; // Restart from stage 1. - - app->stat.nstage_2_fail += 1; + // Enforce quasineutrality of the positivity shifts. + gyrokinetic_post_positivity_quasineut(app, fout); + + // Compute the fields and apply BCs + gyrokinetic_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); + + for (int i = 0; i < app->num_species; ++i) { + struct gk_species *gks = &app->species[i]; + // Compute moment of f_new to compute moment of df/dt. + // Need to do it after the fields are updated. + gk_species_calc_int_mom_dt(app, gks, dt, gks->fdot_mom_new); } - else { - struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_species; ++i) { - struct gk_species *gks = &app->species[i]; - // Step f. - gk_species_combine(gks, gks->f1, 1.0/3.0, gks->f, 2.0/3.0, gks->fnew, &gks->local_ext); - gk_species_copy_range(gks, gks->f, gks->f1, &gks->local_ext); - // Step boundary fluxes. - gk_species_bflux_set(app, &gks->bflux, gks->bflux.f, 2.0/3.0, gks->bflux.fnew); - gk_species_bflux_calc_voltime_integrated_mom(app, gks, &gks->bflux, tcurr); - } - - for (int i=0; inum_neut_species; ++i) { - struct gk_neut_species *gkns = &app->neut_species[i]; - gk_neut_species_combine(gkns, gkns->f1, 1.0/3.0, gkns->f, 2.0/3.0, gkns->fnew, &gkns->local_ext); - gk_neut_species_copy_range(gkns, gkns->f, gkns->f1, &gkns->local_ext); - // Step boundary fluxes. - gk_neut_species_bflux_set(app, &gkns->bflux, gkns->bflux.f, 2.0/3.0, gkns->bflux.fnew); - gk_neut_species_bflux_calc_voltime_integrated_mom(app, gkns, &gkns->bflux, tcurr); - } - app->stat.time_stepper_arithmetic_tm += gkyl_time_diff_now_sec(wst); - - // Apply positivity shift if requested. - for (int i=0; inum_species; ++i) { - struct gk_species *gks = &app->species[i]; - gk_species_positivity_apply(app, gks, &gks->positivity, gks->fnew, gks->f); - } - for (int i=0; inum_neut_species; ++i) { - struct gk_neut_species *gkns = &app->neut_species[i]; - gk_neut_species_positivity_apply(app, gkns, &gkns->positivity, gkns->fnew, gkns->f); - } - - for (int i=0; inum_species; ++i) { - struct gk_species *gks = &app->species[i]; - fout[i] = gks->f; - bflux_out[i] = gks->bflux.f; - } - for (int i=0; inum_neut_species; ++i) { - fout_neut[i] = app->neut_species[i].f; - } - - // Enforce quasineutrality of the positivity shifts. - gyrokinetic_post_positivity_quasineut(app, fout); - - // Compute the fields and apply BCs - gyrokinetic_calc_field_and_apply_bc(app, tcurr, fout, bflux_out, fout_neut); - - for (int i=0; inum_species; ++i) { - struct gk_species *gks = &app->species[i]; - // Compute moment of f_new to compute moment of df/dt. - // Need to do it after the fields are updated. - gk_species_calc_int_mom_dt(app, gks, dt, gks->fdot_mom_new); - } - - // Scale species according to some criteria. - for (int i=0; inum_species; ++i) { - struct gk_species *gks = &app->species[i]; - gk_species_scaling_apply(app, gks, &gks->sca, gks->f, bflux_out); - } - for (int i=0; inum_neut_species; ++i) { - struct gk_neut_species *gkns = &app->neut_species[i]; - gk_neut_species_scaling_apply(app, gkns, &gkns->sca, gkns->f, bflux_out); - } - - // Compute field energy divided by dt for energy balance diagnostics. - gk_field_calc_energy_dt(app, app->field, dt, app->field->em_energy_red_new); - - state = RK_COMPLETE; + + // Scale species according to some criteria. + for (int i = 0; i < app->num_species; ++i) { + struct gk_species *gks = &app->species[i]; + gk_species_scaling_apply(app, gks, &gks->sca, gks->f, bflux_out); } - break; + for (int i = 0; i < app->num_neut_species; ++i) { + struct gk_neut_species *gkns = &app->neut_species[i]; + gk_neut_species_scaling_apply(app, gkns, &gkns->sca, gkns->f, bflux_out); + } + + // Compute field energy divided by dt for energy balance diagnostics. + gk_field_calc_energy_dt(app, app->field, dt, app->field->em_energy_red_new); + + state = RK_COMPLETE; + } + break; - case RK_COMPLETE: // can't happen: suppresses warning - break; + case RK_COMPLETE: // can't happen: suppresses warning + break; } } diff --git a/gyrokinetic/apps/multib_conn.c b/gyrokinetic/apps/multib_conn.c index 32240d535d..1f9fe70996 100644 --- a/gyrokinetic/apps/multib_conn.c +++ b/gyrokinetic/apps/multib_conn.c @@ -10,19 +10,20 @@ * @param n length of a * return number of unique elements in a */ -static -int count_distinct(int a[], int n) +static int count_distinct(int a[], int n) { - int i, j, count = 1; - for (i = 1; i < n; i++) { // Check if a[i] is a new element - for (j = 0; j < i; j++) { - if (a[i] == a[j]) // Check if a[i] has already been found - break; // Break if it is a duplicate - } - if (i == j) - count++; //increment the number of distinct elements - } - return count; + int i, j, count = 1; + for (i = 1; i < n; i++) { // Check if a[i] is a new element + for (j = 0; j < i; j++) { + if (a[i] == a[j]) { // Check if a[i] has already been found + break; // Break if it is a duplicate + } + } + if (i == j) { + count++; //increment the number of distinct elements + } + } + return count; } /** @@ -33,42 +34,40 @@ int count_distinct(int a[], int n) * @param unique_array on output contains the unique elements in a * return number of unique elements in a */ -static int -get_unique(int *a, int n, int *unique_array) { - unique_array[0] = a[0]; // The first element of a is the first unique element - int i, j, count = 1; - for (i = 1; i < n; i++) { // Check if a[i] is a new element - for (j = 0; j < i; j++) { - if (a[i] == a[j]) // Check if a[i] has already been found - break; // Break if it is a duplicate - } - if (i == j) { - count++; //increment the number of distinct elements - unique_array[i] = a[i]; - } - } - return count; +static int get_unique(int *a, int n, int *unique_array) +{ + unique_array[0] = a[0]; // The first element of a is the first unique element + int i, j, count = 1; + for (i = 1; i < n; i++) { // Check if a[i] is a new element + for (j = 0; j < i; j++) { + if (a[i] == a[j]) { // Check if a[i] has already been found + break; // Break if it is a duplicate + } + } + if (i == j) { + count++; //increment the number of distinct elements + unique_array[i] = a[i]; + } + } + return count; } - /** Insert an element at the beginning of an array of ints * @param arr of length n+1 (padded with one dummy value at the end) * @param n number of values in arr before insertion * @param new val value to insert */ -static void -insert_below(int* arr, int n, int new_val) +static void insert_below(int *arr, int n, int new_val) { int temp_arr[GKYL_MAX_BLOCKS] = {-1}; - for (int i = 0; iconn[bidx]; int neighbor_num = 0; @@ -113,8 +110,7 @@ get_neighbors(struct gkyl_block_topo *block_topo, int bidx, int dir, int *neighb * @param direction * return number of neighbors */ -int -get_num_neighbors(struct gkyl_block_topo *block_topo, int bidx, int dir) +int get_num_neighbors(struct gkyl_block_topo *block_topo, int bidx, int dir) { int neighbor_idxs[1000] = {-1}; int neighbor_num = get_neighbors(block_topo, bidx, dir, neighbor_idxs); @@ -130,8 +126,7 @@ get_num_neighbors(struct gkyl_block_topo *block_topo, int bidx, int dir) * @param neighbor_idxs on output index of neighboring block below * return number of neighbors below (0 or 1) */ -int -get_below(struct gkyl_block_topo *block_topo, int bidx, int dir, int *neighbor_idxs) +int get_below(struct gkyl_block_topo *block_topo, int bidx, int dir, int *neighbor_idxs) { struct gkyl_block_connections conn = block_topo->conn[bidx]; int neighbor_num = 0; @@ -151,8 +146,7 @@ get_below(struct gkyl_block_topo *block_topo, int bidx, int dir, int *neighbor_i * @param direction * return number of neighbors */ -int -get_num_below(struct gkyl_block_topo *block_topo, int bidx, int dir) +int get_num_below(struct gkyl_block_topo *block_topo, int bidx, int dir) { int neighbor_idxs[1000] = {-1}; int neighbor_num = get_neighbors(block_topo, bidx, dir, neighbor_idxs); @@ -168,8 +162,7 @@ get_num_below(struct gkyl_block_topo *block_topo, int bidx, int dir) * @param neighbor_idxs on output index of neighboring block above * return number of neighbors above (0 or 1) */ -int -get_above(struct gkyl_block_topo *block_topo, int bidx, int dir, int *neighbor_idxs) +int get_above(struct gkyl_block_topo *block_topo, int bidx, int dir, int *neighbor_idxs) { struct gkyl_block_connections conn = block_topo->conn[bidx]; int neighbor_num = 0; @@ -189,17 +182,13 @@ get_above(struct gkyl_block_topo *block_topo, int bidx, int dir, int *neighbor_i * @param direction * return number of neighbors */ -int -get_num_above(struct gkyl_block_topo *block_topo, int bidx, int dir) +int get_num_above(struct gkyl_block_topo *block_topo, int bidx, int dir) { int neighbor_idxs[1000] = {-1}; int neighbor_num = get_neighbors(block_topo, bidx, dir, neighbor_idxs); return neighbor_num; } - - - /** * Get the indices of connected blocks in a direction. * @@ -209,40 +198,41 @@ get_num_above(struct gkyl_block_topo *block_topo, int bidx, int dir) * @param block_list ordered indices of connected blocks including self * return number of connected blocks */ -int -get_connected(struct gkyl_block_topo *block_topo, int bidx, int dir, int* block_list) +int get_connected(struct gkyl_block_topo *block_topo, int bidx, int dir, int *block_list) { struct gkyl_block_connections conn; block_list[0] = bidx; int num_blocks = 1; int curr_bidx = bidx; - while(true) { + while (true) { conn = block_topo->conn[curr_bidx]; if (conn.connections[dir][0].edge == GKYL_PHYSICAL) { break; - } - else if (conn.connections[dir][0].edge == GKYL_UPPER_POSITIVE) { - if (conn.connections[dir][0].bid == bidx) return num_blocks; + } else if (conn.connections[dir][0].edge == GKYL_UPPER_POSITIVE) { + if (conn.connections[dir][0].bid == bidx) { + return num_blocks; + } insert_below(block_list, num_blocks, conn.connections[dir][0].bid); curr_bidx = conn.connections[dir][0].bid; - num_blocks+=1; + num_blocks += 1; } } curr_bidx = bidx; - while(true) { + while (true) { conn = block_topo->conn[curr_bidx]; if (conn.connections[dir][1].edge == GKYL_PHYSICAL) { break; - } - else if (conn.connections[dir][1].edge == GKYL_LOWER_POSITIVE) { - if (conn.connections[dir][1].bid == bidx) return num_blocks; + } else if (conn.connections[dir][1].edge == GKYL_LOWER_POSITIVE) { + if (conn.connections[dir][1].bid == bidx) { + return num_blocks; + } insert_above(block_list, num_blocks, conn.connections[dir][1].bid); curr_bidx = conn.connections[dir][1].bid; - num_blocks+=1; + num_blocks += 1; } } - + return num_blocks; } @@ -254,30 +244,26 @@ get_connected(struct gkyl_block_topo *block_topo, int bidx, int dir, int* block_ * @param direction * return number of connected blocks */ -int -get_num_connected(struct gkyl_block_topo *block_topo, int bidx, int dir) +int get_num_connected(struct gkyl_block_topo *block_topo, int bidx, int dir) { int block_list[1000] = {-1}; int num_blocks = get_connected(block_topo, bidx, dir, block_list); return num_blocks; } - - /** * Check if a block corner is an interior corner * @param block_topo block topology object * @param bidx block index * @param edges list of edges (0 for lower, 1 for upper) */ -int -check_corner(struct gkyl_block_topo *block_topo, int bidx, int* edges) +int check_corner(struct gkyl_block_topo *block_topo, int bidx, int *edges) { struct gkyl_block_connections conn = block_topo->conn[bidx]; int ndim = block_topo->ndim; int interior = 1; // true for (int i = 0; i < ndim; i++) { - if(conn.connections[i][edges[i]].edge == GKYL_PHYSICAL) { + if (conn.connections[i][edges[i]].edge == GKYL_PHYSICAL) { interior = 0; break; } @@ -292,29 +278,36 @@ check_corner(struct gkyl_block_topo *block_topo, int bidx, int* edges) * @param edges list of edges of length ndim (0 for lower, 1 for upper) * @param block list on output a list of block indices that touch the corner */ -int -get_corner_connected(struct gkyl_block_topo *block_topo, int bidx, int* edges, int* block_list) +int get_corner_connected(struct gkyl_block_topo *block_topo, int bidx, int *edges, int *block_list) { int ndim = block_topo->ndim; int num_corner_connected = 0; struct gkyl_block_connections conn = block_topo->conn[bidx]; int interior = check_corner(block_topo, bidx, edges); - if (interior == 0) return num_corner_connected; - num_corner_connected+=1; + if (interior == 0) { + return num_corner_connected; + } + num_corner_connected += 1; block_list[0] = bidx; int next_dir = 0; int next_edges[ndim]; - for (int i = 0; i < ndim; i++) next_edges[i] = edges[i]; + for (int i = 0; i < ndim; i++) { + next_edges[i] = edges[i]; + } - while(true) { + while (true) { int next_bidx = conn.connections[next_dir][next_edges[next_dir]].bid; - if (next_bidx == bidx) break; // back at original + if (next_bidx == bidx) { + break; // back at original + } block_list[num_corner_connected] = next_bidx; - num_corner_connected+=1; + num_corner_connected += 1; next_edges[next_dir] = !next_edges[next_dir]; // 0 ->1 or 1 ->0 - next_dir = !next_dir; + next_dir = !next_dir; interior = check_corner(block_topo, next_bidx, next_edges); - if(interior == 0) break; // no more corners + if (interior == 0) { + break; // no more corners + } conn = block_topo->conn[next_bidx]; } @@ -328,17 +321,17 @@ get_corner_connected(struct gkyl_block_topo *block_topo, int bidx, int* edges, i * @param edges list of edges of length ndim (0 for lower, 1 for upper) * return number of blocks touching this corner */ -int -get_num_corner_connected(struct gkyl_block_topo *block_topo, int bidx, int* edges) +int get_num_corner_connected(struct gkyl_block_topo *block_topo, int bidx, int *edges) { int block_list[1000] = {-1}; int num_corner_connected = get_corner_connected(block_topo, bidx, edges, block_list); return num_corner_connected; } - -int -gkyl_multib_conn_get_connection(struct gkyl_block_topo *block_topo, int bidx, int dir, int corner_num, enum gkyl_conn_id conn_id, int *block_list) +int gkyl_multib_conn_get_connection( + struct gkyl_block_topo *block_topo, int bidx, int dir, int corner_num, enum gkyl_conn_id conn_id, + int *block_list +) { struct gkyl_block_connections conn = block_topo->conn[bidx]; int num_connected = 0; @@ -346,23 +339,19 @@ gkyl_multib_conn_get_connection(struct gkyl_block_topo *block_topo, int bidx, in if (conn_id == GKYL_CONN_NEIGHBOR) { num_connected = get_num_neighbors(block_topo, bidx, dir); get_neighbors(block_topo, bidx, dir, block_list); - } - else if (conn_id == GKYL_CONN_ALL) { + } else if (conn_id == GKYL_CONN_ALL) { num_connected = get_num_connected(block_topo, bidx, dir); get_connected(block_topo, bidx, dir, block_list); - } - else if (conn_id == GKYL_CONN_CORNER) { - int e0 = corner_num/2; - int e1 = corner_num%2; - int edges[2] = {e0,e1}; + } else if (conn_id == GKYL_CONN_CORNER) { + int e0 = corner_num / 2; + int e1 = corner_num % 2; + int edges[2] = {e0, e1}; num_connected = get_num_corner_connected(block_topo, bidx, edges); get_corner_connected(block_topo, bidx, edges, block_list); - } - else if (conn_id == GKYL_CONN_BELOW) { + } else if (conn_id == GKYL_CONN_BELOW) { num_connected = get_num_below(block_topo, bidx, dir); get_below(block_topo, bidx, dir, block_list); - } - else if (conn_id == GKYL_CONN_ABOVE) { + } else if (conn_id == GKYL_CONN_ABOVE) { num_connected = get_num_above(block_topo, bidx, dir); get_above(block_topo, bidx, dir, block_list); } @@ -370,11 +359,12 @@ gkyl_multib_conn_get_connection(struct gkyl_block_topo *block_topo, int bidx, in return num_connected; } -int -gkyl_multib_conn_get_num_connected(struct gkyl_block_topo *block_topo, int bidx, int dir, int corner_num, enum gkyl_conn_id conn_id) +int gkyl_multib_conn_get_num_connected( + struct gkyl_block_topo *block_topo, int bidx, int dir, int corner_num, enum gkyl_conn_id conn_id +) { int block_list[1000] = {-1}; - int num_connected = gkyl_multib_conn_get_connection(block_topo, bidx, dir, corner_num, conn_id, block_list); + int num_connected = + gkyl_multib_conn_get_connection(block_topo, bidx, dir, corner_num, conn_id, block_list); return num_connected; } - diff --git a/gyrokinetic/creg/rt_arg_parse.h b/gyrokinetic/creg/rt_arg_parse.h index ac622fc504..ac9855fda7 100644 --- a/gyrokinetic/creg/rt_arg_parse.h +++ b/gyrokinetic/creg/rt_arg_parse.h @@ -17,7 +17,7 @@ struct gkyl_app_args { bool use_gpu; // should this be run on GPU? - bool use_mpi; // should this be run on MPI? + bool use_mpi; // should this be run on MPI? bool step_mode; // run for fixed number of steps? (for valgrind/cuda-memcheck) bool trace_mem; // should we trace memory allocation/deallocations? int num_steps; // number of steps @@ -26,7 +26,8 @@ struct gkyl_app_args { int vcells[3]; // velocity space cells int cuts[3]; // domain decomposition "cuts" char file_name[1024]; // name of input file - char app_name[128]; // basename of argv[0] — use with snprintf/strcpy to set char[] name fields (cannot assign directly in compound literals) + char app_name + [128]; // basename of argv[0] — use with snprintf/strcpy to set char[] name fields (cannot assign directly in compound literals) enum gkyl_basis_type basis_type; // type of basis functions to use enum gkyl_mp_recon mp_recon; // the XX in MP-XX bool skip_limiters; // should we skip limiters? @@ -35,45 +36,36 @@ struct gkyl_app_args { char opt_args[128]; // optional arguments }; -static int -get_basis_type(const char *nm) +static int get_basis_type(const char *nm) { if (strcmp(nm, "ms") == 0) { return GKYL_BASIS_MODAL_SERENDIPITY; - } - else if (strcmp(nm, "mt") == 0) { + } else if (strcmp(nm, "mt") == 0) { return GKYL_BASIS_MODAL_TENSOR; } return -1; } -static int -get_mp_recon_type(const char *nm) +static int get_mp_recon_type(const char *nm) { if (strcmp(nm, "u1") == 0) { return GKYL_MP_U1; - } - else if (strcmp(nm, "u3") == 0) { + } else if (strcmp(nm, "u3") == 0) { return GKYL_MP_U3; - } - else if (strcmp(nm, "u5") == 0) { + } else if (strcmp(nm, "u5") == 0) { return GKYL_MP_U5; - } - else if (strcmp(nm, "c2") == 0) { + } else if (strcmp(nm, "c2") == 0) { return GKYL_MP_C2; - } - else if (strcmp(nm, "c4") == 0) { + } else if (strcmp(nm, "c4") == 0) { return GKYL_MP_C4; - } - else if (strcmp(nm, "c6") == 0) { + } else if (strcmp(nm, "c6") == 0) { return GKYL_MP_C6; - } - + } + return -1; } -static struct gkyl_app_args -parse_app_args(int argc, char **argv) +static struct gkyl_app_args parse_app_args(int argc, char **argv) { bool use_gpu = false; bool use_mpi = false; @@ -85,134 +77,130 @@ parse_app_args(int argc, char **argv) int num_steps = INT_MAX; int num_threads = 1; // by default use only 1 thread - struct gkyl_app_args args = { - .xcells = { 0 }, - .vcells = { 0 }, - .cuts = { 1, 1, 1 }, - }; + struct gkyl_app_args args = {.xcells = {0}, .vcells = {0}, .cuts = {1, 1, 1}}; strcpy(args.file_name, APP_ARGS_DEFAULT_FILE_NAME); // default args.basis_type = GKYL_BASIS_MODAL_SERENDIPITY; int c; while ((c = getopt(argc, argv, "+hjgmMt:s:i:b:x:y:z:u:v:w:r:c:d:e:o:")) != -1) { - switch (c) - { - case 'h': - printf("Usage: -g -m -s nsteps -t nthreads -i inp -b [ms|mt] -x NX -y NY -z NZ -u VX -v VY -w VZ\n"); - printf(" All flags and parameters are optional.\n"); - printf(" -g Run on GPUs if GPUs are present and code built for GPUs\n"); - printf(" -M Run with MPI if code built with MPI\n"); - printf(" -sN Only run N steps of simulation\n"); - printf(" -tN Use N threads (when available)\n"); - printf(" -b Basis function to use (ms: Modal serendipity; mt: Modal tensor-product)\n"); - printf(" (Ignored for finite-volume solvers)\n"); - printf(" -j Recovery scheme. One of u1, u3, u5, c2, c4, c6\n"); - printf(" (Only used for MP-XX solvers)\n"); - printf(" -l Turn off limiters\n"); - printf(" -rN Restart the simulation from frame N\n"); - printf(" -m Turn on memory allocation/deallocation tracing\n"); - printf(" -o Optional arguments (as string, requires parsing)\n"); - printf("\n"); - printf(" Grid resolution in configuration space:\n"); - printf(" -xNX -yNY -zNZ\n"); - printf(" Grid resolution in velocity space:\n"); - printf(" -uVX -vVY -wVZ\n"); - printf(" Domain decomposition in each direction:\n"); - printf(" -cPX -dPY -ePZ\n"); - exit(-1); - break; - - case 'g': - use_gpu = true; - break; - - case 'M': - use_mpi = true; - break; - - case 'm': - trace_mem = true; - break; - - case 'l': - skip_limiters = true; - break; - - case 'r': - is_restart = true; - restart_frame = atoi(optarg); - break; - - case 's': - step_mode = true; - num_steps = atoi(optarg); - break; - - case 't': - num_threads = atoi(optarg); - break; - - case 'c': - args.cuts[0] = atoi(optarg); - break; - - case 'd': - args.cuts[1] = atoi(optarg); - break; - - case 'e': - args.cuts[2] = atoi(optarg); - break; - - case 'x': - args.xcells[0] = atoi(optarg); - break; - - case 'y': - args.xcells[1] = atoi(optarg); - break; - - case 'z': - args.xcells[2] = atoi(optarg); - break; - - case 'u': - args.vcells[0] = atoi(optarg); - break; - - case 'v': - args.vcells[1] = atoi(optarg); - break; - - case 'w': - args.vcells[2] = atoi(optarg); - break; - - case 'i': - strcpy(args.file_name, optarg); - break; - - case 'b': - args.basis_type = get_basis_type(optarg); - assert(args.basis_type != -1); - break; - - case 'j': - args.mp_recon = get_mp_recon_type(optarg); - assert(args.mp_recon != -1); - break; - - case 'o': - assert(strlen(optarg) < sizeof(args.opt_args)); - strcpy(args.opt_args, optarg); - break; - - case '?': - break; + switch (c) { + case 'h': + printf("Usage: -g -m -s nsteps -t nthreads -i inp -b [ms|mt] -x NX -y NY -z NZ -u " + "VX -v VY -w VZ\n"); + printf(" All flags and parameters are optional.\n"); + printf(" -g Run on GPUs if GPUs are present and code built for GPUs\n"); + printf(" -M Run with MPI if code built with MPI\n"); + printf(" -sN Only run N steps of simulation\n"); + printf(" -tN Use N threads (when available)\n"); + printf(" -b Basis function to use (ms: Modal serendipity; mt: Modal tensor-product)\n"); + printf(" (Ignored for finite-volume solvers)\n"); + printf(" -j Recovery scheme. One of u1, u3, u5, c2, c4, c6\n"); + printf(" (Only used for MP-XX solvers)\n"); + printf(" -l Turn off limiters\n"); + printf(" -rN Restart the simulation from frame N\n"); + printf(" -m Turn on memory allocation/deallocation tracing\n"); + printf(" -o Optional arguments (as string, requires parsing)\n"); + printf("\n"); + printf(" Grid resolution in configuration space:\n"); + printf(" -xNX -yNY -zNZ\n"); + printf(" Grid resolution in velocity space:\n"); + printf(" -uVX -vVY -wVZ\n"); + printf(" Domain decomposition in each direction:\n"); + printf(" -cPX -dPY -ePZ\n"); + exit(-1); + break; + + case 'g': + use_gpu = true; + break; + + case 'M': + use_mpi = true; + break; + + case 'm': + trace_mem = true; + break; + + case 'l': + skip_limiters = true; + break; + + case 'r': + is_restart = true; + restart_frame = atoi(optarg); + break; + + case 's': + step_mode = true; + num_steps = atoi(optarg); + break; + + case 't': + num_threads = atoi(optarg); + break; + + case 'c': + args.cuts[0] = atoi(optarg); + break; + + case 'd': + args.cuts[1] = atoi(optarg); + break; + + case 'e': + args.cuts[2] = atoi(optarg); + break; + + case 'x': + args.xcells[0] = atoi(optarg); + break; + + case 'y': + args.xcells[1] = atoi(optarg); + break; + + case 'z': + args.xcells[2] = atoi(optarg); + break; + + case 'u': + args.vcells[0] = atoi(optarg); + break; + + case 'v': + args.vcells[1] = atoi(optarg); + break; + + case 'w': + args.vcells[2] = atoi(optarg); + break; + + case 'i': + strcpy(args.file_name, optarg); + break; + + case 'b': + args.basis_type = get_basis_type(optarg); + assert(args.basis_type != -1); + break; + + case 'j': + args.mp_recon = get_mp_recon_type(optarg); + assert(args.mp_recon != -1); + break; + + case 'o': + assert(strlen(optarg) < sizeof(args.opt_args)); + strcpy(args.opt_args, optarg); + break; + + case '?': + break; } } - + args.use_gpu = use_gpu; args.use_mpi = use_mpi; args.trace_mem = trace_mem; diff --git a/gyrokinetic/creg/rt_gk_ar_react_nonuniformv_1x2v_p1.c b/gyrokinetic/creg/rt_gk_ar_react_nonuniformv_1x2v_p1.c index 8bdc9896c7..c9e076f380 100644 --- a/gyrokinetic/creg/rt_gk_ar_react_nonuniformv_1x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_ar_react_nonuniformv_1x2v_p1.c @@ -11,8 +11,7 @@ #include -struct ar_react_ctx -{ +struct ar_react_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -82,14 +81,14 @@ struct ar_react_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct ar_react_ctx -create_ctx(void) +struct ar_react_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -126,13 +125,17 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0_elc / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0_elc / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -148,24 +151,37 @@ create_ctx(void) int Nvpar = 6; // Cell count (velocity space: parallel velocity direction). int Nmu = 4; // Cell count (velocity space: magnetic moment direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 6.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). - double vpar_max_Ar1 = 6.0 * vtAr1; // Domain boundary (Ar1+ velocity space: parallel velocity direction). - double mu_max_Ar1 = (3.0 / 2.0) * 0.5 * mass_Ar1 * pow(4.0 * vtAr1, 2.0) / (2.0 * B0); // Domain boundary (Ar1+ velocity space: magnetic moment direction). - double vpar_max_Ar2 = 6.0 * vtAr2; // Domain boundary (Ar2+ velocity space: parallel velocity direction). - double mu_max_Ar2 = (3.0 / 2.0) * 0.5 * mass_Ar2 * pow(4.0 * vtAr2, 2.0) / (2.0 * B0); // Domain boundary (Ar2+ velocity space: magnetic moment direction). + double vpar_max_elc = + 6.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_Ar1 = + 6.0 * vtAr1; // Domain boundary (Ar1+ velocity space: parallel velocity direction). + double mu_max_Ar1 = + (3.0 / 2.0) * 0.5 * mass_Ar1 * pow(4.0 * vtAr1, 2.0) / + (2.0 * B0); // Domain boundary (Ar1+ velocity space: magnetic moment direction). + double vpar_max_Ar2 = + 6.0 * vtAr2; // Domain boundary (Ar2+ velocity space: parallel velocity direction). + double mu_max_Ar2 = + (3.0 / 2.0) * 0.5 * mass_Ar2 * pow(4.0 * vtAr2, 2.0) / + (2.0 * B0); // Domain boundary (Ar2+ velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 1.0e-7; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct ar_react_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -225,14 +241,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct ar_react_ctx *app = ctx; @@ -242,8 +259,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0_elc; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ar_react_ctx *app = ctx; @@ -253,15 +269,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct ar_react_ctx *app = ctx; @@ -271,8 +287,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0_ion; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ar_react_ctx *app = ctx; @@ -282,15 +297,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalAr1DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAr1DensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct ar_react_ctx *app = ctx; @@ -300,8 +315,7 @@ evalAr1DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0_Ar1; } -void -evalAr1TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAr1TempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ar_react_ctx *app = ctx; @@ -311,15 +325,15 @@ evalAr1TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = TAr1; } -void -evalAr1UparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAr1UparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set Ar1+ ion parallel velocity. fout[0] = 0.0; } -void -evalAr2DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAr2DensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct ar_react_ctx *app = ctx; @@ -329,8 +343,7 @@ evalAr2DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0_Ar2; } -void -evalAr2TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAr2TempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ar_react_ctx *app = ctx; @@ -340,28 +353,28 @@ evalAr2TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = TAr2; } -void -evalAr2UparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAr2UparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set Ar2+ ion parallel velocity. fout[0] = 0.0; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct ar_react_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -369,7 +382,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct ar_react_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -382,23 +395,24 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_elc * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_elc * (cvpar * cvpar); } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -409,10 +423,12 @@ main(int argc, char **argv) struct ar_react_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dvpar_max_elc; double mu_max_elc = app->mu_max_elc; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; double mu_max_ion = app->mu_max_ion; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } struct gk_app_ctx create_ctx(void) @@ -177,10 +180,7 @@ struct gk_app_ctx create_ctx(void) char eqdsk_file[128] = "./gyrokinetic/data/eqdsk/asdex_33292_3.800.eqdsk"; // Get info from eqdsk file. - struct gkyl_efit_inp efit_inp = { - .rz_poly_order = 2, - .flux_poly_order = 1, - }; + struct gkyl_efit_inp efit_inp = {.rz_poly_order = 2, .flux_poly_order = 1}; memcpy(efit_inp.filepath, eqdsk_file, sizeof(eqdsk_file)); struct gkyl_efit *efit = gkyl_efit_new(&efit_inp); double R_axis = efit->rmaxis; // R of the magnetic axis. @@ -193,41 +193,41 @@ struct gk_app_ctx create_ctx(void) // Species mass and charge. int num_species = 2; double me = electron_mass; - double mi = proton_mass*2.01410177811; // Deuterium ions - double qi = eV; // ion charge + double mi = proton_mass * 2.01410177811; // Deuterium ions + double qi = eV; // ion charge double qe = -eV; // electron charge // Reference parameters. - double n0 = 6.0e18; + double n0 = 6.0e18; double Te0 = 11.0 * eV; double Ti0 = 29.0 * eV; // Parameters controlling initial conditions. - double den_floor = 0.1*n0; // Min density in IC. - double Te_floor = 4.0*eV; // Min Te in IC. - double Ti_floor = 4.0*eV; // Min Ti in IC. + double den_floor = 0.1 * n0; // Min density in IC. + double Te_floor = 4.0 * eV; // Min Te in IC. + double Ti_floor = 4.0 * eV; // Min Ti in IC. - double B0 = 2.5; + double B0 = 2.5; double q0 = 5.0; double r0 = 0.5; - double vte = sqrt(Te0/me); - double vti = sqrt(Ti0/mi); - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; + double vte = sqrt(Te0 / me); + double vti = sqrt(Ti0 / mi); + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // The radial extent gives [rhop_min, rhop_max] = [1.010, 1.046] double x_min = 0.336373; double x_max = 0.352308; double Lx = x_max - x_min; - double z_min = -(M_PI-1e-10); - double z_max = M_PI-1e-10; + double z_min = -(M_PI - 1e-10); + double z_max = M_PI - 1e-10; double Lz = z_max - z_min; - double Ly = 100*rho_s*q0/r0/3.0; - double y_min = -Ly/2.; - double y_max = Ly/2.; + double Ly = 100 * rho_s * q0 / r0 / 3.0; + double y_min = -Ly / 2.; + double y_max = Ly / 2.; double rho_min = rho_psi(x_min, psi_axis, psi_sep); double rho_max = rho_psi(x_max, psi_axis, psi_sep); @@ -235,32 +235,36 @@ struct gk_app_ctx create_ctx(void) // Source parameters int num_sources = 2; double P_exp = 0.235e6; // P_sol measured [W], half of 0.8MW - double vol_frac = Ly/(2.0*M_PI); // Volume fraction of the simulation box + double vol_frac = Ly / (2.0 * M_PI); // Volume fraction of the simulation box double P_inj = P_exp * vol_frac / num_species; // Core source: // - The particles injection is only the one that are lost through the inner radial boundary. - bool adapt_energy_srcCORE = true; // The source will compensate the losses in energy according to given boundaries. - bool adapt_particle_srcCORE = true; // The source will compensate the losses in particle according to given boundaries. + bool adapt_energy_srcCORE = + true; // The source will compensate the losses in energy according to given boundaries. + bool adapt_particle_srcCORE = + true; // The source will compensate the losses in particle according to given boundaries. double energy_srcCORE = P_inj; // What the source must inject in energy [W] - double particle_srcCORE = 0.0;// What the source must inject in particle [1/s] - double center_srcCORE[3] = {x_min, 0.0, -Lz/4.0}; // This is the position of the ion source, - double sigma_srcCORE[3] = {0.06*Lx, 0.0, Lz/8.0}; // the electron source will be at +Lz/2. + double particle_srcCORE = 0.0; // What the source must inject in particle [1/s] + double center_srcCORE[3] = {x_min, 0.0, -Lz / 4.0}; // This is the position of the ion source, + double sigma_srcCORE[3] = {0.06 * Lx, 0.0, Lz / 8.0}; // the electron source will be at +Lz/2. double floor_srcCORE = 1e-10; // Wall source: // - Injects energy only in the wall region. // - Reinjects particles that are absorbed by the wall. // - Energy is free to leave the system. - bool adapt_energy_srcWALL = false; // The source will compensate the losses in energy according to given boundaries. - bool adapt_particle_srcWALL = true; // The source will compensate the losses in particle according to given boundaries. + bool adapt_energy_srcWALL = + false; // The source will compensate the losses in energy according to given boundaries. + bool adapt_particle_srcWALL = + true; // The source will compensate the losses in particle according to given boundaries. double energy_srcWALL = 0.0; // What the source must inject in energy [W] - double particle_srcWALL = 0.0;// What the source must inject in particle [1/s] - double center_srcWALL[3] = {x_min, 0.0, -Lz/2.0}; // This is the position of the ion source, - double sigma_srcWALL[3] = {0.25*Lx, 0.0, 0.1*Lz}; // the electron source will be at +Lz/2. + double particle_srcWALL = 0.0; // What the source must inject in particle [1/s] + double center_srcWALL[3] = {x_min, 0.0, -Lz / 2.0}; // This is the position of the ion source, + double sigma_srcWALL[3] = {0.25 * Lx, 0.0, 0.1 * Lz}; // the electron source will be at +Lz/2. double floor_srcWALL = 1e-10; double temp_recycle_srcWALL = 4.0 * eV; // Grid parameters - int num_cell_x = 12; + int num_cell_x = 12; int num_cell_y = 12; int num_cell_z = 8; int num_cell_vpar = 8; @@ -268,66 +272,79 @@ struct gk_app_ctx create_ctx(void) int poly_order = 1; // Velocity box dimensions - double vpar_max_elc = 6.*vte; - double mu_max_elc = me*pow(4*vte,2)/(2*B0); - double vpar_max_ion = 6.*vti; - double mu_max_ion = mi*pow(4*vti,2)/(2*B0); + double vpar_max_elc = 6. * vte; + double mu_max_elc = me * pow(4 * vte, 2) / (2 * B0); + double vpar_max_ion = 6. * vti; + double mu_max_ion = mi * pow(4 * vti, 2) / (2 * B0); double final_time = 1.0e-4; int num_frames = 100; double write_phase_freq = 0.01; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-3; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_app_ctx ctx = { .cdim = cdim, .vdim = vdim, - .psi_sep = psi_sep , + .psi_sep = psi_sep, .psi_axis = psi_axis, - .x_min = x_min, .x_max = x_max, - .y_min = y_min, .y_max = y_max, - .z_min = z_min, .z_max = z_max, + .x_min = x_min, + .x_max = x_max, + .y_min = y_min, + .y_max = y_max, + .z_min = z_min, + .z_max = z_max, .Lx = Lx, .Ly = Ly, .Lz = Lz, - .rho_min = rho_min, .rho_max = rho_max, + .rho_min = rho_min, + .rho_max = rho_max, .num_species = num_species, - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .den_floor = den_floor , - .Te_floor = Te_floor , - .Ti_floor = Ti_floor , - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .den_floor = den_floor, + .Te_floor = Te_floor, + .Ti_floor = Ti_floor, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, .B0 = B0, .num_sources = num_sources, .adapt_energy_srcCORE = adapt_energy_srcCORE, .adapt_particle_srcCORE = adapt_particle_srcCORE, .center_srcCORE = {center_srcCORE[0], center_srcCORE[1], center_srcCORE[2]}, .sigma_srcCORE = {sigma_srcCORE[0], sigma_srcCORE[1], sigma_srcCORE[2]}, - .energy_srcCORE = energy_srcCORE, .particle_srcCORE = particle_srcCORE, + .energy_srcCORE = energy_srcCORE, + .particle_srcCORE = particle_srcCORE, .floor_srcCORE = floor_srcCORE, .adapt_energy_srcWALL = adapt_energy_srcWALL, .adapt_particle_srcWALL = adapt_particle_srcWALL, .center_srcWALL = {center_srcWALL[0], center_srcWALL[1], center_srcWALL[2]}, .sigma_srcWALL = {sigma_srcWALL[0], sigma_srcWALL[1], sigma_srcWALL[2]}, - .energy_srcWALL = energy_srcWALL, .particle_srcWALL = particle_srcWALL, + .energy_srcWALL = energy_srcWALL, + .particle_srcWALL = particle_srcWALL, .floor_srcWALL = floor_srcWALL, .temp_recycle_srcWALL = temp_recycle_srcWALL, - .num_cell_x = num_cell_x, - .num_cell_y = num_cell_y, - .num_cell_z = num_cell_z, - .num_cell_vpar = num_cell_vpar, - .num_cell_mu = num_cell_mu, + .num_cell_x = num_cell_x, + .num_cell_y = num_cell_y, + .num_cell_z = num_cell_z, + .num_cell_vpar = num_cell_vpar, + .num_cell_mu = num_cell_mu, .cells = {num_cell_x, num_cell_y, num_cell_z, num_cell_vpar, num_cell_mu}, - .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .poly_order = poly_order, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .write_phase_freq = write_phase_freq, - .final_time = final_time, .num_frames = num_frames, + .final_time = final_time, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; // Copy eqdsk file into ctx. @@ -336,15 +353,16 @@ struct gk_app_ctx create_ctx(void) return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif - + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); @@ -353,10 +371,12 @@ main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // context for init functions int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dLz; double source_floor = 1e-10; - if (x < x_source + 3*lambda_source) + if (x < x_source + 3 * lambda_source) { source_floor = 1e-2; - if (fabs(z) < Lz/4) - fout[0] = 6.0e21*fmax(exp(-(x-x_source)*(x-x_source)/((2*lambda_source)*(2*lambda_source))), source_floor); - else - fout[0] = 6.0e21*1e-40; + } + if (fabs(z) < Lz / 4) { + fout[0] = 6.0e21 * + fmax( + exp(-(x - x_source) * (x - x_source) / ((2 * lambda_source) * (2 * lambda_source))), + source_floor + ); + } else { + fout[0] = 6.0e21 * 1e-40; + } } -void -eval_upar_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_asdex_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -130,14 +139,16 @@ eval_temp_elc_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RES double x_source = app->x_source; double Lz = app->Lz; double eV = GKYL_ELEMENTARY_CHARGE; - if ((x < x_source + 3*lambda_source) && (fabs(z) < Lz/4)) - fout[0] = 40.0*eV; - else - fout[0] = 1.920292202211762*eV; + if ((x < x_source + 3 * lambda_source) && (fabs(z) < Lz / 4)) { + fout[0] = 40.0 * eV; + } else { + fout[0] = 1.920292202211762 * eV; + } } -void -eval_temp_ion_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_asdex_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -145,14 +156,16 @@ eval_temp_ion_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RES double x_source = app->x_source; double Lz = app->Lz; double eV = GKYL_ELEMENTARY_CHARGE; - if ((x < x_source + 3*lambda_source) && (fabs(z) < Lz/4)) - fout[0] = 72.0*eV; - else - fout[0] = 3.4565259639811785*eV; + if ((x < x_source + 3 * lambda_source) && (fabs(z) < Lz / 4)) { + fout[0] = 72.0 * eV; + } else { + fout[0] = 3.4565259639811785 * eV; + } } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -160,7 +173,7 @@ diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } // Velocity space mappings. -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_asdex_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -168,18 +181,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_asdex_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -187,73 +201,75 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -struct gk_asdex_ctx -create_ctx(void) +struct gk_asdex_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge - double Te = 40.0*eV; - double Ti = 72.0*eV; + double Te = 40.0 * eV; + double Ti = 72.0 * eV; double B0 = 2.57; // Magnetic field magnitude in Tesla double n0 = 6.0e18; // Particle density in 1/m^3 // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); - double c_s = sqrt(Te/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; - + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); + double c_s = sqrt(Te / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // Collision parameters. - double nuFrac = 1.0; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nuFrac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); // collision freq + double nuFrac = 1.0; + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nuFrac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te)) + ); // collision freq - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nuIon = nuFrac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mi)*(Ti*sqrt(Ti))); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nuIon = nuFrac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mi) * (Ti * sqrt(Ti))); // Simulation box size (psi, theta). double Lx = 0.172 - 0.150; - double Lz = (M_PI-1.0e-14)*2; + double Lz = (M_PI - 1.0e-14) * 2; // Source parameters. - double x_source = 0.160; // changed from 0.16167 - double lambda_source = 0.0004; // Changed from 0.00034, characteristic length scale of n and T + double x_source = 0.160; // changed from 0.16167 + double lambda_source = 0.0004; // Changed from 0.00034, characteristic length scale of n and T // Physical velocity space limits - double vpar_max_elc = 6.0*vtElc; - double mu_max_elc = me*(4.0*vtElc)*(4.0*vtElc)/(2.0*B0); + double vpar_max_elc = 6.0 * vtElc; + double mu_max_elc = me * (4.0 * vtElc) * (4.0 * vtElc) / (2.0 * B0); - double vpar_max_ion = 6.0*vtIon; - double mu_max_ion = mi*(4.0*vtIon)*(4.0*vtIon)/(2.0*B0); + double vpar_max_ion = 6.0 * vtIon; + double mu_max_ion = mi * (4.0 * vtIon) * (4.0 * vtIon) / (2.0 * B0); // Computational velocity space limits. - double vpar_min_ion_c = -1.0/sqrt(2.0); - double vpar_max_ion_c = 1.0/sqrt(2.0); + double vpar_min_ion_c = -1.0 / sqrt(2.0); + double vpar_max_ion_c = 1.0 / sqrt(2.0); double mu_min_ion_c = 0.; double mu_max_ion_c = 1.; // Computational velocity space limits. - double vpar_min_elc_c = -1.0/sqrt(2.0); - double vpar_max_elc_c = 1.0/sqrt(2.0); + double vpar_min_elc_c = -1.0 / sqrt(2.0); + double vpar_max_elc_c = 1.0 / sqrt(2.0); double mu_min_elc_c = 0.; double mu_max_elc_c = 1.; @@ -264,34 +280,35 @@ create_ctx(void) double t_end = 1.0e-8; double num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_asdex_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, - .Te = Te, - .Ti = Ti, - .c_s = c_s, - .nuElc = nuElc, - .nuIon = nuIon, - .B0 = B0, - .n0 = n0, - .Lx = Lx, - .Lz = Lz, + .Te = Te, + .Ti = Ti, + .c_s = c_s, + .nuElc = nuElc, + .nuIon = nuIon, + .B0 = B0, + .n0 = n0, + .Lx = Lx, + .Lz = Lz, .lambda_source = lambda_source, .x_source = x_source, // Physical velocity space limits - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, // Computational velocity space limits .vpar_min_elc_c = vpar_min_elc_c, .vpar_max_elc_c = vpar_max_elc_c, @@ -306,23 +323,24 @@ create_ctx(void) .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -333,269 +351,250 @@ main(int argc, char **argv) struct gk_asdex_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct bgk_cross_relax_ctx -{ +struct bgk_cross_relax_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -64,14 +63,14 @@ struct bgk_cross_relax_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_cross_relax_ctx -create_ctx(void) +struct bgk_cross_relax_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -96,13 +95,17 @@ create_ctx(void) double Te = (T_par_elc + (2.0 * T_perp_elc)) / 3.0; // Electron temperature. double Ti = (T_par_ion + (2.0 * T_perp_ion)) / 3.0; // Ion temperature. - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_elc / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_ion / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_elc / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_ion / charge_ion); // Ion Coulomb logarithm. double nu_elc = log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(T_par_elc, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(T_par_elc, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(T_par_ion, 3.0 / 2.0)); // Ion collision frequency. - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(T_par_ion, 3.0 / 2.0)); // Ion collision frequency. + double vte_par = sqrt(T_par_elc / mass_elc); // Parallel electron thermal velocity. double vti_par = sqrt(T_par_ion / mass_ion); // Parallel ion thermal velocity. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. @@ -116,20 +119,27 @@ create_ctx(void) int Nvpar = 16; // Cell count (velocity space: parallel velocity direction). int Nmu = 16; // Cell count (velocity space: magnetic moment direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 5.0 * vte_par; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = mass_elc * pow(5.0 * vte_par, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 5.0 * vti_par; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = mass_ion * pow(5.0 * vti_par, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 5.0 * vte_par; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + mass_elc * pow(5.0 * vte_par, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 5.0 * vti_par; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + mass_ion * pow(5.0 * vti_par, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 0.1 / nu_ion; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct bgk_cross_relax_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -172,14 +182,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_cross_relax_ctx *app = ctx; @@ -189,8 +200,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_cross_relax_ctx *app = ctx; @@ -200,8 +210,9 @@ evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_elc; } -void -evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_cross_relax_ctx *app = ctx; @@ -211,8 +222,7 @@ evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_elc; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_cross_relax_ctx *app = ctx; @@ -222,8 +232,9 @@ evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = upar_elc; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_cross_relax_ctx *app = ctx; @@ -233,8 +244,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_cross_relax_ctx *app = ctx; @@ -244,8 +254,9 @@ evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_ion; } -void -evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_cross_relax_ctx *app = ctx; @@ -255,11 +266,10 @@ evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_ion; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_cross_relax_ctx *app = ctx; - + double upar_ion = app->upar_ion; // Set ion parallel velocity. @@ -267,33 +277,35 @@ evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_cross_relax_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -304,10 +316,12 @@ main(int argc, char **argv) struct bgk_cross_relax_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dlambda_source; double x_source = app->x_source; double Lz = app->Lz; - double z_source = -Lz/4.0; + double z_source = -Lz / 4.0; double S0 = 24.08e22; - double source_floor = 0.01*S0; + double source_floor = 0.01 * S0; - if (fabs(z-z_source)lambda_source; double x_source = app->x_source; double Lz = app->Lz; - double z_source = -Lz/4.0; + double z_source = -Lz / 4.0; double eV = GKYL_ELEMENTARY_CHARGE; - if ((x < x_source + 3*lambda_source) && (fabs(z-z_source)lambda_source; double x_source = app->x_source; double Lz = app->Lz; - double z_source = -Lz/4.0; + double z_source = -Lz / 4.0; double eV = GKYL_ELEMENTARY_CHARGE; - if ((x < x_source + 3*lambda_source) && (fabs(z-z_source)vpar_max_elc; @@ -170,18 +177,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_asdex_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -189,73 +197,75 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -struct gk_asdex_ctx -create_ctx(void) +struct gk_asdex_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge - double Te = 40.0*eV; - double Ti = 72.0*eV; + double Te = 40.0 * eV; + double Ti = 72.0 * eV; double B0 = 2.57; // Magnetic field magnitude in Tesla double n0 = 2.0e19; // Particle density in 1/m^3 // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); - double c_s = sqrt(Te/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; - + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); + double c_s = sqrt(Te / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // Collision parameters. - double nuFrac = 1.0; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nuFrac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); // collision freq + double nuFrac = 1.0; + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nuFrac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te)) + ); // collision freq - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nuIon = nuFrac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mi)*(Ti*sqrt(Ti))); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nuIon = nuFrac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mi) * (Ti * sqrt(Ti))); // Simulation box size (psi, theta). double Lx = 0.172 - 0.150; - double Lz = (M_PI-1.0e-14)*2; + double Lz = (M_PI - 1.0e-14) * 2; // Source parameters. - double x_source = 0.1534; - double lambda_source = 0.0011; + double x_source = 0.1534; + double lambda_source = 0.0011; // Physical velocity space limits - double vpar_max_elc = 6.0*vtElc; - double mu_max_elc = me*(4.0*vtElc)*(4.0*vtElc)/(2.0*B0); + double vpar_max_elc = 6.0 * vtElc; + double mu_max_elc = me * (4.0 * vtElc) * (4.0 * vtElc) / (2.0 * B0); - double vpar_max_ion = 6.0*vtIon; - double mu_max_ion = mi*(4.0*vtIon)*(4.0*vtIon)/(2.0*B0); + double vpar_max_ion = 6.0 * vtIon; + double mu_max_ion = mi * (4.0 * vtIon) * (4.0 * vtIon) / (2.0 * B0); // Computational velocity space limits. - double vpar_min_ion_c = -1.0/sqrt(2.0); - double vpar_max_ion_c = 1.0/sqrt(2.0); + double vpar_min_ion_c = -1.0 / sqrt(2.0); + double vpar_max_ion_c = 1.0 / sqrt(2.0); double mu_min_ion_c = 0.; double mu_max_ion_c = 1.; // Computational velocity space limits. - double vpar_min_elc_c = -1.0/sqrt(2.0); - double vpar_max_elc_c = 1.0/sqrt(2.0); + double vpar_min_elc_c = -1.0 / sqrt(2.0); + double vpar_max_elc_c = 1.0 / sqrt(2.0); double mu_min_elc_c = 0.; double mu_max_elc_c = 1.; @@ -266,34 +276,35 @@ create_ctx(void) double t_end = 1.0e-8; double num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_asdex_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, - .Te = Te, - .Ti = Ti, - .c_s = c_s, - .nuElc = nuElc, - .nuIon = nuIon, - .B0 = B0, - .n0 = n0, - .Lx = Lx, - .Lz = Lz, + .Te = Te, + .Ti = Ti, + .c_s = c_s, + .nuElc = nuElc, + .nuIon = nuIon, + .B0 = B0, + .n0 = n0, + .Lx = Lx, + .Lz = Lz, .lambda_source = lambda_source, .x_source = x_source, // Physical velocity space limits - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, // Computational velocity space limits .vpar_min_elc_c = vpar_min_elc_c, .vpar_max_elc_c = vpar_max_elc_c, @@ -308,22 +319,23 @@ create_ctx(void) .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -334,271 +346,252 @@ main(int argc, char **argv) struct gk_asdex_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct bgk_cross_relax_ctx -{ +struct bgk_cross_relax_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -64,14 +63,14 @@ struct bgk_cross_relax_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_cross_relax_ctx -create_ctx(void) +struct bgk_cross_relax_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -96,13 +95,17 @@ create_ctx(void) double Te = (T_par_elc + (2.0 * T_perp_elc)) / 3.0; // Electron temperature. double Ti = (T_par_ion + (2.0 * T_perp_ion)) / 3.0; // Ion temperature. - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_elc / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_ion / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_elc / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_ion / charge_ion); // Ion Coulomb logarithm. double nu_elc = log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(T_par_elc, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(T_par_elc, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(T_par_ion, 3.0 / 2.0)); // Ion collision frequency. - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(T_par_ion, 3.0 / 2.0)); // Ion collision frequency. + double vte_par = sqrt(T_par_elc / mass_elc); // Parallel electron thermal velocity. double vti_par = sqrt(T_par_ion / mass_ion); // Parallel ion thermal velocity. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. @@ -116,20 +119,27 @@ create_ctx(void) int Nvpar = 16; // Cell count (velocity space: parallel velocity direction). int Nmu = 16; // Cell count (velocity space: magnetic moment direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 5.0 * vte_par; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = mass_elc * pow(5.0 * vte_par, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 5.0 * vti_par; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = mass_ion * pow(5.0 * vti_par, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 5.0 * vte_par; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + mass_elc * pow(5.0 * vte_par, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 5.0 * vti_par; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + mass_ion * pow(5.0 * vti_par, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 0.1 / nu_ion; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct bgk_cross_relax_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -172,14 +182,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_cross_relax_ctx *app = ctx; @@ -189,8 +200,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_cross_relax_ctx *app = ctx; @@ -200,8 +210,9 @@ evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_elc; } -void -evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_cross_relax_ctx *app = ctx; @@ -211,8 +222,7 @@ evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_elc; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_cross_relax_ctx *app = ctx; @@ -222,8 +232,9 @@ evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = upar_elc; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_cross_relax_ctx *app = ctx; @@ -233,8 +244,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_cross_relax_ctx *app = ctx; @@ -244,8 +254,9 @@ evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_ion; } -void -evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_cross_relax_ctx *app = ctx; @@ -255,11 +266,10 @@ evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_ion; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_cross_relax_ctx *app = ctx; - + double upar_ion = app->upar_ion; // Set ion parallel velocity. @@ -267,33 +277,35 @@ evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_cross_relax_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -304,10 +316,12 @@ main(int argc, char **argv) struct bgk_cross_relax_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sodshock_ctx -{ +struct sodshock_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using normalized code units). @@ -42,14 +41,14 @@ struct sodshock_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -65,7 +64,7 @@ create_ctx(void) double B0 = 1.0; // Reference magnetic field strength. double n0 = 1.0; // Reference number density. - double vt = 1.0; // Reference thermal velocity. + double vt = 1.0; // Reference thermal velocity. double nu = 100.0; // Collision frequency. // Simulation parameters. @@ -74,14 +73,16 @@ create_ctx(void) int Nmu = 16; // Cell count (velocity space: magnetic moment direction). double Lz = 2.0; // Domain size (configuration space: x-direction). double vpar_max = 6.0 * vt; // Domain boundary (velocity space: parallel velocity direction). - double mu_max = 18.0 * (vt * vt) / 2.0 / B0; // Domain boundary (velocity space: magnetic moment direction). + double mu_max = + 18.0 * (vt * vt) / 2.0 / B0; // Domain boundary (velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 0.1; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -112,14 +113,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double z = xn[0]; @@ -131,8 +131,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (fabs(z) < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -140,8 +139,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double z = xn[0]; @@ -153,8 +151,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (fabs(z) < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -162,15 +159,13 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -181,33 +176,35 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -218,10 +215,12 @@ main(int argc, char **argv) struct sodshock_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sodshock_ctx -{ +struct sodshock_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using normalized code units). @@ -42,14 +41,14 @@ struct sodshock_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -65,7 +64,7 @@ create_ctx(void) double B0 = 1.0; // Reference magnetic field strength. double n0 = 1.0; // Reference number density. - double vt = 1.0; // Reference thermal velocity. + double vt = 1.0; // Reference thermal velocity. double nu = 100.0; // Collision frequency. // Simulation parameters. @@ -74,14 +73,16 @@ create_ctx(void) int Nmu = 16; // Cell count (velocity space: magnetic moment direction). double Lz = 2.0; // Domain size (configuration space: x-direction). double vpar_max = 6.0 * vt; // Domain boundary (velocity space: parallel velocity direction). - double mu_max = 18.0 * (vt * vt) / 2.0 / B0; // Domain boundary (velocity space: magnetic moment direction). + double mu_max = + 18.0 * (vt * vt) / 2.0 / B0; // Domain boundary (velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 0.1; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -112,14 +113,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double z = xn[0]; @@ -131,8 +131,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (fabs(z) < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -140,8 +139,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double z = xn[0]; @@ -153,8 +151,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (fabs(z) < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -162,15 +159,13 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -181,33 +176,35 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -218,10 +215,12 @@ main(int argc, char **argv) struct sodshock_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct bgk_relax_ctx -{ +struct bgk_relax_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using normalized code units). @@ -44,14 +43,14 @@ struct bgk_relax_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_relax_ctx -create_ctx(void) +struct bgk_relax_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -78,14 +77,16 @@ create_ctx(void) int Nmu = 8; // Cell count (velocity space: magnetic moment direction). double Lz = 1.0; // Domain size (configuration space: x-direction). double vpar_max = 8.0 * vt; // Domain boundary (velocity space: parallel velocity direction). - double mu_max = 0.5 * mass * pow(3.5 * vt, 2.0) / B0; // Domain boundary (velocity space: magnetic moment direction). + double mu_max = 0.5 * mass * pow(3.5 * vt, 2.0) / + B0; // Domain boundary (velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 0.5 / nu; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -117,14 +118,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vpar = xn[1]; @@ -138,8 +138,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (fabs(vpar) < v0) { n = n0 / 2.0 / v0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -147,8 +146,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vpar = xn[1], mu = xn[2]; @@ -166,16 +164,16 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vpar - u0) / (sqrt(2.0) * vt)) * ((vpar - u0) / (sqrt(2.0) * vt)) + mu * B0; double vb_sq = ((vpar - u0) / (sqrt(2.0) * vtb)) * ((vpar - u0) / (sqrt(2.0) * vtb)) + mu * B0; - - double n = (n0 / sqrt(2.0 * M_PI * vt)) * exp(-v_sq) + (n0 / sqrt(2.0 * M_PI * vtb)) * - exp(-vb_sq) * (ab * ab) / ((vpar - ub) * (vpar - ub) + sb * sb); // Distribution function. + + double n = (n0 / sqrt(2.0 * M_PI * vt)) * exp(-v_sq) + + (n0 / sqrt(2.0 * M_PI * vtb)) * exp(-vb_sq) * (ab * ab) / + ((vpar - ub) * (vpar - ub) + sb * sb); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalTopHatNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -185,8 +183,7 @@ evalTopHatNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu; } -void -evalBumpNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -196,56 +193,60 @@ evalBumpNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu; } -void -evalBumpSquareNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpSquareNu( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_relax_ctx *app = ctx; double nu = app->nu; // Set collision frequency. - fout[0] = sqrt(2.0)*nu; + fout[0] = sqrt(2.0) * nu; } -void -evalSquareBumpNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSquareBumpNu( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_relax_ctx *app = ctx; double nu = app->nu; // Set collision frequency. - fout[0] = sqrt(2.0)*nu; + fout[0] = sqrt(2.0) * nu; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; - + double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -256,10 +257,12 @@ main(int argc, char **argv) struct bgk_relax_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct bgk_relax_ctx -{ +struct bgk_relax_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -65,14 +64,14 @@ struct bgk_relax_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_relax_ctx -create_ctx(void) +struct bgk_relax_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -103,13 +102,17 @@ create_ctx(void) double Te = (T_par_elc + (2.0 * T_perp_elc)) / 3.0; // Electron temperature. double Ti = (T_par_ion + (2.0 * T_perp_ion)) / 3.0; // Ion temperature. - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -118,20 +121,27 @@ create_ctx(void) int Nvpar = 16; // Cell count (velocity space: parallel velocity direction). int Nmu = 8; // Cell count (velocity space: magnetic moment direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 1.0 / nu_elc; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct bgk_relax_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -175,14 +185,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_relax_ctx *app = ctx; @@ -192,8 +203,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -203,8 +213,9 @@ evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_elc; } -void -evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_relax_ctx *app = ctx; @@ -214,15 +225,15 @@ evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_elc; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_relax_ctx *app = ctx; @@ -232,8 +243,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -243,8 +253,9 @@ evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_ion; } -void -evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_relax_ctx *app = ctx; @@ -254,15 +265,13 @@ evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_ion; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -272,8 +281,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -284,33 +292,35 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -321,10 +331,12 @@ main(int argc, char **argv) struct bgk_relax_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct bgk_relax_ctx -{ +struct bgk_relax_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -65,14 +64,14 @@ struct bgk_relax_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_relax_ctx -create_ctx(void) +struct bgk_relax_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -103,13 +102,17 @@ create_ctx(void) double Te = (T_par_elc + (2.0 * T_perp_elc)) / 3.0; // Electron temperature. double Ti = (T_par_ion + (2.0 * T_perp_ion)) / 3.0; // Ion temperature. - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -118,20 +121,27 @@ create_ctx(void) int Nvpar = 16; // Cell count (velocity space: parallel velocity direction). int Nmu = 8; // Cell count (velocity space: magnetic moment direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 1.0 / nu_elc; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct bgk_relax_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -175,14 +185,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_relax_ctx *app = ctx; @@ -192,8 +203,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -203,8 +213,9 @@ evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_elc; } -void -evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_relax_ctx *app = ctx; @@ -214,15 +225,15 @@ evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_elc; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_relax_ctx *app = ctx; @@ -232,8 +243,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -243,8 +253,9 @@ evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_ion; } -void -evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct bgk_relax_ctx *app = ctx; @@ -254,15 +265,13 @@ evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_ion; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -272,8 +281,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -284,20 +292,21 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -305,7 +314,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct bgk_relax_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -318,23 +327,24 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_elc * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_elc * (cvpar * cvpar); } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -345,10 +355,12 @@ main(int argc, char **argv) struct bgk_relax_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d= x_max) { - fprintf(stderr, "Warning: x = %g out of LUT range [%g, %g]. Clamping to boundaries.\n", x, x_min, x_max); - if (x <= x_min) return lut_val[0]; - if (x >= x_max) return lut_val[N-1]; + fprintf( + stderr, "Warning: x = %g out of LUT range [%g, %g]. Clamping to boundaries.\n", x, x_min, + x_max + ); + if (x <= x_min) { + return lut_val[0]; + } + if (x >= x_max) { + return lut_val[N - 1]; + } } // Assume uniform spacing of the lookup table. - double dx = (x_max - x_min)/(N-1); - int idx = (int)((x - x_min)/dx); + double dx = (x_max - x_min) / (N - 1); + int idx = (int)((x - x_min) / dx); // Safety check. - if (idx < 0 || idx >= N-1) { + if (idx < 0 || idx >= N - 1) { fprintf(stderr, "Error: idx out of bounds in interp_Psi_lut: idx = %d, x = %g\n", idx, x); return 0.0; } // Linear interpolation. double x0 = lut_grid[idx]; - double x1 = lut_grid[idx+1]; + double x1 = lut_grid[idx + 1]; double f0 = lut_val[idx]; - double f1 = lut_val[idx+1]; - return f0 + (f1 - f0)*(x - x0)/(x1 - x0); + double f1 = lut_val[idx + 1]; + return f0 + (f1 - f0) * (x - x0) / (x1 - x0); } // Define the context of the simulation. This stores global parameters. @@ -73,11 +80,11 @@ struct gk_app_ctx { double *dPsidr_int_lut; }; -// Geometry related functions +// Geometry related functions double r_x(double x, double r0) { return x + r0; -} +} // quadratic q profile double qprofile(double r, double a_mid, double qaxis, double qlcfs) @@ -96,7 +103,7 @@ double R_rtheta(double r, double theta, void *ctx) double a_shift = app->a_shift; double R_axis = app->R_axis; double delta = app->delta; - return R_axis - a_shift*r*r/(2.*R_axis) + r*cos(theta + asin(delta)*sin(theta)); + return R_axis - a_shift * r * r / (2. * R_axis) + r * cos(theta + asin(delta) * sin(theta)); } double Z_rtheta(double r, double theta, void *ctx) @@ -104,7 +111,7 @@ double Z_rtheta(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; double Z_axis = app->Z_axis; double kappa = app->kappa; - return Z_axis + kappa*r*sin(theta); + return Z_axis + kappa * r * sin(theta); } double dRdr(double r, double theta, void *ctx) @@ -113,34 +120,34 @@ double dRdr(double r, double theta, void *ctx) double a_shift = app->a_shift; double R_axis = app->R_axis; double delta = app->delta; - return -a_shift*r/(R_axis) + cos(theta + asin(delta)*sin(theta)); + return -a_shift * r / (R_axis) + cos(theta + asin(delta) * sin(theta)); } double dRdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return -r*sin(theta + asin(delta)*sin(theta))*(1.+asin(delta)*cos(theta)); + return -r * sin(theta + asin(delta) * sin(theta)) * (1. + asin(delta) * cos(theta)); } double dZdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*sin(theta); + return kappa * sin(theta); } double dZdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*cos(theta); + return kappa * r * cos(theta); } double Jr(double r, double theta, void *ctx) { - return R_rtheta(r,theta,ctx)*( dRdr(r,theta,ctx) * dZdtheta(r,theta,ctx) - -dRdtheta(r,theta,ctx) * dZdr(r,theta,ctx) ); + return R_rtheta(r, theta, ctx) * (dRdr(r, theta, ctx) * dZdtheta(r, theta, ctx) - + dRdtheta(r, theta, ctx) * dZdr(r, theta, ctx)); } struct integrand_ctx { @@ -155,7 +162,7 @@ double Bphi(double R, void *ctx) struct gk_app_ctx *app = ctx; double B0 = app->B0; double R0 = app->R0; - return B0*R0/R; + return B0 * R0 / R; } double integrand_JoRsq(double t, void *int_ctx) @@ -163,7 +170,7 @@ double integrand_JoRsq(double t, void *int_ctx) struct integrand_ctx *inctx = int_ctx; double r = inctx->r; struct gk_app_ctx *app = inctx->app_ctx; - return Jr(r,t,app) / pow(R_rtheta(r,t,app),2); + return Jr(r, t, app) / pow(R_rtheta(r, t, app), 2); } double intdPsidr(double r, void *ctx) @@ -171,7 +178,7 @@ double intdPsidr(double r, void *ctx) struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - integral = gkyl_dbl_exp(integrand_JoRsq, &tmp_ctx, 0., 2.*M_PI, 7, 1e-10); + integral = gkyl_dbl_exp(integrand_JoRsq, &tmp_ctx, 0., 2. * M_PI, 7, 1e-10); return integral.res; } @@ -181,9 +188,9 @@ double dPsidr(double r, double theta, void *ctx) struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; double integral_val = interp_1x_lut(r, app->r_lut, app->dPsidr_int_lut, app->psi_lut_size); - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); - return ( R*Bt/(2.*M_PI*qprofile(r, app->a_mid, app->qaxis, app->qlcfs)))*integral_val; + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); + return (R * Bt / (2. * M_PI * qprofile(r, app->a_mid, app->qaxis, app->qlcfs))) * integral_val; } double integrant_dpsi(double r, void *int_ctx) @@ -191,7 +198,7 @@ double integrant_dpsi(double r, void *int_ctx) struct integrand_ctx *inctx = int_ctx; struct gk_app_ctx *app = inctx->app_ctx; double q = qprofile(r, app->a_mid, app->qaxis, app->qlcfs); - double dpsi = -r/q; // This is valid in the circular limit. The minus sign comes dBtheta/r < 0 + double dpsi = -r / q; // This is valid in the circular limit. The minus sign comes dBtheta/r < 0 return dpsi; // I am not sure about this sign, I think it must be from dx/dr = -1. // return -dPsidr(r, inctx->theta, app); // Seems to be the exact way but it makes the profile super flat (and -1 factor looks important here). } @@ -205,13 +212,16 @@ double intPsi(double r0, double r, double theta, void *ctx) return integral.res; } -double compute_alpha_integral(double r, double twrap, void *ctx) { +double compute_alpha_integral(double r, double twrap, void *ctx) +{ struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - if (twrap == 0.0) return 0.0; - + if (twrap == 0.0) { + return 0.0; + } + if (0. < twrap) { integral = gkyl_dbl_exp(integrand_JoRsq, &tmp_ctx, 0., twrap, 7, 1e-10); return integral.res; @@ -225,42 +235,47 @@ double alpha(double r, double theta, double phi, void *ctx) { struct gk_app_ctx *app = ctx; double twrap = theta; - while (twrap < -M_PI) twrap = twrap+2.*M_PI; - while (M_PI < twrap) twrap = twrap-2.*M_PI; + while (twrap < -M_PI) { + twrap = twrap + 2. * M_PI; + } + while (M_PI < twrap) { + twrap = twrap - 2. * M_PI; + } double integral_val = compute_alpha_integral(r, twrap, ctx); - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); - return phi - R*Bt*integral_val/dPsidr(r,theta,ctx); + return phi - R * Bt * integral_val / dPsidr(r, theta, ctx); } double gradr(double r, double theta, void *ctx) { - return (R_rtheta(r,theta,ctx)/Jr(r,theta,ctx))*sqrt(pow(dRdtheta(r,theta,ctx),2) + pow(dZdtheta(r,theta,ctx),2)); + return (R_rtheta(r, theta, ctx) / Jr(r, theta, ctx)) * + sqrt(pow(dRdtheta(r, theta, ctx), 2) + pow(dZdtheta(r, theta, ctx), 2)); } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; struct gk_app_ctx *app = ctx; double a_mid = app->a_mid; double Cy = app->Cy; double r0 = app->r0; - double r = r_x(x,r0); - double Bt = Bphi(R_rtheta(r,z,ctx),ctx); - double Bp = dPsidr(r,z,ctx)/R_rtheta(r,z,ctx)*gradr(r,z,ctx); - - double drdtheta = dRdtheta(r,z,ctx); - double dzdtheta = dZdtheta(r,z,ctx); - double den = sqrt(pow(drdtheta,2) + pow(dzdtheta,2)); - double B_r = Bp*drdtheta/den; - double B_z = Bp*dzdtheta/den; - double phi = y/Cy + alpha(r, z, 0, ctx); + double r = r_x(x, r0); + double Bt = Bphi(R_rtheta(r, z, ctx), ctx); + double Bp = dPsidr(r, z, ctx) / R_rtheta(r, z, ctx) * gradr(r, z, ctx); + + double drdtheta = dRdtheta(r, z, ctx); + double dzdtheta = dZdtheta(r, z, ctx); + double den = sqrt(pow(drdtheta, 2) + pow(dzdtheta, 2)); + double B_r = Bp * drdtheta / den; + double B_z = Bp * dzdtheta / den; + double phi = y / Cy + alpha(r, z, 0, ctx); double R = R_rtheta(r, z, ctx); - // xc are computational coords. + // xc are computational coords. // Set Cartesian components of magnetic field. fout[0] = B_r * cos(phi) + Bt * sin(phi); fout[1] = B_r * sin(phi) - Bt * cos(phi); @@ -269,11 +284,11 @@ void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *c double Bmag(double r, double theta, void *ctx) { - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); - double Bp = dPsidr(r,theta,ctx)/R_rtheta(r,theta,ctx)*gradr(r,theta,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); + double Bp = dPsidr(r, theta, ctx) / R_rtheta(r, theta, ctx) * gradr(r, theta, ctx); - return sqrt(pow(Bt,2) + pow(Bp,2)); + return sqrt(pow(Bt, 2) + pow(Bp, 2)); } double rbar(double m, double q, double r, double theta, double vpar, double mu, void *ctx) @@ -281,7 +296,7 @@ double rbar(double m, double q, double r, double theta, double vpar, double mu, struct gk_app_ctx *app = ctx; double e = GKYL_ELEMENTARY_CHARGE; - double R = R_rtheta(r,theta,ctx); + double R = R_rtheta(r, theta, ctx); double r0 = app->r0; double R0 = app->R0; double q0 = app->q0; @@ -289,29 +304,28 @@ double rbar(double m, double q, double r, double theta, double vpar, double mu, double psi_r = interp_1x_lut(r, app->r_lut, app->psi_lut, app->psi_lut_size); double psi_r0 = interp_1x_lut(r0, app->r_lut, app->psi_lut, app->psi_lut_size); - double rpsi = q0/r0 * (psi_r - psi_r0); - + double rpsi = q0 / r0 * (psi_r - psi_r0); + double rmin = r0 - app->x_min; double rmax = r0 + app->x_max; double zmin = app->z_min; double zmax = app->z_max; double Bmax = Bmag(rmax, zmax, ctx); - + double B0 = app->B0; - double B = Bmag(r,theta,ctx); - double E = 0.5 * m * pow(vpar,2) + mu*B; - double sgnvpar = vpar>0 ? 1.0 : -1.0; - double vparbar = E - mu*Bmax > 0 ? - sgnvpar*sqrt(2/m)*sqrt(E - mu*Bmax) : 0.0; + double B = Bmag(r, theta, ctx); + double E = 0.5 * m * pow(vpar, 2) + mu * B; + double sgnvpar = vpar > 0 ? 1.0 : -1.0; + double vparbar = E - mu * Bmax > 0 ? sgnvpar * sqrt(2 / m) * sqrt(E - mu * Bmax) : 0.0; - double rvpar = m*q0/(q*B0*r0) * (R*vpar - R0*vparbar); + double rvpar = m * q0 / (q * B0 * r0) * (R * vpar - R0 * vparbar); double rbar = r0 - rpsi - rvpar; return app->can_max ? rbar : r; } -// Static BGK source term to maintain eq. profile at lower x boundary. +// Static BGK source term to maintain eq. profile at lower x boundary. void double_buffer_profile(double t, const double *xn, double *fout, void *ctx) { double x = xn[0]; @@ -324,12 +338,14 @@ void double_buffer_profile(double t, const double *xn, double *fout, void *ctx) // See Eq. 49 of V. Grandgirard et al. / Computer Physics Communications 207 (2016) 35–68 double Bs = 0.015; // Buffer transition width as a fraction of the domain size. double Bl = app->num_cell_buff / (double)nx; // Buffer fraction. - Hbuff = 1 + 0.5 * (tanh((x - x_max + Bl*Lx)/(Bs*Lx)) - tanh((x - x_min - Bl*Lx)/(Bs*Lx))); + Hbuff = + 1 + 0.5 * (tanh((x - x_max + Bl * Lx) / (Bs * Lx)) - tanh((x - x_min - Bl * Lx) / (Bs * Lx))); fout[0] = Hbuff * app->nu_krook; } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -340,8 +356,8 @@ double tanh_profile(double x, double v0, double Lgrad, void *ctx) { struct gk_app_ctx *app = ctx; // Profile use in Gysela (see V. Grandgirard et al. / Computer Physics Communications 207 (2016) 35–68). - double buff_frac = (double)app->num_cell_buff / app->Nx; - double delta = 0.5*(1-buff_frac) * app->Lx; + double buff_frac = (double)app->num_cell_buff / app->Nx; + double delta = 0.5 * (1 - buff_frac) * app->Lx; double arg = x / (app->a_mid * delta); double prof_factor = (app->a_mid * delta) / Lgrad; return v0 * exp(-prof_factor * tanh(arg)); @@ -370,10 +386,12 @@ double temp_init_ion(double x, void *ctx) double maxellian(double m, double n, double T, double E) { - return n/pow(2*M_PI*T/m,1.5) * exp(-E/T); + return n / pow(2 * M_PI * T / m, 1.5) * exp(-E / T); } -void eval_canon_maxwellian_e(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_canon_maxwellian_e( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_app_ctx *app = ctx; double x = xn[0], z = xn[1], vpar = xn[2], mu = xn[3]; @@ -387,15 +405,18 @@ void eval_canon_maxwellian_e(double t, const double* GKYL_RESTRICT xn, double* G double dens = density_init(xb, ctx); double temp = temp_init_elc(xb, ctx); - double envelope = exp(-pow(xb / (app->Lx / 4.0), 2)) * exp(-pow((theta - M_PI) / (M_PI / 4.0), 2)); + double envelope = + exp(-pow(xb / (app->Lx / 4.0), 2)) * exp(-pow((theta - M_PI) / (M_PI / 4.0), 2)); dens = dens * envelope; - double energy = 0.5*m*pow(vpar,2) + mu*Bmag(r,theta,ctx); + double energy = 0.5 * m * pow(vpar, 2) + mu * Bmag(r, theta, ctx); fout[0] = maxellian(m, dens, temp, energy); } -void eval_canon_maxwellian_i(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_canon_maxwellian_i( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_app_ctx *app = ctx; double x = xn[0], z = xn[1], vpar = xn[2], mu = xn[3]; @@ -409,28 +430,32 @@ void eval_canon_maxwellian_i(double t, const double* GKYL_RESTRICT xn, double* G double dens = density_init(xb, ctx); double temp = temp_init_ion(xb, ctx); - double energy = 0.5*m*pow(vpar,2) + mu*Bmag(r,theta,ctx); + double energy = 0.5 * m * pow(vpar, 2) + mu * Bmag(r, theta, ctx); fout[0] = maxellian(m, dens, temp, energy); } -void eval_dens_ic(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_dens_ic(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = density_init(xn[0], ctx); } -void eval_temp_elc_ic(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_temp_elc_ic( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = temp_init_elc(xn[0], ctx); } -void eval_temp_ion_ic(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_temp_ion_ic( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = temp_init_ion(xn[0], ctx); } // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; @@ -438,52 +463,56 @@ void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) double a_mid = app->a_mid; double Cy = app->Cy; - double r = r_x(x,app->r0); + double r = r_x(x, app->r0); // Map to cylindrical (R, Z, phi) coordinates. double R = R_rtheta(r, z, ctx); double Z = Z_rtheta(r, z, ctx); - double phi = y/Cy + alpha(r, z, 0, ctx); + double phi = y / Cy + alpha(r, z, 0, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + double X = R * cos(phi); + double Y = R * sin(phi); + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } // Taken from rt gk d3d 3x2c, is this the non uniform v grid mapping? -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; double mu_max_elc = app->mu_max_elc; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; double mu_max_ion = app->mu_max_ion; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } struct gk_app_ctx create_ctx(void) @@ -496,74 +525,76 @@ struct gk_app_ctx create_ctx(void) double qe = -eV; // electron charge // Geometry and magnetic field. (Taken from Greenfield et al. 1997 table II) - double a_shift = 0.0; // Parameter in Shafranov shift. - double Z_axis = 0.0; // Magnetic axis height [m]. - double R_axis = 1.6714; // Magnetic axis major radius [m]. - double B_axis = 1.54; // Magnetic field at the magnetic axis [T]. - double a_mid = 0.604; // Minor radius at OBMP [m]. - double R0 = R_axis + 0.5 * a_mid; // Major radius of the simulation box [m]. - double r0 = 0.5*a_mid; // Minor radius of the simulation box [m]. - double B0 = B_axis*(R_axis/R0); // Magnetic field magnitude in the simulation box [T]. - double kappa = 1.0; // cirular geometry for comparison with Dimits et al. 2000. - double delta = 0.0; // - double qaxis = 1.2; // Safety factor at r=0. - double qlcfs = 2.0; // Safety factor at the LCFS. + double a_shift = 0.0; // Parameter in Shafranov shift. + double Z_axis = 0.0; // Magnetic axis height [m]. + double R_axis = 1.6714; // Magnetic axis major radius [m]. + double B_axis = 1.54; // Magnetic field at the magnetic axis [T]. + double a_mid = 0.604; // Minor radius at OBMP [m]. + double R0 = R_axis + 0.5 * a_mid; // Major radius of the simulation box [m]. + double r0 = 0.5 * a_mid; // Minor radius of the simulation box [m]. + double B0 = B_axis * (R_axis / R0); // Magnetic field magnitude in the simulation box [T]. + double kappa = 1.0; // cirular geometry for comparison with Dimits et al. 2000. + double delta = 0.0; // + double qaxis = 1.2; // Safety factor at r=0. + double qlcfs = 2.0; // Safety factor at the LCFS. // Plasma parameters. double AMU = 1.0; // Hydrogen. - double mi = mp*AMU; - double Te0 = 2000*eV; - double Ti0 = 2000*eV; - double n0 = 4.5e19; // [1/m^3] according to Fig 5 of Greenfield et al. 1997. + double mi = mp * AMU; + double Te0 = 2000 * eV; + double Ti0 = 2000 * eV; + double n0 = 4.5e19; // [1/m^3] according to Fig 5 of Greenfield et al. 1997. double nuFrac = 1.0; // Collision factor. - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; - double rho_i = vti/omega_ci; + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; + double rho_i = vti / omega_ci; double q0 = qprofile(r0, a_mid, qaxis, qlcfs); - double Cy = r0/q0; // Cylindrical coordinate shift for field-alignment. + double Cy = r0 / q0; // Cylindrical coordinate shift for field-alignment. - // Configuration domain parameters - double Lx = 150*rho_s; // Domain size along x. - double Lz = 2.*M_PI-1e-10; // Domain size along magnetic field. + // Configuration domain parameters + double Lx = 150 * rho_s; // Domain size along x. + double Lz = 2. * M_PI - 1e-10; // Domain size along magnetic field. - double x_min = -Lx/2; - double x_max = Lx/2; - double z_min = -Lz/2; - double z_max = Lz/2; + double x_min = -Lx / 2; + double x_max = Lx / 2; + double z_min = -Lz / 2; + double z_max = Lz / 2; // Initial conditions and gradients double kTi = 6.92; // R/LTi from Dimits et al. 2000. double etai = 3.114; // Lni/LTi from Dimits et al. 2000. - double LTi = R0/kTi; // Ion temperature gradient scale length [m]. - double Ln = LTi*etai; // Density gradient scale length [m]. + double LTi = R0 / kTi; // Ion temperature gradient scale length [m]. + double Ln = LTi * etai; // Density gradient scale length [m]. double LTe = LTi; // Electron temperature gradient scale length [m]. - double t_unit = R0/c_s; + double t_unit = R0 / c_s; // Check the global shear r/q*dq/dr in the middle of the domain - double rL = r0 - Lx/2; - double rR = r0 + Lx/2; + double rL = r0 - Lx / 2; + double rR = r0 + Lx / 2; double qL = qprofile(rL, a_mid, qaxis, qlcfs); double qR = qprofile(rR, a_mid, qaxis, qlcfs); - double dq_dr = (qR-qL)/(rR-rL); - double s0 = r0/q0*dq_dr; + double dq_dr = (qR - qL) / (rR - rL); + double s0 = r0 / q0 * dq_dr; // Expected ITG growth rate and time scale double gamma_itg_norm = 0.1; // Fig. 1 Dimits et al. 2000 (gamma R0/vti) double ky_itg_norm = 0.1; // Fig. 1 Dimits et al. 2000 (k*rho_i) - double gamma_itg = gamma_itg_norm*vti/Ln; - double ky_itg = ky_itg_norm/rho_i; - double t_itg = 1.0/gamma_itg; - double taue = Te0/Ti0; + double gamma_itg = gamma_itg_norm * vti / Ln; + double ky_itg = ky_itg_norm / rho_i; + double t_itg = 1.0 / gamma_itg; + double taue = Te0 / Ti0; // Eq. 2.9 from Sugama & Watanabe, JPP 2006. - double wgam_sw2007 = sqrt(7.0 + 4.0*taue)/2.0 * q0 * (vti/R0/q0) * sqrt(1.0 + 2.0*(23.0 + 16.0*taue + 4.0*taue*taue)/pow(q0*(7.0 + 4.0*taue), 2)); - double t_gam = 2.*M_PI/wgam_sw2007; + double wgam_sw2007 = + sqrt(7.0 + 4.0 * taue) / 2.0 * q0 * (vti / R0 / q0) * + sqrt(1.0 + 2.0 * (23.0 + 16.0 * taue + 4.0 * taue * taue) / pow(q0 * (7.0 + 4.0 * taue), 2)); + double t_gam = 2. * M_PI / wgam_sw2007; - double rhostar = rho_s/a_mid; - double inv_asp_ratio = a_mid/R0; + double rhostar = rho_s / a_mid; + double inv_asp_ratio = a_mid / R0; // Grid parameters int Nx = 4; @@ -573,20 +604,20 @@ struct gk_app_ctx create_ctx(void) int poly_order = 1; // IC, Krook, buffer, and integration lookup tables (LUTs) parameters. - double nu_krook = 1.0/1.0e-7; + double nu_krook = 1.0 / 1.0e-7; int num_cell_buff = 2; // Number of cells in the buffer region on each side. bool can_max = false; // Whether to use the canonical maxwellian formulation for the IC. - int psi_lut_nfact = 100*(poly_order+1); // Resolution factor for the psi lookup table. + int psi_lut_nfact = 100 * (poly_order + 1); // Resolution factor for the psi lookup table. // Velocity box dimensions - double vpar_max_elc = 4.*vte; - double mu_max_elc = 7*Te0/B0; - double vpar_max_ion = 4.*vti; - double mu_max_ion = 7*Ti0/B0; - double t_end = 0.01*t_itg; + double vpar_max_elc = 4. * vte; + double mu_max_elc = 7 * Te0 / B0; + double vpar_max_ion = 4. * vti; + double mu_max_ion = 7 * Ti0 / B0; + double t_end = 0.01 * t_itg; int num_frames = 1; double write_phase_freq = 1.0; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-3; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -607,59 +638,68 @@ struct gk_app_ctx create_ctx(void) .vdim = vdim, .a_shift = a_shift, .R_axis = R_axis, - .R0 = R0 , - .a_mid = a_mid , - .r0 = r0 , - .B0 = B0 , - .kappa = kappa , - .delta = delta , - .q0 = q0 , - .Cy = Cy , - .qaxis = qaxis , - .qlcfs = qlcfs , - .Ln = Ln , - .LTe = LTe , - .LTi = LTi , - .Lx = Lx , - .Lz = Lz , + .R0 = R0, + .a_mid = a_mid, + .r0 = r0, + .B0 = B0, + .kappa = kappa, + .delta = delta, + .q0 = q0, + .Cy = Cy, + .qaxis = qaxis, + .qlcfs = qlcfs, + .Ln = Ln, + .LTe = LTe, + .LTi = LTi, + .Lx = Lx, + .Lz = Lz, .num_cell_buff = num_cell_buff, .nu_krook = nu_krook, .can_max = can_max, - .x_min = x_min, .x_max = x_max, - .z_min = z_min, .z_max = z_max, - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, + .x_min = x_min, + .x_max = x_max, + .z_min = z_min, + .z_max = z_max, + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, .nuFrac = nuFrac, - .Nx = Nx, - .Nz = Nz, - .Nvpar = Nvpar, - .Nmu = Nmu, + .Nx = Nx, + .Nz = Nz, + .Nvpar = Nvpar, + .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, - .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .poly_order = poly_order, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .write_phase_freq = write_phase_freq, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .psi_lut_size = psi_lut_nfact*Nx, + .psi_lut_size = psi_lut_nfact * Nx }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct timespec timer_global = gkyl_wall_clock(); struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Init(&argc, &argv); + } #endif - + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); @@ -668,169 +708,159 @@ main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // context for init functions int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d= x_max) { - fprintf(stderr, "Warning: x = %g out of LUT range [%g, %g]. Clamping to boundaries.\n", x, x_min, x_max); - if (x <= x_min) return lut_val[0]; - if (x >= x_max) return lut_val[N-1]; + fprintf( + stderr, "Warning: x = %g out of LUT range [%g, %g]. Clamping to boundaries.\n", x, x_min, + x_max + ); + if (x <= x_min) { + return lut_val[0]; + } + if (x >= x_max) { + return lut_val[N - 1]; + } } // Assume uniform spacing of the lookup table. - double dx = (x_max - x_min)/(N-1); - int idx = (int)((x - x_min)/dx); + double dx = (x_max - x_min) / (N - 1); + int idx = (int)((x - x_min) / dx); // Safety check. - if (idx < 0 || idx >= N-1) { + if (idx < 0 || idx >= N - 1) { fprintf(stderr, "Error: idx out of bounds in interp_Psi_lut: idx = %d, x = %g\n", idx, x); return 0.0; } // Linear interpolation. double x0 = lut_grid[idx]; - double x1 = lut_grid[idx+1]; + double x1 = lut_grid[idx + 1]; double f0 = lut_val[idx]; - double f1 = lut_val[idx+1]; - return f0 + (f1 - f0)*(x - x0)/(x1 - x0); + double f1 = lut_val[idx + 1]; + return f0 + (f1 - f0) * (x - x0) / (x1 - x0); } // Define the context of the simulation. This stores global parameters. @@ -73,11 +80,11 @@ struct gk_app_ctx { double *dPsidr_int_lut; }; -// Geometry related functions +// Geometry related functions double r_x(double x, double r0) { return x + r0; -} +} // quadratic q profile double qprofile(double r, double a_mid, double qaxis, double qlcfs) @@ -96,7 +103,7 @@ double R_rtheta(double r, double theta, void *ctx) double a_shift = app->a_shift; double R_axis = app->R_axis; double delta = app->delta; - return R_axis - a_shift*r*r/(2.*R_axis) + r*cos(theta + asin(delta)*sin(theta)); + return R_axis - a_shift * r * r / (2. * R_axis) + r * cos(theta + asin(delta) * sin(theta)); } double Z_rtheta(double r, double theta, void *ctx) @@ -104,7 +111,7 @@ double Z_rtheta(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; double Z_axis = app->Z_axis; double kappa = app->kappa; - return Z_axis + kappa*r*sin(theta); + return Z_axis + kappa * r * sin(theta); } double dRdr(double r, double theta, void *ctx) @@ -113,34 +120,34 @@ double dRdr(double r, double theta, void *ctx) double a_shift = app->a_shift; double R_axis = app->R_axis; double delta = app->delta; - return -a_shift*r/(R_axis) + cos(theta + asin(delta)*sin(theta)); + return -a_shift * r / (R_axis) + cos(theta + asin(delta) * sin(theta)); } double dRdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return -r*sin(theta + asin(delta)*sin(theta))*(1.+asin(delta)*cos(theta)); + return -r * sin(theta + asin(delta) * sin(theta)) * (1. + asin(delta) * cos(theta)); } double dZdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*sin(theta); + return kappa * sin(theta); } double dZdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*cos(theta); + return kappa * r * cos(theta); } double Jr(double r, double theta, void *ctx) { - return R_rtheta(r,theta,ctx)*( dRdr(r,theta,ctx) * dZdtheta(r,theta,ctx) - -dRdtheta(r,theta,ctx) * dZdr(r,theta,ctx) ); + return R_rtheta(r, theta, ctx) * (dRdr(r, theta, ctx) * dZdtheta(r, theta, ctx) - + dRdtheta(r, theta, ctx) * dZdr(r, theta, ctx)); } struct integrand_ctx { @@ -155,7 +162,7 @@ double Bphi(double R, void *ctx) struct gk_app_ctx *app = ctx; double B0 = app->B0; double R0 = app->R0; - return B0*R0/R; + return B0 * R0 / R; } double integrand_JoRsq(double t, void *int_ctx) @@ -163,7 +170,7 @@ double integrand_JoRsq(double t, void *int_ctx) struct integrand_ctx *inctx = int_ctx; double r = inctx->r; struct gk_app_ctx *app = inctx->app_ctx; - return Jr(r,t,app) / pow(R_rtheta(r,t,app),2); + return Jr(r, t, app) / pow(R_rtheta(r, t, app), 2); } double intdPsidr(double r, void *ctx) @@ -171,7 +178,7 @@ double intdPsidr(double r, void *ctx) struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - integral = gkyl_dbl_exp(integrand_JoRsq, &tmp_ctx, 0., 2.*M_PI, 7, 1e-10); + integral = gkyl_dbl_exp(integrand_JoRsq, &tmp_ctx, 0., 2. * M_PI, 7, 1e-10); return integral.res; } @@ -181,9 +188,9 @@ double dPsidr(double r, double theta, void *ctx) struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; double integral_val = interp_1x_lut(r, app->r_lut, app->dPsidr_int_lut, app->psi_lut_size); - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); - return ( R*Bt/(2.*M_PI*qprofile(r, app->a_mid, app->qaxis, app->qlcfs)))*integral_val; + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); + return (R * Bt / (2. * M_PI * qprofile(r, app->a_mid, app->qaxis, app->qlcfs))) * integral_val; } double integrant_dpsi(double r, void *int_ctx) @@ -191,7 +198,7 @@ double integrant_dpsi(double r, void *int_ctx) struct integrand_ctx *inctx = int_ctx; struct gk_app_ctx *app = inctx->app_ctx; double q = qprofile(r, app->a_mid, app->qaxis, app->qlcfs); - double dpsi = -r/q; // This is valid in the circular limit. The minus sign comes dBtheta/r < 0 + double dpsi = -r / q; // This is valid in the circular limit. The minus sign comes dBtheta/r < 0 return dpsi; // I am not sure about this sign, I think it must be from dx/dr = -1. // return -dPsidr(r, inctx->theta, app); // Seems to be the exact way but it makes the profile super flat (and -1 factor looks important here). } @@ -205,13 +212,16 @@ double intPsi(double r0, double r, double theta, void *ctx) return integral.res; } -double compute_alpha_integral(double r, double twrap, void *ctx) { +double compute_alpha_integral(double r, double twrap, void *ctx) +{ struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - if (twrap == 0.0) return 0.0; - + if (twrap == 0.0) { + return 0.0; + } + if (0. < twrap) { integral = gkyl_dbl_exp(integrand_JoRsq, &tmp_ctx, 0., twrap, 7, 1e-10); return integral.res; @@ -225,49 +235,54 @@ double alpha(double r, double theta, double phi, void *ctx) { struct gk_app_ctx *app = ctx; double twrap = theta; - while (twrap < -M_PI) twrap = twrap+2.*M_PI; - while (M_PI < twrap) twrap = twrap-2.*M_PI; + while (twrap < -M_PI) { + twrap = twrap + 2. * M_PI; + } + while (M_PI < twrap) { + twrap = twrap - 2. * M_PI; + } double integral_val = compute_alpha_integral(r, twrap, ctx); - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); - return phi - R*Bt*integral_val/dPsidr(r,theta,ctx); + return phi - R * Bt * integral_val / dPsidr(r, theta, ctx); } double gradr(double r, double theta, void *ctx) { - return (R_rtheta(r,theta,ctx)/Jr(r,theta,ctx))*sqrt(pow(dRdtheta(r,theta,ctx),2) + pow(dZdtheta(r,theta,ctx),2)); + return (R_rtheta(r, theta, ctx) / Jr(r, theta, ctx)) * + sqrt(pow(dRdtheta(r, theta, ctx), 2) + pow(dZdtheta(r, theta, ctx), 2)); } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; struct gk_app_ctx *app = ctx; double a_mid = app->a_mid; double Cy = app->Cy; double r0 = app->r0; - double r = r_x(x,r0); - double Bt = Bphi(R_rtheta(r,z,ctx),ctx); - double Bp = dPsidr(r,z,ctx)/R_rtheta(r,z,ctx)*gradr(r,z,ctx); - - double drdtheta = dRdtheta(r,z,ctx); - double dzdtheta = dZdtheta(r,z,ctx); - double den = sqrt(pow(drdtheta,2) + pow(dzdtheta,2)); - double B_r = Bp*drdtheta/den; - double B_z = Bp*dzdtheta/den; - double phi = y/Cy + alpha(r, z, 0, ctx); + double r = r_x(x, r0); + double Bt = Bphi(R_rtheta(r, z, ctx), ctx); + double Bp = dPsidr(r, z, ctx) / R_rtheta(r, z, ctx) * gradr(r, z, ctx); + + double drdtheta = dRdtheta(r, z, ctx); + double dzdtheta = dZdtheta(r, z, ctx); + double den = sqrt(pow(drdtheta, 2) + pow(dzdtheta, 2)); + double B_r = Bp * drdtheta / den; + double B_z = Bp * dzdtheta / den; + double phi = y / Cy + alpha(r, z, 0, ctx); double R = R_rtheta(r, z, ctx); - // xc are computational coords. + // xc are computational coords. // Set Cartesian components of magnetic field. fout[0] = B_r * cos(phi) + Bt * sin(phi); fout[1] = B_r * sin(phi) - Bt * cos(phi); fout[2] = B_z; } -void bc_shift_func_lo(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_lo(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0]; struct gk_app_ctx *app = ctx; @@ -278,10 +293,10 @@ void bc_shift_func_lo(double t, const double *xc, double* GKYL_RESTRICT fout, vo double r = r_x(x, app->r0); - fout[0] = Cy*( alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx) ); + fout[0] = Cy * (alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx)); } -void bc_shift_func_up(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_up(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0]; struct gk_app_ctx *app = ctx; @@ -292,16 +307,16 @@ void bc_shift_func_up(double t, const double *xc, double* GKYL_RESTRICT fout, vo double r = r_x(x, app->r0); - fout[0] = -Cy*( alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx) ); + fout[0] = -Cy * (alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx)); } double Bmag(double r, double theta, void *ctx) { - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); - double Bp = dPsidr(r,theta,ctx)/R_rtheta(r,theta,ctx)*gradr(r,theta,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); + double Bp = dPsidr(r, theta, ctx) / R_rtheta(r, theta, ctx) * gradr(r, theta, ctx); - return sqrt(pow(Bt,2) + pow(Bp,2)); + return sqrt(pow(Bt, 2) + pow(Bp, 2)); } double rbar(double m, double q, double r, double theta, double vpar, double mu, void *ctx) @@ -309,7 +324,7 @@ double rbar(double m, double q, double r, double theta, double vpar, double mu, struct gk_app_ctx *app = ctx; double e = GKYL_ELEMENTARY_CHARGE; - double R = R_rtheta(r,theta,ctx); + double R = R_rtheta(r, theta, ctx); double r0 = app->r0; double R0 = app->R0; double q0 = app->q0; @@ -317,29 +332,28 @@ double rbar(double m, double q, double r, double theta, double vpar, double mu, double psi_r = interp_1x_lut(r, app->r_lut, app->psi_lut, app->psi_lut_size); double psi_r0 = interp_1x_lut(r0, app->r_lut, app->psi_lut, app->psi_lut_size); - double rpsi = q0/r0 * (psi_r - psi_r0); - + double rpsi = q0 / r0 * (psi_r - psi_r0); + double rmin = r0 - app->x_min; double rmax = r0 + app->x_max; double zmin = app->z_min; double zmax = app->z_max; double Bmax = Bmag(rmax, zmax, ctx); - + double B0 = app->B0; - double B = Bmag(r,theta,ctx); - double E = 0.5 * m * pow(vpar,2) + mu*B; - double sgnvpar = vpar>0 ? 1.0 : -1.0; - double vparbar = E - mu*Bmax > 0 ? - sgnvpar*sqrt(2/m)*sqrt(E - mu*Bmax) : 0.0; + double B = Bmag(r, theta, ctx); + double E = 0.5 * m * pow(vpar, 2) + mu * B; + double sgnvpar = vpar > 0 ? 1.0 : -1.0; + double vparbar = E - mu * Bmax > 0 ? sgnvpar * sqrt(2 / m) * sqrt(E - mu * Bmax) : 0.0; - double rvpar = m*q0/(q*B0*r0) * (R*vpar - R0*vparbar); + double rvpar = m * q0 / (q * B0 * r0) * (R * vpar - R0 * vparbar); double rbar = r0 - rpsi - rvpar; return app->can_max ? rbar : r; } -// Static BGK source term to maintain eq. profile at lower x boundary. +// Static BGK source term to maintain eq. profile at lower x boundary. void double_buffer_profile(double t, const double *xn, double *fout, void *ctx) { double x = xn[0]; @@ -352,7 +366,8 @@ void double_buffer_profile(double t, const double *xn, double *fout, void *ctx) // See Eq. 49 of V. Grandgirard et al. / Computer Physics Communications 207 (2016) 35–68 double Bs = 0.015; // Buffer transition width as a fraction of the domain size. double Bl = app->num_cell_buff / (double)nx; // Buffer fraction. - Hbuff = 1 + 0.5 * (tanh((x - x_max + Bl*Lx)/(Bs*Lx)) - tanh((x - x_min - Bl*Lx)/(Bs*Lx))); + Hbuff = + 1 + 0.5 * (tanh((x - x_max + Bl * Lx) / (Bs * Lx)) - tanh((x - x_min - Bl * Lx) / (Bs * Lx))); fout[0] = Hbuff * app->nu_krook; } @@ -360,8 +375,8 @@ double tanh_profile(double x, double v0, double Lgrad, void *ctx) { struct gk_app_ctx *app = ctx; // Profile use in Gysela (see V. Grandgirard et al. / Computer Physics Communications 207 (2016) 35–68). - double buff_frac = (double)app->num_cell_buff / app->Nx; - double delta = 0.5*(1-buff_frac) * app->Lx; + double buff_frac = (double)app->num_cell_buff / app->Nx; + double delta = 0.5 * (1 - buff_frac) * app->Lx; double arg = x / (app->a_mid * delta); double prof_factor = (app->a_mid * delta) / Lgrad; return v0 * exp(-prof_factor * tanh(arg)); @@ -390,10 +405,12 @@ double temp_init_ion(double x, void *ctx) double maxellian(double m, double n, double T, double E) { - return n/pow(2*M_PI*T/m,1.5) * exp(-E/T); + return n / pow(2 * M_PI * T / m, 1.5) * exp(-E / T); } -void eval_canon_maxwellian_e(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_canon_maxwellian_e( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_app_ctx *app = ctx; double x = xn[0], y = xn[1], z = xn[2], vpar = xn[3], mu = xn[4]; @@ -409,16 +426,19 @@ void eval_canon_maxwellian_e(double t, const double* GKYL_RESTRICT xn, double* G // Initial perturbation. double m_mode = 3.0; // Target k_y * rho_s ~ 0.37 - double alpha_pert = 1.0e-4; // Small amplitude perturbation - double envelope = exp(-pow(xb / (app->Lx / 4.0), 2)) * exp(-pow((theta - M_PI) / (M_PI / 4.0), 2)); + double alpha_pert = 1.0e-4; // Small amplitude perturbation + double envelope = + exp(-pow(xb / (app->Lx / 4.0), 2)) * exp(-pow((theta - M_PI) / (M_PI / 4.0), 2)); dens = dens * (1.0 + alpha_pert * envelope * cos(m_mode * 2.0 * M_PI * y / app->Ly)); - double energy = 0.5*m*pow(vpar,2) + mu*Bmag(r,theta,ctx); + double energy = 0.5 * m * pow(vpar, 2) + mu * Bmag(r, theta, ctx); fout[0] = maxellian(m, dens, temp, energy); } -void eval_canon_maxwellian_i(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_canon_maxwellian_i( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_app_ctx *app = ctx; double x = xn[0], y = xn[1], z = xn[2], vpar = xn[3], mu = xn[4]; @@ -432,28 +452,32 @@ void eval_canon_maxwellian_i(double t, const double* GKYL_RESTRICT xn, double* G double dens = density_init(xb, ctx); double temp = temp_init_ion(xb, ctx); - double energy = 0.5*m*pow(vpar,2) + mu*Bmag(r,theta,ctx); + double energy = 0.5 * m * pow(vpar, 2) + mu * Bmag(r, theta, ctx); fout[0] = maxellian(m, dens, temp, energy); } -void eval_dens_ic(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_dens_ic(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = density_init(xn[0], ctx); } -void eval_temp_elc_ic(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_temp_elc_ic( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = temp_init_elc(xn[0], ctx); } -void eval_temp_ion_ic(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_temp_ion_ic( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = temp_init_ion(xn[0], ctx); } // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; @@ -461,52 +485,56 @@ void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) double a_mid = app->a_mid; double Cy = app->Cy; - double r = r_x(x,app->r0); + double r = r_x(x, app->r0); // Map to cylindrical (R, Z, phi) coordinates. double R = R_rtheta(r, z, ctx); double Z = Z_rtheta(r, z, ctx); - double phi = y/Cy + alpha(r, z, 0, ctx); + double phi = y / Cy + alpha(r, z, 0, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + double X = R * cos(phi); + double Y = R * sin(phi); + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } // Taken from rt gk d3d 3x2c, is this the non uniform v grid mapping? -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; double mu_max_elc = app->mu_max_elc; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; double mu_max_ion = app->mu_max_ion; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } struct gk_app_ctx create_ctx(void) @@ -519,80 +547,82 @@ struct gk_app_ctx create_ctx(void) double qe = -eV; // electron charge // Geometry and magnetic field. (Taken from Greenfield et al. 1997 table II) - double a_shift = 0.0; // Parameter in Shafranov shift. - double Z_axis = 0.0; // Magnetic axis height [m]. - double R_axis = 1.6714; // Magnetic axis major radius [m]. - double B_axis = 1.54; // Magnetic field at the magnetic axis [T]. - double a_mid = 0.604; // Minor radius at OBMP [m]. - double R0 = R_axis + 0.5 * a_mid; // Major radius of the simulation box [m]. - double r0 = 0.5*a_mid; // Minor radius of the simulation box [m]. - double B0 = B_axis*(R_axis/R0); // Magnetic field magnitude in the simulation box [T]. - double kappa = 1.0; // cirular geometry for comparison with Dimits et al. 2000. - double delta = 0.0; // - double qaxis = 1.2; // Safety factor at r=0. - double qlcfs = 2.0; // Safety factor at the LCFS. + double a_shift = 0.0; // Parameter in Shafranov shift. + double Z_axis = 0.0; // Magnetic axis height [m]. + double R_axis = 1.6714; // Magnetic axis major radius [m]. + double B_axis = 1.54; // Magnetic field at the magnetic axis [T]. + double a_mid = 0.604; // Minor radius at OBMP [m]. + double R0 = R_axis + 0.5 * a_mid; // Major radius of the simulation box [m]. + double r0 = 0.5 * a_mid; // Minor radius of the simulation box [m]. + double B0 = B_axis * (R_axis / R0); // Magnetic field magnitude in the simulation box [T]. + double kappa = 1.0; // cirular geometry for comparison with Dimits et al. 2000. + double delta = 0.0; // + double qaxis = 1.2; // Safety factor at r=0. + double qlcfs = 2.0; // Safety factor at the LCFS. // Plasma parameters. double AMU = 1.0; // Hydrogen. - double mi = mp*AMU; - double Te0 = 2000*eV; - double Ti0 = 2000*eV; - double n0 = 4.5e19; // [1/m^3] according to Fig 5 of Greenfield et al. 1997. + double mi = mp * AMU; + double Te0 = 2000 * eV; + double Ti0 = 2000 * eV; + double n0 = 4.5e19; // [1/m^3] according to Fig 5 of Greenfield et al. 1997. double nuFrac = 1.0; // Collision factor. - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; - double rho_i = vti/omega_ci; + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; + double rho_i = vti / omega_ci; double q0 = qprofile(r0, a_mid, qaxis, qlcfs); - double Cy = r0/q0; // Cylindrical coordinate shift for field-alignment. + double Cy = r0 / q0; // Cylindrical coordinate shift for field-alignment. - // Configuration domain parameters - double Lx = 150*rho_s; // Domain size along x. - double Ly = 150*rho_s; // Domain size along y. - double Lz = 2.*M_PI-1e-10; // Domain size along magnetic field. + // Configuration domain parameters + double Lx = 150 * rho_s; // Domain size along x. + double Ly = 150 * rho_s; // Domain size along y. + double Lz = 2. * M_PI - 1e-10; // Domain size along magnetic field. // Adjust the domain size along y to have integer toroidal mode number. // We need: 2*pi*Cy/Ly = integer. - Ly = 2.*M_PI*Cy/round(2.*M_PI*Cy/Ly); + Ly = 2. * M_PI * Cy / round(2. * M_PI * Cy / Ly); - double x_min = -Lx/2; - double x_max = Lx/2; - double y_min = -Ly/2; - double y_max = Ly/2; - double z_min = -Lz/2; - double z_max = Lz/2; + double x_min = -Lx / 2; + double x_max = Lx / 2; + double y_min = -Ly / 2; + double y_max = Ly / 2; + double z_min = -Lz / 2; + double z_max = Lz / 2; // Initial conditions and gradients double kTi = 6.92; // R/LTi from Dimits et al. 2000. double etai = 3.114; // Lni/LTi from Dimits et al. 2000. - double LTi = R0/kTi; // Ion temperature gradient scale length [m]. - double Ln = LTi*etai; // Density gradient scale length [m]. + double LTi = R0 / kTi; // Ion temperature gradient scale length [m]. + double Ln = LTi * etai; // Density gradient scale length [m]. double LTe = LTi; // Electron temperature gradient scale length [m]. - double t_unit = R0/c_s; + double t_unit = R0 / c_s; // Check the global shear r/q*dq/dr in the middle of the domain - double rL = r0 - Lx/2; - double rR = r0 + Lx/2; + double rL = r0 - Lx / 2; + double rR = r0 + Lx / 2; double qL = qprofile(rL, a_mid, qaxis, qlcfs); double qR = qprofile(rR, a_mid, qaxis, qlcfs); - double dq_dr = (qR-qL)/(rR-rL); - double s0 = r0/q0*dq_dr; + double dq_dr = (qR - qL) / (rR - rL); + double s0 = r0 / q0 * dq_dr; // Expected ITG growth rate and time scale double gamma_itg_norm = 0.1; // Fig. 1 Dimits et al. 2000 (gamma R0/vti) double ky_itg_norm = 0.1; // Fig. 1 Dimits et al. 2000 (k*rho_i) - double gamma_itg = gamma_itg_norm*vti/Ln; - double ky_itg = ky_itg_norm/rho_i; - double t_itg = 1.0/gamma_itg; - double taue = Te0/Ti0; + double gamma_itg = gamma_itg_norm * vti / Ln; + double ky_itg = ky_itg_norm / rho_i; + double t_itg = 1.0 / gamma_itg; + double taue = Te0 / Ti0; // Eq. 2.9 from Sugama & Watanabe, JPP 2006. - double wgam_sw2007 = sqrt(7.0 + 4.0*taue)/2.0 * q0 * (vti/R0/q0) * sqrt(1.0 + 2.0*(23.0 + 16.0*taue + 4.0*taue*taue)/pow(q0*(7.0 + 4.0*taue), 2)); - double t_gam = 2.*M_PI/wgam_sw2007; + double wgam_sw2007 = + sqrt(7.0 + 4.0 * taue) / 2.0 * q0 * (vti / R0 / q0) * + sqrt(1.0 + 2.0 * (23.0 + 16.0 * taue + 4.0 * taue * taue) / pow(q0 * (7.0 + 4.0 * taue), 2)); + double t_gam = 2. * M_PI / wgam_sw2007; - double rhostar = rho_s/a_mid; - double inv_asp_ratio = a_mid/R0; + double rhostar = rho_s / a_mid; + double inv_asp_ratio = a_mid / R0; // Grid parameters int Nx = 4; @@ -603,20 +633,20 @@ struct gk_app_ctx create_ctx(void) int poly_order = 1; // IC, Krook, buffer, and integration lookup tables (LUTs) parameters. - double nu_krook = 1.0/1.0e-7; + double nu_krook = 1.0 / 1.0e-7; int num_cell_buff = 2; // Number of cells in the buffer region on each side. bool can_max = false; // Whether to use the canonical maxwellian formulation for the IC. - int psi_lut_nfact = 100*(poly_order+1); // Resolution factor for the psi lookup table. + int psi_lut_nfact = 100 * (poly_order + 1); // Resolution factor for the psi lookup table. // Velocity box dimensions - double vpar_max_elc = 4.*vte; - double mu_max_elc = 7*Te0/B0; - double vpar_max_ion = 4.*vti; - double mu_max_ion = 7*Ti0/B0; - double t_end = 0.01*t_itg; + double vpar_max_elc = 4. * vte; + double mu_max_elc = 7 * Te0 / B0; + double vpar_max_ion = 4. * vti; + double mu_max_ion = 7 * Ti0 / B0; + double t_end = 0.01 * t_itg; int num_frames = 1; double write_phase_freq = 1.0; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-3; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -637,62 +667,72 @@ struct gk_app_ctx create_ctx(void) .vdim = vdim, .a_shift = a_shift, .R_axis = R_axis, - .R0 = R0 , - .a_mid = a_mid , - .r0 = r0 , - .B0 = B0 , - .kappa = kappa , - .delta = delta , - .q0 = q0 , - .Cy = Cy , - .qaxis = qaxis , - .qlcfs = qlcfs , - .Ln = Ln , - .LTe = LTe , - .LTi = LTi , - .Lx = Lx , - .Ly = Ly , - .Lz = Lz , + .R0 = R0, + .a_mid = a_mid, + .r0 = r0, + .B0 = B0, + .kappa = kappa, + .delta = delta, + .q0 = q0, + .Cy = Cy, + .qaxis = qaxis, + .qlcfs = qlcfs, + .Ln = Ln, + .LTe = LTe, + .LTi = LTi, + .Lx = Lx, + .Ly = Ly, + .Lz = Lz, .num_cell_buff = num_cell_buff, .nu_krook = nu_krook, .can_max = can_max, - .x_min = x_min, .x_max = x_max, - .y_min = y_min, .y_max = y_max, - .z_min = z_min, .z_max = z_max, - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, + .x_min = x_min, + .x_max = x_max, + .y_min = y_min, + .y_max = y_max, + .z_min = z_min, + .z_max = z_max, + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, .nuFrac = nuFrac, - .Nx = Nx, - .Ny = Ny, - .Nz = Nz, - .Nvpar = Nvpar, - .Nmu = Nmu, + .Nx = Nx, + .Ny = Ny, + .Nz = Nz, + .Nvpar = Nvpar, + .Nmu = Nmu, .cells = {Nx, Ny, Nz, Nvpar, Nmu}, - .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .poly_order = poly_order, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .write_phase_freq = write_phase_freq, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .psi_lut_size = psi_lut_nfact*Nx, + .psi_lut_size = psi_lut_nfact * Nx }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct timespec timer_global = gkyl_wall_clock(); struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Init(&argc, &argv); + } #endif - + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); @@ -701,158 +741,146 @@ main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // context for init functions int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d= x_max) { - fprintf(stderr, "Warning: x = %g out of LUT range [%g, %g]. Clamping to boundaries.\n", x, x_min, x_max); - if (x <= x_min) return lut_val[0]; - if (x >= x_max) return lut_val[N-1]; + fprintf( + stderr, "Warning: x = %g out of LUT range [%g, %g]. Clamping to boundaries.\n", x, x_min, + x_max + ); + if (x <= x_min) { + return lut_val[0]; + } + if (x >= x_max) { + return lut_val[N - 1]; + } } // Assume uniform spacing of the lookup table. - double dx = (x_max - x_min)/(N-1); - int idx = (int)((x - x_min)/dx); + double dx = (x_max - x_min) / (N - 1); + int idx = (int)((x - x_min) / dx); // Safety check. - if (idx < 0 || idx >= N-1) { + if (idx < 0 || idx >= N - 1) { fprintf(stderr, "Error: idx out of bounds in interp_Psi_lut: idx = %d, x = %g\n", idx, x); return 0.0; } // Linear interpolation. double x0 = lut_grid[idx]; - double x1 = lut_grid[idx+1]; + double x1 = lut_grid[idx + 1]; double f0 = lut_val[idx]; - double f1 = lut_val[idx+1]; - return f0 + (f1 - f0)*(x - x0)/(x1 - x0); + double f1 = lut_val[idx + 1]; + return f0 + (f1 - f0) * (x - x0) / (x1 - x0); } // Define the context of the simulation. This stores global parameters. @@ -66,17 +73,17 @@ struct gk_app_ctx { double *dPsidr_int_lut; }; -// Geometry related functions +// Geometry related functions double r_x(double x, double r0) { return x + r0; -} +} // quadratic q profile double qprofile(double r, double a_mid, double qaxis, double qlcfs) { // Profile from Grandgirard et al. 2008 - return 1.0 + 2.78 * pow(r/a_mid,2.8); + return 1.0 + 2.78 * pow(r / a_mid, 2.8); // Profile from Qu et al. 2026 https://hal.science/hal-05342386v2 // return 0.86 - 0.16 * (r/a_mid) + 2.52 * pow(r/a_mid,2); // return 1.4; @@ -89,7 +96,7 @@ double R_rtheta(double r, double theta, void *ctx) double a_shift = app->a_shift; double R_axis = app->R_axis; double delta = app->delta; - return R_axis - a_shift*r*r/(2.*R_axis) + r*cos(theta + asin(delta)*sin(theta)); + return R_axis - a_shift * r * r / (2. * R_axis) + r * cos(theta + asin(delta) * sin(theta)); } double Z_rtheta(double r, double theta, void *ctx) @@ -97,7 +104,7 @@ double Z_rtheta(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; double Z_axis = app->Z_axis; double kappa = app->kappa; - return Z_axis + kappa*r*sin(theta); + return Z_axis + kappa * r * sin(theta); } double dRdr(double r, double theta, void *ctx) @@ -106,34 +113,34 @@ double dRdr(double r, double theta, void *ctx) double a_shift = app->a_shift; double R_axis = app->R_axis; double delta = app->delta; - return -a_shift*r/(R_axis) + cos(theta + asin(delta)*sin(theta)); + return -a_shift * r / (R_axis) + cos(theta + asin(delta) * sin(theta)); } double dRdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return -r*sin(theta + asin(delta)*sin(theta))*(1.+asin(delta)*cos(theta)); + return -r * sin(theta + asin(delta) * sin(theta)) * (1. + asin(delta) * cos(theta)); } double dZdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*sin(theta); + return kappa * sin(theta); } double dZdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*cos(theta); + return kappa * r * cos(theta); } double Jr(double r, double theta, void *ctx) { - return R_rtheta(r,theta,ctx)*( dRdr(r,theta,ctx) * dZdtheta(r,theta,ctx) - -dRdtheta(r,theta,ctx) * dZdr(r,theta,ctx) ); + return R_rtheta(r, theta, ctx) * (dRdr(r, theta, ctx) * dZdtheta(r, theta, ctx) - + dRdtheta(r, theta, ctx) * dZdr(r, theta, ctx)); } struct integrand_ctx { @@ -148,7 +155,7 @@ double Bphi(double R, void *ctx) struct gk_app_ctx *app = ctx; double B0 = app->B0; double R0 = app->R0; - return B0*R0/R; + return B0 * R0 / R; } double integrand_JoRsq(double t, void *int_ctx) @@ -156,7 +163,7 @@ double integrand_JoRsq(double t, void *int_ctx) struct integrand_ctx *inctx = int_ctx; double r = inctx->r; struct gk_app_ctx *app = inctx->app_ctx; - return Jr(r,t,app) / pow(R_rtheta(r,t,app),2); + return Jr(r, t, app) / pow(R_rtheta(r, t, app), 2); } double intdPsidr(double r, void *ctx) @@ -164,7 +171,7 @@ double intdPsidr(double r, void *ctx) struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - integral = gkyl_dbl_exp(integrand_JoRsq, &tmp_ctx, 0., 2.*M_PI, 7, 1e-10); + integral = gkyl_dbl_exp(integrand_JoRsq, &tmp_ctx, 0., 2. * M_PI, 7, 1e-10); return integral.res; } @@ -174,9 +181,9 @@ double dPsidr(double r, double theta, void *ctx) struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; double integral_val = interp_1x_lut(r, app->r_lut, app->dPsidr_int_lut, app->psi_lut_size); - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); - return ( R*Bt/(2.*M_PI*qprofile(r, app->a_mid, app->qaxis, app->qlcfs)))*integral_val; + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); + return (R * Bt / (2. * M_PI * qprofile(r, app->a_mid, app->qaxis, app->qlcfs))) * integral_val; } double integrant_dpsi(double r, void *int_ctx) @@ -184,7 +191,7 @@ double integrant_dpsi(double r, void *int_ctx) struct integrand_ctx *inctx = int_ctx; struct gk_app_ctx *app = inctx->app_ctx; double q = qprofile(r, app->a_mid, app->qaxis, app->qlcfs); - double dpsi = -r/q; // This is valid in the circular limit. The minus sign comes dBtheta/r < 0 + double dpsi = -r / q; // This is valid in the circular limit. The minus sign comes dBtheta/r < 0 return dpsi; // I am not sure about this sign, I think it must be from dx/dr = -1. // return -dPsidr(r, inctx->theta, app); // Seems to be the exact way but it makes the profile super flat (and -1 factor looks important here). } @@ -198,13 +205,16 @@ double intPsi(double r0, double r, double theta, void *ctx) return integral.res; } -double compute_alpha_integral(double r, double twrap, void *ctx) { +double compute_alpha_integral(double r, double twrap, void *ctx) +{ struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - if (twrap == 0.0) return 0.0; - + if (twrap == 0.0) { + return 0.0; + } + if (0. < twrap) { integral = gkyl_dbl_exp(integrand_JoRsq, &tmp_ctx, 0., twrap, 7, 1e-10); return integral.res; @@ -218,49 +228,54 @@ double alpha(double r, double theta, double phi, void *ctx) { struct gk_app_ctx *app = ctx; double twrap = theta; - while (twrap < -M_PI) twrap = twrap+2.*M_PI; - while (M_PI < twrap) twrap = twrap-2.*M_PI; + while (twrap < -M_PI) { + twrap = twrap + 2. * M_PI; + } + while (M_PI < twrap) { + twrap = twrap - 2. * M_PI; + } double integral_val = compute_alpha_integral(r, twrap, ctx); - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); - return phi - R*Bt*integral_val/dPsidr(r,theta,ctx); + return phi - R * Bt * integral_val / dPsidr(r, theta, ctx); } double gradr(double r, double theta, void *ctx) { - return (R_rtheta(r,theta,ctx)/Jr(r,theta,ctx))*sqrt(pow(dRdtheta(r,theta,ctx),2) + pow(dZdtheta(r,theta,ctx),2)); + return (R_rtheta(r, theta, ctx) / Jr(r, theta, ctx)) * + sqrt(pow(dRdtheta(r, theta, ctx), 2) + pow(dZdtheta(r, theta, ctx), 2)); } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; struct gk_app_ctx *app = ctx; double a_mid = app->a_mid; double Cy = app->Cy; double r0 = app->r0; - double r = r_x(x,r0); - double Bt = Bphi(R_rtheta(r,z,ctx),ctx); - double Bp = dPsidr(r,z,ctx)/R_rtheta(r,z,ctx)*gradr(r,z,ctx); - - double drdtheta = dRdtheta(r,z,ctx); - double dzdtheta = dZdtheta(r,z,ctx); - double den = sqrt(pow(drdtheta,2) + pow(dzdtheta,2)); - double B_r = Bp*drdtheta/den; - double B_z = Bp*dzdtheta/den; - double phi = y/Cy + alpha(r, z, 0, ctx); + double r = r_x(x, r0); + double Bt = Bphi(R_rtheta(r, z, ctx), ctx); + double Bp = dPsidr(r, z, ctx) / R_rtheta(r, z, ctx) * gradr(r, z, ctx); + + double drdtheta = dRdtheta(r, z, ctx); + double dzdtheta = dZdtheta(r, z, ctx); + double den = sqrt(pow(drdtheta, 2) + pow(dzdtheta, 2)); + double B_r = Bp * drdtheta / den; + double B_z = Bp * dzdtheta / den; + double phi = y / Cy + alpha(r, z, 0, ctx); double R = R_rtheta(r, z, ctx); - // xc are computational coords. + // xc are computational coords. // Set Cartesian components of magnetic field. fout[0] = B_r * cos(phi) + Bt * sin(phi); fout[1] = B_r * sin(phi) - Bt * cos(phi); fout[2] = B_z; } -void bc_shift_func_lo(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_lo(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0]; struct gk_app_ctx *app = ctx; @@ -271,10 +286,10 @@ void bc_shift_func_lo(double t, const double *xc, double* GKYL_RESTRICT fout, vo double r = r_x(x, app->r0); - fout[0] = Cy*( alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx) ); + fout[0] = Cy * (alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx)); } -void bc_shift_func_up(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_up(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0]; struct gk_app_ctx *app = ctx; @@ -285,10 +300,10 @@ void bc_shift_func_up(double t, const double *xc, double* GKYL_RESTRICT fout, vo double r = r_x(x, app->r0); - fout[0] = -Cy*( alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx) ); + fout[0] = -Cy * (alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx)); } -void eval_distf_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_distf_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2], vpar = xn[3], mu = xn[4]; @@ -298,17 +313,19 @@ void eval_distf_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR double Lz = app->Lz; // Gaussian in conf-space, constant in v-space. - + double loc[] = {0.0, 0.0, 0.0}; - double sig[] = {Lx/7.0, Ly/7.0, Lz/10.0}; + double sig[] = {Lx / 7.0, Ly / 7.0, Lz / 10.0}; - fout[0] = exp(- pow(x-loc[0],2)/(2.0*pow(sig[0],2)) - - pow(y-loc[1],2)/(2.0*pow(sig[1],2)) - - pow(z-loc[2],2)/(2.0*pow(sig[2],2))); + fout[0] = exp( + -pow(x - loc[0], 2) / (2.0 * pow(sig[0], 2)) - pow(y - loc[1], 2) / (2.0 * pow(sig[1], 2)) - + pow(z - loc[2], 2) / (2.0 * pow(sig[2], 2)) + ); } -void -passive_velocity_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void passive_velocity_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; @@ -323,7 +340,7 @@ passive_velocity_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST } // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; @@ -331,17 +348,19 @@ void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) double a_mid = app->a_mid; double Cy = app->Cy; - double r = r_x(x,app->r0); + double r = r_x(x, app->r0); // Map to cylindrical (R, Z, phi) coordinates. double R = R_rtheta(r, z, ctx); double Z = Z_rtheta(r, z, ctx); - double phi = y/Cy + alpha(r, z, 0, ctx); + double phi = y / Cy + alpha(r, z, 0, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + double X = R * cos(phi); + double Y = R * sin(phi); + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } struct gk_app_ctx create_ctx(void) @@ -355,60 +374,60 @@ struct gk_app_ctx create_ctx(void) // Geometry and magnetic field. (Taken from Greenfield et al. 1997 table II) double a_shift = 0.0; // Parameter in Shafranov shift. - double Z_axis = 0.0; // Magnetic axis height [m]. - double R_axis = 1.6714; // Magnetic axis major radius [m]. - double B_axis = 1.54; // Magnetic field at the magnetic axis [T]. - double a_mid = 0.604; // Minor radius at OBMP [m]. - double R0 = R_axis + 0.5 * a_mid; // Major radius of the simulation box [m]. - double r0 = 0.5*a_mid; // Minor radius of the simulation box [m]. - double B0 = B_axis*(R_axis/R0); // Magnetic field magnitude in the simulation box [T]. - double kappa = 1.0; // cirular geometry for comparison with Dimits et al. 2000. - double delta = 0.0; // - double qaxis = 1.2; // Safety factor at r=0. - double qlcfs = 2.0; // Safety factor at the LCFS. + double Z_axis = 0.0; // Magnetic axis height [m]. + double R_axis = 1.6714; // Magnetic axis major radius [m]. + double B_axis = 1.54; // Magnetic field at the magnetic axis [T]. + double a_mid = 0.604; // Minor radius at OBMP [m]. + double R0 = R_axis + 0.5 * a_mid; // Major radius of the simulation box [m]. + double r0 = 0.5 * a_mid; // Minor radius of the simulation box [m]. + double B0 = B_axis * (R_axis / R0); // Magnetic field magnitude in the simulation box [T]. + double kappa = 1.0; // cirular geometry for comparison with Dimits et al. 2000. + double delta = 0.0; // + double qaxis = 1.2; // Safety factor at r=0. + double qlcfs = 2.0; // Safety factor at the LCFS. // Plasma parameters. double AMU = 1.0; // Hydrogen. - double mi = mp*AMU; - double Te0 = 2000*eV; - double Ti0 = 2000*eV; - double n0 = 4.5e19; // [1/m^3] according to Fig 5 of Greenfield et al. 1997. + double mi = mp * AMU; + double Te0 = 2000 * eV; + double Ti0 = 2000 * eV; + double n0 = 4.5e19; // [1/m^3] according to Fig 5 of Greenfield et al. 1997. double nuFrac = 1.0; // Collision factor. - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; - double rho_i = vti/omega_ci; + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; + double rho_i = vti / omega_ci; double q0 = qprofile(r0, a_mid, qaxis, qlcfs); - double Cy = r0/q0; // Cylindrical coordinate shift for field-alignment. + double Cy = r0 / q0; // Cylindrical coordinate shift for field-alignment. - // Configuration domain parameters - double Lx = 150*rho_s; // Domain size along x. - double Ly = 150*rho_s; // Domain size along y. - double Lz = 2.*M_PI-1e-10; // Domain size along magnetic field. + // Configuration domain parameters + double Lx = 150 * rho_s; // Domain size along x. + double Ly = 150 * rho_s; // Domain size along y. + double Lz = 2. * M_PI - 1e-10; // Domain size along magnetic field. // Adjust the domain size along y to have integer toroidal mode number. // We need: 2*pi*Cy/Ly = integer. - Ly = 2.*M_PI*Cy/round(2.*M_PI*Cy/Ly); + Ly = 2. * M_PI * Cy / round(2. * M_PI * Cy / Ly); - double x_min = -Lx/2; - double x_max = Lx/2; - double y_min = -Ly/2; - double y_max = Ly/2; - double z_min = -Lz/2; - double z_max = Lz/2; + double x_min = -Lx / 2; + double x_max = Lx / 2; + double y_min = -Ly / 2; + double y_max = Ly / 2; + double z_min = -Lz / 2; + double z_max = Lz / 2; double ux = 0.0, uy = 0.0, uz = Lz; // Passive advection velocity. - + // Check the global shear r/q*dq/dr in the middle of the domain - double rL = r0 - Lx/2; - double rR = r0 + Lx/2; + double rL = r0 - Lx / 2; + double rR = r0 + Lx / 2; double qL = qprofile(rL, a_mid, qaxis, qlcfs); double qR = qprofile(rR, a_mid, qaxis, qlcfs); - double dq_dr = (qR-qL)/(rR-rL); - double s0 = r0/q0*dq_dr; - double rhostar = rho_s/a_mid; - double inv_asp_ratio = a_mid/R0; + double dq_dr = (qR - qL) / (rR - rL); + double s0 = r0 / q0 * dq_dr; + double rhostar = rho_s / a_mid; + double inv_asp_ratio = a_mid / R0; // Grid parameters int Nx = 32; @@ -418,16 +437,16 @@ struct gk_app_ctx create_ctx(void) int Nmu = 2; int poly_order = 1; - int psi_lut_nfact = 100*(poly_order+1); // Resolution factor for the psi lookup table. + int psi_lut_nfact = 100 * (poly_order + 1); // Resolution factor for the psi lookup table. // Velocity box dimensions - double vpar_max_elc = 4.*vte; - double mu_max_elc = 7*Te0/B0; + double vpar_max_elc = 4. * vte; + double mu_max_elc = 7 * Te0 / B0; double t_end = 4.0; int num_frames = 40; double write_phase_freq = 1.0; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-3; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -443,55 +462,66 @@ struct gk_app_ctx create_ctx(void) .vdim = vdim, .a_shift = a_shift, .R_axis = R_axis, - .R0 = R0 , - .a_mid = a_mid , - .r0 = r0 , - .B0 = B0 , - .kappa = kappa , - .delta = delta , - .q0 = q0 , - .Cy = Cy , - .qaxis = qaxis , - .qlcfs = qlcfs , - .Lx = Lx , - .Ly = Ly , - .Lz = Lz , - .x_min = x_min, .x_max = x_max, - .y_min = y_min, .y_max = y_max, - .z_min = z_min, .z_max = z_max, - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - .ux = ux, .uy = uy, uz = uz, - .Nx = Nx, - .Ny = Ny, - .Nz = Nz, - .Nvpar = Nvpar, - .Nmu = Nmu, + .R0 = R0, + .a_mid = a_mid, + .r0 = r0, + .B0 = B0, + .kappa = kappa, + .delta = delta, + .q0 = q0, + .Cy = Cy, + .qaxis = qaxis, + .qlcfs = qlcfs, + .Lx = Lx, + .Ly = Ly, + .Lz = Lz, + .x_min = x_min, + .x_max = x_max, + .y_min = y_min, + .y_max = y_max, + .z_min = z_min, + .z_max = z_max, + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + .ux = ux, + .uy = uy, + uz = uz, + .Nx = Nx, + .Ny = Ny, + .Nz = Nz, + .Nvpar = Nvpar, + .Nmu = Nmu, .cells = {Nx, Ny, Nz, Nvpar, Nmu}, - .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, + .poly_order = poly_order, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, .write_phase_freq = write_phase_freq, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .psi_lut_size = psi_lut_nfact*Nx, + .psi_lut_size = psi_lut_nfact * Nx }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct timespec timer_global = gkyl_wall_clock(); struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Init(&argc, &argv); + } #endif - + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); @@ -500,80 +530,73 @@ main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // context for init functions int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; da_shift; double R_axis = app->R_axis; double delta = app->delta; - return R_axis - a_shift*r*r/(2.*R_axis) + r*cos(theta + asin(delta)*sin(theta)); + return R_axis - a_shift * r * r / (2. * R_axis) + r * cos(theta + asin(delta) * sin(theta)); } double Z_rtheta(double r, double theta, void *ctx) @@ -104,7 +113,7 @@ double Z_rtheta(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; double Z_axis = app->Z_axis; double kappa = app->kappa; - return Z_axis + kappa*r*sin(theta); + return Z_axis + kappa * r * sin(theta); } // Partial derivatives of R(r,theta) and Z(r,theta) @@ -114,31 +123,31 @@ double dRdr(double r, double theta, void *ctx) double a_shift = app->a_shift; double R_axis = app->R_axis; double delta = app->delta; - return - a_shift*r/(R_axis) + cos(theta + asin(delta)*sin(theta)); + return -a_shift * r / (R_axis) + cos(theta + asin(delta) * sin(theta)); } double dRdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return -r*sin(theta + asin(delta)*sin(theta))*(1.+asin(delta)*cos(theta)); + return -r * sin(theta + asin(delta) * sin(theta)) * (1. + asin(delta) * cos(theta)); } double dZdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*sin(theta); + return kappa * sin(theta); } double dZdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*cos(theta); + return kappa * r * cos(theta); } double Jr(double r, double theta, void *ctx) { - return R_rtheta(r,theta,ctx)*( dRdr(r,theta,ctx) * dZdtheta(r,theta,ctx) - -dRdtheta(r,theta,ctx) * dZdr(r,theta,ctx) ); + return R_rtheta(r, theta, ctx) * (dRdr(r, theta, ctx) * dZdtheta(r, theta, ctx) - + dRdtheta(r, theta, ctx) * dZdr(r, theta, ctx)); } struct integrand_ctx { @@ -150,7 +159,7 @@ double integrand(double t, void *int_ctx) struct integrand_ctx *inctx = int_ctx; double r = inctx->r; struct gk_app_ctx *app = inctx->app_ctx; - return Jr(r,t,app) / pow(R_rtheta(r,t,app),2); + return Jr(r, t, app) / pow(R_rtheta(r, t, app), 2); } double Bphi(double R, void *ctx) @@ -159,7 +168,7 @@ double Bphi(double R, void *ctx) struct gk_app_ctx *app = ctx; double B0 = app->B0; double R0 = app->R0; - return B0*R0/R; + return B0 * R0 / R; } double dPsidr(double r, double theta, void *ctx) @@ -167,19 +176,23 @@ double dPsidr(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2.*M_PI, 7, 1e-10); + integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2. * M_PI, 7, 1e-10); - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); - double R_omp = R_rtheta(r,0.0,ctx); - return ( R*Bt/(2.*M_PI*qprofile(R_omp)) )*integral.res; + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); + double R_omp = R_rtheta(r, 0.0, ctx); + return (R * Bt / (2. * M_PI * qprofile(R_omp))) * integral.res; } double alpha(double r, double theta, double phi, void *ctx) { double twrap = theta; - while (twrap < -M_PI) twrap = twrap+2.*M_PI; - while (M_PI < twrap) twrap = twrap-2.*M_PI; + while (twrap < -M_PI) { + twrap = twrap + 2. * M_PI; + } + while (M_PI < twrap) { + twrap = twrap - 2. * M_PI; + } struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; @@ -191,19 +204,20 @@ double alpha(double r, double theta, double phi, void *ctx) integral.res = -integral.res; } - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); - return phi - R*Bt*integral.res/dPsidr(r,theta,ctx); + return phi - R * Bt * integral.res / dPsidr(r, theta, ctx); } double gradr(double r, double theta, void *ctx) { - return (R_rtheta(r,theta,ctx)/Jr(r,theta,ctx))*sqrt(pow(dRdtheta(r,theta,ctx),2) + pow(dZdtheta(r,theta,ctx),2)); + return (R_rtheta(r, theta, ctx) / Jr(r, theta, ctx)) * + sqrt(pow(dRdtheta(r, theta, ctx), 2) + pow(dZdtheta(r, theta, ctx), 2)); } // Common source profiles. -void density_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_srcOMP(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; @@ -213,15 +227,17 @@ void density_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_REST double sigma_srcOMP = app->sigma_srcOMP; double floor_src = app->floor_src; - fout[0] = n_srcOMP*(exp(-(pow(x-x_srcOMP,2))/(2.*pow(sigma_srcOMP,2)))+floor_src); + fout[0] = n_srcOMP * (exp(-(pow(x - x_srcOMP, 2)) / (2. * pow(sigma_srcOMP, 2))) + floor_src); } -void zero_func(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void zero_func(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } // Electron source profiles. -void density_elc_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_elc_srcGB( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], z = xn[1]; @@ -232,10 +248,10 @@ void density_elc_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_R double bfac_srcGB = app->bfac_srcGB; double floor_src = app->floor_src; - fout[0] = n_srcGB*exp(-pow(x-x_srcGB,2)/(2.*pow(sigma_srcGB,2))) - *GKYL_MAX2(sin(z)*exp(-pow(fabs(z),1.5)/(2*pow(bfac_srcGB,2))),0.); + fout[0] = n_srcGB * exp(-pow(x - x_srcGB, 2) / (2. * pow(sigma_srcGB, 2))) * + GKYL_MAX2(sin(z) * exp(-pow(fabs(z), 1.5) / (2 * pow(bfac_srcGB, 2))), 0.); } -void temp_elc_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc_srcOMP(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; @@ -244,13 +260,13 @@ void temp_elc_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_RES double sigma_srcOMP = app->sigma_srcOMP; double Te_srcOMP = app->Te_srcOMP; - if (x < x_srcOMP + 3*sigma_srcOMP) { + if (x < x_srcOMP + 3 * sigma_srcOMP) { fout[0] = Te_srcOMP; } else { - fout[0] = Te_srcOMP*3./8.; + fout[0] = Te_srcOMP * 3. / 8.; } } -void temp_elc_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc_srcGB(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; @@ -261,7 +277,9 @@ void temp_elc_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_REST } // Ion source profiles. -void density_ion_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_ion_srcGB( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], z = xn[1]; @@ -272,10 +290,10 @@ void density_ion_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_R double bfac_srcGB = app->bfac_srcGB; double floor_src = app->floor_src; - fout[0] = -n_srcGB*exp(-pow(x-x_srcGB,2)/(2.*pow(sigma_srcGB,2))) - *GKYL_MAX2(sin(z)*exp(-pow(fabs(z),1.5)/(2*pow(bfac_srcGB,2))),0.); + fout[0] = -n_srcGB * exp(-pow(x - x_srcGB, 2) / (2. * pow(sigma_srcGB, 2))) * + GKYL_MAX2(sin(z) * exp(-pow(fabs(z), 1.5) / (2 * pow(bfac_srcGB, 2))), 0.); } -void temp_ion_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion_srcOMP(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; @@ -284,13 +302,13 @@ void temp_ion_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_RES double sigma_srcOMP = app->sigma_srcOMP; double Ti_srcOMP = app->Ti_srcOMP; - if (x < x_srcOMP + 3*sigma_srcOMP) { + if (x < x_srcOMP + 3 * sigma_srcOMP) { fout[0] = Ti_srcOMP; } else { - fout[0] = Ti_srcOMP*3./8.; + fout[0] = Ti_srcOMP * 3. / 8.; } } -void temp_ion_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion_srcGB(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; @@ -301,38 +319,39 @@ void temp_ion_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_REST } // Ion initial conditions -void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; struct gk_app_ctx *app = ctx; double n0 = app->n0; - fout[0] = n0*1.1*(0.5*(1.+tanh(2.*(2.-25.*x)))+0.01); + fout[0] = n0 * 1.1 * (0.5 * (1. + tanh(2. * (2. - 25. * x))) + 0.01); } -void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; struct gk_app_ctx *app = ctx; double Ti0 = app->Ti0; - fout[0] = Ti0*((1./3.)*(2.+tanh(2.*(2.-25.*x)))+0.01); + fout[0] = Ti0 * ((1. / 3.) * (2. + tanh(2. * (2. - 25. * x))) + 0.01); } // Electron initial conditions -void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; struct gk_app_ctx *app = ctx; double Te0 = app->Te0; - fout[0] = Te0*((1./3.)*(2.+tanh(2.*(2.-25.*x)))+0.01); + fout[0] = Te0 * ((1. / 3.) * (2. + tanh(2. * (2. - 25. * x))) + 0.01); } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -340,7 +359,7 @@ diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { struct gk_app_ctx *app = ctx; double Cy = app->Cy; @@ -348,47 +367,48 @@ void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) double x = xc[0], y = xc[1], z = xc[2]; - double r = r_x(x,a_mid); + double r = r_x(x, a_mid); // Map to cylindrical (R, Z, phi) coordinates. - double R = R_rtheta(r, z, ctx); - double Z = Z_rtheta(r, z, ctx); - double phi = y/Cy + alpha(r, z, 0, ctx); + double R = R_rtheta(r, z, ctx); + double Z = Z_rtheta(r, z, ctx); + double phi = y / Cy + alpha(r, z, 0, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); + double X = R * cos(phi); + double Y = R * sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Cy = app->Cy; double a_mid = app->a_mid; double x = xc[0], y = xc[1], z = xc[2]; - double r = r_x(x,a_mid); - double Bt = Bphi(R_rtheta(r,z,ctx),ctx); - double Bp = dPsidr(r,z,ctx)/R_rtheta(r,z,ctx)*gradr(r,z,ctx); - - double drdtheta = dRdtheta(r,z,ctx); - double dzdtheta = dZdtheta(r,z,ctx); - double den = sqrt(pow(drdtheta,2) + pow(dzdtheta,2)); - double B_r = Bp*drdtheta/den; - double B_z = Bp*dzdtheta/den; - double phi = y/Cy + alpha(r, z, 0, ctx); - double R = R_rtheta(r, z, ctx); - - // xc are computational coords. + double r = r_x(x, a_mid); + double Bt = Bphi(R_rtheta(r, z, ctx), ctx); + double Bp = dPsidr(r, z, ctx) / R_rtheta(r, z, ctx) * gradr(r, z, ctx); + + double drdtheta = dRdtheta(r, z, ctx); + double dzdtheta = dZdtheta(r, z, ctx); + double den = sqrt(pow(drdtheta, 2) + pow(dzdtheta, 2)); + double B_r = Bp * drdtheta / den; + double B_z = Bp * dzdtheta / den; + double phi = y / Cy + alpha(r, z, 0, ctx); + double R = R_rtheta(r, z, ctx); + + // xc are computational coords. // Set Cartesian components of magnetic field. fout[0] = B_r * cos(phi) + Bt * sin(phi); fout[1] = B_r * sin(phi) - Bt * cos(phi); fout[2] = B_z; } -struct gk_app_ctx -create_ctx(void) +struct gk_app_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -399,64 +419,67 @@ create_ctx(void) double qe = -eV; // electron charge // Geometry and magnetic field. - double a_shift = 0.6; // Parameter in Shafranov shift. - double Z_axis = 0.00232616113; // Magnetic axis height [m]. - double R_axis = 1.72068012; // Magnetic axis major radius [m]. - double B_axis = 2.0; // Magnetic field at the magnetic axis [T]. + double a_shift = 0.6; // Parameter in Shafranov shift. + double Z_axis = 0.00232616113; // Magnetic axis height [m]. + double R_axis = 1.72068012; // Magnetic axis major radius [m]. + double B_axis = 2.0; // Magnetic field at the magnetic axis [T]. double R_LCFSmid = 2.2801477223421736; // Major radius of the LCFS at the outboard midplane [m]. - double Rmid_min = R_LCFSmid - 5*0.15/8; // Minimum midplane major radius of simulation box [m]. - double Rmid_max = R_LCFSmid + 3*0.15/8; // Maximum midplane major radius of simulation box [m]. - double R0 = 0.5*(Rmid_min+Rmid_max); // Major radius of the simulation box [m]. + double Rmid_min = + R_LCFSmid - 5 * 0.15 / 8; // Minimum midplane major radius of simulation box [m]. + double Rmid_max = + R_LCFSmid + 3 * 0.15 / 8; // Maximum midplane major radius of simulation box [m]. + double R0 = 0.5 * (Rmid_min + Rmid_max); // Major radius of the simulation box [m]. - double a_mid = R_LCFSmid-R_axis; // Minor radius at outboard midplane [m]. + double a_mid = R_LCFSmid - R_axis; // Minor radius at outboard midplane [m]. // Redefine a_mid with Shafranov shift, to ensure LCFS radial location. - a_mid = R_axis/a_shift - sqrt(R_axis*(R_axis - 2*a_shift*R_LCFSmid + 2*a_shift*R_axis))/a_shift; + a_mid = R_axis / a_shift - + sqrt(R_axis * (R_axis - 2 * a_shift * R_LCFSmid + 2 * a_shift * R_axis)) / a_shift; - double r0 = R0-R_axis; // Minor radius of the simulation box [m]. - double B0 = B_axis*(R_axis/R0); // Magnetic field magnitude in the simulation box [T]. - double kappa = 1.488; // Elongation (=1 for no elongation). - double delta = 0.1; // Triangularity (=0 for no triangularity). - double Lx = Rmid_max-Rmid_min; // Domain size along x. - double Lz = 2.*M_PI-1e-10; // Domain size along magnetic field. - double x_min = 0.; - double x_max = Lx; - double z_min = -Lz/2.; - double z_max = Lz/2.; + double r0 = R0 - R_axis; // Minor radius of the simulation box [m]. + double B0 = B_axis * (R_axis / R0); // Magnetic field magnitude in the simulation box [T]. + double kappa = 1.488; // Elongation (=1 for no elongation). + double delta = 0.1; // Triangularity (=0 for no triangularity). + double Lx = Rmid_max - Rmid_min; // Domain size along x. + double Lz = 2. * M_PI - 1e-10; // Domain size along magnetic field. + double x_min = 0.; + double x_max = Lx; + double z_min = -Lz / 2.; + double z_max = Lz / 2.; - double x_LCFS = R_LCFSmid - Rmid_min; // Radial location of the last closed flux surface. + double x_LCFS = R_LCFSmid - Rmid_min; // Radial location of the last closed flux surface. - double q0 = qprofile(R0); // Magnetic safety factor in the center of domain. - double Cy = 1; // Normalization in binormal coordinate. + double q0 = qprofile(R0); // Magnetic safety factor in the center of domain. + double Cy = 1; // Normalization in binormal coordinate. // Plasma parameters. Chosen based on the value of a cubic sline // between the last TS data inside the LCFS and the probe data in // in the far SOL, near R=0.475 m. double AMU = 2.01410177811; - double mi = mp*AMU; // Deuterium ions. - double Te0 = 200*eV; - double Ti0 = 200*eV; - double n0 = 2.0e19; // [1/m^3] + double mi = mp * AMU; // Deuterium ions. + double Te0 = 200 * eV; + double Ti0 = 200 * eV; + double n0 = 2.0e19; // [1/m^3] double nu_frac = 1.0; - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // Source parameters double n_srcOMP = 3.e19; double x_srcOMP = x_min; - double Te_srcOMP = 2*Te0; - double Ti_srcOMP = 2*Ti0; - double sigma_srcOMP = 0.03*Lx; - double n_srcGB = 0.04*1.3553306021427228e+23; + double Te_srcOMP = 2 * Te0; + double Ti_srcOMP = 2 * Ti0; + double sigma_srcOMP = 0.03 * Lx; + double n_srcGB = 0.04 * 1.3553306021427228e+23; double x_srcGB = x_min; - double sigma_srcGB = 10*rho_s; + double sigma_srcGB = 10 * rho_s; double bfac_srcGB = 1.2; - double Te_srcGB = 350*eV; - double Ti_srcGB = 350*eV; + double Te_srcGB = 350 * eV; + double Ti_srcGB = 350 * eV; double floor_src = 1e-2; // Grid parameters @@ -466,15 +489,16 @@ create_ctx(void) int Nmu = 4; int poly_order = 1; - double vpar_max_elc = 4.*vte; - double mu_max_elc = me*pow(4*vte,2)/(2*B0); - double vpar_max_ion = 4.*vti; - double mu_max_ion = mi*pow(4*vti,2)/(2*B0); + double vpar_max_elc = 4. * vte; + double mu_max_elc = me * pow(4 * vte, 2) / (2 * B0); + double vpar_max_ion = 4. * vti; + double mu_max_ion = mi * pow(4 * vti, 2) / (2 * B0); double t_end = 1.e-7; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -483,66 +507,75 @@ create_ctx(void) .vdim = vdim, .a_shift = a_shift, .R_axis = R_axis, - .R0 = R0 , - .a_mid = a_mid , - .r0 = r0 , - .B0 = B0 , - .kappa = kappa , - .delta = delta , - .q0 = q0 , - .Cy = Cy , - .Lx = Lx , - .Lz = Lz , - .x_min = x_min, .x_max = x_max, - .z_min = z_min, .z_max = z_max, + .R0 = R0, + .a_mid = a_mid, + .r0 = r0, + .B0 = B0, + .kappa = kappa, + .delta = delta, + .q0 = q0, + .Cy = Cy, + .Lx = Lx, + .Lz = Lz, + .x_min = x_min, + .x_max = x_max, + .z_min = z_min, + .z_max = z_max, .x_LCFS = x_LCFS, - - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - + + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + .nu_frac = nu_frac, - - .n_srcOMP = n_srcOMP , - .x_srcOMP = x_srcOMP , - .Te_srcOMP = Te_srcOMP , - .Ti_srcOMP = Ti_srcOMP , + + .n_srcOMP = n_srcOMP, + .x_srcOMP = x_srcOMP, + .Te_srcOMP = Te_srcOMP, + .Ti_srcOMP = Ti_srcOMP, .sigma_srcOMP = sigma_srcOMP, - .n_srcGB = n_srcGB , - .x_srcGB = x_srcGB , - .sigma_srcGB = sigma_srcGB , - .bfac_srcGB = bfac_srcGB , - .Te_srcGB = Te_srcGB , - .Ti_srcGB = Ti_srcGB , - .floor_src = floor_src , - + .n_srcGB = n_srcGB, + .x_srcGB = x_srcGB, + .sigma_srcGB = sigma_srcGB, + .bfac_srcGB = bfac_srcGB, + .Te_srcGB = Te_srcGB, + .Ti_srcGB = Ti_srcGB, + .floor_src = floor_src, + .Nx = Nx, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -553,202 +586,191 @@ main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; da_shift; double R_axis = app->R_axis; double delta = app->delta; - return R_axis - a_shift*r*r/(2.*R_axis) + r*cos(theta + asin(delta)*sin(theta)); + return R_axis - a_shift * r * r / (2. * R_axis) + r * cos(theta + asin(delta) * sin(theta)); } double Z_rtheta(double r, double theta, void *ctx) @@ -109,7 +119,7 @@ double Z_rtheta(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; double Z_axis = app->Z_axis; double kappa = app->kappa; - return Z_axis + kappa*r*sin(theta); + return Z_axis + kappa * r * sin(theta); } // Partial derivatives of R(r,theta) and Z(r,theta) @@ -119,31 +129,31 @@ double dRdr(double r, double theta, void *ctx) double a_shift = app->a_shift; double R_axis = app->R_axis; double delta = app->delta; - return - a_shift*r/(R_axis) + cos(theta + asin(delta)*sin(theta)); + return -a_shift * r / (R_axis) + cos(theta + asin(delta) * sin(theta)); } double dRdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return -r*sin(theta + asin(delta)*sin(theta))*(1.+asin(delta)*cos(theta)); + return -r * sin(theta + asin(delta) * sin(theta)) * (1. + asin(delta) * cos(theta)); } double dZdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*sin(theta); + return kappa * sin(theta); } double dZdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*cos(theta); + return kappa * r * cos(theta); } double Jr(double r, double theta, void *ctx) { - return R_rtheta(r,theta,ctx)*( dRdr(r,theta,ctx) * dZdtheta(r,theta,ctx) - -dRdtheta(r,theta,ctx) * dZdr(r,theta,ctx) ); + return R_rtheta(r, theta, ctx) * (dRdr(r, theta, ctx) * dZdtheta(r, theta, ctx) - + dRdtheta(r, theta, ctx) * dZdr(r, theta, ctx)); } struct integrand_ctx { @@ -155,7 +165,7 @@ double integrand(double t, void *int_ctx) struct integrand_ctx *inctx = int_ctx; double r = inctx->r; struct gk_app_ctx *app = inctx->app_ctx; - return Jr(r,t,app) / pow(R_rtheta(r,t,app),2); + return Jr(r, t, app) / pow(R_rtheta(r, t, app), 2); } double Bphi(double R, void *ctx) @@ -164,7 +174,7 @@ double Bphi(double R, void *ctx) struct gk_app_ctx *app = ctx; double B0 = app->B0; double R0 = app->R0; - return B0*R0/R; + return B0 * R0 / R; } double dPsidr(double r, double theta, void *ctx) @@ -172,19 +182,23 @@ double dPsidr(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2.*M_PI, 7, 1e-10); + integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2. * M_PI, 7, 1e-10); - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); - double R_omp = R_rtheta(r,0.0,ctx); - return ( R*Bt/(2.*M_PI*qprofile(R_omp)))*integral.res; + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); + double R_omp = R_rtheta(r, 0.0, ctx); + return (R * Bt / (2. * M_PI * qprofile(R_omp))) * integral.res; } double alpha(double r, double theta, double phi, void *ctx) { double twrap = theta; - while (twrap < -M_PI) twrap = twrap+2.*M_PI; - while (M_PI < twrap) twrap = twrap-2.*M_PI; + while (twrap < -M_PI) { + twrap = twrap + 2. * M_PI; + } + while (M_PI < twrap) { + twrap = twrap - 2. * M_PI; + } struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; @@ -196,19 +210,20 @@ double alpha(double r, double theta, double phi, void *ctx) integral.res = -integral.res; } - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); - return phi - R*Bt*integral.res/dPsidr(r,theta,ctx); + return phi - R * Bt * integral.res / dPsidr(r, theta, ctx); } double gradr(double r, double theta, void *ctx) { - return (R_rtheta(r,theta,ctx)/Jr(r,theta,ctx))*sqrt(pow(dRdtheta(r,theta,ctx),2) + pow(dZdtheta(r,theta,ctx),2)); + return (R_rtheta(r, theta, ctx) / Jr(r, theta, ctx)) * + sqrt(pow(dRdtheta(r, theta, ctx), 2) + pow(dZdtheta(r, theta, ctx), 2)); } // Common source profiles. -void density_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_srcOMP(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; @@ -218,15 +233,17 @@ void density_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_REST double sigma_srcOMP = app->sigma_srcOMP; double floor_src = app->floor_src; - fout[0] = n_srcOMP*(exp(-(pow(x-x_srcOMP,2))/(2.*pow(sigma_srcOMP,2)))+floor_src); + fout[0] = n_srcOMP * (exp(-(pow(x - x_srcOMP, 2)) / (2. * pow(sigma_srcOMP, 2))) + floor_src); } -void zero_func(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void zero_func(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } // Electron source profiles. -void density_elc_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_elc_srcGB( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], z = xn[2]; @@ -236,10 +253,10 @@ void density_elc_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_R double sigma_srcGB = app->sigma_srcGB; double bfac_srcGB = app->bfac_srcGB; - fout[0] = n_srcGB*exp(-pow(x-x_srcGB,2)/(2.*pow(sigma_srcGB,2))) - *GKYL_MAX2(sin(z)*exp(-pow(fabs(z),1.5)/(2*pow(bfac_srcGB,2))),0.); + fout[0] = n_srcGB * exp(-pow(x - x_srcGB, 2) / (2. * pow(sigma_srcGB, 2))) * + GKYL_MAX2(sin(z) * exp(-pow(fabs(z), 1.5) / (2 * pow(bfac_srcGB, 2))), 0.); } -void temp_elc_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc_srcOMP(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; @@ -248,13 +265,13 @@ void temp_elc_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_RES double sigma_srcOMP = app->sigma_srcOMP; double Te_srcOMP = app->Te_srcOMP; - if (x < x_srcOMP + 3*sigma_srcOMP) { + if (x < x_srcOMP + 3 * sigma_srcOMP) { fout[0] = Te_srcOMP; } else { - fout[0] = Te_srcOMP*3./8.; + fout[0] = Te_srcOMP * 3. / 8.; } } -void temp_elc_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc_srcGB(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; @@ -265,7 +282,9 @@ void temp_elc_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_REST } // Ion source profiles. -void density_ion_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_ion_srcGB( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], z = xn[2]; @@ -275,10 +294,10 @@ void density_ion_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_R double sigma_srcGB = app->sigma_srcGB; double bfac_srcGB = app->bfac_srcGB; - fout[0] = n_srcGB*exp(-pow(x-x_srcGB,2)/(2.*pow(sigma_srcGB,2))) - *GKYL_MAX2(-sin(z)*exp(-pow(fabs(z),1.5)/(2*pow(bfac_srcGB,2))),0.); + fout[0] = n_srcGB * exp(-pow(x - x_srcGB, 2) / (2. * pow(sigma_srcGB, 2))) * + GKYL_MAX2(-sin(z) * exp(-pow(fabs(z), 1.5) / (2 * pow(bfac_srcGB, 2))), 0.); } -void temp_ion_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion_srcOMP(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; @@ -287,13 +306,13 @@ void temp_ion_srcOMP(double t, const double * GKYL_RESTRICT xn, double* GKYL_RES double sigma_srcOMP = app->sigma_srcOMP; double Ti_srcOMP = app->Ti_srcOMP; - if (x < x_srcOMP + 3*sigma_srcOMP) { + if (x < x_srcOMP + 3 * sigma_srcOMP) { fout[0] = Ti_srcOMP; } else { - fout[0] = Ti_srcOMP*3./8.; + fout[0] = Ti_srcOMP * 3. / 8.; } } -void temp_ion_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion_srcGB(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; @@ -304,40 +323,40 @@ void temp_ion_srcGB(double t, const double * GKYL_RESTRICT xn, double* GKYL_REST } // Initial density. -void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; struct gk_app_ctx *app = ctx; double n0 = app->n0; - fout[0] = 0.5*n0*(0.5*(1.+tanh(2.*(2.-25.*x)))+0.01); + fout[0] = 0.5 * n0 * (0.5 * (1. + tanh(2. * (2. - 25. * x))) + 0.01); } // Initial electron temperature. -void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; struct gk_app_ctx *app = ctx; double Te0 = app->Te0; - fout[0] = Te0*((1./3.)*(2.+tanh(2.*(2.-25.*x)))+0.01); + fout[0] = Te0 * ((1. / 3.) * (2. + tanh(2. * (2. - 25. * x))) + 0.01); } // Initial ion temperature. -void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; struct gk_app_ctx *app = ctx; double Ti0 = app->Ti0; - fout[0] = Ti0*((1./3.)*(2.+tanh(2.*(2.-25.*x)))+0.01); + fout[0] = Ti0 * ((1. / 3.) * (2. + tanh(2. * (2. - 25. * x))) + 0.01); } // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; @@ -346,20 +365,22 @@ void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) double a_mid = app->a_mid; double x_inner = app->x_inner; - double r = r_x(x,a_mid,x_inner); + double r = r_x(x, a_mid, x_inner); // Map to cylindrical (R, Z, phi) coordinates. - double R = R_rtheta(r, z, ctx); - double Z = Z_rtheta(r, z, ctx); - double phi = y/Cy + alpha(r, z, 0, ctx); + double R = R_rtheta(r, z, ctx); + double Z = Z_rtheta(r, z, ctx); + double phi = y / Cy + alpha(r, z, 0, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); + double X = R * cos(phi); + double Y = R * sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -367,18 +388,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -386,18 +408,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; @@ -405,26 +428,26 @@ void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *c double a_mid = app->a_mid; double Cy = app->Cy; double x_inner = app->x_inner; - double r = r_x(x,a_mid,x_inner); - double Bt = Bphi(R_rtheta(r,z,ctx),ctx); - double Bp = dPsidr(r,z,ctx)/R_rtheta(r,z,ctx)*gradr(r,z,ctx); - - double drdtheta = dRdtheta(r,z,ctx); - double dzdtheta = dZdtheta(r,z,ctx); - double den = sqrt(pow(drdtheta,2) + pow(dzdtheta,2)); - double B_r = Bp*drdtheta/den; - double B_z = Bp*dzdtheta/den; - double phi = y/Cy + alpha(r, z, 0, ctx); - double R = R_rtheta(r, z, ctx); - - // xc are computational coords. + double r = r_x(x, a_mid, x_inner); + double Bt = Bphi(R_rtheta(r, z, ctx), ctx); + double Bp = dPsidr(r, z, ctx) / R_rtheta(r, z, ctx) * gradr(r, z, ctx); + + double drdtheta = dRdtheta(r, z, ctx); + double dzdtheta = dZdtheta(r, z, ctx); + double den = sqrt(pow(drdtheta, 2) + pow(dzdtheta, 2)); + double B_r = Bp * drdtheta / den; + double B_z = Bp * dzdtheta / den; + double phi = y / Cy + alpha(r, z, 0, ctx); + double R = R_rtheta(r, z, ctx); + + // xc are computational coords. // Set Cartesian components of magnetic field. fout[0] = B_r * cos(phi) + Bt * sin(phi); fout[1] = B_r * sin(phi) - Bt * cos(phi); fout[2] = B_z; } -void bc_shift_func_lo(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_lo(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0]; @@ -435,12 +458,12 @@ void bc_shift_func_lo(double t, const double *xc, double* GKYL_RESTRICT fout, vo double z_min = app->z_min; double z_max = app->z_max; - double r = r_x(x,a_mid,x_inner); + double r = r_x(x, a_mid, x_inner); - fout[0] = Cy*( alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx) ); + fout[0] = Cy * (alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx)); } -void bc_shift_func_up(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_up(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0]; @@ -451,13 +474,12 @@ void bc_shift_func_up(double t, const double *xc, double* GKYL_RESTRICT fout, vo double z_min = app->z_min; double z_max = app->z_max; - double r = r_x(x,a_mid,x_inner); + double r = r_x(x, a_mid, x_inner); - fout[0] = -Cy*( alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx) ); + fout[0] = -Cy * (alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx)); } -struct gk_app_ctx -create_ctx(void) +struct gk_app_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -472,23 +494,26 @@ create_ctx(void) double Z_axis = 0.013055028; // Magnetic axis height [m]. double R_axisTrue = 1.6486461; // Change R_axis to fit geometry better. double R_axis = 1.6; // Magnetic axis major radius [m]. - double B_axis = 2.0*R_axisTrue/R_axis; // Magnetic field at the magnetic axis [T]. + double B_axis = 2.0 * R_axisTrue / R_axis; // Magnetic field at the magnetic axis [T]. double R_LCFSmid = 2.17; // Major radius of the LCFS at the outboard midplane [m]. - double x_inner = 5*0.15/8; // Radial extent inside LCFS - double x_outer = 3*0.15/8; // Radial extent outside LCFS + double x_inner = 5 * 0.15 / 8; // Radial extent inside LCFS + double x_outer = 3 * 0.15 / 8; // Radial extent outside LCFS double Rmid_min = R_LCFSmid - x_inner; // Minimum midplane major radius of simulation box [m]. double Rmid_max = R_LCFSmid + x_outer; // Maximum midplane major radius of simulation box [m]. - double R0 = 0.5*(Rmid_min+Rmid_max); // Major radius of the simulation box [m]. + double R0 = 0.5 * (Rmid_min + Rmid_max); // Major radius of the simulation box [m]. // Minor radius at outboard midplane [m]. Redefine it with // Shafranov shift, to ensure LCFS radial location. - double a_mid = fabs(a_shift)<1e-13? R_LCFSmid-R_axis : - R_axis/a_shift - sqrt(R_axis*(R_axis - 2*a_shift*R_LCFSmid + 2*a_shift*R_axis))/a_shift; + double a_mid = + fabs(a_shift) < 1e-13 ? + R_LCFSmid - R_axis : + R_axis / a_shift - + sqrt(R_axis * (R_axis - 2 * a_shift * R_LCFSmid + 2 * a_shift * R_axis)) / a_shift; double side_wall_bias = 0.0; // Potential of the side wall. - double r0 = R0-R_axis; // Minor radius of the simulation box [m]. - double B0 = B_axis*(R_axis/R0); // Magnetic field magnitude in the simulation box [T]. + double r0 = R0 - R_axis; // Minor radius of the simulation box [m]. + double B0 = B_axis * (R_axis / R0); // Magnetic field magnitude in the simulation box [T]. double kappa = 1.35; // Elongation (=1 for no elongation). double delta = 0.4; // Triangularity (=0 for no triangularity). @@ -498,43 +523,43 @@ create_ctx(void) // between the last TS data inside the LCFS and the probe data in // in the far SOL, near R=0.475 m. double AMU = 2.01410177811; - double mi = mp*AMU; // Deuterium ions. - double Te0 = 100*eV; - double Ti0 = 100*eV; + double mi = mp * AMU; // Deuterium ions. + double Te0 = 100 * eV; + double Ti0 = 100 * eV; double n0 = 2.0e19; // [1/m^3] - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); // Sound speed. - double omega_ci = fabs(qi*B0/mi); // Ion cyclotron frequency. - double rho_s = c_s/omega_ci; // Ion sound gyroradius. + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. + double c_s = sqrt(Te0 / mi); // Sound speed. + double omega_ci = fabs(qi * B0 / mi); // Ion cyclotron frequency. + double rho_s = c_s / omega_ci; // Ion sound gyroradius. - double Lx = Rmid_max-Rmid_min; // Domain size along x. - double Ly = 150*rho_s; // Domain size along y. - double Lz = 2.*M_PI-1e-10; // Domain size along magnetic field. + double Lx = Rmid_max - Rmid_min; // Domain size along x. + double Ly = 150 * rho_s; // Domain size along y. + double Lz = 2. * M_PI - 1e-10; // Domain size along magnetic field. double x_min = 0.; double x_max = Lx; - double y_min = -Ly/2.; - double y_max = Ly/2.; - double z_min = -Lz/2.; - double z_max = Lz/2.; + double y_min = -Ly / 2.; + double y_max = Ly / 2.; + double z_min = -Lz / 2.; + double z_max = Lz / 2.; double q0 = qprofile(R0); // Magnetic safety factor in the center of domain. - double Cy = r0/q0; // Normalization in binormal coordinate. + double Cy = r0 / q0; // Normalization in binormal coordinate. double nu_frac = 0.1; // Source parameters double n_srcOMP = 9.e22; double x_srcOMP = x_min; - double Te_srcOMP = 2*Te0; - double Ti_srcOMP = 2*Ti0; - double sigma_srcOMP = 0.03*Lx; - double n_srcGB = 1.1*8.092675420182799e+21; + double Te_srcOMP = 2 * Te0; + double Ti_srcOMP = 2 * Ti0; + double sigma_srcOMP = 0.03 * Lx; + double n_srcGB = 1.1 * 8.092675420182799e+21; double x_srcGB = x_min; - double sigma_srcGB = 10*rho_s; + double sigma_srcGB = 10 * rho_s; double bfac_srcGB = 1.2; - double Te_srcGB = 100*eV; - double Ti_srcGB = 100*eV; + double Te_srcGB = 100 * eV; + double Ti_srcGB = 100 * eV; double floor_src = 1e-2; // Grid parameters @@ -545,15 +570,16 @@ create_ctx(void) int Nmu = 4; int poly_order = 1; - double vpar_max_elc = 4.*vte; - double mu_max_elc = me*pow(4*vte,2)/(2*B0); - double vpar_max_ion = 4.*vti; - double mu_max_ion = mi*pow(4*vti,2)/(2*B0); + double vpar_max_elc = 4. * vte; + double mu_max_elc = me * pow(4 * vte, 2) / (2 * B0); + double vpar_max_ion = 4. * vti; + double mu_max_ion = mi * pow(4 * vti, 2) / (2 * B0); double t_end = 1.e-7; // End time, should terminate in 43 steps. int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -575,18 +601,25 @@ create_ctx(void) .Lx = Lx, .Ly = Ly, .Lz = Lz, - .x_min = x_min, .x_max = x_max, - .y_min = y_min, .y_max = y_max, - .z_min = z_min, .z_max = z_max, + .x_min = x_min, + .x_max = x_max, + .y_min = y_min, + .y_max = y_max, + .z_min = z_min, + .z_max = z_max, .x_LCFS = x_LCFS, - - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - + + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + .nu_frac = nu_frac, - + .n_srcOMP = n_srcOMP, .x_srcOMP = x_srcOMP, .Te_srcOMP = Te_srcOMP, @@ -599,7 +632,7 @@ create_ctx(void) .Te_srcGB = Te_srcGB, .Ti_srcGB = Ti_srcGB, .floor_src = floor_src, - + .Nx = Nx, .Ny = Ny, .Nz = Nz, @@ -607,26 +640,29 @@ create_ctx(void) .Nmu = Nmu, .cells = {Nx, Ny, Nz, Nvpar, Nmu}, .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -637,217 +673,196 @@ main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dxSource; double lambdaSource = app->lambdaSource; if (x < xSource + 3 * lambdaSource) { - return 80*GKYL_ELEMENTARY_CHARGE; + return 80 * GKYL_ELEMENTARY_CHARGE; } else { - return 30*GKYL_ELEMENTARY_CHARGE; + return 30 * GKYL_ELEMENTARY_CHARGE; } } // Initial density. -double densityInit(double t, const double * GKYL_RESTRICT xn, void *ctx) +double densityInit(double t, const double *GKYL_RESTRICT xn, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; struct gk_app_ctx *app = ctx; - double Ls = app->Lz/4; + double Ls = app->Lz / 4; double xSource[3] = {x, y, 0}; double effectiveSource = sourceDensity(t, xSource, ctx); - double c_ss = sqrt(5/3*sourceTemperature(t, xSource, ctx)/app->mi); - double nPeak = 4*sqrt(5)/3/c_ss*Ls*effectiveSource/2; + double c_ss = sqrt(5 / 3 * sourceTemperature(t, xSource, ctx) / app->mi); + double nPeak = 4 * sqrt(5) / 3 / c_ss * Ls * effectiveSource / 2; pcg64_random_t rng = gkyl_pcg64_init(0); - double perturb = 1e-3*(gkyl_pcg64_rand_double(&rng) - 0.5)*2.0; + double perturb = 1e-3 * (gkyl_pcg64_rand_double(&rng) - 0.5) * 2.0; if (fabs(z) <= Ls) { - return nPeak * (1 + sqrt(1-pow(z/Ls,2)))/2 * (1+perturb); + return nPeak * (1 + sqrt(1 - pow(z / Ls, 2))) / 2 * (1 + perturb); } else { - return nPeak/2 * (1+perturb); + return nPeak / 2 * (1 + perturb); } } // Initial temperature. -double temperatureInit(double t, const double * GKYL_RESTRICT xn, void *ctx) +double temperatureInit(double t, const double *GKYL_RESTRICT xn, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; struct gk_app_ctx *app = ctx; double xSource = app->xSource; double lambdaSource = app->lambdaSource; - if (x < xSource + 3*lambdaSource) { - return 80*GKYL_ELEMENTARY_CHARGE; + if (x < xSource + 3 * lambdaSource) { + return 80 * GKYL_ELEMENTARY_CHARGE; } else { - return 20*GKYL_ELEMENTARY_CHARGE; + return 20 * GKYL_ELEMENTARY_CHARGE; } } // Initial ion drift speed. -double driftSpeed(const double * GKYL_RESTRICT xn, void *ctx){ +double driftSpeed(const double *GKYL_RESTRICT xn, void *ctx) +{ double x = xn[0], y = xn[1], z = xn[2]; struct gk_app_ctx *app = ctx; double xSource = app->xSource; @@ -139,16 +150,16 @@ double driftSpeed(const double * GKYL_RESTRICT xn, void *ctx){ double Lz = app->Lz; double mi = app->mi; double Te; - if (x < xSource + 3*lambdaSource) { - Te = 50*GKYL_ELEMENTARY_CHARGE; + if (x < xSource + 3 * lambdaSource) { + Te = 50 * GKYL_ELEMENTARY_CHARGE; } else { - Te = 20*GKYL_ELEMENTARY_CHARGE; + Te = 20 * GKYL_ELEMENTARY_CHARGE; } - double Ls = Lz/4; + double Ls = Lz / 4; if (fabs(z) <= Ls) { - return z/Ls*sqrt(Te/mi); + return z / Ls * sqrt(Te / mi); } else { - return (z > 0 ? 1.0 : -1.0)*sqrt(Te/mi); + return (z > 0 ? 1.0 : -1.0) * sqrt(Te / mi); } } @@ -166,7 +177,7 @@ double Bphi(const double *xc, void *ctx) double B_axis = app->B_axis; double R0 = app->R0; double R = Rx(xc, ctx); - return B_axis*R0/R; + return B_axis * R0 / R; } // Vertical magnetic field. @@ -182,20 +193,20 @@ double bmag(const double *xc, void *ctx) { double Bt = Bphi(xc, ctx); double Bv = Bvert(xc, ctx); - return sqrt(pow(Bt,2) + pow(Bv,2)); + return sqrt(pow(Bt, 2) + pow(Bv, 2)); } // Field line pitch. double thetax(const double *xc, void *ctx) { - return asin(Bvert(xc, ctx)/bmag(xc, ctx)); + return asin(Bvert(xc, ctx) / bmag(xc, ctx)); } // Parallel coordinate mapping. double Zx(const double *xc, void *ctx) { double theta = thetax(xc, ctx); - return xc[2]*sin(theta); + return xc[2] * sin(theta); } double phix(const double *xc, void *ctx) @@ -216,51 +227,66 @@ double phix(const double *xc, void *ctx) // Helical sheared mapping. Passes right hand check and conserves particle. double theta = thetax(xc, ctx); - return y/Rc + (Bt * z*sin(theta))/(Bv * x); + return y / Rc + (Bt * z * sin(theta)) / (Bv * x); } // Interface function calls. -void source_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = sourceDensity(t, xn, ctx); } -void source_temperature(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = sourceTemperature(t, xn, ctx); } -void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = densityInit(t, xn, ctx); } -void temp_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = temperatureInit(t, xn, ctx); } -void upar_ion_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = driftSpeed(xn, ctx); } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) -{ +void source_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +{ + fout[0] = sourceDensity(t, xn, ctx); +} +void source_temperature( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) +{ + fout[0] = sourceTemperature(t, xn, ctx); +} +void density_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +{ + fout[0] = densityInit(t, xn, ctx); +} +void temp_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +{ + fout[0] = temperatureInit(t, xn, ctx); +} +void upar_ion_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +{ + fout[0] = driftSpeed(xn, ctx); +} +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) +{ // Cartesian formulation of the magnetic field. double Bt = Bphi(xc, ctx); double Bv = Bvert(xc, ctx); double phi = phix(xc, ctx); - fout[0] = -Bt*sin(phi); - fout[1] = Bt*cos(phi); + fout[0] = -Bt * sin(phi); + fout[1] = Bt * cos(phi); fout[2] = Bv; } -void zero_func(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = 0.0; } +void zero_func(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +{ + fout[0] = 0.0; +} // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; // Map to cylindrical (R, Z, phi) coordinates. - double R = Rx(xc, ctx); - double Z = Zx(xc, ctx); + double R = Rx(xc, ctx); + double Z = Zx(xc, ctx); double phi = phix(xc, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); + double X = R * cos(phi); + double Y = R * sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -struct gk_app_ctx -create_ctx(void) +struct gk_app_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -274,10 +300,10 @@ create_ctx(void) // between the last TS data inside the LCFS and the probe data in // in the far SOL, near R=0.475 m. double AMU = 2.01410177811; - double mi = mp*AMU; // Deuterium ions. - double Te0 = 40*eV; - double Ti0 = 40*eV; - double n0 = 7e18*10; // [1/m^3] + double mi = mp * AMU; // Deuterium ions. + double Te0 = 40 * eV; + double Ti0 = 40 * eV; + double n0 = 7e18 * 10; // [1/m^3] // Geometry and magnetic field. double B_axis = 0.5; @@ -286,14 +312,14 @@ create_ctx(void) double Lp = 2.4; // Poloidal length at x0. double Lt = 8.0; // Toroidal length at x0. double Rc = R0 + a0; - double B0 = B_axis*R0/Rc; + double B0 = B_axis * R0 / Rc; - double sintheta = Lp/Lt; - double Bv0 = B0*sintheta; + double sintheta = Lp / Lt; + double Bv0 = B0 * sintheta; // Source parameters. double P_SOL = 8.1e5; - double S0 = 5.7691e23*10; // Multiplied by 10 to increase beta + double S0 = 5.7691e23 * 10; // Multiplied by 10 to increase beta double xSource = Rc - 0.05; double lambdaSource = 0.005; @@ -301,22 +327,22 @@ create_ctx(void) double nuFrac = 0.1; // Derived parameters. - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); // Sound speed. - double omega_ci = fabs(qi*B0/mi); // Ion cyclotron frequency. - double rho_s = c_s/omega_ci; // Ion sound gyroradius. + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. + double c_s = sqrt(Te0 / mi); // Sound speed. + double omega_ci = fabs(qi * B0 / mi); // Ion cyclotron frequency. + double rho_s = c_s / omega_ci; // Ion sound gyroradius. // Box size. - double Lx = 50*rho_s; - double Ly = 100*rho_s; + double Lx = 50 * rho_s; + double Ly = 100 * rho_s; double Lz = Lt; // [m] - double x_min = Rc - Lx/2; - double x_max = Rc + Lx/2; - double y_min = -Ly/2; - double y_max = Ly/2; - double z_min = -Lz/2; - double z_max = Lz/2; + double x_min = Rc - Lx / 2; + double x_max = Rc + Lx / 2; + double y_min = -Ly / 2; + double y_max = Ly / 2; + double z_min = -Lz / 2; + double z_max = Lz / 2; // Grid parameters int Nx = 8; @@ -326,15 +352,16 @@ create_ctx(void) int Nmu = 2; int poly_order = 1; - double vpar_max_elc = 4.*vte; - double mu_max_elc = 12*me*pow(vte,2)/(2*B0); - double vpar_max_ion = 4.*vti; - double mu_max_ion = 12*mi*pow(vti,2)/(2*B0); + double vpar_max_elc = 4. * vte; + double mu_max_elc = 12 * me * pow(vte, 2) / (2 * B0); + double vpar_max_ion = 4. * vti; + double mu_max_ion = 12 * mi * pow(vti, 2) / (2 * B0); double t_end = 1.e-6; // End time, should terminate in 43 steps. int num_frames = 1; - double write_phase_freq = 1.0; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 1.0; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -348,21 +375,28 @@ create_ctx(void) .Lx = Lx, .Ly = Ly, .Lz = Lz, - .x_min = x_min, .x_max = x_max, - .y_min = y_min, .y_max = y_max, - .z_min = z_min, .z_max = z_max, - - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - + .x_min = x_min, + .x_max = x_max, + .y_min = y_min, + .y_max = y_max, + .z_min = z_min, + .z_max = z_max, + + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + .nu_frac = nuFrac, - + .P_SOL = P_SOL, .S0 = S0, .xSource = xSource, .lambdaSource = lambdaSource, - + .Nx = Nx, .Ny = Ny, .Nz = Nz, @@ -370,26 +404,29 @@ create_ctx(void) .Nmu = Nmu, .cells = {Nx, Ny, Nz, Nvpar, Nmu}, .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -400,10 +437,12 @@ main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dxSource; double lambdaSource = app->lambdaSource; if (x < xSource + 3 * lambdaSource) { - return 80*GKYL_ELEMENTARY_CHARGE; + return 80 * GKYL_ELEMENTARY_CHARGE; } else { - return 30*GKYL_ELEMENTARY_CHARGE; + return 30 * GKYL_ELEMENTARY_CHARGE; } } // Initial density. -double densityInit(double t, const double * GKYL_RESTRICT xn, void *ctx) +double densityInit(double t, const double *GKYL_RESTRICT xn, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; struct gk_app_ctx *app = ctx; - double Ls = app->Lz/4; + double Ls = app->Lz / 4; double xSource[3] = {x, y, 0}; double effectiveSource = sourceDensity(t, xSource, ctx); - double c_ss = sqrt(5/3*sourceTemperature(t, xSource, ctx)/app->mi); - double nPeak = 4*sqrt(5)/3/c_ss*Ls*effectiveSource/2; + double c_ss = sqrt(5 / 3 * sourceTemperature(t, xSource, ctx) / app->mi); + double nPeak = 4 * sqrt(5) / 3 / c_ss * Ls * effectiveSource / 2; pcg64_random_t rng = gkyl_pcg64_init(0); - double perturb = 1e-3*(gkyl_pcg64_rand_double(&rng) - 0.5)*2.0; + double perturb = 1e-3 * (gkyl_pcg64_rand_double(&rng) - 0.5) * 2.0; if (fabs(z) <= Ls) { - return nPeak * (1 + sqrt(1-pow(z/Ls,2)))/2 * (1+perturb); + return nPeak * (1 + sqrt(1 - pow(z / Ls, 2))) / 2 * (1 + perturb); } else { - return nPeak/2 * (1+perturb); + return nPeak / 2 * (1 + perturb); } } // Initial temperature. -double temperatureInit(double t, const double * GKYL_RESTRICT xn, void *ctx) +double temperatureInit(double t, const double *GKYL_RESTRICT xn, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; struct gk_app_ctx *app = ctx; double xSource = app->xSource; double lambdaSource = app->lambdaSource; - if (x < xSource + 3*lambdaSource) { - return 80*GKYL_ELEMENTARY_CHARGE; + if (x < xSource + 3 * lambdaSource) { + return 80 * GKYL_ELEMENTARY_CHARGE; } else { - return 20*GKYL_ELEMENTARY_CHARGE; + return 20 * GKYL_ELEMENTARY_CHARGE; } } // Initial ion drift speed. -double driftSpeed(const double * GKYL_RESTRICT xn, void *ctx){ +double driftSpeed(const double *GKYL_RESTRICT xn, void *ctx) +{ double x = xn[0], y = xn[1], z = xn[2]; struct gk_app_ctx *app = ctx; double xSource = app->xSource; @@ -147,16 +158,16 @@ double driftSpeed(const double * GKYL_RESTRICT xn, void *ctx){ double Lz = app->Lz; double mi = app->mi; double Te; - if (x < xSource + 3*lambdaSource) { - Te = 50*GKYL_ELEMENTARY_CHARGE; + if (x < xSource + 3 * lambdaSource) { + Te = 50 * GKYL_ELEMENTARY_CHARGE; } else { - Te = 20*GKYL_ELEMENTARY_CHARGE; + Te = 20 * GKYL_ELEMENTARY_CHARGE; } - double Ls = Lz/4; + double Ls = Lz / 4; if (fabs(z) <= Ls) { - return z/Ls*sqrt(Te/mi); + return z / Ls * sqrt(Te / mi); } else { - return (z > 0 ? 1.0 : -1.0)*sqrt(Te/mi); + return (z > 0 ? 1.0 : -1.0) * sqrt(Te / mi); } } @@ -179,7 +190,7 @@ double Bphi(const double *xc, void *ctx) double R0 = app->R0; double R = Rx(xc, ctx); - return B0*R0/R; + return B0 * R0 / R; } double Bvert(const double *xc, void *ctx) @@ -189,15 +200,15 @@ double Bvert(const double *xc, void *ctx) double x0 = app->x0; int n = app->n; double R = Rx(xc, ctx); - - return Bvx0 * pow(R/x0, n); + + return Bvx0 * pow(R / x0, n); } double Bmag(const double *xc, void *ctx) { double Bt = Bphi(xc, ctx); double Bv = Bvert(xc, ctx); - return Bv * sqrt(1 + pow(Bt/Bv,2)); + return Bv * sqrt(1 + pow(Bt / Bv, 2)); } // Toroidal angle coordinate. @@ -209,7 +220,7 @@ double phix(const double *xc, void *ctx) double Lz = app->Lz; double Bt = Bphi(xc, ctx); double Bv = Bvert(xc, ctx); - return y/R0 + (Bt * z)/(Bv * x); + return y / R0 + (Bt * z) / (Bv * x); } double qprofile(const double *xc, void *ctx) @@ -220,50 +231,64 @@ double qprofile(const double *xc, void *ctx) double Bt = Bphi(xc, ctx); double Bv = Bvert(xc, ctx); - return (H * Bt)/(2*GKYL_PI*R*Bv); + return (H * Bt) / (2 * GKYL_PI * R * Bv); } // Interface function calls. -void source_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = sourceDensity(t, xn, ctx); } -void source_temperature(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = sourceTemperature(t, xn, ctx); } -void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = densityInit(t, xn, ctx); } -void temp_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = temperatureInit(t, xn, ctx); } -void upar_ion_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = driftSpeed(xn, ctx); } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) -{ +void source_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +{ + fout[0] = sourceDensity(t, xn, ctx); +} +void source_temperature( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) +{ + fout[0] = sourceTemperature(t, xn, ctx); +} +void density_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +{ + fout[0] = densityInit(t, xn, ctx); +} +void temp_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +{ + fout[0] = temperatureInit(t, xn, ctx); +} +void upar_ion_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +{ + fout[0] = driftSpeed(xn, ctx); +} +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) +{ // Cartesian formulation of the magnetic field. double Bt = Bphi(xc, ctx); double Bv = Bvert(xc, ctx); double phi = phix(xc, ctx); - fout[0] = -Bt*sin(phi); - fout[1] = Bt*cos(phi); + fout[0] = -Bt * sin(phi); + fout[1] = Bt * cos(phi); fout[2] = Bv; } -void zero_func(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) -{ fout[0] = 0.0; } - +void zero_func(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +{ + fout[0] = 0.0; +} // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { // Map to cylindrical (R, Z, phi) coordinates. - double R = Rx(xc, ctx); - double Z = Zx(xc, ctx); + double R = Rx(xc, ctx); + double Z = Zx(xc, ctx); double phi = phix(xc, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); + double X = R * cos(phi); + double Y = R * sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -struct gk_app_ctx -create_ctx(void) +struct gk_app_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -277,10 +302,10 @@ create_ctx(void) // between the last TS data inside the LCFS and the probe data in // in the far SOL, near R=0.475 m. double AMU = 2.01410177811; - double mi = mp*AMU; // Deuterium ions. - double Te0 = 40*eV; - double Ti0 = 40*eV; - double n0 = 7e18*10; // [1/m^3] + double mi = mp * AMU; // Deuterium ions. + double Te0 = 40 * eV; + double Ti0 = 40 * eV; + double n0 = 7e18 * 10; // [1/m^3] // Geometry and magnetic field. double B0 = 0.5; @@ -291,16 +316,16 @@ create_ctx(void) int shear = -2; double x0 = R0 + a0; - + const double vec0[3] = {x0, 0.0, 0.0}; - double Bc = Bphi(vec0, &(struct gk_app_ctx){.B0=B0, .R0=R0}); + double Bc = Bphi(vec0, &(struct gk_app_ctx){.B0 = B0, .R0 = R0}); double Bvx0 = H * Bc / Lcx0; double n = shear + 2; // Source parameters. // double P_SOL = 0.62*1e6; // Power crossing the separatrix, in Watts. // double Psrc = P_SOL * Ly / (2*M_PI*Rc); - double S0 = 5.7691e23*10; // Taken from the input file. + double S0 = 5.7691e23 * 10; // Taken from the input file. double xSource = x0 - 0.05; double lambdaSource = 0.005; @@ -308,22 +333,22 @@ create_ctx(void) double nuFrac = 0.1; // Derived parameters. - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); // Sound speed. - double omega_ci = fabs(qi*B0/mi); // Ion cyclotron frequency. - double rho_s = c_s/omega_ci; // Ion sound gyroradius. + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. + double c_s = sqrt(Te0 / mi); // Sound speed. + double omega_ci = fabs(qi * B0 / mi); // Ion cyclotron frequency. + double rho_s = c_s / omega_ci; // Ion sound gyroradius. // Box size. - double Lx = 56*rho_s; - double Ly = 100*rho_s*H/Lcx0; + double Lx = 56 * rho_s; + double Ly = 100 * rho_s * H / Lcx0; double Lz = H; // [m] - double x_min = x0 - Lx/2; - double x_max = x0 + Lx/2; - double y_min = -Ly/2; - double y_max = Ly/2; - double z_min = -Lz/2; - double z_max = Lz/2; + double x_min = x0 - Lx / 2; + double x_max = x0 + Lx / 2; + double y_min = -Ly / 2; + double y_max = Ly / 2; + double z_min = -Lz / 2; + double z_max = Lz / 2; // Grid parameters int Nx = 8; @@ -333,15 +358,16 @@ create_ctx(void) int Nmu = 2; int poly_order = 1; - double vpar_max_elc = 4.*vte; - double mu_max_elc = 12*me*pow(vte,2)/(2*B0); - double vpar_max_ion = 4.*vti; - double mu_max_ion = 12*mi*pow(vti,2)/(2*B0); + double vpar_max_elc = 4. * vte; + double mu_max_elc = 12 * me * pow(vte, 2) / (2 * B0); + double vpar_max_ion = 4. * vti; + double mu_max_ion = 12 * mi * pow(vti, 2) / (2 * B0); double t_end = 1.e-6; // End time, should terminate in 43 steps. int num_frames = 1; - double write_phase_freq = 1.0; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 1.0; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -360,20 +386,27 @@ create_ctx(void) .Lx = Lx, .Ly = Ly, .Lz = Lz, - .x_min = x_min, .x_max = x_max, - .y_min = y_min, .y_max = y_max, - .z_min = z_min, .z_max = z_max, - - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - + .x_min = x_min, + .x_max = x_max, + .y_min = y_min, + .y_max = y_max, + .z_min = z_min, + .z_max = z_max, + + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + .nu_frac = nuFrac, - + .S0 = S0, .xSource = xSource, .lambdaSource = lambdaSource, - + .Nx = Nx, .Ny = Ny, .Nz = Nz, @@ -381,26 +414,29 @@ create_ctx(void) .Nmu = Nmu, .cells = {Nx, Ny, Nz, Nvpar, Nmu}, .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -411,13 +447,15 @@ main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // Context for init functions. // Extract variables from command line arguments. - sscanf(app_args.opt_args, "max_run_time=%lf",&ctx.max_run_time); + sscanf(app_args.opt_args, "max_run_time=%lf", &ctx.max_run_time); int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct ion_sound_ctx -{ +struct ion_sound_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -53,14 +52,14 @@ struct ion_sound_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct ion_sound_ctx -create_ctx(void) +struct ion_sound_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -83,7 +82,7 @@ create_ctx(void) // Derived physical quantities (using non-normalized physical units). double nu_ion = 2.0; // Ion collision frequency. double nu_elc = nu_ion * sqrt(mass_ion / mass_elc); // Electron collision frequency. - + double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -92,20 +91,27 @@ create_ctx(void) int Nvpar = 64; // Cell count (velocity space: parallel velocity direction). int Nmu = 12; // Cell count (velocity space: magnetic moment direction). double Lz = 2.0 * M_PI / kz; // Domain size (configuration space: z-direction). - double vpar_max_elc = 6.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = mass_elc * pow(6.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = mass_ion * pow(6.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 6.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + mass_elc * pow(6.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + mass_ion * pow(6.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 2.0; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct ion_sound_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -140,14 +146,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct ion_sound_ctx *app = ctx; @@ -157,8 +164,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; @@ -168,15 +174,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct ion_sound_ctx *app = ctx; double z = xn[0]; @@ -191,8 +197,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; @@ -202,15 +207,13 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; @@ -220,8 +223,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; @@ -232,33 +234,35 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -269,10 +273,12 @@ main(int argc, char **argv) struct ion_sound_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct ion_sound_ctx -{ +struct ion_sound_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -48,14 +47,14 @@ struct ion_sound_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct ion_sound_ctx -create_ctx(void) +struct ion_sound_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -84,18 +83,22 @@ create_ctx(void) int Nvpar = 48; // Cell count (velocity space: parallel velocity direction). int Nmu = 8; // Cell count (velocity space: magnetic moment direction). double Lz = 2.0 * M_PI / kz; // Domain size (configuration space: z-direction). - double vpar_max_ion = 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = mass_ion * pow(5.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_ion = + 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + mass_ion * pow(5.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 20.0; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct ion_sound_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -126,14 +129,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct ion_sound_ctx *app = ctx; double z = xn[0]; @@ -148,8 +152,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; @@ -159,15 +162,13 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; @@ -178,33 +179,35 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -215,10 +218,12 @@ main(int argc, char **argv) struct ion_sound_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct ion_sound_ctx -{ +struct ion_sound_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -53,14 +52,14 @@ struct ion_sound_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct ion_sound_ctx -create_ctx(void) +struct ion_sound_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -83,7 +82,7 @@ create_ctx(void) // Derived physical quantities (using non-normalized physical units). double nu_ion = 2.0; // Ion collision frequency. double nu_elc = nu_ion * sqrt(mass_ion / mass_elc); // Electron collision frequency. - + double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -92,20 +91,27 @@ create_ctx(void) int Nvpar = 64; // Cell count (velocity space: parallel velocity direction). int Nmu = 12; // Cell count (velocity space: magnetic moment direction). double Lz = 2.0 * M_PI / kz; // Domain size (configuration space: z-direction). - double vpar_max_elc = 6.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = mass_elc * pow(6.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = mass_ion * pow(6.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 6.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + mass_elc * pow(6.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + mass_ion * pow(6.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 0.25; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct ion_sound_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -140,14 +146,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct ion_sound_ctx *app = ctx; @@ -157,8 +164,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; @@ -168,15 +174,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct ion_sound_ctx *app = ctx; double z = xn[0]; @@ -191,8 +197,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; @@ -202,15 +207,13 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; @@ -220,8 +223,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; @@ -232,20 +234,21 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct ion_sound_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -253,7 +256,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct ion_sound_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -266,18 +269,18 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_elc * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_elc * (cvpar * cvpar); } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } static inline void -mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_ion(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct ion_sound_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -290,23 +293,24 @@ mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_ion * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_ion * (cvpar * cvpar); } mu = mu_max_ion * (cmu * cmu); // Set rescaled ion velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -317,10 +321,12 @@ main(int argc, char **argv) struct ion_sound_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct lapd_cart_ctx -{ +struct lapd_cart_ctx { int cdim, vdim; // Dimensionality. - + // Physical constants (using non-normalized physical units). double epsilon0; // Permittivity of free space. double mass_elc; // Electron mass. @@ -65,14 +64,14 @@ struct lapd_cart_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lapd_cart_ctx -create_ctx(void) +struct lapd_cart_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -95,13 +94,15 @@ create_ctx(void) double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Collision frequencies. - double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion,4) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_elc) * pow(Te,3.0/2.0)); - double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion,4) * n0 / - (12.0 * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_ion) * pow(Ti,3.0/2.0)); - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_ion_elc*(mass_elc/mass_ion); - + double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4) * n0 / + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); + double nu_ion = + nu_frac * log_lambda_ion * pow(charge_ion, 4) * n0 / + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_ion_elc * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -124,18 +125,25 @@ create_ctx(void) double Ly = 100.0 * rho_s; // Domain size (configuration space: y-direction). double Lz = 36.0 * 40.0 * rho_s; // Domain size (configuration space: z-direction). double L_perp = Lx; // Perpendicular length of domain. - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte,2) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti,2) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double t_end = 1.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lapd_cart_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -184,14 +192,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cart_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -207,9 +214,10 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n = 0.0; if (r < 0.5 * L_perp) { - n = ((1.0 - (1.0 / 20.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + (1.0 / 20.0)) * n0 * (1.0 + perturb); - } - else { + n = ((1.0 - (1.0 / 20.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + + (1.0 / 20.0)) * + n0 * (1.0 + perturb); + } else { n = (1.0 / 20.0) * n0 * (1.0 + perturb); } @@ -217,15 +225,13 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cart_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -238,9 +244,10 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double T = 0.0; if (r < 0.5 * L_perp) { - T = ((1.0 - (1.0 / 5.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + (1.0 / 5.0)) * Te; - } - else { + T = ((1.0 - (1.0 / 5.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + + (1.0 / 5.0)) * + Te; + } else { T = (1.0 / 5.0) * Te; } @@ -248,8 +255,7 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cart_ctx *app = ctx; @@ -259,8 +265,9 @@ evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lapd_cart_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -276,15 +283,17 @@ evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = S0 * (floor_src + (1.0 - floor_src) * 0.5 * (1.0 - tanh((r - r_src) / L_src))); } -void -evalSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set source parallel velocity. fout[0] = 0.0; } -void -evalSourceTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempElcInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lapd_cart_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -297,9 +306,10 @@ evalSourceTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double T = 0.0; if (r < 0.5 * L_perp) { - T = (1.0 - (1.0 / 2.5) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + (1.0 / 2.5)) * Te_src; - } - else { + T = (1.0 - (1.0 / 2.5) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + + (1.0 / 2.5)) * + Te_src; + } else { T = (1.0 / 2.5) * Te_src; } @@ -307,8 +317,9 @@ evalSourceTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalSourceTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempIonInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lapd_cart_ctx *app = ctx; @@ -318,8 +329,7 @@ evalSourceTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = Ti; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cart_ctx *app = ctx; @@ -329,8 +339,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cart_ctx *app = ctx; @@ -340,8 +349,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cart_ctx *app = ctx; @@ -351,8 +359,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cart_ctx *app = ctx; @@ -363,33 +370,35 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cart_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -400,10 +409,12 @@ main(int argc, char **argv) struct lapd_cart_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct lapd_cyl_ctx -{ +struct lapd_cyl_ctx { int cdim, vdim; // Dimensionality. - + // Physical constants (using non-normalized physical units). double epsilon0; // Permittivity of free space. double mass_elc; // Electron mass. @@ -65,14 +64,14 @@ struct lapd_cyl_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lapd_cyl_ctx -create_ctx(void) +struct lapd_cyl_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -95,13 +94,15 @@ create_ctx(void) double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Collision frequencies. - double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion,4) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_elc) * pow(Te,3.0/2.0)); - double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion,4) * n0 / - (12.0 * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_ion) * pow(Ti,3.0/2.0)); - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_ion_elc*(mass_elc/mass_ion); - + double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4) * n0 / + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); + double nu_ion = + nu_frac * log_lambda_ion * pow(charge_ion, 4) * n0 / + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_ion_elc * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -124,18 +125,25 @@ create_ctx(void) double Ltheta = 2.0 * M_PI; // Domain size (configuration space: angular direction). double Lz = 36.0 * 40.0 * rho_s; // Domain size (configuration space: z-direction). double L_perp = 100.0 * rho_s; // Perpendicular length of domain. - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte,2) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti,2) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double t_end = 1.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lapd_cyl_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -184,15 +192,14 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; double r = xn[0]; @@ -206,9 +213,10 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n = 0.0; if (r < 0.5 * L_perp) { - n = ((1.0 - (1.0 / 20.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + (1.0 / 20.0)) * n0 * (1.0 + perturb); - } - else { + n = ((1.0 - (1.0 / 20.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + + (1.0 / 20.0)) * + n0 * (1.0 + perturb); + } else { n = (1.0 / 20.0) * n0 * (1.0 + perturb); } @@ -216,15 +224,13 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; double r = xn[0]; @@ -235,9 +241,10 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double T = 0.0; if (r < 0.5 * L_perp) { - T = ((1.0 - (1.0 / 5.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + (1.0 / 5.0)) * Te; - } - else { + T = ((1.0 - (1.0 / 5.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + + (1.0 / 5.0)) * + Te; + } else { T = (1.0 / 5.0) * Te; } @@ -245,8 +252,7 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; @@ -256,8 +262,9 @@ evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lapd_cyl_ctx *app = ctx; double r = xn[0]; @@ -271,15 +278,17 @@ evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = S0 * (floor_src + (1.0 - floor_src) * 0.5 * (1.0 - tanh((r - r_src) / L_src))); } -void -evalSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set source parallel velocity. fout[0] = 0.0; } -void -evalSourceTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempElcInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lapd_cyl_ctx *app = ctx; double r = xn[0]; @@ -290,9 +299,10 @@ evalSourceTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double T = 0.0; if (r < 0.5 * L_perp) { - T = (1.0 - (1.0 / 2.5) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + (1.0 / 2.5)) * Te_src; - } - else { + T = (1.0 - (1.0 / 2.5) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + + (1.0 / 2.5)) * + Te_src; + } else { T = (1.0 / 2.5) * Te_src; } @@ -300,8 +310,9 @@ evalSourceTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalSourceTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempIonInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lapd_cyl_ctx *app = ctx; @@ -311,8 +322,7 @@ evalSourceTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = Ti; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; @@ -322,8 +332,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; @@ -333,8 +342,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; @@ -344,8 +352,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; @@ -356,7 +363,7 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double r = zc[0], theta = zc[1], z = zc[2]; @@ -366,27 +373,27 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* xp[2] = z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -397,10 +404,12 @@ main(int argc, char **argv) struct lapd_cyl_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct lapd_cyl_ctx -{ +struct lapd_cyl_ctx { int cdim, vdim; // Dimensionality. - + // Physical constants (using non-normalized physical units). double epsilon0; // Permittivity of free space. double mass_elc; // Electron mass. @@ -65,14 +64,14 @@ struct lapd_cyl_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lapd_cyl_ctx -create_ctx(void) +struct lapd_cyl_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -95,13 +94,15 @@ create_ctx(void) double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Collision frequencies. - double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion,4) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_elc) * pow(Te,3.0/2.0)); - double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion,4) * n0 / - (12.0 * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_ion) * pow(Ti,3.0/2.0)); - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_ion_elc*(mass_elc/mass_ion); - + double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4) * n0 / + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); + double nu_ion = + nu_frac * log_lambda_ion * pow(charge_ion, 4) * n0 / + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_ion_elc * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -124,18 +125,25 @@ create_ctx(void) double Ltheta = 2.0 * M_PI; // Domain size (configuration space: angular direction). double Lz = 36.0 * 40.0 * rho_s; // Domain size (configuration space: z-direction). double L_perp = 100.0 * rho_s; // Perpendicular length of domain. - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte,2) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti,2) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double t_end = 1.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lapd_cyl_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -184,15 +192,14 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; double r = xn[0]; @@ -206,9 +213,10 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n = 0.0; if (r < 0.5 * L_perp) { - n = ((1.0 - (1.0 / 20.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + (1.0 / 20.0)) * n0 * (1.0 + perturb); - } - else { + n = ((1.0 - (1.0 / 20.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + + (1.0 / 20.0)) * + n0 * (1.0 + perturb); + } else { n = (1.0 / 20.0) * n0 * (1.0 + perturb); } @@ -216,15 +224,13 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; double r = xn[0]; @@ -235,9 +241,10 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double T = 0.0; if (r < 0.5 * L_perp) { - T = ((1.0 - (1.0 / 5.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + (1.0 / 5.0)) * Te; - } - else { + T = ((1.0 - (1.0 / 5.0)) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + + (1.0 / 5.0)) * + Te; + } else { T = (1.0 / 5.0) * Te; } @@ -245,8 +252,7 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; @@ -256,8 +262,9 @@ evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lapd_cyl_ctx *app = ctx; double r = xn[0]; @@ -271,15 +278,17 @@ evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = S0 * (floor_src + (1.0 - floor_src) * 0.5 * (1.0 - tanh((r - r_src) / L_src))); } -void -evalSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set source parallel velocity. fout[0] = 0.0; } -void -evalSourceTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempElcInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lapd_cyl_ctx *app = ctx; double r = xn[0]; @@ -290,9 +299,10 @@ evalSourceTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double T = 0.0; if (r < 0.5 * L_perp) { - T = (1.0 - (1.0 / 2.5) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + (1.0 / 2.5)) * Te_src; - } - else { + T = (1.0 - (1.0 / 2.5) * pow(1.0 - (r / (0.5 * L_perp)) * (r / (0.5 * L_perp)), 3.0) + + (1.0 / 2.5)) * + Te_src; + } else { T = (1.0 / 2.5) * Te_src; } @@ -300,8 +310,9 @@ evalSourceTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalSourceTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempIonInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lapd_cyl_ctx *app = ctx; @@ -311,8 +322,7 @@ evalSourceTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = Ti; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; @@ -322,8 +332,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; @@ -333,8 +342,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; @@ -344,8 +352,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; @@ -355,19 +362,18 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_ion_elc; } -void -mc2nu_r(double t, const double* GKYL_RESTRICT xc, double* GKYL_RESTRICT xnu, void* ctx) +void mc2nu_r(double t, const double *GKYL_RESTRICT xc, double *GKYL_RESTRICT xnu, void *ctx) { struct lapd_cyl_ctx *app = ctx; double r = xc[0]; double r_min = 2.5 * app->rho_s; double r_max = 2.5 * app->rho_s + app->Lr; double poly_order = 1.4; - xnu[0] = pow(r - r_min, poly_order)*pow(r_max - r_min, 1 - poly_order) + r_min; + xnu[0] = pow(r - r_min, poly_order) * pow(r_max - r_min, 1 - poly_order) + r_min; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double r = zc[0], theta = zc[1], z = zc[2]; @@ -377,27 +383,27 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* xp[2] = z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct lapd_cyl_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -408,10 +414,12 @@ main(int argc, char **argv) struct lapd_cyl_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct lbo_cross_relax_ctx -{ +struct lbo_cross_relax_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -64,14 +63,14 @@ struct lbo_cross_relax_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_cross_relax_ctx -create_ctx(void) +struct lbo_cross_relax_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -96,13 +95,17 @@ create_ctx(void) double Te = (T_par_elc + (2.0 * T_perp_elc)) / 3.0; // Electron temperature. double Ti = (T_par_ion + (2.0 * T_perp_ion)) / 3.0; // Ion temperature. - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_elc / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_ion / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_elc / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_par_ion / charge_ion); // Ion Coulomb logarithm. double nu_elc = log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(T_par_elc, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(T_par_elc, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(T_par_ion, 3.0 / 2.0)); // Ion collision frequency. - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(T_par_ion, 3.0 / 2.0)); // Ion collision frequency. + double vte_par = sqrt(T_par_elc / mass_elc); // Parallel electron thermal velocity. double vti_par = sqrt(T_par_ion / mass_ion); // Parallel ion thermal velocity. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. @@ -116,20 +119,27 @@ create_ctx(void) int Nvpar = 16; // Cell count (velocity space: parallel velocity direction). int Nmu = 16; // Cell count (velocity space: magnetic moment direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 5.0 * vte_par; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = mass_elc * pow(5.0 * vte_par, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 5.0 * vti_par; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = mass_ion * pow(5.0 * vti_par, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 5.0 * vte_par; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + mass_elc * pow(5.0 * vte_par, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 5.0 * vti_par; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + mass_ion * pow(5.0 * vti_par, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 0.1 / nu_ion; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lbo_cross_relax_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -172,14 +182,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_cross_relax_ctx *app = ctx; @@ -189,8 +200,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_relax_ctx *app = ctx; @@ -200,8 +210,9 @@ evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_elc; } -void -evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_cross_relax_ctx *app = ctx; @@ -211,8 +222,7 @@ evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_elc; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_relax_ctx *app = ctx; @@ -222,8 +232,9 @@ evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = upar_elc; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_cross_relax_ctx *app = ctx; @@ -233,8 +244,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_relax_ctx *app = ctx; @@ -244,8 +254,9 @@ evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_ion; } -void -evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_cross_relax_ctx *app = ctx; @@ -255,19 +266,17 @@ evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_ion; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_relax_ctx *app = ctx; - + double upar_ion = app->upar_ion; // Set ion parallel velocity. fout[0] = upar_ion; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_relax_ctx *app = ctx; @@ -277,8 +286,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_relax_ctx *app = ctx; @@ -289,33 +297,35 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_relax_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -326,10 +336,12 @@ main(int argc, char **argv) struct lbo_cross_relax_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct lbo_relax_ctx -{ +struct lbo_relax_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using normalized code units). @@ -44,14 +43,14 @@ struct lbo_relax_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_relax_ctx -create_ctx(void) +struct lbo_relax_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -78,14 +77,16 @@ create_ctx(void) int Nmu = 16; // Cell count (velocity space: magnetic moment direction). double Lz = 1.0; // Domain size (configuration space: x-direction). double vpar_max = 8.0 * vt; // Domain boundary (velocity space: parallel velocity direction). - double mu_max = 0.5 * mass * pow(3.5 * vt, 2.0) / B0; // Domain boundary (velocity space: magnetic moment direction). + double mu_max = 0.5 * mass * pow(3.5 * vt, 2.0) / + B0; // Domain boundary (velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 0.5 / nu; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -117,14 +118,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vpar = xn[1]; @@ -138,8 +138,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (fabs(vpar) < v0) { n = n0 / 2.0 / v0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -147,8 +146,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vpar = xn[1], mu = xn[2]; @@ -166,16 +164,16 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vpar - u0) / (sqrt(2.0) * vt)) * ((vpar - u0) / (sqrt(2.0) * vt)) + mu * B0; double vb_sq = ((vpar - u0) / (sqrt(2.0) * vtb)) * ((vpar - u0) / (sqrt(2.0) * vtb)) + mu * B0; - - double n = (n0 / sqrt(2.0 * M_PI * vt)) * exp(-v_sq) + (n0 / sqrt(2.0 * M_PI * vtb)) * - exp(-vb_sq) * (ab * ab) / ((vpar - ub) * (vpar - ub) + sb * sb); // Distribution function. + + double n = (n0 / sqrt(2.0 * M_PI * vt)) * exp(-v_sq) + + (n0 / sqrt(2.0 * M_PI * vtb)) * exp(-vb_sq) * (ab * ab) / + ((vpar - ub) * (vpar - ub) + sb * sb); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalTopHatNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -185,8 +183,7 @@ evalTopHatNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu; } -void -evalBumpNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -197,33 +194,35 @@ evalBumpNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; - + double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -234,10 +233,12 @@ main(int argc, char **argv) struct lbo_relax_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct lbo_relax_ctx -{ +struct lbo_relax_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -65,14 +64,14 @@ struct lbo_relax_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_relax_ctx -create_ctx(void) +struct lbo_relax_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -103,13 +102,17 @@ create_ctx(void) double Te = (T_par_elc + (2.0 * T_perp_elc)) / 3.0; // Electron temperature. double Ti = (T_par_ion + (2.0 * T_perp_ion)) / 3.0; // Ion temperature. - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -118,20 +121,27 @@ create_ctx(void) int Nvpar = 16; // Cell count (velocity space: parallel velocity direction). int Nmu = 8; // Cell count (velocity space: magnetic moment direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 1.0 / nu_elc; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lbo_relax_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -175,14 +185,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_relax_ctx *app = ctx; @@ -192,8 +203,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -203,8 +213,9 @@ evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_elc; } -void -evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_relax_ctx *app = ctx; @@ -214,15 +225,15 @@ evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_elc; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_relax_ctx *app = ctx; @@ -232,8 +243,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -243,8 +253,9 @@ evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_ion; } -void -evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_relax_ctx *app = ctx; @@ -254,15 +265,13 @@ evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_ion; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -272,8 +281,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -284,20 +292,21 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -305,7 +314,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct lbo_relax_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -318,23 +327,24 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_elc * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_elc * (cvpar * cvpar); } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -345,10 +355,12 @@ main(int argc, char **argv) struct lbo_relax_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct lbo_relax_ctx -{ +struct lbo_relax_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -69,14 +68,14 @@ struct lbo_relax_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_relax_ctx -create_ctx(void) +struct lbo_relax_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -107,13 +106,17 @@ create_ctx(void) double Te = (T_par_elc + (2.0 * T_perp_elc)) / 3.0; // Electron temperature. double Ti = (T_par_ion + (2.0 * T_perp_ion)) / 3.0; // Ion temperature. - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -126,20 +129,27 @@ create_ctx(void) double Lx = 1.0; // Domain size (configuration space: x-direction). double Ly = 1.0; // Domain size (configuration space: y-direction). double Lz = 1.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 0.04 / nu_elc; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lbo_relax_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -187,14 +197,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_relax_ctx *app = ctx; @@ -204,8 +215,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -215,8 +225,9 @@ evalElcTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_elc; } -void -evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_relax_ctx *app = ctx; @@ -226,15 +237,15 @@ evalElcTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_elc; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_relax_ctx *app = ctx; @@ -244,8 +255,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -255,8 +265,9 @@ evalIonTparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_par_ion; } -void -evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTperpInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct lbo_relax_ctx *app = ctx; @@ -266,15 +277,13 @@ evalIonTperpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T_perp_ion; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -284,8 +293,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -296,20 +304,21 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -317,7 +326,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct lbo_relax_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -330,23 +339,24 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_elc * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_elc * (cvpar * cvpar); } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -357,10 +367,12 @@ main(int argc, char **argv) struct lbo_relax_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct lbo_relax_ctx -{ +struct lbo_relax_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using normalized code units). @@ -44,14 +43,14 @@ struct lbo_relax_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_relax_ctx -create_ctx(void) +struct lbo_relax_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -78,14 +77,16 @@ create_ctx(void) int Nmu = 16; // Cell count (velocity space: magnetic moment direction). double Lz = 1.0; // Domain size (configuration space: x-direction). double vpar_max = 8.0 * vt; // Domain boundary (velocity space: parallel velocity direction). - double mu_max = 0.5 * mass * pow(3.5 * vt, 2.0) / B0; // Domain boundary (velocity space: magnetic moment direction). + double mu_max = 0.5 * mass * pow(3.5 * vt, 2.0) / + B0; // Domain boundary (velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 0.01 / nu; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -117,14 +118,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vpar = xn[1]; @@ -138,8 +138,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (fabs(vpar) < v0) { n = n0 / 2.0 / v0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -147,8 +146,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vpar = xn[1], mu = xn[2]; @@ -166,16 +164,16 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vpar - u0) / (sqrt(2.0) * vt)) * ((vpar - u0) / (sqrt(2.0) * vt)) + mu * B0; double vb_sq = ((vpar - u0) / (sqrt(2.0) * vtb)) * ((vpar - u0) / (sqrt(2.0) * vtb)) + mu * B0; - - double n = (n0 / sqrt(2.0 * M_PI * vt)) * exp(-v_sq) + (n0 / sqrt(2.0 * M_PI * vtb)) * - exp(-vb_sq) * (ab * ab) / ((vpar - ub) * (vpar - ub) + sb * sb); // Distribution function. + + double n = (n0 / sqrt(2.0 * M_PI * vt)) * exp(-v_sq) + + (n0 / sqrt(2.0 * M_PI * vtb)) * exp(-vb_sq) * (ab * ab) / + ((vpar - ub) * (vpar - ub) + sb * sb); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalTopHatNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -185,8 +183,7 @@ evalTopHatNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu; } -void -evalBumpNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -197,20 +194,21 @@ evalBumpNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; - + double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -218,7 +216,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout } static inline void -mapc2p_vel_square(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_square(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct lbo_relax_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -231,18 +229,18 @@ mapc2p_vel_square(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRIC if (cvpar < 0.0) { vpar = -vpar_max * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max * (cvpar * cvpar); } mu = mu_max * (cmu * cmu); // Set rescaled top hat velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } static inline void -mapc2p_vel_bump(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_bump(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct lbo_relax_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -255,23 +253,24 @@ mapc2p_vel_bump(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT if (cvpar < 0.0) { vpar = -vpar_max * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max * (cvpar * cvpar); } mu = mu_max * (cmu * cmu); // Set rescaled bump velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -282,10 +281,12 @@ main(int argc, char **argv) struct lbo_relax_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct lbo_relax_ctx -{ +struct lbo_relax_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using normalized code units). @@ -44,14 +43,14 @@ struct lbo_relax_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_relax_ctx -create_ctx(void) +struct lbo_relax_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -77,14 +76,16 @@ create_ctx(void) int Nmu = 16; // Cell count (velocity space: magnetic moment direction). double Lz = 1.0; // Domain size (configuration space: x-direction). double vpar_max = 8.0 * vt; // Domain boundary (velocity space: parallel velocity direction). - double mu_max = 0.5 * mass * pow(3.5 * vt, 2.0) / B0; // Domain boundary (velocity space: magnetic moment direction). + double mu_max = 0.5 * mass * pow(3.5 * vt, 2.0) / + B0; // Domain boundary (velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 0.5 / nu; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -116,14 +117,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vpar = xn[1]; @@ -137,8 +137,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (fabs(vpar) < v0) { n = n0 / 2.0 / v0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -146,8 +145,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vpar = xn[1], mu = xn[2]; @@ -165,16 +163,16 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vpar - u0) / (sqrt(2.0) * vt)) * ((vpar - u0) / (sqrt(2.0) * vt)) + mu * B0; double vb_sq = ((vpar - u0) / (sqrt(2.0) * vtb)) * ((vpar - u0) / (sqrt(2.0) * vtb)) + mu * B0; - - double n = (n0 / sqrt(2.0 * M_PI * vt)) * exp(-v_sq) + (n0 / sqrt(2.0 * M_PI * vtb)) * - exp(-vb_sq) * (ab * ab) / ((vpar - ub) * (vpar - ub) + sb * sb); // Distribution function. + + double n = (n0 / sqrt(2.0 * M_PI * vt)) * exp(-v_sq) + + (n0 / sqrt(2.0 * M_PI * vtb)) * exp(-vb_sq) * (ab * ab) / + ((vpar - ub) * (vpar - ub) + sb * sb); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalTopHatNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -184,8 +182,7 @@ evalTopHatNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu; } -void -evalBumpNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -196,33 +193,35 @@ evalBumpNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; - + double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -233,10 +232,12 @@ main(int argc, char **argv) struct lbo_relax_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct boundary_ctx -{ +struct boundary_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -42,14 +41,14 @@ struct boundary_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct boundary_ctx -create_ctx(void) +struct boundary_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -65,7 +64,7 @@ create_ctx(void) // Derived physical quantities (using non-normalized physical units). double B0 = 1; // Reference magnetic field strength (Tesla). - + double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. // Simulation parameters. @@ -73,17 +72,21 @@ create_ctx(void) int Nvpar = 32; // Cell count (velocity space: parallel velocity direction). int Nmu = 32; // Cell count (velocity space: magnetic moment direction). double Lz = 1.0; // Domain size (configuration space: z-direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double cfl_frac = 1.0; // CFL coefficient. double t_end = 3.; // Final simulation time. int num_frames = 5; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct boundary_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -108,19 +111,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) +void compareToAnalytics(const struct gkyl_gk *app_inp, void *ctx) { struct boundary_ctx *app = ctx; char filename[256]; sprintf(filename, "%s-ion_integrated_moms.gkyl", app_inp->name); - struct gkyl_dynvec_etype_ncomp enc = { }; + struct gkyl_dynvec_etype_ncomp enc = {}; enc = gkyl_dynvec_read_ncomp(filename); gkyl_dynvec integrated_moms = gkyl_dynvec_new(enc.type, enc.ncomp); @@ -139,7 +142,7 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double erf_arg = L / (sqrt(2) * time * vt); double N_analytic = 2 * app->n0 / (sqrt(2 * M_PI)); - N_analytic *= sqrt(M_PI / 2) * L * erf(erf_arg) + time * vt * (exp(-erf_arg*erf_arg) - 1); + N_analytic *= sqrt(M_PI / 2) * L * erf(erf_arg) + time * vt * (exp(-erf_arg * erf_arg) - 1); double diff = fabs(N - N_analytic); int check = gkyl_compare_double(N, N_analytic, 1e-2); @@ -166,7 +169,7 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double erf_arg = L / (sqrt(2) * time * vt); double dNdt_analytic = app->n0 / (sqrt(2 * M_PI)); - dNdt_analytic *= 1 - exp(-erf_arg*erf_arg); + dNdt_analytic *= 1 - exp(-erf_arg * erf_arg); // printf("dNdt: %g, dNdt_analytic: %g, difference: %g\n", dNdt, dNdt_analytic, fabs(dNdt - dNdt_analytic)); @@ -195,7 +198,7 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double erf_arg = L / (sqrt(2) * time * vt); double dNdt_analytic = app->n0 / (sqrt(2 * M_PI)); - dNdt_analytic *= 1 - exp(-erf_arg*erf_arg); + dNdt_analytic *= 1 - exp(-erf_arg * erf_arg); double diff = fabs(dNdt - dNdt_analytic); int check = gkyl_compare_double(dNdt, dNdt_analytic, 1e-1); @@ -212,28 +215,27 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) gkyl_dynvec_release(bflux_moms_upper); } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct boundary_ctx *app = ctx; fout[0] = app->n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; fout[0] = app->Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). xp[0] = zc[0]; @@ -241,24 +243,24 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -269,10 +271,12 @@ main(int argc, char **argv) struct boundary_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct boundary_ctx -{ +struct boundary_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -42,14 +41,14 @@ struct boundary_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct boundary_ctx -create_ctx(void) +struct boundary_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -65,7 +64,7 @@ create_ctx(void) // Derived physical quantities (using non-normalized physical units). double B0 = 1; // Reference magnetic field strength (Tesla). - + double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. // Simulation parameters. @@ -73,17 +72,21 @@ create_ctx(void) int Nvpar = 32; // Cell count (velocity space: parallel velocity direction). int Nmu = 32; // Cell count (velocity space: magnetic moment direction). double Lz = 1.0; // Domain size (configuration space: z-direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double cfl_frac = 1.0; // CFL coefficient. double t_end = 3; // Final simulation time. int num_frames = 5; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct boundary_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -108,20 +111,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - -void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) +void compareToAnalytics(const struct gkyl_gk *app_inp, void *ctx) { struct boundary_ctx *app = ctx; char filename[256]; sprintf(filename, "%s-ion_integrated_moms.gkyl", app_inp->name); - struct gkyl_dynvec_etype_ncomp enc = { }; + struct gkyl_dynvec_etype_ncomp enc = {}; enc = gkyl_dynvec_read_ncomp(filename); gkyl_dynvec integrated_moms = gkyl_dynvec_new(enc.type, enc.ncomp); @@ -140,7 +142,7 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double erf_arg = L / (sqrt(2) * time * vt); double N_analytic = 2 * app->n0 / (sqrt(2 * M_PI)); - N_analytic *= sqrt(M_PI / 2) * L * erf(erf_arg) + time * vt * (exp(-erf_arg*erf_arg) - 1); + N_analytic *= sqrt(M_PI / 2) * L * erf(erf_arg) + time * vt * (exp(-erf_arg * erf_arg) - 1); double diff = fabs(N - N_analytic) / fabs(N_analytic); int check = gkyl_compare_double(diff, 0.0, 1e-2); @@ -172,14 +174,18 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double erf_arg = L / (sqrt(2) * time * vt); double dNdt_analytic = app->n0 / (sqrt(2 * M_PI)); - dNdt_analytic *= 1 - exp(-erf_arg*erf_arg); + dNdt_analytic *= 1 - exp(-erf_arg * erf_arg); // printf("dNdt: %g, dNdt_analytic: %g, difference: %g\n", dNdt, dNdt_analytic, fabs(dNdt - dNdt_analytic)); double diff = fabs(dNdt - dNdt_analytic); int check = gkyl_compare_double(dNdt, dNdt_analytic, 1e-1); if (check != 1) { - printf("Error: dNdt (lower boundary) and dNdt_analytic do not match within tolerance at time step %d.\n", i); + printf( + "Error: dNdt (lower boundary) and dNdt_analytic do not match within tolerance at time " + "step %d.\n", + i + ); printf(" Time: %g\n", time); printf(" dNdt (computed): %g\n", dNdt); printf(" dNdt_analytic (expected): %g\n", dNdt_analytic); @@ -206,12 +212,16 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double erf_arg = L / (sqrt(2) * time * vt); double dNdt_analytic = app->n0 / (sqrt(2 * M_PI)); - dNdt_analytic *= 1 - exp(-erf_arg*erf_arg); + dNdt_analytic *= 1 - exp(-erf_arg * erf_arg); double diff = fabs(dNdt - dNdt_analytic); int check = gkyl_compare_double(dNdt, dNdt_analytic, 1e-1); if (check != 1) { - printf("Error: dNdt (upper boundary) and dNdt_analytic do not match within tolerance at time step %d.\n", i); + printf( + "Error: dNdt (upper boundary) and dNdt_analytic do not match within tolerance at time " + "step %d.\n", + i + ); printf(" Time: %g\n", time); printf(" dNdt (computed): %g\n", dNdt); printf(" dNdt_analytic (expected): %g\n", dNdt_analytic); @@ -228,61 +238,63 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) gkyl_dynvec_release(bflux_moms_upper); } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct boundary_ctx *app = ctx; fout[0] = app->n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; fout[0] = app->Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -static inline void -nonuniform_position_map_z(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_z( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { struct boundary_ctx *app = ctx; double z = zc[0]; double L = app->Lz; double b = 1.2; // controls non-uniformity - xp[0] = L * tan(2*z*b/L) / (2 * tan(b)); + xp[0] = L * tan(2 * z * b / L) / (2 * tan(b)); } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -293,10 +305,12 @@ main(int argc, char **argv) struct boundary_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct boundary_ctx -{ +struct boundary_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -42,14 +41,14 @@ struct boundary_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct boundary_ctx -create_ctx(void) +struct boundary_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -65,7 +64,7 @@ create_ctx(void) // Derived physical quantities (using non-normalized physical units). double B0 = 1; // Reference magnetic field strength (Tesla). - + double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. // Simulation parameters. @@ -73,17 +72,21 @@ create_ctx(void) int Nvpar = 32; // Cell count (velocity space: parallel velocity direction). int Nmu = 32; // Cell count (velocity space: magnetic moment direction). double Lz = 1.0; // Domain size (configuration space: z-direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double cfl_frac = 1.0; // CFL coefficient. double t_end = 3; // Final simulation time. int num_frames = 5; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct boundary_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -108,20 +111,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - -void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) +void compareToAnalytics(const struct gkyl_gk *app_inp, void *ctx) { struct boundary_ctx *app = ctx; char filename[256]; sprintf(filename, "%s-ion_integrated_moms.gkyl", app_inp->name); - struct gkyl_dynvec_etype_ncomp enc = { }; + struct gkyl_dynvec_etype_ncomp enc = {}; enc = gkyl_dynvec_read_ncomp(filename); gkyl_dynvec integrated_moms = gkyl_dynvec_new(enc.type, enc.ncomp); @@ -140,7 +142,7 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double erf_arg = L / (sqrt(2) * time * vt); double N_analytic = 2 * app->n0 / (sqrt(2 * M_PI)); - N_analytic *= sqrt(M_PI / 2) * L * erf(erf_arg) + time * vt * (exp(-erf_arg*erf_arg) - 1); + N_analytic *= sqrt(M_PI / 2) * L * erf(erf_arg) + time * vt * (exp(-erf_arg * erf_arg) - 1); double diff = fabs(N - N_analytic); int check = gkyl_compare_double(N, N_analytic, 1e-2); @@ -167,7 +169,7 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double erf_arg = L / (sqrt(2) * time * vt); double dNdt_analytic = app->n0 / (sqrt(2 * M_PI)); - dNdt_analytic *= 1 - exp(-erf_arg*erf_arg); + dNdt_analytic *= 1 - exp(-erf_arg * erf_arg); // printf("dNdt: %g, dNdt_analytic: %g, difference: %g\n", dNdt, dNdt_analytic, fabs(dNdt - dNdt_analytic)); @@ -196,7 +198,7 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double erf_arg = L / (sqrt(2) * time * vt); double dNdt_analytic = app->n0 / (sqrt(2 * M_PI)); - dNdt_analytic *= 1 - exp(-erf_arg*erf_arg); + dNdt_analytic *= 1 - exp(-erf_arg * erf_arg); double diff = fabs(dNdt - dNdt_analytic); int check = gkyl_compare_double(dNdt, dNdt_analytic, 1e-1); @@ -213,61 +215,63 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) gkyl_dynvec_release(bflux_moms_upper); } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct boundary_ctx *app = ctx; fout[0] = app->n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; fout[0] = app->Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -static inline void -nonuniform_position_map_z(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_z( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { struct boundary_ctx *app = ctx; double z = zc[0]; double L = app->Lz; double b = 5; // controls non-uniformity - xp[0] = L * atan(2*z*b/L) / (2 * atan(b)); + xp[0] = L * atan(2 * z * b / L) / (2 * atan(b)); } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -278,10 +282,12 @@ main(int argc, char **argv) struct boundary_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct boundary_ctx -{ +struct boundary_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -42,14 +41,14 @@ struct boundary_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct boundary_ctx -create_ctx(void) +struct boundary_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -65,25 +64,29 @@ create_ctx(void) // Derived physical quantities (using non-normalized physical units). double B0 = 1; // Reference magnetic field strength (Tesla). - + double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. // Simulation parameters. int Nz = 16; // Cell count (configuration space: z-direction). int Nvpar = 32; // Cell count (velocity space: parallel velocity direction). int Nmu = 32; // Cell count (velocity space: magnetic moment direction). - double Lz = 1.0/5.0; // Domain size (configuration space: z-direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double Lz = 1.0 / 5.0; // Domain size (configuration space: z-direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double cfl_frac = 1.0; // CFL coefficient. double t_end = 3.; // Final simulation time. int num_frames = 5; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct boundary_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -108,19 +111,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) +void compareToAnalytics(const struct gkyl_gk *app_inp, void *ctx) { struct boundary_ctx *app = ctx; char filename[256]; sprintf(filename, "%s-ion_integrated_moms.gkyl", app_inp->name); - struct gkyl_dynvec_etype_ncomp enc = { }; + struct gkyl_dynvec_etype_ncomp enc = {}; enc = gkyl_dynvec_read_ncomp(filename); gkyl_dynvec integrated_moms = gkyl_dynvec_new(enc.type, enc.ncomp); @@ -135,11 +138,11 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double N = data[0]; double vt = sqrt(app->Ti / app->mass_ion); - double L = app->Lz*5.; // We need physical length, not computational length. + double L = app->Lz * 5.; // We need physical length, not computational length. double erf_arg = L / (sqrt(2) * time * vt); double N_analytic = 2 * app->n0 / (sqrt(2 * M_PI)); - N_analytic *= sqrt(M_PI / 2) * L * erf(erf_arg) + time * vt * (exp(-erf_arg*erf_arg) - 1); + N_analytic *= sqrt(M_PI / 2) * L * erf(erf_arg) + time * vt * (exp(-erf_arg * erf_arg) - 1); double diff = fabs(N - N_analytic); int check = gkyl_compare_double(N, N_analytic, 1e-2); @@ -162,11 +165,11 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double dNdt = data[0]; double vt = sqrt(app->Ti / app->mass_ion); - double L = app->Lz*5.; // We need physical length, not computational length. + double L = app->Lz * 5.; // We need physical length, not computational length. double erf_arg = L / (sqrt(2) * time * vt); double dNdt_analytic = app->n0 / (sqrt(2 * M_PI)); - dNdt_analytic *= 1 - exp(-erf_arg*erf_arg); + dNdt_analytic *= 1 - exp(-erf_arg * erf_arg); // printf("dNdt: %g, dNdt_analytic: %g, difference: %g\n", dNdt, dNdt_analytic, fabs(dNdt - dNdt_analytic)); @@ -191,11 +194,11 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double dNdt = data[0]; double vt = sqrt(app->Ti / app->mass_ion); - double L = app->Lz*5.; // We need physical length, not computational length. + double L = app->Lz * 5.; // We need physical length, not computational length. double erf_arg = L / (sqrt(2) * time * vt); double dNdt_analytic = app->n0 / (sqrt(2 * M_PI)); - dNdt_analytic *= 1 - exp(-erf_arg*erf_arg); + dNdt_analytic *= 1 - exp(-erf_arg * erf_arg); double diff = fabs(dNdt - dNdt_analytic); int check = gkyl_compare_double(dNdt, dNdt_analytic, 1e-1); @@ -212,53 +215,52 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) gkyl_dynvec_release(bflux_moms_upper); } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct boundary_ctx *app = ctx; fout[0] = app->n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; fout[0] = app->Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; - xp[1] = zc[1]; - xp[2] = 5*zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = 5 * zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -269,10 +271,12 @@ main(int argc, char **argv) struct boundary_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct boundary_ctx -{ +struct boundary_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -43,14 +42,14 @@ struct boundary_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct boundary_ctx -create_ctx(void) +struct boundary_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -66,7 +65,7 @@ create_ctx(void) // Derived physical quantities (using non-normalized physical units). double B0 = 1; // Reference magnetic field strength (Tesla). - + double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. // Simulation parameters. @@ -74,17 +73,21 @@ create_ctx(void) int Nvpar = 32; // Cell count (velocity space: parallel velocity direction). int Nmu = 32; // Cell count (velocity space: magnetic moment direction). double Lz = 1.0; // Domain size (configuration space: z-direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double cfl_frac = 1.0; // CFL coefficient. double t_end = 3.; // Final simulation time. int num_frames = 5; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct boundary_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -109,13 +112,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) +void compareToAnalytics(const struct gkyl_gk *app_inp, void *ctx) { struct boundary_ctx *app = ctx; char filename[256]; @@ -126,10 +129,11 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double *field_comp = gkyl_array_fetch(field, 0); - double sheath_val = field_comp[0]/sqrt(2.) - field_comp[1]*sqrt(3./2.); + double sheath_val = field_comp[0] / sqrt(2.) - field_comp[1] * sqrt(3. / 2.); - double analytical_sheath = app_inp->field.electron_temp / app_inp->field.electron_charge - * log(2 * sqrt(app_inp->field.electron_temp / app_inp->field.electron_mass)/(app->vti)); + double analytical_sheath = + app_inp->field.electron_temp / app_inp->field.electron_charge * + log(2 * sqrt(app_inp->field.electron_temp / app_inp->field.electron_mass) / (app->vti)); int check = gkyl_compare_double(sheath_val, analytical_sheath, 1e-3); if (check != 1) { @@ -138,35 +142,33 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) printf("Analytical sheath value: %g\n", analytical_sheath); printf("Difference: %g\n", sheath_val - analytical_sheath); printf("Percent difference: %g\n", fabs((sheath_val - analytical_sheath) / sheath_val)); - } - else { + } else { printf("Sheath value and analytical sheath value match!\n"); } gkyl_array_release(field); } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct boundary_ctx *app = ctx; fout[0] = app->n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; fout[0] = app->Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). xp[0] = zc[0]; @@ -174,24 +176,24 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -202,10 +204,12 @@ main(int argc, char **argv) struct boundary_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct boundary_ctx -{ +struct boundary_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -42,14 +41,14 @@ struct boundary_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct boundary_ctx -create_ctx(void) +struct boundary_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -65,7 +64,7 @@ create_ctx(void) // Derived physical quantities (using non-normalized physical units). double B0 = 1; // Reference magnetic field strength (Tesla). - + double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. // Simulation parameters. @@ -73,17 +72,21 @@ create_ctx(void) int Nvpar = 32; // Cell count (velocity space: parallel velocity direction). int Nmu = 32; // Cell count (velocity space: magnetic moment direction). double Lz = 1.0; // Domain size (configuration space: z-direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double cfl_frac = 1.0; // CFL coefficient. double t_end = 3; // Final simulation time. int num_frames = 5; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct boundary_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -108,14 +111,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - -void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) +void compareToAnalytics(const struct gkyl_gk *app_inp, void *ctx) { struct boundary_ctx *app = ctx; char filename[256]; @@ -126,10 +128,11 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double *field_comp = gkyl_array_fetch(field, 0); - double sheath_val = field_comp[0]/sqrt(2.) - field_comp[1]*sqrt(3./2.); + double sheath_val = field_comp[0] / sqrt(2.) - field_comp[1] * sqrt(3. / 2.); - double analytical_sheath = app_inp->field.electron_temp / app_inp->field.electron_charge - * log(2 * sqrt(app_inp->field.electron_temp / app_inp->field.electron_mass)/(app->vti)); + double analytical_sheath = + app_inp->field.electron_temp / app_inp->field.electron_charge * + log(2 * sqrt(app_inp->field.electron_temp / app_inp->field.electron_mass) / (app->vti)); int check = gkyl_compare_double(sheath_val, analytical_sheath, 1e-1); if (check != 1) { @@ -138,68 +141,69 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) printf("Analytical sheath value: %g\n", analytical_sheath); printf("Difference: %g\n", sheath_val - analytical_sheath); printf("Percent difference: %g\n", fabs((sheath_val - analytical_sheath) / sheath_val)); - } - else { + } else { printf("Sheath value and analytical sheath value match!\n"); } gkyl_array_release(field); } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct boundary_ctx *app = ctx; fout[0] = app->n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; fout[0] = app->Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -static inline void -nonuniform_position_map_z(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_z( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { struct boundary_ctx *app = ctx; double z = zc[0]; double L = app->Lz; double b = 1.2; // controls non-uniformity - xp[0] = L * tan(2*z*b/L) / (2 * tan(b)); + xp[0] = L * tan(2 * z * b / L) / (2 * tan(b)); } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -210,10 +214,12 @@ main(int argc, char **argv) struct boundary_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct boundary_ctx -{ +struct boundary_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -42,14 +41,14 @@ struct boundary_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct boundary_ctx -create_ctx(void) +struct boundary_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -65,7 +64,7 @@ create_ctx(void) // Derived physical quantities (using non-normalized physical units). double B0 = 1; // Reference magnetic field strength (Tesla). - + double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. // Simulation parameters. @@ -73,17 +72,21 @@ create_ctx(void) int Nvpar = 32; // Cell count (velocity space: parallel velocity direction). int Nmu = 32; // Cell count (velocity space: magnetic moment direction). double Lz = 1.0; // Domain size (configuration space: z-direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double cfl_frac = 1.0; // CFL coefficient. double t_end = 3; // Final simulation time. int num_frames = 5; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct boundary_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -108,13 +111,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) +void compareToAnalytics(const struct gkyl_gk *app_inp, void *ctx) { struct boundary_ctx *app = ctx; char filename[256]; @@ -125,10 +128,11 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double *field_comp = gkyl_array_fetch(field, 0); - double sheath_val = field_comp[0]/sqrt(2.) - field_comp[1]*sqrt(3./2.); + double sheath_val = field_comp[0] / sqrt(2.) - field_comp[1] * sqrt(3. / 2.); - double analytical_sheath = app_inp->field.electron_temp / app_inp->field.electron_charge - * log(2 * sqrt(app_inp->field.electron_temp / app_inp->field.electron_mass)/(app->vti)); + double analytical_sheath = + app_inp->field.electron_temp / app_inp->field.electron_charge * + log(2 * sqrt(app_inp->field.electron_temp / app_inp->field.electron_mass) / (app->vti)); int check = gkyl_compare_double(sheath_val, analytical_sheath, 1e-2); if (check != 1) { @@ -137,68 +141,69 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) printf("Analytical sheath value: %g\n", analytical_sheath); printf("Difference: %g\n", sheath_val - analytical_sheath); printf("Percent difference: %g\n", fabs((sheath_val - analytical_sheath) / sheath_val)); - } - else { + } else { printf("Sheath value and analytical sheath value match!\n"); } gkyl_array_release(field); } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct boundary_ctx *app = ctx; fout[0] = app->n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; fout[0] = app->Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -static inline void -nonuniform_position_map_z(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_z( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { struct boundary_ctx *app = ctx; double z = zc[0]; double L = app->Lz; double b = 5; // controls non-uniformity - xp[0] = L * atan(2*z*b/L) / ( 2 * atan(b) ); + xp[0] = L * atan(2 * z * b / L) / (2 * atan(b)); } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -209,10 +214,12 @@ main(int argc, char **argv) struct boundary_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct boundary_ctx -{ +struct boundary_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -42,14 +41,14 @@ struct boundary_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct boundary_ctx -create_ctx(void) +struct boundary_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -65,25 +64,29 @@ create_ctx(void) // Derived physical quantities (using non-normalized physical units). double B0 = 1; // Reference magnetic field strength (Tesla). - + double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. // Simulation parameters. int Nz = 16; // Cell count (configuration space: z-direction). int Nvpar = 32; // Cell count (velocity space: parallel velocity direction). int Nmu = 32; // Cell count (velocity space: magnetic moment direction). - double Lz = 1.0/5.0; // Domain size (configuration space: z-direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double Lz = 1.0 / 5.0; // Domain size (configuration space: z-direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double cfl_frac = 1.0; // CFL coefficient. double t_end = 3.; // Final simulation time. int num_frames = 5; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct boundary_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -108,13 +111,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) +void compareToAnalytics(const struct gkyl_gk *app_inp, void *ctx) { struct boundary_ctx *app = ctx; char filename[256]; @@ -125,10 +128,11 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) double *field_comp = gkyl_array_fetch(field, 0); - double sheath_val = field_comp[0]/sqrt(2.) - field_comp[1]*sqrt(3./2.); + double sheath_val = field_comp[0] / sqrt(2.) - field_comp[1] * sqrt(3. / 2.); - double analytical_sheath = app_inp->field.electron_temp / app_inp->field.electron_charge - * log(2 * sqrt(app_inp->field.electron_temp / app_inp->field.electron_mass)/(app->vti)); + double analytical_sheath = + app_inp->field.electron_temp / app_inp->field.electron_charge * + log(2 * sqrt(app_inp->field.electron_temp / app_inp->field.electron_mass) / (app->vti)); int check = gkyl_compare_double(sheath_val, analytical_sheath, 1e-3); if (check != 1) { @@ -137,60 +141,58 @@ void compareToAnalytics(const struct gkyl_gk *app_inp, void* ctx ) printf("Analytical sheath value: %g\n", analytical_sheath); printf("Difference: %g\n", sheath_val - analytical_sheath); printf("Percent difference: %g\n", fabs((sheath_val - analytical_sheath) / sheath_val)); - } - else { + } else { printf("Sheath value and analytical sheath value match!\n"); } gkyl_array_release(field); } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct boundary_ctx *app = ctx; fout[0] = app->n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; fout[0] = app->Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; - xp[1] = zc[1]; - xp[2] = 5*zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = 5 * zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct boundary_ctx *app = ctx; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -201,10 +203,12 @@ main(int argc, char **argv) struct boundary_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct li_react_ctx -{ +struct li_react_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -45,7 +44,7 @@ struct li_react_ctx double R; // Radial coordinate (simple toroidal coordinates). double B0; // Reference magnetic field strength (Tesla). - + double log_lambda_elc; // Electron Coulomb logarithm. double log_lambda_ion; // Ion Coulomb logarithm. double nu_elc; // Electron collision frequency. @@ -90,14 +89,14 @@ struct li_react_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct li_react_ctx -create_ctx(void) +struct li_react_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -132,15 +131,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0_elc / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0_elc / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -164,24 +167,37 @@ create_ctx(void) double Lx = 50.0 * rho_s; // Domain size (configuration space: x-direction). double Ly = 100.0 * rho_s; // Domain size (configuration space: y-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). - double vpar_max_Li1 = 4.0 * vtLi1; // Domain boundary (Li1+ velocity space: parallel velocity direction). - double mu_max_Li1 = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vtLi1, 2.0) / (2.0 * B0); // Domain boundary (Li1+ velocity space: magnetic moment direction). - double vpar_max_Li2 = 4.0 * vtLi2; // Domain boundary (Li2+ velocity space: parallel velocity direction). - double mu_max_Li2 = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vtLi2, 2.0) / (2.0 * B0); // Domain boundary (Li2+ velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_Li1 = + 4.0 * vtLi1; // Domain boundary (Li1+ velocity space: parallel velocity direction). + double mu_max_Li1 = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vtLi1, 2.0) / + (2.0 * B0); // Domain boundary (Li1+ velocity space: magnetic moment direction). + double vpar_max_Li2 = + 4.0 * vtLi2; // Domain boundary (Li2+ velocity space: parallel velocity direction). + double mu_max_Li2 = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vtLi2, 2.0) / + (2.0 * B0); // Domain boundary (Li2+ velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 1.0e-7; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct li_react_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -250,14 +266,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -272,14 +289,17 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -287,9 +307,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -297,8 +318,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -312,8 +332,7 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; // Electron isotropic temperature (left). - } - else { + } else { T = 0.5 * Te; // Electron isotropic temperature (right). } @@ -321,15 +340,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -344,10 +363,12 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Electron source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Electron source total number density (left). + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -355,8 +376,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -369,8 +391,7 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Electron source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Electron source isotropic temperature (right). } @@ -378,15 +399,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -401,14 +424,17 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -416,9 +442,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 0.85 * 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -426,8 +453,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -441,8 +467,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Ion isotropic temperature (right). } @@ -450,15 +475,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -473,10 +498,13 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = 0.85 * GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Ion source total number density (left). - } - else { + n = 0.85 * + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Ion source total number density (left). + } else { n = 0.85 * 1.0e-40 * n_src; // Ion source total number density (right). } @@ -484,8 +512,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -498,8 +527,7 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Ion source isotropic temperature (right). } @@ -507,15 +535,17 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalLi1DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1DensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -530,14 +560,17 @@ evalLi1DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -545,9 +578,10 @@ evalLi1DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 0.05 * 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Li1+ ion total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Li1+ ion total number density (left). + } else { n = 0.5 * n_peak; // Li1+ ion total number density (right). } @@ -555,8 +589,7 @@ evalLi1DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalLi1TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1TempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -570,8 +603,7 @@ evalLi1TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Li1+ ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Li1+ ion isotropic temperature (right). } @@ -579,15 +611,15 @@ evalLi1TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalLi1UparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1UparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set Li1+ ion parallel velocity. fout[0] = 0.0; } -void -evalLi1SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1SourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -602,10 +634,13 @@ evalLi1SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = 0.05 * GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Li1+ ion source total number density (left). - } - else { + n = 0.05 * + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Li1+ ion source total number density (left). + } else { n = 0.05 * 1.0e-40 * n_src; // Li1+ ion source total number density (right). } @@ -613,8 +648,9 @@ evalLi1SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalLi1SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1SourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -627,8 +663,7 @@ evalLi1SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Li1+ ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Li1+ ion source isotropic temperature (right). } @@ -636,15 +671,17 @@ evalLi1SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalLi1SourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1SourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set Li1+ ion source parallel velocity. fout[0] = 0.0; } -void -evalLi2DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2DensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -659,14 +696,17 @@ evalLi2DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -674,9 +714,10 @@ evalLi2DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 0.05 * 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Li2+ ion total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Li2+ ion total number density (left). + } else { n = 0.5 * n_peak; // Li2+ ion total number density (right). } @@ -684,8 +725,7 @@ evalLi2DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalLi2TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2TempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -699,8 +739,7 @@ evalLi2TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Li2+ ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Li2+ ion isotropic temperature (right). } @@ -708,15 +747,15 @@ evalLi2TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalLi2UparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2UparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set Li2+ ion parallel velocity. fout[0] = 0.0; } -void -evalLi2SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2SourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -731,10 +770,13 @@ evalLi2SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = 0.05 * GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Li2+ ion source total number density (left). - } - else { + n = 0.05 * + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Li2+ ion source total number density (left). + } else { n = 0.05 * 1.0e-40 * n_src; // Li2+ ion source total number density (right). } @@ -742,8 +784,9 @@ evalLi2SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalLi2SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2SourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -756,8 +799,7 @@ evalLi2SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Li2+ ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Li2+ ion source isotropic temperature (right). } @@ -765,15 +807,15 @@ evalLi2SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalLi2SourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2SourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set Li2+ ion source parallel velocity. fout[0] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; @@ -783,8 +825,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; @@ -794,8 +835,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalElcIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; @@ -805,8 +845,7 @@ evalElcIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalIonElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; @@ -817,7 +856,7 @@ evalIonElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct li_react_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -832,11 +871,12 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; double x = zc[0]; @@ -844,20 +884,21 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0 * R / x; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -868,10 +909,12 @@ main(int argc, char **argv) struct li_react_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct li_react_ctx -{ +struct li_react_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -45,7 +44,7 @@ struct li_react_ctx double R; // Radial coordinate (simple toroidal coordinates). double B0; // Reference magnetic field strength (Tesla). - + double log_lambda_elc; // Electron Coulomb logarithm. double log_lambda_ion; // Ion Coulomb logarithm. double nu_elc; // Electron collision frequency. @@ -90,14 +89,14 @@ struct li_react_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct li_react_ctx -create_ctx(void) +struct li_react_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -132,15 +131,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0_elc / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0_elc / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0_elc / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -164,24 +167,37 @@ create_ctx(void) double Lx = 50.0 * rho_s; // Domain size (configuration space: x-direction). double Ly = 100.0 * rho_s; // Domain size (configuration space: y-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). - double vpar_max_Li1 = 4.0 * vtLi1; // Domain boundary (Li1+ velocity space: parallel velocity direction). - double mu_max_Li1 = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vtLi1, 2.0) / (2.0 * B0); // Domain boundary (Li1+ velocity space: magnetic moment direction). - double vpar_max_Li2 = 4.0 * vtLi2; // Domain boundary (Li2+ velocity space: parallel velocity direction). - double mu_max_Li2 = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vtLi2, 2.0) / (2.0 * B0); // Domain boundary (Li2+ velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_Li1 = + 4.0 * vtLi1; // Domain boundary (Li1+ velocity space: parallel velocity direction). + double mu_max_Li1 = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vtLi1, 2.0) / + (2.0 * B0); // Domain boundary (Li1+ velocity space: magnetic moment direction). + double vpar_max_Li2 = + 4.0 * vtLi2; // Domain boundary (Li2+ velocity space: parallel velocity direction). + double mu_max_Li2 = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vtLi2, 2.0) / + (2.0 * B0); // Domain boundary (Li2+ velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 1.0e-7; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct li_react_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -250,14 +266,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -272,14 +289,17 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -287,9 +307,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -297,8 +318,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -312,8 +332,7 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; // Electron isotropic temperature (left). - } - else { + } else { T = 0.5 * Te; // Electron isotropic temperature (right). } @@ -321,15 +340,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -344,10 +363,12 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Electron source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Electron source total number density (left). + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -355,8 +376,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -369,8 +391,7 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Electron source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Electron source isotropic temperature (right). } @@ -378,15 +399,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -401,14 +424,17 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -416,9 +442,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 0.85 * 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -426,8 +453,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -441,8 +467,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Ion isotropic temperature (right). } @@ -450,15 +475,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -473,10 +498,13 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = 0.85 * GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Ion source total number density (left). - } - else { + n = 0.85 * + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Ion source total number density (left). + } else { n = 0.85 * 1.0e-40 * n_src; // Ion source total number density (right). } @@ -484,8 +512,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -498,8 +527,7 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Ion source isotropic temperature (right). } @@ -507,15 +535,17 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalLi1DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1DensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -530,14 +560,17 @@ evalLi1DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -545,9 +578,10 @@ evalLi1DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 0.05 * 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Li1+ ion total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Li1+ ion total number density (left). + } else { n = 0.5 * n_peak; // Li1+ ion total number density (right). } @@ -555,8 +589,7 @@ evalLi1DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalLi1TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1TempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -570,8 +603,7 @@ evalLi1TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Li1+ ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Li1+ ion isotropic temperature (right). } @@ -579,15 +611,15 @@ evalLi1TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalLi1UparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1UparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set Li1+ ion parallel velocity. fout[0] = 0.0; } -void -evalLi1SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1SourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -602,10 +634,13 @@ evalLi1SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = 0.05 * GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Li1+ ion source total number density (left). - } - else { + n = 0.05 * + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Li1+ ion source total number density (left). + } else { n = 0.05 * 1.0e-40 * n_src; // Li1+ ion source total number density (right). } @@ -613,8 +648,9 @@ evalLi1SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalLi1SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1SourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -627,8 +663,7 @@ evalLi1SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Li1+ ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Li1+ ion source isotropic temperature (right). } @@ -636,15 +671,17 @@ evalLi1SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalLi1SourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi1SourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set Li1+ ion source parallel velocity. fout[0] = 0.0; } -void -evalLi2DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2DensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -659,14 +696,17 @@ evalLi2DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -674,9 +714,10 @@ evalLi2DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 0.05 * 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Li2+ ion total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Li2+ ion total number density (left). + } else { n = 0.5 * n_peak; // Li2+ ion total number density (right). } @@ -684,8 +725,7 @@ evalLi2DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalLi2TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2TempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -699,8 +739,7 @@ evalLi2TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Li2+ ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Li2+ ion isotropic temperature (right). } @@ -708,15 +747,15 @@ evalLi2TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalLi2UparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2UparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set Li2+ ion parallel velocity. fout[0] = 0.0; } -void -evalLi2SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2SourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -731,10 +770,13 @@ evalLi2SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = 0.05 * GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Li2+ ion source total number density (left). - } - else { + n = 0.05 * + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Li2+ ion source total number density (left). + } else { n = 0.05 * 1.0e-40 * n_src; // Li2+ ion source total number density (right). } @@ -742,8 +784,9 @@ evalLi2SourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalLi2SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2SourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct li_react_ctx *app = ctx; double x = xn[0]; @@ -756,8 +799,7 @@ evalLi2SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Li2+ ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Li2+ ion source isotropic temperature (right). } @@ -765,15 +807,15 @@ evalLi2SourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalLi2SourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalLi2SourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set Li2+ ion source parallel velocity. fout[0] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; @@ -783,8 +825,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; @@ -794,8 +835,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalElcIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; @@ -805,8 +845,7 @@ evalElcIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalIonElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; @@ -817,7 +856,7 @@ evalIonElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct li_react_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -832,11 +871,12 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct li_react_ctx *app = ctx; double x = zc[0]; @@ -844,7 +884,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -852,7 +892,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct li_react_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -865,23 +905,24 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_elc * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_elc * (cvpar * cvpar); } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -892,10 +933,12 @@ main(int argc, char **argv) struct li_react_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dR_axis; double delta = app->delta; - return R_axis + r*cos(theta + asin(delta)*sin(theta)); + return R_axis + r * cos(theta + asin(delta) * sin(theta)); } double Z_rtheta(double r, double theta, void *ctx) @@ -82,7 +94,7 @@ double Z_rtheta(double r, double theta, void *ctx) // Z (height) as a function of minor radius r and poloidal angle theta. struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*sin(theta); + return kappa * r * sin(theta); } // Partial derivatives of R(r,theta) and Z(r,theta) @@ -90,31 +102,31 @@ double dRdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return cos(theta + asin(delta)*sin(theta)); + return cos(theta + asin(delta) * sin(theta)); } double dRdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return -r*sin(theta + asin(delta)*sin(theta))*(1.+asin(delta)*cos(theta)); + return -r * sin(theta + asin(delta) * sin(theta)) * (1. + asin(delta) * cos(theta)); } double dZdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*sin(theta); + return kappa * sin(theta); } double dZdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*cos(theta); + return kappa * r * cos(theta); } double Jr(double r, double theta, void *ctx) { - return R_rtheta(r,theta,ctx)*( dRdr(r,theta,ctx) * dZdtheta(r,theta,ctx) - -dRdtheta(r,theta,ctx) * dZdr(r,theta,ctx) ); + return R_rtheta(r, theta, ctx) * (dRdr(r, theta, ctx) * dZdtheta(r, theta, ctx) - + dRdtheta(r, theta, ctx) * dZdr(r, theta, ctx)); } struct integrand_ctx { @@ -126,7 +138,7 @@ double integrand(double t, void *int_ctx) struct integrand_ctx *inctx = int_ctx; double r = inctx->r; struct gk_app_ctx *app = inctx->app_ctx; - return Jr(r,t,app) / pow(R_rtheta(r,t,app),2); + return Jr(r, t, app) / pow(R_rtheta(r, t, app), 2); } double Bphi(double R, void *ctx) @@ -135,7 +147,7 @@ double Bphi(double R, void *ctx) struct gk_app_ctx *app = ctx; double B0 = app->B0; double R0 = app->R0; - return B0*R0/R; + return B0 * R0 / R; } double dPsidr(double r, double theta, void *ctx) @@ -143,24 +155,28 @@ double dPsidr(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2.*M_PI, 7, 1e-10); + integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2. * M_PI, 7, 1e-10); double B0 = app->B0; double R_axis = app->R_axis; double a_mid = app->a_mid; double qSep = app->qSep; double sSep = app->sSep; - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); - return ( Bt*R/(2.*M_PI*qprofile(r,a_mid,qSep,sSep)) )*integral.res; + return (Bt * R / (2. * M_PI * qprofile(r, a_mid, qSep, sSep))) * integral.res; } double alpha(double r, double theta, double phi, void *ctx) { double twrap = theta; - while (twrap < -M_PI) twrap = twrap+2.*M_PI; - while (M_PI < twrap) twrap = twrap-2.*M_PI; + while (twrap < -M_PI) { + twrap = twrap + 2. * M_PI; + } + while (M_PI < twrap) { + twrap = twrap - 2. * M_PI; + } struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; @@ -172,36 +188,37 @@ double alpha(double r, double theta, double phi, void *ctx) integral.res = -integral.res; } - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); - return phi - Bt*R*integral.res/dPsidr(r,theta,ctx); + return phi - Bt * R * integral.res / dPsidr(r, theta, ctx); } double gradr(double r, double theta, void *ctx) { - return (R_rtheta(r,theta,ctx)/Jr(r,theta,ctx))*sqrt(pow(dRdtheta(r,theta,ctx),2) + pow(dZdtheta(r,theta,ctx),2)); + return (R_rtheta(r, theta, ctx) / Jr(r, theta, ctx)) * + sqrt(pow(dRdtheta(r, theta, ctx), 2) + pow(dZdtheta(r, theta, ctx), 2)); } // Electron source profiles. -void density_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Lz = app->Lz; double n_src = app->n_src; double z = xn[0]; - if (fabs(z) < Lz/4.) { + if (fabs(z) < Lz / 4.) { fout[0] = app->n_src; } else { fout[0] = 1e-40; } } -void upar_elc_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_elc_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void temp_elc_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Te_src = app->Te_src; @@ -210,11 +227,11 @@ void temp_elc_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI } // Ion source profiles. -void upar_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_ion_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void temp_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Ti_src = app->Ti_src; @@ -223,35 +240,35 @@ void temp_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI } // Ion initial conditions -void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Lz = app->Lz; double mi = app->mi; double z = xn[0]; - double Ls = Lz/4.; + double Ls = Lz / 4.; double xn0[] = {0.}; double n_src0[1], Te_src0[1]; - density_src(t,xn0,n_src0,ctx); - temp_elc_src(t,xn0,Te_src0,ctx); - double effSrc = n_src0[0]; - double c_ss = sqrt(5./3.*Te_src0[0]/mi); - double nPeak = 89.*sqrt(5.)/3./c_ss*Ls*effSrc/2.; + density_src(t, xn0, n_src0, ctx); + temp_elc_src(t, xn0, Te_src0, ctx); + double effSrc = n_src0[0]; + double c_ss = sqrt(5. / 3. * Te_src0[0] / mi); + double nPeak = 89. * sqrt(5.) / 3. / c_ss * Ls * effSrc / 2.; double perturb = 0.; if (fabs(z) <= Ls) { - fout[0] = nPeak*(1.+sqrt(1.-pow(z/Ls,2)))/2.*(1.+perturb); + fout[0] = nPeak * (1. + sqrt(1. - pow(z / Ls, 2))) / 2. * (1. + perturb); } else { - fout[0] = nPeak/2.*(1.+perturb); + fout[0] = nPeak / 2. * (1. + perturb); } } -void upar_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double z = xn[0]; fout[0] = 0.0; } -void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Ti0 = app->Ti0; @@ -261,13 +278,13 @@ void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f } // Electron initial conditions -void upar_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double z = xn[0]; fout[0] = 0.0; } -void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Te0 = app->Te0; @@ -277,29 +294,29 @@ void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f } // Collision frequencies. -void evalNuElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuElc; } -void evalNuIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuIon; } -void evalNuElcIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuElcIon; } -void evalNuIonElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuIonElc; } // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { struct gk_app_ctx *app = ctx; double r0 = app->r0; @@ -308,20 +325,22 @@ void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) double x = xc[0], y = xc[1], z = xc[2]; - double r = x+r0; + double r = x + r0; // Map to cylindrical (R, Z, phi) coordinates. - double R = R_rtheta(r, z, ctx); - double Z = kappa*r*sin(z); - double phi = q0/r0*y + alpha(r, z, 0, ctx); + double R = R_rtheta(r, z, ctx); + double Z = kappa * r * sin(z); + double phi = q0 / r0 * y + alpha(r, z, 0, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); + double X = R * cos(phi); + double Y = R * sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; @@ -329,27 +348,26 @@ void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *c double r0 = app->r0; double q0 = app->q0; - double r = x+r0; - double Bt = Bphi(R_rtheta(r,z,ctx),ctx); - double Bp = dPsidr(r,z,ctx)/R_rtheta(r,z,ctx)*gradr(r,z,ctx); + double r = x + r0; + double Bt = Bphi(R_rtheta(r, z, ctx), ctx); + double Bp = dPsidr(r, z, ctx) / R_rtheta(r, z, ctx) * gradr(r, z, ctx); - double drdtheta = dRdtheta(r,z,ctx); - double dzdtheta = dZdtheta(r,z,ctx); - double den = sqrt(pow(drdtheta,2) + pow(dzdtheta,2)); - double B_r = Bp*drdtheta/den; - double B_z = Bp*dzdtheta/den; - double phi = q0/r0*y + alpha(r, z, 0, ctx); - double R = R_rtheta(r, z, ctx); + double drdtheta = dRdtheta(r, z, ctx); + double dzdtheta = dZdtheta(r, z, ctx); + double den = sqrt(pow(drdtheta, 2) + pow(dzdtheta, 2)); + double B_r = Bp * drdtheta / den; + double B_z = Bp * dzdtheta / den; + double phi = q0 / r0 * y + alpha(r, z, 0, ctx); + double R = R_rtheta(r, z, ctx); - // xc are computational coords. + // xc are computational coords. // Set Cartesian components of magnetic field. fout[0] = B_r * cos(phi) + Bt * sin(phi); fout[1] = B_r * sin(phi) - Bt * cos(phi); fout[2] = B_z; } -struct gk_app_ctx -create_ctx(void) +struct gk_app_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -360,21 +378,22 @@ create_ctx(void) double qe = -eV; // electron charge // Geometry and magnetic field. - double R_axis = 0.4; // Magnetic axis major radius [m]. - double B_axis = 0.224374548; // Magnetic field at the magnetic axis [T]. - double R_LCFSmid = 0.5948; // Major radius of the LCFS at the outboard midplane [m]. - double R0 = R_LCFSmid+0.025; // Major radius of the simulation box [m]. - double a_mid = R_LCFSmid-R_axis; // Minor radius at outboard midplane [m]. - double r0 = R0-R_axis; // Minor radius of the simulation box [m]. - double B0 = B_axis*(R_axis/R0); // Magnetic field magnitude in the simulation box [T]. - double qSep = 3.69546081; // Safety factor at the separatrix. - double sSep = 2.27976219; // Magnetic shear at the separatrix. - double kappa = 1.57; // Elongation (=1 for no elongation). - double delta = 0.6; // Triangularity (=0 for no triangularity). - double Lz = 0.62*2.*M_PI; // Domain size along magnetic field. - - double q0 = qprofile(0.+r0,a_mid,qSep,sSep); // Magnetic safety factor in the center of domain. - double epsilon0 = r0/R0; // Inverse aspect ratio in the center of the domain. + double R_axis = 0.4; // Magnetic axis major radius [m]. + double B_axis = 0.224374548; // Magnetic field at the magnetic axis [T]. + double R_LCFSmid = 0.5948; // Major radius of the LCFS at the outboard midplane [m]. + double R0 = R_LCFSmid + 0.025; // Major radius of the simulation box [m]. + double a_mid = R_LCFSmid - R_axis; // Minor radius at outboard midplane [m]. + double r0 = R0 - R_axis; // Minor radius of the simulation box [m]. + double B0 = B_axis * (R_axis / R0); // Magnetic field magnitude in the simulation box [T]. + double qSep = 3.69546081; // Safety factor at the separatrix. + double sSep = 2.27976219; // Magnetic shear at the separatrix. + double kappa = 1.57; // Elongation (=1 for no elongation). + double delta = 0.6; // Triangularity (=0 for no triangularity). + double Lz = 0.62 * 2. * M_PI; // Domain size along magnetic field. + + double q0 = + qprofile(0. + r0, a_mid, qSep, sSep); // Magnetic safety factor in the center of domain. + double epsilon0 = r0 / R0; // Inverse aspect ratio in the center of the domain. // Perpendicular wavenumber (k_perp) times ion sound gyroradius (rho_s). double kperpRhos = 0.15; @@ -382,33 +401,33 @@ create_ctx(void) // Plasma parameters. Chosen based on the value of a cubic sline // between the last TS data inside the LCFS and the probe data in // in the far SOL, near R=0.475 m. - double mi = mp; // Hydrogen ions. - double Te0 = 178*eV; - double Ti0 = 70*eV; - double n0 = 1.78e18; // [1/m^3] + double mi = mp; // Hydrogen ions. + double Te0 = 178 * eV; + double Ti0 = 70 * eV; + double n0 = 1.78e18; // [1/m^3] double nuFrac = 1.0; // Electron-electron collision freq. - double logLambdaElc = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuElc = nuFrac * logLambdaElc * pow(eV, 4) * n0 / - (6*sqrt(2.) * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(me) * pow(Te0,3./2.)); + (6 * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(me) * pow(Te0, 3. / 2.)); // Ion-ion collision freq. - double logLambdaIon = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuIon = nuFrac * logLambdaIon * pow(eV, 4) * n0 / - (12 * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(mi) * pow(Ti0,3./2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(mi) * pow(Ti0, 3. / 2.)); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // Source parameters double n_src = 1.95e22; - double Te_src = 410*eV; - double Ti_src = 40*eV; + double Te_src = 410 * eV; + double Ti_src = 40 * eV; // Grid parameters int Nz = 16; @@ -416,15 +435,16 @@ create_ctx(void) int Nmu = 8; int poly_order = 1; - double vpar_max_elc = 4.*vte; - double mu_max_elc = me*pow(1.5*4*vte,2)/(2*B0); - double vpar_max_ion = 4.*vti; - double mu_max_ion = mi*pow(1.5*4*vti,2)/(2*B0); + double vpar_max_elc = 4. * vte; + double mu_max_elc = me * pow(1.5 * 4 * vte, 2) / (2 * B0); + double vpar_max_ion = 4. * vti; + double mu_max_ion = mi * pow(1.5 * 4 * vti, 2) / (2 * B0); double t_end = 6.0e-8; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -432,54 +452,67 @@ create_ctx(void) .cdim = cdim, .vdim = vdim, .R_axis = R_axis, - .R0 = R0 , - .a_mid = a_mid , - .r0 = r0 , - .B0 = B0 , - .qSep = qSep , - .sSep = sSep , - .kappa = kappa , - .delta = delta , - .q0 = q0 , - .Lz = Lz , - .z_min = -Lz/2., .z_max = Lz/2., - - .kperp = kperpRhos/rho_s, - - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - + .R0 = R0, + .a_mid = a_mid, + .r0 = r0, + .B0 = B0, + .qSep = qSep, + .sSep = sSep, + .kappa = kappa, + .delta = delta, + .q0 = q0, + .Lz = Lz, + .z_min = -Lz / 2., + .z_max = Lz / 2., + + .kperp = kperpRhos / rho_s, + + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + .nuFrac = nuFrac, - .nuElc = nuElc, .nuIon = nuIon, - .nuElcIon = nuElcIon, .nuIonElc = nuIonElc, - - .n_src = n_src, .Te_src = Te_src, .Ti_src = Ti_src, - + .nuElc = nuElc, + .nuIon = nuIon, + .nuElcIon = nuElcIon, + .nuIonElc = nuIonElc, + + .n_src = n_src, + .Te_src = Te_src, + .Ti_src = Ti_src, + .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nz, Nvpar, Nmu}, .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -490,10 +523,12 @@ int main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dR_axis; double delta = app->delta; - return R_axis + r*cos(theta + asin(delta)*sin(theta)); + return R_axis + r * cos(theta + asin(delta) * sin(theta)); } double Z_rtheta(double r, double theta, void *ctx) @@ -77,7 +86,7 @@ double Z_rtheta(double r, double theta, void *ctx) // Z (height) as a function of minor radius r and poloidal angle theta. struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*sin(theta); + return kappa * r * sin(theta); } // Partial derivatives of R(r,theta) and Z(r,theta) @@ -85,31 +94,31 @@ double dRdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return cos(theta + asin(delta)*sin(theta)); + return cos(theta + asin(delta) * sin(theta)); } double dRdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return -r*sin(theta + asin(delta)*sin(theta))*(1.+asin(delta)*cos(theta)); + return -r * sin(theta + asin(delta) * sin(theta)) * (1. + asin(delta) * cos(theta)); } double dZdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*sin(theta); + return kappa * sin(theta); } double dZdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*cos(theta); + return kappa * r * cos(theta); } double Jr(double r, double theta, void *ctx) { - return R_rtheta(r,theta,ctx)*( dRdr(r,theta,ctx) * dZdtheta(r,theta,ctx) - -dRdtheta(r,theta,ctx) * dZdr(r,theta,ctx) ); + return R_rtheta(r, theta, ctx) * (dRdr(r, theta, ctx) * dZdtheta(r, theta, ctx) - + dRdtheta(r, theta, ctx) * dZdr(r, theta, ctx)); } struct integrand_ctx { @@ -121,14 +130,14 @@ double integrand(double t, void *int_ctx) struct integrand_ctx *inctx = int_ctx; double r = inctx->r; struct gk_app_ctx *app = inctx->app_ctx; - return Jr(r,t,app) / pow(R_rtheta(r,t,app),2); + return Jr(r, t, app) / pow(R_rtheta(r, t, app), 2); } double dPsidr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2.*M_PI, 7, 1e-10); + integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2. * M_PI, 7, 1e-10); double B0 = app->B0; double R_axis = app->R_axis; @@ -136,14 +145,18 @@ double dPsidr(double r, double theta, void *ctx) double qSep = app->qSep; double sSep = app->sSep; - return ( B0*R_axis/(2.*M_PI*qprofile(r,a_mid,qSep,sSep)) )*integral.res; + return (B0 * R_axis / (2. * M_PI * qprofile(r, a_mid, qSep, sSep))) * integral.res; } double alpha(double r, double theta, double phi, void *ctx) { double twrap = theta; - while (twrap < -M_PI) twrap = twrap+2.*M_PI; - while (M_PI < twrap) twrap = twrap-2.*M_PI; + while (twrap < -M_PI) { + twrap = twrap + 2. * M_PI; + } + while (M_PI < twrap) { + twrap = twrap - 2. * M_PI; + } struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; @@ -158,7 +171,7 @@ double alpha(double r, double theta, double phi, void *ctx) double B0 = app->B0; double R_axis = app->R_axis; - return phi - B0*R_axis*integral.res/dPsidr(r,theta,ctx); + return phi - B0 * R_axis * integral.res / dPsidr(r, theta, ctx); } double Bphi(double R, void *ctx) @@ -167,32 +180,33 @@ double Bphi(double R, void *ctx) struct gk_app_ctx *app = ctx; double B0 = app->B0; double R0 = app->R0; - return B0*R0/R; + return B0 * R0 / R; } double gradr(double r, double theta, void *ctx) { - return (R_rtheta(r,theta,ctx)/Jr(r,theta,ctx))*sqrt(pow(dRdtheta(r,theta,ctx),2) + pow(dZdtheta(r,theta,ctx),2)); + return (R_rtheta(r, theta, ctx) / Jr(r, theta, ctx)) * + sqrt(pow(dRdtheta(r, theta, ctx), 2) + pow(dZdtheta(r, theta, ctx), 2)); } // Ion source profiles. -void density_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Lz = app->Lz; double n_src = app->n_src; double z = xn[0]; - if (fabs(z) < Lz/4.) { + if (fabs(z) < Lz / 4.) { fout[0] = app->n_src; } else { fout[0] = 1e-40; } } -void upar_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_ion_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void temp_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Ti_src = app->Ti_src; @@ -201,36 +215,36 @@ void temp_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI } // Ion initial conditions -void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Lz = app->Lz; double mi = app->mi; double z = xn[0]; - double Ls = Lz/4.; + double Ls = Lz / 4.; double xn0[] = {0.}; double n_src0[1]; - density_src(t,xn0,n_src0,ctx); - double effSrc = n_src0[0]; + density_src(t, xn0, n_src0, ctx); + double effSrc = n_src0[0]; double eV = GKYL_ELEMENTARY_CHARGE; - double Te_src = 410*eV; - double c_ss = sqrt(5./3.*Te_src/mi); - double nPeak = 89.*sqrt(5.)/3./c_ss*Ls*effSrc/2.; + double Te_src = 410 * eV; + double c_ss = sqrt(5. / 3. * Te_src / mi); + double nPeak = 89. * sqrt(5.) / 3. / c_ss * Ls * effSrc / 2.; double perturb = 0.; if (fabs(z) <= Ls) { - fout[0] = nPeak*(1.+sqrt(1.-pow(z/Ls,2)))/2.*(1.+perturb); + fout[0] = nPeak * (1. + sqrt(1. - pow(z / Ls, 2))) / 2. * (1. + perturb); } else { - fout[0] = nPeak/2.*(1.+perturb); + fout[0] = nPeak / 2. * (1. + perturb); } } -void upar_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double z = xn[0]; fout[0] = 0.0; } -void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Ti0 = app->Ti0; @@ -240,14 +254,14 @@ void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f } // Collision frequencies. -void evalNuIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuIon; } // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { struct gk_app_ctx *app = ctx; double r0 = app->r0; @@ -256,47 +270,48 @@ void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) double x = xc[0], y = xc[1], z = xc[2]; - double r = x+r0; + double r = x + r0; // Map to cylindrical (R, Z, phi) coordinates. - double R = R_rtheta(r, z, ctx); - double Z = kappa*r*sin(z); - double phi = -q0/r0*y - alpha(r, z, 0, ctx); + double R = R_rtheta(r, z, ctx); + double Z = kappa * r * sin(z); + double phi = -q0 / r0 * y - alpha(r, z, 0, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); + double X = R * cos(phi); + double Y = R * sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double r0 = app->r0; double q0 = app->q0; double x = 0., y = 0., z = xc[2]; - double r = x+r0; - double Bt = Bphi(R_rtheta(r,z,ctx),ctx); - double Bp = dPsidr(r,z,ctx)/R_rtheta(r,z,ctx)*gradr(r,z,ctx); - - double drdtheta = dRdtheta(r,z,ctx); - double dzdtheta = dZdtheta(r,z,ctx); - double den = sqrt(pow(drdtheta,2) + pow(dzdtheta,2)); - double B_r = Bp*drdtheta/den; - double B_z = Bp*dzdtheta/den; - double phi = -q0/r0*y - alpha(r, z, 0, ctx); - double R = R_rtheta(r, z, ctx); - - // xc are computational coords. + double r = x + r0; + double Bt = Bphi(R_rtheta(r, z, ctx), ctx); + double Bp = dPsidr(r, z, ctx) / R_rtheta(r, z, ctx) * gradr(r, z, ctx); + + double drdtheta = dRdtheta(r, z, ctx); + double dzdtheta = dZdtheta(r, z, ctx); + double den = sqrt(pow(drdtheta, 2) + pow(dzdtheta, 2)); + double B_r = Bp * drdtheta / den; + double B_z = Bp * dzdtheta / den; + double phi = -q0 / r0 * y - alpha(r, z, 0, ctx); + double R = R_rtheta(r, z, ctx); + + // xc are computational coords. // Set Cartesian components of magnetic field. fout[0] = B_r * cos(phi) - Bt * sin(phi); fout[1] = B_r * sin(phi) + Bt * cos(phi); fout[2] = B_z; } -struct gk_app_ctx -create_ctx(void) +struct gk_app_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -307,45 +322,46 @@ create_ctx(void) double qe = -eV; // electron charge // Geometry and magnetic field. - double R_axis = 0.4; // Magnetic axis major radius [m]. - double B_axis = 0.224374548; // Magnetic field at the magnetic axis [T]. - double R_LCFSmid = 0.5948; // Major radius of the LCFS at the outboard midplane [m]. - double R0 = R_LCFSmid+0.025; // Major radius of the simulation box [m]. - double a_mid = R_LCFSmid-R_axis; // Minor radius at outboard midplane [m]. - double r0 = R0-R_axis; // Minor radius of the simulation box [m]. - double B0 = B_axis*(R_axis/R0); // Magnetic field magnitude in the simulation box [T]. - double qSep = 3.69546081; // Safety factor at the separatrix. - double sSep = 2.27976219; // Magnetic shear at the separatrix. - double kappa = 1.57; // Elongation (=1 for no elongation). - double delta = 0.6; // Triangularity (=0 for no triangularity). - double Lz = 0.62*2.*M_PI; // Domain size along magnetic field. - - double q0 = qprofile(0.+r0,a_mid,qSep,sSep); // Magnetic safety factor in the center of domain. - double epsilon0 = r0/R0; // Inverse aspect ratio in the center of the domain. + double R_axis = 0.4; // Magnetic axis major radius [m]. + double B_axis = 0.224374548; // Magnetic field at the magnetic axis [T]. + double R_LCFSmid = 0.5948; // Major radius of the LCFS at the outboard midplane [m]. + double R0 = R_LCFSmid + 0.025; // Major radius of the simulation box [m]. + double a_mid = R_LCFSmid - R_axis; // Minor radius at outboard midplane [m]. + double r0 = R0 - R_axis; // Minor radius of the simulation box [m]. + double B0 = B_axis * (R_axis / R0); // Magnetic field magnitude in the simulation box [T]. + double qSep = 3.69546081; // Safety factor at the separatrix. + double sSep = 2.27976219; // Magnetic shear at the separatrix. + double kappa = 1.57; // Elongation (=1 for no elongation). + double delta = 0.6; // Triangularity (=0 for no triangularity). + double Lz = 0.62 * 2. * M_PI; // Domain size along magnetic field. + + double q0 = + qprofile(0. + r0, a_mid, qSep, sSep); // Magnetic safety factor in the center of domain. + double epsilon0 = r0 / R0; // Inverse aspect ratio in the center of the domain. // Plasma parameters. Chosen based on the value of a cubic sline // between the last TS data inside the LCFS and the probe data in // in the far SOL, near R=0.475 m. - double mi = mp; // Hydrogen ions. - double Te0 = 178*eV; - double Ti0 = 70*eV; - double n0 = 1.78e18; // [1/m^3] + double mi = mp; // Hydrogen ions. + double Te0 = 178 * eV; + double Ti0 = 70 * eV; + double n0 = 1.78e18; // [1/m^3] double nuFrac = 1.0; // Ion-ion collision freq. - double logLambdaIon = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuIon = nuFrac * logLambdaIon * pow(eV, 4) * n0 / - (12 * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(mi) * pow(Ti0,3./2.)); + (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(mi) * pow(Ti0, 3. / 2.)); - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // Source parameters double n_src = 1.95e22; - double Ti_src = 40*eV; + double Ti_src = 40 * eV; // Grid parameters int Nz = 64; @@ -353,13 +369,14 @@ create_ctx(void) int Nmu = 45; int poly_order = 1; - double vpar_max_ion = 4.*vti; - double mu_max_ion = mi*pow(1.5*4*vti,2)/(2*B0); + double vpar_max_ion = 4. * vti; + double mu_max_ion = mi * pow(1.5 * 4 * vti, 2) / (2 * B0); double t_end = 8.0e-6; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -367,49 +384,59 @@ create_ctx(void) .cdim = cdim, .vdim = vdim, .R_axis = R_axis, - .R0 = R0 , - .a_mid = a_mid , - .r0 = r0 , - .B0 = B0 , - .qSep = qSep , - .sSep = sSep , - .kappa = kappa , - .delta = delta , - .q0 = q0 , - .Lz = Lz , - .z_min = -Lz/2., .z_max = Lz/2., - - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - - .nuFrac = nuFrac, .nuIon = nuIon, - - .n_src = n_src, .Ti_src = Ti_src, - + .R0 = R0, + .a_mid = a_mid, + .r0 = r0, + .B0 = B0, + .qSep = qSep, + .sSep = sSep, + .kappa = kappa, + .delta = delta, + .q0 = q0, + .Lz = Lz, + .z_min = -Lz / 2., + .z_max = Lz / 2., + + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + + .nuFrac = nuFrac, + .nuIon = nuIon, + + .n_src = n_src, + .Ti_src = Ti_src, + .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nz, Nvpar, Nmu}, .poly_order = poly_order, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -420,10 +447,12 @@ int main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dLz; @@ -76,17 +91,17 @@ void density_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRIC double x = xn[0]; double z = xn[1]; - if ( app->psi_max - x < app->Lx_core/6.0 ) { + if (app->psi_max - x < app->Lx_core / 6.0) { fout[0] = app->n_src; } else { - fout[0] = app->n_src*1.0e-5; + fout[0] = app->n_src * 1.0e-5; } } -void upar_elc_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_elc_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void temp_elc_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Te_src = app->Te_src; @@ -94,11 +109,11 @@ void temp_elc_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI } // Ion source profiles. -void upar_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_ion_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void temp_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Ti_src = app->Ti_src; @@ -106,17 +121,17 @@ void temp_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI } // Ion initial conditions -void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->n0; } -void upar_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = 0.0; } -void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Ti0 = app->Ti0; @@ -124,12 +139,12 @@ void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f } // Electron initial conditions -void upar_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = 0.0; } -void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Te0 = app->Te0; @@ -137,37 +152,37 @@ void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f } // Collision frequencies. -void evalNuElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuElc; } -void evalNuIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuIon; } -void evalNuElcIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuElcIon; } -void evalNuIonElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuIonElc; } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; fout[0] = 0.3; // Diffusivity [m^2/s]. } -struct gk_app_ctx -create_ctx(void) +struct gk_app_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -178,7 +193,7 @@ create_ctx(void) double qe = -eV; // electron charge // Geometry and magnetic field. - double Lz = 2.0*(M_PI-1e-14); // Domain size along magnetic field. + double Lz = 2.0 * (M_PI - 1e-14); // Domain size along magnetic field. double B0 = 0.24; double psi_LCFS = -0.0054760172700000; // psi at LCFS. Taken from efit double psi_min = psi_LCFS - 0.0004; // inner flux surface of domain @@ -189,33 +204,33 @@ create_ctx(void) // Plasma parameters. Chosen based on the value of a cubic sline // between the last TS data inside the LCFS and the probe data in // in the far SOL, near R=0.475 m. - double mi = mp; // Hydrogen ions. - double Te0 = 178*eV; - double Ti0 = 70*eV; - double n0 = 1.78e18; // [1/m^3] + double mi = mp; // Hydrogen ions. + double Te0 = 178 * eV; + double Ti0 = 70 * eV; + double n0 = 1.78e18; // [1/m^3] double nuFrac = 1.0; // Electron-electron collision freq. - double logLambdaElc = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuElc = nuFrac * logLambdaElc * pow(eV, 4) * n0 / - (6*sqrt(2.) * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(me) * pow(Te0,3./2.)); + (6 * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(me) * pow(Te0, 3. / 2.)); // Ion-ion collision freq. - double logLambdaIon = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuIon = nuFrac * logLambdaIon * pow(eV, 4) * n0 / - (12 * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(mi) * pow(Ti0,3./2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(mi) * pow(Ti0, 3. / 2.)); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // Source parameters double n_src = 1.95e22; - double Te_src = 410*eV; - double Ti_src = 40*eV; + double Te_src = 410 * eV; + double Ti_src = 40 * eV; // Grid parameters int Nx = 8; @@ -224,62 +239,77 @@ create_ctx(void) int Nmu = 8; int poly_order = 1; - double vpar_max_elc = 4.*vte; - double mu_max_elc = me*pow(1.5*4*vte,2)/(2*B0); - double vpar_max_ion = 4.*vti; - double mu_max_ion = mi*pow(1.5*4*vti,2)/(2*B0); + double vpar_max_elc = 4. * vte; + double mu_max_elc = me * pow(1.5 * 4 * vte, 2) / (2 * B0); + double vpar_max_ion = 4. * vti; + double mu_max_ion = mi * pow(1.5 * 4 * vti, 2) / (2 * B0); double t_end = 6.0e-8; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_app_ctx ctx = { .cdim = cdim, .vdim = vdim, - .Lz = Lz , - .z_min = -Lz/2., .z_max = Lz/2., - .psi_min = psi_min, .psi_max = psi_max, + .Lz = Lz, + .z_min = -Lz / 2., + .z_max = Lz / 2., + .psi_min = psi_min, + .psi_max = psi_max, .psi_LCFS = psi_LCFS, .Lx = Lx, .Lx_core = Lx_core, - - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - + + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + .nuFrac = nuFrac, - .nuElc = nuElc, .nuIon = nuIon, - .nuElcIon = nuElcIon, .nuIonElc = nuIonElc, - - .n_src = n_src, .Te_src = Te_src, .Ti_src = Ti_src, - + .nuElc = nuElc, + .nuIon = nuIon, + .nuElcIon = nuElcIon, + .nuIonElc = nuIonElc, + + .n_src = n_src, + .Te_src = Te_src, + .Ti_src = Ti_src, + .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -290,10 +320,12 @@ int main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dLz; @@ -74,17 +89,17 @@ void density_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRIC double x = xn[0]; double z = xn[2]; - if ( app->psi_max - x < app->Lx_core/6.0 ) { + if (app->psi_max - x < app->Lx_core / 6.0) { fout[0] = app->n_src; } else { - fout[0] = app->n_src*1.0e-5; + fout[0] = app->n_src * 1.0e-5; } } -void upar_elc_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_elc_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void temp_elc_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Te_src = app->Te_src; @@ -92,11 +107,11 @@ void temp_elc_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI } // Ion source profiles. -void upar_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_ion_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void temp_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Ti_src = app->Ti_src; @@ -104,17 +119,17 @@ void temp_ion_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI } // Ion initial conditions -void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->n0; } -void upar_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = 0.0; } -void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Ti0 = app->Ti0; @@ -122,12 +137,12 @@ void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f } // Electron initial conditions -void upar_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = 0.0; } -void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double Te0 = app->Te0; @@ -135,29 +150,28 @@ void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f } // Collision frequencies. -void evalNuElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuElc; } -void evalNuIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuIon; } -void evalNuElcIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuElcIon; } -void evalNuIonElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuIonElc; } -struct gk_app_ctx -create_ctx(void) +struct gk_app_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -168,8 +182,8 @@ create_ctx(void) double qe = -eV; // electron charge // Geometry and magnetic field. - double Lz = 2.0*(M_PI-1e-14); // Domain size along magnetic field. - double Ly = 2.0*M_PI/8.0; + double Lz = 2.0 * (M_PI - 1e-14); // Domain size along magnetic field. + double Ly = 2.0 * M_PI / 8.0; double B0 = 0.24; double psi_LCFS = 0.003172759514520552; // psi at LCFS. Taken from efit double psi_min = psi_LCFS - 0.0004; // inner flux surface of domain @@ -180,33 +194,33 @@ create_ctx(void) // Plasma parameters. Chosen based on the value of a cubic sline // between the last TS data inside the LCFS and the probe data in // in the far SOL, near R=0.475 m. - double mi = mp; // Hydrogen ions. - double Te0 = 178*eV; - double Ti0 = 70*eV; - double n0 = 1.78e18; // [1/m^3] + double mi = mp; // Hydrogen ions. + double Te0 = 178 * eV; + double Ti0 = 70 * eV; + double n0 = 1.78e18; // [1/m^3] double nuFrac = 1.0; // Electron-electron collision freq. - double logLambdaElc = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuElc = nuFrac * logLambdaElc * pow(eV, 4) * n0 / - (6*sqrt(2.) * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(me) * pow(Te0,3./2.)); + (6 * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(me) * pow(Te0, 3. / 2.)); // Ion-ion collision freq. - double logLambdaIon = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuIon = nuFrac * logLambdaIon * pow(eV, 4) * n0 / - (12 * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(mi) * pow(Ti0,3./2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(mi) * pow(Ti0, 3. / 2.)); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // Source parameters double n_src = 1.95e22; - double Te_src = 410*eV; - double Ti_src = 40*eV; + double Te_src = 410 * eV; + double Ti_src = 40 * eV; // Grid parameters int Nx = 4; @@ -216,64 +230,79 @@ create_ctx(void) int Nmu = 4; int poly_order = 1; - double vpar_max_elc = 4.*vte; - double mu_max_elc = me*pow(1.5*4*vte,2)/(2*B0); - double vpar_max_ion = 4.*vti; - double mu_max_ion = mi*pow(1.5*4*vti,2)/(2*B0); + double vpar_max_elc = 4. * vte; + double mu_max_elc = me * pow(1.5 * 4 * vte, 2) / (2 * B0); + double vpar_max_ion = 4. * vti; + double mu_max_ion = mi * pow(1.5 * 4 * vti, 2) / (2 * B0); double t_end = 6.0e-8; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_app_ctx ctx = { .cdim = cdim, .vdim = vdim, - .Lz = Lz , - .Ly = Ly , - .z_min = -Lz/2., .z_max = Lz/2., - .psi_min = psi_min, .psi_max = psi_max, + .Lz = Lz, + .Ly = Ly, + .z_min = -Lz / 2., + .z_max = Lz / 2., + .psi_min = psi_min, + .psi_max = psi_max, .psi_LCFS = psi_LCFS, .Lx = Lx, .Lx_core = Lx_core, - - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - + + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + .nuFrac = nuFrac, - .nuElc = nuElc, .nuIon = nuIon, - .nuElcIon = nuElcIon, .nuIonElc = nuIonElc, - - .n_src = n_src, .Te_src = Te_src, .Ti_src = Ti_src, - + .nuElc = nuElc, + .nuIon = nuIon, + .nuElcIon = nuElcIon, + .nuIonElc = nuIonElc, + + .n_src = n_src, + .Te_src = Te_src, + .Ti_src = Ti_src, + .Nz = Nz, .Ny = Ny, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Ny, Nz, Nvpar, Nmu}, .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -284,10 +313,12 @@ int main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dTe; fout[0] = T; } -void -eval_temp_ar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_ar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mdpx_ctx *app = ctx; double T = app->TAr; fout[0] = T; } -void -evalNuElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mdpx_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mdpx_ctx *app = ctx; fout[0] = app->nuIon; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mdpx_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -143,67 +139,75 @@ double plasma_freq(double n, double m) { double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - return sqrt(n*eV*eV/m/eps0); + return sqrt(n * eV * eV / m / eps0); } -double coulomb_logarithm(double ns, double nr, double ms, double mr, double Ts, double Tr, double qs, double qr) +double coulomb_logarithm( + double ns, double nr, double ms, double mr, double Ts, double Tr, double qs, double qr +) { - double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double hbar = GKYL_PLANCKS_CONSTANT_H/2/M_PI; - double vts = sqrt(Ts/ms); - double vtr = sqrt(Tr/mr); - double wps = plasma_freq(ns,ms); - double wpr = plasma_freq(nr,mr); - double inner1 = wps*wps/(Ts/ms + 3*Ts/ms) + wpr*wpr/(Tr/mr + 3*Ts/ms); - double u = 3*(vts*vts + vtr*vtr); - double msr = ms*mr/(ms+mr); - double inner2 = fmax(fabs(qs*qr)/(4*M_PI*eps0*msr*u*u), hbar/(2*sqrt(eV)*msr*u)); - double inner = (1/inner1)*(1/inner2/inner2) + 1; - return 0.5*log(inner); + double hbar = GKYL_PLANCKS_CONSTANT_H / 2 / M_PI; + double vts = sqrt(Ts / ms); + double vtr = sqrt(Tr / mr); + double wps = plasma_freq(ns, ms); + double wpr = plasma_freq(nr, mr); + double inner1 = wps * wps / (Ts / ms + 3 * Ts / ms) + wpr * wpr / (Tr / mr + 3 * Ts / ms); + double u = 3 * (vts * vts + vtr * vtr); + double msr = ms * mr / (ms + mr); + double inner2 = + fmax(fabs(qs * qr) / (4 * M_PI * eps0 * msr * u * u), hbar / (2 * sqrt(eV) * msr * u)); + double inner = (1 / inner1) * (1 / inner2 / inner2) + 1; + return 0.5 * log(inner); } -double norm_nu_func(double nuFrac, double ns, double nr, double ms, double mr, double qs, double qr, double Ts, double Tr) +double norm_nu_func( + double nuFrac, double ns, double nr, double ms, double mr, double qs, double qr, double Ts, + double Tr +) { double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double clog = coulomb_logarithm(ns,nr,ms,mr,Ts, Tr, qs, qr); - double vts = sqrt(Ts/ms); - double vtr = sqrt(Tr/mr); - return nuFrac/ms*(1/mr+1/ms)*qs*qs*qr*qr*clog/(6*pow(M_PI,1.5)*eps0*eps0); + double clog = coulomb_logarithm(ns, nr, ms, mr, Ts, Tr, qs, qr); + double vts = sqrt(Ts / ms); + double vtr = sqrt(Tr / mr); + return nuFrac / ms * (1 / mr + 1 / ms) * qs * qs * qr * qr * clog / + (6 * pow(M_PI, 1.5) * eps0 * eps0); } -struct gk_mdpx_ctx -create_ctx(void) +struct gk_mdpx_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mAr = 39.95*GKYL_PROTON_MASS; // Ar ion mass + double mAr = 39.95 * GKYL_PROTON_MASS; // Ar ion mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge - double Te = 4.0*eV; - double TAr = eV/40.0; + double Te = 4.0 * eV; + double TAr = eV / 40.0; double B0 = 1.0; // Magnetic field magnitude in Tesla double n0 = 1.0e14; // Particle density in 1/m^3 - + // Derived parameters. - double vtElc = sqrt(Te/me); - double vtAr = sqrt(TAr/mAr); + double vtElc = sqrt(Te / me); + double vtAr = sqrt(TAr / mAr); double r_prof = 0.16; // Initial conditions radial extent. double L_prof = 0.04; // Initial conditions length. // Collision parameters. double nuFrac = 1.0; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nuFrac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); // collision freq + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nuFrac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te)) + ); // collision freq - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(TAr/eV); - double nuIon = nuFrac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mAr)*(TAr*sqrt(TAr))); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(TAr / eV); + double nuIon = nuFrac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mAr) * (TAr * sqrt(TAr))); // Simulation parameters. int Nx = 10; // Cell count (configuration space: x-direction). @@ -215,35 +219,36 @@ create_ctx(void) double Ly = 0.5; // Ly box size in meters double Lz = 0.1; // Lz box size in meters - double vpar_max_elc = 4.0*vtElc; - double mu_max_elc = 18*me*vtElc*vtElc/(2.0*B0); + double vpar_max_elc = 4.0 * vtElc; + double mu_max_elc = 18 * me * vtElc * vtElc / (2.0 * B0); - double vpar_max_Ar = 4.0*vtAr; - double mu_max_Ar = 18.*mAr*vtAr*vtAr/(2.0*B0); + double vpar_max_Ar = 4.0 * vtAr; + double mu_max_Ar = 18. * mAr * vtAr * vtAr / (2.0 * B0); - double t_end = 4.0e-10; + double t_end = 4.0e-10; double num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_mdpx_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massAr = mAr, - .Te = Te, - .TAr = TAr, + .Te = Te, + .TAr = TAr, .vtElc = vtElc, .vtAr = vtAr, - .nuElc = nuElc, - .nuIon = nuIon, + .nuElc = nuElc, + .nuIon = nuIon, .nuFrac = nuFrac, - .B0 = B0, - .n0 = n0, + .B0 = B0, + .n0 = n0, .r_prof = r_prof, .L_prof = L_prof, .Nx = Nx, @@ -252,30 +257,31 @@ create_ctx(void) .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Ny, Nz, Nvpar, Nmu}, - .Lx = Lx, - .Ly = Ly, - .Lz = Lz, - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_Ar = vpar_max_Ar, - .mu_max_Ar = mu_max_Ar, - .t_end = t_end, - .num_frames = num_frames, + .Lx = Lx, + .Ly = Ly, + .Lz = Lz, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_Ar = vpar_max_Ar, + .mu_max_Ar = mu_max_Ar, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -286,10 +292,12 @@ main(int argc, char **argv) struct gk_mdpx_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters @@ -90,14 +89,14 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -double -psi_RZ(double RIn, double ZIn, void *ctx) +double psi_RZ(double RIn, double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; double mcB = app->mcB; @@ -109,35 +108,34 @@ psi_RZ(double RIn, double ZIn, void *ctx) return psi; } -double -R_psiZ(double psiIn, double ZIn, void *ctx) +double R_psiZ(double psiIn, double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; - double Rout = sqrt(2.0 * psiIn / (app->mcB * - (1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn - app->Z_m) / app->gamma, 2.))) + - 1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn + app->Z_m) / app->gamma, 2.)))))); + double Rout = sqrt( + 2.0 * psiIn / + (app->mcB * (1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn - app->Z_m) / app->gamma, 2.))) + + 1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn + app->Z_m) / app->gamma, 2.))))) + ); return Rout; } -void -Bfield_psiZ(double psiIn, double ZIn, void *ctx, double *BRad, double *BZ, double *Bmag) +void Bfield_psiZ(double psiIn, double ZIn, void *ctx, double *BRad, double *BZ, double *Bmag) { struct gk_mirror_ctx *app = ctx; double Rcoord = R_psiZ(psiIn, ZIn, ctx); double mcB = app->mcB; double gamma = app->gamma; double Z_m = app->Z_m; - *BRad = -(1.0 / 2.0) * Rcoord * mcB * - (-2.0 * (ZIn - Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn - Z_m) / gamma, 2.), 2.))) - - 2.0 * (ZIn + Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn + Z_m) / gamma, 2.), 2.)))); - *BZ = mcB * - (1.0 / (M_PI * gamma * (1.0 + pow((ZIn - Z_m) / gamma, 2.))) + - 1.0 / (M_PI * gamma * (1.0 + pow((ZIn + Z_m) / gamma, 2.)))); + *BRad = + -(1.0 / 2.0) * Rcoord * mcB * + (-2.0 * (ZIn - Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn - Z_m) / gamma, 2.), 2.))) - + 2.0 * (ZIn + Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn + Z_m) / gamma, 2.), 2.)))); + *BZ = mcB * (1.0 / (M_PI * gamma * (1.0 + pow((ZIn - Z_m) / gamma, 2.))) + + 1.0 / (M_PI * gamma * (1.0 + pow((ZIn + Z_m) / gamma, 2.)))); *Bmag = sqrt(pow(*BRad, 2) + pow(*BZ, 2)); } -double -integrand_z_psiZ(double ZIn, void *ctx) +double integrand_z_psiZ(double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = app->psi_in; @@ -146,19 +144,15 @@ integrand_z_psiZ(double ZIn, void *ctx) return Bmag / BZ; } -double -z_psiZ(double psiIn, double ZIn, void *ctx) +double z_psiZ(double psiIn, double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; app->psi_in = psiIn; double eps = 0.0; struct gkyl_qr_res integral; - if (eps <= ZIn) - { + if (eps <= ZIn) { integral = gkyl_dbl_exp(integrand_z_psiZ, ctx, eps, ZIn, 7, 1e-14); - } - else - { + } else { integral = gkyl_dbl_exp(integrand_z_psiZ, ctx, ZIn, eps, 7, 1e-14); integral.res = -integral.res; } @@ -166,30 +160,27 @@ z_psiZ(double psiIn, double ZIn, void *ctx) } // Invert z(Z) via root-finding. -double -root_Z_psiz(double Z, void *ctx) +double root_Z_psiz(double Z, void *ctx) { struct gk_mirror_ctx *app = ctx; return app->z_in - z_psiZ(app->psi_in, Z, ctx); } -double -Z_psiz(double psiIn, double zIn, void *ctx) +double Z_psiz(double psiIn, double zIn, void *ctx) { struct gk_mirror_ctx *app = ctx; double maxL = app->Z_max - app->Z_min; - double eps = maxL / app->Nz; // Interestingly using a smaller eps yields larger errors in some geo quantities. + double eps = + maxL / + app->Nz; // Interestingly using a smaller eps yields larger errors in some geo quantities. app->psi_in = psiIn; app->z_in = zIn; struct gkyl_qr_res Zout; - if (zIn >= 0.0) - { + if (zIn >= 0.0) { double fl = root_Z_psiz(-eps, ctx); double fr = root_Z_psiz(app->Z_max + eps, ctx); Zout = gkyl_ridders(root_Z_psiz, ctx, -eps, app->Z_max + eps, fl, fr, 1000, 1e-14); - } - else - { + } else { double fl = root_Z_psiz(app->Z_min - eps, ctx); double fr = root_Z_psiz(eps, ctx); Zout = gkyl_ridders(root_Z_psiz, ctx, app->Z_min - eps, eps, fl, fr, 1000, 1e-14); @@ -199,8 +190,9 @@ Z_psiz(double psiIn, double zIn, void *ctx) // -- Source functions. -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -210,25 +202,26 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(Z) <= app->Z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(Z) <= app->Z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -236,19 +229,17 @@ eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -257,42 +248,30 @@ eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT double R = R_psiZ(psi, Z, ctx); // Cylindrical radial coordinate. double BRad, BZ, Bmag; Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); - if (fabs(Z) <= app->Z_bt) - { + if (fabs(Z) <= app->Z_bt) { fout[0] = app->n0 * pow(1.0 - pow((R - app->R_bt) / app->alim, 2), app->alphaIC0 / 2); - } - else if (fabs(Z) <= app->Z_m) - { + } else if (fabs(Z) <= app->Z_m) { fout[0] = app->n0 * pow(1.0 - pow((R - app->R_bt) / app->alim, 2), app->alphaIC1 / 2); - } - else - { + } else { fout[0] = app->n_m * sqrt(Bmag / app->B_m); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. double z = xn[0]; - if (fabs(z) <= app->z_m) - { + if (fabs(z) <= app->z_m) { fout[0] = 0.0; - } - else if (z > app->z_m) - { + } else if (z > app->z_m) { fout[0] = app->cs_m * (z - app->z_m); //* (z - / app->z_m); - } - else - { + } else { fout[0] = app->cs_m * (z + app->z_m); //* (z + app->z_m) / app->z_m; } } -void -eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -301,23 +280,19 @@ eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double R = R_psiZ(psi, Z, ctx); // Cylindrical radial coordinate. double BRad, BZ, Bmag; Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); - if (fabs(Z) <= app->Z_bt) - { + if (fabs(Z) <= app->Z_bt) { fout[0] = app->Ti0 * pow((1.0 - pow((R - app->R_bt) / app->alim, 2)), app->alphaIC0 / 2); - } - else if (fabs(Z) <= app->Z_m) - { + } else if (fabs(Z) <= app->Z_m) { fout[0] = app->Ti0 * pow((1.0 - pow((R - app->R_bt) / app->alim, 2)), app->alphaIC1 / 2); - } - else - { + } else { fout[0] = app->Ti_m * sqrt(Bmag / app->B_m); } } // Elc initial conditions -void -eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0]; @@ -325,8 +300,7 @@ eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout[0] = app->n0; } -void -eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double z = xn[0]; @@ -334,8 +308,7 @@ eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo fout[0] = 0.0; } -void -eval_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double z = xn[0]; @@ -344,29 +317,25 @@ eval_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo } // Evaluate collision frequencies -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElcIon; } -void -evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIonElc; @@ -374,8 +343,7 @@ evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fou // Geometry evaluation functions for the gk app // mapc2p must assume a 3d input xc -void -mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double psi = xc[0]; double theta = xc[1]; @@ -393,8 +361,7 @@ mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) } // bfield_func must assume a 3d input xc -void -bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xc[2]; @@ -404,15 +371,14 @@ bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); double phi = xc[1]; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. - fout[0] = BRad*cos(phi); - fout[1] = BRad*sin(phi); + fout[0] = BRad * cos(phi); + fout[1] = BRad * sin(phi); fout[2] = BZ; } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -422,7 +388,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -446,11 +412,12 @@ create_ctx(void) (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti0, 3. / 2.)); // Ion-ion collision freq. double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); - double nuElc = nuFrac * logLambdaElc * pow(eV, 4.) * n0 / - (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); + double nuElc = + nuFrac * logLambdaElc * pow(eV, 4.) * n0 / + (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); // Cross collision freq. - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); // Thermal speeds. double vti = sqrt(Ti0 / mi); @@ -506,13 +473,14 @@ create_ctx(void) double mu_max_elc = me * pow(3. * vte, 2.) / (2. * B_p); int Nz = 32; int Nvpar = 32; // Number of cells in the paralell velocity direction 96 - int Nmu = 16; // Number of cells in the mu direction 192 + int Nmu = 16; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 1.0e-7; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -581,18 +549,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -603,10 +572,12 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters @@ -87,14 +86,14 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -double -psi_RZ(double RIn, double ZIn, void *ctx) +double psi_RZ(double RIn, double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; double mcB = app->mcB; @@ -106,35 +105,34 @@ psi_RZ(double RIn, double ZIn, void *ctx) return psi; } -double -R_psiZ(double psiIn, double ZIn, void *ctx) +double R_psiZ(double psiIn, double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; - double Rout = sqrt(2.0 * psiIn / (app->mcB * - (1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn - app->Z_m) / app->gamma, 2.))) + - 1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn + app->Z_m) / app->gamma, 2.)))))); + double Rout = sqrt( + 2.0 * psiIn / + (app->mcB * (1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn - app->Z_m) / app->gamma, 2.))) + + 1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn + app->Z_m) / app->gamma, 2.))))) + ); return Rout; } -void -Bfield_psiZ(double psiIn, double ZIn, void *ctx, double *BRad, double *BZ, double *Bmag) +void Bfield_psiZ(double psiIn, double ZIn, void *ctx, double *BRad, double *BZ, double *Bmag) { struct gk_mirror_ctx *app = ctx; double Rcoord = R_psiZ(psiIn, ZIn, ctx); double mcB = app->mcB; double gamma = app->gamma; double Z_m = app->Z_m; - *BRad = -(1.0 / 2.0) * Rcoord * mcB * - (-2.0 * (ZIn - Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn - Z_m) / gamma, 2.), 2.))) - - 2.0 * (ZIn + Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn + Z_m) / gamma, 2.), 2.)))); - *BZ = mcB * - (1.0 / (M_PI * gamma * (1.0 + pow((ZIn - Z_m) / gamma, 2.))) + - 1.0 / (M_PI * gamma * (1.0 + pow((ZIn + Z_m) / gamma, 2.)))); + *BRad = + -(1.0 / 2.0) * Rcoord * mcB * + (-2.0 * (ZIn - Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn - Z_m) / gamma, 2.), 2.))) - + 2.0 * (ZIn + Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn + Z_m) / gamma, 2.), 2.)))); + *BZ = mcB * (1.0 / (M_PI * gamma * (1.0 + pow((ZIn - Z_m) / gamma, 2.))) + + 1.0 / (M_PI * gamma * (1.0 + pow((ZIn + Z_m) / gamma, 2.)))); *Bmag = sqrt(pow(*BRad, 2) + pow(*BZ, 2)); } -double -integrand_z_psiZ(double ZIn, void *ctx) +double integrand_z_psiZ(double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = app->psi_in; @@ -143,19 +141,15 @@ integrand_z_psiZ(double ZIn, void *ctx) return Bmag / BZ; } -double -z_psiZ(double psiIn, double ZIn, void *ctx) +double z_psiZ(double psiIn, double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; app->psi_in = psiIn; double eps = 0.0; struct gkyl_qr_res integral; - if (eps <= ZIn) - { + if (eps <= ZIn) { integral = gkyl_dbl_exp(integrand_z_psiZ, ctx, eps, ZIn, 7, 1e-14); - } - else - { + } else { integral = gkyl_dbl_exp(integrand_z_psiZ, ctx, ZIn, eps, 7, 1e-14); integral.res = -integral.res; } @@ -163,30 +157,27 @@ z_psiZ(double psiIn, double ZIn, void *ctx) } // Invert z(Z) via root-finding. -double -root_Z_psiz(double Z, void *ctx) +double root_Z_psiz(double Z, void *ctx) { struct gk_mirror_ctx *app = ctx; return app->z_in - z_psiZ(app->psi_in, Z, ctx); } -double -Z_psiz(double psiIn, double zIn, void *ctx) +double Z_psiz(double psiIn, double zIn, void *ctx) { struct gk_mirror_ctx *app = ctx; double maxL = app->Z_max - app->Z_min; - double eps = maxL / app->Nz; // Interestingly using a smaller eps yields larger errors in some geo quantities. + double eps = + maxL / + app->Nz; // Interestingly using a smaller eps yields larger errors in some geo quantities. app->psi_in = psiIn; app->z_in = zIn; struct gkyl_qr_res Zout; - if (zIn >= 0.0) - { + if (zIn >= 0.0) { double fl = root_Z_psiz(-eps, ctx); double fr = root_Z_psiz(app->Z_max + eps, ctx); Zout = gkyl_ridders(root_Z_psiz, ctx, -eps, app->Z_max + eps, fl, fr, 1000, 1e-14); - } - else - { + } else { double fl = root_Z_psiz(app->Z_min - eps, ctx); double fr = root_Z_psiz(eps, ctx); Zout = gkyl_ridders(root_Z_psiz, ctx, app->Z_min - eps, eps, fl, fr, 1000, 1e-14); @@ -196,8 +187,9 @@ Z_psiz(double psiIn, double zIn, void *ctx) // -- Source functions. -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -207,25 +199,26 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(Z) <= app->Z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(Z) <= app->Z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -233,19 +226,17 @@ eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -254,42 +245,30 @@ eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT double R = R_psiZ(psi, Z, ctx); // Cylindrical radial coordinate. double BRad, BZ, Bmag; Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); - if (fabs(Z) <= app->Z_bt) - { + if (fabs(Z) <= app->Z_bt) { fout[0] = app->n0 * pow(1.0 - pow((R - app->R_bt) / app->alim, 2), app->alphaIC0 / 2); - } - else if (fabs(Z) <= app->Z_m) - { + } else if (fabs(Z) <= app->Z_m) { fout[0] = app->n0 * pow(1.0 - pow((R - app->R_bt) / app->alim, 2), app->alphaIC1 / 2); - } - else - { + } else { fout[0] = app->n_m * sqrt(Bmag / app->B_m); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. double z = xn[0]; - if (fabs(z) <= app->z_m) - { + if (fabs(z) <= app->z_m) { fout[0] = 0.0; - } - else if (z > app->z_m) - { + } else if (z > app->z_m) { fout[0] = app->cs_m * (z - app->z_m); //* (z - / app->z_m); - } - else - { + } else { fout[0] = app->cs_m * (z + app->z_m); //* (z + app->z_m) / app->z_m; } } -void -eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -298,23 +277,17 @@ eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double R = R_psiZ(psi, Z, ctx); // Cylindrical radial coordinate. double BRad, BZ, Bmag; Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); - if (fabs(Z) <= app->Z_bt) - { + if (fabs(Z) <= app->Z_bt) { fout[0] = app->Ti0 * pow((1.0 - pow((R - app->R_bt) / app->alim, 2)), app->alphaIC0 / 2); - } - else if (fabs(Z) <= app->Z_m) - { + } else if (fabs(Z) <= app->Z_m) { fout[0] = app->Ti0 * pow((1.0 - pow((R - app->R_bt) / app->alim, 2)), app->alphaIC1 / 2); - } - else - { + } else { fout[0] = app->Ti_m * sqrt(Bmag / app->B_m); } } // Evaluate collision frequencies -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; @@ -322,8 +295,7 @@ evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, // Geometry evaluation functions for the gk app // mapc2p must assume a 3d input xc -void -mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double psi = xc[0]; double theta = xc[1]; @@ -341,8 +313,7 @@ mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) } // bmag_func must assume a 3d input xc -void -bmag_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) +void bmag_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xc[2]; @@ -354,8 +325,7 @@ bmag_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) } // bfield_func must assume a 3d input xc -void -bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xc[2]; @@ -365,15 +335,16 @@ bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); double phi = xc[1]; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. - fout[0] = BRad*cos(phi); - fout[1] = BRad*sin(phi); + fout[0] = BRad * cos(phi); + fout[1] = BRad * sin(phi); fout[2] = BZ; } -void -loss_cone_damping_rate_profile(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void loss_cone_damping_rate_profile( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0], vpar = xn[1], mu = xn[2]; @@ -387,33 +358,36 @@ loss_cone_damping_rate_profile(double t, const double *GKYL_RESTRICT xn, double double xc[] = {0.0, 0.0, z}; bmag_func(t, xc, bmag, ctx); - double Rm = B_m/bmag[0]; // Mirror ratio. + double Rm = B_m / bmag[0]; // Mirror ratio. double Delta_phi = 0.0; // Potential difference. - double mu_bound = (0.5*mass*pow(vpar,2)+charge*Delta_phi)/(bmag[0]*(Rm-1)); + double mu_bound = (0.5 * mass * pow(vpar, 2) + charge * Delta_phi) / (bmag[0] * (Rm - 1)); double loss_cone_mask; - if (mu <= mu_bound) + if (mu <= mu_bound) { loss_cone_mask = 1.0; - else + } else { loss_cone_mask = 0.0; + } double vt = app->vti; double z_m = app->z_m; double z_max = app->z_max; double Lpar; - if (fabs(z) <= z_m) + if (fabs(z) <= z_m) { Lpar = z_m; - else + } else { Lpar = z_max - z_m; + } double alpha = app->alpha; - fout[0] = (1.0-alpha) * (vt/Lpar) * loss_cone_mask; + fout[0] = (1.0 - alpha) * (vt / Lpar) * loss_cone_mask; } -void -loss_cone_damping_rate_scaling(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void loss_cone_damping_rate_scaling( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0], vpar = xn[1], mu = xn[2]; @@ -424,14 +398,13 @@ loss_cone_damping_rate_scaling(double t, const double *GKYL_RESTRICT xn, double if (fabs(z) < z_m) { double Lpar = z_m; - fout[0] = (1.0-alpha) * vt/Lpar; - } - else + fout[0] = (1.0 - alpha) * vt / Lpar; + } else { fout[0] = 0.0; + } } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -441,7 +414,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -518,13 +491,14 @@ create_ctx(void) double mu_max_ion = mi * pow(3. * vti, 2.) / (2. * B_p); int Nz = 32; int Nvpar = 32; // Number of cells in the paralell velocity direction 96 - int Nmu = 48; // Number of cells in the mu direction 192 + int Nmu = 48; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 6.0e-7; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -590,31 +564,34 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -calc_integrated_diagnostics(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_app* app, - double t_curr, bool is_restart_IC, bool force_calc, double dt) +void calc_integrated_diagnostics( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_app *app, double t_curr, bool is_restart_IC, + bool force_calc, double dt +) { if (!is_restart_IC && (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_calc)) { gkyl_gyrokinetic_app_calc_field_energy(app, t_curr); gkyl_gyrokinetic_app_calc_integrated_mom(app, t_curr); - if ( !(dt < 0.0) ) + if (!(dt < 0.0)) { gkyl_gyrokinetic_app_save_dt(app, t_curr, dt); + } } } -void -write_data(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot_phase, - gkyl_gyrokinetic_app* app, double t_curr, bool is_restart_IC, bool force_write) +void write_data( + struct gkyl_tm_trigger *iot_conf, struct gkyl_tm_trigger *iot_phase, gkyl_gyrokinetic_app *app, + double t_curr, bool is_restart_IC, bool force_write +) { bool trig_now_conf = gkyl_tm_trigger_check_and_bump(iot_conf, t_curr); if (trig_now_conf || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_app_write_conf(app, t_curr, frame); if (!is_restart_IC) { @@ -626,7 +603,7 @@ write_data(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot_phase, bool trig_now_phase = gkyl_tm_trigger_check_and_bump(iot_phase, t_curr); if (trig_now_phase || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_app_write_phase(app, t_curr, frame); } @@ -637,7 +614,9 @@ int main(int argc, char **argv) struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -648,10 +627,12 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dmcB; @@ -127,35 +127,34 @@ psi_RZ(double RIn, double ZIn, void *ctx) return psi; } -double -R_psiZ(double psiIn, double ZIn, void *ctx) +double R_psiZ(double psiIn, double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; - double Rout = sqrt(2.0 * psiIn / (app->mcB * - (1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn - app->Z_m) / app->gamma, 2.))) + - 1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn + app->Z_m) / app->gamma, 2.)))))); + double Rout = sqrt( + 2.0 * psiIn / + (app->mcB * (1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn - app->Z_m) / app->gamma, 2.))) + + 1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn + app->Z_m) / app->gamma, 2.))))) + ); return Rout; } -void -Bfield_psiZ(double psiIn, double ZIn, void *ctx, double *BRad, double *BZ, double *Bmag) +void Bfield_psiZ(double psiIn, double ZIn, void *ctx, double *BRad, double *BZ, double *Bmag) { struct gk_mirror_ctx *app = ctx; double Rcoord = R_psiZ(psiIn, ZIn, ctx); double mcB = app->mcB; double gamma = app->gamma; double Z_m = app->Z_m; - *BRad = -(1.0 / 2.0) * Rcoord * mcB * - (-2.0 * (ZIn - Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn - Z_m) / gamma, 2.), 2.))) - - 2.0 * (ZIn + Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn + Z_m) / gamma, 2.), 2.)))); - *BZ = mcB * - (1.0 / (M_PI * gamma * (1.0 + pow((ZIn - Z_m) / gamma, 2.))) + - 1.0 / (M_PI * gamma * (1.0 + pow((ZIn + Z_m) / gamma, 2.)))); + *BRad = + -(1.0 / 2.0) * Rcoord * mcB * + (-2.0 * (ZIn - Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn - Z_m) / gamma, 2.), 2.))) - + 2.0 * (ZIn + Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn + Z_m) / gamma, 2.), 2.)))); + *BZ = mcB * (1.0 / (M_PI * gamma * (1.0 + pow((ZIn - Z_m) / gamma, 2.))) + + 1.0 / (M_PI * gamma * (1.0 + pow((ZIn + Z_m) / gamma, 2.)))); *Bmag = sqrt(pow(*BRad, 2) + pow(*BZ, 2)); } -double -integrand_z_psiZ(double ZIn, void *ctx) +double integrand_z_psiZ(double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = app->psi_in; @@ -164,19 +163,15 @@ integrand_z_psiZ(double ZIn, void *ctx) return Bmag / BZ; } -double -z_psiZ(double psiIn, double ZIn, void *ctx) +double z_psiZ(double psiIn, double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; app->psi_in = psiIn; double eps = 0.0; struct gkyl_qr_res integral; - if (eps <= ZIn) - { + if (eps <= ZIn) { integral = gkyl_dbl_exp(integrand_z_psiZ, ctx, eps, ZIn, 7, 1e-14); - } - else - { + } else { integral = gkyl_dbl_exp(integrand_z_psiZ, ctx, ZIn, eps, 7, 1e-14); integral.res = -integral.res; } @@ -184,30 +179,27 @@ z_psiZ(double psiIn, double ZIn, void *ctx) } // Invert z(Z) via root-finding. -double -root_Z_psiz(double Z, void *ctx) +double root_Z_psiz(double Z, void *ctx) { struct gk_mirror_ctx *app = ctx; return app->z_in - z_psiZ(app->psi_in, Z, ctx); } -double -Z_psiz(double psiIn, double zIn, void *ctx) +double Z_psiz(double psiIn, double zIn, void *ctx) { struct gk_mirror_ctx *app = ctx; double maxL = app->Z_max - app->Z_min; - double eps = maxL / app->Nz; // Interestingly using a smaller eps yields larger errors in some geo quantities. + double eps = + maxL / + app->Nz; // Interestingly using a smaller eps yields larger errors in some geo quantities. app->psi_in = psiIn; app->z_in = zIn; struct gkyl_qr_res Zout; - if (zIn >= 0.0) - { + if (zIn >= 0.0) { double fl = root_Z_psiz(-eps, ctx); double fr = root_Z_psiz(app->Z_max + eps, ctx); Zout = gkyl_ridders(root_Z_psiz, ctx, -eps, app->Z_max + eps, fl, fr, 1000, 1e-14); - } - else - { + } else { double fl = root_Z_psiz(app->Z_min - eps, ctx); double fr = root_Z_psiz(eps, ctx); Zout = gkyl_ridders(root_Z_psiz, ctx, app->Z_min - eps, eps, fl, fr, 1000, 1e-14); @@ -215,8 +207,9 @@ Z_psiz(double psiIn, double zIn, void *ctx) return Zout.res; } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0]; @@ -229,25 +222,26 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. double Z = Z_psiz(psi, z, ctx); // Cylindrical axial coordinate. - if (fabs(Z) <= app->Z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-pow(z - zSrc, 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(Z) <= app->Z_m) { + fout[0] = fmax( + NSrcFloor, + (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * exp(-pow(z - zSrc, 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0]; @@ -256,37 +250,31 @@ eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0]; struct gk_mirror_ctx *app = ctx; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0*exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double z = xn[0]; @@ -294,18 +282,16 @@ eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { + } else { fout[0] = (fabs(z) / z) * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); } } -void -eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0]; @@ -313,18 +299,16 @@ eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Ti_par0 = app->Ti_par0; double Ti_par_m = app->Ti_par_m; - if (fabs(z) <= z_m) - { - fout[0] = Ti_par_m+(Ti_par0-Ti_par_m)*tanh(4 * fabs(z_m - fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Ti_par_m + (Ti_par0 - Ti_par_m) * tanh(4 * fabs(z_m - fabs(z))); + } else { fout[0] = Ti_par_m; } } -void -eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0]; @@ -332,18 +316,14 @@ eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Ti_perp0 = app->Ti_perp0; double Ti_perp_m = app->Ti_perp_m; - if (fabs(z) <= z_m) - { - fout[0] = Ti_perp_m - Ti_perp0*tanh(3.*fabs(z_m-fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Ti_perp_m - Ti_perp0 * tanh(3. * fabs(z_m - fabs(z))); + } else { fout[0] = Ti_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; @@ -351,8 +331,7 @@ evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, // Geometry evaluation functions for the gk app // mapc2p must assume a 3d input xc -void -mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double psi = xc[0]; double theta = xc[1]; @@ -370,8 +349,7 @@ mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) } // bmag_func must assume a 3d input xc -void -bmag_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) +void bmag_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double z = xc[2]; @@ -384,8 +362,7 @@ bmag_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) } // bfield_func must assume a 3d input xc -void -bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double z = xc[2]; @@ -396,14 +373,14 @@ bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); double phi = xc[1]; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. - fout[0] = BRad*cos(phi); - fout[1] = BRad*sin(phi); + fout[0] = BRad * cos(phi); + fout[1] = BRad * sin(phi); fout[2] = BZ; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -413,35 +390,35 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * // Linear map up to vpar_max/lin_frac_inv, then a power grid. double vpar_lin_fac_inv = app->vpar_lin_fac_inv; double vpar_pow = app->vpar_pow; - if (fabs(cvpar) <= 1.0/vpar_lin_fac_inv) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -1.0/vpar_lin_fac_inv) - vp[0] = -vpar_max_ion*pow(vpar_lin_fac_inv,vpar_pow-1)*pow(fabs(cvpar),vpar_pow); - else - vp[0] = vpar_max_ion*pow(vpar_lin_fac_inv,vpar_pow-1)*pow(fabs(cvpar),vpar_pow); - -// // Quadratic mu. -// vp[1] = mu_max_ion*pow(cmu,2.0); + if (fabs(cvpar) <= 1.0 / vpar_lin_fac_inv) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -1.0 / vpar_lin_fac_inv) { + vp[0] = -vpar_max_ion * pow(vpar_lin_fac_inv, vpar_pow - 1) * pow(fabs(cvpar), vpar_pow); + } else { + vp[0] = vpar_max_ion * pow(vpar_lin_fac_inv, vpar_pow - 1) * pow(fabs(cvpar), vpar_pow); + } + + // // Quadratic mu. + // vp[1] = mu_max_ion*pow(cmu,2.0); // Linear map up to mu_max/lin_frac_inv, then a power grid. double mu_lin_fac_inv = app->mu_lin_fac_inv; double mu_pow = app->mu_pow; -// if (cmu <= 1.0/mu_lin_fac_inv) -// vp[0] = mu_max_ion*cmu; -// else -// vp[0] = mu_max_ion*pow(mu_lin_fac_inv,mu_pow-1)*pow(cmu,mu_pow); + // if (cmu <= 1.0/mu_lin_fac_inv) + // vp[0] = mu_max_ion*cmu; + // else + // vp[0] = mu_max_ion*pow(mu_lin_fac_inv,mu_pow-1)*pow(cmu,mu_pow); double w = 0.3; double f = 0.012; - double a = mu_max_ion*(f-1.0)/(w*w-1.0); - double b = mu_max_ion*(w*w-f)/(w*w-1.0); - if (cmu <= w) - vp[1] = (f*mu_max_ion/w)*cmu; - else - vp[1] = a*pow(cmu,2)+b; - + double a = mu_max_ion * (f - 1.0) / (w * w - 1.0); + double b = mu_max_ion * (w * w - f) / (w * w - 1.0); + if (cmu <= w) { + vp[1] = (f * mu_max_ion / w) * cmu; + } else { + vp[1] = a * pow(cmu, 2) + b; + } } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -451,7 +428,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -488,7 +465,7 @@ create_ctx(void) // Axial coordinate Z extents. Endure that Z=0 is not on // the boundary of a cell (due to AD errors). double Z_min = -2.5; - double Z_max = 2.5; + double Z_max = 2.5; // Parameters controlling the magnetic equilibrium model. double mcB = 6.51292; @@ -511,19 +488,19 @@ create_ctx(void) // Computational velocity space limits. double vpar_lin_fac_inv = 4; double vpar_pow = 3; - double vpar_min_ion_c = -1.0/pow(vpar_lin_fac_inv,(vpar_pow-1)/vpar_pow); - double vpar_max_ion_c = 1.0/pow(vpar_lin_fac_inv,(vpar_pow-1)/vpar_pow); + double vpar_min_ion_c = -1.0 / pow(vpar_lin_fac_inv, (vpar_pow - 1) / vpar_pow); + double vpar_max_ion_c = 1.0 / pow(vpar_lin_fac_inv, (vpar_pow - 1) / vpar_pow); double mu_min_ion_c = 0.; double mu_max_ion_c = 1.; - double mu_lin_fac_inv = 1.0/0.012; + double mu_lin_fac_inv = 1.0 / 0.012; double mu_pow = 2; -// double mu_min_ion_c = 0.0; -// double mu_max_ion_c = 1.0/pow(mu_lin_fac_inv,(mu_pow-1)/mu_pow); + // double mu_min_ion_c = 0.0; + // double mu_max_ion_c = 1.0/pow(mu_lin_fac_inv,(mu_pow-1)/mu_pow); // Grid DOF: int Nz = 64; // Number of cells in z direction. int Nvpar = 32; // Number of cells in parallel velocity direction. - int Nmu = 16; // Number of cells in mu direction. + int Nmu = 16; // Number of cells in mu direction. int poly_order = 1; // Initial conditions parameter.s @@ -534,7 +511,7 @@ create_ctx(void) double Ti_perp_m = 15000 * eV; double Ti_par_m = 1000 * eV; double z_m = 0.982544; - double cs_m = sqrt((Te0+3.0*Ti_par_m)/mi); + double cs_m = sqrt((Te0 + 3.0 * Ti_par_m) / mi); // Factor multiplying collisionless terms. double alpha_oap = 0.01; @@ -542,13 +519,13 @@ create_ctx(void) // Duration of each phase. double tau_oap = 100e-9; double tau_fdp = 1e-9; - double tau_fdp_extra = 2*tau_fdp; + double tau_fdp_extra = 2 * tau_fdp; int num_cycles = 2; // Number of OAP+FDP cycles to run. // Frame counts for each phase type (specified independently) int num_frames_oap = 1; // Frames per OAP phase int num_frames_fdp = 1; // Frames per FDP phase - int num_frames_fdp_extra = 1; // Frames for the extra FDP phase + int num_frames_fdp_extra = 1; // Frames for the extra FDP phase // Whether to evolve the field. bool is_static_field_oap = true; @@ -561,70 +538,93 @@ create_ctx(void) enum gkyl_gyrokinetic_fdot_multiplier_type fdot_mult_type_fdp = GKYL_GK_FDOT_MULTIPLIER_NONE; // Calculate phase structure - double t_end = (tau_oap + tau_fdp)*num_cycles + tau_fdp_extra; - double tau_pair = tau_oap+tau_fdp; // Duration of an OAP+FDP pair. - int num_phases = 2*num_cycles + 1; + double t_end = (tau_oap + tau_fdp) * num_cycles + tau_fdp_extra; + double tau_pair = tau_oap + tau_fdp; // Duration of an OAP+FDP pair. + int num_phases = 2 * num_cycles + 1; int num_frames = num_cycles * (num_frames_oap + num_frames_fdp) + num_frames_fdp_extra; - struct gk_poa_phase_params *poa_phases = gkyl_malloc(num_phases * sizeof(struct gk_poa_phase_params)); - for (int i=0; i<(num_phases-1)/2; i++) { + struct gk_poa_phase_params *poa_phases = + gkyl_malloc(num_phases * sizeof(struct gk_poa_phase_params)); + for (int i = 0; i < (num_phases - 1) / 2; i++) { // OAPs. - poa_phases[2*i].phase = GK_POA_OAP; - poa_phases[2*i].num_frames = num_frames_oap; - poa_phases[2*i].duration = tau_oap; - poa_phases[2*i].alpha = alpha_oap; - poa_phases[2*i].is_static_field = is_static_field_oap; - poa_phases[2*i].fdot_mult_type = fdot_mult_type_oap; - poa_phases[2*i].is_positivity_enabled = is_positivity_enabled_oap; + poa_phases[2 * i].phase = GK_POA_OAP; + poa_phases[2 * i].num_frames = num_frames_oap; + poa_phases[2 * i].duration = tau_oap; + poa_phases[2 * i].alpha = alpha_oap; + poa_phases[2 * i].is_static_field = is_static_field_oap; + poa_phases[2 * i].fdot_mult_type = fdot_mult_type_oap; + poa_phases[2 * i].is_positivity_enabled = is_positivity_enabled_oap; // FDPs. - poa_phases[2*i+1].phase = GK_POA_FDP; - poa_phases[2*i+1].num_frames = num_frames_fdp; - poa_phases[2*i+1].duration = tau_fdp; - poa_phases[2*i+1].alpha = alpha_fdp; - poa_phases[2*i+1].is_static_field = is_static_field_fdp; - poa_phases[2*i+1].fdot_mult_type = fdot_mult_type_fdp; - poa_phases[2*i+1].is_positivity_enabled = is_positivity_enabled_fdp; + poa_phases[2 * i + 1].phase = GK_POA_FDP; + poa_phases[2 * i + 1].num_frames = num_frames_fdp; + poa_phases[2 * i + 1].duration = tau_fdp; + poa_phases[2 * i + 1].alpha = alpha_fdp; + poa_phases[2 * i + 1].is_static_field = is_static_field_fdp; + poa_phases[2 * i + 1].fdot_mult_type = fdot_mult_type_fdp; + poa_phases[2 * i + 1].is_positivity_enabled = is_positivity_enabled_fdp; } // Add an extra, longer FDP. - poa_phases[num_phases-1].phase = GK_POA_FDP; - poa_phases[num_phases-1].num_frames = num_frames_fdp_extra; - poa_phases[num_phases-1].duration = tau_fdp_extra; - poa_phases[num_phases-1].alpha = alpha_fdp; - poa_phases[num_phases-1].is_static_field = is_static_field_fdp; - poa_phases[num_phases-1].fdot_mult_type = fdot_mult_type_fdp; - poa_phases[num_phases-1].is_positivity_enabled = is_positivity_enabled_fdp; - - double write_phase_freq = 0.5; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - double int_diag_calc_freq = 5; // Frequency of calculating integrated diagnostics (as a factor of num_frames). + poa_phases[num_phases - 1].phase = GK_POA_FDP; + poa_phases[num_phases - 1].num_frames = num_frames_fdp_extra; + poa_phases[num_phases - 1].duration = tau_fdp_extra; + poa_phases[num_phases - 1].alpha = alpha_fdp; + poa_phases[num_phases - 1].is_static_field = is_static_field_fdp; + poa_phases[num_phases - 1].fdot_mult_type = fdot_mult_type_fdp; + poa_phases[num_phases - 1].is_positivity_enabled = is_positivity_enabled_fdp; + + double write_phase_freq = + 0.5; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double int_diag_calc_freq = + 5; // Frequency of calculating integrated diagnostics (as a factor of num_frames). double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_mirror_ctx ctx = { - .cdim = cdim, .vdim = vdim, - .mi = mi, .qi = qi, - .me = me, .qe = qe, - .Te0 = Te0, .Ti0 = Ti0, .n0 = n0, - .B_p = B_p, .beta = beta, .tau = tau, + .cdim = cdim, + .vdim = vdim, + .mi = mi, + .qi = qi, + .me = me, + .qe = qe, + .Te0 = Te0, + .Ti0 = Ti0, + .n0 = n0, + .B_p = B_p, + .beta = beta, + .tau = tau, .alim = alim, .alphaIC0 = alphaIC0, .alphaIC1 = alphaIC1, - .nuFrac = nuFrac, .logLambdaIon = logLambdaIon, .nuIon = nuIon, - .vti = vti, .vte = vte, .c_s = c_s, - .omega_ci = omega_ci, .rho_s = rho_s, + .nuFrac = nuFrac, + .logLambdaIon = logLambdaIon, + .nuIon = nuIon, + .vti = vti, + .vte = vte, + .c_s = c_s, + .omega_ci = omega_ci, + .rho_s = rho_s, .RatZeq0 = RatZeq0, - .Z_min = Z_min, .Z_max = Z_max, + .Z_min = Z_min, + .Z_max = Z_max, // Parameters controlling the magnetic equilibrium model. - .mcB = mcB, .gamma = gamma, + .mcB = mcB, + .gamma = gamma, .Z_m = Z_m, .z_m = z_m, // Initial condition parameters. - .Ti_perp0 = Ti_perp0, .Ti_par0 = Ti_par0, - .Ti_perp_m = Ti_perp_m, .Ti_par_m = Ti_par_m, .cs_m = cs_m, + .Ti_perp0 = Ti_perp0, + .Ti_par0 = Ti_par0, + .Ti_perp_m = Ti_perp_m, + .Ti_par_m = Ti_par_m, + .cs_m = cs_m, // Source parameters - .NSrcIon = NSrcIon, .NSrcFloorIon = NSrcFloorIon, - .TSrc0Ion = TSrc0Ion, .TSrcFloorIon = TSrcFloorIon, - .lineLengthSrcIon = lineLengthSrcIon, .sigSrcIon = sigSrcIon, + .NSrcIon = NSrcIon, + .NSrcFloorIon = NSrcFloorIon, + .TSrc0Ion = TSrc0Ion, + .TSrcFloorIon = TSrcFloorIon, + .lineLengthSrcIon = lineLengthSrcIon, + .sigSrcIon = sigSrcIon, // Physical velocity space limits. .vpar_min_ion = vpar_min_ion, .vpar_max_ion = vpar_max_ion, @@ -649,46 +649,47 @@ create_ctx(void) .num_frames = num_frames, .num_phases = num_phases, .poa_phases = poa_phases, - .write_phase_freq = write_phase_freq , - .int_diag_calc_freq = int_diag_calc_freq , - .dt_failure_tol = dt_failure_tol , - .num_failures_max = num_failures_max , + .write_phase_freq = write_phase_freq, + .int_diag_calc_freq = int_diag_calc_freq, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max }; // Populate a couple more values in the context. ctx.psi_eval = psi_RZ(ctx.RatZeq0, 0., &ctx); - ctx.z_min = z_psiZ(ctx.psi_eval, ctx.Z_min, &ctx); - ctx.z_max = z_psiZ(ctx.psi_eval, ctx.Z_max, &ctx); + ctx.z_min = z_psiZ(ctx.psi_eval, ctx.Z_min, &ctx); + ctx.z_max = z_psiZ(ctx.psi_eval, ctx.Z_max, &ctx); return ctx; } -void -release_ctx(struct gk_mirror_ctx *ctx) +void release_ctx(struct gk_mirror_ctx *ctx) { gkyl_free(ctx->poa_phases); } -void -calc_integrated_diagnostics(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_app* app, - double t_curr, bool force_calc, double dt) +void calc_integrated_diagnostics( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_app *app, double t_curr, bool force_calc, double dt +) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_calc) { gkyl_gyrokinetic_app_calc_field_energy(app, t_curr); gkyl_gyrokinetic_app_calc_integrated_mom(app, t_curr); - if ( !(dt < 0.0) ) + if (!(dt < 0.0)) { gkyl_gyrokinetic_app_save_dt(app, t_curr, dt); + } } } -void -write_data(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot_phase, - gkyl_gyrokinetic_app* app, double t_curr, bool force_write) +void write_data( + struct gkyl_tm_trigger *iot_conf, struct gkyl_tm_trigger *iot_phase, gkyl_gyrokinetic_app *app, + double t_curr, bool force_write +) { bool trig_now_conf = gkyl_tm_trigger_check_and_bump(iot_conf, t_curr); if (trig_now_conf || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_app_write_conf(app, t_curr, frame); gkyl_gyrokinetic_app_write_field_energy(app); @@ -698,7 +699,7 @@ write_data(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot_phase, bool trig_now_phase = gkyl_tm_trigger_check_and_bump(iot_phase, t_curr); if (trig_now_phase || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_app_write_phase(app, t_curr, frame); } @@ -711,16 +712,17 @@ struct time_frame_state { int num_frames; // Number of frames at the end of current phase. }; -void reset_io_triggers(struct gk_mirror_ctx *ctx, struct time_frame_state *tfs, - struct gkyl_tm_trigger *trig_write_conf, struct gkyl_tm_trigger *trig_write_phase, - struct gkyl_tm_trigger *trig_calc_intdiag) +void reset_io_triggers( + struct gk_mirror_ctx *ctx, struct time_frame_state *tfs, struct gkyl_tm_trigger *trig_write_conf, + struct gkyl_tm_trigger *trig_write_phase, struct gkyl_tm_trigger *trig_calc_intdiag +) { // Reset I/O triggers: double t_curr = tfs->t_curr; double t_end = tfs->t_end; int frame_curr = tfs->frame_curr; int num_frames = tfs->num_frames; - int num_int_diag_calc = ctx->int_diag_calc_freq*num_frames; + int num_int_diag_calc = ctx->int_diag_calc_freq * num_frames; // Prevent division by zero when frame_curr equals num_frames int frames_remaining = num_frames - frame_curr; @@ -734,16 +736,19 @@ void reset_io_triggers(struct gk_mirror_ctx *ctx, struct time_frame_state *tfs, trig_write_phase->tcurr = t_curr; trig_write_phase->curr = frame_curr; - int diag_frames = GKYL_MAX2(frames_remaining, (num_int_diag_calc/num_frames) * frames_remaining); + int diag_frames = + GKYL_MAX2(frames_remaining, (num_int_diag_calc / num_frames) * frames_remaining); trig_calc_intdiag->dt = time_remaining / diag_frames; trig_calc_intdiag->tcurr = t_curr; trig_calc_intdiag->curr = frame_curr; } -void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_steps, +void run_phase( + gkyl_gyrokinetic_app *app, struct gk_mirror_ctx *ctx, double num_steps, struct gkyl_tm_trigger *trig_write_conf, struct gkyl_tm_trigger *trig_write_phase, - struct gkyl_tm_trigger *trig_calc_intdiag, struct time_frame_state *tfs, - struct gk_poa_phase_params *pparams) + struct gkyl_tm_trigger *trig_calc_intdiag, struct time_frame_state *tfs, + struct gk_poa_phase_params *pparams +) { tfs->t_end = tfs->t_curr + pparams->duration; tfs->num_frames = tfs->frame_curr + pparams->num_frames; @@ -751,22 +756,18 @@ void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_ // Run an OAP or FDP. double t_curr = tfs->t_curr; double t_end = tfs->t_end; - + // Reset I/O triggers: reset_io_triggers(ctx, tfs, trig_write_conf, trig_write_phase, trig_calc_intdiag); // Reset simulation parameters and function pointers. struct gkyl_gyrokinetic_collisionless collisionless_inp = { - .type = GKYL_GK_COLLISIONLESS_ES, - .scale_factor = pparams->alpha, + .type = GKYL_GK_COLLISIONLESS_ES, .scale_factor = pparams->alpha }; struct gkyl_gyrokinetic_fdot_multiplier fdot_mult_inp = { .num_multipliers = 1, - .multiplier[0] = { - .type = pparams->fdot_mult_type, - .cellwise_const = true, - .write_diagnostics = true, - }, + .multiplier[0] = + {.type = pparams->fdot_mult_type, .cellwise_const = true, .write_diagnostics = true} }; struct gkyl_gyrokinetic_field field_inp = { .gkfield_id = GKYL_GK_FIELD_BOLTZMANN, @@ -774,11 +775,11 @@ void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_ .electron_charge = ctx->qe, .electron_temp = ctx->Te0, .polarization_bmag = ctx->B_p, - .is_static = pparams->is_static_field, + .is_static = pparams->is_static_field }; struct gkyl_gyrokinetic_positivity positivity_inp = { - .type = pparams->is_positivity_enabled? GKYL_GK_POSITIVITY_SHIFT : GKYL_GK_POSITIVITY_NONE, - .write_diagnostics = pparams->is_positivity_enabled, + .type = pparams->is_positivity_enabled ? GKYL_GK_POSITIVITY_SHIFT : GKYL_GK_POSITIVITY_NONE, + .write_diagnostics = pparams->is_positivity_enabled }; gkyl_gyrokinetic_app_reset_species_collisionless(app, t_curr, "ion", collisionless_inp); @@ -794,19 +795,19 @@ void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_ int num_failures = 0, num_failures_max = ctx->num_failures_max; long step = 1; - while ((t_curr < t_end) && (step <= num_steps)) - { - if (step == 1 || step % 1 == 0) + while ((t_curr < t_end) && (step <= num_steps)) { + if (step == 1 || step % 1 == 0) { gkyl_gyrokinetic_app_cout(app, stdout, "Taking time-step at t = %g ...", t_curr); + } dt = fmin(dt, t_end - t_curr); // Don't step beyond t_end. struct gkyl_update_status status = gkyl_gyrokinetic_update(app, dt); - if (step == 1 || step % 1 == 0) + if (step == 1 || step % 1 == 0) { gkyl_gyrokinetic_app_cout(app, stdout, " dt = %g\n", status.dt_actual); + } - if (!status.success) - { + if (!status.success) { gkyl_gyrokinetic_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; } @@ -818,22 +819,24 @@ void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_ if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_gyrokinetic_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); gkyl_gyrokinetic_app_cout(app, stdout, " is below %g*dt_init ...", dt_failure_tol); gkyl_gyrokinetic_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { - gkyl_gyrokinetic_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_gyrokinetic_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_gyrokinetic_app_cout( + app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_integrated_diagnostics(trig_calc_intdiag, app, t_curr, true, status.dt_actual); write_data(trig_write_conf, trig_write_phase, app, t_curr, true); break; } - } - else { + } else { num_failures = 0; } @@ -841,7 +844,7 @@ void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_ } tfs->t_curr = t_curr; - tfs->frame_curr = tfs->frame_curr+pparams->num_frames; + tfs->frame_curr = tfs->frame_curr + pparams->num_frames; } int main(int argc, char **argv) @@ -849,7 +852,9 @@ int main(int argc, char **argv) struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -860,87 +865,76 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d 0) - { - gkyl_gyrokinetic_app_cout(app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_gyrokinetic_app_cout(app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); + if (stat.nstage_2_fail > 0) { + gkyl_gyrokinetic_app_cout( + app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); } gkyl_gyrokinetic_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_gyrokinetic_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_gyrokinetic_app_print_timings(app, stdout); - freeresources: +freeresources: // simulation complete, free app gkyl_gyrokinetic_app_release(app); gkyl_gyrokinetic_comms_release(comm); release_ctx(&ctx); - + #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif return 0; } diff --git a/gyrokinetic/creg/rt_gk_mirror_kinetic_elc_1x2v_p1.c b/gyrokinetic/creg/rt_gk_mirror_kinetic_elc_1x2v_p1.c index 0f85017266..439455b90d 100644 --- a/gyrokinetic/creg/rt_gk_mirror_kinetic_elc_1x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_mirror_kinetic_elc_1x2v_p1.c @@ -13,8 +13,7 @@ #include // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters @@ -100,14 +99,14 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -double -psi_RZ(double RIn, double ZIn, void *ctx) +double psi_RZ(double RIn, double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; double mcB = app->mcB; @@ -119,35 +118,34 @@ psi_RZ(double RIn, double ZIn, void *ctx) return psi; } -double -R_psiZ(double psiIn, double ZIn, void *ctx) +double R_psiZ(double psiIn, double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; - double Rout = sqrt(2.0 * psiIn / (app->mcB * - (1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn - app->Z_m) / app->gamma, 2.))) + - 1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn + app->Z_m) / app->gamma, 2.)))))); + double Rout = sqrt( + 2.0 * psiIn / + (app->mcB * (1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn - app->Z_m) / app->gamma, 2.))) + + 1.0 / (M_PI * app->gamma * (1.0 + pow((ZIn + app->Z_m) / app->gamma, 2.))))) + ); return Rout; } -void -Bfield_psiZ(double psiIn, double ZIn, void *ctx, double *BRad, double *BZ, double *Bmag) +void Bfield_psiZ(double psiIn, double ZIn, void *ctx, double *BRad, double *BZ, double *Bmag) { struct gk_mirror_ctx *app = ctx; double Rcoord = R_psiZ(psiIn, ZIn, ctx); double mcB = app->mcB; double gamma = app->gamma; double Z_m = app->Z_m; - *BRad = -(1.0 / 2.0) * Rcoord * mcB * - (-2.0 * (ZIn - Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn - Z_m) / gamma, 2.), 2.))) - - 2.0 * (ZIn + Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn + Z_m) / gamma, 2.), 2.)))); - *BZ = mcB * - (1.0 / (M_PI * gamma * (1.0 + pow((ZIn - Z_m) / gamma, 2.))) + - 1.0 / (M_PI * gamma * (1.0 + pow((ZIn + Z_m) / gamma, 2.)))); + *BRad = + -(1.0 / 2.0) * Rcoord * mcB * + (-2.0 * (ZIn - Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn - Z_m) / gamma, 2.), 2.))) - + 2.0 * (ZIn + Z_m) / (M_PI * pow(gamma, 3.) * (pow(1.0 + pow((ZIn + Z_m) / gamma, 2.), 2.)))); + *BZ = mcB * (1.0 / (M_PI * gamma * (1.0 + pow((ZIn - Z_m) / gamma, 2.))) + + 1.0 / (M_PI * gamma * (1.0 + pow((ZIn + Z_m) / gamma, 2.)))); *Bmag = sqrt(pow(*BRad, 2) + pow(*BZ, 2)); } -double -integrand_z_psiZ(double ZIn, void *ctx) +double integrand_z_psiZ(double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = app->psi_in; @@ -156,19 +154,15 @@ integrand_z_psiZ(double ZIn, void *ctx) return Bmag / BZ; } -double -z_psiZ(double psiIn, double ZIn, void *ctx) +double z_psiZ(double psiIn, double ZIn, void *ctx) { struct gk_mirror_ctx *app = ctx; app->psi_in = psiIn; double eps = 0.0; struct gkyl_qr_res integral; - if (eps <= ZIn) - { + if (eps <= ZIn) { integral = gkyl_dbl_exp(integrand_z_psiZ, ctx, eps, ZIn, 7, 1e-14); - } - else - { + } else { integral = gkyl_dbl_exp(integrand_z_psiZ, ctx, ZIn, eps, 7, 1e-14); integral.res = -integral.res; } @@ -176,30 +170,27 @@ z_psiZ(double psiIn, double ZIn, void *ctx) } // Invert z(Z) via root-finding. -double -root_Z_psiz(double Z, void *ctx) +double root_Z_psiz(double Z, void *ctx) { struct gk_mirror_ctx *app = ctx; return app->z_in - z_psiZ(app->psi_in, Z, ctx); } -double -Z_psiz(double psiIn, double zIn, void *ctx) +double Z_psiz(double psiIn, double zIn, void *ctx) { struct gk_mirror_ctx *app = ctx; double maxL = app->Z_max - app->Z_min; - double eps = maxL / app->Nz; // Interestingly using a smaller eps yields larger errors in some geo quantities. + double eps = + maxL / + app->Nz; // Interestingly using a smaller eps yields larger errors in some geo quantities. app->psi_in = psiIn; app->z_in = zIn; struct gkyl_qr_res Zout; - if (zIn >= 0.0) - { + if (zIn >= 0.0) { double fl = root_Z_psiz(-eps, ctx); double fr = root_Z_psiz(app->Z_max + eps, ctx); Zout = gkyl_ridders(root_Z_psiz, ctx, -eps, app->Z_max + eps, fl, fr, 1000, 1e-14); - } - else - { + } else { double fl = root_Z_psiz(app->Z_min - eps, ctx); double fr = root_Z_psiz(eps, ctx); Zout = gkyl_ridders(root_Z_psiz, ctx, app->Z_min - eps, eps, fl, fr, 1000, 1e-14); @@ -208,8 +199,9 @@ Z_psiz(double psiIn, double zIn, void *ctx) } // -- Source functions. -void -eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -219,25 +211,26 @@ eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcElc; double sigSrc = app->sigSrcElc; double NSrcFloor = app->NSrcFloorElc; - if (fabs(Z) <= app->Z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.)))); - } - else - { + if (fabs(Z) <= app->Z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -245,18 +238,16 @@ eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcElc; double TSrc0 = app->TSrc0Elc; double Tfloor = app->TSrcFloorElc; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -266,25 +257,26 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(Z) <= app->Z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(Z) <= app->Z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -292,19 +284,17 @@ eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Electrons initial conditions -void -eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -313,42 +303,30 @@ eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT double R = R_psiZ(psi, Z, ctx); // Cylindrical radial coordinate. double BRad, BZ, Bmag; Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); - if (fabs(Z) <= app->Z_bt) - { + if (fabs(Z) <= app->Z_bt) { fout[0] = app->n0 * pow((1.0 - pow((R - app->R_bt) / app->alim, 2.)), app->alphaIC0 / 2.); - } - else if (fabs(Z) <= app->Z_m) - { + } else if (fabs(Z) <= app->Z_m) { fout[0] = app->n0 * pow((1.0 - pow((R - app->R_bt) / app->alim, 2.)), app->alphaIC1 / 2.); - } - else - { + } else { fout[0] = app->n_m * sqrt(Bmag / app->B_m); } } -void -eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. double z = xn[0]; - if (fabs(z) <= app->z_m) - { + if (fabs(z) <= app->z_m) { fout[0] = 0.0; - } - else if (z > app->z_m) - { + } else if (z > app->z_m) { fout[0] = app->cs_m * (z - app->z_m); - } - else - { + } else { fout[0] = app->cs_m * (z + app->z_m); } } -void -eval_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -357,23 +335,19 @@ eval_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double R = R_psiZ(psi, Z, ctx); // Cylindrical radial coordinate. double BRad, BZ, Bmag; Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); - if (fabs(Z) <= app->Z_bt) - { + if (fabs(Z) <= app->Z_bt) { fout[0] = app->Te0 * pow((1.0 - pow((R - app->R_bt) / app->alim, 2.)), app->alphaIC0 / 2.); - } - else if (fabs(Z) <= app->Z_m) - { + } else if (fabs(Z) <= app->Z_m) { fout[0] = app->Te0 * pow((1.0 - pow((R - app->R_bt) / app->alim, 2.)), app->alphaIC1 / 2.); - } - else - { + } else { fout[0] = app->Te_m * sqrt(Bmag / app->B_m); } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -382,42 +356,30 @@ eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT double R = R_psiZ(psi, Z, ctx); // Cylindrical radial coordinate. double BRad, BZ, Bmag; Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); - if (fabs(Z) <= app->Z_bt) - { + if (fabs(Z) <= app->Z_bt) { fout[0] = app->n0 * pow(1.0 - pow((R - app->R_bt) / app->alim, 2), app->alphaIC0 / 2); - } - else if (fabs(Z) <= app->Z_m) - { + } else if (fabs(Z) <= app->Z_m) { fout[0] = app->n0 * pow(1.0 - pow((R - app->R_bt) / app->alim, 2), app->alphaIC1 / 2); - } - else - { + } else { fout[0] = app->n_m * sqrt(Bmag / app->B_m); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. double z = xn[0]; - if (fabs(z) <= app->z_m) - { + if (fabs(z) <= app->z_m) { fout[0] = 0.0; - } - else if (z > app->z_m) - { + } else if (z > app->z_m) { fout[0] = app->cs_m * (z - app->z_m); //* (z - / app->z_m); - } - else - { + } else { fout[0] = app->cs_m * (z + app->z_m); //* (z + app->z_m) / app->z_m; } } -void -eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = psi_RZ(app->RatZeq0, 0.0, ctx); // Magnetic flux function psi of field line. @@ -426,44 +388,35 @@ eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double R = R_psiZ(psi, Z, ctx); // Cylindrical radial coordinate. double BRad, BZ, Bmag; Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); - if (fabs(Z) <= app->Z_bt) - { + if (fabs(Z) <= app->Z_bt) { fout[0] = app->Ti0 * pow((1.0 - pow((R - app->R_bt) / app->alim, 2)), app->alphaIC0 / 2); - } - else if (fabs(Z) <= app->Z_m) - { + } else if (fabs(Z) <= app->Z_m) { fout[0] = app->Ti0 * pow((1.0 - pow((R - app->R_bt) / app->alim, 2)), app->alphaIC1 / 2); - } - else - { + } else { fout[0] = app->Ti_m * sqrt(Bmag / app->B_m); } } // Evaluate collision frequencies -void -evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElcIon; } -void -evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIonElc; @@ -471,8 +424,7 @@ evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fou // Geometry evaluation functions for the gk app // mapc2p must assume a 3d input xc -void -mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double psi = xc[0]; double theta = xc[1]; @@ -490,8 +442,7 @@ mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) } // bfield_func must assume a 3d input xc -void -bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xc[2]; @@ -501,15 +452,14 @@ bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) Bfield_psiZ(psi, Z, ctx, &BRad, &BZ, &Bmag); double phi = xc[1]; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. - fout[0] = BRad*cos(phi); - fout[1] = BRad*sin(phi); + fout[0] = BRad * cos(phi); + fout[1] = BRad * sin(phi); fout[2] = BZ; } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -519,7 +469,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -541,12 +491,13 @@ create_ctx(void) double nuFrac = 1.0; double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); - double nuElc = nuFrac * logLambdaElc * pow(eV, 4.) * n0 / - (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); + double nuElc = + nuFrac * logLambdaElc * pow(eV, 4.) * n0 / + (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); double nuIon = nuFrac * logLambdaIon * pow(eV, 4.) * n0 / (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti0, 3. / 2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); // Thermal speeds. double vti = sqrt(Ti0 / mi); @@ -611,13 +562,14 @@ create_ctx(void) double mu_max_ion = mi * pow(3. * vti, 2.) / (2. * B_p); int Nz = 32; int Nvpar = 32; // Number of cells in the paralell velocity direction 96 - int Nmu = 48; // Number of cells in the mu direction 192 + int Nmu = 48; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 4.0e-8; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -649,7 +601,7 @@ create_ctx(void) .c_s = c_s, .omega_ci = omega_ci, .rho_s = rho_s, - .kperp = kperp, + .kperp = kperp, .RatZeq0 = RatZeq0, .Z_min = Z_min, .Z_max = Z_max, @@ -696,18 +648,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -718,10 +671,12 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dgeqdsk_file, sizeof(params->geqdsk_file)); @@ -442,239 +415,249 @@ create_asdex_lsn_gk_block_geom(void *ctx) // Theta limits are actually set internally by the code. double theta_min = -1.0, theta_max = 1.0; - double psi_sep = params->psi_sep; // Psi at the separatrix. + double psi_sep = params->psi_sep; // Psi at the separatrix. double psi_axis = params->psi_axis; // Psi at the magnetic axis. double psi_min_core = params->psi_min_core; // Minimum psi the core. - double psi_max_sol = params->psi_max_sol ; // Maximum psi the SOL. - double psi_min_pf = params->psi_min_pf ; // Minimum psi the private flux. + double psi_max_sol = params->psi_max_sol; // Maximum psi the SOL. + double psi_min_pf = params->psi_min_pf; // Minimum psi the private flux. // Number of cells. - int Npsi_sol = params->Npsi_sol ; - int Npsi_pf = params->Npsi_pf ; - int Npsi_core = params->Npsi_core ; + int Npsi_sol = params->Npsi_sol; + int Npsi_pf = params->Npsi_pf; + int Npsi_core = params->Npsi_core; int Ntheta_divertor = params->Ntheta_divertor; - int Ntheta_sol = params->Ntheta_sol ; + int Ntheta_sol = params->Ntheta_sol; // Block 0: outer private flux (PF) region. - gkyl_gk_block_geom_set_block(bgeom, 0, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_min_pf, theta_min }, - .upper = { psi_sep, theta_max }, - .cells = { Npsi_pf, Ntheta_divertor }, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_R, - .rleft = 1.1, - .rright = 1.7, - .rmin = 1.1, - .rmax = 1.7, - .zmin = -1.3, - .zmax = -0.9, - .zmin_left = -1.18, - .zmax_right = -1.18, - .plate_spec = true, - .plate_func_lower = divertor_plate_func_out, - .plate_func_upper = divertor_plate_func_in, - } - }, - - .connections[0] = { // x-direction. - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - { .bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE }, - }, - .connections[1] = { // z-direction. - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // Physical boundary. - { .bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 0, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_min_pf, theta_min}, + .upper = {psi_sep, theta_max}, + .cells = {Npsi_pf, Ntheta_divertor}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_R, + .rleft = 1.1, + .rright = 1.7, + .rmin = 1.1, + .rmax = 1.7, + .zmin = -1.3, + .zmax = -0.9, + .zmin_left = -1.18, + .zmax_right = -1.18, + .plate_spec = true, + .plate_func_lower = divertor_plate_func_out, + .plate_func_upper = divertor_plate_func_in}}, + + .connections[0] = + {// x-direction. + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // Physical boundary. + {.bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// z-direction. + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // Physical boundary. + {.bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // Block 1: lower outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 1, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_sep, theta_min }, - .upper = { psi_max_sol, theta_max }, - .cells = { Npsi_sol, Ntheta_divertor }, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO, - .rclose = 2.5, - .rleft = 0.8, - .rright = 2.5, - .rmin = 0.8, - .rmax = 2.5, - .zmin = -1.3, - .zmax = 1.0, - .plate_spec = true, - .plate_func_lower = divertor_plate_func_out, - .plate_func_upper = divertor_plate_func_in, - } - }, - - .connections[0] = { // x-direction. - { .bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 1, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - }, - .connections[1] = { // z-direction. - { .bid = 1, .dir = 1, .edge = GKYL_PHYSICAL}, // Physical boundary. - { .bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 1, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_sep, theta_min}, + .upper = {psi_max_sol, theta_max}, + .cells = {Npsi_sol, Ntheta_divertor}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO, + .rclose = 2.5, + .rleft = 0.8, + .rright = 2.5, + .rmin = 0.8, + .rmax = 2.5, + .zmin = -1.3, + .zmax = 1.0, + .plate_spec = true, + .plate_func_lower = divertor_plate_func_out, + .plate_func_upper = divertor_plate_func_in}}, + + .connections[0] = + { + // x-direction. + {.bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 1, .dir = 0, .edge = GKYL_PHYSICAL} // Physical boundary. + }, + .connections[1] = + {// z-direction. + {.bid = 1, .dir = 1, .edge = GKYL_PHYSICAL}, // Physical boundary. + {.bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // Block 2: mid SOL. - gkyl_gk_block_geom_set_block(bgeom, 2, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_sep, theta_min }, - .upper = { psi_max_sol, theta_max }, - .cells = { Npsi_sol, Ntheta_sol }, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID, - .rclose = 2.5, - .rleft = 0.8, - .rright = 2.5, - .rmin = 0.8, - .rmax = 2.5, - .zmin = -1.3, - .zmax = 1.0, - .plate_spec = true, - .plate_func_lower = divertor_plate_func_out, - .plate_func_upper = divertor_plate_func_in, - } - }, - - .connections[0] = { // x-direction. - { .bid = 5, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 2, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - }, - .connections[1] = { // z-direction. - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 3, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 2, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_sep, theta_min}, + .upper = {psi_max_sol, theta_max}, + .cells = {Npsi_sol, Ntheta_sol}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID, + .rclose = 2.5, + .rleft = 0.8, + .rright = 2.5, + .rmin = 0.8, + .rmax = 2.5, + .zmin = -1.3, + .zmax = 1.0, + .plate_spec = true, + .plate_func_lower = divertor_plate_func_out, + .plate_func_upper = divertor_plate_func_in}}, + + .connections[0] = + { + // x-direction. + {.bid = 5, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 0, .edge = GKYL_PHYSICAL} // Physical boundary. + }, + .connections[1] = + {// z-direction. + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // Block 3: lower inner SOL. - gkyl_gk_block_geom_set_block(bgeom, 3, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_sep, theta_min }, - .upper = { psi_max_sol, theta_max }, - .cells = { Npsi_sol, Ntheta_divertor }, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP, - .rclose = 2.5, - .rleft = 0.8, - .rright = 2.5, - .rmin = 0.8, - .rmax = 2.5, - .zmin = -1.3, - .zmax = 1.0, - .plate_spec = true, - .plate_func_lower = divertor_plate_func_out, - .plate_func_upper = divertor_plate_func_in, - } - }, - - .connections[0] = { // x-direction. - { .bid = 4, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 3, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - }, - .connections[1] = { // z-direction. - { .bid = 2, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 3, .dir = 1, .edge = GKYL_PHYSICAL}, // Physical boundary. - } - } + gkyl_gk_block_geom_set_block( + bgeom, 3, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_sep, theta_min}, + .upper = {psi_max_sol, theta_max}, + .cells = {Npsi_sol, Ntheta_divertor}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP, + .rclose = 2.5, + .rleft = 0.8, + .rright = 2.5, + .rmin = 0.8, + .rmax = 2.5, + .zmin = -1.3, + .zmax = 1.0, + .plate_spec = true, + .plate_func_lower = divertor_plate_func_out, + .plate_func_upper = divertor_plate_func_in}}, + + .connections[0] = + { + // x-direction. + {.bid = 4, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 0, .edge = GKYL_PHYSICAL} // Physical boundary. + }, + .connections[1] = + { + // z-direction. + {.bid = 2, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 1, .edge = GKYL_PHYSICAL} // Physical boundary. + }} ); // Block 4: inner private flux (PF) region. - gkyl_gk_block_geom_set_block(bgeom, 4, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_min_pf, theta_min }, - .upper = { psi_sep, theta_max }, - .cells = { Npsi_pf, Ntheta_divertor }, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_L, - .rleft = 1.1, - .rright = 1.7, - .rmin = 1.1, - .rmax = 1.7, - .zmin = -1.3, - .zmax = -0.9, - .zmin_left = -1.18, - .zmax_right = -1.18, - .plate_spec = true, - .plate_func_lower = divertor_plate_func_out, - .plate_func_upper = divertor_plate_func_in, - } - }, - - .connections[0] = { // x-direction. - { .bid = 4, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - { .bid = 3, .dir = 0, .edge = GKYL_LOWER_POSITIVE }, - }, - .connections[1] = { // z-direction. - { .bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, // Physical boundary. - { .bid = 4, .dir = 1, .edge = GKYL_PHYSICAL}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 4, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_min_pf, theta_min}, + .upper = {psi_sep, theta_max}, + .cells = {Npsi_pf, Ntheta_divertor}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_L, + .rleft = 1.1, + .rright = 1.7, + .rmin = 1.1, + .rmax = 1.7, + .zmin = -1.3, + .zmax = -0.9, + .zmin_left = -1.18, + .zmax_right = -1.18, + .plate_spec = true, + .plate_func_lower = divertor_plate_func_out, + .plate_func_upper = divertor_plate_func_in}}, + + .connections[0] = + {// x-direction. + {.bid = 4, .dir = 0, .edge = GKYL_PHYSICAL}, // Physical boundary. + {.bid = 3, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// z-direction. + {.bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, // Physical boundary. + {.bid = 4, .dir = 1, .edge = GKYL_PHYSICAL} + }} ); // Block 5: core region. - gkyl_gk_block_geom_set_block(bgeom, 5, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_min_core, theta_min }, - .upper = { psi_sep, theta_max }, - .cells = { Npsi_core, Ntheta_sol }, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_CORE, - .rclose = 2.0, - .rleft = 0.8, - .rright = 2.5, - .rmin = 0.8, - .rmax = 2.5, - .zmin = -1.3, - .zmax = 1.0, - } - }, - - .connections[0] = { // x-direction. - { .bid = 5, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE }, - }, - .connections[1] = { // z-direction. - { .bid = 5, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 5, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 5, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_min_core, theta_min}, + .upper = {psi_sep, theta_max}, + .cells = {Npsi_core, Ntheta_sol}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_CORE, + .rclose = 2.0, + .rleft = 0.8, + .rright = 2.5, + .rmin = 0.8, + .rmax = 2.5, + .zmin = -1.3, + .zmax = 1.0}}, + + .connections[0] = + {// x-direction. + {.bid = 5, .dir = 0, .edge = GKYL_PHYSICAL}, // Physical boundary. + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// z-direction. + {.bid = 5, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 5, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); return bgeom; } // Velocity space mappings. -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_asdex_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -682,18 +665,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_asdex_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -701,19 +685,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -double -init_profile(double psi, double f_min, double f_max, void *ctx) +double init_profile(double psi, double f_min, double f_max, void *ctx) { // Profile in D. Michels, et al. Phys. Plasmas 29, 032307 (2022) eqn 17: struct gk_asdex_ctx *params = ctx; @@ -726,24 +710,24 @@ init_profile(double psi, double f_min, double f_max, void *ctx) double rho_max = rho_psi(psi_max, psi_axis, psi_sep); double rho = rho_psi(psi, psi_axis, psi_sep); - double c1 = (f_max-f_min)/2.0; - double c2 = M_PI/(rho_max-rho_min); - double c3 = M_PI/2 - c2*rho_min; - double c4 = (f_max+f_min)/2.0; + double c1 = (f_max - f_min) / 2.0; + double c2 = M_PI / (rho_max - rho_min); + double c3 = M_PI / 2 - c2 * rho_min; + double c4 = (f_max + f_min) / 2.0; double f = -1.0; - if (rho <= rho_min) + if (rho <= rho_min) { f = f_max; - else if (rho_min < rho && rho <= rho_max) - f = c1*sin(c2*rho + c3) + c4; - else + } else if (rho_min < rho && rho <= rho_max) { + f = c1 * sin(c2 * rho + c3) + c4; + } else { f = f_min; + } return f; } -void -init_dens(double t, const double *xn, double* restrict fout, void *ctx) +void init_dens(double t, const double *xn, double *restrict fout, void *ctx) { struct gk_asdex_ctx *params = ctx; double psi = xn[0], theta = xn[1]; @@ -756,8 +740,7 @@ init_dens(double t, const double *xn, double* restrict fout, void *ctx) fout[0] = init_profile(psi, den_min, den_max, ctx); } -void -init_temp_elc(double t, const double *xn, double* restrict fout, void *ctx) +void init_temp_elc(double t, const double *xn, double *restrict fout, void *ctx) { struct gk_asdex_ctx *params = ctx; double psi = xn[0], theta = xn[1]; @@ -765,14 +748,13 @@ init_temp_elc(double t, const double *xn, double* restrict fout, void *ctx) // Mimics the SOL profile in D. Michels, et al. Phys. Plasmas 29, 032307 // (2022), figure 8 experimental. double eV = GKYL_ELEMENTARY_CHARGE; // Elementary charge. - double T_min = 17.0*eV; - double T_max = 300.0*eV; + double T_min = 17.0 * eV; + double T_max = 300.0 * eV; fout[0] = init_profile(psi, T_min, T_max, ctx); } -void -init_temp_ion(double t, const double *xn, double* restrict fout, void *ctx) +void init_temp_ion(double t, const double *xn, double *restrict fout, void *ctx) { struct gk_asdex_ctx *params = ctx; double psi = xn[0], theta = xn[1]; @@ -780,20 +762,20 @@ init_temp_ion(double t, const double *xn, double* restrict fout, void *ctx) // Mimics the SOL profile in D. Michels, et al. Phys. Plasmas 29, 032307 // (2022), figure 7 GRILLIX w/ neutrals. double eV = GKYL_ELEMENTARY_CHARGE; // Elementary charge. - double T_min = 17.0*eV; - double T_max = 300.0*eV; + double T_min = 17.0 * eV; + double T_max = 300.0 * eV; fout[0] = init_profile(psi, T_min, T_max, ctx); } -void -init_upar(double t, const double *xn, double* restrict fout, void *ctx) +void init_upar(double t, const double *xn, double *restrict fout, void *ctx) { fout[0] = 0.0; } -void -init_source_dens(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_source_dens( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_asdex_ctx *params = ctx; double x = xn[0], z = xn[1]; @@ -803,21 +785,24 @@ init_source_dens(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRIC double ndot_src = params->ndot_src; double source_floor = 1e-10; - if (x < psi_src + 3*lambda_src) + if (x < psi_src + 3 * lambda_src) { source_floor = 1e-2; + } - double src_prof = exp(-pow(x-psi_src,2)/(2*pow(lambda_src,2))); + double src_prof = exp(-pow(x - psi_src, 2) / (2 * pow(lambda_src, 2))); fout[0] = ndot_src * fmax(src_prof, source_floor); } -void -init_source_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_source_upar( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -init_source_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_source_temp_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_asdex_ctx *params = ctx; double x = xn[0], z = xn[1]; @@ -827,14 +812,16 @@ init_source_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RES double Te_src = params->Te_src; double eV = GKYL_ELEMENTARY_CHARGE; - if (x < psi_src + 3*lambda_src) + if (x < psi_src + 3 * lambda_src) { fout[0] = Te_src; - else - fout[0] = 2.0*eV; + } else { + fout[0] = 2.0 * eV; + } } -void -init_source_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_source_temp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_asdex_ctx *params = ctx; double x = xn[0], z = xn[1]; @@ -844,67 +831,70 @@ init_source_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RES double Ti_src = params->Ti_src; double eV = GKYL_ELEMENTARY_CHARGE; - if (x < psi_src + 3*lambda_src) + if (x < psi_src + 3 * lambda_src) { fout[0] = Ti_src; - else - fout[0] = 2.0*eV; + } else { + fout[0] = 2.0 * eV; + } } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; fout[0] = 0.3; // Diffusivity [m^2/s]. } -struct gk_asdex_ctx -create_ctx(void) +struct gk_asdex_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; // Permittivity of free space. double eV = GKYL_ELEMENTARY_CHARGE; // Elementary charge. - double mi = 2.014*GKYL_PROTON_MASS; // Ion mass. + double mi = 2.014 * GKYL_PROTON_MASS; // Ion mass. double me = GKYL_ELECTRON_MASS; // Electron mass. double qi = eV; // Ion charge. double qe = -eV; // Electron charge. - double Te = 150.0*eV; // Electron temperature. - double Ti = 150.0*eV; // Ion temperature. - double B0 = (1.937854e+00+3.937710e+00)/2.0; // B field amplitude. + double Te = 150.0 * eV; // Electron temperature. + double Ti = 150.0 * eV; // Ion temperature. + double B0 = (1.937854e+00 + 3.937710e+00) / 2.0; // B field amplitude. double n0 = 1.0e19; // Particle density. // Derived parameters. - double vt_ion = sqrt(Ti/mi); - double vt_elc = sqrt(Te/me); - double c_s = sqrt(Te/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; + double vt_ion = sqrt(Ti / mi); + double vt_elc = sqrt(Te / me); + double c_s = sqrt(Te / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // Collision parameters. - double nu_frac = 1.0; - double logLambda_elc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nu_elc = nu_frac*logLambda_elc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*pow(eps0,2)*sqrt(me)*pow(Te,3.0/2.0)); + double nu_frac = 1.0; + double logLambda_elc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nu_elc = + nu_frac * logLambda_elc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * pow(eps0, 2) * sqrt(me) * pow(Te, 3.0 / 2.0)); - double logLambda_ion = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nu_ion = nu_frac*logLambda_ion*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*pow(eps0,2)*sqrt(mi)*pow(Ti,3.0/2.0)); + double logLambda_ion = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nu_ion = nu_frac * logLambda_ion * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * pow(eps0, 2) * sqrt(mi) * pow(Ti, 3.0 / 2.0)); // Location of the numerical equilibrium. char geqdsk_file[128] = "gyrokinetic/data/eqdsk/asdex.geqdsk"; // Position space parameters. double num_blocks = 6; - double R_axis = (1.61640+1.70022)/2.0; // R of the magnetic axis. - double Z_axis = (-0.0013+0.1001)/2.0; // Z of the magnetic axis. + double R_axis = (1.61640 + 1.70022) / 2.0; // R of the magnetic axis. + double Z_axis = (-0.0013 + 0.1001) / 2.0; // Z of the magnetic axis. double R_sep_OZA = 2.1389435; // Separatrix major at outboard Z axis. double R_sep_omp = 2.1334876; // Separatrix major at the OMP. double psi_axis = -9.276977e-02; // Psi at the magnetic axis. // Get the separatrix psi. - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .rz_poly_order = 2, - .flux_poly_order = 1, + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .rz_poly_order = 2, + .flux_poly_order = 1 }; // Copy eqdsk file into efit_inp. memcpy(efit_inp.filepath, geqdsk_file, sizeof(geqdsk_file)); @@ -917,7 +907,7 @@ create_ctx(void) double rho_max_sol = 1.04; double psi_min_core = psi_rho(rho_min_core, psi_axis, psi_sep); double psi_max_sol = psi_rho(rho_max_sol, psi_axis, psi_sep); -// double psi_min_pf = 0.1446524024; + // double psi_min_pf = 0.1446524024; double psi_min_pf = 0.14775; // Number of cells. @@ -931,93 +921,96 @@ create_ctx(void) // Adjust psi_min_core to ensure that dx_core = dx_sol. // we need ((psi_sep-shift_fac_core * psi_min_core)/Npsi_core) / ((psi_max_sol-psi_sep)/Npsi_sol) = 1 - double shift_fac_core = (-Npsi_core*psi_max_sol + Npsi_core*psi_sep + Npsi_sol*psi_sep)/(Npsi_sol*psi_min_core); + double shift_fac_core = (-Npsi_core * psi_max_sol + Npsi_core * psi_sep + Npsi_sol * psi_sep) / + (Npsi_sol * psi_min_core); psi_min_core *= shift_fac_core; - double shift_fac_pf = (Npsi_pf*psi_min_core + Npsi_core*psi_sep - Npsi_pf*psi_sep)/(Npsi_core*psi_min_pf); + double shift_fac_pf = + (Npsi_pf * psi_min_core + Npsi_core * psi_sep - Npsi_pf * psi_sep) / (Npsi_core * psi_min_pf); psi_min_pf *= shift_fac_pf; - printf(" shift_fac_core = %9e\n",shift_fac_core); - printf(" shift_fac_pf = %9e\n",shift_fac_pf); + printf(" shift_fac_core = %9e\n", shift_fac_core); + printf(" shift_fac_pf = %9e\n", shift_fac_pf); double Lx_core = psi_sep - psi_min_core; // z location of the X-point on psi=psi_min. double z_xpt_psi_sep_lo = -2.8469; - double z_xpt_psi_sep_up = 2.8486; + double z_xpt_psi_sep_up = 2.8486; // Source parameters. double psi_src = psi_min_core; double lambda_src = psi_rho(0.915, psi_axis, psi_sep) - psi_min_core; double Lc_src = 67.0; // Connection length in near SOL. double n_sep = 0.75e19; - double Te_sep = 70.0*eV; - double cs_sep = sqrt(Te_sep/mi); - double ndot_src = 2.0*n_sep*cs_sep/Lc_src; - double Te_src = 2.*Te; - double Ti_src = 2.*Ti; + double Te_sep = 70.0 * eV; + double cs_sep = sqrt(Te_sep / mi); + double ndot_src = 2.0 * n_sep * cs_sep / Lc_src; + double Te_src = 2. * Te; + double Ti_src = 2. * Ti; // Physical velocity space limits - double vpar_max_elc = 6.0*vt_elc; - double mu_max_elc = me*pow(4.0*vt_elc,2)/(2.0*B0); + double vpar_max_elc = 6.0 * vt_elc; + double mu_max_elc = me * pow(4.0 * vt_elc, 2) / (2.0 * B0); - double vpar_max_ion = 6.0*vt_ion; - double mu_max_ion = mi*pow(4.0*vt_ion,2)/(2.0*B0); + double vpar_max_ion = 6.0 * vt_ion; + double mu_max_ion = mi * pow(4.0 * vt_ion, 2) / (2.0 * B0); // Computational velocity space limits. - double vpar_min_ion_c = -1.0/sqrt(2.0); - double vpar_max_ion_c = 1.0/sqrt(2.0); + double vpar_min_ion_c = -1.0 / sqrt(2.0); + double vpar_max_ion_c = 1.0 / sqrt(2.0); double mu_min_ion_c = 0.; double mu_max_ion_c = 1.; // Computational velocity space limits. - double vpar_min_elc_c = -1.0/sqrt(2.0); - double vpar_max_elc_c = 1.0/sqrt(2.0); + double vpar_min_elc_c = -1.0 / sqrt(2.0); + double vpar_max_elc_c = 1.0 / sqrt(2.0); double mu_min_elc_c = 0.; double mu_max_elc_c = 1.; // Longest radial chord in the core in m. This is the one touching the x-point, calculated graphically. - double Lx_core_m_max = sqrt(pow(1.5667-1.4433,2)+pow(-0.5603-(-0.9245),2)); + double Lx_core_m_max = sqrt(pow(1.5667 - 1.4433, 2) + pow(-0.5603 - (-0.9245), 2)); // Longest radial core in the sol in m. This is the one touching the x-point and the HFS wall, calculated graphically. - double Lx_sol_m_max = sqrt(pow(1.1511-1.4433,2)+pow(-0.5513-(-0.9245),2)); - // rho_s with 120 eV is about 5.4e-4 m. - - printf(" X-point @ (R,Z) = (%.9e,%9e)\n",Rxpt,Zxpt); - printf(" psi_axis = %.13e\n",psi_axis); - printf(" psi_sep = %.13e\n",psi_sep); - printf(" psi_min_core = %.13e\n",psi_min_core); - printf(" psi_max_sol = %.13e\n",psi_max_sol); - printf(" psi_min_pf = %.13e\n",psi_min_pf); - printf(" Npsi_sol = %d\n",Npsi_sol ); - printf(" Npsi_pf = %d\n",Npsi_pf ); - printf(" Npsi_core = %d\n",Npsi_core ); - printf(" Ntheta_divertor = %d\n",Ntheta_divertor); - printf(" Ntheta_sol = %d\n",Ntheta_sol ); + double Lx_sol_m_max = sqrt(pow(1.1511 - 1.4433, 2) + pow(-0.5513 - (-0.9245), 2)); + // rho_s with 120 eV is about 5.4e-4 m. + + printf(" X-point @ (R,Z) = (%.9e,%9e)\n", Rxpt, Zxpt); + printf(" psi_axis = %.13e\n", psi_axis); + printf(" psi_sep = %.13e\n", psi_sep); + printf(" psi_min_core = %.13e\n", psi_min_core); + printf(" psi_max_sol = %.13e\n", psi_max_sol); + printf(" psi_min_pf = %.13e\n", psi_min_pf); + printf(" Npsi_sol = %d\n", Npsi_sol); + printf(" Npsi_pf = %d\n", Npsi_pf); + printf(" Npsi_core = %d\n", Npsi_core); + printf(" Ntheta_divertor = %d\n", Ntheta_divertor); + printf(" Ntheta_sol = %d\n", Ntheta_sol); double t_end = 1.0e-7; double num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_asdex_ctx ctx = { .cdim = cdim, .vdim = vdim, - .charge_elc = qe, - .charge_ion = qi, - .mass_elc = me, + .charge_elc = qe, + .charge_ion = qi, + .mass_elc = me, .mass_ion = mi, - .Te = Te, - .Ti = Ti, - .c_s = c_s, - .nu_elc = nu_elc, - .nu_ion = nu_ion, - .B0 = B0, - .n0 = n0, + .Te = Te, + .Ti = Ti, + .c_s = c_s, + .nu_elc = nu_elc, + .nu_ion = nu_ion, + .B0 = B0, + .n0 = n0, .num_blocks = num_blocks, .psi_axis = psi_axis, .psi_sep = psi_sep, .psi_min_core = psi_min_core, .psi_max_sol = psi_max_sol, .psi_min_pf = psi_min_pf, - .Lx_core = Lx_core, + .Lx_core = Lx_core, .z_xpt_psi_sep_lo = z_xpt_psi_sep_lo, .z_xpt_psi_sep_up = z_xpt_psi_sep_up, .lambda_src = lambda_src, @@ -1026,10 +1019,10 @@ create_ctx(void) .Te_src = Te_src, .Ti_src = Ti_src, // Physical velocity space limits - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, // Computational velocity space limits .vpar_min_elc_c = vpar_min_elc_c, .vpar_max_elc_c = vpar_max_elc_c, @@ -1039,20 +1032,20 @@ create_ctx(void) .vpar_max_ion_c = vpar_max_ion_c, .mu_min_ion_c = mu_min_ion_c, .mu_max_ion_c = mu_max_ion_c, - .Npsi_sol = Npsi_sol , - .Npsi_pf = Npsi_pf , - .Npsi_core = Npsi_core , + .Npsi_sol = Npsi_sol, + .Npsi_pf = Npsi_pf, + .Npsi_core = Npsi_core, .Ntheta_divertor = Ntheta_divertor, - .Ntheta_sol = Ntheta_sol , + .Ntheta_sol = Ntheta_sol, .Nvpar = Nvpar, .Nmu = Nmu, .cells_v = {Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; // Copy eqdsk file into ctx. @@ -1060,8 +1053,7 @@ create_ctx(void) return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -1080,27 +1072,27 @@ main(int argc, char **argv) struct gkyl_comm *comm = gkyl_gyrokinetic_comms_new(app_args.use_mpi, app_args.use_gpu, stderr); struct gk_asdex_ctx ctx = create_ctx(); // Context for init functions. - + // Construct block geometry struct gkyl_gk_block_geom *bgeom = create_asdex_lsn_gk_block_geom(&ctx); int cells_v[ctx.vdim]; - for (int d=0; dcdim = ctx.cdim; app_inp->poly_order = 1; app_inp->basis_type = app_args.basis_type; @@ -1390,23 +1374,21 @@ main(int argc, char **argv) app_inp->field = field; app_inp->comm = comm; - // Set app output name from the executable name (argv[0]). snprintf(app_inp->name, sizeof(app_inp->name), "%s", app_args.app_name); struct gkyl_gyrokinetic_run_inp run_inp = { .app_type = GKYL_GK_MULTIB, .multib_app_inp = *app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = app_args.num_steps, - }, + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = app_args.num_steps} }; gkyl_gyrokinetic_run_simulation(&run_inp); @@ -1416,9 +1398,10 @@ main(int argc, char **argv) gkyl_free(app_inp); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif - + return 0; } diff --git a/gyrokinetic/creg/rt_gk_multib_asdex_solonly_3x2v_p1.c b/gyrokinetic/creg/rt_gk_multib_asdex_solonly_3x2v_p1.c index 01a4d91a74..271ec1bd05 100644 --- a/gyrokinetic/creg/rt_gk_multib_asdex_solonly_3x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_multib_asdex_solonly_3x2v_p1.c @@ -15,9 +15,9 @@ struct gk_app_ctx { int num_species; double me, qe, mi, qi; // Initial conditions. - double den_floor ; - double Te_floor ; - double Ti_floor ; + double den_floor; + double Te_floor; + double Ti_floor; double n0, Te0, Ti0, B0; // Reference parameters. // Collision parameters double nuFrac, nuElc, nuIon; @@ -44,23 +44,22 @@ struct gk_app_ctx { double t_end, write_phase_freq; int num_frames, int_diag_calc_num, num_failures_max; double dt_failure_tol; - }; double rho_psi(double psi, double psi_axis, double psi_sep) { // Normalized radial coordinate. - return sqrt((psi-psi_axis) / (psi_sep - psi_axis)); + return sqrt((psi - psi_axis) / (psi_sep - psi_axis)); } double psi_rho(double rho, double psi_axis, double psi_sep) { // Poloidal flux given the normalized radial coordinate. - return pow(rho,2) * (psi_sep - psi_axis) + psi_axis; + return pow(rho, 2) * (psi_sep - psi_axis) + psi_axis; } // Density initial condition (like AUG exp profile) -void eval_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; @@ -71,20 +70,21 @@ void eval_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI double rho = rho_psi(x, psi_axis, psi_sep); - double profile = (-2.17282515*pow(rho, 3.0) + 6.80801422*pow(rho, 2.0) - 7.12279432*rho + 2.48870613) * 1.0e22; + double profile = + (-2.17282515 * pow(rho, 3.0) + 6.80801422 * pow(rho, 2.0) - 7.12279432 * rho + 2.48870613) * + 1.0e22; fout[0] = fmax(profile, den_floor); } // Flow initial condition -void -eval_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } // Electron temperature initial conditions -void eval_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; @@ -96,17 +96,17 @@ void eval_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTR double rho = rho_psi(x, psi_axis, psi_sep); - double profile = (-140.97018851*rho + 156.25649838) * eV; + double profile = (-140.97018851 * rho + 156.25649838) * eV; // Multiply by a function that smoothly drops the temperature by 2X towards // the divertor plates. - profile *= 0.5+0.5*exp(-0.25*pow(z/(M_PI/1.35),10)); + profile *= 0.5 + 0.5 * exp(-0.25 * pow(z / (M_PI / 1.35), 10)); fout[0] = fmax(profile, Te_floor); } // Ion temperature initial conditions -void eval_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; @@ -118,57 +118,57 @@ void eval_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTR double rho = rho_psi(x, psi_axis, psi_sep); - double profile = (125.6039 * exp(-206.2917*(rho-1.0)) + 20.9689) * eV; + double profile = (125.6039 * exp(-206.2917 * (rho - 1.0)) + 20.9689) * eV; // Multiply by a function that smoothly drops the temperature by 5X towards // the divertor plates. - profile *= 0.5+0.5*exp(-0.25*pow(z/(M_PI/1.35),10)); + profile *= 0.5 + 0.5 * exp(-0.25 * pow(z / (M_PI / 1.35), 10)); fout[0] = fmax(profile, Ti_floor); } // Taken from rt gk d3d 3x2c, is this the non uniform v grid mapping? -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; double mu_max_elc = app->mu_max_elc; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; double mu_max_ion = app->mu_max_ion; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } - -struct gkyl_gk_block_geom* -create_gk_block_geom(void *ctx) +struct gkyl_gk_block_geom *create_gk_block_geom(void *ctx) { struct gk_app_ctx *params = ctx; - struct gkyl_gk_block_geom *bgeom = gkyl_gk_block_geom_new(3,3); + struct gkyl_gk_block_geom *bgeom = gkyl_gk_block_geom_new(3, 3); /* Block layout and coordinates. @@ -204,150 +204,160 @@ create_gk_block_geom(void *ctx) symbol such as o,x,%, or % are instead connected to the other edge with the same symbol. Edges that do not coincide with another edge are a physical boundary. - */ + */ - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "./gyrokinetic/data/eqdsk/asdex_33292_3.800.eqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "./gyrokinetic/data/eqdsk/asdex_33292_3.800.eqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1 }; // Theta limits are actually set internally by the code. double theta_min = -1.0, theta_max = 1.0; - double psi_sep = params->psi_sep; // Psi at the separatrix. + double psi_sep = params->psi_sep; // Psi at the separatrix. double psi_axis = params->psi_axis; // Psi at the magnetic axis. // Number of cells. - int Npsi_sol = 12; - int Npsi_pf = 12; + int Npsi_sol = 12; + int Npsi_pf = 12; int Ntheta_divertor = 2; - int Ntheta_sol = 8; + int Ntheta_sol = 8; int nalpha = 8; // Block 0: lower outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 0, &(struct gkyl_gk_block_geom_info) { - .lower = { params->x_min, params->y_min, params->z_min }, - .upper = { params->x_max, params->y_max, params->z_max }, - .cells = { Npsi_sol, nalpha, Ntheta_divertor}, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO, - .rclose = 2.5, // Closest R to region of interest. - .rright = 2.5, // Closest R to outboard SOL. - .rleft = 0.7, // Closest R to inboard SOL. - .rmax = 2.5, // Largest R in machine. - .rmin = 0.7, // Smallest R in machine. - .zmin = -1.3, // Lower Z boundary. - .zmax = 1.0, // Upper Z boundary. - .zmin_left = -1.0, // Z of inboard divertor plate. - .zmin_right = -1.0, // Z of outboard divertor plate. - } - }, - - .connections[0] = { // x-direction. - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, - }, - .connections[1] = { // y-direction. - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, - }, - .connections[2] = { // z-direction. - { .bid = 0, .dir = 2, .edge = GKYL_PHYSICAL}, - { .bid = 1, .dir = 2, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 0, + &(struct gkyl_gk_block_geom_info + ){.lower = {params->x_min, params->y_min, params->z_min}, + .upper = {params->x_max, params->y_max, params->z_max}, + .cells = {Npsi_sol, nalpha, Ntheta_divertor}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = + (struct gkyl_tok_geo_grid_inp){ + .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO, + .rclose = 2.5, // Closest R to region of interest. + .rright = 2.5, // Closest R to outboard SOL. + .rleft = 0.7, // Closest R to inboard SOL. + .rmax = 2.5, // Largest R in machine. + .rmin = 0.7, // Smallest R in machine. + .zmin = -1.3, // Lower Z boundary. + .zmax = 1.0, // Upper Z boundary. + .zmin_left = -1.0, // Z of inboard divertor plate. + .zmin_right = -1.0 // Z of outboard divertor plate. + }}, + + .connections[0] = + {// x-direction. + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} + }, + .connections[1] = + {// y-direction. + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }, + .connections[2] = + {// z-direction. + {.bid = 0, .dir = 2, .edge = GKYL_PHYSICAL}, + {.bid = 1, .dir = 2, .edge = GKYL_LOWER_POSITIVE} + }} ); // Block 1: mid SOL. - gkyl_gk_block_geom_set_block(bgeom, 1, &(struct gkyl_gk_block_geom_info) { - .lower = { params->x_min, params->y_min, params->z_min }, - .upper = { params->x_max, params->y_max, params->z_max }, - .cells = { Npsi_sol, nalpha, Ntheta_sol }, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID, - .rclose = 2.5, // Closest R to region of interest. - .rright = 2.5, // Closest R to outboard SOL. - .rleft = 0.7, // Closest R to inboard SOL. - .rmax = 2.5, // Largest R in machine. - .rmin = 0.7, // Smallest R in machine. - .zmin = -1.3, // Lower Z boundary. - .zmax = 1.0, // Upper Z boundary. - .zmin_left = -1.0, // Z of inboard divertor plate. - .zmin_right = -1.0, // Z of outboard divertor plate. - } - }, - - .connections[0] = { // x-direction. - { .bid = 1, .dir = 0, .edge = GKYL_PHYSICAL}, - { .bid = 1, .dir = 0, .edge = GKYL_PHYSICAL }, - }, - .connections[1] = { // y-direction. - { .bid = 1, .dir = 1, .edge = GKYL_PHYSICAL}, - { .bid = 1, .dir = 1, .edge = GKYL_PHYSICAL }, - }, - .connections[2] = { // z-direction. - { .bid = 0, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 2, .dir = 2, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 1, + &(struct gkyl_gk_block_geom_info + ){.lower = {params->x_min, params->y_min, params->z_min}, + .upper = {params->x_max, params->y_max, params->z_max}, + .cells = {Npsi_sol, nalpha, Ntheta_sol}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = + (struct gkyl_tok_geo_grid_inp){ + .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID, + .rclose = 2.5, // Closest R to region of interest. + .rright = 2.5, // Closest R to outboard SOL. + .rleft = 0.7, // Closest R to inboard SOL. + .rmax = 2.5, // Largest R in machine. + .rmin = 0.7, // Smallest R in machine. + .zmin = -1.3, // Lower Z boundary. + .zmax = 1.0, // Upper Z boundary. + .zmin_left = -1.0, // Z of inboard divertor plate. + .zmin_right = -1.0 // Z of outboard divertor plate. + }}, + + .connections[0] = + {// x-direction. + {.bid = 1, .dir = 0, .edge = GKYL_PHYSICAL}, + {.bid = 1, .dir = 0, .edge = GKYL_PHYSICAL} + }, + .connections[1] = + {// y-direction. + {.bid = 1, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 1, .dir = 1, .edge = GKYL_PHYSICAL} + }, + .connections[2] = + {// z-direction. + {.bid = 0, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 2, .edge = GKYL_LOWER_POSITIVE} + }} ); // Block 2: lower inner SOL. - gkyl_gk_block_geom_set_block(bgeom, 2, &(struct gkyl_gk_block_geom_info) { - .lower = { params->x_min, params->y_min, params->z_min }, - .upper = { params->x_max, params->y_max, params->z_max }, - .cells = { Npsi_sol, nalpha, Ntheta_divertor}, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP, - .rclose = 2.5, // Closest R to region of interest. - .rright = 2.5, // Closest R to outboard SOL. - .rleft = 0.7, // Closest R to inboard SOL. - .rmax = 2.5, // Largest R in machine. - .rmin = 0.7, // Smallest R in machine. - .zmin = -1.3, // Lower Z boundary. - .zmax = 1.0, // Upper Z boundary. - .zmin_left = -1.0, // Z of inboard divertor plate. - .zmin_right = -1.0, // Z of outboard divertor plate. - } - }, - - .connections[0] = { // x-direction. - { .bid = 2, .dir = 0, .edge = GKYL_PHYSICAL}, - { .bid = 2, .dir = 0, .edge = GKYL_PHYSICAL }, - }, - .connections[1] = { // x-direction. - { .bid = 2, .dir = 1, .edge = GKYL_PHYSICAL}, - { .bid = 2, .dir = 1, .edge = GKYL_PHYSICAL }, - }, - .connections[2] = { // z-direction. - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 2, .dir = 1, .edge = GKYL_PHYSICAL}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 2, + &(struct gkyl_gk_block_geom_info + ){.lower = {params->x_min, params->y_min, params->z_min}, + .upper = {params->x_max, params->y_max, params->z_max}, + .cells = {Npsi_sol, nalpha, Ntheta_divertor}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = + (struct gkyl_tok_geo_grid_inp){ + .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP, + .rclose = 2.5, // Closest R to region of interest. + .rright = 2.5, // Closest R to outboard SOL. + .rleft = 0.7, // Closest R to inboard SOL. + .rmax = 2.5, // Largest R in machine. + .rmin = 0.7, // Smallest R in machine. + .zmin = -1.3, // Lower Z boundary. + .zmax = 1.0, // Upper Z boundary. + .zmin_left = -1.0, // Z of inboard divertor plate. + .zmin_right = -1.0 // Z of outboard divertor plate. + }}, + + .connections[0] = + {// x-direction. + {.bid = 2, .dir = 0, .edge = GKYL_PHYSICAL}, + {.bid = 2, .dir = 0, .edge = GKYL_PHYSICAL} + }, + .connections[1] = + {// x-direction. + {.bid = 2, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 2, .dir = 1, .edge = GKYL_PHYSICAL} + }, + .connections[2] = + {// z-direction. + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 1, .edge = GKYL_PHYSICAL} + }} ); return bgeom; } - struct gk_app_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality @@ -361,7 +371,7 @@ struct gk_app_ctx create_ctx(void) struct gkyl_efit_inp efit_inp = { .filepath = "./gyrokinetic/data/eqdsk/asdex_33292_3.800.eqdsk", .rz_poly_order = 2, - .flux_poly_order = 1, + .flux_poly_order = 1 }; struct gkyl_efit *efit = gkyl_efit_new(&efit_inp); @@ -375,41 +385,41 @@ struct gk_app_ctx create_ctx(void) // Species mass and charge. int num_species = 2; double me = electron_mass; - double mi = proton_mass*2.01410177811; // Deuterium ions - double qi = eV; // ion charge + double mi = proton_mass * 2.01410177811; // Deuterium ions + double qi = eV; // ion charge double qe = -eV; // electron charge // Reference parameters. - double n0 = 6.0e18; + double n0 = 6.0e18; double Te0 = 11.0 * eV; double Ti0 = 29.0 * eV; // Parameters controlling initial conditions. - double den_floor = 0.1*n0; // Min density in IC. - double Te_floor = 4.0*eV; // Min Te in IC. - double Ti_floor = 4.0*eV; // Min Ti in IC. + double den_floor = 0.1 * n0; // Min density in IC. + double Te_floor = 4.0 * eV; // Min Te in IC. + double Ti_floor = 4.0 * eV; // Min Ti in IC. - double B0 = 2.5; + double B0 = 2.5; double q0 = 5.0; double r0 = 0.5; - double vte = sqrt(Te0/me); - double vti = sqrt(Ti0/mi); - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; + double vte = sqrt(Te0 / me); + double vti = sqrt(Ti0 / mi); + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // The radial extent gives [rhop_min, rhop_max] = [1.010, 1.046] double x_min = 0.336373; double x_max = 0.352308; double Lx = x_max - x_min; - double z_min = -(M_PI-1e-10); - double z_max = M_PI-1e-10; + double z_min = -(M_PI - 1e-10); + double z_max = M_PI - 1e-10; double Lz = z_max - z_min; - double Ly = 100*rho_s*q0/r0/3.0; - double y_min = -Ly/2.; - double y_max = Ly/2.; + double Ly = 100 * rho_s * q0 / r0 / 3.0; + double y_min = -Ly / 2.; + double y_max = Ly / 2.; double rho_min = rho_psi(x_min, psi_axis, psi_sep); double rho_max = rho_psi(x_max, psi_axis, psi_sep); @@ -417,32 +427,36 @@ struct gk_app_ctx create_ctx(void) // Source parameters int num_sources = 2; double P_exp = 0.235e6; // P_sol measured [W], half of 0.8MW - double vol_frac = Ly/(2.0*M_PI); // Volume fraction of the simulation box + double vol_frac = Ly / (2.0 * M_PI); // Volume fraction of the simulation box double P_inj = P_exp * vol_frac / num_species; // Core source: // - The particles injection is only the one that are lost through the inner radial boundary. - bool adapt_energy_srcCORE = true; // The source will compensate the losses in energy according to given boundaries. - bool adapt_particle_srcCORE = true; // The source will compensate the losses in particle according to given boundaries. + bool adapt_energy_srcCORE = + true; // The source will compensate the losses in energy according to given boundaries. + bool adapt_particle_srcCORE = + true; // The source will compensate the losses in particle according to given boundaries. double energy_srcCORE = P_inj; // What the source must inject in energy [W] - double particle_srcCORE = 0.0;// What the source must inject in particle [1/s] - double center_srcCORE[3] = {x_min, 0.0, -Lz/4.0}; // This is the position of the ion source, - double sigma_srcCORE[3] = {0.06*Lx, 0.0, Lz/8.0}; // the electron source will be at +Lz/2. + double particle_srcCORE = 0.0; // What the source must inject in particle [1/s] + double center_srcCORE[3] = {x_min, 0.0, -Lz / 4.0}; // This is the position of the ion source, + double sigma_srcCORE[3] = {0.06 * Lx, 0.0, Lz / 8.0}; // the electron source will be at +Lz/2. double floor_srcCORE = 1e-10; // Wall source: // - Injects energy only in the wall region. // - Reinjects particles that are absorbed by the wall. // - Energy is free to leave the system. - bool adapt_energy_srcWALL = false; // The source will compensate the losses in energy according to given boundaries. - bool adapt_particle_srcWALL = true; // The source will compensate the losses in particle according to given boundaries. + bool adapt_energy_srcWALL = + false; // The source will compensate the losses in energy according to given boundaries. + bool adapt_particle_srcWALL = + true; // The source will compensate the losses in particle according to given boundaries. double energy_srcWALL = 0.0; // What the source must inject in energy [W] - double particle_srcWALL = 0.0;// What the source must inject in particle [1/s] - double center_srcWALL[3] = {x_min, 0.0, -Lz/2.0}; // This is the position of the ion source, - double sigma_srcWALL[3] = {0.25*Lx, 0.0, 0.1*Lz}; // the electron source will be at +Lz/2. + double particle_srcWALL = 0.0; // What the source must inject in particle [1/s] + double center_srcWALL[3] = {x_min, 0.0, -Lz / 2.0}; // This is the position of the ion source, + double sigma_srcWALL[3] = {0.25 * Lx, 0.0, 0.1 * Lz}; // the electron source will be at +Lz/2. double floor_srcWALL = 1e-10; double temp_recycle_srcWALL = 4.0 * eV; // Grid parameters - int num_cell_x = 12; + int num_cell_x = 12; int num_cell_y = 12; int num_cell_z = 8; int num_cell_vpar = 8; @@ -450,75 +464,85 @@ struct gk_app_ctx create_ctx(void) int poly_order = 1; // Velocity box dimensions - double vpar_max_elc = 6.*vte; - double mu_max_elc = me*pow(4*vte,2)/(2*B0); - double vpar_max_ion = 6.*vti; - double mu_max_ion = mi*pow(4*vti,2)/(2*B0); + double vpar_max_elc = 6. * vte; + double mu_max_elc = me * pow(4 * vte, 2) / (2 * B0); + double vpar_max_ion = 6. * vti; + double mu_max_ion = mi * pow(4 * vti, 2) / (2 * B0); double t_end = 1.0e-4; int num_frames = 100; double write_phase_freq = 0.01; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-3; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_app_ctx ctx = { .cdim = cdim, .vdim = vdim, - .psi_sep = psi_sep , + .psi_sep = psi_sep, .psi_axis = psi_axis, - .x_min = x_min, .x_max = x_max, - .y_min = y_min, .y_max = y_max, - .z_min = z_min, .z_max = z_max, + .x_min = x_min, + .x_max = x_max, + .y_min = y_min, + .y_max = y_max, + .z_min = z_min, + .z_max = z_max, .Lx = Lx, .Ly = Ly, .Lz = Lz, - .rho_min = rho_min, .rho_max = rho_max, + .rho_min = rho_min, + .rho_max = rho_max, .num_species = num_species, - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .den_floor = den_floor , - .Te_floor = Te_floor , - .Ti_floor = Ti_floor , - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .den_floor = den_floor, + .Te_floor = Te_floor, + .Ti_floor = Ti_floor, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, .B0 = B0, .num_sources = num_sources, .adapt_energy_srcCORE = adapt_energy_srcCORE, .adapt_particle_srcCORE = adapt_particle_srcCORE, .center_srcCORE = {center_srcCORE[0], center_srcCORE[1], center_srcCORE[2]}, .sigma_srcCORE = {sigma_srcCORE[0], sigma_srcCORE[1], sigma_srcCORE[2]}, - .energy_srcCORE = energy_srcCORE, .particle_srcCORE = particle_srcCORE, + .energy_srcCORE = energy_srcCORE, + .particle_srcCORE = particle_srcCORE, .floor_srcCORE = floor_srcCORE, .adapt_energy_srcWALL = adapt_energy_srcWALL, .adapt_particle_srcWALL = adapt_particle_srcWALL, .center_srcWALL = {center_srcWALL[0], center_srcWALL[1], center_srcWALL[2]}, .sigma_srcWALL = {sigma_srcWALL[0], sigma_srcWALL[1], sigma_srcWALL[2]}, - .energy_srcWALL = energy_srcWALL, .particle_srcWALL = particle_srcWALL, + .energy_srcWALL = energy_srcWALL, + .particle_srcWALL = particle_srcWALL, .floor_srcWALL = floor_srcWALL, .temp_recycle_srcWALL = temp_recycle_srcWALL, - .num_cell_x = num_cell_x, - .num_cell_y = num_cell_y, - .num_cell_z = num_cell_z, - .num_cell_vpar = num_cell_vpar, - .num_cell_mu = num_cell_mu, + .num_cell_x = num_cell_x, + .num_cell_y = num_cell_y, + .num_cell_z = num_cell_z, + .num_cell_vpar = num_cell_vpar, + .num_cell_mu = num_cell_mu, .cells = {num_cell_x, num_cell_y, num_cell_z, num_cell_vpar, num_cell_mu}, - .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .poly_order = poly_order, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .write_phase_freq = write_phase_freq, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - - -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -537,16 +561,17 @@ main(int argc, char **argv) struct gkyl_comm *comm = gkyl_gyrokinetic_comms_new(app_args.use_mpi, app_args.use_gpu, stderr); struct gk_app_ctx ctx = create_ctx(); // Context for init functions. - + // Construct block geometry struct gkyl_gk_block_geom *bgeom = create_gk_block_geom(&ctx); int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcdim = ctx.cdim; app_inp->poly_order = 1; app_inp->basis_type = app_args.basis_type; @@ -935,8 +935,8 @@ main(int argc, char **argv) app_inp->num_species = 2; app_inp->species[0] = elc; app_inp->species[1] = ion; - app_inp->num_periodic_dir=1; - app_inp->periodic_dirs[0]=1; + app_inp->num_periodic_dir = 1; + app_inp->periodic_dirs[0] = 1; app_inp->field = field; app_inp->comm = comm; app_inp->use_gpu = app_args.use_gpu; @@ -946,17 +946,16 @@ main(int argc, char **argv) struct gkyl_gyrokinetic_run_inp run_inp = { .app_type = GKYL_GK_MULTIB, .multib_app_inp = *app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = app_args.num_steps, - }, + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = app_args.num_steps} }; gkyl_gyrokinetic_run_simulation(&run_inp); @@ -965,10 +964,10 @@ main(int argc, char **argv) gkyl_gyrokinetic_comms_release(comm); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif - - return 0; + return 0; } diff --git a/gyrokinetic/creg/rt_gk_multib_nstx_solonly_3x2v_p1.c b/gyrokinetic/creg/rt_gk_multib_nstx_solonly_3x2v_p1.c index c7c81739ce..3cc475cb3a 100644 --- a/gyrokinetic/creg/rt_gk_multib_nstx_solonly_3x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_multib_nstx_solonly_3x2v_p1.c @@ -9,38 +9,37 @@ #include - - - - //// ACTUAL SHAPED PLATES -void shaped_pfunc_lower_outer(double s, double* RZ){ +void shaped_pfunc_lower_outer(double s, double *RZ) +{ // Linear parametric segment between (r1,z1)=(0.55,-1.7) and (r2,z2)=(1.2,-1.5); s in [0,1] - RZ[0] = 0.55 + (1.2 - 0.55)*s; // 0.55 + 0.65*s - RZ[1] = -1.7 + (-1.5 + 1.7)*s; // -1.7 + 0.2*s + RZ[0] = 0.55 + (1.2 - 0.55) * s; // 0.55 + 0.65*s + RZ[1] = -1.7 + (-1.5 + 1.7) * s; // -1.7 + 0.2*s } -void shaped_pfunc_upper_outer(double s, double* RZ){ +void shaped_pfunc_upper_outer(double s, double *RZ) +{ // Symmetric (Z flipped) segment: (0.55,+1.7) to (1.2,+1.5); s in [0,1] - RZ[0] = 0.55 + (1.2 - 0.55)*s; // 0.55 + 0.65*s - RZ[1] = 1.7 + (1.5 - 1.7)*s; // 1.7 - 0.2*s + RZ[0] = 0.55 + (1.2 - 0.55) * s; // 0.55 + 0.65*s + RZ[1] = 1.7 + (1.5 - 1.7) * s; // 1.7 - 0.2*s } -void shaped_pfunc_upper_inner(double s, double* RZ){ +void shaped_pfunc_upper_inner(double s, double *RZ) +{ // Upper inner plate: vertical flip of lower inner plate // (r1,z1) = (0.2, +1.2) -> (r2,z2) = (0.35, +1.4) - RZ[0] = 0.2 + (0.35 - 0.2)*s; // 0.2 + 0.15*s - RZ[1] = 1.2 + (1.4 - 1.2)*s; // 1.2 + 0.2*s + RZ[0] = 0.2 + (0.35 - 0.2) * s; // 0.2 + 0.15*s + RZ[1] = 1.2 + (1.4 - 1.2) * s; // 1.2 + 0.2*s } -void shaped_pfunc_lower_inner(double s, double* RZ){ +void shaped_pfunc_lower_inner(double s, double *RZ) +{ // Lower inner plate: (r1,z1) = (0.2, -1.2) -> (r2,z2) = (0.35, -1.4) - RZ[0] = 0.2 + (0.35 - 0.2)*s; // 0.2 + 0.15*s - RZ[1] = -1.2 + (-1.4 + 1.2)*s; // -1.2 - 0.2*s + RZ[0] = 0.2 + (0.35 - 0.2) * s; // 0.2 + 0.15*s + RZ[1] = -1.2 + (-1.4 + 1.2) * s; // -1.2 - 0.2*s } - struct gk_app_ctx { int cdim, vdim; // Dimensionality. double chargeElc; // electron charge @@ -85,10 +84,7 @@ struct gk_app_ctx { int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; - - -struct gk_app_ctx -create_ctx(void) +struct gk_app_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -100,107 +96,106 @@ create_ctx(void) double qi = eV; // ion charge double qe = -eV; // electron charge - double temp_fac = 3.0; - double Te = 1500.0/temp_fac*eV; - double Ti = 1500.0/temp_fac*eV; - double TH0 = 100.0*eV; + double Te = 1500.0 / temp_fac * eV; + double Ti = 1500.0 / temp_fac * eV; + double TH0 = 100.0 * eV; double B0 = 2.18; // Magnetic field magnitude in Tesla double n0 = 2.0e19; // Particle density in 1/m^3 - double n0H0 = n0*1.0e-2; // Particle density in 1/m^3 - - // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); - double vtH0 = sqrt(TH0/mH0); + double n0H0 = n0 * 1.0e-2; // Particle density in 1/m^3 + // Derived parameters. + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); + double vtH0 = sqrt(TH0 / mH0); - double nsource = 1.675e22*2.5*temp_fac; - double Tsource = 3000.0*eV/temp_fac; + double nsource = 1.675e22 * 2.5 * temp_fac; + double Tsource = 3000.0 * eV / temp_fac; double cx = 0.0065612; - double cz = 0.4916200*1.4; + double cz = 0.4916200 * 1.4; double xcenter = -0.10; // Collision parameters. double nu_frac = 0.25; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nu_frac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); // collision freq + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nu_frac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te)) + ); // collision freq - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nuIon = nu_frac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mi)*(Ti*sqrt(Ti))); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nuIon = nu_frac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mi) * (Ti * sqrt(Ti))); // Simulation box size (m). - double vpar_max_elc = 8.0*vtElc; - double mu_max_elc = 18*me*vtElc*vtElc/(2.0*B0); + double vpar_max_elc = 8.0 * vtElc; + double mu_max_elc = 18 * me * vtElc * vtElc / (2.0 * B0); - double vpar_max_ion = 8.0*vtIon; - double mu_max_ion = 18*mi*vtIon*vtIon/(2.0*B0); + double vpar_max_ion = 8.0 * vtIon; + double mu_max_ion = 18 * mi * vtIon * vtIon / (2.0 * B0); - double vpar_max_H0 = 6.0*vtH0; + double vpar_max_H0 = 6.0 * vtH0; // Number of cells. int Nx = 4; - int Ny=8; + int Ny = 8; int Nz = 8; int Nvpar = 16; int Nmu = 12; - double t_end = 8.0e-3; + double t_end = 8.0e-3; double num_frames = 800; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_app_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, .massH0 = mH0, - .Te = Te, - .Ti = Ti, - .TH0 = TH0, + .Te = Te, + .Ti = Ti, + .TH0 = TH0, .vtIon = vtIon, .vtElc = vtElc, .vtH0 = vtH0, - .nuElc = nuElc, - .nuIon = nuIon, + .nuElc = nuElc, + .nuIon = nuIon, .nu_frac = nu_frac, - .B0 = B0, - .n0 = n0, + .B0 = B0, + .n0 = n0, .n0H0 = n0H0, .nsource = nsource, .Tsource = Tsource, .cx = cx, .xcenter = xcenter, .cz = cz, - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, - .vpar_max_H0 = vpar_max_H0, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, + .vpar_max_H0 = vpar_max_H0, .Nx = Nx, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Ny, Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -struct gkyl_gk_block_geom* -create_gk_block_geom(void *ctx) +struct gkyl_gk_block_geom *create_gk_block_geom(void *ctx) { - struct gk_app_ctx *app = ctx; struct gkyl_gk_block_geom *bgeom = gkyl_gk_block_geom_new(3, 3); @@ -235,25 +230,23 @@ create_gk_block_geom(void *ctx) symbol such as o,x,%, or % are instead connected to the other edge with the same symbol. Edges that do not coincide with another edge are a physical boundary. - */ - + */ struct gkyl_efit_inp efit_inp = { .filepath = "./gyrokinetic/data/eqdsk/nstxu_DN.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; struct gkyl_efit *efit = gkyl_efit_new(&efit_inp); // double psisep = -0.0354402478890806; // from eqdsk our rep double psisep = efit->psisep; gkyl_efit_release(efit); - double wout = 0.0069402478890806/4.0; - double win = 0.0069402478890806/4.0; - double wcore = 0.0069402478890806/4.0; - double wpf = 0.0069402478890806/4.0; - + double wout = 0.0069402478890806 / 4.0; + double win = 0.0069402478890806 / 4.0; + double wcore = 0.0069402478890806 / 4.0; + double wpf = 0.0069402478890806 / 4.0; double psi_lo_outer_sol = psisep; double psi_up_outer_sol = psisep + wout; @@ -266,15 +259,15 @@ create_gk_block_geom(void *ctx) double psi_lo_inner_sol = psisep; double psi_up_inner_sol = psisep + win; - + int npsi_outer_sol = 6; int npsi_core = 6; int npsi_pf = 6; int npsi_inner_sol = 6; - double ntheta_lower_inner = 4; + double ntheta_lower_inner = 4; double ntheta_middle_inner = 8; - double ntheta_upper_inner = 4; + double ntheta_upper_inner = 4; double ntheta_lower_outer = 4; double ntheta_middle_outer = 8; @@ -285,168 +278,180 @@ create_gk_block_geom(void *ctx) double rright_out = 1.6; double rmin = 0.2; - double Lz = (M_PI-1e-14)*2.0; - double theta_lo = -Lz/2.0, theta_up = Lz/2.0; + double Lz = (M_PI - 1e-14) * 2.0; + double theta_lo = -Lz / 2.0, theta_up = Lz / 2.0; - double Ly = 2.0*M_PI/10.0; - double alpha_lo = -Ly/2.0; - double alpha_up = Ly/2.0; + double Ly = 2.0 * M_PI / 10.0; + double alpha_lo = -Ly / 2.0; + double alpha_up = Ly / 2.0; int nalpha = 8; double compression_factor = 0.0; double radial_compression_factor = 0.0; // block 0. Lower outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 0, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, alpha_lo, theta_lo}, - .upper = { psi_up_outer_sol, alpha_up, theta_up}, - .cells = { npsi_outer_sol, nalpha, ntheta_lower_outer}, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compression_factor = compression_factor, - .radial_compression_factor = radial_compression_factor, + gkyl_gk_block_geom_set_block( + bgeom, 0, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, alpha_lo, theta_lo}, + .upper = {psi_up_outer_sol, alpha_up, theta_up}, + .cells = {npsi_outer_sol, nalpha, ntheta_lower_outer}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compression_factor = compression_factor, + .radial_compression_factor = radial_compression_factor}, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = rmin, // closest R to inboard SOL + .rmin = rmin, // smallest R in machine + .rmax = rright_out, // largest R in machine + .use_cubics = + false, // Whether to use cubic representation of psi(R,Z) for field line tracing + .zmin = -zouter, + .zmax = zouter, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}}, + + .connections[0] = + { + // x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = rmin, // closest R to inboard SOL - .rmin = rmin, // smallest R in machine - .rmax = rright_out, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - .zmin = -zouter, - .zmax = zouter, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - }, - .connections[2] = { // z-direction connections - { .bid = 0, .dir = 2, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 1, .dir = 2, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[1] = + { + // y-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[2] = + {// z-direction connections + {.bid = 0, .dir = 2, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 1, .dir = 2, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 1. Middle outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 1, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, alpha_lo, theta_lo}, - .upper = { psi_up_outer_sol, alpha_up, theta_up}, - .cells = { npsi_outer_sol, nalpha, ntheta_middle_outer}, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compression_factor = compression_factor, - .radial_compression_factor = radial_compression_factor, + gkyl_gk_block_geom_set_block( + bgeom, 1, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, alpha_lo, theta_lo}, + .upper = {psi_up_outer_sol, alpha_up, theta_up}, + .cells = {npsi_outer_sol, nalpha, ntheta_middle_outer}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compression_factor = compression_factor, + .radial_compression_factor = radial_compression_factor}, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, + .rclose = rright_out, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = rmin, // closest R to inboard SOL + .rmin = rmin, // smallest R in machine + .rmax = rright_out, // largest R in machine + .use_cubics = + false, // Whether to use cubic representation of psi(R,Z) for field line tracing + .zmin = -zouter, + .zmax = zouter, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}}, + + .connections[0] = + { + // x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, - .rclose = rright_out, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = rmin, // closest R to inboard SOL - .rmin = rmin, // smallest R in machine - .rmax = rright_out, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - .zmin = -zouter, - .zmax = zouter, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - }, - .connections[2] = { // z-direction connections - { .bid = 0, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 2, .dir = 2, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[1] = + { + // y-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[2] = + {// z-direction connections + {.bid = 0, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 2, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 2. Upper outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 2, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, alpha_lo, theta_lo}, - .upper = { psi_up_outer_sol, alpha_up, theta_up}, - .cells = { npsi_outer_sol, nalpha, ntheta_upper_outer}, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compression_factor = compression_factor, - .radial_compression_factor = radial_compression_factor, + gkyl_gk_block_geom_set_block( + bgeom, 2, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, alpha_lo, theta_lo}, + .upper = {psi_up_outer_sol, alpha_up, theta_up}, + .cells = {npsi_outer_sol, nalpha, ntheta_upper_outer}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compression_factor = compression_factor, + .radial_compression_factor = radial_compression_factor}, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = rmin, // closest R to inboard SOL + .rmin = rmin, // smallest R in machine + .rmax = rright_out, // largest R in machine + .use_cubics = + false, // Whether to use cubic representation of psi(R,Z) for field line tracing + .zmin = -zouter, + .zmax = zouter, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}}, + + .connections[0] = + { + // x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = rmin, // closest R to inboard SOL - .rmin = rmin, // smallest R in machine - .rmax = rright_out, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - .zmin = -zouter, - .zmax = zouter, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - }, - .connections[2] = { // z-direction connections - { .bid = 1, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 2, .edge = GKYL_PHYSICAL}, // physical boundary - } - } + .connections[1] = + { + // y-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[2] = + { + // z-direction connections + {.bid = 1, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 2, .edge = GKYL_PHYSICAL} // physical boundary + }} ); - return bgeom; } - -void -init_density_outer(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_outer( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Density profile: 1e19 at separatrix, 1e17 at outer boundary double psi = xn[0]; double psisep = -0.0354402478890806; - double psi_outer = psisep + 0.0069402478890806/4.0; + double psi_outer = psisep + 0.0069402478890806 / 4.0; double n_sep = 1.0e19; double n_outer = 1.0e17; @@ -458,48 +463,40 @@ init_density_outer(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTR fout[0] = n; } -void -source_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void source_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; struct gk_app_ctx *app = ctx; double nsource = app->nsource; double psisep = -0.0354402478890806; // from eqdsk our rep - double wout = 0.0069402478890806/4.0; - if(x <= psisep+wout/8.0) + double wout = 0.0069402478890806 / 4.0; + if (x <= psisep + wout / 8.0) { fout[0] = nsource; - else - fout[0] = nsource*1.0e-5; - + } else { + fout[0] = nsource * 1.0e-5; + } } - -void -init_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_upar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } - - -void -init_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; - double T = 2.0*app->Te; + double T = 2.0 * app->Te; fout[0] = T; } -void -init_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; - double T = 2.0*app->Ti; + double T = 2.0 * app->Ti; fout[0] = T; } -void -source_temp(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void source_temp(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; double T = app->Tsource; @@ -507,7 +504,7 @@ source_temp(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -519,21 +516,23 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v double vpar = 0.0; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vpar = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vpar = -vpar_max_elc*2.0*pow(cvpar,2); - else - vpar = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vpar = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vpar = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vpar = vpar_max_elc * 2.0 * pow(cvpar, 2); + } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } static inline void -mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_ion(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -545,45 +544,51 @@ mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v double vpar = 0.0; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vpar = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vpar = -vpar_max_ion*2.0*pow(cvpar,2); - else - vpar = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vpar = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vpar = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vpar = vpar_max_ion * 2.0 * pow(cvpar, 2); + } mu = mu_max_ion * (cmu * cmu); // Set rescaled ion velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar ; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } - -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_app_ctx *app = ctx; fout[0] = 0.3; // Diffusivity [m^2/s]. } -void -calc_integrated_diagnostics(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_multib_app* app, double t_curr, double dt, bool force_calc) +void calc_integrated_diagnostics( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_multib_app *app, double t_curr, double dt, + bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_calc) { gkyl_gyrokinetic_multib_app_calc_field_energy(app, t_curr); gkyl_gyrokinetic_multib_app_calc_integrated_mom(app, t_curr); - if ( !(dt < 0.0) ) + if (!(dt < 0.0)) { gkyl_gyrokinetic_multib_app_save_dt(app, t_curr, dt); + } } } -static void -write_data(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_multib_app* app, double t_curr, bool force_write) +static void write_data( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_multib_app *app, double t_curr, bool force_write +) { bool trig_now = gkyl_tm_trigger_check_and_bump(iot, t_curr); if (trig_now || force_write) { - int frame = (!trig_now) && force_write? iot->curr : iot->curr-1; + int frame = (!trig_now) && force_write ? iot->curr : iot->curr - 1; gkyl_gyrokinetic_multib_app_write(app, t_curr, frame); gkyl_gyrokinetic_multib_app_write_field_energy(app); @@ -592,8 +597,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_multib_app* app, double } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -616,273 +620,264 @@ main(int argc, char **argv) struct gkyl_gk_block_geom *bgeom = create_gk_block_geom(&ctx); int nblocks = gkyl_gk_block_geom_num_blocks(bgeom); - int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcdim = ctx.cdim; app_inp->poly_order = 1; app_inp->basis_type = app_args.basis_type; @@ -891,8 +886,8 @@ main(int argc, char **argv) app_inp->num_species = 2; app_inp->species[0] = elc; app_inp->species[1] = ion; - app_inp->num_periodic_dir=1; - app_inp->periodic_dirs[0]=1; + app_inp->num_periodic_dir = 1; + app_inp->periodic_dirs[0] = 1; app_inp->field = field; app_inp->comm = comm; app_inp->use_gpu = app_args.use_gpu; @@ -902,17 +897,16 @@ main(int argc, char **argv) struct gkyl_gyrokinetic_run_inp run_inp = { .app_type = GKYL_GK_MULTIB, .multib_app_inp = *app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = app_args.num_steps, - }, + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = app_args.num_steps} }; gkyl_gyrokinetic_run_simulation(&run_inp); @@ -921,10 +915,10 @@ main(int argc, char **argv) gkyl_gyrokinetic_comms_release(comm); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif - - return 0; + return 0; } diff --git a/gyrokinetic/creg/rt_gk_multib_sheath_1x2v_p1.c b/gyrokinetic/creg/rt_gk_multib_sheath_1x2v_p1.c index ecdac989a9..5a15953b5c 100644 --- a/gyrokinetic/creg/rt_gk_multib_sheath_1x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_multib_sheath_1x2v_p1.c @@ -7,8 +7,7 @@ #include -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -70,14 +69,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -104,15 +103,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -132,20 +135,27 @@ create_ctx(void) int Nvpar = 6; // Cell count (velocity space: parallel velocity direction). int Nmu = 4; // Cell count (velocity space: magnetic moment direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -196,14 +206,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -214,9 +225,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -224,8 +236,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -235,15 +246,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -255,8 +266,7 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Electron source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -264,8 +274,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -275,15 +286,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -294,9 +307,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -304,8 +318,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -315,15 +328,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -335,8 +348,7 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Ion source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -344,8 +356,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -355,15 +368,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -373,8 +386,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -384,8 +396,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -395,8 +406,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -407,30 +417,29 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[0] = B0; } -struct gkyl_gk_block_geom* -create_gk_block_geom(void *ctx) +struct gkyl_gk_block_geom *create_gk_block_geom(void *ctx) { - struct sheath_ctx *app = ctx; struct gkyl_gk_block_geom *bgeom = gkyl_gk_block_geom_new(1, 3); @@ -452,89 +461,94 @@ create_gk_block_geom(void *ctx) symbol such as o,x,%, or % are instead connected to the other edge with the same symbol. Edges that do not coincide with another edge are a physical boundary. - */ - + */ - int nz=app->Nz; + int nz = app->Nz; double Lz = app->Lz; // block 0. Lower SOL. - gkyl_gk_block_geom_set_block(bgeom, 0, &(struct gkyl_gk_block_geom_info) { - .lower = { -Lz/2.0 }, - .upper = { -Lz/4.0 }, - .cells = { nz/4}, - .cuts = { 1 }, - .geometry = { - .geometry_id = GKYL_GEOMETRY_MAPC2P, - .world = { 0.0, 0.0 }, - .mapc2p = mapc2p, - .c2p_ctx = app, - .bfield_func = bfield_func, - .bfield_ctx = app - }, - - .connections[0] = { // z-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 0, + &(struct gkyl_gk_block_geom_info + ){.lower = {-Lz / 2.0}, + .upper = {-Lz / 4.0}, + .cells = {nz / 4}, + .cuts = {1}, + .geometry = + {.geometry_id = GKYL_GEOMETRY_MAPC2P, + .world = {0.0, 0.0}, + .mapc2p = mapc2p, + .c2p_ctx = app, + .bfield_func = bfield_func, + .bfield_ctx = app}, + + .connections[0] = + {// z-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 1. Middle SOL. - gkyl_gk_block_geom_set_block(bgeom, 1, &(struct gkyl_gk_block_geom_info) { - .lower = { -Lz/4.0}, - .upper = { Lz/4.0}, - .cells = { nz/2}, - .cuts = { 1 }, - .geometry = { - .geometry_id = GKYL_GEOMETRY_MAPC2P, - .world = { 0.0, 0.0 }, - .mapc2p = mapc2p, - .c2p_ctx = app, - .bfield_func = bfield_func, - .bfield_ctx = app - }, - - .connections[0] = { // z-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE}, - } + gkyl_gk_block_geom_set_block( + bgeom, 1, + &(struct gkyl_gk_block_geom_info + ){.lower = {-Lz / 4.0}, + .upper = {Lz / 4.0}, + .cells = {nz / 2}, + .cuts = {1}, + .geometry = + {.geometry_id = GKYL_GEOMETRY_MAPC2P, + .world = {0.0, 0.0}, + .mapc2p = mapc2p, + .c2p_ctx = app, + .bfield_func = bfield_func, + .bfield_ctx = app}, + + .connections[0] = + {// z-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + } } ); // block 2. Upper SOL. - gkyl_gk_block_geom_set_block(bgeom, 2, &(struct gkyl_gk_block_geom_info) { - .lower = { Lz/4.0}, - .upper = { Lz/2.0}, - .cells = { nz/4}, - .cuts = { 1 }, - .geometry = { - .geometry_id = GKYL_GEOMETRY_MAPC2P, - .world = { 0.0, 0.0 }, - .mapc2p = mapc2p, - .c2p_ctx = app, - .bfield_func = bfield_func, - .bfield_ctx = app - }, - - .connections[0] = { // z-direction connections - { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - } - } + gkyl_gk_block_geom_set_block( + bgeom, 2, + &(struct gkyl_gk_block_geom_info + ){.lower = {Lz / 4.0}, + .upper = {Lz / 2.0}, + .cells = {nz / 4}, + .cuts = {1}, + .geometry = + {.geometry_id = GKYL_GEOMETRY_MAPC2P, + .world = {0.0, 0.0}, + .mapc2p = mapc2p, + .c2p_ctx = app, + .bfield_func = bfield_func, + .bfield_ctx = app}, + + .connections[0] = + { + // z-direction connections + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }} ); return bgeom; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -545,10 +559,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcdim = ctx.cdim; app_inp->poly_order = 1; app_inp->basis_type = app_args.basis_type; @@ -771,23 +777,21 @@ main(int argc, char **argv) app_inp->field = field; app_inp->comm = comm; - // Set app output name from the executable name (argv[0]). snprintf(app_inp->name, sizeof(app_inp->name), "%s", app_args.app_name); struct gkyl_gyrokinetic_run_inp run_inp = { .app_type = GKYL_GK_MULTIB, .multib_app_inp = *app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = app_args.num_steps, - }, + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = app_args.num_steps} }; gkyl_gyrokinetic_run_simulation(&run_inp); @@ -797,8 +801,9 @@ main(int argc, char **argv) gkyl_free(app_inp); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif return 0; diff --git a/gyrokinetic/creg/rt_gk_multib_slab_2x2v_p1.c b/gyrokinetic/creg/rt_gk_multib_slab_2x2v_p1.c index e0b2852f62..435127c7e5 100644 --- a/gyrokinetic/creg/rt_gk_multib_slab_2x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_multib_slab_2x2v_p1.c @@ -7,8 +7,7 @@ #include -struct slab_ctx -{ +struct slab_ctx { int cdim, vdim; // Dimensionality // Physical constants (using non-normalized physical units). @@ -60,14 +59,14 @@ struct slab_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct slab_ctx -create_ctx(void) +struct slab_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -78,15 +77,15 @@ create_ctx(void) double mass_ion = 2.014 * GKYL_PROTON_MASS; // Proton mass. double charge_ion = GKYL_ELEMENTARY_CHARGE; // Proton charge. - double Te = 100.0*5.0/8.0 * GKYL_ELEMENTARY_CHARGE; // Electron temperature. - double Ti = 150.0*5.0/8.0 * GKYL_ELEMENTARY_CHARGE; // Ion temperature. + double Te = 100.0 * 5.0 / 8.0 * GKYL_ELEMENTARY_CHARGE; // Electron temperature. + double Ti = 150.0 * 5.0 / 8.0 * GKYL_ELEMENTARY_CHARGE; // Ion temperature. double n0 = 3.0e19; // Reference number density (1 / m^3). double B0 = 2.51; // Magnetic field axis (simple toroidal coordinates). double R_outer = 5.6; //double cx = 0.00159/2.16; - double cx = 0.00159/2.16 * 6.0; - double cz = 7.22285*3.0; + double cx = 0.00159 / 2.16 * 6.0; + double cz = 7.22285 * 3.0; double x_center = 0.03; double nu_frac = 0.25; // Collision frequency fraction. @@ -95,11 +94,13 @@ create_ctx(void) double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Collision frequencies. - double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion,4) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_elc) * pow(Te,3.0/2.0)); - double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion,4) * n0 / - (12.0 * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_ion) * pow(Ti,3.0/2.0)); - + double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4) * n0 / + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); + double nu_ion = + nu_frac * log_lambda_ion * pow(charge_ion, 4) * n0 / + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -108,7 +109,7 @@ create_ctx(void) double n_src = 6.1e23; // Source number density. //double T_src = 200*5.0/2.0*0.3*1.6251586572438161*1.17*5.0/8.0 * GKYL_ELEMENTARY_CHARGE; // Source Temperature - double T_src = 285.0*5.0/8.0 * GKYL_ELEMENTARY_CHARGE; // Source Temperature + double T_src = 285.0 * 5.0 / 8.0 * GKYL_ELEMENTARY_CHARGE; // Source Temperature // Simulation parameters. int Nx = 8; // Cell count (configuration space: x-direction). @@ -117,18 +118,25 @@ create_ctx(void) int Nmu = 6; // Cell count (velocity space: magnetic moment direction). double Lx = 0.06; // Domain size (configuration space: x-direction). double Lz = 120.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 6.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte,2) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti,2) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 6.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double t_end = 5.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct slab_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -173,36 +181,35 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct slab_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; - xp[0] = x; xp[1] = y; xp[2] = z; + xp[0] = x; + xp[1] = y; + xp[2] = z; } -void bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct slab_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -struct gkyl_gk_block_geom* -create_gk_block_geom(void *ctx) +struct gkyl_gk_block_geom *create_gk_block_geom(void *ctx) { - struct slab_ctx *app = ctx; struct gkyl_gk_block_geom *bgeom = gkyl_gk_block_geom_new(2, 3); @@ -224,189 +231,202 @@ create_gk_block_geom(void *ctx) symbol such as o,x,%, or % are instead connected to the other edge with the same symbol. Edges that do not coincide with another edge are a physical boundary. - */ - + */ - int nx=8; - int nz=4; + int nx = 8; + int nz = 4; double Lz = 120.0; double Lx = 0.06; // block 0. Lower SOL. - gkyl_gk_block_geom_set_block(bgeom, 0, &(struct gkyl_gk_block_geom_info) { - .lower = { 0.0, -Lz/2.0 }, - .upper = { Lx, -Lz/6.0 }, - .cells = { nx, nz}, - .cuts = { 1, 1 }, - .geometry = { - .geometry_id = GKYL_GEOMETRY_MAPC2P, - .mapc2p = mapc2p, - .c2p_ctx = app, - .bfield_func = bfield_func, - .bfield_ctx = app - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 1, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 0, + &(struct gkyl_gk_block_geom_info + ){.lower = {0.0, -Lz / 2.0}, + .upper = {Lx, -Lz / 6.0}, + .cells = {nx, nz}, + .cuts = {1, 1}, + .geometry = + {.geometry_id = GKYL_GEOMETRY_MAPC2P, + .mapc2p = mapc2p, + .c2p_ctx = app, + .bfield_func = bfield_func, + .bfield_ctx = app}, + + .connections[0] = + { + // x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 1, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 1. Middle SOL. - gkyl_gk_block_geom_set_block(bgeom, 1, &(struct gkyl_gk_block_geom_info) { - .lower = { 0.0, -Lz/6.0}, - .upper = { Lx, Lz/6.0}, - .cells = { nx, nz}, - .cuts = { 1, 1 }, - .geometry = { - .geometry_id = GKYL_GEOMETRY_MAPC2P, - .mapc2p = mapc2p, - .c2p_ctx = app, - .bfield_func = bfield_func, - .bfield_ctx = app - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } + gkyl_gk_block_geom_set_block( + bgeom, 1, + &(struct gkyl_gk_block_geom_info + ){.lower = {0.0, -Lz / 6.0}, + .upper = {Lx, Lz / 6.0}, + .cells = {nx, nz}, + .cuts = {1, 1}, + .geometry = + {.geometry_id = GKYL_GEOMETRY_MAPC2P, + .mapc2p = mapc2p, + .c2p_ctx = app, + .bfield_func = bfield_func, + .bfield_ctx = app}, + + .connections[0] = + { + // x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + } } ); // block 2. Upper SOL. - gkyl_gk_block_geom_set_block(bgeom, 2, &(struct gkyl_gk_block_geom_info) { - .lower = { 0.0, Lz/6.0}, - .upper = { Lx, Lz/2.0}, - .cells = { nx, nz}, - .cuts = { 1, 1 }, - .geometry = { - .geometry_id = GKYL_GEOMETRY_MAPC2P, - .mapc2p = mapc2p, - .c2p_ctx = app, - .bfield_func = bfield_func, - .bfield_ctx = app - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary - } - } + gkyl_gk_block_geom_set_block( + bgeom, 2, + &(struct gkyl_gk_block_geom_info + ){.lower = {0.0, Lz / 6.0}, + .upper = {Lx, Lz / 2.0}, + .cells = {nx, nz}, + .cuts = {1, 1}, + .geometry = + {.geometry_id = GKYL_GEOMETRY_MAPC2P, + .mapc2p = mapc2p, + .c2p_ctx = app, + .bfield_func = bfield_func, + .bfield_ctx = app}, + + .connections[0] = + { + // x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + { + // z-direction connections + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); return bgeom; } -void -evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct slab_ctx *app = ctx; double x = xn[0], z = xn[1]; double n_src = app->n_src; - double cx= app->cx; - double cz= app->cz; - double x_center= app->x_center; + double cx = app->cx; + double cz = app->cz; + double x_center = app->x_center; double Lz = app->Lz; double n = 0.0; - n = exp( -(x-x_center)*(x-x_center)/2/cx/cx ) * exp( -z*z/2/cz/cz ); - if (n < 1e-5) + n = exp(-(x - x_center) * (x - x_center) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n < 1e-5) { n = 1e-5; - n = n*n_src; + } + n = n * n_src; fout[0] = n; } -void -evalSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set source parallel velocity. fout[0] = 0.0; } -void -evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct slab_ctx *app = ctx; double T_src = app->T_src; fout[0] = T_src; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct slab_ctx *app = ctx; double x = xn[0], z = xn[1]; - double n0= app->n0; - double cx= app->cx; - double cz= app->cz; - double x_center= app->x_center; + double n0 = app->n0; + double cx = app->cx; + double cz = app->cz; + double x_center = app->x_center; double Lz = app->Lz; double n = 0.0; - n = exp( -(x-x_center)*(x-x_center)/2/cx/cx ) * exp( -z*z/2/cz/cz ); - if (n < 1e-5) + n = exp(-(x - x_center) * (x - x_center) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n < 1e-5) { n = 1e-5; - n = n*n0; + } + n = n * n0; fout[0] = n; } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct slab_ctx *app = ctx; double Te = app->Te; fout[0] = Te; } -void -evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct slab_ctx *app = ctx; double Ti = app->Ti; fout[0] = Ti; } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; fout[0] = 0.03; // Diffusivity [m^2/s]. } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -421,10 +441,12 @@ main(int argc, char **argv) int nblocks = gkyl_gk_block_geom_num_blocks(bgeom); int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcdim = ctx.cdim; app_inp->poly_order = 1; app_inp->basis_type = app_args.basis_type; @@ -672,22 +693,17 @@ main(int argc, char **argv) struct gkyl_gyrokinetic_run_inp run_inp = { .app_type = GKYL_GK_MULTIB, .multib_app_inp = *app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = app_args.num_steps, - }, - .print_verbosity = { - .enabled = true, - .frequency = 0.1, - .estimate_completion_time = true, - }, + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = app_args.num_steps}, + .print_verbosity = {.enabled = true, .frequency = 0.1, .estimate_completion_time = true} }; gkyl_gyrokinetic_run_simulation(&run_inp); @@ -697,8 +713,9 @@ main(int argc, char **argv) gkyl_free(app_inp); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif return 0; diff --git a/gyrokinetic/creg/rt_gk_multib_step_2x2v_p1.c b/gyrokinetic/creg/rt_gk_multib_step_2x2v_p1.c index 023538ba37..8bc1e36423 100644 --- a/gyrokinetic/creg/rt_gk_multib_step_2x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_multib_step_2x2v_p1.c @@ -7,37 +7,40 @@ #include -void shaped_pfunc_lower_outer(double s, double* RZ){ - double p0[2] = {5.488-0.6,-8.600}; - double p1[2] = {5.855-0.6,-8.52318}; - p1[0] = (p1[0] - p0[0])*2 + p1[0]; - p1[1] = (p1[1] - p0[1])*2 + p1[1]; - RZ[0] = (1-s)*p0[0]+s*p1[0]; - RZ[1] = (1-s)*p0[1]+s*p1[1]; +void shaped_pfunc_lower_outer(double s, double *RZ) +{ + double p0[2] = {5.488 - 0.6, -8.600}; + double p1[2] = {5.855 - 0.6, -8.52318}; + p1[0] = (p1[0] - p0[0]) * 2 + p1[0]; + p1[1] = (p1[1] - p0[1]) * 2 + p1[1]; + RZ[0] = (1 - s) * p0[0] + s * p1[0]; + RZ[1] = (1 - s) * p0[1] + s * p1[1]; } -void shaped_pfunc_upper_outer(double s, double* RZ){ - double p0[2] = {5.488-0.6,8.600}; - double p1[2] = {5.855-0.6,8.52318}; - p1[0] = (p1[0] - p0[0])*2 + p1[0]; - p1[1] = (p1[1] - p0[1])*2 + p1[1]; - RZ[0] = (1-s)*p0[0]+s*p1[0]; - RZ[1] = (1-s)*p0[1]+s*p1[1]; +void shaped_pfunc_upper_outer(double s, double *RZ) +{ + double p0[2] = {5.488 - 0.6, 8.600}; + double p1[2] = {5.855 - 0.6, 8.52318}; + p1[0] = (p1[0] - p0[0]) * 2 + p1[0]; + p1[1] = (p1[1] - p0[1]) * 2 + p1[1]; + RZ[0] = (1 - s) * p0[0] + s * p1[0]; + RZ[1] = (1 - s) * p0[1] + s * p1[1]; } //old inner plates -void shaped_pfunc_upper_inner(double s, double* RZ){ - RZ[0] = 1.651 + (1.8 - 1.651)*s; - RZ[1] = 6.331 + (6.777 - 6.331)*s; +void shaped_pfunc_upper_inner(double s, double *RZ) +{ + RZ[0] = 1.651 + (1.8 - 1.651) * s; + RZ[1] = 6.331 + (6.777 - 6.331) * s; } -void shaped_pfunc_lower_inner(double s, double* RZ){ - RZ[0] = 1.651 + (1.8 - 1.651)*s; - RZ[1] = -(6.331 + (6.777 - 6.331)*s); +void shaped_pfunc_lower_inner(double s, double *RZ) +{ + RZ[0] = 1.651 + (1.8 - 1.651) * s; + RZ[1] = -(6.331 + (6.777 - 6.331) * s); } -struct gkyl_gk_block_geom* -create_gk_block_geom(void) +struct gkyl_gk_block_geom *create_gk_block_geom(void) { struct gkyl_gk_block_geom *bgeom = gkyl_gk_block_geom_new(2, 12); @@ -72,14 +75,13 @@ create_gk_block_geom(void) symbol such as o,x,%, or % are instead connected to the other edge with the same symbol. Edges that do not coincide with another edge are a physical boundary. - */ - - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/step.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, - .reflect = true, + */ + + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/step.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1, + .reflect = true }; struct gkyl_efit *efit = gkyl_efit_new(&efit_inp); @@ -100,7 +102,7 @@ create_gk_block_geom(void) double psi_lo_pf = psisep; double psi_up_pf = psisep + wpf; - double psi_lo_inner_sol = psisep - win ; + double psi_lo_inner_sol = psisep - win; double psi_up_inner_sol = psisep; int npsi_outer_sol = 4; @@ -108,463 +110,491 @@ create_gk_block_geom(void) int npsi_pf = 2; int npsi_inner_sol = 2; - double ntheta_lower_inner = 4; - double ntheta_middle_inner = 4*2; - double ntheta_upper_inner = 4; + double ntheta_lower_inner = 4; + double ntheta_middle_inner = 4 * 2; + double ntheta_upper_inner = 4; double ntheta_lower_outer = 6; - double ntheta_middle_outer = 6*2; + double ntheta_middle_outer = 6 * 2; double ntheta_upper_outer = 6; - double ncuts_lower_inner = 1;//ntheta_lower_inner; - double ncuts_middle_inner = 1;//ntheta_middle_inner; - double ncuts_upper_inner = 1;//ntheta_upper_inner; + double ncuts_lower_inner = 1; //ntheta_lower_inner; + double ncuts_middle_inner = 1; //ntheta_middle_inner; + double ncuts_upper_inner = 1; //ntheta_upper_inner; - double ncuts_lower_outer = 1;//ntheta_lower_outer; - double ncuts_middle_outer = 1;//ntheta_middle_outer; - double ncuts_upper_outer = 1;//ntheta_upper_outer; + double ncuts_lower_outer = 1; //ntheta_lower_outer; + double ncuts_middle_outer = 1; //ntheta_middle_outer; + double ncuts_upper_outer = 1; //ntheta_upper_outer; double zinner = 6.34; double zouter = 8.29; double rright_out = 5.2; - // Note that for tokamak multi-block simulations, - // these theta limits are just placeholders and will be + // Note that for tokamak multi-block simulations, + // these theta limits are just placeholders and will be // reset in the multi-block app. - double Lz = (M_PI-1e-14)*2.0; - double theta_lo = -Lz/2.0, theta_up = Lz/2.0; - - // block 0. Lower outer PF region. - gkyl_gk_block_geom_set_block(bgeom, 0, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_pf, theta_lo}, - .upper = { psi_up_pf, theta_up}, - .cells = { npsi_pf, ntheta_lower_outer }, - .cuts = { 1, ncuts_lower_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_R, - .rright = rright_out, - .rleft = 0.0, - .rmin = 1.7, - .rmax = 6.2, - .zmin_right = -zouter, - .zmin_left = -zinner, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_lower_inner, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 9, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + double Lz = (M_PI - 1e-14) * 2.0; + double theta_lo = -Lz / 2.0, theta_up = Lz / 2.0; + + // block 0. Lower outer PF region. + gkyl_gk_block_geom_set_block( + bgeom, 0, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_pf, theta_lo}, + .upper = {psi_up_pf, theta_up}, + .cells = {npsi_pf, ntheta_lower_outer}, + .cuts = {1, ncuts_lower_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_R, + .rright = rright_out, + .rleft = 0.0, + .rmin = 1.7, + .rmax = 6.2, + .zmin_right = -zouter, + .zmin_left = -zinner, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_lower_inner}}, + + .connections[0] = + { + // x-direction connections + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 9, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 1. Lower outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 1, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, theta_lo}, - .upper = { psi_up_outer_sol, theta_up}, - .cells = { npsi_outer_sol, ntheta_lower_outer}, - .cuts = { 1, ncuts_lower_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 0.0, // closest R to inboard SOL - .rmin = 0.7, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - .zmin = -zouter, - .zmax = zouter, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE } - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 1, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, theta_lo}, + .upper = {psi_up_outer_sol, theta_up}, + .cells = {npsi_outer_sol, ntheta_lower_outer}, + .cuts = {1, ncuts_lower_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 0.0, // closest R to inboard SOL + .rmin = 0.7, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false, // Whether to use cubic representation of psi(R,Z) for field line tracing + .zmin = -zouter, + .zmax = zouter, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 2. Middle outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 2, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, theta_lo }, - .upper = { psi_up_outer_sol, theta_up }, - .cells = { npsi_outer_sol, ntheta_middle_outer}, - .cuts = { 1, ncuts_middle_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 0.0, // closest R to inboard SOL - .rmin = 0.7, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - .zmin = -zouter, - .zmax = zouter, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 10, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 3, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 2, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, theta_lo}, + .upper = {psi_up_outer_sol, theta_up}, + .cells = {npsi_outer_sol, ntheta_middle_outer}, + .cuts = {1, ncuts_middle_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 0.0, // closest R to inboard SOL + .rmin = 0.7, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false, // Whether to use cubic representation of psi(R,Z) for field line tracing + .zmin = -zouter, + .zmax = zouter, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 10, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// z-direction connections + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 3. Upper outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 3, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, theta_lo }, - .upper = { psi_up_outer_sol, theta_up }, - .cells = { npsi_outer_sol, ntheta_upper_outer}, - .cuts = { 1, ncuts_upper_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 0.0, // closest R to inboard SOL - .rmin = 0.7, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - .zmin = -zouter, - .zmax = zouter, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 4, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 2, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 3, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, theta_lo}, + .upper = {psi_up_outer_sol, theta_up}, + .cells = {npsi_outer_sol, ntheta_upper_outer}, + .cuts = {1, ncuts_upper_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 0.0, // closest R to inboard SOL + .rmin = 0.7, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false, // Whether to use cubic representation of psi(R,Z) for field line tracing + .zmin = -zouter, + .zmax = zouter, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 4, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// z-direction connections + {.bid = 2, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }} ); // block 4. Upper outer PF region. - gkyl_gk_block_geom_set_block(bgeom, 4, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_pf, theta_lo}, - .upper = { psi_up_pf, theta_up}, - .cells = { npsi_pf, ntheta_upper_outer }, - .cuts = { 1, ncuts_upper_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_UP_R, - .rright = rright_out, - .rleft = 0.0, - .rmin = 1.7, - .rmax = 6.2, - .zmax_right = zouter, - .zmax_left = zinner, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_upper_inner, - .plate_func_upper = shaped_pfunc_upper_outer, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 5, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary - } - } + gkyl_gk_block_geom_set_block( + bgeom, 4, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_pf, theta_lo}, + .upper = {psi_up_pf, theta_up}, + .cells = {npsi_pf, ntheta_upper_outer}, + .cuts = {1, ncuts_upper_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_UP_R, + .rright = rright_out, + .rleft = 0.0, + .rmin = 1.7, + .rmax = 6.2, + .zmax_right = zouter, + .zmax_left = zinner, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_upper_inner, + .plate_func_upper = shaped_pfunc_upper_outer}}, + + .connections[0] = + { + // x-direction connections + {.bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + { + // z-direction connections + {.bid = 5, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); // block 5. Upper inner PF region. - gkyl_gk_block_geom_set_block(bgeom, 5, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_pf, theta_lo}, - .upper = { psi_up_pf, theta_up}, - .cells = { npsi_pf, ntheta_upper_inner }, - .cuts = { 1, ncuts_upper_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_UP_L, - .rright = rright_out, - .rleft = 0.0, - .rmin = 1.7, - .rmax = 6.2, - .zmax_right = zouter, - .zmax_left = zinner, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_upper_inner, - .plate_func_upper = shaped_pfunc_upper_outer, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 6, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + gkyl_gk_block_geom_set_block( + bgeom, 5, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_pf, theta_lo}, + .upper = {psi_up_pf, theta_up}, + .cells = {npsi_pf, ntheta_upper_inner}, + .cuts = {1, ncuts_upper_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_UP_L, + .rright = rright_out, + .rleft = 0.0, + .rmin = 1.7, + .rmax = 6.2, + .zmax_right = zouter, + .zmax_left = zinner, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_upper_inner, + .plate_func_upper = shaped_pfunc_upper_outer}}, + + .connections[0] = + { + // x-direction connections + {.bid = 6, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); - + // block 6. Upper inner SOL. - gkyl_gk_block_geom_set_block(bgeom, 6, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_inner_sol, theta_lo }, - .upper = { psi_up_inner_sol, theta_up }, - .cells = { npsi_inner_sol, ntheta_upper_inner}, - .cuts = { 1, ncuts_upper_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP, - .rleft = 2.0, - .rright= rright_out, - .rmin = 0.0, - .rmax = 6.2, - .zmin = -zinner, - .zmax = zinner, - .plate_spec = true, - .plate_func_upper = shaped_pfunc_upper_inner, - .plate_func_lower= shaped_pfunc_lower_inner, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 5, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 7, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + gkyl_gk_block_geom_set_block( + bgeom, 6, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_inner_sol, theta_lo}, + .upper = {psi_up_inner_sol, theta_up}, + .cells = {npsi_inner_sol, ntheta_upper_inner}, + .cuts = {1, ncuts_upper_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP, + .rleft = 2.0, + .rright = rright_out, + .rmin = 0.0, + .rmax = 6.2, + .zmin = -zinner, + .zmax = zinner, + .plate_spec = true, + .plate_func_upper = shaped_pfunc_upper_inner, + .plate_func_lower = shaped_pfunc_lower_inner}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 5, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 7, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); - + // block 7. Middle inner SOL. - gkyl_gk_block_geom_set_block(bgeom, 7, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_inner_sol, theta_lo }, - .upper = { psi_up_inner_sol, theta_up }, - .cells = { npsi_inner_sol, ntheta_middle_inner}, - .cuts = { 1, ncuts_middle_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID, - .rleft = 2.0, - .rright= rright_out, - .rmin = 0.0, - .rmax = 6.2, - .zmin = -zinner, - .zmax = zinner, - .plate_spec = true, - .plate_func_upper = shaped_pfunc_upper_inner, - .plate_func_lower= shaped_pfunc_lower_inner, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 11, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 6, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 8, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + gkyl_gk_block_geom_set_block( + bgeom, 7, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_inner_sol, theta_lo}, + .upper = {psi_up_inner_sol, theta_up}, + .cells = {npsi_inner_sol, ntheta_middle_inner}, + .cuts = {1, ncuts_middle_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID, + .rleft = 2.0, + .rright = rright_out, + .rmin = 0.0, + .rmax = 6.2, + .zmin = -zinner, + .zmax = zinner, + .plate_spec = true, + .plate_func_upper = shaped_pfunc_upper_inner, + .plate_func_lower = shaped_pfunc_lower_inner}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 11, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// z-direction connections + {.bid = 6, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 8, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 8. Lower inner SOL. - gkyl_gk_block_geom_set_block(bgeom, 8, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_inner_sol, theta_lo }, - .upper = { psi_up_inner_sol, theta_up }, - .cells = { npsi_inner_sol, ntheta_lower_inner}, - .cuts = { 1, ncuts_lower_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO, - .rleft = 2.0, - .rright= rright_out, - .rmin = 0.0, - .rmax = 6.2, - .zmin = -zinner, - .zmax = zinner, - .plate_spec = true, - .plate_func_upper = shaped_pfunc_upper_inner, - .plate_func_lower= shaped_pfunc_lower_inner, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 9, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 7, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} - } - } + gkyl_gk_block_geom_set_block( + bgeom, 8, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_inner_sol, theta_lo}, + .upper = {psi_up_inner_sol, theta_up}, + .cells = {npsi_inner_sol, ntheta_lower_inner}, + .cuts = {1, ncuts_lower_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO, + .rleft = 2.0, + .rright = rright_out, + .rmin = 0.0, + .rmax = 6.2, + .zmin = -zinner, + .zmax = zinner, + .plate_spec = true, + .plate_func_upper = shaped_pfunc_upper_inner, + .plate_func_lower = shaped_pfunc_lower_inner}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 9, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// z-direction connections + {.bid = 7, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }} ); // block 9. Lower inner PF region. - gkyl_gk_block_geom_set_block(bgeom, 9, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_pf, theta_lo}, - .upper = { psi_up_pf, theta_up}, - .cells = { npsi_pf, ntheta_lower_inner }, - .cuts = { 1, ncuts_lower_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_L, - .rright = rright_out, - .rleft = 0.0, - .rmin = 1.7, - .rmax = 6.2, - .zmin_right = -zouter, - .zmin_left = -zinner, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_lower_inner, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 8, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary - } - } + gkyl_gk_block_geom_set_block( + bgeom, 9, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_pf, theta_lo}, + .upper = {psi_up_pf, theta_up}, + .cells = {npsi_pf, ntheta_lower_inner}, + .cuts = {1, ncuts_lower_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_L, + .rright = rright_out, + .rleft = 0.0, + .rmin = 1.7, + .rmax = 6.2, + .zmin_right = -zouter, + .zmin_left = -zinner, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_lower_inner}}, + + .connections[0] = + { + // x-direction connections + {.bid = 8, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + { + // z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); - // block 10. outer core. - gkyl_gk_block_geom_set_block(bgeom, 10, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_core, theta_lo}, - .upper = { psi_up_core, theta_up}, - .cells = { npsi_core, ntheta_middle_outer}, - .cuts = { 1, ncuts_middle_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_R, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 2.0, // closest R to inboard SOL - .rmin = 1.58, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - } - }, - - .connections[0] = { // x-direction connections - { .bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 11, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, // physical boundary - { .bid = 11, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 10, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_core, theta_lo}, + .upper = {psi_up_core, theta_up}, + .cells = {npsi_core, ntheta_middle_outer}, + .cuts = {1, ncuts_middle_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = + (struct gkyl_tok_geo_grid_inp){ + .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_R, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 2.0, // closest R to inboard SOL + .rmin = 1.58, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false // Whether to use cubic representation of psi(R,Z) for field line tracing + }}, + + .connections[0] = + { + // x-direction connections + {.bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + {// z-direction connections + {.bid = 11, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, // physical boundary + {.bid = 11, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 11. Inner Core. - gkyl_gk_block_geom_set_block(bgeom, 11, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_core, theta_lo }, - .upper = { psi_up_core, theta_up }, - .cells = { npsi_core, ntheta_middle_inner}, - .cuts = { 1, ncuts_middle_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_L, - .rclose = 0.0, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 2.0, // closest R to inboard SOL - .rmin = 1.58, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - } - }, - - .connections[0] = { // x-direction connections - { .bid = 7, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 10, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 10, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + gkyl_gk_block_geom_set_block( + bgeom, 11, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_core, theta_lo}, + .upper = {psi_up_core, theta_up}, + .cells = {npsi_core, ntheta_middle_inner}, + .cuts = {1, ncuts_middle_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = + (struct gkyl_tok_geo_grid_inp){ + .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_L, + .rclose = 0.0, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 2.0, // closest R to inboard SOL + .rmin = 1.58, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false // Whether to use cubic representation of psi(R,Z) for field line tracing + }}, + + .connections[0] = + { + // x-direction connections + {.bid = 7, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + {// z-direction connections + {.bid = 10, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 10, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); return bgeom; @@ -604,57 +634,60 @@ struct gk_step_ctx { double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct gk_step_ctx -create_ctx(void) +struct gk_step_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge double n_fac = 1.0; - double temp_fac = 9.0/n_fac; + double temp_fac = 9.0 / n_fac; - double Te = 1500.0/temp_fac*eV; - double Ti = 1500.0/temp_fac*eV; + double Te = 1500.0 / temp_fac * eV; + double Ti = 1500.0 / temp_fac * eV; double B0 = 2.51; // Magnetic field magnitude in Tesla - double n0 = 3.0e19/n_fac; // Particle density in 1/m^3 - + double n0 = 3.0e19 / n_fac; // Particle density in 1/m^3 + // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); // Source parameters - double nsource = 1.675e22*2.5*temp_fac/6.0; - double T_source = 3000.0*eV/temp_fac; + double nsource = 1.675e22 * 2.5 * temp_fac / 6.0; + double T_source = 3000.0 * eV / temp_fac; double cx = 0.0065612; - double cz = 0.4916200*1.4; + double cz = 0.4916200 * 1.4; double psisep = 1.5093065418975686; //This is the value from efit // Collision parameters. double nuFrac = 0.25; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nuFrac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); // collision freq + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nuFrac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te)) + ); // collision freq - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nuIon = nuFrac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mi)*(Ti*sqrt(Ti))); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nuIon = nuFrac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mi) * (Ti * sqrt(Ti))); // Simulation box size (m). - double vpar_max_elc = 8.0*vtElc; - double mu_max_elc = 18*me*vtElc*vtElc/(2.0*B0); + double vpar_max_elc = 8.0 * vtElc; + double mu_max_elc = 18 * me * vtElc * vtElc / (2.0 * B0); - double vpar_max_ion = 8.0*vtIon; - double mu_max_ion = 18*mi*vtIon*vtIon/(2.0*B0); + double vpar_max_ion = 8.0 * vtIon; + double mu_max_ion = 18 * mi * vtIon * vtIon / (2.0 * B0); // Number of cells. int Nx = 4; @@ -662,56 +695,56 @@ create_ctx(void) int Nvpar = 16; int Nmu = 12; - double t_end = 100.0e-10; + double t_end = 100.0e-10; double num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_step_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, - .Te = Te, - .Ti = Ti, + .Te = Te, + .Ti = Ti, .vtIon = vtIon, .vtElc = vtElc, - .nuElc = nuElc, - .nuIon = nuIon, + .nuElc = nuElc, + .nuIon = nuIon, .nuFrac = nuFrac, - .B0 = B0, - .n0 = n0, + .B0 = B0, + .n0 = n0, .nsource = nsource, - .T_source = T_source, + .T_source = T_source, .temp_fac = temp_fac, .n_fac = n_fac, .cx = cx, .cz = cz, - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .Nx = Nx, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -init_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; @@ -720,8 +753,9 @@ init_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fo fout[0] = n0; } -void -init_density_core(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_core( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //1.5e20 at inner core and 2e19 at sep double x = xn[0], z = xn[1]; @@ -731,12 +765,13 @@ init_density_core(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI double n_fac = app->n_fac; double slope = 3.0e20; double intercept = -4.22792e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } -void -init_density_outer(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_outer( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -746,12 +781,13 @@ init_density_outer(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTR double n_fac = app->n_fac; double slope = 2.7e20; double intercept = -3.77513e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } -void -init_density_inner(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_inner( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -761,12 +797,11 @@ init_density_inner(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTR double n_fac = app->n_fac; double slope = 5.4e20; double intercept = -7.85026e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } -void -init_density_pf(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_pf(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -776,46 +811,42 @@ init_density_pf(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT double n_fac = app->n_fac; double slope = -5.4e20; double intercept = 8.45026e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } -void -source_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void source_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; struct gk_step_ctx *app = ctx; double nsource = app->nsource; - if(x >= 1.5593065418975687) + if (x >= 1.5593065418975687) { fout[0] = nsource; - else - fout[0] = nsource*1.0e-5; + } else { + fout[0] = nsource * 1.0e-5; + } } -void -init_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_upar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void -init_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; - double T = 2.0*app->Te; + double T = 2.0 * app->Te; fout[0] = T; } -void -init_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; - double T = 2.0*app->Ti; + double T = 2.0 * app->Ti; fout[0] = T; } -void -source_temp(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void source_temp(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double T = app->T_source; @@ -823,7 +854,7 @@ source_temp(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_step_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -835,21 +866,23 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v double vpar = 0.0; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vpar = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vpar = -vpar_max_elc*2.0*pow(cvpar,2); - else - vpar = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vpar = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vpar = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vpar = vpar_max_elc * 2.0 * pow(cvpar, 2); + } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } static inline void -mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_ion(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_step_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -861,34 +894,38 @@ mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v double vpar = 0.0; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vpar = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vpar = -vpar_max_ion*2.0*pow(cvpar,2); - else - vpar = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vpar = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vpar = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vpar = vpar_max_ion * 2.0 * pow(cvpar, 2); + } mu = mu_max_ion * (cmu * cmu); // Set rescaled ion velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar ; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; fout[0] = 0.22; // Diffusivity [m^2/s]. } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -903,10 +940,12 @@ main(int argc, char **argv) int nblocks = gkyl_gk_block_geom_num_blocks(bgeom); int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcdim = ctx.cdim; app_inp->poly_order = 1; app_inp->basis_type = app_args.basis_type; @@ -1662,17 +1674,16 @@ main(int argc, char **argv) struct gkyl_gyrokinetic_run_inp run_inp = { .app_type = GKYL_GK_MULTIB, .multib_app_inp = *app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = app_args.num_steps, - }, + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = app_args.num_steps} }; gkyl_gyrokinetic_run_simulation(&run_inp); @@ -1682,8 +1693,9 @@ main(int argc, char **argv) gkyl_free(app_inp); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif return 0; diff --git a/gyrokinetic/creg/rt_gk_multib_step_eirene_2x2v_p1.c b/gyrokinetic/creg/rt_gk_multib_step_eirene_2x2v_p1.c index cd1bb0ba29..ca9d400a1e 100644 --- a/gyrokinetic/creg/rt_gk_multib_step_eirene_2x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_multib_step_eirene_2x2v_p1.c @@ -8,45 +8,49 @@ #include // Outer plates for angle of 3.05 degrees -void shaped_pfunc_lower_outer(double s, double* RZ){ - double p0[2] = {5.488-0.6,-8.538}; - double p1[2] = {5.855-0.6,-8.52318}; - p1[0] = (p1[0] - p0[0])*2 + p1[0]; - p1[1] = (p1[1] - p0[1])*2 + p1[1]; - RZ[0] = (1-s)*p0[0]+s*p1[0]; - RZ[1] = (1-s)*p0[1]+s*p1[1]; +void shaped_pfunc_lower_outer(double s, double *RZ) +{ + double p0[2] = {5.488 - 0.6, -8.538}; + double p1[2] = {5.855 - 0.6, -8.52318}; + p1[0] = (p1[0] - p0[0]) * 2 + p1[0]; + p1[1] = (p1[1] - p0[1]) * 2 + p1[1]; + RZ[0] = (1 - s) * p0[0] + s * p1[0]; + RZ[1] = (1 - s) * p0[1] + s * p1[1]; } -void shaped_pfunc_upper_outer(double s, double* RZ){ - double p0[2] = {5.488-0.6,8.538}; - double p1[2] = {5.855-0.6,8.52318}; - p1[0] = (p1[0] - p0[0])*2 + p1[0]; - p1[1] = (p1[1] - p0[1])*2 + p1[1]; - RZ[0] = (1-s)*p0[0]+s*p1[0]; - RZ[1] = (1-s)*p0[1]+s*p1[1]; +void shaped_pfunc_upper_outer(double s, double *RZ) +{ + double p0[2] = {5.488 - 0.6, 8.538}; + double p1[2] = {5.855 - 0.6, 8.52318}; + p1[0] = (p1[0] - p0[0]) * 2 + p1[0]; + p1[1] = (p1[1] - p0[1]) * 2 + p1[1]; + RZ[0] = (1 - s) * p0[0] + s * p1[0]; + RZ[1] = (1 - s) * p0[1] + s * p1[1]; } //old inner plates -void shaped_pfunc_upper_inner(double s, double* RZ){ - RZ[0] = 1.651 + (1.8 - 1.651)*s; - RZ[1] = 6.331 + (6.777 - 6.331)*s; +void shaped_pfunc_upper_inner(double s, double *RZ) +{ + RZ[0] = 1.651 + (1.8 - 1.651) * s; + RZ[1] = 6.331 + (6.777 - 6.331) * s; } -void shaped_pfunc_lower_inner(double s, double* RZ){ - RZ[0] = 1.651 + (1.8 - 1.651)*s; - RZ[1] = -(6.331 + (6.777 - 6.331)*s); +void shaped_pfunc_lower_inner(double s, double *RZ) +{ + RZ[0] = 1.651 + (1.8 - 1.651) * s; + RZ[1] = -(6.331 + (6.777 - 6.331) * s); } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; fout[0] = 0.5; // Diffusivity [m^2/s]. } -struct gkyl_gk_block_geom* -create_gk_block_geom(void) +struct gkyl_gk_block_geom *create_gk_block_geom(void) { struct gkyl_gk_block_geom *bgeom = gkyl_gk_block_geom_new(2, 8); @@ -81,14 +85,13 @@ create_gk_block_geom(void) symbol such as o,x,%, or % are instead connected to the other edge with the same symbol. Edges that do not coincide with another edge are a physical boundary. - */ - + */ struct gkyl_efit_inp efit_inp = { .filepath = "gyrokinetic/data/eqdsk/step.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; struct gkyl_efit *efit = gkyl_efit_new(&efit_inp); @@ -110,7 +113,7 @@ create_gk_block_geom(void) double psi_lo_pf = psisep; double psi_up_pf = psisep + wpf; - double psi_lo_inner_sol = psisep - win ; + double psi_lo_inner_sol = psisep - win; double psi_up_inner_sol = psisep; int npsi_outer_sol = 8; @@ -118,375 +121,386 @@ create_gk_block_geom(void) int npsi_pf = 4; int npsi_inner_sol = 4; - double ntheta_lower_inner = 4; - double ntheta_middle_inner = 8*2; - double ntheta_upper_inner = 4; + double ntheta_lower_inner = 4; + double ntheta_middle_inner = 8 * 2; + double ntheta_upper_inner = 4; double ntheta_lower_outer = 8; - double ntheta_middle_outer = 12*2; + double ntheta_middle_outer = 12 * 2; double ntheta_upper_outer = 8; - double ncuts_lower_inner = 1;//ntheta_lower_inner; - double ncuts_middle_inner = 1;//ntheta_middle_inner; - double ncuts_upper_inner = 1;//ntheta_upper_inner; + double ncuts_lower_inner = 1; //ntheta_lower_inner; + double ncuts_middle_inner = 1; //ntheta_middle_inner; + double ncuts_upper_inner = 1; //ntheta_upper_inner; - double ncuts_lower_outer = 1;//ntheta_lower_outer; - double ncuts_middle_outer = 1;//ntheta_middle_outer; - double ncuts_upper_outer = 1;//ntheta_upper_outer; + double ncuts_lower_outer = 1; //ntheta_lower_outer; + double ncuts_middle_outer = 1; //ntheta_middle_outer; + double ncuts_upper_outer = 1; //ntheta_upper_outer; double zinner = 6.34; double zouter = 8.29; double rright_out = 5.2; - double Lz = (M_PI-1e-14)*2.0; - double theta_lo = -Lz/2.0, theta_up = Lz/2.0; + double Lz = (M_PI - 1e-14) * 2.0; + double theta_lo = -Lz / 2.0, theta_up = Lz / 2.0; double compression_factor = 0.5; double radial_compression_factor = 0.5; double radial_compression_factor_none = 0.0; // block 0. Lower outer PF region. - gkyl_gk_block_geom_set_block(bgeom, 0, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_pf, theta_lo}, - .upper = { psi_up_pf, theta_up}, - .cells = { npsi_pf, ntheta_lower_outer }, - .cuts = { 1, ncuts_lower_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_FROMFILE, - .geometry_path = "./gyrokinetic/data/eirene/", - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_R, - .half_domain=true, - .rright = rright_out, - .rleft = 0.0, - .rmin = 1.7, - .rmax = 6.2, - .zmin_right = -zouter, - .zmin_left = -zinner, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_lower_inner, + gkyl_gk_block_geom_set_block( + bgeom, 0, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_pf, theta_lo}, + .upper = {psi_up_pf, theta_up}, + .cells = {npsi_pf, ntheta_lower_outer}, + .cuts = {1, ncuts_lower_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_FROMFILE, + .geometry_path = "./gyrokinetic/data/eirene/", + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_R, + .half_domain = true, + .rright = rright_out, + .rleft = 0.0, + .rmin = 1.7, + .rmax = 6.2, + .zmin_right = -zouter, + .zmin_left = -zinner, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_lower_inner}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = radial_compression_factor, + .compression_factor = compression_factor}}, + + .connections[0] = + { + // x-direction connections + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor=true, - .radial_compression_factor = radial_compression_factor, - .compression_factor = compression_factor - } - }, - - .connections[0] = { // x-direction connections - { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 5, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 5, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 1. Lower outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 1, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, theta_lo}, - .upper = { psi_up_outer_sol, theta_up}, - .cells = { npsi_outer_sol, ntheta_lower_outer}, - .cuts = { 1, ncuts_lower_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_FROMFILE, - .geometry_path = "./gyrokinetic/data/eirene/", - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, - .half_domain=true, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 0.0, // closest R to inboard SOL - .rmin = 0.7, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - .zmin = -zouter, - .zmax = zouter, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, + gkyl_gk_block_geom_set_block( + bgeom, 1, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, theta_lo}, + .upper = {psi_up_outer_sol, theta_up}, + .cells = {npsi_outer_sol, ntheta_lower_outer}, + .cuts = {1, ncuts_lower_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_FROMFILE, + .geometry_path = "./gyrokinetic/data/eirene/", + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, + .half_domain = true, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 0.0, // closest R to inboard SOL + .rmin = 0.7, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false, // Whether to use cubic representation of psi(R,Z) for field line tracing + .zmin = -zouter, + .zmax = zouter, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = radial_compression_factor, + .compression_factor = compression_factor}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor=true, - .radial_compression_factor = radial_compression_factor, - .compression_factor = compression_factor - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE } - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 2. Middle outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 2, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, theta_lo }, - .upper = { psi_up_outer_sol, theta_up }, - .cells = { npsi_outer_sol, ntheta_middle_outer}, - .cuts = { 1, ncuts_middle_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_FROMFILE, - .geometry_path = "./gyrokinetic/data/eirene/", - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, - .half_domain=true, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 0.0, // closest R to inboard SOL - .rmin = 0.7, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - .zmin = -zouter, - .zmax = zouter, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, + gkyl_gk_block_geom_set_block( + bgeom, 2, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, theta_lo}, + .upper = {psi_up_outer_sol, theta_up}, + .cells = {npsi_outer_sol, ntheta_middle_outer}, + .cuts = {1, ncuts_middle_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_FROMFILE, + .geometry_path = "./gyrokinetic/data/eirene/", + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, + .half_domain = true, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 0.0, // closest R to inboard SOL + .rmin = 0.7, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false, // Whether to use cubic representation of psi(R,Z) for field line tracing + .zmin = -zouter, + .zmax = zouter, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = radial_compression_factor, + .compression_factor = compression_factor}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 6, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor=true, - .radial_compression_factor = radial_compression_factor, - .compression_factor = compression_factor - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 6, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - } - } + .connections[1] = + {// z-direction connections + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }} ); - // block 7. Middle inner SOL. - gkyl_gk_block_geom_set_block(bgeom, 3, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_inner_sol, theta_lo }, - .upper = { psi_up_inner_sol, theta_up }, - .cells = { npsi_inner_sol, ntheta_middle_inner}, - .cuts = { 1, ncuts_middle_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_FROMFILE, - .geometry_path = "./gyrokinetic/data/eirene/", - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID, - .half_domain=true, - .rleft = 2.0, - .rright= rright_out, - .rmin = 0.0, - .rmax = 6.2, - .zmin = -zinner, - .zmax = zinner, - .plate_spec = true, - .plate_func_upper = shaped_pfunc_upper_inner, - .plate_func_lower= shaped_pfunc_lower_inner, + gkyl_gk_block_geom_set_block( + bgeom, 3, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_inner_sol, theta_lo}, + .upper = {psi_up_inner_sol, theta_up}, + .cells = {npsi_inner_sol, ntheta_middle_inner}, + .cuts = {1, ncuts_middle_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_FROMFILE, + .geometry_path = "./gyrokinetic/data/eirene/", + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID, + .half_domain = true, + .rleft = 2.0, + .rright = rright_out, + .rmin = 0.0, + .rmax = 6.2, + .zmin = -zinner, + .zmax = zinner, + .plate_spec = true, + .plate_func_upper = shaped_pfunc_upper_inner, + .plate_func_lower = shaped_pfunc_lower_inner}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = radial_compression_factor_none, + .compression_factor = compression_factor}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 7, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor=true, - .radial_compression_factor = radial_compression_factor_none, - .compression_factor = compression_factor - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 7, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - { .bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 8. Lower inner SOL. - gkyl_gk_block_geom_set_block(bgeom, 4, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_inner_sol, theta_lo }, - .upper = { psi_up_inner_sol, theta_up }, - .cells = { npsi_inner_sol, ntheta_lower_inner}, - .cuts = { 1, ncuts_lower_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_FROMFILE, - .geometry_path = "./gyrokinetic/data/eirene/", - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO, - .half_domain=true, - .rleft = 2.0, - .rright= rright_out, - .rmin = 0.0, - .rmax = 6.2, - .zmin = -zinner, - .zmax = zinner, - .plate_spec = true, - .plate_func_upper = shaped_pfunc_upper_inner, - .plate_func_lower= shaped_pfunc_lower_inner, + gkyl_gk_block_geom_set_block( + bgeom, 4, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_inner_sol, theta_lo}, + .upper = {psi_up_inner_sol, theta_up}, + .cells = {npsi_inner_sol, ntheta_lower_inner}, + .cuts = {1, ncuts_lower_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_FROMFILE, + .geometry_path = "./gyrokinetic/data/eirene/", + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO, + .half_domain = true, + .rleft = 2.0, + .rright = rright_out, + .rmin = 0.0, + .rmax = 6.2, + .zmin = -zinner, + .zmax = zinner, + .plate_spec = true, + .plate_func_upper = shaped_pfunc_upper_inner, + .plate_func_lower = shaped_pfunc_lower_inner}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = radial_compression_factor_none, + .compression_factor = compression_factor}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 5, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor=true, - .radial_compression_factor = radial_compression_factor_none, - .compression_factor = compression_factor - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 5, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 3, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} - } - } + .connections[1] = + {// z-direction connections + {.bid = 3, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }} ); // block 9. Lower inner PF region. - gkyl_gk_block_geom_set_block(bgeom, 5, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_pf, theta_lo}, - .upper = { psi_up_pf, theta_up}, - .cells = { npsi_pf, ntheta_lower_inner }, - .cuts = { 1, ncuts_lower_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_FROMFILE, - .geometry_path = "./gyrokinetic/data/eirene/", - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_L, - .half_domain=true, - .rright = rright_out, - .rleft = 0.0, - .rmin = 1.7, - .rmax = 6.2, - .zmin_right = -zouter, - .zmin_left = -zinner, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_lower_inner, + gkyl_gk_block_geom_set_block( + bgeom, 5, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_pf, theta_lo}, + .upper = {psi_up_pf, theta_up}, + .cells = {npsi_pf, ntheta_lower_inner}, + .cuts = {1, ncuts_lower_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_FROMFILE, + .geometry_path = "./gyrokinetic/data/eirene/", + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_L, + .half_domain = true, + .rright = rright_out, + .rleft = 0.0, + .rmin = 1.7, + .rmax = 6.2, + .zmin_right = -zouter, + .zmin_left = -zinner, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_lower_inner}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = radial_compression_factor, + .compression_factor = compression_factor}}, + + .connections[0] = + { + // x-direction connections + {.bid = 4, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor=true, - .radial_compression_factor = radial_compression_factor, - .compression_factor = compression_factor - } - }, - - .connections[0] = { // x-direction connections - { .bid = 4, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary - } - } + .connections[1] = + { + // z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); - // block 10. outer core. - gkyl_gk_block_geom_set_block(bgeom, 6, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_core, theta_lo}, - .upper = { psi_up_core, theta_up}, - .cells = { npsi_core, ntheta_middle_outer}, - .cuts = { 1, ncuts_middle_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_FROMFILE, - .geometry_path = "./gyrokinetic/data/eirene/", - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_R, - .half_domain=true, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 2.0, // closest R to inboard SOL - .rmin = 1.58, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing + gkyl_gk_block_geom_set_block( + bgeom, 6, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_core, theta_lo}, + .upper = {psi_up_core, theta_up}, + .cells = {npsi_core, ntheta_middle_outer}, + .cuts = {1, ncuts_middle_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_FROMFILE, + .geometry_path = "./gyrokinetic/data/eirene/", + .efit_info = efit_inp, + .tok_grid_info = + (struct gkyl_tok_geo_grid_inp){ + .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_R, + .half_domain = true, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 2.0, // closest R to inboard SOL + .rmin = 1.58, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false // Whether to use cubic representation of psi(R,Z) for field line tracing + }, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = radial_compression_factor_none, + .compression_factor = compression_factor}}, + + .connections[0] = + { + // x-direction connections + {.bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor=true, - .radial_compression_factor = radial_compression_factor_none, - .compression_factor = compression_factor - } - }, - - .connections[0] = { // x-direction connections - { .bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 7, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, // physical boundary - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - } - } + .connections[1] = + {// z-direction connections + {.bid = 7, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, // physical boundary + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }} ); // block 11. Inner Core. - gkyl_gk_block_geom_set_block(bgeom, 7, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_core, theta_lo }, - .upper = { psi_up_core, theta_up }, - .cells = { npsi_core, ntheta_middle_inner}, - .cuts = { 1, ncuts_middle_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_FROMFILE, - .geometry_path = "./gyrokinetic/data/eirene/", - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_L, - .half_domain=true, - .rclose = 0.0, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 2.0, // closest R to inboard SOL - .rmin = 1.58, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing + gkyl_gk_block_geom_set_block( + bgeom, 7, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_core, theta_lo}, + .upper = {psi_up_core, theta_up}, + .cells = {npsi_core, ntheta_middle_inner}, + .cuts = {1, ncuts_middle_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_FROMFILE, + .geometry_path = "./gyrokinetic/data/eirene/", + .efit_info = efit_inp, + .tok_grid_info = + (struct gkyl_tok_geo_grid_inp){ + .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_L, + .half_domain = true, + .rclose = 0.0, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 2.0, // closest R to inboard SOL + .rmin = 1.58, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false // Whether to use cubic representation of psi(R,Z) for field line tracing + }, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = radial_compression_factor_none, + .compression_factor = compression_factor}}, + + .connections[0] = + { + // x-direction connections + {.bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor=true, - .radial_compression_factor = radial_compression_factor_none, - .compression_factor = compression_factor - } - }, - - .connections[0] = { // x-direction connections - { .bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - { .bid = 6, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 6, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); return bgeom; @@ -529,36 +543,31 @@ struct gk_step_ctx { double write_phase_freq; }; - - -struct gk_step_ctx -create_ctx(void) +struct gk_step_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge - double n_fac = 32.0; - double temp_fac = 9.0/n_fac; + double temp_fac = 9.0 / n_fac; - double Te = 1500.0/temp_fac*eV; - double Ti = 1500.0/temp_fac*eV; + double Te = 1500.0 / temp_fac * eV; + double Ti = 1500.0 / temp_fac * eV; double B0 = 2.51; // Magnetic field magnitude in Tesla - double n0 = 3.0e19/n_fac; // Particle density in 1/m^3 - - // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); + double n0 = 3.0e19 / n_fac; // Particle density in 1/m^3 + // Derived parameters. + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); - double nsource = 1.675e22*2.5*temp_fac/6.0; - double Tsource = 3000.0*eV/temp_fac; + double nsource = 1.675e22 * 2.5 * temp_fac / 6.0; + double Tsource = 3000.0 * eV / temp_fac; double psisep = 1.5093065418975686; //This is the value from efit double xcenter = psisep; @@ -567,14 +576,11 @@ create_ctx(void) // Simulation box size (m). - double vpar_max_elc = 6.0*vtElc; - double mu_max_elc = 36*me*vtElc*vtElc/(2.0*B0); - - double vpar_max_ion = 8.0*vtIon; - double mu_max_ion = 36*mi*vtIon*vtIon/(2.0*B0); - - + double vpar_max_elc = 6.0 * vtElc; + double mu_max_elc = 36 * me * vtElc * vtElc / (2.0 * B0); + double vpar_max_ion = 8.0 * vtIon; + double mu_max_ion = 36 * mi * vtIon * vtIon / (2.0 * B0); // Number of cells. int Nx = 4; @@ -584,7 +590,7 @@ create_ctx(void) double t_end = 2.0e-9; double num_frames = 1; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-2; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double write_phase_freq = 0.2; @@ -592,44 +598,42 @@ create_ctx(void) struct gk_step_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, - .Te = Te, - .Ti = Ti, + .Te = Te, + .Ti = Ti, .vtIon = vtIon, .vtElc = vtElc, .nu_frac = nu_frac, - .B0 = B0, - .n0 = n0, + .B0 = B0, + .n0 = n0, .nsource = nsource, .Tsource = Tsource, .temp_fac = temp_fac, .n_fac = n_fac, .xcenter = xcenter, - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .Nx = Nx, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .write_phase_freq = write_phase_freq, + .write_phase_freq = write_phase_freq }; return ctx; } - -void -init_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; @@ -638,8 +642,9 @@ init_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fo fout[0] = n0; } -void -init_density_core(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_core( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //1.5e20 at inner core and 2e19 at sep double x = xn[0], z = xn[1]; @@ -649,12 +654,13 @@ init_density_core(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI double n_fac = app->n_fac; double slope = 3.0e20; double intercept = -4.22792e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } -void -init_density_outer(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_outer( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -664,12 +670,13 @@ init_density_outer(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTR double n_fac = app->n_fac; double slope = 2.7e20; double intercept = -3.77513e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } -void -init_density_inner(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_inner( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -679,12 +686,11 @@ init_density_inner(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTR double n_fac = app->n_fac; double slope = 5.4e20; double intercept = -7.85026e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } -void -init_density_pf(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_pf(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -694,12 +700,13 @@ init_density_pf(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT double n_fac = app->n_fac; double slope = -5.4e20; double intercept = 8.45026e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } -void -init_density_core_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_core_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //1.5e20 at inner core and 2e19 at sep double x = xn[0], z = xn[1]; @@ -709,12 +716,13 @@ init_density_core_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RE double n_fac = app->n_fac; double slope = 3.0e20; double intercept = -4.22792e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } -void -init_density_outer_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_outer_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -724,12 +732,13 @@ init_density_outer_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_R double n_fac = app->n_fac; double slope = 2.7e20; double intercept = -3.77513e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } -void -init_density_inner_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_inner_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -739,12 +748,13 @@ init_density_inner_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_R double n_fac = app->n_fac; double slope = 5.4e20; double intercept = -7.85026e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } -void -init_density_pf_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_pf_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -754,49 +764,43 @@ init_density_pf_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_REST double n_fac = app->n_fac; double slope = -5.4e20; double intercept = 8.45026e+20; - double n = slope*x + intercept; - fout[0] = n/n_fac; + double n = slope * x + intercept; + fout[0] = n / n_fac; } - -void -source_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void source_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; struct gk_step_ctx *app = ctx; double nsource = app->nsource; - if(x >= 1.5593065418975687) + if (x >= 1.5593065418975687) { fout[0] = nsource; - else - fout[0] = nsource*1.0e-5; + } else { + fout[0] = nsource * 1.0e-5; + } } - -void -init_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_upar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void -init_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; - double T = 2.0*app->Te; + double T = 2.0 * app->Te; fout[0] = T; } -void -init_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; - double T = 2.0*app->Ti; + double T = 2.0 * app->Ti; fout[0] = T; } -void -source_temp(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void source_temp(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double T = app->Tsource; @@ -804,7 +808,7 @@ source_temp(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_step_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -816,21 +820,23 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v double vpar = 0.0; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vpar = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vpar = -vpar_max_elc*2.0*pow(cvpar,2); - else - vpar = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vpar = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vpar = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vpar = vpar_max_elc * 2.0 * pow(cvpar, 2); + } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } static inline void -mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_ion(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_step_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -842,36 +848,42 @@ mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v double vpar = 0.0; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vpar = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vpar = -vpar_max_ion*2.0*pow(cvpar,2); - else - vpar = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vpar = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vpar = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vpar = vpar_max_ion * 2.0 * pow(cvpar, 2); + } mu = mu_max_ion * (cmu * cmu); // Set rescaled ion velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar ; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -void -calc_integrated_diagnostics(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_multib_app* app, double t_curr, double dt, bool force_calc) +void calc_integrated_diagnostics( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_multib_app *app, double t_curr, double dt, + bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_calc) { gkyl_gyrokinetic_multib_app_calc_field_energy(app, t_curr); gkyl_gyrokinetic_multib_app_calc_integrated_mom(app, t_curr); - if ( !(dt < 0.0) ) + if (!(dt < 0.0)) { gkyl_gyrokinetic_multib_app_save_dt(app, t_curr, dt); + } } } -static void -write_data(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_multib_app* app, double t_curr, bool force_write) +static void write_data( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_multib_app *app, double t_curr, bool force_write +) { bool trig_now = gkyl_tm_trigger_check_and_bump(iot, t_curr); if (trig_now || force_write) { - int frame = (!trig_now) && force_write? iot->curr : iot->curr-1; + int frame = (!trig_now) && force_write ? iot->curr : iot->curr - 1; gkyl_gyrokinetic_multib_app_write(app, t_curr, frame); gkyl_gyrokinetic_multib_app_write_field_energy(app); @@ -880,13 +892,14 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_multib_app* app, double } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -904,590 +917,566 @@ main(int argc, char **argv) struct gk_step_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcdim = ctx.cdim; app_inp->poly_order = 1; app_inp->basis_type = app_args.basis_type; @@ -1507,22 +1496,17 @@ main(int argc, char **argv) struct gkyl_gyrokinetic_run_inp run_inp = { .app_type = GKYL_GK_MULTIB, .multib_app_inp = *app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = app_args.num_steps, - }, - .print_verbosity = { - .enabled = true, - .frequency = 0.001, - .estimate_completion_time = true, - }, + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = app_args.num_steps}, + .print_verbosity = {.enabled = true, .frequency = 0.001, .estimate_completion_time = true} }; gkyl_gyrokinetic_run_simulation(&run_inp); @@ -1532,8 +1516,9 @@ main(int argc, char **argv) gkyl_free(app_inp); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif return 0; diff --git a/gyrokinetic/creg/rt_gk_multib_step_nonuniform_2x2v_p1.c b/gyrokinetic/creg/rt_gk_multib_step_nonuniform_2x2v_p1.c index abe718cfdc..14e024e799 100644 --- a/gyrokinetic/creg/rt_gk_multib_step_nonuniform_2x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_multib_step_nonuniform_2x2v_p1.c @@ -15,45 +15,49 @@ #endif // Outer plates for angle of 3.05 degrees -void shaped_pfunc_lower_outer(double s, double* RZ){ - double p0[2] = {5.488-0.6,-8.538}; - double p1[2] = {5.855-0.6,-8.52318}; - p1[0] = (p1[0] - p0[0])*3 + p1[0]; - p1[1] = (p1[1] - p0[1])*3 + p1[1]; - RZ[0] = (1-s)*p0[0]+s*p1[0]; - RZ[1] = (1-s)*p0[1]+s*p1[1]; +void shaped_pfunc_lower_outer(double s, double *RZ) +{ + double p0[2] = {5.488 - 0.6, -8.538}; + double p1[2] = {5.855 - 0.6, -8.52318}; + p1[0] = (p1[0] - p0[0]) * 3 + p1[0]; + p1[1] = (p1[1] - p0[1]) * 3 + p1[1]; + RZ[0] = (1 - s) * p0[0] + s * p1[0]; + RZ[1] = (1 - s) * p0[1] + s * p1[1]; } -void shaped_pfunc_upper_outer(double s, double* RZ){ - double p0[2] = {5.488-0.6,8.538}; - double p1[2] = {5.855-0.6,8.52318}; - p1[0] = (p1[0] - p0[0])*3 + p1[0]; - p1[1] = (p1[1] - p0[1])*3 + p1[1]; - RZ[0] = (1-s)*p0[0]+s*p1[0]; - RZ[1] = (1-s)*p0[1]+s*p1[1]; +void shaped_pfunc_upper_outer(double s, double *RZ) +{ + double p0[2] = {5.488 - 0.6, 8.538}; + double p1[2] = {5.855 - 0.6, 8.52318}; + p1[0] = (p1[0] - p0[0]) * 3 + p1[0]; + p1[1] = (p1[1] - p0[1]) * 3 + p1[1]; + RZ[0] = (1 - s) * p0[0] + s * p1[0]; + RZ[1] = (1 - s) * p0[1] + s * p1[1]; } //old inner plates -void shaped_pfunc_upper_inner(double s, double* RZ){ - RZ[0] = 1.651 + (1.8 - 1.651)*s; - RZ[1] = 6.331 + (6.777 - 6.331)*s; +void shaped_pfunc_upper_inner(double s, double *RZ) +{ + RZ[0] = 1.651 + (1.8 - 1.651) * s; + RZ[1] = 6.331 + (6.777 - 6.331) * s; } -void shaped_pfunc_lower_inner(double s, double* RZ){ - RZ[0] = 1.651 + (1.8 - 1.651)*s; - RZ[1] = -(6.331 + (6.777 - 6.331)*s); +void shaped_pfunc_lower_inner(double s, double *RZ) +{ + RZ[0] = 1.651 + (1.8 - 1.651) * s; + RZ[1] = -(6.331 + (6.777 - 6.331) * s); } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; fout[0] = 0.5; // Diffusivity [m^2/s]. } -struct gkyl_gk_block_geom* -create_gk_block_geom(void) +struct gkyl_gk_block_geom *create_gk_block_geom(void) { struct gkyl_gk_block_geom *bgeom = gkyl_gk_block_geom_new(2, 12); @@ -88,14 +92,13 @@ create_gk_block_geom(void) symbol such as o,x,%, or % are instead connected to the other edge with the same symbol. Edges that do not coincide with another edge are a physical boundary. - */ - + */ struct gkyl_efit_inp efit_inp = { .filepath = "gyrokinetic/data/eqdsk/step.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; struct gkyl_efit *efit = gkyl_efit_new(&efit_inp); @@ -117,7 +120,7 @@ create_gk_block_geom(void) double psi_lo_pf = psisep; double psi_up_pf = psisep + wpf; - double psi_lo_inner_sol = psisep - win ; + double psi_lo_inner_sol = psisep - win; double psi_up_inner_sol = psisep; int npsi_outer_sol = 4; @@ -125,512 +128,528 @@ create_gk_block_geom(void) int npsi_pf = 2; int npsi_inner_sol = 2; - double ntheta_lower_inner = 4; + double ntheta_lower_inner = 4; double ntheta_middle_inner = 8; - double ntheta_upper_inner = 4; + double ntheta_upper_inner = 4; double ntheta_lower_outer = 4; double ntheta_middle_outer = 12; double ntheta_upper_outer = 4; - double ncuts_lower_inner = 1;//ntheta_lower_inner; - double ncuts_middle_inner = 1;//ntheta_middle_inner; - double ncuts_upper_inner = 1;//ntheta_upper_inner; + double ncuts_lower_inner = 1; //ntheta_lower_inner; + double ncuts_middle_inner = 1; //ntheta_middle_inner; + double ncuts_upper_inner = 1; //ntheta_upper_inner; - double ncuts_lower_outer = 1;//ntheta_lower_outer; - double ncuts_middle_outer = 1;//ntheta_middle_outer; - double ncuts_upper_outer = 1;//ntheta_upper_outer; + double ncuts_lower_outer = 1; //ntheta_lower_outer; + double ncuts_middle_outer = 1; //ntheta_middle_outer; + double ncuts_upper_outer = 1; //ntheta_upper_outer; double zinner = 6.34; double zouter = 8.29; double rright_out = 5.2; - double Lz = (M_PI-1e-14)*2.0; - double theta_lo = -Lz/2.0, theta_up = Lz/2.0; + double Lz = (M_PI - 1e-14) * 2.0; + double theta_lo = -Lz / 2.0, theta_up = Lz / 2.0; double compression_factor = 0.25; double radial_compression_factor = 0.5; double radial_compression_factor_none = 0.0; // block 0. Lower outer PF region. - gkyl_gk_block_geom_set_block(bgeom, 0, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_pf, theta_lo}, - .upper = { psi_up_pf, theta_up}, - .cells = { npsi_pf, ntheta_lower_outer }, - .cuts = { 1, ncuts_lower_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_R, - .rright = rright_out, - .rleft = 0.0, - .rmin = 1.7, - .rmax = 6.2, - .zmin_right = -zouter, - .zmin_left = -zinner, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_lower_inner, - }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor, - .compression_factor = compression_factor + gkyl_gk_block_geom_set_block( + bgeom, 0, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_pf, theta_lo}, + .upper = {psi_up_pf, theta_up}, + .cells = {npsi_pf, ntheta_lower_outer}, + .cuts = {1, ncuts_lower_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_R, + .rright = rright_out, + .rleft = 0.0, + .rmin = 1.7, + .rmax = 6.2, + .zmin_right = -zouter, + .zmin_left = -zinner, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_lower_inner}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor, + .compression_factor = compression_factor}}, + + .connections[0] = + { + // x-direction connections + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - }, - - .connections[0] = { // x-direction connections - { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 9, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 9, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 1. Lower outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 1, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, theta_lo}, - .upper = { psi_up_outer_sol, theta_up}, - .cells = { npsi_outer_sol, ntheta_lower_outer}, - .cuts = { 1, ncuts_lower_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 0.0, // closest R to inboard SOL - .rmin = 0.7, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - .zmin = -zouter, - .zmax = zouter, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor, - .compression_factor = compression_factor + gkyl_gk_block_geom_set_block( + bgeom, 1, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, theta_lo}, + .upper = {psi_up_outer_sol, theta_up}, + .cells = {npsi_outer_sol, ntheta_lower_outer}, + .cuts = {1, ncuts_lower_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 0.0, // closest R to inboard SOL + .rmin = 0.7, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false, // Whether to use cubic representation of psi(R,Z) for field line tracing + .zmin = -zouter, + .zmax = zouter, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor, + .compression_factor = compression_factor}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE } - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 2. Middle outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 2, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, theta_lo }, - .upper = { psi_up_outer_sol, theta_up }, - .cells = { npsi_outer_sol, ntheta_middle_outer}, - .cuts = { 1, ncuts_middle_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 0.0, // closest R to inboard SOL - .rmin = 0.7, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - .zmin = -zouter, - .zmax = zouter, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor, - .compression_factor = compression_factor + gkyl_gk_block_geom_set_block( + bgeom, 2, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, theta_lo}, + .upper = {psi_up_outer_sol, theta_up}, + .cells = {npsi_outer_sol, ntheta_middle_outer}, + .cuts = {1, ncuts_middle_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 0.0, // closest R to inboard SOL + .rmin = 0.7, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false, // Whether to use cubic representation of psi(R,Z) for field line tracing + .zmin = -zouter, + .zmax = zouter, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor, + .compression_factor = compression_factor}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 10, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 10, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 3, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[1] = + {// z-direction connections + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 3. Upper outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 3, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, theta_lo }, - .upper = { psi_up_outer_sol, theta_up }, - .cells = { npsi_outer_sol, ntheta_upper_outer}, - .cuts = { 1, ncuts_upper_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 0.0, // closest R to inboard SOL - .rmin = 0.7, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - .zmin = -zouter, - .zmax = zouter, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor, - .compression_factor = compression_factor + gkyl_gk_block_geom_set_block( + bgeom, 3, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, theta_lo}, + .upper = {psi_up_outer_sol, theta_up}, + .cells = {npsi_outer_sol, ntheta_upper_outer}, + .cuts = {1, ncuts_upper_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 0.0, // closest R to inboard SOL + .rmin = 0.7, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false, // Whether to use cubic representation of psi(R,Z) for field line tracing + .zmin = -zouter, + .zmax = zouter, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor, + .compression_factor = compression_factor}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 4, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 4, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 2, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - } - } + .connections[1] = + {// z-direction connections + {.bid = 2, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }} ); // block 4. Upper outer PF region. - gkyl_gk_block_geom_set_block(bgeom, 4, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_pf, theta_lo}, - .upper = { psi_up_pf, theta_up}, - .cells = { npsi_pf, ntheta_upper_outer }, - .cuts = { 1, ncuts_upper_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_UP_R, - .rright = rright_out, - .rleft = 0.0, - .rmin = 1.7, - .rmax = 6.2, - .zmax_right = zouter, - .zmax_left = zinner, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_upper_inner, - .plate_func_upper = shaped_pfunc_upper_outer, - }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor, - .compression_factor = compression_factor + gkyl_gk_block_geom_set_block( + bgeom, 4, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_pf, theta_lo}, + .upper = {psi_up_pf, theta_up}, + .cells = {npsi_pf, ntheta_upper_outer}, + .cuts = {1, ncuts_upper_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_UP_R, + .rright = rright_out, + .rleft = 0.0, + .rmin = 1.7, + .rmax = 6.2, + .zmax_right = zouter, + .zmax_left = zinner, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_upper_inner, + .plate_func_upper = shaped_pfunc_upper_outer}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor, + .compression_factor = compression_factor}}, + + .connections[0] = + { + // x-direction connections + {.bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - }, - - .connections[0] = { // x-direction connections - { .bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 5, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary - } - } + .connections[1] = + { + // z-direction connections + {.bid = 5, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); // block 5. Upper inner PF region. - gkyl_gk_block_geom_set_block(bgeom, 5, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_pf, theta_lo}, - .upper = { psi_up_pf, theta_up}, - .cells = { npsi_pf, ntheta_upper_inner }, - .cuts = { 1, ncuts_upper_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_UP_L, - .rright = rright_out, - .rleft = 0.0, - .rmin = 1.7, - .rmax = 6.2, - .zmax_right = zouter, - .zmax_left = zinner, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_upper_inner, - .plate_func_upper = shaped_pfunc_upper_outer, + gkyl_gk_block_geom_set_block( + bgeom, 5, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_pf, theta_lo}, + .upper = {psi_up_pf, theta_up}, + .cells = {npsi_pf, ntheta_upper_inner}, + .cuts = {1, ncuts_upper_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_UP_L, + .rright = rright_out, + .rleft = 0.0, + .rmin = 1.7, + .rmax = 6.2, + .zmax_right = zouter, + .zmax_left = zinner, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_upper_inner, + .plate_func_upper = shaped_pfunc_upper_outer}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor, + .compression_factor = compression_factor}}, + + .connections[0] = + { + // x-direction connections + {.bid = 6, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor, - .compression_factor = compression_factor - }, - }, - - .connections[0] = { // x-direction connections - { .bid = 6, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); - + // block 6. Upper inner SOL. - gkyl_gk_block_geom_set_block(bgeom, 6, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_inner_sol, theta_lo }, - .upper = { psi_up_inner_sol, theta_up }, - .cells = { npsi_inner_sol, ntheta_upper_inner}, - .cuts = { 1, ncuts_upper_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP, - .rleft = 2.0, - .rright= rright_out, - .rmin = 0.0, - .rmax = 6.2, - .zmin = -zinner, - .zmax = zinner, - .plate_spec = true, - .plate_func_upper = shaped_pfunc_upper_inner, - .plate_func_lower= shaped_pfunc_lower_inner, - }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor_none, - .compression_factor = compression_factor + gkyl_gk_block_geom_set_block( + bgeom, 6, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_inner_sol, theta_lo}, + .upper = {psi_up_inner_sol, theta_up}, + .cells = {npsi_inner_sol, ntheta_upper_inner}, + .cuts = {1, ncuts_upper_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP, + .rleft = 2.0, + .rright = rright_out, + .rmin = 0.0, + .rmax = 6.2, + .zmin = -zinner, + .zmax = zinner, + .plate_spec = true, + .plate_func_upper = shaped_pfunc_upper_inner, + .plate_func_lower = shaped_pfunc_lower_inner}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor_none, + .compression_factor = compression_factor}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 5, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 5, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 7, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 7, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); - + // block 7. Middle inner SOL. - gkyl_gk_block_geom_set_block(bgeom, 7, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_inner_sol, theta_lo }, - .upper = { psi_up_inner_sol, theta_up }, - .cells = { npsi_inner_sol, ntheta_middle_inner}, - .cuts = { 1, ncuts_middle_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID, - .rleft = 2.0, - .rright= rright_out, - .rmin = 0.0, - .rmax = 6.2, - .zmin = -zinner, - .zmax = zinner, - .plate_spec = true, - .plate_func_upper = shaped_pfunc_upper_inner, - .plate_func_lower= shaped_pfunc_lower_inner, + gkyl_gk_block_geom_set_block( + bgeom, 7, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_inner_sol, theta_lo}, + .upper = {psi_up_inner_sol, theta_up}, + .cells = {npsi_inner_sol, ntheta_middle_inner}, + .cuts = {1, ncuts_middle_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID, + .rleft = 2.0, + .rright = rright_out, + .rmin = 0.0, + .rmax = 6.2, + .zmin = -zinner, + .zmax = zinner, + .plate_spec = true, + .plate_func_upper = shaped_pfunc_upper_inner, + .plate_func_lower = shaped_pfunc_lower_inner}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor_none, + .compression_factor = compression_factor}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 11, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor_none, - .compression_factor = compression_factor - }, - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 11, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 6, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 8, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + .connections[1] = + {// z-direction connections + {.bid = 6, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 8, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 8. Lower inner SOL. - gkyl_gk_block_geom_set_block(bgeom, 8, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_inner_sol, theta_lo }, - .upper = { psi_up_inner_sol, theta_up }, - .cells = { npsi_inner_sol, ntheta_lower_inner}, - .cuts = { 1, ncuts_lower_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO, - .rleft = 2.0, - .rright= rright_out, - .rmin = 0.0, - .rmax = 6.2, - .zmin = -zinner, - .zmax = zinner, - .plate_spec = true, - .plate_func_upper = shaped_pfunc_upper_inner, - .plate_func_lower= shaped_pfunc_lower_inner, + gkyl_gk_block_geom_set_block( + bgeom, 8, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_inner_sol, theta_lo}, + .upper = {psi_up_inner_sol, theta_up}, + .cells = {npsi_inner_sol, ntheta_lower_inner}, + .cuts = {1, ncuts_lower_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO, + .rleft = 2.0, + .rright = rright_out, + .rmin = 0.0, + .rmax = 6.2, + .zmin = -zinner, + .zmax = zinner, + .plate_spec = true, + .plate_func_upper = shaped_pfunc_upper_inner, + .plate_func_lower = shaped_pfunc_lower_inner}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor_none, + .compression_factor = compression_factor}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 9, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor_none, - .compression_factor = compression_factor - }, - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 9, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - }, - .connections[1] = { // z-direction connections - { .bid = 7, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} - } - } + .connections[1] = + {// z-direction connections + {.bid = 7, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }} ); // block 9. Lower inner PF region. - gkyl_gk_block_geom_set_block(bgeom, 9, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_pf, theta_lo}, - .upper = { psi_up_pf, theta_up}, - .cells = { npsi_pf, ntheta_lower_inner }, - .cuts = { 1, ncuts_lower_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_L, - .rright = rright_out, - .rleft = 0.0, - .rmin = 1.7, - .rmax = 6.2, - .zmin_right = -zouter, - .zmin_left = -zinner, - .plate_spec = true, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_lower_inner, + gkyl_gk_block_geom_set_block( + bgeom, 9, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_pf, theta_lo}, + .upper = {psi_up_pf, theta_up}, + .cells = {npsi_pf, ntheta_lower_inner}, + .cuts = {1, ncuts_lower_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_L, + .rright = rright_out, + .rleft = 0.0, + .rmin = 1.7, + .rmax = 6.2, + .zmin_right = -zouter, + .zmin_left = -zinner, + .plate_spec = true, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_lower_inner}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor, + .compression_factor = compression_factor}}, + + .connections[0] = + { + // x-direction connections + {.bid = 8, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor, - .compression_factor = compression_factor - }, - }, - - .connections[0] = { // x-direction connections - { .bid = 8, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary - } - } + .connections[1] = + { + // z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); - // block 10. outer core. - gkyl_gk_block_geom_set_block(bgeom, 10, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_core, theta_lo}, - .upper = { psi_up_core, theta_up}, - .cells = { npsi_core, ntheta_middle_outer}, - .cuts = { 1, ncuts_middle_outer }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_R, - .rclose = 6.2, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 2.0, // closest R to inboard SOL - .rmin = 1.58, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing - }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor_none, - .compression_factor = compression_factor + gkyl_gk_block_geom_set_block( + bgeom, 10, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_core, theta_lo}, + .upper = {psi_up_core, theta_up}, + .cells = {npsi_core, ntheta_middle_outer}, + .cuts = {1, ncuts_middle_outer}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = + (struct gkyl_tok_geo_grid_inp){ + .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_R, + .rclose = 6.2, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 2.0, // closest R to inboard SOL + .rmin = 1.58, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false // Whether to use cubic representation of psi(R,Z) for field line tracing + }, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor_none, + .compression_factor = compression_factor}}, + + .connections[0] = + { + // x-direction connections + {.bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - }, - - .connections[0] = { // x-direction connections - { .bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 11, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, // physical boundary - { .bid = 11, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[1] = + {// z-direction connections + {.bid = 11, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, // physical boundary + {.bid = 11, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 11. Inner Core. - gkyl_gk_block_geom_set_block(bgeom, 11, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_core, theta_lo }, - .upper = { psi_up_core, theta_up }, - .cells = { npsi_core, ntheta_middle_inner}, - .cuts = { 1, ncuts_middle_inner }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_L, - .rclose = 0.0, // Closest R to region of interest - .rright = rright_out, // Closest R to outboard SOL - .rleft = 2.0, // closest R to inboard SOL - .rmin = 1.58, // smallest R in machine - .rmax = 6.2, // largest R in machine - .use_cubics = false, // Whether to use cubic representation of psi(R,Z) for field line tracing + gkyl_gk_block_geom_set_block( + bgeom, 11, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_core, theta_lo}, + .upper = {psi_up_core, theta_up}, + .cells = {npsi_core, ntheta_middle_inner}, + .cuts = {1, ncuts_middle_inner}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = + (struct gkyl_tok_geo_grid_inp){ + .ftype = GKYL_GEOMETRY_TOKAMAK_CORE_L, + .rclose = 0.0, // Closest R to region of interest + .rright = rright_out, // Closest R to outboard SOL + .rleft = 2.0, // closest R to inboard SOL + .rmin = 1.58, // smallest R in machine + .rmax = 6.2, // largest R in machine + .use_cubics = + false // Whether to use cubic representation of psi(R,Z) for field line tracing + }, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .radial_compression_factor = radial_compression_factor_none, + .compression_factor = compression_factor}}, + + .connections[0] = + { + // x-direction connections + {.bid = 7, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .radial_compression_factor = radial_compression_factor_none, - .compression_factor = compression_factor - }, - }, - - .connections[0] = { // x-direction connections - { .bid = 7, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - }, - .connections[1] = { // z-direction connections - { .bid = 10, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 10, .dir = 1, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[1] = + {// z-direction connections + {.bid = 10, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 10, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); return bgeom; @@ -681,62 +700,60 @@ struct gk_step_ctx { int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; - - -struct gk_step_ctx -create_ctx(void) +struct gk_step_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // ion mass double mH0 = GKYL_PROTON_MASS; // H0 mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge - double n_fac = 1.0; - double temp_fac = 9.0/n_fac; + double temp_fac = 9.0 / n_fac; - double Te = 1500.0/temp_fac*eV; - double Ti = 1500.0/temp_fac*eV; - double TH0 = 100.0*eV; + double Te = 1500.0 / temp_fac * eV; + double Ti = 1500.0 / temp_fac * eV; + double TH0 = 100.0 * eV; double B0 = 2.51; // Magnetic field magnitude in Tesla - double n0 = 3.0e19/n_fac; // Particle density in 1/m^3 - double n0H0 = n0*1.0e-2; // Particle density in 1/m^3 - - // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); - double vtH0 = sqrt(TH0/mH0); + double n0 = 3.0e19 / n_fac; // Particle density in 1/m^3 + double n0H0 = n0 * 1.0e-2; // Particle density in 1/m^3 + // Derived parameters. + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); + double vtH0 = sqrt(TH0 / mH0); - double nsource = 1.675e22*2.5*temp_fac/6.0; - double Tsource = 3000.0*eV/temp_fac; + double nsource = 1.675e22 * 2.5 * temp_fac / 6.0; + double Tsource = 3000.0 * eV / temp_fac; double cx = 0.0065612; - double cz = 0.4916200*1.4; + double cz = 0.4916200 * 1.4; double psisep = 1.5093065418975686; //This is the value from efit double xcenter = psisep; // Collision parameters. double nu_frac = 1.0; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nu_frac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); // collision freq + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nu_frac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te)) + ); // collision freq - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nuIon = nu_frac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mi)*(Ti*sqrt(Ti))); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nuIon = nu_frac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mi) * (Ti * sqrt(Ti))); // Simulation box size (m). - double vpar_max_elc = 6.0*vtElc; - double mu_max_elc = 18*me*vtElc*vtElc/(2.0*B0); + double vpar_max_elc = 6.0 * vtElc; + double mu_max_elc = 18 * me * vtElc * vtElc / (2.0 * B0); - double vpar_max_ion = 8.0*vtIon; - double mu_max_ion = 18*mi*vtIon*vtIon/(2.0*B0); + double vpar_max_ion = 8.0 * vtIon; + double mu_max_ion = 18 * mi * vtIon * vtIon / (2.0 * B0); - double vpar_max_H0 = 6.0*vtH0; + double vpar_max_H0 = 6.0 * vtH0; // Number of cells. int Nx = 4; @@ -744,31 +761,31 @@ create_ctx(void) int Nvpar = 16; int Nmu = 12; - double t_end = 1.0e-8; + double t_end = 1.0e-8; double num_frames = 1; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-2; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_step_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, .massH0 = mH0, - .Te = Te, - .Ti = Ti, - .TH0 = TH0, + .Te = Te, + .Ti = Ti, + .TH0 = TH0, .vtIon = vtIon, .vtElc = vtElc, .vtH0 = vtH0, - .nuElc = nuElc, - .nuIon = nuIon, + .nuElc = nuElc, + .nuIon = nuIon, .nu_frac = nu_frac, - .B0 = B0, - .n0 = n0, + .B0 = B0, + .n0 = n0, .n0H0 = n0H0, .nsource = nsource, .Tsource = Tsource, @@ -777,28 +794,26 @@ create_ctx(void) .cx = cx, .xcenter = xcenter, .cz = cz, - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, - .vpar_max_H0 = vpar_max_H0, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, + .vpar_max_H0 = vpar_max_H0, .Nx = Nx, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - -void -init_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; @@ -807,8 +822,9 @@ init_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fo fout[0] = n0; } -void -init_density_core(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_core( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //1.5e20 at inner core and 2e19 at sep double x = xn[0], z = xn[1]; @@ -818,13 +834,13 @@ init_density_core(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI double n_fac = app->n_fac; double slope = 3.0e20; double intercept = -4.22792e+20; - double n = slope*x + intercept; - fout[0] = fmax(n/n_fac, n0*1e-3); + double n = slope * x + intercept; + fout[0] = fmax(n / n_fac, n0 * 1e-3); } - -void -init_density_outer(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_outer( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -834,12 +850,13 @@ init_density_outer(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTR double n_fac = app->n_fac; double slope = 2.7e20; double intercept = -3.77513e+20; - double n = slope*x + intercept; - fout[0] = fmax(n/n_fac, n0*1e-3); + double n = slope * x + intercept; + fout[0] = fmax(n / n_fac, n0 * 1e-3); } -void -init_density_inner(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_inner( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -849,12 +866,11 @@ init_density_inner(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTR double n_fac = app->n_fac; double slope = 5.4e20; double intercept = -7.85026e+20; - double n = slope*x + intercept; - fout[0] = fmax(n/n_fac, n0*1e-3); + double n = slope * x + intercept; + fout[0] = fmax(n / n_fac, n0 * 1e-3); } -void -init_density_pf(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_density_pf(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { //2e19 at sep 2e17 at outer boundary double x = xn[0], z = xn[1]; @@ -864,88 +880,77 @@ init_density_pf(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT double n_fac = app->n_fac; double slope = -5.4e20; double intercept = 8.45026e+20; - double n = slope*x + intercept; - fout[0] = fmax(n/n_fac, n0*1e-3); + double n = slope * x + intercept; + fout[0] = fmax(n / n_fac, n0 * 1e-3); } - -void -source_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void source_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; struct gk_step_ctx *app = ctx; double nsource = app->nsource; //if(x >= 1.5593065418975687 + 0.05) for 1.5x domain - if(x >= 1.5593065418975687) + if (x >= 1.5593065418975687) { fout[0] = nsource; - else - fout[0] = nsource*1.0e-5; + } else { + fout[0] = nsource * 1.0e-5; + } } - -void -init_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_upar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void -init_udrift_H0(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_udrift_H0(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; } -void -init_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; - double T = 2.0*app->Te; + double T = 2.0 * app->Te; fout[0] = T; } -void -init_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; - double T = 2.0*app->Ti; + double T = 2.0 * app->Ti; fout[0] = T; } -void -source_temp(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void source_temp(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double T = app->Tsource; fout[0] = T; } - -void -init_temp_H0(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_temp_H0(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double T = app->TH0; fout[0] = T; } -void -init_nu_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_nu_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *input = ctx; fout[0] = input->nuElc; } -void -init_nu_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_nu_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *input = ctx; fout[0] = input->nuIon; } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_step_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -957,21 +962,23 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v double vpar = 0.0; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vpar = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vpar = -vpar_max_elc*2.0*pow(cvpar,2); - else - vpar = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vpar = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vpar = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vpar = vpar_max_elc * 2.0 * pow(cvpar, 2); + } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } static inline void -mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_ion(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_step_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -983,38 +990,42 @@ mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v double vpar = 0.0; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vpar = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vpar = -vpar_max_ion*2.0*pow(cvpar,2); - else - vpar = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vpar = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vpar = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vpar = vpar_max_ion * 2.0 * pow(cvpar, 2); + } mu = mu_max_ion * (cmu * cmu); // Set rescaled ion velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar ; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } - - -void -calc_integrated_diagnostics(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_multib_app* app, double t_curr, double dt, bool force_calc) +void calc_integrated_diagnostics( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_multib_app *app, double t_curr, double dt, + bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_calc) { gkyl_gyrokinetic_multib_app_calc_field_energy(app, t_curr); gkyl_gyrokinetic_multib_app_calc_integrated_mom(app, t_curr); - if ( !(dt < 0.0) ) + if (!(dt < 0.0)) { gkyl_gyrokinetic_multib_app_save_dt(app, t_curr, dt); + } } } -static void -write_data(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_multib_app* app, double t_curr, bool force_write) +static void write_data( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_multib_app *app, double t_curr, bool force_write +) { bool trig_now = gkyl_tm_trigger_check_and_bump(iot, t_curr); if (trig_now || force_write) { - int frame = (!trig_now) && force_write? iot->curr : iot->curr-1; + int frame = (!trig_now) && force_write ? iot->curr : iot->curr - 1; gkyl_gyrokinetic_multib_app_write(app, t_curr, frame); gkyl_gyrokinetic_multib_app_write_field_energy(app); @@ -1023,8 +1034,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_multib_app* app, double } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -1049,346 +1059,329 @@ main(int argc, char **argv) struct gk_step_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcdim = ctx.cdim; app_inp->poly_order = 1; app_inp->basis_type = app_args.basis_type; @@ -1865,18 +1844,17 @@ main(int argc, char **argv) // Set app output name from the executable name (argv[0]). snprintf(app_inp->name, sizeof(app_inp->name), "%s", app_args.app_name); struct gkyl_gyrokinetic_run_inp run_inp = { - .app_type = GKYL_GK_MULTIB, - .multib_app_inp = *app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = app_args.num_steps, - }, + .app_type = GKYL_GK_MULTIB, + .multib_app_inp = *app_inp, + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = app_args.num_steps} }; gkyl_gyrokinetic_run_simulation(&run_inp); @@ -1884,8 +1862,9 @@ main(int argc, char **argv) gkyl_free(app_inp); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif return 0; diff --git a/gyrokinetic/creg/rt_gk_multib_step_sol_1x2v_p1.c b/gyrokinetic/creg/rt_gk_multib_step_sol_1x2v_p1.c index d8cd25699d..a8f40b192e 100644 --- a/gyrokinetic/creg/rt_gk_multib_step_sol_1x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_multib_step_sol_1x2v_p1.c @@ -7,28 +7,31 @@ #include -void shaped_pfunc_lower_outer(double s, double* RZ){ - RZ[0] = 3.5+2.0*s; +void shaped_pfunc_lower_outer(double s, double *RZ) +{ + RZ[0] = 3.5 + 2.0 * s; RZ[1] = -8.29; } -void shaped_pfunc_upper_outer(double s, double* RZ){ - RZ[0] = 3.5+2.0*s; +void shaped_pfunc_upper_outer(double s, double *RZ) +{ + RZ[0] = 3.5 + 2.0 * s; RZ[1] = 8.29; } -void shaped_pfunc_upper_inner(double s, double* RZ){ - RZ[0] = 1.651 + (1.8 - 1.651)*s; - RZ[1] = 6.331 + (6.777 - 6.331)*s; +void shaped_pfunc_upper_inner(double s, double *RZ) +{ + RZ[0] = 1.651 + (1.8 - 1.651) * s; + RZ[1] = 6.331 + (6.777 - 6.331) * s; } -void shaped_pfunc_lower_inner(double s, double* RZ){ - RZ[0] = 1.65 + (1.8 - 1.65)*s; - RZ[1] = -(6.33 + (6.777 - 6.33)*s); +void shaped_pfunc_lower_inner(double s, double *RZ) +{ + RZ[0] = 1.65 + (1.8 - 1.65) * s; + RZ[1] = -(6.33 + (6.777 - 6.33) * s); } -struct gkyl_gk_block_geom* -create_gk_block_geom(void) +struct gkyl_gk_block_geom *create_gk_block_geom(void) { struct gkyl_gk_block_geom *bgeom = gkyl_gk_block_geom_new(1, 3); @@ -49,16 +52,13 @@ create_gk_block_geom(void) symbol such as o,x,%, or % are instead connected to the other edge with the same symbol. Edges that do not coincide with another edge are a physical boundary. - */ - - + */ - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/step.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, - .reflect = true, + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/step.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1, + .reflect = true }; struct gkyl_efit *efit = gkyl_efit_new(&efit_inp); @@ -72,106 +72,107 @@ create_gk_block_geom(void) int npsi_outer_sol = 10; - double ntheta_lower = 4; + double ntheta_lower = 4; double ntheta_middle = 8; - double ntheta_upper = 4; + double ntheta_upper = 4; - // Note that for tokamak multi-block simulations, - // these theta limits are just placeholders and will be + // Note that for tokamak multi-block simulations, + // these theta limits are just placeholders and will be // reset in the multi-block app. double theta_lo = -M_PI + 1e-14, theta_up = M_PI - 1e-14; // block 0. Lower outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 0, &(struct gkyl_gk_block_geom_info) { - .lower = { theta_lo }, - .upper = { theta_up }, - .cells = { ntheta_lower}, - .cuts = { 1 }, - .geometry = { - .world = {1.2014, 0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, - .rright = 6.2, - .rleft = 1.1, - .rmin = 2.1, - .rmax = 6.2, - .zmin = -8.29, - .zmax = 8.29, - .plate_spec = false, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - } - }, - - .connections[0] = { // z-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - } - } + gkyl_gk_block_geom_set_block( + bgeom, 0, + &(struct gkyl_gk_block_geom_info + ){.lower = {theta_lo}, + .upper = {theta_up}, + .cells = {ntheta_lower}, + .cuts = {1}, + .geometry = + {.world = {1.2014, 0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, + .rright = 6.2, + .rleft = 1.1, + .rmin = 2.1, + .rmax = 6.2, + .zmin = -8.29, + .zmax = 8.29, + .plate_spec = false, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}}, + + .connections[0] = + {// z-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 1. Middle outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 1, &(struct gkyl_gk_block_geom_info) { - .lower = { theta_lo }, - .upper = { theta_up }, - .cells = { ntheta_middle}, - .cuts = { 1 }, - .geometry = { - .world = {1.2014, 0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, - .rright = 6.2, - .rleft = 1.1, - .rmin = 2.1, - .rmax = 6.2, - .plate_spec = false, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - .zmin = -8.29, - .zmax = 8.29, - } - }, - - .connections[0] = { // z-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} - } - } + gkyl_gk_block_geom_set_block( + bgeom, 1, + &(struct gkyl_gk_block_geom_info + ){.lower = {theta_lo}, + .upper = {theta_up}, + .cells = {ntheta_middle}, + .cuts = {1}, + .geometry = + {.world = {1.2014, 0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, + .rright = 6.2, + .rleft = 1.1, + .rmin = 2.1, + .rmax = 6.2, + .plate_spec = false, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer, + .zmin = -8.29, + .zmax = 8.29}}, + + .connections[0] = + {// z-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 2. Upper outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 2, &(struct gkyl_gk_block_geom_info) { - .lower = { theta_lo }, - .upper = { theta_up }, - .cells = { ntheta_upper}, - .cuts = { 1 }, - .geometry = { - .world = {1.2014, 0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, - .rright = 6.2, - .rleft = 1.1, - .rmin = 2.1, - .rmax = 6.2, - .plate_spec = false, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - .zmin = -8.29, - .zmax = 8.29, - } - }, - - .connections[0] = { // z-direction connections - { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 2, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary - } - } + gkyl_gk_block_geom_set_block( + bgeom, 2, + &(struct gkyl_gk_block_geom_info + ){.lower = {theta_lo}, + .upper = {theta_up}, + .cells = {ntheta_upper}, + .cuts = {1}, + .geometry = + {.world = {1.2014, 0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, + .rright = 6.2, + .rleft = 1.1, + .rmin = 2.1, + .rmax = 6.2, + .plate_spec = false, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer, + .zmin = -8.29, + .zmax = 8.29}}, + + .connections[0] = + { + // z-direction connections + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }} ); return bgeom; @@ -211,115 +212,117 @@ struct gk_step_ctx { double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct gk_step_ctx -create_ctx(void) +struct gk_step_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge - double Te = 364*eV; - double Ti = 534*eV; + double Te = 364 * eV; + double Ti = 534 * eV; double B0 = 2.51; // Magnetic field magnitude in Tesla double n0 = 3.0e19; // Particle density in 1/m^3 - + // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); double k_perp_rho_s = 0.3; // Product of perpendicular wavenumber and ion-sound gyroradius. double c_s = sqrt(Te / mi); // Sound speed. - double omega_ci = fabs(qi* B0 / mi); // Ion cyclotron frequency. + double omega_ci = fabs(qi * B0 / mi); // Ion cyclotron frequency. double rho_s = c_s / omega_ci; // Ion-sound gyroradius. double k_perp = k_perp_rho_s / rho_s; // Perpendicular wavenumber (for Poisson solver). // Source parameters. - double nsource = 3.9e23; // peak source rate in particles/m^3/s - double T_source = 1037.0*eV; + double nsource = 3.9e23; // peak source rate in particles/m^3/s + double T_source = 1037.0 * eV; double cz = 0.8; - double cx = 0.0065612*4; + double cx = 0.0065612 * 4; // Collision parameters. double nuFrac = 0.25; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nuFrac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); // collision freq + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nuFrac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te)) + ); // collision freq - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nuIon = nuFrac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mi)*(Ti*sqrt(Ti))); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nuIon = nuFrac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mi) * (Ti * sqrt(Ti))); // Simulation box size (m). - double vpar_max_elc = 6.0*vtElc; - double mu_max_elc = 12*me*vtElc*vtElc/(2.0*B0); + double vpar_max_elc = 6.0 * vtElc; + double mu_max_elc = 12 * me * vtElc * vtElc / (2.0 * B0); - double vpar_max_ion = 6.0*vtIon; - double mu_max_ion = 12*mi*vtIon*vtIon/(2.0*B0); + double vpar_max_ion = 6.0 * vtIon; + double mu_max_ion = 12 * mi * vtIon * vtIon / (2.0 * B0); // Number of cells. int Nz = 4; int Nvpar = 12; int Nmu = 8; - double t_end = 1.0e-4; + double t_end = 1.0e-4; double num_frames = 10; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_step_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, - .Te = Te, - .Ti = Ti, + .Te = Te, + .Ti = Ti, .vtIon = vtIon, .vtElc = vtElc, - .nuElc = nuElc, - .nuIon = nuIon, + .nuElc = nuElc, + .nuIon = nuIon, .nuFrac = nuFrac, - .B0 = B0, - .n0 = n0, + .B0 = B0, + .n0 = n0, .k_perp = k_perp, - .T_source = T_source, + .T_source = T_source, .nsource = nsource, .cx = cx, .cz = cz, - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - -void -initDensity(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void initDensity(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = 1.2014, z = xn[0]; @@ -328,14 +331,14 @@ initDensity(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double cx = app->cx; double cz = app->cz; double xcenter = 1.2014; - double n = n0*exp(-(x-xcenter)*(x-xcenter)/2/cx/cx) * exp(-z*z/2/cz/cz); - if (n/n0 < 1e-1) - n = n0*1e-1; + double n = n0 * exp(-(x - xcenter) * (x - xcenter) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n / n0 < 1e-1) { + n = n0 * 1e-1; + } fout[0] = n; } -void -sourceDensity(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void sourceDensity(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = 1.2014, z = xn[0]; @@ -344,49 +347,48 @@ sourceDensity(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f double cx = app->cx; double cz = app->cz; double xcenter = 1.2014; - double n = nsource*exp(-(x-xcenter)*(x-xcenter)/2/cx/cx) * exp(-z*z/2/cz/cz); - if (n/nsource < 1e-3) - n = nsource*1e-3; + double n = + nsource * exp(-(x - xcenter) * (x - xcenter) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n / nsource < 1e-3) { + n = nsource * 1e-3; + } fout[0] = n; } -void -initTempElc(double t, const double *xn, double* restrict fout, void *ctx) +void initTempElc(double t, const double *xn, double *restrict fout, void *ctx) { struct gk_step_ctx *input = ctx; double T = input->Te; fout[0] = T; } -void -initTempIon(double t, const double *xn, double* restrict fout, void *ctx) +void initTempIon(double t, const double *xn, double *restrict fout, void *ctx) { struct gk_step_ctx *input = ctx; double T = input->Ti; fout[0] = T; } -void -initUpar(double t, const double *xn, double* restrict fout, void *ctx) +void initUpar(double t, const double *xn, double *restrict fout, void *ctx) { fout[0] = 0.0; } -void -sourceTemp(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void sourceTemp(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *input = ctx; double T = input->T_source; fout[0] = T; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -397,10 +399,12 @@ main(int argc, char **argv) struct gk_step_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcdim = ctx.cdim; app_inp->poly_order = 1; app_inp->basis_type = app_args.basis_type; @@ -588,17 +581,16 @@ main(int argc, char **argv) struct gkyl_gyrokinetic_run_inp run_inp = { .app_type = GKYL_GK_MULTIB, .multib_app_inp = *app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = app_args.num_steps, - }, + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = app_args.num_steps} }; gkyl_gyrokinetic_run_simulation(&run_inp); @@ -608,10 +600,10 @@ main(int argc, char **argv) gkyl_free(app_inp); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif - - return 0; + return 0; } diff --git a/gyrokinetic/creg/rt_gk_multib_step_sol_2x2v_p1.c b/gyrokinetic/creg/rt_gk_multib_step_sol_2x2v_p1.c index 2e2461ab0e..665ab4cef3 100644 --- a/gyrokinetic/creg/rt_gk_multib_step_sol_2x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_multib_step_sol_2x2v_p1.c @@ -7,28 +7,31 @@ #include -void shaped_pfunc_lower_outer(double s, double* RZ){ - RZ[0] = 3.5+2.0*s; +void shaped_pfunc_lower_outer(double s, double *RZ) +{ + RZ[0] = 3.5 + 2.0 * s; RZ[1] = -8.29; } -void shaped_pfunc_upper_outer(double s, double* RZ){ - RZ[0] = 3.5+2.0*s; +void shaped_pfunc_upper_outer(double s, double *RZ) +{ + RZ[0] = 3.5 + 2.0 * s; RZ[1] = 8.29; } -void shaped_pfunc_upper_inner(double s, double* RZ){ - RZ[0] = 1.651 + (1.8 - 1.651)*s; - RZ[1] = 6.331 + (6.777 - 6.331)*s; +void shaped_pfunc_upper_inner(double s, double *RZ) +{ + RZ[0] = 1.651 + (1.8 - 1.651) * s; + RZ[1] = 6.331 + (6.777 - 6.331) * s; } -void shaped_pfunc_lower_inner(double s, double* RZ){ - RZ[0] = 1.65 + (1.8 - 1.65)*s; - RZ[1] = -(6.33 + (6.777 - 6.33)*s); +void shaped_pfunc_lower_inner(double s, double *RZ) +{ + RZ[0] = 1.65 + (1.8 - 1.65) * s; + RZ[1] = -(6.33 + (6.777 - 6.33) * s); } -struct gkyl_gk_block_geom* -create_gk_block_geom(void) +struct gkyl_gk_block_geom *create_gk_block_geom(void) { struct gkyl_gk_block_geom *bgeom = gkyl_gk_block_geom_new(2, 3); @@ -49,16 +52,13 @@ create_gk_block_geom(void) symbol such as o,x,%, or % are instead connected to the other edge with the same symbol. Edges that do not coincide with another edge are a physical boundary. - */ + */ - - - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/step.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, - .reflect = true, + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/step.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1, + .reflect = true }; struct gkyl_efit *efit = gkyl_efit_new(&efit_inp); @@ -72,121 +72,125 @@ create_gk_block_geom(void) int npsi_outer_sol = 10; - double ntheta_lower = 4; + double ntheta_lower = 4; double ntheta_middle = 8; - double ntheta_upper = 4; + double ntheta_upper = 4; - // Note that for tokamak multi-block simulations, - // these theta limits are just placeholders and will be + // Note that for tokamak multi-block simulations, + // these theta limits are just placeholders and will be // reset in the multi-block app. double theta_lo = -M_PI + 1e-14, theta_up = M_PI - 1e-14; // block 0. Lower outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 0, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, theta_lo }, - .upper = { psisep, theta_up }, - .cells = { npsi_outer_sol, ntheta_lower}, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, - .rright = 6.2, - .rleft = 1.1, - .rmin = 2.1, - .rmax = 6.2, - .zmin = -8.29, - .zmax = 8.29, - .plate_spec = false, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 1, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + gkyl_gk_block_geom_set_block( + bgeom, 0, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, theta_lo}, + .upper = {psisep, theta_up}, + .cells = {npsi_outer_sol, ntheta_lower}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, + .rright = 6.2, + .rleft = 1.1, + .rmin = 2.1, + .rmax = 6.2, + .zmin = -8.29, + .zmax = 8.29, + .plate_spec = false, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} + }, + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 1, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 1. Middle outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 1, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, theta_lo }, - .upper = { psisep, theta_up }, - .cells = { npsi_outer_sol, ntheta_middle}, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, - .rright = 6.2, - .rleft = 1.1, - .rmin = 2.1, - .rmax = 6.2, - .plate_spec = false, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - .zmin = -8.29, - .zmax = 8.29, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} - }, - .connections[1] = { // z-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE} - } - } + gkyl_gk_block_geom_set_block( + bgeom, 1, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, theta_lo}, + .upper = {psisep, theta_up}, + .cells = {npsi_outer_sol, ntheta_middle}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, + .rright = 6.2, + .rleft = 1.1, + .rmin = 2.1, + .rmax = 6.2, + .plate_spec = false, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer, + .zmin = -8.29, + .zmax = 8.29}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} + }, + .connections[1] = + {// z-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 2. Upper outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 2, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_lo_outer_sol, theta_lo }, - .upper = { psisep, theta_up }, - .cells = { npsi_outer_sol, ntheta_upper}, - .cuts = { 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, -// .geometry_id = GKYL_GEOMETRY_FROMFILE, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, - .rright = 6.2, - .rleft = 1.1, - .rmin = 2.1, - .rmax = 6.2, - .plate_spec = false, - .plate_func_lower = shaped_pfunc_lower_outer, - .plate_func_upper = shaped_pfunc_upper_outer, - .zmin = -8.29, - .zmax = 8.29, - } - }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} - }, - .connections[1] = { // z-direction connections - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary - } - } + gkyl_gk_block_geom_set_block( + bgeom, 2, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_lo_outer_sol, theta_lo}, + .upper = {psisep, theta_up}, + .cells = {npsi_outer_sol, ntheta_upper}, + .cuts = {1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + // .geometry_id = GKYL_GEOMETRY_FROMFILE, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, + .rright = 6.2, + .rleft = 1.1, + .rmin = 2.1, + .rmax = 6.2, + .plate_spec = false, + .plate_func_lower = shaped_pfunc_lower_outer, + .plate_func_upper = shaped_pfunc_upper_outer, + .zmin = -8.29, + .zmax = 8.29}}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} + }, + .connections[1] = + { + // z-direction connections + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); return bgeom; @@ -225,54 +229,57 @@ struct gk_step_ctx { double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct gk_step_ctx -create_ctx(void) +struct gk_step_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge - double Te = 364*eV; - double Ti = 534*eV; + double Te = 364 * eV; + double Ti = 534 * eV; double B0 = 2.51; // Magnetic field magnitude in Tesla double n0 = 3.0e19; // Particle density in 1/m^3 - + // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); // Source parameters. - double nsource = 3.9e23; // peak source rate in particles/m^3/s - double T_source = 1037.0*eV; + double nsource = 3.9e23; // peak source rate in particles/m^3/s + double T_source = 1037.0 * eV; double cz = 0.8; - double cx = 0.0065612*4; + double cx = 0.0065612 * 4; // Collision parameters. double nuFrac = 0.25; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nuFrac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); // collision freq + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nuFrac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te)) + ); // collision freq - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nuIon = nuFrac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mi)*(Ti*sqrt(Ti))); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nuIon = nuFrac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mi) * (Ti * sqrt(Ti))); // Simulation box size (m). - double vpar_max_elc = 6.0*vtElc; - double mu_max_elc = 12*me*vtElc*vtElc/(2.0*B0); + double vpar_max_elc = 6.0 * vtElc; + double mu_max_elc = 12 * me * vtElc * vtElc / (2.0 * B0); - double vpar_max_ion = 6.0*vtIon; - double mu_max_ion = 12*mi*vtIon*vtIon/(2.0*B0); + double vpar_max_ion = 6.0 * vtIon; + double mu_max_ion = 12 * mi * vtIon * vtIon / (2.0 * B0); // Number of cells. int Nx = 4; @@ -280,54 +287,54 @@ create_ctx(void) int Nvpar = 12; int Nmu = 8; - double t_end = 2.0e-6; + double t_end = 2.0e-6; double num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_step_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, - .Te = Te, - .Ti = Ti, + .Te = Te, + .Ti = Ti, .vtIon = vtIon, .vtElc = vtElc, - .nuElc = nuElc, - .nuIon = nuIon, + .nuElc = nuElc, + .nuIon = nuIon, .nuFrac = nuFrac, - .B0 = B0, - .n0 = n0, - .T_source = T_source, + .B0 = B0, + .n0 = n0, + .T_source = T_source, .nsource = nsource, .cx = cx, .cz = cz, - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .Nx = Nx, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -initDensity(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void initDensity(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; @@ -336,14 +343,14 @@ initDensity(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double cx = app->cx; double cz = app->cz; double xcenter = 1.2014; - double n = n0*exp(-(x-xcenter)*(x-xcenter)/2/cx/cx) * exp(-z*z/2/cz/cz); - if (n/n0 < 1e-1) - n = n0*1e-1; + double n = n0 * exp(-(x - xcenter) * (x - xcenter) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n / n0 < 1e-1) { + n = n0 * 1e-1; + } fout[0] = n; } -void -sourceDensity(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void sourceDensity(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; @@ -352,57 +359,57 @@ sourceDensity(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f double cx = app->cx; double cz = app->cz; double xcenter = 1.2014; - double n = nsource*exp(-(x-xcenter)*(x-xcenter)/2/cx/cx) * exp(-z*z/2/cz/cz); - if (n/nsource < 1e-3) - n = nsource*1e-3; + double n = + nsource * exp(-(x - xcenter) * (x - xcenter) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n / nsource < 1e-3) { + n = nsource * 1e-3; + } fout[0] = n; } -void -initTempElc(double t, const double *xn, double* restrict fout, void *ctx) +void initTempElc(double t, const double *xn, double *restrict fout, void *ctx) { struct gk_step_ctx *input = ctx; double T = input->Te; fout[0] = T; } -void -initTempIon(double t, const double *xn, double* restrict fout, void *ctx) +void initTempIon(double t, const double *xn, double *restrict fout, void *ctx) { struct gk_step_ctx *input = ctx; double T = input->Ti; fout[0] = T; } -void -initUpar(double t, const double *xn, double* restrict fout, void *ctx) +void initUpar(double t, const double *xn, double *restrict fout, void *ctx) { fout[0] = 0.0; } -void -sourceTemp(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void sourceTemp(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *input = ctx; double T = input->T_source; fout[0] = T; } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; fout[0] = 0.03; // Diffusivity [m^2/s]. } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -417,10 +424,12 @@ main(int argc, char **argv) int nblocks = gkyl_gk_block_geom_num_blocks(bgeom); int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcdim = ctx.cdim; app_inp->poly_order = 1; app_inp->basis_type = app_args.basis_type; @@ -669,17 +678,16 @@ main(int argc, char **argv) struct gkyl_gyrokinetic_run_inp run_inp = { .app_type = GKYL_GK_MULTIB, .multib_app_inp = *app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = app_args.num_steps, - }, + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = app_args.num_steps} }; gkyl_gyrokinetic_run_simulation(&run_inp); @@ -689,8 +697,9 @@ main(int argc, char **argv) gkyl_free(app_inp); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif return 0; diff --git a/gyrokinetic/creg/rt_gk_multib_tcv_x21_3x2v_p1.c b/gyrokinetic/creg/rt_gk_multib_tcv_x21_3x2v_p1.c index fd79d97eaf..505585eb5f 100644 --- a/gyrokinetic/creg/rt_gk_multib_tcv_x21_3x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_multib_tcv_x21_3x2v_p1.c @@ -33,7 +33,7 @@ struct gk_tcv_ctx { double Te_src; // Electron source temperature. double Ti_src; // Ion source temperature. - // Domain parameters. + // Domain parameters. char geqdsk_file[128]; // File with equilibrium. double psi_axis; // Psi at the magnetic axis. double psi_sep; // Psi at the separatrix. @@ -71,48 +71,48 @@ struct gk_tcv_ctx { double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -void divertor_plate_func_out(double s, double* RZ) +void divertor_plate_func_out(double s, double *RZ) { // Straight bottom plate. double R_lo = 0.6662613750; double R_up = 0.9668828249; double Z = -0.75; - RZ[0] = R_lo + (R_up-R_lo)*s; + RZ[0] = R_lo + (R_up - R_lo) * s; RZ[1] = Z; } -void divertor_plate_func_in(double s, double* RZ) +void divertor_plate_func_in(double s, double *RZ) { // Straight left plate. double R = 0.6240000129; double Z_lo = -0.7014500499; - double Z_up = -0.4014500499; + double Z_up = -0.4014500499; RZ[0] = R; - RZ[1] = Z_lo + (Z_up-Z_lo)*s; + RZ[1] = Z_lo + (Z_up - Z_lo) * s; } double rho_psi(double psi, double psi_axis, double psi_sep) { // Normalized radial coordinate. - return sqrt((psi-psi_axis) / (psi_sep - psi_axis)); + return sqrt((psi - psi_axis) / (psi_sep - psi_axis)); } double psi_rho(double rho, double psi_axis, double psi_sep) { // Poloidal flux given the normalized radial coordinate. - return pow(rho,2) * (psi_sep - psi_axis) + psi_axis; + return pow(rho, 2) * (psi_sep - psi_axis) + psi_axis; } -struct gkyl_gk_block_geom* -create_asdex_lsn_gk_block_geom(void *ctx) +struct gkyl_gk_block_geom *create_asdex_lsn_gk_block_geom(void *ctx) { struct gk_tcv_ctx *params = ctx; @@ -152,12 +152,11 @@ create_asdex_lsn_gk_block_geom(void *ctx) symbol such as o,x,%, or % are instead connected to the other edge with the same symbol. Edges that do not coincide with another edge are a physical boundary. - */ + */ - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .rz_poly_order = 2, - .flux_poly_order = 1, + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .rz_poly_order = 2, + .flux_poly_order = 1 }; // Copy eqdsk file into efit_inp. memcpy(efit_inp.filepath, params->geqdsk_file, sizeof(params->geqdsk_file)); @@ -165,310 +164,320 @@ create_asdex_lsn_gk_block_geom(void *ctx) // Theta limits are actually set internally by the code. double theta_min = -1.0, theta_max = 1.0; - double psi_sep = params->psi_sep; // Psi at the separatrix. + double psi_sep = params->psi_sep; // Psi at the separatrix. double psi_axis = params->psi_axis; // Psi at the magnetic axis. double psi_max_core = params->psi_max_core; // Minimum psi the core. - double psi_min_sol = params->psi_min_sol ; // Maximum psi the SOL. - double psi_max_pf = params->psi_max_pf ; // Minimum psi the private flux. + double psi_min_sol = params->psi_min_sol; // Maximum psi the SOL. + double psi_max_pf = params->psi_max_pf; // Minimum psi the private flux. double y_min = params->y_min; // Lower boundary in y. double y_max = params->y_max; // Upper boundary in y. // Number of cells. - int Npsi_sol = params->Npsi_sol ; - int Npsi_pf = params->Npsi_pf ; - int Npsi_core = params->Npsi_core ; + int Npsi_sol = params->Npsi_sol; + int Npsi_pf = params->Npsi_pf; + int Npsi_core = params->Npsi_core; int Ntheta_divertor_lfs = params->Ntheta_divertor_lfs; int Ntheta_divertor_hfs = params->Ntheta_divertor_hfs; - int Ntheta_sol = params->Ntheta_sol ; - int Ny = params->Ny ; + int Ntheta_sol = params->Ntheta_sol; + int Ny = params->Ny; // Block 0: outer private flux (PF) region. - gkyl_gk_block_geom_set_block(bgeom, 0, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_sep, y_min, theta_min }, - .upper = { psi_max_pf, y_max, theta_max }, - .cells = { Npsi_pf, Ny, Ntheta_divertor_lfs }, - .cuts = { 1, 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_R, - .rmin = 0.618, - .rmax = 1.14, - .zmin = -0.75, - .zmax = -0.38, - .rleft = 0.618, - .rright = 1.14, - .zmin_left = -0.45, - .zmin_right = -0.75, - .plate_spec = true, - .plate_func_lower = divertor_plate_func_out, - .plate_func_upper = divertor_plate_func_in, + gkyl_gk_block_geom_set_block( + bgeom, 0, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_sep, y_min, theta_min}, + .upper = {psi_max_pf, y_max, theta_max}, + .cells = {Npsi_pf, Ny, Ntheta_divertor_lfs}, + .cuts = {1, 1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_R, + .rmin = 0.618, + .rmax = 1.14, + .zmin = -0.75, + .zmax = -0.38, + .rleft = 0.618, + .rright = 1.14, + .zmin_left = -0.45, + .zmin_right = -0.75, + .plate_spec = true, + .plate_func_lower = divertor_plate_func_out, + .plate_func_upper = divertor_plate_func_in}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = params->radial_compression_fac, + .compression_factor = params->parallel_compression_fac}}, + + .connections[0] = + {// x-direction. + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // Physical boundary. + {.bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor = true, - .radial_compression_factor = params->radial_compression_fac, - .compression_factor = params->parallel_compression_fac + .connections[1] = + {// y-direction. + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} }, - }, - - .connections[0] = { // x-direction. - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - { .bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE }, - }, - .connections[1] = { // y-direction. - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - }, - .connections[2] = { // z-direction. - { .bid = 0, .dir = 2, .edge = GKYL_PHYSICAL}, // Physical boundary. - { .bid = 4, .dir = 2, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[2] = + {// z-direction. + {.bid = 0, .dir = 2, .edge = GKYL_PHYSICAL}, // Physical boundary. + {.bid = 4, .dir = 2, .edge = GKYL_LOWER_POSITIVE} + }} ); // Block 1: lower outer SOL. - gkyl_gk_block_geom_set_block(bgeom, 1, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_min_sol, y_min, theta_min }, - .upper = { psi_sep, y_max, theta_max }, - .cells = { Npsi_sol, Ny, Ntheta_divertor_lfs }, - .cuts = { 1, 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO, - .rmin = 0.618, - .rmax = 1.14, - .zmin = -0.75, - .zmax = 0.35, - .rclose = 0.825, - .rleft = 0.62, - .rright = 0.9, - .zmin_left = -0.45, - .zmin_right = -0.75, - .plate_spec = true, - .plate_func_lower = divertor_plate_func_out, - .plate_func_upper = divertor_plate_func_in, + gkyl_gk_block_geom_set_block( + bgeom, 1, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_min_sol, y_min, theta_min}, + .upper = {psi_sep, y_max, theta_max}, + .cells = {Npsi_sol, Ny, Ntheta_divertor_lfs}, + .cuts = {1, 1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO, + .rmin = 0.618, + .rmax = 1.14, + .zmin = -0.75, + .zmax = 0.35, + .rclose = 0.825, + .rleft = 0.62, + .rright = 0.9, + .zmin_left = -0.45, + .zmin_right = -0.75, + .plate_spec = true, + .plate_func_lower = divertor_plate_func_out, + .plate_func_upper = divertor_plate_func_in}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = params->radial_compression_fac, + .compression_factor = params->parallel_compression_fac}}, + + .connections[0] = + { + // x-direction. + {.bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 1, .dir = 0, .edge = GKYL_PHYSICAL} // Physical boundary. }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor = true, - .radial_compression_factor = params->radial_compression_fac, - .compression_factor = params->parallel_compression_fac + .connections[1] = + {// y-direction. + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} }, - }, - - .connections[0] = { // x-direction. - { .bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 1, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - }, - .connections[1] = { // y-direction. - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - }, - .connections[2] = { // z-direction. - { .bid = 1, .dir = 2, .edge = GKYL_PHYSICAL}, // Physical boundary. - { .bid = 2, .dir = 2, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[2] = + {// z-direction. + {.bid = 1, .dir = 2, .edge = GKYL_PHYSICAL}, // Physical boundary. + {.bid = 2, .dir = 2, .edge = GKYL_LOWER_POSITIVE} + }} ); // Block 2: mid SOL. - gkyl_gk_block_geom_set_block(bgeom, 2, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_min_sol, y_min, theta_min }, - .upper = { psi_sep, y_max, theta_max }, - .cells = { Npsi_sol, Ny, Ntheta_sol }, - .cuts = { 1, 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID, - .rmin = 0.618, - .rmax = 1.14, - .zmin = -0.75, - .zmax = 0.35, - .rclose = 0.825, - .rleft = 0.62, - .rright = 0.9, - .zmin_left = -0.45, - .zmin_right = -0.75, - .plate_spec = true, - .plate_func_lower = divertor_plate_func_out, - .plate_func_upper = divertor_plate_func_in, + gkyl_gk_block_geom_set_block( + bgeom, 2, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_min_sol, y_min, theta_min}, + .upper = {psi_sep, y_max, theta_max}, + .cells = {Npsi_sol, Ny, Ntheta_sol}, + .cuts = {1, 1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID, + .rmin = 0.618, + .rmax = 1.14, + .zmin = -0.75, + .zmax = 0.35, + .rclose = 0.825, + .rleft = 0.62, + .rright = 0.9, + .zmin_left = -0.45, + .zmin_right = -0.75, + .plate_spec = true, + .plate_func_lower = divertor_plate_func_out, + .plate_func_upper = divertor_plate_func_in}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = params->radial_compression_fac, + .compression_factor = params->parallel_compression_fac}}, + + .connections[0] = + { + // x-direction. + {.bid = 5, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 0, .edge = GKYL_PHYSICAL} // Physical boundary. }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor = true, - .radial_compression_factor = params->radial_compression_fac, - .compression_factor = params->parallel_compression_fac + .connections[1] = + {// y-direction. + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} }, - }, - - .connections[0] = { // x-direction. - { .bid = 5, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 2, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - }, - .connections[1] = { // y-direction. - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - }, - .connections[2] = { // z-direction. - { .bid = 1, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 3, .dir = 2, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[2] = + {// z-direction. + {.bid = 1, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 2, .edge = GKYL_LOWER_POSITIVE} + }} ); // Block 3: lower inner SOL. - gkyl_gk_block_geom_set_block(bgeom, 3, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_min_sol, y_min, theta_min }, - .upper = { psi_sep, y_max, theta_max }, - .cells = { Npsi_sol, Ny, Ntheta_divertor_hfs }, - .cuts = { 1, 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP, - .rmin = 0.618, - .rmax = 1.14, - .zmin = -0.75, - .zmax = 0.35, - .rclose = 0.825, - .rleft = 0.62, - .rright = 0.9, - .zmin_left = -0.45, - .zmin_right = -0.75, - .plate_spec = true, - .plate_func_lower = divertor_plate_func_out, - .plate_func_upper = divertor_plate_func_in, + gkyl_gk_block_geom_set_block( + bgeom, 3, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_min_sol, y_min, theta_min}, + .upper = {psi_sep, y_max, theta_max}, + .cells = {Npsi_sol, Ny, Ntheta_divertor_hfs}, + .cuts = {1, 1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP, + .rmin = 0.618, + .rmax = 1.14, + .zmin = -0.75, + .zmax = 0.35, + .rclose = 0.825, + .rleft = 0.62, + .rright = 0.9, + .zmin_left = -0.45, + .zmin_right = -0.75, + .plate_spec = true, + .plate_func_lower = divertor_plate_func_out, + .plate_func_upper = divertor_plate_func_in}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = params->radial_compression_fac, + .compression_factor = params->parallel_compression_fac}}, + + .connections[0] = + { + // x-direction. + {.bid = 4, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 0, .edge = GKYL_PHYSICAL} // Physical boundary. }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor = true, - .radial_compression_factor = params->radial_compression_fac, - .compression_factor = params->parallel_compression_fac + .connections[1] = + {// y-direction. + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} }, - }, - - .connections[0] = { // x-direction. - { .bid = 4, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 3, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - }, - .connections[1] = { // y-direction. - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - }, - .connections[2] = { // z-direction. - { .bid = 2, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 3, .dir = 2, .edge = GKYL_PHYSICAL}, // Physical boundary. - } - } + .connections[2] = + { + // z-direction. + {.bid = 2, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 2, .edge = GKYL_PHYSICAL} // Physical boundary. + }} ); // Block 4: inner private flux (PF) region. - gkyl_gk_block_geom_set_block(bgeom, 4, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_sep, y_min, theta_min }, - .upper = { psi_max_pf, y_max, theta_max }, - .cells = { Npsi_pf, Ny, Ntheta_divertor_hfs }, - .cuts = { 1, 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_L, - .rmin = 0.618, - .rmax = 1.14, - .zmin = -0.75, - .zmax = -0.38, - .rleft = 0.618, - .rright = 1.14, - .zmin_left = -0.45, - .zmin_right = -0.75, - .plate_spec = true, - .plate_func_lower = divertor_plate_func_out, - .plate_func_upper = divertor_plate_func_in, + gkyl_gk_block_geom_set_block( + bgeom, 4, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_sep, y_min, theta_min}, + .upper = {psi_max_pf, y_max, theta_max}, + .cells = {Npsi_pf, Ny, Ntheta_divertor_hfs}, + .cuts = {1, 1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_PF_LO_L, + .rmin = 0.618, + .rmax = 1.14, + .zmin = -0.75, + .zmax = -0.38, + .rleft = 0.618, + .rright = 1.14, + .zmin_left = -0.45, + .zmin_right = -0.75, + .plate_spec = true, + .plate_func_lower = divertor_plate_func_out, + .plate_func_upper = divertor_plate_func_in}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = params->radial_compression_fac, + .compression_factor = params->parallel_compression_fac}}, + + .connections[0] = + {// x-direction. + {.bid = 4, .dir = 0, .edge = GKYL_PHYSICAL}, // Physical boundary. + {.bid = 3, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor = true, - .radial_compression_factor = params->radial_compression_fac, - .compression_factor = params->parallel_compression_fac + .connections[1] = + {// y-direction. + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} }, - }, - - .connections[0] = { // x-direction. - { .bid = 4, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - { .bid = 3, .dir = 0, .edge = GKYL_LOWER_POSITIVE }, - }, - .connections[1] = { // y-direction. - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - }, - .connections[2] = { // z-direction. - { .bid = 0, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, // Physical boundary. - { .bid = 4, .dir = 2, .edge = GKYL_PHYSICAL}, - } - } + .connections[2] = + {// z-direction. + {.bid = 0, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, // Physical boundary. + {.bid = 4, .dir = 2, .edge = GKYL_PHYSICAL} + }} ); // Block 5: core region. - gkyl_gk_block_geom_set_block(bgeom, 5, &(struct gkyl_gk_block_geom_info) { - .lower = { psi_sep, y_min, theta_min }, - .upper = { psi_max_core, y_max, theta_max }, - .cells = { Npsi_core, Ny, Ntheta_sol }, - .cuts = { 1, 1, 1 }, - .geometry = { - .world = {0.0}, - .geometry_id = GKYL_GEOMETRY_TOKAMAK, - .efit_info = efit_inp, - .tok_grid_info = (struct gkyl_tok_geo_grid_inp) { - .ftype = GKYL_GEOMETRY_TOKAMAK_CORE, - .rmin = 0.618, - .rmax = 1.14, - .zmin = -0.75, - .zmax = 0.35, - .rclose = 1.14, - .rleft = 0.618, - .rright = 1.14, + gkyl_gk_block_geom_set_block( + bgeom, 5, + &(struct gkyl_gk_block_geom_info + ){.lower = {psi_sep, y_min, theta_min}, + .upper = {psi_max_core, y_max, theta_max}, + .cells = {Npsi_core, Ny, Ntheta_sol}, + .cuts = {1, 1, 1}, + .geometry = + {.world = {0.0}, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .efit_info = efit_inp, + .tok_grid_info = (struct gkyl_tok_geo_grid_inp + ){.ftype = GKYL_GEOMETRY_TOKAMAK_CORE, + .rmin = 0.618, + .rmax = 1.14, + .zmin = -0.75, + .zmax = 0.35, + .rclose = 1.14, + .rleft = 0.618, + .rright = 1.14}, + .position_map_info = + {.id = GKYL_PMAP_XPT_COMPRESSION, + .compress_divertor = true, + .radial_compression_factor = params->radial_compression_fac, + .compression_factor = params->parallel_compression_fac}}, + + .connections[0] = + {// x-direction. + {.bid = 5, .dir = 0, .edge = GKYL_PHYSICAL}, // Physical boundary. + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} }, - .position_map_info = { - .id = GKYL_PMAP_XPT_COMPRESSION, - .compress_divertor = true, - .radial_compression_factor = params->radial_compression_fac, - .compression_factor = params->parallel_compression_fac + .connections[1] = + {// y-direction. + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} }, - }, - - .connections[0] = { // x-direction. - { .bid = 5, .dir = 0, .edge = GKYL_PHYSICAL }, // Physical boundary. - { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE }, - }, - .connections[1] = { // y-direction. - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, - }, - .connections[2] = { // z-direction. - { .bid = 5, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, - { .bid = 5, .dir = 2, .edge = GKYL_LOWER_POSITIVE}, - } - } + .connections[2] = + {// z-direction. + {.bid = 5, .dir = 2, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 5, .dir = 2, .edge = GKYL_LOWER_POSITIVE} + }} ); return bgeom; } // Velocity space mappings. -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_tcv_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -476,18 +485,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_tcv_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -495,19 +505,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -double -init_profile(double psi, double f_min, double f_max, void *ctx) +double init_profile(double psi, double f_min, double f_max, void *ctx) { // Profile in D. Michels, et al. Phys. Plasmas 29, 032307 (2022) eqn 17: struct gk_tcv_ctx *params = ctx; @@ -520,24 +530,24 @@ init_profile(double psi, double f_min, double f_max, void *ctx) double rho_max = rho_psi(psi_max, psi_axis, psi_sep); double rho = rho_psi(psi, psi_axis, psi_sep); - double c1 = (f_max-f_min)/2.0; - double c2 = M_PI/(rho_max-rho_min); - double c3 = M_PI/2 - c2*rho_min; - double c4 = (f_max+f_min)/2.0; + double c1 = (f_max - f_min) / 2.0; + double c2 = M_PI / (rho_max - rho_min); + double c3 = M_PI / 2 - c2 * rho_min; + double c4 = (f_max + f_min) / 2.0; double f = -1.0; - if (rho <= rho_min) + if (rho <= rho_min) { f = f_max; - else if (rho_min < rho && rho <= rho_max) - f = c1*sin(c2*rho + c3) + c4; - else + } else if (rho_min < rho && rho <= rho_max) { + f = c1 * sin(c2 * rho + c3) + c4; + } else { f = f_min; + } return f; } -void -init_dens(double t, const double *xn, double* restrict fout, void *ctx) +void init_dens(double t, const double *xn, double *restrict fout, void *ctx) { double psi = xn[0], alpha = xn[1], theta = xn[2]; @@ -548,11 +558,10 @@ init_dens(double t, const double *xn, double* restrict fout, void *ctx) double rho = rho_psi(psi, psi_axis, psi_sep); - fout[0] = n_max * 1.165 * 0.5 * (1.0 + (0.815/1.165) * tanh((0.905 - rho)/0.048)); + fout[0] = n_max * 1.165 * 0.5 * (1.0 + (0.815 / 1.165) * tanh((0.905 - rho) / 0.048)); } -void -init_temp_elc(double t, const double *xn, double* restrict fout, void *ctx) +void init_temp_elc(double t, const double *xn, double *restrict fout, void *ctx) { double psi = xn[0], alpha = xn[1], theta = xn[2]; @@ -563,11 +572,10 @@ init_temp_elc(double t, const double *xn, double* restrict fout, void *ctx) double rho = rho_psi(psi, psi_axis, psi_sep); - fout[0] = Te_max * 1.1694 * 0.5 * ( 1.0 + (95.05/116.94) * tanh((0.87 - rho)/0.066)); + fout[0] = Te_max * 1.1694 * 0.5 * (1.0 + (95.05 / 116.94) * tanh((0.87 - rho) / 0.066)); } -void -init_temp_ion(double t, const double *xn, double* restrict fout, void *ctx) +void init_temp_ion(double t, const double *xn, double *restrict fout, void *ctx) { double psi = xn[0], alpha = xn[1], theta = xn[2]; @@ -578,17 +586,17 @@ init_temp_ion(double t, const double *xn, double* restrict fout, void *ctx) double rho = rho_psi(psi, psi_axis, psi_sep); - fout[0] = Ti_max * 1.1694 * 0.5 * ( 1.0 + (95.05/116.94) * tanh((0.87 - rho)/0.066)); + fout[0] = Ti_max * 1.1694 * 0.5 * (1.0 + (95.05 / 116.94) * tanh((0.87 - rho) / 0.066)); } -void -init_upar(double t, const double *xn, double* restrict fout, void *ctx) +void init_upar(double t, const double *xn, double *restrict fout, void *ctx) { fout[0] = 0.0; } -void -init_source_dens(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_source_dens( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double psi = xn[0], alpha = xn[1], theta = xn[2]; @@ -598,21 +606,24 @@ init_source_dens(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRIC double ndot_src = params->ndot_src; double source_floor = 1e-10; - if (psi < psi_src + 3*lambda_src) + if (psi < psi_src + 3 * lambda_src) { source_floor = 1e-2; + } - double src_prof = exp(-pow(psi-psi_src,2)/(2*pow(lambda_src,2))); + double src_prof = exp(-pow(psi - psi_src, 2) / (2 * pow(lambda_src, 2))); fout[0] = ndot_src * fmax(src_prof, source_floor); } -void -init_source_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_source_upar( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -init_source_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_source_temp_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double psi = xn[0], alpha = xn[1], theta = xn[2]; @@ -622,14 +633,16 @@ init_source_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RES double Te_src = params->Te_src; double eV = GKYL_ELEMENTARY_CHARGE; - if (psi < psi_src + 3*lambda_src) + if (psi < psi_src + 3 * lambda_src) { fout[0] = Te_src; - else - fout[0] = 2.0*eV; + } else { + fout[0] = 2.0 * eV; + } } -void -init_source_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void init_source_temp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_tcv_ctx *params = ctx; double psi = xn[0], alpha = xn[1], theta = xn[2]; @@ -639,53 +652,56 @@ init_source_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RES double Ti_src = params->Ti_src; double eV = GKYL_ELEMENTARY_CHARGE; - if (psi < psi_src + 3*lambda_src) + if (psi < psi_src + 3 * lambda_src) { fout[0] = Ti_src; - else - fout[0] = 2.0*eV; + } else { + fout[0] = 2.0 * eV; + } } -struct gk_tcv_ctx -create_ctx(void) +struct gk_tcv_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; // Permittivity of free space. double eV = GKYL_ELEMENTARY_CHARGE; // Elementary charge. - double mi = 2.014*GKYL_PROTON_MASS; // Ion mass. + double mi = 2.014 * GKYL_PROTON_MASS; // Ion mass. double me = GKYL_ELECTRON_MASS; // Electron mass. double qi = eV; // Ion charge. double qe = -eV; // Electron charge. - double Te_max = 200.0*eV; // Maximum electron temperature. - double Ti_max = 200.0*eV; // Maximum ion temperature. - double B_max = 1.561831e+00; // Maximum B field amplitude. - double n_max = 2.0e19; // Maximum particle density. + double Te_max = 200.0 * eV; // Maximum electron temperature. + double Ti_max = 200.0 * eV; // Maximum ion temperature. + double B_max = 1.561831e+00; // Maximum B field amplitude. + double n_max = 2.0e19; // Maximum particle density. - double Te_min = 20.0*eV; // Minimum electron temperature. - double Ti_min = 20.0*eV; // Minimum ion temperature. - double B_min = 9.689716e-01; // Minimum B field amplitude. - double n_min = 0.2e19; // Minimum particle density. + double Te_min = 20.0 * eV; // Minimum electron temperature. + double Ti_min = 20.0 * eV; // Minimum ion temperature. + double B_min = 9.689716e-01; // Minimum B field amplitude. + double n_min = 0.2e19; // Minimum particle density. - double Te0 = 0.5*(Te_min+Te_max); // Reference electron temperature. - double Ti0 = 0.5*(Ti_min+Ti_max); // Reference ion temperature. - double B0 = 0.5*(B_min +B_max ); // Reference B field amplitude. - double n0 = 0.5*(n_min +n_max ); // Reference particle density. + double Te0 = 0.5 * (Te_min + Te_max); // Reference electron temperature. + double Ti0 = 0.5 * (Ti_min + Ti_max); // Reference ion temperature. + double B0 = 0.5 * (B_min + B_max); // Reference B field amplitude. + double n0 = 0.5 * (n_min + n_max); // Reference particle density. // Derived parameters. - double vt_ion = sqrt(Ti0/mi); - double vt_elc = sqrt(Te0/me); - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; + double vt_ion = sqrt(Ti0 / mi); + double vt_elc = sqrt(Te0 / me); + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // Collision parameters. - double nu_frac = 1.0; - double logLambda_elc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te0/eV); - double nu_elc = nu_frac*logLambda_elc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*pow(eps0,2)*sqrt(me)*pow(Te0,3.0/2.0)); + double nu_frac = 1.0; + double logLambda_elc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); + double nu_elc = + nu_frac * logLambda_elc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * pow(eps0, 2) * sqrt(me) * pow(Te0, 3.0 / 2.0)); - double logLambda_ion = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti0/eV); - double nu_ion = nu_frac*logLambda_ion*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*pow(eps0,2)*sqrt(mi)*pow(Ti0,3.0/2.0)); + double logLambda_ion = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); + double nu_ion = nu_frac * logLambda_ion * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * pow(eps0, 2) * sqrt(mi) * pow(Ti0, 3.0 / 2.0)); // Location of the numerical equilibrium. char geqdsk_file[128] = "gyrokinetic/data/eqdsk/tcv_65402_t1.eqdsk"; @@ -694,10 +710,9 @@ create_ctx(void) double num_blocks = 6; // Get the separatrix psi. - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .rz_poly_order = 2, - .flux_poly_order = 1, + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .rz_poly_order = 2, + .flux_poly_order = 1 }; // Copy eqdsk file into efit_inp. memcpy(efit_inp.filepath, geqdsk_file, sizeof(geqdsk_file)); @@ -712,7 +727,7 @@ create_ctx(void) double rho_max_sol = 1.04; double psi_max_core = psi_rho(rho_min_core, psi_axis, psi_sep); double psi_min_sol = psi_rho(rho_max_sol, psi_axis, psi_sep); - double psi_max_pf = psi_sep + 0.5*(psi_sep-psi_min_sol); + double psi_max_pf = psi_sep + 0.5 * (psi_sep - psi_min_sol); // Number of cells. int Npsi_sol = 4; @@ -725,93 +740,95 @@ create_ctx(void) int Nvpar = 4; // Number of cells in vpar. int Nmu = 4; // Number of cells in mu. - double parallel_compression_fac = 0.5; // Compress cells near X-pt (0 to 1, 0 is full compression). + double parallel_compression_fac = + 0.5; // Compress cells near X-pt (0 to 1, 0 is full compression). double radial_compression_fac = 0.5; // Compress cells separatrix (0 to 1, 0 is full compression). // Adjust psi so that psi_LCFS is at a cell boundary. - double delta_psi = (psi_sep-psi_min_sol)/Npsi_sol; // Cell length in psi. - psi_max_core = psi_sep + Npsi_core*delta_psi; // Adjust inner radial core boundary. + double delta_psi = (psi_sep - psi_min_sol) / Npsi_sol; // Cell length in psi. + psi_max_core = psi_sep + Npsi_core * delta_psi; // Adjust inner radial core boundary. rho_min_core = rho_psi(psi_max_core, psi_axis, psi_sep); // Minimum psi_N. double Lx_core = psi_sep - psi_max_core; double r0 = 1.093 - R_axis; double q0 = 3.2; // q95, see Oliveira 2022. - double Ly = 100*rho_s*q0/r0/3.0; - double y_min = -Ly/2.; - double y_max = Ly/2.; + double Ly = 100 * rho_s * q0 / r0 / 3.0; + double y_min = -Ly / 2.; + double y_max = Ly / 2.; // Source parameters. double power_in = 150e3; // Input power [W]. double ndot_src = 1.85e21; // Input particle source rate [particles/s]. - double Te_src = 0.5*power_in/((3.0/2.0)*ndot_src); - double Ti_src = 0.5*power_in/((3.0/2.0)*ndot_src); + double Te_src = 0.5 * power_in / ((3.0 / 2.0) * ndot_src); + double Ti_src = 0.5 * power_in / ((3.0 / 2.0) * ndot_src); double psi_src = psi_max_core; double lambda_src = psi_rho(0.915, psi_axis, psi_sep) - psi_max_core; // Physical velocity space limits - double vpar_max_elc = 6.0*vt_elc; - double mu_max_elc = me*pow(4.0*vt_elc,2)/(2.0*B0); + double vpar_max_elc = 6.0 * vt_elc; + double mu_max_elc = me * pow(4.0 * vt_elc, 2) / (2.0 * B0); - double vpar_max_ion = 6.0*vt_ion; - double mu_max_ion = mi*pow(4.0*vt_ion,2)/(2.0*B0); + double vpar_max_ion = 6.0 * vt_ion; + double mu_max_ion = mi * pow(4.0 * vt_ion, 2) / (2.0 * B0); // Computational velocity space limits. - double vpar_min_ion_c = -1.0/sqrt(2.0); - double vpar_max_ion_c = 1.0/sqrt(2.0); + double vpar_min_ion_c = -1.0 / sqrt(2.0); + double vpar_max_ion_c = 1.0 / sqrt(2.0); double mu_min_ion_c = 0.; double mu_max_ion_c = 1.; // Computational velocity space limits. - double vpar_min_elc_c = -1.0/sqrt(2.0); - double vpar_max_elc_c = 1.0/sqrt(2.0); + double vpar_min_elc_c = -1.0 / sqrt(2.0); + double vpar_max_elc_c = 1.0 / sqrt(2.0); double mu_min_elc_c = 0.; double mu_max_elc_c = 1.; - printf(" X-point @ (R,Z) = (%.9e,%9e)\n",Rxpt,Zxpt); - printf(" psi_axis = %.13e\n",psi_axis); - printf(" psi_sep = %.13e\n",psi_sep); - printf(" rho_min_core = %.13e\n",rho_min_core); - printf(" rho_max_sol = %.13e\n",rho_max_sol); - printf(" psi_max_core = %.13e\n",psi_max_core); - printf(" psi_min_sol = %.13e\n",psi_min_sol); - printf(" psi_max_pf = %.13e\n",psi_max_pf); - printf(" Npsi_sol = %d\n",Npsi_sol ); - printf(" Npsi_pf = %d\n",Npsi_pf ); - printf(" Npsi_core = %d\n",Npsi_core ); - printf(" Ntheta_divertor_lfs = %d\n",Ntheta_divertor_lfs); - printf(" Ntheta_divertor_hfs = %d\n",Ntheta_divertor_hfs); - printf(" Ntheta_sol = %d\n",Ntheta_sol ); + printf(" X-point @ (R,Z) = (%.9e,%9e)\n", Rxpt, Zxpt); + printf(" psi_axis = %.13e\n", psi_axis); + printf(" psi_sep = %.13e\n", psi_sep); + printf(" rho_min_core = %.13e\n", rho_min_core); + printf(" rho_max_sol = %.13e\n", rho_max_sol); + printf(" psi_max_core = %.13e\n", psi_max_core); + printf(" psi_min_sol = %.13e\n", psi_min_sol); + printf(" psi_max_pf = %.13e\n", psi_max_pf); + printf(" Npsi_sol = %d\n", Npsi_sol); + printf(" Npsi_pf = %d\n", Npsi_pf); + printf(" Npsi_core = %d\n", Npsi_core); + printf(" Ntheta_divertor_lfs = %d\n", Ntheta_divertor_lfs); + printf(" Ntheta_divertor_hfs = %d\n", Ntheta_divertor_hfs); + printf(" Ntheta_sol = %d\n", Ntheta_sol); double t_end = 1.0e-7; double num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_tcv_ctx ctx = { .cdim = cdim, .vdim = vdim, - .charge_elc = qe, - .charge_ion = qi, - .mass_elc = me, + .charge_elc = qe, + .charge_ion = qi, + .mass_elc = me, .mass_ion = mi, - .Te_max = Te_max, - .Ti_max = Ti_max, - .n_max = n_max, - .Te0 = Te0, - .Ti0 = Ti0, - .n0 = n0, - .B0 = B0, - .c_s = c_s, - .nu_frac = nu_frac, + .Te_max = Te_max, + .Ti_max = Ti_max, + .n_max = n_max, + .Te0 = Te0, + .Ti0 = Ti0, + .n0 = n0, + .B0 = B0, + .c_s = c_s, + .nu_frac = nu_frac, .num_blocks = num_blocks, .psi_axis = psi_axis, .psi_sep = psi_sep, .psi_max_core = psi_max_core, .psi_min_sol = psi_min_sol, .psi_max_pf = psi_max_pf, - .Lx_core = Lx_core, + .Lx_core = Lx_core, .Ly = Ly, .y_min = y_min, .y_max = y_max, @@ -821,10 +838,10 @@ create_ctx(void) .Te_src = Te_src, .Ti_src = Ti_src, // Physical velocity space limits - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, // Computational velocity space limits .vpar_min_elc_c = vpar_min_elc_c, .vpar_max_elc_c = vpar_max_elc_c, @@ -834,24 +851,24 @@ create_ctx(void) .vpar_max_ion_c = vpar_max_ion_c, .mu_min_ion_c = mu_min_ion_c, .mu_max_ion_c = mu_max_ion_c, - .Npsi_sol = Npsi_sol , - .Npsi_pf = Npsi_pf , - .Npsi_core = Npsi_core , + .Npsi_sol = Npsi_sol, + .Npsi_pf = Npsi_pf, + .Npsi_core = Npsi_core, .Ntheta_divertor_lfs = Ntheta_divertor_lfs, .Ntheta_divertor_hfs = Ntheta_divertor_hfs, - .Ntheta_sol = Ntheta_sol , - .Ny = Ny , + .Ntheta_sol = Ntheta_sol, + .Ny = Ny, .Nvpar = Nvpar, .Nmu = Nmu, .cells_v = {Nvpar, Nmu}, .parallel_compression_fac = parallel_compression_fac, - .radial_compression_fac = radial_compression_fac, - .t_end = t_end, - .num_frames = num_frames, + .radial_compression_fac = radial_compression_fac, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; // Copy eqdsk file into ctx. @@ -859,8 +876,7 @@ create_ctx(void) return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -879,27 +895,27 @@ main(int argc, char **argv) struct gkyl_comm *comm = gkyl_gyrokinetic_comms_new(app_args.use_mpi, app_args.use_gpu, stderr); struct gk_tcv_ctx ctx = create_ctx(); // Context for init functions. - + // Construct block geometry struct gkyl_gk_block_geom *bgeom = create_asdex_lsn_gk_block_geom(&ctx); int cells_v[ctx.vdim]; - for (int d=0; dcdim = ctx.cdim; app_inp->poly_order = 1; app_inp->basis_type = app_args.basis_type; @@ -1187,17 +1200,16 @@ main(int argc, char **argv) struct gkyl_gyrokinetic_run_inp run_inp = { .app_type = GKYL_GK_MULTIB, .multib_app_inp = *app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = app_args.num_steps, - }, + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = app_args.num_steps} }; gkyl_gyrokinetic_run_simulation(&run_inp); @@ -1207,9 +1219,10 @@ main(int argc, char **argv) gkyl_free(app_inp); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif - + return 0; } diff --git a/gyrokinetic/creg/rt_gk_neut_recycle_1x3v_p1.c b/gyrokinetic/creg/rt_gk_neut_recycle_1x3v_p1.c index d36e898db7..9883a8ec05 100644 --- a/gyrokinetic/creg/rt_gk_neut_recycle_1x3v_p1.c +++ b/gyrokinetic/creg/rt_gk_neut_recycle_1x3v_p1.c @@ -11,10 +11,9 @@ #include -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. - + // Physical constants (using non-normalized physical units). double mass_elc; // Electron mass. double charge_elc; // Electron charge. @@ -31,7 +30,7 @@ struct sheath_ctx double Tn_recycle; // Neutral recycling temperature. double k_perp_rho_s; // Product of perpendicular wavenumber and ion-sound gyroradius. - + double B0; // Reference magnetic field strength (Tesla). double c_s; // Sound speed. @@ -65,8 +64,7 @@ struct sheath_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -76,7 +74,7 @@ create_ctx(void) double mass_ion = GKYL_PROTON_MASS; // Proton mass. double mass_neut = mass_ion; // Neutral mass. double charge_elc = -eV; // Electron charge. - double charge_ion = eV; // Proton charge. + double charge_ion = eV; // Proton charge. double Te = 30.0 * eV; // Electron temperature. double Ti = 60.0 * eV; // Ion temperature. @@ -101,8 +99,8 @@ create_ctx(void) double k_perp = k_perp_rho_s / rho_s; // Perpendicular wavenumber (for Poisson solver). - double n_src = pow(n0,2.0)*8e-21; // Source number density. - double T_src = 10.0*eV; // Source temperature. + double n_src = pow(n0, 2.0) * 8e-21; // Source number density. + double T_src = 10.0 * eV; // Source temperature. int Nz = 224; // Number of cells along magnetic field. int Nvpar = 16; // Number of cells in vpar. @@ -110,18 +108,18 @@ create_ctx(void) int Nv = 16; // Number of cells in neutral v. double Lz = 40.0; // Domain size along z. - double vpar_max_elc = 4.0*vte; // Maximum electron vpar. - double mu_max_elc = 12.0*mass_elc*pow(vte,2)/(2.0*B0); // Maximum electron mu. + double vpar_max_elc = 4.0 * vte; // Maximum electron vpar. + double mu_max_elc = 12.0 * mass_elc * pow(vte, 2) / (2.0 * B0); // Maximum electron mu. double vpar_max_ion = 4.0 * vti; // Maximum ion vpar. - double mu_max_ion = 12.0*mass_ion*pow(vti,2)/(2.0*B0); // Maximum ion mu. + double mu_max_ion = 12.0 * mass_ion * pow(vti, 2) / (2.0 * B0); // Maximum ion mu. double v_max_neut = 4.0 * vtn; // Maximum neutral velocity. - - double t_end = .00625*Lz/c_s; // Final simulation time. + + double t_end = .00625 * Lz / c_s; // Final simulation time. int num_frames = 1; // Number of output frames. - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -162,14 +160,15 @@ create_ctx(void) .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Neutral source rate. struct sheath_ctx *app = ctx; @@ -180,17 +179,19 @@ evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = n_src; } -void -evalSourceUdriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceUdriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Neutral source drift velocity. - fout[0] = 0.0; + fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; } -void -evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Neutral source temperature. struct sheath_ctx *app = ctx; @@ -200,8 +201,7 @@ evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = T_src; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Electron/ion density. struct sheath_ctx *app = ctx; @@ -211,15 +211,15 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -static double -sech(double x) +static double sech(double x) { // Hyperbolic secant. - return 1.0/cosh(x); + return 1.0 / cosh(x); } -void -evalDensityNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityNeutInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Neutral density. struct sheath_ctx *app = ctx; @@ -233,34 +233,30 @@ evalDensityNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR // Set number density. if (z <= 0) { - den = n0*(pow(sech((-Lz/2-z)/z0),2) + flr); - } - else { - den = n0*(pow(sech((Lz/2-z)/z0),2) + flr); + den = n0 * (pow(sech((-Lz / 2 - z) / z0), 2) + flr); + } else { + den = n0 * (pow(sech((Lz / 2 - z) / z0), 2) + flr); } fout[0] = den; } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Electron/ion parallel drift speed. struct sheath_ctx *app = ctx; - double z = xn[0]; - fout[0] = app->c_s*z/(app->Lz/2.); + double z = xn[0]; + fout[0] = app->c_s * z / (app->Lz / 2.); } -void -evalUdriftInit(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalUdriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Neutral drift velocity. - fout[0] = 0.0; + fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; } -void -evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Electron temperature. struct sheath_ctx *app = ctx; @@ -270,8 +266,7 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Ion temperature. struct sheath_ctx *app = ctx; @@ -281,26 +276,28 @@ evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalTempNeutInit(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalTempNeutInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Neutral temperature. struct sheath_ctx *app = ctx; double Tn = app->Tn; - fout[0] = Tn/6.0; + fout[0] = Tn / 6.0; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). double x = zc[0], y = zc[1], z = zc[2]; - xp[0] = x; xp[1] = y; xp[2] = z; + xp[0] = x; + xp[1] = y; + xp[2] = z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -312,8 +309,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -331,215 +327,205 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for initialization functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -24,7 +23,7 @@ struct sheath_ctx double Te; // Electron temperature. double Ti; // Ion temperature. - double T0; // Neutrals. + double T0; // Neutrals. double n0; // Reference number density (1 / m^3). double B_axis; // Magnetic field axis (simple toroidal coordinates). @@ -32,12 +31,12 @@ struct sheath_ctx double a0; // Minor axis (simple toroidal coordinates). double nu_frac; // Collision frequency fraction. - double rec_frac; + double rec_frac; // Derived physical quantities (using non-normalized physical units). double R; // Radial coordinate (simple toroidal coordinates). double B0; // Reference magnetic field strength (Tesla). - + double log_lambda_elc; // Electron Coulomb logarithm. double log_lambda_ion; // Ion Coulomb logarithm. double nu_elc; // Electron collision frequency. @@ -68,23 +67,23 @@ struct sheath_ctx double Ly; // Domain length along y. double Lz; // Domain length along z. double vpar_max_elc; // Maximum parallel electron velocity. - double mu_max_elc; // Maximum electron magnetic moment. + double mu_max_elc; // Maximum electron magnetic moment. double vpar_max_ion; // Maximum parallel ion velocity. - double mu_max_ion; // Maximum ion magnetic moment. + double mu_max_ion; // Maximum ion magnetic moment. double vmax_neut; // Neutrals. int poly_order; // Polynomial order. double cfl_frac; // CFL coefficient. double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -106,20 +105,24 @@ create_ctx(void) double nu_frac = 0.1; // Collision frequency fraction. double rec_frac = 1.0; - + // Derived physical quantities (using non-normalized physical units). double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -139,21 +142,24 @@ create_ctx(void) int Nz = 8; // Number of cells along z. int Nvpar = 6; // Number of cells along vpar. int Nmu = 4; // Number of cells along mu. - double Lx = 50.0*rho_s; // Domain length along x. - double Ly = 100.0*rho_s; // Domain length along 1. + double Lx = 50.0 * rho_s; // Domain length along x. + double Ly = 100.0 * rho_s; // Domain length along 1. double Lz = 4.0; // Domain length along z. - double vpar_max_elc = 4.0*vte; // Maximum parallel electron velocity. - double mu_max_elc = (3.0/2.0)*0.5*mass_elc*pow(4.0*vte,2.0)/(2.0*B0); // Maximum electron magnetic moment. - double vpar_max_ion = 4.0*vti; // Maximum parallel ion velocity. - double mu_max_ion = (3.0/2.0)*0.5*mass_ion*pow(4.0*vti,2.0)/(2.0*B0); // Maximum ion magnetic moment. - double vmax_neut = 4.0*vtn; + double vpar_max_elc = 4.0 * vte; // Maximum parallel electron velocity. + double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Maximum electron magnetic moment. + double vpar_max_ion = 4.0 * vti; // Maximum parallel ion velocity. + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Maximum ion magnetic moment. + double vmax_neut = 4.0 * vtn; int poly_order = 1; // Polynomial order. double cfl_frac = 0.50; // CFL coefficient. double t_end = 2.0e-7; // Final simulation time. int num_frames = 2; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -197,7 +203,7 @@ create_ctx(void) .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, - .cells = {Nx,Ny,Nz,Nvpar,Nmu}, + .cells = {Nx, Ny, Nz, Nvpar, Nmu}, .Lx = Lx, .Ly = Ly, .Lz = Lz, @@ -213,14 +219,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -235,14 +242,17 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -250,9 +260,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -260,8 +271,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -275,8 +285,7 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; // Electron isotropic temperature (left). - } - else { + } else { T = 0.5 * Te; // Electron isotropic temperature (right). } @@ -284,15 +293,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -307,10 +316,12 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Electron source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Electron source total number density (left). + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -318,8 +329,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -332,8 +344,7 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Electron source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Electron source isotropic temperature (right). } @@ -341,15 +352,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -364,14 +377,17 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -379,9 +395,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -389,8 +406,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -404,8 +420,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Ion isotropic temperature (right). } @@ -413,15 +428,16 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } // Neutral profiles. -void neut_density_init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void neut_density_init( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[2]; @@ -431,37 +447,36 @@ void neut_density_init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE //Set number density. if (z <= 0) { - n = n0*(pow(1.0/cosh(-(Lz/2. + z)/0.2),2.0) + 1.e-6); - } - else { - n = n0*(pow(1.0/cosh((-Lz/2. + z)/0.2),2.0) + 1.e-6); + n = n0 * (pow(1.0 / cosh(-(Lz / 2. + z) / 0.2), 2.0) + 1.e-6); + } else { + n = n0 * (pow(1.0 / cosh((-Lz / 2. + z) / 0.2), 2.0) + 1.e-6); } - fout[0] = n; + fout[0] = n; } -void unit_density(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void unit_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; - fout[0] = 1.0; + fout[0] = 1.0; } -void temp_neut(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_neut(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double T = app->T0; fout[0] = T; } -void udrift(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void udrift(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - fout[0] = 0.0; + fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; } - -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -476,10 +491,12 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Ion source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Ion source total number density (left). + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -487,8 +504,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -501,8 +519,7 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Ion source isotropic temperature (right). } @@ -510,15 +527,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -528,8 +545,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -539,8 +555,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -550,8 +565,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -562,7 +576,7 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -577,12 +591,13 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). -// xp[0] = X; xp[1] = Y; xp[2] = Z; - xp[0] = x; xp[1] = y; xp[2] = z; + // xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = x; + xp[1] = y; + xp[2] = z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0]; @@ -590,20 +605,21 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -614,19 +630,18 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcx; double cz = app->cz; double xcenter = 1.2014; - double n = n0*exp(-(x-xcenter)*(x-xcenter)/2/cx/cx) * exp(-z*z/2/cz/cz); - if (n/n0 < 1e-1) - n = n0*1e-1; + double n = n0 * exp(-(x - xcenter) * (x - xcenter) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n / n0 < 1e-1) { + n = n0 * 1e-1; + } fout[0] = n; } -void unit_density(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void unit_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; - fout[0] = 1.0; + fout[0] = 1.0; } -void -eval_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void -evalDensityInitD0(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInitD0( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; double z = xn[0]; @@ -94,8 +94,7 @@ evalDensityInitD0(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = n0; } -void -evalTempD0Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempD0Init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; @@ -105,34 +104,30 @@ evalTempD0Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = TD0; } -void -eval_udrift(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_udrift(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - fout[0] = 0.0; + fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; } - - -void -eval_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double T = app->Te; fout[0] = T; } -void -eval_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double T = app->Ti; fout[0] = T; } -void -eval_density_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_density_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -141,20 +136,23 @@ eval_density_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_REST //double cx = app->cx; //double cz = app->cz; //double xcenter = 1.2014; - if (fabs(z) > app->Lz/20.0*(3.0/4.0) ) + if (fabs(z) > app->Lz / 20.0 * (3.0 / 4.0)) { fout[0] = nsource; - else - fout[0] = nsource*1.e-3; + } else { + fout[0] = nsource * 1.e-3; + } } -void -eval_upar_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; double n0 = app->n0; @@ -162,22 +160,19 @@ eval_temp_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = T; } -void -evalNuElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuD0(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuD0(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; fout[0] = app->nuD0; @@ -187,17 +182,16 @@ double plasma_frequency(double n, double m) { double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - return sqrt(n*eV*eV/m/eps0); + return sqrt(n * eV * eV / m / eps0); } -struct gk_step_ctx -create_ctx(void) +struct gk_step_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge @@ -206,106 +200,107 @@ create_ctx(void) double Te = 25.0 * GKYL_ELEMENTARY_CHARGE; // Electron temperature. double Ti = 25.0 * GKYL_ELEMENTARY_CHARGE; // Ion temperature. double n0 = 1.0e19; // Reference number density (1 / m^3). - + double TD0 = 10.0 * GKYL_ELEMENTARY_CHARGE; - double nD0 = 1.0*n0; + double nD0 = 1.0 * n0; // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); - double vtD0 = sqrt(TD0/mi); + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); + double vtD0 = sqrt(TD0 / mi); // Source parameters. double nsource = 2.870523e25; // Source number density. - double T_source = 2.0*Te; - double cx = 0.0065612*9; + double T_source = 2.0 * Te; + double cx = 0.0065612 * 9; double cz = 0.4916200; // Collision parameters. double nuFrac = 0.25; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nuFrac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); // collision freq - - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nuIon = nuFrac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mi)*(Ti*sqrt(Ti))); + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nuFrac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te)) + ); // collision freq + + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nuIon = nuFrac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mi) * (Ti * sqrt(Ti))); double nuD0 = 1e8; // Simulation box size (m). double lower_x = 0.934; double upper_x = 1.334; double Lx = upper_x - lower_x; - double Lz = (M_PI-1e-14)*2.0; + double Lz = (M_PI - 1e-14) * 2.0; - double vpar_max_elc = 4.0*vtElc; - double mu_max_elc = 12*me*vtElc*vtElc/(2.0*B0); + double vpar_max_elc = 4.0 * vtElc; + double mu_max_elc = 12 * me * vtElc * vtElc / (2.0 * B0); - double vpar_max_ion = 4.0*vtIon; - double mu_max_ion = 12*mi*vtIon*vtIon/(2.0*B0); + double vpar_max_ion = 4.0 * vtIon; + double mu_max_ion = 12 * mi * vtIon * vtIon / (2.0 * B0); double vpar_max_D0 = vtD0; - // Number of cells. int Nx = 4; int Nz = 8; int Nvpar = 12; int Nmu = 8; - double t_end = 1e-6; + double t_end = 1e-6; double num_frames = 1; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_step_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, - .Te = Te, - .Ti = Ti, + .Te = Te, + .Ti = Ti, .TD0 = TD0, .vtIon = vtIon, .vtElc = vtElc, .vtD0 = vtD0, - .nuElc = nuElc, - .nuIon = nuIon, + .nuElc = nuElc, + .nuIon = nuIon, .nuD0 = nuD0, .nuFrac = nuFrac, - .B0 = B0, - .n0 = n0, + .B0 = B0, + .n0 = n0, .nD0 = nD0, - .T_source = T_source, + .T_source = T_source, .nsource = nsource, .cx = cx, .cz = cz, .lower_x = lower_x, .upper_x = upper_x, .Lx = Lx, - .Lz = Lz, - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, - .vpar_max_D0= vpar_max_D0, + .Lz = Lz, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, + .vpar_max_D0 = vpar_max_D0, .Nx = Nx, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -323,157 +318,151 @@ main(int argc, char **argv) struct gk_step_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_nozzle_ctx -{ +struct gk_nozzle_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters @@ -41,46 +40,49 @@ struct gk_nozzle_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -void -eval_density_ion_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_init( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_nozzle_ctx *app = ctx; double z = xn[0]; - if (fabs(z) < 0.2){ + if (fabs(z) < 0.2) { fout[0] = app->n_init; } else { fout[0] = 1e-6 * app->n_init; } } -void -eval_upar_ion_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_init( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_init( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_nozzle_ctx *app = ctx; double z = xn[0]; fout[0] = app->Ti_init; } -void -eval_nu_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_nu_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_nozzle_ctx *app = ctx; fout[0] = app->nu_ion; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_nozzle_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -100,12 +102,11 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * // Quadratic map in mu. // vp[1] = mu_max_ion*pow(cmu,2); - vp[0] = vpar_max_ion*cvpar; - vp[1] = mu_max_ion*cmu; + vp[0] = vpar_max_ion * cvpar; + vp[1] = mu_max_ion * cmu; } -struct gk_nozzle_ctx -create_ctx(void) +struct gk_nozzle_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -114,11 +115,11 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double me = GKYL_ELECTRON_MASS; // Electron mass. double mi = GKYL_PROTON_MASS; // Ion mass. - double qe = -eV; // Electron charge. - double qi = eV; // Ion charge. + double qe = -eV; // Electron charge. + double qi = eV; // Ion charge. double z_min = -1.0; - double z_max = 1.0; + double z_max = 1.0; double psi_eval = 1e-5; double B_p = 0.008; @@ -134,26 +135,26 @@ create_ctx(void) double mu_max_ion = mi * pow(8. * vti, 2.) / (2. * B_p); int Nz = 16; int Nvpar = 32; // Number of cells in the paralell velocity direction 96 - int Nmu = 32; // Number of cells in the mu direction 192 + int Nmu = 32; // Number of cells in the mu direction 192 int poly_order = 1; // double loglambda_ion = 6.6 - 0.5 * log(n_init / 1e20) + 1.5 * log(Ti_init / eV); // double nu_frac = 100.0; // double nu_ion = nu_frac * loglambda_ion * pow(eV, 4.) * n_init / // (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti_init, 3. / 2.)); - + double nu_ion = 1 / (5e-3); printf("nu_ion = %g\n", nu_ion); - printf("1/nu_ion = %g\n", 1.0/nu_ion); + printf("1/nu_ion = %g\n", 1.0 / nu_ion); double t_end = 10e-11; int num_frames = 1300; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - struct gk_nozzle_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -181,18 +182,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -203,10 +205,12 @@ int main(int argc, char **argv) struct gk_nozzle_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_nozzle_ctx -{ +struct gk_nozzle_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters @@ -42,46 +41,49 @@ struct gk_nozzle_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -void -eval_density_ion_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_init( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_nozzle_ctx *app = ctx; double z = xn[0]; - if (fabs(z) < 0.2){ + if (fabs(z) < 0.2) { fout[0] = app->n_init; } else { fout[0] = 1e-6 * app->n_init; } } -void -eval_upar_ion_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_init( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_init( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_nozzle_ctx *app = ctx; double z = xn[0]; fout[0] = app->Ti_init; } -void -eval_nu_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_nu_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_nozzle_ctx *app = ctx; fout[0] = app->nu_ion; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_nozzle_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -101,12 +103,11 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * // Quadratic map in mu. // vp[1] = mu_max_ion*pow(cmu,2); - vp[0] = vpar_max_ion*cvpar; - vp[1] = mu_max_ion*cmu; + vp[0] = vpar_max_ion * cvpar; + vp[1] = mu_max_ion * cmu; } -struct gk_nozzle_ctx -create_ctx(void) +struct gk_nozzle_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -115,11 +116,11 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double me = GKYL_ELECTRON_MASS; // Electron mass. double mi = GKYL_PROTON_MASS; // Ion mass. - double qe = -eV; // Electron charge. - double qi = eV; // Ion charge. + double qe = -eV; // Electron charge. + double qi = eV; // Ion charge. - double z_min = 0.0; - double z_max = 1.0; + double z_min = 0.0; + double z_max = 1.0; double psi_eval = 1e-5; double B_p = 0.008; @@ -137,26 +138,26 @@ create_ctx(void) printf("vpar_max_ion = %g\n", vpar_max_ion); int Nz = 16; int Nvpar = 32; // Number of cells in the paralell velocity direction 96 - int Nmu = 32; // Number of cells in the mu direction 192 + int Nmu = 32; // Number of cells in the mu direction 192 int poly_order = 1; // double loglambda_ion = 6.6 - 0.5 * log(n_init / 1e20) + 1.5 * log(Ti_init / eV); // double nu_frac = 100.0; // double nu_ion = nu_frac * loglambda_ion * pow(eV, 4.) * n_init / // (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti_init, 3. / 2.)); - + double nu_ion = 1 / (5e-3); printf("nu_ion = %g\n", nu_ion); - printf("1/nu_ion = %g\n", 1.0/nu_ion); + printf("1/nu_ion = %g\n", 1.0 / nu_ion); double t_end = 10e-9; int num_frames = 100; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - struct gk_nozzle_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -184,18 +185,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -206,10 +208,12 @@ int main(int argc, char **argv) struct gk_nozzle_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct passive_ctx -{ +struct passive_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -22,7 +21,7 @@ struct passive_ctx double Te; // Electron temperature. double n0; // Reference number density (1 / m^3). double B0; // Reference magnetic field strength (Tesla). - + double ux, uz; // Passive advection velocity. double f_amplitude; // Amplitude of the distribution. double f_floor; // Floor of the distribution. @@ -42,14 +41,14 @@ struct passive_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct passive_ctx -create_ctx(void) +struct passive_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -65,7 +64,7 @@ create_ctx(void) double f_amplitude = 1.0; // Amplitude of the distribution. double f_floor = 1.0e-10; // Floor of the distribution. - double vte = sqrt(Te/mass_elc); // Electron thermal velocity. + double vte = sqrt(Te / mass_elc); // Electron thermal velocity. // Simulation parameters. int Nx = 16; // Cell count (configuration space: x-direction). @@ -74,18 +73,22 @@ create_ctx(void) int Nmu = 2; // Cell count (velocity space: magnetic moment direction). double Lx = 1.0; // Domain size (configuration space: x-direction). double Lz = 1.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0*vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = mass_elc*pow(vpar_max_elc,2.0)/(2.0*B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + mass_elc * pow(vpar_max_elc, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 1.0; // Final simulation time. int num_frames = 10; // Number of output frames. - double write_phase_freq = 1.0; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 1.0; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct passive_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -94,7 +97,8 @@ create_ctx(void) .Te = Te, .n0 = n0, .B0 = B0, - .ux = ux, uz = uz, + .ux = ux, + uz = uz, .f_amplitude = f_amplitude, .f_floor = f_floor, .Nx = Nx, @@ -113,14 +117,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -distf_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void distf_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1], vpar = xn[2], mu = xn[3]; @@ -131,17 +134,19 @@ distf_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double f_floor = app->f_floor; // Cube - double rx2 = pow(x-Lx/2,2); - double rz2 = pow(z-Lz/2,2); + double rx2 = pow(x - Lx / 2, 2); + double rz2 = pow(z - Lz / 2, 2); - if (rx2 < pow(Lx/4,2) && rz2 < pow(Lz/4,2)) + if (rx2 < pow(Lx / 4, 2) && rz2 < pow(Lz / 4, 2)) { fout[0] = f_amplitude; - else + } else { fout[0] = f_floor; + } } -void -passive_velocity_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void passive_velocity_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], z = xn[1]; @@ -154,36 +159,38 @@ passive_velocity_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct passive_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; - xp[0] = x; xp[1] = y; xp[2] = z; + xp[0] = x; + xp[1] = y; + xp[2] = z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct passive_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -194,10 +201,12 @@ main(int argc, char **argv) struct passive_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct passive_ctx -{ +struct passive_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -22,7 +21,7 @@ struct passive_ctx double Te; // Electron temperature. double n0; // Reference number density (1 / m^3). double B0; // Reference magnetic field strength (Tesla). - + double ux, uy, uz; // Passive advection velocity. double f_amplitude; // Amplitude of the distribution. double f_floor; // Floor of the distribution. @@ -44,14 +43,14 @@ struct passive_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct passive_ctx -create_ctx(void) +struct passive_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -67,7 +66,7 @@ create_ctx(void) double f_amplitude = 1.0; // Amplitude of the distribution. double f_floor = 1.0e-10; // Floor of the distribution. - double vte = sqrt(Te/mass_elc); // Electron thermal velocity. + double vte = sqrt(Te / mass_elc); // Electron thermal velocity. // Simulation parameters. int Nx = 16; // Cell count (configuration space: x-direction). @@ -78,18 +77,22 @@ create_ctx(void) double Lx = 1.0; // Domain size (configuration space: x-direction). double Ly = 1.0; // Domain size (configuration space: y-direction). double Lz = 1.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0*vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = mass_elc*pow(vpar_max_elc,2.0)/(2.0*B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + mass_elc * pow(vpar_max_elc, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 1.; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 1.0; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 1.0; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct passive_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -98,7 +101,9 @@ create_ctx(void) .Te = Te, .n0 = n0, .B0 = B0, - .ux = ux, .uy = uy, uz = uz, + .ux = ux, + .uy = uy, + uz = uz, .f_amplitude = f_amplitude, .f_floor = f_floor, .Nx = Nx, @@ -119,14 +124,13 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -distf_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void distf_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2], vpar = xn[3], mu = xn[4]; @@ -138,18 +142,20 @@ distf_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double f_floor = app->f_floor; // Cube - double rx2 = pow(x-Lx/2,2); - double ry2 = pow(y-Ly/2,2); - double rz2 = pow(z-Lz/2,2); + double rx2 = pow(x - Lx / 2, 2); + double ry2 = pow(y - Ly / 2, 2); + double rz2 = pow(z - Lz / 2, 2); - if (rx2 < pow(Lx/4,2) && ry2 < pow(Ly/4,2) && rz2 < pow(Lz/4,2)) + if (rx2 < pow(Lx / 4, 2) && ry2 < pow(Ly / 4, 2) && rz2 < pow(Lz / 4, 2)) { fout[0] = f_amplitude; - else + } else { fout[0] = f_floor; + } } -void -passive_velocity_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void passive_velocity_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; @@ -164,52 +170,54 @@ passive_velocity_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double x = zc[0], y = zc[1], z = zc[2]; struct passive_ctx *app = ctx; - xp[0] = x; xp[1] = y; xp[2] = z; + xp[0] = x; + xp[1] = y; + xp[2] = z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { double x = zc[0], y = zc[1], z = zc[2]; struct passive_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -void bc_shift_func_lo(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_lo(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; struct gk_app_ctx *app = ctx; - fout[0] = -(x-0.5); + fout[0] = -(x - 0.5); } -void bc_shift_func_up(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_up(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { - bc_shift_func_lo(t,xc,fout,ctx); + bc_shift_func_lo(t, xc, fout, ctx); fout[0] *= -1.0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -220,10 +228,12 @@ main(int argc, char **argv) struct passive_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct rad_ctx -{ +struct rad_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -62,14 +61,14 @@ struct rad_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct rad_ctx -create_ctx(void) +struct rad_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -90,15 +89,19 @@ create_ctx(void) double k_perp_rho_s = 0.1; // Product of perpendicular wavenumber and ion-sound gyroradius. // Derived physical constants (using non-normalized physical units). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -112,20 +115,27 @@ create_ctx(void) int Nvpar = 16; // Cell count (velocity space: parallel velocity direction). int Nmu = 8; // Cell count (velocity space: magnetic moment direction). double Lz = 100.0 * rho_s; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = 0.75 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = 0.75 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + 0.75 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + 0.75 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 1.0e-7; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct rad_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -168,14 +178,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct rad_ctx *app = ctx; @@ -185,15 +196,13 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -203,8 +212,9 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct rad_ctx *app = ctx; @@ -214,15 +224,13 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -232,8 +240,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -243,8 +250,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -254,8 +260,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = app->nu_ion; } -void -evalElcIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -265,8 +270,7 @@ evalElcIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalIonElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -277,33 +281,35 @@ evalIonElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -314,10 +320,12 @@ main(int argc, char **argv) struct rad_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct rad_ctx -{ +struct rad_ctx { int cdim, vdim; // Dimensionality. - + // Physical constants (using non-normalized physical units). double epsilon0; // Permittivity of free space. double mass_elc; // Electron mass. @@ -59,14 +58,14 @@ struct rad_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct rad_ctx -create_ctx(void) +struct rad_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -91,13 +90,15 @@ create_ctx(void) double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Collision frequencies. - double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion,4) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_elc) * pow(Te,3.0/2.0)); - double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion,4) * n0 / - (12.0 * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_ion) * pow(Ti,3.0/2.0)); - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4) * n0 / + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); + double nu_ion = + nu_frac * log_lambda_ion * pow(charge_ion, 4) * n0 / + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -112,18 +113,23 @@ create_ctx(void) int Nmu = 32; // Cell count (velocity space: magnetic moment direction). int Nvneut = 8; // Cell count (velocity space: each direction for neutral) double Lz = 2 * 5.596343e-02; // Domain size (configuration space: z-direction). - double vpar_max_elc = 8.0 * vte; // Domain size (electron velocity space: parallel velocity direction). - double mu_max_elc = 0.75 * mass_elc * (4.0 * vte) * (4.0 * vte) / (2.0 * B0); // Domain size (electron velocity space: magnetic moment direction). + double vpar_max_elc = + 8.0 * vte; // Domain size (electron velocity space: parallel velocity direction). + double mu_max_elc = + 0.75 * mass_elc * (4.0 * vte) * (4.0 * vte) / + (2.0 * B0); // Domain size (electron velocity space: magnetic moment direction). double vpar_max_ion = 8.0 * vti; // Domain size (ion velocity space: parallel velocity direction). - double mu_max_ion = 0.75 * mass_ion * (4.0 * vti) * (4.0 * vti) / (2.0 * B0); // Domain size (ion velocity space: magnetic moment direction). + double mu_max_ion = 0.75 * mass_ion * (4.0 * vti) * (4.0 * vti) / + (2.0 * B0); // Domain size (ion velocity space: magnetic moment direction). double t_end = 1.0e-10; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct rad_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -165,47 +171,45 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; - double n0 = app -> n0; + double n0 = app->n0; double x = xn[0]; - double Lz = app -> Lz; + double Lz = app->Lz; // Set number density. - fout[0] = fmax( n0 * pow(x+1.0,120.0), n0*1e-6); + fout[0] = fmax(n0 * pow(x + 1.0, 120.0), n0 * 1e-6); } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct rad_ctx *app = ctx; - double n0 = app -> n0; + double n0 = app->n0; double x = xn[0]; - double Lz = app -> Lz; + double Lz = app->Lz; // Set number density. - fout[0] = fmax( n0 * pow(x+1.0,120.0), n0*1e-6); + fout[0] = fmax(n0 * pow(x + 1.0, 120.0), n0 * 1e-6); } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -215,8 +219,7 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -226,8 +229,7 @@ evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -237,8 +239,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -248,8 +249,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = app->nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -259,8 +259,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -271,33 +270,35 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -308,10 +309,12 @@ main(int argc, char **argv) struct rad_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct rad_ctx -{ +struct rad_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -62,14 +61,14 @@ struct rad_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct rad_ctx -create_ctx(void) +struct rad_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -90,15 +89,19 @@ create_ctx(void) double k_perp_rho_s = 0.1; // Product of perpendicular wavenumber and ion-sound gyroradius. // Derived physical constants (using non-normalized physical units). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -112,20 +115,27 @@ create_ctx(void) int Nvpar = 16; // Cell count (velocity space: parallel velocity direction). int Nmu = 8; // Cell count (velocity space: magnetic moment direction). double Lz = 100.0 * rho_s; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = 0.75 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = 0.75 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + 0.75 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + 0.75 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 1.0e-7; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct rad_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -168,14 +178,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct rad_ctx *app = ctx; @@ -185,15 +196,13 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -203,8 +212,9 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct rad_ctx *app = ctx; @@ -214,15 +224,13 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -232,8 +240,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -243,8 +250,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -254,8 +260,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = app->nu_ion; } -void -evalElcIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -265,8 +270,7 @@ evalElcIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalIonElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; @@ -277,20 +281,21 @@ evalIonElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct rad_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -298,7 +303,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct rad_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -311,23 +316,24 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_elc * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_elc * (cvpar * cvpar); } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -338,10 +344,12 @@ main(int argc, char **argv) struct rad_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. double epsilon0; // Permittivity of free space. @@ -72,14 +71,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -106,15 +105,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -134,20 +137,23 @@ create_ctx(void) int Nvpar = 6; // Number of cells in parallel velocity. int Nmu = 4; // Number of cells in mu. double Lz = 4.0; // Domain size along z. - double vpar_max_elc = 4.0*vte; // Maximum electron parallel velocity. - double mu_max_elc = (3.0/2.0)*0.5*mass_elc*pow(4.0*vte, 2.0)/(2.0*B0); // Maximum electron magnetic moment. - double vpar_max_ion = 4.0*vti; // Maximum ion parallel velocity. - double mu_max_ion = (3.0/2.0)*0.5*mass_ion*pow(4.0*vti, 2.0)/(2.0*B0); // Maximum ion magnetic moment. + double vpar_max_elc = 4.0 * vte; // Maximum electron parallel velocity. + double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Maximum electron magnetic moment. + double vpar_max_ion = 4.0 * vti; // Maximum ion parallel velocity. + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Maximum ion magnetic moment. int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -198,14 +204,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -216,9 +223,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -226,8 +234,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -237,15 +244,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -257,8 +264,7 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Electron source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -266,8 +272,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -277,15 +284,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -296,9 +305,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -306,8 +316,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -317,15 +326,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -337,8 +346,7 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Ion source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -346,8 +354,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -357,15 +366,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -375,8 +384,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -386,8 +394,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -397,8 +404,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -409,33 +415,35 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -446,227 +454,214 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -85,14 +84,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -123,15 +122,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -155,10 +158,16 @@ create_ctx(void) int Nvy_neut = 16; // Cell count (neutral velocity space: vy-direction). int Nvz_neut = 16; // Cell count (neutral velocity space: vz-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double vx_max_neut = 4.0 * vtD0; // Domain boundary (neutral velocity space: vx-direction). double vy_max_neut = 4.0 * vtD0; // Domain boundary (neutral velocity space: vy-direction). double vz_max_neut = 4.0 * vtD0; // Domain boundary (neutral velocity space: vz-direction). @@ -167,11 +176,12 @@ create_ctx(void) double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -232,14 +242,15 @@ create_ctx(void) .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .Nvx_neut = Nvx_neut, + .Nvx_neut = Nvx_neut }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -249,8 +260,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n_peak; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -260,15 +270,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -278,8 +288,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n_peak; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -289,15 +298,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalD0DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalD0DensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -307,8 +316,7 @@ evalD0DensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = n0_D0; } -void -evalD0TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalD0TempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -318,15 +326,17 @@ evalD0TempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = TD0; } -void -evalD0UdriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalD0UdriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set neutral deuterium drift velocity. - fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -336,8 +346,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -347,8 +356,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -358,8 +366,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -370,33 +377,35 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -407,10 +416,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. double epsilon0; // Permittivity of free space. @@ -72,14 +71,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -106,15 +105,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -134,20 +137,23 @@ create_ctx(void) int Nvpar = 6; // Number of cells in parallel velocity. int Nmu = 4; // Number of cells in mu. double Lz = 4.0; // Domain size along z. - double vpar_max_elc = 4.0*vte; // Maximum electron parallel velocity. - double mu_max_elc = (3.0/2.0)*0.5*mass_elc*pow(4.0*vte, 2.0)/(2.0*B0); // Maximum electron magnetic moment. - double vpar_max_ion = 4.0*vti; // Maximum ion parallel velocity. - double mu_max_ion = (3.0/2.0)*0.5*mass_ion*pow(4.0*vti, 2.0)/(2.0*B0); // Maximum ion magnetic moment. + double vpar_max_elc = 4.0 * vte; // Maximum electron parallel velocity. + double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Maximum electron magnetic moment. + double vpar_max_ion = 4.0 * vti; // Maximum ion parallel velocity. + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Maximum ion magnetic moment. int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -198,14 +204,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -216,9 +223,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -226,8 +234,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -237,15 +244,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -257,8 +264,7 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Electron source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -266,8 +272,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -277,15 +284,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -296,9 +305,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -306,8 +316,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -317,15 +326,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -337,8 +346,7 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Ion source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -346,8 +354,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -357,15 +366,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -375,8 +384,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -386,8 +394,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -397,8 +404,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -409,33 +415,35 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -446,234 +454,220 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -35,7 +34,7 @@ struct sheath_ctx // Derived physical quantities (using non-normalized physical units). double R; // Radial coordinate (simple toroidal coordinates). double B0; // Reference magnetic field strength (Tesla). - + double log_lambda_elc; // Electron Coulomb logarithm. double log_lambda_ion; // Ion Coulomb logarithm. double nu_elc; // Electron collision frequency. @@ -72,14 +71,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -104,15 +103,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -132,20 +135,27 @@ create_ctx(void) int Nmu = 4; // Cell count (velocity space: magnetic moment direction). double Lx = 50.0 * rho_s; // Domain size (configuration space: x-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -197,14 +207,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -219,14 +230,14 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), floor_src) * n_src; + double src_density = + GKYL_MAX2(exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), floor_src) * n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -234,9 +245,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -244,8 +256,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -259,8 +270,7 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; // Electron isotropic temperature (left). - } - else { + } else { T = 0.5 * Te; // Electron isotropic temperature (right). } @@ -268,15 +278,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -291,10 +301,12 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), - floor_src) * n_src; // Electron source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), + floor_src + ) * + n_src; // Electron source total number density (left). + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -302,8 +314,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -316,8 +329,7 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Electron source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Electron source isotropic temperature (right). } @@ -325,15 +337,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -348,14 +362,14 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), floor_src) * n_src; + double src_density = + GKYL_MAX2(exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), floor_src) * n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -363,9 +377,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -373,8 +388,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -388,8 +402,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Ion isotropic temperature (right). } @@ -397,15 +410,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -420,10 +433,12 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), - floor_src) * n_src; // Ion source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), + floor_src + ) * + n_src; // Ion source total number density (left). + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -431,8 +446,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -445,8 +461,7 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Ion source isotropic temperature (right). } @@ -454,15 +469,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -472,8 +487,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -483,8 +497,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -494,8 +507,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -505,8 +517,9 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_ion_elc; } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -514,7 +527,7 @@ diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -529,12 +542,13 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). -// xp[0] = X; xp[1] = Y; xp[2] = Z; - xp[0] = x; xp[1] = y; xp[2] = z; + // xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = x; + xp[1] = y; + xp[2] = z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0]; @@ -542,15 +556,14 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -void -init_field(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void init_field(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -558,16 +571,17 @@ init_field(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double Lx = app->Lx; double Te0 = app->Te; - fout[0] = 1.4*(Te0/GKYL_ELEMENTARY_CHARGE); //*cos((M_PI/Lx)*x+M_PI); + fout[0] = 1.4 * (Te0 / GKYL_ELEMENTARY_CHARGE); //*cos((M_PI/Lx)*x+M_PI); } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -578,267 +592,258 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -35,7 +34,7 @@ struct sheath_ctx // Derived physical quantities (using non-normalized physical units). double R; // Radial coordinate (simple toroidal coordinates). double B0; // Reference magnetic field strength (Tesla). - + double log_lambda_elc; // Electron Coulomb logarithm. double log_lambda_ion; // Ion Coulomb logarithm. double nu_elc; // Electron collision frequency. @@ -72,14 +71,14 @@ struct sheath_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -104,13 +103,17 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -132,20 +135,27 @@ create_ctx(void) double Lx = 50.0 * rho_s; // Domain size (configuration space: x-direction). double Ly = 100.0 * rho_s; // Domain size (configuration space: y-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 0.50; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -197,14 +207,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -219,14 +230,17 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -234,9 +248,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -244,8 +259,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -259,8 +273,7 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; // Electron isotropic temperature (left). - } - else { + } else { T = 0.5 * Te; // Electron isotropic temperature (right). } @@ -268,15 +281,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -291,10 +304,12 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Electron source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Electron source total number density (left). + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -302,8 +317,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -316,8 +332,7 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Electron source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Electron source isotropic temperature (right). } @@ -325,15 +340,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -348,14 +365,17 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -363,9 +383,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -373,8 +394,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -388,8 +408,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Ion isotropic temperature (right). } @@ -397,15 +416,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -420,10 +439,12 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Ion source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Ion source total number density (left). + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -431,8 +452,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -445,8 +467,7 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Ion source isotropic temperature (right). } @@ -454,15 +475,16 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -477,12 +499,13 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). -// xp[0] = X; xp[1] = Y; xp[2] = Z; - xp[0] = x; xp[1] = y; xp[2] = z; + // xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = x; + xp[1] = y; + xp[2] = z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0]; @@ -490,20 +513,21 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -514,239 +538,228 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -80,14 +79,14 @@ struct sheath_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -103,7 +102,7 @@ create_ctx(void) double n0 = 1.0e17; // Reference number density (1 / m^3). double TD0 = 10.0 * GKYL_ELEMENTARY_CHARGE; - double nD0 = 1.0*n0; + double nD0 = 1.0 * n0; double B_axis = 0.5; // Magnetic field axis (simple toroidal coordinates). double R0 = 0.85; // Major radius (simple toroidal coordinates). @@ -122,20 +121,22 @@ create_ctx(void) double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Collision frequencies. - double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion,4) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_elc) * pow(Te,3.0/2.0)); - double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion,4) * n0 / - (12.0 * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_ion) * pow(Ti,3.0/2.0)); - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4) * n0 / + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); + double nu_ion = + nu_frac * log_lambda_ion * pow(charge_ion, 4) * n0 / + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. double omega_ci = fabs(charge_ion * B0 / mass_ion); // Ion cyclotron frequency. double rho_s = c_s / omega_ci; // Ion-sound gyroradius. - double vtD0 = sqrt(TD0/mass_ion); + double vtD0 = sqrt(TD0 / mass_ion); double k_perp = k_perp_rho_s / rho_s; // Perpendicular wavenumber (for Poisson solver). @@ -154,19 +155,26 @@ create_ctx(void) double Lx = 1.0; double Ly = 1.0; double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte,2) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti,2) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). - double vpar_max_D0 = 8.0*vtD0; + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_D0 = 8.0 * vtD0; double t_end = 6.0e-8; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -217,35 +225,38 @@ create_ctx(void) .mu_max_elc = mu_max_elc, .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, - .vpar_max_D0= vpar_max_D0, + .vpar_max_D0 = vpar_max_D0, .t_end = t_end, .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double n_src = app->n_src; fout[0] = n_src; } -void -evalSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set source parallel velocity. fout[0] = 0.0; } -void -evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -255,16 +266,16 @@ evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = T_src; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double n_peak = app->n_peak; fout[0] = n_peak; } -void -evalDensityInitD0(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInitD0( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -273,15 +284,13 @@ evalDensityInitD0(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = n0; } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -291,18 +300,14 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -eval_udrift(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_udrift(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - fout[0] = 0.0; + fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; } - - -void -evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -312,8 +317,7 @@ evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalTempD0Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempD0Init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -323,8 +327,7 @@ evalTempD0Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = TD0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -334,8 +337,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -345,8 +347,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -356,8 +357,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -368,33 +368,35 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -405,10 +407,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -72,14 +71,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -106,13 +105,17 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -132,20 +135,27 @@ create_ctx(void) int Nvpar = 6; // Cell count (velocity space: parallel velocity direction). int Nmu = 4; // Cell count (velocity space: magnetic moment direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -194,14 +204,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -212,9 +223,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -222,8 +234,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -233,15 +244,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -253,8 +264,7 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Electron source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -262,8 +272,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -273,15 +284,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -292,9 +305,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -302,8 +316,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -313,15 +326,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -333,8 +346,7 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Ion source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -342,8 +354,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -353,15 +366,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -371,8 +384,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -383,33 +395,35 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -420,10 +434,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -24,7 +23,7 @@ struct sheath_ctx double Te; // Electron temperature. double Ti; // Ion temperature. - double T0; + double T0; double n0; // Reference number density (1 / m^3). double B_axis; // Magnetic field axis (simple toroidal coordinates). @@ -71,14 +70,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -109,13 +108,15 @@ create_ctx(void) double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Collision frequencies. - double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion,4) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_elc) * pow(Te,3.0/2.0)); - double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion,4) * n0 / - (12.0 * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_ion) * pow(Ti,3.0/2.0)); - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4) * n0 / + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); + double nu_ion = + nu_frac * log_lambda_ion * pow(charge_ion, 4) * n0 / + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -135,18 +136,25 @@ create_ctx(void) int Nmu = 8; // Cell count (velocity space: magnetic moment direction). double Lx = 50.0 * rho_s; // Domain size (configuration space: x-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte,2) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti,2) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double t_end = 1.0e-7; // Final simulation time. int num_frames = 2; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -197,14 +205,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -219,9 +228,12 @@ evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; - } - else { + n = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; + } else { n = 1.0e-40 * n_src; } @@ -229,15 +241,17 @@ evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = n; } -void -evalSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set source parallel velocity. fout[0] = 0.0; } -void -evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -250,8 +264,7 @@ evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; - } - else { + } else { T = (3.0 / 8.0) * T_src; } @@ -259,8 +272,7 @@ evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = T; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -275,14 +287,17 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -291,8 +306,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (fabs(z) <= 0.25 * Lz) { n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); - } - else { + } else { n = 0.5 * n_peak; } @@ -300,34 +314,32 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalDensityNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityNeutInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; - double n = 0.1*app->n0; + double n = 0.1 * app->n0; // Set number density. fout[0] = n; } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalUdriftInit(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalUdriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - fout[0] = 0.0; + fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; } -void -evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -341,8 +353,7 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; - } - else { + } else { T = 0.5 * Te; } @@ -350,8 +361,7 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -365,8 +375,7 @@ evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; - } - else { + } else { T = 0.5 * Ti; } @@ -374,17 +383,16 @@ evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } - -void -evalTempNeutInit(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalTempNeutInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double T = app->T0; fout[0] = T; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -394,8 +402,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -405,8 +412,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -416,8 +422,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -428,7 +433,7 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -443,10 +448,12 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0]; @@ -454,20 +461,21 @@ void bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0 * R / x; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -478,10 +486,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality // Physical constants (using non-normalized physical units). @@ -68,21 +67,21 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. // Physical constants (using non-normalized physical units). double epsilon0 = GKYL_EPSILON0; // Permittivity of free space. double eV = GKYL_ELEMENTARY_CHARGE; // Elementary charge. - + double mass_elc = GKYL_ELECTRON_MASS; // Electron mass. double mass_ion = 2.014 * GKYL_PROTON_MASS; // Proton mass. double charge_elc = -eV; // Electron charge. @@ -107,13 +106,15 @@ create_ctx(void) double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Collision frequencies. - double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion,4) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_elc) * pow(Te,3.0/2.0)); - double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion,4) * n0 / - (12.0 * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_ion) * pow(Ti,3.0/2.0)); - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4) * n0 / + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); + double nu_ion = + nu_frac * log_lambda_ion * pow(charge_ion, 4) * n0 / + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -133,18 +134,25 @@ create_ctx(void) int Nmu = 4; // Cell count (velocity space: magnetic moment direction). double Lx = 50.0 * rho_s; // Domain size (configuration space: x-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte,2) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti,2) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -194,14 +202,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -216,9 +225,12 @@ evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; - } - else { + n = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; + } else { n = 1.0e-40 * n_src; } @@ -226,15 +238,17 @@ evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = n; } -void -evalSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set source parallel velocity. fout[0] = 0.0; } -void -evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -247,8 +261,7 @@ evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; - } - else { + } else { T = (3.0 / 8.0) * T_src; } @@ -256,8 +269,7 @@ evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = T; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -272,25 +284,24 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double Lz = app->Lz; -// double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + // double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; double src_density = GKYL_MAX2(1.0, floor_src) * n_src; double src_temp = 0.0; double n = 0; -// if (x < xmu_src + 3.0 * xsigma_src) { - src_temp = T_src; -// } -// else { -// src_temp = (3.0 / 8.0) * T_src; -// } + // if (x < xmu_src + 3.0 * xsigma_src) { + src_temp = T_src; + // } + // else { + // src_temp = (3.0 / 8.0) * T_src; + // } double c_s_src = sqrt((5.0 / 3.0) * src_temp / mass_ion); double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); - } - else { + } else { n = 0.5 * n_peak; } @@ -298,8 +309,9 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalDensityInitElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInitElc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -308,12 +320,13 @@ evalDensityInitElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI // Perturb the electron density to get a mode in the potential. double Lx = app->Lx; - double kx = 4.0 * 2.0*M_PI/Lx; - fout[0] *= 1.0+0.25*sin(kx*x); + double kx = 4.0 * 2.0 * M_PI / Lx; + fout[0] *= 1.0 + 0.25 * sin(kx * x); } -void -evalDensityInitIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInitIon( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -321,15 +334,13 @@ evalDensityInitIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI evalDensityInit(t, xn, fout, ctx); } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -343,8 +354,7 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; - } - else { + } else { T = 0.5 * Te; } @@ -352,8 +362,7 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -367,8 +376,7 @@ evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; - } - else { + } else { T = 0.5 * Ti; } @@ -376,8 +384,7 @@ evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -387,8 +394,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -398,8 +404,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -409,8 +414,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -421,7 +425,7 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -436,10 +440,12 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0]; @@ -447,20 +453,21 @@ void bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0 * R / x; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -471,10 +478,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. double epsilon0; // Permittivity of free space. @@ -80,14 +79,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -103,8 +102,8 @@ create_ctx(void) double n0 = 7.0e18; // Reference number density (1 / m^3). double mass_neut = mass_ion; // Neutral mass. - double gas_gamma = 5.0/3.0; // Adiabatic index. - double n0_neut = 1e-4*n0; // Reference neutral number density (1 / m^3). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + double n0_neut = 1e-4 * n0; // Reference neutral number density (1 / m^3). double T0_neut = Ti; // Reference neutral temperature. double rec_frac = 0.98; // Recycling coefficient. @@ -121,15 +120,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -149,20 +152,23 @@ create_ctx(void) int Nvpar = 6; // Number of cells in parallel velocity. int Nmu = 4; // Number of cells in mu. double Lz = 4.0; // Domain size along z. - double vpar_max_elc = 4.0*vte; // Maximum electron parallel velocity. - double mu_max_elc = (3.0/2.0)*0.5*mass_elc*pow(4.0*vte, 2.0)/(2.0*B0); // Maximum electron magnetic moment. - double vpar_max_ion = 4.0*vti; // Maximum ion parallel velocity. - double mu_max_ion = (3.0/2.0)*0.5*mass_ion*pow(4.0*vti, 2.0)/(2.0*B0); // Maximum ion magnetic moment. + double vpar_max_elc = 4.0 * vte; // Maximum electron parallel velocity. + double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Maximum electron magnetic moment. + double vpar_max_ion = 4.0 * vti; // Maximum ion parallel velocity. + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Maximum ion magnetic moment. int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -218,14 +224,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -236,9 +243,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -246,8 +254,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -257,15 +264,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -277,8 +284,7 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Electron source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -286,8 +292,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -297,15 +304,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -316,9 +325,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -326,8 +336,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -337,15 +346,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -357,8 +366,7 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Ion source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -366,8 +374,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -377,15 +386,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -395,8 +404,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -406,8 +414,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -417,8 +424,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -428,8 +434,9 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_ion_elc; } -void -eval_neut_mom_init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_neut_mom_init( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0]; @@ -448,11 +455,12 @@ eval_neut_mom_init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[3] = 0.0; // Total energy density. - fout[4] = n0_neut*T0_neut/(gas_gamma-1.0); + fout[4] = n0_neut * T0_neut / (gas_gamma - 1.0); } -void -eval_neut_density_init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_neut_density_init( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0]; @@ -462,8 +470,9 @@ eval_neut_density_init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE fout[0] = n0_neut; } -void -eval_neut_udrift_init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_neut_udrift_init( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0]; @@ -473,8 +482,9 @@ eval_neut_udrift_init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[2] = 0.0; } -void -eval_neut_temp_init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval_neut_temp_init( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double z = xn[0]; @@ -485,46 +495,50 @@ eval_neut_temp_init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -void -calc_integrated_diagnostics(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_app* app, - double t_curr, bool is_restart_IC, bool force_calc, double dt) +void calc_integrated_diagnostics( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_app *app, double t_curr, bool is_restart_IC, + bool force_calc, double dt +) { if (!is_restart_IC && (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_calc)) { gkyl_gyrokinetic_app_calc_field_energy(app, t_curr); gkyl_gyrokinetic_app_calc_integrated_mom(app, t_curr); - if ( !(dt < 0.0) ) + if (!(dt < 0.0)) { gkyl_gyrokinetic_app_save_dt(app, t_curr, dt); + } } } -void -write_data(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot_phase, - gkyl_gyrokinetic_app* app, double t_curr, bool is_restart_IC, bool force_write) +void write_data( + struct gkyl_tm_trigger *iot_conf, struct gkyl_tm_trigger *iot_phase, gkyl_gyrokinetic_app *app, + double t_curr, bool is_restart_IC, bool force_write +) { bool trig_now_conf = gkyl_tm_trigger_check_and_bump(iot_conf, t_curr); if (trig_now_conf || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_app_write_conf(app, t_curr, frame); if (!is_restart_IC) { @@ -536,19 +550,20 @@ write_data(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot_phase, bool trig_now_phase = gkyl_tm_trigger_check_and_bump(iot_phase, t_curr); if (trig_now_phase || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_app_write_phase(app, t_curr, frame); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -559,223 +574,210 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -35,7 +34,7 @@ struct sheath_ctx // Derived physical quantities (using non-normalized physical units). double R; // Radial coordinate (simple toroidal coordinates). double B0; // Reference magnetic field strength (Tesla). - + double log_lambda_elc; // Electron Coulomb logarithm. double log_lambda_ion; // Ion Coulomb logarithm. double nu_elc; // Electron collision frequency. @@ -77,14 +76,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -109,15 +108,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -131,22 +134,28 @@ create_ctx(void) int Nmu = 4; // Cell count (velocity space: magnetic moment direction). double Lx = 50.0 * rho_s; // Domain size (configuration space: x-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. // Source parameters. double n_src = 1.4690539 * 3.612270e23; // Source number density. - double T_src = Te/5.0; // Source temperature. + double T_src = Te / 5.0; // Source temperature. double xmu_src = R; // Source mean position (x-direction). double xsigma_src = 0.005; // Source standard deviation (x-direction). double floor_src = 0.1; // Minimum source intensity. double heating_power_elc = 453e3; // Electron heating power [W]. double heating_power_ion = 453e3; // Ion heating power [W]. - double nu_Q_ion = Lz/c_s; // Ion heating rate [1/s]. + double nu_Q_ion = Lz / c_s; // Ion heating rate [1/s]. double nu_Q_elc = nu_elc; // Electron heating rate [1/s]. double floor_Q = 1e-8; // Minimum heating amplitude. @@ -154,11 +163,12 @@ create_ctx(void) double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -215,14 +225,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -237,22 +248,25 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), floor_src) * n_src; + double src_density = + GKYL_MAX2(exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), floor_src) * n_src; double src_temp = 0.0; double n = 0; - if (x < xmu_src + 3.0 * xsigma_src) + if (x < xmu_src + 3.0 * xsigma_src) { src_temp = 10.0 * T_src; - else + } else { src_temp = (3.0 / 8.0) * 10.0 * T_src; + } double c_s_src = sqrt((5.0 / 3.0) * src_temp / mass_ion); double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -260,8 +274,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -275,8 +288,7 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; // Electron isotropic temperature (left). - } - else { + } else { T = 0.5 * Te; // Electron isotropic temperature (right). } @@ -284,15 +296,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -307,10 +319,12 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), - floor_src) * n_src; // Electron source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), + floor_src + ) * + n_src; // Electron source total number density (left). + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -318,8 +332,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -332,8 +347,7 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Electron source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Electron source isotropic temperature (right). } @@ -341,15 +355,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -364,22 +380,25 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), floor_src) * n_src; + double src_density = + GKYL_MAX2(exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), floor_src) * n_src; double src_temp = 0.0; double n = 0; - if (x < xmu_src + 3.0 * xsigma_src) + if (x < xmu_src + 3.0 * xsigma_src) { src_temp = 10.0 * T_src; - else + } else { src_temp = (3.0 / 8.0) * 10.0 * T_src; + } double c_s_src = sqrt((5.0 / 3.0) * src_temp / mass_ion); double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -387,8 +406,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -402,8 +420,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Ion isotropic temperature (right). } @@ -411,15 +428,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -434,10 +451,12 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), - floor_src) * n_src; // Ion source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), + floor_src + ) * + n_src; // Ion source total number density (left). + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -445,8 +464,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -459,8 +479,7 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Ion source isotropic temperature (right). } @@ -468,15 +487,17 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -heat_rate_func_ion(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void heat_rate_func_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -490,18 +511,17 @@ heat_rate_func_ion(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double S_Q = 0.0; if (fabs(z) < 0.25 * Lz) { - S_Q = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), - floor_Q); - } - else { + S_Q = GKYL_MAX2(exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), floor_Q); + } else { S_Q = 1.0e-40; } - fout[0] = S_Q*nu_Q_ion; + fout[0] = S_Q * nu_Q_ion; } -void -heat_temp_shape_func_ion(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void heat_temp_shape_func_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -514,18 +534,17 @@ heat_temp_shape_func_ion(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double s_T = 0.0; if (fabs(z) < 0.25 * Lz) { - s_T = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), - floor_Q); - } - else { + s_T = GKYL_MAX2(exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), floor_Q); + } else { s_T = 1.0e-40; } fout[0] = s_T; } -void -heat_rate_func_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void heat_rate_func_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -539,18 +558,17 @@ heat_rate_func_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double S_Q = 0.0; if (fabs(z) < 0.25 * Lz) { - S_Q = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), - floor_Q); - } - else { + S_Q = GKYL_MAX2(exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), floor_Q); + } else { S_Q = 1.0e-40; } - fout[0] = S_Q*nu_Q_elc; + fout[0] = S_Q * nu_Q_elc; } -void -heat_temp_shape_func_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void heat_temp_shape_func_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -563,18 +581,15 @@ heat_temp_shape_func_elc(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double s_T = 0.0; if (fabs(z) < 0.25 * Lz) { - s_T = GKYL_MAX2(exp(-pow(x - xmu_src,2.0) / (2.0 * pow(xsigma_src,2.0))), - floor_Q); - } - else { + s_T = GKYL_MAX2(exp(-pow(x - xmu_src, 2.0) / (2.0 * pow(xsigma_src, 2.0))), floor_Q); + } else { s_T = 1.0e-40; } fout[0] = s_T; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -584,8 +599,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -595,8 +609,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -606,8 +619,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -618,7 +630,7 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -633,12 +645,13 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). -// xp[0] = X; xp[1] = Y; xp[2] = Z; - xp[0] = x; xp[1] = y; xp[2] = z; + // xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = x; + xp[1] = y; + xp[2] = z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0]; @@ -646,15 +659,14 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -void -init_field(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void init_field(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -662,16 +674,17 @@ init_field(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double Lx = app->Lx; double Te0 = app->Te; - fout[0] = 1.4*(Te0/GKYL_ELEMENTARY_CHARGE); //*cos((M_PI/Lx)*x+M_PI); + fout[0] = 1.4 * (Te0 / GKYL_ELEMENTARY_CHARGE); //*cos((M_PI/Lx)*x+M_PI); } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -682,266 +695,257 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -74,14 +73,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -108,15 +107,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -136,20 +139,27 @@ create_ctx(void) int Nvpar = 6; // Cell count (velocity space: parallel velocity direction). int Nmu = 4; // Cell count (velocity space: magnetic moment direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -200,14 +210,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -218,9 +229,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -228,8 +240,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -239,15 +250,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -259,8 +270,7 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Electron source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -268,8 +278,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -279,15 +290,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -298,9 +311,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -308,8 +322,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -319,15 +332,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -339,8 +352,7 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Ion source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -348,8 +360,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -359,15 +372,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -377,8 +390,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -388,8 +400,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -399,8 +410,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -411,20 +421,21 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -432,7 +443,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct sheath_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -445,18 +456,18 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_elc * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_elc * (cvpar * cvpar); } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } static inline void -mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_ion(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct sheath_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -469,23 +480,24 @@ mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_ion * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_ion * (cvpar * cvpar); } mu = mu_max_ion * (cmu * cmu); // Set rescaled ion velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -496,10 +508,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -35,7 +34,7 @@ struct sheath_ctx // Derived physical quantities (using non-normalized physical units). double R; // Radial coordinate (simple toroidal coordinates). double B0; // Reference magnetic field strength (Tesla). - + double log_lambda_elc; // Electron Coulomb logarithm. double log_lambda_ion; // Ion Coulomb logarithm. double nu_elc; // Electron collision frequency. @@ -72,14 +71,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -104,15 +103,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -132,20 +135,27 @@ create_ctx(void) int Nmu = 4; // Cell count (velocity space: magnetic moment direction). double Lx = 50.0 * rho_s; // Domain size (configuration space: x-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -197,14 +207,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -219,14 +230,17 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -234,9 +248,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -244,8 +259,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -259,8 +273,7 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; // Electron isotropic temperature (left). - } - else { + } else { T = 0.5 * Te; // Electron isotropic temperature (right). } @@ -268,15 +281,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -291,10 +304,12 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Electron source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Electron source total number density (left). + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -302,8 +317,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -316,8 +332,7 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Electron source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Electron source isotropic temperature (right). } @@ -325,15 +340,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -348,14 +365,17 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -363,9 +383,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -373,8 +394,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -388,8 +408,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Ion isotropic temperature (right). } @@ -397,15 +416,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -420,10 +439,12 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Ion source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Ion source total number density (left). + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -431,8 +452,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -445,8 +467,7 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Ion source isotropic temperature (right). } @@ -454,15 +475,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -472,8 +493,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -483,8 +503,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -494,8 +513,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -506,7 +524,7 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -521,11 +539,12 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0]; @@ -533,7 +552,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -541,7 +560,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct sheath_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -554,18 +573,18 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_elc * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_elc * (cvpar * cvpar); } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } static inline void -mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_ion(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct sheath_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -578,23 +597,24 @@ mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_ion * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_ion * (cvpar * cvpar); } mu = mu_max_ion * (cmu * cmu); // Set rescaled ion velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -605,10 +625,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -35,7 +34,7 @@ struct sheath_ctx // Derived physical quantities (using non-normalized physical units). double R; // Radial coordinate (simple toroidal coordinates). double B0; // Reference magnetic field strength (Tesla). - + double log_lambda_elc; // Electron Coulomb logarithm. double log_lambda_ion; // Ion Coulomb logarithm. double nu_elc; // Electron collision frequency. @@ -74,14 +73,14 @@ struct sheath_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -106,15 +105,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -136,20 +139,27 @@ create_ctx(void) double Lx = 50.0 * rho_s; // Domain size (configuration space: x-direction). double Ly = 100.0 * rho_s; // Domain size (configuration space: y-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -203,14 +213,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -225,14 +236,17 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -240,9 +254,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -250,8 +265,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -265,8 +279,7 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; // Electron isotropic temperature (left). - } - else { + } else { T = 0.5 * Te; // Electron isotropic temperature (right). } @@ -274,15 +287,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -297,10 +310,12 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Electron source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Electron source total number density (left). + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -308,8 +323,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -322,8 +338,7 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Electron source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Electron source isotropic temperature (right). } @@ -331,15 +346,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -354,14 +371,17 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -369,9 +389,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -379,8 +400,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -394,8 +414,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Ion isotropic temperature (right). } @@ -403,15 +422,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -426,10 +445,12 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Ion source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Ion source total number density (left). + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -437,8 +458,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -451,8 +473,7 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Ion source isotropic temperature (right). } @@ -460,15 +481,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -478,8 +499,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -489,8 +509,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -500,8 +519,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -512,7 +530,7 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -527,11 +545,12 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0]; @@ -539,7 +558,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; @@ -547,7 +566,7 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout } static inline void -mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_elc(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct sheath_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -560,18 +579,18 @@ mapc2p_vel_elc(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_elc * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_elc * (cvpar * cvpar); } mu = mu_max_elc * (cmu * cmu); // Set rescaled electron velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } static inline void -mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT vp, void* ctx) +mapc2p_vel_ion(double t, const double *GKYL_RESTRICT vc, double *GKYL_RESTRICT vp, void *ctx) { struct sheath_ctx *app = ctx; double cvpar = vc[0], cmu = vc[1]; @@ -584,23 +603,24 @@ mapc2p_vel_ion(double t, const double* GKYL_RESTRICT vc, double* GKYL_RESTRICT v if (cvpar < 0.0) { vpar = -vpar_max_ion * (cvpar * cvpar); - } - else { + } else { vpar = vpar_max_ion * (cvpar * cvpar); } mu = mu_max_ion * (cmu * cmu); // Set rescaled ion velocity space coordinates (vpar, mu) from old velocity space coordinates (cvpar, cmu): - vp[0] = vpar; vp[1] = mu; + vp[0] = vpar; + vp[1] = mu; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -611,10 +631,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -74,14 +73,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -108,15 +107,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -136,20 +139,27 @@ create_ctx(void) int Nvpar = 6; // Cell count (velocity space: parallel velocity direction). int Nmu = 4; // Cell count (velocity space: magnetic moment direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -200,14 +210,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -218,9 +229,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -228,8 +240,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -239,15 +250,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -259,8 +270,7 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Electron source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -268,8 +278,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -279,15 +290,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -298,9 +311,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n = 0.0; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -308,8 +322,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -319,15 +332,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -339,8 +352,7 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(z) < 0.25 * Lz) { n = n_src; // Ion source total number density (left). - } - else { + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -348,8 +360,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -359,15 +372,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T_src; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -377,8 +390,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -388,8 +400,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -399,8 +410,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -411,54 +421,57 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0; } -static inline void -nonuniform_position_map_x(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_x( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { // Set rescaled configuration space coordinate X, from old configuration space coordinate x. xp[0] = zc[0]; } -static inline void -nonuniform_position_map_y(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_y( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { // Set rescaled configuration space coordinate Y, from old configuration space coordinate y. xp[0] = zc[0]; } -static inline void -nonuniform_position_map_z(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_z( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { struct sheath_ctx *app = ctx; double z = zc[0]; - double Lz = app -> Lz; + double Lz = app->Lz; double Z = 0.0; if (fabs(z) < Lz * 0.25) { - Z = - ((z - (0.25 * Lz)) * (z - (0.25 * Lz)) / (0.5 * Lz)) + (0.25 * Lz); - } - else { + Z = -((z - (0.25 * Lz)) * (z - (0.25 * Lz)) / (0.5 * Lz)) + (0.25 * Lz); + } else { Z = z; } @@ -466,13 +479,14 @@ nonuniform_position_map_z(double t, const double* GKYL_RESTRICT zc, double* GKYL xp[0] = Z; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -483,10 +497,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -35,7 +34,7 @@ struct sheath_ctx // Derived physical quantities (using non-normalized physical units). double R; // Radial coordinate (simple toroidal coordinates). double B0; // Reference magnetic field strength (Tesla). - + double log_lambda_elc; // Electron Coulomb logarithm. double log_lambda_ion; // Ion Coulomb logarithm. double nu_elc; // Electron collision frequency. @@ -72,14 +71,14 @@ struct sheath_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -104,15 +103,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -132,20 +135,27 @@ create_ctx(void) int Nmu = 4; // Cell count (velocity space: magnetic moment direction). double Lx = 50.0 * rho_s; // Domain size (configuration space: x-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -197,14 +207,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -219,14 +230,17 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -234,9 +248,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -244,8 +259,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -259,8 +273,7 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; // Electron isotropic temperature (left). - } - else { + } else { T = 0.5 * Te; // Electron isotropic temperature (right). } @@ -268,15 +281,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -291,10 +304,12 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Electron source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Electron source total number density (left). + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -302,8 +317,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -316,8 +332,7 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Electron source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Electron source isotropic temperature (right). } @@ -325,15 +340,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -348,14 +365,17 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -363,9 +383,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -373,8 +394,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -388,8 +408,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Ion isotropic temperature (right). } @@ -397,15 +416,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -420,10 +439,12 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Ion source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Ion source total number density (left). + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -431,8 +452,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -445,8 +467,7 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Ion source isotropic temperature (right). } @@ -454,15 +475,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -472,8 +493,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -483,8 +503,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -494,8 +513,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -506,7 +524,7 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -521,11 +539,12 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0]; @@ -533,41 +552,43 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0 * R / x; } -static inline void -nonuniform_position_map_x(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_x( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { // Set rescaled configuration space coordinate X, from old configuration space coordinate x. xp[0] = zc[0]; } -static inline void -nonuniform_position_map_y(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_y( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { // Set rescaled configuration space coordinate Y, from old configuration space coordinate y. xp[0] = zc[0]; } -static inline void -nonuniform_position_map_z(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_z( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { struct sheath_ctx *app = ctx; double z = zc[0]; - double Lz = app -> Lz; + double Lz = app->Lz; double Z = 0.0; if (fabs(z) < Lz * 0.25) { - Z = - ((z - (0.25 * Lz)) * (z - (0.25 * Lz)) / (0.5 * Lz)) + (0.25 * Lz); - } - else { + Z = -((z - (0.25 * Lz)) * (z - (0.25 * Lz)) / (0.5 * Lz)) + (0.25 * Lz); + } else { Z = z; } @@ -575,13 +596,14 @@ nonuniform_position_map_z(double t, const double* GKYL_RESTRICT zc, double* GKYL xp[0] = Z; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -592,10 +614,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -35,7 +34,7 @@ struct sheath_ctx // Derived physical quantities (using non-normalized physical units). double R; // Radial coordinate (simple toroidal coordinates). double B0; // Reference magnetic field strength (Tesla). - + double log_lambda_elc; // Electron Coulomb logarithm. double log_lambda_ion; // Ion Coulomb logarithm. double nu_elc; // Electron collision frequency. @@ -74,14 +73,14 @@ struct sheath_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -106,15 +105,19 @@ create_ctx(void) double R = R0 + a0; // Radial coordinate (simple toroidal coordinates). double B0 = B_axis * (R0 / R); // Reference magnetic field strength (Tesla). - double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. - double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. + double log_lambda_elc = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Te / charge_ion); // Electron Coulomb logarithm. + double log_lambda_ion = + 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Ion Coulomb logarithm. double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4.0) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * pow(Te, 3.0 / 2.0)); // Electron collision frequency. + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); // Electron collision frequency. double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion, 4.0) * n0 / - (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); // Ion collision frequency. - double nu_elc_ion = nu_elc*sqrt(2.0); - double nu_ion_elc = nu_elc_ion*(mass_elc/mass_ion); - + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2.0) * sqrt(mass_ion) * + pow(Ti, 3.0 / 2.0)); // Ion collision frequency. + double nu_elc_ion = nu_elc * sqrt(2.0); + double nu_ion_elc = nu_elc_ion * (mass_elc / mass_ion); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -136,20 +139,27 @@ create_ctx(void) double Lx = 50.0 * rho_s; // Domain size (configuration space: x-direction). double Ly = 100.0 * rho_s; // Domain size (configuration space: y-direction). double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2.0) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2.0) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). int poly_order = 1; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. double t_end = 6.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -203,14 +213,15 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -225,14 +236,17 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -240,9 +254,10 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Electron total number density (left). - } - else { + n = 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz))) + ); // Electron total number density (left). + } else { n = 0.5 * n_peak; // Electron total number density (right). } @@ -250,8 +265,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -265,8 +279,7 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Te; // Electron isotropic temperature (left). - } - else { + } else { T = 0.5 * Te; // Electron isotropic temperature (right). } @@ -274,15 +287,15 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalElcUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electron parallel velocity. fout[0] = 0.0; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -297,10 +310,12 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Electron source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Electron source total number density (left). + } else { n = 1.0e-40 * n_src; // Electron source total number density (right). } @@ -308,8 +323,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -322,8 +338,7 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Electron source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Electron source isotropic temperature (right). } @@ -331,15 +346,17 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalElcSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set electron source parallel velocity. fout[0] = 0.0; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -354,14 +371,17 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double Lz = app->Lz; - double src_density = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src) * n_src; + double src_density = + GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), floor_src + ) * + n_src; double src_temp = 0.0; double n = 0; if (x < xmu_src + 3.0 * xsigma_src) { src_temp = T_src; - } - else { + } else { src_temp = (3.0 / 8.0) * T_src; } @@ -369,9 +389,10 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double n_peak = 4.0 * sqrt(5.0) / 3.0 / c_s_src * (0.125 * Lz) * src_density; if (fabs(z) <= 0.25 * Lz) { - n = 0.5 * n_peak * (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). - } - else { + n = + 0.5 * n_peak * + (1.0 + sqrt(1.0 - (z / (0.25 * Lz)) * (z / (0.25 * Lz)))); // Ion total number density (left). + } else { n = 0.5 * n_peak; // Ion total number density (right). } @@ -379,8 +400,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -394,8 +414,7 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < xmu_src + 3.0 * xsigma_src) { T = (5.0 / 4.0) * Ti; // Ion isotropic temperature (left). - } - else { + } else { T = 0.5 * Ti; // Ion isotropic temperature (right). } @@ -403,15 +422,15 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = T; } -void -evalIonUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set ion parallel velocity. fout[0] = 0.0; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], z = xn[2]; @@ -426,10 +445,12 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double n = 0.0; if (fabs(z) < 0.25 * Lz) { - n = GKYL_MAX2(exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), - floor_src) * n_src; // Ion source total number density (left). - } - else { + n = GKYL_MAX2( + exp(-((x - xmu_src) * (x - xmu_src)) / ((2.0 * xsigma_src) * (2.0 * xsigma_src))), + floor_src + ) * + n_src; // Ion source total number density (left). + } else { n = 1.0e-40 * n_src; // Ion source total number density (right). } @@ -437,8 +458,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -451,8 +473,7 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES if (x < xmu_src + 3.0 * xsigma_src) { T = T_src; // Ion source isotropic temperature (left). - } - else { + } else { T = (3.0 / 8.0) * T_src; // Ion source isotropic temperature (right). } @@ -460,15 +481,15 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = T; } -void -evalIonSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set ion source parallel velocity. fout[0] = 0.0; } -void -evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -478,8 +499,7 @@ evalNuElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -489,8 +509,7 @@ evalNuIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -500,8 +519,7 @@ evalNuElcIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_elc_ion; } -void -evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -511,9 +529,8 @@ evalNuIonElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = nu_ion_elc; } - static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; @@ -528,11 +545,12 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* double Z = y; // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = X; xp[1] = Y; xp[2] = Z; + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = zc[0]; @@ -540,41 +558,43 @@ bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout double B0 = app->B0; double R = app->R; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = B0 * R / x; } -static inline void -nonuniform_position_map_x(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_x( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { // Set rescaled configuration space coordinate X, from old configuration space coordinate x. xp[0] = zc[0]; } -static inline void -nonuniform_position_map_y(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_y( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { // Set rescaled configuration space coordinate Y, from old configuration space coordinate y. xp[0] = zc[0]; } -static inline void -nonuniform_position_map_z(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +static inline void nonuniform_position_map_z( + double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx +) { struct sheath_ctx *app = ctx; double z = zc[0]; - double Lz = app -> Lz; + double Lz = app->Lz; double Z = 0.0; if (fabs(z) < Lz * 0.25) { - Z = - ((z - (0.25 * Lz)) * (z - (0.25 * Lz)) / (0.5 * Lz)) + (0.25 * Lz); - } - else { + Z = -((z - (0.25 * Lz)) * (z - (0.25 * Lz)) / (0.5 * Lz)) + (0.25 * Lz); + } else { Z = z; } @@ -582,13 +602,14 @@ nonuniform_position_map_z(double t, const double* GKYL_RESTRICT zc, double* GKYL xp[0] = Z; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -599,10 +620,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct slab_ctx -{ +struct slab_ctx { int cdim, vdim; // Dimensionality // Physical constants (using non-normalized physical units). @@ -63,14 +62,14 @@ struct slab_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct slab_ctx -create_ctx(void) +struct slab_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -81,15 +80,15 @@ create_ctx(void) double mass_ion = 2.014 * GKYL_PROTON_MASS; // Proton mass. double charge_ion = GKYL_ELEMENTARY_CHARGE; // Proton charge. - double Te = 100.0*5.0/8.0 * GKYL_ELEMENTARY_CHARGE; // Electron temperature. - double Ti = 150.0*5.0/8.0 * GKYL_ELEMENTARY_CHARGE; // Ion temperature. + double Te = 100.0 * 5.0 / 8.0 * GKYL_ELEMENTARY_CHARGE; // Electron temperature. + double Ti = 150.0 * 5.0 / 8.0 * GKYL_ELEMENTARY_CHARGE; // Ion temperature. double n0 = 3.0e19; // Reference number density (1 / m^3). double B0 = 2.51; // Magnetic field axis (simple toroidal coordinates). double R_outer = 5.6; //double cx = 0.00159/2.16; - double cx = 0.00159/2.16 * 6.0; - double cz = 7.22285*3.0; + double cx = 0.00159 / 2.16 * 6.0; + double cz = 7.22285 * 3.0; double x_center = 0.03; double nu_frac = 0.25; // Collision frequency fraction. @@ -98,11 +97,13 @@ create_ctx(void) double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Collision frequencies. - double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion,4) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_elc) * pow(Te,3.0/2.0)); - double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion,4) * n0 / - (12.0 * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_ion) * pow(Ti,3.0/2.0)); - + double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4) * n0 / + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); + double nu_ion = + nu_frac * log_lambda_ion * pow(charge_ion, 4) * n0 / + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. @@ -111,7 +112,7 @@ create_ctx(void) double n_src = 6.1e23; // Source number density. //double T_src = 200*5.0/2.0*0.3*1.6251586572438161*1.17*5.0/8.0 * GKYL_ELEMENTARY_CHARGE; // Source Temperature - double T_src = 285.0*5.0/8.0 * GKYL_ELEMENTARY_CHARGE; // Source Temperature + double T_src = 285.0 * 5.0 / 8.0 * GKYL_ELEMENTARY_CHARGE; // Source Temperature // Simulation parameters. int Nx = 8; // Cell count (configuration space: x-direction). @@ -120,18 +121,25 @@ create_ctx(void) int Nmu = 6; // Cell count (velocity space: magnetic moment direction). double Lx = 0.06; // Domain size (configuration space: x-direction). double Lz = 120; // Domain size (configuration space: z-direction). - double vpar_max_elc = 6.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte,2) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti,2) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_elc = + 6.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 6.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). double t_end = 5.0e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct slab_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -176,94 +184,96 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct slab_ctx *app = ctx; double x = xn[0], z = xn[1]; double n_src = app->n_src; - double cx= app->cx; - double cz= app->cz; - double x_center= app->x_center; + double cx = app->cx; + double cz = app->cz; + double x_center = app->x_center; double Lz = app->Lz; double n = 0.0; - n = exp( -(x-x_center)*(x-x_center)/2/cx/cx ) * exp( -z*z/2/cz/cz ); - if (n < 1e-5) + n = exp(-(x - x_center) * (x - x_center) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n < 1e-5) { n = 1e-5; - n = n*n_src; + } + n = n * n_src; fout[0] = n; } -void -evalSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set source parallel velocity. fout[0] = 0.0; } -void -evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct slab_ctx *app = ctx; double T_src = app->T_src; fout[0] = T_src; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct slab_ctx *app = ctx; double x = xn[0], z = xn[1]; - double n0= app->n0; - double cx= app->cx; - double cz= app->cz; - double x_center= app->x_center; + double n0 = app->n0; + double cx = app->cx; + double cz = app->cz; + double x_center = app->x_center; double Lz = app->Lz; double n = 0.0; - n = exp( -(x-x_center)*(x-x_center)/2/cx/cx ) * exp( -z*z/2/cz/cz ); - if (n < 1e-5) + n = exp(-(x - x_center) * (x - x_center) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n < 1e-5) { n = 1e-5; - n = n*n0; + } + n = n * n0; fout[0] = n; } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct slab_ctx *app = ctx; double Te = app->Te; fout[0] = Te; } -void -evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct slab_ctx *app = ctx; double Ti = app->Ti; fout[0] = Ti; } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -271,31 +281,34 @@ diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { struct slab_ctx *app = ctx; double x = zc[0], y = zc[1], z = zc[2]; - xp[0] = x; xp[1] = y; xp[2] = z; + xp[0] = x; + xp[1] = y; + xp[2] = z; } -void bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct slab_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -306,10 +319,12 @@ main(int argc, char **argv) struct slab_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dlambda_source; double x_source = app->x_source; double Lz = app->Lz; - double Ls = Lz/4; + double Ls = Lz / 4; double floor = 0.1; - // find source density at z = 0 double source_density = 0; double source_floor = 1e-10; - if (x > x_source) - source_floor = 1e-2; // higher floor to left of source peak - source_density = fmax(exp(-(x-x_source)*(x-x_source)/((2*lambda_source)*(2*lambda_source))), source_floor); + if (x > x_source) { + source_floor = 1e-2; // higher floor to left of source peak + } + source_density = fmax( + exp(-(x - x_source) * (x - x_source) / ((2 * lambda_source) * (2 * lambda_source))), + source_floor + ); // find source temp at z = 0 double source_temp = 0; double eV = GKYL_ELEMENTARY_CHARGE; - if (x > x_source - 3*lambda_source) - source_temp = 80*eV; - else - source_temp = 30*eV; + if (x > x_source - 3 * lambda_source) { + source_temp = 80 * eV; + } else { + source_temp = 30 * eV; + } // now compute initial desity - double effective_source = 3.800419e+23*fmax(source_density, floor); - double c_ss = sqrt(5.0/3.0*source_temp/app->massIon); - double n_peak = 4*sqrt(5)/3/c_ss*Ls*effective_source/2; + double effective_source = 3.800419e+23 * fmax(source_density, floor); + double c_ss = sqrt(5.0 / 3.0 * source_temp / app->massIon); + double n_peak = 4 * sqrt(5) / 3 / c_ss * Ls * effective_source / 2; double perturb = 0; - if (fabs(z) <= Ls) - fout[0] = n_peak*(1+sqrt(1-(z/Ls)*(z/Ls)))/2*(1+perturb); - else - fout[0] = n_peak/2*(1+perturb); + if (fabs(z) <= Ls) { + fout[0] = n_peak * (1 + sqrt(1 - (z / Ls) * (z / Ls))) / 2 * (1 + perturb); + } else { + fout[0] = n_peak / 2 * (1 + perturb); + } } -void -eval_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void -eval_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_solovev_ctx *app = ctx; double x = xn[0], y = xn[1], z = xn[2]; double lambda_source = app->lambda_source; double x_source = app->x_source; double eV = GKYL_ELEMENTARY_CHARGE; - if (x > x_source - 3*lambda_source) - fout[0] = 50*eV; - else - fout[0] = 20*eV; + if (x > x_source - 3 * lambda_source) { + fout[0] = 50 * eV; + } else { + fout[0] = 20 * eV; + } } -void -eval_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_solovev_ctx *app = ctx; double x = xn[0], y = xn[1], z = xn[2]; double lambda_source = app->lambda_source; double x_source = app->x_source; double eV = GKYL_ELEMENTARY_CHARGE; - if (x > x_source - 3*lambda_source) - fout[0] = 50*eV; - else - fout[0] = 20*eV; + if (x > x_source - 3 * lambda_source) { + fout[0] = 50 * eV; + } else { + fout[0] = 20 * eV; + } } -void -eval_density_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_density_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_solovev_ctx *app = ctx; double x = xn[0], y = xn[1], z = xn[2]; @@ -131,128 +136,135 @@ eval_density_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_REST double x_source = app->x_source; double Lz = app->Lz; double source_floor = 1e-10; - if (x > x_source) - source_floor = 1e-2; // higher floor to left of source peak - if (fabs(z) < Lz/4) - fout[0] = 3.800419e+23*fmax(exp(-(x-x_source)*(x-x_source)/((2*lambda_source)*(2*lambda_source))), source_floor); - else - fout[0] = 3.800419e+23*1e-40; + if (x > x_source) { + source_floor = 1e-2; // higher floor to left of source peak + } + if (fabs(z) < Lz / 4) { + fout[0] = 3.800419e+23 * + fmax( + exp(-(x - x_source) * (x - x_source) / ((2 * lambda_source) * (2 * lambda_source))), + source_floor + ); + } else { + fout[0] = 3.800419e+23 * 1e-40; + } } -void -eval_upar_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_solovev_ctx *app = ctx; double x = xn[0], y = xn[1], z = xn[2]; double lambda_source = app->lambda_source; double x_source = app->x_source; double eV = GKYL_ELEMENTARY_CHARGE; - if (x > x_source - 3*lambda_source) - fout[0] = 80*eV; - else - fout[0] = 30*eV; + if (x > x_source - 3 * lambda_source) { + fout[0] = 80 * eV; + } else { + fout[0] = 30 * eV; + } } -void -eval_temp_ion_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_solovev_ctx *app = ctx; double x = xn[0], y = xn[1], z = xn[2]; double lambda_source = app->lambda_source; double x_source = app->x_source; double eV = GKYL_ELEMENTARY_CHARGE; - if (x > x_source - 3*lambda_source) - fout[0] = 80*eV; - else - fout[0] = 30*eV; + if (x > x_source - 3 * lambda_source) { + fout[0] = 80 * eV; + } else { + fout[0] = 30 * eV; + } } -void -evalNuElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_solovev_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_solovev_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuElcIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_solovev_ctx *app = ctx; fout[0] = app->nuElcIon; } -void -evalNuIonElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_solovev_ctx *app = ctx; fout[0] = app->nuIonElc; } -struct gk_solovev_ctx -create_ctx(void) +struct gk_solovev_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge - double Te = 40.0*eV; - double Ti = 40.0*eV; + double Te = 40.0 * eV; + double Ti = 40.0 * eV; double B0 = 0.55; // Magnetic field magnitude in Tesla double n0 = 7.0e18; // Particle density in 1/m^3 // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); - double c_s = sqrt(Te/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; - + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); + double c_s = sqrt(Te / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; // Collision parameters. double nuFrac = 0.1; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nuFrac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nuFrac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te))); - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nuIon = nuFrac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mi)*(Ti*sqrt(Ti))); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nuIon = nuFrac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mi) * (Ti * sqrt(Ti))); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); // Simulation box size (psi, alpha, theta). double q0 = 2.0; double r0 = 0.40705706492831; double Lx = 0.02; - double Ly = 50 * rho_s * q0/r0 ; // should be 0.107890816895 - double Lz = (M_PI-1e-14)*2.0 ; // Domain size (configuration space: z-direction). + double Ly = 50 * rho_s * q0 / r0; // should be 0.107890816895 + double Lz = (M_PI - 1e-14) * 2.0; // Domain size (configuration space: z-direction). // Source parameters. double x_source = -0.07; - double lambda_source = 0.03*Lx; + double lambda_source = 0.03 * Lx; // Velocity Grid - double vpar_max_elc = 4.0*vtElc; - double mu_max_elc = 0.75*me*(4.0*vtElc)*(4.0*vtElc)/(2.0*B0); + double vpar_max_elc = 4.0 * vtElc; + double mu_max_elc = 0.75 * me * (4.0 * vtElc) * (4.0 * vtElc) / (2.0 * B0); - double vpar_max_ion = 4.0*vtIon; - double mu_max_ion = 0.75*mi*(4.0*vtIon)*(4.0*vtIon)/(2.0*B0); + double vpar_max_ion = 4.0 * vtIon; + double mu_max_ion = 0.75 * mi * (4.0 * vtIon) * (4.0 * vtIon) / (2.0 * B0); int Nx = 4; // Number of cells in x. int Ny = 2; // Number of cells in y. @@ -260,61 +272,63 @@ create_ctx(void) int Nvpar = 6; // Number of cells in vpar. int Nmu = 4; // Number of cells in mu. - double t_end = 4.0e-7; + double t_end = 4.0e-7; double num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_solovev_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, - .Te = Te, - .Ti = Ti, - .c_s = c_s, - .nuElc = nuElc, - .nuIon = nuIon, - .nuElcIon = nuElcIon, - .nuIonElc = nuIonElc, - .B0 = B0, - .n0 = n0, - .Lx = Lx, - .Ly = Ly, - .Lz = Lz, + .Te = Te, + .Ti = Ti, + .c_s = c_s, + .nuElc = nuElc, + .nuIon = nuIon, + .nuElcIon = nuElcIon, + .nuIonElc = nuIonElc, + .B0 = B0, + .n0 = n0, + .Lx = Lx, + .Ly = Ly, + .Lz = Lz, .lambda_source = lambda_source, .x_source = x_source, - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .Nx = Nx, .Ny = Ny, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Ny, Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -325,255 +339,244 @@ main(int argc, char **argv) struct gk_solovev_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d -struct sheath_ctx -{ +struct sheath_ctx { int cdim, vdim; // Dimensionality. // Physical constants (using non-normalized physical units). @@ -78,14 +77,14 @@ struct sheath_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -101,7 +100,7 @@ create_ctx(void) double n0 = 1.0e17; // Reference number density (1 / m^3). double TD0 = 10.0 * GKYL_ELEMENTARY_CHARGE; - double nD0 = 1.0*n0; + double nD0 = 1.0 * n0; double B_axis = 0.5; // Magnetic field axis (simple toroidal coordinates). double R0 = 0.85; // Major radius (simple toroidal coordinates). @@ -120,18 +119,20 @@ create_ctx(void) double log_lambda_ion = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(Ti / charge_ion); // Collision frequencies. - double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion,4) * n0 / - (6.0 * sqrt(2.0) * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_elc) * pow(Te,3.0/2.0)); - double nu_ion = nu_frac * log_lambda_ion * pow(charge_ion,4) * n0 / - (12.0 * pow(M_PI,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_ion) * pow(Ti,3.0/2.0)); - + double nu_elc = nu_frac * log_lambda_elc * pow(charge_ion, 4) * n0 / + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_elc) * + pow(Te, 3.0 / 2.0)); + double nu_ion = + nu_frac * log_lambda_ion * pow(charge_ion, 4) * n0 / + (12.0 * pow(M_PI, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_ion) * pow(Ti, 3.0 / 2.0)); + double c_s = sqrt(Te / mass_ion); // Sound speed. double vte = sqrt(Te / mass_elc); // Electron thermal velocity. double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. double omega_ci = fabs(charge_ion * B0 / mass_ion); // Ion cyclotron frequency. double rho_s = c_s / omega_ci; // Ion-sound gyroradius. - double vtD0 = sqrt(TD0/mass_ion); + double vtD0 = sqrt(TD0 / mass_ion); double k_perp = k_perp_rho_s / rho_s; // Perpendicular wavenumber (for Poisson solver). @@ -150,19 +151,26 @@ create_ctx(void) double Lx = 1.0; double Ly = 1.0; double Lz = 4.0; // Domain size (configuration space: z-direction). - double vpar_max_elc = 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). - double mu_max_elc = (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte,2) / (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). - double vpar_max_ion = 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). - double mu_max_ion = (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti,2) / (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). - double vpar_max_D0 = 8.0*vtD0; + double vpar_max_elc = + 4.0 * vte; // Domain boundary (electron velocity space: parallel velocity direction). + double mu_max_elc = + (3.0 / 2.0) * 0.5 * mass_elc * pow(4.0 * vte, 2) / + (2.0 * B0); // Domain boundary (electron velocity space: magnetic moment direction). + double vpar_max_ion = + 4.0 * vti; // Domain boundary (ion velocity space: parallel velocity direction). + double mu_max_ion = + (3.0 / 2.0) * 0.5 * mass_ion * pow(4.0 * vti, 2) / + (2.0 * B0); // Domain boundary (ion velocity space: magnetic moment direction). + double vpar_max_D0 = 8.0 * vtD0; double t_end = 1.20e-6; // Final simulation time. int num_frames = 1; // Number of output frames. - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct sheath_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -211,35 +219,38 @@ create_ctx(void) .mu_max_elc = mu_max_elc, .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, - .vpar_max_D0= vpar_max_D0, + .vpar_max_D0 = vpar_max_D0, .t_end = t_end, .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double n_src = app->n_src; fout[0] = n_src; } -void -evalSourceUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceUparInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { // Set source parallel velocity. fout[0] = 0.0; } -void -evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -249,16 +260,16 @@ evalSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = T_src; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double n_peak = app->n_peak; fout[0] = n_peak; } -void -evalDensityInitD0(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInitD0( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double z = xn[0]; @@ -267,15 +278,13 @@ evalDensityInitD0(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = n0; } -void -evalUparInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalUparInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set parallel velocity. fout[0] = 0.0; } -void -evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -285,18 +294,14 @@ evalTempElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -eval_udrift(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_udrift(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - fout[0] = 0.0; + fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; } - - -void -evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -306,8 +311,7 @@ evalTempIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalTempD0Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempD0Init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -317,8 +321,7 @@ evalTempD0Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = TD0; } -void -evalNuElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -328,8 +331,7 @@ evalNuElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo fout[0] = nu_elc; } -void -evalNuIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNuIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -340,33 +342,35 @@ evalNuIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { // Set physical coordinates (X, Y, Z) from computational coordinates (x, y, z). - xp[0] = zc[0]; xp[1] = zc[1]; xp[2] = zc[2]; + xp[0] = zc[0]; + xp[1] = zc[1]; + xp[2] = zc[2]; } -void -bfield_func(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double B0 = app->B0; - // zc are computational coords. + // zc are computational coords. // Set Cartesian components of magnetic field. fout[0] = 0.0; fout[1] = 0.0; fout[2] = app->B0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -377,10 +381,12 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcx; double cz = app->cz; double xcenter = 1.2014; - double n = n0*exp(-(x-xcenter)*(x-xcenter)/2/cx/cx) * exp(-z*z/2/cz/cz); - if (n/n0 < 1e-1) - n = n0*1e-1; + double n = n0 * exp(-(x - xcenter) * (x - xcenter) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n / n0 < 1e-1) { + n = n0 * 1e-1; + } fout[0] = n; } -void unit_density(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void unit_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; - fout[0] = 1.0; + fout[0] = 1.0; } -void -eval_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void -evalDensityInitD0(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInitD0( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; double z = xn[0]; @@ -96,8 +97,7 @@ evalDensityInitD0(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = n0; } -void -evalTempD0Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempD0Init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; @@ -107,35 +107,30 @@ evalTempD0Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = TD0; } -void -eval_udrift(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_udrift(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - fout[0] = 0.0; + fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; } - - -void -eval_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double T = app->Te; fout[0] = T; } -void -eval_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double T = app->Ti; fout[0] = T; } - -void -eval_density_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_density_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -143,20 +138,24 @@ eval_density_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_REST double cx = app->cx; double cz = app->cz; double xcenter = 1.2014; - double n = nsource*exp(-(x-xcenter)*(x-xcenter)/2/cx/cx) * exp(-z*z/2/cz/cz); - if (n/nsource < 1e-5) - n = nsource*1e-5; + double n = + nsource * exp(-(x - xcenter) * (x - xcenter) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n / nsource < 1e-5) { + n = nsource * 1e-5; + } fout[0] = n; } -void -eval_upar_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; double n0 = app->n0; @@ -164,8 +163,9 @@ eval_temp_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = T; } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -176,17 +176,16 @@ double plasma_frequency(double n, double m) { double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - return sqrt(n*eV*eV/m/eps0); + return sqrt(n * eV * eV / m / eps0); } -struct gk_step_ctx -create_ctx(void) +struct gk_step_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge @@ -195,19 +194,19 @@ create_ctx(void) double Te = 25.0 * GKYL_ELEMENTARY_CHARGE; // Electron temperature. double Ti = 25.0 * GKYL_ELEMENTARY_CHARGE; // Ion temperature. double n0 = 1.0e17; // Reference number density (1 / m^3). - + double TD0 = 10.0 * GKYL_ELEMENTARY_CHARGE; - double nD0 = 1.0*n0; + double nD0 = 1.0 * n0; // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); - double vtD0 = sqrt(TD0/mi); + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); + double vtD0 = sqrt(TD0 / mi); // Source parameters. double nsource = 2.870523e21; // Source number density. - double T_source = 2.0*Te; - double cx = 0.0065612*9; + double T_source = 2.0 * Te; + double cx = 0.0065612 * 9; double cz = 0.4916200; // Recycling parameters. @@ -215,25 +214,28 @@ create_ctx(void) // Collision parameters. double nuFrac = 0.25; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nuFrac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); // collision freq + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nuFrac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te)) + ); // collision freq - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nuIon = nuFrac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mi)*(Ti*sqrt(Ti))); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nuIon = nuFrac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mi) * (Ti * sqrt(Ti))); // Simulation box size (m). double lower_x = 0.934; double upper_x = 1.4688; double Lx = upper_x - lower_x; - double Lz = (M_PI-1e-14)*2.0; + double Lz = (M_PI - 1e-14) * 2.0; - double vpar_max_elc = 4.0*vtElc; - double mu_max_elc = 12*me*vtElc*vtElc/(2.0*B0); + double vpar_max_elc = 4.0 * vtElc; + double mu_max_elc = 12 * me * vtElc * vtElc / (2.0 * B0); - double vpar_max_ion = 4.0*vtIon; - double mu_max_ion = 12*mi*vtIon*vtIon/(2.0*B0); + double vpar_max_ion = 4.0 * vtIon; + double mu_max_ion = 12 * mi * vtIon * vtIon / (2.0 * B0); - double vpar_max_D0 = 4.0*vtD0; + double vpar_max_D0 = 4.0 * vtD0; // Number of cells. int Nx = 4; @@ -241,33 +243,34 @@ create_ctx(void) int Nvpar = 12; int Nmu = 8; - double t_end = 5e-8; + double t_end = 5e-8; double num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_step_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, - .Te = Te, - .Ti = Ti, + .Te = Te, + .Ti = Ti, .TD0 = TD0, .vtIon = vtIon, .vtElc = vtElc, .vtD0 = vtD0, - .nuElc = nuElc, - .nuIon = nuIon, + .nuElc = nuElc, + .nuIon = nuIon, .nuFrac = nuFrac, - .B0 = B0, - .n0 = n0, + .B0 = B0, + .n0 = n0, .nD0 = nD0, - .T_source = T_source, + .T_source = T_source, .nsource = nsource, .cx = cx, .cz = cz, @@ -275,34 +278,35 @@ create_ctx(void) .lower_x = lower_x, .upper_x = upper_x, .Lx = Lx, - .Lz = Lz, - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, - .vpar_max_D0= vpar_max_D0, + .Lz = Lz, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, + .vpar_max_D0 = vpar_max_D0, .Nx = Nx, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -313,403 +317,389 @@ main(int argc, char **argv) struct gk_step_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dcx; double cz = app->cz; double xcenter = 1.2014; - double n = n0*exp(-(x-xcenter)*(x-xcenter)/2/cx/cx) * exp(-z*z/2/cz/cz); - if (n/n0 < 1e-1) - n = n0*1e-1; + double n = n0 * exp(-(x - xcenter) * (x - xcenter) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n / n0 < 1e-1) { + n = n0 * 1e-1; + } fout[0] = n; } -void -eval_density_ar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_density_ar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double x = xn[0], z = xn[1]; double n0 = app->n0Ar; - double cz = app->cz/1.4/2.0; + double cz = app->cz / 1.4 / 2.0; double zcenter = 3.14; double n = 0.0; - if (z>0) - n = n0 * exp(-(z-zcenter)*(z-zcenter)/(2.0*cz*cz)); - else - n = n0 * exp(-(z+zcenter)*(z+zcenter)/(2.0*cz*cz)); - if (n < 1.0e8) + if (z > 0) { + n = n0 * exp(-(z - zcenter) * (z - zcenter) / (2.0 * cz * cz)); + } else { + n = n0 * exp(-(z + zcenter) * (z + zcenter) / (2.0 * cz * cz)); + } + if (n < 1.0e8) { n = 1.0e8; + } fout[0] = n; } -void -eval_density_Ar1(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_density_Ar1( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 1.0e5; } -void -eval_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void -eval_udrift(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_udrift(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - fout[0] = 0.0; + fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; } - - -void -eval_temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double T = app->Te; fout[0] = T; } -void -eval_temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double T = app->Ti; fout[0] = T; } - -void -eval_temp_ar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_ar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_step_ctx *app = ctx; double T = app->TAr; fout[0] = T; } -void -eval_density_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_density_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; double x = xn[0], z = xn[1]; @@ -149,20 +145,24 @@ eval_density_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_REST double cx = app->cx; double cz = app->cz; double xcenter = 1.2014; - double n = nsource*exp(-(x-xcenter)*(x-xcenter)/2/cx/cx) * exp(-z*z/2/cz/cz); - if (n/nsource < 1e-5) - n = nsource*1e-5; + double n = + nsource * exp(-(x - xcenter) * (x - xcenter) / 2 / cx / cx) * exp(-z * z / 2 / cz / cz); + if (n / nsource < 1e-5) { + n = nsource * 1e-5; + } fout[0] = n; } -void -eval_upar_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_temp_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; double n0 = app->n0; @@ -170,8 +170,9 @@ eval_temp_source(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = T; } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_step_ctx *app = ctx; @@ -182,62 +183,64 @@ double plasma_freq(double n, double m) { double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - return sqrt(n*eV*eV/m/eps0); + return sqrt(n * eV * eV / m / eps0); } -struct gk_step_ctx -create_ctx(void) +struct gk_step_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // ion mass - double mAr = 39.95*GKYL_PROTON_MASS; // Ar ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // ion mass + double mAr = 39.95 * GKYL_PROTON_MASS; // Ar ion mass double me = GKYL_ELECTRON_MASS; double qi = eV; // ion charge double qe = -eV; // electron charge - double Te = 100*2.8*eV; - double Ti = 150*2.8*eV; - double TAr = 40.0*eV; + double Te = 100 * 2.8 * eV; + double Ti = 150 * 2.8 * eV; + double TAr = 40.0 * eV; double B0 = 2.51; // Magnetic field magnitude in Tesla - double n0 = 3.0e19/2.8; // Particle density in 1/m^3 - double n0Ar = n0*0.0001/3.0; // Particle density in 1/m^3 - + double n0 = 3.0e19 / 2.8; // Particle density in 1/m^3 + double n0Ar = n0 * 0.0001 / 3.0; // Particle density in 1/m^3 + // Derived parameters. - double vtIon = sqrt(Ti/mi); - double vtElc = sqrt(Te/me); - double vtAr = sqrt(TAr/mAr); + double vtIon = sqrt(Ti / mi); + double vtElc = sqrt(Te / me); + double vtAr = sqrt(TAr / mAr); // Source parameters. - double nsource = 3.9e23/2.8; // peak source rate in particles/m^3/s - double T_source = 285*eV*2.8; - double cx = 0.0065612*9; + double nsource = 3.9e23 / 2.8; // peak source rate in particles/m^3/s + double T_source = 285 * eV * 2.8; + double cx = 0.0065612 * 9; double cz = 0.4916200; // Collision parameters. double nuFrac = 0.25; - double logLambdaElc = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Te/eV); - double nuElc = nuFrac*logLambdaElc*pow(eV, 4.0)*n0/(6.0*sqrt(2.0)*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(me)*(Te*sqrt(Te))); // collision freq + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te / eV); + double nuElc = nuFrac * logLambdaElc * pow(eV, 4.0) * n0 / + (6.0 * sqrt(2.0) * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(me) * (Te * sqrt(Te)) + ); // collision freq - double logLambdaIon = 6.6 - 0.5*log(n0/1e20) + 1.5*log(Ti/eV); - double nuIon = nuFrac*logLambdaIon*pow(eV, 4.0)*n0/(12.0*M_PI*sqrt(M_PI)*eps0*eps0*sqrt(mi)*(Ti*sqrt(Ti))); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti / eV); + double nuIon = nuFrac * logLambdaIon * pow(eV, 4.0) * n0 / + (12.0 * M_PI * sqrt(M_PI) * eps0 * eps0 * sqrt(mi) * (Ti * sqrt(Ti))); // Simulation box size (m). double lower_x = 0.934; double upper_x = 1.4688; double Lx = upper_x - lower_x; - double Lz = (M_PI-1e-14)*2.0; + double Lz = (M_PI - 1e-14) * 2.0; - double vpar_max_elc = 4.0*vtElc; - double mu_max_elc = 18*me*vtElc*vtElc/(2.0*B0); + double vpar_max_elc = 4.0 * vtElc; + double mu_max_elc = 18 * me * vtElc * vtElc / (2.0 * B0); - double vpar_max_ion = 4.0*vtIon; - double mu_max_ion = 18*mi*vtIon*vtIon/(2.0*B0); + double vpar_max_ion = 4.0 * vtIon; + double mu_max_ion = 18 * mi * vtIon * vtIon / (2.0 * B0); - double vpar_max_Ar = 4.0*vtAr; - double mu_max_Ar = 18.*mAr*vtAr*vtAr/(2.0*B0); + double vpar_max_Ar = 4.0 * vtAr; + double mu_max_Ar = 18. * mAr * vtAr * vtAr / (2.0 * B0); // Number of cells. int Nx = 4; @@ -245,69 +248,71 @@ create_ctx(void) int Nvpar = 16; int Nmu = 8; - double t_end = 2.0e-6; + double t_end = 2.0e-6; double num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct gk_step_ctx ctx = { .cdim = cdim, .vdim = vdim, - .chargeElc = qe, - .massElc = me, - .chargeIon = qi, + .chargeElc = qe, + .massElc = me, + .chargeIon = qi, .massIon = mi, .massAr = mAr, - .Te = Te, - .Ti = Ti, - .TAr = TAr, + .Te = Te, + .Ti = Ti, + .TAr = TAr, .vtIon = vtIon, .vtElc = vtElc, .vtAr = vtAr, - .nuElc = nuElc, - .nuIon = nuIon, + .nuElc = nuElc, + .nuIon = nuIon, .nuFrac = nuFrac, - .B0 = B0, - .n0 = n0, + .B0 = B0, + .n0 = n0, .n0Ar = n0Ar, - .T_source = T_source, + .T_source = T_source, .nsource = nsource, .cx = cx, .cz = cz, .lower_x = lower_x, .upper_x = upper_x, .Lx = Lx, - .Lz = Lz, - .vpar_max_elc = vpar_max_elc, - .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, - .mu_max_ion = mu_max_ion, - .vpar_max_Ar = vpar_max_Ar, - .mu_max_Ar = mu_max_Ar, + .Lz = Lz, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, + .vpar_max_Ar = vpar_max_Ar, + .mu_max_Ar = mu_max_Ar, .Nx = Nx, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, - .t_end = t_end, - .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -318,264 +323,258 @@ main(int argc, char **argv) struct gk_step_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; da_shift; double R_axis = app->R_axis; double delta = app->delta; - return R_axis - a_shift*r*r/(2.*R_axis) + r*cos(theta + asin(delta)*sin(theta)); + return R_axis - a_shift * r * r / (2. * R_axis) + r * cos(theta + asin(delta) * sin(theta)); } double Z_rtheta(double r, double theta, void *ctx) @@ -65,7 +64,7 @@ double Z_rtheta(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; double Z_axis = app->Z_axis; double kappa = app->kappa; - return Z_axis + kappa*r*sin(theta); + return Z_axis + kappa * r * sin(theta); } double dRdr(double r, double theta, void *ctx) @@ -74,34 +73,34 @@ double dRdr(double r, double theta, void *ctx) double a_shift = app->a_shift; double R_axis = app->R_axis; double delta = app->delta; - return - a_shift*r/(R_axis) + cos(theta + asin(delta)*sin(theta)); + return -a_shift * r / (R_axis) + cos(theta + asin(delta) * sin(theta)); } double dRdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return -r*sin(theta + asin(delta)*sin(theta))*(1.+asin(delta)*cos(theta)); + return -r * sin(theta + asin(delta) * sin(theta)) * (1. + asin(delta) * cos(theta)); } double dZdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*sin(theta); + return kappa * sin(theta); } double dZdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*cos(theta); + return kappa * r * cos(theta); } double Jr(double r, double theta, void *ctx) { - return R_rtheta(r,theta,ctx)*( dRdr(r,theta,ctx) * dZdtheta(r,theta,ctx) - -dRdtheta(r,theta,ctx) * dZdr(r,theta,ctx) ); + return R_rtheta(r, theta, ctx) * (dRdr(r, theta, ctx) * dZdtheta(r, theta, ctx) - + dRdtheta(r, theta, ctx) * dZdr(r, theta, ctx)); } struct integrand_ctx { @@ -114,7 +113,7 @@ double integrand(double t, void *int_ctx) struct integrand_ctx *inctx = int_ctx; double r = inctx->r; struct gk_app_ctx *app = inctx->app_ctx; - return Jr(r,t,app) / pow(R_rtheta(r,t,app),2); + return Jr(r, t, app) / pow(R_rtheta(r, t, app), 2); } double Bphi(double R, void *ctx) @@ -123,7 +122,7 @@ double Bphi(double R, void *ctx) struct gk_app_ctx *app = ctx; double B0 = app->B0; double R0 = app->R0; - return B0*R0/R; + return B0 * R0 / R; } double dPsidr(double r, double theta, void *ctx) @@ -131,19 +130,23 @@ double dPsidr(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2.*M_PI, 7, 1e-10); + integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2. * M_PI, 7, 1e-10); - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); - double R_omp = R_rtheta(r,0.0,ctx); - return ( R*Bt/(2.*M_PI*qprofile(R_omp)))*integral.res; + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); + double R_omp = R_rtheta(r, 0.0, ctx); + return (R * Bt / (2. * M_PI * qprofile(R_omp))) * integral.res; } double alpha(double r, double theta, double phi, void *ctx) { double twrap = theta; - while (twrap < -M_PI) twrap = twrap+2.*M_PI; - while (M_PI < twrap) twrap = twrap-2.*M_PI; + while (twrap < -M_PI) { + twrap = twrap + 2. * M_PI; + } + while (M_PI < twrap) { + twrap = twrap - 2. * M_PI; + } struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; @@ -155,24 +158,25 @@ double alpha(double r, double theta, double phi, void *ctx) integral.res = -integral.res; } - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); - return phi - R*Bt*integral.res/dPsidr(r,theta,ctx); + return phi - R * Bt * integral.res / dPsidr(r, theta, ctx); } double gradr(double r, double theta, void *ctx) { - return (R_rtheta(r,theta,ctx)/Jr(r,theta,ctx))*sqrt(pow(dRdtheta(r,theta,ctx),2) + pow(dZdtheta(r,theta,ctx),2)); + return (R_rtheta(r, theta, ctx) / Jr(r, theta, ctx)) * + sqrt(pow(dRdtheta(r, theta, ctx), 2) + pow(dZdtheta(r, theta, ctx), 2)); } -void zero_func(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void zero_func(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } // Density initial condition (like TCV exp profile) -void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; struct gk_app_ctx *app = ctx; @@ -181,11 +185,11 @@ void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI double c1 = 0.5; double c2 = 8.0; double c3 = 0.005; - fout[0] = n0*(c1*(1.+tanh(c2*(-10*(x+x0))))+c3); + fout[0] = n0 * (c1 * (1. + tanh(c2 * (-10 * (x + x0)))) + c3); } // Electron temperature initial conditions -void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; struct gk_app_ctx *app = ctx; @@ -195,11 +199,11 @@ void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f double c1 = 0.5; // control the temperature at the _core double c2 = 8.0; // control the width of the transition region double c3 = 0.1; // control the temperature at the SOL - fout[0] = c0*T0*(c1*(1.+tanh(c2*(-10*(x+x0))))+c3); + fout[0] = c0 * T0 * (c1 * (1. + tanh(c2 * (-10 * (x + x0)))) + c3); } // Ion temperature initial conditions -void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; struct gk_app_ctx *app = ctx; @@ -209,23 +213,23 @@ void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f double c1 = 0.5; // control the temperature at the _core double c2 = 3.0; // control the width of the transition region double c3 = 0.2; // control the temperature at the SOL - fout[0] = c0*T0*(c1*(1.+tanh(c2*(-10*(x+x0))))+c3); + fout[0] = c0 * T0 * (c1 * (1. + tanh(c2 * (-10 * (x + x0)))) + c3); } // Collision frequencies. -void nuElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void nuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuElc; } -void nuIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void nuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_app_ctx *app = ctx; fout[0] = app->nuIon; } // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; @@ -234,81 +238,85 @@ void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) double x_inner = app->x_inner; double Cy = app->Cy; - double r = r_x(x,a_mid,x_inner); + double r = r_x(x, a_mid, x_inner); // Map to cylindrical (R, Z, phi) coordinates. double R = R_rtheta(r, z, ctx); double Z = Z_rtheta(r, z, ctx); - double phi = y/Cy + alpha(r, z, 0, ctx); + double phi = y / Cy + alpha(r, z, 0, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + double X = R * cos(phi); + double Y = R * sin(phi); + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } // Taken from rt gk d3d 3x2c, is this the non uniform v grid mapping? -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; double mu_max_elc = app->mu_max_elc; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; double mu_max_ion = app->mu_max_ion; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; struct gk_app_ctx *app = ctx; double a_mid = app->a_mid; double Cy = app->Cy; double x_inner = app->x_inner; - double r = r_x(x,a_mid,x_inner); - double Bt = Bphi(R_rtheta(r,z,ctx),ctx); - double Bp = dPsidr(r,z,ctx)/R_rtheta(r,z,ctx)*gradr(r,z,ctx); - - double drdtheta = dRdtheta(r,z,ctx); - double dzdtheta = dZdtheta(r,z,ctx); - double den = sqrt(pow(drdtheta,2) + pow(dzdtheta,2)); - double B_r = Bp*drdtheta/den; - double B_z = Bp*dzdtheta/den; - double phi = y/Cy + alpha(r, z, 0, ctx); + double r = r_x(x, a_mid, x_inner); + double Bt = Bphi(R_rtheta(r, z, ctx), ctx); + double Bp = dPsidr(r, z, ctx) / R_rtheta(r, z, ctx) * gradr(r, z, ctx); + + double drdtheta = dRdtheta(r, z, ctx); + double dzdtheta = dZdtheta(r, z, ctx); + double den = sqrt(pow(drdtheta, 2) + pow(dzdtheta, 2)); + double B_r = Bp * drdtheta / den; + double B_z = Bp * dzdtheta / den; + double phi = y / Cy + alpha(r, z, 0, ctx); double R = R_rtheta(r, z, ctx); - // xc are computational coords. + // xc are computational coords. // Set Cartesian components of magnetic field. fout[0] = B_r * cos(phi) + Bt * sin(phi); fout[1] = B_r * sin(phi) - Bt * cos(phi); fout[2] = B_z; } -void bc_shift_func_lo(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_lo(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0]; struct gk_app_ctx *app = ctx; @@ -321,10 +329,10 @@ void bc_shift_func_lo(double t, const double *xc, double* GKYL_RESTRICT fout, vo double r = r_x(x, a_mid, x_inner); - fout[0] = Cy*( alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx) ); + fout[0] = Cy * (alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx)); } -void bc_shift_func_up(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_up(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0]; struct gk_app_ctx *app = ctx; @@ -337,10 +345,10 @@ void bc_shift_func_up(double t, const double *xc, double* GKYL_RESTRICT fout, vo double r = r_x(x, a_mid, x_inner); - fout[0] = -Cy*( alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx) ); + fout[0] = -Cy * (alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx)); } -void density_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; @@ -350,22 +358,22 @@ void density_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRIC double sigma_srcGB = 0.02; double bfac_srcGB = 1.0; - fout[0] = n_srcGB*exp(-pow(x-x_srcGB,2)/(2.*pow(sigma_srcGB,2))) - *GKYL_MAX2(sin(z)*exp(-pow(fabs(z),1.5)/(2*pow(bfac_srcGB,2))),0.); + fout[0] = n_srcGB * exp(-pow(x - x_srcGB, 2) / (2. * pow(sigma_srcGB, 2))) * + GKYL_MAX2(sin(z) * exp(-pow(fabs(z), 1.5) / (2 * pow(bfac_srcGB, 2))), 0.); } -void temp_src(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_src(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; struct gk_app_ctx *app = ctx; double x_srcOMP = 0.0; double sigma_srcOMP = 0.2; - double Te_srcOMP = 200*1e-19; + double Te_srcOMP = 200 * 1e-19; - if (x < x_srcOMP + 3*sigma_srcOMP) { + if (x < x_srcOMP + 3 * sigma_srcOMP) { fout[0] = Te_srcOMP; } else { - fout[0] = Te_srcOMP*3./8.; + fout[0] = Te_srcOMP * 3. / 8.; } } @@ -379,69 +387,70 @@ struct gk_app_ctx create_ctx(void) double qe = -eV; // electron charge // Geometry and magnetic field. - double a_shift = 0.5; // Parameter in Shafranov shift. - double Z_axis = 0.1414361745; // Magnetic axis height [m]. - double R_axis = 0.8867856264; // Magnetic axis major radius [m]. - double B_axis = 1.4; // Magnetic field at the magnetic axis [T]. + double a_shift = 0.5; // Parameter in Shafranov shift. + double Z_axis = 0.1414361745; // Magnetic axis height [m]. + double R_axis = 0.8867856264; // Magnetic axis major radius [m]. + double B_axis = 1.4; // Magnetic field at the magnetic axis [T]. double R_LCFSmid = 1.0870056099999; // Major radius of the LCFS at the outboard midplane [m - double x_inner = 0.04; // Radial extent inside LCFS - double x_outer = 0.00; // Radial extent outside LCFS - double Rmid_min = R_LCFSmid - x_inner; // Minimum midplane major radius of simulation box [m]. - double Rmid_max = R_LCFSmid + x_outer; // Maximum midplane major radius of simulation box [m]. - double a_mid = R_LCFSmid-R_axis; // Minor radius at outboard midplane [m]. + double x_inner = 0.04; // Radial extent inside LCFS + double x_outer = 0.00; // Radial extent outside LCFS + double Rmid_min = R_LCFSmid - x_inner; // Minimum midplane major radius of simulation box [m]. + double Rmid_max = R_LCFSmid + x_outer; // Maximum midplane major radius of simulation box [m]. + double a_mid = R_LCFSmid - R_axis; // Minor radius at outboard midplane [m]. // Redefine a_mid with Shafranov shift, to ensure LCFS radial location. - a_mid = R_axis/a_shift - sqrt(R_axis*(R_axis - 2*a_shift*R_LCFSmid + 2*a_shift*R_axis))/a_shift; - double R0 = 0.5*(Rmid_min+Rmid_max); // Major radius of the simulation box [m]. - double r0 = R0-R_axis; // Minor radius of the simulation box [m]. - double B0 = B_axis*(R_axis/R0); // Magnetic field magnitude in the simulation box [T]. - double kappa = 1.4; // Elongation (=1 for no elongation). - double delta = -0.38; // Triangularity (=0 for no triangularity). + a_mid = R_axis / a_shift - + sqrt(R_axis * (R_axis - 2 * a_shift * R_LCFSmid + 2 * a_shift * R_axis)) / a_shift; + double R0 = 0.5 * (Rmid_min + Rmid_max); // Major radius of the simulation box [m]. + double r0 = R0 - R_axis; // Minor radius of the simulation box [m]. + double B0 = B_axis * (R_axis / R0); // Magnetic field magnitude in the simulation box [T]. + double kappa = 1.4; // Elongation (=1 for no elongation). + double delta = -0.38; // Triangularity (=0 for no triangularity). // Plasma parameters. Chosen based on the value of a cubic sline // between the last TS data inside the LCFS and the probe data in // in the far SOL, near R=0.475 m. double AMU = 2.01410177811; - double mi = mp*AMU; // Deuterium ions. - double Te0 = 100*eV; - double Ti0 = 100*eV; - double n0 = 2.0e19; // [1/m^3] - double Bref = 1.129; // Reference magnetic field [T]. - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; - - // Configuration domain parameters - double Lx = Rmid_max-Rmid_min; // Domain size along x. - double x_min = 0.; - double x_max = Lx; - double x_LCFS = R_LCFSmid - Rmid_min; // Radial location of the last closed flux surface. - double q0 = qprofile(R0); // Safety factor in the center of domain. - double Cy = r0/q0; // Normalization in binormal coordinate. - - double Ly = 150*rho_s; // Domain size along y. + double mi = mp * AMU; // Deuterium ions. + double Te0 = 100 * eV; + double Ti0 = 100 * eV; + double n0 = 2.0e19; // [1/m^3] + double Bref = 1.129; // Reference magnetic field [T]. + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; + + // Configuration domain parameters + double Lx = Rmid_max - Rmid_min; // Domain size along x. + double x_min = 0.; + double x_max = Lx; + double x_LCFS = R_LCFSmid - Rmid_min; // Radial location of the last closed flux surface. + double q0 = qprofile(R0); // Safety factor in the center of domain. + double Cy = r0 / q0; // Normalization in binormal coordinate. + + double Ly = 150 * rho_s; // Domain size along y. // Adjust the domain size along y to have integer toroidal mode number. // We need: 2*pi*Cy/Ly = integer (Cy = r0/q0) - Ly = 2.*M_PI*Cy/round(2.*M_PI*Cy/Ly); - double y_min = -Ly/2.; - double y_max = Ly/2.; + Ly = 2. * M_PI * Cy / round(2. * M_PI * Cy / Ly); + double y_min = -Ly / 2.; + double y_max = Ly / 2.; - double vol_frac = 1.0/(2.*M_PI*Cy/Ly); + double vol_frac = 1.0 / (2. * M_PI * Cy / Ly); - double Lz = 2.*M_PI-1e-10; // Domain size along magnetic field. - double z_min = -Lz/2.; - double z_max = Lz/2.; + double Lz = 2. * M_PI - 1e-10; // Domain size along magnetic field. + double z_min = -Lz / 2.; + double z_max = Lz / 2.; // Collision frequencies double nuFrac = 0.5; // Electron-electron collision freq. - double logLambdaElc = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuElc = nuFrac * logLambdaElc * pow(eV, 4) * n0 / - (6*sqrt(2.) * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(me) * pow(Te0,3./2.)); + (6 * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(me) * pow(Te0, 3. / 2.)); // Ion-ion collision freq. - double logLambdaIon = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuIon = nuFrac * logLambdaIon * pow(eV, 4) * n0 / - (12 * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(mi) * pow(Ti0,3./2.)); + (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(mi) * pow(Ti0, 3. / 2.)); // Source parameters double num_sources = 1; // We do not activate the recycling source here. @@ -450,8 +459,8 @@ struct gk_app_ctx create_ctx(void) bool adapt_particle_srcCORE = false; double energy_srcCORE = 0.2e6; // [W] double particle_srcCORE = 0.6e22; // [1/s] - double center_srcCORE[3] = {x_min, 0.0, -Lz/4}; // This is the position of the ion source, - double sigma_srcCORE[3] = {0.03*Lx, 0.0, Lz/6}; // the electron source will be at +Lz/2. + double center_srcCORE[3] = {x_min, 0.0, -Lz / 4}; // This is the position of the ion source, + double sigma_srcCORE[3] = {0.03 * Lx, 0.0, Lz / 6}; // the electron source will be at +Lz/2. double floor_srcCORE = 1e-10; // Grid parameters int Nx = 8; @@ -461,14 +470,14 @@ struct gk_app_ctx create_ctx(void) int Nmu = 8; int poly_order = 1; // Velocity box dimensions - double vpar_max_elc = 6.*vte; - double mu_max_elc = 1.5*me*pow(4*vte,2)/(2*B0); - double vpar_max_ion = 6.*vti; - double mu_max_ion = 1.5*mi*pow(4*vti,2)/(2*B0); - double t_end = 25*0.00551633e-6; + double vpar_max_elc = 6. * vte; + double mu_max_elc = 1.5 * me * pow(4 * vte, 2) / (2 * B0); + double vpar_max_ion = 6. * vti; + double mu_max_ion = 1.5 * mi * pow(4 * vti, 2) / (2 * B0); + double t_end = 25 * 0.00551633e-6; int num_frames = 1; double write_phase_freq = 0.2; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-3; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -477,62 +486,75 @@ struct gk_app_ctx create_ctx(void) .vdim = vdim, .a_shift = a_shift, .R_axis = R_axis, - .R0 = R0 , - .a_mid = a_mid , + .R0 = R0, + .a_mid = a_mid, .x_inner = x_inner, - .r0 = r0 , - .B0 = B0 , - .kappa = kappa , - .delta = delta , - .q0 = q0 , - .Cy = Cy , - .Lx = Lx , - .Ly = Ly , - .Lz = Lz , - .x_min = x_min, .x_max = x_max, - .y_min = y_min, .y_max = y_max, - .z_min = z_min, .z_max = z_max, + .r0 = r0, + .B0 = B0, + .kappa = kappa, + .delta = delta, + .q0 = q0, + .Cy = Cy, + .Lx = Lx, + .Ly = Ly, + .Lz = Lz, + .x_min = x_min, + .x_max = x_max, + .y_min = y_min, + .y_max = y_max, + .z_min = z_min, + .z_max = z_max, .Bref = Bref, .x_LCFS = x_LCFS, - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - .nuFrac = nuFrac, .nuElc = nuElc, .nuIon = nuIon, + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + .nuFrac = nuFrac, + .nuElc = nuElc, + .nuIon = nuIon, .num_sources = num_sources, .adapt_energy_srcCORE = adapt_energy_srcCORE, .adapt_particle_srcCORE = adapt_particle_srcCORE, .center_srcCORE = {center_srcCORE[0], center_srcCORE[1], center_srcCORE[2]}, .sigma_srcCORE = {sigma_srcCORE[0], sigma_srcCORE[1], sigma_srcCORE[2]}, - .energy_srcCORE = energy_srcCORE, .particle_srcCORE = particle_srcCORE, + .energy_srcCORE = energy_srcCORE, + .particle_srcCORE = particle_srcCORE, .floor_srcCORE = floor_srcCORE, - .Nx = Nx, - .Ny = Ny, - .Nz = Nz, - .Nvpar = Nvpar, - .Nmu = Nmu, + .Nx = Nx, + .Ny = Ny, + .Nz = Nz, + .Nvpar = Nvpar, + .Nmu = Nmu, .cells = {Nx, Ny, Nz, Nvpar, Nmu}, - .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .poly_order = poly_order, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .write_phase_freq = write_phase_freq, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Init(&argc, &argv); + } #endif - + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); @@ -541,10 +563,12 @@ main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // context for init functions int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; da_shift; double R_axis = app->R_axis; double delta = app->delta; - return R_axis - a_shift*r*r/(2.*R_axis) + r*cos(theta + asin(delta)*sin(theta)); + return R_axis - a_shift * r * r / (2. * R_axis) + r * cos(theta + asin(delta) * sin(theta)); } double Z_rtheta(double r, double theta, void *ctx) @@ -73,7 +72,7 @@ double Z_rtheta(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; double Z_axis = app->Z_axis; double kappa = app->kappa; - return Z_axis + kappa*r*sin(theta); + return Z_axis + kappa * r * sin(theta); } double dRdr(double r, double theta, void *ctx) @@ -82,34 +81,34 @@ double dRdr(double r, double theta, void *ctx) double a_shift = app->a_shift; double R_axis = app->R_axis; double delta = app->delta; - return - a_shift*r/(R_axis) + cos(theta + asin(delta)*sin(theta)); + return -a_shift * r / (R_axis) + cos(theta + asin(delta) * sin(theta)); } double dRdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return -r*sin(theta + asin(delta)*sin(theta))*(1.+asin(delta)*cos(theta)); + return -r * sin(theta + asin(delta) * sin(theta)) * (1. + asin(delta) * cos(theta)); } double dZdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*sin(theta); + return kappa * sin(theta); } double dZdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*cos(theta); + return kappa * r * cos(theta); } double Jr(double r, double theta, void *ctx) { - return R_rtheta(r,theta,ctx)*( dRdr(r,theta,ctx) * dZdtheta(r,theta,ctx) - -dRdtheta(r,theta,ctx) * dZdr(r,theta,ctx) ); + return R_rtheta(r, theta, ctx) * (dRdr(r, theta, ctx) * dZdtheta(r, theta, ctx) - + dRdtheta(r, theta, ctx) * dZdr(r, theta, ctx)); } struct integrand_ctx { @@ -122,7 +121,7 @@ double integrand(double t, void *int_ctx) struct integrand_ctx *inctx = int_ctx; double r = inctx->r; struct gk_app_ctx *app = inctx->app_ctx; - return Jr(r,t,app) / pow(R_rtheta(r,t,app),2); + return Jr(r, t, app) / pow(R_rtheta(r, t, app), 2); } double Bphi(double R, void *ctx) @@ -131,7 +130,7 @@ double Bphi(double R, void *ctx) struct gk_app_ctx *app = ctx; double B0 = app->B0; double R0 = app->R0; - return B0*R0/R; + return B0 * R0 / R; } double dPsidr(double r, double theta, void *ctx) @@ -139,19 +138,23 @@ double dPsidr(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2.*M_PI, 7, 1e-10); + integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2. * M_PI, 7, 1e-10); - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); - double R_omp = R_rtheta(r,0.0,ctx); - return ( R*Bt/(2.*M_PI*qprofile(R_omp)))*integral.res; + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); + double R_omp = R_rtheta(r, 0.0, ctx); + return (R * Bt / (2. * M_PI * qprofile(R_omp))) * integral.res; } double alpha(double r, double theta, double phi, void *ctx) { double twrap = theta; - while (twrap < -M_PI) twrap = twrap+2.*M_PI; - while (M_PI < twrap) twrap = twrap-2.*M_PI; + while (twrap < -M_PI) { + twrap = twrap + 2. * M_PI; + } + while (M_PI < twrap) { + twrap = twrap - 2. * M_PI; + } struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; @@ -163,24 +166,25 @@ double alpha(double r, double theta, double phi, void *ctx) integral.res = -integral.res; } - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); - return phi - R*Bt*integral.res/dPsidr(r,theta,ctx); + return phi - R * Bt * integral.res / dPsidr(r, theta, ctx); } double gradr(double r, double theta, void *ctx) { - return (R_rtheta(r,theta,ctx)/Jr(r,theta,ctx))*sqrt(pow(dRdtheta(r,theta,ctx),2) + pow(dZdtheta(r,theta,ctx),2)); + return (R_rtheta(r, theta, ctx) / Jr(r, theta, ctx)) * + sqrt(pow(dRdtheta(r, theta, ctx), 2) + pow(dZdtheta(r, theta, ctx), 2)); } -void zero_func(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void zero_func(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } // Density initial condition (like TCV exp profile) -void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; struct gk_app_ctx *app = ctx; @@ -189,11 +193,11 @@ void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI double c1 = 0.5; double c2 = 8.0; double c3 = 0.005; - fout[0] = n0*(c1*(1.+tanh(c2*(-10*(x+x0))))+c3); + fout[0] = n0 * (c1 * (1. + tanh(c2 * (-10 * (x + x0)))) + c3); } // Electron temperature initial conditions -void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; struct gk_app_ctx *app = ctx; @@ -203,11 +207,11 @@ void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f double c1 = 0.5; // control the temperature at the _core double c2 = 8.0; // control the width of the transition region double c3 = 0.1; // control the temperature at the SOL - fout[0] = c0*T0*(c1*(1.+tanh(c2*(-10*(x+x0))))+c3); + fout[0] = c0 * T0 * (c1 * (1. + tanh(c2 * (-10 * (x + x0)))) + c3); } // Ion temperature initial conditions -void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[1]; struct gk_app_ctx *app = ctx; @@ -217,11 +221,12 @@ void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f double c1 = 0.5; // control the temperature at the _core double c2 = 3.0; // control the width of the transition region double c3 = 0.2; // control the temperature at the SOL - fout[0] = c0*T0*(c1*(1.+tanh(c2*(-10*(x+x0))))+c3); + fout[0] = c0 * T0 * (c1 * (1. + tanh(c2 * (-10 * (x + x0)))) + c3); } -void -diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void diffusion_D_func( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -229,86 +234,89 @@ diffusion_D_func(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; struct gk_app_ctx *app = ctx; double Cy = app->Cy; double a_mid = app->a_mid; double x_inner = app->x_inner; - double r = r_x(x,a_mid,x_inner); + double r = r_x(x, a_mid, x_inner); // Map to cylindrical (R, Z, phi) coordinates. - double R = R_rtheta(r, z, ctx); - double Z = Z_rtheta(r, z, ctx); - double phi = y/Cy + alpha(r, z, 0, ctx); + double R = R_rtheta(r, z, ctx); + double Z = Z_rtheta(r, z, ctx); + double phi = y / Cy + alpha(r, z, 0, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + double X = R * cos(phi); + double Y = R * sin(phi); + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } // Taken from rt gk d3d 3x2c, is this the non uniform v grid mapping? -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; double mu_max_elc = app->mu_max_elc; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; double mu_max_ion = app->mu_max_ion; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; struct gk_app_ctx *app = ctx; double a_mid = app->a_mid; double Cy = app->Cy; double x_inner = app->x_inner; - double r = r_x(x,a_mid,x_inner); - double Bt = Bphi(R_rtheta(r,z,ctx),ctx); - double Bp = dPsidr(r,z,ctx)/R_rtheta(r,z,ctx)*gradr(r,z,ctx); - - double drdtheta = dRdtheta(r,z,ctx); - double dzdtheta = dZdtheta(r,z,ctx); - double den = sqrt(pow(drdtheta,2) + pow(dzdtheta,2)); - double B_r = Bp*drdtheta/den; - double B_z = Bp*dzdtheta/den; - double phi = y/Cy + alpha(r, z, 0, ctx); - double R = R_rtheta(r, z, ctx); - - // xc are computational coords. + double r = r_x(x, a_mid, x_inner); + double Bt = Bphi(R_rtheta(r, z, ctx), ctx); + double Bp = dPsidr(r, z, ctx) / R_rtheta(r, z, ctx) * gradr(r, z, ctx); + + double drdtheta = dRdtheta(r, z, ctx); + double dzdtheta = dZdtheta(r, z, ctx); + double den = sqrt(pow(drdtheta, 2) + pow(dzdtheta, 2)); + double B_r = Bp * drdtheta / den; + double B_z = Bp * dzdtheta / den; + double phi = y / Cy + alpha(r, z, 0, ctx); + double R = R_rtheta(r, z, ctx); + + // xc are computational coords. // Set Cartesian components of magnetic field. fout[0] = B_r * cos(phi) + Bt * sin(phi); fout[1] = B_r * sin(phi) - Bt * cos(phi); fout[2] = B_z; } - struct gk_app_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -324,19 +332,22 @@ struct gk_app_ctx create_ctx(void) double R_axis = 0.8867856264; // Magnetic axis major radius [m]. double B_axis = 1.4; // Magnetic field at the magnetic axis [T]. double R_LCFSmid = 1.0870056099999; // Major radius of the LCFS at the outboard midplane [m - double x_inner = 0.04; // Radial extent inside LCFS + double x_inner = 0.04; // Radial extent inside LCFS double x_outer = 0.08; // Radial extent outside LCFS double Rmid_min = R_LCFSmid - x_inner; // Minimum midplane major radius of simulation box [m]. double Rmid_max = R_LCFSmid + x_outer; // Maximum midplane major radius of simulation box [m]. - double R0 = 0.5*(Rmid_min+Rmid_max); // Major radius of the simulation box [m]. + double R0 = 0.5 * (Rmid_min + Rmid_max); // Major radius of the simulation box [m]. // Minor radius at outboard midplane [m]. Redefine it with // Shafranov shift, to ensure LCFS radial location. - double a_mid = fabs(a_shift)<1e-13? R_LCFSmid-R_axis : - R_axis/a_shift - sqrt(R_axis*(R_axis - 2*a_shift*R_LCFSmid + 2*a_shift*R_axis))/a_shift; - - double r0 = R0-R_axis; // Minor radius of the simulation box [m]. - double B0 = B_axis*(R_axis/R0); // Magnetic field magnitude in the simulation box [T]. + double a_mid = + fabs(a_shift) < 1e-13 ? + R_LCFSmid - R_axis : + R_axis / a_shift - + sqrt(R_axis * (R_axis - 2 * a_shift * R_LCFSmid + 2 * a_shift * R_axis)) / a_shift; + + double r0 = R0 - R_axis; // Minor radius of the simulation box [m]. + double B0 = B_axis * (R_axis / R0); // Magnetic field magnitude in the simulation box [T]. double kappa = 1.4; // Elongation (=1 for no elongation). double delta = -0.38; // Triangularity (=0 for no triangularity). @@ -344,40 +355,40 @@ struct gk_app_ctx create_ctx(void) // between the last TS data inside the LCFS and the probe data in // in the far SOL, near R=0.475 m. double AMU = 2.01410177811; - double mi = mp*AMU; // Deuterium ions. - double Te0 = 100*eV; - double Ti0 = 100*eV; + double mi = mp * AMU; // Deuterium ions. + double Te0 = 100 * eV; + double Ti0 = 100 * eV; double n0 = 2.0e19; // [1/m^3] double Bref = 1.129; // Reference magnetic field [T]. - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); // Thermal speeds. - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); // Thermal speeds. + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; - // Configuration domain parameters - double Lx = Rmid_max-Rmid_min; // Domain size along x. + // Configuration domain parameters + double Lx = Rmid_max - Rmid_min; // Domain size along x. double x_min = 0.; double x_max = Lx; double x_LCFS = R_LCFSmid - Rmid_min; // Radial location of the last closed flux surface. double q0 = qprofile(R0); // Safety factor in the center of domain. - double Cy = r0/q0; // Normalization in binormal coordinate. + double Cy = r0 / q0; // Normalization in binormal coordinate. - double Lz = 2.*M_PI-1e-10; // Domain size along magnetic field. - double z_min = -Lz/2.; - double z_max = Lz/2.; + double Lz = 2. * M_PI - 1e-10; // Domain size along magnetic field. + double z_min = -Lz / 2.; + double z_max = Lz / 2.; // Collision frequencies // We note that initial profile are unstable for the full collision frequency (nu=1.0). // This factor can be increased once a saturated state is reached. double nuFrac = 0.1; // Electron-electron collision freq. - double logLambdaElc = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuElc = nuFrac * logLambdaElc * pow(eV, 4) * n0 / - (6*sqrt(2.) * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(me) * pow(Te0,3./2.)); + (6 * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(me) * pow(Te0, 3. / 2.)); // Ion-ion collision freq. - double logLambdaIon = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuIon = nuFrac * logLambdaIon * pow(eV, 4) * n0 / - (12 * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(mi) * pow(Ti0,3./2.)); + (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(mi) * pow(Ti0, 3. / 2.)); // Source parameters int num_sources = 2; @@ -386,12 +397,14 @@ struct gk_app_ctx create_ctx(void) // Core source: // - Injects energy only in the core region (0.25MW per species). // - The particles injection is only the one that are lost through the inner radial boundary. - bool adapt_energy_srcCORE = true; // The source will compensate the losses in energy according to given boundaries. - bool adapt_particle_srcCORE = true; // The source will compensate the losses in particle according to given boundaries. + bool adapt_energy_srcCORE = + true; // The source will compensate the losses in energy according to given boundaries. + bool adapt_particle_srcCORE = + true; // The source will compensate the losses in particle according to given boundaries. double energy_srcCORE = P_exp; // What the source must inject in energy [W] - double particle_srcCORE = 0.0;// What the source must inject in particle [1/s] - double center_srcCORE[2] = {x_min, -Lz/4}; // This is the position of the ion source, - double sigma_srcCORE[2] = {0.03*Lx, Lz/6}; // the electron source will be at +Lz/2. + double particle_srcCORE = 0.0; // What the source must inject in particle [1/s] + double center_srcCORE[2] = {x_min, -Lz / 4}; // This is the position of the ion source, + double sigma_srcCORE[2] = {0.03 * Lx, Lz / 6}; // the electron source will be at +Lz/2. double floor_srcCORE = 1e-10; // Recycling source: // - Reinjects particles that are absorbed by the wall. @@ -401,25 +414,26 @@ struct gk_app_ctx create_ctx(void) double adapt_particle_fraction_srcRECY = recycling_rate; double energy_srcRECY = 0.0; // [W] double particle_srcRECY = 0.0; // [1/s] - double center_srcRECY[2] = {0.5*x_LCFS, M_PI}; - double sigma_srcRECY[2] = {0.25*x_LCFS, 0.05*Lz}; + double center_srcRECY[2] = {0.5 * x_LCFS, M_PI}; + double sigma_srcRECY[2] = {0.25 * x_LCFS, 0.05 * Lz}; double floor_srcRECY = 1e-10; // Grid parameters - int Nx = 9; // The LCFS is positionned at 1/3 of the domain -> the resolution must be divisible by 3. + int Nx = + 9; // The LCFS is positionned at 1/3 of the domain -> the resolution must be divisible by 3. int Nz = 8; int Nvpar = 8; int Nmu = 8; int poly_order = 1; // Velocity box dimensions - double vpar_max_elc = 5.*vte; - double mu_max_elc = me*pow(4*vte,2)/(2*B0); - double vpar_max_ion = 5.*vti; - double mu_max_ion = mi*pow(4*vti,2)/(2*B0); + double vpar_max_elc = 5. * vte; + double mu_max_elc = me * pow(4 * vte, 2) / (2 * B0); + double vpar_max_ion = 5. * vti; + double mu_max_ion = mi * pow(4 * vti, 2) / (2 * B0); double t_end = 1.e-7; // Should take 8 time steps int num_frames = 1; double write_phase_freq = 1.0; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-3; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -439,21 +453,30 @@ struct gk_app_ctx create_ctx(void) .Cy = Cy, .Lx = Lx, .Lz = Lz, - .x_min = x_min, .x_max = x_max, - .z_min = z_min, .z_max = z_max, + .x_min = x_min, + .x_max = x_max, + .z_min = z_min, + .z_max = z_max, .Bref = Bref, .x_LCFS = x_LCFS, - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - .nuFrac = nuFrac, .nuElc = nuElc, .nuIon = nuIon, + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + .nuFrac = nuFrac, + .nuElc = nuElc, + .nuIon = nuIon, .num_sources = num_sources, .adapt_energy_srcCORE = adapt_energy_srcCORE, .adapt_particle_srcCORE = adapt_particle_srcCORE, .center_srcCORE = {center_srcCORE[0], center_srcCORE[1]}, .sigma_srcCORE = {sigma_srcCORE[0], sigma_srcCORE[1]}, - .energy_srcCORE = energy_srcCORE, .particle_srcCORE = particle_srcCORE, + .energy_srcCORE = energy_srcCORE, + .particle_srcCORE = particle_srcCORE, .floor_srcCORE = floor_srcCORE, .adapt_energy_srcRECY = adapt_energy_srcRECY, @@ -461,36 +484,40 @@ struct gk_app_ctx create_ctx(void) .adapt_particle_fraction_srcRECY = adapt_particle_fraction_srcRECY, .center_srcRECY = {center_srcRECY[0], center_srcRECY[1]}, .sigma_srcRECY = {sigma_srcRECY[0], sigma_srcRECY[1]}, - .energy_srcRECY = energy_srcRECY, .particle_srcRECY = particle_srcRECY, + .energy_srcRECY = energy_srcRECY, + .particle_srcRECY = particle_srcRECY, .floor_srcRECY = floor_srcRECY, - + .Nx = Nx, .Nz = Nz, .Nvpar = Nvpar, .Nmu = Nmu, .cells = {Nx, Nz, Nvpar, Nmu}, .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .write_phase_freq = write_phase_freq, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Init(&argc, &argv); + } #endif - + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); @@ -499,10 +526,12 @@ main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // context for init functions int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; da_shift; double R_axis = app->R_axis; double delta = app->delta; - return R_axis - a_shift*r*r/(2.*R_axis) + r*cos(theta + asin(delta)*sin(theta)); + return R_axis - a_shift * r * r / (2. * R_axis) + r * cos(theta + asin(delta) * sin(theta)); } double Z_rtheta(double r, double theta, void *ctx) @@ -73,7 +72,7 @@ double Z_rtheta(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; double Z_axis = app->Z_axis; double kappa = app->kappa; - return Z_axis + kappa*r*sin(theta); + return Z_axis + kappa * r * sin(theta); } double dRdr(double r, double theta, void *ctx) @@ -82,34 +81,34 @@ double dRdr(double r, double theta, void *ctx) double a_shift = app->a_shift; double R_axis = app->R_axis; double delta = app->delta; - return - a_shift*r/(R_axis) + cos(theta + asin(delta)*sin(theta)); + return -a_shift * r / (R_axis) + cos(theta + asin(delta) * sin(theta)); } double dRdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double delta = app->delta; - return -r*sin(theta + asin(delta)*sin(theta))*(1.+asin(delta)*cos(theta)); + return -r * sin(theta + asin(delta) * sin(theta)) * (1. + asin(delta) * cos(theta)); } double dZdr(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*sin(theta); + return kappa * sin(theta); } double dZdtheta(double r, double theta, void *ctx) { struct gk_app_ctx *app = ctx; double kappa = app->kappa; - return kappa*r*cos(theta); + return kappa * r * cos(theta); } double Jr(double r, double theta, void *ctx) { - return R_rtheta(r,theta,ctx)*( dRdr(r,theta,ctx) * dZdtheta(r,theta,ctx) - -dRdtheta(r,theta,ctx) * dZdr(r,theta,ctx) ); + return R_rtheta(r, theta, ctx) * (dRdr(r, theta, ctx) * dZdtheta(r, theta, ctx) - + dRdtheta(r, theta, ctx) * dZdr(r, theta, ctx)); } struct integrand_ctx { @@ -122,7 +121,7 @@ double integrand(double t, void *int_ctx) struct integrand_ctx *inctx = int_ctx; double r = inctx->r; struct gk_app_ctx *app = inctx->app_ctx; - return Jr(r,t,app) / pow(R_rtheta(r,t,app),2); + return Jr(r, t, app) / pow(R_rtheta(r, t, app), 2); } double Bphi(double R, void *ctx) @@ -131,7 +130,7 @@ double Bphi(double R, void *ctx) struct gk_app_ctx *app = ctx; double B0 = app->B0; double R0 = app->R0; - return B0*R0/R; + return B0 * R0 / R; } double dPsidr(double r, double theta, void *ctx) @@ -139,19 +138,23 @@ double dPsidr(double r, double theta, void *ctx) struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2.*M_PI, 7, 1e-10); + integral = gkyl_dbl_exp(integrand, &tmp_ctx, 0., 2. * M_PI, 7, 1e-10); - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); - double R_omp = R_rtheta(r,0.0,ctx); - return ( R*Bt/(2.*M_PI*qprofile(R_omp)))*integral.res; + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); + double R_omp = R_rtheta(r, 0.0, ctx); + return (R * Bt / (2. * M_PI * qprofile(R_omp))) * integral.res; } double alpha(double r, double theta, double phi, void *ctx) { double twrap = theta; - while (twrap < -M_PI) twrap = twrap+2.*M_PI; - while (M_PI < twrap) twrap = twrap-2.*M_PI; + while (twrap < -M_PI) { + twrap = twrap + 2. * M_PI; + } + while (M_PI < twrap) { + twrap = twrap - 2. * M_PI; + } struct gk_app_ctx *app = ctx; struct integrand_ctx tmp_ctx = {.app_ctx = app, .r = r}; @@ -163,24 +166,25 @@ double alpha(double r, double theta, double phi, void *ctx) integral.res = -integral.res; } - double R = R_rtheta(r,theta,ctx); - double Bt = Bphi(R,ctx); + double R = R_rtheta(r, theta, ctx); + double Bt = Bphi(R, ctx); - return phi - R*Bt*integral.res/dPsidr(r,theta,ctx); + return phi - R * Bt * integral.res / dPsidr(r, theta, ctx); } double gradr(double r, double theta, void *ctx) { - return (R_rtheta(r,theta,ctx)/Jr(r,theta,ctx))*sqrt(pow(dRdtheta(r,theta,ctx),2) + pow(dZdtheta(r,theta,ctx),2)); + return (R_rtheta(r, theta, ctx) / Jr(r, theta, ctx)) * + sqrt(pow(dRdtheta(r, theta, ctx), 2) + pow(dZdtheta(r, theta, ctx), 2)); } -void zero_func(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void zero_func(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } // Density initial condition (like TCV exp profile) -void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void density_init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; struct gk_app_ctx *app = ctx; @@ -189,11 +193,11 @@ void density_init(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRI double c1 = 0.5; double c2 = 8.0; double c3 = 0.005; - fout[0] = n0*(c1*(1.+tanh(c2*(-10*(x+x0))))+c3); + fout[0] = n0 * (c1 * (1. + tanh(c2 * (-10 * (x + x0)))) + c3); } // Electron temperature initial conditions -void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; struct gk_app_ctx *app = ctx; @@ -203,11 +207,11 @@ void temp_elc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f double c1 = 0.5; // control the temperature at the _core double c2 = 8.0; // control the width of the transition region double c3 = 0.1; // control the temperature at the SOL - fout[0] = c0*T0*(c1*(1.+tanh(c2*(-10*(x+x0))))+c3); + fout[0] = c0 * T0 * (c1 * (1. + tanh(c2 * (-10 * (x + x0)))) + c3); } // Ion temperature initial conditions -void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], z = xn[2]; struct gk_app_ctx *app = ctx; @@ -217,11 +221,11 @@ void temp_ion(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT f double c1 = 0.5; // control the temperature at the _core double c2 = 3.0; // control the width of the transition region double c3 = 0.2; // control the temperature at the SOL - fout[0] = c0*T0*(c1*(1.+tanh(c2*(-10*(x+x0))))+c3); + fout[0] = c0 * T0 * (c1 * (1. + tanh(c2 * (-10 * (x + x0)))) + c3); } // Geometry evaluation functions for the gk app -void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; @@ -230,81 +234,85 @@ void mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) double x_inner = app->x_inner; double Cy = app->Cy; - double r = r_x(x,a_mid,x_inner); + double r = r_x(x, a_mid, x_inner); // Map to cylindrical (R, Z, phi) coordinates. double R = R_rtheta(r, z, ctx); double Z = Z_rtheta(r, z, ctx); - double phi = y/Cy + alpha(r, z, 0, ctx); + double phi = y / Cy + alpha(r, z, 0, ctx); // Map to Cartesian (X, Y, Z) coordinates. - double X = R*cos(phi); - double Y = R*sin(phi); - xp[0] = X; xp[1] = Y; xp[2] = Z; + double X = R * cos(phi); + double Y = R * sin(phi); + xp[0] = X; + xp[1] = Y; + xp[2] = Z; } // Taken from rt gk d3d 3x2c, is this the non uniform v grid mapping? -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; double mu_max_elc = app->mu_max_elc; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_elc*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_elc*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_elc*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_elc * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_elc * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_elc * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_app_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; double mu_max_ion = app->mu_max_ion; double cvpar = vc[0], cmu = vc[1]; // Linear map up to vpar_max/2, then quadratic. - if (fabs(cvpar) <= 0.5) - vp[0] = vpar_max_ion*cvpar; - else if (cvpar < -0.5) - vp[0] = -vpar_max_ion*2.0*pow(cvpar,2); - else - vp[0] = vpar_max_ion*2.0*pow(cvpar,2); + if (fabs(cvpar) <= 0.5) { + vp[0] = vpar_max_ion * cvpar; + } else if (cvpar < -0.5) { + vp[0] = -vpar_max_ion * 2.0 * pow(cvpar, 2); + } else { + vp[0] = vpar_max_ion * 2.0 * pow(cvpar, 2); + } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; struct gk_app_ctx *app = ctx; double a_mid = app->a_mid; double Cy = app->Cy; double x_inner = app->x_inner; - double r = r_x(x,a_mid,x_inner); - double Bt = Bphi(R_rtheta(r,z,ctx),ctx); - double Bp = dPsidr(r,z,ctx)/R_rtheta(r,z,ctx)*gradr(r,z,ctx); - - double drdtheta = dRdtheta(r,z,ctx); - double dzdtheta = dZdtheta(r,z,ctx); - double den = sqrt(pow(drdtheta,2) + pow(dzdtheta,2)); - double B_r = Bp*drdtheta/den; - double B_z = Bp*dzdtheta/den; - double phi = y/Cy + alpha(r, z, 0, ctx); + double r = r_x(x, a_mid, x_inner); + double Bt = Bphi(R_rtheta(r, z, ctx), ctx); + double Bp = dPsidr(r, z, ctx) / R_rtheta(r, z, ctx) * gradr(r, z, ctx); + + double drdtheta = dRdtheta(r, z, ctx); + double dzdtheta = dZdtheta(r, z, ctx); + double den = sqrt(pow(drdtheta, 2) + pow(dzdtheta, 2)); + double B_r = Bp * drdtheta / den; + double B_z = Bp * dzdtheta / den; + double phi = y / Cy + alpha(r, z, 0, ctx); double R = R_rtheta(r, z, ctx); - // xc are computational coords. + // xc are computational coords. // Set Cartesian components of magnetic field. fout[0] = B_r * cos(phi) + Bt * sin(phi); fout[1] = B_r * sin(phi) - Bt * cos(phi); fout[2] = B_z; } -void bc_shift_func_lo(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_lo(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0]; struct gk_app_ctx *app = ctx; @@ -317,10 +325,10 @@ void bc_shift_func_lo(double t, const double *xc, double* GKYL_RESTRICT fout, vo double r = r_x(x, a_mid, x_inner); - fout[0] = Cy*( alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx) ); + fout[0] = Cy * (alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx)); } -void bc_shift_func_up(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_up(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0]; struct gk_app_ctx *app = ctx; @@ -333,7 +341,7 @@ void bc_shift_func_up(double t, const double *xc, double* GKYL_RESTRICT fout, vo double r = r_x(x, a_mid, x_inner); - fout[0] = -Cy*( alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx) ); + fout[0] = -Cy * (alpha(r, z_min, 0.0, ctx) - alpha(r, z_max, 0.0, ctx)); } struct gk_app_ctx create_ctx(void) @@ -351,19 +359,22 @@ struct gk_app_ctx create_ctx(void) double R_axis = 0.8867856264; // Magnetic axis major radius [m]. double B_axis = 1.4; // Magnetic field at the magnetic axis [T]. double R_LCFSmid = 1.0870056099999; // Major radius of the LCFS at the outboard midplane [m - double x_inner = 0.04; // Radial extent inside LCFS + double x_inner = 0.04; // Radial extent inside LCFS double x_outer = 0.08; // Radial extent outside LCFS double Rmid_min = R_LCFSmid - x_inner; // Minimum midplane major radius of simulation box [m]. double Rmid_max = R_LCFSmid + x_outer; // Maximum midplane major radius of simulation box [m]. - double R0 = 0.5*(Rmid_min+Rmid_max); // Major radius of the simulation box [m]. + double R0 = 0.5 * (Rmid_min + Rmid_max); // Major radius of the simulation box [m]. // Minor radius at outboard midplane [m]. Redefine it with // Shafranov shift, to ensure LCFS radial location. - double a_mid = fabs(a_shift)<1e-13? R_LCFSmid-R_axis : - R_axis/a_shift - sqrt(R_axis*(R_axis - 2*a_shift*R_LCFSmid + 2*a_shift*R_axis))/a_shift; - - double r0 = R0-R_axis; // Minor radius of the simulation box [m]. - double B0 = B_axis*(R_axis/R0); // Magnetic field magnitude in the simulation box [T]. + double a_mid = + fabs(a_shift) < 1e-13 ? + R_LCFSmid - R_axis : + R_axis / a_shift - + sqrt(R_axis * (R_axis - 2 * a_shift * R_LCFSmid + 2 * a_shift * R_axis)) / a_shift; + + double r0 = R0 - R_axis; // Minor radius of the simulation box [m]. + double B0 = B_axis * (R_axis / R0); // Magnetic field magnitude in the simulation box [T]. double kappa = 1.4; // Elongation (=1 for no elongation). double delta = -0.38; // Triangularity (=0 for no triangularity). @@ -372,60 +383,65 @@ struct gk_app_ctx create_ctx(void) // in the far SOL, near R=0.475 m. int num_species = 2; double AMU = 2.01410177811; - double mi = mp*AMU; // Deuterium ions. - double Te0 = 100*eV; // Ion reference temperature [J]. - double Ti0 = 100*eV; // Electron reference temperature [J]. - double n0 = 2.0e19; // Reference density [1/m^3]. + double mi = mp * AMU; // Deuterium ions. + double Te0 = 100 * eV; // Ion reference temperature [J]. + double Ti0 = 100 * eV; // Electron reference temperature [J]. + double n0 = 2.0e19; // Reference density [1/m^3]. double Bref = 1.129; // Reference magnetic field [T]. - double vte = sqrt(Te0/me), vti = sqrt(Ti0/mi); - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; + double vte = sqrt(Te0 / me), vti = sqrt(Ti0 / mi); + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; - // Configuration domain parameters - double Lx = Rmid_max-Rmid_min; // Domain size along x. + // Configuration domain parameters + double Lx = Rmid_max - Rmid_min; // Domain size along x. double x_min = 0.; double x_max = Lx; double x_LCFS = R_LCFSmid - Rmid_min; // Radial location of the last closed flux surface. double q0 = qprofile(R0); // Safety factor in the center of domain. - double Cy = r0/q0; // Normalization in binormal coordinate. + double Cy = r0 / q0; // Normalization in binormal coordinate. - double Ly = 150*rho_s; // Domain size along y. + double Ly = 150 * rho_s; // Domain size along y. // Adjust the domain size along y to have integer toroidal mode number. // We need: 2*pi*Cy/Ly = integer. - Ly = 2.*M_PI*Cy/round(2.*M_PI*Cy/Ly); - double y_min = -Ly/2.; - double y_max = Ly/2.; + Ly = 2. * M_PI * Cy / round(2. * M_PI * Cy / Ly); + double y_min = -Ly / 2.; + double y_max = Ly / 2.; - double Lz = 2.*M_PI-1e-10; // Domain size along magnetic field. - double z_min = -Lz/2.; - double z_max = Lz/2.; + double Lz = 2. * M_PI - 1e-10; // Domain size along magnetic field. + double z_min = -Lz / 2.; + double z_max = Lz / 2.; // Collision frequencies double nuFrac = 0.1; // Electron-electron collision freq. - double logLambdaElc = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuElc = nuFrac * logLambdaElc * pow(eV, 4) * n0 / - (6*sqrt(2.) * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(me) * pow(Te0,3./2.)); + (6 * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(me) * pow(Te0, 3. / 2.)); // Ion-ion collision freq. - double logLambdaIon = 6.6 - 0.5 * log(n0/1e20) + 1.5 * log(Ti0/eV); + double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuIon = nuFrac * logLambdaIon * pow(eV, 4) * n0 / - (12 * pow(M_PI,3./2.) * pow(eps0,2) * sqrt(mi) * pow(Ti0,3./2.)); + (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2) * sqrt(mi) * pow(Ti0, 3. / 2.)); // Source parameters int num_sources = 2; double P_exp = 0.34e6; // P_sol measured [W] - double vol_frac = 1.0/(2.*M_PI*Cy/Ly); // Volume fraction of the simulation box (=0.5 here). - double P_inj = P_exp * vol_frac / num_species; // Injection power normalized to the volume fraction and per species [W] + double vol_frac = + 1.0 / (2. * M_PI * Cy / Ly); // Volume fraction of the simulation box (=0.5 here). + double P_inj = + P_exp * vol_frac / + num_species; // Injection power normalized to the volume fraction and per species [W] // Core source: // - Injects energy only in the core region (0.25MW per species). // - The particles injection is only the one that are lost through the inner radial boundary. - bool adapt_energy_srcCORE = true; // The source will compensate the losses in energy according to given boundaries. - bool adapt_particle_srcCORE = true; // The source will compensate the losses in particle according to given boundaries. + bool adapt_energy_srcCORE = + true; // The source will compensate the losses in energy according to given boundaries. + bool adapt_particle_srcCORE = + true; // The source will compensate the losses in particle according to given boundaries. double energy_srcCORE = P_inj; // What the source must inject in energy [W] double particle_srcCORE = 0.0; // What the source must inject in particle [1/s] - double center_srcCORE[3] = {x_min, 0.0, -Lz/4}; // This is the position of the ion source, - double sigma_srcCORE[3] = {0.03*Lx, 0.0, Lz/6}; // the electron source will be at +Lz/2. + double center_srcCORE[3] = {x_min, 0.0, -Lz / 4}; // This is the position of the ion source, + double sigma_srcCORE[3] = {0.03 * Lx, 0.0, Lz / 6}; // the electron source will be at +Lz/2. double floor_srcCORE = 1e-10; // Recycling source: // - Reinjects particles that are absorbed by the wall. @@ -434,26 +450,27 @@ struct gk_app_ctx create_ctx(void) bool adapt_particle_srcRECY = true; double energy_srcRECY = 0.0; // [W] double particle_srcRECY = 0.0; // [1/s] - double center_srcRECY[3] = {0.5*x_LCFS, 0.0, M_PI}; - double sigma_srcRECY[3] = {0.25*x_LCFS, 0.0, 0.05*Lz}; + double center_srcRECY[3] = {0.5 * x_LCFS, 0.0, M_PI}; + double sigma_srcRECY[3] = {0.25 * x_LCFS, 0.0, 0.05 * Lz}; double floor_srcRECY = 1e-10; // Grid parameters (reduced resolution for the regression test, minimal recommended values in comments) - int Nx = 24; // (24) The LCFS is positionned at 1/3 of the domain -> the resolution must be divisible by 3. + int Nx = + 24; // (24) The LCFS is positionned at 1/3 of the domain -> the resolution must be divisible by 3. int Ny = 4; // (16) int Nz = 8; // (12) int Nvpar = 8; // (12) int Nmu = 4; // (8) int poly_order = 1; // Velocity box dimensions - double vpar_max_elc = 5.*vte; - double mu_max_elc = 1.*me*pow(4*vte,2)/(2*B0); - double vpar_max_ion = 5.*vti; - double mu_max_ion = 1.*mi*pow(4*vti,2)/(2*B0); + double vpar_max_elc = 5. * vte; + double mu_max_elc = 1. * me * pow(4 * vte, 2) / (2 * B0); + double vpar_max_ion = 5. * vti; + double mu_max_ion = 1. * mi * pow(4 * vti, 2) / (2 * B0); double t_end = 1.e-7; int num_frames = 1; double write_phase_freq = 1.0; - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-3; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -474,28 +491,39 @@ struct gk_app_ctx create_ctx(void) .Lx = Lx, .Ly = Ly, .Lz = Lz, - .x_min = x_min, .x_max = x_max, - .y_min = y_min, .y_max = y_max, - .z_min = z_min, .z_max = z_max, + .x_min = x_min, + .x_max = x_max, + .y_min = y_min, + .y_max = y_max, + .z_min = z_min, + .z_max = z_max, .Bref = Bref, .x_LCFS = x_LCFS, .num_species = num_species, - .me = me, .qe = qe, - .mi = mi, .qi = qi, - .n0 = n0, .Te0 = Te0, .Ti0 = Ti0, - .nuFrac = nuFrac, .nuElc = nuElc, .nuIon = nuIon, + .me = me, + .qe = qe, + .mi = mi, + .qi = qi, + .n0 = n0, + .Te0 = Te0, + .Ti0 = Ti0, + .nuFrac = nuFrac, + .nuElc = nuElc, + .nuIon = nuIon, .num_sources = num_sources, .adapt_energy_srcCORE = adapt_energy_srcCORE, .adapt_particle_srcCORE = adapt_particle_srcCORE, .center_srcCORE = {center_srcCORE[0], center_srcCORE[1], center_srcCORE[2]}, .sigma_srcCORE = {sigma_srcCORE[0], sigma_srcCORE[1], sigma_srcCORE[2]}, - .energy_srcCORE = energy_srcCORE, .particle_srcCORE = particle_srcCORE, + .energy_srcCORE = energy_srcCORE, + .particle_srcCORE = particle_srcCORE, .floor_srcCORE = floor_srcCORE, .adapt_energy_srcRECY = adapt_energy_srcRECY, .adapt_particle_srcRECY = adapt_particle_srcRECY, .center_srcRECY = {center_srcRECY[0], center_srcRECY[1], center_srcRECY[2]}, .sigma_srcRECY = {sigma_srcRECY[0], sigma_srcRECY[1], sigma_srcRECY[2]}, - .energy_srcRECY = energy_srcRECY, .particle_srcRECY = particle_srcRECY, + .energy_srcRECY = energy_srcRECY, + .particle_srcRECY = particle_srcRECY, .floor_srcRECY = floor_srcRECY, .Nx = Nx, .Ny = Ny, @@ -504,27 +532,30 @@ struct gk_app_ctx create_ctx(void) .Nmu = Nmu, .cells = {Nx, Ny, Nz, Nvpar, Nmu}, .poly_order = poly_order, - .vpar_max_elc = vpar_max_elc, .mu_max_elc = mu_max_elc, - .vpar_max_ion = vpar_max_ion, .mu_max_ion = mu_max_ion, + .vpar_max_elc = vpar_max_elc, + .mu_max_elc = mu_max_elc, + .vpar_max_ion = vpar_max_ion, + .mu_max_ion = mu_max_ion, .write_phase_freq = write_phase_freq, - .t_end = t_end, .num_frames = num_frames, + .t_end = t_end, + .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Init(&argc, &argv); + } #endif - + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); @@ -533,10 +564,12 @@ main(int argc, char **argv) struct gk_app_ctx ctx = create_ctx(); // context for init functions int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters @@ -87,16 +86,17 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; - // -- Source functions. -void -eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; @@ -104,43 +104,42 @@ eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcElc; double sigSrc = app->sigSrcElc; double NSrcFloor = app->NSrcFloorElc; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double sigSrc = app->sigSrcElc; double TSrc0 = app->TSrc0Elc; double Tfloor = app->TSrcFloorElc; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; @@ -148,185 +147,165 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Electrons initial conditions -void -eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0*exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Te_par0 = app->Te_par0; double Te_par_m = app->Te_par_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_par_m+(Te_par0-Te_par_m)*tanh(4 * fabs(z_m - fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_par_m + (Te_par0 - Te_par_m) * tanh(4 * fabs(z_m - fabs(z))); + } else { fout[0] = Te_par_m; } } -void -eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Te_perp0 = app->Te_perp0; double Te_perp_m = app->Te_perp_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_perp_m - Te_perp0*tanh(3.*fabs(z_m-fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_perp_m - Te_perp0 * tanh(3. * fabs(z_m - fabs(z))); + } else { fout[0] = Te_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0* exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Ti_par0 = app->Ti_par0; double Ti_par_m = app->Ti_par_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_par_m + (Ti_par0 - Ti_par_m) * tanh(4 * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_par_m * GKYL_MAX2(1.e-2, 4 * log(fabs(fabs(z) - z_m) + 1)); } } -void -eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Ti_perp0 = app->Ti_perp0; double Ti_perp_m = app->Ti_perp_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_perp_m + (Ti_perp0 - Ti_perp_m) * tanh(3. * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -334,20 +313,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./3.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 3.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_ion*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_ion*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_ion * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_ion * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -355,21 +333,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./6.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 6.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_elc*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_elc*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_elc * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_elc * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -379,7 +355,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -395,8 +371,9 @@ create_ctx(void) double nuFrac = 1.0; // Electron-electron collision freq. double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); - double nuElc = nuFrac * logLambdaElc * pow(eV, 4.) * n0 / - (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); + double nuElc = + nuFrac * logLambdaElc * pow(eV, 4.) * n0 / + (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); // Ion-ion collision freq. double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); double nuIon = nuFrac * logLambdaIon * pow(eV, 4.) * n0 / @@ -418,7 +395,7 @@ create_ctx(void) // Axial coordinate Z extents. Endure that Z=0 is not on // the boundary of a cell (due to AD errors). double z_min = -2.0; - double z_max = 2.0; + double z_max = 2.0; double psi_eval = 2.5e-3; double z_m = 1.0; @@ -461,13 +438,14 @@ create_ctx(void) double mu_max_ion = mi * pow(3. * vti, 2.) / (2. * B_p); int Nz = 32; int Nvpar = 8; // Number of cells in the paralell velocity direction 96 - int Nmu = 8; // Number of cells in the mu direction 192 + int Nmu = 8; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 1e-8; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -537,18 +515,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -559,10 +538,12 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters @@ -89,16 +88,17 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; - // -- Source functions. -void -eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; @@ -106,43 +106,42 @@ eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcElc; double sigSrc = app->sigSrcElc; double NSrcFloor = app->NSrcFloorElc; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double sigSrc = app->sigSrcElc; double TSrc0 = app->TSrc0Elc; double Tfloor = app->TSrcFloorElc; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; @@ -150,214 +149,190 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Electrons initial conditions -void -eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0*exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Te_par0 = app->Te_par0; double Te_par_m = app->Te_par_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_par_m+(Te_par0-Te_par_m)*tanh(4 * fabs(z_m - fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_par_m + (Te_par0 - Te_par_m) * tanh(4 * fabs(z_m - fabs(z))); + } else { fout[0] = Te_par_m; } } -void -eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Te_perp0 = app->Te_perp0; double Te_perp_m = app->Te_perp_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_perp_m - Te_perp0*tanh(3.*fabs(z_m-fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_perp_m - Te_perp0 * tanh(3. * fabs(z_m - fabs(z))); + } else { fout[0] = Te_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0* exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Ti_par0 = app->Ti_par0; double Ti_par_m = app->Ti_par_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_par_m + (Ti_par0 - Ti_par_m) * tanh(4 * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_par_m * GKYL_MAX2(1.e-2, 4 * log(fabs(fabs(z) - z_m) + 1)); } } -void -eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Ti_perp0 = app->Ti_perp0; double Ti_perp_m = app->Ti_perp_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_perp_m + (Ti_perp0 - Ti_perp_m) * tanh(3. * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Evaluate collision frequencies -void -evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElcIon; } -void -evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIonElc; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -365,20 +340,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./3.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 3.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_ion*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_ion*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_ion * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_ion * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -386,21 +360,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./6.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 6.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_elc*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_elc*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_elc * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_elc * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -410,7 +382,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -427,12 +399,13 @@ create_ctx(void) double nuFrac = 1.0; double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); - double nuElc = nuFrac * logLambdaElc * pow(eV, 4.) * n0 / - (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); + double nuElc = + nuFrac * logLambdaElc * pow(eV, 4.) * n0 / + (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); double nuIon = nuFrac * logLambdaIon * pow(eV, 4.) * n0 / (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti0, 3. / 2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); // Thermal speeds. double vti = sqrt(Ti0 / mi); @@ -450,7 +423,7 @@ create_ctx(void) // Axial coordinate Z extents. Endure that Z=0 is not on // the boundary of a cell (due to AD errors). double z_min = -2.0; - double z_max = 2.0; + double z_max = 2.0; double psi_eval = 2.5e-3; double z_m = 1; @@ -475,7 +448,7 @@ create_ctx(void) double Ti_par0 = 7500 * eV; double Ti_par_m = 1000 * eV; - double Te_par0 = 1800 * eV; + double Te_par0 = 1800 * eV; double Te_par_m = 300 * eV; double Te_perp0 = 2000 * eV; double Te_perp_m = 3000 * eV; @@ -486,7 +459,6 @@ create_ctx(void) double Ti_m = 3081.437703 * eV; double cs_m = 4.037740e5; - // Grid parameters double vpar_max_elc = 20 * vte; double mu_max_elc = me * pow(3. * vte, 2.) / (2. * B_p); @@ -494,13 +466,14 @@ create_ctx(void) double mu_max_ion = mi * pow(3. * vti, 2.) / (2. * B_p); int Nz = 128; int Nvpar = 32; // Number of cells in the paralell velocity direction 96 - int Nmu = 32; // Number of cells in the mu direction 192 + int Nmu = 32; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 4.0e-9; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -529,7 +502,7 @@ create_ctx(void) .c_s = c_s, .omega_ci = omega_ci, .rho_s = rho_s, - .kperp = kperp, + .kperp = kperp, .z_min = z_min, .z_max = z_max, .psi_eval = psi_eval, @@ -572,18 +545,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -594,10 +568,12 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d #include #include - + #include // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters double mi; @@ -90,15 +89,17 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; // -- Source functions. -void -eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; @@ -106,43 +107,42 @@ eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcElc; double sigSrc = app->sigSrcElc; double NSrcFloor = app->NSrcFloorElc; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double sigSrc = app->sigSrcElc; double TSrc0 = app->TSrc0Elc; double Tfloor = app->TSrcFloorElc; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; @@ -150,214 +150,190 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Electrons initial conditions -void -eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0*exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Te_par0 = app->Te_par0; double Te_par_m = app->Te_par_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_par_m+(Te_par0-Te_par_m)*tanh(4 * fabs(z_m - fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_par_m + (Te_par0 - Te_par_m) * tanh(4 * fabs(z_m - fabs(z))); + } else { fout[0] = Te_par_m; } } -void -eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Te_perp0 = app->Te_perp0; double Te_perp_m = app->Te_perp_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_perp_m - Te_perp0*tanh(3.*fabs(z_m-fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_perp_m - Te_perp0 * tanh(3. * fabs(z_m - fabs(z))); + } else { fout[0] = Te_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0* exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Ti_par0 = app->Ti_par0; double Ti_par_m = app->Ti_par_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_par_m + (Ti_par0 - Ti_par_m) * tanh(4 * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_par_m * GKYL_MAX2(1.e-2, 4 * log(fabs(fabs(z) - z_m) + 1)); } } -void -eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Ti_perp0 = app->Ti_perp0; double Ti_perp_m = app->Ti_perp_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_perp_m + (Ti_perp0 - Ti_perp_m) * tanh(3. * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Evaluate collision frequencies -void -evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElcIon; } -void -evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIonElc; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -365,20 +341,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./3.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 3.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_ion*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_ion*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_ion * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_ion * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -386,21 +361,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./6.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 6.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_elc*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_elc*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_elc * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_elc * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -410,7 +383,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -427,12 +400,13 @@ create_ctx(void) double nuFrac = 1.0; double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); - double nuElc = nuFrac * logLambdaElc * pow(eV, 4.) * n0 / - (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); + double nuElc = + nuFrac * logLambdaElc * pow(eV, 4.) * n0 / + (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); double nuIon = nuFrac * logLambdaIon * pow(eV, 4.) * n0 / (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti0, 3. / 2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); // Thermal speeds. double vti = sqrt(Ti0 / mi); @@ -448,7 +422,7 @@ create_ctx(void) // Geometry parameters. double z_min = -2.0; - double z_max = 2.0; + double z_max = 2.0; double z_m = 1.0; double psi_min = 1e-6; double psi_max = 3e-3; @@ -474,7 +448,7 @@ create_ctx(void) double Ti_par0 = 7500 * eV; double Ti_par_m = 1000 * eV; - double Te_par0 = 1800 * eV; + double Te_par0 = 1800 * eV; double Te_par_m = 300 * eV; double Te_perp0 = 2000 * eV; double Te_perp_m = 3000 * eV; @@ -493,13 +467,14 @@ create_ctx(void) int Nx = 8; int Nz = 32; int Nvpar = 32; // Number of cells in the paralell velocity direction 96 - int Nmu = 32; // Number of cells in the mu direction 192 + int Nmu = 32; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 1.5e-10; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -528,7 +503,7 @@ create_ctx(void) .c_s = c_s, .omega_ci = omega_ci, .rho_s = rho_s, - .kperp = kperp, + .kperp = kperp, .z_min = z_min, .z_max = z_max, .z_m = z_m, @@ -571,7 +546,7 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } @@ -581,7 +556,9 @@ int main(int argc, char **argv) struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -592,25 +569,27 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters double mi; @@ -89,15 +88,17 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; // -- Source functions. -void -eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -106,25 +107,26 @@ eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcElc; double sigSrc = app->sigSrcElc; double NSrcFloor = app->NSrcFloorElc; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -132,18 +134,16 @@ eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcElc; double TSrc0 = app->TSrc0Elc; double Tfloor = app->TSrcFloorElc; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -152,25 +152,26 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -178,57 +179,47 @@ eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Potential initial condition -void -eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[1]; double z_m = app->z_m; - double sigma = 0.9*z_m; + double sigma = 0.9 * z_m; double center_potential = 5.0 * app->Te0 / app->qi; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*center_potential*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { + if (fabs(z) <= sigma) { + fout[0] = 0.5 * center_potential * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { fout[0] = 0.0; } } // Electrons initial conditions -void -eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[1]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0*exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -236,18 +227,17 @@ eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -255,18 +245,16 @@ eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Te_par0 = app->Te_par0; double Te_par_m = app->Te_par_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_par_m+(Te_par0-Te_par_m)*tanh(4 * fabs(z_m - fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_par_m + (Te_par0 - Te_par_m) * tanh(4 * fabs(z_m - fabs(z))); + } else { fout[0] = Te_par_m; } } -void -eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -274,37 +262,31 @@ eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Te_perp0 = app->Te_perp0; double Te_perp_m = app->Te_perp_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_perp_m - Te_perp0*tanh(3.*fabs(z_m-fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_perp_m - Te_perp0 * tanh(3. * fabs(z_m - fabs(z))); + } else { fout[0] = Te_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[1]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0* exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -312,17 +294,16 @@ eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -330,18 +311,16 @@ eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Ti_par0 = app->Ti_par0; double Ti_par_m = app->Ti_par_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_par_m + (Ti_par0 - Ti_par_m) * tanh(4 * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_par_m * GKYL_MAX2(1.e-2, 4 * log(fabs(fabs(z) - z_m) + 1)); } } -void -eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -349,46 +328,39 @@ eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Ti_perp0 = app->Ti_perp0; double Ti_perp_m = app->Ti_perp_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_perp_m + (Ti_perp0 - Ti_perp_m) * tanh(3. * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Evaluate collision frequencies -void -evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElcIon; } -void -evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIonElc; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -396,20 +368,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./3.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 3.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_ion*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_ion*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_ion * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_ion * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -417,21 +388,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./6.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 6.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_elc*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_elc*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_elc * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_elc * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -441,7 +410,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -458,12 +427,13 @@ create_ctx(void) double nuFrac = 1.0; double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); - double nuElc = nuFrac * logLambdaElc * pow(eV, 4.) * n0 / - (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); + double nuElc = + nuFrac * logLambdaElc * pow(eV, 4.) * n0 / + (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); double nuIon = nuFrac * logLambdaIon * pow(eV, 4.) * n0 / (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti0, 3. / 2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); // Thermal speeds. double vti = sqrt(Ti0 / mi); @@ -479,7 +449,7 @@ create_ctx(void) // Geometry parameters. double z_min = -2.0; - double z_max = 2.0; + double z_max = 2.0; double z_m = 1.0; double psi_min = 1e-6; double psi_max = 3e-3; @@ -504,7 +474,7 @@ create_ctx(void) double Ti_par0 = 7500 * eV; double Ti_par_m = 1000 * eV; - double Te_par0 = 1800 * eV; + double Te_par0 = 1800 * eV; double Te_par_m = 300 * eV; double Te_perp0 = 2000 * eV; double Te_perp_m = 3000 * eV; @@ -523,13 +493,14 @@ create_ctx(void) int Nx = 8; int Nz = 32; int Nvpar = 32; // Number of cells in the paralell velocity direction 96 - int Nmu = 32; // Number of cells in the mu direction 192 + int Nmu = 32; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 1.5e-8; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -558,7 +529,7 @@ create_ctx(void) .c_s = c_s, .omega_ci = omega_ci, .rho_s = rho_s, - .kperp = kperp, + .kperp = kperp, .z_min = z_min, .z_max = z_max, .z_m = z_m, @@ -600,18 +571,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -622,24 +594,26 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters @@ -90,15 +89,17 @@ struct gk_mirror_ctx int poly_order; double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; // -- Source functions. -void -eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -107,25 +108,26 @@ eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcElc; double sigSrc = app->sigSrcElc; double NSrcFloor = app->NSrcFloorElc; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -133,18 +135,16 @@ eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcElc; double TSrc0 = app->TSrc0Elc; double Tfloor = app->TSrcFloorElc; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -153,25 +153,26 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -179,57 +180,47 @@ eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Potential initial condition -void -eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[1]; double z_m = app->z_m; - double sigma = 0.9*z_m; + double sigma = 0.9 * z_m; double center_potential = 5.0 * app->Te0 / app->qi; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*center_potential*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { + if (fabs(z) <= sigma) { + fout[0] = 0.5 * center_potential * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { fout[0] = 0.0; } } // Electrons initial conditions -void -eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[1]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0*exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -237,18 +228,17 @@ eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -256,18 +246,16 @@ eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Te_par0 = app->Te_par0; double Te_par_m = app->Te_par_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_par_m+(Te_par0-Te_par_m)*tanh(4 * fabs(z_m - fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_par_m + (Te_par0 - Te_par_m) * tanh(4 * fabs(z_m - fabs(z))); + } else { fout[0] = Te_par_m; } } -void -eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -275,37 +263,31 @@ eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Te_perp0 = app->Te_perp0; double Te_perp_m = app->Te_perp_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_perp_m - Te_perp0*tanh(3.*fabs(z_m-fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_perp_m - Te_perp0 * tanh(3. * fabs(z_m - fabs(z))); + } else { fout[0] = Te_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[1]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0* exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -313,17 +295,16 @@ eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -331,18 +312,16 @@ eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Ti_par0 = app->Ti_par0; double Ti_par_m = app->Ti_par_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_par_m + (Ti_par0 - Ti_par_m) * tanh(4 * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_par_m * GKYL_MAX2(1.e-2, 4 * log(fabs(fabs(z) - z_m) + 1)); } } -void -eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -350,46 +329,39 @@ eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Ti_perp0 = app->Ti_perp0; double Ti_perp_m = app->Ti_perp_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_perp_m + (Ti_perp0 - Ti_perp_m) * tanh(3. * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Evaluate collision frequencies -void -evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElcIon; } -void -evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIonElc; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -397,20 +369,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./3.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 3.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_ion*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_ion*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_ion * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_ion * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -418,21 +389,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./6.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 6.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_elc*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_elc*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_elc * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_elc * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -442,7 +411,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -459,12 +428,13 @@ create_ctx(void) double nuFrac = 1.0; double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); - double nuElc = nuFrac * logLambdaElc * pow(eV, 4.) * n0 / - (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); + double nuElc = + nuFrac * logLambdaElc * pow(eV, 4.) * n0 / + (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); double nuIon = nuFrac * logLambdaIon * pow(eV, 4.) * n0 / (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti0, 3. / 2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); // Thermal speeds. double vti = sqrt(Ti0 / mi); @@ -480,7 +450,7 @@ create_ctx(void) // Geometry parameters. double z_min = -2.0; - double z_max = 2.0; + double z_max = 2.0; double z_m = 0.982544; double psi_min = 1e-5; double psi_max = 1e-3; @@ -505,7 +475,7 @@ create_ctx(void) double Ti_par0 = 7500 * eV; double Ti_par_m = 1000 * eV; - double Te_par0 = 1800 * eV; + double Te_par0 = 1800 * eV; double Te_par_m = 300 * eV; double Te_perp0 = 2000 * eV; double Te_perp_m = 3000 * eV; @@ -525,13 +495,14 @@ create_ctx(void) int Ny = 4; int Nz = 16; int Nvpar = 16; // Number of cells in the paralell velocity direction 96 - int Nmu = 16; // Number of cells in the mu direction 192 + int Nmu = 16; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 1.5e-10; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -560,7 +531,7 @@ create_ctx(void) .c_s = c_s, .omega_ci = omega_ci, .rho_s = rho_s, - .kperp = kperp, + .kperp = kperp, .z_min = z_min, .z_max = z_max, .z_m = z_m, @@ -603,26 +574,27 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } // Run the 2D simulation that generates the initial conditions. -static void -run_2x_sim(struct gk_mirror_ctx ctx, const struct gkyl_app_args app_args, - int *cells_x, int *cells_v, struct gkyl_comm *comm) +static void run_2x_sim( + struct gk_mirror_ctx ctx, const struct gkyl_app_args app_args, int *cells_x, int *cells_v, + struct gkyl_comm *comm +) { struct gkyl_gyrokinetic_projection elc_ic = { - .proj_id = GKYL_PROJ_BIMAXWELLIAN, + .proj_id = GKYL_PROJ_BIMAXWELLIAN, .ctx_density = &ctx, .density = eval_density_elc, .ctx_upar = &ctx, - .upar= eval_upar_elc, + .upar = eval_upar_elc, .ctx_temppar = &ctx, - .temppar = eval_temp_par_elc, + .temppar = eval_temp_par_elc, .ctx_tempperp = &ctx, - .tempperp = eval_temp_perp_elc, + .tempperp = eval_temp_perp_elc }; struct gkyl_gyrokinetic_species elc = { @@ -631,69 +603,68 @@ run_2x_sim(struct gk_mirror_ctx ctx, const struct gkyl_app_args app_args, .mass = ctx.me, .vdim = ctx.vdim, .lower = {-1.0, 0.0}, - .upper = { 1.0, 1.0}, - .cells = { cells_v[0], cells_v[1] }, + .upper = {1.0, 1.0}, + .cells = {cells_v[0], cells_v[1]}, .polarization_density = ctx.n0, - .mapc2p = { - .mapping = mapc2p_vel_elc, - .ctx = &ctx, - }, + .mapc2p = {.mapping = mapc2p_vel_elc, .ctx = &ctx}, .projection = elc_ic, - .collisionless = { - .type = GKYL_GK_COLLISIONLESS_ES, - }, - - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNuElc, - .self_nu_ctx = &ctx, - .num_cross_collisions = 1, - .collide_with = { "ion" }, - .cross_nu = { evalNuElcIon, }, - .cross_nu_ctx = &ctx, - .den_ref = ctx.n0, - .temp_ref = ctx.Te0, - }, - - .source = { - .source_id = GKYL_PROJ_SOURCE, - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_MAXWELLIAN_PRIM, - .ctx_density = &ctx, - .density = eval_density_elc_source, - .ctx_upar = &ctx, - .upar= eval_upar_elc_source, - .ctx_temp = &ctx, - .temp = eval_temp_elc_source, - }, - }, - - .bcs = { - { .dir = 0, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, .projection = elc_ic, }, - { .dir = 0, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, .projection = elc_ic, }, - { .dir = 1, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH }, - { .dir = 1, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH }, - }, + .collisionless = {.type = GKYL_GK_COLLISIONLESS_ES}, + + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, + .self_nu = evalNuElc, + .self_nu_ctx = &ctx, + .num_cross_collisions = 1, + .collide_with = {"ion"}, + .cross_nu = {evalNuElcIon}, + .cross_nu_ctx = &ctx, + .den_ref = ctx.n0, + .temp_ref = ctx.Te0}, + + .source = + {.source_id = GKYL_PROJ_SOURCE, + .num_sources = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_MAXWELLIAN_PRIM, + .ctx_density = &ctx, + .density = eval_density_elc_source, + .ctx_upar = &ctx, + .upar = eval_upar_elc_source, + .ctx_temp = &ctx, + .temp = eval_temp_elc_source}}, + + .bcs = + {{.dir = 0, + .edge = GKYL_LOWER_EDGE, + .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, + .projection = elc_ic}, + {.dir = 0, + .edge = GKYL_UPPER_EDGE, + .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, + .projection = elc_ic}, + {.dir = 1, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH}, + {.dir = 1, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH}}, .num_diag_moments = 8, - .diag_moments = {GKYL_F_MOMENT_BIMAXWELLIAN, GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2, GKYL_F_MOMENT_M2PAR, GKYL_F_MOMENT_M2PERP, GKYL_F_MOMENT_M3PAR, GKYL_F_MOMENT_M3PERP }, + .diag_moments = + {GKYL_F_MOMENT_BIMAXWELLIAN, GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2, + GKYL_F_MOMENT_M2PAR, GKYL_F_MOMENT_M2PERP, GKYL_F_MOMENT_M3PAR, GKYL_F_MOMENT_M3PERP} }; struct gkyl_gyrokinetic_projection ion_ic = { - .proj_id = GKYL_PROJ_BIMAXWELLIAN, + .proj_id = GKYL_PROJ_BIMAXWELLIAN, .ctx_density = &ctx, .density = eval_density_ion, .ctx_upar = &ctx, - .upar= eval_upar_ion, + .upar = eval_upar_ion, .ctx_temppar = &ctx, - .temppar = eval_temp_par_ion, + .temppar = eval_temp_par_ion, .ctx_tempperp = &ctx, - .tempperp = eval_temp_perp_ion, + .tempperp = eval_temp_perp_ion }; struct gkyl_gyrokinetic_species ion = { @@ -702,96 +673,89 @@ run_2x_sim(struct gk_mirror_ctx ctx, const struct gkyl_app_args app_args, .mass = ctx.mi, .vdim = ctx.vdim, .lower = {-1.0, 0.0}, - .upper = { 1.0, 1.0}, - .cells = { cells_v[0], cells_v[1] }, + .upper = {1.0, 1.0}, + .cells = {cells_v[0], cells_v[1]}, .polarization_density = ctx.n0, - .mapc2p = { - .mapping = mapc2p_vel_ion, - .ctx = &ctx, - }, + .mapc2p = {.mapping = mapc2p_vel_ion, .ctx = &ctx}, .projection = ion_ic, .scale_with_polarization = true, - .collisionless = { - .type = GKYL_GK_COLLISIONLESS_ES, - }, - - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNuIon, - .self_nu_ctx = &ctx, - .num_cross_collisions = 1, - .collide_with = { "elc" }, - .cross_nu = { evalNuIonElc, }, - .cross_nu_ctx = &ctx, - .den_ref = ctx.n0, - .temp_ref = ctx.Ti0, - }, - - .source = { - .source_id = GKYL_PROJ_SOURCE, - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_MAXWELLIAN_PRIM, - .ctx_density = &ctx, - .density = eval_density_ion_source, - .ctx_upar = &ctx, - .upar= eval_upar_ion_source, - .ctx_temp = &ctx, - .temp = eval_temp_ion_source, - }, - }, - - .bcs = { - { .dir = 0, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, .projection = ion_ic, }, - { .dir = 0, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, .projection = ion_ic, }, - { .dir = 1, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH }, - { .dir = 1, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH }, - }, + .collisionless = {.type = GKYL_GK_COLLISIONLESS_ES}, + + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, + .self_nu = evalNuIon, + .self_nu_ctx = &ctx, + .num_cross_collisions = 1, + .collide_with = {"elc"}, + .cross_nu = {evalNuIonElc}, + .cross_nu_ctx = &ctx, + .den_ref = ctx.n0, + .temp_ref = ctx.Ti0}, + + .source = + {.source_id = GKYL_PROJ_SOURCE, + .num_sources = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_MAXWELLIAN_PRIM, + .ctx_density = &ctx, + .density = eval_density_ion_source, + .ctx_upar = &ctx, + .upar = eval_upar_ion_source, + .ctx_temp = &ctx, + .temp = eval_temp_ion_source}}, + + .bcs = + {{.dir = 0, + .edge = GKYL_LOWER_EDGE, + .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, + .projection = ion_ic}, + {.dir = 0, + .edge = GKYL_UPPER_EDGE, + .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, + .projection = ion_ic}, + {.dir = 1, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH}, + {.dir = 1, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH}}, .num_diag_moments = 8, - .diag_moments = {GKYL_F_MOMENT_BIMAXWELLIAN, GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2, GKYL_F_MOMENT_M2PAR, GKYL_F_MOMENT_M2PERP, GKYL_F_MOMENT_M3PAR, GKYL_F_MOMENT_M3PERP }, + .diag_moments = + {GKYL_F_MOMENT_BIMAXWELLIAN, GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2, + GKYL_F_MOMENT_M2PAR, GKYL_F_MOMENT_M2PERP, GKYL_F_MOMENT_M3PAR, GKYL_F_MOMENT_M3PERP} }; - struct gkyl_gyrokinetic_field field = - { + struct gkyl_gyrokinetic_field field = { .polarization_bmag = ctx.B_p, - .poisson_bcs = { - { .dir = 0, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_FIELD_NEUMANN, .value = {0.0} }, - { .dir = 0, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_FIELD_DIRICHLET, .value = {0.0} }, - }, + .poisson_bcs = + {{.dir = 0, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_FIELD_NEUMANN, .value = {0.0}}, + {.dir = 0, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_FIELD_DIRICHLET, .value = {0.0}}}, .polarization_potential = eval_potential, - .polarization_potential_ctx = &ctx, + .polarization_potential_ctx = &ctx }; - + struct gkyl_mirror_geo_grid_inp grid_inp = { .filename_psi = "gyrokinetic/data/unit/wham_hires.geqdsk_psi.gkyl", // psi file to use .rclose = 0.2, // closest R to region of interest - .zmin = -2.0, // Z of lower boundary - .zmax = 2.0, // Z of upper boundary + .zmin = -2.0, // Z of lower boundary + .zmax = 2.0, // Z of upper boundary .include_axis = false, // Include R=0 axis in grid - .fl_coord = GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z, // coordinate system for psi grid + .fl_coord = GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z // coordinate system for psi grid }; // GK app struct gkyl_gk app_inp = { .name = "gk_wham_2x2v_p1", - .cdim = ctx.cdim-1, + .cdim = ctx.cdim - 1, .lower = {ctx.psi_min, ctx.z_min}, .upper = {ctx.psi_max, ctx.z_max}, - .cells = { cells_x[0], cells_x[2] }, + .cells = {cells_x[0], cells_x[2]}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, - .geometry = { - .geometry_id = GKYL_GEOMETRY_MIRROR, - .world = {0.0}, - .mirror_grid_info = grid_inp, - }, + .geometry = {.geometry_id = GKYL_GEOMETRY_MIRROR, .world = {0.0}, .mirror_grid_info = grid_inp}, .num_periodic_dir = 0, .periodic_dirs = {}, @@ -801,59 +765,56 @@ run_2x_sim(struct gk_mirror_ctx ctx, const struct gkyl_app_args app_args, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; struct gkyl_gyrokinetic_run_inp run_inp_2x = { .app_inp = app_inp, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = 1, - } + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = 1} }; gkyl_gyrokinetic_run_simulation(&run_inp_2x); } // Run the 3D simulation using the final frame of the 2D sim as IC. -static void -run_3x_sim(struct gk_mirror_ctx ctx, const struct gkyl_app_args app_args, - int *cells_x, int *cells_v, struct gkyl_comm *comm) +static void run_3x_sim( + struct gk_mirror_ctx ctx, const struct gkyl_app_args app_args, int *cells_x, int *cells_v, + struct gkyl_comm *comm +) { // Recreate projection ICs for use in boundary conditions. struct gkyl_gyrokinetic_projection elc_ic = { - .proj_id = GKYL_PROJ_BIMAXWELLIAN, + .proj_id = GKYL_PROJ_BIMAXWELLIAN, .ctx_density = &ctx, .density = eval_density_elc, .ctx_upar = &ctx, - .upar= eval_upar_elc, + .upar = eval_upar_elc, .ctx_temppar = &ctx, - .temppar = eval_temp_par_elc, + .temppar = eval_temp_par_elc, .ctx_tempperp = &ctx, - .tempperp = eval_temp_perp_elc, + .tempperp = eval_temp_perp_elc }; struct gkyl_gyrokinetic_projection ion_ic = { - .proj_id = GKYL_PROJ_BIMAXWELLIAN, + .proj_id = GKYL_PROJ_BIMAXWELLIAN, .ctx_density = &ctx, .density = eval_density_ion, .ctx_upar = &ctx, - .upar= eval_upar_ion, + .upar = eval_upar_ion, .ctx_temppar = &ctx, - .temppar = eval_temp_par_ion, + .temppar = eval_temp_par_ion, .ctx_tempperp = &ctx, - .tempperp = eval_temp_perp_ion, + .tempperp = eval_temp_perp_ion }; // ...................................................... // @@ -866,46 +827,44 @@ run_3x_sim(struct gk_mirror_ctx ctx, const struct gkyl_app_args app_args, .mass = ctx.me, .vdim = ctx.vdim, .lower = {-1.0, 0.0}, - .upper = { 1.0, 1.0}, - .cells = { cells_v[0], cells_v[1] }, + .upper = {1.0, 1.0}, + .cells = {cells_v[0], cells_v[1]}, .polarization_density = ctx.n0, - .mapc2p = { - .mapping = mapc2p_vel_elc, - .ctx = &ctx, - }, - - .init_from_file = { - .type = GKYL_IC_IMPORT_F, - .file_name = "gk_wham_2x2v_p1-elc_0.gkyl", - }, - - .collisionless = { - .type = GKYL_GK_COLLISIONLESS_ES, - }, - - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNuElc, - .self_nu_ctx = &ctx, - .num_cross_collisions = 1, - .collide_with = { "ion" }, - .cross_nu = { evalNuElcIon, }, - .cross_nu_ctx = &ctx, - .den_ref = ctx.n0, - .temp_ref = ctx.Te0, - }, - - .bcs = { - { .dir = 0, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, .projection = elc_ic, }, - { .dir = 0, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, .projection = elc_ic, }, - { .dir = 2, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH }, - { .dir = 2, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH }, - }, + .mapc2p = {.mapping = mapc2p_vel_elc, .ctx = &ctx}, + + .init_from_file = {.type = GKYL_IC_IMPORT_F, .file_name = "gk_wham_2x2v_p1-elc_0.gkyl"}, + + .collisionless = {.type = GKYL_GK_COLLISIONLESS_ES}, + + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, + .self_nu = evalNuElc, + .self_nu_ctx = &ctx, + .num_cross_collisions = 1, + .collide_with = {"ion"}, + .cross_nu = {evalNuElcIon}, + .cross_nu_ctx = &ctx, + .den_ref = ctx.n0, + .temp_ref = ctx.Te0}, + + .bcs = + {{.dir = 0, + .edge = GKYL_LOWER_EDGE, + .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, + .projection = elc_ic}, + {.dir = 0, + .edge = GKYL_UPPER_EDGE, + .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, + .projection = elc_ic}, + {.dir = 2, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH}, + {.dir = 2, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH}}, .num_diag_moments = 8, - .diag_moments = {GKYL_F_MOMENT_BIMAXWELLIAN, GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2, GKYL_F_MOMENT_M2PAR, GKYL_F_MOMENT_M2PERP, GKYL_F_MOMENT_M3PAR, GKYL_F_MOMENT_M3PERP }, + .diag_moments = + {GKYL_F_MOMENT_BIMAXWELLIAN, GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2, + GKYL_F_MOMENT_M2PAR, GKYL_F_MOMENT_M2PERP, GKYL_F_MOMENT_M3PAR, GKYL_F_MOMENT_M3PERP} }; struct gkyl_gyrokinetic_species ion3d = { @@ -914,57 +873,53 @@ run_3x_sim(struct gk_mirror_ctx ctx, const struct gkyl_app_args app_args, .mass = ctx.mi, .vdim = ctx.vdim, .lower = {-1.0, 0.0}, - .upper = { 1.0, 1.0}, - .cells = { cells_v[0], cells_v[1] }, + .upper = {1.0, 1.0}, + .cells = {cells_v[0], cells_v[1]}, .polarization_density = ctx.n0, - .mapc2p = { - .mapping = mapc2p_vel_ion, - .ctx = &ctx, - }, - - .init_from_file = { - .type = GKYL_IC_IMPORT_F, - .file_name = "gk_wham_2x2v_p1-ion_0.gkyl", - }, - - .collisionless = { - .type = GKYL_GK_COLLISIONLESS_ES, - }, - - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNuIon, - .self_nu_ctx = &ctx, - .num_cross_collisions = 1, - .collide_with = { "elc" }, - .cross_nu = { evalNuIonElc, }, - .cross_nu_ctx = &ctx, - .den_ref = ctx.n0, - .temp_ref = ctx.Ti0, - }, - - .bcs = { - { .dir = 0, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, .projection = ion_ic, }, - { .dir = 0, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, .projection = ion_ic, }, - { .dir = 2, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH }, - { .dir = 2, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH }, - }, + .mapc2p = {.mapping = mapc2p_vel_ion, .ctx = &ctx}, + + .init_from_file = {.type = GKYL_IC_IMPORT_F, .file_name = "gk_wham_2x2v_p1-ion_0.gkyl"}, + + .collisionless = {.type = GKYL_GK_COLLISIONLESS_ES}, + + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, + .self_nu = evalNuIon, + .self_nu_ctx = &ctx, + .num_cross_collisions = 1, + .collide_with = {"elc"}, + .cross_nu = {evalNuIonElc}, + .cross_nu_ctx = &ctx, + .den_ref = ctx.n0, + .temp_ref = ctx.Ti0}, + + .bcs = + {{.dir = 0, + .edge = GKYL_LOWER_EDGE, + .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, + .projection = ion_ic}, + {.dir = 0, + .edge = GKYL_UPPER_EDGE, + .type = GKYL_BC_GK_SPECIES_FIXED_FUNC, + .projection = ion_ic}, + {.dir = 2, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH}, + {.dir = 2, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_SPECIES_SHEATH}}, .num_diag_moments = 8, - .diag_moments = {GKYL_F_MOMENT_BIMAXWELLIAN, GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2, GKYL_F_MOMENT_M2PAR, GKYL_F_MOMENT_M2PERP, GKYL_F_MOMENT_M3PAR, GKYL_F_MOMENT_M3PERP }, + .diag_moments = + {GKYL_F_MOMENT_BIMAXWELLIAN, GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2, + GKYL_F_MOMENT_M2PAR, GKYL_F_MOMENT_M2PERP, GKYL_F_MOMENT_M3PAR, GKYL_F_MOMENT_M3PERP} }; - struct gkyl_gyrokinetic_field field3d = - { + struct gkyl_gyrokinetic_field field3d = { .polarization_bmag = ctx.B_p, - .poisson_bcs = { - { .dir = 0, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_FIELD_NEUMANN, .value = {0.0} }, - { .dir = 0, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_FIELD_DIRICHLET, .value = {0.0} }, - { .dir = 1, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_FIELD_PERIODIC, }, - { .dir = 1, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_FIELD_PERIODIC, }, - }, + .poisson_bcs = + {{.dir = 0, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_FIELD_NEUMANN, .value = {0.0}}, + {.dir = 0, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_FIELD_DIRICHLET, .value = {0.0}}, + {.dir = 1, .edge = GKYL_LOWER_EDGE, .type = GKYL_BC_GK_FIELD_PERIODIC}, + {.dir = 1, .edge = GKYL_UPPER_EDGE, .type = GKYL_BC_GK_FIELD_PERIODIC}} }; // GK app @@ -972,23 +927,20 @@ run_3x_sim(struct gk_mirror_ctx ctx, const struct gkyl_app_args app_args, .filename_psi = "gyrokinetic/data/unit/wham_hires.geqdsk_psi.gkyl", .rclose = 0.2, .zmin = -2.0, - .zmax = 2.0, + .zmax = 2.0, .include_axis = false, - .fl_coord = GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z, + .fl_coord = GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z }; struct gkyl_gk app_inp_3x = { .cdim = ctx.cdim, - .lower = {ctx.psi_min, - M_PI, ctx.z_min}, - .upper = {ctx.psi_max, M_PI, ctx.z_max}, - .cells = { cells_x[0], cells_x[1], cells_x[2] }, + .lower = {ctx.psi_min, -M_PI, ctx.z_min}, + .upper = {ctx.psi_max, M_PI, ctx.z_max}, + .cells = {cells_x[0], cells_x[1], cells_x[2]}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, - .geometry = { - .geometry_id = GKYL_GEOMETRY_MIRROR, - .mirror_grid_info = grid_inp, - }, + .geometry = {.geometry_id = GKYL_GEOMETRY_MIRROR, .mirror_grid_info = grid_inp}, .num_periodic_dir = 1, .periodic_dirs = {1}, @@ -998,28 +950,26 @@ run_3x_sim(struct gk_mirror_ctx ctx, const struct gkyl_app_args app_args, .field = field3d, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, + .cuts = {app_args.cuts[0], app_args.cuts[0], app_args.cuts[1]}, + .comm = comm} }; // Set app output name from the executable name (argv[0]). snprintf(app_inp_3x.name, sizeof(app_inp_3x.name), "%s", app_args.app_name); struct gkyl_gyrokinetic_run_inp run_inp3x = { .app_inp = app_inp_3x, - .time_stepping = { - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .write_phase_freq = ctx.write_phase_freq, - .int_diag_calc_num = ctx.int_diag_calc_num, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - .is_restart = app_args.is_restart, - .restart_frame = app_args.restart_frame, - .num_steps = 1, - } + .time_stepping = + {.t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .write_phase_freq = ctx.write_phase_freq, + .int_diag_calc_num = ctx.int_diag_calc_num, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + .is_restart = app_args.is_restart, + .restart_frame = app_args.restart_frame, + .num_steps = 1} }; gkyl_gyrokinetic_run_simulation(&run_inp3x); @@ -1030,7 +980,9 @@ int main(int argc, char **argv) struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -1041,10 +993,12 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters @@ -91,15 +90,17 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; // -- Source functions. -void -eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -108,25 +109,26 @@ eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcElc; double sigSrc = app->sigSrcElc; double NSrcFloor = app->NSrcFloorElc; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -134,18 +136,16 @@ eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcElc; double TSrc0 = app->TSrc0Elc; double Tfloor = app->TSrcFloorElc; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -154,25 +154,26 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -180,57 +181,47 @@ eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Potential initial condition -void -eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[2]; double z_m = app->z_m; - double sigma = 0.9*z_m; + double sigma = 0.9 * z_m; double center_potential = 5.0 * app->Te0 / app->qi; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*center_potential*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { + if (fabs(z) <= sigma) { + fout[0] = 0.5 * center_potential * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { fout[0] = 0.0; } } // Electrons initial conditions -void -eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[2]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0*exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -238,18 +229,17 @@ eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -257,18 +247,16 @@ eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Te_par0 = app->Te_par0; double Te_par_m = app->Te_par_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_par_m+(Te_par0-Te_par_m)*tanh(4 * fabs(z_m - fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_par_m + (Te_par0 - Te_par_m) * tanh(4 * fabs(z_m - fabs(z))); + } else { fout[0] = Te_par_m; } } -void -eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -276,37 +264,31 @@ eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Te_perp0 = app->Te_perp0; double Te_perp_m = app->Te_perp_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_perp_m - Te_perp0*tanh(3.*fabs(z_m-fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_perp_m - Te_perp0 * tanh(3. * fabs(z_m - fabs(z))); + } else { fout[0] = Te_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[2]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0* exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -314,17 +296,16 @@ eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -332,18 +313,16 @@ eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Ti_par0 = app->Ti_par0; double Ti_par_m = app->Ti_par_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_par_m + (Ti_par0 - Ti_par_m) * tanh(4 * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_par_m * GKYL_MAX2(1.e-2, 4 * log(fabs(fabs(z) - z_m) + 1)); } } -void -eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -351,46 +330,39 @@ eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Ti_perp0 = app->Ti_perp0; double Ti_perp_m = app->Ti_perp_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_perp_m + (Ti_perp0 - Ti_perp_m) * tanh(3. * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Evaluate collision frequencies -void -evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElcIon; } -void -evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIonElc; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -398,20 +370,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./3.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 3.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_ion*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_ion*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_ion * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_ion * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -419,21 +390,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./6.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 6.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_elc*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_elc*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_elc * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_elc * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -443,7 +412,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -460,12 +429,13 @@ create_ctx(void) double nuFrac = 1.0; double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); - double nuElc = nuFrac * logLambdaElc * pow(eV, 4.) * n0 / - (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); + double nuElc = + nuFrac * logLambdaElc * pow(eV, 4.) * n0 / + (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); double nuIon = nuFrac * logLambdaIon * pow(eV, 4.) * n0 / (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti0, 3. / 2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); // Thermal speeds. double vti = sqrt(Ti0 / mi); @@ -481,7 +451,7 @@ create_ctx(void) // Geometry parameters. double z_min = -2.0; - double z_max = 2.0; + double z_max = 2.0; double z_m = 0.982544; double psi_min = 1e-5; double psi_max = 1e-3; @@ -506,7 +476,7 @@ create_ctx(void) double Ti_par0 = 7500 * eV; double Ti_par_m = 1000 * eV; - double Te_par0 = 1800 * eV; + double Te_par0 = 1800 * eV; double Te_par_m = 300 * eV; double Te_perp0 = 2000 * eV; double Te_perp_m = 3000 * eV; @@ -526,13 +496,14 @@ create_ctx(void) int Ny = 2; int Nz = 32; int Nvpar = 10; // Number of cells in the paralell velocity direction 96 - int Nmu = 10; // Number of cells in the mu direction 192 + int Nmu = 10; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 1e-9; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -561,7 +532,7 @@ create_ctx(void) .c_s = c_s, .omega_ci = omega_ci, .rho_s = rho_s, - .kperp = kperp, + .kperp = kperp, .z_min = z_min, .z_max = z_max, .z_m = z_m, @@ -604,18 +575,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -626,24 +598,26 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters double mi; @@ -73,15 +72,17 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; // -- Source functions. -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -90,25 +91,26 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -116,57 +118,47 @@ eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Potential initial condition -void -eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[1]; double z_m = app->z_m; - double sigma = 0.9*z_m; + double sigma = 0.9 * z_m; double center_potential = 5.0 * app->Te0 / app->qi; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*center_potential*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { + if (fabs(z) <= sigma) { + fout[0] = 0.5 * center_potential * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { fout[0] = 0.0; } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[1]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0*exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -174,18 +166,17 @@ eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -193,18 +184,16 @@ eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Ti_par0 = app->Ti_par0; double Ti_par_m = app->Ti_par_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_par_m + (Ti_par0 - Ti_par_m) * tanh(4 * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_par_m * GKYL_MAX2(1.e-2, 4 * log(fabs(fabs(z) - z_m) + 1)); } } -void -eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -212,18 +201,14 @@ eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Ti_perp0 = app->Ti_perp0; double Ti_perp_m = app->Ti_perp_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_perp_m + (Ti_perp0 - Ti_perp_m) * tanh(3. * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } -void -eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { eval_temp_par_ion(t, xn, fout, ctx); double Tpar = fout[0]; @@ -234,14 +219,13 @@ eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo // Evaluate collision frequencies -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -249,21 +233,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./3.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 3.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_ion*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_ion*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_ion * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_ion * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -273,7 +255,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -311,7 +293,7 @@ create_ctx(void) // Geometry parameters. double z_min = -2.0; - double z_max = 2.0; + double z_max = 2.0; double psi_min = 1e-5; double psi_max = 1e-3; @@ -338,13 +320,14 @@ create_ctx(void) int Nx = 4; int Nz = 32; int Nvpar = 16; // Number of cells in the paralell velocity direction 96 - int Nmu = 16; // Number of cells in the mu direction 192 + int Nmu = 16; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 5e-9; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -372,7 +355,7 @@ create_ctx(void) .c_s = c_s, .omega_ci = omega_ci, .rho_s = rho_s, - .kperp = kperp, + .kperp = kperp, .z_min = z_min, .z_max = z_max, .psi_min = psi_min, @@ -401,19 +384,20 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; ctx.z_m = 0.98; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -424,24 +408,26 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; dnuIon; } -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; fout[0] = 1e17; } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = 0.0; } -void -eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->Ti0; } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double src_amp = app->ion_source_amplitude; double z_src = 0.0; double src_sigma = app->ion_source_sigma; - double src_amp_floor = src_amp*1e-2; - if (fabs(z) <= 1.0) - { + double src_amp_floor = src_amp * 1e-2; + if (fabs(z) <= 1.0) { // fout[0] = fmax(src_amp_floor, (src_amp / sqrt(2.0 * M_PI * pow(src_sigma, 2))) * - // exp(-1 * pow((z - z_src), 2) / (2.0 * pow(src_sigma, 2)))); - - // cubic polynomial drop of to the edge + // exp(-1 * pow((z - z_src), 2) / (2.0 * pow(src_sigma, 2)))); + + // cubic polynomial drop of to the edge fout[0] = src_amp * (1 - pow(fabs(z), 6)); - } - else - { + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double TSrc0 = app->ion_source_temp; - double Tfloor = TSrc0*1e-2; - if (fabs(z) <= 1.0) - { + double Tfloor = TSrc0 * 1e-2; + if (fabs(z) <= 1.0) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -172,21 +167,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./6.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 6.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_ion*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_ion*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_ion * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_ion * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -196,7 +189,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -224,9 +217,9 @@ create_ctx(void) // Geometry parameters. double z_min = -2.0; - double z_max = 2.0; + double z_max = 2.0; double psi_min = 1e-6; // Go smaller. 1e-4 might be too small - double psi_eval= 1e-3; + double psi_eval = 1e-3; double psi_max = 3e-3; // aim for 2e-2 // Grid parameters @@ -234,7 +227,7 @@ create_ctx(void) double mu_max_ion = mi * pow(3. * vti, 2.) / (2. * B_p); int Nz = 64; int Nvpar = 32; // 96 uniform - int Nmu = 16; // 192 uniform + int Nmu = 16; // 192 uniform int poly_order = 1; // Source parameters @@ -242,21 +235,21 @@ create_ctx(void) double ion_source_sigma = 0.5; double ion_source_temp = 5000. * eV; - // POA parameters + // POA parameters // Factor multiplying collisionless terms. double alpha_oap = 0.000005; double alpha_fdp = 1.0; // Duration of each phase. double tau_oap = 3.0e-6; double tau_fdp = 2.0e-9; - double tau_fdp_extra = 2.*tau_fdp; + double tau_fdp_extra = 2. * tau_fdp; int num_cycles = 2; // Number of OAP+FDP cycles to run. // Frame counts for each phase type (specified independently) - int num_frames_oap = 1; // Frames per OAP phase - int num_frames_fdp = 1; // Frames per FDP phase - int num_frames_fdp_extra = 1; // Frames for the extra FDP phase - + int num_frames_oap = 1; // Frames per OAP phase + int num_frames_fdp = 1; // Frames per FDP phase + int num_frames_fdp_extra = 1; // Frames for the extra FDP phase + // Whether to evolve the field. bool is_static_field_oap = true; bool is_static_field_fdp = false; @@ -268,45 +261,47 @@ create_ctx(void) enum gkyl_gyrokinetic_fdot_multiplier_type fdot_mult_type_fdp = GKYL_GK_FDOT_MULTIPLIER_NONE; // Calculate phase structure - double t_end = (tau_oap + tau_fdp)*num_cycles + tau_fdp_extra; - double tau_pair = tau_oap+tau_fdp; // Duration of an OAP+FDP pair. - int num_phases = 2*num_cycles + 1; + double t_end = (tau_oap + tau_fdp) * num_cycles + tau_fdp_extra; + double tau_pair = tau_oap + tau_fdp; // Duration of an OAP+FDP pair. + int num_phases = 2 * num_cycles + 1; int num_frames = num_cycles * (num_frames_oap + num_frames_fdp) + num_frames_fdp_extra; - struct gk_poa_phase_params *poa_phases = gkyl_malloc(num_phases * sizeof(struct gk_poa_phase_params)); - for (int i=0; i<(num_phases-1)/2; i++) { + struct gk_poa_phase_params *poa_phases = + gkyl_malloc(num_phases * sizeof(struct gk_poa_phase_params)); + for (int i = 0; i < (num_phases - 1) / 2; i++) { // OAPs. - poa_phases[2*i].phase = GK_POA_OAP; - poa_phases[2*i].num_frames = num_frames_oap; - poa_phases[2*i].duration = tau_oap; - poa_phases[2*i].alpha = alpha_oap; - poa_phases[2*i].is_static_field = is_static_field_oap; - poa_phases[2*i].fdot_mult_type = fdot_mult_type_oap; - poa_phases[2*i].is_positivity_enabled = is_positivity_enabled_oap; + poa_phases[2 * i].phase = GK_POA_OAP; + poa_phases[2 * i].num_frames = num_frames_oap; + poa_phases[2 * i].duration = tau_oap; + poa_phases[2 * i].alpha = alpha_oap; + poa_phases[2 * i].is_static_field = is_static_field_oap; + poa_phases[2 * i].fdot_mult_type = fdot_mult_type_oap; + poa_phases[2 * i].is_positivity_enabled = is_positivity_enabled_oap; // FDPs. - poa_phases[2*i+1].phase = GK_POA_FDP; - poa_phases[2*i+1].num_frames = num_frames_fdp; - poa_phases[2*i+1].duration = tau_fdp; - poa_phases[2*i+1].alpha = alpha_fdp; - poa_phases[2*i+1].is_static_field = is_static_field_fdp; - poa_phases[2*i+1].fdot_mult_type = fdot_mult_type_fdp; - poa_phases[2*i+1].is_positivity_enabled = is_positivity_enabled_fdp; + poa_phases[2 * i + 1].phase = GK_POA_FDP; + poa_phases[2 * i + 1].num_frames = num_frames_fdp; + poa_phases[2 * i + 1].duration = tau_fdp; + poa_phases[2 * i + 1].alpha = alpha_fdp; + poa_phases[2 * i + 1].is_static_field = is_static_field_fdp; + poa_phases[2 * i + 1].fdot_mult_type = fdot_mult_type_fdp; + poa_phases[2 * i + 1].is_positivity_enabled = is_positivity_enabled_fdp; } // The final stage is an extra, longer FDP. - poa_phases[num_phases-1].phase = GK_POA_FDP; - poa_phases[num_phases-1].num_frames = num_frames_fdp_extra; - poa_phases[num_phases-1].duration = tau_fdp_extra; - poa_phases[num_phases-1].alpha = alpha_fdp; - poa_phases[num_phases-1].is_static_field = is_static_field_fdp; - poa_phases[num_phases-1].fdot_mult_type = fdot_mult_type_fdp; - poa_phases[num_phases-1].is_positivity_enabled = is_positivity_enabled_fdp; + poa_phases[num_phases - 1].phase = GK_POA_FDP; + poa_phases[num_phases - 1].num_frames = num_frames_fdp_extra; + poa_phases[num_phases - 1].duration = tau_fdp_extra; + poa_phases[num_phases - 1].alpha = alpha_fdp; + poa_phases[num_phases - 1].is_static_field = is_static_field_fdp; + poa_phases[num_phases - 1].fdot_mult_type = fdot_mult_type_fdp; + poa_phases[num_phases - 1].is_positivity_enabled = is_positivity_enabled_fdp; double write_phase_freq = 0.2; - double int_diag_calc_freq = 100; // Frequency of calculating integrated diagnostics (as a factor of num_frames). + double int_diag_calc_freq = + 100; // Frequency of calculating integrated diagnostics (as a factor of num_frames). double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct gk_mirror_ctx ctx = { .cdim = cdim, .vdim = vdim, @@ -350,37 +345,38 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .num_phases = num_phases, - .poa_phases = poa_phases, + .poa_phases = poa_phases }; - + return ctx; } -void -release_ctx(struct gk_mirror_ctx *ctx) +void release_ctx(struct gk_mirror_ctx *ctx) { gkyl_free(ctx->poa_phases); } -void -calc_integrated_diagnostics(struct gkyl_tm_trigger* iot, gkyl_gyrokinetic_app* app, - double t_curr, bool force_calc, double dt) +void calc_integrated_diagnostics( + struct gkyl_tm_trigger *iot, gkyl_gyrokinetic_app *app, double t_curr, bool force_calc, double dt +) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_calc) { gkyl_gyrokinetic_app_calc_field_energy(app, t_curr); gkyl_gyrokinetic_app_calc_integrated_mom(app, t_curr); - if ( !(dt < 0.0) ) + if (!(dt < 0.0)) { gkyl_gyrokinetic_app_save_dt(app, t_curr, dt); + } } } -void -write_data(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot_phase, - gkyl_gyrokinetic_app* app, double t_curr, bool force_write) +void write_data( + struct gkyl_tm_trigger *iot_conf, struct gkyl_tm_trigger *iot_phase, gkyl_gyrokinetic_app *app, + double t_curr, bool force_write +) { bool trig_now_conf = gkyl_tm_trigger_check_and_bump(iot_conf, t_curr); if (trig_now_conf || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_app_write_conf(app, t_curr, frame); gkyl_gyrokinetic_app_write_field_energy(app); gkyl_gyrokinetic_app_write_integrated_mom(app); @@ -388,7 +384,7 @@ write_data(struct gkyl_tm_trigger* iot_conf, struct gkyl_tm_trigger* iot_phase, } bool trig_now_phase = gkyl_tm_trigger_check_and_bump(iot_phase, t_curr); if (trig_now_phase || force_write) { - int frame = (!trig_now_conf) && force_write? iot_conf->curr : iot_conf->curr-1; + int frame = (!trig_now_conf) && force_write ? iot_conf->curr : iot_conf->curr - 1; gkyl_gyrokinetic_app_write_phase(app, t_curr, frame); } } @@ -400,16 +396,17 @@ struct time_frame_state { int num_frames; // Number of frames at the end of current phase. }; -void reset_io_triggers(struct gk_mirror_ctx *ctx, struct time_frame_state *tfs, - struct gkyl_tm_trigger *trig_write_conf, struct gkyl_tm_trigger *trig_write_phase, - struct gkyl_tm_trigger *trig_calc_intdiag) +void reset_io_triggers( + struct gk_mirror_ctx *ctx, struct time_frame_state *tfs, struct gkyl_tm_trigger *trig_write_conf, + struct gkyl_tm_trigger *trig_write_phase, struct gkyl_tm_trigger *trig_calc_intdiag +) { // Reset I/O triggers: double t_curr = tfs->t_curr; double t_end = tfs->t_end; int frame_curr = tfs->frame_curr; int num_frames = tfs->num_frames; - int num_int_diag_calc = ctx->int_diag_calc_freq*num_frames; + int num_int_diag_calc = ctx->int_diag_calc_freq * num_frames; // Prevent division by zero when frame_curr equals num_frames int frames_remaining = num_frames - frame_curr; @@ -423,16 +420,19 @@ void reset_io_triggers(struct gk_mirror_ctx *ctx, struct time_frame_state *tfs, trig_write_phase->tcurr = t_curr; trig_write_phase->curr = frame_curr; - int diag_frames = GKYL_MAX2(frames_remaining, (num_int_diag_calc/num_frames) * frames_remaining); + int diag_frames = + GKYL_MAX2(frames_remaining, (num_int_diag_calc / num_frames) * frames_remaining); trig_calc_intdiag->dt = time_remaining / diag_frames; trig_calc_intdiag->tcurr = t_curr; trig_calc_intdiag->curr = frame_curr; } -void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_steps, +void run_phase( + gkyl_gyrokinetic_app *app, struct gk_mirror_ctx *ctx, double num_steps, struct gkyl_tm_trigger *trig_write_conf, struct gkyl_tm_trigger *trig_write_phase, struct gkyl_tm_trigger *trig_calc_intdiag, struct time_frame_state *tfs, - struct gk_poa_phase_params *pparams) + struct gk_poa_phase_params *pparams +) { tfs->t_end = tfs->t_curr + pparams->duration; tfs->num_frames = tfs->frame_curr + pparams->num_frames; @@ -440,22 +440,18 @@ void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_ // Run an OAP or FDP. double t_curr = tfs->t_curr; double t_end = tfs->t_end; - + // Reset I/O triggers: reset_io_triggers(ctx, tfs, trig_write_conf, trig_write_phase, trig_calc_intdiag); // Reset simulation parameters and function pointers. struct gkyl_gyrokinetic_collisionless collisionless_inp = { - .type = GKYL_GK_COLLISIONLESS_ES, - .scale_factor = pparams->alpha, + .type = GKYL_GK_COLLISIONLESS_ES, .scale_factor = pparams->alpha }; struct gkyl_gyrokinetic_fdot_multiplier fdot_mult = { .num_multipliers = 1, - .multiplier[0] = { - .type = pparams->fdot_mult_type, - .cellwise_const = true, - .write_diagnostics = true, - } + .multiplier[0] = + {.type = pparams->fdot_mult_type, .cellwise_const = true, .write_diagnostics = true} }; struct gkyl_gyrokinetic_field reset_field = { .gkfield_id = GKYL_GK_FIELD_BOLTZMANN, @@ -463,11 +459,11 @@ void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_ .electron_charge = ctx->qe, .electron_temp = ctx->Te0, .polarization_bmag = ctx->B_p, - .is_static = pparams->is_static_field, + .is_static = pparams->is_static_field }; struct gkyl_gyrokinetic_positivity positivity_inp = { - .type = pparams->is_positivity_enabled? GKYL_GK_POSITIVITY_SHIFT : GKYL_GK_POSITIVITY_NONE, - .write_diagnostics = pparams->is_positivity_enabled, + .type = pparams->is_positivity_enabled ? GKYL_GK_POSITIVITY_SHIFT : GKYL_GK_POSITIVITY_NONE, + .write_diagnostics = pparams->is_positivity_enabled }; gkyl_gyrokinetic_app_reset_species_fdot_multiplier(app, t_curr, "ion", fdot_mult); @@ -483,8 +479,7 @@ void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_ int num_failures = 0, num_failures_max = ctx->num_failures_max; long step = 1; - while ((t_curr < t_end) && (step <= num_steps)) - { + while ((t_curr < t_end) && (step <= num_steps)) { gkyl_gyrokinetic_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); dt = fmin(dt, t_end - t_curr); // Don't step beyond t_end. @@ -492,8 +487,7 @@ void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_ gkyl_gyrokinetic_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - if (!status.success) - { + if (!status.success) { gkyl_gyrokinetic_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; } @@ -505,29 +499,31 @@ void run_phase(gkyl_gyrokinetic_app* app, struct gk_mirror_ctx *ctx, double num_ if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_gyrokinetic_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); gkyl_gyrokinetic_app_cout(app, stdout, " is below %g*dt_init ...", dt_failure_tol); gkyl_gyrokinetic_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { - gkyl_gyrokinetic_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_gyrokinetic_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_gyrokinetic_app_cout( + app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_integrated_diagnostics(trig_calc_intdiag, app, t_curr, true, status.dt_actual); write_data(trig_write_conf, trig_write_phase, app, t_curr, true); break; } - } - else { + } else { num_failures = 0; } step += 1; } tfs->t_curr = t_curr; - tfs->frame_curr = tfs->frame_curr+pparams->num_frames; + tfs->frame_curr = tfs->frame_curr + pparams->num_frames; } int main(int argc, char **argv) @@ -535,7 +531,9 @@ int main(int argc, char **argv) struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -546,10 +544,12 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // context for init functions int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d 0) - { - gkyl_gyrokinetic_app_cout(app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_gyrokinetic_app_cout(app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); + if (stat.nstage_2_fail > 0) { + gkyl_gyrokinetic_app_cout( + app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_gyrokinetic_app_cout( + app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); } gkyl_gyrokinetic_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_gyrokinetic_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_gyrokinetic_app_print_timings(app, stdout); - freeresources: +freeresources: // simulation complete, free app gkyl_gyrokinetic_app_release(app); gkyl_gyrokinetic_comms_release(comm); release_ctx(&ctx); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif return 0; } diff --git a/gyrokinetic/creg/rt_gk_wham_nonuniformx_1x2v_p1.c b/gyrokinetic/creg/rt_gk_wham_nonuniformx_1x2v_p1.c index ab951609cd..0b8a09318a 100644 --- a/gyrokinetic/creg/rt_gk_wham_nonuniformx_1x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_wham_nonuniformx_1x2v_p1.c @@ -14,8 +14,7 @@ #include // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters @@ -89,16 +88,17 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; - // -- Source functions. -void -eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; @@ -106,43 +106,42 @@ eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcElc; double sigSrc = app->sigSrcElc; double NSrcFloor = app->NSrcFloorElc; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double sigSrc = app->sigSrcElc; double TSrc0 = app->TSrc0Elc; double Tfloor = app->TSrcFloorElc; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; @@ -150,214 +149,190 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Electrons initial conditions -void -eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0*exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Te_par0 = app->Te_par0; double Te_par_m = app->Te_par_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_par_m+(Te_par0-Te_par_m)*tanh(4 * fabs(z_m - fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_par_m + (Te_par0 - Te_par_m) * tanh(4 * fabs(z_m - fabs(z))); + } else { fout[0] = Te_par_m; } } -void -eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Te_perp0 = app->Te_perp0; double Te_perp_m = app->Te_perp_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_perp_m - Te_perp0*tanh(3.*fabs(z_m-fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_perp_m - Te_perp0 * tanh(3. * fabs(z_m - fabs(z))); + } else { fout[0] = Te_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0* exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Ti_par0 = app->Ti_par0; double Ti_par_m = app->Ti_par_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_par_m + (Ti_par0 - Ti_par_m) * tanh(4 * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_par_m * GKYL_MAX2(1.e-2, 4 * log(fabs(fabs(z) - z_m) + 1)); } } -void -eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double z = xn[0]; double z_m = app->z_m; double Ti_perp0 = app->Ti_perp0; double Ti_perp_m = app->Ti_perp_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_perp_m + (Ti_perp0 - Ti_perp_m) * tanh(3. * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Evaluate collision frequencies -void -evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElcIon; } -void -evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIonElc; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -365,20 +340,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./3.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 3.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_ion*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_ion*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_ion * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_ion * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -386,21 +360,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./6.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 6.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_elc*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_elc*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_elc * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_elc * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 1, vdim = 2; // Dimensionality. @@ -410,7 +382,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -427,12 +399,13 @@ create_ctx(void) double nuFrac = 1.0; double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); - double nuElc = nuFrac * logLambdaElc * pow(eV, 4.) * n0 / - (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); + double nuElc = + nuFrac * logLambdaElc * pow(eV, 4.) * n0 / + (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); double nuIon = nuFrac * logLambdaIon * pow(eV, 4.) * n0 / (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti0, 3. / 2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); // Thermal speeds. double vti = sqrt(Ti0 / mi); @@ -450,7 +423,7 @@ create_ctx(void) // Axial coordinate Z extents. Endure that Z=0 is not on // the boundary of a cell (due to AD errors). double z_min = -2.0; - double z_max = 2.0; + double z_max = 2.0; double psi_eval = 0.0026530898059565; double z_m = 0.982544; @@ -475,7 +448,7 @@ create_ctx(void) double Ti_par0 = 7500 * eV; double Ti_par_m = 1000 * eV; - double Te_par0 = 1800 * eV; + double Te_par0 = 1800 * eV; double Te_par_m = 300 * eV; double Te_perp0 = 2000 * eV; double Te_perp_m = 3000 * eV; @@ -493,13 +466,14 @@ create_ctx(void) double mu_max_ion = mi * pow(3. * vti, 2.) / (2. * B_p); int Nz = 128; int Nvpar = 32; // Number of cells in the paralell velocity direction 96 - int Nmu = 32; // Number of cells in the mu direction 192 + int Nmu = 32; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 4.0e-9; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -528,7 +502,7 @@ create_ctx(void) .c_s = c_s, .omega_ci = omega_ci, .rho_s = rho_s, - .kperp = kperp, + .kperp = kperp, .z_min = z_min, .z_max = z_max, .psi_eval = psi_eval, @@ -571,18 +545,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -593,10 +568,12 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters double mi; @@ -89,15 +88,17 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; // -- Source functions. -void -eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -106,25 +107,26 @@ eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcElc; double sigSrc = app->sigSrcElc; double NSrcFloor = app->NSrcFloorElc; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -132,18 +134,16 @@ eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcElc; double TSrc0 = app->TSrc0Elc; double Tfloor = app->TSrcFloorElc; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -152,25 +152,26 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -178,57 +179,47 @@ eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Potential initial condition -void -eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[1]; double z_m = app->z_m; - double sigma = 0.9*z_m; + double sigma = 0.9 * z_m; double center_potential = 5.0 * app->Te0 / app->qi; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*center_potential*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { + if (fabs(z) <= sigma) { + fout[0] = 0.5 * center_potential * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { fout[0] = 0.0; } } // Electrons initial conditions -void -eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[1]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0*exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -236,18 +227,17 @@ eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -255,18 +245,16 @@ eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Te_par0 = app->Te_par0; double Te_par_m = app->Te_par_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_par_m+(Te_par0-Te_par_m)*tanh(4 * fabs(z_m - fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_par_m + (Te_par0 - Te_par_m) * tanh(4 * fabs(z_m - fabs(z))); + } else { fout[0] = Te_par_m; } } -void -eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -274,37 +262,31 @@ eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Te_perp0 = app->Te_perp0; double Te_perp_m = app->Te_perp_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_perp_m - Te_perp0*tanh(3.*fabs(z_m-fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_perp_m - Te_perp0 * tanh(3. * fabs(z_m - fabs(z))); + } else { fout[0] = Te_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[1]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0* exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -312,17 +294,16 @@ eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -330,18 +311,16 @@ eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Ti_par0 = app->Ti_par0; double Ti_par_m = app->Ti_par_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_par_m + (Ti_par0 - Ti_par_m) * tanh(4 * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_par_m * GKYL_MAX2(1.e-2, 4 * log(fabs(fabs(z) - z_m) + 1)); } } -void -eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -349,46 +328,39 @@ eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Ti_perp0 = app->Ti_perp0; double Ti_perp_m = app->Ti_perp_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_perp_m + (Ti_perp0 - Ti_perp_m) * tanh(3. * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Evaluate collision frequencies -void -evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElcIon; } -void -evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIonElc; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -396,20 +368,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./3.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 3.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_ion*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_ion*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_ion * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_ion * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -417,21 +388,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./6.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 6.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_elc*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_elc*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_elc * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_elc * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 2, vdim = 2; // Dimensionality. @@ -441,7 +410,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -458,12 +427,13 @@ create_ctx(void) double nuFrac = 1.0; double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); - double nuElc = nuFrac * logLambdaElc * pow(eV, 4.) * n0 / - (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); + double nuElc = + nuFrac * logLambdaElc * pow(eV, 4.) * n0 / + (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); double nuIon = nuFrac * logLambdaIon * pow(eV, 4.) * n0 / (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti0, 3. / 2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); // Thermal speeds. double vti = sqrt(Ti0 / mi); @@ -479,7 +449,7 @@ create_ctx(void) // Geometry parameters. double z_min = -2.0; - double z_max = 2.0; + double z_max = 2.0; double z_m = 0.982544; double psi_min = 1e-5; double psi_max = 1e-3; @@ -504,7 +474,7 @@ create_ctx(void) double Ti_par0 = 7500 * eV; double Ti_par_m = 1000 * eV; - double Te_par0 = 1800 * eV; + double Te_par0 = 1800 * eV; double Te_par_m = 300 * eV; double Te_perp0 = 2000 * eV; double Te_perp_m = 3000 * eV; @@ -523,13 +493,14 @@ create_ctx(void) int Nx = 4; int Nz = 64; int Nvpar = 32; // Number of cells in the paralell velocity direction 96 - int Nmu = 32; // Number of cells in the mu direction 192 + int Nmu = 32; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 1.5e-10; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -558,7 +529,7 @@ create_ctx(void) .c_s = c_s, .omega_ci = omega_ci, .rho_s = rho_s, - .kperp = kperp, + .kperp = kperp, .z_min = z_min, .z_max = z_max, .z_m = z_m, @@ -600,18 +571,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -622,24 +594,26 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d // Define the context of the simulation. This is basically all the globals -struct gk_mirror_ctx -{ +struct gk_mirror_ctx { int cdim, vdim; // Dimensionality. // Plasma parameters @@ -91,15 +90,17 @@ struct gk_mirror_ctx double t_end; // End time. int num_frames; // Number of output frames. - double write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + double + write_phase_freq; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; // -- Source functions. -void -eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -108,25 +109,26 @@ eval_density_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcElc; double sigSrc = app->sigSrcElc; double NSrcFloor = app->NSrcFloorElc; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2.))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2.))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_elc_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -134,18 +136,16 @@ eval_temp_elc_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcElc; double TSrc0 = app->TSrc0Elc; double Tfloor = app->TSrcFloorElc; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } -void -eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -154,25 +154,26 @@ eval_density_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_R double zSrc = app->lineLengthSrcIon; double sigSrc = app->sigSrcIon; double NSrcFloor = app->NSrcFloorIon; - if (fabs(z) <= app->z_m) - { - fout[0] = fmax(NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * - exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2)))); - } - else - { + if (fabs(z) <= app->z_m) { + fout[0] = fmax( + NSrcFloor, (NSrc / sqrt(2.0 * M_PI * pow(sigSrc, 2))) * + exp(-1 * pow((z - zSrc), 2) / (2.0 * pow(sigSrc, 2))) + ); + } else { fout[0] = 1e-16; } } -void -eval_upar_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = 0.0; } -void -eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_ion_source( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -180,57 +181,47 @@ eval_temp_ion_source(double t, const double *GKYL_RESTRICT xn, double *GKYL_REST double sigSrc = app->sigSrcIon; double TSrc0 = app->TSrc0Ion; double Tfloor = app->TSrcFloorIon; - if (fabs(z) <= 2.0 * sigSrc) - { + if (fabs(z) <= 2.0 * sigSrc) { fout[0] = TSrc0; - } - else - { + } else { fout[0] = Tfloor; } } // Potential initial condition -void -eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_potential(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[2]; double z_m = app->z_m; - double sigma = 0.9*z_m; + double sigma = 0.9 * z_m; double center_potential = 5.0 * app->Te0 / app->qi; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*center_potential*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { + if (fabs(z) <= sigma) { + fout[0] = 0.5 * center_potential * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { fout[0] = 0.0; } } // Electrons initial conditions -void -eval_density_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[2]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0*exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -238,18 +229,17 @@ eval_upar_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -257,18 +247,16 @@ eval_temp_par_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Te_par0 = app->Te_par0; double Te_par_m = app->Te_par_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_par_m+(Te_par0-Te_par_m)*tanh(4 * fabs(z_m - fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_par_m + (Te_par0 - Te_par_m) * tanh(4 * fabs(z_m - fabs(z))); + } else { fout[0] = Te_par_m; } } -void -eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_elc( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -276,37 +264,31 @@ eval_temp_perp_elc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Te_perp0 = app->Te_perp0; double Te_perp_m = app->Te_perp_m; - if (fabs(z) <= z_m) - { - fout[0] = Te_perp_m - Te_perp0*tanh(3.*fabs(z_m-fabs(z))); - } - else - { + if (fabs(z) <= z_m) { + fout[0] = Te_perp_m - Te_perp0 * tanh(3. * fabs(z_m - fabs(z))); + } else { fout[0] = Te_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Ion initial conditions -void -eval_density_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_density_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. double z = xn[2]; double z_m = app->z_m; - double sigma = 0.9*z_m; - if (fabs(z) <= sigma) - { - fout[0] = 0.5*app->n0*(1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); - } - else - { - fout[0] = 0.5*app->n0* exp(-5 * (fabs(sigma - fabs(z)))); + double sigma = 0.9 * z_m; + if (fabs(z) <= sigma) { + fout[0] = 0.5 * app->n0 * (1. + tanh(10. * sigma * fabs(sigma - fabs(z)))); + } else { + fout[0] = 0.5 * app->n0 * exp(-5 * (fabs(sigma - fabs(z)))); } } -void -eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -314,17 +296,16 @@ eval_upar_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fo double cs_m = app->cs_m; double z_m = app->z_m; double z_max = app->z_max; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = 0.0; - } - else - { - fout[0] = fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here + } else { + fout[0] = + fabs(z) / z * cs_m * tanh(3 * (z_max - z_m) * fabs(fabs(z) - z_m)); // Maybe put a 5 here } } -void -eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_par_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -332,18 +313,16 @@ eval_temp_par_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRIC double z_m = app->z_m; double Ti_par0 = app->Ti_par0; double Ti_par_m = app->Ti_par_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_par_m + (Ti_par0 - Ti_par_m) * tanh(4 * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_par_m * GKYL_MAX2(1.e-2, 4 * log(fabs(fabs(z) - z_m) + 1)); } } -void -eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void eval_temp_perp_ion( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct gk_mirror_ctx *app = ctx; double psi = xn[0]; // Magnetic flux function psi of field line. @@ -351,46 +330,39 @@ eval_temp_perp_ion(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRI double z_m = app->z_m; double Ti_perp0 = app->Ti_perp0; double Ti_perp_m = app->Ti_perp_m; - if (fabs(z) <= z_m) - { + if (fabs(z) <= z_m) { fout[0] = Ti_perp_m + (Ti_perp0 - Ti_perp_m) * tanh(3. * fabs(z_m - fabs(z))); - } - else - { + } else { fout[0] = Ti_perp_m * GKYL_MAX2(1.e-3, exp(-5. * (fabs(z_m - fabs(z))))); } } // Evaluate collision frequencies -void -evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIon; } -void -evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuElcIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuElcIon; } -void -evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void evalNuIonElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_mirror_ctx *app = ctx; fout[0] = app->nuIonElc; } -void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_ion(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_ion = app->vpar_max_ion; @@ -398,20 +370,19 @@ void mapc2p_vel_ion(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./3.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 3.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_ion*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_ion*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_ion * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_ion * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_ion*pow(cmu,2); + vp[1] = mu_max_ion * pow(cmu, 2); } -void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void *ctx) +void mapc2p_vel_elc(double t, const double *vc, double *GKYL_RESTRICT vp, void *ctx) { struct gk_mirror_ctx *app = ctx; double vpar_max_elc = app->vpar_max_elc; @@ -419,21 +390,19 @@ void mapc2p_vel_elc(double t, const double *vc, double* GKYL_RESTRICT vp, void * double cvpar = vc[0], cmu = vc[1]; double b = 1.45; - double linear_velocity_threshold = 1./6.; - double frac_linear = 1/b*atan(linear_velocity_threshold*tan(b)); + double linear_velocity_threshold = 1. / 6.; + double frac_linear = 1 / b * atan(linear_velocity_threshold * tan(b)); if (fabs(cvpar) < frac_linear) { - double func_frac = tan(frac_linear*b) / tan(b); - vp[0] = vpar_max_elc*func_frac*cvpar/frac_linear; - } - else { - vp[0] = vpar_max_elc*tan(cvpar*b)/tan(b); + double func_frac = tan(frac_linear * b) / tan(b); + vp[0] = vpar_max_elc * func_frac * cvpar / frac_linear; + } else { + vp[0] = vpar_max_elc * tan(cvpar * b) / tan(b); } // Quadratic map in mu. - vp[1] = mu_max_elc*pow(cmu,2); + vp[1] = mu_max_elc * pow(cmu, 2); } -struct gk_mirror_ctx -create_ctx(void) +struct gk_mirror_ctx create_ctx(void) { int cdim = 3, vdim = 2; // Dimensionality. @@ -443,7 +412,7 @@ create_ctx(void) double eV = GKYL_ELEMENTARY_CHARGE; double mp = GKYL_PROTON_MASS; // ion mass double me = GKYL_ELECTRON_MASS; - double qi = eV; // ion charge + double qi = eV; // ion charge double qe = -eV; // electron charge // Plasma parameters. @@ -460,12 +429,13 @@ create_ctx(void) double nuFrac = 1.0; double logLambdaElc = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Te0 / eV); double logLambdaIon = 6.6 - 0.5 * log(n0 / 1e20) + 1.5 * log(Ti0 / eV); - double nuElc = nuFrac * logLambdaElc * pow(eV, 4.) * n0 / - (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); + double nuElc = + nuFrac * logLambdaElc * pow(eV, 4.) * n0 / + (6. * sqrt(2.) * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(me) * pow(Te0, 3. / 2.)); double nuIon = nuFrac * logLambdaIon * pow(eV, 4.) * n0 / (12 * pow(M_PI, 3. / 2.) * pow(eps0, 2.) * sqrt(mi) * pow(Ti0, 3. / 2.)); - double nuElcIon = nuElc*sqrt(2.0); - double nuIonElc = nuElcIon*(me/mi); + double nuElcIon = nuElc * sqrt(2.0); + double nuIonElc = nuElcIon * (me / mi); // Thermal speeds. double vti = sqrt(Ti0 / mi); @@ -481,7 +451,7 @@ create_ctx(void) // Geometry parameters. double z_min = -2.0; - double z_max = 2.0; + double z_max = 2.0; double z_m = 0.982544; double psi_min = 1e-5; double psi_max = 1e-3; @@ -506,7 +476,7 @@ create_ctx(void) double Ti_par0 = 7500 * eV; double Ti_par_m = 1000 * eV; - double Te_par0 = 1800 * eV; + double Te_par0 = 1800 * eV; double Te_par_m = 300 * eV; double Te_perp0 = 2000 * eV; double Te_perp_m = 3000 * eV; @@ -526,13 +496,14 @@ create_ctx(void) int Ny = 2; int Nz = 32; int Nvpar = 10; // Number of cells in the paralell velocity direction 96 - int Nmu = 10; // Number of cells in the mu direction 192 + int Nmu = 10; // Number of cells in the mu direction 192 int poly_order = 1; double t_end = 1e-9; int num_frames = 1; - double write_phase_freq = 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). - int int_diag_calc_num = num_frames*100; + double write_phase_freq = + 0.2; // Frequency of writing phase-space diagnostics (as a fraction of num_frames). + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -561,7 +532,7 @@ create_ctx(void) .c_s = c_s, .omega_ci = omega_ci, .rho_s = rho_s, - .kperp = kperp, + .kperp = kperp, .z_min = z_min, .z_max = z_max, .z_m = z_m, @@ -604,18 +575,19 @@ create_ctx(void) .write_phase_freq = write_phase_freq, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } - int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) MPI_Init(&argc, &argv); + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } #endif if (app_args.trace_mem) { @@ -626,24 +598,26 @@ int main(int argc, char **argv) struct gk_mirror_ctx ctx = create_ctx(); // Context for init functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d #include -void -read_adas_field_iz(enum gkyl_ion_type type_ion, struct adas_field *data) { +void read_adas_field_iz(enum gkyl_ion_type type_ion, struct adas_field *data) +{ char fname[4000]; const char *fmt = "%s/%s"; if (type_ion == GKYL_ION_H) { data->NT = 29, data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/ioniz_h.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_h.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_h.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 1; - data->Eiz[0] = 13.6; - } - else if (type_ion == GKYL_ION_HE) { + data->Eiz[0] = 13.6; + } else if (type_ion == GKYL_ION_HE) { data->NT = 30; data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/ioniz_he.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_he.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_he.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 2; data->Eiz[0] = 24.6; data->Eiz[1] = 54.4; - } - else if (type_ion == GKYL_ION_LI) { + } else if (type_ion == GKYL_ION_LI) { data->NT = 25; data->NN = 16; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/ioniz_li.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_li.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_li.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 3; data->Eiz[0] = 5.4; data->Eiz[1] = 75.6; data->Eiz[2] = 122.4; - } - else if (type_ion == GKYL_ION_BE) { + } else if (type_ion == GKYL_ION_BE) { data->NT = 25; data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/ioniz_be.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_be.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_be.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 4; data->Eiz[0] = 9.3; data->Eiz[1] = 18.2; data->Eiz[3] = 153.9; data->Eiz[4] = 217.7; - } - else if (type_ion == GKYL_ION_B) { + } else if (type_ion == GKYL_ION_B) { data->NT = 48; data->NN = 26; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/ioniz_b.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_b.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_b.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 5; data->Eiz[0] = 8.3; data->Eiz[1] = 25.2; data->Eiz[2] = 37.9; data->Eiz[3] = 259.4; data->Eiz[5] = 340.2; - } - else if (type_ion == GKYL_ION_C) { + } else if (type_ion == GKYL_ION_C) { data->NT = 30; data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/ioniz_c.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_c.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_c.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 6; data->Eiz[0] = 11.3; data->Eiz[1] = 24.4; @@ -99,16 +94,15 @@ read_adas_field_iz(enum gkyl_ion_type type_ion, struct adas_field *data) { data->Eiz[3] = 64.5; data->Eiz[4] = 392.1; data->Eiz[5] = 490.0; - } - else if (type_ion == GKYL_ION_N) { + } else if (type_ion == GKYL_ION_N) { data->NT = 30; data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/ioniz_n.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_n.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_n.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 7; data->Eiz[0] = 14.5; data->Eiz[1] = 29.6; @@ -117,16 +111,15 @@ read_adas_field_iz(enum gkyl_ion_type type_ion, struct adas_field *data) { data->Eiz[4] = 97.9; data->Eiz[5] = 552.1; data->Eiz[6] = 667.0; - } - else if (type_ion == GKYL_ION_O) { + } else if (type_ion == GKYL_ION_O) { data->NT = 30; data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/ioniz_o.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_o.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_o.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 8; data->Eiz[0] = 13.6; data->Eiz[1] = 35.1; @@ -136,16 +129,15 @@ read_adas_field_iz(enum gkyl_ion_type type_ion, struct adas_field *data) { data->Eiz[5] = 138.1; data->Eiz[6] = 739.3; data->Eiz[7] = 871.4; - } - else if (type_ion == GKYL_ION_AR) { + } else if (type_ion == GKYL_ION_AR) { data->NT = 48; data->NN = 26; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/ioniz_ar.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_ar.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_ar.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 18; data->Eiz[0] = 15.8; data->Eiz[1] = 27.6; @@ -165,113 +157,105 @@ read_adas_field_iz(enum gkyl_ion_type type_ion, struct adas_field *data) { data->Eiz[15] = 918.; data->Eiz[16] = 4120.7; data->Eiz[17] = 4426.2; - } - else + } else { fprintf(stderr, "Incorrect ion type for ionization."); + } } - -void -read_adas_field_recomb(enum gkyl_ion_type type_ion, struct adas_field *data) { + +void read_adas_field_recomb(enum gkyl_ion_type type_ion, struct adas_field *data) +{ char fname[4000]; const char *fmt = "%s/%s"; if (type_ion == GKYL_ION_H) { data->NT = 29, data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/recomb_h.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_h.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_h.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 1; - } - else if (type_ion == GKYL_ION_HE) { + } else if (type_ion == GKYL_ION_HE) { data->NT = 30; data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/recomb_he.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_he.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_he.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 2; - } - else if (type_ion == GKYL_ION_LI) { + } else if (type_ion == GKYL_ION_LI) { data->NT = 25; data->NN = 16; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/recomb_li.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_li.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_li.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 3; - } - else if (type_ion == GKYL_ION_BE) { + } else if (type_ion == GKYL_ION_BE) { data->NT = 25; data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/recomb_be.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_be.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_be.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 4; - } - else if (type_ion == GKYL_ION_B) { + } else if (type_ion == GKYL_ION_B) { data->NT = 48; data->NN = 26; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/recomb_b.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_b.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_b.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 5; - } - else if (type_ion == GKYL_ION_C) { + } else if (type_ion == GKYL_ION_C) { data->NT = 30; data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/recomb_c.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_c.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_c.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 6; - } - else if (type_ion == GKYL_ION_N) { + } else if (type_ion == GKYL_ION_N) { data->NT = 30; data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/recomb_n.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_n.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_n.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 7; - } - else if (type_ion == GKYL_ION_O) { + } else if (type_ion == GKYL_ION_O) { data->NT = 30; data->NN = 24; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/recomb_o.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_o.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_o.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 8; - } - else if (type_ion == GKYL_ION_AR) { + } else if (type_ion == GKYL_ION_AR) { data->NT = 48; data->NN = 26; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/recomb_ar.npy"); - data->logData = fopen(fname,"rb"); + data->logData = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logT_ar.npy"); data->logT = fopen(fname, "rb"); snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/logN_ar.npy"); - data->logN = fopen(fname, "rb"); + data->logN = fopen(fname, "rb"); data->Zmax = 18; - } - else + } else { fprintf(stderr, "Incorrect ion type for recombination."); + } } diff --git a/gyrokinetic/data/adas/read_adas.h b/gyrokinetic/data/adas/read_adas.h index 078a38d56b..02c049a9b9 100644 --- a/gyrokinetic/data/adas/read_adas.h +++ b/gyrokinetic/data/adas/read_adas.h @@ -14,7 +14,7 @@ typedef struct adas_field { FILE *logT; FILE *logN; long NT; - long NN; + long NN; int Zmax; struct gkyl_array fld; double Eiz[GKYL_MAX_CHARGE_STATE]; @@ -27,26 +27,23 @@ array_from_numpy(FILE *fp, long sz, int Zmax, int charge_state, struct gkyl_arra int zi = charge_state; double array[Zmax][sz]; long res_sz = fread(array, 1, sizeof(double[Zmax][sz]), fp); - - for (int i=0; i #include -void eval_one(double t, const double *xn, double* restrict fout, void *ctx) +void eval_one(double t, const double *xn, double *restrict fout, void *ctx) { fout[0] = 1.0; } -void eval_hat(double t, const double *xn, double* restrict fout, void *ctx) +void eval_hat(double t, const double *xn, double *restrict fout, void *ctx) { fout[0] = 2. - fabs(xn[0]); } -void eval_hat_2x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_hat_2x(double t, const double *xn, double *restrict fout, void *ctx) { double psi = xn[0], z = xn[1]; fout[0] = 2. - fabs(z); } -void eval_ramp_sheath_2x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_ramp_sheath_2x(double t, const double *xn, double *restrict fout, void *ctx) { double psi = xn[0], z = xn[1]; fout[0] = 2. + psi; } -void eval_parabola_2x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_parabola_2x(double t, const double *xn, double *restrict fout, void *ctx) { double psi = xn[0], z = xn[1]; - fout[0] = 10. - psi*psi - z*z; + fout[0] = 10. - psi * psi - z * z; } -void eval_parabola_3x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_parabola_3x(double t, const double *xn, double *restrict fout, void *ctx) { double psi = xn[0], z = xn[1], y = xn[2]; - fout[0] = 10. - psi*psi - z*z - y*y; + fout[0] = 10. - psi * psi - z * z - y * y; } -void -test_ambi_bolt_init_1x_ho() +void test_ambi_bolt_init_1x_ho() { int poly_order = 1; double lower[] = {-1.0}, upper[] = {1.0}; int cells[] = {8}; - int cdim = sizeof(lower)/sizeof(lower[0]); + int cdim = sizeof(lower) / sizeof(lower[0]); // Grid. struct gkyl_rect_grid grid; @@ -65,34 +64,34 @@ test_ambi_bolt_init_1x_ho() struct gkyl_basis *basis; basis = gkyl_cart_modal_serendip_new(cdim, poly_order); - int ghost[] = { 1 }; + int ghost[] = {1}; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); double mass_e = 1.0, charge_e = -1.0, temp_e = 1.0; bool use_gpu = false; - struct gkyl_ambi_bolt_potential *ambi = gkyl_ambi_bolt_potential_new(&grid, basis, mass_e, charge_e, temp_e, use_gpu); + struct gkyl_ambi_bolt_potential *ambi = + gkyl_ambi_bolt_potential_new(&grid, basis, mass_e, charge_e, temp_e, use_gpu); - TEST_CHECK( ambi->cdim == 1); - TEST_CHECK( ambi->num_basis == basis->num_basis); - TEST_CHECK( ambi->use_gpu == use_gpu); - TEST_CHECK( gkyl_compare_double(ambi->dz, 2./8., 1e-12)); - TEST_CHECK( gkyl_compare_double(ambi->mass_e, mass_e, 1e-12)); - TEST_CHECK( gkyl_compare_double(ambi->charge_e, charge_e, 1e-12)); - TEST_CHECK( gkyl_compare_double(ambi->temp_e, temp_e, 1e-12)); + TEST_CHECK(ambi->cdim == 1); + TEST_CHECK(ambi->num_basis == basis->num_basis); + TEST_CHECK(ambi->use_gpu == use_gpu); + TEST_CHECK(gkyl_compare_double(ambi->dz, 2. / 8., 1e-12)); + TEST_CHECK(gkyl_compare_double(ambi->mass_e, mass_e, 1e-12)); + TEST_CHECK(gkyl_compare_double(ambi->charge_e, charge_e, 1e-12)); + TEST_CHECK(gkyl_compare_double(ambi->temp_e, temp_e, 1e-12)); gkyl_free(basis); gkyl_ambi_bolt_potential_release(ambi); } -void -test_ambi_bolt_sheath_calc_1x_ho() +void test_ambi_bolt_sheath_calc_1x_ho() { int poly_order = 1; double lower[] = {-1.0}, upper[] = {1.0}; int cells[] = {8}; - int cdim = sizeof(lower)/sizeof(lower[0]); + int cdim = sizeof(lower) / sizeof(lower[0]); // Grid. struct gkyl_rect_grid grid; @@ -102,28 +101,33 @@ test_ambi_bolt_sheath_calc_1x_ho() struct gkyl_basis *basis; basis = gkyl_cart_modal_serendip_new(cdim, poly_order); - int ghost[] = { 1 }; + int ghost[] = {1}; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); double mass_e = 1.0, charge_e = -1.0, temp_e = 1.0; bool use_gpu = false; - struct gkyl_ambi_bolt_potential *ambi = gkyl_ambi_bolt_potential_new(&grid, basis, mass_e, charge_e, temp_e, use_gpu); + struct gkyl_ambi_bolt_potential *ambi = + gkyl_ambi_bolt_potential_new(&grid, basis, mass_e, charge_e, temp_e, use_gpu); - struct gkyl_array *sheath_vals[2*cdim]; - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -131,54 +135,69 @@ test_ambi_bolt_sheath_calc_1x_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[0], &lower_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[0]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[0], &upper_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[1]); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[0], &lower_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, + sheath_vals[0] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[0], &upper_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, + sheath_vals[1] + ); // Serendipity 1x basis is [1/sqrt(2), sqrt(3/2)x]. // sheath_vals stores both the ion density and sheath value // Ion density is the first 2 components. Should be 1 - // Sheath potential is the second part. + // Sheath potential is the second part. // phi_s = Te/e * log(ni (Te/me) / (sqrt(2*pi) gamma_i J dz/2)) // phi_s = log(1/(sqrt(2*pi) 0.5 * 1/4)) - double *sheath_lower_c = ((double *) gkyl_array_cfetch(sheath_vals[0], 0)); - double *sheath_upper_c = ((double *) gkyl_array_cfetch(sheath_vals[1], 9)); + double *sheath_lower_c = ((double *)gkyl_array_cfetch(sheath_vals[0], 0)); + double *sheath_upper_c = ((double *)gkyl_array_cfetch(sheath_vals[1], 9)); TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], sqrt(2), 1e-12)); TEST_CHECK(gkyl_compare_double(sheath_lower_c[1], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[2], log(1/(sqrt(2*M_PI)*ambi->dz/2))*sqrt(2), 1e-12)); - TEST_MSG(" Got: %.9e | Expected: %.9e\n", sheath_lower_c[2], log(1/(sqrt(2*M_PI)*ambi->dz/2))*sqrt(2)); + TEST_CHECK(gkyl_compare_double( + sheath_lower_c[2], log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)) * sqrt(2), 1e-12 + )); + TEST_MSG( + " Got: %.9e | Expected: %.9e\n", sheath_lower_c[2], + log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)) * sqrt(2) + ); TEST_CHECK(gkyl_compare_double(sheath_lower_c[3], 0, 1e-12)); TEST_CHECK(gkyl_compare_double(sheath_upper_c[0], sqrt(2), 1e-12)); TEST_CHECK(gkyl_compare_double(sheath_upper_c[1], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_upper_c[2], log(1/(sqrt(2*M_PI)*ambi->dz/2))*sqrt(2), 1e-12)); + TEST_CHECK(gkyl_compare_double( + sheath_upper_c[2], log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)) * sqrt(2), 1e-12 + )); TEST_CHECK(gkyl_compare_double(sheath_upper_c[3], 0, 1e-12)); // This operation happens after the sheaths are determined in the app, so we should test this // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - int idx_par = cdim-1, off = 2*idx_par; - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); // Only the lower sheath values are used for computing the field - double *sheath_lower_c_avg = ((double *) gkyl_array_cfetch(sheath_vals[0], 0)); + double *sheath_lower_c_avg = ((double *)gkyl_array_cfetch(sheath_vals[0], 0)); TEST_CHECK(gkyl_compare_double(sheath_lower_c_avg[0], sqrt(2), 1e-12)); TEST_CHECK(gkyl_compare_double(sheath_lower_c_avg[1], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c_avg[2], log(1/(sqrt(2*M_PI)*ambi->dz/2))*sqrt(2), 1e-12)); + TEST_CHECK(gkyl_compare_double( + sheath_lower_c_avg[2], log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)) * sqrt(2), 1e-12 + )); TEST_CHECK(gkyl_compare_double(sheath_lower_c_avg[3], 0, 1e-12)); gkyl_free(basis); - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -233,42 +256,49 @@ test_ambi_bolt_phi_calc_1x_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[0], &lower_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[0]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[0], &upper_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[1]); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[0], &lower_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, + sheath_vals[0] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[0], &upper_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, + sheath_vals[1] + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - int idx_par = cdim-1, off = 2*idx_par; - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); struct gkyl_array *phi = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, - M0, sheath_vals[0], phi); + gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, M0, sheath_vals[0], phi); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { - double *phi_c = ((double *) gkyl_array_cfetch(phi, iter.idx[0])); + double *phi_c = ((double *)gkyl_array_cfetch(phi, iter.idx[0])); // phi should be the same value as the sheath potential - TEST_CHECK(gkyl_compare_double(phi_c[0], log(1/(sqrt(2*M_PI)*ambi->dz/2))*sqrt(2), 1e-12)); + TEST_CHECK( + gkyl_compare_double(phi_c[0], log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)) * sqrt(2), 1e-12) + ); TEST_CHECK(gkyl_compare_double(phi_c[1], 0.0, 1e-12)); } gkyl_free(basis); - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -324,54 +358,67 @@ test_ambi_bolt_sheath_calc_1x_hat_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); - gkyl_proj_on_basis *proj_hat = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_hat, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_hat = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_hat, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_hat, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[0], &lower_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[0]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[0], &upper_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[1]); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[0], &lower_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, + sheath_vals[0] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[0], &upper_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, + sheath_vals[1] + ); // Serendipity 1x basis is [1/sqrt(2), sqrt(3/2)x]. // sheath_vals stores both the ion density and sheath value // Ion density is the first 2 components. Should be 1 - // Sheath potential is the second part. + // Sheath potential is the second part. // phi_s = Te/e * log(ni (Te/me) / (sqrt(2*pi) gamma_i J dz/2)) // phi_s = log(1/(sqrt(2*pi) 0.5 * 1/4)) - double *sheath_lower_c = ((double *) gkyl_array_cfetch(sheath_vals[0], 0)); - double *sheath_upper_c = ((double *) gkyl_array_cfetch(sheath_vals[1], 9)); + double *sheath_lower_c = ((double *)gkyl_array_cfetch(sheath_vals[0], 0)); + double *sheath_upper_c = ((double *)gkyl_array_cfetch(sheath_vals[1], 9)); TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], sqrt(2), 1e-12)); TEST_CHECK(gkyl_compare_double(sheath_lower_c[1], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[2], log(1/(sqrt(2*M_PI)*ambi->dz/2))*sqrt(2), 1e-12)); + TEST_CHECK(gkyl_compare_double( + sheath_lower_c[2], log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)) * sqrt(2), 1e-12 + )); TEST_CHECK(gkyl_compare_double(sheath_lower_c[3], 0, 1e-12)); TEST_CHECK(gkyl_compare_double(sheath_upper_c[0], sqrt(2), 1e-12)); TEST_CHECK(gkyl_compare_double(sheath_upper_c[1], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_upper_c[2], log(1/(sqrt(2*M_PI)*ambi->dz/2))*sqrt(2), 1e-12)); + TEST_CHECK(gkyl_compare_double( + sheath_upper_c[2], log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)) * sqrt(2), 1e-12 + )); TEST_CHECK(gkyl_compare_double(sheath_upper_c[3], 0, 1e-12)); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - int idx_par = cdim-1, off = 2*idx_par; - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); // Only the lower sheath values are used for calculations - double *sheath_lower_c_avg = ((double *) gkyl_array_cfetch(sheath_vals[0], 0)); + double *sheath_lower_c_avg = ((double *)gkyl_array_cfetch(sheath_vals[0], 0)); TEST_CHECK(gkyl_compare_double(sheath_lower_c_avg[0], sqrt(2), 1e-12)); TEST_CHECK(gkyl_compare_double(sheath_lower_c_avg[1], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c_avg[2], log(1/(sqrt(2*M_PI)*ambi->dz/2))*sqrt(2), 1e-12)); + TEST_CHECK(gkyl_compare_double( + sheath_lower_c_avg[2], log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)) * sqrt(2), 1e-12 + )); TEST_CHECK(gkyl_compare_double(sheath_lower_c_avg[3], 0, 1e-12)); gkyl_free(basis); - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -427,45 +478,51 @@ test_ambi_bolt_phi_calc_1x_hat_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); - gkyl_proj_on_basis *proj_hat = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_hat, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_hat = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_hat, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_hat, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[0], &lower_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[0]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[0], &upper_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[1]); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[0], &lower_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, + sheath_vals[0] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[0], &upper_ghost[0], cmag, jacobtot_inv, gamma_i, M0, M0, + sheath_vals[1] + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - int idx_par = cdim-1, off = 2*idx_par; - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); struct gkyl_array *phi = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, - M0, sheath_vals[0], phi); + gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, M0, sheath_vals[0], phi); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local); - double phi_sheath = log(1/(sqrt(2*M_PI)*ambi->dz/2)); + double phi_sheath = log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)); while (gkyl_range_iter_next(&iter)) { - double *phi_c = ((double *) gkyl_array_cfetch(phi, iter.idx[0])); - double *ni_c = ((double *) gkyl_array_cfetch(M0, iter.idx[0])); - double ni = ni_c[0]/sqrt(2); - TEST_CHECK(gkyl_compare_double(phi_c[0]/sqrt(2), phi_sheath + log(ni), 2e-4)); + double *phi_c = ((double *)gkyl_array_cfetch(phi, iter.idx[0])); + double *ni_c = ((double *)gkyl_array_cfetch(M0, iter.idx[0])); + double ni = ni_c[0] / sqrt(2); + TEST_CHECK(gkyl_compare_double(phi_c[0] / sqrt(2), phi_sheath + log(ni), 2e-4)); } gkyl_free(basis); - for (int j=0; jcdim == 2); - TEST_CHECK( ambi->num_basis == basis->num_basis); - TEST_CHECK( ambi->use_gpu == use_gpu); - TEST_CHECK( gkyl_compare_double(ambi->dz, 2./16., 1e-12)); // Second direction is field line length - TEST_CHECK( gkyl_compare_double(ambi->mass_e, mass_e, 1e-12)); - TEST_CHECK( gkyl_compare_double(ambi->charge_e, charge_e, 1e-12)); - TEST_CHECK( gkyl_compare_double(ambi->temp_e, temp_e, 1e-12)); + TEST_CHECK(ambi->cdim == 2); + TEST_CHECK(ambi->num_basis == basis->num_basis); + TEST_CHECK(ambi->use_gpu == use_gpu); + TEST_CHECK(gkyl_compare_double(ambi->dz, 2. / 16., 1e-12) + ); // Second direction is field line length + TEST_CHECK(gkyl_compare_double(ambi->mass_e, mass_e, 1e-12)); + TEST_CHECK(gkyl_compare_double(ambi->charge_e, charge_e, 1e-12)); + TEST_CHECK(gkyl_compare_double(ambi->temp_e, temp_e, 1e-12)); gkyl_free(basis); gkyl_ambi_bolt_potential_release(ambi); } -void -test_ambi_bolt_sheath_calc_2x_one_ho() +void test_ambi_bolt_sheath_calc_2x_one_ho() { int poly_order = 1; double lower[] = {-1.0, -1.0}, upper[] = {1.0, 1.0}; int cells[] = {8, 16}; - int cdim = sizeof(lower)/sizeof(lower[0]); + int cdim = sizeof(lower) / sizeof(lower[0]); // Grid. struct gkyl_rect_grid grid; @@ -530,28 +587,33 @@ test_ambi_bolt_sheath_calc_2x_one_ho() struct gkyl_basis *basis; basis = gkyl_cart_modal_serendip_new(cdim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); double mass_e = 1.0, charge_e = -1.0, temp_e = 1.0; bool use_gpu = false; - struct gkyl_ambi_bolt_potential *ambi = gkyl_ambi_bolt_potential_new(&grid, basis, mass_e, charge_e, temp_e, use_gpu); + struct gkyl_ambi_bolt_potential *ambi = + gkyl_ambi_bolt_potential_new(&grid, basis, mass_e, charge_e, temp_e, use_gpu); - struct gkyl_array *sheath_vals[2*cdim]; - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -559,57 +621,68 @@ test_ambi_bolt_sheath_calc_2x_one_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - int idx_par = cdim-1, off = 2*idx_par; - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off + 1] + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); // Serendipity 2x basis is [1/2,(sqrt(3)*x)/2,(sqrt(3)*y)/2,(3*x*y)/2]. // sheath_vals stores both the ion density and sheath value // Ion density is the first 2 components. Should be 1 - // Sheath potential is the second part. + // Sheath potential is the second part. // phi_s = Te/e * log(ni (Te/me) / (sqrt(2*pi) gamma_i J dz/2)) // phi_s = log(1/(sqrt(2*pi) 0.5 * 1/4)) - double phi_sheath = log(1/(sqrt(2*M_PI)*ambi->dz/2)); + double phi_sheath = log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)); struct gkyl_range_iter iter; - for (int ix_cdim = 0; ix_cdim < cdim; ix_cdim++) - { + for (int ix_cdim = 0; ix_cdim < cdim; ix_cdim++) { // Only the lower cells are used to calculate the field gkyl_range_iter_init(&iter, &lower_ghost[ix_cdim]); while (gkyl_range_iter_next(&iter)) { long lidx = gkyl_range_idx(&lower_ghost[ix_cdim], iter.idx); - double *sheath_lower_c = ((double *) gkyl_array_cfetch(sheath_vals[off], lidx)); - if (ix_cdim == 1) TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], 2, 1e-12)); - else TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[1], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[2], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[3], 0, 1e-12)); - if (ix_cdim == 1) TEST_CHECK(gkyl_compare_double(sheath_lower_c[4], phi_sheath*2, 1e-12)); - else TEST_CHECK(gkyl_compare_double(sheath_lower_c[4], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[5], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[6], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[7], 0, 1e-12)); + double *sheath_lower_c = ((double *)gkyl_array_cfetch(sheath_vals[off], lidx)); + if (ix_cdim == 1) { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], 2, 1e-12)); + } else { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], 0, 1e-12)); + } + TEST_CHECK(gkyl_compare_double(sheath_lower_c[1], 0, 1e-12)); + TEST_CHECK(gkyl_compare_double(sheath_lower_c[2], 0, 1e-12)); + TEST_CHECK(gkyl_compare_double(sheath_lower_c[3], 0, 1e-12)); + if (ix_cdim == 1) { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[4], phi_sheath * 2, 1e-12)); + } else { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[4], 0, 1e-12)); + } + TEST_CHECK(gkyl_compare_double(sheath_lower_c[5], 0, 1e-12)); + TEST_CHECK(gkyl_compare_double(sheath_lower_c[6], 0, 1e-12)); + TEST_CHECK(gkyl_compare_double(sheath_lower_c[7], 0, 1e-12)); } } - + gkyl_free(basis); - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -664,58 +741,70 @@ test_ambi_bolt_sheath_calc_2x_hat_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); - gkyl_proj_on_basis *proj_hat = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_hat_2x, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_hat = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_hat_2x, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_hat, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - int idx_par = cdim-1, off = 2*idx_par; - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off + 1] + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); // Serendipity 2x basis is [1/2,(sqrt(3)*x)/2,(sqrt(3)*y)/2,(3*x*y)/2]. // sheath_vals stores both the ion density and sheath value // Ion density is the first 2 components. Should be 1 - // Sheath potential is the second part. + // Sheath potential is the second part. // phi_s = Te/e * log(ni (Te/me) / (sqrt(2*pi) gamma_i J dz/2)) // phi_s = log(1/(sqrt(2*pi) 0.5 * 1/4)) - double phi_sheath = log(1/(sqrt(2*M_PI)*ambi->dz/2)); + double phi_sheath = log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)); struct gkyl_range_iter iter; - for (int ix_cdim = 0; ix_cdim < cdim; ix_cdim++) - { + for (int ix_cdim = 0; ix_cdim < cdim; ix_cdim++) { // Only the lower cells are used to calculate the field gkyl_range_iter_init(&iter, &lower_ghost[ix_cdim]); while (gkyl_range_iter_next(&iter)) { long lidx = gkyl_range_idx(&lower_ghost[ix_cdim], iter.idx); - double *sheath_lower_c = ((double *) gkyl_array_cfetch(sheath_vals[off], lidx)); - if (ix_cdim == 1) TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], 2, 1e-12)); - else TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[1], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[2], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[3], 0, 1e-12)); - if (ix_cdim == 1) TEST_CHECK(gkyl_compare_double(sheath_lower_c[4], phi_sheath*2, 1e-12)); - else TEST_CHECK(gkyl_compare_double(sheath_lower_c[4], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[5], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[6], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[7], 0, 1e-12)); + double *sheath_lower_c = ((double *)gkyl_array_cfetch(sheath_vals[off], lidx)); + if (ix_cdim == 1) { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], 2, 1e-12)); + } else { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], 0, 1e-12)); + } + TEST_CHECK(gkyl_compare_double(sheath_lower_c[1], 0, 1e-12)); + TEST_CHECK(gkyl_compare_double(sheath_lower_c[2], 0, 1e-12)); + TEST_CHECK(gkyl_compare_double(sheath_lower_c[3], 0, 1e-12)); + if (ix_cdim == 1) { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[4], phi_sheath * 2, 1e-12)); + } else { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[4], 0, 1e-12)); + } + TEST_CHECK(gkyl_compare_double(sheath_lower_c[5], 0, 1e-12)); + TEST_CHECK(gkyl_compare_double(sheath_lower_c[6], 0, 1e-12)); + TEST_CHECK(gkyl_compare_double(sheath_lower_c[7], 0, 1e-12)); } } - + gkyl_free(basis); - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -771,58 +864,73 @@ test_ambi_bolt_sheath_calc_2x_ramp_sheath_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); - gkyl_proj_on_basis *proj_ramp = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_ramp_sheath_2x, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_ramp = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_ramp_sheath_2x, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_ramp, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - int idx_par = cdim-1, off = 2*idx_par; - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off + 1] + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); // Serendipity 2x basis is [1/2,(sqrt(3)*x)/2,(sqrt(3)*y)/2,(3*x*y)/2]. // sheath_vals stores both the ion density and sheath value // Ion density is the first 2 components. Should be 1 - // Sheath potential is the second part. + // Sheath potential is the second part. // phi_s = Te/e * log(ni (Te/me) / (sqrt(2*pi) gamma_i J dz/2)) struct gkyl_range_iter iter; - for (int ix_cdim = 0; ix_cdim < cdim; ix_cdim++) - { + for (int ix_cdim = 0; ix_cdim < cdim; ix_cdim++) { // Only the lower cells are used to calculate the field gkyl_range_iter_init(&iter, &lower_ghost[ix_cdim]); while (gkyl_range_iter_next(&iter)) { long lidx = gkyl_range_idx(&lower_ghost[ix_cdim], iter.idx); - double *sheath_lower_c = ((double *) gkyl_array_cfetch(sheath_vals[off], lidx)); - double *density_c = ((double *) gkyl_array_cfetch(M0, lidx)); - double phi_sheath = log((density_c[0]/2)/(sqrt(2*M_PI)*ambi->dz/2)); - if (ix_cdim == 1) TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], density_c[0], 1e-12)); - else TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], 0, 1e-12)); - if (ix_cdim == 1) TEST_CHECK(gkyl_compare_double(sheath_lower_c[1], density_c[1], 1e-12)); - else TEST_CHECK(gkyl_compare_double(sheath_lower_c[1], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[2], 0, 1e-12)); - TEST_CHECK(gkyl_compare_double(sheath_lower_c[3], 0, 1e-12)); - // Not exact because division happens at quadrature nodes - if (ix_cdim == 1) TEST_CHECK(gkyl_compare_double(sheath_lower_c[4]/2, phi_sheath, 1e-3)); - else TEST_CHECK(gkyl_compare_double(sheath_lower_c[4], 0, 1e-12)); - // Slope of sheath potential is difficult to calculate + double *sheath_lower_c = ((double *)gkyl_array_cfetch(sheath_vals[off], lidx)); + double *density_c = ((double *)gkyl_array_cfetch(M0, lidx)); + double phi_sheath = log((density_c[0] / 2) / (sqrt(2 * M_PI) * ambi->dz / 2)); + if (ix_cdim == 1) { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], density_c[0], 1e-12)); + } else { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[0], 0, 1e-12)); + } + if (ix_cdim == 1) { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[1], density_c[1], 1e-12)); + } else { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[1], 0, 1e-12)); + } + TEST_CHECK(gkyl_compare_double(sheath_lower_c[2], 0, 1e-12)); + TEST_CHECK(gkyl_compare_double(sheath_lower_c[3], 0, 1e-12)); + // Not exact because division happens at quadrature nodes + if (ix_cdim == 1) { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[4] / 2, phi_sheath, 1e-3)); + } else { + TEST_CHECK(gkyl_compare_double(sheath_lower_c[4], 0, 1e-12)); + } + // Slope of sheath potential is difficult to calculate } } - + gkyl_free(basis); - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -878,46 +990,51 @@ test_ambi_bolt_phi_calc_2x_one_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - int idx_par = cdim-1, off = 2*idx_par; - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off + 1] + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); struct gkyl_array *phi = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, - M0, sheath_vals[off], phi); + gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, M0, sheath_vals[off], phi); - double phi_sheath = log(1/(sqrt(2*M_PI)*ambi->dz/2)); + double phi_sheath = log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long lidx = gkyl_range_idx(&local, iter.idx); - double *phi_c = ((double *) gkyl_array_cfetch(phi, lidx)); - TEST_CHECK(gkyl_compare_double(phi_c[0]/2, phi_sheath, 1e-12)); + double *phi_c = ((double *)gkyl_array_cfetch(phi, lidx)); + TEST_CHECK(gkyl_compare_double(phi_c[0] / 2, phi_sheath, 1e-12)); TEST_CHECK(gkyl_compare_double(phi_c[1], 0.0, 1e-12)); TEST_CHECK(gkyl_compare_double(phi_c[2], 0.0, 1e-12)); TEST_CHECK(gkyl_compare_double(phi_c[3], 0.0, 1e-12)); } gkyl_free(basis); - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -973,46 +1094,52 @@ test_ambi_bolt_phi_calc_2x_hat_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); - gkyl_proj_on_basis *proj_hat = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_hat_2x, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_hat = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_hat_2x, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_hat, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - int idx_par = cdim-1, off = 2*idx_par; - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off + 1] + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); struct gkyl_array *phi = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, - M0, sheath_vals[off], phi); + gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, M0, sheath_vals[off], phi); - double phi_sheath = log(1/(sqrt(2*M_PI)*ambi->dz/2)); + double phi_sheath = log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long lidx = gkyl_range_idx(&local, iter.idx); - double *phi_c = ((double *) gkyl_array_cfetch(phi, lidx)); - double *ni_c = ((double *) gkyl_array_cfetch(M0, lidx)); - double ni = ni_c[0]/2; - TEST_CHECK(gkyl_compare_double(phi_c[0]/2, phi_sheath + log(ni), 1e-3)); + double *phi_c = ((double *)gkyl_array_cfetch(phi, lidx)); + double *ni_c = ((double *)gkyl_array_cfetch(M0, lidx)); + double ni = ni_c[0] / 2; + TEST_CHECK(gkyl_compare_double(phi_c[0] / 2, phi_sheath + log(ni), 1e-3)); } gkyl_free(basis); - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -1069,46 +1200,52 @@ test_ambi_bolt_phi_calc_2x_ramp_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); - gkyl_proj_on_basis *proj_ramp = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_ramp_sheath_2x, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_ramp = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_ramp_sheath_2x, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_ramp, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - int idx_par = cdim-1, off = 2*idx_par; - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off + 1] + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); struct gkyl_array *phi = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, - M0, sheath_vals[off], phi); + gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, M0, sheath_vals[off], phi); - double phi_sheath = log(1/(sqrt(2*M_PI)*ambi->dz/2)); + double phi_sheath = log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { long lidx = gkyl_range_idx(&local, iter.idx); - double *phi_c = ((double *) gkyl_array_cfetch(phi, lidx)); - double *ni_c = ((double *) gkyl_array_cfetch(M0, lidx)); - double ni = ni_c[0]/2; - TEST_CHECK(gkyl_compare_double(phi_c[0]/2, phi_sheath + log(ni), 1e-3)); + double *phi_c = ((double *)gkyl_array_cfetch(phi, lidx)); + double *ni_c = ((double *)gkyl_array_cfetch(M0, lidx)); + double ni = ni_c[0] / 2; + TEST_CHECK(gkyl_compare_double(phi_c[0] / 2, phi_sheath + log(ni), 1e-3)); } gkyl_free(basis); - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -1165,52 +1306,58 @@ test_ambi_bolt_phi_calc_2x_parabola_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); - gkyl_proj_on_basis *proj_func = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_parabola_2x, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_func = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_parabola_2x, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_func, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - int idx_par = cdim-1, off = 2*idx_par; - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off + 1] + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); struct gkyl_array *phi = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, - M0, sheath_vals[off], phi); + gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, M0, sheath_vals[off], phi); struct gkyl_range_iter iter; int idx_ghost[GKYL_MAX_CDIM]; gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { gkyl_copy_int_arr(cdim, iter.idx, idx_ghost); - idx_ghost[cdim-1] = local_ext.lower[cdim-1]; + idx_ghost[cdim - 1] = local_ext.lower[cdim - 1]; long lidx = gkyl_range_idx(&local, iter.idx); long ghost_lidx = gkyl_range_idx(&local_ext, idx_ghost); - double *phi_c = ((double *) gkyl_array_cfetch(phi, lidx)); - double *ni_c = ((double *) gkyl_array_cfetch(M0, lidx)); - double *sheath_vals_c = ((double *) gkyl_array_cfetch(sheath_vals[off], ghost_lidx)); - double ni = ni_c[0]/2; - double ni_sheath = sheath_vals_c[0]/2; - double phi_sheath = sheath_vals_c[4]/2; - TEST_CHECK(gkyl_compare_double(phi_c[0]/2, phi_sheath + log(ni/ni_sheath), 1e-6)); + double *phi_c = ((double *)gkyl_array_cfetch(phi, lidx)); + double *ni_c = ((double *)gkyl_array_cfetch(M0, lidx)); + double *sheath_vals_c = ((double *)gkyl_array_cfetch(sheath_vals[off], ghost_lidx)); + double ni = ni_c[0] / 2; + double ni_sheath = sheath_vals_c[0] / 2; + double phi_sheath = sheath_vals_c[4] / 2; + TEST_CHECK(gkyl_compare_double(phi_c[0] / 2, phi_sheath + log(ni / ni_sheath), 1e-6)); } gkyl_free(basis); - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -1267,55 +1418,63 @@ test_ambi_bolt_phi_calc_3x_one_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); - gkyl_proj_on_basis *proj_func = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_func = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_func, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - int idx_par = cdim-1, off = 2*idx_par; - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off + 1] + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); struct gkyl_array *phi = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, - M0, sheath_vals[off], phi); + gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, M0, sheath_vals[off], phi); struct gkyl_range_iter iter; int idx_ghost[GKYL_MAX_CDIM]; - double known_phi_sheath = log(1/(sqrt(2*M_PI)*ambi->dz/2)); + double known_phi_sheath = log(1 / (sqrt(2 * M_PI) * ambi->dz / 2)); gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { gkyl_copy_int_arr(cdim, iter.idx, idx_ghost); - idx_ghost[cdim-1] = local_ext.lower[cdim-1]; + idx_ghost[cdim - 1] = local_ext.lower[cdim - 1]; long lidx = gkyl_range_idx(&local, iter.idx); long ghost_lidx = gkyl_range_idx(&local_ext, idx_ghost); - double *phi_c = ((double *) gkyl_array_cfetch(phi, lidx)); - double *ni_c = ((double *) gkyl_array_cfetch(M0, lidx)); - double *sheath_vals_c = ((double *) gkyl_array_cfetch(sheath_vals[off], ghost_lidx)); - double ni = ni_c[0]/pow(2.,3./2.); - double ni_sheath = sheath_vals_c[0]/pow(2.,3./2.); - double phi_sheath = sheath_vals_c[8]/pow(2.,3./2.); // 8 coefficients in serendipity 3xP1 + double *phi_c = ((double *)gkyl_array_cfetch(phi, lidx)); + double *ni_c = ((double *)gkyl_array_cfetch(M0, lidx)); + double *sheath_vals_c = ((double *)gkyl_array_cfetch(sheath_vals[off], ghost_lidx)); + double ni = ni_c[0] / pow(2., 3. / 2.); + double ni_sheath = sheath_vals_c[0] / pow(2., 3. / 2.); + double phi_sheath = sheath_vals_c[8] / pow(2., 3. / 2.); // 8 coefficients in serendipity 3xP1 TEST_CHECK(gkyl_compare_double(ni_sheath, 1.0, 1e-12)); TEST_CHECK(gkyl_compare_double(phi_sheath, known_phi_sheath, 1e-12)); - TEST_CHECK(gkyl_compare_double(phi_c[0]/pow(2.,3./2.), phi_sheath + log(ni/ni_sheath), 1e-12)); + TEST_CHECK( + gkyl_compare_double(phi_c[0] / pow(2., 3. / 2.), phi_sheath + log(ni / ni_sheath), 1e-12) + ); } gkyl_free(basis); - for (int j=0; jnum_basis, local_ext.volume); - sheath_vals[2*j+1] = gkyl_array_new(GKYL_DOUBLE, 2*basis->num_basis, local_ext.volume); - gkyl_array_clear(sheath_vals[2*j], 0.0); - gkyl_array_clear(sheath_vals[2*j+1], 0.0); + struct gkyl_array *sheath_vals[2 * cdim]; + for (int j = 0; j < cdim; ++j) { + sheath_vals[2 * j] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + sheath_vals[2 * j + 1] = gkyl_array_new(GKYL_DOUBLE, 2 * basis->num_basis, local_ext.volume); + gkyl_array_clear(sheath_vals[2 * j], 0.0); + gkyl_array_clear(sheath_vals[2 * j + 1], 0.0); } // Local skin and ghost ranges for configuration space fields. struct gkyl_range lower_skin[cdim], lower_ghost[cdim], upper_skin[cdim], upper_ghost[cdim]; - for (int dir=0; dirnum_basis, local_ext.volume); @@ -1372,52 +1535,60 @@ test_ambi_bolt_phi_calc_3x_parabola_ho() struct gkyl_array *M0 = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); struct gkyl_array *gamma_i = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_one = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_one, NULL); - gkyl_proj_on_basis *proj_func = gkyl_proj_on_basis_new(&grid, basis, poly_order+1, 1, eval_parabola_3x, NULL); + gkyl_proj_on_basis *proj_one = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_one, NULL); + gkyl_proj_on_basis *proj_func = + gkyl_proj_on_basis_new(&grid, basis, poly_order + 1, 1, eval_parabola_3x, NULL); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, jacobtot_inv); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, cmag); gkyl_proj_on_basis_advance(proj_func, 0.0, &local_ext, M0); gkyl_proj_on_basis_advance(proj_one, 0.0, &local_ext, gamma_i); - int idx_par = cdim-1, off = 2*idx_par; - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_LOWER_EDGE, - &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off]); - gkyl_ambi_bolt_potential_sheath_calc(ambi, GKYL_UPPER_EDGE, - &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, M0, M0, sheath_vals[off+1]); + int idx_par = cdim - 1, off = 2 * idx_par; + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_LOWER_EDGE, &lower_skin[idx_par], &lower_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off] + ); + gkyl_ambi_bolt_potential_sheath_calc( + ambi, GKYL_UPPER_EDGE, &upper_skin[idx_par], &upper_ghost[idx_par], cmag, jacobtot_inv, gamma_i, + M0, M0, sheath_vals[off + 1] + ); // Copy upper sheath values into lower ghost & add to lower sheath values for averaging. - gkyl_array_copy_range_to_range(sheath_vals[off+1], sheath_vals[off+1], - &lower_ghost[idx_par], &upper_ghost[idx_par]); - gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off+1]); + gkyl_array_copy_range_to_range( + sheath_vals[off + 1], sheath_vals[off + 1], &lower_ghost[idx_par], &upper_ghost[idx_par] + ); + gkyl_array_accumulate(sheath_vals[off], 1., sheath_vals[off + 1]); gkyl_array_scale(sheath_vals[off], 0.5); struct gkyl_array *phi = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, local_ext.volume); - gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, - M0, sheath_vals[off], phi); + gkyl_ambi_bolt_potential_phi_calc(ambi, &local, &local_ext, M0, sheath_vals[off], phi); struct gkyl_range_iter iter; int idx_ghost[GKYL_MAX_CDIM]; gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { gkyl_copy_int_arr(cdim, iter.idx, idx_ghost); - idx_ghost[cdim-1] = local_ext.lower[cdim-1]; + idx_ghost[cdim - 1] = local_ext.lower[cdim - 1]; long lidx = gkyl_range_idx(&local, iter.idx); long ghost_lidx = gkyl_range_idx(&local_ext, idx_ghost); - double *phi_c = ((double *) gkyl_array_cfetch(phi, lidx)); - double *ni_c = ((double *) gkyl_array_cfetch(M0, lidx)); - double *sheath_vals_c = ((double *) gkyl_array_cfetch(sheath_vals[off], ghost_lidx)); - double ni = ni_c[0]/pow(2.,3./2.); // 1st coefficient is 1/2^(3/2) - double ni_sheath = sheath_vals_c[0]/pow(2.,3./2.); - double phi_sheath = sheath_vals_c[8]/pow(2.,3./2.); // 8 coefficients in serendipity 3xP1 - TEST_CHECK(gkyl_compare_double(phi_c[0]/pow(2.,3./2.), phi_sheath + log(ni/ni_sheath), 1e-5)); + double *phi_c = ((double *)gkyl_array_cfetch(phi, lidx)); + double *ni_c = ((double *)gkyl_array_cfetch(M0, lidx)); + double *sheath_vals_c = ((double *)gkyl_array_cfetch(sheath_vals[off], ghost_lidx)); + double ni = ni_c[0] / pow(2., 3. / 2.); // 1st coefficient is 1/2^(3/2) + double ni_sheath = sheath_vals_c[0] / pow(2., 3. / 2.); + double phi_sheath = sheath_vals_c[8] / pow(2., 3. / 2.); // 8 coefficients in serendipity 3xP1 + TEST_CHECK( + gkyl_compare_double(phi_c[0] / pow(2., 3. / 2.), phi_sheath + log(ni / ni_sheath), 1e-5) + ); } gkyl_free(basis); - for (int j=0; j #include - #include #include #include @@ -28,34 +27,34 @@ #include #include - - - - // Z is constant at 8.429 // R goes from 4.9 to 5.9 -void horizontal_pfunc_upper(double s, double* RZ){ +void horizontal_pfunc_upper(double s, double *RZ) +{ RZ[0] = 4.9 + s; RZ[1] = 8.429; } // Z is constant at -8.429 // R goes from 4.9 to 5.3 -void horizontal_pfunc_lower(double s, double* RZ){ +void horizontal_pfunc_lower(double s, double *RZ) +{ RZ[0] = 4.9 + s; RZ[1] = -8.429; } // R is constant at 4.9 // R goes from 8.0 to 8.5 -void vertical_pfunc_upper(double s, double* RZ){ +void vertical_pfunc_upper(double s, double *RZ) +{ RZ[0] = 4.9; - RZ[1] = 8.0 + s/2; + RZ[1] = 8.0 + s / 2; } -void vertical_pfunc_lower(double s, double* RZ){ +void vertical_pfunc_lower(double s, double *RZ) +{ RZ[0] = 4.9; - RZ[1] = -8.0 - s/2; + RZ[1] = -8.0 - s / 2; } // Actual Plate info: @@ -65,106 +64,101 @@ void vertical_pfunc_lower(double s, double* RZ){ // Try a Different (slanted) plate instead // p1 [5.151,8.516] // p2 [5.852, 8.434] -void shaped_pfunc_upper(double s, double* RZ){ - RZ[0] = 0.8 + (0.916 - 0.8)*s; - RZ[1] = -1.2 + (-1.329 + 1.2)*s; +void shaped_pfunc_upper(double s, double *RZ) +{ + RZ[0] = 0.8 + (0.916 - 0.8) * s; + RZ[1] = -1.2 + (-1.329 + 1.2) * s; } -void shaped_pfunc_lower(double s, double* RZ){ - RZ[0] = 1.6 + (1.8 - 1.6)*s; - RZ[1] = -1.26 + (-1.1 + 1.26)*s; +void shaped_pfunc_lower(double s, double *RZ) +{ + RZ[0] = 1.6 + (1.8 - 1.6) * s; + RZ[1] = -1.26 + (-1.1 + 1.26) * s; } -void -write_geometry(gk_geometry *up, struct gkyl_rect_grid grid, struct gkyl_basis basis, struct gkyl_range local, const char *name) +void write_geometry( + gk_geometry *up, struct gkyl_rect_grid grid, struct gkyl_basis basis, struct gkyl_range local, + const char *name +) { const char *fmt = "%s-%s.gkyl"; int sz = gkyl_calc_strlen(fmt, name, "jacobtot_inv"); - char fileNm[sz+1]; // ensure no buffer overflow + char fileNm[sz + 1]; // ensure no buffer overflow sprintf(fileNm, fmt, name, "mapc2p"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2p, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2p, fileNm); sprintf(fileNm, fmt, name, "bmag"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag, fileNm); sprintf(fileNm, fmt, name, "g_ij"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.g_ij, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.g_ij, fileNm); sprintf(fileNm, fmt, name, "dxdz"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dxdz, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dxdz, fileNm); sprintf(fileNm, fmt, name, "dzdx"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dzdx, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dzdx, fileNm); sprintf(fileNm, fmt, name, "normals"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.normals, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.normals, fileNm); sprintf(fileNm, fmt, name, "jacobgeo"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo, fileNm); sprintf(fileNm, fmt, name, "jacobgeo_inv"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo_inv, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo_inv, fileNm); sprintf(fileNm, fmt, name, "gij"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gij, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gij, fileNm); sprintf(fileNm, fmt, name, "b_i"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.b_i, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.b_i, fileNm); sprintf(fileNm, fmt, name, "bcart"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bcart, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bcart, fileNm); sprintf(fileNm, fmt, name, "cmag"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.cmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.cmag, fileNm); sprintf(fileNm, fmt, name, "jacobtot"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot, fileNm); sprintf(fileNm, fmt, name, "jacobtot_inv"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot_inv, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot_inv, fileNm); sprintf(fileNm, fmt, name, "gxxj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxxj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxxj, fileNm); sprintf(fileNm, fmt, name, "gxyj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxyj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxyj, fileNm); sprintf(fileNm, fmt, name, "gyyj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gyyj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gyyj, fileNm); sprintf(fileNm, fmt, name, "gxzj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxzj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxzj, fileNm); sprintf(fileNm, fmt, name, "eps2"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.eps2, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.eps2, fileNm); // Write Nodal Coordinates struct gkyl_range nrange; gkyl_gk_geometry_init_nodal_range(&nrange, &local, 1); - struct gkyl_array* mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); + struct gkyl_array *mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&basis, &grid, false); gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange, &local, 3, mc2p_nodal, up->geo_corn.mc2p, false); gkyl_nodal_ops_release(n2m); struct gkyl_rect_grid ngrid; gkyl_gk_geometry_init_nodal_grid(&ngrid, &grid, &nrange); sprintf(fileNm, fmt, name, "nodes"); - gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, fileNm); + gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, fileNm); gkyl_array_release(mc2p_nodal); } - - - -void -test_asdex_fixed_z_ho() +void test_asdex_fixed_z_ho() { clock_t start, end; double cpu_time_used; start = clock(); + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1 + }; + double clower[] = {0.16, -0.01, -M_PI + 1e-14}; + double cupper[] = {0.17501, 0.01, M_PI - 1e-14}; - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, - }; - - double clower[] = { 0.16, -0.01, -M_PI+1e-14 }; - double cupper[] = {0.17501, 0.01, M_PI-1e-14 }; - - int ccells[] = { 2, 1, 2 }; - - + int ccells[] = {2, 1, 2}; struct gkyl_rect_grid cgrid; gkyl_rect_grid_init(&cgrid, 3, clower, cupper, ccells); struct gkyl_range clocal, clocal_ext; - int cnghost[GKYL_MAX_CDIM] = { 1, 1, 1 }; + int cnghost[GKYL_MAX_CDIM] = {1, 1, 1}; gkyl_create_grid_ranges(&cgrid, cnghost, &clocal_ext, &clocal); int cpoly_order = 1; struct gkyl_basis cbasis; @@ -182,10 +176,10 @@ test_asdex_fixed_z_ho() .zmin = -1.3, .zmax = 1.0, .zmin_left = -1.3, - .zmin_right = -1.3, - }; + .zmin_right = -1.3 + }; struct gkyl_gk_geometry_inp geometry_inp = { - .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, .efit_info = efit_inp, .tok_grid_info = ginp, .position_map = pmap, @@ -200,44 +194,38 @@ test_asdex_fixed_z_ho() .geo_local_ext = clocal_ext, .geo_global = clocal, .geo_global_ext = clocal_ext, - .geo_basis = cbasis, + .geo_basis = cbasis }; - struct gk_geometry* up = gkyl_gk_geometry_tok_new(&geometry_inp); + struct gk_geometry *up = gkyl_gk_geometry_tok_new(&geometry_inp); gkyl_gk_geometry_release(up); gkyl_position_map_release(pmap); end = clock(); - cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC; } -void -test_asdex_shaped_plate_ho() +void test_asdex_shaped_plate_ho() { clock_t start, end; double cpu_time_used; start = clock(); + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1 + }; + double clower[] = {0.16, -0.01, -M_PI + 1e-14}; + double cupper[] = {0.17501, 0.01, M_PI - 1e-14}; - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, - }; - - double clower[] = { 0.16, -0.01, -M_PI+1e-14 }; - double cupper[] = {0.17501, 0.01, M_PI-1e-14 }; - - int ccells[] = { 2, 1, 2 }; - - + int ccells[] = {2, 1, 2}; struct gkyl_rect_grid cgrid; gkyl_rect_grid_init(&cgrid, 3, clower, cupper, ccells); struct gkyl_range clocal, clocal_ext; - int cnghost[GKYL_MAX_CDIM] = { 1, 1, 1 }; + int cnghost[GKYL_MAX_CDIM] = {1, 1, 1}; gkyl_create_grid_ranges(&cgrid, cnghost, &clocal_ext, &clocal); int cpoly_order = 1; struct gkyl_basis cbasis; @@ -255,10 +243,10 @@ test_asdex_shaped_plate_ho() .zmin = -1.3, .zmax = 1.0, .zmin_left = -1.2, - .zmin_right = -1.0, - }; + .zmin_right = -1.0 + }; struct gkyl_gk_geometry_inp geometry_inp = { - .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, .efit_info = efit_inp, .tok_grid_info = ginp, .position_map = pmap, @@ -273,37 +261,33 @@ test_asdex_shaped_plate_ho() .geo_local_ext = clocal_ext, .geo_global = clocal, .geo_global_ext = clocal_ext, - .geo_basis = cbasis, + .geo_basis = cbasis }; - struct gk_geometry* up = gkyl_gk_geometry_tok_new(&geometry_inp); + struct gk_geometry *up = gkyl_gk_geometry_tok_new(&geometry_inp); //write_geometry(up, cgrid, cbasis, clocal, "asdex"); gkyl_gk_geometry_release(up); gkyl_position_map_release(pmap); end = clock(); - cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC; } -void -test_asdex_lower_ho() +void test_asdex_lower_ho() { clock_t start, end; double cpu_time_used; start = clock(); + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1 + }; - - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, - }; - - double clower[] = { 0.16, -0.01, -M_PI+1e-14 }; - double cupper[] = {0.17501, 0.01, M_PI-1e-14 }; - int ccells[] = { 2, 1, 2 }; + double clower[] = {0.16, -0.01, -M_PI + 1e-14}; + double cupper[] = {0.17501, 0.01, M_PI - 1e-14}; + int ccells[] = {2, 1, 2}; struct gkyl_tok_geo_grid_inp ginp = { .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO, @@ -315,14 +299,14 @@ test_asdex_lower_ho() .zmin = -1.3, .zmax = 1.0, .zmin_left = -1.2, - .zmin_right = -1.0, - }; + .zmin_right = -1.0 + }; gkyl_gk_geometry_tok_set_grid_extents(efit_inp, ginp, &clower[2], &cupper[2]); struct gkyl_rect_grid cgrid; gkyl_rect_grid_init(&cgrid, 3, clower, cupper, ccells); struct gkyl_range clocal, clocal_ext; - int cnghost[GKYL_MAX_CDIM] = { 1, 1, 1 }; + int cnghost[GKYL_MAX_CDIM] = {1, 1, 1}; gkyl_create_grid_ranges(&cgrid, cnghost, &clocal_ext, &clocal); int cpoly_order = 1; struct gkyl_basis cbasis; @@ -331,7 +315,7 @@ test_asdex_lower_ho() struct gkyl_position_map *pmap = gkyl_position_map_null_new(); struct gkyl_gk_geometry_inp geometry_inp = { - .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, .efit_info = efit_inp, .tok_grid_info = ginp, .position_map = pmap, @@ -346,37 +330,33 @@ test_asdex_lower_ho() .geo_local_ext = clocal_ext, .geo_global = clocal, .geo_global_ext = clocal_ext, - .geo_basis = cbasis, + .geo_basis = cbasis }; - struct gk_geometry* up = gkyl_gk_geometry_tok_new(&geometry_inp); + struct gk_geometry *up = gkyl_gk_geometry_tok_new(&geometry_inp); //write_geometry(up, cgrid, cbasis, clocal, "asdexlo"); gkyl_gk_geometry_release(up); gkyl_position_map_release(pmap); end = clock(); - cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC; } -void -test_asdex_middle_ho() +void test_asdex_middle_ho() { clock_t start, end; double cpu_time_used; start = clock(); + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1 + }; - - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, - }; - - double clower[] = { 0.16, -0.01, -M_PI+1e-14 }; - double cupper[] = {0.17501, 0.01, M_PI-1e-14 }; - int ccells[] = { 2, 1, 2 }; + double clower[] = {0.16, -0.01, -M_PI + 1e-14}; + double cupper[] = {0.17501, 0.01, M_PI - 1e-14}; + int ccells[] = {2, 1, 2}; struct gkyl_tok_geo_grid_inp ginp = { .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID, @@ -388,14 +368,14 @@ test_asdex_middle_ho() .zmin = -1.3, .zmax = 1.0, .zmin_left = -1.2, - .zmin_right = -1.0, - }; + .zmin_right = -1.0 + }; gkyl_gk_geometry_tok_set_grid_extents(efit_inp, ginp, &clower[2], &cupper[2]); struct gkyl_rect_grid cgrid; gkyl_rect_grid_init(&cgrid, 3, clower, cupper, ccells); struct gkyl_range clocal, clocal_ext; - int cnghost[GKYL_MAX_CDIM] = { 1, 1, 1 }; + int cnghost[GKYL_MAX_CDIM] = {1, 1, 1}; gkyl_create_grid_ranges(&cgrid, cnghost, &clocal_ext, &clocal); int cpoly_order = 1; struct gkyl_basis cbasis; @@ -404,7 +384,7 @@ test_asdex_middle_ho() struct gkyl_position_map *pmap = gkyl_position_map_null_new(); struct gkyl_gk_geometry_inp geometry_inp = { - .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, .efit_info = efit_inp, .tok_grid_info = ginp, .position_map = pmap, @@ -419,37 +399,33 @@ test_asdex_middle_ho() .geo_local_ext = clocal_ext, .geo_global = clocal, .geo_global_ext = clocal_ext, - .geo_basis = cbasis, + .geo_basis = cbasis }; - struct gk_geometry* up = gkyl_gk_geometry_tok_new(&geometry_inp); + struct gk_geometry *up = gkyl_gk_geometry_tok_new(&geometry_inp); //write_geometry(up, cgrid, cbasis, clocal, "asdexmid"); gkyl_gk_geometry_release(up); gkyl_position_map_release(pmap); end = clock(); - cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC; } -void -test_asdex_upper_ho() +void test_asdex_upper_ho() { clock_t start, end; double cpu_time_used; start = clock(); + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1 + }; - - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, - }; - - double clower[] = { 0.16, -0.01, -M_PI+1e-14 }; - double cupper[] = {0.17501, 0.01, M_PI-1e-14 }; - int ccells[] = { 2, 1, 2 }; + double clower[] = {0.16, -0.01, -M_PI + 1e-14}; + double cupper[] = {0.17501, 0.01, M_PI - 1e-14}; + int ccells[] = {2, 1, 2}; struct gkyl_tok_geo_grid_inp ginp = { .ftype = GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP, @@ -461,14 +437,14 @@ test_asdex_upper_ho() .zmin = -1.3, .zmax = 1.0, .zmin_left = -1.2, - .zmin_right = -1.0, - }; + .zmin_right = -1.0 + }; gkyl_gk_geometry_tok_set_grid_extents(efit_inp, ginp, &clower[2], &cupper[2]); struct gkyl_rect_grid cgrid; gkyl_rect_grid_init(&cgrid, 3, clower, cupper, ccells); struct gkyl_range clocal, clocal_ext; - int cnghost[GKYL_MAX_CDIM] = { 1, 1, 1 }; + int cnghost[GKYL_MAX_CDIM] = {1, 1, 1}; gkyl_create_grid_ranges(&cgrid, cnghost, &clocal_ext, &clocal); int cpoly_order = 1; struct gkyl_basis cbasis; @@ -477,7 +453,7 @@ test_asdex_upper_ho() struct gkyl_position_map *pmap = gkyl_position_map_null_new(); struct gkyl_gk_geometry_inp geometry_inp = { - .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, .efit_info = efit_inp, .tok_grid_info = ginp, .position_map = pmap, @@ -492,25 +468,22 @@ test_asdex_upper_ho() .geo_local_ext = clocal_ext, .geo_global = clocal, .geo_global_ext = clocal_ext, - .geo_basis = cbasis, + .geo_basis = cbasis }; - struct gk_geometry* up = gkyl_gk_geometry_tok_new(&geometry_inp); + struct gk_geometry *up = gkyl_gk_geometry_tok_new(&geometry_inp); //write_geometry(up, cgrid, cbasis, clocal, "asdexup"); gkyl_gk_geometry_release(up); gkyl_position_map_release(pmap); end = clock(); - cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC; } - - -TEST_LIST = { - //{ "test_asdex_fixed_z_ho", test_asdex_fixed_z_ho}, - { "test_asdex_shaped_plate_ho", test_asdex_shaped_plate_ho}, - { "test_asdex_lower_ho", test_asdex_lower_ho}, - { "test_asdex_middle_ho", test_asdex_middle_ho}, - { "test_asdex_upper_ho", test_asdex_upper_ho}, - { NULL, NULL }, +TEST_LIST = { //{ "test_asdex_fixed_z_ho", test_asdex_fixed_z_ho}, + {"test_asdex_shaped_plate_ho", test_asdex_shaped_plate_ho}, + {"test_asdex_lower_ho", test_asdex_lower_ho}, + {"test_asdex_middle_ho", test_asdex_middle_ho}, + {"test_asdex_upper_ho", test_asdex_upper_ho}, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_bc_sheath_gyrokinetic.c b/gyrokinetic/unit/ctest_bc_sheath_gyrokinetic.c index bc9239dd23..8e6dceddc3 100644 --- a/gyrokinetic/unit/ctest_bc_sheath_gyrokinetic.c +++ b/gyrokinetic/unit/ctest_bc_sheath_gyrokinetic.c @@ -13,14 +13,14 @@ #include #include -static struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { - struct gkyl_array* a; - if (use_gpu) + struct gkyl_array *a; + if (use_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } @@ -39,8 +39,7 @@ struct test_sheath_ctx { double sigmaz; // Width of distribution in z. }; -void -eval_func_1x2v(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_func_1x2v(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double vpar = xn[1], mu = xn[2]; double z = xn[0]; @@ -54,12 +53,11 @@ eval_func_1x2v(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx double z0 = pars->z0; double sigmaz = pars->sigmaz; - double envelope = exp( -pow(z-z0,2)/(2.0*pow(sigmaz,2)) ); - fout[0] = exp( -(pow(vpar-upar,2) + 2.0*mu*B0/m) /(2.0*pow(vt,2)) ) * envelope + 0.1; + double envelope = exp(-pow(z - z0, 2) / (2.0 * pow(sigmaz, 2))); + fout[0] = exp(-(pow(vpar - upar, 2) + 2.0 * mu * B0 / m) / (2.0 * pow(vt, 2))) * envelope + 0.1; } -void -eval_func_2x2v(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_func_2x2v(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double vpar = xn[2], mu = xn[3]; double x = xn[0], z = xn[1]; @@ -75,12 +73,12 @@ eval_func_2x2v(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx double sigmax = pars->sigmax; double sigmaz = pars->sigmaz; - double envelope = exp( -pow(x-x0,2)/(2.0*pow(sigmax,2)) ) * exp( -pow(z-z0,2)/(2.0*pow(sigmaz,2)) ); - fout[0] = exp( -(pow(vpar-upar,2) + 2.0*mu*B0/m) /(2.0*pow(vt,2)) ) * envelope + 0.1; + double envelope = + exp(-pow(x - x0, 2) / (2.0 * pow(sigmax, 2))) * exp(-pow(z - z0, 2) / (2.0 * pow(sigmaz, 2))); + fout[0] = exp(-(pow(vpar - upar, 2) + 2.0 * mu * B0 / m) / (2.0 * pow(vt, 2))) * envelope + 0.1; } -void -eval_func_3x2v(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_func_3x2v(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double vpar = xn[3], mu = xn[4]; double x = xn[0], y = xn[1], z = xn[2]; @@ -98,28 +96,31 @@ eval_func_3x2v(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx double sigmay = pars->sigmay; double sigmaz = pars->sigmaz; - double envelope = exp( -pow(x-x0,2)/(2.0*pow(sigmax,2)) ) * exp( -pow(y-y0,2)/(2.0*pow(sigmay,2)) ) * exp( -pow(z-z0,2)/(2.0*pow(sigmaz,2)) ); - fout[0] = exp( -(pow(vpar-upar,2) + 2.0*mu*B0/m) /(2.0*pow(vt,2)) ) * envelope + 0.1; + double envelope = exp(-pow(x - x0, 2) / (2.0 * pow(sigmax, 2))) * + exp(-pow(y - y0, 2) / (2.0 * pow(sigmay, 2))) * + exp(-pow(z - z0, 2) / (2.0 * pow(sigmaz, 2))); + fout[0] = exp(-(pow(vpar - upar, 2) + 2.0 * mu * B0 / m) / (2.0 * pow(vt, 2))) * envelope + 0.1; } -// Checks that the distribution function values in the ghost cells are set to +// Checks that the distribution function values in the ghost cells are set to // 0 for velocities beyond the cutoff velocity and >0 otherwise. -void -check_function(double phi_mpe, double phi_wall, double charge, double mass, int cdim, - struct gkyl_array *distf_ho, struct gkyl_rect_grid grid, struct gkyl_range ghost_r, enum gkyl_edge_loc edge){ - +void check_function( + double phi_mpe, double phi_wall, double charge, double mass, int cdim, + struct gkyl_array *distf_ho, struct gkyl_rect_grid grid, struct gkyl_range ghost_r, + enum gkyl_edge_loc edge +) +{ double delta_phi = phi_mpe - phi_wall; double vpar_cut; if (delta_phi < 0) { - vpar_cut = charge < 0.? DBL_MAX : sqrt(charge*fabs(delta_phi)/(0.5*mass)); - } - else { - vpar_cut = charge < 0.? sqrt(fabs(charge)*delta_phi/(0.5*mass)) : DBL_MAX; + vpar_cut = charge < 0. ? DBL_MAX : sqrt(charge * fabs(delta_phi) / (0.5 * mass)); + } else { + vpar_cut = charge < 0. ? sqrt(fabs(charge) * delta_phi / (0.5 * mass)) : DBL_MAX; } int num_cells = 0; int num_zero_cells = 0; int num_zero_cells_expected = 0; - // We need the sign of charge*delta_phi to determine + // We need the sign of charge*delta_phi to determine // which part of the distribution function is cut off by the sheath BC. double qphi_sign = charge * delta_phi > 0 ? 1.0 : -1.0; struct gkyl_range_iter iter; @@ -134,75 +135,95 @@ check_function(double phi_mpe, double phi_wall, double charge, double mass, int // Get cell boundaries along vpar. double xc[GKYL_MAX_DIM] = {0}; gkyl_rect_grid_cell_center(&grid, idx_g, xc); - double cell_lower_vpar = xc[cdim] - 0.5*grid.dx[cdim]; - double cell_upper_vpar = xc[cdim] + 0.5*grid.dx[cdim]; - + double cell_lower_vpar = xc[cdim] - 0.5 * grid.dx[cdim]; + double cell_upper_vpar = xc[cdim] + 0.5 * grid.dx[cdim]; + num_cells++; num_zero_cells += distf_c[0] > tol ? 0 : 1; - if ( edge == GKYL_LOWER_EDGE && - ( cell_lower_vpar > -qphi_sign*vpar_cut || cell_upper_vpar < qphi_sign*vpar_cut ) ) { + if (edge == GKYL_LOWER_EDGE && + (cell_lower_vpar > -qphi_sign * vpar_cut || cell_upper_vpar < qphi_sign * vpar_cut)) { num_zero_cells_expected++; - for (int k=0; kncomp; k++) { - TEST_CHECK( gkyl_compare(distf_c[k], ref_val, tol) ); - TEST_MSG( "Expected %.9e | Got: %.9e at idx=%d,%d,%d\n", ref_val, distf_c[k], idx_g[0], idx_g[1], idx_g[2]); + for (int k = 0; k < distf_ho->ncomp; k++) { + TEST_CHECK(gkyl_compare(distf_c[k], ref_val, tol)); + TEST_MSG( + "Expected %.9e | Got: %.9e at idx=%d,%d,%d\n", ref_val, distf_c[k], idx_g[0], idx_g[1], + idx_g[2] + ); } - } - else if (edge == GKYL_UPPER_EDGE && - ( cell_lower_vpar > -qphi_sign*vpar_cut || cell_upper_vpar < qphi_sign*vpar_cut ) ) { + } else if (edge == GKYL_UPPER_EDGE && (cell_lower_vpar > -qphi_sign * vpar_cut || + cell_upper_vpar < qphi_sign * vpar_cut)) { num_zero_cells_expected++; - for (int k=0; kncomp; k++) { - TEST_CHECK( gkyl_compare(distf_c[k], ref_val, tol) ); - TEST_MSG( "Expected %.9e | Got: %.9e at idx=%d,%d,%d\n", ref_val, distf_c[k], idx_g[0], idx_g[1], idx_g[2]); + for (int k = 0; k < distf_ho->ncomp; k++) { + TEST_CHECK(gkyl_compare(distf_c[k], ref_val, tol)); + TEST_MSG( + "Expected %.9e | Got: %.9e at idx=%d,%d,%d\n", ref_val, distf_c[k], idx_g[0], idx_g[1], + idx_g[2] + ); } } else { // Check that the average cell value is bigger than 0 for cells that are not expected to be cut off by the sheath BC. double cell_avg = distf_c[0]; - TEST_CHECK( cell_avg > ref_val ); - TEST_MSG( "Expected > %.9e | Got: %.9e at idx=%d,%d,%d\n", ref_val, cell_avg, idx_g[0], idx_g[1], idx_g[2]); + TEST_CHECK(cell_avg > ref_val); + TEST_MSG( + "Expected > %.9e | Got: %.9e at idx=%d,%d,%d\n", ref_val, cell_avg, idx_g[0], idx_g[1], + idx_g[2] + ); } } // Uncomment for debugging. // printf("\n"); - // printf("Edge: %s | Charge: %.1e | Delta phi: %.2e\n", + // printf("Edge: %s | Charge: %.1e | Delta phi: %.2e\n", // edge == GKYL_LOWER_EDGE? "lower" : "upper", charge, delta_phi); // printf("zero cell = %d | zero cell expected = %d | total cells = %d\n", num_zero_cells, num_zero_cells_expected, num_cells); } -void write_out_fields(int cdim, int vdim, enum gkyl_edge_loc edge, bool use_gpu, - struct gkyl_array *distf_ho, struct gkyl_array *phi_ho, struct gkyl_array *phiw_ho, - struct gkyl_rect_grid grid_ext, struct gkyl_range local_ext, - struct gkyl_rect_grid grid_conf, struct gkyl_range local_conf, struct gkyl_basis *basis, struct gkyl_basis basis_conf) { - +void write_out_fields( + int cdim, int vdim, enum gkyl_edge_loc edge, bool use_gpu, struct gkyl_array *distf_ho, + struct gkyl_array *phi_ho, struct gkyl_array *phiw_ho, struct gkyl_rect_grid grid_ext, + struct gkyl_range local_ext, struct gkyl_rect_grid grid_conf, struct gkyl_range local_conf, + struct gkyl_basis *basis, struct gkyl_basis basis_conf +) +{ struct gkyl_msgpack_map_elem io_meta[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = basis->poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = basis->id } + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = basis->poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = basis->id} }; - int io_meta_len = sizeof(io_meta)/sizeof(io_meta[0]); + int io_meta_len = sizeof(io_meta) / sizeof(io_meta[0]); struct gkyl_msgpack_data *mt = gkyl_msgpack_create(io_meta_len, io_meta); struct gkyl_msgpack_map_elem io_meta_conf[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = basis_conf.poly_order }, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = basis_conf.id } + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = basis_conf.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = basis_conf.id} }; - int io_meta_conf_len = sizeof(io_meta_conf)/sizeof(io_meta_conf[0]); + int io_meta_conf_len = sizeof(io_meta_conf) / sizeof(io_meta_conf[0]); struct gkyl_msgpack_data *mt_conf = gkyl_msgpack_create(io_meta_conf_len, io_meta_conf); char fname[256]; const char *fmt = "bc_sheath_%dx%dv_%s_%s_%s.gkyl"; - snprintf(fname, sizeof(fname), fmt, cdim, vdim, edge == GKYL_LOWER_EDGE? "lower" : "upper", use_gpu? "gpu" : "cpu", "distf_out"); + snprintf( + fname, sizeof(fname), fmt, cdim, vdim, edge == GKYL_LOWER_EDGE ? "lower" : "upper", + use_gpu ? "gpu" : "cpu", "distf_out" + ); gkyl_grid_sub_array_write(&grid_ext, &local_ext, mt, distf_ho, fname); - snprintf(fname, sizeof(fname), fmt, cdim, vdim, edge == GKYL_LOWER_EDGE? "lower" : "upper", use_gpu? "gpu" : "cpu", "phi_mpe"); + snprintf( + fname, sizeof(fname), fmt, cdim, vdim, edge == GKYL_LOWER_EDGE ? "lower" : "upper", + use_gpu ? "gpu" : "cpu", "phi_mpe" + ); gkyl_grid_sub_array_write(&grid_conf, &local_conf, mt_conf, phi_ho, fname); - snprintf(fname, sizeof(fname), fmt, cdim, vdim, edge == GKYL_LOWER_EDGE? "lower" : "upper", use_gpu? "gpu" : "cpu", "phi_wall"); + snprintf( + fname, sizeof(fname), fmt, cdim, vdim, edge == GKYL_LOWER_EDGE ? "lower" : "upper", + use_gpu ? "gpu" : "cpu", "phi_wall" + ); gkyl_grid_sub_array_write(&grid_conf, &local_conf, mt_conf, phiw_ho, fname); gkyl_msgpack_data_release(mt); gkyl_msgpack_data_release(mt_conf); } -void -test_bc_sheath_gyrokinetic_1x2v(const int *cells, enum gkyl_edge_loc edge, - double charge, double phi_mpe, bool write_fields, bool use_gpu) +void test_bc_sheath_gyrokinetic_1x2v( + const int *cells, enum gkyl_edge_loc edge, double charge, double phi_mpe, bool write_fields, + bool use_gpu +) { /* This test applies the sheath BC to a Maxwellian distribution function on both upper and lower edges in the z direction, @@ -217,33 +238,33 @@ test_bc_sheath_gyrokinetic_1x2v(const int *cells, enum gkyl_edge_loc edge, double mass = 1.0; // Species mass. double vt = 1.0; // Reference thermal speed (for grid extents). double B0 = 1.0; // Magnetic field magnitude. - double upar_distf = 1.0*vt; // Parallel flow speed in distribution function. - double vt_distf = 1.5*vt; // Thermal speed in distribution function. + double upar_distf = 1.0 * vt; // Parallel flow speed in distribution function. + double vt_distf = 1.5 * vt; // Thermal speed in distribution function. double phi_wall = 0.0; // Potential at wall. double z0 = 0.2; double sigmaz = 1.0; - + int poly_order = 1; - double lower[] = {-1.0, -5.0*vt, 0.}; - double upper[] = { 1.0, 5.0*vt, mass*(pow(5.0*vt,2))/(2.0*B0)}; + double lower[] = {-1.0, -5.0 * vt, 0.}; + double upper[] = {1.0, 5.0 * vt, mass * (pow(5.0 * vt, 2)) / (2.0 * B0)}; int vdim = 2; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int cdim = ndim - vdim; - int dir = cdim-1; // Always applied in the parallel direction. + int dir = cdim - 1; // Always applied in the parallel direction. double lower_conf[cdim], upper_conf[cdim]; int cells_conf[cdim]; - for (int d=0; dncomp, distf->size) : gkyl_array_acquire(distf); + struct gkyl_array *distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : + gkyl_array_acquire(distf); struct test_sheath_ctx proj_ctx = { - .B0 = B0, - .mass = mass, - .upar = upar_distf, - .vt = vt_distf, - .z0 = z0, - .sigmaz = sigmaz + .B0 = B0, .mass = mass, .upar = upar_distf, .vt = vt_distf, .z0 = z0, .sigmaz = sigmaz }; - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &grid, - .basis = &basis_ho, - .num_ret_vals = 1, - .eval = eval_func_1x2v, - .ctx = &proj_ctx, - } + gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &grid, .basis = &basis_ho, .num_ret_vals = 1, .eval = eval_func_1x2v, .ctx = &proj_ctx} ); gkyl_proj_on_basis_advance(projDistf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); @@ -327,18 +342,21 @@ test_bc_sheath_gyrokinetic_1x2v(const int *cells, enum gkyl_edge_loc edge, // Initialize the electrostatic potential at MPE and WALL double dgnormc = pow(sqrt(2.0), cdim); struct gkyl_array *phi = mkarr(use_gpu, basis_conf.num_basis, local_conf_ext.volume); - struct gkyl_array *phi_ho = use_gpu? mkarr(false, phi->ncomp, phi->size) : gkyl_array_acquire(phi); + struct gkyl_array *phi_ho = use_gpu ? mkarr(false, phi->ncomp, phi->size) : + gkyl_array_acquire(phi); gkyl_array_shiftc(phi_ho, phi_mpe * dgnormc, 0 * basis_conf.num_basis); gkyl_array_copy(phi, phi_ho); struct gkyl_array *phiw = mkarr(use_gpu, basis_conf.num_basis, local_conf_ext.volume); - struct gkyl_array *phiw_ho = use_gpu? mkarr(false, phiw->ncomp, phiw->size) : gkyl_array_acquire(phiw); + struct gkyl_array *phiw_ho = use_gpu ? mkarr(false, phiw->ncomp, phiw->size) : + gkyl_array_acquire(phiw); gkyl_array_shiftc(phiw_ho, phi_wall * dgnormc, 0 * basis_conf.num_basis); gkyl_array_copy(phiw, phiw_ho); // Create the BC updater. - struct gkyl_bc_sheath_gyrokinetic *bcsheath = gkyl_bc_sheath_gyrokinetic_new(dir, edge, - basis, &skin_r, &ghost_r, gvm, cdim, 2.*charge/mass, use_gpu); + struct gkyl_bc_sheath_gyrokinetic *bcsheath = gkyl_bc_sheath_gyrokinetic_new( + dir, edge, basis, &skin_r, &ghost_r, gvm, cdim, 2. * charge / mass, use_gpu + ); // Advance the BC updater. gkyl_bc_sheath_gyrokinetic_advance(bcsheath, phi, phiw, distf, &local_conf); @@ -350,9 +368,12 @@ test_bc_sheath_gyrokinetic_1x2v(const int *cells, enum gkyl_edge_loc edge, check_function(phi_mpe, phi_wall, charge, mass, cdim, distf_ho, grid, ghost_r, edge); // Write out the distribution function after applying BC if requested. - if (write_fields) - write_out_fields(cdim, vdim, edge, use_gpu, distf_ho, phi_ho, phiw_ho, - grid_ext, local_ext, grid_conf, local_conf, &basis_ho, basis_conf); + if (write_fields) { + write_out_fields( + cdim, vdim, edge, use_gpu, distf_ho, phi_ho, phiw_ho, grid_ext, local_ext, grid_conf, + local_conf, &basis_ho, basis_conf + ); + } // Clean up. gkyl_proj_on_basis_release(projDistf); @@ -362,18 +383,20 @@ test_bc_sheath_gyrokinetic_1x2v(const int *cells, enum gkyl_edge_loc edge, gkyl_array_release(phi_ho); gkyl_array_release(phiw); gkyl_array_release(phiw_ho); - if (use_gpu) + if (use_gpu) { gkyl_cart_modal_basis_release_cu(basis); - else + } else { gkyl_cart_modal_basis_release(basis); + } gkyl_velocity_map_release(gvm); gkyl_bc_sheath_gyrokinetic_release(bcsheath); } -void -test_bc_sheath_gyrokinetic_2x2v(const int *cells, enum gkyl_edge_loc edge, - double charge, double phi_mpe, bool write_fields, bool use_gpu) +void test_bc_sheath_gyrokinetic_2x2v( + const int *cells, enum gkyl_edge_loc edge, double charge, double phi_mpe, bool write_fields, + bool use_gpu +) { /* This test applies the sheath BC to a Maxwellian distribution function on both upper and lower edges in the z direction, @@ -388,8 +411,8 @@ test_bc_sheath_gyrokinetic_2x2v(const int *cells, enum gkyl_edge_loc edge, double mass = 1.; // Species mass. double vt = 1.0; // Reference thermal speed (for grid extents). double B0 = 1.0; // Magnetic field magnitude. - double upar_distf = 1.0*vt; // Parallel flow speed in distribution function. - double vt_distf = 1.5*vt; // Thermal speed in distribution function. + double upar_distf = 1.0 * vt; // Parallel flow speed in distribution function. + double vt_distf = 1.5 * vt; // Thermal speed in distribution function. double phi_wall = 0.0; // Potential at wall. double x0 = 0.0; // x-center of distribution function double z0 = 0.2; // z-center of distribution function @@ -397,26 +420,26 @@ test_bc_sheath_gyrokinetic_2x2v(const int *cells, enum gkyl_edge_loc edge, double sigmaz = 1.0; // Width of distribution function in z. int poly_order = 1; - double lower[] = { 0.0, -1.0, -5.0*vt, 0.}; - double upper[] = { 1.0, 1.0, 5.0*vt, mass*(pow(5.0*vt,2))/(2.0*B0)}; + double lower[] = {0.0, -1.0, -5.0 * vt, 0.}; + double upper[] = {1.0, 1.0, 5.0 * vt, mass * (pow(5.0 * vt, 2)) / (2.0 * B0)}; int vdim = 2; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int cdim = ndim - vdim; - int dir = cdim-1; // Always applied in the parallel direction. + int dir = cdim - 1; // Always applied in the parallel direction. double lower_conf[cdim], upper_conf[cdim]; int cells_conf[cdim]; - for (int d=0; dncomp, distf->size) : gkyl_array_acquire(distf); + struct gkyl_array *distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : + gkyl_array_acquire(distf); struct test_sheath_ctx proj_ctx = { .B0 = B0, .mass = mass, @@ -488,13 +515,8 @@ test_bc_sheath_gyrokinetic_2x2v(const int *cells, enum gkyl_edge_loc edge, .sigmax = sigmax, .sigmaz = sigmaz }; - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &grid, - .basis = &basis_ho, - .num_ret_vals = 1, - .eval = eval_func_2x2v, - .ctx = &proj_ctx, - } + gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &grid, .basis = &basis_ho, .num_ret_vals = 1, .eval = eval_func_2x2v, .ctx = &proj_ctx} ); gkyl_proj_on_basis_advance(projDistf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); @@ -502,18 +524,21 @@ test_bc_sheath_gyrokinetic_2x2v(const int *cells, enum gkyl_edge_loc edge, // Initialize the electrostatic potential at MPE and WALL. double dgnormc = pow(sqrt(2.0), cdim); struct gkyl_array *phi = mkarr(use_gpu, basis_conf.num_basis, local_conf_ext.volume); - struct gkyl_array *phi_ho = use_gpu? mkarr(false, phi->ncomp, phi->size) : gkyl_array_acquire(phi); + struct gkyl_array *phi_ho = use_gpu ? mkarr(false, phi->ncomp, phi->size) : + gkyl_array_acquire(phi); gkyl_array_shiftc(phi_ho, phi_mpe * dgnormc, 0 * basis_conf.num_basis); gkyl_array_copy(phi, phi_ho); struct gkyl_array *phiw = mkarr(use_gpu, basis_conf.num_basis, local_conf_ext.volume); - struct gkyl_array *phiw_ho = use_gpu? mkarr(false, phiw->ncomp, phiw->size) : gkyl_array_acquire(phiw); + struct gkyl_array *phiw_ho = use_gpu ? mkarr(false, phiw->ncomp, phiw->size) : + gkyl_array_acquire(phiw); gkyl_array_shiftc(phiw_ho, phi_wall * dgnormc, 0 * basis_conf.num_basis); gkyl_array_copy(phiw, phiw_ho); // Create the BC updater. - struct gkyl_bc_sheath_gyrokinetic *bcsheath = gkyl_bc_sheath_gyrokinetic_new(dir, edge, - basis, &skin_r, &ghost_r, gvm, cdim, 2.*charge/mass, use_gpu); + struct gkyl_bc_sheath_gyrokinetic *bcsheath = gkyl_bc_sheath_gyrokinetic_new( + dir, edge, basis, &skin_r, &ghost_r, gvm, cdim, 2. * charge / mass, use_gpu + ); // Advance the BC updater. gkyl_bc_sheath_gyrokinetic_advance(bcsheath, phi, phiw, distf, &local_conf); @@ -525,9 +550,12 @@ test_bc_sheath_gyrokinetic_2x2v(const int *cells, enum gkyl_edge_loc edge, check_function(phi_mpe, phi_wall, charge, mass, cdim, distf_ho, grid, ghost_r, edge); // Write out the distribution function after applying BC if requested. - if (write_fields) - write_out_fields(cdim, vdim, edge, use_gpu, distf_ho, phi_ho, phiw_ho, - grid_ext, local_ext, grid_conf, local_conf, &basis_ho, basis_conf); + if (write_fields) { + write_out_fields( + cdim, vdim, edge, use_gpu, distf_ho, phi_ho, phiw_ho, grid_ext, local_ext, grid_conf, + local_conf, &basis_ho, basis_conf + ); + } // Clean up. gkyl_proj_on_basis_release(projDistf); @@ -537,18 +565,20 @@ test_bc_sheath_gyrokinetic_2x2v(const int *cells, enum gkyl_edge_loc edge, gkyl_array_release(phi_ho); gkyl_array_release(phiw); gkyl_array_release(phiw_ho); - if (use_gpu) + if (use_gpu) { gkyl_cart_modal_basis_release_cu(basis); - else + } else { gkyl_cart_modal_basis_release(basis); + } gkyl_velocity_map_release(gvm); gkyl_bc_sheath_gyrokinetic_release(bcsheath); } -void -test_bc_sheath_gyrokinetic_3x2v(const int *cells, enum gkyl_edge_loc edge, - double charge, double phi_mpe, bool write_fields, bool use_gpu) +void test_bc_sheath_gyrokinetic_3x2v( + const int *cells, enum gkyl_edge_loc edge, double charge, double phi_mpe, bool write_fields, + bool use_gpu +) { /* This test applies the sheath BC to a Maxwellian distribution function on both upper and lower edges in the z direction, @@ -563,17 +593,17 @@ test_bc_sheath_gyrokinetic_3x2v(const int *cells, enum gkyl_edge_loc edge, double mass = 1.; // Species mass. double vt = 1.0; // Reference thermal speed (for grid extents). double B0 = 1.0; // Magnetic field magnitude. - double upar_distf = 1.0*vt; // Parallel flow speed in distribution function. - double vt_distf = 1.5*vt; // Thermal speed in distribution function. + double upar_distf = 1.0 * vt; // Parallel flow speed in distribution function. + double vt_distf = 1.5 * vt; // Thermal speed in distribution function. double phi_wall = 0.0; // Potential at wall. int poly_order = 1; - double lower[] = { 0.0, -2.0, -1.0, -5.0*vt, 0.}; - double upper[] = { 1.0, 2.0, 1.0, 5.0*vt, mass*(pow(5.0*vt,2))/(2.0*B0)}; + double lower[] = {0.0, -2.0, -1.0, -5.0 * vt, 0.}; + double upper[] = {1.0, 2.0, 1.0, 5.0 * vt, mass * (pow(5.0 * vt, 2)) / (2.0 * B0)}; int vdim = 2; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int cdim = ndim - vdim; - int dir = cdim-1; // Always applied in the parallel direction. + int dir = cdim - 1; // Always applied in the parallel direction. double x0 = 0.0; // x-center of distribution function double y0 = 0.0; // y-center of distribution function double z0 = 0.2; // z-center of distribution function @@ -583,17 +613,17 @@ test_bc_sheath_gyrokinetic_3x2v(const int *cells, enum gkyl_edge_loc edge, double lower_conf[cdim], upper_conf[cdim]; int cells_conf[cdim]; - for (int d=0; dncomp, distf->size) : gkyl_array_acquire(distf); + struct gkyl_array *distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : + gkyl_array_acquire(distf); struct test_sheath_ctx proj_ctx = { .B0 = B0, .mass = mass, @@ -667,13 +701,8 @@ test_bc_sheath_gyrokinetic_3x2v(const int *cells, enum gkyl_edge_loc edge, .sigmay = sigmay, .sigmaz = sigmaz }; - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &grid, - .basis = &basis_ho, - .num_ret_vals = 1, - .eval = eval_func_3x2v, - .ctx = &proj_ctx, - } + gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &grid, .basis = &basis_ho, .num_ret_vals = 1, .eval = eval_func_3x2v, .ctx = &proj_ctx} ); gkyl_proj_on_basis_advance(projDistf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); @@ -681,18 +710,21 @@ test_bc_sheath_gyrokinetic_3x2v(const int *cells, enum gkyl_edge_loc edge, // Initialize the electrostatic potential at MPE and WALL. double dgnormc = pow(sqrt(2.0), cdim); struct gkyl_array *phi = mkarr(use_gpu, basis_conf.num_basis, local_conf_ext.volume); - struct gkyl_array *phi_ho = use_gpu? mkarr(false, phi->ncomp, phi->size) : gkyl_array_acquire(phi); + struct gkyl_array *phi_ho = use_gpu ? mkarr(false, phi->ncomp, phi->size) : + gkyl_array_acquire(phi); gkyl_array_shiftc(phi_ho, phi_mpe * dgnormc, 0 * basis_conf.num_basis); gkyl_array_copy(phi, phi_ho); struct gkyl_array *phiw = mkarr(use_gpu, basis_conf.num_basis, local_conf_ext.volume); - struct gkyl_array *phiw_ho = use_gpu? mkarr(false, phiw->ncomp, phiw->size) : gkyl_array_acquire(phiw); + struct gkyl_array *phiw_ho = use_gpu ? mkarr(false, phiw->ncomp, phiw->size) : + gkyl_array_acquire(phiw); gkyl_array_shiftc(phiw_ho, phi_wall * dgnormc, 0 * basis_conf.num_basis); gkyl_array_copy(phiw, phiw_ho); // Create the BC updater. - struct gkyl_bc_sheath_gyrokinetic *bcsheath = gkyl_bc_sheath_gyrokinetic_new(dir, edge, - basis, &skin_r, &ghost_r, gvm, cdim, 2.*charge/mass, use_gpu); + struct gkyl_bc_sheath_gyrokinetic *bcsheath = gkyl_bc_sheath_gyrokinetic_new( + dir, edge, basis, &skin_r, &ghost_r, gvm, cdim, 2. * charge / mass, use_gpu + ); // Advance the BC updater. gkyl_bc_sheath_gyrokinetic_advance(bcsheath, phi, phiw, distf, &local_conf); @@ -704,9 +736,12 @@ test_bc_sheath_gyrokinetic_3x2v(const int *cells, enum gkyl_edge_loc edge, check_function(phi_mpe, phi_wall, charge, mass, cdim, distf_ho, grid, ghost_r, edge); // Write out the distribution function after applying BC if requested. - if (write_fields) - write_out_fields(cdim, vdim, edge, use_gpu, distf_ho, phi_ho, phiw_ho, - grid_ext, local_ext, grid_conf, local_conf, &basis_ho, basis_conf); + if (write_fields) { + write_out_fields( + cdim, vdim, edge, use_gpu, distf_ho, phi_ho, phiw_ho, grid_ext, local_ext, grid_conf, + local_conf, &basis_ho, basis_conf + ); + } // Clean up. gkyl_proj_on_basis_release(projDistf); @@ -716,10 +751,11 @@ test_bc_sheath_gyrokinetic_3x2v(const int *cells, enum gkyl_edge_loc edge, gkyl_array_release(phi_ho); gkyl_array_release(phiw); gkyl_array_release(phiw_ho); - if (use_gpu) + if (use_gpu) { gkyl_cart_modal_basis_release_cu(basis); - else + } else { gkyl_cart_modal_basis_release(basis); + } gkyl_velocity_map_release(gvm); gkyl_bc_sheath_gyrokinetic_release(bcsheath); @@ -735,29 +771,45 @@ void test_bc_sheath_gk_1x2v_ho() phi_mpe = 1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); // Electrons with negative sheath entrance potential. phi_mpe = -1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); // Ions with positive sheath entrance potential. phi_mpe = 1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); // Ions with negative sheath entrance potential. phi_mpe = -1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); } void test_bc_sheath_gk_2x2v_ho() @@ -765,34 +817,50 @@ void test_bc_sheath_gk_2x2v_ho() double phi_mpe; // Potential at the magnetic presheath entrance. double charge; // Species charge (+ or - for electrons/ions). bool write_fields; - + // Electrons with positive sheath entrance potential. phi_mpe = 1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); // Electrons with negative sheath entrance potential. phi_mpe = -1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); // Ions with positive sheath entrance potential. phi_mpe = 1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); // Ions with negative sheath entrance potential. phi_mpe = -1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); } void test_bc_sheath_gk_3x2v_ho() @@ -805,29 +873,45 @@ void test_bc_sheath_gk_3x2v_ho() phi_mpe = 1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); // Electrons with negative sheath entrance potential. phi_mpe = -1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); // Ions with positive sheath entrance potential. phi_mpe = 1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); // Ions with negative sheath entrance potential. phi_mpe = -1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false); - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, false + ); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, false + ); } #ifdef GKYL_HAVE_CUDA @@ -841,29 +925,45 @@ void test_bc_sheath_gk_1x2v_dev() phi_mpe = 1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); // Electrons with negative sheath entrance potential. phi_mpe = -1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); // Ions with positive sheath entrance potential. phi_mpe = 1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); // Ions with negative sheath entrance potential. phi_mpe = -1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_1x2v((int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_1x2v( + (int[]){4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); } void test_bc_sheath_gk_2x2v_dev() @@ -876,29 +976,45 @@ void test_bc_sheath_gk_2x2v_dev() phi_mpe = 1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); // Electrons with negative sheath entrance potential. phi_mpe = -1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); // Ions with positive sheath entrance potential. phi_mpe = 1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); // Ions with negative sheath entrance potential. phi_mpe = -1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_2x2v((int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_2x2v( + (int[]){4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); } void test_bc_sheath_gk_3x2v_dev() @@ -911,40 +1027,56 @@ void test_bc_sheath_gk_3x2v_dev() phi_mpe = 1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); // Electrons with negative sheath entrance potential. phi_mpe = -1.0; charge = -1.0; write_fields = false; - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); // Ions with positive sheath entrance potential. phi_mpe = 1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); // Ions with negative sheath entrance potential. phi_mpe = -1.0; charge = 1.0; write_fields = false; - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true); - test_bc_sheath_gyrokinetic_3x2v((int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_LOWER_EDGE, charge, phi_mpe, write_fields, true + ); + test_bc_sheath_gyrokinetic_3x2v( + (int[]){4, 4, 4, 16, 12}, GKYL_UPPER_EDGE, charge, phi_mpe, write_fields, true + ); } #endif TEST_LIST = { - { "test_bc_sheath_gk_1x2v_ho", test_bc_sheath_gk_1x2v_ho }, - { "test_bc_sheath_gk_2x2v_ho", test_bc_sheath_gk_2x2v_ho }, - { "test_bc_sheath_gk_3x2v_ho", test_bc_sheath_gk_3x2v_ho }, + {"test_bc_sheath_gk_1x2v_ho", test_bc_sheath_gk_1x2v_ho}, + {"test_bc_sheath_gk_2x2v_ho", test_bc_sheath_gk_2x2v_ho}, + {"test_bc_sheath_gk_3x2v_ho", test_bc_sheath_gk_3x2v_ho}, #ifdef GKYL_HAVE_CUDA - { "test_bc_sheath_gk_1x2v_dev", test_bc_sheath_gk_1x2v_dev }, - { "test_bc_sheath_gk_2x2v_dev", test_bc_sheath_gk_2x2v_dev }, - { "test_bc_sheath_gk_3x2v_dev", test_bc_sheath_gk_3x2v_dev }, + {"test_bc_sheath_gk_1x2v_dev", test_bc_sheath_gk_1x2v_dev}, + {"test_bc_sheath_gk_2x2v_dev", test_bc_sheath_gk_2x2v_dev}, + {"test_bc_sheath_gk_3x2v_dev", test_bc_sheath_gk_3x2v_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_bc_twistshift.c b/gyrokinetic/unit/ctest_bc_twistshift.c index 707d48c149..b05313720f 100644 --- a/gyrokinetic/unit/ctest_bc_twistshift.c +++ b/gyrokinetic/unit/ctest_bc_twistshift.c @@ -28,7 +28,7 @@ struct test_bc_twistshift_output_meta { }; // returned gkyl_array_meta must be freed using gyrokinetic_array_meta_release -static struct gkyl_msgpack_data* +static struct gkyl_msgpack_data * test_bc_twistshift_array_meta_new(struct test_bc_twistshift_output_meta meta) { struct gkyl_msgpack_data *mt = gkyl_malloc(sizeof(*mt)); @@ -59,10 +59,11 @@ test_bc_twistshift_array_meta_new(struct test_bc_twistshift_output_meta meta) return mt; } -static void -test_bc_twistshift_array_meta_release(struct gkyl_msgpack_data *mt) +static void test_bc_twistshift_array_meta_release(struct gkyl_msgpack_data *mt) { - if (!mt) return; + if (!mt) { + return; + } MPACK_FREE(mt->meta); gkyl_free(mt); } @@ -76,22 +77,25 @@ struct skin_ghost_ranges { }; // Create ghost and skin sub-ranges given a parent range -static void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { int ndim = parent->ndim; - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } // Apply periodic BCs along parallel direction -void -apply_periodic_bc(struct gkyl_array *buff, struct gkyl_array *fld, const int dir, const struct skin_ghost_ranges sgr) +void apply_periodic_bc( + struct gkyl_array *buff, struct gkyl_array *fld, const int dir, const struct skin_ghost_ranges sgr +) { gkyl_array_copy_to_buffer(buff->data, fld, &(sgr.lower_skin[dir])); gkyl_array_copy_from_buffer(fld, buff->data, &(sgr.upper_ghost[dir])); @@ -100,14 +104,14 @@ apply_periodic_bc(struct gkyl_array *buff, struct gkyl_array *fld, const int dir gkyl_array_copy_from_buffer(fld, buff->data, &(sgr.lower_ghost[dir])); } -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } @@ -120,13 +124,14 @@ struct test_bc_twistshift_ctx { enum gkyl_edge_loc edge; }; -void -mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; xp[2] = xc[2]; + xp[0] = xc[0]; + xp[1] = xc[1]; + xp[2] = xc[2]; } -void eval_bfield_3x(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_bfield_3x(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; @@ -138,81 +143,74 @@ void eval_bfield_3x(double t, const double *xn, double* GKYL_RESTRICT fout, void fout[2] = B0; } -void -shift1_fig6(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void shift1_fig6(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { struct test_bc_twistshift_ctx *pars = ctx; - double Lx[2] = {pars->upper[0]-pars->lower[0], pars->upper[1]-pars->lower[1]}; - double dx[2] = {Lx[0]/pars->cells[0], Lx[1]/pars->cells[1]}; + double Lx[2] = {pars->upper[0] - pars->lower[0], pars->upper[1] - pars->lower[1]}; + double dx[2] = {Lx[0] / pars->cells[0], Lx[1] / pars->cells[1]}; - fout[0] = 4.0*dx[1]; + fout[0] = 4.0 * dx[1]; } -void -shift1m_fig6(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void shift1m_fig6(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { shift1_fig6(t, xn, fout, ctx); fout[0] *= -1.0; } -void -shift2_fig6(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void shift2_fig6(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 1.1; } -void -shift2m_fig6(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void shift2m_fig6(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { shift2_fig6(t, xn, fout, ctx); fout[0] *= -1.0; } -void -init_donor_fig6(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void init_donor_fig6(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double y = xn[1]; double mu = 0.0; double sigma = 0.3; - fout[0] = ( 1.0/sqrt(2.0*M_PI*pow(sigma,2)) ) * exp( -pow(y-mu,2)/(2.0*pow(sigma,2)) ); + fout[0] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2))) * exp(-pow(y - mu, 2) / (2.0 * pow(sigma, 2))); } -void -shift_fig9(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void shift_fig9(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { struct test_bc_twistshift_ctx *pars = ctx; - double Lx[2] = {pars->upper[0]-pars->lower[0], pars->upper[1]-pars->lower[1]}; - double dx[2] = {Lx[0]/pars->cells[0], Lx[1]/pars->cells[1]}; + double Lx[2] = {pars->upper[0] - pars->lower[0], pars->upper[1] - pars->lower[1]}; + double dx[2] = {Lx[0] / pars->cells[0], Lx[1] / pars->cells[1]}; - fout[0] = dx[1]/2.0; + fout[0] = dx[1] / 2.0; } -void -shiftm_fig9(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void shiftm_fig9(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { shift_fig9(t, xn, fout, ctx); fout[0] *= -1.0; } -void -init_donor_fig9(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void init_donor_fig9(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double y = xn[1]; struct test_bc_twistshift_ctx *pars = ctx; - double ymid = 0.5*(pars->upper[1]+pars->lower[1]); - double dy = (pars->upper[1]-pars->lower[1])/pars->cells[1]; + double ymid = 0.5 * (pars->upper[1] + pars->lower[1]); + double dy = (pars->upper[1] - pars->lower[1]) / pars->cells[1]; fout[0] = 0.; - if (ymid < y && y < ymid+dy) + if (ymid < y && y < ymid + dy) { fout[0] = 1.; + } } -void -test_bc_twistshift_3x_fig6_wcells(const int *cells, enum gkyl_edge_loc edge, - bool check_distf, bool use_gpu, bool write_f) +void test_bc_twistshift_3x_fig6_wcells( + const int *cells, enum gkyl_edge_loc edge, bool check_distf, bool use_gpu, bool write_f +) { double vt = 1.0; // Thermal speed. double mass = 1.0; @@ -221,14 +219,14 @@ test_bc_twistshift_3x_fig6_wcells(const int *cells, enum gkyl_edge_loc edge, int poly_order = 1; const double lower[] = {-2.0, -1.50, -3.0}; - const double upper[] = { 2.0, 1.50, 3.0}; + const double upper[] = {2.0, 1.50, 3.0}; int vdim = 0; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int cdim = ndim - vdim; double lower_conf[cdim], upper_conf[cdim]; int cells_conf[cdim]; - for (int d=0; dgeo_corn.bmag, 0.0); - gkyl_array_shiftc(gk_geom->geo_corn.bmag, B0*pow(sqrt(2.0),cdim), 0); + gkyl_array_shiftc(gk_geom->geo_corn.bmag, B0 * pow(sqrt(2.0), cdim), 0); - struct gkyl_dg_updater_moment *mcalc = gkyl_dg_updater_moment_gyrokinetic_new(&grid, &basis_conf, - &basis, &local_conf, mass, 0, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0M1M2, true, use_gpu); + struct gkyl_dg_updater_moment *mcalc = gkyl_dg_updater_moment_gyrokinetic_new( + &grid, &basis_conf, &basis, &local_conf, mass, 0, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0M1M2, + true, use_gpu + ); int num_mom = gkyl_dg_updater_moment_gyrokinetic_num_mom(mcalc); struct gkyl_array *marr = mkarr(use_gpu, num_mom, local_ext_conf.volume); @@ -670,62 +671,59 @@ test_bc_twistshift_3x2v_fig6_wcells(const int *cells, enum gkyl_edge_loc edge, if (use_gpu) { red_integ_mom_skin = gkyl_cu_malloc(sizeof(double[num_mom])); red_integ_mom_ghost = gkyl_cu_malloc(sizeof(double[num_mom])); - } - else { + } else { red_integ_mom_skin = gkyl_malloc(sizeof(double[num_mom])); red_integ_mom_ghost = gkyl_malloc(sizeof(double[num_mom])); } double *red_integ_mom_skin_ho = gkyl_malloc(sizeof(double[num_mom])); double *red_integ_mom_ghost_ho = gkyl_malloc(sizeof(double[num_mom])); - gkyl_dg_updater_moment_gyrokinetic_advance(mcalc, - &skin_rng, &skin_rng_conf, distf, marr); + gkyl_dg_updater_moment_gyrokinetic_advance(mcalc, &skin_rng, &skin_rng_conf, distf, marr); gkyl_array_reduce_range(red_integ_mom_skin, marr, GKYL_SUM, &skin_rng_conf); - gkyl_dg_updater_moment_gyrokinetic_advance(mcalc, - &ghost_rng, &ghost_rng_conf, distf, marr); + gkyl_dg_updater_moment_gyrokinetic_advance(mcalc, &ghost_rng, &ghost_rng_conf, distf, marr); gkyl_array_reduce_range(red_integ_mom_ghost, marr, GKYL_SUM, &ghost_rng_conf); if (use_gpu) { - gkyl_cu_memcpy(red_integ_mom_skin_ho, red_integ_mom_skin, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - gkyl_cu_memcpy(red_integ_mom_ghost_ho, red_integ_mom_ghost, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + red_integ_mom_skin_ho, red_integ_mom_skin, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + gkyl_cu_memcpy( + red_integ_mom_ghost_ho, red_integ_mom_ghost, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(red_integ_mom_skin_ho, red_integ_mom_skin, sizeof(double[num_mom])); memcpy(red_integ_mom_ghost_ho, red_integ_mom_ghost, sizeof(double[num_mom])); } - for (int k=0; kupper[0]-pars->lower[0], pars->upper[1]-pars->lower[1]}; - double dx[2] = {Lx[0]/pars->cells[0], Lx[1]/pars->cells[1]}; + double Lx[2] = {pars->upper[0] - pars->lower[0], pars->upper[1] - pars->lower[1]}; + double dx[2] = {Lx[0] / pars->cells[0], Lx[1] / pars->cells[1]}; - fout[0] = 0.6*x+1.8; + fout[0] = 0.6 * x + 1.8; } -void -init_donor_3x_fig11(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void init_donor_3x_fig11(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; struct test_bc_twistshift_ctx *pars = ctx; - double Lx[2] = {pars->upper[0]-pars->lower[0], pars->upper[1]-pars->lower[1]}; + double Lx[2] = {pars->upper[0] - pars->lower[0], pars->upper[1] - pars->lower[1]}; double B0 = pars->B0; double vt = pars->vt; double mass = pars->mass; - double vtsq = vt*vt; + double vtsq = vt * vt; double beta[2] = {0.0, 0.0}; double sigma[2] = {0.6, 0.2}; - fout[0] = ( 1.0/pow(sqrt(2.0*M_PI*vtsq),3) ) - * exp( -pow(x-beta[0],2)/(2.0*pow(sigma[0],2)) -pow(y-beta[1],2)/(2.0*pow(sigma[1],2)) ); + fout[0] = + (1.0 / pow(sqrt(2.0 * M_PI * vtsq), 3)) * exp( + -pow(x - beta[0], 2) / (2.0 * pow(sigma[0], 2)) - + pow(y - beta[1], 2) / (2.0 * pow(sigma[1], 2)) + ); } -void -init_donor_3x2v_fig11(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void init_donor_3x2v_fig11(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2], vpar = xn[3], mu = xn[4]; @@ -862,15 +859,16 @@ init_donor_3x2v_fig11(double t, const double *xn, double* GKYL_RESTRICT fout, vo double B0 = pars->B0; double vt = pars->vt; double mass = pars->mass; - double vtsq = vt*vt; + double vtsq = vt * vt; init_donor_3x_fig11(t, xn, fout, ctx); - fout[0] *= exp( -(pow(vpar,2)+2.0*mu*B0/mass)/(2.0*vtsq) ); + fout[0] *= exp(-(pow(vpar, 2) + 2.0 * mu * B0 / mass) / (2.0 * vtsq)); } -void -test_bc_twistshift_3x_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, - int apply_in_half_x, bool check_distf, bool use_gpu, bool write_f) +void test_bc_twistshift_3x_fig11_wcells( + const int *cells, enum gkyl_edge_loc edge, int apply_in_half_x, bool check_distf, bool use_gpu, + bool write_f +) { double vt = 1.0; // Thermal speed. double mass = 1.0; @@ -879,14 +877,14 @@ test_bc_twistshift_3x_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, int poly_order = 1; const double lower[] = {-2.0, -1.50, -3.0}; - const double upper[] = { 2.0, 1.50, 3.0}; + const double upper[] = {2.0, 1.50, 3.0}; int vdim = 0; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int cdim = ndim - vdim; double lower_conf[cdim], upper_conf[cdim]; int cells_conf[cdim]; - for (int d=0; d 0) { + } else if (apply_in_half_x > 0) { // Apply the BC only on the upper half of the domain. - int x_half_len = (update_rng.upper[0] - update_rng.lower[0] + 1)/2; + int x_half_len = (update_rng.upper[0] - update_rng.lower[0] + 1) / 2; gkyl_range_shorten_from_below(&update_rng, &update_rng, 0, x_half_len); } @@ -1001,7 +996,7 @@ test_bc_twistshift_3x_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, .grid = &grid, .shift_func = shift_fig11, .shift_func_ctx = &proj_ctx, - .use_gpu = use_gpu, + .use_gpu = use_gpu }; struct gkyl_bc_twistshift *tsup = gkyl_bc_twistshift_inew(&tsinp); @@ -1017,160 +1012,140 @@ test_bc_twistshift_3x_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, if (write_f) { double lower_ext[ndim], upper_ext[ndim]; int cells_ext[ndim]; - for (int d=0; d 0) { + } else if (apply_in_half_x > 0) { // Applied the BC only on the upper half of the domain. - int x_half_len = (ghost_rng.upper[0] - ghost_rng.lower[0] + 1)/2; + int x_half_len = (ghost_rng.upper[0] - ghost_rng.lower[0] + 1) / 2; gkyl_range_shorten_from_below(&check_ghost_rng, &ghost_rng, 0, x_half_len); gkyl_range_shorten_from_above(&check_other_ghost_rng, &ghost_rng, 0, x_half_len); - } - else + } else { check_ghost_rng = ghost_rng; + } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &check_ghost_rng); while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&check_ghost_rng, iter.idx); double *f_c = gkyl_array_fetch(distf_ho, linidx); - int refidx = (iter.idx[0]-1)*cells[1] + iter.idx[1]-1; - TEST_CHECK( gkyl_compare(f0[refidx], f_c[0], 1e-13) ); - TEST_CHECK( gkyl_compare(f1[refidx], f_c[1], 1e-13) ); - TEST_CHECK( gkyl_compare(f2[refidx], f_c[2], 1e-12) ); - TEST_CHECK( gkyl_compare(f6[refidx], f_c[6], 1e-12) ); + int refidx = (iter.idx[0] - 1) * cells[1] + iter.idx[1] - 1; + TEST_CHECK(gkyl_compare(f0[refidx], f_c[0], 1e-13)); + TEST_CHECK(gkyl_compare(f1[refidx], f_c[1], 1e-13)); + TEST_CHECK(gkyl_compare(f2[refidx], f_c[2], 1e-12)); + TEST_CHECK(gkyl_compare(f6[refidx], f_c[6], 1e-12)); } if (apply_in_half_x != 0) { - // Check that the other half is untouched. + // Check that the other half is untouched. int skin_idx[GKYL_MAX_DIM]; gkyl_range_iter_init(&iter, &check_other_ghost_rng); while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&check_other_ghost_rng, iter.idx); double *f_c = gkyl_array_fetch(distf_ho, linidx); - - for (int d=0; dncomp; k++) - TEST_CHECK( gkyl_compare(fskin_c[k], f_c[k], 1e-15) ); + + for (int k = 0; k < distf_ho->ncomp; k++) { + TEST_CHECK(gkyl_compare(fskin_c[k], f_c[k], 1e-15)); + } } } } @@ -1181,62 +1156,56 @@ test_bc_twistshift_3x_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, gkyl_proj_on_basis_release(projDistf); gkyl_array_release(distf_ho); gkyl_array_release(distf); - } -void -init_donor_3x_fig14(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void init_donor_3x_fig14(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; struct test_bc_twistshift_ctx *pars = ctx; double Lx[3] = { - pars->upper[0]-pars->lower[0], - pars->upper[1]-pars->lower[1], - pars->upper[2]-pars->lower[2], + pars->upper[0] - pars->lower[0], pars->upper[1] - pars->lower[1], + pars->upper[2] - pars->lower[2] }; double f_amplitude = 1.0; double f_floor = 1.0e-10; // Cube - double rx2 = pow(x-Lx[0]/2,2); - double ry2 = pow(y-Lx[1]/2,2); - double rz2 = pow(z-Lx[2]/2,2); + double rx2 = pow(x - Lx[0] / 2, 2); + double ry2 = pow(y - Lx[1] / 2, 2); + double rz2 = pow(z - Lx[2] / 2, 2); - if (rx2 < pow(Lx[0]/4,2) && ry2 < pow(Lx[1]/4,2)) + if (rx2 < pow(Lx[0] / 4, 2) && ry2 < pow(Lx[1] / 4, 2)) { fout[0] = f_amplitude; - else + } else { fout[0] = f_floor; + } } -void -shift_fig14(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void shift_fig14(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct test_bc_twistshift_ctx *pars = ctx; double Lx[3] = { - pars->upper[0]-pars->lower[0], - pars->upper[1]-pars->lower[1], - pars->upper[2]-pars->lower[2], - }; - double dx[3] = { - Lx[0]/pars->cells[0], - Lx[1]/pars->cells[1], - Lx[2]/pars->cells[2], + pars->upper[0] - pars->lower[0], pars->upper[1] - pars->lower[1], + pars->upper[2] - pars->lower[2] }; + double dx[3] = {Lx[0] / pars->cells[0], Lx[1] / pars->cells[1], Lx[2] / pars->cells[2]}; enum gkyl_edge_loc edge = pars->edge; - fout[0] = -(x-0.5); + fout[0] = -(x - 0.5); - if (edge == GKYL_UPPER_EDGE) + if (edge == GKYL_UPPER_EDGE) { fout[0] *= -1.0; + } } -void -test_bc_twistshift_3x_fig14_wcells(const int *cells, enum gkyl_edge_loc edge, - int apply_in_half_x, bool check_distf, bool use_gpu, bool write_f) +void test_bc_twistshift_3x_fig14_wcells( + const int *cells, enum gkyl_edge_loc edge, int apply_in_half_x, bool check_distf, bool use_gpu, + bool write_f +) { double vt = 1.0; // Thermal speed. double mass = 1.0; @@ -1247,12 +1216,12 @@ test_bc_twistshift_3x_fig14_wcells(const int *cells, enum gkyl_edge_loc edge, const double lower[] = {0.0, 0.0, 0.0}; const double upper[] = {1.0, 1.0, 1.0}; int vdim = 0; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int cdim = ndim - vdim; double lower_conf[cdim], upper_conf[cdim]; int cells_conf[cdim]; - for (int d=0; d 0) { + } else if (apply_in_half_x > 0) { // Apply the BC only on the upper half of the domain. - int x_half_len = (update_rng.upper[0] - update_rng.lower[0] + 1)/2; + int x_half_len = (update_rng.upper[0] - update_rng.lower[0] + 1) / 2; gkyl_range_shorten_from_below(&update_rng, &update_rng, 0, x_half_len); } @@ -1368,7 +1334,7 @@ test_bc_twistshift_3x_fig14_wcells(const int *cells, enum gkyl_edge_loc edge, .grid = &grid, .shift_func = shift_fig14, .shift_func_ctx = &proj_ctx, - .use_gpu = use_gpu, + .use_gpu = use_gpu }; struct gkyl_bc_twistshift *tsup = gkyl_bc_twistshift_inew(&tsinp); @@ -1384,15 +1350,17 @@ test_bc_twistshift_3x_fig14_wcells(const int *cells, enum gkyl_edge_loc edge, if (write_f) { double lower_ext[ndim], upper_ext[ndim]; int cells_ext[ndim]; - for (int d=0; d 0) { + } else if (apply_in_half_x > 0) { // Applied the BC only on the upper half of the domain. - int x_half_len = (ghost_rng.upper[0] - ghost_rng.lower[0] + 1)/2; + int x_half_len = (ghost_rng.upper[0] - ghost_rng.lower[0] + 1) / 2; gkyl_range_shorten_from_below(&check_ghost_rng, &ghost_rng, 0, x_half_len); gkyl_range_shorten_from_above(&check_other_ghost_rng, &ghost_rng, 0, x_half_len); - } - else + } else { check_ghost_rng = ghost_rng; + } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &check_ghost_rng); while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&check_ghost_rng, iter.idx); double *f_c = gkyl_array_fetch(distf_ho, linidx); - int refidx = (iter.idx[0]-1)*cells[1] + iter.idx[1]-1; - TEST_CHECK( gkyl_compare(f0[refidx], f_c[0], 1e-13) ); - TEST_CHECK( gkyl_compare(f1[refidx], f_c[1], 1e-13) ); - TEST_CHECK( gkyl_compare(f2[refidx], f_c[2], 1e-12) ); - TEST_CHECK( gkyl_compare(f6[refidx], f_c[6], 1e-12) ); + int refidx = (iter.idx[0] - 1) * cells[1] + iter.idx[1] - 1; + TEST_CHECK(gkyl_compare(f0[refidx], f_c[0], 1e-13)); + TEST_CHECK(gkyl_compare(f1[refidx], f_c[1], 1e-13)); + TEST_CHECK(gkyl_compare(f2[refidx], f_c[2], 1e-12)); + TEST_CHECK(gkyl_compare(f6[refidx], f_c[6], 1e-12)); } - } gkyl_array_release(buff_per); @@ -1664,12 +1607,12 @@ test_bc_twistshift_3x_fig14_wcells(const int *cells, enum gkyl_edge_loc edge, gkyl_proj_on_basis_release(projDistf); gkyl_array_release(distf_ho); gkyl_array_release(distf); - } -void -test_bc_twistshift_3x2v_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, - int apply_in_half_x, bool check_distf, bool use_gpu, bool write_f) +void test_bc_twistshift_3x2v_fig11_wcells( + const int *cells, enum gkyl_edge_loc edge, int apply_in_half_x, bool check_distf, bool use_gpu, + bool write_f +) { double vt = 1.0; // Thermal speed. double mass = 1.0; @@ -1677,25 +1620,25 @@ test_bc_twistshift_3x2v_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, int bc_dir = 2; // Direction in which to apply TS. int poly_order = 1; - const double lower[] = {-2.0, -1.50, -3.0, -5.0*vt, 0.}; - const double upper[] = { 2.0, 1.50, 3.0, 5.0*vt, mass*(pow(5.0*vt,2))/(2.0*B0)}; + const double lower[] = {-2.0, -1.50, -3.0, -5.0 * vt, 0.}; + const double upper[] = {2.0, 1.50, 3.0, 5.0 * vt, mass * (pow(5.0 * vt, 2)) / (2.0 * B0)}; int vdim = 2; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int cdim = ndim - vdim; double lower_conf[cdim], upper_conf[cdim]; int cells_conf[cdim]; - for (int d=0; d 0) { + } else if (apply_in_half_x > 0) { // Apply the BC only on the upper half of the domain. - int x_half_len = (update_rng.upper[0] - update_rng.lower[0] + 1)/2; + int x_half_len = (update_rng.upper[0] - update_rng.lower[0] + 1) / 2; gkyl_range_shorten_from_below(&update_rng, &update_rng, 0, x_half_len); } @@ -1818,7 +1766,7 @@ test_bc_twistshift_3x2v_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, .grid = &grid, .shift_func = shift_fig11, .shift_func_ctx = &proj_ctx, - .use_gpu = use_gpu, + .use_gpu = use_gpu }; struct gkyl_bc_twistshift *tsup = gkyl_bc_twistshift_inew(&tsinp); @@ -1834,22 +1782,25 @@ test_bc_twistshift_3x2v_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, if (write_f) { double lower_ext[ndim], upper_ext[ndim]; int cells_ext[ndim]; - for (int d=0; dgeo_corn.bmag, 0.0); - gkyl_array_shiftc(gk_geom->geo_corn.bmag, B0*pow(sqrt(2.0),cdim), 0); + gkyl_array_shiftc(gk_geom->geo_corn.bmag, B0 * pow(sqrt(2.0), cdim), 0); - struct gkyl_dg_updater_moment *mcalc = gkyl_dg_updater_moment_gyrokinetic_new(&grid, &basis_conf, - &basis, &local_conf, mass, 0, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0M1M2, true, use_gpu); + struct gkyl_dg_updater_moment *mcalc = gkyl_dg_updater_moment_gyrokinetic_new( + &grid, &basis_conf, &basis, &local_conf, mass, 0, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0M1M2, + true, use_gpu + ); int num_mom = gkyl_dg_updater_moment_gyrokinetic_num_mom(mcalc); struct gkyl_array *marr = mkarr(use_gpu, num_mom, local_ext_conf.volume); @@ -1897,181 +1850,162 @@ test_bc_twistshift_3x2v_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, if (use_gpu) { red_integ_mom_skin = gkyl_cu_malloc(sizeof(double[num_mom])); red_integ_mom_ghost = gkyl_cu_malloc(sizeof(double[num_mom])); - } - else { + } else { red_integ_mom_skin = gkyl_malloc(sizeof(double[num_mom])); red_integ_mom_ghost = gkyl_malloc(sizeof(double[num_mom])); } double *red_integ_mom_skin_ho = gkyl_malloc(sizeof(double[num_mom])); double *red_integ_mom_ghost_ho = gkyl_malloc(sizeof(double[num_mom])); - gkyl_dg_updater_moment_gyrokinetic_advance(mcalc, - &skin_rng, &skin_rng_conf, distf, marr); + gkyl_dg_updater_moment_gyrokinetic_advance(mcalc, &skin_rng, &skin_rng_conf, distf, marr); gkyl_array_reduce_range(red_integ_mom_skin, marr, GKYL_SUM, &skin_rng_conf); - gkyl_dg_updater_moment_gyrokinetic_advance(mcalc, - &ghost_rng, &ghost_rng_conf, distf, marr); + gkyl_dg_updater_moment_gyrokinetic_advance(mcalc, &ghost_rng, &ghost_rng_conf, distf, marr); gkyl_array_reduce_range(red_integ_mom_ghost, marr, GKYL_SUM, &ghost_rng_conf); if (use_gpu) { - gkyl_cu_memcpy(red_integ_mom_skin_ho, red_integ_mom_skin, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - gkyl_cu_memcpy(red_integ_mom_ghost_ho, red_integ_mom_ghost, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + red_integ_mom_skin_ho, red_integ_mom_skin, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + gkyl_cu_memcpy( + red_integ_mom_ghost_ho, red_integ_mom_ghost, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H + ); + } else { memcpy(red_integ_mom_skin_ho, red_integ_mom_skin, sizeof(double[num_mom])); memcpy(red_integ_mom_ghost_ho, red_integ_mom_ghost, sizeof(double[num_mom])); } - for (int k=0; k 0) { + } else if (apply_in_half_x > 0) { // Applied the BC only on the upper half of the domain. - int x_half_len = (ghost_rng.upper[0] - ghost_rng.lower[0] + 1)/2; + int x_half_len = (ghost_rng.upper[0] - ghost_rng.lower[0] + 1) / 2; gkyl_range_shorten_from_below(&check_ghost_rng, &ghost_rng, 0, x_half_len); gkyl_range_shorten_from_above(&check_other_ghost_rng, &ghost_rng, 0, x_half_len); - } - else + } else { check_ghost_rng = ghost_rng; + } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &check_ghost_rng); while (gkyl_range_iter_next(&iter)) { - if (iter.idx[3]==1 && iter.idx[4]==1) { + if (iter.idx[3] == 1 && iter.idx[4] == 1) { long linidx = gkyl_range_idx(&check_ghost_rng, iter.idx); double *f_c = gkyl_array_fetch(distf_ho, linidx); - int refidx = (iter.idx[0]-1)*cells[1] + iter.idx[1]-1; - TEST_CHECK( gkyl_compare(f0[refidx], f_c[0], 1e-13) ); - TEST_CHECK( gkyl_compare(f1[refidx], f_c[1], 1e-13) ); - TEST_CHECK( gkyl_compare(f2[refidx], f_c[2], 1e-12) ); - TEST_CHECK( gkyl_compare(f6[refidx], f_c[6], 1e-12) ); + int refidx = (iter.idx[0] - 1) * cells[1] + iter.idx[1] - 1; + TEST_CHECK(gkyl_compare(f0[refidx], f_c[0], 1e-13)); + TEST_CHECK(gkyl_compare(f1[refidx], f_c[1], 1e-13)); + TEST_CHECK(gkyl_compare(f2[refidx], f_c[2], 1e-12)); + TEST_CHECK(gkyl_compare(f6[refidx], f_c[6], 1e-12)); } } if (apply_in_half_x != 0) { - // Check that the other half is untouched. + // Check that the other half is untouched. int skin_idx[GKYL_MAX_DIM]; gkyl_range_iter_init(&iter, &check_other_ghost_rng); while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&check_other_ghost_rng, iter.idx); double *f_c = gkyl_array_fetch(distf_ho, linidx); - - for (int d=0; dncomp; k++) - TEST_CHECK( gkyl_compare(fskin_c[k], f_c[k], 1e-15) ); + + for (int k = 0; k < distf_ho->ncomp; k++) { + TEST_CHECK(gkyl_compare(fskin_c[k], f_c[k], 1e-15)); + } } } } @@ -2081,8 +2015,7 @@ test_bc_twistshift_3x2v_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, if (use_gpu) { gkyl_cu_free(red_integ_mom_skin); gkyl_cu_free(red_integ_mom_ghost); - } - else { + } else { gkyl_free(red_integ_mom_skin); gkyl_free(red_integ_mom_ghost); } @@ -2097,23 +2030,30 @@ test_bc_twistshift_3x2v_fig11_wcells(const int *cells, enum gkyl_edge_loc edge, gkyl_proj_on_basis_release(projDistf); gkyl_array_release(distf_ho); gkyl_array_release(distf); - } // CBC geometry (see rt_gk_cbc_passive_3x2v_p1.c) -static double -interp_1x_lut_cbc(double x, double *lut_grid, double *lut_val, int N) +static double interp_1x_lut_cbc(double x, double *lut_grid, double *lut_val, int N) { double x_min = lut_grid[0]; - double x_max = lut_grid[N-1]; - if (x <= x_min) return lut_val[0]; - if (x >= x_max) return lut_val[N-1]; - double dx = (x_max - x_min)/(N-1); - int idx = (int)((x - x_min)/dx); - if (idx < 0) idx = 0; - if (idx >= N-1) idx = N-2; - return lut_val[idx] + (lut_val[idx+1] - lut_val[idx])*(x - lut_grid[idx])/(lut_grid[idx+1] - lut_grid[idx]); + double x_max = lut_grid[N - 1]; + if (x <= x_min) { + return lut_val[0]; + } + if (x >= x_max) { + return lut_val[N - 1]; + } + double dx = (x_max - x_min) / (N - 1); + int idx = (int)((x - x_min) / dx); + if (idx < 0) { + idx = 0; + } + if (idx >= N - 1) { + idx = N - 2; + } + return lut_val[idx] + (lut_val[idx + 1] - lut_val[idx]) * (x - lut_grid[idx]) / + (lut_grid[idx + 1] - lut_grid[idx]); } struct gk_cbc_app_ctx { @@ -2131,69 +2071,71 @@ struct integrand_cbc_ctx { double theta; }; -static double r_x_cbc(double x, double r0) { return x + r0; } +static double r_x_cbc(double x, double r0) +{ + return x + r0; +} static double qprofile_cbc(double r, double a_mid, double qaxis, double qlcfs) { - return 1.0 + 2.78*pow(r/a_mid, 2.8); + return 1.0 + 2.78 * pow(r / a_mid, 2.8); } static double R_rtheta_cbc(double r, double theta, void *ctx) { struct gk_cbc_app_ctx *app = ctx; - return app->R_axis - app->a_shift*r*r/(2.*app->R_axis) - + r*cos(theta + asin(app->delta)*sin(theta)); + return app->R_axis - app->a_shift * r * r / (2. * app->R_axis) + + r * cos(theta + asin(app->delta) * sin(theta)); } static double dRdr_cbc(double r, double theta, void *ctx) { struct gk_cbc_app_ctx *app = ctx; - return -app->a_shift*r/app->R_axis + cos(theta + asin(app->delta)*sin(theta)); + return -app->a_shift * r / app->R_axis + cos(theta + asin(app->delta) * sin(theta)); } static double dRdtheta_cbc(double r, double theta, void *ctx) { struct gk_cbc_app_ctx *app = ctx; - return -r*sin(theta + asin(app->delta)*sin(theta))*(1. + asin(app->delta)*cos(theta)); + return -r * sin(theta + asin(app->delta) * sin(theta)) * (1. + asin(app->delta) * cos(theta)); } static double dZdr_cbc(double r, double theta, void *ctx) { struct gk_cbc_app_ctx *app = ctx; - return app->kappa*sin(theta); + return app->kappa * sin(theta); } static double dZdtheta_cbc(double r, double theta, void *ctx) { struct gk_cbc_app_ctx *app = ctx; - return app->kappa*r*cos(theta); + return app->kappa * r * cos(theta); } static double Jr_cbc(double r, double theta, void *ctx) { - return R_rtheta_cbc(r, theta, ctx) - *(dRdr_cbc(r, theta, ctx)*dZdtheta_cbc(r, theta, ctx) - - dRdtheta_cbc(r, theta, ctx)*dZdr_cbc(r, theta, ctx)); + return R_rtheta_cbc(r, theta, ctx) * (dRdr_cbc(r, theta, ctx) * dZdtheta_cbc(r, theta, ctx) - + dRdtheta_cbc(r, theta, ctx) * dZdr_cbc(r, theta, ctx)); } static double Bphi_cbc(double R, void *ctx) { struct gk_cbc_app_ctx *app = ctx; - return app->B0*app->R0/R; + return app->B0 * app->R0 / R; } static double integrand_JoRsq_cbc(double t, void *int_ctx) { struct integrand_cbc_ctx *inctx = int_ctx; - return Jr_cbc(inctx->r, t, inctx->app_ctx) - / pow(R_rtheta_cbc(inctx->r, t, inctx->app_ctx), 2); + return Jr_cbc(inctx->r, t, inctx->app_ctx) / pow(R_rtheta_cbc(inctx->r, t, inctx->app_ctx), 2); } static double intdPsidr_cbc(double r, void *ctx) { struct gk_cbc_app_ctx *app = ctx; struct integrand_cbc_ctx tmp_ctx = {.app_ctx = app, .r = r}; - struct gkyl_qr_res integral = gkyl_dbl_exp(integrand_JoRsq_cbc, &tmp_ctx, 0., 2.*M_PI, 7, 1e-10); + struct gkyl_qr_res integral = + gkyl_dbl_exp(integrand_JoRsq_cbc, &tmp_ctx, 0., 2. * M_PI, 7, 1e-10); return integral.res; } @@ -2203,7 +2145,8 @@ static double dPsidr_cbc(double r, double theta, void *ctx) double integral_val = interp_1x_lut_cbc(r, app->r_lut, app->dPsidr_int_lut, app->psi_lut_size); double R = R_rtheta_cbc(r, theta, ctx); double Bt = Bphi_cbc(R, ctx); - return (R*Bt/(2.*M_PI*qprofile_cbc(r, app->a_mid, app->qaxis, app->qlcfs)))*integral_val; + return (R * Bt / (2. * M_PI * qprofile_cbc(r, app->a_mid, app->qaxis, app->qlcfs))) * + integral_val; } static double compute_alpha_integral_cbc(double r, double twrap, void *ctx) @@ -2211,7 +2154,9 @@ static double compute_alpha_integral_cbc(double r, double twrap, void *ctx) struct gk_cbc_app_ctx *app = ctx; struct integrand_cbc_ctx tmp_ctx = {.app_ctx = app, .r = r}; struct gkyl_qr_res integral; - if (twrap == 0.0) return 0.0; + if (twrap == 0.0) { + return 0.0; + } if (0. < twrap) { integral = gkyl_dbl_exp(integrand_JoRsq_cbc, &tmp_ctx, 0., twrap, 7, 1e-10); return integral.res; @@ -2224,94 +2169,117 @@ static double compute_alpha_integral_cbc(double r, double twrap, void *ctx) static double alpha_cbc(double r, double theta, double phi, void *ctx) { double twrap = theta; - while (twrap < -M_PI) twrap += 2.*M_PI; - while (twrap > M_PI) twrap -= 2.*M_PI; + while (twrap < -M_PI) { + twrap += 2. * M_PI; + } + while (twrap > M_PI) { + twrap -= 2. * M_PI; + } double integral_val = compute_alpha_integral_cbc(r, twrap, ctx); - double R = R_rtheta_cbc(r, theta, ctx); + double R = R_rtheta_cbc(r, theta, ctx); double Bt = Bphi_cbc(R, ctx); - return phi - R*Bt*integral_val/dPsidr_cbc(r, theta, ctx); + return phi - R * Bt * integral_val / dPsidr_cbc(r, theta, ctx); } -void bc_shift_func_lo_cbc(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_lo_cbc(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { struct gk_cbc_app_ctx *app = ctx; double r = r_x_cbc(xc[0], app->r0); - fout[0] = app->Cy*(alpha_cbc(r, app->z_min, 0.0, ctx) - alpha_cbc(r, app->z_max, 0.0, ctx)); + fout[0] = app->Cy * (alpha_cbc(r, app->z_min, 0.0, ctx) - alpha_cbc(r, app->z_max, 0.0, ctx)); } -void bc_shift_func_up_cbc(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bc_shift_func_up_cbc(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { struct gk_cbc_app_ctx *app = ctx; double r = r_x_cbc(xc[0], app->r0); - fout[0] = -app->Cy*(alpha_cbc(r, app->z_min, 0.0, ctx) - alpha_cbc(r, app->z_max, 0.0, ctx)); + fout[0] = -app->Cy * (alpha_cbc(r, app->z_min, 0.0, ctx) - alpha_cbc(r, app->z_max, 0.0, ctx)); } -void init_donor_3x_cbc(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void init_donor_3x_cbc(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { struct gk_cbc_app_ctx *app = ctx; double x = xn[0], y = xn[1], z = xn[2]; - double sigx = app->Lx/7.0, sigy = app->Ly/7.0, sigz = app->Lz/10.0; - double mux = 0.*app->Lx; - fout[0] = exp(-pow(x-mux,2)/(2.*pow(sigx,2)) - pow(y,2)/(2.*pow(sigy,2)) - pow(z,2)/(2.*pow(sigz,2))); + double sigx = app->Lx / 7.0, sigy = app->Ly / 7.0, sigz = app->Lz / 10.0; + double mux = 0. * app->Lx; + fout[0] = exp( + -pow(x - mux, 2) / (2. * pow(sigx, 2)) - pow(y, 2) / (2. * pow(sigy, 2)) - + pow(z, 2) / (2. * pow(sigz, 2)) + ); } -void -test_bc_twistshift_3x_cbc_wcells(const int *cells, enum gkyl_edge_loc edge, - bool check_distf, bool use_gpu, bool write_f) +void test_bc_twistshift_3x_cbc_wcells( + const int *cells, enum gkyl_edge_loc edge, bool check_distf, bool use_gpu, bool write_f +) { int bc_dir = 2; int poly_order = 1; // Physical parameters matching rt_gk_cbc_passive_3x2v_p1.c create_ctx(). - double eV = GKYL_ELEMENTARY_CHARGE; - double mp = GKYL_PROTON_MASS; - double qi = eV; - double mi = mp; // AMU = 1 (hydrogen) - double Te0 = 2000.*eV; + double eV = GKYL_ELEMENTARY_CHARGE; + double mp = GKYL_PROTON_MASS; + double qi = eV; + double mi = mp; // AMU = 1 (hydrogen) + double Te0 = 2000. * eV; double R_axis = 1.6714; double B_axis = 1.54; - double a_mid = 0.604; - double R0 = R_axis + 0.5*a_mid; - double r0 = 0.5*a_mid; - double B0 = B_axis*(R_axis/R0); - double qaxis = 1.2; - double qlcfs = 2.0; - - double c_s = sqrt(Te0/mi); - double omega_ci = fabs(qi*B0/mi); - double rho_s = c_s/omega_ci; - double q0 = qprofile_cbc(r0, a_mid, qaxis, qlcfs); - double Cy = r0/q0; - - double Lx = 150.*rho_s; - double Ly = 150.*rho_s; - Ly = 2.*M_PI*Cy/round(2.*M_PI*Cy/Ly); // adjust to integer toroidal mode number - double Lz = 2.*M_PI - 1e-10; + double a_mid = 0.604; + double R0 = R_axis + 0.5 * a_mid; + double r0 = 0.5 * a_mid; + double B0 = B_axis * (R_axis / R0); + double qaxis = 1.2; + double qlcfs = 2.0; + + double c_s = sqrt(Te0 / mi); + double omega_ci = fabs(qi * B0 / mi); + double rho_s = c_s / omega_ci; + double q0 = qprofile_cbc(r0, a_mid, qaxis, qlcfs); + double Cy = r0 / q0; + + double Lx = 150. * rho_s; + double Ly = 150. * rho_s; + Ly = 2. * M_PI * Cy / round(2. * M_PI * Cy / Ly); // adjust to integer toroidal mode number + double Lz = 2. * M_PI - 1e-10; // Use a fixed LUT size sufficient for accurate geometry evaluation. int psi_lut_size = 200; struct gk_cbc_app_ctx app_ctx = { - .a_shift = 0.0, .Z_axis = 0.0, - .R_axis = R_axis, .R0 = R0, .a_mid = a_mid, .r0 = r0, - .B0 = B0, .kappa = 1.0, .delta = 0.0, - .q0 = q0, .Cy = Cy, .qaxis = qaxis, .qlcfs = qlcfs, - .Lx = Lx, .Ly = Ly, .Lz = Lz, - .x_min = -Lx/2., .x_max = Lx/2., - .y_min = -Ly/2., .y_max = Ly/2., - .z_min = -Lz/2., .z_max = Lz/2., - .psi_lut_size = psi_lut_size, + .a_shift = 0.0, + .Z_axis = 0.0, + .R_axis = R_axis, + .R0 = R0, + .a_mid = a_mid, + .r0 = r0, + .B0 = B0, + .kappa = 1.0, + .delta = 0.0, + .q0 = q0, + .Cy = Cy, + .qaxis = qaxis, + .qlcfs = qlcfs, + .Lx = Lx, + .Ly = Ly, + .Lz = Lz, + .x_min = -Lx / 2., + .x_max = Lx / 2., + .y_min = -Ly / 2., + .y_max = Ly / 2., + .z_min = -Lz / 2., + .z_max = Lz / 2., + .psi_lut_size = psi_lut_size }; // Populate lookup tables (avoids redundant integration in geometry evaluations). - app_ctx.r_lut = gkyl_malloc(psi_lut_size*sizeof(double)); - app_ctx.dPsidr_int_lut = gkyl_malloc(psi_lut_size*sizeof(double)); - double r_lut_min = 0.0, r_lut_max = 2.0*a_mid; - for (int i=0; i #include -void -proj_one(double t, const double *xn, double *fout, void *ctx) +void proj_one(double t, const double *xn, double *fout, void *ctx) { fout[0] = 1; fout[1] = 0; @@ -30,8 +29,7 @@ proj_one(double t, const double *xn, double *fout, void *ctx) fout[8] = 1; } -void -proj_cyl(double t, const double *xn, double *fout, void *ctx) +void proj_cyl(double t, const double *xn, double *fout, void *ctx) { double r = xn[0]; double theta = xn[1]; @@ -44,24 +42,22 @@ proj_cyl(double t, const double *xn, double *fout, void *ctx) fout[4] = 1; fout[5] = 0; - fout[6] = -r*sin(theta); + fout[6] = -r * sin(theta); fout[7] = 0; - fout[8] = r*cos(theta); + fout[8] = r * cos(theta); } - - void test_cartesian_2x_onecell() { - double lower[] = { -1, -1 }, upper[] = { 1, 1 }; - int cells[] = { 8, 16 }; - int dim = sizeof(lower)/sizeof(lower[0]); + double lower[] = {-1, -1}, upper[] = {1, 1}; + int cells[] = {8, 16}; + int dim = sizeof(lower) / sizeof(lower[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); //ranges struct gkyl_range local, local_ext; - int nghost[GKYL_MAX_CDIM] = { 1, 1 }; + int nghost[GKYL_MAX_CDIM] = {1, 1}; gkyl_create_grid_ranges(&grid, nghost, &local_ext, &local); // basis function int poly_order = 1; @@ -69,8 +65,8 @@ void test_cartesian_2x_onecell() gkyl_cart_modal_serendip(&basis, dim, poly_order); // Create cartesian tangent vectors and duals - struct gkyl_array *dxdz= gkyl_array_new(GKYL_DOUBLE, 9*basis.num_basis, local_ext.volume); - struct gkyl_array *dzdx= gkyl_array_new(GKYL_DOUBLE, 9*basis.num_basis, local_ext.volume); + struct gkyl_array *dxdz = gkyl_array_new(GKYL_DOUBLE, 9 * basis.num_basis, local_ext.volume); + struct gkyl_array *dzdx = gkyl_array_new(GKYL_DOUBLE, 9 * basis.num_basis, local_ext.volume); gkyl_eval_on_nodes *proj = gkyl_eval_on_nodes_new(&grid, &basis, 9, &proj_one, 0); gkyl_eval_on_nodes_advance(proj, 0.0, &local, dxdz); gkyl_eval_on_nodes_advance(proj, 0.0, &local, dzdx); @@ -83,25 +79,27 @@ void test_cartesian_2x_onecell() int edge1 = 1; //upper edge int edge2 = 0; //lower edge int dir = 1; // second direction - int idx1[GKYL_MAX_DIM] = {4,16}; - int idx2[GKYL_MAX_DIM] = {4,1}; + int idx1[GKYL_MAX_DIM] = {4, 16}; + int idx2[GKYL_MAX_DIM] = {4, 1}; long loc1 = gkyl_range_idx(&local, idx1); long loc2 = gkyl_range_idx(&local, idx2); const double *dxdz_i = gkyl_array_fetch(dxdz, loc1); const double *dzdx_j = gkyl_array_fetch(dzdx, loc2); int num_nodes = 2; - double tj_i[dim*dim*num_nodes]; + double tj_i[dim * dim * num_nodes]; calc_tensor(bt, dir, edge1, edge2, dzdx_j, dxdz_i, tj_i); - for(int n = 0; ntensor, "tji.gkyl"); + gkyl_grid_sub_array_write(&grid2, &local2, 0, bt->tensor, "tji.gkyl"); gkyl_array_release(dxdz1); gkyl_array_release(dzdx2); @@ -166,47 +161,44 @@ void test_block_tensor_cartesian_2x_z_ho() void test_block_tensor_cartesian_2x_x_ho() { // Block 2 grid - double lower2[] = { -1.0, 0.0 }, upper2[] = { 1.0, 1.0 }; - int cells2[] = { 8, 16 }; - int dim = sizeof(lower2)/sizeof(lower2[0]); + double lower2[] = {-1.0, 0.0}, upper2[] = {1.0, 1.0}; + int cells2[] = {8, 16}; + int dim = sizeof(lower2) / sizeof(lower2[0]); struct gkyl_rect_grid grid2; gkyl_rect_grid_init(&grid2, dim, lower2, upper2, cells2); struct gkyl_range local2, local_ext2; - int nghost[GKYL_MAX_CDIM] = { 1, 1 }; + int nghost[GKYL_MAX_CDIM] = {1, 1}; gkyl_create_grid_ranges(&grid2, nghost, &local_ext2, &local2); // Block 1 grid - double lower1[] = { -1.0, -1 }, upper1[] = { 0.0, 1.0 }; - int cells1[] = { 8, 16 }; + double lower1[] = {-1.0, -1}, upper1[] = {0.0, 1.0}; + int cells1[] = {8, 16}; struct gkyl_rect_grid grid1; gkyl_rect_grid_init(&grid1, dim, lower1, upper1, cells1); struct gkyl_range local1, local_ext1; gkyl_create_grid_ranges(&grid1, nghost, &local_ext1, &local1); - - // Common basis int poly_order = 1; struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); // Block 2 duals - struct gkyl_array *dzdx2 = gkyl_array_new(GKYL_DOUBLE, 9*basis.num_basis, local_ext2.volume); + struct gkyl_array *dzdx2 = gkyl_array_new(GKYL_DOUBLE, 9 * basis.num_basis, local_ext2.volume); gkyl_eval_on_nodes *proj2 = gkyl_eval_on_nodes_new(&grid2, &basis, 9, &proj_one, 0); gkyl_eval_on_nodes_advance(proj2, 0.0, &local2, dzdx2); gkyl_eval_on_nodes_release(proj2); gkyl_grid_sub_array_write(&grid2, &local2, 0, dzdx2, "dzdx2.gkyl"); // Block 1 tangents - struct gkyl_array *dxdz1 = gkyl_array_new(GKYL_DOUBLE, 9*basis.num_basis, local_ext1.volume); + struct gkyl_array *dxdz1 = gkyl_array_new(GKYL_DOUBLE, 9 * basis.num_basis, local_ext1.volume); gkyl_eval_on_nodes *proj1 = gkyl_eval_on_nodes_new(&grid1, &basis, 9, &proj_one, 0); gkyl_eval_on_nodes_advance(proj1, 0.0, &local1, dxdz1); gkyl_eval_on_nodes_release(proj1); gkyl_grid_sub_array_write(&grid1, &local1, 0, dxdz1, "dxdz1.gkyl"); - - - struct bc_block_tensor *bt = gkyl_bc_block_tensor_new(&grid2, &local2, &local_ext2, &basis, false); + struct bc_block_tensor *bt = + gkyl_bc_block_tensor_new(&grid2, &local2, &local_ext2, &basis, false); int edge1 = 1; //upper edge int edge2 = 0; //lower edge int dir = 0; // first direction @@ -223,47 +215,44 @@ void test_block_tensor_cartesian_2x_x_ho() void test_block_tensor_cyl_cart_2x_z_ho() { // Block 2 grid - double lower2[] = { 0.5, -1.0 }, upper2[] = { 1.0, 0.0 }; - int cells2[] = { 8, 16 }; - int dim = sizeof(lower2)/sizeof(lower2[0]); + double lower2[] = {0.5, -1.0}, upper2[] = {1.0, 0.0}; + int cells2[] = {8, 16}; + int dim = sizeof(lower2) / sizeof(lower2[0]); struct gkyl_rect_grid grid2; gkyl_rect_grid_init(&grid2, dim, lower2, upper2, cells2); struct gkyl_range local2, local_ext2; - int nghost[GKYL_MAX_CDIM] = { 1, 1 }; + int nghost[GKYL_MAX_CDIM] = {1, 1}; gkyl_create_grid_ranges(&grid2, nghost, &local_ext2, &local2); // Block 1 grid - double lower1[] = { 0.5, 0.0 }, upper1[] = { 1.0, M_PI/2 }; - int cells1[] = { 8, 16 }; + double lower1[] = {0.5, 0.0}, upper1[] = {1.0, M_PI / 2}; + int cells1[] = {8, 16}; struct gkyl_rect_grid grid1; gkyl_rect_grid_init(&grid1, dim, lower1, upper1, cells1); struct gkyl_range local1, local_ext1; gkyl_create_grid_ranges(&grid1, nghost, &local_ext1, &local1); - - // Common basis int poly_order = 1; struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); // Block 2 duals - struct gkyl_array *dzdx2 = gkyl_array_new(GKYL_DOUBLE, 9*basis.num_basis, local_ext2.volume); + struct gkyl_array *dzdx2 = gkyl_array_new(GKYL_DOUBLE, 9 * basis.num_basis, local_ext2.volume); gkyl_eval_on_nodes *proj2 = gkyl_eval_on_nodes_new(&grid2, &basis, 9, &proj_one, 0); gkyl_eval_on_nodes_advance(proj2, 0.0, &local2, dzdx2); gkyl_eval_on_nodes_release(proj2); gkyl_grid_sub_array_write(&grid2, &local2, 0, dzdx2, "dzdx2.gkyl"); // Block 1 tangents - struct gkyl_array *dxdz1 = gkyl_array_new(GKYL_DOUBLE, 9*basis.num_basis, local_ext1.volume); + struct gkyl_array *dxdz1 = gkyl_array_new(GKYL_DOUBLE, 9 * basis.num_basis, local_ext1.volume); gkyl_eval_on_nodes *proj1 = gkyl_eval_on_nodes_new(&grid1, &basis, 9, &proj_cyl, 0); gkyl_eval_on_nodes_advance(proj1, 0.0, &local1, dxdz1); gkyl_eval_on_nodes_release(proj1); gkyl_grid_sub_array_write(&grid1, &local1, 0, dxdz1, "dxdz1.gkyl"); - - - struct bc_block_tensor *bt = gkyl_bc_block_tensor_new(&grid2, &local2, &local_ext2, &basis, false); + struct bc_block_tensor *bt = + gkyl_bc_block_tensor_new(&grid2, &local2, &local_ext2, &basis, false); int edge1 = 0; // lower edge int edge2 = 1; // upper edge int dir = 1; // second direction @@ -275,18 +264,17 @@ void test_block_tensor_cyl_cart_2x_z_ho() gkyl_bc_block_tensor_release(bt); } - void test_cartesian_3x_onecell() { - double lower[] = { -1, -1 ,-1}, upper[] = { 1, 1 ,1}; - int cells[] = { 8, 16,4 }; - int dim = sizeof(lower)/sizeof(lower[0]); + double lower[] = {-1, -1, -1}, upper[] = {1, 1, 1}; + int cells[] = {8, 16, 4}; + int dim = sizeof(lower) / sizeof(lower[0]); struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); //ranges struct gkyl_range local, local_ext; - int nghost[GKYL_MAX_CDIM] = { 1, 1 ,1}; + int nghost[GKYL_MAX_CDIM] = {1, 1, 1}; gkyl_create_grid_ranges(&grid, nghost, &local_ext, &local); // basis function int poly_order = 1; @@ -294,8 +282,8 @@ void test_cartesian_3x_onecell() gkyl_cart_modal_serendip(&basis, dim, poly_order); // Create cartesian tangent vectors and duals - struct gkyl_array *dxdz= gkyl_array_new(GKYL_DOUBLE, 9*basis.num_basis, local_ext.volume); - struct gkyl_array *dzdx= gkyl_array_new(GKYL_DOUBLE, 9*basis.num_basis, local_ext.volume); + struct gkyl_array *dxdz = gkyl_array_new(GKYL_DOUBLE, 9 * basis.num_basis, local_ext.volume); + struct gkyl_array *dzdx = gkyl_array_new(GKYL_DOUBLE, 9 * basis.num_basis, local_ext.volume); gkyl_eval_on_nodes *proj = gkyl_eval_on_nodes_new(&grid, &basis, 9, &proj_one, 0); gkyl_eval_on_nodes_advance(proj, 0.0, &local, dxdz); gkyl_eval_on_nodes_advance(proj, 0.0, &local, dzdx); @@ -308,21 +296,22 @@ void test_cartesian_3x_onecell() int edge1 = 1; //upper edge int edge2 = 0; //lower edge int dir = 2; // third direction - int idx1[3] = {4,8,4}; - int idx2[3] = {4,8,4}; + int idx1[3] = {4, 8, 4}; + int idx2[3] = {4, 8, 4}; long loc1 = gkyl_range_idx(&local, idx1); long loc2 = gkyl_range_idx(&local, idx2); const double *dxdz_i = gkyl_array_fetch(dxdz, loc1); const double *dzdx_j = gkyl_array_fetch(dzdx, loc2); int num_nodes = 4; - double tj_i[dim*dim*num_nodes]; + double tj_i[dim * dim * num_nodes]; calc_tensor(bt, dir, edge1, edge2, dzdx_j, dxdz_i, tj_i); - for(int n = 0; n #include - -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } -void -mapc2p_3x(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p_3x(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; xp[2] = xc[2]; + xp[0] = xc[0]; + xp[1] = xc[1]; + xp[2] = xc[2]; } - -void -bfield_func_3x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func_3x(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; fout[0] = 0.0; @@ -48,12 +46,12 @@ bfield_func_3x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx void eval_n(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 1.0e19*(1.0 + 0.5*cos(x)); + fout[0] = 1.0e19 * (1.0 + 0.5 * cos(x)); } -void eval_vtsq(double t, const double *xn, double* restrict fout, void *ctx) +void eval_vtsq(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - double vtsq = (10.0*1.602e-19/9.1e-31)*exp(-x*x/(M_PI)); + double vtsq = (10.0 * 1.602e-19 / 9.1e-31) * exp(-x * x / (M_PI)); fout[0] = vtsq; } void eval_upar(double t, const double *xn, double *restrict fout, void *ctx) @@ -62,7 +60,7 @@ void eval_upar(double t, const double *xn, double *restrict fout, void *ctx) double vtsq[1]; eval_vtsq(t, xn, vtsq, ctx); - double vt = sqrt(vtsq[0]); + double vt = sqrt(vtsq[0]); fout[0] = vt; } @@ -70,20 +68,20 @@ void eval_upar(double t, const double *xn, double *restrict fout, void *ctx) void eval_n_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], z = xn[1]; - fout[0] = 1.0e19*(1.0 + 0.5*cos(x)*sin(z)); + fout[0] = 1.0e19 * (1.0 + 0.5 * cos(x) * sin(z)); } -void eval_vtsq_2x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_vtsq_2x(double t, const double *xn, double *restrict fout, void *ctx) { // in 2D, just initialize a constant temperature double x = xn[0], z = xn[1]; - double vtsq = (10.0*1.602e-19/9.1e-31);//*exp(-x*x/(M_PI))*exp(-z*z/(M_PI)); + double vtsq = (10.0 * 1.602e-19 / 9.1e-31); //*exp(-x*x/(M_PI))*exp(-z*z/(M_PI)); fout[0] = vtsq; } void eval_upar_2x(double t, const double *xn, double *restrict fout, void *ctx) { double vtsq[1]; eval_vtsq_2x(t, xn, vtsq, ctx); - double vt = sqrt(vtsq[0]); + double vt = sqrt(vtsq[0]); fout[0] = vt; } @@ -92,27 +90,27 @@ void test_1x1v(int poly_order, bool use_gpu) { double mass = 9.1e-31; double err_max = 1.0e-10, iter_max = 50; - double vt = sqrt(10.0*1.602e-19/9.1e-31); // reference temperature - double lower[] = {-M_PI, -4.0*vt}, upper[] = {M_PI, 4.0*vt}; + double vt = sqrt(10.0 * 1.602e-19 / 9.1e-31); // reference temperature + double lower[] = {-M_PI, -4.0 * vt}, upper[] = {M_PI, 4.0 * vt}; int cells[] = {4, 16}; int vdim = 1; - int ndim = sizeof(cells)/sizeof(cells[0]); + int ndim = sizeof(cells) / sizeof(cells[0]); int cdim = ndim - vdim; double confLower[cdim], confUpper[cdim]; int confCells[cdim]; - for (int d=0; d 1) { gkyl_cart_modal_serendip(&basis, ndim, poly_order); - } - else if (poly_order == 1) { + } else if (poly_order == 1) { /* Force hybrid basis (p=2 in vpar). */ gkyl_cart_modal_gkhybrid(&basis, cdim, vdim); } gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); - int confGhost[] = { 1, 1, 1 }; // 3 elements because it's used by geo. + int confGhost[] = {1, 1, 1}; // 3 elements because it's used by geo. struct gkyl_range confLocal, confLocal_ext; // local, local-ext conf-space ranges gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); - int velGhost[] = { 0, 0 }; + int velGhost[] = {0, 0}; struct gkyl_range velLocal, velLocal_ext; // local, local-ext vel-space ranges gkyl_create_grid_ranges(&velGrid, velGhost, &velLocal_ext, &velLocal); - int ghost[GKYL_MAX_DIM] = { 0 }; - for (int d=0; d #include - -void -proj_func(double t, const double *xn, double *fout, void *ctx) +void proj_func(double t, const double *xn, double *fout, void *ctx) { double x = xn[0]; double z = xn[1]; - fout[0] = z*cos(x); + fout[0] = z * cos(x); } -void -proj_func2(double t, const double *xn, double *fout, void *ctx) +void proj_func2(double t, const double *xn, double *fout, void *ctx) { double x = xn[0]; double z = xn[1]; - fout[0] = sin((2.*M_PI/(2.*M_PI))*x); + fout[0] = sin((2. * M_PI / (2. * M_PI)) * x); } -void evalFunc1x_neumannx_dirichletx(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc1x_neumannx_dirichletx(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double a = 5.0; double c0 = 0.; - double c1 = a/12. - 1./2.; - fout[0] = -(1.-a*pow(x,2)); + double c1 = a / 12. - 1. / 2.; + fout[0] = -(1. - a * pow(x, 2)); } -void check_same(struct gkyl_range range, struct gkyl_basis basis, struct gkyl_array *field1, struct gkyl_array* field2) +void check_same( + struct gkyl_range range, struct gkyl_basis basis, struct gkyl_array *field1, + struct gkyl_array *field2 +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); @@ -50,33 +50,32 @@ void check_same(struct gkyl_range range, struct gkyl_basis basis, struct gkyl_ar long lidx = gkyl_range_idx(&range, iter.idx); const double *f1 = gkyl_array_cfetch(field1, lidx); const double *f2 = gkyl_array_cfetch(field2, lidx); - for(int i = 0; i< basis.num_basis; i++) - TEST_CHECK( gkyl_compare(f1[i], f2[i], 1e-10) ); + for (int i = 0; i < basis.num_basis; i++) { + TEST_CHECK(gkyl_compare(f1[i], f2[i], 1e-10)); + } } } - -void -test_deflate_inflate(bool use_gpu) +void test_deflate_inflate(bool use_gpu) { // Create the 2d field. // Create xz grid. - double lower[] = { -M_PI, 0.0 }, upper[] = { M_PI, 1.0 }; - int cells[] = { 12, 8 }; + double lower[] = {-M_PI, 0.0}, upper[] = {M_PI, 1.0}; + int cells[] = {12, 8}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 2, lower, upper, cells); // Ranges. struct gkyl_range local, local_ext; - int nghost[GKYL_MAX_CDIM] = { 1, 1 }; + int nghost[GKYL_MAX_CDIM] = {1, 1}; gkyl_create_grid_ranges(&grid, nghost, &local_ext, &local); // Basis function. int poly_order = 1; struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, 2, poly_order); - struct gkyl_basis *basis_on_dev = use_gpu? gkyl_cart_modal_serendip_cu_dev_new(2, poly_order) - : gkyl_cart_modal_serendip_new(2, poly_order); + struct gkyl_basis *basis_on_dev = use_gpu ? gkyl_cart_modal_serendip_cu_dev_new(2, poly_order) : + gkyl_cart_modal_serendip_new(2, poly_order); // Project initial function on 2d field. struct gkyl_array *field = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); @@ -84,58 +83,68 @@ test_deflate_inflate(bool use_gpu) gkyl_eval_on_nodes_advance(proj, 0.0, &local, field); gkyl_eval_on_nodes_release(proj); //gkyl_grid_sub_array_write(&grid, &local, 0, field, "in_field.gkyl"); - struct gkyl_array *field_dev = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) - : gkyl_array_acquire(field); + struct gkyl_array *field_dev = + use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : + gkyl_array_acquire(field); gkyl_array_copy(field_dev, field); // Create deflated 1d grid, ranges, basis, and field. - double deflated_lower[] = { -M_PI}, deflated_upper[] = { M_PI}; - int deflated_cells[] = { 12}; + double deflated_lower[] = {-M_PI}, deflated_upper[] = {M_PI}; + int deflated_cells[] = {12}; struct gkyl_rect_grid deflated_grid; gkyl_rect_grid_init(&deflated_grid, 1, deflated_lower, deflated_upper, deflated_cells); // Ranges. struct gkyl_range deflated_local, deflated_local_ext; - int deflated_nghost[GKYL_MAX_CDIM] = { 1 }; + int deflated_nghost[GKYL_MAX_CDIM] = {1}; gkyl_create_grid_ranges(&deflated_grid, deflated_nghost, &deflated_local_ext, &deflated_local); // Deflated basis function. int deflated_poly_order = 1; struct gkyl_basis deflated_basis; gkyl_cart_modal_serendip(&deflated_basis, 1, deflated_poly_order); - struct gkyl_basis *deflated_basis_on_dev = use_gpu? gkyl_cart_modal_serendip_cu_dev_new(1, poly_order) - : gkyl_cart_modal_serendip_new(1, poly_order); - + struct gkyl_basis *deflated_basis_on_dev = use_gpu ? + gkyl_cart_modal_serendip_cu_dev_new(1, poly_order) : + gkyl_cart_modal_serendip_new(1, poly_order); + // Deflated field. - struct gkyl_array *deflated_field = gkyl_array_new(GKYL_DOUBLE, deflated_basis.num_basis, deflated_local_ext.volume); - struct gkyl_array *deflated_field_dev = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, deflated_basis.num_basis, deflated_local_ext.volume) - : gkyl_array_acquire(deflated_field); + struct gkyl_array *deflated_field = + gkyl_array_new(GKYL_DOUBLE, deflated_basis.num_basis, deflated_local_ext.volume); + struct gkyl_array *deflated_field_dev = + use_gpu ? + gkyl_array_cu_dev_new(GKYL_DOUBLE, deflated_basis.num_basis, deflated_local_ext.volume) : + gkyl_array_acquire(deflated_field); // Create nrange and the 2d nodal array to be populated. - int nodes[2] = { 1, 1 }; - if (poly_order == 1){ - for (int d=0; d Store the result in the 2d nodal field. - gkyl_nodal_ops_m2n_deflated(n2m_1d, deflated_basis_on_dev, - &deflated_grid, &nrange, &deflated_nrange, &deflated_local, 1, - nodal_fld_dev, deflated_field_dev, ctr); + gkyl_nodal_ops_m2n_deflated( + n2m_1d, deflated_basis_on_dev, &deflated_grid, &nrange, &deflated_nrange, &deflated_local, 1, + nodal_fld_dev, deflated_field_dev, ctr + ); ctr += 1; - if (zidx == local.upper[1]){ - gkyl_deflate_zsurf_advance(deflator_up, zidx, &local, &deflated_local, field_dev, deflated_field_dev, 1); - gkyl_nodal_ops_m2n_deflated(n2m_1d, deflated_basis_on_dev, - &deflated_grid, &nrange, &deflated_nrange, &deflated_local, 1, - nodal_fld_dev, deflated_field_dev, ctr); + if (zidx == local.upper[1]) { + gkyl_deflate_zsurf_advance( + deflator_up, zidx, &local, &deflated_local, field_dev, deflated_field_dev, 1 + ); + gkyl_nodal_ops_m2n_deflated( + n2m_1d, deflated_basis_on_dev, &deflated_grid, &nrange, &deflated_nrange, &deflated_local, + 1, nodal_fld_dev, deflated_field_dev, ctr + ); } } struct gkyl_array *out_field = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); - struct gkyl_array *out_field_dev = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : gkyl_array_acquire(out_field); + struct gkyl_array *out_field_dev = + use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : + gkyl_array_acquire(out_field); // Convert back to modal and do a check. struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&basis, &grid, use_gpu); - gkyl_nodal_ops_n2m(n2m, basis_on_dev, &grid, &nrange, &local, 1, nodal_fld_dev, out_field_dev, false); + gkyl_nodal_ops_n2m( + n2m, basis_on_dev, &grid, &nrange, &local, 1, nodal_fld_dev, out_field_dev, false + ); gkyl_array_copy(out_field, out_field_dev); //gkyl_grid_sub_array_write(&grid, &local, 0, out_field, "out_field.gkyl"); @@ -177,8 +196,7 @@ test_deflate_inflate(bool use_gpu) if (use_gpu) { gkyl_cart_modal_basis_release_cu(basis_on_dev); gkyl_cart_modal_basis_release_cu(deflated_basis_on_dev); - } - else { + } else { gkyl_cart_modal_basis_release(basis_on_dev); gkyl_cart_modal_basis_release(deflated_basis_on_dev); } @@ -191,26 +209,25 @@ test_deflate_inflate(bool use_gpu) gkyl_array_release(out_field_dev); gkyl_array_release(deflated_field_dev); gkyl_array_release(nodal_fld_dev); - + gkyl_nodal_ops_release(n2m_1d); gkyl_nodal_ops_release(n2m); gkyl_deflate_zsurf_release(deflator_lo); gkyl_deflate_zsurf_release(deflator_up); } -void -test_deflate_zsurf_poisson_slices_ho() +void test_deflate_zsurf_poisson_slices_ho() { // Create the 2d field. // Create xz grid. - double lower[] = { -M_PI, 0.0 }, upper[] = { 3*M_PI/2, 1.0 }; - int cells[] = { 12, 8 }; + double lower[] = {-M_PI, 0.0}, upper[] = {3 * M_PI / 2, 1.0}; + int cells[] = {12, 8}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 2, lower, upper, cells); // Ranges. struct gkyl_range local, local_ext; - int nghost[GKYL_MAX_CDIM] = { 1, 1 }; + int nghost[GKYL_MAX_CDIM] = {1, 1}; gkyl_create_grid_ranges(&grid, nghost, &local_ext, &local); // Basis function. @@ -227,14 +244,14 @@ test_deflate_zsurf_poisson_slices_ho() // Create deflated 1d grid, ranges, basis, and field. // Create xz grid. - double deflated_lower[] = { -M_PI}, deflated_upper[] = { M_PI}; - int deflated_cells[] = { 12}; + double deflated_lower[] = {-M_PI}, deflated_upper[] = {M_PI}; + int deflated_cells[] = {12}; struct gkyl_rect_grid deflated_grid; gkyl_rect_grid_init(&deflated_grid, 1, deflated_lower, deflated_upper, deflated_cells); // Ranges, struct gkyl_range deflated_local, deflated_local_ext; - int deflated_nghost[GKYL_MAX_CDIM] = { 1 }; + int deflated_nghost[GKYL_MAX_CDIM] = {1}; gkyl_create_grid_ranges(&deflated_grid, deflated_nghost, &deflated_local_ext, &deflated_local); // Basis function. @@ -243,40 +260,47 @@ test_deflate_zsurf_poisson_slices_ho() gkyl_cart_modal_serendip(&deflated_basis, 1, deflated_poly_order); // Field. - struct gkyl_array *deflated_field = gkyl_array_new(GKYL_DOUBLE, deflated_basis.num_basis, deflated_local_ext.volume); - struct gkyl_array *deflated_phi = gkyl_array_new(GKYL_DOUBLE, deflated_basis.num_basis, deflated_local_ext.volume); + struct gkyl_array *deflated_field = + gkyl_array_new(GKYL_DOUBLE, deflated_basis.num_basis, deflated_local_ext.volume); + struct gkyl_array *deflated_phi = + gkyl_array_new(GKYL_DOUBLE, deflated_basis.num_basis, deflated_local_ext.volume); // Create nrange and the 2d nodal array to be populated. - int nodes[2] = { 1, 1 }; - if (poly_order == 1){ - for (int d=0; d - -void -proj_jac(double t, const double *xn, double *fout, void *ctx) +void proj_jac(double t, const double *xn, double *fout, void *ctx) { double x = xn[0]; double z = xn[1]; - fout[0] = 1.0 + z*z*cos(x); + fout[0] = 1.0 + z * z * cos(x); } -void -proj_rho(double t, const double *xn, double *fout, void *ctx) +void proj_rho(double t, const double *xn, double *fout, void *ctx) { double x = xn[0]; double z = xn[1]; - fout[0] = z*sin((2.*M_PI/(2.*M_PI))*x); + fout[0] = z * sin((2. * M_PI / (2. * M_PI)) * x); } // Check continuity along last dim in 2x -void check_continuity_2x(struct gkyl_rect_grid grid, struct gkyl_range range, struct gkyl_basis basis, struct gkyl_array *field) +void check_continuity_2x( + struct gkyl_rect_grid grid, struct gkyl_range range, struct gkyl_basis basis, + struct gkyl_array *field +) { struct gkyl_array *nodes = gkyl_array_new(GKYL_DOUBLE, grid.ndim, basis.num_basis); basis.node_list(gkyl_array_fetch(nodes, 0)); @@ -48,7 +48,7 @@ void check_continuity_2x(struct gkyl_rect_grid grid, struct gkyl_range range, st int nidx; long lin_nidx; int idx[3]; - const double *node_i ; + const double *node_i; while (gkyl_range_iter_next(&iter)) { if (iter.idx[1] != range.upper[1]) { @@ -58,22 +58,25 @@ void check_continuity_2x(struct gkyl_rect_grid grid, struct gkyl_range range, st long lidx_up = gkyl_range_idx(&range, idx); double *arr = gkyl_array_fetch(field, lidx); double *arr_up = gkyl_array_fetch(field, lidx_up); - node_i = gkyl_array_cfetch(nodes, 2); + node_i = gkyl_array_cfetch(nodes, 2); double temp1 = basis.eval_expand(node_i, arr); - node_i = gkyl_array_cfetch(nodes, 3); + node_i = gkyl_array_cfetch(nodes, 3); double temp2 = basis.eval_expand(node_i, arr); - node_i = gkyl_array_cfetch(nodes, 0); + node_i = gkyl_array_cfetch(nodes, 0); double temp_up1 = basis.eval_expand(node_i, arr_up); - node_i = gkyl_array_cfetch(nodes, 1); + node_i = gkyl_array_cfetch(nodes, 1); double temp_up2 = basis.eval_expand(node_i, arr_up); - TEST_CHECK( gkyl_compare(temp1, temp_up1, 1e-12) ); - TEST_CHECK( gkyl_compare(temp2, temp_up2, 1e-12) ); + TEST_CHECK(gkyl_compare(temp1, temp_up1, 1e-12)); + TEST_CHECK(gkyl_compare(temp2, temp_up2, 1e-12)); } } gkyl_array_release(nodes); } -void check_same(struct gkyl_range range, struct gkyl_basis basis, struct gkyl_array *field1, struct gkyl_array* field2) +void check_same( + struct gkyl_range range, struct gkyl_basis basis, struct gkyl_array *field1, + struct gkyl_array *field2 +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); @@ -81,29 +84,27 @@ void check_same(struct gkyl_range range, struct gkyl_basis basis, struct gkyl_ar long lidx = gkyl_range_idx(&range, iter.idx); const double *f1 = gkyl_array_cfetch(field1, lidx); const double *f2 = gkyl_array_cfetch(field2, lidx); - for(int i = 0; i< basis.num_basis; i++) - TEST_CHECK( gkyl_compare(f1[i], f2[i], 1e-10) ); + for (int i = 0; i < basis.num_basis; i++) { + TEST_CHECK(gkyl_compare(f1[i], f2[i], 1e-10)); + } } } - - -void -test_bop(bool use_gpu) +void test_bop(bool use_gpu) { int c_lop = 0; int c_rop = 0; int c_oop = 0; // create the 2d field // create xz grid - double lower[] = { -M_PI, 0.0 }, upper[] = { M_PI, 1.0 }; - int cells[] = { 12, 8 }; + double lower[] = {-M_PI, 0.0}, upper[] = {M_PI, 1.0}; + int cells[] = {12, 8}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 2, lower, upper, cells); //ranges struct gkyl_range local, local_ext; - int nghost[GKYL_MAX_CDIM] = { 1, 1 }; + int nghost[GKYL_MAX_CDIM] = {1, 1}; gkyl_create_grid_ranges(&grid, nghost, &local_ext, &local); struct gkyl_range global_sub_range = local; @@ -112,8 +113,8 @@ test_bop(bool use_gpu) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, 2, poly_order); - struct gkyl_basis *basis_on_dev = use_gpu? gkyl_cart_modal_serendip_cu_dev_new(2, poly_order) - : gkyl_cart_modal_serendip_new(2, poly_order); + struct gkyl_basis *basis_on_dev = use_gpu ? gkyl_cart_modal_serendip_cu_dev_new(2, poly_order) : + gkyl_cart_modal_serendip_new(2, poly_order); // project initial functions on 2d field struct gkyl_array *rho = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); @@ -121,7 +122,7 @@ test_bop(bool use_gpu) gkyl_proj_on_basis_advance(proj, 0.0, &local, rho); gkyl_proj_on_basis_release(proj); - struct gkyl_array *jac= gkyl_array_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); + struct gkyl_array *jac = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); gkyl_eval_on_nodes *eon = gkyl_eval_on_nodes_new(&grid, &basis, 1, &proj_jac, 0); gkyl_eval_on_nodes_advance(eon, 0.0, &local, jac); gkyl_eval_on_nodes_release(eon); @@ -131,12 +132,16 @@ test_bop(bool use_gpu) // Get C = rho.J struct gkyl_array *Cxz = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); - gkyl_dg_mul_op(&basis, 0, Cxz, 0,rho, 0, jac); + gkyl_dg_mul_op(&basis, 0, Cxz, 0, rho, 0, jac); //gkyl_grid_sub_array_write(&grid, &local, 0, Cxz, "Cxz.gkyl"); - struct gkyl_array *Cxz_dev = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : gkyl_array_acquire(Cxz); + struct gkyl_array *Cxz_dev = + use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : + gkyl_array_acquire(Cxz); gkyl_array_copy(Cxz_dev, Cxz); - struct gkyl_array *jac_dev = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : gkyl_array_acquire(jac); + struct gkyl_array *jac_dev = + use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : + gkyl_array_acquire(jac); gkyl_array_copy(jac_dev, jac); // Allocate Exz which will store C/J, the smoothed version of it, and @@ -145,12 +150,19 @@ test_bop(bool use_gpu) struct gkyl_array *Exz_smooth = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); struct gkyl_array *Fxz = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); - struct gkyl_array *Exz_dev = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : gkyl_array_acquire(Exz); - struct gkyl_array *Exz_smooth_dev = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : gkyl_array_acquire(Exz_smooth); - struct gkyl_array *Fxz_dev = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : gkyl_array_acquire(Fxz); + struct gkyl_array *Exz_dev = + use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : + gkyl_array_acquire(Exz); + struct gkyl_array *Exz_smooth_dev = + use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : + gkyl_array_acquire(Exz_smooth); + struct gkyl_array *Fxz_dev = + use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume) : + gkyl_array_acquire(Fxz); // Make deflated array operator - struct gkyl_deflated_dg_bin_ops* operator = gkyl_deflated_dg_bin_ops_new(grid, basis_on_dev, basis, local, use_gpu); + struct gkyl_deflated_dg_bin_ops *operator= + gkyl_deflated_dg_bin_ops_new(grid, basis_on_dev, basis, local, use_gpu); // Divide gkyl_deflated_dg_bin_ops_div(operator, c_oop, Exz_dev, c_lop, Cxz_dev, c_rop, jac_dev); @@ -159,7 +171,8 @@ test_bop(bool use_gpu) //gkyl_grid_sub_array_write(&grid, &local, 0, Exz, "Exz.gkyl"); // Smooth E - struct gkyl_fem_parproj *fem_parproj = gkyl_fem_parproj_new(&local, &grid, &basis, GKYL_FEM_PARPROJ_NONE, 0, 0, 0, use_gpu); + struct gkyl_fem_parproj *fem_parproj = + gkyl_fem_parproj_new(&local, &grid, &basis, GKYL_FEM_PARPROJ_NONE, 0, 0, 0, use_gpu); gkyl_fem_parproj_set_rhs(fem_parproj, Exz_dev, Exz_dev); gkyl_fem_parproj_solve(fem_parproj, Exz_smooth_dev); gkyl_fem_parproj_release(fem_parproj); @@ -169,16 +182,17 @@ test_bop(bool use_gpu) // Multiply gkyl_deflated_dg_bin_ops_mul(operator, c_oop, Fxz_dev, c_lop, Exz_smooth_dev, c_rop, jac_dev); - + gkyl_array_copy(Fxz, Fxz_dev); //gkyl_grid_sub_array_write(&grid, &local, 0, Fxz, "Fxz.gkyl"); check_continuity_2x(grid, local, basis, Fxz); - - if (use_gpu) + + if (use_gpu) { gkyl_cart_modal_basis_release_cu(basis_on_dev); - else + } else { gkyl_cart_modal_basis_release(basis_on_dev); + } gkyl_array_release(rho); gkyl_array_release(jac); @@ -191,21 +205,23 @@ test_bop(bool use_gpu) gkyl_array_release(Exz_dev); gkyl_array_release(Exz_smooth_dev); gkyl_array_release(Fxz_dev); - - gkyl_deflated_dg_bin_ops_release(operator); - } -void test_deflated_bop_ho(void) { test_bop(false); } -void test_deflated_bop_dev(void) { test_bop(true); } +void test_deflated_bop_ho(void) +{ + test_bop(false); +} +void test_deflated_bop_dev(void) +{ + test_bop(true); +} TEST_LIST = { - { "test_deflated_bop_ho", test_deflated_bop_ho}, + {"test_deflated_bop_ho", test_deflated_bop_ho}, #ifdef GKYL_HAVE_CUDA - { "test_deflated_bop_dev", test_deflated_bop_dev}, + {"test_deflated_bop_dev", test_deflated_bop_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; - diff --git a/gyrokinetic/unit/ctest_deflated_fem_poisson.c b/gyrokinetic/unit/ctest_deflated_fem_poisson.c index f4fc952b6d..b88545f370 100644 --- a/gyrokinetic/unit/ctest_deflated_fem_poisson.c +++ b/gyrokinetic/unit/ctest_deflated_fem_poisson.c @@ -19,8 +19,10 @@ #include #include - -double calc_l2(struct gkyl_rect_grid grid, struct gkyl_range range, struct gkyl_range range_ext, struct gkyl_basis basis, struct gkyl_array* field1, struct gkyl_array* field2) +double calc_l2( + struct gkyl_rect_grid grid, struct gkyl_range range, struct gkyl_range range_ext, + struct gkyl_basis basis, struct gkyl_array *field1, struct gkyl_array *field2 +) { struct gkyl_array *diff = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, range_ext.volume); struct gkyl_range_iter iter; @@ -30,7 +32,7 @@ double calc_l2(struct gkyl_rect_grid grid, struct gkyl_range range, struct gkyl_ const double *f1 = gkyl_array_cfetch(field1, lidx); const double *f2 = gkyl_array_cfetch(field2, lidx); double *diff_i = gkyl_array_fetch(diff, lidx); - for(int i = 0; i 0) - TEST_CHECK( l2s[i-1]>3.5*l2s[i] ); - i+=1; + for (int nx = 4; nx < 129; nx *= 2) { + l2s[i] = test_zind_dd_nxnz(nx, ny); + if (i > 0) { + TEST_CHECK(l2s[i - 1] > 3.5 * l2s[i]); + } + i += 1; } } -void test_deflated_fem_poisson_simplez_dd_ho(){ +void test_deflated_fem_poisson_simplez_dd_ho() +{ double l2s[6]; int ny = 32; int i = 0; - for(int nx = 4; nx < 129; nx*=2){ - l2s[i] = test_simplez_dd_nxnz(nx,ny); - if (i > 0) - TEST_CHECK( l2s[i-1]>3.5*l2s[i] ); - i+=1; + for (int nx = 4; nx < 129; nx *= 2) { + l2s[i] = test_simplez_dd_nxnz(nx, ny); + if (i > 0) { + TEST_CHECK(l2s[i - 1] > 3.5 * l2s[i]); + } + i += 1; } } -void test_deflated_fem_poisson_zdep_nd_ho(){ +void test_deflated_fem_poisson_zdep_nd_ho() +{ // Expected results //double l2s[6] = { 1.4891748591339167, 0.4361776844752765, 0.1139546668200294, 0.0288104647768966, 0.0072320934639821, 0.0018431764053742}; double l2s[6]; int ny = 32; int i = 0; - for(int nx = 4; nx < 129; nx*=2){ - l2s[i] = test_zdep_nd_nxnz(nx,ny); - if (i > 0) - TEST_CHECK( l2s[i-1]>3.0*l2s[i] ); - i+=1; + for (int nx = 4; nx < 129; nx *= 2) { + l2s[i] = test_zdep_nd_nxnz(nx, ny); + if (i > 0) { + TEST_CHECK(l2s[i - 1] > 3.0 * l2s[i]); + } + i += 1; } } -void test_deflated_fem_poisson_3x_dd_dd_ho(){ +void test_deflated_fem_poisson_3x_dd_dd_ho() +{ // Expected results //double l2s[6] = { 4.2333527815296019, 1.5169449008531153, 0.4618522366946782, 0.1324749882413162, 0.0438774243422054, 0.0212827374990034}; double l2s[6]; int ny = 32; int nz = 20; int i = 0; - for(int nx = 4; nx < 129; nx*=2){ - l2s[i] = test_3x_dd_dd_nxnynz(nx,ny, nz); - if (i > 0) - TEST_CHECK( l2s[i-1]>2.0*l2s[i] ); - i+=1; + for (int nx = 4; nx < 129; nx *= 2) { + l2s[i] = test_3x_dd_dd_nxnynz(nx, ny, nz); + if (i > 0) { + TEST_CHECK(l2s[i - 1] > 2.0 * l2s[i]); + } + i += 1; } } - TEST_LIST = { - { "test_deflated_fem_poisson_zind_dd_ho", test_deflated_fem_poisson_zind_dd_ho}, - { "test_deflated_fem_poisson_simplez_dd_ho", test_deflated_fem_poisson_simplez_dd_ho}, - { "test_deflated_fem_poisson_zdep_nd_ho", test_deflated_fem_poisson_zdep_nd_ho}, - { "test_deflated_fem_poisson_3x_dd_dd_ho", test_deflated_fem_poisson_3x_dd_dd_ho}, - { NULL, NULL }, + {"test_deflated_fem_poisson_zind_dd_ho", test_deflated_fem_poisson_zind_dd_ho}, + {"test_deflated_fem_poisson_simplez_dd_ho", test_deflated_fem_poisson_simplez_dd_ho}, + {"test_deflated_fem_poisson_zdep_nd_ho", test_deflated_fem_poisson_zdep_nd_ho}, + {"test_deflated_fem_poisson_3x_dd_dd_ho", test_deflated_fem_poisson_3x_dd_dd_ho}, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_dg_cx.c b/gyrokinetic/unit/ctest_dg_cx.c index 8e73287fb0..a02cd6b38c 100644 --- a/gyrokinetic/unit/ctest_dg_cx.c +++ b/gyrokinetic/unit/ctest_dg_cx.c @@ -11,61 +11,61 @@ #include // Allocate array (filled with zeros). -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } // Global variables double echarge = GKYL_ELEMENTARY_CHARGE; double emass = GKYL_ELECTRON_MASS; -double d_ion_mass = GKYL_PROTON_MASS*2.01410177811; +double d_ion_mass = GKYL_PROTON_MASS * 2.01410177811; double B0 = 0.5; double check_fac = 1.0e10; -void eval_n(double t, const double *xn, double* restrict fout, void *ctx) +void eval_n(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 1.0e19; } -void eval_T_over_m_ion(double t, const double *xn, double* restrict fout, void *ctx) +void eval_T_over_m_ion(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 40.*echarge/d_ion_mass; + fout[0] = 40. * echarge / d_ion_mass; } -void eval_T_over_m_neut(double t, const double *xn, double* restrict fout, void *ctx) +void eval_T_over_m_neut(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 4.*echarge/d_ion_mass; + fout[0] = 4. * echarge / d_ion_mass; } -static inline -void proj_on_basis_copy(const struct gkyl_proj_on_basis *proj_op, double tm, struct gkyl_range *rng, - struct gkyl_array *arr, bool use_gpu) +static inline void proj_on_basis_copy( + const struct gkyl_proj_on_basis *proj_op, double tm, struct gkyl_range *rng, + struct gkyl_array *arr, bool use_gpu +) { - struct gkyl_array *arr_ho = use_gpu? mkarr(false, arr->ncomp, arr->size) - : gkyl_array_acquire(arr); + struct gkyl_array *arr_ho = use_gpu ? mkarr(false, arr->ncomp, arr->size) : + gkyl_array_acquire(arr); gkyl_proj_on_basis_advance(proj_op, tm, rng, arr_ho); gkyl_array_copy(arr, arr_ho); gkyl_array_release(arr_ho); } // test 2x2v / 2x3v -void -test_coll_cx_d(bool use_gpu) +void test_coll_cx_d(bool use_gpu) { int charge_state = 0; int poly_order = 1; int cdim = 2, vdim_vl = 3; - // Grids - double lower_ion[] = {-2.0,-2.0}, upper_ion[] = {2.0,2.0}; + // Grids + double lower_ion[] = {-2.0, -2.0}, upper_ion[] = {2.0, 2.0}; int ghost_gk[] = {0, 0}; int cells_gk[] = {2, 2}; @@ -79,104 +79,111 @@ test_coll_cx_d(bool use_gpu) gkyl_cart_modal_serendip(&basis, cdim, poly_order); // Projection updater for moments. - gkyl_proj_on_basis *proj_n = gkyl_proj_on_basis_new(&confGrid, &basis, - poly_order+1, 1, eval_n, NULL); - gkyl_proj_on_basis *proj_T_over_m_ion = gkyl_proj_on_basis_new(&confGrid, &basis, - poly_order+1, 1, eval_T_over_m_ion, NULL); - gkyl_proj_on_basis *proj_T_over_m_neut = gkyl_proj_on_basis_new(&confGrid, &basis, - poly_order+1, 1, eval_T_over_m_neut, NULL); - - double vt_sq_ion_min = 1*echarge/d_ion_mass; - double vt_sq_neut_min = 1*echarge/d_ion_mass; + gkyl_proj_on_basis *proj_n = + gkyl_proj_on_basis_new(&confGrid, &basis, poly_order + 1, 1, eval_n, NULL); + gkyl_proj_on_basis *proj_T_over_m_ion = + gkyl_proj_on_basis_new(&confGrid, &basis, poly_order + 1, 1, eval_T_over_m_ion, NULL); + gkyl_proj_on_basis *proj_T_over_m_neut = + gkyl_proj_on_basis_new(&confGrid, &basis, poly_order + 1, 1, eval_T_over_m_neut, NULL); + + double vt_sq_ion_min = 1 * echarge / d_ion_mass; + double vt_sq_neut_min = 1 * echarge / d_ion_mass; struct gkyl_dg_cx_inp cx_inp = { .cbasis = &basis, .conf_rng = &confRange, - .vt_sq_ion_min = vt_sq_ion_min, - .vt_sq_neut_min = vt_sq_neut_min, - .type_ion = GKYL_ION_D, + .vt_sq_ion_min = vt_sq_ion_min, + .vt_sq_neut_min = vt_sq_neut_min, + .type_ion = GKYL_ION_D }; - + // Coll struct. - struct gkyl_dg_cx *coll_cx_up = gkyl_dg_cx_new(&cx_inp, use_gpu);; + struct gkyl_dg_cx *coll_cx_up = gkyl_dg_cx_new(&cx_inp, use_gpu); + ; struct gkyl_array *n_ion = mkarr(use_gpu, basis.num_basis, confRange.volume); struct gkyl_array *T_over_m_ion = mkarr(use_gpu, basis.num_basis, confRange.volume); - struct gkyl_array *moms_ion = mkarr(use_gpu, (1+2)*basis.num_basis, confRange.volume); + struct gkyl_array *moms_ion = mkarr(use_gpu, (1 + 2) * basis.num_basis, confRange.volume); struct gkyl_array *n_neut = mkarr(use_gpu, basis.num_basis, confRange.volume); struct gkyl_array *T_over_m_neut = mkarr(use_gpu, basis.num_basis, confRange.volume); - struct gkyl_array *moms_neut = mkarr(use_gpu, (3+2)*basis.num_basis, confRange.volume); + struct gkyl_array *moms_neut = mkarr(use_gpu, (3 + 2) * basis.num_basis, confRange.volume); struct gkyl_array *coef_cx = mkarr(use_gpu, basis.num_basis, confRange.volume); - + // Arrays necessary for prim_vars. - struct gkyl_array *u_par_ion = mkarr(use_gpu, 3*basis.num_basis, confRange.volume); - struct gkyl_array *b_i = mkarr(use_gpu, 3*basis.num_basis, confRange.volume); + struct gkyl_array *u_par_ion = mkarr(use_gpu, 3 * basis.num_basis, confRange.volume); + struct gkyl_array *b_i = mkarr(use_gpu, 3 * basis.num_basis, confRange.volume); struct gkyl_array *b_x = mkarr(use_gpu, basis.num_basis, confRange.volume); struct gkyl_array *b_y = mkarr(use_gpu, basis.num_basis, confRange.volume); struct gkyl_array *b_z = mkarr(use_gpu, basis.num_basis, confRange.volume); - + // Project moments on basis. proj_on_basis_copy(proj_n, 0.0, &confRange, n_ion, use_gpu); proj_on_basis_copy(proj_T_over_m_ion, 0.0, &confRange, T_over_m_ion, use_gpu); gkyl_array_set_offset(moms_ion, 1.0, n_ion, 0); - gkyl_array_set_offset(moms_ion, 1.0, T_over_m_ion, (1+1)*basis.num_basis); + gkyl_array_set_offset(moms_ion, 1.0, T_over_m_ion, (1 + 1) * basis.num_basis); proj_on_basis_copy(proj_n, 0.0, &confRange, n_neut, use_gpu); proj_on_basis_copy(proj_T_over_m_neut, 0.0, &confRange, T_over_m_neut, use_gpu); gkyl_array_set_offset(moms_neut, 1.0, n_neut, 0); - gkyl_array_set_offset(moms_neut, 1.0, T_over_m_neut, (1+vdim_vl)*basis.num_basis); + gkyl_array_set_offset(moms_neut, 1.0, T_over_m_neut, (1 + vdim_vl) * basis.num_basis); // Project b_i. gkyl_array_set_offset(b_i, 1.0, b_x, 0); gkyl_array_set_offset(b_i, 1.0, b_y, basis.num_basis); - gkyl_array_set_offset(b_i, 1.0, b_z, 2*basis.num_basis); + gkyl_array_set_offset(b_i, 1.0, b_z, 2 * basis.num_basis); // Compute the CX reaction rate. - gkyl_dg_cx_coll(coll_cx_up, moms_ion, moms_neut, u_par_ion, coef_cx, 0); + gkyl_dg_cx_coll(coll_cx_up, moms_ion, moms_neut, u_par_ion, coef_cx, 0); - struct gkyl_array *coef_cx_ho = use_gpu? mkarr(false, coef_cx->ncomp, coef_cx->size) - : gkyl_array_acquire(coef_cx); + struct gkyl_array *coef_cx_ho = use_gpu ? mkarr(false, coef_cx->ncomp, coef_cx->size) : + gkyl_array_acquire(coef_cx); gkyl_array_copy(coef_cx_ho, coef_cx); - const double *cv_cx = gkyl_array_cfetch(coef_cx_ho, gkyl_range_idx(&confRange, (int[2]) { 1, 1})); + const double *cv_cx = gkyl_array_cfetch(coef_cx_ho, gkyl_range_idx(&confRange, (int[2]){1, 1})); // Test against predicted value. - double p1_vals[] = {3.242709205939892e-14, 0.000000000000000e+00, - 0.000000000000000e+00, 0.000000000000000e+00}; - for (int i=0; i #include -void -mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; xp[2] = xc[2]; + xp[0] = xc[0]; + xp[1] = xc[1]; + xp[2] = xc[2]; } -void -bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; fout[1] = 0.0; fout[2] = 1.0; } -void -test_dg_gyrokinetic_ho() +void test_dg_gyrokinetic_ho() { // initialize grid and ranges int cdim = 3, vdim = 2; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int cells[] = {8, 8, 8, 8, 8}; int ghost[] = {1, 1, 1, 0, 0}; @@ -51,13 +50,13 @@ test_dg_gyrokinetic_ho() double velLower[vdim], velUpper[vdim]; int velCells[vdim]; - for (int d=0; dnum_equations == 1 ); + TEST_CHECK(eqn->num_equations == 1); // this is not possible from user code and should NOT be done. This // is for testing only struct dg_gyrokinetic *gyrokinetic = container_of(eqn, struct dg_gyrokinetic, eqn); - TEST_CHECK( gyrokinetic->cdim == 3 ); - TEST_CHECK( gyrokinetic->pdim == 5 ); - TEST_CHECK( gyrokinetic->conf_range.volume == 512 ); + TEST_CHECK(gyrokinetic->cdim == 3); + TEST_CHECK(gyrokinetic->pdim == 5); + TEST_CHECK(gyrokinetic->conf_range.volume == 512); - gkyl_gk_geometry_release(gk_geom); + gkyl_gk_geometry_release(gk_geom); gkyl_position_map_release(pmap); gkyl_velocity_map_release(gvm); gkyl_dg_eqn_release(eqn); @@ -133,8 +134,8 @@ test_dg_gyrokinetic_ho() #endif TEST_LIST = { - { "dg_gyrokinetic_ho", test_dg_gyrokinetic_ho }, + {"dg_gyrokinetic_ho", test_dg_gyrokinetic_ho}, #ifdef GKYL_HAVE_CUDA -#endif - { NULL, NULL }, +#endif + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_dg_gyrokinetic_kern_tm.c b/gyrokinetic/unit/ctest_dg_gyrokinetic_kern_tm.c index 87f0b962ec..2529237a6a 100644 --- a/gyrokinetic/unit/ctest_dg_gyrokinetic_kern_tm.c +++ b/gyrokinetic/unit/ctest_dg_gyrokinetic_kern_tm.c @@ -13,37 +13,36 @@ #include #include -void -mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; xp[2] = xc[2]; + xp[0] = xc[0]; + xp[1] = xc[1]; + xp[2] = xc[2]; } -void -bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; fout[1] = 0.0; fout[2] = 1.0; } -static struct gkyl_array* -mkarr1(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr1(bool use_gpu, long nc, long size) { - struct gkyl_array* a; - if (use_gpu) + struct gkyl_array *a; + if (use_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } -void -test_3x2v_p1(bool use_gpu) +void test_3x2v_p1(bool use_gpu) { // initialize grid and ranges int cdim = 3, vdim = 2; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int cells[] = {8, 8, 8, 8, 8}; int ghost[] = {1, 1, 1, 0, 0}; @@ -62,13 +61,13 @@ test_3x2v_p1(bool use_gpu) double velLower[vdim], velUpper[vdim]; int velCells[vdim]; - for (int d=0; d 1) { gkyl_cart_modal_serendip(&basis, pdim, poly_order); - gkyl_cart_modal_serendip(&surf_basis, pdim-1, poly_order); + gkyl_cart_modal_serendip(&surf_basis, pdim - 1, poly_order); } else if (poly_order == 1) { /* Force hybrid basis (p=2 in velocity space). */ gkyl_cart_modal_gkhybrid(&basis, cdim, vdim); - gkyl_cart_modal_gkhybrid(&surf_basis, cdim-1, vdim); + gkyl_cart_modal_gkhybrid(&surf_basis, cdim - 1, vdim); } gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); @@ -91,52 +90,56 @@ test_3x2v_p1(bool use_gpu) // Initialize geometry struct gkyl_gk_geometry_inp geometry_input = { - .geometry_id = GKYL_GEOMETRY_MAPC2P, - .world = {0.0, 0.0}, - .mapc2p = mapc2p, // mapping of computational to physical space - .c2p_ctx = 0, - .bfield_func = bfield_func, // magnetic field magnitude - .bfield_ctx =0 , - .position_map = pmap, - .grid = confGrid, - .local = confRange, - .local_ext = confRange_ext, - .global = confRange, - .global_ext = confRange_ext, - .basis = confBasis, - .geo_grid = confGrid, - .geo_local = confRange, - .geo_local_ext = confRange_ext, - .geo_global = confRange, - .geo_global_ext = confRange_ext, - .geo_basis = confBasis, + .geometry_id = GKYL_GEOMETRY_MAPC2P, + .world = {0.0, 0.0}, + .mapc2p = mapc2p, // mapping of computational to physical space + .c2p_ctx = 0, + .bfield_func = bfield_func, // magnetic field magnitude + .bfield_ctx = 0, + .position_map = pmap, + .grid = confGrid, + .local = confRange, + .local_ext = confRange_ext, + .global = confRange, + .global_ext = confRange_ext, + .basis = confBasis, + .geo_grid = confGrid, + .geo_local = confRange, + .geo_local_ext = confRange_ext, + .geo_global = confRange, + .geo_global_ext = confRange_ext, + .geo_basis = confBasis }; struct gk_geometry *gk_geom = gkyl_gk_geometry_mapc2p_new(&geometry_input); // Initialize gyrokinetic variables - struct gkyl_array *flux_surf = mkarr1(use_gpu, 4*surf_basis.num_basis, phaseRange_ext.volume); + struct gkyl_array *flux_surf = mkarr1(use_gpu, 4 * surf_basis.num_basis, phaseRange_ext.volume); struct gkyl_array *phi = mkarr1(use_gpu, confBasis.num_basis, confRange_ext.volume); struct gkyl_array *apar = mkarr1(use_gpu, confBasis.num_basis, confRange_ext.volume); struct gkyl_array *apardot = mkarr1(use_gpu, confBasis.num_basis, confRange_ext.volume); - struct gkyl_dg_gyrokinetic_auxfields aux = { .flux_surf = flux_surf, - .phi = phi, .apar = apar, .apardot = apardot }; + struct gkyl_dg_gyrokinetic_auxfields aux = { + .flux_surf = flux_surf, .phi = phi, .apar = apar, .apardot = apardot + }; const bool is_zero_flux[GKYL_MAX_DIM] = {false}; // Initialize velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, phaseGrid, velGrid, - phaseRange, phaseRange_ext, velLocal, velLocal_ext, false); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = gkyl_velocity_map_new( + c2p_in, phaseGrid, velGrid, phaseRange, phaseRange_ext, velLocal, velLocal_ext, false + ); - struct gkyl_dg_updater_gyrokinetic* up; - up = gkyl_dg_updater_gyrokinetic_new(&phaseGrid, &confBasis, &basis, &confRange, &phaseRange, - is_zero_flux, 1.0, 1.0, GKYL_GK_COLLISIONLESS_ES, gk_geom, gvm, &aux, use_gpu); + struct gkyl_dg_updater_gyrokinetic *up; + up = gkyl_dg_updater_gyrokinetic_new( + &phaseGrid, &confBasis, &basis, &confRange, &phaseRange, is_zero_flux, 1.0, 1.0, + GKYL_GK_COLLISIONLESS_ES, gk_geom, gvm, &aux, use_gpu + ); // initialize arrays struct gkyl_array *fin, *rhs, *cflrate; struct gkyl_array *fin_h, *qmem_h, *rhs_h; - + fin = mkarr1(use_gpu, basis.num_basis, phaseRange_ext.volume); rhs = mkarr1(use_gpu, basis.num_basis, phaseRange_ext.volume); cflrate = mkarr1(use_gpu, 1, phaseRange_ext.volume); @@ -144,17 +147,17 @@ test_3x2v_p1(bool use_gpu) struct timespec tm = gkyl_wall_clock(); // run hyper_dg_advance int nrep = 1; - for(int n=0; n // Allocate array (filled with zeros). -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } @@ -40,30 +40,35 @@ struct test_ctx { double upper[GKYL_MAX_DIM]; // Grid upper limit in each direction. }; -static void calc_int_moms(int num_mom, struct gkyl_rect_grid *confGrid, struct gkyl_basis *confBasis, - struct gkyl_range *confLocal, bool use_gpu, struct gkyl_array *moms, double *int_moms) +static void calc_int_moms( + int num_mom, struct gkyl_rect_grid *confGrid, struct gkyl_basis *confBasis, + struct gkyl_range *confLocal, bool use_gpu, struct gkyl_array *moms, double *int_moms +) { // Compute the volume integral of the moments. - double *integrated_moms = use_gpu? gkyl_cu_malloc(num_mom*sizeof(double)) : gkyl_malloc(num_mom*sizeof(double)); + double *integrated_moms = use_gpu ? gkyl_cu_malloc(num_mom * sizeof(double)) : + gkyl_malloc(num_mom * sizeof(double)); - struct gkyl_array_integrate* integ_op = gkyl_array_integrate_new(confGrid, confBasis, - num_mom, GKYL_ARRAY_INTEGRATE_OP_NONE, use_gpu); + struct gkyl_array_integrate *integ_op = + gkyl_array_integrate_new(confGrid, confBasis, num_mom, GKYL_ARRAY_INTEGRATE_OP_NONE, use_gpu); - gkyl_array_integrate_advance(integ_op, moms, 1.0, moms, confLocal, confLocal, integrated_moms); + gkyl_array_integrate_advance(integ_op, moms, 1.0, moms, confLocal, confLocal, integrated_moms); - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(int_moms, integrated_moms, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(int_moms, integrated_moms, sizeof(double[num_mom])); + } - if (use_gpu) + if (use_gpu) { gkyl_cu_free(integrated_moms); - else + } else { gkyl_free(integrated_moms); + } gkyl_array_integrate_release(integ_op); } -void eval_fdonor_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_fdonor_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; @@ -74,18 +79,19 @@ void eval_fdonor_1x(double t, const double *xn, double* restrict fout, void *ctx double *upper = tctx->upper; double Lx[GKYL_MAX_CDIM]; - for (int d=0; dncomp, distf->size) - : gkyl_array_acquire(distf); - gkyl_proj_on_basis *proj_distf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_fdonor_1x, &proj_ctx); + struct gkyl_array *distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : + gkyl_array_acquire(distf); + gkyl_proj_on_basis *proj_distf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_fdonor_1x, &proj_ctx); gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); int num_mom = 1; // Calculate the integral of the field. double int_moms[num_mom]; - for (int i=0; incomp, distf_tar->size) - : gkyl_array_acquire(distf_tar); + struct gkyl_array *distf_tar_ho = use_gpu ? mkarr(false, distf_tar->ncomp, distf_tar->size) : + gkyl_array_acquire(distf_tar); // Create the interpolation operator and interpolate onto the target grid. - struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new(ndim, &basis, - &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); + struct gkyl_dg_interpolate *interp = + gkyl_dg_interpolate_new(ndim, &basis, &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); gkyl_dg_interpolate_advance(interp, distf, distf_tar); // Calculate the integrated moments of the target. double int_moms_tar[num_mom]; - for (int i=0; iupper; double Lx[GKYL_MAX_CDIM]; - for (int d=0; dncomp, distf->size) - : gkyl_array_acquire(distf); - gkyl_proj_on_basis *proj_distf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_fdonor_1x, &proj_ctx); + struct gkyl_array *distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : + gkyl_array_acquire(distf); + gkyl_proj_on_basis *proj_distf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_fdonor_1x, &proj_ctx); gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); int num_mom = 1; // Calculate the integral of the field. double int_moms[num_mom]; - for (int i=0; incomp, distf_tar->size) - : gkyl_array_acquire(distf_tar); + struct gkyl_array *distf_tar_ho = use_gpu ? mkarr(false, distf_tar->ncomp, distf_tar->size) : + gkyl_array_acquire(distf_tar); // Create the interpolation operator and interpolate onto the target grid. - struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new(ndim, &basis, - &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); + struct gkyl_dg_interpolate *interp = + gkyl_dg_interpolate_new(ndim, &basis, &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); gkyl_dg_interpolate_advance(interp, distf, distf_tar); // Calculate the integrated moments of the target. double int_moms_tar[num_mom]; - for (int i=0; iupper; double Lx[GKYL_MAX_CDIM]; - for (int d=0; dncomp, distf->size) - : gkyl_array_acquire(distf); - gkyl_proj_on_basis *proj_distf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_distf_1x1v_vlasov, &proj_ctx); + struct gkyl_array *distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : + gkyl_array_acquire(distf); + gkyl_proj_on_basis *proj_distf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_distf_1x1v_vlasov, &proj_ctx); gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); - int num_mom = 2+vdim; + int num_mom = 2 + vdim; // Calculate the moments. - struct gkyl_array *moms = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_ext.volume); - struct gkyl_array *moms_ho = use_gpu? mkarr(false, moms->ncomp, moms->size) - : gkyl_array_acquire(moms); + struct gkyl_array *moms = mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_ext.volume); + struct gkyl_array *moms_ho = use_gpu ? mkarr(false, moms->ncomp, moms->size) : + gkyl_array_acquire(moms); calc_moms_vlasov(&grid, &confBasis, &basis, &confLocal, &local, use_gpu, distf, moms); gkyl_array_copy(moms_ho, moms); // Calculate the integrated moments. double int_moms[num_mom]; - for (int i=0; incomp, distf_tar->size) - : gkyl_array_acquire(distf_tar); + struct gkyl_array *distf_tar_ho = use_gpu ? mkarr(false, distf_tar->ncomp, distf_tar->size) : + gkyl_array_acquire(distf_tar); // Create the interpolation operator and interpolate onto the target grid. - struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new(cdim, &basis, - &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); + struct gkyl_dg_interpolate *interp = + gkyl_dg_interpolate_new(cdim, &basis, &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); gkyl_dg_interpolate_advance(interp, distf, distf_tar); // Calculate the moments. - struct gkyl_array *moms_tar = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_tar_ext.volume); - struct gkyl_array *moms_tar_ho = use_gpu? mkarr(false, moms_tar->ncomp, moms_tar->size) - : gkyl_array_acquire(moms_tar); - calc_moms_vlasov(&grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, use_gpu, distf_tar, moms_tar); + struct gkyl_array *moms_tar = + mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_tar_ext.volume); + struct gkyl_array *moms_tar_ho = use_gpu ? mkarr(false, moms_tar->ncomp, moms_tar->size) : + gkyl_array_acquire(moms_tar); + calc_moms_vlasov( + &grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, use_gpu, distf_tar, moms_tar + ); gkyl_array_copy(moms_tar_ho, moms_tar); // Calculate the integrated moments of the target. double int_moms_tar[num_mom]; - for (int i=0; incomp; m++) { - TEST_CHECK( gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol) ); - TEST_MSG( "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m]); + for (int m = 2 * confBasis.num_basis; m < moms->ncomp; m++) { + TEST_CHECK(gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol)); + TEST_MSG( + "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m] + ); } } } - for (int i=0; iupper; double Lx[GKYL_MAX_CDIM]; - for (int d=0; dncomp, distf->size) - : gkyl_array_acquire(distf); - gkyl_proj_on_basis *proj_distf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_distf_1x2v_vlasov, &proj_ctx); + struct gkyl_array *distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : + gkyl_array_acquire(distf); + gkyl_proj_on_basis *proj_distf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_distf_1x2v_vlasov, &proj_ctx); gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); - int num_mom = 2+vdim; + int num_mom = 2 + vdim; // Calculate the moments. - struct gkyl_array *moms = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_ext.volume); - struct gkyl_array *moms_ho = use_gpu? mkarr(false, moms->ncomp, moms->size) - : gkyl_array_acquire(moms); + struct gkyl_array *moms = mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_ext.volume); + struct gkyl_array *moms_ho = use_gpu ? mkarr(false, moms->ncomp, moms->size) : + gkyl_array_acquire(moms); calc_moms_vlasov(&grid, &confBasis, &basis, &confLocal, &local, use_gpu, distf, moms); gkyl_array_copy(moms_ho, moms); // Calculate the integrated moments. double int_moms[num_mom]; - for (int i=0; incomp, distf_tar->size) - : gkyl_array_acquire(distf_tar); + struct gkyl_array *distf_tar_ho = use_gpu ? mkarr(false, distf_tar->ncomp, distf_tar->size) : + gkyl_array_acquire(distf_tar); // Create the interpolation operator and interpolate onto the target grid. - struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new(cdim, &basis, - &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); + struct gkyl_dg_interpolate *interp = + gkyl_dg_interpolate_new(cdim, &basis, &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); gkyl_dg_interpolate_advance(interp, distf, distf_tar); // Calculate the moments. - struct gkyl_array *moms_tar = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_tar_ext.volume); - struct gkyl_array *moms_tar_ho = use_gpu? mkarr(false, moms_tar->ncomp, moms_tar->size) - : gkyl_array_acquire(moms_tar); - calc_moms_vlasov(&grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, use_gpu, distf_tar, moms_tar); + struct gkyl_array *moms_tar = + mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_tar_ext.volume); + struct gkyl_array *moms_tar_ho = use_gpu ? mkarr(false, moms_tar->ncomp, moms_tar->size) : + gkyl_array_acquire(moms_tar); + calc_moms_vlasov( + &grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, use_gpu, distf_tar, moms_tar + ); gkyl_array_copy(moms_tar_ho, moms_tar); // Calculate the integrated moments of the target. double int_moms_tar[num_mom]; - for (int i=0; incomp; m++) { - TEST_CHECK( gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol) ); - TEST_MSG( "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m]); + for (int m = 2 * confBasis.num_basis; m < moms->ncomp; m++) { + TEST_CHECK(gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol)); + TEST_MSG( + "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m] + ); } } } - for (int i=0; iupper; double Lx[GKYL_MAX_CDIM]; - for (int d=0; dncomp, distf->size) - : gkyl_array_acquire(distf); - gkyl_proj_on_basis *proj_distf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_distf_1x1v_gk, &proj_ctx); + struct gkyl_array *distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : + gkyl_array_acquire(distf); + gkyl_proj_on_basis *proj_distf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_distf_1x1v_gk, &proj_ctx); gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); // Initialize geometry. - struct gk_geometry *gk_geom = init_gk_geo(poly_order, confGrid, confBasis, confLocal, confLocal_ext, &proj_ctx, use_gpu); + struct gk_geometry *gk_geom = + init_gk_geo(poly_order, confGrid, confBasis, confLocal, confLocal_ext, &proj_ctx, use_gpu); // Velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, grid, velGrid, - local, local_ext, velLocal, velLocal_ext, use_gpu); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, velGrid, local, local_ext, velLocal, velLocal_ext, use_gpu); int num_mom = 3; // Calculate the moments. - struct gkyl_array *moms = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_ext.volume); - struct gkyl_array *moms_ho = use_gpu? mkarr(false, moms->ncomp, moms->size) - : gkyl_array_acquire(moms); - calc_moms_gk(&grid, &confBasis, &basis, &confLocal, &local, mass, charge, gvm, gk_geom, use_gpu, distf, moms); + struct gkyl_array *moms = mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_ext.volume); + struct gkyl_array *moms_ho = use_gpu ? mkarr(false, moms->ncomp, moms->size) : + gkyl_array_acquire(moms); + calc_moms_gk( + &grid, &confBasis, &basis, &confLocal, &local, mass, charge, gvm, gk_geom, use_gpu, distf, moms + ); gkyl_array_copy(moms_ho, moms); // Calculate the integrated moments. double int_moms[num_mom]; - for (int i=0; incomp, distf_tar->size) - : gkyl_array_acquire(distf_tar); + struct gkyl_array *distf_tar_ho = use_gpu ? mkarr(false, distf_tar->ncomp, distf_tar->size) : + gkyl_array_acquire(distf_tar); // Create the interpolation operator and interpolate onto the target grid. - struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new(cdim, &basis, - &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); + struct gkyl_dg_interpolate *interp = + gkyl_dg_interpolate_new(cdim, &basis, &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); gkyl_dg_interpolate_advance(interp, distf, distf_tar); // Calculate the moments. - struct gkyl_array *moms_tar = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_tar_ext.volume); - struct gkyl_array *moms_tar_ho = use_gpu? mkarr(false, moms_tar->ncomp, moms_tar->size) - : gkyl_array_acquire(moms_tar); - calc_moms_gk(&grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, - mass, charge, gvm_tar, gk_geom_tar, use_gpu, distf_tar, moms_tar); + struct gkyl_array *moms_tar = + mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_tar_ext.volume); + struct gkyl_array *moms_tar_ho = use_gpu ? mkarr(false, moms_tar->ncomp, moms_tar->size) : + gkyl_array_acquire(moms_tar); + calc_moms_gk( + &grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, mass, charge, gvm_tar, gk_geom_tar, + use_gpu, distf_tar, moms_tar + ); gkyl_array_copy(moms_tar_ho, moms_tar); // Calculate the integrated moments of the target. double int_moms_tar[num_mom]; - for (int i=0; incomp; m++) { - TEST_CHECK( gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol) ); - TEST_MSG( "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m]); + for (int m = 2 * confBasis.num_basis; m < moms->ncomp; m++) { + TEST_CHECK(gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol)); + TEST_MSG( + "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m] + ); } } } - for (int i=0; iupper; double Lx[GKYL_MAX_CDIM]; - for (int d=0; dncomp, distf->size) - : gkyl_array_acquire(distf); - gkyl_proj_on_basis *proj_distf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_distf_1x2v_gk, &proj_ctx); + struct gkyl_array *distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : + gkyl_array_acquire(distf); + gkyl_proj_on_basis *proj_distf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_distf_1x2v_gk, &proj_ctx); gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); // Initialize geometry. - struct gk_geometry *gk_geom = init_gk_geo(poly_order, confGrid, confBasis, confLocal, confLocal_ext, &proj_ctx, use_gpu); + struct gk_geometry *gk_geom = + init_gk_geo(poly_order, confGrid, confBasis, confLocal, confLocal_ext, &proj_ctx, use_gpu); // Velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, grid, velGrid, - local, local_ext, velLocal, velLocal_ext, use_gpu); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, velGrid, local, local_ext, velLocal, velLocal_ext, use_gpu); int num_mom = 3; // Calculate the moments. - struct gkyl_array *moms = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_ext.volume); - struct gkyl_array *moms_ho = use_gpu? mkarr(false, moms->ncomp, moms->size) - : gkyl_array_acquire(moms); - calc_moms_gk(&grid, &confBasis, &basis, &confLocal, &local, mass, charge, gvm, gk_geom, use_gpu, distf, moms); + struct gkyl_array *moms = mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_ext.volume); + struct gkyl_array *moms_ho = use_gpu ? mkarr(false, moms->ncomp, moms->size) : + gkyl_array_acquire(moms); + calc_moms_gk( + &grid, &confBasis, &basis, &confLocal, &local, mass, charge, gvm, gk_geom, use_gpu, distf, moms + ); gkyl_array_copy(moms_ho, moms); // Calculate the integrated moments. double int_moms[num_mom]; - for (int i=0; incomp, distf_tar->size) - : gkyl_array_acquire(distf_tar); + struct gkyl_array *distf_tar_ho = use_gpu ? mkarr(false, distf_tar->ncomp, distf_tar->size) : + gkyl_array_acquire(distf_tar); // Create the interpolation operator and interpolate onto the target grid. - struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new(cdim, &basis, - &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); + struct gkyl_dg_interpolate *interp = + gkyl_dg_interpolate_new(cdim, &basis, &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); gkyl_dg_interpolate_advance(interp, distf, distf_tar); // Calculate the moments. - struct gkyl_array *moms_tar = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_tar_ext.volume); - struct gkyl_array *moms_tar_ho = use_gpu? mkarr(false, moms_tar->ncomp, moms_tar->size) - : gkyl_array_acquire(moms_tar); - calc_moms_gk(&grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, - mass, charge, gvm_tar, gk_geom_tar, use_gpu, distf_tar, moms_tar); + struct gkyl_array *moms_tar = + mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_tar_ext.volume); + struct gkyl_array *moms_tar_ho = use_gpu ? mkarr(false, moms_tar->ncomp, moms_tar->size) : + gkyl_array_acquire(moms_tar); + calc_moms_gk( + &grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, mass, charge, gvm_tar, gk_geom_tar, + use_gpu, distf_tar, moms_tar + ); gkyl_array_copy(moms_tar_ho, moms_tar); // Calculate the integrated moments of the target. double int_moms_tar[num_mom]; - for (int i=0; incomp; m++) { - TEST_CHECK( gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol) ); - TEST_MSG( "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m]); + for (int m = 2 * confBasis.num_basis; m < moms->ncomp; m++) { + TEST_CHECK(gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol)); + TEST_MSG( + "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m] + ); } } } - for (int i=0; iupper; double Lx[GKYL_MAX_CDIM]; - for (int d=0; dncomp, distf->size) - : gkyl_array_acquire(distf); - gkyl_proj_on_basis *proj_distf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_distf_2x2v_gk, &proj_ctx); + struct gkyl_array *distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : + gkyl_array_acquire(distf); + gkyl_proj_on_basis *proj_distf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_distf_2x2v_gk, &proj_ctx); gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); // Initialize geometry. - struct gk_geometry *gk_geom = init_gk_geo(poly_order, confGrid, confBasis, confLocal, confLocal_ext, &proj_ctx, use_gpu); + struct gk_geometry *gk_geom = + init_gk_geo(poly_order, confGrid, confBasis, confLocal, confLocal_ext, &proj_ctx, use_gpu); // Velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, grid, velGrid, - local, local_ext, velLocal, velLocal_ext, use_gpu); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, velGrid, local, local_ext, velLocal, velLocal_ext, use_gpu); int num_mom = 3; // Calculate the moments. - struct gkyl_array *moms = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_ext.volume); - struct gkyl_array *moms_ho = use_gpu? mkarr(false, moms->ncomp, moms->size) - : gkyl_array_acquire(moms); - calc_moms_gk(&grid, &confBasis, &basis, &confLocal, &local, mass, charge, gvm, gk_geom, use_gpu, distf, moms); + struct gkyl_array *moms = mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_ext.volume); + struct gkyl_array *moms_ho = use_gpu ? mkarr(false, moms->ncomp, moms->size) : + gkyl_array_acquire(moms); + calc_moms_gk( + &grid, &confBasis, &basis, &confLocal, &local, mass, charge, gvm, gk_geom, use_gpu, distf, moms + ); gkyl_array_copy(moms_ho, moms); // Calculate the integrated moments. double int_moms[num_mom]; - for (int i=0; incomp, distf_tar->size) - : gkyl_array_acquire(distf_tar); + struct gkyl_array *distf_tar_ho = use_gpu ? mkarr(false, distf_tar->ncomp, distf_tar->size) : + gkyl_array_acquire(distf_tar); // Create the interpolation operator and interpolate onto the target grid. - struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new(cdim, &basis, - &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); + struct gkyl_dg_interpolate *interp = + gkyl_dg_interpolate_new(cdim, &basis, &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); gkyl_dg_interpolate_advance(interp, distf, distf_tar); // Calculate the moments. - struct gkyl_array *moms_tar = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_tar_ext.volume); - struct gkyl_array *moms_tar_ho = use_gpu? mkarr(false, moms_tar->ncomp, moms_tar->size) - : gkyl_array_acquire(moms_tar); - calc_moms_gk(&grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, - mass, charge, gvm_tar, gk_geom_tar, use_gpu, distf_tar, moms_tar); + struct gkyl_array *moms_tar = + mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_tar_ext.volume); + struct gkyl_array *moms_tar_ho = use_gpu ? mkarr(false, moms_tar->ncomp, moms_tar->size) : + gkyl_array_acquire(moms_tar); + calc_moms_gk( + &grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, mass, charge, gvm_tar, gk_geom_tar, + use_gpu, distf_tar, moms_tar + ); gkyl_array_copy(moms_tar_ho, moms_tar); // Calculate the integrated moments of the target. double int_moms_tar[num_mom]; - for (int i=0; incomp; m++) { - TEST_CHECK( gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol) ); - TEST_MSG( "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m]); + for (int m = 2 * confBasis.num_basis; m < moms->ncomp; m++) { + TEST_CHECK(gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol)); + TEST_MSG( + "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m] + ); } } } - for (int i=0; iupper; double Lx[GKYL_MAX_CDIM]; - for (int d=0; dncomp, distf->size) - : gkyl_array_acquire(distf); - gkyl_proj_on_basis *proj_distf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_distf_3x2v_gk, &proj_ctx); + struct gkyl_array *distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : + gkyl_array_acquire(distf); + gkyl_proj_on_basis *proj_distf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_distf_3x2v_gk, &proj_ctx); gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); // Initialize geometry. - struct gk_geometry *gk_geom = init_gk_geo(poly_order, confGrid, confBasis, confLocal, confLocal_ext, &proj_ctx, use_gpu); + struct gk_geometry *gk_geom = + init_gk_geo(poly_order, confGrid, confBasis, confLocal, confLocal_ext, &proj_ctx, use_gpu); // Velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, grid, velGrid, - local, local_ext, velLocal, velLocal_ext, use_gpu); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, velGrid, local, local_ext, velLocal, velLocal_ext, use_gpu); int num_mom = 3; // Calculate the moments. - struct gkyl_array *moms = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_ext.volume); - struct gkyl_array *moms_ho = use_gpu? mkarr(false, moms->ncomp, moms->size) - : gkyl_array_acquire(moms); - calc_moms_gk(&grid, &confBasis, &basis, &confLocal, &local, mass, charge, gvm, gk_geom, use_gpu, distf, moms); + struct gkyl_array *moms = mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_ext.volume); + struct gkyl_array *moms_ho = use_gpu ? mkarr(false, moms->ncomp, moms->size) : + gkyl_array_acquire(moms); + calc_moms_gk( + &grid, &confBasis, &basis, &confLocal, &local, mass, charge, gvm, gk_geom, use_gpu, distf, moms + ); gkyl_array_copy(moms_ho, moms); // Calculate the integrated moments. double int_moms[num_mom]; - for (int i=0; incomp, distf_tar->size) - : gkyl_array_acquire(distf_tar); + struct gkyl_array *distf_tar_ho = use_gpu ? mkarr(false, distf_tar->ncomp, distf_tar->size) : + gkyl_array_acquire(distf_tar); // Create the interpolation operator and interpolate onto the target grid. - struct gkyl_dg_interpolate *interp = gkyl_dg_interpolate_new(cdim, &basis, - &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); + struct gkyl_dg_interpolate *interp = + gkyl_dg_interpolate_new(cdim, &basis, &grid, &grid_tar, &local, &local_tar, ghost, use_gpu); gkyl_dg_interpolate_advance(interp, distf, distf_tar); // Calculate the moments. - struct gkyl_array *moms_tar = mkarr(use_gpu, num_mom*confBasis.num_basis, confLocal_tar_ext.volume); - struct gkyl_array *moms_tar_ho = use_gpu? mkarr(false, moms_tar->ncomp, moms_tar->size) - : gkyl_array_acquire(moms_tar); - calc_moms_gk(&grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, - mass, charge, gvm_tar, gk_geom_tar, use_gpu, distf_tar, moms_tar); + struct gkyl_array *moms_tar = + mkarr(use_gpu, num_mom * confBasis.num_basis, confLocal_tar_ext.volume); + struct gkyl_array *moms_tar_ho = use_gpu ? mkarr(false, moms_tar->ncomp, moms_tar->size) : + gkyl_array_acquire(moms_tar); + calc_moms_gk( + &grid_tar, &confBasis, &basis, &confLocal_tar, &local_tar, mass, charge, gvm_tar, gk_geom_tar, + use_gpu, distf_tar, moms_tar + ); gkyl_array_copy(moms_tar_ho, moms_tar); // Calculate the integrated moments of the target. double int_moms_tar[num_mom]; - for (int i=0; incomp; m++) { - TEST_CHECK( gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol) ); - TEST_MSG( "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m]); + for (int m = 2 * confBasis.num_basis; m < moms->ncomp; m++) { + TEST_CHECK(gkyl_compare(moms_c[m], moms_tar_c[m], m2_tol)); + TEST_MSG( + "idx=%d | m=%d | Got: %.13e | Expected: %.13e\n", iter.idx[0], m, moms_tar_c[m], moms_c[m] + ); } } } - for (int i=0; i #include -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } -void -mapc2p_1x(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p_1x(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; + xp[0] = xc[0]; } -void -bfield_func_1x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func_1x(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { - double x = xc[0]; + double x = xc[0]; fout[0] = 0.0; fout[1] = 0.0; fout[2] = 1.0; } -void -mapc2p_2x(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p_2x(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; + xp[0] = xc[0]; + xp[1] = xc[1]; } -void -bfield_func_2x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func_2x(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1]; fout[0] = 0.0; @@ -66,79 +63,76 @@ bfield_func_2x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx fout[2] = 1.0; } -void -mapc2p_3x(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p_3x(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; xp[2] = xc[2]; + xp[0] = xc[0]; + xp[1] = xc[1]; + xp[2] = xc[2]; } -void -bfield_func_3x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func_3x(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; fout[1] = 0.0; fout[2] = 1.0; } -void -eval_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double *arr = ctx; double ne = arr[1]; - fout[0] = ne*1.1; + fout[0] = ne * 1.1; } -void -eval_cdensity(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_cdensity(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 1e19; } -void -eval_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void -eval_vthsq(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_vthsq(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - double *arr=ctx; + double *arr = ctx; double te = arr[0]; - fout[0] = te*GKYL_ELEMENTARY_CHARGE/GKYL_ELECTRON_MASS; + fout[0] = te * GKYL_ELEMENTARY_CHARGE / GKYL_ELECTRON_MASS; } -void -test_1x(int poly_order, bool use_gpu, double te, int atomic_z, - int charge_state, int num_ne[1], int ne_interval) +void test_1x( + int poly_order, bool use_gpu, double te, int atomic_z, int charge_state, int num_ne[1], + int ne_interval +) { double mass = GKYL_ELECTRON_MASS; - double charge = -1.0*GKYL_ELEMENTARY_CHARGE; + double charge = -1.0 * GKYL_ELEMENTARY_CHARGE; double vtsq_min = 0.0; - double vth = sqrt(te*GKYL_ELEMENTARY_CHARGE/GKYL_ELECTRON_MASS); + double vth = sqrt(te * GKYL_ELEMENTARY_CHARGE / GKYL_ELECTRON_MASS); // Phase space and Configuration space extents and resolution - double lower[] = {-1.0, -4*vth, 0.0}; - double upper[] = {1.0, 4*vth, 9*vth*vth*GKYL_ELECTRON_MASS}; + double lower[] = {-1.0, -4 * vth, 0.0}; + double upper[] = {1.0, 4 * vth, 9 * vth * vth * GKYL_ELECTRON_MASS}; int cells[] = {2, 256, 128}; int vdim = 2; - int ndim = sizeof(cells)/sizeof(cells[0]); + int ndim = sizeof(cells) / sizeof(cells[0]); int cdim = ndim - vdim; double confLower[cdim], confUpper[cdim]; int confCells[cdim]; - for (int d=0; d 1) { gkyl_cart_modal_serendip(&basis, ndim, poly_order); - gkyl_cart_modal_serendip(&surf_mu_basis, ndim-1, poly_order); + gkyl_cart_modal_serendip(&surf_mu_basis, ndim - 1, poly_order); } else if (poly_order == 1) { /* Force hybrid basis (p=2 in vpar). */ gkyl_cart_modal_gkhybrid(&basis, cdim, vdim); @@ -161,18 +155,18 @@ test_1x(int poly_order, bool use_gpu, double te, int atomic_z, gkyl_cart_modal_gkhybrid(&surf_mu_basis, cdim, poly_order); } // constant vpar surface - gkyl_cart_modal_serendip(&surf_vpar_basis, ndim-1, poly_order); + gkyl_cart_modal_serendip(&surf_vpar_basis, ndim - 1, poly_order); gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); - int confGhost[] = { 1 }; + int confGhost[] = {1}; struct gkyl_range confLocal, confLocal_ext; // local, local-ext conf-space ranges gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); - int ghost[] = { confGhost[0], 0 , 0}; + int ghost[] = {confGhost[0], 0, 0}; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); - int vGhost[] = {0,0}; + int vGhost[] = {0, 0}; struct gkyl_range vLocal, vLocal_ext; gkyl_create_grid_ranges(&vGrid, vGhost, &vLocal_ext, &vLocal); @@ -185,40 +179,42 @@ test_1x(int poly_order, bool use_gpu, double te, int atomic_z, .mapc2p = mapc2p_3x, // mapping of computational to physical space .c2p_ctx = 0, .bfield_func = bfield_func_3x, // magnetic field magnitude - .bfield_ctx = 0 , + .bfield_ctx = 0, .position_map = pmap, .grid = confGrid, .local = confLocal, .local_ext = confLocal_ext, .global = confLocal, .global_ext = confLocal_ext, - .basis = confBasis, + .basis = confBasis }; int geo_ghost[3] = {1}; geometry_input.geo_grid = gkyl_gk_geometry_augment_grid(confGrid, geometry_input); gkyl_cart_modal_serendip(&geometry_input.geo_basis, 3, poly_order); - gkyl_create_grid_ranges(&geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global); + gkyl_create_grid_ranges( + &geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global + ); memcpy(&geometry_input.geo_local, &geometry_input.geo_global, sizeof(struct gkyl_range)); memcpy(&geometry_input.geo_local_ext, &geometry_input.geo_global_ext, sizeof(struct gkyl_range)); - struct gk_geometry* gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); + struct gk_geometry *gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); // deflate geometry struct gk_geometry *gk_geom = gkyl_gk_geometry_deflate(gk_geom_3d, &geometry_input); gkyl_gk_geometry_release(gk_geom_3d); // If we are on the gpu, copy from host if (use_gpu) { - struct gk_geometry* gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); + struct gk_geometry *gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); gkyl_gk_geometry_release(gk_geom); gk_geom = gkyl_gk_geometry_acquire(gk_geom_dev); gkyl_gk_geometry_release(gk_geom_dev); } // Initialize velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, grid, vGrid, - local, local_ext, vLocal, vLocal_ext, use_gpu); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, vGrid, local, local_ext, vLocal, vLocal_ext, use_gpu); // allocate drag coefficients in vparallel and mu for each collision // vnu = v_par*nu(v) @@ -229,49 +225,59 @@ test_1x(int poly_order, bool use_gpu, double te, int atomic_z, int num_ne_per_coll[num_collisions]; num_ne_per_coll[0] = num_ne[0]; struct all_radiation_states *rad_data = gkyl_radiation_read_rad_fit_params(); - int stat = gkyl_radiation_read_get_num_densities(*rad_data, atomic_z, charge_state, - 1, 1e30, num_ne_per_coll); + int stat = gkyl_radiation_read_get_num_densities( + *rad_data, atomic_z, charge_state, 1, 1e30, num_ne_per_coll + ); struct gkyl_gk_rad_drag *vnu, *vsqnu, *vnu_surf, *vsqnu_surf; - vnu = gkyl_dg_calc_gk_rad_vars_drag_new(num_collisions, - num_ne_per_coll, basis.num_basis, local_ext.volume, use_gpu); - vsqnu = gkyl_dg_calc_gk_rad_vars_drag_new(num_collisions, - num_ne_per_coll, basis.num_basis, local_ext.volume, use_gpu); - vnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new(num_collisions, - num_ne_per_coll, surf_vpar_basis.num_basis, local_ext.volume, use_gpu); - vsqnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new(num_collisions, - num_ne_per_coll, surf_mu_basis.num_basis, local_ext.volume, use_gpu); + vnu = gkyl_dg_calc_gk_rad_vars_drag_new( + num_collisions, num_ne_per_coll, basis.num_basis, local_ext.volume, use_gpu + ); + vsqnu = gkyl_dg_calc_gk_rad_vars_drag_new( + num_collisions, num_ne_per_coll, basis.num_basis, local_ext.volume, use_gpu + ); + vnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new( + num_collisions, num_ne_per_coll, surf_vpar_basis.num_basis, local_ext.volume, use_gpu + ); + vsqnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new( + num_collisions, num_ne_per_coll, surf_mu_basis.num_basis, local_ext.volume, use_gpu + ); double a[GKYL_MAX_RAD_DENSITIES], alpha[GKYL_MAX_RAD_DENSITIES], beta[GKYL_MAX_RAD_DENSITIES], gamma[GKYL_MAX_RAD_DENSITIES], v0[GKYL_MAX_RAD_DENSITIES], n_elc_d[GKYL_MAX_RAD_DENSITIES]; - int status = gkyl_radiation_read_get_fit_params(*rad_data, atomic_z, charge_state, - a, alpha, beta, gamma, v0, num_ne, n_elc_d, 1e19, 1, 1e30); + int status = gkyl_radiation_read_get_fit_params( + *rad_data, atomic_z, charge_state, a, alpha, beta, gamma, v0, num_ne, n_elc_d, 1e19, 1, 1e30 + ); assert(num_ne[0] == num_ne_per_coll[0]); if (status == 1) { - printf("No radiation fits exist for z=%d, charge state=%d\n",atomic_z, charge_state); - TEST_CHECK( status==0 ); + printf("No radiation fits exist for z=%d, charge state=%d\n", atomic_z, charge_state); + TEST_CHECK(status == 0); } double ctx[2], Lz[1]; ne_interval = fmin(ne_interval, num_ne[0]); struct gkyl_array *n_elc = mkarr(use_gpu, 1, num_ne[0]); struct gkyl_array *n_elc_ho = mkarr(false, 1, num_ne[0]); - memcpy(n_elc_ho->data, n_elc_d, num_ne[0]*sizeof(double)); + memcpy(n_elc_ho->data, n_elc_d, num_ne[0] * sizeof(double)); gkyl_array_copy(n_elc, n_elc_ho); gkyl_array_release(n_elc_ho); - + ctx[0] = te; - ctx[1] = n_elc_d[ne_interval-1]; + ctx[1] = n_elc_d[ne_interval - 1]; - gkyl_radiation_read_get_fit_lz(*rad_data, atomic_z, charge_state, log10(n_elc_d[ne_interval-1]), ctx, Lz); + gkyl_radiation_read_get_fit_lz( + *rad_data, atomic_z, charge_state, log10(n_elc_d[ne_interval - 1]), ctx, Lz + ); gkyl_radiation_read_release_fit_params(rad_data); - - struct gkyl_dg_calc_gk_rad_vars *calc_gk_rad_vars = gkyl_dg_calc_gk_rad_vars_new(&grid, - &confBasis, &basis, charge, mass, gk_geom, gvm, use_gpu); - gkyl_dg_calc_gk_rad_vars_nu_advance(calc_gk_rad_vars, &confLocal, &local, - a[ne_interval-1], alpha[ne_interval-1],beta[ne_interval-1], gamma[ne_interval-1], v0[ne_interval-1], - vnu_surf[0].data[ne_interval-1].arr, vnu[0].data[ne_interval-1].arr, - vsqnu_surf[0].data[ne_interval-1].arr, vsqnu[0].data[ne_interval-1].arr); + struct gkyl_dg_calc_gk_rad_vars *calc_gk_rad_vars = + gkyl_dg_calc_gk_rad_vars_new(&grid, &confBasis, &basis, charge, mass, gk_geom, gvm, use_gpu); + + gkyl_dg_calc_gk_rad_vars_nu_advance( + calc_gk_rad_vars, &confLocal, &local, a[ne_interval - 1], alpha[ne_interval - 1], + beta[ne_interval - 1], gamma[ne_interval - 1], v0[ne_interval - 1], + vnu_surf[0].data[ne_interval - 1].arr, vnu[0].data[ne_interval - 1].arr, + vsqnu_surf[0].data[ne_interval - 1].arr, vsqnu[0].data[ne_interval - 1].arr + ); struct gkyl_array *nvnu, *nvsqnu, *nvnu_surf, *nvsqnu_surf; nvnu = mkarr(use_gpu, basis.num_basis, local_ext.volume); @@ -281,26 +287,26 @@ test_1x(int poly_order, bool use_gpu, double te, int atomic_z, // Project n, udrift, and vt^2 based on input functions struct gkyl_array *m0_ho = mkarr(false, confBasis.num_basis, confLocal_ext.volume); - struct gkyl_array *udrift_ho = mkarr(false, vdim*confBasis.num_basis, confLocal_ext.volume); + struct gkyl_array *udrift_ho = mkarr(false, vdim * confBasis.num_basis, confLocal_ext.volume); struct gkyl_array *vtsq_ho = mkarr(false, confBasis.num_basis, confLocal_ext.volume); struct gkyl_array *vtsq_imp = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, 1, eval_density, ctx); - - gkyl_proj_on_basis *proj_udrift = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, vdim, eval_upar, 0); - - gkyl_proj_on_basis *proj_vtsq = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, 1, eval_vthsq, ctx); - gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0_ho); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_density, ctx); + + gkyl_proj_on_basis *proj_udrift = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_upar, 0); + + gkyl_proj_on_basis *proj_vtsq = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_vthsq, ctx); + gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0_ho); gkyl_proj_on_basis_advance(proj_udrift, 0.0, &confLocal, udrift_ho); gkyl_proj_on_basis_advance(proj_vtsq, 0.0, &confLocal, vtsq_ho); gkyl_array_copy(vtsq_imp, vtsq_ho); // Projection routine expects the primitive moments as a single array. - struct gkyl_array *prim_moms_ho = mkarr(false, 3*confBasis.num_basis, confLocal_ext.volume); - gkyl_array_set_offset(prim_moms_ho, 1.0, m0_ho, 0*confBasis.num_basis); - gkyl_array_set_offset(prim_moms_ho, 1.0, udrift_ho, 1*confBasis.num_basis); - gkyl_array_set_offset(prim_moms_ho, 1.0, vtsq_ho, 2*confBasis.num_basis); + struct gkyl_array *prim_moms_ho = mkarr(false, 3 * confBasis.num_basis, confLocal_ext.volume); + gkyl_array_set_offset(prim_moms_ho, 1.0, m0_ho, 0 * confBasis.num_basis); + gkyl_array_set_offset(prim_moms_ho, 1.0, udrift_ho, 1 * confBasis.num_basis); + gkyl_array_set_offset(prim_moms_ho, 1.0, vtsq_ho, 2 * confBasis.num_basis); // Create distribution function array struct gkyl_array *f = mkarr(use_gpu, basis.num_basis, local_ext.volume); @@ -310,46 +316,48 @@ test_1x(int poly_order, bool use_gpu, double te, int atomic_z, .phase_grid = &grid, .conf_basis = &confBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, - .vel_range = &vLocal, + .vel_range = &vLocal, .gk_geom = gk_geom, .vel_map = gvm, .mass = mass, - .bimaxwellian = false, - .use_gpu = use_gpu, + .bimaxwellian = false, + .use_gpu = use_gpu }; - struct gkyl_gk_maxwellian_proj_on_basis *proj_max = gkyl_gk_maxwellian_proj_on_basis_inew( &inp_proj ); + struct gkyl_gk_maxwellian_proj_on_basis *proj_max = + gkyl_gk_maxwellian_proj_on_basis_inew(&inp_proj); // If on GPUs, need to copy n, udrift, and vt^2 onto device - struct gkyl_array *prim_moms, *m0, *vtsq; + struct gkyl_array *prim_moms, *m0, *vtsq; if (use_gpu) { - prim_moms = mkarr(use_gpu, 3*confBasis.num_basis, confLocal_ext.volume); + prim_moms = mkarr(use_gpu, 3 * confBasis.num_basis, confLocal_ext.volume); m0 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); vtsq = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); - + gkyl_array_copy(prim_moms, prim_moms_ho); gkyl_array_copy(m0, m0_ho); gkyl_array_copy(vtsq, vtsq_ho); - gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, - &local, &confLocal, prim_moms, false, f); - } - else { + gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, &local, &confLocal, prim_moms, false, f); + } else { vtsq = vtsq_ho; m0 = m0_ho; - gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, - &local, &confLocal, prim_moms_ho, false, f); + gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, &local, &confLocal, prim_moms_ho, false, f); } struct gkyl_array *vtsq_min_normalized = mkarr(use_gpu, 1, num_ne[0]); gkyl_array_clear(vtsq_min_normalized, vtsq_min); - // initialize solver + // initialize solver struct gkyl_dg_updater_collisions *slvr; - struct gkyl_dg_rad_gyrokinetic_auxfields drag_inp = { .nvnu_surf = nvnu_surf, .nvnu = nvnu, .nvsqnu_surf = nvsqnu_surf, .nvsqnu = nvsqnu}; - slvr = gkyl_dg_updater_rad_gyrokinetic_new(&grid, &confBasis, &basis, &local, &confLocal, gvm, &drag_inp, use_gpu); + struct gkyl_dg_rad_gyrokinetic_auxfields drag_inp = { + .nvnu_surf = nvnu_surf, .nvnu = nvnu, .nvsqnu_surf = nvsqnu_surf, .nvsqnu = nvsqnu + }; + slvr = gkyl_dg_updater_rad_gyrokinetic_new( + &grid, &confBasis, &basis, &local, &confLocal, gvm, &drag_inp, use_gpu + ); struct gkyl_array *cflrate, *rhs, *fmax; cflrate = mkarr(use_gpu, 1, local_ext.volume); @@ -364,15 +372,18 @@ test_1x(int poly_order, bool use_gpu, double te, int atomic_z, gkyl_array_clear(nvsqnu, 0.0); // Assumed electron and ion density are the same and uniform - gkyl_dg_calc_gk_rad_vars_nI_nu_advance(calc_gk_rad_vars, - &confLocal, &local, &vnu_surf[0], &vnu[0], &vsqnu_surf[0], &vsqnu[0], - n_elc, m0, m0, nvnu_surf, nvnu, nvsqnu_surf, nvsqnu, vtsq_min_normalized, vtsq); + gkyl_dg_calc_gk_rad_vars_nI_nu_advance( + calc_gk_rad_vars, &confLocal, &local, &vnu_surf[0], &vnu[0], &vsqnu_surf[0], &vsqnu[0], n_elc, + m0, m0, nvnu_surf, nvnu, nvsqnu_surf, nvsqnu, vtsq_min_normalized, vtsq + ); gkyl_dg_updater_rad_gyrokinetic_advance(slvr, &local, f, cflrate, rhs); // Take 2nd moment of rhs to find energy loss on host - struct gkyl_dg_updater_moment *m2_calc = gkyl_dg_updater_moment_gyrokinetic_new(&grid, &confBasis, &basis, - &confLocal, GKYL_ELECTRON_MASS, -GKYL_ELEMENTARY_CHARGE, gvm, gk_geom, NULL, GKYL_F_MOMENT_M2, false, use_gpu); + struct gkyl_dg_updater_moment *m2_calc = gkyl_dg_updater_moment_gyrokinetic_new( + &grid, &confBasis, &basis, &confLocal, GKYL_ELECTRON_MASS, -GKYL_ELEMENTARY_CHARGE, gvm, + gk_geom, NULL, GKYL_F_MOMENT_M2, false, use_gpu + ); struct gkyl_array *m2_final = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); gkyl_dg_updater_moment_gyrokinetic_advance(m2_calc, &local, &confLocal, rhs, m2_final); @@ -384,20 +395,20 @@ test_1x(int poly_order, bool use_gpu, double te, int atomic_z, gkyl_array_copy(m2_final_host, m2_final); } - double *m00 = gkyl_array_fetch(m0_ho, 0+ghost[0]); - double *m20 = gkyl_array_fetch(m2_final_host, 0+ghost[0]); - - double cell_avg_m2 = m20[0]/pow(sqrt(2.0),cdim); - double cell_avg_m0 = m00[0]/pow(sqrt(2.0),cdim); + double *m00 = gkyl_array_fetch(m0_ho, 0 + ghost[0]); + double *m20 = gkyl_array_fetch(m2_final_host, 0 + ghost[0]); + + double cell_avg_m2 = m20[0] / pow(sqrt(2.0), cdim); + double cell_avg_m0 = m00[0] / pow(sqrt(2.0), cdim); // two factors of density, one for the electrons and one for the ions - double cell_avg0 = 1.0/2.0*GKYL_ELECTRON_MASS*cell_avg_m2/(cell_avg_m0*cell_avg_m0); + double cell_avg0 = 1.0 / 2.0 * GKYL_ELECTRON_MASS * cell_avg_m2 / (cell_avg_m0 * cell_avg_m0); double correct = Lz[0]; // Fit error typically >10%, so %1 should be sufficient here - TEST_CHECK( gkyl_compare( -correct*1e30, cell_avg0*1e30, 1e-2)); - TEST_CHECK( cell_avg0<0 ); - + TEST_CHECK(gkyl_compare(-correct * 1e30, cell_avg0 * 1e30, 1e-2)); + TEST_CHECK(cell_avg0 < 0); + // Release memory gkyl_dg_calc_gk_rad_vars_drag_release(vnu, num_collisions, use_gpu); gkyl_dg_calc_gk_rad_vars_drag_release(vnu_surf, num_collisions, use_gpu); @@ -412,7 +423,7 @@ test_1x(int poly_order, bool use_gpu, double te, int atomic_z, gkyl_dg_calc_gk_rad_vars_release(calc_gk_rad_vars); gkyl_array_release(m0_ho); - gkyl_array_release(udrift_ho); + gkyl_array_release(udrift_ho); gkyl_array_release(vtsq_ho); gkyl_array_release(vtsq_imp); gkyl_array_release(vtsq_min_normalized); @@ -432,8 +443,8 @@ test_1x(int poly_order, bool use_gpu, double te, int atomic_z, if (use_gpu) { gkyl_array_release(m0); - gkyl_array_release(prim_moms); - gkyl_array_release(m2_final_host); + gkyl_array_release(prim_moms); + gkyl_array_release(m2_final_host); } gkyl_velocity_map_release(gvm); @@ -441,36 +452,35 @@ test_1x(int poly_order, bool use_gpu, double te, int atomic_z, gkyl_gk_geometry_release(gk_geom); } -void -test_2x(int poly_order, bool use_gpu, double te) +void test_2x(int poly_order, bool use_gpu, double te) { double mass = GKYL_ELECTRON_MASS; - double charge = -1.0*GKYL_ELEMENTARY_CHARGE; + double charge = -1.0 * GKYL_ELEMENTARY_CHARGE; - double vth = sqrt(te*GKYL_ELEMENTARY_CHARGE/GKYL_ELECTRON_MASS); + double vth = sqrt(te * GKYL_ELEMENTARY_CHARGE / GKYL_ELECTRON_MASS); double vtsq_min = 0.0; // Phase space and Configuration space extents and resolution - double lower[] = {-2.0, -1.0, -4*vth, 0.0}; - double upper[] = {2.0, 1.0, 4*vth, 9*vth*vth*GKYL_ELECTRON_MASS}; + double lower[] = {-2.0, -1.0, -4 * vth, 0.0}; + double upper[] = {2.0, 1.0, 4 * vth, 9 * vth * vth * GKYL_ELECTRON_MASS}; int cells[] = {2, 2, 256, 128}; int vdim = 2; - int ndim = sizeof(cells)/sizeof(cells[0]); + int ndim = sizeof(cells) / sizeof(cells[0]); int cdim = ndim - vdim; double confLower[cdim], confUpper[cdim]; int confCells[cdim]; - for (int d=0; d 1) { gkyl_cart_modal_serendip(&basis, ndim, poly_order); - gkyl_cart_modal_serendip(&surf_mu_basis, ndim-1, poly_order); + gkyl_cart_modal_serendip(&surf_mu_basis, ndim - 1, poly_order); } else if (poly_order == 1) { /* Force hybrid basis (p=2 in vpar). */ gkyl_cart_modal_gkhybrid(&basis, cdim, vdim); @@ -493,14 +503,14 @@ test_2x(int poly_order, bool use_gpu, double te) gkyl_cart_modal_gkhybrid(&surf_mu_basis, cdim, poly_order); } // constant vpar surface - gkyl_cart_modal_serendip(&surf_vpar_basis, ndim-1, poly_order); + gkyl_cart_modal_serendip(&surf_vpar_basis, ndim - 1, poly_order); gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); - int confGhost[] = { 1, 1 }; + int confGhost[] = {1, 1}; struct gkyl_range confLocal, confLocal_ext; // local, local-ext conf-space ranges gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); - int ghost[] = { confGhost[0], confGhost[1], 0 , 0}; + int ghost[] = {confGhost[0], confGhost[1], 0, 0}; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); @@ -517,40 +527,42 @@ test_2x(int poly_order, bool use_gpu, double te) .mapc2p = mapc2p_3x, // mapping of computational to physical space .c2p_ctx = 0, .bfield_func = bfield_func_3x, // magnetic field magnitude - .bfield_ctx = 0 , + .bfield_ctx = 0, .position_map = pmap, .grid = confGrid, .local = confLocal, .local_ext = confLocal_ext, .global = confLocal, .global_ext = confLocal_ext, - .basis = confBasis, + .basis = confBasis }; int geo_ghost[3] = {1}; geometry_input.geo_grid = gkyl_gk_geometry_augment_grid(confGrid, geometry_input); gkyl_cart_modal_serendip(&geometry_input.geo_basis, 3, poly_order); - gkyl_create_grid_ranges(&geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global); + gkyl_create_grid_ranges( + &geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global + ); memcpy(&geometry_input.geo_local, &geometry_input.geo_global, sizeof(struct gkyl_range)); memcpy(&geometry_input.geo_local_ext, &geometry_input.geo_global_ext, sizeof(struct gkyl_range)); - struct gk_geometry* gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); + struct gk_geometry *gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); // deflate geometry struct gk_geometry *gk_geom = gkyl_gk_geometry_deflate(gk_geom_3d, &geometry_input); gkyl_gk_geometry_release(gk_geom_3d); // If we are on the gpu, copy from host if (use_gpu) { - struct gk_geometry* gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); + struct gk_geometry *gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); gkyl_gk_geometry_release(gk_geom); gk_geom = gkyl_gk_geometry_acquire(gk_geom_dev); gkyl_gk_geometry_release(gk_geom_dev); } // Initialize velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, grid, vGrid, - local, local_ext, vLocal, vLocal_ext, use_gpu); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, vGrid, local, local_ext, vLocal, vLocal_ext, use_gpu); // allocate drag coefficients in vparallel and mu for each collision // vnu = v_par*nu(v) @@ -562,50 +574,57 @@ test_2x(int poly_order, bool use_gpu, double te) int atomic_z = 3; int charge_state = 0; struct all_radiation_states *rad_data = gkyl_radiation_read_rad_fit_params(); - int stat = gkyl_radiation_read_get_num_densities(*rad_data, atomic_z, charge_state, - 1, 1e30, num_ne_per_coll); + int stat = gkyl_radiation_read_get_num_densities( + *rad_data, atomic_z, charge_state, 1, 1e30, num_ne_per_coll + ); struct gkyl_gk_rad_drag *vnu, *vsqnu, *vnu_surf, *vsqnu_surf; - vnu = gkyl_dg_calc_gk_rad_vars_drag_new(num_collisions, - num_ne_per_coll, basis.num_basis, local_ext.volume, use_gpu); - vsqnu = gkyl_dg_calc_gk_rad_vars_drag_new(num_collisions, - num_ne_per_coll, basis.num_basis, local_ext.volume, use_gpu); - vnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new(num_collisions, - num_ne_per_coll, surf_vpar_basis.num_basis, local_ext.volume, use_gpu); - vsqnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new(num_collisions, - num_ne_per_coll, surf_mu_basis.num_basis, local_ext.volume, use_gpu); + vnu = gkyl_dg_calc_gk_rad_vars_drag_new( + num_collisions, num_ne_per_coll, basis.num_basis, local_ext.volume, use_gpu + ); + vsqnu = gkyl_dg_calc_gk_rad_vars_drag_new( + num_collisions, num_ne_per_coll, basis.num_basis, local_ext.volume, use_gpu + ); + vnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new( + num_collisions, num_ne_per_coll, surf_vpar_basis.num_basis, local_ext.volume, use_gpu + ); + vsqnu_surf = gkyl_dg_calc_gk_rad_vars_drag_new( + num_collisions, num_ne_per_coll, surf_mu_basis.num_basis, local_ext.volume, use_gpu + ); double a[1], alpha[1], beta[1], gamma[1], v0[1], n_elc_d[1]; int num_ne[1] = {1}; int ne_interval = 1; - int status = gkyl_radiation_read_get_fit_params(*rad_data, atomic_z, charge_state, - a, alpha, beta, gamma, v0, num_ne, n_elc_d, 1e19, 1, 1e30); + int status = gkyl_radiation_read_get_fit_params( + *rad_data, atomic_z, charge_state, a, alpha, beta, gamma, v0, num_ne, n_elc_d, 1e19, 1, 1e30 + ); assert(num_ne[0] == num_ne_per_coll[0]); struct gkyl_array *n_elc = mkarr(use_gpu, 1, num_ne[0]); struct gkyl_array *n_elc_ho = mkarr(false, 1, num_ne[0]); - memcpy(n_elc_ho->data, n_elc_d, num_ne[0]*sizeof(double)); + memcpy(n_elc_ho->data, n_elc_d, num_ne[0] * sizeof(double)); gkyl_array_copy(n_elc, n_elc_ho); gkyl_array_release(n_elc_ho); if (status == 1) { - printf("No radiation fits exist for z=%d, charge state=%d\n",atomic_z, charge_state); - TEST_CHECK( status==0 ); + printf("No radiation fits exist for z=%d, charge state=%d\n", atomic_z, charge_state); + TEST_CHECK(status == 0); } double ctx[2], Lz[1]; ctx[0] = te; - ctx[1] = n_elc_d[ne_interval-1]; + ctx[1] = n_elc_d[ne_interval - 1]; gkyl_radiation_read_get_fit_lz(*rad_data, atomic_z, charge_state, log10(ctx[1]), ctx, Lz); gkyl_radiation_read_release_fit_params(rad_data); - - struct gkyl_dg_calc_gk_rad_vars *calc_gk_rad_vars = gkyl_dg_calc_gk_rad_vars_new(&grid, - &confBasis, &basis, charge, mass, gk_geom, gvm, use_gpu); - gkyl_dg_calc_gk_rad_vars_nu_advance(calc_gk_rad_vars, &confLocal, &local, - a[0], alpha[0], beta[0], gamma[0], v0[0], - vnu_surf[0].data[ne_interval-1].arr, vnu[0].data[ne_interval-1].arr, - vsqnu_surf[0].data[ne_interval-1].arr, vsqnu[0].data[ne_interval-1].arr); + struct gkyl_dg_calc_gk_rad_vars *calc_gk_rad_vars = + gkyl_dg_calc_gk_rad_vars_new(&grid, &confBasis, &basis, charge, mass, gk_geom, gvm, use_gpu); + + gkyl_dg_calc_gk_rad_vars_nu_advance( + calc_gk_rad_vars, &confLocal, &local, a[0], alpha[0], beta[0], gamma[0], v0[0], + vnu_surf[0].data[ne_interval - 1].arr, vnu[0].data[ne_interval - 1].arr, + vsqnu_surf[0].data[ne_interval - 1].arr, vsqnu[0].data[ne_interval - 1].arr + ); struct gkyl_array *nvnu, *nvsqnu, *nvnu_surf, *nvsqnu_surf; nvnu = mkarr(use_gpu, basis.num_basis, local_ext.volume); @@ -615,29 +634,29 @@ test_2x(int poly_order, bool use_gpu, double te) // Project n, udrift, and vt^2 based on input functions struct gkyl_array *m0_ho = mkarr(false, confBasis.num_basis, confLocal_ext.volume); - struct gkyl_array *udrift_ho = mkarr(false, vdim*confBasis.num_basis, confLocal_ext.volume); + struct gkyl_array *udrift_ho = mkarr(false, vdim * confBasis.num_basis, confLocal_ext.volume); struct gkyl_array *vtsq_ho = mkarr(false, confBasis.num_basis, confLocal_ext.volume); struct gkyl_array *vtsq_imp = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, 1, eval_density, ctx); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_density, ctx); + + gkyl_proj_on_basis *proj_udrift = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_upar, 0); - gkyl_proj_on_basis *proj_udrift = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, vdim, eval_upar, 0); - - gkyl_proj_on_basis *proj_vtsq = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, 1, eval_vthsq, ctx); + gkyl_proj_on_basis *proj_vtsq = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_vthsq, ctx); gkyl_array_copy(vtsq_imp, vtsq_ho); - - gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0_ho); + + gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0_ho); gkyl_proj_on_basis_advance(proj_udrift, 0.0, &confLocal, udrift_ho); gkyl_proj_on_basis_advance(proj_vtsq, 0.0, &confLocal, vtsq_ho); - + // proj_maxwellian expects the primitive moments as a single array. - struct gkyl_array *prim_moms_ho = mkarr(false, 3*confBasis.num_basis, confLocal_ext.volume); - gkyl_array_set_offset(prim_moms_ho, 1.0, m0_ho, 0*confBasis.num_basis); - gkyl_array_set_offset(prim_moms_ho, 1.0, udrift_ho, 1*confBasis.num_basis); - gkyl_array_set_offset(prim_moms_ho, 1.0, vtsq_ho, 2*confBasis.num_basis); + struct gkyl_array *prim_moms_ho = mkarr(false, 3 * confBasis.num_basis, confLocal_ext.volume); + gkyl_array_set_offset(prim_moms_ho, 1.0, m0_ho, 0 * confBasis.num_basis); + gkyl_array_set_offset(prim_moms_ho, 1.0, udrift_ho, 1 * confBasis.num_basis); + gkyl_array_set_offset(prim_moms_ho, 1.0, vtsq_ho, 2 * confBasis.num_basis); // Create distribution function array struct gkyl_array *f = mkarr(use_gpu, basis.num_basis, local_ext.volume); @@ -647,47 +666,48 @@ test_2x(int poly_order, bool use_gpu, double te) .phase_grid = &grid, .conf_basis = &confBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, - .vel_range = &vLocal, + .vel_range = &vLocal, .gk_geom = gk_geom, .vel_map = gvm, .mass = mass, - .bimaxwellian = false, - .use_gpu = use_gpu, + .bimaxwellian = false, + .use_gpu = use_gpu }; - struct gkyl_gk_maxwellian_proj_on_basis *proj_max = gkyl_gk_maxwellian_proj_on_basis_inew( &inp_proj ); + struct gkyl_gk_maxwellian_proj_on_basis *proj_max = + gkyl_gk_maxwellian_proj_on_basis_inew(&inp_proj); // If on GPUs, need to copy n, udrift, and vt^2 onto device - struct gkyl_array *prim_moms, *m0, *vtsq; + struct gkyl_array *prim_moms, *m0, *vtsq; if (use_gpu) { - prim_moms = mkarr(use_gpu, 3*confBasis.num_basis, confLocal_ext.volume); + prim_moms = mkarr(use_gpu, 3 * confBasis.num_basis, confLocal_ext.volume); m0 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); vtsq = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); - + gkyl_array_copy(prim_moms, prim_moms_ho); gkyl_array_copy(m0, m0_ho); gkyl_array_copy(vtsq, vtsq_ho); - gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, - &local, &confLocal, prim_moms, false, f); - } - else { + gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, &local, &confLocal, prim_moms, false, f); + } else { vtsq = vtsq_ho; m0 = m0_ho; - gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, - &local, &confLocal, prim_moms_ho, false, f); + gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, &local, &confLocal, prim_moms_ho, false, f); } struct gkyl_array *vtsq_min_normalized = mkarr(false, 1, 1); gkyl_array_clear(vtsq_min_normalized, vtsq_min); - // initialize solver + // initialize solver struct gkyl_dg_updater_collisions *slvr; - struct gkyl_dg_rad_gyrokinetic_auxfields drag_inp = { .nvnu_surf = nvnu_surf, .nvnu = nvnu, - .nvsqnu_surf = nvsqnu_surf, .nvsqnu = nvsqnu}; - slvr = gkyl_dg_updater_rad_gyrokinetic_new(&grid, &confBasis, &basis, &local, &confLocal, gvm, &drag_inp, use_gpu); + struct gkyl_dg_rad_gyrokinetic_auxfields drag_inp = { + .nvnu_surf = nvnu_surf, .nvnu = nvnu, .nvsqnu_surf = nvsqnu_surf, .nvsqnu = nvsqnu + }; + slvr = gkyl_dg_updater_rad_gyrokinetic_new( + &grid, &confBasis, &basis, &local, &confLocal, gvm, &drag_inp, use_gpu + ); struct gkyl_array *cflrate, *rhs, *fmax; cflrate = mkarr(use_gpu, 1, local_ext.volume); @@ -700,22 +720,24 @@ test_2x(int poly_order, bool use_gpu, double te) gkyl_array_clear(nvnu, 0.0); gkyl_array_clear(nvsqnu_surf, 0.0); gkyl_array_clear(nvsqnu, 0.0); - - // Assumed electron and ion density are the same and uniform - gkyl_dg_calc_gk_rad_vars_nI_nu_advance(calc_gk_rad_vars, - &confLocal, &local, &vnu_surf[0], &vnu[0], &vsqnu_surf[0], &vsqnu[0], - n_elc, m0, m0, nvnu_surf, nvnu, nvsqnu_surf, nvsqnu, vtsq_min_normalized, vtsq); + // Assumed electron and ion density are the same and uniform + gkyl_dg_calc_gk_rad_vars_nI_nu_advance( + calc_gk_rad_vars, &confLocal, &local, &vnu_surf[0], &vnu[0], &vsqnu_surf[0], &vsqnu[0], n_elc, + m0, m0, nvnu_surf, nvnu, nvsqnu_surf, nvsqnu, vtsq_min_normalized, vtsq + ); gkyl_dg_updater_rad_gyrokinetic_advance(slvr, &local, f, cflrate, rhs); - + gkyl_grid_sub_array_write(&grid, &local, 0, rhs, "ctest_dg_rad_gyrokinetic_2x_rhs.gkyl"); gkyl_grid_sub_array_write(&grid, &local, 0, nvnu, "ctest_dg_rad_gyrokinetic_2x_nvnu.gkyl"); gkyl_grid_sub_array_write(&grid, &local, 0, nvsqnu, "ctest_dg_rad_gyrokinetic_2x_nvsqnu.gkyl"); gkyl_grid_sub_array_write(&grid, &local, 0, f, "ctest_dg_rad_gyrokinetic_2x_f.gkyl"); // Take 2nd moment of rhs to find energy loss on host - struct gkyl_dg_updater_moment *m2_calc = gkyl_dg_updater_moment_gyrokinetic_new(&grid, &confBasis, &basis, - &confLocal, GKYL_ELECTRON_MASS, -GKYL_ELEMENTARY_CHARGE, gvm, gk_geom, NULL, GKYL_F_MOMENT_M2, false, use_gpu); + struct gkyl_dg_updater_moment *m2_calc = gkyl_dg_updater_moment_gyrokinetic_new( + &grid, &confBasis, &basis, &confLocal, GKYL_ELECTRON_MASS, -GKYL_ELEMENTARY_CHARGE, gvm, + gk_geom, NULL, GKYL_F_MOMENT_M2, false, use_gpu + ); struct gkyl_array *m2_final = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); gkyl_dg_updater_moment_gyrokinetic_advance(m2_calc, &local, &confLocal, rhs, m2_final); @@ -726,19 +748,19 @@ test_2x(int poly_order, bool use_gpu, double te) gkyl_array_copy(m2_final_host, m2_final); } - double *m00 = gkyl_array_fetch(m0_ho, 0+ghost[0]); - double *m20 = gkyl_array_fetch(m2_final_host, 0+ghost[0]); + double *m00 = gkyl_array_fetch(m0_ho, 0 + ghost[0]); + double *m20 = gkyl_array_fetch(m2_final_host, 0 + ghost[0]); - double cell_avg_m2 = m20[confLocal_ext.volume]/pow(sqrt(2.0),cdim); - double cell_avg_m0 = m00[confLocal_ext.volume]/pow(sqrt(2.0),cdim); + double cell_avg_m2 = m20[confLocal_ext.volume] / pow(sqrt(2.0), cdim); + double cell_avg_m0 = m00[confLocal_ext.volume] / pow(sqrt(2.0), cdim); // two factors of density, one for the electrons and one for the ions - double cell_avg0 = 1.0/2.0*GKYL_ELECTRON_MASS*cell_avg_m2/(cell_avg_m0*cell_avg_m0); + double cell_avg0 = 1.0 / 2.0 * GKYL_ELECTRON_MASS * cell_avg_m2 / (cell_avg_m0 * cell_avg_m0); double correct = Lz[0]; // Fit error typically >10%, so %1 should be sufficient here - TEST_CHECK( gkyl_compare( -correct*1e30, cell_avg0*1e30, 1e-2)); - TEST_CHECK( cell_avg0<0 ); + TEST_CHECK(gkyl_compare(-correct * 1e30, cell_avg0 * 1e30, 1e-2)); + TEST_CHECK(cell_avg0 < 0); // Release memory gkyl_dg_calc_gk_rad_vars_drag_release(vnu, num_collisions, use_gpu); @@ -754,7 +776,7 @@ test_2x(int poly_order, bool use_gpu, double te) gkyl_dg_calc_gk_rad_vars_release(calc_gk_rad_vars); gkyl_array_release(m0_ho); - gkyl_array_release(udrift_ho); + gkyl_array_release(udrift_ho); gkyl_array_release(vtsq_ho); gkyl_array_release(vtsq_imp); gkyl_array_release(vtsq_min_normalized); @@ -775,8 +797,8 @@ test_2x(int poly_order, bool use_gpu, double te) if (use_gpu) { gkyl_array_release(m0); gkyl_array_release(vtsq); - gkyl_array_release(prim_moms); - gkyl_array_release(m2_final_host); + gkyl_array_release(prim_moms); + gkyl_array_release(m2_final_host); } gkyl_velocity_map_release(gvm); @@ -786,40 +808,82 @@ test_2x(int poly_order, bool use_gpu, double te) static int num_ne[1] = {1}; static int num_ne2[1] = {20}; -void test_1x2v_p1_10eV() { test_1x(1, false, 10.0, 3, 0, num_ne, 1); } -void test_rad_gk_1x2v_p1_30eV_ho() { test_1x(1, false, 30.0, 3, 0, num_ne, 1); } -void test_rad_gk_1x2v_p1_H_ho() { test_1x(1, false, 30.0, 1, 0, num_ne, 1); } -void test_1x2v_p1_100eV() { test_1x(1, false, 100.0, 3, 0, num_ne, 1); } -void test_1x2v_p1_500eV() { test_1x(1, false, 500.0, 3, 0, num_ne, 1); } -void test_1x2v_p1_1000eV() { test_1x(1, false, 1000.0, 3, 0, num_ne, 1); } -void test_rad_gk_1x2v_p1_5000eV_ho() { test_1x(1, false, 5000.0, 3, 0, num_ne, 1); } -void test_1x2v_p1_10000eV() { test_1x(1, false, 10000.0, 3, 0, num_ne, 1); } -void test_rad_gk_2x2v_p1_ho() { test_2x(1, false, 30.0); } - -void test_rad_gk_1x2v_p1_Li1_lowNe_ho() { test_1x(1, false, 30.0, 3, 1, num_ne2, 1); } -void test_rad_gk_1x2v_p1_Li1_midNe_ho() { test_1x(1, false, 30.0, 3, 1, num_ne2, 6); } -void test_rad_gk_1x2v_p1_Li1_highNe_ho() { test_1x(1, false, 30.0, 3, 1, num_ne2, 13); } +void test_1x2v_p1_10eV() +{ + test_1x(1, false, 10.0, 3, 0, num_ne, 1); +} +void test_rad_gk_1x2v_p1_30eV_ho() +{ + test_1x(1, false, 30.0, 3, 0, num_ne, 1); +} +void test_rad_gk_1x2v_p1_H_ho() +{ + test_1x(1, false, 30.0, 1, 0, num_ne, 1); +} +void test_1x2v_p1_100eV() +{ + test_1x(1, false, 100.0, 3, 0, num_ne, 1); +} +void test_1x2v_p1_500eV() +{ + test_1x(1, false, 500.0, 3, 0, num_ne, 1); +} +void test_1x2v_p1_1000eV() +{ + test_1x(1, false, 1000.0, 3, 0, num_ne, 1); +} +void test_rad_gk_1x2v_p1_5000eV_ho() +{ + test_1x(1, false, 5000.0, 3, 0, num_ne, 1); +} +void test_1x2v_p1_10000eV() +{ + test_1x(1, false, 10000.0, 3, 0, num_ne, 1); +} +void test_rad_gk_2x2v_p1_ho() +{ + test_2x(1, false, 30.0); +} + +void test_rad_gk_1x2v_p1_Li1_lowNe_ho() +{ + test_1x(1, false, 30.0, 3, 1, num_ne2, 1); +} +void test_rad_gk_1x2v_p1_Li1_midNe_ho() +{ + test_1x(1, false, 30.0, 3, 1, num_ne2, 6); +} +void test_rad_gk_1x2v_p1_Li1_highNe_ho() +{ + test_1x(1, false, 30.0, 3, 1, num_ne2, 13); +} #ifdef GKYL_HAVE_CUDA -void test_rad_gk_1x2v_p1_dev() { test_1x(1, true, 30.0, 3, 0, num_ne, 1); } -void test_rad_gk_1x2v_p1_L1_midNe_dev() {test_1x(1, true, 30.0, 3, 1, num_ne2, 6); } +void test_rad_gk_1x2v_p1_dev() +{ + test_1x(1, true, 30.0, 3, 0, num_ne, 1); +} +void test_rad_gk_1x2v_p1_L1_midNe_dev() +{ + test_1x(1, true, 30.0, 3, 1, num_ne2, 6); +} #endif TEST_LIST = { - { "test_rad_gk_1x2v_p1_Li0_30eV_ho", test_rad_gk_1x2v_p1_30eV_ho }, - { "test_rad_gk_1x2v_p1_Li0_5000eV_ho", test_rad_gk_1x2v_p1_5000eV_ho }, - { "test_rad_gk_1x2v_p1_H_ho", test_rad_gk_1x2v_p1_H_ho }, - { "test_rad_gk_1x2v_p1_Li1_lowNe_ho", test_rad_gk_1x2v_p1_Li1_lowNe_ho }, - { "test_rad_gk_1x2v_p1_Li1_midNe_ho", test_rad_gk_1x2v_p1_Li1_midNe_ho }, - { "test_rad_gk_1x2v_p1_Li1_highNe_ho", test_rad_gk_1x2v_p1_Li1_highNe_ho }, - { "test_rad_gk_2x2v_p1_ho", test_rad_gk_2x2v_p1_ho }, + {"test_rad_gk_1x2v_p1_Li0_30eV_ho", test_rad_gk_1x2v_p1_30eV_ho}, + {"test_rad_gk_1x2v_p1_Li0_5000eV_ho", test_rad_gk_1x2v_p1_5000eV_ho}, + {"test_rad_gk_1x2v_p1_H_ho", test_rad_gk_1x2v_p1_H_ho}, + {"test_rad_gk_1x2v_p1_Li1_lowNe_ho", test_rad_gk_1x2v_p1_Li1_lowNe_ho}, + {"test_rad_gk_1x2v_p1_Li1_midNe_ho", test_rad_gk_1x2v_p1_Li1_midNe_ho}, + {"test_rad_gk_1x2v_p1_Li1_highNe_ho", test_rad_gk_1x2v_p1_Li1_highNe_ho}, + {"test_rad_gk_2x2v_p1_ho", test_rad_gk_2x2v_p1_ho}, #ifdef GKYL_HAVE_CUDA - { "test_rad_gk_1x2v_p1_dev", test_rad_gk_1x2v_p1_dev }, - { "test_rad_gk_1x2v_p1_L1_midNe_dev", test_rad_gk_1x2v_p1_L1_midNe_dev}, + {"test_rad_gk_1x2v_p1_dev", test_rad_gk_1x2v_p1_dev}, + {"test_rad_gk_1x2v_p1_L1_midNe_dev", test_rad_gk_1x2v_p1_L1_midNe_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_dg_recomb.c b/gyrokinetic/unit/ctest_dg_recomb.c index f65e364594..2117367b00 100644 --- a/gyrokinetic/unit/ctest_dg_recomb.c +++ b/gyrokinetic/unit/ctest_dg_recomb.c @@ -16,40 +16,39 @@ double emass = GKYL_ELECTRON_MASS; double check_fac = 1.e10; double B0 = 0.5; -void eval_n_elc(double t, const double *xn, double* restrict fout, void *ctx) +void eval_n_elc(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 1.0e19; } -void eval_T_over_m_elc(double t, const double *xn, double* restrict fout, void *ctx) +void eval_T_over_m_elc(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 4.0*echarge/emass; + fout[0] = 4.0 * echarge / emass; } -void -test_coll_recomb(bool use_gpu, enum gkyl_ion_type type_ion) +void test_coll_recomb(bool use_gpu, enum gkyl_ion_type type_ion) { int charge_state; - if (type_ion == GKYL_ION_H) { + if (type_ion == GKYL_ION_H) { charge_state = 0; - } - else if (type_ion == GKYL_ION_LI || type_ion == GKYL_ION_AR) { + } else if (type_ion == GKYL_ION_LI || type_ion == GKYL_ION_AR) { charge_state = 1; } // use vt = 4 eV for all grids - double vmax_elc = 4.*sqrt(4.*echarge/emass); + double vmax_elc = 4. * sqrt(4. * echarge / emass); double vmin_elc = -vmax_elc; - double mumax_elc = 12.*4.*echarge/(2.*B0); + double mumax_elc = 12. * 4. * echarge / (2. * B0); int poly_order = 1; const int cdim = 3, vdim_gk = 2; int pdim_gk = cdim + vdim_gk; - // for gk grids - double lower_elc[] = {-2.0,-2.0,-2.0,vmin_elc,0.0}, upper_elc[] = {2.0,2.0,2.0,vmax_elc,mumax_elc}; + // for gk grids + double lower_elc[] = {-2.0, -2.0, -2.0, vmin_elc, 0.0}, + upper_elc[] = {2.0, 2.0, 2.0, vmax_elc, mumax_elc}; int ghost_gk[] = {0, 0, 0, 0, 0}; int cells_gk[] = {16, 16, 16, 8, 4}; - + struct gkyl_rect_grid confGrid; struct gkyl_range confRange, confRange_ext; gkyl_rect_grid_init(&confGrid, cdim, lower_elc, upper_elc, cells_gk); @@ -69,10 +68,10 @@ test_coll_recomb(bool use_gpu, enum gkyl_ion_type type_ion) gkyl_cart_modal_serendip(&basis, cdim, poly_order); // projection updater for moments - gkyl_proj_on_basis *proj_n_elc = gkyl_proj_on_basis_new(&confGrid, &basis, - poly_order+1, 1, eval_n_elc, NULL); - gkyl_proj_on_basis *proj_T_over_m_elc = gkyl_proj_on_basis_new(&confGrid, &basis, - poly_order+1, 1, eval_T_over_m_elc, NULL); + gkyl_proj_on_basis *proj_n_elc = + gkyl_proj_on_basis_new(&confGrid, &basis, poly_order + 1, 1, eval_n_elc, NULL); + gkyl_proj_on_basis *proj_T_over_m_elc = + gkyl_proj_on_basis_new(&confGrid, &basis, poly_order + 1, 1, eval_T_over_m_elc, NULL); struct gkyl_dg_recomb_inp rec_inp = { .grid = &phaseGrid_elc, @@ -82,107 +81,161 @@ test_coll_recomb(bool use_gpu, enum gkyl_ion_type type_ion) .conf_rng_ext = &confRange_ext, .phase_rng = &phaseRange_elc, .type_ion = type_ion, - .charge_state = charge_state, + .charge_state = charge_state }; - + // coll struct. struct gkyl_dg_recomb *coll_recomb_up = gkyl_dg_recomb_new(&rec_inp, use_gpu); - + struct gkyl_array *n_elc = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, confRange.volume); struct gkyl_array *T_over_m_elc = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, confRange.volume); - struct gkyl_array *moms_elc = gkyl_array_new(GKYL_DOUBLE, 3*basis.num_basis, confRange.volume); + struct gkyl_array *moms_elc = gkyl_array_new(GKYL_DOUBLE, 3 * basis.num_basis, confRange.volume); struct gkyl_array *coef_recomb = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, confRange.volume); - + // project moments on basis gkyl_proj_on_basis_advance(proj_n_elc, 0.0, &confRange, n_elc); gkyl_proj_on_basis_advance(proj_T_over_m_elc, 0.0, &confRange, T_over_m_elc); - + gkyl_array_set_offset(moms_elc, 1.0, n_elc, 0); - gkyl_array_set_offset(moms_elc, 1.0, T_over_m_elc, 2*basis.num_basis); + gkyl_array_set_offset(moms_elc, 1.0, T_over_m_elc, 2 * basis.num_basis); // cuda stuff if (use_gpu) { - struct gkyl_array *moms_elc_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3*basis.num_basis, confRange.volume); - struct gkyl_array *coef_recomb_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, confRange.volume); + struct gkyl_array *moms_elc_cu = + gkyl_array_cu_dev_new(GKYL_DOUBLE, 3 * basis.num_basis, confRange.volume); + struct gkyl_array *coef_recomb_cu = + gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, confRange.volume); gkyl_array_copy(moms_elc_cu, moms_elc); - + gkyl_dg_recomb_coll(coll_recomb_up, moms_elc_cu, coef_recomb_cu, 0); gkyl_array_copy(coef_recomb, coef_recomb_cu); - gkyl_array_release(moms_elc_cu); + gkyl_array_release(moms_elc_cu); gkyl_array_release(coef_recomb_cu); - } - else { + } else { gkyl_dg_recomb_coll(coll_recomb_up, moms_elc, coef_recomb, 0); } - const double *cv_r = gkyl_array_cfetch(coef_recomb, gkyl_range_idx(&confRange, (int[3]) { 1, 1, 1})); + const double *cv_r = + gkyl_array_cfetch(coef_recomb, gkyl_range_idx(&confRange, (int[3]){1, 1, 1})); // test against predicted value if (type_ion == GKYL_ION_H) { double p1_vals[] = {4.0651315620487753e-19, 0.0000000000000000e+00, 0.0000000000000000e+00, - 0.0000000000000000e+00, 0.0000000000000000e+00, 0.0000000000000000e+00, - 0.0000000000000000e+00, 0.0000000000000000e+00}; - for (int i=0; i -void test_efit_solovev_ho(){ - - struct gkyl_efit_inp inp = { +void test_efit_solovev_ho() +{ + struct gkyl_efit_inp inp = { .filepath = "gyrokinetic/data/eqdsk/solovev.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; - struct gkyl_efit* efit = gkyl_efit_new(&inp); + struct gkyl_efit *efit = gkyl_efit_new(&inp); //printf( "rdim=%g zdim=%g rcentr=%g rleft=%g zmid=%g rmaxis=%g zmaxis=%g simag=%1.16e sibry=%1.16e bcentr=%g current=%g simag=%g rmaxis=%g zmaxis=%g sibry=%g \n", efit->rdim, efit->zdim, efit->rcentr, efit->rleft, efit->zmid, efit->rmaxis, efit->zmaxis, efit->simag, efit->sibry, efit->bcentr, efit-> current, efit->simag, efit->rmaxis, efit-> zmaxis, efit->sibry); gkyl_grid_sub_array_write(&efit->rzgrid, &efit->rzlocal, 0, efit->psizr, "solovev_psi.gkyl"); - gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->fpolflux, "solovev_fpol.gkyl"); + gkyl_grid_sub_array_write( + &efit->fluxgrid, &efit->fluxlocal, 0, efit->fpolflux, "solovev_fpol.gkyl" + ); gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->qflux, "solovev_q.gkyl"); gkyl_efit_release(efit); - } -void test_efit_step_ho(){ - struct gkyl_efit_inp inp = { +void test_efit_step_ho() +{ + struct gkyl_efit_inp inp = { .filepath = "gyrokinetic/data/eqdsk/step.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; - struct gkyl_efit* efit = gkyl_efit_new(&inp); + struct gkyl_efit *efit = gkyl_efit_new(&inp); //printf( "rdim=%g zdim=%g rcentr=%g rleft=%g zmid=%g rmaxis=%g zmaxis=%g simag=%1.16e sibry=%1.16e bcentr=%g current=%g simag=%g rmaxis=%g zmaxis=%g sibry=%g \n", efit->rdim, efit->zdim, efit->rcentr, efit->rleft, efit->zmid, efit->rmaxis, efit->zmaxis, efit->simag, efit->sibry, efit->bcentr, efit-> current, efit->simag, efit->rmaxis, efit-> zmaxis, efit->sibry); gkyl_grid_sub_array_write(&efit->rzgrid, &efit->rzlocal, 0, efit->psizr, "step_psi.gkyl"); @@ -48,35 +50,35 @@ void test_efit_step_ho(){ gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->qflux, "step_q.gkyl"); gkyl_efit_release(efit); - } -void test_efit_nstxu_ho(){ +void test_efit_nstxu_ho() +{ // Uses DN configuration by default, but one can switch to SN by changing the filepath if desired. - struct gkyl_efit_inp inp = { + struct gkyl_efit_inp inp = { .filepath = "gyrokinetic/data/eqdsk/nstxu_DN.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; - struct gkyl_efit* efit = gkyl_efit_new(&inp); + struct gkyl_efit *efit = gkyl_efit_new(&inp); // printf( "rdim=%g zdim=%g rcentr=%g rleft=%g zmid=%g rmaxis=%g zmaxis=%g simag=%1.16e sibry=%1.16e bcentr=%g current=%g simag=%g rmaxis=%g zmaxis=%g sibry=%g psisep=%g \n", efit->rdim, efit->zdim, efit->rcentr, efit->rleft, efit->zmid, efit->rmaxis, efit->zmaxis, efit->simag, efit->sibry, efit->bcentr, efit-> current, efit->simag, efit->rmaxis, efit-> zmaxis, efit->sibry, efit->psisep); gkyl_grid_sub_array_write(&efit->rzgrid, &efit->rzlocal, 0, efit->psizr, "nstxu_DN_psi.gkyl"); - gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->fpolflux, "nstxu_DN_fpol.gkyl"); + gkyl_grid_sub_array_write( + &efit->fluxgrid, &efit->fluxlocal, 0, efit->fpolflux, "nstxu_DN_fpol.gkyl" + ); gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->qflux, "nstxu_DN_q.gkyl"); gkyl_efit_release(efit); - } -void test_efit_asdex_ho(){ - struct gkyl_efit_inp inp = { - .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, +void test_efit_asdex_ho() +{ + struct gkyl_efit_inp inp = { + .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1 }; - struct gkyl_efit* efit = gkyl_efit_new(&inp); + struct gkyl_efit *efit = gkyl_efit_new(&inp); //printf( "rdim=%g zdim=%g rcentr=%g rleft=%g zmid=%g rmaxis=%g zmaxis=%g simag=%1.16e sibry=%1.16e bcentr=%g current=%g simag=%g rmaxis=%g zmaxis=%g sibry=%g \n", efit->rdim, efit->zdim, efit->rcentr, efit->rleft, efit->zmid, efit->rmaxis, efit->zmaxis, efit->simag, efit->sibry, efit->bcentr, efit-> current, efit->simag, efit->rmaxis, efit-> zmaxis, efit->sibry); gkyl_grid_sub_array_write(&efit->rzgrid, &efit->rzlocal, 0, efit->psizr, "asdex_psi.gkyl"); @@ -84,54 +86,55 @@ void test_efit_asdex_ho(){ gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->qflux, "asdex_q.gkyl"); gkyl_efit_release(efit); - } -void test_efit_cerfon_ho(){ - - struct gkyl_efit_inp inp = { +void test_efit_cerfon_ho() +{ + struct gkyl_efit_inp inp = { .filepath = "gyrokinetic/data/eqdsk/cerfon.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; - struct gkyl_efit* efit = gkyl_efit_new(&inp); + struct gkyl_efit *efit = gkyl_efit_new(&inp); //printf( "rdim=%g zdim=%g rcentr=%g rleft=%g zmid=%g rmaxis=%g zmaxis=%g simag=%1.16e sibry=%1.16e bcentr=%g current=%g simag=%g rmaxis=%g zmaxis=%g sibry=%g \n", efit->rdim, efit->zdim, efit->rcentr, efit->rleft, efit->zmid, efit->rmaxis, efit->zmaxis, efit->simag, efit->sibry, efit->bcentr, efit-> current, efit->simag, efit->rmaxis, efit-> zmaxis, efit->sibry); gkyl_grid_sub_array_write(&efit->rzgrid, &efit->rzlocal, 0, efit->psizr, "cerfon_psi.gkyl"); - gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->fpolflux, "cerfon_fpol.gkyl"); + gkyl_grid_sub_array_write( + &efit->fluxgrid, &efit->fluxlocal, 0, efit->fpolflux, "cerfon_fpol.gkyl" + ); gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->qflux, "cerfon_q.gkyl"); gkyl_efit_release(efit); - } -void test_efit_elliptical_ho(){ - struct gkyl_efit_inp inp = { +void test_efit_elliptical_ho() +{ + struct gkyl_efit_inp inp = { .filepath = "gyrokinetic/data/eqdsk/elliptical.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; - struct gkyl_efit* efit = gkyl_efit_new(&inp); + struct gkyl_efit *efit = gkyl_efit_new(&inp); //printf( "rdim=%g zdim=%g rcentr=%g rleft=%g zmid=%g rmaxis=%g zmaxis=%g simag=%1.16e sibry=%1.16e bcentr=%g current=%g simag=%g rmaxis=%g zmaxis=%g sibry=%g \n", efit->rdim, efit->zdim, efit->rcentr, efit->rleft, efit->zmid, efit->rmaxis, efit->zmaxis, efit->simag, efit->sibry, efit->bcentr, efit-> current, efit->simag, efit->rmaxis, efit-> zmaxis, efit->sibry); gkyl_grid_sub_array_write(&efit->rzgrid, &efit->rzlocal, 0, efit->psizr, "elliptical_psi.gkyl"); - gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->fpolflux, "elliptical_fpol.gkyl"); + gkyl_grid_sub_array_write( + &efit->fluxgrid, &efit->fluxlocal, 0, efit->fpolflux, "elliptical_fpol.gkyl" + ); gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->qflux, "elliptical_q.gkyl"); gkyl_efit_release(efit); - } -void test_efit_wham_ho(){ - struct gkyl_efit_inp inp = { - .filepath = "gyrokinetic/data/eqdsk/wham.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, +void test_efit_wham_ho() +{ + struct gkyl_efit_inp inp = { + .filepath = "gyrokinetic/data/eqdsk/wham.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1 //.reflect = true, }; - struct gkyl_efit* efit = gkyl_efit_new(&inp); + struct gkyl_efit *efit = gkyl_efit_new(&inp); //printf( "rdim=%g zdim=%g rcentr=%g rleft=%g zmid=%g rmaxis=%g zmaxis=%g simag=%1.16e sibry=%1.16e bcentr=%g current=%g simag=%g rmaxis=%g zmaxis=%g sibry=%g \n", efit->rdim, efit->zdim, efit->rcentr, efit->rleft, efit->zmid, efit->rmaxis, efit->zmaxis, efit->simag, efit->sibry, efit->bcentr, efit-> current, efit->simag, efit->rmaxis, efit-> zmaxis, efit->sibry); gkyl_grid_sub_array_write(&efit->rzgrid, &efit->rzlocal, 0, efit->psizr, "wham_psi.gkyl"); @@ -139,17 +142,14 @@ void test_efit_wham_ho(){ gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->qflux, "wham_q.gkyl"); gkyl_efit_release(efit); - } - -void test_efit_tcv_ho(){ - struct gkyl_efit_inp inp = { - .filepath = "gyrokinetic/data/eqdsk/tcv.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, +void test_efit_tcv_ho() +{ + struct gkyl_efit_inp inp = { + .filepath = "gyrokinetic/data/eqdsk/tcv.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1 }; - struct gkyl_efit* efit = gkyl_efit_new(&inp); + struct gkyl_efit *efit = gkyl_efit_new(&inp); //printf( "rdim=%g zdim=%g rcentr=%g rleft=%g zmid=%g rmaxis=%g zmaxis=%g simag=%1.16e sibry=%1.16e bcentr=%g current=%g simag=%g rmaxis=%g zmaxis=%g sibry=%g \n", efit->rdim, efit->zdim, efit->rcentr, efit->rleft, efit->zmid, efit->rmaxis, efit->zmaxis, efit->simag, efit->sibry, efit->bcentr, efit-> current, efit->simag, efit->rmaxis, efit-> zmaxis, efit->sibry); gkyl_grid_sub_array_write(&efit->rzgrid, &efit->rzlocal, 0, efit->psizr, "tcv_psi.gkyl"); @@ -157,17 +157,17 @@ void test_efit_tcv_ho(){ gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->qflux, "tcv_q.gkyl"); gkyl_efit_release(efit); - } -void test_efit_mast_ho(){ - struct gkyl_efit_inp inp = { +void test_efit_mast_ho() +{ + struct gkyl_efit_inp inp = { .filepath = "gyrokinetic/data/eqdsk/mast.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; - struct gkyl_efit* efit = gkyl_efit_new(&inp); + struct gkyl_efit *efit = gkyl_efit_new(&inp); //printf( "rdim=%g zdim=%g rcentr=%g rleft=%g zmid=%g rmaxis=%g zmaxis=%g simag=%1.16e sibry=%1.16e bcentr=%g current=%g simag=%g rmaxis=%g zmaxis=%g sibry=%g \n", efit->rdim, efit->zdim, efit->rcentr, efit->rleft, efit->zmid, efit->rmaxis, efit->zmaxis, efit->simag, efit->sibry, efit->bcentr, efit-> current, efit->simag, efit->rmaxis, efit-> zmaxis, efit->sibry); gkyl_grid_sub_array_write(&efit->rzgrid, &efit->rzlocal, 0, efit->psizr, "mast_psi.gkyl"); @@ -175,17 +175,17 @@ void test_efit_mast_ho(){ gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->qflux, "mast_q.gkyl"); gkyl_efit_release(efit); - } -void test_efit_ltx_ho(){ - struct gkyl_efit_inp inp = { +void test_efit_ltx_ho() +{ + struct gkyl_efit_inp inp = { .filepath = "gyrokinetic/data/eqdsk/LTX_103955_03.eqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; - struct gkyl_efit* efit = gkyl_efit_new(&inp); + struct gkyl_efit *efit = gkyl_efit_new(&inp); //printf( "rdim=%g zdim=%g rcentr=%g rleft=%g zmid=%g rmaxis=%g zmaxis=%g simag=%1.16e sibry=%1.16e bcentr=%g current=%g simag=%g rmaxis=%g zmaxis=%g sibry=%g \n", efit->rdim, efit->zdim, efit->rcentr, efit->rleft, efit->zmid, efit->rmaxis, efit->zmaxis, efit->simag, efit->sibry, efit->bcentr, efit-> current, efit->simag, efit->rmaxis, efit-> zmaxis, efit->sibry); gkyl_grid_sub_array_write(&efit->rzgrid, &efit->rzlocal, 0, efit->psizr, "ltx_psi.gkyl"); @@ -193,19 +193,18 @@ void test_efit_ltx_ho(){ gkyl_grid_sub_array_write(&efit->fluxgrid, &efit->fluxlocal, 0, efit->qflux, "ltx_q.gkyl"); gkyl_efit_release(efit); - } TEST_LIST = { - { "test_efit_solovev_ho", test_efit_solovev_ho}, - { "test_efit_step_ho", test_efit_step_ho}, - { "test_efit_asdex_ho", test_efit_asdex_ho}, - { "test_efit_nstxu_ho", test_efit_nstxu_ho}, - { "test_efit_cerfon_ho", test_efit_cerfon_ho}, - { "test_efit_elliptical_ho", test_efit_elliptical_ho}, - { "test_efit_wham_ho", test_efit_wham_ho}, - { "test_efit_tcv_ho", test_efit_tcv_ho}, - { "test_efit_mast_ho", test_efit_mast_ho}, - { "test_efit_ltx_ho", test_efit_ltx_ho}, - { NULL, NULL }, + {"test_efit_solovev_ho", test_efit_solovev_ho}, + {"test_efit_step_ho", test_efit_step_ho}, + {"test_efit_asdex_ho", test_efit_asdex_ho}, + {"test_efit_nstxu_ho", test_efit_nstxu_ho}, + {"test_efit_cerfon_ho", test_efit_cerfon_ho}, + {"test_efit_elliptical_ho", test_efit_elliptical_ho}, + {"test_efit_wham_ho", test_efit_wham_ho}, + {"test_efit_tcv_ho", test_efit_tcv_ho}, + {"test_efit_mast_ho", test_efit_mast_ho}, + {"test_efit_ltx_ho", test_efit_ltx_ho}, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_fem_parproj.c b/gyrokinetic/unit/ctest_fem_parproj.c index ea55b9c2b4..7772fd9b88 100644 --- a/gyrokinetic/unit/ctest_fem_parproj.c +++ b/gyrokinetic/unit/ctest_fem_parproj.c @@ -15,12 +15,11 @@ #include #include -static struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { // Allocate array (filled with zeros) - struct gkyl_array* a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } @@ -32,23 +31,26 @@ struct skin_ghost_ranges { struct gkyl_range upper_ghost[GKYL_MAX_DIM]; }; -static void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { // Create ghost and skin sub-ranges given a parent range int ndim = parent->ndim; - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } -void -apply_periodic_bc(struct gkyl_array *buff, struct gkyl_array *fld, const int dir, const struct skin_ghost_ranges sgr) +void apply_periodic_bc( + struct gkyl_array *buff, struct gkyl_array *fld, const int dir, const struct skin_ghost_ranges sgr +) { // Apply periodic BCs along parallel direction gkyl_array_copy_to_buffer(buff->data, fld, &(sgr.lower_skin[dir])); @@ -58,18 +60,22 @@ apply_periodic_bc(struct gkyl_array *buff, struct gkyl_array *fld, const int dir gkyl_array_copy_from_buffer(fld, buff->data, &(sgr.lower_ghost[dir])); } -static void check_continuity_par(struct gkyl_range range, struct gkyl_basis basis, struct gkyl_array *field) +static void +check_continuity_par(struct gkyl_range range, struct gkyl_basis basis, struct gkyl_array *field) { // Check continuity along last dim. - if (basis.poly_order > 1) return; + if (basis.poly_order > 1) { + return; + } int ndim = basis.ndim; - int pardir = ndim-1; + int pardir = ndim - 1; int num_nodes_perp_max = 4; // 3x p=1. int num_nodes_perp = 1; - if (ndim == 2) + if (ndim == 2) { num_nodes_perp = 2; - else if (ndim == 3) + } else if (ndim == 3) { num_nodes_perp = 4; + } struct gkyl_array *nodes = gkyl_array_new(GKYL_DOUBLE, ndim, basis.num_basis); basis.node_list(gkyl_array_fetch(nodes, 0)); @@ -80,8 +86,9 @@ static void check_continuity_par(struct gkyl_range range, struct gkyl_basis basi while (gkyl_range_iter_next(&iter)) { if (iter.idx[pardir] < range.upper[pardir]) { int *idx_lo = iter.idx; - for (int d=0; d 1 || ndim == 1) return; + if (basis.poly_order > 1 || ndim == 1) { + return; + } int num_nodes = basis.num_basis; struct gkyl_array *nodes = gkyl_array_new(GKYL_DOUBLE, ndim, basis.num_basis); basis.node_list(gkyl_array_fetch(nodes, 0)); @@ -125,8 +138,9 @@ static void check_continuity_perp(struct gkyl_range range, struct gkyl_basis bas int perpdir = 0; if (iter.idx[perpdir] < range.upper[perpdir]) { int *idx_lo = iter.idx; - for (int d=0; d 1) return; // Check only working for p=1. + if (basis.poly_order > 1) { + return; // Check only working for p=1. + } int ndim = basis.ndim; - int pardir = ndim-1; + int pardir = ndim - 1; int num_nodes_perp_max = 4; // 3x p=1. int num_nodes_perp = 1; - if (ndim == 2) + if (ndim == 2) { num_nodes_perp = 2; - else if (ndim == 3) + } else if (ndim == 3) { num_nodes_perp = 4; + } struct gkyl_array *nodes = gkyl_array_new(GKYL_DOUBLE, ndim, basis.num_basis); basis.node_list(gkyl_array_fetch(nodes, 0)); - for (int e=0; e<2; e++) { - + for (int e = 0; e < 2; e++) { struct gkyl_range perp_range; - if (e == 0) + if (e == 0) { gkyl_range_shorten_from_above(&perp_range, &local, pardir, 1); - else + } else { gkyl_range_shorten_from_below(&perp_range, &local, pardir, 1); + } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &perp_range); while (gkyl_range_iter_next(&iter)) { int diri_idx[ndim]; - for (int d=0; d 1) return; // Check only working for p=1. + if (basis.poly_order > 1) { + return; // Check only working for p=1. + } int ndim = basis.ndim; - int pardir = ndim-1; + int pardir = ndim - 1; int num_nodes_perp_max = 4; // 3x p=1. int num_nodes_perp = 1; - if (ndim == 2) + if (ndim == 2) { num_nodes_perp = 2; - else if (ndim == 3) + } else if (ndim == 3) { num_nodes_perp = 4; + } struct gkyl_array *nodes = gkyl_array_new(GKYL_DOUBLE, ndim, basis.num_basis); basis.node_list(gkyl_array_fetch(nodes, 0)); - for (int e=0; e<2; e++) { - + for (int e = 0; e < 2; e++) { struct gkyl_range perp_range; - if (e == 0) + if (e == 0) { gkyl_range_shorten_from_above(&perp_range, &local, pardir, 1); - else + } else { gkyl_range_shorten_from_below(&perp_range, &local, pardir, 1); + } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &perp_range); while (gkyl_range_iter_next(&iter)) { int diri_idx[ndim]; - for (int d=0; dnum_bias_line; j++) { + for (int j = 0; j < bls->num_bias_line; j++) { struct gkyl_poisson_bias_line *bl = &bls->bl[j]; bool found_node = true; - for (int bld=0; bld<2; bld++) { + for (int bld = 0; bld < 2; bld++) { int perp_dir = bl->perp_dirs[bld]; - found_node = found_node && (fabs(bl->perp_coords[bld]-node_comp[perp_dir]) < 1e-11); + found_node = found_node && (fabs(bl->perp_coords[bld] - node_comp[perp_dir]) < 1e-11); } if (found_node) { is_node_biased = true; @@ -337,73 +379,84 @@ void check_dirichlet_bc_bias(struct gkyl_rect_grid grid, struct gkyl_range local } } - double ref_val; + double ref_val; if (is_node_biased) { // Check biasing value is enforced. struct gkyl_poisson_bias_line *bl = &bls->bl[biased_node_idx]; - ref_val = bl->val; - TEST_CHECK( gkyl_compare(ref_val, fn_fem[i], 1e-12) ); - } - else { + ref_val = bl->val; + TEST_CHECK(gkyl_compare(ref_val, fn_fem[i], 1e-12)); + } else { // Check Dirichlet value is enforced. - ref_val = fn_dg[i]; - TEST_CHECK( gkyl_compare(ref_val, fn_fem[i], 1e-12) ); + ref_val = fn_dg[i]; + TEST_CHECK(gkyl_compare(ref_val, fn_fem[i], 1e-12)); + } + if (ndim == 1) { + TEST_MSG( + "e=%d, idx_skin=%d, idx_diri=%d, node %d: ref=%.9e fem=%.9e diff=%.9e\n", e, + iter.idx[0], diri_idx[0], off_skin + i, ref_val, fn_fem[i], fn_dg[i] - fn_fem[i] + ); + } else if (ndim == 2) { + TEST_MSG( + "e=%d, idx_skin=%d,%d, idx_diri=%d,%d, node %d: ref=%.9e fem=%.9e diff=%.9e\n", e, + iter.idx[0], iter.idx[1], diri_idx[0], diri_idx[1], off_skin + i, ref_val, fn_fem[i], + fn_dg[i] - fn_fem[i] + ); + } else if (ndim == 3) { + TEST_MSG( + "e=%d, idx_skin=%d,%d,%d, idx_diri=%d,%d,%d, node %d: ref=%.9e fem=%.9e diff=%.9e\n", e, + iter.idx[0], iter.idx[1], iter.idx[2], diri_idx[0], diri_idx[1], diri_idx[2], + off_skin + i, ref_val, fn_fem[i], fn_dg[i] - fn_fem[i] + ); } - if (ndim == 1) - TEST_MSG( "e=%d, idx_skin=%d, idx_diri=%d, node %d: ref=%.9e fem=%.9e diff=%.9e\n", e, - iter.idx[0], diri_idx[0], off_skin+i, ref_val, fn_fem[i], fn_dg[i]-fn_fem[i]); - else if (ndim == 2) - TEST_MSG( "e=%d, idx_skin=%d,%d, idx_diri=%d,%d, node %d: ref=%.9e fem=%.9e diff=%.9e\n", e, - iter.idx[0], iter.idx[1], diri_idx[0], diri_idx[1], off_skin+i, ref_val, fn_fem[i], fn_dg[i]-fn_fem[i]); - else if (ndim == 3) - TEST_MSG( "e=%d, idx_skin=%d,%d,%d, idx_diri=%d,%d,%d, node %d: ref=%.9e fem=%.9e diff=%.9e\n", e, - iter.idx[0], iter.idx[1], iter.idx[2], diri_idx[0], diri_idx[1], diri_idx[2], off_skin+i, ref_val, fn_fem[i], fn_dg[i]-fn_fem[i]); } } } gkyl_array_release(nodes); } -void evalFunc1x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = sin(2.*M_PI*x); + fout[0] = sin(2. * M_PI * x); } -void evalFunc1x_dirichlet(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc1x_dirichlet(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; // Test Dirichlet BCs with something that's not 0 at the boundary. - fout[0] = cos(2.*M_PI*x); + fout[0] = cos(2. * M_PI * x); } -void ghost_from_skin_surf(bool use_gpu, int dim, struct skin_ghost_ranges *sgr, - struct gkyl_basis *basis, struct gkyl_array *rho) +void ghost_from_skin_surf( + bool use_gpu, int dim, struct skin_ghost_ranges *sgr, struct gkyl_basis *basis, + struct gkyl_array *rho +) { // The ghost range with the value of the skin at the boundary. - struct gkyl_array *bc_buffer = mkarr(use_gpu, rho->ncomp, sgr->lower_ghost[dim-1].volume); - - struct gkyl_bc_basic_gyrokinetic* bc_op_lo = gkyl_bc_basic_gyrokinetic_new(dim-1, GKYL_LOWER_EDGE, - GKYL_BC_GK_FIELD_BOUNDARY_VALUE, basis, &sgr->lower_skin[dim-1], &sgr->lower_ghost[dim-1], - basis->num_basis, dim, use_gpu); + struct gkyl_array *bc_buffer = mkarr(use_gpu, rho->ncomp, sgr->lower_ghost[dim - 1].volume); + + struct gkyl_bc_basic_gyrokinetic *bc_op_lo = gkyl_bc_basic_gyrokinetic_new( + dim - 1, GKYL_LOWER_EDGE, GKYL_BC_GK_FIELD_BOUNDARY_VALUE, basis, &sgr->lower_skin[dim - 1], + &sgr->lower_ghost[dim - 1], basis->num_basis, dim, use_gpu + ); gkyl_bc_basic_gyrokinetic_advance(bc_op_lo, bc_buffer, rho); gkyl_bc_basic_gyrokinetic_release(bc_op_lo); - - struct gkyl_bc_basic_gyrokinetic* bc_op_up = gkyl_bc_basic_gyrokinetic_new(dim-1, GKYL_UPPER_EDGE, - GKYL_BC_GK_FIELD_BOUNDARY_VALUE, basis, &sgr->upper_skin[dim-1], &sgr->upper_ghost[dim-1], - basis->num_basis, dim, use_gpu); + + struct gkyl_bc_basic_gyrokinetic *bc_op_up = gkyl_bc_basic_gyrokinetic_new( + dim - 1, GKYL_UPPER_EDGE, GKYL_BC_GK_FIELD_BOUNDARY_VALUE, basis, &sgr->upper_skin[dim - 1], + &sgr->upper_ghost[dim - 1], basis->num_basis, dim, use_gpu + ); gkyl_bc_basic_gyrokinetic_advance(bc_op_up, bc_buffer, rho); gkyl_bc_basic_gyrokinetic_release(bc_op_up); - + gkyl_array_release(bc_buffer); } -void -test_1x(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) +void test_1x(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) { double lower[] = {-0.5}, upper[] = {0.5}; int cells[] = {4}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // grids. struct gkyl_rect_grid grid; @@ -413,40 +466,46 @@ test_1x(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1 }; + int ghost[] = {1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct skin_ghost_ranges skin_ghost; // skin/ghost. skin_ghost_ranges_init(&skin_ghost, &localRange_ext, ghost); // projection updater for DG field. - gkyl_proj_on_basis *projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, - bctype==GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype==GKYL_FEM_PARPROJ_DIRICHLET_SKIN? evalFunc1x_dirichlet : evalFunc1x, - NULL); + gkyl_proj_on_basis *projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, + bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN ? + evalFunc1x_dirichlet : + evalFunc1x, + NULL + ); // create DG field we wish to make continuous. struct gkyl_array *rho = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); // create array holding continuous field we'll compute. struct gkyl_array *phi = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *rho_ho = use_gpu? mkarr(false, rho->ncomp, rho->size) : gkyl_array_acquire(rho); - struct gkyl_array *phi_ho = use_gpu? mkarr(false, phi->ncomp, phi->size) : gkyl_array_acquire(phi); + struct gkyl_array *rho_ho = use_gpu ? mkarr(false, rho->ncomp, rho->size) : + gkyl_array_acquire(rho); + struct gkyl_array *phi_ho = use_gpu ? mkarr(false, phi->ncomp, phi->size) : + gkyl_array_acquire(phi); // project distribution function on basis. gkyl_proj_on_basis_advance(projob, 0.0, &localRange, rho_ho); - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) { // Fill the ghost cell so we can apply Dirichlet BCs. ghost_from_skin_surf(false, dim, &skin_ghost, &basis, rho_ho); + } gkyl_array_copy(rho, rho_ho); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_1x_p2_rho_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_1x_p2_rho_1.gkyl"); // parallel FEM projection method. - struct gkyl_fem_parproj *parproj = gkyl_fem_parproj_new(&localRange, &grid, &basis, - bctype, 0, 0, 0, use_gpu); + struct gkyl_fem_parproj *parproj = + gkyl_fem_parproj_new(&localRange, &grid, &basis, bctype, 0, 0, 0, use_gpu); // Set the RHS source. gkyl_fem_parproj_set_rhs(parproj, rho, rho); @@ -456,11 +515,12 @@ test_1x(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) gkyl_array_copy(phi_ho, phi); if (bctype == GKYL_FEM_PARPROJ_PERIODIC) { - struct gkyl_array *parbuff = mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim-1].volume); - apply_periodic_bc(parbuff, phi_ho, dim-1, skin_ghost); + struct gkyl_array *parbuff = + mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim - 1].volume); + apply_periodic_bc(parbuff, phi_ho, dim - 1, skin_ghost); gkyl_array_release(parbuff); } -// gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_1x_p2_phi_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_1x_p2_phi_1.gkyl"); // Check continuity at cell boundaries. check_continuity_par(localRange, basis, phi_ho); @@ -471,108 +531,107 @@ test_1x(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) } else if (bctype == GKYL_FEM_PARPROJ_NONE) { // Solution (checked visually, also checked that phi is actually continuous, // and checked that visually looks like results in g2): - const double sol[8] = {-0.9089542445638024, -0.4554124667453318, - -0.8488758876834943, 0.4900987222626481, - 0.8488758876834943, 0.490098722262648 , - 0.9089542445638024, -0.4554124667453318}; + const double sol[8] = {-0.9089542445638024, -0.4554124667453318, -0.8488758876834943, + 0.4900987222626481, 0.8488758876834943, 0.490098722262648, + 0.9089542445638024, -0.4554124667453318}; const double *phi_p; phi_p = gkyl_array_cfetch(phi_ho, 1); - TEST_CHECK( gkyl_compare(sol[0], phi_p[0], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[0], phi_p[0], 1e-14)); TEST_MSG("Expected: %.13e in cell (%d)", sol[0], 1); TEST_MSG("Produced: %.13e", phi_p[0]); - TEST_CHECK( gkyl_compare(sol[1], phi_p[1], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[1], phi_p[1], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 2); - TEST_CHECK( gkyl_compare(sol[2], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[3], phi_p[1], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[2], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[3], phi_p[1], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 3); - TEST_CHECK( gkyl_compare(sol[4], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[5], phi_p[1], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[4], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[5], phi_p[1], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 4); - TEST_CHECK( gkyl_compare(sol[6], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[7], phi_p[1], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[6], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[7], phi_p[1], 1e-14)); } else if (bctype == GKYL_FEM_PARPROJ_PERIODIC) { // Solution (checked visually against g2): - const double sol[8] = {-0.8638954769035714, -0.498770286141977, - -0.8638954769035713, 0.498770286141977, - 0.8638954769035713, 0.498770286141977, - 0.8638954769035713, -0.498770286141977}; + const double sol[8] = {-0.8638954769035714, -0.498770286141977, -0.8638954769035713, + 0.498770286141977, 0.8638954769035713, 0.498770286141977, + 0.8638954769035713, -0.498770286141977}; const double *phi_p; phi_p = gkyl_array_cfetch(phi_ho, 0); - TEST_CHECK( gkyl_compare(sol[6], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[7], phi_p[1], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[6], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[7], phi_p[1], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 1); - TEST_CHECK( gkyl_compare(sol[0], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[1], phi_p[1], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[0], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[1], phi_p[1], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 2); - TEST_CHECK( gkyl_compare(sol[2], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[3], phi_p[1], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[2], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[3], phi_p[1], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 3); - TEST_CHECK( gkyl_compare(sol[4], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[5], phi_p[1], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[4], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[5], phi_p[1], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 4); - TEST_CHECK( gkyl_compare(sol[6], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[7], phi_p[1], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[6], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[7], phi_p[1], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 5); - TEST_CHECK( gkyl_compare(sol[0], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[1], phi_p[1], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[0], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[1], phi_p[1], 1e-14)); } - } if (poly_order == 2) { + } + if (poly_order == 2) { if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) { check_dirichlet_bc(localRange, localRange_ext, basis, bctype, rho_ho, phi_ho); } else if (bctype == GKYL_FEM_PARPROJ_NONE) { // Solution (checked visually against g2): - const double sol[12] = {-0.9010465429057769, -0.4272439810948228, 0.0875367707148495, - -0.9039382020247494, 0.4172269800703625, 0.08107082435707 , - 0.9039382020247495, 0.4172269800703625, -0.0810708243570699, - 0.9010465429057768, -0.4272439810948229, -0.0875367707148495}; + const double sol[12] = {-0.9010465429057769, -0.4272439810948228, 0.0875367707148495, + -0.9039382020247494, 0.4172269800703625, 0.08107082435707, + 0.9039382020247495, 0.4172269800703625, -0.0810708243570699, + 0.9010465429057768, -0.4272439810948229, -0.0875367707148495}; const double *phi_p; phi_p = gkyl_array_cfetch(phi_ho, 1); - TEST_CHECK( gkyl_compare(sol[0], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[1], phi_p[1], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[2], phi_p[2], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[0], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[1], phi_p[1], 1e-14)); + TEST_CHECK(gkyl_compare(sol[2], phi_p[2], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 2); - TEST_CHECK( gkyl_compare(sol[3], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[4], phi_p[1], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[5], phi_p[2], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[3], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[4], phi_p[1], 1e-14)); + TEST_CHECK(gkyl_compare(sol[5], phi_p[2], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 3); - TEST_CHECK( gkyl_compare(sol[6], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[7], phi_p[1], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[8], phi_p[2], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[6], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[7], phi_p[1], 1e-14)); + TEST_CHECK(gkyl_compare(sol[8], phi_p[2], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 4); - TEST_CHECK( gkyl_compare(sol[9], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[10], phi_p[1], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[11], phi_p[2], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[9], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[10], phi_p[1], 1e-14)); + TEST_CHECK(gkyl_compare(sol[11], phi_p[2], 1e-14)); } else if (bctype == GKYL_FEM_PARPROJ_PERIODIC) { // Solution (checked visually against g2): - const double sol[12] = {-0.9044201452112453, -0.418896480241106, 0.0799931666307734, - -0.9044201452112451, 0.418896480241106, 0.0799931666307734, - 0.904420145211245 , 0.418896480241106, -0.0799931666307734, - 0.9044201452112451, -0.418896480241106, -0.0799931666307734}; + const double sol[12] = {-0.9044201452112453, -0.418896480241106, 0.0799931666307734, + -0.9044201452112451, 0.418896480241106, 0.0799931666307734, + 0.904420145211245, 0.418896480241106, -0.0799931666307734, + 0.9044201452112451, -0.418896480241106, -0.0799931666307734}; const double *phi_p; phi_p = gkyl_array_cfetch(phi_ho, 0); - TEST_CHECK( gkyl_compare(sol[9], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[10], phi_p[1], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[11], phi_p[2], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[9], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[10], phi_p[1], 1e-14)); + TEST_CHECK(gkyl_compare(sol[11], phi_p[2], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 1); - TEST_CHECK( gkyl_compare(sol[0], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[1], phi_p[1], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[2], phi_p[2], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[0], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[1], phi_p[1], 1e-14)); + TEST_CHECK(gkyl_compare(sol[2], phi_p[2], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 2); - TEST_CHECK( gkyl_compare(sol[3], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[4], phi_p[1], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[5], phi_p[2], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[3], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[4], phi_p[1], 1e-14)); + TEST_CHECK(gkyl_compare(sol[5], phi_p[2], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 3); - TEST_CHECK( gkyl_compare(sol[6], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[7], phi_p[1], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[8], phi_p[2], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[6], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[7], phi_p[1], 1e-14)); + TEST_CHECK(gkyl_compare(sol[8], phi_p[2], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 4); - TEST_CHECK( gkyl_compare(sol[9], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[10], phi_p[1], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[11], phi_p[2], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[9], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[10], phi_p[1], 1e-14)); + TEST_CHECK(gkyl_compare(sol[11], phi_p[2], 1e-14)); phi_p = gkyl_array_cfetch(phi_ho, 5); - TEST_CHECK( gkyl_compare(sol[0], phi_p[0], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[1], phi_p[1], 1e-14) ); - TEST_CHECK( gkyl_compare(sol[2], phi_p[2], 1e-14) ); + TEST_CHECK(gkyl_compare(sol[0], phi_p[0], 1e-14)); + TEST_CHECK(gkyl_compare(sol[1], phi_p[1], 1e-14)); + TEST_CHECK(gkyl_compare(sol[2], phi_p[2], 1e-14)); } } @@ -582,44 +641,41 @@ test_1x(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) gkyl_array_release(phi); gkyl_array_release(rho_ho); gkyl_array_release(phi_ho); - } -void evalFunc2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; double mu = .2; double sig = 0.3; - fout[0] = exp(-(pow(x-mu,2))/(2.0*sig*sig))*sin(2.*M_PI*y); + fout[0] = exp(-(pow(x - mu, 2)) / (2.0 * sig * sig)) * sin(2. * M_PI * y); } -void evalFunc2x_xcont(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_xcont(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; double mu = .2; double sig = 0.3; - fout[0] = exp(-(pow(x-mu,2))/(2.0*sig*sig)); + fout[0] = exp(-(pow(x - mu, 2)) / (2.0 * sig * sig)); } -void evalFunc2x_ydiscont(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_ydiscont(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; - fout[0] = 2.0+sin(2.*M_PI*y); + fout[0] = 2.0 + sin(2. * M_PI * y); } -void -evalFunc2x_dirichlet(double t, const double *xn, double *fout, void *ctx) +void evalFunc2x_dirichlet(double t, const double *xn, double *fout, void *ctx) { double x = xn[0], z = xn[1]; - fout[0] = cos(x)*cos(5*z); + fout[0] = cos(x) * cos(5 * z); } -void -test_2x(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) +void test_2x(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) { double lower[] = {-2., -0.5}, upper[] = {2., 0.5}; int cells[] = {3, 4}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; @@ -629,52 +685,58 @@ test_2x(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct skin_ghost_ranges skin_ghost; // skin/ghost. skin_ghost_ranges_init(&skin_ghost, &localRange_ext, ghost); // Projection updater for DG field. - gkyl_proj_on_basis *projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, - bctype==GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype==GKYL_FEM_PARPROJ_DIRICHLET_SKIN? evalFunc2x_dirichlet : evalFunc2x, - NULL); + gkyl_proj_on_basis *projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, + bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN ? + evalFunc2x_dirichlet : + evalFunc2x, + NULL + ); // create DG field we wish to make continuous. struct gkyl_array *rho = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); // create array holding continuous field we'll compute. struct gkyl_array *phi = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *rho_ho = use_gpu? mkarr(false, rho->ncomp, rho->size) : gkyl_array_acquire(rho); - struct gkyl_array *phi_ho = use_gpu? mkarr(false, phi->ncomp, phi->size) : gkyl_array_acquire(phi); + struct gkyl_array *rho_ho = use_gpu ? mkarr(false, rho->ncomp, rho->size) : + gkyl_array_acquire(rho); + struct gkyl_array *phi_ho = use_gpu ? mkarr(false, phi->ncomp, phi->size) : + gkyl_array_acquire(phi); // Project distribution function on basis. gkyl_proj_on_basis_advance(projob, 0.0, &localRange, rho_ho); - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) { // Fill the ghost cell so we can apply Dirichlet BCs. ghost_from_skin_surf(false, dim, &skin_ghost, &basis, rho_ho); + } gkyl_array_copy(rho, rho_ho); -// // Project a function that is continuous in x but discontinuous in z. -// gkyl_eval_on_nodes *evcont = gkyl_eval_on_nodes_new(&grid, &basis, -// 1, evalFunc2x_xcont, NULL); -// gkyl_proj_on_basis *projdiscont = gkyl_proj_on_basis_new(&grid, &basis, -// poly_order+1, 1, evalFunc2x_ydiscont, NULL); -// gkyl_eval_on_nodes_advance(evcont, 0.0, &localRange, rho_ho); -// gkyl_proj_on_basis_advance(projdiscont, 0.0, &localRange, phi_ho); -// gkyl_proj_on_basis_release(projdiscont); -// gkyl_eval_on_nodes_release(evcont); -// gkyl_dg_mul_op(basis, 0, rho_ho, 0, phi_ho, 0, rho_ho); -// gkyl_array_copy(rho, rho_ho); + // // Project a function that is continuous in x but discontinuous in z. + // gkyl_eval_on_nodes *evcont = gkyl_eval_on_nodes_new(&grid, &basis, + // 1, evalFunc2x_xcont, NULL); + // gkyl_proj_on_basis *projdiscont = gkyl_proj_on_basis_new(&grid, &basis, + // poly_order+1, 1, evalFunc2x_ydiscont, NULL); + // gkyl_eval_on_nodes_advance(evcont, 0.0, &localRange, rho_ho); + // gkyl_proj_on_basis_advance(projdiscont, 0.0, &localRange, phi_ho); + // gkyl_proj_on_basis_release(projdiscont); + // gkyl_eval_on_nodes_release(evcont); + // gkyl_dg_mul_op(basis, 0, rho_ho, 0, phi_ho, 0, rho_ho); + // gkyl_array_copy(rho, rho_ho); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_2x_p1_rho_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_2x_p1_rho_1.gkyl"); // Parallel FEM projection method. - struct gkyl_fem_parproj *parproj = gkyl_fem_parproj_new(&localRange, &grid, &basis, - bctype, 0, 0, 0, use_gpu); + struct gkyl_fem_parproj *parproj = + gkyl_fem_parproj_new(&localRange, &grid, &basis, bctype, 0, 0, 0, use_gpu); // Set the RHS source. gkyl_fem_parproj_set_rhs(parproj, rho, rho); @@ -684,15 +746,16 @@ test_2x(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) gkyl_array_copy(phi_ho, phi); if (bctype == GKYL_FEM_PARPROJ_PERIODIC) { - struct gkyl_array *parbuff = mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim-1].volume); - apply_periodic_bc(parbuff, phi_ho, dim-1, skin_ghost); + struct gkyl_array *parbuff = + mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim - 1].volume); + apply_periodic_bc(parbuff, phi_ho, dim - 1, skin_ghost); gkyl_array_release(parbuff); } -// gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_2x_p1_phi_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_2x_p1_phi_1.gkyl"); // Check continuity at cell boundaries. check_continuity_par(localRange, basis, phi_ho); -// check_continuity_perp(localRange, basis, phi_ho); + // check_continuity_perp(localRange, basis, phi_ho); if (poly_order == 1) { if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) { @@ -701,60 +764,63 @@ test_2x(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) // Solution (checked continuity manually): const double sol[48] = { // idx = [0,:] - -4.2253125086607479e-04, -4.2252954845312053e-04, - -2.1170042428951191e-04, -2.1169957133119468e-04, - -3.9460357085969891e-04, -3.9460198096965074e-04, - 2.2782447785903476e-04, 2.2782355993558733e-04, - 3.9460357085969891e-04, 3.9460198096965057e-04, - 2.2782447785903476e-04, 2.2782355993558747e-04, - 4.2253125086607485e-04, 4.2252954845312059e-04, - -2.1170042428951191e-04, -2.1169957133119463e-04, + -4.2253125086607479e-04, -4.2252954845312053e-04, -2.1170042428951191e-04, + -2.1169957133119468e-04, -3.9460357085969891e-04, -3.9460198096965074e-04, + 2.2782447785903476e-04, 2.2782355993558733e-04, 3.9460357085969891e-04, + 3.9460198096965057e-04, 2.2782447785903476e-04, 2.2782355993558747e-04, + 4.2253125086607485e-04, 4.2252954845312059e-04, -2.1170042428951191e-04, + -2.1169957133119463e-04, // idx = [1,:] - -6.2761887708076181e-01, -4.3547064325365575e-01, - -3.1445527945628282e-01, -2.1818343555290270e-01, - -5.8613569890365669e-01, -4.0668771950060645e-01, - 3.3840560354367566e-01, 2.3480126432979020e-01, - 5.8613569890365669e-01, 4.0668771950060634e-01, - 3.3840560354367566e-01, 2.3480126432979012e-01, - 6.2761887708076181e-01, 4.3547064325365564e-01, - -3.1445527945628282e-01, -2.1818343555290265e-01, + -6.2761887708076181e-01, -4.3547064325365575e-01, -3.1445527945628282e-01, + -2.1818343555290270e-01, -5.8613569890365669e-01, -4.0668771950060645e-01, + 3.3840560354367566e-01, 2.3480126432979020e-01, 5.8613569890365669e-01, + 4.0668771950060634e-01, 3.3840560354367566e-01, 2.3480126432979012e-01, + 6.2761887708076181e-01, 4.3547064325365564e-01, -3.1445527945628282e-01, + -2.1818343555290265e-01, // idx = [2,:] - -2.8612000924778641e-02, 2.8608472382826922e-02, - -1.4335443172858760e-02, 1.4333675270894658e-02, - -2.6720858424593201e-02, 2.6717563105605024e-02, - 1.5427294804416765e-02, -1.5425392251111881e-02, - 2.6720858424593201e-02, -2.6717563105605024e-02, - 1.5427294804416765e-02, -1.5425392251111872e-02, - 2.8612000924778638e-02, -2.8608472382826912e-02, - -1.4335443172858762e-02, 1.4333675270894653e-02, + -2.8612000924778641e-02, 2.8608472382826922e-02, -1.4335443172858760e-02, + 1.4333675270894658e-02, -2.6720858424593201e-02, 2.6717563105605024e-02, + 1.5427294804416765e-02, -1.5425392251111881e-02, 2.6720858424593201e-02, + -2.6717563105605024e-02, 1.5427294804416765e-02, -1.5425392251111872e-02, + 2.8612000924778638e-02, -2.8608472382826912e-02, -1.4335443172858762e-02, + 1.4333675270894653e-02 }; - for (int k=0; kncomp, rho->size) : gkyl_array_acquire(rho); - struct gkyl_array *phi_ho = use_gpu? mkarr(false, phi->ncomp, phi->size) : gkyl_array_acquire(phi); + struct gkyl_array *rho_ho = use_gpu ? mkarr(false, rho->ncomp, rho->size) : + gkyl_array_acquire(rho); + struct gkyl_array *phi_ho = use_gpu ? mkarr(false, phi->ncomp, phi->size) : + gkyl_array_acquire(phi); // Project distribution function on basis. gkyl_proj_on_basis_advance(projob, 0.0, &localRange, rho_ho); - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) { // Fill the ghost cell so we can apply Dirichlet BCs. ghost_from_skin_surf(false, dim, &skin_ghost, &basis, rho_ho); + } gkyl_array_copy(rho, rho_ho); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_2x_p1_bias_rho_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_2x_p1_bias_rho_1.gkyl"); // Specify the bias: struct gkyl_poisson_bias_line bias[] = { {.perp_dirs = {0, 1}, .perp_coords = {-2., -0.5}, // Location of the plane in the 'dir' dimension. - .val = 0.,}, // Biasing value. + .val = 0.}, // Biasing value. {.perp_dirs = {0, 1}, - .perp_coords = {-2+2*4.0/3.0, 0.5}, // Location of the plane in the 'dir' dimension. - .val = 0.,}, // Biasing value. + .perp_coords = {-2 + 2 * 4.0 / 3.0, 0.5}, // Location of the plane in the 'dir' dimension. + .val = 0.} // Biasing value. }; struct gkyl_poisson_bias_line_list bll = { - .num_bias_line = sizeof(bias)/sizeof(bias[0]), // Number of bias lines. - .bl = bias, + .num_bias_line = sizeof(bias) / sizeof(bias[0]), // Number of bias lines. + .bl = bias }; // Parallel FEM projection method. - struct gkyl_fem_parproj *parproj = gkyl_fem_parproj_new(&localRange, &grid, &basis, - bctype, &bll, 0, 0, use_gpu); + struct gkyl_fem_parproj *parproj = + gkyl_fem_parproj_new(&localRange, &grid, &basis, bctype, &bll, 0, 0, use_gpu); // Set the RHS source. gkyl_fem_parproj_set_rhs(parproj, rho, rho); @@ -1077,11 +1139,12 @@ test_2x_bias(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) gkyl_array_copy(phi_ho, phi); if (bctype == GKYL_FEM_PARPROJ_PERIODIC) { - struct gkyl_array *parbuff = mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim-1].volume); - apply_periodic_bc(parbuff, phi_ho, dim-1, skin_ghost); + struct gkyl_array *parbuff = + mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim - 1].volume); + apply_periodic_bc(parbuff, phi_ho, dim - 1, skin_ghost); gkyl_array_release(parbuff); } -// gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_2x_p1_bias_phi_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_2x_p1_bias_phi_1.gkyl"); // Check continuity at cell boundaries. check_continuity_par(localRange, basis, phi_ho); @@ -1096,29 +1159,28 @@ test_2x_bias(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) gkyl_array_release(phi); gkyl_array_release(rho_ho); gkyl_array_release(phi_ho); - } -void evalWeight2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalWeight2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; double mu = 0.0; double sig = 0.3; double Lx = 4.0; - fout[0] = cos((2.*M_PI/(2*Lx))*x); - if (y < 0.0) - fout[0] *= exp(-(pow(y-mu,2))/(2.0*pow(sig,2))); - else - fout[0] *= 3.0*exp(-(pow(y-mu,2))/(2.0*pow(sig,2))); + fout[0] = cos((2. * M_PI / (2 * Lx)) * x); + if (y < 0.0) { + fout[0] *= exp(-(pow(y - mu, 2)) / (2.0 * pow(sig, 2))); + } else { + fout[0] *= 3.0 * exp(-(pow(y - mu, 2)) / (2.0 * pow(sig, 2))); + } } -void -test_2x_weighted(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) +void test_2x_weighted(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) { double lower[] = {-2., -0.5}, upper[] = {2., 0.5}; int cells[] = {3, 4}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // grids. struct gkyl_rect_grid grid; @@ -1128,7 +1190,7 @@ test_2x_weighted(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_ struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct skin_ghost_ranges skin_ghost; // skin/ghost. @@ -1141,35 +1203,41 @@ test_2x_weighted(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_ // Weight in the projection operation. struct gkyl_array *jac = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *rho_ho = use_gpu? mkarr(false, rho->ncomp, rho->size) : gkyl_array_acquire(rho); - struct gkyl_array *phi_ho = use_gpu? mkarr(false, phi->ncomp, phi->size) : gkyl_array_acquire(phi); - struct gkyl_array *jac_ho = use_gpu? mkarr(false, jac->ncomp, jac->size) : gkyl_array_acquire(jac); + struct gkyl_array *rho_ho = use_gpu ? mkarr(false, rho->ncomp, rho->size) : + gkyl_array_acquire(rho); + struct gkyl_array *phi_ho = use_gpu ? mkarr(false, phi->ncomp, phi->size) : + gkyl_array_acquire(phi); + struct gkyl_array *jac_ho = use_gpu ? mkarr(false, jac->ncomp, jac->size) : + gkyl_array_acquire(jac); // Project distribution function on basis. - gkyl_proj_on_basis *projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, - bctype==GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype==GKYL_FEM_PARPROJ_DIRICHLET_SKIN? evalFunc2x_dirichlet : evalFunc2x, - NULL); + gkyl_proj_on_basis *projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, + bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN ? + evalFunc2x_dirichlet : + evalFunc2x, + NULL + ); gkyl_proj_on_basis_advance(projob, 0.0, &localRange, rho_ho); - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) { // Fill the ghost cell so we can apply Dirichlet BCs. ghost_from_skin_surf(false, dim, &skin_ghost, &basis, rho_ho); + } gkyl_array_copy(rho, rho_ho); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_2x_p1_rho_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_2x_p1_rho_1.gkyl"); // Project the weight onto the basis. - gkyl_eval_on_nodes *proj_weight = gkyl_eval_on_nodes_new(&grid, &basis, - 1, evalWeight2x, NULL); + gkyl_eval_on_nodes *proj_weight = gkyl_eval_on_nodes_new(&grid, &basis, 1, evalWeight2x, NULL); gkyl_eval_on_nodes_advance(proj_weight, 0.0, &localRange, jac_ho); gkyl_array_copy(jac, jac_ho); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, jac_ho, "ctest_fem_parproj_2x_p1_jac_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, jac_ho, "ctest_fem_parproj_2x_p1_jac_1.gkyl"); // Parallel FEM projection method. - struct gkyl_fem_parproj *parproj = gkyl_fem_parproj_new(&localRange, &grid, &basis, - bctype, 0, jac, jac, use_gpu); + struct gkyl_fem_parproj *parproj = + gkyl_fem_parproj_new(&localRange, &grid, &basis, bctype, 0, jac, jac, use_gpu); // Set the RHS source. gkyl_fem_parproj_set_rhs(parproj, rho, rho); @@ -1179,17 +1247,19 @@ test_2x_weighted(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_ gkyl_array_copy(phi_ho, phi); if (bctype == GKYL_FEM_PARPROJ_PERIODIC) { - struct gkyl_array *parbuff = mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim-1].volume); - apply_periodic_bc(parbuff, phi_ho, dim-1, skin_ghost); + struct gkyl_array *parbuff = + mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim - 1].volume); + apply_periodic_bc(parbuff, phi_ho, dim - 1, skin_ghost); gkyl_array_release(parbuff); } -// gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_2x_p1_phi_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_2x_p1_phi_1.gkyl"); // Check that the field is continuous. check_continuity_par(localRange, basis, phi_ho); - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) { check_dirichlet_bc(localRange, localRange_ext, basis, bctype, rho_ho, phi_ho); + } gkyl_fem_parproj_release(parproj); gkyl_proj_on_basis_release(projob); @@ -1200,31 +1270,29 @@ test_2x_weighted(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_ gkyl_array_release(rho_ho); gkyl_array_release(phi_ho); gkyl_array_release(jac_ho); - } -void evalFunc2x_selfadjoint(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_selfadjoint(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; double mu = .2; double sig = 0.3; - fout[0] = exp(-(pow(x-mu,2))/(2.0*sig*sig))*(2.0+cos(2.*M_PI*y)); + fout[0] = exp(-(pow(x - mu, 2)) / (2.0 * sig * sig)) * (2.0 + cos(2. * M_PI * y)); } -void evalGunc2x_selfadjoint(double t, const double *xn, double* restrict fout, void *ctx) +void evalGunc2x_selfadjoint(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; double mu = .1; double sig = 0.4; - fout[0] = exp(-(pow(x-mu,2))/(2.0*sig*sig))*(2.0+y*y); + fout[0] = exp(-(pow(x - mu, 2)) / (2.0 * sig * sig)) * (2.0 + y * y); } -void -test_2x_selfadjoint(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) +void test_2x_selfadjoint(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) { // Check that the operator is self-adjoint. double lower[] = {-2., -0.5}, upper[] = {2., 0.5}; int cells[] = {3, 4}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // grids. struct gkyl_rect_grid grid; @@ -1234,7 +1302,7 @@ test_2x_selfadjoint(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool u struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct skin_ghost_ranges skin_ghost; // skin/ghost. @@ -1248,61 +1316,67 @@ test_2x_selfadjoint(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool u struct gkyl_array *rho_fem = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); struct gkyl_array *phi_fem = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *rho_ho = use_gpu? mkarr(false, rho_dg->ncomp, rho_dg->size) : gkyl_array_acquire(rho_dg); - struct gkyl_array *phi_ho = use_gpu? mkarr(false, phi_dg->ncomp, phi_dg->size) : gkyl_array_acquire(phi_dg); + struct gkyl_array *rho_ho = use_gpu ? mkarr(false, rho_dg->ncomp, rho_dg->size) : + gkyl_array_acquire(rho_dg); + struct gkyl_array *phi_ho = use_gpu ? mkarr(false, phi_dg->ncomp, phi_dg->size) : + gkyl_array_acquire(phi_dg); // Project fields onto basis. - gkyl_proj_on_basis *projob_rho = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc2x_selfadjoint, NULL); + gkyl_proj_on_basis *projob_rho = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc2x_selfadjoint, NULL); gkyl_proj_on_basis_advance(projob_rho, 0.0, &localRange, rho_ho); gkyl_proj_on_basis_release(projob_rho); gkyl_array_copy(rho_dg, rho_ho); - gkyl_proj_on_basis *projob_phi = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalGunc2x_selfadjoint, NULL); + gkyl_proj_on_basis *projob_phi = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalGunc2x_selfadjoint, NULL); gkyl_proj_on_basis_advance(projob_phi, 0.0, &localRange, phi_ho); gkyl_proj_on_basis_release(projob_phi); gkyl_array_copy(phi_dg, phi_ho); // Parallel FEM projection method. - struct gkyl_fem_parproj *parproj = gkyl_fem_parproj_new(&localRange, &grid, &basis, - bctype, 0, 0, 0, use_gpu); + struct gkyl_fem_parproj *parproj = + gkyl_fem_parproj_new(&localRange, &grid, &basis, bctype, 0, 0, 0, use_gpu); - struct gkyl_array_integrate* arr_int_op = gkyl_array_integrate_new(&grid, &basis, 1, GKYL_ARRAY_INTEGRATE_OP_NONE, use_gpu); + struct gkyl_array_integrate *arr_int_op = + gkyl_array_integrate_new(&grid, &basis, 1, GKYL_ARRAY_INTEGRATE_OP_NONE, use_gpu); // Smooth rho_dg and integrate phi_dg*rho_fem. gkyl_fem_parproj_set_rhs(parproj, rho_dg, rho_dg); gkyl_fem_parproj_solve(parproj, rho_fem); gkyl_dg_mul_op(&basis, 0, prod, 0, phi_dg, 0, rho_fem); - double *int_prodA = use_gpu? gkyl_cu_malloc(sizeof(double)) : gkyl_malloc(sizeof(double)); + double *int_prodA = use_gpu ? gkyl_cu_malloc(sizeof(double)) : gkyl_malloc(sizeof(double)); gkyl_array_integrate_advance(arr_int_op, prod, 1.0, 0, &localRange, 0, int_prodA); double int_prodA_ho[1]; - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(int_prodA_ho, int_prodA, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(int_prodA_ho, int_prodA, sizeof(double)); + } // Smooth phi_dg and integrate phi_fem*rho_dg. gkyl_fem_parproj_set_rhs(parproj, phi_dg, phi_dg); gkyl_fem_parproj_solve(parproj, phi_fem); gkyl_dg_mul_op(&basis, 0, prod, 0, phi_fem, 0, rho_dg); - double *int_prodB = use_gpu? gkyl_cu_malloc(sizeof(double)) : gkyl_malloc(sizeof(double)); + double *int_prodB = use_gpu ? gkyl_cu_malloc(sizeof(double)) : gkyl_malloc(sizeof(double)); gkyl_array_integrate_advance(arr_int_op, prod, 1.0, 0, &localRange, 0, int_prodB); double int_prodB_ho[1]; - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(int_prodB_ho, int_prodB, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(int_prodB_ho, int_prodB, sizeof(double)); + } - TEST_CHECK( gkyl_compare(int_prodA_ho[0],int_prodB_ho[0], 1e-14) ); - TEST_MSG("int phi_dg*rho_fem = %.13e | int phi_fem*rho_dg = %.13e", int_prodA_ho[0],int_prodB_ho[0]); -// printf("\nint phi_dg*rho_fem = %.13e | int phi_fem*rho_dg = %.13e\n", int_prodA_ho[0],int_prodB_ho[0]); + TEST_CHECK(gkyl_compare(int_prodA_ho[0], int_prodB_ho[0], 1e-14)); + TEST_MSG( + "int phi_dg*rho_fem = %.13e | int phi_fem*rho_dg = %.13e", int_prodA_ho[0], int_prodB_ho[0] + ); + // printf("\nint phi_dg*rho_fem = %.13e | int phi_fem*rho_dg = %.13e\n", int_prodA_ho[0],int_prodB_ho[0]); if (use_gpu) { gkyl_cu_free(int_prodA); gkyl_cu_free(int_prodB); - } - else { + } else { gkyl_free(int_prodA); gkyl_free(int_prodB); } @@ -1315,31 +1389,29 @@ test_2x_selfadjoint(int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool u gkyl_array_release(phi_fem); gkyl_array_release(rho_ho); gkyl_array_release(phi_ho); - } -void evalFunc3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc3x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; double mu[2] = {.2, 0.2}; double sig = 0.3; - fout[0] = exp(-(pow(x-mu[0],2)+pow(y-mu[1],2))/(2.0*sig*sig))*sin(2.*M_PI*z); + fout[0] = exp(-(pow(x - mu[0], 2) + pow(y - mu[1], 2)) / (2.0 * sig * sig)) * sin(2. * M_PI * z); } -void evalFunc3x_dirichlet(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc3x_dirichlet(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; double mu[2] = {.2, 0.2}; double sig = 0.3; - fout[0] = exp(-(pow(x-mu[0],2)+pow(y-mu[1],2))/(2.0*sig*sig))*cos(2.*M_PI*z); + fout[0] = exp(-(pow(x - mu[0], 2) + pow(y - mu[1], 2)) / (2.0 * sig * sig)) * cos(2. * M_PI * z); } -void -test_3x(const int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) +void test_3x(const int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu) { double lower[] = {-2., -2., -0.5}, upper[] = {2., 2., 0.5}; int cells[] = {3, 3, 4}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // grids. struct gkyl_rect_grid grid; @@ -1349,40 +1421,46 @@ test_3x(const int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1, 1}; + int ghost[] = {1, 1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct skin_ghost_ranges skin_ghost; // skin/ghost. skin_ghost_ranges_init(&skin_ghost, &localRange_ext, ghost); // projection updater for DG field. - gkyl_proj_on_basis *projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, - bctype==GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype==GKYL_FEM_PARPROJ_DIRICHLET_SKIN? evalFunc3x_dirichlet : evalFunc3x, - NULL); + gkyl_proj_on_basis *projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, + bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN ? + evalFunc3x_dirichlet : + evalFunc3x, + NULL + ); // create DG field we wish to make continuous. struct gkyl_array *rho = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); // create array holding continuous field we'll compute. struct gkyl_array *phi = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *rho_ho = use_gpu? mkarr(false, rho->ncomp, rho->size) : gkyl_array_acquire(rho); - struct gkyl_array *phi_ho = use_gpu? mkarr(false, phi->ncomp, phi->size) : gkyl_array_acquire(phi); + struct gkyl_array *rho_ho = use_gpu ? mkarr(false, rho->ncomp, rho->size) : + gkyl_array_acquire(rho); + struct gkyl_array *phi_ho = use_gpu ? mkarr(false, phi->ncomp, phi->size) : + gkyl_array_acquire(phi); // project distribution function on basis. gkyl_proj_on_basis_advance(projob, 0.0, &localRange, rho_ho); - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) { // Fill the ghost cell so we can apply Dirichlet BCs. ghost_from_skin_surf(false, dim, &skin_ghost, &basis, rho_ho); + } gkyl_array_copy(rho, rho_ho); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_3x_p2_rho_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_3x_p2_rho_1.gkyl"); // parallel FEM projection method. - struct gkyl_fem_parproj *parproj = gkyl_fem_parproj_new(&localRange, &grid, &basis, - bctype, 0, 0, 0, use_gpu); + struct gkyl_fem_parproj *parproj = + gkyl_fem_parproj_new(&localRange, &grid, &basis, bctype, 0, 0, 0, use_gpu); // Set the RHS source. gkyl_fem_parproj_set_rhs(parproj, rho, rho); @@ -1392,11 +1470,12 @@ test_3x(const int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu gkyl_array_copy(phi_ho, phi); if (bctype == GKYL_FEM_PARPROJ_PERIODIC) { - struct gkyl_array *parbuff = mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim-1].volume); - apply_periodic_bc(parbuff, phi_ho, dim-1, skin_ghost); + struct gkyl_array *parbuff = + mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim - 1].volume); + apply_periodic_bc(parbuff, phi_ho, dim - 1, skin_ghost); gkyl_array_release(parbuff); } -// gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_3x_p1_phi_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_3x_p1_phi_1.gkyl"); // Check continuity at cell boundaries. check_continuity_par(localRange, basis, phi_ho); @@ -1409,83 +1488,78 @@ test_3x(const int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool use_gpu // and checked that visually looks like results in g2): const double sol[96] = { // idx = [0,1,:] - -2.9175130738000619e-04, -2.9175013189013625e-04, - -2.0243038272814358e-04, -1.4617587558971766e-04, - -2.0242956711958172e-04, -1.4617528663516419e-04, - -1.0142349903065383e-04, -1.0142309038708445e-04, - -2.7246767537113221e-04, -2.7246657757659220e-04, - -1.8905051806532438e-04, 1.5730928572099475e-04, - -1.8904975636533129e-04, 1.5730865190902163e-04, - 1.0914836749545332e-04, 1.0914792772775724e-04, - 2.7246767537113210e-04, 2.7246657757659220e-04, - 1.8905051806532432e-04, 1.5730928572099478e-04, - 1.8904975636533134e-04, 1.5730865190902163e-04, - 1.0914836749545326e-04, 1.0914792772775718e-04, - 2.9175130738000619e-04, 2.9175013189013631e-04, - 2.0243038272814358e-04, -1.4617587558971761e-04, - 2.0242956711958167e-04, -1.4617528663516419e-04, + -2.9175130738000619e-04, -2.9175013189013625e-04, -2.0243038272814358e-04, + -1.4617587558971766e-04, -2.0242956711958172e-04, -1.4617528663516419e-04, + -1.0142349903065383e-04, -1.0142309038708445e-04, -2.7246767537113221e-04, + -2.7246657757659220e-04, -1.8905051806532438e-04, 1.5730928572099475e-04, + -1.8904975636533129e-04, 1.5730865190902163e-04, 1.0914836749545332e-04, + 1.0914792772775724e-04, 2.7246767537113210e-04, 2.7246657757659220e-04, + 1.8905051806532432e-04, 1.5730928572099478e-04, 1.8904975636533134e-04, + 1.5730865190902163e-04, 1.0914836749545326e-04, 1.0914792772775718e-04, + 2.9175130738000619e-04, 2.9175013189013631e-04, 2.0243038272814358e-04, + -1.4617587558971761e-04, 2.0242956711958167e-04, -1.4617528663516419e-04, -1.0142349903065386e-04, -1.0142309038708456e-04, // idx = [1,0,:] - -2.9175130738000619e-04, -2.0243038272814342e-04, - -2.9175013189013631e-04, -1.4617587558971766e-04, - -2.0242956711958167e-04, -1.0142349903065388e-04, - -1.4617528663516419e-04, -1.0142309038708458e-04, - -2.7246767537113221e-04, -1.8905051806532432e-04, - -2.7246657757659220e-04, 1.5730928572099475e-04, - -1.8904975636533140e-04, 1.0914836749545325e-04, - 1.5730865190902168e-04, 1.0914792772775730e-04, - 2.7246767537113210e-04, 1.8905051806532430e-04, - 2.7246657757659220e-04, 1.5730928572099478e-04, - 1.8904975636533134e-04, 1.0914836749545328e-04, - 1.5730865190902160e-04, 1.0914792772775720e-04, - 2.9175130738000625e-04, 2.0243038272814347e-04, - 2.9175013189013631e-04, -1.4617587558971761e-04, - 2.0242956711958167e-04, -1.0142349903065384e-04, + -2.9175130738000619e-04, -2.0243038272814342e-04, -2.9175013189013631e-04, + -1.4617587558971766e-04, -2.0242956711958167e-04, -1.0142349903065388e-04, + -1.4617528663516419e-04, -1.0142309038708458e-04, -2.7246767537113221e-04, + -1.8905051806532432e-04, -2.7246657757659220e-04, 1.5730928572099475e-04, + -1.8904975636533140e-04, 1.0914836749545325e-04, 1.5730865190902168e-04, + 1.0914792772775730e-04, 2.7246767537113210e-04, 1.8905051806532430e-04, + 2.7246657757659220e-04, 1.5730928572099478e-04, 1.8904975636533134e-04, + 1.0914836749545328e-04, 1.5730865190902160e-04, 1.0914792772775720e-04, + 2.9175130738000625e-04, 2.0243038272814347e-04, 2.9175013189013631e-04, + -1.4617587558971761e-04, 2.0242956711958167e-04, -1.0142349903065384e-04, -1.4617528663516416e-04, -1.0142309038708461e-04, // idx = [1,2,:] - -1.9756145041229078e-02, -1.3707715786581542e-02, - 1.9753708637470873e-02, -9.8984022577751872e-03, - 1.3706025298371970e-02, -6.8679635934884792e-03, - 9.8971815487547514e-03, 6.8671166098145447e-03, - -1.8450340332725093e-02, -1.2801688837518459e-02, - 1.8448064965823664e-02, 1.0652308957739044e-02, - 1.2800110084035459e-02, 7.3910584964231056e-03, - -1.0650995274046001e-02, -7.3901470026747126e-03, - 1.8450340332725097e-02, 1.2801688837518463e-02, - -1.8448064965823671e-02, 1.0652308957739044e-02, - -1.2800110084035459e-02, 7.3910584964231134e-03, - -1.0650995274045996e-02, -7.3901470026747221e-03, - 1.9756145041229078e-02, 1.3707715786581542e-02, - -1.9753708637470870e-02, -9.8984022577751907e-03, - -1.3706025298371980e-02, -6.8679635934884914e-03, - 9.8971815487547583e-03, 6.8671166098145560e-03}; - for (int k=0; kncomp, rho->size) : gkyl_array_acquire(rho); - struct gkyl_array *phi_ho = use_gpu? mkarr(false, phi->ncomp, phi->size) : gkyl_array_acquire(phi); + struct gkyl_array *rho_ho = use_gpu ? mkarr(false, rho->ncomp, rho->size) : + gkyl_array_acquire(rho); + struct gkyl_array *phi_ho = use_gpu ? mkarr(false, phi->ncomp, phi->size) : + gkyl_array_acquire(phi); // project distribution function on basis. gkyl_proj_on_basis_advance(projob, 0.0, &localRange, rho_ho); - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) { // Fill the ghost cell so we can apply Dirichlet BCs. ghost_from_skin_surf(false, dim, &skin_ghost, &basis, rho_ho); + } gkyl_array_copy(rho, rho_ho); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_3x_p1_bias_rho_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_parproj_3x_p1_bias_rho_1.gkyl"); // Specify the bias: struct gkyl_poisson_bias_line bias[] = { {.perp_dirs = {0, 2}, .perp_coords = {-2., -0.5}, // Location of the plane in the 'dir' dimension. - .val = 0.,}, // Biasing value. + .val = 0.}, // Biasing value. {.perp_dirs = {0, 2}, - .perp_coords = {-2+2*4.0/3.0, 0.5}, // Location of the plane in the 'dir' dimension. - .val = 0.,}, // Biasing value. + .perp_coords = {-2 + 2 * 4.0 / 3.0, 0.5}, // Location of the plane in the 'dir' dimension. + .val = 0.} // Biasing value. }; struct gkyl_poisson_bias_line_list bll = { - .num_bias_line = sizeof(bias)/sizeof(bias[0]), // Number of bias lines. - .bl = bias, + .num_bias_line = sizeof(bias) / sizeof(bias[0]), // Number of bias lines. + .bl = bias }; // parallel FEM projection method. - struct gkyl_fem_parproj *parproj = gkyl_fem_parproj_new(&localRange, &grid, &basis, - bctype, &bll, 0, 0, use_gpu); + struct gkyl_fem_parproj *parproj = + gkyl_fem_parproj_new(&localRange, &grid, &basis, bctype, &bll, 0, 0, use_gpu); // Set the RHS source. gkyl_fem_parproj_set_rhs(parproj, rho, rho); @@ -1819,11 +1991,12 @@ test_3x_bias(const int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool us gkyl_array_copy(phi_ho, phi); if (bctype == GKYL_FEM_PARPROJ_PERIODIC) { - struct gkyl_array *parbuff = mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim-1].volume); - apply_periodic_bc(parbuff, phi_ho, dim-1, skin_ghost); + struct gkyl_array *parbuff = + mkarr(false, basis.num_basis, skin_ghost.lower_skin[dim - 1].volume); + apply_periodic_bc(parbuff, phi_ho, dim - 1, skin_ghost); gkyl_array_release(parbuff); } -// gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_3x_p1_bias_phi_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_parproj_3x_p1_bias_phi_1.gkyl"); // Check continuity at cell boundaries. check_continuity_par(localRange, basis, phi_ho); @@ -1838,166 +2011,262 @@ test_3x_bias(const int poly_order, enum gkyl_fem_parproj_bc_type bctype, bool us gkyl_array_release(phi); gkyl_array_release(rho_ho); gkyl_array_release(phi_ho); - } -void test_fem_parproj_1x_p1_bcnone_ho() {test_1x(1, GKYL_FEM_PARPROJ_NONE, false);} -void test_fem_parproj_1x_p1_bcdirichlet_ho() { +void test_fem_parproj_1x_p1_bcnone_ho() +{ + test_1x(1, GKYL_FEM_PARPROJ_NONE, false); +} +void test_fem_parproj_1x_p1_bcdirichlet_ho() +{ test_1x(1, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, false); test_1x(1, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, false); } -void test_fem_parproj_1x_p1_bcperiodic_ho() {test_1x(1, GKYL_FEM_PARPROJ_PERIODIC, false);} +void test_fem_parproj_1x_p1_bcperiodic_ho() +{ + test_1x(1, GKYL_FEM_PARPROJ_PERIODIC, false); +} -void test_fem_parproj_1x_p2_bcnone_ho() {test_1x(2, GKYL_FEM_PARPROJ_NONE, false);} -void test_fem_parproj_1x_p2_bcdirichlet_ho() { +void test_fem_parproj_1x_p2_bcnone_ho() +{ + test_1x(2, GKYL_FEM_PARPROJ_NONE, false); +} +void test_fem_parproj_1x_p2_bcdirichlet_ho() +{ test_1x(2, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, false); test_1x(2, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, false); } -void test_fem_parproj_1x_p2_bcperiodic_ho() {test_1x(2, GKYL_FEM_PARPROJ_PERIODIC, false);} +void test_fem_parproj_1x_p2_bcperiodic_ho() +{ + test_1x(2, GKYL_FEM_PARPROJ_PERIODIC, false); +} -void test_fem_parproj_2x_p1_bcnone_ho() {test_2x(1, GKYL_FEM_PARPROJ_NONE, false);} -void test_fem_parproj_2x_p1_bcdirichlet_ho() { +void test_fem_parproj_2x_p1_bcnone_ho() +{ + test_2x(1, GKYL_FEM_PARPROJ_NONE, false); +} +void test_fem_parproj_2x_p1_bcdirichlet_ho() +{ test_2x(1, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, false); test_2x(1, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, false); } -void test_fem_parproj_2x_p1_bcperiodic_ho() {test_2x(1, GKYL_FEM_PARPROJ_PERIODIC, false);} -void test_fem_parproj_2x_p1_weighted_ho() { +void test_fem_parproj_2x_p1_bcperiodic_ho() +{ + test_2x(1, GKYL_FEM_PARPROJ_PERIODIC, false); +} +void test_fem_parproj_2x_p1_weighted_ho() +{ test_2x_weighted(1, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, false); test_2x_weighted(1, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, false); } -void test_fem_parproj_2x_p1_selfadjoint_ho() {test_2x_selfadjoint(1, GKYL_FEM_PARPROJ_NONE, false);} -void test_fem_parproj_2x_p1_bcdirichlet_bias_ho() { +void test_fem_parproj_2x_p1_selfadjoint_ho() +{ + test_2x_selfadjoint(1, GKYL_FEM_PARPROJ_NONE, false); +} +void test_fem_parproj_2x_p1_bcdirichlet_bias_ho() +{ test_2x_bias(1, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, false); test_2x_bias(1, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, false); } -void test_fem_parproj_2x_p2_bcnone_ho() {test_2x(2, GKYL_FEM_PARPROJ_NONE, false);} -void test_fem_parproj_2x_p2_bcdirichlet_ho() { +void test_fem_parproj_2x_p2_bcnone_ho() +{ + test_2x(2, GKYL_FEM_PARPROJ_NONE, false); +} +void test_fem_parproj_2x_p2_bcdirichlet_ho() +{ test_2x(2, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, false); test_2x(2, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, false); } -void test_fem_parproj_2x_p2_bcperiodic_ho() {test_2x(2, GKYL_FEM_PARPROJ_PERIODIC, false);} +void test_fem_parproj_2x_p2_bcperiodic_ho() +{ + test_2x(2, GKYL_FEM_PARPROJ_PERIODIC, false); +} -void test_fem_parproj_3x_p1_bcnone_ho() {test_3x(1, GKYL_FEM_PARPROJ_NONE, false);} -void test_fem_parproj_3x_p1_bcdirichlet_ho() { +void test_fem_parproj_3x_p1_bcnone_ho() +{ + test_3x(1, GKYL_FEM_PARPROJ_NONE, false); +} +void test_fem_parproj_3x_p1_bcdirichlet_ho() +{ test_3x(1, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, false); test_3x(1, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, false); } -void test_fem_parproj_3x_p1_bcperiodic_ho() {test_3x(1, GKYL_FEM_PARPROJ_PERIODIC, false);} -void test_fem_parproj_3x_p1_bcdirichlet_bias_ho() { +void test_fem_parproj_3x_p1_bcperiodic_ho() +{ + test_3x(1, GKYL_FEM_PARPROJ_PERIODIC, false); +} +void test_fem_parproj_3x_p1_bcdirichlet_bias_ho() +{ test_3x_bias(1, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, false); test_3x_bias(1, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, false); } -void test_fem_parproj_3x_p2_bcnone_ho() {test_3x(2, GKYL_FEM_PARPROJ_NONE, false);} -void test_fem_parproj_3x_p2_bcdirichlet_ho() { +void test_fem_parproj_3x_p2_bcnone_ho() +{ + test_3x(2, GKYL_FEM_PARPROJ_NONE, false); +} +void test_fem_parproj_3x_p2_bcdirichlet_ho() +{ test_3x(2, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, false); test_3x(2, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, false); } -void test_fem_parproj_3x_p2_bcperiodic_ho() {test_3x(2, GKYL_FEM_PARPROJ_PERIODIC, false);} +void test_fem_parproj_3x_p2_bcperiodic_ho() +{ + test_3x(2, GKYL_FEM_PARPROJ_PERIODIC, false); +} #ifdef GKYL_HAVE_CUDA // ......... GPU tests ............ // -void test_fem_parproj_1x_p1_bcnone_dev() {test_1x(1, GKYL_FEM_PARPROJ_NONE, true);} -void test_fem_parproj_1x_p1_bcdirichlet_dev() { +void test_fem_parproj_1x_p1_bcnone_dev() +{ + test_1x(1, GKYL_FEM_PARPROJ_NONE, true); +} +void test_fem_parproj_1x_p1_bcdirichlet_dev() +{ test_1x(1, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, true); test_1x(1, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, true); } -void test_fem_parproj_1x_p1_bcperiodic_dev() {test_1x(1, GKYL_FEM_PARPROJ_PERIODIC, true);} +void test_fem_parproj_1x_p1_bcperiodic_dev() +{ + test_1x(1, GKYL_FEM_PARPROJ_PERIODIC, true); +} -void test_fem_parproj_1x_p2_bcnone_dev() {test_1x(2, GKYL_FEM_PARPROJ_NONE, true);} -void test_fem_parproj_1x_p2_bcdirichlet_dev() { +void test_fem_parproj_1x_p2_bcnone_dev() +{ + test_1x(2, GKYL_FEM_PARPROJ_NONE, true); +} +void test_fem_parproj_1x_p2_bcdirichlet_dev() +{ test_1x(2, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, true); test_1x(2, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, true); } -void test_fem_parproj_1x_p2_bcperiodic_dev() {test_1x(2, GKYL_FEM_PARPROJ_PERIODIC, true);} +void test_fem_parproj_1x_p2_bcperiodic_dev() +{ + test_1x(2, GKYL_FEM_PARPROJ_PERIODIC, true); +} -void test_fem_parproj_2x_p1_bcnone_dev() {test_2x(1, GKYL_FEM_PARPROJ_NONE, true);} -void test_fem_parproj_2x_p1_bcdirichlet_dev() { +void test_fem_parproj_2x_p1_bcnone_dev() +{ + test_2x(1, GKYL_FEM_PARPROJ_NONE, true); +} +void test_fem_parproj_2x_p1_bcdirichlet_dev() +{ test_2x(1, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, true); test_2x(1, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, true); } -void test_fem_parproj_2x_p1_bcperiodic_dev() {test_2x(1, GKYL_FEM_PARPROJ_PERIODIC, true);} -void test_fem_parproj_2x_p1_weighted_dev() {test_2x_weighted(1, GKYL_FEM_PARPROJ_NONE, true);} -void test_fem_parproj_2x_p1_selfadjoint_dev() {test_2x_selfadjoint(1, GKYL_FEM_PARPROJ_NONE, true);} -void test_fem_parproj_2x_p1_bcdirichlet_bias_dev() { +void test_fem_parproj_2x_p1_bcperiodic_dev() +{ + test_2x(1, GKYL_FEM_PARPROJ_PERIODIC, true); +} +void test_fem_parproj_2x_p1_weighted_dev() +{ + test_2x_weighted(1, GKYL_FEM_PARPROJ_NONE, true); +} +void test_fem_parproj_2x_p1_selfadjoint_dev() +{ + test_2x_selfadjoint(1, GKYL_FEM_PARPROJ_NONE, true); +} +void test_fem_parproj_2x_p1_bcdirichlet_bias_dev() +{ test_2x_bias(1, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, true); test_2x_bias(1, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, true); } -void test_fem_parproj_2x_p2_bcnone_dev() {test_2x(2, GKYL_FEM_PARPROJ_NONE, true);} -void test_fem_parproj_2x_p2_bcdirichlet_dev() { +void test_fem_parproj_2x_p2_bcnone_dev() +{ + test_2x(2, GKYL_FEM_PARPROJ_NONE, true); +} +void test_fem_parproj_2x_p2_bcdirichlet_dev() +{ test_2x(2, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, true); test_2x(2, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, true); } -void test_fem_parproj_2x_p2_bcperiodic_dev() {test_2x(2, GKYL_FEM_PARPROJ_PERIODIC, true);} +void test_fem_parproj_2x_p2_bcperiodic_dev() +{ + test_2x(2, GKYL_FEM_PARPROJ_PERIODIC, true); +} -void test_fem_parproj_3x_p1_bcnone_dev() {test_3x(1, GKYL_FEM_PARPROJ_NONE, true);} -void test_fem_parproj_3x_p1_bcdirichlet_dev() { +void test_fem_parproj_3x_p1_bcnone_dev() +{ + test_3x(1, GKYL_FEM_PARPROJ_NONE, true); +} +void test_fem_parproj_3x_p1_bcdirichlet_dev() +{ test_3x(1, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, true); test_3x(1, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, true); } -void test_fem_parproj_3x_p1_bcperiodic_dev() {test_3x(1, GKYL_FEM_PARPROJ_PERIODIC, true);} -void test_fem_parproj_3x_p1_bcdirichlet_bias_dev() { +void test_fem_parproj_3x_p1_bcperiodic_dev() +{ + test_3x(1, GKYL_FEM_PARPROJ_PERIODIC, true); +} +void test_fem_parproj_3x_p1_bcdirichlet_bias_dev() +{ test_3x_bias(1, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, true); test_3x_bias(1, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, true); } -void test_fem_parproj_3x_p2_bcnone_dev() {test_3x(2, GKYL_FEM_PARPROJ_NONE, true);} -void test_fem_parproj_3x_p2_bcdirichlet_dev() { +void test_fem_parproj_3x_p2_bcnone_dev() +{ + test_3x(2, GKYL_FEM_PARPROJ_NONE, true); +} +void test_fem_parproj_3x_p2_bcdirichlet_dev() +{ test_3x(2, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, true); test_3x(2, GKYL_FEM_PARPROJ_DIRICHLET_SKIN, true); } -void test_fem_parproj_3x_p2_bcperiodic_dev() {test_3x(2, GKYL_FEM_PARPROJ_PERIODIC, true);} +void test_fem_parproj_3x_p2_bcperiodic_dev() +{ + test_3x(2, GKYL_FEM_PARPROJ_PERIODIC, true); +} #endif TEST_LIST = { - { "test_fem_parproj_1x_p1_bcnone_ho", test_fem_parproj_1x_p1_bcnone_ho }, - { "test_fem_parproj_1x_p1_bcdirichlet_ho", test_fem_parproj_1x_p1_bcdirichlet_ho }, - { "test_fem_parproj_1x_p1_bcperiodic_ho", test_fem_parproj_1x_p1_bcperiodic_ho }, - { "test_fem_parproj_1x_p2_bcnone_ho", test_fem_parproj_1x_p2_bcnone_ho }, + {"test_fem_parproj_1x_p1_bcnone_ho", test_fem_parproj_1x_p1_bcnone_ho}, + {"test_fem_parproj_1x_p1_bcdirichlet_ho", test_fem_parproj_1x_p1_bcdirichlet_ho}, + {"test_fem_parproj_1x_p1_bcperiodic_ho", test_fem_parproj_1x_p1_bcperiodic_ho}, + {"test_fem_parproj_1x_p2_bcnone_ho", test_fem_parproj_1x_p2_bcnone_ho}, // { "test_fem_parproj_1x_p2_bcdirichlet_ho", test_fem_parproj_1x_p2_bcdirichlet_ho }, - { "test_fem_parproj_1x_p2_bcperiodic_ho", test_fem_parproj_1x_p2_bcperiodic_ho }, - { "test_fem_parproj_2x_p1_bcnone_ho", test_fem_parproj_2x_p1_bcnone_ho }, - { "test_fem_parproj_2x_p1_bcdirichlet_ho", test_fem_parproj_2x_p1_bcdirichlet_ho }, - { "test_fem_parproj_2x_p1_bcperiodic_ho", test_fem_parproj_2x_p1_bcperiodic_ho }, - { "test_fem_parproj_2x_p2_bcnone_ho", test_fem_parproj_2x_p2_bcnone_ho }, + {"test_fem_parproj_1x_p2_bcperiodic_ho", test_fem_parproj_1x_p2_bcperiodic_ho}, + {"test_fem_parproj_2x_p1_bcnone_ho", test_fem_parproj_2x_p1_bcnone_ho}, + {"test_fem_parproj_2x_p1_bcdirichlet_ho", test_fem_parproj_2x_p1_bcdirichlet_ho}, + {"test_fem_parproj_2x_p1_bcperiodic_ho", test_fem_parproj_2x_p1_bcperiodic_ho}, + {"test_fem_parproj_2x_p2_bcnone_ho", test_fem_parproj_2x_p2_bcnone_ho}, // { "test_fem_parproj_2x_p2_bcdirichlet_ho", test_fem_parproj_2x_p2_bcdirichlet_ho }, - { "test_fem_parproj_2x_p2_bcperiodic_ho", test_fem_parproj_2x_p2_bcperiodic_ho }, - { "test_fem_parproj_2x_p1_weighted_ho", test_fem_parproj_2x_p1_weighted_ho}, - { "test_fem_parproj_2x_p1_selfadjoint_ho", test_fem_parproj_2x_p1_selfadjoint_ho}, - { "test_fem_parproj_2x_p1_bcdirichlet_bias_ho", test_fem_parproj_2x_p1_bcdirichlet_bias_ho }, - { "test_fem_parproj_3x_p1_bcnone_ho", test_fem_parproj_3x_p1_bcnone_ho }, - { "test_fem_parproj_3x_p1_bcdirichlet_ho", test_fem_parproj_3x_p1_bcdirichlet_ho }, - { "test_fem_parproj_3x_p1_bcperiodic_ho", test_fem_parproj_3x_p1_bcperiodic_ho }, - { "test_fem_parproj_3x_p1_bcdirichlet_bias_ho", test_fem_parproj_3x_p1_bcdirichlet_bias_ho }, - { "test_fem_parproj_3x_p2_bcnone_ho", test_fem_parproj_3x_p2_bcnone_ho }, + {"test_fem_parproj_2x_p2_bcperiodic_ho", test_fem_parproj_2x_p2_bcperiodic_ho}, + {"test_fem_parproj_2x_p1_weighted_ho", test_fem_parproj_2x_p1_weighted_ho}, + {"test_fem_parproj_2x_p1_selfadjoint_ho", test_fem_parproj_2x_p1_selfadjoint_ho}, + {"test_fem_parproj_2x_p1_bcdirichlet_bias_ho", test_fem_parproj_2x_p1_bcdirichlet_bias_ho}, + {"test_fem_parproj_3x_p1_bcnone_ho", test_fem_parproj_3x_p1_bcnone_ho}, + {"test_fem_parproj_3x_p1_bcdirichlet_ho", test_fem_parproj_3x_p1_bcdirichlet_ho}, + {"test_fem_parproj_3x_p1_bcperiodic_ho", test_fem_parproj_3x_p1_bcperiodic_ho}, + {"test_fem_parproj_3x_p1_bcdirichlet_bias_ho", test_fem_parproj_3x_p1_bcdirichlet_bias_ho}, + {"test_fem_parproj_3x_p2_bcnone_ho", test_fem_parproj_3x_p2_bcnone_ho}, // { "test_fem_parproj_3x_p2_bcdirichlet_ho", test_fem_parproj_3x_p2_bcdirichlet_ho }, - { "test_fem_parproj_3x_p2_bcperiodic_ho", test_fem_parproj_3x_p2_bcperiodic_ho }, + {"test_fem_parproj_3x_p2_bcperiodic_ho", test_fem_parproj_3x_p2_bcperiodic_ho}, #ifdef GKYL_HAVE_CUDA - { "test_fem_parproj_1x_p1_bcnone_dev", test_fem_parproj_1x_p1_bcnone_dev }, - { "test_fem_parproj_1x_p1_bcdirichlet_dev", test_fem_parproj_1x_p1_bcdirichlet_dev }, - { "test_fem_parproj_1x_p1_bcperiodic_dev", test_fem_parproj_1x_p1_bcperiodic_dev }, - { "test_fem_parproj_1x_p2_bcnone_dev", test_fem_parproj_1x_p2_bcnone_dev }, + {"test_fem_parproj_1x_p1_bcnone_dev", test_fem_parproj_1x_p1_bcnone_dev}, + {"test_fem_parproj_1x_p1_bcdirichlet_dev", test_fem_parproj_1x_p1_bcdirichlet_dev}, + {"test_fem_parproj_1x_p1_bcperiodic_dev", test_fem_parproj_1x_p1_bcperiodic_dev}, + {"test_fem_parproj_1x_p2_bcnone_dev", test_fem_parproj_1x_p2_bcnone_dev}, // { "test_fem_parproj_1x_p2_bcdirichlet_dev", test_fem_parproj_1x_p2_bcdirichlet_dev }, - { "test_fem_parproj_1x_p2_bcperiodic_dev", test_fem_parproj_1x_p2_bcperiodic_dev }, - { "test_fem_parproj_2x_p1_bcnone_dev", test_fem_parproj_2x_p1_bcnone_dev }, - { "test_fem_parproj_2x_p1_bcdirichlet_dev", test_fem_parproj_2x_p1_bcdirichlet_dev }, - { "test_fem_parproj_2x_p1_bcperiodic_dev", test_fem_parproj_2x_p1_bcperiodic_dev }, - { "test_fem_parproj_2x_p2_bcnone_dev", test_fem_parproj_2x_p2_bcnone_dev }, + {"test_fem_parproj_1x_p2_bcperiodic_dev", test_fem_parproj_1x_p2_bcperiodic_dev}, + {"test_fem_parproj_2x_p1_bcnone_dev", test_fem_parproj_2x_p1_bcnone_dev}, + {"test_fem_parproj_2x_p1_bcdirichlet_dev", test_fem_parproj_2x_p1_bcdirichlet_dev}, + {"test_fem_parproj_2x_p1_bcperiodic_dev", test_fem_parproj_2x_p1_bcperiodic_dev}, + {"test_fem_parproj_2x_p2_bcnone_dev", test_fem_parproj_2x_p2_bcnone_dev}, // { "test_fem_parproj_2x_p2_bcdirichlet_dev", test_fem_parproj_2x_p2_bcdirichlet_dev }, - { "test_fem_parproj_2x_p2_bcperiodic_dev", test_fem_parproj_2x_p2_bcperiodic_dev }, - { "test_fem_parproj_2x_p1_weighted_dev", test_fem_parproj_2x_p1_weighted_dev}, - { "test_fem_parproj_2x_p1_selfadjoint_dev", test_fem_parproj_2x_p1_selfadjoint_dev}, - { "test_fem_parproj_2x_p1_bcdirichlet_bias_dev", test_fem_parproj_2x_p1_bcdirichlet_bias_dev }, - { "test_fem_parproj_3x_p1_bcnone_dev", test_fem_parproj_3x_p1_bcnone_dev }, - { "test_fem_parproj_3x_p1_bcdirichlet_dev", test_fem_parproj_3x_p1_bcdirichlet_dev }, - { "test_fem_parproj_3x_p1_bcperiodic_dev", test_fem_parproj_3x_p1_bcperiodic_dev }, - { "test_fem_parproj_3x_p1_bcdirichlet_bias_dev", test_fem_parproj_3x_p1_bcdirichlet_bias_dev }, - { "test_fem_parproj_3x_p2_bcnone_dev", test_fem_parproj_3x_p2_bcnone_dev }, + {"test_fem_parproj_2x_p2_bcperiodic_dev", test_fem_parproj_2x_p2_bcperiodic_dev}, + {"test_fem_parproj_2x_p1_weighted_dev", test_fem_parproj_2x_p1_weighted_dev}, + {"test_fem_parproj_2x_p1_selfadjoint_dev", test_fem_parproj_2x_p1_selfadjoint_dev}, + {"test_fem_parproj_2x_p1_bcdirichlet_bias_dev", test_fem_parproj_2x_p1_bcdirichlet_bias_dev}, + {"test_fem_parproj_3x_p1_bcnone_dev", test_fem_parproj_3x_p1_bcnone_dev}, + {"test_fem_parproj_3x_p1_bcdirichlet_dev", test_fem_parproj_3x_p1_bcdirichlet_dev}, + {"test_fem_parproj_3x_p1_bcperiodic_dev", test_fem_parproj_3x_p1_bcperiodic_dev}, + {"test_fem_parproj_3x_p1_bcdirichlet_bias_dev", test_fem_parproj_3x_p1_bcdirichlet_bias_dev}, + {"test_fem_parproj_3x_p2_bcnone_dev", test_fem_parproj_3x_p2_bcnone_dev}, // { "test_fem_parproj_3x_p2_bcdirichlet_dev", test_fem_parproj_3x_p2_bcdirichlet_dev }, - { "test_fem_parproj_3x_p2_bcperiodic_dev", test_fem_parproj_3x_p2_bcperiodic_dev }, + {"test_fem_parproj_3x_p2_bcperiodic_dev", test_fem_parproj_3x_p2_bcperiodic_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; - diff --git a/gyrokinetic/unit/ctest_fem_poisson_perp.c b/gyrokinetic/unit/ctest_fem_poisson_perp.c index 88da795804..265b535720 100644 --- a/gyrokinetic/unit/ctest_fem_poisson_perp.c +++ b/gyrokinetic/unit/ctest_fem_poisson_perp.c @@ -18,8 +18,10 @@ #include //#include -static double error_L2norm(struct gkyl_rect_grid grid, struct gkyl_range range, - struct gkyl_basis basis, struct gkyl_array* field1, struct gkyl_array* field2) +static double error_L2norm( + struct gkyl_rect_grid grid, struct gkyl_range range, struct gkyl_basis basis, + struct gkyl_array *field1, struct gkyl_array *field2 +) { // Compute the L2 norm of the difference between 2 fields. assert(field1->ncomp == field2->ncomp); @@ -41,12 +43,11 @@ static double error_L2norm(struct gkyl_rect_grid grid, struct gkyl_range range, return sqrt(l2[0]); } -static struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { // allocate array (filled with zeros) - struct gkyl_array* a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } @@ -54,10 +55,10 @@ double poly_test_func_1x(double x, double a, double *c) { // Function that can be used to produce homogeneous Dirichlet or Neumann // boundary values depending on the choice of a and c. It assumes x \in [0,1]. - return pow(x,2)/2.-a*pow(x,4)/12.+c[0]*x+c[1]; + return pow(x, 2) / 2. - a * pow(x, 4) / 12. + c[0] * x + c[1]; } -void evalFunc_consteps_periodicx_sol_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_periodicx_sol_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], z = xn[1]; // These values have to match those in the test below. @@ -65,18 +66,18 @@ void evalFunc_consteps_periodicx_sol_2x(double t, const double *xn, double* rest double amn[] = {0., 10., 10.}; double bmn[] = {0., 10., 10.}; fout[0] = 0.; - for (int m=1; m<4; m++) { - double a = amn[m-1]; - double b = bmn[m-1]; - double t1 = a*cos(m*x); - double t2 = b*sin(m*x); - fout[0] += t1+t2; + for (int m = 1; m < 4; m++) { + double a = amn[m - 1]; + double b = bmn[m - 1]; + double t1 = a * cos(m * x); + double t2 = b * sin(m * x); + fout[0] += t1 + t2; } double kz = 1.; - fout[0] *= (1.+kz*z); -// fout[0] *= (1.+kz*z+0.5*pow(z,2)); + fout[0] *= (1. + kz * z); + // fout[0] *= (1.+kz*z+0.5*pow(z,2)); } -void evalFunc_consteps_periodicx_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_periodicx_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], z = xn[1]; // These values have to match those in the test below. @@ -84,83 +85,93 @@ void evalFunc_consteps_periodicx_2x(double t, const double *xn, double* restrict double amn[] = {0., 10., 10.}; double bmn[] = {0., 10., 10.}; fout[0] = 0.; - for (int m=1; m<4; m++) { - double a = amn[m-1]; - double b = bmn[m-1]; - double t1 = a*gxx*pow(m,2)*cos(m*x); - double t2 = b*gxx*pow(m,2)*sin(m*x); - fout[0] += t1+t2; + for (int m = 1; m < 4; m++) { + double a = amn[m - 1]; + double b = bmn[m - 1]; + double t1 = a * gxx * pow(m, 2) * cos(m * x); + double t2 = b * gxx * pow(m, 2) * sin(m * x); + fout[0] += t1 + t2; } double kz = 1.; - fout[0] *= (1.+kz*z); -// fout[0] *= (1.+kz*z+0.5*pow(z,2)); + fout[0] *= (1. + kz * z); + // fout[0] *= (1.+kz*z+0.5*pow(z,2)); } -void evalFunc_consteps_dirichletx_sol_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_sol_2x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], z = xn[1]; double a = 2.; - double c[] = {a/12.-1./2., 0.}; + double c[] = {a / 12. - 1. / 2., 0.}; double kz = 1.; double xp = x, zp = z; fout[0] = poly_test_func_1x(xp, a, c) -// *sin(kz*z); - *(1.+kz*z); -// *(1.+kz*z+0.5*pow(z,2)); + // *sin(kz*z); + * (1. + kz * z); + // *(1.+kz*z+0.5*pow(z,2)); } -void evalFunc_consteps_dirichletx_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], z = xn[1]; double a = 2.; - double c[] = {a/12.-1./2., 0.}; + double c[] = {a / 12. - 1. / 2., 0.}; double kz = 1.; double xp = x, zp = z; - fout[0] = -(1 - a*pow(xp,2)) -// *sin(kz*z); - *(1.+kz*z); -// *(1.+kz*z+0.5*pow(z,2)); + fout[0] = -(1 - a * pow(xp, 2)) + // *sin(kz*z); + * (1. + kz * z); + // *(1.+kz*z+0.5*pow(z,2)); } -void evalFunc_consteps_neumannx_dirichletx_sol_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_neumannx_dirichletx_sol_2x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], z = xn[1]; double a = 5.; - double c[] = {0., a/12.-1./2.}; + double c[] = {0., a / 12. - 1. / 2.}; fout[0] = poly_test_func_1x(x, a, c); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_neumannx_dirichletx_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_neumannx_dirichletx_2x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], z = xn[1]; double a = 5.; - double c[] = {0., a/12.-1./2.}; - fout[0] = -(1 - a*pow(x,2)); + double c[] = {0., a / 12. - 1. / 2.}; + fout[0] = -(1 - a * pow(x, 2)); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_dirichletx_neumannx_sol_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_neumannx_sol_2x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], z = xn[1]; double a = 5.; - double c[] = {0., a/12.-1./2.}; - fout[0] = poly_test_func_1x(x-1., a, c); + double c[] = {0., a / 12. - 1. / 2.}; + fout[0] = poly_test_func_1x(x - 1., a, c); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_dirichletx_neumannx_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_neumannx_2x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], z = xn[1]; double a = 5.; - double c[] = {0., a/12.-1./2.}; - fout[0] = -(1 - a*pow(x-1.,2)); + double c[] = {0., a / 12. - 1. / 2.}; + fout[0] = -(1 - a * pow(x - 1., 2)); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } // Persistent objects created by consteps test. @@ -176,8 +187,7 @@ struct fem_poisson_perp_consteps_objs { struct gkyl_basis basis; }; -void -fem_poisson_perp_consteps_objs_release(struct fem_poisson_perp_consteps_objs *objs) +void fem_poisson_perp_consteps_objs_release(struct fem_poisson_perp_consteps_objs *objs) { gkyl_fem_poisson_perp_release(objs->poisson); gkyl_array_release(objs->eps); @@ -189,29 +199,32 @@ fem_poisson_perp_consteps_objs_release(struct fem_poisson_perp_consteps_objs *ob gkyl_free(objs); } - // Helper: verify phi_ho against reference solution sol over a range. // pass filter_dim < 0 to check all cells; otherwise only checks cells // where iter.idx[filter_dim] == filter_idx. // Solution; checked convergence but note that p=2 serendipity doesn't // converge as p+1. One must use tensor basis and a RHS in the space of // the basis for that. -static void -check_sol(const struct gkyl_range *range, const struct gkyl_array *phi_ho, - int num_basis, const double *sol, double scale_fac, - int filter_dim, int filter_idx, double tol) +static void check_sol( + const struct gkyl_range *range, const struct gkyl_array *phi_ho, int num_basis, const double *sol, + double scale_fac, int filter_dim, int filter_idx, double tol +) { long i = 0; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, range); while (gkyl_range_iter_next(&iter)) { - if (filter_dim >= 0 && iter.idx[filter_dim] != filter_idx) continue; + if (filter_dim >= 0 && iter.idx[filter_dim] != filter_idx) { + continue; + } long loc = gkyl_range_idx(range, iter.idx); const double *phi_p = gkyl_array_cfetch(phi_ho, loc); for (int m = 0; m < num_basis; m++) { - TEST_CHECK( gkyl_compare(sol[i]*scale_fac, phi_p[m], tol) ); - TEST_MSG("Expected: %.13e in cell (%d,%d,%d)", sol[i]*scale_fac, - iter.idx[0], iter.idx[1], iter.idx[2]); + TEST_CHECK(gkyl_compare(sol[i] * scale_fac, phi_p[m], tol)); + TEST_MSG( + "Expected: %.13e in cell (%d,%d,%d)", sol[i] * scale_fac, iter.idx[0], iter.idx[1], + iter.idx[2] + ); TEST_MSG("Produced: %.13e", phi_p[m]); i += 1; } @@ -249,48 +262,56 @@ static const double *get_sol_3x_bias_p2_NxDx_PyPy(void); static const double *get_sol_3x_biasB_p1_DxDx_DyDy(void); static const double *get_sol_3x_biasB_p1_DxDx_PyPy(void); -void -fem_poisson_perp_consteps_2x_check(struct fem_poisson_perp_consteps_objs *objs, - int poly_order, struct gkyl_poisson_bc bcs, double scale_fac) +void fem_poisson_perp_consteps_2x_check( + struct fem_poisson_perp_consteps_objs *objs, int poly_order, struct gkyl_poisson_bc bcs, + double scale_fac +) { // Check results in fem_poisson_perp_consteps_2x test. if (poly_order == 1) { if (bcs.lo_type[0] == GKYL_POISSON_PERIODIC && bcs.up_type[0] == GKYL_POISSON_PERIODIC) { // Solution not yet verified for periodic 2x. - } else if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { - check_sol(&objs->localRange, objs->phi_ho, objs->basis.num_basis, - get_sol_2x_p1_DxDx(), scale_fac, -1, -1, 1e-10); + } else if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && + bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { + check_sol( + &objs->localRange, objs->phi_ho, objs->basis.num_basis, get_sol_2x_p1_DxDx(), scale_fac, -1, + -1, 1e-10 + ); } else if (bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { - check_sol(&objs->localRange, objs->phi_ho, objs->basis.num_basis, - get_sol_2x_p1_NxDx(), scale_fac, -1, -1, 1e-10); + check_sol( + &objs->localRange, objs->phi_ho, objs->basis.num_basis, get_sol_2x_p1_NxDx(), scale_fac, -1, + -1, 1e-10 + ); } else if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_NEUMANN) { - check_sol(&objs->localRange, objs->phi_ho, objs->basis.num_basis, - get_sol_2x_p1_DxNx(), scale_fac, -1, -1, 1e-10); + check_sol( + &objs->localRange, objs->phi_ho, objs->basis.num_basis, get_sol_2x_p1_DxNx(), scale_fac, -1, + -1, 1e-10 + ); } else { - TEST_CHECK( gkyl_compare(1., 2., 1e-10) ); + TEST_CHECK(gkyl_compare(1., 2., 1e-10)); TEST_MSG("This BC combination is not available"); } } else { - TEST_CHECK( gkyl_compare(1., 2., 1e-10) ); + TEST_CHECK(gkyl_compare(1., 2., 1e-10)); TEST_MSG("This poly_order is not available"); } - } -struct fem_poisson_perp_consteps_objs* -test_fem_poisson_perp_consteps_2x_objs(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) +struct fem_poisson_perp_consteps_objs *test_fem_poisson_perp_consteps_2x_objs( + int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu +) { double epsilon_0 = 1.0; - double lower[] = {-M_PI,-M_PI}, upper[] = {M_PI,M_PI}; - if ( (bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) - || (bcs.lo_type[0]==GKYL_POISSON_NEUMANN && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) - || (bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_NEUMANN) ) - { - lower[0] = 0.; upper[0] = 1.; + double lower[] = {-M_PI, -M_PI}, upper[] = {M_PI, M_PI}; + if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) || + (bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) || + (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_NEUMANN)) { + lower[0] = 0.; + upper[0] = 1.; } - int dim = sizeof(lower)/sizeof(lower[0]); - int dim_perp = dim-1; + int dim = sizeof(lower) / sizeof(lower[0]); + int dim_perp = dim - 1; struct fem_poisson_perp_consteps_objs *objs = gkyl_malloc(sizeof(*objs)); @@ -301,31 +322,41 @@ test_fem_poisson_perp_consteps_2x_objs(int poly_order, const int *cells, struct // Basis functions. gkyl_cart_modal_serendip(&objs->basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; gkyl_create_grid_ranges(&grid, ghost, &objs->localRange_ext, &objs->localRange); // Projection updater for DG field. gkyl_proj_on_basis *projob, *projob_sol; - if (bcs.lo_type[0]==GKYL_POISSON_PERIODIC && bcs.up_type[0]==GKYL_POISSON_PERIODIC) { - projob = gkyl_proj_on_basis_new(&grid, &objs->basis, - poly_order+1, 1, evalFunc_consteps_periodicx_2x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &objs->basis, - 2*(poly_order+1), 1, evalFunc_consteps_periodicx_sol_2x, NULL); - } else if (bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) { - projob = gkyl_proj_on_basis_new(&grid, &objs->basis, - poly_order+1, 1, evalFunc_consteps_dirichletx_2x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &objs->basis, - 2*(poly_order+1), 1, evalFunc_consteps_dirichletx_sol_2x, NULL); - } else if (bcs.lo_type[0]==GKYL_POISSON_NEUMANN && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) { - projob = gkyl_proj_on_basis_new(&grid, &objs->basis, - poly_order+1, 1, evalFunc_consteps_neumannx_dirichletx_2x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &objs->basis, - 2*(poly_order+1), 1, evalFunc_consteps_neumannx_dirichletx_sol_2x, NULL); - } else if (bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_NEUMANN) { - projob = gkyl_proj_on_basis_new(&grid, &objs->basis, - poly_order+1, 1, evalFunc_consteps_dirichletx_neumannx_2x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &objs->basis, - 2*(poly_order+1), 1, evalFunc_consteps_dirichletx_neumannx_sol_2x, NULL); + if (bcs.lo_type[0] == GKYL_POISSON_PERIODIC && bcs.up_type[0] == GKYL_POISSON_PERIODIC) { + projob = gkyl_proj_on_basis_new( + &grid, &objs->basis, poly_order + 1, 1, evalFunc_consteps_periodicx_2x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &objs->basis, 2 * (poly_order + 1), 1, evalFunc_consteps_periodicx_sol_2x, NULL + ); + } else if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { + projob = gkyl_proj_on_basis_new( + &grid, &objs->basis, poly_order + 1, 1, evalFunc_consteps_dirichletx_2x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &objs->basis, 2 * (poly_order + 1), 1, evalFunc_consteps_dirichletx_sol_2x, NULL + ); + } else if (bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { + projob = gkyl_proj_on_basis_new( + &grid, &objs->basis, poly_order + 1, 1, evalFunc_consteps_neumannx_dirichletx_2x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &objs->basis, 2 * (poly_order + 1), 1, evalFunc_consteps_neumannx_dirichletx_sol_2x, + NULL + ); + } else if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_NEUMANN) { + projob = gkyl_proj_on_basis_new( + &grid, &objs->basis, poly_order + 1, 1, evalFunc_consteps_dirichletx_neumannx_2x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &objs->basis, 2 * (poly_order + 1), 1, evalFunc_consteps_dirichletx_neumannx_sol_2x, + NULL + ); } // Create DG field we wish to make continuous. @@ -333,16 +364,15 @@ test_fem_poisson_perp_consteps_2x_objs(int poly_order, const int *cells, struct // Create array holding continuous field we'll compute. objs->phi = mkarr(use_gpu, objs->basis.num_basis, objs->localRange_ext.volume); // Create DG field for permittivity tensor. - int epsnum = dim_perp+ceil((pow(3.,dim_perp-1)-dim_perp)/2); - objs->eps = mkarr(use_gpu, epsnum*objs->basis.num_basis, objs->localRange_ext.volume); + int epsnum = dim_perp + ceil((pow(3., dim_perp - 1) - dim_perp) / 2); + objs->eps = mkarr(use_gpu, epsnum * objs->basis.num_basis, objs->localRange_ext.volume); // Analytic solution. objs->phisol_ho = mkarr(false, objs->basis.num_basis, objs->localRange_ext.volume); // Device copies: if (use_gpu) { objs->rho_ho = mkarr(false, objs->rho->ncomp, objs->rho->size); objs->phi_ho = mkarr(false, objs->phi->ncomp, objs->phi->size); - } - else { + } else { objs->rho_ho = gkyl_array_acquire(objs->rho); objs->phi_ho = gkyl_array_acquire(objs->phi); } @@ -353,23 +383,25 @@ test_fem_poisson_perp_consteps_2x_objs(int poly_order, const int *cells, struct gkyl_array_copy(objs->rho, objs->rho_ho); // Project the permittivity onto the basis. - double dg0norm = pow(sqrt(2.),dim); - gkyl_array_shiftc(objs->eps, epsilon_0*dg0norm, 0*objs->basis.num_basis); + double dg0norm = pow(sqrt(2.), dim); + gkyl_array_shiftc(objs->eps, epsilon_0 * dg0norm, 0 * objs->basis.num_basis); // Project the analytic solution. gkyl_proj_on_basis_advance(projob_sol, 0.0, &objs->localRange, objs->phisol_ho); gkyl_proj_on_basis_release(projob_sol); // FEM poisson solver. - objs->poisson = gkyl_fem_poisson_perp_new(&objs->localRange, &grid, objs->basis, &bcs, NULL, objs->eps, NULL, use_gpu); + objs->poisson = gkyl_fem_poisson_perp_new( + &objs->localRange, &grid, objs->basis, &bcs, NULL, objs->eps, NULL, use_gpu + ); -// struct gkyl_fem_parproj* smooth_op = gkyl_fem_parproj_new(&objs->localRange, &grid, -// &objs->localRange_ext, &objs->basis, GKYL_FEM_PARPROJ_DIRICHLET, NULL, NULL, NULL, use_gpu); -// gkyl_fem_parproj_set_rhs(smooth_op, objs->rho, objs->rho); -// gkyl_fem_parproj_solve (smooth_op, objs->rho); + // struct gkyl_fem_parproj* smooth_op = gkyl_fem_parproj_new(&objs->localRange, &grid, + // &objs->localRange_ext, &objs->basis, GKYL_FEM_PARPROJ_DIRICHLET, NULL, NULL, NULL, use_gpu); + // gkyl_fem_parproj_set_rhs(smooth_op, objs->rho, objs->rho); + // gkyl_fem_parproj_solve (smooth_op, objs->rho); // Check that the solver can be called multiple times without issue. - for (int i=0; i<2; i++) { + for (int i = 0; i < 2; i++) { // Set the RHS source. gkyl_fem_poisson_perp_set_rhs(objs->poisson, objs->rho); @@ -377,69 +409,77 @@ test_fem_poisson_perp_consteps_2x_objs(int poly_order, const int *cells, struct gkyl_fem_poisson_perp_solve(objs->poisson, objs->phi); } gkyl_array_copy(objs->phi_ho, objs->phi); -// gkyl_fem_parproj_set_rhs(smooth_op, phi, phi); -// gkyl_fem_parproj_solve (smooth_op, phi); -// gkyl_fem_parproj_release(smooth_op); + // gkyl_fem_parproj_set_rhs(smooth_op, phi, phi); + // gkyl_fem_parproj_solve (smooth_op, phi); + // gkyl_fem_parproj_release(smooth_op); if (bcs.lo_type[0] == GKYL_POISSON_PERIODIC) { // Subtract the volume averaged sol from the numerical and analytic solutions. - // This is not strictly necessary, as the potential is only known up to + // This is not strictly necessary, as the potential is only known up to // constant shift, but it makes unit testing more robust across CPU/GPU. struct gkyl_array *sol_cellavg = gkyl_array_new(GKYL_DOUBLE, 1, objs->localRange_ext.volume); double sol_avg[1]; // Factor accounting for normalization when subtracting a constant from a // DG field and the 1/N to properly compute the volume averaged RHS. - double mavgfac = -pow(sqrt(2.),dim); // /perpRange.volume; + double mavgfac = -pow(sqrt(2.), dim); // /perpRange.volume; // Subtract the volume averaged sol from the sol. gkyl_array_clear(sol_cellavg, 0.0); gkyl_dg_calc_average_range(&objs->basis, 0, sol_cellavg, 0, objs->phi_ho, objs->localRange); - for (int kIdx=0; kIdxlocalRange, (int[]){0,0,1}, (int[]){0,0,kIdx+1}); + gkyl_range_deflate(&perp_range, &objs->localRange, (int[]){0, 0, 1}, (int[]){0, 0, kIdx + 1}); gkyl_array_reduce_range(sol_avg, sol_cellavg, GKYL_SUM, &perp_range); - gkyl_array_shiftc_range(objs->phi_ho, mavgfac*sol_avg[0]/perp_range.volume, 0, &perp_range); + gkyl_array_shiftc_range( + objs->phi_ho, mavgfac * sol_avg[0] / perp_range.volume, 0, &perp_range + ); } // Now do the same to the analytic solution. gkyl_array_clear(sol_cellavg, 0.0); gkyl_dg_calc_average_range(&objs->basis, 0, sol_cellavg, 0, objs->phisol_ho, objs->localRange); - for (int kIdx=0; kIdxlocalRange, (int[]){0,0,1}, (int[]){0,0,kIdx+1}); + gkyl_range_deflate(&perp_range, &objs->localRange, (int[]){0, 0, 1}, (int[]){0, 0, kIdx + 1}); gkyl_array_reduce_range(sol_avg, sol_cellavg, GKYL_SUM, &perp_range); - gkyl_array_shiftc_range(objs->phisol_ho, mavgfac*sol_avg[0]/perp_range.volume, 0, &perp_range); + gkyl_array_shiftc_range( + objs->phisol_ho, mavgfac * sol_avg[0] / perp_range.volume, 0, &perp_range + ); } gkyl_array_release(sol_cellavg); } -// double errL2 = error_L2norm(grid, objs->localRange, objs->basis, phi, phisol); -// printf("error L2 norm = %g\n",errL2); + // double errL2 = error_L2norm(grid, objs->localRange, objs->basis, phi, phisol); + // printf("error L2 norm = %g\n",errL2); // Check results for correctness. fem_poisson_perp_consteps_2x_check(objs, poly_order, bcs, 1.0); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, objs->rho_ho, "ctest_fem_poisson_perp_2x_rho_1.gkyl"); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, objs->phi_ho, "ctest_fem_poisson_perp_2x_phi_8x8_p1.gkyl"); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, objs->phisol_ho, "ctest_fem_poisson_perp_2x_phisol_8x8_p1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, objs->rho_ho, "ctest_fem_poisson_perp_2x_rho_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, objs->phi_ho, "ctest_fem_poisson_perp_2x_phi_8x8_p1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, objs->phisol_ho, "ctest_fem_poisson_perp_2x_phisol_8x8_p1.gkyl"); return objs; } -void -test_fem_poisson_perp_consteps_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) +void test_fem_poisson_perp_consteps_2x( + int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu +) { - struct fem_poisson_perp_consteps_objs *objs = test_fem_poisson_perp_consteps_2x_objs(poly_order, cells, bcs, use_gpu); + struct fem_poisson_perp_consteps_objs *objs = + test_fem_poisson_perp_consteps_2x_objs(poly_order, cells, bcs, use_gpu); fem_poisson_perp_consteps_objs_release(objs); } -void -test_fem_poisson_perp_consteps_2x_update(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) +void test_fem_poisson_perp_consteps_2x_update( + int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu +) { // Run the first test. - struct fem_poisson_perp_consteps_objs *objs = test_fem_poisson_perp_consteps_2x_objs(poly_order, cells, bcs, use_gpu); + struct fem_poisson_perp_consteps_objs *objs = + test_fem_poisson_perp_consteps_2x_objs(poly_order, cells, bcs, use_gpu); double global_fac = 1.0; // Check that the solver can be called multiple times without issue. - for (int i=0; i<2; i++) { + for (int i = 0; i < 2; i++) { // Now update the LHS matrix. Multiply it by a constant so the solution should be the same as before but divided by that constant. double prob_fac = 1.3; gkyl_array_scale(objs->eps, prob_fac); @@ -456,25 +496,26 @@ test_fem_poisson_perp_consteps_2x_update(int poly_order, const int *cells, struc gkyl_array_copy(objs->phi_ho, objs->phi); // Check results for correctness. - fem_poisson_perp_consteps_2x_check(objs, poly_order, bcs, 1.0/global_fac); + fem_poisson_perp_consteps_2x_check(objs, poly_order, bcs, 1.0 / global_fac); - // Release persistent objects. + // Release persistent objects. fem_poisson_perp_consteps_objs_release(objs); } -void -test_fem_poisson_perp_consteps_2x_bias(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) +void test_fem_poisson_perp_consteps_2x_bias( + int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu +) { double epsilon_0 = 1.0; - double lower[] = {-M_PI,-M_PI}, upper[] = {M_PI,M_PI}; - if ( (bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) - || (bcs.lo_type[0]==GKYL_POISSON_NEUMANN && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) - || (bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_NEUMANN) ) - { - lower[0] = 0.; upper[0] = 1.; + double lower[] = {-M_PI, -M_PI}, upper[] = {M_PI, M_PI}; + if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) || + (bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) || + (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_NEUMANN)) { + lower[0] = 0.; + upper[0] = 1.; } - int dim = sizeof(lower)/sizeof(lower[0]); - int dim_perp = dim-1; + int dim = sizeof(lower) / sizeof(lower[0]); + int dim_perp = dim - 1; // Grids. struct gkyl_rect_grid grid; @@ -484,27 +525,33 @@ test_fem_poisson_perp_consteps_2x_bias(int poly_order, const int *cells, struct struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); // Projection updater for DG field. gkyl_proj_on_basis *projob, *projob_sol; - if (bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_dirichletx_2x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_dirichletx_sol_2x, NULL); - } else if (bcs.lo_type[0]==GKYL_POISSON_NEUMANN && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_neumannx_dirichletx_2x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_neumannx_dirichletx_sol_2x, NULL); - } else if (bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_NEUMANN) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_dirichletx_neumannx_2x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_dirichletx_neumannx_sol_2x, NULL); + if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_dirichletx_2x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc_consteps_dirichletx_sol_2x, NULL + ); + } else if (bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_neumannx_dirichletx_2x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc_consteps_neumannx_dirichletx_sol_2x, NULL + ); + } else if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_NEUMANN) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_dirichletx_neumannx_2x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc_consteps_dirichletx_neumannx_sol_2x, NULL + ); } // Create DG field we wish to make continuous. @@ -512,8 +559,8 @@ test_fem_poisson_perp_consteps_2x_bias(int poly_order, const int *cells, struct // Create array holding continuous field we'll compute. struct gkyl_array *phi = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); // Create DG field for permittivity tensor. - int epsnum = dim_perp+ceil((pow(3.,dim_perp-1)-dim_perp)/2); - struct gkyl_array *eps = mkarr(use_gpu, epsnum*basis.num_basis, localRange_ext.volume); + int epsnum = dim_perp + ceil((pow(3., dim_perp - 1) - dim_perp) / 2); + struct gkyl_array *eps = mkarr(use_gpu, epsnum * basis.num_basis, localRange_ext.volume); // Analytic solution. struct gkyl_array *phisol_ho = mkarr(false, basis.num_basis, localRange_ext.volume); // Device copies: @@ -521,8 +568,7 @@ test_fem_poisson_perp_consteps_2x_bias(int poly_order, const int *cells, struct if (use_gpu) { rho_ho = mkarr(false, rho->ncomp, rho->size); phi_ho = mkarr(false, phi->ncomp, phi->size); - } - else { + } else { rho_ho = gkyl_array_acquire(rho); phi_ho = gkyl_array_acquire(phi); } @@ -532,8 +578,8 @@ test_fem_poisson_perp_consteps_2x_bias(int poly_order, const int *cells, struct gkyl_array_copy(rho, rho_ho); // Project the permittivity onto the basis. - double dg0norm = pow(sqrt(2.),dim); - gkyl_array_shiftc(eps, epsilon_0*dg0norm, 0*basis.num_basis); + double dg0norm = pow(sqrt(2.), dim); + gkyl_array_shiftc(eps, epsilon_0 * dg0norm, 0 * basis.num_basis); // Project the analytic solution. gkyl_proj_on_basis_advance(projob_sol, 0.0, &localRange, phisol_ho); @@ -542,18 +588,19 @@ test_fem_poisson_perp_consteps_2x_bias(int poly_order, const int *cells, struct struct gkyl_poisson_bias_line bias = { .perp_dirs = {0, 1}, .perp_coords = {0.5, -M_PI}, // Location of the plane in the 'dir' dimension. - .val = 0., // Biasing value. + .val = 0. // Biasing value. }; struct gkyl_poisson_bias_line_list bll = { .num_bias_line = 1, // Number of bias lines. - .bl = &bias, + .bl = &bias }; // FEM poisson solver. - struct gkyl_fem_poisson_perp *poisson = gkyl_fem_poisson_perp_new(&localRange, &grid, basis, &bcs, &bll, eps, NULL, use_gpu); + struct gkyl_fem_poisson_perp *poisson = + gkyl_fem_poisson_perp_new(&localRange, &grid, basis, &bcs, &bll, eps, NULL, use_gpu); // Check that the solver can be called multiple times without issue. - for (int i=0; i<2; i++) { + for (int i = 0; i < 2; i++) { // Set the RHS source. gkyl_fem_poisson_perp_set_rhs(poisson, rho); @@ -562,32 +609,37 @@ test_fem_poisson_perp_consteps_2x_bias(int poly_order, const int *cells, struct gkyl_array_copy(phi_ho, phi); - // double errL2 = error_L2norm(grid, localRange, basis, phi, phisol); - // printf("error L2 norm = %g\n",errL2); + // double errL2 = error_L2norm(grid, localRange, basis, phi, phisol); + // printf("error L2 norm = %g\n",errL2); if (poly_order == 1) { if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { - check_sol(&localRange, phi_ho, basis.num_basis, - get_sol_2x_bias_p1_DxDx(), 1.0, -1, -1, 1e-10); - } else if (bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { - check_sol(&localRange, phi_ho, basis.num_basis, - get_sol_2x_bias_p1_NxDx(), 1.0, -1, -1, 1e-10); - } else if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_NEUMANN) { - check_sol(&localRange, phi_ho, basis.num_basis, - get_sol_2x_bias_p1_DxNx(), 1.0, -1, -1, 1e-10); + check_sol( + &localRange, phi_ho, basis.num_basis, get_sol_2x_bias_p1_DxDx(), 1.0, -1, -1, 1e-10 + ); + } else if (bcs.lo_type[0] == GKYL_POISSON_NEUMANN && + bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { + check_sol( + &localRange, phi_ho, basis.num_basis, get_sol_2x_bias_p1_NxDx(), 1.0, -1, -1, 1e-10 + ); + } else if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && + bcs.up_type[0] == GKYL_POISSON_NEUMANN) { + check_sol( + &localRange, phi_ho, basis.num_basis, get_sol_2x_bias_p1_DxNx(), 1.0, -1, -1, 1e-10 + ); } else { - TEST_CHECK( gkyl_compare(1., 2., 1e-10) ); + TEST_CHECK(gkyl_compare(1., 2., 1e-10)); TEST_MSG("This BC combination is not available"); } } else { - TEST_CHECK( gkyl_compare(1., 2., 1e-10) ); + TEST_CHECK(gkyl_compare(1., 2., 1e-10)); TEST_MSG("This poly_order is not available"); } } -// gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_poisson_perp_2x_rho_1.gkyl"); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_poisson_perp_2x_phi_8x8_p1.gkyl"); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, phisol_ho, "ctest_fem_poisson_perp_2x_phisol_8x8_p1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_poisson_perp_2x_rho_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_poisson_perp_2x_phi_8x8_p1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, phisol_ho, "ctest_fem_poisson_perp_2x_phisol_8x8_p1.gkyl"); gkyl_fem_poisson_perp_release(poisson); gkyl_proj_on_basis_release(projob); @@ -600,285 +652,336 @@ test_fem_poisson_perp_consteps_2x_bias(int poly_order, const int *cells, struct gkyl_array_release(phi_ho); } -void evalFunc_consteps_periodicx_periodicy_sol_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_periodicx_periodicy_sol_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; // These values have to match those in the test below. - double gxx = 1.0, gxy = 0., gyy = 1.0; + double gxx = 1.0, gxy = 0., gyy = 1.0; double amn[] = {0., 10., 0., 10., 0., 0., 10., 0., 0.}; double bmn[] = {0., 10., 0., 10., 0., 0., 10., 0., 0.}; fout[0] = 0.; - for (int m=1; m<4; m++) { - for (int n=1; n<4; n++) { - double a = amn[(m-1)*3+(n-1)]; - double b = bmn[(m-1)*3+(n-1)]; - double t1 = a*cos(m*x)*cos(n*y); - double t2 = b*sin(m*x)*sin(n*y); - fout[0] += t1+t2; + for (int m = 1; m < 4; m++) { + for (int n = 1; n < 4; n++) { + double a = amn[(m - 1) * 3 + (n - 1)]; + double b = bmn[(m - 1) * 3 + (n - 1)]; + double t1 = a * cos(m * x) * cos(n * y); + double t2 = b * sin(m * x) * sin(n * y); + fout[0] += t1 + t2; } } double kz = 1.; - fout[0] *= (1.+kz*z); -// fout[0] *= (1.+kz*z+0.5*pow(z,2)); + fout[0] *= (1. + kz * z); + // fout[0] *= (1.+kz*z+0.5*pow(z,2)); } -void evalFunc_consteps_periodicx_periodicy_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_periodicx_periodicy_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; // These values have to match those in the test below. - double gxx = 1.0, gxy = 0., gyy = 1.0; + double gxx = 1.0, gxy = 0., gyy = 1.0; double amn[] = {0., 10., 0., 10., 0., 0., 10., 0., 0.}; double bmn[] = {0., 10., 0., 10., 0., 0., 10., 0., 0.}; fout[0] = 0.; - for (int m=1; m<4; m++) { - for (int n=1; n<4; n++) { - double a = amn[(m-1)*3+(n-1)]; - double b = bmn[(m-1)*3+(n-1)]; - double t1 = (a*gxx*pow(m,2) - 2*b*gxy*m*n + a*gyy*pow(n,2))*cos(m*x)*cos(n*y); - double t2 = (b*gxx*pow(m,2) - 2*a*gxy*m*n + b*gyy*pow(n,2))*sin(m*x)*sin(n*y); - fout[0] += t1+t2; + for (int m = 1; m < 4; m++) { + for (int n = 1; n < 4; n++) { + double a = amn[(m - 1) * 3 + (n - 1)]; + double b = bmn[(m - 1) * 3 + (n - 1)]; + double t1 = + (a * gxx * pow(m, 2) - 2 * b * gxy * m * n + a * gyy * pow(n, 2)) * cos(m * x) * cos(n * y); + double t2 = + (b * gxx * pow(m, 2) - 2 * a * gxy * m * n + b * gyy * pow(n, 2)) * sin(m * x) * sin(n * y); + fout[0] += t1 + t2; } } double kz = 1.; - fout[0] *= (1.+kz*z); -// fout[0] *= (1.+kz*z+0.5*pow(z,2)); + fout[0] *= (1. + kz * z); + // fout[0] *= (1.+kz*z+0.5*pow(z,2)); } -void evalFunc_consteps_dirichletx_dirichlety_sol_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_dirichlety_sol_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 2.; - double c[] = {a/12.-1./2., 0.}; + double c[] = {a / 12. - 1. / 2., 0.}; double b = 2.; - double d[] = {b/12.-1./2., 0.}; + double d[] = {b / 12. - 1. / 2., 0.}; double kz = 1.; double xp = x, yp = y, zp = z; - fout[0] = poly_test_func_1x(xp, a, c)*poly_test_func_1x(yp, b, d) -// *sin(kz*z); - *(1.+kz*z); -// *(1.+kz*z+0.5*pow(z,2)); + fout[0] = poly_test_func_1x(xp, a, c) * + poly_test_func_1x(yp, b, d) + // *sin(kz*z); + * (1. + kz * z); + // *(1.+kz*z+0.5*pow(z,2)); } -void evalFunc_consteps_dirichletx_dirichlety_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_dirichlety_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 2.; - double c[] = {a/12.-1./2., 0.}; + double c[] = {a / 12. - 1. / 2., 0.}; double b = 2.; - double d[] = {b/12.-1./2., 0.}; + double d[] = {b / 12. - 1. / 2., 0.}; double kz = 1.; double xp = x, yp = y, zp = z; - fout[0] = -( (1 - b*pow(yp,2))*poly_test_func_1x(xp, a, c) - +(1 - a*pow(xp,2))*poly_test_func_1x(yp, b, d) ) -// *sin(kz*z); - *(1.+kz*z); -// *(1.+kz*z+0.5*pow(z,2)); + fout[0] = -((1 - b * pow(yp, 2)) * poly_test_func_1x(xp, a, c) + + (1 - a * pow(xp, 2)) * poly_test_func_1x(yp, b, d)) + // *sin(kz*z); + * (1. + kz * z); + // *(1.+kz*z+0.5*pow(z,2)); } -void evalFunc_consteps_dirichletx_periodicy_sol_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_periodicy_sol_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 2.; - double c[] = {a/12.-1./2., 0.}; + double c[] = {a / 12. - 1. / 2., 0.}; double n = 2.; - fout[0] = poly_test_func_1x(x, a, c)*sin(n*y); + fout[0] = poly_test_func_1x(x, a, c) * sin(n * y); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_dirichletx_periodicy_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_periodicy_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 2.; - double c[] = {a/12.-1./2., 0.}; + double c[] = {a / 12. - 1. / 2., 0.}; double n = 2.; - fout[0] = -( (1-a*pow(x,2))*sin(n*y) - -pow(n,2)*poly_test_func_1x(x, a, c)*sin(n*y) ); + fout[0] = + -((1 - a * pow(x, 2)) * sin(n * y) - pow(n, 2) * poly_test_func_1x(x, a, c) * sin(n * y)); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_periodicx_dirichlety_sol_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_periodicx_dirichlety_sol_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double b = 2.; - double d[] = {b/12.-1./2., 0.}; + double d[] = {b / 12. - 1. / 2., 0.}; double m = 2.; - fout[0] = sin(m*x)*poly_test_func_1x(y, b, d); + fout[0] = sin(m * x) * poly_test_func_1x(y, b, d); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_periodicx_dirichlety_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_periodicx_dirichlety_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double b = 2.; - double d[] = {b/12.-1./2., 0.}; + double d[] = {b / 12. - 1. / 2., 0.}; double m = 2.; - fout[0] = -( (1-b*pow(y,2))*sin(m*x) - -pow(m,2)*poly_test_func_1x(y, b, d)*sin(m*x) ); + fout[0] = + -((1 - b * pow(y, 2)) * sin(m * x) - pow(m, 2) * poly_test_func_1x(y, b, d) * sin(m * x)); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_dirichletx_neumanny_dirichlety_sol_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_neumanny_dirichlety_sol_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 2.; - double c[] = {a/12.-1./2., 0.}; + double c[] = {a / 12. - 1. / 2., 0.}; double b = 5.; - double d[] = {0., b/12.-1./2.}; - fout[0] = poly_test_func_1x(x, a, c)*poly_test_func_1x(y, b, d); + double d[] = {0., b / 12. - 1. / 2.}; + fout[0] = poly_test_func_1x(x, a, c) * poly_test_func_1x(y, b, d); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_dirichletx_neumanny_dirichlety_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_neumanny_dirichlety_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 2.; - double c[] = {a/12.-1./2., 0.}; + double c[] = {a / 12. - 1. / 2., 0.}; double b = 5.; - double d[] = {0., b/12.-1./2.}; - fout[0] = -( (1 - b*pow(y,2))*poly_test_func_1x(x, a, c) - +(1 - a*pow(x,2))*poly_test_func_1x(y, b, d) ); + double d[] = {0., b / 12. - 1. / 2.}; + fout[0] = + -((1 - b * pow(y, 2)) * poly_test_func_1x(x, a, c) + + (1 - a * pow(x, 2)) * poly_test_func_1x(y, b, d)); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_dirichletx_dirichlety_neumanny_sol_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_dirichlety_neumanny_sol_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 2.; - double c[] = {a/12.-1./2., 0.}; + double c[] = {a / 12. - 1. / 2., 0.}; double b = 5.; - double d[] = {0., b/12.-1./2.}; - fout[0] = poly_test_func_1x(x, a, c)*poly_test_func_1x(y-1., b, d); + double d[] = {0., b / 12. - 1. / 2.}; + fout[0] = poly_test_func_1x(x, a, c) * poly_test_func_1x(y - 1., b, d); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_dirichletx_dirichlety_neumanny_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_dirichlety_neumanny_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 2.; - double c[] = {a/12.-1./2., 0.}; + double c[] = {a / 12. - 1. / 2., 0.}; double b = 5.; - double d[] = {0., b/12.-1./2.}; - fout[0] = -( (1 - b*pow(y-1.,2))*poly_test_func_1x(x , a, c) - +(1 - a*pow(x ,2))*poly_test_func_1x(y-1., b, d) ); + double d[] = {0., b / 12. - 1. / 2.}; + fout[0] = + -((1 - b * pow(y - 1., 2)) * poly_test_func_1x(x, a, c) + + (1 - a * pow(x, 2)) * poly_test_func_1x(y - 1., b, d)); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_neumannx_dirichletx_dirichlety_sol_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_neumannx_dirichletx_dirichlety_sol_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 5.; - double c[] = {0., a/12.-1./2.}; + double c[] = {0., a / 12. - 1. / 2.}; double b = 2.; - double d[] = {b/12.-1./2., 0.}; - fout[0] = poly_test_func_1x(x, a, c)*poly_test_func_1x(y, b, d); + double d[] = {b / 12. - 1. / 2., 0.}; + fout[0] = poly_test_func_1x(x, a, c) * poly_test_func_1x(y, b, d); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_neumannx_dirichletx_dirichlety_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_neumannx_dirichletx_dirichlety_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 5.; - double c[] = {0., a/12.-1./2.}; + double c[] = {0., a / 12. - 1. / 2.}; double b = 2.; - double d[] = {b/12.-1./2., 0.}; - fout[0] = -( (1 - b*pow(y,2))*poly_test_func_1x(x, a, c) - +(1 - a*pow(x,2))*poly_test_func_1x(y, b, d) ); + double d[] = {b / 12. - 1. / 2., 0.}; + fout[0] = + -((1 - b * pow(y, 2)) * poly_test_func_1x(x, a, c) + + (1 - a * pow(x, 2)) * poly_test_func_1x(y, b, d)); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_dirichletx_neumannx_dirichlety_sol_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_neumannx_dirichlety_sol_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 5.; - double c[] = {0., a/12.-1./2.}; + double c[] = {0., a / 12. - 1. / 2.}; double b = 2.; - double d[] = {b/12.-1./2., 0.}; - fout[0] = poly_test_func_1x(x-1., a, c)*poly_test_func_1x(y, b, d); + double d[] = {b / 12. - 1. / 2., 0.}; + fout[0] = poly_test_func_1x(x - 1., a, c) * poly_test_func_1x(y, b, d); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_dirichletx_neumannx_dirichlety_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_dirichletx_neumannx_dirichlety_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 5.; - double c[] = {0., a/12.-1./2.}; + double c[] = {0., a / 12. - 1. / 2.}; double b = 2.; - double d[] = {b/12.-1./2., 0.}; - fout[0] = -( (1 - b*pow(y ,2))*poly_test_func_1x(x-1., a, c) - +(1 - a*pow(x-1.,2))*poly_test_func_1x(y , b, d) ); + double d[] = {b / 12. - 1. / 2., 0.}; + fout[0] = + -((1 - b * pow(y, 2)) * poly_test_func_1x(x - 1., a, c) + + (1 - a * pow(x - 1., 2)) * poly_test_func_1x(y, b, d)); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_neumannx_dirichletx_periodicy_sol_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_neumannx_dirichletx_periodicy_sol_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 5.; - double c[] = {0., a/12.-1./2.}; + double c[] = {0., a / 12. - 1. / 2.}; double n = 2.; - fout[0] = poly_test_func_1x(x, a, c)*sin(n*y); + fout[0] = poly_test_func_1x(x, a, c) * sin(n * y); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void evalFunc_consteps_neumannx_dirichletx_periodicy_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_consteps_neumannx_dirichletx_periodicy_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double a = 5.; - double c[] = {0., a/12.-1./2.}; + double c[] = {0., a / 12. - 1. / 2.}; double n = 2.; - fout[0] = -( (1 - a*pow(x,2))*sin(n*y) - -pow(n,2)*sin(n*y)*poly_test_func_1x(x, a, c) ); + fout[0] = + -((1 - a * pow(x, 2)) * sin(n * y) - pow(n, 2) * sin(n * y) * poly_test_func_1x(x, a, c)); double kz = 1.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } -void -test_fem_poisson_perp_consteps_3x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) +void test_fem_poisson_perp_consteps_3x( + int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu +) { double epsilon_0 = 1.0; - double lower[] = {-M_PI,-M_PI,-M_PI}, upper[] = {M_PI,M_PI,M_PI}; - if ( ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) - || ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_NEUMANN && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) - || ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_NEUMANN)) - || ((bcs.lo_type[0]==GKYL_POISSON_NEUMANN && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) - || ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_NEUMANN) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) ) - { - lower[0] = 0.; upper[0] = 1.; - lower[1] = 0.; upper[1] = 1.; - } else if ( ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_PERIODIC && bcs.up_type[1]==GKYL_POISSON_PERIODIC)) - || ((bcs.lo_type[0]==GKYL_POISSON_NEUMANN && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_PERIODIC && bcs.up_type[1]==GKYL_POISSON_PERIODIC)) ) - { - lower[0] = 0.; upper[0] = 1.; - } else if ((bcs.lo_type[0]==GKYL_POISSON_PERIODIC && bcs.up_type[0]==GKYL_POISSON_PERIODIC) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) { - lower[1] = 0.; upper[1] = 1.; + double lower[] = {-M_PI, -M_PI, -M_PI}, upper[] = {M_PI, M_PI, M_PI}; + if (((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET)) || + ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + (bcs.lo_type[1] == GKYL_POISSON_NEUMANN && bcs.up_type[1] == GKYL_POISSON_DIRICHLET)) || + ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_NEUMANN)) || + ((bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET)) || + ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_NEUMANN) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET))) { + lower[0] = 0.; + upper[0] = 1.; + lower[1] = 0.; + upper[1] = 1.; + } else if (((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && + (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC) + ) || + ((bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && + (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC) + )) { + lower[0] = 0.; + upper[0] = 1.; + } else if ((bcs.lo_type[0] == GKYL_POISSON_PERIODIC && bcs.up_type[0] == GKYL_POISSON_PERIODIC) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET + )) { + lower[1] = 0.; + upper[1] = 1.; } - int dim = sizeof(lower)/sizeof(lower[0]); - int dim_perp = dim-1; + int dim = sizeof(lower) / sizeof(lower[0]); + int dim_perp = dim - 1; // Grids. struct gkyl_rect_grid grid; @@ -888,66 +991,97 @@ test_fem_poisson_perp_consteps_3x(int poly_order, const int *cells, struct gkyl_ struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1, 1 }; + int ghost[] = {1, 1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); // Projection updater for DG field. gkyl_proj_on_basis *projob, *projob_sol; - if ((bcs.lo_type[0]==GKYL_POISSON_PERIODIC && bcs.up_type[0]==GKYL_POISSON_PERIODIC) && - (bcs.lo_type[1]==GKYL_POISSON_PERIODIC && bcs.up_type[1]==GKYL_POISSON_PERIODIC)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_periodicx_periodicy_3x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_periodicx_periodicy_sol_3x, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_dirichletx_dirichlety_3x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_dirichletx_dirichlety_sol_3x, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_PERIODIC && bcs.up_type[1]==GKYL_POISSON_PERIODIC)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_dirichletx_periodicy_3x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_dirichletx_periodicy_sol_3x, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_PERIODIC && bcs.up_type[0]==GKYL_POISSON_PERIODIC) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_periodicx_dirichlety_3x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_periodicx_dirichlety_sol_3x, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_NEUMANN && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_dirichletx_neumanny_dirichlety_3x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_dirichletx_neumanny_dirichlety_sol_3x, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_NEUMANN)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_dirichletx_dirichlety_neumanny_3x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_dirichletx_dirichlety_neumanny_sol_3x, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_NEUMANN && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_neumannx_dirichletx_dirichlety_3x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_neumannx_dirichletx_dirichlety_sol_3x, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_NEUMANN) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_dirichletx_neumannx_dirichlety_3x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_dirichletx_neumannx_dirichlety_sol_3x, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_NEUMANN && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_PERIODIC && bcs.up_type[1]==GKYL_POISSON_PERIODIC)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc_consteps_neumannx_dirichletx_periodicy_3x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc_consteps_neumannx_dirichletx_periodicy_sol_3x, NULL); + if ((bcs.lo_type[0] == GKYL_POISSON_PERIODIC && bcs.up_type[0] == GKYL_POISSON_PERIODIC) && + (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC)) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_periodicx_periodicy_3x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc_consteps_periodicx_periodicy_sol_3x, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET + )) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_dirichletx_dirichlety_3x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc_consteps_dirichletx_dirichlety_sol_3x, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && + (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC)) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_dirichletx_periodicy_3x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc_consteps_dirichletx_periodicy_sol_3x, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_PERIODIC && bcs.up_type[0] == GKYL_POISSON_PERIODIC) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET + )) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_periodicx_dirichlety_3x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc_consteps_periodicx_dirichlety_sol_3x, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && + (bcs.lo_type[1] == GKYL_POISSON_NEUMANN && bcs.up_type[1] == GKYL_POISSON_DIRICHLET)) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_dirichletx_neumanny_dirichlety_3x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, + evalFunc_consteps_dirichletx_neumanny_dirichlety_sol_3x, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_NEUMANN)) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_dirichletx_dirichlety_neumanny_3x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, + evalFunc_consteps_dirichletx_dirichlety_neumanny_sol_3x, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET + )) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_neumannx_dirichletx_dirichlety_3x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, + evalFunc_consteps_neumannx_dirichletx_dirichlety_sol_3x, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_NEUMANN) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET + )) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_dirichletx_neumannx_dirichlety_3x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, + evalFunc_consteps_dirichletx_neumannx_dirichlety_sol_3x, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC)) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_consteps_neumannx_dirichletx_periodicy_3x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, + evalFunc_consteps_neumannx_dirichletx_periodicy_sol_3x, NULL + ); } // Create DG field we wish to make continuous. @@ -955,8 +1089,8 @@ test_fem_poisson_perp_consteps_3x(int poly_order, const int *cells, struct gkyl_ // Create array holding continuous field we'll compute. struct gkyl_array *phi = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); // Create DG field for permittivity tensor. - int epsnum = dim_perp+ceil((pow(3.,dim_perp-1)-dim_perp)/2); - struct gkyl_array *eps = mkarr(use_gpu, epsnum*basis.num_basis, localRange_ext.volume); + int epsnum = dim_perp + ceil((pow(3., dim_perp - 1) - dim_perp) / 2); + struct gkyl_array *eps = mkarr(use_gpu, epsnum * basis.num_basis, localRange_ext.volume); // Analytic solution. struct gkyl_array *phisol_ho = mkarr(false, basis.num_basis, localRange_ext.volume); // Device copies: @@ -964,8 +1098,7 @@ test_fem_poisson_perp_consteps_3x(int poly_order, const int *cells, struct gkyl_ if (use_gpu) { rho_ho = mkarr(false, rho->ncomp, rho->size); phi_ho = mkarr(false, phi->ncomp, phi->size); - } - else { + } else { rho_ho = gkyl_array_acquire(rho); phi_ho = gkyl_array_acquire(phi); } @@ -975,24 +1108,25 @@ test_fem_poisson_perp_consteps_3x(int poly_order, const int *cells, struct gkyl_ gkyl_array_copy(rho, rho_ho); // Project the permittivity onto the basis. - double dg0norm = pow(sqrt(2.),dim); - gkyl_array_shiftc(eps, epsilon_0*dg0norm, 0*basis.num_basis); - gkyl_array_shiftc(eps, 0.*dg0norm, 1*basis.num_basis); - gkyl_array_shiftc(eps, epsilon_0*dg0norm, 2*basis.num_basis); + double dg0norm = pow(sqrt(2.), dim); + gkyl_array_shiftc(eps, epsilon_0 * dg0norm, 0 * basis.num_basis); + gkyl_array_shiftc(eps, 0. * dg0norm, 1 * basis.num_basis); + gkyl_array_shiftc(eps, epsilon_0 * dg0norm, 2 * basis.num_basis); // Project the analytic solution. gkyl_proj_on_basis_advance(projob_sol, 0.0, &localRange, phisol_ho); // FEM poisson solver. - struct gkyl_fem_poisson_perp *poisson = gkyl_fem_poisson_perp_new(&localRange, &grid, basis, &bcs, NULL, eps, NULL, use_gpu); + struct gkyl_fem_poisson_perp *poisson = + gkyl_fem_poisson_perp_new(&localRange, &grid, basis, &bcs, NULL, eps, NULL, use_gpu); -// struct gkyl_fem_parproj* smooth_op = gkyl_fem_parproj_new(&localRange, &grid, &localRange_ext, -// &basis, GKYL_FEM_PARPROJ_DIRICHLET, NULL, NULL, NULL, use_gpu); -// gkyl_fem_parproj_set_rhs(smooth_op, rho, rho); -// gkyl_fem_parproj_solve (smooth_op, rho); + // struct gkyl_fem_parproj* smooth_op = gkyl_fem_parproj_new(&localRange, &grid, &localRange_ext, + // &basis, GKYL_FEM_PARPROJ_DIRICHLET, NULL, NULL, NULL, use_gpu); + // gkyl_fem_parproj_set_rhs(smooth_op, rho, rho); + // gkyl_fem_parproj_solve (smooth_op, rho); // Check that the solver can be called multiple times without issue. - for (int i=0; i<2; i++) { + for (int i = 0; i < 2; i++) { // Set the RHS source. gkyl_fem_poisson_perp_set_rhs(poisson, rho); @@ -1000,134 +1134,183 @@ test_fem_poisson_perp_consteps_3x(int poly_order, const int *cells, struct gkyl_ gkyl_fem_poisson_perp_solve(poisson, phi); gkyl_array_copy(phi_ho, phi); - // gkyl_fem_parproj_set_rhs(smooth_op, phi, phi); - // gkyl_fem_parproj_solve (smooth_op, phi); - // gkyl_fem_parproj_release(smooth_op); + // gkyl_fem_parproj_set_rhs(smooth_op, phi, phi); + // gkyl_fem_parproj_solve (smooth_op, phi); + // gkyl_fem_parproj_release(smooth_op); if (bcs.lo_type[0] == GKYL_POISSON_PERIODIC && bcs.lo_type[1] == GKYL_POISSON_PERIODIC) { // Subtract the volume averaged sol from the numerical and analytic solutions. - // This is not strictly necessary, as the potential is only known up to + // This is not strictly necessary, as the potential is only known up to // constant shift, but it makes unit testing more robust across CPU/GPU. struct gkyl_array *sol_cellavg = gkyl_array_new(GKYL_DOUBLE, 1, localRange_ext.volume); double sol_avg[1]; // Factor accounting for normalization when subtracting a constant from a // DG field and the 1/N to properly compute the volume averaged RHS. - double mavgfac = -pow(sqrt(2.),dim); // /perpRange.volume; + double mavgfac = -pow(sqrt(2.), dim); // /perpRange.volume; // Subtract the volume averaged sol from the sol. gkyl_array_clear(sol_cellavg, 0.0); gkyl_dg_calc_average_range(&basis, 0, sol_cellavg, 0, phi_ho, localRange); - for (int kIdx=0; kIdxncomp, rho->size); phi_ho = mkarr(false, phi->ncomp, phi->size); - } - else { + } else { rho_ho = gkyl_array_acquire(rho); phi_ho = gkyl_array_acquire(phi); } @@ -1213,10 +1402,10 @@ test_fem_poisson_perp_consteps_3x_bias(int poly_order, const int *cells, struct gkyl_array_copy(rho, rho_ho); // Project the permittivity onto the basis. - double dg0norm = pow(sqrt(2.),dim); - gkyl_array_shiftc(eps, epsilon_0*dg0norm, 0*basis.num_basis); - gkyl_array_shiftc(eps, 0.*dg0norm, 1*basis.num_basis); - gkyl_array_shiftc(eps, epsilon_0*dg0norm, 2*basis.num_basis); + double dg0norm = pow(sqrt(2.), dim); + gkyl_array_shiftc(eps, epsilon_0 * dg0norm, 0 * basis.num_basis); + gkyl_array_shiftc(eps, 0. * dg0norm, 1 * basis.num_basis); + gkyl_array_shiftc(eps, epsilon_0 * dg0norm, 2 * basis.num_basis); // Project the analytic solution. gkyl_proj_on_basis_advance(projob_sol, 0.0, &localRange, phisol_ho); @@ -1225,23 +1414,24 @@ test_fem_poisson_perp_consteps_3x_bias(int poly_order, const int *cells, struct struct gkyl_poisson_bias_line bias = { .perp_dirs = {0, 2}, .perp_coords = {0.5, -M_PI}, // Location of the plane in the 'dir' dimension. - .val = 0., // Biasing value. + .val = 0. // Biasing value. }; struct gkyl_poisson_bias_line_list bll = { .num_bias_line = 1, // Number of bias lines. - .bl = &bias, + .bl = &bias }; // FEM poisson solver. - struct gkyl_fem_poisson_perp *poisson = gkyl_fem_poisson_perp_new(&localRange, &grid, basis, &bcs, &bll, eps, NULL, use_gpu); + struct gkyl_fem_poisson_perp *poisson = + gkyl_fem_poisson_perp_new(&localRange, &grid, basis, &bcs, &bll, eps, NULL, use_gpu); -// struct gkyl_fem_parproj* smooth_op = gkyl_fem_parproj_new(&localRange, &grid, &localRange_ext, -// &basis, GKYL_FEM_PARPROJ_DIRICHLET, NULL, NULL, NULL, use_gpu); -// gkyl_fem_parproj_set_rhs(smooth_op, rho, rho); -// gkyl_fem_parproj_solve (smooth_op, rho); + // struct gkyl_fem_parproj* smooth_op = gkyl_fem_parproj_new(&localRange, &grid, &localRange_ext, + // &basis, GKYL_FEM_PARPROJ_DIRICHLET, NULL, NULL, NULL, use_gpu); + // gkyl_fem_parproj_set_rhs(smooth_op, rho, rho); + // gkyl_fem_parproj_solve (smooth_op, rho); // Check that the solver can be called multiple times without issue. - for (int i=0; i<2; i++) { + for (int i = 0; i < 2; i++) { // Set the RHS source. gkyl_fem_poisson_perp_set_rhs(poisson, rho); @@ -1250,36 +1440,40 @@ test_fem_poisson_perp_consteps_3x_bias(int poly_order, const int *cells, struct } gkyl_array_copy(phi_ho, phi); -// gkyl_fem_parproj_set_rhs(smooth_op, phi, phi); -// gkyl_fem_parproj_solve (smooth_op, phi); -// gkyl_fem_parproj_release(smooth_op); + // gkyl_fem_parproj_set_rhs(smooth_op, phi, phi); + // gkyl_fem_parproj_solve (smooth_op, phi); + // gkyl_fem_parproj_release(smooth_op); -// double errL2 = error_L2norm(grid, localRange, basis, phi, phisol); -// printf("error L2 norm = %g\n",errL2); + // double errL2 = error_L2norm(grid, localRange, basis, phi, phisol); + // printf("error L2 norm = %g\n",errL2); if (poly_order == 1) { if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET)) { // Solution; checked convergence: - check_sol(&localRange, phi_ho, basis.num_basis, - get_sol_3x_biasB_p1_DxDx_DyDy(), 1.0, 1, 3, 1e-10); - } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC)) { + check_sol( + &localRange, phi_ho, basis.num_basis, get_sol_3x_biasB_p1_DxDx_DyDy(), 1.0, 1, 3, 1e-10 + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && + (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC + )) { // Solution; checked convergence: - check_sol(&localRange, phi_ho, basis.num_basis, - get_sol_3x_biasB_p1_DxDx_PyPy(), 1.0, 1, 3, 1e-10); + check_sol( + &localRange, phi_ho, basis.num_basis, get_sol_3x_biasB_p1_DxDx_PyPy(), 1.0, 1, 3, 1e-10 + ); } else { - TEST_CHECK( gkyl_compare(1., 2., 1e-10) ); + TEST_CHECK(gkyl_compare(1., 2., 1e-10)); TEST_MSG("This BC combination is not available"); } } else { - TEST_CHECK( gkyl_compare(1., 2., 1e-10) ); + TEST_CHECK(gkyl_compare(1., 2., 1e-10)); TEST_MSG("This poly_order is not available"); } -// gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_poisson_perp_3x_rho_1.gkyl"); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_poisson_perp_3x_phi_8x8x8_p1.gkyl"); -// gkyl_grid_sub_array_write(&grid, &localRange, 0, phisol_ho, "ctest_fem_poisson_perp_3x_phisol_8x8x8_p1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, rho_ho, "ctest_fem_poisson_perp_3x_rho_1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, phi_ho, "ctest_fem_poisson_perp_3x_phi_8x8x8_p1.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, 0, phisol_ho, "ctest_fem_poisson_perp_3x_phisol_8x8x8_p1.gkyl"); gkyl_fem_poisson_perp_release(poisson); gkyl_proj_on_basis_release(projob); @@ -1292,16 +1486,18 @@ test_fem_poisson_perp_consteps_3x_bias(int poly_order, const int *cells, struct gkyl_array_release(phi_ho); } -void test_fem_poisson_perp_2x_p1_periodic_consteps_ho() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_periodic_consteps_ho() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; test_fem_poisson_perp_consteps_2x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_2x_p1_dirichletx_consteps_ho() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_dirichletx_consteps_ho() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1310,8 +1506,9 @@ void test_fem_poisson_perp_2x_p1_dirichletx_consteps_ho() { test_fem_poisson_perp_consteps_2x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_ho() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_ho() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1320,8 +1517,9 @@ void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_ho() { test_fem_poisson_perp_consteps_2x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_ho() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_ho() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_NEUMANN; @@ -1330,8 +1528,9 @@ void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_ho() { test_fem_poisson_perp_consteps_2x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_update_ho() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_update_ho() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1340,8 +1539,9 @@ void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_update_ho() { test_fem_poisson_perp_consteps_2x_update(1, cells, bc_tv, false); } -void test_fem_poisson_perp_2x_p1_dirichletx_consteps_bias_ho() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_dirichletx_consteps_bias_ho() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1350,8 +1550,9 @@ void test_fem_poisson_perp_2x_p1_dirichletx_consteps_bias_ho() { test_fem_poisson_perp_consteps_2x_bias(1, cells, bc_tv, false); } -void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_bias_ho() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_bias_ho() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1360,8 +1561,9 @@ void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_bias_ho() { test_fem_poisson_perp_consteps_2x_bias(1, cells, bc_tv, false); } -void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_bias_ho() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_bias_ho() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_NEUMANN; @@ -1370,8 +1572,9 @@ void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_bias_ho() { test_fem_poisson_perp_consteps_2x_bias(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p1_periodicx_periodicy_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_periodicx_periodicy_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; @@ -1380,8 +1583,9 @@ void test_fem_poisson_perp_3x_p1_periodicx_periodicy_consteps_ho() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1394,8 +1598,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_ho() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1406,8 +1611,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_ho() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p1_periodicx_dirichlety_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_periodicx_dirichlety_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; @@ -1418,8 +1624,9 @@ void test_fem_poisson_perp_3x_p1_periodicx_dirichlety_consteps_ho() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1432,8 +1639,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_consteps_ho() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1446,8 +1654,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_consteps_ho() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1460,8 +1669,9 @@ void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_consteps_ho() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_NEUMANN; @@ -1474,8 +1684,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_consteps_ho() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1488,8 +1699,9 @@ void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_consteps_ho() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_bias_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_bias_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1502,8 +1714,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_bias_ho() { test_fem_poisson_perp_consteps_3x_bias(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_bias_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_bias_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1514,8 +1727,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_bias_ho() { test_fem_poisson_perp_consteps_3x_bias(1, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p2_periodicx_periodicy_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_periodicx_periodicy_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; @@ -1524,8 +1738,9 @@ void test_fem_poisson_perp_3x_p2_periodicx_periodicy_consteps_ho() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1538,8 +1753,9 @@ void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_consteps_ho() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p2_dirichletx_periodicy_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_dirichletx_periodicy_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1550,8 +1766,9 @@ void test_fem_poisson_perp_3x_p2_dirichletx_periodicy_consteps_ho() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p2_periodicx_dirichlety_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_periodicx_dirichlety_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; @@ -1562,8 +1779,9 @@ void test_fem_poisson_perp_3x_p2_periodicx_dirichlety_consteps_ho() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p2_dirichletx_neumanny_dirichlety_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_dirichletx_neumanny_dirichlety_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1576,8 +1794,9 @@ void test_fem_poisson_perp_3x_p2_dirichletx_neumanny_dirichlety_consteps_ho() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_neumanny_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_neumanny_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1590,8 +1809,9 @@ void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_neumanny_consteps_ho() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_dirichlety_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_dirichlety_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1604,8 +1824,9 @@ void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_dirichlety_consteps_ho() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p2_dirichletx_neumannx_dirichlety_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_dirichletx_neumannx_dirichlety_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_NEUMANN; @@ -1618,8 +1839,9 @@ void test_fem_poisson_perp_3x_p2_dirichletx_neumannx_dirichlety_consteps_ho() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, false); } -void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_periodicy_consteps_ho() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_periodicy_consteps_ho() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1633,16 +1855,18 @@ void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_periodicy_consteps_ho() { } #ifdef GKYL_HAVE_CUDA -void test_fem_poisson_perp_2x_p1_periodic_consteps_dev() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_periodic_consteps_dev() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; test_fem_poisson_perp_consteps_2x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_2x_p1_dirichletx_consteps_dev() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_dirichletx_consteps_dev() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1651,8 +1875,9 @@ void test_fem_poisson_perp_2x_p1_dirichletx_consteps_dev() { test_fem_poisson_perp_consteps_2x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_dev() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_dev() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1661,8 +1886,9 @@ void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_dev() { test_fem_poisson_perp_consteps_2x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_dev() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_dev() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_NEUMANN; @@ -1671,8 +1897,9 @@ void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_dev() { test_fem_poisson_perp_consteps_2x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_update_dev() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_update_dev() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1681,8 +1908,9 @@ void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_update_dev() { test_fem_poisson_perp_consteps_2x_update(1, cells, bc_tv, true); } -void test_fem_poisson_perp_2x_p1_dirichletx_consteps_bias_dev() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_dirichletx_consteps_bias_dev() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1691,8 +1919,9 @@ void test_fem_poisson_perp_2x_p1_dirichletx_consteps_bias_dev() { test_fem_poisson_perp_consteps_2x_bias(1, cells, bc_tv, true); } -void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_bias_dev() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_bias_dev() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1701,8 +1930,9 @@ void test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_bias_dev() { test_fem_poisson_perp_consteps_2x_bias(1, cells, bc_tv, true); } -void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_bias_dev() { - int cells[] = {8,8}; +void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_bias_dev() +{ + int cells[] = {8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_NEUMANN; @@ -1711,8 +1941,9 @@ void test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_bias_dev() { test_fem_poisson_perp_consteps_2x_bias(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p1_periodicx_periodicy_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_periodicx_periodicy_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; @@ -1721,8 +1952,9 @@ void test_fem_poisson_perp_3x_p1_periodicx_periodicy_consteps_dev() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1735,8 +1967,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_dev() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1747,8 +1980,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_dev() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p1_periodicx_dirichlety_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_periodicx_dirichlety_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; @@ -1759,8 +1993,9 @@ void test_fem_poisson_perp_3x_p1_periodicx_dirichlety_consteps_dev() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1773,8 +2008,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_consteps_dev() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1787,8 +2023,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_consteps_dev() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1801,8 +2038,9 @@ void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_consteps_dev() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_NEUMANN; @@ -1815,8 +2053,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_consteps_dev() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1829,8 +2068,9 @@ void test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_consteps_dev() { test_fem_poisson_perp_consteps_3x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_bias_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_bias_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1843,8 +2083,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_bias_dev() { test_fem_poisson_perp_consteps_3x_bias(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_bias_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_bias_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1855,8 +2096,9 @@ void test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_bias_dev() { test_fem_poisson_perp_consteps_3x_bias(1, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p2_periodicx_periodicy_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_periodicx_periodicy_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; @@ -1865,8 +2107,9 @@ void test_fem_poisson_perp_3x_p2_periodicx_periodicy_consteps_dev() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1879,8 +2122,9 @@ void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_consteps_dev() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p2_dirichletx_periodicy_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_dirichletx_periodicy_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1891,8 +2135,9 @@ void test_fem_poisson_perp_3x_p2_dirichletx_periodicy_consteps_dev() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p2_periodicx_dirichlety_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_periodicx_dirichlety_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; @@ -1903,8 +2148,9 @@ void test_fem_poisson_perp_3x_p2_periodicx_dirichlety_consteps_dev() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p2_dirichletx_neumanny_dirichlety_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_dirichletx_neumanny_dirichlety_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1917,8 +2163,9 @@ void test_fem_poisson_perp_3x_p2_dirichletx_neumanny_dirichlety_consteps_dev() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_neumanny_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_neumanny_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1931,8 +2178,9 @@ void test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_neumanny_consteps_dev() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_dirichlety_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_dirichlety_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1945,8 +2193,9 @@ void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_dirichlety_consteps_dev() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p2_dirichletx_neumannx_dirichlety_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_dirichletx_neumannx_dirichlety_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_NEUMANN; @@ -1959,8 +2208,9 @@ void test_fem_poisson_perp_3x_p2_dirichletx_neumannx_dirichlety_consteps_dev() { test_fem_poisson_perp_consteps_3x(2, cells, bc_tv, true); } -void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_periodicy_consteps_dev() { - int cells[] = {8,8,8}; +void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_periodicy_consteps_dev() +{ + int cells[] = {8, 8, 8}; struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_NEUMANN; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -1976,26 +2226,43 @@ void test_fem_poisson_perp_3x_p2_neumannx_dirichletx_periodicy_consteps_dev() { #endif TEST_LIST = { - { "test_fem_poisson_perp_2x_p1_periodicx_ho", test_fem_poisson_perp_2x_p1_periodic_consteps_ho }, - { "test_fem_poisson_perp_2x_p1_dirichletx_ho", test_fem_poisson_perp_2x_p1_dirichletx_consteps_ho }, - { "test_fem_poisson_perp_2x_p1_neumannx_dirichletx_ho", test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_ho }, - { "test_fem_poisson_perp_2x_p1_dirichletx_neumannx_ho", test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_ho }, - { "test_fem_poisson_perp_2x_p1_neumannx_dirichletx_update_ho", test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_update_ho }, - { "test_fem_poisson_perp_2x_p1_dirichletx_bias_ho", test_fem_poisson_perp_2x_p1_dirichletx_consteps_bias_ho }, - { "test_fem_poisson_perp_2x_p1_neumannx_dirichletx_bias_ho", test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_bias_ho }, - { "test_fem_poisson_perp_2x_p1_dirichletx_neumannx_bias_ho", test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_bias_ho }, - - { "test_fem_poisson_perp_3x_p1_periodicx_periodicy_ho", test_fem_poisson_perp_3x_p1_periodicx_periodicy_consteps_ho }, - { "test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_ho", test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_ho }, - { "test_fem_poisson_perp_3x_p1_dirichletx_periodicy_ho", test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_ho }, - { "test_fem_poisson_perp_3x_p1_periodicx_dirichlety_ho", test_fem_poisson_perp_3x_p1_periodicx_dirichlety_consteps_ho }, - { "test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_ho", test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_consteps_ho }, - { "test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_ho", test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_consteps_ho }, - { "test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_ho", test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_consteps_ho }, - { "test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_ho", test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_consteps_ho }, - { "test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_ho", test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_consteps_ho }, - { "test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_bias_ho", test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_bias_ho }, - { "test_fem_poisson_perp_3x_p1_dirichletx_periodicy_bias_ho", test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_bias_ho }, + {"test_fem_poisson_perp_2x_p1_periodicx_ho", test_fem_poisson_perp_2x_p1_periodic_consteps_ho}, + {"test_fem_poisson_perp_2x_p1_dirichletx_ho", test_fem_poisson_perp_2x_p1_dirichletx_consteps_ho}, + {"test_fem_poisson_perp_2x_p1_neumannx_dirichletx_ho", + test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_ho}, + {"test_fem_poisson_perp_2x_p1_dirichletx_neumannx_ho", + test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_ho}, + {"test_fem_poisson_perp_2x_p1_neumannx_dirichletx_update_ho", + test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_update_ho}, + {"test_fem_poisson_perp_2x_p1_dirichletx_bias_ho", + test_fem_poisson_perp_2x_p1_dirichletx_consteps_bias_ho}, + {"test_fem_poisson_perp_2x_p1_neumannx_dirichletx_bias_ho", + test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_bias_ho}, + {"test_fem_poisson_perp_2x_p1_dirichletx_neumannx_bias_ho", + test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_bias_ho}, + + {"test_fem_poisson_perp_3x_p1_periodicx_periodicy_ho", + test_fem_poisson_perp_3x_p1_periodicx_periodicy_consteps_ho}, + {"test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_ho", + test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_ho}, + {"test_fem_poisson_perp_3x_p1_dirichletx_periodicy_ho", + test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_ho}, + {"test_fem_poisson_perp_3x_p1_periodicx_dirichlety_ho", + test_fem_poisson_perp_3x_p1_periodicx_dirichlety_consteps_ho}, + {"test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_ho", + test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_consteps_ho}, + {"test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_ho", + test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_consteps_ho}, + {"test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_ho", + test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_consteps_ho}, + {"test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_ho", + test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_consteps_ho}, + {"test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_ho", + test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_consteps_ho}, + {"test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_bias_ho", + test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_bias_ho}, + {"test_fem_poisson_perp_3x_p1_dirichletx_periodicy_bias_ho", + test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_bias_ho}, // { "test_fem_poisson_perp_3x_p2_periodicx_periodicy_ho", test_fem_poisson_perp_3x_p2_periodicx_periodicy_consteps_ho }, // { "test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_ho", test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_consteps_ho }, // { "test_fem_poisson_perp_3x_p2_dirichletx_periodicy_ho", test_fem_poisson_perp_3x_p2_dirichletx_periodicy_consteps_ho }, @@ -2006,26 +2273,44 @@ TEST_LIST = { // { "test_fem_poisson_perp_3x_p2_dirichletx_neumannx_dirichlety_ho", test_fem_poisson_perp_3x_p2_dirichletx_neumannx_dirichlety_consteps_ho }, // { "test_fem_poisson_perp_3x_p2_neumannx_dirichletx_periodicy_ho", test_fem_poisson_perp_3x_p2_neumannx_dirichletx_periodicy_consteps_ho }, #ifdef GKYL_HAVE_CUDA - { "test_fem_poisson_perp_2x_p1_periodicx_dev", test_fem_poisson_perp_2x_p1_periodic_consteps_dev }, - { "test_fem_poisson_perp_2x_p1_dirichletx_dev", test_fem_poisson_perp_2x_p1_dirichletx_consteps_dev }, - { "test_fem_poisson_perp_2x_p1_neumannx_dirichletx_dev", test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_dev }, - { "test_fem_poisson_perp_2x_p1_dirichletx_neumannx_dev", test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_dev }, - { "test_fem_poisson_perp_2x_p1_neumannx_dirichletx_update_dev", test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_update_dev }, - { "test_fem_poisson_perp_2x_p1_dirichletx_bias_dev", test_fem_poisson_perp_2x_p1_dirichletx_consteps_bias_dev }, - { "test_fem_poisson_perp_2x_p1_neumannx_dirichletx_bias_dev", test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_bias_dev }, - { "test_fem_poisson_perp_2x_p1_dirichletx_neumannx_bias_dev", test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_bias_dev }, - - { "test_fem_poisson_perp_3x_p1_periodicx_periodicy_dev", test_fem_poisson_perp_3x_p1_periodicx_periodicy_consteps_dev }, - { "test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_dev", test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_dev }, - { "test_fem_poisson_perp_3x_p1_dirichletx_periodicy_dev", test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_dev }, - { "test_fem_poisson_perp_3x_p1_periodicx_dirichlety_dev", test_fem_poisson_perp_3x_p1_periodicx_dirichlety_consteps_dev }, - { "test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_dev", test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_consteps_dev }, - { "test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_dev", test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_consteps_dev }, - { "test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_dev", test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_consteps_dev }, - { "test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_dev", test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_consteps_dev }, - { "test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_dev", test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_consteps_dev }, - { "test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_bias_dev", test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_bias_dev }, - { "test_fem_poisson_perp_3x_p1_dirichletx_periodicy_bias_dev", test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_bias_dev }, + {"test_fem_poisson_perp_2x_p1_periodicx_dev", test_fem_poisson_perp_2x_p1_periodic_consteps_dev}, + {"test_fem_poisson_perp_2x_p1_dirichletx_dev", test_fem_poisson_perp_2x_p1_dirichletx_consteps_dev + }, + {"test_fem_poisson_perp_2x_p1_neumannx_dirichletx_dev", + test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_dev}, + {"test_fem_poisson_perp_2x_p1_dirichletx_neumannx_dev", + test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_dev}, + {"test_fem_poisson_perp_2x_p1_neumannx_dirichletx_update_dev", + test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_update_dev}, + {"test_fem_poisson_perp_2x_p1_dirichletx_bias_dev", + test_fem_poisson_perp_2x_p1_dirichletx_consteps_bias_dev}, + {"test_fem_poisson_perp_2x_p1_neumannx_dirichletx_bias_dev", + test_fem_poisson_perp_2x_p1_neumannx_dirichletx_consteps_bias_dev}, + {"test_fem_poisson_perp_2x_p1_dirichletx_neumannx_bias_dev", + test_fem_poisson_perp_2x_p1_dirichletx_neumannx_consteps_bias_dev}, + + {"test_fem_poisson_perp_3x_p1_periodicx_periodicy_dev", + test_fem_poisson_perp_3x_p1_periodicx_periodicy_consteps_dev}, + {"test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_dev", + test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_dev}, + {"test_fem_poisson_perp_3x_p1_dirichletx_periodicy_dev", + test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_dev}, + {"test_fem_poisson_perp_3x_p1_periodicx_dirichlety_dev", + test_fem_poisson_perp_3x_p1_periodicx_dirichlety_consteps_dev}, + {"test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_dev", + test_fem_poisson_perp_3x_p1_dirichletx_neumanny_dirichlety_consteps_dev}, + {"test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_dev", + test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_neumanny_consteps_dev}, + {"test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_dev", + test_fem_poisson_perp_3x_p1_neumannx_dirichletx_dirichlety_consteps_dev}, + {"test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_dev", + test_fem_poisson_perp_3x_p1_dirichletx_neumannx_dirichlety_consteps_dev}, + {"test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_dev", + test_fem_poisson_perp_3x_p1_neumannx_dirichletx_periodicy_consteps_dev}, + {"test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_bias_dev", + test_fem_poisson_perp_3x_p1_dirichletx_dirichlety_consteps_bias_dev}, + {"test_fem_poisson_perp_3x_p1_dirichletx_periodicy_bias_dev", + test_fem_poisson_perp_3x_p1_dirichletx_periodicy_consteps_bias_dev}, // { "test_fem_poisson_perp_3x_p2_periodicx_periodicy_dev", test_fem_poisson_perp_3x_p2_periodicx_periodicy_consteps_dev }, // { "test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_dev", test_fem_poisson_perp_3x_p2_dirichletx_dirichlety_consteps_dev }, // { "test_fem_poisson_perp_3x_p2_dirichletx_periodicy_dev", test_fem_poisson_perp_3x_p2_dirichletx_periodicy_consteps_dev }, @@ -2036,2558 +2321,4270 @@ TEST_LIST = { // { "test_fem_poisson_perp_3x_p2_dirichletx_neumannx_dirichlety_dev", test_fem_poisson_perp_3x_p2_dirichletx_neumannx_dirichlety_consteps_dev }, // { "test_fem_poisson_perp_3x_p2_neumannx_dirichletx_periodicy_dev", test_fem_poisson_perp_3x_p2_neumannx_dirichletx_periodicy_consteps_dev }, #endif - { NULL, NULL }, + {NULL, NULL} }; - // ============================================================ // Solution array definitions (forward-declared above). // ============================================================ -static const double * -get_sol_2x_p1_DxDx(void) +static const double *get_sol_2x_p1_DxDx(void) { static const double sol[256] = { - 0.0592784971266791, 0.0342244562732445, -0.0076848087077185, -0.004436826376072 , - 0.0326575388702468, 0.0188548388578077, -0.0076848087077184, -0.004436826376072 , - 0.0060365806138147, 0.0034852214423708, -0.0076848087077184, -0.004436826376072 , - -0.0205843776426173, -0.011884395973066 , -0.0076848087077184, -0.004436826376072 , - -0.0472053358990496, -0.0272540133885028, -0.0076848087077183, -0.004436826376072 , - -0.0738262941554814, -0.0426236308039397, -0.0076848087077184, -0.004436826376072 , - -0.1004472524119136, -0.0579932482193765, -0.0076848087077186, -0.004436826376072 , - -0.1270682106683453, -0.0733628656348134, -0.0076848087077185, -0.004436826376072 , - - 0.1515053065818721, 0.0190227169922115, -0.0196410056887546, -0.0024660871694134, - 0.0834668670525276, 0.0104799404455762, -0.0196410056887545, -0.0024660871694134, - 0.0154284275231832, 0.0019371638989408, -0.0196410056887545, -0.0024660871694134, - -0.0526100120061611, -0.0066056126476946, -0.0196410056887545, -0.0024660871694134, - -0.1206484515355057, -0.0151483891943299, -0.0196410056887544, -0.0024660871694134, - -0.1886868910648499, -0.0236911657409653, -0.0196410056887545, -0.0024660871694134, - -0.2567253305941943, -0.0322339422876006, -0.0196410056887547, -0.0024660871694134, - -0.3247637701235385, -0.040776718834236 , -0.0196410056887545, -0.0024660871694134, - - 0.1936336022589356, 0.0053000658574412, -0.0251024783837958, -0.0006870955612404, - 0.1066760663456682, 0.0029198970139942, -0.0251024783837957, -0.0006870955612404, - 0.0197185304324009, 0.0005397281705472, -0.0251024783837957, -0.0006870955612404, - -0.0672390054808664, -0.0018404406728998, -0.0251024783837957, -0.0006870955612404, - -0.1541965413941337, -0.0042206095163468, -0.0251024783837957, -0.0006870955612405, - -0.2411540773074009, -0.0066007783597938, -0.0251024783837957, -0.0006870955612404, - -0.3281116132206683, -0.0089809472032408, -0.0251024783837958, -0.0006870955612404, - -0.4150691491339354, -0.0113611160466878, -0.0251024783837957, -0.0006870955612404, - - 0.192494999673069 , -0.0059574383668913, -0.0249548710136595, 0.000772316716123 , - 0.1060487906890969, -0.0032820547831718, -0.0249548710136595, 0.000772316716123 , - 0.0196025817051248, -0.0006066711994523, -0.0249548710136594, 0.000772316716123 , - -0.0668436272788473, 0.0020687123842672, -0.0249548710136594, 0.000772316716123 , - -0.1532898362628194, 0.0047440959679867, -0.0249548710136594, 0.000772316716123 , - -0.2397360452467914, 0.0074194795517062, -0.0249548710136595, 0.000772316716123 , - -0.3261822542307636, 0.0100948631354257, -0.0249548710136595, 0.000772316716123 , - -0.4126284632147356, 0.0127702467191452, -0.0249548710136594, 0.000772316716123 , - - 0.1583369220970716, -0.013763736916611 , -0.0205266499095721, 0.0017843179303531, - 0.0872305209919558, -0.0075826782921555, -0.020526649909572, 0.0017843179303531, - 0.0161241198868402, -0.0014016196677002, -0.020526649909572, 0.0017843179303531, - -0.0549822812182755, 0.0047794389567552, -0.020526649909572, 0.0017843179303531, - -0.1260886823233912, 0.0109604975812106, -0.020526649909572, 0.0017843179303531, - -0.1971950834285068, 0.017141556205666 , -0.020526649909572, 0.0017843179303531, - -0.2683014845336226, 0.0233226148301214, -0.020526649909572, 0.0017843179303531, - -0.3394078856387381, 0.0295036734545768, -0.020526649909572, 0.0017843179303531, - - 0.1048226005613422, -0.0171327710275426, -0.0135891035131684, 0.0022210763491261, - 0.0577485651331015, -0.0094387368591906, -0.0135891035131684, 0.0022210763491261, - 0.0106745297048609, -0.0017447026908387, -0.0135891035131683, 0.0022210763491261, - -0.0363995057233797, 0.0059493314775132, -0.0135891035131683, 0.0022210763491261, - -0.0834735411516203, 0.0136433656458652, -0.0135891035131683, 0.0022210763491261, - -0.1305475765798609, 0.0213373998142171, -0.0135891035131683, 0.0022210763491261, - -0.1776216120081016, 0.0290314339825691, -0.0135891035131684, 0.0022210763491261, - -0.2246956474363422, 0.036725468150921 , -0.0135891035131683, 0.0022210763491261, - - 0.0490310738538797, -0.0150784819355111, -0.0063563423764922, 0.0019547602401182, - 0.0270120579611045, -0.0083069938305107, -0.0063563423764922, 0.0019547602401182, - 0.0049930420683294, -0.0015355057255103, -0.0063563423764922, 0.0019547602401182, - -0.0170259738244458, 0.0052359823794901, -0.0063563423764922, 0.0019547602401182, - -0.0390449897172209, 0.0120074704844905, -0.0063563423764922, 0.0019547602401182, - -0.0610640056099961, 0.0187789585894908, -0.0063563423764922, 0.0019547602401182, - -0.0830830215027712, 0.0255504466944912, -0.0063563423764922, 0.0019547602401182, - -0.1051020373955464, 0.0323219347994916, -0.0063563423764922, 0.0019547602401182, - - 0.0114571885202825, -0.0066148108763414, -0.001485299161996, 0.0008575378710055, - 0.0063119612942494, -0.0036442125523494, -0.001485299161996, 0.0008575378710055, - 0.0011667340682163, -0.0006736142283574, -0.001485299161996, 0.0008575378710055, - -0.0039784931578168, 0.0022969840956346, -0.001485299161996, 0.0008575378710055, - -0.0091237203838499, 0.0052675824196266, -0.001485299161996, 0.0008575378710055, - -0.014268947609883 , 0.0082381807436186, -0.001485299161996, 0.0008575378710055, - -0.0194141748359161, 0.0112087790676106, -0.001485299161996, 0.0008575378710055, - -0.0245594020619492, 0.0141793773916026, -0.001485299161996, 0.0008575378710055, + 0.0592784971266791, 0.0342244562732445, -0.0076848087077185, -0.004436826376072, + 0.0326575388702468, 0.0188548388578077, -0.0076848087077184, -0.004436826376072, + 0.0060365806138147, 0.0034852214423708, -0.0076848087077184, -0.004436826376072, + -0.0205843776426173, -0.011884395973066, -0.0076848087077184, -0.004436826376072, + -0.0472053358990496, -0.0272540133885028, -0.0076848087077183, -0.004436826376072, + -0.0738262941554814, -0.0426236308039397, -0.0076848087077184, -0.004436826376072, + -0.1004472524119136, -0.0579932482193765, -0.0076848087077186, -0.004436826376072, + -0.1270682106683453, -0.0733628656348134, -0.0076848087077185, -0.004436826376072, + + 0.1515053065818721, 0.0190227169922115, -0.0196410056887546, -0.0024660871694134, + 0.0834668670525276, 0.0104799404455762, -0.0196410056887545, -0.0024660871694134, + 0.0154284275231832, 0.0019371638989408, -0.0196410056887545, -0.0024660871694134, + -0.0526100120061611, -0.0066056126476946, -0.0196410056887545, -0.0024660871694134, + -0.1206484515355057, -0.0151483891943299, -0.0196410056887544, -0.0024660871694134, + -0.1886868910648499, -0.0236911657409653, -0.0196410056887545, -0.0024660871694134, + -0.2567253305941943, -0.0322339422876006, -0.0196410056887547, -0.0024660871694134, + -0.3247637701235385, -0.040776718834236, -0.0196410056887545, -0.0024660871694134, + + 0.1936336022589356, 0.0053000658574412, -0.0251024783837958, -0.0006870955612404, + 0.1066760663456682, 0.0029198970139942, -0.0251024783837957, -0.0006870955612404, + 0.0197185304324009, 0.0005397281705472, -0.0251024783837957, -0.0006870955612404, + -0.0672390054808664, -0.0018404406728998, -0.0251024783837957, -0.0006870955612404, + -0.1541965413941337, -0.0042206095163468, -0.0251024783837957, -0.0006870955612405, + -0.2411540773074009, -0.0066007783597938, -0.0251024783837957, -0.0006870955612404, + -0.3281116132206683, -0.0089809472032408, -0.0251024783837958, -0.0006870955612404, + -0.4150691491339354, -0.0113611160466878, -0.0251024783837957, -0.0006870955612404, + + 0.192494999673069, -0.0059574383668913, -0.0249548710136595, 0.000772316716123, + 0.1060487906890969, -0.0032820547831718, -0.0249548710136595, 0.000772316716123, + 0.0196025817051248, -0.0006066711994523, -0.0249548710136594, 0.000772316716123, + -0.0668436272788473, 0.0020687123842672, -0.0249548710136594, 0.000772316716123, + -0.1532898362628194, 0.0047440959679867, -0.0249548710136594, 0.000772316716123, + -0.2397360452467914, 0.0074194795517062, -0.0249548710136595, 0.000772316716123, + -0.3261822542307636, 0.0100948631354257, -0.0249548710136595, 0.000772316716123, + -0.4126284632147356, 0.0127702467191452, -0.0249548710136594, 0.000772316716123, + + 0.1583369220970716, -0.013763736916611, -0.0205266499095721, 0.0017843179303531, + 0.0872305209919558, -0.0075826782921555, -0.020526649909572, 0.0017843179303531, + 0.0161241198868402, -0.0014016196677002, -0.020526649909572, 0.0017843179303531, + -0.0549822812182755, 0.0047794389567552, -0.020526649909572, 0.0017843179303531, + -0.1260886823233912, 0.0109604975812106, -0.020526649909572, 0.0017843179303531, + -0.1971950834285068, 0.017141556205666, -0.020526649909572, 0.0017843179303531, + -0.2683014845336226, 0.0233226148301214, -0.020526649909572, 0.0017843179303531, + -0.3394078856387381, 0.0295036734545768, -0.020526649909572, 0.0017843179303531, + + 0.1048226005613422, -0.0171327710275426, -0.0135891035131684, 0.0022210763491261, + 0.0577485651331015, -0.0094387368591906, -0.0135891035131684, 0.0022210763491261, + 0.0106745297048609, -0.0017447026908387, -0.0135891035131683, 0.0022210763491261, + -0.0363995057233797, 0.0059493314775132, -0.0135891035131683, 0.0022210763491261, + -0.0834735411516203, 0.0136433656458652, -0.0135891035131683, 0.0022210763491261, + -0.1305475765798609, 0.0213373998142171, -0.0135891035131683, 0.0022210763491261, + -0.1776216120081016, 0.0290314339825691, -0.0135891035131684, 0.0022210763491261, + -0.2246956474363422, 0.036725468150921, -0.0135891035131683, 0.0022210763491261, + + 0.0490310738538797, -0.0150784819355111, -0.0063563423764922, 0.0019547602401182, + 0.0270120579611045, -0.0083069938305107, -0.0063563423764922, 0.0019547602401182, + 0.0049930420683294, -0.0015355057255103, -0.0063563423764922, 0.0019547602401182, + -0.0170259738244458, 0.0052359823794901, -0.0063563423764922, 0.0019547602401182, + -0.0390449897172209, 0.0120074704844905, -0.0063563423764922, 0.0019547602401182, + -0.0610640056099961, 0.0187789585894908, -0.0063563423764922, 0.0019547602401182, + -0.0830830215027712, 0.0255504466944912, -0.0063563423764922, 0.0019547602401182, + -0.1051020373955464, 0.0323219347994916, -0.0063563423764922, 0.0019547602401182, + + 0.0114571885202825, -0.0066148108763414, -0.001485299161996, 0.0008575378710055, + 0.0063119612942494, -0.0036442125523494, -0.001485299161996, 0.0008575378710055, + 0.0011667340682163, -0.0006736142283574, -0.001485299161996, 0.0008575378710055, + -0.0039784931578168, 0.0022969840956346, -0.001485299161996, 0.0008575378710055, + -0.0091237203838499, 0.0052675824196266, -0.001485299161996, 0.0008575378710055, + -0.014268947609883, 0.0082381807436186, -0.001485299161996, 0.0008575378710055, + -0.0194141748359161, 0.0112087790676106, -0.001485299161996, 0.0008575378710055, + -0.0245594020619492, 0.0141793773916026, -0.001485299161996, 0.0008575378710055 }; return sol; } -static const double * -get_sol_2x_p1_NxDx(void) +static const double *get_sol_2x_p1_NxDx(void) { static const double sol[256] = { - 0.2779969376054874, -0.0077857556587993, -0.0360392619648285, 0.00100933805314 , - 0.153153272024753 , -0.0042893060786969, -0.0360392619648284, 0.00100933805314 , - 0.0283096064440185, -0.0007928564985946, -0.0360392619648283, 0.00100933805314 , - -0.0965340591367159, 0.0027035930815078, -0.0360392619648281, 0.00100933805314 , - -0.2213777247174505, 0.0062000426616102, -0.0360392619648281, 0.00100933805314 , - -0.346221390298185 , 0.0096964922417126, -0.0360392619648282, 0.00100933805314 , - -0.4710650558789194, 0.0131929418218149, -0.0360392619648277, 0.00100933805314 , - -0.5959087214596539, 0.0166893914019174, -0.0360392619648275, 0.00100933805314 , - - 0.226190519948558 , -0.0221246935211791, -0.0293231266236292, 0.0028682244940153, - 0.1246122296507558, -0.0121888724188829, -0.0293231266236291, 0.0028682244940153, - 0.0230339393529535, -0.0022530513165867, -0.029323126623629, 0.0028682244940153, - -0.0785443509448487, 0.0076827697857095, -0.0293231266236288, 0.0028682244940153, - -0.180122641242651 , 0.0176185908880057, -0.0293231266236288, 0.0028682244940153, - -0.2817009315404533, 0.027554411990302 , -0.0293231266236289, 0.0028682244940153, - -0.3832792218382556, 0.0374902330925981, -0.0293231266236285, 0.0028682244940153, - -0.4848575121360578, 0.0474260541948944, -0.0293231266236283, 0.0028682244940153, - - 0.1311172040286984, -0.0327659110179022, -0.0169979112172524, 0.0042477419386764, - 0.0722347123270466, -0.0180513013074449, -0.0169979112172524, 0.0042477419386764, - 0.0133522206253946, -0.0033366915969877, -0.0169979112172523, 0.0042477419386764, - -0.0455302710762573, 0.0113779181134696, -0.0169979112172521, 0.0042477419386764, - -0.1044127627779092, 0.0260925278239268, -0.0169979112172521, 0.0042477419386764, - -0.1632952544795612, 0.040807137534384 , -0.0169979112172522, 0.0042477419386764, - -0.2221777461812131, 0.0555217472448413, -0.0169979112172518, 0.0042477419386764, - -0.2810602378828649, 0.0702363569552985, -0.0169979112172516, 0.0042477419386764, - - 0.0098560286339075, -0.0372442612385308, -0.001277726297742, 0.0048283110563137, - 0.0054298549021959, -0.0205185011099672, -0.001277726297742, 0.0048283110563137, - 0.0010036811704842, -0.0037927409814036, -0.0012777262977419, 0.0048283110563137, - -0.0034224925612274, 0.0129330191471601, -0.0012777262977417, 0.0048283110563136, - -0.0078486662929391, 0.0296587792757237, -0.0012777262977417, 0.0048283110563136, - -0.0122748400246508, 0.0463845394042873, -0.0012777262977418, 0.0048283110563137, - -0.0167010137563625, 0.0631102995328509, -0.0012777262977415, 0.0048283110563136, - -0.0211271874880741, 0.0798360596614145, -0.0012777262977413, 0.0048283110563136, - - -0.1119744480538166, -0.0330945972726272, 0.0145162623068366, 0.0042903525161177, - -0.0616886403509404, -0.0182323801920337, 0.0145162623068366, 0.0042903525161177, - -0.0114028326480642, -0.0033701631114402, 0.0145162623068367, 0.0042903525161177, - 0.038882975054812 , 0.0114920539691533, 0.0145162623068368, 0.0042903525161176, - 0.0891687827576881, 0.0263542710497468, 0.0145162623068368, 0.0042903525161176, - 0.1394545904605643, 0.0412164881303402, 0.0145162623068367, 0.0042903525161176, - 0.1897403981634405, 0.0560787052109337, 0.014516262306837, 0.0042903525161176, - 0.2400262058663167, 0.0709409222915272, 0.0145162623068371, 0.0042903525161176, - - -0.2002161484584767, -0.0178517722097536, 0.0259558334923958, 0.0023142869872789, - -0.1103025037352214, -0.0098348469192286, 0.0259558334923958, 0.0023142869872789, - -0.0203888590119662, -0.0018179216287036, 0.0259558334923959, 0.0023142869872789, - 0.0695247857112891, 0.0061990036618213, 0.025955833492396, 0.0023142869872788, - 0.1594384304345443, 0.0142159289523463, 0.025955833492396, 0.0023142869872788, - 0.2493520751577995, 0.0222328542428713, 0.0259558334923959, 0.0023142869872789, - 0.3392657198810548, 0.0302497795333963, 0.0259558334923961, 0.0023142869872788, - 0.42917936460431 , 0.0382667048239213, 0.0259558334923963, 0.0023142869872788, - - -0.2121714756100758, 0.0109493608605278, 0.0275057108788264, -0.0014194648610122, - -0.1168888981292207, 0.006032190342864 , 0.0275057108788265, -0.0014194648610122, - -0.0216063206483658, 0.0011150198252003, 0.0275057108788265, -0.0014194648610122, - 0.0736762568324892, -0.0038021506924635, 0.0275057108788265, -0.0014194648610122, - 0.1689588343133442, -0.0087193212101273, 0.0275057108788266, -0.0014194648610122, - 0.2642414117941991, -0.013636491727791 , 0.0275057108788265, -0.0014194648610122, - 0.3595239892750541, -0.0185536622454548, 0.0275057108788266, -0.0014194648610123, - 0.4548065667559091, -0.0234708327631186, 0.0275057108788267, -0.0014194648610123, - - -0.0966033131446177, 0.0557739488486548, 0.0125235628099973, -0.0072304823595651, - -0.053220418987227 , 0.0307268232286602, 0.0125235628099973, -0.0072304823595651, - -0.0098375248298362, 0.0056796976086655, 0.0125235628099973, -0.0072304823595651, - 0.0335453693275546, -0.0193674280113291, 0.0125235628099973, -0.0072304823595651, - 0.0769282634849454, -0.0444145536313237, 0.0125235628099973, -0.0072304823595651, - 0.1203111576423362, -0.0694616792513183, 0.0125235628099973, -0.0072304823595651, - 0.163694051799727 , -0.0945088048713129, 0.0125235628099974, -0.0072304823595652, - 0.2070769459571177, -0.1195559304913075, 0.0125235628099974, -0.0072304823595652, + 0.2779969376054874, -0.0077857556587993, -0.0360392619648285, 0.00100933805314, + 0.153153272024753, -0.0042893060786969, -0.0360392619648284, 0.00100933805314, + 0.0283096064440185, -0.0007928564985946, -0.0360392619648283, 0.00100933805314, + -0.0965340591367159, 0.0027035930815078, -0.0360392619648281, 0.00100933805314, + -0.2213777247174505, 0.0062000426616102, -0.0360392619648281, 0.00100933805314, + -0.346221390298185, 0.0096964922417126, -0.0360392619648282, 0.00100933805314, + -0.4710650558789194, 0.0131929418218149, -0.0360392619648277, 0.00100933805314, + -0.5959087214596539, 0.0166893914019174, -0.0360392619648275, 0.00100933805314, + + 0.226190519948558, -0.0221246935211791, -0.0293231266236292, 0.0028682244940153, + 0.1246122296507558, -0.0121888724188829, -0.0293231266236291, 0.0028682244940153, + 0.0230339393529535, -0.0022530513165867, -0.029323126623629, 0.0028682244940153, + -0.0785443509448487, 0.0076827697857095, -0.0293231266236288, 0.0028682244940153, + -0.180122641242651, 0.0176185908880057, -0.0293231266236288, 0.0028682244940153, + -0.2817009315404533, 0.027554411990302, -0.0293231266236289, 0.0028682244940153, + -0.3832792218382556, 0.0374902330925981, -0.0293231266236285, 0.0028682244940153, + -0.4848575121360578, 0.0474260541948944, -0.0293231266236283, 0.0028682244940153, + + 0.1311172040286984, -0.0327659110179022, -0.0169979112172524, 0.0042477419386764, + 0.0722347123270466, -0.0180513013074449, -0.0169979112172524, 0.0042477419386764, + 0.0133522206253946, -0.0033366915969877, -0.0169979112172523, 0.0042477419386764, + -0.0455302710762573, 0.0113779181134696, -0.0169979112172521, 0.0042477419386764, + -0.1044127627779092, 0.0260925278239268, -0.0169979112172521, 0.0042477419386764, + -0.1632952544795612, 0.040807137534384, -0.0169979112172522, 0.0042477419386764, + -0.2221777461812131, 0.0555217472448413, -0.0169979112172518, 0.0042477419386764, + -0.2810602378828649, 0.0702363569552985, -0.0169979112172516, 0.0042477419386764, + + 0.0098560286339075, -0.0372442612385308, -0.001277726297742, 0.0048283110563137, + 0.0054298549021959, -0.0205185011099672, -0.001277726297742, 0.0048283110563137, + 0.0010036811704842, -0.0037927409814036, -0.0012777262977419, 0.0048283110563137, + -0.0034224925612274, 0.0129330191471601, -0.0012777262977417, 0.0048283110563136, + -0.0078486662929391, 0.0296587792757237, -0.0012777262977417, 0.0048283110563136, + -0.0122748400246508, 0.0463845394042873, -0.0012777262977418, 0.0048283110563137, + -0.0167010137563625, 0.0631102995328509, -0.0012777262977415, 0.0048283110563136, + -0.0211271874880741, 0.0798360596614145, -0.0012777262977413, 0.0048283110563136, + + -0.1119744480538166, -0.0330945972726272, 0.0145162623068366, 0.0042903525161177, + -0.0616886403509404, -0.0182323801920337, 0.0145162623068366, 0.0042903525161177, + -0.0114028326480642, -0.0033701631114402, 0.0145162623068367, 0.0042903525161177, + 0.038882975054812, 0.0114920539691533, 0.0145162623068368, 0.0042903525161176, + 0.0891687827576881, 0.0263542710497468, 0.0145162623068368, 0.0042903525161176, + 0.1394545904605643, 0.0412164881303402, 0.0145162623068367, 0.0042903525161176, + 0.1897403981634405, 0.0560787052109337, 0.014516262306837, 0.0042903525161176, + 0.2400262058663167, 0.0709409222915272, 0.0145162623068371, 0.0042903525161176, + + -0.2002161484584767, -0.0178517722097536, 0.0259558334923958, 0.0023142869872789, + -0.1103025037352214, -0.0098348469192286, 0.0259558334923958, 0.0023142869872789, + -0.0203888590119662, -0.0018179216287036, 0.0259558334923959, 0.0023142869872789, + 0.0695247857112891, 0.0061990036618213, 0.025955833492396, 0.0023142869872788, + 0.1594384304345443, 0.0142159289523463, 0.025955833492396, 0.0023142869872788, + 0.2493520751577995, 0.0222328542428713, 0.0259558334923959, 0.0023142869872789, + 0.3392657198810548, 0.0302497795333963, 0.0259558334923961, 0.0023142869872788, + 0.42917936460431, 0.0382667048239213, 0.0259558334923963, 0.0023142869872788, + + -0.2121714756100758, 0.0109493608605278, 0.0275057108788264, -0.0014194648610122, + -0.1168888981292207, 0.006032190342864, 0.0275057108788265, -0.0014194648610122, + -0.0216063206483658, 0.0011150198252003, 0.0275057108788265, -0.0014194648610122, + 0.0736762568324892, -0.0038021506924635, 0.0275057108788265, -0.0014194648610122, + 0.1689588343133442, -0.0087193212101273, 0.0275057108788266, -0.0014194648610122, + 0.2642414117941991, -0.013636491727791, 0.0275057108788265, -0.0014194648610122, + 0.3595239892750541, -0.0185536622454548, 0.0275057108788266, -0.0014194648610123, + 0.4548065667559091, -0.0234708327631186, 0.0275057108788267, -0.0014194648610123, + + -0.0966033131446177, 0.0557739488486548, 0.0125235628099973, -0.0072304823595651, + -0.053220418987227, 0.0307268232286602, 0.0125235628099973, -0.0072304823595651, + -0.0098375248298362, 0.0056796976086655, 0.0125235628099973, -0.0072304823595651, + 0.0335453693275546, -0.0193674280113291, 0.0125235628099973, -0.0072304823595651, + 0.0769282634849454, -0.0444145536313237, 0.0125235628099973, -0.0072304823595651, + 0.1203111576423362, -0.0694616792513183, 0.0125235628099973, -0.0072304823595651, + 0.163694051799727, -0.0945088048713129, 0.0125235628099974, -0.0072304823595652, + 0.2070769459571177, -0.1195559304913075, 0.0125235628099974, -0.0072304823595652 }; return sol; } -static const double * -get_sol_2x_p1_DxNx(void) +static const double *get_sol_2x_p1_DxNx(void) { static const double sol[256] = { - -0.0966033131446173, -0.0557739488486548, 0.012523562809997 , 0.0072304823595651, - -0.053220418987227 , -0.0307268232286602, 0.0125235628099973, 0.0072304823595651, - -0.0098375248298362, -0.0056796976086655, 0.0125235628099973, 0.0072304823595651, - 0.0335453693275545, 0.0193674280113291, 0.0125235628099973, 0.0072304823595651, - 0.0769282634849452, 0.0444145536313237, 0.0125235628099971, 0.0072304823595651, - 0.1203111576423362, 0.0694616792513183, 0.0125235628099974, 0.0072304823595651, - 0.1636940517997271, 0.0945088048713129, 0.0125235628099971, 0.0072304823595652, - 0.2070769459571174, 0.1195559304913075, 0.0125235628099976, 0.0072304823595651, - - -0.2121714756100753, -0.0109493608605278, 0.0275057108788262, 0.0014194648610122, - -0.1168888981292208, -0.0060321903428641, 0.0275057108788265, 0.0014194648610122, - -0.0216063206483658, -0.0011150198252003, 0.0275057108788265, 0.0014194648610122, - 0.0736762568324891, 0.0038021506924635, 0.0275057108788265, 0.0014194648610122, - 0.168958834313344 , 0.0087193212101273, 0.0275057108788263, 0.0014194648610122, - 0.2642414117941991, 0.013636491727791 , 0.0275057108788266, 0.0014194648610122, - 0.3595239892750542, 0.0185536622454548, 0.0275057108788264, 0.0014194648610122, - 0.4548065667559088, 0.0234708327631186, 0.0275057108788267, 0.0014194648610122, - - -0.2002161484584764, 0.0178517722097536, 0.0259558334923957, -0.0023142869872788, - -0.1103025037352215, 0.0098348469192286, 0.0259558334923959, -0.0023142869872789, - -0.0203888590119662, 0.0018179216287036, 0.0259558334923959, -0.0023142869872789, - 0.069524785711289 , -0.0061990036618213, 0.0259558334923959, -0.0023142869872789, - 0.1594384304345441, -0.0142159289523463, 0.0259558334923958, -0.0023142869872788, - 0.2493520751577995, -0.0222328542428713, 0.0259558334923959, -0.0023142869872789, - 0.3392657198810548, -0.0302497795333963, 0.0259558334923958, -0.0023142869872789, - 0.4291793646043098, -0.0382667048239212, 0.0259558334923961, -0.0023142869872789, - - -0.1119744480538163, 0.0330945972726272, 0.0145162623068365, -0.0042903525161176, - -0.0616886403509405, 0.0182323801920337, 0.0145162623068366, -0.0042903525161177, - -0.0114028326480643, 0.0033701631114402, 0.0145162623068367, -0.0042903525161177, - 0.0388829750548119, -0.0114920539691533, 0.0145162623068367, -0.0042903525161177, - 0.0891687827576879, -0.0263542710497468, 0.0145162623068366, -0.0042903525161176, - 0.1394545904605643, -0.0412164881303402, 0.0145162623068367, -0.0042903525161177, - 0.1897403981634405, -0.0560787052109337, 0.0145162623068366, -0.0042903525161176, - 0.2400262058663166, -0.0709409222915272, 0.0145162623068367, -0.0042903525161177, - - 0.0098560286339078, 0.0372442612385308, -0.0012777262977421, -0.0048283110563137, - 0.0054298549021959, 0.0205185011099672, -0.0012777262977419, -0.0048283110563137, - 0.0010036811704842, 0.0037927409814036, -0.0012777262977419, -0.0048283110563137, - -0.0034224925612275, -0.0129330191471601, -0.0012777262977419, -0.0048283110563137, - -0.0078486662929393, -0.0296587792757237, -0.001277726297742 , -0.0048283110563136, - -0.0122748400246508, -0.0463845394042873, -0.0012777262977419, -0.0048283110563137, - -0.0167010137563626, -0.063110299532851 , -0.0012777262977419, -0.0048283110563136, - -0.0211271874880741, -0.0798360596614145, -0.0012777262977419, -0.0048283110563137, - - 0.1311172040286987, 0.0327659110179021, -0.0169979112172525, -0.0042477419386764, - 0.0722347123270465, 0.0180513013074449, -0.0169979112172524, -0.0042477419386764, - 0.0133522206253946, 0.0033366915969877, -0.0169979112172523, -0.0042477419386764, - -0.0455302710762574, -0.0113779181134696, -0.0169979112172523, -0.0042477419386764, - -0.1044127627779095, -0.0260925278239268, -0.0169979112172524, -0.0042477419386764, - -0.1632952544795612, -0.040807137534384 , -0.0169979112172523, -0.0042477419386764, - -0.2221777461812133, -0.0555217472448413, -0.0169979112172523, -0.0042477419386764, - -0.2810602378828649, -0.0702363569552985, -0.0169979112172524, -0.0042477419386764, - - 0.2261905199485582, 0.0221246935211791, -0.0293231266236291, -0.0028682244940153, - 0.1246122296507557, 0.0121888724188829, -0.0293231266236291, -0.0028682244940153, - 0.0230339393529534, 0.0022530513165867, -0.029323126623629 , -0.0028682244940153, - -0.0785443509448489, -0.0076827697857095, -0.029323126623629 , -0.0028682244940153, - -0.1801226412426513, -0.0176185908880057, -0.029323126623629 , -0.0028682244940153, - -0.2817009315404534, -0.0275544119903019, -0.0293231266236291, -0.0028682244940153, - -0.3832792218382559, -0.0374902330925982, -0.029323126623629 , -0.0028682244940153, - -0.4848575121360577, -0.0474260541948943, -0.0293231266236291, -0.0028682244940153, - - 0.2779969376054876, 0.0077857556587993, -0.0360392619648284, -0.00100933805314 , - 0.153153272024753 , 0.0042893060786969, -0.0360392619648284, -0.00100933805314 , - 0.0283096064440184, 0.0007928564985946, -0.0360392619648283, -0.00100933805314 , - -0.0965340591367161, -0.0027035930815078, -0.0360392619648283, -0.00100933805314 , - -0.2213777247174507, -0.0062000426616102, -0.0360392619648283, -0.00100933805314 , - -0.346221390298185 , -0.0096964922417126, -0.0360392619648284, -0.00100933805314 , - -0.4710650558789197, -0.013192941821815 , -0.0360392619648282, -0.00100933805314 , - -0.5959087214596538, -0.0166893914019173, -0.0360392619648285, -0.00100933805314 , + -0.0966033131446173, -0.0557739488486548, 0.012523562809997, 0.0072304823595651, + -0.053220418987227, -0.0307268232286602, 0.0125235628099973, 0.0072304823595651, + -0.0098375248298362, -0.0056796976086655, 0.0125235628099973, 0.0072304823595651, + 0.0335453693275545, 0.0193674280113291, 0.0125235628099973, 0.0072304823595651, + 0.0769282634849452, 0.0444145536313237, 0.0125235628099971, 0.0072304823595651, + 0.1203111576423362, 0.0694616792513183, 0.0125235628099974, 0.0072304823595651, + 0.1636940517997271, 0.0945088048713129, 0.0125235628099971, 0.0072304823595652, + 0.2070769459571174, 0.1195559304913075, 0.0125235628099976, 0.0072304823595651, + + -0.2121714756100753, -0.0109493608605278, 0.0275057108788262, 0.0014194648610122, + -0.1168888981292208, -0.0060321903428641, 0.0275057108788265, 0.0014194648610122, + -0.0216063206483658, -0.0011150198252003, 0.0275057108788265, 0.0014194648610122, + 0.0736762568324891, 0.0038021506924635, 0.0275057108788265, 0.0014194648610122, + 0.168958834313344, 0.0087193212101273, 0.0275057108788263, 0.0014194648610122, + 0.2642414117941991, 0.013636491727791, 0.0275057108788266, 0.0014194648610122, + 0.3595239892750542, 0.0185536622454548, 0.0275057108788264, 0.0014194648610122, + 0.4548065667559088, 0.0234708327631186, 0.0275057108788267, 0.0014194648610122, + + -0.2002161484584764, 0.0178517722097536, 0.0259558334923957, -0.0023142869872788, + -0.1103025037352215, 0.0098348469192286, 0.0259558334923959, -0.0023142869872789, + -0.0203888590119662, 0.0018179216287036, 0.0259558334923959, -0.0023142869872789, + 0.069524785711289, -0.0061990036618213, 0.0259558334923959, -0.0023142869872789, + 0.1594384304345441, -0.0142159289523463, 0.0259558334923958, -0.0023142869872788, + 0.2493520751577995, -0.0222328542428713, 0.0259558334923959, -0.0023142869872789, + 0.3392657198810548, -0.0302497795333963, 0.0259558334923958, -0.0023142869872789, + 0.4291793646043098, -0.0382667048239212, 0.0259558334923961, -0.0023142869872789, + + -0.1119744480538163, 0.0330945972726272, 0.0145162623068365, -0.0042903525161176, + -0.0616886403509405, 0.0182323801920337, 0.0145162623068366, -0.0042903525161177, + -0.0114028326480643, 0.0033701631114402, 0.0145162623068367, -0.0042903525161177, + 0.0388829750548119, -0.0114920539691533, 0.0145162623068367, -0.0042903525161177, + 0.0891687827576879, -0.0263542710497468, 0.0145162623068366, -0.0042903525161176, + 0.1394545904605643, -0.0412164881303402, 0.0145162623068367, -0.0042903525161177, + 0.1897403981634405, -0.0560787052109337, 0.0145162623068366, -0.0042903525161176, + 0.2400262058663166, -0.0709409222915272, 0.0145162623068367, -0.0042903525161177, + + 0.0098560286339078, 0.0372442612385308, -0.0012777262977421, -0.0048283110563137, + 0.0054298549021959, 0.0205185011099672, -0.0012777262977419, -0.0048283110563137, + 0.0010036811704842, 0.0037927409814036, -0.0012777262977419, -0.0048283110563137, + -0.0034224925612275, -0.0129330191471601, -0.0012777262977419, -0.0048283110563137, + -0.0078486662929393, -0.0296587792757237, -0.001277726297742, -0.0048283110563136, + -0.0122748400246508, -0.0463845394042873, -0.0012777262977419, -0.0048283110563137, + -0.0167010137563626, -0.063110299532851, -0.0012777262977419, -0.0048283110563136, + -0.0211271874880741, -0.0798360596614145, -0.0012777262977419, -0.0048283110563137, + + 0.1311172040286987, 0.0327659110179021, -0.0169979112172525, -0.0042477419386764, + 0.0722347123270465, 0.0180513013074449, -0.0169979112172524, -0.0042477419386764, + 0.0133522206253946, 0.0033366915969877, -0.0169979112172523, -0.0042477419386764, + -0.0455302710762574, -0.0113779181134696, -0.0169979112172523, -0.0042477419386764, + -0.1044127627779095, -0.0260925278239268, -0.0169979112172524, -0.0042477419386764, + -0.1632952544795612, -0.040807137534384, -0.0169979112172523, -0.0042477419386764, + -0.2221777461812133, -0.0555217472448413, -0.0169979112172523, -0.0042477419386764, + -0.2810602378828649, -0.0702363569552985, -0.0169979112172524, -0.0042477419386764, + + 0.2261905199485582, 0.0221246935211791, -0.0293231266236291, -0.0028682244940153, + 0.1246122296507557, 0.0121888724188829, -0.0293231266236291, -0.0028682244940153, + 0.0230339393529534, 0.0022530513165867, -0.029323126623629, -0.0028682244940153, + -0.0785443509448489, -0.0076827697857095, -0.029323126623629, -0.0028682244940153, + -0.1801226412426513, -0.0176185908880057, -0.029323126623629, -0.0028682244940153, + -0.2817009315404534, -0.0275544119903019, -0.0293231266236291, -0.0028682244940153, + -0.3832792218382559, -0.0374902330925982, -0.029323126623629, -0.0028682244940153, + -0.4848575121360577, -0.0474260541948943, -0.0293231266236291, -0.0028682244940153, + + 0.2779969376054876, 0.0077857556587993, -0.0360392619648284, -0.00100933805314, + 0.153153272024753, 0.0042893060786969, -0.0360392619648284, -0.00100933805314, + 0.0283096064440184, 0.0007928564985946, -0.0360392619648283, -0.00100933805314, + -0.0965340591367161, -0.0027035930815078, -0.0360392619648283, -0.00100933805314, + -0.2213777247174507, -0.0062000426616102, -0.0360392619648283, -0.00100933805314, + -0.346221390298185, -0.0096964922417126, -0.0360392619648284, -0.00100933805314, + -0.4710650558789197, -0.013192941821815, -0.0360392619648282, -0.00100933805314, + -0.5959087214596538, -0.0166893914019173, -0.0360392619648285, -0.00100933805314 }; return sol; } -static const double * -get_sol_2x_bias_p1_DxDx(void) +static const double *get_sol_2x_bias_p1_DxDx(void) { static const double sol[256] = { - 0.0523071668741079, 0.0301995568753129, 0.0043898894860765, 0.0025345038764989, - 0.0326575388702468, 0.0188548388578077, -0.0076848087077184, -0.004436826376072 , - 0.0060365806138147, 0.0034852214423708, -0.0076848087077184, -0.004436826376072 , - -0.0205843776426173, -0.011884395973066 , -0.0076848087077184, -0.004436826376072 , - -0.0472053358990496, -0.0272540133885028, -0.0076848087077183, -0.004436826376072 , - -0.0738262941554814, -0.0426236308039397, -0.0076848087077184, -0.004436826376072 , - -0.1004472524119136, -0.0579932482193765, -0.0076848087077186, -0.004436826376072 , - -0.1270682106683453, -0.0733628656348134, -0.0076848087077185, -0.004436826376072 , - - 0.1305913158241592, 0.0149978175942799, 0.0165830888926301, 0.0045052430831576, - 0.0834668670525276, 0.0104799404455762, -0.0196410056887545, -0.0024660871694134, - 0.0154284275231832, 0.0019371638989408, -0.0196410056887545, -0.0024660871694134, - -0.0526100120061611, -0.0066056126476946, -0.0196410056887545, -0.0024660871694134, - -0.1206484515355057, -0.0151483891943299, -0.0196410056887544, -0.0024660871694134, - -0.1886868910648499, -0.0236911657409653, -0.0196410056887545, -0.0024660871694134, - -0.2567253305941943, -0.0322339422876006, -0.0196410056887547, -0.0024660871694134, - -0.3247637701235385, -0.040776718834236 , -0.0196410056887545, -0.0024660871694134, - - 0.1587769509960808, 0.0012751664595096, 0.0352710125851786, 0.0062842346913305, - 0.1066760663456682, 0.0029198970139942, -0.0251024783837957, -0.0006870955612404, - 0.0197185304324009, 0.0005397281705472, -0.0251024783837957, -0.0006870955612404, - -0.0672390054808664, -0.0018404406728998, -0.0251024783837957, -0.0006870955612404, - -0.1541965413941337, -0.0042206095163468, -0.0251024783837957, -0.0006870955612405, - -0.2411540773074009, -0.0066007783597938, -0.0251024783837957, -0.0006870955612404, - -0.3281116132206683, -0.0089809472032408, -0.0251024783837958, -0.0006870955612404, - -0.4150691491339354, -0.0113611160466878, -0.0251024783837957, -0.0006870955612404, - - 0.1436956879050723, -0.0099823377648229, 0.0595680163429045, 0.0077436469686939, - 0.1060487906890969, -0.0032820547831718, -0.0249548710136595, 0.000772316716123 , - 0.0196025817051248, -0.0006066711994523, -0.0249548710136594, 0.000772316716123 , - -0.0668436272788473, 0.0020687123842672, -0.0249548710136594, 0.000772316716123 , - -0.1532898362628194, 0.0047440959679867, -0.0249548710136594, 0.000772316716123 , - -0.2397360452467914, 0.0074194795517062, -0.0249548710136595, 0.000772316716123 , - -0.3261822542307636, 0.0100948631354257, -0.0249548710136595, 0.000772316716123 , - -0.4126284632147356, 0.0127702467191452, -0.0249548710136594, 0.000772316716123 , - - 0.1095376103290749, -0.0097388375186793, 0.0639962374469919, -0.0051870123222179, - 0.0872305209919558, -0.0075826782921555, -0.020526649909572 , 0.0017843179303531, - 0.0161241198868402, -0.0014016196677002, -0.020526649909572 , 0.0017843179303531, - -0.0549822812182755, 0.0047794389567552, -0.020526649909572 , 0.0017843179303531, - -0.1260886823233912, 0.0109604975812106, -0.020526649909572 , 0.0017843179303531, - -0.1971950834285068, 0.017141556205666 , -0.020526649909572 , 0.0017843179303531, - -0.2683014845336226, 0.0233226148301214, -0.020526649909572 , 0.0017843179303531, - -0.3394078856387381, 0.0295036734545768, -0.020526649909572 , 0.0017843179303531, - - 0.0699659492984875, -0.013107871629611 , 0.0467843874558059, -0.0047502539034449, - 0.0577485651331015, -0.0094387368591906, -0.0135891035131684, 0.0022210763491261, - 0.0106745297048609, -0.0017447026908387, -0.0135891035131683, 0.0022210763491261, - -0.0363995057233797, 0.0059493314775132, -0.0135891035131683, 0.0022210763491261, - -0.0834735411516203, 0.0136433656458652, -0.0135891035131683, 0.0022210763491261, - -0.1305475765798609, 0.0213373998142171, -0.0135891035131683, 0.0022210763491261, - -0.1776216120081016, 0.0290314339825691, -0.0135891035131684, 0.0022210763491261, - -0.2246956474363422, 0.036725468150921 , -0.0135891035131683, 0.0022210763491261, - - 0.0281170830961668, -0.0110535825375795, 0.0298677522048923, -0.0050165700124528, - 0.0270120579611045, -0.0083069938305107, -0.0063563423764922, 0.0019547602401182, - 0.0049930420683294, -0.0015355057255103, -0.0063563423764922, 0.0019547602401182, - -0.0170259738244458, 0.0052359823794901, -0.0063563423764922, 0.0019547602401182, - -0.0390449897172209, 0.0120074704844905, -0.0063563423764922, 0.0019547602401182, - -0.0610640056099961, 0.0187789585894908, -0.0063563423764922, 0.0019547602401182, - -0.0830830215027712, 0.0255504466944912, -0.0063563423764922, 0.0019547602401182, - -0.1051020373955464, 0.0323219347994916, -0.0063563423764922, 0.0019547602401182, - - 0.0044858582677115, -0.0025899114784098, 0.0105893990317988, -0.0061137923815654, - 0.0063119612942494, -0.0036442125523494, -0.001485299161996 , 0.0008575378710055, - 0.0011667340682163, -0.0006736142283574, -0.001485299161996 , 0.0008575378710055, - -0.0039784931578168, 0.0022969840956346, -0.001485299161996 , 0.0008575378710055, - -0.0091237203838499, 0.0052675824196266, -0.001485299161996 , 0.0008575378710055, - -0.014268947609883 , 0.0082381807436186, -0.001485299161996 , 0.0008575378710055, - -0.0194141748359161, 0.0112087790676106, -0.001485299161996 , 0.0008575378710055, - -0.0245594020619492, 0.0141793773916026, -0.001485299161996 , 0.0008575378710055, + 0.0523071668741079, 0.0301995568753129, 0.0043898894860765, 0.0025345038764989, + 0.0326575388702468, 0.0188548388578077, -0.0076848087077184, -0.004436826376072, + 0.0060365806138147, 0.0034852214423708, -0.0076848087077184, -0.004436826376072, + -0.0205843776426173, -0.011884395973066, -0.0076848087077184, -0.004436826376072, + -0.0472053358990496, -0.0272540133885028, -0.0076848087077183, -0.004436826376072, + -0.0738262941554814, -0.0426236308039397, -0.0076848087077184, -0.004436826376072, + -0.1004472524119136, -0.0579932482193765, -0.0076848087077186, -0.004436826376072, + -0.1270682106683453, -0.0733628656348134, -0.0076848087077185, -0.004436826376072, + + 0.1305913158241592, 0.0149978175942799, 0.0165830888926301, 0.0045052430831576, + 0.0834668670525276, 0.0104799404455762, -0.0196410056887545, -0.0024660871694134, + 0.0154284275231832, 0.0019371638989408, -0.0196410056887545, -0.0024660871694134, + -0.0526100120061611, -0.0066056126476946, -0.0196410056887545, -0.0024660871694134, + -0.1206484515355057, -0.0151483891943299, -0.0196410056887544, -0.0024660871694134, + -0.1886868910648499, -0.0236911657409653, -0.0196410056887545, -0.0024660871694134, + -0.2567253305941943, -0.0322339422876006, -0.0196410056887547, -0.0024660871694134, + -0.3247637701235385, -0.040776718834236, -0.0196410056887545, -0.0024660871694134, + + 0.1587769509960808, 0.0012751664595096, 0.0352710125851786, 0.0062842346913305, + 0.1066760663456682, 0.0029198970139942, -0.0251024783837957, -0.0006870955612404, + 0.0197185304324009, 0.0005397281705472, -0.0251024783837957, -0.0006870955612404, + -0.0672390054808664, -0.0018404406728998, -0.0251024783837957, -0.0006870955612404, + -0.1541965413941337, -0.0042206095163468, -0.0251024783837957, -0.0006870955612405, + -0.2411540773074009, -0.0066007783597938, -0.0251024783837957, -0.0006870955612404, + -0.3281116132206683, -0.0089809472032408, -0.0251024783837958, -0.0006870955612404, + -0.4150691491339354, -0.0113611160466878, -0.0251024783837957, -0.0006870955612404, + + 0.1436956879050723, -0.0099823377648229, 0.0595680163429045, 0.0077436469686939, + 0.1060487906890969, -0.0032820547831718, -0.0249548710136595, 0.000772316716123, + 0.0196025817051248, -0.0006066711994523, -0.0249548710136594, 0.000772316716123, + -0.0668436272788473, 0.0020687123842672, -0.0249548710136594, 0.000772316716123, + -0.1532898362628194, 0.0047440959679867, -0.0249548710136594, 0.000772316716123, + -0.2397360452467914, 0.0074194795517062, -0.0249548710136595, 0.000772316716123, + -0.3261822542307636, 0.0100948631354257, -0.0249548710136595, 0.000772316716123, + -0.4126284632147356, 0.0127702467191452, -0.0249548710136594, 0.000772316716123, + + 0.1095376103290749, -0.0097388375186793, 0.0639962374469919, -0.0051870123222179, + 0.0872305209919558, -0.0075826782921555, -0.020526649909572, 0.0017843179303531, + 0.0161241198868402, -0.0014016196677002, -0.020526649909572, 0.0017843179303531, + -0.0549822812182755, 0.0047794389567552, -0.020526649909572, 0.0017843179303531, + -0.1260886823233912, 0.0109604975812106, -0.020526649909572, 0.0017843179303531, + -0.1971950834285068, 0.017141556205666, -0.020526649909572, 0.0017843179303531, + -0.2683014845336226, 0.0233226148301214, -0.020526649909572, 0.0017843179303531, + -0.3394078856387381, 0.0295036734545768, -0.020526649909572, 0.0017843179303531, + + 0.0699659492984875, -0.013107871629611, 0.0467843874558059, -0.0047502539034449, + 0.0577485651331015, -0.0094387368591906, -0.0135891035131684, 0.0022210763491261, + 0.0106745297048609, -0.0017447026908387, -0.0135891035131683, 0.0022210763491261, + -0.0363995057233797, 0.0059493314775132, -0.0135891035131683, 0.0022210763491261, + -0.0834735411516203, 0.0136433656458652, -0.0135891035131683, 0.0022210763491261, + -0.1305475765798609, 0.0213373998142171, -0.0135891035131683, 0.0022210763491261, + -0.1776216120081016, 0.0290314339825691, -0.0135891035131684, 0.0022210763491261, + -0.2246956474363422, 0.036725468150921, -0.0135891035131683, 0.0022210763491261, + + 0.0281170830961668, -0.0110535825375795, 0.0298677522048923, -0.0050165700124528, + 0.0270120579611045, -0.0083069938305107, -0.0063563423764922, 0.0019547602401182, + 0.0049930420683294, -0.0015355057255103, -0.0063563423764922, 0.0019547602401182, + -0.0170259738244458, 0.0052359823794901, -0.0063563423764922, 0.0019547602401182, + -0.0390449897172209, 0.0120074704844905, -0.0063563423764922, 0.0019547602401182, + -0.0610640056099961, 0.0187789585894908, -0.0063563423764922, 0.0019547602401182, + -0.0830830215027712, 0.0255504466944912, -0.0063563423764922, 0.0019547602401182, + -0.1051020373955464, 0.0323219347994916, -0.0063563423764922, 0.0019547602401182, + + 0.0044858582677115, -0.0025899114784098, 0.0105893990317988, -0.0061137923815654, + 0.0063119612942494, -0.0036442125523494, -0.001485299161996, 0.0008575378710055, + 0.0011667340682163, -0.0006736142283574, -0.001485299161996, 0.0008575378710055, + -0.0039784931578168, 0.0022969840956346, -0.001485299161996, 0.0008575378710055, + -0.0091237203838499, 0.0052675824196266, -0.001485299161996, 0.0008575378710055, + -0.014268947609883, 0.0082381807436186, -0.001485299161996, 0.0008575378710055, + -0.0194141748359161, 0.0112087790676106, -0.001485299161996, 0.0008575378710055, + -0.0245594020619492, 0.0141793773916026, -0.001485299161996, 0.0008575378710055 }; return sol; } -static const double * -get_sol_2x_bias_p1_NxDx(void) +static const double *get_sol_2x_bias_p1_NxDx(void) { static const double sol[256] = { - 0.2947281302116576, -0.0077857556587993, -0.0650185376299358, 0.00100933805314 , - 0.153153272024753 , -0.0042893060786969, -0.0360392619648284, 0.00100933805314 , - 0.0283096064440185, -0.0007928564985946, -0.0360392619648283, 0.00100933805314 , - -0.0965340591367159, 0.0027035930815078, -0.0360392619648281, 0.00100933805314 , - -0.2213777247174505, 0.0062000426616102, -0.0360392619648281, 0.00100933805314 , - -0.346221390298185 , 0.0096964922417126, -0.0360392619648282, 0.00100933805314 , - -0.4710650558789194, 0.0131929418218149, -0.0360392619648277, 0.00100933805314 , - -0.5959087214596539, 0.0166893914019174, -0.0360392619648275, 0.00100933805314 , - - 0.2429217125547281, -0.0221246935211791, -0.0583024022887365, 0.0028682244940153, - 0.1246122296507558, -0.0121888724188829, -0.0293231266236291, 0.0028682244940153, - 0.0230339393529535, -0.0022530513165867, -0.029323126623629 , 0.0028682244940153, - -0.0785443509448487, 0.0076827697857095, -0.0293231266236288, 0.0028682244940153, - -0.180122641242651 , 0.0176185908880057, -0.0293231266236288, 0.0028682244940153, - -0.2817009315404533, 0.027554411990302 , -0.0293231266236289, 0.0028682244940153, - -0.3832792218382556, 0.0374902330925981, -0.0293231266236285, 0.0028682244940153, - -0.4848575121360578, 0.0474260541948944, -0.0293231266236283, 0.0028682244940153, - - 0.1478483966348686, -0.0327659110179021, -0.0459771868823598, 0.0042477419386764, - 0.0722347123270466, -0.0180513013074449, -0.0169979112172524, 0.0042477419386764, - 0.0133522206253946, -0.0033366915969877, -0.0169979112172523, 0.0042477419386764, - -0.0455302710762573, 0.0113779181134696, -0.0169979112172521, 0.0042477419386764, - -0.1044127627779092, 0.0260925278239268, -0.0169979112172521, 0.0042477419386764, - -0.1632952544795612, 0.040807137534384 , -0.0169979112172522, 0.0042477419386764, - -0.2221777461812131, 0.0555217472448413, -0.0169979112172518, 0.0042477419386764, - -0.2810602378828649, 0.0702363569552985, -0.0169979112172516, 0.0042477419386764, - - 0.0265872212400777, -0.0372442612385308, -0.0302570019628494, 0.0048283110563137, - 0.0054298549021959, -0.0205185011099672, -0.001277726297742 , 0.0048283110563137, - 0.0010036811704842, -0.0037927409814036, -0.0012777262977419, 0.0048283110563137, - -0.0034224925612274, 0.0129330191471601, -0.0012777262977417, 0.0048283110563136, - -0.0078486662929391, 0.0296587792757237, -0.0012777262977417, 0.0048283110563136, - -0.0122748400246508, 0.0463845394042873, -0.0012777262977418, 0.0048283110563137, - -0.0167010137563625, 0.0631102995328509, -0.0012777262977415, 0.0048283110563136, - -0.0211271874880741, 0.0798360596614145, -0.0012777262977413, 0.0048283110563136, - - -0.0973346545234177, -0.0343020670920067, -0.0108406039001324, 0.0063817515918889, - -0.0616886403509404, -0.0182323801920337, 0.0145162623068366, 0.0042903525161177, - -0.0114028326480642, -0.0033701631114402, 0.0145162623068367, 0.0042903525161177, - 0.038882975054812 , 0.0114920539691533, 0.0145162623068368, 0.0042903525161176, - 0.0891687827576881, 0.0263542710497468, 0.0145162623068368, 0.0042903525161176, - 0.1394545904605643, 0.0412164881303402, 0.0145162623068367, 0.0042903525161176, - 0.1897403981634405, 0.0560787052109337, 0.014516262306837 , 0.0042903525161176, - 0.2400262058663167, 0.0709409222915272, 0.0145162623068371, 0.0042903525161176, - - -0.1897591530796203, -0.0190592420291331, 0.0078437862017036, 0.0044056860630501, - -0.1103025037352214, -0.0098348469192286, 0.0259558334923958, 0.0023142869872789, - -0.0203888590119662, -0.0018179216287036, 0.0259558334923959, 0.0023142869872789, - 0.0695247857112891, 0.0061990036618213, 0.025955833492396 , 0.0023142869872788, - 0.1594384304345443, 0.0142159289523463, 0.025955833492396 , 0.0023142869872788, - 0.2493520751577995, 0.0222328542428713, 0.0259558334923959, 0.0023142869872789, - 0.3392657198810548, 0.0302497795333963, 0.0259558334923961, 0.0023142869872788, - 0.42917936460431 , 0.0382667048239213, 0.0259558334923963, 0.0023142869872788, - - -0.2058972783827619, 0.0097418910411483, 0.0166384825044111, 0.000671934214759 , - -0.1168888981292207, 0.006032190342864 , 0.0275057108788265, -0.0014194648610122, - -0.0216063206483658, 0.0011150198252003, 0.0275057108788265, -0.0014194648610122, - 0.0736762568324892, -0.0038021506924635, 0.0275057108788265, -0.0014194648610122, - 0.1689588343133442, -0.0087193212101273, 0.0275057108788266, -0.0014194648610122, - 0.2642414117941991, -0.013636491727791 , 0.0275057108788265, -0.0014194648610122, - 0.3595239892750541, -0.0185536622454548, 0.0275057108788266, -0.0014194648610123, - 0.4548065667559091, -0.0234708327631186, 0.0275057108788267, -0.0014194648610123, - - -0.0945119140688464, 0.0545664790292753, 0.0089011533518588, -0.0051390832837939, - -0.053220418987227 , 0.0307268232286602, 0.0125235628099973, -0.0072304823595651, - -0.0098375248298362, 0.0056796976086655, 0.0125235628099973, -0.0072304823595651, - 0.0335453693275546, -0.0193674280113291, 0.0125235628099973, -0.0072304823595651, - 0.0769282634849454, -0.0444145536313237, 0.0125235628099973, -0.0072304823595651, - 0.1203111576423362, -0.0694616792513183, 0.0125235628099973, -0.0072304823595651, - 0.163694051799727 , -0.0945088048713129, 0.0125235628099974, -0.0072304823595652, - 0.2070769459571177, -0.1195559304913075, 0.0125235628099974, -0.0072304823595652, + 0.2947281302116576, -0.0077857556587993, -0.0650185376299358, 0.00100933805314, + 0.153153272024753, -0.0042893060786969, -0.0360392619648284, 0.00100933805314, + 0.0283096064440185, -0.0007928564985946, -0.0360392619648283, 0.00100933805314, + -0.0965340591367159, 0.0027035930815078, -0.0360392619648281, 0.00100933805314, + -0.2213777247174505, 0.0062000426616102, -0.0360392619648281, 0.00100933805314, + -0.346221390298185, 0.0096964922417126, -0.0360392619648282, 0.00100933805314, + -0.4710650558789194, 0.0131929418218149, -0.0360392619648277, 0.00100933805314, + -0.5959087214596539, 0.0166893914019174, -0.0360392619648275, 0.00100933805314, + + 0.2429217125547281, -0.0221246935211791, -0.0583024022887365, 0.0028682244940153, + 0.1246122296507558, -0.0121888724188829, -0.0293231266236291, 0.0028682244940153, + 0.0230339393529535, -0.0022530513165867, -0.029323126623629, 0.0028682244940153, + -0.0785443509448487, 0.0076827697857095, -0.0293231266236288, 0.0028682244940153, + -0.180122641242651, 0.0176185908880057, -0.0293231266236288, 0.0028682244940153, + -0.2817009315404533, 0.027554411990302, -0.0293231266236289, 0.0028682244940153, + -0.3832792218382556, 0.0374902330925981, -0.0293231266236285, 0.0028682244940153, + -0.4848575121360578, 0.0474260541948944, -0.0293231266236283, 0.0028682244940153, + + 0.1478483966348686, -0.0327659110179021, -0.0459771868823598, 0.0042477419386764, + 0.0722347123270466, -0.0180513013074449, -0.0169979112172524, 0.0042477419386764, + 0.0133522206253946, -0.0033366915969877, -0.0169979112172523, 0.0042477419386764, + -0.0455302710762573, 0.0113779181134696, -0.0169979112172521, 0.0042477419386764, + -0.1044127627779092, 0.0260925278239268, -0.0169979112172521, 0.0042477419386764, + -0.1632952544795612, 0.040807137534384, -0.0169979112172522, 0.0042477419386764, + -0.2221777461812131, 0.0555217472448413, -0.0169979112172518, 0.0042477419386764, + -0.2810602378828649, 0.0702363569552985, -0.0169979112172516, 0.0042477419386764, + + 0.0265872212400777, -0.0372442612385308, -0.0302570019628494, 0.0048283110563137, + 0.0054298549021959, -0.0205185011099672, -0.001277726297742, 0.0048283110563137, + 0.0010036811704842, -0.0037927409814036, -0.0012777262977419, 0.0048283110563137, + -0.0034224925612274, 0.0129330191471601, -0.0012777262977417, 0.0048283110563136, + -0.0078486662929391, 0.0296587792757237, -0.0012777262977417, 0.0048283110563136, + -0.0122748400246508, 0.0463845394042873, -0.0012777262977418, 0.0048283110563137, + -0.0167010137563625, 0.0631102995328509, -0.0012777262977415, 0.0048283110563136, + -0.0211271874880741, 0.0798360596614145, -0.0012777262977413, 0.0048283110563136, + + -0.0973346545234177, -0.0343020670920067, -0.0108406039001324, 0.0063817515918889, + -0.0616886403509404, -0.0182323801920337, 0.0145162623068366, 0.0042903525161177, + -0.0114028326480642, -0.0033701631114402, 0.0145162623068367, 0.0042903525161177, + 0.038882975054812, 0.0114920539691533, 0.0145162623068368, 0.0042903525161176, + 0.0891687827576881, 0.0263542710497468, 0.0145162623068368, 0.0042903525161176, + 0.1394545904605643, 0.0412164881303402, 0.0145162623068367, 0.0042903525161176, + 0.1897403981634405, 0.0560787052109337, 0.014516262306837, 0.0042903525161176, + 0.2400262058663167, 0.0709409222915272, 0.0145162623068371, 0.0042903525161176, + + -0.1897591530796203, -0.0190592420291331, 0.0078437862017036, 0.0044056860630501, + -0.1103025037352214, -0.0098348469192286, 0.0259558334923958, 0.0023142869872789, + -0.0203888590119662, -0.0018179216287036, 0.0259558334923959, 0.0023142869872789, + 0.0695247857112891, 0.0061990036618213, 0.025955833492396, 0.0023142869872788, + 0.1594384304345443, 0.0142159289523463, 0.025955833492396, 0.0023142869872788, + 0.2493520751577995, 0.0222328542428713, 0.0259558334923959, 0.0023142869872789, + 0.3392657198810548, 0.0302497795333963, 0.0259558334923961, 0.0023142869872788, + 0.42917936460431, 0.0382667048239213, 0.0259558334923963, 0.0023142869872788, + + -0.2058972783827619, 0.0097418910411483, 0.0166384825044111, 0.000671934214759, + -0.1168888981292207, 0.006032190342864, 0.0275057108788265, -0.0014194648610122, + -0.0216063206483658, 0.0011150198252003, 0.0275057108788265, -0.0014194648610122, + 0.0736762568324892, -0.0038021506924635, 0.0275057108788265, -0.0014194648610122, + 0.1689588343133442, -0.0087193212101273, 0.0275057108788266, -0.0014194648610122, + 0.2642414117941991, -0.013636491727791, 0.0275057108788265, -0.0014194648610122, + 0.3595239892750541, -0.0185536622454548, 0.0275057108788266, -0.0014194648610123, + 0.4548065667559091, -0.0234708327631186, 0.0275057108788267, -0.0014194648610123, + + -0.0945119140688464, 0.0545664790292753, 0.0089011533518588, -0.0051390832837939, + -0.053220418987227, 0.0307268232286602, 0.0125235628099973, -0.0072304823595651, + -0.0098375248298362, 0.0056796976086655, 0.0125235628099973, -0.0072304823595651, + 0.0335453693275546, -0.0193674280113291, 0.0125235628099973, -0.0072304823595651, + 0.0769282634849454, -0.0444145536313237, 0.0125235628099973, -0.0072304823595651, + 0.1203111576423362, -0.0694616792513183, 0.0125235628099973, -0.0072304823595651, + 0.163694051799727, -0.0945088048713129, 0.0125235628099974, -0.0072304823595652, + 0.2070769459571177, -0.1195559304913075, 0.0125235628099974, -0.0072304823595652 }; return sol; } -static const double * -get_sol_2x_bias_p1_DxNx(void) +static const double *get_sol_2x_bias_p1_DxNx(void) { static const double sol[256] = { - -0.0945119140688464, -0.0545664790292753, 0.0089011533518588, 0.0051390832837939, - -0.053220418987227 , -0.0307268232286602, 0.0125235628099973, 0.0072304823595651, - -0.0098375248298362, -0.0056796976086655, 0.0125235628099973, 0.0072304823595651, - 0.0335453693275545, 0.0193674280113291, 0.0125235628099973, 0.0072304823595651, - 0.0769282634849452, 0.0444145536313237, 0.0125235628099971, 0.0072304823595651, - 0.1203111576423362, 0.0694616792513183, 0.0125235628099974, 0.0072304823595651, - 0.1636940517997271, 0.0945088048713129, 0.0125235628099971, 0.0072304823595652, - 0.2070769459571174, 0.1195559304913075, 0.0125235628099976, 0.0072304823595651, - - -0.2058972783827619, -0.0097418910411483, 0.0166384825044111, -0.000671934214759 , - -0.1168888981292208, -0.0060321903428641, 0.0275057108788265, 0.0014194648610122, - -0.0216063206483658, -0.0011150198252003, 0.0275057108788265, 0.0014194648610122, - 0.0736762568324891, 0.0038021506924635, 0.0275057108788265, 0.0014194648610122, - 0.168958834313344 , 0.0087193212101273, 0.0275057108788263, 0.0014194648610122, - 0.2642414117941991, 0.013636491727791 , 0.0275057108788266, 0.0014194648610122, - 0.3595239892750542, 0.0185536622454548, 0.0275057108788264, 0.0014194648610122, - 0.4548065667559088, 0.0234708327631186, 0.0275057108788267, 0.0014194648610122, - - -0.1897591530796203, 0.0190592420291331, 0.0078437862017036, -0.0044056860630501, - -0.1103025037352215, 0.0098348469192286, 0.0259558334923959, -0.0023142869872789, - -0.0203888590119662, 0.0018179216287036, 0.0259558334923959, -0.0023142869872789, - 0.069524785711289 , -0.0061990036618213, 0.0259558334923959, -0.0023142869872789, - 0.1594384304345441, -0.0142159289523463, 0.0259558334923958, -0.0023142869872788, - 0.2493520751577995, -0.0222328542428713, 0.0259558334923959, -0.0023142869872789, - 0.3392657198810548, -0.0302497795333963, 0.0259558334923958, -0.0023142869872789, - 0.4291793646043098, -0.0382667048239212, 0.0259558334923961, -0.0023142869872789, - - -0.0973346545234177, 0.0343020670920067, -0.0108406039001325, -0.0063817515918889, - -0.0616886403509405, 0.0182323801920337, 0.0145162623068366, -0.0042903525161177, - -0.0114028326480643, 0.0033701631114402, 0.0145162623068367, -0.0042903525161177, - 0.0388829750548119, -0.0114920539691533, 0.0145162623068367, -0.0042903525161177, - 0.0891687827576879, -0.0263542710497468, 0.0145162623068366, -0.0042903525161176, - 0.1394545904605643, -0.0412164881303402, 0.0145162623068367, -0.0042903525161177, - 0.1897403981634405, -0.0560787052109337, 0.0145162623068366, -0.0042903525161176, - 0.2400262058663166, -0.0709409222915272, 0.0145162623068367, -0.0042903525161177, - - 0.0265872212400778, 0.0372442612385308, -0.0302570019628495, -0.0048283110563137, - 0.0054298549021959, 0.0205185011099672, -0.0012777262977419, -0.0048283110563137, - 0.0010036811704842, 0.0037927409814036, -0.0012777262977419, -0.0048283110563137, - -0.0034224925612275, -0.0129330191471601, -0.0012777262977419, -0.0048283110563137, - -0.0078486662929393, -0.0296587792757237, -0.001277726297742 , -0.0048283110563136, - -0.0122748400246508, -0.0463845394042873, -0.0012777262977419, -0.0048283110563137, - -0.0167010137563626, -0.063110299532851 , -0.0012777262977419, -0.0048283110563136, - -0.0211271874880741, -0.0798360596614145, -0.0012777262977419, -0.0048283110563137, - - 0.1478483966348688, 0.0327659110179022, -0.04597718688236 , -0.0042477419386764, - 0.0722347123270465, 0.0180513013074449, -0.0169979112172524, -0.0042477419386764, - 0.0133522206253946, 0.0033366915969877, -0.0169979112172523, -0.0042477419386764, - -0.0455302710762574, -0.0113779181134696, -0.0169979112172523, -0.0042477419386764, - -0.1044127627779095, -0.0260925278239268, -0.0169979112172524, -0.0042477419386764, - -0.1632952544795612, -0.040807137534384 , -0.0169979112172523, -0.0042477419386764, - -0.2221777461812133, -0.0555217472448413, -0.0169979112172523, -0.0042477419386764, - -0.2810602378828649, -0.0702363569552985, -0.0169979112172524, -0.0042477419386764, - - 0.2429217125547283, 0.0221246935211791, -0.0583024022887367, -0.0028682244940153, - 0.1246122296507557, 0.0121888724188829, -0.0293231266236291, -0.0028682244940153, - 0.0230339393529534, 0.0022530513165867, -0.029323126623629 , -0.0028682244940153, - -0.0785443509448489, -0.0076827697857095, -0.029323126623629 , -0.0028682244940153, - -0.1801226412426513, -0.0176185908880057, -0.029323126623629 , -0.0028682244940153, - -0.2817009315404534, -0.0275544119903019, -0.0293231266236291, -0.0028682244940153, - -0.3832792218382559, -0.0374902330925982, -0.029323126623629 , -0.0028682244940153, - -0.4848575121360577, -0.0474260541948943, -0.0293231266236291, -0.0028682244940153, - - 0.2947281302116578, 0.0077857556587993, -0.065018537629936 , -0.00100933805314 , - 0.153153272024753 , 0.0042893060786969, -0.0360392619648284, -0.00100933805314 , - 0.0283096064440184, 0.0007928564985946, -0.0360392619648283, -0.00100933805314 , - -0.0965340591367161, -0.0027035930815078, -0.0360392619648283, -0.00100933805314 , - -0.2213777247174507, -0.0062000426616102, -0.0360392619648283, -0.00100933805314 , - -0.346221390298185 , -0.0096964922417126, -0.0360392619648284, -0.00100933805314 , - -0.4710650558789197, -0.013192941821815 , -0.0360392619648282, -0.00100933805314 , - -0.5959087214596538, -0.0166893914019173, -0.0360392619648285, -0.00100933805314 , + -0.0945119140688464, -0.0545664790292753, 0.0089011533518588, 0.0051390832837939, + -0.053220418987227, -0.0307268232286602, 0.0125235628099973, 0.0072304823595651, + -0.0098375248298362, -0.0056796976086655, 0.0125235628099973, 0.0072304823595651, + 0.0335453693275545, 0.0193674280113291, 0.0125235628099973, 0.0072304823595651, + 0.0769282634849452, 0.0444145536313237, 0.0125235628099971, 0.0072304823595651, + 0.1203111576423362, 0.0694616792513183, 0.0125235628099974, 0.0072304823595651, + 0.1636940517997271, 0.0945088048713129, 0.0125235628099971, 0.0072304823595652, + 0.2070769459571174, 0.1195559304913075, 0.0125235628099976, 0.0072304823595651, + + -0.2058972783827619, -0.0097418910411483, 0.0166384825044111, -0.000671934214759, + -0.1168888981292208, -0.0060321903428641, 0.0275057108788265, 0.0014194648610122, + -0.0216063206483658, -0.0011150198252003, 0.0275057108788265, 0.0014194648610122, + 0.0736762568324891, 0.0038021506924635, 0.0275057108788265, 0.0014194648610122, + 0.168958834313344, 0.0087193212101273, 0.0275057108788263, 0.0014194648610122, + 0.2642414117941991, 0.013636491727791, 0.0275057108788266, 0.0014194648610122, + 0.3595239892750542, 0.0185536622454548, 0.0275057108788264, 0.0014194648610122, + 0.4548065667559088, 0.0234708327631186, 0.0275057108788267, 0.0014194648610122, + + -0.1897591530796203, 0.0190592420291331, 0.0078437862017036, -0.0044056860630501, + -0.1103025037352215, 0.0098348469192286, 0.0259558334923959, -0.0023142869872789, + -0.0203888590119662, 0.0018179216287036, 0.0259558334923959, -0.0023142869872789, + 0.069524785711289, -0.0061990036618213, 0.0259558334923959, -0.0023142869872789, + 0.1594384304345441, -0.0142159289523463, 0.0259558334923958, -0.0023142869872788, + 0.2493520751577995, -0.0222328542428713, 0.0259558334923959, -0.0023142869872789, + 0.3392657198810548, -0.0302497795333963, 0.0259558334923958, -0.0023142869872789, + 0.4291793646043098, -0.0382667048239212, 0.0259558334923961, -0.0023142869872789, + + -0.0973346545234177, 0.0343020670920067, -0.0108406039001325, -0.0063817515918889, + -0.0616886403509405, 0.0182323801920337, 0.0145162623068366, -0.0042903525161177, + -0.0114028326480643, 0.0033701631114402, 0.0145162623068367, -0.0042903525161177, + 0.0388829750548119, -0.0114920539691533, 0.0145162623068367, -0.0042903525161177, + 0.0891687827576879, -0.0263542710497468, 0.0145162623068366, -0.0042903525161176, + 0.1394545904605643, -0.0412164881303402, 0.0145162623068367, -0.0042903525161177, + 0.1897403981634405, -0.0560787052109337, 0.0145162623068366, -0.0042903525161176, + 0.2400262058663166, -0.0709409222915272, 0.0145162623068367, -0.0042903525161177, + + 0.0265872212400778, 0.0372442612385308, -0.0302570019628495, -0.0048283110563137, + 0.0054298549021959, 0.0205185011099672, -0.0012777262977419, -0.0048283110563137, + 0.0010036811704842, 0.0037927409814036, -0.0012777262977419, -0.0048283110563137, + -0.0034224925612275, -0.0129330191471601, -0.0012777262977419, -0.0048283110563137, + -0.0078486662929393, -0.0296587792757237, -0.001277726297742, -0.0048283110563136, + -0.0122748400246508, -0.0463845394042873, -0.0012777262977419, -0.0048283110563137, + -0.0167010137563626, -0.063110299532851, -0.0012777262977419, -0.0048283110563136, + -0.0211271874880741, -0.0798360596614145, -0.0012777262977419, -0.0048283110563137, + + 0.1478483966348688, 0.0327659110179022, -0.04597718688236, -0.0042477419386764, + 0.0722347123270465, 0.0180513013074449, -0.0169979112172524, -0.0042477419386764, + 0.0133522206253946, 0.0033366915969877, -0.0169979112172523, -0.0042477419386764, + -0.0455302710762574, -0.0113779181134696, -0.0169979112172523, -0.0042477419386764, + -0.1044127627779095, -0.0260925278239268, -0.0169979112172524, -0.0042477419386764, + -0.1632952544795612, -0.040807137534384, -0.0169979112172523, -0.0042477419386764, + -0.2221777461812133, -0.0555217472448413, -0.0169979112172523, -0.0042477419386764, + -0.2810602378828649, -0.0702363569552985, -0.0169979112172524, -0.0042477419386764, + + 0.2429217125547283, 0.0221246935211791, -0.0583024022887367, -0.0028682244940153, + 0.1246122296507557, 0.0121888724188829, -0.0293231266236291, -0.0028682244940153, + 0.0230339393529534, 0.0022530513165867, -0.029323126623629, -0.0028682244940153, + -0.0785443509448489, -0.0076827697857095, -0.029323126623629, -0.0028682244940153, + -0.1801226412426513, -0.0176185908880057, -0.029323126623629, -0.0028682244940153, + -0.2817009315404534, -0.0275544119903019, -0.0293231266236291, -0.0028682244940153, + -0.3832792218382559, -0.0374902330925982, -0.029323126623629, -0.0028682244940153, + -0.4848575121360577, -0.0474260541948943, -0.0293231266236291, -0.0028682244940153, + + 0.2947281302116578, 0.0077857556587993, -0.065018537629936, -0.00100933805314, + 0.153153272024753, 0.0042893060786969, -0.0360392619648284, -0.00100933805314, + 0.0283096064440184, 0.0007928564985946, -0.0360392619648283, -0.00100933805314, + -0.0965340591367161, -0.0027035930815078, -0.0360392619648283, -0.00100933805314, + -0.2213777247174507, -0.0062000426616102, -0.0360392619648283, -0.00100933805314, + -0.346221390298185, -0.0096964922417126, -0.0360392619648284, -0.00100933805314, + -0.4710650558789197, -0.013192941821815, -0.0360392619648282, -0.00100933805314, + -0.5959087214596538, -0.0166893914019173, -0.0360392619648285, -0.00100933805314 }; return sol; } -static const double * -get_sol_3x_bias_p1_DxDx_DyDy(void) +static const double *get_sol_3x_bias_p1_DxDx_DyDy(void) { static const double sol[512] = { - -1.4857902425065184e-04, -8.5782139646996372e-05, -8.5782139646865672e-05, 1.8914704406197892e-04, -4.9526341416772864e-05, 1.0920409680558287e-04, - 1.0920409680550554e-04, 6.3049014687256998e-05, -3.7869881831633913e-04, -2.1864186469671895e-04, -4.7077585402820190e-05, 4.8209875139245301e-04, - -2.7180256605144123e-05, 2.7833984389239624e-04, 5.9931650281304105e-05, 3.4601554422903200e-05, -4.8238508035628331e-04, -2.7850515599677118e-04, - -1.2785705897207671e-05, 6.1409551253425998e-04, -7.3818307415179943e-06, 3.5454820946987623e-04, 1.6276715296076932e-05, 9.3973659577562421e-06, - -4.7821812488875947e-04, -2.7609936313588445e-04, 1.5191498758083683e-05, 6.0879081146090802e-04, 8.7708158973654205e-06, 3.5148553887719326e-04, - -1.9339385888747259e-05, -1.1165599648880918e-05, -3.9208040614287438e-04, -2.2636772803058295e-04, 3.4540136347233381e-05, 4.9913404823207755e-04, - 1.9941757017920681e-05, 2.8817517710849280e-04, -4.3970975879881029e-05, -2.5386654760770837e-05, -2.5807022372215224e-04, -1.4899691313582957e-04, - 4.2830678547521361e-05, 3.2853372287024223e-04, 2.4728303788985857e-05, 1.8967903333702248e-04, -5.4525167891612326e-05, -3.1480120359827638e-05, - -1.1891747993225567e-04, -6.8657039050248661e-05, 3.7509195538050490e-05, 1.5138671107812069e-04, 2.1655944140984915e-05, 8.7403158392697900e-05, - -4.7750707052706831e-05, -2.7568883570882659e-05, -2.6974823754671981e-05, -1.5573921756102582e-05, 1.5573921756086665e-05, 3.4340030182754069e-05, - 8.9916079182148039e-06, 1.9826225669992933e-05, -1.9826225669985302e-05, -1.1446676727580283e-05, -3.7869881831637274e-04, -4.7077585402708903e-05, - -2.1864186469670288e-04, 4.8209875139248608e-04, -2.7180256605210324e-05, 5.9931650281245863e-05, 2.7833984389239038e-04, 3.4601554422944427e-05, - -9.6593915317034899e-04, -1.2040150071024966e-04, -1.2040150071024630e-04, 1.2296791992509439e-03, -1.5153325635635661e-05, 1.5327592891960440e-04, - 1.5327592891959123e-04, 1.9290789976223312e-05, -1.2313170233906195e-03, -1.5389090291881229e-04, -3.2814484098396489e-05, 1.5675158485681691e-03, - -4.1817897444776702e-06, 1.9590927819016461e-04, 4.1774151505829872e-05, 5.3235857015899117e-06, -1.2211748055640191e-03, -1.5284687644820770e-04, - 3.8670096290763775e-05, 1.5546043993793627e-03, 4.7845587083223804e-06, 1.9458019071073231e-04, -4.9228580170615438e-05, -6.0909347156166817e-06, - -1.0016098602570024e-03, -1.2554426638121464e-04, 8.8095783986847693e-05, 1.2750894369280114e-03, 1.0978610563435414e-05, 1.5982287543424525e-04, - -1.1214945864320036e-04, -1.3976210615571825e-05, -6.5979684339352812e-04, -8.2940058872077652e-05, 1.0925005331179741e-04, 8.3994778696934870e-04, - 1.3618940110575512e-05, 1.0558601423795712e-04, -1.3907969009605144e-04, -1.7337455796105482e-05, -3.0491150826769746e-04, -3.8726663276881513e-05, - 9.5643090454551556e-05, 3.8816455270337567e-04, 1.1907675738098372e-05, 4.9300592207781632e-05, -1.2175748182276777e-04, -1.5158947764468026e-05, - -6.9626408103776196e-05, -9.0509819492167675e-06, 4.0198825461396472e-05, 8.8637203992388735e-05, 5.2255868648144249e-06, 1.1522262245235528e-05, - -5.1174713585175428e-05, -6.6523812089424644e-06, -4.8238508035620151e-04, -1.2785705897252288e-05, -2.7850515599680664e-04, 6.1409551253430368e-04, - -7.3818307414815423e-06, 1.6276715296141225e-05, 3.5454820946987097e-04, 9.3973659577153728e-06, -1.2313170233906072e-03, -3.2814484098386040e-05, - -1.5389090291881698e-04, 1.5675158485681897e-03, -4.1817897444823730e-06, 4.1774151505828591e-05, 1.9590927819015664e-04, 5.3235857015929212e-06, - -1.5708705777981958e-03, -4.2150433122696279e-05, -4.2150433122698495e-05, 1.9997811123959371e-03, -1.2083229378437410e-06, 5.3659188242121851e-05, - 5.3659188242117866e-05, 1.5382434574345833e-06, -1.5587645637327890e-03, -4.2060661306192221e-05, 4.9139843602174565e-05, 1.9843696720032254e-03, - 1.2601527202679231e-06, 5.3544905127007844e-05, -6.2556987501449741e-05, -1.6042248447095148e-06, -1.2792161864866266e-03, -3.4731820796201924e-05, - 1.1225748725242052e-04, 1.6284934001327763e-03, 2.9711553210228856e-06, 4.4214997854706335e-05, -1.4290827386115453e-04, -3.7823996304679761e-06, - -8.4357750896041524e-04, -2.3165757864813304e-05, 1.3925862048675021e-04, 1.0739079292105724e-03, 3.7065142258784857e-06, 2.9490936864656485e-05, - -1.7728179706443526e-04, -4.7185409457017731e-06, -3.9114247992314450e-04, -1.1058811420873844e-05, 1.2195486531873429e-04, 4.9794003061819580e-04, - 3.2834345625943677e-06, 1.4078309516759583e-05, -1.5525342423245637e-04, -4.1799436025258761e-06, -8.9955228480428413e-05, -2.6858679675509360e-06, - 5.1935675378201352e-05, 1.1451660589930813e-04, 1.5506865940911167e-06, 3.4192174121908953e-06, -6.6116193242601623e-05, -1.9740860933638614e-06, - -4.7821812488872613e-04, 1.5191498758100369e-05, -2.7609936313588413e-04, 6.0879081146098728e-04, 8.7708158973496454e-06, -1.9339385888790925e-05, - 3.5148553887716583e-04, -1.1165599648852878e-05, -1.2211748055639972e-03, 3.8670096290759126e-05, -1.5284687644821456e-04, 1.5546043993793848e-03, - 4.7845587083257541e-06, -4.9228580170613290e-05, 1.9458019071072680e-04, -6.0909347156182750e-06, -1.5587645637327831e-03, 4.9139843602175452e-05, - -4.2060661306194789e-05, 1.9843696720032327e-03, 1.2601527202678208e-06, -6.2556987501449768e-05, 5.3544905127004523e-05, -1.6042248447091459e-06, - -1.5474982642617466e-03, 4.8565262338569481e-05, 4.8565262338568776e-05, 1.9700272218948593e-03, -1.5918873674820159e-06, -6.1825522557911871e-05, - -6.1825522557912508e-05, 2.0265363267635107e-06, -1.2706869384245629e-03, 3.9656184460819470e-05, 1.1125183114826664e-04, 1.6176353260059105e-03, - -3.5517711434683191e-06, -5.0483909874733382e-05, -1.4162803339381479e-04, 4.5215468089140504e-06, -8.3879554668975795e-04, 2.5926625069031862e-05, - 1.3810078013050519e-04, 1.0678202998640151e-03, -4.3749936672351580e-06, -3.3005631306618052e-05, -1.7580781995370960e-04, 5.5695420273585997e-06, - -3.8988499721200347e-04, 1.1784819402652368e-05, 1.2107784645253936e-04, 4.9633920480195821e-04, -3.7897816410764171e-06, -1.5002546732690018e-05, - -1.5413694411715089e-04, 4.8245436976423641e-06, -9.0086007742574192e-05, 2.6103625253466520e-06, 5.2011180820413507e-05, 1.1468309313383139e-04, - -1.5070935067046508e-06, -3.3230959625222529e-06, -6.6212314692308015e-05, 1.9185903485009741e-06, -3.9208040614284722e-04, 3.4540136347213093e-05, - -2.2636772803059100e-04, 4.9913404823208253e-04, 1.9941757017931554e-05, -4.3970975879880263e-05, 2.8817517710850375e-04, -2.5386654760776736e-05, - -1.0016098602569918e-03, 8.8095783986845972e-05, -1.2554426638121602e-04, 1.2750894369280275e-03, 1.0978610563435211e-05, -1.1214945864320599e-04, - 1.5982287543424081e-04, -1.3976210615569642e-05, -1.2792161864866210e-03, 1.1225748725241937e-04, -3.4731820796203604e-05, 1.6284934001327808e-03, - 2.9711553210233968e-06, -1.4290827386115594e-04, 4.4214997854704112e-05, -3.7823996304677249e-06, -1.2706869384245618e-03, 1.1125183114826646e-04, - 3.9656184460818718e-05, 1.6176353260059101e-03, -3.5517711434682683e-06, -1.4162803339381555e-04, -5.0483909874733890e-05, 4.5215468089141537e-06, - -1.0441173998824859e-03, 9.1153799606617992e-05, 9.1153799606618073e-05, 1.3292032360397348e-03, -8.0518327772840401e-06, -1.1604243491016443e-04, - -1.1604243491016380e-04, 1.0250305362999503e-05, -6.9005433895489503e-04, 5.9949151256281410e-05, 1.1326460393002962e-04, 8.7846678973585207e-04, - -9.9641793477503907e-06, -7.6317668737877270e-05, -1.4419037369695810e-04, 1.2684799080065410e-05, -3.2161392308227690e-04, 2.7631503624010198e-05, - 9.9454569354364179e-05, 4.0942739519954688e-04, -8.6944232123168641e-06, -3.5176009937019723e-05, -1.2660964699911679e-04, 1.1068348703517426e-05, - -7.4676777957819192e-05, 6.2861604388864368e-06, 4.3114657856159156e-05, 9.5066526934358737e-05, -3.6293164215592856e-06, -8.0025338133193964e-06, - -5.4886684916474010e-05, 4.6202650513188232e-06, -2.5807022372216449e-04, 4.2830678547518969e-05, -1.4899691313582071e-04, 3.2853372287025562e-04, - 2.4728303788984804e-05, -5.4525167891608260e-05, 1.8967903333701682e-04, -3.1480120359831297e-05, -6.5979684339352498e-04, 1.0925005331179476e-04, - -8.2940058872077706e-05, 8.3994778696934924e-04, 1.3618940110576470e-05, -1.3907969009605478e-04, 1.0558601423795538e-04, -1.7337455796106072e-05, - -8.4357750896041372e-04, 1.3925862048674929e-04, -2.3165757864814100e-05, 1.0739079292105683e-03, 3.7065142258784857e-06, -1.7728179706443878e-04, - 2.9490936864655540e-05, -4.7185409457013005e-06, -8.3879554668975860e-04, 1.3810078013050441e-04, 2.5926625069031462e-05, 1.0678202998640096e-03, - -4.3749936672350818e-06, -1.7580781995371169e-04, -3.3005631306617849e-05, 5.5695420273589242e-06, -6.9005433895489578e-04, 1.1326460393002904e-04, - 5.9949151256281458e-05, 8.7846678973584904e-04, -9.9641793477503653e-06, -1.4419037369695927e-04, -7.6317668737876267e-05, 1.2684799080065638e-05, - -4.5700790975607651e-04, 7.4600267375337498e-05, 7.4600267375337959e-05, 5.8178935875592588e-04, -1.2358685770139086e-05, -9.4969125900869786e-05, - -9.4969125900869000e-05, 1.5733101584855904e-05, -2.1405750025111815e-04, 3.4466226050632516e-05, 6.5667216952079626e-05, 2.7250376448509594e-04, - -1.0812713792346902e-05, -4.3876885114389393e-05, -8.3596995207867956e-05, 1.3765017386719724e-05, -5.0159272049234077e-05, 7.8690281972934216e-06, - 2.8959469219980895e-05, 6.3854760712488500e-05, -4.5431855479681580e-06, -1.0017587816761052e-05, -3.6866563286394175e-05, 5.7836570226375672e-06, - -1.1891747993226251e-04, 3.7509195538055992e-05, -6.8657039050244378e-05, 1.5138671107812595e-04, 2.1655944140983332e-05, -4.7750707052715593e-05, - 8.7403158392689037e-05, -2.7568883570880843e-05, -3.0491150826769691e-04, 9.5643090454552613e-05, -3.8726663276881581e-05, 3.8816455270336027e-04, - 1.1907675738097432e-05, -1.2175748182277376e-04, 4.9300592207778536e-05, -1.5158947764468221e-05, -3.9114247992314591e-04, 1.2195486531873341e-04, - -1.1058811420874908e-05, 4.9794003061817552e-04, 3.2834345625941889e-06, -1.5525342423246220e-04, 1.4078309516759917e-05, -4.1799436025256102e-06, - -3.8988499721200818e-04, 1.2107784645253757e-04, 1.1784819402651616e-05, 4.9633920480194390e-04, -3.7897816410767364e-06, -1.5413694411715395e-04, - -1.5002546732686913e-05, 4.8245436976436923e-06, -3.2161392308228053e-04, 9.9454569354363149e-05, 2.7631503624011527e-05, 4.0942739519954103e-04, - -8.6944232123161492e-06, -1.2660964699911720e-04, -3.5176009937017941e-05, 1.1068348703517651e-05, -2.1405750025111896e-04, 6.5667216952079626e-05, - 3.4466226050632868e-05, 2.7250376448509437e-04, -1.0812713792346967e-05, -8.3596995207868051e-05, -4.3876885114388695e-05, 1.3765017386719678e-05, - -1.0163877852160976e-04, 3.0438753201852812e-05, 3.0438753201852917e-05, 1.2939023268193514e-04, -9.5264492369834572e-06, -3.8749750996843554e-05, - -3.8749750996843378e-05, 1.2127551130928198e-05, -2.4458655728475410e-05, 6.9692295538358886e-06, 1.4121211468851588e-05, 3.1136847587379800e-05, - -4.0236865589514017e-06, -8.8721081333432448e-06, -1.7976867336290102e-05, 5.1223140190652031e-06, -2.6974823754661329e-05, 1.5573921756091266e-05, - -1.5573921756096677e-05, 3.4340030182743030e-05, 8.9916079182173179e-06, -1.9826225669985950e-05, 1.9826225669986620e-05, -1.1446676727580623e-05, - -6.9626408103756491e-05, 4.0198825461406474e-05, -9.0509819492174502e-06, 8.8637203992336435e-05, 5.2255868648150289e-06, -5.1174713585190749e-05, - 1.1522262245218026e-05, -6.6523812089505900e-06, -8.9955228480439079e-05, 5.1935675378196955e-05, -2.6858679675677970e-06, 1.1451660589925285e-04, - 1.5506865940821917e-06, -6.6116193242616016e-05, 3.4192174122066818e-06, -1.9740860933552026e-06, -9.0086007742595225e-05, 5.2011180820405816e-05, - 2.6103625253575236e-06, 1.1468309313381435e-04, -1.5070935066976264e-06, -6.6212314692306511e-05, -3.3230959625159697e-06, 1.9185903485014870e-06, - -7.4676777957820601e-05, 4.3114657856161548e-05, 6.2861604388869069e-06, 9.5066526934354780e-05, -3.6293164215604896e-06, -5.4886684916472533e-05, - -8.0025338133181208e-06, 4.6202650513183065e-06, -5.0159272049234396e-05, 2.8959469219981146e-05, 7.8690281972935876e-06, 6.3854760712487497e-05, - -4.5431855479681952e-06, -3.6866563286393782e-05, -1.0017587816760623e-05, 5.7836570226374503e-06, -2.4458655728475423e-05, 1.4121211468851677e-05, - 6.9692295538358971e-06, 3.1136847587379671e-05, -4.0236865589514525e-06, -1.7976867336290004e-05, -8.8721081333431685e-06, 5.1223140190651497e-06, - -6.1937980258105384e-06, 3.5759909575078880e-06, 3.5759909575078880e-06, 7.8849527650921135e-06, -2.0645993419368465e-06, -4.5523796014734159e-06, - -4.5523796014734159e-06, 2.6283175883640376e-06, + -1.4857902425065184e-04, -8.5782139646996372e-05, -8.5782139646865672e-05, + 1.8914704406197892e-04, -4.9526341416772864e-05, 1.0920409680558287e-04, + 1.0920409680550554e-04, 6.3049014687256998e-05, -3.7869881831633913e-04, + -2.1864186469671895e-04, -4.7077585402820190e-05, 4.8209875139245301e-04, + -2.7180256605144123e-05, 2.7833984389239624e-04, 5.9931650281304105e-05, + 3.4601554422903200e-05, -4.8238508035628331e-04, -2.7850515599677118e-04, + -1.2785705897207671e-05, 6.1409551253425998e-04, -7.3818307415179943e-06, + 3.5454820946987623e-04, 1.6276715296076932e-05, 9.3973659577562421e-06, + -4.7821812488875947e-04, -2.7609936313588445e-04, 1.5191498758083683e-05, + 6.0879081146090802e-04, 8.7708158973654205e-06, 3.5148553887719326e-04, + -1.9339385888747259e-05, -1.1165599648880918e-05, -3.9208040614287438e-04, + -2.2636772803058295e-04, 3.4540136347233381e-05, 4.9913404823207755e-04, + 1.9941757017920681e-05, 2.8817517710849280e-04, -4.3970975879881029e-05, + -2.5386654760770837e-05, -2.5807022372215224e-04, -1.4899691313582957e-04, + 4.2830678547521361e-05, 3.2853372287024223e-04, 2.4728303788985857e-05, + 1.8967903333702248e-04, -5.4525167891612326e-05, -3.1480120359827638e-05, + -1.1891747993225567e-04, -6.8657039050248661e-05, 3.7509195538050490e-05, + 1.5138671107812069e-04, 2.1655944140984915e-05, 8.7403158392697900e-05, + -4.7750707052706831e-05, -2.7568883570882659e-05, -2.6974823754671981e-05, + -1.5573921756102582e-05, 1.5573921756086665e-05, 3.4340030182754069e-05, + 8.9916079182148039e-06, 1.9826225669992933e-05, -1.9826225669985302e-05, + -1.1446676727580283e-05, -3.7869881831637274e-04, -4.7077585402708903e-05, + -2.1864186469670288e-04, 4.8209875139248608e-04, -2.7180256605210324e-05, + 5.9931650281245863e-05, 2.7833984389239038e-04, 3.4601554422944427e-05, + -9.6593915317034899e-04, -1.2040150071024966e-04, -1.2040150071024630e-04, + 1.2296791992509439e-03, -1.5153325635635661e-05, 1.5327592891960440e-04, + 1.5327592891959123e-04, 1.9290789976223312e-05, -1.2313170233906195e-03, + -1.5389090291881229e-04, -3.2814484098396489e-05, 1.5675158485681691e-03, + -4.1817897444776702e-06, 1.9590927819016461e-04, 4.1774151505829872e-05, + 5.3235857015899117e-06, -1.2211748055640191e-03, -1.5284687644820770e-04, + 3.8670096290763775e-05, 1.5546043993793627e-03, 4.7845587083223804e-06, + 1.9458019071073231e-04, -4.9228580170615438e-05, -6.0909347156166817e-06, + -1.0016098602570024e-03, -1.2554426638121464e-04, 8.8095783986847693e-05, + 1.2750894369280114e-03, 1.0978610563435414e-05, 1.5982287543424525e-04, + -1.1214945864320036e-04, -1.3976210615571825e-05, -6.5979684339352812e-04, + -8.2940058872077652e-05, 1.0925005331179741e-04, 8.3994778696934870e-04, + 1.3618940110575512e-05, 1.0558601423795712e-04, -1.3907969009605144e-04, + -1.7337455796105482e-05, -3.0491150826769746e-04, -3.8726663276881513e-05, + 9.5643090454551556e-05, 3.8816455270337567e-04, 1.1907675738098372e-05, + 4.9300592207781632e-05, -1.2175748182276777e-04, -1.5158947764468026e-05, + -6.9626408103776196e-05, -9.0509819492167675e-06, 4.0198825461396472e-05, + 8.8637203992388735e-05, 5.2255868648144249e-06, 1.1522262245235528e-05, + -5.1174713585175428e-05, -6.6523812089424644e-06, -4.8238508035620151e-04, + -1.2785705897252288e-05, -2.7850515599680664e-04, 6.1409551253430368e-04, + -7.3818307414815423e-06, 1.6276715296141225e-05, 3.5454820946987097e-04, + 9.3973659577153728e-06, -1.2313170233906072e-03, -3.2814484098386040e-05, + -1.5389090291881698e-04, 1.5675158485681897e-03, -4.1817897444823730e-06, + 4.1774151505828591e-05, 1.9590927819015664e-04, 5.3235857015929212e-06, + -1.5708705777981958e-03, -4.2150433122696279e-05, -4.2150433122698495e-05, + 1.9997811123959371e-03, -1.2083229378437410e-06, 5.3659188242121851e-05, + 5.3659188242117866e-05, 1.5382434574345833e-06, -1.5587645637327890e-03, + -4.2060661306192221e-05, 4.9139843602174565e-05, 1.9843696720032254e-03, + 1.2601527202679231e-06, 5.3544905127007844e-05, -6.2556987501449741e-05, + -1.6042248447095148e-06, -1.2792161864866266e-03, -3.4731820796201924e-05, + 1.1225748725242052e-04, 1.6284934001327763e-03, 2.9711553210228856e-06, + 4.4214997854706335e-05, -1.4290827386115453e-04, -3.7823996304679761e-06, + -8.4357750896041524e-04, -2.3165757864813304e-05, 1.3925862048675021e-04, + 1.0739079292105724e-03, 3.7065142258784857e-06, 2.9490936864656485e-05, + -1.7728179706443526e-04, -4.7185409457017731e-06, -3.9114247992314450e-04, + -1.1058811420873844e-05, 1.2195486531873429e-04, 4.9794003061819580e-04, + 3.2834345625943677e-06, 1.4078309516759583e-05, -1.5525342423245637e-04, + -4.1799436025258761e-06, -8.9955228480428413e-05, -2.6858679675509360e-06, + 5.1935675378201352e-05, 1.1451660589930813e-04, 1.5506865940911167e-06, + 3.4192174121908953e-06, -6.6116193242601623e-05, -1.9740860933638614e-06, + -4.7821812488872613e-04, 1.5191498758100369e-05, -2.7609936313588413e-04, + 6.0879081146098728e-04, 8.7708158973496454e-06, -1.9339385888790925e-05, + 3.5148553887716583e-04, -1.1165599648852878e-05, -1.2211748055639972e-03, + 3.8670096290759126e-05, -1.5284687644821456e-04, 1.5546043993793848e-03, + 4.7845587083257541e-06, -4.9228580170613290e-05, 1.9458019071072680e-04, + -6.0909347156182750e-06, -1.5587645637327831e-03, 4.9139843602175452e-05, + -4.2060661306194789e-05, 1.9843696720032327e-03, 1.2601527202678208e-06, + -6.2556987501449768e-05, 5.3544905127004523e-05, -1.6042248447091459e-06, + -1.5474982642617466e-03, 4.8565262338569481e-05, 4.8565262338568776e-05, + 1.9700272218948593e-03, -1.5918873674820159e-06, -6.1825522557911871e-05, + -6.1825522557912508e-05, 2.0265363267635107e-06, -1.2706869384245629e-03, + 3.9656184460819470e-05, 1.1125183114826664e-04, 1.6176353260059105e-03, + -3.5517711434683191e-06, -5.0483909874733382e-05, -1.4162803339381479e-04, + 4.5215468089140504e-06, -8.3879554668975795e-04, 2.5926625069031862e-05, + 1.3810078013050519e-04, 1.0678202998640151e-03, -4.3749936672351580e-06, + -3.3005631306618052e-05, -1.7580781995370960e-04, 5.5695420273585997e-06, + -3.8988499721200347e-04, 1.1784819402652368e-05, 1.2107784645253936e-04, + 4.9633920480195821e-04, -3.7897816410764171e-06, -1.5002546732690018e-05, + -1.5413694411715089e-04, 4.8245436976423641e-06, -9.0086007742574192e-05, + 2.6103625253466520e-06, 5.2011180820413507e-05, 1.1468309313383139e-04, + -1.5070935067046508e-06, -3.3230959625222529e-06, -6.6212314692308015e-05, + 1.9185903485009741e-06, -3.9208040614284722e-04, 3.4540136347213093e-05, + -2.2636772803059100e-04, 4.9913404823208253e-04, 1.9941757017931554e-05, + -4.3970975879880263e-05, 2.8817517710850375e-04, -2.5386654760776736e-05, + -1.0016098602569918e-03, 8.8095783986845972e-05, -1.2554426638121602e-04, + 1.2750894369280275e-03, 1.0978610563435211e-05, -1.1214945864320599e-04, + 1.5982287543424081e-04, -1.3976210615569642e-05, -1.2792161864866210e-03, + 1.1225748725241937e-04, -3.4731820796203604e-05, 1.6284934001327808e-03, + 2.9711553210233968e-06, -1.4290827386115594e-04, 4.4214997854704112e-05, + -3.7823996304677249e-06, -1.2706869384245618e-03, 1.1125183114826646e-04, + 3.9656184460818718e-05, 1.6176353260059101e-03, -3.5517711434682683e-06, + -1.4162803339381555e-04, -5.0483909874733890e-05, 4.5215468089141537e-06, + -1.0441173998824859e-03, 9.1153799606617992e-05, 9.1153799606618073e-05, + 1.3292032360397348e-03, -8.0518327772840401e-06, -1.1604243491016443e-04, + -1.1604243491016380e-04, 1.0250305362999503e-05, -6.9005433895489503e-04, + 5.9949151256281410e-05, 1.1326460393002962e-04, 8.7846678973585207e-04, + -9.9641793477503907e-06, -7.6317668737877270e-05, -1.4419037369695810e-04, + 1.2684799080065410e-05, -3.2161392308227690e-04, 2.7631503624010198e-05, + 9.9454569354364179e-05, 4.0942739519954688e-04, -8.6944232123168641e-06, + -3.5176009937019723e-05, -1.2660964699911679e-04, 1.1068348703517426e-05, + -7.4676777957819192e-05, 6.2861604388864368e-06, 4.3114657856159156e-05, + 9.5066526934358737e-05, -3.6293164215592856e-06, -8.0025338133193964e-06, + -5.4886684916474010e-05, 4.6202650513188232e-06, -2.5807022372216449e-04, + 4.2830678547518969e-05, -1.4899691313582071e-04, 3.2853372287025562e-04, + 2.4728303788984804e-05, -5.4525167891608260e-05, 1.8967903333701682e-04, + -3.1480120359831297e-05, -6.5979684339352498e-04, 1.0925005331179476e-04, + -8.2940058872077706e-05, 8.3994778696934924e-04, 1.3618940110576470e-05, + -1.3907969009605478e-04, 1.0558601423795538e-04, -1.7337455796106072e-05, + -8.4357750896041372e-04, 1.3925862048674929e-04, -2.3165757864814100e-05, + 1.0739079292105683e-03, 3.7065142258784857e-06, -1.7728179706443878e-04, + 2.9490936864655540e-05, -4.7185409457013005e-06, -8.3879554668975860e-04, + 1.3810078013050441e-04, 2.5926625069031462e-05, 1.0678202998640096e-03, + -4.3749936672350818e-06, -1.7580781995371169e-04, -3.3005631306617849e-05, + 5.5695420273589242e-06, -6.9005433895489578e-04, 1.1326460393002904e-04, + 5.9949151256281458e-05, 8.7846678973584904e-04, -9.9641793477503653e-06, + -1.4419037369695927e-04, -7.6317668737876267e-05, 1.2684799080065638e-05, + -4.5700790975607651e-04, 7.4600267375337498e-05, 7.4600267375337959e-05, + 5.8178935875592588e-04, -1.2358685770139086e-05, -9.4969125900869786e-05, + -9.4969125900869000e-05, 1.5733101584855904e-05, -2.1405750025111815e-04, + 3.4466226050632516e-05, 6.5667216952079626e-05, 2.7250376448509594e-04, + -1.0812713792346902e-05, -4.3876885114389393e-05, -8.3596995207867956e-05, + 1.3765017386719724e-05, -5.0159272049234077e-05, 7.8690281972934216e-06, + 2.8959469219980895e-05, 6.3854760712488500e-05, -4.5431855479681580e-06, + -1.0017587816761052e-05, -3.6866563286394175e-05, 5.7836570226375672e-06, + -1.1891747993226251e-04, 3.7509195538055992e-05, -6.8657039050244378e-05, + 1.5138671107812595e-04, 2.1655944140983332e-05, -4.7750707052715593e-05, + 8.7403158392689037e-05, -2.7568883570880843e-05, -3.0491150826769691e-04, + 9.5643090454552613e-05, -3.8726663276881581e-05, 3.8816455270336027e-04, + 1.1907675738097432e-05, -1.2175748182277376e-04, 4.9300592207778536e-05, + -1.5158947764468221e-05, -3.9114247992314591e-04, 1.2195486531873341e-04, + -1.1058811420874908e-05, 4.9794003061817552e-04, 3.2834345625941889e-06, + -1.5525342423246220e-04, 1.4078309516759917e-05, -4.1799436025256102e-06, + -3.8988499721200818e-04, 1.2107784645253757e-04, 1.1784819402651616e-05, + 4.9633920480194390e-04, -3.7897816410767364e-06, -1.5413694411715395e-04, + -1.5002546732686913e-05, 4.8245436976436923e-06, -3.2161392308228053e-04, + 9.9454569354363149e-05, 2.7631503624011527e-05, 4.0942739519954103e-04, + -8.6944232123161492e-06, -1.2660964699911720e-04, -3.5176009937017941e-05, + 1.1068348703517651e-05, -2.1405750025111896e-04, 6.5667216952079626e-05, + 3.4466226050632868e-05, 2.7250376448509437e-04, -1.0812713792346967e-05, + -8.3596995207868051e-05, -4.3876885114388695e-05, 1.3765017386719678e-05, + -1.0163877852160976e-04, 3.0438753201852812e-05, 3.0438753201852917e-05, + 1.2939023268193514e-04, -9.5264492369834572e-06, -3.8749750996843554e-05, + -3.8749750996843378e-05, 1.2127551130928198e-05, -2.4458655728475410e-05, + 6.9692295538358886e-06, 1.4121211468851588e-05, 3.1136847587379800e-05, + -4.0236865589514017e-06, -8.8721081333432448e-06, -1.7976867336290102e-05, + 5.1223140190652031e-06, -2.6974823754661329e-05, 1.5573921756091266e-05, + -1.5573921756096677e-05, 3.4340030182743030e-05, 8.9916079182173179e-06, + -1.9826225669985950e-05, 1.9826225669986620e-05, -1.1446676727580623e-05, + -6.9626408103756491e-05, 4.0198825461406474e-05, -9.0509819492174502e-06, + 8.8637203992336435e-05, 5.2255868648150289e-06, -5.1174713585190749e-05, + 1.1522262245218026e-05, -6.6523812089505900e-06, -8.9955228480439079e-05, + 5.1935675378196955e-05, -2.6858679675677970e-06, 1.1451660589925285e-04, + 1.5506865940821917e-06, -6.6116193242616016e-05, 3.4192174122066818e-06, + -1.9740860933552026e-06, -9.0086007742595225e-05, 5.2011180820405816e-05, + 2.6103625253575236e-06, 1.1468309313381435e-04, -1.5070935066976264e-06, + -6.6212314692306511e-05, -3.3230959625159697e-06, 1.9185903485014870e-06, + -7.4676777957820601e-05, 4.3114657856161548e-05, 6.2861604388869069e-06, + 9.5066526934354780e-05, -3.6293164215604896e-06, -5.4886684916472533e-05, + -8.0025338133181208e-06, 4.6202650513183065e-06, -5.0159272049234396e-05, + 2.8959469219981146e-05, 7.8690281972935876e-06, 6.3854760712487497e-05, + -4.5431855479681952e-06, -3.6866563286393782e-05, -1.0017587816760623e-05, + 5.7836570226374503e-06, -2.4458655728475423e-05, 1.4121211468851677e-05, + 6.9692295538358971e-06, 3.1136847587379671e-05, -4.0236865589514525e-06, + -1.7976867336290004e-05, -8.8721081333431685e-06, 5.1223140190651497e-06, + -6.1937980258105384e-06, 3.5759909575078880e-06, 3.5759909575078880e-06, + 7.8849527650921135e-06, -2.0645993419368465e-06, -4.5523796014734159e-06, + -4.5523796014734159e-06, 2.6283175883640376e-06 }; return sol; } -static const double * -get_sol_3x_bias_p1_DxDx_PyPy(void) +static const double *get_sol_3x_bias_p1_DxDx_PyPy(void) { static const double sol[512] = { - 5.0226946551362277e-03, 2.8998541112002828e-03, 2.8998541112001328e-03, -6.3940913062055585e-03, 1.6742315517121347e-03, -3.6916303368608990e-03, - -3.6916303368608040e-03, -2.1313637687352333e-03, 5.0226946551361054e-03, 2.8998541112002867e-03, -2.8998541112002039e-03, -6.3940913062055281e-03, - -1.6742315517121328e-03, -3.6916303368608964e-03, 3.6916303368608209e-03, 2.1313637687352342e-03, -5.0226946551365859e-03, -2.8998541112002637e-03, - -2.8998541112003253e-03, 6.3940913062057849e-03, -1.6742315517121109e-03, 3.6916303368608938e-03, 3.6916303368609415e-03, 2.1313637687352177e-03, - -5.0226946551364645e-03, -2.8998541112002676e-03, 2.8998541112003947e-03, 6.3940913062057719e-03, 1.6742315517121085e-03, 3.6916303368608890e-03, - -3.6916303368609489e-03, -2.1313637687352207e-03, 5.0226946551364515e-03, 2.8998541112002685e-03, 2.8998541112002637e-03, -6.3940913062056999e-03, - 1.6742315517121265e-03, -3.6916303368608890e-03, -3.6916303368609046e-03, -2.1313637687352246e-03, 5.0226946551364463e-03, 2.8998541112002746e-03, - -2.8998541112002672e-03, -6.3940913062057441e-03, -1.6742315517121232e-03, -3.6916303368608881e-03, 3.6916303368608790e-03, 2.1313637687352246e-03, - -5.0226946551362259e-03, -2.8998541112002832e-03, -2.8998541112002503e-03, 6.3940913062056105e-03, -1.6742315517121248e-03, 3.6916303368609046e-03, - 3.6916303368609068e-03, 2.1313637687352290e-03, -5.0226946551362190e-03, -2.8998541112002893e-03, 2.8998541112002538e-03, 6.3940913062056392e-03, - 1.6742315517121209e-03, 3.6916303368609068e-03, -3.6916303368608916e-03, -2.1313637687352281e-03, 1.2790705487348994e-02, 1.5850090338456867e-03, - 7.3847172562461283e-03, -1.6283079974463467e-02, 9.1510539235880120e-04, -2.0177799327709654e-03, -9.4010406064926836e-03, -1.1649657873507447e-03, - 1.2790705487348885e-02, 1.5850090338456915e-03, -7.3847172562461908e-03, -1.6283079974463436e-02, -9.1510539235879838e-04, -2.0177799327709650e-03, - 9.4010406064927009e-03, 1.1649657873507447e-03, -1.2790705487349287e-02, -1.5850090338456703e-03, -7.3847172562462498e-03, 1.6283079974463682e-02, - -9.1510539235878569e-04, 2.0177799327709607e-03, 9.4010406064927773e-03, 1.1649657873507358e-03, -1.2790705487349180e-02, -1.5850090338456742e-03, - 7.3847172562463122e-03, 1.6283079974463655e-02, 9.1510539235878320e-04, 2.0177799327709585e-03, -9.4010406064927911e-03, -1.1649657873507374e-03, - 1.2790705487349174e-02, 1.5850090338456761e-03, 7.3847172562462315e-03, -1.6283079974463582e-02, 9.1510539235879448e-04, -2.0177799327709585e-03, - -9.4010406064927565e-03, -1.1649657873507384e-03, 1.2790705487349183e-02, 1.5850090338456796e-03, -7.3847172562462263e-03, -1.6283079974463623e-02, - -9.1510539235879263e-04, -2.0177799327709572e-03, 9.4010406064927322e-03, 1.1649657873507393e-03, -1.2790705487348996e-02, -1.5850090338456880e-03, - -7.3847172562462159e-03, 1.6283079974463543e-02, -9.1510539235879599e-04, 2.0177799327709711e-03, 9.4010406064927738e-03, 1.1649657873507428e-03, - -1.2790705487349006e-02, -1.5850090338456926e-03, 7.3847172562462116e-03, 1.6283079974463575e-02, 9.1510539235879350e-04, 2.0177799327709715e-03, - -9.4010406064927547e-03, -1.1649657873507419e-03, 1.6258847328107631e-02, 4.1732359150411819e-04, 9.3870498815959488e-03, -2.0698163334150768e-02, - 2.4094188789408792e-04, -5.3126963343913351e-04, -1.1950090172702790e-02, -3.0672866587835884e-04, 1.6258847328107544e-02, 4.1732359150412318e-04, - -9.3870498815960008e-03, -2.0698163334150737e-02, -2.4094188789408486e-04, -5.3126963343913417e-04, 1.1950090172702807e-02, 3.0672866587835884e-04, - -1.6258847328107867e-02, -4.1732359150410052e-04, -9.3870498815960286e-03, 2.0698163334150962e-02, -2.4094188789407700e-04, 5.3126963343912647e-04, - 1.1950090172702856e-02, 3.0672866587835233e-04, -1.6258847328107773e-02, -4.1732359150410545e-04, 9.3870498815960806e-03, 2.0698163334150928e-02, - 2.4094188789407423e-04, 5.3126963343912430e-04, -1.1950090172702876e-02, -3.0672866587835314e-04, 1.6258847328107780e-02, 4.1732359150410756e-04, - 9.3870498815960286e-03, -2.0698163334150858e-02, 2.4094188789407990e-04, -5.3126963343912723e-04, -1.1950090172702843e-02, -3.0672866587835341e-04, - 1.6258847328107794e-02, 4.1732359150410756e-04, -9.3870498815960164e-03, -2.0698163334150893e-02, -2.4094188789407995e-04, -5.3126963343912517e-04, - 1.1950090172702823e-02, 3.0672866587835455e-04, -1.6258847328107638e-02, -4.1732359150411965e-04, -9.3870498815960199e-03, 2.0698163334150855e-02, - -2.4094188789408291e-04, 5.3126963343913568e-04, 1.1950090172702871e-02, 3.0672866587835650e-04, -1.6258847328107656e-02, -4.1732359150412036e-04, - 9.3870498815960095e-03, 2.0698163334150886e-02, 2.4094188789408158e-04, 5.3126963343913492e-04, -1.1950090172702854e-02, -3.0672866587835694e-04, - 1.6064983708873892e-02, -5.2925080425479339e-04, 9.2751226688452867e-03, -2.0451367188367861e-02, -3.0556309430532816e-04, 6.7375745464185800e-04, - -1.1807602351500069e-02, 3.8899404780599303e-04, 1.6064983708873822e-02, -5.2925080425478700e-04, -9.2751226688453266e-03, -2.0451367188367833e-02, - 3.0556309430533130e-04, 6.7375745464185615e-04, 1.1807602351500086e-02, -3.8899404780599412e-04, -1.6064983708874072e-02, 5.2925080425480684e-04, - -9.2751226688453318e-03, 2.0451367188368024e-02, 3.0556309430533526e-04, -6.7375745464186689e-04, 1.1807602351500116e-02, -3.8899404780599748e-04, - -1.6064983708873996e-02, 5.2925080425480402e-04, 9.2751226688453751e-03, 2.0451367188367989e-02, -3.0556309430533781e-04, -6.7375745464186602e-04, - -1.1807602351500135e-02, 3.8899404780599791e-04, 1.6064983708874003e-02, -5.2925080425480196e-04, 9.2751226688453387e-03, -2.0451367188367930e-02, - -3.0556309430533493e-04, 6.7375745464186396e-04, -1.1807602351500104e-02, 3.8899404780599742e-04, 1.6064983708874016e-02, -5.2925080425480337e-04, - -9.2751226688453300e-03, -2.0451367188367958e-02, 3.0556309430533374e-04, 6.7375745464186678e-04, 1.1807602351500088e-02, -3.8899404780599602e-04, - -1.6064983708873902e-02, 5.2925080425479133e-04, -9.2751226688453405e-03, 2.0451367188367951e-02, 3.0556309430533249e-04, -6.7375745464185865e-04, - 1.1807602351500142e-02, -3.8899404780599656e-04, -1.6064983708873923e-02, 5.2925080425479058e-04, 9.2751226688453266e-03, 2.0451367188367976e-02, - -3.0556309430533211e-04, -6.7375745464186027e-04, -1.1807602351500125e-02, 3.8899404780599553e-04, 1.3108851408420495e-02, -1.1774729751721242e-03, - 7.5683988894183754e-03, -1.6688092464312451e-02, -6.7981433917913405e-04, 1.4989702203260478e-03, -9.6348746765321652e-03, 8.6543086021247605e-04, - 1.3108851408420441e-02, -1.1774729751721192e-03, -7.5683988894184049e-03, -1.6688092464312427e-02, 6.7981433917913730e-04, 1.4989702203260455e-03, - 9.6348746765321774e-03, -8.6543086021247735e-04, -1.3108851408420628e-02, 1.1774729751721368e-03, -7.5683988894183997e-03, 1.6688092464312576e-02, - 6.7981433917913838e-04, -1.4989702203260585e-03, 9.6348746765321982e-03, -8.6543086021248039e-04, -1.3108851408420566e-02, 1.1774729751721311e-03, - 7.5683988894184361e-03, 1.6688092464312545e-02, -6.7981433917914142e-04, -1.4989702203260570e-03, -9.6348746765322138e-03, 8.6543086021248104e-04, - 1.3108851408420576e-02, -1.1774729751721318e-03, 7.5683988894184092e-03, -1.6688092464312500e-02, -6.7981433917913817e-04, 1.4989702203260522e-03, - -9.6348746765321843e-03, 8.6543086021247909e-04, 1.3108851408420587e-02, -1.1774729751721333e-03, -7.5683988894184040e-03, -1.6688092464312517e-02, - 6.7981433917913730e-04, 1.4989702203260546e-03, 9.6348746765321774e-03, -8.6543086021247779e-04, -1.3108851408420507e-02, 1.1774729751721248e-03, - -7.5683988894184135e-03, 1.6688092464312531e-02, 6.7981433917913882e-04, -1.4989702203260522e-03, 9.6348746765322225e-03, -8.6543086021248115e-04, - -1.3108851408420528e-02, 1.1774729751721261e-03, 7.5683988894184023e-03, 1.6688092464312552e-02, -6.7981433917913817e-04, -1.4989702203260537e-03, - -9.6348746765322086e-03, 8.6543086021248017e-04, 8.5642422695473425e-03, -1.4463583345179229e-03, 4.9445675797283326e-03, -1.0902623153480380e-02, - -8.3505537377857994e-04, 1.8412720436711647e-03, -6.2946324125349529e-03, 1.0630589100648789e-03, 8.5642422695473095e-03, -1.4463583345179173e-03, - -4.9445675797283508e-03, -1.0902623153480369e-02, 8.3505537377858319e-04, 1.8412720436711617e-03, 6.2946324125349607e-03, -1.0630589100648806e-03, - -8.5642422695474396e-03, 1.4463583345179336e-03, -4.9445675797283465e-03, 1.0902623153480473e-02, 8.3505537377858200e-04, -1.8412720436711751e-03, - 6.2946324125349737e-03, -1.0630589100648819e-03, -8.5642422695473945e-03, 1.4463583345179286e-03, 4.9445675797283725e-03, 1.0902623153480451e-02, - -8.3505537377858482e-04, -1.8412720436711725e-03, -6.2946324125349859e-03, 1.0630589100648832e-03, 8.5642422695474049e-03, -1.4463583345179279e-03, - 4.9445675797283543e-03, -1.0902623153480420e-02, -8.3505537377858363e-04, 1.8412720436711679e-03, -6.2946324125349659e-03, 1.0630589100648815e-03, - 8.5642422695474084e-03, -1.4463583345179294e-03, -4.9445675797283508e-03, -1.0902623153480428e-02, 8.3505537377858276e-04, 1.8412720436711697e-03, - 6.2946324125349616e-03, -1.0630589100648802e-03, -8.5642422695473546e-03, 1.4463583345179234e-03, -4.9445675797283560e-03, 1.0902623153480446e-02, - 8.3505537377858406e-04, -1.8412720436711708e-03, 6.2946324125349911e-03, -1.0630589100648848e-03, -8.5642422695473720e-03, 1.4463583345179244e-03, - 4.9445675797283465e-03, 1.0902623153480463e-02, -8.3505537377858352e-04, -1.8412720436711725e-03, -6.2946324125349815e-03, 1.0630589100648841e-03, - 3.8932555050064832e-03, -1.2504371313709222e-03, 2.2477721138394924e-03, -4.9562700674910002e-03, -7.2194021440170409e-04, 1.5918565112213662e-03, - -2.8615038576424224e-03, 9.1905878526491434e-04, 3.8932555050064706e-03, -1.2504371313709168e-03, -2.2477721138395002e-03, -4.9562700674909959e-03, - 7.2194021440170734e-04, 1.5918565112213634e-03, 2.8615038576424237e-03, -9.1905878526491597e-04, -3.8932555050065431e-03, 1.2504371313709329e-03, - -2.2477721138394993e-03, 4.9562700674910557e-03, 7.2194021440170637e-04, -1.5918565112213766e-03, 2.8615038576424324e-03, -9.1905878526491694e-04, - -3.8932555050065162e-03, 1.2504371313709277e-03, 2.2477721138395149e-03, 4.9562700674910419e-03, -7.2194021440170908e-04, -1.5918565112213743e-03, - -2.8615038576424411e-03, 9.1905878526491824e-04, 3.8932555050065266e-03, -1.2504371313709268e-03, 2.2477721138395011e-03, -4.9562700674910297e-03, - -7.2194021440170745e-04, 1.5918565112213688e-03, -2.8615038576424263e-03, 9.1905878526491640e-04, 3.8932555050065266e-03, -1.2504371313709283e-03, - -2.2477721138395011e-03, -4.9562700674910315e-03, 7.2194021440170680e-04, 1.5918565112213706e-03, 2.8615038576424263e-03, -9.1905878526491532e-04, - -3.8932555050064949e-03, 1.2504371313709220e-03, -2.2477721138395028e-03, 4.9562700674910410e-03, 7.2194021440170723e-04, -1.5918565112213730e-03, - 2.8615038576424424e-03, -9.1905878526491922e-04, -3.8932555050065088e-03, 1.2504371313709229e-03, 2.2477721138394937e-03, 4.9562700674910531e-03, - -7.2194021440170680e-04, -1.5918565112213738e-03, -2.8615038576424354e-03, 9.1905878526491857e-04, 8.6371743090067675e-04, -4.9866749123428583e-04, - 4.9866749123428833e-04, -1.0995468558481246e-03, -2.8790581030022907e-04, 6.3482367321052548e-04, -6.3482367321052939e-04, 3.6651561861604439e-04, - 8.6371743090068336e-04, -4.9866749123428031e-04, -4.9866749123428453e-04, -1.0995468558481305e-03, 2.8790581030023222e-04, 6.3482367321052299e-04, - 6.3482367321052603e-04, -3.6651561861604585e-04, -8.6371743090070082e-04, 4.9866749123429613e-04, -4.9866749123428887e-04, 1.0995468558481442e-03, - 2.8790581030023097e-04, -6.3482367321053622e-04, 6.3482367321053134e-04, -3.6651561861604666e-04, -8.6371743090069041e-04, 4.9866749123429136e-04, - 4.9866749123429473e-04, 1.0995468558481370e-03, -2.8790581030023368e-04, -6.3482367321053416e-04, -6.3482367321053546e-04, 3.6651561861604786e-04, - 8.6371743090070527e-04, -4.9866749123429028e-04, 4.9866749123428529e-04, -1.0995468558481448e-03, -2.8790581030023249e-04, 6.3482367321052863e-04, - -6.3482367321052613e-04, 3.6651561861604677e-04, 8.6371743090070006e-04, -4.9866749123429147e-04, -4.9866749123428833e-04, -1.0995468558481398e-03, - 2.8790581030023173e-04, 6.3482367321053036e-04, 6.3482367321052884e-04, -3.6651561861604590e-04, -8.6371743090068976e-04, 4.9866749123428540e-04, - -4.9866749123428844e-04, 1.0995468558481435e-03, 2.8790581030023178e-04, -6.3482367321053210e-04, 6.3482367321053361e-04, -3.6651561861604856e-04, - -8.6371743090070180e-04, 4.9866749123428594e-04, 4.9866749123428161e-04, 1.0995468558481518e-03, -2.8790581030023140e-04, -6.3482367321053329e-04, - -6.3482367321052884e-04, 3.6651561861604791e-04, + 5.0226946551362277e-03, 2.8998541112002828e-03, 2.8998541112001328e-03, + -6.3940913062055585e-03, 1.6742315517121347e-03, -3.6916303368608990e-03, + -3.6916303368608040e-03, -2.1313637687352333e-03, 5.0226946551361054e-03, + 2.8998541112002867e-03, -2.8998541112002039e-03, -6.3940913062055281e-03, + -1.6742315517121328e-03, -3.6916303368608964e-03, 3.6916303368608209e-03, + 2.1313637687352342e-03, -5.0226946551365859e-03, -2.8998541112002637e-03, + -2.8998541112003253e-03, 6.3940913062057849e-03, -1.6742315517121109e-03, + 3.6916303368608938e-03, 3.6916303368609415e-03, 2.1313637687352177e-03, + -5.0226946551364645e-03, -2.8998541112002676e-03, 2.8998541112003947e-03, + 6.3940913062057719e-03, 1.6742315517121085e-03, 3.6916303368608890e-03, + -3.6916303368609489e-03, -2.1313637687352207e-03, 5.0226946551364515e-03, + 2.8998541112002685e-03, 2.8998541112002637e-03, -6.3940913062056999e-03, + 1.6742315517121265e-03, -3.6916303368608890e-03, -3.6916303368609046e-03, + -2.1313637687352246e-03, 5.0226946551364463e-03, 2.8998541112002746e-03, + -2.8998541112002672e-03, -6.3940913062057441e-03, -1.6742315517121232e-03, + -3.6916303368608881e-03, 3.6916303368608790e-03, 2.1313637687352246e-03, + -5.0226946551362259e-03, -2.8998541112002832e-03, -2.8998541112002503e-03, + 6.3940913062056105e-03, -1.6742315517121248e-03, 3.6916303368609046e-03, + 3.6916303368609068e-03, 2.1313637687352290e-03, -5.0226946551362190e-03, + -2.8998541112002893e-03, 2.8998541112002538e-03, 6.3940913062056392e-03, + 1.6742315517121209e-03, 3.6916303368609068e-03, -3.6916303368608916e-03, + -2.1313637687352281e-03, 1.2790705487348994e-02, 1.5850090338456867e-03, + 7.3847172562461283e-03, -1.6283079974463467e-02, 9.1510539235880120e-04, + -2.0177799327709654e-03, -9.4010406064926836e-03, -1.1649657873507447e-03, + 1.2790705487348885e-02, 1.5850090338456915e-03, -7.3847172562461908e-03, + -1.6283079974463436e-02, -9.1510539235879838e-04, -2.0177799327709650e-03, + 9.4010406064927009e-03, 1.1649657873507447e-03, -1.2790705487349287e-02, + -1.5850090338456703e-03, -7.3847172562462498e-03, 1.6283079974463682e-02, + -9.1510539235878569e-04, 2.0177799327709607e-03, 9.4010406064927773e-03, + 1.1649657873507358e-03, -1.2790705487349180e-02, -1.5850090338456742e-03, + 7.3847172562463122e-03, 1.6283079974463655e-02, 9.1510539235878320e-04, + 2.0177799327709585e-03, -9.4010406064927911e-03, -1.1649657873507374e-03, + 1.2790705487349174e-02, 1.5850090338456761e-03, 7.3847172562462315e-03, + -1.6283079974463582e-02, 9.1510539235879448e-04, -2.0177799327709585e-03, + -9.4010406064927565e-03, -1.1649657873507384e-03, 1.2790705487349183e-02, + 1.5850090338456796e-03, -7.3847172562462263e-03, -1.6283079974463623e-02, + -9.1510539235879263e-04, -2.0177799327709572e-03, 9.4010406064927322e-03, + 1.1649657873507393e-03, -1.2790705487348996e-02, -1.5850090338456880e-03, + -7.3847172562462159e-03, 1.6283079974463543e-02, -9.1510539235879599e-04, + 2.0177799327709711e-03, 9.4010406064927738e-03, 1.1649657873507428e-03, + -1.2790705487349006e-02, -1.5850090338456926e-03, 7.3847172562462116e-03, + 1.6283079974463575e-02, 9.1510539235879350e-04, 2.0177799327709715e-03, + -9.4010406064927547e-03, -1.1649657873507419e-03, 1.6258847328107631e-02, + 4.1732359150411819e-04, 9.3870498815959488e-03, -2.0698163334150768e-02, + 2.4094188789408792e-04, -5.3126963343913351e-04, -1.1950090172702790e-02, + -3.0672866587835884e-04, 1.6258847328107544e-02, 4.1732359150412318e-04, + -9.3870498815960008e-03, -2.0698163334150737e-02, -2.4094188789408486e-04, + -5.3126963343913417e-04, 1.1950090172702807e-02, 3.0672866587835884e-04, + -1.6258847328107867e-02, -4.1732359150410052e-04, -9.3870498815960286e-03, + 2.0698163334150962e-02, -2.4094188789407700e-04, 5.3126963343912647e-04, + 1.1950090172702856e-02, 3.0672866587835233e-04, -1.6258847328107773e-02, + -4.1732359150410545e-04, 9.3870498815960806e-03, 2.0698163334150928e-02, + 2.4094188789407423e-04, 5.3126963343912430e-04, -1.1950090172702876e-02, + -3.0672866587835314e-04, 1.6258847328107780e-02, 4.1732359150410756e-04, + 9.3870498815960286e-03, -2.0698163334150858e-02, 2.4094188789407990e-04, + -5.3126963343912723e-04, -1.1950090172702843e-02, -3.0672866587835341e-04, + 1.6258847328107794e-02, 4.1732359150410756e-04, -9.3870498815960164e-03, + -2.0698163334150893e-02, -2.4094188789407995e-04, -5.3126963343912517e-04, + 1.1950090172702823e-02, 3.0672866587835455e-04, -1.6258847328107638e-02, + -4.1732359150411965e-04, -9.3870498815960199e-03, 2.0698163334150855e-02, + -2.4094188789408291e-04, 5.3126963343913568e-04, 1.1950090172702871e-02, + 3.0672866587835650e-04, -1.6258847328107656e-02, -4.1732359150412036e-04, + 9.3870498815960095e-03, 2.0698163334150886e-02, 2.4094188789408158e-04, + 5.3126963343913492e-04, -1.1950090172702854e-02, -3.0672866587835694e-04, + 1.6064983708873892e-02, -5.2925080425479339e-04, 9.2751226688452867e-03, + -2.0451367188367861e-02, -3.0556309430532816e-04, 6.7375745464185800e-04, + -1.1807602351500069e-02, 3.8899404780599303e-04, 1.6064983708873822e-02, + -5.2925080425478700e-04, -9.2751226688453266e-03, -2.0451367188367833e-02, + 3.0556309430533130e-04, 6.7375745464185615e-04, 1.1807602351500086e-02, + -3.8899404780599412e-04, -1.6064983708874072e-02, 5.2925080425480684e-04, + -9.2751226688453318e-03, 2.0451367188368024e-02, 3.0556309430533526e-04, + -6.7375745464186689e-04, 1.1807602351500116e-02, -3.8899404780599748e-04, + -1.6064983708873996e-02, 5.2925080425480402e-04, 9.2751226688453751e-03, + 2.0451367188367989e-02, -3.0556309430533781e-04, -6.7375745464186602e-04, + -1.1807602351500135e-02, 3.8899404780599791e-04, 1.6064983708874003e-02, + -5.2925080425480196e-04, 9.2751226688453387e-03, -2.0451367188367930e-02, + -3.0556309430533493e-04, 6.7375745464186396e-04, -1.1807602351500104e-02, + 3.8899404780599742e-04, 1.6064983708874016e-02, -5.2925080425480337e-04, + -9.2751226688453300e-03, -2.0451367188367958e-02, 3.0556309430533374e-04, + 6.7375745464186678e-04, 1.1807602351500088e-02, -3.8899404780599602e-04, + -1.6064983708873902e-02, 5.2925080425479133e-04, -9.2751226688453405e-03, + 2.0451367188367951e-02, 3.0556309430533249e-04, -6.7375745464185865e-04, + 1.1807602351500142e-02, -3.8899404780599656e-04, -1.6064983708873923e-02, + 5.2925080425479058e-04, 9.2751226688453266e-03, 2.0451367188367976e-02, + -3.0556309430533211e-04, -6.7375745464186027e-04, -1.1807602351500125e-02, + 3.8899404780599553e-04, 1.3108851408420495e-02, -1.1774729751721242e-03, + 7.5683988894183754e-03, -1.6688092464312451e-02, -6.7981433917913405e-04, + 1.4989702203260478e-03, -9.6348746765321652e-03, 8.6543086021247605e-04, + 1.3108851408420441e-02, -1.1774729751721192e-03, -7.5683988894184049e-03, + -1.6688092464312427e-02, 6.7981433917913730e-04, 1.4989702203260455e-03, + 9.6348746765321774e-03, -8.6543086021247735e-04, -1.3108851408420628e-02, + 1.1774729751721368e-03, -7.5683988894183997e-03, 1.6688092464312576e-02, + 6.7981433917913838e-04, -1.4989702203260585e-03, 9.6348746765321982e-03, + -8.6543086021248039e-04, -1.3108851408420566e-02, 1.1774729751721311e-03, + 7.5683988894184361e-03, 1.6688092464312545e-02, -6.7981433917914142e-04, + -1.4989702203260570e-03, -9.6348746765322138e-03, 8.6543086021248104e-04, + 1.3108851408420576e-02, -1.1774729751721318e-03, 7.5683988894184092e-03, + -1.6688092464312500e-02, -6.7981433917913817e-04, 1.4989702203260522e-03, + -9.6348746765321843e-03, 8.6543086021247909e-04, 1.3108851408420587e-02, + -1.1774729751721333e-03, -7.5683988894184040e-03, -1.6688092464312517e-02, + 6.7981433917913730e-04, 1.4989702203260546e-03, 9.6348746765321774e-03, + -8.6543086021247779e-04, -1.3108851408420507e-02, 1.1774729751721248e-03, + -7.5683988894184135e-03, 1.6688092464312531e-02, 6.7981433917913882e-04, + -1.4989702203260522e-03, 9.6348746765322225e-03, -8.6543086021248115e-04, + -1.3108851408420528e-02, 1.1774729751721261e-03, 7.5683988894184023e-03, + 1.6688092464312552e-02, -6.7981433917913817e-04, -1.4989702203260537e-03, + -9.6348746765322086e-03, 8.6543086021248017e-04, 8.5642422695473425e-03, + -1.4463583345179229e-03, 4.9445675797283326e-03, -1.0902623153480380e-02, + -8.3505537377857994e-04, 1.8412720436711647e-03, -6.2946324125349529e-03, + 1.0630589100648789e-03, 8.5642422695473095e-03, -1.4463583345179173e-03, + -4.9445675797283508e-03, -1.0902623153480369e-02, 8.3505537377858319e-04, + 1.8412720436711617e-03, 6.2946324125349607e-03, -1.0630589100648806e-03, + -8.5642422695474396e-03, 1.4463583345179336e-03, -4.9445675797283465e-03, + 1.0902623153480473e-02, 8.3505537377858200e-04, -1.8412720436711751e-03, + 6.2946324125349737e-03, -1.0630589100648819e-03, -8.5642422695473945e-03, + 1.4463583345179286e-03, 4.9445675797283725e-03, 1.0902623153480451e-02, + -8.3505537377858482e-04, -1.8412720436711725e-03, -6.2946324125349859e-03, + 1.0630589100648832e-03, 8.5642422695474049e-03, -1.4463583345179279e-03, + 4.9445675797283543e-03, -1.0902623153480420e-02, -8.3505537377858363e-04, + 1.8412720436711679e-03, -6.2946324125349659e-03, 1.0630589100648815e-03, + 8.5642422695474084e-03, -1.4463583345179294e-03, -4.9445675797283508e-03, + -1.0902623153480428e-02, 8.3505537377858276e-04, 1.8412720436711697e-03, + 6.2946324125349616e-03, -1.0630589100648802e-03, -8.5642422695473546e-03, + 1.4463583345179234e-03, -4.9445675797283560e-03, 1.0902623153480446e-02, + 8.3505537377858406e-04, -1.8412720436711708e-03, 6.2946324125349911e-03, + -1.0630589100648848e-03, -8.5642422695473720e-03, 1.4463583345179244e-03, + 4.9445675797283465e-03, 1.0902623153480463e-02, -8.3505537377858352e-04, + -1.8412720436711725e-03, -6.2946324125349815e-03, 1.0630589100648841e-03, + 3.8932555050064832e-03, -1.2504371313709222e-03, 2.2477721138394924e-03, + -4.9562700674910002e-03, -7.2194021440170409e-04, 1.5918565112213662e-03, + -2.8615038576424224e-03, 9.1905878526491434e-04, 3.8932555050064706e-03, + -1.2504371313709168e-03, -2.2477721138395002e-03, -4.9562700674909959e-03, + 7.2194021440170734e-04, 1.5918565112213634e-03, 2.8615038576424237e-03, + -9.1905878526491597e-04, -3.8932555050065431e-03, 1.2504371313709329e-03, + -2.2477721138394993e-03, 4.9562700674910557e-03, 7.2194021440170637e-04, + -1.5918565112213766e-03, 2.8615038576424324e-03, -9.1905878526491694e-04, + -3.8932555050065162e-03, 1.2504371313709277e-03, 2.2477721138395149e-03, + 4.9562700674910419e-03, -7.2194021440170908e-04, -1.5918565112213743e-03, + -2.8615038576424411e-03, 9.1905878526491824e-04, 3.8932555050065266e-03, + -1.2504371313709268e-03, 2.2477721138395011e-03, -4.9562700674910297e-03, + -7.2194021440170745e-04, 1.5918565112213688e-03, -2.8615038576424263e-03, + 9.1905878526491640e-04, 3.8932555050065266e-03, -1.2504371313709283e-03, + -2.2477721138395011e-03, -4.9562700674910315e-03, 7.2194021440170680e-04, + 1.5918565112213706e-03, 2.8615038576424263e-03, -9.1905878526491532e-04, + -3.8932555050064949e-03, 1.2504371313709220e-03, -2.2477721138395028e-03, + 4.9562700674910410e-03, 7.2194021440170723e-04, -1.5918565112213730e-03, + 2.8615038576424424e-03, -9.1905878526491922e-04, -3.8932555050065088e-03, + 1.2504371313709229e-03, 2.2477721138394937e-03, 4.9562700674910531e-03, + -7.2194021440170680e-04, -1.5918565112213738e-03, -2.8615038576424354e-03, + 9.1905878526491857e-04, 8.6371743090067675e-04, -4.9866749123428583e-04, + 4.9866749123428833e-04, -1.0995468558481246e-03, -2.8790581030022907e-04, + 6.3482367321052548e-04, -6.3482367321052939e-04, 3.6651561861604439e-04, + 8.6371743090068336e-04, -4.9866749123428031e-04, -4.9866749123428453e-04, + -1.0995468558481305e-03, 2.8790581030023222e-04, 6.3482367321052299e-04, + 6.3482367321052603e-04, -3.6651561861604585e-04, -8.6371743090070082e-04, + 4.9866749123429613e-04, -4.9866749123428887e-04, 1.0995468558481442e-03, + 2.8790581030023097e-04, -6.3482367321053622e-04, 6.3482367321053134e-04, + -3.6651561861604666e-04, -8.6371743090069041e-04, 4.9866749123429136e-04, + 4.9866749123429473e-04, 1.0995468558481370e-03, -2.8790581030023368e-04, + -6.3482367321053416e-04, -6.3482367321053546e-04, 3.6651561861604786e-04, + 8.6371743090070527e-04, -4.9866749123429028e-04, 4.9866749123428529e-04, + -1.0995468558481448e-03, -2.8790581030023249e-04, 6.3482367321052863e-04, + -6.3482367321052613e-04, 3.6651561861604677e-04, 8.6371743090070006e-04, + -4.9866749123429147e-04, -4.9866749123428833e-04, -1.0995468558481398e-03, + 2.8790581030023173e-04, 6.3482367321053036e-04, 6.3482367321052884e-04, + -3.6651561861604590e-04, -8.6371743090068976e-04, 4.9866749123428540e-04, + -4.9866749123428844e-04, 1.0995468558481435e-03, 2.8790581030023178e-04, + -6.3482367321053210e-04, 6.3482367321053361e-04, -3.6651561861604856e-04, + -8.6371743090070180e-04, 4.9866749123428594e-04, 4.9866749123428161e-04, + 1.0995468558481518e-03, -2.8790581030023140e-04, -6.3482367321053329e-04, + -6.3482367321052884e-04, 3.6651561861604791e-04 }; return sol; } -static const double * -get_sol_3x_bias_p1_PxPx_DyDy(void) +static const double *get_sol_3x_bias_p1_PxPx_DyDy(void) { static const double sol[512] = { - 5.0226946551374047e-03, 2.8998541112002477e-03, 2.8998541112002247e-03, -6.3940913062064493e-03, 1.6742315517121274e-03, -3.6916303368605963e-03, - -3.6916303368608513e-03, -2.1313637687352671e-03, 1.2790705487349972e-02, 7.3847172562462203e-03, 1.5850090338456310e-03, -1.6283079974464206e-02, - 9.1510539235879567e-04, -9.4010406064925674e-03, -2.0177799327709238e-03, -1.1649657873507653e-03, 1.6258847328108415e-02, 9.3870498815960199e-03, - 4.1732359150406154e-04, -2.0698163334151354e-02, 2.4094188789408060e-04, -1.1950090172702729e-02, -5.3126963343909015e-04, -3.0672866587836957e-04, - 1.6064983708874485e-02, 9.2751226688453300e-03, -5.2925080425484793e-04, -2.0451367188368302e-02, -3.0556309430533428e-04, -1.1807602351500038e-02, - 6.7375745464189811e-04, 3.8899404780598740e-04, 1.3108851408420902e-02, 7.5683988894183979e-03, -1.1774729751721765e-03, -1.6688092464312750e-02, - -6.7981433917913892e-04, -9.6348746765321513e-03, 1.4989702203260884e-03, 8.6543086021247096e-04, 8.5642422695475732e-03, 4.9445675797283361e-03, - -1.4463583345179739e-03, -1.0902623153480544e-02, -8.3505537377858644e-04, -6.2946324125349503e-03, 1.8412720436712046e-03, 1.0630589100648776e-03, - 3.8932555050065370e-03, 2.2477721138394720e-03, -1.2504371313709736e-03, -4.9562700674910228e-03, -7.2194021440171125e-04, -2.8615038576424259e-03, - 1.5918565112214074e-03, 9.1905878526491250e-04, 8.6371743090054871e-04, 4.9866749123423770e-04, -4.9866749123433972e-04, -1.0995468558480034e-03, - -2.8790581030023926e-04, -6.3482367321054012e-04, 6.3482367321056777e-04, 3.6651561861604206e-04, 5.0226946551373657e-03, -2.8998541112002702e-03, - 2.8998541112002286e-03, -6.3940913062062463e-03, -1.6742315517121252e-03, 3.6916303368607138e-03, -3.6916303368608734e-03, 2.1313637687352550e-03, - 1.2790705487349948e-02, -7.3847172562462315e-03, 1.5850090338456367e-03, -1.6283079974464067e-02, -9.1510539235879220e-04, 9.4010406064926489e-03, - -2.0177799327709398e-03, 1.1649657873507560e-03, 1.6258847328108415e-02, -9.3870498815960199e-03, 4.1732359150406864e-04, -2.0698163334151271e-02, - -2.4094188789407586e-04, 1.1950090172702777e-02, -5.3126963343910468e-04, 3.0672866587836117e-04, 1.6064983708874509e-02, -9.2751226688453179e-03, - -5.2925080425484088e-04, -2.0451367188368264e-02, 3.0556309430533862e-04, 1.1807602351500059e-02, 6.7375745464188727e-04, -3.8899404780599363e-04, - 1.3108851408420951e-02, -7.5683988894183702e-03, -1.1774729751721673e-03, -1.6688092464312750e-02, 6.7981433917914467e-04, 9.6348746765321531e-03, - 1.4989702203260782e-03, -8.6543086021247681e-04, 8.5642422695476547e-03, -4.9445675797282892e-03, -1.4463583345179648e-03, -1.0902623153480574e-02, - 8.3505537377859176e-04, 6.2946324125349338e-03, 1.8412720436711953e-03, -1.0630589100648830e-03, 3.8932555050066524e-03, -2.2477721138394052e-03, - -1.2504371313709630e-03, -4.9562700674910896e-03, 7.2194021440171732e-04, 2.8615038576423877e-03, 1.5918565112213962e-03, -9.1905878526491900e-04, - 8.6371743090070375e-04, -4.9866749123414814e-04, -4.9866749123432703e-04, -1.0995468558481086e-03, 2.8790581030024653e-04, 6.3482367321047940e-04, - 6.3482367321055606e-04, -3.6651561861604878e-04, -5.0226946551355815e-03, -2.8998541112004064e-03, -2.8998541112002945e-03, 6.3940913062051005e-03, - -1.6742315517121022e-03, 3.6916303368610673e-03, 3.6916303368609120e-03, 2.1313637687351951e-03, -1.2790705487348395e-02, -7.3847172562463070e-03, - -1.5850090338457032e-03, 1.6283079974463061e-02, -9.1510539235877886e-04, 9.4010406064928363e-03, 2.0177799327709784e-03, 1.1649657873507200e-03, - -1.6258847328107093e-02, -9.3870498815960667e-03, -4.1732359150413803e-04, 2.0698163334150407e-02, -2.4094188789407412e-04, 1.1950090172702878e-02, - 5.3126963343915065e-04, 3.0672866587834696e-04, -1.6064983708873427e-02, -9.2751226688453613e-03, 5.2925080425477149e-04, 2.0451367188367559e-02, - 3.0556309430533705e-04, 1.1807602351500126e-02, -6.7375745464184141e-04, -3.8899404780600122e-04, -1.3108851408420103e-02, -7.5683988894184265e-03, - 1.1774729751721036e-03, 1.6688092464312205e-02, 6.7981433917913914e-04, 9.6348746765321912e-03, -1.4989702203260322e-03, -8.6543086021248473e-04, - -8.5642422695470250e-03, -4.9445675797283699e-03, 1.4463583345179017e-03, 1.0902623153480194e-02, 8.3505537377858319e-04, 6.2946324125349572e-03, - -1.8412720436711478e-03, -1.0630589100648835e-03, -3.8932555050062343e-03, -2.2477721138395206e-03, 1.2504371313709038e-03, 4.9562700674908649e-03, - 7.2194021440170626e-04, 2.8615038576424111e-03, -1.5918565112213521e-03, -9.1905878526491868e-04, -8.6371743090048723e-04, -4.9866749123431348e-04, - 4.9866749123427011e-04, 1.0995468558480334e-03, 2.8790581030022875e-04, 6.3482367321050141e-04, -6.3482367321051421e-04, -3.6651561861605013e-04, - -5.0226946551355824e-03, 2.8998541112004064e-03, -2.8998541112002976e-03, 6.3940913062052853e-03, 1.6742315517121005e-03, -3.6916303368609619e-03, - 3.6916303368608946e-03, -2.1313637687352047e-03, -1.2790705487348402e-02, 7.3847172562463009e-03, -1.5850090338457047e-03, 1.6283079974463197e-02, - 9.1510539235877832e-04, -9.4010406064927565e-03, 2.0177799327709676e-03, -1.1649657873507263e-03, -1.6258847328107107e-02, 9.3870498815960580e-03, - -4.1732359150413803e-04, 2.0698163334150515e-02, 2.4094188789407342e-04, -1.1950090172702817e-02, 5.3126963343914230e-04, -3.0672866587835125e-04, - -1.6064983708873441e-02, 9.2751226688453526e-03, 5.2925080425477008e-04, 2.0451367188367642e-02, -3.0556309430533781e-04, -1.1807602351500076e-02, - -6.7375745464184553e-04, 3.8899404780599835e-04, -1.3108851408420125e-02, 7.5683988894184127e-03, 1.1774729751720999e-03, 1.6688092464312271e-02, - -6.7981433917914098e-04, -9.6348746765321531e-03, -1.4989702203260372e-03, 8.6543086021248158e-04, -8.5642422695470614e-03, 4.9445675797283499e-03, - 1.4463583345178976e-03, 1.0902623153480243e-02, -8.3505537377858601e-04, -6.2946324125349286e-03, -1.8412720436711528e-03, 1.0630589100648804e-03, - -3.8932555050062894e-03, 2.2477721138394889e-03, 1.2504371313708973e-03, 4.9562700674909014e-03, -7.2194021440171005e-04, -2.8615038576423912e-03, - -1.5918565112213552e-03, 9.1905878526491705e-04, -8.6371743090057050e-04, 4.9866749123426534e-04, 4.9866749123426046e-04, 1.0995468558480613e-03, - -2.8790581030023438e-04, -6.3482367321048537e-04, -6.3482367321051594e-04, 3.6651561861604910e-04, 5.0226946551371540e-03, 2.8998541112001484e-03, - 2.8998541112002308e-03, -6.3940913062060711e-03, 1.6742315517121297e-03, -3.6916303368608261e-03, -3.6916303368608634e-03, -2.1313637687352298e-03, - 1.2790705487349752e-02, 7.3847172562461301e-03, 1.5850090338456432e-03, -1.6283079974463873e-02, 9.1510539235879914e-04, -9.4010406064926923e-03, - -2.0177799327709372e-03, -1.1649657873507423e-03, 1.6258847328108252e-02, 9.3870498815959418e-03, 4.1732359150407997e-04, -2.0698163334151087e-02, - 2.4094188789408404e-04, -1.1950090172702791e-02, -5.3126963343911292e-04, -3.0672866587835694e-04, 1.6064983708874391e-02, 9.2751226688452693e-03, - -5.2925080425482386e-04, -2.0451367188368114e-02, -3.0556309430532870e-04, -1.1807602351500069e-02, 6.7375745464187588e-04, 3.8899404780599265e-04, - 1.3108851408420885e-02, 7.5683988894183589e-03, -1.1774729751721552e-03, -1.6688092464312639e-02, -6.7981433917913383e-04, -9.6348746765321687e-03, - 1.4989702203260650e-03, 8.6543086021247508e-04, 8.5642422695476304e-03, 4.9445675797283161e-03, -1.4463583345179526e-03, -1.0902623153480515e-02, - -8.3505537377857994e-04, -6.2946324125349555e-03, 1.8412720436711812e-03, 1.0630589100648806e-03, 3.8932555050066667e-03, 2.2477721138394777e-03, - -1.2504371313709515e-03, -4.9562700674910783e-03, -7.2194021440170301e-04, -2.8615038576424228e-03, 1.5918565112213816e-03, 9.1905878526491402e-04, - 8.6371743090075666e-04, 4.9866749123427510e-04, -4.9866749123431652e-04, -1.0995468558481457e-03, -2.8790581030022923e-04, -6.3482367321053286e-04, - 6.3482367321054283e-04, 3.6651561861604319e-04, 5.0226946551366995e-03, -2.8998541112004112e-03, 2.8998541112002733e-03, -6.3940913062058456e-03, - -1.6742315517121052e-03, 3.6916303368609562e-03, -3.6916303368608825e-03, 2.1313637687352185e-03, 1.2790705487349422e-02, -7.3847172562463209e-03, - 1.5850090338456729e-03, -1.6283079974463713e-02, -9.1510539235878201e-04, 9.4010406064927877e-03, -2.0177799327709533e-03, 1.1649657873507328e-03, - 1.6258847328108013e-02, -9.3870498815960806e-03, 4.1732359150410263e-04, -2.0698163334150969e-02, -2.4094188789407177e-04, 1.1950090172702859e-02, - -5.3126963343912354e-04, 3.0672866587835081e-04, 1.6064983708874218e-02, -9.2751226688453682e-03, -5.2925080425480825e-04, -2.0451367188368035e-02, - 3.0556309430533862e-04, 1.1807602351500116e-02, 6.7375745464186602e-04, -3.8899404780599835e-04, 1.3108851408420767e-02, -7.5683988894184265e-03, - -1.1774729751721411e-03, -1.6688092464312590e-02, 6.7981433917914185e-04, 9.6348746765321965e-03, 1.4989702203260583e-03, -8.6543086021247898e-04, - 8.5642422695475610e-03, -4.9445675797283551e-03, -1.4463583345179385e-03, -1.0902623153480489e-02, 8.3505537377858807e-04, 6.2946324125349711e-03, - 1.8412720436711760e-03, -1.0630589100648837e-03, 3.8932555050066476e-03, -2.2477721138394889e-03, -1.2504371313709372e-03, -4.9562700674910679e-03, - 7.2194021440171125e-04, 2.8615038576424285e-03, 1.5918565112213771e-03, -9.1905878526491651e-04, 8.6371743090078821e-04, -4.9866749123425689e-04, - -4.9866749123430134e-04, -1.0995468558481546e-03, 2.8790581030023796e-04, 6.3482367321052776e-04, 6.3482367321053687e-04, -3.6651561861604666e-04, - -5.0226946551359909e-03, -2.8998541112001167e-03, -2.8998541112002759e-03, 6.3940913062055568e-03, -1.6742315517121373e-03, 3.6916303368608578e-03, - 3.6916303368608851e-03, 2.1313637687352211e-03, -1.2790705487348746e-02, -7.3847172562461188e-03, -1.5850090338456876e-03, 1.6283079974463436e-02, - -9.1510539235880228e-04, 9.4010406064927061e-03, 2.0177799327709607e-03, 1.1649657873507406e-03, -1.6258847328107395e-02, -9.3870498815959453e-03, - -4.1732359150412247e-04, 2.0698163334150727e-02, -2.4094188789409087e-04, 1.1950090172702807e-02, 5.3126963343913221e-04, 3.0672866587835851e-04, - -1.6064983708873673e-02, -9.2751226688452884e-03, 5.2925080425478559e-04, 2.0451367188367823e-02, 3.0556309430532767e-04, 1.1807602351500090e-02, - -6.7375745464185247e-04, -3.8899404780598913e-04, -1.3108851408420302e-02, -7.5683988894183780e-03, 1.1774729751721164e-03, 1.6688092464312423e-02, - 6.7981433917913426e-04, 9.6348746765321878e-03, -1.4989702203260481e-03, -8.6543086021247952e-04, -8.5642422695471846e-03, -4.9445675797283413e-03, - 1.4463583345179110e-03, 1.0902623153480366e-02, 8.3505537377857669e-04, 6.2946324125349694e-03, -1.8412720436711595e-03, -1.0630589100648785e-03, - -3.8932555050063661e-03, -2.2477721138395106e-03, 1.2504371313709108e-03, 4.9562700674909976e-03, 7.2194021440170138e-04, 2.8615038576424359e-03, - -1.5918565112213645e-03, -9.1905878526491716e-04, -8.6371743090059934e-04, -4.9866749123431847e-04, 4.9866749123427478e-04, 1.0995468558481266e-03, - 2.8790581030022511e-04, 6.3482367321053329e-04, -6.3482367321052462e-04, -3.6651561861604710e-04, -5.0226946551354965e-03, 2.8998541112004025e-03, - -2.8998541112003192e-03, 6.3940913062049453e-03, 1.6742315517121124e-03, -3.6916303368612121e-03, 3.6916303368609424e-03, -2.1313637687351882e-03, - -1.2790705487348383e-02, 7.3847172562463270e-03, -1.5850090338457210e-03, 1.6283079974462999e-02, 9.1510539235878320e-04, -9.4010406064929612e-03, - 2.0177799327710032e-03, -1.1649657873507161e-03, -1.6258847328107139e-02, 9.3870498815960927e-03, -4.1732359150415077e-04, 2.0698163334150421e-02, - 2.4094188789407423e-04, -1.1950090172702984e-02, 5.3126963343916604e-04, -3.0672866587833851e-04, -1.6064983708873506e-02, 9.2751226688453838e-03, - 5.2925080425476434e-04, 2.0451367188367625e-02, -3.0556309430534030e-04, -1.1807602351500206e-02, -6.7375745464182590e-04, 3.8899404780600453e-04, - -1.3108851408420209e-02, 7.5683988894184318e-03, 1.1774729751720971e-03, 1.6688092464312309e-02, -6.7981433917914597e-04, -9.6348746765322554e-03, - -1.4989702203260255e-03, 8.6543086021249242e-04, -8.5642422695471621e-03, 4.9445675797283543e-03, 1.4463583345178917e-03, 1.0902623153480321e-02, - -8.3505537377858807e-04, -6.2946324125349954e-03, -1.8412720436711400e-03, 1.0630589100648895e-03, -3.8932555050064065e-03, 2.2477721138394872e-03, - 1.2504371313708923e-03, 4.9562700674910176e-03, -7.2194021440171179e-04, -2.8615038576424237e-03, -1.5918565112213459e-03, 9.1905878526492789e-04, - -8.6371743090070266e-04, 4.9866749123425895e-04, 4.9866749123425667e-04, 1.0995468558482129e-03, -2.8790581030023547e-04, -6.3482367321048342e-04, - -6.3482367321050521e-04, 3.6651561861605837e-04, + 5.0226946551374047e-03, 2.8998541112002477e-03, 2.8998541112002247e-03, + -6.3940913062064493e-03, 1.6742315517121274e-03, -3.6916303368605963e-03, + -3.6916303368608513e-03, -2.1313637687352671e-03, 1.2790705487349972e-02, + 7.3847172562462203e-03, 1.5850090338456310e-03, -1.6283079974464206e-02, + 9.1510539235879567e-04, -9.4010406064925674e-03, -2.0177799327709238e-03, + -1.1649657873507653e-03, 1.6258847328108415e-02, 9.3870498815960199e-03, + 4.1732359150406154e-04, -2.0698163334151354e-02, 2.4094188789408060e-04, + -1.1950090172702729e-02, -5.3126963343909015e-04, -3.0672866587836957e-04, + 1.6064983708874485e-02, 9.2751226688453300e-03, -5.2925080425484793e-04, + -2.0451367188368302e-02, -3.0556309430533428e-04, -1.1807602351500038e-02, + 6.7375745464189811e-04, 3.8899404780598740e-04, 1.3108851408420902e-02, + 7.5683988894183979e-03, -1.1774729751721765e-03, -1.6688092464312750e-02, + -6.7981433917913892e-04, -9.6348746765321513e-03, 1.4989702203260884e-03, + 8.6543086021247096e-04, 8.5642422695475732e-03, 4.9445675797283361e-03, + -1.4463583345179739e-03, -1.0902623153480544e-02, -8.3505537377858644e-04, + -6.2946324125349503e-03, 1.8412720436712046e-03, 1.0630589100648776e-03, + 3.8932555050065370e-03, 2.2477721138394720e-03, -1.2504371313709736e-03, + -4.9562700674910228e-03, -7.2194021440171125e-04, -2.8615038576424259e-03, + 1.5918565112214074e-03, 9.1905878526491250e-04, 8.6371743090054871e-04, + 4.9866749123423770e-04, -4.9866749123433972e-04, -1.0995468558480034e-03, + -2.8790581030023926e-04, -6.3482367321054012e-04, 6.3482367321056777e-04, + 3.6651561861604206e-04, 5.0226946551373657e-03, -2.8998541112002702e-03, + 2.8998541112002286e-03, -6.3940913062062463e-03, -1.6742315517121252e-03, + 3.6916303368607138e-03, -3.6916303368608734e-03, 2.1313637687352550e-03, + 1.2790705487349948e-02, -7.3847172562462315e-03, 1.5850090338456367e-03, + -1.6283079974464067e-02, -9.1510539235879220e-04, 9.4010406064926489e-03, + -2.0177799327709398e-03, 1.1649657873507560e-03, 1.6258847328108415e-02, + -9.3870498815960199e-03, 4.1732359150406864e-04, -2.0698163334151271e-02, + -2.4094188789407586e-04, 1.1950090172702777e-02, -5.3126963343910468e-04, + 3.0672866587836117e-04, 1.6064983708874509e-02, -9.2751226688453179e-03, + -5.2925080425484088e-04, -2.0451367188368264e-02, 3.0556309430533862e-04, + 1.1807602351500059e-02, 6.7375745464188727e-04, -3.8899404780599363e-04, + 1.3108851408420951e-02, -7.5683988894183702e-03, -1.1774729751721673e-03, + -1.6688092464312750e-02, 6.7981433917914467e-04, 9.6348746765321531e-03, + 1.4989702203260782e-03, -8.6543086021247681e-04, 8.5642422695476547e-03, + -4.9445675797282892e-03, -1.4463583345179648e-03, -1.0902623153480574e-02, + 8.3505537377859176e-04, 6.2946324125349338e-03, 1.8412720436711953e-03, + -1.0630589100648830e-03, 3.8932555050066524e-03, -2.2477721138394052e-03, + -1.2504371313709630e-03, -4.9562700674910896e-03, 7.2194021440171732e-04, + 2.8615038576423877e-03, 1.5918565112213962e-03, -9.1905878526491900e-04, + 8.6371743090070375e-04, -4.9866749123414814e-04, -4.9866749123432703e-04, + -1.0995468558481086e-03, 2.8790581030024653e-04, 6.3482367321047940e-04, + 6.3482367321055606e-04, -3.6651561861604878e-04, -5.0226946551355815e-03, + -2.8998541112004064e-03, -2.8998541112002945e-03, 6.3940913062051005e-03, + -1.6742315517121022e-03, 3.6916303368610673e-03, 3.6916303368609120e-03, + 2.1313637687351951e-03, -1.2790705487348395e-02, -7.3847172562463070e-03, + -1.5850090338457032e-03, 1.6283079974463061e-02, -9.1510539235877886e-04, + 9.4010406064928363e-03, 2.0177799327709784e-03, 1.1649657873507200e-03, + -1.6258847328107093e-02, -9.3870498815960667e-03, -4.1732359150413803e-04, + 2.0698163334150407e-02, -2.4094188789407412e-04, 1.1950090172702878e-02, + 5.3126963343915065e-04, 3.0672866587834696e-04, -1.6064983708873427e-02, + -9.2751226688453613e-03, 5.2925080425477149e-04, 2.0451367188367559e-02, + 3.0556309430533705e-04, 1.1807602351500126e-02, -6.7375745464184141e-04, + -3.8899404780600122e-04, -1.3108851408420103e-02, -7.5683988894184265e-03, + 1.1774729751721036e-03, 1.6688092464312205e-02, 6.7981433917913914e-04, + 9.6348746765321912e-03, -1.4989702203260322e-03, -8.6543086021248473e-04, + -8.5642422695470250e-03, -4.9445675797283699e-03, 1.4463583345179017e-03, + 1.0902623153480194e-02, 8.3505537377858319e-04, 6.2946324125349572e-03, + -1.8412720436711478e-03, -1.0630589100648835e-03, -3.8932555050062343e-03, + -2.2477721138395206e-03, 1.2504371313709038e-03, 4.9562700674908649e-03, + 7.2194021440170626e-04, 2.8615038576424111e-03, -1.5918565112213521e-03, + -9.1905878526491868e-04, -8.6371743090048723e-04, -4.9866749123431348e-04, + 4.9866749123427011e-04, 1.0995468558480334e-03, 2.8790581030022875e-04, + 6.3482367321050141e-04, -6.3482367321051421e-04, -3.6651561861605013e-04, + -5.0226946551355824e-03, 2.8998541112004064e-03, -2.8998541112002976e-03, + 6.3940913062052853e-03, 1.6742315517121005e-03, -3.6916303368609619e-03, + 3.6916303368608946e-03, -2.1313637687352047e-03, -1.2790705487348402e-02, + 7.3847172562463009e-03, -1.5850090338457047e-03, 1.6283079974463197e-02, + 9.1510539235877832e-04, -9.4010406064927565e-03, 2.0177799327709676e-03, + -1.1649657873507263e-03, -1.6258847328107107e-02, 9.3870498815960580e-03, + -4.1732359150413803e-04, 2.0698163334150515e-02, 2.4094188789407342e-04, + -1.1950090172702817e-02, 5.3126963343914230e-04, -3.0672866587835125e-04, + -1.6064983708873441e-02, 9.2751226688453526e-03, 5.2925080425477008e-04, + 2.0451367188367642e-02, -3.0556309430533781e-04, -1.1807602351500076e-02, + -6.7375745464184553e-04, 3.8899404780599835e-04, -1.3108851408420125e-02, + 7.5683988894184127e-03, 1.1774729751720999e-03, 1.6688092464312271e-02, + -6.7981433917914098e-04, -9.6348746765321531e-03, -1.4989702203260372e-03, + 8.6543086021248158e-04, -8.5642422695470614e-03, 4.9445675797283499e-03, + 1.4463583345178976e-03, 1.0902623153480243e-02, -8.3505537377858601e-04, + -6.2946324125349286e-03, -1.8412720436711528e-03, 1.0630589100648804e-03, + -3.8932555050062894e-03, 2.2477721138394889e-03, 1.2504371313708973e-03, + 4.9562700674909014e-03, -7.2194021440171005e-04, -2.8615038576423912e-03, + -1.5918565112213552e-03, 9.1905878526491705e-04, -8.6371743090057050e-04, + 4.9866749123426534e-04, 4.9866749123426046e-04, 1.0995468558480613e-03, + -2.8790581030023438e-04, -6.3482367321048537e-04, -6.3482367321051594e-04, + 3.6651561861604910e-04, 5.0226946551371540e-03, 2.8998541112001484e-03, + 2.8998541112002308e-03, -6.3940913062060711e-03, 1.6742315517121297e-03, + -3.6916303368608261e-03, -3.6916303368608634e-03, -2.1313637687352298e-03, + 1.2790705487349752e-02, 7.3847172562461301e-03, 1.5850090338456432e-03, + -1.6283079974463873e-02, 9.1510539235879914e-04, -9.4010406064926923e-03, + -2.0177799327709372e-03, -1.1649657873507423e-03, 1.6258847328108252e-02, + 9.3870498815959418e-03, 4.1732359150407997e-04, -2.0698163334151087e-02, + 2.4094188789408404e-04, -1.1950090172702791e-02, -5.3126963343911292e-04, + -3.0672866587835694e-04, 1.6064983708874391e-02, 9.2751226688452693e-03, + -5.2925080425482386e-04, -2.0451367188368114e-02, -3.0556309430532870e-04, + -1.1807602351500069e-02, 6.7375745464187588e-04, 3.8899404780599265e-04, + 1.3108851408420885e-02, 7.5683988894183589e-03, -1.1774729751721552e-03, + -1.6688092464312639e-02, -6.7981433917913383e-04, -9.6348746765321687e-03, + 1.4989702203260650e-03, 8.6543086021247508e-04, 8.5642422695476304e-03, + 4.9445675797283161e-03, -1.4463583345179526e-03, -1.0902623153480515e-02, + -8.3505537377857994e-04, -6.2946324125349555e-03, 1.8412720436711812e-03, + 1.0630589100648806e-03, 3.8932555050066667e-03, 2.2477721138394777e-03, + -1.2504371313709515e-03, -4.9562700674910783e-03, -7.2194021440170301e-04, + -2.8615038576424228e-03, 1.5918565112213816e-03, 9.1905878526491402e-04, + 8.6371743090075666e-04, 4.9866749123427510e-04, -4.9866749123431652e-04, + -1.0995468558481457e-03, -2.8790581030022923e-04, -6.3482367321053286e-04, + 6.3482367321054283e-04, 3.6651561861604319e-04, 5.0226946551366995e-03, + -2.8998541112004112e-03, 2.8998541112002733e-03, -6.3940913062058456e-03, + -1.6742315517121052e-03, 3.6916303368609562e-03, -3.6916303368608825e-03, + 2.1313637687352185e-03, 1.2790705487349422e-02, -7.3847172562463209e-03, + 1.5850090338456729e-03, -1.6283079974463713e-02, -9.1510539235878201e-04, + 9.4010406064927877e-03, -2.0177799327709533e-03, 1.1649657873507328e-03, + 1.6258847328108013e-02, -9.3870498815960806e-03, 4.1732359150410263e-04, + -2.0698163334150969e-02, -2.4094188789407177e-04, 1.1950090172702859e-02, + -5.3126963343912354e-04, 3.0672866587835081e-04, 1.6064983708874218e-02, + -9.2751226688453682e-03, -5.2925080425480825e-04, -2.0451367188368035e-02, + 3.0556309430533862e-04, 1.1807602351500116e-02, 6.7375745464186602e-04, + -3.8899404780599835e-04, 1.3108851408420767e-02, -7.5683988894184265e-03, + -1.1774729751721411e-03, -1.6688092464312590e-02, 6.7981433917914185e-04, + 9.6348746765321965e-03, 1.4989702203260583e-03, -8.6543086021247898e-04, + 8.5642422695475610e-03, -4.9445675797283551e-03, -1.4463583345179385e-03, + -1.0902623153480489e-02, 8.3505537377858807e-04, 6.2946324125349711e-03, + 1.8412720436711760e-03, -1.0630589100648837e-03, 3.8932555050066476e-03, + -2.2477721138394889e-03, -1.2504371313709372e-03, -4.9562700674910679e-03, + 7.2194021440171125e-04, 2.8615038576424285e-03, 1.5918565112213771e-03, + -9.1905878526491651e-04, 8.6371743090078821e-04, -4.9866749123425689e-04, + -4.9866749123430134e-04, -1.0995468558481546e-03, 2.8790581030023796e-04, + 6.3482367321052776e-04, 6.3482367321053687e-04, -3.6651561861604666e-04, + -5.0226946551359909e-03, -2.8998541112001167e-03, -2.8998541112002759e-03, + 6.3940913062055568e-03, -1.6742315517121373e-03, 3.6916303368608578e-03, + 3.6916303368608851e-03, 2.1313637687352211e-03, -1.2790705487348746e-02, + -7.3847172562461188e-03, -1.5850090338456876e-03, 1.6283079974463436e-02, + -9.1510539235880228e-04, 9.4010406064927061e-03, 2.0177799327709607e-03, + 1.1649657873507406e-03, -1.6258847328107395e-02, -9.3870498815959453e-03, + -4.1732359150412247e-04, 2.0698163334150727e-02, -2.4094188789409087e-04, + 1.1950090172702807e-02, 5.3126963343913221e-04, 3.0672866587835851e-04, + -1.6064983708873673e-02, -9.2751226688452884e-03, 5.2925080425478559e-04, + 2.0451367188367823e-02, 3.0556309430532767e-04, 1.1807602351500090e-02, + -6.7375745464185247e-04, -3.8899404780598913e-04, -1.3108851408420302e-02, + -7.5683988894183780e-03, 1.1774729751721164e-03, 1.6688092464312423e-02, + 6.7981433917913426e-04, 9.6348746765321878e-03, -1.4989702203260481e-03, + -8.6543086021247952e-04, -8.5642422695471846e-03, -4.9445675797283413e-03, + 1.4463583345179110e-03, 1.0902623153480366e-02, 8.3505537377857669e-04, + 6.2946324125349694e-03, -1.8412720436711595e-03, -1.0630589100648785e-03, + -3.8932555050063661e-03, -2.2477721138395106e-03, 1.2504371313709108e-03, + 4.9562700674909976e-03, 7.2194021440170138e-04, 2.8615038576424359e-03, + -1.5918565112213645e-03, -9.1905878526491716e-04, -8.6371743090059934e-04, + -4.9866749123431847e-04, 4.9866749123427478e-04, 1.0995468558481266e-03, + 2.8790581030022511e-04, 6.3482367321053329e-04, -6.3482367321052462e-04, + -3.6651561861604710e-04, -5.0226946551354965e-03, 2.8998541112004025e-03, + -2.8998541112003192e-03, 6.3940913062049453e-03, 1.6742315517121124e-03, + -3.6916303368612121e-03, 3.6916303368609424e-03, -2.1313637687351882e-03, + -1.2790705487348383e-02, 7.3847172562463270e-03, -1.5850090338457210e-03, + 1.6283079974462999e-02, 9.1510539235878320e-04, -9.4010406064929612e-03, + 2.0177799327710032e-03, -1.1649657873507161e-03, -1.6258847328107139e-02, + 9.3870498815960927e-03, -4.1732359150415077e-04, 2.0698163334150421e-02, + 2.4094188789407423e-04, -1.1950090172702984e-02, 5.3126963343916604e-04, + -3.0672866587833851e-04, -1.6064983708873506e-02, 9.2751226688453838e-03, + 5.2925080425476434e-04, 2.0451367188367625e-02, -3.0556309430534030e-04, + -1.1807602351500206e-02, -6.7375745464182590e-04, 3.8899404780600453e-04, + -1.3108851408420209e-02, 7.5683988894184318e-03, 1.1774729751720971e-03, + 1.6688092464312309e-02, -6.7981433917914597e-04, -9.6348746765322554e-03, + -1.4989702203260255e-03, 8.6543086021249242e-04, -8.5642422695471621e-03, + 4.9445675797283543e-03, 1.4463583345178917e-03, 1.0902623153480321e-02, + -8.3505537377858807e-04, -6.2946324125349954e-03, -1.8412720436711400e-03, + 1.0630589100648895e-03, -3.8932555050064065e-03, 2.2477721138394872e-03, + 1.2504371313708923e-03, 4.9562700674910176e-03, -7.2194021440171179e-04, + -2.8615038576424237e-03, -1.5918565112213459e-03, 9.1905878526492789e-04, + -8.6371743090070266e-04, 4.9866749123425895e-04, 4.9866749123425667e-04, + 1.0995468558482129e-03, -2.8790581030023547e-04, -6.3482367321048342e-04, + -6.3482367321050521e-04, 3.6651561861605837e-04 }; return sol; } -static const double * -get_sol_3x_bias_p1_DxDx_NyDy(void) +static const double *get_sol_3x_bias_p1_DxDx_NyDy(void) { static const double sol[512] = { - -6.9079330390629801e-04, -3.9882969996476189e-04, 1.9369084511113992e-05, 8.7940752169275444e-04, 1.1182746156426905e-05, 5.0772616937670115e-04, - -2.4657619741027554e-05, -1.4236083395042380e-05, -5.6185672699465936e-04, -3.2438813257638433e-04, 5.5072482877209447e-05, 7.1526609919163396e-04, - 3.1796112814150550e-05, 4.1295907491048809e-04, -7.0109474725162422e-05, -4.0477724105344443e-05, -3.2502275688893505e-04, -1.8765197618263087e-04, - 8.1663673516578359e-05, 4.1376697705834621e-04, 4.7148543887737761e-05, 2.3888847558643323e-04, -1.0396112459892713e-04, -6.0021983272398073e-05, - -2.2431527513896648e-05, -1.2950848448637168e-05, 9.3037454217519903e-05, 2.8556232243850333e-05, 5.3715199237214681e-05, 1.6486948373111031e-05, - -1.1844040261445826e-04, -6.8381598332397376e-05, 2.8251817425953193e-04, 1.6311194395994056e-04, 8.3025338190665209e-05, -3.5965694232108491e-04, - 4.7934701354154866e-05, -2.0764803246514594e-04, -1.0569457822356623e-04, -6.1022793189381905e-05, 5.0481002617883098e-04, 2.9145220450425613e-04, - 4.5314922353602512e-05, -6.4264336602178908e-04, 2.6162582618972440e-05, -3.7103032036580117e-04, -5.7687709677044810e-05, -3.3306014710878311e-05, - 5.3693018033440596e-04, 3.0999678415207708e-04, -2.6770342705469010e-05, -6.8353360772284585e-04, -1.5455864567294547e-05, -3.9463831241894835e-04, - 3.4079717623710872e-05, 1.9675934143967217e-05, 2.4528129331624464e-04, 1.4161322072328672e-04, -1.4161322072332120e-04, -3.1225290264544673e-04, - -8.1760431105425965e-05, -1.8027929739759170e-04, 1.8027929739763954e-04, 1.0408430088183608e-04, -1.7637269696838631e-03, -2.2062884079452740e-04, - 4.9468484637507319e-05, 2.2452950174551758e-03, 6.1951506089924524e-06, 2.8086934398447670e-04, -6.2975360691777362e-05, -7.8866746576113936e-06, - -1.4344421799159486e-03, -1.7939931355867353e-04, 1.4064417737504758e-04, 1.8261023019737138e-03, 1.7608728039188745e-05, 2.2838250579132761e-04, - -1.7904566643377488e-04, -2.2416615502115621e-05, -8.2967964857643035e-04, -1.0371181608154435e-04, 2.0851563288962292e-04, 1.0562153967439481e-03, - 2.6089469003520896e-05, 1.3202929245949860e-04, -2.6544874554619840e-04, -3.3212938152301273e-05, -5.7211901773873569e-05, -7.1296099928764446e-06, - 2.3746882866713706e-04, 7.2833040600970948e-05, 2.9672293680699401e-05, 9.0762788507300187e-06, -3.0230732248927766e-04, -3.7774017352396973e-05, - 7.2082558778282157e-04, 8.9944959225539376e-05, 2.1173132536804161e-04, -9.1763982097132471e-04, 2.6373734989019922e-05, -1.1450353272677223e-04, - -2.6954245076450602e-04, -3.3574820128277174e-05, 1.2870709745399684e-03, 1.6018636460857875e-04, 1.1519060110358107e-04, -1.6384928596764488e-03, - 1.4180159317135439e-05, -2.0392365286806921e-04, -1.4664224517805719e-04, -1.8051910306269282e-05, 1.3669669930979470e-03, 1.6922519313425260e-04, - -6.9062613281952698e-05, -1.7402036887708442e-03, -8.9615892346788474e-06, -2.1543044331873715e-04, 8.7919470620908099e-05, 1.1408461742067528e-05, - 6.2367351899503742e-04, 7.6851632631626000e-05, -3.6007807407825444e-04, -7.9396134934042945e-04, -4.4370310787516813e-05, -9.7835203972673063e-05, - 4.5839379876786319e-04, 5.6485181349801060e-05, -2.2508116665430275e-03, -6.0589640055258542e-05, 6.3151521941853120e-05, 2.8653733298781617e-03, - 1.7047546620032634e-06, 7.7133036611583063e-05, -8.0394414780745167e-05, -2.1702209096828419e-06, -1.8304802004777839e-03, -4.9253344222028937e-05, - 1.7952696313978540e-04, 2.3302745517463802e-03, 4.8402587889251854e-06, 6.2701478332860363e-05, -2.2854500881667886e-04, -6.1618431473634482e-06, - -1.0586408004009461e-03, -2.8478966558306632e-05, 2.6609472226573651e-04, 1.3476921061319536e-03, 7.1538337474718335e-06, 3.6254864168172705e-05, - -3.3874923065981108e-04, -9.1071166597731378e-06, -7.3130563309161035e-05, -2.0610335296603170e-06, 3.0288987840833758e-04, 9.3098133806493509e-05, - 8.0985669980506337e-06, 2.6237781666312881e-06, -3.8559093698597503e-04, -1.0309799896356255e-05, 9.1873938193641036e-04, 2.4320623105375322e-05, - 2.6976650148029252e-04, -1.1695920015167591e-03, 7.1328895618554546e-06, -3.0961126534047540e-05, -3.4342355254598974e-04, -9.0804538732886023e-06, - 1.6392548325407505e-03, 4.3147080612413811e-05, 1.4622328788140799e-04, -2.0868370054480294e-03, 3.7365707477203179e-06, -5.4927960382745753e-05, - -1.8614809738656867e-04, -4.7568041008803349e-06, 1.7385437019493174e-03, 4.5304719745681212e-05, -8.8898832400838445e-05, -2.2132357097847683e-03, - -2.4908572133142122e-06, -5.7674721348964573e-05, 1.1317177141253271e-04, 3.1709609176343877e-06, 7.9228320374875242e-04, 2.0495214248909324e-05, - -4.5742492095876726e-04, -1.0086082258578600e-03, -1.1832917463708485e-05, -2.6091227965377788e-05, 5.8232023070588939e-04, 1.5063777489328235e-05, - -2.2340461539592346e-03, 7.0269213258613311e-05, 6.2692883129639407e-05, 2.8440301613965667e-03, -1.9695499036957175e-06, -8.9455520679791617e-05, - -7.9810549217891458e-05, 2.5073158495669902e-06, -1.8168031392969803e-03, 5.7149799176488832e-05, 1.7820248370310410e-04, 2.3128631055018322e-03, - -5.6049473482291679e-06, -7.2753981509130874e-05, -2.2685889348759451e-04, 7.1353222864950245e-06, -1.0507771170938870e-03, 3.3019066232459204e-05, - 2.6406284642211032e-04, 1.3376813225743581e-03, -8.3269378127493067e-06, -4.2034592749949409e-05, -3.3616257139440161e-04, 1.0600525082959169e-05, - -7.3041740691808134e-05, 2.1123152916991204e-06, 3.0043293633984995e-04, 9.2985059059888983e-05, -9.5170831626752805e-06, -2.6890619020219609e-06, - -3.8246315140499850e-04, 1.2115627743500475e-05, 9.1036543165672220e-04, -2.9155325553533829e-05, 2.6733745933858288e-04, -1.1589316276819181e-03, - -8.5352976962444854e-06, 3.7115896237255145e-05, -3.4033128468836796e-04, 1.0865775553292953e-05, 1.6238014988128172e-03, -5.2069067000113288e-05, - 1.4456504608357674e-04, -2.0671642931638563e-03, -4.6939570960796462e-06, 6.6286006115703452e-05, -1.8403708921444040e-04, 5.9755952373201247e-06, - 1.7210227955432630e-03, -5.5420419775662968e-05, -8.8434304245289404e-05, -2.1909308947362749e-03, 2.7590526689666105e-06, 7.0552412321437028e-05, - 1.1258040847991929e-04, -3.5123844659675123e-06, 7.8392504372920872e-04, -2.5320800186122937e-05, -4.5259933502154824e-04, -9.9796795365608205e-04, - 1.4618970803559581e-05, 3.2234391985325116e-05, 5.7617706668597769e-04, -1.8610534889900269e-05, -1.8339090424506843e-03, 1.6075005578360761e-04, - 5.1471540987780427e-05, 2.3346396048014714e-03, -4.5090950025754530e-06, -2.0464125429304014e-04, -6.5525331588775609e-05, 5.7402583940354572e-06, - -1.4913852692680597e-03, 1.3073029568382339e-04, 1.4628465166305414e-04, 1.8985931336037614e-03, -1.2822821572042931e-05, -1.6642489828339903e-04, - -1.8622621593640859e-04, 1.6323965035577423e-05, -8.6268379122426020e-04, 7.5576666091141834e-05, 2.1669631592544916e-04, 1.0982309911733820e-03, - -1.9020141320076695e-05, -9.6212120541949218e-05, -2.7586308244495619e-04, 2.4213401094000003e-05, -6.0575372069967455e-05, 5.0851459879377340e-06, - 2.4640119579254699e-04, 7.7114872895307326e-05, -2.1678156787094102e-05, -6.4735943521887308e-06, -3.1367858331675602e-04, 2.7597161158338475e-05, - 7.4559480183159898e-04, -6.5975041930545276e-05, 2.1904137112216987e-04, -9.4917202172906947e-04, -1.9348461836307453e-05, 8.3988868724731795e-05, - -2.7884843156041284e-04, 2.4631366250678167e-05, 1.3297080252287668e-03, -1.1772587914055043e-04, 1.1819655564340515e-04, -1.6927715315547805e-03, - -1.0529897957677521e-05, 1.4986975558194376e-04, -1.5046894560673518e-04, 1.3404981510784434e-05, 1.4085793923499623e-03, -1.2496886316451210e-04, - -7.2660150604629122e-05, -1.7931779383632163e-03, 6.3481591817070706e-06, 1.5909036411151771e-04, 9.2499279607521743e-05, -8.0814606941427644e-06, - 6.4136415990857299e-04, -5.6986764463632038e-05, -3.7029177037178836e-04, -8.1648224320973327e-04, 3.2901323803321743e-05, 7.2546431794944845e-05, - 4.7139624290569047e-04, -4.1884701925559310e-05, -1.2100112667458897e-03, 1.9945749296636440e-04, 3.3972790274495772e-05, 1.5403927676947034e-03, - -5.5938134322215696e-06, -2.5391737091356098e-04, -4.3248721623872660e-05, 7.1211483658335299e-06, -9.8397636034453450e-04, 1.6222237447238830e-04, - 9.6528523782578516e-05, 1.2526412858398512e-03, -1.5903892253583135e-05, -2.0651557490663052e-04, -1.2288467388474000e-04, 2.0246291318839486e-05, - -5.6925297375807257e-04, 9.3835695361493563e-05, 1.4291213510234853e-04, 7.2468181732210975e-04, -2.3579175340076496e-05, -1.1945659553664517e-04, - -1.8193286738518963e-04, 3.0017233855795637e-05, -4.0541836830676359e-05, 6.4812209752868387e-06, 1.6233938212623677e-04, 5.1611380785723758e-05, - -2.6854953961718241e-05, -8.2508536825548366e-06, -2.0666453033267172e-04, 3.4187431139095443e-05, 4.9013450248755377e-04, -8.1515030663001578e-05, - 1.4404674523170864e-04, -6.2396083704236598e-04, -2.3949705609325615e-05, 1.0377189629761350e-04, -1.8337727148740832e-04, 3.0488933717316898e-05, - 8.7363231171246156e-04, -1.4558955682893914e-04, 7.7365818157923587e-05, -1.1121688959189492e-03, -1.3043739320776170e-05, 1.8534133239460972e-04, - -9.8489782725531659e-05, 1.6605202170929833e-05, 9.2429031121327328e-04, -1.5463556819535182e-04, -4.8118408509521975e-05, -1.1766585566365616e-03, - 7.8210222232853527e-06, 1.9685726688898814e-04, 6.1256659750270513e-05, -9.9564742906303526e-06, 4.2047339144771385e-04, -7.0544580168748378e-05, - -2.4276042573941192e-04, -5.3527945482356677e-04, 4.0728932350295730e-05, 8.9806073776681691e-05, 3.0904373733406230e-04, -5.1849560869830381e-05, - -5.6182935935282811e-04, 1.7477050575086486e-04, 1.5794234573042703e-05, 7.1523125908826493e-04, -4.9015805954909655e-06, -2.2248984820528401e-04, - -2.0106692702968120e-05, 6.2399082612448420e-06, -4.5678597105276730e-04, 1.4215113869939708e-04, 4.4852593938587782e-05, 5.8150682190454017e-04, - -1.3931219752469142e-05, -1.8096408850885645e-04, -5.7099147102286593e-05, 1.7735000277791322e-05, -2.6422489214980252e-04, 8.2272349665436255e-05, - 6.6322596801483795e-05, 3.3636886209089138e-04, -2.0639815215036942e-05, -1.0473599369591789e-04, -8.4431319984719147e-05, 2.6275310782271061e-05, - -1.9172276725498251e-05, 5.8565003039016137e-06, 7.5158596679360178e-05, 2.4407075553624133e-05, -2.3478895984198962e-05, -7.4555592663146275e-06, - -9.5679901449448646e-05, 2.9889574222544112e-05, 2.2595287291712833e-04, -7.1010304284437612e-05, 6.6364474451957597e-05, -2.8764704994641428e-04, - -2.0900174336625055e-05, 9.0398959214416647e-05, -8.4484631909731762e-05, 2.6606758363727290e-05, 4.0170043536066267e-04, -1.2688043902193714e-04, - 3.5103428034237590e-05, -5.1138073042365968e-04, -1.1356462993730947e-05, 1.6152387668003697e-04, -4.4688068740591611e-05, 1.4457231881138533e-05, - 4.2273028355949746e-04, -1.3494024878531186e-04, -2.2961839515623369e-05, -5.3815256880357897e-04, 6.7031296572293737e-06, 1.7178433706557214e-04, - 2.9231340645244033e-05, -8.5333523155403361e-06, 1.9147960544159756e-04, -6.1665043824634419e-05, -1.1055080174602965e-04, -2.4376120081633150e-04, - 3.5602329651742721e-05, 7.8502068648085319e-05, 1.4073559490929551e-04, -4.5323190465914605e-05, -1.2955898186390926e-04, 7.4800913055063687e-05, - 3.6522239721318641e-06, 1.6493376891421171e-04, -2.1086124934482099e-06, -9.5224555881080988e-05, -4.6494272799621577e-06, 2.6843480916631399e-06, - -1.0528648823581542e-04, 6.0787182324984421e-05, 1.0361506757951604e-05, 1.3403391313090328e-04, -5.9822187159139861e-06, -7.7384515826667597e-05, - -1.3190612774451585e-05, 7.6156038361061387e-06, -6.0862501235595707e-05, 3.5138981471927000e-05, 1.5286694095101679e-05, 7.7480399814173790e-05, - -8.8257769508283041e-06, -4.4733329689633267e-05, -1.9460573362581266e-05, 1.1235567269471202e-05, -4.5142603222996201e-06, 2.6063094122710723e-06, - 1.7245977964551712e-05, 5.7468340527632004e-06, -9.9569700202718593e-06, -3.3179361873508551e-06, -2.1954820139700859e-05, 1.2675621317665824e-05, - 5.1479709017778204e-05, -2.9721823859217862e-05, 1.5082155306937880e-05, -6.5535729817849114e-05, -8.7076864264203733e-06, 3.7837071251873586e-05, - -1.9200187299523851e-05, 1.1085233305871462e-05, 9.0968534244011416e-05, -5.2520707733565707e-05, 7.7167285674099497e-06, -1.1580658468917291e-04, - -4.4552553156573706e-06, 6.6860962844225174e-05, -9.8237042928275584e-06, 5.6717183179032468e-06, 9.4503458338676474e-05, -5.4561597111185429e-05, - -5.6758391897901815e-06, -1.2030668453073529e-04, 3.2769472841023753e-06, 6.9459096699131382e-05, 7.2255704379213280e-06, -4.1716850373824735e-06, - 4.2336308243184655e-05, -2.4442878960697636e-05, -2.4442878960697636e-05, -5.3895814709293923e-05, 1.4112102747728219e-05, 3.1116763130605032e-05, - 3.1116763130605032e-05, -1.7965271569764636e-05, + -6.9079330390629801e-04, -3.9882969996476189e-04, 1.9369084511113992e-05, + 8.7940752169275444e-04, 1.1182746156426905e-05, 5.0772616937670115e-04, + -2.4657619741027554e-05, -1.4236083395042380e-05, -5.6185672699465936e-04, + -3.2438813257638433e-04, 5.5072482877209447e-05, 7.1526609919163396e-04, + 3.1796112814150550e-05, 4.1295907491048809e-04, -7.0109474725162422e-05, + -4.0477724105344443e-05, -3.2502275688893505e-04, -1.8765197618263087e-04, + 8.1663673516578359e-05, 4.1376697705834621e-04, 4.7148543887737761e-05, + 2.3888847558643323e-04, -1.0396112459892713e-04, -6.0021983272398073e-05, + -2.2431527513896648e-05, -1.2950848448637168e-05, 9.3037454217519903e-05, + 2.8556232243850333e-05, 5.3715199237214681e-05, 1.6486948373111031e-05, + -1.1844040261445826e-04, -6.8381598332397376e-05, 2.8251817425953193e-04, + 1.6311194395994056e-04, 8.3025338190665209e-05, -3.5965694232108491e-04, + 4.7934701354154866e-05, -2.0764803246514594e-04, -1.0569457822356623e-04, + -6.1022793189381905e-05, 5.0481002617883098e-04, 2.9145220450425613e-04, + 4.5314922353602512e-05, -6.4264336602178908e-04, 2.6162582618972440e-05, + -3.7103032036580117e-04, -5.7687709677044810e-05, -3.3306014710878311e-05, + 5.3693018033440596e-04, 3.0999678415207708e-04, -2.6770342705469010e-05, + -6.8353360772284585e-04, -1.5455864567294547e-05, -3.9463831241894835e-04, + 3.4079717623710872e-05, 1.9675934143967217e-05, 2.4528129331624464e-04, + 1.4161322072328672e-04, -1.4161322072332120e-04, -3.1225290264544673e-04, + -8.1760431105425965e-05, -1.8027929739759170e-04, 1.8027929739763954e-04, + 1.0408430088183608e-04, -1.7637269696838631e-03, -2.2062884079452740e-04, + 4.9468484637507319e-05, 2.2452950174551758e-03, 6.1951506089924524e-06, + 2.8086934398447670e-04, -6.2975360691777362e-05, -7.8866746576113936e-06, + -1.4344421799159486e-03, -1.7939931355867353e-04, 1.4064417737504758e-04, + 1.8261023019737138e-03, 1.7608728039188745e-05, 2.2838250579132761e-04, + -1.7904566643377488e-04, -2.2416615502115621e-05, -8.2967964857643035e-04, + -1.0371181608154435e-04, 2.0851563288962292e-04, 1.0562153967439481e-03, + 2.6089469003520896e-05, 1.3202929245949860e-04, -2.6544874554619840e-04, + -3.3212938152301273e-05, -5.7211901773873569e-05, -7.1296099928764446e-06, + 2.3746882866713706e-04, 7.2833040600970948e-05, 2.9672293680699401e-05, + 9.0762788507300187e-06, -3.0230732248927766e-04, -3.7774017352396973e-05, + 7.2082558778282157e-04, 8.9944959225539376e-05, 2.1173132536804161e-04, + -9.1763982097132471e-04, 2.6373734989019922e-05, -1.1450353272677223e-04, + -2.6954245076450602e-04, -3.3574820128277174e-05, 1.2870709745399684e-03, + 1.6018636460857875e-04, 1.1519060110358107e-04, -1.6384928596764488e-03, + 1.4180159317135439e-05, -2.0392365286806921e-04, -1.4664224517805719e-04, + -1.8051910306269282e-05, 1.3669669930979470e-03, 1.6922519313425260e-04, + -6.9062613281952698e-05, -1.7402036887708442e-03, -8.9615892346788474e-06, + -2.1543044331873715e-04, 8.7919470620908099e-05, 1.1408461742067528e-05, + 6.2367351899503742e-04, 7.6851632631626000e-05, -3.6007807407825444e-04, + -7.9396134934042945e-04, -4.4370310787516813e-05, -9.7835203972673063e-05, + 4.5839379876786319e-04, 5.6485181349801060e-05, -2.2508116665430275e-03, + -6.0589640055258542e-05, 6.3151521941853120e-05, 2.8653733298781617e-03, + 1.7047546620032634e-06, 7.7133036611583063e-05, -8.0394414780745167e-05, + -2.1702209096828419e-06, -1.8304802004777839e-03, -4.9253344222028937e-05, + 1.7952696313978540e-04, 2.3302745517463802e-03, 4.8402587889251854e-06, + 6.2701478332860363e-05, -2.2854500881667886e-04, -6.1618431473634482e-06, + -1.0586408004009461e-03, -2.8478966558306632e-05, 2.6609472226573651e-04, + 1.3476921061319536e-03, 7.1538337474718335e-06, 3.6254864168172705e-05, + -3.3874923065981108e-04, -9.1071166597731378e-06, -7.3130563309161035e-05, + -2.0610335296603170e-06, 3.0288987840833758e-04, 9.3098133806493509e-05, + 8.0985669980506337e-06, 2.6237781666312881e-06, -3.8559093698597503e-04, + -1.0309799896356255e-05, 9.1873938193641036e-04, 2.4320623105375322e-05, + 2.6976650148029252e-04, -1.1695920015167591e-03, 7.1328895618554546e-06, + -3.0961126534047540e-05, -3.4342355254598974e-04, -9.0804538732886023e-06, + 1.6392548325407505e-03, 4.3147080612413811e-05, 1.4622328788140799e-04, + -2.0868370054480294e-03, 3.7365707477203179e-06, -5.4927960382745753e-05, + -1.8614809738656867e-04, -4.7568041008803349e-06, 1.7385437019493174e-03, + 4.5304719745681212e-05, -8.8898832400838445e-05, -2.2132357097847683e-03, + -2.4908572133142122e-06, -5.7674721348964573e-05, 1.1317177141253271e-04, + 3.1709609176343877e-06, 7.9228320374875242e-04, 2.0495214248909324e-05, + -4.5742492095876726e-04, -1.0086082258578600e-03, -1.1832917463708485e-05, + -2.6091227965377788e-05, 5.8232023070588939e-04, 1.5063777489328235e-05, + -2.2340461539592346e-03, 7.0269213258613311e-05, 6.2692883129639407e-05, + 2.8440301613965667e-03, -1.9695499036957175e-06, -8.9455520679791617e-05, + -7.9810549217891458e-05, 2.5073158495669902e-06, -1.8168031392969803e-03, + 5.7149799176488832e-05, 1.7820248370310410e-04, 2.3128631055018322e-03, + -5.6049473482291679e-06, -7.2753981509130874e-05, -2.2685889348759451e-04, + 7.1353222864950245e-06, -1.0507771170938870e-03, 3.3019066232459204e-05, + 2.6406284642211032e-04, 1.3376813225743581e-03, -8.3269378127493067e-06, + -4.2034592749949409e-05, -3.3616257139440161e-04, 1.0600525082959169e-05, + -7.3041740691808134e-05, 2.1123152916991204e-06, 3.0043293633984995e-04, + 9.2985059059888983e-05, -9.5170831626752805e-06, -2.6890619020219609e-06, + -3.8246315140499850e-04, 1.2115627743500475e-05, 9.1036543165672220e-04, + -2.9155325553533829e-05, 2.6733745933858288e-04, -1.1589316276819181e-03, + -8.5352976962444854e-06, 3.7115896237255145e-05, -3.4033128468836796e-04, + 1.0865775553292953e-05, 1.6238014988128172e-03, -5.2069067000113288e-05, + 1.4456504608357674e-04, -2.0671642931638563e-03, -4.6939570960796462e-06, + 6.6286006115703452e-05, -1.8403708921444040e-04, 5.9755952373201247e-06, + 1.7210227955432630e-03, -5.5420419775662968e-05, -8.8434304245289404e-05, + -2.1909308947362749e-03, 2.7590526689666105e-06, 7.0552412321437028e-05, + 1.1258040847991929e-04, -3.5123844659675123e-06, 7.8392504372920872e-04, + -2.5320800186122937e-05, -4.5259933502154824e-04, -9.9796795365608205e-04, + 1.4618970803559581e-05, 3.2234391985325116e-05, 5.7617706668597769e-04, + -1.8610534889900269e-05, -1.8339090424506843e-03, 1.6075005578360761e-04, + 5.1471540987780427e-05, 2.3346396048014714e-03, -4.5090950025754530e-06, + -2.0464125429304014e-04, -6.5525331588775609e-05, 5.7402583940354572e-06, + -1.4913852692680597e-03, 1.3073029568382339e-04, 1.4628465166305414e-04, + 1.8985931336037614e-03, -1.2822821572042931e-05, -1.6642489828339903e-04, + -1.8622621593640859e-04, 1.6323965035577423e-05, -8.6268379122426020e-04, + 7.5576666091141834e-05, 2.1669631592544916e-04, 1.0982309911733820e-03, + -1.9020141320076695e-05, -9.6212120541949218e-05, -2.7586308244495619e-04, + 2.4213401094000003e-05, -6.0575372069967455e-05, 5.0851459879377340e-06, + 2.4640119579254699e-04, 7.7114872895307326e-05, -2.1678156787094102e-05, + -6.4735943521887308e-06, -3.1367858331675602e-04, 2.7597161158338475e-05, + 7.4559480183159898e-04, -6.5975041930545276e-05, 2.1904137112216987e-04, + -9.4917202172906947e-04, -1.9348461836307453e-05, 8.3988868724731795e-05, + -2.7884843156041284e-04, 2.4631366250678167e-05, 1.3297080252287668e-03, + -1.1772587914055043e-04, 1.1819655564340515e-04, -1.6927715315547805e-03, + -1.0529897957677521e-05, 1.4986975558194376e-04, -1.5046894560673518e-04, + 1.3404981510784434e-05, 1.4085793923499623e-03, -1.2496886316451210e-04, + -7.2660150604629122e-05, -1.7931779383632163e-03, 6.3481591817070706e-06, + 1.5909036411151771e-04, 9.2499279607521743e-05, -8.0814606941427644e-06, + 6.4136415990857299e-04, -5.6986764463632038e-05, -3.7029177037178836e-04, + -8.1648224320973327e-04, 3.2901323803321743e-05, 7.2546431794944845e-05, + 4.7139624290569047e-04, -4.1884701925559310e-05, -1.2100112667458897e-03, + 1.9945749296636440e-04, 3.3972790274495772e-05, 1.5403927676947034e-03, + -5.5938134322215696e-06, -2.5391737091356098e-04, -4.3248721623872660e-05, + 7.1211483658335299e-06, -9.8397636034453450e-04, 1.6222237447238830e-04, + 9.6528523782578516e-05, 1.2526412858398512e-03, -1.5903892253583135e-05, + -2.0651557490663052e-04, -1.2288467388474000e-04, 2.0246291318839486e-05, + -5.6925297375807257e-04, 9.3835695361493563e-05, 1.4291213510234853e-04, + 7.2468181732210975e-04, -2.3579175340076496e-05, -1.1945659553664517e-04, + -1.8193286738518963e-04, 3.0017233855795637e-05, -4.0541836830676359e-05, + 6.4812209752868387e-06, 1.6233938212623677e-04, 5.1611380785723758e-05, + -2.6854953961718241e-05, -8.2508536825548366e-06, -2.0666453033267172e-04, + 3.4187431139095443e-05, 4.9013450248755377e-04, -8.1515030663001578e-05, + 1.4404674523170864e-04, -6.2396083704236598e-04, -2.3949705609325615e-05, + 1.0377189629761350e-04, -1.8337727148740832e-04, 3.0488933717316898e-05, + 8.7363231171246156e-04, -1.4558955682893914e-04, 7.7365818157923587e-05, + -1.1121688959189492e-03, -1.3043739320776170e-05, 1.8534133239460972e-04, + -9.8489782725531659e-05, 1.6605202170929833e-05, 9.2429031121327328e-04, + -1.5463556819535182e-04, -4.8118408509521975e-05, -1.1766585566365616e-03, + 7.8210222232853527e-06, 1.9685726688898814e-04, 6.1256659750270513e-05, + -9.9564742906303526e-06, 4.2047339144771385e-04, -7.0544580168748378e-05, + -2.4276042573941192e-04, -5.3527945482356677e-04, 4.0728932350295730e-05, + 8.9806073776681691e-05, 3.0904373733406230e-04, -5.1849560869830381e-05, + -5.6182935935282811e-04, 1.7477050575086486e-04, 1.5794234573042703e-05, + 7.1523125908826493e-04, -4.9015805954909655e-06, -2.2248984820528401e-04, + -2.0106692702968120e-05, 6.2399082612448420e-06, -4.5678597105276730e-04, + 1.4215113869939708e-04, 4.4852593938587782e-05, 5.8150682190454017e-04, + -1.3931219752469142e-05, -1.8096408850885645e-04, -5.7099147102286593e-05, + 1.7735000277791322e-05, -2.6422489214980252e-04, 8.2272349665436255e-05, + 6.6322596801483795e-05, 3.3636886209089138e-04, -2.0639815215036942e-05, + -1.0473599369591789e-04, -8.4431319984719147e-05, 2.6275310782271061e-05, + -1.9172276725498251e-05, 5.8565003039016137e-06, 7.5158596679360178e-05, + 2.4407075553624133e-05, -2.3478895984198962e-05, -7.4555592663146275e-06, + -9.5679901449448646e-05, 2.9889574222544112e-05, 2.2595287291712833e-04, + -7.1010304284437612e-05, 6.6364474451957597e-05, -2.8764704994641428e-04, + -2.0900174336625055e-05, 9.0398959214416647e-05, -8.4484631909731762e-05, + 2.6606758363727290e-05, 4.0170043536066267e-04, -1.2688043902193714e-04, + 3.5103428034237590e-05, -5.1138073042365968e-04, -1.1356462993730947e-05, + 1.6152387668003697e-04, -4.4688068740591611e-05, 1.4457231881138533e-05, + 4.2273028355949746e-04, -1.3494024878531186e-04, -2.2961839515623369e-05, + -5.3815256880357897e-04, 6.7031296572293737e-06, 1.7178433706557214e-04, + 2.9231340645244033e-05, -8.5333523155403361e-06, 1.9147960544159756e-04, + -6.1665043824634419e-05, -1.1055080174602965e-04, -2.4376120081633150e-04, + 3.5602329651742721e-05, 7.8502068648085319e-05, 1.4073559490929551e-04, + -4.5323190465914605e-05, -1.2955898186390926e-04, 7.4800913055063687e-05, + 3.6522239721318641e-06, 1.6493376891421171e-04, -2.1086124934482099e-06, + -9.5224555881080988e-05, -4.6494272799621577e-06, 2.6843480916631399e-06, + -1.0528648823581542e-04, 6.0787182324984421e-05, 1.0361506757951604e-05, + 1.3403391313090328e-04, -5.9822187159139861e-06, -7.7384515826667597e-05, + -1.3190612774451585e-05, 7.6156038361061387e-06, -6.0862501235595707e-05, + 3.5138981471927000e-05, 1.5286694095101679e-05, 7.7480399814173790e-05, + -8.8257769508283041e-06, -4.4733329689633267e-05, -1.9460573362581266e-05, + 1.1235567269471202e-05, -4.5142603222996201e-06, 2.6063094122710723e-06, + 1.7245977964551712e-05, 5.7468340527632004e-06, -9.9569700202718593e-06, + -3.3179361873508551e-06, -2.1954820139700859e-05, 1.2675621317665824e-05, + 5.1479709017778204e-05, -2.9721823859217862e-05, 1.5082155306937880e-05, + -6.5535729817849114e-05, -8.7076864264203733e-06, 3.7837071251873586e-05, + -1.9200187299523851e-05, 1.1085233305871462e-05, 9.0968534244011416e-05, + -5.2520707733565707e-05, 7.7167285674099497e-06, -1.1580658468917291e-04, + -4.4552553156573706e-06, 6.6860962844225174e-05, -9.8237042928275584e-06, + 5.6717183179032468e-06, 9.4503458338676474e-05, -5.4561597111185429e-05, + -5.6758391897901815e-06, -1.2030668453073529e-04, 3.2769472841023753e-06, + 6.9459096699131382e-05, 7.2255704379213280e-06, -4.1716850373824735e-06, + 4.2336308243184655e-05, -2.4442878960697636e-05, -2.4442878960697636e-05, + -5.3895814709293923e-05, 1.4112102747728219e-05, 3.1116763130605032e-05, + 3.1116763130605032e-05, -1.7965271569764636e-05 }; return sol; } -static const double * -get_sol_3x_bias_p1_DxDx_DyNy(void) +static const double *get_sol_3x_bias_p1_DxDx_DyNy(void) { static const double sol[512] = { - 2.4528129331630134e-04, 1.4161322072330483e-04, 1.4161322072328683e-04, -3.1225290264548392e-04, 8.1760431105401652e-05, -1.8027929739760661e-04, - -1.8027929739761000e-04, -1.0408430088182000e-04, 5.3693018033431348e-04, 3.0999678415214295e-04, 2.6770342705417267e-05, -6.8353360772280454e-04, - 1.5455864567346426e-05, -3.9463831241897844e-04, -3.4079717623695104e-05, -1.9675934143992066e-05, 5.0481002617899188e-04, 2.9145220450423542e-04, - -4.5314922353404482e-05, -6.4264336602190574e-04, -2.6162582619074331e-05, -3.7103032036578127e-04, 5.7687709676937853e-05, 3.3306014710932019e-05, - 2.8251817425993943e-04, 1.6311194395979506e-04, -8.3025338190720856e-05, -3.5965694232132722e-04, -4.7934701354125037e-05, -2.0764803246505980e-04, - 1.0569457822360065e-04, 6.1022793189366422e-05, -2.2431527513860707e-05, -1.2950848448608950e-05, -9.3037454217678806e-05, 2.8556232243852698e-05, - -5.3715199237144208e-05, 1.6486948373083493e-05, 1.1844040261456511e-04, 6.8381598332347218e-05, -3.2502275688907155e-04, -1.8765197618256113e-04, - -8.1663673516519012e-05, 4.1376697705843729e-04, -4.7148543887784260e-05, 2.3888847558638216e-04, 1.0396112459887155e-04, 6.0021983272434631e-05, - -5.6185672699466782e-04, -3.2438813257639734e-04, -5.5072482877194797e-05, 7.1526609919159482e-04, -3.1796112814151838e-05, 4.1295907491050522e-04, - 7.0109474725142730e-05, 4.0477724105347290e-05, -6.9079330390630332e-04, -3.9882969996476124e-04, -1.9369084511126962e-05, 8.7940752169269742e-04, - -1.1182746156417725e-05, 5.0772616937670993e-04, 2.4657619741037014e-05, 1.4236083395034633e-05, 6.2367351899500370e-04, 7.6851632631555648e-05, - 3.6007807407826783e-04, -7.9396134934036906e-04, 4.4370310787568746e-05, -9.7835203972601709e-05, -4.5839379876788942e-04, -5.6485181349849416e-05, - 1.3669669930979761e-03, 1.6922519313425672e-04, 6.9062613281975358e-05, -1.7402036887708588e-03, 8.9615892346698773e-06, -2.1543044331873924e-04, - -8.7919470620924958e-05, -1.1408461742061553e-05, 1.2870709745400632e-03, 1.6018636460856113e-04, -1.1519060110356575e-04, -1.6384928596765102e-03, - -1.4180159317139120e-05, -2.0392365286805704e-04, 1.4664224517804710e-04, 1.8051910306271542e-05, 7.2082558778293704e-04, 8.9944959225516229e-05, - -2.1173132536804489e-04, -9.1763982097139551e-04, -2.6373734989019563e-05, -1.1450353272675932e-04, 2.6954245076451052e-04, 3.3574820128275405e-05, - -5.7211901773804499e-05, -7.1296099928855400e-06, -2.3746882866716045e-04, 7.2833040600929667e-05, -2.9672293680691639e-05, 9.0762788507323819e-06, - 3.0230732248929024e-04, 3.7774017352392656e-05, -8.2967964857642753e-04, -1.0371181608153377e-04, -2.0851563288963774e-04, 1.0562153967439373e-03, - -2.6089469003517304e-05, 1.3202929245949090e-04, 2.6544874554620365e-04, 3.3212938152299769e-05, -1.4344421799159632e-03, -1.7939931355866409e-04, - -1.4064417737504262e-04, 1.8261023019736982e-03, -1.7608728039193037e-05, 2.2838250579132398e-04, 1.7904566643376686e-04, 2.2416615502119518e-05, - -1.7637269696838659e-03, -2.2062884079452653e-04, -4.9468484637505455e-05, 2.2452950174551419e-03, -6.1951506089930910e-06, 2.8086934398448092e-04, - 6.2975360691774624e-05, 7.8866746576120576e-06, 7.9228320374871762e-04, 2.0495214248979126e-05, 4.5742492095879333e-04, -1.0086082258578147e-03, - 1.1832917463663955e-05, -2.6091227965457842e-05, -5.8232023070591639e-04, -1.5063777489280264e-05, 1.7385437019493434e-03, 4.5304719745675459e-05, - 8.8898832400847294e-05, -2.2132357097847822e-03, 2.4908572133151579e-06, -5.7674721348962351e-05, -1.1317177141254004e-04, -3.1709609176348154e-06, - 1.6392548325408021e-03, 4.3147080612406641e-05, -1.4622328788140213e-04, -2.0868370054480641e-03, -3.7365707477220556e-06, -5.4927960382742277e-05, - 1.8614809738656446e-04, 4.7568041008815300e-06, 9.1873938193646955e-04, 2.4320623105365984e-05, -2.6976650148029420e-04, -1.1695920015167992e-03, - -7.1328895618548160e-06, -3.0961126534042701e-05, 3.4342355254599055e-04, 9.0804538732882195e-06, -7.3130563309116366e-05, -2.0610335296653078e-06, - -3.0288987840834431e-04, 9.3098133806460183e-05, -8.0985669980487482e-06, 2.6237781666334921e-06, 3.8559093698597817e-04, 1.0309799896355122e-05, - -1.0586408004009239e-03, -2.8478966558305924e-05, -2.6609472226574274e-04, 1.3476921061319287e-03, -7.1538337474704410e-06, 3.6254864168172258e-05, - 3.3874923065981298e-04, 9.1071166597727465e-06, -1.8304802004777767e-03, -4.9253344222025752e-05, -1.7952696313978798e-04, 2.3302745517463576e-03, - -4.8402587889251591e-06, 6.2701478332859929e-05, 2.2854500881667826e-04, 6.1618431473638616e-06, -2.2508116665430249e-03, -6.0589640055256245e-05, - -6.3151521941853120e-05, 2.8653733298781361e-03, -1.7047546620036213e-06, 7.7133036611583822e-05, 8.0394414780744056e-05, 2.1702209096831663e-06, - 7.8392504372925523e-04, -2.5320800186145820e-05, 4.5259933502152905e-04, -9.9796795365614537e-04, -1.4618970803541214e-05, 3.2234391985342402e-05, - -5.7617706668595004e-04, 1.8610534889883806e-05, 1.7210227955432836e-03, -5.5420419775660136e-05, 8.8434304245293659e-05, -2.1909308947362935e-03, - -2.7590526689701884e-06, 7.0552412321432068e-05, -1.1258040847992118e-04, 3.5123844659711566e-06, 1.6238014988128491e-03, -5.2069067000117360e-05, - -1.4456504608357444e-04, -2.0671642931638810e-03, 4.6939570960792625e-06, 6.6286006115705404e-05, 1.8403708921443886e-04, -5.9755952373196969e-06, - 9.1036543165675754e-04, -2.9155325553538169e-05, -2.6733745933858315e-04, -1.1589316276819452e-03, 8.5352976962446396e-06, 3.7115896237257653e-05, - 3.4033128468836791e-04, -1.0865775553293072e-05, -7.3041740691777587e-05, 2.1123152916959775e-06, -3.0043293633985239e-04, 9.2985059059862732e-05, - 9.5170831626758565e-06, -2.6890619020200572e-06, 3.8246315140499926e-04, -1.2115627743500696e-05, -1.0507771170938653e-03, 3.3019066232458140e-05, - -2.6406284642211314e-04, 1.3376813225743343e-03, 8.3269378127498946e-06, -4.2034592749948440e-05, 3.3616257139440221e-04, -1.0600525082959479e-05, - -1.8168031392969675e-03, 5.7149799176489184e-05, -1.7820248370310621e-04, 2.3128631055018096e-03, 5.6049473482294999e-06, -7.2753981509130305e-05, - 2.2685889348759484e-04, -7.1353222864949212e-06, -2.2340461539592260e-03, 7.0269213258614450e-05, -6.2692883129639935e-05, 2.8440301613965437e-03, - 1.9695499036957175e-06, -8.9455520679790750e-05, 7.9810549217890943e-05, -2.5073158495669610e-06, 6.4136415990857722e-04, -5.6986764463633543e-05, - 3.7029177037179703e-04, -8.1648224320975094e-04, -3.2901323803324068e-05, 7.2546431794953979e-05, -4.7139624290569486e-04, 4.1884701925557338e-05, - 1.4085793923499818e-03, -1.2496886316451560e-04, 7.2660150604629298e-05, -1.7931779383632382e-03, -6.3481591817058695e-06, 1.5909036411152085e-04, - -9.2499279607519873e-05, 8.0814606941412736e-06, 1.3297080252287884e-03, -1.1772587914055242e-04, -1.1819655564340408e-04, -1.6927715315548004e-03, - 1.0529897957677164e-05, 1.4986975558194462e-04, 1.5046894560673474e-04, -1.3404981510784272e-05, 7.4559480183162229e-04, -6.5975041930547919e-05, - -2.1904137112216997e-04, -9.4917202172908996e-04, 1.9348461836307433e-05, 8.3988868724733218e-05, 2.7884843156041278e-04, -2.4631366250678018e-05, - -6.0575372069946429e-05, 5.0851459879353555e-06, -2.4640119579254818e-04, 7.7114872895287390e-05, 2.1678156787094268e-05, -6.4735943521869927e-06, - 3.1367858331675646e-04, -2.7597161158338441e-05, -8.6268379122424329e-04, 7.5576666091140113e-05, -2.1669631592545041e-04, 1.0982309911733632e-03, - 1.9020141320076898e-05, -9.6212120541947429e-05, 2.7586308244495630e-04, -2.4213401094000017e-05, -1.4913852692680471e-03, 1.3073029568382250e-04, - -1.4628465166305546e-04, 1.8985931336037425e-03, 1.2822821572043187e-05, -1.6642489828339754e-04, 1.8622621593640876e-04, -1.6323965035577555e-05, - -1.8339090424506746e-03, 1.6075005578360718e-04, -5.1471540987780780e-05, 2.3346396048014523e-03, 4.5090950025754530e-06, -2.0464125429303859e-04, - 6.5525331588775406e-05, -5.7402583940352802e-06, 4.2047339144771884e-04, -7.0544580168746372e-05, 2.4276042573941360e-04, -5.3527945482357089e-04, - -4.0728932350297417e-05, 8.9806073776680376e-05, -3.0904373733406609e-04, 5.1849560869832665e-05, 9.2429031121328423e-04, -1.5463556819535337e-04, - 4.8118408509523703e-05, -1.1766585566365740e-03, -7.8210222232856864e-06, 1.9685726688899052e-04, -6.1256659750271475e-05, 9.9564742906302052e-06, - 8.7363231171247609e-04, -1.4558955682894122e-04, -7.7365818157923235e-05, -1.1121688959189638e-03, 1.3043739320776170e-05, 1.8534133239461173e-04, - 9.8489782725531320e-05, -1.6605202170929907e-05, 4.9013450248756884e-04, -8.1515030663003706e-05, -1.4404674523170886e-04, -6.2396083704238073e-04, - 2.3949705609325615e-05, 1.0377189629761538e-04, 1.8337727148740848e-04, -3.0488933717316904e-05, -4.0541836830662847e-05, 6.4812209752848744e-06, - -1.6233938212623750e-04, 5.1611380785709785e-05, 2.6854953961718350e-05, -8.2508536825531239e-06, 2.0666453033267208e-04, -3.4187431139095545e-05, - -5.6925297375806162e-04, 9.3835695361491842e-05, -1.4291213510234937e-04, 7.2468181732209653e-04, 2.3579175340076526e-05, -1.1945659553664353e-04, - 1.8193286738518982e-04, -3.0017233855795586e-05, -9.8397636034452582e-04, 1.6222237447238684e-04, -9.6528523782579045e-05, 1.2526412858398384e-03, - 1.5903892253583209e-05, -2.0651557490662865e-04, 1.2288467388474008e-04, -2.0246291318839398e-05, -1.2100112667458827e-03, 1.9945749296636326e-04, - -3.3972790274496219e-05, 1.5403927676946908e-03, 5.5938134322216204e-06, -2.5391737091355897e-04, 4.3248721623872789e-05, -7.1211483658335443e-06, - 1.9147960544160306e-04, -6.1665043824636221e-05, 1.1055080174602976e-04, -2.4376120081633551e-04, -3.5602329651741962e-05, 7.8502068648086647e-05, - -1.4073559490929594e-04, 4.5323190465914280e-05, 4.2273028355950445e-04, -1.3494024878531264e-04, 2.2961839515624121e-05, -5.3815256880358536e-04, - -6.7031296572295651e-06, 1.7178433706557325e-04, -2.9231340645244964e-05, 8.5333523155405428e-06, 4.0170043536067135e-04, -1.2688043902193852e-04, - -3.5103428034237394e-05, -5.1138073042366814e-04, 1.1356462993730807e-05, 1.6152387668003857e-04, 4.4688068740591320e-05, -1.4457231881138467e-05, - 2.2595287291713638e-04, -7.1010304284439536e-05, -6.6364474451958058e-05, -2.8764704994642274e-04, 2.0900174336624889e-05, 9.0398959214418450e-05, - 8.4484631909732033e-05, -2.6606758363727233e-05, -1.9172276725491939e-05, 5.8565003038994394e-06, -7.5158596679360720e-05, 2.4407075553616452e-05, - 2.3478895984198975e-05, -7.4555592663126946e-06, 9.5679901449448836e-05, -2.9889574222544105e-05, -2.6422489214979829e-04, 8.2272349665434154e-05, - -6.6322596801484445e-05, 3.3636886209088439e-04, 2.0639815215036979e-05, -1.0473599369591595e-04, 8.4431319984719323e-05, -2.6275310782271078e-05, - -4.5678597105276454e-04, 1.4215113869939523e-04, -4.4852593938587911e-05, 5.8150682190453355e-04, 1.3931219752469295e-05, -1.8096408850885461e-04, - 5.7099147102286688e-05, -1.7735000277791359e-05, -5.6182935935282605e-04, 1.7477050575086326e-04, -1.5794234573042971e-05, 7.1523125908825875e-04, - 4.9015805954909655e-06, -2.2248984820528222e-04, 2.0106692702968208e-05, -6.2399082612448200e-06, 4.2336308243184337e-05, -2.4442878960699218e-05, - 2.4442878960699808e-05, -5.3895814709293103e-05, -1.4112102747727776e-05, 3.1116763130606509e-05, -3.1116763130606143e-05, 1.7965271569764575e-05, - 9.4503458338682613e-05, -5.4561597111185097e-05, 5.6758391897917417e-06, -1.2030668453073874e-04, -3.2769472841017108e-06, 6.9459096699131965e-05, - -7.2255704379226824e-06, 4.1716850373820128e-06, 9.0968534244016471e-05, -5.2520707733566358e-05, -7.7167285674121299e-06, -1.1580658468917736e-04, - 4.4552553156561441e-06, 6.6860962844225892e-05, 9.8237042928283342e-06, -5.6717183179027064e-06, 5.1479709017779133e-05, -2.9721823859220088e-05, - -1.5082155306938090e-05, -6.5535729817851269e-05, 8.7076864264206867e-06, 3.7837071251875416e-05, 1.9200187299524397e-05, -1.1085233305871360e-05, - -4.5142603223004349e-06, 2.6063094122691225e-06, -1.7245977964552505e-05, 5.7468340527625220e-06, 9.9569700202717051e-06, -3.3179361873487524e-06, - 2.1954820139701161e-05, -1.2675621317665762e-05, -6.0862501235599170e-05, 3.5138981471924683e-05, -1.5286694095102407e-05, 7.7480399814173464e-05, - 8.8257769508282516e-06, -4.4733329689631329e-05, 1.9460573362581161e-05, -1.1235567269471365e-05, -1.0528648823582079e-04, 6.0787182324981514e-05, - -1.0361506757951987e-05, 1.3403391313090323e-04, 5.9822187159136922e-06, -7.7384515826665673e-05, 1.3190612774451854e-05, -7.6156038361059896e-06, - -1.2955898186391113e-04, 7.4800913055062928e-05, -3.6522239721294407e-06, 1.6493376891421133e-04, 2.1086124934497494e-06, -9.5224555881079430e-05, - 4.6494272799617046e-06, -2.6843480916634906e-06, + 2.4528129331630134e-04, 1.4161322072330483e-04, 1.4161322072328683e-04, + -3.1225290264548392e-04, 8.1760431105401652e-05, -1.8027929739760661e-04, + -1.8027929739761000e-04, -1.0408430088182000e-04, 5.3693018033431348e-04, + 3.0999678415214295e-04, 2.6770342705417267e-05, -6.8353360772280454e-04, + 1.5455864567346426e-05, -3.9463831241897844e-04, -3.4079717623695104e-05, + -1.9675934143992066e-05, 5.0481002617899188e-04, 2.9145220450423542e-04, + -4.5314922353404482e-05, -6.4264336602190574e-04, -2.6162582619074331e-05, + -3.7103032036578127e-04, 5.7687709676937853e-05, 3.3306014710932019e-05, + 2.8251817425993943e-04, 1.6311194395979506e-04, -8.3025338190720856e-05, + -3.5965694232132722e-04, -4.7934701354125037e-05, -2.0764803246505980e-04, + 1.0569457822360065e-04, 6.1022793189366422e-05, -2.2431527513860707e-05, + -1.2950848448608950e-05, -9.3037454217678806e-05, 2.8556232243852698e-05, + -5.3715199237144208e-05, 1.6486948373083493e-05, 1.1844040261456511e-04, + 6.8381598332347218e-05, -3.2502275688907155e-04, -1.8765197618256113e-04, + -8.1663673516519012e-05, 4.1376697705843729e-04, -4.7148543887784260e-05, + 2.3888847558638216e-04, 1.0396112459887155e-04, 6.0021983272434631e-05, + -5.6185672699466782e-04, -3.2438813257639734e-04, -5.5072482877194797e-05, + 7.1526609919159482e-04, -3.1796112814151838e-05, 4.1295907491050522e-04, + 7.0109474725142730e-05, 4.0477724105347290e-05, -6.9079330390630332e-04, + -3.9882969996476124e-04, -1.9369084511126962e-05, 8.7940752169269742e-04, + -1.1182746156417725e-05, 5.0772616937670993e-04, 2.4657619741037014e-05, + 1.4236083395034633e-05, 6.2367351899500370e-04, 7.6851632631555648e-05, + 3.6007807407826783e-04, -7.9396134934036906e-04, 4.4370310787568746e-05, + -9.7835203972601709e-05, -4.5839379876788942e-04, -5.6485181349849416e-05, + 1.3669669930979761e-03, 1.6922519313425672e-04, 6.9062613281975358e-05, + -1.7402036887708588e-03, 8.9615892346698773e-06, -2.1543044331873924e-04, + -8.7919470620924958e-05, -1.1408461742061553e-05, 1.2870709745400632e-03, + 1.6018636460856113e-04, -1.1519060110356575e-04, -1.6384928596765102e-03, + -1.4180159317139120e-05, -2.0392365286805704e-04, 1.4664224517804710e-04, + 1.8051910306271542e-05, 7.2082558778293704e-04, 8.9944959225516229e-05, + -2.1173132536804489e-04, -9.1763982097139551e-04, -2.6373734989019563e-05, + -1.1450353272675932e-04, 2.6954245076451052e-04, 3.3574820128275405e-05, + -5.7211901773804499e-05, -7.1296099928855400e-06, -2.3746882866716045e-04, + 7.2833040600929667e-05, -2.9672293680691639e-05, 9.0762788507323819e-06, + 3.0230732248929024e-04, 3.7774017352392656e-05, -8.2967964857642753e-04, + -1.0371181608153377e-04, -2.0851563288963774e-04, 1.0562153967439373e-03, + -2.6089469003517304e-05, 1.3202929245949090e-04, 2.6544874554620365e-04, + 3.3212938152299769e-05, -1.4344421799159632e-03, -1.7939931355866409e-04, + -1.4064417737504262e-04, 1.8261023019736982e-03, -1.7608728039193037e-05, + 2.2838250579132398e-04, 1.7904566643376686e-04, 2.2416615502119518e-05, + -1.7637269696838659e-03, -2.2062884079452653e-04, -4.9468484637505455e-05, + 2.2452950174551419e-03, -6.1951506089930910e-06, 2.8086934398448092e-04, + 6.2975360691774624e-05, 7.8866746576120576e-06, 7.9228320374871762e-04, + 2.0495214248979126e-05, 4.5742492095879333e-04, -1.0086082258578147e-03, + 1.1832917463663955e-05, -2.6091227965457842e-05, -5.8232023070591639e-04, + -1.5063777489280264e-05, 1.7385437019493434e-03, 4.5304719745675459e-05, + 8.8898832400847294e-05, -2.2132357097847822e-03, 2.4908572133151579e-06, + -5.7674721348962351e-05, -1.1317177141254004e-04, -3.1709609176348154e-06, + 1.6392548325408021e-03, 4.3147080612406641e-05, -1.4622328788140213e-04, + -2.0868370054480641e-03, -3.7365707477220556e-06, -5.4927960382742277e-05, + 1.8614809738656446e-04, 4.7568041008815300e-06, 9.1873938193646955e-04, + 2.4320623105365984e-05, -2.6976650148029420e-04, -1.1695920015167992e-03, + -7.1328895618548160e-06, -3.0961126534042701e-05, 3.4342355254599055e-04, + 9.0804538732882195e-06, -7.3130563309116366e-05, -2.0610335296653078e-06, + -3.0288987840834431e-04, 9.3098133806460183e-05, -8.0985669980487482e-06, + 2.6237781666334921e-06, 3.8559093698597817e-04, 1.0309799896355122e-05, + -1.0586408004009239e-03, -2.8478966558305924e-05, -2.6609472226574274e-04, + 1.3476921061319287e-03, -7.1538337474704410e-06, 3.6254864168172258e-05, + 3.3874923065981298e-04, 9.1071166597727465e-06, -1.8304802004777767e-03, + -4.9253344222025752e-05, -1.7952696313978798e-04, 2.3302745517463576e-03, + -4.8402587889251591e-06, 6.2701478332859929e-05, 2.2854500881667826e-04, + 6.1618431473638616e-06, -2.2508116665430249e-03, -6.0589640055256245e-05, + -6.3151521941853120e-05, 2.8653733298781361e-03, -1.7047546620036213e-06, + 7.7133036611583822e-05, 8.0394414780744056e-05, 2.1702209096831663e-06, + 7.8392504372925523e-04, -2.5320800186145820e-05, 4.5259933502152905e-04, + -9.9796795365614537e-04, -1.4618970803541214e-05, 3.2234391985342402e-05, + -5.7617706668595004e-04, 1.8610534889883806e-05, 1.7210227955432836e-03, + -5.5420419775660136e-05, 8.8434304245293659e-05, -2.1909308947362935e-03, + -2.7590526689701884e-06, 7.0552412321432068e-05, -1.1258040847992118e-04, + 3.5123844659711566e-06, 1.6238014988128491e-03, -5.2069067000117360e-05, + -1.4456504608357444e-04, -2.0671642931638810e-03, 4.6939570960792625e-06, + 6.6286006115705404e-05, 1.8403708921443886e-04, -5.9755952373196969e-06, + 9.1036543165675754e-04, -2.9155325553538169e-05, -2.6733745933858315e-04, + -1.1589316276819452e-03, 8.5352976962446396e-06, 3.7115896237257653e-05, + 3.4033128468836791e-04, -1.0865775553293072e-05, -7.3041740691777587e-05, + 2.1123152916959775e-06, -3.0043293633985239e-04, 9.2985059059862732e-05, + 9.5170831626758565e-06, -2.6890619020200572e-06, 3.8246315140499926e-04, + -1.2115627743500696e-05, -1.0507771170938653e-03, 3.3019066232458140e-05, + -2.6406284642211314e-04, 1.3376813225743343e-03, 8.3269378127498946e-06, + -4.2034592749948440e-05, 3.3616257139440221e-04, -1.0600525082959479e-05, + -1.8168031392969675e-03, 5.7149799176489184e-05, -1.7820248370310621e-04, + 2.3128631055018096e-03, 5.6049473482294999e-06, -7.2753981509130305e-05, + 2.2685889348759484e-04, -7.1353222864949212e-06, -2.2340461539592260e-03, + 7.0269213258614450e-05, -6.2692883129639935e-05, 2.8440301613965437e-03, + 1.9695499036957175e-06, -8.9455520679790750e-05, 7.9810549217890943e-05, + -2.5073158495669610e-06, 6.4136415990857722e-04, -5.6986764463633543e-05, + 3.7029177037179703e-04, -8.1648224320975094e-04, -3.2901323803324068e-05, + 7.2546431794953979e-05, -4.7139624290569486e-04, 4.1884701925557338e-05, + 1.4085793923499818e-03, -1.2496886316451560e-04, 7.2660150604629298e-05, + -1.7931779383632382e-03, -6.3481591817058695e-06, 1.5909036411152085e-04, + -9.2499279607519873e-05, 8.0814606941412736e-06, 1.3297080252287884e-03, + -1.1772587914055242e-04, -1.1819655564340408e-04, -1.6927715315548004e-03, + 1.0529897957677164e-05, 1.4986975558194462e-04, 1.5046894560673474e-04, + -1.3404981510784272e-05, 7.4559480183162229e-04, -6.5975041930547919e-05, + -2.1904137112216997e-04, -9.4917202172908996e-04, 1.9348461836307433e-05, + 8.3988868724733218e-05, 2.7884843156041278e-04, -2.4631366250678018e-05, + -6.0575372069946429e-05, 5.0851459879353555e-06, -2.4640119579254818e-04, + 7.7114872895287390e-05, 2.1678156787094268e-05, -6.4735943521869927e-06, + 3.1367858331675646e-04, -2.7597161158338441e-05, -8.6268379122424329e-04, + 7.5576666091140113e-05, -2.1669631592545041e-04, 1.0982309911733632e-03, + 1.9020141320076898e-05, -9.6212120541947429e-05, 2.7586308244495630e-04, + -2.4213401094000017e-05, -1.4913852692680471e-03, 1.3073029568382250e-04, + -1.4628465166305546e-04, 1.8985931336037425e-03, 1.2822821572043187e-05, + -1.6642489828339754e-04, 1.8622621593640876e-04, -1.6323965035577555e-05, + -1.8339090424506746e-03, 1.6075005578360718e-04, -5.1471540987780780e-05, + 2.3346396048014523e-03, 4.5090950025754530e-06, -2.0464125429303859e-04, + 6.5525331588775406e-05, -5.7402583940352802e-06, 4.2047339144771884e-04, + -7.0544580168746372e-05, 2.4276042573941360e-04, -5.3527945482357089e-04, + -4.0728932350297417e-05, 8.9806073776680376e-05, -3.0904373733406609e-04, + 5.1849560869832665e-05, 9.2429031121328423e-04, -1.5463556819535337e-04, + 4.8118408509523703e-05, -1.1766585566365740e-03, -7.8210222232856864e-06, + 1.9685726688899052e-04, -6.1256659750271475e-05, 9.9564742906302052e-06, + 8.7363231171247609e-04, -1.4558955682894122e-04, -7.7365818157923235e-05, + -1.1121688959189638e-03, 1.3043739320776170e-05, 1.8534133239461173e-04, + 9.8489782725531320e-05, -1.6605202170929907e-05, 4.9013450248756884e-04, + -8.1515030663003706e-05, -1.4404674523170886e-04, -6.2396083704238073e-04, + 2.3949705609325615e-05, 1.0377189629761538e-04, 1.8337727148740848e-04, + -3.0488933717316904e-05, -4.0541836830662847e-05, 6.4812209752848744e-06, + -1.6233938212623750e-04, 5.1611380785709785e-05, 2.6854953961718350e-05, + -8.2508536825531239e-06, 2.0666453033267208e-04, -3.4187431139095545e-05, + -5.6925297375806162e-04, 9.3835695361491842e-05, -1.4291213510234937e-04, + 7.2468181732209653e-04, 2.3579175340076526e-05, -1.1945659553664353e-04, + 1.8193286738518982e-04, -3.0017233855795586e-05, -9.8397636034452582e-04, + 1.6222237447238684e-04, -9.6528523782579045e-05, 1.2526412858398384e-03, + 1.5903892253583209e-05, -2.0651557490662865e-04, 1.2288467388474008e-04, + -2.0246291318839398e-05, -1.2100112667458827e-03, 1.9945749296636326e-04, + -3.3972790274496219e-05, 1.5403927676946908e-03, 5.5938134322216204e-06, + -2.5391737091355897e-04, 4.3248721623872789e-05, -7.1211483658335443e-06, + 1.9147960544160306e-04, -6.1665043824636221e-05, 1.1055080174602976e-04, + -2.4376120081633551e-04, -3.5602329651741962e-05, 7.8502068648086647e-05, + -1.4073559490929594e-04, 4.5323190465914280e-05, 4.2273028355950445e-04, + -1.3494024878531264e-04, 2.2961839515624121e-05, -5.3815256880358536e-04, + -6.7031296572295651e-06, 1.7178433706557325e-04, -2.9231340645244964e-05, + 8.5333523155405428e-06, 4.0170043536067135e-04, -1.2688043902193852e-04, + -3.5103428034237394e-05, -5.1138073042366814e-04, 1.1356462993730807e-05, + 1.6152387668003857e-04, 4.4688068740591320e-05, -1.4457231881138467e-05, + 2.2595287291713638e-04, -7.1010304284439536e-05, -6.6364474451958058e-05, + -2.8764704994642274e-04, 2.0900174336624889e-05, 9.0398959214418450e-05, + 8.4484631909732033e-05, -2.6606758363727233e-05, -1.9172276725491939e-05, + 5.8565003038994394e-06, -7.5158596679360720e-05, 2.4407075553616452e-05, + 2.3478895984198975e-05, -7.4555592663126946e-06, 9.5679901449448836e-05, + -2.9889574222544105e-05, -2.6422489214979829e-04, 8.2272349665434154e-05, + -6.6322596801484445e-05, 3.3636886209088439e-04, 2.0639815215036979e-05, + -1.0473599369591595e-04, 8.4431319984719323e-05, -2.6275310782271078e-05, + -4.5678597105276454e-04, 1.4215113869939523e-04, -4.4852593938587911e-05, + 5.8150682190453355e-04, 1.3931219752469295e-05, -1.8096408850885461e-04, + 5.7099147102286688e-05, -1.7735000277791359e-05, -5.6182935935282605e-04, + 1.7477050575086326e-04, -1.5794234573042971e-05, 7.1523125908825875e-04, + 4.9015805954909655e-06, -2.2248984820528222e-04, 2.0106692702968208e-05, + -6.2399082612448200e-06, 4.2336308243184337e-05, -2.4442878960699218e-05, + 2.4442878960699808e-05, -5.3895814709293103e-05, -1.4112102747727776e-05, + 3.1116763130606509e-05, -3.1116763130606143e-05, 1.7965271569764575e-05, + 9.4503458338682613e-05, -5.4561597111185097e-05, 5.6758391897917417e-06, + -1.2030668453073874e-04, -3.2769472841017108e-06, 6.9459096699131965e-05, + -7.2255704379226824e-06, 4.1716850373820128e-06, 9.0968534244016471e-05, + -5.2520707733566358e-05, -7.7167285674121299e-06, -1.1580658468917736e-04, + 4.4552553156561441e-06, 6.6860962844225892e-05, 9.8237042928283342e-06, + -5.6717183179027064e-06, 5.1479709017779133e-05, -2.9721823859220088e-05, + -1.5082155306938090e-05, -6.5535729817851269e-05, 8.7076864264206867e-06, + 3.7837071251875416e-05, 1.9200187299524397e-05, -1.1085233305871360e-05, + -4.5142603223004349e-06, 2.6063094122691225e-06, -1.7245977964552505e-05, + 5.7468340527625220e-06, 9.9569700202717051e-06, -3.3179361873487524e-06, + 2.1954820139701161e-05, -1.2675621317665762e-05, -6.0862501235599170e-05, + 3.5138981471924683e-05, -1.5286694095102407e-05, 7.7480399814173464e-05, + 8.8257769508282516e-06, -4.4733329689631329e-05, 1.9460573362581161e-05, + -1.1235567269471365e-05, -1.0528648823582079e-04, 6.0787182324981514e-05, + -1.0361506757951987e-05, 1.3403391313090323e-04, 5.9822187159136922e-06, + -7.7384515826665673e-05, 1.3190612774451854e-05, -7.6156038361059896e-06, + -1.2955898186391113e-04, 7.4800913055062928e-05, -3.6522239721294407e-06, + 1.6493376891421133e-04, 2.1086124934497494e-06, -9.5224555881079430e-05, + 4.6494272799617046e-06, -2.6843480916634906e-06 }; return sol; } -static const double * -get_sol_3x_bias_p1_NxDx_DyDy(void) +static const double *get_sol_3x_bias_p1_NxDx_DyDy(void) { static const double sol[512] = { - -6.9079330390640719e-04, 1.9369084511107887e-05, -3.9882969996474807e-04, 8.7940752169279673e-04, 1.1182746156434002e-05, -2.4657619741025694e-05, - 5.0772616937669475e-04, -1.4236083395045803e-05, -1.7637269696839362e-03, 4.9468484637509975e-05, -2.2062884079452052e-04, 2.2452950174552027e-03, - 6.1951506089905610e-06, -6.2975360691778988e-05, 2.8086934398447404e-04, -7.8866746576099621e-06, -2.2508116665430774e-03, 6.3151521941853120e-05, - -6.0589640055252084e-05, 2.8653733298781795e-03, 1.7047546620036724e-06, -8.0394414780744964e-05, 7.7133036611580502e-05, -2.1702209096831959e-06, - -2.2340461539592654e-03, 6.2692883129640016e-05, 7.0269213258618177e-05, 2.8440301613965775e-03, -1.9695499036957175e-06, -7.9810549217891811e-05, - -8.9455520679792837e-05, 2.5073158495670495e-06, -1.8339090424507008e-03, 5.1471540987781308e-05, 1.6075005578361081e-04, 2.3346396048014796e-03, - -4.5090950025754014e-06, -6.5525331588775718e-05, -2.0464125429304049e-04, 5.7402583940354860e-06, -1.2100112667458984e-03, 3.3972790274496971e-05, - 1.9945749296636572e-04, 1.5403927676947125e-03, -5.5938134322214671e-06, -4.3248721623873019e-05, -2.5391737091356016e-04, 7.1211483658333825e-06, - -5.6182935935283765e-04, 1.5794234573048036e-05, 1.7477050575086299e-04, 7.1523125908827686e-04, -4.9015805954886396e-06, -2.0106692702968323e-05, - -2.2248984820528309e-04, 6.2399082612450707e-06, -1.2955898186394569e-04, 3.6522239721253135e-06, 7.4800913055049985e-05, 1.6493376891422626e-04, - -2.1086124934573583e-06, -4.6494272799621899e-06, -9.5224555881080460e-05, 2.6843480916630107e-06, -5.6185672699473244e-04, 5.5072482877236356e-05, - -3.2438813257639447e-04, 7.1526609919165174e-04, 3.1796112814129558e-05, -7.0109474725178509e-05, 4.1295907491049807e-04, -4.0477724105331453e-05, - -1.4344421799160239e-03, 1.4064417737504346e-04, -1.7939931355866488e-04, 1.8261023019737433e-03, 1.7608728039191811e-05, -1.7904566643377166e-04, - 2.2838250579132406e-04, -2.2416615502117464e-05, -1.8304802004778312e-03, 1.7952696313978692e-04, -4.9253344222021144e-05, 2.3302745517463975e-03, - 4.8402587889253895e-06, -2.2854500881667913e-04, 6.2701478332856839e-05, -6.1618431473636253e-06, -1.8168031392970061e-03, 1.7820248370310613e-04, - 5.7149799176493609e-05, 2.3128631055018408e-03, -5.6049473482291162e-06, -2.2685889348759538e-04, -7.2753981509132270e-05, 7.1353222864948475e-06, - -1.4913852692680716e-03, 1.4628465166305601e-04, 1.3073029568382662e-04, 1.8985931336037672e-03, -1.2822821572042982e-05, -1.8622621593640965e-04, - -1.6642489828339919e-04, 1.6323965035577511e-05, -9.8397636034453667e-04, 9.6528523782581091e-05, 1.6222237447239060e-04, 1.2526412858398577e-03, - -1.5903892253582650e-05, -1.2288467388474103e-04, -2.0651557490663017e-04, 2.0246291318839398e-05, -4.5678597105276139e-04, 4.4852593938591367e-05, - 1.4215113869939943e-04, 5.8150682190455003e-04, -1.3931219752469052e-05, -5.7099147102287596e-05, -1.8096408850885493e-04, 1.7735000277791423e-05, - -1.0528648823579432e-04, 1.0361506757991369e-05, 6.0787182324990825e-05, 1.3403391313092093e-04, -5.9822187158932228e-06, -1.3190612774449762e-05, - -7.7384515826664616e-05, 7.6156038361076735e-06, -3.2502275688907800e-04, 8.1663673516511111e-05, -1.8765197618261133e-04, 4.1376697705841322e-04, - 4.7148543887775912e-05, -1.0396112459888250e-04, 2.3888847558642490e-04, -6.0021983272421675e-05, -8.2967964857650755e-04, 2.0851563288962598e-04, - -1.0371181608152599e-04, 1.0562153967439828e-03, 2.6089469003523400e-05, -2.6544874554619845e-04, 1.3202929245948819e-04, -3.3212938152303442e-05, - -1.0586408004009799e-03, 2.6609472226574263e-04, -2.8478966558299951e-05, 1.3476921061319647e-03, 7.1538337474710669e-06, -3.3874923065981428e-04, - 3.6254864168169568e-05, -9.1071166597727990e-06, -1.0507771170939024e-03, 2.6406284642211417e-04, 3.3019066232463053e-05, 1.3376813225743620e-03, - -8.3269378127498438e-06, -3.3616257139440362e-04, -4.2034592749950561e-05, 1.0600525082959492e-05, -8.6268379122426443e-04, 2.1669631592545168e-04, - 7.5576666091144490e-05, 1.0982309911733842e-03, -1.9020141320076871e-05, -2.7586308244495760e-04, -9.6212120541949218e-05, 2.4213401094000003e-05, - -5.6925297375806660e-04, 1.4291213510235064e-04, 9.3835695361496762e-05, 7.2468181732211192e-04, -2.3579175340076520e-05, -1.8193286738519131e-04, - -1.1945659553664515e-04, 3.0017233855795525e-05, -2.6422489214978181e-04, 6.6322596801488701e-05, 8.2272349665441635e-05, 3.3636886209089366e-04, - -2.0639815215035295e-05, -8.4431319984722521e-05, -1.0473599369591775e-04, 2.6275310782270177e-05, -6.0862501235539220e-05, 1.5286694095082349e-05, - 3.5138981471942260e-05, 7.7480399814187993e-05, -8.8257769508439589e-06, -1.9460573362585078e-05, -4.4733329689626524e-05, 1.1235567269471844e-05, - -2.2431527514113289e-05, 9.3037454217544569e-05, -1.2950848448533081e-05, 2.8556232243984154e-05, 5.3715199237225361e-05, -1.1844040261446435e-04, - 1.6486948373042730e-05, -6.8381598332408421e-05, -5.7211901773897239e-05, 2.3746882866716487e-04, -7.1296099928691076e-06, 7.2833040600977603e-05, - 2.9672293680690542e-05, -3.0230732248929393e-04, 9.0762788507249009e-06, -3.7774017352391789e-05, -7.3130563309168069e-05, 3.0288987840834702e-04, - -2.0610335296580487e-06, 9.3098133806489877e-05, 8.0985669980488566e-06, -3.8559093698598045e-04, 2.6237781666304576e-06, -1.0309799896355221e-05, - -7.3041740691809096e-05, 3.0043293633985466e-04, 2.1123152917003706e-06, 9.2985059059884443e-05, -9.5170831626762140e-06, -3.8246315140500132e-04, - -2.6890619020216670e-06, 1.2115627743500962e-05, -6.0575372069963200e-05, 2.4640119579254937e-04, 5.0851459879394492e-06, 7.7114872895303545e-05, - -2.1678156787094499e-05, -3.1367858331675787e-04, -6.4735943521885902e-06, 2.7597161158338549e-05, -4.0541836830664609e-05, 1.6233938212623799e-04, - 6.4812209752894441e-06, 5.1611380785719807e-05, -2.6854953961718529e-05, -2.0666453033267354e-04, -8.2508536825550670e-06, 3.4187431139095416e-05, - -1.9172276725473528e-05, 7.5158596679357562e-05, 5.8565003039065181e-06, 2.4407075553617848e-05, -2.3478895984200893e-05, -9.5679901449450205e-05, - -7.4555592663157456e-06, 2.9889574222544275e-05, -4.5142603222569322e-06, 1.7245977964563073e-05, 2.6063094122765399e-06, 5.7468340527402128e-06, - -9.9569700202618558e-06, -2.1954820139718512e-05, -3.3179361873593818e-06, 1.2675621317656365e-05, 2.8251817425973917e-04, 8.3025338190885302e-05, - 1.6311194395986483e-04, -3.5965694232120829e-04, 4.7934701354040375e-05, -1.0569457822370867e-04, -2.0764803246510629e-04, -6.1022793189308512e-05, - 7.2082558778287632e-04, 2.1173132536805907e-04, 8.9944959225527071e-05, -9.1763982097136667e-04, 2.6373734989017391e-05, -2.6954245076451784e-04, - -1.1450353272676479e-04, -3.3574820128275134e-05, 9.1873938193643518e-04, 2.6976650148030157e-04, 2.4320623105370497e-05, -1.1695920015167823e-03, - 7.1328895618531744e-06, -3.4342355254599554e-04, -3.0961126534044084e-05, -9.0804538732871234e-06, 9.1036543165673597e-04, 2.6733745933858662e-04, - -2.9155325553535425e-05, -1.1589316276819316e-03, -8.5352976962452274e-06, -3.4033128468837051e-04, 3.7115896237257009e-05, 1.0865775553293366e-05, - 7.4559480183160993e-04, 2.1904137112217147e-04, -6.5975041930545168e-05, -9.4917202172907879e-04, -1.9348461836308022e-05, -2.7884843156041446e-04, - 8.3988868724732270e-05, 2.4631366250678289e-05, 4.9013450248756711e-04, 1.4404674523170834e-04, -8.1515030663000454e-05, -6.2396083704237433e-04, - -2.3949705609326177e-05, -1.8337727148740908e-04, 1.0377189629761366e-04, 3.0488933717317135e-05, 2.2595287291714611e-04, 6.6364474451956215e-05, - -7.1010304284436148e-05, -2.8764704994642436e-04, -2.0900174336625099e-05, -8.4484631909732398e-05, 9.0398959214415590e-05, 2.6606758363727161e-05, - 5.1479709017806705e-05, 1.5082155306918322e-05, -2.9721823859213156e-05, -6.5535729817872018e-05, -8.7076864264308121e-06, -1.9200187299506148e-05, - 3.7837071251867237e-05, 1.1085233305882173e-05, 5.0481002617914204e-04, 4.5314922353442369e-05, 2.9145220450415503e-04, -6.4264336602200712e-04, - 2.6162582619072271e-05, -5.7687709676956983e-05, -3.7103032036573172e-04, -3.3306014710934500e-05, 1.2870709745400660e-03, 1.1519060110358824e-04, - 1.6018636460855650e-04, -1.6384928596765208e-03, 1.4180159317132296e-05, -1.4664224517806261e-04, -2.0392365286805419e-04, -1.8051910306266937e-05, - 1.6392548325407947e-03, 1.4622328788140983e-04, 4.3147080612405137e-05, -2.0868370054480650e-03, 3.7365707477203691e-06, -1.8614809738656999e-04, - -5.4927960382739824e-05, -4.7568041008804086e-06, 1.6238014988128394e-03, 1.4456504608357777e-04, -5.2069067000117178e-05, -2.0671642931638762e-03, - -4.6939570960801832e-06, -1.8403708921444116e-04, 6.6286006115706569e-05, 5.9755952373204787e-06, 1.3297080252287802e-03, 1.1819655564340479e-04, - -1.1772587914055171e-04, -1.6927715315547928e-03, -1.0529897957677752e-05, -1.5046894560673534e-04, 1.4986975558194465e-04, 1.3404981510784509e-05, - 8.7363231171247240e-04, 7.7365818157922530e-05, -1.4558955682893938e-04, -1.1121688959189588e-03, -1.3043739320776373e-05, -9.8489782725531469e-05, - 1.8534133239461051e-04, 1.6605202170929968e-05, 4.0170043536067303e-04, 3.5103428034234649e-05, -1.2688043902193719e-04, -5.1138073042366749e-04, - -1.1356462993731803e-05, -4.4688068740589646e-05, 1.6152387668003727e-04, 1.4457231881139441e-05, 9.0968534244010386e-05, 7.7167285674124671e-06, - -5.2520707733572158e-05, -1.1580658468916999e-04, -4.4552553156533683e-06, -9.8237042928303434e-06, 6.6860962844231083e-05, 5.6717183178996131e-06, - 5.3693018033442353e-04, -2.6770342705478280e-05, 3.0999678415212110e-04, -6.8353360772288336e-04, -1.5455864567310600e-05, 3.4079717623727183e-05, - -3.9463831241897117e-04, 1.9675934143970172e-05, 1.3669669930980236e-03, -6.9062613281972092e-05, 1.6922519313424257e-04, -1.7402036887709063e-03, - -8.9615892346685745e-06, 8.7919470620919008e-05, -2.1543044331872856e-04, 1.1408461742061493e-05, 1.7385437019493595e-03, -8.8898832400841277e-05, - 4.5304719745671474e-05, -2.2132357097848017e-03, -2.4908572133149280e-06, 1.1317177141253521e-04, -5.7674721348956699e-05, 3.1709609176355087e-06, - 1.7210227955432816e-03, -8.8434304245292331e-05, -5.5420419775666512e-05, -2.1909308947362927e-03, 2.7590526689673258e-06, 1.1258040847992115e-04, - 7.0552412321438289e-05, -3.5123844659690170e-06, 1.4085793923499720e-03, -7.2660150604630884e-05, -1.2496886316451367e-04, -1.7931779383632289e-03, - 6.3481591817070960e-06, 9.2499279607521838e-05, 1.5909036411151944e-04, -8.0814606941423358e-06, 9.2429031121327957e-04, -4.8118408509523615e-05, - -1.5463556819535234e-04, -1.1766585566365692e-03, 7.8210222232854560e-06, 6.1256659750271475e-05, 1.9685726688898922e-04, -9.9564742906303086e-06, - 4.2273028355950131e-04, -2.2961839515624145e-05, -1.3494024878531275e-04, -5.3815256880358276e-04, 6.7031296572297566e-06, 2.9231340645244466e-05, - 1.7178433706557334e-04, -8.5333523155407037e-06, 9.4503458338678696e-05, -5.6758391897908312e-06, -5.4561597111185503e-05, -1.2030668453073674e-04, - 3.2769472841020526e-06, 7.2255704379215940e-06, 6.9459096699131477e-05, -4.1716850373821949e-06, 2.4528129331627364e-04, -1.4161322072330534e-04, - 1.4161322072332695e-04, -3.1225290264551026e-04, -8.1760431105412073e-05, 1.8027929739760823e-04, -1.8027929739762065e-04, 1.0408430088182956e-04, - 6.2367351899509228e-04, -3.6007807407824750e-04, 7.6851632631600670e-05, -7.9396134934046816e-04, -4.4370310787535901e-05, 4.5839379876786568e-04, - -9.7835203972629722e-05, 5.6485181349827101e-05, 7.9228320374876609e-04, -4.5742492095878081e-04, 2.0495214248910872e-05, -1.0086082258578591e-03, - -1.1832917463701227e-05, 5.8232023070590674e-04, -2.6091227965398181e-05, 1.5063777489310737e-05, 7.8392504372921544e-04, -4.5259933502155209e-04, - -2.5320800186128338e-05, -9.9796795365610460e-04, 1.4618970803557920e-05, 5.7617706668597292e-04, 3.2234391985331892e-05, -1.8610534889895576e-05, - 6.4136415990857201e-04, -3.7029177037179280e-04, -5.6986764463631171e-05, -8.1648224320974032e-04, 3.2901323803323126e-05, 4.7139624290569340e-04, - 7.2546431794947067e-05, -4.1884701925559473e-05, 4.2047339144771472e-04, -2.4276042573941338e-04, -7.0544580168748093e-05, -5.3527945482356937e-04, - 4.0728932350296049e-05, 3.0904373733406420e-04, 8.9806073776681975e-05, -5.1849560869830896e-05, 1.9147960544159881e-04, -1.1055080174603042e-04, - -6.1665043824634527e-05, -2.4376120081633304e-04, 3.5602329651742815e-05, 1.4073559490929629e-04, 7.8502068648085658e-05, -4.5323190465914727e-05, - 4.2336308243185197e-05, -2.4442878960697954e-05, -2.4442878960697954e-05, -5.3895814709294411e-05, 1.4112102747728401e-05, 3.1116763130605317e-05, - 3.1116763130605317e-05, -1.7965271569764799e-05, + -6.9079330390640719e-04, 1.9369084511107887e-05, -3.9882969996474807e-04, + 8.7940752169279673e-04, 1.1182746156434002e-05, -2.4657619741025694e-05, + 5.0772616937669475e-04, -1.4236083395045803e-05, -1.7637269696839362e-03, + 4.9468484637509975e-05, -2.2062884079452052e-04, 2.2452950174552027e-03, + 6.1951506089905610e-06, -6.2975360691778988e-05, 2.8086934398447404e-04, + -7.8866746576099621e-06, -2.2508116665430774e-03, 6.3151521941853120e-05, + -6.0589640055252084e-05, 2.8653733298781795e-03, 1.7047546620036724e-06, + -8.0394414780744964e-05, 7.7133036611580502e-05, -2.1702209096831959e-06, + -2.2340461539592654e-03, 6.2692883129640016e-05, 7.0269213258618177e-05, + 2.8440301613965775e-03, -1.9695499036957175e-06, -7.9810549217891811e-05, + -8.9455520679792837e-05, 2.5073158495670495e-06, -1.8339090424507008e-03, + 5.1471540987781308e-05, 1.6075005578361081e-04, 2.3346396048014796e-03, + -4.5090950025754014e-06, -6.5525331588775718e-05, -2.0464125429304049e-04, + 5.7402583940354860e-06, -1.2100112667458984e-03, 3.3972790274496971e-05, + 1.9945749296636572e-04, 1.5403927676947125e-03, -5.5938134322214671e-06, + -4.3248721623873019e-05, -2.5391737091356016e-04, 7.1211483658333825e-06, + -5.6182935935283765e-04, 1.5794234573048036e-05, 1.7477050575086299e-04, + 7.1523125908827686e-04, -4.9015805954886396e-06, -2.0106692702968323e-05, + -2.2248984820528309e-04, 6.2399082612450707e-06, -1.2955898186394569e-04, + 3.6522239721253135e-06, 7.4800913055049985e-05, 1.6493376891422626e-04, + -2.1086124934573583e-06, -4.6494272799621899e-06, -9.5224555881080460e-05, + 2.6843480916630107e-06, -5.6185672699473244e-04, 5.5072482877236356e-05, + -3.2438813257639447e-04, 7.1526609919165174e-04, 3.1796112814129558e-05, + -7.0109474725178509e-05, 4.1295907491049807e-04, -4.0477724105331453e-05, + -1.4344421799160239e-03, 1.4064417737504346e-04, -1.7939931355866488e-04, + 1.8261023019737433e-03, 1.7608728039191811e-05, -1.7904566643377166e-04, + 2.2838250579132406e-04, -2.2416615502117464e-05, -1.8304802004778312e-03, + 1.7952696313978692e-04, -4.9253344222021144e-05, 2.3302745517463975e-03, + 4.8402587889253895e-06, -2.2854500881667913e-04, 6.2701478332856839e-05, + -6.1618431473636253e-06, -1.8168031392970061e-03, 1.7820248370310613e-04, + 5.7149799176493609e-05, 2.3128631055018408e-03, -5.6049473482291162e-06, + -2.2685889348759538e-04, -7.2753981509132270e-05, 7.1353222864948475e-06, + -1.4913852692680716e-03, 1.4628465166305601e-04, 1.3073029568382662e-04, + 1.8985931336037672e-03, -1.2822821572042982e-05, -1.8622621593640965e-04, + -1.6642489828339919e-04, 1.6323965035577511e-05, -9.8397636034453667e-04, + 9.6528523782581091e-05, 1.6222237447239060e-04, 1.2526412858398577e-03, + -1.5903892253582650e-05, -1.2288467388474103e-04, -2.0651557490663017e-04, + 2.0246291318839398e-05, -4.5678597105276139e-04, 4.4852593938591367e-05, + 1.4215113869939943e-04, 5.8150682190455003e-04, -1.3931219752469052e-05, + -5.7099147102287596e-05, -1.8096408850885493e-04, 1.7735000277791423e-05, + -1.0528648823579432e-04, 1.0361506757991369e-05, 6.0787182324990825e-05, + 1.3403391313092093e-04, -5.9822187158932228e-06, -1.3190612774449762e-05, + -7.7384515826664616e-05, 7.6156038361076735e-06, -3.2502275688907800e-04, + 8.1663673516511111e-05, -1.8765197618261133e-04, 4.1376697705841322e-04, + 4.7148543887775912e-05, -1.0396112459888250e-04, 2.3888847558642490e-04, + -6.0021983272421675e-05, -8.2967964857650755e-04, 2.0851563288962598e-04, + -1.0371181608152599e-04, 1.0562153967439828e-03, 2.6089469003523400e-05, + -2.6544874554619845e-04, 1.3202929245948819e-04, -3.3212938152303442e-05, + -1.0586408004009799e-03, 2.6609472226574263e-04, -2.8478966558299951e-05, + 1.3476921061319647e-03, 7.1538337474710669e-06, -3.3874923065981428e-04, + 3.6254864168169568e-05, -9.1071166597727990e-06, -1.0507771170939024e-03, + 2.6406284642211417e-04, 3.3019066232463053e-05, 1.3376813225743620e-03, + -8.3269378127498438e-06, -3.3616257139440362e-04, -4.2034592749950561e-05, + 1.0600525082959492e-05, -8.6268379122426443e-04, 2.1669631592545168e-04, + 7.5576666091144490e-05, 1.0982309911733842e-03, -1.9020141320076871e-05, + -2.7586308244495760e-04, -9.6212120541949218e-05, 2.4213401094000003e-05, + -5.6925297375806660e-04, 1.4291213510235064e-04, 9.3835695361496762e-05, + 7.2468181732211192e-04, -2.3579175340076520e-05, -1.8193286738519131e-04, + -1.1945659553664515e-04, 3.0017233855795525e-05, -2.6422489214978181e-04, + 6.6322596801488701e-05, 8.2272349665441635e-05, 3.3636886209089366e-04, + -2.0639815215035295e-05, -8.4431319984722521e-05, -1.0473599369591775e-04, + 2.6275310782270177e-05, -6.0862501235539220e-05, 1.5286694095082349e-05, + 3.5138981471942260e-05, 7.7480399814187993e-05, -8.8257769508439589e-06, + -1.9460573362585078e-05, -4.4733329689626524e-05, 1.1235567269471844e-05, + -2.2431527514113289e-05, 9.3037454217544569e-05, -1.2950848448533081e-05, + 2.8556232243984154e-05, 5.3715199237225361e-05, -1.1844040261446435e-04, + 1.6486948373042730e-05, -6.8381598332408421e-05, -5.7211901773897239e-05, + 2.3746882866716487e-04, -7.1296099928691076e-06, 7.2833040600977603e-05, + 2.9672293680690542e-05, -3.0230732248929393e-04, 9.0762788507249009e-06, + -3.7774017352391789e-05, -7.3130563309168069e-05, 3.0288987840834702e-04, + -2.0610335296580487e-06, 9.3098133806489877e-05, 8.0985669980488566e-06, + -3.8559093698598045e-04, 2.6237781666304576e-06, -1.0309799896355221e-05, + -7.3041740691809096e-05, 3.0043293633985466e-04, 2.1123152917003706e-06, + 9.2985059059884443e-05, -9.5170831626762140e-06, -3.8246315140500132e-04, + -2.6890619020216670e-06, 1.2115627743500962e-05, -6.0575372069963200e-05, + 2.4640119579254937e-04, 5.0851459879394492e-06, 7.7114872895303545e-05, + -2.1678156787094499e-05, -3.1367858331675787e-04, -6.4735943521885902e-06, + 2.7597161158338549e-05, -4.0541836830664609e-05, 1.6233938212623799e-04, + 6.4812209752894441e-06, 5.1611380785719807e-05, -2.6854953961718529e-05, + -2.0666453033267354e-04, -8.2508536825550670e-06, 3.4187431139095416e-05, + -1.9172276725473528e-05, 7.5158596679357562e-05, 5.8565003039065181e-06, + 2.4407075553617848e-05, -2.3478895984200893e-05, -9.5679901449450205e-05, + -7.4555592663157456e-06, 2.9889574222544275e-05, -4.5142603222569322e-06, + 1.7245977964563073e-05, 2.6063094122765399e-06, 5.7468340527402128e-06, + -9.9569700202618558e-06, -2.1954820139718512e-05, -3.3179361873593818e-06, + 1.2675621317656365e-05, 2.8251817425973917e-04, 8.3025338190885302e-05, + 1.6311194395986483e-04, -3.5965694232120829e-04, 4.7934701354040375e-05, + -1.0569457822370867e-04, -2.0764803246510629e-04, -6.1022793189308512e-05, + 7.2082558778287632e-04, 2.1173132536805907e-04, 8.9944959225527071e-05, + -9.1763982097136667e-04, 2.6373734989017391e-05, -2.6954245076451784e-04, + -1.1450353272676479e-04, -3.3574820128275134e-05, 9.1873938193643518e-04, + 2.6976650148030157e-04, 2.4320623105370497e-05, -1.1695920015167823e-03, + 7.1328895618531744e-06, -3.4342355254599554e-04, -3.0961126534044084e-05, + -9.0804538732871234e-06, 9.1036543165673597e-04, 2.6733745933858662e-04, + -2.9155325553535425e-05, -1.1589316276819316e-03, -8.5352976962452274e-06, + -3.4033128468837051e-04, 3.7115896237257009e-05, 1.0865775553293366e-05, + 7.4559480183160993e-04, 2.1904137112217147e-04, -6.5975041930545168e-05, + -9.4917202172907879e-04, -1.9348461836308022e-05, -2.7884843156041446e-04, + 8.3988868724732270e-05, 2.4631366250678289e-05, 4.9013450248756711e-04, + 1.4404674523170834e-04, -8.1515030663000454e-05, -6.2396083704237433e-04, + -2.3949705609326177e-05, -1.8337727148740908e-04, 1.0377189629761366e-04, + 3.0488933717317135e-05, 2.2595287291714611e-04, 6.6364474451956215e-05, + -7.1010304284436148e-05, -2.8764704994642436e-04, -2.0900174336625099e-05, + -8.4484631909732398e-05, 9.0398959214415590e-05, 2.6606758363727161e-05, + 5.1479709017806705e-05, 1.5082155306918322e-05, -2.9721823859213156e-05, + -6.5535729817872018e-05, -8.7076864264308121e-06, -1.9200187299506148e-05, + 3.7837071251867237e-05, 1.1085233305882173e-05, 5.0481002617914204e-04, + 4.5314922353442369e-05, 2.9145220450415503e-04, -6.4264336602200712e-04, + 2.6162582619072271e-05, -5.7687709676956983e-05, -3.7103032036573172e-04, + -3.3306014710934500e-05, 1.2870709745400660e-03, 1.1519060110358824e-04, + 1.6018636460855650e-04, -1.6384928596765208e-03, 1.4180159317132296e-05, + -1.4664224517806261e-04, -2.0392365286805419e-04, -1.8051910306266937e-05, + 1.6392548325407947e-03, 1.4622328788140983e-04, 4.3147080612405137e-05, + -2.0868370054480650e-03, 3.7365707477203691e-06, -1.8614809738656999e-04, + -5.4927960382739824e-05, -4.7568041008804086e-06, 1.6238014988128394e-03, + 1.4456504608357777e-04, -5.2069067000117178e-05, -2.0671642931638762e-03, + -4.6939570960801832e-06, -1.8403708921444116e-04, 6.6286006115706569e-05, + 5.9755952373204787e-06, 1.3297080252287802e-03, 1.1819655564340479e-04, + -1.1772587914055171e-04, -1.6927715315547928e-03, -1.0529897957677752e-05, + -1.5046894560673534e-04, 1.4986975558194465e-04, 1.3404981510784509e-05, + 8.7363231171247240e-04, 7.7365818157922530e-05, -1.4558955682893938e-04, + -1.1121688959189588e-03, -1.3043739320776373e-05, -9.8489782725531469e-05, + 1.8534133239461051e-04, 1.6605202170929968e-05, 4.0170043536067303e-04, + 3.5103428034234649e-05, -1.2688043902193719e-04, -5.1138073042366749e-04, + -1.1356462993731803e-05, -4.4688068740589646e-05, 1.6152387668003727e-04, + 1.4457231881139441e-05, 9.0968534244010386e-05, 7.7167285674124671e-06, + -5.2520707733572158e-05, -1.1580658468916999e-04, -4.4552553156533683e-06, + -9.8237042928303434e-06, 6.6860962844231083e-05, 5.6717183178996131e-06, + 5.3693018033442353e-04, -2.6770342705478280e-05, 3.0999678415212110e-04, + -6.8353360772288336e-04, -1.5455864567310600e-05, 3.4079717623727183e-05, + -3.9463831241897117e-04, 1.9675934143970172e-05, 1.3669669930980236e-03, + -6.9062613281972092e-05, 1.6922519313424257e-04, -1.7402036887709063e-03, + -8.9615892346685745e-06, 8.7919470620919008e-05, -2.1543044331872856e-04, + 1.1408461742061493e-05, 1.7385437019493595e-03, -8.8898832400841277e-05, + 4.5304719745671474e-05, -2.2132357097848017e-03, -2.4908572133149280e-06, + 1.1317177141253521e-04, -5.7674721348956699e-05, 3.1709609176355087e-06, + 1.7210227955432816e-03, -8.8434304245292331e-05, -5.5420419775666512e-05, + -2.1909308947362927e-03, 2.7590526689673258e-06, 1.1258040847992115e-04, + 7.0552412321438289e-05, -3.5123844659690170e-06, 1.4085793923499720e-03, + -7.2660150604630884e-05, -1.2496886316451367e-04, -1.7931779383632289e-03, + 6.3481591817070960e-06, 9.2499279607521838e-05, 1.5909036411151944e-04, + -8.0814606941423358e-06, 9.2429031121327957e-04, -4.8118408509523615e-05, + -1.5463556819535234e-04, -1.1766585566365692e-03, 7.8210222232854560e-06, + 6.1256659750271475e-05, 1.9685726688898922e-04, -9.9564742906303086e-06, + 4.2273028355950131e-04, -2.2961839515624145e-05, -1.3494024878531275e-04, + -5.3815256880358276e-04, 6.7031296572297566e-06, 2.9231340645244466e-05, + 1.7178433706557334e-04, -8.5333523155407037e-06, 9.4503458338678696e-05, + -5.6758391897908312e-06, -5.4561597111185503e-05, -1.2030668453073674e-04, + 3.2769472841020526e-06, 7.2255704379215940e-06, 6.9459096699131477e-05, + -4.1716850373821949e-06, 2.4528129331627364e-04, -1.4161322072330534e-04, + 1.4161322072332695e-04, -3.1225290264551026e-04, -8.1760431105412073e-05, + 1.8027929739760823e-04, -1.8027929739762065e-04, 1.0408430088182956e-04, + 6.2367351899509228e-04, -3.6007807407824750e-04, 7.6851632631600670e-05, + -7.9396134934046816e-04, -4.4370310787535901e-05, 4.5839379876786568e-04, + -9.7835203972629722e-05, 5.6485181349827101e-05, 7.9228320374876609e-04, + -4.5742492095878081e-04, 2.0495214248910872e-05, -1.0086082258578591e-03, + -1.1832917463701227e-05, 5.8232023070590674e-04, -2.6091227965398181e-05, + 1.5063777489310737e-05, 7.8392504372921544e-04, -4.5259933502155209e-04, + -2.5320800186128338e-05, -9.9796795365610460e-04, 1.4618970803557920e-05, + 5.7617706668597292e-04, 3.2234391985331892e-05, -1.8610534889895576e-05, + 6.4136415990857201e-04, -3.7029177037179280e-04, -5.6986764463631171e-05, + -8.1648224320974032e-04, 3.2901323803323126e-05, 4.7139624290569340e-04, + 7.2546431794947067e-05, -4.1884701925559473e-05, 4.2047339144771472e-04, + -2.4276042573941338e-04, -7.0544580168748093e-05, -5.3527945482356937e-04, + 4.0728932350296049e-05, 3.0904373733406420e-04, 8.9806073776681975e-05, + -5.1849560869830896e-05, 1.9147960544159881e-04, -1.1055080174603042e-04, + -6.1665043824634527e-05, -2.4376120081633304e-04, 3.5602329651742815e-05, + 1.4073559490929629e-04, 7.8502068648085658e-05, -4.5323190465914727e-05, + 4.2336308243185197e-05, -2.4442878960697954e-05, -2.4442878960697954e-05, + -5.3895814709294411e-05, 1.4112102747728401e-05, 3.1116763130605317e-05, + 3.1116763130605317e-05, -1.7965271569764799e-05 }; return sol; } -static const double * -get_sol_3x_bias_p1_DxNx_DyDy(void) +static const double *get_sol_3x_bias_p1_DxNx_DyDy(void) { static const double sol[512] = { - 2.4528129331641009e-04, 1.4161322072339013e-04, 1.4161322072323059e-04, -3.1225290264558366e-04, 8.1760431105386229e-05, -1.8027929739766388e-04, - -1.8027929739757061e-04, -1.0408430088180949e-04, 6.2367351899508393e-04, 3.6007807407826723e-04, 7.6851632631613504e-05, -7.9396134934045298e-04, - 4.4370310787524178e-05, -4.5839379876787668e-04, -9.7835203972628665e-05, -5.6485181349821416e-05, 7.9228320374878549e-04, 4.5742492095878005e-04, - 2.0495214248914016e-05, -1.0086082258578244e-03, 1.1832917463701158e-05, -5.8232023070591693e-04, -2.6091227965387976e-05, -1.5063777489315933e-05, - 7.8392504372923799e-04, 4.5259933502155545e-04, -2.5320800186129666e-05, -9.9796795365606730e-04, -1.4618970803555413e-05, -5.7617706668598300e-04, - 3.2234391985323307e-05, 1.8610534889900770e-05, 6.4136415990862026e-04, 3.7029177037178126e-04, -5.6986764463615016e-05, -8.1648224320972546e-04, - -3.2901323803334279e-05, -4.7139624290569432e-04, 7.2546431794942595e-05, 4.1884701925559656e-05, 4.2047339144775083e-04, 2.4276042573940094e-04, - -7.0544580168771268e-05, -5.3527945482357338e-04, -4.0728932350285410e-05, -3.0904373733406024e-04, 8.9806073776675660e-05, 5.1849560869833525e-05, - 1.9147960544158748e-04, 1.1055080174602805e-04, -6.1665043824638729e-05, -2.4376120081634332e-04, -3.5602329651747633e-05, -1.4073559490929369e-04, - 7.8502068648088301e-05, 4.5323190465911326e-05, 4.2336308243161155e-05, 2.4442878960684070e-05, -2.4442878960701085e-05, -5.3895814709309427e-05, - -1.4112102747730210e-05, -3.1116763130613984e-05, 3.1116763130599923e-05, 1.7965271569761685e-05, 5.3693018033450050e-04, 2.6770342705359106e-05, - 3.0999678415209730e-04, -6.8353360772295210e-04, 1.5455864567378393e-05, -3.4079717623668880e-05, -3.9463831241894352e-04, -1.9675934144003216e-05, - 1.3669669930980539e-03, 6.9062613281974694e-05, 1.6922519313423946e-04, -1.7402036887709158e-03, 8.9615892346710530e-06, -8.7919470620922207e-05, - -2.1543044331872175e-04, -1.1408461742063897e-05, 1.7385437019493855e-03, 8.8898832400845966e-05, 4.5304719745672186e-05, -2.2132357097847956e-03, - 2.4908572133136756e-06, -1.1317177141254158e-04, -5.7674721348954423e-05, -3.1709609176349484e-06, 1.7210227955433098e-03, 8.8434304245292155e-05, - -5.5420419775666248e-05, -2.1909308947362814e-03, -2.7590526689688848e-06, -1.1258040847992607e-04, 7.0552412321439102e-05, 3.5123844659692677e-06, - 1.4085793923499944e-03, 7.2660150604627523e-05, -1.2496886316451722e-04, -1.7931779383632191e-03, -6.3481591817073264e-06, -9.2499279607523736e-05, - 1.5909036411151779e-04, 8.0814606941438113e-06, 9.2429031121328542e-04, 4.8118408509518702e-05, -1.5463556819535819e-04, -1.1766585566365631e-03, - -7.8210222232860947e-06, -6.1256659750269686e-05, 1.9685726688898863e-04, 9.9564742906309574e-06, 4.2273028355947908e-04, 2.2961839515620249e-05, - -1.3494024878532319e-04, -5.3815256880358146e-04, -6.7031296572285555e-06, -2.9231340645240418e-05, 1.7178433706557119e-04, 8.5333523155413458e-06, - 9.4503458338600580e-05, 5.6758391897734915e-06, -5.4561597111207316e-05, -1.2030668453075738e-04, -3.2769472841110353e-06, -7.2255704379161823e-06, - 6.9459096699120947e-05, 4.1716850373823499e-06, 5.0481002617904804e-04, -4.5314922353421830e-05, 2.9145220450423634e-04, -6.4264336602196082e-04, - -2.6162582619079407e-05, 5.7687709676965182e-05, -3.7103032036577476e-04, 3.3306014710926822e-05, 1.2870709745401126e-03, -1.1519060110358146e-04, - 1.6018636460855631e-04, -1.6384928596765438e-03, -1.4180159317133011e-05, 1.4664224517805789e-04, -2.0392365286805118e-04, 1.8051910306267174e-05, - 1.6392548325408359e-03, -1.4622328788140585e-04, 4.3147080612402216e-05, -2.0868370054480776e-03, -3.7365707477212382e-06, 1.8614809738656579e-04, - -5.4927960382736503e-05, 4.7568041008804382e-06, 1.6238014988128691e-03, -1.4456504608357661e-04, -5.2069067000120898e-05, -2.0671642931638788e-03, - 4.6939570960793650e-06, 1.8403708921443785e-04, 6.6286006115708751e-05, -5.9755952373199925e-06, 1.3297080252287945e-03, -1.1819655564340603e-04, - -1.1772587914055666e-04, -1.6927715315547887e-03, 1.0529897957677164e-05, 1.5046894560673396e-04, 1.4986975558194660e-04, -1.3404981510783889e-05, - 8.7363231171246579e-04, -7.7365818157924915e-05, -1.4558955682894646e-04, -1.1121688959189475e-03, 1.3043739320776322e-05, 9.8489782725532608e-05, - 1.8534133239461251e-04, -1.6605202170929098e-05, 4.0170043536063898e-04, -3.5103428034237590e-05, -1.2688043902194603e-04, -5.1138073042364775e-04, - 1.1356462993731508e-05, 4.4688068740596321e-05, 1.6152387668004025e-04, -1.4457231881137132e-05, 9.0968534243944562e-05, -7.7167285673880403e-06, - -5.2520707733581692e-05, -1.1580658468914775e-04, 4.4552553156694357e-06, 9.8237042928496913e-06, 6.6860962844229497e-05, -5.6717183178946029e-06, - 2.8251817425989937e-04, -8.3025338190759114e-05, 1.6311194395982403e-04, -3.5965694232128895e-04, -4.7934701354103719e-05, 1.0569457822362715e-04, - -2.0764803246508764e-04, 6.1022793189351798e-05, 7.2082558778295428e-04, -2.1173132536804774e-04, 8.9944959225520430e-05, -9.1763982097140733e-04, - -2.6373734989020383e-05, 2.6954245076451236e-04, -1.1450353272676037e-04, 3.3574820128275771e-05, 9.1873938193649102e-04, -2.6976650148029723e-04, - 2.4320623105364212e-05, -1.1695920015168078e-03, -7.1328895618542281e-06, 3.4342355254599196e-04, -3.0961126534039862e-05, 9.0804538732875994e-06, - 9.1036543165677055e-04, -2.6733745933858483e-04, -2.9155325553541354e-05, -1.1589316276819444e-03, 8.5352976962447920e-06, 3.4033128468836813e-04, - 3.7115896237260282e-05, -1.0865775553293173e-05, 7.4559480183162316e-04, -2.1904137112217098e-04, -6.5975041930551768e-05, -9.4917202172907988e-04, - 1.9348461836307690e-05, 2.7884843156041278e-04, 8.3988868724735793e-05, -2.4631366250678018e-05, 4.9013450248755551e-04, -1.4404674523170886e-04, - -8.1515030663008111e-05, -6.2396083704236186e-04, 2.3949705609325855e-05, 1.8337727148740878e-04, 1.0377189629761795e-04, -3.0488933717316698e-05, - 2.2595287291710662e-04, -6.6364474451956418e-05, -7.1010304284444564e-05, -2.8764704994639070e-04, 2.0900174336625617e-05, 8.4484631909733713e-05, - 9.0398959214423478e-05, -2.6606758363726633e-05, 5.1479709017752949e-05, -1.5082155306935768e-05, -2.9721823859212993e-05, -6.5535729817781379e-05, - 8.7076864264203513e-06, 1.9200187299526287e-05, 3.7837071251892241e-05, -1.1085233305871834e-05, -2.2431527513872884e-05, -9.3037454217624434e-05, - -1.2950848448593547e-05, 2.8556232243847948e-05, -5.3715199237173366e-05, 1.1844040261451382e-04, 1.6486948373078488e-05, 6.8381598332375028e-05, - -5.7211901773788798e-05, -2.3746882866715864e-04, -7.1296099928848429e-06, 7.2833040600918297e-05, -2.9672293680692828e-05, 3.0230732248928867e-04, - 9.0762788507335424e-06, 3.7774017352393571e-05, -7.3130563309101350e-05, -3.0288987840834501e-04, -2.0610335296664254e-06, 9.3098133806454356e-05, - -8.0985669980490108e-06, 3.8559093698597833e-04, 2.6237781666355622e-06, 1.0309799896355250e-05, -7.3041740691768927e-05, -3.0043293633985325e-04, - 2.1123152916934326e-06, 9.2985059059864345e-05, 9.5170831626760479e-06, 3.8246315140499947e-04, -2.6890619020178464e-06, -1.2115627743500844e-05, - -6.0575372069947465e-05, -2.4640119579254834e-04, 5.0851459879323011e-06, 7.7114872895296986e-05, 2.1678156787094434e-05, 3.1367858331675619e-04, - -6.4735943521846032e-06, -2.7597161158338549e-05, -4.0541836830675247e-05, -1.6233938212623694e-04, 6.4812209752813668e-06, 5.1611380785727993e-05, - 2.6854953961718624e-05, 2.0666453033267132e-04, -8.2508536825505439e-06, -3.4187431139095714e-05, -1.9172276725516337e-05, -7.5158596679359270e-05, - 5.8565003038960250e-06, 2.4407075553646800e-05, 2.3478895984199182e-05, 9.5679901449446152e-05, -7.4555592663082866e-06, -2.9889574222545057e-05, - -4.5142603223459884e-06, -1.7245977964566013e-05, 2.6063094122603197e-06, 5.7468340528147339e-06, 9.9569700202628604e-06, 2.1954820139689062e-05, - -3.3179361873405256e-06, -1.2675621317670252e-05, -3.2502275688898297e-04, -8.1663673516515218e-05, -1.8765197618259547e-04, 4.1376697705835895e-04, - -4.7148543887783813e-05, 1.0396112459888037e-04, 2.3888847558641401e-04, 6.0021983272428126e-05, -8.2967964857640498e-04, -2.0851563288963555e-04, - -1.0371181608153745e-04, 1.0562153967439215e-03, -2.6089469003518687e-05, 2.6544874554620268e-04, 1.3202929245949519e-04, 3.3212938152300663e-05, - -1.0586408004009109e-03, -2.6609472226574323e-04, -2.8478966558307740e-05, 1.3476921061319242e-03, -7.1538337474705816e-06, 3.3874923065981352e-04, - 3.6254864168174548e-05, 9.1071166597727244e-06, -1.0507771170938588e-03, -2.6406284642211346e-04, 3.3019066232456236e-05, 1.3376813225743371e-03, - 8.3269378127500487e-06, 3.3616257139440253e-04, -4.2034592749946726e-05, -1.0600525082959604e-05, -8.6268379122424405e-04, -2.1669631592545016e-04, - 7.5576666091137728e-05, 1.0982309911733714e-03, 1.9020141320077115e-05, 2.7586308244495586e-04, -9.6212120541945694e-05, -2.4213401094000305e-05, - -5.6925297375807105e-04, -1.4291213510234823e-04, 9.3835695361489321e-05, 7.2468181732211106e-04, 2.3579175340076791e-05, 1.8193286738518824e-04, - -1.1945659553664183e-04, -3.0017233855795931e-05, -2.6422489214981732e-04, -6.6322596801482765e-05, 8.2272349665431173e-05, 3.3636886209090379e-04, - 2.0639815215037020e-05, 8.4431319984715745e-05, -1.0473599369591468e-04, -2.6275310782271935e-05, -6.0862501235637246e-05, -1.5286694095084582e-05, - 3.5138981471916619e-05, 7.7480399814190974e-05, 8.8257769508375181e-06, 1.9460573362573226e-05, -4.4733329689633741e-05, -1.1235567269473010e-05, - -5.6185672699463572e-04, -5.5072482877231199e-05, -3.2438813257640027e-04, 7.1526609919158365e-04, -3.1796112814134138e-05, 7.0109474725172762e-05, - 4.1295907491050273e-04, 4.0477724105333954e-05, -1.4344421799159428e-03, -1.4064417737504625e-04, -1.7939931355866808e-04, 1.8261023019736887e-03, - -1.7608728039191811e-05, 1.7904566643377122e-04, 2.2838250579132729e-04, 2.2416615502118027e-05, -1.8304802004777663e-03, -1.7952696313978887e-04, - -4.9253344222027344e-05, 2.3302745517463559e-03, -4.8402587889248271e-06, 2.2854500881667938e-04, 6.2701478332861487e-05, 6.1618431473634482e-06, - -1.8168031392969621e-03, -1.7820248370310657e-04, 5.7149799176487768e-05, 2.3128631055018131e-03, 5.6049473482295761e-06, 2.2685889348759498e-04, - -7.2753981509129112e-05, -7.1353222864950982e-06, -1.4913852692680471e-03, -1.4628465166305517e-04, 1.3073029568382095e-04, 1.8985931336037497e-03, - 1.2822821572043416e-05, 1.8622621593640838e-04, -1.6642489828339656e-04, -1.6323965035577717e-05, -9.8397636034453146e-04, -9.6528523782577987e-05, - 1.6222237447238529e-04, 1.2526412858398478e-03, 1.5903892253583568e-05, 1.2288467388473875e-04, -2.0651557490662816e-04, -2.0246291318839724e-05, - -4.5678597105277500e-04, -4.4852593938584658e-05, 1.4215113869939401e-04, 5.8150682190454331e-04, 1.3931219752470214e-05, 5.7099147102284574e-05, - -1.8096408850885512e-04, -1.7735000277791535e-05, -1.0528648823582545e-04, -1.0361506757950515e-05, 6.0787182324986102e-05, 1.3403391313090627e-04, - 5.9822187159117466e-06, 1.3190612774451422e-05, -7.7384515826668979e-05, -7.6156038361048664e-06, -6.9079330390632197e-04, -1.9369084511119769e-05, - -3.9882969996474915e-04, 8.7940752169272311e-04, -1.1182746156426749e-05, 2.4657619741028168e-05, 5.0772616937670007e-04, 1.4236083395043767e-05, - -1.7637269696838601e-03, -4.9468484637510063e-05, -2.2062884079452458e-04, 2.2452950174551459e-03, -6.1951506089909447e-06, 6.2975360691778500e-05, - 2.8086934398447859e-04, 7.8866746576102568e-06, -2.2508116665430171e-03, -6.3151521941853567e-05, -6.0589640055257214e-05, 2.8653733298781379e-03, - -1.7047546620036213e-06, 8.0394414780744815e-05, 7.7133036611584486e-05, 2.1702209096830778e-06, -2.2340461539592216e-03, -6.2692883129640193e-05, - 7.0269213258613216e-05, 2.8440301613965480e-03, 1.9695499036957683e-06, 7.9810549217891404e-05, -8.9455520679789923e-05, -2.5073158495670495e-06, - -1.8339090424506739e-03, -5.1471540987780868e-05, 1.6075005578360620e-04, 2.3346396048014584e-03, 4.5090950025756064e-06, 6.5525331588775406e-05, - -2.0464125429303824e-04, -5.7402583940354860e-06, -1.2100112667458858e-03, -3.3972790274495860e-05, 1.9945749296636228e-04, 1.5403927676946978e-03, - 5.5938134322217229e-06, 4.3248721623872484e-05, -2.5391737091355897e-04, -7.1211483658334858e-06, -5.6182935935283006e-04, -1.5794234573042483e-05, - 1.7477050575086367e-04, 7.1523125908826428e-04, 4.9015805954910036e-06, 2.0106692702967991e-05, -2.2248984820528303e-04, -6.2399082612448268e-06, - -1.2955898186391279e-04, -3.6522239721291976e-06, 7.4800913055063917e-05, 1.6493376891421342e-04, 2.1086124934495961e-06, 4.6494272799615834e-06, - -9.5224555881080636e-05, -2.6843480916634093e-06, + 2.4528129331641009e-04, 1.4161322072339013e-04, 1.4161322072323059e-04, + -3.1225290264558366e-04, 8.1760431105386229e-05, -1.8027929739766388e-04, + -1.8027929739757061e-04, -1.0408430088180949e-04, 6.2367351899508393e-04, + 3.6007807407826723e-04, 7.6851632631613504e-05, -7.9396134934045298e-04, + 4.4370310787524178e-05, -4.5839379876787668e-04, -9.7835203972628665e-05, + -5.6485181349821416e-05, 7.9228320374878549e-04, 4.5742492095878005e-04, + 2.0495214248914016e-05, -1.0086082258578244e-03, 1.1832917463701158e-05, + -5.8232023070591693e-04, -2.6091227965387976e-05, -1.5063777489315933e-05, + 7.8392504372923799e-04, 4.5259933502155545e-04, -2.5320800186129666e-05, + -9.9796795365606730e-04, -1.4618970803555413e-05, -5.7617706668598300e-04, + 3.2234391985323307e-05, 1.8610534889900770e-05, 6.4136415990862026e-04, + 3.7029177037178126e-04, -5.6986764463615016e-05, -8.1648224320972546e-04, + -3.2901323803334279e-05, -4.7139624290569432e-04, 7.2546431794942595e-05, + 4.1884701925559656e-05, 4.2047339144775083e-04, 2.4276042573940094e-04, + -7.0544580168771268e-05, -5.3527945482357338e-04, -4.0728932350285410e-05, + -3.0904373733406024e-04, 8.9806073776675660e-05, 5.1849560869833525e-05, + 1.9147960544158748e-04, 1.1055080174602805e-04, -6.1665043824638729e-05, + -2.4376120081634332e-04, -3.5602329651747633e-05, -1.4073559490929369e-04, + 7.8502068648088301e-05, 4.5323190465911326e-05, 4.2336308243161155e-05, + 2.4442878960684070e-05, -2.4442878960701085e-05, -5.3895814709309427e-05, + -1.4112102747730210e-05, -3.1116763130613984e-05, 3.1116763130599923e-05, + 1.7965271569761685e-05, 5.3693018033450050e-04, 2.6770342705359106e-05, + 3.0999678415209730e-04, -6.8353360772295210e-04, 1.5455864567378393e-05, + -3.4079717623668880e-05, -3.9463831241894352e-04, -1.9675934144003216e-05, + 1.3669669930980539e-03, 6.9062613281974694e-05, 1.6922519313423946e-04, + -1.7402036887709158e-03, 8.9615892346710530e-06, -8.7919470620922207e-05, + -2.1543044331872175e-04, -1.1408461742063897e-05, 1.7385437019493855e-03, + 8.8898832400845966e-05, 4.5304719745672186e-05, -2.2132357097847956e-03, + 2.4908572133136756e-06, -1.1317177141254158e-04, -5.7674721348954423e-05, + -3.1709609176349484e-06, 1.7210227955433098e-03, 8.8434304245292155e-05, + -5.5420419775666248e-05, -2.1909308947362814e-03, -2.7590526689688848e-06, + -1.1258040847992607e-04, 7.0552412321439102e-05, 3.5123844659692677e-06, + 1.4085793923499944e-03, 7.2660150604627523e-05, -1.2496886316451722e-04, + -1.7931779383632191e-03, -6.3481591817073264e-06, -9.2499279607523736e-05, + 1.5909036411151779e-04, 8.0814606941438113e-06, 9.2429031121328542e-04, + 4.8118408509518702e-05, -1.5463556819535819e-04, -1.1766585566365631e-03, + -7.8210222232860947e-06, -6.1256659750269686e-05, 1.9685726688898863e-04, + 9.9564742906309574e-06, 4.2273028355947908e-04, 2.2961839515620249e-05, + -1.3494024878532319e-04, -5.3815256880358146e-04, -6.7031296572285555e-06, + -2.9231340645240418e-05, 1.7178433706557119e-04, 8.5333523155413458e-06, + 9.4503458338600580e-05, 5.6758391897734915e-06, -5.4561597111207316e-05, + -1.2030668453075738e-04, -3.2769472841110353e-06, -7.2255704379161823e-06, + 6.9459096699120947e-05, 4.1716850373823499e-06, 5.0481002617904804e-04, + -4.5314922353421830e-05, 2.9145220450423634e-04, -6.4264336602196082e-04, + -2.6162582619079407e-05, 5.7687709676965182e-05, -3.7103032036577476e-04, + 3.3306014710926822e-05, 1.2870709745401126e-03, -1.1519060110358146e-04, + 1.6018636460855631e-04, -1.6384928596765438e-03, -1.4180159317133011e-05, + 1.4664224517805789e-04, -2.0392365286805118e-04, 1.8051910306267174e-05, + 1.6392548325408359e-03, -1.4622328788140585e-04, 4.3147080612402216e-05, + -2.0868370054480776e-03, -3.7365707477212382e-06, 1.8614809738656579e-04, + -5.4927960382736503e-05, 4.7568041008804382e-06, 1.6238014988128691e-03, + -1.4456504608357661e-04, -5.2069067000120898e-05, -2.0671642931638788e-03, + 4.6939570960793650e-06, 1.8403708921443785e-04, 6.6286006115708751e-05, + -5.9755952373199925e-06, 1.3297080252287945e-03, -1.1819655564340603e-04, + -1.1772587914055666e-04, -1.6927715315547887e-03, 1.0529897957677164e-05, + 1.5046894560673396e-04, 1.4986975558194660e-04, -1.3404981510783889e-05, + 8.7363231171246579e-04, -7.7365818157924915e-05, -1.4558955682894646e-04, + -1.1121688959189475e-03, 1.3043739320776322e-05, 9.8489782725532608e-05, + 1.8534133239461251e-04, -1.6605202170929098e-05, 4.0170043536063898e-04, + -3.5103428034237590e-05, -1.2688043902194603e-04, -5.1138073042364775e-04, + 1.1356462993731508e-05, 4.4688068740596321e-05, 1.6152387668004025e-04, + -1.4457231881137132e-05, 9.0968534243944562e-05, -7.7167285673880403e-06, + -5.2520707733581692e-05, -1.1580658468914775e-04, 4.4552553156694357e-06, + 9.8237042928496913e-06, 6.6860962844229497e-05, -5.6717183178946029e-06, + 2.8251817425989937e-04, -8.3025338190759114e-05, 1.6311194395982403e-04, + -3.5965694232128895e-04, -4.7934701354103719e-05, 1.0569457822362715e-04, + -2.0764803246508764e-04, 6.1022793189351798e-05, 7.2082558778295428e-04, + -2.1173132536804774e-04, 8.9944959225520430e-05, -9.1763982097140733e-04, + -2.6373734989020383e-05, 2.6954245076451236e-04, -1.1450353272676037e-04, + 3.3574820128275771e-05, 9.1873938193649102e-04, -2.6976650148029723e-04, + 2.4320623105364212e-05, -1.1695920015168078e-03, -7.1328895618542281e-06, + 3.4342355254599196e-04, -3.0961126534039862e-05, 9.0804538732875994e-06, + 9.1036543165677055e-04, -2.6733745933858483e-04, -2.9155325553541354e-05, + -1.1589316276819444e-03, 8.5352976962447920e-06, 3.4033128468836813e-04, + 3.7115896237260282e-05, -1.0865775553293173e-05, 7.4559480183162316e-04, + -2.1904137112217098e-04, -6.5975041930551768e-05, -9.4917202172907988e-04, + 1.9348461836307690e-05, 2.7884843156041278e-04, 8.3988868724735793e-05, + -2.4631366250678018e-05, 4.9013450248755551e-04, -1.4404674523170886e-04, + -8.1515030663008111e-05, -6.2396083704236186e-04, 2.3949705609325855e-05, + 1.8337727148740878e-04, 1.0377189629761795e-04, -3.0488933717316698e-05, + 2.2595287291710662e-04, -6.6364474451956418e-05, -7.1010304284444564e-05, + -2.8764704994639070e-04, 2.0900174336625617e-05, 8.4484631909733713e-05, + 9.0398959214423478e-05, -2.6606758363726633e-05, 5.1479709017752949e-05, + -1.5082155306935768e-05, -2.9721823859212993e-05, -6.5535729817781379e-05, + 8.7076864264203513e-06, 1.9200187299526287e-05, 3.7837071251892241e-05, + -1.1085233305871834e-05, -2.2431527513872884e-05, -9.3037454217624434e-05, + -1.2950848448593547e-05, 2.8556232243847948e-05, -5.3715199237173366e-05, + 1.1844040261451382e-04, 1.6486948373078488e-05, 6.8381598332375028e-05, + -5.7211901773788798e-05, -2.3746882866715864e-04, -7.1296099928848429e-06, + 7.2833040600918297e-05, -2.9672293680692828e-05, 3.0230732248928867e-04, + 9.0762788507335424e-06, 3.7774017352393571e-05, -7.3130563309101350e-05, + -3.0288987840834501e-04, -2.0610335296664254e-06, 9.3098133806454356e-05, + -8.0985669980490108e-06, 3.8559093698597833e-04, 2.6237781666355622e-06, + 1.0309799896355250e-05, -7.3041740691768927e-05, -3.0043293633985325e-04, + 2.1123152916934326e-06, 9.2985059059864345e-05, 9.5170831626760479e-06, + 3.8246315140499947e-04, -2.6890619020178464e-06, -1.2115627743500844e-05, + -6.0575372069947465e-05, -2.4640119579254834e-04, 5.0851459879323011e-06, + 7.7114872895296986e-05, 2.1678156787094434e-05, 3.1367858331675619e-04, + -6.4735943521846032e-06, -2.7597161158338549e-05, -4.0541836830675247e-05, + -1.6233938212623694e-04, 6.4812209752813668e-06, 5.1611380785727993e-05, + 2.6854953961718624e-05, 2.0666453033267132e-04, -8.2508536825505439e-06, + -3.4187431139095714e-05, -1.9172276725516337e-05, -7.5158596679359270e-05, + 5.8565003038960250e-06, 2.4407075553646800e-05, 2.3478895984199182e-05, + 9.5679901449446152e-05, -7.4555592663082866e-06, -2.9889574222545057e-05, + -4.5142603223459884e-06, -1.7245977964566013e-05, 2.6063094122603197e-06, + 5.7468340528147339e-06, 9.9569700202628604e-06, 2.1954820139689062e-05, + -3.3179361873405256e-06, -1.2675621317670252e-05, -3.2502275688898297e-04, + -8.1663673516515218e-05, -1.8765197618259547e-04, 4.1376697705835895e-04, + -4.7148543887783813e-05, 1.0396112459888037e-04, 2.3888847558641401e-04, + 6.0021983272428126e-05, -8.2967964857640498e-04, -2.0851563288963555e-04, + -1.0371181608153745e-04, 1.0562153967439215e-03, -2.6089469003518687e-05, + 2.6544874554620268e-04, 1.3202929245949519e-04, 3.3212938152300663e-05, + -1.0586408004009109e-03, -2.6609472226574323e-04, -2.8478966558307740e-05, + 1.3476921061319242e-03, -7.1538337474705816e-06, 3.3874923065981352e-04, + 3.6254864168174548e-05, 9.1071166597727244e-06, -1.0507771170938588e-03, + -2.6406284642211346e-04, 3.3019066232456236e-05, 1.3376813225743371e-03, + 8.3269378127500487e-06, 3.3616257139440253e-04, -4.2034592749946726e-05, + -1.0600525082959604e-05, -8.6268379122424405e-04, -2.1669631592545016e-04, + 7.5576666091137728e-05, 1.0982309911733714e-03, 1.9020141320077115e-05, + 2.7586308244495586e-04, -9.6212120541945694e-05, -2.4213401094000305e-05, + -5.6925297375807105e-04, -1.4291213510234823e-04, 9.3835695361489321e-05, + 7.2468181732211106e-04, 2.3579175340076791e-05, 1.8193286738518824e-04, + -1.1945659553664183e-04, -3.0017233855795931e-05, -2.6422489214981732e-04, + -6.6322596801482765e-05, 8.2272349665431173e-05, 3.3636886209090379e-04, + 2.0639815215037020e-05, 8.4431319984715745e-05, -1.0473599369591468e-04, + -2.6275310782271935e-05, -6.0862501235637246e-05, -1.5286694095084582e-05, + 3.5138981471916619e-05, 7.7480399814190974e-05, 8.8257769508375181e-06, + 1.9460573362573226e-05, -4.4733329689633741e-05, -1.1235567269473010e-05, + -5.6185672699463572e-04, -5.5072482877231199e-05, -3.2438813257640027e-04, + 7.1526609919158365e-04, -3.1796112814134138e-05, 7.0109474725172762e-05, + 4.1295907491050273e-04, 4.0477724105333954e-05, -1.4344421799159428e-03, + -1.4064417737504625e-04, -1.7939931355866808e-04, 1.8261023019736887e-03, + -1.7608728039191811e-05, 1.7904566643377122e-04, 2.2838250579132729e-04, + 2.2416615502118027e-05, -1.8304802004777663e-03, -1.7952696313978887e-04, + -4.9253344222027344e-05, 2.3302745517463559e-03, -4.8402587889248271e-06, + 2.2854500881667938e-04, 6.2701478332861487e-05, 6.1618431473634482e-06, + -1.8168031392969621e-03, -1.7820248370310657e-04, 5.7149799176487768e-05, + 2.3128631055018131e-03, 5.6049473482295761e-06, 2.2685889348759498e-04, + -7.2753981509129112e-05, -7.1353222864950982e-06, -1.4913852692680471e-03, + -1.4628465166305517e-04, 1.3073029568382095e-04, 1.8985931336037497e-03, + 1.2822821572043416e-05, 1.8622621593640838e-04, -1.6642489828339656e-04, + -1.6323965035577717e-05, -9.8397636034453146e-04, -9.6528523782577987e-05, + 1.6222237447238529e-04, 1.2526412858398478e-03, 1.5903892253583568e-05, + 1.2288467388473875e-04, -2.0651557490662816e-04, -2.0246291318839724e-05, + -4.5678597105277500e-04, -4.4852593938584658e-05, 1.4215113869939401e-04, + 5.8150682190454331e-04, 1.3931219752470214e-05, 5.7099147102284574e-05, + -1.8096408850885512e-04, -1.7735000277791535e-05, -1.0528648823582545e-04, + -1.0361506757950515e-05, 6.0787182324986102e-05, 1.3403391313090627e-04, + 5.9822187159117466e-06, 1.3190612774451422e-05, -7.7384515826668979e-05, + -7.6156038361048664e-06, -6.9079330390632197e-04, -1.9369084511119769e-05, + -3.9882969996474915e-04, 8.7940752169272311e-04, -1.1182746156426749e-05, + 2.4657619741028168e-05, 5.0772616937670007e-04, 1.4236083395043767e-05, + -1.7637269696838601e-03, -4.9468484637510063e-05, -2.2062884079452458e-04, + 2.2452950174551459e-03, -6.1951506089909447e-06, 6.2975360691778500e-05, + 2.8086934398447859e-04, 7.8866746576102568e-06, -2.2508116665430171e-03, + -6.3151521941853567e-05, -6.0589640055257214e-05, 2.8653733298781379e-03, + -1.7047546620036213e-06, 8.0394414780744815e-05, 7.7133036611584486e-05, + 2.1702209096830778e-06, -2.2340461539592216e-03, -6.2692883129640193e-05, + 7.0269213258613216e-05, 2.8440301613965480e-03, 1.9695499036957683e-06, + 7.9810549217891404e-05, -8.9455520679789923e-05, -2.5073158495670495e-06, + -1.8339090424506739e-03, -5.1471540987780868e-05, 1.6075005578360620e-04, + 2.3346396048014584e-03, 4.5090950025756064e-06, 6.5525331588775406e-05, + -2.0464125429303824e-04, -5.7402583940354860e-06, -1.2100112667458858e-03, + -3.3972790274495860e-05, 1.9945749296636228e-04, 1.5403927676946978e-03, + 5.5938134322217229e-06, 4.3248721623872484e-05, -2.5391737091355897e-04, + -7.1211483658334858e-06, -5.6182935935283006e-04, -1.5794234573042483e-05, + 1.7477050575086367e-04, 7.1523125908826428e-04, 4.9015805954910036e-06, + 2.0106692702967991e-05, -2.2248984820528303e-04, -6.2399082612448268e-06, + -1.2955898186391279e-04, -3.6522239721291976e-06, 7.4800913055063917e-05, + 1.6493376891421342e-04, 2.1086124934495961e-06, 4.6494272799615834e-06, + -9.5224555881080636e-05, -2.6843480916634093e-06 }; return sol; } -static const double * -get_sol_3x_bias_p1_NxDx_PyPy(void) +static const double *get_sol_3x_bias_p1_NxDx_PyPy(void) { static const double sol[512] = { - 2.3004015067766781e-02, -6.5620995429994662e-04, 1.3281374291817376e-02, -2.9285031811004718e-02, -3.7886299375998559e-04, 8.3538153360449507e-04, - -1.6907720999310375e-02, 4.8230775330259821e-04, 2.3004015067766743e-02, -6.5620995429994662e-04, -1.3281374291817399e-02, -2.9285031811004721e-02, - 3.7886299375998613e-04, 8.3538153360449409e-04, 1.6907720999310372e-02, -4.8230775330259897e-04, -2.3004015067766920e-02, 6.5620995429994662e-04, - -1.3281374291817378e-02, 2.9285031811004874e-02, 3.7886299375998532e-04, -8.3538153360449409e-04, 1.6907720999310375e-02, -4.8230775330259572e-04, - -2.3004015067766864e-02, 6.5620995429994662e-04, 1.3281374291817409e-02, 2.9285031811004846e-02, -3.7886299375998613e-04, -8.3538153360449333e-04, - -1.6907720999310392e-02, 4.8230775330259610e-04, 2.3004015067766864e-02, -6.5620995429994803e-04, 1.3281374291817413e-02, -2.9285031811004836e-02, - -3.7886299375998738e-04, 8.3538153360449452e-04, -1.6907720999310399e-02, 4.8230775330259767e-04, 2.3004015067766868e-02, -6.5620995429994738e-04, - -1.3281374291817413e-02, -2.9285031811004839e-02, 3.7886299375998700e-04, 8.3538153360449496e-04, 1.6907720999310406e-02, -4.8230775330259751e-04, - -2.3004015067766875e-02, 6.5620995429994738e-04, -1.3281374291817416e-02, 2.9285031811004916e-02, 3.7886299375998608e-04, -8.3538153360449333e-04, - 1.6907720999310434e-02, -4.8230775330259653e-04, -2.3004015067766889e-02, 6.5620995429994803e-04, 1.3281374291817407e-02, 2.9285031811004950e-02, - -3.7886299375998700e-04, -8.3538153360449496e-04, -1.6907720999310406e-02, 4.8230775330259659e-04, 1.8634512108127495e-02, -1.8665237556726594e-03, - 1.0758640581844770e-02, -2.3722479674155590e-02, -1.0776379927864414e-03, 2.3761594399866787e-03, -1.3696180025719200e-02, 1.3718762923137797e-03, - 1.8634512108127461e-02, -1.8665237556726600e-03, -1.0758640581844791e-02, -2.3722479674155590e-02, 1.0776379927864405e-03, 2.3761594399866791e-03, - 1.3696180025719193e-02, -1.3718762923137797e-03, -1.8634512108127634e-02, 1.8665237556726600e-03, -1.0758640581844775e-02, 2.3722479674155736e-02, - 1.0776379927864412e-03, -2.3761594399866822e-03, 1.3696180025719200e-02, -1.3718762923137810e-03, -1.8634512108127582e-02, 1.8665237556726615e-03, - 1.0758640581844805e-02, 2.3722479674155708e-02, -1.0776379927864405e-03, -2.3761594399866826e-03, -1.3696180025719215e-02, 1.3718762923137808e-03, - 1.8634512108127579e-02, -1.8665237556726637e-03, 1.0758640581844798e-02, -2.3722479674155701e-02, -1.0776379927864448e-03, 2.3761594399866843e-03, - -1.3696180025719224e-02, 1.3718762923137829e-03, 1.8634512108127579e-02, -1.8665237556726650e-03, -1.0758640581844798e-02, -2.3722479674155698e-02, - 1.0776379927864440e-03, 2.3761594399866848e-03, 1.3696180025719226e-02, -1.3718762923137823e-03, -1.8634512108127582e-02, 1.8665237556726615e-03, - -1.0758640581844805e-02, 2.3722479674155774e-02, 1.0776379927864433e-03, -2.3761594399866839e-03, 1.3696180025719250e-02, -1.3718762923137827e-03, - -1.8634512108127600e-02, 1.8665237556726628e-03, 1.0758640581844798e-02, 2.3722479674155805e-02, -1.0776379927864422e-03, -2.3761594399866848e-03, - -1.3696180025719233e-02, 1.3718762923137823e-03, 1.0604640693740158e-02, -2.7695246669819525e-03, 6.1225921591901529e-03, -1.3500132005025856e-02, - -1.5989858120093413e-03, 3.5257157385353115e-03, -7.7943048471972058e-03, 2.0355729307294634e-03, 1.0604640693740116e-02, -2.7695246669819560e-03, - -6.1225921591901780e-03, -1.3500132005025865e-02, 1.5989858120093389e-03, 3.5257157385353119e-03, 7.7943048471972023e-03, -2.0355729307294629e-03, - -1.0604640693740295e-02, 2.7695246669819538e-03, -6.1225921591901581e-03, 1.3500132005025995e-02, 1.5989858120093409e-03, -3.5257157385353158e-03, - 7.7943048471972006e-03, -2.0355729307294647e-03, -1.0604640693740237e-02, 2.7695246669819542e-03, 6.1225921591901902e-03, 1.3500132005025971e-02, - -1.5989858120093407e-03, -3.5257157385353158e-03, -7.7943048471972188e-03, 2.0355729307294647e-03, 1.0604640693740227e-02, -2.7695246669819551e-03, - 6.1225921591901780e-03, -1.3500132005025953e-02, -1.5989858120093394e-03, 3.5257157385353167e-03, -7.7943048471972205e-03, 2.0355729307294655e-03, - 1.0604640693740225e-02, -2.7695246669819551e-03, -6.1225921591901798e-03, -1.3500132005025953e-02, 1.5989858120093394e-03, 3.5257157385353167e-03, - 7.7943048471972223e-03, -2.0355729307294655e-03, -1.0604640693740237e-02, 2.7695246669819555e-03, -6.1225921591901867e-03, 1.3500132005026026e-02, - 1.5989858120093404e-03, -3.5257157385353175e-03, 7.7943048471972483e-03, -2.0355729307294651e-03, -1.0604640693740246e-02, 2.7695246669819573e-03, - 6.1225921591901815e-03, 1.3500132005026061e-02, -1.5989858120093394e-03, -3.5257157385353184e-03, -7.7943048471972318e-03, 2.0355729307294647e-03, - 3.3969299063247823e-04, -3.1569456526246991e-03, 1.9612183958349583e-04, -4.3244277172230813e-04, -1.8226634223598899e-03, 4.0189181579988681e-03, - -2.4967095066302401e-04, 2.3203234803717216e-03, 3.3969299063242467e-04, -3.1569456526247021e-03, -1.9612183958352686e-04, -4.3244277172231269e-04, - 1.8226634223598884e-03, 4.0189181579988673e-03, 2.4967095066302146e-04, -2.3203234803717211e-03, -3.3969299063260508e-04, 3.1569456526247017e-03, - -1.9612183958349588e-04, 4.3244277172242685e-04, 1.8226634223598920e-03, -4.0189181579988733e-03, 2.4967095066301458e-04, -2.3203234803717242e-03, - -3.3969299063254366e-04, 3.1569456526247043e-03, 1.9612183958353144e-04, 4.3244277172240067e-04, -1.8226634223598910e-03, -4.0189181579988725e-03, - -2.4967095066302965e-04, 2.3203234803717246e-03, 3.3969299063253238e-04, -3.1569456526247051e-03, 1.9612183958351835e-04, -4.3244277172238121e-04, - -1.8226634223598925e-03, 4.0189181579988742e-03, -2.4967095066303089e-04, 2.3203234803717246e-03, 3.3969299063252832e-04, -3.1569456526247056e-03, - -1.9612183958352063e-04, -4.3244277172238012e-04, 1.8226634223598920e-03, 4.0189181579988733e-03, 2.4967095066303165e-04, -2.3203234803717246e-03, - -3.3969299063254079e-04, 3.1569456526247051e-03, -1.9612183958352521e-04, 4.3244277172244989e-04, 1.8226634223598923e-03, -4.0189181579988759e-03, - 2.4967095066305648e-04, -2.3203234803717259e-03, -3.3969299063254426e-04, 3.1569456526247064e-03, 1.9612183958352312e-04, 4.3244277172247927e-04, - -1.8226634223598914e-03, -4.0189181579988768e-03, -2.4967095066303968e-04, 2.3203234803717255e-03, -1.0004294319619630e-02, -2.8151582054434295e-03, - -5.7759820184846399e-03, 1.2735867044672292e-02, -1.6253323477241504e-03, 3.5838090592689460e-03, 7.3530562666047940e-03, 2.0691131250931472e-03, - -1.0004294319619697e-02, -2.8151582054434343e-03, 5.7759820184846017e-03, 1.2735867044672292e-02, 1.6253323477241478e-03, 3.5838090592689481e-03, - -7.3530562666047940e-03, -2.0691131250931464e-03, 1.0004294319619515e-02, 2.8151582054434343e-03, 5.7759820184846485e-03, -1.2735867044672193e-02, - 1.6253323477241535e-03, -3.5838090592689512e-03, -7.3530562666048105e-03, -2.0691131250931490e-03, 1.0004294319619585e-02, 2.8151582054434378e-03, - -5.7759820184846095e-03, -1.2735867044672217e-02, -1.6253323477241519e-03, -3.5838090592689503e-03, 7.3530562666047966e-03, 2.0691131250931494e-03, - -1.0004294319619599e-02, -2.8151582054434373e-03, -5.7759820184846242e-03, 1.2735867044672245e-02, -1.6253323477241524e-03, 3.5838090592689529e-03, - 7.3530562666047940e-03, 2.0691131250931481e-03, -1.0004294319619604e-02, -2.8151582054434373e-03, 5.7759820184846208e-03, 1.2735867044672245e-02, - 1.6253323477241519e-03, 3.5838090592689520e-03, -7.3530562666047948e-03, -2.0691131250931490e-03, 1.0004294319619588e-02, 2.8151582054434360e-03, - 5.7759820184846173e-03, -1.2735867044672182e-02, 1.6253323477241522e-03, -3.5838090592689546e-03, -7.3530562666047732e-03, -2.0691131250931498e-03, - 1.0004294319619592e-02, 2.8151582054434386e-03, -5.7759820184846147e-03, -1.2735867044672156e-02, -1.6253323477241513e-03, -3.5838090592689559e-03, - 7.3530562666047896e-03, 2.0691131250931490e-03, -1.7517266800300840e-02, -1.5224584786921185e-03, -1.0113598702620196e-02, 2.2300181684695344e-02, - -8.7899181250292451e-04, 1.9381505727626407e-03, 1.2875015898636386e-02, 1.1189917549145393e-03, -1.7517266800300923e-02, -1.5224584786921235e-03, - 1.0113598702620148e-02, 2.2300181684695351e-02, 8.7899181250292147e-04, 1.9381505727626422e-03, -1.2875015898636382e-02, -1.1189917549145384e-03, - 1.7517266800300735e-02, 1.5224584786921213e-03, 1.0113598702620219e-02, -2.2300181684695265e-02, 8.7899181250292884e-04, -1.9381505727626449e-03, - -1.2875015898636408e-02, -1.1189917549145410e-03, 1.7517266800300819e-02, 1.5224584786921235e-03, -1.0113598702620170e-02, -2.2300181684695282e-02, - -8.7899181250292635e-04, -1.9381505727626449e-03, 1.2875015898636398e-02, 1.1189917549145421e-03, -1.7517266800300829e-02, -1.5224584786921235e-03, - -1.0113598702620184e-02, 2.2300181684695317e-02, -8.7899181250292581e-04, 1.9381505727626440e-03, 1.2875015898636386e-02, 1.1189917549145388e-03, - -1.7517266800300836e-02, -1.5224584786921235e-03, 1.0113598702620180e-02, 2.2300181684695306e-02, 8.7899181250292548e-04, 1.9381505727626431e-03, - -1.2875015898636391e-02, -1.1189917549145393e-03, 1.7517266800300819e-02, 1.5224584786921243e-03, 1.0113598702620179e-02, -2.2300181684695261e-02, - 8.7899181250292613e-04, -1.9381505727626485e-03, -1.2875015898636375e-02, -1.1189917549145419e-03, 1.7517266800300829e-02, 1.5224584786921256e-03, - -1.0113598702620170e-02, -2.2300181684695240e-02, -8.7899181250292472e-04, -1.9381505727626490e-03, 1.2875015898636389e-02, 1.1189917549145416e-03, - -1.8501401394323238e-02, 9.5426810591446164e-04, -1.0681789075397860e-02, 2.3553024408339691e-02, 5.5094694782878678e-04, -1.2148214890143143e-03, - 1.3598344982384715e-02, -7.0137751369975460e-04, -1.8501401394323349e-02, 9.5426810591445394e-04, 1.0681789075397798e-02, 2.3553024408339705e-02, - -5.5094694782879036e-04, -1.2148214890143111e-03, -1.3598344982384707e-02, 7.0137751369975688e-04, 1.8501401394323141e-02, -9.5426810591446240e-04, - 1.0681789075397893e-02, -2.3553024408339618e-02, -5.5094694782878277e-04, 1.2148214890143139e-03, -1.3598344982384747e-02, 7.0137751369975341e-04, - 1.8501401394323241e-02, -9.5426810591445600e-04, -1.0681789075397836e-02, -2.3553024408339642e-02, 5.5094694782878548e-04, 1.2148214890143119e-03, - 1.3598344982384733e-02, -7.0137751369975449e-04, -1.8501401394323245e-02, 9.5426810591445676e-04, -1.0681789075397853e-02, 2.3553024408339673e-02, - 5.5094694782878439e-04, -1.2148214890143098e-03, 1.3598344982384717e-02, -7.0137751369975406e-04, -1.8501401394323259e-02, 9.5426810591445600e-04, - 1.0681789075397847e-02, 2.3553024408339663e-02, -5.5094694782878548e-04, -1.2148214890143111e-03, -1.3598344982384724e-02, 7.0137751369975406e-04, - 1.8501401394323241e-02, -9.5426810591445318e-04, 1.0681789075397848e-02, -2.3553024408339635e-02, -5.5094694782878374e-04, 1.2148214890143083e-03, - -1.3598344982384712e-02, 7.0137751369975319e-04, 1.8501401394323262e-02, -9.5426810591445112e-04, -1.0681789075397840e-02, -2.3553024408339611e-02, - 5.5094694782878461e-04, 1.2148214890143072e-03, 1.3598344982384726e-02, -7.0137751369975406e-04, -8.4242802754184182e-03, 4.8637604847417016e-03, - -4.8637604847417077e-03, 1.0724445933620218e-02, 2.8080934251394820e-03, -6.1917617466852098e-03, 6.1917617466851959e-03, -3.5748153112067321e-03, - -8.4242802754185605e-03, 4.8637604847416903e-03, 4.8637604847416253e-03, 1.0724445933620250e-02, -2.8080934251394894e-03, -6.1917617466852046e-03, - -6.1917617466851795e-03, 3.5748153112067356e-03, 8.4242802754183228e-03, -4.8637604847417016e-03, 4.8637604847417597e-03, -1.0724445933620146e-02, - -2.8080934251394755e-03, 6.1917617466852089e-03, -6.1917617466852376e-03, 3.5748153112067278e-03, 8.4242802754184443e-03, -4.8637604847416921e-03, - -4.8637604847416895e-03, -1.0724445933620177e-02, 2.8080934251394803e-03, 6.1917617466852072e-03, 6.1917617466852185e-03, -3.5748153112067295e-03, - -8.4242802754184443e-03, 4.8637604847416973e-03, -4.8637604847417016e-03, 1.0724445933620217e-02, 2.8080934251394829e-03, -6.1917617466852055e-03, - 6.1917617466851968e-03, -3.5748153112067325e-03, -8.4242802754184512e-03, 4.8637604847416973e-03, 4.8637604847416964e-03, 1.0724445933620199e-02, - -2.8080934251394829e-03, -6.1917617466852089e-03, -6.1917617466852072e-03, 3.5748153112067312e-03, 8.4242802754184477e-03, -4.8637604847416964e-03, - 4.8637604847416973e-03, -1.0724445933620185e-02, -2.8080934251394833e-03, 6.1917617466852011e-03, -6.1917617466852029e-03, 3.5748153112067291e-03, - 8.4242802754184738e-03, -4.8637604847416938e-03, -4.8637604847416825e-03, -1.0724445933620168e-02, 2.8080934251394850e-03, 6.1917617466852011e-03, - 6.1917617466852133e-03, -3.5748153112067286e-03, + 2.3004015067766781e-02, -6.5620995429994662e-04, 1.3281374291817376e-02, + -2.9285031811004718e-02, -3.7886299375998559e-04, 8.3538153360449507e-04, + -1.6907720999310375e-02, 4.8230775330259821e-04, 2.3004015067766743e-02, + -6.5620995429994662e-04, -1.3281374291817399e-02, -2.9285031811004721e-02, + 3.7886299375998613e-04, 8.3538153360449409e-04, 1.6907720999310372e-02, + -4.8230775330259897e-04, -2.3004015067766920e-02, 6.5620995429994662e-04, + -1.3281374291817378e-02, 2.9285031811004874e-02, 3.7886299375998532e-04, + -8.3538153360449409e-04, 1.6907720999310375e-02, -4.8230775330259572e-04, + -2.3004015067766864e-02, 6.5620995429994662e-04, 1.3281374291817409e-02, + 2.9285031811004846e-02, -3.7886299375998613e-04, -8.3538153360449333e-04, + -1.6907720999310392e-02, 4.8230775330259610e-04, 2.3004015067766864e-02, + -6.5620995429994803e-04, 1.3281374291817413e-02, -2.9285031811004836e-02, + -3.7886299375998738e-04, 8.3538153360449452e-04, -1.6907720999310399e-02, + 4.8230775330259767e-04, 2.3004015067766868e-02, -6.5620995429994738e-04, + -1.3281374291817413e-02, -2.9285031811004839e-02, 3.7886299375998700e-04, + 8.3538153360449496e-04, 1.6907720999310406e-02, -4.8230775330259751e-04, + -2.3004015067766875e-02, 6.5620995429994738e-04, -1.3281374291817416e-02, + 2.9285031811004916e-02, 3.7886299375998608e-04, -8.3538153360449333e-04, + 1.6907720999310434e-02, -4.8230775330259653e-04, -2.3004015067766889e-02, + 6.5620995429994803e-04, 1.3281374291817407e-02, 2.9285031811004950e-02, + -3.7886299375998700e-04, -8.3538153360449496e-04, -1.6907720999310406e-02, + 4.8230775330259659e-04, 1.8634512108127495e-02, -1.8665237556726594e-03, + 1.0758640581844770e-02, -2.3722479674155590e-02, -1.0776379927864414e-03, + 2.3761594399866787e-03, -1.3696180025719200e-02, 1.3718762923137797e-03, + 1.8634512108127461e-02, -1.8665237556726600e-03, -1.0758640581844791e-02, + -2.3722479674155590e-02, 1.0776379927864405e-03, 2.3761594399866791e-03, + 1.3696180025719193e-02, -1.3718762923137797e-03, -1.8634512108127634e-02, + 1.8665237556726600e-03, -1.0758640581844775e-02, 2.3722479674155736e-02, + 1.0776379927864412e-03, -2.3761594399866822e-03, 1.3696180025719200e-02, + -1.3718762923137810e-03, -1.8634512108127582e-02, 1.8665237556726615e-03, + 1.0758640581844805e-02, 2.3722479674155708e-02, -1.0776379927864405e-03, + -2.3761594399866826e-03, -1.3696180025719215e-02, 1.3718762923137808e-03, + 1.8634512108127579e-02, -1.8665237556726637e-03, 1.0758640581844798e-02, + -2.3722479674155701e-02, -1.0776379927864448e-03, 2.3761594399866843e-03, + -1.3696180025719224e-02, 1.3718762923137829e-03, 1.8634512108127579e-02, + -1.8665237556726650e-03, -1.0758640581844798e-02, -2.3722479674155698e-02, + 1.0776379927864440e-03, 2.3761594399866848e-03, 1.3696180025719226e-02, + -1.3718762923137823e-03, -1.8634512108127582e-02, 1.8665237556726615e-03, + -1.0758640581844805e-02, 2.3722479674155774e-02, 1.0776379927864433e-03, + -2.3761594399866839e-03, 1.3696180025719250e-02, -1.3718762923137827e-03, + -1.8634512108127600e-02, 1.8665237556726628e-03, 1.0758640581844798e-02, + 2.3722479674155805e-02, -1.0776379927864422e-03, -2.3761594399866848e-03, + -1.3696180025719233e-02, 1.3718762923137823e-03, 1.0604640693740158e-02, + -2.7695246669819525e-03, 6.1225921591901529e-03, -1.3500132005025856e-02, + -1.5989858120093413e-03, 3.5257157385353115e-03, -7.7943048471972058e-03, + 2.0355729307294634e-03, 1.0604640693740116e-02, -2.7695246669819560e-03, + -6.1225921591901780e-03, -1.3500132005025865e-02, 1.5989858120093389e-03, + 3.5257157385353119e-03, 7.7943048471972023e-03, -2.0355729307294629e-03, + -1.0604640693740295e-02, 2.7695246669819538e-03, -6.1225921591901581e-03, + 1.3500132005025995e-02, 1.5989858120093409e-03, -3.5257157385353158e-03, + 7.7943048471972006e-03, -2.0355729307294647e-03, -1.0604640693740237e-02, + 2.7695246669819542e-03, 6.1225921591901902e-03, 1.3500132005025971e-02, + -1.5989858120093407e-03, -3.5257157385353158e-03, -7.7943048471972188e-03, + 2.0355729307294647e-03, 1.0604640693740227e-02, -2.7695246669819551e-03, + 6.1225921591901780e-03, -1.3500132005025953e-02, -1.5989858120093394e-03, + 3.5257157385353167e-03, -7.7943048471972205e-03, 2.0355729307294655e-03, + 1.0604640693740225e-02, -2.7695246669819551e-03, -6.1225921591901798e-03, + -1.3500132005025953e-02, 1.5989858120093394e-03, 3.5257157385353167e-03, + 7.7943048471972223e-03, -2.0355729307294655e-03, -1.0604640693740237e-02, + 2.7695246669819555e-03, -6.1225921591901867e-03, 1.3500132005026026e-02, + 1.5989858120093404e-03, -3.5257157385353175e-03, 7.7943048471972483e-03, + -2.0355729307294651e-03, -1.0604640693740246e-02, 2.7695246669819573e-03, + 6.1225921591901815e-03, 1.3500132005026061e-02, -1.5989858120093394e-03, + -3.5257157385353184e-03, -7.7943048471972318e-03, 2.0355729307294647e-03, + 3.3969299063247823e-04, -3.1569456526246991e-03, 1.9612183958349583e-04, + -4.3244277172230813e-04, -1.8226634223598899e-03, 4.0189181579988681e-03, + -2.4967095066302401e-04, 2.3203234803717216e-03, 3.3969299063242467e-04, + -3.1569456526247021e-03, -1.9612183958352686e-04, -4.3244277172231269e-04, + 1.8226634223598884e-03, 4.0189181579988673e-03, 2.4967095066302146e-04, + -2.3203234803717211e-03, -3.3969299063260508e-04, 3.1569456526247017e-03, + -1.9612183958349588e-04, 4.3244277172242685e-04, 1.8226634223598920e-03, + -4.0189181579988733e-03, 2.4967095066301458e-04, -2.3203234803717242e-03, + -3.3969299063254366e-04, 3.1569456526247043e-03, 1.9612183958353144e-04, + 4.3244277172240067e-04, -1.8226634223598910e-03, -4.0189181579988725e-03, + -2.4967095066302965e-04, 2.3203234803717246e-03, 3.3969299063253238e-04, + -3.1569456526247051e-03, 1.9612183958351835e-04, -4.3244277172238121e-04, + -1.8226634223598925e-03, 4.0189181579988742e-03, -2.4967095066303089e-04, + 2.3203234803717246e-03, 3.3969299063252832e-04, -3.1569456526247056e-03, + -1.9612183958352063e-04, -4.3244277172238012e-04, 1.8226634223598920e-03, + 4.0189181579988733e-03, 2.4967095066303165e-04, -2.3203234803717246e-03, + -3.3969299063254079e-04, 3.1569456526247051e-03, -1.9612183958352521e-04, + 4.3244277172244989e-04, 1.8226634223598923e-03, -4.0189181579988759e-03, + 2.4967095066305648e-04, -2.3203234803717259e-03, -3.3969299063254426e-04, + 3.1569456526247064e-03, 1.9612183958352312e-04, 4.3244277172247927e-04, + -1.8226634223598914e-03, -4.0189181579988768e-03, -2.4967095066303968e-04, + 2.3203234803717255e-03, -1.0004294319619630e-02, -2.8151582054434295e-03, + -5.7759820184846399e-03, 1.2735867044672292e-02, -1.6253323477241504e-03, + 3.5838090592689460e-03, 7.3530562666047940e-03, 2.0691131250931472e-03, + -1.0004294319619697e-02, -2.8151582054434343e-03, 5.7759820184846017e-03, + 1.2735867044672292e-02, 1.6253323477241478e-03, 3.5838090592689481e-03, + -7.3530562666047940e-03, -2.0691131250931464e-03, 1.0004294319619515e-02, + 2.8151582054434343e-03, 5.7759820184846485e-03, -1.2735867044672193e-02, + 1.6253323477241535e-03, -3.5838090592689512e-03, -7.3530562666048105e-03, + -2.0691131250931490e-03, 1.0004294319619585e-02, 2.8151582054434378e-03, + -5.7759820184846095e-03, -1.2735867044672217e-02, -1.6253323477241519e-03, + -3.5838090592689503e-03, 7.3530562666047966e-03, 2.0691131250931494e-03, + -1.0004294319619599e-02, -2.8151582054434373e-03, -5.7759820184846242e-03, + 1.2735867044672245e-02, -1.6253323477241524e-03, 3.5838090592689529e-03, + 7.3530562666047940e-03, 2.0691131250931481e-03, -1.0004294319619604e-02, + -2.8151582054434373e-03, 5.7759820184846208e-03, 1.2735867044672245e-02, + 1.6253323477241519e-03, 3.5838090592689520e-03, -7.3530562666047948e-03, + -2.0691131250931490e-03, 1.0004294319619588e-02, 2.8151582054434360e-03, + 5.7759820184846173e-03, -1.2735867044672182e-02, 1.6253323477241522e-03, + -3.5838090592689546e-03, -7.3530562666047732e-03, -2.0691131250931498e-03, + 1.0004294319619592e-02, 2.8151582054434386e-03, -5.7759820184846147e-03, + -1.2735867044672156e-02, -1.6253323477241513e-03, -3.5838090592689559e-03, + 7.3530562666047896e-03, 2.0691131250931490e-03, -1.7517266800300840e-02, + -1.5224584786921185e-03, -1.0113598702620196e-02, 2.2300181684695344e-02, + -8.7899181250292451e-04, 1.9381505727626407e-03, 1.2875015898636386e-02, + 1.1189917549145393e-03, -1.7517266800300923e-02, -1.5224584786921235e-03, + 1.0113598702620148e-02, 2.2300181684695351e-02, 8.7899181250292147e-04, + 1.9381505727626422e-03, -1.2875015898636382e-02, -1.1189917549145384e-03, + 1.7517266800300735e-02, 1.5224584786921213e-03, 1.0113598702620219e-02, + -2.2300181684695265e-02, 8.7899181250292884e-04, -1.9381505727626449e-03, + -1.2875015898636408e-02, -1.1189917549145410e-03, 1.7517266800300819e-02, + 1.5224584786921235e-03, -1.0113598702620170e-02, -2.2300181684695282e-02, + -8.7899181250292635e-04, -1.9381505727626449e-03, 1.2875015898636398e-02, + 1.1189917549145421e-03, -1.7517266800300829e-02, -1.5224584786921235e-03, + -1.0113598702620184e-02, 2.2300181684695317e-02, -8.7899181250292581e-04, + 1.9381505727626440e-03, 1.2875015898636386e-02, 1.1189917549145388e-03, + -1.7517266800300836e-02, -1.5224584786921235e-03, 1.0113598702620180e-02, + 2.2300181684695306e-02, 8.7899181250292548e-04, 1.9381505727626431e-03, + -1.2875015898636391e-02, -1.1189917549145393e-03, 1.7517266800300819e-02, + 1.5224584786921243e-03, 1.0113598702620179e-02, -2.2300181684695261e-02, + 8.7899181250292613e-04, -1.9381505727626485e-03, -1.2875015898636375e-02, + -1.1189917549145419e-03, 1.7517266800300829e-02, 1.5224584786921256e-03, + -1.0113598702620170e-02, -2.2300181684695240e-02, -8.7899181250292472e-04, + -1.9381505727626490e-03, 1.2875015898636389e-02, 1.1189917549145416e-03, + -1.8501401394323238e-02, 9.5426810591446164e-04, -1.0681789075397860e-02, + 2.3553024408339691e-02, 5.5094694782878678e-04, -1.2148214890143143e-03, + 1.3598344982384715e-02, -7.0137751369975460e-04, -1.8501401394323349e-02, + 9.5426810591445394e-04, 1.0681789075397798e-02, 2.3553024408339705e-02, + -5.5094694782879036e-04, -1.2148214890143111e-03, -1.3598344982384707e-02, + 7.0137751369975688e-04, 1.8501401394323141e-02, -9.5426810591446240e-04, + 1.0681789075397893e-02, -2.3553024408339618e-02, -5.5094694782878277e-04, + 1.2148214890143139e-03, -1.3598344982384747e-02, 7.0137751369975341e-04, + 1.8501401394323241e-02, -9.5426810591445600e-04, -1.0681789075397836e-02, + -2.3553024408339642e-02, 5.5094694782878548e-04, 1.2148214890143119e-03, + 1.3598344982384733e-02, -7.0137751369975449e-04, -1.8501401394323245e-02, + 9.5426810591445676e-04, -1.0681789075397853e-02, 2.3553024408339673e-02, + 5.5094694782878439e-04, -1.2148214890143098e-03, 1.3598344982384717e-02, + -7.0137751369975406e-04, -1.8501401394323259e-02, 9.5426810591445600e-04, + 1.0681789075397847e-02, 2.3553024408339663e-02, -5.5094694782878548e-04, + -1.2148214890143111e-03, -1.3598344982384724e-02, 7.0137751369975406e-04, + 1.8501401394323241e-02, -9.5426810591445318e-04, 1.0681789075397848e-02, + -2.3553024408339635e-02, -5.5094694782878374e-04, 1.2148214890143083e-03, + -1.3598344982384712e-02, 7.0137751369975319e-04, 1.8501401394323262e-02, + -9.5426810591445112e-04, -1.0681789075397840e-02, -2.3553024408339611e-02, + 5.5094694782878461e-04, 1.2148214890143072e-03, 1.3598344982384726e-02, + -7.0137751369975406e-04, -8.4242802754184182e-03, 4.8637604847417016e-03, + -4.8637604847417077e-03, 1.0724445933620218e-02, 2.8080934251394820e-03, + -6.1917617466852098e-03, 6.1917617466851959e-03, -3.5748153112067321e-03, + -8.4242802754185605e-03, 4.8637604847416903e-03, 4.8637604847416253e-03, + 1.0724445933620250e-02, -2.8080934251394894e-03, -6.1917617466852046e-03, + -6.1917617466851795e-03, 3.5748153112067356e-03, 8.4242802754183228e-03, + -4.8637604847417016e-03, 4.8637604847417597e-03, -1.0724445933620146e-02, + -2.8080934251394755e-03, 6.1917617466852089e-03, -6.1917617466852376e-03, + 3.5748153112067278e-03, 8.4242802754184443e-03, -4.8637604847416921e-03, + -4.8637604847416895e-03, -1.0724445933620177e-02, 2.8080934251394803e-03, + 6.1917617466852072e-03, 6.1917617466852185e-03, -3.5748153112067295e-03, + -8.4242802754184443e-03, 4.8637604847416973e-03, -4.8637604847417016e-03, + 1.0724445933620217e-02, 2.8080934251394829e-03, -6.1917617466852055e-03, + 6.1917617466851968e-03, -3.5748153112067325e-03, -8.4242802754184512e-03, + 4.8637604847416973e-03, 4.8637604847416964e-03, 1.0724445933620199e-02, + -2.8080934251394829e-03, -6.1917617466852089e-03, -6.1917617466852072e-03, + 3.5748153112067312e-03, 8.4242802754184477e-03, -4.8637604847416964e-03, + 4.8637604847416973e-03, -1.0724445933620185e-02, -2.8080934251394833e-03, + 6.1917617466852011e-03, -6.1917617466852029e-03, 3.5748153112067291e-03, + 8.4242802754184738e-03, -4.8637604847416938e-03, -4.8637604847416825e-03, + -1.0724445933620168e-02, 2.8080934251394850e-03, 6.1917617466852011e-03, + 6.1917617466852133e-03, -3.5748153112067286e-03 }; return sol; } -static const double * -get_sol_3x_bias_p2_PxPx_PyPy(void) +static const double *get_sol_3x_bias_p2_PxPx_PyPy(void) { static const double sol[640] = { - 5.4502158943918211e+00, 1.4782758980221811e+00, -1.0143961216287423e+00, -7.0788264442624271e+00, 4.1786262474674174e-01, -1.8819043793655346e+00, - 1.2913668593654497e+00, 1.4300160023058239e-01, -4.3919645391728357e-01, 1.5665697539380616e+01, -1.4624872597200635e+00, 1.6993190682438275e+00, - -2.2418353145413441e+00, 1.7213213200231410e+00, -3.4316478965842806e-01, -2.1633011812923613e+00, 2.8539460745428178e+00, 5.2659329213503925e-01, - 1.2999235352023769e-01, 1.5665697539380627e+01, -5.1231786808679800e+00, -3.9077797649552437e-01, 4.6941444639961460e-01, 6.3815280014559725e+00, - -6.5917730762051951e-01, 4.9747600316724139e-01, -5.9758337641761972e-01, 5.4963863363049092e-01, 3.9419202503096262e-01, 1.5665697539380638e+01, - 7.1054273576010019e-15, -1.7069809072513831e+00, 1.8181896694868822e+00, -1.4048349091629908e-01, 6.5229796081267557e-16, 2.1730550089788037e+00, - -2.3146282139230303e+00, 1.2499260451994659e-01, -1.2499260451994597e-01, 1.5665697539380631e+01, 2.7278721498501426e+00, -7.0755542166833685e-01, - -5.2355818804680432e-01, -3.6131739081926675e+00, 4.1518369083043022e-01, 9.0074636843026545e-01, 6.6651052638833630e-01, -3.2079725539104875e-01, - -3.4211688329996676e-01, 1.5665697539380625e+01, -1.9249877224862288e+00, 1.6136475856827914e-01, -1.4711148381875034e+00, 2.3101029185750042e+00, - -1.8942923385713109e-03, -2.0542379553857743e-01, 1.8727880636075556e+00, -4.5294792043656273e-01, 1.9363822721812923e-01, 1.5665697539380639e+01, - -3.0549093633740085e+00, -3.7994249985831274e-01, 1.0685398632759302e+00, 3.7485383873339733e+00, -1.7386900795665511e-01, 4.8368200776802284e-01, - -1.3602940093361655e+00, -3.7184297847002318e-01, 3.8712131218628787e-01, 1.5665697539380631e+01, 3.3874749822062711e+00, -1.5370291956071291e-01, - 1.8947604832419591e+00, -4.4528747113469986e+00, 3.4505908199700336e-01, 1.9566996785213275e-01, -2.4121059242273448e+00, -1.9863797621842202e-01, - -1.9863797621842175e-01, 1.5665697539380615e+01, 6.2531003217557561e+00, -2.2418353145413406e+00, 1.6993190682438222e+00, -8.1009304520475087e+00, - 8.3115202323859816e-01, 2.8539460745428187e+00, -2.1633011812923626e+00, -8.0750981210547657e-01, -4.1090887349067584e-01, 1.5665697539380639e+01, - 6.1153471320564314e+00, 9.3575965172465736e-01, -1.5569123679262598e+00, -7.9255651286233890e+00, 7.6024277282743713e-01, -1.1912594861150771e+00, - 1.9820117526159073e+00, -8.2119407263786293e-01, -2.3899601848999669e-01, 1.5665697539380625e+01, 1.4210854715202004e-14, 2.2494971535489068e+00, - -1.2756734231893674e+00, -1.4048349091629930e-01, -9.5208296129717008e-16, -2.8636999022292637e+00, 1.6239833206725696e+00, -3.0175884102839090e-01, - 3.0175884102839184e-01, 1.5665697539380625e+01, -3.3256561883227675e-01, 1.7005280561147451e+00, 8.4033563321960258e-01, 2.8288585126417820e-01, - -1.7119007404034631e-01, -2.1648402712362214e+00, -1.0697808916513580e+00, 2.6872211366005361e-01, 1.1327550506052576e-01, 1.5665697539380623e+01, - 1.9249877224862217e+00, 1.4711148381875025e+00, -1.6136475856828625e-01, -2.5910699004075894e+00, 1.8942923385745344e-03, -1.8727880636075520e+00, - 2.0542379553857337e-01, 6.2971415694500832e-01, -3.7040446372657576e-01, 1.5665697539380616e+01, -2.7278721498501426e+00, 9.2492417508745106e-01, - -2.1560377848025780e+00, 3.3322069263600800e+00, -4.1518369083043161e-01, -1.1774654907158588e+00, 2.7447223855344651e+00, 7.4754870093938741e-01, - -8.4634562248372333e-02, 1.5665697539380632e+01, -8.1780880442419672e+00, -1.4787766771950537e+00, -2.6228088648617565e-01, 1.0270549879706238e+01, - -8.3304631557717246e-01, 1.8825418912939917e+00, 3.3389406508122027e-01, 4.7955449618885981e-01, 4.7955449618885876e-01, 1.5665697539380645e+01, - -3.0549093633739872e+00, -3.5612118829268411e+00, 2.8726145195092379e+00, 3.7485383873339710e+00, -1.7386900795665752e-01, 4.5335652480671502e+00, - -3.6569532464990155e+00, -1.9507674196157704e-01, 2.1035507567784320e-01, 1.5665697539380650e+01, -5.1231786808679587e+00, -2.0232575732512998e+00, - 2.1018940431553883e+00, 6.3815280014559841e+00, -6.5917730762052029e-01, 2.5756878623133690e+00, -2.6757952355637431e+00, 9.7639007917882614e-01, - -3.2559420517375662e-02, 1.5665697539380657e+01, 7.1054273576010019e-15, -3.0167309868706003e+00, 5.0843958986766680e-01, -1.4048349091628809e-01, - -4.6926773889305484e-15, 3.8404192770477850e+00, -6.4726394585405389e-01, 3.0175884102839057e-01, -3.0175884102839112e-01, 1.5665697539380634e+01, - -6.5960283235613559e-01, -2.7880259776413983e+00, -2.9535395799047315e-01, 6.9921731223805828e-01, 7.0124608833432911e-02, 3.5492686474345190e+00, - 3.7599740870352377e-01, -4.2391812020101916e-01, 1.5827993394684697e-01, 1.5665697539380623e+01, 1.4624872597200849e+00, -2.2418353145413441e+00, - 1.6993190682438222e+00, -2.0022883018557298e+00, 3.4316478965842812e-01, 2.8539460745428231e+00, -2.1633011812923608e+00, -9.5334473768337713e-01, - 2.9675909202810047e-01, 1.5665697539380618e+01, 8.5106536630742653e+00, 1.6257374643920475e-01, 1.6110561095734441e+00, -1.0974886203719290e+01, - 1.0042363896175210e+00, -2.0696288548243347e-01, -2.0509389025866294e+00, -1.0500354508773038e+00, -2.9107116022099289e-01, 1.5665697539380604e+01, - 8.1780880442419708e+00, 3.7874514632244436e+00, -2.0463938995432054e+00, -1.0551516861538820e+01, 8.3304631557717457e-01, -4.8215772879830547e+00, - 2.6051413316078422e+00, -4.7955449618885798e-01, -4.7955449618885859e-01, 1.5665697539380607e+01, -2.7278721498501213e+00, 4.6487098044534978e+00, - -3.4175961947383620e+00, 3.3322069263600782e+00, -4.1518369083043488e-01, -5.9179936242654509e+00, 4.3507367294468446e+00, 4.9756349189949461e-01, - 1.6535064679152256e-01, 1.5665697539380638e+01, -9.6405753039620095e+00, 1.4711148381874999e+00, -1.6136475856828092e-01, 1.2132354690645652e+01, - -1.1762111052355997e+00, -1.8727880636075553e+00, 2.0542379553857698e-01, 1.1311403928438426e+00, 4.8455424518915058e-01, 1.5665697539380664e+01, - 2.1316282072803006e-14, 3.5592472331681240e+00, 3.4076656429851582e-02, -1.4048349091629220e-01, 3.8695282355514626e-15, -4.5310641702982455e+00, - -4.3380947396400749e-02, -1.2499260451994629e-01, 1.2499260451994701e-01, 1.5665697539380647e+01, -3.3256561883228386e-01, 3.3330076528705277e+00, - -7.9214396353617822e-01, 2.8288585126419385e-01, -1.7119007404034725e-01, -4.2430521303823481e+00, 1.0084309674947685e+00, 6.9547355920839171e-01, - -3.1347594048781219e-01, 1.5665697539380625e+01, -6.2531003217557455e+00, 1.6993190682438204e+00, -2.2418353145413406e+00, 7.8199634702149483e+00, - -8.3115202323860138e-01, -2.1633011812923604e+00, 2.8539460745428218e+00, 1.2342612576538134e+00, -1.5842572057662735e-02, 1.5665697539380620e+01, - -1.0905960194092088e+01, -2.2455097313438745e+00, 2.4716228830705056e-01, 1.3743240296982613e+01, -1.2482300064076051e+00, 2.8586237541840607e+00, - -3.1464748454693747e-01, 1.1021105926083008e+00, 5.1991253846043550e-01, 1.5665697539380623e+01, -3.3874749822062640e+00, -5.4199310599802200e+00, - 3.6788734962989853e+00, 4.1719077295144302e+00, -3.4505908199700158e-01, 6.8997891471291757e+00, -4.6833531907539676e+00, 1.9863797621842311e-01, - 1.9863797621842255e-01, 1.5665697539380625e+01, 8.5106536630742688e+00, -4.1037281292243684e+00, 2.3300982732117133e+00, -1.0974886203719295e+01, - 1.0042363896175179e+00, 5.2242101413176201e+00, -2.9663083532485550e+00, -8.7326921436885940e-01, -4.6783739672943780e-01, 1.5665697539380618e+01, - 9.6405753039620379e+00, 1.6136475856828092e-01, -1.4711148381874981e+00, -1.2413321672478254e+01, 1.1762111052356046e+00, -2.0542379553857670e-01, - 1.8727880636075478e+00, -1.3079066293522887e+00, -3.0778800868070544e-01, 1.5665697539380631e+01, 2.7278721498501639e+00, 3.0162302076977188e+00, - -1.7851165979825812e+00, -3.6131739081926835e+00, 4.1518369083042983e-01, -3.8397817651193273e+00, 2.2725248703007228e+00, -9.2431493744783222e-01, - 2.6140079875681571e-01, 1.5665697539380655e+01, 2.7278721498501568e+00, -3.0162302076977152e+00, 1.7851165979825847e+00, -3.6131739081926679e+00, - 4.1518369083043077e-01, 3.8397817651193265e+00, -2.2725248703007153e+00, -9.2431493744783277e-01, 2.6140079875681599e-01, 1.5665697539380639e+01, - 9.6405753039620414e+00, -1.6136475856828447e-01, 1.4711148381874963e+00, -1.2413321672478233e+01, 1.1762111052356037e+00, 2.0542379553857706e-01, - -1.8727880636075500e+00, -1.3079066293522899e+00, -3.0778800868070444e-01, 1.5665697539380607e+01, 8.5106536630742688e+00, 4.1037281292243657e+00, - -2.3300982732117159e+00, -1.0974886203719272e+01, 1.0042363896175219e+00, -5.2242101413176147e+00, 2.9663083532485537e+00, -8.7326921436885985e-01, - -4.6783739672943597e-01, 1.5665697539380588e+01, -3.3874749822062782e+00, 5.4199310599802200e+00, -3.6788734962989835e+00, 4.1719077295144462e+00, - -3.4505908199700419e-01, -6.8997891471291819e+00, 4.6833531907539623e+00, 1.9863797621842127e-01, 1.9863797621842422e-01, 1.5665697539380609e+01, - -1.0905960194092074e+01, 2.2455097313438710e+00, -2.4716228830704523e-01, 1.3743240296982599e+01, -1.2482300064076046e+00, -2.8586237541840540e+00, - 3.1464748454693053e-01, 1.1021105926083008e+00, 5.1991253846043417e-01, 1.5665697539380636e+01, -6.2531003217557384e+00, -1.6993190682438204e+00, - 2.2418353145413406e+00, 7.8199634702149314e+00, -8.3115202323859982e-01, 2.1633011812923595e+00, -2.8539460745428191e+00, 1.2342612576538141e+00, - -1.5842572057662315e-02, 1.5665697539380639e+01, -3.3256561883227675e-01, -3.3330076528705250e+00, 7.9214396353617644e-01, 2.8288585126417620e-01, - -1.7119007404034572e-01, 4.2430521303823490e+00, -1.0084309674947725e+00, 6.9547355920839105e-01, -3.1347594048781230e-01, 1.5665697539380634e+01, - 2.8421709430404007e-14, -3.5592472331681222e+00, -3.4076656429846253e-02, -1.4048349091630685e-01, -8.1004038685081991e-16, 4.5310641702982473e+00, - 4.3380947396408673e-02, -1.2499260451994648e-01, 1.2499260451994688e-01, 1.5665697539380645e+01, -9.6405753039620237e+00, -1.4711148381875070e+00, - 1.6136475856828447e-01, 1.2132354690645675e+01, -1.1762111052356012e+00, 1.8727880636075578e+00, -2.0542379553857232e-01, 1.1311403928438450e+00, - 4.8455424518914980e-01, 1.5665697539380643e+01, -2.7278721498501284e+00, -4.6487098044534987e+00, 3.4175961947383620e+00, 3.3322069263601044e+00, - -4.1518369083043150e-01, 5.9179936242654536e+00, -4.3507367294468464e+00, 4.9756349189949367e-01, 1.6535064679152167e-01, 1.5665697539380613e+01, - 8.1780880442419601e+00, -3.7874514632244480e+00, 2.0463938995432098e+00, -1.0551516861538797e+01, 8.3304631557717412e-01, 4.8215772879830503e+00, - -2.6051413316078431e+00, -4.7955449618885987e-01, -4.7955449618885732e-01, 1.5665697539380586e+01, 8.5106536630742582e+00, -1.6257374643921096e-01, - -1.6110561095734477e+00, -1.0974886203719283e+01, 1.0042363896175217e+00, 2.0696288548243486e-01, 2.0509389025866258e+00, -1.0500354508773055e+00, - -2.9107116022099189e-01, 1.5665697539380597e+01, 1.4624872597200707e+00, 2.2418353145413406e+00, -1.6993190682438186e+00, -2.0022883018557285e+00, - 3.4316478965842906e-01, -2.8539460745428187e+00, 2.1633011812923577e+00, -9.5334473768337691e-01, 2.9675909202809997e-01, 1.5665697539380623e+01, - -6.5960283235613559e-01, 2.7880259776413947e+00, 2.9535395799047315e-01, 6.9921731223805195e-01, 7.0124608833429983e-02, -3.5492686474345136e+00, - -3.7599740870352399e-01, -4.2391812020101871e-01, 1.5827993394684667e-01, 1.5665697539380631e+01, 0.0000000000000000e+00, 3.0167309868705985e+00, - -5.0843958986766680e-01, -1.4048349091628975e-01, -1.2979111161188702e-15, -3.8404192770477770e+00, 6.4726394585405544e-01, 3.0175884102839184e-01, - -3.0175884102839107e-01, 1.5665697539380629e+01, -5.1231786808679658e+00, 2.0232575732513016e+00, -2.1018940431553936e+00, 6.3815280014559876e+00, - -6.5917730762052162e-01, -2.5756878623133637e+00, 2.6757952355637480e+00, 9.7639007917883069e-01, -3.2559420517376217e-02, 1.5665697539380636e+01, - -3.0549093633740156e+00, 3.5612118829268429e+00, -2.8726145195092361e+00, 3.7485383873339750e+00, -1.7386900795665677e-01, -4.5335652480671609e+00, - 3.6569532464990164e+00, -1.9507674196157757e-01, 2.1035507567784251e-01, 1.5665697539380638e+01, -8.1780880442419814e+00, 1.4787766771950537e+00, - 2.6228088648617742e-01, 1.0270549879706252e+01, -8.3304631557717312e-01, -1.8825418912939991e+00, -3.3389406508121872e-01, 4.7955449618885904e-01, - 4.7955449618885837e-01, 1.5665697539380629e+01, -2.7278721498501497e+00, -9.2492417508744751e-01, 2.1560377848025762e+00, 3.3322069263600911e+00, - -4.1518369083043205e-01, 1.1774654907158566e+00, -2.7447223855344633e+00, 7.4754870093938719e-01, -8.4634562248372056e-02, 1.5665697539380616e+01, - 1.9249877224862075e+00, -1.4711148381874990e+00, 1.6136475856828802e-01, -2.5910699004075779e+00, 1.8942923385743744e-03, 1.8727880636075500e+00, - -2.0542379553857354e-01, 6.2971415694500765e-01, -3.7040446372657621e-01, 1.5665697539380616e+01, -3.3256561883229097e-01, -1.7005280561147487e+00, - -8.4033563321960258e-01, 2.8288585126418925e-01, -1.7119007404034650e-01, 2.1648402712362236e+00, 1.0697808916513587e+00, 2.6872211366005372e-01, - 1.1327550506052518e-01, 1.5665697539380611e+01, 0.0000000000000000e+00, -2.2494971535489121e+00, 1.2756734231893638e+00, -1.4048349091628354e-01, - -1.9482695447842184e-16, 2.8636999022292722e+00, -1.6239833206725702e+00, -3.0175884102839207e-01, 3.0175884102839212e-01, 1.5665697539380615e+01, - 6.1153471320564172e+00, -9.3575965172466091e-01, 1.5569123679262589e+00, -7.9255651286233739e+00, 7.6024277282743702e-01, 1.1912594861150809e+00, - -1.9820117526159078e+00, -8.2119407263786348e-01, -2.3899601848999721e-01, 1.5665697539380615e+01, 6.2531003217557384e+00, 2.2418353145413388e+00, - -1.6993190682438248e+00, -8.1009304520474963e+00, 8.3115202323859849e-01, -2.8539460745428178e+00, 2.1633011812923590e+00, -8.0750981210547501e-01, - -4.1090887349067573e-01, 1.5665697539380620e+01, 3.3874749822062569e+00, 1.5370291956072180e-01, -1.8947604832419573e+00, -4.4528747113470075e+00, - 3.4505908199700430e-01, -1.9566996785213062e-01, 2.4121059242273430e+00, -1.9863797621842222e-01, -1.9863797621842241e-01, 1.5665697539380620e+01, - -3.0549093633740227e+00, 3.7994249985831807e-01, -1.0685398632759249e+00, 3.7485383873339648e+00, -1.7386900795665666e-01, -4.8368200776803066e-01, - 1.3602940093361668e+00, -3.7184297847002262e-01, 3.8712131218628748e-01, 1.5665697539380634e+01, -1.9249877224862217e+00, -1.6136475856827737e-01, - 1.4711148381874981e+00, 2.3101029185750024e+00, -1.8942923385708280e-03, 2.0542379553857140e-01, -1.8727880636075536e+00, -4.5294792043656368e-01, - 1.9363822721812987e-01, 1.5665697539380638e+01, 2.7278721498501355e+00, 7.0755542166834040e-01, 5.2355818804680254e-01, -3.6131739081926684e+00, - 4.1518369083042905e-01, -9.0074636843026978e-01, -6.6651052638833552e-01, -3.2079725539105020e-01, -3.4211688329996731e-01, 1.5665697539380632e+01, - 0.0000000000000000e+00, 1.7069809072513848e+00, -1.8181896694868858e+00, -1.4048349091628820e-01, -4.7951458347135731e-16, -2.1730550089788068e+00, - 2.3146282139230339e+00, 1.2499260451994659e-01, -1.2499260451994658e-01, 1.5665697539380618e+01, -5.1231786808679871e+00, 3.9077797649552615e-01, - -4.6941444639961638e-01, 6.3815280014559947e+00, -6.5917730762052062e-01, -4.9747600316724699e-01, 5.9758337641762205e-01, 5.4963863363049015e-01, - 3.9419202503096307e-01, 1.5665697539380618e+01, -1.4624872597200849e+00, -1.6993190682438257e+00, 2.2418353145413406e+00, 1.7213213200231645e+00, - -3.4316478965842862e-01, 2.1633011812923599e+00, -2.8539460745428191e+00, 5.2659329213503836e-01, 1.2999235352023908e-01, 1.5665697539380609e+01, - 5.4502158943918175e+00, -1.4782758980221766e+00, 1.0143961216287396e+00, -7.0788264442624165e+00, 4.1786262474674263e-01, 1.8819043793655328e+00, - -1.2913668593654577e+00, 1.4300160023058200e-01, -4.3919645391728296e-01, 1.5665697539380606e+01, + 5.4502158943918211e+00, 1.4782758980221811e+00, -1.0143961216287423e+00, + -7.0788264442624271e+00, 4.1786262474674174e-01, -1.8819043793655346e+00, + 1.2913668593654497e+00, 1.4300160023058239e-01, -4.3919645391728357e-01, + 1.5665697539380616e+01, -1.4624872597200635e+00, 1.6993190682438275e+00, + -2.2418353145413441e+00, 1.7213213200231410e+00, -3.4316478965842806e-01, + -2.1633011812923613e+00, 2.8539460745428178e+00, 5.2659329213503925e-01, + 1.2999235352023769e-01, 1.5665697539380627e+01, -5.1231786808679800e+00, + -3.9077797649552437e-01, 4.6941444639961460e-01, 6.3815280014559725e+00, + -6.5917730762051951e-01, 4.9747600316724139e-01, -5.9758337641761972e-01, + 5.4963863363049092e-01, 3.9419202503096262e-01, 1.5665697539380638e+01, + 7.1054273576010019e-15, -1.7069809072513831e+00, 1.8181896694868822e+00, + -1.4048349091629908e-01, 6.5229796081267557e-16, 2.1730550089788037e+00, + -2.3146282139230303e+00, 1.2499260451994659e-01, -1.2499260451994597e-01, + 1.5665697539380631e+01, 2.7278721498501426e+00, -7.0755542166833685e-01, + -5.2355818804680432e-01, -3.6131739081926675e+00, 4.1518369083043022e-01, + 9.0074636843026545e-01, 6.6651052638833630e-01, -3.2079725539104875e-01, + -3.4211688329996676e-01, 1.5665697539380625e+01, -1.9249877224862288e+00, + 1.6136475856827914e-01, -1.4711148381875034e+00, 2.3101029185750042e+00, + -1.8942923385713109e-03, -2.0542379553857743e-01, 1.8727880636075556e+00, + -4.5294792043656273e-01, 1.9363822721812923e-01, 1.5665697539380639e+01, + -3.0549093633740085e+00, -3.7994249985831274e-01, 1.0685398632759302e+00, + 3.7485383873339733e+00, -1.7386900795665511e-01, 4.8368200776802284e-01, + -1.3602940093361655e+00, -3.7184297847002318e-01, 3.8712131218628787e-01, + 1.5665697539380631e+01, 3.3874749822062711e+00, -1.5370291956071291e-01, + 1.8947604832419591e+00, -4.4528747113469986e+00, 3.4505908199700336e-01, + 1.9566996785213275e-01, -2.4121059242273448e+00, -1.9863797621842202e-01, + -1.9863797621842175e-01, 1.5665697539380615e+01, 6.2531003217557561e+00, + -2.2418353145413406e+00, 1.6993190682438222e+00, -8.1009304520475087e+00, + 8.3115202323859816e-01, 2.8539460745428187e+00, -2.1633011812923626e+00, + -8.0750981210547657e-01, -4.1090887349067584e-01, 1.5665697539380639e+01, + 6.1153471320564314e+00, 9.3575965172465736e-01, -1.5569123679262598e+00, + -7.9255651286233890e+00, 7.6024277282743713e-01, -1.1912594861150771e+00, + 1.9820117526159073e+00, -8.2119407263786293e-01, -2.3899601848999669e-01, + 1.5665697539380625e+01, 1.4210854715202004e-14, 2.2494971535489068e+00, + -1.2756734231893674e+00, -1.4048349091629930e-01, -9.5208296129717008e-16, + -2.8636999022292637e+00, 1.6239833206725696e+00, -3.0175884102839090e-01, + 3.0175884102839184e-01, 1.5665697539380625e+01, -3.3256561883227675e-01, + 1.7005280561147451e+00, 8.4033563321960258e-01, 2.8288585126417820e-01, + -1.7119007404034631e-01, -2.1648402712362214e+00, -1.0697808916513580e+00, + 2.6872211366005361e-01, 1.1327550506052576e-01, 1.5665697539380623e+01, + 1.9249877224862217e+00, 1.4711148381875025e+00, -1.6136475856828625e-01, + -2.5910699004075894e+00, 1.8942923385745344e-03, -1.8727880636075520e+00, + 2.0542379553857337e-01, 6.2971415694500832e-01, -3.7040446372657576e-01, + 1.5665697539380616e+01, -2.7278721498501426e+00, 9.2492417508745106e-01, + -2.1560377848025780e+00, 3.3322069263600800e+00, -4.1518369083043161e-01, + -1.1774654907158588e+00, 2.7447223855344651e+00, 7.4754870093938741e-01, + -8.4634562248372333e-02, 1.5665697539380632e+01, -8.1780880442419672e+00, + -1.4787766771950537e+00, -2.6228088648617565e-01, 1.0270549879706238e+01, + -8.3304631557717246e-01, 1.8825418912939917e+00, 3.3389406508122027e-01, + 4.7955449618885981e-01, 4.7955449618885876e-01, 1.5665697539380645e+01, + -3.0549093633739872e+00, -3.5612118829268411e+00, 2.8726145195092379e+00, + 3.7485383873339710e+00, -1.7386900795665752e-01, 4.5335652480671502e+00, + -3.6569532464990155e+00, -1.9507674196157704e-01, 2.1035507567784320e-01, + 1.5665697539380650e+01, -5.1231786808679587e+00, -2.0232575732512998e+00, + 2.1018940431553883e+00, 6.3815280014559841e+00, -6.5917730762052029e-01, + 2.5756878623133690e+00, -2.6757952355637431e+00, 9.7639007917882614e-01, + -3.2559420517375662e-02, 1.5665697539380657e+01, 7.1054273576010019e-15, + -3.0167309868706003e+00, 5.0843958986766680e-01, -1.4048349091628809e-01, + -4.6926773889305484e-15, 3.8404192770477850e+00, -6.4726394585405389e-01, + 3.0175884102839057e-01, -3.0175884102839112e-01, 1.5665697539380634e+01, + -6.5960283235613559e-01, -2.7880259776413983e+00, -2.9535395799047315e-01, + 6.9921731223805828e-01, 7.0124608833432911e-02, 3.5492686474345190e+00, + 3.7599740870352377e-01, -4.2391812020101916e-01, 1.5827993394684697e-01, + 1.5665697539380623e+01, 1.4624872597200849e+00, -2.2418353145413441e+00, + 1.6993190682438222e+00, -2.0022883018557298e+00, 3.4316478965842812e-01, + 2.8539460745428231e+00, -2.1633011812923608e+00, -9.5334473768337713e-01, + 2.9675909202810047e-01, 1.5665697539380618e+01, 8.5106536630742653e+00, + 1.6257374643920475e-01, 1.6110561095734441e+00, -1.0974886203719290e+01, + 1.0042363896175210e+00, -2.0696288548243347e-01, -2.0509389025866294e+00, + -1.0500354508773038e+00, -2.9107116022099289e-01, 1.5665697539380604e+01, + 8.1780880442419708e+00, 3.7874514632244436e+00, -2.0463938995432054e+00, + -1.0551516861538820e+01, 8.3304631557717457e-01, -4.8215772879830547e+00, + 2.6051413316078422e+00, -4.7955449618885798e-01, -4.7955449618885859e-01, + 1.5665697539380607e+01, -2.7278721498501213e+00, 4.6487098044534978e+00, + -3.4175961947383620e+00, 3.3322069263600782e+00, -4.1518369083043488e-01, + -5.9179936242654509e+00, 4.3507367294468446e+00, 4.9756349189949461e-01, + 1.6535064679152256e-01, 1.5665697539380638e+01, -9.6405753039620095e+00, + 1.4711148381874999e+00, -1.6136475856828092e-01, 1.2132354690645652e+01, + -1.1762111052355997e+00, -1.8727880636075553e+00, 2.0542379553857698e-01, + 1.1311403928438426e+00, 4.8455424518915058e-01, 1.5665697539380664e+01, + 2.1316282072803006e-14, 3.5592472331681240e+00, 3.4076656429851582e-02, + -1.4048349091629220e-01, 3.8695282355514626e-15, -4.5310641702982455e+00, + -4.3380947396400749e-02, -1.2499260451994629e-01, 1.2499260451994701e-01, + 1.5665697539380647e+01, -3.3256561883228386e-01, 3.3330076528705277e+00, + -7.9214396353617822e-01, 2.8288585126419385e-01, -1.7119007404034725e-01, + -4.2430521303823481e+00, 1.0084309674947685e+00, 6.9547355920839171e-01, + -3.1347594048781219e-01, 1.5665697539380625e+01, -6.2531003217557455e+00, + 1.6993190682438204e+00, -2.2418353145413406e+00, 7.8199634702149483e+00, + -8.3115202323860138e-01, -2.1633011812923604e+00, 2.8539460745428218e+00, + 1.2342612576538134e+00, -1.5842572057662735e-02, 1.5665697539380620e+01, + -1.0905960194092088e+01, -2.2455097313438745e+00, 2.4716228830705056e-01, + 1.3743240296982613e+01, -1.2482300064076051e+00, 2.8586237541840607e+00, + -3.1464748454693747e-01, 1.1021105926083008e+00, 5.1991253846043550e-01, + 1.5665697539380623e+01, -3.3874749822062640e+00, -5.4199310599802200e+00, + 3.6788734962989853e+00, 4.1719077295144302e+00, -3.4505908199700158e-01, + 6.8997891471291757e+00, -4.6833531907539676e+00, 1.9863797621842311e-01, + 1.9863797621842255e-01, 1.5665697539380625e+01, 8.5106536630742688e+00, + -4.1037281292243684e+00, 2.3300982732117133e+00, -1.0974886203719295e+01, + 1.0042363896175179e+00, 5.2242101413176201e+00, -2.9663083532485550e+00, + -8.7326921436885940e-01, -4.6783739672943780e-01, 1.5665697539380618e+01, + 9.6405753039620379e+00, 1.6136475856828092e-01, -1.4711148381874981e+00, + -1.2413321672478254e+01, 1.1762111052356046e+00, -2.0542379553857670e-01, + 1.8727880636075478e+00, -1.3079066293522887e+00, -3.0778800868070544e-01, + 1.5665697539380631e+01, 2.7278721498501639e+00, 3.0162302076977188e+00, + -1.7851165979825812e+00, -3.6131739081926835e+00, 4.1518369083042983e-01, + -3.8397817651193273e+00, 2.2725248703007228e+00, -9.2431493744783222e-01, + 2.6140079875681571e-01, 1.5665697539380655e+01, 2.7278721498501568e+00, + -3.0162302076977152e+00, 1.7851165979825847e+00, -3.6131739081926679e+00, + 4.1518369083043077e-01, 3.8397817651193265e+00, -2.2725248703007153e+00, + -9.2431493744783277e-01, 2.6140079875681599e-01, 1.5665697539380639e+01, + 9.6405753039620414e+00, -1.6136475856828447e-01, 1.4711148381874963e+00, + -1.2413321672478233e+01, 1.1762111052356037e+00, 2.0542379553857706e-01, + -1.8727880636075500e+00, -1.3079066293522899e+00, -3.0778800868070444e-01, + 1.5665697539380607e+01, 8.5106536630742688e+00, 4.1037281292243657e+00, + -2.3300982732117159e+00, -1.0974886203719272e+01, 1.0042363896175219e+00, + -5.2242101413176147e+00, 2.9663083532485537e+00, -8.7326921436885985e-01, + -4.6783739672943597e-01, 1.5665697539380588e+01, -3.3874749822062782e+00, + 5.4199310599802200e+00, -3.6788734962989835e+00, 4.1719077295144462e+00, + -3.4505908199700419e-01, -6.8997891471291819e+00, 4.6833531907539623e+00, + 1.9863797621842127e-01, 1.9863797621842422e-01, 1.5665697539380609e+01, + -1.0905960194092074e+01, 2.2455097313438710e+00, -2.4716228830704523e-01, + 1.3743240296982599e+01, -1.2482300064076046e+00, -2.8586237541840540e+00, + 3.1464748454693053e-01, 1.1021105926083008e+00, 5.1991253846043417e-01, + 1.5665697539380636e+01, -6.2531003217557384e+00, -1.6993190682438204e+00, + 2.2418353145413406e+00, 7.8199634702149314e+00, -8.3115202323859982e-01, + 2.1633011812923595e+00, -2.8539460745428191e+00, 1.2342612576538141e+00, + -1.5842572057662315e-02, 1.5665697539380639e+01, -3.3256561883227675e-01, + -3.3330076528705250e+00, 7.9214396353617644e-01, 2.8288585126417620e-01, + -1.7119007404034572e-01, 4.2430521303823490e+00, -1.0084309674947725e+00, + 6.9547355920839105e-01, -3.1347594048781230e-01, 1.5665697539380634e+01, + 2.8421709430404007e-14, -3.5592472331681222e+00, -3.4076656429846253e-02, + -1.4048349091630685e-01, -8.1004038685081991e-16, 4.5310641702982473e+00, + 4.3380947396408673e-02, -1.2499260451994648e-01, 1.2499260451994688e-01, + 1.5665697539380645e+01, -9.6405753039620237e+00, -1.4711148381875070e+00, + 1.6136475856828447e-01, 1.2132354690645675e+01, -1.1762111052356012e+00, + 1.8727880636075578e+00, -2.0542379553857232e-01, 1.1311403928438450e+00, + 4.8455424518914980e-01, 1.5665697539380643e+01, -2.7278721498501284e+00, + -4.6487098044534987e+00, 3.4175961947383620e+00, 3.3322069263601044e+00, + -4.1518369083043150e-01, 5.9179936242654536e+00, -4.3507367294468464e+00, + 4.9756349189949367e-01, 1.6535064679152167e-01, 1.5665697539380613e+01, + 8.1780880442419601e+00, -3.7874514632244480e+00, 2.0463938995432098e+00, + -1.0551516861538797e+01, 8.3304631557717412e-01, 4.8215772879830503e+00, + -2.6051413316078431e+00, -4.7955449618885987e-01, -4.7955449618885732e-01, + 1.5665697539380586e+01, 8.5106536630742582e+00, -1.6257374643921096e-01, + -1.6110561095734477e+00, -1.0974886203719283e+01, 1.0042363896175217e+00, + 2.0696288548243486e-01, 2.0509389025866258e+00, -1.0500354508773055e+00, + -2.9107116022099189e-01, 1.5665697539380597e+01, 1.4624872597200707e+00, + 2.2418353145413406e+00, -1.6993190682438186e+00, -2.0022883018557285e+00, + 3.4316478965842906e-01, -2.8539460745428187e+00, 2.1633011812923577e+00, + -9.5334473768337691e-01, 2.9675909202809997e-01, 1.5665697539380623e+01, + -6.5960283235613559e-01, 2.7880259776413947e+00, 2.9535395799047315e-01, + 6.9921731223805195e-01, 7.0124608833429983e-02, -3.5492686474345136e+00, + -3.7599740870352399e-01, -4.2391812020101871e-01, 1.5827993394684667e-01, + 1.5665697539380631e+01, 0.0000000000000000e+00, 3.0167309868705985e+00, + -5.0843958986766680e-01, -1.4048349091628975e-01, -1.2979111161188702e-15, + -3.8404192770477770e+00, 6.4726394585405544e-01, 3.0175884102839184e-01, + -3.0175884102839107e-01, 1.5665697539380629e+01, -5.1231786808679658e+00, + 2.0232575732513016e+00, -2.1018940431553936e+00, 6.3815280014559876e+00, + -6.5917730762052162e-01, -2.5756878623133637e+00, 2.6757952355637480e+00, + 9.7639007917883069e-01, -3.2559420517376217e-02, 1.5665697539380636e+01, + -3.0549093633740156e+00, 3.5612118829268429e+00, -2.8726145195092361e+00, + 3.7485383873339750e+00, -1.7386900795665677e-01, -4.5335652480671609e+00, + 3.6569532464990164e+00, -1.9507674196157757e-01, 2.1035507567784251e-01, + 1.5665697539380638e+01, -8.1780880442419814e+00, 1.4787766771950537e+00, + 2.6228088648617742e-01, 1.0270549879706252e+01, -8.3304631557717312e-01, + -1.8825418912939991e+00, -3.3389406508121872e-01, 4.7955449618885904e-01, + 4.7955449618885837e-01, 1.5665697539380629e+01, -2.7278721498501497e+00, + -9.2492417508744751e-01, 2.1560377848025762e+00, 3.3322069263600911e+00, + -4.1518369083043205e-01, 1.1774654907158566e+00, -2.7447223855344633e+00, + 7.4754870093938719e-01, -8.4634562248372056e-02, 1.5665697539380616e+01, + 1.9249877224862075e+00, -1.4711148381874990e+00, 1.6136475856828802e-01, + -2.5910699004075779e+00, 1.8942923385743744e-03, 1.8727880636075500e+00, + -2.0542379553857354e-01, 6.2971415694500765e-01, -3.7040446372657621e-01, + 1.5665697539380616e+01, -3.3256561883229097e-01, -1.7005280561147487e+00, + -8.4033563321960258e-01, 2.8288585126418925e-01, -1.7119007404034650e-01, + 2.1648402712362236e+00, 1.0697808916513587e+00, 2.6872211366005372e-01, + 1.1327550506052518e-01, 1.5665697539380611e+01, 0.0000000000000000e+00, + -2.2494971535489121e+00, 1.2756734231893638e+00, -1.4048349091628354e-01, + -1.9482695447842184e-16, 2.8636999022292722e+00, -1.6239833206725702e+00, + -3.0175884102839207e-01, 3.0175884102839212e-01, 1.5665697539380615e+01, + 6.1153471320564172e+00, -9.3575965172466091e-01, 1.5569123679262589e+00, + -7.9255651286233739e+00, 7.6024277282743702e-01, 1.1912594861150809e+00, + -1.9820117526159078e+00, -8.2119407263786348e-01, -2.3899601848999721e-01, + 1.5665697539380615e+01, 6.2531003217557384e+00, 2.2418353145413388e+00, + -1.6993190682438248e+00, -8.1009304520474963e+00, 8.3115202323859849e-01, + -2.8539460745428178e+00, 2.1633011812923590e+00, -8.0750981210547501e-01, + -4.1090887349067573e-01, 1.5665697539380620e+01, 3.3874749822062569e+00, + 1.5370291956072180e-01, -1.8947604832419573e+00, -4.4528747113470075e+00, + 3.4505908199700430e-01, -1.9566996785213062e-01, 2.4121059242273430e+00, + -1.9863797621842222e-01, -1.9863797621842241e-01, 1.5665697539380620e+01, + -3.0549093633740227e+00, 3.7994249985831807e-01, -1.0685398632759249e+00, + 3.7485383873339648e+00, -1.7386900795665666e-01, -4.8368200776803066e-01, + 1.3602940093361668e+00, -3.7184297847002262e-01, 3.8712131218628748e-01, + 1.5665697539380634e+01, -1.9249877224862217e+00, -1.6136475856827737e-01, + 1.4711148381874981e+00, 2.3101029185750024e+00, -1.8942923385708280e-03, + 2.0542379553857140e-01, -1.8727880636075536e+00, -4.5294792043656368e-01, + 1.9363822721812987e-01, 1.5665697539380638e+01, 2.7278721498501355e+00, + 7.0755542166834040e-01, 5.2355818804680254e-01, -3.6131739081926684e+00, + 4.1518369083042905e-01, -9.0074636843026978e-01, -6.6651052638833552e-01, + -3.2079725539105020e-01, -3.4211688329996731e-01, 1.5665697539380632e+01, + 0.0000000000000000e+00, 1.7069809072513848e+00, -1.8181896694868858e+00, + -1.4048349091628820e-01, -4.7951458347135731e-16, -2.1730550089788068e+00, + 2.3146282139230339e+00, 1.2499260451994659e-01, -1.2499260451994658e-01, + 1.5665697539380618e+01, -5.1231786808679871e+00, 3.9077797649552615e-01, + -4.6941444639961638e-01, 6.3815280014559947e+00, -6.5917730762052062e-01, + -4.9747600316724699e-01, 5.9758337641762205e-01, 5.4963863363049015e-01, + 3.9419202503096307e-01, 1.5665697539380618e+01, -1.4624872597200849e+00, + -1.6993190682438257e+00, 2.2418353145413406e+00, 1.7213213200231645e+00, + -3.4316478965842862e-01, 2.1633011812923599e+00, -2.8539460745428191e+00, + 5.2659329213503836e-01, 1.2999235352023908e-01, 1.5665697539380609e+01, + 5.4502158943918175e+00, -1.4782758980221766e+00, 1.0143961216287396e+00, + -7.0788264442624165e+00, 4.1786262474674263e-01, 1.8819043793655328e+00, + -1.2913668593654577e+00, 1.4300160023058200e-01, -4.3919645391728296e-01, + 1.5665697539380606e+01 }; return sol; } -static const double * -get_sol_3x_bias_p2_DxDx_DyDy(void) +static const double *get_sol_3x_bias_p2_DxDx_DyDy(void) { static const double sol[640] = { - -1.6736386918814842e-04, -8.9993566755474939e-05, -8.9993566755553327e-05, 2.1306090344382802e-04, -4.8127663587508573e-05, 1.1456541205790448e-04, - 1.1456541205785753e-04, 5.1386806341961409e-06, 5.1386806342542322e-06, 1.3021735293941976e-16, -4.0904809409466058e-04, -2.1943276528524800e-04, - -4.9944248969825226e-05, 5.2073459404767034e-04, -2.6835819803993821e-05, 2.7934669199395864e-04, 6.3581027727126449e-05, 1.2959979779996389e-05, - 4.8277858685092419e-06, 2.5963965559206471e-18, -5.1818273509544963e-04, -2.7802320360133129e-04, -1.3907438669093784e-05, 6.5966735965373763e-04, - -7.4779609092899315e-06, 3.5393466478226404e-04, 1.7704726007174729e-05, 1.6382516606644185e-05, 4.1749764935150647e-06, -6.3547404895491045e-17, - -5.1295357548712922e-04, -2.7521036368747691e-04, 1.5668491170627079e-05, 6.5301043019852262e-04, 8.3756457236890595e-06, 3.5035380700139911e-04, - -1.9946616319957822e-05, 1.6222781764510503e-05, 3.2005306256819650e-06, 2.2995172754667680e-16, -4.2024623592899952e-04, -2.2547403683496499e-04, - 3.6177829984709971e-05, 5.3499027675668620e-04, 1.9370676929407923e-05, 2.8703747245083336e-04, -4.6055825421175033e-05, 1.3288392231881120e-05, - 1.9005356520037570e-06, 3.1362767201675851e-16, -2.7595668815097143e-04, -1.4805299908269591e-04, 4.5030778835311037e-05, 3.5130390791152642e-04, - 2.4117676294458697e-05, 1.8847739297140733e-04, -5.7325983606757273e-05, 8.7302227497018262e-06, 2.7620610285165812e-07, -2.5080839944164045e-17, - -1.2491297408360295e-04, -6.7053537941976415e-05, 3.9653588273064960e-05, 1.5901921507471145e-04, 2.1192021856326956e-05, 8.5361837309139718e-05, - -5.0480604823932580e-05, 3.9233331137339112e-06, -1.6763676439127430e-06, -1.9950606076705151e-17, -2.1186748034872204e-05, -1.1173638897301938e-05, - 1.7314566130892644e-05, 2.6971578150237605e-05, 9.3854234968676341e-06, 1.4224489489855110e-05, -2.2042135620260495e-05, 8.1993829229793671e-07, - -3.9368034886668810e-06, 1.3826372781016619e-17, -4.0904809409451714e-04, -4.9944248969747733e-05, -2.1943276528526315e-04, 5.2073459404797934e-04, - -2.6835819804019046e-05, 6.3581027727065517e-05, 2.7934669199371020e-04, 4.8277858685077774e-06, 1.2959979779994376e-05, 6.9723122910651338e-17, - -9.9858541584180540e-04, -1.2197991056199567e-04, -1.2197991056206587e-04, 1.2712391981478468e-03, -1.4892793976961156e-05, 1.5528530782951420e-04, - 1.5528530782953203e-04, 1.2151963571855302e-05, 1.2151963571851188e-05, 5.5315123985650645e-17, -1.2650670719583249e-03, -1.5452803962138343e-04, - -3.3989146299085161e-05, 1.6104810110849606e-03, -4.1472845964592906e-06, 1.9672037871097946e-04, 4.3269543497749215e-05, 1.5346594041114546e-05, - 1.0513071189119953e-05, 8.1224921361588226e-17, -1.2522942054227102e-03, -1.5296725544019501e-04, 3.8195274286687170e-05, 1.5942206408098643e-03, - 4.6718088449734621e-06, 1.9473343798517319e-04, -4.8624112756910573e-05, 1.5201005557162338e-05, 8.0589243504866540e-06, 1.2646430323484297e-16, - -1.0259673331826800e-03, -1.2532171759625012e-04, 8.8249173983067660e-05, 1.3060974747577253e-03, 1.0787713458074866e-05, 1.5953956192457048e-04, - -1.1234473024707882e-04, 1.2449879038406603e-05, 4.7859185315923841e-06, 1.2492617262243828e-16, -6.7370284092416264e-04, -8.2291875715507218e-05, - 1.0985003716686473e-04, 8.5765067834920466e-04, 1.3428120325720441e-05, 1.0476085113908371e-04, -1.3984349355511364e-04, 8.1833370321413966e-06, - 6.9543751779662684e-07, 7.0997481676593796e-17, -3.0500488785042019e-04, -3.7252512702599006e-05, 9.6677053695450602e-05, 3.8828342864919080e-04, - 1.1825246932944356e-05, 4.7423939530637341e-05, -1.2307375840803705e-04, 3.6677659788390534e-06, -4.2161030397036606e-06, -3.8675472809755950e-18, - -5.1280526705659661e-05, -6.2839193715145735e-06, 4.2430283014355643e-05, 6.5282162763118009e-05, 5.1630088156727532e-06, 7.9996808448424854e-06, - -5.4015448353894996e-05, 7.5571876572633797e-07, -9.9330071707124047e-06, -8.6830981711185261e-17, -5.1818273509495415e-04, -1.3907438669079623e-05, - -2.7802320360142870e-04, 6.5966735965313611e-04, -7.4779609092294263e-06, 1.7704726006891892e-05, 3.5393466478249959e-04, 4.1749764934271104e-06, - 1.6382516606623020e-05, 4.0749186165041001e-17, -1.2650670719581497e-03, -3.3989146299039705e-05, -1.5452803962143685e-04, 1.6104810110848080e-03, - -4.1472845964594609e-06, 4.3269543497699613e-05, 1.9672037871103638e-04, 1.0513071189135437e-05, 1.5346594041119834e-05, 7.9240261984326072e-17, - -1.6026670347201000e-03, -4.3053493382510712e-05, -4.3053493382558044e-05, 2.0402592745641132e-03, -1.1564832204205967e-06, 5.4808820093699731e-05, - 5.4808820093733822e-05, 1.3279889860017377e-05, 1.3279889860022863e-05, 9.2097956645809326e-17, -1.5864825433925698e-03, -4.2619862890565045e-05, - 4.8395012432343505e-05, 2.0196557693944101e-03, 1.3017448917312349e-06, 5.4256791123399684e-05, -6.1608787613830381e-05, 1.3153443349271750e-05, - 1.0179488166753925e-05, 1.0205130438863518e-16, -1.2997582939416842e-03, -3.4916529755849637e-05, 1.1180845736502144e-04, 1.6546443250261163e-03, - 3.0057340765579082e-06, 4.4450139752483907e-05, -1.4233664084413466e-04, 1.0772906330799025e-05, 6.0455797587637271e-06, 9.1330888093378114e-17, - -8.5348426805717222e-04, -2.2928719752622003e-05, 1.3917704869122568e-04, 1.0865196300130122e-03, 3.7402936569764150e-06, 2.9189177861487167e-05, - -1.7717795290418068e-04, 7.0805126791898829e-06, 8.7830508376714211e-07, 5.6615583707764242e-17, -3.8639859219410038e-04, -1.0375616284744785e-05, - 1.2249026701637098e-04, 4.9190087168677211e-04, 3.2966811714911069e-06, 1.3208574766734493e-05, -1.5593501202052922e-04, 3.1755470736365147e-06, - -5.3221282290210776e-06, 5.8555555451602192e-18, -6.4987942613438211e-05, -1.7584195977303762e-06, 5.3733951100266865e-05, 8.2732251790000952e-05, - 1.4372749293382423e-06, 2.2385385205262093e-06, -6.8405470204461853e-05, 6.5629254036916556e-07, -1.2558648067133677e-05, -6.2643782381705725e-17, - -5.1295357548637873e-04, 1.5668491170882496e-05, -2.7521036368765222e-04, 6.5301043019802346e-04, 8.3756457234651734e-06, -1.9946616319747704e-05, - 3.5035380700151241e-04, 3.2005306256888069e-06, 1.6222781764533938e-05, 1.1021652978936597e-16, -1.2522942054223754e-03, 3.8195274286697429e-05, - -1.5296725544028156e-04, 1.5942206408096325e-03, 4.6718088449811464e-06, -4.8624112756891437e-05, 1.9473343798523865e-04, 8.0589243504738045e-06, - 1.5201005557168734e-05, 8.5918816888484507e-17, -1.5864825433924558e-03, 4.8395012432365846e-05, -4.2619862890609910e-05, 2.0196557693943381e-03, - 1.3017448917293096e-06, -6.1608787613840504e-05, 5.4256791123429228e-05, 1.0179488166751226e-05, 1.3153443349275177e-05, 8.8436997644373772e-17, - -1.5704614601383636e-03, 4.7905128339743241e-05, 4.7905128339721455e-05, 1.9992602892418077e-03, -1.4574932682125792e-06, -6.0985145558572417e-05, - -6.0985145558559136e-05, 1.0082546116344673e-05, 1.0082546116347507e-05, 8.7079524843457519e-17, -1.2866320417064825e-03, 3.9248066346110315e-05, - 1.1067785968105715e-04, 1.6379340806129848e-03, -3.3712632304338978e-06, -4.9964359181647862e-05, -1.4089734474548839e-04, 8.2578616887689264e-06, - 5.9880257100210153e-06, 7.5321941371283178e-17, -8.4486437881703771e-04, 2.5771383674393462e-05, 1.3776937488854907e-04, 1.0755461660389958e-03, - -4.1977162667747768e-06, -3.2808002798411447e-05, -1.7538592781772406e-04, 5.4274990248750375e-06, 8.6992119349358339e-07, 5.0348534537109036e-17, - -3.8249295195446459e-04, 1.1673090903164162e-05, 1.2125163449742982e-04, 4.8692883535647754e-04, -3.6878033555764420e-06, -1.4860311881417390e-05, - -1.5435818325335691e-04, 2.4339111771927973e-06, -5.2720559362171523e-06, 1.5157875640171339e-17, -6.4327335572091798e-05, 1.9416918503506198e-06, - 5.3193484611823988e-05, 8.1891272588506745e-05, -1.6349233391438523e-06, -2.4718514327569146e-06, -6.7717434735062581e-05, 5.0282216664009615e-07, - -1.2435436975576558e-05, -9.9002448715467669e-18, -4.2024623592846105e-04, 3.6177829984429400e-05, -2.2547403683507238e-04, 5.3499027675656065e-04, - 1.9370676929591888e-05, -4.6055825421170601e-05, 2.8703747245078457e-04, 1.9005356520859239e-06, 1.3288392231919035e-05, 9.9271504070519187e-17, - -1.0259673331823702e-03, 8.8249173983027626e-05, -1.2532171759632019e-04, 1.3060974747575818e-03, 1.0787713458090848e-05, -1.1234473024706425e-04, - 1.5953956192458536e-04, 4.7859185315675474e-06, 1.2449879038409287e-05, 7.5617121957013773e-17, -1.2997582939415506e-03, 1.1180845736501496e-04, - -3.4916529755881803e-05, 1.6546443250260369e-03, 3.0057340765646887e-06, -1.4233664084413027e-04, 4.4450139752502529e-05, 6.0455797587646961e-06, - 1.0772906330801502e-05, 7.4237365136813508e-17, -1.2866320417064361e-03, 1.1067785968106318e-04, 3.9248066346090854e-05, 1.6379340806129577e-03, - -3.3712632304321939e-06, -1.4089734474549226e-04, -4.9964359181636593e-05, 5.9880257100190332e-06, 8.2578616887703291e-06, 7.2093480822636435e-17, - -1.0540980928973197e-03, 9.0676106148561848e-05, 9.0676106148553960e-05, 1.3419090576788013e-03, -7.7938401140048707e-06, -1.1543431202056919e-04, - -1.1543431202056450e-04, 4.9043496343493622e-06, 4.9043496343501398e-06, 6.3037991309102385e-17, -6.9217011202356304e-04, 5.9541218839865003e-05, - 1.1287158611772119e-04, 8.8116025352627286e-04, -9.7032178227066747e-06, -7.5798354446155174e-05, -1.4369004629315670e-04, 3.2234047118027443e-06, - 7.1260045700449238e-07, 4.4875646352635977e-17, -3.1336327392571109e-04, 2.6963244897811973e-05, 9.9338449335989494e-05, 3.9892398862896702e-04, - -8.5312831858724501e-06, -3.4325289834583248e-05, -1.2646182156855073e-04, 1.4457563333310716e-06, -4.3177809666449573e-06, 2.0591662977301158e-17, - -5.2701904096224544e-05, 4.5069561575177094e-06, 4.3578076238989909e-05, 6.7091633065451405e-05, -3.7645201112378417e-06, -5.7375355586665948e-06, - -5.5476635063979589e-05, 2.9887242508465092e-07, -1.0186424686089527e-05, -4.2994398398959147e-18, -2.7595668815092784e-04, 4.5030778835202332e-05, - -1.4805299908260343e-04, 3.5130390791139420e-04, 2.4117676294505365e-05, -5.7325983606700216e-05, 1.8847739297142972e-04, 2.7620610285355521e-07, - 8.7302227496579397e-06, 2.2068417882700666e-17, -6.7370284092403904e-04, 1.0985003716684141e-04, -8.2291875715501757e-05, 8.5765067834911381e-04, - 1.3428120325718364e-05, -1.3984349355510245e-04, 1.0476085113909073e-04, 6.9543751780616676e-07, 8.1833370321377933e-06, 4.8437492265353730e-17, - -8.5348426805707486e-04, 1.3917704869120990e-04, -2.2928719752636328e-05, 1.0865196300129493e-03, 3.7402936569831785e-06, -1.7717795290417499e-04, - 2.9189177861496532e-05, 8.7830508376708133e-07, 7.0805126791911475e-06, 5.2844436006943742e-17, -8.4486437881698816e-04, 1.3776937488854695e-04, - 2.5771383674380513e-05, 1.0755461660389629e-03, -4.1977162667738222e-06, -1.7538592781772452e-04, -3.2808002798403451e-05, 8.6992119349322436e-07, - 5.4274990248764156e-06, 5.3857020936747595e-17, -6.9217011202354765e-04, 1.1287158611772247e-04, 5.9541218839857820e-05, 8.8116025352626148e-04, - -9.7032178227062241e-06, -1.4369004629315852e-04, -7.5798354446150322e-05, 7.1260045700381200e-07, 3.2234047118037552e-06, 4.7224205907133811e-17, - -4.5451002284198453e-04, 7.4115147977006358e-05, 7.4115147977004203e-05, 5.7860944874782883e-04, -1.2080644800994201e-05, -9.4351549492118655e-05, - -9.4351549492116771e-05, 4.6835828133488412e-07, 4.6835828133561553e-07, 3.4282674743364552e-17, -2.0576429737189132e-04, 3.3563630657697868e-05, - 6.5229065397315528e-05, 2.6194618532257558e-04, -1.0621583438880923e-05, -4.2727845056957630e-05, -8.3039210743648229e-05, 2.0994736147339859e-07, - -2.8385484135676012e-06, 1.7422616860709244e-17, -3.4602943899175216e-05, 5.6125950401316104e-06, 2.8616778662176850e-05, 4.4050932407094513e-05, - -4.6829279478430336e-06, -7.1450581043514569e-06, -3.6430304491689317e-05, 4.3342012469426337e-08, -6.6915544801017071e-06, -3.5904178472779480e-18, - -1.2491297408348596e-04, 3.9653588273158940e-05, -6.7053537942000783e-05, 1.5901921507466678e-04, 2.1192021856246867e-05, -5.0480604823934877e-05, - 8.5361837309134270e-05, -1.6763676439549742e-06, 3.9233331137395939e-06, 4.4671544762584355e-18, -3.0500488785035785e-04, 9.6677053695436562e-05, - -3.7252512702608323e-05, 3.8828342864913893e-04, 1.1825246932935438e-05, -1.2307375840802916e-04, 4.7423939530636514e-05, -4.2161030396958425e-06, - 3.6677659788430429e-06, 2.4128934571038136e-17, -3.8639859219403587e-04, 1.2249026701636486e-04, -1.0375616284750664e-05, 4.9190087168672289e-04, - 3.2966811714913877e-06, -1.5593501202052686e-04, 1.3208574766736104e-05, -5.3221282290233434e-06, 3.1755470736278715e-06, 3.1432284870142483e-17, - -3.8249295195442838e-04, 1.2125163449742528e-04, 1.1673090903159696e-05, 4.8692883535644642e-04, -3.6878033555725236e-06, -1.5435818325335593e-04, - -1.4860311881412347e-05, -5.2720559362166873e-06, 2.4339111771886909e-06, 3.2077275460478534e-17, -3.1336327392569852e-04, 9.9338449335986784e-05, - 2.6963244897806884e-05, 3.9892398862895548e-04, -8.5312831858720622e-06, -1.2646182156854913e-04, -3.4325289834580172e-05, -4.3177809666453419e-06, - 1.4457563333301612e-06, 2.8122834349512110e-17, -2.0576429737189064e-04, 6.5229065397313983e-05, 3.3563630657696838e-05, 2.6194618532257119e-04, - -1.0621583438879969e-05, -8.3039210743649097e-05, -4.2727845056955679e-05, -2.8385484135681285e-06, 2.0994736147304273e-07, 2.0500639862063439e-17, - -9.3151209302059127e-05, 2.9542138267396792e-05, 2.9542138267397802e-05, 1.1858521738957481e-04, -9.3312153718748475e-06, -3.7608324302396471e-05, - -3.7608324302396125e-05, -1.2706382352886107e-06, -1.2706382352886850e-06, 1.0852179600489556e-17, -1.5684011184944028e-05, 4.9183748803106635e-06, - 1.2939562203297638e-05, 1.9966373918734288e-05, -4.1420646084805540e-06, -6.2612880579344652e-06, -1.6472580531169222e-05, -2.6020768542684102e-07, - -3.0088387502362375e-06, 2.9995937327780627e-18, -2.1186748034736431e-05, 1.7314566130796099e-05, -1.1173638897437015e-05, 2.6971578150202090e-05, - 9.3854234968672513e-06, -2.2042135620263812e-05, 1.4224489489858336e-05, -3.9368034887195114e-06, 8.1993829231012340e-07, 7.6416996781065047e-18, - -5.1280526705648921e-05, 4.2430283014323821e-05, -6.2839193714807337e-06, 6.5282162763124067e-05, 5.1630088157216431e-06, -5.4015448353865011e-05, - 7.9996808448244386e-06, -9.9330071707169702e-06, 7.5571876571604143e-07, 9.7641800636517703e-18, -6.4987942613452184e-05, 5.3733951100238621e-05, - -1.7584195977080992e-06, 8.2732251789935588e-05, 1.4372749293546847e-06, -6.8405470204479200e-05, 2.2385385205287847e-06, -1.2558648067127453e-05, - 6.5629254041339423e-07, 9.0893247680704442e-18, -6.4327335572037439e-05, 5.3193484611841084e-05, 1.9416918503227109e-06, 8.1891272588485915e-05, - -1.6349233391667857e-06, -6.7717434735056211e-05, -2.4718514327320817e-06, -1.2435436975574417e-05, 5.0282216664938090e-07, 9.9415504832613775e-18, - -5.2701904096233008e-05, 4.3578076238977095e-05, 4.5069561575094119e-06, 6.7091633065443219e-05, -3.7645201112378235e-06, -5.5476635063977041e-05, - -5.7375355586687267e-06, -1.0186424686092530e-05, 2.9887242509399168e-07, 8.8524613742982187e-18, -3.4602943899185231e-05, 2.8616778662172665e-05, - 5.6125950401316646e-06, 4.4050932407092101e-05, -4.6829279478433995e-06, -3.6430304491688470e-05, -7.1450581043495511e-06, -6.6915544801019002e-06, - 4.3342012473073687e-08, 6.6378527613512372e-18, -1.5684011184945674e-05, 1.2939562203297628e-05, 4.9183748803111208e-06, 1.9966373918733990e-05, - -4.1420646084811334e-06, -1.6472580531168789e-05, -6.2612880579338876e-06, -3.0088387502362185e-06, -2.6020768542654058e-07, 3.8580014055187301e-18, - -2.4631643688340385e-06, 2.2363599383471548e-06, 2.2363599383472056e-06, 3.1357068183325297e-06, -1.7612712352079330e-06, -2.8469757015205160e-06, - -2.8469757015205410e-06, -6.3071636577514211e-07, -6.3071636577518499e-07, 1.2372631589442725e-18, + -1.6736386918814842e-04, -8.9993566755474939e-05, -8.9993566755553327e-05, + 2.1306090344382802e-04, -4.8127663587508573e-05, 1.1456541205790448e-04, + 1.1456541205785753e-04, 5.1386806341961409e-06, 5.1386806342542322e-06, + 1.3021735293941976e-16, -4.0904809409466058e-04, -2.1943276528524800e-04, + -4.9944248969825226e-05, 5.2073459404767034e-04, -2.6835819803993821e-05, + 2.7934669199395864e-04, 6.3581027727126449e-05, 1.2959979779996389e-05, + 4.8277858685092419e-06, 2.5963965559206471e-18, -5.1818273509544963e-04, + -2.7802320360133129e-04, -1.3907438669093784e-05, 6.5966735965373763e-04, + -7.4779609092899315e-06, 3.5393466478226404e-04, 1.7704726007174729e-05, + 1.6382516606644185e-05, 4.1749764935150647e-06, -6.3547404895491045e-17, + -5.1295357548712922e-04, -2.7521036368747691e-04, 1.5668491170627079e-05, + 6.5301043019852262e-04, 8.3756457236890595e-06, 3.5035380700139911e-04, + -1.9946616319957822e-05, 1.6222781764510503e-05, 3.2005306256819650e-06, + 2.2995172754667680e-16, -4.2024623592899952e-04, -2.2547403683496499e-04, + 3.6177829984709971e-05, 5.3499027675668620e-04, 1.9370676929407923e-05, + 2.8703747245083336e-04, -4.6055825421175033e-05, 1.3288392231881120e-05, + 1.9005356520037570e-06, 3.1362767201675851e-16, -2.7595668815097143e-04, + -1.4805299908269591e-04, 4.5030778835311037e-05, 3.5130390791152642e-04, + 2.4117676294458697e-05, 1.8847739297140733e-04, -5.7325983606757273e-05, + 8.7302227497018262e-06, 2.7620610285165812e-07, -2.5080839944164045e-17, + -1.2491297408360295e-04, -6.7053537941976415e-05, 3.9653588273064960e-05, + 1.5901921507471145e-04, 2.1192021856326956e-05, 8.5361837309139718e-05, + -5.0480604823932580e-05, 3.9233331137339112e-06, -1.6763676439127430e-06, + -1.9950606076705151e-17, -2.1186748034872204e-05, -1.1173638897301938e-05, + 1.7314566130892644e-05, 2.6971578150237605e-05, 9.3854234968676341e-06, + 1.4224489489855110e-05, -2.2042135620260495e-05, 8.1993829229793671e-07, + -3.9368034886668810e-06, 1.3826372781016619e-17, -4.0904809409451714e-04, + -4.9944248969747733e-05, -2.1943276528526315e-04, 5.2073459404797934e-04, + -2.6835819804019046e-05, 6.3581027727065517e-05, 2.7934669199371020e-04, + 4.8277858685077774e-06, 1.2959979779994376e-05, 6.9723122910651338e-17, + -9.9858541584180540e-04, -1.2197991056199567e-04, -1.2197991056206587e-04, + 1.2712391981478468e-03, -1.4892793976961156e-05, 1.5528530782951420e-04, + 1.5528530782953203e-04, 1.2151963571855302e-05, 1.2151963571851188e-05, + 5.5315123985650645e-17, -1.2650670719583249e-03, -1.5452803962138343e-04, + -3.3989146299085161e-05, 1.6104810110849606e-03, -4.1472845964592906e-06, + 1.9672037871097946e-04, 4.3269543497749215e-05, 1.5346594041114546e-05, + 1.0513071189119953e-05, 8.1224921361588226e-17, -1.2522942054227102e-03, + -1.5296725544019501e-04, 3.8195274286687170e-05, 1.5942206408098643e-03, + 4.6718088449734621e-06, 1.9473343798517319e-04, -4.8624112756910573e-05, + 1.5201005557162338e-05, 8.0589243504866540e-06, 1.2646430323484297e-16, + -1.0259673331826800e-03, -1.2532171759625012e-04, 8.8249173983067660e-05, + 1.3060974747577253e-03, 1.0787713458074866e-05, 1.5953956192457048e-04, + -1.1234473024707882e-04, 1.2449879038406603e-05, 4.7859185315923841e-06, + 1.2492617262243828e-16, -6.7370284092416264e-04, -8.2291875715507218e-05, + 1.0985003716686473e-04, 8.5765067834920466e-04, 1.3428120325720441e-05, + 1.0476085113908371e-04, -1.3984349355511364e-04, 8.1833370321413966e-06, + 6.9543751779662684e-07, 7.0997481676593796e-17, -3.0500488785042019e-04, + -3.7252512702599006e-05, 9.6677053695450602e-05, 3.8828342864919080e-04, + 1.1825246932944356e-05, 4.7423939530637341e-05, -1.2307375840803705e-04, + 3.6677659788390534e-06, -4.2161030397036606e-06, -3.8675472809755950e-18, + -5.1280526705659661e-05, -6.2839193715145735e-06, 4.2430283014355643e-05, + 6.5282162763118009e-05, 5.1630088156727532e-06, 7.9996808448424854e-06, + -5.4015448353894996e-05, 7.5571876572633797e-07, -9.9330071707124047e-06, + -8.6830981711185261e-17, -5.1818273509495415e-04, -1.3907438669079623e-05, + -2.7802320360142870e-04, 6.5966735965313611e-04, -7.4779609092294263e-06, + 1.7704726006891892e-05, 3.5393466478249959e-04, 4.1749764934271104e-06, + 1.6382516606623020e-05, 4.0749186165041001e-17, -1.2650670719581497e-03, + -3.3989146299039705e-05, -1.5452803962143685e-04, 1.6104810110848080e-03, + -4.1472845964594609e-06, 4.3269543497699613e-05, 1.9672037871103638e-04, + 1.0513071189135437e-05, 1.5346594041119834e-05, 7.9240261984326072e-17, + -1.6026670347201000e-03, -4.3053493382510712e-05, -4.3053493382558044e-05, + 2.0402592745641132e-03, -1.1564832204205967e-06, 5.4808820093699731e-05, + 5.4808820093733822e-05, 1.3279889860017377e-05, 1.3279889860022863e-05, + 9.2097956645809326e-17, -1.5864825433925698e-03, -4.2619862890565045e-05, + 4.8395012432343505e-05, 2.0196557693944101e-03, 1.3017448917312349e-06, + 5.4256791123399684e-05, -6.1608787613830381e-05, 1.3153443349271750e-05, + 1.0179488166753925e-05, 1.0205130438863518e-16, -1.2997582939416842e-03, + -3.4916529755849637e-05, 1.1180845736502144e-04, 1.6546443250261163e-03, + 3.0057340765579082e-06, 4.4450139752483907e-05, -1.4233664084413466e-04, + 1.0772906330799025e-05, 6.0455797587637271e-06, 9.1330888093378114e-17, + -8.5348426805717222e-04, -2.2928719752622003e-05, 1.3917704869122568e-04, + 1.0865196300130122e-03, 3.7402936569764150e-06, 2.9189177861487167e-05, + -1.7717795290418068e-04, 7.0805126791898829e-06, 8.7830508376714211e-07, + 5.6615583707764242e-17, -3.8639859219410038e-04, -1.0375616284744785e-05, + 1.2249026701637098e-04, 4.9190087168677211e-04, 3.2966811714911069e-06, + 1.3208574766734493e-05, -1.5593501202052922e-04, 3.1755470736365147e-06, + -5.3221282290210776e-06, 5.8555555451602192e-18, -6.4987942613438211e-05, + -1.7584195977303762e-06, 5.3733951100266865e-05, 8.2732251790000952e-05, + 1.4372749293382423e-06, 2.2385385205262093e-06, -6.8405470204461853e-05, + 6.5629254036916556e-07, -1.2558648067133677e-05, -6.2643782381705725e-17, + -5.1295357548637873e-04, 1.5668491170882496e-05, -2.7521036368765222e-04, + 6.5301043019802346e-04, 8.3756457234651734e-06, -1.9946616319747704e-05, + 3.5035380700151241e-04, 3.2005306256888069e-06, 1.6222781764533938e-05, + 1.1021652978936597e-16, -1.2522942054223754e-03, 3.8195274286697429e-05, + -1.5296725544028156e-04, 1.5942206408096325e-03, 4.6718088449811464e-06, + -4.8624112756891437e-05, 1.9473343798523865e-04, 8.0589243504738045e-06, + 1.5201005557168734e-05, 8.5918816888484507e-17, -1.5864825433924558e-03, + 4.8395012432365846e-05, -4.2619862890609910e-05, 2.0196557693943381e-03, + 1.3017448917293096e-06, -6.1608787613840504e-05, 5.4256791123429228e-05, + 1.0179488166751226e-05, 1.3153443349275177e-05, 8.8436997644373772e-17, + -1.5704614601383636e-03, 4.7905128339743241e-05, 4.7905128339721455e-05, + 1.9992602892418077e-03, -1.4574932682125792e-06, -6.0985145558572417e-05, + -6.0985145558559136e-05, 1.0082546116344673e-05, 1.0082546116347507e-05, + 8.7079524843457519e-17, -1.2866320417064825e-03, 3.9248066346110315e-05, + 1.1067785968105715e-04, 1.6379340806129848e-03, -3.3712632304338978e-06, + -4.9964359181647862e-05, -1.4089734474548839e-04, 8.2578616887689264e-06, + 5.9880257100210153e-06, 7.5321941371283178e-17, -8.4486437881703771e-04, + 2.5771383674393462e-05, 1.3776937488854907e-04, 1.0755461660389958e-03, + -4.1977162667747768e-06, -3.2808002798411447e-05, -1.7538592781772406e-04, + 5.4274990248750375e-06, 8.6992119349358339e-07, 5.0348534537109036e-17, + -3.8249295195446459e-04, 1.1673090903164162e-05, 1.2125163449742982e-04, + 4.8692883535647754e-04, -3.6878033555764420e-06, -1.4860311881417390e-05, + -1.5435818325335691e-04, 2.4339111771927973e-06, -5.2720559362171523e-06, + 1.5157875640171339e-17, -6.4327335572091798e-05, 1.9416918503506198e-06, + 5.3193484611823988e-05, 8.1891272588506745e-05, -1.6349233391438523e-06, + -2.4718514327569146e-06, -6.7717434735062581e-05, 5.0282216664009615e-07, + -1.2435436975576558e-05, -9.9002448715467669e-18, -4.2024623592846105e-04, + 3.6177829984429400e-05, -2.2547403683507238e-04, 5.3499027675656065e-04, + 1.9370676929591888e-05, -4.6055825421170601e-05, 2.8703747245078457e-04, + 1.9005356520859239e-06, 1.3288392231919035e-05, 9.9271504070519187e-17, + -1.0259673331823702e-03, 8.8249173983027626e-05, -1.2532171759632019e-04, + 1.3060974747575818e-03, 1.0787713458090848e-05, -1.1234473024706425e-04, + 1.5953956192458536e-04, 4.7859185315675474e-06, 1.2449879038409287e-05, + 7.5617121957013773e-17, -1.2997582939415506e-03, 1.1180845736501496e-04, + -3.4916529755881803e-05, 1.6546443250260369e-03, 3.0057340765646887e-06, + -1.4233664084413027e-04, 4.4450139752502529e-05, 6.0455797587646961e-06, + 1.0772906330801502e-05, 7.4237365136813508e-17, -1.2866320417064361e-03, + 1.1067785968106318e-04, 3.9248066346090854e-05, 1.6379340806129577e-03, + -3.3712632304321939e-06, -1.4089734474549226e-04, -4.9964359181636593e-05, + 5.9880257100190332e-06, 8.2578616887703291e-06, 7.2093480822636435e-17, + -1.0540980928973197e-03, 9.0676106148561848e-05, 9.0676106148553960e-05, + 1.3419090576788013e-03, -7.7938401140048707e-06, -1.1543431202056919e-04, + -1.1543431202056450e-04, 4.9043496343493622e-06, 4.9043496343501398e-06, + 6.3037991309102385e-17, -6.9217011202356304e-04, 5.9541218839865003e-05, + 1.1287158611772119e-04, 8.8116025352627286e-04, -9.7032178227066747e-06, + -7.5798354446155174e-05, -1.4369004629315670e-04, 3.2234047118027443e-06, + 7.1260045700449238e-07, 4.4875646352635977e-17, -3.1336327392571109e-04, + 2.6963244897811973e-05, 9.9338449335989494e-05, 3.9892398862896702e-04, + -8.5312831858724501e-06, -3.4325289834583248e-05, -1.2646182156855073e-04, + 1.4457563333310716e-06, -4.3177809666449573e-06, 2.0591662977301158e-17, + -5.2701904096224544e-05, 4.5069561575177094e-06, 4.3578076238989909e-05, + 6.7091633065451405e-05, -3.7645201112378417e-06, -5.7375355586665948e-06, + -5.5476635063979589e-05, 2.9887242508465092e-07, -1.0186424686089527e-05, + -4.2994398398959147e-18, -2.7595668815092784e-04, 4.5030778835202332e-05, + -1.4805299908260343e-04, 3.5130390791139420e-04, 2.4117676294505365e-05, + -5.7325983606700216e-05, 1.8847739297142972e-04, 2.7620610285355521e-07, + 8.7302227496579397e-06, 2.2068417882700666e-17, -6.7370284092403904e-04, + 1.0985003716684141e-04, -8.2291875715501757e-05, 8.5765067834911381e-04, + 1.3428120325718364e-05, -1.3984349355510245e-04, 1.0476085113909073e-04, + 6.9543751780616676e-07, 8.1833370321377933e-06, 4.8437492265353730e-17, + -8.5348426805707486e-04, 1.3917704869120990e-04, -2.2928719752636328e-05, + 1.0865196300129493e-03, 3.7402936569831785e-06, -1.7717795290417499e-04, + 2.9189177861496532e-05, 8.7830508376708133e-07, 7.0805126791911475e-06, + 5.2844436006943742e-17, -8.4486437881698816e-04, 1.3776937488854695e-04, + 2.5771383674380513e-05, 1.0755461660389629e-03, -4.1977162667738222e-06, + -1.7538592781772452e-04, -3.2808002798403451e-05, 8.6992119349322436e-07, + 5.4274990248764156e-06, 5.3857020936747595e-17, -6.9217011202354765e-04, + 1.1287158611772247e-04, 5.9541218839857820e-05, 8.8116025352626148e-04, + -9.7032178227062241e-06, -1.4369004629315852e-04, -7.5798354446150322e-05, + 7.1260045700381200e-07, 3.2234047118037552e-06, 4.7224205907133811e-17, + -4.5451002284198453e-04, 7.4115147977006358e-05, 7.4115147977004203e-05, + 5.7860944874782883e-04, -1.2080644800994201e-05, -9.4351549492118655e-05, + -9.4351549492116771e-05, 4.6835828133488412e-07, 4.6835828133561553e-07, + 3.4282674743364552e-17, -2.0576429737189132e-04, 3.3563630657697868e-05, + 6.5229065397315528e-05, 2.6194618532257558e-04, -1.0621583438880923e-05, + -4.2727845056957630e-05, -8.3039210743648229e-05, 2.0994736147339859e-07, + -2.8385484135676012e-06, 1.7422616860709244e-17, -3.4602943899175216e-05, + 5.6125950401316104e-06, 2.8616778662176850e-05, 4.4050932407094513e-05, + -4.6829279478430336e-06, -7.1450581043514569e-06, -3.6430304491689317e-05, + 4.3342012469426337e-08, -6.6915544801017071e-06, -3.5904178472779480e-18, + -1.2491297408348596e-04, 3.9653588273158940e-05, -6.7053537942000783e-05, + 1.5901921507466678e-04, 2.1192021856246867e-05, -5.0480604823934877e-05, + 8.5361837309134270e-05, -1.6763676439549742e-06, 3.9233331137395939e-06, + 4.4671544762584355e-18, -3.0500488785035785e-04, 9.6677053695436562e-05, + -3.7252512702608323e-05, 3.8828342864913893e-04, 1.1825246932935438e-05, + -1.2307375840802916e-04, 4.7423939530636514e-05, -4.2161030396958425e-06, + 3.6677659788430429e-06, 2.4128934571038136e-17, -3.8639859219403587e-04, + 1.2249026701636486e-04, -1.0375616284750664e-05, 4.9190087168672289e-04, + 3.2966811714913877e-06, -1.5593501202052686e-04, 1.3208574766736104e-05, + -5.3221282290233434e-06, 3.1755470736278715e-06, 3.1432284870142483e-17, + -3.8249295195442838e-04, 1.2125163449742528e-04, 1.1673090903159696e-05, + 4.8692883535644642e-04, -3.6878033555725236e-06, -1.5435818325335593e-04, + -1.4860311881412347e-05, -5.2720559362166873e-06, 2.4339111771886909e-06, + 3.2077275460478534e-17, -3.1336327392569852e-04, 9.9338449335986784e-05, + 2.6963244897806884e-05, 3.9892398862895548e-04, -8.5312831858720622e-06, + -1.2646182156854913e-04, -3.4325289834580172e-05, -4.3177809666453419e-06, + 1.4457563333301612e-06, 2.8122834349512110e-17, -2.0576429737189064e-04, + 6.5229065397313983e-05, 3.3563630657696838e-05, 2.6194618532257119e-04, + -1.0621583438879969e-05, -8.3039210743649097e-05, -4.2727845056955679e-05, + -2.8385484135681285e-06, 2.0994736147304273e-07, 2.0500639862063439e-17, + -9.3151209302059127e-05, 2.9542138267396792e-05, 2.9542138267397802e-05, + 1.1858521738957481e-04, -9.3312153718748475e-06, -3.7608324302396471e-05, + -3.7608324302396125e-05, -1.2706382352886107e-06, -1.2706382352886850e-06, + 1.0852179600489556e-17, -1.5684011184944028e-05, 4.9183748803106635e-06, + 1.2939562203297638e-05, 1.9966373918734288e-05, -4.1420646084805540e-06, + -6.2612880579344652e-06, -1.6472580531169222e-05, -2.6020768542684102e-07, + -3.0088387502362375e-06, 2.9995937327780627e-18, -2.1186748034736431e-05, + 1.7314566130796099e-05, -1.1173638897437015e-05, 2.6971578150202090e-05, + 9.3854234968672513e-06, -2.2042135620263812e-05, 1.4224489489858336e-05, + -3.9368034887195114e-06, 8.1993829231012340e-07, 7.6416996781065047e-18, + -5.1280526705648921e-05, 4.2430283014323821e-05, -6.2839193714807337e-06, + 6.5282162763124067e-05, 5.1630088157216431e-06, -5.4015448353865011e-05, + 7.9996808448244386e-06, -9.9330071707169702e-06, 7.5571876571604143e-07, + 9.7641800636517703e-18, -6.4987942613452184e-05, 5.3733951100238621e-05, + -1.7584195977080992e-06, 8.2732251789935588e-05, 1.4372749293546847e-06, + -6.8405470204479200e-05, 2.2385385205287847e-06, -1.2558648067127453e-05, + 6.5629254041339423e-07, 9.0893247680704442e-18, -6.4327335572037439e-05, + 5.3193484611841084e-05, 1.9416918503227109e-06, 8.1891272588485915e-05, + -1.6349233391667857e-06, -6.7717434735056211e-05, -2.4718514327320817e-06, + -1.2435436975574417e-05, 5.0282216664938090e-07, 9.9415504832613775e-18, + -5.2701904096233008e-05, 4.3578076238977095e-05, 4.5069561575094119e-06, + 6.7091633065443219e-05, -3.7645201112378235e-06, -5.5476635063977041e-05, + -5.7375355586687267e-06, -1.0186424686092530e-05, 2.9887242509399168e-07, + 8.8524613742982187e-18, -3.4602943899185231e-05, 2.8616778662172665e-05, + 5.6125950401316646e-06, 4.4050932407092101e-05, -4.6829279478433995e-06, + -3.6430304491688470e-05, -7.1450581043495511e-06, -6.6915544801019002e-06, + 4.3342012473073687e-08, 6.6378527613512372e-18, -1.5684011184945674e-05, + 1.2939562203297628e-05, 4.9183748803111208e-06, 1.9966373918733990e-05, + -4.1420646084811334e-06, -1.6472580531168789e-05, -6.2612880579338876e-06, + -3.0088387502362185e-06, -2.6020768542654058e-07, 3.8580014055187301e-18, + -2.4631643688340385e-06, 2.2363599383471548e-06, 2.2363599383472056e-06, + 3.1357068183325297e-06, -1.7612712352079330e-06, -2.8469757015205160e-06, + -2.8469757015205410e-06, -6.3071636577514211e-07, -6.3071636577518499e-07, + 1.2372631589442725e-18 }; return sol; } -static const double * -get_sol_3x_bias_p2_DxDx_PyPy(void) +static const double *get_sol_3x_bias_p2_DxDx_PyPy(void) { static const double sol[640] = { - 5.8616184533469527e-03, 3.1565760734898127e-03, 2.7094777984668392e-03, -7.4620748753877917e-03, 1.4328949642727182e-03, -4.0184476689694810e-03, - -3.4492736718164069e-03, -1.7632215123710278e-04, -5.2264298589365711e-04, 3.5131649393126775e-17, 5.8616184533454548e-03, 3.1565760734899480e-03, - -2.7094777984674428e-03, -7.4620748753869296e-03, -1.4328949642726360e-03, -4.0184476689695782e-03, 3.4492736718167269e-03, -1.7632215123710747e-04, - -5.2264298589345328e-04, 1.3113006726376057e-16, -5.8616184533450645e-03, -3.1565760734899063e-03, -2.7094777984659453e-03, 7.4620748753872505e-03, - -1.4328949642727893e-03, 4.0184476689695140e-03, 3.4492736718158296e-03, 1.7632215123710446e-04, 5.2264298589332133e-04, -6.7007510729665259e-16, - -5.8616184533434972e-03, -3.1565760734900798e-03, 2.7094777984662758e-03, 7.4620748753870840e-03, 1.4328949642727672e-03, 4.0184476689695556e-03, - -3.4492736718152593e-03, 1.7632215123710763e-04, 5.2264298589287594e-04, -1.2842098510653892e-15, 5.8616184533454565e-03, 3.1565760734899358e-03, - 2.7094777984669749e-03, -7.4620748753874231e-03, 1.4328949642725803e-03, -4.0184476689694975e-03, -3.4492736718174520e-03, -1.7632215123710847e-04, - -5.2264298589330311e-04, 2.1405198315438111e-16, 5.8616184533454088e-03, 3.1565760734899601e-03, -2.7094777984659605e-03, -7.4620748753875914e-03, - -1.4328949642728730e-03, -4.0184476689694984e-03, 3.4492736718165261e-03, -1.7632215123710143e-04, -5.2264298589249668e-04, 4.4941804705996507e-16, - -5.8616184533449344e-03, -3.1565760734899059e-03, -2.7094777984672976e-03, 7.4620748753882150e-03, -1.4328949642725777e-03, 4.0184476689694298e-03, - 3.4492736718163448e-03, 1.7632215123710584e-04, 5.2264298589430025e-04, -1.1539732792029041e-15, -5.8616184533448580e-03, -3.1565760734899163e-03, - 2.7094777984665547e-03, 7.4620748753871950e-03, 1.4328949642728101e-03, 4.0184476689695513e-03, -3.4492736718163097e-03, 1.7632215123710075e-04, - 5.2264298589368996e-04, -8.7123700173506059e-16, 1.4341205890542634e-02, 1.7536458636411641e-03, 6.5546632008048515e-03, -1.8256929039364878e-02, - 7.9551267430263116e-04, -2.2324613660129437e-03, -8.3443485748260857e-03, -1.6506737964353752e-04, -1.3363619667712365e-03, -1.1204417257716884e-16, - 1.4341205890541529e-02, 1.7536458636412541e-03, -6.5546632008052566e-03, -1.8256929039364305e-02, -7.9551267430259690e-04, -2.2324613660130101e-03, - 8.3443485748262783e-03, -1.6506737964354181e-04, -1.3363619667710529e-03, -2.9814579716794004e-17, -1.4341205890541050e-02, -1.7536458636412450e-03, - -6.5546632008041819e-03, 1.8256929039364444e-02, -7.9551267430269512e-04, 2.2324613660129719e-03, 8.3443485748256590e-03, 1.6506737964353847e-04, - 1.3363619667711248e-03, -4.3980537973069959e-16, -1.4341205890539973e-02, -1.7536458636413575e-03, 6.5546632008044474e-03, 1.8256929039364378e-02, - 7.9551267430268016e-04, 2.2324613660129871e-03, -8.3443485748254404e-03, 1.6506737964354083e-04, 1.3363619667708508e-03, -8.3643101508846570e-16, - 1.4341205890541506e-02, 1.7536458636412552e-03, 6.5546632008047102e-03, -1.8256929039364576e-02, 7.9551267430260947e-04, -2.2324613660129641e-03, - -8.3443485748265888e-03, -1.6506737964354324e-04, -1.3363619667710507e-03, -4.1976905387266643e-17, 1.4341205890541499e-02, 1.7536458636412508e-03, - -6.5546632008043762e-03, -1.8256929039364728e-02, -7.9551267430271193e-04, -2.2324613660129507e-03, 8.3443485748262540e-03, -1.6506737964353831e-04, - -1.3363619667707905e-03, 1.2001911151799687e-16, -1.4341205890540923e-02, -1.7536458636412493e-03, -6.5546632008049869e-03, 1.8256929039365152e-02, - -7.9551267430258573e-04, 2.2324613660129086e-03, 8.3443485748260250e-03, 1.6506737964353893e-04, 1.3363619667713777e-03, -7.5128207929077665e-16, - -1.4341205890540861e-02, -1.7536458636412447e-03, 6.5546632008047874e-03, 1.8256929039364479e-02, 7.9551267430266900e-04, 2.2324613660129867e-03, - -8.3443485748261013e-03, 1.6506737964353663e-04, 1.3363619667711953e-03, -5.9938370361699392e-16, 1.8173569455656034e-02, 4.8776519957604707e-04, - 8.2864356215894778e-03, -2.3135681230452648e-02, 2.2095135802113725e-04, -6.2094461961560558e-04, -1.0548964172698889e-02, -1.4276292489187592e-04, - -1.7088219069646235e-03, -2.2100584181581480e-16, 1.8173569455655188e-02, 4.8776519957610518e-04, -8.2864356215897883e-03, -2.3135681230452277e-02, - -2.2095135802111752e-04, -6.2094461961565469e-04, 1.0548964172699016e-02, -1.4276292489187839e-04, -1.7088219069644811e-03, -1.4876109397575244e-16, - -1.8173569455654716e-02, -4.8776519957612248e-04, -8.2864356215890025e-03, 2.3135681230452315e-02, -2.2095135802118989e-04, 6.2094461961563778e-04, - 1.0548964172698589e-02, 1.4276292489187435e-04, 1.7088219069645867e-03, -2.4290390950766229e-16, -1.8173569455653963e-02, -4.8776519957620059e-04, - 8.2864356215892210e-03, 2.3135681230452270e-02, 2.2095135802117612e-04, 6.2094461961563290e-04, -1.0548964172698514e-02, 1.4276292489187487e-04, - 1.7088219069644197e-03, -4.9858079137137815e-16, 1.8173569455655174e-02, 4.8776519957611424e-04, 8.2864356215893130e-03, -2.3135681230452416e-02, - 2.2095135802114696e-04, -6.2094461961562466e-04, -1.0548964172699123e-02, -1.4276292489187687e-04, -1.7088219069645082e-03, -2.1645988308624400e-16, - 1.8173569455655150e-02, 4.8776519957610638e-04, -8.2864356215892158e-03, -2.3135681230452523e-02, -2.2095135802118319e-04, -6.2094461961560764e-04, - 1.0548964172699019e-02, -1.4276292489187549e-04, -1.7088219069644247e-03, -9.9140963264315763e-17, -1.8173569455654598e-02, -4.8776519957612372e-04, - -8.2864356215895125e-03, 2.3135681230452829e-02, -2.2095135802112378e-04, 6.2094461961558758e-04, 1.0548964172698830e-02, 1.4276292489187435e-04, - 1.7088219069646298e-03, -4.4848074315116613e-16, -1.8173569455654511e-02, -4.8776519957611250e-04, 8.2864356215895073e-03, 2.3135681230452385e-02, - 2.2095135802115403e-04, 6.2094461961564071e-04, -1.0548964172698927e-02, 1.4276292489187402e-04, 1.7088219069645871e-03, -3.8396631432671612e-16, - 1.7990573879785168e-02, -5.5033150535898810e-04, 8.1929460267051273e-03, -2.2902720538814127e-02, -2.5005174898973937e-04, 7.0059403080543526e-04, - -1.0429948176920740e-02, -1.0938846751228960e-04, -1.6994005263250107e-03, -2.9381282230482898e-16, 1.7990573879784484e-02, -5.5033150535894278e-04, - -8.1929460267053771e-03, -2.2902720538813877e-02, 2.5005174898975357e-04, 7.0059403080541163e-04, 1.0429948176920835e-02, -1.0938846751228980e-04, - -1.6994005263248999e-03, -2.1887573342775259e-16, -1.7990573879784102e-02, 5.5033150535891903e-04, -8.1929460267048202e-03, 2.2902720538813891e-02, - 2.5005174898969345e-04, -7.0059403080540827e-04, 1.0429948176920542e-02, 1.0938846751228834e-04, 1.6994005263249875e-03, -9.5982628332163999e-17, - -1.7990573879783599e-02, 5.5033150535885561e-04, 8.1929460267049902e-03, 2.2902720538813839e-02, -2.5005174898970787e-04, -7.0059403080540989e-04, - -1.0429948176920533e-02, 1.0938846751229020e-04, 1.6994005263248945e-03, -2.6117596237755658e-16, 1.7990573879784501e-02, -5.5033150535894180e-04, - 8.1929460267050076e-03, -2.2902720538813939e-02, -2.5005174898971990e-04, 7.0059403080542258e-04, -1.0429948176920834e-02, -1.0938846751229017e-04, - -1.6994005263249294e-03, -2.9830977257397701e-16, 1.7990573879784477e-02, -5.5033150535894039e-04, -8.1929460267049954e-03, -2.2902720538814009e-02, - 2.5005174898970760e-04, 7.0059403080542919e-04, 1.0429948176920820e-02, -1.0938846751228923e-04, -1.6994005263249057e-03, -2.2477885568782595e-16, - -1.7990573879783998e-02, 5.5033150535891339e-04, -8.1929460267051394e-03, 2.2902720538814262e-02, 2.5005174898973828e-04, -7.0059403080544437e-04, - 1.0429948176920719e-02, 1.0938846751228730e-04, 1.6994005263249799e-03, -2.4211931635057277e-16, -1.7990573879783870e-02, 5.5033150535892814e-04, - 8.1929460267052071e-03, 2.2902720538813964e-02, -2.5005174898972549e-04, -7.0059403080541304e-04, -1.0429948176920808e-02, 1.0938846751228806e-04, - 1.6994005263249764e-03, -2.2479850252782248e-16, 1.4738458963226696e-02, -1.2698766175711731e-03, 6.7039542837525066e-03, -1.8762648099116208e-02, - -5.7647737886046312e-04, 1.6166037551301662e-03, -8.5344020981064049e-03, -6.4925612047121364e-05, -1.3983785661310436e-03, -3.1436539032981156e-16, - 1.4738458963226148e-02, -1.2698766175711388e-03, -6.7039542837527217e-03, -1.8762648099116017e-02, 5.7647737886047179e-04, 1.6166037551301536e-03, - 8.5344020981064830e-03, -6.4925612047123370e-05, -1.3983785661309629e-03, -2.2651529080434071e-16, -1.4738458963225858e-02, 1.2698766175711083e-03, - -6.7039542837523470e-03, 1.8762648099116059e-02, 5.7647737886042745e-04, -1.6166037551301447e-03, 8.5344020981062939e-03, 6.4925612047122083e-05, - 1.3983785661310230e-03, -2.6426688005693668e-18, -1.4738458963225537e-02, 1.2698766175710658e-03, 6.7039542837524684e-03, 1.8762648099116003e-02, - -5.7647737886044100e-04, -1.6166037551301432e-03, -8.5344020981063112e-03, 6.4925612047124061e-05, 1.3983785661309737e-03, -1.0693961517654768e-16, - 1.4738458963226163e-02, -1.2698766175711421e-03, 6.7039542837524580e-03, -1.8762648099116073e-02, -5.7647737886044490e-04, 1.6166037551301495e-03, - -8.5344020981064517e-03, -6.4925612047124346e-05, -1.3983785661309850e-03, -2.9001981455784633e-16, 1.4738458963226148e-02, -1.2698766175711347e-03, - -6.7039542837524701e-03, -1.8762648099116111e-02, 5.7647737886044295e-04, 1.6166037551301597e-03, 8.5344020981064691e-03, -6.4925612047121879e-05, - -1.3983785661309876e-03, -2.6297640124286923e-16, -1.4738458963225773e-02, 1.2698766175711076e-03, -6.7039542837525265e-03, 1.8762648099116309e-02, - 5.7647737886046138e-04, -1.6166037551301768e-03, 8.5344020981064049e-03, 6.4925612047123655e-05, 1.3983785661310136e-03, -1.1897205361844484e-16, - -1.4738458963225598e-02, 1.2698766175711174e-03, 6.7039542837526315e-03, 1.8762648099116094e-02, -5.7647737886045455e-04, -1.6166037551301579e-03, - -8.5344020981064795e-03, 6.4925612047122815e-05, 1.3983785661310164e-03, -1.2970455818161604e-16, 9.6780483124899331e-03, -1.5800101497750775e-03, - 4.3916291488594571e-03, -1.2320542821102249e-02, -7.1712350226570088e-04, 2.0114161532917741e-03, -5.5907196612254642e-03, -9.3539679266368939e-06, - -9.2641347200032116e-04, -2.8000043592001863e-16, 9.6780483124894682e-03, -1.5800101497750636e-03, -4.3916291488596462e-03, -1.2320542821102098e-02, - 7.1712350226570555e-04, 2.0114161532917641e-03, 5.5907196612255249e-03, -9.3539679266382915e-06, -9.2641347200025893e-04, -1.7598141661156963e-16, - -9.6780483124893086e-03, 1.5800101497750179e-03, -4.3916291488593964e-03, 1.2320542821102162e-02, 7.1712350226567508e-04, -2.0114161532917589e-03, - 5.5907196612253905e-03, 9.3539679266371463e-06, 9.2641347200030392e-04, 4.0721693196094477e-17, -9.6780483124891143e-03, 1.5800101497749840e-03, - 4.3916291488594753e-03, 1.2320542821102124e-02, -7.1712350226568712e-04, -2.0114161532917519e-03, -5.5907196612254156e-03, 9.3539679266377680e-06, - 9.2641347200027888e-04, -2.4654046496217829e-17, 9.6780483124894769e-03, -1.5800101497750604e-03, 4.3916291488594718e-03, -1.2320542821102155e-02, - -7.1712350226568169e-04, 2.0114161532917675e-03, -5.5907196612254920e-03, -9.3539679266380458e-06, -9.2641347200028029e-04, -2.2870225702025344e-16, - 9.6780483124894959e-03, -1.5800101497750504e-03, -4.3916291488594770e-03, -1.2320542821102181e-02, 7.1712350226568690e-04, 2.0114161532917693e-03, - 5.5907196612255145e-03, -9.3539679266376545e-06, -9.2641347200029232e-04, -2.2829444272414866e-16, -9.6780483124892132e-03, 1.5800101497750205e-03, - -4.3916291488594935e-03, 1.2320542821102315e-02, 7.1712350226569264e-04, -2.0114161532917840e-03, 5.5907196612254538e-03, 9.3539679266373140e-06, - 9.2641347200030078e-04, -5.5723315262335439e-17, -9.6780483124890137e-03, 1.5800101497750283e-03, 4.3916291488596115e-03, 1.2320542821102166e-02, - -7.1712350226569026e-04, -2.0114161532917680e-03, -5.5907196612255119e-03, 9.3539679266372666e-06, 9.2641347200030143e-04, -9.4706440125226137e-17, - 4.3851076902750950e-03, -1.3897533935028055e-03, 1.9712094061431666e-03, -5.5824175834556997e-03, -6.3058672814617642e-04, 1.7692116884069039e-03, - -2.5094284625967966e-03, 5.7352089444010442e-05, -4.3418753644622294e-04, -2.1350469860381366e-16, 4.3851076902746621e-03, -1.3897533935027994e-03, - -1.9712094061433475e-03, -5.5824175834555817e-03, 6.3058672814617761e-04, 1.7692116884068941e-03, 2.5094284625968382e-03, 5.7352089444009608e-05, - -4.3418753644616927e-04, -9.6273135977081884e-17, -4.3851076902746717e-03, 1.3897533935027498e-03, -1.9712094061431966e-03, 5.5824175834556684e-03, - 6.3058672814615073e-04, -1.7692116884068868e-03, 2.5094284625967606e-03, -5.7352089444010137e-05, 4.3418753644620695e-04, 5.1581442514916895e-17, - -4.3851076902745945e-03, 1.3897533935027168e-03, 1.9712094061432365e-03, 5.5824175834556606e-03, -6.3058672814616135e-04, -1.7692116884068772e-03, - -2.5094284625967792e-03, -5.7352089444009873e-05, 4.3418753644620283e-04, 1.1137537455112442e-17, 4.3851076902746916e-03, -1.3897533935027931e-03, - 1.9712094061432530e-03, -5.5824175834556251e-03, -6.3058672814615398e-04, 1.7692116884068991e-03, -2.5094284625968122e-03, 5.7352089444009642e-05, - -4.3418753644619464e-04, -1.4813473259956328e-16, 4.3851076902747445e-03, -1.3897533935027821e-03, -1.9712094061432421e-03, -5.5824175834556502e-03, - 6.3058672814615831e-04, 1.7692116884068967e-03, 2.5094284625968312e-03, 5.7352089444009920e-05, -4.3418753644621064e-04, -1.5910457447133395e-16, - -4.3851076902745728e-03, 1.3897533935027500e-03, -1.9712094061432430e-03, 5.5824175834557430e-03, 6.3058672814616276e-04, -1.7692116884069080e-03, - 2.5094284625967874e-03, -5.7352089444010144e-05, 4.3418753644620494e-04, -3.1243208329125511e-17, -4.3851076902743412e-03, 1.3897533935027602e-03, - 1.9712094061433735e-03, 5.5824175834556468e-03, -6.3058672814615756e-04, -1.7692116884068922e-03, -2.5094284625968291e-03, -5.7352089444009412e-05, - 4.3418753644620240e-04, -9.6295615860319939e-17, 7.5073464735969588e-04, -6.0801547049924465e-04, 3.0194257199911358e-04, -9.5571525078467329e-04, - -2.7511963833464409e-04, 7.7402802696399620e-04, -3.8438497801566524e-04, 1.3522801738399896e-04, -1.0185503033916061e-04, -1.4242012451345626e-16, - 7.5073464735926740e-04, -6.0801547049924812e-04, -3.0194257199929502e-04, -9.5571525078458190e-04, 2.7511963833464257e-04, 7.7402802696399035e-04, - 3.8438497801568947e-04, 1.3522801738399787e-04, -1.0185503033910946e-04, -3.8640659624400708e-19, -7.5073464735945486e-04, 6.0801547049919554e-04, - -3.0194257199923441e-04, 9.5571525078469509e-04, 2.7511963833461666e-04, -7.7402802696398200e-04, 3.8438497801567277e-04, -1.3522801738399831e-04, - 1.0185503033916149e-04, 4.8896644747051199e-17, -7.5073464735949226e-04, 6.0801547049916149e-04, 3.0194257199923653e-04, 9.5571525078472295e-04, - -2.7511963833462766e-04, -7.7402802696397040e-04, -3.8438497801568844e-04, -1.3522801738399839e-04, 1.0185503033917997e-04, 2.9084605296716279e-17, - 7.5073464735932194e-04, -6.0801547049923880e-04, 3.0194257199927599e-04, -9.5571525078461019e-04, -2.7511963833462154e-04, 7.7402802696399393e-04, - -3.8438497801566952e-04, 1.3522801738399825e-04, -1.0185503033914513e-04, -4.9539149096075250e-17, 7.5073464735941865e-04, -6.0801547049922568e-04, - -3.0194257199925669e-04, -9.5571525078464576e-04, 2.7511963833462230e-04, 7.7402802696398948e-04, 3.8438497801569158e-04, 1.3522801738399858e-04, - -1.0185503033917348e-04, -7.4179190831097889e-17, -7.5073464735936021e-04, 6.0801547049919218e-04, -3.0194257199924238e-04, 9.5571525078470029e-04, - 2.7511963833462598e-04, -7.7402802696400087e-04, 3.8438497801564849e-04, -1.3522801738399882e-04, 1.0185503033914628e-04, -2.0403375001758317e-17, - -7.5073464735908807e-04, 6.0801547049920519e-04, 3.0194257199940230e-04, 9.5571525078465302e-04, -2.7511963833461422e-04, -7.7402802696398753e-04, - -3.8438497801567906e-04, -1.3522801738399798e-04, 1.0185503033914848e-04, -1.1793080162498876e-16, + 5.8616184533469527e-03, 3.1565760734898127e-03, 2.7094777984668392e-03, + -7.4620748753877917e-03, 1.4328949642727182e-03, -4.0184476689694810e-03, + -3.4492736718164069e-03, -1.7632215123710278e-04, -5.2264298589365711e-04, + 3.5131649393126775e-17, 5.8616184533454548e-03, 3.1565760734899480e-03, + -2.7094777984674428e-03, -7.4620748753869296e-03, -1.4328949642726360e-03, + -4.0184476689695782e-03, 3.4492736718167269e-03, -1.7632215123710747e-04, + -5.2264298589345328e-04, 1.3113006726376057e-16, -5.8616184533450645e-03, + -3.1565760734899063e-03, -2.7094777984659453e-03, 7.4620748753872505e-03, + -1.4328949642727893e-03, 4.0184476689695140e-03, 3.4492736718158296e-03, + 1.7632215123710446e-04, 5.2264298589332133e-04, -6.7007510729665259e-16, + -5.8616184533434972e-03, -3.1565760734900798e-03, 2.7094777984662758e-03, + 7.4620748753870840e-03, 1.4328949642727672e-03, 4.0184476689695556e-03, + -3.4492736718152593e-03, 1.7632215123710763e-04, 5.2264298589287594e-04, + -1.2842098510653892e-15, 5.8616184533454565e-03, 3.1565760734899358e-03, + 2.7094777984669749e-03, -7.4620748753874231e-03, 1.4328949642725803e-03, + -4.0184476689694975e-03, -3.4492736718174520e-03, -1.7632215123710847e-04, + -5.2264298589330311e-04, 2.1405198315438111e-16, 5.8616184533454088e-03, + 3.1565760734899601e-03, -2.7094777984659605e-03, -7.4620748753875914e-03, + -1.4328949642728730e-03, -4.0184476689694984e-03, 3.4492736718165261e-03, + -1.7632215123710143e-04, -5.2264298589249668e-04, 4.4941804705996507e-16, + -5.8616184533449344e-03, -3.1565760734899059e-03, -2.7094777984672976e-03, + 7.4620748753882150e-03, -1.4328949642725777e-03, 4.0184476689694298e-03, + 3.4492736718163448e-03, 1.7632215123710584e-04, 5.2264298589430025e-04, + -1.1539732792029041e-15, -5.8616184533448580e-03, -3.1565760734899163e-03, + 2.7094777984665547e-03, 7.4620748753871950e-03, 1.4328949642728101e-03, + 4.0184476689695513e-03, -3.4492736718163097e-03, 1.7632215123710075e-04, + 5.2264298589368996e-04, -8.7123700173506059e-16, 1.4341205890542634e-02, + 1.7536458636411641e-03, 6.5546632008048515e-03, -1.8256929039364878e-02, + 7.9551267430263116e-04, -2.2324613660129437e-03, -8.3443485748260857e-03, + -1.6506737964353752e-04, -1.3363619667712365e-03, -1.1204417257716884e-16, + 1.4341205890541529e-02, 1.7536458636412541e-03, -6.5546632008052566e-03, + -1.8256929039364305e-02, -7.9551267430259690e-04, -2.2324613660130101e-03, + 8.3443485748262783e-03, -1.6506737964354181e-04, -1.3363619667710529e-03, + -2.9814579716794004e-17, -1.4341205890541050e-02, -1.7536458636412450e-03, + -6.5546632008041819e-03, 1.8256929039364444e-02, -7.9551267430269512e-04, + 2.2324613660129719e-03, 8.3443485748256590e-03, 1.6506737964353847e-04, + 1.3363619667711248e-03, -4.3980537973069959e-16, -1.4341205890539973e-02, + -1.7536458636413575e-03, 6.5546632008044474e-03, 1.8256929039364378e-02, + 7.9551267430268016e-04, 2.2324613660129871e-03, -8.3443485748254404e-03, + 1.6506737964354083e-04, 1.3363619667708508e-03, -8.3643101508846570e-16, + 1.4341205890541506e-02, 1.7536458636412552e-03, 6.5546632008047102e-03, + -1.8256929039364576e-02, 7.9551267430260947e-04, -2.2324613660129641e-03, + -8.3443485748265888e-03, -1.6506737964354324e-04, -1.3363619667710507e-03, + -4.1976905387266643e-17, 1.4341205890541499e-02, 1.7536458636412508e-03, + -6.5546632008043762e-03, -1.8256929039364728e-02, -7.9551267430271193e-04, + -2.2324613660129507e-03, 8.3443485748262540e-03, -1.6506737964353831e-04, + -1.3363619667707905e-03, 1.2001911151799687e-16, -1.4341205890540923e-02, + -1.7536458636412493e-03, -6.5546632008049869e-03, 1.8256929039365152e-02, + -7.9551267430258573e-04, 2.2324613660129086e-03, 8.3443485748260250e-03, + 1.6506737964353893e-04, 1.3363619667713777e-03, -7.5128207929077665e-16, + -1.4341205890540861e-02, -1.7536458636412447e-03, 6.5546632008047874e-03, + 1.8256929039364479e-02, 7.9551267430266900e-04, 2.2324613660129867e-03, + -8.3443485748261013e-03, 1.6506737964353663e-04, 1.3363619667711953e-03, + -5.9938370361699392e-16, 1.8173569455656034e-02, 4.8776519957604707e-04, + 8.2864356215894778e-03, -2.3135681230452648e-02, 2.2095135802113725e-04, + -6.2094461961560558e-04, -1.0548964172698889e-02, -1.4276292489187592e-04, + -1.7088219069646235e-03, -2.2100584181581480e-16, 1.8173569455655188e-02, + 4.8776519957610518e-04, -8.2864356215897883e-03, -2.3135681230452277e-02, + -2.2095135802111752e-04, -6.2094461961565469e-04, 1.0548964172699016e-02, + -1.4276292489187839e-04, -1.7088219069644811e-03, -1.4876109397575244e-16, + -1.8173569455654716e-02, -4.8776519957612248e-04, -8.2864356215890025e-03, + 2.3135681230452315e-02, -2.2095135802118989e-04, 6.2094461961563778e-04, + 1.0548964172698589e-02, 1.4276292489187435e-04, 1.7088219069645867e-03, + -2.4290390950766229e-16, -1.8173569455653963e-02, -4.8776519957620059e-04, + 8.2864356215892210e-03, 2.3135681230452270e-02, 2.2095135802117612e-04, + 6.2094461961563290e-04, -1.0548964172698514e-02, 1.4276292489187487e-04, + 1.7088219069644197e-03, -4.9858079137137815e-16, 1.8173569455655174e-02, + 4.8776519957611424e-04, 8.2864356215893130e-03, -2.3135681230452416e-02, + 2.2095135802114696e-04, -6.2094461961562466e-04, -1.0548964172699123e-02, + -1.4276292489187687e-04, -1.7088219069645082e-03, -2.1645988308624400e-16, + 1.8173569455655150e-02, 4.8776519957610638e-04, -8.2864356215892158e-03, + -2.3135681230452523e-02, -2.2095135802118319e-04, -6.2094461961560764e-04, + 1.0548964172699019e-02, -1.4276292489187549e-04, -1.7088219069644247e-03, + -9.9140963264315763e-17, -1.8173569455654598e-02, -4.8776519957612372e-04, + -8.2864356215895125e-03, 2.3135681230452829e-02, -2.2095135802112378e-04, + 6.2094461961558758e-04, 1.0548964172698830e-02, 1.4276292489187435e-04, + 1.7088219069646298e-03, -4.4848074315116613e-16, -1.8173569455654511e-02, + -4.8776519957611250e-04, 8.2864356215895073e-03, 2.3135681230452385e-02, + 2.2095135802115403e-04, 6.2094461961564071e-04, -1.0548964172698927e-02, + 1.4276292489187402e-04, 1.7088219069645871e-03, -3.8396631432671612e-16, + 1.7990573879785168e-02, -5.5033150535898810e-04, 8.1929460267051273e-03, + -2.2902720538814127e-02, -2.5005174898973937e-04, 7.0059403080543526e-04, + -1.0429948176920740e-02, -1.0938846751228960e-04, -1.6994005263250107e-03, + -2.9381282230482898e-16, 1.7990573879784484e-02, -5.5033150535894278e-04, + -8.1929460267053771e-03, -2.2902720538813877e-02, 2.5005174898975357e-04, + 7.0059403080541163e-04, 1.0429948176920835e-02, -1.0938846751228980e-04, + -1.6994005263248999e-03, -2.1887573342775259e-16, -1.7990573879784102e-02, + 5.5033150535891903e-04, -8.1929460267048202e-03, 2.2902720538813891e-02, + 2.5005174898969345e-04, -7.0059403080540827e-04, 1.0429948176920542e-02, + 1.0938846751228834e-04, 1.6994005263249875e-03, -9.5982628332163999e-17, + -1.7990573879783599e-02, 5.5033150535885561e-04, 8.1929460267049902e-03, + 2.2902720538813839e-02, -2.5005174898970787e-04, -7.0059403080540989e-04, + -1.0429948176920533e-02, 1.0938846751229020e-04, 1.6994005263248945e-03, + -2.6117596237755658e-16, 1.7990573879784501e-02, -5.5033150535894180e-04, + 8.1929460267050076e-03, -2.2902720538813939e-02, -2.5005174898971990e-04, + 7.0059403080542258e-04, -1.0429948176920834e-02, -1.0938846751229017e-04, + -1.6994005263249294e-03, -2.9830977257397701e-16, 1.7990573879784477e-02, + -5.5033150535894039e-04, -8.1929460267049954e-03, -2.2902720538814009e-02, + 2.5005174898970760e-04, 7.0059403080542919e-04, 1.0429948176920820e-02, + -1.0938846751228923e-04, -1.6994005263249057e-03, -2.2477885568782595e-16, + -1.7990573879783998e-02, 5.5033150535891339e-04, -8.1929460267051394e-03, + 2.2902720538814262e-02, 2.5005174898973828e-04, -7.0059403080544437e-04, + 1.0429948176920719e-02, 1.0938846751228730e-04, 1.6994005263249799e-03, + -2.4211931635057277e-16, -1.7990573879783870e-02, 5.5033150535892814e-04, + 8.1929460267052071e-03, 2.2902720538813964e-02, -2.5005174898972549e-04, + -7.0059403080541304e-04, -1.0429948176920808e-02, 1.0938846751228806e-04, + 1.6994005263249764e-03, -2.2479850252782248e-16, 1.4738458963226696e-02, + -1.2698766175711731e-03, 6.7039542837525066e-03, -1.8762648099116208e-02, + -5.7647737886046312e-04, 1.6166037551301662e-03, -8.5344020981064049e-03, + -6.4925612047121364e-05, -1.3983785661310436e-03, -3.1436539032981156e-16, + 1.4738458963226148e-02, -1.2698766175711388e-03, -6.7039542837527217e-03, + -1.8762648099116017e-02, 5.7647737886047179e-04, 1.6166037551301536e-03, + 8.5344020981064830e-03, -6.4925612047123370e-05, -1.3983785661309629e-03, + -2.2651529080434071e-16, -1.4738458963225858e-02, 1.2698766175711083e-03, + -6.7039542837523470e-03, 1.8762648099116059e-02, 5.7647737886042745e-04, + -1.6166037551301447e-03, 8.5344020981062939e-03, 6.4925612047122083e-05, + 1.3983785661310230e-03, -2.6426688005693668e-18, -1.4738458963225537e-02, + 1.2698766175710658e-03, 6.7039542837524684e-03, 1.8762648099116003e-02, + -5.7647737886044100e-04, -1.6166037551301432e-03, -8.5344020981063112e-03, + 6.4925612047124061e-05, 1.3983785661309737e-03, -1.0693961517654768e-16, + 1.4738458963226163e-02, -1.2698766175711421e-03, 6.7039542837524580e-03, + -1.8762648099116073e-02, -5.7647737886044490e-04, 1.6166037551301495e-03, + -8.5344020981064517e-03, -6.4925612047124346e-05, -1.3983785661309850e-03, + -2.9001981455784633e-16, 1.4738458963226148e-02, -1.2698766175711347e-03, + -6.7039542837524701e-03, -1.8762648099116111e-02, 5.7647737886044295e-04, + 1.6166037551301597e-03, 8.5344020981064691e-03, -6.4925612047121879e-05, + -1.3983785661309876e-03, -2.6297640124286923e-16, -1.4738458963225773e-02, + 1.2698766175711076e-03, -6.7039542837525265e-03, 1.8762648099116309e-02, + 5.7647737886046138e-04, -1.6166037551301768e-03, 8.5344020981064049e-03, + 6.4925612047123655e-05, 1.3983785661310136e-03, -1.1897205361844484e-16, + -1.4738458963225598e-02, 1.2698766175711174e-03, 6.7039542837526315e-03, + 1.8762648099116094e-02, -5.7647737886045455e-04, -1.6166037551301579e-03, + -8.5344020981064795e-03, 6.4925612047122815e-05, 1.3983785661310164e-03, + -1.2970455818161604e-16, 9.6780483124899331e-03, -1.5800101497750775e-03, + 4.3916291488594571e-03, -1.2320542821102249e-02, -7.1712350226570088e-04, + 2.0114161532917741e-03, -5.5907196612254642e-03, -9.3539679266368939e-06, + -9.2641347200032116e-04, -2.8000043592001863e-16, 9.6780483124894682e-03, + -1.5800101497750636e-03, -4.3916291488596462e-03, -1.2320542821102098e-02, + 7.1712350226570555e-04, 2.0114161532917641e-03, 5.5907196612255249e-03, + -9.3539679266382915e-06, -9.2641347200025893e-04, -1.7598141661156963e-16, + -9.6780483124893086e-03, 1.5800101497750179e-03, -4.3916291488593964e-03, + 1.2320542821102162e-02, 7.1712350226567508e-04, -2.0114161532917589e-03, + 5.5907196612253905e-03, 9.3539679266371463e-06, 9.2641347200030392e-04, + 4.0721693196094477e-17, -9.6780483124891143e-03, 1.5800101497749840e-03, + 4.3916291488594753e-03, 1.2320542821102124e-02, -7.1712350226568712e-04, + -2.0114161532917519e-03, -5.5907196612254156e-03, 9.3539679266377680e-06, + 9.2641347200027888e-04, -2.4654046496217829e-17, 9.6780483124894769e-03, + -1.5800101497750604e-03, 4.3916291488594718e-03, -1.2320542821102155e-02, + -7.1712350226568169e-04, 2.0114161532917675e-03, -5.5907196612254920e-03, + -9.3539679266380458e-06, -9.2641347200028029e-04, -2.2870225702025344e-16, + 9.6780483124894959e-03, -1.5800101497750504e-03, -4.3916291488594770e-03, + -1.2320542821102181e-02, 7.1712350226568690e-04, 2.0114161532917693e-03, + 5.5907196612255145e-03, -9.3539679266376545e-06, -9.2641347200029232e-04, + -2.2829444272414866e-16, -9.6780483124892132e-03, 1.5800101497750205e-03, + -4.3916291488594935e-03, 1.2320542821102315e-02, 7.1712350226569264e-04, + -2.0114161532917840e-03, 5.5907196612254538e-03, 9.3539679266373140e-06, + 9.2641347200030078e-04, -5.5723315262335439e-17, -9.6780483124890137e-03, + 1.5800101497750283e-03, 4.3916291488596115e-03, 1.2320542821102166e-02, + -7.1712350226569026e-04, -2.0114161532917680e-03, -5.5907196612255119e-03, + 9.3539679266372666e-06, 9.2641347200030143e-04, -9.4706440125226137e-17, + 4.3851076902750950e-03, -1.3897533935028055e-03, 1.9712094061431666e-03, + -5.5824175834556997e-03, -6.3058672814617642e-04, 1.7692116884069039e-03, + -2.5094284625967966e-03, 5.7352089444010442e-05, -4.3418753644622294e-04, + -2.1350469860381366e-16, 4.3851076902746621e-03, -1.3897533935027994e-03, + -1.9712094061433475e-03, -5.5824175834555817e-03, 6.3058672814617761e-04, + 1.7692116884068941e-03, 2.5094284625968382e-03, 5.7352089444009608e-05, + -4.3418753644616927e-04, -9.6273135977081884e-17, -4.3851076902746717e-03, + 1.3897533935027498e-03, -1.9712094061431966e-03, 5.5824175834556684e-03, + 6.3058672814615073e-04, -1.7692116884068868e-03, 2.5094284625967606e-03, + -5.7352089444010137e-05, 4.3418753644620695e-04, 5.1581442514916895e-17, + -4.3851076902745945e-03, 1.3897533935027168e-03, 1.9712094061432365e-03, + 5.5824175834556606e-03, -6.3058672814616135e-04, -1.7692116884068772e-03, + -2.5094284625967792e-03, -5.7352089444009873e-05, 4.3418753644620283e-04, + 1.1137537455112442e-17, 4.3851076902746916e-03, -1.3897533935027931e-03, + 1.9712094061432530e-03, -5.5824175834556251e-03, -6.3058672814615398e-04, + 1.7692116884068991e-03, -2.5094284625968122e-03, 5.7352089444009642e-05, + -4.3418753644619464e-04, -1.4813473259956328e-16, 4.3851076902747445e-03, + -1.3897533935027821e-03, -1.9712094061432421e-03, -5.5824175834556502e-03, + 6.3058672814615831e-04, 1.7692116884068967e-03, 2.5094284625968312e-03, + 5.7352089444009920e-05, -4.3418753644621064e-04, -1.5910457447133395e-16, + -4.3851076902745728e-03, 1.3897533935027500e-03, -1.9712094061432430e-03, + 5.5824175834557430e-03, 6.3058672814616276e-04, -1.7692116884069080e-03, + 2.5094284625967874e-03, -5.7352089444010144e-05, 4.3418753644620494e-04, + -3.1243208329125511e-17, -4.3851076902743412e-03, 1.3897533935027602e-03, + 1.9712094061433735e-03, 5.5824175834556468e-03, -6.3058672814615756e-04, + -1.7692116884068922e-03, -2.5094284625968291e-03, -5.7352089444009412e-05, + 4.3418753644620240e-04, -9.6295615860319939e-17, 7.5073464735969588e-04, + -6.0801547049924465e-04, 3.0194257199911358e-04, -9.5571525078467329e-04, + -2.7511963833464409e-04, 7.7402802696399620e-04, -3.8438497801566524e-04, + 1.3522801738399896e-04, -1.0185503033916061e-04, -1.4242012451345626e-16, + 7.5073464735926740e-04, -6.0801547049924812e-04, -3.0194257199929502e-04, + -9.5571525078458190e-04, 2.7511963833464257e-04, 7.7402802696399035e-04, + 3.8438497801568947e-04, 1.3522801738399787e-04, -1.0185503033910946e-04, + -3.8640659624400708e-19, -7.5073464735945486e-04, 6.0801547049919554e-04, + -3.0194257199923441e-04, 9.5571525078469509e-04, 2.7511963833461666e-04, + -7.7402802696398200e-04, 3.8438497801567277e-04, -1.3522801738399831e-04, + 1.0185503033916149e-04, 4.8896644747051199e-17, -7.5073464735949226e-04, + 6.0801547049916149e-04, 3.0194257199923653e-04, 9.5571525078472295e-04, + -2.7511963833462766e-04, -7.7402802696397040e-04, -3.8438497801568844e-04, + -1.3522801738399839e-04, 1.0185503033917997e-04, 2.9084605296716279e-17, + 7.5073464735932194e-04, -6.0801547049923880e-04, 3.0194257199927599e-04, + -9.5571525078461019e-04, -2.7511963833462154e-04, 7.7402802696399393e-04, + -3.8438497801566952e-04, 1.3522801738399825e-04, -1.0185503033914513e-04, + -4.9539149096075250e-17, 7.5073464735941865e-04, -6.0801547049922568e-04, + -3.0194257199925669e-04, -9.5571525078464576e-04, 2.7511963833462230e-04, + 7.7402802696398948e-04, 3.8438497801569158e-04, 1.3522801738399858e-04, + -1.0185503033917348e-04, -7.4179190831097889e-17, -7.5073464735936021e-04, + 6.0801547049919218e-04, -3.0194257199924238e-04, 9.5571525078470029e-04, + 2.7511963833462598e-04, -7.7402802696400087e-04, 3.8438497801564849e-04, + -1.3522801738399882e-04, 1.0185503033914628e-04, -2.0403375001758317e-17, + -7.5073464735908807e-04, 6.0801547049920519e-04, 3.0194257199940230e-04, + 9.5571525078465302e-04, -2.7511963833461422e-04, -7.7402802696398753e-04, + -3.8438497801567906e-04, -1.3522801738399798e-04, 1.0185503033914848e-04, + -1.1793080162498876e-16 }; return sol; } -static const double * -get_sol_3x_bias_p2_PxPx_DyDy(void) +static const double *get_sol_3x_bias_p2_PxPx_DyDy(void) { static const double sol[640] = { - 5.8616184533438415e-03, 2.7094777984664276e-03, 3.1565760734900668e-03, -7.4620748753882350e-03, 1.4328949642728596e-03, -3.4492736718159259e-03, - -4.0184476689694194e-03, -5.2264298589377572e-04, -1.7632215123710571e-04, 7.5979082301536452e-16, 1.4341205890540316e-02, 6.5546632008047770e-03, - 1.7536458636413647e-03, -1.8256929039365127e-02, 7.9551267430269046e-04, -8.3443485748257561e-03, -2.2324613660128874e-03, -1.3363619667711227e-03, - -1.6506737964354078e-04, 3.6150316530706261e-16, 1.8173569455654341e-02, 8.2864356215895402e-03, 4.8776519957621312e-04, -2.3135681230452718e-02, - 2.2095135802116113e-04, -1.0548964172698679e-02, -6.2094461961555993e-04, -1.7088219069645069e-03, -1.4276292489187270e-04, 5.1918134700881396e-17, - 1.7990573879784012e-02, 8.1929460267052539e-03, -5.5033150535884162e-04, -2.2902720538814019e-02, -2.5005174898972505e-04, -1.0429948176920631e-02, - 7.0059403080549435e-04, -1.6994005263249402e-03, -1.0938846751228856e-04, -1.2584677568311243e-16, 1.4738458963226040e-02, 6.7039542837526826e-03, - -1.2698766175710315e-03, -1.8762648099115885e-02, -5.7647737886045108e-04, -8.5344020981063303e-03, 1.6166037551302282e-03, -1.3983785661310184e-03, - -6.4925612047121907e-05, -1.8098485043007565e-16, 9.6780483124897562e-03, 4.3916291488596626e-03, -1.5800101497749428e-03, -1.2320542821101696e-02, - -7.1712350226569319e-04, -5.5907196612254087e-03, 2.0114161532918473e-03, -9.2641347200033764e-04, -9.3539679266380255e-06, -1.6937631708429027e-16, - 4.3851076902753881e-03, 1.9712094061434021e-03, -1.3897533935026676e-03, -5.5824175834548635e-03, -6.3058672814616796e-04, -2.5094284625967645e-03, - 1.7692116884069950e-03, -4.3418753644630751e-04, 5.7352089444009778e-05, -1.4852136885022670e-16, 7.5073464736049515e-04, 3.0194257199939721e-04, - -6.0801547049908864e-04, -9.5571525078346354e-04, -2.7511963833462213e-04, -3.8438497801564561e-04, 7.7402802696411872e-04, -1.0185503033937700e-04, - 1.3522801738399966e-04, -1.4286296276697706e-16, 5.8616184533469779e-03, -2.7094777984656123e-03, 3.1565760734897567e-03, -7.4620748753869183e-03, - -1.4328949642729051e-03, 3.4492736718160564e-03, -4.0184476689695886e-03, -5.2264298589454821e-04, -1.7632215123711094e-04, -6.7813185122706456e-16, - 1.4341205890542550e-02, -6.5546632008040961e-03, 1.7536458636411602e-03, -1.8256929039364284e-02, -7.9551267430271930e-04, 8.3443485748258672e-03, - -2.2324613660130005e-03, -1.3363619667715958e-03, -1.6506737964354276e-04, -7.8197593865398220e-16, 1.8173569455655954e-02, -8.2864356215889539e-03, - 4.8776519957606008e-04, -2.3135681230452221e-02, -2.2095135802118867e-04, 1.0548964172698731e-02, -6.2094461961564851e-04, -1.7088219069647786e-03, - -1.4276292489187592e-04, -8.4118925304500103e-16, 1.7990573879785136e-02, -8.1929460267047751e-03, -5.5033150535897292e-04, -2.2902720538813804e-02, - 2.5005174898969182e-04, 1.0429948176920627e-02, 7.0059403080542312e-04, -1.6994005263250738e-03, -1.0938846751228902e-04, -8.4256328087254971e-16, - 1.4738458963226729e-02, -6.7039542837523261e-03, -1.2698766175711523e-03, -1.8762648099115882e-02, 5.7647737886041476e-04, 8.5344020981062939e-03, - 1.6166037551301748e-03, -1.3983785661310505e-03, -6.4925612047123343e-05, -7.5173252314282128e-16, 9.6780483124900302e-03, -4.3916291488594302e-03, - -1.5800101497750632e-03, -1.2320542821101879e-02, 7.1712350226565871e-04, 5.5907196612253506e-03, 2.0114161532917923e-03, -9.2641347200027953e-04, - -9.3539679266398297e-06, -5.7142268612241973e-16, 4.3851076902752207e-03, -1.9712094061432820e-03, -1.3897533935028036e-03, -5.5824175834552616e-03, - 6.3058672814613696e-04, 2.5094284625966955e-03, 1.7692116884069258e-03, -4.3418753644613930e-04, 5.7352089444007216e-05, -3.7186439493645241e-16, - 7.5073464735979530e-04, -3.0194257199933616e-04, -6.0801547049926167e-04, -9.5571525078413867e-04, 2.7511963833461807e-04, 3.8438497801561016e-04, - 7.7402802696402645e-04, -1.0185503033901673e-04, 1.3522801738399568e-04, -1.7344565127837030e-16, -5.8616184533437782e-03, -2.7094777984653143e-03, - -3.1565760734898899e-03, 7.4620748753859260e-03, -1.4328949642730510e-03, 3.4492736718157403e-03, 4.0184476689695582e-03, 5.2264298589424073e-04, - 1.7632215123711454e-04, -2.6639418630864231e-15, -1.4341205890539730e-02, -6.5546632008041325e-03, -1.7536458636412510e-03, 1.8256929039363289e-02, - -7.9551267430277178e-04, 8.3443485748254734e-03, 2.2324613660130274e-03, 1.3363619667713857e-03, 1.6506737964354411e-04, -1.9292192738161615e-15, - -1.8173569455653408e-02, -8.2864356215890805e-03, -4.8776519957612161e-04, 2.3135681230451340e-02, -2.2095135802118347e-04, 1.0548964172698379e-02, - 6.2094461961568668e-04, 1.7088219069646359e-03, 1.4276292489187820e-04, -1.3481263701032338e-15, -1.7990573879782777e-02, -8.1929460267048185e-03, - 5.5033150535891741e-04, 2.2902720538813103e-02, 2.5005174898972982e-04, 1.0429948176920324e-02, -7.0059403080535579e-04, 1.6994005263249862e-03, - 1.0938846751228772e-04, -8.9840064440486445e-16, -1.4738458963224539e-02, -6.7039542837522108e-03, 1.2698766175711124e-03, 1.8762648099115476e-02, - 5.7647737886046832e-04, 8.5344020981060979e-03, -1.6166037551300773e-03, 1.3983785661310171e-03, 6.4925612047124915e-05, -6.1187347955024573e-16, - -9.6780483124879711e-03, -4.3916291488591110e-03, 1.5800101497750261e-03, 1.2320542821101815e-02, 7.1712350226572485e-04, 5.5907196612252595e-03, - -2.0114161532916912e-03, 9.2641347200032853e-04, 9.3539679266387489e-06, -4.6292186796819506e-16, -4.3851076902733134e-03, -1.9712094061426948e-03, - 1.3897533935027539e-03, 5.5824175834555583e-03, 6.3058672814622597e-04, 2.5094284625967163e-03, -1.7692116884068161e-03, 4.3418753644631916e-04, - -5.7352089444008754e-05, -3.9198879635261493e-16, -7.5073464735810850e-04, -3.0194257199840505e-04, 6.0801547049918589e-04, 9.5571525078483321e-04, - 2.7511963833473397e-04, 3.8438497801580814e-04, -7.7402802696390958e-04, 1.0185503033949897e-04, -1.3522801738399619e-04, -3.6578027336901036e-16, - -5.8616184533451425e-03, 2.7094777984647540e-03, -3.1565760734898244e-03, 7.4620748753849216e-03, 1.4328949642729910e-03, -3.4492736718154675e-03, - 4.0184476689696406e-03, 5.2264298589441637e-04, 1.7632215123710636e-04, -1.2133063787372501e-15, -1.4341205890540856e-02, 6.5546632008035184e-03, - -1.7536458636411736e-03, 1.8256929039362498e-02, 7.9551267430280159e-04, -8.3443485748255965e-03, 2.2324613660130695e-03, 1.3363619667714104e-03, - 1.6506737964353888e-04, -9.9280213755089207e-16, -1.8173569455654268e-02, 8.2864356215885965e-03, -4.8776519957604241e-04, 2.3135681230450685e-02, - 2.2095135802123198e-04, -1.0548964172698592e-02, 6.2094461961572202e-04, 1.7088219069646433e-03, 1.4276292489187519e-04, -7.4002985514707971e-16, - -1.7990573879783364e-02, 8.1929460267045028e-03, 5.5033150535899775e-04, 2.2902720538812545e-02, -2.5005174898968104e-04, -1.0429948176920546e-02, - -7.0059403080533129e-04, 1.6994005263250003e-03, 1.0938846751228570e-04, -4.9004278444642846e-16, -1.4738458963224845e-02, 6.7039542837520451e-03, - 1.2698766175711876e-03, 1.8762648099114980e-02, -5.7647737886043146e-04, -8.5344020981063216e-03, -1.6166037551300651e-03, 1.3983785661310227e-03, - 6.4925612047122652e-05, -3.2296552980969570e-16, -9.6780483124880180e-03, 4.3916291488590511e-03, 1.5800101497751003e-03, 1.2320542821101354e-02, - -7.1712350226569850e-04, -5.5907196612254790e-03, -2.0114161532916825e-03, 9.2641347200030295e-04, 9.3539679266380831e-06, -2.4057760356606480e-16, - -4.3851076902730957e-03, 1.9712094061426987e-03, 1.3897533935028320e-03, 5.5824175834551185e-03, -6.3058672814621599e-04, -2.5094284625969167e-03, - -1.7692116884068106e-03, 4.3418753644622441e-04, -5.7352089444008971e-05, -2.0305749738373731e-16, -7.5073464735759318e-04, 3.0194257199835984e-04, - 6.0801547049927826e-04, 9.5571525078440365e-04, -2.7511963833477229e-04, -3.8438497801593683e-04, -7.7402802696390968e-04, 1.0185503033923353e-04, - -1.3522801738399603e-04, -1.8989785385171275e-16, 5.8616184533443853e-03, 2.7094777984674944e-03, 3.1565760734900872e-03, -7.4620748753883720e-03, - 1.4328949642726720e-03, -3.4492736718159966e-03, -4.0184476689694845e-03, -5.2264298589279788e-04, -1.7632215123711129e-04, -5.4265573850165279e-16, - 1.4341205890540911e-02, 6.5546632008053659e-03, 1.7536458636413798e-03, -1.8256929039365485e-02, 7.9551267430259494e-04, -8.3443485748257423e-03, - -2.2324613660129611e-03, -1.3363619667708334e-03, -1.6506737964354484e-04, -5.2931364482778452e-16, 1.8173569455654976e-02, 8.2864356215898716e-03, - 4.8776519957622092e-04, -2.3135681230453297e-02, 2.2095135802110061e-04, -1.0548964172698645e-02, -6.2094461961561544e-04, -1.7088219069643828e-03, - -1.4276292489187880e-04, -4.8820771494737806e-16, 1.7990573879784651e-02, 8.1929460267054152e-03, -5.5033150535884672e-04, -2.2902720538814807e-02, - -2.5005174898976051e-04, -1.0429948176920573e-02, 7.0059403080542843e-04, -1.6994005263248472e-03, -1.0938846751229052e-04, -4.5741231311481576e-16, - 1.4738458963226618e-02, 6.7039542837527503e-03, -1.2698766175710536e-03, -1.8762648099116912e-02, -5.7647737886047234e-04, -8.5344020981063320e-03, - 1.6166037551301538e-03, -1.3983785661309375e-03, -6.4925612047122964e-05, -3.8795519996012429e-16, 9.6780483124902384e-03, 4.3916291488596557e-03, - -1.5800101497749808e-03, -1.2320542821102991e-02, -7.1712350226571595e-04, -5.5907196612254781e-03, 2.0114161532917654e-03, -9.2641347200029004e-04, - -9.3539679266394197e-06, -2.8306978253837860e-16, 4.3851076902757255e-03, 1.9712094061433358e-03, -1.3897533935027134e-03, -5.5824175834564777e-03, - -6.3058672814617761e-04, -2.5094284625968811e-03, 1.7692116884068887e-03, -4.3418753644631651e-04, 5.7352089444008633e-05, -1.7232291504532142e-16, - 7.5073464736067936e-04, 3.0194257199930120e-04, -6.0801547049913504e-04, -9.5571525078550705e-04, -2.7511963833463054e-04, -3.8438497801588398e-04, - 7.7402802696397853e-04, -1.0185503033950893e-04, 1.3522801738399557e-04, -4.0183722521239453e-17, 5.8616184533470351e-03, -2.7094777984668556e-03, - 3.1565760734897884e-03, -7.4620748753884292e-03, -1.4328949642727011e-03, 3.4492736718147151e-03, -4.0184476689695669e-03, -5.2264298589348862e-04, - -1.7632215123709768e-04, -1.7670040387231012e-16, 1.4341205890542679e-02, -6.5546632008048776e-03, 1.7536458636411584e-03, -1.8256929039365721e-02, - -7.9551267430265718e-04, 8.3443485748250831e-03, -2.2324613660129741e-03, -1.3363619667712435e-03, -1.6506737964353709e-04, -1.4159583548387092e-16, - 1.8173569455656079e-02, -8.2864356215895836e-03, 4.8776519957605444e-04, -2.3135681230453547e-02, -2.2095135802115623e-04, 1.0548964172698277e-02, - -6.2094461961560113e-04, -1.7088219069646528e-03, -1.4276292489187457e-04, -1.4370112997316304e-16, 1.7990573879785251e-02, -8.1929460267053007e-03, - -5.5033150535897248e-04, -2.2902720538814959e-02, 2.5005174898971768e-04, 1.0429948176920377e-02, 7.0059403080546291e-04, -1.6994005263250254e-03, - -1.0938846751228595e-04, -1.5154734466435251e-16, 1.4738458963226835e-02, -6.7039542837527511e-03, -1.2698766175711551e-03, -1.8762648099116933e-02, - 5.7647737886044566e-04, 8.5344020981062575e-03, 1.6166037551302000e-03, -1.3983785661310325e-03, -6.4925612047119887e-05, -1.3440270325811173e-16, - 9.6780483124901291e-03, -4.3916291488597260e-03, -1.5800101497750667e-03, -1.2320542821102842e-02, 7.1712350226570121e-04, 5.5907196612255084e-03, - 2.0114161532918192e-03, -9.2641347200029612e-04, -9.3539679266370565e-06, -1.4142510264724841e-16, 4.3851076902753161e-03, -1.9712094061434342e-03, - -1.3897533935028018e-03, -5.5824175834561316e-03, 6.3058672814617610e-04, 2.5094284625970021e-03, 1.7692116884069483e-03, -4.3418753644620977e-04, - 5.7352089444010801e-05, -1.9072614114096155e-16, 7.5073464735991131e-04, -3.0194257199937617e-04, -6.0801547049925137e-04, -9.5571525078493903e-04, - 2.7511963833464702e-04, 3.8438497801606439e-04, 7.7402802696404770e-04, -1.0185503033922346e-04, 1.3522801738399928e-04, -2.7159400245815774e-16, - -5.8616184533466023e-03, -2.7094777984677395e-03, -3.1565760734897845e-03, 7.4620748753841835e-03, -1.4328949642725887e-03, 3.4492736718177599e-03, - 4.0184476689697820e-03, 5.2264298589374536e-04, 1.7632215123710281e-04, 6.9624920624588576e-16, -1.4341205890542202e-02, -6.5546632008054067e-03, - -1.7536458636411407e-03, 1.8256929039362189e-02, -7.9551267430255700e-04, 8.3443485748269514e-03, 2.2324613660131649e-03, 1.3363619667713061e-03, - 1.6506737964353991e-04, 7.9619770587187039e-16, -1.8173569455655531e-02, -8.2864356215898473e-03, -4.8776519957603753e-04, 2.3135681230450622e-02, - -2.2095135802110795e-04, 1.0548964172699432e-02, 6.2094461961576712e-04, 1.7088219069646905e-03, 1.4276292489187359e-04, 8.8902897800480822e-16, - -1.7990573879784658e-02, -8.1929460267054447e-03, 5.5033150535898246e-04, 2.2902720538812607e-02, 2.5005174898973703e-04, 1.0429948176921063e-02, - -7.0059403080529117e-04, 1.6994005263250337e-03, 1.0938846751228540e-04, 8.3212135948128831e-16, -1.4738458963226208e-02, -6.7039542837528223e-03, - 1.2698766175711698e-03, 1.8762648099115160e-02, 5.7647737886047179e-04, 8.5344020981066252e-03, -1.6166037551300441e-03, 1.3983785661310264e-03, - 6.4925612047122625e-05, 6.5153847757252344e-16, -9.6780483124894370e-03, -4.3916291488597390e-03, 1.5800101497750823e-03, 1.2320542821101609e-02, - 7.1712350226571194e-04, 5.5907196612255735e-03, -2.0114161532916600e-03, 9.2641347200029536e-04, 9.3539679266377731e-06, 4.4198077128583854e-16, - -4.3851076902745763e-03, -1.9712094061434095e-03, 1.3897533935028131e-03, 5.5824175834554360e-03, 6.3058672814618846e-04, 2.5094284625968039e-03, - -1.7692116884067968e-03, 4.3418753644618364e-04, -5.7352089444011329e-05, 2.2471737429018154e-16, -7.5073464735914738e-04, -3.0194257199931464e-04, - 6.0801547049925528e-04, 9.5571525078477911e-04, 2.7511963833465596e-04, 3.8438497801555562e-04, -7.7402802696389049e-04, 1.0185503033907287e-04, - -1.3522801738399904e-04, -4.6964796235091913e-18, -5.8616184533469675e-03, 2.7094777984668465e-03, -3.1565760734898287e-03, 7.4620748753871542e-03, - 1.4328949642727234e-03, -3.4492736718168822e-03, 4.0184476689694862e-03, 5.2264298589321757e-04, 1.7632215123710289e-04, 3.1776391741962064e-16, - -1.4341205890542656e-02, 6.5546632008048533e-03, -1.7536458636411461e-03, 1.8256929039364295e-02, 7.9551267430261793e-04, -8.3443485748262783e-03, - 2.2324613660129611e-03, 1.3363619667710806e-03, 1.6506737964354023e-04, 6.1540592612503074e-16, -1.8173569455655979e-02, 8.2864356215894587e-03, - -4.8776519957602799e-04, 2.3135681230452138e-02, 2.2095135802114259e-04, -1.0548964172698903e-02, 6.2094461961562705e-04, 1.7088219069645884e-03, - 1.4276292489187310e-04, 8.2893778027973621e-16, -1.7990573879785053e-02, 8.1929460267051672e-03, 5.5033150535899850e-04, 2.2902720538813707e-02, - -2.5005174898971009e-04, -1.0429948176920639e-02, -7.0059403080539537e-04, 1.6994005263249936e-03, 1.0938846751228491e-04, 8.3447909816312473e-16, - -1.4738458963226533e-02, 6.7039542837526367e-03, 1.2698766175711900e-03, 1.8762648099115934e-02, -5.7647737886044523e-04, -8.5344020981062904e-03, - -1.6166037551301263e-03, 1.3983785661310295e-03, 6.4925612047121229e-05, 6.7923021830212132e-16, -9.6780483124897076e-03, 4.3916291488596357e-03, - 1.5800101497751005e-03, 1.2320542821102105e-02, -7.1712350226568917e-04, -5.5907196612253263e-03, -2.0114161532917402e-03, 9.2641347200033612e-04, - 9.3539679266379476e-06, 4.8083758871934514e-16, -4.3851076902747940e-03, 1.9712094061433835e-03, 1.3897533935028239e-03, 5.5824175834556494e-03, - -6.3058672814616601e-04, -2.5094284625966556e-03, -1.7692116884068809e-03, 4.3418753644626132e-04, -5.7352089444010286e-05, 2.7793202384748856e-16, - -7.5073464735935424e-04, 3.0194257199937368e-04, 6.0801547049924899e-04, 9.5571525078468316e-04, -2.7511963833462994e-04, -3.8438497801557200e-04, - -7.7402802696398536e-04, 1.0185503033921120e-04, -1.3522801738399890e-04, 8.1559707371039833e-17, + 5.8616184533438415e-03, 2.7094777984664276e-03, 3.1565760734900668e-03, + -7.4620748753882350e-03, 1.4328949642728596e-03, -3.4492736718159259e-03, + -4.0184476689694194e-03, -5.2264298589377572e-04, -1.7632215123710571e-04, + 7.5979082301536452e-16, 1.4341205890540316e-02, 6.5546632008047770e-03, + 1.7536458636413647e-03, -1.8256929039365127e-02, 7.9551267430269046e-04, + -8.3443485748257561e-03, -2.2324613660128874e-03, -1.3363619667711227e-03, + -1.6506737964354078e-04, 3.6150316530706261e-16, 1.8173569455654341e-02, + 8.2864356215895402e-03, 4.8776519957621312e-04, -2.3135681230452718e-02, + 2.2095135802116113e-04, -1.0548964172698679e-02, -6.2094461961555993e-04, + -1.7088219069645069e-03, -1.4276292489187270e-04, 5.1918134700881396e-17, + 1.7990573879784012e-02, 8.1929460267052539e-03, -5.5033150535884162e-04, + -2.2902720538814019e-02, -2.5005174898972505e-04, -1.0429948176920631e-02, + 7.0059403080549435e-04, -1.6994005263249402e-03, -1.0938846751228856e-04, + -1.2584677568311243e-16, 1.4738458963226040e-02, 6.7039542837526826e-03, + -1.2698766175710315e-03, -1.8762648099115885e-02, -5.7647737886045108e-04, + -8.5344020981063303e-03, 1.6166037551302282e-03, -1.3983785661310184e-03, + -6.4925612047121907e-05, -1.8098485043007565e-16, 9.6780483124897562e-03, + 4.3916291488596626e-03, -1.5800101497749428e-03, -1.2320542821101696e-02, + -7.1712350226569319e-04, -5.5907196612254087e-03, 2.0114161532918473e-03, + -9.2641347200033764e-04, -9.3539679266380255e-06, -1.6937631708429027e-16, + 4.3851076902753881e-03, 1.9712094061434021e-03, -1.3897533935026676e-03, + -5.5824175834548635e-03, -6.3058672814616796e-04, -2.5094284625967645e-03, + 1.7692116884069950e-03, -4.3418753644630751e-04, 5.7352089444009778e-05, + -1.4852136885022670e-16, 7.5073464736049515e-04, 3.0194257199939721e-04, + -6.0801547049908864e-04, -9.5571525078346354e-04, -2.7511963833462213e-04, + -3.8438497801564561e-04, 7.7402802696411872e-04, -1.0185503033937700e-04, + 1.3522801738399966e-04, -1.4286296276697706e-16, 5.8616184533469779e-03, + -2.7094777984656123e-03, 3.1565760734897567e-03, -7.4620748753869183e-03, + -1.4328949642729051e-03, 3.4492736718160564e-03, -4.0184476689695886e-03, + -5.2264298589454821e-04, -1.7632215123711094e-04, -6.7813185122706456e-16, + 1.4341205890542550e-02, -6.5546632008040961e-03, 1.7536458636411602e-03, + -1.8256929039364284e-02, -7.9551267430271930e-04, 8.3443485748258672e-03, + -2.2324613660130005e-03, -1.3363619667715958e-03, -1.6506737964354276e-04, + -7.8197593865398220e-16, 1.8173569455655954e-02, -8.2864356215889539e-03, + 4.8776519957606008e-04, -2.3135681230452221e-02, -2.2095135802118867e-04, + 1.0548964172698731e-02, -6.2094461961564851e-04, -1.7088219069647786e-03, + -1.4276292489187592e-04, -8.4118925304500103e-16, 1.7990573879785136e-02, + -8.1929460267047751e-03, -5.5033150535897292e-04, -2.2902720538813804e-02, + 2.5005174898969182e-04, 1.0429948176920627e-02, 7.0059403080542312e-04, + -1.6994005263250738e-03, -1.0938846751228902e-04, -8.4256328087254971e-16, + 1.4738458963226729e-02, -6.7039542837523261e-03, -1.2698766175711523e-03, + -1.8762648099115882e-02, 5.7647737886041476e-04, 8.5344020981062939e-03, + 1.6166037551301748e-03, -1.3983785661310505e-03, -6.4925612047123343e-05, + -7.5173252314282128e-16, 9.6780483124900302e-03, -4.3916291488594302e-03, + -1.5800101497750632e-03, -1.2320542821101879e-02, 7.1712350226565871e-04, + 5.5907196612253506e-03, 2.0114161532917923e-03, -9.2641347200027953e-04, + -9.3539679266398297e-06, -5.7142268612241973e-16, 4.3851076902752207e-03, + -1.9712094061432820e-03, -1.3897533935028036e-03, -5.5824175834552616e-03, + 6.3058672814613696e-04, 2.5094284625966955e-03, 1.7692116884069258e-03, + -4.3418753644613930e-04, 5.7352089444007216e-05, -3.7186439493645241e-16, + 7.5073464735979530e-04, -3.0194257199933616e-04, -6.0801547049926167e-04, + -9.5571525078413867e-04, 2.7511963833461807e-04, 3.8438497801561016e-04, + 7.7402802696402645e-04, -1.0185503033901673e-04, 1.3522801738399568e-04, + -1.7344565127837030e-16, -5.8616184533437782e-03, -2.7094777984653143e-03, + -3.1565760734898899e-03, 7.4620748753859260e-03, -1.4328949642730510e-03, + 3.4492736718157403e-03, 4.0184476689695582e-03, 5.2264298589424073e-04, + 1.7632215123711454e-04, -2.6639418630864231e-15, -1.4341205890539730e-02, + -6.5546632008041325e-03, -1.7536458636412510e-03, 1.8256929039363289e-02, + -7.9551267430277178e-04, 8.3443485748254734e-03, 2.2324613660130274e-03, + 1.3363619667713857e-03, 1.6506737964354411e-04, -1.9292192738161615e-15, + -1.8173569455653408e-02, -8.2864356215890805e-03, -4.8776519957612161e-04, + 2.3135681230451340e-02, -2.2095135802118347e-04, 1.0548964172698379e-02, + 6.2094461961568668e-04, 1.7088219069646359e-03, 1.4276292489187820e-04, + -1.3481263701032338e-15, -1.7990573879782777e-02, -8.1929460267048185e-03, + 5.5033150535891741e-04, 2.2902720538813103e-02, 2.5005174898972982e-04, + 1.0429948176920324e-02, -7.0059403080535579e-04, 1.6994005263249862e-03, + 1.0938846751228772e-04, -8.9840064440486445e-16, -1.4738458963224539e-02, + -6.7039542837522108e-03, 1.2698766175711124e-03, 1.8762648099115476e-02, + 5.7647737886046832e-04, 8.5344020981060979e-03, -1.6166037551300773e-03, + 1.3983785661310171e-03, 6.4925612047124915e-05, -6.1187347955024573e-16, + -9.6780483124879711e-03, -4.3916291488591110e-03, 1.5800101497750261e-03, + 1.2320542821101815e-02, 7.1712350226572485e-04, 5.5907196612252595e-03, + -2.0114161532916912e-03, 9.2641347200032853e-04, 9.3539679266387489e-06, + -4.6292186796819506e-16, -4.3851076902733134e-03, -1.9712094061426948e-03, + 1.3897533935027539e-03, 5.5824175834555583e-03, 6.3058672814622597e-04, + 2.5094284625967163e-03, -1.7692116884068161e-03, 4.3418753644631916e-04, + -5.7352089444008754e-05, -3.9198879635261493e-16, -7.5073464735810850e-04, + -3.0194257199840505e-04, 6.0801547049918589e-04, 9.5571525078483321e-04, + 2.7511963833473397e-04, 3.8438497801580814e-04, -7.7402802696390958e-04, + 1.0185503033949897e-04, -1.3522801738399619e-04, -3.6578027336901036e-16, + -5.8616184533451425e-03, 2.7094777984647540e-03, -3.1565760734898244e-03, + 7.4620748753849216e-03, 1.4328949642729910e-03, -3.4492736718154675e-03, + 4.0184476689696406e-03, 5.2264298589441637e-04, 1.7632215123710636e-04, + -1.2133063787372501e-15, -1.4341205890540856e-02, 6.5546632008035184e-03, + -1.7536458636411736e-03, 1.8256929039362498e-02, 7.9551267430280159e-04, + -8.3443485748255965e-03, 2.2324613660130695e-03, 1.3363619667714104e-03, + 1.6506737964353888e-04, -9.9280213755089207e-16, -1.8173569455654268e-02, + 8.2864356215885965e-03, -4.8776519957604241e-04, 2.3135681230450685e-02, + 2.2095135802123198e-04, -1.0548964172698592e-02, 6.2094461961572202e-04, + 1.7088219069646433e-03, 1.4276292489187519e-04, -7.4002985514707971e-16, + -1.7990573879783364e-02, 8.1929460267045028e-03, 5.5033150535899775e-04, + 2.2902720538812545e-02, -2.5005174898968104e-04, -1.0429948176920546e-02, + -7.0059403080533129e-04, 1.6994005263250003e-03, 1.0938846751228570e-04, + -4.9004278444642846e-16, -1.4738458963224845e-02, 6.7039542837520451e-03, + 1.2698766175711876e-03, 1.8762648099114980e-02, -5.7647737886043146e-04, + -8.5344020981063216e-03, -1.6166037551300651e-03, 1.3983785661310227e-03, + 6.4925612047122652e-05, -3.2296552980969570e-16, -9.6780483124880180e-03, + 4.3916291488590511e-03, 1.5800101497751003e-03, 1.2320542821101354e-02, + -7.1712350226569850e-04, -5.5907196612254790e-03, -2.0114161532916825e-03, + 9.2641347200030295e-04, 9.3539679266380831e-06, -2.4057760356606480e-16, + -4.3851076902730957e-03, 1.9712094061426987e-03, 1.3897533935028320e-03, + 5.5824175834551185e-03, -6.3058672814621599e-04, -2.5094284625969167e-03, + -1.7692116884068106e-03, 4.3418753644622441e-04, -5.7352089444008971e-05, + -2.0305749738373731e-16, -7.5073464735759318e-04, 3.0194257199835984e-04, + 6.0801547049927826e-04, 9.5571525078440365e-04, -2.7511963833477229e-04, + -3.8438497801593683e-04, -7.7402802696390968e-04, 1.0185503033923353e-04, + -1.3522801738399603e-04, -1.8989785385171275e-16, 5.8616184533443853e-03, + 2.7094777984674944e-03, 3.1565760734900872e-03, -7.4620748753883720e-03, + 1.4328949642726720e-03, -3.4492736718159966e-03, -4.0184476689694845e-03, + -5.2264298589279788e-04, -1.7632215123711129e-04, -5.4265573850165279e-16, + 1.4341205890540911e-02, 6.5546632008053659e-03, 1.7536458636413798e-03, + -1.8256929039365485e-02, 7.9551267430259494e-04, -8.3443485748257423e-03, + -2.2324613660129611e-03, -1.3363619667708334e-03, -1.6506737964354484e-04, + -5.2931364482778452e-16, 1.8173569455654976e-02, 8.2864356215898716e-03, + 4.8776519957622092e-04, -2.3135681230453297e-02, 2.2095135802110061e-04, + -1.0548964172698645e-02, -6.2094461961561544e-04, -1.7088219069643828e-03, + -1.4276292489187880e-04, -4.8820771494737806e-16, 1.7990573879784651e-02, + 8.1929460267054152e-03, -5.5033150535884672e-04, -2.2902720538814807e-02, + -2.5005174898976051e-04, -1.0429948176920573e-02, 7.0059403080542843e-04, + -1.6994005263248472e-03, -1.0938846751229052e-04, -4.5741231311481576e-16, + 1.4738458963226618e-02, 6.7039542837527503e-03, -1.2698766175710536e-03, + -1.8762648099116912e-02, -5.7647737886047234e-04, -8.5344020981063320e-03, + 1.6166037551301538e-03, -1.3983785661309375e-03, -6.4925612047122964e-05, + -3.8795519996012429e-16, 9.6780483124902384e-03, 4.3916291488596557e-03, + -1.5800101497749808e-03, -1.2320542821102991e-02, -7.1712350226571595e-04, + -5.5907196612254781e-03, 2.0114161532917654e-03, -9.2641347200029004e-04, + -9.3539679266394197e-06, -2.8306978253837860e-16, 4.3851076902757255e-03, + 1.9712094061433358e-03, -1.3897533935027134e-03, -5.5824175834564777e-03, + -6.3058672814617761e-04, -2.5094284625968811e-03, 1.7692116884068887e-03, + -4.3418753644631651e-04, 5.7352089444008633e-05, -1.7232291504532142e-16, + 7.5073464736067936e-04, 3.0194257199930120e-04, -6.0801547049913504e-04, + -9.5571525078550705e-04, -2.7511963833463054e-04, -3.8438497801588398e-04, + 7.7402802696397853e-04, -1.0185503033950893e-04, 1.3522801738399557e-04, + -4.0183722521239453e-17, 5.8616184533470351e-03, -2.7094777984668556e-03, + 3.1565760734897884e-03, -7.4620748753884292e-03, -1.4328949642727011e-03, + 3.4492736718147151e-03, -4.0184476689695669e-03, -5.2264298589348862e-04, + -1.7632215123709768e-04, -1.7670040387231012e-16, 1.4341205890542679e-02, + -6.5546632008048776e-03, 1.7536458636411584e-03, -1.8256929039365721e-02, + -7.9551267430265718e-04, 8.3443485748250831e-03, -2.2324613660129741e-03, + -1.3363619667712435e-03, -1.6506737964353709e-04, -1.4159583548387092e-16, + 1.8173569455656079e-02, -8.2864356215895836e-03, 4.8776519957605444e-04, + -2.3135681230453547e-02, -2.2095135802115623e-04, 1.0548964172698277e-02, + -6.2094461961560113e-04, -1.7088219069646528e-03, -1.4276292489187457e-04, + -1.4370112997316304e-16, 1.7990573879785251e-02, -8.1929460267053007e-03, + -5.5033150535897248e-04, -2.2902720538814959e-02, 2.5005174898971768e-04, + 1.0429948176920377e-02, 7.0059403080546291e-04, -1.6994005263250254e-03, + -1.0938846751228595e-04, -1.5154734466435251e-16, 1.4738458963226835e-02, + -6.7039542837527511e-03, -1.2698766175711551e-03, -1.8762648099116933e-02, + 5.7647737886044566e-04, 8.5344020981062575e-03, 1.6166037551302000e-03, + -1.3983785661310325e-03, -6.4925612047119887e-05, -1.3440270325811173e-16, + 9.6780483124901291e-03, -4.3916291488597260e-03, -1.5800101497750667e-03, + -1.2320542821102842e-02, 7.1712350226570121e-04, 5.5907196612255084e-03, + 2.0114161532918192e-03, -9.2641347200029612e-04, -9.3539679266370565e-06, + -1.4142510264724841e-16, 4.3851076902753161e-03, -1.9712094061434342e-03, + -1.3897533935028018e-03, -5.5824175834561316e-03, 6.3058672814617610e-04, + 2.5094284625970021e-03, 1.7692116884069483e-03, -4.3418753644620977e-04, + 5.7352089444010801e-05, -1.9072614114096155e-16, 7.5073464735991131e-04, + -3.0194257199937617e-04, -6.0801547049925137e-04, -9.5571525078493903e-04, + 2.7511963833464702e-04, 3.8438497801606439e-04, 7.7402802696404770e-04, + -1.0185503033922346e-04, 1.3522801738399928e-04, -2.7159400245815774e-16, + -5.8616184533466023e-03, -2.7094777984677395e-03, -3.1565760734897845e-03, + 7.4620748753841835e-03, -1.4328949642725887e-03, 3.4492736718177599e-03, + 4.0184476689697820e-03, 5.2264298589374536e-04, 1.7632215123710281e-04, + 6.9624920624588576e-16, -1.4341205890542202e-02, -6.5546632008054067e-03, + -1.7536458636411407e-03, 1.8256929039362189e-02, -7.9551267430255700e-04, + 8.3443485748269514e-03, 2.2324613660131649e-03, 1.3363619667713061e-03, + 1.6506737964353991e-04, 7.9619770587187039e-16, -1.8173569455655531e-02, + -8.2864356215898473e-03, -4.8776519957603753e-04, 2.3135681230450622e-02, + -2.2095135802110795e-04, 1.0548964172699432e-02, 6.2094461961576712e-04, + 1.7088219069646905e-03, 1.4276292489187359e-04, 8.8902897800480822e-16, + -1.7990573879784658e-02, -8.1929460267054447e-03, 5.5033150535898246e-04, + 2.2902720538812607e-02, 2.5005174898973703e-04, 1.0429948176921063e-02, + -7.0059403080529117e-04, 1.6994005263250337e-03, 1.0938846751228540e-04, + 8.3212135948128831e-16, -1.4738458963226208e-02, -6.7039542837528223e-03, + 1.2698766175711698e-03, 1.8762648099115160e-02, 5.7647737886047179e-04, + 8.5344020981066252e-03, -1.6166037551300441e-03, 1.3983785661310264e-03, + 6.4925612047122625e-05, 6.5153847757252344e-16, -9.6780483124894370e-03, + -4.3916291488597390e-03, 1.5800101497750823e-03, 1.2320542821101609e-02, + 7.1712350226571194e-04, 5.5907196612255735e-03, -2.0114161532916600e-03, + 9.2641347200029536e-04, 9.3539679266377731e-06, 4.4198077128583854e-16, + -4.3851076902745763e-03, -1.9712094061434095e-03, 1.3897533935028131e-03, + 5.5824175834554360e-03, 6.3058672814618846e-04, 2.5094284625968039e-03, + -1.7692116884067968e-03, 4.3418753644618364e-04, -5.7352089444011329e-05, + 2.2471737429018154e-16, -7.5073464735914738e-04, -3.0194257199931464e-04, + 6.0801547049925528e-04, 9.5571525078477911e-04, 2.7511963833465596e-04, + 3.8438497801555562e-04, -7.7402802696389049e-04, 1.0185503033907287e-04, + -1.3522801738399904e-04, -4.6964796235091913e-18, -5.8616184533469675e-03, + 2.7094777984668465e-03, -3.1565760734898287e-03, 7.4620748753871542e-03, + 1.4328949642727234e-03, -3.4492736718168822e-03, 4.0184476689694862e-03, + 5.2264298589321757e-04, 1.7632215123710289e-04, 3.1776391741962064e-16, + -1.4341205890542656e-02, 6.5546632008048533e-03, -1.7536458636411461e-03, + 1.8256929039364295e-02, 7.9551267430261793e-04, -8.3443485748262783e-03, + 2.2324613660129611e-03, 1.3363619667710806e-03, 1.6506737964354023e-04, + 6.1540592612503074e-16, -1.8173569455655979e-02, 8.2864356215894587e-03, + -4.8776519957602799e-04, 2.3135681230452138e-02, 2.2095135802114259e-04, + -1.0548964172698903e-02, 6.2094461961562705e-04, 1.7088219069645884e-03, + 1.4276292489187310e-04, 8.2893778027973621e-16, -1.7990573879785053e-02, + 8.1929460267051672e-03, 5.5033150535899850e-04, 2.2902720538813707e-02, + -2.5005174898971009e-04, -1.0429948176920639e-02, -7.0059403080539537e-04, + 1.6994005263249936e-03, 1.0938846751228491e-04, 8.3447909816312473e-16, + -1.4738458963226533e-02, 6.7039542837526367e-03, 1.2698766175711900e-03, + 1.8762648099115934e-02, -5.7647737886044523e-04, -8.5344020981062904e-03, + -1.6166037551301263e-03, 1.3983785661310295e-03, 6.4925612047121229e-05, + 6.7923021830212132e-16, -9.6780483124897076e-03, 4.3916291488596357e-03, + 1.5800101497751005e-03, 1.2320542821102105e-02, -7.1712350226568917e-04, + -5.5907196612253263e-03, -2.0114161532917402e-03, 9.2641347200033612e-04, + 9.3539679266379476e-06, 4.8083758871934514e-16, -4.3851076902747940e-03, + 1.9712094061433835e-03, 1.3897533935028239e-03, 5.5824175834556494e-03, + -6.3058672814616601e-04, -2.5094284625966556e-03, -1.7692116884068809e-03, + 4.3418753644626132e-04, -5.7352089444010286e-05, 2.7793202384748856e-16, + -7.5073464735935424e-04, 3.0194257199937368e-04, 6.0801547049924899e-04, + 9.5571525078468316e-04, -2.7511963833462994e-04, -3.8438497801557200e-04, + -7.7402802696398536e-04, 1.0185503033921120e-04, -1.3522801738399890e-04, + 8.1559707371039833e-17 }; return sol; } -static const double * -get_sol_3x_bias_p2_DxDx_NyDy(void) +static const double *get_sol_3x_bias_p2_DxDx_NyDy(void) { static const double sol[640] = { - -7.4185325279775777e-04, -3.9802597843886317e-04, 2.0456784067311337e-05, 9.4440888007033875e-04, 1.0964684083884220e-05, 5.0670299970896452e-04, - -2.6042304806390264e-05, 2.3457263346557451e-05, 5.0764812234692848e-06, 4.6249790389122405e-16, -6.0391518322723753e-04, -3.2401990289661228e-04, - 5.8133025438359082e-05, 7.6880819717104528e-04, 3.1157234701922163e-05, 4.1249030379146855e-04, -7.4005667889377098e-05, 1.9094342915952928e-05, - 4.2641058539285365e-06, 2.2220549807193982e-16, -3.5046776690493651e-04, -1.8804143086081278e-04, 8.6097341540881974e-05, 4.4615949312709391e-04, - 4.6138941825176955e-05, 2.3938426697811351e-04, -1.0960536143111664e-04, 1.1077684120019632e-05, 2.6393373958545555e-06, -6.0886009644883065e-17, - -2.6369173463173775e-05, -1.4156115092826504e-05, 9.7874810518121645e-05, 3.3569013123064332e-05, 5.2437299075732224e-05, 1.8021301046369540e-05, - -1.2459855077791895e-04, 8.2737327434932787e-07, 2.0225634437670926e-07, 6.6278316245383176e-17, 3.0109676195020615e-04, 1.6152938865401258e-04, - 8.6992163559215918e-05, -3.8330822797399874e-04, 4.6572459248672606e-05, -2.0563337622609749e-04, -1.1074450567150355e-04, -9.5344390692561088e-06, - -3.0476196625405792e-06, 2.2276701672177206e-17, 5.4219548657417969e-04, 2.9091105641263198e-04, 4.6964511263907207e-05, -6.9023655328536414e-04, - 2.5099762187585532e-05, -3.7034141718852477e-04, -5.9787702377023312e-05, -1.7138457671756282e-05, -7.1078530314263283e-06, -8.0749235629294875e-17, - 5.8489869202431376e-04, 3.1367048785931479e-04, -2.8617271620076177e-05, -7.4459944282300513e-04, -1.5601216384924636e-05, -3.9931508426118849e-04, - 3.6430932046668254e-05, -1.8606531928361270e-05, -1.1993596362267388e-05, 1.4335740025532410e-16, 2.9366410440273647e-04, 1.5833417110391160e-04, - -1.4679523967225448e-04, -3.7384615745770508e-04, -7.8278512648658480e-05, -2.0156573641113469e-04, 1.8687621490631206e-04, -8.6854584349767026e-06, - -1.7623476288397682e-05, 1.0848651979579840e-16, -1.8111297630617701e-03, -2.2122899042749104e-04, 4.9921555573584552e-05, 2.3056406705032101e-03, - 6.1001783803918497e-06, 2.8163335848549242e-04, -6.3552138125501126e-05, 2.1979419790257315e-05, 1.2783176280283245e-05, 2.7857679634059921e-16, - -1.4743782859745810e-03, -1.8009465973339172e-04, 1.4186131475810724e-04, 1.8769425632445258e-03, 1.7335155668372967e-05, 2.2926770929982310e-04, - -1.8059513103274984e-04, 1.7891815716313254e-05, 1.0737709998699541e-05, 1.9230809006369143e-16, -8.5563118982650362e-04, -1.0451452877111586e-04, - 2.1009107982633018e-04, 1.0892527473457480e-03, 2.5673892807397301e-05, 1.3305117783823689e-04, -2.6745435254661471e-04, 1.0380762902201684e-05, - 6.6467490018292703e-06, 1.0350256818363629e-16, -6.4401076442146066e-05, -7.8652359084521495e-06, 2.3880385491964199e-04, 8.1985147666923674e-05, - 2.9185828660963689e-05, 1.0012760081344271e-05, -3.0400686433692739e-04, 7.7809221149302604e-07, 5.1040642097443571e-07, 4.0017417234473824e-17, - 7.3504616021202588e-04, 8.9786913323456805e-05, 2.1219385883249455e-04, -9.3574317878674154e-04, 2.5939534318854238e-05, -1.1430233396837355e-04, - -2.7013127437547352e-04, -8.9337392931330060e-06, -7.6719397877145017e-06, 7.5198342416082037e-18, 1.3236741350855302e-03, 1.6169038423836875e-04, - 1.1444951102739500e-04, -1.6850901479238580e-03, 1.4004905074148330e-05, -2.0583833004827264e-04, -1.4569880785232482e-04, -1.6042765456802835e-05, - -1.7897506519468700e-05, -3.8723351581988297e-18, 1.4277325347643744e-03, 1.7441241606392551e-04, -7.0228009414156255e-05, -1.8175606551730900e-03, - -8.5314378017897350e-06, -2.2203398570291407e-04, 8.9403066536777049e-05, -1.7465893456537019e-05, -3.0180009723344792e-05, -1.0928219871388014e-17, - 7.1871323474241155e-04, 8.7710214994633017e-05, -3.5755576442373147e-04, -9.1495071101386225e-04, -4.3774882151247583e-05, -1.1165861388560425e-04, - 4.5518279763373005e-04, -8.1880463208147463e-06, -4.4456825652039233e-05, 7.1223580357852086e-18, -2.2944506126900003e-03, -6.1638761923244069e-05, - 6.3246271865104631e-05, 2.9209274547706780e-03, 1.6996066367278695e-06, 7.8468610735826896e-05, -8.0515035224969260e-05, 1.9018655925888491e-05, - 1.6147340377872063e-05, 2.0553230239201092e-16, -1.8678324615435337e-03, -5.0177806705329094e-05, 1.7972636255985107e-04, 2.3778254749349001e-03, - 4.8298278531543210e-06, 6.3878356071487048e-05, -2.2879885225845367e-04, 1.5481586715521866e-05, 1.3563696440515726e-05, 1.6862058727884781e-16, - -1.0839644414274879e-03, -2.9119379734342048e-05, 2.6616909306346494e-04, 1.3799301146204916e-03, 7.1531646979130580e-06, 3.7070135770886574e-05, - -3.3884390766164969e-04, 8.9821168968253373e-06, 8.3963955227197131e-06, 1.1080275815901326e-16, -8.1583353672125855e-05, -2.1908826904612249e-06, - 3.0254949112894263e-04, 1.0385887422230145e-04, 8.1313422416431917e-06, 2.7890813449652836e-06, -3.8515761035684532e-04, 6.7280421817372825e-07, - 6.4546625765658320e-07, 5.5833352067559234e-17, 9.3120558827591447e-04, 2.5018632896846171e-05, 2.6884245930155251e-04, -1.1854619810895742e-03, - 7.2279537638850403e-06, -3.1849720933209709e-05, -3.4224720987189211e-04, -7.7309086961042199e-06, -9.6892163186684390e-06, 1.2233071025946061e-17, - 1.6769291755919060e-03, 4.5047880146268317e-05, 1.4502400361684611e-04, -2.1347979518942318e-03, 3.8980585320111308e-06, -5.7347754260091483e-05, - -1.8462136052193066e-04, -1.3884451253037142e-05, -2.2607359364033955e-05, -2.0946695208114841e-17, 1.8087408305902113e-03, 4.8609262873996871e-05, - -8.8933756155094482e-05, -2.3025994638613619e-03, -2.3689535246092704e-06, -6.1881537000419012e-05, 1.1321623074936586e-04, -1.5106133674163060e-05, - -3.8108004663823115e-05, -4.9996761330612133e-17, 9.1041892369570464e-04, 2.4407192087710259e-05, -4.5307301340336866e-04, -1.1589997251880580e-03, - -1.2201146101856527e-05, -3.1071332312954140e-05, 5.7678007822296613e-04, -7.0756666654389634e-06, -5.6202873171474166e-05, -1.3729881301442140e-16, - -2.2712814698433652e-03, 6.9283273198997747e-05, 6.2607182589646940e-05, 2.8914322086887731e-03, -1.9084463650281187e-06, -8.8200379526165773e-05, - -7.9701449000710122e-05, 1.4578513220970450e-05, 1.5993584902369550e-05, 1.6206959329244378e-16, -1.8489709303060869e-03, 5.6401394648714923e-05, - 1.7791020436132239e-04, 2.3538139908238103e-03, -5.4230258469318264e-06, -7.1801232593806587e-05, -2.2648681018836513e-04, 1.1867224005866736e-05, - 1.3434536925262127e-05, 1.3884044675756950e-16, -1.0730176634537302e-03, 3.2732351109901716e-05, 2.6347918201770733e-04, 1.3659944281656225e-03, - -8.0305360856003998e-06, -4.1669592924460280e-05, -3.3541954324910466e-04, 6.8851645536146903e-06, 8.3164350440197039e-06, 9.8989004851509373e-17, - -8.0757424528281682e-05, 2.4649783637425219e-06, 2.9949136733266980e-04, 1.0280743336824143e-04, -9.1266848261765632e-06, -3.1380161064322520e-06, - -3.8126449637687740e-04, 5.1575107170413136e-07, 6.3927833037311136e-07, 5.4320200009267459e-17, 9.2180607376450324e-04, -2.8115105526507709e-05, - 2.6612401553146117e-04, -1.1734960229442387e-03, -8.1052313173914392e-06, 3.5791654512843503e-05, -3.3878652215938284e-04, -5.9258354008351692e-06, - -9.5969568198567602e-06, 1.2354355107121336e-17, 1.6599996084286698e-03, -5.0637183330130939e-05, 1.4355365040744227e-04, -2.1132459353674824e-03, - -4.3684028831008672e-06, 6.4463160899271821e-05, -1.8274954204225148e-04, -1.0642774281309240e-05, -2.2392186132941561e-05, -2.4439344978395069e-17, - 1.7904898493183452e-03, -5.4594815714699535e-05, -8.8038739116137082e-05, -2.2793652342907554e-03, 2.7188239063177206e-06, 6.9501385310809908e-05, - 1.1207683823986927e-04, -1.1580436012146539e-05, -3.7747530559387761e-05, -5.5342821763728846e-17, 9.0124227629169657e-04, -2.7574015762423465e-05, - -4.4848460248174822e-04, -1.1473174857899373e-03, 1.3619750416073549e-05, 3.5102825588544167e-05, 5.7093884748957700e-04, -5.4247562557651676e-06, - -5.5653119508561458e-05, -9.2909246370792702e-17, -1.8607939734754306e-03, 1.6006863502989764e-04, 5.1292513034897540e-05, 2.3688651979412874e-03, - -4.4105638650402665e-06, -2.0377377840281942e-04, -6.5297421839984664e-05, 8.6581482607711247e-06, 1.3099218422382047e-05, 1.2130732581462570e-16, - -1.5148068254142147e-03, 1.3030661548299124e-04, 1.4575747047953651e-04, 1.9284097119175174e-03, -1.2533216551743824e-05, -1.6588553643187131e-04, - -1.8555509319178660e-04, 7.0478959388719097e-06, 1.1003322845519252e-05, 1.0671497867529702e-16, -8.7908999816598422e-04, 7.5622040169426828e-05, - 2.1586222088963472e-04, 1.1191167491928862e-03, -1.8560279471199331e-05, -9.6269883559477111e-05, -2.7480124608354376e-04, 4.0890266760258649e-06, - 6.8115232787057308e-06, 7.9717774256069590e-17, -6.6158684055542149e-05, 5.6930861126356883e-06, 2.4536651900581864e-04, 8.4222652499154474e-05, - -2.1095228673489870e-05, -7.2475264609192327e-06, -3.1236139835906653e-04, 3.0620542597938747e-07, 5.2383308233409013e-07, 4.5367438840226148e-17, - 7.5521454677788689e-04, -6.4959947881067446e-05, 2.1803021136887151e-04, -9.6141834203176198e-04, -1.8739033755341927e-05, 8.2696613375289981e-05, - -2.7756118472743952e-04, -3.5194659963031186e-06, -7.8598788404717967e-06, 1.0409110540003064e-17, 1.3599971624203907e-03, -1.1698967736129318e-04, - 1.1761250922651231e-04, -1.7313308153829561e-03, -1.0103627331035097e-05, 1.4893254125386500e-04, -1.4972543114425156e-04, -6.3208097101481016e-06, - -1.8339153449490702e-05, -1.8592739562088397e-17, 1.4669018971550508e-03, -1.2615623684791310e-04, -7.2126947445431660e-05, -1.8674248210697011e-03, - 6.2473383435715822e-06, 1.6060193832964713e-04, 9.1820490646870895e-05, -6.8766677416233056e-06, -3.0915439591944671e-05, -3.4169910043710598e-17, - 7.3835886561778822e-04, -6.3621467426451799e-05, -3.6743879842920073e-04, -9.3996038534386532e-04, 3.1529332913731504e-05, 8.0992674189995619e-05, - 4.6776429544571370e-04, -3.2207980489607478e-06, -4.5587253648864800e-05, -1.3033565763243572e-17, -1.2218883130104699e-03, 1.9925006776766980e-04, - 3.3680823229324827e-05, 1.5555127229134420e-03, -5.4906542718873293e-06, -2.5365331033436574e-04, -4.2877035890732717e-05, 1.2579210421270085e-06, - 8.6095141065868681e-06, 8.5843190723295419e-17, -9.9469578895192406e-04, 1.6220276314314548e-04, 9.5710452873525549e-05, 1.2662875474526807e-03, - -1.5602511542291027e-05, -2.0649060889963317e-04, -1.2184323687799138e-04, 1.0239596690626961e-06, 7.2319800498269018e-06, 7.6128518192850284e-17, - -5.7725205425157491e-04, 9.4132221087062096e-05, 1.4174402118255613e-04, 7.3486496691657513e-04, -2.3105816616276255e-05, -1.1983408465235449e-04, - -1.8044581161690831e-04, 5.9407987857311818e-07, 4.4769112358823013e-06, 5.8602639297672241e-17, -4.3439872336690766e-05, 7.0856641229987313e-06, - 1.6111739776339482e-04, 5.5300695965309908e-05, -2.6262233432286444e-05, -9.0203339996338009e-06, -2.0510889533447221e-04, 4.4421321296519763e-08, - 3.4429239733250568e-07, 3.4926715594934423e-17, 4.9591678847464517e-04, -8.0861991798899719e-05, 1.4316667347179717e-04, -6.3132191851335946e-04, - -2.3329868400283431e-05, 1.0294055168874697e-04, -1.8225690491621555e-04, -5.1117197886643198e-07, -5.1659110589382652e-06, 1.0102921131673717e-17, - 8.9304807164371051e-04, -1.4562879398958924e-04, 7.7225405099948114e-05, -1.1368859353378222e-03, -1.2582857886102611e-05, 1.8539128287040646e-04, - -9.8311031283336125e-05, -9.1822109815642119e-07, -1.2053450101606588e-05, -8.9611256229312162e-18, 9.6325796444312359e-04, -1.5703540377679862e-04, - -4.7364249466624545e-05, -1.2262659386990057e-03, 7.7720809383173407e-06, 1.9991235362653694e-04, 6.0296585106922121e-05, -9.9955532671637544e-07, - -2.0321917006824889e-05, -1.4644761409477663e-17, 4.8485609369285158e-04, -7.9184942178627942e-05, -2.4126875678009328e-04, -6.1724121140272088e-04, - 3.9263369648519171e-05, 1.0080560040594159e-04, 3.0714478305167290e-04, -4.6828117363387576e-07, -2.9948261566553504e-05, -1.2605868310791414e-17, - -5.5318357068331902e-04, 1.7536157032520592e-04, 1.5250285570937922e-05, 7.0422482410403353e-04, -4.8299508614752260e-06, -2.2324229706304245e-04, - -1.9414223854234676e-05, -7.6230039760333720e-06, 3.8612474615733436e-06, 5.1737179513716968e-17, -4.5032633391021244e-04, 1.4275601491743441e-04, - 4.3336922314421925e-05, 5.7328344530477055e-04, -1.3724632897095447e-05, -1.8173412014178895e-04, -5.5169636466947756e-05, -6.2054078588158429e-06, - 3.2435488692399899e-06, 4.8028491712169638e-17, -2.6133624469453566e-04, 8.2846618815280416e-05, 6.4181688197263934e-05, 3.3269149827546476e-04, - -2.0323581324053096e-05, -1.0546706130613400e-04, -8.1705857651543159e-05, -3.6005452741340406e-06, 2.0081691410636277e-06, 3.8520388310352902e-17, - -1.9661496835333231e-05, 6.2364545034745673e-06, 7.2956872225951117e-05, 2.5029872332176844e-05, -2.3096613004447442e-05, -7.9392561682747264e-06, - -9.2877018106376599e-05, -2.7032276650755302e-07, 1.5500833779823407e-07, 2.3954220237922715e-17, 2.2452284971681333e-04, -7.1167813182502039e-05, - 6.4833668634053107e-05, -2.8582657318236793e-04, -2.0511575929727710e-05, 9.0599474345224277e-05, -8.2535854840078805e-05, 3.0981066058928703e-06, - -2.3154572454531680e-06, 8.4437989845047043e-18, 4.0432786569248309e-04, -1.2816820392756137e-04, 3.4987563703451466e-05, -5.1472555438688986e-04, - -1.1047540869100629e-05, 1.6316325294175941e-04, -4.4540568810560594e-05, 5.5618567638296239e-06, -5.4055108406485347e-06, -3.3020213440190191e-18, - 4.3610842151560496e-04, -1.3819686293535001e-04, -2.1413925090722030e-05, -5.5518347382006619e-04, 6.8888362637683960e-06, 1.7593013720955338e-04, - 2.7260783634202321e-05, 6.0629566842151169e-06, -9.1041122183861232e-06, -7.2371742466117540e-18, 2.1943348004293205e-04, -6.9776478809210302e-05, - -1.0931001556628712e-04, -2.7934760190890623e-04, 3.4451757069420710e-05, 8.8828250006272910e-05, 1.3915602444573250e-04, 2.8472996610849330e-06, - -1.3462461610689810e-05, -1.4223434379638855e-18, -9.3040091887961748e-05, 7.6930184467915048e-05, 2.5570471988835521e-06, 1.1844376047444965e-04, - -2.1248537374219816e-06, -9.7935203603906131e-05, -3.2552234182110448e-06, -1.7981070634123119e-05, 7.9801219628408649e-07, 1.3255963992479744e-17, - -7.5742210399364090e-05, 6.2625581143333398e-05, 7.2652034204423278e-06, 9.6422865071444226e-05, -6.0388313855885586e-06, -7.9724871095860508e-05, - -9.2488947105183267e-06, -1.4636620319132153e-05, 6.7044703542109376e-07, 1.5454990145859717e-17, -4.3958996718337654e-05, 3.6342108184726977e-05, - 1.0755488950520903e-05, 5.5961562078806149e-05, -8.9457858332929588e-06, -4.6264958144601579e-05, -1.3692167872881542e-05, -8.4914149761173461e-06, - 4.1533005655934768e-07, 2.3331565406350569e-17, -3.3149552045454746e-06, 2.7320505889872851e-06, 1.2216240033802679e-05, 4.2200706411281198e-06, - -1.0173710041968676e-05, -3.4780097375416221e-06, -1.5551762461788650e-05, -6.3374425050565725e-07, 3.2586873501894366e-08, 1.4287004275686782e-17, - 3.7749886887661497e-05, -3.1230076485256521e-05, 1.0834213338389489e-05, -4.8057116773325226e-05, -9.0542379286305008e-06, 3.9757137205703429e-05, - -1.3792387169260664e-05, 7.3084505808951379e-06, -4.7736440058582091e-07, -5.1426902537239170e-19, 6.8002926475318857e-05, -5.6225462188814054e-05, - 5.8069646962412217e-06, -8.6570446906972983e-05, -4.9002968245301933e-06, 7.1577263531492970e-05, -7.3924984553271851e-06, 1.3140222484471872e-05, - -1.1167339315051476e-06, -1.0014636178582984e-18, 7.3270287126041972e-05, -6.0708847522397337e-05, -3.7405038611585289e-06, -9.3276007817187916e-05, - 2.8745282594752142e-06, 7.7284792487988441e-05, 4.7618111116923385e-06, 1.4257402535386491e-05, -1.8716955469369723e-06, -1.7259023988470547e-18, - 3.7604074979957093e-05, -3.0294674009570444e-05, -1.8072883786921887e-05, -4.7871492379369695e-05, 1.5390330853863949e-05, 3.8566332418962707e-05, - 2.3007504344675715e-05, 6.6491000063331675e-06, -2.8178579922985129e-06, -7.5910951338837699e-19, + -7.4185325279775777e-04, -3.9802597843886317e-04, 2.0456784067311337e-05, + 9.4440888007033875e-04, 1.0964684083884220e-05, 5.0670299970896452e-04, + -2.6042304806390264e-05, 2.3457263346557451e-05, 5.0764812234692848e-06, + 4.6249790389122405e-16, -6.0391518322723753e-04, -3.2401990289661228e-04, + 5.8133025438359082e-05, 7.6880819717104528e-04, 3.1157234701922163e-05, + 4.1249030379146855e-04, -7.4005667889377098e-05, 1.9094342915952928e-05, + 4.2641058539285365e-06, 2.2220549807193982e-16, -3.5046776690493651e-04, + -1.8804143086081278e-04, 8.6097341540881974e-05, 4.4615949312709391e-04, + 4.6138941825176955e-05, 2.3938426697811351e-04, -1.0960536143111664e-04, + 1.1077684120019632e-05, 2.6393373958545555e-06, -6.0886009644883065e-17, + -2.6369173463173775e-05, -1.4156115092826504e-05, 9.7874810518121645e-05, + 3.3569013123064332e-05, 5.2437299075732224e-05, 1.8021301046369540e-05, + -1.2459855077791895e-04, 8.2737327434932787e-07, 2.0225634437670926e-07, + 6.6278316245383176e-17, 3.0109676195020615e-04, 1.6152938865401258e-04, + 8.6992163559215918e-05, -3.8330822797399874e-04, 4.6572459248672606e-05, + -2.0563337622609749e-04, -1.1074450567150355e-04, -9.5344390692561088e-06, + -3.0476196625405792e-06, 2.2276701672177206e-17, 5.4219548657417969e-04, + 2.9091105641263198e-04, 4.6964511263907207e-05, -6.9023655328536414e-04, + 2.5099762187585532e-05, -3.7034141718852477e-04, -5.9787702377023312e-05, + -1.7138457671756282e-05, -7.1078530314263283e-06, -8.0749235629294875e-17, + 5.8489869202431376e-04, 3.1367048785931479e-04, -2.8617271620076177e-05, + -7.4459944282300513e-04, -1.5601216384924636e-05, -3.9931508426118849e-04, + 3.6430932046668254e-05, -1.8606531928361270e-05, -1.1993596362267388e-05, + 1.4335740025532410e-16, 2.9366410440273647e-04, 1.5833417110391160e-04, + -1.4679523967225448e-04, -3.7384615745770508e-04, -7.8278512648658480e-05, + -2.0156573641113469e-04, 1.8687621490631206e-04, -8.6854584349767026e-06, + -1.7623476288397682e-05, 1.0848651979579840e-16, -1.8111297630617701e-03, + -2.2122899042749104e-04, 4.9921555573584552e-05, 2.3056406705032101e-03, + 6.1001783803918497e-06, 2.8163335848549242e-04, -6.3552138125501126e-05, + 2.1979419790257315e-05, 1.2783176280283245e-05, 2.7857679634059921e-16, + -1.4743782859745810e-03, -1.8009465973339172e-04, 1.4186131475810724e-04, + 1.8769425632445258e-03, 1.7335155668372967e-05, 2.2926770929982310e-04, + -1.8059513103274984e-04, 1.7891815716313254e-05, 1.0737709998699541e-05, + 1.9230809006369143e-16, -8.5563118982650362e-04, -1.0451452877111586e-04, + 2.1009107982633018e-04, 1.0892527473457480e-03, 2.5673892807397301e-05, + 1.3305117783823689e-04, -2.6745435254661471e-04, 1.0380762902201684e-05, + 6.6467490018292703e-06, 1.0350256818363629e-16, -6.4401076442146066e-05, + -7.8652359084521495e-06, 2.3880385491964199e-04, 8.1985147666923674e-05, + 2.9185828660963689e-05, 1.0012760081344271e-05, -3.0400686433692739e-04, + 7.7809221149302604e-07, 5.1040642097443571e-07, 4.0017417234473824e-17, + 7.3504616021202588e-04, 8.9786913323456805e-05, 2.1219385883249455e-04, + -9.3574317878674154e-04, 2.5939534318854238e-05, -1.1430233396837355e-04, + -2.7013127437547352e-04, -8.9337392931330060e-06, -7.6719397877145017e-06, + 7.5198342416082037e-18, 1.3236741350855302e-03, 1.6169038423836875e-04, + 1.1444951102739500e-04, -1.6850901479238580e-03, 1.4004905074148330e-05, + -2.0583833004827264e-04, -1.4569880785232482e-04, -1.6042765456802835e-05, + -1.7897506519468700e-05, -3.8723351581988297e-18, 1.4277325347643744e-03, + 1.7441241606392551e-04, -7.0228009414156255e-05, -1.8175606551730900e-03, + -8.5314378017897350e-06, -2.2203398570291407e-04, 8.9403066536777049e-05, + -1.7465893456537019e-05, -3.0180009723344792e-05, -1.0928219871388014e-17, + 7.1871323474241155e-04, 8.7710214994633017e-05, -3.5755576442373147e-04, + -9.1495071101386225e-04, -4.3774882151247583e-05, -1.1165861388560425e-04, + 4.5518279763373005e-04, -8.1880463208147463e-06, -4.4456825652039233e-05, + 7.1223580357852086e-18, -2.2944506126900003e-03, -6.1638761923244069e-05, + 6.3246271865104631e-05, 2.9209274547706780e-03, 1.6996066367278695e-06, + 7.8468610735826896e-05, -8.0515035224969260e-05, 1.9018655925888491e-05, + 1.6147340377872063e-05, 2.0553230239201092e-16, -1.8678324615435337e-03, + -5.0177806705329094e-05, 1.7972636255985107e-04, 2.3778254749349001e-03, + 4.8298278531543210e-06, 6.3878356071487048e-05, -2.2879885225845367e-04, + 1.5481586715521866e-05, 1.3563696440515726e-05, 1.6862058727884781e-16, + -1.0839644414274879e-03, -2.9119379734342048e-05, 2.6616909306346494e-04, + 1.3799301146204916e-03, 7.1531646979130580e-06, 3.7070135770886574e-05, + -3.3884390766164969e-04, 8.9821168968253373e-06, 8.3963955227197131e-06, + 1.1080275815901326e-16, -8.1583353672125855e-05, -2.1908826904612249e-06, + 3.0254949112894263e-04, 1.0385887422230145e-04, 8.1313422416431917e-06, + 2.7890813449652836e-06, -3.8515761035684532e-04, 6.7280421817372825e-07, + 6.4546625765658320e-07, 5.5833352067559234e-17, 9.3120558827591447e-04, + 2.5018632896846171e-05, 2.6884245930155251e-04, -1.1854619810895742e-03, + 7.2279537638850403e-06, -3.1849720933209709e-05, -3.4224720987189211e-04, + -7.7309086961042199e-06, -9.6892163186684390e-06, 1.2233071025946061e-17, + 1.6769291755919060e-03, 4.5047880146268317e-05, 1.4502400361684611e-04, + -2.1347979518942318e-03, 3.8980585320111308e-06, -5.7347754260091483e-05, + -1.8462136052193066e-04, -1.3884451253037142e-05, -2.2607359364033955e-05, + -2.0946695208114841e-17, 1.8087408305902113e-03, 4.8609262873996871e-05, + -8.8933756155094482e-05, -2.3025994638613619e-03, -2.3689535246092704e-06, + -6.1881537000419012e-05, 1.1321623074936586e-04, -1.5106133674163060e-05, + -3.8108004663823115e-05, -4.9996761330612133e-17, 9.1041892369570464e-04, + 2.4407192087710259e-05, -4.5307301340336866e-04, -1.1589997251880580e-03, + -1.2201146101856527e-05, -3.1071332312954140e-05, 5.7678007822296613e-04, + -7.0756666654389634e-06, -5.6202873171474166e-05, -1.3729881301442140e-16, + -2.2712814698433652e-03, 6.9283273198997747e-05, 6.2607182589646940e-05, + 2.8914322086887731e-03, -1.9084463650281187e-06, -8.8200379526165773e-05, + -7.9701449000710122e-05, 1.4578513220970450e-05, 1.5993584902369550e-05, + 1.6206959329244378e-16, -1.8489709303060869e-03, 5.6401394648714923e-05, + 1.7791020436132239e-04, 2.3538139908238103e-03, -5.4230258469318264e-06, + -7.1801232593806587e-05, -2.2648681018836513e-04, 1.1867224005866736e-05, + 1.3434536925262127e-05, 1.3884044675756950e-16, -1.0730176634537302e-03, + 3.2732351109901716e-05, 2.6347918201770733e-04, 1.3659944281656225e-03, + -8.0305360856003998e-06, -4.1669592924460280e-05, -3.3541954324910466e-04, + 6.8851645536146903e-06, 8.3164350440197039e-06, 9.8989004851509373e-17, + -8.0757424528281682e-05, 2.4649783637425219e-06, 2.9949136733266980e-04, + 1.0280743336824143e-04, -9.1266848261765632e-06, -3.1380161064322520e-06, + -3.8126449637687740e-04, 5.1575107170413136e-07, 6.3927833037311136e-07, + 5.4320200009267459e-17, 9.2180607376450324e-04, -2.8115105526507709e-05, + 2.6612401553146117e-04, -1.1734960229442387e-03, -8.1052313173914392e-06, + 3.5791654512843503e-05, -3.3878652215938284e-04, -5.9258354008351692e-06, + -9.5969568198567602e-06, 1.2354355107121336e-17, 1.6599996084286698e-03, + -5.0637183330130939e-05, 1.4355365040744227e-04, -2.1132459353674824e-03, + -4.3684028831008672e-06, 6.4463160899271821e-05, -1.8274954204225148e-04, + -1.0642774281309240e-05, -2.2392186132941561e-05, -2.4439344978395069e-17, + 1.7904898493183452e-03, -5.4594815714699535e-05, -8.8038739116137082e-05, + -2.2793652342907554e-03, 2.7188239063177206e-06, 6.9501385310809908e-05, + 1.1207683823986927e-04, -1.1580436012146539e-05, -3.7747530559387761e-05, + -5.5342821763728846e-17, 9.0124227629169657e-04, -2.7574015762423465e-05, + -4.4848460248174822e-04, -1.1473174857899373e-03, 1.3619750416073549e-05, + 3.5102825588544167e-05, 5.7093884748957700e-04, -5.4247562557651676e-06, + -5.5653119508561458e-05, -9.2909246370792702e-17, -1.8607939734754306e-03, + 1.6006863502989764e-04, 5.1292513034897540e-05, 2.3688651979412874e-03, + -4.4105638650402665e-06, -2.0377377840281942e-04, -6.5297421839984664e-05, + 8.6581482607711247e-06, 1.3099218422382047e-05, 1.2130732581462570e-16, + -1.5148068254142147e-03, 1.3030661548299124e-04, 1.4575747047953651e-04, + 1.9284097119175174e-03, -1.2533216551743824e-05, -1.6588553643187131e-04, + -1.8555509319178660e-04, 7.0478959388719097e-06, 1.1003322845519252e-05, + 1.0671497867529702e-16, -8.7908999816598422e-04, 7.5622040169426828e-05, + 2.1586222088963472e-04, 1.1191167491928862e-03, -1.8560279471199331e-05, + -9.6269883559477111e-05, -2.7480124608354376e-04, 4.0890266760258649e-06, + 6.8115232787057308e-06, 7.9717774256069590e-17, -6.6158684055542149e-05, + 5.6930861126356883e-06, 2.4536651900581864e-04, 8.4222652499154474e-05, + -2.1095228673489870e-05, -7.2475264609192327e-06, -3.1236139835906653e-04, + 3.0620542597938747e-07, 5.2383308233409013e-07, 4.5367438840226148e-17, + 7.5521454677788689e-04, -6.4959947881067446e-05, 2.1803021136887151e-04, + -9.6141834203176198e-04, -1.8739033755341927e-05, 8.2696613375289981e-05, + -2.7756118472743952e-04, -3.5194659963031186e-06, -7.8598788404717967e-06, + 1.0409110540003064e-17, 1.3599971624203907e-03, -1.1698967736129318e-04, + 1.1761250922651231e-04, -1.7313308153829561e-03, -1.0103627331035097e-05, + 1.4893254125386500e-04, -1.4972543114425156e-04, -6.3208097101481016e-06, + -1.8339153449490702e-05, -1.8592739562088397e-17, 1.4669018971550508e-03, + -1.2615623684791310e-04, -7.2126947445431660e-05, -1.8674248210697011e-03, + 6.2473383435715822e-06, 1.6060193832964713e-04, 9.1820490646870895e-05, + -6.8766677416233056e-06, -3.0915439591944671e-05, -3.4169910043710598e-17, + 7.3835886561778822e-04, -6.3621467426451799e-05, -3.6743879842920073e-04, + -9.3996038534386532e-04, 3.1529332913731504e-05, 8.0992674189995619e-05, + 4.6776429544571370e-04, -3.2207980489607478e-06, -4.5587253648864800e-05, + -1.3033565763243572e-17, -1.2218883130104699e-03, 1.9925006776766980e-04, + 3.3680823229324827e-05, 1.5555127229134420e-03, -5.4906542718873293e-06, + -2.5365331033436574e-04, -4.2877035890732717e-05, 1.2579210421270085e-06, + 8.6095141065868681e-06, 8.5843190723295419e-17, -9.9469578895192406e-04, + 1.6220276314314548e-04, 9.5710452873525549e-05, 1.2662875474526807e-03, + -1.5602511542291027e-05, -2.0649060889963317e-04, -1.2184323687799138e-04, + 1.0239596690626961e-06, 7.2319800498269018e-06, 7.6128518192850284e-17, + -5.7725205425157491e-04, 9.4132221087062096e-05, 1.4174402118255613e-04, + 7.3486496691657513e-04, -2.3105816616276255e-05, -1.1983408465235449e-04, + -1.8044581161690831e-04, 5.9407987857311818e-07, 4.4769112358823013e-06, + 5.8602639297672241e-17, -4.3439872336690766e-05, 7.0856641229987313e-06, + 1.6111739776339482e-04, 5.5300695965309908e-05, -2.6262233432286444e-05, + -9.0203339996338009e-06, -2.0510889533447221e-04, 4.4421321296519763e-08, + 3.4429239733250568e-07, 3.4926715594934423e-17, 4.9591678847464517e-04, + -8.0861991798899719e-05, 1.4316667347179717e-04, -6.3132191851335946e-04, + -2.3329868400283431e-05, 1.0294055168874697e-04, -1.8225690491621555e-04, + -5.1117197886643198e-07, -5.1659110589382652e-06, 1.0102921131673717e-17, + 8.9304807164371051e-04, -1.4562879398958924e-04, 7.7225405099948114e-05, + -1.1368859353378222e-03, -1.2582857886102611e-05, 1.8539128287040646e-04, + -9.8311031283336125e-05, -9.1822109815642119e-07, -1.2053450101606588e-05, + -8.9611256229312162e-18, 9.6325796444312359e-04, -1.5703540377679862e-04, + -4.7364249466624545e-05, -1.2262659386990057e-03, 7.7720809383173407e-06, + 1.9991235362653694e-04, 6.0296585106922121e-05, -9.9955532671637544e-07, + -2.0321917006824889e-05, -1.4644761409477663e-17, 4.8485609369285158e-04, + -7.9184942178627942e-05, -2.4126875678009328e-04, -6.1724121140272088e-04, + 3.9263369648519171e-05, 1.0080560040594159e-04, 3.0714478305167290e-04, + -4.6828117363387576e-07, -2.9948261566553504e-05, -1.2605868310791414e-17, + -5.5318357068331902e-04, 1.7536157032520592e-04, 1.5250285570937922e-05, + 7.0422482410403353e-04, -4.8299508614752260e-06, -2.2324229706304245e-04, + -1.9414223854234676e-05, -7.6230039760333720e-06, 3.8612474615733436e-06, + 5.1737179513716968e-17, -4.5032633391021244e-04, 1.4275601491743441e-04, + 4.3336922314421925e-05, 5.7328344530477055e-04, -1.3724632897095447e-05, + -1.8173412014178895e-04, -5.5169636466947756e-05, -6.2054078588158429e-06, + 3.2435488692399899e-06, 4.8028491712169638e-17, -2.6133624469453566e-04, + 8.2846618815280416e-05, 6.4181688197263934e-05, 3.3269149827546476e-04, + -2.0323581324053096e-05, -1.0546706130613400e-04, -8.1705857651543159e-05, + -3.6005452741340406e-06, 2.0081691410636277e-06, 3.8520388310352902e-17, + -1.9661496835333231e-05, 6.2364545034745673e-06, 7.2956872225951117e-05, + 2.5029872332176844e-05, -2.3096613004447442e-05, -7.9392561682747264e-06, + -9.2877018106376599e-05, -2.7032276650755302e-07, 1.5500833779823407e-07, + 2.3954220237922715e-17, 2.2452284971681333e-04, -7.1167813182502039e-05, + 6.4833668634053107e-05, -2.8582657318236793e-04, -2.0511575929727710e-05, + 9.0599474345224277e-05, -8.2535854840078805e-05, 3.0981066058928703e-06, + -2.3154572454531680e-06, 8.4437989845047043e-18, 4.0432786569248309e-04, + -1.2816820392756137e-04, 3.4987563703451466e-05, -5.1472555438688986e-04, + -1.1047540869100629e-05, 1.6316325294175941e-04, -4.4540568810560594e-05, + 5.5618567638296239e-06, -5.4055108406485347e-06, -3.3020213440190191e-18, + 4.3610842151560496e-04, -1.3819686293535001e-04, -2.1413925090722030e-05, + -5.5518347382006619e-04, 6.8888362637683960e-06, 1.7593013720955338e-04, + 2.7260783634202321e-05, 6.0629566842151169e-06, -9.1041122183861232e-06, + -7.2371742466117540e-18, 2.1943348004293205e-04, -6.9776478809210302e-05, + -1.0931001556628712e-04, -2.7934760190890623e-04, 3.4451757069420710e-05, + 8.8828250006272910e-05, 1.3915602444573250e-04, 2.8472996610849330e-06, + -1.3462461610689810e-05, -1.4223434379638855e-18, -9.3040091887961748e-05, + 7.6930184467915048e-05, 2.5570471988835521e-06, 1.1844376047444965e-04, + -2.1248537374219816e-06, -9.7935203603906131e-05, -3.2552234182110448e-06, + -1.7981070634123119e-05, 7.9801219628408649e-07, 1.3255963992479744e-17, + -7.5742210399364090e-05, 6.2625581143333398e-05, 7.2652034204423278e-06, + 9.6422865071444226e-05, -6.0388313855885586e-06, -7.9724871095860508e-05, + -9.2488947105183267e-06, -1.4636620319132153e-05, 6.7044703542109376e-07, + 1.5454990145859717e-17, -4.3958996718337654e-05, 3.6342108184726977e-05, + 1.0755488950520903e-05, 5.5961562078806149e-05, -8.9457858332929588e-06, + -4.6264958144601579e-05, -1.3692167872881542e-05, -8.4914149761173461e-06, + 4.1533005655934768e-07, 2.3331565406350569e-17, -3.3149552045454746e-06, + 2.7320505889872851e-06, 1.2216240033802679e-05, 4.2200706411281198e-06, + -1.0173710041968676e-05, -3.4780097375416221e-06, -1.5551762461788650e-05, + -6.3374425050565725e-07, 3.2586873501894366e-08, 1.4287004275686782e-17, + 3.7749886887661497e-05, -3.1230076485256521e-05, 1.0834213338389489e-05, + -4.8057116773325226e-05, -9.0542379286305008e-06, 3.9757137205703429e-05, + -1.3792387169260664e-05, 7.3084505808951379e-06, -4.7736440058582091e-07, + -5.1426902537239170e-19, 6.8002926475318857e-05, -5.6225462188814054e-05, + 5.8069646962412217e-06, -8.6570446906972983e-05, -4.9002968245301933e-06, + 7.1577263531492970e-05, -7.3924984553271851e-06, 1.3140222484471872e-05, + -1.1167339315051476e-06, -1.0014636178582984e-18, 7.3270287126041972e-05, + -6.0708847522397337e-05, -3.7405038611585289e-06, -9.3276007817187916e-05, + 2.8745282594752142e-06, 7.7284792487988441e-05, 4.7618111116923385e-06, + 1.4257402535386491e-05, -1.8716955469369723e-06, -1.7259023988470547e-18, + 3.7604074979957093e-05, -3.0294674009570444e-05, -1.8072883786921887e-05, + -4.7871492379369695e-05, 1.5390330853863949e-05, 3.8566332418962707e-05, + 2.3007504344675715e-05, 6.6491000063331675e-06, -2.8178579922985129e-06, + -7.5910951338837699e-19 }; return sol; } -static const double * -get_sol_3x_bias_p2_DxDx_DyNy(void) +static const double *get_sol_3x_bias_p2_DxDx_DyNy(void) { static const double sol[640] = { - 2.9366410440246786e-04, 1.5833417110396627e-04, 1.4679523967276470e-04, -3.7384615745761769e-04, 7.8278512648382849e-05, -2.0156573641117145e-04, - -1.8687621490639760e-04, -8.6854584348496205e-06, -1.7623476288500814e-05, 5.2300407698711697e-17, 5.8489869202463327e-04, 3.1367048785918631e-04, - 2.8617271619829673e-05, -7.4459944282316928e-04, 1.5601216385170638e-05, -3.9931508426113612e-04, -3.6430932046669887e-05, -1.8606531928366969e-05, - -1.1993596362429246e-05, -2.0892545508593297e-17, 5.4219548657418501e-04, 2.9091105641273601e-04, -4.6964511263591833e-05, -6.9023655328552677e-04, - -2.5099762187887353e-05, -3.7034141718842486e-04, 5.9787702377095255e-05, -1.7138457671773087e-05, -7.1078530313942427e-06, 3.9115154576600269e-17, - 3.0109676195039589e-04, 1.6152938865406988e-04, -8.6992163559288790e-05, -3.8330822797356349e-04, -4.6572459248522587e-05, -2.0563337622632095e-04, - 1.1074450567142924e-04, -9.5344390692464763e-06, -3.0476196624031540e-06, 5.6810779361459721e-17, -2.6369173462459848e-05, -1.4156115092992755e-05, - -9.7874810517917558e-05, 3.3569013122980706e-05, -5.2437299075891127e-05, 1.8021301046486428e-05, 1.2459855077798471e-04, 8.2737327436896982e-07, - 2.0225634438136138e-07, -1.3373254239006441e-16, -3.5046776690432491e-04, -1.8804143086091797e-04, -8.6097341541172933e-05, 4.4615949312728348e-04, - -4.6138941824949177e-05, 2.3938426697800533e-04, 1.0960536143108869e-04, 1.1077684120011821e-05, 2.6393373958376242e-06, -1.6032627550668000e-16, - -6.0391518322698437e-04, -3.2401990289661098e-04, -5.8133025438105893e-05, 7.6880819717087235e-04, -3.1157234702228416e-05, 4.1249030379158797e-04, - 7.4005667889267377e-05, 1.9094342915948621e-05, 4.2641058540425827e-06, 2.0275386120011121e-16, -7.4185325279781252e-04, -3.9802597843876847e-04, - -2.0456784067544166e-05, 9.4440888007044500e-04, -1.0964684083691834e-05, 5.0670299970890988e-04, 2.6042304806449675e-05, 2.3457263346559995e-05, - 5.0764812237368312e-06, 2.3746653068095925e-16, 7.1871323474278386e-04, 8.7710214994792733e-05, 3.5755576442357139e-04, -9.1495071101398823e-04, - 4.3774882151079233e-05, -1.1165861388563981e-04, -4.5518279763369802e-04, -8.1880463208082919e-06, -4.4456825652008327e-05, 3.4242442663156875e-18, - 1.4277325347644839e-03, 1.7441241606391770e-04, 7.0228009414156716e-05, -1.8175606551731503e-03, 8.5314378018246768e-06, -2.2203398570289667e-04, - -8.9403066536790140e-05, -1.7465893456554210e-05, -3.0180009723319835e-05, 8.4266422106792768e-18, 1.3236741350856989e-03, 1.6169038423838374e-04, - -1.1444951102738993e-04, -1.6850901479238550e-03, -1.4004905074141413e-05, -2.0583833004829191e-04, 1.4569880785236580e-04, -1.6042765456800721e-05, - -1.7897506519466129e-05, 7.4908691137896685e-18, 7.3504616021230983e-04, 8.9786913323435284e-05, -2.1219385883246752e-04, -9.3574317878671607e-04, - -2.5939534318855813e-05, -1.1430233396838016e-04, 2.7013127437548387e-04, -8.9337392931378460e-06, -7.6719397877386337e-06, -3.8697968593087614e-18, - -6.4401076441772531e-05, -7.8652359084996697e-06, -2.3880385491960462e-04, 8.1985147666986571e-05, -2.9185828660990960e-05, 1.0012760081324107e-05, - 3.0400686433691541e-04, 7.7809221149930562e-07, 5.1040642096020408e-07, -1.3552017760322912e-17, -8.5563118982616470e-04, -1.0451452877114972e-04, - -2.1009107982637403e-04, 1.0892527473457853e-03, -2.5673892807371934e-05, 1.3305117783822941e-04, 2.6745435254661032e-04, 1.0380762902208026e-05, - 6.6467490018253722e-06, 2.7973538917408030e-17, -1.4743782859743448e-03, -1.8009465973339782e-04, -1.4186131475814963e-04, 1.8769425632445393e-03, - -1.7335155668355575e-05, 2.2926770929982388e-04, 1.8059513103275228e-04, 1.7891815716312892e-05, 1.0737709998674950e-05, 1.0215351539542659e-16, - -1.8111297630616155e-03, -2.2122899042747670e-04, -4.9921555573624397e-05, 2.3056406705032179e-03, -6.1001783803642330e-06, 2.8163335848549524e-04, - 6.3552138125521157e-05, 2.1979419790251000e-05, 1.2783176280231583e-05, 1.6952945329051220e-16, 9.1041892369545115e-04, 2.4407192087632311e-05, - 4.5307301340360138e-04, -1.1589997251880938e-03, 1.2201146101923685e-05, -3.1071332313057810e-05, -5.7678007822300462e-04, -7.0756666650892133e-06, - -5.6202873171458269e-05, 3.4656927675756581e-18, 1.8087408305903975e-03, 4.8609262873996356e-05, 8.8933756155082204e-05, -2.3025994638614634e-03, - 2.3689535246087084e-06, -6.1881537000423172e-05, -1.1321623074934100e-04, -1.5106133674220888e-05, -3.8108004663833130e-05, -2.0277669099632116e-18, - 1.6769291755920760e-03, 4.5047880146264644e-05, -1.4502400361682781e-04, -2.1347979518942664e-03, -3.8980585320159521e-06, -5.7347754260095698e-05, - 1.8462136052194050e-04, -1.3884451253027081e-05, -2.2607359364032397e-05, -3.6018740075868448e-18, 9.3120558827613370e-04, 2.5018632896834594e-05, - -2.6884245930153939e-04, -1.1854619810895682e-03, -7.2279537638890951e-06, -3.1849720933219562e-05, 3.4224720987189965e-04, -7.7309086961055159e-06, - -9.6892163186640667e-06, 2.9794417583722753e-18, -8.1583353671867056e-05, -2.1908826904851967e-06, -3.0254949112893797e-04, 1.0385887422231885e-04, - -8.1313422416429613e-06, 2.7890813449587394e-06, 3.8515761035684765e-04, 6.7280421817594080e-07, 6.4546625765690147e-07, 2.4525852988621017e-17, - -1.0839644414272339e-03, -2.9119379734364328e-05, -2.6616909306347378e-04, 1.3799301146205072e-03, -7.1531646979110311e-06, 3.7070135770882644e-05, - 3.3884390766164801e-04, 8.9821168968263622e-06, 8.3963955227189118e-06, 6.1062881766822862e-17, -1.8678324615433244e-03, -5.0177806705337605e-05, - -1.7972636255985985e-04, 2.3778254749349070e-03, -4.8298278531550706e-06, 6.3878356071485530e-05, 2.2879885225844988e-04, 1.5481586715522154e-05, - 1.3563696440521318e-05, 1.0170969510065392e-16, -2.2944506126898303e-03, -6.1638761923241793e-05, -6.3246271865108493e-05, 2.9209274547706884e-03, - -1.6996066367282102e-06, 7.8468610735822411e-05, 8.0515035224968325e-05, 1.9018655925887671e-05, 1.6147340377885233e-05, 1.3017529747857753e-16, - 9.0124227629200860e-04, -2.7574015762490868e-05, 4.4848460248164451e-04, -1.1473174857901441e-03, -1.3619750415973458e-05, 3.5102825588677369e-05, - -5.7093884748951151e-04, -5.4247562557807852e-06, -5.5653119508569121e-05, 7.1998202120845336e-18, 1.7904898493184785e-03, -5.4594815714664041e-05, - 8.8038739116150133e-05, -2.2793652342908430e-03, -2.7188239063540939e-06, 6.9501385310805707e-05, -1.1207683823985288e-04, -1.1580436012153722e-05, - -3.7747530559385986e-05, -1.5499910534328783e-17, 1.6599996084288332e-03, -5.0637183330141720e-05, -1.4355365040743972e-04, -2.1132459353675240e-03, - 4.3684028831044450e-06, 6.4463160899274558e-05, 1.8274954204226132e-04, -1.0642774281306924e-05, -2.2392186132941347e-05, -9.7248139365350449e-18, - 9.2180607376468311e-04, -2.8115105526518080e-05, -2.6612401553145607e-04, -1.1734960229442541e-03, 8.1052313173892082e-06, 3.5791654512840400e-05, - 3.3878652215938977e-04, -5.9258354008358425e-06, -9.5969568198578901e-06, 6.9752705364097240e-18, -8.0757424528087745e-05, 2.4649783637273693e-06, - -2.9949136733266676e-04, 1.0280743336824149e-04, 9.1266848261757754e-06, -3.1380161064356613e-06, 3.8126449637687908e-04, 5.1575107170505907e-07, - 6.3927833037202208e-07, 3.5192119948421573e-17, -1.0730176634535381e-03, 3.2732351109887696e-05, -2.6347918201771086e-04, 1.3659944281656262e-03, - 8.0305360856018143e-06, -4.1669592924463010e-05, 3.3541954324910477e-04, 6.8851645536152629e-06, 8.3164350440190415e-06, 6.7623191256853138e-17, - -1.8489709303059082e-03, 5.6401394648705165e-05, -1.7791020436132767e-04, 2.3538139908238099e-03, 5.4230258469341092e-06, -7.1801232593809148e-05, - 2.2648681018836388e-04, 1.1867224005866285e-05, 1.3434536925260396e-05, 9.6858086594756248e-17, -2.2712814698432004e-03, 6.9283273198992435e-05, - -6.2607182589649867e-05, 2.8914322086887683e-03, 1.9084463650295836e-06, -8.8200379526170002e-05, 7.9701449000709159e-05, 1.4578513220969622e-05, - 1.5993584902367352e-05, 1.1458621488120533e-16, 7.3835886561804734e-04, -6.3621467426478321e-05, 3.6743879842914538e-04, -9.3996038534395249e-04, - -3.1529332913732161e-05, 8.0992674190009836e-05, -4.6776429544570817e-04, -3.2207980490257788e-06, -4.5587253648868073e-05, -5.2983440882930716e-17, - 1.4669018971551885e-03, -1.2615623684792459e-04, 7.2126947445427228e-05, -1.8674248210697438e-03, -6.2473383435674419e-06, 1.6060193832965298e-04, - -9.1820490646871234e-05, -6.8766677416135300e-06, -3.0915439591939562e-05, -2.2073630823871677e-17, 1.3599971624205301e-03, -1.1698967736130279e-04, - -1.1761250922651303e-04, -1.7313308153829919e-03, 1.0103627331035624e-05, 1.4893254125386966e-04, 1.4972543114425736e-04, -6.3208097101507841e-06, - -1.8339153449490641e-05, -1.3511233360745342e-17, 7.5521454677802871e-04, -6.4959947881077407e-05, -2.1803021136886910e-04, -9.6141834203178074e-04, - 1.8739033755341243e-05, 8.2696613375290469e-05, 2.7756118472744331e-04, -3.5194659963027014e-06, -7.8598788404715155e-06, 6.3647442170826156e-18, - -6.6158684055394061e-05, 5.6930861126234088e-06, -2.4536651900581766e-04, 8.4222652499145448e-05, 2.1095228673489402e-05, -7.2475264609209123e-06, - 3.1236139835906821e-04, 3.0620542597954841e-07, 5.2383308233434244e-07, 3.2945633218545722e-17, -8.7908999816583612e-04, 7.5622040169414726e-05, - -2.1586222088963581e-04, 1.1191167491928801e-03, 1.8560279471199578e-05, -9.6269883559480283e-05, 2.7480124608354371e-04, 4.0890266760259386e-06, - 6.8115232787059417e-06, 6.0328404987001239e-17, -1.5148068254140711e-03, 1.3030661548298094e-04, -1.4575747047953794e-04, 1.9284097119175055e-03, - 1.2533216551744164e-05, -1.6588553643187519e-04, 1.8555509319178416e-04, 7.0478959388720808e-06, 1.1003322845519606e-05, 8.2874361330714665e-17, - -1.8607939734752923e-03, 1.6006863502988851e-04, -5.1292513034897953e-05, 2.3688651979412710e-03, 4.4105638650403004e-06, -2.0377377840282172e-04, - 6.5297421839983865e-05, 8.6581482607713805e-06, 1.3099218422382941e-05, 9.7474000767547502e-17, 4.8485609369288524e-04, -7.9184942178639150e-05, - 2.4126875678013267e-04, -6.1724121140272294e-04, -3.9263369648531429e-05, 1.0080560040594443e-04, -3.0714478305168537e-04, -4.6828117362726122e-07, - -2.9948261566555140e-05, -1.5921508748764577e-17, 9.6325796444322377e-04, -1.5703540377681838e-04, 4.7364249466624342e-05, -1.2262659386990328e-03, - -7.7720809383103560e-06, 1.9991235362654542e-04, -6.0296585106920495e-05, -9.9955532671419899e-07, -2.0321917006825774e-05, -2.2758358789180729e-17, - 8.9304807164381145e-04, -1.4562879398959960e-04, -7.7225405099946433e-05, -1.1368859353378421e-03, 1.2582857886101947e-05, 1.8539128287041017e-04, - 9.8311031283338307e-05, -9.1822109815711544e-07, -1.2053450101606825e-05, -1.3072496749888570e-17, 4.9591678847475055e-04, -8.0861991798911103e-05, - -1.4316667347179625e-04, -6.3132191851337312e-04, 2.3329868400283174e-05, 1.0294055168874902e-04, 1.8225690491621642e-04, -5.1117197886615828e-07, - -5.1659110589384939e-06, 2.0803388797406004e-18, -4.3439872336584223e-05, 7.0856641229869017e-06, -1.6111739776339564e-04, 5.5300695965298171e-05, - 2.6262233432285939e-05, -9.0203339996339110e-06, 2.0510889533447205e-04, 4.4421321296593752e-08, 3.4429239733182826e-07, 2.2562023417140470e-17, - -5.7725205425146931e-04, 9.4132221087049370e-05, -1.4174402118255600e-04, 7.3486496691656049e-04, 2.3105816616276611e-05, -1.1983408465235623e-04, - 1.8044581161690771e-04, 5.9407987857315407e-07, 4.4769112358815145e-06, 4.4436566150092569e-17, -9.9469578895181997e-04, 1.6220276314313309e-04, - -9.5710452873525644e-05, 1.2662875474526614e-03, 1.5602511542291521e-05, -2.0649060889963382e-04, 1.2184323687798982e-04, 1.0239596690627556e-06, - 7.2319800498266867e-06, 6.1369779999155662e-17, -1.2218883130103663e-03, 1.9925006776765812e-04, -3.3680823229324854e-05, 1.5555127229134207e-03, - 5.4906542718873632e-06, -2.5365331033436612e-04, 4.2877035890732656e-05, 1.2579210421270104e-06, 8.6095141065869613e-06, 7.1629786937454728e-17, - 2.1943348004296780e-04, -6.9776478809209231e-05, 1.0931001556629078e-04, -2.7934760190890233e-04, -3.4451757069426652e-05, 8.8828250006276136e-05, - -1.3915602444573700e-04, 2.8472996610827392e-06, -1.3462461610689957e-05, -1.3423725475374167e-17, 4.3610842151565722e-04, -1.3819686293535999e-04, - 2.1413925090727119e-05, -5.5518347382007280e-04, -6.8888362637695031e-06, 1.7593013720955733e-04, -2.7260783634204059e-05, 6.0629566842156252e-06, - -9.1041122183868957e-06, -1.3232981739875361e-17, 4.0432786569254695e-04, -1.2816820392757143e-04, -3.4987563703448329e-05, -5.1472555438689680e-04, - 1.1047540869101181e-05, 1.6316325294176266e-04, 4.4540568810561190e-05, 5.5618567638297611e-06, -5.4055108406481688e-06, -1.1067173402525196e-17, - 2.2452284971688618e-04, -7.1167813182509290e-05, -6.4833668634051413e-05, -2.8582657318237232e-04, 2.0511575929728835e-05, 9.0599474345227855e-05, - 8.2535854840079563e-05, 3.0981066058932078e-06, -2.3154572454531503e-06, -2.0250909035767044e-18, -1.9661496835268277e-05, 6.2364545034624598e-06, - -7.2956872225952743e-05, 2.5029872332164925e-05, 2.3096613004447052e-05, -7.9392561682745486e-06, 9.2877018106373739e-05, -2.7032276650741835e-07, - 1.5500833780181726e-07, 1.3277001112846085e-17, -2.6133624469447495e-04, 8.2846618815267040e-05, -6.4181688197265032e-05, 3.3269149827544773e-04, - 2.0323581324052313e-05, -1.0546706130613412e-04, 8.1705857651540774e-05, -3.6005452741341418e-06, 2.0081691410669324e-06, 2.8571060802081716e-17, - -4.5032633391014668e-04, 1.4275601491742435e-04, -4.3336922314422691e-05, 5.7328344530475027e-04, 1.3724632897094390e-05, -1.8173412014178887e-04, - 5.5169636466947789e-05, -6.2054078588159285e-06, 3.2435488692397214e-06, 3.8969589344185024e-17, -5.5318357068325397e-04, 1.7536157032519553e-04, - -1.5250285570937746e-05, 7.0422482410401348e-04, 4.8299508614755072e-06, -2.2324229706304123e-04, 1.9414223854234778e-05, -7.6230039760334219e-06, - 3.8612474615728133e-06, 4.3284701132573816e-17, 3.7604074979975477e-05, -3.0294674009582567e-05, 1.8072883786917177e-05, -4.7871492379365758e-05, - -1.5390330853862085e-05, 3.8566332418961975e-05, -2.3007504344675498e-05, 6.6491000063301673e-06, -2.8178579922956300e-06, -7.9095918696594176e-18, - 7.3270287126054955e-05, -6.0708847522411039e-05, 3.7405038611583371e-06, -9.3276007817184013e-05, -2.8745282594779060e-06, 7.7284792487990650e-05, - -4.7618111116928247e-06, 1.4257402535386187e-05, -1.8716955469354936e-06, -3.9505250537844865e-18, 6.8002926475353674e-05, -5.6225462188821847e-05, - -5.8069646962339915e-06, -8.6570446906970746e-05, 4.9002968245327234e-06, 7.1577263531495111e-05, 7.3924984553274739e-06, 1.3140222484471143e-05, - -1.1167339315079637e-06, -1.0990652265370899e-17, 3.7749886887707968e-05, -3.1230076485260194e-05, -1.0834213338389640e-05, -4.8057116773323850e-05, - 9.0542379286307905e-06, 3.9757137205704310e-05, 1.3792387169260654e-05, 7.3084505808988420e-06, -4.7736440058837683e-07, -1.5484276100280180e-17, - -3.3149552045122865e-06, 2.7320505889780681e-06, -1.2216240033828867e-05, 4.2200706411434401e-06, 1.0173710041948193e-05, -3.4780097375270807e-06, - 1.5551762461777675e-05, -6.3374425050783931e-07, 3.2586873484871532e-08, 7.1248334377215630e-18, -4.3958996718323173e-05, 3.6342108184710239e-05, - -1.0755488950499986e-05, 5.5961562078764271e-05, 8.9457858333129674e-06, -4.6264958144617056e-05, 1.3692167872886584e-05, -8.4914149761200091e-06, - 4.1533005654660920e-07, 2.1226076432594638e-17, -7.5742210399340238e-05, 6.2625581143322420e-05, -7.2652034204399960e-06, 9.6422865071429752e-05, - 6.0388313855885739e-06, -7.9724871095856144e-05, 9.2488947105202630e-06, -1.4636620319129859e-05, 6.7044703542218178e-07, 1.4353850908910043e-17, - -9.3040091887932651e-05, 7.6930184467904680e-05, -2.5570471988813422e-06, 1.1844376047443472e-04, 2.1248537374239493e-06, -9.7935203603904451e-05, - 3.2552234182113150e-06, -1.7981070634123197e-05, 7.9801219628634659e-07, 1.4947070801485985e-17, + 2.9366410440246786e-04, 1.5833417110396627e-04, 1.4679523967276470e-04, + -3.7384615745761769e-04, 7.8278512648382849e-05, -2.0156573641117145e-04, + -1.8687621490639760e-04, -8.6854584348496205e-06, -1.7623476288500814e-05, + 5.2300407698711697e-17, 5.8489869202463327e-04, 3.1367048785918631e-04, + 2.8617271619829673e-05, -7.4459944282316928e-04, 1.5601216385170638e-05, + -3.9931508426113612e-04, -3.6430932046669887e-05, -1.8606531928366969e-05, + -1.1993596362429246e-05, -2.0892545508593297e-17, 5.4219548657418501e-04, + 2.9091105641273601e-04, -4.6964511263591833e-05, -6.9023655328552677e-04, + -2.5099762187887353e-05, -3.7034141718842486e-04, 5.9787702377095255e-05, + -1.7138457671773087e-05, -7.1078530313942427e-06, 3.9115154576600269e-17, + 3.0109676195039589e-04, 1.6152938865406988e-04, -8.6992163559288790e-05, + -3.8330822797356349e-04, -4.6572459248522587e-05, -2.0563337622632095e-04, + 1.1074450567142924e-04, -9.5344390692464763e-06, -3.0476196624031540e-06, + 5.6810779361459721e-17, -2.6369173462459848e-05, -1.4156115092992755e-05, + -9.7874810517917558e-05, 3.3569013122980706e-05, -5.2437299075891127e-05, + 1.8021301046486428e-05, 1.2459855077798471e-04, 8.2737327436896982e-07, + 2.0225634438136138e-07, -1.3373254239006441e-16, -3.5046776690432491e-04, + -1.8804143086091797e-04, -8.6097341541172933e-05, 4.4615949312728348e-04, + -4.6138941824949177e-05, 2.3938426697800533e-04, 1.0960536143108869e-04, + 1.1077684120011821e-05, 2.6393373958376242e-06, -1.6032627550668000e-16, + -6.0391518322698437e-04, -3.2401990289661098e-04, -5.8133025438105893e-05, + 7.6880819717087235e-04, -3.1157234702228416e-05, 4.1249030379158797e-04, + 7.4005667889267377e-05, 1.9094342915948621e-05, 4.2641058540425827e-06, + 2.0275386120011121e-16, -7.4185325279781252e-04, -3.9802597843876847e-04, + -2.0456784067544166e-05, 9.4440888007044500e-04, -1.0964684083691834e-05, + 5.0670299970890988e-04, 2.6042304806449675e-05, 2.3457263346559995e-05, + 5.0764812237368312e-06, 2.3746653068095925e-16, 7.1871323474278386e-04, + 8.7710214994792733e-05, 3.5755576442357139e-04, -9.1495071101398823e-04, + 4.3774882151079233e-05, -1.1165861388563981e-04, -4.5518279763369802e-04, + -8.1880463208082919e-06, -4.4456825652008327e-05, 3.4242442663156875e-18, + 1.4277325347644839e-03, 1.7441241606391770e-04, 7.0228009414156716e-05, + -1.8175606551731503e-03, 8.5314378018246768e-06, -2.2203398570289667e-04, + -8.9403066536790140e-05, -1.7465893456554210e-05, -3.0180009723319835e-05, + 8.4266422106792768e-18, 1.3236741350856989e-03, 1.6169038423838374e-04, + -1.1444951102738993e-04, -1.6850901479238550e-03, -1.4004905074141413e-05, + -2.0583833004829191e-04, 1.4569880785236580e-04, -1.6042765456800721e-05, + -1.7897506519466129e-05, 7.4908691137896685e-18, 7.3504616021230983e-04, + 8.9786913323435284e-05, -2.1219385883246752e-04, -9.3574317878671607e-04, + -2.5939534318855813e-05, -1.1430233396838016e-04, 2.7013127437548387e-04, + -8.9337392931378460e-06, -7.6719397877386337e-06, -3.8697968593087614e-18, + -6.4401076441772531e-05, -7.8652359084996697e-06, -2.3880385491960462e-04, + 8.1985147666986571e-05, -2.9185828660990960e-05, 1.0012760081324107e-05, + 3.0400686433691541e-04, 7.7809221149930562e-07, 5.1040642096020408e-07, + -1.3552017760322912e-17, -8.5563118982616470e-04, -1.0451452877114972e-04, + -2.1009107982637403e-04, 1.0892527473457853e-03, -2.5673892807371934e-05, + 1.3305117783822941e-04, 2.6745435254661032e-04, 1.0380762902208026e-05, + 6.6467490018253722e-06, 2.7973538917408030e-17, -1.4743782859743448e-03, + -1.8009465973339782e-04, -1.4186131475814963e-04, 1.8769425632445393e-03, + -1.7335155668355575e-05, 2.2926770929982388e-04, 1.8059513103275228e-04, + 1.7891815716312892e-05, 1.0737709998674950e-05, 1.0215351539542659e-16, + -1.8111297630616155e-03, -2.2122899042747670e-04, -4.9921555573624397e-05, + 2.3056406705032179e-03, -6.1001783803642330e-06, 2.8163335848549524e-04, + 6.3552138125521157e-05, 2.1979419790251000e-05, 1.2783176280231583e-05, + 1.6952945329051220e-16, 9.1041892369545115e-04, 2.4407192087632311e-05, + 4.5307301340360138e-04, -1.1589997251880938e-03, 1.2201146101923685e-05, + -3.1071332313057810e-05, -5.7678007822300462e-04, -7.0756666650892133e-06, + -5.6202873171458269e-05, 3.4656927675756581e-18, 1.8087408305903975e-03, + 4.8609262873996356e-05, 8.8933756155082204e-05, -2.3025994638614634e-03, + 2.3689535246087084e-06, -6.1881537000423172e-05, -1.1321623074934100e-04, + -1.5106133674220888e-05, -3.8108004663833130e-05, -2.0277669099632116e-18, + 1.6769291755920760e-03, 4.5047880146264644e-05, -1.4502400361682781e-04, + -2.1347979518942664e-03, -3.8980585320159521e-06, -5.7347754260095698e-05, + 1.8462136052194050e-04, -1.3884451253027081e-05, -2.2607359364032397e-05, + -3.6018740075868448e-18, 9.3120558827613370e-04, 2.5018632896834594e-05, + -2.6884245930153939e-04, -1.1854619810895682e-03, -7.2279537638890951e-06, + -3.1849720933219562e-05, 3.4224720987189965e-04, -7.7309086961055159e-06, + -9.6892163186640667e-06, 2.9794417583722753e-18, -8.1583353671867056e-05, + -2.1908826904851967e-06, -3.0254949112893797e-04, 1.0385887422231885e-04, + -8.1313422416429613e-06, 2.7890813449587394e-06, 3.8515761035684765e-04, + 6.7280421817594080e-07, 6.4546625765690147e-07, 2.4525852988621017e-17, + -1.0839644414272339e-03, -2.9119379734364328e-05, -2.6616909306347378e-04, + 1.3799301146205072e-03, -7.1531646979110311e-06, 3.7070135770882644e-05, + 3.3884390766164801e-04, 8.9821168968263622e-06, 8.3963955227189118e-06, + 6.1062881766822862e-17, -1.8678324615433244e-03, -5.0177806705337605e-05, + -1.7972636255985985e-04, 2.3778254749349070e-03, -4.8298278531550706e-06, + 6.3878356071485530e-05, 2.2879885225844988e-04, 1.5481586715522154e-05, + 1.3563696440521318e-05, 1.0170969510065392e-16, -2.2944506126898303e-03, + -6.1638761923241793e-05, -6.3246271865108493e-05, 2.9209274547706884e-03, + -1.6996066367282102e-06, 7.8468610735822411e-05, 8.0515035224968325e-05, + 1.9018655925887671e-05, 1.6147340377885233e-05, 1.3017529747857753e-16, + 9.0124227629200860e-04, -2.7574015762490868e-05, 4.4848460248164451e-04, + -1.1473174857901441e-03, -1.3619750415973458e-05, 3.5102825588677369e-05, + -5.7093884748951151e-04, -5.4247562557807852e-06, -5.5653119508569121e-05, + 7.1998202120845336e-18, 1.7904898493184785e-03, -5.4594815714664041e-05, + 8.8038739116150133e-05, -2.2793652342908430e-03, -2.7188239063540939e-06, + 6.9501385310805707e-05, -1.1207683823985288e-04, -1.1580436012153722e-05, + -3.7747530559385986e-05, -1.5499910534328783e-17, 1.6599996084288332e-03, + -5.0637183330141720e-05, -1.4355365040743972e-04, -2.1132459353675240e-03, + 4.3684028831044450e-06, 6.4463160899274558e-05, 1.8274954204226132e-04, + -1.0642774281306924e-05, -2.2392186132941347e-05, -9.7248139365350449e-18, + 9.2180607376468311e-04, -2.8115105526518080e-05, -2.6612401553145607e-04, + -1.1734960229442541e-03, 8.1052313173892082e-06, 3.5791654512840400e-05, + 3.3878652215938977e-04, -5.9258354008358425e-06, -9.5969568198578901e-06, + 6.9752705364097240e-18, -8.0757424528087745e-05, 2.4649783637273693e-06, + -2.9949136733266676e-04, 1.0280743336824149e-04, 9.1266848261757754e-06, + -3.1380161064356613e-06, 3.8126449637687908e-04, 5.1575107170505907e-07, + 6.3927833037202208e-07, 3.5192119948421573e-17, -1.0730176634535381e-03, + 3.2732351109887696e-05, -2.6347918201771086e-04, 1.3659944281656262e-03, + 8.0305360856018143e-06, -4.1669592924463010e-05, 3.3541954324910477e-04, + 6.8851645536152629e-06, 8.3164350440190415e-06, 6.7623191256853138e-17, + -1.8489709303059082e-03, 5.6401394648705165e-05, -1.7791020436132767e-04, + 2.3538139908238099e-03, 5.4230258469341092e-06, -7.1801232593809148e-05, + 2.2648681018836388e-04, 1.1867224005866285e-05, 1.3434536925260396e-05, + 9.6858086594756248e-17, -2.2712814698432004e-03, 6.9283273198992435e-05, + -6.2607182589649867e-05, 2.8914322086887683e-03, 1.9084463650295836e-06, + -8.8200379526170002e-05, 7.9701449000709159e-05, 1.4578513220969622e-05, + 1.5993584902367352e-05, 1.1458621488120533e-16, 7.3835886561804734e-04, + -6.3621467426478321e-05, 3.6743879842914538e-04, -9.3996038534395249e-04, + -3.1529332913732161e-05, 8.0992674190009836e-05, -4.6776429544570817e-04, + -3.2207980490257788e-06, -4.5587253648868073e-05, -5.2983440882930716e-17, + 1.4669018971551885e-03, -1.2615623684792459e-04, 7.2126947445427228e-05, + -1.8674248210697438e-03, -6.2473383435674419e-06, 1.6060193832965298e-04, + -9.1820490646871234e-05, -6.8766677416135300e-06, -3.0915439591939562e-05, + -2.2073630823871677e-17, 1.3599971624205301e-03, -1.1698967736130279e-04, + -1.1761250922651303e-04, -1.7313308153829919e-03, 1.0103627331035624e-05, + 1.4893254125386966e-04, 1.4972543114425736e-04, -6.3208097101507841e-06, + -1.8339153449490641e-05, -1.3511233360745342e-17, 7.5521454677802871e-04, + -6.4959947881077407e-05, -2.1803021136886910e-04, -9.6141834203178074e-04, + 1.8739033755341243e-05, 8.2696613375290469e-05, 2.7756118472744331e-04, + -3.5194659963027014e-06, -7.8598788404715155e-06, 6.3647442170826156e-18, + -6.6158684055394061e-05, 5.6930861126234088e-06, -2.4536651900581766e-04, + 8.4222652499145448e-05, 2.1095228673489402e-05, -7.2475264609209123e-06, + 3.1236139835906821e-04, 3.0620542597954841e-07, 5.2383308233434244e-07, + 3.2945633218545722e-17, -8.7908999816583612e-04, 7.5622040169414726e-05, + -2.1586222088963581e-04, 1.1191167491928801e-03, 1.8560279471199578e-05, + -9.6269883559480283e-05, 2.7480124608354371e-04, 4.0890266760259386e-06, + 6.8115232787059417e-06, 6.0328404987001239e-17, -1.5148068254140711e-03, + 1.3030661548298094e-04, -1.4575747047953794e-04, 1.9284097119175055e-03, + 1.2533216551744164e-05, -1.6588553643187519e-04, 1.8555509319178416e-04, + 7.0478959388720808e-06, 1.1003322845519606e-05, 8.2874361330714665e-17, + -1.8607939734752923e-03, 1.6006863502988851e-04, -5.1292513034897953e-05, + 2.3688651979412710e-03, 4.4105638650403004e-06, -2.0377377840282172e-04, + 6.5297421839983865e-05, 8.6581482607713805e-06, 1.3099218422382941e-05, + 9.7474000767547502e-17, 4.8485609369288524e-04, -7.9184942178639150e-05, + 2.4126875678013267e-04, -6.1724121140272294e-04, -3.9263369648531429e-05, + 1.0080560040594443e-04, -3.0714478305168537e-04, -4.6828117362726122e-07, + -2.9948261566555140e-05, -1.5921508748764577e-17, 9.6325796444322377e-04, + -1.5703540377681838e-04, 4.7364249466624342e-05, -1.2262659386990328e-03, + -7.7720809383103560e-06, 1.9991235362654542e-04, -6.0296585106920495e-05, + -9.9955532671419899e-07, -2.0321917006825774e-05, -2.2758358789180729e-17, + 8.9304807164381145e-04, -1.4562879398959960e-04, -7.7225405099946433e-05, + -1.1368859353378421e-03, 1.2582857886101947e-05, 1.8539128287041017e-04, + 9.8311031283338307e-05, -9.1822109815711544e-07, -1.2053450101606825e-05, + -1.3072496749888570e-17, 4.9591678847475055e-04, -8.0861991798911103e-05, + -1.4316667347179625e-04, -6.3132191851337312e-04, 2.3329868400283174e-05, + 1.0294055168874902e-04, 1.8225690491621642e-04, -5.1117197886615828e-07, + -5.1659110589384939e-06, 2.0803388797406004e-18, -4.3439872336584223e-05, + 7.0856641229869017e-06, -1.6111739776339564e-04, 5.5300695965298171e-05, + 2.6262233432285939e-05, -9.0203339996339110e-06, 2.0510889533447205e-04, + 4.4421321296593752e-08, 3.4429239733182826e-07, 2.2562023417140470e-17, + -5.7725205425146931e-04, 9.4132221087049370e-05, -1.4174402118255600e-04, + 7.3486496691656049e-04, 2.3105816616276611e-05, -1.1983408465235623e-04, + 1.8044581161690771e-04, 5.9407987857315407e-07, 4.4769112358815145e-06, + 4.4436566150092569e-17, -9.9469578895181997e-04, 1.6220276314313309e-04, + -9.5710452873525644e-05, 1.2662875474526614e-03, 1.5602511542291521e-05, + -2.0649060889963382e-04, 1.2184323687798982e-04, 1.0239596690627556e-06, + 7.2319800498266867e-06, 6.1369779999155662e-17, -1.2218883130103663e-03, + 1.9925006776765812e-04, -3.3680823229324854e-05, 1.5555127229134207e-03, + 5.4906542718873632e-06, -2.5365331033436612e-04, 4.2877035890732656e-05, + 1.2579210421270104e-06, 8.6095141065869613e-06, 7.1629786937454728e-17, + 2.1943348004296780e-04, -6.9776478809209231e-05, 1.0931001556629078e-04, + -2.7934760190890233e-04, -3.4451757069426652e-05, 8.8828250006276136e-05, + -1.3915602444573700e-04, 2.8472996610827392e-06, -1.3462461610689957e-05, + -1.3423725475374167e-17, 4.3610842151565722e-04, -1.3819686293535999e-04, + 2.1413925090727119e-05, -5.5518347382007280e-04, -6.8888362637695031e-06, + 1.7593013720955733e-04, -2.7260783634204059e-05, 6.0629566842156252e-06, + -9.1041122183868957e-06, -1.3232981739875361e-17, 4.0432786569254695e-04, + -1.2816820392757143e-04, -3.4987563703448329e-05, -5.1472555438689680e-04, + 1.1047540869101181e-05, 1.6316325294176266e-04, 4.4540568810561190e-05, + 5.5618567638297611e-06, -5.4055108406481688e-06, -1.1067173402525196e-17, + 2.2452284971688618e-04, -7.1167813182509290e-05, -6.4833668634051413e-05, + -2.8582657318237232e-04, 2.0511575929728835e-05, 9.0599474345227855e-05, + 8.2535854840079563e-05, 3.0981066058932078e-06, -2.3154572454531503e-06, + -2.0250909035767044e-18, -1.9661496835268277e-05, 6.2364545034624598e-06, + -7.2956872225952743e-05, 2.5029872332164925e-05, 2.3096613004447052e-05, + -7.9392561682745486e-06, 9.2877018106373739e-05, -2.7032276650741835e-07, + 1.5500833780181726e-07, 1.3277001112846085e-17, -2.6133624469447495e-04, + 8.2846618815267040e-05, -6.4181688197265032e-05, 3.3269149827544773e-04, + 2.0323581324052313e-05, -1.0546706130613412e-04, 8.1705857651540774e-05, + -3.6005452741341418e-06, 2.0081691410669324e-06, 2.8571060802081716e-17, + -4.5032633391014668e-04, 1.4275601491742435e-04, -4.3336922314422691e-05, + 5.7328344530475027e-04, 1.3724632897094390e-05, -1.8173412014178887e-04, + 5.5169636466947789e-05, -6.2054078588159285e-06, 3.2435488692397214e-06, + 3.8969589344185024e-17, -5.5318357068325397e-04, 1.7536157032519553e-04, + -1.5250285570937746e-05, 7.0422482410401348e-04, 4.8299508614755072e-06, + -2.2324229706304123e-04, 1.9414223854234778e-05, -7.6230039760334219e-06, + 3.8612474615728133e-06, 4.3284701132573816e-17, 3.7604074979975477e-05, + -3.0294674009582567e-05, 1.8072883786917177e-05, -4.7871492379365758e-05, + -1.5390330853862085e-05, 3.8566332418961975e-05, -2.3007504344675498e-05, + 6.6491000063301673e-06, -2.8178579922956300e-06, -7.9095918696594176e-18, + 7.3270287126054955e-05, -6.0708847522411039e-05, 3.7405038611583371e-06, + -9.3276007817184013e-05, -2.8745282594779060e-06, 7.7284792487990650e-05, + -4.7618111116928247e-06, 1.4257402535386187e-05, -1.8716955469354936e-06, + -3.9505250537844865e-18, 6.8002926475353674e-05, -5.6225462188821847e-05, + -5.8069646962339915e-06, -8.6570446906970746e-05, 4.9002968245327234e-06, + 7.1577263531495111e-05, 7.3924984553274739e-06, 1.3140222484471143e-05, + -1.1167339315079637e-06, -1.0990652265370899e-17, 3.7749886887707968e-05, + -3.1230076485260194e-05, -1.0834213338389640e-05, -4.8057116773323850e-05, + 9.0542379286307905e-06, 3.9757137205704310e-05, 1.3792387169260654e-05, + 7.3084505808988420e-06, -4.7736440058837683e-07, -1.5484276100280180e-17, + -3.3149552045122865e-06, 2.7320505889780681e-06, -1.2216240033828867e-05, + 4.2200706411434401e-06, 1.0173710041948193e-05, -3.4780097375270807e-06, + 1.5551762461777675e-05, -6.3374425050783931e-07, 3.2586873484871532e-08, + 7.1248334377215630e-18, -4.3958996718323173e-05, 3.6342108184710239e-05, + -1.0755488950499986e-05, 5.5961562078764271e-05, 8.9457858333129674e-06, + -4.6264958144617056e-05, 1.3692167872886584e-05, -8.4914149761200091e-06, + 4.1533005654660920e-07, 2.1226076432594638e-17, -7.5742210399340238e-05, + 6.2625581143322420e-05, -7.2652034204399960e-06, 9.6422865071429752e-05, + 6.0388313855885739e-06, -7.9724871095856144e-05, 9.2488947105202630e-06, + -1.4636620319129859e-05, 6.7044703542218178e-07, 1.4353850908910043e-17, + -9.3040091887932651e-05, 7.6930184467904680e-05, -2.5570471988813422e-06, + 1.1844376047443472e-04, 2.1248537374239493e-06, -9.7935203603904451e-05, + 3.2552234182113150e-06, -1.7981070634123197e-05, 7.9801219628634659e-07, + 1.4947070801485985e-17 }; return sol; } -static const double * -get_sol_3x_bias_p2_NxDx_DyDy(void) +static const double *get_sol_3x_bias_p2_NxDx_DyDy(void) { static const double sol[640] = { - -7.4185325279800725e-04, 2.0456784067503705e-05, -3.9802597843864769e-04, 9.4440888007044066e-04, 1.0964684083799404e-05, -2.6042304806460913e-05, - 5.0670299970892744e-04, 5.0764812236798420e-06, 2.3457263346544559e-05, 1.1444387639127215e-16, -1.8111297630616463e-03, 4.9921555573646745e-05, - -2.2122899042748763e-04, 2.3056406705032361e-03, 6.1001783803440449e-06, -6.3552138125513161e-05, 2.8163335848548543e-04, 1.2783176280256957e-05, - 2.1979419790247300e-05, 1.2089115540443858e-16, -2.2944506126898988e-03, 6.3246271865103235e-05, -6.1638761923246536e-05, 2.9209274547706849e-03, - 1.6996066367289599e-06, -8.0515035224970196e-05, 7.8468610735821001e-05, 1.6147340377878863e-05, 1.9018655925888982e-05, 1.3207856945143187e-16, - -2.2712814698432750e-03, 6.2607182589647211e-05, 6.9283273198993004e-05, 2.8914322086887648e-03, -1.9084463650291406e-06, -7.9701449000710786e-05, - -8.8200379526168931e-05, 1.5993584902368012e-05, 1.4578513220970464e-05, 1.2605949657091669e-16, -1.8607939734753515e-03, 5.1292513034896070e-05, - 1.6006863502989648e-04, 2.3688651979412701e-03, -4.4105638650403004e-06, -6.5297421839985193e-05, -2.0377377840282183e-04, 1.3099218422382167e-05, - 8.6581482607717041e-06, 1.0239515161122573e-16, -1.2218883130103891e-03, 3.3680823229323207e-05, 1.9925006776767170e-04, 1.5555127229134171e-03, - -5.4906542718873810e-06, -4.2877035890733429e-05, -2.5365331033436693e-04, 8.6095141065858618e-06, 1.2579210421273283e-06, 6.3066757853797817e-17, - -5.5318357068322437e-04, 1.5250285570931653e-05, 1.7536157032521370e-04, 7.0422482410400979e-04, -4.8299508614777137e-06, -1.9414223854238400e-05, - -2.2324229706304001e-04, 3.8612474615743837e-06, -7.6230039760317829e-06, 1.7937266001530596e-18, -9.3040091887798182e-05, 2.5570471989134180e-06, - 7.6930184467945161e-05, 1.1844376047445425e-04, -2.1248537373841836e-06, -3.2552234182275937e-06, -9.7935203603889923e-05, 7.9801219626825619e-07, - -1.7981070634123007e-05, -1.0128036117885212e-16, -6.0391518322645214e-04, 5.8133025438251359e-05, -3.2401990289692670e-04, 7.6880819717100853e-04, - 3.1157234702082137e-05, -7.4005667889303007e-05, 4.1249030379150915e-04, 4.2641058537420046e-06, 1.9094342915989936e-05, 5.7972050663881779e-17, - -1.4743782859743769e-03, 1.4186131475814385e-04, -1.8009465973344265e-04, 1.8769425632445367e-03, 1.7335155668334535e-05, -1.8059513103275561e-04, - 2.2926770929982291e-04, 1.0737709998713822e-05, 1.7891815716327078e-05, 1.1195061398383187e-16, -1.8678324615434192e-03, 1.7972636255984167e-04, - -5.0177806705345845e-05, 2.3778254749349014e-03, 4.8298278531591253e-06, -2.2879885225845310e-04, 6.3878356071482792e-05, 1.3563696440508467e-05, - 1.5481586715523658e-05, 1.2519746461652156e-16, -1.8489709303060073e-03, 1.7791020436131827e-04, 5.6401394648710322e-05, 2.3538139908237995e-03, - -5.4230258469329165e-06, -2.2648681018836580e-04, -7.1801232593808891e-05, 1.3434536925262129e-05, 1.1867224005867195e-05, 1.1843790739414284e-16, - -1.5148068254141455e-03, 1.4575747047953139e-04, 1.3030661548298953e-04, 1.9284097119174970e-03, -1.2533216551743824e-05, -1.8555509319178703e-04, - -1.6588553643187407e-04, 1.1003322845518524e-05, 7.0478959388723687e-06, 9.8852723025181421e-17, -9.9469578895185944e-04, 9.5710452873520142e-05, - 1.6220276314314437e-04, 1.2662875474526525e-03, -1.5602511542291162e-05, -1.2184323687799192e-04, -2.0649060889963542e-04, 7.2319800498275634e-06, - 1.0239596690629926e-06, 6.8625507719155729e-17, -4.5032633391014229e-04, 4.3336922314407004e-05, 1.4275601491743747e-04, 5.7328344530472913e-04, - -1.3724632897102337e-05, -5.5169636466954247e-05, -1.8173412014179445e-04, 3.2435488692356264e-06, -6.2054078588162292e-06, 2.9730292178322782e-17, - -7.5742210399298401e-05, 7.2652034204017456e-06, 6.2625581143333262e-05, 9.6422865071383131e-05, -6.0388313856066335e-06, -9.2488947105253537e-06, - -7.9724871095872353e-05, 6.7044703544074461e-07, -1.4636620319128287e-05, -2.7309579880584324e-17, -3.5046776690446905e-04, 8.6097341540724331e-05, - -1.8804143086101184e-04, 4.4615949312715598e-04, 4.6138941825169657e-05, -1.0960536143110376e-04, 2.3938426697808543e-04, 2.6393373956046143e-06, - 1.1077684120010877e-05, 6.7512769569450989e-17, -8.5563118982642501e-04, 2.1009107982625130e-04, -1.0451452877112072e-04, 1.0892527473457733e-03, - 2.5673892807441163e-05, -2.6745435254661563e-04, 1.3305117783822521e-04, 6.6467490018670767e-06, 1.0380762902208861e-05, 1.2439980280761793e-16, - -1.0839644414274159e-03, 2.6616909306344830e-04, -2.9119379734350206e-05, 1.3799301146204899e-03, 7.1531646979159201e-06, -3.3884390766165056e-04, - 3.7070135770882529e-05, 8.3963955227112072e-06, 8.9821168968255152e-06, 1.1281238326745632e-16, -1.0730176634536760e-03, 2.6347918201769812e-04, - 3.2732351109899887e-05, 1.3659944281656090e-03, -8.0305360855985600e-06, -3.3541954324910591e-04, -4.1669592924462712e-05, 8.3164350440211320e-06, - 6.8851645536151122e-06, 1.0152614645118684e-16, -8.7908999816593467e-04, 2.1586222088962838e-04, 7.5622040169425608e-05, 1.1191167491928647e-03, - -1.8560279471199128e-05, -2.7480124608354468e-04, -9.6269883559479470e-05, 6.8115232787051463e-06, 4.0890266760257836e-06, 8.8210735506913166e-17, - -5.7725205425153165e-04, 1.4174402118254949e-04, 9.4132221087060022e-05, 7.3486496691654532e-04, -2.3105816616276570e-05, -1.8044581161690717e-04, - -1.1983408465235718e-04, 4.4769112358833051e-06, 5.9407987857323031e-07, 7.2862062998879852e-17, -2.6133624469449972e-04, 6.4181688197260221e-05, - 8.2846618815276906e-05, 3.3269149827542507e-04, -2.0323581324049829e-05, -8.1705857651543105e-05, -1.0546706130613814e-04, 2.0081691410600528e-06, - -3.6005452741349643e-06, 6.1693126814669362e-17, -4.3958996718367131e-05, 1.0755488950523258e-05, 3.6342108184685594e-05, 5.5961562078727293e-05, - -8.9457858332897807e-06, -1.3692167872848242e-05, -4.6264958144620241e-05, 4.1533005659194891e-07, -8.4914149761237141e-06, 8.2812149854959705e-17, - -2.6369173463935267e-05, 9.7874810518100015e-05, -1.4156115092418241e-05, 3.3569013123087527e-05, 5.2437299075712193e-05, -1.2459855077796993e-04, - 1.8021301046369524e-05, 2.0225634453753787e-07, 8.2737327431625208e-07, 2.8177397077573526e-16, -6.4401076442197511e-05, 2.3880385491959882e-04, - -7.8652359084217054e-06, 8.1985147666929623e-05, 2.9185828660984950e-05, -3.0400686433693097e-04, 1.0012760081337085e-05, 5.1040642097596895e-07, - 7.7809221148224797e-07, 1.2817421272705128e-16, -8.1583353672124066e-05, 3.0254949112893249e-04, -2.1908826904486396e-06, 1.0385887422229175e-04, - 8.1313422416425124e-06, -3.8515761035684960e-04, 2.7890813449622491e-06, 6.4546625765873201e-07, 6.7280421817243716e-07, 9.2197833111684565e-17, - -8.0757424528256949e-05, 2.9949136733266134e-04, 2.4649783637441816e-06, 1.0280743336822311e-04, -9.1266848261750555e-06, -3.8126449637687881e-04, - -3.1380161064341044e-06, 6.3927833037391234e-07, 5.1575107170366369e-07, 7.5874538131131677e-17, -6.6158684055516007e-05, 2.4536651900581257e-04, - 5.6930861126352351e-06, 8.4222652499130987e-05, -2.1095228673489812e-05, -3.1236139835906734e-04, -7.2475264609201958e-06, 5.2383308233429554e-07, - 3.0620542597919858e-07, 6.8193629092451981e-17, -4.3439872336668323e-05, 1.6111739776338878e-04, 7.0856641229971160e-06, 5.5300695965283921e-05, - -2.6262233432286572e-05, -2.0510889533447113e-04, -9.0203339996343701e-06, 3.4429239733307118e-07, 4.4421321296388115e-08, 6.6096051000889153e-17, - -1.9661496835318848e-05, 7.2956872225944395e-05, 6.2364545034732409e-06, 2.5029872332157129e-05, -2.3096613004447269e-05, -9.2877018106369294e-05, - -7.9392561682712807e-06, 1.5500833779624817e-07, -2.7032276650636750e-07, 7.6653401639516628e-17, -3.3149552044579930e-06, 1.2216240033808677e-05, - 2.7320505890367992e-06, 4.2200706410946925e-06, -1.0173710041956921e-05, -1.5551762461784462e-05, -3.4780097375448968e-06, 3.2586873488663109e-08, - -6.3374425049983369e-07, 1.1208704012626897e-16, 3.0109676195024578e-04, 8.6992163559396031e-05, 1.6152938865388649e-04, -3.8330822797395835e-04, - 4.6572459248561327e-05, -1.1074450567149586e-04, -2.0563337622614048e-04, -3.0476196626152295e-06, -9.5344390692388496e-06, 1.9092368042348901e-16, - 7.3504616021194998e-04, 2.1219385883252588e-04, 8.9786913323488897e-05, -9.3574317878677841e-04, 2.5939534318833506e-05, -2.7013127437548854e-04, - -1.1430233396836451e-04, -7.6719397877112796e-06, -8.9337392931369159e-06, 9.5643625673969897e-17, 9.3120558827590547e-04, 2.6884245930155592e-04, - 2.5018632896854560e-05, -1.1854619810895955e-03, 7.2279537638824679e-06, -3.4224720987189417e-04, -3.1849720933210353e-05, -9.6892163186664671e-06, - -7.7309086961064527e-06, 5.6028473148456790e-17, 9.2180607376450964e-04, 2.6612401553145846e-04, -2.8115105526505151e-05, -1.1734960229442622e-03, - -8.1052313173919847e-06, -3.3878652215938403e-04, 3.5791654512842331e-05, -9.5969568198564807e-06, -5.9258354008360331e-06, 4.5038336270219261e-17, - 7.5521454677789578e-04, 2.1803021136886734e-04, -6.4959947881067839e-05, -9.6141834203178659e-04, -1.8739033755342080e-05, -2.7756118472743892e-04, - 8.2696613375290293e-05, -7.8598788404716561e-06, -3.5194659963033452e-06, 4.4233911651540140e-17, 4.9591678847464625e-04, 1.4316667347179192e-04, - -8.0861991798903798e-05, -6.3132191851337973e-04, -2.3329868400283943e-05, -1.8225690491621515e-04, 1.0294055168874891e-04, -5.1659110589369388e-06, - -5.1117197886668249e-07, 4.9241705811745897e-17, 2.2452284971679964e-04, 6.4833668634040463e-05, -7.1167813182507325e-05, -2.8582657318238186e-04, - -2.0511575929733324e-05, -8.2535854840072923e-05, 9.0599474345226703e-05, -2.3154572454575781e-06, 3.0981066058919801e-06, 6.5702071410912399e-17, - 3.7749886887585332e-05, 1.0834213338346070e-05, -3.1230076485287651e-05, -4.8057116773306991e-05, -9.0542379286509143e-06, -1.3792387169287603e-05, - 3.9757137205718499e-05, -4.7736440055484852e-07, 7.3084505808939707e-06, 1.0203989573196756e-16, 5.4219548657402584e-04, 4.6964511263801802e-05, - 2.9091105641275715e-04, -6.9023655328555940e-04, 2.5099762187725797e-05, -5.9787702377005517e-05, -3.7034141718845218e-04, -7.1078530313566328e-06, - -1.7138457671768140e-05, 1.9161885033206326e-18, 1.3236741350855599e-03, 1.1444951102741669e-04, 1.6169038423836617e-04, -1.6850901479239001e-03, - 1.4004905074152640e-05, -1.4569880785233498e-04, -2.0583833004826857e-04, -1.7897506519471960e-05, -1.6042765456802161e-05, 1.4300776630829959e-17, - 1.6769291755919155e-03, 1.4502400361685275e-04, 4.5047880146265376e-05, -2.1347979518942612e-03, 3.8980585320075360e-06, -1.8462136052192925e-04, - -5.7347754260088115e-05, -2.2607359364032996e-05, -1.3884451253031794e-05, 1.5312228686440909e-17, 1.6599996084286732e-03, 1.4355365040744238e-04, - -5.0637183330136170e-05, -2.1132459353675054e-03, -4.3684028831049219e-06, -1.8274954204225104e-04, 6.4463160899273976e-05, -2.2392186132941893e-05, - -1.0642774281307195e-05, 1.6238941250461819e-17, 1.3599971624203883e-03, 1.1761250922650970e-04, -1.1698967736129490e-04, -1.7313308153829791e-03, - -1.0103627331035387e-05, -1.4972543114425037e-04, 1.4893254125386701e-04, -1.8339153449490943e-05, -6.3208097101488461e-06, 1.9476238450815159e-17, - 8.9304807164369880e-04, 7.7225405099946121e-05, -1.4562879398959312e-04, -1.1368859353378387e-03, -1.2582857886101920e-05, -9.8311031283335407e-05, - 1.8539128287040863e-04, -1.2053450101605257e-05, -9.1822109815714625e-07, 2.5781257654841598e-17, 4.0432786569244986e-04, 3.4987563703455363e-05, - -1.2816820392757135e-04, -5.1472555438690146e-04, -1.1047540869096394e-05, -4.4540568810559333e-05, 1.6316325294176082e-04, -5.4055108406509953e-06, - 5.5618567638278036e-06, 3.8946897289047353e-17, 6.8002926475210410e-05, 5.8069646962579202e-06, -5.6225462188851432e-05, -8.6570446906967778e-05, - -4.9002968245208387e-06, -7.3924984553276374e-06, 7.1577263531497699e-05, -1.1167339314804364e-06, 1.3140222484467003e-05, 6.6267225159319282e-17, - 5.8489869202466081e-04, -2.8617271619844676e-05, 3.1367048785920317e-04, -7.4459944282312168e-04, -1.5601216385088299e-05, 3.6430932046641732e-05, - -3.9931508426116090e-04, -1.1993596362323995e-05, -1.8606531928345532e-05, -1.6210055668937958e-16, 1.4277325347644965e-03, -7.0228009414114608e-05, - 1.7441241606388127e-04, -1.8175606551731254e-03, -8.5314378018309973e-06, 8.9403066536796741e-05, -2.2203398570289293e-04, -3.0180009723339873e-05, - -1.7465893456541061e-05, -4.3318933013182567e-17, 1.8087408305902700e-03, -8.8933756155081838e-05, 4.8609262873974651e-05, -2.3025994638613892e-03, - -2.3689535246149096e-06, 1.1321623074936765e-04, -6.1881537000414255e-05, -3.8108004663828739e-05, -1.5106133674190260e-05, -1.2329061675074945e-17, - 1.7904898493183250e-03, -8.8038739116152721e-05, -5.4594815714690414e-05, -2.2793652342907728e-03, 2.7188239063321850e-06, 1.1207683823987290e-04, - 6.9501385310799283e-05, -3.7747530559389502e-05, -1.1580436012148740e-05, -4.7213831098352963e-18, 1.4669018971550354e-03, -7.2126947445435468e-05, - -1.2615623684791142e-04, -1.8674248210697169e-03, 6.2473383435735753e-06, 9.1820490646871939e-05, 1.6060193832964490e-04, -3.0915439591943777e-05, - -6.8766677416190290e-06, 2.3884772252174143e-18, 9.6325796444311643e-04, -4.7364249466621374e-05, -1.5703540377680101e-04, -1.2262659386990189e-03, - 7.7720809383160633e-06, 6.0296585106922731e-05, 1.9991235362653838e-04, -2.0321917006824412e-05, -9.9955532671635744e-07, 8.8559730946373446e-18, - 4.3610842151558675e-04, -2.1413925090714942e-05, -1.3819686293535334e-04, -5.5518347382007356e-04, 6.8888362637715224e-06, 2.7260783634202982e-05, - 1.7593013720955538e-04, -9.1041122183867737e-06, 6.0629566842156548e-06, 1.5573035261013121e-17, 7.3270287126041931e-05, -3.7405038611519128e-06, - -6.0708847522380898e-05, -9.3276007817195505e-05, 2.8745282594694069e-06, 4.7618111116912238e-06, 7.7284792487987154e-05, -1.8716955469427051e-06, - 1.4257402535389059e-05, 8.5076182105527532e-18, 2.9366410440316701e-04, -1.4679523967258041e-04, 1.5833417110366465e-04, -3.7384615745768692e-04, - -7.8278512648504361e-05, 1.8687621490632084e-04, -2.0156573641119286e-04, -1.7623476288564741e-05, -8.6854584349435904e-06, -1.2727645769649134e-16, - 7.1871323474263348e-04, -3.5755576442369596e-04, 8.7710214994732844e-05, -9.1495071101393652e-04, -4.3774882151098579e-05, 4.5518279763370506e-04, - -1.1165861388559535e-04, -4.4456825652019548e-05, -8.1880463208024440e-06, -1.3893386733482794e-17, 9.1041892369559275e-04, -4.5307301340345680e-04, - 2.4407192087609418e-05, -1.1589997251879149e-03, -1.2201146101918565e-05, 5.7678007822305362e-04, -3.1071332312990467e-05, -5.6202873171461935e-05, - -7.0756666652780254e-06, -3.2435527423937891e-17, 9.0124227629166816e-04, -4.4848460248175293e-04, -2.7574015762470031e-05, -1.1473174857899882e-03, - 1.3619750416026979e-05, 5.7093884748954675e-04, 3.5102825588581247e-05, -5.5653119508575166e-05, -5.4247562557556097e-06, -7.4236581082921709e-18, - 7.3835886561779212e-04, -3.6743879842918988e-04, -6.3621467426429139e-05, -9.3996038534390695e-04, 3.1529332913748146e-05, 4.6776429544570465e-04, - 8.0992674190014512e-05, -4.5587253648867070e-05, -3.2207980489842500e-06, 3.0495007042036106e-18, 4.8485609369284887e-04, -2.4126875678009098e-04, - -7.9184942178625679e-05, -6.1724121140272674e-04, 3.9263369648520594e-05, 3.0714478305167810e-04, 1.0080560040594569e-04, -2.9948261566550803e-05, - -4.6828117363520094e-07, 2.1116594102843436e-18, 2.1943348004293224e-04, -1.0931001556628331e-04, -6.9776478809210180e-05, -2.7934760190890894e-04, - 3.4451757069420533e-05, 1.3915602444573510e-04, 8.8828250006272802e-05, -1.3462461610690233e-05, 2.8472996610841432e-06, 2.7189423663698649e-18, - 3.7604074979956313e-05, -1.8072883786921466e-05, -3.0294674009569994e-05, -4.7871492379370643e-05, 1.5390330853863688e-05, 2.3007504344676501e-05, - 3.8566332418963669e-05, -2.8178579922984523e-06, 6.6491000063332310e-06, 9.1249273016952658e-19, + -7.4185325279800725e-04, 2.0456784067503705e-05, -3.9802597843864769e-04, + 9.4440888007044066e-04, 1.0964684083799404e-05, -2.6042304806460913e-05, + 5.0670299970892744e-04, 5.0764812236798420e-06, 2.3457263346544559e-05, + 1.1444387639127215e-16, -1.8111297630616463e-03, 4.9921555573646745e-05, + -2.2122899042748763e-04, 2.3056406705032361e-03, 6.1001783803440449e-06, + -6.3552138125513161e-05, 2.8163335848548543e-04, 1.2783176280256957e-05, + 2.1979419790247300e-05, 1.2089115540443858e-16, -2.2944506126898988e-03, + 6.3246271865103235e-05, -6.1638761923246536e-05, 2.9209274547706849e-03, + 1.6996066367289599e-06, -8.0515035224970196e-05, 7.8468610735821001e-05, + 1.6147340377878863e-05, 1.9018655925888982e-05, 1.3207856945143187e-16, + -2.2712814698432750e-03, 6.2607182589647211e-05, 6.9283273198993004e-05, + 2.8914322086887648e-03, -1.9084463650291406e-06, -7.9701449000710786e-05, + -8.8200379526168931e-05, 1.5993584902368012e-05, 1.4578513220970464e-05, + 1.2605949657091669e-16, -1.8607939734753515e-03, 5.1292513034896070e-05, + 1.6006863502989648e-04, 2.3688651979412701e-03, -4.4105638650403004e-06, + -6.5297421839985193e-05, -2.0377377840282183e-04, 1.3099218422382167e-05, + 8.6581482607717041e-06, 1.0239515161122573e-16, -1.2218883130103891e-03, + 3.3680823229323207e-05, 1.9925006776767170e-04, 1.5555127229134171e-03, + -5.4906542718873810e-06, -4.2877035890733429e-05, -2.5365331033436693e-04, + 8.6095141065858618e-06, 1.2579210421273283e-06, 6.3066757853797817e-17, + -5.5318357068322437e-04, 1.5250285570931653e-05, 1.7536157032521370e-04, + 7.0422482410400979e-04, -4.8299508614777137e-06, -1.9414223854238400e-05, + -2.2324229706304001e-04, 3.8612474615743837e-06, -7.6230039760317829e-06, + 1.7937266001530596e-18, -9.3040091887798182e-05, 2.5570471989134180e-06, + 7.6930184467945161e-05, 1.1844376047445425e-04, -2.1248537373841836e-06, + -3.2552234182275937e-06, -9.7935203603889923e-05, 7.9801219626825619e-07, + -1.7981070634123007e-05, -1.0128036117885212e-16, -6.0391518322645214e-04, + 5.8133025438251359e-05, -3.2401990289692670e-04, 7.6880819717100853e-04, + 3.1157234702082137e-05, -7.4005667889303007e-05, 4.1249030379150915e-04, + 4.2641058537420046e-06, 1.9094342915989936e-05, 5.7972050663881779e-17, + -1.4743782859743769e-03, 1.4186131475814385e-04, -1.8009465973344265e-04, + 1.8769425632445367e-03, 1.7335155668334535e-05, -1.8059513103275561e-04, + 2.2926770929982291e-04, 1.0737709998713822e-05, 1.7891815716327078e-05, + 1.1195061398383187e-16, -1.8678324615434192e-03, 1.7972636255984167e-04, + -5.0177806705345845e-05, 2.3778254749349014e-03, 4.8298278531591253e-06, + -2.2879885225845310e-04, 6.3878356071482792e-05, 1.3563696440508467e-05, + 1.5481586715523658e-05, 1.2519746461652156e-16, -1.8489709303060073e-03, + 1.7791020436131827e-04, 5.6401394648710322e-05, 2.3538139908237995e-03, + -5.4230258469329165e-06, -2.2648681018836580e-04, -7.1801232593808891e-05, + 1.3434536925262129e-05, 1.1867224005867195e-05, 1.1843790739414284e-16, + -1.5148068254141455e-03, 1.4575747047953139e-04, 1.3030661548298953e-04, + 1.9284097119174970e-03, -1.2533216551743824e-05, -1.8555509319178703e-04, + -1.6588553643187407e-04, 1.1003322845518524e-05, 7.0478959388723687e-06, + 9.8852723025181421e-17, -9.9469578895185944e-04, 9.5710452873520142e-05, + 1.6220276314314437e-04, 1.2662875474526525e-03, -1.5602511542291162e-05, + -1.2184323687799192e-04, -2.0649060889963542e-04, 7.2319800498275634e-06, + 1.0239596690629926e-06, 6.8625507719155729e-17, -4.5032633391014229e-04, + 4.3336922314407004e-05, 1.4275601491743747e-04, 5.7328344530472913e-04, + -1.3724632897102337e-05, -5.5169636466954247e-05, -1.8173412014179445e-04, + 3.2435488692356264e-06, -6.2054078588162292e-06, 2.9730292178322782e-17, + -7.5742210399298401e-05, 7.2652034204017456e-06, 6.2625581143333262e-05, + 9.6422865071383131e-05, -6.0388313856066335e-06, -9.2488947105253537e-06, + -7.9724871095872353e-05, 6.7044703544074461e-07, -1.4636620319128287e-05, + -2.7309579880584324e-17, -3.5046776690446905e-04, 8.6097341540724331e-05, + -1.8804143086101184e-04, 4.4615949312715598e-04, 4.6138941825169657e-05, + -1.0960536143110376e-04, 2.3938426697808543e-04, 2.6393373956046143e-06, + 1.1077684120010877e-05, 6.7512769569450989e-17, -8.5563118982642501e-04, + 2.1009107982625130e-04, -1.0451452877112072e-04, 1.0892527473457733e-03, + 2.5673892807441163e-05, -2.6745435254661563e-04, 1.3305117783822521e-04, + 6.6467490018670767e-06, 1.0380762902208861e-05, 1.2439980280761793e-16, + -1.0839644414274159e-03, 2.6616909306344830e-04, -2.9119379734350206e-05, + 1.3799301146204899e-03, 7.1531646979159201e-06, -3.3884390766165056e-04, + 3.7070135770882529e-05, 8.3963955227112072e-06, 8.9821168968255152e-06, + 1.1281238326745632e-16, -1.0730176634536760e-03, 2.6347918201769812e-04, + 3.2732351109899887e-05, 1.3659944281656090e-03, -8.0305360855985600e-06, + -3.3541954324910591e-04, -4.1669592924462712e-05, 8.3164350440211320e-06, + 6.8851645536151122e-06, 1.0152614645118684e-16, -8.7908999816593467e-04, + 2.1586222088962838e-04, 7.5622040169425608e-05, 1.1191167491928647e-03, + -1.8560279471199128e-05, -2.7480124608354468e-04, -9.6269883559479470e-05, + 6.8115232787051463e-06, 4.0890266760257836e-06, 8.8210735506913166e-17, + -5.7725205425153165e-04, 1.4174402118254949e-04, 9.4132221087060022e-05, + 7.3486496691654532e-04, -2.3105816616276570e-05, -1.8044581161690717e-04, + -1.1983408465235718e-04, 4.4769112358833051e-06, 5.9407987857323031e-07, + 7.2862062998879852e-17, -2.6133624469449972e-04, 6.4181688197260221e-05, + 8.2846618815276906e-05, 3.3269149827542507e-04, -2.0323581324049829e-05, + -8.1705857651543105e-05, -1.0546706130613814e-04, 2.0081691410600528e-06, + -3.6005452741349643e-06, 6.1693126814669362e-17, -4.3958996718367131e-05, + 1.0755488950523258e-05, 3.6342108184685594e-05, 5.5961562078727293e-05, + -8.9457858332897807e-06, -1.3692167872848242e-05, -4.6264958144620241e-05, + 4.1533005659194891e-07, -8.4914149761237141e-06, 8.2812149854959705e-17, + -2.6369173463935267e-05, 9.7874810518100015e-05, -1.4156115092418241e-05, + 3.3569013123087527e-05, 5.2437299075712193e-05, -1.2459855077796993e-04, + 1.8021301046369524e-05, 2.0225634453753787e-07, 8.2737327431625208e-07, + 2.8177397077573526e-16, -6.4401076442197511e-05, 2.3880385491959882e-04, + -7.8652359084217054e-06, 8.1985147666929623e-05, 2.9185828660984950e-05, + -3.0400686433693097e-04, 1.0012760081337085e-05, 5.1040642097596895e-07, + 7.7809221148224797e-07, 1.2817421272705128e-16, -8.1583353672124066e-05, + 3.0254949112893249e-04, -2.1908826904486396e-06, 1.0385887422229175e-04, + 8.1313422416425124e-06, -3.8515761035684960e-04, 2.7890813449622491e-06, + 6.4546625765873201e-07, 6.7280421817243716e-07, 9.2197833111684565e-17, + -8.0757424528256949e-05, 2.9949136733266134e-04, 2.4649783637441816e-06, + 1.0280743336822311e-04, -9.1266848261750555e-06, -3.8126449637687881e-04, + -3.1380161064341044e-06, 6.3927833037391234e-07, 5.1575107170366369e-07, + 7.5874538131131677e-17, -6.6158684055516007e-05, 2.4536651900581257e-04, + 5.6930861126352351e-06, 8.4222652499130987e-05, -2.1095228673489812e-05, + -3.1236139835906734e-04, -7.2475264609201958e-06, 5.2383308233429554e-07, + 3.0620542597919858e-07, 6.8193629092451981e-17, -4.3439872336668323e-05, + 1.6111739776338878e-04, 7.0856641229971160e-06, 5.5300695965283921e-05, + -2.6262233432286572e-05, -2.0510889533447113e-04, -9.0203339996343701e-06, + 3.4429239733307118e-07, 4.4421321296388115e-08, 6.6096051000889153e-17, + -1.9661496835318848e-05, 7.2956872225944395e-05, 6.2364545034732409e-06, + 2.5029872332157129e-05, -2.3096613004447269e-05, -9.2877018106369294e-05, + -7.9392561682712807e-06, 1.5500833779624817e-07, -2.7032276650636750e-07, + 7.6653401639516628e-17, -3.3149552044579930e-06, 1.2216240033808677e-05, + 2.7320505890367992e-06, 4.2200706410946925e-06, -1.0173710041956921e-05, + -1.5551762461784462e-05, -3.4780097375448968e-06, 3.2586873488663109e-08, + -6.3374425049983369e-07, 1.1208704012626897e-16, 3.0109676195024578e-04, + 8.6992163559396031e-05, 1.6152938865388649e-04, -3.8330822797395835e-04, + 4.6572459248561327e-05, -1.1074450567149586e-04, -2.0563337622614048e-04, + -3.0476196626152295e-06, -9.5344390692388496e-06, 1.9092368042348901e-16, + 7.3504616021194998e-04, 2.1219385883252588e-04, 8.9786913323488897e-05, + -9.3574317878677841e-04, 2.5939534318833506e-05, -2.7013127437548854e-04, + -1.1430233396836451e-04, -7.6719397877112796e-06, -8.9337392931369159e-06, + 9.5643625673969897e-17, 9.3120558827590547e-04, 2.6884245930155592e-04, + 2.5018632896854560e-05, -1.1854619810895955e-03, 7.2279537638824679e-06, + -3.4224720987189417e-04, -3.1849720933210353e-05, -9.6892163186664671e-06, + -7.7309086961064527e-06, 5.6028473148456790e-17, 9.2180607376450964e-04, + 2.6612401553145846e-04, -2.8115105526505151e-05, -1.1734960229442622e-03, + -8.1052313173919847e-06, -3.3878652215938403e-04, 3.5791654512842331e-05, + -9.5969568198564807e-06, -5.9258354008360331e-06, 4.5038336270219261e-17, + 7.5521454677789578e-04, 2.1803021136886734e-04, -6.4959947881067839e-05, + -9.6141834203178659e-04, -1.8739033755342080e-05, -2.7756118472743892e-04, + 8.2696613375290293e-05, -7.8598788404716561e-06, -3.5194659963033452e-06, + 4.4233911651540140e-17, 4.9591678847464625e-04, 1.4316667347179192e-04, + -8.0861991798903798e-05, -6.3132191851337973e-04, -2.3329868400283943e-05, + -1.8225690491621515e-04, 1.0294055168874891e-04, -5.1659110589369388e-06, + -5.1117197886668249e-07, 4.9241705811745897e-17, 2.2452284971679964e-04, + 6.4833668634040463e-05, -7.1167813182507325e-05, -2.8582657318238186e-04, + -2.0511575929733324e-05, -8.2535854840072923e-05, 9.0599474345226703e-05, + -2.3154572454575781e-06, 3.0981066058919801e-06, 6.5702071410912399e-17, + 3.7749886887585332e-05, 1.0834213338346070e-05, -3.1230076485287651e-05, + -4.8057116773306991e-05, -9.0542379286509143e-06, -1.3792387169287603e-05, + 3.9757137205718499e-05, -4.7736440055484852e-07, 7.3084505808939707e-06, + 1.0203989573196756e-16, 5.4219548657402584e-04, 4.6964511263801802e-05, + 2.9091105641275715e-04, -6.9023655328555940e-04, 2.5099762187725797e-05, + -5.9787702377005517e-05, -3.7034141718845218e-04, -7.1078530313566328e-06, + -1.7138457671768140e-05, 1.9161885033206326e-18, 1.3236741350855599e-03, + 1.1444951102741669e-04, 1.6169038423836617e-04, -1.6850901479239001e-03, + 1.4004905074152640e-05, -1.4569880785233498e-04, -2.0583833004826857e-04, + -1.7897506519471960e-05, -1.6042765456802161e-05, 1.4300776630829959e-17, + 1.6769291755919155e-03, 1.4502400361685275e-04, 4.5047880146265376e-05, + -2.1347979518942612e-03, 3.8980585320075360e-06, -1.8462136052192925e-04, + -5.7347754260088115e-05, -2.2607359364032996e-05, -1.3884451253031794e-05, + 1.5312228686440909e-17, 1.6599996084286732e-03, 1.4355365040744238e-04, + -5.0637183330136170e-05, -2.1132459353675054e-03, -4.3684028831049219e-06, + -1.8274954204225104e-04, 6.4463160899273976e-05, -2.2392186132941893e-05, + -1.0642774281307195e-05, 1.6238941250461819e-17, 1.3599971624203883e-03, + 1.1761250922650970e-04, -1.1698967736129490e-04, -1.7313308153829791e-03, + -1.0103627331035387e-05, -1.4972543114425037e-04, 1.4893254125386701e-04, + -1.8339153449490943e-05, -6.3208097101488461e-06, 1.9476238450815159e-17, + 8.9304807164369880e-04, 7.7225405099946121e-05, -1.4562879398959312e-04, + -1.1368859353378387e-03, -1.2582857886101920e-05, -9.8311031283335407e-05, + 1.8539128287040863e-04, -1.2053450101605257e-05, -9.1822109815714625e-07, + 2.5781257654841598e-17, 4.0432786569244986e-04, 3.4987563703455363e-05, + -1.2816820392757135e-04, -5.1472555438690146e-04, -1.1047540869096394e-05, + -4.4540568810559333e-05, 1.6316325294176082e-04, -5.4055108406509953e-06, + 5.5618567638278036e-06, 3.8946897289047353e-17, 6.8002926475210410e-05, + 5.8069646962579202e-06, -5.6225462188851432e-05, -8.6570446906967778e-05, + -4.9002968245208387e-06, -7.3924984553276374e-06, 7.1577263531497699e-05, + -1.1167339314804364e-06, 1.3140222484467003e-05, 6.6267225159319282e-17, + 5.8489869202466081e-04, -2.8617271619844676e-05, 3.1367048785920317e-04, + -7.4459944282312168e-04, -1.5601216385088299e-05, 3.6430932046641732e-05, + -3.9931508426116090e-04, -1.1993596362323995e-05, -1.8606531928345532e-05, + -1.6210055668937958e-16, 1.4277325347644965e-03, -7.0228009414114608e-05, + 1.7441241606388127e-04, -1.8175606551731254e-03, -8.5314378018309973e-06, + 8.9403066536796741e-05, -2.2203398570289293e-04, -3.0180009723339873e-05, + -1.7465893456541061e-05, -4.3318933013182567e-17, 1.8087408305902700e-03, + -8.8933756155081838e-05, 4.8609262873974651e-05, -2.3025994638613892e-03, + -2.3689535246149096e-06, 1.1321623074936765e-04, -6.1881537000414255e-05, + -3.8108004663828739e-05, -1.5106133674190260e-05, -1.2329061675074945e-17, + 1.7904898493183250e-03, -8.8038739116152721e-05, -5.4594815714690414e-05, + -2.2793652342907728e-03, 2.7188239063321850e-06, 1.1207683823987290e-04, + 6.9501385310799283e-05, -3.7747530559389502e-05, -1.1580436012148740e-05, + -4.7213831098352963e-18, 1.4669018971550354e-03, -7.2126947445435468e-05, + -1.2615623684791142e-04, -1.8674248210697169e-03, 6.2473383435735753e-06, + 9.1820490646871939e-05, 1.6060193832964490e-04, -3.0915439591943777e-05, + -6.8766677416190290e-06, 2.3884772252174143e-18, 9.6325796444311643e-04, + -4.7364249466621374e-05, -1.5703540377680101e-04, -1.2262659386990189e-03, + 7.7720809383160633e-06, 6.0296585106922731e-05, 1.9991235362653838e-04, + -2.0321917006824412e-05, -9.9955532671635744e-07, 8.8559730946373446e-18, + 4.3610842151558675e-04, -2.1413925090714942e-05, -1.3819686293535334e-04, + -5.5518347382007356e-04, 6.8888362637715224e-06, 2.7260783634202982e-05, + 1.7593013720955538e-04, -9.1041122183867737e-06, 6.0629566842156548e-06, + 1.5573035261013121e-17, 7.3270287126041931e-05, -3.7405038611519128e-06, + -6.0708847522380898e-05, -9.3276007817195505e-05, 2.8745282594694069e-06, + 4.7618111116912238e-06, 7.7284792487987154e-05, -1.8716955469427051e-06, + 1.4257402535389059e-05, 8.5076182105527532e-18, 2.9366410440316701e-04, + -1.4679523967258041e-04, 1.5833417110366465e-04, -3.7384615745768692e-04, + -7.8278512648504361e-05, 1.8687621490632084e-04, -2.0156573641119286e-04, + -1.7623476288564741e-05, -8.6854584349435904e-06, -1.2727645769649134e-16, + 7.1871323474263348e-04, -3.5755576442369596e-04, 8.7710214994732844e-05, + -9.1495071101393652e-04, -4.3774882151098579e-05, 4.5518279763370506e-04, + -1.1165861388559535e-04, -4.4456825652019548e-05, -8.1880463208024440e-06, + -1.3893386733482794e-17, 9.1041892369559275e-04, -4.5307301340345680e-04, + 2.4407192087609418e-05, -1.1589997251879149e-03, -1.2201146101918565e-05, + 5.7678007822305362e-04, -3.1071332312990467e-05, -5.6202873171461935e-05, + -7.0756666652780254e-06, -3.2435527423937891e-17, 9.0124227629166816e-04, + -4.4848460248175293e-04, -2.7574015762470031e-05, -1.1473174857899882e-03, + 1.3619750416026979e-05, 5.7093884748954675e-04, 3.5102825588581247e-05, + -5.5653119508575166e-05, -5.4247562557556097e-06, -7.4236581082921709e-18, + 7.3835886561779212e-04, -3.6743879842918988e-04, -6.3621467426429139e-05, + -9.3996038534390695e-04, 3.1529332913748146e-05, 4.6776429544570465e-04, + 8.0992674190014512e-05, -4.5587253648867070e-05, -3.2207980489842500e-06, + 3.0495007042036106e-18, 4.8485609369284887e-04, -2.4126875678009098e-04, + -7.9184942178625679e-05, -6.1724121140272674e-04, 3.9263369648520594e-05, + 3.0714478305167810e-04, 1.0080560040594569e-04, -2.9948261566550803e-05, + -4.6828117363520094e-07, 2.1116594102843436e-18, 2.1943348004293224e-04, + -1.0931001556628331e-04, -6.9776478809210180e-05, -2.7934760190890894e-04, + 3.4451757069420533e-05, 1.3915602444573510e-04, 8.8828250006272802e-05, + -1.3462461610690233e-05, 2.8472996610841432e-06, 2.7189423663698649e-18, + 3.7604074979956313e-05, -1.8072883786921466e-05, -3.0294674009569994e-05, + -4.7871492379370643e-05, 1.5390330853863688e-05, 2.3007504344676501e-05, + 3.8566332418963669e-05, -2.8178579922984523e-06, 6.6491000063332310e-06, + 9.1249273016952658e-19 }; return sol; } -static const double * -get_sol_3x_bias_p2_DxNx_DyDy(void) +static const double *get_sol_3x_bias_p2_DxNx_DyDy(void) { static const double sol[640] = { - 2.9366410440283302e-04, 1.4679523967220964e-04, 1.5833417110396145e-04, -3.7384615745763466e-04, 7.8278512648638829e-05, -1.8687621490641275e-04, - -2.0156573641115063e-04, -1.7623476288484310e-05, -8.6854584350381429e-06, 2.9951311795116681e-17, 7.1871323474270667e-04, 3.5755576442359968e-04, - 8.7710214994801027e-05, -9.1495071101377866e-04, 4.3774882151080975e-05, -4.5518279763380145e-04, -1.1165861388558839e-04, -4.4456825652005657e-05, - -8.1880463207962555e-06, -3.9361218137492589e-17, 9.1041892369561194e-04, 4.5307301340353107e-04, 2.4407192087611417e-05, -1.1589997251881807e-03, - 1.2201146101977434e-05, -5.7678007822299421e-04, -3.1071332313249856e-05, -5.6202873171480712e-05, -7.0756666651934822e-06, -1.8044717852722420e-16, - 9.0124227629218500e-04, 4.4848460248163091e-04, -2.7574015762270924e-05, -1.1473174857904726e-03, -1.3619750416150265e-05, -5.7093884748939789e-04, - 3.5102825588767622e-05, -5.5653119508558761e-05, -5.4247562557377872e-06, -1.0868209604022288e-16, 7.3835886561839309e-04, 3.6743879842905105e-04, - -6.3621467426616747e-05, -9.3996038534400355e-04, -3.1529332913601345e-05, -4.6776429544575414e-04, 8.0992674190034908e-05, -4.5587253648843827e-05, - -3.2207980489953576e-06, -1.6498451698665985e-17, 4.8485609369309200e-04, 2.4126875678013410e-04, -7.9184942178653760e-05, -6.1724121140280101e-04, - -3.9263369648527702e-05, -3.0714478305167691e-04, 1.0080560040600143e-04, -2.9948261566577983e-05, -4.6828117365321368e-07, -2.7907473466889570e-16, - 2.1943348004327650e-04, 1.0931001556619420e-04, -6.9776478809175255e-05, -2.7934760190897551e-04, -3.4451757069465494e-05, -1.3915602444572510e-04, - 8.8828250006243000e-05, -1.3462461610682388e-05, 2.8472996610262629e-06, -2.8517753439349179e-17, 3.7604074980109599e-05, 1.8072883786862083e-05, - -3.0294674009660176e-05, -4.7871492379410237e-05, -1.5390330853845416e-05, -2.3007504344661451e-05, 3.8566332418977053e-05, -2.8178579922810013e-06, - 6.6491000063179548e-06, 1.8201534010187335e-16, 5.8489869202416793e-04, 2.8617271619977579e-05, 3.1367048785938028e-04, -7.4459944282304351e-04, - 1.5601216385000831e-05, -3.6430932046655128e-05, -3.9931508426120242e-04, -1.1993596362356830e-05, -1.8606531928369523e-05, 1.1609094708570108e-16, - 1.4277325347643946e-03, 7.0228009414118281e-05, 1.7441241606394765e-04, -1.8175606551731423e-03, 8.5314378018203992e-06, -8.9403066536814779e-05, - -2.2203398570290480e-04, -3.0180009723319791e-05, -1.7465893456551608e-05, 7.9952680116957346e-18, 1.8087408305903605e-03, 8.8933756155068312e-05, - 4.8609262874017952e-05, -2.3025994638615327e-03, 2.3689535246137682e-06, -1.1321623074934033e-04, -6.1881537000456281e-05, -3.8108004663832317e-05, - -1.5106133674201696e-05, -3.4437911683227506e-17, 1.7904898493185757e-03, 8.8038739116105775e-05, -5.4594815714643902e-05, -2.2793652342909749e-03, - -2.7188239063507206e-06, -1.1207683823983096e-04, 6.9501385310806059e-05, -3.7747530559384820e-05, -1.1580436012161972e-05, -5.3751195984836405e-17, - 1.4669018971553392e-03, 7.2126947445379482e-05, -1.2615623684791947e-04, -1.8674248210698470e-03, -6.2473383435676977e-06, -9.1820490646863468e-05, - 1.6060193832966014e-04, -3.0915439591938444e-05, -6.8766677416264973e-06, -7.2829702745483415e-17, 9.6325796444333490e-04, 4.7364249466599229e-05, - -1.5703540377681876e-04, -1.2262659386990920e-03, -7.7720809383183452e-06, -6.0296585106921430e-05, 1.9991235362654895e-04, -2.0321917006824303e-05, - -9.9955532670582353e-07, -5.6107483444491660e-17, 4.3610842151573615e-04, 2.1413925090684689e-05, -1.3819686293538045e-04, -5.5518347382010706e-04, - -6.8888362637714928e-06, -2.7260783634201552e-05, 1.7593013720956378e-04, -9.1041122183843021e-06, 6.0629566842222413e-06, -1.1946646468031830e-17, - 7.3270287126065377e-05, 3.7405038611191754e-06, -6.0708847522435975e-05, -9.3276007817201794e-05, -2.8745282594642544e-06, -4.7618111116780999e-06, - 7.7284792488002224e-05, -1.8716955469385451e-06, 1.4257402535388324e-05, 4.2151661090997407e-17, 5.4219548657403398e-04, -4.6964511263722479e-05, - 2.9091105641265626e-04, -6.9023655328565383e-04, -2.5099762187774952e-05, 5.9787702377004467e-05, -3.7034141718838637e-04, -7.1078530314491457e-06, - -1.7138457671755167e-05, 7.2291469764503234e-17, 1.3236741350854942e-03, -1.1444951102741537e-04, 1.6169038423840810e-04, -1.6850901479239229e-03, - -1.4004905074144496e-05, 1.4569880785234056e-04, -2.0583833004829050e-04, -1.7897506519463947e-05, -1.6042765456801554e-05, 8.1778256449745880e-17, - 1.6769291755919702e-03, -1.4502400361685578e-04, 4.5047880146293769e-05, -2.1347979518943441e-03, -3.8980585320151169e-06, 1.8462136052193719e-04, - -5.7347754260101918e-05, -2.2607359364033162e-05, -1.3884451253030498e-05, 3.1613783950993451e-17, 1.6599996084288107e-03, -1.4355365040746436e-04, - -5.0637183330118932e-05, -2.1132459353676147e-03, 4.3684028831022470e-06, 1.8274954204226714e-04, 6.4463160899275100e-05, -2.2392186132939819e-05, - -1.0642774281307588e-05, -2.0569040606703768e-18, 1.3599971624205561e-03, -1.1761250922653675e-04, -1.1698967736129657e-04, -1.7313308153830715e-03, - 1.0103627331037176e-05, 1.4972543114426227e-04, 1.4893254125387590e-04, -1.8339153449488886e-05, -6.3208097101509027e-06, -1.6520376512049561e-17, - 8.9304807164383899e-04, -7.7225405099968049e-05, -1.4562879398960886e-04, -1.1368859353378985e-03, 1.2582857886104629e-05, 9.8311031283340679e-05, - 1.8539128287041925e-04, -1.2053450101604032e-05, -9.1822109816026481e-07, -1.1776408068596795e-17, 4.0432786569251865e-04, -3.4987563703472656e-05, - -1.2816820392759742e-04, -5.1472555438692672e-04, 1.1047540869096497e-05, 4.4540568810563562e-05, 1.6316325294177080e-04, -5.4055108406492386e-06, - 5.5618567638242114e-06, 1.2197631094270155e-17, 6.8002926475168316e-05, -5.8069646962690798e-06, -5.6225462188887827e-05, -8.6570446906960555e-05, - 4.9002968245240032e-06, 7.3924984553178245e-06, 7.1577263531512648e-05, -1.1167339314809732e-06, 1.3140222484464619e-05, 5.8504681465728778e-17, - 3.0109676194992063e-04, -8.6992163559340913e-05, 1.6152938865410021e-04, -3.8330822797374379e-04, -4.6572459248559639e-05, 1.1074450567149812e-04, - -2.0563337622629170e-04, -3.0476196624545761e-06, -9.5344390692410756e-06, 2.5658063100360113e-16, 7.3504616021197644e-04, -2.1219385883250536e-04, - 8.9786913323481145e-05, -9.3574317878682058e-04, -2.5939534318848258e-05, 2.7013127437548311e-04, -1.1430233396836765e-04, -7.6719397877277883e-06, - -8.9337392931367838e-06, 1.3999285833550340e-16, 9.3120558827594559e-04, -2.6884245930155841e-04, 2.5018632896869424e-05, -1.1854619810896538e-03, - -7.2279537638851598e-06, 3.4224720987189987e-04, -3.1849720933216418e-05, -9.6892163186646901e-06, -7.7309086961071439e-06, 8.5740907185919959e-17, - 9.2180607376459356e-04, -2.6612401553146941e-04, -2.8115105526496142e-05, -1.1734960229443305e-03, 8.1052313173897706e-06, 3.3878652215939243e-04, - 3.5791654512842690e-05, -9.5969568198558014e-06, -5.9258354008375010e-06, 4.8242096485927886e-17, 7.5521454677799423e-04, -2.1803021136888130e-04, - -6.4959947881067893e-05, -9.6141834203184470e-04, 1.8739033755341866e-05, 2.7756118472744694e-04, 8.2696613375294535e-05, -7.8598788404704144e-06, - -3.5194659963044798e-06, 2.6526019995138209e-17, 4.9591678847472865e-04, -1.4316667347180327e-04, -8.0861991798912851e-05, -6.3132191851341746e-04, - 2.3329868400285224e-05, 1.8225690491622097e-04, 1.0294055168875558e-04, -5.1659110589356979e-06, -5.1117197886743053e-07, 1.7518231999671528e-17, - 2.2452284971683406e-04, -6.4833668634043566e-05, -7.1167813182526515e-05, -2.8582657318240094e-04, 2.0511575929736604e-05, 8.2535854840080106e-05, - 9.0599474345229793e-05, -2.3154572454563152e-06, 3.0981066058906943e-06, 2.0293341889326816e-17, 3.7749886887509071e-05, -1.0834213338340566e-05, - -3.1230076485337226e-05, -4.8057116773339659e-05, 9.0542379286492321e-06, 1.3792387169257779e-05, 3.9757137205697967e-05, -4.7736440054448337e-07, - 7.3084505808889546e-06, 5.1380996417200149e-17, -2.6369173463370998e-05, -9.7874810518086666e-05, -1.4156115092791256e-05, 3.3569013122789893e-05, - -5.2437299075761091e-05, 1.2459855077792001e-04, 1.8021301046546994e-05, 2.0225634435349193e-07, 8.2737327434274039e-07, 2.9408986913590118e-16, - -6.4401076442212866e-05, -2.3880385491961627e-04, -7.8652359084084544e-06, 8.1985147666903182e-05, -2.9185828660976991e-05, 3.0400686433693043e-04, - 1.0012760081321650e-05, 5.1040642098054282e-07, 7.7809221148924742e-07, 1.8801925825746067e-16, -8.1583353672089317e-05, -3.0254949112893596e-04, - -2.1908826904423915e-06, 1.0385887422223798e-04, -8.1313422416431392e-06, 3.8515761035684808e-04, 2.7890813449623851e-06, 6.4546625765844063e-07, - 6.7280421817217426e-07, 1.2336526352308237e-16, -8.0757424528202224e-05, -2.9949136733266730e-04, 2.4649783637492719e-06, 1.0280743336817254e-04, - 9.1266848261748081e-06, 3.8126449637688130e-04, -3.1380161064321046e-06, 6.3927833037451373e-07, 5.1575107170323075e-07, 8.6261223990707393e-17, - -6.6158684055452865e-05, -2.4536651900581988e-04, 5.6930861126347582e-06, 8.4222652499092417e-05, 2.1095228673489606e-05, 3.1236139835907060e-04, - -7.2475264609154193e-06, 5.2383308233506750e-07, 3.0620542597858777e-07, 5.8835010400590615e-17, -4.3439872336614058e-05, -1.6111739776339496e-04, - 7.0856641229928402e-06, 5.5300695965266336e-05, 2.6262233432287653e-05, 2.0510889533447631e-04, -9.0203339996267705e-06, 3.4429239733317430e-07, - 4.4421321296056952e-08, 3.7118787564661390e-17, -1.9661496835279546e-05, -7.2956872225940153e-05, 6.2364545034698510e-06, 2.5029872332166819e-05, - 2.3096613004453422e-05, 9.2877018106378645e-05, -7.9392561682623682e-06, 1.5500833779623422e-07, -2.7032276650592434e-07, 1.8444121589638132e-17, - -3.3149552044149548e-06, -1.2216240033765435e-05, 2.7320505890445826e-06, 4.2200706411741357e-06, 1.0173710041980746e-05, 1.5551762461853329e-05, - -3.4780097375158219e-06, 3.2586873483438240e-08, -6.3374425049766073e-07, -1.3804174291048425e-17, -3.5046776690512922e-04, -8.6097341540895459e-05, - -1.8804143086066668e-04, 4.4615949312742958e-04, -4.6138941825076984e-05, 1.0960536143114947e-04, 2.3938426697787092e-04, 2.6393373958459857e-06, - 1.1077684119986845e-05, 2.8754810140367706e-16, -8.5563118982646936e-04, -2.1009107982628570e-04, -1.0451452877109037e-04, 1.0892527473456870e-03, - -2.5673892807405829e-05, 2.6745435254660658e-04, 1.3305117783823987e-04, 6.6467490018443551e-06, 1.0380762902200129e-05, 1.8034621692091753e-16, - -1.0839644414273974e-03, -2.6616909306344407e-04, -2.9119379734335553e-05, 1.3799301146204357e-03, -7.1531646979175727e-06, 3.3884390766164969e-04, - 3.7070135770883186e-05, 8.3963955227189068e-06, 8.9821168968238431e-06, 1.3648290180391621e-16, -1.0730176634536303e-03, -2.6347918201769844e-04, - 3.2732351109902035e-05, 1.3659944281655622e-03, 8.0305360855978434e-06, 3.3541954324910601e-04, -4.1669592924459006e-05, 8.3164350440210235e-06, - 6.8851645536143642e-06, 1.0951181679474486e-16, -8.7908999816589000e-04, -2.1586222088963193e-04, 7.5622040169423250e-05, 1.1191167491928352e-03, - 1.8560279471198105e-05, 2.7480124608354631e-04, -9.6269883559473628e-05, 6.8115232787058816e-06, 4.0890266760255126e-06, 8.2352293683465305e-17, - -5.7725205425149739e-04, -1.4174402118255575e-04, 9.4132221087056837e-05, 7.3486496691653816e-04, 2.3105816616275750e-05, 1.8044581161690863e-04, - -1.1983408465234938e-04, 4.4769112358827155e-06, 5.9407987857321188e-07, 5.1878348453767501e-17, -2.6133624469446931e-04, -6.4181688197269951e-05, - 8.2846618815280525e-05, 3.3269149827545961e-04, 2.0323581324048325e-05, 8.1705857651539975e-05, -1.0546706130612097e-04, 2.0081691410597411e-06, - -3.6005452741329560e-06, 1.9482062592479926e-17, -4.3958996718269349e-05, -1.0755488950552287e-05, 3.6342108184730914e-05, 5.5961562078827826e-05, - 8.9457858332771938e-06, 1.3692167872827874e-05, -4.6264958144590181e-05, 4.1533005657324436e-07, -8.4914149761139613e-06, -3.6675292072574968e-17, - -6.0391518322665716e-04, -5.8133025437974522e-05, -3.2401990289680299e-04, 7.6880819717064326e-04, -3.1157234702201196e-05, 7.4005667889288912e-05, - 4.1249030379167482e-04, 4.2641058538617344e-06, 1.9094342915962170e-05, 1.4047071619921544e-16, -1.4743782859743583e-03, -1.4186131475806473e-04, - -1.8009465973341197e-04, 1.8769425632444658e-03, -1.7335155668375508e-05, 1.8059513103273111e-04, 2.2926770929981871e-04, 1.0737709998697717e-05, - 1.7891815716318834e-05, 1.2513825497453909e-16, -1.8678324615433617e-03, -1.7972636255982402e-04, -5.0177806705344206e-05, 2.3778254749348320e-03, - -4.8298278531647810e-06, 2.2879885225845213e-04, 6.3878356071490829e-05, 1.3563696440515171e-05, 1.5481586715522774e-05, 1.2872813679253942e-16, - -1.8489709303059541e-03, -1.7791020436131418e-04, 5.6401394648706507e-05, 2.3538139908237531e-03, 5.4230258469302585e-06, 2.2648681018836461e-04, - -7.1801232593804391e-05, 1.3434536925261634e-05, 1.1867224005867065e-05, 1.1871040135927971e-16, -1.5148068254141093e-03, -1.4575747047953298e-04, - 1.3030661548298330e-04, 1.9284097119174682e-03, 1.2533216551742667e-05, 1.8555509319178608e-04, -1.6588553643186879e-04, 1.1003322845519037e-05, - 7.0478959388720587e-06, 9.6340345162047416e-17, -9.9469578895184643e-04, -9.5710452873525712e-05, 1.6220276314313697e-04, 1.2662875474526423e-03, - 1.5602511542290004e-05, 1.2184323687798953e-04, -2.0649060889962924e-04, 7.2319800498276379e-06, 1.0239596690627012e-06, 6.3275699227690185e-17, - -4.5032633391016435e-04, -4.3336922314424310e-05, 1.4275601491742489e-04, 5.7328344530474149e-04, 1.3724632897095396e-05, 5.5169636466947329e-05, - -1.8173412014178784e-04, 3.2435488692378338e-06, -6.2054078588167645e-06, 2.8221989307501208e-17, -7.5742210399375013e-05, -7.2652034204510260e-06, - 6.2625581143304829e-05, 9.6422865071426825e-05, 6.0388313855867765e-06, 9.2488947105098056e-06, -7.9724871095863313e-05, 6.7044703543938449e-07, - -1.4636620319136193e-05, 5.1691853407524822e-18, -7.4185325279727617e-04, -2.0456784067398124e-05, -3.9802597843889169e-04, 9.4440888007032834e-04, - -1.0964684083796703e-05, 2.6042304806468720e-05, 5.0670299970890598e-04, 5.0764812236771154e-06, 2.3457263346578311e-05, -1.0073674248609138e-16, - -1.8111297630613963e-03, -4.9921555573597583e-05, -2.2122899042755054e-04, 2.3056406705031186e-03, -6.1001783803646252e-06, 6.3552138125520804e-05, - 2.8163335848550429e-04, 1.2783176280236964e-05, 2.1979419790258758e-05, 6.6977617418593946e-17, -2.2944506126897760e-03, -6.3246271865093260e-05, - -6.1638761923269263e-05, 2.9209274547706120e-03, -1.6996066367323673e-06, 8.0515035224969721e-05, 7.8468610735829105e-05, 1.6147340377878379e-05, - 1.9018655925890873e-05, 1.1423587423447701e-16, -2.2712814698432077e-03, -6.2607182589644026e-05, 6.9283273198982406e-05, 2.8914322086887149e-03, - 1.9084463650277778e-06, 7.9701449000711097e-05, -8.8200379526163659e-05, 1.5993584902367006e-05, 1.4578513220971289e-05, 1.1911881276741378e-16, - -1.8607939734753178e-03, -5.1292513034896659e-05, 1.6006863502988669e-04, 2.3688651979412380e-03, 4.4105638650393805e-06, 6.5297421839984935e-05, - -2.0377377840281700e-04, 1.3099218422382080e-05, 8.6581482607716177e-06, 1.0056404625464723e-16, -1.2218883130103921e-03, -3.3680823229325111e-05, - 1.9925006776766002e-04, 1.5555127229134004e-03, 5.4906542718873293e-06, 4.2877035890732338e-05, -2.5365331033436308e-04, 8.6095141065870595e-06, - 1.2579210421268802e-06, 6.9454607065394521e-17, -5.5318357068327587e-04, -1.5250285570936698e-05, 1.7536157032519589e-04, 7.0422482410400209e-04, - 4.8299508614765804e-06, 1.9414223854234138e-05, -2.2324229706303925e-04, 3.8612474615724914e-06, -7.6230039760333550e-06, 3.8651870276418839e-17, - -9.3040091887944807e-05, -2.5570471988800072e-06, 7.6930184467910291e-05, 1.1844376047442972e-04, 2.1248537374226546e-06, 3.2552234182123116e-06, - -9.7935203603902093e-05, 7.9801219628591905e-07, -1.7981070634122831e-05, 1.2404970576903513e-17, + 2.9366410440283302e-04, 1.4679523967220964e-04, 1.5833417110396145e-04, + -3.7384615745763466e-04, 7.8278512648638829e-05, -1.8687621490641275e-04, + -2.0156573641115063e-04, -1.7623476288484310e-05, -8.6854584350381429e-06, + 2.9951311795116681e-17, 7.1871323474270667e-04, 3.5755576442359968e-04, + 8.7710214994801027e-05, -9.1495071101377866e-04, 4.3774882151080975e-05, + -4.5518279763380145e-04, -1.1165861388558839e-04, -4.4456825652005657e-05, + -8.1880463207962555e-06, -3.9361218137492589e-17, 9.1041892369561194e-04, + 4.5307301340353107e-04, 2.4407192087611417e-05, -1.1589997251881807e-03, + 1.2201146101977434e-05, -5.7678007822299421e-04, -3.1071332313249856e-05, + -5.6202873171480712e-05, -7.0756666651934822e-06, -1.8044717852722420e-16, + 9.0124227629218500e-04, 4.4848460248163091e-04, -2.7574015762270924e-05, + -1.1473174857904726e-03, -1.3619750416150265e-05, -5.7093884748939789e-04, + 3.5102825588767622e-05, -5.5653119508558761e-05, -5.4247562557377872e-06, + -1.0868209604022288e-16, 7.3835886561839309e-04, 3.6743879842905105e-04, + -6.3621467426616747e-05, -9.3996038534400355e-04, -3.1529332913601345e-05, + -4.6776429544575414e-04, 8.0992674190034908e-05, -4.5587253648843827e-05, + -3.2207980489953576e-06, -1.6498451698665985e-17, 4.8485609369309200e-04, + 2.4126875678013410e-04, -7.9184942178653760e-05, -6.1724121140280101e-04, + -3.9263369648527702e-05, -3.0714478305167691e-04, 1.0080560040600143e-04, + -2.9948261566577983e-05, -4.6828117365321368e-07, -2.7907473466889570e-16, + 2.1943348004327650e-04, 1.0931001556619420e-04, -6.9776478809175255e-05, + -2.7934760190897551e-04, -3.4451757069465494e-05, -1.3915602444572510e-04, + 8.8828250006243000e-05, -1.3462461610682388e-05, 2.8472996610262629e-06, + -2.8517753439349179e-17, 3.7604074980109599e-05, 1.8072883786862083e-05, + -3.0294674009660176e-05, -4.7871492379410237e-05, -1.5390330853845416e-05, + -2.3007504344661451e-05, 3.8566332418977053e-05, -2.8178579922810013e-06, + 6.6491000063179548e-06, 1.8201534010187335e-16, 5.8489869202416793e-04, + 2.8617271619977579e-05, 3.1367048785938028e-04, -7.4459944282304351e-04, + 1.5601216385000831e-05, -3.6430932046655128e-05, -3.9931508426120242e-04, + -1.1993596362356830e-05, -1.8606531928369523e-05, 1.1609094708570108e-16, + 1.4277325347643946e-03, 7.0228009414118281e-05, 1.7441241606394765e-04, + -1.8175606551731423e-03, 8.5314378018203992e-06, -8.9403066536814779e-05, + -2.2203398570290480e-04, -3.0180009723319791e-05, -1.7465893456551608e-05, + 7.9952680116957346e-18, 1.8087408305903605e-03, 8.8933756155068312e-05, + 4.8609262874017952e-05, -2.3025994638615327e-03, 2.3689535246137682e-06, + -1.1321623074934033e-04, -6.1881537000456281e-05, -3.8108004663832317e-05, + -1.5106133674201696e-05, -3.4437911683227506e-17, 1.7904898493185757e-03, + 8.8038739116105775e-05, -5.4594815714643902e-05, -2.2793652342909749e-03, + -2.7188239063507206e-06, -1.1207683823983096e-04, 6.9501385310806059e-05, + -3.7747530559384820e-05, -1.1580436012161972e-05, -5.3751195984836405e-17, + 1.4669018971553392e-03, 7.2126947445379482e-05, -1.2615623684791947e-04, + -1.8674248210698470e-03, -6.2473383435676977e-06, -9.1820490646863468e-05, + 1.6060193832966014e-04, -3.0915439591938444e-05, -6.8766677416264973e-06, + -7.2829702745483415e-17, 9.6325796444333490e-04, 4.7364249466599229e-05, + -1.5703540377681876e-04, -1.2262659386990920e-03, -7.7720809383183452e-06, + -6.0296585106921430e-05, 1.9991235362654895e-04, -2.0321917006824303e-05, + -9.9955532670582353e-07, -5.6107483444491660e-17, 4.3610842151573615e-04, + 2.1413925090684689e-05, -1.3819686293538045e-04, -5.5518347382010706e-04, + -6.8888362637714928e-06, -2.7260783634201552e-05, 1.7593013720956378e-04, + -9.1041122183843021e-06, 6.0629566842222413e-06, -1.1946646468031830e-17, + 7.3270287126065377e-05, 3.7405038611191754e-06, -6.0708847522435975e-05, + -9.3276007817201794e-05, -2.8745282594642544e-06, -4.7618111116780999e-06, + 7.7284792488002224e-05, -1.8716955469385451e-06, 1.4257402535388324e-05, + 4.2151661090997407e-17, 5.4219548657403398e-04, -4.6964511263722479e-05, + 2.9091105641265626e-04, -6.9023655328565383e-04, -2.5099762187774952e-05, + 5.9787702377004467e-05, -3.7034141718838637e-04, -7.1078530314491457e-06, + -1.7138457671755167e-05, 7.2291469764503234e-17, 1.3236741350854942e-03, + -1.1444951102741537e-04, 1.6169038423840810e-04, -1.6850901479239229e-03, + -1.4004905074144496e-05, 1.4569880785234056e-04, -2.0583833004829050e-04, + -1.7897506519463947e-05, -1.6042765456801554e-05, 8.1778256449745880e-17, + 1.6769291755919702e-03, -1.4502400361685578e-04, 4.5047880146293769e-05, + -2.1347979518943441e-03, -3.8980585320151169e-06, 1.8462136052193719e-04, + -5.7347754260101918e-05, -2.2607359364033162e-05, -1.3884451253030498e-05, + 3.1613783950993451e-17, 1.6599996084288107e-03, -1.4355365040746436e-04, + -5.0637183330118932e-05, -2.1132459353676147e-03, 4.3684028831022470e-06, + 1.8274954204226714e-04, 6.4463160899275100e-05, -2.2392186132939819e-05, + -1.0642774281307588e-05, -2.0569040606703768e-18, 1.3599971624205561e-03, + -1.1761250922653675e-04, -1.1698967736129657e-04, -1.7313308153830715e-03, + 1.0103627331037176e-05, 1.4972543114426227e-04, 1.4893254125387590e-04, + -1.8339153449488886e-05, -6.3208097101509027e-06, -1.6520376512049561e-17, + 8.9304807164383899e-04, -7.7225405099968049e-05, -1.4562879398960886e-04, + -1.1368859353378985e-03, 1.2582857886104629e-05, 9.8311031283340679e-05, + 1.8539128287041925e-04, -1.2053450101604032e-05, -9.1822109816026481e-07, + -1.1776408068596795e-17, 4.0432786569251865e-04, -3.4987563703472656e-05, + -1.2816820392759742e-04, -5.1472555438692672e-04, 1.1047540869096497e-05, + 4.4540568810563562e-05, 1.6316325294177080e-04, -5.4055108406492386e-06, + 5.5618567638242114e-06, 1.2197631094270155e-17, 6.8002926475168316e-05, + -5.8069646962690798e-06, -5.6225462188887827e-05, -8.6570446906960555e-05, + 4.9002968245240032e-06, 7.3924984553178245e-06, 7.1577263531512648e-05, + -1.1167339314809732e-06, 1.3140222484464619e-05, 5.8504681465728778e-17, + 3.0109676194992063e-04, -8.6992163559340913e-05, 1.6152938865410021e-04, + -3.8330822797374379e-04, -4.6572459248559639e-05, 1.1074450567149812e-04, + -2.0563337622629170e-04, -3.0476196624545761e-06, -9.5344390692410756e-06, + 2.5658063100360113e-16, 7.3504616021197644e-04, -2.1219385883250536e-04, + 8.9786913323481145e-05, -9.3574317878682058e-04, -2.5939534318848258e-05, + 2.7013127437548311e-04, -1.1430233396836765e-04, -7.6719397877277883e-06, + -8.9337392931367838e-06, 1.3999285833550340e-16, 9.3120558827594559e-04, + -2.6884245930155841e-04, 2.5018632896869424e-05, -1.1854619810896538e-03, + -7.2279537638851598e-06, 3.4224720987189987e-04, -3.1849720933216418e-05, + -9.6892163186646901e-06, -7.7309086961071439e-06, 8.5740907185919959e-17, + 9.2180607376459356e-04, -2.6612401553146941e-04, -2.8115105526496142e-05, + -1.1734960229443305e-03, 8.1052313173897706e-06, 3.3878652215939243e-04, + 3.5791654512842690e-05, -9.5969568198558014e-06, -5.9258354008375010e-06, + 4.8242096485927886e-17, 7.5521454677799423e-04, -2.1803021136888130e-04, + -6.4959947881067893e-05, -9.6141834203184470e-04, 1.8739033755341866e-05, + 2.7756118472744694e-04, 8.2696613375294535e-05, -7.8598788404704144e-06, + -3.5194659963044798e-06, 2.6526019995138209e-17, 4.9591678847472865e-04, + -1.4316667347180327e-04, -8.0861991798912851e-05, -6.3132191851341746e-04, + 2.3329868400285224e-05, 1.8225690491622097e-04, 1.0294055168875558e-04, + -5.1659110589356979e-06, -5.1117197886743053e-07, 1.7518231999671528e-17, + 2.2452284971683406e-04, -6.4833668634043566e-05, -7.1167813182526515e-05, + -2.8582657318240094e-04, 2.0511575929736604e-05, 8.2535854840080106e-05, + 9.0599474345229793e-05, -2.3154572454563152e-06, 3.0981066058906943e-06, + 2.0293341889326816e-17, 3.7749886887509071e-05, -1.0834213338340566e-05, + -3.1230076485337226e-05, -4.8057116773339659e-05, 9.0542379286492321e-06, + 1.3792387169257779e-05, 3.9757137205697967e-05, -4.7736440054448337e-07, + 7.3084505808889546e-06, 5.1380996417200149e-17, -2.6369173463370998e-05, + -9.7874810518086666e-05, -1.4156115092791256e-05, 3.3569013122789893e-05, + -5.2437299075761091e-05, 1.2459855077792001e-04, 1.8021301046546994e-05, + 2.0225634435349193e-07, 8.2737327434274039e-07, 2.9408986913590118e-16, + -6.4401076442212866e-05, -2.3880385491961627e-04, -7.8652359084084544e-06, + 8.1985147666903182e-05, -2.9185828660976991e-05, 3.0400686433693043e-04, + 1.0012760081321650e-05, 5.1040642098054282e-07, 7.7809221148924742e-07, + 1.8801925825746067e-16, -8.1583353672089317e-05, -3.0254949112893596e-04, + -2.1908826904423915e-06, 1.0385887422223798e-04, -8.1313422416431392e-06, + 3.8515761035684808e-04, 2.7890813449623851e-06, 6.4546625765844063e-07, + 6.7280421817217426e-07, 1.2336526352308237e-16, -8.0757424528202224e-05, + -2.9949136733266730e-04, 2.4649783637492719e-06, 1.0280743336817254e-04, + 9.1266848261748081e-06, 3.8126449637688130e-04, -3.1380161064321046e-06, + 6.3927833037451373e-07, 5.1575107170323075e-07, 8.6261223990707393e-17, + -6.6158684055452865e-05, -2.4536651900581988e-04, 5.6930861126347582e-06, + 8.4222652499092417e-05, 2.1095228673489606e-05, 3.1236139835907060e-04, + -7.2475264609154193e-06, 5.2383308233506750e-07, 3.0620542597858777e-07, + 5.8835010400590615e-17, -4.3439872336614058e-05, -1.6111739776339496e-04, + 7.0856641229928402e-06, 5.5300695965266336e-05, 2.6262233432287653e-05, + 2.0510889533447631e-04, -9.0203339996267705e-06, 3.4429239733317430e-07, + 4.4421321296056952e-08, 3.7118787564661390e-17, -1.9661496835279546e-05, + -7.2956872225940153e-05, 6.2364545034698510e-06, 2.5029872332166819e-05, + 2.3096613004453422e-05, 9.2877018106378645e-05, -7.9392561682623682e-06, + 1.5500833779623422e-07, -2.7032276650592434e-07, 1.8444121589638132e-17, + -3.3149552044149548e-06, -1.2216240033765435e-05, 2.7320505890445826e-06, + 4.2200706411741357e-06, 1.0173710041980746e-05, 1.5551762461853329e-05, + -3.4780097375158219e-06, 3.2586873483438240e-08, -6.3374425049766073e-07, + -1.3804174291048425e-17, -3.5046776690512922e-04, -8.6097341540895459e-05, + -1.8804143086066668e-04, 4.4615949312742958e-04, -4.6138941825076984e-05, + 1.0960536143114947e-04, 2.3938426697787092e-04, 2.6393373958459857e-06, + 1.1077684119986845e-05, 2.8754810140367706e-16, -8.5563118982646936e-04, + -2.1009107982628570e-04, -1.0451452877109037e-04, 1.0892527473456870e-03, + -2.5673892807405829e-05, 2.6745435254660658e-04, 1.3305117783823987e-04, + 6.6467490018443551e-06, 1.0380762902200129e-05, 1.8034621692091753e-16, + -1.0839644414273974e-03, -2.6616909306344407e-04, -2.9119379734335553e-05, + 1.3799301146204357e-03, -7.1531646979175727e-06, 3.3884390766164969e-04, + 3.7070135770883186e-05, 8.3963955227189068e-06, 8.9821168968238431e-06, + 1.3648290180391621e-16, -1.0730176634536303e-03, -2.6347918201769844e-04, + 3.2732351109902035e-05, 1.3659944281655622e-03, 8.0305360855978434e-06, + 3.3541954324910601e-04, -4.1669592924459006e-05, 8.3164350440210235e-06, + 6.8851645536143642e-06, 1.0951181679474486e-16, -8.7908999816589000e-04, + -2.1586222088963193e-04, 7.5622040169423250e-05, 1.1191167491928352e-03, + 1.8560279471198105e-05, 2.7480124608354631e-04, -9.6269883559473628e-05, + 6.8115232787058816e-06, 4.0890266760255126e-06, 8.2352293683465305e-17, + -5.7725205425149739e-04, -1.4174402118255575e-04, 9.4132221087056837e-05, + 7.3486496691653816e-04, 2.3105816616275750e-05, 1.8044581161690863e-04, + -1.1983408465234938e-04, 4.4769112358827155e-06, 5.9407987857321188e-07, + 5.1878348453767501e-17, -2.6133624469446931e-04, -6.4181688197269951e-05, + 8.2846618815280525e-05, 3.3269149827545961e-04, 2.0323581324048325e-05, + 8.1705857651539975e-05, -1.0546706130612097e-04, 2.0081691410597411e-06, + -3.6005452741329560e-06, 1.9482062592479926e-17, -4.3958996718269349e-05, + -1.0755488950552287e-05, 3.6342108184730914e-05, 5.5961562078827826e-05, + 8.9457858332771938e-06, 1.3692167872827874e-05, -4.6264958144590181e-05, + 4.1533005657324436e-07, -8.4914149761139613e-06, -3.6675292072574968e-17, + -6.0391518322665716e-04, -5.8133025437974522e-05, -3.2401990289680299e-04, + 7.6880819717064326e-04, -3.1157234702201196e-05, 7.4005667889288912e-05, + 4.1249030379167482e-04, 4.2641058538617344e-06, 1.9094342915962170e-05, + 1.4047071619921544e-16, -1.4743782859743583e-03, -1.4186131475806473e-04, + -1.8009465973341197e-04, 1.8769425632444658e-03, -1.7335155668375508e-05, + 1.8059513103273111e-04, 2.2926770929981871e-04, 1.0737709998697717e-05, + 1.7891815716318834e-05, 1.2513825497453909e-16, -1.8678324615433617e-03, + -1.7972636255982402e-04, -5.0177806705344206e-05, 2.3778254749348320e-03, + -4.8298278531647810e-06, 2.2879885225845213e-04, 6.3878356071490829e-05, + 1.3563696440515171e-05, 1.5481586715522774e-05, 1.2872813679253942e-16, + -1.8489709303059541e-03, -1.7791020436131418e-04, 5.6401394648706507e-05, + 2.3538139908237531e-03, 5.4230258469302585e-06, 2.2648681018836461e-04, + -7.1801232593804391e-05, 1.3434536925261634e-05, 1.1867224005867065e-05, + 1.1871040135927971e-16, -1.5148068254141093e-03, -1.4575747047953298e-04, + 1.3030661548298330e-04, 1.9284097119174682e-03, 1.2533216551742667e-05, + 1.8555509319178608e-04, -1.6588553643186879e-04, 1.1003322845519037e-05, + 7.0478959388720587e-06, 9.6340345162047416e-17, -9.9469578895184643e-04, + -9.5710452873525712e-05, 1.6220276314313697e-04, 1.2662875474526423e-03, + 1.5602511542290004e-05, 1.2184323687798953e-04, -2.0649060889962924e-04, + 7.2319800498276379e-06, 1.0239596690627012e-06, 6.3275699227690185e-17, + -4.5032633391016435e-04, -4.3336922314424310e-05, 1.4275601491742489e-04, + 5.7328344530474149e-04, 1.3724632897095396e-05, 5.5169636466947329e-05, + -1.8173412014178784e-04, 3.2435488692378338e-06, -6.2054078588167645e-06, + 2.8221989307501208e-17, -7.5742210399375013e-05, -7.2652034204510260e-06, + 6.2625581143304829e-05, 9.6422865071426825e-05, 6.0388313855867765e-06, + 9.2488947105098056e-06, -7.9724871095863313e-05, 6.7044703543938449e-07, + -1.4636620319136193e-05, 5.1691853407524822e-18, -7.4185325279727617e-04, + -2.0456784067398124e-05, -3.9802597843889169e-04, 9.4440888007032834e-04, + -1.0964684083796703e-05, 2.6042304806468720e-05, 5.0670299970890598e-04, + 5.0764812236771154e-06, 2.3457263346578311e-05, -1.0073674248609138e-16, + -1.8111297630613963e-03, -4.9921555573597583e-05, -2.2122899042755054e-04, + 2.3056406705031186e-03, -6.1001783803646252e-06, 6.3552138125520804e-05, + 2.8163335848550429e-04, 1.2783176280236964e-05, 2.1979419790258758e-05, + 6.6977617418593946e-17, -2.2944506126897760e-03, -6.3246271865093260e-05, + -6.1638761923269263e-05, 2.9209274547706120e-03, -1.6996066367323673e-06, + 8.0515035224969721e-05, 7.8468610735829105e-05, 1.6147340377878379e-05, + 1.9018655925890873e-05, 1.1423587423447701e-16, -2.2712814698432077e-03, + -6.2607182589644026e-05, 6.9283273198982406e-05, 2.8914322086887149e-03, + 1.9084463650277778e-06, 7.9701449000711097e-05, -8.8200379526163659e-05, + 1.5993584902367006e-05, 1.4578513220971289e-05, 1.1911881276741378e-16, + -1.8607939734753178e-03, -5.1292513034896659e-05, 1.6006863502988669e-04, + 2.3688651979412380e-03, 4.4105638650393805e-06, 6.5297421839984935e-05, + -2.0377377840281700e-04, 1.3099218422382080e-05, 8.6581482607716177e-06, + 1.0056404625464723e-16, -1.2218883130103921e-03, -3.3680823229325111e-05, + 1.9925006776766002e-04, 1.5555127229134004e-03, 5.4906542718873293e-06, + 4.2877035890732338e-05, -2.5365331033436308e-04, 8.6095141065870595e-06, + 1.2579210421268802e-06, 6.9454607065394521e-17, -5.5318357068327587e-04, + -1.5250285570936698e-05, 1.7536157032519589e-04, 7.0422482410400209e-04, + 4.8299508614765804e-06, 1.9414223854234138e-05, -2.2324229706303925e-04, + 3.8612474615724914e-06, -7.6230039760333550e-06, 3.8651870276418839e-17, + -9.3040091887944807e-05, -2.5570471988800072e-06, 7.6930184467910291e-05, + 1.1844376047442972e-04, 2.1248537374226546e-06, 3.2552234182123116e-06, + -9.7935203603902093e-05, 7.9801219628591905e-07, -1.7981070634122831e-05, + 1.2404970576903513e-17 }; return sol; } -static const double * -get_sol_3x_bias_p2_NxDx_PyPy(void) +static const double *get_sol_3x_bias_p2_NxDx_PyPy(void) { static const double sol[640] = { - 2.6007376622747585e-02, -7.1800944496270788e-04, 1.1848784811247477e-02, -3.3108431266206981e-02, -3.2577961081452374e-04, 9.1405475845812636e-04, - -1.5083977257749990e-02, -1.7357322650915152e-04, -2.4528231596292736e-03, -2.4878168330471732e-16, 2.6007376622748265e-02, -7.1800944496270181e-04, - -1.1848784811247111e-02, -3.3108431266206918e-02, 3.2577961081452483e-04, 9.1405475845813167e-04, 1.5083977257749992e-02, -1.7357322650915244e-04, - -2.4528231596292914e-03, -2.9270179092558335e-16, -2.6007376622746436e-02, 7.1800944496270365e-04, -1.1848784811247128e-02, 3.3108431266207619e-02, - 3.2577961081452374e-04, -9.1405475845813221e-04, 1.5083977257749993e-02, 1.7357322650914987e-04, 2.4528231596292996e-03, 4.7189503890956915e-16, - -2.6007376622746225e-02, 7.1800944496270365e-04, 1.1848784811247218e-02, 3.3108431266207473e-02, -3.2577961081452266e-04, -9.1405475845812983e-04, - -1.5083977257750094e-02, 1.7357322650915022e-04, 2.4528231596292701e-03, 3.0312274075053911e-16, 2.6007376622748459e-02, -7.1800944496270528e-04, - 1.1848784811247060e-02, -3.3108431266207390e-02, -3.2577961081452564e-04, 9.1405475845812646e-04, -1.5083977257750094e-02, -1.7357322650914743e-04, - -2.4528231596292814e-03, -8.5723427941119742e-16, 2.6007376622748039e-02, -7.1800944496270603e-04, -1.1848784811247305e-02, -3.3108431266207404e-02, - 3.2577961081452428e-04, 9.1405475845812983e-04, 1.5083977257750113e-02, -1.7357322650914767e-04, -2.4528231596292857e-03, -8.5960190237677279e-16, - -2.6007376622747401e-02, 7.1800944496269888e-04, -1.1848784811247390e-02, 3.3108431266207647e-02, 3.2577961081452456e-04, -9.1405475845813178e-04, - 1.5083977257750217e-02, 1.7357322650914784e-04, 2.4528231596292831e-03, 4.3789679653681983e-16, -2.6007376622747918e-02, 7.1800944496269563e-04, - 1.1848784811247176e-02, 3.3108431266207820e-02, -3.2577961081452510e-04, -9.1405475845813199e-04, -1.5083977257750136e-02, 1.7357322650914862e-04, - 2.4528231596293512e-03, 6.5295682528229116e-16, 2.1167581926037952e-02, -2.0404149472422264e-03, 9.6451162689074419e-03, -2.6947178926806876e-02, - -9.2582118178574223e-04, 2.5975298860486684e-03, -1.2278619011668608e-02, -1.4581758526841442e-04, -1.9953554848409750e-03, -1.9846597865511841e-16, - 2.1167581926038660e-02, -2.0404149472422147e-03, -9.6451162689070637e-03, -2.6947178926806793e-02, 9.2582118178574689e-04, 2.5975298860486740e-03, - 1.2278619011668618e-02, -1.4581758526841315e-04, -1.9953554848410001e-03, -2.5019234191788001e-16, -2.1167581926036835e-02, 2.0404149472422121e-03, - -9.6451162689070880e-03, 2.6947178926807511e-02, 9.2582118178574755e-04, -2.5975298860486731e-03, 1.2278619011668634e-02, 1.4581758526841532e-04, - 1.9953554848409988e-03, 3.9159096504921086e-16, -2.1167581926036603e-02, 2.0404149472422251e-03, 9.6451162689071834e-03, 2.6947178926807359e-02, - -9.2582118178574538e-04, -2.5975298860486736e-03, -1.2278619011668735e-02, 1.4581758526841545e-04, 1.9953554848409628e-03, 2.0929696023269232e-16, - 2.1167581926038861e-02, -2.0404149472422139e-03, 9.6451162689070169e-03, -2.6947178926807269e-02, -9.2582118178574809e-04, 2.5975298860486775e-03, - -1.2278619011668728e-02, -1.4581758526841361e-04, -1.9953554848409823e-03, -7.9443263974794385e-16, 2.1167581926038424e-02, -2.0404149472422199e-03, - -9.6451162689072650e-03, -2.6947178926807272e-02, 9.2582118178574646e-04, 2.5975298860486822e-03, 1.2278619011668740e-02, -1.4581758526841242e-04, - -1.9953554848409828e-03, -7.8880633582714310e-16, -2.1167581926037807e-02, 2.0404149472422139e-03, -9.6451162689073638e-03, 2.6947178926807511e-02, - 9.2582118178574147e-04, -2.5975298860486788e-03, 1.2278619011668837e-02, 1.4581758526841556e-04, 1.9953554848409784e-03, 3.3757240821831445e-16, - -2.1167581926038358e-02, 2.0404149472422026e-03, 9.6451162689071418e-03, 2.6947178926807695e-02, -9.2582118178574679e-04, -2.5975298860486827e-03, - -1.2278619011668761e-02, 1.4581758526841396e-04, 1.9953554848410500e-03, 5.6669789601608066e-16, 1.2275170226804905e-02, -3.0219442678672110e-03, - 5.5947305550585781e-03, -1.5626782955866884e-02, -1.3712873229270483e-03, 3.8470559923940166e-03, -7.1223158999083576e-03, -9.0296763116215595e-05, - -1.1559633592517281e-03, -6.9718374565947281e-17, 1.2275170226805658e-02, -3.0219442678672001e-03, -5.5947305550581826e-03, -1.5626782955866773e-02, - 1.3712873229270539e-03, 3.8470559923940275e-03, 7.1223158999083758e-03, -9.0296763116215229e-05, -1.1559633592517569e-03, -1.4733928253897693e-16, - -1.2275170226803833e-02, 3.0219442678672010e-03, -5.5947305550581930e-03, 1.5626782955867457e-02, 1.3712873229270600e-03, -3.8470559923940400e-03, - 7.1223158999083949e-03, 9.0296763116214091e-05, 1.1559633592517521e-03, 2.5233815904687563e-16, -1.2275170226803531e-02, 3.0219442678672201e-03, - 5.5947305550582936e-03, 1.5626782955867318e-02, -1.3712873229270563e-03, -3.8470559923940353e-03, -7.1223158999084843e-03, 9.0296763116214240e-05, - 1.1559633592516992e-03, 5.2185638882926514e-17, 1.2275170226805847e-02, -3.0219442678672036e-03, 5.5947305550581201e-03, -1.5626782955867217e-02, - -1.3712873229270600e-03, 3.8470559923940396e-03, -7.1223158999084608e-03, -9.0296763116213142e-05, -1.1559633592517328e-03, -6.6939086156592258e-16, - 1.2275170226805410e-02, -3.0219442678672010e-03, -5.5947305550583725e-03, -1.5626782955867214e-02, 1.3712873229270585e-03, 3.8470559923940357e-03, - 7.1223158999084730e-03, -9.0296763116213142e-05, -1.1559633592517333e-03, -6.4814241569201302e-16, -1.2275170226804797e-02, 3.0219442678672027e-03, - -5.5947305550584931e-03, 1.5626782955867457e-02, 1.3712873229270509e-03, -3.8470559923940418e-03, 7.1223158999085727e-03, 9.0296763116214592e-05, - 1.1559633592517172e-03, 1.6762567593882249e-16, -1.2275170226805394e-02, 3.0219442678671832e-03, 5.5947305550582476e-03, 1.5626782955867613e-02, - -1.3712873229270585e-03, -3.8470559923940518e-03, -7.1223158999085137e-03, 9.0296763116213643e-05, 1.1559633592517944e-03, 4.2371697733289753e-16, - 9.0474567801809424e-04, -3.4352259624794690e-03, 4.1169560207639477e-04, -1.1517774563953767e-03, -1.5590467568280778e-03, 4.3731801293314995e-03, - -5.2410497766300346e-04, -6.9908714440816747e-06, -8.5716525570030737e-05, 1.0087562543266326e-16, 9.0474567801889904e-04, -3.4352259624794495e-03, - -4.1169560207597003e-04, -1.1517774563952127e-03, 1.5590467568280886e-03, 4.3731801293315194e-03, 5.2410497766303328e-04, -6.9908714440807184e-06, - -8.5716525570061461e-05, -5.6432601174820048e-18, -9.0474567801707064e-04, 3.4352259624794521e-03, -4.1169560207595583e-04, 1.1517774563958598e-03, - 1.5590467568280977e-03, -4.3731801293315281e-03, 5.2410497766305550e-04, 6.9908714440814486e-06, 8.5716525570062870e-05, 8.6255396812375980e-17, - -9.0474567801669475e-04, 3.4352259624794807e-03, 4.1169560207607108e-04, 1.1517774563957334e-03, -1.5590467568280932e-03, -4.3731801293315237e-03, - -5.2410497766312977e-04, 6.9908714440819949e-06, 8.5716525569984293e-05, -1.3917550946240810e-16, 9.0474567801907370e-04, -3.4352259624794599e-03, - 4.1169560207588384e-04, -1.1517774563956219e-03, -1.5590467568280992e-03, 4.3731801293315272e-03, -5.2410497766310223e-04, -6.9908714440815824e-06, - -8.5716525570027485e-05, -5.1400324451132017e-16, 9.0474567801863742e-04, -3.4352259624794608e-03, -4.1169560207614204e-04, -1.1517774563956321e-03, - 1.5590467568280975e-03, 4.3731801293315263e-03, 5.2410497766311502e-04, -6.9908714440814571e-06, -8.5716525570032567e-05, -4.7577337964055999e-16, - -9.0474567801801639e-04, 3.4352259624794634e-03, -4.1169560207629687e-04, 1.1517774563958468e-03, 1.5590467568280832e-03, -4.3731801293315333e-03, - 5.2410497766318864e-04, 6.9908714440820102e-06, 8.5716525570000217e-05, -2.7030317045506741e-17, -9.0474567801871299e-04, 3.4352259624794265e-03, - 4.1169560207601508e-04, 1.1517774563959680e-03, -1.5590467568280971e-03, -4.3731801293315437e-03, -5.2410497766315698e-04, 6.9908714440803449e-06, - 8.5716525570093269e-05, 2.6678103786357335e-16, -1.0581162695290412e-02, -3.0527070726671960e-03, -4.8324237754404486e-03, 1.3470243573400322e-02, - -1.3858207373338267e-03, 3.8862182740439268e-03, 6.1518688616377165e-03, 1.0413219047989221e-04, 9.8886045271099243e-04, 2.6471475052799496e-16, - -1.0581162695289520e-02, -3.0527070726671652e-03, 4.8324237754409204e-03, 1.3470243573400565e-02, 1.3858207373338431e-03, 3.8862182740439549e-03, - -6.1518688616376757e-03, 1.0413219047989387e-04, 9.8886045271095969e-04, 1.3007774156867251e-16, 1.0581162695291366e-02, 3.0527070726671726e-03, - 4.8324237754409638e-03, -1.3470243573399944e-02, 1.3858207373338529e-03, -3.8862182740439606e-03, -6.1518688616376228e-03, -1.0413219047989234e-04, - -9.8886045271095080e-04, -7.2029495873022837e-17, 1.0581162695291859e-02, 3.0527070726672134e-03, -4.8324237754408294e-03, -1.3470243573400048e-02, - -1.3858207373338460e-03, -3.8862182740439519e-03, 6.1518688616375673e-03, -1.0413219047989091e-04, -9.8886045271106789e-04, -3.3870964976905638e-16, - -1.0581162695289399e-02, -3.0527070726671869e-03, -4.8324237754410488e-03, 1.3470243573400178e-02, -1.3858207373338583e-03, 3.8862182740439588e-03, - 6.1518688616376107e-03, 1.0413219047989210e-04, 9.8886045271101564e-04, -3.6264231760319537e-16, -1.0581162695289836e-02, -3.0527070726671861e-03, - 4.8324237754407869e-03, 1.3470243573400162e-02, 1.3858207373338581e-03, 3.8862182740439571e-03, -6.1518688616375950e-03, 1.0413219047989166e-04, - 9.8886045271100783e-04, -3.0792945033231846e-16, 1.0581162695290471e-02, 3.0527070726671943e-03, 4.8324237754405726e-03, -1.3470243573399975e-02, - 1.3858207373338386e-03, -3.8862182740439627e-03, -6.1518688616375317e-03, -1.0413219047989114e-04, -9.8886045271105163e-04, -2.1358911569739497e-16, - 1.0581162695289621e-02, 3.0527070726671401e-03, -4.8324237754409187e-03, -1.3470243573399878e-02, -1.3858207373338620e-03, -3.8862182740439693e-03, - 6.1518688616375326e-03, -1.0413219047989298e-04, -9.8886045271093757e-04, 1.3214781814909572e-16, -1.9031365111332042e-02, -1.6465866379909038e-03, - -8.7078302006787928e-03, 2.4227689429447936e-02, -7.4805055566576264e-04, 2.0961706872077266e-03, 1.1085416336256877e-02, 2.4312033959708541e-04, - 1.7660289489446149e-03, 3.8057582919529090e-16, -1.9031365111331047e-02, -1.6465866379908704e-03, 8.7078302006793409e-03, 2.4227689429448307e-02, - 7.4805055566578898e-04, 2.0961706872077699e-03, -1.1085416336256830e-02, 2.4312033959708639e-04, 1.7660289489445911e-03, 2.3881830595770688e-16, - 1.9031365111332910e-02, 1.6465866379908717e-03, 8.7078302006794259e-03, -2.4227689429447686e-02, 7.4805055566580069e-04, -2.0961706872077682e-03, - -1.1085416336256692e-02, -2.4312033959708937e-04, -1.7660289489445677e-03, -1.8584489782554045e-16, 1.9031365111333579e-02, 1.6465866379909394e-03, - -8.7078302006792629e-03, -2.4227689429447780e-02, -7.4805055566579137e-04, -2.0961706872077665e-03, 1.1085416336256659e-02, -2.4312033959708498e-04, - -1.7660289489447455e-03, -5.1718202387898003e-16, -1.9031365111331008e-02, -1.6465866379908984e-03, -8.7078302006795335e-03, 2.4227689429447918e-02, - -7.4805055566581186e-04, 2.0961706872077656e-03, 1.1085416336256747e-02, 2.4312033959708631e-04, 1.7660289489446780e-03, -2.4150304858849214e-16, - -1.9031365111331439e-02, -1.6465866379908991e-03, 8.7078302006792785e-03, 2.4227689429447880e-02, 7.4805055566581598e-04, 2.0961706872077573e-03, - -1.1085416336256737e-02, 2.4312033959708406e-04, 1.7660289489446750e-03, -1.8347290836793516e-16, 1.9031365111332136e-02, 1.6465866379909175e-03, - 8.7078302006789923e-03, -2.4227689429447741e-02, 7.4805055566579007e-04, -2.0961706872077812e-03, -1.1085416336256640e-02, -2.4312033959708709e-04, - -1.7660289489446971e-03, -3.4726000200140564e-16, 1.9031365111331040e-02, 1.6465866379908351e-03, -8.7078302006794485e-03, -2.4227689429447651e-02, - -7.4805055566582986e-04, -2.0961706872077816e-03, 1.1085416336256615e-02, -2.4312033959708875e-04, -1.7660289489445636e-03, 6.9267354347634622e-17, - -2.0505104876293125e-02, 1.0112205753418885e-03, -9.4250538894833577e-03, 2.6103819129888628e-02, 4.5837908688127320e-04, -1.2873242618557583e-03, - 1.1998470795679696e-02, 4.1004436283959206e-04, 1.8695463276148204e-03, 4.3637760805796555e-16, -2.0505104876292011e-02, 1.0112205753419238e-03, - 9.4250538894840395e-03, 2.6103819129889190e-02, -4.5837908688122088e-04, -1.2873242618556893e-03, -1.1998470795679674e-02, 4.1004436283959467e-04, - 1.8695463276148486e-03, 2.9371309167686647e-16, 2.0505104876293870e-02, -1.0112205753419258e-03, 9.4250538894841800e-03, -2.6103819129888555e-02, - -4.5837908688119828e-04, 1.2873242618556939e-03, -1.1998470795679395e-02, -4.1004436283959342e-04, -1.8695463276147601e-03, -2.1445411480602755e-16, - 2.0505104876294828e-02, -1.0112205753418297e-03, -9.4250538894839822e-03, -2.6103819129888618e-02, 4.5837908688120944e-04, 1.2873242618557062e-03, - 1.1998470795679393e-02, -4.1004436283959196e-04, -1.8695463276150368e-03, -6.4377669631513899e-16, -2.0505104876292091e-02, 1.0112205753418824e-03, - -9.4250538894843239e-03, 2.6103819129888756e-02, 4.5837908688119063e-04, -1.2873242618557058e-03, 1.1998470795679535e-02, 4.1004436283959304e-04, - 1.8695463276149720e-03, -1.9183169463589791e-16, -2.0505104876292531e-02, 1.0112205753418854e-03, 9.4250538894840898e-03, 2.6103819129888715e-02, - -4.5837908688118191e-04, -1.2873242618557073e-03, -1.1998470795679519e-02, 4.1004436283959380e-04, 1.8695463276149843e-03, -1.4415816212542290e-16, - 2.0505104876293291e-02, -1.0112205753418581e-03, 9.4250538894836821e-03, -2.6103819129888638e-02, -4.5837908688122555e-04, 1.2873242618556954e-03, - -1.1998470795679428e-02, -4.1004436283959196e-04, -1.8695463276149401e-03, -4.2175518614235540e-16, 2.0505104876291865e-02, -1.0112205753419709e-03, - -9.4250538894843309e-03, -2.6103819129888559e-02, 4.5837908688115355e-04, 1.2873242618556950e-03, 1.1998470795679389e-02, -4.1004436283959678e-04, - -1.8695463276148037e-03, 1.0082365576140328e-16, -1.0271215618252966e-02, 5.1490211242928427e-03, -4.8319444906675807e-03, 1.3075668540126886e-02, - 2.3387746451529658e-03, -6.5549099570769986e-03, 6.1512587129415961e-03, 6.0501265406261173e-04, 8.5061915836237459e-04, 4.1782997179837206e-16, - -1.0271215618251738e-02, 5.1490211242928722e-03, 4.8319444906685131e-03, 1.3075668540127792e-02, -2.3387746451528726e-03, -6.5549099570768746e-03, - -6.1512587129416560e-03, 6.0501265406261542e-04, 8.5061915836254654e-04, 2.6693706628250703e-16, 1.0271215618253567e-02, -5.1490211242928869e-03, - 4.8319444906687256e-03, -1.3075668540127089e-02, -2.3387746451528505e-03, 6.5549099570769084e-03, -6.1512587129411147e-03, -6.0501265406261390e-04, - -8.5061915836233762e-04, -1.7021528662009007e-16, 1.0271215618254951e-02, -5.1490211242927377e-03, -4.8319444906684767e-03, -1.3075668540127100e-02, - 2.3387746451528696e-03, 6.5549099570769301e-03, 6.1512587129411772e-03, -6.0501265406261130e-04, -8.5061915836276327e-04, -7.1891925493360827e-16, - -1.0271215618251993e-02, 5.1490211242928132e-03, -4.8319444906688921e-03, 1.3075668540127258e-02, 2.3387746451528453e-03, -6.5549099570769154e-03, - 6.1512587129413984e-03, 6.0501265406261216e-04, 8.5061915836275167e-04, -2.2397369512977885e-16, -1.0271215618252423e-02, 5.1490211242928097e-03, - 4.8319444906687308e-03, 1.3075668540127205e-02, -2.3387746451528127e-03, -6.5549099570769162e-03, -6.1512587129413689e-03, 6.0501265406261205e-04, - 8.5061915836281857e-04, -1.9582901219255179e-16, 1.0271215618253280e-02, -5.1490211242927802e-03, 4.8319444906680890e-03, -1.3075668540127176e-02, - -2.3387746451529043e-03, 6.5549099570769015e-03, -6.1512587129412370e-03, -6.0501265406260999e-04, -8.5061915836256996e-04, -4.2037013883311255e-16, - 1.0271215618251405e-02, -5.1490211242929294e-03, -4.8319444906691081e-03, -1.3075668540127058e-02, 2.3387746451527603e-03, 6.5549099570769223e-03, - 6.1512587129412049e-03, -6.0501265406261661e-04, -8.5061915836252063e-04, 2.5108205205904367e-16, + 2.6007376622747585e-02, -7.1800944496270788e-04, 1.1848784811247477e-02, + -3.3108431266206981e-02, -3.2577961081452374e-04, 9.1405475845812636e-04, + -1.5083977257749990e-02, -1.7357322650915152e-04, -2.4528231596292736e-03, + -2.4878168330471732e-16, 2.6007376622748265e-02, -7.1800944496270181e-04, + -1.1848784811247111e-02, -3.3108431266206918e-02, 3.2577961081452483e-04, + 9.1405475845813167e-04, 1.5083977257749992e-02, -1.7357322650915244e-04, + -2.4528231596292914e-03, -2.9270179092558335e-16, -2.6007376622746436e-02, + 7.1800944496270365e-04, -1.1848784811247128e-02, 3.3108431266207619e-02, + 3.2577961081452374e-04, -9.1405475845813221e-04, 1.5083977257749993e-02, + 1.7357322650914987e-04, 2.4528231596292996e-03, 4.7189503890956915e-16, + -2.6007376622746225e-02, 7.1800944496270365e-04, 1.1848784811247218e-02, + 3.3108431266207473e-02, -3.2577961081452266e-04, -9.1405475845812983e-04, + -1.5083977257750094e-02, 1.7357322650915022e-04, 2.4528231596292701e-03, + 3.0312274075053911e-16, 2.6007376622748459e-02, -7.1800944496270528e-04, + 1.1848784811247060e-02, -3.3108431266207390e-02, -3.2577961081452564e-04, + 9.1405475845812646e-04, -1.5083977257750094e-02, -1.7357322650914743e-04, + -2.4528231596292814e-03, -8.5723427941119742e-16, 2.6007376622748039e-02, + -7.1800944496270603e-04, -1.1848784811247305e-02, -3.3108431266207404e-02, + 3.2577961081452428e-04, 9.1405475845812983e-04, 1.5083977257750113e-02, + -1.7357322650914767e-04, -2.4528231596292857e-03, -8.5960190237677279e-16, + -2.6007376622747401e-02, 7.1800944496269888e-04, -1.1848784811247390e-02, + 3.3108431266207647e-02, 3.2577961081452456e-04, -9.1405475845813178e-04, + 1.5083977257750217e-02, 1.7357322650914784e-04, 2.4528231596292831e-03, + 4.3789679653681983e-16, -2.6007376622747918e-02, 7.1800944496269563e-04, + 1.1848784811247176e-02, 3.3108431266207820e-02, -3.2577961081452510e-04, + -9.1405475845813199e-04, -1.5083977257750136e-02, 1.7357322650914862e-04, + 2.4528231596293512e-03, 6.5295682528229116e-16, 2.1167581926037952e-02, + -2.0404149472422264e-03, 9.6451162689074419e-03, -2.6947178926806876e-02, + -9.2582118178574223e-04, 2.5975298860486684e-03, -1.2278619011668608e-02, + -1.4581758526841442e-04, -1.9953554848409750e-03, -1.9846597865511841e-16, + 2.1167581926038660e-02, -2.0404149472422147e-03, -9.6451162689070637e-03, + -2.6947178926806793e-02, 9.2582118178574689e-04, 2.5975298860486740e-03, + 1.2278619011668618e-02, -1.4581758526841315e-04, -1.9953554848410001e-03, + -2.5019234191788001e-16, -2.1167581926036835e-02, 2.0404149472422121e-03, + -9.6451162689070880e-03, 2.6947178926807511e-02, 9.2582118178574755e-04, + -2.5975298860486731e-03, 1.2278619011668634e-02, 1.4581758526841532e-04, + 1.9953554848409988e-03, 3.9159096504921086e-16, -2.1167581926036603e-02, + 2.0404149472422251e-03, 9.6451162689071834e-03, 2.6947178926807359e-02, + -9.2582118178574538e-04, -2.5975298860486736e-03, -1.2278619011668735e-02, + 1.4581758526841545e-04, 1.9953554848409628e-03, 2.0929696023269232e-16, + 2.1167581926038861e-02, -2.0404149472422139e-03, 9.6451162689070169e-03, + -2.6947178926807269e-02, -9.2582118178574809e-04, 2.5975298860486775e-03, + -1.2278619011668728e-02, -1.4581758526841361e-04, -1.9953554848409823e-03, + -7.9443263974794385e-16, 2.1167581926038424e-02, -2.0404149472422199e-03, + -9.6451162689072650e-03, -2.6947178926807272e-02, 9.2582118178574646e-04, + 2.5975298860486822e-03, 1.2278619011668740e-02, -1.4581758526841242e-04, + -1.9953554848409828e-03, -7.8880633582714310e-16, -2.1167581926037807e-02, + 2.0404149472422139e-03, -9.6451162689073638e-03, 2.6947178926807511e-02, + 9.2582118178574147e-04, -2.5975298860486788e-03, 1.2278619011668837e-02, + 1.4581758526841556e-04, 1.9953554848409784e-03, 3.3757240821831445e-16, + -2.1167581926038358e-02, 2.0404149472422026e-03, 9.6451162689071418e-03, + 2.6947178926807695e-02, -9.2582118178574679e-04, -2.5975298860486827e-03, + -1.2278619011668761e-02, 1.4581758526841396e-04, 1.9953554848410500e-03, + 5.6669789601608066e-16, 1.2275170226804905e-02, -3.0219442678672110e-03, + 5.5947305550585781e-03, -1.5626782955866884e-02, -1.3712873229270483e-03, + 3.8470559923940166e-03, -7.1223158999083576e-03, -9.0296763116215595e-05, + -1.1559633592517281e-03, -6.9718374565947281e-17, 1.2275170226805658e-02, + -3.0219442678672001e-03, -5.5947305550581826e-03, -1.5626782955866773e-02, + 1.3712873229270539e-03, 3.8470559923940275e-03, 7.1223158999083758e-03, + -9.0296763116215229e-05, -1.1559633592517569e-03, -1.4733928253897693e-16, + -1.2275170226803833e-02, 3.0219442678672010e-03, -5.5947305550581930e-03, + 1.5626782955867457e-02, 1.3712873229270600e-03, -3.8470559923940400e-03, + 7.1223158999083949e-03, 9.0296763116214091e-05, 1.1559633592517521e-03, + 2.5233815904687563e-16, -1.2275170226803531e-02, 3.0219442678672201e-03, + 5.5947305550582936e-03, 1.5626782955867318e-02, -1.3712873229270563e-03, + -3.8470559923940353e-03, -7.1223158999084843e-03, 9.0296763116214240e-05, + 1.1559633592516992e-03, 5.2185638882926514e-17, 1.2275170226805847e-02, + -3.0219442678672036e-03, 5.5947305550581201e-03, -1.5626782955867217e-02, + -1.3712873229270600e-03, 3.8470559923940396e-03, -7.1223158999084608e-03, + -9.0296763116213142e-05, -1.1559633592517328e-03, -6.6939086156592258e-16, + 1.2275170226805410e-02, -3.0219442678672010e-03, -5.5947305550583725e-03, + -1.5626782955867214e-02, 1.3712873229270585e-03, 3.8470559923940357e-03, + 7.1223158999084730e-03, -9.0296763116213142e-05, -1.1559633592517333e-03, + -6.4814241569201302e-16, -1.2275170226804797e-02, 3.0219442678672027e-03, + -5.5947305550584931e-03, 1.5626782955867457e-02, 1.3712873229270509e-03, + -3.8470559923940418e-03, 7.1223158999085727e-03, 9.0296763116214592e-05, + 1.1559633592517172e-03, 1.6762567593882249e-16, -1.2275170226805394e-02, + 3.0219442678671832e-03, 5.5947305550582476e-03, 1.5626782955867613e-02, + -1.3712873229270585e-03, -3.8470559923940518e-03, -7.1223158999085137e-03, + 9.0296763116213643e-05, 1.1559633592517944e-03, 4.2371697733289753e-16, + 9.0474567801809424e-04, -3.4352259624794690e-03, 4.1169560207639477e-04, + -1.1517774563953767e-03, -1.5590467568280778e-03, 4.3731801293314995e-03, + -5.2410497766300346e-04, -6.9908714440816747e-06, -8.5716525570030737e-05, + 1.0087562543266326e-16, 9.0474567801889904e-04, -3.4352259624794495e-03, + -4.1169560207597003e-04, -1.1517774563952127e-03, 1.5590467568280886e-03, + 4.3731801293315194e-03, 5.2410497766303328e-04, -6.9908714440807184e-06, + -8.5716525570061461e-05, -5.6432601174820048e-18, -9.0474567801707064e-04, + 3.4352259624794521e-03, -4.1169560207595583e-04, 1.1517774563958598e-03, + 1.5590467568280977e-03, -4.3731801293315281e-03, 5.2410497766305550e-04, + 6.9908714440814486e-06, 8.5716525570062870e-05, 8.6255396812375980e-17, + -9.0474567801669475e-04, 3.4352259624794807e-03, 4.1169560207607108e-04, + 1.1517774563957334e-03, -1.5590467568280932e-03, -4.3731801293315237e-03, + -5.2410497766312977e-04, 6.9908714440819949e-06, 8.5716525569984293e-05, + -1.3917550946240810e-16, 9.0474567801907370e-04, -3.4352259624794599e-03, + 4.1169560207588384e-04, -1.1517774563956219e-03, -1.5590467568280992e-03, + 4.3731801293315272e-03, -5.2410497766310223e-04, -6.9908714440815824e-06, + -8.5716525570027485e-05, -5.1400324451132017e-16, 9.0474567801863742e-04, + -3.4352259624794608e-03, -4.1169560207614204e-04, -1.1517774563956321e-03, + 1.5590467568280975e-03, 4.3731801293315263e-03, 5.2410497766311502e-04, + -6.9908714440814571e-06, -8.5716525570032567e-05, -4.7577337964055999e-16, + -9.0474567801801639e-04, 3.4352259624794634e-03, -4.1169560207629687e-04, + 1.1517774563958468e-03, 1.5590467568280832e-03, -4.3731801293315333e-03, + 5.2410497766318864e-04, 6.9908714440820102e-06, 8.5716525570000217e-05, + -2.7030317045506741e-17, -9.0474567801871299e-04, 3.4352259624794265e-03, + 4.1169560207601508e-04, 1.1517774563959680e-03, -1.5590467568280971e-03, + -4.3731801293315437e-03, -5.2410497766315698e-04, 6.9908714440803449e-06, + 8.5716525570093269e-05, 2.6678103786357335e-16, -1.0581162695290412e-02, + -3.0527070726671960e-03, -4.8324237754404486e-03, 1.3470243573400322e-02, + -1.3858207373338267e-03, 3.8862182740439268e-03, 6.1518688616377165e-03, + 1.0413219047989221e-04, 9.8886045271099243e-04, 2.6471475052799496e-16, + -1.0581162695289520e-02, -3.0527070726671652e-03, 4.8324237754409204e-03, + 1.3470243573400565e-02, 1.3858207373338431e-03, 3.8862182740439549e-03, + -6.1518688616376757e-03, 1.0413219047989387e-04, 9.8886045271095969e-04, + 1.3007774156867251e-16, 1.0581162695291366e-02, 3.0527070726671726e-03, + 4.8324237754409638e-03, -1.3470243573399944e-02, 1.3858207373338529e-03, + -3.8862182740439606e-03, -6.1518688616376228e-03, -1.0413219047989234e-04, + -9.8886045271095080e-04, -7.2029495873022837e-17, 1.0581162695291859e-02, + 3.0527070726672134e-03, -4.8324237754408294e-03, -1.3470243573400048e-02, + -1.3858207373338460e-03, -3.8862182740439519e-03, 6.1518688616375673e-03, + -1.0413219047989091e-04, -9.8886045271106789e-04, -3.3870964976905638e-16, + -1.0581162695289399e-02, -3.0527070726671869e-03, -4.8324237754410488e-03, + 1.3470243573400178e-02, -1.3858207373338583e-03, 3.8862182740439588e-03, + 6.1518688616376107e-03, 1.0413219047989210e-04, 9.8886045271101564e-04, + -3.6264231760319537e-16, -1.0581162695289836e-02, -3.0527070726671861e-03, + 4.8324237754407869e-03, 1.3470243573400162e-02, 1.3858207373338581e-03, + 3.8862182740439571e-03, -6.1518688616375950e-03, 1.0413219047989166e-04, + 9.8886045271100783e-04, -3.0792945033231846e-16, 1.0581162695290471e-02, + 3.0527070726671943e-03, 4.8324237754405726e-03, -1.3470243573399975e-02, + 1.3858207373338386e-03, -3.8862182740439627e-03, -6.1518688616375317e-03, + -1.0413219047989114e-04, -9.8886045271105163e-04, -2.1358911569739497e-16, + 1.0581162695289621e-02, 3.0527070726671401e-03, -4.8324237754409187e-03, + -1.3470243573399878e-02, -1.3858207373338620e-03, -3.8862182740439693e-03, + 6.1518688616375326e-03, -1.0413219047989298e-04, -9.8886045271093757e-04, + 1.3214781814909572e-16, -1.9031365111332042e-02, -1.6465866379909038e-03, + -8.7078302006787928e-03, 2.4227689429447936e-02, -7.4805055566576264e-04, + 2.0961706872077266e-03, 1.1085416336256877e-02, 2.4312033959708541e-04, + 1.7660289489446149e-03, 3.8057582919529090e-16, -1.9031365111331047e-02, + -1.6465866379908704e-03, 8.7078302006793409e-03, 2.4227689429448307e-02, + 7.4805055566578898e-04, 2.0961706872077699e-03, -1.1085416336256830e-02, + 2.4312033959708639e-04, 1.7660289489445911e-03, 2.3881830595770688e-16, + 1.9031365111332910e-02, 1.6465866379908717e-03, 8.7078302006794259e-03, + -2.4227689429447686e-02, 7.4805055566580069e-04, -2.0961706872077682e-03, + -1.1085416336256692e-02, -2.4312033959708937e-04, -1.7660289489445677e-03, + -1.8584489782554045e-16, 1.9031365111333579e-02, 1.6465866379909394e-03, + -8.7078302006792629e-03, -2.4227689429447780e-02, -7.4805055566579137e-04, + -2.0961706872077665e-03, 1.1085416336256659e-02, -2.4312033959708498e-04, + -1.7660289489447455e-03, -5.1718202387898003e-16, -1.9031365111331008e-02, + -1.6465866379908984e-03, -8.7078302006795335e-03, 2.4227689429447918e-02, + -7.4805055566581186e-04, 2.0961706872077656e-03, 1.1085416336256747e-02, + 2.4312033959708631e-04, 1.7660289489446780e-03, -2.4150304858849214e-16, + -1.9031365111331439e-02, -1.6465866379908991e-03, 8.7078302006792785e-03, + 2.4227689429447880e-02, 7.4805055566581598e-04, 2.0961706872077573e-03, + -1.1085416336256737e-02, 2.4312033959708406e-04, 1.7660289489446750e-03, + -1.8347290836793516e-16, 1.9031365111332136e-02, 1.6465866379909175e-03, + 8.7078302006789923e-03, -2.4227689429447741e-02, 7.4805055566579007e-04, + -2.0961706872077812e-03, -1.1085416336256640e-02, -2.4312033959708709e-04, + -1.7660289489446971e-03, -3.4726000200140564e-16, 1.9031365111331040e-02, + 1.6465866379908351e-03, -8.7078302006794485e-03, -2.4227689429447651e-02, + -7.4805055566582986e-04, -2.0961706872077816e-03, 1.1085416336256615e-02, + -2.4312033959708875e-04, -1.7660289489445636e-03, 6.9267354347634622e-17, + -2.0505104876293125e-02, 1.0112205753418885e-03, -9.4250538894833577e-03, + 2.6103819129888628e-02, 4.5837908688127320e-04, -1.2873242618557583e-03, + 1.1998470795679696e-02, 4.1004436283959206e-04, 1.8695463276148204e-03, + 4.3637760805796555e-16, -2.0505104876292011e-02, 1.0112205753419238e-03, + 9.4250538894840395e-03, 2.6103819129889190e-02, -4.5837908688122088e-04, + -1.2873242618556893e-03, -1.1998470795679674e-02, 4.1004436283959467e-04, + 1.8695463276148486e-03, 2.9371309167686647e-16, 2.0505104876293870e-02, + -1.0112205753419258e-03, 9.4250538894841800e-03, -2.6103819129888555e-02, + -4.5837908688119828e-04, 1.2873242618556939e-03, -1.1998470795679395e-02, + -4.1004436283959342e-04, -1.8695463276147601e-03, -2.1445411480602755e-16, + 2.0505104876294828e-02, -1.0112205753418297e-03, -9.4250538894839822e-03, + -2.6103819129888618e-02, 4.5837908688120944e-04, 1.2873242618557062e-03, + 1.1998470795679393e-02, -4.1004436283959196e-04, -1.8695463276150368e-03, + -6.4377669631513899e-16, -2.0505104876292091e-02, 1.0112205753418824e-03, + -9.4250538894843239e-03, 2.6103819129888756e-02, 4.5837908688119063e-04, + -1.2873242618557058e-03, 1.1998470795679535e-02, 4.1004436283959304e-04, + 1.8695463276149720e-03, -1.9183169463589791e-16, -2.0505104876292531e-02, + 1.0112205753418854e-03, 9.4250538894840898e-03, 2.6103819129888715e-02, + -4.5837908688118191e-04, -1.2873242618557073e-03, -1.1998470795679519e-02, + 4.1004436283959380e-04, 1.8695463276149843e-03, -1.4415816212542290e-16, + 2.0505104876293291e-02, -1.0112205753418581e-03, 9.4250538894836821e-03, + -2.6103819129888638e-02, -4.5837908688122555e-04, 1.2873242618556954e-03, + -1.1998470795679428e-02, -4.1004436283959196e-04, -1.8695463276149401e-03, + -4.2175518614235540e-16, 2.0505104876291865e-02, -1.0112205753419709e-03, + -9.4250538894843309e-03, -2.6103819129888559e-02, 4.5837908688115355e-04, + 1.2873242618556950e-03, 1.1998470795679389e-02, -4.1004436283959678e-04, + -1.8695463276148037e-03, 1.0082365576140328e-16, -1.0271215618252966e-02, + 5.1490211242928427e-03, -4.8319444906675807e-03, 1.3075668540126886e-02, + 2.3387746451529658e-03, -6.5549099570769986e-03, 6.1512587129415961e-03, + 6.0501265406261173e-04, 8.5061915836237459e-04, 4.1782997179837206e-16, + -1.0271215618251738e-02, 5.1490211242928722e-03, 4.8319444906685131e-03, + 1.3075668540127792e-02, -2.3387746451528726e-03, -6.5549099570768746e-03, + -6.1512587129416560e-03, 6.0501265406261542e-04, 8.5061915836254654e-04, + 2.6693706628250703e-16, 1.0271215618253567e-02, -5.1490211242928869e-03, + 4.8319444906687256e-03, -1.3075668540127089e-02, -2.3387746451528505e-03, + 6.5549099570769084e-03, -6.1512587129411147e-03, -6.0501265406261390e-04, + -8.5061915836233762e-04, -1.7021528662009007e-16, 1.0271215618254951e-02, + -5.1490211242927377e-03, -4.8319444906684767e-03, -1.3075668540127100e-02, + 2.3387746451528696e-03, 6.5549099570769301e-03, 6.1512587129411772e-03, + -6.0501265406261130e-04, -8.5061915836276327e-04, -7.1891925493360827e-16, + -1.0271215618251993e-02, 5.1490211242928132e-03, -4.8319444906688921e-03, + 1.3075668540127258e-02, 2.3387746451528453e-03, -6.5549099570769154e-03, + 6.1512587129413984e-03, 6.0501265406261216e-04, 8.5061915836275167e-04, + -2.2397369512977885e-16, -1.0271215618252423e-02, 5.1490211242928097e-03, + 4.8319444906687308e-03, 1.3075668540127205e-02, -2.3387746451528127e-03, + -6.5549099570769162e-03, -6.1512587129413689e-03, 6.0501265406261205e-04, + 8.5061915836281857e-04, -1.9582901219255179e-16, 1.0271215618253280e-02, + -5.1490211242927802e-03, 4.8319444906680890e-03, -1.3075668540127176e-02, + -2.3387746451529043e-03, 6.5549099570769015e-03, -6.1512587129412370e-03, + -6.0501265406260999e-04, -8.5061915836256996e-04, -4.2037013883311255e-16, + 1.0271215618251405e-02, -5.1490211242929294e-03, -4.8319444906691081e-03, + -1.3075668540127058e-02, 2.3387746451527603e-03, 6.5549099570769223e-03, + 6.1512587129412049e-03, -6.0501265406261661e-04, -8.5061915836252063e-04, + 2.5108205205904367e-16 }; return sol; } -static const double * -get_sol_3x_biasB_p1_DxDx_DyDy(void) +static const double *get_sol_3x_biasB_p1_DxDx_DyDy(void) { static const double sol[512] = { - -4.4041922402994508e-03, -2.5427615754988948e-03, -1.0665671304152860e-04, 3.7718620629148253e-05, - -6.1578281985007731e-05, 2.1776855773916784e-05, -1.6454514526474550e-05, -9.5000183910323872e-06, - -2.6096743371754640e-03, -1.5066961810654262e-03, -6.9169901643607081e-05, 6.1409551253443335e-04, - -3.9935261333768437e-05, 3.5454820946981773e-04, 1.6276715296146205e-05, 9.3973659577225150e-06, - -4.8238508035630792e-04, -2.7850515599675828e-04, -1.2785705897272424e-05, 6.1409551253432623e-04, - -7.3818307414892410e-06, 3.5454820946985161e-04, 1.6276715296142577e-05, 9.3973659577230299e-06, - 1.6449041764628515e-03, 9.4968586907191971e-04, 4.3598489849228317e-05, 6.1409551253429771e-04, - 2.5171599850703604e-05, 3.5454820946987070e-04, 1.6276715296122763e-05, 9.3973659577310852e-06, - 3.7721934332819408e-03, 2.1778768941405919e-03, 9.9982685595574256e-05, 6.1409551253416305e-04, - 5.7725030442970594e-05, 3.5454820946990772e-04, 1.6276715296088936e-05, 9.3973659577540534e-06, - 5.8994826901014163e-03, 3.4060679192091698e-03, 1.5636688134197224e-04, 6.1409551253423353e-04, - 9.0278461035230045e-05, 3.5454820946988067e-04, 1.6276715296172321e-05, 9.3973659576982136e-06, - 8.0267719469204173e-03, 4.6342589442779272e-03, 2.1275107708848732e-04, 6.1409551253416761e-04, - 1.2283189162741587e-04, 3.5454820946994730e-04, 1.6276715296031209e-05, 9.3973659577826543e-06, - 1.0154061203738809e-02, 5.8624499693468073e-03, 2.6913527283490597e-04, 6.1409551253420447e-04, - 1.5538532221965102e-04, 3.5454820946989601e-04, 1.6276715296035092e-05, 9.3973659577696252e-06, - - -1.1018979264020300e-02, -1.2762874932783809e-03, -2.6494102141839070e-04, -2.8994604615678344e-04, - -2.9807206064867279e-05, -2.1095413934670354e-04, -5.7460710141012667e-05, -1.4174919685463714e-05, - -6.6613512061697421e-03, -8.3254054991779977e-04, -1.7752438980077028e-04, 1.5675158485682092e-03, - -2.2623231571673787e-05, 1.9590927819014637e-04, 4.1774151505839880e-05, 5.3235857015895280e-06, - -1.2313170233906152e-03, -1.5389090291880844e-04, -3.2814484098407900e-05, 1.5675158485681827e-03, - -4.1817897444755747e-06, 1.9590927819015892e-04, 4.1774151505836052e-05, 5.3235857015888046e-06, - 4.1987171593885252e-03, 5.2475874408017883e-04, 1.1189542160396868e-04, 1.5675158485681906e-03, - 1.4259652082721208e-05, 1.9590927819016068e-04, 4.1774151505830529e-05, 5.3235857015890257e-06, - 9.6287513421676133e-03, 1.2034083910791829e-03, 2.5660532730632313e-04, 1.5675158485681483e-03, - 3.2701093909920751e-05, 1.9590927819017681e-04, 4.1774151505832115e-05, 5.3235857015865329e-06, - 1.5058785524946838e-02, 1.8820580380781381e-03, 4.0131523300871499e-04, 1.5675158485681689e-03, - 5.1142535737119170e-05, 1.9590927819017611e-04, 4.1774151505820053e-05, 5.3235857015869310e-06, - 2.0488819707725963e-02, 2.5607076850771271e-03, 5.4602513871109741e-04, 1.5675158485682298e-03, - 6.9583977564318124e-05, 1.9590927819018239e-04, 4.1774151505813304e-05, 5.3235857015801149e-06, - 2.5918853890504821e-02, 3.2393573320761929e-03, 6.9073504441345018e-04, 1.5675158485681817e-03, - 8.8025419391506493e-05, 1.9590927819018424e-04, 4.1774151505804312e-05, 5.3235857015857799e-06, - - -1.3366720692763396e-02, -7.9181652594083197e-05, -3.2014002221508991e-04, -1.5665805187687065e-03, - -2.0619519041054335e-06, -5.2611111707254622e-04, -1.0875897838019112e-04, -1.5442149291387570e-05, - -8.4983155591709623e-03, -2.2803131377920161e-04, -2.2803131377920622e-04, 1.9997811123959363e-03, - -6.5369545832163292e-06, 5.3659188242116111e-05, 5.3659188242125605e-05, 1.5382434574337128e-06, - -1.5708705777981867e-03, -4.2150433122697153e-05, -4.2150433122704234e-05, 1.9997811123959380e-03, - -1.2083229378424886e-06, 5.3659188242120123e-05, 5.3659188242120949e-05, 1.5382434574338455e-06, - 5.3565744035745932e-03, 1.4373044753380644e-04, 1.4373044753380633e-04, 1.9997811123959493e-03, - 4.1203087075293580e-06, 5.3659188242120502e-05, 5.3659188242116450e-05, 1.5382434574343029e-06, - 1.2284019384947355e-02, 3.2961132819031189e-04, 3.2961132819030463e-04, 1.9997811123959436e-03, - 9.4489403529038885e-06, 5.3659188242125564e-05, 5.3659188242113645e-05, 1.5382434574343915e-06, - 1.9211464366320145e-02, 5.1549220884680247e-04, 5.1549220884683142e-04, 1.9997811123959662e-03, - 1.4777571998274944e-05, 5.3659188242126635e-05, 5.3659188242104951e-05, 1.5382434574354242e-06, - 2.6138909347692911e-02, 7.0137308950330574e-04, 7.0137308950334932e-04, 1.9997811123960299e-03, - 2.0106203643644923e-05, 5.3659188242122142e-05, 5.3659188242088599e-05, 1.5382434574373129e-06, - 3.3066354329065621e-02, 8.8725397015985226e-04, 8.8725397015982602e-04, 1.9997811123959944e-03, - 2.5434835289019607e-05, 5.3659188242128064e-05, 5.3659188242090029e-05, 1.5382434574371947e-06, - - -1.1772420545074049e-02, 9.9965127203158893e-04, -2.9771347337083224e-04, -4.1374953013227720e-03, - 1.5009925916331957e-05, -9.5820722469863165e-04, -1.4619029680330181e-04, -6.1688324763178938e-06, - -8.4328227495495626e-03, 2.6584360504410145e-04, -2.2754565363904947e-04, 1.9843696720032210e-03, - 6.8173505958705989e-06, -6.2556987501449985e-05, 5.3544905127008731e-05, -1.6042248447103262e-06, - -1.5587645637327799e-03, 4.9139843602173047e-05, -4.2060661306196192e-05, 1.9843696720032301e-03, - 1.2601527202690473e-06, -6.2556987501449782e-05, 5.3544905127005309e-05, -1.6042248447096918e-06, - 5.3152936220840080e-03, -1.6756391783975450e-04, 1.4342433102665958e-04, 1.9843696720032410e-03, - -4.2970451553338836e-06, -6.2556987501450744e-05, 5.3544905127002904e-05, -1.6042248447089394e-06, - 1.2189351807900777e-02, -3.8426767928168319e-04, 3.2890932335951224e-04, 1.9843696720032457e-03, - -9.8542430309342842e-06, -6.2556987501449619e-05, 5.3544905127001169e-05, -1.6042248447085263e-06, - 1.9063409993717553e-02, -6.0097144072361120e-04, 5.1439431569237854e-04, 1.9843696720032670e-03, - -1.5411440906539592e-05, -6.2556987501451611e-05, 5.3544905126996466e-05, -1.6042248447072574e-06, - 2.5937468179534327e-02, -8.1767520216553769e-04, 6.9987930802523882e-04, 1.9843696720033108e-03, - -2.0968638782141884e-05, -6.2556987501459797e-05, 5.3544905126988287e-05, -1.6042248447047786e-06, - 3.2811526365351132e-02, -1.0343789636074571e-03, 8.8536430035807004e-04, 1.9843696720032926e-03, - -2.6525836657742338e-05, -6.2556987501455094e-05, 5.3544905126988287e-05, -1.6042248447056049e-06, - - -9.0272890314765722e-03, 5.8525114630483929e-04, -2.2574513915869974e-04, -4.4933715731932363e-03, - 2.6541011214171422e-05, 7.5274196333601873e-04, -1.5552020407559827e-04, 7.8220800114296213e-07, - -6.9204828041277604e-03, 6.0730626955139981e-04, -1.8789706627799494e-04, 1.6284934001327706e-03, - 1.6073771990022628e-05, -1.4290827386115464e-04, 4.4214997854705820e-05, -3.7823996304681823e-06, - -1.2792161864866225e-03, 1.1225748725241897e-04, -3.4731820796203245e-05, 1.6284934001327780e-03, - 2.9711553210232943e-06, -1.4290827386115610e-04, 4.4214997854704085e-05, -3.7823996304676809e-06, - 4.3620504311545211e-03, -3.8279129504656216e-04, 1.1843342468558873e-04, 1.6284934001327851e-03, - -1.0131461347976333e-05, -1.4290827386115716e-04, 4.4214997854703523e-05, -3.7823996304675407e-06, - 1.0003317048795649e-02, -8.7784007734554280e-04, 2.7159867016738124e-04, 1.6284934001327919e-03, - -2.3234078016975833e-05, -1.4290827386115735e-04, 4.4214997854702446e-05, -3.7823996304672675e-06, - 1.5644583666436781e-02, -1.3728888596445214e-03, 4.2476391564917615e-04, 1.6284934001328049e-03, - -3.6336694685976650e-05, -1.4290827386115966e-04, 4.4214997854700812e-05, -3.7823996304667661e-06, - 2.1285850284077916e-02, -1.8679376419435008e-03, 5.7792916113097177e-04, 1.6284934001328227e-03, - -4.9439311354977518e-05, -1.4290827386116670e-04, 4.4214997854699179e-05, -3.7823996304657628e-06, - 2.6927116901719089e-02, -2.3629864242424841e-03, 7.3109440661274961e-04, 1.6284934001328183e-03, - -6.2541928023973379e-05, -1.4290827386116294e-04, 4.4214997854697953e-05, -3.7823996304655858e-06, - - -6.2247900453550730e-03, 1.0327723977360613e-03, -1.3371278969370395e-04, -2.4924537019540933e-03, - 2.6593890523597406e-05, 4.0248850825023367e-04, -1.3292722975764579e-04, 1.2261851803121024e-05, - -4.5637037010479806e-03, 7.5338078003219552e-04, -1.2532535988959181e-04, 1.0739079292105612e-03, - 2.0052019536976041e-05, -1.7728179706443800e-04, 2.9490936864655919e-05, -4.7185409457015368e-06, - -8.4357750896041491e-04, 1.3925862048674964e-04, -2.3165757864813873e-05, 1.0739079292105657e-03, - 3.7065142258784086e-06, -1.7728179706443867e-04, 2.9490936864655435e-05, -4.7185409457013454e-06, - 2.8765486831271551e-03, -4.7486353905869716e-04, 7.8993844159963767e-05, 1.0739079292105696e-03, - -1.2638991085219166e-05, -1.7728179706443922e-04, 2.9490936864655282e-05, -4.7185409457013344e-06, - 6.5966748752147126e-03, -1.0889856986041411e-03, 1.8115344618474199e-04, 1.0739079292105755e-03, - -2.8984496396316930e-05, -1.7728179706443943e-04, 2.9490936864654591e-05, -4.7185409457010650e-06, - 1.0316801067302282e-02, -1.7031078581495856e-03, 2.8331304820951964e-04, 1.0739079292105826e-03, - -4.5330001707415101e-05, -1.7728179706444065e-04, 2.9490936864654490e-05, -4.7185409457012421e-06, - 1.4036927259389841e-02, -2.3172300176950325e-03, 3.8547265023429852e-04, 1.0739079292105855e-03, - -6.1675507018512700e-05, -1.7728179706444239e-04, 2.9490936864654900e-05, -4.7185409457009464e-06, - 1.7757053451477430e-02, -2.9313521772404848e-03, 4.8763225225907262e-04, 1.0739079292105883e-03, - -7.8021012329608367e-05, -1.7728179706444209e-04, 2.9490936864654080e-05, -4.7185409457005339e-06, - - -2.7685660836065627e-03, 9.6267943695907572e-04, -5.1302926806916285e-05, -1.3595218641067415e-03, - 2.0985465997969670e-05, 2.5160999330443233e-04, -8.5156552130073984e-05, 1.5318561784528383e-05, - -2.1160573442293054e-03, 6.5976850295807366e-04, -5.9827506156292608e-05, 4.9794003061817010e-04, - 1.7763183947286998e-05, -1.5525342423246231e-04, 1.4078309516760695e-05, -4.1799436025251460e-06, - -3.9114247992314439e-04, 1.2195486531873465e-04, -1.1058811420875967e-05, 4.9794003061817314e-04, - 3.2834345625935113e-06, -1.5525342423246226e-04, 1.4078309516760042e-05, -4.1799436025254264e-06, - 1.3337723843830172e-03, -4.1585877232060533e-04, 3.7709883314540850e-05, 4.9794003061817682e-04, - -1.1196314822099668e-05, -1.5525342423246185e-04, 1.4078309516759505e-05, -4.1799436025257211e-06, - 3.0586872486891748e-03, -9.5367240995994330e-04, 8.6478578049958005e-05, 4.9794003061818224e-04, - -2.5676064206792951e-05, -1.5525342423246198e-04, 1.4078309516758496e-05, -4.1799436025261192e-06, - 4.7836021129953393e-03, -1.4914860475992832e-03, 1.3524727278537308e-04, 4.9794003061818745e-04, - -4.0155813591486747e-05, -1.5525342423246160e-04, 1.4078309516757525e-05, -4.1799436025265182e-06, - 6.5085169773014956e-03, -2.0292996852386224e-03, 1.8401596752079196e-04, 4.9794003061818853e-04, - -5.4635562976179490e-05, -1.5525342423246120e-04, 1.4078309516757781e-05, -4.1799436025266952e-06, - 8.2334318416076614e-03, -2.5671133228779642e-03, 2.3278466225620765e-04, 4.9794003061819168e-04, - -6.9115312360872741e-05, -1.5525342423246101e-04, 1.4078309516756759e-05, -4.1799436025271077e-06, - - -5.5057819369581863e-04, 3.1787646834022232e-04, -7.4775167389616631e-06, -4.6186028600569848e-04, - 4.3171463021096952e-06, 2.6665516045338905e-04, -2.9312012410193478e-05, 1.6923298255515372e-05, - -4.8665238793613104e-04, 2.8096888717670101e-04, -1.4530384527701296e-05, 1.1451660589924915e-04, - 8.3891214184953722e-06, -6.6116193242614837e-05, 3.4192174122083424e-06, -1.9740860933551212e-06, - -8.9955228480437954e-05, 5.1935675378195315e-05, -2.6858679675683887e-06, 1.1451660589925117e-04, - 1.5506865940831339e-06, -6.6116193242615583e-05, 3.4192174122070139e-06, -1.9740860933552669e-06, - 3.0674193097525530e-04, -1.7709753642030946e-04, 9.1586485925635640e-06, 1.1451660589925462e-04, - -5.2877482303300981e-06, -6.6116193242616098e-05, 3.4192174122056849e-06, -1.9740860933554109e-06, - 7.0343909043094825e-04, -4.0613074821881383e-04, 2.1003165152696916e-05, 1.1451660589925732e-04, - -1.2126183054742609e-05, -6.6116193242617480e-05, 3.4192174122050653e-06, -1.9740860933548040e-06, - 1.1001362498866394e-03, -6.3516396001732215e-04, 3.2847681712829456e-05, 1.1451660589926117e-04, - -1.8964617879153966e-05, -6.6116193242618767e-05, 3.4192174122030078e-06, -1.9740860933549811e-06, - 1.4968334093423308e-03, -8.6419717181582527e-04, 4.4692198272961002e-05, 1.1451660589926484e-04, - -2.5803052703569116e-05, -6.6116193242617331e-05, 3.4192174122015514e-06, -1.9740860933558666e-06, - 1.8935305687980254e-03, -1.0932303836143303e-03, 5.6536714833096980e-05, 1.1451660589926414e-04, - -3.2641487527979211e-05, -6.6116193242619960e-05, 3.4192174122038129e-06, -1.9740860933535500e-06, + -4.4041922402994508e-03, -2.5427615754988948e-03, -1.0665671304152860e-04, + 3.7718620629148253e-05, -6.1578281985007731e-05, 2.1776855773916784e-05, + -1.6454514526474550e-05, -9.5000183910323872e-06, -2.6096743371754640e-03, + -1.5066961810654262e-03, -6.9169901643607081e-05, 6.1409551253443335e-04, + -3.9935261333768437e-05, 3.5454820946981773e-04, 1.6276715296146205e-05, + 9.3973659577225150e-06, -4.8238508035630792e-04, -2.7850515599675828e-04, + -1.2785705897272424e-05, 6.1409551253432623e-04, -7.3818307414892410e-06, + 3.5454820946985161e-04, 1.6276715296142577e-05, 9.3973659577230299e-06, + 1.6449041764628515e-03, 9.4968586907191971e-04, 4.3598489849228317e-05, + 6.1409551253429771e-04, 2.5171599850703604e-05, 3.5454820946987070e-04, + 1.6276715296122763e-05, 9.3973659577310852e-06, 3.7721934332819408e-03, + 2.1778768941405919e-03, 9.9982685595574256e-05, 6.1409551253416305e-04, + 5.7725030442970594e-05, 3.5454820946990772e-04, 1.6276715296088936e-05, + 9.3973659577540534e-06, 5.8994826901014163e-03, 3.4060679192091698e-03, + 1.5636688134197224e-04, 6.1409551253423353e-04, 9.0278461035230045e-05, + 3.5454820946988067e-04, 1.6276715296172321e-05, 9.3973659576982136e-06, + 8.0267719469204173e-03, 4.6342589442779272e-03, 2.1275107708848732e-04, + 6.1409551253416761e-04, 1.2283189162741587e-04, 3.5454820946994730e-04, + 1.6276715296031209e-05, 9.3973659577826543e-06, 1.0154061203738809e-02, + 5.8624499693468073e-03, 2.6913527283490597e-04, 6.1409551253420447e-04, + 1.5538532221965102e-04, 3.5454820946989601e-04, 1.6276715296035092e-05, + 9.3973659577696252e-06, + + -1.1018979264020300e-02, -1.2762874932783809e-03, -2.6494102141839070e-04, + -2.8994604615678344e-04, -2.9807206064867279e-05, -2.1095413934670354e-04, + -5.7460710141012667e-05, -1.4174919685463714e-05, -6.6613512061697421e-03, + -8.3254054991779977e-04, -1.7752438980077028e-04, 1.5675158485682092e-03, + -2.2623231571673787e-05, 1.9590927819014637e-04, 4.1774151505839880e-05, + 5.3235857015895280e-06, -1.2313170233906152e-03, -1.5389090291880844e-04, + -3.2814484098407900e-05, 1.5675158485681827e-03, -4.1817897444755747e-06, + 1.9590927819015892e-04, 4.1774151505836052e-05, 5.3235857015888046e-06, + 4.1987171593885252e-03, 5.2475874408017883e-04, 1.1189542160396868e-04, + 1.5675158485681906e-03, 1.4259652082721208e-05, 1.9590927819016068e-04, + 4.1774151505830529e-05, 5.3235857015890257e-06, 9.6287513421676133e-03, + 1.2034083910791829e-03, 2.5660532730632313e-04, 1.5675158485681483e-03, + 3.2701093909920751e-05, 1.9590927819017681e-04, 4.1774151505832115e-05, + 5.3235857015865329e-06, 1.5058785524946838e-02, 1.8820580380781381e-03, + 4.0131523300871499e-04, 1.5675158485681689e-03, 5.1142535737119170e-05, + 1.9590927819017611e-04, 4.1774151505820053e-05, 5.3235857015869310e-06, + 2.0488819707725963e-02, 2.5607076850771271e-03, 5.4602513871109741e-04, + 1.5675158485682298e-03, 6.9583977564318124e-05, 1.9590927819018239e-04, + 4.1774151505813304e-05, 5.3235857015801149e-06, 2.5918853890504821e-02, + 3.2393573320761929e-03, 6.9073504441345018e-04, 1.5675158485681817e-03, + 8.8025419391506493e-05, 1.9590927819018424e-04, 4.1774151505804312e-05, + 5.3235857015857799e-06, + + -1.3366720692763396e-02, -7.9181652594083197e-05, -3.2014002221508991e-04, + -1.5665805187687065e-03, -2.0619519041054335e-06, -5.2611111707254622e-04, + -1.0875897838019112e-04, -1.5442149291387570e-05, -8.4983155591709623e-03, + -2.2803131377920161e-04, -2.2803131377920622e-04, 1.9997811123959363e-03, + -6.5369545832163292e-06, 5.3659188242116111e-05, 5.3659188242125605e-05, + 1.5382434574337128e-06, -1.5708705777981867e-03, -4.2150433122697153e-05, + -4.2150433122704234e-05, 1.9997811123959380e-03, -1.2083229378424886e-06, + 5.3659188242120123e-05, 5.3659188242120949e-05, 1.5382434574338455e-06, + 5.3565744035745932e-03, 1.4373044753380644e-04, 1.4373044753380633e-04, + 1.9997811123959493e-03, 4.1203087075293580e-06, 5.3659188242120502e-05, + 5.3659188242116450e-05, 1.5382434574343029e-06, 1.2284019384947355e-02, + 3.2961132819031189e-04, 3.2961132819030463e-04, 1.9997811123959436e-03, + 9.4489403529038885e-06, 5.3659188242125564e-05, 5.3659188242113645e-05, + 1.5382434574343915e-06, 1.9211464366320145e-02, 5.1549220884680247e-04, + 5.1549220884683142e-04, 1.9997811123959662e-03, 1.4777571998274944e-05, + 5.3659188242126635e-05, 5.3659188242104951e-05, 1.5382434574354242e-06, + 2.6138909347692911e-02, 7.0137308950330574e-04, 7.0137308950334932e-04, + 1.9997811123960299e-03, 2.0106203643644923e-05, 5.3659188242122142e-05, + 5.3659188242088599e-05, 1.5382434574373129e-06, 3.3066354329065621e-02, + 8.8725397015985226e-04, 8.8725397015982602e-04, 1.9997811123959944e-03, + 2.5434835289019607e-05, 5.3659188242128064e-05, 5.3659188242090029e-05, + 1.5382434574371947e-06, + + -1.1772420545074049e-02, 9.9965127203158893e-04, -2.9771347337083224e-04, + -4.1374953013227720e-03, 1.5009925916331957e-05, -9.5820722469863165e-04, + -1.4619029680330181e-04, -6.1688324763178938e-06, -8.4328227495495626e-03, + 2.6584360504410145e-04, -2.2754565363904947e-04, 1.9843696720032210e-03, + 6.8173505958705989e-06, -6.2556987501449985e-05, 5.3544905127008731e-05, + -1.6042248447103262e-06, -1.5587645637327799e-03, 4.9139843602173047e-05, + -4.2060661306196192e-05, 1.9843696720032301e-03, 1.2601527202690473e-06, + -6.2556987501449782e-05, 5.3544905127005309e-05, -1.6042248447096918e-06, + 5.3152936220840080e-03, -1.6756391783975450e-04, 1.4342433102665958e-04, + 1.9843696720032410e-03, -4.2970451553338836e-06, -6.2556987501450744e-05, + 5.3544905127002904e-05, -1.6042248447089394e-06, 1.2189351807900777e-02, + -3.8426767928168319e-04, 3.2890932335951224e-04, 1.9843696720032457e-03, + -9.8542430309342842e-06, -6.2556987501449619e-05, 5.3544905127001169e-05, + -1.6042248447085263e-06, 1.9063409993717553e-02, -6.0097144072361120e-04, + 5.1439431569237854e-04, 1.9843696720032670e-03, -1.5411440906539592e-05, + -6.2556987501451611e-05, 5.3544905126996466e-05, -1.6042248447072574e-06, + 2.5937468179534327e-02, -8.1767520216553769e-04, 6.9987930802523882e-04, + 1.9843696720033108e-03, -2.0968638782141884e-05, -6.2556987501459797e-05, + 5.3544905126988287e-05, -1.6042248447047786e-06, 3.2811526365351132e-02, + -1.0343789636074571e-03, 8.8536430035807004e-04, 1.9843696720032926e-03, + -2.6525836657742338e-05, -6.2556987501455094e-05, 5.3544905126988287e-05, + -1.6042248447056049e-06, + + -9.0272890314765722e-03, 5.8525114630483929e-04, -2.2574513915869974e-04, + -4.4933715731932363e-03, 2.6541011214171422e-05, 7.5274196333601873e-04, + -1.5552020407559827e-04, 7.8220800114296213e-07, -6.9204828041277604e-03, + 6.0730626955139981e-04, -1.8789706627799494e-04, 1.6284934001327706e-03, + 1.6073771990022628e-05, -1.4290827386115464e-04, 4.4214997854705820e-05, + -3.7823996304681823e-06, -1.2792161864866225e-03, 1.1225748725241897e-04, + -3.4731820796203245e-05, 1.6284934001327780e-03, 2.9711553210232943e-06, + -1.4290827386115610e-04, 4.4214997854704085e-05, -3.7823996304676809e-06, + 4.3620504311545211e-03, -3.8279129504656216e-04, 1.1843342468558873e-04, + 1.6284934001327851e-03, -1.0131461347976333e-05, -1.4290827386115716e-04, + 4.4214997854703523e-05, -3.7823996304675407e-06, 1.0003317048795649e-02, + -8.7784007734554280e-04, 2.7159867016738124e-04, 1.6284934001327919e-03, + -2.3234078016975833e-05, -1.4290827386115735e-04, 4.4214997854702446e-05, + -3.7823996304672675e-06, 1.5644583666436781e-02, -1.3728888596445214e-03, + 4.2476391564917615e-04, 1.6284934001328049e-03, -3.6336694685976650e-05, + -1.4290827386115966e-04, 4.4214997854700812e-05, -3.7823996304667661e-06, + 2.1285850284077916e-02, -1.8679376419435008e-03, 5.7792916113097177e-04, + 1.6284934001328227e-03, -4.9439311354977518e-05, -1.4290827386116670e-04, + 4.4214997854699179e-05, -3.7823996304657628e-06, 2.6927116901719089e-02, + -2.3629864242424841e-03, 7.3109440661274961e-04, 1.6284934001328183e-03, + -6.2541928023973379e-05, -1.4290827386116294e-04, 4.4214997854697953e-05, + -3.7823996304655858e-06, + + -6.2247900453550730e-03, 1.0327723977360613e-03, -1.3371278969370395e-04, + -2.4924537019540933e-03, 2.6593890523597406e-05, 4.0248850825023367e-04, + -1.3292722975764579e-04, 1.2261851803121024e-05, -4.5637037010479806e-03, + 7.5338078003219552e-04, -1.2532535988959181e-04, 1.0739079292105612e-03, + 2.0052019536976041e-05, -1.7728179706443800e-04, 2.9490936864655919e-05, + -4.7185409457015368e-06, -8.4357750896041491e-04, 1.3925862048674964e-04, + -2.3165757864813873e-05, 1.0739079292105657e-03, 3.7065142258784086e-06, + -1.7728179706443867e-04, 2.9490936864655435e-05, -4.7185409457013454e-06, + 2.8765486831271551e-03, -4.7486353905869716e-04, 7.8993844159963767e-05, + 1.0739079292105696e-03, -1.2638991085219166e-05, -1.7728179706443922e-04, + 2.9490936864655282e-05, -4.7185409457013344e-06, 6.5966748752147126e-03, + -1.0889856986041411e-03, 1.8115344618474199e-04, 1.0739079292105755e-03, + -2.8984496396316930e-05, -1.7728179706443943e-04, 2.9490936864654591e-05, + -4.7185409457010650e-06, 1.0316801067302282e-02, -1.7031078581495856e-03, + 2.8331304820951964e-04, 1.0739079292105826e-03, -4.5330001707415101e-05, + -1.7728179706444065e-04, 2.9490936864654490e-05, -4.7185409457012421e-06, + 1.4036927259389841e-02, -2.3172300176950325e-03, 3.8547265023429852e-04, + 1.0739079292105855e-03, -6.1675507018512700e-05, -1.7728179706444239e-04, + 2.9490936864654900e-05, -4.7185409457009464e-06, 1.7757053451477430e-02, + -2.9313521772404848e-03, 4.8763225225907262e-04, 1.0739079292105883e-03, + -7.8021012329608367e-05, -1.7728179706444209e-04, 2.9490936864654080e-05, + -4.7185409457005339e-06, + + -2.7685660836065627e-03, 9.6267943695907572e-04, -5.1302926806916285e-05, + -1.3595218641067415e-03, 2.0985465997969670e-05, 2.5160999330443233e-04, + -8.5156552130073984e-05, 1.5318561784528383e-05, -2.1160573442293054e-03, + 6.5976850295807366e-04, -5.9827506156292608e-05, 4.9794003061817010e-04, + 1.7763183947286998e-05, -1.5525342423246231e-04, 1.4078309516760695e-05, + -4.1799436025251460e-06, -3.9114247992314439e-04, 1.2195486531873465e-04, + -1.1058811420875967e-05, 4.9794003061817314e-04, 3.2834345625935113e-06, + -1.5525342423246226e-04, 1.4078309516760042e-05, -4.1799436025254264e-06, + 1.3337723843830172e-03, -4.1585877232060533e-04, 3.7709883314540850e-05, + 4.9794003061817682e-04, -1.1196314822099668e-05, -1.5525342423246185e-04, + 1.4078309516759505e-05, -4.1799436025257211e-06, 3.0586872486891748e-03, + -9.5367240995994330e-04, 8.6478578049958005e-05, 4.9794003061818224e-04, + -2.5676064206792951e-05, -1.5525342423246198e-04, 1.4078309516758496e-05, + -4.1799436025261192e-06, 4.7836021129953393e-03, -1.4914860475992832e-03, + 1.3524727278537308e-04, 4.9794003061818745e-04, -4.0155813591486747e-05, + -1.5525342423246160e-04, 1.4078309516757525e-05, -4.1799436025265182e-06, + 6.5085169773014956e-03, -2.0292996852386224e-03, 1.8401596752079196e-04, + 4.9794003061818853e-04, -5.4635562976179490e-05, -1.5525342423246120e-04, + 1.4078309516757781e-05, -4.1799436025266952e-06, 8.2334318416076614e-03, + -2.5671133228779642e-03, 2.3278466225620765e-04, 4.9794003061819168e-04, + -6.9115312360872741e-05, -1.5525342423246101e-04, 1.4078309516756759e-05, + -4.1799436025271077e-06, + + -5.5057819369581863e-04, 3.1787646834022232e-04, -7.4775167389616631e-06, + -4.6186028600569848e-04, 4.3171463021096952e-06, 2.6665516045338905e-04, + -2.9312012410193478e-05, 1.6923298255515372e-05, -4.8665238793613104e-04, + 2.8096888717670101e-04, -1.4530384527701296e-05, 1.1451660589924915e-04, + 8.3891214184953722e-06, -6.6116193242614837e-05, 3.4192174122083424e-06, + -1.9740860933551212e-06, -8.9955228480437954e-05, 5.1935675378195315e-05, + -2.6858679675683887e-06, 1.1451660589925117e-04, 1.5506865940831339e-06, + -6.6116193242615583e-05, 3.4192174122070139e-06, -1.9740860933552669e-06, + 3.0674193097525530e-04, -1.7709753642030946e-04, 9.1586485925635640e-06, + 1.1451660589925462e-04, -5.2877482303300981e-06, -6.6116193242616098e-05, + 3.4192174122056849e-06, -1.9740860933554109e-06, 7.0343909043094825e-04, + -4.0613074821881383e-04, 2.1003165152696916e-05, 1.1451660589925732e-04, + -1.2126183054742609e-05, -6.6116193242617480e-05, 3.4192174122050653e-06, + -1.9740860933548040e-06, 1.1001362498866394e-03, -6.3516396001732215e-04, + 3.2847681712829456e-05, 1.1451660589926117e-04, -1.8964617879153966e-05, + -6.6116193242618767e-05, 3.4192174122030078e-06, -1.9740860933549811e-06, + 1.4968334093423308e-03, -8.6419717181582527e-04, 4.4692198272961002e-05, + 1.1451660589926484e-04, -2.5803052703569116e-05, -6.6116193242617331e-05, + 3.4192174122015514e-06, -1.9740860933558666e-06, 1.8935305687980254e-03, + -1.0932303836143303e-03, 5.6536714833096980e-05, 1.1451660589926414e-04, + -3.2641487527979211e-05, -6.6116193242619960e-05, 3.4192174122038129e-06, + -1.9740860933535500e-06 }; return sol; } -static const double * -get_sol_3x_biasB_p1_DxDx_PyPy(void) +static const double *get_sol_3x_biasB_p1_DxDx_PyPy(void) { static const double sol[512] = { - -4.4584195633810733e-02, -2.5740697350783534e-02, -2.5740697350783579e-02, -1.8124746495123774e-03, - -1.4861398544603536e-02, -1.0464327267955061e-03, -1.0464327267952910e-03, -6.0415821650423960e-04, - -2.7172476676301741e-02, -1.5688036723611624e-02, -1.5688036723611940e-02, 6.3940913062058213e-03, - -9.0574922254338681e-03, 3.6916303368608886e-03, 3.6916303368611492e-03, 2.1313637687352016e-03, - -5.0226946551364480e-03, -2.8998541112002685e-03, -2.8998541112003865e-03, 6.3940913062057042e-03, - -1.6742315517121146e-03, 3.6916303368608925e-03, 3.6916303368609532e-03, 2.1313637687352198e-03, - 1.7127087366028894e-02, 9.8883285012110831e-03, 9.8883285012111924e-03, 6.3940913062055550e-03, - 5.7090291220096342e-03, 3.6916303368608968e-03, 3.6916303368608166e-03, 2.1313637687352294e-03, - 3.9276869387194165e-02, 2.2676511113622431e-02, 2.2676511113622465e-02, 6.3940913062055810e-03, - 1.3092289795731417e-02, 3.6916303368608795e-03, 3.6916303368607927e-03, 2.1313637687352285e-03, - 6.1426651408359283e-02, 3.5464693726033808e-02, 3.5464693726033690e-02, 6.3940913062052454e-03, - 2.0475550469453228e-02, 3.6916303368609051e-03, 3.6916303368603937e-03, 2.1313637687352597e-03, - 8.3576433429524880e-02, 4.8252876338445126e-02, 4.8252876338445223e-02, 6.3940913062050780e-03, - 2.7858811143174983e-02, 3.6916303368609116e-03, 3.6916303368605278e-03, 2.1313637687352407e-03, - 1.0572621545068980e-01, 6.1041058950856514e-02, 6.1041058950856819e-02, 6.3940913062048828e-03, - 3.5242071816896710e-02, 3.6916303368609302e-03, 3.6916303368602554e-03, 2.1313637687352754e-03, - - -1.1102433537931264e-01, -1.2618535216278336e-02, -6.4099929917845411e-02, -8.9682417343014686e-03, - -7.2853147038970641e-03, -3.0849513258657400e-03, -5.1778167794565748e-03, -1.7810974784254808e-03, - -6.9196949126305612e-02, -8.5748037579501200e-03, -3.9950877205173575e-02, 1.6283079974463717e-02, - -4.9506652579006920e-03, 2.0177799327709633e-03, 9.4010406064929421e-03, 1.1649657873507272e-03, - -1.2790705487349173e-02, -1.5850090338456765e-03, -7.3847172562463191e-03, 1.6283079974463602e-02, - -9.1510539235878645e-04, 2.0177799327709620e-03, 9.4010406064927929e-03, 1.1649657873507361e-03, - 4.3615538151607305e-02, 5.4047856902587656e-03, 2.5181442692680946e-02, 1.6283079974463464e-02, - 3.1204544731831146e-03, 2.0177799327709646e-03, 9.4010406064926819e-03, 1.1649657873507419e-03, - 1.0002178179056370e-01, 1.2394580414363204e-02, 5.7747602641608005e-02, 1.6283079974463429e-02, - 7.1560143387250389e-03, 2.0177799327709498e-03, 9.4010406064926472e-03, 1.1649657873507367e-03, - 1.5642802542952000e-01, 1.9384375138467660e-02, 9.0313762590535099e-02, 1.6283079974463169e-02, - 1.1191574204266976e-02, 2.0177799327709732e-03, 9.4010406064923436e-03, 1.1649657873507619e-03, - 2.1283426906847663e-01, 2.6374169862572072e-02, 1.2287992253946231e-01, 1.6283079974463037e-02, - 1.5227134069808879e-02, 2.0177799327709767e-03, 9.4010406064924355e-03, 1.1649657873507486e-03, - 2.6924051270743282e-01, 3.3363964586676544e-02, 1.5544608248838956e-01, 1.6283079974462881e-02, - 1.9262693935350784e-02, 2.0177799327709745e-03, 9.4010406064922517e-03, 1.1649657873507658e-03, - - -1.3411820617565154e-01, -7.1471730461837319e-04, -7.7433182438742088e-02, -2.3541399004220864e-02, - -4.1264222821590300e-04, -5.3288649468649753e-03, -1.3591633052187288e-02, -3.0766216115476501e-03, - -8.7959388364324778e-02, -2.2576955867742456e-03, -5.0783376549897868e-02, 2.0698163334151001e-02, - -1.3034811547723213e-03, 5.3126963343912994e-04, 1.1950090172702994e-02, 3.0672866587834431e-04, - -1.6258847328107777e-02, -4.1732359150410962e-04, -9.3870498815960927e-03, 2.0698163334150890e-02, - -2.4094188789407537e-04, 5.3126963343912972e-04, 1.1950090172702871e-02, 3.0672866587835244e-04, - 5.5441693708109245e-02, 1.4230484037660233e-03, 3.2009276786705683e-02, 2.0698163334150758e-02, - 8.2159737898417041e-04, 5.3126963343913048e-04, 1.1950090172702781e-02, 3.0672866587835640e-04, - 1.2714223474432620e-01, 3.2634203990361591e-03, 7.3405603455007323e-02, 2.0698163334150685e-02, - 1.8841366458624319e-03, 5.3126963343912452e-04, 1.1950090172702732e-02, 3.0672866587835499e-04, - 1.9884277578054310e-01, 5.1037923943063040e-03, 1.1480193012330903e-01, 2.0698163334150494e-02, - 2.9466759127406974e-03, 5.3126963343914316e-04, 1.1950090172702516e-02, 3.0672866587837911e-04, - 2.7054331681676019e-01, 6.9441643895764137e-03, 1.5619825679161076e-01, 2.0698163334150376e-02, - 4.0092151796189430e-03, 5.3126963343914295e-04, 1.1950090172702569e-02, 3.0672866587836512e-04, - 3.4224385785297706e-01, 8.7845363848465582e-03, 1.9759458345991249e-01, 2.0698163334150217e-02, - 5.0717544464971807e-03, 5.3126963343913763e-04, 1.1950090172702404e-02, 3.0672866587837380e-04, - - -1.1928578703942408e-01, 9.2782184856526548e-03, -6.8869681257707843e-02, -4.6181363305459550e-02, - 5.3567819402917122e-03, -7.7423245368986879e-03, -2.6662822535950936e-02, -4.4700331555318972e-03, - -8.6910597817874607e-02, 2.8632150910907813e-03, -5.0177857045581288e-02, 2.0451367188368066e-02, - 1.6530780035890727e-03, -6.7375745464186710e-04, 1.1807602351500225e-02, -3.8899404780600724e-04, - -1.6064983708874006e-02, 5.2925080425480250e-04, -9.2751226688453908e-03, 2.0451367188367962e-02, - 3.0556309430533808e-04, -6.7375745464186331e-04, 1.1807602351500130e-02, -3.8899404780599808e-04, - 5.4780630400126623e-02, -1.8047134825811763e-03, 3.1627611707890503e-02, 2.0451367188367844e-02, - -1.0419518149783942e-03, -6.7375745464185745e-04, 1.1807602351500053e-02, -3.8899404780599412e-04, - 1.2562624450912718e-01, -4.1386777694171518e-03, 7.2530346084626315e-02, 2.0451367188367760e-02, - -2.3894667242621149e-03, -6.7375745464186157e-04, 1.1807602351499998e-02, -3.8899404780599623e-04, - 1.9647185861812774e-01, -6.4726420562531166e-03, 1.1343308046136219e-01, 2.0451367188367618e-02, - -3.7369816335458337e-03, -6.7375745464185604e-04, 1.1807602351499856e-02, -3.8899404780597677e-04, - 2.6731747272712841e-01, -8.8066063430890917e-03, 1.5433581483809802e-01, 2.0451367188367504e-02, - -5.0844965428295582e-03, -6.7375745464184748e-04, 1.1807602351499857e-02, -3.8899404780599114e-04, - 3.3816308683612889e-01, -1.1140570629925068e-02, 1.9523854921483388e-01, 2.0451367188367358e-02, - -6.4320114521133013e-03, -6.7375745464184401e-04, 1.1807602351499738e-02, -3.8899404780597807e-04, - - -9.0256922639355669e-02, 7.4816041899959870e-03, -5.2109858582059222e-02, -4.9944638029515029e-02, - 4.3195061930644124e-03, 5.5695968619307399e-03, -2.8835550210918881e-02, 3.2156082475134026e-03, - -7.0918099467613696e-02, 6.3700581364470044e-03, -4.0944583818043473e-02, 1.6688092464312621e-02, - 3.6777547798312509e-03, -1.4989702203260580e-03, 9.6348746765322780e-03, -8.6543086021248668e-04, - -1.3108851408420578e-02, 1.1774729751721309e-03, -7.5683988894184482e-03, 1.6688092464312531e-02, - 6.7981433917914131e-04, -1.4989702203260537e-03, 9.6348746765322121e-03, -8.6543086021248039e-04, - 4.4700396650772564e-02, -4.0151121861027438e-03, 2.5807786039206568e-02, 1.6688092464312434e-02, - -2.3181261014729678e-03, -1.4989702203260457e-03, 9.6348746765321479e-03, -8.6543086021247551e-04, - 1.0250964470996564e-01, -9.2076973473776153e-03, 5.9183970967831553e-02, 1.6688092464312344e-02, - -5.3160665421250692e-03, -1.4989702203260431e-03, 9.6348746765320993e-03, -8.6543086021247031e-04, - 1.6031889276915876e-01, -1.4400282508652482e-02, 9.2560155896456567e-02, 1.6688092464312219e-02, - -8.3140069827771709e-03, -1.4989702203260405e-03, 9.6348746765320039e-03, -8.6543086021246185e-04, - 2.1812814082835194e-01, -1.9592867669927353e-02, 1.2593634082508157e-01, 1.6688092464312139e-02, - -1.1311947423429281e-02, -1.4989702203260298e-03, 9.6348746765319727e-03, -8.6543086021246326e-04, - 2.7593738888754493e-01, -2.4785452831202218e-02, 1.5931252575370652e-01, 1.6688092464312014e-02, - -1.4309887864081385e-02, -1.4989702203260164e-03, 9.6348746765319068e-03, -8.6543086021245220e-04, - - -5.8558107995076741e-02, 1.0819714977870510e-02, -3.3808539414192727e-02, -3.3336939184891466e-02, - 6.2467653550285626e-03, 4.0188625366329098e-03, -1.9247090812355247e-02, 2.3202913673611098e-03, - -4.6332036744757193e-02, 7.8247117949072180e-03, -2.6749813886689226e-02, 1.0902623153480511e-02, - 4.5175994611209259e-03, -1.8412720436711764e-03, 6.2946324125350284e-03, -1.0630589100648897e-03, - -8.5642422695474067e-03, 1.4463583345179297e-03, -4.9445675797283829e-03, 1.0902623153480446e-02, - 8.3505537377858677e-04, -1.8412720436711710e-03, 6.2946324125349841e-03, -1.0630589100648835e-03, - 2.9203552205662404e-02, -4.9319951258713617e-03, 1.6860678727232462e-02, 1.0902623153480373e-02, - -2.8474887135637528e-03, -1.8412720436711636e-03, 6.2946324125349408e-03, -1.0630589100648780e-03, - 6.6971346680872179e-02, -1.1310348586260647e-02, 3.8665925034193284e-02, 1.0902623153480289e-02, - -6.5300328009060870e-03, -1.8412720436711597e-03, 6.2946324125349000e-03, -1.0630589100648752e-03, - 1.0473914115608197e-01, -1.7688702046649935e-02, 6.0471171341154130e-02, 1.0902623153480199e-02, - -1.0212576888248429e-02, -1.8412720436711517e-03, 6.2946324125348506e-03, -1.0630589100648624e-03, - 1.4250693563129183e-01, -2.4067055507039227e-02, 8.2276417648114969e-02, 1.0902623153480149e-02, - -1.3895120975590763e-02, -1.8412720436711443e-03, 6.2946324125348081e-03, -1.0630589100648648e-03, - 1.8027473010650152e-01, -3.0445408967428502e-02, 1.0408166395507577e-01, 1.0902623153480041e-02, - -1.7577665062933099e-02, -1.8412720436711389e-03, 6.2946324125347829e-03, -1.0630589100648566e-03, - - -2.3652444410766166e-02, 9.3330792887737161e-03, -1.3655745147548512e-02, -2.0295051641274243e-02, - 5.3884558397416238e-03, 3.5108747474153165e-03, -1.1717353528307028e-02, 2.0270044805112890e-03, - -2.1062278650861084e-02, 6.7647898429604248e-03, -1.2160312248821570e-02, 4.9562700674910870e-03, - 3.9056532368444519e-03, -1.5918565112213788e-03, 2.8615038576424623e-03, -9.1905878526492464e-04, - -3.8932555050065249e-03, 1.2504371313709281e-03, -2.2477721138395197e-03, 4.9562700674910401e-03, - 7.2194021440171005e-04, -1.5918565112213727e-03, 2.8615038576424393e-03, -9.1905878526491835e-04, - 1.3275767640848053e-02, -4.2639155802185694e-03, 7.6647680211425293e-03, 4.9562700674909976e-03, - -2.4617728080410309e-03, -1.5918565112213643e-03, 2.8615038576424133e-03, -9.1905878526491358e-04, - 3.0444790786702609e-02, -9.7782682918080652e-03, 1.7577308156124568e-02, 4.9562700674909361e-03, - -5.6454858304837699e-03, -1.5918565112213565e-03, 2.8615038576423899e-03, -9.1905878526490664e-04, - 4.7613813932557182e-02, -1.5292621003397559e-02, 2.7489848291106629e-02, 4.9562700674908727e-03, - -8.8291988529265123e-03, -1.5918565112213502e-03, 2.8615038576423760e-03, -9.1905878526489938e-04, - 6.4782837078411787e-02, -2.0806973714987066e-02, 3.7402388426088666e-02, 4.9562700674908502e-03, - -1.2012911875369252e-02, -1.5918565112213396e-03, 2.8615038576423270e-03, -9.1905878526489797e-04, - 8.1951860224266287e-02, -2.6321326426576551e-02, 4.7314928561070724e-02, 4.9562700674907565e-03, - -1.5196624897811980e-02, -1.5918565112213333e-03, 2.8615038576423326e-03, -9.1905878526488875e-04, - - -3.7435384457706450e-03, 2.1613329293873962e-03, -2.1613329293874040e-03, -7.1070190998701816e-03, - 1.2478461485902145e-03, 4.1032393904458621e-03, -4.1032393904458613e-03, 2.3690063666233913e-03, - -4.6726594701638740e-03, 2.6977612029305646e-03, -2.6977612029305677e-03, 1.0995468558481671e-03, - 1.5575531567212943e-03, -6.3482367321053882e-04, 6.3482367321053459e-04, -3.6651561861605436e-04, - -8.6371743090069562e-04, 4.9866749123429245e-04, -4.9866749123429516e-04, 1.0995468558481431e-03, - 2.8790581030023514e-04, -6.3482367321053210e-04, 6.3482367321053307e-04, -3.6651561861604824e-04, - 2.9452246083624873e-03, -1.7004262204619832e-03, 1.7004262204619765e-03, 1.0995468558481299e-03, - -9.8174153612082390e-04, -6.3482367321052331e-04, 6.3482367321052440e-04, -3.6651561861604314e-04, - 6.7541666476256586e-03, -3.8995199321582566e-03, 3.8995199321582427e-03, 1.0995468558480971e-03, - -2.2513888825418833e-03, -6.3482367321051475e-04, 6.3482367321052418e-04, -3.6651561861603663e-04, - 1.0563108686888851e-02, -6.0986136438545271e-03, 6.0986136438545184e-03, 1.0995468558480518e-03, - -3.5210362289629427e-03, -6.3482367321051041e-04, 6.3482367321053936e-04, -3.6651561861602774e-04, - 1.4372050726152056e-02, -8.2977073555508037e-03, 8.2977073555507794e-03, 1.0995468558480691e-03, - -4.7906835753840022e-03, -6.3482367321049816e-04, 6.3482367321049653e-04, -3.6651561861602606e-04, - 1.8180992765415183e-02, -1.0496801067247074e-02, 1.0496801067247093e-02, 1.0995468558479870e-03, - -6.0603309218050499e-03, -6.3482367321049653e-04, 6.3482367321053340e-04, -3.6651561861601522e-04, + -4.4584195633810733e-02, -2.5740697350783534e-02, -2.5740697350783579e-02, + -1.8124746495123774e-03, -1.4861398544603536e-02, -1.0464327267955061e-03, + -1.0464327267952910e-03, -6.0415821650423960e-04, -2.7172476676301741e-02, + -1.5688036723611624e-02, -1.5688036723611940e-02, 6.3940913062058213e-03, + -9.0574922254338681e-03, 3.6916303368608886e-03, 3.6916303368611492e-03, + 2.1313637687352016e-03, -5.0226946551364480e-03, -2.8998541112002685e-03, + -2.8998541112003865e-03, 6.3940913062057042e-03, -1.6742315517121146e-03, + 3.6916303368608925e-03, 3.6916303368609532e-03, 2.1313637687352198e-03, + 1.7127087366028894e-02, 9.8883285012110831e-03, 9.8883285012111924e-03, + 6.3940913062055550e-03, 5.7090291220096342e-03, 3.6916303368608968e-03, + 3.6916303368608166e-03, 2.1313637687352294e-03, 3.9276869387194165e-02, + 2.2676511113622431e-02, 2.2676511113622465e-02, 6.3940913062055810e-03, + 1.3092289795731417e-02, 3.6916303368608795e-03, 3.6916303368607927e-03, + 2.1313637687352285e-03, 6.1426651408359283e-02, 3.5464693726033808e-02, + 3.5464693726033690e-02, 6.3940913062052454e-03, 2.0475550469453228e-02, + 3.6916303368609051e-03, 3.6916303368603937e-03, 2.1313637687352597e-03, + 8.3576433429524880e-02, 4.8252876338445126e-02, 4.8252876338445223e-02, + 6.3940913062050780e-03, 2.7858811143174983e-02, 3.6916303368609116e-03, + 3.6916303368605278e-03, 2.1313637687352407e-03, 1.0572621545068980e-01, + 6.1041058950856514e-02, 6.1041058950856819e-02, 6.3940913062048828e-03, + 3.5242071816896710e-02, 3.6916303368609302e-03, 3.6916303368602554e-03, + 2.1313637687352754e-03, + + -1.1102433537931264e-01, -1.2618535216278336e-02, -6.4099929917845411e-02, + -8.9682417343014686e-03, -7.2853147038970641e-03, -3.0849513258657400e-03, + -5.1778167794565748e-03, -1.7810974784254808e-03, -6.9196949126305612e-02, + -8.5748037579501200e-03, -3.9950877205173575e-02, 1.6283079974463717e-02, + -4.9506652579006920e-03, 2.0177799327709633e-03, 9.4010406064929421e-03, + 1.1649657873507272e-03, -1.2790705487349173e-02, -1.5850090338456765e-03, + -7.3847172562463191e-03, 1.6283079974463602e-02, -9.1510539235878645e-04, + 2.0177799327709620e-03, 9.4010406064927929e-03, 1.1649657873507361e-03, + 4.3615538151607305e-02, 5.4047856902587656e-03, 2.5181442692680946e-02, + 1.6283079974463464e-02, 3.1204544731831146e-03, 2.0177799327709646e-03, + 9.4010406064926819e-03, 1.1649657873507419e-03, 1.0002178179056370e-01, + 1.2394580414363204e-02, 5.7747602641608005e-02, 1.6283079974463429e-02, + 7.1560143387250389e-03, 2.0177799327709498e-03, 9.4010406064926472e-03, + 1.1649657873507367e-03, 1.5642802542952000e-01, 1.9384375138467660e-02, + 9.0313762590535099e-02, 1.6283079974463169e-02, 1.1191574204266976e-02, + 2.0177799327709732e-03, 9.4010406064923436e-03, 1.1649657873507619e-03, + 2.1283426906847663e-01, 2.6374169862572072e-02, 1.2287992253946231e-01, + 1.6283079974463037e-02, 1.5227134069808879e-02, 2.0177799327709767e-03, + 9.4010406064924355e-03, 1.1649657873507486e-03, 2.6924051270743282e-01, + 3.3363964586676544e-02, 1.5544608248838956e-01, 1.6283079974462881e-02, + 1.9262693935350784e-02, 2.0177799327709745e-03, 9.4010406064922517e-03, + 1.1649657873507658e-03, + + -1.3411820617565154e-01, -7.1471730461837319e-04, -7.7433182438742088e-02, + -2.3541399004220864e-02, -4.1264222821590300e-04, -5.3288649468649753e-03, + -1.3591633052187288e-02, -3.0766216115476501e-03, -8.7959388364324778e-02, + -2.2576955867742456e-03, -5.0783376549897868e-02, 2.0698163334151001e-02, + -1.3034811547723213e-03, 5.3126963343912994e-04, 1.1950090172702994e-02, + 3.0672866587834431e-04, -1.6258847328107777e-02, -4.1732359150410962e-04, + -9.3870498815960927e-03, 2.0698163334150890e-02, -2.4094188789407537e-04, + 5.3126963343912972e-04, 1.1950090172702871e-02, 3.0672866587835244e-04, + 5.5441693708109245e-02, 1.4230484037660233e-03, 3.2009276786705683e-02, + 2.0698163334150758e-02, 8.2159737898417041e-04, 5.3126963343913048e-04, + 1.1950090172702781e-02, 3.0672866587835640e-04, 1.2714223474432620e-01, + 3.2634203990361591e-03, 7.3405603455007323e-02, 2.0698163334150685e-02, + 1.8841366458624319e-03, 5.3126963343912452e-04, 1.1950090172702732e-02, + 3.0672866587835499e-04, 1.9884277578054310e-01, 5.1037923943063040e-03, + 1.1480193012330903e-01, 2.0698163334150494e-02, 2.9466759127406974e-03, + 5.3126963343914316e-04, 1.1950090172702516e-02, 3.0672866587837911e-04, + 2.7054331681676019e-01, 6.9441643895764137e-03, 1.5619825679161076e-01, + 2.0698163334150376e-02, 4.0092151796189430e-03, 5.3126963343914295e-04, + 1.1950090172702569e-02, 3.0672866587836512e-04, 3.4224385785297706e-01, + 8.7845363848465582e-03, 1.9759458345991249e-01, 2.0698163334150217e-02, + 5.0717544464971807e-03, 5.3126963343913763e-04, 1.1950090172702404e-02, + 3.0672866587837380e-04, + + -1.1928578703942408e-01, 9.2782184856526548e-03, -6.8869681257707843e-02, + -4.6181363305459550e-02, 5.3567819402917122e-03, -7.7423245368986879e-03, + -2.6662822535950936e-02, -4.4700331555318972e-03, -8.6910597817874607e-02, + 2.8632150910907813e-03, -5.0177857045581288e-02, 2.0451367188368066e-02, + 1.6530780035890727e-03, -6.7375745464186710e-04, 1.1807602351500225e-02, + -3.8899404780600724e-04, -1.6064983708874006e-02, 5.2925080425480250e-04, + -9.2751226688453908e-03, 2.0451367188367962e-02, 3.0556309430533808e-04, + -6.7375745464186331e-04, 1.1807602351500130e-02, -3.8899404780599808e-04, + 5.4780630400126623e-02, -1.8047134825811763e-03, 3.1627611707890503e-02, + 2.0451367188367844e-02, -1.0419518149783942e-03, -6.7375745464185745e-04, + 1.1807602351500053e-02, -3.8899404780599412e-04, 1.2562624450912718e-01, + -4.1386777694171518e-03, 7.2530346084626315e-02, 2.0451367188367760e-02, + -2.3894667242621149e-03, -6.7375745464186157e-04, 1.1807602351499998e-02, + -3.8899404780599623e-04, 1.9647185861812774e-01, -6.4726420562531166e-03, + 1.1343308046136219e-01, 2.0451367188367618e-02, -3.7369816335458337e-03, + -6.7375745464185604e-04, 1.1807602351499856e-02, -3.8899404780597677e-04, + 2.6731747272712841e-01, -8.8066063430890917e-03, 1.5433581483809802e-01, + 2.0451367188367504e-02, -5.0844965428295582e-03, -6.7375745464184748e-04, + 1.1807602351499857e-02, -3.8899404780599114e-04, 3.3816308683612889e-01, + -1.1140570629925068e-02, 1.9523854921483388e-01, 2.0451367188367358e-02, + -6.4320114521133013e-03, -6.7375745464184401e-04, 1.1807602351499738e-02, + -3.8899404780597807e-04, + + -9.0256922639355669e-02, 7.4816041899959870e-03, -5.2109858582059222e-02, + -4.9944638029515029e-02, 4.3195061930644124e-03, 5.5695968619307399e-03, + -2.8835550210918881e-02, 3.2156082475134026e-03, -7.0918099467613696e-02, + 6.3700581364470044e-03, -4.0944583818043473e-02, 1.6688092464312621e-02, + 3.6777547798312509e-03, -1.4989702203260580e-03, 9.6348746765322780e-03, + -8.6543086021248668e-04, -1.3108851408420578e-02, 1.1774729751721309e-03, + -7.5683988894184482e-03, 1.6688092464312531e-02, 6.7981433917914131e-04, + -1.4989702203260537e-03, 9.6348746765322121e-03, -8.6543086021248039e-04, + 4.4700396650772564e-02, -4.0151121861027438e-03, 2.5807786039206568e-02, + 1.6688092464312434e-02, -2.3181261014729678e-03, -1.4989702203260457e-03, + 9.6348746765321479e-03, -8.6543086021247551e-04, 1.0250964470996564e-01, + -9.2076973473776153e-03, 5.9183970967831553e-02, 1.6688092464312344e-02, + -5.3160665421250692e-03, -1.4989702203260431e-03, 9.6348746765320993e-03, + -8.6543086021247031e-04, 1.6031889276915876e-01, -1.4400282508652482e-02, + 9.2560155896456567e-02, 1.6688092464312219e-02, -8.3140069827771709e-03, + -1.4989702203260405e-03, 9.6348746765320039e-03, -8.6543086021246185e-04, + 2.1812814082835194e-01, -1.9592867669927353e-02, 1.2593634082508157e-01, + 1.6688092464312139e-02, -1.1311947423429281e-02, -1.4989702203260298e-03, + 9.6348746765319727e-03, -8.6543086021246326e-04, 2.7593738888754493e-01, + -2.4785452831202218e-02, 1.5931252575370652e-01, 1.6688092464312014e-02, + -1.4309887864081385e-02, -1.4989702203260164e-03, 9.6348746765319068e-03, + -8.6543086021245220e-04, + + -5.8558107995076741e-02, 1.0819714977870510e-02, -3.3808539414192727e-02, + -3.3336939184891466e-02, 6.2467653550285626e-03, 4.0188625366329098e-03, + -1.9247090812355247e-02, 2.3202913673611098e-03, -4.6332036744757193e-02, + 7.8247117949072180e-03, -2.6749813886689226e-02, 1.0902623153480511e-02, + 4.5175994611209259e-03, -1.8412720436711764e-03, 6.2946324125350284e-03, + -1.0630589100648897e-03, -8.5642422695474067e-03, 1.4463583345179297e-03, + -4.9445675797283829e-03, 1.0902623153480446e-02, 8.3505537377858677e-04, + -1.8412720436711710e-03, 6.2946324125349841e-03, -1.0630589100648835e-03, + 2.9203552205662404e-02, -4.9319951258713617e-03, 1.6860678727232462e-02, + 1.0902623153480373e-02, -2.8474887135637528e-03, -1.8412720436711636e-03, + 6.2946324125349408e-03, -1.0630589100648780e-03, 6.6971346680872179e-02, + -1.1310348586260647e-02, 3.8665925034193284e-02, 1.0902623153480289e-02, + -6.5300328009060870e-03, -1.8412720436711597e-03, 6.2946324125349000e-03, + -1.0630589100648752e-03, 1.0473914115608197e-01, -1.7688702046649935e-02, + 6.0471171341154130e-02, 1.0902623153480199e-02, -1.0212576888248429e-02, + -1.8412720436711517e-03, 6.2946324125348506e-03, -1.0630589100648624e-03, + 1.4250693563129183e-01, -2.4067055507039227e-02, 8.2276417648114969e-02, + 1.0902623153480149e-02, -1.3895120975590763e-02, -1.8412720436711443e-03, + 6.2946324125348081e-03, -1.0630589100648648e-03, 1.8027473010650152e-01, + -3.0445408967428502e-02, 1.0408166395507577e-01, 1.0902623153480041e-02, + -1.7577665062933099e-02, -1.8412720436711389e-03, 6.2946324125347829e-03, + -1.0630589100648566e-03, + + -2.3652444410766166e-02, 9.3330792887737161e-03, -1.3655745147548512e-02, + -2.0295051641274243e-02, 5.3884558397416238e-03, 3.5108747474153165e-03, + -1.1717353528307028e-02, 2.0270044805112890e-03, -2.1062278650861084e-02, + 6.7647898429604248e-03, -1.2160312248821570e-02, 4.9562700674910870e-03, + 3.9056532368444519e-03, -1.5918565112213788e-03, 2.8615038576424623e-03, + -9.1905878526492464e-04, -3.8932555050065249e-03, 1.2504371313709281e-03, + -2.2477721138395197e-03, 4.9562700674910401e-03, 7.2194021440171005e-04, + -1.5918565112213727e-03, 2.8615038576424393e-03, -9.1905878526491835e-04, + 1.3275767640848053e-02, -4.2639155802185694e-03, 7.6647680211425293e-03, + 4.9562700674909976e-03, -2.4617728080410309e-03, -1.5918565112213643e-03, + 2.8615038576424133e-03, -9.1905878526491358e-04, 3.0444790786702609e-02, + -9.7782682918080652e-03, 1.7577308156124568e-02, 4.9562700674909361e-03, + -5.6454858304837699e-03, -1.5918565112213565e-03, 2.8615038576423899e-03, + -9.1905878526490664e-04, 4.7613813932557182e-02, -1.5292621003397559e-02, + 2.7489848291106629e-02, 4.9562700674908727e-03, -8.8291988529265123e-03, + -1.5918565112213502e-03, 2.8615038576423760e-03, -9.1905878526489938e-04, + 6.4782837078411787e-02, -2.0806973714987066e-02, 3.7402388426088666e-02, + 4.9562700674908502e-03, -1.2012911875369252e-02, -1.5918565112213396e-03, + 2.8615038576423270e-03, -9.1905878526489797e-04, 8.1951860224266287e-02, + -2.6321326426576551e-02, 4.7314928561070724e-02, 4.9562700674907565e-03, + -1.5196624897811980e-02, -1.5918565112213333e-03, 2.8615038576423326e-03, + -9.1905878526488875e-04, + + -3.7435384457706450e-03, 2.1613329293873962e-03, -2.1613329293874040e-03, + -7.1070190998701816e-03, 1.2478461485902145e-03, 4.1032393904458621e-03, + -4.1032393904458613e-03, 2.3690063666233913e-03, -4.6726594701638740e-03, + 2.6977612029305646e-03, -2.6977612029305677e-03, 1.0995468558481671e-03, + 1.5575531567212943e-03, -6.3482367321053882e-04, 6.3482367321053459e-04, + -3.6651561861605436e-04, -8.6371743090069562e-04, 4.9866749123429245e-04, + -4.9866749123429516e-04, 1.0995468558481431e-03, 2.8790581030023514e-04, + -6.3482367321053210e-04, 6.3482367321053307e-04, -3.6651561861604824e-04, + 2.9452246083624873e-03, -1.7004262204619832e-03, 1.7004262204619765e-03, + 1.0995468558481299e-03, -9.8174153612082390e-04, -6.3482367321052331e-04, + 6.3482367321052440e-04, -3.6651561861604314e-04, 6.7541666476256586e-03, + -3.8995199321582566e-03, 3.8995199321582427e-03, 1.0995468558480971e-03, + -2.2513888825418833e-03, -6.3482367321051475e-04, 6.3482367321052418e-04, + -3.6651561861603663e-04, 1.0563108686888851e-02, -6.0986136438545271e-03, + 6.0986136438545184e-03, 1.0995468558480518e-03, -3.5210362289629427e-03, + -6.3482367321051041e-04, 6.3482367321053936e-04, -3.6651561861602774e-04, + 1.4372050726152056e-02, -8.2977073555508037e-03, 8.2977073555507794e-03, + 1.0995468558480691e-03, -4.7906835753840022e-03, -6.3482367321049816e-04, + 6.3482367321049653e-04, -3.6651561861602606e-04, 1.8180992765415183e-02, + -1.0496801067247074e-02, 1.0496801067247093e-02, 1.0995468558479870e-03, + -6.0603309218050499e-03, -6.3482367321049653e-04, 6.3482367321053340e-04, + -3.6651561861601522e-04 }; return sol; } - diff --git a/gyrokinetic/unit/ctest_fem_poisson_perp_ksq.c b/gyrokinetic/unit/ctest_fem_poisson_perp_ksq.c index 41fbac70f0..4469b15859 100644 --- a/gyrokinetic/unit/ctest_fem_poisson_perp_ksq.c +++ b/gyrokinetic/unit/ctest_fem_poisson_perp_ksq.c @@ -25,8 +25,10 @@ #include #include -static double error_L2norm(struct gkyl_rect_grid grid, struct gkyl_range range, - struct gkyl_basis basis, struct gkyl_array* field1, struct gkyl_array* field2) +static double error_L2norm( + struct gkyl_rect_grid grid, struct gkyl_range range, struct gkyl_basis basis, + struct gkyl_array *field1, struct gkyl_array *field2 +) { // Compute the L2 norm of the difference between 2 fields. assert(field1->ncomp == field2->ncomp); @@ -48,8 +50,10 @@ static double error_L2norm(struct gkyl_rect_grid grid, struct gkyl_range range, return sqrt(l2[0]); } -static double field_L2norm(struct gkyl_rect_grid grid, struct gkyl_range range, - struct gkyl_basis basis, struct gkyl_array *field) +static double field_L2norm( + struct gkyl_rect_grid grid, struct gkyl_range range, struct gkyl_basis basis, + struct gkyl_array *field +) { // Compute the L2 norm of a single field. struct gkyl_array *l2_cell = gkyl_array_new(GKYL_DOUBLE, 1, field->size); @@ -62,135 +66,155 @@ static double field_L2norm(struct gkyl_rect_grid grid, struct gkyl_range range, } // Return true when the TEST_OUTPUT env var is set (enables results file writing). -static bool helmholtz_write_output(void) { return getenv("TEST_OUTPUT") != NULL; } +static bool helmholtz_write_output(void) +{ + return getenv("TEST_OUTPUT") != NULL; +} // Return true when the HELMHOLTZ_VERBOSE env var is set (enables extra printf output). -static bool helmholtz_verbose(void) { return getenv("HELMHOLTZ_VERBOSE") != NULL; } +static bool helmholtz_verbose(void) +{ + return getenv("HELMHOLTZ_VERBOSE") != NULL; +} -static struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { // allocate array (filled with zeros) - struct gkyl_array* a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } // We want to test the solution to the Helmholtz equation: -d^2(phi)/dx^2 - kSq*phi = rho -static double ksquare() { return 20.0; } // To get kSq everywhere in one place for easy editing. -static double x_dirichletbc_lo() { return 0.0; } // to set BC values in one place for easy editing. -static double x_dirichletbc_up() { return 0.5; } // Only effective for 2x problem. -static double ksq_factor() { return 3.0; } // To set the factor we introduce on kSq for testing, in one place for easy editing. -static double eps_factor() { return 4.0; } // To set the factor we introduce on epsilon for testing, in one place for easy editing. +static double ksquare() +{ + return 20.0; +} // To get kSq everywhere in one place for easy editing. +static double x_dirichletbc_lo() +{ + return 0.0; +} // to set BC values in one place for easy editing. +static double x_dirichletbc_up() +{ + return 0.5; +} // Only effective for 2x problem. +static double ksq_factor() +{ + return 3.0; +} // To set the factor we introduce on kSq for testing, in one place for easy editing. +static double eps_factor() +{ + return 4.0; +} // To set the factor we introduce on epsilon for testing, in one place for easy editing. static double p1_func(double x) { // This is a linear polynomial that is compatible with the BCs above. (assumes domain is [0,1]) - double a = -ksquare()*x_dirichletbc_lo(); - double b = -ksquare()*x_dirichletbc_up(); - return (b - a)*x + a; + double a = -ksquare() * x_dirichletbc_lo(); + double b = -ksquare() * x_dirichletbc_up(); + return (b - a) * x + a; } -static void evalFunc_ksquare(double t, const double *xn, double* restrict fout, void *ctx) -{ +static void evalFunc_ksquare(double t, const double *xn, double *restrict fout, void *ctx) +{ double x = xn[0], y = xn[1], z = xn[2]; fout[0] = ksquare(); - fout[0] *= cos(2*M_PI*x); - fout[0] *= exp(4*M_PI*y); - fout[0] *= sin(z)+2; + fout[0] *= cos(2 * M_PI * x); + fout[0] *= exp(4 * M_PI * y); + fout[0] *= sin(z) + 2; } // RHS: rho(x,z) = (1.+kz*z+0.5*pow(z,2)) * sum_{m=1}^2 b_m sin(2*pi*m*x) -void evalFunc_rhs_dirichletx_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_rhs_dirichletx_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], z = xn[1]; // These values have to match those in the test below. double bmn[] = {1.5, 1.5, -0.5}; fout[0] = 0.; - for (int m=1; m<3; m++) { - double b = bmn[m-1]; - double t2 = b*sin(2*M_PI*m*x); + for (int m = 1; m < 3; m++) { + double b = bmn[m - 1]; + double t2 = b * sin(2 * M_PI * m * x); fout[0] += t2; } double kz = 1.; - fout[0] *= (1.+kz*z+0.5*pow(z,2)); - + fout[0] *= (1. + kz * z + 0.5 * pow(z, 2)); + // fout[0] *= 0.0; // To test exact integration (linear polynomial) fout[0] += p1_func(x); } // Solution: phi(x,z) = (1.+kz*z+0.5*pow(z,2)) * sum_{m=1}^2 b_m*sin(2*pi*m*x)/( (2*pi*m)^2 - kSq ) -void evalFunc_sol_dirichletx_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_sol_dirichletx_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], z = xn[1]; // These values have to match those in the test below. double bmn[] = {1.5, 1.5, -0.5}; fout[0] = 0.; - for (int m=1; m<3; m++) { - double b = bmn[m-1]; - double kx = 2*M_PI*m; - double t2 = b*sin(kx*x)/(kx*kx - ksquare()); + for (int m = 1; m < 3; m++) { + double b = bmn[m - 1]; + double kx = 2 * M_PI * m; + double t2 = b * sin(kx * x) / (kx * kx - ksquare()); fout[0] += t2; } double kz = 1.; - fout[0] *= (1.+kz*z+0.5*pow(z,2)); - + fout[0] *= (1. + kz * z + 0.5 * pow(z, 2)); + // fout[0] *= 0.0; // To test exact integration (linear polynomial) - fout[0] += -p1_func(x)/ksquare(); + fout[0] += -p1_func(x) / ksquare(); } // Periodic case (This is not suitable for convergence test as it leaves a constant offset in the solution) -void evalFunc_rhs_periodicx_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_rhs_periodicx_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], z = xn[1]; // These values have to match those in the test below. double gxx = 1.0; double amn[] = {-0.6, -2., 1.5}; - double bmn[] = { 1., 0.7, -0.3}; + double bmn[] = {1., 0.7, -0.3}; fout[0] = 0.; - for (int m=1; m<3; m++) { - double a = amn[m-1]; - double b = bmn[m-1]; - double kx = 2*M_PI*m; - double t1 = a*cos(kx*x); - double t2 = b*sin(kx*x); - fout[0] += t1+t2; + for (int m = 1; m < 3; m++) { + double a = amn[m - 1]; + double b = bmn[m - 1]; + double kx = 2 * M_PI * m; + double t1 = a * cos(kx * x); + double t2 = b * sin(kx * x); + fout[0] += t1 + t2; } double kz = 0.; - fout[0] *= (1.+kz*z); - + fout[0] *= (1. + kz * z); } -void evalFunc_sol_periodicx_2x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_sol_periodicx_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], z = xn[1]; // These values have to match those in the test below. double amn[] = {-0.6, -2., 1.5}; - double bmn[] = { 1., 0.7, -0.3}; + double bmn[] = {1., 0.7, -0.3}; fout[0] = 0.; - for (int m=1; m<3; m++) { - double a = amn[m-1]; - double b = bmn[m-1]; - double kx = 2*M_PI*m; - double t1 = a*cos(kx*x)/(kx*kx - ksquare()); - double t2 = b*sin(kx*x)/(kx*kx - ksquare()); - fout[0] += t1+t2; + for (int m = 1; m < 3; m++) { + double a = amn[m - 1]; + double b = bmn[m - 1]; + double kx = 2 * M_PI * m; + double t1 = a * cos(kx * x) / (kx * kx - ksquare()); + double t2 = b * sin(kx * x) / (kx * kx - ksquare()); + fout[0] += t1 + t2; } double kz = 0.; - fout[0] *= (1.+kz*z); + fout[0] *= (1. + kz * z); } double trig_func(double x, double y, bool laplacian) { double amn[] = {0.0, -1., 0., -0.0}; double out = 0.; - for (int m=0; m<4; m++) { + for (int m = 0; m < 4; m++) { double a = amn[m]; - double kx = M_PI*m; - double ky = 2*M_PI*m*0; - double t2 = a*cos(ky*y); - if (m > 0) - t2 *= sin(kx*x); + double kx = M_PI * m; + double ky = 2 * M_PI * m * 0; + double t2 = a * cos(ky * y); + if (m > 0) { + t2 *= sin(kx * x); + } if (laplacian) { - t2 *= -(kx*kx + ky*ky); + t2 *= -(kx * kx + ky * ky); } out += t2; } @@ -208,79 +232,104 @@ double z_envelope(double z) // Derive rho from: -nabla_perp^2 phi + kSq(x,y)*phi = rho // => rho = (kx^2 + ky^2)*phi + kSq(x,y)*phi // This is consistent with any kSq(x,y), including the spatially varying evalFunc_ksquare. -void evalFunc_sol_dirichletx_dirichlety_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_sol_dirichletx_dirichlety_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double kx = M_PI, ky = M_PI; - fout[0] = sin(kx*x) * sin(ky*y) * z_envelope(z); + fout[0] = sin(kx * x) * sin(ky * y) * z_envelope(z); } -void evalFunc_rhs_dirichletx_dirichlety_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_rhs_dirichletx_dirichlety_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double kx = M_PI, ky = M_PI; double kSq_val[1]; evalFunc_ksquare(t, xn, kSq_val, ctx); - double phi_val = sin(kx*x) * sin(ky*y) * z_envelope(z); - fout[0] = (kx*kx + ky*ky - kSq_val[0]) * phi_val; + double phi_val = sin(kx * x) * sin(ky * y) * z_envelope(z); + fout[0] = (kx * kx + ky * ky - kSq_val[0]) * phi_val; } -void evalFunc_sol_dirichletx_periodicy_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_sol_dirichletx_periodicy_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; - fout[0] = trig_func(x,y,false); + fout[0] = trig_func(x, y, false); fout[0] *= z_envelope(z); } // Periodic case (This is not suitable for convergence test as it leaves a constant offset in the solution) -void evalFunc_rhs_dirichletx_periodicy_3x(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc_rhs_dirichletx_periodicy_3x( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2]; double kSq[1]; evalFunc_ksquare(t, xn, kSq, ctx); double fsol[1]; evalFunc_sol_dirichletx_periodicy_3x(t, xn, fsol, ctx); - fout[0] = -trig_func(x,y,true)*z_envelope(z) - kSq[0]*fsol[0]; + fout[0] = -trig_func(x, y, true) * z_envelope(z) - kSq[0] * fsol[0]; } // Read 2x grid resolution from environment variables (or defaults). -static void get_2x_cells(int *cells) { +static void get_2x_cells(int *cells) +{ int nx = 32, nz = 48; char *env; - if ((env = getenv("TEST_NX"))) nx = atoi(env); - if ((env = getenv("TEST_NZ"))) nz = atoi(env); - cells[0] = nx; cells[1] = nz; + if ((env = getenv("TEST_NX"))) { + nx = atoi(env); + } + if ((env = getenv("TEST_NZ"))) { + nz = atoi(env); + } + cells[0] = nx; + cells[1] = nz; } // Read 3x grid resolution from environment variables (or defaults). -static void get_3x_cells(int *cells) { +static void get_3x_cells(int *cells) +{ int nx = 8, ny = 8, nz = 4; char *env; - if ((env = getenv("TEST_NX"))) nx = atoi(env); - if ((env = getenv("TEST_NY"))) ny = atoi(env); - if ((env = getenv("TEST_NZ"))) nz = atoi(env); - cells[0] = nx; cells[1] = ny; cells[2] = nz; + if ((env = getenv("TEST_NX"))) { + nx = atoi(env); + } + if ((env = getenv("TEST_NY"))) { + ny = atoi(env); + } + if ((env = getenv("TEST_NZ"))) { + nz = atoi(env); + } + cells[0] = nx; + cells[1] = ny; + cells[2] = nz; } // Introduce eps and ksq factors. -static void introduce_factors(struct gkyl_array *eps, struct gkyl_array *kSqFld) { +static void introduce_factors(struct gkyl_array *eps, struct gkyl_array *kSqFld) +{ gkyl_array_scale(eps, eps_factor()); gkyl_array_scale(kSqFld, ksq_factor()); } // Remove eps and ksq factors. -static void remove_factors(struct gkyl_array *eps, struct gkyl_array *kSqFld) { - gkyl_array_scale(eps, 1.0/eps_factor()); - gkyl_array_scale(kSqFld, 1.0/ksq_factor()); +static void remove_factors(struct gkyl_array *eps, struct gkyl_array *kSqFld) +{ + gkyl_array_scale(eps, 1.0 / eps_factor()); + gkyl_array_scale(kSqFld, 1.0 / ksq_factor()); } -static double -solve_fem_helmholtz_perp_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu, - double *sol_L2_out) +static double solve_fem_helmholtz_perp_2x( + int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu, double *sol_L2_out +) { double epsilon_0 = 1.0; - double kSq = ksquare(); // Helmholtz wave number squared. + double kSq = ksquare(); // Helmholtz wave number squared. double lower[] = {0.0, -M_PI}, upper[] = {1.0, M_PI}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); int dim_perp = dim - 1; // Grids. @@ -291,22 +340,22 @@ solve_fem_helmholtz_perp_2x(int poly_order, const int *cells, struct gkyl_poisso struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); // Projection updater for DG field. gkyl_proj_on_basis *projob = NULL, *projob_sol = NULL; if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order + 1, 1, evalFunc_rhs_dirichletx_2x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - poly_order + 1, 1, evalFunc_sol_dirichletx_2x, NULL); + projob = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_rhs_dirichletx_2x, NULL); + projob_sol = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_sol_dirichletx_2x, NULL); } else if ((bcs.lo_type[0] == GKYL_POISSON_PERIODIC && bcs.up_type[0] == GKYL_POISSON_PERIODIC)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order + 1, 1, evalFunc_rhs_periodicx_2x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - poly_order + 1, 1, evalFunc_sol_periodicx_2x, NULL); + projob = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_rhs_periodicx_2x, NULL); + projob_sol = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_sol_periodicx_2x, NULL); } // Create DG field we wish to make continuous. @@ -348,8 +397,8 @@ solve_fem_helmholtz_perp_2x(int poly_order, const int *cells, struct gkyl_poisso introduce_factors(eps, kSqFld); // FEM Helmholtz solver. - struct gkyl_fem_poisson_perp *poisson = gkyl_fem_poisson_perp_new(&localRange, &grid, basis, - &bcs, NULL, eps, kSqFld, use_gpu); + struct gkyl_fem_poisson_perp *poisson = + gkyl_fem_poisson_perp_new(&localRange, &grid, basis, &bcs, NULL, eps, kSqFld, use_gpu); // Set the RHS source. gkyl_fem_poisson_perp_set_rhs(poisson, rho); @@ -369,7 +418,9 @@ solve_fem_helmholtz_perp_2x(int poly_order, const int *cells, struct gkyl_poisso gkyl_array_copy(phi_ho, phi); #ifdef GKYL_HAVE_CUDA - if (use_gpu) cudaDeviceSynchronize(); + if (use_gpu) { + cudaDeviceSynchronize(); + } #endif // Write data to text file for visualization (Python notebook can read this) @@ -385,14 +436,17 @@ solve_fem_helmholtz_perp_2x(int poly_order, const int *cells, struct gkyl_poisso const double *phi_p = gkyl_array_cfetch(phi_ho, loc); const double *phisol_p = gkyl_array_cfetch(phisol_ho, loc); // Write cell center coordinates and the 0th basis coefficient (cell average) - fprintf(fp, "%.16e %.16e %.16e %.16e\n", xc[0], xc[1], phi_p[0]/dg0norm, phisol_p[0]/dg0norm); + fprintf( + fp, "%.16e %.16e %.16e %.16e\n", xc[0], xc[1], phi_p[0] / dg0norm, phisol_p[0] / dg0norm + ); } fclose(fp); } double err_L2 = error_L2norm(grid, localRange, basis, phi_ho, phisol_ho); - if (sol_L2_out) + if (sol_L2_out) { *sol_L2_out = field_L2norm(grid, localRange, basis, phisol_ho); + } gkyl_fem_poisson_perp_release(poisson); gkyl_proj_on_basis_release(projob); @@ -407,8 +461,9 @@ solve_fem_helmholtz_perp_2x(int poly_order, const int *cells, struct gkyl_poisso return err_L2; } -void -test_fem_helmholtz_perp_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) +void test_fem_helmholtz_perp_2x( + int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu +) { if (helmholtz_write_output()) { // Single-resolution mode (called from Python): check relative L2 error < 1%. @@ -417,31 +472,33 @@ test_fem_helmholtz_perp_2x(int poly_order, const int *cells, struct gkyl_poisson double rel_err = (sol_L2 > 0.0) ? err_L2 / sol_L2 : err_L2; TEST_CHECK(rel_err < 0.01); TEST_MSG("Relative L2 error = %.6e (threshold 1%%)", rel_err); - if (helmholtz_verbose()) + if (helmholtz_verbose()) { printf("L2 error = %.6e, relative L2 error = %.6e\n", err_L2, rel_err); + } } else { // Default convergence check: run at baseline and 2x resolution, verify error ratio >= 3.5 // (consistent with 2nd-order convergence: factor of 4 = 2^2). - int cells2[2] = {2*cells[0], 2*cells[1]}; - double err_coarse = solve_fem_helmholtz_perp_2x(poly_order, cells, bcs, use_gpu, NULL); - double err_fine = solve_fem_helmholtz_perp_2x(poly_order, cells2, bcs, use_gpu, NULL); + int cells2[2] = {2 * cells[0], 2 * cells[1]}; + double err_coarse = solve_fem_helmholtz_perp_2x(poly_order, cells, bcs, use_gpu, NULL); + double err_fine = solve_fem_helmholtz_perp_2x(poly_order, cells2, bcs, use_gpu, NULL); double ratio = err_coarse / err_fine; TEST_CHECK(ratio >= 3.5); TEST_MSG("L2 error ratio (2x refinement) = %.4f (expected >= 3.5 for 2nd order)", ratio); - if (helmholtz_verbose()) + if (helmholtz_verbose()) { printf("L2 error: coarse = %.6e, fine = %.6e, ratio = %.4f\n", err_coarse, err_fine, ratio); + } } } -static double -solve_fem_helmholtz_perp_3x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu, - double *sol_L2_out) +static double solve_fem_helmholtz_perp_3x( + int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu, double *sol_L2_out +) { double epsilon_0 = 1.0; - double kSq = ksquare(); // Helmholtz wave number squared. + double kSq = ksquare(); // Helmholtz wave number squared. double lower[] = {0.0, 0.0, -M_PI}, upper[] = {1.0, 1.0, M_PI}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); int dim_perp = dim - 1; // Grids. @@ -452,7 +509,7 @@ solve_fem_helmholtz_perp_3x(int poly_order, const int *cells, struct gkyl_poisso struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1, 1 }; + int ghost[] = {1, 1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); @@ -460,19 +517,24 @@ solve_fem_helmholtz_perp_3x(int poly_order, const int *cells, struct gkyl_poisso gkyl_proj_on_basis *projob = NULL, *projob_sol = NULL, *projob_kSq = NULL; if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order + 1, 1, evalFunc_rhs_dirichletx_dirichlety_3x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2 * (poly_order + 1), 1, evalFunc_sol_dirichletx_dirichlety_3x, NULL); - } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_rhs_dirichletx_dirichlety_3x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc_sol_dirichletx_dirichlety_3x, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order + 1, 1, evalFunc_rhs_dirichletx_periodicy_3x, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2 * (poly_order + 1), 1, evalFunc_sol_dirichletx_periodicy_3x, NULL); + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc_rhs_dirichletx_periodicy_3x, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc_sol_dirichletx_periodicy_3x, NULL + ); } - projob_kSq = gkyl_proj_on_basis_new(&grid, &basis, - 2 * (poly_order + 1), 1, evalFunc_ksquare, NULL); + projob_kSq = + gkyl_proj_on_basis_new(&grid, &basis, 2 * (poly_order + 1), 1, evalFunc_ksquare, NULL); // Create DG field we wish to make continuous. struct gkyl_array *rho = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); @@ -504,7 +566,7 @@ solve_fem_helmholtz_perp_3x(int poly_order, const int *cells, struct gkyl_poisso // Project the permittivity onto the basis. double dg0norm = pow(sqrt(2.), dim); gkyl_array_shiftc(eps, epsilon_0 * dg0norm, 0 * basis.num_basis); - gkyl_array_shiftc(eps, 0.0 * dg0norm, 1 * basis.num_basis); // gxy = 0 + gkyl_array_shiftc(eps, 0.0 * dg0norm, 1 * basis.num_basis); // gxy = 0 gkyl_array_shiftc(eps, epsilon_0 * dg0norm, 2 * basis.num_basis); // Project kSq onto the basis. @@ -518,8 +580,8 @@ solve_fem_helmholtz_perp_3x(int poly_order, const int *cells, struct gkyl_poisso introduce_factors(eps, kSqFld); // FEM Helmholtz solver. - struct gkyl_fem_poisson_perp *poisson = gkyl_fem_poisson_perp_new(&localRange, &grid, basis, - &bcs, NULL, eps, kSqFld, use_gpu); + struct gkyl_fem_poisson_perp *poisson = + gkyl_fem_poisson_perp_new(&localRange, &grid, basis, &bcs, NULL, eps, kSqFld, use_gpu); // Set the RHS source. gkyl_fem_poisson_perp_set_rhs(poisson, rho); @@ -539,7 +601,9 @@ solve_fem_helmholtz_perp_3x(int poly_order, const int *cells, struct gkyl_poisso gkyl_array_copy(phi_ho, phi); #ifdef GKYL_HAVE_CUDA - if (use_gpu) cudaDeviceSynchronize(); + if (use_gpu) { + cudaDeviceSynchronize(); + } #endif // Write data to text file for visualization (Python notebook can read this) @@ -555,14 +619,18 @@ solve_fem_helmholtz_perp_3x(int poly_order, const int *cells, struct gkyl_poisso const double *phi_p = gkyl_array_cfetch(phi_ho, loc); const double *phisol_p = gkyl_array_cfetch(phisol_ho, loc); // Write cell center coordinates and the 0th basis coefficient (cell average) - fprintf(fp, "%.16e %.16e %.16e %.16e %.16e\n", xc[0], xc[1], xc[2], phi_p[0]/dg0norm, phisol_p[0]/dg0norm); + fprintf( + fp, "%.16e %.16e %.16e %.16e %.16e\n", xc[0], xc[1], xc[2], phi_p[0] / dg0norm, + phisol_p[0] / dg0norm + ); } fclose(fp); } double err_L2 = error_L2norm(grid, localRange, basis, phi_ho, phisol_ho); - if (sol_L2_out) + if (sol_L2_out) { *sol_L2_out = field_L2norm(grid, localRange, basis, phisol_ho); + } gkyl_fem_poisson_perp_release(poisson); gkyl_proj_on_basis_release(projob); @@ -579,20 +647,22 @@ solve_fem_helmholtz_perp_3x(int poly_order, const int *cells, struct gkyl_poisso return err_L2; } -void -test_fem_helmholtz_perp_3x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) +void test_fem_helmholtz_perp_3x( + int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu +) { // Validate poly_order and BC combination before running. if (poly_order != 1) { - TEST_CHECK( gkyl_compare(1., 2., 1e-10) ); + TEST_CHECK(gkyl_compare(1., 2., 1e-10)); TEST_MSG("This poly_order is not available"); return; } bool dd = (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET); - bool ydir_ok = (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET) || - (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC); + bool ydir_ok = + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET) || + (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC); if (!dd || !ydir_ok) { - TEST_CHECK( gkyl_compare(1., 2., 1e-10) ); + TEST_CHECK(gkyl_compare(1., 2., 1e-10)); TEST_MSG("This BC combination is not available"); return; } @@ -604,62 +674,86 @@ test_fem_helmholtz_perp_3x(int poly_order, const int *cells, struct gkyl_poisson double rel_err = (sol_L2 > 0.0) ? err_L2 / sol_L2 : err_L2; TEST_CHECK(rel_err < 0.01); TEST_MSG("Relative L2 error = %.6e (threshold 1%%)", rel_err); - if (helmholtz_verbose()) + if (helmholtz_verbose()) { printf("L2 error = %.6e, relative L2 error = %.6e\n", err_L2, rel_err); + } } else { // Default convergence check: run at baseline and 2x resolution, verify error ratio >= 3.5 - int cells2[3] = {2*cells[0], 2*cells[1], 2*cells[2]}; - double err_coarse = solve_fem_helmholtz_perp_3x(poly_order, cells, bcs, use_gpu, NULL); - double err_fine = solve_fem_helmholtz_perp_3x(poly_order, cells2, bcs, use_gpu, NULL); + int cells2[3] = {2 * cells[0], 2 * cells[1], 2 * cells[2]}; + double err_coarse = solve_fem_helmholtz_perp_3x(poly_order, cells, bcs, use_gpu, NULL); + double err_fine = solve_fem_helmholtz_perp_3x(poly_order, cells2, bcs, use_gpu, NULL); double ratio = err_coarse / err_fine; TEST_CHECK(ratio >= 3.5); TEST_MSG("L2 error ratio (2x refinement) = %.4f (expected >= 3.5 for 2nd order)", ratio); - if (helmholtz_verbose()) + if (helmholtz_verbose()) { printf("L2 error: coarse = %.6e, fine = %.6e, ratio = %.4f\n", err_coarse, err_fine, ratio); + } } } // 2x test wrappers -void test_fem_poisson_perp_ksq_2x_p1_dirichletx_ho() { - int cells[2]; get_2x_cells(cells); +void test_fem_poisson_perp_ksq_2x_p1_dirichletx_ho() +{ + int cells[2]; + get_2x_cells(cells); struct gkyl_poisson_bc bc_tv; - bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; - bc_tv.lo_value[0].v[0] = x_dirichletbc_lo(); bc_tv.up_value[0].v[0] = x_dirichletbc_up(); + bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; + bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; + bc_tv.lo_value[0].v[0] = x_dirichletbc_lo(); + bc_tv.up_value[0].v[0] = x_dirichletbc_up(); test_fem_helmholtz_perp_2x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_ksq_2x_p1_periodicx_ho() { - int cells[2]; get_2x_cells(cells); +void test_fem_poisson_perp_ksq_2x_p1_periodicx_ho() +{ + int cells[2]; + get_2x_cells(cells); struct gkyl_poisson_bc bc_tv; - bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; - bc_tv.lo_value[0].v[0] = 0.; bc_tv.up_value[0].v[0] = 0.; + bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; + bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; + bc_tv.lo_value[0].v[0] = 0.; + bc_tv.up_value[0].v[0] = 0.; test_fem_helmholtz_perp_2x(1, cells, bc_tv, false); } // 3x test wrappers -void test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_ho() { - int cells[3]; get_3x_cells(cells); +void test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_ho() +{ + int cells[3]; + get_3x_cells(cells); struct gkyl_poisson_bc bc_tv; - bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; - bc_tv.lo_type[1] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[1] = GKYL_POISSON_DIRICHLET; - bc_tv.lo_value[0].v[0] = 0.; bc_tv.up_value[0].v[0] = 0.; - bc_tv.lo_value[1].v[0] = 0.; bc_tv.up_value[1].v[0] = 0.; + bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; + bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; + bc_tv.lo_type[1] = GKYL_POISSON_DIRICHLET; + bc_tv.up_type[1] = GKYL_POISSON_DIRICHLET; + bc_tv.lo_value[0].v[0] = 0.; + bc_tv.up_value[0].v[0] = 0.; + bc_tv.lo_value[1].v[0] = 0.; + bc_tv.up_value[1].v[0] = 0.; test_fem_helmholtz_perp_3x(1, cells, bc_tv, false); } -void test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_ho() { - int cells[3]; get_3x_cells(cells); +void test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_ho() +{ + int cells[3]; + get_3x_cells(cells); struct gkyl_poisson_bc bc_tv; - bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; - bc_tv.lo_type[1] = GKYL_POISSON_PERIODIC; bc_tv.up_type[1] = GKYL_POISSON_PERIODIC; - bc_tv.lo_value[0].v[0] = 0.; bc_tv.up_value[0].v[0] = 0.; - bc_tv.lo_value[1].v[0] = 0.; bc_tv.up_value[1].v[0] = 0.; + bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; + bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; + bc_tv.lo_type[1] = GKYL_POISSON_PERIODIC; + bc_tv.up_type[1] = GKYL_POISSON_PERIODIC; + bc_tv.lo_value[0].v[0] = 0.; + bc_tv.up_value[0].v[0] = 0.; + bc_tv.lo_value[1].v[0] = 0.; + bc_tv.up_value[1].v[0] = 0.; test_fem_helmholtz_perp_3x(1, cells, bc_tv, false); } #ifdef GKYL_HAVE_CUDA -void test_fem_poisson_perp_ksq_2x_p1_dirichletx_dev() { - int cells[2]; get_2x_cells(cells); +void test_fem_poisson_perp_ksq_2x_p1_dirichletx_dev() +{ + int cells[2]; + get_2x_cells(cells); struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -668,8 +762,10 @@ void test_fem_poisson_perp_ksq_2x_p1_dirichletx_dev() { test_fem_helmholtz_perp_2x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_ksq_2x_p1_periodicx_dev() { - int cells[2]; get_2x_cells(cells); +void test_fem_poisson_perp_ksq_2x_p1_periodicx_dev() +{ + int cells[2]; + get_2x_cells(cells); struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_PERIODIC; bc_tv.up_type[0] = GKYL_POISSON_PERIODIC; @@ -678,8 +774,10 @@ void test_fem_poisson_perp_ksq_2x_p1_periodicx_dev() { test_fem_helmholtz_perp_2x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_dev() { - int cells[3]; get_3x_cells(cells); +void test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_dev() +{ + int cells[3]; + get_3x_cells(cells); struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -692,8 +790,10 @@ void test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_dev() { test_fem_helmholtz_perp_3x(1, cells, bc_tv, true); } -void test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_dev() { - int cells[3]; get_3x_cells(cells); +void test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_dev() +{ + int cells[3]; + get_3x_cells(cells); struct gkyl_poisson_bc bc_tv; bc_tv.lo_type[0] = GKYL_POISSON_DIRICHLET; bc_tv.up_type[0] = GKYL_POISSON_DIRICHLET; @@ -707,20 +807,24 @@ void test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_dev() { } #endif -TEST_LIST = { - // 2x tests - { "test_fem_poisson_perp_ksq_2x_p1_dirichletx_ho", test_fem_poisson_perp_ksq_2x_p1_dirichletx_ho }, - { "test_fem_poisson_perp_ksq_2x_p1_periodicx_ho", test_fem_poisson_perp_ksq_2x_p1_periodicx_ho }, +TEST_LIST = { // 2x tests + {"test_fem_poisson_perp_ksq_2x_p1_dirichletx_ho", test_fem_poisson_perp_ksq_2x_p1_dirichletx_ho}, + {"test_fem_poisson_perp_ksq_2x_p1_periodicx_ho", test_fem_poisson_perp_ksq_2x_p1_periodicx_ho}, // 3x tests - { "test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_ho", test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_ho }, - { "test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_ho", test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_ho }, + {"test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_ho", + test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_ho}, + {"test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_ho", + test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_ho}, #ifdef GKYL_HAVE_CUDA - { "test_fem_poisson_perp_ksq_2x_p1_dirichletx_dev", test_fem_poisson_perp_ksq_2x_p1_dirichletx_dev }, - { "test_fem_poisson_perp_ksq_2x_p1_periodicx_dev", test_fem_poisson_perp_ksq_2x_p1_periodicx_dev }, - { "test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_dev", test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_dev }, - { "test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_dev", test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_dev }, + {"test_fem_poisson_perp_ksq_2x_p1_dirichletx_dev", test_fem_poisson_perp_ksq_2x_p1_dirichletx_dev + }, + {"test_fem_poisson_perp_ksq_2x_p1_periodicx_dev", test_fem_poisson_perp_ksq_2x_p1_periodicx_dev}, + {"test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_dev", + test_fem_poisson_perp_ksq_3x_p1_dirichletx_dirichlety_dev}, + {"test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_dev", + test_fem_poisson_perp_ksq_3x_p1_dirichletx_periodicy_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_gk_geometry_mapc2p.c b/gyrokinetic/unit/ctest_gk_geometry_mapc2p.c index ea77b3b247..1bb0475ccd 100644 --- a/gyrokinetic/unit/ctest_gk_geometry_mapc2p.c +++ b/gyrokinetic/unit/ctest_gk_geometry_mapc2p.c @@ -3,7 +3,6 @@ #include #include - #include #include #include @@ -22,119 +21,120 @@ #include -void -write_geometry(gk_geometry *up, struct gkyl_rect_grid grid, struct gkyl_range local, const char *name) +void write_geometry( + gk_geometry *up, struct gkyl_rect_grid grid, struct gkyl_range local, const char *name +) { const char *fmt = "%s-%s.gkyl"; int sz = gkyl_calc_strlen(fmt, name, "jacobtot_inv"); - char fileNm[sz+1]; // ensure no buffer overflow + char fileNm[sz + 1]; // ensure no buffer overflow sprintf(fileNm, fmt, name, "mapc2p"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2p, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2p, fileNm); sprintf(fileNm, fmt, name, "mapc2nu"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2nu_pos, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2nu_pos, fileNm); sprintf(fileNm, fmt, name, "bmag_corn"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag, fileNm); sprintf(fileNm, fmt, name, "bmag"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bmag, fileNm); sprintf(fileNm, fmt, name, "g_ij"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.g_ij, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.g_ij, fileNm); sprintf(fileNm, fmt, name, "dxdz"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dxdz, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dxdz, fileNm); sprintf(fileNm, fmt, name, "dzdx"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dzdx, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dzdx, fileNm); sprintf(fileNm, fmt, name, "normals"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.normals, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.normals, fileNm); sprintf(fileNm, fmt, name, "jacobgeo"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo, fileNm); sprintf(fileNm, fmt, name, "jacobgeo_inv"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo_inv, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo_inv, fileNm); sprintf(fileNm, fmt, name, "gij"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gij, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gij, fileNm); sprintf(fileNm, fmt, name, "b_i"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.b_i, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.b_i, fileNm); sprintf(fileNm, fmt, name, "bcart"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bcart, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bcart, fileNm); sprintf(fileNm, fmt, name, "cmag"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.cmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.cmag, fileNm); sprintf(fileNm, fmt, name, "jacobtot"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot, fileNm); sprintf(fileNm, fmt, name, "jacobtot_inv"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot_inv, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot_inv, fileNm); sprintf(fileNm, fmt, name, "gxxj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxxj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxxj, fileNm); sprintf(fileNm, fmt, name, "gxyj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxyj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxyj, fileNm); sprintf(fileNm, fmt, name, "gyyj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gyyj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gyyj, fileNm); sprintf(fileNm, fmt, name, "gxzj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxzj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxzj, fileNm); sprintf(fileNm, fmt, name, "eps2"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.eps2, fileNm); - + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.eps2, fileNm); // Create Nodal Range and Grid and Write Nodal Coordinates struct gkyl_range nrange; gkyl_gk_geometry_init_nodal_range(&nrange, &local, up->basis.poly_order); - struct gkyl_array* mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); + struct gkyl_array *mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&up->basis, &grid, false); - gkyl_nodal_ops_m2n(n2m, &up->basis, &grid, &nrange, &local, 3, mc2p_nodal, up->geo_corn.mc2p, false); + gkyl_nodal_ops_m2n( + n2m, &up->basis, &grid, &nrange, &local, 3, mc2p_nodal, up->geo_corn.mc2p, false + ); gkyl_nodal_ops_release(n2m); struct gkyl_rect_grid ngrid; gkyl_gk_geometry_init_nodal_grid(&ngrid, &grid, &nrange); sprintf(fileNm, fmt, name, "nodes"); - gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, fileNm); + gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, fileNm); gkyl_array_release(mc2p_nodal); } - // Functions for this test -void mapc2p(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void mapc2p(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double r = xn[0], theta = xn[1], z = xn[2]; - fout[0] = r*cos(theta); - fout[1] = r*sin(theta); + fout[0] = r * cos(theta); + fout[1] = r * sin(theta); fout[2] = z; } -void exact_gij(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_gij(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double r = xn[0], theta = xn[1], phi = xn[2]; fout[0] = 1.0; fout[1] = 0.0; fout[2] = 0.0; - fout[3] = r*r; + fout[3] = r * r; fout[4] = 0.0; fout[5] = 1.0; } -void bfield_func(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx){ +void bfield_func(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) +{ fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0398; } -void -test_mapc2p_3x_p1_ho() +void test_mapc2p_3x_p1_ho() { struct gkyl_basis basis; int poly_order = 1; gkyl_cart_modal_serendip(&basis, 3, poly_order); - + double Lz = 1.8049e+01; double Lx = 1.2534e+00; - double Rmax = Lx/2; - double Rmin = 0.5*Rmax; + double Rmax = Lx / 2; + double Rmin = 0.5 * Rmax; int Nz = 10; - double lower[3] = {Rmin, -0.1, -Lz/2}; - double upper[3] = {Rmax, 0.1, Lz/2}; - int cells[3] = { 8, 1, 8 }; + double lower[3] = {Rmin, -0.1, -Lz / 2}; + double upper[3] = {Rmax, 0.1, Lz / 2}; + int cells[3] = {8, 1, 8}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 3, lower, upper, cells); - + struct gkyl_range ext_range, range; - int nghost[3] = { 1,1,1}; + int nghost[3] = {1, 1, 1}; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); struct gkyl_position_map *pmap = gkyl_position_map_null_new(); @@ -145,7 +145,7 @@ test_mapc2p_3x_p1_ho() .mapc2p = mapc2p, // mapping of computational to physical space .c2p_ctx = 0, .bfield_func = bfield_func, // magnetic field magnitude - .bfield_ctx =0 , + .bfield_ctx = 0, .position_map = pmap, .grid = grid, .local = range, @@ -158,7 +158,7 @@ test_mapc2p_3x_p1_ho() .geo_local_ext = ext_range, .geo_global = range, .geo_global_ext = ext_range, - .geo_basis = basis, + .geo_basis = basis }; struct gk_geometry *gk_geom = gkyl_gk_geometry_mapc2p_new(&geometry_input); @@ -167,144 +167,196 @@ test_mapc2p_3x_p1_ho() // Define nodal operations enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates int cidx[3]; - int nodes[] = { 1, 1, 1 }; - for (int d=0; dgeo_corn.mc2p, false); + struct gkyl_array *mapc2p_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange, &range, 3, mapc2p_nodal, gk_geom->geo_corn.mc2p, false + ); - struct gkyl_array* mapc2p_nodal_interior = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, mapc2p_nodal_interior, gk_geom->geo_int.mc2p, true); + struct gkyl_array *mapc2p_nodal_interior = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, mapc2p_nodal_interior, + gk_geom->geo_int.mc2p, true + ); // Check that |bhat|=1 at nodes - struct gkyl_array* bhat_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, bhat_nodal, gk_geom->geo_int.bcart, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *bhat_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, bhat_nodal, gk_geom->geo_int.bcart, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; double *bhat_n = gkyl_array_fetch(bhat_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double bhat_mag = sqrt(bhat_n[0]*bhat_n[0] + bhat_n[1]*bhat_n[1] + bhat_n[2]*bhat_n[2]); - TEST_CHECK( gkyl_compare( bhat_mag, 1.0, 1e-12) ); + double bhat_mag = + sqrt(bhat_n[0] * bhat_n[0] + bhat_n[1] * bhat_n[1] + bhat_n[2] * bhat_n[2]); + TEST_CHECK(gkyl_compare(bhat_mag, 1.0, 1e-12)); } } } // Check that the duals are what they should be - struct gkyl_array* dualmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, dualmag_nodal, gk_geom->geo_int.dualmag, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *dualmag_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, dualmag_nodal, gk_geom->geo_int.dualmag, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *dualmag_n = gkyl_array_fetch(dualmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); - double e2mag = sqrt(1/(mapc2p_n[0]*mapc2p_n[0] + mapc2p_n[1]*mapc2p_n[1])); // 1/R - TEST_CHECK( gkyl_compare( dualmag_n[0], 1.0, 1e-8) ); - TEST_CHECK( gkyl_compare( dualmag_n[1], e2mag, 1e-6) ); - TEST_CHECK( gkyl_compare( dualmag_n[2], 1.0, 1e-8) ); + double *dualmag_n = + gkyl_array_fetch(dualmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *mapc2p_n = + gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double e2mag = sqrt(1 / (mapc2p_n[0] * mapc2p_n[0] + mapc2p_n[1] * mapc2p_n[1])); // 1/R + TEST_CHECK(gkyl_compare(dualmag_n[0], 1.0, 1e-8)); + TEST_CHECK(gkyl_compare(dualmag_n[1], e2mag, 1e-6)); + TEST_CHECK(gkyl_compare(dualmag_n[2], 1.0, 1e-8)); } } } - // Check that Jacobgeo is what it should be. J = R in cylindrical coordinates - struct gkyl_array* jacobgeo_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_nodal, gk_geom->geo_int.jacobgeo, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *jacobgeo_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_nodal, gk_geom->geo_int.jacobgeo, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobgeo_n = gkyl_array_fetch(jacobgeo_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *jacobgeo_n = + gkyl_array_fetch(jacobgeo_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); // mapc2p_n[0] = x, mapc2p_n[1] = y, mapc2p_n[2] = z - double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); - double radius = sqrt(mapc2p_n[0]*mapc2p_n[0] + mapc2p_n[1]*mapc2p_n[1]); - TEST_CHECK( gkyl_compare( jacobgeo_n[0], radius, 1e-6) ); + double *mapc2p_n = + gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double radius = sqrt(mapc2p_n[0] * mapc2p_n[0] + mapc2p_n[1] * mapc2p_n[1]); + TEST_CHECK(gkyl_compare(jacobgeo_n[0], radius, 1e-6)); } } } // Check bmag is what it should be - struct gkyl_array* bmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, bmag_nodal, gk_geom->geo_int.bmag, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *bmag_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, bmag_nodal, gk_geom->geo_int.bmag, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = grid.lower[PSI_IDX] + ip*(grid.upper[PSI_IDX]-grid.lower[PSI_IDX])/grid.cells[PSI_IDX]; - double alpha = grid.lower[AL_IDX] + ia*(grid.upper[AL_IDX]-grid.lower[AL_IDX])/grid.cells[AL_IDX]; - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double psi = grid.lower[PSI_IDX] + + ip * (grid.upper[PSI_IDX] - grid.lower[PSI_IDX]) / grid.cells[PSI_IDX]; + double alpha = + grid.lower[AL_IDX] + ia * (grid.upper[AL_IDX] - grid.lower[AL_IDX]) / grid.cells[AL_IDX]; + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; double xn[3] = {psi, alpha, theta}; double *bmag_n = gkyl_array_fetch(bmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); double bmag_anal[3]; bfield_func(0, xn, bmag_anal, 0); - TEST_CHECK( gkyl_compare( bmag_n[0], bmag_anal[2], 1e-8) ); + TEST_CHECK(gkyl_compare(bmag_n[0], bmag_anal[2], 1e-8)); } } } // Check gij - struct gkyl_array* gij_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_nodal, gk_geom->geo_int.g_ij, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *gij_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_nodal, gk_geom->geo_int.g_ij, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; double *gij_n = gkyl_array_fetch(gij_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); - double r = sqrt(mapc2p_n[0]*mapc2p_n[0] + mapc2p_n[1]*mapc2p_n[1]); + double *mapc2p_n = + gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double r = sqrt(mapc2p_n[0] * mapc2p_n[0] + mapc2p_n[1] * mapc2p_n[1]); double xn[3] = {r, 0.0, 0.0}; double fout[6]; exact_gij(0.0, xn, fout, 0); - for (int i=0; i<6; ++i) - TEST_CHECK( gkyl_compare( gij_n[i], fout[i], 1e-6) ); + for (int i = 0; i < 6; ++i) { + TEST_CHECK(gkyl_compare(gij_n[i], fout[i], 1e-6)); + } } } } // Check mapc2p - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]; it<=nrange.upper[TH_IDX]; ++it) { + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX]; it <= nrange.upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = grid.lower[PSI_IDX] + ip*(grid.upper[PSI_IDX]-grid.lower[PSI_IDX])/grid.cells[PSI_IDX]; - double alpha = grid.lower[AL_IDX] + ia*(grid.upper[AL_IDX]-grid.lower[AL_IDX])/grid.cells[AL_IDX]; - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double psi = grid.lower[PSI_IDX] + + ip * (grid.upper[PSI_IDX] - grid.lower[PSI_IDX]) / grid.cells[PSI_IDX]; + double alpha = + grid.lower[AL_IDX] + ia * (grid.upper[AL_IDX] - grid.lower[AL_IDX]) / grid.cells[AL_IDX]; + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; // mapc2p_n[0] = x, mapc2p_n[1] = y, mapc2p_n[2] = z double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal, gkyl_range_idx(&nrange, cidx)); double xn[3] = {psi, alpha, theta}; double fout[3]; mapc2p(0.0, xn, fout, 0); - for (int i=0; i<3; ++i) - TEST_CHECK( gkyl_compare( mapc2p_n[i], fout[i], 1e-6) ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mapc2p_n[i], fout[i], 1e-6)); + } } } } - + // Release memory gkyl_array_release(bhat_nodal); @@ -319,55 +371,49 @@ test_mapc2p_3x_p1_ho() gkyl_gk_geometry_release(gk_geom); } -void -mapz(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void mapz(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double Lz = 1.8049e+01; - double a = -Lz/2; - fout[0] = -1/(2*a) * pow(a - xn[0], 2) + a; + double a = -Lz / 2; + fout[0] = -1 / (2 * a) * pow(a - xn[0], 2) + a; } -void -dmapz_dz(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void dmapz_dz(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double Lz = 1.8049e+01; - double a = -Lz/2; - fout[0] = 1 - xn[0]/a; + double a = -Lz / 2; + fout[0] = 1 - xn[0] / a; } -void -test_mapc2p_3x_p1_pmap_ho() -{ +void test_mapc2p_3x_p1_pmap_ho() +{ enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates struct gkyl_basis basis; int poly_order = 1; int cdim = 3; gkyl_cart_modal_serendip(&basis, cdim, poly_order); - + double Lz = 1.8049e+01; double Lx = 1.2534e+00; - double Rmax = Lx/2; - double Rmin = 0.05*Rmax; + double Rmax = Lx / 2; + double Rmin = 0.05 * Rmax; int Nz = 10; - double lower[3] = {Rmin, -M_PI, -Lz/2}; - double upper[3] = {Rmax, M_PI, Lz/2}; - int cells[3] = { 18, 18, Nz }; + double lower[3] = {Rmin, -M_PI, -Lz / 2}; + double upper[3] = {Rmax, M_PI, Lz / 2}; + int cells[3] = {18, 18, Nz}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, cdim, lower, upper, cells); - + struct gkyl_range ext_range, range; - int nghost[3] = { 1,1,1}; + int nghost[3] = {1, 1, 1}; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); - struct gkyl_position_map_inp pos_map_inp = { - .maps = {0, 0, mapz}, - .ctxs = {0, 0, 0}, - }; + struct gkyl_position_map_inp pos_map_inp = {.maps = {0, 0, mapz}, .ctxs = {0, 0, 0}}; // Configuration space geometry initialization - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp, grid, range, - ext_range, range, ext_range, basis); + struct gkyl_position_map *pos_map = + gkyl_position_map_new(pos_map_inp, grid, range, ext_range, range, ext_range, basis); // Initialize geometry struct gkyl_gk_geometry_inp geometry_input = { @@ -375,7 +421,7 @@ test_mapc2p_3x_p1_pmap_ho() .mapc2p = mapc2p, // mapping of computational to physical space .c2p_ctx = 0, .bfield_func = bfield_func, // magnetic field magnitude - .bfield_ctx =0 , + .bfield_ctx = 0, .grid = grid, .local = range, .local_ext = ext_range, @@ -388,61 +434,73 @@ test_mapc2p_3x_p1_pmap_ho() .geo_global = range, .geo_global_ext = ext_range, .geo_basis = basis, - .position_map = pos_map, + .position_map = pos_map }; struct gk_geometry *gk_geom = gkyl_gk_geometry_mapc2p_new(&geometry_input); - + gkyl_position_map_set_mc2nu(pos_map, gk_geom->geo_corn.mc2nu_pos); // Define the nodes for the script to calculate values at int cidx[3]; - int nodes[] = { 1, 1, 1 }; - for (int d=0; dgeo_corn.mc2p, false + ); - struct gkyl_array* mapc2p_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange, &range, 3, mapc2p_nodal, gk_geom->geo_corn.mc2p, false); - - struct gkyl_array* mapc2p_nodal_interior = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, mapc2p_nodal_interior, gk_geom->geo_int.mc2p, true); + struct gkyl_array *mapc2p_nodal_interior = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, mapc2p_nodal_interior, + gk_geom->geo_int.mc2p, true + ); // Check mapc2p - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]; it<=nrange.upper[TH_IDX]; ++it) { + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX]; it <= nrange.upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = grid.lower[PSI_IDX] + ip*(grid.upper[PSI_IDX]-grid.lower[PSI_IDX])/grid.cells[PSI_IDX]; - double alpha = grid.lower[AL_IDX] + ia*(grid.upper[AL_IDX]-grid.lower[AL_IDX])/grid.cells[AL_IDX]; - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double psi = grid.lower[PSI_IDX] + + ip * (grid.upper[PSI_IDX] - grid.lower[PSI_IDX]) / grid.cells[PSI_IDX]; + double alpha = + grid.lower[AL_IDX] + ia * (grid.upper[AL_IDX] - grid.lower[AL_IDX]) / grid.cells[AL_IDX]; + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; // mapc2p_n[0] = x, mapc2p_n[1] = y, mapc2p_n[2] = z double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal, gkyl_range_idx(&nrange, cidx)); mapz(0.0, &theta, &theta, 0); double xn[3] = {psi, alpha, theta}; double fout[3]; mapc2p(0.0, xn, fout, 0); - for (int i=0; i<3; ++i){ - TEST_CHECK( gkyl_compare( mapc2p_n[i], fout[i], 1e-8) ); - TEST_MSG( "i %d, idx %d %d %d, mapc2p_n %g, fout %g\n", i, ip, ia, it, mapc2p_n[i], fout[i] ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mapc2p_n[i], fout[i], 1e-8)); + TEST_MSG( + "i %d, idx %d %d %d, mapc2p_n %g, fout %g\n", i, ip, ia, it, mapc2p_n[i], fout[i] + ); } } } @@ -450,52 +508,68 @@ test_mapc2p_3x_p1_pmap_ho() // Check that Jacobgeo is what it should be. J = R in cylindrical coordinates // We have a contribution from the position map too, given as dZ/dz - struct gkyl_array* jacobgeo_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_nodal, gk_geom->geo_int.jacobgeo, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *jacobgeo_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_nodal, gk_geom->geo_int.jacobgeo, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = calc_running_coord(psi_lo, ip-nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); - double alpha = calc_running_coord(alpha_lo, ia-nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); - double theta = calc_running_coord(theta_lo, it-nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); - double *jacobgeo_n = gkyl_array_fetch(jacobgeo_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double psi = + calc_running_coord(psi_lo, ip - nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); + double alpha = + calc_running_coord(alpha_lo, ia - nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); + double theta = + calc_running_coord(theta_lo, it - nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); + double *jacobgeo_n = + gkyl_array_fetch(jacobgeo_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); // mapc2p_n[0] = x, mapc2p_n[1] = y, mapc2p_n[2] = z - double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); - double radius = sqrt(mapc2p_n[0]*mapc2p_n[0] + mapc2p_n[1]*mapc2p_n[1]); + double *mapc2p_n = + gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double radius = sqrt(mapc2p_n[0] * mapc2p_n[0] + mapc2p_n[1] * mapc2p_n[1]); double fout[1]; dmapz_dz(0.0, &theta, fout, 0); double jacob_anal = radius * fout[0]; - TEST_CHECK( gkyl_compare( jacobgeo_n[0], jacob_anal, 1e-5) ); + TEST_CHECK(gkyl_compare(jacobgeo_n[0], jacob_anal, 1e-5)); } } } // Check bmag is what it should be - struct gkyl_array* bmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange, &range, 1, bmag_nodal, gk_geom->geo_corn.bmag, false); - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]; it<=nrange.upper[TH_IDX]; ++it) { + struct gkyl_array *bmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange, &range, 1, bmag_nodal, gk_geom->geo_corn.bmag, false + ); + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX]; it <= nrange.upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = grid.lower[PSI_IDX] + ip*(grid.upper[PSI_IDX]-grid.lower[PSI_IDX])/grid.cells[PSI_IDX]; - double alpha = grid.lower[AL_IDX] + ia*(grid.upper[AL_IDX]-grid.lower[AL_IDX])/grid.cells[AL_IDX]; - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double psi = grid.lower[PSI_IDX] + + ip * (grid.upper[PSI_IDX] - grid.lower[PSI_IDX]) / grid.cells[PSI_IDX]; + double alpha = + grid.lower[AL_IDX] + ia * (grid.upper[AL_IDX] - grid.lower[AL_IDX]) / grid.cells[AL_IDX]; + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; mapz(0.0, &theta, &theta, 0); double xn[3] = {psi, alpha, theta}; double *bmag_n = gkyl_array_fetch(bmag_nodal, gkyl_range_idx(&nrange, cidx)); double bmag_anal[3]; bfield_func(0, xn, bmag_anal, 0); - TEST_CHECK( gkyl_compare( bmag_n[0], bmag_anal[2], 1e-8) ); + TEST_CHECK(gkyl_compare(bmag_n[0], bmag_anal[2], 1e-8)); } } } - // Release memory gkyl_array_release(jacobgeo_nodal); gkyl_array_release(mapc2p_nodal); @@ -507,7 +581,7 @@ test_mapc2p_3x_p1_pmap_ho() } TEST_LIST = { - { "test_mapc2p_3x_p1_ho", test_mapc2p_3x_p1_ho}, - { "test_mapc2p_3x_p1_pmap_ho", test_mapc2p_3x_p1_pmap_ho}, - { NULL, NULL }, + {"test_mapc2p_3x_p1_ho", test_mapc2p_3x_p1_ho}, + {"test_mapc2p_3x_p1_pmap_ho", test_mapc2p_3x_p1_pmap_ho}, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_gk_geometry_mirror.c b/gyrokinetic/unit/ctest_gk_geometry_mirror.c index e22dc46bb5..49266d2728 100644 --- a/gyrokinetic/unit/ctest_gk_geometry_mirror.c +++ b/gyrokinetic/unit/ctest_gk_geometry_mirror.c @@ -15,96 +15,96 @@ #include #include -void -write_geometry(gk_geometry *up, struct gkyl_rect_grid grid, struct gkyl_range local, const char *name) +void write_geometry( + gk_geometry *up, struct gkyl_rect_grid grid, struct gkyl_range local, const char *name +) { const char *fmt = "%s-%s.gkyl"; int sz = gkyl_calc_strlen(fmt, name, "jacobtot_inv"); - char fileNm[sz+1]; // ensure no buffer overflow + char fileNm[sz + 1]; // ensure no buffer overflow sprintf(fileNm, fmt, name, "mapc2p"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2p, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2p, fileNm); sprintf(fileNm, fmt, name, "mapc2nu"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2nu_pos, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2nu_pos, fileNm); sprintf(fileNm, fmt, name, "bmag_corn"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag, fileNm); sprintf(fileNm, fmt, name, "bmag"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bmag, fileNm); sprintf(fileNm, fmt, name, "g_ij"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.g_ij, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.g_ij, fileNm); sprintf(fileNm, fmt, name, "dxdz"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dxdz, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dxdz, fileNm); sprintf(fileNm, fmt, name, "dzdx"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dzdx, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dzdx, fileNm); sprintf(fileNm, fmt, name, "normals"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.normals, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.normals, fileNm); sprintf(fileNm, fmt, name, "jacobgeo"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo, fileNm); sprintf(fileNm, fmt, name, "jacobgeo_inv"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo_inv, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo_inv, fileNm); sprintf(fileNm, fmt, name, "gij"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gij, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gij, fileNm); sprintf(fileNm, fmt, name, "b_i"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.b_i, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.b_i, fileNm); sprintf(fileNm, fmt, name, "bcart"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bcart, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bcart, fileNm); sprintf(fileNm, fmt, name, "cmag"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.cmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.cmag, fileNm); sprintf(fileNm, fmt, name, "jacobtot"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot, fileNm); sprintf(fileNm, fmt, name, "jacobtot_inv"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot_inv, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot_inv, fileNm); sprintf(fileNm, fmt, name, "gxxj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxxj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxxj, fileNm); sprintf(fileNm, fmt, name, "gxyj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxyj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxyj, fileNm); sprintf(fileNm, fmt, name, "gyyj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gyyj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gyyj, fileNm); sprintf(fileNm, fmt, name, "gxzj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxzj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxzj, fileNm); sprintf(fileNm, fmt, name, "eps2"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.eps2, fileNm); - + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.eps2, fileNm); // Create Nodal Range and Grid and Write Nodal Coordinates struct gkyl_range nrange; gkyl_gk_geometry_init_nodal_range(&nrange, &local, up->basis.poly_order); - struct gkyl_array* mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); + struct gkyl_array *mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&up->basis, &grid, false); - gkyl_nodal_ops_m2n(n2m, &up->basis, &grid, &nrange, &local, 3, mc2p_nodal, up->geo_corn.mc2p, false); + gkyl_nodal_ops_m2n( + n2m, &up->basis, &grid, &nrange, &local, 3, mc2p_nodal, up->geo_corn.mc2p, false + ); gkyl_nodal_ops_release(n2m); struct gkyl_rect_grid ngrid; gkyl_gk_geometry_init_nodal_grid(&ngrid, &grid, &nrange); sprintf(fileNm, fmt, name, "nodes"); - gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, fileNm); + gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, fileNm); gkyl_array_release(mc2p_nodal); } -void -test_mirror_load_geometry_ho() +void test_mirror_load_geometry_ho() { - struct gkyl_efit_inp inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/wham.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, - .reflect = true, + struct gkyl_efit_inp inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/wham.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1, + .reflect = true }; clock_t start, end; double cpu_time_used; start = clock(); - double clower[] = { 1e-10, -0.01, -2.0 }; - double cupper[] = { 3e-3, 0.01, 2.0 }; + double clower[] = {1e-10, -0.01, -2.0}; + double cupper[] = {3e-3, 0.01, 2.0}; - int ccells[] = { 4, 4, 8 }; + int ccells[] = {4, 4, 8}; struct gkyl_rect_grid cgrid; gkyl_rect_grid_init(&cgrid, 3, clower, cupper, ccells); struct gkyl_range clocal, clocal_ext; - int cnghost[GKYL_MAX_CDIM] = { 1, 1, 1 }; + int cnghost[GKYL_MAX_CDIM] = {1, 1, 1}; gkyl_create_grid_ranges(&cgrid, cnghost, &clocal_ext, &clocal); int cpoly_order = 1; @@ -114,16 +114,16 @@ test_mirror_load_geometry_ho() struct gkyl_mirror_geo_grid_inp ginp = { .filename_psi = "gyrokinetic/data/unit/wham_hires.geqdsk_psi.gkyl", // psi file to use .rclose = 0.2, // closest R to region of interest - .zmin = -2.0, // Z of lower boundary - .zmax = 2.0, // Z of upper boundary + .zmin = -2.0, // Z of lower boundary + .zmax = 2.0, // Z of upper boundary .include_axis = false, // Include R=0 axis in grid - .fl_coord = GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z, // coordinate system for psi grid + .fl_coord = GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z // coordinate system for psi grid }; struct gkyl_position_map *pmap = gkyl_position_map_null_new(); struct gkyl_gk_geometry_inp geometry_inp = { - .geometry_id = GKYL_GEOMETRY_MIRROR, + .geometry_id = GKYL_GEOMETRY_MIRROR, .mirror_grid_info = ginp, .position_map = pmap, .grid = cgrid, @@ -137,16 +137,16 @@ test_mirror_load_geometry_ho() .geo_local_ext = clocal_ext, .geo_global = clocal, .geo_global_ext = clocal_ext, - .geo_basis = cbasis, + .geo_basis = cbasis }; - struct gk_geometry* up = gkyl_gk_geometry_mirror_new(&geometry_inp); + struct gk_geometry *up = gkyl_gk_geometry_mirror_new(&geometry_inp); //write_geometry(up, cgrid, clocal, "whamlores"); gkyl_gk_geometry_release(up); gkyl_position_map_release(pmap); end = clock(); - cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC; } // def psi_f(R, Z): @@ -154,48 +154,49 @@ test_mirror_load_geometry_ho() // return Bmag/2 * R**2 // Functions for test_3x_straight_cylinder -void mapc2p(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void mapc2p(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double psi = xn[0], alpha = xn[1], zeta = xn[2]; - fout[0] = sqrt(psi * 4 ); // Function fed is psi = 0.25 * R^2 from the efit file - fout[1] = zeta; // Note that this does not have pi-1e-2 in it because the coordinate zeta is always defined -pi to pi + fout[0] = sqrt(psi * 4); // Function fed is psi = 0.25 * R^2 from the efit file + fout[1] = + zeta; // Note that this does not have pi-1e-2 in it because the coordinate zeta is always defined -pi to pi fout[2] = -alpha; // There is a minus due to conventions } -void exact_gij(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_gij(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double r = xn[0], theta = xn[1], phi = xn[2]; - double psi = r*r/4; - fout[0] = 1/psi; // g_11 + double psi = r * r / 4; + fout[0] = 1 / psi; // g_11 fout[1] = 0.0; // g_12 fout[2] = 0.0; // g_13 - fout[3] = r*r; // g_22 + fout[3] = r * r; // g_22 fout[4] = 0.0; // g_23 - fout[5] = 1,0; // g_33 + fout[5] = 1, 0; // g_33 } -void exact_g_contra_ij(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_g_contra_ij(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double r = xn[0], theta = xn[1], phi = xn[2]; - double psi = r*r/4; - fout[0] = r*r/4; // g_11 + double psi = r * r / 4; + fout[0] = r * r / 4; // g_11 fout[1] = 0.0; // g_12 fout[2] = 0.0; // g_13 - fout[3] = 1/psi/4; // g_22 + fout[3] = 1 / psi / 4; // g_22 fout[4] = 0.0; // g_23 fout[5] = 1.0; // g_33 } -void exact_dual_magnitude(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_dual_magnitude(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double r = xn[0], theta = xn[1], phi = xn[2]; - double psi = r*r/4; - fout[0] = r/2; - fout[1] = 1/(2*sqrt(psi)); + double psi = r * r / 4; + fout[0] = r / 2; + fout[1] = 1 / (2 * sqrt(psi)); fout[2] = 1.0; } -void exact_normals(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_normals(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double psi = xn[0], alpha = xn[1], theta = xn[2]; // Remember cylindrical angle = - alpha @@ -210,18 +211,17 @@ void exact_normals(double t, const double *xn, double* GKYL_RESTRICT fout, void fout[8] = 1.0; } -void exact_jacobian(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_jacobian(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 2.0; } - -void bmag_func(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx){ +void bmag_func(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) +{ fout[0] = 0.5; } -void -test_mirror_3x_p1_straight_cylinder_ho() +void test_mirror_3x_p1_straight_cylinder_ho() { // Very similar to the unit test in ctest_gk_geometry.c // The geometry is created to extend from Z = -1 to 1, R = (0.001, 1) in units meters @@ -234,29 +234,29 @@ test_mirror_3x_p1_straight_cylinder_ho() int poly_order = 1; int cdim = 3; gkyl_cart_modal_serendip(&basis, cdim, poly_order); - + double psiMax = 0.2; double psiMin = 0.1; int Nz = 10; double lower[3] = {psiMin, -1.0, -1.0}; - double upper[3] = {psiMax, 1.0, 1.0}; + double upper[3] = {psiMax, 1.0, 1.0}; // int cells[3] = { 18, 18, Nz }; - int cells[3] = { 2, 2, 2}; + int cells[3] = {2, 2, 2}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, cdim, lower, upper, cells); - + struct gkyl_range ext_range, range; - int nghost[3] = { 1,1,1}; + int nghost[3] = {1, 1, 1}; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); struct gkyl_mirror_geo_grid_inp ginp = { .filename_psi = "gyrokinetic/data/unit/straight_cylinder.geqdsk_psi.gkyl", // psi file to use .rclose = 0.5, // closest R to region of interest - .zmin = -1.0, // Z of lower boundary - .zmax = 1.0, // Z of upper boundary + .zmin = -1.0, // Z of lower boundary + .zmax = 1.0, // Z of upper boundary .include_axis = false, // Include R=0 axis in grid - .fl_coord = GKYL_GEOMETRY_MIRROR_GRID_GEN_PSI_CART_Z, // coordinate system for psi grid + .fl_coord = GKYL_GEOMETRY_MIRROR_GRID_GEN_PSI_CART_Z // coordinate system for psi grid }; struct gkyl_position_map *pos_map = gkyl_position_map_null_new(); @@ -277,7 +277,7 @@ test_mirror_3x_p1_straight_cylinder_ho() .geo_local_ext = ext_range, .geo_global = range, .geo_global_ext = ext_range, - .geo_basis = basis, + .geo_basis = basis }; struct gk_geometry *gk_geom = gkyl_gk_geometry_mirror_new(&geometry_input); @@ -287,50 +287,58 @@ test_mirror_3x_p1_straight_cylinder_ho() // Define nodal operations enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates int cidx[3]; - int nodes[] = { 1, 1, 1 }; - for (int d=0; dgeo_corn.mc2p, false); - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]; it<=nrange.upper[TH_IDX]; ++it) { + struct gkyl_array *mapc2p_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange, &range, 3, mapc2p_nodal, gk_geom->geo_corn.mc2p, false + ); + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX]; it <= nrange.upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = grid.lower[PSI_IDX] + ip*(grid.upper[PSI_IDX]-grid.lower[PSI_IDX])/grid.cells[PSI_IDX]; - double alpha = grid.lower[AL_IDX] + ia*(grid.upper[AL_IDX]-grid.lower[AL_IDX])/grid.cells[AL_IDX]; - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double psi = grid.lower[PSI_IDX] + + ip * (grid.upper[PSI_IDX] - grid.lower[PSI_IDX]) / grid.cells[PSI_IDX]; + double alpha = + grid.lower[AL_IDX] + ia * (grid.upper[AL_IDX] - grid.lower[AL_IDX]) / grid.cells[AL_IDX]; + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; // geo_corn.mapc2p_nodal - double *mapc2p_n = gkyl_array_fetch(gk_geom->geo_corn.mc2p_nodal, gkyl_range_idx(&nrange, cidx)); + double *mapc2p_n = + gkyl_array_fetch(gk_geom->geo_corn.mc2p_nodal, gkyl_range_idx(&nrange, cidx)); double xn[3] = {psi, -alpha, theta}; double fout[3]; mapc2p(0.0, xn, fout, 0); - for (int i=0; i<3; ++i) - TEST_CHECK( gkyl_compare( mapc2p_n[i], fout[i], 1e-8) ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mapc2p_n[i], fout[i], 1e-8)); + } // geo_corn.mc2p double *mapc2p = gkyl_array_fetch(mapc2p_nodal, gkyl_range_idx(&nrange, cidx)); - for (int i=0; i<3; ++i) - TEST_CHECK( gkyl_compare( mapc2p[i], fout[i], 1e-8) ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mapc2p[i], fout[i], 1e-8)); + } // geo_corn.mc2p_deflated not tested because it's populated elsewhere } @@ -338,60 +346,71 @@ test_mirror_3x_p1_straight_cylinder_ho() } // Check mc2nu_pos - struct gkyl_array* mc2nu_pos_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange, &range, 3, mc2nu_pos_nodal, gk_geom->geo_corn.mc2nu_pos, false); - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]; it<=nrange.upper[TH_IDX]; ++it) { + struct gkyl_array *mc2nu_pos_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange, &range, 3, mc2nu_pos_nodal, gk_geom->geo_corn.mc2nu_pos, false + ); + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX]; it <= nrange.upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = grid.lower[PSI_IDX] + ip*(grid.upper[PSI_IDX]-grid.lower[PSI_IDX])/grid.cells[PSI_IDX]; - double alpha = grid.lower[AL_IDX] + ia*(grid.upper[AL_IDX]-grid.lower[AL_IDX])/grid.cells[AL_IDX]; - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double psi = grid.lower[PSI_IDX] + + ip * (grid.upper[PSI_IDX] - grid.lower[PSI_IDX]) / grid.cells[PSI_IDX]; + double alpha = + grid.lower[AL_IDX] + ia * (grid.upper[AL_IDX] - grid.lower[AL_IDX]) / grid.cells[AL_IDX]; + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; double xn[3] = {psi, alpha, theta}; // geo_corn.mc2nu_pos double *mc2nu_pos_n = gkyl_array_fetch(mc2nu_pos_nodal, gkyl_range_idx(&nrange, cidx)); - for (int i=0; i<3; ++i) - TEST_CHECK( gkyl_compare( mc2nu_pos_n[i], xn[i], 1e-8) ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mc2nu_pos_n[i], xn[i], 1e-8)); + } // geo_corn.mc2nu_pos_nodal - double *mc2nu_pos = gkyl_array_fetch(gk_geom->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(&nrange, cidx)); - for (int i=0; i<3; ++i) - TEST_CHECK( gkyl_compare( mc2nu_pos[i], xn[i], 1e-8) ); + double *mc2nu_pos = + gkyl_array_fetch(gk_geom->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(&nrange, cidx)); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mc2nu_pos[i], xn[i], 1e-8)); + } // geo_corn.mc2nu_pos_deflated not tested because it's populated elsewhere } } } - - - // Check bmag is what it should be - struct gkyl_array* bmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange, &range, 1, bmag_nodal, gk_geom->geo_corn.bmag, false); - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]; it<=nrange.upper[TH_IDX]; ++it) { + struct gkyl_array *bmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange, &range, 1, bmag_nodal, gk_geom->geo_corn.bmag, false + ); + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX]; it <= nrange.upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = grid.lower[PSI_IDX] + ip*(grid.upper[PSI_IDX]-grid.lower[PSI_IDX])/grid.cells[PSI_IDX]; - double alpha = grid.lower[AL_IDX] + ia*(grid.upper[AL_IDX]-grid.lower[AL_IDX])/grid.cells[AL_IDX]; - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double psi = grid.lower[PSI_IDX] + + ip * (grid.upper[PSI_IDX] - grid.lower[PSI_IDX]) / grid.cells[PSI_IDX]; + double alpha = + grid.lower[AL_IDX] + ia * (grid.upper[AL_IDX] - grid.lower[AL_IDX]) / grid.cells[AL_IDX]; + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; double xn[3] = {psi, -alpha, theta}; // geo_corn.bmag double *bmag_n = gkyl_array_fetch(bmag_nodal, gkyl_range_idx(&nrange, cidx)); double bmag_anal[1]; bmag_func(0, xn, bmag_anal, 0); - TEST_CHECK( gkyl_compare( bmag_n[0], bmag_anal[0], 1e-7) ); + TEST_CHECK(gkyl_compare(bmag_n[0], bmag_anal[0], 1e-7)); // geo_corn.bmag_nodal - double *bmag = gkyl_array_fetch(gk_geom->geo_corn.bmag_nodal, gkyl_range_idx(&nrange, cidx)); - TEST_CHECK( gkyl_compare( bmag[0], bmag_anal[0], 1e-7) ); + double *bmag = + gkyl_array_fetch(gk_geom->geo_corn.bmag_nodal, gkyl_range_idx(&nrange, cidx)); + TEST_CHECK(gkyl_compare(bmag[0], bmag_anal[0], 1e-7)); } } } @@ -399,283 +418,390 @@ test_mirror_3x_p1_straight_cylinder_ho() // Second let's validate geo_int. Many coponents still need to be added // Plus 3 away from axis to avoid errors - double dels[2] = {1.0/sqrt(3), 1.0-1.0/sqrt(3) }; - double theta_lo = grid.lower[TH_IDX] + dels[1]*grid.dx[TH_IDX]/2.0; - double psi_lo = grid.lower[PSI_IDX] + dels[1]*grid.dx[PSI_IDX]/2.0; - double alpha_lo = grid.lower[AL_IDX] + dels[1]*grid.dx[AL_IDX]/2.0; - + double dels[2] = {1.0 / sqrt(3), 1.0 - 1.0 / sqrt(3)}; + double theta_lo = grid.lower[TH_IDX] + dels[1] * grid.dx[TH_IDX] / 2.0; + double psi_lo = grid.lower[PSI_IDX] + dels[1] * grid.dx[PSI_IDX] / 2.0; + double alpha_lo = grid.lower[AL_IDX] + dels[1] * grid.dx[AL_IDX] / 2.0; // geo_int.mc2p - struct gkyl_array* mc2p_nodal_interior = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, mc2p_nodal_interior, gk_geom->geo_int.mc2p, true); + struct gkyl_array *mc2p_nodal_interior = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, mc2p_nodal_interior, + gk_geom->geo_int.mc2p, true + ); // Check that the mapc2p is what it should be - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *mc2p_n = gkyl_array_fetch(mc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); - - double psi= calc_running_coord(psi_lo, ip-nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); - double alpha= calc_running_coord(alpha_lo, ia-nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); - double theta= calc_running_coord(theta_lo, it-nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); + double *mc2p_n = + gkyl_array_fetch(mc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + + double psi = + calc_running_coord(psi_lo, ip - nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); + double alpha = + calc_running_coord(alpha_lo, ia - nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); + double theta = + calc_running_coord(theta_lo, it - nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); double xn[3] = {psi, -alpha, theta}; double fout[3]; mapc2p(0.0, xn, fout, 0); - for (int i=0; i<3; ++i) { - TEST_CHECK( gkyl_compare( mc2p_n[i], fout[i], 1e-8) ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mc2p_n[i], fout[i], 1e-8)); } // geo_int.mc2p_nodal - double *mc2p = gkyl_array_fetch(gk_geom->geo_int.mc2p_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - for (int i=0; i<3; ++i) { - TEST_CHECK( gkyl_compare( mc2p[i], fout[i], 1e-8) ); + double *mc2p = gkyl_array_fetch( + gk_geom->geo_int.mc2p_nodal, gkyl_range_idx(&nrange_quad_interior, cidx) + ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mc2p[i], fout[i], 1e-8)); } } } } // geo_int.bmag - struct gkyl_array* bmag_nodal_interior = gkyl_array_new(GKYL_DOUBLE, 1, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, bmag_nodal_interior, gk_geom->geo_int.bmag, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { - double *bmag_n = gkyl_array_fetch(bmag_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + struct gkyl_array *bmag_nodal_interior = + gkyl_array_new(GKYL_DOUBLE, 1, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, bmag_nodal_interior, + gk_geom->geo_int.bmag, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { + double *bmag_n = + gkyl_array_fetch(bmag_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); double fout[1]; bmag_func(0.0, NULL, fout, 0); - TEST_CHECK( gkyl_compare( bmag_n[0], fout[0], 1e-8) ); + TEST_CHECK(gkyl_compare(bmag_n[0], fout[0], 1e-8)); // geo_int.bmag_nodal - double *bmag = gkyl_array_fetch(gk_geom->geo_int.bmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - TEST_CHECK( gkyl_compare( bmag[0], fout[0], 1e-8) ); + double *bmag = gkyl_array_fetch( + gk_geom->geo_int.bmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx) + ); + TEST_CHECK(gkyl_compare(bmag[0], fout[0], 1e-8)); } } - } - + } // geo_int.g_ij - struct gkyl_array* gij_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_nodal, gk_geom->geo_int.g_ij, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *gij_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_nodal, gk_geom->geo_int.g_ij, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; double *gij_n = gkyl_array_fetch(gij_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double *mapc2p_n = gkyl_array_fetch(mc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *mapc2p_n = + gkyl_array_fetch(mc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); double r = mapc2p_n[0]; double xn[3] = {r, 0.0, 0.0}; double fout[6]; exact_gij(0.0, xn, fout, 0); - for (int i=0; i<6; ++i) - TEST_CHECK( gkyl_compare( gij_n[i], fout[i], 1e-6) ); + for (int i = 0; i < 6; ++i) { + TEST_CHECK(gkyl_compare(gij_n[i], fout[i], 1e-6)); + } // geo_int.g_ij_nodal - double *gij = gkyl_array_fetch(gk_geom->geo_int.g_ij_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - for (int i=0; i<6; ++i) - TEST_CHECK( gkyl_compare( gij[i], fout[i], 1e-6) ); + double *gij = gkyl_array_fetch( + gk_geom->geo_int.g_ij_nodal, gkyl_range_idx(&nrange_quad_interior, cidx) + ); + for (int i = 0; i < 6; ++i) { + TEST_CHECK(gkyl_compare(gij[i], fout[i], 1e-6)); + } } } } // geo_int.gij - struct gkyl_array* gij_contra_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_contra_nodal, gk_geom->geo_int.gij, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *gij_contra_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_contra_nodal, gk_geom->geo_int.gij, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *gij_contra_n = gkyl_array_fetch(gij_contra_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double *mapc2p_n = gkyl_array_fetch(mc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *gij_contra_n = + gkyl_array_fetch(gij_contra_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *mapc2p_n = + gkyl_array_fetch(mc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); double r = mapc2p_n[0]; double xn[3] = {r, 0.0, 0.0}; double fout[6]; exact_g_contra_ij(0.0, xn, fout, 0); - for (int i=0; i<6; ++i) - TEST_CHECK( gkyl_compare( gij_contra_n[i], fout[i], 1e-6) ); + for (int i = 0; i < 6; ++i) { + TEST_CHECK(gkyl_compare(gij_contra_n[i], fout[i], 1e-6)); + } // geo_int.gij_nodal does not exist } } } - // Check that |bhat|=1 at nodes - struct gkyl_array* bhat_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, bhat_nodal, gk_geom->geo_int.bcart, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *bhat_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, bhat_nodal, gk_geom->geo_int.bcart, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; double *bhat_n = gkyl_array_fetch(bhat_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double bhat_mag = sqrt(bhat_n[0]*bhat_n[0] + bhat_n[1]*bhat_n[1] + bhat_n[2]*bhat_n[2]); - TEST_CHECK( gkyl_compare( bhat_mag, 1.0, 1e-12) ); + double bhat_mag = + sqrt(bhat_n[0] * bhat_n[0] + bhat_n[1] * bhat_n[1] + bhat_n[2] * bhat_n[2]); + TEST_CHECK(gkyl_compare(bhat_mag, 1.0, 1e-12)); // geo_int.bcart_nodal - double *bhat = gkyl_array_fetch(gk_geom->geo_int.bcart_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double bhat_mag_nodal = sqrt(bhat[0]*bhat[0] + bhat[1]*bhat[1] + bhat[2]*bhat[2]); - TEST_CHECK( gkyl_compare( bhat_mag_nodal, 1.0, 1e-12) ); + double *bhat = gkyl_array_fetch( + gk_geom->geo_int.bcart_nodal, gkyl_range_idx(&nrange_quad_interior, cidx) + ); + double bhat_mag_nodal = sqrt(bhat[0] * bhat[0] + bhat[1] * bhat[1] + bhat[2] * bhat[2]); + TEST_CHECK(gkyl_compare(bhat_mag_nodal, 1.0, 1e-12)); } } } // Check that the duals are what they should be // There are errors at low psi, so we shift away from the axis by a few cells - struct gkyl_array* dualmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, dualmag_nodal, gk_geom->geo_int.dualmag, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX] + 3; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *dualmag_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, dualmag_nodal, gk_geom->geo_int.dualmag, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX] + 3; + ip <= nrange_quad_interior.upper[PSI_IDX]; ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *dualmag_n = gkyl_array_fetch(dualmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double *mapc2p_n = gkyl_array_fetch(mc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *dualmag_n = + gkyl_array_fetch(dualmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *mapc2p_n = + gkyl_array_fetch(mc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); double xn[3] = {mapc2p_n[0], mapc2p_n[1], mapc2p_n[2]}; double dualmag_anal[3]; exact_dual_magnitude(0, xn, dualmag_anal, 0); - TEST_CHECK( gkyl_compare( dualmag_n[0], dualmag_anal[0], 1e-6) ); - TEST_CHECK( gkyl_compare( dualmag_n[1], dualmag_anal[1], 1e-6) ); - TEST_CHECK( gkyl_compare( dualmag_n[2], dualmag_anal[2], 1e-6) ); + TEST_CHECK(gkyl_compare(dualmag_n[0], dualmag_anal[0], 1e-6)); + TEST_CHECK(gkyl_compare(dualmag_n[1], dualmag_anal[1], 1e-6)); + TEST_CHECK(gkyl_compare(dualmag_n[2], dualmag_anal[2], 1e-6)); // geo_int.dualmag_nodal - double *dualmag = gkyl_array_fetch(gk_geom->geo_int.dualmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - TEST_CHECK( gkyl_compare( dualmag[0], dualmag_anal[0], 1e-6) ); - TEST_CHECK( gkyl_compare( dualmag[1], dualmag_anal[1], 1e-6) ); - TEST_CHECK( gkyl_compare( dualmag[2], dualmag_anal[2], 1e-6) ); + double *dualmag = gkyl_array_fetch( + gk_geom->geo_int.dualmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx) + ); + TEST_CHECK(gkyl_compare(dualmag[0], dualmag_anal[0], 1e-6)); + TEST_CHECK(gkyl_compare(dualmag[1], dualmag_anal[1], 1e-6)); + TEST_CHECK(gkyl_compare(dualmag[2], dualmag_anal[2], 1e-6)); } } } // Check cmag = 1 - struct gkyl_array* cmag_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, cmag_nodal, gk_geom->geo_int.cmag, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *cmag_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, cmag_nodal, gk_geom->geo_int.cmag, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; double *cmag_n = gkyl_array_fetch(cmag_nodal, gkyl_range_idx(&nrange, cidx)); - TEST_CHECK( gkyl_compare( cmag_n[0], 1.0, 1e-8) ); + TEST_CHECK(gkyl_compare(cmag_n[0], 1.0, 1e-8)); } } } - // Check that Jacobgeo is what it should be. This is the Jacobian for the problem - struct gkyl_array* jacobgeo_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_nodal, gk_geom->geo_int.jacobgeo, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *jacobgeo_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_nodal, gk_geom->geo_int.jacobgeo, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; double *jacobgeo_n = gkyl_array_fetch(jacobgeo_nodal, gkyl_range_idx(&nrange, cidx)); double fout[1]; exact_jacobian(0.0, NULL, fout, 0); - TEST_CHECK( gkyl_compare( jacobgeo_n[0], fout[0], 1e-6) ); + TEST_CHECK(gkyl_compare(jacobgeo_n[0], fout[0], 1e-6)); // geo_int.jacobgeo_nodal - double *jacobgeo = gkyl_array_fetch(gk_geom->geo_int.jacobgeo_nodal, gkyl_range_idx(&nrange, cidx)); - TEST_CHECK( gkyl_compare( jacobgeo[0], fout[0], 1e-6) ); + double *jacobgeo = + gkyl_array_fetch(gk_geom->geo_int.jacobgeo_nodal, gkyl_range_idx(&nrange, cidx)); + TEST_CHECK(gkyl_compare(jacobgeo[0], fout[0], 1e-6)); } } } // Check jacobgeo_inv - struct gkyl_array* jacobgeo_inv_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_inv_nodal, gk_geom->geo_int.jacobgeo_inv, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *jacobgeo_inv_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_inv_nodal, + gk_geom->geo_int.jacobgeo_inv, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobgeo_inv_n = gkyl_array_fetch(jacobgeo_inv_nodal, gkyl_range_idx(&nrange, cidx)); + double *jacobgeo_inv_n = + gkyl_array_fetch(jacobgeo_inv_nodal, gkyl_range_idx(&nrange, cidx)); double fout[1]; exact_jacobian(0.0, NULL, fout, 0); - TEST_CHECK( gkyl_compare( jacobgeo_inv_n[0], 1/fout[0], 1e-6) ); + TEST_CHECK(gkyl_compare(jacobgeo_inv_n[0], 1 / fout[0], 1e-6)); } } } // Check jacobtot - struct gkyl_array* jacobtot_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_nodal, gk_geom->geo_int.jacobtot, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *jacobtot_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_nodal, gk_geom->geo_int.jacobtot, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobtot_n = gkyl_array_fetch(jacobtot_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *jacobtot_n = + gkyl_array_fetch(jacobtot_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); // mapc2p_n[0] = x, mapc2p_n[1] = y, mapc2p_n[2] = z double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal, gkyl_range_idx(&nrange, cidx)); double foutJ[1]; exact_jacobian(0.0, NULL, foutJ, 0); double foutB[1]; bmag_func(0.0, NULL, foutB, 0); - TEST_CHECK( gkyl_compare( jacobtot_n[0], foutJ[0]*foutB[0], 1e-6) ); + TEST_CHECK(gkyl_compare(jacobtot_n[0], foutJ[0] * foutB[0], 1e-6)); } } } // Check jacobtot_inv - struct gkyl_array* jacobtot_inv_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_inv_nodal, gk_geom->geo_int.jacobtot_inv, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *jacobtot_inv_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_inv_nodal, + gk_geom->geo_int.jacobtot_inv, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobtot_inv_n = gkyl_array_fetch(jacobtot_inv_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *jacobtot_inv_n = + gkyl_array_fetch(jacobtot_inv_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); // mapc2p_n[0] = x, mapc2p_n[1] = y, mapc2p_n[2] = z double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal, gkyl_range_idx(&nrange, cidx)); double foutJ[1]; exact_jacobian(0.0, NULL, foutJ, 0); double foutB[1]; bmag_func(0.0, NULL, foutB, 0); - TEST_CHECK( gkyl_compare( jacobtot_inv_n[0], 1/foutJ[0]/foutB[0], 1e-6) ); + TEST_CHECK(gkyl_compare(jacobtot_inv_n[0], 1 / foutJ[0] / foutB[0], 1e-6)); } } } - // Check normals // Plus 3 away from axis to avoid errors - struct gkyl_array* normals_nodal = gkyl_array_new(GKYL_DOUBLE, 9*basis.num_basis, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 9*basis.num_basis, normals_nodal, gk_geom->geo_int.normals, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]+3; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *normals_nodal = + gkyl_array_new(GKYL_DOUBLE, 9 * basis.num_basis, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 9 * basis.num_basis, normals_nodal, + gk_geom->geo_int.normals, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX] + 3; + ip <= nrange_quad_interior.upper[PSI_IDX]; ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *normals_n = gkyl_array_fetch(normals_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double psi= calc_running_coord(psi_lo, ia-nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); - double alpha= calc_running_coord(alpha_lo, ia-nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); - double theta= calc_running_coord(theta_lo, ia-nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); + double *normals_n = + gkyl_array_fetch(normals_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double psi = + calc_running_coord(psi_lo, ia - nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); + double alpha = + calc_running_coord(alpha_lo, ia - nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); + double theta = + calc_running_coord(theta_lo, ia - nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); double xn[3] = {psi, alpha, theta}; double fout[9]; exact_normals(0.0, xn, fout, 0); - for (int i=0; i<9; ++i) { - TEST_CHECK( gkyl_compare( normals_n[i], fout[i], 1e-3) ); + for (int i = 0; i < 9; ++i) { + TEST_CHECK(gkyl_compare(normals_n[i], fout[i], 1e-3)); } // geo_int.normals_nodal - double *normals = gkyl_array_fetch(gk_geom->geo_int.normals_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - for (int i=0; i<9; ++i) { - TEST_CHECK( gkyl_compare( normals[i], fout[i], 1e-3) ); + double *normals = gkyl_array_fetch( + gk_geom->geo_int.normals_nodal, gkyl_range_idx(&nrange_quad_interior, cidx) + ); + for (int i = 0; i < 9; ++i) { + TEST_CHECK(gkyl_compare(normals[i], fout[i], 1e-3)); } } } @@ -689,98 +815,140 @@ test_mirror_3x_p1_straight_cylinder_ho() // create mirror geometry for surfaces struct gkyl_mirror_grid_gen *mirror_grid_surf[3]; for (int dir = 0; dir < cdim; dir++) { - mirror_grid_surf[dir] = - gkyl_mirror_grid_gen_surf_inew(&(struct gkyl_mirror_grid_gen_inp) { - .comp_grid = &grid, - .nrange = gk_geom->nrange_surf[dir], - .local = gk_geom->local, - .global = gk_geom->global, - .dir = dir, - .position_map = pos_map, - - .R = { psi_grid.lower[0], psi_grid.upper[0] }, - .Z = { psi_grid.lower[1], psi_grid.upper[1] }, - - // psi(R,Z) grid size - .nrcells = psi_grid.cells[0]-1, // cells and not nodes - .nzcells = psi_grid.cells[1]-1, // cells and not nodes - - .psiRZ = psi, - .fl_coord = ginp.fl_coord, - .include_axis = ginp.include_axis, - .write_psi_cubic = false, - } - ); + mirror_grid_surf[dir] = gkyl_mirror_grid_gen_surf_inew(&(struct gkyl_mirror_grid_gen_inp + ){.comp_grid = &grid, + .nrange = gk_geom->nrange_surf[dir], + .local = gk_geom->local, + .global = gk_geom->global, + .dir = dir, + .position_map = pos_map, + + .R = {psi_grid.lower[0], psi_grid.upper[0]}, + .Z = {psi_grid.lower[1], psi_grid.upper[1]}, + + // psi(R,Z) grid size + .nrcells = psi_grid.cells[0] - 1, // cells and not nodes + .nzcells = psi_grid.cells[1] - 1, // cells and not nodes + + .psiRZ = psi, + .fl_coord = ginp.fl_coord, + .include_axis = ginp.include_axis, + .write_psi_cubic = false}); } - for (int dir = 0; dir < cdim; dir++){ + for (int dir = 0; dir < cdim; dir++) { enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { R_IDX, Z_IDX, PHI_IDX }; // arrangement of cartesian coordinates int cidx[3]; - for(int ia=gk_geom->nrange_surf[dir].lower[AL_IDX]; ia<=gk_geom->nrange_surf[dir].upper[AL_IDX]; ++ia){ - for (int ip=gk_geom->nrange_surf[dir].lower[PSI_IDX]; ip<=gk_geom->nrange_surf[dir].upper[PSI_IDX]; ++ip) { - for (int it=gk_geom->nrange_surf[dir].lower[TH_IDX]; it<=gk_geom->nrange_surf[dir].upper[TH_IDX]; ++it) { + for (int ia = gk_geom->nrange_surf[dir].lower[AL_IDX]; + ia <= gk_geom->nrange_surf[dir].upper[AL_IDX]; ++ia) { + for (int ip = gk_geom->nrange_surf[dir].lower[PSI_IDX]; + ip <= gk_geom->nrange_surf[dir].upper[PSI_IDX]; ++ip) { + for (int it = gk_geom->nrange_surf[dir].lower[TH_IDX]; + it <= gk_geom->nrange_surf[dir].upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; // First fetch the mirror stuff at this location - const double *mirror_rza_n = gkyl_array_cfetch(mirror_grid_surf[dir]->nodes_rza, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - const double *mirror_psi_n = gkyl_array_cfetch(mirror_grid_surf[dir]->nodes_psi, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - const struct gkyl_mirror_grid_gen_geom *mirror_geo_n = gkyl_array_cfetch(mirror_grid_surf[dir]->nodes_geom, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + const double *mirror_rza_n = gkyl_array_cfetch( + mirror_grid_surf[dir]->nodes_rza, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + const double *mirror_psi_n = gkyl_array_cfetch( + mirror_grid_surf[dir]->nodes_psi, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + const struct gkyl_mirror_grid_gen_geom *mirror_geo_n = gkyl_array_cfetch( + mirror_grid_surf[dir]->nodes_geom, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); const double psi = mirror_psi_n[0]; const double alpha = mirror_rza_n[2]; const double theta = mirror_rza_n[1]; // Next fetch the gk_geometry nodal values at this location - double *mc2p_n = gkyl_array_fetch(gk_geom->geo_surf[dir].mc2p_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *jFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *bmag_n = gkyl_array_fetch(gk_geom->geo_surf[dir].bmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *gFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *biFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].b_i_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *cmagFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].cmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *bcartFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].bcart_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *tanvecFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *dualFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *dualmagFld_n = gkyl_array_fetch(gk_geom->geo_surf[dir].dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *normFld_n = gkyl_array_fetch(gk_geom->geo_surf[dir].normals_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *lenr_n = gkyl_array_fetch(gk_geom->geo_surf[dir].lenr_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *B3_n = gkyl_array_fetch(gk_geom->geo_surf[dir].B3_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *curlbhat_n = gkyl_array_fetch(gk_geom->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *normcurlbhat_n = gkyl_array_fetch(gk_geom->geo_surf[dir].normcurlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + double *mc2p_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].mc2p_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *jFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *bmag_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].bmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *gFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *biFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].b_i_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *cmagFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].cmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *bcartFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].bcart_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *tanvecFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *dualFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *dualmagFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *normFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].normals_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *lenr_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].lenr_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *B3_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].B3_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *curlbhat_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *normcurlbhat_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].normcurlbhat_nodal, + gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); // Check mapc2p double fout[8]; mapc2p(0.0, (double[]){psi, -alpha, theta}, fout, 0); - for (int i=0; i<3; ++i) - TEST_CHECK( gkyl_compare( fout[i], mc2p_n[i], 1e-8) ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(fout[i], mc2p_n[i], 1e-8)); + } // Check Jacobian double jgeo; exact_jacobian(0, (double[]){psi, -alpha, theta}, &jgeo, 0); - TEST_CHECK( gkyl_compare( jgeo, jFld_n[0], 1e-6) ); + TEST_CHECK(gkyl_compare(jgeo, jFld_n[0], 1e-6)); // Check bmag double bmag_anal[1]; bmag_func(0, (double[]){psi, -alpha, theta}, bmag_anal, 0); - TEST_CHECK( gkyl_compare( bmag_n[0], bmag_anal[0], 1e-7) ); + TEST_CHECK(gkyl_compare(bmag_n[0], bmag_anal[0], 1e-7)); // Check b_i (magnetic unit vector should have magnitude 1) - double bi_mag = sqrt(biFld_n[0]*biFld_n[0] + biFld_n[1]*biFld_n[1] + biFld_n[2]*biFld_n[2]); - TEST_CHECK( gkyl_compare( bi_mag, 1.0, 1e-8) ); + double bi_mag = + sqrt(biFld_n[0] * biFld_n[0] + biFld_n[1] * biFld_n[1] + biFld_n[2] * biFld_n[2]); + TEST_CHECK(gkyl_compare(bi_mag, 1.0, 1e-8)); // Check cmag (curvature magnitude should be 1 for straight cylinder) - TEST_CHECK( gkyl_compare( cmagFld_n[0], 1.0, 1e-8) ); + TEST_CHECK(gkyl_compare(cmagFld_n[0], 1.0, 1e-8)); // Check normals (surface normal vectors) - double norm_mag = sqrt(normFld_n[0]*normFld_n[0] + normFld_n[1]*normFld_n[1] + normFld_n[2]*normFld_n[2]); - TEST_CHECK( gkyl_compare( norm_mag, 1.0, 1e-8) ); + double norm_mag = sqrt( + normFld_n[0] * normFld_n[0] + normFld_n[1] * normFld_n[1] + normFld_n[2] * normFld_n[2] + ); + TEST_CHECK(gkyl_compare(norm_mag, 1.0, 1e-8)); // Check that dual magnitude is consistent - double dual_mag = sqrt(dualFld_n[0]*dualFld_n[0] + dualFld_n[1]*dualFld_n[1] + dualFld_n[2]*dualFld_n[2]); - TEST_CHECK( gkyl_compare( dual_mag, dualmagFld_n[0], 1e-8) ); - + double dual_mag = sqrt( + dualFld_n[0] * dualFld_n[0] + dualFld_n[1] * dualFld_n[1] + dualFld_n[2] * dualFld_n[2] + ); + TEST_CHECK(gkyl_compare(dual_mag, dualmagFld_n[0], 1e-8)); } } } @@ -809,65 +977,63 @@ test_mirror_3x_p1_straight_cylinder_ho() gkyl_gk_geometry_release(gk_geom); } -void -mapz(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void mapz(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double a = 2.0; double s = 0.2; - fout[0] = (-1/(2*a) * pow(a - xn[0], 2) + a)*(1-s) + s * xn[0]; + fout[0] = (-1 / (2 * a) * pow(a - xn[0], 2) + a) * (1 - s) + s * xn[0]; } -void -dmapz_dz(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void dmapz_dz(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double a = 2.0; double s = 0.2; - fout[0] = (1/a * pow(a - xn[0], 1))*(1-s) + s; + fout[0] = (1 / a * pow(a - xn[0], 1)) * (1 - s) + s; } -void exact_gij_pmap(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_gij_pmap(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double psi = xn[0], alpha = xn[1], theta = xn[2]; - double r = 2*sqrt(psi); + double r = 2 * sqrt(psi); double dThetadtheta; dmapz_dz(0, &theta, &dThetadtheta, 0); - fout[0] = 1/psi; // g_11 + fout[0] = 1 / psi; // g_11 fout[1] = 0.0; // g_12 fout[2] = 0.0; // g_13 - fout[3] = r*r; // g_22 + fout[3] = r * r; // g_22 fout[4] = 0.0; // g_23 - fout[5] = 1.0 * pow(dThetadtheta,2); // g_33 + fout[5] = 1.0 * pow(dThetadtheta, 2); // g_33 } -void exact_g_contra_ij_pmap(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_g_contra_ij_pmap(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double psi = xn[0], alpha = xn[1], theta = xn[2]; - double r = 2*sqrt(psi); + double r = 2 * sqrt(psi); double dThetadtheta; dmapz_dz(0, &theta, &dThetadtheta, 0); - fout[0] = r*r/4; // g_11 + fout[0] = r * r / 4; // g_11 fout[1] = 0.0; // g_12 fout[2] = 0.0; // g_13 - fout[3] = 1/psi/4; // g_22 + fout[3] = 1 / psi / 4; // g_22 fout[4] = 0.0; // g_23 - fout[5] = 1.0 / pow(dThetadtheta,2); // g_33 + fout[5] = 1.0 / pow(dThetadtheta, 2); // g_33 } -void exact_dual_magnitude_pmap(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_dual_magnitude_pmap(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double psi = xn[0], alpha = xn[1], theta = xn[2]; - double r = 2*sqrt(psi); + double r = 2 * sqrt(psi); double dThetadtheta; dmapz_dz(0, &theta, &dThetadtheta, 0); - fout[0] = r/2; - fout[1] = 1/(2*sqrt(psi)); + fout[0] = r / 2; + fout[1] = 1 / (2 * sqrt(psi)); fout[2] = 1.0 / dThetadtheta; } -void exact_normals_pmap(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_normals_pmap(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double psi = xn[0], alpha = xn[1], theta = xn[2]; - double r = 2*sqrt(psi); + double r = 2 * sqrt(psi); double dThetadtheta; dmapz_dz(0, &theta, &dThetadtheta, 0); // Remember cylindrical angle = - alpha @@ -882,47 +1048,43 @@ void exact_normals_pmap(double t, const double *xn, double* GKYL_RESTRICT fout, fout[8] = -1.0; } -void -test_mirror_3x_p1_pmap_straight_cylinder_ho() +void test_mirror_3x_p1_pmap_straight_cylinder_ho() { // Same as the above test, but using a quadratic position map struct gkyl_basis basis; int poly_order = 1; int cdim = 3; gkyl_cart_modal_serendip(&basis, cdim, poly_order); - + double psiMax = 0.2; double psiMin = 0.1; int Nz = 10; double lower[3] = {psiMin, -M_PI, -2.0}; - double upper[3] = {psiMax, M_PI, 2.0}; + double upper[3] = {psiMax, M_PI, 2.0}; // int cells[3] = { 18, 18, Nz }; - int cells[3] = { 8, 1, 8}; + int cells[3] = {8, 1, 8}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, cdim, lower, upper, cells); - + struct gkyl_range ext_range, range; - int nghost[3] = { 1,1,1}; + int nghost[3] = {1, 1, 1}; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); - struct gkyl_position_map_inp pos_map_inp = { - .maps = {0, 0, mapz}, - .ctxs = {0, 0, 0}, - }; + struct gkyl_position_map_inp pos_map_inp = {.maps = {0, 0, mapz}, .ctxs = {0, 0, 0}}; // Configuration space geometry initialization - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp, grid, range, - ext_range, range, ext_range, basis); + struct gkyl_position_map *pos_map = + gkyl_position_map_new(pos_map_inp, grid, range, ext_range, range, ext_range, basis); struct gkyl_mirror_geo_grid_inp ginp = { .filename_psi = "gyrokinetic/data/unit/wham_hires.geqdsk_psi.gkyl", // psi file to use .rclose = 0.2, // closest R to region of interest - .zmin = -2.0, // Z of lower boundary - .zmax = 2.0, // Z of upper boundary + .zmin = -2.0, // Z of lower boundary + .zmax = 2.0, // Z of upper boundary .include_axis = false, // Include R=0 axis in grid - .fl_coord = GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z, // coordinate system for psi grid + .fl_coord = GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z // coordinate system for psi grid }; // Initialize geometry @@ -941,7 +1103,7 @@ test_mirror_3x_p1_pmap_straight_cylinder_ho() .geo_local_ext = ext_range, .geo_global = range, .geo_global_ext = ext_range, - .geo_basis = basis, + .geo_basis = basis }; struct gk_geometry *gk_geom = gkyl_gk_geometry_mirror_new(&geometry_input); @@ -950,310 +1112,418 @@ test_mirror_3x_p1_pmap_straight_cylinder_ho() // write_geometry(gk_geom, grid, range, "straight_cylinder"); - int theta_shift = 1; // Because of the forward/backward difference + int theta_shift = 1; // Because of the forward/backward difference // used to calculate derivatives of the map, the edge values of the map - // have a linear order error so the derivatives are not accurate and the + // have a linear order error so the derivatives are not accurate and the // Jacobian will be a little wrong there. // Define nodal operations enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates int cidx[3]; - int nodes[] = { 1, 1, 1 }; - for (int d=0; dgeo_corn.mc2p, false); + struct gkyl_array *mapc2p_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange, &range, 3, mapc2p_nodal, gk_geom->geo_corn.mc2p, false + ); // Check that |bhat|=1 at nodes - struct gkyl_array* bhat_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, bhat_nodal, gk_geom->geo_int.bcart, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *bhat_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, bhat_nodal, gk_geom->geo_int.bcart, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; double *bhat_n = gkyl_array_fetch(bhat_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double bhat_mag = sqrt(bhat_n[0]*bhat_n[0] + bhat_n[1]*bhat_n[1] + bhat_n[2]*bhat_n[2]); - TEST_CHECK( gkyl_compare( bhat_mag, 1.0, 1e-12) ); + double bhat_mag = + sqrt(bhat_n[0] * bhat_n[0] + bhat_n[1] * bhat_n[1] + bhat_n[2] * bhat_n[2]); + TEST_CHECK(gkyl_compare(bhat_mag, 1.0, 1e-12)); } } } // Check that the duals are what they should be // There are errors at low psi, so we shift away from the axis by a few cells - struct gkyl_array* dualmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, dualmag_nodal, gk_geom->geo_int.dualmag, true); - struct gkyl_array* mapc2p_nodal_interior = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, mapc2p_nodal_interior, gk_geom->geo_int.mc2p, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX] + 3; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX] + theta_shift; it<=nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { + struct gkyl_array *dualmag_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, dualmag_nodal, gk_geom->geo_int.dualmag, + true + ); + struct gkyl_array *mapc2p_nodal_interior = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, mapc2p_nodal_interior, + gk_geom->geo_int.mc2p, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX] + 3; + ip <= nrange_quad_interior.upper[PSI_IDX]; ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX] + theta_shift; + it <= nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi= calc_running_coord(psi_lo, ia-nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); - double alpha= calc_running_coord(alpha_lo, ia-nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); - double theta= calc_running_coord(theta_lo, ia-nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); + double psi = + calc_running_coord(psi_lo, ia - nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); + double alpha = + calc_running_coord(alpha_lo, ia - nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); + double theta = + calc_running_coord(theta_lo, ia - nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); double xn[3] = {psi, alpha, theta}; - double *dualmag_n = gkyl_array_fetch(dualmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *dualmag_n = + gkyl_array_fetch(dualmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); double dualmag_anal[3]; exact_dual_magnitude_pmap(0, xn, dualmag_anal, 0); - TEST_CHECK( gkyl_compare( dualmag_n[0], dualmag_anal[0], 1e-6) ); - TEST_CHECK( gkyl_compare( dualmag_n[1], dualmag_anal[1], 1e-6) ); - TEST_CHECK( gkyl_compare( dualmag_n[2], dualmag_anal[2], 1e-6) ); + TEST_CHECK(gkyl_compare(dualmag_n[0], dualmag_anal[0], 1e-6)); + TEST_CHECK(gkyl_compare(dualmag_n[1], dualmag_anal[1], 1e-6)); + TEST_CHECK(gkyl_compare(dualmag_n[2], dualmag_anal[2], 1e-6)); } } } // Check bmag is what it should be - struct gkyl_array* bmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange, &range, 1, bmag_nodal, gk_geom->geo_corn.bmag, false); - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]; it<=nrange.upper[TH_IDX]; ++it) { + struct gkyl_array *bmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange, &range, 1, bmag_nodal, gk_geom->geo_corn.bmag, false + ); + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX]; it <= nrange.upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = grid.lower[PSI_IDX] + ip*(grid.upper[PSI_IDX]-grid.lower[PSI_IDX])/grid.cells[PSI_IDX]; - double alpha = grid.lower[AL_IDX] + ia*(grid.upper[AL_IDX]-grid.lower[AL_IDX])/grid.cells[AL_IDX]; - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double psi = grid.lower[PSI_IDX] + + ip * (grid.upper[PSI_IDX] - grid.lower[PSI_IDX]) / grid.cells[PSI_IDX]; + double alpha = + grid.lower[AL_IDX] + ia * (grid.upper[AL_IDX] - grid.lower[AL_IDX]) / grid.cells[AL_IDX]; + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; double xn[3] = {psi, alpha, theta}; double *bmag_n = gkyl_array_fetch(bmag_nodal, gkyl_range_idx(&nrange, cidx)); double bmag_anal[1]; bmag_func(0, xn, bmag_anal, 0); - TEST_CHECK( gkyl_compare( bmag_n[0], bmag_anal[0], 1e-8) ); + TEST_CHECK(gkyl_compare(bmag_n[0], bmag_anal[0], 1e-8)); } } } // Check cmag = 1 - struct gkyl_array* cmag_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, cmag_nodal, gk_geom->geo_int.cmag, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *cmag_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, cmag_nodal, gk_geom->geo_int.cmag, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; double *cmag_n = gkyl_array_fetch(cmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - TEST_CHECK( gkyl_compare( cmag_n[0], 1.0, 1e-6) ); + TEST_CHECK(gkyl_compare(cmag_n[0], 1.0, 1e-6)); } } } // Check g_ij - struct gkyl_array* gij_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_nodal, gk_geom->geo_int.g_ij, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX] + theta_shift; it<=nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { + struct gkyl_array *gij_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_nodal, gk_geom->geo_int.g_ij, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX] + theta_shift; + it <= nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi= calc_running_coord(psi_lo, ia-nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); - double alpha= calc_running_coord(alpha_lo, ia-nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); - double theta= calc_running_coord(theta_lo, ia-nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); + double psi = + calc_running_coord(psi_lo, ia - nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); + double alpha = + calc_running_coord(alpha_lo, ia - nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); + double theta = + calc_running_coord(theta_lo, ia - nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); double *gij_n = gkyl_array_fetch(gij_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); double xn[3] = {psi, alpha, theta}; double fout[6]; exact_gij_pmap(0.0, xn, fout, 0); - for (int i=0; i<6; ++i) - { - TEST_CHECK( gkyl_compare( gij_n[i], fout[i], 1e-6) ); + for (int i = 0; i < 6; ++i) { + TEST_CHECK(gkyl_compare(gij_n[i], fout[i], 1e-6)); } } } } // Check g^ij - struct gkyl_array* gij_contra_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_contra_nodal, gk_geom->geo_int.gij, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX] + theta_shift; it<=nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { + struct gkyl_array *gij_contra_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_contra_nodal, gk_geom->geo_int.gij, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX] + theta_shift; + it <= nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *gij_contra_n = gkyl_array_fetch(gij_contra_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double psi= calc_running_coord(psi_lo, ia-nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); - double alpha= calc_running_coord(alpha_lo, ia-nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); - double theta= calc_running_coord(theta_lo, ia-nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); + double *gij_contra_n = + gkyl_array_fetch(gij_contra_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double psi = + calc_running_coord(psi_lo, ia - nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); + double alpha = + calc_running_coord(alpha_lo, ia - nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); + double theta = + calc_running_coord(theta_lo, ia - nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); double xn[3] = {psi, alpha, theta}; double fout[6]; exact_g_contra_ij_pmap(0.0, xn, fout, 0); - for (int i=0; i<6; ++i) - TEST_CHECK( gkyl_compare( gij_contra_n[i], fout[i], 1e-6) ); + for (int i = 0; i < 6; ++i) { + TEST_CHECK(gkyl_compare(gij_contra_n[i], fout[i], 1e-6)); + } } } } // Check that Jacobgeo is what it should be. This is the Jacobian for the problem - struct gkyl_array* jacobgeo_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_nodal, gk_geom->geo_int.jacobgeo, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX] + theta_shift; it<=nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { + struct gkyl_array *jacobgeo_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_nodal, gk_geom->geo_int.jacobgeo, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX] + theta_shift; + it <= nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobgeo_n = gkyl_array_fetch(jacobgeo_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double *jacobgeo_n = + gkyl_array_fetch(jacobgeo_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; double xn[1] = {theta}; double fout[1]; dmapz_dz(0.0, xn, fout, 0); - double jacobian_analytic = 2/M_PI * fout[0]; - TEST_CHECK( gkyl_compare( jacobgeo_n[0], jacobian_analytic, 1e-6) ); + double jacobian_analytic = 2 / M_PI * fout[0]; + TEST_CHECK(gkyl_compare(jacobgeo_n[0], jacobian_analytic, 1e-6)); } } } // Check jacobgeo_inv - struct gkyl_array* jacobgeo_inv_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_inv_nodal, gk_geom->geo_int.jacobgeo_inv, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX] + theta_shift; it<=nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { + struct gkyl_array *jacobgeo_inv_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_inv_nodal, + gk_geom->geo_int.jacobgeo_inv, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX] + theta_shift; + it <= nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobgeo_inv_n = gkyl_array_fetch(jacobgeo_inv_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double *jacobgeo_inv_n = + gkyl_array_fetch(jacobgeo_inv_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; double xn[1] = {theta}; double fout[1]; dmapz_dz(0.0, xn, fout, 0); - double jacobian_analytic = 2/M_PI * fout[0]; - TEST_CHECK( gkyl_compare( jacobgeo_inv_n[0], 1/jacobian_analytic, 1e-6) ); + double jacobian_analytic = 2 / M_PI * fout[0]; + TEST_CHECK(gkyl_compare(jacobgeo_inv_n[0], 1 / jacobian_analytic, 1e-6)); } } } // Check jacobtot - struct gkyl_array* jacobtot_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_nodal, gk_geom->geo_int.jacobtot, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX] + theta_shift; it<=nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { + struct gkyl_array *jacobtot_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_nodal, gk_geom->geo_int.jacobtot, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX] + theta_shift; + it <= nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobtot_n = gkyl_array_fetch(jacobtot_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double *jacobtot_n = + gkyl_array_fetch(jacobtot_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; double xn[1] = {theta}; double fout[1]; dmapz_dz(0.0, xn, fout, 0); - double jacobian_analytic = 2/M_PI * fout[0]; + double jacobian_analytic = 2 / M_PI * fout[0]; double magnetic_field = 0.5; double jacobtot_analytic = jacobian_analytic * magnetic_field; - TEST_CHECK( gkyl_compare( jacobtot_n[0], jacobtot_analytic, 1e-6) ); + TEST_CHECK(gkyl_compare(jacobtot_n[0], jacobtot_analytic, 1e-6)); } } } // Check jacobtot_inv - struct gkyl_array* jacobtot_inv_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_inv_nodal, gk_geom->geo_int.jacobtot_inv, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX] + theta_shift; it<=nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { + struct gkyl_array *jacobtot_inv_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_inv_nodal, + gk_geom->geo_int.jacobtot_inv, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX] + theta_shift; + it <= nrange_quad_interior.upper[TH_IDX] - theta_shift; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobtot_inv_n = gkyl_array_fetch(jacobtot_inv_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double *jacobtot_inv_n = + gkyl_array_fetch(jacobtot_inv_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; double xn[1] = {theta}; double fout[1]; dmapz_dz(0.0, xn, fout, 0); - double jacobian_analytic = 2/M_PI * fout[0]; + double jacobian_analytic = 2 / M_PI * fout[0]; double magnetic_field = 0.5; double jacobtot_analytic = jacobian_analytic * magnetic_field; - TEST_CHECK( gkyl_compare( jacobtot_inv_n[0], 1/jacobtot_analytic, 1e-6) ); + TEST_CHECK(gkyl_compare(jacobtot_inv_n[0], 1 / jacobtot_analytic, 1e-6)); } } } // Check mapc2p - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]; it<=nrange.upper[TH_IDX]; ++it) { + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX]; it <= nrange.upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi= calc_running_coord(psi_lo, ia-nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); - double alpha= calc_running_coord(alpha_lo, ia-nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); - double theta= calc_running_coord(theta_lo, ia-nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); + double psi = + calc_running_coord(psi_lo, ia - nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); + double alpha = + calc_running_coord(alpha_lo, ia - nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); + double theta = + calc_running_coord(theta_lo, ia - nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); // mapc2p_n[0] = R, mapc2p_n[1] = Theta, mapc2p_n[2] = Z_cylindrical double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal, gkyl_range_idx(&nrange, cidx)); mapz(0.0, &theta, &theta, 0); double xn[3] = {psi, alpha, theta}; double fout[3]; mapc2p(0.0, xn, fout, 0); - for (int i=0; i<3; ++i) - TEST_CHECK( gkyl_compare( mapc2p_n[i], fout[i], 1e-8) ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mapc2p_n[i], fout[i], 1e-8)); + } } } } // Check mc2nu_pos - struct gkyl_array* mc2nu_pos_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange, &range, 3, mc2nu_pos_nodal, gk_geom->geo_corn.mc2nu_pos, false); - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]; it<=nrange.upper[TH_IDX]; ++it) { + struct gkyl_array *mc2nu_pos_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange, &range, 3, mc2nu_pos_nodal, gk_geom->geo_corn.mc2nu_pos, false + ); + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX]; it <= nrange.upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi= calc_running_coord(psi_lo, ia-nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); - double alpha= calc_running_coord(alpha_lo, ia-nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); - double theta= calc_running_coord(theta_lo, ia-nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); + double psi = + calc_running_coord(psi_lo, ia - nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); + double alpha = + calc_running_coord(alpha_lo, ia - nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); + double theta = + calc_running_coord(theta_lo, ia - nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); mapz(0.0, &theta, &theta, 0); double xn[3] = {psi, alpha, theta}; double *mc2nu_pos_n = gkyl_array_fetch(mc2nu_pos_nodal, gkyl_range_idx(&nrange, cidx)); - for (int i=0; i<3; ++i) - TEST_CHECK( gkyl_compare( mc2nu_pos_n[i], xn[i], 1e-8) ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mc2nu_pos_n[i], xn[i], 1e-8)); + } } } } // Check normals // Plus 3 away from axis to avoid errors - struct gkyl_array* normals_nodal = gkyl_array_new(GKYL_DOUBLE, 9*basis.num_basis, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 9*basis.num_basis, normals_nodal, gk_geom->geo_int.normals, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]+3; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *normals_nodal = + gkyl_array_new(GKYL_DOUBLE, 9 * basis.num_basis, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 9 * basis.num_basis, normals_nodal, + gk_geom->geo_int.normals, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX] + 3; + ip <= nrange_quad_interior.upper[PSI_IDX]; ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *normals_n = gkyl_array_fetch(normals_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double psi= calc_running_coord(psi_lo, ia-nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); - double alpha= calc_running_coord(alpha_lo, ia-nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); - double theta= calc_running_coord(theta_lo, ia-nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); + double *normals_n = + gkyl_array_fetch(normals_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double psi = + calc_running_coord(psi_lo, ia - nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); + double alpha = + calc_running_coord(alpha_lo, ia - nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); + double theta = + calc_running_coord(theta_lo, ia - nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); double xn[3] = {psi, alpha, theta}; double fout[9]; exact_normals_pmap(0.0, xn, fout, 0); - for (int i=0; i<9; ++i) - { - TEST_CHECK( gkyl_compare( normals_n[i], fout[i], 1e-6) ); + for (int i = 0; i < 9; ++i) { + TEST_CHECK(gkyl_compare(normals_n[i], fout[i], 1e-6)); } } } @@ -1278,10 +1548,9 @@ test_mirror_3x_p1_pmap_straight_cylinder_ho() gkyl_gk_geometry_release(gk_geom); } - TEST_LIST = { - { "test_mirror_load_geometry_ho", test_mirror_load_geometry_ho }, - { "test_mirror_3x_p1_straight_cylinder_ho", test_mirror_3x_p1_straight_cylinder_ho }, + {"test_mirror_load_geometry_ho", test_mirror_load_geometry_ho}, + {"test_mirror_3x_p1_straight_cylinder_ho", test_mirror_3x_p1_straight_cylinder_ho}, // { "test_mirror_3x_p1_pmap_straight_cylinder_ho", test_mirror_3x_p1_pmap_straight_cylinder_ho }, - { NULL, NULL }, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_gk_geometry_tok.c b/gyrokinetic/unit/ctest_gk_geometry_tok.c index f514710dac..38a6a410fb 100644 --- a/gyrokinetic/unit/ctest_gk_geometry_tok.c +++ b/gyrokinetic/unit/ctest_gk_geometry_tok.c @@ -25,99 +25,100 @@ #include #include -void -write_geometry(gk_geometry *up, struct gkyl_rect_grid grid, struct gkyl_range local, const char *name) +void write_geometry( + gk_geometry *up, struct gkyl_rect_grid grid, struct gkyl_range local, const char *name +) { const char *fmt = "%s-%s.gkyl"; int sz = gkyl_calc_strlen(fmt, name, "jacobtot_inv"); - char fileNm[sz+1]; // ensure no buffer overflow + char fileNm[sz + 1]; // ensure no buffer overflow sprintf(fileNm, fmt, name, "mapc2p"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2p, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2p, fileNm); sprintf(fileNm, fmt, name, "mapc2nu"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2nu_pos, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2nu_pos, fileNm); sprintf(fileNm, fmt, name, "bmag_corn"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag, fileNm); sprintf(fileNm, fmt, name, "bmag_inv_corn"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag_inv, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag_inv, fileNm); sprintf(fileNm, fmt, name, "bmag"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bmag, fileNm); sprintf(fileNm, fmt, name, "g_ij"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.g_ij, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.g_ij, fileNm); sprintf(fileNm, fmt, name, "dxdz"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dxdz, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dxdz, fileNm); sprintf(fileNm, fmt, name, "dzdx"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dzdx, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dzdx, fileNm); sprintf(fileNm, fmt, name, "normals"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.normals, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.normals, fileNm); sprintf(fileNm, fmt, name, "jacobgeo"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo, fileNm); sprintf(fileNm, fmt, name, "jacobgeo_inv"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo_inv, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo_inv, fileNm); sprintf(fileNm, fmt, name, "gij"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gij, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gij, fileNm); sprintf(fileNm, fmt, name, "b_i"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.b_i, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.b_i, fileNm); sprintf(fileNm, fmt, name, "bcart"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bcart, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bcart, fileNm); sprintf(fileNm, fmt, name, "cmag"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.cmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.cmag, fileNm); sprintf(fileNm, fmt, name, "jacobtot"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot, fileNm); sprintf(fileNm, fmt, name, "jacobtot_inv"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot_inv, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot_inv, fileNm); sprintf(fileNm, fmt, name, "gxxj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxxj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxxj, fileNm); sprintf(fileNm, fmt, name, "gxyj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxyj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxyj, fileNm); sprintf(fileNm, fmt, name, "gyyj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gyyj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gyyj, fileNm); sprintf(fileNm, fmt, name, "gxzj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxzj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxzj, fileNm); sprintf(fileNm, fmt, name, "eps2"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.eps2, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.eps2, fileNm); sprintf(fileNm, fmt, name, "qprofile"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.qprofile, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.qprofile, fileNm); // Create Nodal Range and Grid and Write Nodal Coordinates struct gkyl_range nrange; gkyl_gk_geometry_init_nodal_range(&nrange, &local, up->basis.poly_order); - struct gkyl_array* mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); + struct gkyl_array *mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&up->basis, &grid, false); - gkyl_nodal_ops_m2n(n2m, &up->basis, &grid, &nrange, &local, 3, mc2p_nodal, up->geo_corn.mc2p, false); + gkyl_nodal_ops_m2n( + n2m, &up->basis, &grid, &nrange, &local, 3, mc2p_nodal, up->geo_corn.mc2p, false + ); gkyl_nodal_ops_release(n2m); struct gkyl_rect_grid ngrid; gkyl_gk_geometry_init_nodal_grid(&ngrid, &grid, &nrange); sprintf(fileNm, fmt, name, "nodes"); - gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, fileNm); + gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, fileNm); gkyl_array_release(mc2p_nodal); } -void -test_tok_elliptical_ho() +void test_tok_elliptical_ho() { clock_t start, end; double cpu_time_used; start = clock(); - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/elliptical.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, - .reflect = true, - }; + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/elliptical.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1, + .reflect = true + }; double psisep = -4.0; - double clower[] = { -5.0, -0.01, -M_PI+1e-14 }; - double cupper[] = {psisep, 0.01, M_PI-1e-14 }; + double clower[] = {-5.0, -0.01, -M_PI + 1e-14}; + double cupper[] = {psisep, 0.01, M_PI - 1e-14}; - int ccells[] = { 2, 1, 2 }; + int ccells[] = {2, 1, 2}; struct gkyl_rect_grid cgrid; gkyl_rect_grid_init(&cgrid, 3, clower, cupper, ccells); struct gkyl_range clocal, clocal_ext; - int cnghost[GKYL_MAX_CDIM] = { 1, 1, 1 }; + int cnghost[GKYL_MAX_CDIM] = {1, 1, 1}; gkyl_create_grid_ranges(&cgrid, cnghost, &clocal_ext, &clocal); int cpoly_order = 1; struct gkyl_basis cbasis; @@ -132,11 +133,11 @@ test_tok_elliptical_ho() .rright = 6.0, .rleft = 0.0, .zmin = -3.0, - .zmax = 3.0, - }; + .zmax = 3.0 + }; struct gkyl_gk_geometry_inp geometry_inp = { - .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, .efit_info = efit_inp, .tok_grid_info = ginp, .position_map = pmap, @@ -151,61 +152,62 @@ test_tok_elliptical_ho() .geo_local_ext = clocal_ext, .geo_global = clocal, .geo_global_ext = clocal_ext, - .geo_basis = cbasis, + .geo_basis = cbasis }; - struct gk_geometry* up = gkyl_gk_geometry_tok_new(&geometry_inp); + struct gk_geometry *up = gkyl_gk_geometry_tok_new(&geometry_inp); gkyl_gk_geometry_release(up); gkyl_position_map_release(pmap); end = clock(); - cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC; } - // Functions for test_3x_straight_cylinder -void mapc2p(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void mapc2p(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double psi = xn[0], alpha = xn[1], theta = xn[2]; - fout[0] = sqrt(psi * 4 ); // Function fed is psi = 0.5/2 * R^2 from the efit file - fout[1] = theta * 1.0 / M_PI; // Note that this does not have pi-1e-2 in it because the coordinate zeta is always defined -pi to pi + fout[0] = sqrt(psi * 4); // Function fed is psi = 0.5/2 * R^2 from the efit file + fout[1] = + theta * 1.0 / + M_PI; // Note that this does not have pi-1e-2 in it because the coordinate zeta is always defined -pi to pi fout[2] = alpha; // There is a minus due to conventions } -void exact_gij(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_gij(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double r = xn[0], theta = xn[1], phi = xn[2]; - double psi = r*r/4; - fout[0] = 1/psi; // g_11 + double psi = r * r / 4; + fout[0] = 1 / psi; // g_11 fout[1] = 0.0; // g_12 fout[2] = 0.0; // g_13 - fout[3] = r*r; // g_22 + fout[3] = r * r; // g_22 fout[4] = 0.0; // g_23 - fout[5] = 1/(M_PI*M_PI); // g_33 + fout[5] = 1 / (M_PI * M_PI); // g_33 } -void exact_g_contra_ij(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_g_contra_ij(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double r = xn[0], theta = xn[1], phi = xn[2]; - double psi = r*r/4; - fout[0] = r*r/4; // g_11 + double psi = r * r / 4; + fout[0] = r * r / 4; // g_11 fout[1] = 0.0; // g_12 fout[2] = 0.0; // g_13 - fout[3] = 1/psi/4; // g_22 + fout[3] = 1 / psi / 4; // g_22 fout[4] = 0.0; // g_23 - fout[5] = (M_PI*M_PI); // g_33 + fout[5] = (M_PI * M_PI); // g_33 } -void exact_dual_magnitude(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_dual_magnitude(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double r = xn[0], theta = xn[1], phi = xn[2]; - double psi = r*r/4; - fout[0] = r/2; - fout[1] = 1/(2*sqrt(psi)); + double psi = r * r / 4; + fout[0] = r / 2; + fout[1] = 1 / (2 * sqrt(psi)); fout[2] = M_PI; } -void exact_normals(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx) +void exact_normals(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) { double psi = xn[0], alpha = xn[1], theta = xn[2]; // Remember cylindrical angle = - alpha @@ -220,12 +222,12 @@ void exact_normals(double t, const double *xn, double* GKYL_RESTRICT fout, void fout[8] = 1.0; } -void bmag_func(double t, const double *xn, double* GKYL_RESTRICT fout, void *ctx){ +void bmag_func(double t, const double *xn, double *GKYL_RESTRICT fout, void *ctx) +{ fout[0] = 0.5; } -void -test_tok_3x_p1_straight_cylinder_ho() +void test_tok_3x_p1_straight_cylinder_ho() { // Very similar to the unit test in ctest_gk_geometry.c // The geometry is created to extend from Z = -1 to 1, R = (0.001, 1) in units meters @@ -238,36 +240,30 @@ test_tok_3x_p1_straight_cylinder_ho() int poly_order = 1; int cdim = 3; gkyl_cart_modal_serendip(&basis, cdim, poly_order); - + double psiMax = 0.2; double psiMin = 0.1; - double lower[3] = {psiMin, -1.0, -M_PI+1e-14}; - double upper[3] = {psiMax, 1.0, M_PI-1e-14}; - int cells[3] = { 8, 2, 8}; + double lower[3] = {psiMin, -1.0, -M_PI + 1e-14}; + double upper[3] = {psiMax, 1.0, M_PI - 1e-14}; + int cells[3] = {8, 2, 8}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, cdim, lower, upper, cells); - + struct gkyl_range ext_range, range; - int nghost[3] = { 1,1,1}; + int nghost[3] = {1, 1, 1}; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); struct gkyl_position_map *pmap = gkyl_position_map_null_new(); - struct gkyl_efit_inp inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/straight_cylinder.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, - .reflect = true, + struct gkyl_efit_inp inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/straight_cylinder.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1, + .reflect = true }; struct gkyl_tok_geo_grid_inp ginp = { - .rclose = 0.5, - .zmin = -1., - .zmax = 1., - .rleft = 0.001, - .rmax = 1.0, - .rright = 1.0, + .rclose = 0.5, .zmin = -1., .zmax = 1., .rleft = 0.001, .rmax = 1.0, .rright = 1.0 }; // Initialize geometry struct gkyl_gk_geometry_inp geometry_input = { @@ -286,7 +282,7 @@ test_tok_3x_p1_straight_cylinder_ho() .geo_local_ext = ext_range, .geo_global = range, .geo_global_ext = ext_range, - .geo_basis = basis, + .geo_basis = basis }; struct gk_geometry *gk_geom = gkyl_gk_geometry_tok_new(&geometry_input); @@ -296,266 +292,359 @@ test_tok_3x_p1_straight_cylinder_ho() // Define nodal operations enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates int cidx[3]; - int nodes[] = { 1, 1, 1 }; - for (int d=0; dgeo_int.bcart, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *bhat_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, bhat_nodal, gk_geom->geo_int.bcart, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; double *bhat_n = gkyl_array_fetch(bhat_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double bhat_mag = sqrt(bhat_n[0]*bhat_n[0] + bhat_n[1]*bhat_n[1] + bhat_n[2]*bhat_n[2]); - TEST_CHECK( gkyl_compare( bhat_mag, 1.0, 1e-12) ); + double bhat_mag = + sqrt(bhat_n[0] * bhat_n[0] + bhat_n[1] * bhat_n[1] + bhat_n[2] * bhat_n[2]); + TEST_CHECK(gkyl_compare(bhat_mag, 1.0, 1e-12)); } } } // Check that the duals are what they should be // There are errors at low psi, so we shift away from the axis by a few cells - struct gkyl_array* dualmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, dualmag_nodal, gk_geom->geo_int.dualmag, true); - struct gkyl_array* mapc2p_nodal_interior = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 3, mapc2p_nodal_interior, gk_geom->geo_int.mc2p, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *dualmag_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, dualmag_nodal, gk_geom->geo_int.dualmag, + true + ); + struct gkyl_array *mapc2p_nodal_interior = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 3, mapc2p_nodal_interior, + gk_geom->geo_int.mc2p, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *dualmag_n = gkyl_array_fetch(dualmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *dualmag_n = + gkyl_array_fetch(dualmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *mapc2p_n = + gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); double xn[3] = {mapc2p_n[0], mapc2p_n[1], mapc2p_n[2]}; double dualmag_ana[3]; exact_dual_magnitude(0, xn, dualmag_ana, 0); - TEST_CHECK( gkyl_compare( dualmag_n[0], dualmag_ana[0], 1e-6) ); - TEST_CHECK( gkyl_compare( dualmag_n[1], dualmag_ana[1], 1e-6) ); - TEST_CHECK( gkyl_compare( dualmag_n[2], dualmag_ana[2], 1e-6) ); + TEST_CHECK(gkyl_compare(dualmag_n[0], dualmag_ana[0], 1e-6)); + TEST_CHECK(gkyl_compare(dualmag_n[1], dualmag_ana[1], 1e-6)); + TEST_CHECK(gkyl_compare(dualmag_n[2], dualmag_ana[2], 1e-6)); } } } // Check bmag is what it should be - struct gkyl_array* bmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange, &range, 1, bmag_nodal, gk_geom->geo_corn.bmag, false); - struct gkyl_array* mapc2p_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange, &range, 3, mapc2p_nodal, gk_geom->geo_corn.mc2p, false); - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]; it<=nrange.upper[TH_IDX]; ++it) { + struct gkyl_array *bmag_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange, &range, 1, bmag_nodal, gk_geom->geo_corn.bmag, false + ); + struct gkyl_array *mapc2p_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange, &range, 3, mapc2p_nodal, gk_geom->geo_corn.mc2p, false + ); + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX]; it <= nrange.upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = grid.lower[PSI_IDX] + ip*(grid.upper[PSI_IDX]-grid.lower[PSI_IDX])/grid.cells[PSI_IDX]; - double alpha = grid.lower[AL_IDX] + ia*(grid.upper[AL_IDX]-grid.lower[AL_IDX])/grid.cells[AL_IDX]; - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double psi = grid.lower[PSI_IDX] + + ip * (grid.upper[PSI_IDX] - grid.lower[PSI_IDX]) / grid.cells[PSI_IDX]; + double alpha = + grid.lower[AL_IDX] + ia * (grid.upper[AL_IDX] - grid.lower[AL_IDX]) / grid.cells[AL_IDX]; + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; double xn[3] = {psi, alpha, theta}; double *bmag_n = gkyl_array_fetch(bmag_nodal, gkyl_range_idx(&nrange, cidx)); double bmag_ana[1]; bmag_func(0, xn, bmag_ana, 0); - TEST_CHECK( gkyl_compare( bmag_n[0], bmag_ana[0], 1e-8) ); + TEST_CHECK(gkyl_compare(bmag_n[0], bmag_ana[0], 1e-8)); } } } // Check cmag = 1 - struct gkyl_array* cmag_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, cmag_nodal, gk_geom->geo_int.cmag, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *cmag_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, cmag_nodal, gk_geom->geo_int.cmag, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; double *cmag_n = gkyl_array_fetch(cmag_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - TEST_CHECK( gkyl_compare( cmag_n[0], 1.0, 1e-6) ); + TEST_CHECK(gkyl_compare(cmag_n[0], 1.0, 1e-6)); } } } // Check g_ij - struct gkyl_array* gij_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_nodal, gk_geom->geo_int.g_ij, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *gij_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_nodal, gk_geom->geo_int.g_ij, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; double *gij_n = gkyl_array_fetch(gij_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *mapc2p_n = + gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); double r = mapc2p_n[0]; double xn[3] = {r, 0.0, 0.0}; double fout[6]; exact_gij(0.0, xn, fout, 0); double tol; - for (int i=0; i<6; ++i) - { - if (i == 4) + for (int i = 0; i < 6; ++i) { + if (i == 4) { tol = 1e-3; - else + } else { tol = 1e-6; - TEST_CHECK( gkyl_compare( gij_n[i], fout[i], tol) ); + } + TEST_CHECK(gkyl_compare(gij_n[i], fout[i], tol)); } } } } // Check g^ij - struct gkyl_array* gij_contra_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_contra_nodal, gk_geom->geo_int.gij, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *gij_contra_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 6, gij_contra_nodal, gk_geom->geo_int.gij, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *gij_contra_n = gkyl_array_fetch(gij_contra_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *gij_contra_n = + gkyl_array_fetch(gij_contra_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *mapc2p_n = + gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); double r = mapc2p_n[0]; double xn[3] = {r, 0.0, 0.0}; double fout[6]; exact_g_contra_ij(0.0, xn, fout, 0); double tol; - for (int i=0; i<6; ++i) - { - if (i == 4) + for (int i = 0; i < 6; ++i) { + if (i == 4) { tol = 1e-2; - else + } else { tol = 1e-6; - TEST_CHECK( gkyl_compare( gij_contra_n[i], fout[i], tol) ); + } + TEST_CHECK(gkyl_compare(gij_contra_n[i], fout[i], tol)); } } } } // Check that Jacobgeo is what it should be. This is the Jacobian for the problem - struct gkyl_array* jacobgeo_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_nodal, gk_geom->geo_int.jacobgeo, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *jacobgeo_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_nodal, gk_geom->geo_int.jacobgeo, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobgeo_n = gkyl_array_fetch(jacobgeo_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); - double jacobian_anaytic = 2/M_PI; - TEST_CHECK( gkyl_compare( jacobgeo_n[0], jacobian_anaytic, 1e-6) ); + double *jacobgeo_n = + gkyl_array_fetch(jacobgeo_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *mapc2p_n = + gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double jacobian_anaytic = 2 / M_PI; + TEST_CHECK(gkyl_compare(jacobgeo_n[0], jacobian_anaytic, 1e-6)); } } } // Check jacobgeo_inv - struct gkyl_array* jacobgeo_inv_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_inv_nodal, gk_geom->geo_int.jacobgeo_inv, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *jacobgeo_inv_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobgeo_inv_nodal, + gk_geom->geo_int.jacobgeo_inv, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobgeo_inv_n = gkyl_array_fetch(jacobgeo_inv_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); - double jacobian_anaytic = 2/M_PI; - TEST_CHECK( gkyl_compare( jacobgeo_inv_n[0], 1/jacobian_anaytic, 1e-6) ); + double *jacobgeo_inv_n = + gkyl_array_fetch(jacobgeo_inv_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *mapc2p_n = + gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double jacobian_anaytic = 2 / M_PI; + TEST_CHECK(gkyl_compare(jacobgeo_inv_n[0], 1 / jacobian_anaytic, 1e-6)); } } } // Check jacobtot - struct gkyl_array* jacobtot_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_nodal, gk_geom->geo_int.jacobtot, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *jacobtot_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_nodal, gk_geom->geo_int.jacobtot, + true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobtot_n = gkyl_array_fetch(jacobtot_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *jacobtot_n = + gkyl_array_fetch(jacobtot_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); // mapc2p_n[0] = x, mapc2p_n[1] = y, mapc2p_n[2] = z - double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); - double jacobian_anaytic = 2/M_PI; + double *mapc2p_n = + gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double jacobian_anaytic = 2 / M_PI; double magnetic_field = 0.5; double jacobtot_anaytic = jacobian_anaytic * magnetic_field; - TEST_CHECK( gkyl_compare( jacobtot_n[0], jacobtot_anaytic, 1e-6) ); + TEST_CHECK(gkyl_compare(jacobtot_n[0], jacobtot_anaytic, 1e-6)); } } } // Check jacobtot_inv - struct gkyl_array* jacobtot_inv_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_inv_nodal, gk_geom->geo_int.jacobtot_inv, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + struct gkyl_array *jacobtot_inv_nodal = + gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 1, jacobtot_inv_nodal, + gk_geom->geo_int.jacobtot_inv, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *jacobtot_inv_n = gkyl_array_fetch(jacobtot_inv_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double *jacobtot_inv_n = + gkyl_array_fetch(jacobtot_inv_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); // mapc2p_n[0] = x, mapc2p_n[1] = y, mapc2p_n[2] = z - double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); - double jacobian_anaytic = 2/M_PI; + double *mapc2p_n = + gkyl_array_fetch(mapc2p_nodal_interior, gkyl_range_idx(&nrange_quad_interior, cidx)); + double jacobian_anaytic = 2 / M_PI; double magnetic_field = 0.5; double jacobtot_anaytic = jacobian_anaytic * magnetic_field; - TEST_CHECK( gkyl_compare( jacobtot_inv_n[0], 1/jacobtot_anaytic, 1e-6) ); + TEST_CHECK(gkyl_compare(jacobtot_inv_n[0], 1 / jacobtot_anaytic, 1e-6)); } } } // Check mapc2p - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]+1; it<=nrange.upper[TH_IDX]-1; ++it) { + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX] + 1; it <= nrange.upper[TH_IDX] - 1; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = grid.lower[PSI_IDX] + ip*(grid.upper[PSI_IDX]-grid.lower[PSI_IDX])/grid.cells[PSI_IDX]; - double alpha = grid.lower[AL_IDX] + ia*(grid.upper[AL_IDX]-grid.lower[AL_IDX])/grid.cells[AL_IDX]; - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double psi = grid.lower[PSI_IDX] + + ip * (grid.upper[PSI_IDX] - grid.lower[PSI_IDX]) / grid.cells[PSI_IDX]; + double alpha = + grid.lower[AL_IDX] + ia * (grid.upper[AL_IDX] - grid.lower[AL_IDX]) / grid.cells[AL_IDX]; + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; // mapc2p_n[0] = R, mapc2p_n[1] = Theta, mapc2p_n[2] = Z_cylindrical double *mapc2p_n = gkyl_array_fetch(mapc2p_nodal, gkyl_range_idx(&nrange, cidx)); double xn[3] = {psi, alpha, theta}; double fout[3]; mapc2p(0.0, xn, fout, 0); - for (int i=0; i<3; ++i) - TEST_CHECK( gkyl_compare( mapc2p_n[i], fout[i], 1e-6) ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mapc2p_n[i], fout[i], 1e-6)); + } } } } // Check mc2nu_pos - struct gkyl_array* mc2nu_pos_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange, &range, 3, mc2nu_pos_nodal, gk_geom->geo_corn.mc2nu_pos, false); - for (int ia=nrange.lower[AL_IDX]; ia<=nrange.upper[AL_IDX]; ++ia){ - for (int ip=nrange.lower[PSI_IDX]; ip<=nrange.upper[PSI_IDX]; ++ip) { - for (int it=nrange.lower[TH_IDX]; it<=nrange.upper[TH_IDX]; ++it) { + struct gkyl_array *mc2nu_pos_nodal = gkyl_array_new(GKYL_DOUBLE, grid.ndim, nrange.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange, &range, 3, mc2nu_pos_nodal, gk_geom->geo_corn.mc2nu_pos, false + ); + for (int ia = nrange.lower[AL_IDX]; ia <= nrange.upper[AL_IDX]; ++ia) { + for (int ip = nrange.lower[PSI_IDX]; ip <= nrange.upper[PSI_IDX]; ++ip) { + for (int it = nrange.lower[TH_IDX]; it <= nrange.upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double psi = grid.lower[PSI_IDX] + ip*(grid.upper[PSI_IDX]-grid.lower[PSI_IDX])/grid.cells[PSI_IDX]; - double alpha = grid.lower[AL_IDX] + ia*(grid.upper[AL_IDX]-grid.lower[AL_IDX])/grid.cells[AL_IDX]; - double theta = grid.lower[TH_IDX] + it*(grid.upper[TH_IDX]-grid.lower[TH_IDX])/grid.cells[TH_IDX]; + double psi = grid.lower[PSI_IDX] + + ip * (grid.upper[PSI_IDX] - grid.lower[PSI_IDX]) / grid.cells[PSI_IDX]; + double alpha = + grid.lower[AL_IDX] + ia * (grid.upper[AL_IDX] - grid.lower[AL_IDX]) / grid.cells[AL_IDX]; + double theta = + grid.lower[TH_IDX] + it * (grid.upper[TH_IDX] - grid.lower[TH_IDX]) / grid.cells[TH_IDX]; double xn[3] = {psi, alpha, theta}; double *mc2nu_pos_n = gkyl_array_fetch(mc2nu_pos_nodal, gkyl_range_idx(&nrange, cidx)); - for (int i=0; i<3; ++i) { - TEST_CHECK( gkyl_compare( mc2nu_pos_n[i], xn[i], 1e-8) ); + for (int i = 0; i < 3; ++i) { + TEST_CHECK(gkyl_compare(mc2nu_pos_n[i], xn[i], 1e-8)); } } } @@ -563,28 +652,39 @@ test_tok_3x_p1_straight_cylinder_ho() // Check normals // Plus 3 away from axis to avoid errors - double dels[2] = {1.0/sqrt(3), 1.0-1.0/sqrt(3) }; - double theta_lo = grid.lower[TH_IDX] + dels[1]*grid.dx[TH_IDX]/2.0; - double psi_lo = grid.lower[PSI_IDX] + dels[1]*grid.dx[PSI_IDX]/2.0; - double alpha_lo = grid.lower[AL_IDX] + dels[1]*grid.dx[AL_IDX]/2.0; - struct gkyl_array* normals_nodal = gkyl_array_new(GKYL_DOUBLE, 9*basis.num_basis, nrange_quad_interior.volume); - gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange_quad_interior, &range, 9*basis.num_basis, normals_nodal, gk_geom->geo_int.normals, true); - for (int ia=nrange_quad_interior.lower[AL_IDX]; ia<=nrange_quad_interior.upper[AL_IDX]; ++ia){ - for (int ip=nrange_quad_interior.lower[PSI_IDX]; ip<=nrange_quad_interior.upper[PSI_IDX]; ++ip) { - for (int it=nrange_quad_interior.lower[TH_IDX]; it<=nrange_quad_interior.upper[TH_IDX]; ++it) { + double dels[2] = {1.0 / sqrt(3), 1.0 - 1.0 / sqrt(3)}; + double theta_lo = grid.lower[TH_IDX] + dels[1] * grid.dx[TH_IDX] / 2.0; + double psi_lo = grid.lower[PSI_IDX] + dels[1] * grid.dx[PSI_IDX] / 2.0; + double alpha_lo = grid.lower[AL_IDX] + dels[1] * grid.dx[AL_IDX] / 2.0; + struct gkyl_array *normals_nodal = + gkyl_array_new(GKYL_DOUBLE, 9 * basis.num_basis, nrange_quad_interior.volume); + gkyl_nodal_ops_m2n( + n2m, &basis, &grid, &nrange_quad_interior, &range, 9 * basis.num_basis, normals_nodal, + gk_geom->geo_int.normals, true + ); + for (int ia = nrange_quad_interior.lower[AL_IDX]; ia <= nrange_quad_interior.upper[AL_IDX]; + ++ia) { + for (int ip = nrange_quad_interior.lower[PSI_IDX]; ip <= nrange_quad_interior.upper[PSI_IDX]; + ++ip) { + for (int it = nrange_quad_interior.lower[TH_IDX]; it <= nrange_quad_interior.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *normals_n = gkyl_array_fetch(normals_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); - double psi= calc_running_coord(psi_lo, ia-nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); - double alpha= calc_running_coord(alpha_lo, ia-nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); - double theta= calc_running_coord(theta_lo, ia-nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); + double *normals_n = + gkyl_array_fetch(normals_nodal, gkyl_range_idx(&nrange_quad_interior, cidx)); + double psi = + calc_running_coord(psi_lo, ia - nrange_quad_interior.lower[PSI_IDX], grid.dx[PSI_IDX]); + double alpha = + calc_running_coord(alpha_lo, ia - nrange_quad_interior.lower[AL_IDX], grid.dx[AL_IDX]); + double theta = + calc_running_coord(theta_lo, ia - nrange_quad_interior.lower[TH_IDX], grid.dx[TH_IDX]); double xn[3] = {psi, alpha, theta}; double fout[9]; exact_normals(0.0, xn, fout, 0); double tol; - for (int i=0; i<9; ++i) { - TEST_CHECK( gkyl_compare( normals_n[i], fout[i], 1e-3) ); + for (int i = 0; i < 9; ++i) { + TEST_CHECK(gkyl_compare(normals_n[i], fout[i], 1e-3)); } } } @@ -609,15 +709,14 @@ test_tok_3x_p1_straight_cylinder_ho() gkyl_gk_geometry_release(gk_geom); } -void -test_tok_asdex_qprofile_core_ho() +void test_tok_asdex_qprofile_core_ho() { - double clower[] = { -0.09, -0.01, -M_PI+1e-14 }; - double cupper[] = {0.14975, 0.01, M_PI-1e-14 }; - int ccells[] = { 4, 1, 4 }; + double clower[] = {-0.09, -0.01, -M_PI + 1e-14}; + double cupper[] = {0.14975, 0.01, M_PI - 1e-14}; + int ccells[] = {4, 1, 4}; int cpoly_order = 1; - int cnghost[GKYL_MAX_CDIM] = { 1, 1, 1 }; + int cnghost[GKYL_MAX_CDIM] = {1, 1, 1}; struct gkyl_rect_grid cgrid; struct gkyl_range clocal, clocal_ext; struct gkyl_basis cbasis; @@ -625,11 +724,10 @@ test_tok_asdex_qprofile_core_ho() gkyl_create_grid_ranges(&cgrid, cnghost, &clocal_ext, &clocal); gkyl_cart_modal_serendip(&cbasis, 3, cpoly_order); - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1 }; struct gkyl_tok_geo_grid_inp ginp = { .ftype = GKYL_GEOMETRY_TOKAMAK_CORE, @@ -641,13 +739,13 @@ test_tok_asdex_qprofile_core_ho() .zmin = -1.3, .zmax = 1.0, .zmin_left = -1.2, - .zmin_right = -1.0, + .zmin_right = -1.0 }; // Initialize geometry struct gkyl_position_map *pmap = gkyl_position_map_null_new(); struct gkyl_gk_geometry_inp geometry_input = { - .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, .efit_info = efit_inp, .tok_grid_info = ginp, .position_map = pmap, @@ -662,38 +760,37 @@ test_tok_asdex_qprofile_core_ho() .geo_local_ext = clocal_ext, .geo_global = clocal, .geo_global_ext = clocal_ext, - .geo_basis = cbasis, + .geo_basis = cbasis }; struct gk_geometry *gk_geom = gkyl_gk_geometry_tok_new(&geometry_input); write_geometry(gk_geom, cgrid, clocal, "asdex_core"); -// // Create Nodal Range and Grid and Write Nodal Coordinates -// struct gkyl_range nrange; -// gkyl_gk_geometry_init_nodal_range(&nrange, &clocal, cpoly_order); -// struct gkyl_array* mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); -// struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&cbasis, &cgrid, false); -// gkyl_nodal_ops_m2n(n2m, &cbasis, &cgrid, &nrange, &clocal, 3, mc2p_nodal, gk_geom->geo_int.mc2p, true); -// gkyl_nodal_ops_release(n2m); -// struct gkyl_rect_grid ngrid; -// gkyl_gk_geometry_init_nodal_grid(&ngrid, &cgrid, &nrange); -// -// gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, "asdex_core_nodes.gkyl"); -// gkyl_array_release(mc2p_nodal); + // // Create Nodal Range and Grid and Write Nodal Coordinates + // struct gkyl_range nrange; + // gkyl_gk_geometry_init_nodal_range(&nrange, &clocal, cpoly_order); + // struct gkyl_array* mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); + // struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&cbasis, &cgrid, false); + // gkyl_nodal_ops_m2n(n2m, &cbasis, &cgrid, &nrange, &clocal, 3, mc2p_nodal, gk_geom->geo_int.mc2p, true); + // gkyl_nodal_ops_release(n2m); + // struct gkyl_rect_grid ngrid; + // gkyl_gk_geometry_init_nodal_grid(&ngrid, &cgrid, &nrange); + // + // gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, "asdex_core_nodes.gkyl"); + // gkyl_array_release(mc2p_nodal); gkyl_gk_geometry_release(gk_geom); gkyl_position_map_release(pmap); } -void -test_tok_asdex_qprofile_sol_ho() +void test_tok_asdex_qprofile_sol_ho() { - double clower[] = { 0.16, -0.01, -M_PI+1e-14 }; - double cupper[] = {0.17501, 0.01, M_PI-1e-14 }; - int ccells[] = { 4, 1, 4 }; + double clower[] = {0.16, -0.01, -M_PI + 1e-14}; + double cupper[] = {0.17501, 0.01, M_PI - 1e-14}; + int ccells[] = {4, 1, 4}; int cpoly_order = 1; - int cnghost[GKYL_MAX_CDIM] = { 1, 1, 1 }; + int cnghost[GKYL_MAX_CDIM] = {1, 1, 1}; struct gkyl_rect_grid cgrid; struct gkyl_range clocal, clocal_ext; struct gkyl_basis cbasis; @@ -701,11 +798,10 @@ test_tok_asdex_qprofile_sol_ho() gkyl_create_grid_ranges(&cgrid, cnghost, &clocal_ext, &clocal); gkyl_cart_modal_serendip(&cbasis, 3, cpoly_order); - struct gkyl_efit_inp efit_inp = { - // psiRZ and related inputs - .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", - .rz_poly_order = 2, - .flux_poly_order = 1, + struct gkyl_efit_inp efit_inp = {// psiRZ and related inputs + .filepath = "gyrokinetic/data/eqdsk/asdex.geqdsk", + .rz_poly_order = 2, + .flux_poly_order = 1 }; struct gkyl_tok_geo_grid_inp ginp = { @@ -718,13 +814,13 @@ test_tok_asdex_qprofile_sol_ho() .zmin = -1.3, .zmax = 1.0, .zmin_left = -1.2, - .zmin_right = -1.0, + .zmin_right = -1.0 }; struct gkyl_position_map *pmap = gkyl_position_map_null_new(); struct gkyl_gk_geometry_inp geometry_inp = { - .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, .efit_info = efit_inp, .tok_grid_info = ginp, .position_map = pmap, @@ -739,19 +835,19 @@ test_tok_asdex_qprofile_sol_ho() .geo_local_ext = clocal_ext, .geo_global = clocal, .geo_global_ext = clocal_ext, - .geo_basis = cbasis, + .geo_basis = cbasis }; - struct gk_geometry* gk_geom = gkyl_gk_geometry_tok_new(&geometry_inp); + struct gk_geometry *gk_geom = gkyl_gk_geometry_tok_new(&geometry_inp); write_geometry(gk_geom, cgrid, clocal, "asdex_sol"); gkyl_gk_geometry_release(gk_geom); gkyl_position_map_release(pmap); } TEST_LIST = { - { "test_tok_elliptical_ho", test_tok_elliptical_ho}, - { "test_tok_3x_p1_straight_cylinder_ho", test_tok_3x_p1_straight_cylinder_ho}, - { "test_tok_asdex_qprofile_core_ho", test_tok_asdex_qprofile_core_ho}, - { "test_tok_asdex_qprofile_sol_ho", test_tok_asdex_qprofile_sol_ho}, - { NULL, NULL }, + {"test_tok_elliptical_ho", test_tok_elliptical_ho}, + {"test_tok_3x_p1_straight_cylinder_ho", test_tok_3x_p1_straight_cylinder_ho}, + {"test_tok_asdex_qprofile_core_ho", test_tok_asdex_qprofile_core_ho}, + {"test_tok_asdex_qprofile_sol_ho", test_tok_asdex_qprofile_sol_ho}, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_gkgeom.c b/gyrokinetic/unit/ctest_gkgeom.c index 621ead1ea0..10d255c028 100644 --- a/gyrokinetic/unit/ctest_gkgeom.c +++ b/gyrokinetic/unit/ctest_gkgeom.c @@ -12,36 +12,47 @@ // Elliptical "equilibrium" +static inline double sq(double x) +{ + return x * x; +} +static inline double cub(double x) +{ + return x * x * x; +} +static inline double qad(double x) +{ + return x * x * x * x; +} +static inline double pen(double x) +{ + return x * x * x * x * x; +} +static inline double hex(double x) +{ + return x * x * x * x * x * x; +} - -static inline double sq(double x) { return x*x; } -static inline double cub(double x) { return x*x*x; } -static inline double qad(double x) { return x*x*x*x; } -static inline double pen(double x) { return x*x*x*x*x; } -static inline double hex(double x) { return x*x*x*x*x*x; } - -void -psi_ellip(double t, const double *xn, double *fout, void *ctx) +void psi_ellip(double t, const double *xn, double *fout, void *ctx) { double R = xn[0], Z = xn[1]; - fout[0] = (R-2)*(R-2) + Z*Z/4; + fout[0] = (R - 2) * (R - 2) + Z * Z / 4; } -void -gkgeom_ellip_unit_ho(void) +void gkgeom_ellip_unit_ho(void) { // create RZ grid - double lower[] = { 0.5, -4.0 }, upper[] = { 6.0, 4.0 }; + double lower[] = {0.5, -4.0}, upper[] = {6.0, 4.0}; // as ellipitical surfaces are exact, we only need 1 cell in each // direction - int cells[] = { 1, 1 }; + int cells[] = {1, 1}; struct gkyl_rect_grid rzgrid; gkyl_rect_grid_init(&rzgrid, 2, lower, upper, cells); // RZ ranges struct gkyl_range rzlocal, rzlocal_ext; - int nghost[GKYL_MAX_CDIM] = { 0, 0 }; + int nghost[GKYL_MAX_CDIM] = {0, 0}; gkyl_create_grid_ranges(&rzgrid, nghost, &rzlocal_ext, &rzlocal); // RZ basis function @@ -51,23 +62,20 @@ gkgeom_ellip_unit_ho(void) // allocate psiRZ array, initialize and write it to file struct gkyl_array *psiRZ = gkyl_array_new(GKYL_DOUBLE, rzbasis.num_basis, rzlocal_ext.volume); - - gkyl_eval_on_nodes *eon = gkyl_eval_on_nodes_new(&rzgrid, - &rzbasis, 1, &psi_ellip, 0); + + gkyl_eval_on_nodes *eon = gkyl_eval_on_nodes_new(&rzgrid, &rzbasis, 1, &psi_ellip, 0); gkyl_eval_on_nodes_advance(eon, 0.0, &rzlocal, psiRZ); gkyl_eval_on_nodes_release(eon); gkyl_grid_sub_array_write(&rzgrid, &rzlocal, 0, psiRZ, "ellip_psi.gkyl"); - gkyl_gkgeom *geo = gkyl_gkgeom_new(&(struct gkyl_gkgeom_inp) { - // psiRZ and related inputs - .rzgrid = &rzgrid, - .rzbasis = &rzbasis, - .psiRZ = psiRZ, - .rzlocal = &rzlocal, - .quad_param = { .eps = 1e-14 } - } - ); + gkyl_gkgeom *geo = gkyl_gkgeom_new(&(struct gkyl_gkgeom_inp){// psiRZ and related inputs + .rzgrid = &rzgrid, + .rzbasis = &rzbasis, + .psiRZ = psiRZ, + .rzlocal = &rzlocal, + .quad_param = {.eps = 1e-14} + }); // exact values computed with the following Maxima code /* @@ -84,25 +92,23 @@ gkgeom_ellip_unit_ho(void) fR : sqrt(1+diff(R,Z)^2)$ Ipsi : quad_qag(fR,Z,Zmin,Zmax, 3, 'epsrel=1e-12)$ */ - + do { double psi_ref = 6.0; - double arcL = gkyl_gkgeom_integrate_psi_contour(geo, psi_ref, - lower[1], upper[1], upper[0]); + double arcL = gkyl_gkgeom_integrate_psi_contour(geo, psi_ref, lower[1], upper[1], upper[0]); - TEST_CHECK( gkyl_compare(8.382428377712543, arcL, 1e-12) ); - - } while(0); + TEST_CHECK(gkyl_compare(8.382428377712543, arcL, 1e-12)); + + } while (0); do { double psi_ref = 10.1; - double arcL = gkyl_gkgeom_integrate_psi_contour(geo, psi_ref, - lower[1], upper[1], upper[0]); + double arcL = gkyl_gkgeom_integrate_psi_contour(geo, psi_ref, lower[1], upper[1], upper[0]); + + TEST_CHECK(gkyl_compare(8.172574228918158, arcL, 1e-12)); + + } while (0); - TEST_CHECK( gkyl_compare(8.172574228918158, arcL, 1e-12) ); - - } while(0); - gkyl_gkgeom_release(geo); gkyl_array_release(psiRZ); } @@ -112,34 +118,40 @@ struct cerfon_ctx { double R0, psi_prefactor; }; -void -psi_cerfon(double t, const double *xn, double *fout, void *ctx) +void psi_cerfon(double t, const double *xn, double *fout, void *ctx) { struct cerfon_ctx *s = ctx; double R0 = s->R0, psi_prefactor = s->psi_prefactor; double R = xn[0], Z = xn[1]; - double x = R/R0, y = Z/R0; - - fout[0] = psi_prefactor*(0.00373804283369699*hex(x)*log(x) - 0.00574955335438162*hex(x) - 0.0448565140043639*qad(x)*sq(y)*log(x) + 0.0503044260840946*qad(x)*sq(y) + 0.017623348727471*qad(x)*log(x) + 0.0956643504553683*qad(x) + 0.0299043426695759*sq(x)*qad(y)*log(x) - 0.0160920841654771*sq(x)*qad(y) - 0.0704933949098842*sq(x)*sq(y)*log(x) + 0.0644725519961135*sq(x)*sq(y) - 7.00898484784405e-5*sq(x)*log(x) - 0.303766642191745*sq(x) - 0.00199362284463839*hex(y) + 0.0117488991516474*qad(y) + 7.00898484784405e-5*sq(y) + 0.0145368720253975); + double x = R / R0, y = Z / R0; + + fout[0] = psi_prefactor * + (0.00373804283369699 * hex(x) * log(x) - 0.00574955335438162 * hex(x) - + 0.0448565140043639 * qad(x) * sq(y) * log(x) + 0.0503044260840946 * qad(x) * sq(y) + + 0.017623348727471 * qad(x) * log(x) + 0.0956643504553683 * qad(x) + + 0.0299043426695759 * sq(x) * qad(y) * log(x) - 0.0160920841654771 * sq(x) * qad(y) - + 0.0704933949098842 * sq(x) * sq(y) * log(x) + 0.0644725519961135 * sq(x) * sq(y) - + 7.00898484784405e-5 * sq(x) * log(x) - 0.303766642191745 * sq(x) - + 0.00199362284463839 * hex(y) + 0.0117488991516474 * qad(y) + + 7.00898484784405e-5 * sq(y) + 0.0145368720253975); } -void -gkgeom_cerfon_unit_ho(void) +void gkgeom_cerfon_unit_ho(void) { // Cerfon Double Null Configuration - - struct cerfon_ctx ctx = { .R0 = 2.5, .psi_prefactor = 1.0 }; - + + struct cerfon_ctx ctx = {.R0 = 2.5, .psi_prefactor = 1.0}; + // create RZ grid - double lower[] = { 0.01, -6.0 }, upper[] = { 6.0, 6.0 }; - int cells[] = { 64, 128 }; + double lower[] = {0.01, -6.0}, upper[] = {6.0, 6.0}; + int cells[] = {64, 128}; struct gkyl_rect_grid rzgrid; gkyl_rect_grid_init(&rzgrid, 2, lower, upper, cells); // RZ ranges struct gkyl_range rzlocal, rzlocal_ext; - int nghost[GKYL_MAX_CDIM] = { 0, 0 }; + int nghost[GKYL_MAX_CDIM] = {0, 0}; gkyl_create_grid_ranges(&rzgrid, nghost, &rzlocal_ext, &rzlocal); // RZ basis function @@ -149,86 +161,83 @@ gkgeom_cerfon_unit_ho(void) // allocate psiRZ array, initialize and write it to file struct gkyl_array *psiRZ = gkyl_array_new(GKYL_DOUBLE, rzbasis.num_basis, rzlocal_ext.volume); - - gkyl_eval_on_nodes *eon = gkyl_eval_on_nodes_new(&rzgrid, - &rzbasis, 1, &psi_cerfon, &ctx); + + gkyl_eval_on_nodes *eon = gkyl_eval_on_nodes_new(&rzgrid, &rzbasis, 1, &psi_cerfon, &ctx); gkyl_eval_on_nodes_advance(eon, 0.0, &rzlocal, psiRZ); gkyl_eval_on_nodes_release(eon); gkyl_grid_sub_array_write(&rzgrid, &rzlocal, 0, psiRZ, "cerfon_psi.gkyl"); - gkyl_gkgeom *geo = gkyl_gkgeom_new(&(struct gkyl_gkgeom_inp) { - // psiRZ and related inputs - .rzgrid = &rzgrid, - .rzbasis = &rzbasis, - .psiRZ = psiRZ, - .rzlocal = &rzlocal - } - ); + gkyl_gkgeom *geo = gkyl_gkgeom_new(&(struct gkyl_gkgeom_inp){// psiRZ and related inputs + .rzgrid = &rzgrid, + .rzbasis = &rzbasis, + .psiRZ = psiRZ, + .rzlocal = &rzlocal + }); int cum_nroots = 0; // compute R for various psi, Z do { double psi = 0.060095, Z = -5.611532889; - double R[2] = { 0.0 }, dR[2] = { 0.0 }; + double R[2] = {0.0}, dR[2] = {0.0}; int nr = gkyl_gkgeom_R_psiZ(geo, psi, Z, 2, R, dR); double rcheck = 2.63244; - for (int i=0; iB, gamma = s->gamma, Zm = s->Zm; double R = xn[0], Z = xn[1]; // double Lorentzian: See Francisquez PoP 2023. - double psi = sq(R)*B/(2*M_PI*gamma)* - ( - 1/(1+sq((Z-Zm)/gamma)) - + - 1/(1+sq((Z+Zm)/gamma)) - ); + double psi = sq(R) * B / (2 * M_PI * gamma) * + (1 / (1 + sq((Z - Zm) / gamma)) + 1 / (1 + sq((Z + Zm) / gamma))); fout[0] = psi; } -void -gkgeom_wham_2l_unit_ho(void) +void gkgeom_wham_2l_unit_ho(void) { - // WHAM Configuration - struct wham_ctx ctx = { - .B = 6.51292, - .gamma = 0.124904, - .Zm = 0.98 - }; - + struct wham_ctx ctx = {.B = 6.51292, .gamma = 0.124904, .Zm = 0.98}; + // create RZ grid - double lower[] = { 0.01, -2.0 }; - double upper[] = { 0.4, 2.0 }; - int cells[] = { 64, 128 }; + double lower[] = {0.01, -2.0}; + double upper[] = {0.4, 2.0}; + int cells[] = {64, 128}; struct gkyl_rect_grid rzgrid; gkyl_rect_grid_init(&rzgrid, 2, lower, upper, cells); // RZ ranges struct gkyl_range rzlocal, rzlocal_ext; - int nghost[GKYL_MAX_CDIM] = { 0, 0 }; + int nghost[GKYL_MAX_CDIM] = {0, 0}; gkyl_create_grid_ranges(&rzgrid, nghost, &rzlocal_ext, &rzlocal); // RZ basis function @@ -345,22 +343,19 @@ gkgeom_wham_2l_unit_ho(void) // allocate psiRZ array, initialize and write it to file struct gkyl_array *psiRZ = gkyl_array_new(GKYL_DOUBLE, rzbasis.num_basis, rzlocal_ext.volume); - - gkyl_eval_on_nodes *eon = gkyl_eval_on_nodes_new(&rzgrid, - &rzbasis, 1, &psi_wham, &ctx); + + gkyl_eval_on_nodes *eon = gkyl_eval_on_nodes_new(&rzgrid, &rzbasis, 1, &psi_wham, &ctx); gkyl_eval_on_nodes_advance(eon, 0.0, &rzlocal, psiRZ); gkyl_eval_on_nodes_release(eon); gkyl_grid_sub_array_write(&rzgrid, &rzlocal, 0, psiRZ, "wham_psi.gkyl"); - gkyl_gkgeom *geo = gkyl_gkgeom_new(&(struct gkyl_gkgeom_inp) { - // psiRZ and related inputs - .rzgrid = &rzgrid, - .rzbasis = &rzbasis, - .psiRZ = psiRZ, - .rzlocal = &rzlocal - } - ); + gkyl_gkgeom *geo = gkyl_gkgeom_new(&(struct gkyl_gkgeom_inp){// psiRZ and related inputs + .rzgrid = &rzgrid, + .rzbasis = &rzbasis, + .psiRZ = psiRZ, + .rzlocal = &rzlocal + }); int cum_nroots = 0; @@ -368,27 +363,27 @@ gkgeom_wham_2l_unit_ho(void) // compute outboard SOL geometry int npsi = 10, ntheta = 16; double psi_min = 0.001, psi_max = 0.02; - double dpsi = (psi_max-psi_min)/npsi; - double dtheta = M_PI/ntheta; - + double dpsi = (psi_max - psi_min) / npsi; + double dtheta = M_PI / ntheta; + // Computational grid: theta X psi X alpha (only 2D for now) - double clower[] = { -M_PI/2, psi_min }; - double cupper[] = { M_PI/2, psi_max }; - int ccells[] = { 16, 10 }; - + double clower[] = {-M_PI / 2, psi_min}; + double cupper[] = {M_PI / 2, psi_max}; + int ccells[] = {16, 10}; + struct gkyl_rect_grid cgrid; gkyl_rect_grid_init(&cgrid, 2, clower, cupper, ccells); // create mpc2p DG array struct gkyl_range clocal, clocal_ext; - gkyl_create_grid_ranges(&cgrid, (int[]) { 0, 0, 0 }, - &clocal_ext, &clocal); + gkyl_create_grid_ranges(&cgrid, (int[]){0, 0, 0}, &clocal_ext, &clocal); int cpoly_order = 2; struct gkyl_basis cbasis; gkyl_cart_modal_serendip(&cbasis, 2, cpoly_order); - struct gkyl_array *mapc2p = gkyl_array_new(GKYL_DOUBLE, 2*cbasis.num_basis, clocal_ext.volume); - + struct gkyl_array *mapc2p = + gkyl_array_new(GKYL_DOUBLE, 2 * cbasis.num_basis, clocal_ext.volume); + struct gkyl_gkgeom_geo_inp ginp = { .cgrid = &cgrid, .cbasis = &cbasis, @@ -396,47 +391,43 @@ gkgeom_wham_2l_unit_ho(void) .rclose = upper[0], .zmin = lower[1], .zmax = upper[1], - + .write_node_coord_array = true, .node_file_nm = "wham_out_sol_nod.gkyl" }; gkyl_gkgeom_calcgeom(geo, &ginp, mapc2p); - + gkyl_array_release(mapc2p); - } while(0); + } while (0); gkyl_gkgeom_release(geo); gkyl_array_release(psiRZ); } -void -wham_beta0_rt(void) +void wham_beta0_rt(void) { fprintf(stdout, "---- WHAM beta-0 Configuration\n"); - + struct gkyl_rect_grid rzgrid; - struct gkyl_array *psiRZ = - gkyl_grid_array_new_from_file(&rzgrid, "psi_dg.gkyl"); + struct gkyl_array *psiRZ = gkyl_grid_array_new_from_file(&rzgrid, "psi_dg.gkyl"); // RZ ranges struct gkyl_range rzlocal, rzlocal_ext; - int nghost[GKYL_MAX_CDIM] = { 0, 0 }; - gkyl_create_grid_ranges(&rzgrid, nghost, &rzlocal_ext, &rzlocal); - + int nghost[GKYL_MAX_CDIM] = {0, 0}; + gkyl_create_grid_ranges(&rzgrid, nghost, &rzlocal_ext, &rzlocal); + // RZ basis function int rz_poly_order = 2; struct gkyl_basis rzbasis; - gkyl_cart_modal_serendip(&rzbasis, 2, rz_poly_order); - - gkyl_gkgeom *geo = gkyl_gkgeom_new(&(struct gkyl_gkgeom_inp) { - // psiRZ and related inputs - .rzgrid = &rzgrid, - .rzbasis = &rzbasis, - .psiRZ = psiRZ, - .rzlocal = &rzlocal - } - ); + gkyl_cart_modal_serendip(&rzbasis, 2, rz_poly_order); + + gkyl_gkgeom *geo = gkyl_gkgeom_new(&(struct gkyl_gkgeom_inp){// psiRZ and related inputs + .rzgrid = &rzgrid, + .rzbasis = &rzbasis, + .psiRZ = psiRZ, + .rzlocal = &rzlocal + }); int cum_nroots = 0; @@ -444,28 +435,28 @@ wham_beta0_rt(void) // compute outboard SOL geometry int npsi = 10, ntheta = 16; //double psi_min = 1.0e-4, psi_max = 3.16726875e-03; - double psi_min = 0.0e-6, psi_max = 3.16726875e-03; - double dpsi = (psi_max-psi_min)/npsi; - double dtheta = M_PI/ntheta; - + double psi_min = 0.0e-6, psi_max = 3.16726875e-03; + double dpsi = (psi_max - psi_min) / npsi; + double dtheta = M_PI / ntheta; + // Computational grid: theta X psi X alpha (only 2D for now) - double clower[] = { -M_PI/2, psi_min }; - double cupper[] = { M_PI/2, psi_max }; - int ccells[] = { 16, 10 }; - + double clower[] = {-M_PI / 2, psi_min}; + double cupper[] = {M_PI / 2, psi_max}; + int ccells[] = {16, 10}; + struct gkyl_rect_grid cgrid; gkyl_rect_grid_init(&cgrid, 2, clower, cupper, ccells); // create mpc2p DG array struct gkyl_range clocal, clocal_ext; - gkyl_create_grid_ranges(&cgrid, (int[]) { 0, 0, 0 }, - &clocal_ext, &clocal); + gkyl_create_grid_ranges(&cgrid, (int[]){0, 0, 0}, &clocal_ext, &clocal); int cpoly_order = 2; struct gkyl_basis cbasis; gkyl_cart_modal_serendip(&cbasis, 2, cpoly_order); - struct gkyl_array *mapc2p = gkyl_array_new(GKYL_DOUBLE, 2*cbasis.num_basis, clocal_ext.volume); - + struct gkyl_array *mapc2p = + gkyl_array_new(GKYL_DOUBLE, 2 * cbasis.num_basis, clocal_ext.volume); + struct gkyl_gkgeom_geo_inp ginp = { .cgrid = &cgrid, .cbasis = &cbasis, @@ -473,27 +464,29 @@ wham_beta0_rt(void) .rclose = rzgrid.upper[0], .zmin = -2.0, //rzgrid.lower[1], .zmax = 2.0, //rzgrid.upper[1], - + .write_node_coord_array = true, .node_file_nm = "wham_out_sol_nod.gkyl" }; gkyl_gkgeom_calcgeom(geo, &ginp, mapc2p); - + struct gkyl_gkgeom_stat stat = gkyl_gkgeom_get_stat(geo); - fprintf(stdout, "Total number of contour funcs called = %ld. Total calls from root-finder = %ld\n", - stat.nquad_cont_calls-cum_nroots, stat.nroot_cont_calls); + fprintf( + stdout, "Total number of contour funcs called = %ld. Total calls from root-finder = %ld\n", + stat.nquad_cont_calls - cum_nroots, stat.nroot_cont_calls + ); gkyl_array_release(mapc2p); - } while(0); + } while (0); gkyl_gkgeom_release(geo); - gkyl_array_release(psiRZ); + gkyl_array_release(psiRZ); } TEST_LIST = { - { "gkgeom_ellip_ho", gkgeom_ellip_unit_ho }, - { "gkgeom_cerfon_ho", gkgeom_cerfon_unit_ho }, - { "gkgeom_wham_ho", gkgeom_wham_2l_unit_ho }, - { NULL, NULL } + {"gkgeom_ellip_ho", gkgeom_ellip_unit_ho}, + {"gkgeom_cerfon_ho", gkgeom_cerfon_unit_ho}, + {"gkgeom_wham_ho", gkgeom_wham_2l_unit_ho}, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_gkneut_hamil.c b/gyrokinetic/unit/ctest_gkneut_hamil.c index 3a7954b734..db7e54c23c 100644 --- a/gyrokinetic/unit/ctest_gkneut_hamil.c +++ b/gyrokinetic/unit/ctest_gkneut_hamil.c @@ -10,29 +10,29 @@ #include // Function to allocate a gkyl array, zero-initialized, on CPU or GPU -static struct gkyl_array* mkarr(bool on_gpu, long nc, long size) { - return on_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) +{ + return on_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); } -void eval_gxx(double t, const double *xn, double* restrict fout, void *ctx) +void eval_gxx(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 1.0; } -void eval_gyy(double t, const double *xn, double* restrict fout, void *ctx) +void eval_gyy(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 2.0; } -void eval_gzz(double t, const double *xn, double* restrict fout, void *ctx) +void eval_gzz(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 3.0; } -void -test_hamil(int cdim, bool use_gpu) +void test_hamil(int cdim, bool use_gpu) { // construct phase grid // construct phase basis @@ -49,15 +49,14 @@ test_hamil(int cdim, bool use_gpu) int Nx = 4; int Nv = 16; - for(int i=0; incomp, hamil->size) - : gkyl_array_acquire(hamil); + hamil_ho = use_gpu ? mkarr(false, hamil->ncomp, hamil->size) : gkyl_array_acquire(hamil); struct gkyl_array *gxx_ho, *gyy_ho, *gzz_ho; - gxx_ho = use_gpu ? mkarr(false, gxx->ncomp, gxx->size) - : gkyl_array_acquire(gxx); - gyy_ho = use_gpu ? mkarr(false, gyy->ncomp, gyy->size) - : gkyl_array_acquire(gyy); - gzz_ho = use_gpu ? mkarr(false, gzz->ncomp, gzz->size) - : gkyl_array_acquire(gzz); + gxx_ho = use_gpu ? mkarr(false, gxx->ncomp, gxx->size) : gkyl_array_acquire(gxx); + gyy_ho = use_gpu ? mkarr(false, gyy->ncomp, gyy->size) : gkyl_array_acquire(gyy); + gzz_ho = use_gpu ? mkarr(false, gzz->ncomp, gzz->size) : gkyl_array_acquire(gzz); gkyl_proj_on_basis_advance(proj_gxx, 1.0, &confRange, gxx_ho); gkyl_proj_on_basis_advance(proj_gyy, 1.0, &confRange, gyy_ho); @@ -120,12 +115,13 @@ test_hamil(int cdim, bool use_gpu) gkyl_array_set_offset(gij, 1.0, gxx, 0); gkyl_array_set_offset(gij, 1.0, gxy, cbasis.num_basis); - gkyl_array_set_offset(gij, 1.0, gxz, 2*cbasis.num_basis); - gkyl_array_set_offset(gij, 1.0, gyy, 3*cbasis.num_basis); - gkyl_array_set_offset(gij, 1.0, gyz, 4*cbasis.num_basis); - gkyl_array_set_offset(gij, 1.0, gzz, 5*cbasis.num_basis); + gkyl_array_set_offset(gij, 1.0, gxz, 2 * cbasis.num_basis); + gkyl_array_set_offset(gij, 1.0, gyy, 3 * cbasis.num_basis); + gkyl_array_set_offset(gij, 1.0, gyz, 4 * cbasis.num_basis); + gkyl_array_set_offset(gij, 1.0, gzz, 5 * cbasis.num_basis); - struct gkyl_dg_calc_gk_neut_hamil* hamil_calc = gkyl_dg_calc_gk_neut_hamil_new(&grid, &pbasis, cdim, use_gpu); + struct gkyl_dg_calc_gk_neut_hamil *hamil_calc = + gkyl_dg_calc_gk_neut_hamil_new(&grid, &pbasis, cdim, use_gpu); gkyl_dg_calc_gk_neut_hamil_calc(hamil_calc, &confRange, &range, gij, hamil); if (use_gpu) { @@ -135,65 +131,72 @@ test_hamil(int cdim, bool use_gpu) /* char fname[1024]; */ /* sprintf(fname, "ctest_gk_neut_hamil_%dx.gkyl", cdim); */ /* gkyl_grid_sub_array_write(&grid, &range, 0, hamil, fname); */ - + // test against predicted value - if (cdim==3) { - const double *fv = gkyl_array_cfetch(hamil_ho, gkyl_range_idx(&range_ext, (int[6]){1, 1, 1, 1, 1, 1})); - double p1_vals[] = { 2.1125000000000000e+01, -2.2204460492503131e-16, 3.3306690738754696e-16, - 2.2204460492503131e-16, -2.7063293868263760e-01, -5.4126587736527476e-01, - -8.1189881604791214e-01, -8.3266726846886741e-17, -1.6653345369377348e-16, - -1.3877787807814457e-16, 0.0000000000000000e+00, 2.7755575615628914e-16, - -8.3266726846886741e-17, 0.0000000000000000e+00, 2.7755575615628914e-17, - 0.0000000000000000e+00, 0.0000000000000000e+00, 5.2735593669694936e-16, - -1.9428902930940239e-16, -2.2204460492503131e-16, 0.0000000000000000e+00, - 2.2204460492503131e-16, 1.3877787807814457e-16, -2.7755575615628914e-17, - 2.7755575615628914e-17, -2.7755575615628914e-17, -2.7755575615628914e-17, - -1.1102230246251565e-16, 0.0000000000000000e+00, -5.5511151231257827e-17, - 0.0000000000000000e+00, -1.1102230246251565e-16, 0.0000000000000000e+00, - 0.0000000000000000e+00, 0.0000000000000000e+00, 5.5511151231257827e-17, - -2.2204460492503131e-16, 2.2204460492503131e-16, -2.7755575615628914e-17, - 1.6653345369377348e-16, -2.2204460492503131e-16, -5.5511151231257827e-17, - -6.9388939039072284e-17, -4.8572257327350599e-17, 3.4694469519536142e-17, - -4.8572257327350599e-17, -1.1102230246251565e-16, -1.1102230246251565e-16, - -5.5511151231257827e-17, 0.0000000000000000e+00, 5.5511151231257827e-17, - -1.1102230246251565e-16, -1.3877787807814457e-16, 5.5511151231257827e-17, - 4.1633363423443370e-17, 5.5511151231257827e-17, -2.7755575615628914e-17, - -6.9388939039072284e-18, 1.7347234759768071e-17, 2.0816681711721685e-17, - 1.3877787807814457e-17, 2.7755575615628914e-17, -2.0816681711721685e-17, - -8.7378663975128048e-18}; - for (int i=0; i // Allocate cu_dev array -static struct gkyl_array* -mkarr(long nc, long size, bool use_gpu) +static struct gkyl_array *mkarr(long nc, long size, bool use_gpu) { - struct gkyl_array* a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } // Create ghost ranges -struct skin_ghost_ranges -{ +struct skin_ghost_ranges { struct gkyl_range lower_skin[GKYL_MAX_DIM]; struct gkyl_range lower_ghost[GKYL_MAX_DIM]; @@ -33,17 +32,19 @@ struct skin_ghost_ranges }; // Create ghost and skin sub-ranges given a parent range -static void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { int ndim = parent->ndim; - for (int d = 0; d < ndim; ++d){ - gkyl_skin_ghost_ranges(&sgr->lower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } @@ -57,50 +58,52 @@ void eval_den_i(double t, const double *xn, double *restrict fout, void *ctx) double x = xn[0]; fout[0] = 1.0e19; } -void eval_vtsq_e(double t, const double *xn, double* restrict fout, void *ctx) +void eval_vtsq_e(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double eV = 1.602e-19; double me = 9.11e-31; - double Te = 30.0*eV; - fout[0] = Te/me; + double Te = 30.0 * eV; + fout[0] = Te / me; } -void eval_vtsq_i(double t, const double *xn, double* restrict fout, void *ctx) +void eval_vtsq_i(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double eV = 1.602e-19; double mi = 1.67e-27; - double Ti = 10.0*eV; - fout[0] = Ti/mi; + double Ti = 10.0 * eV; + fout[0] = Ti / mi; } void eval_upar_e(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double vtsq[1]; eval_vtsq_e(t, xn, vtsq, ctx); - double vt = sqrt(vtsq[0]); - fout[0] = 0.01*vt; + double vt = sqrt(vtsq[0]); + fout[0] = 0.01 * vt; } void eval_upar_i(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double vtsq[1]; eval_vtsq_i(t, xn, vtsq, ctx); - double vt = sqrt(vtsq[0]); - fout[0] = 0.01*vt; + double vt = sqrt(vtsq[0]); + fout[0] = 0.01 * vt; } void eval_nu_ei(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double eV = 1.602e-19; double me = 9.11e-31; - double Te = 30.0*eV; + double Te = 30.0 * eV; double logLambdaElc, nuElc; double den[1]; - eval_den_e(t, xn, den, ctx); - logLambdaElc = 6.6 - 0.5*log(den[0]/1.0e20) + 1.5*log(Te/eV); - nuElc = logLambdaElc*pow(eV,4)*den[0]/(6.0*sqrt(2.0)*pow(M_PI,3.0/2.0)*pow(8.85e-12,2)*sqrt(me)*pow(Te,3.0/2.0)); - fout[0] = nuElc/1.96; + eval_den_e(t, xn, den, ctx); + logLambdaElc = 6.6 - 0.5 * log(den[0] / 1.0e20) + 1.5 * log(Te / eV); + nuElc = + logLambdaElc * pow(eV, 4) * den[0] / + (6.0 * sqrt(2.0) * pow(M_PI, 3.0 / 2.0) * pow(8.85e-12, 2) * sqrt(me) * pow(Te, 3.0 / 2.0)); + fout[0] = nuElc / 1.96; } void eval_nu_ie(double t, const double *xn, double *restrict fout, void *ctx) { @@ -108,8 +111,8 @@ void eval_nu_ie(double t, const double *xn, double *restrict fout, void *ctx) double me = 9.11e-31; double mi = 1.67e-27; double nu_ei[1]; - eval_nu_ei(t, xn, nu_ei, ctx); - fout[0] = nu_ei[0]*me/mi; + eval_nu_ei(t, xn, nu_ei, ctx); + fout[0] = nu_ei[0] * me / mi; } void test_1x1v(int poly_order, bool use_gpu) @@ -117,12 +120,12 @@ void test_1x1v(int poly_order, bool use_gpu) double eV = 1.602e-19; double me = 9.11e-31; double mi = 1.67e-27; - double Te = 30.0*eV; + double Te = 30.0 * eV; double delta_sr = 1.0; double betaGreenep1 = 1.0; - double vt = sqrt(Te/me); + double vt = sqrt(Te / me); - double lower[] = {-0.5, -5.0*vt}, upper[] = {0.5, 5.0*vt}; + double lower[] = {-0.5, -5.0 * vt}, upper[] = {0.5, 5.0 * vt}; int cells[] = {2, 32}; int vdim = 1, cdim = 1; int ndim = cdim + vdim; @@ -138,10 +141,11 @@ void test_1x1v(int poly_order, bool use_gpu) // Basis functions struct gkyl_basis basis, confBasis; - if (poly_order==1) + if (poly_order == 1) { gkyl_cart_modal_gkhybrid(&basis, cdim, vdim); - else + } else { gkyl_cart_modal_serendip(&basis, ndim, poly_order); + } gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); // Configuration space range @@ -164,9 +168,12 @@ void test_1x1v(int poly_order, bool use_gpu) den_e_ho = mkarr(confBasis.num_basis, confLocal_ext.volume, false); upar_e_ho = mkarr(confBasis.num_basis, confLocal_ext.volume, false); vtsq_e_ho = mkarr(confBasis.num_basis, confLocal_ext.volume, false); - gkyl_proj_on_basis *proj_den_e = gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order+1, 1, eval_den_e, NULL); - gkyl_proj_on_basis *proj_upar_e = gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order+1, 1, eval_upar_e, NULL); - gkyl_proj_on_basis *proj_vtsq_e = gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order+1, 1, eval_vtsq_e, NULL); + gkyl_proj_on_basis *proj_den_e = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_den_e, NULL); + gkyl_proj_on_basis *proj_upar_e = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_upar_e, NULL); + gkyl_proj_on_basis *proj_vtsq_e = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_vtsq_e, NULL); gkyl_proj_on_basis_advance(proj_den_e, 0.0, &confLocal, den_e_ho); gkyl_proj_on_basis_advance(proj_upar_e, 0.0, &confLocal, upar_e_ho); gkyl_proj_on_basis_advance(proj_vtsq_e, 0.0, &confLocal, vtsq_e_ho); @@ -183,18 +190,21 @@ void test_1x1v(int poly_order, bool use_gpu) upar_e = upar_e_ho; vtsq_e = vtsq_e_ho; } - struct gkyl_array *prim_moms_e = mkarr(3*confBasis.num_basis, confLocal_ext.volume, use_gpu); - gkyl_array_set_offset(prim_moms_e, 1., den_e, 0*confBasis.num_basis); - gkyl_array_set_offset(prim_moms_e, 1., upar_e, 1*confBasis.num_basis); - gkyl_array_set_offset(prim_moms_e, 1., vtsq_e, 2*confBasis.num_basis); + struct gkyl_array *prim_moms_e = mkarr(3 * confBasis.num_basis, confLocal_ext.volume, use_gpu); + gkyl_array_set_offset(prim_moms_e, 1., den_e, 0 * confBasis.num_basis); + gkyl_array_set_offset(prim_moms_e, 1., upar_e, 1 * confBasis.num_basis); + gkyl_array_set_offset(prim_moms_e, 1., vtsq_e, 2 * confBasis.num_basis); // (2) ion struct gkyl_array *den_i_ho, *upar_i_ho, *vtsq_i_ho; den_i_ho = mkarr(confBasis.num_basis, confLocal_ext.volume, false); upar_i_ho = mkarr(confBasis.num_basis, confLocal_ext.volume, false); vtsq_i_ho = mkarr(confBasis.num_basis, confLocal_ext.volume, false); - gkyl_proj_on_basis *proj_den_i = gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order+1, 1, eval_den_i, NULL); - gkyl_proj_on_basis *proj_upar_i = gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order+1, 1, eval_upar_i, NULL); - gkyl_proj_on_basis *proj_vtsq_i = gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order+1, 1, eval_vtsq_i, NULL); + gkyl_proj_on_basis *proj_den_i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_den_i, NULL); + gkyl_proj_on_basis *proj_upar_i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_upar_i, NULL); + gkyl_proj_on_basis *proj_vtsq_i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_vtsq_i, NULL); gkyl_proj_on_basis_advance(proj_den_i, 0.0, &confLocal, den_i_ho); gkyl_proj_on_basis_advance(proj_upar_i, 0.0, &confLocal, upar_i_ho); gkyl_proj_on_basis_advance(proj_vtsq_i, 0.0, &confLocal, vtsq_i_ho); @@ -211,27 +221,36 @@ void test_1x1v(int poly_order, bool use_gpu) upar_i = upar_i_ho; vtsq_i = vtsq_i_ho; } - struct gkyl_array *prim_moms_i = mkarr(3*confBasis.num_basis, confLocal_ext.volume, use_gpu); - gkyl_array_set_offset(prim_moms_i, 1., den_i, 0*confBasis.num_basis); - gkyl_array_set_offset(prim_moms_i, 1., upar_i, 1*confBasis.num_basis); - gkyl_array_set_offset(prim_moms_i, 1., vtsq_i, 2*confBasis.num_basis); - + struct gkyl_array *prim_moms_i = mkarr(3 * confBasis.num_basis, confLocal_ext.volume, use_gpu); + gkyl_array_set_offset(prim_moms_i, 1., den_i, 0 * confBasis.num_basis); + gkyl_array_set_offset(prim_moms_i, 1., upar_i, 1 * confBasis.num_basis); + gkyl_array_set_offset(prim_moms_i, 1., vtsq_i, 2 * confBasis.num_basis); + // Create collisionality arrays struct gkyl_array *nu_ei = mkarr(confBasis.num_basis, confLocal_ext.volume, use_gpu); - gkyl_proj_on_basis *proj_nu_ei = gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order+1, 1, eval_nu_ei, NULL); + gkyl_proj_on_basis *proj_nu_ei = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_nu_ei, NULL); struct gkyl_array *nu_ie = mkarr(confBasis.num_basis, confLocal_ext.volume, use_gpu); - gkyl_proj_on_basis *proj_nu_ie = gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order+1, 1, eval_nu_ie, NULL); + gkyl_proj_on_basis *proj_nu_ie = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_nu_ie, NULL); gkyl_proj_on_basis_advance(proj_nu_ei, 0.0, &confLocal, nu_ei); gkyl_proj_on_basis_advance(proj_nu_ie, 0.0, &confLocal, nu_ie); // Calculate the cross primitive moments - gkyl_gyrokinetic_cross_prim_moms_bgk *crossPrimMomsCalc = gkyl_gyrokinetic_cross_prim_moms_bgk_new(&basis, &confBasis, use_gpu); - struct gkyl_array *prim_moms_cross_e = mkarr(3*confBasis.num_basis, confLocal_ext.volume, use_gpu); - struct gkyl_array *prim_moms_cross_i = mkarr(3*confBasis.num_basis, confLocal_ext.volume, use_gpu); - gkyl_gyrokinetic_cross_prim_moms_bgk_advance(crossPrimMomsCalc, &confLocal, delta_sr, betaGreenep1, - me, prim_moms_e, mi, prim_moms_i, prim_moms_cross_e); - gkyl_gyrokinetic_cross_prim_moms_bgk_advance(crossPrimMomsCalc, &confLocal, delta_sr, betaGreenep1, - mi, prim_moms_i, me, prim_moms_e, prim_moms_cross_i); + gkyl_gyrokinetic_cross_prim_moms_bgk *crossPrimMomsCalc = + gkyl_gyrokinetic_cross_prim_moms_bgk_new(&basis, &confBasis, use_gpu); + struct gkyl_array *prim_moms_cross_e = + mkarr(3 * confBasis.num_basis, confLocal_ext.volume, use_gpu); + struct gkyl_array *prim_moms_cross_i = + mkarr(3 * confBasis.num_basis, confLocal_ext.volume, use_gpu); + gkyl_gyrokinetic_cross_prim_moms_bgk_advance( + crossPrimMomsCalc, &confLocal, delta_sr, betaGreenep1, me, prim_moms_e, mi, prim_moms_i, + prim_moms_cross_e + ); + gkyl_gyrokinetic_cross_prim_moms_bgk_advance( + crossPrimMomsCalc, &confLocal, delta_sr, betaGreenep1, mi, prim_moms_i, me, prim_moms_e, + prim_moms_cross_i + ); gkyl_gyrokinetic_cross_prim_moms_bgk_release(crossPrimMomsCalc); // Write out on host @@ -240,18 +259,34 @@ void test_1x1v(int poly_order, bool use_gpu) //gkyl_grid_sub_array_write(&confGrid, &confLocal, 0, prim_moms_cross, fname); // Compare with the expected cross moments - for (int k=0; k // Allocate array (filled with zeros). -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } - -void evalFunc1x_1(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc1x_1(double t, const double *xn, double *restrict fout, void *ctx) { fout[0] = 1.0; } -void evalFunc1x_quad(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc1x_quad(double t, const double *xn, double *restrict fout, void *ctx) { - fout[0] = -pow(xn[0]-0.5, 2) + 1.0; + fout[0] = -pow(xn[0] - 0.5, 2) + 1.0; } -void evalFunc2x_quad(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_quad(double t, const double *xn, double *restrict fout, void *ctx) { - fout[0] = (-pow(xn[0]-0.5, 2) + 1.0) * (-pow(xn[1]-0.5, 2) + 1.0); + fout[0] = (-pow(xn[0] - 0.5, 2) + 1.0) * (-pow(xn[1] - 0.5, 2) + 1.0); } -void evalFunc3x_quad(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc3x_quad(double t, const double *xn, double *restrict fout, void *ctx) { - fout[0] = (-pow(xn[0]-0.5, 2) + 1.0) * (-pow(xn[1]-0.5, 2) + 1.0) * (-pow(xn[2]-0.5, 2) + 1.0); + fout[0] = + (-pow(xn[0] - 0.5, 2) + 1.0) * (-pow(xn[1] - 0.5, 2) + 1.0) * (-pow(xn[2] - 0.5, 2) + 1.0); } -void test_1x_flat( bool use_gpu ) -{ +void test_1x_flat(bool use_gpu) +{ int cells[] = {8}; int poly_order = 1; double lower[] = {0.0}, upper[] = {1.0}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; @@ -62,38 +62,39 @@ void test_1x_flat( bool use_gpu ) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct gkyl_array *npol = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *npol_ho = use_gpu? mkarr(false, npol->ncomp, npol->size) - : gkyl_array_acquire(npol); + struct gkyl_array *npol_ho = use_gpu ? mkarr(false, npol->ncomp, npol->size) : + gkyl_array_acquire(npol); struct gkyl_array *epsilon = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *epsilon_ho = use_gpu? mkarr(false, epsilon->ncomp, epsilon->size) - : gkyl_array_acquire(epsilon); + struct gkyl_array *epsilon_ho = use_gpu ? mkarr(false, epsilon->ncomp, epsilon->size) : + gkyl_array_acquire(epsilon); - struct gkyl_eval_on_nodes *epsilon_proj = gkyl_eval_on_nodes_new(&grid, &basis, - 1, evalFunc1x_1, NULL); + struct gkyl_eval_on_nodes *epsilon_proj = + gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc1x_1, NULL); gkyl_eval_on_nodes_advance(epsilon_proj, 0.0, &localRange, epsilon_ho); gkyl_eval_on_nodes_release(epsilon_proj); gkyl_array_copy(epsilon, epsilon_ho); struct gkyl_basis phi_pol_basis; - gkyl_cart_modal_tensor(&phi_pol_basis, 1, poly_order+1); + gkyl_cart_modal_tensor(&phi_pol_basis, 1, poly_order + 1); struct gkyl_array *phi_pol = mkarr(use_gpu, phi_pol_basis.num_basis, localRange_ext.volume); - struct gkyl_array *phi_pol_ho = use_gpu? mkarr(false, phi_pol->ncomp, phi_pol->size) - : gkyl_array_acquire(phi_pol); + struct gkyl_array *phi_pol_ho = use_gpu ? mkarr(false, phi_pol->ncomp, phi_pol->size) : + gkyl_array_acquire(phi_pol); - struct gkyl_eval_on_nodes *phi_pol_proj = gkyl_eval_on_nodes_new(&grid, &phi_pol_basis, - 1, evalFunc1x_1, NULL); + struct gkyl_eval_on_nodes *phi_pol_proj = + gkyl_eval_on_nodes_new(&grid, &phi_pol_basis, 1, evalFunc1x_1, NULL); gkyl_eval_on_nodes_advance(phi_pol_proj, 0.0, &localRange, phi_pol_ho); gkyl_eval_on_nodes_release(phi_pol_proj); gkyl_array_copy(phi_pol, phi_pol_ho); - struct gkyl_gyrokinetic_pol_density* npol_op = gkyl_gyrokinetic_pol_density_new(basis, grid, use_gpu); + struct gkyl_gyrokinetic_pol_density *npol_op = + gkyl_gyrokinetic_pol_density_new(basis, grid, use_gpu); gkyl_gyrokinetic_pol_density_advance(npol_op, &localRange, epsilon, phi_pol, npol); gkyl_array_copy(npol_ho, npol); @@ -104,8 +105,8 @@ void test_1x_flat( bool use_gpu ) while (gkyl_range_iter_next(&conf_iter)) { long linidx = gkyl_range_idx(&localRange, conf_iter.idx); double *npol_d = gkyl_array_fetch(npol_ho, linidx); - TEST_CHECK( gkyl_compare(npol_d[0], sqrt(2), 1e-14) ); - TEST_CHECK( gkyl_compare(npol_d[1], 0.0, 1e-12) ); + TEST_CHECK(gkyl_compare(npol_d[0], sqrt(2), 1e-14)); + TEST_CHECK(gkyl_compare(npol_d[1], 0.0, 1e-12)); } gkyl_array_release(npol_ho); gkyl_array_release(npol); @@ -116,22 +117,22 @@ void test_1x_flat( bool use_gpu ) gkyl_gyrokinetic_pol_density_release(npol_op); } -void test_pol_density_1x_flat_ho() +void test_pol_density_1x_flat_ho() { test_1x_flat(false); } -void test_pol_density_1x_flat_dev() +void test_pol_density_1x_flat_dev() { test_1x_flat(true); } -void test_1x_quad( bool use_gpu ) -{ +void test_1x_quad(bool use_gpu) +{ int cells[] = {8}; int poly_order = 1; double lower[] = {0.0}, upper[] = {1.0}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); @@ -140,37 +141,38 @@ void test_1x_quad( bool use_gpu ) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct gkyl_array *npol = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *npol_ho = use_gpu? mkarr(false, npol->ncomp, npol->size) - : gkyl_array_acquire(npol); + struct gkyl_array *npol_ho = use_gpu ? mkarr(false, npol->ncomp, npol->size) : + gkyl_array_acquire(npol); struct gkyl_array *epsilon = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *epsilon_ho = use_gpu? mkarr(false, epsilon->ncomp, epsilon->size) - : gkyl_array_acquire(epsilon); + struct gkyl_array *epsilon_ho = use_gpu ? mkarr(false, epsilon->ncomp, epsilon->size) : + gkyl_array_acquire(epsilon); - struct gkyl_eval_on_nodes *epsilon_proj = gkyl_eval_on_nodes_new(&grid, &basis, - 1, evalFunc1x_1, NULL); + struct gkyl_eval_on_nodes *epsilon_proj = + gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc1x_1, NULL); gkyl_eval_on_nodes_advance(epsilon_proj, 0.0, &localRange, epsilon_ho); gkyl_eval_on_nodes_release(epsilon_proj); gkyl_array_copy(epsilon, epsilon_ho); struct gkyl_basis phi_pol_basis; - gkyl_cart_modal_tensor(&phi_pol_basis, 1, poly_order+1); + gkyl_cart_modal_tensor(&phi_pol_basis, 1, poly_order + 1); struct gkyl_array *phi_pol = mkarr(use_gpu, phi_pol_basis.num_basis, localRange_ext.volume); - struct gkyl_array *phi_pol_ho = use_gpu? mkarr(false, phi_pol->ncomp, phi_pol->size) - : gkyl_array_acquire(phi_pol); + struct gkyl_array *phi_pol_ho = use_gpu ? mkarr(false, phi_pol->ncomp, phi_pol->size) : + gkyl_array_acquire(phi_pol); - struct gkyl_eval_on_nodes *phi_pol_proj = gkyl_eval_on_nodes_new(&grid, &phi_pol_basis, - 1, evalFunc1x_quad, NULL); + struct gkyl_eval_on_nodes *phi_pol_proj = + gkyl_eval_on_nodes_new(&grid, &phi_pol_basis, 1, evalFunc1x_quad, NULL); gkyl_eval_on_nodes_advance(phi_pol_proj, 0.0, &localRange, phi_pol_ho); gkyl_eval_on_nodes_release(phi_pol_proj); gkyl_array_copy(phi_pol, phi_pol_ho); - struct gkyl_gyrokinetic_pol_density* npol_op = gkyl_gyrokinetic_pol_density_new(basis, grid, use_gpu); + struct gkyl_gyrokinetic_pol_density *npol_op = + gkyl_gyrokinetic_pol_density_new(basis, grid, use_gpu); gkyl_gyrokinetic_pol_density_advance(npol_op, &localRange, epsilon, phi_pol, npol); gkyl_array_copy(npol_ho, npol); @@ -183,44 +185,44 @@ void test_1x_quad( bool use_gpu ) double *npol_d = gkyl_array_fetch(npol_ho, linidx); double tol = 1e-5; if (conf_iter.idx[0] == 1) { - TEST_CHECK( gkyl_compare(npol_d[0], 1.141683, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 1.141683, tol)); TEST_MSG("npol_d[0] = %g", npol_d[0]); - TEST_CHECK( gkyl_compare(npol_d[1], 0.044652, tol) ); + TEST_CHECK(gkyl_compare(npol_d[1], 0.044652, tol)); TEST_MSG("npol_d[1] = %g", npol_d[1]); } else if (conf_iter.idx[0] == 2) { - TEST_CHECK( gkyl_compare(npol_d[0], 1.274265, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 1.274265, tol)); TEST_MSG("npol_d[0] = %g", npol_d[0]); - TEST_CHECK( gkyl_compare(npol_d[1], 0.031894, tol) ); + TEST_CHECK(gkyl_compare(npol_d[1], 0.031894, tol)); TEST_MSG("npol_d[1] = %g", npol_d[1]); } else if (conf_iter.idx[0] == 3) { - TEST_CHECK( gkyl_compare(npol_d[0], 1.362654, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 1.362654, tol)); TEST_MSG("npol_d[0] = %g", npol_d[0]); - TEST_CHECK( gkyl_compare(npol_d[1], 0.019137, tol) ); + TEST_CHECK(gkyl_compare(npol_d[1], 0.019137, tol)); TEST_MSG("npol_d[1] = %g", npol_d[1]); } else if (conf_iter.idx[0] == 4) { - TEST_CHECK( gkyl_compare(npol_d[0], 1.406848, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 1.406848, tol)); TEST_MSG("npol_d[0] = %g", npol_d[0]); - TEST_CHECK( gkyl_compare(npol_d[1], 0.006379, tol) ); + TEST_CHECK(gkyl_compare(npol_d[1], 0.006379, tol)); TEST_MSG("npol_d[1] = %g", npol_d[1]); } else if (conf_iter.idx[0] == 5) { - TEST_CHECK( gkyl_compare(npol_d[0], 1.406848, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 1.406848, tol)); TEST_MSG("npol_d[0] = %g", npol_d[0]); - TEST_CHECK( gkyl_compare(npol_d[1], -0.006379, tol) ); + TEST_CHECK(gkyl_compare(npol_d[1], -0.006379, tol)); TEST_MSG("npol_d[1] = %g", npol_d[1]); } else if (conf_iter.idx[0] == 6) { - TEST_CHECK( gkyl_compare(npol_d[0], 1.362654, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 1.362654, tol)); TEST_MSG("npol_d[0] = %g", npol_d[0]); - TEST_CHECK( gkyl_compare(npol_d[1], -0.019137, tol) ); + TEST_CHECK(gkyl_compare(npol_d[1], -0.019137, tol)); TEST_MSG("npol_d[1] = %g", npol_d[1]); } else if (conf_iter.idx[0] == 7) { - TEST_CHECK( gkyl_compare(npol_d[0], 1.274265, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 1.274265, tol)); TEST_MSG("npol_d[0] = %g", npol_d[0]); - TEST_CHECK( gkyl_compare(npol_d[1], -0.031894, tol) ); + TEST_CHECK(gkyl_compare(npol_d[1], -0.031894, tol)); TEST_MSG("npol_d[1] = %g", npol_d[1]); } else if (conf_iter.idx[0] == 8) { - TEST_CHECK( gkyl_compare(npol_d[0], 1.141683, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 1.141683, tol)); TEST_MSG("npol_d[0] = %g", npol_d[0]); - TEST_CHECK( gkyl_compare(npol_d[1], -0.044652, tol) ); + TEST_CHECK(gkyl_compare(npol_d[1], -0.044652, tol)); TEST_MSG("npol_d[1] = %g", npol_d[1]); } } @@ -234,24 +236,23 @@ void test_1x_quad( bool use_gpu ) gkyl_gyrokinetic_pol_density_release(npol_op); } -void test_pol_density_1x_quad_ho() +void test_pol_density_1x_quad_ho() { test_1x_quad(false); } -void test_pol_density_1x_quad_dev() +void test_pol_density_1x_quad_dev() { test_1x_quad(true); } -void -test_2x_quad( bool use_gpu ) +void test_2x_quad(bool use_gpu) { int cells[] = {7, 7}; int poly_order = 1; double lower[] = {0.0, 0.0}, upper[] = {1.0, 1.0}; double time = 0.0; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); @@ -260,37 +261,38 @@ test_2x_quad( bool use_gpu ) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct gkyl_array *npol = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *npol_ho = use_gpu? mkarr(false, npol->ncomp, npol->size) - : gkyl_array_acquire(npol); + struct gkyl_array *npol_ho = use_gpu ? mkarr(false, npol->ncomp, npol->size) : + gkyl_array_acquire(npol); struct gkyl_array *epsilon = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *epsilon_ho = use_gpu? mkarr(false, epsilon->ncomp, epsilon->size) - : gkyl_array_acquire(epsilon); + struct gkyl_array *epsilon_ho = use_gpu ? mkarr(false, epsilon->ncomp, epsilon->size) : + gkyl_array_acquire(epsilon); - struct gkyl_eval_on_nodes *epsilon_proj = gkyl_eval_on_nodes_new(&grid, &basis, - 1, evalFunc1x_1, NULL); + struct gkyl_eval_on_nodes *epsilon_proj = + gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc1x_1, NULL); gkyl_eval_on_nodes_advance(epsilon_proj, time, &localRange, epsilon_ho); gkyl_eval_on_nodes_release(epsilon_proj); gkyl_array_copy(epsilon, epsilon_ho); struct gkyl_basis phi_pol_basis; - gkyl_cart_modal_tensor(&phi_pol_basis, dim, poly_order+1); + gkyl_cart_modal_tensor(&phi_pol_basis, dim, poly_order + 1); struct gkyl_array *phi_pol = mkarr(use_gpu, phi_pol_basis.num_basis, localRange_ext.volume); - struct gkyl_array *phi_pol_ho = use_gpu? mkarr(false, phi_pol->ncomp, phi_pol->size) - : gkyl_array_acquire(phi_pol); + struct gkyl_array *phi_pol_ho = use_gpu ? mkarr(false, phi_pol->ncomp, phi_pol->size) : + gkyl_array_acquire(phi_pol); - struct gkyl_eval_on_nodes *phi_pol_proj = gkyl_eval_on_nodes_new(&grid, &phi_pol_basis, - 1, evalFunc2x_quad, NULL); + struct gkyl_eval_on_nodes *phi_pol_proj = + gkyl_eval_on_nodes_new(&grid, &phi_pol_basis, 1, evalFunc2x_quad, NULL); gkyl_eval_on_nodes_advance(phi_pol_proj, time, &localRange, phi_pol_ho); gkyl_eval_on_nodes_release(phi_pol_proj); gkyl_array_copy(phi_pol, phi_pol_ho); - struct gkyl_gyrokinetic_pol_density* npol_op = gkyl_gyrokinetic_pol_density_new(basis, grid, use_gpu); + struct gkyl_gyrokinetic_pol_density *npol_op = + gkyl_gyrokinetic_pol_density_new(basis, grid, use_gpu); gkyl_gyrokinetic_pol_density_advance(npol_op, &localRange, epsilon, phi_pol, npol); gkyl_array_copy(npol_ho, npol); @@ -303,40 +305,40 @@ test_2x_quad( bool use_gpu ) double *npol_d = gkyl_array_fetch(npol_ho, linidx); double tol = 1e-12; if (conf_iter.idx[1] == 1) { - TEST_CHECK( gkyl_compare(npol_d[0], 3.2585034013604615, tol) ); - TEST_CHECK( gkyl_compare(npol_d[1], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[2], 0.1413919026586975, tol) ); - TEST_CHECK( gkyl_compare(npol_d[3], 0.0, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 3.2585034013604615, tol)); + TEST_CHECK(gkyl_compare(npol_d[1], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[2], 0.1413919026586975, tol)); + TEST_CHECK(gkyl_compare(npol_d[3], 0.0, tol)); } else if (conf_iter.idx[1] == 2) { - TEST_CHECK( gkyl_compare(npol_d[0], 3.6666666666666150, tol) ); - TEST_CHECK( gkyl_compare(npol_d[1], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[2], 0.0942612684391317, tol) ); - TEST_CHECK( gkyl_compare(npol_d[3], 0.0, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 3.6666666666666150, tol)); + TEST_CHECK(gkyl_compare(npol_d[1], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[2], 0.0942612684391317, tol)); + TEST_CHECK(gkyl_compare(npol_d[3], 0.0, tol)); } else if (conf_iter.idx[1] == 3) { - TEST_CHECK( gkyl_compare(npol_d[0], 3.9115646258503931, tol) ); - TEST_CHECK( gkyl_compare(npol_d[1], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[2], 0.0471306342195649, tol) ); - TEST_CHECK( gkyl_compare(npol_d[3], 0.0, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 3.9115646258503931, tol)); + TEST_CHECK(gkyl_compare(npol_d[1], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[2], 0.0471306342195649, tol)); + TEST_CHECK(gkyl_compare(npol_d[3], 0.0, tol)); } else if (conf_iter.idx[1] == 4) { - TEST_CHECK( gkyl_compare(npol_d[0], 3.9931972789115648, tol) ); - TEST_CHECK( gkyl_compare(npol_d[1], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[2], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[3], 0.0, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 3.9931972789115648, tol)); + TEST_CHECK(gkyl_compare(npol_d[1], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[2], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[3], 0.0, tol)); } else if (conf_iter.idx[1] == 5) { - TEST_CHECK( gkyl_compare(npol_d[0], 3.9115646258503931, tol) ); - TEST_CHECK( gkyl_compare(npol_d[1], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[2], -0.0471306342195649, tol) ); - TEST_CHECK( gkyl_compare(npol_d[3], 0.0, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 3.9115646258503931, tol)); + TEST_CHECK(gkyl_compare(npol_d[1], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[2], -0.0471306342195649, tol)); + TEST_CHECK(gkyl_compare(npol_d[3], 0.0, tol)); } else if (conf_iter.idx[1] == 6) { - TEST_CHECK( gkyl_compare(npol_d[0], 3.6666666666666150, tol) ); - TEST_CHECK( gkyl_compare(npol_d[1], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[2], -0.0942612684391317, tol) ); - TEST_CHECK( gkyl_compare(npol_d[3], 0.0, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 3.6666666666666150, tol)); + TEST_CHECK(gkyl_compare(npol_d[1], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[2], -0.0942612684391317, tol)); + TEST_CHECK(gkyl_compare(npol_d[3], 0.0, tol)); } else if (conf_iter.idx[1] == 7) { - TEST_CHECK( gkyl_compare(npol_d[0], 3.2585034013604615, tol) ); - TEST_CHECK( gkyl_compare(npol_d[1], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[2], -0.1413919026586975, tol) ); - TEST_CHECK( gkyl_compare(npol_d[3], 0.0, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 3.2585034013604615, tol)); + TEST_CHECK(gkyl_compare(npol_d[1], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[2], -0.1413919026586975, tol)); + TEST_CHECK(gkyl_compare(npol_d[3], 0.0, tol)); } } @@ -349,24 +351,23 @@ test_2x_quad( bool use_gpu ) gkyl_gyrokinetic_pol_density_release(npol_op); } -void test_pol_density_2x_quad_ho() +void test_pol_density_2x_quad_ho() { test_2x_quad(false); } -void test_pol_density_2x_quad_dev() +void test_pol_density_2x_quad_dev() { test_2x_quad(true); } -void -test_3x_flat( bool use_gpu ) +void test_3x_flat(bool use_gpu) { int cells[] = {7, 7, 7}; int poly_order = 1; double lower[] = {0.0, 0.0, 0.0}, upper[] = {1.0, 1.0, 1.0}; double time = 0.0; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); @@ -375,37 +376,38 @@ test_3x_flat( bool use_gpu ) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct gkyl_array *npol = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *npol_ho = use_gpu? mkarr(false, npol->ncomp, npol->size) - : gkyl_array_acquire(npol); + struct gkyl_array *npol_ho = use_gpu ? mkarr(false, npol->ncomp, npol->size) : + gkyl_array_acquire(npol); struct gkyl_array *epsilon = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); - struct gkyl_array *epsilon_ho = use_gpu? mkarr(false, epsilon->ncomp, epsilon->size) - : gkyl_array_acquire(epsilon); + struct gkyl_array *epsilon_ho = use_gpu ? mkarr(false, epsilon->ncomp, epsilon->size) : + gkyl_array_acquire(epsilon); - struct gkyl_eval_on_nodes *epsilon_proj = gkyl_eval_on_nodes_new(&grid, &basis, - 1, evalFunc1x_1, NULL); + struct gkyl_eval_on_nodes *epsilon_proj = + gkyl_eval_on_nodes_new(&grid, &basis, 1, evalFunc1x_1, NULL); gkyl_eval_on_nodes_advance(epsilon_proj, time, &localRange, epsilon_ho); gkyl_eval_on_nodes_release(epsilon_proj); gkyl_array_copy(epsilon, epsilon_ho); struct gkyl_basis phi_pol_basis; - gkyl_cart_modal_tensor(&phi_pol_basis, dim, poly_order+1); + gkyl_cart_modal_tensor(&phi_pol_basis, dim, poly_order + 1); struct gkyl_array *phi_pol = mkarr(use_gpu, phi_pol_basis.num_basis, localRange_ext.volume); - struct gkyl_array *phi_pol_ho = use_gpu? mkarr(false, phi_pol->ncomp, phi_pol->size) - : gkyl_array_acquire(phi_pol); + struct gkyl_array *phi_pol_ho = use_gpu ? mkarr(false, phi_pol->ncomp, phi_pol->size) : + gkyl_array_acquire(phi_pol); - struct gkyl_eval_on_nodes *phi_pol_proj = gkyl_eval_on_nodes_new(&grid, &phi_pol_basis, - 1, evalFunc1x_quad, NULL); + struct gkyl_eval_on_nodes *phi_pol_proj = + gkyl_eval_on_nodes_new(&grid, &phi_pol_basis, 1, evalFunc1x_quad, NULL); gkyl_eval_on_nodes_advance(phi_pol_proj, time, &localRange, phi_pol_ho); gkyl_eval_on_nodes_release(phi_pol_proj); gkyl_array_copy(phi_pol, phi_pol_ho); - struct gkyl_gyrokinetic_pol_density* npol_op = gkyl_gyrokinetic_pol_density_new(basis, grid, use_gpu); + struct gkyl_gyrokinetic_pol_density *npol_op = + gkyl_gyrokinetic_pol_density_new(basis, grid, use_gpu); gkyl_gyrokinetic_pol_density_advance(npol_op, &localRange, epsilon, phi_pol, npol); gkyl_array_copy(npol_ho, npol); @@ -417,14 +419,14 @@ test_3x_flat( bool use_gpu ) long linidx = gkyl_range_idx(&localRange, conf_iter.idx); double *npol_d = gkyl_array_fetch(npol_ho, linidx); double tol = 1e-12; - TEST_CHECK( gkyl_compare(npol_d[0], 5.6568542494927714, tol) ); - TEST_CHECK( gkyl_compare(npol_d[1], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[2], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[3], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[4], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[5], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[6], 0.0, tol) ); - TEST_CHECK( gkyl_compare(npol_d[7], 0.0, tol) ); + TEST_CHECK(gkyl_compare(npol_d[0], 5.6568542494927714, tol)); + TEST_CHECK(gkyl_compare(npol_d[1], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[2], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[3], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[4], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[5], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[6], 0.0, tol)); + TEST_CHECK(gkyl_compare(npol_d[7], 0.0, tol)); } gkyl_array_release(npol_ho); @@ -436,28 +438,26 @@ test_3x_flat( bool use_gpu ) gkyl_gyrokinetic_pol_density_release(npol_op); } -void -test_pol_density_3x_flat_ho() +void test_pol_density_3x_flat_ho() { test_3x_flat(false); } -void -test_pol_density_3x_flat_dev() +void test_pol_density_3x_flat_dev() { test_3x_flat(true); } TEST_LIST = { - { "test_pol_density_1x_flat_ho", test_pol_density_1x_flat_ho }, - { "test_pol_density_1x_quad_ho", test_pol_density_1x_quad_ho }, - { "test_pol_density_2x_quad_ho", test_pol_density_2x_quad_ho }, - { "test_pol_density_3x_flat_ho", test_pol_density_3x_flat_ho }, + {"test_pol_density_1x_flat_ho", test_pol_density_1x_flat_ho}, + {"test_pol_density_1x_quad_ho", test_pol_density_1x_quad_ho}, + {"test_pol_density_2x_quad_ho", test_pol_density_2x_quad_ho}, + {"test_pol_density_3x_flat_ho", test_pol_density_3x_flat_ho}, #ifdef GKYL_HAVE_CUDA - { "test_pol_density_1x_flat_dev", test_pol_density_1x_flat_dev }, - { "test_pol_density_1x_quad_dev", test_pol_density_1x_quad_dev }, - { "test_pol_density_2x_quad_dev", test_pol_density_2x_quad_dev }, - { "test_pol_density_3x_flat_dev", test_pol_density_3x_flat_dev }, + {"test_pol_density_1x_flat_dev", test_pol_density_1x_flat_dev}, + {"test_pol_density_1x_quad_dev", test_pol_density_1x_quad_dev}, + {"test_pol_density_2x_quad_dev", test_pol_density_2x_quad_dev}, + {"test_pol_density_3x_flat_dev", test_pol_density_3x_flat_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_integrated_moms.c b/gyrokinetic/unit/ctest_integrated_moms.c index a8547c8d97..eb3a9ad98d 100644 --- a/gyrokinetic/unit/ctest_integrated_moms.c +++ b/gyrokinetic/unit/ctest_integrated_moms.c @@ -23,86 +23,81 @@ #include #include - -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } -void -mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; xp[2] = xc[2]; + xp[0] = xc[0]; + xp[1] = xc[1]; + xp[2] = xc[2]; } -void -bfield_func(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; fout[1] = 0.0; fout[2] = 1.0; } -void -eval_density(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_density(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 3.0e19; } -void -eval_upar(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_upar(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void -eval_vthsq(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_vthsq(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // D ion mass - fout[0] =150*eV/mi; + double mi = 2.014 * GKYL_PROTON_MASS; // D ion mass + fout[0] = 150 * eV / mi; } -void -test_2x_option(bool use_gpu) +void test_2x_option(bool use_gpu) { - int poly_order=1; + int poly_order = 1; double eps0 = GKYL_EPSILON0; double eV = GKYL_ELEMENTARY_CHARGE; - double mi = 2.014*GKYL_PROTON_MASS; // D ion mass + double mi = 2.014 * GKYL_PROTON_MASS; // D ion mass double qi = eV; // ion charge - double Ti = 150*eV; + double Ti = 150 * eV; double B0 = 1.0; // Magnetic field magnitude in Tesla double n0 = 3.0e19; // Particle density in 1/m^3 - double vtIon = sqrt(Ti/mi); - double vpar_max_ion = 6.0*vtIon; - double mu_max_ion = 12.*mi*vtIon*vtIon/(2.0*B0); + double vtIon = sqrt(Ti / mi); + double vpar_max_ion = 6.0 * vtIon; + double mu_max_ion = 12. * mi * vtIon * vtIon / (2.0 * B0); // Phase space and Configuration space extents and resolution double lower[] = {0.0, 0.0, -vpar_max_ion, 0.0}; double upper[] = {1.0, 1.0, vpar_max_ion, mu_max_ion}; int cells[] = {10, 16, 16, 20}; int vdim = 2; - int ndim = sizeof(cells)/sizeof(cells[0]); + int ndim = sizeof(cells) / sizeof(cells[0]); int cdim = ndim - vdim; double confLower[cdim], confUpper[cdim], vLower[vdim], vUpper[vdim]; int confCells[cdim], vCells[vdim]; - for (int i = 0; i < cdim; i++){ - confLower[i] = lower[i]; + for (int i = 0; i < cdim; i++) { + confLower[i] = lower[i]; confUpper[i] = upper[i]; confCells[i] = cells[i]; } - for (int i = 0; i < vdim; i++){ - vLower[i] = lower[cdim+i]; - vUpper[i] = upper[cdim+i]; - vCells[i] = cells[cdim+i]; + for (int i = 0; i < vdim; i++) { + vLower[i] = lower[cdim + i]; + vUpper[i] = upper[cdim + i]; + vCells[i] = cells[cdim + i]; } // grids @@ -117,7 +112,7 @@ test_2x_option(bool use_gpu) struct gkyl_basis basis, confBasis, surf_vpar_basis, surf_mu_basis; if (poly_order > 1) { gkyl_cart_modal_serendip(&basis, ndim, poly_order); - gkyl_cart_modal_serendip(&surf_mu_basis, ndim-1, poly_order); + gkyl_cart_modal_serendip(&surf_mu_basis, ndim - 1, poly_order); } else if (poly_order == 1) { /* Force hybrid basis (p=2 in vpar). */ gkyl_cart_modal_gkhybrid(&basis, cdim, vdim); @@ -127,11 +122,11 @@ test_2x_option(bool use_gpu) gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); // Ranges - int confGhost[] = { 1, 1 }; + int confGhost[] = {1, 1}; struct gkyl_range confLocal, confLocal_ext; // local, local-ext conf-space ranges gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); - int ghost[] = { confGhost[0], confGhost[1], 0 , 0}; + int ghost[] = {confGhost[0], confGhost[1], 0, 0}; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); @@ -148,31 +143,33 @@ test_2x_option(bool use_gpu) .mapc2p = mapc2p, // mapping of computational to physical space .c2p_ctx = 0, .bfield_func = bfield_func, // magnetic field magnitude - .bfield_ctx = 0 , + .bfield_ctx = 0, .position_map = pmap, .grid = confGrid, .local = confLocal, .local_ext = confLocal_ext, .global = confLocal, .global_ext = confLocal_ext, - .basis = confBasis, + .basis = confBasis }; int geo_ghost[3] = {1}; geometry_input.geo_grid = gkyl_gk_geometry_augment_grid(confGrid, geometry_input); gkyl_cart_modal_serendip(&geometry_input.geo_basis, 3, poly_order); - gkyl_create_grid_ranges(&geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global); + gkyl_create_grid_ranges( + &geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global + ); memcpy(&geometry_input.geo_local, &geometry_input.geo_global, sizeof(struct gkyl_range)); memcpy(&geometry_input.geo_local_ext, &geometry_input.geo_global_ext, sizeof(struct gkyl_range)); - struct gk_geometry* gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); + struct gk_geometry *gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); // deflate geometry struct gk_geometry *gk_geom = gkyl_gk_geometry_deflate(gk_geom_3d, &geometry_input); gkyl_gk_geometry_release(gk_geom_3d); // If we are on the gpu, copy from host if (use_gpu) { - struct gk_geometry* gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); + struct gk_geometry *gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); gkyl_gk_geometry_release(gk_geom); gk_geom = gkyl_gk_geometry_acquire(gk_geom_dev); gkyl_gk_geometry_release(gk_geom_dev); @@ -180,28 +177,28 @@ test_2x_option(bool use_gpu) // Project n, udrift, and vt^2 based on input functions struct gkyl_array *m0 = mkarr(false, confBasis.num_basis, confLocal_ext.volume); - struct gkyl_array *udrift = mkarr(false, vdim*confBasis.num_basis, confLocal_ext.volume); + struct gkyl_array *udrift = mkarr(false, vdim * confBasis.num_basis, confLocal_ext.volume); struct gkyl_array *vtsq = mkarr(false, confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, 1, eval_density, NULL); - gkyl_proj_on_basis *proj_udrift = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, vdim, eval_upar, 0); - gkyl_proj_on_basis *proj_vtsq = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, 1, eval_vthsq, 0); - gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_density, NULL); + gkyl_proj_on_basis *proj_udrift = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_upar, 0); + gkyl_proj_on_basis *proj_vtsq = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_vthsq, 0); + gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); gkyl_proj_on_basis_advance(proj_udrift, 0.0, &confLocal, udrift); gkyl_proj_on_basis_advance(proj_vtsq, 0.0, &confLocal, vtsq); - + // Projection routine expects the primitive moments as a single array. - struct gkyl_array *prim_moms = mkarr(false, 3*confBasis.num_basis, confLocal_ext.volume); - gkyl_array_set_offset(prim_moms, 1.0, m0, 0*confBasis.num_basis); - gkyl_array_set_offset(prim_moms, 1.0, udrift, 1*confBasis.num_basis); - gkyl_array_set_offset(prim_moms, 1.0, vtsq, 2*confBasis.num_basis); + struct gkyl_array *prim_moms = mkarr(false, 3 * confBasis.num_basis, confLocal_ext.volume); + gkyl_array_set_offset(prim_moms, 1.0, m0, 0 * confBasis.num_basis); + gkyl_array_set_offset(prim_moms, 1.0, udrift, 1 * confBasis.num_basis); + gkyl_array_set_offset(prim_moms, 1.0, vtsq, 2 * confBasis.num_basis); // Velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, grid, vGrid, - local, local_ext, vLocal, vLocal_ext, use_gpu); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, vGrid, local, local_ext, vLocal, vLocal_ext, use_gpu); // Create distribution function array struct gkyl_array *f = mkarr(use_gpu, basis.num_basis, local_ext.volume); @@ -211,72 +208,75 @@ test_2x_option(bool use_gpu) .phase_grid = &grid, .conf_basis = &confBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, - .vel_range = &vLocal, + .vel_range = &vLocal, .gk_geom = gk_geom, .vel_map = gvm, .mass = mi, - .bimaxwellian = false, - .use_gpu = use_gpu, + .bimaxwellian = false, + .use_gpu = use_gpu }; - struct gkyl_gk_maxwellian_proj_on_basis *proj_max = gkyl_gk_maxwellian_proj_on_basis_inew( &inp_proj ); + struct gkyl_gk_maxwellian_proj_on_basis *proj_max = + gkyl_gk_maxwellian_proj_on_basis_inew(&inp_proj); // If on GPUs, need to copy primitive moments onto device struct gkyl_array *prim_moms_dev, *m0_dev; if (use_gpu) { - prim_moms_dev = mkarr(use_gpu, 3*confBasis.num_basis, confLocal_ext.volume); + prim_moms_dev = mkarr(use_gpu, 3 * confBasis.num_basis, confLocal_ext.volume); m0_dev = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); - + gkyl_array_copy(prim_moms_dev, prim_moms); gkyl_array_copy(m0_dev, m0); - gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, - &local, &confLocal, prim_moms_dev, false, f); - } - else { - gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, - &local, &confLocal, prim_moms, false, f); + gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, &local, &confLocal, prim_moms_dev, false, f); + } else { + gkyl_gk_maxwellian_proj_on_basis_advance(proj_max, &local, &confLocal, prim_moms, false, f); } // Initialize integrated moment calculator - struct gkyl_dg_updater_moment *mcalc = gkyl_dg_updater_moment_gyrokinetic_new(&grid, &confBasis, &basis, - &confLocal, mi, qi, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0M1M2PARM2PERP, true, use_gpu); + struct gkyl_dg_updater_moment *mcalc = gkyl_dg_updater_moment_gyrokinetic_new( + &grid, &confBasis, &basis, &confLocal, mi, qi, gvm, gk_geom, NULL, + GKYL_F_MOMENT_M0M1M2PARM2PERP, true, use_gpu + ); int num_mom = gkyl_dg_updater_moment_gyrokinetic_num_mom(mcalc); struct gkyl_array *marr = mkarr(use_gpu, num_mom, confLocal_ext.volume); - struct gkyl_array *marr_host = use_gpu? marr_host = mkarr(false, marr->ncomp, marr->size) - : gkyl_array_acquire(marr); - + struct gkyl_array *marr_host = use_gpu ? marr_host = mkarr(false, marr->ncomp, marr->size) : + gkyl_array_acquire(marr); double *red_integ_diag_global; - if (use_gpu) - red_integ_diag_global = gkyl_cu_malloc(4*sizeof(double)); - else - red_integ_diag_global = gkyl_malloc(4*sizeof(double)); + if (use_gpu) { + red_integ_diag_global = gkyl_cu_malloc(4 * sizeof(double)); + } else { + red_integ_diag_global = gkyl_malloc(4 * sizeof(double)); + } // Now calculate the integrated moments - double avals_global[2+vdim]; + double avals_global[2 + vdim]; gkyl_dg_updater_moment_gyrokinetic_advance(mcalc, &local, &confLocal, f, marr); gkyl_array_reduce_range(red_integ_diag_global, marr, GKYL_SUM, &confLocal); - if (use_gpu) - gkyl_cu_memcpy(avals_global, red_integ_diag_global, sizeof(double[2+vdim]), GKYL_CU_MEMCPY_D2H); - else - memcpy(avals_global, red_integ_diag_global, sizeof(double[2+vdim])); + if (use_gpu) { + gkyl_cu_memcpy( + avals_global, red_integ_diag_global, sizeof(double[2 + vdim]), GKYL_CU_MEMCPY_D2H + ); + } else { + memcpy(avals_global, red_integ_diag_global, sizeof(double[2 + vdim])); + } // Check the integrated moments are correct. Values computed by Akash Shukla on 2/26/24 // Check of intM1 really just checks the drift velocity is close to zero, this will not be perfect. - TEST_CHECK( gkyl_compare( avals_global[0]/3e19, 1.0, 1e-2)); - TEST_CHECK( gkyl_compare( avals_global[1]/3e19, 0.0, 1e-2)); - TEST_CHECK( gkyl_compare( avals_global[2]/2.14e+29, 1.0, 1e-2)); - TEST_MSG( "Got: %.9e | Expected: %.9e\n",avals_global[2]/2.14e+29, 1.0); - TEST_CHECK( gkyl_compare( avals_global[3]/4.21e+29, 1.0, 1e-2)); - TEST_MSG( "Got: %.9e | Expected: %.9e\n",avals_global[3]/4.21e+29, 1.0); + TEST_CHECK(gkyl_compare(avals_global[0] / 3e19, 1.0, 1e-2)); + TEST_CHECK(gkyl_compare(avals_global[1] / 3e19, 0.0, 1e-2)); + TEST_CHECK(gkyl_compare(avals_global[2] / 2.14e+29, 1.0, 1e-2)); + TEST_MSG("Got: %.9e | Expected: %.9e\n", avals_global[2] / 2.14e+29, 1.0); + TEST_CHECK(gkyl_compare(avals_global[3] / 4.21e+29, 1.0, 1e-2)); + TEST_MSG("Got: %.9e | Expected: %.9e\n", avals_global[3] / 4.21e+29, 1.0); gkyl_array_release(m0); - gkyl_array_release(udrift); + gkyl_array_release(udrift); gkyl_array_release(vtsq); gkyl_array_release(prim_moms); @@ -295,8 +295,7 @@ test_2x_option(bool use_gpu) gkyl_array_release(m0_dev); gkyl_array_release(prim_moms_dev); gkyl_cu_free(red_integ_diag_global); - } - else { + } else { gkyl_free(red_integ_diag_global); } @@ -305,17 +304,23 @@ test_2x_option(bool use_gpu) gkyl_position_map_release(pmap); } -void test_integrated_moms_2x_ho() { test_2x_option(false); } +void test_integrated_moms_2x_ho() +{ + test_2x_option(false); +} #ifdef GKYL_HAVE_CUDA -void test_integrated_moms_2x_dev() { test_2x_option(true); } +void test_integrated_moms_2x_dev() +{ + test_2x_option(true); +} #endif TEST_LIST = { - { "test_integrated_moms_2x_ho", test_integrated_moms_2x_ho }, + {"test_integrated_moms_2x_ho", test_integrated_moms_2x_ho}, #ifdef GKYL_HAVE_CUDA - { "test_integrated_moms_2x_dev", test_integrated_moms_2x_dev }, + {"test_integrated_moms_2x_dev", test_integrated_moms_2x_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_loss_cone_mask_gyrokinetic.c b/gyrokinetic/unit/ctest_loss_cone_mask_gyrokinetic.c index 7a36288bf2..1674906a21 100644 --- a/gyrokinetic/unit/ctest_loss_cone_mask_gyrokinetic.c +++ b/gyrokinetic/unit/ctest_loss_cone_mask_gyrokinetic.c @@ -33,22 +33,21 @@ struct loss_cone_mask_test_ctx { }; // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { - struct gkyl_array* a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -void -mapc2p_3x(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p_3x(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; xp[2] = xc[2]; + xp[0] = xc[0]; + xp[1] = xc[1]; + xp[2] = xc[2]; } -void -bfield_func_3x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func_3x(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; @@ -58,12 +57,11 @@ bfield_func_3x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx fout[0] = 0.0; fout[1] = 0.0; - fout[2] = B_m * (1.0 - ((R_m-1.0)/R_m)*pow(cos(z), 2.0)); -// fout[0] = (B_m/R_m) * (1.0 + (R_m-1.0)*pow(sin(z), 2.0)); + fout[2] = B_m * (1.0 - ((R_m - 1.0) / R_m) * pow(cos(z), 2.0)); + // fout[0] = (B_m/R_m) * (1.0 + (R_m-1.0)*pow(sin(z), 2.0)); } -void -phi_func_1x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void phi_func_1x(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double z = xc[0]; @@ -75,8 +73,7 @@ phi_func_1x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) fout[0] = 0.0; //0.5 * phi_fac*T0/eV * (1.0 + cos(z)); } -void -mask_ref_1x2v(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void mask_ref_1x2v(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double z = xc[0], vpar = xc[1], mu = xc[2]; struct loss_cone_mask_test_ctx *params = ctx; @@ -100,17 +97,17 @@ mask_ref_1x2v(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) bmag_m = bfield_m[2]; // mu_bound = (0.5*m*vpar^2+q*(phi-phi_m))/(B*(B_max/B-1)) - double mu_bound = (0.5*mass*pow(vpar,2)+charge*(phi-phi_m))/(bmag*(bmag_m/bmag-1)); - if (mu_bound < mu && fabs(z) < z_m) + double mu_bound = + (0.5 * mass * pow(vpar, 2) + charge * (phi - phi_m)) / (bmag * (bmag_m / bmag - 1)); + if (mu_bound < mu && fabs(z) < z_m) { fout[0] = 1.0; - else + } else { fout[0] = 0; + } } -void -test_1x2v_gk(int poly_order, bool use_gpu) +void test_1x2v_gk(int poly_order, bool use_gpu) { - double eV = GKYL_ELEMENTARY_CHARGE; double mass_proton = GKYL_PROTON_MASS; @@ -120,11 +117,11 @@ test_1x2v_gk(int poly_order, bool use_gpu) .eV = eV, .R_m = 8.0, .B_m = 4.0, - .z_m = M_PI/2.0, - .mass = 2.014*mass_proton, + .z_m = M_PI / 2.0, + .mass = 2.014 * mass_proton, .charge = eV, .n0 = 1e18, - .T0 = 100*eV, + .T0 = 100 * eV, .phi_fac = 3.0, .z_max = M_PI, .Nz = 8, @@ -132,33 +129,34 @@ test_1x2v_gk(int poly_order, bool use_gpu) .Nmu = 4, .quad_type = GKYL_GAUSS_LOBATTO_QUAD, .num_quad = 2, - .cellwise_trap_loss = true, + .cellwise_trap_loss = true }; - ctx.B0 = ctx.B_m/2.0; - ctx.vpar_max = 6.0*sqrt(ctx.T0/ctx.mass); - ctx.mu_max = 0.5*ctx.mass*pow(ctx.vpar_max,2)/ctx.B0; + ctx.B0 = ctx.B_m / 2.0; + ctx.vpar_max = 6.0 * sqrt(ctx.T0 / ctx.mass); + ctx.mu_max = 0.5 * ctx.mass * pow(ctx.vpar_max, 2) / ctx.B0; double mass = ctx.mass; - double lower[] = {-ctx.z_max, -ctx.vpar_max, 0.0}, upper[] = {ctx.z_max, ctx.vpar_max, ctx.mu_max}; + double lower[] = {-ctx.z_max, -ctx.vpar_max, 0.0}, + upper[] = {ctx.z_max, ctx.vpar_max, ctx.mu_max}; int cells[] = {ctx.Nz, ctx.Nvpar, ctx.Nmu}; - const int ndim = sizeof(cells)/sizeof(cells[0]); + const int ndim = sizeof(cells) / sizeof(cells[0]); const int cdim = ctx.cdim; - const int vdim = ndim-ctx.cdim; + const int vdim = ndim - ctx.cdim; // Grids. double lower_conf[cdim], upper_conf[cdim]; int cells_conf[cdim]; - for (int d=0; dncomp, phi->size) - : gkyl_array_acquire(phi); + struct gkyl_array *phi_ho = use_gpu ? mkarr(false, phi->ncomp, phi->size) : + gkyl_array_acquire(phi); gkyl_eval_on_nodes *evphi = gkyl_eval_on_nodes_new(&grid_conf, &basis_conf, 1, phi_func_1x, &ctx); gkyl_eval_on_nodes_advance(evphi, 0.0, &local_conf, phi_ho); @@ -261,23 +265,21 @@ test_1x2v_gk(int poly_order, bool use_gpu) if (use_gpu) { bmag_max_loc = gkyl_cu_malloc(sizeof(double)); gkyl_cu_memcpy(bmag_max_loc, bmag_max_loc_ho, sizeof(double), GKYL_CU_MEMCPY_H2D); - } - else { + } else { bmag_max_loc = gkyl_malloc(sizeof(double)); memcpy(bmag_max_loc, bmag_max_loc_ho, sizeof(double)); } // Get the magnetic field at the mirror throat. double bfield_max_ho[3], bmag_max_ho[1]; - double xc_infl[] = {0.0,0.0,ctx.z_m}; + double xc_infl[] = {0.0, 0.0, ctx.z_m}; bfield_func_3x(0.0, xc_infl, bfield_max_ho, &ctx); bmag_max_ho[0] = bfield_max_ho[2]; double *bmag_max; if (use_gpu) { bmag_max = gkyl_cu_malloc(sizeof(double)); gkyl_cu_memcpy(bmag_max, bmag_max_ho, sizeof(double), GKYL_CU_MEMCPY_H2D); - } - else { + } else { bmag_max = gkyl_malloc(sizeof(double)); memcpy(bmag_max, bmag_max_ho, sizeof(double)); } @@ -290,36 +292,36 @@ test_1x2v_gk(int poly_order, bool use_gpu) if (use_gpu) { phi_m = gkyl_cu_malloc(sizeof(double)); gkyl_cu_memcpy(phi_m, phi_m_ho, sizeof(double), GKYL_CU_MEMCPY_H2D); - } - else { + } else { phi_m = gkyl_malloc(sizeof(double)); memcpy(phi_m, phi_m_ho, sizeof(double)); } // Basis used to project the mask. struct gkyl_basis basis_mask; - if (ctx.num_quad == 1 || ctx.cellwise_trap_loss) + if (ctx.num_quad == 1 || ctx.cellwise_trap_loss) { gkyl_cart_modal_serendip(&basis_mask, ndim, 0); - else { - if (poly_order == 1) + } else { + if (poly_order == 1) { gkyl_cart_modal_gkhybrid(&basis_mask, cdim, vdim); - else + } else { gkyl_cart_modal_serendip(&basis_mask, ndim, poly_order); + } } // Create mask array. struct gkyl_array *mask = mkarr(use_gpu, basis_mask.num_basis, local_ext.volume); - struct gkyl_array *mask_ho = use_gpu? mkarr(false, mask->ncomp, mask->size) - : gkyl_array_acquire(mask); + struct gkyl_array *mask_ho = use_gpu ? mkarr(false, mask->ncomp, mask->size) : + gkyl_array_acquire(mask); // Project the loss cone mask. struct gkyl_loss_cone_mask_gyrokinetic_inp inp_proj = { .phase_grid = &grid, .conf_basis = &basis_conf, .phase_basis = &basis, - .conf_range = &local_conf, + .conf_range = &local_conf, .conf_range_ext = &local_ext_conf, - .vel_range = &local_vel, + .vel_range = &local_vel, .vel_map = gvm, .bmag = gk_geom->geo_int.bmag, .bmag_max = bmag_max, @@ -329,9 +331,10 @@ test_1x2v_gk(int poly_order, bool use_gpu) .qtype = ctx.quad_type, .num_quad = ctx.num_quad, .cellwise_trap_loss = ctx.cellwise_trap_loss, - .use_gpu = use_gpu, + .use_gpu = use_gpu }; - struct gkyl_loss_cone_mask_gyrokinetic *proj_mask = gkyl_loss_cone_mask_gyrokinetic_inew( &inp_proj ); + struct gkyl_loss_cone_mask_gyrokinetic *proj_mask = + gkyl_loss_cone_mask_gyrokinetic_inew(&inp_proj); gkyl_loss_cone_mask_gyrokinetic_advance(proj_mask, &local, &local_conf, phi, phi_m, mask); @@ -339,43 +342,45 @@ test_1x2v_gk(int poly_order, bool use_gpu) // Project expected mask. struct gkyl_array *mask_ref_ho = mkarr(false, basis_mask.num_basis, local_ext.volume); - gkyl_proj_on_basis *evmask_ref = gkyl_proj_on_basis_new(&grid, &basis_mask, basis_mask.poly_order+1, 1, mask_ref_1x2v, &ctx); + gkyl_proj_on_basis *evmask_ref = + gkyl_proj_on_basis_new(&grid, &basis_mask, basis_mask.poly_order + 1, 1, mask_ref_1x2v, &ctx); gkyl_proj_on_basis_advance(evmask_ref, 0.0, &local, mask_ref_ho); gkyl_proj_on_basis_release(evmask_ref); if (ctx.num_quad == 1) { // Rescale to deal with normalization. - gkyl_array_scale(mask_ref_ho, 1.0/pow(sqrt(2.0),cdim+vdim)); + gkyl_array_scale(mask_ref_ho, 1.0 / pow(sqrt(2.0), cdim + vdim)); } -// // values to compare at index (1, 9, 9) [remember, lower-left index is (1,1,1)] -// double p1_vals[] = { -// 7.2307139183122714e-03, 0.0000000000000000e+00, 1.9198293226362615e-04, -7.7970439910196674e-04, 0.0000000000000000e+00, 0.0000000000000000e+00, -// -2.0701958137127286e-05, 0.0000000000000000e+00, -1.4953406100022537e-04, 0.0000000000000000e+00, 1.6124599381836546e-05, 0.0000000000000000e+00, -// -8.2719200283232917e-19, 0.0000000000000000e+00, -3.4806248503322844e-20, 0.0000000000000000e+00, }; -// double p2_vals[] = { -// 7.2307468609012666e-03, 0.0000000000000000e+00, 1.9198380692343289e-04, -7.8092230706225602e-04, 0.0000000000000000e+00, 0.0000000000000000e+00, -// -2.0734294852987710e-05, 3.6591823321385775e-18, -1.4953474226616330e-04, 3.7739922227981074e-05, 0.0000000000000000e+00, 7.0473141211557788e-19, -// 0.0000000000000000e+00, -4.8789097761847700e-19, 1.6149786206441256e-05, 0.0000000000000000e+00, 1.0020339643610290e-06, 5.4210108624275222e-20, -// 0.0000000000000000e+00, 0.0000000000000000e+00 }; -// -// const double *fv = gkyl_array_cfetch(distf, gkyl_range_idx(&local_ext, (int[3]) { 1, 9, 9 })); -// if (poly_order == 1) { -// for (int i=0; i #include -void -write_geometry(gk_geometry *up, struct gkyl_rect_grid grid, struct gkyl_basis basis, struct gkyl_range local, const char *name) +void write_geometry( + gk_geometry *up, struct gkyl_rect_grid grid, struct gkyl_basis basis, struct gkyl_range local, + const char *name +) { const char *fmt = "%s-%s.gkyl"; int sz = gkyl_calc_strlen(fmt, name, "jacobtot_inv"); - char fileNm[sz+1]; // ensure no buffer overflow + char fileNm[sz + 1]; // ensure no buffer overflow sprintf(fileNm, fmt, name, "mapc2p"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2p, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.mc2p, fileNm); sprintf(fileNm, fmt, name, "bmag"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_corn.bmag, fileNm); sprintf(fileNm, fmt, name, "g_ij"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.g_ij, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.g_ij, fileNm); sprintf(fileNm, fmt, name, "dxdz"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dxdz, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dxdz, fileNm); sprintf(fileNm, fmt, name, "dzdx"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dzdx, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.dzdx, fileNm); sprintf(fileNm, fmt, name, "normals"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.normals, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.normals, fileNm); sprintf(fileNm, fmt, name, "jacobgeo"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo, fileNm); sprintf(fileNm, fmt, name, "jacobgeo_inv"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo_inv, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobgeo_inv, fileNm); sprintf(fileNm, fmt, name, "gij"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gij, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gij, fileNm); sprintf(fileNm, fmt, name, "b_i"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.b_i, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.b_i, fileNm); sprintf(fileNm, fmt, name, "bcart"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bcart, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.bcart, fileNm); sprintf(fileNm, fmt, name, "cmag"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.cmag, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.cmag, fileNm); sprintf(fileNm, fmt, name, "jacobtot"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot, fileNm); sprintf(fileNm, fmt, name, "jacobtot_inv"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot_inv, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.jacobtot_inv, fileNm); sprintf(fileNm, fmt, name, "gxxj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxxj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxxj, fileNm); sprintf(fileNm, fmt, name, "gxyj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxyj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxyj, fileNm); sprintf(fileNm, fmt, name, "gyyj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gyyj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gyyj, fileNm); sprintf(fileNm, fmt, name, "gxzj"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxzj, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.gxzj, fileNm); sprintf(fileNm, fmt, name, "eps2"); - gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.eps2, fileNm); + gkyl_grid_sub_array_write(&grid, &local, 0, up->geo_int.eps2, fileNm); // Write Nodal Coordinates struct gkyl_range nrange; gkyl_gk_geometry_init_nodal_range(&nrange, &local, 1); - struct gkyl_array* mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); + struct gkyl_array *mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange.volume); struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&basis, &grid, false); gkyl_nodal_ops_m2n(n2m, &basis, &grid, &nrange, &local, 3, mc2p_nodal, up->geo_corn.mc2p, false); gkyl_nodal_ops_release(n2m); struct gkyl_rect_grid ngrid; gkyl_gk_geometry_init_nodal_grid(&ngrid, &grid, &nrange); sprintf(fileNm, fmt, name, "nodes"); - gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, fileNm); + gkyl_grid_sub_array_write(&ngrid, &nrange, 0, mc2p_nodal, fileNm); gkyl_array_release(mc2p_nodal); } -struct gkyl_efit_inp inp = { - // psiRZ and related inputs +struct gkyl_efit_inp inp = { // psiRZ and related inputs .filepath = "gyrokinetic/data/eqdsk/ltx_miller.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; int cpoly_order = 1; struct gkyl_basis cbasis; -int cnghost[GKYL_MAX_CDIM] = { 1, 1, 1 }; +int cnghost[GKYL_MAX_CDIM] = {1, 1, 1}; struct gkyl_rect_grid cgrid; struct gkyl_range clocal, clocal_ext; -void -test_ltx_miller_ho() +void test_ltx_miller_ho() { clock_t start, end; double cpu_time_used; start = clock(); - double clower[] = { 0.0018, -0.01, -M_PI+1e-14 }; - double cupper[] = {0.0024, 0.01, M_PI-1e-14 }; - int ccells[] = { 2,1,2 }; + double clower[] = {0.0018, -0.01, -M_PI + 1e-14}; + double cupper[] = {0.0024, 0.01, M_PI - 1e-14}; + int ccells[] = {2, 1, 2}; struct gkyl_tok_geo_grid_inp ginp = { .ftype = GKYL_GEOMETRY_TOKAMAK_IWL, .rclose = 0.4, - .rleft= 0.2, - .rright= 0.45, - .rmin=0.1, - .rmax=0.65, + .rleft = 0.2, + .rright = 0.45, + .rmin = 0.1, + .rmax = 0.65, .zmin = -0.3, - .zmax = 0.3, - }; + .zmax = 0.3 + }; gkyl_rect_grid_init(&cgrid, 3, clower, cupper, ccells); gkyl_create_grid_ranges(&cgrid, cnghost, &clocal_ext, &clocal); @@ -122,7 +122,7 @@ test_ltx_miller_ho() struct gkyl_position_map *pmap = gkyl_position_map_null_new(); struct gkyl_gk_geometry_inp geometry_inp = { - .geometry_id = GKYL_GEOMETRY_TOKAMAK, + .geometry_id = GKYL_GEOMETRY_TOKAMAK, .efit_info = inp, .tok_grid_info = ginp, .position_map = pmap, @@ -137,23 +137,18 @@ test_ltx_miller_ho() .geo_local_ext = clocal_ext, .geo_global = clocal, .geo_global_ext = clocal_ext, - .geo_basis = cbasis, + .geo_basis = cbasis }; - struct gk_geometry* up = gkyl_gk_geometry_tok_new(&geometry_inp); + struct gk_geometry *up = gkyl_gk_geometry_tok_new(&geometry_inp); write_geometry(up, cgrid, cbasis, clocal, "ltx_miller"); gkyl_gk_geometry_release(up); gkyl_position_map_release(pmap); end = clock(); - cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC; gkyl_position_map_release(pmap); } - - -TEST_LIST = { - { "test_ltx_miller_ho", test_ltx_miller_ho}, - { NULL, NULL }, -}; +TEST_LIST = {{"test_ltx_miller_ho", test_ltx_miller_ho}, {NULL, NULL}}; diff --git a/gyrokinetic/unit/ctest_mirror_grid_gen.c b/gyrokinetic/unit/ctest_mirror_grid_gen.c index e570eeb50c..5636b6fff0 100644 --- a/gyrokinetic/unit/ctest_mirror_grid_gen.c +++ b/gyrokinetic/unit/ctest_mirror_grid_gen.c @@ -11,18 +11,20 @@ #include #include -static inline double SQ(double x) { return x*x; }; +static inline double SQ(double x) +{ + return x * x; +}; -static void -test_wham(bool include_axis, enum gkyl_mirror_grid_gen_field_line_coord fl_coord) +static void test_wham(bool include_axis, enum gkyl_mirror_grid_gen_field_line_coord fl_coord) { - double clower[] = { 2.0e-6, 0.0, -2.0 }; - double cupper[] = { 3.0e-3, 2*M_PI, 2.0 }; - int cells[] = { 10, 16, 32 }; + double clower[] = {2.0e-6, 0.0, -2.0}; + double cupper[] = {3.0e-3, 2 * M_PI, 2.0}; + int cells[] = {10, 16, 32}; int cdim = 3; const char *fname = "gyrokinetic/data/unit/wham_hires.geqdsk_psi.gkyl"; - + // computational grid struct gkyl_rect_grid comp_grid; gkyl_rect_grid_init(&comp_grid, cdim, clower, cupper, cells); @@ -31,58 +33,52 @@ test_wham(bool include_axis, enum gkyl_mirror_grid_gen_field_line_coord fl_coord fprintf(stderr, "Unable to find file %s!\n", fname); goto cleanup; } - + // read psi(R,Z) from file struct gkyl_rect_grid psi_grid; struct gkyl_array *psi = gkyl_grid_array_new_from_file(&psi_grid, fname); struct gkyl_range node_range; - gkyl_range_init_from_shape(&node_range, 3, (int[3]) { cells[0]+1, cells[1]+1, cells[2]+1 }); + gkyl_range_init_from_shape(&node_range, 3, (int[3]){cells[0] + 1, cells[1] + 1, cells[2] + 1}); struct gkyl_range ext_range, range; - int nghost[3] = {1,1,1}; + int nghost[3] = {1, 1, 1}; gkyl_create_grid_ranges(&comp_grid, nghost, &ext_range, &range); struct gkyl_position_map *gpm = gkyl_position_map_null_new(); // create mirror geometry - struct gkyl_mirror_grid_gen *geom = - gkyl_mirror_grid_gen_inew(&(struct gkyl_mirror_grid_gen_inp) { - .comp_grid = &comp_grid, - .nrange = node_range, - .local = range, - .global = range, - - .R = { psi_grid.lower[0], psi_grid.upper[0] }, - .Z = { psi_grid.lower[1], psi_grid.upper[1] }, - - // psi(R,Z) grid size - .nrcells = psi_grid.cells[0]-1, // cells and not nodes - .nzcells = psi_grid.cells[1]-1, // cells and not nodes - - .psiRZ = psi, - .fl_coord = fl_coord, - .include_axis = include_axis, - .write_psi_cubic = false, - - .position_map = gpm, - } - ); + struct gkyl_mirror_grid_gen *geom = gkyl_mirror_grid_gen_inew(&(struct gkyl_mirror_grid_gen_inp + ){.comp_grid = &comp_grid, + .nrange = node_range, + .local = range, + .global = range, - TEST_CHECK( include_axis == gkyl_mirror_grid_gen_is_include_axis(geom) ); - TEST_CHECK( fl_coord == gkyl_mirror_grid_gen_fl_coord(geom) ); - + .R = {psi_grid.lower[0], psi_grid.upper[0]}, + .Z = {psi_grid.lower[1], psi_grid.upper[1]}, + + // psi(R,Z) grid size + .nrcells = psi_grid.cells[0] - 1, // cells and not nodes + .nzcells = psi_grid.cells[1] - 1, // cells and not nodes + + .psiRZ = psi, + .fl_coord = fl_coord, + .include_axis = include_axis, + .write_psi_cubic = false, + + .position_map = gpm}); + + TEST_CHECK(include_axis == gkyl_mirror_grid_gen_is_include_axis(geom)); + TEST_CHECK(fl_coord == gkyl_mirror_grid_gen_fl_coord(geom)); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &node_range); while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&node_range, iter.idx); - const double *rz = - gkyl_array_cfetch(geom->nodes_rza, loc); + const double *rz = gkyl_array_cfetch(geom->nodes_rza, loc); - const struct gkyl_mirror_grid_gen_geom *g = - gkyl_array_cfetch(geom->nodes_geom, loc); + const struct gkyl_mirror_grid_gen_geom *g = gkyl_array_cfetch(geom->nodes_geom, loc); // check Jacobian double Jac = gkyl_vec3_triple( @@ -91,21 +87,20 @@ test_wham(bool include_axis, enum gkyl_mirror_grid_gen_field_line_coord fl_coord gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]) ); - if (rz[0] > 0) - TEST_CHECK( gkyl_compare_double(Jac, g->Jc, 1e-14) ); + if (rz[0] > 0) { + TEST_CHECK(gkyl_compare_double(Jac, g->Jc, 1e-14)); + } // check C = Jc*Bmag/sqrt(g33) - double g33 = - gkyl_vec3_dot( - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]), - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]) - ); - double Bmag = gkyl_vec3_len( - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->B) + double g33 = gkyl_vec3_dot( + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]), + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]) ); - - if (fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_PSI_CART_Z) - TEST_CHECK( gkyl_compare_double(Bmag*g->Jc/sqrt(g33), 1.0, 1e-14) ); + double Bmag = gkyl_vec3_len(gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->B)); + + if (fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_PSI_CART_Z) { + TEST_CHECK(gkyl_compare_double(Bmag * g->Jc / sqrt(g33), 1.0, 1e-14)); + } // check B only points in the parallel direction // ... B^1 = 0 @@ -113,20 +108,20 @@ test_wham(bool include_axis, enum gkyl_mirror_grid_gen_field_line_coord fl_coord gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->B), gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->dual[0]) ); - TEST_CHECK( gkyl_compare_double(B1, 0.0, 1e-14) ); + TEST_CHECK(gkyl_compare_double(B1, 0.0, 1e-14)); // ... B^2 = 0 double B2 = gkyl_vec3_dot( gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->B), gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->dual[1]) ); - TEST_CHECK( gkyl_compare_double(B1, 0.0, 1e-14) ); - + TEST_CHECK(gkyl_compare_double(B1, 0.0, 1e-14)); + // check relationship between tangents and duals - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { struct gkyl_vec3 tcart = gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[i]); - - for (int j=0; j<3; ++j) { + + for (int j = 0; j < 3; ++j) { struct gkyl_vec3 dcart = gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->dual[j]); // NOTE: the tangent/dual relations only hold off-axis as at @@ -134,10 +129,11 @@ test_wham(bool include_axis, enum gkyl_mirror_grid_gen_field_line_coord fl_coord if (rz[0] > 0) { // tang[i] dot dual[j] = delta_{i,j} double tdotd = gkyl_vec3_dot(tcart, dcart); - if (i == j) - TEST_CHECK( gkyl_compare_double(tdotd, 1.0, 1e-14) ); - else - TEST_CHECK( gkyl_compare_double(tdotd, 0.0, 1e-14) ); + if (i == j) { + TEST_CHECK(gkyl_compare_double(tdotd, 1.0, 1e-14)); + } else { + TEST_CHECK(gkyl_compare_double(tdotd, 0.0, 1e-14)); + } } } } @@ -147,248 +143,228 @@ test_wham(bool include_axis, enum gkyl_mirror_grid_gen_field_line_coord fl_coord gkyl_array_release(psi); gkyl_position_map_release(gpm); - cleanup: +cleanup: return; } -static void -test_mirror_grid_gen_wham_no_axis_psi_ho(void) +static void test_mirror_grid_gen_wham_no_axis_psi_ho(void) { test_wham(false, GKYL_GEOMETRY_MIRROR_GRID_GEN_PSI_CART_Z); } -static void -test_mirror_grid_gen_wham_with_axis_psi_ho(void) +static void test_mirror_grid_gen_wham_with_axis_psi_ho(void) { test_wham(true, GKYL_GEOMETRY_MIRROR_GRID_GEN_PSI_CART_Z); } -static void -test_mirror_grid_gen_wham_no_axis_sqrt_psi_ho(void) +static void test_mirror_grid_gen_wham_no_axis_sqrt_psi_ho(void) { test_wham(false, GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z); } -static void -test_mirror_grid_gen_wham_with_axis_sqrt_psi_ho(void) +static void test_mirror_grid_gen_wham_with_axis_sqrt_psi_ho(void) { test_wham(true, GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z); } -static void -test_quad_geom(bool include_axis, enum gkyl_mirror_grid_gen_field_line_coord fl_coord) +static void test_quad_geom(bool include_axis, enum gkyl_mirror_grid_gen_field_line_coord fl_coord) { - double clower[] = { 1.0e-3, 0.0, -0.75 }; - double cupper[] = { 0.5, 2*M_PI, 0.75 }; - int cells[] = { 3, 3, 3 }; + double clower[] = {1.0e-3, 0.0, -0.75}; + double cupper[] = {0.5, 2 * M_PI, 0.75}; + int cells[] = {3, 3, 3}; int cdim = 3; - + // computational grid struct gkyl_rect_grid comp_grid; gkyl_rect_grid_init(&comp_grid, cdim, clower, cupper, cells); // construct analytical psi(R,Z) on a nodal grid: - int psi_nodes[] = { 9, 17 }; + int psi_nodes[] = {9, 17}; struct gkyl_range psi_nodes_range; gkyl_range_init_from_shape(&psi_nodes_range, 2, psi_nodes); - + struct gkyl_rect_grid psi_grid; - gkyl_rect_grid_init(&psi_grid, 2, - (double[]) { 0.0, -1.0 }, - (double[]) { 1.0, 1.0 }, - psi_nodes - ); - + gkyl_rect_grid_init(&psi_grid, 2, (double[]){0.0, -1.0}, (double[]){1.0, 1.0}, psi_nodes); + struct gkyl_array *psi = gkyl_array_new(GKYL_DOUBLE, 1, psi_nodes_range.volume); - double dnodes[] = { 1.0/(psi_nodes[0]-1), 2.0/(psi_nodes[1]-1) }; - + double dnodes[] = {1.0 / (psi_nodes[0] - 1), 2.0 / (psi_nodes[1] - 1)}; + struct gkyl_range_iter psi_nodes_iter; gkyl_range_iter_init(&psi_nodes_iter, &psi_nodes_range); while (gkyl_range_iter_next(&psi_nodes_iter)) { - double R = 0.0 + psi_nodes_iter.idx[0]*dnodes[0]; - double Z = -1.0 + psi_nodes_iter.idx[1]*dnodes[1]; + double R = 0.0 + psi_nodes_iter.idx[0] * dnodes[0]; + double Z = -1.0 + psi_nodes_iter.idx[1] * dnodes[1]; double *pn = gkyl_array_fetch(psi, gkyl_range_idx(&psi_nodes_range, psi_nodes_iter.idx)); - pn[0] = 0.5*(R*R)*(Z*Z+1.0); // psi(R,Z) = 1/2*R^2*(Z^2+1.0) + pn[0] = 0.5 * (R * R) * (Z * Z + 1.0); // psi(R,Z) = 1/2*R^2*(Z^2+1.0) } struct gkyl_range node_range; - gkyl_range_init_from_shape(&node_range, 3, (int[3]) { cells[0]+1, cells[1]+1, cells[2]+1 }); + gkyl_range_init_from_shape(&node_range, 3, (int[3]){cells[0] + 1, cells[1] + 1, cells[2] + 1}); struct gkyl_range ext_range, range; - int nghost[3] = { 1,1,1}; + int nghost[3] = {1, 1, 1}; gkyl_create_grid_ranges(&comp_grid, nghost, &ext_range, &range); struct gkyl_position_map *gpm = gkyl_position_map_null_new(); // create mirror geometry - struct gkyl_mirror_grid_gen *geom = - gkyl_mirror_grid_gen_inew(&(struct gkyl_mirror_grid_gen_inp) { - .comp_grid = &comp_grid, - .nrange = node_range, - .local = range, - .global = range, - - .R = { psi_grid.lower[0], psi_grid.upper[0] }, - .Z = { psi_grid.lower[1], psi_grid.upper[1] }, - - // psi(R,Z) grid size - .nrcells = psi_grid.cells[0]-1, // cells and not nodes - .nzcells = psi_grid.cells[1]-1, // cells and not nodes - - .psiRZ = psi, - .fl_coord = fl_coord, - .include_axis = include_axis, - .write_psi_cubic = false, - .psi_cubic_fname = "ctest_mirror_grid_gen_quad.gkyl", - - .position_map = gpm, - } - ); + struct gkyl_mirror_grid_gen *geom = gkyl_mirror_grid_gen_inew(&(struct gkyl_mirror_grid_gen_inp + ){.comp_grid = &comp_grid, + .nrange = node_range, + .local = range, + .global = range, - TEST_CHECK( include_axis == gkyl_mirror_grid_gen_is_include_axis(geom) ); - TEST_CHECK( fl_coord == gkyl_mirror_grid_gen_fl_coord(geom) ); + .R = {psi_grid.lower[0], psi_grid.upper[0]}, + .Z = {psi_grid.lower[1], psi_grid.upper[1]}, + + // psi(R,Z) grid size + .nrcells = psi_grid.cells[0] - 1, // cells and not nodes + .nzcells = psi_grid.cells[1] - 1, // cells and not nodes + + .psiRZ = psi, + .fl_coord = fl_coord, + .include_axis = include_axis, + .write_psi_cubic = false, + .psi_cubic_fname = "ctest_mirror_grid_gen_quad.gkyl", + + .position_map = gpm}); + + TEST_CHECK(include_axis == gkyl_mirror_grid_gen_is_include_axis(geom)); + TEST_CHECK(fl_coord == gkyl_mirror_grid_gen_fl_coord(geom)); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &node_range); while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&node_range, iter.idx); - const double *rz = - gkyl_array_cfetch(geom->nodes_rza, loc); + const double *rz = gkyl_array_cfetch(geom->nodes_rza, loc); double r = rz[0], z = rz[1]; - const struct gkyl_mirror_grid_gen_geom *g = - gkyl_array_cfetch(geom->nodes_geom, loc); + const struct gkyl_mirror_grid_gen_geom *g = gkyl_array_cfetch(geom->nodes_geom, loc); // construct metric tensor double g00 = gkyl_vec3_dot( - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[0]), - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[0]) + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[0]), + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[0]) ); double g01 = gkyl_vec3_dot( - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[0]), - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[1]) + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[0]), + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[1]) ); double g02 = gkyl_vec3_dot( - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[0]), - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]) + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[0]), + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]) ); double g11 = gkyl_vec3_dot( - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[1]), - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[1]) + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[1]), + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[1]) ); double g12 = gkyl_vec3_dot( - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[1]), - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]) + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[1]), + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]) ); double g22 = gkyl_vec3_dot( - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]), - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]) + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]), + gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->tang[2]) ); - if (r>0) { + if (r > 0) { if (fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_PSI_CART_Z) { // g00 - TEST_CHECK ( gkyl_compare_double(1/(SQ(r)*SQ(1+SQ(z))), g00, 1e-14) ); + TEST_CHECK(gkyl_compare_double(1 / (SQ(r) * SQ(1 + SQ(z))), g00, 1e-14)); // g01 - TEST_CHECK ( gkyl_compare_double(0.0, g01, 1e-14) ); + TEST_CHECK(gkyl_compare_double(0.0, g01, 1e-14)); // g02 - TEST_CHECK ( gkyl_compare_double(-SQ(r)*z/(SQ(r)*SQ(1+SQ(z))), g02, 1e-14) ); - + TEST_CHECK(gkyl_compare_double(-SQ(r) * z / (SQ(r) * SQ(1 + SQ(z))), g02, 1e-14)); + // g11 - TEST_CHECK ( gkyl_compare_double(SQ(r), g11, 1e-14) ); + TEST_CHECK(gkyl_compare_double(SQ(r), g11, 1e-14)); // g12 - TEST_CHECK ( gkyl_compare_double(0.0, g12, 1e-14) ); - + TEST_CHECK(gkyl_compare_double(0.0, g12, 1e-14)); + // g22 - TEST_CHECK ( gkyl_compare_double( (SQ(r*(1+SQ(z)))+SQ(SQ(r)*z))/(SQ(r)*SQ(1+SQ(z))), - g22, 1e-14) - ); - } - + TEST_CHECK(gkyl_compare_double( + (SQ(r * (1 + SQ(z))) + SQ(SQ(r) * z)) / (SQ(r) * SQ(1 + SQ(z))), g22, 1e-14 + )); + } + if (fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { - double psil = 0.5*SQ(r)*(1+SQ(z)); - + double psil = 0.5 * SQ(r) * (1 + SQ(z)); + // g00 - TEST_CHECK ( gkyl_compare_double(4*psil/(SQ(r)*SQ(1+SQ(z))), g00, 1e-14) ); + TEST_CHECK(gkyl_compare_double(4 * psil / (SQ(r) * SQ(1 + SQ(z))), g00, 1e-14)); // g01 - TEST_CHECK ( gkyl_compare_double(0.0, g01, 1e-14) ); + TEST_CHECK(gkyl_compare_double(0.0, g01, 1e-14)); // g02 - TEST_CHECK ( gkyl_compare_double(-2*sqrt(psil)*SQ(r)*z/(SQ(r)*SQ(1+SQ(z))), g02, 1e-13) ); + TEST_CHECK( + gkyl_compare_double(-2 * sqrt(psil) * SQ(r) * z / (SQ(r) * SQ(1 + SQ(z))), g02, 1e-13) + ); // g11 - TEST_CHECK ( gkyl_compare_double(SQ(r), g11, 1e-14) ); + TEST_CHECK(gkyl_compare_double(SQ(r), g11, 1e-14)); // g12 - TEST_CHECK ( gkyl_compare_double(0.0, g12, 1e-14) ); + TEST_CHECK(gkyl_compare_double(0.0, g12, 1e-14)); // g22 - TEST_CHECK ( gkyl_compare_double( (SQ(r*(1+SQ(z)))+SQ(SQ(r)*z))/(SQ(r)*SQ(1+SQ(z))), - g22, 1e-14) - ); + TEST_CHECK(gkyl_compare_double( + (SQ(r * (1 + SQ(z))) + SQ(SQ(r) * z)) / (SQ(r) * SQ(1 + SQ(z))), g22, 1e-14 + )); } - double Bmag = gkyl_vec3_len( - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->B) - ); - TEST_CHECK( gkyl_compare_double(sqrt(SQ(r*(1+SQ(z)))+SQ(SQ(r)*z))/r, Bmag, 1e-14) ); - } - else { + double Bmag = gkyl_vec3_len(gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->B)); + TEST_CHECK(gkyl_compare_double(sqrt(SQ(r * (1 + SQ(z))) + SQ(SQ(r) * z)) / r, Bmag, 1e-14)); + } else { // on-axis - double Bmag = gkyl_vec3_len( - gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->B) - ); - TEST_CHECK( gkyl_compare_double(1+SQ(z), Bmag, 1e-14) ); + double Bmag = gkyl_vec3_len(gkyl_vec3_polar_con_to_cart(rz[0], 0.0, g->B)); + TEST_CHECK(gkyl_compare_double(1 + SQ(z), Bmag, 1e-14)); } - } gkyl_mirror_grid_gen_release(geom); gkyl_array_release(psi); gkyl_position_map_release(gpm); - cleanup: +cleanup: return; } -static void -test_mirror_grid_gen_quad_geom_no_axis_psi_ho(void) +static void test_mirror_grid_gen_quad_geom_no_axis_psi_ho(void) { test_quad_geom(false, GKYL_GEOMETRY_MIRROR_GRID_GEN_PSI_CART_Z); } -static void -test_mirror_grid_gen_quad_geom_with_axis_psi_ho(void) +static void test_mirror_grid_gen_quad_geom_with_axis_psi_ho(void) { test_quad_geom(true, GKYL_GEOMETRY_MIRROR_GRID_GEN_PSI_CART_Z); } -static void -test_mirror_grid_gen_quad_geom_no_axis_sqrt_psi_ho(void) +static void test_mirror_grid_gen_quad_geom_no_axis_sqrt_psi_ho(void) { test_quad_geom(false, GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z); } -static void -test_mirror_grid_gen_quad_geom_with_axis_sqrt_psi_ho(void) +static void test_mirror_grid_gen_quad_geom_with_axis_sqrt_psi_ho(void) { test_quad_geom(true, GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z); } TEST_LIST = { - { "mirror_grid_gen_wham_no_axis_psi_ho", test_mirror_grid_gen_wham_no_axis_psi_ho }, - { "mirror_grid_gen_wham_with_axis_psi_ho", test_mirror_grid_gen_wham_with_axis_psi_ho }, + {"mirror_grid_gen_wham_no_axis_psi_ho", test_mirror_grid_gen_wham_no_axis_psi_ho}, + {"mirror_grid_gen_wham_with_axis_psi_ho", test_mirror_grid_gen_wham_with_axis_psi_ho}, - { "mirror_grid_gen_wham_no_axis_sqrt_psi_ho", test_mirror_grid_gen_wham_no_axis_sqrt_psi_ho }, - { "mirror_grid_gen_wham_with_axis_sqrt_psi_ho", test_mirror_grid_gen_wham_with_axis_sqrt_psi_ho }, + {"mirror_grid_gen_wham_no_axis_sqrt_psi_ho", test_mirror_grid_gen_wham_no_axis_sqrt_psi_ho}, + {"mirror_grid_gen_wham_with_axis_sqrt_psi_ho", test_mirror_grid_gen_wham_with_axis_sqrt_psi_ho}, - { "mirror_grid_gen_quad_geom_no_axis_psi_ho", test_mirror_grid_gen_quad_geom_no_axis_psi_ho}, - { "mirror_grid_gen_quad_geom_with_axis_psi_ho", test_mirror_grid_gen_quad_geom_with_axis_psi_ho}, + {"mirror_grid_gen_quad_geom_no_axis_psi_ho", test_mirror_grid_gen_quad_geom_no_axis_psi_ho}, + {"mirror_grid_gen_quad_geom_with_axis_psi_ho", test_mirror_grid_gen_quad_geom_with_axis_psi_ho}, - { "mirror_grid_gen_quad_geom_no_axis_sqrt_psi_ho", test_mirror_grid_gen_quad_geom_no_axis_sqrt_psi_ho }, - { "mirror_grid_gen_quad_geom_with_axis_sqrt_psi_ho", test_mirror_grid_gen_quad_geom_with_axis_sqrt_psi_ho }, - { NULL, NULL }, + {"mirror_grid_gen_quad_geom_no_axis_sqrt_psi_ho", + test_mirror_grid_gen_quad_geom_no_axis_sqrt_psi_ho}, + {"mirror_grid_gen_quad_geom_with_axis_sqrt_psi_ho", + test_mirror_grid_gen_quad_geom_with_axis_sqrt_psi_ho}, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_mom_gyrokinetic.c b/gyrokinetic/unit/ctest_mom_gyrokinetic.c index 51c87d65ad..8bc4535574 100644 --- a/gyrokinetic/unit/ctest_mom_gyrokinetic.c +++ b/gyrokinetic/unit/ctest_mom_gyrokinetic.c @@ -15,52 +15,49 @@ #include #include -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } -void -bfield_func_1x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func_1x(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { - double x = xc[0]; + double x = xc[0]; fout[0] = 0.0; fout[1] = 0.0; - fout[2] = cos((2.*M_PI/(2.*2.*M_PI))*x); + fout[2] = cos((2. * M_PI / (2. * 2. * M_PI)) * x); } -void -bfield_func_2x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func_2x(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1]; fout[0] = 0.0; fout[1] = 0.0; - fout[2] = cos((2.*M_PI/(2.*2.*M_PI))*x)*exp(-(y*y)/(2.*pow(M_PI/3,2))); + fout[2] = cos((2. * M_PI / (2. * 2. * M_PI)) * x) * exp(-(y * y) / (2. * pow(M_PI / 3, 2))); } -void -mapc2p_3x(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p_3x(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; xp[2] = xc[2]; + xp[0] = xc[0]; + xp[1] = xc[1]; + xp[2] = xc[2]; } -void -bfield_func_3x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func_3x(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; fout[0] = 0.0; fout[1] = 0.0; - fout[2] = cos((2.*M_PI/(2.*2.*M_PI))*x)*exp(-(y*y)/(2.*pow(M_PI/3,2))); + fout[2] = cos((2. * M_PI / (2. * 2. * M_PI)) * x) * exp(-(y * y) / (2. * pow(M_PI / 3, 2))); } -void -test_mom_gyrokinetic_ho() +void test_mom_gyrokinetic_ho() { double mass = 1.0; double charge = 1.0; @@ -69,22 +66,22 @@ test_mom_gyrokinetic_ho() int cells[] = {4, 2, 2}; int vdim = 2; - int ndim = sizeof(cells)/sizeof(cells[0]); + int ndim = sizeof(cells) / sizeof(cells[0]); int cdim = ndim - vdim; double confLower[cdim], confUpper[cdim]; int confCells[cdim]; - for (int d=0; dcdim == 1 ); - TEST_CHECK( m2->pdim == 3 ); - TEST_CHECK( m2->poly_order == 1 ); - TEST_CHECK( m2->num_config == confBasis.num_basis ); - TEST_CHECK( m2->num_phase == basis.num_basis ); - TEST_CHECK( m2->num_mom == 1 ); - - struct gkyl_mom_type *m3par = gkyl_mom_gyrokinetic_new(&confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M3PAR, false); - TEST_CHECK( m3par->num_mom == 1 ); - - gkyl_gk_geometry_release(gk_geom); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, velGrid, local, local_ext, velLocal, velLocal_ext, false); + + struct gkyl_mom_type *m2 = gkyl_mom_gyrokinetic_new( + &confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M2, false + ); + + TEST_CHECK(m2->cdim == 1); + TEST_CHECK(m2->pdim == 3); + TEST_CHECK(m2->poly_order == 1); + TEST_CHECK(m2->num_config == confBasis.num_basis); + TEST_CHECK(m2->num_phase == basis.num_basis); + TEST_CHECK(m2->num_mom == 1); + + struct gkyl_mom_type *m3par = gkyl_mom_gyrokinetic_new( + &confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M3PAR, false + ); + TEST_CHECK(m3par->num_mom == 1); + + gkyl_gk_geometry_release(gk_geom); gkyl_mom_type_release(m2); gkyl_mom_type_release(m3par); gkyl_velocity_map_release(gvm); gkyl_position_map_release(pmap); } -void distf_1x1v(double t, const double *xn, double* restrict fout, void *ctx) +void distf_1x1v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], vpar = xn[1]; double bfield[3]; - bfield_func_1x(t, xn, &bfield[0], ctx); - double bmag = sqrt(bfield[0]*bfield[0]+bfield[1]*bfield[1]+bfield[2]*bfield[2]); - fout[0] = bmag*(x*x)*(vpar-0.5)*(vpar-0.5); + bfield_func_1x(t, xn, &bfield[0], ctx); + double bmag = sqrt(bfield[0] * bfield[0] + bfield[1] * bfield[1] + bfield[2] * bfield[2]); + fout[0] = bmag * (x * x) * (vpar - 0.5) * (vpar - 0.5); } -void distf_1x2v(double t, const double *xn, double* restrict fout, void *ctx) +void distf_1x2v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], vpar = xn[1], mu = xn[2]; double bfield[3]; - bfield_func_1x(t, xn, &bfield[0], ctx); - double bmag = sqrt(bfield[0]*bfield[0]+bfield[1]*bfield[1]+bfield[2]*bfield[2]); - fout[0] = bmag*(x*x)*(vpar-0.5)*(vpar-0.5); + bfield_func_1x(t, xn, &bfield[0], ctx); + double bmag = sqrt(bfield[0] * bfield[0] + bfield[1] * bfield[1] + bfield[2] * bfield[2]); + fout[0] = bmag * (x * x) * (vpar - 0.5) * (vpar - 0.5); } -void distf_2x2v(double t, const double *xn, double* restrict fout, void *ctx) +void distf_2x2v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1], vpar = xn[2], mu = xn[3]; double bfield[3]; - bfield_func_2x(t, xn, &bfield[0], ctx); - double bmag = sqrt(bfield[0]*bfield[0]+bfield[1]*bfield[1]+bfield[2]*bfield[2]); - fout[0] = bmag*(x*x+y*y)*(vpar-0.5)*(vpar-0.5); + bfield_func_2x(t, xn, &bfield[0], ctx); + double bmag = sqrt(bfield[0] * bfield[0] + bfield[1] * bfield[1] + bfield[2] * bfield[2]); + fout[0] = bmag * (x * x + y * y) * (vpar - 0.5) * (vpar - 0.5); } -void -test_1x1v(int polyOrder, bool use_gpu) +void test_1x1v(int polyOrder, bool use_gpu) { double mass = 1.0; double charge = 1.0; @@ -198,22 +202,22 @@ test_1x1v(int polyOrder, bool use_gpu) int cells[] = {4, 2}; int vdim = 1; - int ndim = sizeof(cells)/sizeof(cells[0]); + int ndim = sizeof(cells) / sizeof(cells[0]); int cdim = ndim - vdim; double confLower[cdim], confUpper[cdim]; int confCells[cdim]; - for (int d=0; dncomp, distf->size) : gkyl_array_acquire(distf); - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, distf_1x1v, NULL); + distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : gkyl_array_acquire(distf); + gkyl_proj_on_basis *projDistf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, distf_1x1v, NULL); gkyl_proj_on_basis_advance(projDistf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); -// gkyl_grid_sub_array_write(&grid, &local, distf_ho, "ctest_mom_gyrokinetic_1x1v_p1_distf.gkyl"); + // gkyl_grid_sub_array_write(&grid, &local, distf_ho, "ctest_mom_gyrokinetic_1x1v_p1_distf.gkyl"); struct gkyl_position_map *pmap = gkyl_position_map_null_new(); // Initialize geometry struct gkyl_gk_geometry_inp geometry_input = { .geometry_id = GKYL_GEOMETRY_MAPC2P, - .world = {0.0, 0.0}, .mapc2p = mapc2p_3x, .c2p_ctx = 0, - .bfield_func = bfield_func_3x, .bfield_ctx = 0, - .basis = confBasis, .grid = confGrid, - .local = confLocal, .local_ext = confLocal_ext, - .global = confLocal, .global_ext = confLocal_ext, - .position_map = pmap, + .world = {0.0, 0.0}, + .mapc2p = mapc2p_3x, + .c2p_ctx = 0, + .bfield_func = bfield_func_3x, + .bfield_ctx = 0, + .basis = confBasis, + .grid = confGrid, + .local = confLocal, + .local_ext = confLocal_ext, + .global = confLocal, + .global_ext = confLocal_ext, + .position_map = pmap }; int geo_ghost[3] = {1, 1, 1}; geometry_input.geo_grid = gkyl_gk_geometry_augment_grid(confGrid, geometry_input); gkyl_cart_modal_serendip(&geometry_input.geo_basis, 3, poly_order); - gkyl_create_grid_ranges(&geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global); + gkyl_create_grid_ranges( + &geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global + ); memcpy(&geometry_input.geo_local, &geometry_input.geo_global, sizeof(struct gkyl_range)); memcpy(&geometry_input.geo_local_ext, &geometry_input.geo_global_ext, sizeof(struct gkyl_range)); // Deflate geometry. - struct gk_geometry* gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); + struct gk_geometry *gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); struct gk_geometry *gk_geom = gkyl_gk_geometry_deflate(gk_geom_3d, &geometry_input); gkyl_gk_geometry_release(gk_geom_3d); // If we are on the gpu, copy from host. if (use_gpu) { - struct gk_geometry* gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); + struct gk_geometry *gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); gkyl_gk_geometry_release(gk_geom); gk_geom = gkyl_gk_geometry_acquire(gk_geom_dev); gkyl_gk_geometry_release(gk_geom_dev); @@ -288,20 +302,26 @@ test_1x1v(int polyOrder, bool use_gpu) // If we are on the gpu, copy from host if (use_gpu) { - struct gk_geometry* gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); + struct gk_geometry *gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); gkyl_gk_geometry_release(gk_geom); gk_geom = gkyl_gk_geometry_acquire(gk_geom_dev); gkyl_gk_geometry_release(gk_geom_dev); } // Initialize velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, grid, velGrid, - local, local_ext, velLocal, velLocal_ext, use_gpu); - - struct gkyl_mom_type *M0_t = gkyl_mom_gyrokinetic_new(&confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0, use_gpu); - struct gkyl_mom_type *M1_t = gkyl_mom_gyrokinetic_new(&confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M1, use_gpu); - struct gkyl_mom_type *M2_t = gkyl_mom_gyrokinetic_new(&confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M2, use_gpu); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, velGrid, local, local_ext, velLocal, velLocal_ext, use_gpu); + + struct gkyl_mom_type *M0_t = gkyl_mom_gyrokinetic_new( + &confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0, use_gpu + ); + struct gkyl_mom_type *M1_t = gkyl_mom_gyrokinetic_new( + &confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M1, use_gpu + ); + struct gkyl_mom_type *M2_t = gkyl_mom_gyrokinetic_new( + &confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M2, use_gpu + ); gkyl_mom_calc *m0calc = gkyl_mom_calc_new(&grid, M0_t, use_gpu); gkyl_mom_calc *m1calc = gkyl_mom_calc_new(&grid, M1_t, use_gpu); gkyl_mom_calc *m2calc = gkyl_mom_calc_new(&grid, M2_t, use_gpu); @@ -311,9 +331,9 @@ test_1x1v(int polyOrder, bool use_gpu) m0 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); m1 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); - m0_ho = use_gpu? mkarr(false, m0->ncomp, m0->size) : gkyl_array_acquire(m0); - m1_ho = use_gpu? mkarr(false, m1->ncomp, m1->size) : gkyl_array_acquire(m1); - m2_ho = use_gpu? mkarr(false, m2->ncomp, m2->size) : gkyl_array_acquire(m2); + m0_ho = use_gpu ? mkarr(false, m0->ncomp, m0->size) : gkyl_array_acquire(m0); + m1_ho = use_gpu ? mkarr(false, m1->ncomp, m1->size) : gkyl_array_acquire(m1); + m2_ho = use_gpu ? mkarr(false, m2->ncomp, m2->size) : gkyl_array_acquire(m2); // compute the moments if (use_gpu) { @@ -329,120 +349,128 @@ test_1x1v(int polyOrder, bool use_gpu) gkyl_array_copy(m1_ho, m1); gkyl_array_copy(m2_ho, m2); - double *m00 = gkyl_array_fetch(m0_ho, 0+confGhost[0]); double *m01 = gkyl_array_fetch(m0_ho, 1+confGhost[0]); - double *m02 = gkyl_array_fetch(m0_ho, 2+confGhost[0]); double *m03 = gkyl_array_fetch(m0_ho, 3+confGhost[0]); - double *m10 = gkyl_array_fetch(m1_ho, 0+confGhost[0]); double *m11 = gkyl_array_fetch(m1_ho, 1+confGhost[0]); - double *m12 = gkyl_array_fetch(m1_ho, 2+confGhost[0]); double *m13 = gkyl_array_fetch(m1_ho, 3+confGhost[0]); - double *m20 = gkyl_array_fetch(m2_ho, 0+confGhost[0]); double *m21 = gkyl_array_fetch(m2_ho, 1+confGhost[0]); - double *m22 = gkyl_array_fetch(m2_ho, 2+confGhost[0]); double *m23 = gkyl_array_fetch(m2_ho, 3+confGhost[0]); - - if (poly_order==1) { + double *m00 = gkyl_array_fetch(m0_ho, 0 + confGhost[0]); + double *m01 = gkyl_array_fetch(m0_ho, 1 + confGhost[0]); + double *m02 = gkyl_array_fetch(m0_ho, 2 + confGhost[0]); + double *m03 = gkyl_array_fetch(m0_ho, 3 + confGhost[0]); + double *m10 = gkyl_array_fetch(m1_ho, 0 + confGhost[0]); + double *m11 = gkyl_array_fetch(m1_ho, 1 + confGhost[0]); + double *m12 = gkyl_array_fetch(m1_ho, 2 + confGhost[0]); + double *m13 = gkyl_array_fetch(m1_ho, 3 + confGhost[0]); + double *m20 = gkyl_array_fetch(m2_ho, 0 + confGhost[0]); + double *m21 = gkyl_array_fetch(m2_ho, 1 + confGhost[0]); + double *m22 = gkyl_array_fetch(m2_ho, 2 + confGhost[0]); + double *m23 = gkyl_array_fetch(m2_ho, 3 + confGhost[0]); + + if (poly_order == 1) { // Check M0. - TEST_CHECK( gkyl_compare( 1.52537436025689e+01, m00[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.57234787161818e+00, m00[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.08286277145113e+00, m01[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -5.10949091314880e+00, m01[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.08286277145113e+00, m02[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.10949091314880e+00, m02[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.52537436025689e+01, m03[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -3.57234787161818e+00, m03[1], 1e-12) ); + TEST_CHECK(gkyl_compare(1.52537436025689e+01, m00[0], 1e-12)); + TEST_CHECK(gkyl_compare(3.57234787161818e+00, m00[1], 1e-12)); + TEST_CHECK(gkyl_compare(6.08286277145113e+00, m01[0], 1e-12)); + TEST_CHECK(gkyl_compare(-5.10949091314880e+00, m01[1], 1e-12)); + TEST_CHECK(gkyl_compare(6.08286277145113e+00, m02[0], 1e-12)); + TEST_CHECK(gkyl_compare(5.10949091314880e+00, m02[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.52537436025689e+01, m03[0], 1e-12)); + TEST_CHECK(gkyl_compare(-3.57234787161818e+00, m03[1], 1e-12)); // Check M1. - TEST_CHECK( gkyl_compare( -1.28452577705844e+01, m10[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -3.00829294452057e+00, m10[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -5.12241075490621e+00, m11[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.30272919002004e+00, m11[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -5.12241075490621e+00, m12[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -4.30272919002004e+00, m12[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -1.28452577705844e+01, m13[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.00829294452057e+00, m13[1], 1e-12) ); + TEST_CHECK(gkyl_compare(-1.28452577705844e+01, m10[0], 1e-12)); + TEST_CHECK(gkyl_compare(-3.00829294452057e+00, m10[1], 1e-12)); + TEST_CHECK(gkyl_compare(-5.12241075490621e+00, m11[0], 1e-12)); + TEST_CHECK(gkyl_compare(4.30272919002004e+00, m11[1], 1e-12)); + TEST_CHECK(gkyl_compare(-5.12241075490621e+00, m12[0], 1e-12)); + TEST_CHECK(gkyl_compare(-4.30272919002004e+00, m12[1], 1e-12)); + TEST_CHECK(gkyl_compare(-1.28452577705844e+01, m13[0], 1e-12)); + TEST_CHECK(gkyl_compare(3.00829294452057e+00, m13[1], 1e-12)); // Check M2. - TEST_CHECK( gkyl_compare( 3.31835825740096e+01, m20[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 7.77142344001148e+00, m20[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.32328944501744e+01, m21[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -1.11153837408851e+01, m21[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.32328944501744e+01, m22[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.11153837408851e+01, m22[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.31835825740096e+01, m23[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -7.77142344001148e+00, m23[1], 1e-12) ); - } else if (poly_order==2) { - double m0Correct[] = { - 1.526837339934706e+01, 3.951518219554417e+00, -3.363344534446567e+00, - 6.052510010088350e+00, -4.868229034295940e+00, 8.480389975048731e-01, - 6.052510010088350e+00, 4.868229034295939e+00, 8.480389975048728e-01, - 1.526837339934706e+01, -3.951518219554418e+00, -3.363344534446568e+00 - }; - double m1Correct[] = { - -1.285757759945016e+01, -3.327594290151089e+00, 2.832290134270792e+00, - -5.096850534811242e+00, 4.099561292038686e+00, -7.141381031619991e-01, - -5.096850534811242e+00, -4.099561292038685e+00, -7.141381031619988e-01, - -1.285757759945016e+01, 3.327594290151089e+00, 2.832290134270792e+00 - }; - double m2Correct[] = { - 3.407258063854292e+01, 8.818124868900387e+00, -7.316749513532877e+00, - 1.350665391724979e+01, -1.086383742390252e+01, 1.844856766501832e+00, - 1.350665391724979e+01, 1.086383742390252e+01, 1.844856766501832e+00, - 3.407258063854292e+01, -8.818124868900387e+00, -7.316749513532877e+00 - }; + TEST_CHECK(gkyl_compare(3.31835825740096e+01, m20[0], 1e-12)); + TEST_CHECK(gkyl_compare(7.77142344001148e+00, m20[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.32328944501744e+01, m21[0], 1e-12)); + TEST_CHECK(gkyl_compare(-1.11153837408851e+01, m21[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.32328944501744e+01, m22[0], 1e-12)); + TEST_CHECK(gkyl_compare(1.11153837408851e+01, m22[1], 1e-12)); + TEST_CHECK(gkyl_compare(3.31835825740096e+01, m23[0], 1e-12)); + TEST_CHECK(gkyl_compare(-7.77142344001148e+00, m23[1], 1e-12)); + } else if (poly_order == 2) { + double m0Correct[] = {1.526837339934706e+01, 3.951518219554417e+00, -3.363344534446567e+00, + 6.052510010088350e+00, -4.868229034295940e+00, 8.480389975048731e-01, + 6.052510010088350e+00, 4.868229034295939e+00, 8.480389975048728e-01, + 1.526837339934706e+01, -3.951518219554418e+00, -3.363344534446568e+00}; + double m1Correct[] = {-1.285757759945016e+01, -3.327594290151089e+00, 2.832290134270792e+00, + -5.096850534811242e+00, 4.099561292038686e+00, -7.141381031619991e-01, + -5.096850534811242e+00, -4.099561292038685e+00, -7.141381031619988e-01, + -1.285757759945016e+01, 3.327594290151089e+00, 2.832290134270792e+00}; + double m2Correct[] = {3.407258063854292e+01, 8.818124868900387e+00, -7.316749513532877e+00, + 1.350665391724979e+01, -1.086383742390252e+01, 1.844856766501832e+00, + 1.350665391724979e+01, 1.086383742390252e+01, 1.844856766501832e+00, + 3.407258063854292e+01, -8.818124868900387e+00, -7.316749513532877e+00}; // Check M0. - TEST_CHECK( gkyl_compare( m0Correct[0 ], m00[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m0Correct[1 ], m00[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m0Correct[2 ], m00[2], 1e-12) ); - TEST_CHECK( gkyl_compare( m0Correct[3 ], m01[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m0Correct[4 ], m01[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m0Correct[5 ], m01[2], 1e-12) ); - TEST_CHECK( gkyl_compare( m0Correct[6 ], m02[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m0Correct[7 ], m02[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m0Correct[8 ], m02[2], 1e-12) ); - TEST_CHECK( gkyl_compare( m0Correct[9 ], m03[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m0Correct[10], m03[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m0Correct[11], m03[2], 1e-12) ); + TEST_CHECK(gkyl_compare(m0Correct[0], m00[0], 1e-12)); + TEST_CHECK(gkyl_compare(m0Correct[1], m00[1], 1e-12)); + TEST_CHECK(gkyl_compare(m0Correct[2], m00[2], 1e-12)); + TEST_CHECK(gkyl_compare(m0Correct[3], m01[0], 1e-12)); + TEST_CHECK(gkyl_compare(m0Correct[4], m01[1], 1e-12)); + TEST_CHECK(gkyl_compare(m0Correct[5], m01[2], 1e-12)); + TEST_CHECK(gkyl_compare(m0Correct[6], m02[0], 1e-12)); + TEST_CHECK(gkyl_compare(m0Correct[7], m02[1], 1e-12)); + TEST_CHECK(gkyl_compare(m0Correct[8], m02[2], 1e-12)); + TEST_CHECK(gkyl_compare(m0Correct[9], m03[0], 1e-12)); + TEST_CHECK(gkyl_compare(m0Correct[10], m03[1], 1e-12)); + TEST_CHECK(gkyl_compare(m0Correct[11], m03[2], 1e-12)); // Check M1. - TEST_CHECK( gkyl_compare( m1Correct[0 ], m10[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m1Correct[1 ], m10[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m1Correct[2 ], m10[2], 1e-12) ); - TEST_CHECK( gkyl_compare( m1Correct[3 ], m11[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m1Correct[4 ], m11[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m1Correct[5 ], m11[2], 1e-12) ); - TEST_CHECK( gkyl_compare( m1Correct[6 ], m12[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m1Correct[7 ], m12[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m1Correct[8 ], m12[2], 1e-12) ); - TEST_CHECK( gkyl_compare( m1Correct[9 ], m13[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m1Correct[10], m13[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m1Correct[11], m13[2], 1e-12) ); + TEST_CHECK(gkyl_compare(m1Correct[0], m10[0], 1e-12)); + TEST_CHECK(gkyl_compare(m1Correct[1], m10[1], 1e-12)); + TEST_CHECK(gkyl_compare(m1Correct[2], m10[2], 1e-12)); + TEST_CHECK(gkyl_compare(m1Correct[3], m11[0], 1e-12)); + TEST_CHECK(gkyl_compare(m1Correct[4], m11[1], 1e-12)); + TEST_CHECK(gkyl_compare(m1Correct[5], m11[2], 1e-12)); + TEST_CHECK(gkyl_compare(m1Correct[6], m12[0], 1e-12)); + TEST_CHECK(gkyl_compare(m1Correct[7], m12[1], 1e-12)); + TEST_CHECK(gkyl_compare(m1Correct[8], m12[2], 1e-12)); + TEST_CHECK(gkyl_compare(m1Correct[9], m13[0], 1e-12)); + TEST_CHECK(gkyl_compare(m1Correct[10], m13[1], 1e-12)); + TEST_CHECK(gkyl_compare(m1Correct[11], m13[2], 1e-12)); // Check M2. - TEST_CHECK( gkyl_compare( m2Correct[0 ], m20[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m2Correct[1 ], m20[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m2Correct[2 ], m20[2], 1e-12) ); - TEST_CHECK( gkyl_compare( m2Correct[3 ], m21[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m2Correct[4 ], m21[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m2Correct[5 ], m21[2], 1e-12) ); - TEST_CHECK( gkyl_compare( m2Correct[6 ], m22[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m2Correct[7 ], m22[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m2Correct[8 ], m22[2], 1e-12) ); - TEST_CHECK( gkyl_compare( m2Correct[9 ], m23[0], 1e-12) ); - TEST_CHECK( gkyl_compare( m2Correct[10], m23[1], 1e-12) ); - TEST_CHECK( gkyl_compare( m2Correct[11], m23[2], 1e-12) ); + TEST_CHECK(gkyl_compare(m2Correct[0], m20[0], 1e-12)); + TEST_CHECK(gkyl_compare(m2Correct[1], m20[1], 1e-12)); + TEST_CHECK(gkyl_compare(m2Correct[2], m20[2], 1e-12)); + TEST_CHECK(gkyl_compare(m2Correct[3], m21[0], 1e-12)); + TEST_CHECK(gkyl_compare(m2Correct[4], m21[1], 1e-12)); + TEST_CHECK(gkyl_compare(m2Correct[5], m21[2], 1e-12)); + TEST_CHECK(gkyl_compare(m2Correct[6], m22[0], 1e-12)); + TEST_CHECK(gkyl_compare(m2Correct[7], m22[1], 1e-12)); + TEST_CHECK(gkyl_compare(m2Correct[8], m22[2], 1e-12)); + TEST_CHECK(gkyl_compare(m2Correct[9], m23[0], 1e-12)); + TEST_CHECK(gkyl_compare(m2Correct[10], m23[1], 1e-12)); + TEST_CHECK(gkyl_compare(m2Correct[11], m23[2], 1e-12)); } - gkyl_gk_geometry_release(gk_geom); + gkyl_gk_geometry_release(gk_geom); // release memory for moment data object - gkyl_array_release(m0); gkyl_array_release(m1); gkyl_array_release(m2); - gkyl_array_release(m0_ho); gkyl_array_release(m1_ho); gkyl_array_release(m2_ho); - gkyl_mom_calc_release(m0calc); gkyl_mom_calc_release(m1calc); gkyl_mom_calc_release(m2calc); - gkyl_mom_type_release(M0_t); gkyl_mom_type_release(M1_t); gkyl_mom_type_release(M2_t); + gkyl_array_release(m0); + gkyl_array_release(m1); + gkyl_array_release(m2); + gkyl_array_release(m0_ho); + gkyl_array_release(m1_ho); + gkyl_array_release(m2_ho); + gkyl_mom_calc_release(m0calc); + gkyl_mom_calc_release(m1calc); + gkyl_mom_calc_release(m2calc); + gkyl_mom_type_release(M0_t); + gkyl_mom_type_release(M1_t); + gkyl_mom_type_release(M2_t); gkyl_proj_on_basis_release(projDistf); - gkyl_array_release(distf); gkyl_array_release(distf_ho); + gkyl_array_release(distf); + gkyl_array_release(distf_ho); gkyl_velocity_map_release(gvm); gkyl_position_map_release(pmap); } -void -test_1x2v(int poly_order, bool use_gpu) +void test_1x2v(int poly_order, bool use_gpu) { double mass = 1.0; double charge = 1.0; @@ -450,22 +478,22 @@ test_1x2v(int poly_order, bool use_gpu) int cells[] = {4, 2, 2}; int vdim = 2; - int ndim = sizeof(cells)/sizeof(cells[0]); + int ndim = sizeof(cells) / sizeof(cells[0]); int cdim = ndim - vdim; double confLower[cdim], confUpper[cdim]; int confCells[cdim]; - for (int d=0; dncomp, distf->size) : gkyl_array_acquire(distf); - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, distf_1x2v, NULL); + distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : gkyl_array_acquire(distf); + gkyl_proj_on_basis *projDistf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, distf_1x2v, NULL); gkyl_proj_on_basis_advance(projDistf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); @@ -513,26 +543,34 @@ test_1x2v(int poly_order, bool use_gpu) // Initialize geometry struct gkyl_gk_geometry_inp geometry_input = { .geometry_id = GKYL_GEOMETRY_MAPC2P, - .world = {0.0, 0.0}, .mapc2p = mapc2p_3x, .c2p_ctx = 0, - .bfield_func = bfield_func_3x, .bfield_ctx = 0, - .basis = confBasis, .grid = confGrid, - .local = confLocal, .local_ext = confLocal_ext, - .global = confLocal, .global_ext = confLocal_ext, - .position_map = pmap, + .world = {0.0, 0.0}, + .mapc2p = mapc2p_3x, + .c2p_ctx = 0, + .bfield_func = bfield_func_3x, + .bfield_ctx = 0, + .basis = confBasis, + .grid = confGrid, + .local = confLocal, + .local_ext = confLocal_ext, + .global = confLocal, + .global_ext = confLocal_ext, + .position_map = pmap }; int geo_ghost[3] = {1, 1, 1}; geometry_input.geo_grid = gkyl_gk_geometry_augment_grid(confGrid, geometry_input); gkyl_cart_modal_serendip(&geometry_input.geo_basis, 3, poly_order); - gkyl_create_grid_ranges(&geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global); + gkyl_create_grid_ranges( + &geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global + ); memcpy(&geometry_input.geo_local, &geometry_input.geo_global, sizeof(struct gkyl_range)); memcpy(&geometry_input.geo_local_ext, &geometry_input.geo_global_ext, sizeof(struct gkyl_range)); // Deflate geometry. - struct gk_geometry* gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); + struct gk_geometry *gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); struct gk_geometry *gk_geom = gkyl_gk_geometry_deflate(gk_geom_3d, &geometry_input); gkyl_gk_geometry_release(gk_geom_3d); // If we are on the gpu, copy from host. if (use_gpu) { - struct gk_geometry* gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); + struct gk_geometry *gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); gkyl_gk_geometry_release(gk_geom); gk_geom = gkyl_gk_geometry_acquire(gk_geom_dev); gkyl_gk_geometry_release(gk_geom_dev); @@ -540,20 +578,26 @@ test_1x2v(int poly_order, bool use_gpu) // If we are on the gpu, copy from host if (use_gpu) { - struct gk_geometry* gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); + struct gk_geometry *gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); gkyl_gk_geometry_release(gk_geom); gk_geom = gkyl_gk_geometry_acquire(gk_geom_dev); gkyl_gk_geometry_release(gk_geom_dev); } // Initialize velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, grid, velGrid, - local, local_ext, velLocal, velLocal_ext, use_gpu); - - struct gkyl_mom_type *M0_t = gkyl_mom_gyrokinetic_new(&confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0, use_gpu); - struct gkyl_mom_type *M1_t = gkyl_mom_gyrokinetic_new(&confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M1, use_gpu); - struct gkyl_mom_type *M2_t = gkyl_mom_gyrokinetic_new(&confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M2, use_gpu); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, velGrid, local, local_ext, velLocal, velLocal_ext, use_gpu); + + struct gkyl_mom_type *M0_t = gkyl_mom_gyrokinetic_new( + &confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0, use_gpu + ); + struct gkyl_mom_type *M1_t = gkyl_mom_gyrokinetic_new( + &confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M1, use_gpu + ); + struct gkyl_mom_type *M2_t = gkyl_mom_gyrokinetic_new( + &confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M2, use_gpu + ); gkyl_mom_calc *m0calc = gkyl_mom_calc_new(&grid, M0_t, use_gpu); gkyl_mom_calc *m1calc = gkyl_mom_calc_new(&grid, M1_t, use_gpu); gkyl_mom_calc *m2calc = gkyl_mom_calc_new(&grid, M2_t, use_gpu); @@ -563,9 +607,9 @@ test_1x2v(int poly_order, bool use_gpu) m0 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); m1 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); - m0_ho = use_gpu? mkarr(false, m0->ncomp, m0->size) : gkyl_array_acquire(m0); - m1_ho = use_gpu? mkarr(false, m1->ncomp, m1->size) : gkyl_array_acquire(m1); - m2_ho = use_gpu? mkarr(false, m2->ncomp, m2->size) : gkyl_array_acquire(m2); + m0_ho = use_gpu ? mkarr(false, m0->ncomp, m0->size) : gkyl_array_acquire(m0); + m1_ho = use_gpu ? mkarr(false, m1->ncomp, m1->size) : gkyl_array_acquire(m1); + m2_ho = use_gpu ? mkarr(false, m2->ncomp, m2->size) : gkyl_array_acquire(m2); // compute the moments if (use_gpu) { @@ -581,102 +625,115 @@ test_1x2v(int poly_order, bool use_gpu) gkyl_array_copy(m1_ho, m1); gkyl_array_copy(m2_ho, m2); - double *m00 = gkyl_array_fetch(m0_ho, gkyl_range_idx(&confLocal, &(int) {0+confGhost[0]})); - double *m01 = gkyl_array_fetch(m0_ho, gkyl_range_idx(&confLocal, &(int) {1+confGhost[0]})); - double *m02 = gkyl_array_fetch(m0_ho, 2+confGhost[0]); double *m03 = gkyl_array_fetch(m0_ho, 3+confGhost[0]); - double *m10 = gkyl_array_fetch(m1_ho, 0+confGhost[0]); double *m11 = gkyl_array_fetch(m1_ho, 1+confGhost[0]); - double *m12 = gkyl_array_fetch(m1_ho, 2+confGhost[0]); double *m13 = gkyl_array_fetch(m1_ho, 3+confGhost[0]); - double *m20 = gkyl_array_fetch(m2_ho, 0+confGhost[0]); double *m21 = gkyl_array_fetch(m2_ho, 1+confGhost[0]); - double *m22 = gkyl_array_fetch(m2_ho, 2+confGhost[0]); double *m23 = gkyl_array_fetch(m2_ho, 3+confGhost[0]); - if (poly_order==1) { + double *m00 = gkyl_array_fetch(m0_ho, gkyl_range_idx(&confLocal, &(int){0 + confGhost[0]})); + double *m01 = gkyl_array_fetch(m0_ho, gkyl_range_idx(&confLocal, &(int){1 + confGhost[0]})); + double *m02 = gkyl_array_fetch(m0_ho, 2 + confGhost[0]); + double *m03 = gkyl_array_fetch(m0_ho, 3 + confGhost[0]); + double *m10 = gkyl_array_fetch(m1_ho, 0 + confGhost[0]); + double *m11 = gkyl_array_fetch(m1_ho, 1 + confGhost[0]); + double *m12 = gkyl_array_fetch(m1_ho, 2 + confGhost[0]); + double *m13 = gkyl_array_fetch(m1_ho, 3 + confGhost[0]); + double *m20 = gkyl_array_fetch(m2_ho, 0 + confGhost[0]); + double *m21 = gkyl_array_fetch(m2_ho, 1 + confGhost[0]); + double *m22 = gkyl_array_fetch(m2_ho, 2 + confGhost[0]); + double *m23 = gkyl_array_fetch(m2_ho, 3 + confGhost[0]); + if (poly_order == 1) { // Check M0. - TEST_CHECK( gkyl_compare( 191.6841953662915, m00[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 44.89144731817122, m00[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 76.4395079823428, m01[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -64.2077564653283, m01[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 76.43950798234282, m02[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 64.20775646532829, m02[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 191.68419536629153, m03[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -44.89144731817124, m03[1], 1e-12) ); - + TEST_CHECK(gkyl_compare(191.6841953662915, m00[0], 1e-12)); + TEST_CHECK(gkyl_compare(44.89144731817122, m00[1], 1e-12)); + TEST_CHECK(gkyl_compare(76.4395079823428, m01[0], 1e-12)); + TEST_CHECK(gkyl_compare(-64.2077564653283, m01[1], 1e-12)); + TEST_CHECK(gkyl_compare(76.43950798234282, m02[0], 1e-12)); + TEST_CHECK(gkyl_compare(64.20775646532829, m02[1], 1e-12)); + TEST_CHECK(gkyl_compare(191.68419536629153, m03[0], 1e-12)); + TEST_CHECK(gkyl_compare(-44.89144731817124, m03[1], 1e-12)); + // Check M1. - TEST_CHECK( gkyl_compare( -161.41826978214021, m10[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -37.80332405740736, m10[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -64.37011198513079, m11[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 54.069689655013306, m11[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -64.37011198513079, m12[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -54.06968965501329, m12[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -161.41826978214021, m13[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 37.80332405740738, m13[1], 1e-12) ); - + TEST_CHECK(gkyl_compare(-161.41826978214021, m10[0], 1e-12)); + TEST_CHECK(gkyl_compare(-37.80332405740736, m10[1], 1e-12)); + TEST_CHECK(gkyl_compare(-64.37011198513079, m11[0], 1e-12)); + TEST_CHECK(gkyl_compare(54.069689655013306, m11[1], 1e-12)); + TEST_CHECK(gkyl_compare(-64.37011198513079, m12[0], 1e-12)); + TEST_CHECK(gkyl_compare(-54.06968965501329, m12[1], 1e-12)); + TEST_CHECK(gkyl_compare(-161.41826978214021, m13[0], 1e-12)); + TEST_CHECK(gkyl_compare(37.80332405740738, m13[1], 1e-12)); + // Check M2. - TEST_CHECK( gkyl_compare( 798.6216162040179, m20[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 187.0330526857825, m20[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 318.4730138551306, m21[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -267.5113727722169, m21[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 318.4730138551307, m22[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 267.5113727722168, m22[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 798.6216162040179, m23[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -187.0330526857825, m23[1], 1e-12) ); - } else if (poly_order==2) { + TEST_CHECK(gkyl_compare(798.6216162040179, m20[0], 1e-12)); + TEST_CHECK(gkyl_compare(187.0330526857825, m20[1], 1e-12)); + TEST_CHECK(gkyl_compare(318.4730138551306, m21[0], 1e-12)); + TEST_CHECK(gkyl_compare(-267.5113727722169, m21[1], 1e-12)); + TEST_CHECK(gkyl_compare(318.4730138551307, m22[0], 1e-12)); + TEST_CHECK(gkyl_compare(267.5113727722168, m22[1], 1e-12)); + TEST_CHECK(gkyl_compare(798.6216162040179, m23[0], 1e-12)); + TEST_CHECK(gkyl_compare(-187.0330526857825, m23[1], 1e-12)); + } else if (poly_order == 2) { // Check M0. - TEST_CHECK( gkyl_compare( 1.918680388146181e+02, m00[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.965624243631351e+01, m00[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -4.226503392363477e+01, m00[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 7.605808393388897e+01, m01[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -6.117597028054660e+01, m01[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.065677233807588e+01, m01[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 7.605808393388898e+01, m02[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.117597028054661e+01, m02[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.065677233807589e+01, m02[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 1.918680388146182e+02, m03[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -4.965624243631353e+01, m03[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -4.226503392363478e+01, m03[2], 1e-12) ); - + TEST_CHECK(gkyl_compare(1.918680388146181e+02, m00[0], 1e-12)); + TEST_CHECK(gkyl_compare(4.965624243631351e+01, m00[1], 1e-12)); + TEST_CHECK(gkyl_compare(-4.226503392363477e+01, m00[2], 1e-12)); + TEST_CHECK(gkyl_compare(7.605808393388897e+01, m01[0], 1e-12)); + TEST_CHECK(gkyl_compare(-6.117597028054660e+01, m01[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.065677233807588e+01, m01[2], 1e-12)); + TEST_CHECK(gkyl_compare(7.605808393388898e+01, m02[0], 1e-12)); + TEST_CHECK(gkyl_compare(6.117597028054661e+01, m02[1], 1e-12)); + TEST_CHECK(gkyl_compare(1.065677233807589e+01, m02[2], 1e-12)); + TEST_CHECK(gkyl_compare(1.918680388146182e+02, m03[0], 1e-12)); + TEST_CHECK(gkyl_compare(-4.965624243631353e+01, m03[1], 1e-12)); + TEST_CHECK(gkyl_compare(-4.226503392363478e+01, m03[2], 1e-12)); + // Check M1. - TEST_CHECK( gkyl_compare( -1.615730853175732e+02, m10[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -4.181578310426401e+01, m10[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.559160751463980e+01, m10[2], 1e-12) ); - TEST_CHECK( gkyl_compare( -6.404891278643279e+01, m11[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.151660655203925e+01, m11[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -8.974124074169159e+00, m11[2], 1e-12) ); - TEST_CHECK( gkyl_compare( -6.404891278643282e+01, m12[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -5.151660655203925e+01, m12[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -8.974124074169165e+00, m12[2], 1e-12) ); - TEST_CHECK( gkyl_compare( -1.615730853175732e+02, m13[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.181578310426401e+01, m13[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.559160751463981e+01, m13[2], 1e-12) ); - + TEST_CHECK(gkyl_compare(-1.615730853175732e+02, m10[0], 1e-12)); + TEST_CHECK(gkyl_compare(-4.181578310426401e+01, m10[1], 1e-12)); + TEST_CHECK(gkyl_compare(3.559160751463980e+01, m10[2], 1e-12)); + TEST_CHECK(gkyl_compare(-6.404891278643279e+01, m11[0], 1e-12)); + TEST_CHECK(gkyl_compare(5.151660655203925e+01, m11[1], 1e-12)); + TEST_CHECK(gkyl_compare(-8.974124074169159e+00, m11[2], 1e-12)); + TEST_CHECK(gkyl_compare(-6.404891278643282e+01, m12[0], 1e-12)); + TEST_CHECK(gkyl_compare(-5.151660655203925e+01, m12[1], 1e-12)); + TEST_CHECK(gkyl_compare(-8.974124074169165e+00, m12[2], 1e-12)); + TEST_CHECK(gkyl_compare(-1.615730853175732e+02, m13[0], 1e-12)); + TEST_CHECK(gkyl_compare(4.181578310426401e+01, m13[1], 1e-12)); + TEST_CHECK(gkyl_compare(3.559160751463981e+01, m13[2], 1e-12)); + // Check M2. - TEST_CHECK( gkyl_compare( 8.1190475372078379e+02, m20[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.1012431009892106e+02, m20[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -1.7647505392675140e+02, m20[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.2184578675181643e+02, m21[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -2.5887094792399040e+02, m21[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.4496698534420823e+01, m21[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 3.2184578675181643e+02, m22[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.5887094792399046e+02, m22[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 4.4496698534420837e+01, m22[2], 1e-12) ); - TEST_CHECK( gkyl_compare( 8.1190475372078390e+02, m23[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -2.1012431009892100e+02, m23[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -1.7647505392675134e+02, m23[2], 1e-12) ); + TEST_CHECK(gkyl_compare(8.1190475372078379e+02, m20[0], 1e-12)); + TEST_CHECK(gkyl_compare(2.1012431009892106e+02, m20[1], 1e-12)); + TEST_CHECK(gkyl_compare(-1.7647505392675140e+02, m20[2], 1e-12)); + TEST_CHECK(gkyl_compare(3.2184578675181643e+02, m21[0], 1e-12)); + TEST_CHECK(gkyl_compare(-2.5887094792399040e+02, m21[1], 1e-12)); + TEST_CHECK(gkyl_compare(4.4496698534420823e+01, m21[2], 1e-12)); + TEST_CHECK(gkyl_compare(3.2184578675181643e+02, m22[0], 1e-12)); + TEST_CHECK(gkyl_compare(2.5887094792399046e+02, m22[1], 1e-12)); + TEST_CHECK(gkyl_compare(4.4496698534420837e+01, m22[2], 1e-12)); + TEST_CHECK(gkyl_compare(8.1190475372078390e+02, m23[0], 1e-12)); + TEST_CHECK(gkyl_compare(-2.1012431009892100e+02, m23[1], 1e-12)); + TEST_CHECK(gkyl_compare(-1.7647505392675134e+02, m23[2], 1e-12)); } - gkyl_gk_geometry_release(gk_geom); + gkyl_gk_geometry_release(gk_geom); // release memory for moment data object - gkyl_array_release(m0); gkyl_array_release(m1); gkyl_array_release(m2); - gkyl_array_release(m0_ho); gkyl_array_release(m1_ho); gkyl_array_release(m2_ho); - gkyl_mom_calc_release(m0calc); gkyl_mom_calc_release(m1calc); gkyl_mom_calc_release(m2calc); - gkyl_mom_type_release(M0_t); gkyl_mom_type_release(M1_t); gkyl_mom_type_release(M2_t); + gkyl_array_release(m0); + gkyl_array_release(m1); + gkyl_array_release(m2); + gkyl_array_release(m0_ho); + gkyl_array_release(m1_ho); + gkyl_array_release(m2_ho); + gkyl_mom_calc_release(m0calc); + gkyl_mom_calc_release(m1calc); + gkyl_mom_calc_release(m2calc); + gkyl_mom_type_release(M0_t); + gkyl_mom_type_release(M1_t); + gkyl_mom_type_release(M2_t); gkyl_proj_on_basis_release(projDistf); - gkyl_array_release(distf); gkyl_array_release(distf_ho); + gkyl_array_release(distf); + gkyl_array_release(distf_ho); gkyl_velocity_map_release(gvm); gkyl_position_map_release(pmap); } -void -test_2x2v(int poly_order, bool use_gpu) +void test_2x2v(int poly_order, bool use_gpu) { double mass = 1.; double charge = 1.0; @@ -684,22 +741,22 @@ test_2x2v(int poly_order, bool use_gpu) int cells[] = {4, 4, 2, 2}; int vdim = 2; - int ndim = sizeof(cells)/sizeof(cells[0]); + int ndim = sizeof(cells) / sizeof(cells[0]); int cdim = ndim - vdim; double confLower[cdim], confUpper[cdim]; int confCells[cdim]; - for (int d=0; dncomp, distf->size) : gkyl_array_acquire(distf); - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, distf_2x2v, NULL); + distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : gkyl_array_acquire(distf); + gkyl_proj_on_basis *projDistf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, distf_2x2v, NULL); gkyl_proj_on_basis_advance(projDistf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); @@ -747,26 +806,34 @@ test_2x2v(int poly_order, bool use_gpu) // Initialize geometry struct gkyl_gk_geometry_inp geometry_input = { .geometry_id = GKYL_GEOMETRY_MAPC2P, - .world = {0.0, 0.0}, .mapc2p = mapc2p_3x, .c2p_ctx = 0, - .bfield_func = bfield_func_3x, .bfield_ctx = 0, - .basis = confBasis, .grid = confGrid, - .local = confLocal, .local_ext = confLocal_ext, - .global = confLocal, .global_ext = confLocal_ext, - .position_map = pmap, + .world = {0.0, 0.0}, + .mapc2p = mapc2p_3x, + .c2p_ctx = 0, + .bfield_func = bfield_func_3x, + .bfield_ctx = 0, + .basis = confBasis, + .grid = confGrid, + .local = confLocal, + .local_ext = confLocal_ext, + .global = confLocal, + .global_ext = confLocal_ext, + .position_map = pmap }; int geo_ghost[3] = {1, 1, 1}; geometry_input.geo_grid = gkyl_gk_geometry_augment_grid(confGrid, geometry_input); gkyl_cart_modal_serendip(&geometry_input.geo_basis, 3, poly_order); - gkyl_create_grid_ranges(&geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global); + gkyl_create_grid_ranges( + &geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global + ); memcpy(&geometry_input.geo_local, &geometry_input.geo_global, sizeof(struct gkyl_range)); memcpy(&geometry_input.geo_local_ext, &geometry_input.geo_global_ext, sizeof(struct gkyl_range)); // Deflate geometry. - struct gk_geometry* gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); + struct gk_geometry *gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); struct gk_geometry *gk_geom = gkyl_gk_geometry_deflate(gk_geom_3d, &geometry_input); gkyl_gk_geometry_release(gk_geom_3d); // If we are on the gpu, copy from host. if (use_gpu) { - struct gk_geometry* gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); + struct gk_geometry *gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); gkyl_gk_geometry_release(gk_geom); gk_geom = gkyl_gk_geometry_acquire(gk_geom_dev); gkyl_gk_geometry_release(gk_geom_dev); @@ -774,20 +841,26 @@ test_2x2v(int poly_order, bool use_gpu) // If we are on the gpu, copy from host if (use_gpu) { - struct gk_geometry* gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); + struct gk_geometry *gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); gkyl_gk_geometry_release(gk_geom); gk_geom = gkyl_gk_geometry_acquire(gk_geom_dev); gkyl_gk_geometry_release(gk_geom_dev); } // Initialize velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, grid, velGrid, - local, local_ext, velLocal, velLocal_ext, use_gpu); - - struct gkyl_mom_type *M0_t = gkyl_mom_gyrokinetic_new(&confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0, use_gpu); - struct gkyl_mom_type *M1_t = gkyl_mom_gyrokinetic_new(&confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M1, use_gpu); - struct gkyl_mom_type *M2_t = gkyl_mom_gyrokinetic_new(&confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M2, use_gpu); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, velGrid, local, local_ext, velLocal, velLocal_ext, use_gpu); + + struct gkyl_mom_type *M0_t = gkyl_mom_gyrokinetic_new( + &confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0, use_gpu + ); + struct gkyl_mom_type *M1_t = gkyl_mom_gyrokinetic_new( + &confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M1, use_gpu + ); + struct gkyl_mom_type *M2_t = gkyl_mom_gyrokinetic_new( + &confBasis, &basis, &confLocal, mass, charge, gvm, gk_geom, NULL, GKYL_F_MOMENT_M2, use_gpu + ); gkyl_mom_calc *m0calc = gkyl_mom_calc_new(&grid, M0_t, use_gpu); gkyl_mom_calc *m1calc = gkyl_mom_calc_new(&grid, M1_t, use_gpu); gkyl_mom_calc *m2calc = gkyl_mom_calc_new(&grid, M2_t, use_gpu); @@ -797,9 +870,9 @@ test_2x2v(int poly_order, bool use_gpu) m0 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); m1 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); - m0_ho = use_gpu? mkarr(false, m0->ncomp, m0->size) : gkyl_array_acquire(m0); - m1_ho = use_gpu? mkarr(false, m1->ncomp, m1->size) : gkyl_array_acquire(m1); - m2_ho = use_gpu? mkarr(false, m2->ncomp, m2->size) : gkyl_array_acquire(m2); + m0_ho = use_gpu ? mkarr(false, m0->ncomp, m0->size) : gkyl_array_acquire(m0); + m1_ho = use_gpu ? mkarr(false, m1->ncomp, m1->size) : gkyl_array_acquire(m1); + m2_ho = use_gpu ? mkarr(false, m2->ncomp, m2->size) : gkyl_array_acquire(m2); // compute the moments if (use_gpu) { @@ -815,210 +888,343 @@ test_2x2v(int poly_order, bool use_gpu) gkyl_array_copy(m1_ho, m1); gkyl_array_copy(m2_ho, m2); - if (poly_order==1) { + if (poly_order == 1) { double m0Correct[] = { - 5.674373976691270e+01, 2.201144875962325e+01, 3.651966323006221e+01, 1.314016650990054e+01, - 2.219569636062632e+02, 6.028640616624954e+01, 4.206235100555175e+01, 3.552942178215428e+00, - 2.219569636062633e+02, 6.028640616624952e+01, -4.206235100555176e+01, -3.552942178215411e+00, - 5.674373976691270e+01, 2.201144875962326e+01, -3.651966323006221e+01, -1.314016650990054e+01, - 7.709667278852976e+01, -3.719961743450785e+00, 4.321049456829391e+01, -4.192642488321794e+00, - 1.403753088009537e+02, -5.979190987388544e+01, -2.255457479022396e+01, -2.512741619288884e+01, - 1.403753088009537e+02, -5.979190987388544e+01, 2.255457479022397e+01, 2.512741619288884e+01, - 7.709667278852976e+01, -3.719961743450784e+00, -4.321049456829390e+01, 4.192642488321796e+00, - 7.709667278852976e+01, 3.719961743450789e+00, 4.321049456829391e+01, 4.192642488321798e+00, - 1.403753088009537e+02, 5.979190987388544e+01, -2.255457479022396e+01, 2.512741619288883e+01, - 1.403753088009538e+02, 5.979190987388544e+01, 2.255457479022397e+01, -2.512741619288886e+01, - 7.709667278852974e+01, 3.719961743450781e+00, -4.321049456829391e+01, -4.192642488321795e+00, - 5.674373976691270e+01, -2.201144875962325e+01, 3.651966323006221e+01, -1.314016650990054e+01, - 2.219569636062632e+02, -6.028640616624953e+01, 4.206235100555175e+01, -3.552942178215412e+00, - 2.219569636062632e+02, -6.028640616624953e+01, -4.206235100555175e+01, 3.552942178215411e+00, - 5.674373976691268e+01, -2.201144875962326e+01, -3.651966323006221e+01, 1.314016650990054e+01 + 5.674373976691270e+01, 2.201144875962325e+01, 3.651966323006221e+01, 1.314016650990054e+01, + 2.219569636062632e+02, 6.028640616624954e+01, 4.206235100555175e+01, 3.552942178215428e+00, + 2.219569636062633e+02, 6.028640616624952e+01, -4.206235100555176e+01, -3.552942178215411e+00, + 5.674373976691270e+01, 2.201144875962326e+01, -3.651966323006221e+01, -1.314016650990054e+01, + 7.709667278852976e+01, -3.719961743450785e+00, 4.321049456829391e+01, -4.192642488321794e+00, + 1.403753088009537e+02, -5.979190987388544e+01, -2.255457479022396e+01, -2.512741619288884e+01, + 1.403753088009537e+02, -5.979190987388544e+01, 2.255457479022397e+01, 2.512741619288884e+01, + 7.709667278852976e+01, -3.719961743450784e+00, -4.321049456829390e+01, 4.192642488321796e+00, + 7.709667278852976e+01, 3.719961743450789e+00, 4.321049456829391e+01, 4.192642488321798e+00, + 1.403753088009537e+02, 5.979190987388544e+01, -2.255457479022396e+01, 2.512741619288883e+01, + 1.403753088009538e+02, 5.979190987388544e+01, 2.255457479022397e+01, -2.512741619288886e+01, + 7.709667278852974e+01, 3.719961743450781e+00, -4.321049456829391e+01, -4.192642488321795e+00, + 5.674373976691270e+01, -2.201144875962325e+01, 3.651966323006221e+01, -1.314016650990054e+01, + 2.219569636062632e+02, -6.028640616624953e+01, 4.206235100555175e+01, -3.552942178215412e+00, + 2.219569636062632e+02, -6.028640616624953e+01, -4.206235100555175e+01, 3.552942178215411e+00, + 5.674373976691268e+01, -2.201144875962326e+01, -3.651966323006221e+01, 1.314016650990054e+01 }; - double m1Correct[] = { - -4.778420190897913e+01, -1.853595685020905e+01, -3.075340061478923e+01, -1.106540337675835e+01, - -1.869111272473795e+02, -5.076749992947330e+01, -3.542092716256990e+01, -2.991951307970891e+00, - -1.869111272473796e+02, -5.076749992947327e+01, 3.542092716256991e+01, 2.991951307970870e+00, - -4.778420190897913e+01, -1.853595685020905e+01, 3.075340061478923e+01, 1.106540337675835e+01, - -6.492351392718295e+01, 3.132599362905920e+00, -3.638778489961594e+01, 3.530646305955197e+00, - -1.182107863586978e+02, 5.035108199906144e+01, 1.899332613913597e+01, 2.115992942559060e+01, - -1.182107863586978e+02, 5.035108199906144e+01, -1.899332613913598e+01, -2.115992942559060e+01, - -6.492351392718297e+01, 3.132599362905925e+00, 3.638778489961592e+01, -3.530646305955196e+00, - -6.492351392718297e+01, -3.132599362905928e+00, -3.638778489961594e+01, -3.530646305955196e+00, - -1.182107863586979e+02, -5.035108199906144e+01, 1.899332613913597e+01, -2.115992942559060e+01, - -1.182107863586979e+02, -5.035108199906144e+01, -1.899332613913597e+01, 2.115992942559062e+01, - -6.492351392718295e+01, -3.132599362905919e+00, 3.638778489961592e+01, 3.530646305955196e+00, - -4.778420190897911e+01, 1.853595685020907e+01, -3.075340061478922e+01, 1.106540337675835e+01, - -1.869111272473795e+02, 5.076749992947325e+01, -3.542092716256990e+01, 2.991951307970878e+00, - -1.869111272473796e+02, 5.076749992947332e+01, 3.542092716256988e+01, -2.991951307970872e+00, - -4.778420190897911e+01, 1.853595685020906e+01, 3.075340061478923e+01, -1.106540337675835e+01 - }; - double m2Correct[] = { - 1.7255254110177472e+02, 8.6614534630645736e+01, 1.1063403695082026e+02, 5.2786216315915581e+01, - 6.6441284173393137e+02, 2.6439185237405923e+02, 1.2269711803426455e+02, 2.7413399942981236e+01, - 6.6441284173393137e+02, 2.6439185237405917e+02, -1.2269711803426455e+02, -2.7413399942981226e+01, - 1.7255254110177469e+02, 8.6614534630645750e+01, -1.1063403695082026e+02, -5.2786216315915588e+01, - 2.9870227767186833e+02, -1.4057203507647915e+00, 1.6705772180910421e+02, -8.9711445800787164e+00, - 5.3490257604330156e+02, -2.0840706081732725e+02, -9.1818255893805784e+01, -1.0137235681690159e+02, - 5.3490257604330168e+02, -2.0840706081732725e+02, 9.1818255893805798e+01, 1.0137235681690161e+02, - 2.9870227767186833e+02, -1.4057203507647853e+00, -1.6705772180910421e+02, 8.9711445800787146e+00, - 2.9870227767186833e+02, 1.4057203507648230e+00, 1.6705772180910421e+02, 8.9711445800787146e+00, - 5.3490257604330156e+02, 2.0840706081732725e+02, -9.1818255893805784e+01, 1.0137235681690157e+02, - 5.3490257604330179e+02, 2.0840706081732725e+02, 9.1818255893805798e+01, -1.0137235681690161e+02, - 2.9870227767186839e+02, 1.4057203507648186e+00, -1.6705772180910421e+02, -8.9711445800787182e+00, - 1.7255254110177469e+02, -8.6614534630645764e+01, 1.1063403695082023e+02, -5.2786216315915595e+01, - 6.6441284173393160e+02, -2.6439185237405911e+02, 1.2269711803426458e+02, -2.7413399942981219e+01, - 6.6441284173393137e+02, -2.6439185237405917e+02, -1.2269711803426451e+02, 2.7413399942981194e+01, - 1.7255254110177469e+02, -8.6614534630645736e+01, -1.1063403695082019e+02, 5.2786216315915574e+01 - }; - for (int i=0; i #include - -void check_same(struct gkyl_range range, struct gkyl_basis basis, struct gkyl_array *field1, struct gkyl_array* field2) +void check_same( + struct gkyl_range range, struct gkyl_basis basis, struct gkyl_array *field1, + struct gkyl_array *field2 +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); @@ -21,32 +23,31 @@ void check_same(struct gkyl_range range, struct gkyl_basis basis, struct gkyl_ar long lidx = gkyl_range_idx(&range, iter.idx); const double *f1 = gkyl_array_cfetch(field1, lidx); const double *f2 = gkyl_array_cfetch(field2, lidx); - for(int i = 0; i< basis.num_basis; i++) - TEST_CHECK( gkyl_compare(f1[i], f2[i], 1e-10) ); + for (int i = 0; i < basis.num_basis; i++) { + TEST_CHECK(gkyl_compare(f1[i], f2[i], 1e-10)); + } } } -void -proj_func(double t, const double *xn, double *fout, void *ctx) +void proj_func(double t, const double *xn, double *fout, void *ctx) { - fout[0] = cos(xn[0])*sin(xn[1]); + fout[0] = cos(xn[0]) * sin(xn[1]); } -void -proj_func3d(double t, const double *xn, double *fout, void *ctx) +void proj_func3d(double t, const double *xn, double *fout, void *ctx) { - fout[0] = cos(2*xn[0])*sin(xn[1])*xn[2]*xn[2]*xn[2]; + fout[0] = cos(2 * xn[0]) * sin(xn[1]) * xn[2] * xn[2] * xn[2]; } -void -test_nodal_ops_p1_2x_ho(){ +void test_nodal_ops_p1_2x_ho() +{ // create grid, ranges, basis - double lower[] = { 0.0, -1.5 }, upper[] = { 1.5, 1.5 }; - int cells[] = { 8, 16 }; + double lower[] = {0.0, -1.5}, upper[] = {1.5, 1.5}; + int cells[] = {8, 16}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 2, lower, upper, cells); struct gkyl_range local, local_ext; - int nghost[GKYL_MAX_CDIM] = { 1, 1 }; + int nghost[GKYL_MAX_CDIM] = {1, 1}; gkyl_create_grid_ranges(&grid, nghost, &local_ext, &local); int poly_order = 1; struct gkyl_basis basis; @@ -59,37 +60,39 @@ test_nodal_ops_p1_2x_ho(){ #else struct gkyl_basis *basis_on_dev = &basis; #endif - + // Project initial function struct gkyl_array *funcdg = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); struct gkyl_eval_on_nodes *eon = gkyl_eval_on_nodes_new(&grid, &basis, 1, &proj_func, 0); gkyl_eval_on_nodes_advance(eon, 0.0, &local, funcdg); gkyl_grid_sub_array_write(&grid, &local, 0, funcdg, "proj_func.gkyl"); #ifdef GKYL_HAVE_CUDA - struct gkyl_array *funcdg_dev = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); + struct gkyl_array *funcdg_dev = + gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); gkyl_array_copy(funcdg_dev, funcdg); #else struct gkyl_array *funcdg_dev = funcdg; #endif // Construct nrange and nodal field - int nodes[3] = { 1, 1, 1 }; - for (int d=0; d #include -void -test_nonuniform_position_map(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void test_nonuniform_position_map( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double poly_order = 2; double z = xn[0]; double left = 0.25; double right = 0.75; - if (z < -left) + if (z < -left) { fout[0] = z; - else if (z < right) - fout[0] = - pow(z - right, poly_order)/fabs(pow(left-right, poly_order-1)) + right; - else + } else if (z < right) { + fout[0] = -pow(z - right, poly_order) / fabs(pow(left - right, poly_order - 1)) + right; + } else { fout[0] = z; + } } -void -test_nonuniform_position_map_slope(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void test_nonuniform_position_map_slope( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double poly_order = 2; double z = xn[0]; double left = 0.25; double right = 0.75; - if (z < -left) + if (z < -left) { fout[0] = 1.0; - else if (z < right) - fout[0] = - poly_order * pow(z - right, poly_order-1)/fabs(pow(left-right, poly_order-1)); - else + } else if (z < right) { + fout[0] = + -poly_order * pow(z - right, poly_order - 1) / fabs(pow(left - right, poly_order - 1)); + } else { fout[0] = 1.0; + } } -void -test_identity_position_map(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void test_identity_position_map( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { fout[0] = xn[0]; } -void -test_nonuniform_position_map_3x(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void test_nonuniform_position_map_3x( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double poly_order = 2; double left = 0.25; double right = 0.75; - for (int i = 0; i<3; i++) - { + for (int i = 0; i < 3; i++) { double z = xn[i]; - if (z < -left) + if (z < -left) { fout[i] = z; - else if (z < right) - fout[i] = - pow(z - right, poly_order)/fabs(pow(left-right, poly_order-1)) + right; - else + } else if (z < right) { + fout[i] = -pow(z - right, poly_order) / fabs(pow(left - right, poly_order - 1)) + right; + } else { fout[i] = z; + } } } -void -bmag_func(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) +void bmag_func(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; double s = 0.6; double c = 0.; // double B = (4*pow(s*(x-c),2) - 0.3*pow(s*(x-c),4) + 1)*exp(-pow(s*(x-c),2)); - double B = 1/(1+100*pow(x-M_PI/2,2)) + 1/(1+100*pow(x+M_PI/2,2)); + double B = 1 / (1 + 100 * pow(x - M_PI / 2, 2)) + 1 / (1 + 100 * pow(x + M_PI / 2, 2)); fout[0] = B; } -void -test_position_map_init_1x_ho() +void test_position_map_init_1x_ho() { int cells[] = {32}; int poly_order = 1; double lower[] = {0.0}, upper[] = {1.0}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); // Ranges - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); - + // Basis functions. struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); struct gkyl_position_map_inp pos_map_inp = { - .maps = {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, - .ctxs = {NULL, NULL, NULL}, + .maps = + {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, + .ctxs = {NULL, NULL, NULL} }; - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp, - grid, localRange, localRange_ext, localRange, localRange_ext, basis); + struct gkyl_position_map *pos_map = gkyl_position_map_new( + pos_map_inp, grid, localRange, localRange_ext, localRange, localRange_ext, basis + ); TEST_CHECK(pos_map->to_optimize == 0); TEST_CHECK(pos_map->grid.ndim == 1); @@ -115,33 +122,32 @@ test_position_map_init_1x_ho() gkyl_position_map_release(pos_map); } - -void -test_position_map_init_1x_null_ho() +void test_position_map_init_1x_null_ho() { int cells[] = {8}; int poly_order = 1; double lower[] = {0.0}, upper[] = {1.0}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); // Ranges - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); - + // Basis functions. struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - struct gkyl_position_map_inp pos_map_inp = { }; - - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp, \ - grid, localRange, localRange_ext, localRange, localRange_ext, basis); + struct gkyl_position_map_inp pos_map_inp = {}; + + struct gkyl_position_map *pos_map = gkyl_position_map_new( + pos_map_inp, grid, localRange, localRange_ext, localRange, localRange_ext, basis + ); TEST_CHECK(pos_map->id == GKYL_PMAP_USER_INPUT); - for (double i = 0; i < 1; i = i+0.1){ + for (double i = 0; i < 1; i = i + 0.1) { double x[1] = {i}; double y[1]; pos_map->maps[0](0.0, x, y, pos_map->ctxs[0]); @@ -163,32 +169,33 @@ test_position_map_init_1x_null_ho() gkyl_position_map_release(pos_map); } -void -test_position_map_init_2x_ho() +void test_position_map_init_2x_ho() { - int cells[] = {8,8}; + int cells[] = {8, 8}; int poly_order = 1; double lower[] = {0.0, 0.0}, upper[] = {1.0, 1.0}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); // Ranges - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); - + // Basis functions. struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); struct gkyl_position_map_inp pos_map_inp = { - .maps = {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, - .ctxs = {0, 0, 0}, + .maps = + {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, + .ctxs = {0, 0, 0} }; - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp, \ - grid, localRange, localRange_ext, localRange, localRange_ext, basis); + struct gkyl_position_map *pos_map = gkyl_position_map_new( + pos_map_inp, grid, localRange, localRange_ext, localRange, localRange_ext, basis + ); TEST_CHECK(pos_map->to_optimize == 0); TEST_CHECK(pos_map->grid.ndim == 2); @@ -200,32 +207,33 @@ test_position_map_init_2x_ho() gkyl_position_map_release(pos_map); } -void -test_position_map_init_3x_ho() +void test_position_map_init_3x_ho() { int cells[] = {8, 8, 8}; int poly_order = 1; double lower[] = {0.0, 0.0, 0.0}, upper[] = {1.0, 1.0, 1.0}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); // Ranges - int ghost[] = { 1, 1, 1}; + int ghost[] = {1, 1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); - + // Basis functions. struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); struct gkyl_position_map_inp pos_map_inp = { - .maps = {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, - .ctxs = {0, 0, 0}, + .maps = + {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, + .ctxs = {0, 0, 0} }; - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp, \ - grid, localRange, localRange_ext, localRange, localRange_ext, basis); + struct gkyl_position_map *pos_map = gkyl_position_map_new( + pos_map_inp, grid, localRange, localRange_ext, localRange, localRange_ext, basis + ); TEST_CHECK(pos_map->to_optimize == 0); TEST_CHECK(pos_map->grid.ndim == 3); @@ -237,97 +245,100 @@ test_position_map_init_3x_ho() gkyl_position_map_release(pos_map); } -void -test_position_map_set_ho() +void test_position_map_set_ho() { int cells[] = {8, 8, 8}; int poly_order = 1; double lower[] = {0.0, 0.0, 0.0}, upper[] = {1.0, 1.0, 1.0}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); // Ranges - int ghost[] = { 1, 1, 1}; + int ghost[] = {1, 1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); - + // Basis functions. struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - + struct gkyl_position_map_inp pos_map_inp = { - .maps = {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, - .ctxs = {0, 0, 0}, + .maps = + {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, + .ctxs = {0, 0, 0} }; - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp, \ - grid, localRange, localRange_ext, localRange, localRange_ext, basis); + struct gkyl_position_map *pos_map = gkyl_position_map_new( + pos_map_inp, grid, localRange, localRange_ext, localRange, localRange_ext, basis + ); - struct gkyl_array *pmap_arr_set = gkyl_array_new(GKYL_DOUBLE, \ - 3*pos_map->basis.num_basis, pos_map->local_ext.volume); + struct gkyl_array *pmap_arr_set = + gkyl_array_new(GKYL_DOUBLE, 3 * pos_map->basis.num_basis, pos_map->local_ext.volume); gkyl_array_clear(pmap_arr_set, 1.0); gkyl_position_map_set_mc2nu(pos_map, pmap_arr_set); - double *pos_map_i = pos_map->mc2nu->data; - for (unsigned i=0; imc2nu->size; ++i) - TEST_CHECK( gkyl_compare(pos_map_i[i], 1.0, 1e-14) ); + double *pos_map_i = pos_map->mc2nu->data; + for (unsigned i = 0; i < pos_map->mc2nu->size; ++i) { + TEST_CHECK(gkyl_compare(pos_map_i[i], 1.0, 1e-14)); + } gkyl_array_release(pmap_arr_set); gkyl_position_map_release(pos_map); } - -void -test_gkyl_position_map_eval_mc2nu_ho() +void test_gkyl_position_map_eval_mc2nu_ho() { int cells[] = {8, 8, 8}; int poly_order = 2; double lower[] = {0.0, 0.0, 0.0}, upper[] = {1.0, 1.0, 1.0}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); // Ranges - int ghost[] = { 1, 1, 1}; + int ghost[] = {1, 1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); - + // Basis functions. struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - + struct gkyl_position_map_inp pos_map_inp = { - .maps = {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, - .ctxs = {0, 0, 0}, + .maps = + {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, + .ctxs = {0, 0, 0} }; - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp, \ - grid, localRange, localRange_ext, localRange, localRange_ext, basis); + struct gkyl_position_map *pos_map = gkyl_position_map_new( + pos_map_inp, grid, localRange, localRange_ext, localRange, localRange_ext, basis + ); - struct gkyl_array *pmap_arr_set = gkyl_array_new(GKYL_DOUBLE, \ - 3*pos_map->basis.num_basis, pos_map->local_ext.volume); + struct gkyl_array *pmap_arr_set = + gkyl_array_new(GKYL_DOUBLE, 3 * pos_map->basis.num_basis, pos_map->local_ext.volume); - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 3, test_nonuniform_position_map_3x, 0); + gkyl_proj_on_basis *projDistf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 3, test_nonuniform_position_map_3x, 0); gkyl_proj_on_basis_advance(projDistf, 0.0, &localRange, pmap_arr_set); gkyl_proj_on_basis_release(projDistf); gkyl_position_map_set_mc2nu(pos_map, pmap_arr_set); - for (int i=0; i<3; i++) { - for (int j=0; j<3; j++) { - for (int k=0; k<5; k++) { - double x[3] = {i/10.0, j/10.0, k/10.0}; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + for (int k = 0; k < 5; k++) { + double x[3] = {i / 10.0, j / 10.0, k / 10.0}; double x_fa[3]; gkyl_position_map_eval_mc2nu(pos_map, x, x_fa); double x_analytic[3]; test_nonuniform_position_map(0.0, &x[0], &x_analytic[0], 0); test_nonuniform_position_map(0.0, &x[1], &x_analytic[1], 0); test_nonuniform_position_map(0.0, &x[2], &x_analytic[2], 0); - for (int d=0; d<3; ++d) - TEST_CHECK( gkyl_compare(x_fa[d], x_analytic[d], 1e-12) ); + for (int d = 0; d < 3; ++d) { + TEST_CHECK(gkyl_compare(x_fa[d], x_analytic[d], 1e-12)); + } } } } @@ -336,54 +347,57 @@ test_gkyl_position_map_eval_mc2nu_ho() gkyl_position_map_release(pos_map); } - -void -test_gkyl_position_map_slope_ho() +void test_gkyl_position_map_slope_ho() { int cells[] = {8, 8, 8}; int poly_order = 2; double lower[] = {0.0, 0.0, 0.0}, upper[] = {1.0, 1.0, 1.0}; - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); // Ranges - int ghost[] = { 1, 1, 1}; + int ghost[] = {1, 1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); - + // Basis functions. struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - + struct gkyl_position_map_inp pos_map_inp = { - .maps = {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, - .ctxs = {0, 0, 0}, + .maps = + {test_nonuniform_position_map, test_nonuniform_position_map, test_nonuniform_position_map}, + .ctxs = {0, 0, 0} }; - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp, \ - grid, localRange, localRange_ext, localRange, localRange_ext, basis); + struct gkyl_position_map *pos_map = gkyl_position_map_new( + pos_map_inp, grid, localRange, localRange_ext, localRange, localRange_ext, basis + ); - struct gkyl_array *pmap_arr_set = gkyl_array_new(GKYL_DOUBLE, \ - 3*pos_map->basis.num_basis, pos_map->local_ext.volume); + struct gkyl_array *pmap_arr_set = + gkyl_array_new(GKYL_DOUBLE, 3 * pos_map->basis.num_basis, pos_map->local_ext.volume); - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 3, test_nonuniform_position_map_3x, 0); + gkyl_proj_on_basis *projDistf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 3, test_nonuniform_position_map_3x, 0); gkyl_proj_on_basis_advance(projDistf, 0.0, &localRange, pmap_arr_set); gkyl_proj_on_basis_release(projDistf); gkyl_position_map_set_mc2nu(pos_map, pmap_arr_set); - for (int i=0; i<8; i++) { - for (int j=0; j<8; j++) { - for (int k=0; k<8; k++) { - double x[3] = {i/8.0, j/8.0, k/8.0}; - if (x[0] == 0.25 || x[0] == 0.75) + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + for (int k = 0; k < 8; k++) { + double x[3] = {i / 8.0, j / 8.0, k / 8.0}; + if (x[0] == 0.25 || x[0] == 0.75) { continue; - if (x[1] == 0.25 || x[1] == 0.75) + } + if (x[1] == 0.25 || x[1] == 0.75) { continue; - if (x[2] == 0.25 || x[2] == 0.75) + } + if (x[2] == 0.25 || x[2] == 0.75) { continue; + } double x_analytic[3]; test_nonuniform_position_map_slope(0.0, &x[0], &x_analytic[0], 0); test_nonuniform_position_map_slope(0.0, &x[1], &x_analytic[1], 0); @@ -392,8 +406,9 @@ test_gkyl_position_map_slope_ho() slope[0] = gkyl_position_map_slope(pos_map, 0, x[0], 1e-6, i, &localRange); slope[1] = gkyl_position_map_slope(pos_map, 1, x[1], 1e-6, j, &localRange); slope[2] = gkyl_position_map_slope(pos_map, 2, x[2], 1e-6, k, &localRange); - for (int d=0; d<3; ++d) - TEST_CHECK( gkyl_compare(slope[d], x_analytic[d], 1e-6) ); + for (int d = 0; d < 3; ++d) { + TEST_CHECK(gkyl_compare(slope[d], x_analytic[d], 1e-6)); + } } } } @@ -401,44 +416,45 @@ test_gkyl_position_map_slope_ho() gkyl_position_map_release(pos_map); } -void -test_position_polynomial_map_optimize_1x_ho() +void test_position_polynomial_map_optimize_1x_ho() { int cells[] = {64}; int poly_order = 1; - double lower[] = {-M_PI+1e-2}, upper[] = {M_PI-1e-2}; - int dim = sizeof(lower)/sizeof(lower[0]); + double lower[] = {-M_PI + 1e-2}, upper[] = {M_PI - 1e-2}; + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); // Ranges - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); - + // Basis functions. struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); struct gkyl_position_map_inp pos_map_inp = { - .id = GKYL_PMAP_CONSTANT_DB_POLYNOMIAL, - .map_strength = 1.0, + .id = GKYL_PMAP_CONSTANT_DB_POLYNOMIAL, .map_strength = 1.0 }; - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp,\ - grid, localRange, localRange_ext, localRange, localRange_ext, basis); + struct gkyl_position_map *pos_map = gkyl_position_map_new( + pos_map_inp, grid, localRange, localRange_ext, localRange, localRange_ext, basis + ); // Project bmag_func onto bmag_global - struct gkyl_array *bmag_global = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, localRange_ext.volume); - gkyl_proj_on_basis *projB = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, 1, bmag_func, 0); + struct gkyl_array *bmag_global = + gkyl_array_new(GKYL_DOUBLE, basis.num_basis, localRange_ext.volume); + gkyl_proj_on_basis *projB = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, bmag_func, 0); gkyl_proj_on_basis_advance(projB, 0.0, &localRange, bmag_global); gkyl_proj_on_basis_release(projB); - + struct gkyl_rect_grid grid3D; double lower3D[] = {0.4, -0.1, lower[0]}, upper3D[] = {0.6, 0.1, upper[0]}; - int cells3D[] = { 1, 1, cells[0]}; + int cells3D[] = {1, 1, cells[0]}; gkyl_rect_grid_init(&grid3D, 3, lower3D, upper3D, cells3D); - int ghost3D[] = { 1, 1 , 1}; + int ghost3D[] = {1, 1, 1}; struct gkyl_range localRange3D, localRange3D_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid3D, ghost3D, &localRange3D_ext, &localRange3D); @@ -447,49 +463,50 @@ test_position_polynomial_map_optimize_1x_ho() gkyl_position_map_optimize(pos_map, grid3D, localRange3D); TEST_CHECK(pos_map->to_optimize == true); - TEST_CHECK( gkyl_compare(pos_map->constB_ctx->theta_throat, 1.565796, 1e-6) ); - TEST_CHECK( gkyl_compare(pos_map->constB_ctx->Bmag_throat, 1.093613, 1e-6) ); - TEST_CHECK( gkyl_compare(pos_map->constB_ctx->psi, 0.5, 1e-6) ); - TEST_CHECK( gkyl_compare(pos_map->constB_ctx->alpha, 0.0, 1e-6) ); - TEST_CHECK( gkyl_compare(pos_map->constB_ctx->map_strength, 1.0, 1e-6) ); - TEST_CHECK( pos_map->constB_ctx->map_order_center == 2 ); - TEST_CHECK( pos_map->constB_ctx->map_order_expander == 3 ); - TEST_CHECK( pos_map->constB_ctx->N_theta_boundaries == 65 ); + TEST_CHECK(gkyl_compare(pos_map->constB_ctx->theta_throat, 1.565796, 1e-6)); + TEST_CHECK(gkyl_compare(pos_map->constB_ctx->Bmag_throat, 1.093613, 1e-6)); + TEST_CHECK(gkyl_compare(pos_map->constB_ctx->psi, 0.5, 1e-6)); + TEST_CHECK(gkyl_compare(pos_map->constB_ctx->alpha, 0.0, 1e-6)); + TEST_CHECK(gkyl_compare(pos_map->constB_ctx->map_strength, 1.0, 1e-6)); + TEST_CHECK(pos_map->constB_ctx->map_order_center == 2); + TEST_CHECK(pos_map->constB_ctx->map_order_expander == 3); + TEST_CHECK(pos_map->constB_ctx->N_theta_boundaries == 65); gkyl_position_map_release(pos_map); gkyl_array_release(bmag_global); } -void -test_position_map_numeric_optimize_1x_ho() +void test_position_map_numeric_optimize_1x_ho() { int cells[] = {64}; int poly_order = 1; - double lower[] = {-M_PI+1e-2}, upper[] = {M_PI-1e-2}; - int dim = sizeof(lower)/sizeof(lower[0]); + double lower[] = {-M_PI + 1e-2}, upper[] = {M_PI - 1e-2}; + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); // Ranges - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); - + // Basis functions. struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); struct gkyl_position_map_inp pos_map_inp = { - .id = GKYL_PMAP_CONSTANT_DB_NUMERIC, - .map_strength = 1.0, + .id = GKYL_PMAP_CONSTANT_DB_NUMERIC, .map_strength = 1.0 }; - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp,\ - grid, localRange, localRange_ext, localRange, localRange_ext, basis); + struct gkyl_position_map *pos_map = gkyl_position_map_new( + pos_map_inp, grid, localRange, localRange_ext, localRange, localRange_ext, basis + ); // Project bmag_func onto bmag_global - struct gkyl_array *bmag_global = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, localRange_ext.volume); - gkyl_proj_on_basis *projB = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, 1, bmag_func, 0); + struct gkyl_array *bmag_global = + gkyl_array_new(GKYL_DOUBLE, basis.num_basis, localRange_ext.volume); + gkyl_proj_on_basis *projB = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, bmag_func, 0); gkyl_proj_on_basis_advance(projB, 0.0, &localRange, bmag_global); gkyl_proj_on_basis_release(projB); @@ -497,7 +514,7 @@ test_position_map_numeric_optimize_1x_ho() double lower3D[] = {0.4, -0.1, lower[0]}, upper3D[] = {0.6, 0.1, upper[0]}; int cells3D[] = {1, 1, cells[0]}; gkyl_rect_grid_init(&grid3D, 3, lower3D, upper3D, cells3D); - int ghost3D[] = { 1, 1 , 1}; + int ghost3D[] = {1, 1, 1}; struct gkyl_range localRange3D, localRange3D_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid3D, ghost3D, &localRange3D_ext, &localRange3D); @@ -505,50 +522,50 @@ test_position_map_numeric_optimize_1x_ho() gkyl_position_map_set_bmag(pos_map, NULL, bmag_global); gkyl_position_map_optimize(pos_map, grid3D, localRange3D); - double theta_extrema_analytic[5] = {lower[0], lower[0]/2, 0.0, upper[0]/2, upper[0]}; + double theta_extrema_analytic[5] = {lower[0], lower[0] / 2, 0.0, upper[0] / 2, upper[0]}; - TEST_CHECK( pos_map->constB_ctx->num_extrema == 5 ); - TEST_CHECK( gkyl_compare(pos_map->constB_ctx->theta_extrema[0], theta_extrema_analytic[0], 1e-15) ); - TEST_CHECK( gkyl_compare(pos_map->constB_ctx->theta_extrema[1], theta_extrema_analytic[1], 1e-15) ); - TEST_CHECK( gkyl_compare(pos_map->constB_ctx->theta_extrema[2], theta_extrema_analytic[2], 1e-15) ); - TEST_CHECK( gkyl_compare(pos_map->constB_ctx->theta_extrema[3], theta_extrema_analytic[3], 1e-15) ); - TEST_CHECK( gkyl_compare(pos_map->constB_ctx->theta_extrema[4], theta_extrema_analytic[4], 1e-15) ); + TEST_CHECK(pos_map->constB_ctx->num_extrema == 5); + TEST_CHECK(gkyl_compare(pos_map->constB_ctx->theta_extrema[0], theta_extrema_analytic[0], 1e-15)); + TEST_CHECK(gkyl_compare(pos_map->constB_ctx->theta_extrema[1], theta_extrema_analytic[1], 1e-15)); + TEST_CHECK(gkyl_compare(pos_map->constB_ctx->theta_extrema[2], theta_extrema_analytic[2], 1e-15)); + TEST_CHECK(gkyl_compare(pos_map->constB_ctx->theta_extrema[3], theta_extrema_analytic[3], 1e-15)); + TEST_CHECK(gkyl_compare(pos_map->constB_ctx->theta_extrema[4], theta_extrema_analytic[4], 1e-15)); gkyl_position_map_release(pos_map); gkyl_array_release(bmag_global); } - -void -test_position_map_numeric_calculate_1x_ho() +void test_position_map_numeric_calculate_1x_ho() { int cells[] = {64}; int poly_order = 1; - double lower[] = {-M_PI+1e-2}, upper[] = {M_PI-1e-2}; - int dim = sizeof(lower)/sizeof(lower[0]); + double lower[] = {-M_PI + 1e-2}, upper[] = {M_PI - 1e-2}; + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, dim, lower, upper, cells); // Ranges - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); - + // Basis functions. struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); struct gkyl_position_map_inp pos_map_inp = { - .id = GKYL_PMAP_CONSTANT_DB_NUMERIC, - .map_strength = 1.0, + .id = GKYL_PMAP_CONSTANT_DB_NUMERIC, .map_strength = 1.0 }; - struct gkyl_position_map *pos_map = gkyl_position_map_new(pos_map_inp,\ - grid, localRange, localRange_ext, localRange, localRange_ext, basis); + struct gkyl_position_map *pos_map = gkyl_position_map_new( + pos_map_inp, grid, localRange, localRange_ext, localRange, localRange_ext, basis + ); // Project bmag_func onto bmag_global - struct gkyl_array *bmag_global = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, localRange_ext.volume); - gkyl_proj_on_basis *projB = gkyl_proj_on_basis_new(&grid, &basis, poly_order+1, 1, bmag_func, 0); + struct gkyl_array *bmag_global = + gkyl_array_new(GKYL_DOUBLE, basis.num_basis, localRange_ext.volume); + gkyl_proj_on_basis *projB = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, bmag_func, 0); gkyl_proj_on_basis_advance(projB, 0.0, &localRange, bmag_global); gkyl_proj_on_basis_release(projB); @@ -556,7 +573,7 @@ test_position_map_numeric_calculate_1x_ho() double lower3D[] = {0.4, -0.1, lower[0]}, upper3D[] = {0.6, 0.1, upper[0]}; int cells3D[] = {1, 1, cells[0]}; gkyl_rect_grid_init(&grid3D, 3, lower3D, upper3D, cells3D); - int ghost3D[] = { 1, 1 , 1}; + int ghost3D[] = {1, 1, 1}; struct gkyl_range localRange3D, localRange3D_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid3D, ghost3D, &localRange3D_ext, &localRange3D); @@ -566,22 +583,22 @@ test_position_map_numeric_calculate_1x_ho() double theta_map = 1.0; pos_map->maps[2](0.0, &theta_map, &theta_map, pos_map->ctxs[2]); - TEST_CHECK( gkyl_compare(theta_map, 1.505924, 1e-5) ); + TEST_CHECK(gkyl_compare(theta_map, 1.505924, 1e-5)); gkyl_position_map_release(pos_map); gkyl_array_release(bmag_global); } TEST_LIST = { - { "test_position_map_init_1x_ho", test_position_map_init_1x_ho }, - { "test_position_map_init_1x_null_ho", test_position_map_init_1x_null_ho }, - { "test_position_map_init_2x_ho", test_position_map_init_2x_ho }, - { "test_position_map_init_3x_ho", test_position_map_init_3x_ho }, - { "test_position_map_set_ho", test_position_map_set_ho }, - { "test_gkyl_position_map_eval_mc2nu_ho", test_gkyl_position_map_eval_mc2nu_ho }, - { "test_gkyl_position_map_slope_ho", test_gkyl_position_map_slope_ho }, - { "test_position_polynomial_map_optimize_1x_ho", test_position_polynomial_map_optimize_1x_ho }, - { "test_position_map_numeric_optimize_1x_ho", test_position_map_numeric_optimize_1x_ho }, - { "test_position_map_numeric_calculate_1x_ho", test_position_map_numeric_calculate_1x_ho }, - { NULL, NULL }, + {"test_position_map_init_1x_ho", test_position_map_init_1x_ho}, + {"test_position_map_init_1x_null_ho", test_position_map_init_1x_null_ho}, + {"test_position_map_init_2x_ho", test_position_map_init_2x_ho}, + {"test_position_map_init_3x_ho", test_position_map_init_3x_ho}, + {"test_position_map_set_ho", test_position_map_set_ho}, + {"test_gkyl_position_map_eval_mc2nu_ho", test_gkyl_position_map_eval_mc2nu_ho}, + {"test_gkyl_position_map_slope_ho", test_gkyl_position_map_slope_ho}, + {"test_position_polynomial_map_optimize_1x_ho", test_position_polynomial_map_optimize_1x_ho}, + {"test_position_map_numeric_optimize_1x_ho", test_position_map_numeric_optimize_1x_ho}, + {"test_position_map_numeric_calculate_1x_ho", test_position_map_numeric_calculate_1x_ho}, + {NULL, NULL} }; \ No newline at end of file diff --git a/gyrokinetic/unit/ctest_positivity_shift_gyrokinetic.c b/gyrokinetic/unit/ctest_positivity_shift_gyrokinetic.c index 4aca6b46b4..732966851a 100644 --- a/gyrokinetic/unit/ctest_positivity_shift_gyrokinetic.c +++ b/gyrokinetic/unit/ctest_positivity_shift_gyrokinetic.c @@ -16,14 +16,14 @@ #include // Allocate array (filled with zeros). -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } @@ -38,13 +38,14 @@ struct test_ctx { double mu_max; // Maximum mu of the grid. }; -void -mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; xp[2] = xc[2]; + xp[0] = xc[0]; + xp[1] = xc[1]; + xp[2] = xc[2]; } -void eval_bfield_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_bfield_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; @@ -56,13 +57,13 @@ void eval_bfield_1x(double t, const double *xn, double* restrict fout, void *ctx fout[2] = B0; } -void eval_bmag_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_bmag_1x(double t, const double *xn, double *restrict fout, void *ctx) { struct test_ctx *tctx = ctx; fout[0] = tctx->B0; } -void eval_distf_1x2v(double t, const double *xn, double* restrict fout, void *ctx) +void eval_distf_1x2v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], vpar = xn[1], mu = xn[2]; @@ -71,18 +72,19 @@ void eval_distf_1x2v(double t, const double *xn, double* restrict fout, void *ct double mass = tctx->mass; double n0 = tctx->n0; double upar = tctx->upar; - double vtsq = tctx->temp/mass; + double vtsq = tctx->temp / mass; int vdim = tctx->vdim; - fout[0] = (n0/pow(2.0*M_PI*vtsq,vdim/2.0)) * exp(-(pow(vpar-upar,2)+2.0*mu*B0/mass)/(2.0*vtsq)); + fout[0] = (n0 / pow(2.0 * M_PI * vtsq, vdim / 2.0)) * + exp(-(pow(vpar - upar, 2) + 2.0 * mu * B0 / mass) / (2.0 * vtsq)); // Intentionally set some places to be negative. - if (fabs(vpar) > 0.8*tctx->vpar_max || mu > 0.8*tctx->mu_max) - fout[0] = -0.2 * (n0/pow(2.0*M_PI*vtsq,vdim/2.0)); + if (fabs(vpar) > 0.8 * tctx->vpar_max || mu > 0.8 * tctx->mu_max) { + fout[0] = -0.2 * (n0 / pow(2.0 * M_PI * vtsq, vdim / 2.0)); + } } -void -test_1x2v(int poly_order, bool use_gpu) +void test_1x2v(int poly_order, bool use_gpu) { int cdim = 1; double vpar_max = 6.0; @@ -90,8 +92,8 @@ test_1x2v(int poly_order, bool use_gpu) double lower[] = {0.1, -vpar_max, 0.0}, upper[] = {1.0, vpar_max, mu_max}; int cells[] = {2, 12, 8}; - int ndim = sizeof(cells)/sizeof(cells[0]); - int vdim = ndim-cdim; + int ndim = sizeof(cells) / sizeof(cells[0]); + int vdim = ndim - cdim; struct test_ctx proj_ctx = { .n0 = 1.0, // Density. @@ -101,22 +103,22 @@ test_1x2v(int poly_order, bool use_gpu) .B0 = 1.0, // Magnetic field. .vdim = vdim, // Number of velocity space dimensions. .vpar_max = vpar_max, // Maximum vpar of the grid. - .mu_max = mu_max, // Maximum mu of the grid. + .mu_max = mu_max // Maximum mu of the grid. }; double confLower[cdim], confUpper[cdim]; int confCells[cdim]; - for (int d=0; dncomp, bmag->size); - gkyl_proj_on_basis *proj_bmag = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, 1, eval_bmag_1x, &proj_ctx); + } + gkyl_proj_on_basis *proj_bmag = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_bmag_1x, &proj_ctx); gkyl_proj_on_basis_advance(proj_bmag, 0.0, &confLocal, bmag_ho); gkyl_array_copy(bmag, bmag_ho); @@ -164,10 +170,11 @@ test_1x2v(int poly_order, bool use_gpu) struct gkyl_array *distf_ho, *distf; distf = mkarr(use_gpu, basis.num_basis, local_ext.volume); distf_ho = distf; - if (use_gpu) + if (use_gpu) { distf_ho = mkarr(false, distf->ncomp, distf->size); - gkyl_proj_on_basis *proj_distf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_distf_1x2v, &proj_ctx); + } + gkyl_proj_on_basis *proj_distf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_distf_1x2v, &proj_ctx); gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); @@ -176,61 +183,73 @@ test_1x2v(int poly_order, bool use_gpu) // Initialize geometry struct gkyl_gk_geometry_inp geometry_input = { .geometry_id = GKYL_GEOMETRY_MAPC2P, - .world = {0.0}, .mapc2p = mapc2p, .c2p_ctx = 0, - .bfield_func = eval_bfield_1x, .bfield_ctx = &proj_ctx, - .basis = confBasis, .grid = confGrid, - .local = confLocal, .local_ext = confLocal_ext, - .global = confLocal, .global_ext = confLocal_ext, - .position_map = pmap, + .world = {0.0}, + .mapc2p = mapc2p, + .c2p_ctx = 0, + .bfield_func = eval_bfield_1x, + .bfield_ctx = &proj_ctx, + .basis = confBasis, + .grid = confGrid, + .local = confLocal, + .local_ext = confLocal_ext, + .global = confLocal, + .global_ext = confLocal_ext, + .position_map = pmap }; int geo_ghost[3] = {1, 1, 1}; geometry_input.geo_grid = gkyl_gk_geometry_augment_grid(confGrid, geometry_input); gkyl_cart_modal_serendip(&geometry_input.geo_basis, 3, poly_order); - gkyl_create_grid_ranges(&geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global); + gkyl_create_grid_ranges( + &geometry_input.geo_grid, geo_ghost, &geometry_input.geo_global_ext, &geometry_input.geo_global + ); memcpy(&geometry_input.geo_local, &geometry_input.geo_global, sizeof(struct gkyl_range)); memcpy(&geometry_input.geo_local_ext, &geometry_input.geo_global_ext, sizeof(struct gkyl_range)); // Deflate geometry. - struct gk_geometry* gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); + struct gk_geometry *gk_geom_3d = gkyl_gk_geometry_mapc2p_new(&geometry_input); struct gk_geometry *gk_geom = gkyl_gk_geometry_deflate(gk_geom_3d, &geometry_input); gkyl_gk_geometry_release(gk_geom_3d); // If we are on the gpu, copy from host. if (use_gpu) { - struct gk_geometry* gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); + struct gk_geometry *gk_geom_dev = gkyl_gk_geometry_new(gk_geom, &geometry_input, use_gpu); gkyl_gk_geometry_release(gk_geom); gk_geom = gkyl_gk_geometry_acquire(gk_geom_dev); gkyl_gk_geometry_release(gk_geom_dev); } // Velocity space mapping. - struct gkyl_mapc2p_inp c2p_in = { }; - struct gkyl_velocity_map *gvm = gkyl_velocity_map_new(c2p_in, grid, velGrid, - local, local_ext, velLocal, velLocal_ext, use_gpu); + struct gkyl_mapc2p_inp c2p_in = {}; + struct gkyl_velocity_map *gvm = + gkyl_velocity_map_new(c2p_in, grid, velGrid, local, local_ext, velLocal, velLocal_ext, use_gpu); // Compute the integrated moments of the original f. struct gkyl_dg_updater_moment *int_mom_up = gkyl_dg_updater_moment_gyrokinetic_new( - &grid, &confBasis, &basis, &confLocal, proj_ctx.mass, 0, gvm, gk_geom, NULL, GKYL_F_MOMENT_M0M1M2PARM2PERP, true, use_gpu); + &grid, &confBasis, &basis, &confLocal, proj_ctx.mass, 0, gvm, gk_geom, NULL, + GKYL_F_MOMENT_M0M1M2PARM2PERP, true, use_gpu + ); int num_mom = gkyl_dg_updater_moment_gyrokinetic_num_mom(int_mom_up); struct gkyl_array *intmom_grid = mkarr(use_gpu, num_mom, confLocal_ext.volume); double *red_intmom; - if (use_gpu) - red_intmom = gkyl_cu_malloc(sizeof(double[2+vdim])); - else - red_intmom = gkyl_malloc(sizeof(double[2+vdim])); + if (use_gpu) { + red_intmom = gkyl_cu_malloc(sizeof(double[2 + vdim])); + } else { + red_intmom = gkyl_malloc(sizeof(double[2 + vdim])); + } gkyl_dg_updater_moment_gyrokinetic_advance(int_mom_up, &local, &confLocal, distf, intmom_grid); gkyl_array_reduce_range(red_intmom, intmom_grid, GKYL_SUM, &confLocal); - double intmom_pre[2+vdim]; - if (use_gpu) - gkyl_cu_memcpy(intmom_pre, red_intmom, sizeof(double[2+vdim]), GKYL_CU_MEMCPY_D2H); - else - memcpy(intmom_pre, red_intmom, sizeof(double[2+vdim])); - -// printf("\nintmom_pre = %16.14e %16.14e %16.14e %16.14e\n",intmom_pre[0],intmom_pre[1],intmom_pre[2],intmom_pre[3]); -// // Write distribution function to file. -// char fname0[1024]; -// sprintf(fname0, "ctest_positivity_shift_gyrokinetic_1x2v_p%d_pre.gkyl", poly_order); -// gkyl_grid_sub_array_write(&grid, &local, NULL, distf, fname0); + double intmom_pre[2 + vdim]; + if (use_gpu) { + gkyl_cu_memcpy(intmom_pre, red_intmom, sizeof(double[2 + vdim]), GKYL_CU_MEMCPY_D2H); + } else { + memcpy(intmom_pre, red_intmom, sizeof(double[2 + vdim])); + } + + // printf("\nintmom_pre = %16.14e %16.14e %16.14e %16.14e\n",intmom_pre[0],intmom_pre[1],intmom_pre[2],intmom_pre[3]); + // // Write distribution function to file. + // char fname0[1024]; + // sprintf(fname0, "ctest_positivity_shift_gyrokinetic_1x2v_p%d_pre.gkyl", poly_order); + // gkyl_grid_sub_array_write(&grid, &local, NULL, distf, fname0); // Run the positivity shift. First time it sets ffloor in the pos_shift updater. struct gkyl_array *m0 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); @@ -239,9 +258,9 @@ test_1x2v(int poly_order, bool use_gpu) deltaf = mkarr(use_gpu, basis.num_basis, local_ext.volume); gkyl_array_set(deltaf, -1.0, distf); - - struct gkyl_positivity_shift_gyrokinetic* pos_shift = gkyl_positivity_shift_gyrokinetic_new(confBasis, - basis, grid, proj_ctx.mass, gk_geom, gvm, &confLocal_ext, use_gpu); + struct gkyl_positivity_shift_gyrokinetic *pos_shift = gkyl_positivity_shift_gyrokinetic_new( + confBasis, basis, grid, proj_ctx.mass, gk_geom, gvm, &confLocal_ext, use_gpu + ); gkyl_positivity_shift_gyrokinetic_advance(pos_shift, &confLocal, &local, distf, m0, ps_delta_m0); // Project distf and apply the positivity shift again (using new ffloor). @@ -255,38 +274,48 @@ test_1x2v(int poly_order, bool use_gpu) // Compute the integrated moments after the positivity shift. gkyl_dg_updater_moment_gyrokinetic_advance(int_mom_up, &local, &confLocal, distf, intmom_grid); gkyl_array_reduce_range(red_intmom, intmom_grid, GKYL_SUM, &confLocal); - double intmom_post[2+vdim]; - if (use_gpu) - gkyl_cu_memcpy(intmom_post, red_intmom, sizeof(double[2+vdim]), GKYL_CU_MEMCPY_D2H); - else - memcpy(intmom_post, red_intmom, sizeof(double[2+vdim])); + double intmom_post[2 + vdim]; + if (use_gpu) { + gkyl_cu_memcpy(intmom_post, red_intmom, sizeof(double[2 + vdim]), GKYL_CU_MEMCPY_D2H); + } else { + memcpy(intmom_post, red_intmom, sizeof(double[2 + vdim])); + } // Compute the integrated moments of the shift. struct gkyl_array *ps_intmom_grid = mkarr(use_gpu, num_mom, confLocal_ext.volume); gkyl_dg_updater_moment_gyrokinetic_advance(int_mom_up, &local, &confLocal, deltaf, ps_intmom_grid); gkyl_array_reduce_range(red_intmom, ps_intmom_grid, GKYL_SUM, &confLocal); - double intmom_shift[2+vdim]; - if (use_gpu) - gkyl_cu_memcpy(intmom_shift, red_intmom, sizeof(double[2+vdim]), GKYL_CU_MEMCPY_D2H); - else - memcpy(intmom_shift, red_intmom, sizeof(double[2+vdim])); - -// printf("intmom_post = %16.14e %16.14e %16.14e %16.14e\n",intmom_post[0],intmom_post[1],intmom_post[2],intmom_post[3]); -// printf("intmom_shift = %16.14e %16.14e %16.14e %16.14e\n",intmom_shift[0],intmom_shift[1],intmom_shift[2],intmom_shift[3]); -// // Write distribution function to file. -// char fname1[1024]; -// sprintf(fname1, "ctest_positivity_shift_gyrokinetic_1x2v_p%d_post.gkyl", poly_order); -// gkyl_grid_sub_array_write(&grid, &local, NULL, distf, fname1); - + double intmom_shift[2 + vdim]; + if (use_gpu) { + gkyl_cu_memcpy(intmom_shift, red_intmom, sizeof(double[2 + vdim]), GKYL_CU_MEMCPY_D2H); + } else { + memcpy(intmom_shift, red_intmom, sizeof(double[2 + vdim])); + } + + // printf("intmom_post = %16.14e %16.14e %16.14e %16.14e\n",intmom_post[0],intmom_post[1],intmom_post[2],intmom_post[3]); + // printf("intmom_shift = %16.14e %16.14e %16.14e %16.14e\n",intmom_shift[0],intmom_shift[1],intmom_shift[2],intmom_shift[3]); + // // Write distribution function to file. + // char fname1[1024]; + // sprintf(fname1, "ctest_positivity_shift_gyrokinetic_1x2v_p%d_post.gkyl", poly_order); + // gkyl_grid_sub_array_write(&grid, &local, NULL, distf, fname1); + // Check the integrated moments. - TEST_CHECK( gkyl_compare( intmom_shift[0], 9.13090909090910e+00, 1e-10)); - TEST_MSG("intmom_shift[0]: produced: %.14e | expected: %.14e", intmom_shift[0], 9.13090909090910e+00); - TEST_CHECK( gkyl_compare( intmom_shift[1], 8.61055942680578e-16, 1e-10)); - TEST_MSG("intmom_shift[1]: produced: %.14e | expected: %.14e", intmom_shift[1], 8.61055942680578e-16); - TEST_CHECK( gkyl_compare( intmom_shift[2], 1.79770909090909e+02, 1e-10)); - TEST_MSG("intmom_shift[2]: produced: %.14e | expected: %.14e", intmom_shift[2], 1.79770909090909e+02); - TEST_CHECK( gkyl_compare( intmom_shift[3], 4.58457166783993e+02, 1e-10)); - TEST_MSG("intmom_shift[3]: produced: %.14e | expected: %.14e", intmom_shift[3], 4.58457166783993e+02); + TEST_CHECK(gkyl_compare(intmom_shift[0], 9.13090909090910e+00, 1e-10)); + TEST_MSG( + "intmom_shift[0]: produced: %.14e | expected: %.14e", intmom_shift[0], 9.13090909090910e+00 + ); + TEST_CHECK(gkyl_compare(intmom_shift[1], 8.61055942680578e-16, 1e-10)); + TEST_MSG( + "intmom_shift[1]: produced: %.14e | expected: %.14e", intmom_shift[1], 8.61055942680578e-16 + ); + TEST_CHECK(gkyl_compare(intmom_shift[2], 1.79770909090909e+02, 1e-10)); + TEST_MSG( + "intmom_shift[2]: produced: %.14e | expected: %.14e", intmom_shift[2], 1.79770909090909e+02 + ); + TEST_CHECK(gkyl_compare(intmom_shift[3], 4.58457166783993e+02, 1e-10)); + TEST_MSG( + "intmom_shift[3]: produced: %.14e | expected: %.14e", intmom_shift[3], 4.58457166783993e+02 + ); gkyl_array_release(bmag); gkyl_array_release(distf); @@ -299,7 +328,7 @@ test_1x2v(int poly_order, bool use_gpu) gkyl_array_release(bmag_ho); gkyl_array_release(distf_ho); gkyl_cu_free(red_intmom); - } else{ + } else { gkyl_free(red_intmom); } gkyl_proj_on_basis_release(proj_bmag); @@ -322,9 +351,9 @@ void test_positivity_shift_1x2v_dev() } TEST_LIST = { - { "test_positivity_shift_1x2v_ho", test_positivity_shift_1x2v_ho }, + {"test_positivity_shift_1x2v_ho", test_positivity_shift_1x2v_ho}, #ifdef GKYL_HAVE_CUDA - { "test_positivity_shift_1x2v_dev", test_positivity_shift_1x2v_dev }, + {"test_positivity_shift_1x2v_dev", test_positivity_shift_1x2v_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/gyrokinetic/unit/ctest_proj_gk_bimaxwellian_on_basis.c b/gyrokinetic/unit/ctest_proj_gk_bimaxwellian_on_basis.c index a73acdb625..57ac8f81f1 100644 --- a/gyrokinetic/unit/ctest_proj_gk_bimaxwellian_on_basis.c +++ b/gyrokinetic/unit/ctest_proj_gk_bimaxwellian_on_basis.c @@ -15,21 +15,20 @@ #include // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { - struct gkyl_array* a = gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -void -mapc2p_3x(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p_3x(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; xp[2] = xc[2]; + xp[0] = xc[0]; + xp[1] = xc[1]; + xp[2] = xc[2]; } -void -bfield_func_3x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func_3x(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; fout[0] = 0.0; @@ -37,7 +36,7 @@ bfield_func_3x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx fout[2] = 1.0; } -void eval_prim_moms_1x2v_gk(double t, const double *xn, double* restrict fout, void *ctx) +void eval_prim_moms_1x2v_gk(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double den = 1.0; @@ -45,30 +44,29 @@ void eval_prim_moms_1x2v_gk(double t, const double *xn, double* restrict fout, v double tpar = 1.3; double tperp = 0.6; double mass = 1.0; - fout[0] = den; // Density. - fout[1] = upar; // Parallel drift speed. - fout[2] = tpar/mass; // Parallel temperature divided by mass (vtpar^2). - fout[3] = tperp/mass; // Perpendicular temperature divided by mass (vtperp^2). + fout[0] = den; // Density. + fout[1] = upar; // Parallel drift speed. + fout[2] = tpar / mass; // Parallel temperature divided by mass (vtpar^2). + fout[3] = tperp / mass; // Perpendicular temperature divided by mass (vtperp^2). } -void -test_1x2v_gk(int poly_order, bool use_gpu) +void test_1x2v_gk(int poly_order, bool use_gpu) { double mass = 1.0; double lower[] = {0.1, -6.0, 0.0}, upper[] = {1.0, 6.0, 6.0}; int cells[] = {2, 16, 16}; int vdim = 2, cdim = 1; - int ndim = cdim+vdim; + int ndim = cdim + vdim; double confLower[] = {lower[0]}, confUpper[] = {upper[0]}; int confCells[] = {cells[0]}; double velLower[vdim], velUpper[vdim]; int velCells[vdim]; - for (int d=0; d // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { - struct gkyl_array* a = gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -void eval_den(double t, const double *xn, double* restrict fout, void *ctx) +void eval_den(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 1.0; } -void eval_udrift_2v_gk(double t, const double *xn, double* restrict fout, void *ctx) +void eval_udrift_2v_gk(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 0.5; } -void eval_vtsq(double t, const double *xn, double* restrict fout, void *ctx) +void eval_vtsq(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double vtsq = 1.0; fout[0] = vtsq; } -void -mapc2p_3x(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p_3x(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { - xp[0] = xc[0]; xp[1] = xc[1]; xp[2] = xc[2]; + xp[0] = xc[0]; + xp[1] = xc[1]; + xp[2] = xc[2]; } - -void -bfield_func_3x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx) +void bfield_func_3x(double t, const double *xc, double *GKYL_RESTRICT fout, void *ctx) { double x = xc[0], y = xc[1], z = xc[2]; fout[0] = 0.0; @@ -58,29 +56,28 @@ bfield_func_3x(double t, const double *xc, double* GKYL_RESTRICT fout, void *ctx fout[2] = 1.0; } -void -test_1x2v_gk(int poly_order, bool use_gpu) +void test_1x2v_gk(int poly_order, bool use_gpu) { double mass = 1.0; double lower[] = {0.1, -6.0, 0.0}, upper[] = {1.0, 6.0, 6.0}; int cells[] = {2, 16, 16}; int vdim = 2; - int ndim = sizeof(cells)/sizeof(cells[0]); - int cdim = ndim-vdim; + int ndim = sizeof(cells) / sizeof(cells[0]); + int cdim = ndim - vdim; double confLower[cdim], confUpper[cdim]; int confCells[cdim]; - for (int d=0; d 0) { double r1, r2; double delta = sqrt(delta2); //// compute both roots - double qq = -0.5*(bq + (bq/fabs(bq)) * delta); - r1 = qq/aq; - r2 = cq/qq; + double qq = -0.5 * (bq + (bq / fabs(bq)) * delta); + r1 = qq / aq; + r2 = cq / qq; int sidx = 0; - if ((-1<=r1) && (r1 < 1)) { + if ((-1 <= r1) && (r1 < 1)) { sol.nsol += 1; - sol.R[sidx] = r1*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r1 * dx[0] * 0.5 + xc[0]; double x = r1; - double C = 0.125*(SQ(x)*(90.0*psi[8]*y+23.2379000772445*psi[6])+x*(46.47580015448901*psi[7]*y+12.0*psi[3])+2* (13.41640786499874*psi[5]-15.0*psi[8])*y-7.745966692414834*psi[6]+6.928203230275509*psi[2]) ; - double A = 0.125*(2*x*(45.0*psi[8]*SQ(y)+23.2379000772445*psi[6]*y-15.0*psi[8]+13.41640786499874*psi[4])+23.2379000772445*psi[7]*SQ(y)+12.0*psi[3]*y-7.745966692414834*psi[7]+6.928203230275509*psi[1]); - sol.dRdZ[sidx] = -C/A*dx[0]/dx[1]; - + double C = 0.125 * (SQ(x) * (90.0 * psi[8] * y + 23.2379000772445 * psi[6]) + + x * (46.47580015448901 * psi[7] * y + 12.0 * psi[3]) + + 2 * (13.41640786499874 * psi[5] - 15.0 * psi[8]) * y - + 7.745966692414834 * psi[6] + 6.928203230275509 * psi[2]); + double A = 0.125 * (2 * x * + (45.0 * psi[8] * SQ(y) + 23.2379000772445 * psi[6] * y - 15.0 * psi[8] + + 13.41640786499874 * psi[4]) + + 23.2379000772445 * psi[7] * SQ(y) + 12.0 * psi[3] * y - + 7.745966692414834 * psi[7] + 6.928203230275509 * psi[1]); + sol.dRdZ[sidx] = -C / A * dx[0] / dx[1]; + sidx += 1; } - if ((-1<=r2) && (r2 < 1)) { + if ((-1 <= r2) && (r2 < 1)) { sol.nsol += 1; - sol.R[sidx] = r2*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r2 * dx[0] * 0.5 + xc[0]; double x = r2; - double C = 0.125*(SQ(x)*(90.0*psi[8]*y+23.2379000772445*psi[6])+x*(46.47580015448901*psi[7]*y+12.0*psi[3])+2* (13.41640786499874*psi[5]-15.0*psi[8])*y-7.745966692414834*psi[6]+6.928203230275509*psi[2]) ; - double A = 0.125*(2*x*(45.0*psi[8]*SQ(y)+23.2379000772445*psi[6]*y-15.0*psi[8]+13.41640786499874*psi[4])+23.2379000772445*psi[7]*SQ(y)+12.0*psi[3]*y-7.745966692414834*psi[7]+6.928203230275509*psi[1]); - sol.dRdZ[sidx] = -C/A*dx[0]/dx[1]; - + double C = 0.125 * (SQ(x) * (90.0 * psi[8] * y + 23.2379000772445 * psi[6]) + + x * (46.47580015448901 * psi[7] * y + 12.0 * psi[3]) + + 2 * (13.41640786499874 * psi[5] - 15.0 * psi[8]) * y - + 7.745966692414834 * psi[6] + 6.928203230275509 * psi[2]); + double A = 0.125 * (2 * x * + (45.0 * psi[8] * SQ(y) + 23.2379000772445 * psi[6] * y - 15.0 * psi[8] + + 13.41640786499874 * psi[4]) + + 23.2379000772445 * psi[7] * SQ(y) + 12.0 * psi[3] * y - + 7.745966692414834 * psi[7] + 6.928203230275509 * psi[1]); + sol.dRdZ[sidx] = -C / A * dx[0] / dx[1]; + sidx += 1; } } return sol; } -static inline double cub(double x) { return x*x*x; } +static inline double cub(double x) +{ + return x * x * x; +} static inline struct RdRdZ_sol cub_root(const double *psi, double psi0, double Z, double xc[2], double dx[2]) { - struct RdRdZ_sol sol = { .nsol = 0 }; - double y = (Z-xc[1])/(dx[1]*0.5); + struct RdRdZ_sol sol = {.nsol = 0}; + double y = (Z - xc[1]) / (dx[1] * 0.5); double coeffs[4]; // coeffs = [x^0, x^1, x^2, x^3] - coeffs[3] = 0.125*(175.0*psi[15]*cub(y)+88.74119674649424*psi[13]*SQ(y)+(45.8257569495584*psi[11]-105.0*psi[15])*y+26.45751311064591*psi[8]-29.58039891549808*psi[13]); - coeffs[2] = 0.125*(88.74119674649424*psi[14]*cub(y)+45.0*psi[10]*SQ(y)+(23.2379000772445*psi[6]-53.24471804789655*psi[14])*y+13.41640786499874*psi[4]-15.0*psi[10]); - coeffs[1] = 0.125*((45.8257569495584*psi[12]-105.0*psi[15])*cub(y)+(23.2379000772445*psi[7]-53.24471804789655*psi[13])*SQ(y)+(12.0*psi[3]+63.0*psi[15]-27.49545416973504*psi[12]-27.49545416973504*psi[11])*y-15.87450786638754*psi[8]-7.745966692414834*psi[7]+17.74823934929885*psi[13]+6.928203230275509*psi[1]); - coeffs[0] = 0.125*((26.45751311064591*psi[9]-29.58039891549808*psi[14])*cub(y)+(13.41640786499874*psi[5]-15.0*psi[10])*SQ(y)+(-15.87450786638754*psi[9]-7.745966692414834*psi[6]+6.928203230275509*psi[2]+17.74823934929885*psi[14])*y-4.47213595499958*psi[5]-4.47213595499958*psi[4]+5.0*psi[10]+4.0*psi[0]) - psi0; - - coeffs[0] = coeffs[0]/coeffs[3]; - coeffs[1] = coeffs[1]/coeffs[3]; - coeffs[2] = coeffs[2]/coeffs[3]; - coeffs[3] = coeffs[3]/coeffs[3]; + coeffs[3] = 0.125 * (175.0 * psi[15] * cub(y) + 88.74119674649424 * psi[13] * SQ(y) + + (45.8257569495584 * psi[11] - 105.0 * psi[15]) * y + + 26.45751311064591 * psi[8] - 29.58039891549808 * psi[13]); + coeffs[2] = 0.125 * (88.74119674649424 * psi[14] * cub(y) + 45.0 * psi[10] * SQ(y) + + (23.2379000772445 * psi[6] - 53.24471804789655 * psi[14]) * y + + 13.41640786499874 * psi[4] - 15.0 * psi[10]); + coeffs[1] = 0.125 * ((45.8257569495584 * psi[12] - 105.0 * psi[15]) * cub(y) + + (23.2379000772445 * psi[7] - 53.24471804789655 * psi[13]) * SQ(y) + + (12.0 * psi[3] + 63.0 * psi[15] - 27.49545416973504 * psi[12] - + 27.49545416973504 * psi[11]) * + y - + 15.87450786638754 * psi[8] - 7.745966692414834 * psi[7] + + 17.74823934929885 * psi[13] + 6.928203230275509 * psi[1]); + coeffs[0] = + 0.125 * ((26.45751311064591 * psi[9] - 29.58039891549808 * psi[14]) * cub(y) + + (13.41640786499874 * psi[5] - 15.0 * psi[10]) * SQ(y) + + (-15.87450786638754 * psi[9] - 7.745966692414834 * psi[6] + + 6.928203230275509 * psi[2] + 17.74823934929885 * psi[14]) * + y - + 4.47213595499958 * psi[5] - 4.47213595499958 * psi[4] + 5.0 * psi[10] + 4.0 * psi[0]) - + psi0; + + coeffs[0] = coeffs[0] / coeffs[3]; + coeffs[1] = coeffs[1] / coeffs[3]; + coeffs[2] = coeffs[2] / coeffs[3]; + coeffs[3] = coeffs[3] / coeffs[3]; struct gkyl_lo_poly_roots rts; rts = gkyl_calc_lo_poly_roots(GKYL_LO_POLY_3, coeffs); int sidx = 0; - for(int i =0; i<3; i++){ - if(rts.rpart[i] < 1.0 && rts.rpart[i] > -1.0 && fabs(rts.impart[i])<1e-10){ + for (int i = 0; i < 3; i++) { + if (rts.rpart[i] < 1.0 && rts.rpart[i] > -1.0 && fabs(rts.impart[i]) < 1e-10) { sol.nsol += 1; - sol.R[sidx] = rts.rpart[i]*dx[0]*0.5 + xc[0]; + sol.R[sidx] = rts.rpart[i] * dx[0] * 0.5 + xc[0]; double x = rts.rpart[i]; - double dpsidx = 6.5625000000000000e+01*(x*x)*(y*y*y)*psi[15]+-9.6824583655185426e-01*psi[7]+-6.6555897559870685e+00*(y*y)*psi[13]+5.7282196186947996e+00*(y*y*y)*psi[12]+2.9047375096555625e+00*psi[7]*(y*y)+3.3277948779935343e+01*(x*x)*(y*y)*psi[13]+5.8094750193111251e+00*psi[6]*x*y+-1.3125000000000000e+01*(y*y*y)*psi[15]+9.9215674164922145e+00*(x*x)*psi[8]+-3.7500000000000000e+00*x*psi[10]+8.6602540378443860e-01*psi[1]+-3.4369317712168801e+00*y*psi[12]+-1.3311179511974137e+01*x*psi[14]*y+-1.9843134832984430e+00*psi[8]+-3.4369317712168801e+00*y*psi[11]+-3.9375000000000000e+01*(x*x)*y*psi[15]+1.7184658856084400e+01*(x*x)*y*psi[11]+2.2185299186623562e+00*psi[13]+2.2185299186623560e+01*x*psi[14]*(y*y*y)+1.5000000000000000e+00*y*psi[3]+-1.1092649593311780e+01*(x*x)*psi[13]+1.1250000000000000e+01*x*(y*y)*psi[10]+7.8750000000000000e+00*y*psi[15]+3.3541019662496847e+00*x*psi[4]; - double dpsidy = -9.6824583655185426e-01*psi[6]+1.5000000000000000e+00*x*psi[3]+2.2185299186623560e+01*(x*x*x)*y*psi[13]+7.8750000000000000e+00*x*psi[15]+3.3277948779935343e+01*(x*x)*psi[14]*(y*y)+2.2185299186623562e+00*psi[14]+-3.4369317712168801e+00*x*psi[12]+9.9215674164922145e+00*(y*y)*psi[9]+-3.4369317712168801e+00*x*psi[11]+-1.3311179511974137e+01*x*y*psi[13]+-1.1092649593311780e+01*psi[14]*(y*y)+-3.9375000000000000e+01*x*(y*y)*psi[15]+-1.3125000000000000e+01*(x*x*x)*psi[15]+-3.7500000000000000e+00*y*psi[10]+2.9047375096555625e+00*psi[6]*(x*x)+5.8094750193111251e+00*psi[7]*x*y+-6.6555897559870685e+00*(x*x)*psi[14]+5.7282196186947996e+00*(x*x*x)*psi[11]+-1.9843134832984430e+00*psi[9]+6.5625000000000000e+01*(x*x*x)*(y*y)*psi[15]+3.3541019662496847e+00*psi[5]*y+1.1250000000000000e+01*(x*x)*y*psi[10]+1.7184658856084400e+01*x*(y*y)*psi[12]+8.6602540378443860e-01*psi[2]; - - sol.dRdZ[sidx] = -dpsidy/dpsidx*dx[0]/dx[1]; - sidx+=1; + double dpsidx = + 6.5625000000000000e+01 * (x * x) * (y * y * y) * psi[15] + + -9.6824583655185426e-01 * psi[7] + -6.6555897559870685e+00 * (y * y) * psi[13] + + 5.7282196186947996e+00 * (y * y * y) * psi[12] + 2.9047375096555625e+00 * psi[7] * (y * y) + + 3.3277948779935343e+01 * (x * x) * (y * y) * psi[13] + + 5.8094750193111251e+00 * psi[6] * x * y + -1.3125000000000000e+01 * (y * y * y) * psi[15] + + 9.9215674164922145e+00 * (x * x) * psi[8] + -3.7500000000000000e+00 * x * psi[10] + + 8.6602540378443860e-01 * psi[1] + -3.4369317712168801e+00 * y * psi[12] + + -1.3311179511974137e+01 * x * psi[14] * y + -1.9843134832984430e+00 * psi[8] + + -3.4369317712168801e+00 * y * psi[11] + -3.9375000000000000e+01 * (x * x) * y * psi[15] + + 1.7184658856084400e+01 * (x * x) * y * psi[11] + 2.2185299186623562e+00 * psi[13] + + 2.2185299186623560e+01 * x * psi[14] * (y * y * y) + 1.5000000000000000e+00 * y * psi[3] + + -1.1092649593311780e+01 * (x * x) * psi[13] + + 1.1250000000000000e+01 * x * (y * y) * psi[10] + 7.8750000000000000e+00 * y * psi[15] + + 3.3541019662496847e+00 * x * psi[4]; + double dpsidy = + -9.6824583655185426e-01 * psi[6] + 1.5000000000000000e+00 * x * psi[3] + + 2.2185299186623560e+01 * (x * x * x) * y * psi[13] + 7.8750000000000000e+00 * x * psi[15] + + 3.3277948779935343e+01 * (x * x) * psi[14] * (y * y) + 2.2185299186623562e+00 * psi[14] + + -3.4369317712168801e+00 * x * psi[12] + 9.9215674164922145e+00 * (y * y) * psi[9] + + -3.4369317712168801e+00 * x * psi[11] + -1.3311179511974137e+01 * x * y * psi[13] + + -1.1092649593311780e+01 * psi[14] * (y * y) + + -3.9375000000000000e+01 * x * (y * y) * psi[15] + + -1.3125000000000000e+01 * (x * x * x) * psi[15] + -3.7500000000000000e+00 * y * psi[10] + + 2.9047375096555625e+00 * psi[6] * (x * x) + 5.8094750193111251e+00 * psi[7] * x * y + + -6.6555897559870685e+00 * (x * x) * psi[14] + + 5.7282196186947996e+00 * (x * x * x) * psi[11] + -1.9843134832984430e+00 * psi[9] + + 6.5625000000000000e+01 * (x * x * x) * (y * y) * psi[15] + + 3.3541019662496847e+00 * psi[5] * y + 1.1250000000000000e+01 * (x * x) * y * psi[10] + + 1.7184658856084400e+01 * x * (y * y) * psi[12] + 8.6602540378443860e-01 * psi[2]; + + sol.dRdZ[sidx] = -dpsidy / dpsidx * dx[0] / dx[1]; + sidx += 1; } } return sol; } - -static int -getR(const struct gkyl_range rzlocal, const struct gkyl_rect_grid rzgrid, struct gkyl_array *psiRZ, double psi, double Z, int nmaxroots, - double *R, double *dR) +static int getR( + const struct gkyl_range rzlocal, const struct gkyl_rect_grid rzgrid, struct gkyl_array *psiRZ, + double psi, double Z, int nmaxroots, double *R, double *dR +) { int zcell = get_idx(1, Z, &rzgrid, &rzlocal); int sidx = 0; - int idx[2] = { 0, zcell }; - double dx[2] = {rzgrid.dx[0], rzgrid.dx[1] }; - + int idx[2] = {0, zcell}; + double dx[2] = {rzgrid.dx[0], rzgrid.dx[1]}; + struct gkyl_range rangeR; - gkyl_range_deflate(&rangeR, &rzlocal, (int[]) { 0, 1 }, (int[]) { 0, zcell }); + gkyl_range_deflate(&rangeR, &rzlocal, (int[]){0, 1}, (int[]){0, zcell}); struct gkyl_range_iter riter; gkyl_range_iter_init(&riter, &rangeR); - + // loop over all R cells to find psi crossing - while (gkyl_range_iter_next(&riter) && sidx<=nmaxroots) { + while (gkyl_range_iter_next(&riter) && sidx <= nmaxroots) { long loc = gkyl_range_idx(&rangeR, riter.idx); const double *psih = gkyl_array_cfetch(psiRZ, loc); @@ -130,35 +198,37 @@ getR(const struct gkyl_range rzlocal, const struct gkyl_rect_grid rzgrid, struct gkyl_rect_grid_cell_center(&rzgrid, idx, xc); struct RdRdZ_sol sol = quad_root(psih, psi, Z, xc, dx); - - if (sol.nsol > 0) - for (int s=0; s 0) { + for (int s = 0; s < sol.nsol; ++s) { + R[sidx] = sol.R[s]; + dR[sidx] = sol.dRdZ[s]; + sidx += 1; } + } } return sidx; } -static int -getRcub(const struct gkyl_range rzlocal, const struct gkyl_rect_grid rzgrid, struct gkyl_array *psiRZ, double psi, double Z, int nmaxroots, - double *R, double *dR) +static int getRcub( + const struct gkyl_range rzlocal, const struct gkyl_rect_grid rzgrid, struct gkyl_array *psiRZ, + double psi, double Z, int nmaxroots, double *R, double *dR +) { int zcell = get_idx(1, Z, &rzgrid, &rzlocal); int sidx = 0; - int idx[2] = { 0, zcell }; - double dx[2] = {rzgrid.dx[0], rzgrid.dx[1] }; - + int idx[2] = {0, zcell}; + double dx[2] = {rzgrid.dx[0], rzgrid.dx[1]}; + struct gkyl_range rangeR; - gkyl_range_deflate(&rangeR, &rzlocal, (int[]) { 0, 1 }, (int[]) { 0, zcell }); + gkyl_range_deflate(&rangeR, &rzlocal, (int[]){0, 1}, (int[]){0, zcell}); struct gkyl_range_iter riter; gkyl_range_iter_init(&riter, &rangeR); - + // loop over all R cells to find psi crossing - while (gkyl_range_iter_next(&riter) && sidx<=nmaxroots) { + while (gkyl_range_iter_next(&riter) && sidx <= nmaxroots) { long loc = gkyl_range_idx(&rangeR, riter.idx); const double *psih = gkyl_array_cfetch(psiRZ, loc); @@ -167,53 +237,49 @@ getRcub(const struct gkyl_range rzlocal, const struct gkyl_rect_grid rzgrid, str gkyl_rect_grid_cell_center(&rzgrid, idx, xc); struct RdRdZ_sol sol = cub_root(psih, psi, Z, xc, dx); - - if (sol.nsol > 0) - for (int s=0; s 0) { + for (int s = 0; s < sol.nsol; ++s) { + R[sidx] = sol.R[s]; + dR[sidx] = sol.dRdZ[s]; + sidx += 1; } + } } return sidx; } - -void -time_roots_compare_quad_and_cub_ho(void) +void time_roots_compare_quad_and_cub_ho(void) { - clock_t start, end; double cpu_time_used; - struct gkyl_efit_inp inp = { + struct gkyl_efit_inp inp = { .filepath = "gyrokinetic/data/eqdsk/wham.geqdsk", .rz_poly_order = 2, .flux_poly_order = 1, - .reflect = true, + .reflect = true }; - struct gkyl_efit* efit = gkyl_efit_new(&inp); + struct gkyl_efit *efit = gkyl_efit_new(&inp); // project the cubic on cubic basis: this should result in the same // DG expansions - double lower[2] = {efit->rmin, efit->zmin }; + double lower[2] = {efit->rmin, efit->zmin}; double upper[2] = {efit->rmax, efit->zmax}; - int cells[2] = {efit->nr-1, efit->nz-1}; + int cells[2] = {efit->nr - 1, efit->nz - 1}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 2, lower, upper, cells); struct gkyl_range local, local_ext; - int nghost[GKYL_MAX_CDIM] = { 0, 0 }; + int nghost[GKYL_MAX_CDIM] = {0, 0}; gkyl_create_grid_ranges(&grid, nghost, &local_ext, &local); struct gkyl_basis basis; gkyl_cart_modal_tensor(&basis, 2, 3); - gkyl_proj_on_basis *projCub = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &grid, - .basis = &basis, - .num_ret_vals = 1, - .ctx = efit->evf->ctx, - .eval = efit->evf->eval_cubic - } - ); + gkyl_proj_on_basis *projCub = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &grid, + .basis = &basis, + .num_ret_vals = 1, + .ctx = efit->evf->ctx, + .eval = efit->evf->eval_cubic}); struct gkyl_array *psi_cubic_DG = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); gkyl_proj_on_basis_advance(projCub, 0.0, &local, psi_cubic_DG); gkyl_grid_sub_array_write(&grid, &local, 0, psi_cubic_DG, "psi_cubic.gkyl"); @@ -230,7 +296,7 @@ time_roots_compare_quad_and_cub_ho(void) start = clock(); nr = getR(efit->rzlocal, efit->rzgrid, efit->psizr, psi0, Z, nmaxroots, R, dR); end = clock(); - cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC; //printf("Quadratic total time = %g\n", cpu_time_used); double quad_time = cpu_time_used; @@ -240,16 +306,15 @@ time_roots_compare_quad_and_cub_ho(void) //for(int i=0; i // Allocate array (filled with zeros). -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } -void create_lower_dim_objects(int cdim_tar, struct gkyl_rect_grid grid_tar, int poly_order, - struct gkyl_rect_grid *grid, struct gkyl_rect_grid *confGrid, - struct gkyl_basis *basis, struct gkyl_basis *confBasis, - struct gkyl_range *confLocal, struct gkyl_range *confLocal_ext, - struct gkyl_range *local, struct gkyl_range *local_ext) +void create_lower_dim_objects( + int cdim_tar, struct gkyl_rect_grid grid_tar, int poly_order, struct gkyl_rect_grid *grid, + struct gkyl_rect_grid *confGrid, struct gkyl_basis *basis, struct gkyl_basis *confBasis, + struct gkyl_range *confLocal, struct gkyl_range *confLocal_ext, struct gkyl_range *local, + struct gkyl_range *local_ext +) { // Create lower dimensional grid, basis and range based on the target // dimensionality and grid. - const int ndim = grid_tar.ndim-1; - const int cdim = cdim_tar-1; - const int vdim = ndim-cdim; + const int ndim = grid_tar.ndim - 1; + const int cdim = cdim_tar - 1; + const int vdim = ndim - cdim; double confLower[GKYL_MAX_CDIM] = {0.0}, confUpper[GKYL_MAX_CDIM] = {0.0}; int confCells[GKYL_MAX_CDIM] = {0}; - confLower[cdim-1] = grid_tar.lower[cdim_tar-1]; - confUpper[cdim-1] = grid_tar.upper[cdim_tar-1]; - confCells[cdim-1] = grid_tar.cells[cdim_tar-1]; + confLower[cdim - 1] = grid_tar.lower[cdim_tar - 1]; + confUpper[cdim - 1] = grid_tar.upper[cdim_tar - 1]; + confCells[cdim - 1] = grid_tar.cells[cdim_tar - 1]; if (cdim_tar == 3) { confLower[0] = grid_tar.lower[0]; confUpper[0] = grid_tar.upper[0]; @@ -46,15 +47,15 @@ void create_lower_dim_objects(int cdim_tar, struct gkyl_rect_grid grid_tar, int double lower[GKYL_MAX_DIM] = {0.0}, upper[GKYL_MAX_DIM] = {0.0}; int cells[GKYL_MAX_DIM] = {0}; - for (int d=0; dmass; double n0 = tctx->n0; double upar = tctx->upar; - double vtsq = tctx->temp/mass; + double vtsq = tctx->temp / mass; int vdim = tctx->vdim; double den = den_profile_1x(n0, x); - fout[0] = (den/pow(2.0*M_PI*vtsq,vdim/2.0)) * exp(-(pow(vpar-upar,2)+2.0*mu*B0/mass)/(2.0*vtsq)); + fout[0] = (den / pow(2.0 * M_PI * vtsq, vdim / 2.0)) * + exp(-(pow(vpar - upar, 2) + 2.0 * mu * B0 / mass) / (2.0 * vtsq)); } -void -test_2x2v(int poly_order, bool use_gpu) +void test_2x2v(int poly_order, bool use_gpu) { const int cdim = 2; double vpar_max = 6.0; @@ -121,8 +124,8 @@ test_2x2v(int poly_order, bool use_gpu) double lower[] = {0.1, -M_PI, -vpar_max, 0.0}, upper[] = {1.0, M_PI, vpar_max, mu_max}; int cells[] = {2, 4, 6, 4}; - const int ndim = sizeof(cells)/sizeof(cells[0]); - const int vdim = ndim-cdim; + const int ndim = sizeof(cells) / sizeof(cells[0]); + const int vdim = ndim - cdim; struct test_ctx proj_ctx = { .n0 = 1.0, // Density. @@ -132,12 +135,12 @@ test_2x2v(int poly_order, bool use_gpu) .B0 = 1.0, // Magnetic field. .vdim = vdim, // Number of velocity space dimensions. .vpar_max = vpar_max, // Maximum vpar of the grid. - .mu_max = mu_max, // Maximum mu of the grid. + .mu_max = mu_max // Maximum mu of the grid. }; double confLower[GKYL_MAX_CDIM] = {0.0}, confUpper[GKYL_MAX_CDIM] = {0.0}; int confCells[GKYL_MAX_CDIM] = {0}; - for (int d=0; dncomp, distf_low->size) - : gkyl_array_acquire(distf_low); + distf_low_ho = use_gpu ? mkarr(false, distf_low->ncomp, distf_low->size) : + gkyl_array_acquire(distf_low); // Project the donor distribution. - gkyl_proj_on_basis *proj_distf_low = gkyl_proj_on_basis_new(&grid_low, &basis_low, - poly_order+1, 1, eval_distf_2x2v_low, &proj_ctx); + gkyl_proj_on_basis *proj_distf_low = gkyl_proj_on_basis_new( + &grid_low, &basis_low, poly_order + 1, 1, eval_distf_2x2v_low, &proj_ctx + ); gkyl_proj_on_basis_advance(proj_distf_low, 0.0, &local_low, distf_low_ho); gkyl_array_copy(distf_low, distf_low_ho); -// // Write distribution function to file. -// char fname0[1024]; -// sprintf(fname0, "ctest_translate_dim_2x2v_p%d_low.gkyl", poly_order); -// gkyl_grid_sub_array_write(&grid_low, &local_low, NULL, distf_low, fname0); + // // Write distribution function to file. + // char fname0[1024]; + // sprintf(fname0, "ctest_translate_dim_2x2v_p%d_low.gkyl", poly_order); + // gkyl_grid_sub_array_write(&grid_low, &local_low, NULL, distf_low, fname0); // Create target distribution function arrays. struct gkyl_array *distf_ho, *distf; distf = mkarr(use_gpu, basis.num_basis, local_ext.volume); - distf_ho = use_gpu? mkarr(false, distf->ncomp, distf->size) - : gkyl_array_acquire(distf); + distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : gkyl_array_acquire(distf); // Translate the DG coefficients. int cdim_do = confGrid_low.ndim; int vdim_do = grid_low.ndim - cdim_do; - struct gkyl_translate_dim* trans_dim_upd = gkyl_translate_dim_new(cdim_do, - basis_low, cdim, basis, 0, GKYL_NO_EDGE, use_gpu); + struct gkyl_translate_dim *trans_dim_upd = + gkyl_translate_dim_new(cdim_do, basis_low, cdim, basis, 0, GKYL_NO_EDGE, use_gpu); gkyl_translate_dim_advance(trans_dim_upd, &local_low, &local, distf_low, 1, distf); gkyl_array_copy(distf_ho, distf); -// // Write distribution function to file. -// char fname1[1024]; -// sprintf(fname1, "ctest_translate_dim_2x2v_p%d.gkyl", poly_order); -// gkyl_grid_sub_array_write(&grid, &local, NULL, distf_ho, fname1); - + // // Write distribution function to file. + // char fname1[1024]; + // sprintf(fname1, "ctest_translate_dim_2x2v_p%d.gkyl", poly_order); + // gkyl_grid_sub_array_write(&grid, &local, NULL, distf_ho, fname1); + // How DG coefficients of the higher dim field are mapped to those of the // lower dim field. If <0, its amplitude is 0. - int dg_map[] = {0,-1,1,2,3,-1,-1,4,-1,5,6,-1,-1,-1,7,-1,8,-1,9,10,-1,-1,11,-1}; + int dg_map[] = {0, -1, 1, 2, 3, -1, -1, 4, -1, 5, 6, -1, + -1, -1, 7, -1, 8, -1, 9, 10, -1, -1, 11, -1}; // Check coefficients of the higher dimensional field. int pidx_do[GKYL_MAX_DIM] = {-1}; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { - // Translate the target idx to the donor idx: - for (int d=0; dmass; double n0 = tctx->n0; double upar = tctx->upar; - double vtsq = tctx->temp/mass; + double vtsq = tctx->temp / mass; int vdim = tctx->vdim; double den = den_profile_2x(n0, x, y); - fout[0] = (den/pow(2.0*M_PI*vtsq,vdim/2.0)) * exp(-(pow(vpar-upar,2)+2.0*mu*B0/mass)/(2.0*vtsq)); + fout[0] = (den / pow(2.0 * M_PI * vtsq, vdim / 2.0)) * + exp(-(pow(vpar - upar, 2) + 2.0 * mu * B0 / mass) / (2.0 * vtsq)); } -void -test_3x2v(int poly_order, bool use_gpu) +void test_3x2v(int poly_order, bool use_gpu) { const int cdim = 3; double vpar_max = 6.0; @@ -280,8 +293,8 @@ test_3x2v(int poly_order, bool use_gpu) double lower[] = {0.1, -0.3, -M_PI, -vpar_max, 0.0}, upper[] = {1.0, 0.3, M_PI, vpar_max, mu_max}; int cells[] = {2, 2, 4, 6, 4}; - const int ndim = sizeof(cells)/sizeof(cells[0]); - const int vdim = ndim-cdim; + const int ndim = sizeof(cells) / sizeof(cells[0]); + const int vdim = ndim - cdim; struct test_ctx proj_ctx = { .n0 = 1.0, // Density. @@ -291,12 +304,12 @@ test_3x2v(int poly_order, bool use_gpu) .B0 = 1.0, // Magnetic field. .vdim = vdim, // Number of velocity space dimensions. .vpar_max = vpar_max, // Maximum vpar of the grid. - .mu_max = mu_max, // Maximum mu of the grid. + .mu_max = mu_max // Maximum mu of the grid. }; double confLower[GKYL_MAX_CDIM] = {0.0}, confUpper[GKYL_MAX_CDIM] = {0.0}; int confCells[GKYL_MAX_CDIM] = {0}; - for (int d=0; dncomp, distf_low->size) - : gkyl_array_acquire(distf_low); + distf_low_ho = use_gpu ? mkarr(false, distf_low->ncomp, distf_low->size) : + gkyl_array_acquire(distf_low); // Project the donor distribution. - gkyl_proj_on_basis *proj_distf_low = gkyl_proj_on_basis_new(&grid_low, &basis_low, - poly_order+1, 1, eval_distf_3x2v_low, &proj_ctx); + gkyl_proj_on_basis *proj_distf_low = gkyl_proj_on_basis_new( + &grid_low, &basis_low, poly_order + 1, 1, eval_distf_3x2v_low, &proj_ctx + ); gkyl_proj_on_basis_advance(proj_distf_low, 0.0, &local_low, distf_low_ho); gkyl_array_copy(distf_low, distf_low_ho); -// // Write distribution function to file. -// char fname0[1024]; -// sprintf(fname0, "ctest_translate_dim_3x2v_p%d_low.gkyl", poly_order); -// gkyl_grid_sub_array_write(&grid_low, &local_low, NULL, distf_low, fname0); + // // Write distribution function to file. + // char fname0[1024]; + // sprintf(fname0, "ctest_translate_dim_3x2v_p%d_low.gkyl", poly_order); + // gkyl_grid_sub_array_write(&grid_low, &local_low, NULL, distf_low, fname0); // Create target distribution function arrays. struct gkyl_array *distf_ho, *distf; distf = mkarr(use_gpu, basis.num_basis, local_ext.volume); - distf_ho = use_gpu? mkarr(false, distf->ncomp, distf->size) - : gkyl_array_acquire(distf); + distf_ho = use_gpu ? mkarr(false, distf->ncomp, distf->size) : gkyl_array_acquire(distf); // Translate the DG coefficients. int cdim_do = confGrid_low.ndim; int vdim_do = grid_low.ndim - cdim_do; - struct gkyl_translate_dim* trans_dim_upd = gkyl_translate_dim_new(cdim_do, - basis_low, cdim, basis, 0, GKYL_NO_EDGE, use_gpu); + struct gkyl_translate_dim *trans_dim_upd = + gkyl_translate_dim_new(cdim_do, basis_low, cdim, basis, 0, GKYL_NO_EDGE, use_gpu); gkyl_translate_dim_advance(trans_dim_upd, &local_low, &local, distf_low, 1, distf); gkyl_array_copy(distf_ho, distf); -// // Write distribution function to file. -// char fname1[1024]; -// sprintf(fname1, "ctest_translate_dim_3x2v_p%d.gkyl", poly_order); -// gkyl_grid_sub_array_write(&grid, &local, NULL, distf_ho, fname1); - + // // Write distribution function to file. + // char fname1[1024]; + // sprintf(fname1, "ctest_translate_dim_3x2v_p%d.gkyl", poly_order); + // gkyl_grid_sub_array_write(&grid, &local, NULL, distf_ho, fname1); + // How DG coefficients of the higher dim field are mapped to those of the // lower dim field. If <0, its amplitude is 0. - int dg_map[] = { - 0,1,-1,2,3,4,-1,5,-1,6,-1,7,8,-1,9,10,-1,-1,11,-1,-1,12,-1,13,-1,14, - -1,-1,-1,15,-1,-1,16,17,-1,18,19,-1,20,-1,21,-1,22,-1,-1,23,-1,-1 - }; + int dg_map[] = {0, 1, -1, 2, 3, 4, -1, 5, -1, 6, -1, 7, 8, -1, 9, 10, + -1, -1, 11, -1, -1, 12, -1, 13, -1, 14, -1, -1, -1, 15, -1, -1, + 16, 17, -1, 18, 19, -1, 20, -1, 21, -1, 22, -1, -1, 23, -1, -1}; // Check coefficients of the higher dimensional field. int pidx_do[GKYL_MAX_DIM] = {-1}; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local); while (gkyl_range_iter_next(&iter)) { - // Translate the target idx to the donor idx: - for (int d=0; dndim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } // for testing - int num_send_neigh[] = { 1, 2, 2 }; + int num_send_neigh[] = {1, 2, 2}; // for testing (these hard-coded values depend on how the algorithm - // is implemented) - struct gkyl_comm_conn conn_0[] = { - { .block_id = 0, .rank = 0 }, - }; - gkyl_range_init(&conn_0[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); + // is implemented) + struct gkyl_comm_conn conn_0[] = {{.block_id = 0, .rank = 0}}; + gkyl_range_init(&conn_0[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); - struct gkyl_comm_conn conn_1[] = { - { .block_id = 1, .rank = 0 }, - { .block_id = 2, .rank = 0 }, - }; - gkyl_range_init(&conn_1[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - gkyl_range_init(&conn_1[1].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - - struct gkyl_comm_conn conn_2[] = { - { .block_id = 1, .rank = 0 }, - { .block_id = 2, .rank = 0 }, - }; - gkyl_range_init(&conn_2[0].range, 2, (int[]) { 301, 1 }, (int[]) { 600, 300 }); - gkyl_range_init(&conn_2[1].range, 2, (int[]) { 301, 1 }, (int[]) { 600, 300 }); - - struct gkyl_comm_conn *block_conn[] = { conn_0, conn_1, conn_2 }; - - for (int bid=0; bidnum_comm_conn ); + struct gkyl_comm_conn conn_1[] = {{.block_id = 1, .rank = 0}, {.block_id = 2, .rank = 0}}; + gkyl_range_init(&conn_1[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); + gkyl_range_init(&conn_1[1].range, 2, (int[]){1, 1}, (int[]){300, 300}); + + struct gkyl_comm_conn conn_2[] = {{.block_id = 1, .rank = 0}, {.block_id = 2, .rank = 0}}; + gkyl_range_init(&conn_2[0].range, 2, (int[]){301, 1}, (int[]){600, 300}); + gkyl_range_init(&conn_2[1].range, 2, (int[]){301, 1}, (int[]){600, 300}); + + struct gkyl_comm_conn *block_conn[] = {conn_0, conn_1, conn_2}; + + for (int bid = 0; bid < num_blocks; ++bid) { + for (int brank = 0; brank < num_cuts[bid]; ++brank) { + struct gkyl_multib_comm_conn *mbcc = gkyl_multib_comm_conn_new_send_from_connections( + bid, brank, nghost, nconnected[bid], block_list[bid], dir, decomp + ); + + TEST_CHECK(num_send_neigh[bid] == mbcc->num_comm_conn); if (mbcc->num_comm_conn > 0) { - for (int ns=0; nsnum_comm_conn; ++ns) { - TEST_CHECK( block_conn[bid][ns].block_id == mbcc->comm_conn[ns].block_id); - TEST_CHECK( block_conn[bid][ns].rank == mbcc->comm_conn[ns].rank); - TEST_CHECK( gkyl_range_compare(&block_conn[bid][ns].range, &mbcc->comm_conn[ns].range) ); + for (int ns = 0; ns < mbcc->num_comm_conn; ++ns) { + TEST_CHECK(block_conn[bid][ns].block_id == mbcc->comm_conn[ns].block_id); + TEST_CHECK(block_conn[bid][ns].rank == mbcc->comm_conn[ns].rank); + TEST_CHECK(gkyl_range_compare(&block_conn[bid][ns].range, &mbcc->comm_conn[ns].range)); } } @@ -352,88 +348,82 @@ test_L_domain_send_connections_dir0_cuts1_ho() } } - for (int i=0; indim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } // for testing - int num_recv_neigh[] = { 1, 2, 2 }; + int num_recv_neigh[] = {1, 2, 2}; // for testing (these hard-coded values depend on how the algorithm - // is implemented) - struct gkyl_comm_conn conn_0[] = { - { .block_id = 0, .rank = 0 }, - }; - gkyl_range_init(&conn_0[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); + // is implemented) + struct gkyl_comm_conn conn_0[] = {{.block_id = 0, .rank = 0}}; + gkyl_range_init(&conn_0[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); - struct gkyl_comm_conn conn_1[] = { - { .block_id = 1, .rank = 0 }, - { .block_id = 2, .rank = 0 }, - }; - gkyl_range_init(&conn_1[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - gkyl_range_init(&conn_1[1].range, 2, (int[]) { 301, 1 }, (int[]) { 600, 300 }); - - struct gkyl_comm_conn conn_2[] = { - { .block_id = 1, .rank = 0 }, - { .block_id = 2, .rank = 0 }, - }; - gkyl_range_init(&conn_2[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - gkyl_range_init(&conn_2[1].range, 2, (int[]) { 301, 1 }, (int[]) { 600, 300 }); - - struct gkyl_comm_conn *block_conn[] = { conn_0, conn_1, conn_2 }; - - for (int bid=0; bidnum_comm_conn ); + struct gkyl_comm_conn conn_1[] = {{.block_id = 1, .rank = 0}, {.block_id = 2, .rank = 0}}; + gkyl_range_init(&conn_1[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); + gkyl_range_init(&conn_1[1].range, 2, (int[]){301, 1}, (int[]){600, 300}); + + struct gkyl_comm_conn conn_2[] = {{.block_id = 1, .rank = 0}, {.block_id = 2, .rank = 0}}; + gkyl_range_init(&conn_2[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); + gkyl_range_init(&conn_2[1].range, 2, (int[]){301, 1}, (int[]){600, 300}); + + struct gkyl_comm_conn *block_conn[] = {conn_0, conn_1, conn_2}; + + for (int bid = 0; bid < num_blocks; ++bid) { + for (int brank = 0; brank < num_cuts[bid]; ++brank) { + struct gkyl_multib_comm_conn *mbcc = gkyl_multib_comm_conn_new_recv_from_connections( + bid, brank, nghost, nconnected[bid], block_list[bid], dir, decomp + ); + + TEST_CHECK(num_recv_neigh[bid] == mbcc->num_comm_conn); if (mbcc->num_comm_conn > 0) { - for (int ns=0; nsnum_comm_conn; ++ns) { - TEST_CHECK( block_conn[bid][ns].block_id == mbcc->comm_conn[ns].block_id); - TEST_CHECK( block_conn[bid][ns].rank == mbcc->comm_conn[ns].rank); - TEST_CHECK( gkyl_range_compare(&block_conn[bid][ns].range, &mbcc->comm_conn[ns].range) ); + for (int ns = 0; ns < mbcc->num_comm_conn; ++ns) { + TEST_CHECK(block_conn[bid][ns].block_id == mbcc->comm_conn[ns].block_id); + TEST_CHECK(block_conn[bid][ns].rank == mbcc->comm_conn[ns].rank); + TEST_CHECK(gkyl_range_compare(&block_conn[bid][ns].range, &mbcc->comm_conn[ns].range)); } } @@ -441,161 +431,165 @@ test_L_domain_recv_connections_dir0_cuts1_ho() } } - for (int i=0; indim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } - // for testing - int num_send_neigh[] = { 1, 3, 3 }; + int num_send_neigh[] = {1, 3, 3}; // for testing (these hard-coded values depend on how the algorithm - // is implemented) - struct gkyl_comm_conn conn_0[] = { - { .block_id = 0, .rank = 0 }, - }; - gkyl_range_init(&conn_0[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); + // is implemented) + struct gkyl_comm_conn conn_0[] = {{.block_id = 0, .rank = 0}}; + gkyl_range_init(&conn_0[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); struct gkyl_comm_conn conn_1[] = { - { .block_id = 1, .rank = 0 }, // from 0th cut - { .block_id = 2, .rank = 0 }, // from 0th cut - { .block_id = 2, .rank = 0 }, // from 0th cut + {.block_id = 1, .rank = 0}, // from 0th cut + {.block_id = 2, .rank = 0}, // from 0th cut + {.block_id = 2, .rank = 0} // from 0th cut }; - gkyl_range_init(&conn_1[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - gkyl_range_init(&conn_1[1].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - gkyl_range_init(&conn_1[2].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - + gkyl_range_init(&conn_1[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); + gkyl_range_init(&conn_1[1].range, 2, (int[]){1, 1}, (int[]){300, 300}); + gkyl_range_init(&conn_1[2].range, 2, (int[]){1, 1}, (int[]){300, 300}); + struct gkyl_comm_conn conn_2[] = { - { .block_id = 1, .rank = 0 }, // from 0th cut - { .block_id = 2, .rank = 0 }, // from 0th cut - { .block_id = 2, .rank = 0 }, // from 0th cut - { .block_id = 1, .rank = 0 }, // from 1st cut - { .block_id = 2, .rank = 0 }, // from 1st cut - { .block_id = 2, .rank = 0 }, // from 1st cut + {.block_id = 1, .rank = 0}, // from 0th cut + {.block_id = 2, .rank = 0}, // from 0th cut + {.block_id = 2, .rank = 0}, // from 0th cut + {.block_id = 1, .rank = 0}, // from 1st cut + {.block_id = 2, .rank = 0}, // from 1st cut + {.block_id = 2, .rank = 0} // from 1st cut }; - gkyl_range_init(&conn_2[0].range, 2, (int[]) { 301, 1 }, (int[]) { 450, 300 }); - gkyl_range_init(&conn_2[1].range, 2, (int[]) { 301, 1 }, (int[]) { 450, 300 }); - gkyl_range_init(&conn_2[2].range, 2, (int[]) { 301, 1 }, (int[]) { 450, 300 }); - gkyl_range_init(&conn_2[3].range, 2, (int[]) { 451, 1 }, (int[]) { 600, 300 }); - gkyl_range_init(&conn_2[4].range, 2, (int[]) { 451, 1 }, (int[]) { 600, 300 }); - gkyl_range_init(&conn_2[5].range, 2, (int[]) { 451, 1 }, (int[]) { 600, 300 }); - - struct gkyl_comm_conn *block_conn[] = { conn_0, conn_1, conn_2 }; - - for (int bid=0; bidnum_comm_conn ); + gkyl_range_init(&conn_2[0].range, 2, (int[]){301, 1}, (int[]){450, 300}); + gkyl_range_init(&conn_2[1].range, 2, (int[]){301, 1}, (int[]){450, 300}); + gkyl_range_init(&conn_2[2].range, 2, (int[]){301, 1}, (int[]){450, 300}); + gkyl_range_init(&conn_2[3].range, 2, (int[]){451, 1}, (int[]){600, 300}); + gkyl_range_init(&conn_2[4].range, 2, (int[]){451, 1}, (int[]){600, 300}); + gkyl_range_init(&conn_2[5].range, 2, (int[]){451, 1}, (int[]){600, 300}); + + struct gkyl_comm_conn *block_conn[] = {conn_0, conn_1, conn_2}; + + for (int bid = 0; bid < num_blocks; ++bid) { + int start_ns = 0; + for (int brank = 0; brank < num_cuts[bid]; ++brank) { + struct gkyl_multib_comm_conn *mbcc = gkyl_multib_comm_conn_new_send_from_connections( + bid, brank, nghost, nconnected[bid], block_list[bid], dir, decomp + ); + TEST_CHECK(num_send_neigh[bid] == mbcc->num_comm_conn); if (mbcc->num_comm_conn > 0) { - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc->num_comm_conn; ++ns) { // need to get the actual rank that owns this cut int rank_list[decomp[mbcc->comm_conn[ns].block_id]->ndecomp]; // max number of ranks int rank_idx = mbcc->comm_conn[ns].rank; gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc->comm_conn[ns].block_id, rank_list); mbcc->comm_conn[ns].rank = rank_list[rank_idx]; - TEST_CHECK( block_conn[bid][start_ns+ns].block_id == mbcc->comm_conn[ns].block_id); - TEST_CHECK( block_conn[bid][start_ns+ns].rank == mbcc->comm_conn[ns].rank); - TEST_CHECK( gkyl_range_compare(&block_conn[bid][start_ns+ns].range, &mbcc->comm_conn[ns].range) ); + TEST_CHECK(block_conn[bid][start_ns + ns].block_id == mbcc->comm_conn[ns].block_id); + TEST_CHECK(block_conn[bid][start_ns + ns].rank == mbcc->comm_conn[ns].rank); + TEST_CHECK( + gkyl_range_compare(&block_conn[bid][start_ns + ns].range, &mbcc->comm_conn[ns].range) + ); } } - start_ns+=mbcc->num_comm_conn; + start_ns += mbcc->num_comm_conn; gkyl_multib_comm_conn_release(mbcc); } } - for (int i=0; indim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } - // for testing - int num_send_neigh[] = { 1, 3, 3 }; + int num_send_neigh[] = {1, 3, 3}; // for testing (these hard-coded values depend on how the algorithm - // is implemented) - struct gkyl_comm_conn conn_0[] = { - { .block_id = 0, .rank = 0 }, - }; - gkyl_range_init(&conn_0[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); + // is implemented) + struct gkyl_comm_conn conn_0[] = {{.block_id = 0, .rank = 0}}; + gkyl_range_init(&conn_0[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); struct gkyl_comm_conn conn_1[] = { - { .block_id = 1, .rank = 1 }, // from 0th cut - { .block_id = 2, .rank = 0 }, // from 0th cut to 0th cut - { .block_id = 2, .rank = 1 }, // from 0th cut to 1st cut + {.block_id = 1, .rank = 1}, // from 0th cut + {.block_id = 2, .rank = 0}, // from 0th cut to 0th cut + {.block_id = 2, .rank = 1} // from 0th cut to 1st cut }; - gkyl_range_init(&conn_1[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - gkyl_range_init(&conn_1[1].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - gkyl_range_init(&conn_1[2].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - + gkyl_range_init(&conn_1[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); + gkyl_range_init(&conn_1[1].range, 2, (int[]){1, 1}, (int[]){300, 300}); + gkyl_range_init(&conn_1[2].range, 2, (int[]){1, 1}, (int[]){300, 300}); + struct gkyl_comm_conn conn_2[] = { - { .block_id = 1, .rank = 1 }, // from 0th cut - { .block_id = 2, .rank = 0 }, // from 0th cut to 0th cut - { .block_id = 2, .rank = 1 }, // from 0th cut to 1st cut - { .block_id = 1, .rank = 1 }, // from 1st cut to 0th cut - { .block_id = 2, .rank = 0 }, // from 1st cut to 0th cut - { .block_id = 2, .rank = 1 }, // from 1st cut to 1st cut + {.block_id = 1, .rank = 1}, // from 0th cut + {.block_id = 2, .rank = 0}, // from 0th cut to 0th cut + {.block_id = 2, .rank = 1}, // from 0th cut to 1st cut + {.block_id = 1, .rank = 1}, // from 1st cut to 0th cut + {.block_id = 2, .rank = 0}, // from 1st cut to 0th cut + {.block_id = 2, .rank = 1} // from 1st cut to 1st cut }; - gkyl_range_init(&conn_2[0].range, 2, (int[]) { 301, 1 }, (int[]) { 450, 300 }); - gkyl_range_init(&conn_2[1].range, 2, (int[]) { 301, 1 }, (int[]) { 450, 300 }); - gkyl_range_init(&conn_2[2].range, 2, (int[]) { 301, 1 }, (int[]) { 450, 300 }); - gkyl_range_init(&conn_2[3].range, 2, (int[]) { 451, 1 }, (int[]) { 600, 300 }); - gkyl_range_init(&conn_2[4].range, 2, (int[]) { 451, 1 }, (int[]) { 600, 300 }); - gkyl_range_init(&conn_2[5].range, 2, (int[]) { 451, 1 }, (int[]) { 600, 300 }); - - struct gkyl_comm_conn *block_conn[] = { conn_0, conn_1, conn_2 }; - - for (int bid=0; bidnum_comm_conn ); - for (int ns=0; nsnum_comm_conn; ++ns) { + gkyl_range_init(&conn_2[0].range, 2, (int[]){301, 1}, (int[]){450, 300}); + gkyl_range_init(&conn_2[1].range, 2, (int[]){301, 1}, (int[]){450, 300}); + gkyl_range_init(&conn_2[2].range, 2, (int[]){301, 1}, (int[]){450, 300}); + gkyl_range_init(&conn_2[3].range, 2, (int[]){451, 1}, (int[]){600, 300}); + gkyl_range_init(&conn_2[4].range, 2, (int[]){451, 1}, (int[]){600, 300}); + gkyl_range_init(&conn_2[5].range, 2, (int[]){451, 1}, (int[]){600, 300}); + + struct gkyl_comm_conn *block_conn[] = {conn_0, conn_1, conn_2}; + + for (int bid = 0; bid < num_blocks; ++bid) { + int start_ns = 0; + for (int brank = 0; brank < num_cuts[bid]; ++brank) { + struct gkyl_multib_comm_conn *mbcc = gkyl_multib_comm_conn_new_send_from_connections( + bid, brank, nghost, nconnected[bid], block_list[bid], dir, decomp + ); + TEST_CHECK(num_send_neigh[bid] == mbcc->num_comm_conn); + for (int ns = 0; ns < mbcc->num_comm_conn; ++ns) { // need to get the actual rank that owns this cut int rank_list[gkyl_rrobin_decomp_nranks(round_robin_decomp, mbcc->comm_conn[ns].block_id)]; int rank_idx = mbcc->comm_conn[ns].rank; gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc->comm_conn[ns].block_id, rank_list); mbcc->comm_conn[ns].rank = rank_list[rank_idx]; - TEST_CHECK( block_conn[bid][start_ns+ns].block_id == mbcc->comm_conn[ns].block_id); - TEST_CHECK( block_conn[bid][start_ns+ns].rank == mbcc->comm_conn[ns].rank); - TEST_CHECK( gkyl_range_compare(&block_conn[bid][start_ns+ns].range, &mbcc->comm_conn[ns].range) ); + TEST_CHECK(block_conn[bid][start_ns + ns].block_id == mbcc->comm_conn[ns].block_id); + TEST_CHECK(block_conn[bid][start_ns + ns].rank == mbcc->comm_conn[ns].rank); + TEST_CHECK( + gkyl_range_compare(&block_conn[bid][start_ns + ns].range, &mbcc->comm_conn[ns].range) + ); } - start_ns+=mbcc->num_comm_conn; + start_ns += mbcc->num_comm_conn; gkyl_multib_comm_conn_release(mbcc); } } - for (int i=0; indim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } - // for testing - int num_recv_neigh[] = { 1, 3, 3 }; + int num_recv_neigh[] = {1, 3, 3}; // for testing (these hard-coded values depend on how the algorithm - // is implemented) - struct gkyl_comm_conn conn_0[] = { - { .block_id = 0, .rank = 0 }, - }; - gkyl_range_init(&conn_0[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); + // is implemented) + struct gkyl_comm_conn conn_0[] = {{.block_id = 0, .rank = 0}}; + gkyl_range_init(&conn_0[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); struct gkyl_comm_conn conn_1[] = { - { .block_id = 1, .rank = 1 }, // into 0th from 0th cut - { .block_id = 2, .rank = 0 }, // into 0th cut from 0th cut - { .block_id = 2, .rank = 1 }, // into 0th cut from 1st cut + {.block_id = 1, .rank = 1}, // into 0th from 0th cut + {.block_id = 2, .rank = 0}, // into 0th cut from 0th cut + {.block_id = 2, .rank = 1} // into 0th cut from 1st cut }; - gkyl_range_init(&conn_1[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - gkyl_range_init(&conn_1[1].range, 2, (int[]) { 301, 1 }, (int[]) { 450, 300 }); - gkyl_range_init(&conn_1[2].range, 2, (int[]) { 451, 1 }, (int[]) { 600, 300 }); - + gkyl_range_init(&conn_1[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); + gkyl_range_init(&conn_1[1].range, 2, (int[]){301, 1}, (int[]){450, 300}); + gkyl_range_init(&conn_1[2].range, 2, (int[]){451, 1}, (int[]){600, 300}); + struct gkyl_comm_conn conn_2[] = { - { .block_id = 1, .rank = 1 }, // into 0th cut from 0th cut - { .block_id = 2, .rank = 0 }, // into 0th cut from 0th cut - { .block_id = 2, .rank = 1 }, // into 0th cut from 1st cut - { .block_id = 1, .rank = 1 }, // into 1st cut from 0th cut - { .block_id = 2, .rank = 0 }, // into 1st cut from 0th cut - { .block_id = 2, .rank = 1 }, // into 1st cut from 1st cut + {.block_id = 1, .rank = 1}, // into 0th cut from 0th cut + {.block_id = 2, .rank = 0}, // into 0th cut from 0th cut + {.block_id = 2, .rank = 1}, // into 0th cut from 1st cut + {.block_id = 1, .rank = 1}, // into 1st cut from 0th cut + {.block_id = 2, .rank = 0}, // into 1st cut from 0th cut + {.block_id = 2, .rank = 1} // into 1st cut from 1st cut }; - gkyl_range_init(&conn_2[0].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - gkyl_range_init(&conn_2[1].range, 2, (int[]) { 301, 1 }, (int[]) { 450, 300 }); - gkyl_range_init(&conn_2[2].range, 2, (int[]) { 451, 1 }, (int[]) { 600, 300 }); - gkyl_range_init(&conn_2[3].range, 2, (int[]) { 1, 1 }, (int[]) { 300, 300 }); - gkyl_range_init(&conn_2[4].range, 2, (int[]) { 301, 1 }, (int[]) { 450, 300 }); - gkyl_range_init(&conn_2[5].range, 2, (int[]) { 451, 1 }, (int[]) { 600, 300 }); - - struct gkyl_comm_conn *block_conn[] = { conn_0, conn_1, conn_2 }; - - for (int bid=0; bidnum_comm_conn ); - for (int ns=0; nsnum_comm_conn; ++ns) { + gkyl_range_init(&conn_2[0].range, 2, (int[]){1, 1}, (int[]){300, 300}); + gkyl_range_init(&conn_2[1].range, 2, (int[]){301, 1}, (int[]){450, 300}); + gkyl_range_init(&conn_2[2].range, 2, (int[]){451, 1}, (int[]){600, 300}); + gkyl_range_init(&conn_2[3].range, 2, (int[]){1, 1}, (int[]){300, 300}); + gkyl_range_init(&conn_2[4].range, 2, (int[]){301, 1}, (int[]){450, 300}); + gkyl_range_init(&conn_2[5].range, 2, (int[]){451, 1}, (int[]){600, 300}); + + struct gkyl_comm_conn *block_conn[] = {conn_0, conn_1, conn_2}; + + for (int bid = 0; bid < num_blocks; ++bid) { + int start_ns = 0; + for (int brank = 0; brank < num_cuts[bid]; ++brank) { + struct gkyl_multib_comm_conn *mbcc = gkyl_multib_comm_conn_new_recv_from_connections( + bid, brank, nghost, nconnected[bid], block_list[bid], dir, decomp + ); + TEST_CHECK(num_recv_neigh[bid] == mbcc->num_comm_conn); + for (int ns = 0; ns < mbcc->num_comm_conn; ++ns) { // need to get the actual rank that owns this cut int rank_list[gkyl_rrobin_decomp_nranks(round_robin_decomp, mbcc->comm_conn[ns].block_id)]; int rank_idx = mbcc->comm_conn[ns].rank; gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc->comm_conn[ns].block_id, rank_list); mbcc->comm_conn[ns].rank = rank_list[rank_idx]; - TEST_CHECK( block_conn[bid][start_ns+ns].block_id == mbcc->comm_conn[ns].block_id); - TEST_CHECK( block_conn[bid][start_ns+ns].rank == mbcc->comm_conn[ns].rank); - TEST_CHECK( gkyl_range_compare(&block_conn[bid][start_ns+ns].range, &mbcc->comm_conn[ns].range) ); + TEST_CHECK(block_conn[bid][start_ns + ns].block_id == mbcc->comm_conn[ns].block_id); + TEST_CHECK(block_conn[bid][start_ns + ns].rank == mbcc->comm_conn[ns].rank); + TEST_CHECK( + gkyl_range_compare(&block_conn[bid][start_ns + ns].range, &mbcc->comm_conn[ns].range) + ); } - start_ns+=mbcc->num_comm_conn; + start_ns += mbcc->num_comm_conn; gkyl_multib_comm_conn_release(mbcc); } } - for (int i=0; i 1 ? 2 : 1; - + int cuts_flat[] = { - 1, 1, // Block 0. - 1, 1, // Block 1. - ncuts_block2, 1, // Block 2. + 1, + 1, // Block 0. + 1, + 1, // Block 1. + ncuts_block2, + 1 // Block 2. }; int **cuts = cuts_array_new(num_blocks, ndim, cuts_flat); - struct gkyl_block_geom *geom = create_L_domain_block_geom(cuts); + struct gkyl_block_geom *geom = create_L_domain_block_geom(cuts); struct gkyl_block_topo *topo = gkyl_block_geom_topo(geom); // Construct decomp objects. int *branks = gkyl_malloc(sizeof(int[num_blocks])); - for (int i=0; indim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } - int lidx = 0; int local_blocks[num_blocks]; int num_local_blocks = 0; - for (int i=0; iranges[brank]; gkyl_create_ranges(&decomp[bid]->ranges[brank], nghost, local_ranges_ext[bI], local_ranges[bI]); } @@ -975,72 +977,91 @@ test_L_domain_allgather_dir0_cuts2_par_ho() struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); // populate locals - for (int bI=0; bIvolume); - gkyl_array_shiftc(array_local[bI], sqrt(pow(2,ndim)), 0); // Sets es_energy_fac=1. - if (num_ranks > 1) - gkyl_array_scale(array_local[bI], 0.5*my_rank); - else - gkyl_array_scale(array_local[bI], 10.0*bid); - array_global[bI] = mkarr(false, basis.num_basis, global_ranges_ext[bI]->volume); + gkyl_array_shiftc(array_local[bI], sqrt(pow(2, ndim)), 0); // Sets es_energy_fac=1. + if (num_ranks > 1) { + gkyl_array_scale(array_local[bI], 0.5 * my_rank); + } else { + gkyl_array_scale(array_local[bI], 10.0 * bid); + } + array_global[bI] = mkarr(false, basis.num_basis, global_ranges_ext[bI]->volume); } - - struct gkyl_multib_comm_conn **mbcc_send = gkyl_malloc(num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - struct gkyl_multib_comm_conn **mbcc_recv = gkyl_malloc(num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - for (int bI= 0; bInum_comm_conn; ++ns) { - // need to get the actual rank that owns this cut - int rank_idx = mbcc_send[bI]->comm_conn[ns].rank; - gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc_send[bI]->comm_conn[ns].block_id, rank_list); - mbcc_send[bI]->comm_conn[ns].rank = rank_list[rank_idx]; - // Make range a subrange - mbcc_send[bI]->comm_conn[ns].range = *local_ranges[bI]; - } - for (int nr=0; nrnum_comm_conn; ++nr) { - // need to get the actual rank that owns this cut - int rank_idx = mbcc_recv[bI]->comm_conn[nr].rank; - gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc_recv[bI]->comm_conn[nr].block_id, rank_list); - mbcc_recv[bI]->comm_conn[nr].rank = rank_list[rank_idx]; - // Make range a subrange - gkyl_sub_range_init(&mbcc_recv[bI]->comm_conn[nr].range, global_ranges_ext[bI], mbcc_recv[bI]->comm_conn[nr].range.lower, mbcc_recv[bI]->comm_conn[nr].range.upper); + struct gkyl_multib_comm_conn **mbcc_send = + gkyl_malloc(num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + struct gkyl_multib_comm_conn **mbcc_recv = + gkyl_malloc(num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); + for (int bI = 0; bI < num_local_blocks; bI++) { + int bid = local_blocks[bI]; + gkyl_rrobin_decomp_getranks(round_robin_decomp, bid, rank_list); + int brank = -1; + for (int i = 0; i < branks[bid]; ++i) { + if (rank_list[i] == my_rank) { + brank = i; } + } - } + mbcc_send[bI] = gkyl_multib_comm_conn_new_send_from_connections( + bid, brank, nghost, nconnected[bid], block_list[bid], dir, decomp + ); + mbcc_recv[bI] = gkyl_multib_comm_conn_new_recv_from_connections( + bid, brank, nghost, nconnected[bid], block_list[bid], dir, decomp + ); - int stat = gkyl_multib_comm_conn_array_transfer(comm, num_local_blocks, local_blocks, mbcc_send, mbcc_recv, array_local, array_global); + for (int ns = 0; ns < mbcc_send[bI]->num_comm_conn; ++ns) { + // need to get the actual rank that owns this cut + int rank_idx = mbcc_send[bI]->comm_conn[ns].rank; + gkyl_rrobin_decomp_getranks( + round_robin_decomp, mbcc_send[bI]->comm_conn[ns].block_id, rank_list + ); + mbcc_send[bI]->comm_conn[ns].rank = rank_list[rank_idx]; + // Make range a subrange + mbcc_send[bI]->comm_conn[ns].range = *local_ranges[bI]; + } + for (int nr = 0; nr < mbcc_recv[bI]->num_comm_conn; ++nr) { + // need to get the actual rank that owns this cut + int rank_idx = mbcc_recv[bI]->comm_conn[nr].rank; + gkyl_rrobin_decomp_getranks( + round_robin_decomp, mbcc_recv[bI]->comm_conn[nr].block_id, rank_list + ); + mbcc_recv[bI]->comm_conn[nr].rank = rank_list[rank_idx]; + // Make range a subrange + gkyl_sub_range_init( + &mbcc_recv[bI]->comm_conn[nr].range, global_ranges_ext[bI], + mbcc_recv[bI]->comm_conn[nr].range.lower, mbcc_recv[bI]->comm_conn[nr].range.upper + ); + } + } + int stat = gkyl_multib_comm_conn_array_transfer( + comm, num_local_blocks, local_blocks, mbcc_send, mbcc_recv, array_local, array_global + ); - for (int bI=0; bI 1 ? 2 : 1; - + int cuts_flat[] = { 1, 1, // Block 0. 1, ncuts_block1, // Block 1. - 1, 1, // Block 2. + 1, 1 // Block 2. }; int **cuts = cuts_array_new(num_blocks, ndim, cuts_flat); - struct gkyl_block_geom *geom = create_SOL_domain_block_geom(cuts); + struct gkyl_block_geom *geom = create_SOL_domain_block_geom(cuts); struct gkyl_block_topo *topo = gkyl_block_geom_topo(geom); // Construct decomp objects. int *branks = gkyl_malloc(sizeof(int[num_blocks])); - for (int i=0; indim; ++d) + for (int d = 0; d < topo->ndim; ++d) { num_cuts[i] *= ginfo->cuts[d]; - + } + struct gkyl_range range; gkyl_create_global_range(2, ginfo->cells, &range); decomp[i] = gkyl_rect_decomp_new_from_cuts(2, ginfo->cuts, &range); } - int lidx = 0; int local_blocks[num_blocks]; int num_local_blocks = 0; - for (int i=0; iranges[brank], nghost, local_ranges_ext[bI], local_ranges[bI]); } @@ -1200,126 +1228,141 @@ test_SOL_domain_allgather_dir1_cuts2_par(bool use_gpu) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); // populate locals - for (int bI=0; bIvolume); - array_local_ho[bI] = use_gpu ? mkarr(false, basis.num_basis, local_ranges_ext[bI]->volume) - : gkyl_array_acquire(array_local[bI]); - gkyl_array_shiftc(array_local[bI], sqrt(pow(2,ndim)), 0); // Sets es_energy_fac=1. - if (num_ranks > 1) - gkyl_array_scale(array_local[bI], 0.5*my_rank); - else - gkyl_array_scale_range(array_local[bI], 100.0*bid, local_ranges[bI]); - array_global[bI] = mkarr(use_gpu, basis.num_basis, global_ranges_ext[bI]->volume); - array_global_ho[bI] = use_gpu ? mkarr(false, basis.num_basis, global_ranges_ext[bI]->volume) : gkyl_array_acquire(array_global[bI]); + array_local_ho[bI] = use_gpu ? mkarr(false, basis.num_basis, local_ranges_ext[bI]->volume) : + gkyl_array_acquire(array_local[bI]); + gkyl_array_shiftc(array_local[bI], sqrt(pow(2, ndim)), 0); // Sets es_energy_fac=1. + if (num_ranks > 1) { + gkyl_array_scale(array_local[bI], 0.5 * my_rank); + } else { + gkyl_array_scale_range(array_local[bI], 100.0 * bid, local_ranges[bI]); + } + array_global[bI] = mkarr(use_gpu, basis.num_basis, global_ranges_ext[bI]->volume); + array_global_ho[bI] = use_gpu ? mkarr(false, basis.num_basis, global_ranges_ext[bI]->volume) : + gkyl_array_acquire(array_global[bI]); } printf("made arrays\n"); - - struct gkyl_multib_comm_conn **mbcc_send = gkyl_malloc(num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - struct gkyl_multib_comm_conn **mbcc_recv = gkyl_malloc(num_local_blocks * sizeof(struct gkyl_multib_comm_conn *)); - for (int bI= 0; bInum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_send[bI]->num_comm_conn; ++ns) { // need to get the actual rank that owns this cut int rank_idx = mbcc_send[bI]->comm_conn[ns].rank; - gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc_send[bI]->comm_conn[ns].block_id, rank_list); + gkyl_rrobin_decomp_getranks( + round_robin_decomp, mbcc_send[bI]->comm_conn[ns].block_id, rank_list + ); mbcc_send[bI]->comm_conn[ns].rank = rank_list[rank_idx]; // Make range a subrange mbcc_send[bI]->comm_conn[ns].range = *local_ranges[bI]; } - for (int nr=0; nrnum_comm_conn; ++nr) { + for (int nr = 0; nr < mbcc_recv[bI]->num_comm_conn; ++nr) { // need to get the actual rank that owns this cut int rank_idx = mbcc_recv[bI]->comm_conn[nr].rank; - gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc_recv[bI]->comm_conn[nr].block_id, rank_list); + gkyl_rrobin_decomp_getranks( + round_robin_decomp, mbcc_recv[bI]->comm_conn[nr].block_id, rank_list + ); mbcc_recv[bI]->comm_conn[nr].rank = rank_list[rank_idx]; // Make range a subrange - gkyl_sub_range_init(&mbcc_recv[bI]->comm_conn[nr].range, global_ranges_ext[bI], mbcc_recv[bI]->comm_conn[nr].range.lower, mbcc_recv[bI]->comm_conn[nr].range.upper); + gkyl_sub_range_init( + &mbcc_recv[bI]->comm_conn[nr].range, global_ranges_ext[bI], + mbcc_recv[bI]->comm_conn[nr].range.lower, mbcc_recv[bI]->comm_conn[nr].range.upper + ); } // Sort connections according to rank and block ID. gkyl_multib_comm_conn_sort(mbcc_recv[bI]); gkyl_multib_comm_conn_sort(mbcc_send[bI]); - } - printf("calling transfer\n"); - int stat = gkyl_multib_comm_conn_array_transfer(comm, num_local_blocks, local_blocks, mbcc_send, mbcc_recv, array_local, array_global); + int stat = gkyl_multib_comm_conn_array_transfer( + comm, num_local_blocks, local_blocks, mbcc_send, mbcc_recv, array_local, array_global + ); printf("did transfer\n"); - - for (int bI=0; bInum_blocks; int nghost[ndim]; - for (int d=0; dcells, &block_global_range); - + decomp[i] = gkyl_rect_decomp_new_from_cuts(ndim, ginfo->cuts, &block_global_range); if (my_rank == 0) { - printf("b%d ranks: ",i); - for (int d=0; dranges[brank], nghost, &app->local_ext, &app->local); - for (int dir=0; dirlower_skin[dir], &app->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &app->local_ext, nghost); - gkyl_skin_ghost_ranges(&app->upper_skin[dir], &app->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &app->local_ext, nghost); + for (int dir = 0; dir < ndim; ++dir) { + gkyl_skin_ghost_ranges( + &app->lower_skin[dir], &app->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &app->local_ext, nghost + ); + gkyl_skin_ghost_ranges( + &app->upper_skin[dir], &app->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &app->local_ext, nghost + ); } gkyl_cart_modal_serendip(&app->basis, ndim, poly_order); app->f = mkarr(use_gpu, app->basis.num_basis, app->local_ext.volume); - app->f_ho = use_gpu? mkarr(false, app->basis.num_basis, app->local_ext.volume) - : gkyl_array_acquire(app->f); - + app->f_ho = use_gpu ? mkarr(false, app->basis.num_basis, app->local_ext.volume) : + gkyl_array_acquire(app->f); + // Put some value in f that is distinct in every rank and block. -// for (int k=0; kbasis.num_basis; k++) - int k=0; - gkyl_array_shiftc(app->f, bid+100.0*my_rank, k); + // for (int k=0; kbasis.num_basis; k++) + int k = 0; + gkyl_array_shiftc(app->f, bid + 100.0 * my_rank, k); } - // Communication connections. - struct gkyl_multib_comm_conn **mbcc_recv = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); - struct gkyl_multib_comm_conn **mbcc_send = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); + // Communication connections. + struct gkyl_multib_comm_conn **mbcc_recv = + gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); + struct gkyl_multib_comm_conn **mbcc_send = + gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); // Array of local ranges and fields. struct gkyl_array **fs = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_array *)); struct gkyl_range **locals = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_range *)); struct gkyl_range **local_exts = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_range *)); - for (int bI=0; bIconn[bid], decomp); - mbcc_send[bI] = gkyl_multib_comm_conn_new_send(bid, brank, nghost, - &topo->conn[bid], decomp); + mbcc_recv[bI] = gkyl_multib_comm_conn_new_recv(bid, brank, nghost, &topo->conn[bid], decomp); + mbcc_send[bI] = gkyl_multib_comm_conn_new_send(bid, brank, nghost, &topo->conn[bid], decomp); struct app_L *app = singleb_apps[bI]; - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_recv[bI]->num_comm_conn; ++ns) { // Translate the "rank" in gkyl_multib_comm_conn (right now it is a rank index). int rankIdx = mbcc_recv[bI]->comm_conn[ns].rank; - gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc_recv[bI]->comm_conn[ns].block_id, rank_list); + gkyl_rrobin_decomp_getranks( + round_robin_decomp, mbcc_recv[bI]->comm_conn[ns].block_id, rank_list + ); mbcc_recv[bI]->comm_conn[ns].rank = rank_list[rankIdx]; // Make range a sub range. - gkyl_sub_range_init(&mbcc_recv[bI]->comm_conn[ns].range, &app->local_ext, - mbcc_recv[bI]->comm_conn[ns].range.lower, mbcc_recv[bI]->comm_conn[ns].range.upper); + gkyl_sub_range_init( + &mbcc_recv[bI]->comm_conn[ns].range, &app->local_ext, + mbcc_recv[bI]->comm_conn[ns].range.lower, mbcc_recv[bI]->comm_conn[ns].range.upper + ); } - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_send[bI]->num_comm_conn; ++ns) { // Translate the "rank" in gkyl_multib_comm_conn (right now it is a rank index). int rankIdx = mbcc_send[bI]->comm_conn[ns].rank; - gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc_send[bI]->comm_conn[ns].block_id, rank_list); + gkyl_rrobin_decomp_getranks( + round_robin_decomp, mbcc_send[bI]->comm_conn[ns].block_id, rank_list + ); mbcc_send[bI]->comm_conn[ns].rank = rank_list[rankIdx]; // Make range a sub range. - gkyl_sub_range_init(&mbcc_send[bI]->comm_conn[ns].range, &app->local_ext, - mbcc_send[bI]->comm_conn[ns].range.lower, mbcc_send[bI]->comm_conn[ns].range.upper); + gkyl_sub_range_init( + &mbcc_send[bI]->comm_conn[ns].range, &app->local_ext, + mbcc_send[bI]->comm_conn[ns].range.lower, mbcc_send[bI]->comm_conn[ns].range.upper + ); } // Sort connections according to rank and block ID. @@ -394,30 +418,34 @@ test_L_domain_sync(bool use_gpu, bool use_mpi, int **cuts, int poly_order) } // Sync blocks. - gkyl_multib_comm_conn_array_transfer(comm, num_blocks_local, local_blocks, - mbcc_send, mbcc_recv, fs, fs); + gkyl_multib_comm_conn_array_transfer( + comm, num_blocks_local, local_blocks, mbcc_send, mbcc_recv, fs, fs + ); // Check results. - for (int bI=0; bIf_ho, app->f); - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_recv[bI]->num_comm_conn; ++ns) { struct gkyl_comm_conn *cc = &mbcc_recv[bI]->comm_conn[ns]; - double ref = cc->block_id + 100.0*cc->rank; + double ref = cc->block_id + 100.0 * cc->rank; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &cc->range); while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&cc->range, iter.idx); double *f_c = gkyl_array_fetch(app->f_ho, linidx); -// for (int k=0; kbasis.num_basis; k++) { - int k=0; - TEST_CHECK( gkyl_compare(ref, f_c[k], 1e-10) ); - TEST_MSG( "bid:%d | Expected: %.13e | Got: %.13e | Cell:%d,%d\n", bid, ref, f_c[k], iter.idx[0], iter.idx[1]); -// } + // for (int k=0; kbasis.num_basis; k++) { + int k = 0; + TEST_CHECK(gkyl_compare(ref, f_c[k], 1e-10)); + TEST_MSG( + "bid:%d | Expected: %.13e | Got: %.13e | Cell:%d,%d\n", bid, ref, f_c[k], iter.idx[0], + iter.idx[1] + ); + // } } } } @@ -425,14 +453,14 @@ test_L_domain_sync(bool use_gpu, bool use_mpi, int **cuts, int poly_order) gkyl_free(fs); gkyl_free(locals); gkyl_free(local_exts); - for (int bI=0; bIf_ho); gkyl_array_release(app->f); @@ -440,12 +468,14 @@ test_L_domain_sync(bool use_gpu, bool use_mpi, int **cuts, int poly_order) } gkyl_free(singleb_apps); - for (int i=0; inum_blocks; int nghost[ndim]; - for (int d=0; dcells, &block_global_range); - + decomp[i] = gkyl_rect_decomp_new_from_cuts(ndim, ginfo->cuts, &block_global_range); if (my_rank == 0) { - printf("b%d ranks: ",i); - for (int d=0; dranges[brank], nghost, &app->local_ext, &app->local); - for (int dir=0; dirlower_skin[dir], &app->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &app->local_ext, nghost); - gkyl_skin_ghost_ranges(&app->upper_skin[dir], &app->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &app->local_ext, nghost); + for (int dir = 0; dir < ndim; ++dir) { + gkyl_skin_ghost_ranges( + &app->lower_skin[dir], &app->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &app->local_ext, nghost + ); + gkyl_skin_ghost_ranges( + &app->upper_skin[dir], &app->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &app->local_ext, nghost + ); } gkyl_cart_modal_serendip(&app->basis, ndim, poly_order); app->f = mkarr(use_gpu, app->basis.num_basis, app->local_ext.volume); - app->f_ho = use_gpu? mkarr(false, app->basis.num_basis, app->local_ext.volume) - : gkyl_array_acquire(app->f); - + app->f_ho = use_gpu ? mkarr(false, app->basis.num_basis, app->local_ext.volume) : + gkyl_array_acquire(app->f); + // Put some value in f that is distinct in every rank and block. -// for (int k=0; kbasis.num_basis; k++) - int k=0; - gkyl_array_shiftc(app->f, bid+1+100.0*(my_rank+1), k); - printf("bid = %d\n", bid); + // for (int k=0; kbasis.num_basis; k++) + int k = 0; + gkyl_array_shiftc(app->f, bid + 1 + 100.0 * (my_rank + 1), k); + printf("bid = %d\n", bid); } - // Communication connections. - struct gkyl_multib_comm_conn **mbcc_recv = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); - struct gkyl_multib_comm_conn **mbcc_send = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); + // Communication connections. + struct gkyl_multib_comm_conn **mbcc_recv = + gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); + struct gkyl_multib_comm_conn **mbcc_send = + gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); // Array of local ranges and fields. struct gkyl_array **fs = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_array *)); struct gkyl_range **locals = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_range *)); struct gkyl_range **local_exts = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_range *)); - for (int bI=0; bIconn[bid], decomp); - mbcc_send[bI] = gkyl_multib_comm_conn_new_send(bid, brank, nghost, - &topo->conn[bid], decomp); + mbcc_recv[bI] = gkyl_multib_comm_conn_new_recv(bid, brank, nghost, &topo->conn[bid], decomp); + mbcc_send[bI] = gkyl_multib_comm_conn_new_send(bid, brank, nghost, &topo->conn[bid], decomp); struct app_L *app = singleb_apps[bI]; - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_recv[bI]->num_comm_conn; ++ns) { // Translate the "rank" in gkyl_multib_comm_conn (right now it is a rank index). int rankIdx = mbcc_recv[bI]->comm_conn[ns].rank; - gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc_recv[bI]->comm_conn[ns].block_id, rank_list); + gkyl_rrobin_decomp_getranks( + round_robin_decomp, mbcc_recv[bI]->comm_conn[ns].block_id, rank_list + ); mbcc_recv[bI]->comm_conn[ns].rank = rank_list[rankIdx]; // Make range a sub range. - gkyl_sub_range_init(&mbcc_recv[bI]->comm_conn[ns].range, &app->local_ext, - mbcc_recv[bI]->comm_conn[ns].range.lower, mbcc_recv[bI]->comm_conn[ns].range.upper); + gkyl_sub_range_init( + &mbcc_recv[bI]->comm_conn[ns].range, &app->local_ext, + mbcc_recv[bI]->comm_conn[ns].range.lower, mbcc_recv[bI]->comm_conn[ns].range.upper + ); } - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_send[bI]->num_comm_conn; ++ns) { // Translate the "rank" in gkyl_multib_comm_conn (right now it is a rank index). int rankIdx = mbcc_send[bI]->comm_conn[ns].rank; - gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc_send[bI]->comm_conn[ns].block_id, rank_list); + gkyl_rrobin_decomp_getranks( + round_robin_decomp, mbcc_send[bI]->comm_conn[ns].block_id, rank_list + ); mbcc_send[bI]->comm_conn[ns].rank = rank_list[rankIdx]; // Make range a sub range. - gkyl_sub_range_init(&mbcc_send[bI]->comm_conn[ns].range, &app->local_ext, - mbcc_send[bI]->comm_conn[ns].range.lower, mbcc_send[bI]->comm_conn[ns].range.upper); + gkyl_sub_range_init( + &mbcc_send[bI]->comm_conn[ns].range, &app->local_ext, + mbcc_send[bI]->comm_conn[ns].range.lower, mbcc_send[bI]->comm_conn[ns].range.upper + ); } // Sort connections according to rank and block ID. @@ -611,30 +661,34 @@ test_cyclic_domain_sync(bool use_gpu, bool use_mpi, int **cuts, int poly_order) } // Sync blocks. - gkyl_multib_comm_conn_array_transfer(comm, num_blocks_local, local_blocks, - mbcc_send, mbcc_recv, fs, fs); + gkyl_multib_comm_conn_array_transfer( + comm, num_blocks_local, local_blocks, mbcc_send, mbcc_recv, fs, fs + ); // Check results. - for (int bI=0; bIf_ho, app->f); - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_recv[bI]->num_comm_conn; ++ns) { struct gkyl_comm_conn *cc = &mbcc_recv[bI]->comm_conn[ns]; - double ref = cc->block_id+1 + 100.0*(cc->rank+1); + double ref = cc->block_id + 1 + 100.0 * (cc->rank + 1); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &cc->range); while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&cc->range, iter.idx); double *f_c = gkyl_array_fetch(app->f_ho, linidx); -// for (int k=0; kbasis.num_basis; k++) { - int k=0; - TEST_CHECK( gkyl_compare(ref, f_c[k], 1e-10) ); - TEST_MSG( "bid:%d | Expected: %.13e | Got: %.13e | Cell:%d,%d\n", bid, ref, f_c[k], iter.idx[0], iter.idx[1]); -// } + // for (int k=0; kbasis.num_basis; k++) { + int k = 0; + TEST_CHECK(gkyl_compare(ref, f_c[k], 1e-10)); + TEST_MSG( + "bid:%d | Expected: %.13e | Got: %.13e | Cell:%d,%d\n", bid, ref, f_c[k], iter.idx[0], + iter.idx[1] + ); + // } } } } @@ -642,14 +696,14 @@ test_cyclic_domain_sync(bool use_gpu, bool use_mpi, int **cuts, int poly_order) gkyl_free(fs); gkyl_free(locals); gkyl_free(local_exts); - for (int bI=0; bIf_ho); gkyl_array_release(app->f); @@ -657,12 +711,14 @@ test_cyclic_domain_sync(bool use_gpu, bool use_mpi, int **cuts, int poly_order) } gkyl_free(singleb_apps); - for (int i=0; inum_blocks; int nghost[ndim]; - for (int d=0; dcells, &block_global_range); - + decomp[i] = gkyl_rect_decomp_new_from_cuts(ndim, ginfo->cuts, &block_global_range); if (my_rank == 0) { - printf("b%d ranks: ",i); - for (int d=0; dranges[brank], nghost, &app->local_ext, &app->local); - for (int dir=0; dirlower_skin[dir], &app->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &app->local_ext, nghost); - gkyl_skin_ghost_ranges(&app->upper_skin[dir], &app->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &app->local_ext, nghost); + for (int dir = 0; dir < ndim; ++dir) { + gkyl_skin_ghost_ranges( + &app->lower_skin[dir], &app->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &app->local_ext, nghost + ); + gkyl_skin_ghost_ranges( + &app->upper_skin[dir], &app->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &app->local_ext, nghost + ); } gkyl_cart_modal_serendip(&app->basis, ndim, poly_order); app->f = mkarr(use_gpu, app->basis.num_basis, app->local_ext.volume); - app->f_ho = use_gpu? mkarr(false, app->basis.num_basis, app->local_ext.volume) - : gkyl_array_acquire(app->f); - + app->f_ho = use_gpu ? mkarr(false, app->basis.num_basis, app->local_ext.volume) : + gkyl_array_acquire(app->f); + // Put some value in f that is distinct in every rank and block. -// for (int k=0; kbasis.num_basis; k++) - int k=0; - //gkyl_array_shiftc(app->f, bid+1+100.0*(my_rank+1), k); - //printf("bid = %d\n", bid); + // for (int k=0; kbasis.num_basis; k++) + int k = 0; + //gkyl_array_shiftc(app->f, bid+1+100.0*(my_rank+1), k); + //printf("bid = %d\n", bid); int sublower[2] = {app->local.lower[0], app->local.lower[1]}; - int subupper[2] = {app->local.upper[0], app->local.upper[1]/2}; + int subupper[2] = {app->local.upper[0], app->local.upper[1] / 2}; struct gkyl_range lower_range; gkyl_sub_range_init(&lower_range, &app->local_ext, sublower, subupper); - sublower[1] = app->local.upper[1]/2; + sublower[1] = app->local.upper[1] / 2; subupper[1] = app->local.upper[1]; struct gkyl_range upper_range; gkyl_sub_range_init(&upper_range, &app->local_ext, sublower, subupper); gkyl_array_shiftc(app->f, 1.0, k); - double val_lower = 2*bid +1; - double val_upper= 2*bid +2; + double val_lower = 2 * bid + 1; + double val_upper = 2 * bid + 2; gkyl_array_set_range(app->f, val_lower, app->f, &lower_range); gkyl_array_set_range(app->f, val_upper, app->f, &upper_range); } - // Communication connections. - struct gkyl_multib_comm_conn **mbcc_recv = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); - struct gkyl_multib_comm_conn **mbcc_send = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); + // Communication connections. + struct gkyl_multib_comm_conn **mbcc_recv = + gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); + struct gkyl_multib_comm_conn **mbcc_send = + gkyl_malloc(num_blocks_local * sizeof(struct gkyl_multib_comm_conn *)); // Array of local ranges and fields. struct gkyl_array **fs = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_array *)); struct gkyl_range **locals = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_range *)); struct gkyl_range **local_exts = gkyl_malloc(num_blocks_local * sizeof(struct gkyl_range *)); - for (int bI=0; bIconn[bid], decomp); - mbcc_send[bI] = gkyl_multib_comm_conn_new_send(bid, brank, nghost, - &topo->conn[bid], decomp); + mbcc_recv[bI] = gkyl_multib_comm_conn_new_recv(bid, brank, nghost, &topo->conn[bid], decomp); + mbcc_send[bI] = gkyl_multib_comm_conn_new_send(bid, brank, nghost, &topo->conn[bid], decomp); struct app_L *app = singleb_apps[bI]; - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_recv[bI]->num_comm_conn; ++ns) { // Translate the "rank" in gkyl_multib_comm_conn (right now it is a rank index). int rankIdx = mbcc_recv[bI]->comm_conn[ns].rank; - gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc_recv[bI]->comm_conn[ns].block_id, rank_list); + gkyl_rrobin_decomp_getranks( + round_robin_decomp, mbcc_recv[bI]->comm_conn[ns].block_id, rank_list + ); mbcc_recv[bI]->comm_conn[ns].rank = rank_list[rankIdx]; // Make range a sub range. - gkyl_sub_range_init(&mbcc_recv[bI]->comm_conn[ns].range, &app->local_ext, - mbcc_recv[bI]->comm_conn[ns].range.lower, mbcc_recv[bI]->comm_conn[ns].range.upper); + gkyl_sub_range_init( + &mbcc_recv[bI]->comm_conn[ns].range, &app->local_ext, + mbcc_recv[bI]->comm_conn[ns].range.lower, mbcc_recv[bI]->comm_conn[ns].range.upper + ); } - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_send[bI]->num_comm_conn; ++ns) { // Translate the "rank" in gkyl_multib_comm_conn (right now it is a rank index). int rankIdx = mbcc_send[bI]->comm_conn[ns].rank; - gkyl_rrobin_decomp_getranks(round_robin_decomp, mbcc_send[bI]->comm_conn[ns].block_id, rank_list); + gkyl_rrobin_decomp_getranks( + round_robin_decomp, mbcc_send[bI]->comm_conn[ns].block_id, rank_list + ); mbcc_send[bI]->comm_conn[ns].rank = rank_list[rankIdx]; // Make range a sub range. - gkyl_sub_range_init(&mbcc_send[bI]->comm_conn[ns].range, &app->local_ext, - mbcc_send[bI]->comm_conn[ns].range.lower, mbcc_send[bI]->comm_conn[ns].range.upper); + gkyl_sub_range_init( + &mbcc_send[bI]->comm_conn[ns].range, &app->local_ext, + mbcc_send[bI]->comm_conn[ns].range.lower, mbcc_send[bI]->comm_conn[ns].range.upper + ); } // Sort connections according to rank and block ID. @@ -842,37 +918,42 @@ test_cyclic_domain_sync_ser(bool use_gpu, bool use_mpi, int **cuts, int poly_ord } // Sync blocks. - gkyl_multib_comm_conn_array_transfer(comm, num_blocks_local, local_blocks, - mbcc_send, mbcc_recv, fs, fs); + gkyl_multib_comm_conn_array_transfer( + comm, num_blocks_local, local_blocks, mbcc_send, mbcc_recv, fs, fs + ); // Check results. - for (int bI=0; bIf_ho, app->f); - for (int ns=0; nsnum_comm_conn; ++ns) { + for (int ns = 0; ns < mbcc_recv[bI]->num_comm_conn; ++ns) { struct gkyl_comm_conn *cc = &mbcc_recv[bI]->comm_conn[ns]; - double ref_lower = 2*cc->block_id+1; - double ref_upper = 2*cc->block_id+2; + double ref_lower = 2 * cc->block_id + 1; + double ref_upper = 2 * cc->block_id + 2; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &cc->range); while (gkyl_range_iter_next(&iter)) { double ref; - if(iter.idx[1] == 0) + if (iter.idx[1] == 0) { ref = ref_upper; - else + } else { ref = ref_lower; - + } + long linidx = gkyl_range_idx(&cc->range, iter.idx); double *f_c = gkyl_array_fetch(app->f_ho, linidx); -// for (int k=0; kbasis.num_basis; k++) { - int k=0; - TEST_CHECK( gkyl_compare(ref, f_c[k], 1e-10) ); - TEST_MSG( "bid:%d | Expected: %.13e | Got: %.13e | Cell:%d,%d\n", bid, ref, f_c[k], iter.idx[0], iter.idx[1]); -// } + // for (int k=0; kbasis.num_basis; k++) { + int k = 0; + TEST_CHECK(gkyl_compare(ref, f_c[k], 1e-10)); + TEST_MSG( + "bid:%d | Expected: %.13e | Got: %.13e | Cell:%d,%d\n", bid, ref, f_c[k], iter.idx[0], + iter.idx[1] + ); + // } } } } @@ -880,14 +961,14 @@ test_cyclic_domain_sync_ser(bool use_gpu, bool use_mpi, int **cuts, int poly_ord gkyl_free(fs); gkyl_free(locals); gkyl_free(local_exts); - for (int bI=0; bIf_ho); gkyl_array_release(app->f); @@ -895,12 +976,14 @@ test_cyclic_domain_sync_ser(bool use_gpu, bool use_mpi, int **cuts, int poly_ord } gkyl_free(singleb_apps); - for (int i=0; i #include -gkyl_ambi_bolt_potential* -gkyl_ambi_bolt_potential_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, - double mass_e, double charge_e, double temp_e, bool use_gpu) +gkyl_ambi_bolt_potential *gkyl_ambi_bolt_potential_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, double mass_e, double charge_e, + double temp_e, bool use_gpu +) { struct gkyl_ambi_bolt_potential *up = gkyl_malloc(sizeof(struct gkyl_ambi_bolt_potential)); @@ -12,17 +13,18 @@ gkyl_ambi_bolt_potential_new(const struct gkyl_rect_grid *grid, const struct gky up->num_basis = basis->num_basis; up->use_gpu = use_gpu; - up->dz = grid->dx[up->cdim-1]; + up->dz = grid->dx[up->cdim - 1]; up->mass_e = mass_e; up->charge_e = charge_e; up->temp_e = temp_e; up->kernels = gkyl_malloc(sizeof(struct gkyl_ambi_bolt_potential_kernels)); #ifdef GKYL_HAVE_CUDA - if (use_gpu) + if (use_gpu) { up->kernels_cu = gkyl_cu_malloc(sizeof(struct gkyl_ambi_bolt_potential_kernels)); - else + } else { up->kernels_cu = up->kernels; + } #else up->kernels_cu = up->kernels; #endif @@ -30,23 +32,27 @@ gkyl_ambi_bolt_potential_new(const struct gkyl_rect_grid *grid, const struct gky // Select sheath_calc and phi_calc kernels. ambi_bolt_potential_choose_kernels(basis, up->kernels); #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { ambi_bolt_potential_choose_kernels_cu(basis, up->kernels_cu); + } #endif return up; } -void gkyl_ambi_bolt_potential_sheath_calc(struct gkyl_ambi_bolt_potential *up, enum gkyl_edge_loc edge, - const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, - const struct gkyl_array *cmag, const struct gkyl_array *jacobtot_inv, - const struct gkyl_array *gammai, const struct gkyl_array *m0i, const struct gkyl_array *Jm0i, - struct gkyl_array *sheath_vals) +void gkyl_ambi_bolt_potential_sheath_calc( + struct gkyl_ambi_bolt_potential *up, enum gkyl_edge_loc edge, const struct gkyl_range *skin_r, + const struct gkyl_range *ghost_r, const struct gkyl_array *cmag, + const struct gkyl_array *jacobtot_inv, const struct gkyl_array *gammai, + const struct gkyl_array *m0i, const struct gkyl_array *Jm0i, struct gkyl_array *sheath_vals +) { #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) - return gkyl_ambi_bolt_potential_sheath_calc_cu(up, edge, skin_r, ghost_r, - cmag, jacobtot_inv, gammai, m0i, Jm0i, sheath_vals); + if (up->use_gpu) { + return gkyl_ambi_bolt_potential_sheath_calc_cu( + up, edge, skin_r, ghost_r, cmag, jacobtot_inv, gammai, m0i, Jm0i, sheath_vals + ); + } #endif unsigned int keridx = (edge == GKYL_LOWER_EDGE) ? 0 : 1; @@ -62,30 +68,36 @@ void gkyl_ambi_bolt_potential_sheath_calc(struct gkyl_ambi_bolt_potential *up, e while (gkyl_range_iter_next(&iter)) { gkyl_copy_int_arr(up->cdim, iter.idx, idx_s); // Assume only 1 ghost cell on either side along the field line. - idx_s[up->cdim-1] = edge == GKYL_LOWER_EDGE ? iter.idx[up->cdim-1]+1 : iter.idx[up->cdim-1]-1; + idx_s[up->cdim - 1] = edge == GKYL_LOWER_EDGE ? iter.idx[up->cdim - 1] + 1 : + iter.idx[up->cdim - 1] - 1; long ghost_loc = gkyl_range_idx(ghost_r, iter.idx); long skin_loc = gkyl_range_idx(skin_r, idx_s); - const double *cmag_p = (const double*) gkyl_array_cfetch(cmag, skin_loc); - const double *jacobtotinv_p = (const double*) gkyl_array_cfetch(jacobtot_inv, skin_loc); - const double *m0i_p = (const double*) gkyl_array_cfetch(m0i, skin_loc); - const double *Jm0i_p = (const double*) gkyl_array_cfetch(Jm0i, skin_loc); - const double *gammai_p = (const double*) gkyl_array_cfetch(gammai, ghost_loc); - double *out_p = (double*) gkyl_array_cfetch(sheath_vals, ghost_loc); - - up->kernels->sheath_calc[keridx](up->dz, up->charge_e, up->mass_e, up->temp_e, - cmag_p, jacobtotinv_p, gammai_p, m0i_p, Jm0i_p, out_p); + const double *cmag_p = (const double *)gkyl_array_cfetch(cmag, skin_loc); + const double *jacobtotinv_p = (const double *)gkyl_array_cfetch(jacobtot_inv, skin_loc); + const double *m0i_p = (const double *)gkyl_array_cfetch(m0i, skin_loc); + const double *Jm0i_p = (const double *)gkyl_array_cfetch(Jm0i, skin_loc); + const double *gammai_p = (const double *)gkyl_array_cfetch(gammai, ghost_loc); + double *out_p = (double *)gkyl_array_cfetch(sheath_vals, ghost_loc); + + up->kernels->sheath_calc[keridx]( + up->dz, up->charge_e, up->mass_e, up->temp_e, cmag_p, jacobtotinv_p, gammai_p, m0i_p, Jm0i_p, + out_p + ); } } -void gkyl_ambi_bolt_potential_phi_calc(struct gkyl_ambi_bolt_potential *up, - const struct gkyl_range *local, const struct gkyl_range *local_ext, - const struct gkyl_array *m0i, const struct gkyl_array *sheath_vals, struct gkyl_array *phi) +void gkyl_ambi_bolt_potential_phi_calc( + struct gkyl_ambi_bolt_potential *up, const struct gkyl_range *local, + const struct gkyl_range *local_ext, const struct gkyl_array *m0i, + const struct gkyl_array *sheath_vals, struct gkyl_array *phi +) { #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { return gkyl_ambi_bolt_potential_phi_calc_cu(up, local, local_ext, m0i, sheath_vals, phi); + } #endif int idx_g[GKYL_MAX_CDIM]; // Index in ghost grid sheath_vals is defined on. @@ -96,14 +108,14 @@ void gkyl_ambi_bolt_potential_phi_calc(struct gkyl_ambi_bolt_potential *up, // We assume each MPI rank calls this over the local range and // that the sheath values are defined on the lower local ghost range. gkyl_copy_int_arr(up->cdim, iter.idx, idx_g); - idx_g[up->cdim-1] = local_ext->lower[up->cdim-1]; + idx_g[up->cdim - 1] = local_ext->lower[up->cdim - 1]; long loc = gkyl_range_idx(local, iter.idx); long ghost_loc = gkyl_range_idx(local_ext, idx_g); - const double *m0i_p = (const double*) gkyl_array_cfetch(m0i, loc); - const double *sheathvals_p = (const double*) gkyl_array_cfetch(sheath_vals, ghost_loc); - double *phi_p = (double*) gkyl_array_cfetch(phi, loc); + const double *m0i_p = (const double *)gkyl_array_cfetch(m0i, loc); + const double *sheathvals_p = (const double *)gkyl_array_cfetch(sheath_vals, ghost_loc); + double *phi_p = (double *)gkyl_array_cfetch(phi, loc); up->kernels->phi_calc(up->charge_e, up->temp_e, m0i_p, sheathvals_p, phi_p); } @@ -113,8 +125,9 @@ void gkyl_ambi_bolt_potential_release(gkyl_ambi_bolt_potential *up) { gkyl_free(up->kernels); #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { gkyl_cu_free(up->kernels_cu); + } #endif gkyl_free(up); } diff --git a/gyrokinetic/zero/ambi_bolt_potential_cu.cu b/gyrokinetic/zero/ambi_bolt_potential_cu.cu index 09a98fb45f..52b004f27b 100644 --- a/gyrokinetic/zero/ambi_bolt_potential_cu.cu +++ b/gyrokinetic/zero/ambi_bolt_potential_cu.cu @@ -10,36 +10,39 @@ extern "C" { // CUDA kernel to set device pointers to l2g, RHS src and solution // kernels. Doing function pointer stuff in here avoids troublesome // cudaMemcpyFromSymbol. -__global__ static void -ambi_bolt_potential_set_cu_ker_ptrs(struct gkyl_ambi_bolt_potential_kernels* kers, - enum gkyl_basis_type b_type, int dim, int poly_order) +__global__ static void ambi_bolt_potential_set_cu_ker_ptrs( + struct gkyl_ambi_bolt_potential_kernels *kers, enum gkyl_basis_type b_type, int dim, + int poly_order +) { const sheath_calc_kern_edge_list *sheath_calc_list; const phi_calc_kern_list *phi_calc_list; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - sheath_calc_list = ser_sheath_calc_list; - phi_calc_list = ser_phi_calc_list; - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + sheath_calc_list = ser_sheath_calc_list; + phi_calc_list = ser_phi_calc_list; + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } - for (int k=0; k<2; k++) + for (int k = 0; k < 2; k++) { kers->sheath_calc[k] = CSHEATHK(sheath_calc_list, dim, poly_order, k); + } - kers->phi_calc = CPHIK(phi_calc_list, dim, poly_order);; + kers->phi_calc = CPHIK(phi_calc_list, dim, poly_order); + ; } -__global__ static void -gkyl_ambi_bolt_potential_sheath_calc_cu_ker(double dz, double charge_e, double mass_e, double temp_e, - struct gkyl_ambi_bolt_potential_kernels *kers, enum gkyl_edge_loc edge, - struct gkyl_range skin_r, struct gkyl_range ghost_r, - const struct gkyl_array *cmag, const struct gkyl_array *jacobtot_inv, +__global__ static void gkyl_ambi_bolt_potential_sheath_calc_cu_ker( + double dz, double charge_e, double mass_e, double temp_e, + struct gkyl_ambi_bolt_potential_kernels *kers, enum gkyl_edge_loc edge, struct gkyl_range skin_r, + struct gkyl_range ghost_r, const struct gkyl_array *cmag, const struct gkyl_array *jacobtot_inv, const struct gkyl_array *gammai, const struct gkyl_array *m0i, const struct gkyl_array *Jm0i, - struct gkyl_array *sheath_vals) + struct gkyl_array *sheath_vals +) { unsigned int keridx = (edge == GKYL_LOWER_EDGE) ? 0 : 1; @@ -47,9 +50,8 @@ gkyl_ambi_bolt_potential_sheath_calc_cu_ker(double dz, double charge_e, double m int ndim = ghost_r.ndim; - for(unsigned long linc = threadIdx.x + blockIdx.x*blockDim.x; - linc < ghost_r.volume; linc += blockDim.x*gridDim.x) { - + for (unsigned long linc = threadIdx.x + blockIdx.x * blockDim.x; linc < ghost_r.volume; + linc += blockDim.x * gridDim.x) { // inverse index from linc to idx // must use gkyl_sub_range_inv_idx so that linc=0 maps to idx={1,1,...} // since update_range is a subrange @@ -57,35 +59,36 @@ gkyl_ambi_bolt_potential_sheath_calc_cu_ker(double dz, double charge_e, double m gkyl_copy_int_arr(ndim, idx_g, idx_s); // Assume only 1 ghost cell on either side along the field line. - idx_s[ndim-1] = edge == GKYL_LOWER_EDGE? idx_g[ndim-1]+1 : idx_g[ndim-1]-1; + idx_s[ndim - 1] = edge == GKYL_LOWER_EDGE ? idx_g[ndim - 1] + 1 : idx_g[ndim - 1] - 1; long ghost_loc = gkyl_range_idx(&ghost_r, idx_g); long skin_loc = gkyl_range_idx(&skin_r, idx_s); - const double *cmag_p = (const double*) gkyl_array_cfetch(cmag, skin_loc); - const double *jactotinv_p = (const double*) gkyl_array_cfetch(jacobtot_inv, skin_loc); - const double *m0i_p = (const double*) gkyl_array_cfetch(m0i, skin_loc); - const double *Jm0i_p = (const double*) gkyl_array_cfetch(Jm0i, skin_loc); - const double *gammai_p = (const double*) gkyl_array_cfetch(gammai, ghost_loc); - double *out_p = (double*) gkyl_array_cfetch(sheath_vals, ghost_loc); + const double *cmag_p = (const double *)gkyl_array_cfetch(cmag, skin_loc); + const double *jactotinv_p = (const double *)gkyl_array_cfetch(jacobtot_inv, skin_loc); + const double *m0i_p = (const double *)gkyl_array_cfetch(m0i, skin_loc); + const double *Jm0i_p = (const double *)gkyl_array_cfetch(Jm0i, skin_loc); + const double *gammai_p = (const double *)gkyl_array_cfetch(gammai, ghost_loc); + double *out_p = (double *)gkyl_array_cfetch(sheath_vals, ghost_loc); - kers->sheath_calc[keridx](dz, charge_e, mass_e, temp_e, cmag_p, jactotinv_p, gammai_p, m0i_p, Jm0i_p, out_p); + kers->sheath_calc[keridx]( + dz, charge_e, mass_e, temp_e, cmag_p, jactotinv_p, gammai_p, m0i_p, Jm0i_p, out_p + ); } } -__global__ static void -gkyl_ambi_bolt_potential_phi_calc_cu_ker(double charge_e, double temp_e, - struct gkyl_ambi_bolt_potential_kernels *kers, struct gkyl_range local_r, struct gkyl_range extlocal_r, - const struct gkyl_array *m0i, const struct gkyl_array *sheath_vals, - struct gkyl_array *phi) +__global__ static void gkyl_ambi_bolt_potential_phi_calc_cu_ker( + double charge_e, double temp_e, struct gkyl_ambi_bolt_potential_kernels *kers, + struct gkyl_range local_r, struct gkyl_range extlocal_r, const struct gkyl_array *m0i, + const struct gkyl_array *sheath_vals, struct gkyl_array *phi +) { int idx[GKYL_MAX_CDIM], idx_g[GKYL_MAX_CDIM]; // Volume and ghost indices. int ndim = local_r.ndim; - for(unsigned long linc = threadIdx.x + blockIdx.x*blockDim.x; - linc < local_r.volume; linc += blockDim.x*gridDim.x) { - + for (unsigned long linc = threadIdx.x + blockIdx.x * blockDim.x; linc < local_r.volume; + linc += blockDim.x * gridDim.x) { // inverse index from linc to idx // must use gkyl_sub_range_inv_idx so that linc=0 maps to idx={1,1,...} // since update_range is a subrange @@ -94,46 +97,54 @@ gkyl_ambi_bolt_potential_phi_calc_cu_ker(double charge_e, double temp_e, // We assume each MPI rank calls this over the local range and // that the sheath values are defined on the lower local ghost range. gkyl_copy_int_arr(ndim, idx, idx_g); - idx_g[ndim-1] = extlocal_r.lower[ndim-1]; + idx_g[ndim - 1] = extlocal_r.lower[ndim - 1]; long loc = gkyl_range_idx(&local_r, idx); long ghost_loc = gkyl_range_idx(&extlocal_r, idx_g); - const double *m0i_p = (const double*) gkyl_array_cfetch(m0i, loc); - const double *sheathvals_p = (const double*) gkyl_array_cfetch(sheath_vals, ghost_loc); - double *phi_p = (double*) gkyl_array_cfetch(phi, loc); + const double *m0i_p = (const double *)gkyl_array_cfetch(m0i, loc); + const double *sheathvals_p = (const double *)gkyl_array_cfetch(sheath_vals, ghost_loc); + double *phi_p = (double *)gkyl_array_cfetch(phi, loc); kers->phi_calc(charge_e, temp_e, m0i_p, sheathvals_p, phi_p); } } -void -ambi_bolt_potential_choose_kernels_cu(const struct gkyl_basis *basis, struct gkyl_ambi_bolt_potential_kernels *kers) +void ambi_bolt_potential_choose_kernels_cu( + const struct gkyl_basis *basis, struct gkyl_ambi_bolt_potential_kernels *kers +) { - ambi_bolt_potential_set_cu_ker_ptrs<<<1,1>>>(kers, basis->b_type, basis->ndim, basis->poly_order); + ambi_bolt_potential_set_cu_ker_ptrs<<<1, 1> > >( + kers, basis->b_type, basis->ndim, basis->poly_order + ); } -void -gkyl_ambi_bolt_potential_sheath_calc_cu(struct gkyl_ambi_bolt_potential *up, enum gkyl_edge_loc edge, - const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, - const struct gkyl_array *cmag, const struct gkyl_array *jacobtot_inv, - const struct gkyl_array *gammai, const struct gkyl_array *m0i, const struct gkyl_array *Jm0i, - struct gkyl_array *sheath_vals) +void gkyl_ambi_bolt_potential_sheath_calc_cu( + struct gkyl_ambi_bolt_potential *up, enum gkyl_edge_loc edge, const struct gkyl_range *skin_r, + const struct gkyl_range *ghost_r, const struct gkyl_array *cmag, + const struct gkyl_array *jacobtot_inv, const struct gkyl_array *gammai, + const struct gkyl_array *m0i, const struct gkyl_array *Jm0i, struct gkyl_array *sheath_vals +) { int nblocks = ghost_r->nblocks, nthreads = ghost_r->nthreads; - gkyl_ambi_bolt_potential_sheath_calc_cu_ker<<>>(up->dz, up->charge_e, up->mass_e, up->temp_e, - up->kernels_cu, edge, *skin_r, *ghost_r, cmag->on_dev, jacobtot_inv->on_dev, - gammai->on_dev, m0i->on_dev, Jm0i->on_dev, sheath_vals->on_dev); + gkyl_ambi_bolt_potential_sheath_calc_cu_ker<< > >( + up->dz, up->charge_e, up->mass_e, up->temp_e, up->kernels_cu, edge, *skin_r, *ghost_r, + cmag->on_dev, jacobtot_inv->on_dev, gammai->on_dev, m0i->on_dev, Jm0i->on_dev, + sheath_vals->on_dev + ); } -void -gkyl_ambi_bolt_potential_phi_calc_cu(struct gkyl_ambi_bolt_potential *up, const struct gkyl_range *local_r, - const struct gkyl_range *extlocal_r, const struct gkyl_array *m0i, const struct gkyl_array *sheath_vals, - struct gkyl_array *phi) +void gkyl_ambi_bolt_potential_phi_calc_cu( + struct gkyl_ambi_bolt_potential *up, const struct gkyl_range *local_r, + const struct gkyl_range *extlocal_r, const struct gkyl_array *m0i, + const struct gkyl_array *sheath_vals, struct gkyl_array *phi +) { int nblocks = local_r->nblocks, nthreads = local_r->nthreads; - gkyl_ambi_bolt_potential_phi_calc_cu_ker<<>>(up->charge_e, up->temp_e, up->kernels_cu, - *local_r, *extlocal_r, m0i->on_dev, sheath_vals->on_dev, phi->on_dev); + gkyl_ambi_bolt_potential_phi_calc_cu_ker<< > >( + up->charge_e, up->temp_e, up->kernels_cu, *local_r, *extlocal_r, m0i->on_dev, + sheath_vals->on_dev, phi->on_dev + ); } diff --git a/gyrokinetic/zero/bc_basic_gyrokinetic.c b/gyrokinetic/zero/bc_basic_gyrokinetic.c index 5955ee2a1a..d8c106cba8 100644 --- a/gyrokinetic/zero/bc_basic_gyrokinetic.c +++ b/gyrokinetic/zero/bc_basic_gyrokinetic.c @@ -5,14 +5,15 @@ // Private function to create a pointer to the function that applies the BC, // i.e., the array_copy_func applied to expansion coefficients in ghost cell. -struct gkyl_array_copy_func* -gkyl_bc_basic_gyrokinetic_create_arr_copy_func(int dir, enum gkyl_edge_loc edge, - int cdim, enum gkyl_gyrokinetic_bc_type bctype, - const struct gkyl_basis *basis, int ncomp, bool use_gpu) +struct gkyl_array_copy_func *gkyl_bc_basic_gyrokinetic_create_arr_copy_func( + int dir, enum gkyl_edge_loc edge, int cdim, enum gkyl_gyrokinetic_bc_type bctype, + const struct gkyl_basis *basis, int ncomp, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) + if (use_gpu) { return gkyl_bc_basic_gyrokinetic_create_arr_copy_func_cu(dir, edge, cdim, bctype, basis, ncomp); + } #endif struct dg_bc_ctx *ctx = gkyl_malloc(sizeof(*ctx)); @@ -24,39 +25,39 @@ gkyl_bc_basic_gyrokinetic_create_arr_copy_func(int dir, enum gkyl_edge_loc edge, struct gkyl_array_copy_func *fout = gkyl_malloc(sizeof(*fout)); switch (bctype) { - case GKYL_BC_GK_SPECIES_COPY: - fout->func = copy_bc; - break; - - case GKYL_BC_GK_SPECIES_FIXED_FUNC: - assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. - assert(basis->b_type == GKYL_BASIS_MODAL_GKHYBRID); // MF 2025/11/03: Hardcoded for now. - fout->func = phase_boundary_value_bc; - break; - - case GKYL_BC_GK_SPECIES_ABSORB: - fout->func = species_absorb_bc; - break; - - case GKYL_BC_GK_SPECIES_REFLECT: - fout->func = species_reflect_bc; - break; - - case GKYL_BC_GK_SPECIES_BOUNDARY_VALUE: - assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. - assert(basis->b_type == GKYL_BASIS_MODAL_GKHYBRID); // MF 2025/11/03: Hardcoded for now. - fout->func = phase_boundary_value_bc; - break; - - case GKYL_BC_GK_FIELD_BOUNDARY_VALUE: - assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. - fout->func = conf_boundary_value_bc; - break; - - default: - fprintf(stderr, "bctype %d not supported in bc_basic_gyrokinetic. Exiting.\n",bctype); - assert(false); - break; + case GKYL_BC_GK_SPECIES_COPY: + fout->func = copy_bc; + break; + + case GKYL_BC_GK_SPECIES_FIXED_FUNC: + assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. + assert(basis->b_type == GKYL_BASIS_MODAL_GKHYBRID); // MF 2025/11/03: Hardcoded for now. + fout->func = phase_boundary_value_bc; + break; + + case GKYL_BC_GK_SPECIES_ABSORB: + fout->func = species_absorb_bc; + break; + + case GKYL_BC_GK_SPECIES_REFLECT: + fout->func = species_reflect_bc; + break; + + case GKYL_BC_GK_SPECIES_BOUNDARY_VALUE: + assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. + assert(basis->b_type == GKYL_BASIS_MODAL_GKHYBRID); // MF 2025/11/03: Hardcoded for now. + fout->func = phase_boundary_value_bc; + break; + + case GKYL_BC_GK_FIELD_BOUNDARY_VALUE: + assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. + fout->func = conf_boundary_value_bc; + break; + + default: + fprintf(stderr, "bctype %d not supported in bc_basic_gyrokinetic. Exiting.\n", bctype); + assert(false); + break; } fout->ctx = ctx; fout->ctx_on_dev = fout->ctx; @@ -67,10 +68,11 @@ gkyl_bc_basic_gyrokinetic_create_arr_copy_func(int dir, enum gkyl_edge_loc edge, return fout; } -struct gkyl_bc_basic_gyrokinetic* -gkyl_bc_basic_gyrokinetic_new(int dir, enum gkyl_edge_loc edge, enum gkyl_gyrokinetic_bc_type bctype, - const struct gkyl_basis *basis, const struct gkyl_range *skin_r, - const struct gkyl_range *ghost_r, int num_comp, int cdim, bool use_gpu) +struct gkyl_bc_basic_gyrokinetic *gkyl_bc_basic_gyrokinetic_new( + int dir, enum gkyl_edge_loc edge, enum gkyl_gyrokinetic_bc_type bctype, + const struct gkyl_basis *basis, const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, + int num_comp, int cdim, bool use_gpu +) { // Allocate space for new updater. struct gkyl_bc_basic_gyrokinetic *up = gkyl_malloc(sizeof(struct gkyl_bc_basic_gyrokinetic)); @@ -85,55 +87,54 @@ gkyl_bc_basic_gyrokinetic_new(int dir, enum gkyl_edge_loc edge, enum gkyl_gyroki // Create function applied to array contents (DG coefficients) when // copying to/from buffer. - up->array_copy_func = gkyl_bc_basic_gyrokinetic_create_arr_copy_func(dir, edge, - cdim, up->bctype, basis, num_comp, use_gpu); + up->array_copy_func = gkyl_bc_basic_gyrokinetic_create_arr_copy_func( + dir, edge, cdim, up->bctype, basis, num_comp, use_gpu + ); return up; } -void -gkyl_bc_basic_gyrokinetic_buffer_fixed_func(const struct gkyl_bc_basic_gyrokinetic *up, - struct gkyl_array *buff_arr, struct gkyl_array *f_arr) +void gkyl_bc_basic_gyrokinetic_buffer_fixed_func( + const struct gkyl_bc_basic_gyrokinetic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr +) { - if (up->bctype == GKYL_BC_GK_SPECIES_FIXED_FUNC) - gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, - up->ghost_r, up->array_copy_func->on_dev); + if (up->bctype == GKYL_BC_GK_SPECIES_FIXED_FUNC) { + gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, up->ghost_r, up->array_copy_func->on_dev); + } } -void -gkyl_bc_basic_gyrokinetic_advance(const struct gkyl_bc_basic_gyrokinetic *up, - struct gkyl_array *buff_arr, struct gkyl_array *f_arr) +void gkyl_bc_basic_gyrokinetic_advance( + const struct gkyl_bc_basic_gyrokinetic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr +) { // Apply BC in two steps: // 1) Copy skin to buffer while applying array_copy_func. switch (up->bctype) { - case GKYL_BC_GK_SPECIES_COPY: - case GKYL_BC_GK_SPECIES_ABSORB: - gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, - up->skin_r, up->array_copy_func->on_dev); - break; - - case GKYL_BC_GK_SPECIES_REFLECT: - gkyl_array_flip_copy_to_buffer_fn(buff_arr->data, f_arr, up->cdim, - up->skin_r, up->array_copy_func->on_dev); - break; - - case GKYL_BC_GK_SPECIES_BOUNDARY_VALUE: - gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, - up->skin_r, up->array_copy_func->on_dev); - break; - - case GKYL_BC_GK_FIELD_BOUNDARY_VALUE: - gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, - up->skin_r, up->array_copy_func->on_dev); - break; - - case GKYL_BC_GK_SPECIES_FIXED_FUNC: // if BC is fixed func, do nothing, buffer already full - break; - - default: - fprintf(stderr, "bctype %d not supported in bc_basic_gyrokinetic. Exiting.\n",up->bctype); - assert(false); - break; + case GKYL_BC_GK_SPECIES_COPY: + case GKYL_BC_GK_SPECIES_ABSORB: + gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, up->skin_r, up->array_copy_func->on_dev); + break; + + case GKYL_BC_GK_SPECIES_REFLECT: + gkyl_array_flip_copy_to_buffer_fn( + buff_arr->data, f_arr, up->cdim, up->skin_r, up->array_copy_func->on_dev + ); + break; + + case GKYL_BC_GK_SPECIES_BOUNDARY_VALUE: + gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, up->skin_r, up->array_copy_func->on_dev); + break; + + case GKYL_BC_GK_FIELD_BOUNDARY_VALUE: + gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, up->skin_r, up->array_copy_func->on_dev); + break; + + case GKYL_BC_GK_SPECIES_FIXED_FUNC: // if BC is fixed func, do nothing, buffer already full + break; + + default: + fprintf(stderr, "bctype %d not supported in bc_basic_gyrokinetic. Exiting.\n", up->bctype); + assert(false); + break; } // 2) Copy from buffer to ghost. gkyl_array_copy_from_buffer(f_arr, buff_arr->data, up->ghost_r); diff --git a/gyrokinetic/zero/bc_basic_gyrokinetic_cu.cu b/gyrokinetic/zero/bc_basic_gyrokinetic_cu.cu index 8d66f4fe0e..8e3d2a4229 100644 --- a/gyrokinetic/zero/bc_basic_gyrokinetic_cu.cu +++ b/gyrokinetic/zero/bc_basic_gyrokinetic_cu.cu @@ -7,11 +7,11 @@ extern "C" { #include } -__global__ static void -gkyl_bc_basic_gyrokinetic_create_set_cu_dev_ptrs(int dir, enum gkyl_edge_loc edge, - int cdim, enum gkyl_gyrokinetic_bc_type bctype, - const struct gkyl_basis* basis, int ncomp, struct dg_bc_ctx *ctx, - struct gkyl_array_copy_func *fout) +__global__ static void gkyl_bc_basic_gyrokinetic_create_set_cu_dev_ptrs( + int dir, enum gkyl_edge_loc edge, int cdim, enum gkyl_gyrokinetic_bc_type bctype, + const struct gkyl_basis *basis, int ncomp, struct dg_bc_ctx *ctx, + struct gkyl_array_copy_func *fout +) { ctx->dir = dir; ctx->edge = edge; @@ -20,65 +20,69 @@ gkyl_bc_basic_gyrokinetic_create_set_cu_dev_ptrs(int dir, enum gkyl_edge_loc edg ctx->ncomp = ncomp; switch (bctype) { - case GKYL_BC_GK_SPECIES_COPY: - fout->func = copy_bc; - break; - - case GKYL_BC_GK_SPECIES_FIXED_FUNC: - assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. - assert(basis->b_type == GKYL_BASIS_MODAL_GKHYBRID); // MF 2025/11/03: Hardcoded for now. - fout->func = phase_boundary_value_bc; - break; - - case GKYL_BC_GK_SPECIES_ABSORB: - fout->func = species_absorb_bc; - break; - - case GKYL_BC_GK_SPECIES_REFLECT: - fout->func = species_reflect_bc; - break; - - case GKYL_BC_GK_SPECIES_BOUNDARY_VALUE: - assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. - assert(basis->b_type == GKYL_BASIS_MODAL_GKHYBRID); // MF 2025/11/03: Hardcoded for now. - fout->func = phase_boundary_value_bc; - break; - - case GKYL_BC_GK_FIELD_BOUNDARY_VALUE: - assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. - fout->func = conf_boundary_value_bc; - break; - - default: - assert(false); // bctype not supported in bc_basic_gyrokinetic. - break; + case GKYL_BC_GK_SPECIES_COPY: + fout->func = copy_bc; + break; + + case GKYL_BC_GK_SPECIES_FIXED_FUNC: + assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. + assert(basis->b_type == GKYL_BASIS_MODAL_GKHYBRID); // MF 2025/11/03: Hardcoded for now. + fout->func = phase_boundary_value_bc; + break; + + case GKYL_BC_GK_SPECIES_ABSORB: + fout->func = species_absorb_bc; + break; + + case GKYL_BC_GK_SPECIES_REFLECT: + fout->func = species_reflect_bc; + break; + + case GKYL_BC_GK_SPECIES_BOUNDARY_VALUE: + assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. + assert(basis->b_type == GKYL_BASIS_MODAL_GKHYBRID); // MF 2025/11/03: Hardcoded for now. + fout->func = phase_boundary_value_bc; + break; + + case GKYL_BC_GK_FIELD_BOUNDARY_VALUE: + assert(basis->poly_order == 1); // MF 2025/11/03: Hardcoded for now. + fout->func = conf_boundary_value_bc; + break; + + default: + assert(false); // bctype not supported in bc_basic_gyrokinetic. + break; } fout->ctx = ctx; } -struct gkyl_array_copy_func* -gkyl_bc_basic_gyrokinetic_create_arr_copy_func_cu(int dir, enum gkyl_edge_loc edge, - int cdim, enum gkyl_gyrokinetic_bc_type bctype, - const struct gkyl_basis *basis, int ncomp) +struct gkyl_array_copy_func *gkyl_bc_basic_gyrokinetic_create_arr_copy_func_cu( + int dir, enum gkyl_edge_loc edge, int cdim, enum gkyl_gyrokinetic_bc_type bctype, + const struct gkyl_basis *basis, int ncomp +) { // Create host context and bc func structs. - struct dg_bc_ctx *ctx = (struct dg_bc_ctx*) gkyl_malloc(sizeof(struct dg_bc_ctx)); - struct gkyl_array_copy_func *fout = (struct gkyl_array_copy_func*) gkyl_malloc(sizeof(struct gkyl_array_copy_func)); + struct dg_bc_ctx *ctx = (struct dg_bc_ctx *)gkyl_malloc(sizeof(struct dg_bc_ctx)); + struct gkyl_array_copy_func *fout = + (struct gkyl_array_copy_func *)gkyl_malloc(sizeof(struct gkyl_array_copy_func)); fout->ctx = ctx; fout->flags = 0; GKYL_SET_CU_ALLOC(fout->flags); // Create device context and bc func structs. - struct dg_bc_ctx *ctx_cu = (struct dg_bc_ctx*) gkyl_cu_malloc(sizeof(struct dg_bc_ctx)); - struct gkyl_array_copy_func *fout_cu = (struct gkyl_array_copy_func*) gkyl_cu_malloc(sizeof(struct gkyl_array_copy_func)); + struct dg_bc_ctx *ctx_cu = (struct dg_bc_ctx *)gkyl_cu_malloc(sizeof(struct dg_bc_ctx)); + struct gkyl_array_copy_func *fout_cu = + (struct gkyl_array_copy_func *)gkyl_cu_malloc(sizeof(struct gkyl_array_copy_func)); gkyl_cu_memcpy(ctx_cu, ctx, sizeof(struct dg_bc_ctx), GKYL_CU_MEMCPY_H2D); gkyl_cu_memcpy(fout_cu, fout, sizeof(struct gkyl_array_copy_func), GKYL_CU_MEMCPY_H2D); fout->ctx_on_dev = ctx_cu; - gkyl_bc_basic_gyrokinetic_create_set_cu_dev_ptrs<<<1,1>>>(dir, edge, cdim, bctype, basis, ncomp, ctx_cu, fout_cu); + gkyl_bc_basic_gyrokinetic_create_set_cu_dev_ptrs<<<1, 1> > >( + dir, edge, cdim, bctype, basis, ncomp, ctx_cu, fout_cu + ); // Set parent on_dev pointer. fout->on_dev = fout_cu; diff --git a/gyrokinetic/zero/bc_block_tensor.c b/gyrokinetic/zero/bc_block_tensor.c index 201f7e2770..964ca1649f 100644 --- a/gyrokinetic/zero/bc_block_tensor.c +++ b/gyrokinetic/zero/bc_block_tensor.c @@ -6,19 +6,18 @@ static inline double dot_product(const double *v1, const double *v2) { double out = 0.0; - for(int i = 0; i < 3; i++) - out += v1[i]*v2[i]; + for (int i = 0; i < 3; i++) { + out += v1[i] * v2[i]; + } return out; } - - - -struct bc_block_tensor* -gkyl_bc_block_tensor_new(const struct gkyl_rect_grid* grid, const struct gkyl_range *range, const struct gkyl_range* range_ext, - const struct gkyl_basis* basis, bool use_gpu) +struct bc_block_tensor *gkyl_bc_block_tensor_new( + const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + const struct gkyl_range *range_ext, const struct gkyl_basis *basis, bool use_gpu +) { - struct bc_block_tensor *up = gkyl_malloc(sizeof(* up)); + struct bc_block_tensor *up = gkyl_malloc(sizeof(*up)); up->basis = *basis; up->range = *range; up->range_ext = *range_ext; @@ -27,68 +26,77 @@ gkyl_bc_block_tensor_new(const struct gkyl_rect_grid* grid, const struct gkyl_ra up->poly_order = basis->poly_order; struct gkyl_basis surf_basis; - gkyl_cart_modal_tensor(&surf_basis, up->cdim-1, up->poly_order); + gkyl_cart_modal_tensor(&surf_basis, up->cdim - 1, up->poly_order); up->num_surf_nodes = surf_basis.num_basis; - up->tensor = gkyl_array_new(GKYL_DOUBLE, up->cdim*up->cdim*up->num_surf_nodes, up->range_ext.volume); + up->tensor = + gkyl_array_new(GKYL_DOUBLE, up->cdim * up->cdim * up->num_surf_nodes, up->range_ext.volume); return up; } - -void calc_tensor(struct bc_block_tensor *up, int dir, int edge1, int edge2, const double *ej, const double *e_i, double *tj_i) +void calc_tensor( + struct bc_block_tensor *up, int dir, int edge1, int edge2, const double *ej, const double *e_i, + double *tj_i +) { // First evaluate at all the quadrature nodes double ej_surf[up->num_surf_nodes][9]; double e_i_surf[up->num_surf_nodes][9]; - for(int n = 0; n < up->num_surf_nodes; n++) { - for(int i = 0; i < 9; i++) { - e_i_surf[n][i] = bc_block_tensor_choose_kernel(up->cdim, edge1, dir, n) (&e_i[i*up->basis.num_basis]); - ej_surf[n][i] = bc_block_tensor_choose_kernel(up->cdim, edge2, dir, n) (&ej[i*up->basis.num_basis]); + for (int n = 0; n < up->num_surf_nodes; n++) { + for (int i = 0; i < 9; i++) { + e_i_surf[n][i] = + bc_block_tensor_choose_kernel(up->cdim, edge1, dir, n)(&e_i[i * up->basis.num_basis]); + ej_surf[n][i] = + bc_block_tensor_choose_kernel(up->cdim, edge2, dir, n)(&ej[i * up->basis.num_basis]); } } // Now take the dot prduct at the quadrature nodes and fill the tensor // Only Need T11,13,31,33 in 2d - int jctr=0; - for (int j = 0; j < 3; j++){ - if(up->cdim==2 && j==1) + int jctr = 0; + for (int j = 0; j < 3; j++) { + if (up->cdim == 2 && j == 1) { continue; - if(jctr!=dir){ // We only want to fill elements needed at this interface. - // For example if we are at a z edge then we only need T^3'_1 and T^3'_3 - // At the corner cell, T^1'_1 and T^1'_3 will be filled using another blocks tan vecs - jctr+=1; + } + if (jctr != dir) { // We only want to fill elements needed at this interface. + // For example if we are at a z edge then we only need T^3'_1 and T^3'_3 + // At the corner cell, T^1'_1 and T^1'_3 will be filled using another blocks tan vecs + jctr += 1; continue; } - for(int n = 0; n < up->num_surf_nodes; n++) { - int ictr=0; - for (int i = 0; i < 3; i++){ - if(up->cdim==2 && i==1) + for (int n = 0; n < up->num_surf_nodes; n++) { + int ictr = 0; + for (int i = 0; i < 3; i++) { + if (up->cdim == 2 && i == 1) { continue; - tj_i[up->cdim*up->num_surf_nodes*jctr + up->cdim*n + ictr] = dot_product(&ej_surf[n][3*j], &e_i_surf[n][3*i]); + } + tj_i[up->cdim * up->num_surf_nodes * jctr + up->cdim * n + ictr] = + dot_product(&ej_surf[n][3 * j], &e_i_surf[n][3 * i]); //printf("\n\nj,i = %d, %d\n", j,i); //printf("t = %g\n", tj_i[up->cdim*up->num_surf_nodes*jctr + up->cdim*n + ictr]); //printf("index = %d\n", up->cdim*up->num_surf_nodes*jctr + up->cdim*n + ictr); //printf("jctr,ictr,n = %d, %d, %d\n\n", jctr,ictr,n); - ictr+=1; + ictr += 1; } } - jctr+=1; + jctr += 1; } - } -void gkyl_bc_block_tensor_advance(struct bc_block_tensor* up, int dir, int edge1, int edge2, - struct gkyl_array* dxdz1, struct gkyl_array* dzdx2, struct gkyl_range *range1, struct gkyl_range *range2) +void gkyl_bc_block_tensor_advance( + struct bc_block_tensor *up, int dir, int edge1, int edge2, struct gkyl_array *dxdz1, + struct gkyl_array *dzdx2, struct gkyl_range *range1, struct gkyl_range *range2 +) { // Need to loop along only the directions != dir // For block 1, the index in dir will be min/max based on edge1 // For block 2, index in dir is based on edge2 - int idx1[GKYL_MAX_DIM] = { 0}; - int idx2[GKYL_MAX_DIM] = { 0}; + int idx1[GKYL_MAX_DIM] = {0}; + int idx2[GKYL_MAX_DIM] = {0}; idx1[dir] = edge1 == 0 ? range1->lower[dir] : range1->upper[dir]; idx2[dir] = edge2 == 0 ? range2->lower[dir] : range2->upper[dir]; - + struct gkyl_range range_def; int remdir[GKYL_MAX_DIM] = {0}; remdir[dir] = 1; @@ -102,22 +110,22 @@ void gkyl_bc_block_tensor_advance(struct bc_block_tensor* up, int dir, int edge1 // Fill the indices and fetch loc in each block int ictr = 0; for (int i = 0; i < up->cdim; i++) { - if (i!=dir) { + if (i != dir) { idx1[i] = iter.idx[ictr]; idx2[i] = iter.idx[ictr]; - ictr+=1; + ictr += 1; } } long loc1 = gkyl_range_idx(range1, idx1); long loc2 = gkyl_range_idx(range1, idx2); - const double* ej = gkyl_array_cfetch(dzdx2, loc2); - const double* e_i = gkyl_array_cfetch(dxdz1, loc1); - double* tj_i = gkyl_array_fetch(up->tensor, loc2); + const double *ej = gkyl_array_cfetch(dzdx2, loc2); + const double *e_i = gkyl_array_cfetch(dxdz1, loc1); + double *tj_i = gkyl_array_fetch(up->tensor, loc2); calc_tensor(up, dir, edge1, edge2, ej, e_i, tj_i); } } -void gkyl_bc_block_tensor_release(struct bc_block_tensor* up) +void gkyl_bc_block_tensor_release(struct bc_block_tensor *up) { gkyl_array_release(up->tensor); gkyl_free(up); diff --git a/gyrokinetic/zero/bc_sheath_gyrokinetic.c b/gyrokinetic/zero/bc_sheath_gyrokinetic.c index ebbb0e50ab..d4f2100b4e 100644 --- a/gyrokinetic/zero/bc_sheath_gyrokinetic.c +++ b/gyrokinetic/zero/bc_sheath_gyrokinetic.c @@ -3,12 +3,12 @@ #include #include -struct gkyl_bc_sheath_gyrokinetic* -gkyl_bc_sheath_gyrokinetic_new(int dir, enum gkyl_edge_loc edge, const struct gkyl_basis *basis, - const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, const struct gkyl_velocity_map *vel_map, - int cdim, double q2Dm, bool use_gpu) +struct gkyl_bc_sheath_gyrokinetic *gkyl_bc_sheath_gyrokinetic_new( + int dir, enum gkyl_edge_loc edge, const struct gkyl_basis *basis, const struct gkyl_range *skin_r, + const struct gkyl_range *ghost_r, const struct gkyl_velocity_map *vel_map, int cdim, double q2Dm, + bool use_gpu +) { - // Allocate space for new updater. struct gkyl_bc_sheath_gyrokinetic *up = gkyl_malloc(sizeof(*up)); @@ -44,9 +44,10 @@ gkyl_bc_sheath_gyrokinetic_new(int dir, enum gkyl_edge_loc edge, const struct gk } /* Modeled after gkyl_array_flip_copy_to_buffer_fn */ -void -gkyl_bc_sheath_gyrokinetic_advance(const struct gkyl_bc_sheath_gyrokinetic *up, const struct gkyl_array *phi, - const struct gkyl_array *phi_wall, struct gkyl_array *distf, const struct gkyl_range *conf_r) +void gkyl_bc_sheath_gyrokinetic_advance( + const struct gkyl_bc_sheath_gyrokinetic *up, const struct gkyl_array *phi, + const struct gkyl_array *phi_wall, struct gkyl_array *distf, const struct gkyl_range *conf_r +) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { @@ -58,14 +59,13 @@ gkyl_bc_sheath_gyrokinetic_advance(const struct gkyl_bc_sheath_gyrokinetic *up, int fidx[GKYL_MAX_DIM]; // Flipped index. int vidx[2]; - int pdim = up->skin_r->ndim; + int pdim = up->skin_r->ndim; int vpar_dir = up->cdim; - int uplo = up->skin_r->upper[vpar_dir]+up->skin_r->lower[vpar_dir]; + int uplo = up->skin_r->upper[vpar_dir] + up->skin_r->lower[vpar_dir]; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, up->skin_r); while (gkyl_range_iter_next(&iter)) { - gkyl_copy_int_arr(pdim, iter.idx, fidx); fidx[vpar_dir] = uplo - iter.idx[vpar_dir]; // Turn this skin fidx into a ghost fidx. @@ -74,16 +74,18 @@ gkyl_bc_sheath_gyrokinetic_advance(const struct gkyl_bc_sheath_gyrokinetic *up, long skin_loc = gkyl_range_idx(up->skin_r, iter.idx); long ghost_loc = gkyl_range_idx(up->ghost_r, fidx); - const double *inp = (const double*) gkyl_array_cfetch(distf, skin_loc); - double *out = (double*) gkyl_array_fetch(distf, ghost_loc); + const double *inp = (const double *)gkyl_array_cfetch(distf, skin_loc); + double *out = (double *)gkyl_array_fetch(distf, ghost_loc); - for (int d=up->cdim; dcdim] = iter.idx[d]; + for (int d = up->cdim; d < pdim; d++) { + vidx[d - up->cdim] = iter.idx[d]; + } long conf_loc = gkyl_range_idx(conf_r, iter.idx); long vel_loc = gkyl_range_idx(&up->vel_map->local_vel, vidx); - const double *phi_p = (const double*) gkyl_array_cfetch(phi, conf_loc); - const double *phi_wall_p = (const double*) gkyl_array_cfetch(phi_wall, conf_loc); - const double *vmap_p = (const double*) gkyl_array_cfetch(up->vel_map->vmap, vel_loc); + const double *phi_p = (const double *)gkyl_array_cfetch(phi, conf_loc); + const double *phi_wall_p = (const double *)gkyl_array_cfetch(phi_wall, conf_loc); + const double *vmap_p = (const double *)gkyl_array_cfetch(up->vel_map->vmap, vel_loc); // Calculate reflected distribution function fhat. // note: reflected distribution can be diff --git a/gyrokinetic/zero/bc_sheath_gyrokinetic_cu.cu b/gyrokinetic/zero/bc_sheath_gyrokinetic_cu.cu index 59f89886cc..3e093ec2d1 100644 --- a/gyrokinetic/zero/bc_sheath_gyrokinetic_cu.cu +++ b/gyrokinetic/zero/bc_sheath_gyrokinetic_cu.cu @@ -6,36 +6,40 @@ extern "C" { } // CUDA kernel to set device pointers to kernel that computes the reflected f. -__global__ static void -gkyl_bc_gksheath_set_cu_ker_ptrs(const struct gkyl_basis *basis, - enum gkyl_edge_loc edge, struct gkyl_bc_sheath_gyrokinetic_kernels *kers) +__global__ static void gkyl_bc_gksheath_set_cu_ker_ptrs( + const struct gkyl_basis *basis, enum gkyl_edge_loc edge, + struct gkyl_bc_sheath_gyrokinetic_kernels *kers +) { int dim = basis->ndim; enum gkyl_basis_type b_type = basis->b_type; int poly_order = basis->poly_order; switch (b_type) { - case GKYL_BASIS_MODAL_GKHYBRID: - case GKYL_BASIS_MODAL_SERENDIPITY: - kers->reflectedf = ser_sheath_reflect_list[edge].list[dim-2].kernels[poly_order-1]; - break; - default: - assert(false); + case GKYL_BASIS_MODAL_GKHYBRID: + case GKYL_BASIS_MODAL_SERENDIPITY: + kers->reflectedf = ser_sheath_reflect_list[edge].list[dim - 2].kernels[poly_order - 1]; + break; + default: + assert(false); } }; -void -gkyl_bc_gksheath_choose_reflectedf_kernel_cu(const struct gkyl_basis *basis, - enum gkyl_edge_loc edge, struct gkyl_bc_sheath_gyrokinetic_kernels *kers) +void gkyl_bc_gksheath_choose_reflectedf_kernel_cu( + const struct gkyl_basis *basis, enum gkyl_edge_loc edge, + struct gkyl_bc_sheath_gyrokinetic_kernels *kers +) { - gkyl_bc_gksheath_set_cu_ker_ptrs<<<1,1>>>(basis, edge, kers); + gkyl_bc_gksheath_set_cu_ker_ptrs<<<1, 1> > >(basis, edge, kers); } -__global__ static void -gkyl_bc_sheath_gyrokinetic_advance_cu_ker(int cdim, int dir, const struct gkyl_range skin_r, const struct gkyl_range ghost_r, +__global__ static void gkyl_bc_sheath_gyrokinetic_advance_cu_ker( + int cdim, int dir, const struct gkyl_range skin_r, const struct gkyl_range ghost_r, const struct gkyl_range conf_r, const struct gkyl_range vel_r, const struct gkyl_basis *basis, const struct gkyl_array *vmap, double q2Dm, const struct gkyl_array *phi, - const struct gkyl_array *phi_wall, struct gkyl_bc_sheath_gyrokinetic_kernels *kers, struct gkyl_array *distf) + const struct gkyl_array *phi_wall, struct gkyl_bc_sheath_gyrokinetic_kernels *kers, + struct gkyl_array *distf +) { int fidx[GKYL_MAX_DIM]; // Flipped index. int pidx[GKYL_MAX_DIM]; @@ -43,11 +47,10 @@ gkyl_bc_sheath_gyrokinetic_advance_cu_ker(int cdim, int dir, const struct gkyl_r int pdim = skin_r.ndim; int vpar_dir = cdim; - int uplo = skin_r.upper[vpar_dir]+skin_r.lower[vpar_dir]; - - for(unsigned long linc = threadIdx.x + blockIdx.x*blockDim.x; - linc < skin_r.volume; linc += blockDim.x*gridDim.x) { + int uplo = skin_r.upper[vpar_dir] + skin_r.lower[vpar_dir]; + for (unsigned long linc = threadIdx.x + blockIdx.x * blockDim.x; linc < skin_r.volume; + linc += blockDim.x * gridDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -62,23 +65,25 @@ gkyl_bc_sheath_gyrokinetic_advance_cu_ker(int cdim, int dir, const struct gkyl_r long skin_loc = gkyl_range_idx(&skin_r, pidx); long ghost_loc = gkyl_range_idx(&ghost_r, fidx); - const double *inp = (const double*) gkyl_array_cfetch(distf, skin_loc); - double *out = (double*) gkyl_array_fetch(distf, ghost_loc); + const double *inp = (const double *)gkyl_array_cfetch(distf, skin_loc); + double *out = (double *)gkyl_array_fetch(distf, ghost_loc); - for (int d=cdim; dreflectedf(vmap_p, q2Dm, phi_p, phi_wall_p, inp, fhat); // Reflect fhat into skin cells. @@ -86,15 +91,18 @@ gkyl_bc_sheath_gyrokinetic_advance_cu_ker(int cdim, int dir, const struct gkyl_r } } -void -gkyl_bc_sheath_gyrokinetic_advance_cu(const struct gkyl_bc_sheath_gyrokinetic *up, const struct gkyl_array *phi, - const struct gkyl_array *phi_wall, struct gkyl_array *distf, const struct gkyl_range *conf_r) +void gkyl_bc_sheath_gyrokinetic_advance_cu( + const struct gkyl_bc_sheath_gyrokinetic *up, const struct gkyl_array *phi, + const struct gkyl_array *phi_wall, struct gkyl_array *distf, const struct gkyl_range *conf_r +) { if (up->skin_r->volume > 0) { int nblocks = up->skin_r->nblocks, nthreads = up->skin_r->nthreads; - gkyl_bc_sheath_gyrokinetic_advance_cu_ker<<>>(up->cdim, up->dir, *up->skin_r, *up->ghost_r, - *conf_r, up->vel_map->local_vel, up->basis, up->vel_map->vmap->on_dev, up->q2Dm, phi->on_dev, phi_wall->on_dev, - up->kernels_cu, distf->on_dev); + gkyl_bc_sheath_gyrokinetic_advance_cu_ker<< > >( + up->cdim, up->dir, *up->skin_r, *up->ghost_r, *conf_r, up->vel_map->local_vel, up->basis, + up->vel_map->vmap->on_dev, up->q2Dm, phi->on_dev, phi_wall->on_dev, up->kernels_cu, + distf->on_dev + ); } } diff --git a/gyrokinetic/zero/bc_twistshift.c b/gyrokinetic/zero/bc_twistshift.c index bf65db7ccb..df2c5d4244 100644 --- a/gyrokinetic/zero/bc_twistshift.c +++ b/gyrokinetic/zero/bc_twistshift.c @@ -82,46 +82,44 @@ #define tol_xi 1.0e-15 // Indices in 4-element cell boundary array. -#define cellb_lo(dir) (2*dir) -#define cellb_up(dir) (2*dir+1) +#define cellb_lo(dir) (2 * dir) +#define cellb_up(dir) (2 * dir + 1) -double -ts_grid_cell_boundary_in_dir(struct gkyl_rect_grid *grid, const int *idx, enum gkyl_edge_loc edge, int dir) +double ts_grid_cell_boundary_in_dir( + struct gkyl_rect_grid *grid, const int *idx, enum gkyl_edge_loc edge, int dir +) { // Get the coordinate of the cell boundary in specified direction. double xc[grid->ndim]; gkyl_rect_grid_cell_center(grid, idx, xc); - return edge == GKYL_LOWER_EDGE? xc[dir]-0.5*grid->dx[dir] : xc[dir]+0.5*grid->dx[dir]; + return edge == GKYL_LOWER_EDGE ? xc[dir] - 0.5 * grid->dx[dir] : xc[dir] + 0.5 * grid->dx[dir]; } -void -ts_grid_cell_boundaries(struct gkyl_rect_grid *grid, const int *idx, double *cell_bounds) +void ts_grid_cell_boundaries(struct gkyl_rect_grid *grid, const int *idx, double *cell_bounds) { // Get the cell boundaries in every dimension. The array cell_bounds // must be a 2*grid->ndim array. - for (int d=0; dndim; d++) { - cell_bounds[d*2] = ts_grid_cell_boundary_in_dir(grid, idx, GKYL_LOWER_EDGE, d); - cell_bounds[d*2+1] = ts_grid_cell_boundary_in_dir(grid, idx, GKYL_UPPER_EDGE, d); + for (int d = 0; d < grid->ndim; d++) { + cell_bounds[d * 2] = ts_grid_cell_boundary_in_dir(grid, idx, GKYL_LOWER_EDGE, d); + cell_bounds[d * 2 + 1] = ts_grid_cell_boundary_in_dir(grid, idx, GKYL_UPPER_EDGE, d); } } -static inline double -ts_p2l(double coord, double cell_center, double dx) +static inline double ts_p2l(double coord, double cell_center, double dx) { // Transform a physical coordinate (coord) to the [-1,1] logical - // space in a cell centered at cell_center and with length dx. - return 2.0*(coord - cell_center)/dx; + // space in a cell centered at cell_center and with length dx. + return 2.0 * (coord - cell_center) / dx; } // Evaluation of the shift through the DG representation. -static inline void -ts_shift_dg_eval(double t, const double *coord, double *fout, void *ctx) +static inline void ts_shift_dg_eval(double t, const double *coord, double *fout, void *ctx) { struct ts_shift_dg_eval_ctx *tsectx = ctx; int cell_idx[GKYL_MAX_DIM]; gkyl_rect_grid_coord_idx(tsectx->shear_grid, coord, cell_idx); - // Ensure that we do not go outside of the range + // Ensure that we do not go outside of the range // (it does sometimes if x=x_max,x_min). cell_idx[0] = fmin(cell_idx[0], tsectx->shear_r->upper[0]); cell_idx[0] = fmax(cell_idx[0], tsectx->shear_r->lower[0]); @@ -130,50 +128,49 @@ ts_shift_dg_eval(double t, const double *coord, double *fout, void *ctx) gkyl_rect_grid_cell_center(tsectx->shear_grid, cell_idx, xc); long shift_loc = gkyl_range_idx(tsectx->shear_r, cell_idx); - double *shift_c = (double *) gkyl_array_fetch(tsectx->shift_dg, shift_loc); + double *shift_c = (double *)gkyl_array_fetch(tsectx->shift_dg, shift_loc); double xp = ts_p2l(coord[0], xc[0], tsectx->shear_grid->dx[0]); - fout[0] = tsectx->shift_b->eval_expand(&(double) {xp}, shift_c); + fout[0] = tsectx->shift_b->eval_expand(&(double){xp}, shift_c); } -void -ts_interval_dx_and_xc(const double *interval, double *dx, double *xc) +void ts_interval_dx_and_xc(const double *interval, double *dx, double *xc) { // Compute the lenth (dx) and center (xc) of [interval[0], interval[1]]. double lo = interval[0], up = interval[1]; dx[0] = up - lo; - xc[0] = 0.5*(up + lo); + xc[0] = 0.5 * (up + lo); } -static inline double -ts_grid_length_in_dir(struct gkyl_rect_grid *grid, int dir) +static inline double ts_grid_length_in_dir(struct gkyl_rect_grid *grid, int dir) { return grid->upper[dir] - grid->lower[dir]; } -double -ts_wrap_to_range(double val, double lower, double upper, bool pick_upper) +double ts_wrap_to_range(double val, double lower, double upper, bool pick_upper) { // Wrap a number to range [lower,upper]. If pickUpper=true, output upper when // val is a multiple of upper. Otherwise multiples of upper wrap to lower. - double L = upper - lower; - double disp = fmod(val - lower, L); + double L = upper - lower; + double disp = fmod(val - lower, L); double vwrapped = lower + fmod(L + disp, L); - double eps = 1.e-12; - if ( (lower-eps < vwrapped && vwrapped < lower + eps) || - (upper-eps < vwrapped && vwrapped < upper + eps) ) { - if (pick_upper) + double eps = 1.e-12; + if ((lower - eps < vwrapped && vwrapped < lower + eps) || + (upper - eps < vwrapped && vwrapped < upper + eps)) { + if (pick_upper) { return upper; - else + } else { return lower; - } - else + } + } else { return vwrapped; + } } -long -ts_shift_dir_idx_do_linidx(const int *num_do, int shear_dir_idx, int shift_dir_idx, - int shift_dir_num_cells, int shear_r_lower) +long ts_shift_dir_idx_do_linidx( + const int *num_do, int shear_dir_idx, int shift_dir_idx, int shift_dir_num_cells, + int shear_r_lower +) { // Return the linear index to the first donor for the idx=(i,j) target cell, // in the shift_dir_idx_do array. We assume shift_dir_idx_do (whose dimensions @@ -183,23 +180,25 @@ ts_shift_dir_idx_do_linidx(const int *num_do, int shear_dir_idx, int shift_dir_i // Count the number of donors in cells with an idx in the shear dir lower // than this one. NOTE: the -1 here is because the idx is often 1-index // (since ghost cells are the 0th index) but num_do is only defined on the - // local range. - for (int i=0; ishear_dir_in_ts_grid]}; int shift_idx[] = {idx[up->shift_dir_in_ts_grid]}; - int *shift_dir_idx_do_buff_ptr = (int *) gkyl_mem_buff_data(shift_dir_idx_do_buff); + int *shift_dir_idx_do_buff_ptr = (int *)gkyl_mem_buff_data(shift_dir_idx_do_buff); // Evaluate the shift at this test point. double test_pt_in_shear_dir = test_pt[up->shear_dir_in_ts_grid]; double xc_in_shear_dir = xc[up->shear_dir_in_ts_grid]; double dx_in_shear_dir = dx[up->shear_dir_in_ts_grid]; double shift_at_pt = up->shift_b.eval_expand( - &(double) {ts_p2l(test_pt_in_shear_dir, xc_in_shear_dir, dx_in_shear_dir)}, shift_c); + &(double){ts_p2l(test_pt_in_shear_dir, xc_in_shear_dir, dx_in_shear_dir)}, shift_c + ); // Find the index of the cell that owns the shifted point. - double shifted_test_pt[] = { ts_wrap_to_range(test_pt[up->shift_dir_in_ts_grid] - shift_at_pt, - up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid], - false) }; // Shifted test point. + double shifted_test_pt[] = {ts_wrap_to_range( + test_pt[up->shift_dir_in_ts_grid] - shift_at_pt, up->ts_grid.lower[up->shift_dir_in_ts_grid], + up->ts_grid.upper[up->shift_dir_in_ts_grid], false + )}; // Shifted test point. int shift_dir_idx_test_pt[1]; - gkyl_rect_grid_find_cell(&up->shift_grid, shifted_test_pt, (bool[]) {pick_lower}, (int[]) {-1}, shift_dir_idx_test_pt); + gkyl_rect_grid_find_cell( + &up->shift_grid, shifted_test_pt, (bool[]){pick_lower}, (int[]){-1}, shift_dir_idx_test_pt + ); // Get the linear index to the list of donors for this target. - long linidx = ts_shift_dir_idx_do_linidx(up->num_do, - shear_idx[0], shift_idx[0], up->ts_grid.cells[up->shift_dir_in_ts_grid], up->shear_r.lower[0]); + long linidx = ts_shift_dir_idx_do_linidx( + up->num_do, shear_idx[0], shift_idx[0], up->ts_grid.cells[up->shift_dir_in_ts_grid], + up->shear_r.lower[0] + ); // If this donor is not in our list of donors, include it. bool donor_not_found = true; - for (int k=0; kts_grid.dx[d]; - step_sz[d] = (up->ts_grid.dx[d] - 2.0*delta[d])/(num_test_pt[d]-1); + for (int d = 0; d < 2; d++) { + delta[d] = delta_frac * up->ts_grid.dx[d]; + step_sz[d] = (up->ts_grid.dx[d] - 2.0 * delta[d]) / (num_test_pt[d] - 1); } // Number of donors at each cell of the shear direction. - up->num_do = (int*) gkyl_malloc(up->shear_r.volume * sizeof(int)); - for (int i=0; ishear_r.volume; i++) + up->num_do = (int *)gkyl_malloc(up->shear_r.volume * sizeof(int)); + for (int i = 0; i < up->shear_r.volume; i++) { up->num_do[i] = -1; + } // Temporary buffer to store donors at (resized below). size_t curr_buff_sz = up->ts_r.volume * sizeof(int); @@ -282,7 +287,6 @@ ts_find_donors(struct gkyl_bc_twistshift *up) struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &up->ts_r); while (gkyl_range_iter_next(&iter)) { - // Get the cell boundaries and cell center. double cell_b[4] = {0.0}; // Cell boundaries, x lo and up, y lo and up; double xc[2] = {0.0}; // Cell center. @@ -292,83 +296,88 @@ ts_find_donors(struct gkyl_bc_twistshift *up) int shear_idx[] = {iter.idx[up->shear_dir_in_ts_grid]}; int shift_idx[] = {iter.idx[up->shift_dir_in_ts_grid]}; long shift_loc = gkyl_range_idx(&up->shear_r, shear_idx); - double *shift_c = (double *) gkyl_array_fetch(up->shift_dg, shift_loc); + double *shift_c = (double *)gkyl_array_fetch(up->shift_dg, shift_loc); int num_do_curr = 0; - for (int dC=0; dC<2; dC++) { // dC=0: x=const, dC=1: y=const (boundaries). - for (int xS=0; xS<2; xS++) { // xS=0: lower, xS=1 upper (boundary). + for (int dC = 0; dC < 2; dC++) { // dC=0: x=const, dC=1: y=const (boundaries). + for (int xS = 0; xS < 2; xS++) { // xS=0: lower, xS=1 upper (boundary). double test_pt[2] = {0.0}; // Test point to shift. - for (int d=0; d<2; d++) - test_pt[d] = cell_b[2*d]+delta[d]; + for (int d = 0; d < 2; d++) { + test_pt[d] = cell_b[2 * d] + delta[d]; + } // Search first shifted point. Use pick_lower=false in find_cell unless - // searching for points along a x=const line near the upper y-boundary. - bool pick_lower = dC==0 && xS==1; - test_pt[dC] += xS*(up->ts_grid.dx[dC]-2.0*delta[dC]); + // searching for points along a x=const line near the upper y-boundary. + bool pick_lower = dC == 0 && xS == 1; + test_pt[dC] += xS * (up->ts_grid.dx[dC] - 2.0 * delta[dC]); // Shift the test point, find the cell that contains it, and if we // haven't included it yet, add it to our list of donors. - ts_check_shifted_test_point(up, test_pt, xc, up->ts_grid.dx, - shift_c, iter.idx, pick_lower, &num_do_curr, shift_dir_idx_do_buff); - - // Search for other shifted points along this line. - int step_dim = (dC+1) % 2; - for (int sI=1; sIts_grid.dx, shift_c, iter.idx, pick_lower, &num_do_curr, + shift_dir_idx_do_buff + ); + + // Search for other shifted points along this line. + int step_dim = (dC + 1) % 2; + for (int sI = 1; sI < num_test_pt[step_dim]; sI++) { test_pt[step_dim] += step_sz[step_dim]; // Shift the test point, find the cell that contains it, and if we // haven't included it yet, add it to our list of donors. - ts_check_shifted_test_point(up, test_pt, xc, up->ts_grid.dx, - shift_c, iter.idx, pick_lower, &num_do_curr, shift_dir_idx_do_buff); + ts_check_shifted_test_point( + up, test_pt, xc, up->ts_grid.dx, shift_c, iter.idx, pick_lower, &num_do_curr, + shift_dir_idx_do_buff + ); } } } - up->num_do[shear_idx[0]-up->shear_r.lower[0]] = num_do_curr; - + up->num_do[shear_idx[0] - up->shear_r.lower[0]] = num_do_curr; } // Copy the donor list to the persistent object and release the buffer. size_t buff_sz = gkyl_mem_buff_size(shift_dir_idx_do_buff); - up->shift_dir_idx_do = (int *) gkyl_malloc(buff_sz); - int *shift_dir_idx_do_buff_ptr = (int *) gkyl_mem_buff_data(shift_dir_idx_do_buff); + up->shift_dir_idx_do = (int *)gkyl_malloc(buff_sz); + int *shift_dir_idx_do_buff_ptr = (int *)gkyl_mem_buff_data(shift_dir_idx_do_buff); memcpy(up->shift_dir_idx_do, shift_dir_idx_do_buff_ptr, buff_sz); gkyl_mem_buff_release(shift_dir_idx_do_buff); } struct gkyl_qr_res -ts_root_find(double (*func)(double,void*), void *ctx, const double *lims, int max_iter, double tol) +ts_root_find(double (*func)(double, void *), void *ctx, const double *lims, int max_iter, double tol) { // Use a Ridder's root finder to find the root of func in the interval // [lims[0],lims[1]] down to a tolerance 'tol'. Return the interval limit // if the function is smaller than the tolerance there. Return nil if the // function does not change sign in the interval (interval doesn't contain the root). double funcLo = func(lims[0], ctx), funcUp = func(lims[1], ctx); -// if (fabs(funcLo) < tol) -// return (struct gkyl_qr_res) {.res=lims[0], .status=0, .nevals=2}; -// else if (fabs(funcUp) < tol) -// return (struct gkyl_qr_res) {.res=lims[1], .status=0, .nevals=2}; -// else { -// if (funcLo*funcUp < 0) -// return gkyl_ridders(func, ctx, lims[0], lims[1], funcLo, funcUp, max_iter, tol); -// else -// return (struct gkyl_qr_res) {.status=1, .nevals=2}; -// } + // if (fabs(funcLo) < tol) + // return (struct gkyl_qr_res) {.res=lims[0], .status=0, .nevals=2}; + // else if (fabs(funcUp) < tol) + // return (struct gkyl_qr_res) {.res=lims[1], .status=0, .nevals=2}; + // else { + // if (funcLo*funcUp < 0) + // return gkyl_ridders(func, ctx, lims[0], lims[1], funcLo, funcUp, max_iter, tol); + // else + // return (struct gkyl_qr_res) {.status=1, .nevals=2}; + // } if (fabs(funcLo) > tol && fabs(funcUp) > tol) { - if (funcLo*funcUp < 0) + if (funcLo * funcUp < 0) { return gkyl_ridders(func, ctx, lims[0], lims[1], funcLo, funcUp, max_iter, tol); - else - return (struct gkyl_qr_res) {.status=1, .nevals=2}; + } else { + return (struct gkyl_qr_res){.status = 1, .nevals = 2}; + } + } else if (fabs(funcLo) < tol && fabs(funcUp) < tol) { + return (struct gkyl_qr_res){.status = 1, .nevals = 2}; + } else if (fabs(funcLo) < tol) { + return (struct gkyl_qr_res){.res = lims[0], .status = 0, .nevals = 2}; + } else if (fabs(funcUp) < tol) { + return (struct gkyl_qr_res){.res = lims[1], .status = 0, .nevals = 2}; } - else if (fabs(funcLo) < tol && fabs(funcUp) < tol) - return (struct gkyl_qr_res) {.status=1, .nevals=2}; - else if (fabs(funcLo) < tol) - return (struct gkyl_qr_res) {.res=lims[0], .status=0, .nevals=2}; - else if (fabs(funcUp) < tol) - return (struct gkyl_qr_res) {.res=lims[1], .status=0, .nevals=2}; - return (struct gkyl_qr_res) {.status=1, .nevals=2}; + return (struct gkyl_qr_res){.status = 1, .nevals = 2}; } struct ts_shifted_coord_loss_func_ctx { @@ -388,23 +397,24 @@ double ts_shifted_coord_loss_func(double shearCoord, void *ctx) double shift; tsctx->shift_func(0.0, (double[]){shearCoord}, &shift, tsctx->shift_func_ctx); - return tsctx->shiftCoordTar - shift - - (tsctx->shiftCoordDo - tsctx->periodicCopyIdx * tsctx->shiftDirL); + return tsctx->shiftCoordTar - shift - + (tsctx->shiftCoordDo - tsctx->periodicCopyIdx * tsctx->shiftDirL); } -int static inline -ts_sign(double a) +int static inline ts_sign(double a) { - if (a < 0.0) + if (a < 0.0) { return -1; - else if (a > 0.0) + } else if (a > 0.0) { return 1; - else + } else { return 0; + } } double -ts_donor_target_offset(struct gkyl_bc_twistshift *up, const double *xc_do, const double *xc_tar) { +ts_donor_target_offset(struct gkyl_bc_twistshift *up, const double *xc_do, const double *xc_tar) +{ // y-offset between the donor and the target cell (yDo-yTar), in the direction of the shift. // xc_do: cell center coordinates of donor cell. // xc_tar: cell center coordinates of target cell. @@ -416,28 +426,29 @@ ts_donor_target_offset(struct gkyl_bc_twistshift *up, const double *xc_do, const int shift_sign = ts_sign(shift); double shift_dir_L = up->ts_grid.upper[up->shift_dir] - up->ts_grid.lower[up->shift_dir]; - + // The idea here is that we keep shifting the donor cell center until it is in a // periodic copy of our domain which overlaps with the shifted target cell center. double xs_shifted_do = xc_do[shift_dir]; double xs_shifted_tar = xc_tar[shift_dir] - shift; bool keep_shifting = true; while (keep_shifting) { - double xs_shifted_dolo = xs_shifted_do - shift_dir_L/2.0; - double xs_shifted_doup = xs_shifted_do + shift_dir_L/2.0; + double xs_shifted_dolo = xs_shifted_do - shift_dir_L / 2.0; + double xs_shifted_doup = xs_shifted_do + shift_dir_L / 2.0; if (xs_shifted_dolo <= xs_shifted_tar && xs_shifted_tar <= xs_shifted_doup) { keep_shifting = false; break; + } else { + xs_shifted_do = xs_shifted_do - shift_sign * shift_dir_L; } - else - xs_shifted_do = xs_shifted_do - shift_sign*shift_dir_L; } return xc_tar[shift_dir] - xs_shifted_do; } -struct gkyl_qr_res -ts_find_intersect(struct gkyl_bc_twistshift *up, double shiftCoordTar, double shiftCoordDo, - const double *shearDirBounds, const double *shiftDirLimits, int nP_primary) +struct gkyl_qr_res ts_find_intersect( + struct gkyl_bc_twistshift *up, double shiftCoordTar, double shiftCoordDo, + const double *shearDirBounds, const double *shiftDirLimits, int nP_primary +) { // Given a y-coordinate of the target cell (yTar), and a y-coordinate // of the donor cell (yDo), find the x-coordinate where yTar-yShift(x)=yDo @@ -459,7 +470,7 @@ ts_find_intersect(struct gkyl_bc_twistshift *up, double shiftCoordTar, double sh .shiftDirL = shiftDirL, .periodicCopyIdx = nP_primary, .shift_func = up->shift_func, - .shift_func_ctx = up->shift_func_ctx, + .shift_func_ctx = up->shift_func_ctx }; return ts_root_find(ts_shifted_coord_loss_func, &func_ctx, shearDirBounds, max_iter, tol); } @@ -469,16 +480,19 @@ struct ts_val_found { double value; // value found. }; -static inline void -ts_comp_to_phys(int ndim, const double *eta, - const double * GKYL_RESTRICT dx, const double * GKYL_RESTRICT xc, - double* GKYL_RESTRICT xout) +static inline void ts_comp_to_phys( + int ndim, const double *eta, const double *GKYL_RESTRICT dx, const double *GKYL_RESTRICT xc, + double *GKYL_RESTRICT xout +) { - for (int d=0; dshift_b.num_basis; ++i) { - ts_comp_to_phys(1, gkyl_eval_on_nodes_fetch_node(up->ev_on_nod1d, i), - dx, xc, xmu); - func(0.0, xmu, (double *)gkyl_array_fetch(up->func_nod1d,i), func_ctx); + for (int i = 0; i < up->shift_b.num_basis; ++i) { + ts_comp_to_phys(1, gkyl_eval_on_nodes_fetch_node(up->ev_on_nod1d, i), dx, xc, xmu); + func(0.0, xmu, (double *)gkyl_array_fetch(up->func_nod1d, i), func_ctx); } - gkyl_eval_on_nodes_nod2mod(up->ev_on_nod1d, up->func_nod1d, out); + gkyl_eval_on_nodes_nod2mod(up->ev_on_nod1d, up->func_nod1d, out); } -void -ts_integral_xlimdg(struct gkyl_bc_twistshift *up, double sFac, const double *xLimLo, - const double *xLimUp, double yLimLo, double yLimUp, double dyDo, double yOff, - const double *ySh, struct gkyl_mat *mat_do) { +void ts_integral_xlimdg( + struct gkyl_bc_twistshift *up, double sFac, const double *xLimLo, const double *xLimUp, + double yLimLo, double yLimUp, double dyDo, double yOff, const double *ySh, struct gkyl_mat *mat_do +) +{ // Populate a matrix (mat_do) with a sub-cell integral that has variably x limits // represented by a DG polynomial, and a y-integral that goes from yLimLo to yLimUp. // up: BC updater. @@ -515,10 +529,11 @@ ts_integral_xlimdg(struct gkyl_bc_twistshift *up, double sFac, const double *xLi up->kernels->xlimdg(sFac, xLimLo, xLimUp, yLimLo, yLimUp, dyDo, yOff, ySh, mat_do); } -void -ts_integral_ylimdg(struct gkyl_bc_twistshift *up, double sFac, double xLimLo, double xLimUp, - const double *yLimLo, const double *yLimUp, double dyDo, double yOff, - const double *ySh, struct gkyl_mat *mat_do) { +void ts_integral_ylimdg( + struct gkyl_bc_twistshift *up, double sFac, double xLimLo, double xLimUp, const double *yLimLo, + const double *yLimUp, double dyDo, double yOff, const double *ySh, struct gkyl_mat *mat_do +) +{ // Populate a matrix (mat_do) with a sub-cell integral that has variable y limits // represented by a DG polynomial, and a x-integral that goes from xLimLo to xLimUp. // up: BC updater. @@ -534,9 +549,11 @@ ts_integral_ylimdg(struct gkyl_bc_twistshift *up, double sFac, double xLimLo, do up->kernels->ylimdg(sFac, xLimLo, xLimUp, yLimLo, yLimUp, dyDo, yOff, ySh, mat_do); } -void -ts_integral_fullcelllimdg(struct gkyl_bc_twistshift *up, double dyDo, double yOff, - const double *ySh, struct gkyl_mat *mat_do) { +void ts_integral_fullcelllimdg( + struct gkyl_bc_twistshift *up, double dyDo, double yOff, const double *ySh, + struct gkyl_mat *mat_do +) +{ // Populate a matrix (mat_do) with the full-cell integral. // up: BC updater. // sFac: +/-1 factor to add or subtract this subcell integral. @@ -547,14 +564,12 @@ ts_integral_fullcelllimdg(struct gkyl_bc_twistshift *up, double dyDo, double yOf up->kernels->fullcell(dyDo, yOff, ySh, mat_do); } -static inline void -ts_one(double t, const double *xn, double *fout, void *ctx) +static inline void ts_one(double t, const double *xn, double *fout, void *ctx) { fout[0] = 1.0; } -static inline void -ts_minus_one(double t, const double *xn, double *fout, void *ctx) +static inline void ts_minus_one(double t, const double *xn, double *fout, void *ctx) { fout[0] = -1.0; } @@ -571,8 +586,7 @@ struct ts_shift_coord_shifted_log_ctx { void *shift_func_ctx; // Context for shift_func. }; -void -ts_shift_coord_shifted_log(double t, const double *xn, double *fout, void *ctx) +void ts_shift_coord_shifted_log(double t, const double *xn, double *fout, void *ctx) { // Given a logical space x coordinate (xi) and a (physical) y-coordinate in the target cell, // compute the shifted y-coordinate in the logical space of the donor cell (eta \in [-1,1]). @@ -595,20 +609,22 @@ ts_shift_coord_shifted_log(double t, const double *xn, double *fout, void *ctx) int shear_dir = tsctx->shear_dir, shift_dir = tsctx->shift_dir; double *shift_dir_bounds = tsctx->shift_dir_bounds; - double shear_coord_phys = xc_tar[shear_dir] + 0.5*dx[shear_dir]*xi; + double shear_coord_phys = xc_tar[shear_dir] + 0.5 * dx[shear_dir] * xi; double shift; tsctx->shift_func(0.0, (double[]){shear_coord_phys}, &shift, tsctx->shift_func_ctx); double shift_coord_shifted = shift_coord_tar - shift_sign_fac * shift; - shift_coord_shifted = ts_wrap_to_range(shift_coord_shifted, shift_dir_bounds[0], shift_dir_bounds[1], pick_upper); + shift_coord_shifted = + ts_wrap_to_range(shift_coord_shifted, shift_dir_bounds[0], shift_dir_bounds[1], pick_upper); fout[0] = ts_p2l(shift_coord_shifted, xc_do[shift_dir], dx[shift_dir]); } -void -ts_subcellint_sNi_sNii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, - const double *xc_do, const double *xc_tar, const double *cellb_do, const double *cellb_tar, - bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do) +void ts_subcellint_sNi_sNii( + struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, const double *xc_do, + const double *xc_tar, const double *cellb_do, const double *cellb_tar, + bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do +) { // Perform sNi or sNii subcell integrals. // inter_pts: intersections y_{j_tar-/+1/2}-yShift and y_{j_do-/+1/2} (lower/upper y-boundaries of donor cell). @@ -630,10 +646,10 @@ ts_subcellint_sNi_sNii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter .pick_upper = is_upper_shift_dir_cell, .shear_dir = up->shear_dir_in_ts_grid, .shift_dir = up->shift_dir_in_ts_grid, - .shift_dir_bounds = {up->ts_grid.lower[up->shift_dir_in_ts_grid], - up->ts_grid.upper[up->shift_dir_in_ts_grid]}, + .shift_dir_bounds = + {up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid]}, .shift_func = up->shift_func, - .shift_func_ctx = up->shift_func_ctx, + .shift_func_ctx = up->shift_func_ctx }; double xi_b[2]; // Limits of xi integral. @@ -646,8 +662,12 @@ ts_subcellint_sNi_sNii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter if (is_sNi) { // sNi // 1) Add the contribution of the left portion. - xi_b[0] = ts_p2l(inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_up(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_minus_one; @@ -656,13 +676,20 @@ ts_subcellint_sNi_sNii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } // 2) Add the contribution of the right portion. - xi_b[0] = ts_p2l(inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_lo(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_shift_coord_shifted_log; @@ -671,15 +698,21 @@ ts_subcellint_sNi_sNii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); - } - else { + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } + } else { // sNii // 1) Add the contribution of the left portion. - xi_b[0] = ts_p2l(inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_lo(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_shift_coord_shifted_log; @@ -688,13 +721,20 @@ ts_subcellint_sNi_sNii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } // 2) Add the contribution of the right portion. - xi_b[0] = ts_p2l(inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_up(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_minus_one; @@ -703,16 +743,20 @@ ts_subcellint_sNi_sNii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } } } -void -ts_subcellint_si_sii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, - const double *xc_do, const double *xc_tar, const double *cellb_do, const double *cellb_tar, - bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do) +void ts_subcellint_si_sii( + struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, const double *xc_do, + const double *xc_tar, const double *cellb_do, const double *cellb_tar, + bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do +) { // Perform subcell integral si or sii, using fixed x-limits and variable y limits. // inter_pts: intersections y_{j_tar-/+1/2}-yShift and y_{j_do-/+1/2} (lower/upper y-boundaries of donor cell). @@ -733,15 +777,20 @@ ts_subcellint_si_sii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p bool is_si = -shift_lo < -shift_up; - double xi_b[2]; // Limits of xi integral. + double xi_b[2]; // Limits of xi integral. if (is_si) { // si integral. xi_b[0] = -1.0; - xi_b[1] = ts_p2l(inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]);; - } - else { + xi_b[1] = ts_p2l( + inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + ; + } else { // sii integral. - xi_b[0] = ts_p2l(inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]);; + xi_b[0] = ts_p2l( + inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + ; xi_b[1] = 1.0; } @@ -758,10 +807,10 @@ ts_subcellint_si_sii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p .pick_upper = is_upper_shift_dir_cell, .shear_dir = up->shear_dir_in_ts_grid, .shift_dir = up->shift_dir_in_ts_grid, - .shift_dir_bounds = {up->ts_grid.lower[up->shift_dir_in_ts_grid], - up->ts_grid.upper[up->shift_dir_in_ts_grid]}, + .shift_dir_bounds = + {up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid]}, .shift_func = up->shift_func, - .shift_func_ctx = up->shift_func_ctx, + .shift_func_ctx = up->shift_func_ctx }; double etalo_xi[up->shift_b.num_basis], etaup_xi[up->shift_b.num_basis]; @@ -770,15 +819,19 @@ ts_subcellint_si_sii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p // Offset between cell centers in direction of the shift. double xs_off = ts_donor_target_offset(up, xc_do, xc_tar); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } } -void -ts_subcellint_siii_siv(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, - const double *xc_do, const double *xc_tar, const double *cellb_do, const double *cellb_tar, - bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do) +void ts_subcellint_siii_siv( + struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, const double *xc_do, + const double *xc_tar, const double *cellb_do, const double *cellb_tar, + bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do +) { // Perform subcell integral siii or siv, using fixed x-limits and variable y limits. // inter_pts: intersections y_{j_tar-/+1/2}-yShift and y_{j_do-/+1/2} (lower/upper y-boundaries of donor cell). @@ -789,7 +842,7 @@ ts_subcellint_siii_siv(struct gkyl_bc_twistshift *up, struct ts_val_found *inter // is_upper_shift_dir_cell: is the donor the upper cell in the shift dir? // shift_c: DG coefficients of the shift. // mat_do: current donor matrix. - + double x_lo = cellb_tar[cellb_lo(up->shear_dir_in_ts_grid)]; double x_up = cellb_tar[cellb_up(up->shear_dir_in_ts_grid)]; double shift_lo, shift_up; @@ -799,15 +852,20 @@ ts_subcellint_siii_siv(struct gkyl_bc_twistshift *up, struct ts_val_found *inter bool is_siii = -shift_lo > -shift_up; - double xi_b[2]; // Limits of xi integral. + double xi_b[2]; // Limits of xi integral. if (is_siii) { // siii integral. xi_b[0] = -1.0; - xi_b[1] = ts_p2l(inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]);; - } - else { + xi_b[1] = ts_p2l( + inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + ; + } else { // siv integral. - xi_b[0] = ts_p2l(inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]);; + xi_b[0] = ts_p2l( + inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + ; xi_b[1] = 1.0; } @@ -824,10 +882,10 @@ ts_subcellint_siii_siv(struct gkyl_bc_twistshift *up, struct ts_val_found *inter .pick_upper = is_upper_shift_dir_cell, .shear_dir = up->shear_dir_in_ts_grid, .shift_dir = up->shift_dir_in_ts_grid, - .shift_dir_bounds = {up->ts_grid.lower[up->shift_dir_in_ts_grid], - up->ts_grid.upper[up->shift_dir_in_ts_grid]}, + .shift_dir_bounds = + {up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid]}, .shift_func = up->shift_func, - .shift_func_ctx = up->shift_func_ctx, + .shift_func_ctx = up->shift_func_ctx }; double etalo_xi[up->shift_b.num_basis], etaup_xi[up->shift_b.num_basis]; @@ -836,15 +894,19 @@ ts_subcellint_siii_siv(struct gkyl_bc_twistshift *up, struct ts_val_found *inter // Offset between cell centers in direction of the shift. double xs_off = ts_donor_target_offset(up, xc_do, xc_tar); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } } -void -ts_subcellint_sv_svi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, - const double *xc_do, const double *xc_tar, const double *cellb_do, const double *cellb_tar, - bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do) +void ts_subcellint_sv_svi( + struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, const double *xc_do, + const double *xc_tar, const double *cellb_do, const double *cellb_tar, + bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do +) { // Perform sv or svi subcell integrals. // inter_pts: intersections y_{j_tar-/+1/2}-yShift and y_{j_do-/+1/2} (lower/upper y-boundaries of donor cell). @@ -866,10 +928,10 @@ ts_subcellint_sv_svi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p .pick_upper = is_upper_shift_dir_cell, .shear_dir = up->shear_dir_in_ts_grid, .shift_dir = up->shift_dir_in_ts_grid, - .shift_dir_bounds = {up->ts_grid.lower[up->shift_dir_in_ts_grid], - up->ts_grid.upper[up->shift_dir_in_ts_grid]}, + .shift_dir_bounds = + {up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid]}, .shift_func = up->shift_func, - .shift_func_ctx = up->shift_func_ctx, + .shift_func_ctx = up->shift_func_ctx }; double xi_b[2]; // Limits of xi integral. @@ -883,7 +945,9 @@ ts_subcellint_sv_svi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p // sv // 1) Add the contribution of the left portion. xi_b[0] = -1.0; - xi_b[1] = ts_p2l(inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[1] = ts_p2l( + inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_up(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_minus_one; @@ -892,13 +956,20 @@ ts_subcellint_sv_svi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } // 2) Add the contribution of the right portion. - xi_b[0] = ts_p2l(inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_lo(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_shift_coord_shifted_log; @@ -907,15 +978,21 @@ ts_subcellint_sv_svi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); - } - else { + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } + } else { // svi // 1) Add the contribution of the left portion. - xi_b[0] = ts_p2l(inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_lo(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_shift_coord_shifted_log; @@ -924,12 +1001,17 @@ ts_subcellint_sv_svi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } // 2) Add the contribution of the right portion. - xi_b[0] = ts_p2l(inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); xi_b[1] = 1.0; eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_up(up->shift_dir_in_ts_grid)]; @@ -939,16 +1021,20 @@ ts_subcellint_sv_svi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } } } -void -ts_subcellint_svii_sviii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, - const double *xc_do, const double *xc_tar, const double *cellb_do, const double *cellb_tar, - bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do) +void ts_subcellint_svii_sviii( + struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, const double *xc_do, + const double *xc_tar, const double *cellb_do, const double *cellb_tar, + bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do +) { // Perform svii or sviii subcell integrals. // inter_pts: intersections y_{j_tar-/+1/2}-yShift and y_{j_do-/+1/2} (lower/upper y-boundaries of donor cell). @@ -970,10 +1056,10 @@ ts_subcellint_svii_sviii(struct gkyl_bc_twistshift *up, struct ts_val_found *int .pick_upper = is_upper_shift_dir_cell, .shear_dir = up->shear_dir_in_ts_grid, .shift_dir = up->shift_dir_in_ts_grid, - .shift_dir_bounds = {up->ts_grid.lower[up->shift_dir_in_ts_grid], - up->ts_grid.upper[up->shift_dir_in_ts_grid]}, + .shift_dir_bounds = + {up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid]}, .shift_func = up->shift_func, - .shift_func_ctx = up->shift_func_ctx, + .shift_func_ctx = up->shift_func_ctx }; double xi_b[2]; // Limits of xi integral. @@ -987,7 +1073,9 @@ ts_subcellint_svii_sviii(struct gkyl_bc_twistshift *up, struct ts_val_found *int // svii // 1) Add the contribution of the left portion. xi_b[0] = -1.0; - xi_b[1] = ts_p2l(inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[1] = ts_p2l( + inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_lo(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_shift_coord_shifted_log; @@ -996,13 +1084,20 @@ ts_subcellint_svii_sviii(struct gkyl_bc_twistshift *up, struct ts_val_found *int ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } // 2) Add the contribution of the right portion. - xi_b[0] = ts_p2l(inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_up(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_minus_one; @@ -1011,15 +1106,21 @@ ts_subcellint_svii_sviii(struct gkyl_bc_twistshift *up, struct ts_val_found *int ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); - } - else { + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } + } else { // sviii // 1) Add the contribution of the left portion. - xi_b[0] = ts_p2l(inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_up(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_minus_one; @@ -1028,12 +1129,17 @@ ts_subcellint_svii_sviii(struct gkyl_bc_twistshift *up, struct ts_val_found *int ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } // 2) Add the contribution of the right portion. - xi_b[0] = ts_p2l(inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); xi_b[1] = 1.0; eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_lo(up->shift_dir_in_ts_grid)]; @@ -1043,16 +1149,20 @@ ts_subcellint_svii_sviii(struct gkyl_bc_twistshift *up, struct ts_val_found *int ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } } } -void -ts_subcellint_six_sx(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, - const double *xc_do, const double *xc_tar, const double *cellb_do, const double *cellb_tar, - bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do) +void ts_subcellint_six_sx( + struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, const double *xc_do, + const double *xc_tar, const double *cellb_do, const double *cellb_tar, + bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do +) { // Perform six or sx subcell integrals. // inter_pts: intersections y_{j_tar-/+1/2}-yShift and y_{j_do-/+1/2} (lower/upper y-boundaries of donor cell). @@ -1070,13 +1180,20 @@ ts_subcellint_six_sx(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p double xi_b[2]; if (is_six) { // six - xi_b[0] = ts_p2l(inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - } - else { + xi_b[0] = ts_p2l( + inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + } else { // sx - xi_b[0] = ts_p2l(inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[1].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); } struct ts_shift_coord_shifted_log_ctx eta_lims_ctx = { @@ -1088,10 +1205,10 @@ ts_subcellint_six_sx(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p .pick_upper = is_upper_shift_dir_cell, .shear_dir = up->shear_dir_in_ts_grid, .shift_dir = up->shift_dir_in_ts_grid, - .shift_dir_bounds = {up->ts_grid.lower[up->shift_dir_in_ts_grid], - up->ts_grid.upper[up->shift_dir_in_ts_grid]}, + .shift_dir_bounds = + {up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid]}, .shift_func = up->shift_func, - .shift_func_ctx = up->shift_func_ctx, + .shift_func_ctx = up->shift_func_ctx }; evalf_t eta_lims[2]; // Table of functions definting the limits of eta integral. @@ -1104,15 +1221,19 @@ ts_subcellint_six_sx(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_p // Offset between cell centers in direction of the shift. double xs_off = ts_donor_target_offset(up, xc_do, xc_tar); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } } -void -ts_subcellint_sxi_sxii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, - const double *xc_do, const double *xc_tar, const double *cellb_do, const double *cellb_tar, - bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do) +void ts_subcellint_sxi_sxii( + struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, const double *xc_do, + const double *xc_tar, const double *cellb_do, const double *cellb_tar, + bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do +) { // Perform sxi or sxii subcell integrals. // inter_pts: intersections y_{j_tar-/+1/2}-yShift and y_{j_do-/+1/2} (lower/upper y-boundaries of donor cell). @@ -1130,13 +1251,20 @@ ts_subcellint_sxi_sxii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter double xi_b[2]; if (is_sxi) { // six - xi_b[0] = ts_p2l(inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - } - else { + xi_b[0] = ts_p2l( + inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + } else { // sx - xi_b[0] = ts_p2l(inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); - xi_b[1] = ts_p2l(inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[2].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); + xi_b[1] = ts_p2l( + inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); } struct ts_shift_coord_shifted_log_ctx eta_lims_ctx = { @@ -1148,10 +1276,10 @@ ts_subcellint_sxi_sxii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter .pick_upper = is_upper_shift_dir_cell, .shear_dir = up->shear_dir_in_ts_grid, .shift_dir = up->shift_dir_in_ts_grid, - .shift_dir_bounds = {up->ts_grid.lower[up->shift_dir_in_ts_grid], - up->ts_grid.upper[up->shift_dir_in_ts_grid]}, + .shift_dir_bounds = + {up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid]}, .shift_func = up->shift_func, - .shift_func_ctx = up->shift_func_ctx, + .shift_func_ctx = up->shift_func_ctx }; evalf_t eta_lims[2]; // Table of functions definting the limits of eta integral. @@ -1164,15 +1292,19 @@ ts_subcellint_sxi_sxii(struct gkyl_bc_twistshift *up, struct ts_val_found *inter // Offset between cell centers in direction of the shift. double xs_off = ts_donor_target_offset(up, xc_do, xc_tar); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } } -void -ts_subcellint_sxiii_sxiv(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, - const double *xc_do, const double *xc_tar, const double *cellb_do, const double *cellb_tar, - bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do) +void ts_subcellint_sxiii_sxiv( + struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, const double *xc_do, + const double *xc_tar, const double *cellb_do, const double *cellb_tar, + bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do +) { // Perform sxiii or sxiv subcell integrals. // inter_pts: intersections y_{j_tar-/+1/2}-yShift and y_{j_do-/+1/2} (lower/upper y-boundaries of donor cell). @@ -1201,10 +1333,10 @@ ts_subcellint_sxiii_sxiv(struct gkyl_bc_twistshift *up, struct ts_val_found *int .pick_upper = is_upper_shift_dir_cell, .shear_dir = up->shear_dir_in_ts_grid, .shift_dir = up->shift_dir_in_ts_grid, - .shift_dir_bounds = {up->ts_grid.lower[up->shift_dir_in_ts_grid], - up->ts_grid.upper[up->shift_dir_in_ts_grid]}, + .shift_dir_bounds = + {up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid]}, .shift_func = up->shift_func, - .shift_func_ctx = up->shift_func_ctx, + .shift_func_ctx = up->shift_func_ctx }; double xi_b[2]; // Limits of xi integral. @@ -1216,14 +1348,15 @@ ts_subcellint_sxiii_sxiv(struct gkyl_bc_twistshift *up, struct ts_val_found *int // 1) Add the contribution of the left portion. xi_b[0] = -1.0; - xi_b[1] = ts_p2l(inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[1] = ts_p2l( + inter_pts[3].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); if (is_sxiii) { eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_up(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_minus_one; eta_lims[1] = ts_shift_coord_shifted_log; - } - else { + } else { eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_lo(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_shift_coord_shifted_log; eta_lims[1] = ts_one; @@ -1232,20 +1365,24 @@ ts_subcellint_sxiii_sxiv(struct gkyl_bc_twistshift *up, struct ts_val_found *int ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } // 2) Add the contribution of the right portion. - xi_b[0] = ts_p2l(inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid]); + xi_b[0] = ts_p2l( + inter_pts[0].value, xc_do[up->shear_dir_in_ts_grid], up->ts_grid.dx[up->shear_dir_in_ts_grid] + ); xi_b[1] = 1.0; if (is_sxiii) { eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_lo(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_shift_coord_shifted_log; eta_lims[1] = ts_one; - } - else { + } else { eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_up(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_minus_one; eta_lims[1] = ts_shift_coord_shifted_log; @@ -1254,15 +1391,19 @@ ts_subcellint_sxiii_sxiv(struct gkyl_bc_twistshift *up, struct ts_val_found *int ts_nod2mod_proj_1d(up, eta_lims[0], &eta_lims_ctx, xi_b, etalo_xi); ts_nod2mod_proj_1d(up, eta_lims[1], &eta_lims_ctx, xi_b, etaup_xi); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } } -void -ts_subcellint_sxv_sxvi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, - const double *xc_do, const double *xc_tar, const double *cellb_do, const double *cellb_tar, - bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do) +void ts_subcellint_sxv_sxvi( + struct gkyl_bc_twistshift *up, struct ts_val_found *inter_pts, const double *xc_do, + const double *xc_tar, const double *cellb_do, const double *cellb_tar, + bool is_upper_shift_dir_cell, const double *shift_c, struct gkyl_mat *mat_do +) { // Perform subcell integral sxv or sxvi, using fixed x-limits and variable y limits. // inter_pts: intersections y_{j_tar-/+1/2}-yShift and y_{j_do-/+1/2} (lower/upper y-boundaries of donor cell). @@ -1274,10 +1415,11 @@ ts_subcellint_sxv_sxvi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter // shift_c: DG coefficients of the shift. // mat_do: current donor matrix. - double xi_b[] = {-1.0, 1.0}; // Limits of xi integral. + double xi_b[] = {-1.0, 1.0}; // Limits of xi integral. - double shift_dir_bounds[] = {up->ts_grid.lower[up->shift_dir_in_ts_grid], - up->ts_grid.upper[up->shift_dir_in_ts_grid]}; + double shift_dir_bounds[] = { + up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid] + }; double x_eval = xc_do[up->shear_dir_in_ts_grid]; double shift; @@ -1285,8 +1427,9 @@ ts_subcellint_sxv_sxvi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter up->shift_func(0.0, (double[]){x_eval}, &shift, up->shift_func_ctx); double shifted_coord = cellb_tar[cellb_lo(up->shift_dir_in_ts_grid)] - shift; - shifted_coord = ts_wrap_to_range(shifted_coord, shift_dir_bounds[0], shift_dir_bounds[1], - is_upper_shift_dir_cell); + shifted_coord = ts_wrap_to_range( + shifted_coord, shift_dir_bounds[0], shift_dir_bounds[1], is_upper_shift_dir_cell + ); struct ts_shift_coord_shifted_log_ctx eta_lims_ctx = { .shift_sign_fac = 1, @@ -1296,21 +1439,20 @@ ts_subcellint_sxv_sxvi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter .pick_upper = is_upper_shift_dir_cell, .shear_dir = up->shear_dir_in_ts_grid, .shift_dir = up->shift_dir_in_ts_grid, - .shift_dir_bounds = {up->ts_grid.lower[up->shift_dir_in_ts_grid], - up->ts_grid.upper[up->shift_dir_in_ts_grid]}, + .shift_dir_bounds = + {up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid]}, .shift_func = up->shift_func, - .shift_func_ctx = up->shift_func_ctx, + .shift_func_ctx = up->shift_func_ctx }; evalf_t eta_lims[2]; // Table of functions definting the limits of eta integral. - if ( cellb_do[cellb_lo(up->shift_dir_in_ts_grid)] <= shifted_coord && - shifted_coord <= cellb_do[cellb_up(up->shift_dir_in_ts_grid)] ) { + if (cellb_do[cellb_lo(up->shift_dir_in_ts_grid)] <= shifted_coord && + shifted_coord <= cellb_do[cellb_up(up->shift_dir_in_ts_grid)]) { // sxv integral. eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_lo(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_shift_coord_shifted_log; eta_lims[1] = ts_one; - } - else { + } else { // sxvi integral. eta_lims_ctx.shift_coord_tar = cellb_tar[cellb_up(up->shift_dir_in_ts_grid)]; eta_lims[0] = ts_minus_one; @@ -1323,34 +1465,39 @@ ts_subcellint_sxv_sxvi(struct gkyl_bc_twistshift *up, struct ts_val_found *inter // Offset between cell centers in direction of the shift. double xs_off = ts_donor_target_offset(up, xc_do, xc_tar); - if (fabs(xi_b[1] - xi_b[0]) > tol_xi) - up->kernels->ylimdg(1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, - up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, shift_c, mat_do); + if (fabs(xi_b[1] - xi_b[0]) > tol_xi) { + up->kernels->ylimdg( + 1.0, xi_b[0], xi_b[1], etalo_xi, etaup_xi, up->ts_grid.dx[up->shift_dir_in_ts_grid], xs_off, + shift_c, mat_do + ); + } } -struct gkyl_nmat * -ts_calc_mats(struct gkyl_bc_twistshift *up) +struct gkyl_nmat *ts_calc_mats(struct gkyl_bc_twistshift *up) { - // Allocate matrices containing the discrete subcell integrals. int num_do_tot = 0; - for (int i=0; ishear_r.volume; i++) + for (int i = 0; i < up->shear_r.volume; i++) { num_do_tot += up->num_do[i]; + } struct gkyl_nmat *matsdo = gkyl_nmat_new(num_do_tot, up->basis.num_basis, up->basis.num_basis); - for (int n=0; nnum; ++n) { + for (int n = 0; n < matsdo->num; ++n) { struct gkyl_mat mat = gkyl_nmat_get(matsdo, n); - for (int j=0; jnc; ++j) - for (int i=0; inr; ++i) + for (int j = 0; j < matsdo->nc; ++j) { + for (int i = 0; i < matsdo->nr; ++i) { gkyl_mat_set(&mat, i, j, 0.0); + } + } } // y-index of the reference target used to precalc matrices. For positive(negative) // yShift idx=1(last) might be better, but ideally it shouldn't matter. int shift_dir_idx_tar = 1; - double shift_dir_lims[] = {up->ts_grid.lower[up->shift_dir_in_ts_grid], - up->ts_grid.upper[up->shift_dir_in_ts_grid]}; + double shift_dir_lims[] = { + up->ts_grid.lower[up->shift_dir_in_ts_grid], up->ts_grid.upper[up->shift_dir_in_ts_grid] + }; // Create an eval_on_nodes updater to use its nodes and functions (but not // the whole advance method). @@ -1361,7 +1508,6 @@ ts_calc_mats(struct gkyl_bc_twistshift *up) struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &up->shear_r); while (gkyl_range_iter_next(&iter)) { - // Get the cell boundaries and cell center. int idx_tar[2]; // Target index. idx_tar[up->shift_dir_in_ts_grid] = shift_dir_idx_tar; @@ -1372,15 +1518,18 @@ ts_calc_mats(struct gkyl_bc_twistshift *up) gkyl_rect_grid_cell_center(&up->ts_grid, idx_tar, xc_tar); long shift_loc = gkyl_range_idx(&up->shear_r, iter.idx); - double *shift_c = (double *) gkyl_array_fetch(up->shift_dg, shift_loc); + double *shift_c = (double *)gkyl_array_fetch(up->shift_dg, shift_loc); - long linidx_do = ts_shift_dir_idx_do_linidx(up->num_do, iter.idx[0], shift_dir_idx_tar, - up->ts_grid.cells[up->shift_dir_in_ts_grid], up->shear_r.lower[0]); + long linidx_do = ts_shift_dir_idx_do_linidx( + up->num_do, iter.idx[0], shift_dir_idx_tar, up->ts_grid.cells[up->shift_dir_in_ts_grid], + up->shear_r.lower[0] + ); int *shift_dir_idx_do_ptr = &up->shift_dir_idx_do[linidx_do]; long linidx_mats_do = 0; - for (int i=0; ishear_r.lower[0]; i++) + for (int i = 0; i < iter.idx[0] - up->shear_r.lower[0]; i++) { linidx_mats_do += up->num_do[i]; + } // Check that the shift variation within this x-cell < Ly. // The algorithm assumes at most one x-intersection per (y-boundary, y-boundary) pair, @@ -1394,13 +1543,16 @@ ts_calc_mats(struct gkyl_bc_twistshift *up) up->shift_func(0.0, (double[]){xc_tar[up->shear_dir_in_ts_grid]}, &S_c, up->shift_func_ctx); if (fabs(S_up - S_lo) >= Ly) { - fprintf(stderr, "bc_twistshift: shift variation |S(x_up)-S(x_lo)| = %g across a single x-cell" + fprintf( + stderr, + "bc_twistshift: shift variation |S(x_up)-S(x_lo)| = %g across a single x-cell" " exceeds Ly = %g (cell ix=%d). Increase Nx, reduce the shear, or increase Ly.\n", - fabs(S_up - S_lo), Ly, iter.idx[0]); + fabs(S_up - S_lo), Ly, iter.idx[0] + ); assert(false); } - for (int iC=0; iCnum_do[iter.idx[0]-up->shear_r.lower[0]]; iC++){ + for (int iC = 0; iC < up->num_do[iter.idx[0] - up->shear_r.lower[0]]; iC++) { int idx_do[2]; // Target index. idx_do[up->shift_dir_in_ts_grid] = shift_dir_idx_do_ptr[iC]; idx_do[up->shear_dir_in_ts_grid] = iter.idx[0]; @@ -1411,139 +1563,163 @@ ts_calc_mats(struct gkyl_bc_twistshift *up) gkyl_rect_grid_cell_center(&up->ts_grid, idx_do, xc_do); // Get the matrix we are presently assigning. - struct gkyl_mat mat_do = gkyl_nmat_get(matsdo, linidx_mats_do+iC); + struct gkyl_mat mat_do = gkyl_nmat_get(matsdo, linidx_mats_do + iC); // Periodic copy in which to find the target for this donor-target pair: the integer nP such that // S_c \approx y_tar_c - y_do_c + nP*Ly. All 4 inter_pts must use this same nP so that only // roots from the physical intersection are accepted (not roots from other periodic copies). - int nP_primary = (int)round((S_c - (xc_tar[up->shift_dir_in_ts_grid] - xc_do[up->shift_dir_in_ts_grid])) / Ly); + int nP_primary = (int + )round((S_c - (xc_tar[up->shift_dir_in_ts_grid] - xc_do[up->shift_dir_in_ts_grid])) / Ly); // Find the points where y_{j_tar-/+1/2}-yShift intersect the y=y_{j_do-/+1/2} lines. // Also record the number and indices of points found/not found. struct ts_val_found inter_pts[4] = {}; int num_inter_pts_found = 0, num_inter_pts_not_found = 4; int inter_pts_found_idxs[4], inter_pts_not_found_idxs[4]; - for (int i=0; i<2; i++) { // Loop over j_tar-/+1/2 - for (int j=0; j<2; j++) { // Loop over j_do-/+1/2 - double shift_dir_coord_tar = cellb_tar[2*up->shift_dir_in_ts_grid+i]; - double shift_dir_coord_do = cellb_do[2*up->shift_dir_in_ts_grid+j]; - struct gkyl_qr_res inter_res = ts_find_intersect(up, shift_dir_coord_tar, shift_dir_coord_do, - (double[]) {cellb_tar[cellb_lo(up->shear_dir_in_ts_grid)],cellb_tar[cellb_up(up->shear_dir_in_ts_grid)]}, - shift_dir_lims, nP_primary); - int ip_linc = i*2+j; + for (int i = 0; i < 2; i++) { // Loop over j_tar-/+1/2 + for (int j = 0; j < 2; j++) { // Loop over j_do-/+1/2 + double shift_dir_coord_tar = cellb_tar[2 * up->shift_dir_in_ts_grid + i]; + double shift_dir_coord_do = cellb_do[2 * up->shift_dir_in_ts_grid + j]; + struct gkyl_qr_res inter_res = ts_find_intersect( + up, shift_dir_coord_tar, shift_dir_coord_do, + (double[] + ){cellb_tar[cellb_lo(up->shear_dir_in_ts_grid)], + cellb_tar[cellb_up(up->shear_dir_in_ts_grid)]}, + shift_dir_lims, nP_primary + ); + int ip_linc = i * 2 + j; inter_pts[ip_linc].status = inter_res.status == 0; if (inter_res.status == 0) { inter_pts[ip_linc].value = inter_res.res; inter_pts_found_idxs[num_inter_pts_found] = ip_linc; num_inter_pts_found++; - } - else { + } else { inter_pts_not_found_idxs[num_inter_pts_not_found] = ip_linc; num_inter_pts_not_found--; } } } - bool is_upper_shift_dir_cell = idx_do[up->shift_dir_in_ts_grid] == up->ts_grid.cells[up->shift_dir_in_ts_grid]; + bool is_upper_shift_dir_cell = idx_do[up->shift_dir_in_ts_grid] == + up->ts_grid.cells[up->shift_dir_in_ts_grid]; if (num_inter_pts_found == 4) { // sN: all intersections are found at this cell. - ts_subcellint_sNi_sNii(up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, &mat_do); - } - else if (num_inter_pts_found == 1) { + ts_subcellint_sNi_sNii( + up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, + &mat_do + ); + } else if (num_inter_pts_found == 1) { if (inter_pts[1].status) { // si: y_{j_tar-1/2}-yShift intersects x_{i-1/2}. // sii: y_{j_tar-1/2}-yShift intersects x_{i+1/2}. - ts_subcellint_si_sii(up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, &mat_do); - } - else { + ts_subcellint_si_sii( + up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, + &mat_do + ); + } else { // siii: y_{j_tar+1/2}-yShift intersects x_{i-1/2}. // siv: y_{j_tar+1/2}-yShift intersects x_{i+1/2}. - ts_subcellint_siii_siv(up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, &mat_do); + ts_subcellint_siii_siv( + up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, + &mat_do + ); } - } - else if (num_inter_pts_found == 3) { + } else if (num_inter_pts_found == 3) { if (!inter_pts[2].status) { // sv: y_{j_tar+1/2}-yShift doesn't intersect y_{j_do-1/2} & intersects x_{i-1/2}. // svi: y_{j_tar+1/2}-yShift doesn't intersect y_{j_do-1/2} & intersects x_{i+1/2}. - ts_subcellint_sv_svi(up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, &mat_do); - } - else { + ts_subcellint_sv_svi( + up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, + &mat_do + ); + } else { // svii: y_{j_tar-1/2}-yShift doesn't intersect y_{j_do+1/2} & intersects x_{i-1/2}. // sviii: y_{j_tar-1/2}-yShift doesn't intersect y_{j_do+1/2} & intersects x_{i+1/2}. - ts_subcellint_svii_sviii(up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, &mat_do); + ts_subcellint_svii_sviii( + up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, + &mat_do + ); } - } - else if (num_inter_pts_found == 2) { + } else if (num_inter_pts_found == 2) { if (inter_pts[0].status && inter_pts[1].status) { // six: y_{j_tar-1/2}-yShift crosses y_{j_do-/+1/2} (increasing yShift). // sx: y_{j_tar-1/2}-yShift crosses y_{j_do-/+1/2} (decreasing yShift). - ts_subcellint_six_sx(up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, &mat_do); - } - else if (inter_pts[2].status && inter_pts[3].status) { + ts_subcellint_six_sx( + up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, + &mat_do + ); + } else if (inter_pts[2].status && inter_pts[3].status) { // sxi: y_{j_tar+1/2}-yShift crosses y_{j_do-/+1/2} (decreasing yShift). // sxii: y_{j_tar+1/2}-yShift crosses y_{j_do-/+1/2} (increasing yShift). - ts_subcellint_sxi_sxii(up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, &mat_do); - } - else { + ts_subcellint_sxi_sxii( + up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, + &mat_do + ); + } else { // sxiii: y_{j_tar-1/2}-yShift crosses y_{j_do-1/2} & y_{j_tar+1/2}-yShift crosses y_{j_do+1/2} (increasing yShift). // sxiv: y_{j_tar-1/2}-yShift crosses y_{j_do-1/2} & y_{j_tar+1/2}-yShift crosses y_{j_do+1/2} (decreasing yShift). - ts_subcellint_sxiii_sxiv(up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, &mat_do); + ts_subcellint_sxiii_sxiv( + up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, + &mat_do + ); } - } - else if (num_inter_pts_found == 0) { + } else if (num_inter_pts_found == 0) { // sxv: y_{j_tar-1/2}-yShift crosses x_{i-/+1/2}. // sxvi: y_{j_tar+1/2}-yShift crosses x_{i-/+1/2}. - ts_subcellint_sxv_sxvi(up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, &mat_do); - } - else { + ts_subcellint_sxv_sxvi( + up, inter_pts, xc_do, xc_tar, cellb_do, cellb_tar, is_upper_shift_dir_cell, shift_c, + &mat_do + ); + } else { // An error occurred. This shouldn't happen. assert(false); } } - } gkyl_array_release(up->func_nod1d); gkyl_eval_on_nodes_release(up->ev_on_nod1d); - struct gkyl_nmat *matsdo_out = up->use_gpu? gkyl_nmat_cu_dev_new(matsdo->num, matsdo->nr, matsdo->nc) - : gkyl_nmat_acquire(matsdo); + struct gkyl_nmat *matsdo_out = up->use_gpu ? + gkyl_nmat_cu_dev_new(matsdo->num, matsdo->nr, matsdo->nc) : + gkyl_nmat_acquire(matsdo); gkyl_nmat_copy(matsdo_out, matsdo); gkyl_nmat_release(matsdo); return matsdo_out; } -long * -ts_calc_num_numcol_fidx_do(struct gkyl_bc_twistshift *up) +long *ts_calc_num_numcol_fidx_do(struct gkyl_bc_twistshift *up) { // Calculate the linear indices into the donor distribution function gkyl_array // for each num-numcol plane (in the num-numcol-num_basis) space. - long *num_numcol_fidx_do_ho = (long*) gkyl_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); + long *num_numcol_fidx_do_ho = (long *)gkyl_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); // Location in the direction of the BC from which to take donor // distributions. We assume that the user filled the ghost cell with the skin // on the other side (i.e. applied periodicity first). - int bc_dir_loc_do = up->edge == GKYL_LOWER_EDGE? up->local_bcdir_ext_r.lower[up->bc_dir] - : up->local_bcdir_ext_r.upper[up->bc_dir]; + int bc_dir_loc_do = up->edge == GKYL_LOWER_EDGE ? up->local_bcdir_ext_r.lower[up->bc_dir] : + up->local_bcdir_ext_r.upper[up->bc_dir]; // Range over directions other than shear and bc dirs. struct gkyl_range shearbc_perp_r; - int remove[GKYL_MAX_DIM] = {0}, loc_in_dir[GKYL_MAX_DIM] = {0};; + int remove[GKYL_MAX_DIM] = {0}, loc_in_dir[GKYL_MAX_DIM] = {0}; + ; remove[up->shear_dir] = remove[up->bc_dir] = 1; loc_in_dir[up->shear_dir] = up->local_bcdir_ext_r.lower[up->shear_dir]; loc_in_dir[up->bc_dir] = bc_dir_loc_do; gkyl_range_deflate(&shearbc_perp_r, &up->local_bcdir_ext_r, remove, loc_in_dir); int shift_dir_in_shearbc_perp_r; - if (up->shift_dir < up->shear_dir && up->shift_dir < up->bc_dir) + if (up->shift_dir < up->shear_dir && up->shift_dir < up->bc_dir) { shift_dir_in_shearbc_perp_r = up->shift_dir; - else if (up->shift_dir > up->shear_dir && up->shift_dir > up->bc_dir) - shift_dir_in_shearbc_perp_r = up->shift_dir-2; - else - shift_dir_in_shearbc_perp_r = up->shift_dir-1; + } else if (up->shift_dir > up->shear_dir && up->shift_dir > up->bc_dir) { + shift_dir_in_shearbc_perp_r = up->shift_dir - 2; + } else { + shift_dir_in_shearbc_perp_r = up->shift_dir - 1; + } int prev_shift_dir_idx = 0; int donor_count = 0; @@ -1554,7 +1730,7 @@ ts_calc_num_numcol_fidx_do(struct gkyl_bc_twistshift *up) gkyl_range_iter_init(&iter, &shearbc_perp_r); while (gkyl_range_iter_next(&iter)) { int ic = 0; - for (int d=0; dlocal_bcdir_ext_r.ndim; d++) { + for (int d = 0; d < up->local_bcdir_ext_r.ndim; d++) { if (d != up->bc_dir && d != up->shear_dir) { do_idx[d] = iter.idx[ic]; ic++; @@ -1565,15 +1741,16 @@ ts_calc_num_numcol_fidx_do(struct gkyl_bc_twistshift *up) struct gkyl_range_iter shear_dir_iter; gkyl_range_iter_init(&shear_dir_iter, &up->shear_r); while (gkyl_range_iter_next(&shear_dir_iter)) { - int shear_dir_idx = shear_dir_iter.idx[0]; - long linidx_do = ts_shift_dir_idx_do_linidx(up->num_do, shear_dir_idx, - iter.idx[shift_dir_in_shearbc_perp_r], up->ts_grid.cells[up->shift_dir_in_ts_grid], up->shear_r.lower[0]); + long linidx_do = ts_shift_dir_idx_do_linidx( + up->num_do, shear_dir_idx, iter.idx[shift_dir_in_shearbc_perp_r], + up->ts_grid.cells[up->shift_dir_in_ts_grid], up->shear_r.lower[0] + ); - for (int i = 0; i < up->num_do[shear_dir_idx-up->shear_r.lower[0]]; i++) { + for (int i = 0; i < up->num_do[shear_dir_idx - up->shear_r.lower[0]]; i++) { do_idx[up->shear_dir] = shear_dir_idx; - do_idx[up->shift_dir] = up->shift_dir_idx_do[linidx_do+i]; + do_idx[up->shift_dir] = up->shift_dir_idx_do[linidx_do + i]; long loc = gkyl_range_idx(&up->local_bcdir_ext_r, do_idx); num_numcol_fidx_do_ho[donor_count] = loc; @@ -1586,13 +1763,16 @@ ts_calc_num_numcol_fidx_do(struct gkyl_bc_twistshift *up) long *num_numcol_fidx_do; if (!up->use_gpu) { - num_numcol_fidx_do = (long*) gkyl_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); + num_numcol_fidx_do = (long *)gkyl_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); memcpy(num_numcol_fidx_do, num_numcol_fidx_do_ho, up->fmat->num * up->fmat->nc * sizeof(long)); } #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - num_numcol_fidx_do = (long*) gkyl_cu_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); - gkyl_cu_memcpy(num_numcol_fidx_do, num_numcol_fidx_do_ho, up->fmat->num * up->fmat->nc * sizeof(long), GKYL_CU_MEMCPY_H2D); + num_numcol_fidx_do = (long *)gkyl_cu_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); + gkyl_cu_memcpy( + num_numcol_fidx_do, num_numcol_fidx_do_ho, up->fmat->num * up->fmat->nc * sizeof(long), + GKYL_CU_MEMCPY_H2D + ); } #endif @@ -1601,21 +1781,20 @@ ts_calc_num_numcol_fidx_do(struct gkyl_bc_twistshift *up) return num_numcol_fidx_do; } -long * -ts_calc_num_numcol_fidx_tar(struct gkyl_bc_twistshift *up) +long *ts_calc_num_numcol_fidx_tar(struct gkyl_bc_twistshift *up) { - - long *num_numcol_fidx_tar_ho = (long*) gkyl_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); + long *num_numcol_fidx_tar_ho = (long *)gkyl_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); // Location in the direction of the BC in which to place the target // distributions. We assume that the local_bcdir_ext_r is a range extended in z (it // includes the z ghose cell). - int bc_dir_loc_tar = up->edge == GKYL_LOWER_EDGE? up->local_bcdir_ext_r.lower[up->bc_dir] - : up->local_bcdir_ext_r.upper[up->bc_dir]; + int bc_dir_loc_tar = up->edge == GKYL_LOWER_EDGE ? up->local_bcdir_ext_r.lower[up->bc_dir] : + up->local_bcdir_ext_r.upper[up->bc_dir]; // Range over directions other than shear and bc dirs. struct gkyl_range shearbc_perp_r; - int remove[GKYL_MAX_DIM] = {0}, loc_in_dir[GKYL_MAX_DIM] = {0};; + int remove[GKYL_MAX_DIM] = {0}, loc_in_dir[GKYL_MAX_DIM] = {0}; + ; remove[up->shear_dir] = remove[up->bc_dir] = 1; loc_in_dir[up->shear_dir] = up->local_bcdir_ext_r.lower[up->shear_dir]; loc_in_dir[up->bc_dir] = bc_dir_loc_tar; @@ -1628,9 +1807,8 @@ ts_calc_num_numcol_fidx_tar(struct gkyl_bc_twistshift *up) struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &shearbc_perp_r); while (gkyl_range_iter_next(&iter)) { - int ic = 0; - for (int d=0; dlocal_bcdir_ext_r.ndim; d++) { + for (int d = 0; d < up->local_bcdir_ext_r.ndim; d++) { if (d != up->bc_dir && d != up->shear_dir) { tar_idx[d] = iter.idx[ic]; ic++; @@ -1638,7 +1816,6 @@ ts_calc_num_numcol_fidx_tar(struct gkyl_bc_twistshift *up) } tar_idx[up->bc_dir] = bc_dir_loc_tar; - struct gkyl_range_iter shear_dir_iter; gkyl_range_iter_init(&shear_dir_iter, &up->shear_r); while (gkyl_range_iter_next(&shear_dir_iter)) { @@ -1653,13 +1830,16 @@ ts_calc_num_numcol_fidx_tar(struct gkyl_bc_twistshift *up) long *num_numcol_fidx_tar; if (!up->use_gpu) { - num_numcol_fidx_tar = (long*) gkyl_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); + num_numcol_fidx_tar = (long *)gkyl_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); memcpy(num_numcol_fidx_tar, num_numcol_fidx_tar_ho, up->fmat->num * up->fmat->nc * sizeof(long)); } #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - num_numcol_fidx_tar = (long*) gkyl_cu_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); - gkyl_cu_memcpy(num_numcol_fidx_tar, num_numcol_fidx_tar_ho, up->fmat->num * up->fmat->nc * sizeof(long), GKYL_CU_MEMCPY_H2D); + num_numcol_fidx_tar = (long *)gkyl_cu_malloc(up->fmat->num * up->fmat->nc * sizeof(long)); + gkyl_cu_memcpy( + num_numcol_fidx_tar, num_numcol_fidx_tar_ho, up->fmat->num * up->fmat->nc * sizeof(long), + GKYL_CU_MEMCPY_H2D + ); } #endif @@ -1668,45 +1848,44 @@ ts_calc_num_numcol_fidx_tar(struct gkyl_bc_twistshift *up) return num_numcol_fidx_tar; } -void -gkyl_bc_twistshift_choose_kernels(struct gkyl_basis basis, int cdim, int shift_poly_order, - struct gkyl_bc_twistshift_kernels *kers) +void gkyl_bc_twistshift_choose_kernels( + struct gkyl_basis basis, int cdim, int shift_poly_order, struct gkyl_bc_twistshift_kernels *kers +) { int dim = basis.ndim; int vdim = dim - cdim; enum gkyl_basis_type basis_type = basis.b_type; int poly_order = basis.poly_order; switch (basis_type) { - case GKYL_BASIS_MODAL_GKHYBRID: - case GKYL_BASIS_MODAL_SERENDIPITY: - if (shift_poly_order == 1) { - kers->xlimdg = vdim==0? ser_twistshift_xlimdg_list_0v_yShp1[cdim-2].kernels[poly_order] - : ser_twistshift_xlimdg_list_2v_yShp1[cdim-2].kernels[poly_order]; - kers->ylimdg = vdim==0? ser_twistshift_ylimdg_list_0v_yShp1[cdim-2].kernels[poly_order] - : ser_twistshift_ylimdg_list_2v_yShp1[cdim-2].kernels[poly_order]; - kers->fullcell = vdim==0? ser_twistshift_fullcell_list_0v_yShp1[cdim-2].kernels[poly_order] - : ser_twistshift_fullcell_list_2v_yShp1[cdim-2].kernels[poly_order]; - } - else if (shift_poly_order == 2) { - assert(false); // MF 2025/09/20: removed 3x2v kernel because it's 8.5 MB. - kers->xlimdg = vdim==0? ser_twistshift_xlimdg_list_0v_yShp2[cdim-2].kernels[poly_order] - : ser_twistshift_xlimdg_list_2v_yShp2[cdim-2].kernels[poly_order]; - kers->ylimdg = vdim==0? ser_twistshift_ylimdg_list_0v_yShp2[cdim-2].kernels[poly_order] - : ser_twistshift_ylimdg_list_2v_yShp2[cdim-2].kernels[poly_order]; - kers->fullcell = vdim==0? ser_twistshift_fullcell_list_0v_yShp2[cdim-2].kernels[poly_order] - : ser_twistshift_fullcell_list_2v_yShp2[cdim-2].kernels[poly_order]; - } - return; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_GKHYBRID: + case GKYL_BASIS_MODAL_SERENDIPITY: + if (shift_poly_order == 1) { + kers->xlimdg = vdim == 0 ? ser_twistshift_xlimdg_list_0v_yShp1[cdim - 2].kernels[poly_order] : + ser_twistshift_xlimdg_list_2v_yShp1[cdim - 2].kernels[poly_order]; + kers->ylimdg = vdim == 0 ? ser_twistshift_ylimdg_list_0v_yShp1[cdim - 2].kernels[poly_order] : + ser_twistshift_ylimdg_list_2v_yShp1[cdim - 2].kernels[poly_order]; + kers->fullcell = vdim == 0 ? + ser_twistshift_fullcell_list_0v_yShp1[cdim - 2].kernels[poly_order] : + ser_twistshift_fullcell_list_2v_yShp1[cdim - 2].kernels[poly_order]; + } else if (shift_poly_order == 2) { + assert(false); // MF 2025/09/20: removed 3x2v kernel because it's 8.5 MB. + kers->xlimdg = vdim == 0 ? ser_twistshift_xlimdg_list_0v_yShp2[cdim - 2].kernels[poly_order] : + ser_twistshift_xlimdg_list_2v_yShp2[cdim - 2].kernels[poly_order]; + kers->ylimdg = vdim == 0 ? ser_twistshift_ylimdg_list_0v_yShp2[cdim - 2].kernels[poly_order] : + ser_twistshift_ylimdg_list_2v_yShp2[cdim - 2].kernels[poly_order]; + kers->fullcell = vdim == 0 ? + ser_twistshift_fullcell_list_0v_yShp2[cdim - 2].kernels[poly_order] : + ser_twistshift_fullcell_list_2v_yShp2[cdim - 2].kernels[poly_order]; + } + return; + default: + assert(false); + break; } } -struct gkyl_bc_twistshift* -gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp) +struct gkyl_bc_twistshift *gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp) { - // Allocate space for new updater. struct gkyl_bc_twistshift *up = gkyl_malloc(sizeof(struct gkyl_bc_twistshift)); @@ -1722,19 +1901,23 @@ gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp) // Assume the poly order of the DG shift is the same as that of the field, // unless requested otherwise. up->shift_poly_order = inp->basis->poly_order; - if (inp->shift_poly_order) + if (inp->shift_poly_order) { up->shift_poly_order = inp->shift_poly_order; + } const int ndim = inp->bcdir_ext_update_r->ndim; // Check that it is being used for 3D or 5D. Likely only small changes are // needed to make it work in other dimensions. - assert(ndim == 3 || ndim == 5); + assert(ndim == 3 || ndim == 5); - double lo1d[1], up1d[1]; int cells1d[1]; + double lo1d[1], up1d[1]; + int cells1d[1]; // Create 1D grid and range in the direction of the shear. - gkyl_range_init(&up->shear_r, 1, (int[]) {up->local_bcdir_ext_r.lower[inp->shear_dir]}, - (int[]) {up->local_bcdir_ext_r.upper[inp->shear_dir]}); + gkyl_range_init( + &up->shear_r, 1, (int[]){up->local_bcdir_ext_r.lower[inp->shear_dir]}, + (int[]){up->local_bcdir_ext_r.upper[inp->shear_dir]} + ); lo1d[0] = inp->grid->lower[up->shear_dir]; up1d[0] = inp->grid->upper[up->shear_dir]; cells1d[0] = inp->grid->cells[up->shear_dir]; @@ -1743,8 +1926,10 @@ gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp) long linidx = gkyl_range_idx(&up->shear_r, idx); // Create 1D grid and range in the diretion of the shift. - gkyl_range_init(&up->shift_r, 1, (int[]) {up->local_bcdir_ext_r.lower[inp->shift_dir]}, - (int[]) {up->local_bcdir_ext_r.upper[inp->shift_dir]}); + gkyl_range_init( + &up->shift_r, 1, (int[]){up->local_bcdir_ext_r.lower[inp->shift_dir]}, + (int[]){up->local_bcdir_ext_r.upper[inp->shift_dir]} + ); lo1d[0] = inp->grid->lower[up->shift_dir]; up1d[0] = inp->grid->upper[up->shift_dir]; cells1d[0] = inp->grid->cells[up->shift_dir]; @@ -1757,15 +1942,16 @@ gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp) dimup = up->shear_dir; up->shift_dir_in_ts_grid = 0; up->shear_dir_in_ts_grid = 1; - } - else { + } else { dimlo = up->shear_dir; dimup = up->shift_dir; up->shift_dir_in_ts_grid = 1; up->shear_dir_in_ts_grid = 0; } - gkyl_range_init(&up->ts_r, 2, (int[]) {up->local_bcdir_ext_r.lower[dimlo], up->local_bcdir_ext_r.lower[dimup]}, - (int[]) {up->local_bcdir_ext_r.upper[dimlo], up->local_bcdir_ext_r.upper[dimup]}); + gkyl_range_init( + &up->ts_r, 2, (int[]){up->local_bcdir_ext_r.lower[dimlo], up->local_bcdir_ext_r.lower[dimup]}, + (int[]){up->local_bcdir_ext_r.upper[dimlo], up->local_bcdir_ext_r.upper[dimup]} + ); double lo2d[] = {inp->grid->lower[dimlo], inp->grid->lower[dimup]}; double up2d[] = {inp->grid->upper[dimlo], inp->grid->upper[dimup]}; int cells2d[] = {inp->grid->cells[dimlo], inp->grid->cells[dimup]}; @@ -1775,12 +1961,12 @@ gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp) gkyl_cart_modal_serendip(&up->shift_b, 1, up->shift_poly_order); if (inp->shift_func) { up->shift_dg = gkyl_array_new(GKYL_DOUBLE, up->shift_b.num_basis, up->shear_r.volume); - gkyl_eval_on_nodes *evup = gkyl_eval_on_nodes_new(&up->shear_grid, &up->shift_b, 1, - inp->shift_func, inp->shift_func_ctx); + gkyl_eval_on_nodes *evup = gkyl_eval_on_nodes_new( + &up->shear_grid, &up->shift_b, 1, inp->shift_func, inp->shift_func_ctx + ); gkyl_eval_on_nodes_advance(evup, 0.0, &up->shear_r, up->shift_dg); gkyl_eval_on_nodes_release(evup); - } - else { + } else { up->shift_dg = gkyl_array_acquire(inp->shift_dg); } @@ -1792,12 +1978,10 @@ gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp) up->shift_dg_eval_ctx.shear_grid = &up->shear_grid; up->shift_dg_eval_ctx.shear_r = &up->shear_r; up->shift_func_ctx = &up->shift_dg_eval_ctx; - } - else if (shift_func_op == 1) { - up->shift_func = inp->shift_func; + } else if (shift_func_op == 1) { + up->shift_func = inp->shift_func; up->shift_func_ctx = inp->shift_func_ctx; - } - else { + } else { fprintf(stderr, "Twist-shift function option not recognized. Exiting...\n"); assert(false); } @@ -1808,12 +1992,14 @@ gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp) ts_find_donors(up); // Array of cummulative number of donors at given shear_dir cell. - const int num_do_cum_sz = up->grid.cells[up->shear_dir]+1; + const int num_do_cum_sz = up->grid.cells[up->shear_dir] + 1; int num_do_cum_ho[num_do_cum_sz]; - for (int i=0; ishear_r.lower[0]; ishear_r.upper[0]+1; i++) - num_do_cum_ho[i] = num_do_cum_ho[i-1] + up->num_do[i-up->shear_r.lower[0]]; + } + for (int i = up->shear_r.lower[0]; i < up->shear_r.upper[0] + 1; i++) { + num_do_cum_ho[i] = num_do_cum_ho[i - 1] + up->num_do[i - up->shear_r.lower[0]]; + } if (!up->use_gpu) { up->num_do_cum = gkyl_malloc(num_do_cum_sz * sizeof(int)); @@ -1848,9 +2034,10 @@ gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp) // Number of colums in fmat. int fmat_num_col = 1; - for (int d=0; dbc_dir && d != up->shear_dir) + for (int d = 0; d < ndim; d++) { + if (d != up->bc_dir && d != up->shear_dir) { fmat_num_col *= up->local_bcdir_ext_r.upper[d] - up->local_bcdir_ext_r.lower[d] + 1; + } } if (!up->use_gpu) { @@ -1874,59 +2061,65 @@ gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp) // Permutted ghost range, for indexing into the target field. // Order: Shift direction, redundant directions, shear direction. - int lo4D[ndim-1], up4D[ndim-1]; + int lo4D[ndim - 1], up4D[ndim - 1]; lo4D[0] = up->local_bcdir_ext_r.lower[up->shift_dir]; up4D[0] = up->local_bcdir_ext_r.upper[up->shift_dir]; int ic = 1; - for (int d=0; dbc_dir && d != up->shear_dir && d != up->shift_dir) { lo4D[ic] = up->local_bcdir_ext_r.lower[d]; up4D[ic] = up->local_bcdir_ext_r.upper[d]; ic++; } } - lo4D[ndim-2] = up->local_bcdir_ext_r.lower[up->shear_dir]; - up4D[ndim-2] = up->local_bcdir_ext_r.upper[up->shear_dir]; - gkyl_range_init(&up->permutted_ghost_r, ndim-1, lo4D, up4D); + lo4D[ndim - 2] = up->local_bcdir_ext_r.lower[up->shear_dir]; + up4D[ndim - 2] = up->local_bcdir_ext_r.upper[up->shear_dir]; + gkyl_range_init(&up->permutted_ghost_r, ndim - 1, lo4D, up4D); // Create a ghost range, to clear it before adding contributions from TS BC. - if (inp->edge == GKYL_LOWER_EDGE) - gkyl_range_shorten_from_above(&up->ghost_r, &up->local_bcdir_ext_r, inp->bc_dir, inp->num_ghost[inp->bc_dir]); - else - gkyl_range_shorten_from_below(&up->ghost_r, &up->local_bcdir_ext_r, inp->bc_dir, inp->num_ghost[inp->bc_dir]); + if (inp->edge == GKYL_LOWER_EDGE) { + gkyl_range_shorten_from_above( + &up->ghost_r, &up->local_bcdir_ext_r, inp->bc_dir, inp->num_ghost[inp->bc_dir] + ); + } else { + gkyl_range_shorten_from_below( + &up->ghost_r, &up->local_bcdir_ext_r, inp->bc_dir, inp->num_ghost[inp->bc_dir] + ); + } return up; } -struct gkyl_bc_twistshift* -gkyl_bc_twistshift_new(int bc_dir, int shift_dir, int shear_dir, - enum gkyl_edge_loc edge, int cdim, const struct gkyl_range *bcdir_ext_update_r, const int *num_ghost, - const struct gkyl_basis *basis, const struct gkyl_rect_grid *grid, evalf_t shift_func, void *shift_func_ctx, - struct gkyl_array *shift_dg, int shift_poly_order, bool use_gpu) +struct gkyl_bc_twistshift *gkyl_bc_twistshift_new( + int bc_dir, int shift_dir, int shear_dir, enum gkyl_edge_loc edge, int cdim, + const struct gkyl_range *bcdir_ext_update_r, const int *num_ghost, const struct gkyl_basis *basis, + const struct gkyl_rect_grid *grid, evalf_t shift_func, void *shift_func_ctx, + struct gkyl_array *shift_dg, int shift_poly_order, bool use_gpu +) { struct gkyl_bc_twistshift_inp inp = { - .bc_dir = bc_dir , - .shift_dir = shift_dir , - .shear_dir = shear_dir , - .edge = edge , - .cdim = cdim , - .bcdir_ext_update_r = bcdir_ext_update_r, - .num_ghost = num_ghost , - .basis = basis , - .grid = grid , - .shift_func = shift_func , - .shift_func_ctx = shift_func_ctx , - .shift_dg = shift_dg , - .use_gpu = use_gpu , - .shift_poly_order = shift_poly_order , + .bc_dir = bc_dir, + .shift_dir = shift_dir, + .shear_dir = shear_dir, + .edge = edge, + .cdim = cdim, + .bcdir_ext_update_r = bcdir_ext_update_r, + .num_ghost = num_ghost, + .basis = basis, + .grid = grid, + .shift_func = shift_func, + .shift_func_ctx = shift_func_ctx, + .shift_dg = shift_dg, + .use_gpu = use_gpu, + .shift_poly_order = shift_poly_order }; return gkyl_bc_twistshift_inew(&inp); } -void -gkyl_bc_twistshift_advance(struct gkyl_bc_twistshift *up, struct gkyl_array *fdo, struct gkyl_array *ftar) +void gkyl_bc_twistshift_advance( + struct gkyl_bc_twistshift *up, struct gkyl_array *fdo, struct gkyl_array *ftar +) { - #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { gkyl_bc_twistshift_advance_cu(up, fdo, ftar); @@ -1940,17 +2133,16 @@ gkyl_bc_twistshift_advance(struct gkyl_bc_twistshift *up, struct gkyl_array *fdo // fmat->num = sum_i^Nx num_do(i) // fmat->nr = num_basis = ncomp // fmat->nc = Ny*Nvpar*Nmu - for (size_t i=0; ifmat->num * up->fmat->nr * up->fmat->nc; i++) { - + for (size_t i = 0; i < up->fmat->num * up->fmat->nr * up->fmat->nc; i++) { long nc_idx = i / up->fmat->nr; // num-num_col index: current num-num_col plane. int row_idx = i % up->fmat->nr; // row index: current DG coeff. // This if-statement may only be needed in GPU kernel, not for CPUs. if ((nc_idx < up->fmat->num * up->fmat->nc) && (row_idx < fdo->ncomp)) { - const double *fdo_c = (const double*) gkyl_array_cfetch(fdo, up->num_numcol_fidx_do[nc_idx]); + const double *fdo_c = (const double *)gkyl_array_cfetch(fdo, up->num_numcol_fidx_do[nc_idx]); struct gkyl_mat mcurr = gkyl_nmat_get(up->fmat, nc_idx % up->fmat->num); - gkyl_mat_set(&mcurr, row_idx, nc_idx/up->fmat->num, fdo_c[row_idx]); + gkyl_mat_set(&mcurr, row_idx, nc_idx / up->fmat->num, fdo_c[row_idx]); } } @@ -1961,33 +2153,34 @@ gkyl_bc_twistshift_advance(struct gkyl_bc_twistshift *up, struct gkyl_array *fdo gkyl_array_clear_range(ftar, 0.0, &up->ghost_r); // Perform reduction over num_do contributions from mat-mat mults (mm_contr). - int num_cells_skin = (up->shear_r.upper[0]-up->shear_r.lower[0]+1) * up->fmat->nc; - for (size_t i=0; incomp * num_cells_skin; i++) { - + int num_cells_skin = (up->shear_r.upper[0] - up->shear_r.lower[0] + 1) * up->fmat->nc; + for (size_t i = 0; i < ftar->ncomp * num_cells_skin; i++) { long linidx_tar = i / ftar->ncomp; int row_idx = i % ftar->ncomp; // This if-statement may only be needed in GPU kernel, not for CPUs. if ((linidx_tar < num_cells_skin) && (row_idx < ftar->ncomp)) { - double *ftar_c = (double*) gkyl_array_fetch(ftar, up->num_numcol_fidx_tar[linidx_tar]); + double *ftar_c = (double *)gkyl_array_fetch(ftar, up->num_numcol_fidx_tar[linidx_tar]); int idx[GKYL_MAX_DIM] = {1}; gkyl_sub_range_inv_idx(&up->permutted_ghost_r, linidx_tar, idx); int ac[GKYL_MAX_DIM] = {1}; - for (int d=2; dgrid.ndim-1; d++) - ac[d-2] = up->grid.cells[d+1]; - ac[up->permutted_ghost_r.ndim-2] = up->mm_contr->num; - + for (int d = 2; d < up->grid.ndim - 1; d++) { + ac[d - 2] = up->grid.cells[d + 1]; + } + ac[up->permutted_ghost_r.ndim - 2] = up->mm_contr->num; + int start = 0; - for (int d=0; dpermutted_ghost_r.ndim-1; d++) - start = (start + (idx[d]-1)) * ac[d]; + for (int d = 0; d < up->permutted_ghost_r.ndim - 1; d++) { + start = (start + (idx[d] - 1)) * ac[d]; + } - int shear_idx = idx[up->permutted_ghost_r.ndim-1]; + int shear_idx = idx[up->permutted_ghost_r.ndim - 1]; - int do_start = up->num_do_cum[shear_idx-1]; - int do_end = up->num_do_cum[shear_idx-1+1]; - for (int j=do_start; jnum_do_cum[shear_idx - 1]; + int do_end = up->num_do_cum[shear_idx - 1 + 1]; + for (int j = do_start; j < do_end; j++) { // Only loop over num_do[i] elements. long linidx_mm_contr = start + j; struct gkyl_mat mat = gkyl_nmat_get(up->mm_contr, linidx_mm_contr % up->mm_contr->num); ftar_c[row_idx] += gkyl_mat_get(&mat, row_idx, linidx_mm_contr / up->mm_contr->num); @@ -1996,18 +2189,19 @@ gkyl_bc_twistshift_advance(struct gkyl_bc_twistshift *up, struct gkyl_array *fdo } } -struct gkyl_array* -gkyl_bc_twistshift_get_shift_objects(struct gkyl_bc_twistshift *up, struct gkyl_rect_grid *shear_grid, - struct gkyl_range *shear_r, struct gkyl_basis *shift_b) +struct gkyl_array *gkyl_bc_twistshift_get_shift_objects( + struct gkyl_bc_twistshift *up, struct gkyl_rect_grid *shear_grid, struct gkyl_range *shear_r, + struct gkyl_basis *shift_b +) { *shear_grid = up->shear_grid; - *shear_r = up->shear_r ; - *shift_b = up->shift_b ; + *shear_r = up->shear_r; + *shift_b = up->shift_b; return gkyl_array_acquire(up->shift_dg); }; -void -gkyl_bc_twistshift_release(struct gkyl_bc_twistshift *up) { +void gkyl_bc_twistshift_release(struct gkyl_bc_twistshift *up) +{ // Release memory associated with this updater. if (!up->use_gpu) { gkyl_free(up->num_do_cum); diff --git a/gyrokinetic/zero/bc_twistshift_cu.cu b/gyrokinetic/zero/bc_twistshift_cu.cu index f4cbbecab7..72b853683d 100644 --- a/gyrokinetic/zero/bc_twistshift_cu.cu +++ b/gyrokinetic/zero/bc_twistshift_cu.cu @@ -16,10 +16,11 @@ extern "C" { #include // start ID for use in various loops -#define START_ID (threadIdx.x + blockIdx.x*blockDim.x) +#define START_ID (threadIdx.x + blockIdx.x * blockDim.x) -__global__ void -gkyl_bc_twistshift_set_distf_mats_cu_ker(const struct gkyl_array *fdo, const long *num_numcol_fidx_do, struct gkyl_nmat *fmat) +__global__ void gkyl_bc_twistshift_set_distf_mats_cu_ker( + const struct gkyl_array *fdo, const long *num_numcol_fidx_do, struct gkyl_nmat *fmat +) { // Assign the distribution matrices. // This assumes that fdo->ncomp = fmat->nr. @@ -32,41 +33,45 @@ gkyl_bc_twistshift_set_distf_mats_cu_ker(const struct gkyl_array *fdo, const lon int row_idx = START_ID % fmat->nr; // row index: current DG coeff. if ((nc_idx < fmat->num * fmat->nc) && (row_idx < fdo->ncomp)) { - const double *fdo_c = (const double*) gkyl_array_cfetch(fdo, num_numcol_fidx_do[nc_idx]); + const double *fdo_c = (const double *)gkyl_array_cfetch(fdo, num_numcol_fidx_do[nc_idx]); struct gkyl_mat mcurr = gkyl_nmat_get(fmat, nc_idx % fmat->num); - gkyl_mat_set(&mcurr, row_idx, nc_idx/fmat->num, fdo_c[row_idx]); + gkyl_mat_set(&mcurr, row_idx, nc_idx / fmat->num, fdo_c[row_idx]); } } -__global__ void -gkyl_bc_twistshift_add_contr_cu_ker(struct gkyl_array *ftar, long *num_numcol_fidx_tar, int num_cells_skin, - struct gkyl_nmat *mm_contr, int *num_do_cum, struct gkyl_range permutted_ghost_r, struct gkyl_rect_grid grid) +__global__ void gkyl_bc_twistshift_add_contr_cu_ker( + struct gkyl_array *ftar, long *num_numcol_fidx_tar, int num_cells_skin, + struct gkyl_nmat *mm_contr, int *num_do_cum, struct gkyl_range permutted_ghost_r, + struct gkyl_rect_grid grid +) { long linidx_tar = START_ID / ftar->ncomp; int row_idx = START_ID % ftar->ncomp; // This if-statement may only be needed in GPU kernel, not for CPUs. if ((linidx_tar < num_cells_skin) && (row_idx < ftar->ncomp)) { - double *ftar_c = (double*) gkyl_array_fetch(ftar, num_numcol_fidx_tar[linidx_tar]); + double *ftar_c = (double *)gkyl_array_fetch(ftar, num_numcol_fidx_tar[linidx_tar]); int idx[GKYL_MAX_DIM] = {1}; gkyl_sub_range_inv_idx(&permutted_ghost_r, linidx_tar, idx); int ac[GKYL_MAX_DIM] = {1}; - for (int d=2; dnum; + for (int d = 2; d < grid.ndim - 1; d++) { + ac[d - 2] = grid.cells[d + 1]; + } + ac[permutted_ghost_r.ndim - 2] = mm_contr->num; int start = 0; - for (int d=0; dnum); ftar_c[row_idx] += gkyl_mat_get(&mat, row_idx, linidx_mm_contr / mm_contr->num); @@ -74,13 +79,17 @@ gkyl_bc_twistshift_add_contr_cu_ker(struct gkyl_array *ftar, long *num_numcol_fi } } -void -gkyl_bc_twistshift_advance_cu(struct gkyl_bc_twistshift *up, struct gkyl_array *fdo, struct gkyl_array *ftar) +void gkyl_bc_twistshift_advance_cu( + struct gkyl_bc_twistshift *up, struct gkyl_array *fdo, struct gkyl_array *ftar +) { // Set the columns of the donor matrix with the donor distributions. - int num_blocks_set = (up->fmat->num * up->fmat->nr * up->fmat->nc+GKYL_DEFAULT_NUM_THREADS-1)/GKYL_DEFAULT_NUM_THREADS; - gkyl_bc_twistshift_set_distf_mats_cu_ker<<>> - (fdo->on_dev, up->num_numcol_fidx_do, up->fmat->on_dev); + int num_blocks_set = + (up->fmat->num * up->fmat->nr * up->fmat->nc + GKYL_DEFAULT_NUM_THREADS - 1) / + GKYL_DEFAULT_NUM_THREADS; + gkyl_bc_twistshift_set_distf_mats_cu_ker<< > >( + fdo->on_dev, up->num_numcol_fidx_do, up->fmat->on_dev + ); // Perform the mat-mat multiplications. gkyl_nmat_mm(1.0, 0.0, GKYL_NO_TRANS, up->scimat, GKYL_NO_TRANS, up->fmat, up->mm_contr); @@ -89,9 +98,11 @@ gkyl_bc_twistshift_advance_cu(struct gkyl_bc_twistshift *up, struct gkyl_array * gkyl_array_clear_range(ftar, 0.0, &up->ghost_r); // Add the contributions of mat-vec multiplications. - int num_cells_skin = (up->shear_r.upper[0]-up->shear_r.lower[0]+1) * up->fmat->nc; - int num_blocks_add = (ftar->ncomp * num_cells_skin+GKYL_DEFAULT_NUM_THREADS-1)/GKYL_DEFAULT_NUM_THREADS; - gkyl_bc_twistshift_add_contr_cu_ker<<>> - (ftar->on_dev, up->num_numcol_fidx_tar, num_cells_skin, up->mm_contr->on_dev, - up->num_do_cum, up->permutted_ghost_r, up->grid); + int num_cells_skin = (up->shear_r.upper[0] - up->shear_r.lower[0] + 1) * up->fmat->nc; + int num_blocks_add = + (ftar->ncomp * num_cells_skin + GKYL_DEFAULT_NUM_THREADS - 1) / GKYL_DEFAULT_NUM_THREADS; + gkyl_bc_twistshift_add_contr_cu_ker<< > >( + ftar->on_dev, up->num_numcol_fidx_tar, num_cells_skin, up->mm_contr->on_dev, up->num_do_cum, + up->permutted_ghost_r, up->grid + ); } diff --git a/gyrokinetic/zero/boundary_flux.c b/gyrokinetic/zero/boundary_flux.c index bddce621d1..283a40bd7e 100644 --- a/gyrokinetic/zero/boundary_flux.c +++ b/gyrokinetic/zero/boundary_flux.c @@ -10,10 +10,11 @@ #include #include -gkyl_boundary_flux* -gkyl_boundary_flux_new(int dir, enum gkyl_edge_loc edge, - const struct gkyl_rect_grid *grid, const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, - int num_eqns, const struct gkyl_dg_eqn **eqns, bool use_gpu) +gkyl_boundary_flux *gkyl_boundary_flux_new( + int dir, enum gkyl_edge_loc edge, const struct gkyl_rect_grid *grid, + const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, int num_eqns, + const struct gkyl_dg_eqn **eqns, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { @@ -31,29 +32,30 @@ gkyl_boundary_flux_new(int dir, enum gkyl_edge_loc edge, up->use_gpu = use_gpu; up->num_eqns = num_eqns; - up->eqns = gkyl_malloc(up->num_eqns*sizeof(struct gkyl_dg_eqn *)); - for (int i=0; inum_eqns; i++) + up->eqns = gkyl_malloc(up->num_eqns * sizeof(struct gkyl_dg_eqn *)); + for (int i = 0; i < up->num_eqns; i++) { up->eqns[i] = gkyl_dg_eqn_acquire(eqns[i]); + } up->eqns_ho = up->eqns; - + up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); - + up->on_dev = up; - + return up; } -void -gkyl_boundary_flux_advance(gkyl_boundary_flux *up, - const struct gkyl_array *fIn, struct gkyl_array *fluxOut) +void gkyl_boundary_flux_advance( + gkyl_boundary_flux *up, const struct gkyl_array *fIn, struct gkyl_array *fluxOut +) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { gkyl_boundary_flux_advance_cu(up, fIn, fluxOut); return; - } + } #endif int idx_s[GKYL_MAX_DIM]; @@ -64,39 +66,41 @@ gkyl_boundary_flux_advance(gkyl_boundary_flux *up, while (gkyl_range_iter_next(&iter)) { int *idx_g = iter.idx; gkyl_copy_int_arr(up->ghost_r.ndim, idx_g, idx_s); - idx_s[up->dir] = up->edge == GKYL_LOWER_EDGE? idx_g[up->dir]+1 : idx_g[up->dir]-1; + idx_s[up->dir] = up->edge == GKYL_LOWER_EDGE ? idx_g[up->dir] + 1 : idx_g[up->dir] - 1; gkyl_rect_grid_cell_center(&up->grid, idx_g, xc_g); gkyl_rect_grid_cell_center(&up->grid, idx_s, xc_s); - long linidx_g = gkyl_range_idx(&up->ghost_r, idx_g); + long linidx_g = gkyl_range_idx(&up->ghost_r, idx_g); long linidx_s = gkyl_range_idx(&up->skin_r, idx_s); const double *fIn_s = gkyl_array_cfetch(fIn, linidx_s); const double *fIn_g = gkyl_array_cfetch(fIn, linidx_g); double *fluxOut_g = gkyl_array_fetch(fluxOut, linidx_g); - for (int i=0; inum_eqns; i++) { - up->eqns[i]->boundary_diag_term(up->eqns[i], up->dir, xc_s, xc_g, - up->grid.dx, up->grid.dx, idx_s, idx_g, up->edge == GKYL_LOWER_EDGE? -1 : 1, - fIn_s, fIn_g, fluxOut_g); + for (int i = 0; i < up->num_eqns; i++) { + up->eqns[i]->boundary_diag_term( + up->eqns[i], up->dir, xc_s, xc_g, up->grid.dx, up->grid.dx, idx_s, idx_g, + up->edge == GKYL_LOWER_EDGE ? -1 : 1, fIn_s, fIn_g, fluxOut_g + ); } } } -void -gkyl_boundary_flux_release(gkyl_boundary_flux* up) +void gkyl_boundary_flux_release(gkyl_boundary_flux *up) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { gkyl_cu_free(up->eqns); - } + } #endif - for (int i=0; inum_eqns; i++) + for (int i = 0; i < up->num_eqns; i++) { gkyl_dg_eqn_release(up->eqns_ho[i]); + } gkyl_free(up->eqns_ho); - if (GKYL_IS_CU_ALLOC(up->flags)) + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/gyrokinetic/zero/boundary_flux_cu.cu b/gyrokinetic/zero/boundary_flux_cu.cu index 213098f703..edc20ef52e 100644 --- a/gyrokinetic/zero/boundary_flux_cu.cu +++ b/gyrokinetic/zero/boundary_flux_cu.cu @@ -8,12 +8,14 @@ extern "C" { #include } -struct gkyl_boundary_flux* -gkyl_boundary_flux_cu_dev_new(int dir, enum gkyl_edge_loc edge, - const struct gkyl_rect_grid *grid, const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, - int num_eqns, const struct gkyl_dg_eqn **eqns) +struct gkyl_boundary_flux *gkyl_boundary_flux_cu_dev_new( + int dir, enum gkyl_edge_loc edge, const struct gkyl_rect_grid *grid, + const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, int num_eqns, + const struct gkyl_dg_eqn **eqns +) { - struct gkyl_boundary_flux *up = (struct gkyl_boundary_flux*) gkyl_malloc(sizeof(struct gkyl_boundary_flux)); + struct gkyl_boundary_flux *up = + (struct gkyl_boundary_flux *)gkyl_malloc(sizeof(struct gkyl_boundary_flux)); up->dir = dir; up->edge = edge; @@ -22,23 +24,27 @@ gkyl_boundary_flux_cu_dev_new(int dir, enum gkyl_edge_loc edge, up->ghost_r = *ghost_r; up->use_gpu = true; - // Acquire pointers to on_dev objects so memcpy below copies those too. + // Acquire pointers to on_dev objects so memcpy below copies those too. up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); up->num_eqns = num_eqns; - up->eqns_ho = (struct gkyl_dg_eqn **) gkyl_malloc(up->num_eqns*sizeof(struct gkyl_dg_eqn *)); - struct gkyl_dg_eqn **eqns_ho_dev = (struct gkyl_dg_eqn **) gkyl_malloc(up->num_eqns*sizeof(struct gkyl_dg_eqn *)); - for (int i=0; inum_eqns; i++) { + up->eqns_ho = (struct gkyl_dg_eqn **)gkyl_malloc(up->num_eqns * sizeof(struct gkyl_dg_eqn *)); + struct gkyl_dg_eqn **eqns_ho_dev = + (struct gkyl_dg_eqn **)gkyl_malloc(up->num_eqns * sizeof(struct gkyl_dg_eqn *)); + for (int i = 0; i < up->num_eqns; i++) { up->eqns_ho[i] = gkyl_dg_eqn_acquire(eqns[i]); eqns_ho_dev[i] = up->eqns_ho[i]->on_dev; } - up->eqns = (struct gkyl_dg_eqn **) gkyl_cu_malloc(up->num_eqns*sizeof(struct gkyl_dg_eqn *)); - gkyl_cu_memcpy(up->eqns, eqns_ho_dev, up->num_eqns*sizeof(struct gkyl_dg_eqn *), GKYL_CU_MEMCPY_H2D); - - struct gkyl_boundary_flux *up_cu = (struct gkyl_boundary_flux*) gkyl_cu_malloc(sizeof(struct gkyl_boundary_flux)); + up->eqns = (struct gkyl_dg_eqn **)gkyl_cu_malloc(up->num_eqns * sizeof(struct gkyl_dg_eqn *)); + gkyl_cu_memcpy( + up->eqns, eqns_ho_dev, up->num_eqns * sizeof(struct gkyl_dg_eqn *), GKYL_CU_MEMCPY_H2D + ); + + struct gkyl_boundary_flux *up_cu = + (struct gkyl_boundary_flux *)gkyl_cu_malloc(sizeof(struct gkyl_boundary_flux)); gkyl_cu_memcpy(up_cu, up, sizeof(struct gkyl_boundary_flux), GKYL_CU_MEMCPY_H2D); up->on_dev = up_cu; @@ -47,20 +53,19 @@ gkyl_boundary_flux_cu_dev_new(int dir, enum gkyl_edge_loc edge, return up; } -__global__ static void -gkyl_boundary_flux_advance_cu_ker(const struct gkyl_boundary_flux *up, - const struct gkyl_array* fIn, struct gkyl_array* fluxOut) +__global__ static void gkyl_boundary_flux_advance_cu_ker( + const struct gkyl_boundary_flux *up, const struct gkyl_array *fIn, struct gkyl_array *fluxOut +) { int idx_g[GKYL_MAX_DIM], idx_s[GKYL_MAX_DIM]; double xc_g[GKYL_MAX_DIM], xc_s[GKYL_MAX_DIM]; - for (unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < up->ghost_r.volume; tid += blockDim.x*gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < up->ghost_r.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&up->ghost_r, tid, idx_g); gkyl_copy_int_arr(up->ghost_r.ndim, idx_g, idx_s); - idx_s[up->dir] = up->edge == GKYL_LOWER_EDGE? idx_g[up->dir]+1 : idx_g[up->dir]-1; + idx_s[up->dir] = up->edge == GKYL_LOWER_EDGE ? idx_g[up->dir] + 1 : idx_g[up->dir] - 1; gkyl_rect_grid_cell_center(&up->grid, idx_g, xc_g); gkyl_rect_grid_cell_center(&up->grid, idx_s, xc_s); @@ -68,24 +73,26 @@ gkyl_boundary_flux_advance_cu_ker(const struct gkyl_boundary_flux *up, long linidx_g = gkyl_range_idx(&up->ghost_r, idx_g); long linidx_s = gkyl_range_idx(&up->skin_r, idx_s); - const double* fg_c = (const double*) gkyl_array_cfetch(fIn, linidx_g); - const double* fs_c = (const double*) gkyl_array_cfetch(fIn, linidx_s); - double *fluxOut_g = (double*) gkyl_array_fetch(fluxOut, linidx_g); + const double *fg_c = (const double *)gkyl_array_cfetch(fIn, linidx_g); + const double *fs_c = (const double *)gkyl_array_cfetch(fIn, linidx_s); + double *fluxOut_g = (double *)gkyl_array_fetch(fluxOut, linidx_g); - for (int i=0; inum_eqns; i++) { - up->eqns[i]->boundary_diag_term(up->eqns[i], up->dir, xc_s, xc_g, - up->grid.dx, up->grid.dx, idx_s, idx_g, up->edge == GKYL_LOWER_EDGE? -1 : 1, - fs_c, fg_c, fluxOut_g); + for (int i = 0; i < up->num_eqns; i++) { + up->eqns[i]->boundary_diag_term( + up->eqns[i], up->dir, xc_s, xc_g, up->grid.dx, up->grid.dx, idx_s, idx_g, + up->edge == GKYL_LOWER_EDGE ? -1 : 1, fs_c, fg_c, fluxOut_g + ); } } } -void -gkyl_boundary_flux_advance_cu(struct gkyl_boundary_flux *up, - const struct gkyl_array *fIn, struct gkyl_array *fluxOut) +void gkyl_boundary_flux_advance_cu( + struct gkyl_boundary_flux *up, const struct gkyl_array *fIn, struct gkyl_array *fluxOut +) { int nblocks = up->ghost_r.nblocks, nthreads = up->ghost_r.nthreads; - - gkyl_boundary_flux_advance_cu_ker<<>>(up->on_dev, - fIn->on_dev, fluxOut->on_dev); + + gkyl_boundary_flux_advance_cu_ker<< > >( + up->on_dev, fIn->on_dev, fluxOut->on_dev + ); } diff --git a/gyrokinetic/zero/calc_bmag.c b/gyrokinetic/zero/calc_bmag.c index f7367d70ac..ca7b924be9 100644 --- a/gyrokinetic/zero/calc_bmag.c +++ b/gyrokinetic/zero/calc_bmag.c @@ -9,9 +9,10 @@ #include -gkyl_calc_bmag* -gkyl_calc_bmag_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_rect_grid *cgrid, const struct gkyl_rect_grid *pgrid, bool use_gpu) +gkyl_calc_bmag *gkyl_calc_bmag_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_rect_grid *cgrid, const struct gkyl_rect_grid *pgrid, bool use_gpu +) { gkyl_calc_bmag *up = gkyl_malloc(sizeof(gkyl_calc_bmag)); up->cbasis = cbasis; @@ -24,23 +25,23 @@ gkyl_calc_bmag_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pba void gkyl_calc_bmag_global(double t, const double *xn, double *fout, void *ctx) { - struct gkyl_bmag_ctx *gc = (struct gkyl_bmag_ctx*) ctx; + struct gkyl_bmag_ctx *gc = (struct gkyl_bmag_ctx *)ctx; // Need a crude an manual deflated coordinate because this works on deflated geometry due to the allgather double xpt[GKYL_MAX_CDIM]; - if (gc->cgrid->ndim == 1) + if (gc->cgrid->ndim == 1) { xpt[0] = xn[2]; - else if (gc->cgrid->ndim == 2){ + } else if (gc->cgrid->ndim == 2) { xpt[0] = xn[0]; xpt[1] = xn[2]; - } - else{ + } else { xpt[0] = xn[0]; xpt[1] = xn[1]; xpt[2] = xn[2]; } int cidx[GKYL_MAX_CDIM]; - for(int i = 0; i < gc->cgrid->ndim; i++){ - int idxtemp = gc->crange_global->lower[i] + (int) floor((xpt[i] - (gc->cgrid->lower[i]) )/gc->cgrid->dx[i]); + for (int i = 0; i < gc->cgrid->ndim; i++) { + int idxtemp = + gc->crange_global->lower[i] + (int)floor((xpt[i] - (gc->cgrid->lower[i])) / gc->cgrid->dx[i]); idxtemp = GKYL_MIN2(idxtemp, gc->crange_global->upper[i]); idxtemp = GKYL_MAX2(idxtemp, gc->crange_global->lower[i]); cidx[i] = idxtemp; @@ -50,19 +51,21 @@ void gkyl_calc_bmag_global(double t, const double *xn, double *fout, void *ctx) double cxc[gc->cgrid->ndim]; double xyz[gc->cgrid->ndim]; gkyl_rect_grid_cell_center(gc->cgrid, cidx, cxc); - for(int i = 0; i < gc->cgrid->ndim; i++) - xyz[i] = (xpt[i]-cxc[i])/(gc->cgrid->dx[i]*0.5); + for (int i = 0; i < gc->cgrid->ndim; i++) { + xyz[i] = (xpt[i] - cxc[i]) / (gc->cgrid->dx[i] * 0.5); + } fout[0] = gc->cbasis->eval_expand(xyz, mcoeffs); } static inline void bmag_comp(double t, const double *xn, double *fout, void *ctx) { - struct gkyl_bmag_ctx *gc = (struct gkyl_bmag_ctx*) ctx; + struct gkyl_bmag_ctx *gc = (struct gkyl_bmag_ctx *)ctx; double RZPHI[gc->cgrid->ndim]; int cidx[GKYL_MAX_CDIM]; - for(int i = 0; i < gc->cgrid->ndim; i++){ - int idxtemp = gc->crange_global->lower[i] + (int) floor((xn[i] - (gc->cgrid->lower[i]) )/gc->cgrid->dx[i]); + for (int i = 0; i < gc->cgrid->ndim; i++) { + int idxtemp = + gc->crange_global->lower[i] + (int)floor((xn[i] - (gc->cgrid->lower[i])) / gc->cgrid->dx[i]); idxtemp = GKYL_MIN2(idxtemp, gc->crange->upper[i]); idxtemp = GKYL_MAX2(idxtemp, gc->crange->lower[i]); cidx[i] = idxtemp; @@ -70,45 +73,47 @@ static inline void bmag_comp(double t, const double *xn, double *fout, void *ctx long lidx = gkyl_range_idx(gc->crange, cidx); const double *mcoeffs = gkyl_array_cfetch(gc->mapc2p, lidx); - + double cxc[gc->cgrid->ndim]; double xyz[gc->cgrid->ndim]; gkyl_rect_grid_cell_center(gc->cgrid, cidx, cxc); - for(int i = 0; i < gc->cgrid->ndim; i++) - xyz[i] = (xn[i]-cxc[i])/(gc->cgrid->dx[i]*0.5); - for(int i = 0; i < gc->cgrid->ndim; i++){ - RZPHI[i] = gc->cbasis->eval_expand(xyz, &mcoeffs[i*gc->cbasis->num_basis]); + for (int i = 0; i < gc->cgrid->ndim; i++) { + xyz[i] = (xn[i] - cxc[i]) / (gc->cgrid->dx[i] * 0.5); + } + for (int i = 0; i < gc->cgrid->ndim; i++) { + RZPHI[i] = gc->cbasis->eval_expand(xyz, &mcoeffs[i * gc->cbasis->num_basis]); } double R = RZPHI[0]; double Z = RZPHI[1]; int rzidx[2]; - int idxtemp = gc->range->lower[0] + (int) floor((R - gc->grid->lower[0])/gc->grid->dx[0]); + int idxtemp = gc->range->lower[0] + (int)floor((R - gc->grid->lower[0]) / gc->grid->dx[0]); idxtemp = GKYL_MIN2(idxtemp, gc->range->upper[0]); idxtemp = GKYL_MAX2(idxtemp, gc->range->lower[0]); rzidx[0] = idxtemp; - idxtemp = gc->range->lower[1] + (int) floor((Z - gc->grid->lower[1])/gc->grid->dx[1]); + idxtemp = gc->range->lower[1] + (int)floor((Z - gc->grid->lower[1]) / gc->grid->dx[1]); idxtemp = GKYL_MIN2(idxtemp, gc->range->upper[1]); idxtemp = GKYL_MAX2(idxtemp, gc->range->lower[1]); rzidx[1] = idxtemp; - long loc = gkyl_range_idx(gc->range, rzidx); - const double *coeffs = gkyl_array_cfetch(gc->bmagdg,loc); + const double *coeffs = gkyl_array_cfetch(gc->bmagdg, loc); double xc[2]; gkyl_rect_grid_cell_center(gc->grid, rzidx, xc); double xy[2]; - xy[0] = (R-xc[0])/(gc->grid->dx[0]*0.5); - xy[1] = (Z-xc[1])/(gc->grid->dx[1]*0.5); + xy[0] = (R - xc[0]) / (gc->grid->dx[0] * 0.5); + xy[1] = (Z - xc[1]) / (gc->grid->dx[1] * 0.5); fout[0] = gc->basis->eval_expand(xy, coeffs); } -void gkyl_calc_bmag_advance(const gkyl_calc_bmag *up, - const struct gkyl_range *crange, const struct gkyl_range *crange_ext, const struct gkyl_range *crange_global, - const struct gkyl_range *prange, const struct gkyl_range *prange_ext, - const struct gkyl_array *bmagrz, struct gkyl_array* bmag_compdg, struct gkyl_array* mapc2p, bool use_quad) +void gkyl_calc_bmag_advance( + const gkyl_calc_bmag *up, const struct gkyl_range *crange, const struct gkyl_range *crange_ext, + const struct gkyl_range *crange_global, const struct gkyl_range *prange, + const struct gkyl_range *prange_ext, const struct gkyl_array *bmagrz, + struct gkyl_array *bmag_compdg, struct gkyl_array *mapc2p, bool use_quad +) { // Convert bmag into computational coordinates struct gkyl_bmag_ctx *ctx = gkyl_malloc(sizeof(*ctx)); @@ -122,12 +127,13 @@ void gkyl_calc_bmag_advance(const gkyl_calc_bmag *up, ctx->cbasis = up->cbasis; ctx->mapc2p = mapc2p; if (use_quad) { - gkyl_proj_on_basis *eval_bmag_comp = gkyl_proj_on_basis_new(up->cgrid, up->cbasis, 2, 1, bmag_comp, ctx); + gkyl_proj_on_basis *eval_bmag_comp = + gkyl_proj_on_basis_new(up->cgrid, up->cbasis, 2, 1, bmag_comp, ctx); gkyl_proj_on_basis_advance(eval_bmag_comp, 0.0, crange, bmag_compdg); //on ghosts with ext_range gkyl_proj_on_basis_release(eval_bmag_comp); - } - else { - gkyl_eval_on_nodes *eval_bmag_comp = gkyl_eval_on_nodes_new(up->cgrid, up->cbasis, 1, bmag_comp, ctx); + } else { + gkyl_eval_on_nodes *eval_bmag_comp = + gkyl_eval_on_nodes_new(up->cgrid, up->cbasis, 1, bmag_comp, ctx); gkyl_eval_on_nodes_advance(eval_bmag_comp, 0.0, crange, bmag_compdg); //on ghosts with ext_range gkyl_eval_on_nodes_release(eval_bmag_comp); } @@ -136,8 +142,7 @@ void gkyl_calc_bmag_advance(const gkyl_calc_bmag *up, gkyl_free(ctx); } -void -gkyl_calc_bmag_release(gkyl_calc_bmag* up) +void gkyl_calc_bmag_release(gkyl_calc_bmag *up) { gkyl_free(up); } diff --git a/gyrokinetic/zero/calc_derived_geo.c b/gyrokinetic/zero/calc_derived_geo.c index 7343f07d63..e9270e0076 100644 --- a/gyrokinetic/zero/calc_derived_geo.c +++ b/gyrokinetic/zero/calc_derived_geo.c @@ -6,8 +6,9 @@ #include #include -gkyl_calc_derived_geo* -gkyl_calc_derived_geo_new(const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, int node_type, bool use_gpu) +gkyl_calc_derived_geo *gkyl_calc_derived_geo_new( + const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, int node_type, bool use_gpu +) { gkyl_calc_derived_geo *up = gkyl_malloc(sizeof(*up)); up->cdim = cbasis->ndim; @@ -20,13 +21,14 @@ gkyl_calc_derived_geo_new(const struct gkyl_basis *cbasis, const struct gkyl_rec return up; } - -void -gkyl_calc_derived_geo_advance(const gkyl_calc_derived_geo *up, const struct gkyl_range *crange, struct gkyl_array *gFld, - struct gkyl_array *bmagFld, struct gkyl_array *jFld, struct gkyl_array *jinvFld, struct gkyl_array *grFld, - struct gkyl_array *biFld, struct gkyl_array *cmagFld, struct gkyl_array *jtotFld, struct gkyl_array *jtotinvFld, - struct gkyl_array *gxxJFld, struct gkyl_array *gxyJFld, struct gkyl_array *gyyJFld, struct gkyl_array *gxzJFld, - struct gkyl_array *eps2Fld) +void gkyl_calc_derived_geo_advance( + const gkyl_calc_derived_geo *up, const struct gkyl_range *crange, struct gkyl_array *gFld, + struct gkyl_array *bmagFld, struct gkyl_array *jFld, struct gkyl_array *jinvFld, + struct gkyl_array *grFld, struct gkyl_array *biFld, struct gkyl_array *cmagFld, + struct gkyl_array *jtotFld, struct gkyl_array *jtotinvFld, struct gkyl_array *gxxJFld, + struct gkyl_array *gxyJFld, struct gkyl_array *gyyJFld, struct gkyl_array *gxzJFld, + struct gkyl_array *eps2Fld +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, crange); @@ -41,17 +43,19 @@ gkyl_calc_derived_geo_advance(const gkyl_calc_derived_geo *up, const struct gkyl double *cmag_i = gkyl_array_fetch(cmagFld, loc); double *jtot_i = gkyl_array_fetch(jtotFld, loc); double *jtotinv_i = gkyl_array_fetch(jtotinvFld, loc); - double *gxxJ_i= gkyl_array_fetch(gxxJFld, loc); - double *gxyJ_i= gkyl_array_fetch(gxyJFld, loc); - double *gyyJ_i= gkyl_array_fetch(gyyJFld, loc); - double *gxzJ_i= gkyl_array_fetch(gxzJFld, loc); - double *eps2_i= gkyl_array_fetch(eps2Fld, loc); - up->kernel(gij, bmag_i, j_i, jinv_i, grij, bi_i, cmag_i, jtot_i, jtotinv_i, gxxJ_i, gxyJ_i, gyyJ_i, gxzJ_i, eps2_i); + double *gxxJ_i = gkyl_array_fetch(gxxJFld, loc); + double *gxyJ_i = gkyl_array_fetch(gxyJFld, loc); + double *gyyJ_i = gkyl_array_fetch(gyyJFld, loc); + double *gxzJ_i = gkyl_array_fetch(gxzJFld, loc); + double *eps2_i = gkyl_array_fetch(eps2Fld, loc); + up->kernel( + gij, bmag_i, j_i, jinv_i, grij, bi_i, cmag_i, jtot_i, jtotinv_i, gxxJ_i, gxyJ_i, gyyJ_i, + gxzJ_i, eps2_i + ); } } -void -gkyl_calc_derived_geo_release(gkyl_calc_derived_geo* up) +void gkyl_calc_derived_geo_release(gkyl_calc_derived_geo *up) { gkyl_free(up); } diff --git a/gyrokinetic/zero/calc_metric.c b/gyrokinetic/zero/calc_metric.c index d2caf9c6c5..2484485568 100644 --- a/gyrokinetic/zero/calc_metric.c +++ b/gyrokinetic/zero/calc_metric.c @@ -6,11 +6,12 @@ #include #include -gkyl_calc_metric* -gkyl_calc_metric_new(const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, +gkyl_calc_metric *gkyl_calc_metric_new( + const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, const struct gkyl_range *global, const struct gkyl_range *global_ext, - const struct gkyl_range *local, const struct gkyl_range *local_ext, - bool exit_at_checks, bool use_gpu) + const struct gkyl_range *local, const struct gkyl_range *local_ext, bool exit_at_checks, + bool use_gpu +) { gkyl_calc_metric *up = gkyl_malloc(sizeof(gkyl_calc_metric)); @@ -33,25 +34,25 @@ gkyl_calc_metric_new(const struct gkyl_basis *cbasis, const struct gkyl_rect_gri return up; } -static inline double calc_metric(double dxdz[3][3], int i, int j) +static inline double calc_metric(double dxdz[3][3], int i, int j) { double sum = 0; - for (int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) { sum += dxdz[k][i - 1] * dxdz[k][j - 1]; + } return sum; -} +} // Calculates e^1 = e_2 x e_3 /J -static inline void -calc_dual(double J, const double e_2[3], const double e_3[3], double e1[3]) +static inline void calc_dual(double J, const double e_2[3], const double e_3[3], double e1[3]) { - e1[0] = (e_2[1]*e_3[2] - e_2[2]*e_3[1] )/J; - e1[1] = -(e_2[0]*e_3[2] - e_2[2]*e_3[0] )/J; - e1[2] = (e_2[0]*e_3[1] - e_2[1]*e_3[0] )/J; + e1[0] = (e_2[1] * e_3[2] - e_2[2] * e_3[1]) / J; + e1[1] = -(e_2[0] * e_3[2] - e_2[2] * e_3[0]) / J; + e1[2] = (e_2[0] * e_3[1] - e_2[1] * e_3[0]) / J; } -static inline void -matTvec(double M[3][3], double v[3], double result[3]) { +static inline void matTvec(double M[3][3], double v[3], double result[3]) +{ for (int i = 0; i < 3; i++) { result[i] = 0.0; for (int j = 0; j < 3; j++) { @@ -60,18 +61,21 @@ matTvec(double M[3][3], double v[3], double result[3]) { } } -static inline double dot(const double a[3], const double b[3]) { - return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; +static inline double dot(const double a[3], const double b[3]) +{ + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; } -static inline void cross(const double a[3], const double b[3], double c[3]) { - c[0] = a[1]*b[2] - a[2]*b[1]; - c[1] = a[2]*b[0] - a[0]*b[2]; - c[2] = a[0]*b[1] - a[1]*b[0]; +static inline void cross(const double a[3], const double b[3], double c[3]) +{ + c[0] = a[1] * b[2] - a[2] * b[1]; + c[1] = a[2] * b[0] - a[0] * b[2]; + c[2] = a[0] * b[1] - a[1] * b[0]; } static inline void -check_orthonormality(const double tan[9], const double dual[9], bool exit_at_check) { +check_orthonormality(const double tan[9], const double dual[9], bool exit_at_check) +{ // Check that the coordinate system has tangent/dual vectors // satisfying orthonormality. @@ -79,22 +83,26 @@ check_orthonormality(const double tan[9], const double dual[9], bool exit_at_che double prod[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - prod[i][j] = tan[3*i +0]*dual[3*j +0] + tan[3*i +1]*dual[3*j +1] + tan[3*i +2]*dual[3*j +2]; + prod[i][j] = tan[3 * i + 0] * dual[3 * j + 0] + tan[3 * i + 1] * dual[3 * j + 1] + + tan[3 * i + 2] * dual[3 * j + 2]; } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - if ( i==j && prod[i][j] < 0 ) { - fprintf(stderr, "calc_metric.c: Orthonormality violated : e_%d . e^%d = %.6e\n", i+1, j+1, prod[i][j]); + if (i == j && prod[i][j] < 0) { + fprintf( + stderr, "calc_metric.c: Orthonormality violated : e_%d . e^%d = %.6e\n", i + 1, j + 1, + prod[i][j] + ); assert(!exit_at_check); } } } } -static inline void -check_right_handed(const double tan[9], const double dual[9], bool exit_at_check) { +static inline void check_right_handed(const double tan[9], const double dual[9], bool exit_at_check) +{ // Check that the coordinate system is right handed. const double *e1 = &tan[0]; const double *e2 = &tan[3]; @@ -106,39 +114,46 @@ check_right_handed(const double tan[9], const double dual[9], bool exit_at_check double J = dot(e1, cross_e2e3); if (J < 0.0) { - fprintf(stderr, "calc_metric.c: Left-handed coordinate system, J = e_1 . (e_2 x e_3) = %.6e < 0.\n", J); + fprintf( + stderr, "calc_metric.c: Left-handed coordinate system, J = e_1 . (e_2 x e_3) = %.6e < 0.\n", J + ); assert(!exit_at_check); - } - else if (J == 0.0) { + } else if (J == 0.0) { fprintf(stderr, "calc_metric.c: Degenerate coordinate system, J = %.6e\n", J); assert(!exit_at_check); } } -static inline void -check_parallel(double *v1, double *v2, bool exit_at_check) { +static inline void check_parallel(double *v1, double *v2, bool exit_at_check) +{ // Check v1 and v2 are parallel by checking that: - // |v1 x v2 | < eps + // |v1 x v2 | < eps // |v1 . v2 - 1| < eps const double eps = 1e-3; - double cx = v1[1]*v2[2] - v1[2]*v2[1]; - double cy = v1[2]*v2[0] - v1[0]*v2[2]; - double cz = v1[0]*v2[1] - v1[1]*v2[0]; + double cx = v1[1] * v2[2] - v1[2] * v2[1]; + double cy = v1[2] * v2[0] - v1[0] * v2[2]; + double cz = v1[0] * v2[1] - v1[1] * v2[0]; - double c_mag = sqrt(cx*cx + cy*cy + cz*cz); + double c_mag = sqrt(cx * cx + cy * cy + cz * cz); - double dot = v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]; - if (fabs(c_mag) < eps && fabs(dot-1.0) < eps) + double dot = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; + if (fabs(c_mag) < eps && fabs(dot - 1.0) < eps) { return; - else { - fprintf(stderr, "calc_metric.c: inconsistent B & mapc2p (hat{b} not parallel to e_3; |b . e_3|=%.6e, |b x e_3|=%.6e).\n",dot,c_mag); + } else { + fprintf( + stderr, + "calc_metric.c: inconsistent B & mapc2p (hat{b} not parallel to e_3; |b . e_3|=%.6e, |b x " + "e_3|=%.6e).\n", + dot, c_mag + ); assert(!exit_at_check); } } static inline void -check_axisymmetric(struct gkyl_array* arr, struct gkyl_range *range, bool exit_at_check) { +check_axisymmetric(struct gkyl_array *arr, struct gkyl_range *range, bool exit_at_check) +{ const double rel_tol = 1e-6; const double abs_tol = 1e-11; double reldiff; @@ -146,22 +161,21 @@ check_axisymmetric(struct gkyl_array* arr, struct gkyl_range *range, bool exit_a int cidx[3]; int cidx_prev[3]; - for (int ip=range->lower[PSI_IDX]; ip<=range->upper[PSI_IDX]; ++ip) { - for (int it=range->lower[TH_IDX]; it<=range->upper[TH_IDX]; ++it) { - + for (int ip = range->lower[PSI_IDX]; ip <= range->upper[PSI_IDX]; ++ip) { + for (int it = range->lower[TH_IDX]; it <= range->upper[TH_IDX]; ++it) { double g_ij_avg[6] = {0.0}; int num_al = range->upper[AL_IDX] - range->lower[AL_IDX] + 1; - for (int ia=range->lower[AL_IDX]; ia<=range->upper[AL_IDX]; ++ia) { + for (int ia = range->lower[AL_IDX]; ia <= range->upper[AL_IDX]; ++ia) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; const double *g_ij_n = gkyl_array_cfetch(arr, gkyl_range_idx(range, cidx)); for (int k = 0; k < 6; ++k) { - g_ij_avg[k] += g_ij_n[k] / num_al; + g_ij_avg[k] += g_ij_n[k] / num_al; } } - for (int ia=range->lower[AL_IDX] + 1; ia<=range->upper[AL_IDX]; ++ia) { + for (int ia = range->lower[AL_IDX] + 1; ia <= range->upper[AL_IDX]; ++ia) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; @@ -173,109 +187,127 @@ check_axisymmetric(struct gkyl_array* arr, struct gkyl_range *range, bool exit_a const double *g_ij_prev = gkyl_array_cfetch(arr, gkyl_range_idx(range, cidx_prev)); for (int k = 0; k < 6; ++k) { - reldiff = fabs(g_ij_n[k] - g_ij_avg[k])/(rel_tol*fabs(g_ij_avg[k]) + abs_tol); + reldiff = fabs(g_ij_n[k] - g_ij_avg[k]) / (rel_tol * fabs(g_ij_avg[k]) + abs_tol); if (reldiff < 1) { return; - } - else { - fprintf(stderr, "calc_metric.c: Axisymmetry violated at ip=%d, it=%d, ia=%d. g_ij component %d variation %.6e exceeds tolerance\n", ip, it, ia, k, reldiff); + } else { + fprintf( + stderr, + "calc_metric.c: Axisymmetry violated at ip=%d, it=%d, ia=%d. g_ij component %d " + "variation %.6e exceeds tolerance\n", + ip, it, ia, k, reldiff + ); assert(!exit_at_check); } } - } } } } -void gkyl_calc_metric_advance_rz( gkyl_calc_metric *up, struct gkyl_range *nrange, - struct gkyl_array *mc2p_nodal_fd, struct gkyl_array *ddtheta_nodal, - struct gkyl_array *bmag_nodal, double *dzc, struct gkyl_array *gFld, - struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, - struct gkyl_array *dualmagFld, struct gkyl_array *normFld, - struct gkyl_array *jFld, struct gkyl_array* bcartFld, const struct gkyl_range *update_range) +void gkyl_calc_metric_advance_rz( + gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, + struct gkyl_array *ddtheta_nodal, struct gkyl_array *bmag_nodal, double *dzc, + struct gkyl_array *gFld, struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, + struct gkyl_array *dualmagFld, struct gkyl_array *normFld, struct gkyl_array *jFld, + struct gkyl_array *bcartFld, const struct gkyl_range *update_range +) { - struct gkyl_array* gFld_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange->volume); - struct gkyl_array* jFld_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange->volume); - struct gkyl_array* bcartFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); - struct gkyl_array* tanvecFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); - struct gkyl_array* dualFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); - struct gkyl_array* dualmagFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); - struct gkyl_array* normFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *gFld_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange->volume); + struct gkyl_array *jFld_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange->volume); + struct gkyl_array *bcartFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); + struct gkyl_array *tanvecFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *dualFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *dualmagFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); + struct gkyl_array *normFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { R_IDX, Z_IDX, PHI_IDX }; // arrangement of cartesian coordinates int cidx[3]; - for(int ia=nrange->lower[AL_IDX]; ia<=nrange->upper[AL_IDX]; ++ia){ - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { + for (int ia = nrange->lower[AL_IDX]; ia <= nrange->upper[AL_IDX]; ++ia) { + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; const double *mc2p_n = gkyl_array_cfetch(mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); double dxdz[3][3]; - if((ip == nrange->lower[PSI_IDX]) && (up->local.lower[PSI_IDX]== up->global.lower[PSI_IDX]) ) { - dxdz[0][0] = (-3*mc2p_n[R_IDX] + 4*mc2p_n[6+R_IDX] - mc2p_n[12+R_IDX] )/dzc[0]/2; - dxdz[1][0] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[6+Z_IDX] - mc2p_n[12+Z_IDX] )/dzc[0]/2; - dxdz[2][0] = (-3*mc2p_n[PHI_IDX] + 4*mc2p_n[6+PHI_IDX] - mc2p_n[12+PHI_IDX] ); - } - else if((ip == nrange->upper[PSI_IDX]) && (up->local.upper[PSI_IDX]== up->global.upper[PSI_IDX])) { - dxdz[0][0] = (3*mc2p_n[R_IDX] - 4*mc2p_n[3+R_IDX] + mc2p_n[9+R_IDX] )/dzc[0]/2; - dxdz[1][0] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[3+Z_IDX] + mc2p_n[9+Z_IDX] )/dzc[0]/2; - dxdz[2][0] = (3*mc2p_n[PHI_IDX] - 4*mc2p_n[3+PHI_IDX] + mc2p_n[9+PHI_IDX] ); - } - else { - dxdz[0][0] = -(mc2p_n[3 +R_IDX] - mc2p_n[6+R_IDX])/2/dzc[0]; - dxdz[1][0] = -(mc2p_n[3 +Z_IDX] - mc2p_n[6+Z_IDX])/2/dzc[0]; - dxdz[2][0] = -(mc2p_n[3 +PHI_IDX] - mc2p_n[6+PHI_IDX]); + if ((ip == nrange->lower[PSI_IDX]) && + (up->local.lower[PSI_IDX] == up->global.lower[PSI_IDX])) { + dxdz[0][0] = + (-3 * mc2p_n[R_IDX] + 4 * mc2p_n[6 + R_IDX] - mc2p_n[12 + R_IDX]) / dzc[0] / 2; + dxdz[1][0] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[6 + Z_IDX] - mc2p_n[12 + Z_IDX]) / dzc[0] / 2; + dxdz[2][0] = (-3 * mc2p_n[PHI_IDX] + 4 * mc2p_n[6 + PHI_IDX] - mc2p_n[12 + PHI_IDX]); + } else if ((ip == nrange->upper[PSI_IDX]) && + (up->local.upper[PSI_IDX] == up->global.upper[PSI_IDX])) { + dxdz[0][0] = (3 * mc2p_n[R_IDX] - 4 * mc2p_n[3 + R_IDX] + mc2p_n[9 + R_IDX]) / dzc[0] / 2; + dxdz[1][0] = (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[3 + Z_IDX] + mc2p_n[9 + Z_IDX]) / dzc[0] / 2; + dxdz[2][0] = (3 * mc2p_n[PHI_IDX] - 4 * mc2p_n[3 + PHI_IDX] + mc2p_n[9 + PHI_IDX]); + } else { + dxdz[0][0] = -(mc2p_n[3 + R_IDX] - mc2p_n[6 + R_IDX]) / 2 / dzc[0]; + dxdz[1][0] = -(mc2p_n[3 + Z_IDX] - mc2p_n[6 + Z_IDX]) / 2 / dzc[0]; + dxdz[2][0] = -(mc2p_n[3 + PHI_IDX] - mc2p_n[6 + PHI_IDX]); } // Take into account wrapping of cyclic coordinate phi if (dxdz[2][0] < -M_PI) { - dxdz[2][0] += 2*M_PI; + dxdz[2][0] += 2 * M_PI; } else if (dxdz[2][0] > M_PI) { - dxdz[2][0] -= 2*M_PI; - } - dxdz[2][0] = dxdz[2][0]/2.0/dzc[0]; - - if((ia == nrange->lower[AL_IDX]) && (up->local.lower[AL_IDX]== up->global.lower[AL_IDX]) ) { - dxdz[0][1] = (-3*mc2p_n[R_IDX] + 4*mc2p_n[18+R_IDX] - mc2p_n[24+R_IDX])/dzc[1]/2; - dxdz[1][1] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[18+Z_IDX] - mc2p_n[24+Z_IDX])/dzc[1]/2; - dxdz[2][1] = (-3*mc2p_n[PHI_IDX] + 4*mc2p_n[18+PHI_IDX] - mc2p_n[24+PHI_IDX])/dzc[1]/2; + dxdz[2][0] -= 2 * M_PI; } - else if((ia == nrange->upper[AL_IDX]) && (up->local.upper[AL_IDX]== up->global.upper[AL_IDX])){ - dxdz[0][1] = (3*mc2p_n[R_IDX] - 4*mc2p_n[15+R_IDX] + mc2p_n[21+R_IDX] )/dzc[1]/2; - dxdz[1][1] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[15+Z_IDX] + mc2p_n[21+Z_IDX] )/dzc[1]/2; - dxdz[2][1] = (3*mc2p_n[PHI_IDX] - 4*mc2p_n[15+PHI_IDX] + mc2p_n[21+PHI_IDX] )/dzc[1]/2; - } - else { - dxdz[0][1] = -(mc2p_n[15 +R_IDX] - mc2p_n[18 +R_IDX])/2/dzc[1]; - dxdz[1][1] = -(mc2p_n[15 +Z_IDX] - mc2p_n[18 +Z_IDX])/2/dzc[1]; - dxdz[2][1] = -(mc2p_n[15 +PHI_IDX] - mc2p_n[18 +PHI_IDX])/2/dzc[1]; + dxdz[2][0] = dxdz[2][0] / 2.0 / dzc[0]; + + if ((ia == nrange->lower[AL_IDX]) && + (up->local.lower[AL_IDX] == up->global.lower[AL_IDX])) { + dxdz[0][1] = + (-3 * mc2p_n[R_IDX] + 4 * mc2p_n[18 + R_IDX] - mc2p_n[24 + R_IDX]) / dzc[1] / 2; + dxdz[1][1] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[18 + Z_IDX] - mc2p_n[24 + Z_IDX]) / dzc[1] / 2; + dxdz[2][1] = + (-3 * mc2p_n[PHI_IDX] + 4 * mc2p_n[18 + PHI_IDX] - mc2p_n[24 + PHI_IDX]) / dzc[1] / 2; + } else if ((ia == nrange->upper[AL_IDX]) && + (up->local.upper[AL_IDX] == up->global.upper[AL_IDX])) { + dxdz[0][1] = + (3 * mc2p_n[R_IDX] - 4 * mc2p_n[15 + R_IDX] + mc2p_n[21 + R_IDX]) / dzc[1] / 2; + dxdz[1][1] = + (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[15 + Z_IDX] + mc2p_n[21 + Z_IDX]) / dzc[1] / 2; + dxdz[2][1] = + (3 * mc2p_n[PHI_IDX] - 4 * mc2p_n[15 + PHI_IDX] + mc2p_n[21 + PHI_IDX]) / dzc[1] / 2; + } else { + dxdz[0][1] = -(mc2p_n[15 + R_IDX] - mc2p_n[18 + R_IDX]) / 2 / dzc[1]; + dxdz[1][1] = -(mc2p_n[15 + Z_IDX] - mc2p_n[18 + Z_IDX]) / 2 / dzc[1]; + dxdz[2][1] = -(mc2p_n[15 + PHI_IDX] - mc2p_n[18 + PHI_IDX]) / 2 / dzc[1]; } - if((it == nrange->lower[TH_IDX]) && (up->local.lower[TH_IDX]== up->global.lower[TH_IDX])){ - dxdz[0][2] = (-3*mc2p_n[R_IDX] + 4*mc2p_n[30+R_IDX] - mc2p_n[36+R_IDX])/dzc[2]/2; - dxdz[1][2] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[30+Z_IDX] - mc2p_n[36+Z_IDX])/dzc[2]/2; - dxdz[2][2] = (-3*mc2p_n[PHI_IDX] + 4*mc2p_n[30+PHI_IDX] - mc2p_n[36+PHI_IDX])/dzc[2]/2; - } - else if((it == nrange->upper[TH_IDX]) && (up->local.upper[TH_IDX]== up->global.upper[TH_IDX])){ - dxdz[0][2] = (3*mc2p_n[R_IDX] - 4*mc2p_n[27+R_IDX] + mc2p_n[33+R_IDX] )/dzc[2]/2; - dxdz[1][2] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[27+Z_IDX] + mc2p_n[33+Z_IDX] )/dzc[2]/2; - dxdz[2][2] = (3*mc2p_n[PHI_IDX] - 4*mc2p_n[27+PHI_IDX] + mc2p_n[33+PHI_IDX] )/dzc[2]/2; - } - else { - dxdz[0][2] = -(mc2p_n[27 +R_IDX] - mc2p_n[30 +R_IDX])/2/dzc[2]; - dxdz[1][2] = -(mc2p_n[27 +Z_IDX] - mc2p_n[30 +Z_IDX])/2/dzc[2]; - dxdz[2][2] = -(mc2p_n[27 +PHI_IDX] - mc2p_n[30 +PHI_IDX])/2/dzc[2]; + if ((it == nrange->lower[TH_IDX]) && + (up->local.lower[TH_IDX] == up->global.lower[TH_IDX])) { + dxdz[0][2] = + (-3 * mc2p_n[R_IDX] + 4 * mc2p_n[30 + R_IDX] - mc2p_n[36 + R_IDX]) / dzc[2] / 2; + dxdz[1][2] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[30 + Z_IDX] - mc2p_n[36 + Z_IDX]) / dzc[2] / 2; + dxdz[2][2] = + (-3 * mc2p_n[PHI_IDX] + 4 * mc2p_n[30 + PHI_IDX] - mc2p_n[36 + PHI_IDX]) / dzc[2] / 2; + } else if ((it == nrange->upper[TH_IDX]) && + (up->local.upper[TH_IDX] == up->global.upper[TH_IDX])) { + dxdz[0][2] = + (3 * mc2p_n[R_IDX] - 4 * mc2p_n[27 + R_IDX] + mc2p_n[33 + R_IDX]) / dzc[2] / 2; + dxdz[1][2] = + (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[27 + Z_IDX] + mc2p_n[33 + Z_IDX]) / dzc[2] / 2; + dxdz[2][2] = + (3 * mc2p_n[PHI_IDX] - 4 * mc2p_n[27 + PHI_IDX] + mc2p_n[33 + PHI_IDX]) / dzc[2] / 2; + } else { + dxdz[0][2] = -(mc2p_n[27 + R_IDX] - mc2p_n[30 + R_IDX]) / 2 / dzc[2]; + dxdz[1][2] = -(mc2p_n[27 + Z_IDX] - mc2p_n[30 + Z_IDX]) / 2 / dzc[2]; + dxdz[2][2] = -(mc2p_n[27 + PHI_IDX] - mc2p_n[30 + PHI_IDX]) / 2 / dzc[2]; } // Take into account wrapping of cyclic coordinate phi if (dxdz[2][0] < -M_PI) { - dxdz[2][0] += 2*M_PI; + dxdz[2][0] += 2 * M_PI; } else if (dxdz[2][0] > M_PI) { - dxdz[2][0] -= 2*M_PI; + dxdz[2][0] -= 2 * M_PI; } - dxdz[2][0] = dxdz[2][0]/2.0/dzc[0]; + dxdz[2][0] = dxdz[2][0] / 2.0 / dzc[0]; // Use exact expressions for dR/dtheta and dZ/dtheta double *ddtheta_n = gkyl_array_fetch(ddtheta_nodal, gkyl_range_idx(nrange, cidx)); @@ -289,101 +321,133 @@ void gkyl_calc_metric_advance_rz( gkyl_calc_metric *up, struct gkyl_range *nrang // dxdz is in cylindrical coords, calculate J as // J = R(dR/dpsi*dZ/dtheta - dR/dtheta*dZ/dpsi) - double *jFld_n= gkyl_array_fetch(jFld_nodal, gkyl_range_idx(nrange, cidx)); + double *jFld_n = gkyl_array_fetch(jFld_nodal, gkyl_range_idx(nrange, cidx)); double R = mc2p_n[R_IDX]; - jFld_n[0] = sqrt(R*R*( dxdz[0][0]*dxdz[0][0]*dxdz[1][2]*dxdz[1][2] - + dxdz[0][2]*dxdz[0][2]*dxdz[1][0]*dxdz[1][0] - -2*dxdz[0][0]*dxdz[0][2]*dxdz[1][0]*dxdz[1][2] )); + jFld_n[0] = sqrt( + R * R * + (dxdz[0][0] * dxdz[0][0] * dxdz[1][2] * dxdz[1][2] + + dxdz[0][2] * dxdz[0][2] * dxdz[1][0] * dxdz[1][0] - + 2 * dxdz[0][0] * dxdz[0][2] * dxdz[1][0] * dxdz[1][2]) + ); // Calculate dphi/dtheta based on the divergence free condition // on B: 1 = J*B/sqrt(g_33) double *bmag_n = gkyl_array_fetch(bmag_nodal, gkyl_range_idx(nrange, cidx)); - double dphidtheta = (jFld_n[0]*jFld_n[0]*bmag_n[0]*bmag_n[0] - dxdz[0][2]*dxdz[0][2] - dxdz[1][2]*dxdz[1][2])/R/R; + double dphidtheta = (jFld_n[0] * jFld_n[0] * bmag_n[0] * bmag_n[0] - + dxdz[0][2] * dxdz[0][2] - dxdz[1][2] * dxdz[1][2]) / + R / R; dphidtheta = sqrt(dphidtheta); // Recover sign from exact dphidtheta = F(psi)/R/\grad(psi). if (ddtheta_n[2] < 0) { dphidtheta = -dphidtheta; } - double *gFld_n= gkyl_array_fetch(gFld_nodal, gkyl_range_idx(nrange, cidx)); - gFld_n[0] = dxdz[0][0]*dxdz[0][0] + R*R*dxdz[2][0]*dxdz[2][0] + dxdz[1][0]*dxdz[1][0]; - gFld_n[1] = R*R*dxdz[2][0]; - gFld_n[2] = dxdz[0][0]*dxdz[0][2] + R*R*dxdz[2][0]*dphidtheta + dxdz[1][0]*dxdz[1][2]; - gFld_n[3] = R*R; - gFld_n[4] = R*R*dphidtheta; - gFld_n[5] = dxdz[0][2]*dxdz[0][2] + R*R*dphidtheta*dphidtheta + dxdz[1][2]*dxdz[1][2]; + double *gFld_n = gkyl_array_fetch(gFld_nodal, gkyl_range_idx(nrange, cidx)); + gFld_n[0] = + dxdz[0][0] * dxdz[0][0] + R * R * dxdz[2][0] * dxdz[2][0] + dxdz[1][0] * dxdz[1][0]; + gFld_n[1] = R * R * dxdz[2][0]; + gFld_n[2] = + dxdz[0][0] * dxdz[0][2] + R * R * dxdz[2][0] * dphidtheta + dxdz[1][0] * dxdz[1][2]; + gFld_n[3] = R * R; + gFld_n[4] = R * R * dphidtheta; + gFld_n[5] = + dxdz[0][2] * dxdz[0][2] + R * R * dphidtheta * dphidtheta + dxdz[1][2] * dxdz[1][2]; // Calculate cartesian components of bhat - double *bcartFld_n= gkyl_array_fetch(bcartFld_nodal, gkyl_range_idx(nrange, cidx)); + double *bcartFld_n = gkyl_array_fetch(bcartFld_nodal, gkyl_range_idx(nrange, cidx)); double phi = mc2p_n[PHI_IDX]; - double b3 = 1/sqrt(gFld_n[5]); - bcartFld_n[0] = b3*(dxdz[0][2]*cos(phi) - R*sin(phi)*dphidtheta); - bcartFld_n[1] = b3*(dxdz[0][2]*sin(phi) + R*cos(phi)*dphidtheta); - bcartFld_n[2] = b3*(dxdz[1][2]); + double b3 = 1 / sqrt(gFld_n[5]); + bcartFld_n[0] = b3 * (dxdz[0][2] * cos(phi) - R * sin(phi) * dphidtheta); + bcartFld_n[1] = b3 * (dxdz[0][2] * sin(phi) + R * cos(phi) * dphidtheta); + bcartFld_n[2] = b3 * (dxdz[1][2]); // Set cartesian components of tangents and duals double Z = mc2p_n[Z_IDX]; double J = jFld_n[0]; - double *tanvecFld_n= gkyl_array_fetch(tanvecFld_nodal, gkyl_range_idx(nrange, cidx)); - tanvecFld_n[0] = dxdz[0][0]*cos(phi) - R*sin(phi)*dxdz[2][0]; - tanvecFld_n[1] = dxdz[0][0]*sin(phi) + R*cos(phi)*dxdz[2][0]; + double *tanvecFld_n = gkyl_array_fetch(tanvecFld_nodal, gkyl_range_idx(nrange, cidx)); + tanvecFld_n[0] = dxdz[0][0] * cos(phi) - R * sin(phi) * dxdz[2][0]; + tanvecFld_n[1] = dxdz[0][0] * sin(phi) + R * cos(phi) * dxdz[2][0]; tanvecFld_n[2] = dxdz[1][0]; - tanvecFld_n[3] = +R*sin(phi); - tanvecFld_n[4] = -R*cos(phi); - tanvecFld_n[5] = 0.0; + tanvecFld_n[3] = +R * sin(phi); + tanvecFld_n[4] = -R * cos(phi); + tanvecFld_n[5] = 0.0; - tanvecFld_n[6] = dxdz[0][2]*cos(phi) - R*sin(phi)*dphidtheta; - tanvecFld_n[7] = dxdz[0][2]*sin(phi) + R*cos(phi)*dphidtheta; + tanvecFld_n[6] = dxdz[0][2] * cos(phi) - R * sin(phi) * dphidtheta; + tanvecFld_n[7] = dxdz[0][2] * sin(phi) + R * cos(phi) * dphidtheta; tanvecFld_n[8] = dxdz[1][2]; - double *dualFld_n= gkyl_array_fetch(dualFld_nodal, gkyl_range_idx(nrange, cidx)); - dualFld_n[0] = -R/J*cos(phi)*dxdz[1][2]; - dualFld_n[1] = -R/J*sin(phi)*dxdz[1][2]; - dualFld_n[2] = +R/J*dxdz[0][2]; - - dualFld_n[3] = 1/J * ( dxdz[1][0]*dxdz[0][2]*sin(phi) + dxdz[1][0]*R*cos(phi)*dphidtheta - -dxdz[1][2]*dxdz[0][0]*sin(phi) - dxdz[1][2]*R*cos(phi)*dxdz[2][0] ); - dualFld_n[4] = -1/J * ( dxdz[1][0]*dxdz[0][2]*cos(phi) + dxdz[1][0]*R*sin(phi)*dphidtheta - -dxdz[1][2]*dxdz[0][0]*cos(phi) - dxdz[1][2]*R*sin(phi)*dxdz[2][0] ); - dualFld_n[5] = R/J * ( dxdz[0][2]*dxdz[2][0] - dxdz[0][0]*dphidtheta); - - dualFld_n[6] = +R/J*cos(phi)*dxdz[1][0]; - dualFld_n[7] = +R/J*sin(phi)*dxdz[1][0]; - dualFld_n[8] = -R/J*dxdz[0][0]; - - double norm1 = sqrt(dualFld_n[0]*dualFld_n[0] + dualFld_n[1]*dualFld_n[1] + dualFld_n[2]*dualFld_n[2]); - double norm2 = sqrt(dualFld_n[3]*dualFld_n[3] + dualFld_n[4]*dualFld_n[4] + dualFld_n[5]*dualFld_n[5]); - double norm3 = sqrt(dualFld_n[6]*dualFld_n[6] + dualFld_n[7]*dualFld_n[7] + dualFld_n[8]*dualFld_n[8]); + double *dualFld_n = gkyl_array_fetch(dualFld_nodal, gkyl_range_idx(nrange, cidx)); + dualFld_n[0] = -R / J * cos(phi) * dxdz[1][2]; + dualFld_n[1] = -R / J * sin(phi) * dxdz[1][2]; + dualFld_n[2] = +R / J * dxdz[0][2]; + + dualFld_n[3] = + 1 / J * + (dxdz[1][0] * dxdz[0][2] * sin(phi) + dxdz[1][0] * R * cos(phi) * dphidtheta - + dxdz[1][2] * dxdz[0][0] * sin(phi) - dxdz[1][2] * R * cos(phi) * dxdz[2][0]); + dualFld_n[4] = + -1 / J * + (dxdz[1][0] * dxdz[0][2] * cos(phi) + dxdz[1][0] * R * sin(phi) * dphidtheta - + dxdz[1][2] * dxdz[0][0] * cos(phi) - dxdz[1][2] * R * sin(phi) * dxdz[2][0]); + dualFld_n[5] = R / J * (dxdz[0][2] * dxdz[2][0] - dxdz[0][0] * dphidtheta); + + dualFld_n[6] = +R / J * cos(phi) * dxdz[1][0]; + dualFld_n[7] = +R / J * sin(phi) * dxdz[1][0]; + dualFld_n[8] = -R / J * dxdz[0][0]; + + double norm1 = sqrt( + dualFld_n[0] * dualFld_n[0] + dualFld_n[1] * dualFld_n[1] + dualFld_n[2] * dualFld_n[2] + ); + double norm2 = sqrt( + dualFld_n[3] * dualFld_n[3] + dualFld_n[4] * dualFld_n[4] + dualFld_n[5] * dualFld_n[5] + ); + double norm3 = sqrt( + dualFld_n[6] * dualFld_n[6] + dualFld_n[7] * dualFld_n[7] + dualFld_n[8] * dualFld_n[8] + ); double *dualmagFld_n = gkyl_array_fetch(dualmagFld_nodal, gkyl_range_idx(nrange, cidx)); dualmagFld_n[0] = norm1; dualmagFld_n[1] = norm2; dualmagFld_n[2] = norm3; - + // Set normal vectors double *normFld_n = gkyl_array_fetch(normFld_nodal, gkyl_range_idx(nrange, cidx)); - normFld_n[0] = dualFld_n[0]/norm1; - normFld_n[1] = dualFld_n[1]/norm1; - normFld_n[2] = dualFld_n[2]/norm1; + normFld_n[0] = dualFld_n[0] / norm1; + normFld_n[1] = dualFld_n[1] / norm1; + normFld_n[2] = dualFld_n[2] / norm1; - normFld_n[3] = dualFld_n[3]/norm2; - normFld_n[4] = dualFld_n[4]/norm2; - normFld_n[5] = dualFld_n[5]/norm2; + normFld_n[3] = dualFld_n[3] / norm2; + normFld_n[4] = dualFld_n[4] / norm2; + normFld_n[5] = dualFld_n[5] / norm2; - normFld_n[6] = dualFld_n[6]/norm3; - normFld_n[7] = dualFld_n[7]/norm3; - normFld_n[8] = dualFld_n[8]/norm3; + normFld_n[6] = dualFld_n[6] / norm3; + normFld_n[7] = dualFld_n[7] / norm3; + normFld_n[8] = dualFld_n[8] / norm3; } } } - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 6, gFld_nodal, gFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 1, jFld_nodal, jFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 3, bcartFld_nodal, bcartFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, tanvecFld_nodal, tanvecFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, dualFld_nodal, dualFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 3, dualmagFld_nodal, dualmagFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, normFld_nodal, normFld, false); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 6, gFld_nodal, gFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 1, jFld_nodal, jFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 3, bcartFld_nodal, bcartFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, tanvecFld_nodal, tanvecFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, dualFld_nodal, dualFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 3, dualmagFld_nodal, dualmagFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, normFld_nodal, normFld, false + ); gkyl_array_release(gFld_nodal); gkyl_array_release(jFld_nodal); gkyl_array_release(bcartFld_nodal); @@ -393,53 +457,69 @@ void gkyl_calc_metric_advance_rz( gkyl_calc_metric *up, struct gkyl_range *nrang gkyl_array_release(normFld_nodal); } -void -gkyl_calc_metric_advance_rz_interior(gkyl_calc_metric *up, struct gk_geometry *gk_geom) +void gkyl_calc_metric_advance_rz_interior(gkyl_calc_metric *up, struct gk_geometry *gk_geom) { enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { R_IDX, Z_IDX, PHI_IDX }; // arrangement of cartesian coordinates int cidx[3]; - for(int ia=gk_geom->nrange_int.lower[AL_IDX]; ia<=gk_geom->nrange_int.upper[AL_IDX]; ++ia){ - for (int ip=gk_geom->nrange_int.lower[PSI_IDX]; ip<=gk_geom->nrange_int.upper[PSI_IDX]; ++ip) { - for (int it=gk_geom->nrange_int.lower[TH_IDX]; it<=gk_geom->nrange_int.upper[TH_IDX]; ++it) { + for (int ia = gk_geom->nrange_int.lower[AL_IDX]; ia <= gk_geom->nrange_int.upper[AL_IDX]; ++ia) { + for (int ip = gk_geom->nrange_int.lower[PSI_IDX]; ip <= gk_geom->nrange_int.upper[PSI_IDX]; + ++ip) { + for (int it = gk_geom->nrange_int.lower[TH_IDX]; it <= gk_geom->nrange_int.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - const double *mc2p_n = gkyl_array_cfetch(gk_geom->geo_int.mc2p_nodal_fd, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + const double *mc2p_n = gkyl_array_cfetch( + gk_geom->geo_int.mc2p_nodal_fd, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); double dxdz[3][3]; - dxdz[0][0] = -(mc2p_n[3 +R_IDX] - mc2p_n[6+R_IDX])/2/gk_geom->dzc[0]; - dxdz[1][0] = -(mc2p_n[3 +Z_IDX] - mc2p_n[6+Z_IDX])/2/gk_geom->dzc[0]; - dxdz[2][0] = -(mc2p_n[3 +PHI_IDX] - mc2p_n[6+PHI_IDX]); + dxdz[0][0] = -(mc2p_n[3 + R_IDX] - mc2p_n[6 + R_IDX]) / 2 / gk_geom->dzc[0]; + dxdz[1][0] = -(mc2p_n[3 + Z_IDX] - mc2p_n[6 + Z_IDX]) / 2 / gk_geom->dzc[0]; + dxdz[2][0] = -(mc2p_n[3 + PHI_IDX] - mc2p_n[6 + PHI_IDX]); // Take into account wrapping of cyclic coordinate phi if (dxdz[2][0] < -M_PI) { - dxdz[2][0] += 2*M_PI; + dxdz[2][0] += 2 * M_PI; } else if (dxdz[2][0] > M_PI) { - dxdz[2][0] -= 2*M_PI; + dxdz[2][0] -= 2 * M_PI; } - dxdz[2][0] = dxdz[2][0]/2.0/gk_geom->dzc[0]; + dxdz[2][0] = dxdz[2][0] / 2.0 / gk_geom->dzc[0]; // Use exact expressions for dR/dtheta and dZ/dtheta - double *ddtheta_n = gkyl_array_fetch(gk_geom->geo_int.ddtheta_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *ddtheta_n = gkyl_array_fetch( + gk_geom->geo_int.ddtheta_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); dxdz[0][2] = ddtheta_n[0]; dxdz[1][2] = ddtheta_n[1]; // Get position map deriv for psi - double *ddpsi_n = gkyl_array_fetch(gk_geom->geo_int.ddpsi_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *ddpsi_n = gkyl_array_fetch( + gk_geom->geo_int.ddpsi_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); // dxdz is in cylindrical coords, calculate J as // J = R(dR/dpsi*dZ/dtheta - dR/dtheta*dZ/dpsi) - double *jFld_n= gkyl_array_fetch(gk_geom->geo_int.jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *jFld_n = gkyl_array_fetch( + gk_geom->geo_int.jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); double R = mc2p_n[R_IDX]; - jFld_n[0] = sqrt(R*R*( dxdz[0][0]*dxdz[0][0]*dxdz[1][2]*dxdz[1][2] - + dxdz[0][2]*dxdz[0][2]*dxdz[1][0]*dxdz[1][0] - -2*dxdz[0][0]*dxdz[0][2]*dxdz[1][0]*dxdz[1][2] )) ; + jFld_n[0] = sqrt( + R * R * + (dxdz[0][0] * dxdz[0][0] * dxdz[1][2] * dxdz[1][2] + + dxdz[0][2] * dxdz[0][2] * dxdz[1][0] * dxdz[1][0] - + 2 * dxdz[0][0] * dxdz[0][2] * dxdz[1][0] * dxdz[1][2]) + ); // Calculate dphi/dtheta based on the divergence free condition // on B: 1 = J*B/sqrt(g_33) - double *bmag_n = gkyl_array_fetch(gk_geom->geo_int.bmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double dphidtheta = (jFld_n[0]*jFld_n[0]*bmag_n[0]*bmag_n[0]/ddpsi_n[0]/ddpsi_n[0] - dxdz[0][2]*dxdz[0][2] - dxdz[1][2]*dxdz[1][2])/R/R; + double *bmag_n = + gkyl_array_fetch(gk_geom->geo_int.bmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double dphidtheta = + (jFld_n[0] * jFld_n[0] * bmag_n[0] * bmag_n[0] / ddpsi_n[0] / ddpsi_n[0] - + dxdz[0][2] * dxdz[0][2] - dxdz[1][2] * dxdz[1][2]) / + R / R; // Argument is >= 0 analytically; clamp away roundoff so sqrt does not return NaN. dphidtheta = sqrt(fmax(0.0, dphidtheta)); // Recover sign from exact dphidtheta = F(psi)/R/\grad(psi). @@ -451,124 +531,194 @@ gkyl_calc_metric_advance_rz_interior(gkyl_calc_metric *up, struct gk_geometry *g // cmag comes out fine without directtly enforcing the condition //double dphidtheta = ddtheta_n[2]; - double *gFld_n= gkyl_array_fetch(gk_geom->geo_int.g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - gFld_n[0] = dxdz[0][0]*dxdz[0][0] + R*R*dxdz[2][0]*dxdz[2][0] + dxdz[1][0]*dxdz[1][0]; - gFld_n[1] = R*R*dxdz[2][0]; - gFld_n[2] = dxdz[0][0]*dxdz[0][2] + R*R*dxdz[2][0]*dphidtheta + dxdz[1][0]*dxdz[1][2]; - gFld_n[3] = R*R; - gFld_n[4] = R*R*dphidtheta; - gFld_n[5] = dxdz[0][2]*dxdz[0][2] + R*R*dphidtheta*dphidtheta + dxdz[1][2]*dxdz[1][2]; + double *gFld_n = + gkyl_array_fetch(gk_geom->geo_int.g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + gFld_n[0] = + dxdz[0][0] * dxdz[0][0] + R * R * dxdz[2][0] * dxdz[2][0] + dxdz[1][0] * dxdz[1][0]; + gFld_n[1] = R * R * dxdz[2][0]; + gFld_n[2] = + dxdz[0][0] * dxdz[0][2] + R * R * dxdz[2][0] * dphidtheta + dxdz[1][0] * dxdz[1][2]; + gFld_n[3] = R * R; + gFld_n[4] = R * R * dphidtheta; + gFld_n[5] = + dxdz[0][2] * dxdz[0][2] + R * R * dphidtheta * dphidtheta + dxdz[1][2] * dxdz[1][2]; // Calculate cartesian components of bhat - double *bcartFld_n= gkyl_array_fetch(gk_geom->geo_int.bcart_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *bcartFld_n = gkyl_array_fetch( + gk_geom->geo_int.bcart_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); double phi = mc2p_n[PHI_IDX]; - double b3 = 1/sqrt(gFld_n[5]); - bcartFld_n[0] = b3*(dxdz[0][2]*cos(phi) - R*sin(phi)*dphidtheta); - bcartFld_n[1] = b3*(dxdz[0][2]*sin(phi) + R*cos(phi)*dphidtheta); - bcartFld_n[2] = b3*(dxdz[1][2]); + double b3 = 1 / sqrt(gFld_n[5]); + bcartFld_n[0] = b3 * (dxdz[0][2] * cos(phi) - R * sin(phi) * dphidtheta); + bcartFld_n[1] = b3 * (dxdz[0][2] * sin(phi) + R * cos(phi) * dphidtheta); + bcartFld_n[2] = b3 * (dxdz[1][2]); // Set cartesian components of tangents and duals double Z = mc2p_n[Z_IDX]; double J = jFld_n[0]; - double *tanvecFld_n= gkyl_array_fetch(gk_geom->geo_int.dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - tanvecFld_n[0] = dxdz[0][0]*cos(phi) - R*sin(phi)*dxdz[2][0]; - tanvecFld_n[1] = dxdz[0][0]*sin(phi) + R*cos(phi)*dxdz[2][0]; + double *tanvecFld_n = + gkyl_array_fetch(gk_geom->geo_int.dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + tanvecFld_n[0] = dxdz[0][0] * cos(phi) - R * sin(phi) * dxdz[2][0]; + tanvecFld_n[1] = dxdz[0][0] * sin(phi) + R * cos(phi) * dxdz[2][0]; tanvecFld_n[2] = dxdz[1][0]; - tanvecFld_n[3] = -R*sin(phi); - tanvecFld_n[4] = +R*cos(phi); - tanvecFld_n[5] = 0.0; + tanvecFld_n[3] = -R * sin(phi); + tanvecFld_n[4] = +R * cos(phi); + tanvecFld_n[5] = 0.0; - tanvecFld_n[6] = dxdz[0][2]*cos(phi) - R*sin(phi)*dphidtheta; - tanvecFld_n[7] = dxdz[0][2]*sin(phi) + R*cos(phi)*dphidtheta; + tanvecFld_n[6] = dxdz[0][2] * cos(phi) - R * sin(phi) * dphidtheta; + tanvecFld_n[7] = dxdz[0][2] * sin(phi) + R * cos(phi) * dphidtheta; tanvecFld_n[8] = dxdz[1][2]; - double *dualFld_n= gkyl_array_fetch(gk_geom->geo_int.dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - dualFld_n[0] = +R/J*cos(phi)*dxdz[1][2]; - dualFld_n[1] = +R/J*sin(phi)*dxdz[1][2]; - dualFld_n[2] = -R/J*dxdz[0][2]; - - dualFld_n[3] = 1/J * ( dxdz[1][0]*dxdz[0][2]*sin(phi) + dxdz[1][0]*R*cos(phi)*dphidtheta - -dxdz[1][2]*dxdz[0][0]*sin(phi) - dxdz[1][2]*R*cos(phi)*dxdz[2][0] ); - dualFld_n[4] = -1/J * ( dxdz[1][0]*dxdz[0][2]*cos(phi) - dxdz[1][0]*R*sin(phi)*dphidtheta - -dxdz[1][2]*dxdz[0][0]*cos(phi) + dxdz[1][2]*R*sin(phi)*dxdz[2][0] ); - dualFld_n[5] = R/J * ( dxdz[0][2]*dxdz[2][0] - dxdz[0][0]*dphidtheta); - - dualFld_n[6] = -R/J*cos(phi)*dxdz[1][0]; - dualFld_n[7] = -R/J*sin(phi)*dxdz[1][0]; - dualFld_n[8] = +R/J*dxdz[0][0]; + double *dualFld_n = + gkyl_array_fetch(gk_geom->geo_int.dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + dualFld_n[0] = +R / J * cos(phi) * dxdz[1][2]; + dualFld_n[1] = +R / J * sin(phi) * dxdz[1][2]; + dualFld_n[2] = -R / J * dxdz[0][2]; + + dualFld_n[3] = + 1 / J * + (dxdz[1][0] * dxdz[0][2] * sin(phi) + dxdz[1][0] * R * cos(phi) * dphidtheta - + dxdz[1][2] * dxdz[0][0] * sin(phi) - dxdz[1][2] * R * cos(phi) * dxdz[2][0]); + dualFld_n[4] = + -1 / J * + (dxdz[1][0] * dxdz[0][2] * cos(phi) - dxdz[1][0] * R * sin(phi) * dphidtheta - + dxdz[1][2] * dxdz[0][0] * cos(phi) + dxdz[1][2] * R * sin(phi) * dxdz[2][0]); + dualFld_n[5] = R / J * (dxdz[0][2] * dxdz[2][0] - dxdz[0][0] * dphidtheta); + + dualFld_n[6] = -R / J * cos(phi) * dxdz[1][0]; + dualFld_n[7] = -R / J * sin(phi) * dxdz[1][0]; + dualFld_n[8] = +R / J * dxdz[0][0]; // Check that the coordinate system has tangent/dual vectors // satisfying orthonormality, and that it's right handed. check_orthonormality(tanvecFld_n, dualFld_n, up->exit_at_checks); check_right_handed(tanvecFld_n, dualFld_n, up->exit_at_checks); - double norm1 = sqrt(dualFld_n[0]*dualFld_n[0] + dualFld_n[1]*dualFld_n[1] + dualFld_n[2]*dualFld_n[2]); - double norm2 = sqrt(dualFld_n[3]*dualFld_n[3] + dualFld_n[4]*dualFld_n[4] + dualFld_n[5]*dualFld_n[5]); - double norm3 = sqrt(dualFld_n[6]*dualFld_n[6] + dualFld_n[7]*dualFld_n[7] + dualFld_n[8]*dualFld_n[8]); - - double *dualmagFld_n = gkyl_array_fetch(gk_geom->geo_int.dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double norm1 = sqrt( + dualFld_n[0] * dualFld_n[0] + dualFld_n[1] * dualFld_n[1] + dualFld_n[2] * dualFld_n[2] + ); + double norm2 = sqrt( + dualFld_n[3] * dualFld_n[3] + dualFld_n[4] * dualFld_n[4] + dualFld_n[5] * dualFld_n[5] + ); + double norm3 = sqrt( + dualFld_n[6] * dualFld_n[6] + dualFld_n[7] * dualFld_n[7] + dualFld_n[8] * dualFld_n[8] + ); + + double *dualmagFld_n = gkyl_array_fetch( + gk_geom->geo_int.dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); dualmagFld_n[0] = norm1; dualmagFld_n[1] = norm2; dualmagFld_n[2] = norm3; - - // Set normal vectors - double *normFld_n = gkyl_array_fetch(gk_geom->geo_int.normals_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - normFld_n[0] = dualFld_n[0]/norm1; - normFld_n[1] = dualFld_n[1]/norm1; - normFld_n[2] = dualFld_n[2]/norm1; - - normFld_n[3] = dualFld_n[3]/norm2; - normFld_n[4] = dualFld_n[4]/norm2; - normFld_n[5] = dualFld_n[5]/norm2; - - normFld_n[6] = dualFld_n[6]/norm3; - normFld_n[7] = dualFld_n[7]/norm3; - normFld_n[8] = dualFld_n[8]/norm3; - - // Set e^m \dot curl(bhat) - double *curlbhat_n = gkyl_array_fetch(gk_geom->geo_int.curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *dualcurlbhat_n = gkyl_array_fetch(gk_geom->geo_int.dualcurlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - dualcurlbhat_n[0] = dualFld_n[0]*curlbhat_n[0] + dualFld_n[1]*curlbhat_n[1] + dualFld_n[2]*curlbhat_n[2]; - dualcurlbhat_n[1] = dualFld_n[3]*curlbhat_n[0] + dualFld_n[4]*curlbhat_n[1] + dualFld_n[5]*curlbhat_n[2]; - dualcurlbhat_n[2] = dualFld_n[6]*curlbhat_n[0] + dualFld_n[7]*curlbhat_n[1] + dualFld_n[8]*curlbhat_n[2]; - - // Set e^3 \dot B - double *B3_n = gkyl_array_fetch(gk_geom->geo_int.B3_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - B3_n[0] = bmag_n[0]/sqrt(gFld_n[5]); + // Set normal vectors + double *normFld_n = gkyl_array_fetch( + gk_geom->geo_int.normals_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + normFld_n[0] = dualFld_n[0] / norm1; + normFld_n[1] = dualFld_n[1] / norm1; + normFld_n[2] = dualFld_n[2] / norm1; + + normFld_n[3] = dualFld_n[3] / norm2; + normFld_n[4] = dualFld_n[4] / norm2; + normFld_n[5] = dualFld_n[5] / norm2; + + normFld_n[6] = dualFld_n[6] / norm3; + normFld_n[7] = dualFld_n[7] / norm3; + normFld_n[8] = dualFld_n[8] / norm3; + + // Set e^m \dot curl(bhat) + double *curlbhat_n = gkyl_array_fetch( + gk_geom->geo_int.curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + double *dualcurlbhat_n = gkyl_array_fetch( + gk_geom->geo_int.dualcurlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + dualcurlbhat_n[0] = dualFld_n[0] * curlbhat_n[0] + dualFld_n[1] * curlbhat_n[1] + + dualFld_n[2] * curlbhat_n[2]; + dualcurlbhat_n[1] = dualFld_n[3] * curlbhat_n[0] + dualFld_n[4] * curlbhat_n[1] + + dualFld_n[5] * curlbhat_n[2]; + dualcurlbhat_n[2] = dualFld_n[6] * curlbhat_n[0] + dualFld_n[7] * curlbhat_n[1] + + dualFld_n[8] * curlbhat_n[2]; + + // Set e^3 \dot B + double *B3_n = + gkyl_array_fetch(gk_geom->geo_int.B3_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + B3_n[0] = bmag_n[0] / sqrt(gFld_n[5]); // set e^3 \dot B /|B| - double *dualcurlbhatoverB_n = gkyl_array_fetch(gk_geom->geo_int.dualcurlbhatoverB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - dualcurlbhatoverB_n[0] = dualcurlbhat_n[0]/bmag_n[0]; - dualcurlbhatoverB_n[1] = dualcurlbhat_n[1]/bmag_n[0]; - dualcurlbhatoverB_n[2] = dualcurlbhat_n[2]/bmag_n[0]; + double *dualcurlbhatoverB_n = gkyl_array_fetch( + gk_geom->geo_int.dualcurlbhatoverB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + dualcurlbhatoverB_n[0] = dualcurlbhat_n[0] / bmag_n[0]; + dualcurlbhatoverB_n[1] = dualcurlbhat_n[1] / bmag_n[0]; + dualcurlbhatoverB_n[2] = dualcurlbhat_n[2] / bmag_n[0]; // set B^3/B = 1/sqrt(g_33) - double *rtg33inv_n = gkyl_array_fetch(gk_geom->geo_int.rtg33inv_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - rtg33inv_n[0] = 1.0/sqrt(gFld_n[5]); + double *rtg33inv_n = gkyl_array_fetch( + gk_geom->geo_int.rtg33inv_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + rtg33inv_n[0] = 1.0 / sqrt(gFld_n[5]); // set b_i/JB - double* bioverJB_n = gkyl_array_fetch(gk_geom->geo_int.bioverJB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - bioverJB_n[0] = gFld_n[2]/sqrt(gFld_n[5])/J/bmag_n[0]; - bioverJB_n[1] = gFld_n[4]/sqrt(gFld_n[5])/J/bmag_n[0]; - bioverJB_n[2] = gFld_n[5]/sqrt(gFld_n[5])/J/bmag_n[0]; - + double *bioverJB_n = gkyl_array_fetch( + gk_geom->geo_int.bioverJB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + bioverJB_n[0] = gFld_n[2] / sqrt(gFld_n[5]) / J / bmag_n[0]; + bioverJB_n[1] = gFld_n[4] / sqrt(gFld_n[5]) / J / bmag_n[0]; + bioverJB_n[2] = gFld_n[5] / sqrt(gFld_n[5]) / J / bmag_n[0]; } } } - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 6, gk_geom->geo_int.g_ij_nodal, gk_geom->geo_int.g_ij, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.jacobgeo_nodal, gk_geom->geo_int.jacobgeo, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.bcart_nodal, gk_geom->geo_int.bcart, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, gk_geom->geo_int.dxdz_nodal, gk_geom->geo_int.dxdz, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, gk_geom->geo_int.dzdx_nodal, gk_geom->geo_int.dzdx, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.dualmag_nodal, gk_geom->geo_int.dualmag, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, gk_geom->geo_int.normals_nodal, gk_geom->geo_int.normals, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.dualcurlbhat_nodal, gk_geom->geo_int.dualcurlbhat, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.dualcurlbhatoverB_nodal, gk_geom->geo_int.dualcurlbhatoverB, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.rtg33inv_nodal, gk_geom->geo_int.rtg33inv, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.bioverJB_nodal, gk_geom->geo_int.bioverJB, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.B3_nodal, gk_geom->geo_int.B3, true); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 6, + gk_geom->geo_int.g_ij_nodal, gk_geom->geo_int.g_ij, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.jacobgeo_nodal, gk_geom->geo_int.jacobgeo, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.bcart_nodal, gk_geom->geo_int.bcart, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, + gk_geom->geo_int.dxdz_nodal, gk_geom->geo_int.dxdz, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, + gk_geom->geo_int.dzdx_nodal, gk_geom->geo_int.dzdx, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.dualmag_nodal, gk_geom->geo_int.dualmag, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, + gk_geom->geo_int.normals_nodal, gk_geom->geo_int.normals, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.dualcurlbhat_nodal, gk_geom->geo_int.dualcurlbhat, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.dualcurlbhatoverB_nodal, gk_geom->geo_int.dualcurlbhatoverB, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.rtg33inv_nodal, gk_geom->geo_int.rtg33inv, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.bioverJB_nodal, gk_geom->geo_int.bioverJB, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.B3_nodal, gk_geom->geo_int.B3, true + ); } void gkyl_calc_metric_advance_rz_surface(gkyl_calc_metric *up, int dir, struct gk_geometry *gk_geom) @@ -576,58 +726,81 @@ void gkyl_calc_metric_advance_rz_surface(gkyl_calc_metric *up, int dir, struct g enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { R_IDX, Z_IDX, PHI_IDX }; // arrangement of cartesian coordinates int cidx[3]; - for(int ia=gk_geom->nrange_surf[dir].lower[AL_IDX]; ia<=gk_geom->nrange_surf[dir].upper[AL_IDX]; ++ia){ - for (int ip=gk_geom->nrange_surf[dir].lower[PSI_IDX]; ip<=gk_geom->nrange_surf[dir].upper[PSI_IDX]; ++ip) { - for (int it=gk_geom->nrange_surf[dir].lower[TH_IDX]; it<=gk_geom->nrange_surf[dir].upper[TH_IDX]; ++it) { + for (int ia = gk_geom->nrange_surf[dir].lower[AL_IDX]; + ia <= gk_geom->nrange_surf[dir].upper[AL_IDX]; ++ia) { + for (int ip = gk_geom->nrange_surf[dir].lower[PSI_IDX]; + ip <= gk_geom->nrange_surf[dir].upper[PSI_IDX]; ++ip) { + for (int it = gk_geom->nrange_surf[dir].lower[TH_IDX]; + it <= gk_geom->nrange_surf[dir].upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - const double *mc2p_n = gkyl_array_cfetch(gk_geom->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + const double *mc2p_n = gkyl_array_cfetch( + gk_geom->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); double dxdz[3][3]; - if((ip == gk_geom->nrange_surf[dir].lower[PSI_IDX]) && (up->local.lower[PSI_IDX]== up->global.lower[PSI_IDX]) && dir==0) { - dxdz[0][0] = (-3*mc2p_n[R_IDX] + 4*mc2p_n[6+R_IDX] - mc2p_n[12+R_IDX] )/gk_geom->dzc[0]/2; - dxdz[1][0] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[6+Z_IDX] - mc2p_n[12+Z_IDX] )/gk_geom->dzc[0]/2; - dxdz[2][0] = (-3*mc2p_n[PHI_IDX] + 4*mc2p_n[6+PHI_IDX] - mc2p_n[12+PHI_IDX] ); - } - else if((ip == gk_geom->nrange_surf[dir].upper[PSI_IDX]) && (up->local.upper[PSI_IDX]== up->global.upper[PSI_IDX]) && dir==0) { - dxdz[0][0] = (3*mc2p_n[R_IDX] - 4*mc2p_n[3+R_IDX] + mc2p_n[9+R_IDX] )/gk_geom->dzc[0]/2; - dxdz[1][0] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[3+Z_IDX] + mc2p_n[9+Z_IDX] )/gk_geom->dzc[0]/2; - dxdz[2][0] = (3*mc2p_n[PHI_IDX] - 4*mc2p_n[3+PHI_IDX] + mc2p_n[9+PHI_IDX] ); - } - else { - dxdz[0][0] = -(mc2p_n[3 +R_IDX] - mc2p_n[6+R_IDX])/2/gk_geom->dzc[0]; - dxdz[1][0] = -(mc2p_n[3 +Z_IDX] - mc2p_n[6+Z_IDX])/2/gk_geom->dzc[0]; - dxdz[2][0] = -(mc2p_n[3 +PHI_IDX] - mc2p_n[6+PHI_IDX]); + if ((ip == gk_geom->nrange_surf[dir].lower[PSI_IDX]) && + (up->local.lower[PSI_IDX] == up->global.lower[PSI_IDX]) && dir == 0) { + dxdz[0][0] = + (-3 * mc2p_n[R_IDX] + 4 * mc2p_n[6 + R_IDX] - mc2p_n[12 + R_IDX]) / gk_geom->dzc[0] / 2; + dxdz[1][0] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[6 + Z_IDX] - mc2p_n[12 + Z_IDX]) / gk_geom->dzc[0] / 2; + dxdz[2][0] = (-3 * mc2p_n[PHI_IDX] + 4 * mc2p_n[6 + PHI_IDX] - mc2p_n[12 + PHI_IDX]); + } else if ((ip == gk_geom->nrange_surf[dir].upper[PSI_IDX]) && + (up->local.upper[PSI_IDX] == up->global.upper[PSI_IDX]) && dir == 0) { + dxdz[0][0] = + (3 * mc2p_n[R_IDX] - 4 * mc2p_n[3 + R_IDX] + mc2p_n[9 + R_IDX]) / gk_geom->dzc[0] / 2; + dxdz[1][0] = + (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[3 + Z_IDX] + mc2p_n[9 + Z_IDX]) / gk_geom->dzc[0] / 2; + dxdz[2][0] = (3 * mc2p_n[PHI_IDX] - 4 * mc2p_n[3 + PHI_IDX] + mc2p_n[9 + PHI_IDX]); + } else { + dxdz[0][0] = -(mc2p_n[3 + R_IDX] - mc2p_n[6 + R_IDX]) / 2 / gk_geom->dzc[0]; + dxdz[1][0] = -(mc2p_n[3 + Z_IDX] - mc2p_n[6 + Z_IDX]) / 2 / gk_geom->dzc[0]; + dxdz[2][0] = -(mc2p_n[3 + PHI_IDX] - mc2p_n[6 + PHI_IDX]); } // Take into account wrapping of cyclic coordinate phi if (dxdz[2][0] < -M_PI) { - dxdz[2][0] += 2*M_PI; + dxdz[2][0] += 2 * M_PI; } else if (dxdz[2][0] > M_PI) { - dxdz[2][0] -= 2*M_PI; + dxdz[2][0] -= 2 * M_PI; } - dxdz[2][0] = dxdz[2][0]/2.0/gk_geom->dzc[0]; + dxdz[2][0] = dxdz[2][0] / 2.0 / gk_geom->dzc[0]; // Use exact expressions for dR/dtheta and dZ/dtheta - double *ddtheta_n = gkyl_array_fetch(gk_geom->geo_surf[dir].ddtheta_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + double *ddtheta_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].ddtheta_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); dxdz[0][2] = ddtheta_n[0]; // dR/dtheta dxdz[1][2] = ddtheta_n[1]; // dZ/dtheta // Get position map deriv for psi - double *ddpsi_n = gkyl_array_fetch(gk_geom->geo_surf[dir].ddpsi_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + double *ddpsi_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].ddpsi_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); // dxdz is in cylindrical coords, calculate J as // J = R(dR/dpsi*dZ/dtheta - dR/dtheta*dZ/dpsi) - double *jFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + double *jFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); double R = mc2p_n[R_IDX]; - jFld_n[0] = sqrt(R*R*( dxdz[0][0]*dxdz[0][0]*dxdz[1][2]*dxdz[1][2] - + dxdz[0][2]*dxdz[0][2]*dxdz[1][0]*dxdz[1][0] - -2*dxdz[0][0]*dxdz[0][2]*dxdz[1][0]*dxdz[1][2] )) ; + jFld_n[0] = sqrt( + R * R * + (dxdz[0][0] * dxdz[0][0] * dxdz[1][2] * dxdz[1][2] + + dxdz[0][2] * dxdz[0][2] * dxdz[1][0] * dxdz[1][0] - + 2 * dxdz[0][0] * dxdz[0][2] * dxdz[1][0] * dxdz[1][2]) + ); // Calculate dphi/dtheta based on the divergence free condition // on B: 1 = J*B/sqrt(g_33) - double *bmag_n = gkyl_array_fetch(gk_geom->geo_surf[dir].bmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double dphidtheta = (jFld_n[0]*jFld_n[0]*bmag_n[0]*bmag_n[0]/ddpsi_n[0]/ddpsi_n[0] - dxdz[0][2]*dxdz[0][2] - dxdz[1][2]*dxdz[1][2])/R/R; + double *bmag_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].bmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double dphidtheta = + (jFld_n[0] * jFld_n[0] * bmag_n[0] * bmag_n[0] / ddpsi_n[0] / ddpsi_n[0] - + dxdz[0][2] * dxdz[0][2] - dxdz[1][2] * dxdz[1][2]) / + R / R; // Argument is >= 0 analytically; clamp away roundoff so sqrt does not return NaN. dphidtheta = sqrt(fmax(0.0, dphidtheta)); // Recover sign from exact dphidtheta = F(psi)/R/\grad(psi). @@ -635,138 +808,185 @@ void gkyl_calc_metric_advance_rz_surface(gkyl_calc_metric *up, int dir, struct g dphidtheta = -dphidtheta; } - double *gFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - gFld_n[0] = dxdz[0][0]*dxdz[0][0] + R*R*dxdz[2][0]*dxdz[2][0] + dxdz[1][0]*dxdz[1][0]; - gFld_n[1] = R*R*dxdz[2][0]; - gFld_n[2] = dxdz[0][0]*dxdz[0][2] + R*R*dxdz[2][0]*dphidtheta + dxdz[1][0]*dxdz[1][2]; - gFld_n[3] = R*R; - gFld_n[4] = R*R*dphidtheta; - gFld_n[5] = dxdz[0][2]*dxdz[0][2] + R*R*dphidtheta*dphidtheta + dxdz[1][2]*dxdz[1][2]; + double *gFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + gFld_n[0] = + dxdz[0][0] * dxdz[0][0] + R * R * dxdz[2][0] * dxdz[2][0] + dxdz[1][0] * dxdz[1][0]; + gFld_n[1] = R * R * dxdz[2][0]; + gFld_n[2] = + dxdz[0][0] * dxdz[0][2] + R * R * dxdz[2][0] * dphidtheta + dxdz[1][0] * dxdz[1][2]; + gFld_n[3] = R * R; + gFld_n[4] = R * R * dphidtheta; + gFld_n[5] = + dxdz[0][2] * dxdz[0][2] + R * R * dphidtheta * dphidtheta + dxdz[1][2] * dxdz[1][2]; // Calculate cmag, bi, and jtot_inv - double *biFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].b_i_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - biFld_n[0] = gFld_n[2]/sqrt(gFld_n[5]); - biFld_n[1] = gFld_n[4]/sqrt(gFld_n[5]); - biFld_n[2] = gFld_n[5]/sqrt(gFld_n[5]); - - double *cmagFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].cmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - cmagFld_n[0] = jFld_n[0]*bmag_n[0]/sqrt(gFld_n[5]); - double *jtotinvFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].jacobtot_inv_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - jtotinvFld_n[0] = 1.0/(jFld_n[0]*bmag_n[0]); + double *biFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].b_i_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + biFld_n[0] = gFld_n[2] / sqrt(gFld_n[5]); + biFld_n[1] = gFld_n[4] / sqrt(gFld_n[5]); + biFld_n[2] = gFld_n[5] / sqrt(gFld_n[5]); + + double *cmagFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].cmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + cmagFld_n[0] = jFld_n[0] * bmag_n[0] / sqrt(gFld_n[5]); + double *jtotinvFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].jacobtot_inv_nodal, + gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + jtotinvFld_n[0] = 1.0 / (jFld_n[0] * bmag_n[0]); // Calculate cartesian components of bhat - double *bcartFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].bcart_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + double *bcartFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].bcart_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); double phi = mc2p_n[PHI_IDX]; - double b3 = 1/sqrt(gFld_n[5]); - bcartFld_n[0] = b3*(dxdz[0][2]*cos(phi) - R*sin(phi)*dphidtheta); - bcartFld_n[1] = b3*(dxdz[0][2]*sin(phi) + R*cos(phi)*dphidtheta); - bcartFld_n[2] = b3*(dxdz[1][2]); + double b3 = 1 / sqrt(gFld_n[5]); + bcartFld_n[0] = b3 * (dxdz[0][2] * cos(phi) - R * sin(phi) * dphidtheta); + bcartFld_n[1] = b3 * (dxdz[0][2] * sin(phi) + R * cos(phi) * dphidtheta); + bcartFld_n[2] = b3 * (dxdz[1][2]); // Set cartesian components of tangents and duals double Z = mc2p_n[Z_IDX]; double J = jFld_n[0]; - double *tanvecFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - tanvecFld_n[0] = dxdz[0][0]*cos(phi) - R*sin(phi)*dxdz[2][0]; - tanvecFld_n[1] = dxdz[0][0]*sin(phi) + R*cos(phi)*dxdz[2][0]; + double *tanvecFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + tanvecFld_n[0] = dxdz[0][0] * cos(phi) - R * sin(phi) * dxdz[2][0]; + tanvecFld_n[1] = dxdz[0][0] * sin(phi) + R * cos(phi) * dxdz[2][0]; tanvecFld_n[2] = dxdz[1][0]; - tanvecFld_n[3] = -R*sin(phi); - tanvecFld_n[4] = +R*cos(phi); - tanvecFld_n[5] = 0.0; + tanvecFld_n[3] = -R * sin(phi); + tanvecFld_n[4] = +R * cos(phi); + tanvecFld_n[5] = 0.0; - tanvecFld_n[6] = dxdz[0][2]*cos(phi) - R*sin(phi)*dphidtheta; - tanvecFld_n[7] = dxdz[0][2]*sin(phi) + R*cos(phi)*dphidtheta; + tanvecFld_n[6] = dxdz[0][2] * cos(phi) - R * sin(phi) * dphidtheta; + tanvecFld_n[7] = dxdz[0][2] * sin(phi) + R * cos(phi) * dphidtheta; tanvecFld_n[8] = dxdz[1][2]; - double *dualFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - dualFld_n[0] = +R/J*cos(phi)*dxdz[1][2]; - dualFld_n[1] = +R/J*sin(phi)*dxdz[1][2]; - dualFld_n[2] = -R/J*dxdz[0][2]; - - dualFld_n[3] = 1/J * ( dxdz[1][0]*dxdz[0][2]*sin(phi) + dxdz[1][0]*R*cos(phi)*dphidtheta - -dxdz[1][2]*dxdz[0][0]*sin(phi) - dxdz[1][2]*R*cos(phi)*dxdz[2][0] ); - dualFld_n[4] = -1/J * ( dxdz[1][0]*dxdz[0][2]*cos(phi) - dxdz[1][0]*R*sin(phi)*dphidtheta - -dxdz[1][2]*dxdz[0][0]*cos(phi) + dxdz[1][2]*R*sin(phi)*dxdz[2][0] ); - dualFld_n[5] = R/J * ( dxdz[0][2]*dxdz[2][0] - dxdz[0][0]*dphidtheta); - - dualFld_n[6] = -R/J*cos(phi)*dxdz[1][0]; - dualFld_n[7] = -R/J*sin(phi)*dxdz[1][0]; - dualFld_n[8] = +R/J*dxdz[0][0]; + double *dualFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + dualFld_n[0] = +R / J * cos(phi) * dxdz[1][2]; + dualFld_n[1] = +R / J * sin(phi) * dxdz[1][2]; + dualFld_n[2] = -R / J * dxdz[0][2]; + + dualFld_n[3] = + 1 / J * + (dxdz[1][0] * dxdz[0][2] * sin(phi) + dxdz[1][0] * R * cos(phi) * dphidtheta - + dxdz[1][2] * dxdz[0][0] * sin(phi) - dxdz[1][2] * R * cos(phi) * dxdz[2][0]); + dualFld_n[4] = + -1 / J * + (dxdz[1][0] * dxdz[0][2] * cos(phi) - dxdz[1][0] * R * sin(phi) * dphidtheta - + dxdz[1][2] * dxdz[0][0] * cos(phi) + dxdz[1][2] * R * sin(phi) * dxdz[2][0]); + dualFld_n[5] = R / J * (dxdz[0][2] * dxdz[2][0] - dxdz[0][0] * dphidtheta); + + dualFld_n[6] = -R / J * cos(phi) * dxdz[1][0]; + dualFld_n[7] = -R / J * sin(phi) * dxdz[1][0]; + dualFld_n[8] = +R / J * dxdz[0][0]; // Check that the coordinate system has tangent/dual vectors // satisfying orthonormality, and that it's right handed. check_orthonormality(tanvecFld_n, dualFld_n, up->exit_at_checks); check_right_handed(tanvecFld_n, dualFld_n, up->exit_at_checks); - double norm1 = sqrt(dualFld_n[0]*dualFld_n[0] + dualFld_n[1]*dualFld_n[1] + dualFld_n[2]*dualFld_n[2]); - double norm2 = sqrt(dualFld_n[3]*dualFld_n[3] + dualFld_n[4]*dualFld_n[4] + dualFld_n[5]*dualFld_n[5]); - double norm3 = sqrt(dualFld_n[6]*dualFld_n[6] + dualFld_n[7]*dualFld_n[7] + dualFld_n[8]*dualFld_n[8]); - - double *dualmagFld_n = gkyl_array_fetch(gk_geom->geo_surf[dir].dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + double norm1 = sqrt( + dualFld_n[0] * dualFld_n[0] + dualFld_n[1] * dualFld_n[1] + dualFld_n[2] * dualFld_n[2] + ); + double norm2 = sqrt( + dualFld_n[3] * dualFld_n[3] + dualFld_n[4] * dualFld_n[4] + dualFld_n[5] * dualFld_n[5] + ); + double norm3 = sqrt( + dualFld_n[6] * dualFld_n[6] + dualFld_n[7] * dualFld_n[7] + dualFld_n[8] * dualFld_n[8] + ); + + double *dualmagFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); dualmagFld_n[0] = norm1; dualmagFld_n[1] = norm2; dualmagFld_n[2] = norm3; - + // Set normal vectors - double *normFld_n = gkyl_array_fetch(gk_geom->geo_surf[dir].normals_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - normFld_n[0] = dualFld_n[0]/norm1; - normFld_n[1] = dualFld_n[1]/norm1; - normFld_n[2] = dualFld_n[2]/norm1; + double *normFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].normals_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + normFld_n[0] = dualFld_n[0] / norm1; + normFld_n[1] = dualFld_n[1] / norm1; + normFld_n[2] = dualFld_n[2] / norm1; - normFld_n[3] = dualFld_n[3]/norm2; - normFld_n[4] = dualFld_n[4]/norm2; - normFld_n[5] = dualFld_n[5]/norm2; + normFld_n[3] = dualFld_n[3] / norm2; + normFld_n[4] = dualFld_n[4] / norm2; + normFld_n[5] = dualFld_n[5] / norm2; - normFld_n[6] = dualFld_n[6]/norm3; - normFld_n[7] = dualFld_n[7]/norm3; - normFld_n[8] = dualFld_n[8]/norm3; + normFld_n[6] = dualFld_n[6] / norm3; + normFld_n[7] = dualFld_n[7] / norm3; + normFld_n[8] = dualFld_n[8] / norm3; // Set lenr - double *lenr_n = gkyl_array_fetch(gk_geom->geo_surf[dir].lenr_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - lenr_n[0] = J*dualmagFld_n[dir]; - - // Set n^3 \dot B - double *B3_n = gkyl_array_fetch(gk_geom->geo_surf[dir].B3_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - B3_n[0] = bmag_n[0]/sqrt(gFld_n[5])/norm3; - - // Set n^m \dot curl(bhat) - double *curlbhat_n = gkyl_array_fetch(gk_geom->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *normcurlbhat_n = gkyl_array_fetch(gk_geom->geo_surf[dir].normcurlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - normcurlbhat_n[0] = normFld_n[3*dir+0]*curlbhat_n[0] + normFld_n[3*dir+1]*curlbhat_n[1] + normFld_n[3*dir+2]*curlbhat_n[2]; + double *lenr_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].lenr_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + lenr_n[0] = J * dualmagFld_n[dir]; + + // Set n^3 \dot B + double *B3_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].B3_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + B3_n[0] = bmag_n[0] / sqrt(gFld_n[5]) / norm3; + + // Set n^m \dot curl(bhat) + double *curlbhat_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *normcurlbhat_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].normcurlbhat_nodal, + gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + normcurlbhat_n[0] = normFld_n[3 * dir + 0] * curlbhat_n[0] + + normFld_n[3 * dir + 1] * curlbhat_n[1] + + normFld_n[3 * dir + 2] * curlbhat_n[2]; // set bimpactangle = arcsin(1/sqrt(g_33 * g^33)) - double *bimpactangle_n = gkyl_array_fetch(gk_geom->geo_surf[dir].bimpactangle_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - bimpactangle_n[0] = asin(1.0/(sqrt(gFld_n[5]) * norm3)); - + double *bimpactangle_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].bimpactangle_nodal, + gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + bimpactangle_n[0] = asin(1.0 / (sqrt(gFld_n[5]) * norm3)); } } } } - - -void -gkyl_calc_metric_advance_rz_neut_interior( gkyl_calc_metric *up, struct gk_geometry* gk_geom) +void gkyl_calc_metric_advance_rz_neut_interior(gkyl_calc_metric *up, struct gk_geometry *gk_geom) { enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { R_IDX, Z_IDX, PHI_IDX }; // arrangement of cartesian coordinates int cidx[3]; - for (int ia=gk_geom->nrange_int.lower[AL_IDX]; ia<=gk_geom->nrange_int.upper[AL_IDX]; ++ia){ - for (int ip=gk_geom->nrange_int.lower[PSI_IDX]; ip<=gk_geom->nrange_int.upper[PSI_IDX]; ++ip) { - for (int it=gk_geom->nrange_int.lower[TH_IDX]; it<=gk_geom->nrange_int.upper[TH_IDX]; ++it) { + for (int ia = gk_geom->nrange_int.lower[AL_IDX]; ia <= gk_geom->nrange_int.upper[AL_IDX]; ++ia) { + for (int ip = gk_geom->nrange_int.lower[PSI_IDX]; ip <= gk_geom->nrange_int.upper[PSI_IDX]; + ++ip) { + for (int it = gk_geom->nrange_int.lower[TH_IDX]; it <= gk_geom->nrange_int.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - const double *mc2p_n = gkyl_array_cfetch(gk_geom->geo_int.mc2p_nodal_fd, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + const double *mc2p_n = gkyl_array_cfetch( + gk_geom->geo_int.mc2p_nodal_fd, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); double dxdz[3][3]; - dxdz[0][0] = -(mc2p_n[3 +R_IDX] - mc2p_n[6+R_IDX])/2/gk_geom->dzc[0]; - dxdz[1][0] = -(mc2p_n[3 +Z_IDX] - mc2p_n[6+Z_IDX])/2/gk_geom->dzc[0]; - + dxdz[0][0] = -(mc2p_n[3 + R_IDX] - mc2p_n[6 + R_IDX]) / 2 / gk_geom->dzc[0]; + dxdz[1][0] = -(mc2p_n[3 + Z_IDX] - mc2p_n[6 + Z_IDX]) / 2 / gk_geom->dzc[0]; // dphi/dpsi =0 dxdz[2][0] = 0.0; // Use exact expressions for dR/dtheta and dZ/dtheta, dphi/dtheta - double *ddtheta_n = gkyl_array_fetch(gk_geom->geo_int.ddtheta_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *ddtheta_n = gkyl_array_fetch( + gk_geom->geo_int.ddtheta_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); dxdz[0][2] = ddtheta_n[0]; dxdz[1][2] = ddtheta_n[1]; dxdz[2][2] = 0.0; @@ -775,108 +995,137 @@ gkyl_calc_metric_advance_rz_neut_interior( gkyl_calc_metric *up, struct gk_geome // dxdz is in cylindrical coords, calculate J as // J = R(dR/dpsi*dZ/dtheta - dR/dtheta*dZ/dpsi) double R = mc2p_n[R_IDX]; - double jac = sqrt(R*R*( dxdz[0][0]*dxdz[0][0]*dxdz[1][2]*dxdz[1][2] - + dxdz[0][2]*dxdz[0][2]*dxdz[1][0]*dxdz[1][0] - -2*dxdz[0][0]*dxdz[0][2]*dxdz[1][0]*dxdz[1][2] )) ; - - double *gFld_n= gkyl_array_fetch(gk_geom->geo_int.g_ij_neut_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - gFld_n[0] = dxdz[0][0]*dxdz[0][0] + R*R*dxdz[2][0]*dxdz[2][0] + dxdz[1][0]*dxdz[1][0]; - gFld_n[1] = R*R*dxdz[2][0]; - gFld_n[2] = dxdz[0][0]*dxdz[0][2] + R*R*dxdz[2][0]*dphidtheta + dxdz[1][0]*dxdz[1][2]; - gFld_n[3] = R*R; - gFld_n[4] = R*R*dphidtheta; - gFld_n[5] = dxdz[0][2]*dxdz[0][2] + R*R*dphidtheta*dphidtheta + dxdz[1][2]*dxdz[1][2]; - - double *grFld_n= gkyl_array_fetch(gk_geom->geo_int.gij_neut_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - grFld_n[0] = R*R/jac/jac*(dxdz[1][2]*dxdz[1][2] + dxdz[0][2]*dxdz[0][2] ); + double jac = sqrt( + R * R * + (dxdz[0][0] * dxdz[0][0] * dxdz[1][2] * dxdz[1][2] + + dxdz[0][2] * dxdz[0][2] * dxdz[1][0] * dxdz[1][0] - + 2 * dxdz[0][0] * dxdz[0][2] * dxdz[1][0] * dxdz[1][2]) + ); + + double *gFld_n = gkyl_array_fetch( + gk_geom->geo_int.g_ij_neut_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + gFld_n[0] = + dxdz[0][0] * dxdz[0][0] + R * R * dxdz[2][0] * dxdz[2][0] + dxdz[1][0] * dxdz[1][0]; + gFld_n[1] = R * R * dxdz[2][0]; + gFld_n[2] = + dxdz[0][0] * dxdz[0][2] + R * R * dxdz[2][0] * dphidtheta + dxdz[1][0] * dxdz[1][2]; + gFld_n[3] = R * R; + gFld_n[4] = R * R * dphidtheta; + gFld_n[5] = + dxdz[0][2] * dxdz[0][2] + R * R * dphidtheta * dphidtheta + dxdz[1][2] * dxdz[1][2]; + + double *grFld_n = gkyl_array_fetch( + gk_geom->geo_int.gij_neut_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + grFld_n[0] = R * R / jac / jac * (dxdz[1][2] * dxdz[1][2] + dxdz[0][2] * dxdz[0][2]); grFld_n[1] = 0.0; - grFld_n[2] = -R*R/jac/jac*(dxdz[0][0]*dxdz[0][2] + dxdz[1][0]*dxdz[1][2] ); - grFld_n[3] = 1/R/R; + grFld_n[2] = -R * R / jac / jac * (dxdz[0][0] * dxdz[0][2] + dxdz[1][0] * dxdz[1][2]); + grFld_n[3] = 1 / R / R; grFld_n[4] = 0.0; - grFld_n[5] = R*R/jac/jac*(dxdz[0][0]*dxdz[0][0] + dxdz[1][0]*dxdz[1][0] ); - + grFld_n[5] = R * R / jac / jac * (dxdz[0][0] * dxdz[0][0] + dxdz[1][0] * dxdz[1][0]); } } } - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &up->local, 6, gk_geom->geo_int.g_ij_neut_nodal, gk_geom->geo_int.g_ij_neut, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &up->local, 6, gk_geom->geo_int.gij_neut_nodal, gk_geom->geo_int.gij_neut, true); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &up->local, 6, + gk_geom->geo_int.g_ij_neut_nodal, gk_geom->geo_int.g_ij_neut, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &up->local, 6, + gk_geom->geo_int.gij_neut_nodal, gk_geom->geo_int.gij_neut, true + ); } void gkyl_calc_metric_advance_mirror( - gkyl_calc_metric *up, struct gkyl_range *nrange, - struct gkyl_array *mc2p_nodal_fd, struct gkyl_array *ddtheta_nodal, - struct gkyl_array *bmag_nodal, double *dzc, struct gkyl_array *gFld, - struct gkyl_array *tanvecFld, - struct gkyl_array *dualFld, - struct gkyl_array *dualmagFld, - struct gkyl_array *normFld, - struct gkyl_array *jFld, struct gkyl_array* bcartFld, const struct gkyl_range *update_range) + gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, + struct gkyl_array *ddtheta_nodal, struct gkyl_array *bmag_nodal, double *dzc, + struct gkyl_array *gFld, struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, + struct gkyl_array *dualmagFld, struct gkyl_array *normFld, struct gkyl_array *jFld, + struct gkyl_array *bcartFld, const struct gkyl_range *update_range +) { - struct gkyl_array* gFld_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange->volume); - struct gkyl_array* jFld_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange->volume); - struct gkyl_array* bcartFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); - struct gkyl_array* tanvecFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); - struct gkyl_array* dualFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); - struct gkyl_array* dualmagFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); - struct gkyl_array* normFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *gFld_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange->volume); + struct gkyl_array *jFld_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange->volume); + struct gkyl_array *bcartFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); + struct gkyl_array *tanvecFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *dualFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *dualmagFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); + struct gkyl_array *normFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { R_IDX, Z_IDX, PHI_IDX }; // arrangement of cartesian coordinates int cidx[3]; - for (int ia=nrange->lower[AL_IDX]; ia<=nrange->upper[AL_IDX]; ++ia){ - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { + for (int ia = nrange->lower[AL_IDX]; ia <= nrange->upper[AL_IDX]; ++ia) { + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; const double *mc2p_n = gkyl_array_cfetch(mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); double dxdz[3][3]; - if((ip == nrange->lower[PSI_IDX]) && (up->local.lower[PSI_IDX]== up->global.lower[PSI_IDX]) ) { - dxdz[0][0] = (-3*mc2p_n[R_IDX] + 4*mc2p_n[6+R_IDX] - mc2p_n[12+R_IDX] )/dzc[0]/2; - dxdz[1][0] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[6+Z_IDX] - mc2p_n[12+Z_IDX] )/dzc[0]/2; - dxdz[2][0] = (-3*mc2p_n[PHI_IDX] + 4*mc2p_n[6+PHI_IDX] - mc2p_n[12+PHI_IDX] )/dzc[0]/2; - } - else if((ip == nrange->upper[PSI_IDX]) && (up->local.upper[PSI_IDX]== up->global.upper[PSI_IDX])) { - dxdz[0][0] = (3*mc2p_n[R_IDX] - 4*mc2p_n[3+R_IDX] + mc2p_n[9+R_IDX] )/dzc[0]/2; - dxdz[1][0] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[3+Z_IDX] + mc2p_n[9+Z_IDX] )/dzc[0]/2; - dxdz[2][0] = (3*mc2p_n[PHI_IDX] - 4*mc2p_n[3+PHI_IDX] + mc2p_n[9+PHI_IDX] )/dzc[0]/2; - } - else { - dxdz[0][0] = -(mc2p_n[3 +R_IDX] - mc2p_n[6+R_IDX])/2/dzc[0]; - dxdz[1][0] = -(mc2p_n[3 +Z_IDX] - mc2p_n[6+Z_IDX])/2/dzc[0]; - dxdz[2][0] = -(mc2p_n[3 +PHI_IDX] - mc2p_n[6+PHI_IDX])/2/dzc[0]; + if ((ip == nrange->lower[PSI_IDX]) && + (up->local.lower[PSI_IDX] == up->global.lower[PSI_IDX])) { + dxdz[0][0] = + (-3 * mc2p_n[R_IDX] + 4 * mc2p_n[6 + R_IDX] - mc2p_n[12 + R_IDX]) / dzc[0] / 2; + dxdz[1][0] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[6 + Z_IDX] - mc2p_n[12 + Z_IDX]) / dzc[0] / 2; + dxdz[2][0] = + (-3 * mc2p_n[PHI_IDX] + 4 * mc2p_n[6 + PHI_IDX] - mc2p_n[12 + PHI_IDX]) / dzc[0] / 2; + } else if ((ip == nrange->upper[PSI_IDX]) && + (up->local.upper[PSI_IDX] == up->global.upper[PSI_IDX])) { + dxdz[0][0] = (3 * mc2p_n[R_IDX] - 4 * mc2p_n[3 + R_IDX] + mc2p_n[9 + R_IDX]) / dzc[0] / 2; + dxdz[1][0] = (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[3 + Z_IDX] + mc2p_n[9 + Z_IDX]) / dzc[0] / 2; + dxdz[2][0] = + (3 * mc2p_n[PHI_IDX] - 4 * mc2p_n[3 + PHI_IDX] + mc2p_n[9 + PHI_IDX]) / dzc[0] / 2; + } else { + dxdz[0][0] = -(mc2p_n[3 + R_IDX] - mc2p_n[6 + R_IDX]) / 2 / dzc[0]; + dxdz[1][0] = -(mc2p_n[3 + Z_IDX] - mc2p_n[6 + Z_IDX]) / 2 / dzc[0]; + dxdz[2][0] = -(mc2p_n[3 + PHI_IDX] - mc2p_n[6 + PHI_IDX]) / 2 / dzc[0]; } - if((ia == nrange->lower[AL_IDX]) && (up->local.lower[AL_IDX]== up->global.lower[AL_IDX]) ) { - dxdz[0][1] = (-3*mc2p_n[R_IDX] + 4*mc2p_n[18+R_IDX] - mc2p_n[24+R_IDX])/dzc[1]/2; - dxdz[1][1] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[18+Z_IDX] - mc2p_n[24+Z_IDX])/dzc[1]/2; - dxdz[2][1] = (-3*mc2p_n[PHI_IDX] + 4*mc2p_n[18+PHI_IDX] - mc2p_n[24+PHI_IDX])/dzc[1]/2; - } - else if((ia == nrange->upper[AL_IDX]) && (up->local.upper[AL_IDX]== up->global.upper[AL_IDX])){ - dxdz[0][1] = (3*mc2p_n[R_IDX] - 4*mc2p_n[15+R_IDX] + mc2p_n[21+R_IDX] )/dzc[1]/2; - dxdz[1][1] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[15+Z_IDX] + mc2p_n[21+Z_IDX] )/dzc[1]/2; - dxdz[2][1] = (3*mc2p_n[PHI_IDX] - 4*mc2p_n[15+PHI_IDX] + mc2p_n[21+PHI_IDX] )/dzc[1]/2; - } - else { - dxdz[0][1] = -(mc2p_n[15 +R_IDX] - mc2p_n[18 +R_IDX])/2/dzc[1]; - dxdz[1][1] = -(mc2p_n[15 +Z_IDX] - mc2p_n[18 +Z_IDX])/2/dzc[1]; - dxdz[2][1] = -(mc2p_n[15 +PHI_IDX] - mc2p_n[18 +PHI_IDX])/2/dzc[1]; + if ((ia == nrange->lower[AL_IDX]) && + (up->local.lower[AL_IDX] == up->global.lower[AL_IDX])) { + dxdz[0][1] = + (-3 * mc2p_n[R_IDX] + 4 * mc2p_n[18 + R_IDX] - mc2p_n[24 + R_IDX]) / dzc[1] / 2; + dxdz[1][1] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[18 + Z_IDX] - mc2p_n[24 + Z_IDX]) / dzc[1] / 2; + dxdz[2][1] = + (-3 * mc2p_n[PHI_IDX] + 4 * mc2p_n[18 + PHI_IDX] - mc2p_n[24 + PHI_IDX]) / dzc[1] / 2; + } else if ((ia == nrange->upper[AL_IDX]) && + (up->local.upper[AL_IDX] == up->global.upper[AL_IDX])) { + dxdz[0][1] = + (3 * mc2p_n[R_IDX] - 4 * mc2p_n[15 + R_IDX] + mc2p_n[21 + R_IDX]) / dzc[1] / 2; + dxdz[1][1] = + (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[15 + Z_IDX] + mc2p_n[21 + Z_IDX]) / dzc[1] / 2; + dxdz[2][1] = + (3 * mc2p_n[PHI_IDX] - 4 * mc2p_n[15 + PHI_IDX] + mc2p_n[21 + PHI_IDX]) / dzc[1] / 2; + } else { + dxdz[0][1] = -(mc2p_n[15 + R_IDX] - mc2p_n[18 + R_IDX]) / 2 / dzc[1]; + dxdz[1][1] = -(mc2p_n[15 + Z_IDX] - mc2p_n[18 + Z_IDX]) / 2 / dzc[1]; + dxdz[2][1] = -(mc2p_n[15 + PHI_IDX] - mc2p_n[18 + PHI_IDX]) / 2 / dzc[1]; } - if((it == nrange->lower[TH_IDX]) && (up->local.lower[TH_IDX]== up->global.lower[TH_IDX])){ - dxdz[0][2] = (-3*mc2p_n[R_IDX] + 4*mc2p_n[30+R_IDX] - mc2p_n[36+R_IDX])/dzc[2]/2; - dxdz[1][2] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[30+Z_IDX] - mc2p_n[36+Z_IDX])/dzc[2]/2; - dxdz[2][2] = (-3*mc2p_n[PHI_IDX] + 4*mc2p_n[30+PHI_IDX] - mc2p_n[36+PHI_IDX])/dzc[2]/2; - } - else if((it == nrange->upper[TH_IDX]) && (up->local.upper[TH_IDX]== up->global.upper[TH_IDX])){ - dxdz[0][2] = (3*mc2p_n[R_IDX] - 4*mc2p_n[27+R_IDX] + mc2p_n[33+R_IDX] )/dzc[2]/2; - dxdz[1][2] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[27+Z_IDX] + mc2p_n[33+Z_IDX] )/dzc[2]/2; - dxdz[2][2] = (3*mc2p_n[PHI_IDX] - 4*mc2p_n[27+PHI_IDX] + mc2p_n[33+PHI_IDX] )/dzc[2]/2; - } - else { - dxdz[0][2] = -(mc2p_n[27 +R_IDX] - mc2p_n[30 +R_IDX])/2/dzc[2]; - dxdz[1][2] = -(mc2p_n[27 +Z_IDX] - mc2p_n[30 +Z_IDX])/2/dzc[2]; - dxdz[2][2] = -(mc2p_n[27 +PHI_IDX] - mc2p_n[30 +PHI_IDX])/2/dzc[2]; + if ((it == nrange->lower[TH_IDX]) && + (up->local.lower[TH_IDX] == up->global.lower[TH_IDX])) { + dxdz[0][2] = + (-3 * mc2p_n[R_IDX] + 4 * mc2p_n[30 + R_IDX] - mc2p_n[36 + R_IDX]) / dzc[2] / 2; + dxdz[1][2] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[30 + Z_IDX] - mc2p_n[36 + Z_IDX]) / dzc[2] / 2; + dxdz[2][2] = + (-3 * mc2p_n[PHI_IDX] + 4 * mc2p_n[30 + PHI_IDX] - mc2p_n[36 + PHI_IDX]) / dzc[2] / 2; + } else if ((it == nrange->upper[TH_IDX]) && + (up->local.upper[TH_IDX] == up->global.upper[TH_IDX])) { + dxdz[0][2] = + (3 * mc2p_n[R_IDX] - 4 * mc2p_n[27 + R_IDX] + mc2p_n[33 + R_IDX]) / dzc[2] / 2; + dxdz[1][2] = + (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[27 + Z_IDX] + mc2p_n[33 + Z_IDX]) / dzc[2] / 2; + dxdz[2][2] = + (3 * mc2p_n[PHI_IDX] - 4 * mc2p_n[27 + PHI_IDX] + mc2p_n[33 + PHI_IDX]) / dzc[2] / 2; + } else { + dxdz[0][2] = -(mc2p_n[27 + R_IDX] - mc2p_n[30 + R_IDX]) / 2 / dzc[2]; + dxdz[1][2] = -(mc2p_n[27 + Z_IDX] - mc2p_n[30 + Z_IDX]) / 2 / dzc[2]; + dxdz[2][2] = -(mc2p_n[27 + PHI_IDX] - mc2p_n[30 + PHI_IDX]) / 2 / dzc[2]; } // Use exact expressions for dphidtheta, dR/dtheta, and dZ/dtheta @@ -888,94 +1137,122 @@ void gkyl_calc_metric_advance_mirror( double R = mc2p_n[R_IDX]; double *bmag_n = gkyl_array_fetch(bmag_nodal, gkyl_range_idx(nrange, cidx)); - double *gFld_n= gkyl_array_fetch(gFld_nodal, gkyl_range_idx(nrange, cidx)); - gFld_n[5] = dxdz[0][2]*dxdz[0][2] + dxdz[1][2]*dxdz[1][2]; + double *gFld_n = gkyl_array_fetch(gFld_nodal, gkyl_range_idx(nrange, cidx)); + gFld_n[5] = dxdz[0][2] * dxdz[0][2] + dxdz[1][2] * dxdz[1][2]; // dxdz is in cylindrical coordinates. Caculate dR/dpsi as // dR/dpsi = (1/(dZ/dtheta) ) * [sqrt(g_33)/RB + dR/dtheta*dZ/dtheta] // because this is more reliable near R=0 than using finite differences - double dRdpsi = 1/dxdz[1][2]*(sqrt(gFld_n[5])/bmag_n[0]/R + dxdz[0][2]*dxdz[1][0]); + double dRdpsi = + 1 / dxdz[1][2] * (sqrt(gFld_n[5]) / bmag_n[0] / R + dxdz[0][2] * dxdz[1][0]); // Calculate J as J = R(dR/dpsi*dZ/dtheta - dR/dtheta*dZ/dpsi) - double *jFld_n= gkyl_array_fetch(jFld_nodal, gkyl_range_idx(nrange, cidx)); - jFld_n[0] = sqrt(R*R*( dRdpsi*dRdpsi*dxdz[1][2]*dxdz[1][2] - +dxdz[0][2]*dxdz[0][2]*dxdz[1][0]*dxdz[1][0] - -2*dRdpsi*dxdz[0][2]*dxdz[1][0]*dxdz[1][2] )); - - gFld_n[0] = dRdpsi*dRdpsi + dxdz[1][0]*dxdz[1][0]; - gFld_n[1] = 0.0; - gFld_n[2] = dRdpsi*dxdz[0][2] + dxdz[1][0]*dxdz[1][2]; - gFld_n[3] = R*R; - gFld_n[4] = 0.0; + double *jFld_n = gkyl_array_fetch(jFld_nodal, gkyl_range_idx(nrange, cidx)); + jFld_n[0] = sqrt( + R * R * + (dRdpsi * dRdpsi * dxdz[1][2] * dxdz[1][2] + + dxdz[0][2] * dxdz[0][2] * dxdz[1][0] * dxdz[1][0] - + 2 * dRdpsi * dxdz[0][2] * dxdz[1][0] * dxdz[1][2]) + ); + + gFld_n[0] = dRdpsi * dRdpsi + dxdz[1][0] * dxdz[1][0]; + gFld_n[1] = 0.0; + gFld_n[2] = dRdpsi * dxdz[0][2] + dxdz[1][0] * dxdz[1][2]; + gFld_n[3] = R * R; + gFld_n[4] = 0.0; // Now do bcart - double *bcartFld_n= gkyl_array_fetch(bcartFld_nodal, gkyl_range_idx(nrange, cidx)); + double *bcartFld_n = gkyl_array_fetch(bcartFld_nodal, gkyl_range_idx(nrange, cidx)); double phi = mc2p_n[PHI_IDX]; - double b3 = 1/sqrt(gFld_n[5]); - bcartFld_n[0] = b3*dxdz[0][2]*cos(phi); - bcartFld_n[1] = b3*dxdz[0][2]*sin(phi); - bcartFld_n[2] = b3*dxdz[1][2]; + double b3 = 1 / sqrt(gFld_n[5]); + bcartFld_n[0] = b3 * dxdz[0][2] * cos(phi); + bcartFld_n[1] = b3 * dxdz[0][2] * sin(phi); + bcartFld_n[2] = b3 * dxdz[1][2]; // Set cartesian components of tangents and duals double Z = mc2p_n[Z_IDX]; double J = jFld_n[0]; - double *tanvecFld_n= gkyl_array_fetch(tanvecFld_nodal, gkyl_range_idx(nrange, cidx)); - tanvecFld_n[0] = dxdz[0][0]*cos(phi) - R*sin(phi)*dxdz[2][0]; - tanvecFld_n[1] = dxdz[0][0]*sin(phi) + R*cos(phi)*dxdz[2][0]; + double *tanvecFld_n = gkyl_array_fetch(tanvecFld_nodal, gkyl_range_idx(nrange, cidx)); + tanvecFld_n[0] = dxdz[0][0] * cos(phi) - R * sin(phi) * dxdz[2][0]; + tanvecFld_n[1] = dxdz[0][0] * sin(phi) + R * cos(phi) * dxdz[2][0]; tanvecFld_n[2] = dxdz[1][0]; - tanvecFld_n[3] = +R*sin(phi); - tanvecFld_n[4] = -R*cos(phi); - tanvecFld_n[5] = 0.0; + tanvecFld_n[3] = +R * sin(phi); + tanvecFld_n[4] = -R * cos(phi); + tanvecFld_n[5] = 0.0; - tanvecFld_n[6] = dxdz[0][2]*cos(phi); - tanvecFld_n[7] = dxdz[0][2]*sin(phi); + tanvecFld_n[6] = dxdz[0][2] * cos(phi); + tanvecFld_n[7] = dxdz[0][2] * sin(phi); tanvecFld_n[8] = dxdz[1][2]; - double *dualFld_n= gkyl_array_fetch(dualFld_nodal, gkyl_range_idx(nrange, cidx)); - dualFld_n[0] = -R/J*cos(phi)*dxdz[1][2]; - dualFld_n[1] = -R/J*sin(phi)*dxdz[1][2]; - dualFld_n[2] = +R/J*dxdz[0][2]; - - dualFld_n[3] = 1/J * (dxdz[1][0]*dxdz[0][2]*sin(phi) - dxdz[1][2]*dxdz[0][0]*sin(phi) - dxdz[1][2]*R*cos(phi)*dxdz[2][0] ); - dualFld_n[4] = -1/J * (dxdz[1][0]*dxdz[0][2]*cos(phi) - dxdz[1][2]*dxdz[0][0]*cos(phi) + dxdz[1][2]*R*sin(phi)*dxdz[2][0] ); - dualFld_n[5] = R/J * dxdz[0][2]*dxdz[2][0]; - - dualFld_n[6] = +R/J*cos(phi)*dxdz[1][0]; - dualFld_n[7] = +R/J*sin(phi)*dxdz[1][0]; - dualFld_n[8] = -R/J*dxdz[0][0]; - - double norm1 = sqrt(dualFld_n[0]*dualFld_n[0] + dualFld_n[1]*dualFld_n[1] + dualFld_n[2]*dualFld_n[2]); - double norm2 = sqrt(dualFld_n[3]*dualFld_n[3] + dualFld_n[4]*dualFld_n[4] + dualFld_n[5]*dualFld_n[5]); - double norm3 = sqrt(dualFld_n[6]*dualFld_n[6] + dualFld_n[7]*dualFld_n[7] + dualFld_n[8]*dualFld_n[8]); + double *dualFld_n = gkyl_array_fetch(dualFld_nodal, gkyl_range_idx(nrange, cidx)); + dualFld_n[0] = -R / J * cos(phi) * dxdz[1][2]; + dualFld_n[1] = -R / J * sin(phi) * dxdz[1][2]; + dualFld_n[2] = +R / J * dxdz[0][2]; + + dualFld_n[3] = 1 / J * + (dxdz[1][0] * dxdz[0][2] * sin(phi) - dxdz[1][2] * dxdz[0][0] * sin(phi) - + dxdz[1][2] * R * cos(phi) * dxdz[2][0]); + dualFld_n[4] = -1 / J * + (dxdz[1][0] * dxdz[0][2] * cos(phi) - dxdz[1][2] * dxdz[0][0] * cos(phi) + + dxdz[1][2] * R * sin(phi) * dxdz[2][0]); + dualFld_n[5] = R / J * dxdz[0][2] * dxdz[2][0]; + + dualFld_n[6] = +R / J * cos(phi) * dxdz[1][0]; + dualFld_n[7] = +R / J * sin(phi) * dxdz[1][0]; + dualFld_n[8] = -R / J * dxdz[0][0]; + + double norm1 = sqrt( + dualFld_n[0] * dualFld_n[0] + dualFld_n[1] * dualFld_n[1] + dualFld_n[2] * dualFld_n[2] + ); + double norm2 = sqrt( + dualFld_n[3] * dualFld_n[3] + dualFld_n[4] * dualFld_n[4] + dualFld_n[5] * dualFld_n[5] + ); + double norm3 = sqrt( + dualFld_n[6] * dualFld_n[6] + dualFld_n[7] * dualFld_n[7] + dualFld_n[8] * dualFld_n[8] + ); double *dualmagFld_n = gkyl_array_fetch(dualmagFld_nodal, gkyl_range_idx(nrange, cidx)); dualmagFld_n[0] = norm1; dualmagFld_n[1] = norm2; dualmagFld_n[2] = norm3; - + // Set normal vectors double *normFld_n = gkyl_array_fetch(normFld_nodal, gkyl_range_idx(nrange, cidx)); - normFld_n[0] = dualFld_n[0]/norm1; - normFld_n[1] = dualFld_n[1]/norm1; - normFld_n[2] = dualFld_n[2]/norm1; + normFld_n[0] = dualFld_n[0] / norm1; + normFld_n[1] = dualFld_n[1] / norm1; + normFld_n[2] = dualFld_n[2] / norm1; - normFld_n[3] = dualFld_n[3]/norm2; - normFld_n[4] = dualFld_n[4]/norm2; - normFld_n[5] = dualFld_n[5]/norm2; + normFld_n[3] = dualFld_n[3] / norm2; + normFld_n[4] = dualFld_n[4] / norm2; + normFld_n[5] = dualFld_n[5] / norm2; - normFld_n[6] = dualFld_n[6]/norm3; - normFld_n[7] = dualFld_n[7]/norm3; - normFld_n[8] = dualFld_n[8]/norm3; + normFld_n[6] = dualFld_n[6] / norm3; + normFld_n[7] = dualFld_n[7] / norm3; + normFld_n[8] = dualFld_n[8] / norm3; } } } - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 6, gFld_nodal, gFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 1, jFld_nodal, jFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 3, bcartFld_nodal, bcartFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, tanvecFld_nodal, tanvecFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, dualFld_nodal, dualFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 3, dualmagFld_nodal, dualmagFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, normFld_nodal, normFld, false); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 6, gFld_nodal, gFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 1, jFld_nodal, jFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 3, bcartFld_nodal, bcartFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, tanvecFld_nodal, tanvecFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, dualFld_nodal, dualFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 3, dualmagFld_nodal, dualmagFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, normFld_nodal, normFld, false + ); gkyl_array_release(gFld_nodal); gkyl_array_release(jFld_nodal); gkyl_array_release(bcartFld_nodal); @@ -986,39 +1263,37 @@ void gkyl_calc_metric_advance_mirror( } void gkyl_calc_metric_advance_mirror_interior( - gkyl_calc_metric *up, struct gkyl_range *nrange, - struct gkyl_array *mc2p_nodal_fd, struct gkyl_array *ddtheta_nodal, - struct gkyl_array *bmag_nodal, double *dzc, struct gkyl_array *gFld, - struct gkyl_array *tanvecFld, - struct gkyl_array *dualFld, - struct gkyl_array *dualmagFld, - struct gkyl_array *normFld, - struct gkyl_array *jFld, struct gkyl_array* bcartFld, const struct gkyl_range *update_range) + gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, + struct gkyl_array *ddtheta_nodal, struct gkyl_array *bmag_nodal, double *dzc, + struct gkyl_array *gFld, struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, + struct gkyl_array *dualmagFld, struct gkyl_array *normFld, struct gkyl_array *jFld, + struct gkyl_array *bcartFld, const struct gkyl_range *update_range +) { - struct gkyl_array* gFld_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange->volume); - struct gkyl_array* jFld_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange->volume); - struct gkyl_array* bcartFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); - struct gkyl_array* tanvecFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); - struct gkyl_array* dualFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); - struct gkyl_array* dualmagFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); - struct gkyl_array* normFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *gFld_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange->volume); + struct gkyl_array *jFld_nodal = gkyl_array_new(GKYL_DOUBLE, 1, nrange->volume); + struct gkyl_array *bcartFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); + struct gkyl_array *tanvecFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *dualFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *dualmagFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); + struct gkyl_array *normFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { R_IDX, Z_IDX, PHI_IDX }; // arrangement of cartesian coordinates int cidx[3]; - for (int ia=nrange->lower[AL_IDX]; ia<=nrange->upper[AL_IDX]; ++ia){ - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { + for (int ia = nrange->lower[AL_IDX]; ia <= nrange->upper[AL_IDX]; ++ia) { + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; const double *mc2p_n = gkyl_array_cfetch(mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); double dxdz[3][3]; - dxdz[0][0] = -(mc2p_n[3 +R_IDX] - mc2p_n[6+R_IDX])/2/dzc[0]; - dxdz[1][0] = -(mc2p_n[3 +Z_IDX] - mc2p_n[6+Z_IDX])/2/dzc[0]; - dxdz[2][0] = -(mc2p_n[3 +PHI_IDX] - mc2p_n[6+PHI_IDX])/2/dzc[0]; + dxdz[0][0] = -(mc2p_n[3 + R_IDX] - mc2p_n[6 + R_IDX]) / 2 / dzc[0]; + dxdz[1][0] = -(mc2p_n[3 + Z_IDX] - mc2p_n[6 + Z_IDX]) / 2 / dzc[0]; + dxdz[2][0] = -(mc2p_n[3 + PHI_IDX] - mc2p_n[6 + PHI_IDX]) / 2 / dzc[0]; - // Use exact expressions for dR/dtheta, dZ/dtheta, and dphidtheta + // Use exact expressions for dR/dtheta, dZ/dtheta, and dphidtheta double *ddtheta_n = gkyl_array_fetch(ddtheta_nodal, gkyl_range_idx(nrange, cidx)); dxdz[0][2] = ddtheta_n[0]; // dR/dtheta dxdz[1][2] = ddtheta_n[1]; // dZ/dtheta @@ -1027,94 +1302,118 @@ void gkyl_calc_metric_advance_mirror_interior( double R = mc2p_n[R_IDX]; double *bmag_n = gkyl_array_fetch(bmag_nodal, gkyl_range_idx(nrange, cidx)); - double *gFld_n= gkyl_array_fetch(gFld_nodal, gkyl_range_idx(nrange, cidx)); - gFld_n[5] = dxdz[0][2]*dxdz[0][2] + dxdz[1][2]*dxdz[1][2]; + double *gFld_n = gkyl_array_fetch(gFld_nodal, gkyl_range_idx(nrange, cidx)); + gFld_n[5] = dxdz[0][2] * dxdz[0][2] + dxdz[1][2] * dxdz[1][2]; // dxdz is in cylindrical coordinates. Caculate dR/dpsi as // dR/dpsi = (1/(dZ/dtheta) ) * [sqrt(g_33)/RB + dR/dtheta*dZ/dtheta] // because this is more reliable near R=0 than using finite differences - double dRdpsi = 1/dxdz[1][2]*(sqrt(gFld_n[5])/bmag_n[0]/R + dxdz[0][2]*dxdz[1][0]); + double dRdpsi = + 1 / dxdz[1][2] * (sqrt(gFld_n[5]) / bmag_n[0] / R + dxdz[0][2] * dxdz[1][0]); // Calculate J as J = R(dR/dpsi*dZ/dtheta - dR/dtheta*dZ/dpsi) - double *jFld_n= gkyl_array_fetch(jFld_nodal, gkyl_range_idx(nrange, cidx)); - jFld_n[0] = sqrt(R*R*( dRdpsi*dRdpsi*dxdz[1][2]*dxdz[1][2] - +dxdz[0][2]*dxdz[0][2]*dxdz[1][0]*dxdz[1][0] - -2*dRdpsi*dxdz[0][2]*dxdz[1][0]*dxdz[1][2] )); - - gFld_n[0] = dRdpsi*dRdpsi + dxdz[1][0]*dxdz[1][0]; - gFld_n[1] = 0.0; - gFld_n[2] = dRdpsi*dxdz[0][2] + dxdz[1][0]*dxdz[1][2]; - gFld_n[3] = R*R; - gFld_n[4] = 0.0; + double *jFld_n = gkyl_array_fetch(jFld_nodal, gkyl_range_idx(nrange, cidx)); + jFld_n[0] = sqrt( + R * R * + (dRdpsi * dRdpsi * dxdz[1][2] * dxdz[1][2] + + dxdz[0][2] * dxdz[0][2] * dxdz[1][0] * dxdz[1][0] - + 2 * dRdpsi * dxdz[0][2] * dxdz[1][0] * dxdz[1][2]) + ); + + gFld_n[0] = dRdpsi * dRdpsi + dxdz[1][0] * dxdz[1][0]; + gFld_n[1] = 0.0; + gFld_n[2] = dRdpsi * dxdz[0][2] + dxdz[1][0] * dxdz[1][2]; + gFld_n[3] = R * R; + gFld_n[4] = 0.0; // Now do bcart - double *bcartFld_n= gkyl_array_fetch(bcartFld_nodal, gkyl_range_idx(nrange, cidx)); + double *bcartFld_n = gkyl_array_fetch(bcartFld_nodal, gkyl_range_idx(nrange, cidx)); double phi = mc2p_n[PHI_IDX]; - double b3 = 1/sqrt(gFld_n[5]); - bcartFld_n[0] = b3*dxdz[0][2]*cos(phi); - bcartFld_n[1] = b3*dxdz[0][2]*sin(phi); - bcartFld_n[2] = b3*dxdz[1][2]; + double b3 = 1 / sqrt(gFld_n[5]); + bcartFld_n[0] = b3 * dxdz[0][2] * cos(phi); + bcartFld_n[1] = b3 * dxdz[0][2] * sin(phi); + bcartFld_n[2] = b3 * dxdz[1][2]; // Set cartesian components of tangents and duals double Z = mc2p_n[Z_IDX]; double J = jFld_n[0]; - double *tanvecFld_n= gkyl_array_fetch(tanvecFld_nodal, gkyl_range_idx(nrange, cidx)); - tanvecFld_n[0] = dxdz[0][0]*cos(phi) - R*sin(phi)*dxdz[2][0]; - tanvecFld_n[1] = dxdz[0][0]*sin(phi) + R*cos(phi)*dxdz[2][0]; + double *tanvecFld_n = gkyl_array_fetch(tanvecFld_nodal, gkyl_range_idx(nrange, cidx)); + tanvecFld_n[0] = dxdz[0][0] * cos(phi) - R * sin(phi) * dxdz[2][0]; + tanvecFld_n[1] = dxdz[0][0] * sin(phi) + R * cos(phi) * dxdz[2][0]; tanvecFld_n[2] = dxdz[1][0]; - tanvecFld_n[3] = +R*sin(phi); - tanvecFld_n[4] = -R*cos(phi); - tanvecFld_n[5] = 0.0; + tanvecFld_n[3] = +R * sin(phi); + tanvecFld_n[4] = -R * cos(phi); + tanvecFld_n[5] = 0.0; - tanvecFld_n[6] = dxdz[0][2]*cos(phi); - tanvecFld_n[7] = dxdz[0][2]*sin(phi); + tanvecFld_n[6] = dxdz[0][2] * cos(phi); + tanvecFld_n[7] = dxdz[0][2] * sin(phi); tanvecFld_n[8] = dxdz[1][2]; - double *dualFld_n= gkyl_array_fetch(dualFld_nodal, gkyl_range_idx(nrange, cidx)); - dualFld_n[0] = -R/J*cos(phi)*dxdz[1][2]; - dualFld_n[1] = -R/J*sin(phi)*dxdz[1][2]; - dualFld_n[2] = +R/J*dxdz[0][2]; - - dualFld_n[3] = 1/J * (dxdz[1][0]*dxdz[0][2]*sin(phi) - dxdz[1][2]*dxdz[0][0]*sin(phi) - dxdz[1][2]*R*cos(phi)*dxdz[2][0] ); - dualFld_n[4] = -1/J * (dxdz[1][0]*dxdz[0][2]*cos(phi) - dxdz[1][2]*dxdz[0][0]*cos(phi) - dxdz[1][2]*R*sin(phi)*dxdz[2][0] ); - dualFld_n[5] = R/J * dxdz[0][2]*dxdz[2][0]; - - dualFld_n[6] = +R/J*cos(phi)*dxdz[1][0]; - dualFld_n[7] = +R/J*sin(phi)*dxdz[1][0]; - dualFld_n[8] = -R/J*dxdz[0][0]; - - double norm1 = sqrt(dualFld_n[0]*dualFld_n[0] + dualFld_n[1]*dualFld_n[1] + dualFld_n[2]*dualFld_n[2]); - double norm2 = sqrt(dualFld_n[3]*dualFld_n[3] + dualFld_n[4]*dualFld_n[4] + dualFld_n[5]*dualFld_n[5]); - double norm3 = sqrt(dualFld_n[6]*dualFld_n[6] + dualFld_n[7]*dualFld_n[7] + dualFld_n[8]*dualFld_n[8]); + double *dualFld_n = gkyl_array_fetch(dualFld_nodal, gkyl_range_idx(nrange, cidx)); + dualFld_n[0] = -R / J * cos(phi) * dxdz[1][2]; + dualFld_n[1] = -R / J * sin(phi) * dxdz[1][2]; + dualFld_n[2] = +R / J * dxdz[0][2]; + + dualFld_n[3] = 1 / J * + (dxdz[1][0] * dxdz[0][2] * sin(phi) - dxdz[1][2] * dxdz[0][0] * sin(phi) - + dxdz[1][2] * R * cos(phi) * dxdz[2][0]); + dualFld_n[4] = -1 / J * + (dxdz[1][0] * dxdz[0][2] * cos(phi) - dxdz[1][2] * dxdz[0][0] * cos(phi) - + dxdz[1][2] * R * sin(phi) * dxdz[2][0]); + dualFld_n[5] = R / J * dxdz[0][2] * dxdz[2][0]; + + dualFld_n[6] = +R / J * cos(phi) * dxdz[1][0]; + dualFld_n[7] = +R / J * sin(phi) * dxdz[1][0]; + dualFld_n[8] = -R / J * dxdz[0][0]; + + double norm1 = sqrt( + dualFld_n[0] * dualFld_n[0] + dualFld_n[1] * dualFld_n[1] + dualFld_n[2] * dualFld_n[2] + ); + double norm2 = sqrt( + dualFld_n[3] * dualFld_n[3] + dualFld_n[4] * dualFld_n[4] + dualFld_n[5] * dualFld_n[5] + ); + double norm3 = sqrt( + dualFld_n[6] * dualFld_n[6] + dualFld_n[7] * dualFld_n[7] + dualFld_n[8] * dualFld_n[8] + ); double *dualmagFld_n = gkyl_array_fetch(dualmagFld_nodal, gkyl_range_idx(nrange, cidx)); dualmagFld_n[0] = norm1; dualmagFld_n[1] = norm2; dualmagFld_n[2] = norm3; - + // Set normal vectors double *normFld_n = gkyl_array_fetch(normFld_nodal, gkyl_range_idx(nrange, cidx)); - normFld_n[0] = dualFld_n[0]/norm1; - normFld_n[1] = dualFld_n[1]/norm1; - normFld_n[2] = dualFld_n[2]/norm1; + normFld_n[0] = dualFld_n[0] / norm1; + normFld_n[1] = dualFld_n[1] / norm1; + normFld_n[2] = dualFld_n[2] / norm1; - normFld_n[3] = dualFld_n[3]/norm2; - normFld_n[4] = dualFld_n[4]/norm2; - normFld_n[5] = dualFld_n[5]/norm2; + normFld_n[3] = dualFld_n[3] / norm2; + normFld_n[4] = dualFld_n[4] / norm2; + normFld_n[5] = dualFld_n[5] / norm2; - normFld_n[6] = dualFld_n[6]/norm3; - normFld_n[7] = dualFld_n[7]/norm3; - normFld_n[8] = dualFld_n[8]/norm3; + normFld_n[6] = dualFld_n[6] / norm3; + normFld_n[7] = dualFld_n[7] / norm3; + normFld_n[8] = dualFld_n[8] / norm3; } } } gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 6, gFld_nodal, gFld, true); gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 1, jFld_nodal, jFld, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 3, bcartFld_nodal, bcartFld, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, tanvecFld_nodal, tanvecFld, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, dualFld_nodal, dualFld, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 3, dualmagFld_nodal, dualmagFld, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, normFld_nodal, normFld, true); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 3, bcartFld_nodal, bcartFld, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, tanvecFld_nodal, tanvecFld, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, dualFld_nodal, dualFld, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 3, dualmagFld_nodal, dualmagFld, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, normFld_nodal, normFld, true + ); gkyl_array_release(gFld_nodal); gkyl_array_release(jFld_nodal); gkyl_array_release(bcartFld_nodal); @@ -1125,45 +1424,46 @@ void gkyl_calc_metric_advance_mirror_interior( } void gkyl_calc_metric_advance_mirror_surface( - gkyl_calc_metric *up, int dir, struct gkyl_range *nrange, - struct gkyl_array *mc2p_nodal_fd, struct gkyl_array *ddtheta_nodal, - struct gkyl_array *bmag_nodal, double *dzc, - struct gkyl_array *jFld_nodal, - struct gkyl_array *biFld_nodal, - struct gkyl_array *cmagFld_nodal, - struct gkyl_array *jtotinvFld_nodal, - const struct gkyl_range *update_range) + gkyl_calc_metric *up, int dir, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, + struct gkyl_array *ddtheta_nodal, struct gkyl_array *bmag_nodal, double *dzc, + struct gkyl_array *jFld_nodal, struct gkyl_array *biFld_nodal, struct gkyl_array *cmagFld_nodal, + struct gkyl_array *jtotinvFld_nodal, const struct gkyl_range *update_range +) { - struct gkyl_array* gFld_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange->volume); + struct gkyl_array *gFld_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange->volume); enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { R_IDX, Z_IDX, PHI_IDX }; // arrangement of cartesian coordinates int cidx[3]; - for(int ia=nrange->lower[AL_IDX]; ia<=nrange->upper[AL_IDX]; ++ia){ - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { + for (int ia = nrange->lower[AL_IDX]; ia <= nrange->upper[AL_IDX]; ++ia) { + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; const double *mc2p_n = gkyl_array_cfetch(mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); double dxdz[3][3]; - if((ip == nrange->lower[PSI_IDX]) && (up->local.lower[PSI_IDX]== up->global.lower[PSI_IDX]) && dir==0) { - dxdz[0][0] = (-3*mc2p_n[R_IDX] + 4*mc2p_n[6+R_IDX] - mc2p_n[12+R_IDX] )/dzc[0]/2; - dxdz[1][0] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[6+Z_IDX] - mc2p_n[12+Z_IDX] )/dzc[0]/2; - dxdz[2][0] = (-3*mc2p_n[PHI_IDX] + 4*mc2p_n[6+PHI_IDX] - mc2p_n[12+PHI_IDX] )/dzc[0]/2; - } - else if((ip == nrange->upper[PSI_IDX]) && (up->local.upper[PSI_IDX]== up->global.upper[PSI_IDX]) && dir==0) { - dxdz[0][0] = (3*mc2p_n[R_IDX] - 4*mc2p_n[3+R_IDX] + mc2p_n[9+R_IDX] )/dzc[0]/2; - dxdz[1][0] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[3+Z_IDX] + mc2p_n[9+Z_IDX] )/dzc[0]/2; - dxdz[2][0] = (3*mc2p_n[PHI_IDX] - 4*mc2p_n[3+PHI_IDX] + mc2p_n[9+PHI_IDX] )/dzc[0]/2; - } - else { - dxdz[0][0] = -(mc2p_n[3 +R_IDX] - mc2p_n[6+R_IDX])/2/dzc[0]; - dxdz[1][0] = -(mc2p_n[3 +Z_IDX] - mc2p_n[6+Z_IDX])/2/dzc[0]; - dxdz[2][0] = -(mc2p_n[3 +PHI_IDX] - mc2p_n[6+PHI_IDX])/2/dzc[0]; + if ((ip == nrange->lower[PSI_IDX]) && + (up->local.lower[PSI_IDX] == up->global.lower[PSI_IDX]) && dir == 0) { + dxdz[0][0] = + (-3 * mc2p_n[R_IDX] + 4 * mc2p_n[6 + R_IDX] - mc2p_n[12 + R_IDX]) / dzc[0] / 2; + dxdz[1][0] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[6 + Z_IDX] - mc2p_n[12 + Z_IDX]) / dzc[0] / 2; + dxdz[2][0] = + (-3 * mc2p_n[PHI_IDX] + 4 * mc2p_n[6 + PHI_IDX] - mc2p_n[12 + PHI_IDX]) / dzc[0] / 2; + } else if ((ip == nrange->upper[PSI_IDX]) && + (up->local.upper[PSI_IDX] == up->global.upper[PSI_IDX]) && dir == 0) { + dxdz[0][0] = (3 * mc2p_n[R_IDX] - 4 * mc2p_n[3 + R_IDX] + mc2p_n[9 + R_IDX]) / dzc[0] / 2; + dxdz[1][0] = (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[3 + Z_IDX] + mc2p_n[9 + Z_IDX]) / dzc[0] / 2; + dxdz[2][0] = + (3 * mc2p_n[PHI_IDX] - 4 * mc2p_n[3 + PHI_IDX] + mc2p_n[9 + PHI_IDX]) / dzc[0] / 2; + } else { + dxdz[0][0] = -(mc2p_n[3 + R_IDX] - mc2p_n[6 + R_IDX]) / 2 / dzc[0]; + dxdz[1][0] = -(mc2p_n[3 + Z_IDX] - mc2p_n[6 + Z_IDX]) / 2 / dzc[0]; + dxdz[2][0] = -(mc2p_n[3 + PHI_IDX] - mc2p_n[6 + PHI_IDX]) / 2 / dzc[0]; } - // Use exact expressions for dR/dtheta, dZ/dtheta, and dphidtheta + // Use exact expressions for dR/dtheta, dZ/dtheta, and dphidtheta double *ddtheta_n = gkyl_array_fetch(ddtheta_nodal, gkyl_range_idx(nrange, cidx)); dxdz[0][2] = ddtheta_n[0]; // dR/dtheta dxdz[1][2] = ddtheta_n[1]; // dZ/dtheta @@ -1172,190 +1472,227 @@ void gkyl_calc_metric_advance_mirror_surface( double R = mc2p_n[R_IDX]; double *bmag_n = gkyl_array_fetch(bmag_nodal, gkyl_range_idx(nrange, cidx)); - double *gFld_n= gkyl_array_fetch(gFld_nodal, gkyl_range_idx(nrange, cidx)); - gFld_n[5] = dxdz[0][2]*dxdz[0][2] + dxdz[1][2]*dxdz[1][2]; + double *gFld_n = gkyl_array_fetch(gFld_nodal, gkyl_range_idx(nrange, cidx)); + gFld_n[5] = dxdz[0][2] * dxdz[0][2] + dxdz[1][2] * dxdz[1][2]; // dxdz is in cylindrical coordinates. Caculate dR/dpsi as // dR/dpsi = (1/(dZ/dtheta) ) * [sqrt(g_33)/RB + dR/dtheta*dZ/dtheta] // because this is more reliable near R=0 than using finite differences - double dRdpsi = 1/dxdz[1][2]*(sqrt(gFld_n[5])/bmag_n[0]/R + dxdz[0][2]*dxdz[1][0]); + double dRdpsi = + 1 / dxdz[1][2] * (sqrt(gFld_n[5]) / bmag_n[0] / R + dxdz[0][2] * dxdz[1][0]); // Calculate J as J = R(dR/dpsi*dZ/dtheta - dR/dtheta*dZ/dpsi) - double *jFld_n= gkyl_array_fetch(jFld_nodal, gkyl_range_idx(nrange, cidx)); - jFld_n[0] = sqrt(R*R*( dRdpsi*dRdpsi*dxdz[1][2]*dxdz[1][2] - +dxdz[0][2]*dxdz[0][2]*dxdz[1][0]*dxdz[1][0] - -2*dRdpsi*dxdz[0][2]*dxdz[1][0]*dxdz[1][2] )); - - gFld_n[0] = dRdpsi*dRdpsi + dxdz[1][0]*dxdz[1][0]; - gFld_n[1] = 0.0; - gFld_n[2] = dRdpsi*dxdz[0][2] + dxdz[1][0]*dxdz[1][2]; - gFld_n[3] = R*R; - gFld_n[4] = 0.0; + double *jFld_n = gkyl_array_fetch(jFld_nodal, gkyl_range_idx(nrange, cidx)); + jFld_n[0] = sqrt( + R * R * + (dRdpsi * dRdpsi * dxdz[1][2] * dxdz[1][2] + + dxdz[0][2] * dxdz[0][2] * dxdz[1][0] * dxdz[1][0] - + 2 * dRdpsi * dxdz[0][2] * dxdz[1][0] * dxdz[1][2]) + ); + + gFld_n[0] = dRdpsi * dRdpsi + dxdz[1][0] * dxdz[1][0]; + gFld_n[1] = 0.0; + gFld_n[2] = dRdpsi * dxdz[0][2] + dxdz[1][0] * dxdz[1][2]; + gFld_n[3] = R * R; + gFld_n[4] = 0.0; // Calculate cmag, bi, and jtot_inv - double *biFld_n= gkyl_array_fetch(biFld_nodal, gkyl_range_idx(nrange, cidx)); - biFld_n[0] = gFld_n[2]/sqrt(gFld_n[5]); - biFld_n[1] = gFld_n[4]/sqrt(gFld_n[5]); - biFld_n[2] = gFld_n[5]/sqrt(gFld_n[5]); - - double *cmagFld_n= gkyl_array_fetch(cmagFld_nodal, gkyl_range_idx(nrange, cidx)); - cmagFld_n[0] = jFld_n[0]*bmag_n[0]/sqrt(gFld_n[5]); - double *jtotinvFld_n= gkyl_array_fetch(jtotinvFld_nodal, gkyl_range_idx(nrange, cidx)); - jtotinvFld_n[0] = 1.0/(jFld_n[0]*bmag_n[0]); + double *biFld_n = gkyl_array_fetch(biFld_nodal, gkyl_range_idx(nrange, cidx)); + biFld_n[0] = gFld_n[2] / sqrt(gFld_n[5]); + biFld_n[1] = gFld_n[4] / sqrt(gFld_n[5]); + biFld_n[2] = gFld_n[5] / sqrt(gFld_n[5]); + + double *cmagFld_n = gkyl_array_fetch(cmagFld_nodal, gkyl_range_idx(nrange, cidx)); + cmagFld_n[0] = jFld_n[0] * bmag_n[0] / sqrt(gFld_n[5]); + double *jtotinvFld_n = gkyl_array_fetch(jtotinvFld_nodal, gkyl_range_idx(nrange, cidx)); + jtotinvFld_n[0] = 1.0 / (jFld_n[0] * bmag_n[0]); } } } gkyl_array_release(gFld_nodal); } -void gkyl_calc_metric_advance(gkyl_calc_metric *up, struct gkyl_range *nrange, - struct gkyl_array *mc2p_nodal_fd, double *dzc, - struct gkyl_array *gFld, - struct gkyl_array *tanvecFld, - struct gkyl_array *dualFld, - struct gkyl_array *dualmagFld, - struct gkyl_array *normFld, - const struct gkyl_range *update_range) +void gkyl_calc_metric_advance( + gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, double *dzc, + struct gkyl_array *gFld, struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, + struct gkyl_array *dualmagFld, struct gkyl_array *normFld, const struct gkyl_range *update_range +) { - struct gkyl_array* gFld_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange->volume); - struct gkyl_array* tanvecFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); - struct gkyl_array* dualFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); - struct gkyl_array* dualmagFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); - struct gkyl_array* normFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *gFld_nodal = gkyl_array_new(GKYL_DOUBLE, 6, nrange->volume); + struct gkyl_array *tanvecFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *dualFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *dualmagFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); + struct gkyl_array *normFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { X_IDX, Y_IDX, Z_IDX }; // arrangement of cartesian coordinates int cidx[3]; - - for (int ia=nrange->lower[AL_IDX]; ia<=nrange->upper[AL_IDX]; ++ia) { - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { - cidx[PSI_IDX] = ip; - cidx[AL_IDX] = ia; - cidx[TH_IDX] = it; - const double *mc2p_n = gkyl_array_cfetch(mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); - double dxdz[3][3]; // tan vecs at node - double dzdx[3][3]; // duals at node - - if((ip == nrange->lower[PSI_IDX]) && (up->local.lower[PSI_IDX]== up->global.lower[PSI_IDX]) ) { - dxdz[0][0] = (-3*mc2p_n[X_IDX] + 4*mc2p_n[6+X_IDX] - mc2p_n[12+X_IDX] )/dzc[0]/2; - dxdz[1][0] = (-3*mc2p_n[Y_IDX] + 4*mc2p_n[6+Y_IDX] - mc2p_n[12+Y_IDX] )/dzc[0]/2; - dxdz[2][0] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[6+Z_IDX] - mc2p_n[12+Z_IDX] )/dzc[0]/2; - } - else if((ip == nrange->upper[PSI_IDX]) && (up->local.upper[PSI_IDX]== up->global.upper[PSI_IDX])) { - dxdz[0][0] = (3*mc2p_n[X_IDX] - 4*mc2p_n[3+X_IDX] + mc2p_n[9+X_IDX] )/dzc[0]/2; - dxdz[1][0] = (3*mc2p_n[Y_IDX] - 4*mc2p_n[3+Y_IDX] + mc2p_n[9+Y_IDX] )/dzc[0]/2; - dxdz[2][0] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[3+Z_IDX] + mc2p_n[9+Z_IDX] )/dzc[0]/2; - } - else{ - dxdz[0][0] = -(mc2p_n[3 +X_IDX] - mc2p_n[6+X_IDX])/2/dzc[0]; - dxdz[1][0] = -(mc2p_n[3 +Y_IDX] - mc2p_n[6+Y_IDX])/2/dzc[0]; - dxdz[2][0] = -(mc2p_n[3 +Z_IDX] - mc2p_n[6+Z_IDX])/2/dzc[0]; - } + for (int ia = nrange->lower[AL_IDX]; ia <= nrange->upper[AL_IDX]; ++ia) { + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { + cidx[PSI_IDX] = ip; + cidx[AL_IDX] = ia; + cidx[TH_IDX] = it; + const double *mc2p_n = gkyl_array_cfetch(mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); + double dxdz[3][3]; // tan vecs at node + double dzdx[3][3]; // duals at node - if((ia == nrange->lower[AL_IDX]) && (up->local.lower[AL_IDX]== up->global.lower[AL_IDX]) ) { - dxdz[0][1] = (-3*mc2p_n[X_IDX] + 4*mc2p_n[18+X_IDX] - mc2p_n[24+X_IDX])/dzc[1]/2; - dxdz[1][1] = (-3*mc2p_n[Y_IDX] + 4*mc2p_n[18+Y_IDX] - mc2p_n[24+Y_IDX])/dzc[1]/2; - dxdz[2][1] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[18+Z_IDX] - mc2p_n[24+Z_IDX])/dzc[1]/2; - } - else if((ia == nrange->upper[AL_IDX]) && (up->local.upper[AL_IDX]== up->global.upper[AL_IDX])) { - dxdz[0][1] = (3*mc2p_n[X_IDX] - 4*mc2p_n[15+X_IDX] + mc2p_n[21+X_IDX] )/dzc[1]/2; - dxdz[1][1] = (3*mc2p_n[Y_IDX] - 4*mc2p_n[15+Y_IDX] + mc2p_n[21+Y_IDX] )/dzc[1]/2; - dxdz[2][1] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[15+Z_IDX] + mc2p_n[21+Z_IDX] )/dzc[1]/2; - } - else { - dxdz[0][1] = -(mc2p_n[15 +X_IDX] - mc2p_n[18 +X_IDX])/2/dzc[1]; - dxdz[1][1] = -(mc2p_n[15 +Y_IDX] - mc2p_n[18 +Y_IDX])/2/dzc[1]; - dxdz[2][1] = -(mc2p_n[15 +Z_IDX] - mc2p_n[18 +Z_IDX])/2/dzc[1]; - } + if ((ip == nrange->lower[PSI_IDX]) && + (up->local.lower[PSI_IDX] == up->global.lower[PSI_IDX])) { + dxdz[0][0] = + (-3 * mc2p_n[X_IDX] + 4 * mc2p_n[6 + X_IDX] - mc2p_n[12 + X_IDX]) / dzc[0] / 2; + dxdz[1][0] = + (-3 * mc2p_n[Y_IDX] + 4 * mc2p_n[6 + Y_IDX] - mc2p_n[12 + Y_IDX]) / dzc[0] / 2; + dxdz[2][0] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[6 + Z_IDX] - mc2p_n[12 + Z_IDX]) / dzc[0] / 2; + } else if ((ip == nrange->upper[PSI_IDX]) && + (up->local.upper[PSI_IDX] == up->global.upper[PSI_IDX])) { + dxdz[0][0] = (3 * mc2p_n[X_IDX] - 4 * mc2p_n[3 + X_IDX] + mc2p_n[9 + X_IDX]) / dzc[0] / 2; + dxdz[1][0] = (3 * mc2p_n[Y_IDX] - 4 * mc2p_n[3 + Y_IDX] + mc2p_n[9 + Y_IDX]) / dzc[0] / 2; + dxdz[2][0] = (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[3 + Z_IDX] + mc2p_n[9 + Z_IDX]) / dzc[0] / 2; + } else { + dxdz[0][0] = -(mc2p_n[3 + X_IDX] - mc2p_n[6 + X_IDX]) / 2 / dzc[0]; + dxdz[1][0] = -(mc2p_n[3 + Y_IDX] - mc2p_n[6 + Y_IDX]) / 2 / dzc[0]; + dxdz[2][0] = -(mc2p_n[3 + Z_IDX] - mc2p_n[6 + Z_IDX]) / 2 / dzc[0]; + } - if((it == nrange->lower[TH_IDX]) && (up->local.lower[TH_IDX]== up->global.lower[TH_IDX])) { - dxdz[0][2] = (-3*mc2p_n[X_IDX] + 4*mc2p_n[30+X_IDX] - mc2p_n[36+X_IDX])/dzc[2]/2; - dxdz[1][2] = (-3*mc2p_n[Y_IDX] + 4*mc2p_n[30+Y_IDX] - mc2p_n[36+Y_IDX])/dzc[2]/2; - dxdz[2][2] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[30+Z_IDX] - mc2p_n[36+Z_IDX])/dzc[2]/2; - } - else if((it == nrange->upper[TH_IDX]) && (up->local.upper[TH_IDX]== up->global.upper[TH_IDX])) { - dxdz[0][2] = (3*mc2p_n[X_IDX] - 4*mc2p_n[27+X_IDX] + mc2p_n[33+X_IDX] )/dzc[2]/2; - dxdz[1][2] = (3*mc2p_n[Y_IDX] - 4*mc2p_n[27+Y_IDX] + mc2p_n[33+Y_IDX] )/dzc[2]/2; - dxdz[2][2] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[27+Z_IDX] + mc2p_n[33+Z_IDX] )/dzc[2]/2; - } - else{ - dxdz[0][2] = -(mc2p_n[27 +X_IDX] - mc2p_n[30 +X_IDX])/2/dzc[2]; - dxdz[1][2] = -(mc2p_n[27 +Y_IDX] - mc2p_n[30 +Y_IDX])/2/dzc[2]; - dxdz[2][2] = -(mc2p_n[27 +Z_IDX] - mc2p_n[30 +Z_IDX])/2/dzc[2]; - } + if ((ia == nrange->lower[AL_IDX]) && + (up->local.lower[AL_IDX] == up->global.lower[AL_IDX])) { + dxdz[0][1] = + (-3 * mc2p_n[X_IDX] + 4 * mc2p_n[18 + X_IDX] - mc2p_n[24 + X_IDX]) / dzc[1] / 2; + dxdz[1][1] = + (-3 * mc2p_n[Y_IDX] + 4 * mc2p_n[18 + Y_IDX] - mc2p_n[24 + Y_IDX]) / dzc[1] / 2; + dxdz[2][1] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[18 + Z_IDX] - mc2p_n[24 + Z_IDX]) / dzc[1] / 2; + } else if ((ia == nrange->upper[AL_IDX]) && + (up->local.upper[AL_IDX] == up->global.upper[AL_IDX])) { + dxdz[0][1] = + (3 * mc2p_n[X_IDX] - 4 * mc2p_n[15 + X_IDX] + mc2p_n[21 + X_IDX]) / dzc[1] / 2; + dxdz[1][1] = + (3 * mc2p_n[Y_IDX] - 4 * mc2p_n[15 + Y_IDX] + mc2p_n[21 + Y_IDX]) / dzc[1] / 2; + dxdz[2][1] = + (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[15 + Z_IDX] + mc2p_n[21 + Z_IDX]) / dzc[1] / 2; + } else { + dxdz[0][1] = -(mc2p_n[15 + X_IDX] - mc2p_n[18 + X_IDX]) / 2 / dzc[1]; + dxdz[1][1] = -(mc2p_n[15 + Y_IDX] - mc2p_n[18 + Y_IDX]) / 2 / dzc[1]; + dxdz[2][1] = -(mc2p_n[15 + Z_IDX] - mc2p_n[18 + Z_IDX]) / 2 / dzc[1]; + } + + if ((it == nrange->lower[TH_IDX]) && + (up->local.lower[TH_IDX] == up->global.lower[TH_IDX])) { + dxdz[0][2] = + (-3 * mc2p_n[X_IDX] + 4 * mc2p_n[30 + X_IDX] - mc2p_n[36 + X_IDX]) / dzc[2] / 2; + dxdz[1][2] = + (-3 * mc2p_n[Y_IDX] + 4 * mc2p_n[30 + Y_IDX] - mc2p_n[36 + Y_IDX]) / dzc[2] / 2; + dxdz[2][2] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[30 + Z_IDX] - mc2p_n[36 + Z_IDX]) / dzc[2] / 2; + } else if ((it == nrange->upper[TH_IDX]) && + (up->local.upper[TH_IDX] == up->global.upper[TH_IDX])) { + dxdz[0][2] = + (3 * mc2p_n[X_IDX] - 4 * mc2p_n[27 + X_IDX] + mc2p_n[33 + X_IDX]) / dzc[2] / 2; + dxdz[1][2] = + (3 * mc2p_n[Y_IDX] - 4 * mc2p_n[27 + Y_IDX] + mc2p_n[33 + Y_IDX]) / dzc[2] / 2; + dxdz[2][2] = + (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[27 + Z_IDX] + mc2p_n[33 + Z_IDX]) / dzc[2] / 2; + } else { + dxdz[0][2] = -(mc2p_n[27 + X_IDX] - mc2p_n[30 + X_IDX]) / 2 / dzc[2]; + dxdz[1][2] = -(mc2p_n[27 + Y_IDX] - mc2p_n[30 + Y_IDX]) / 2 / dzc[2]; + dxdz[2][2] = -(mc2p_n[27 + Z_IDX] - mc2p_n[30 + Z_IDX]) / 2 / dzc[2]; + } + + double *gFld_n = gkyl_array_fetch(gFld_nodal, gkyl_range_idx(nrange, cidx)); + gFld_n[0] = calc_metric(dxdz, 1, 1); + gFld_n[1] = calc_metric(dxdz, 1, 2); + gFld_n[2] = calc_metric(dxdz, 1, 3); + gFld_n[3] = calc_metric(dxdz, 2, 2); + gFld_n[4] = calc_metric(dxdz, 2, 3); + gFld_n[5] = calc_metric(dxdz, 3, 3); + + double Jsq = gFld_n[0] * (gFld_n[3] * gFld_n[5] - gFld_n[4] * gFld_n[4]) - + gFld_n[1] * (gFld_n[1] * gFld_n[5] - gFld_n[4] * gFld_n[2]) + + gFld_n[2] * (gFld_n[1] * gFld_n[4] - gFld_n[3] * gFld_n[2]); + double J = sqrt(Jsq); + double e_1[3], e_2[3], e_3[3]; + e_1[0] = dxdz[0][0]; + e_1[1] = dxdz[1][0]; + e_1[2] = dxdz[2][0]; + e_2[0] = dxdz[0][1]; + e_2[1] = dxdz[1][1]; + e_2[2] = dxdz[2][1]; + e_3[0] = dxdz[0][2]; + e_3[1] = dxdz[1][2]; + e_3[2] = dxdz[2][2]; + calc_dual(J, e_2, e_3, dzdx[0]); + calc_dual(J, e_3, e_1, dzdx[1]); + calc_dual(J, e_1, e_2, dzdx[2]); + + double *dualFld_n = gkyl_array_fetch(dualFld_nodal, gkyl_range_idx(nrange, cidx)); + dualFld_n[0] = dzdx[0][0]; + dualFld_n[1] = dzdx[0][1]; + dualFld_n[2] = dzdx[0][2]; + dualFld_n[3] = dzdx[1][0]; + dualFld_n[4] = dzdx[1][1]; + dualFld_n[5] = dzdx[1][2]; + dualFld_n[6] = dzdx[2][0]; + dualFld_n[7] = dzdx[2][1]; + dualFld_n[8] = dzdx[2][2]; + + double *tanvecFld_n = gkyl_array_fetch(tanvecFld_nodal, gkyl_range_idx(nrange, cidx)); + tanvecFld_n[0] = dxdz[0][0]; + tanvecFld_n[1] = dxdz[1][0]; + tanvecFld_n[2] = dxdz[2][0]; + tanvecFld_n[3] = dxdz[0][1]; + tanvecFld_n[4] = dxdz[1][1]; + tanvecFld_n[5] = dxdz[2][1]; + tanvecFld_n[6] = dxdz[0][2]; + tanvecFld_n[7] = dxdz[1][2]; + tanvecFld_n[8] = dxdz[2][2]; + + double norm1 = sqrt( + dualFld_n[0] * dualFld_n[0] + dualFld_n[1] * dualFld_n[1] + dualFld_n[2] * dualFld_n[2] + ); + double norm2 = sqrt( + dualFld_n[3] * dualFld_n[3] + dualFld_n[4] * dualFld_n[4] + dualFld_n[5] * dualFld_n[5] + ); + double norm3 = sqrt( + dualFld_n[6] * dualFld_n[6] + dualFld_n[7] * dualFld_n[7] + dualFld_n[8] * dualFld_n[8] + ); + + double *dualmagFld_n = gkyl_array_fetch(dualmagFld_nodal, gkyl_range_idx(nrange, cidx)); + dualmagFld_n[0] = norm1; + dualmagFld_n[1] = norm2; + dualmagFld_n[2] = norm3; + + // Set normal vectors + double *normFld_n = gkyl_array_fetch(normFld_nodal, gkyl_range_idx(nrange, cidx)); + normFld_n[0] = dualFld_n[0] / norm1; + normFld_n[1] = dualFld_n[1] / norm1; + normFld_n[2] = dualFld_n[2] / norm1; + + normFld_n[3] = dualFld_n[3] / norm2; + normFld_n[4] = dualFld_n[4] / norm2; + normFld_n[5] = dualFld_n[5] / norm2; - double *gFld_n= gkyl_array_fetch(gFld_nodal, gkyl_range_idx(nrange, cidx)); - gFld_n[0] = calc_metric(dxdz, 1, 1); - gFld_n[1] = calc_metric(dxdz, 1, 2); - gFld_n[2] = calc_metric(dxdz, 1, 3); - gFld_n[3] = calc_metric(dxdz, 2, 2); - gFld_n[4] = calc_metric(dxdz, 2, 3); - gFld_n[5] = calc_metric(dxdz, 3, 3); - - double Jsq = gFld_n[0]*( gFld_n[3]*gFld_n[5] - gFld_n[4]*gFld_n[4] ) - -gFld_n[1]*( gFld_n[1]*gFld_n[5] - gFld_n[4]*gFld_n[2] ) - +gFld_n[2]*( gFld_n[1]*gFld_n[4] - gFld_n[3]*gFld_n[2] ); - double J = sqrt(Jsq); - double e_1[3], e_2[3], e_3[3]; - e_1[0] = dxdz[0][0]; e_1[1] = dxdz[1][0]; e_1[2] = dxdz[2][0]; - e_2[0] = dxdz[0][1]; e_2[1] = dxdz[1][1]; e_2[2] = dxdz[2][1]; - e_3[0] = dxdz[0][2]; e_3[1] = dxdz[1][2]; e_3[2] = dxdz[2][2]; - calc_dual(J, e_2, e_3, dzdx[0]); - calc_dual(J, e_3, e_1, dzdx[1]); - calc_dual(J, e_1, e_2, dzdx[2]); - - double *dualFld_n= gkyl_array_fetch(dualFld_nodal, gkyl_range_idx(nrange, cidx)); - dualFld_n[0] = dzdx[0][0]; - dualFld_n[1] = dzdx[0][1]; - dualFld_n[2] = dzdx[0][2]; - dualFld_n[3] = dzdx[1][0]; - dualFld_n[4] = dzdx[1][1]; - dualFld_n[5] = dzdx[1][2]; - dualFld_n[6] = dzdx[2][0]; - dualFld_n[7] = dzdx[2][1]; - dualFld_n[8] = dzdx[2][2]; - - double *tanvecFld_n= gkyl_array_fetch(tanvecFld_nodal, gkyl_range_idx(nrange, cidx)); - tanvecFld_n[0] = dxdz[0][0]; - tanvecFld_n[1] = dxdz[1][0]; - tanvecFld_n[2] = dxdz[2][0]; - tanvecFld_n[3] = dxdz[0][1]; - tanvecFld_n[4] = dxdz[1][1]; - tanvecFld_n[5] = dxdz[2][1]; - tanvecFld_n[6] = dxdz[0][2]; - tanvecFld_n[7] = dxdz[1][2]; - tanvecFld_n[8] = dxdz[2][2]; - - double norm1 = sqrt(dualFld_n[0]*dualFld_n[0] + dualFld_n[1]*dualFld_n[1] + dualFld_n[2]*dualFld_n[2]); - double norm2 = sqrt(dualFld_n[3]*dualFld_n[3] + dualFld_n[4]*dualFld_n[4] + dualFld_n[5]*dualFld_n[5]); - double norm3 = sqrt(dualFld_n[6]*dualFld_n[6] + dualFld_n[7]*dualFld_n[7] + dualFld_n[8]*dualFld_n[8]); - - double *dualmagFld_n = gkyl_array_fetch(dualmagFld_nodal, gkyl_range_idx(nrange, cidx)); - dualmagFld_n[0] = norm1; - dualmagFld_n[1] = norm2; - dualmagFld_n[2] = norm3; - - // Set normal vectors - double *normFld_n = gkyl_array_fetch(normFld_nodal, gkyl_range_idx(nrange, cidx)); - normFld_n[0] = dualFld_n[0]/norm1; - normFld_n[1] = dualFld_n[1]/norm1; - normFld_n[2] = dualFld_n[2]/norm1; - - normFld_n[3] = dualFld_n[3]/norm2; - normFld_n[4] = dualFld_n[4]/norm2; - normFld_n[5] = dualFld_n[5]/norm2; - - normFld_n[6] = dualFld_n[6]/norm3; - normFld_n[7] = dualFld_n[7]/norm3; - normFld_n[8] = dualFld_n[8]/norm3; + normFld_n[6] = dualFld_n[6] / norm3; + normFld_n[7] = dualFld_n[7] / norm3; + normFld_n[8] = dualFld_n[8] / norm3; } } } - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 6, gFld_nodal, gFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, tanvecFld_nodal, tanvecFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, dualFld_nodal, dualFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 3, dualmagFld_nodal, dualmagFld, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, normFld_nodal, normFld, false); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 6, gFld_nodal, gFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, tanvecFld_nodal, tanvecFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, dualFld_nodal, dualFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 3, dualmagFld_nodal, dualmagFld, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, normFld_nodal, normFld, false + ); gkyl_array_release(gFld_nodal); gkyl_array_release(tanvecFld_nodal); gkyl_array_release(dualFld_nodal); @@ -1368,67 +1705,79 @@ void gkyl_calc_metric_advance_interior(gkyl_calc_metric *up, struct gk_geometry enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { X_IDX, Y_IDX, Z_IDX }; // arrangement of cartesian coordinates int cidx[3]; - - for(int ia=gk_geom->nrange_int.lower[AL_IDX]; ia<=gk_geom->nrange_int.upper[AL_IDX]; ++ia){ - for (int ip=gk_geom->nrange_int.lower[PSI_IDX]; ip<=gk_geom->nrange_int.upper[PSI_IDX]; ++ip) { - for (int it=gk_geom->nrange_int.lower[TH_IDX]; it<=gk_geom->nrange_int.upper[TH_IDX]; ++it) { + + for (int ia = gk_geom->nrange_int.lower[AL_IDX]; ia <= gk_geom->nrange_int.upper[AL_IDX]; ++ia) { + for (int ip = gk_geom->nrange_int.lower[PSI_IDX]; ip <= gk_geom->nrange_int.upper[PSI_IDX]; + ++ip) { + for (int it = gk_geom->nrange_int.lower[TH_IDX]; it <= gk_geom->nrange_int.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - const double *mc2p_n = gkyl_array_cfetch(gk_geom->geo_int.mc2p_nodal_fd, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + const double *mc2p_n = gkyl_array_cfetch( + gk_geom->geo_int.mc2p_nodal_fd, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); double dxdz[3][3]; // tan vecs at node double dzdx[3][3]; // duals at node - dxdz[0][0] = -(mc2p_n[3 +X_IDX] - mc2p_n[6+X_IDX])/2/gk_geom->dzc[0]; - dxdz[1][0] = -(mc2p_n[3 +Y_IDX] - mc2p_n[6+Y_IDX])/2/gk_geom->dzc[0]; - dxdz[2][0] = -(mc2p_n[3 +Z_IDX] - mc2p_n[6+Z_IDX])/2/gk_geom->dzc[0]; - - - dxdz[0][1] = -(mc2p_n[15 +X_IDX] - mc2p_n[18 +X_IDX])/2/gk_geom->dzc[1]; - dxdz[1][1] = -(mc2p_n[15 +Y_IDX] - mc2p_n[18 +Y_IDX])/2/gk_geom->dzc[1]; - dxdz[2][1] = -(mc2p_n[15 +Z_IDX] - mc2p_n[18 +Z_IDX])/2/gk_geom->dzc[1]; + dxdz[0][0] = -(mc2p_n[3 + X_IDX] - mc2p_n[6 + X_IDX]) / 2 / gk_geom->dzc[0]; + dxdz[1][0] = -(mc2p_n[3 + Y_IDX] - mc2p_n[6 + Y_IDX]) / 2 / gk_geom->dzc[0]; + dxdz[2][0] = -(mc2p_n[3 + Z_IDX] - mc2p_n[6 + Z_IDX]) / 2 / gk_geom->dzc[0]; - dxdz[0][2] = -(mc2p_n[27 +X_IDX] - mc2p_n[30 +X_IDX])/2/gk_geom->dzc[2]; - dxdz[1][2] = -(mc2p_n[27 +Y_IDX] - mc2p_n[30 +Y_IDX])/2/gk_geom->dzc[2]; - dxdz[2][2] = -(mc2p_n[27 +Z_IDX] - mc2p_n[30 +Z_IDX])/2/gk_geom->dzc[2]; + dxdz[0][1] = -(mc2p_n[15 + X_IDX] - mc2p_n[18 + X_IDX]) / 2 / gk_geom->dzc[1]; + dxdz[1][1] = -(mc2p_n[15 + Y_IDX] - mc2p_n[18 + Y_IDX]) / 2 / gk_geom->dzc[1]; + dxdz[2][1] = -(mc2p_n[15 + Z_IDX] - mc2p_n[18 + Z_IDX]) / 2 / gk_geom->dzc[1]; + dxdz[0][2] = -(mc2p_n[27 + X_IDX] - mc2p_n[30 + X_IDX]) / 2 / gk_geom->dzc[2]; + dxdz[1][2] = -(mc2p_n[27 + Y_IDX] - mc2p_n[30 + Y_IDX]) / 2 / gk_geom->dzc[2]; + dxdz[2][2] = -(mc2p_n[27 + Z_IDX] - mc2p_n[30 + Z_IDX]) / 2 / gk_geom->dzc[2]; - const double *bhat_n = gkyl_array_cfetch(gk_geom->geo_int.b_i_nodal_fd, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + const double *bhat_n = gkyl_array_cfetch( + gk_geom->geo_int.b_i_nodal_fd, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); double dbhatdz[3][3]; // tan vecs at node - dbhatdz[0][0] = -(bhat_n[3 +X_IDX] - bhat_n[6+X_IDX])/2/gk_geom->dzc[0]; - dbhatdz[1][0] = -(bhat_n[3 +Y_IDX] - bhat_n[6+Y_IDX])/2/gk_geom->dzc[0]; - dbhatdz[2][0] = -(bhat_n[3 +Z_IDX] - bhat_n[6+Z_IDX])/2/gk_geom->dzc[0]; - - dbhatdz[0][1] = -(bhat_n[15 +X_IDX] - bhat_n[18 +X_IDX])/2/gk_geom->dzc[1]; - dbhatdz[1][1] = -(bhat_n[15 +Y_IDX] - bhat_n[18 +Y_IDX])/2/gk_geom->dzc[1]; - dbhatdz[2][1] = -(bhat_n[15 +Z_IDX] - bhat_n[18 +Z_IDX])/2/gk_geom->dzc[1]; - - dbhatdz[0][2] = -(bhat_n[27 +X_IDX] - bhat_n[30 +X_IDX])/2/gk_geom->dzc[2]; - dbhatdz[1][2] = -(bhat_n[27 +Y_IDX] - bhat_n[30 +Y_IDX])/2/gk_geom->dzc[2]; - dbhatdz[2][2] = -(bhat_n[27 +Z_IDX] - bhat_n[30 +Z_IDX])/2/gk_geom->dzc[2]; - - double *gFld_n= gkyl_array_fetch(gk_geom->geo_int.g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - gFld_n[0] = calc_metric(dxdz, 1, 1); - gFld_n[1] = calc_metric(dxdz, 1, 2); - gFld_n[2] = calc_metric(dxdz, 1, 3); - gFld_n[3] = calc_metric(dxdz, 2, 2); - gFld_n[4] = calc_metric(dxdz, 2, 3); - gFld_n[5] = calc_metric(dxdz, 3, 3); - - double Jsq = gFld_n[0]*( gFld_n[3]*gFld_n[5] - gFld_n[4]*gFld_n[4] ) - -gFld_n[1]*( gFld_n[1]*gFld_n[5] - gFld_n[4]*gFld_n[2] ) - +gFld_n[2]*( gFld_n[1]*gFld_n[4] - gFld_n[3]*gFld_n[2] ); + dbhatdz[0][0] = -(bhat_n[3 + X_IDX] - bhat_n[6 + X_IDX]) / 2 / gk_geom->dzc[0]; + dbhatdz[1][0] = -(bhat_n[3 + Y_IDX] - bhat_n[6 + Y_IDX]) / 2 / gk_geom->dzc[0]; + dbhatdz[2][0] = -(bhat_n[3 + Z_IDX] - bhat_n[6 + Z_IDX]) / 2 / gk_geom->dzc[0]; + + dbhatdz[0][1] = -(bhat_n[15 + X_IDX] - bhat_n[18 + X_IDX]) / 2 / gk_geom->dzc[1]; + dbhatdz[1][1] = -(bhat_n[15 + Y_IDX] - bhat_n[18 + Y_IDX]) / 2 / gk_geom->dzc[1]; + dbhatdz[2][1] = -(bhat_n[15 + Z_IDX] - bhat_n[18 + Z_IDX]) / 2 / gk_geom->dzc[1]; + + dbhatdz[0][2] = -(bhat_n[27 + X_IDX] - bhat_n[30 + X_IDX]) / 2 / gk_geom->dzc[2]; + dbhatdz[1][2] = -(bhat_n[27 + Y_IDX] - bhat_n[30 + Y_IDX]) / 2 / gk_geom->dzc[2]; + dbhatdz[2][2] = -(bhat_n[27 + Z_IDX] - bhat_n[30 + Z_IDX]) / 2 / gk_geom->dzc[2]; + + double *gFld_n = + gkyl_array_fetch(gk_geom->geo_int.g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + gFld_n[0] = calc_metric(dxdz, 1, 1); + gFld_n[1] = calc_metric(dxdz, 1, 2); + gFld_n[2] = calc_metric(dxdz, 1, 3); + gFld_n[3] = calc_metric(dxdz, 2, 2); + gFld_n[4] = calc_metric(dxdz, 2, 3); + gFld_n[5] = calc_metric(dxdz, 3, 3); + + double Jsq = gFld_n[0] * (gFld_n[3] * gFld_n[5] - gFld_n[4] * gFld_n[4]) - + gFld_n[1] * (gFld_n[1] * gFld_n[5] - gFld_n[4] * gFld_n[2]) + + gFld_n[2] * (gFld_n[1] * gFld_n[4] - gFld_n[3] * gFld_n[2]); double J = sqrt(Jsq); double e_1[3], e_2[3], e_3[3]; - e_1[0] = dxdz[0][0]; e_1[1] = dxdz[1][0]; e_1[2] = dxdz[2][0]; - e_2[0] = dxdz[0][1]; e_2[1] = dxdz[1][1]; e_2[2] = dxdz[2][1]; - e_3[0] = dxdz[0][2]; e_3[1] = dxdz[1][2]; e_3[2] = dxdz[2][2]; + e_1[0] = dxdz[0][0]; + e_1[1] = dxdz[1][0]; + e_1[2] = dxdz[2][0]; + e_2[0] = dxdz[0][1]; + e_2[1] = dxdz[1][1]; + e_2[2] = dxdz[2][1]; + e_3[0] = dxdz[0][2]; + e_3[1] = dxdz[1][2]; + e_3[2] = dxdz[2][2]; calc_dual(J, e_2, e_3, dzdx[0]); calc_dual(J, e_3, e_1, dzdx[1]); calc_dual(J, e_1, e_2, dzdx[2]); - double *dualFld_n= gkyl_array_fetch(gk_geom->geo_int.dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *dualFld_n = + gkyl_array_fetch(gk_geom->geo_int.dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); dualFld_n[0] = dzdx[0][0]; dualFld_n[1] = dzdx[0][1]; dualFld_n[2] = dzdx[0][2]; @@ -1439,16 +1788,17 @@ void gkyl_calc_metric_advance_interior(gkyl_calc_metric *up, struct gk_geometry dualFld_n[7] = dzdx[2][1]; dualFld_n[8] = dzdx[2][2]; - double *tanvecFld_n= gkyl_array_fetch(gk_geom->geo_int.dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - tanvecFld_n[0] = dxdz[0][0]; - tanvecFld_n[1] = dxdz[1][0]; - tanvecFld_n[2] = dxdz[2][0]; - tanvecFld_n[3] = dxdz[0][1]; - tanvecFld_n[4] = dxdz[1][1]; - tanvecFld_n[5] = dxdz[2][1]; - tanvecFld_n[6] = dxdz[0][2]; - tanvecFld_n[7] = dxdz[1][2]; - tanvecFld_n[8] = dxdz[2][2]; + double *tanvecFld_n = + gkyl_array_fetch(gk_geom->geo_int.dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + tanvecFld_n[0] = dxdz[0][0]; + tanvecFld_n[1] = dxdz[1][0]; + tanvecFld_n[2] = dxdz[2][0]; + tanvecFld_n[3] = dxdz[0][1]; + tanvecFld_n[4] = dxdz[1][1]; + tanvecFld_n[5] = dxdz[2][1]; + tanvecFld_n[6] = dxdz[0][2]; + tanvecFld_n[7] = dxdz[1][2]; + tanvecFld_n[8] = dxdz[2][2]; // Check that the coordinate system has tangent/dual vectors // satisfying orthonormality, and that it's right handed. @@ -1457,37 +1807,51 @@ void gkyl_calc_metric_advance_interior(gkyl_calc_metric *up, struct gk_geometry // Check if bhat and e_3 are parallel. double bhat_vec[3] = {bhat_n[X_IDX], bhat_n[Y_IDX], bhat_n[Z_IDX]}; - double e_3_norm[3] = {tanvecFld_n[6]/sqrt(gFld_n[5]), - tanvecFld_n[7]/sqrt(gFld_n[5]), - tanvecFld_n[8]/sqrt(gFld_n[5])}; + double e_3_norm[3] = { + tanvecFld_n[6] / sqrt(gFld_n[5]), tanvecFld_n[7] / sqrt(gFld_n[5]), + tanvecFld_n[8] / sqrt(gFld_n[5]) + }; check_parallel(bhat_vec, e_3_norm, up->exit_at_checks); - double norm1 = sqrt(dualFld_n[0]*dualFld_n[0] + dualFld_n[1]*dualFld_n[1] + dualFld_n[2]*dualFld_n[2]); - double norm2 = sqrt(dualFld_n[3]*dualFld_n[3] + dualFld_n[4]*dualFld_n[4] + dualFld_n[5]*dualFld_n[5]); - double norm3 = sqrt(dualFld_n[6]*dualFld_n[6] + dualFld_n[7]*dualFld_n[7] + dualFld_n[8]*dualFld_n[8]); - - double *dualmagFld_n = gkyl_array_fetch(gk_geom->geo_int.dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double norm1 = sqrt( + dualFld_n[0] * dualFld_n[0] + dualFld_n[1] * dualFld_n[1] + dualFld_n[2] * dualFld_n[2] + ); + double norm2 = sqrt( + dualFld_n[3] * dualFld_n[3] + dualFld_n[4] * dualFld_n[4] + dualFld_n[5] * dualFld_n[5] + ); + double norm3 = sqrt( + dualFld_n[6] * dualFld_n[6] + dualFld_n[7] * dualFld_n[7] + dualFld_n[8] * dualFld_n[8] + ); + + double *dualmagFld_n = gkyl_array_fetch( + gk_geom->geo_int.dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); dualmagFld_n[0] = norm1; dualmagFld_n[1] = norm2; dualmagFld_n[2] = norm3; - + // Set normal vectors - double *normFld_n = gkyl_array_fetch(gk_geom->geo_int.normals_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - normFld_n[0] = dualFld_n[0]/norm1; - normFld_n[1] = dualFld_n[1]/norm1; - normFld_n[2] = dualFld_n[2]/norm1; - - normFld_n[3] = dualFld_n[3]/norm2; - normFld_n[4] = dualFld_n[4]/norm2; - normFld_n[5] = dualFld_n[5]/norm2; - - normFld_n[6] = dualFld_n[6]/norm3; - normFld_n[7] = dualFld_n[7]/norm3; - normFld_n[8] = dualFld_n[8]/norm3; - - double *bmag_n = gkyl_array_fetch(gk_geom->geo_int.bmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - // Set e^m \dot curl(bhat) - double *curlbhat_n = gkyl_array_fetch(gk_geom->geo_int.curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *normFld_n = gkyl_array_fetch( + gk_geom->geo_int.normals_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + normFld_n[0] = dualFld_n[0] / norm1; + normFld_n[1] = dualFld_n[1] / norm1; + normFld_n[2] = dualFld_n[2] / norm1; + + normFld_n[3] = dualFld_n[3] / norm2; + normFld_n[4] = dualFld_n[4] / norm2; + normFld_n[5] = dualFld_n[5] / norm2; + + normFld_n[6] = dualFld_n[6] / norm3; + normFld_n[7] = dualFld_n[7] / norm3; + normFld_n[8] = dualFld_n[8] / norm3; + + double *bmag_n = + gkyl_array_fetch(gk_geom->geo_int.bmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + // Set e^m \dot curl(bhat) + double *curlbhat_n = gkyl_array_fetch( + gk_geom->geo_int.curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); // I first need the derivatives of B_X,Y,Z wrt XYZ double dbhatdX[3][3]; matTvec(dzdx, dbhatdz[0], dbhatdX[0]); @@ -1496,46 +1860,88 @@ void gkyl_calc_metric_advance_interior(gkyl_calc_metric *up, struct gk_geometry curlbhat_n[0] = (dbhatdX[2][1] - dbhatdX[1][2]); curlbhat_n[1] = (dbhatdX[0][2] - dbhatdX[2][0]); curlbhat_n[2] = (dbhatdX[1][0] - dbhatdX[0][1]); - double *dualcurlbhat_n = gkyl_array_fetch(gk_geom->geo_int.dualcurlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - dualcurlbhat_n[0] = dualFld_n[0]*curlbhat_n[0] + dualFld_n[1]*curlbhat_n[1] + dualFld_n[2]*curlbhat_n[2]; - dualcurlbhat_n[1] = dualFld_n[3]*curlbhat_n[0] + dualFld_n[4]*curlbhat_n[1] + dualFld_n[5]*curlbhat_n[2]; - dualcurlbhat_n[2] = dualFld_n[6]*curlbhat_n[0] + dualFld_n[7]*curlbhat_n[1] + dualFld_n[8]*curlbhat_n[2]; - - // Set e^3 \dot B - double *B3_n = gkyl_array_fetch(gk_geom->geo_int.B3_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - B3_n[0] = bmag_n[0]/sqrt(gFld_n[5]); + double *dualcurlbhat_n = gkyl_array_fetch( + gk_geom->geo_int.dualcurlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + dualcurlbhat_n[0] = dualFld_n[0] * curlbhat_n[0] + dualFld_n[1] * curlbhat_n[1] + + dualFld_n[2] * curlbhat_n[2]; + dualcurlbhat_n[1] = dualFld_n[3] * curlbhat_n[0] + dualFld_n[4] * curlbhat_n[1] + + dualFld_n[5] * curlbhat_n[2]; + dualcurlbhat_n[2] = dualFld_n[6] * curlbhat_n[0] + dualFld_n[7] * curlbhat_n[1] + + dualFld_n[8] * curlbhat_n[2]; + + // Set e^3 \dot B + double *B3_n = + gkyl_array_fetch(gk_geom->geo_int.B3_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + B3_n[0] = bmag_n[0] / sqrt(gFld_n[5]); // set e^3 \dot B /|B| - double *dualcurlbhatoverB_n = gkyl_array_fetch(gk_geom->geo_int.dualcurlbhatoverB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - dualcurlbhatoverB_n[0] = dualcurlbhat_n[0]/bmag_n[0]; - dualcurlbhatoverB_n[1] = dualcurlbhat_n[1]/bmag_n[0]; - dualcurlbhatoverB_n[2] = dualcurlbhat_n[2]/bmag_n[0]; + double *dualcurlbhatoverB_n = gkyl_array_fetch( + gk_geom->geo_int.dualcurlbhatoverB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + dualcurlbhatoverB_n[0] = dualcurlbhat_n[0] / bmag_n[0]; + dualcurlbhatoverB_n[1] = dualcurlbhat_n[1] / bmag_n[0]; + dualcurlbhatoverB_n[2] = dualcurlbhat_n[2] / bmag_n[0]; // set B^3/B = 1/sqrt(g_33) - double *rtg33inv_n = gkyl_array_fetch(gk_geom->geo_int.rtg33inv_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - rtg33inv_n[0] = 1.0/sqrt(gFld_n[5]); + double *rtg33inv_n = gkyl_array_fetch( + gk_geom->geo_int.rtg33inv_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + rtg33inv_n[0] = 1.0 / sqrt(gFld_n[5]); // set b_i/JB - double* bioverJB_n = gkyl_array_fetch(gk_geom->geo_int.bioverJB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - bioverJB_n[0] = gFld_n[2]/sqrt(gFld_n[5])/J/bmag_n[0]; - bioverJB_n[1] = gFld_n[4]/sqrt(gFld_n[5])/J/bmag_n[0]; - bioverJB_n[2] = gFld_n[5]/sqrt(gFld_n[5])/J/bmag_n[0]; + double *bioverJB_n = gkyl_array_fetch( + gk_geom->geo_int.bioverJB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + bioverJB_n[0] = gFld_n[2] / sqrt(gFld_n[5]) / J / bmag_n[0]; + bioverJB_n[1] = gFld_n[4] / sqrt(gFld_n[5]) / J / bmag_n[0]; + bioverJB_n[2] = gFld_n[5] / sqrt(gFld_n[5]) / J / bmag_n[0]; } } } check_axisymmetric(gk_geom->geo_int.g_ij_nodal, &gk_geom->nrange_int, up->exit_at_checks); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 6, gk_geom->geo_int.g_ij_nodal, gk_geom->geo_int.g_ij, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, gk_geom->geo_int.dxdz_nodal, gk_geom->geo_int.dxdz, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, gk_geom->geo_int.dzdx_nodal, gk_geom->geo_int.dzdx, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.dualmag_nodal, gk_geom->geo_int.dualmag, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, gk_geom->geo_int.normals_nodal, gk_geom->geo_int.normals, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.dualcurlbhat_nodal, gk_geom->geo_int.dualcurlbhat, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.dualcurlbhatoverB_nodal, gk_geom->geo_int.dualcurlbhatoverB, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.rtg33inv_nodal, gk_geom->geo_int.rtg33inv, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.bioverJB_nodal, gk_geom->geo_int.bioverJB, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.B3_nodal, gk_geom->geo_int.B3, true); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 6, + gk_geom->geo_int.g_ij_nodal, gk_geom->geo_int.g_ij, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, + gk_geom->geo_int.dxdz_nodal, gk_geom->geo_int.dxdz, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, + gk_geom->geo_int.dzdx_nodal, gk_geom->geo_int.dzdx, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.dualmag_nodal, gk_geom->geo_int.dualmag, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, + gk_geom->geo_int.normals_nodal, gk_geom->geo_int.normals, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.dualcurlbhat_nodal, gk_geom->geo_int.dualcurlbhat, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.dualcurlbhatoverB_nodal, gk_geom->geo_int.dualcurlbhatoverB, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.rtg33inv_nodal, gk_geom->geo_int.rtg33inv, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.bioverJB_nodal, gk_geom->geo_int.bioverJB, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.B3_nodal, gk_geom->geo_int.B3, true + ); } void gkyl_calc_metric_advance_surface(gkyl_calc_metric *up, int dir, struct gk_geometry *gk_geom) @@ -1543,140 +1949,203 @@ void gkyl_calc_metric_advance_surface(gkyl_calc_metric *up, int dir, struct gk_g enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { X_IDX, Y_IDX, Z_IDX }; // arrangement of cartesian coordinates int cidx[3]; - - for(int ia=gk_geom->nrange_surf[dir].lower[AL_IDX]; ia<=gk_geom->nrange_surf[dir].upper[AL_IDX]; ++ia){ - for (int ip=gk_geom->nrange_surf[dir].lower[PSI_IDX]; ip<=gk_geom->nrange_surf[dir].upper[PSI_IDX]; ++ip) { - for (int it=gk_geom->nrange_surf[dir].lower[TH_IDX]; it<=gk_geom->nrange_surf[dir].upper[TH_IDX]; ++it) { + + for (int ia = gk_geom->nrange_surf[dir].lower[AL_IDX]; + ia <= gk_geom->nrange_surf[dir].upper[AL_IDX]; ++ia) { + for (int ip = gk_geom->nrange_surf[dir].lower[PSI_IDX]; + ip <= gk_geom->nrange_surf[dir].upper[PSI_IDX]; ++ip) { + for (int it = gk_geom->nrange_surf[dir].lower[TH_IDX]; + it <= gk_geom->nrange_surf[dir].upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - const double *mc2p_n = gkyl_array_cfetch(gk_geom->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + const double *mc2p_n = gkyl_array_cfetch( + gk_geom->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); double dxdz[3][3]; // tan vecs at node double dzdx[3][3]; // duals at node - const double *bhat_n = gkyl_array_cfetch(gk_geom->geo_surf[dir].b_i_nodal_fd, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + const double *bhat_n = gkyl_array_cfetch( + gk_geom->geo_surf[dir].b_i_nodal_fd, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); double dbhatdz[3][3]; // tan vecs at node - if((ip == gk_geom->nrange_surf[dir].lower[PSI_IDX]) && (up->local.lower[PSI_IDX]== up->global.lower[PSI_IDX]) && dir==0) { - dxdz[0][0] = (-3*mc2p_n[X_IDX] + 4*mc2p_n[6+X_IDX] - mc2p_n[12+X_IDX] )/gk_geom->dzc[0]/2; - dxdz[1][0] = (-3*mc2p_n[Y_IDX] + 4*mc2p_n[6+Y_IDX] - mc2p_n[12+Y_IDX] )/gk_geom->dzc[0]/2; - dxdz[2][0] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[6+Z_IDX] - mc2p_n[12+Z_IDX] )/gk_geom->dzc[0]/2; - - dbhatdz[0][0] = (-3*bhat_n[X_IDX] + 4*bhat_n[6+X_IDX] - bhat_n[12+X_IDX] )/gk_geom->dzc[0]/2; - dbhatdz[1][0] = (-3*bhat_n[Y_IDX] + 4*bhat_n[6+Y_IDX] - bhat_n[12+Y_IDX] )/gk_geom->dzc[0]/2; - dbhatdz[2][0] = (-3*bhat_n[Z_IDX] + 4*bhat_n[6+Z_IDX] - bhat_n[12+Z_IDX] )/gk_geom->dzc[0]/2; - } - else if((ip == gk_geom->nrange_surf[dir].upper[PSI_IDX]) && (up->local.upper[PSI_IDX]== up->global.upper[PSI_IDX]) && dir==0) { - dxdz[0][0] = (3*mc2p_n[X_IDX] - 4*mc2p_n[3+X_IDX] + mc2p_n[9+X_IDX] )/gk_geom->dzc[0]/2; - dxdz[1][0] = (3*mc2p_n[Y_IDX] - 4*mc2p_n[3+Y_IDX] + mc2p_n[9+Y_IDX] )/gk_geom->dzc[0]/2; - dxdz[2][0] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[3+Z_IDX] + mc2p_n[9+Z_IDX] )/gk_geom->dzc[0]/2; - - dbhatdz[0][0] = (3*bhat_n[X_IDX] - 4*bhat_n[3+X_IDX] + bhat_n[9+X_IDX] )/gk_geom->dzc[0]/2; - dbhatdz[1][0] = (3*bhat_n[Y_IDX] - 4*bhat_n[3+Y_IDX] + bhat_n[9+Y_IDX] )/gk_geom->dzc[0]/2; - dbhatdz[2][0] = (3*bhat_n[Z_IDX] - 4*bhat_n[3+Z_IDX] + bhat_n[9+Z_IDX] )/gk_geom->dzc[0]/2; - } - else{ - dxdz[0][0] = -(mc2p_n[3 +X_IDX] - mc2p_n[6+X_IDX])/2/gk_geom->dzc[0]; - dxdz[1][0] = -(mc2p_n[3 +Y_IDX] - mc2p_n[6+Y_IDX])/2/gk_geom->dzc[0]; - dxdz[2][0] = -(mc2p_n[3 +Z_IDX] - mc2p_n[6+Z_IDX])/2/gk_geom->dzc[0]; - - dbhatdz[0][0] = -(bhat_n[3 +X_IDX] - bhat_n[6+X_IDX])/2/gk_geom->dzc[0]; - dbhatdz[1][0] = -(bhat_n[3 +Y_IDX] - bhat_n[6+Y_IDX])/2/gk_geom->dzc[0]; - dbhatdz[2][0] = -(bhat_n[3 +Z_IDX] - bhat_n[6+Z_IDX])/2/gk_geom->dzc[0]; + if ((ip == gk_geom->nrange_surf[dir].lower[PSI_IDX]) && + (up->local.lower[PSI_IDX] == up->global.lower[PSI_IDX]) && dir == 0) { + dxdz[0][0] = + (-3 * mc2p_n[X_IDX] + 4 * mc2p_n[6 + X_IDX] - mc2p_n[12 + X_IDX]) / gk_geom->dzc[0] / 2; + dxdz[1][0] = + (-3 * mc2p_n[Y_IDX] + 4 * mc2p_n[6 + Y_IDX] - mc2p_n[12 + Y_IDX]) / gk_geom->dzc[0] / 2; + dxdz[2][0] = + (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[6 + Z_IDX] - mc2p_n[12 + Z_IDX]) / gk_geom->dzc[0] / 2; + + dbhatdz[0][0] = + (-3 * bhat_n[X_IDX] + 4 * bhat_n[6 + X_IDX] - bhat_n[12 + X_IDX]) / gk_geom->dzc[0] / 2; + dbhatdz[1][0] = + (-3 * bhat_n[Y_IDX] + 4 * bhat_n[6 + Y_IDX] - bhat_n[12 + Y_IDX]) / gk_geom->dzc[0] / 2; + dbhatdz[2][0] = + (-3 * bhat_n[Z_IDX] + 4 * bhat_n[6 + Z_IDX] - bhat_n[12 + Z_IDX]) / gk_geom->dzc[0] / 2; + } else if ((ip == gk_geom->nrange_surf[dir].upper[PSI_IDX]) && + (up->local.upper[PSI_IDX] == up->global.upper[PSI_IDX]) && dir == 0) { + dxdz[0][0] = + (3 * mc2p_n[X_IDX] - 4 * mc2p_n[3 + X_IDX] + mc2p_n[9 + X_IDX]) / gk_geom->dzc[0] / 2; + dxdz[1][0] = + (3 * mc2p_n[Y_IDX] - 4 * mc2p_n[3 + Y_IDX] + mc2p_n[9 + Y_IDX]) / gk_geom->dzc[0] / 2; + dxdz[2][0] = + (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[3 + Z_IDX] + mc2p_n[9 + Z_IDX]) / gk_geom->dzc[0] / 2; + + dbhatdz[0][0] = + (3 * bhat_n[X_IDX] - 4 * bhat_n[3 + X_IDX] + bhat_n[9 + X_IDX]) / gk_geom->dzc[0] / 2; + dbhatdz[1][0] = + (3 * bhat_n[Y_IDX] - 4 * bhat_n[3 + Y_IDX] + bhat_n[9 + Y_IDX]) / gk_geom->dzc[0] / 2; + dbhatdz[2][0] = + (3 * bhat_n[Z_IDX] - 4 * bhat_n[3 + Z_IDX] + bhat_n[9 + Z_IDX]) / gk_geom->dzc[0] / 2; + } else { + dxdz[0][0] = -(mc2p_n[3 + X_IDX] - mc2p_n[6 + X_IDX]) / 2 / gk_geom->dzc[0]; + dxdz[1][0] = -(mc2p_n[3 + Y_IDX] - mc2p_n[6 + Y_IDX]) / 2 / gk_geom->dzc[0]; + dxdz[2][0] = -(mc2p_n[3 + Z_IDX] - mc2p_n[6 + Z_IDX]) / 2 / gk_geom->dzc[0]; + + dbhatdz[0][0] = -(bhat_n[3 + X_IDX] - bhat_n[6 + X_IDX]) / 2 / gk_geom->dzc[0]; + dbhatdz[1][0] = -(bhat_n[3 + Y_IDX] - bhat_n[6 + Y_IDX]) / 2 / gk_geom->dzc[0]; + dbhatdz[2][0] = -(bhat_n[3 + Z_IDX] - bhat_n[6 + Z_IDX]) / 2 / gk_geom->dzc[0]; } - - if((ia == gk_geom->nrange_surf[dir].lower[AL_IDX]) && (up->local.lower[AL_IDX]== up->global.lower[AL_IDX]) && dir==1 ) { - dxdz[0][1] = (-3*mc2p_n[X_IDX] + 4*mc2p_n[18+X_IDX] - mc2p_n[24+X_IDX])/gk_geom->dzc[1]/2; - dxdz[1][1] = (-3*mc2p_n[Y_IDX] + 4*mc2p_n[18+Y_IDX] - mc2p_n[24+Y_IDX])/gk_geom->dzc[1]/2; - dxdz[2][1] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[18+Z_IDX] - mc2p_n[24+Z_IDX])/gk_geom->dzc[1]/2; - - dbhatdz[0][1] = (-3*bhat_n[X_IDX] + 4*bhat_n[18+X_IDX] - bhat_n[24+X_IDX])/gk_geom->dzc[1]/2; - dbhatdz[1][1] = (-3*bhat_n[Y_IDX] + 4*bhat_n[18+Y_IDX] - bhat_n[24+Y_IDX])/gk_geom->dzc[1]/2; - dbhatdz[2][1] = (-3*bhat_n[Z_IDX] + 4*bhat_n[18+Z_IDX] - bhat_n[24+Z_IDX])/gk_geom->dzc[1]/2; - } - else if((ia == gk_geom->nrange_surf[dir].upper[AL_IDX]) && (up->local.upper[AL_IDX]== up->global.upper[AL_IDX]) && dir==1 ) { - dxdz[0][1] = (3*mc2p_n[X_IDX] - 4*mc2p_n[15+X_IDX] + mc2p_n[21+X_IDX] )/gk_geom->dzc[1]/2; - dxdz[1][1] = (3*mc2p_n[Y_IDX] - 4*mc2p_n[15+Y_IDX] + mc2p_n[21+Y_IDX] )/gk_geom->dzc[1]/2; - dxdz[2][1] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[15+Z_IDX] + mc2p_n[21+Z_IDX] )/gk_geom->dzc[1]/2; - - dbhatdz[0][1] = (3*bhat_n[X_IDX] - 4*bhat_n[15+X_IDX] + bhat_n[21+X_IDX] )/gk_geom->dzc[1]/2; - dbhatdz[1][1] = (3*bhat_n[Y_IDX] - 4*bhat_n[15+Y_IDX] + bhat_n[21+Y_IDX] )/gk_geom->dzc[1]/2; - dbhatdz[2][1] = (3*bhat_n[Z_IDX] - 4*bhat_n[15+Z_IDX] + bhat_n[21+Z_IDX] )/gk_geom->dzc[1]/2; - } - else { - dxdz[0][1] = -(mc2p_n[15 +X_IDX] - mc2p_n[18 +X_IDX])/2/gk_geom->dzc[1]; - dxdz[1][1] = -(mc2p_n[15 +Y_IDX] - mc2p_n[18 +Y_IDX])/2/gk_geom->dzc[1]; - dxdz[2][1] = -(mc2p_n[15 +Z_IDX] - mc2p_n[18 +Z_IDX])/2/gk_geom->dzc[1]; - - dbhatdz[0][1] = -(bhat_n[15 +X_IDX] - bhat_n[18 +X_IDX])/2/gk_geom->dzc[1]; - dbhatdz[1][1] = -(bhat_n[15 +Y_IDX] - bhat_n[18 +Y_IDX])/2/gk_geom->dzc[1]; - dbhatdz[2][1] = -(bhat_n[15 +Z_IDX] - bhat_n[18 +Z_IDX])/2/gk_geom->dzc[1]; + if ((ia == gk_geom->nrange_surf[dir].lower[AL_IDX]) && + (up->local.lower[AL_IDX] == up->global.lower[AL_IDX]) && dir == 1) { + dxdz[0][1] = (-3 * mc2p_n[X_IDX] + 4 * mc2p_n[18 + X_IDX] - mc2p_n[24 + X_IDX]) / + gk_geom->dzc[1] / 2; + dxdz[1][1] = (-3 * mc2p_n[Y_IDX] + 4 * mc2p_n[18 + Y_IDX] - mc2p_n[24 + Y_IDX]) / + gk_geom->dzc[1] / 2; + dxdz[2][1] = (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[18 + Z_IDX] - mc2p_n[24 + Z_IDX]) / + gk_geom->dzc[1] / 2; + + dbhatdz[0][1] = (-3 * bhat_n[X_IDX] + 4 * bhat_n[18 + X_IDX] - bhat_n[24 + X_IDX]) / + gk_geom->dzc[1] / 2; + dbhatdz[1][1] = (-3 * bhat_n[Y_IDX] + 4 * bhat_n[18 + Y_IDX] - bhat_n[24 + Y_IDX]) / + gk_geom->dzc[1] / 2; + dbhatdz[2][1] = (-3 * bhat_n[Z_IDX] + 4 * bhat_n[18 + Z_IDX] - bhat_n[24 + Z_IDX]) / + gk_geom->dzc[1] / 2; + } else if ((ia == gk_geom->nrange_surf[dir].upper[AL_IDX]) && + (up->local.upper[AL_IDX] == up->global.upper[AL_IDX]) && dir == 1) { + dxdz[0][1] = + (3 * mc2p_n[X_IDX] - 4 * mc2p_n[15 + X_IDX] + mc2p_n[21 + X_IDX]) / gk_geom->dzc[1] / 2; + dxdz[1][1] = + (3 * mc2p_n[Y_IDX] - 4 * mc2p_n[15 + Y_IDX] + mc2p_n[21 + Y_IDX]) / gk_geom->dzc[1] / 2; + dxdz[2][1] = + (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[15 + Z_IDX] + mc2p_n[21 + Z_IDX]) / gk_geom->dzc[1] / 2; + + dbhatdz[0][1] = + (3 * bhat_n[X_IDX] - 4 * bhat_n[15 + X_IDX] + bhat_n[21 + X_IDX]) / gk_geom->dzc[1] / 2; + dbhatdz[1][1] = + (3 * bhat_n[Y_IDX] - 4 * bhat_n[15 + Y_IDX] + bhat_n[21 + Y_IDX]) / gk_geom->dzc[1] / 2; + dbhatdz[2][1] = + (3 * bhat_n[Z_IDX] - 4 * bhat_n[15 + Z_IDX] + bhat_n[21 + Z_IDX]) / gk_geom->dzc[1] / 2; + } else { + dxdz[0][1] = -(mc2p_n[15 + X_IDX] - mc2p_n[18 + X_IDX]) / 2 / gk_geom->dzc[1]; + dxdz[1][1] = -(mc2p_n[15 + Y_IDX] - mc2p_n[18 + Y_IDX]) / 2 / gk_geom->dzc[1]; + dxdz[2][1] = -(mc2p_n[15 + Z_IDX] - mc2p_n[18 + Z_IDX]) / 2 / gk_geom->dzc[1]; + + dbhatdz[0][1] = -(bhat_n[15 + X_IDX] - bhat_n[18 + X_IDX]) / 2 / gk_geom->dzc[1]; + dbhatdz[1][1] = -(bhat_n[15 + Y_IDX] - bhat_n[18 + Y_IDX]) / 2 / gk_geom->dzc[1]; + dbhatdz[2][1] = -(bhat_n[15 + Z_IDX] - bhat_n[18 + Z_IDX]) / 2 / gk_geom->dzc[1]; } - if((it == gk_geom->nrange_surf[dir].lower[TH_IDX]) && (up->local.lower[TH_IDX]== up->global.lower[TH_IDX]) && dir==2 ) { - dxdz[0][2] = (-3*mc2p_n[X_IDX] + 4*mc2p_n[30+X_IDX] - mc2p_n[36+X_IDX])/gk_geom->dzc[2]/2; - dxdz[1][2] = (-3*mc2p_n[Y_IDX] + 4*mc2p_n[30+Y_IDX] - mc2p_n[36+Y_IDX])/gk_geom->dzc[2]/2; - dxdz[2][2] = (-3*mc2p_n[Z_IDX] + 4*mc2p_n[30+Z_IDX] - mc2p_n[36+Z_IDX])/gk_geom->dzc[2]/2; - - dbhatdz[0][2] = (-3*bhat_n[X_IDX] + 4*bhat_n[30+X_IDX] - bhat_n[36+X_IDX])/gk_geom->dzc[2]/2; - dbhatdz[1][2] = (-3*bhat_n[Y_IDX] + 4*bhat_n[30+Y_IDX] - bhat_n[36+Y_IDX])/gk_geom->dzc[2]/2; - dbhatdz[2][2] = (-3*bhat_n[Z_IDX] + 4*bhat_n[30+Z_IDX] - bhat_n[36+Z_IDX])/gk_geom->dzc[2]/2; - } - else if((it == gk_geom->nrange_surf[dir].upper[TH_IDX]) && (up->local.upper[TH_IDX]== up->global.upper[TH_IDX]) && dir==2 ) { - dxdz[0][2] = (3*mc2p_n[X_IDX] - 4*mc2p_n[27+X_IDX] + mc2p_n[33+X_IDX] )/gk_geom->dzc[2]/2; - dxdz[1][2] = (3*mc2p_n[Y_IDX] - 4*mc2p_n[27+Y_IDX] + mc2p_n[33+Y_IDX] )/gk_geom->dzc[2]/2; - dxdz[2][2] = (3*mc2p_n[Z_IDX] - 4*mc2p_n[27+Z_IDX] + mc2p_n[33+Z_IDX] )/gk_geom->dzc[2]/2; - - dbhatdz[0][2] = (3*bhat_n[X_IDX] - 4*bhat_n[27+X_IDX] + bhat_n[33+X_IDX] )/gk_geom->dzc[2]/2; - dbhatdz[1][2] = (3*bhat_n[Y_IDX] - 4*bhat_n[27+Y_IDX] + bhat_n[33+Y_IDX] )/gk_geom->dzc[2]/2; - dbhatdz[2][2] = (3*bhat_n[Z_IDX] - 4*bhat_n[27+Z_IDX] + bhat_n[33+Z_IDX] )/gk_geom->dzc[2]/2; - } - else{ - dxdz[0][2] = -(mc2p_n[27 +X_IDX] - mc2p_n[30 +X_IDX])/2/gk_geom->dzc[2]; - dxdz[1][2] = -(mc2p_n[27 +Y_IDX] - mc2p_n[30 +Y_IDX])/2/gk_geom->dzc[2]; - dxdz[2][2] = -(mc2p_n[27 +Z_IDX] - mc2p_n[30 +Z_IDX])/2/gk_geom->dzc[2]; - - dbhatdz[0][2] = -(bhat_n[27 +X_IDX] - bhat_n[30 +X_IDX])/2/gk_geom->dzc[2]; - dbhatdz[1][2] = -(bhat_n[27 +Y_IDX] - bhat_n[30 +Y_IDX])/2/gk_geom->dzc[2]; - dbhatdz[2][2] = -(bhat_n[27 +Z_IDX] - bhat_n[30 +Z_IDX])/2/gk_geom->dzc[2]; + if ((it == gk_geom->nrange_surf[dir].lower[TH_IDX]) && + (up->local.lower[TH_IDX] == up->global.lower[TH_IDX]) && dir == 2) { + dxdz[0][2] = (-3 * mc2p_n[X_IDX] + 4 * mc2p_n[30 + X_IDX] - mc2p_n[36 + X_IDX]) / + gk_geom->dzc[2] / 2; + dxdz[1][2] = (-3 * mc2p_n[Y_IDX] + 4 * mc2p_n[30 + Y_IDX] - mc2p_n[36 + Y_IDX]) / + gk_geom->dzc[2] / 2; + dxdz[2][2] = (-3 * mc2p_n[Z_IDX] + 4 * mc2p_n[30 + Z_IDX] - mc2p_n[36 + Z_IDX]) / + gk_geom->dzc[2] / 2; + + dbhatdz[0][2] = (-3 * bhat_n[X_IDX] + 4 * bhat_n[30 + X_IDX] - bhat_n[36 + X_IDX]) / + gk_geom->dzc[2] / 2; + dbhatdz[1][2] = (-3 * bhat_n[Y_IDX] + 4 * bhat_n[30 + Y_IDX] - bhat_n[36 + Y_IDX]) / + gk_geom->dzc[2] / 2; + dbhatdz[2][2] = (-3 * bhat_n[Z_IDX] + 4 * bhat_n[30 + Z_IDX] - bhat_n[36 + Z_IDX]) / + gk_geom->dzc[2] / 2; + } else if ((it == gk_geom->nrange_surf[dir].upper[TH_IDX]) && + (up->local.upper[TH_IDX] == up->global.upper[TH_IDX]) && dir == 2) { + dxdz[0][2] = + (3 * mc2p_n[X_IDX] - 4 * mc2p_n[27 + X_IDX] + mc2p_n[33 + X_IDX]) / gk_geom->dzc[2] / 2; + dxdz[1][2] = + (3 * mc2p_n[Y_IDX] - 4 * mc2p_n[27 + Y_IDX] + mc2p_n[33 + Y_IDX]) / gk_geom->dzc[2] / 2; + dxdz[2][2] = + (3 * mc2p_n[Z_IDX] - 4 * mc2p_n[27 + Z_IDX] + mc2p_n[33 + Z_IDX]) / gk_geom->dzc[2] / 2; + + dbhatdz[0][2] = + (3 * bhat_n[X_IDX] - 4 * bhat_n[27 + X_IDX] + bhat_n[33 + X_IDX]) / gk_geom->dzc[2] / 2; + dbhatdz[1][2] = + (3 * bhat_n[Y_IDX] - 4 * bhat_n[27 + Y_IDX] + bhat_n[33 + Y_IDX]) / gk_geom->dzc[2] / 2; + dbhatdz[2][2] = + (3 * bhat_n[Z_IDX] - 4 * bhat_n[27 + Z_IDX] + bhat_n[33 + Z_IDX]) / gk_geom->dzc[2] / 2; + } else { + dxdz[0][2] = -(mc2p_n[27 + X_IDX] - mc2p_n[30 + X_IDX]) / 2 / gk_geom->dzc[2]; + dxdz[1][2] = -(mc2p_n[27 + Y_IDX] - mc2p_n[30 + Y_IDX]) / 2 / gk_geom->dzc[2]; + dxdz[2][2] = -(mc2p_n[27 + Z_IDX] - mc2p_n[30 + Z_IDX]) / 2 / gk_geom->dzc[2]; + + dbhatdz[0][2] = -(bhat_n[27 + X_IDX] - bhat_n[30 + X_IDX]) / 2 / gk_geom->dzc[2]; + dbhatdz[1][2] = -(bhat_n[27 + Y_IDX] - bhat_n[30 + Y_IDX]) / 2 / gk_geom->dzc[2]; + dbhatdz[2][2] = -(bhat_n[27 + Z_IDX] - bhat_n[30 + Z_IDX]) / 2 / gk_geom->dzc[2]; } - double *gFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - gFld_n[0] = calc_metric(dxdz, 1, 1); - gFld_n[1] = calc_metric(dxdz, 1, 2); - gFld_n[2] = calc_metric(dxdz, 1, 3); - gFld_n[3] = calc_metric(dxdz, 2, 2); - gFld_n[4] = calc_metric(dxdz, 2, 3); - gFld_n[5] = calc_metric(dxdz, 3, 3); - - double Jsq = gFld_n[0]*( gFld_n[3]*gFld_n[5] - gFld_n[4]*gFld_n[4] ) - -gFld_n[1]*( gFld_n[1]*gFld_n[5] - gFld_n[4]*gFld_n[2] ) - +gFld_n[2]*( gFld_n[1]*gFld_n[4] - gFld_n[3]*gFld_n[2] ); + double *gFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + gFld_n[0] = calc_metric(dxdz, 1, 1); + gFld_n[1] = calc_metric(dxdz, 1, 2); + gFld_n[2] = calc_metric(dxdz, 1, 3); + gFld_n[3] = calc_metric(dxdz, 2, 2); + gFld_n[4] = calc_metric(dxdz, 2, 3); + gFld_n[5] = calc_metric(dxdz, 3, 3); + + double Jsq = gFld_n[0] * (gFld_n[3] * gFld_n[5] - gFld_n[4] * gFld_n[4]) - + gFld_n[1] * (gFld_n[1] * gFld_n[5] - gFld_n[4] * gFld_n[2]) + + gFld_n[2] * (gFld_n[1] * gFld_n[4] - gFld_n[3] * gFld_n[2]); double J = sqrt(Jsq); - double *jFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + double *jFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); jFld_n[0] = J; // Calculate cmag, bi, and jtot_inv - double *biFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].b_i_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - biFld_n[0] = gFld_n[2]/sqrt(gFld_n[5]); - biFld_n[1] = gFld_n[4]/sqrt(gFld_n[5]); - biFld_n[2] = gFld_n[5]/sqrt(gFld_n[5]); - - double *bmag_n = gkyl_array_fetch(gk_geom->geo_surf[dir].bmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *cmagFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].cmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - cmagFld_n[0] = jFld_n[0]*bmag_n[0]/sqrt(gFld_n[5]); - double *jtotinvFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].jacobtot_inv_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - jtotinvFld_n[0] = 1.0/(jFld_n[0]*bmag_n[0]); + double *biFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].b_i_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + biFld_n[0] = gFld_n[2] / sqrt(gFld_n[5]); + biFld_n[1] = gFld_n[4] / sqrt(gFld_n[5]); + biFld_n[2] = gFld_n[5] / sqrt(gFld_n[5]); + + double *bmag_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].bmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *cmagFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].cmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + cmagFld_n[0] = jFld_n[0] * bmag_n[0] / sqrt(gFld_n[5]); + double *jtotinvFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].jacobtot_inv_nodal, + gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + jtotinvFld_n[0] = 1.0 / (jFld_n[0] * bmag_n[0]); double e_1[3], e_2[3], e_3[3]; - e_1[0] = dxdz[0][0]; e_1[1] = dxdz[1][0]; e_1[2] = dxdz[2][0]; - e_2[0] = dxdz[0][1]; e_2[1] = dxdz[1][1]; e_2[2] = dxdz[2][1]; - e_3[0] = dxdz[0][2]; e_3[1] = dxdz[1][2]; e_3[2] = dxdz[2][2]; + e_1[0] = dxdz[0][0]; + e_1[1] = dxdz[1][0]; + e_1[2] = dxdz[2][0]; + e_2[0] = dxdz[0][1]; + e_2[1] = dxdz[1][1]; + e_2[2] = dxdz[2][1]; + e_3[0] = dxdz[0][2]; + e_3[1] = dxdz[1][2]; + e_3[2] = dxdz[2][2]; calc_dual(J, e_2, e_3, dzdx[0]); calc_dual(J, e_3, e_1, dzdx[1]); calc_dual(J, e_1, e_2, dzdx[2]); - double *dualFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + double *dualFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); dualFld_n[0] = dzdx[0][0]; dualFld_n[1] = dzdx[0][1]; dualFld_n[2] = dzdx[0][2]; @@ -1687,55 +2156,73 @@ void gkyl_calc_metric_advance_surface(gkyl_calc_metric *up, int dir, struct gk_g dualFld_n[7] = dzdx[2][1]; dualFld_n[8] = dzdx[2][2]; - double *tanvecFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - tanvecFld_n[0] = dxdz[0][0]; - tanvecFld_n[1] = dxdz[1][0]; - tanvecFld_n[2] = dxdz[2][0]; - tanvecFld_n[3] = dxdz[0][1]; - tanvecFld_n[4] = dxdz[1][1]; - tanvecFld_n[5] = dxdz[2][1]; - tanvecFld_n[6] = dxdz[0][2]; - tanvecFld_n[7] = dxdz[1][2]; - tanvecFld_n[8] = dxdz[2][2]; + double *tanvecFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + tanvecFld_n[0] = dxdz[0][0]; + tanvecFld_n[1] = dxdz[1][0]; + tanvecFld_n[2] = dxdz[2][0]; + tanvecFld_n[3] = dxdz[0][1]; + tanvecFld_n[4] = dxdz[1][1]; + tanvecFld_n[5] = dxdz[2][1]; + tanvecFld_n[6] = dxdz[0][2]; + tanvecFld_n[7] = dxdz[1][2]; + tanvecFld_n[8] = dxdz[2][2]; // Check that the coordinate system has tangent/dual vectors // satisfying orthonormality, and that it's right handed. check_orthonormality(tanvecFld_n, dualFld_n, up->exit_at_checks); check_right_handed(tanvecFld_n, dualFld_n, up->exit_at_checks); - double norm1 = sqrt(dualFld_n[0]*dualFld_n[0] + dualFld_n[1]*dualFld_n[1] + dualFld_n[2]*dualFld_n[2]); - double norm2 = sqrt(dualFld_n[3]*dualFld_n[3] + dualFld_n[4]*dualFld_n[4] + dualFld_n[5]*dualFld_n[5]); - double norm3 = sqrt(dualFld_n[6]*dualFld_n[6] + dualFld_n[7]*dualFld_n[7] + dualFld_n[8]*dualFld_n[8]); - - double *dualmagFld_n = gkyl_array_fetch(gk_geom->geo_surf[dir].dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + double norm1 = sqrt( + dualFld_n[0] * dualFld_n[0] + dualFld_n[1] * dualFld_n[1] + dualFld_n[2] * dualFld_n[2] + ); + double norm2 = sqrt( + dualFld_n[3] * dualFld_n[3] + dualFld_n[4] * dualFld_n[4] + dualFld_n[5] * dualFld_n[5] + ); + double norm3 = sqrt( + dualFld_n[6] * dualFld_n[6] + dualFld_n[7] * dualFld_n[7] + dualFld_n[8] * dualFld_n[8] + ); + + double *dualmagFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); dualmagFld_n[0] = norm1; dualmagFld_n[1] = norm2; dualmagFld_n[2] = norm3; - + // Set normal vectors - double *normFld_n = gkyl_array_fetch(gk_geom->geo_surf[dir].normals_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - normFld_n[0] = dualFld_n[0]/norm1; - normFld_n[1] = dualFld_n[1]/norm1; - normFld_n[2] = dualFld_n[2]/norm1; + double *normFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].normals_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + normFld_n[0] = dualFld_n[0] / norm1; + normFld_n[1] = dualFld_n[1] / norm1; + normFld_n[2] = dualFld_n[2] / norm1; - normFld_n[3] = dualFld_n[3]/norm2; - normFld_n[4] = dualFld_n[4]/norm2; - normFld_n[5] = dualFld_n[5]/norm2; + normFld_n[3] = dualFld_n[3] / norm2; + normFld_n[4] = dualFld_n[4] / norm2; + normFld_n[5] = dualFld_n[5] / norm2; - normFld_n[6] = dualFld_n[6]/norm3; - normFld_n[7] = dualFld_n[7]/norm3; - normFld_n[8] = dualFld_n[8]/norm3; + normFld_n[6] = dualFld_n[6] / norm3; + normFld_n[7] = dualFld_n[7] / norm3; + normFld_n[8] = dualFld_n[8] / norm3; // Set lenr - double *lenr_n = gkyl_array_fetch(gk_geom->geo_surf[dir].lenr_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - lenr_n[0] = J*dualmagFld_n[dir]; - - // Set n^3 \dot B - double *B3_n = gkyl_array_fetch(gk_geom->geo_surf[dir].B3_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - B3_n[0] = bmag_n[0]/sqrt(gFld_n[5])/norm3; - - // Set n^m \dot curl(bhat) - double *curlbhat_n = gkyl_array_fetch(gk_geom->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + double *lenr_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].lenr_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + lenr_n[0] = J * dualmagFld_n[dir]; + + // Set n^3 \dot B + double *B3_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].B3_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + B3_n[0] = bmag_n[0] / sqrt(gFld_n[5]) / norm3; + + // Set n^m \dot curl(bhat) + double *curlbhat_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); // I first need the derivatives of B_X,Y,Z wrt XYZ double dbhatdX[3][3]; matTvec(dzdx, dbhatdz[0], dbhatdX[0]); @@ -1744,44 +2231,58 @@ void gkyl_calc_metric_advance_surface(gkyl_calc_metric *up, int dir, struct gk_g curlbhat_n[0] = (dbhatdX[2][1] - dbhatdX[1][2]); curlbhat_n[1] = (dbhatdX[0][2] - dbhatdX[2][0]); curlbhat_n[2] = (dbhatdX[1][0] - dbhatdX[0][1]); - double *normcurlbhat_n = gkyl_array_fetch(gk_geom->geo_surf[dir].normcurlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - normcurlbhat_n[0] = normFld_n[3*dir+0]*curlbhat_n[0] + normFld_n[3*dir+1]*curlbhat_n[1] + normFld_n[3*dir+2]*curlbhat_n[2]; - - // set bimpactangle = arcsin(1/sqrt(g_33 * g^33)) - double *bimpactangle_n = gkyl_array_fetch(gk_geom->geo_surf[dir].bimpactangle_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - bimpactangle_n[0] = asin(1.0/(sqrt(gFld_n[5]) * norm3)); + double *normcurlbhat_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].normcurlbhat_nodal, + gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + normcurlbhat_n[0] = normFld_n[3 * dir + 0] * curlbhat_n[0] + + normFld_n[3 * dir + 1] * curlbhat_n[1] + + normFld_n[3 * dir + 2] * curlbhat_n[2]; + // set bimpactangle = arcsin(1/sqrt(g_33 * g^33)) + double *bimpactangle_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].bimpactangle_nodal, + gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + bimpactangle_n[0] = asin(1.0 / (sqrt(gFld_n[5]) * norm3)); } } } - check_axisymmetric(gk_geom->geo_surf[dir].g_ij_nodal, &gk_geom->nrange_surf[dir], up->exit_at_checks); + check_axisymmetric( + gk_geom->geo_surf[dir].g_ij_nodal, &gk_geom->nrange_surf[dir], up->exit_at_checks + ); } -void gkyl_calc_metric_advance_bcart(gkyl_calc_metric *up, struct gkyl_range *nrange, - struct gkyl_array *biFld, struct gkyl_array *dualFld, struct gkyl_array *bcartFld, - const struct gkyl_range *update_range) +void gkyl_calc_metric_advance_bcart( + gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *biFld, + struct gkyl_array *dualFld, struct gkyl_array *bcartFld, const struct gkyl_range *update_range +) { - struct gkyl_array* bcartFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); - struct gkyl_array* biFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); - struct gkyl_array* dualFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); + struct gkyl_array *bcartFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); + struct gkyl_array *biFld_nodal = gkyl_array_new(GKYL_DOUBLE, 3, nrange->volume); + struct gkyl_array *dualFld_nodal = gkyl_array_new(GKYL_DOUBLE, 9, nrange->volume); enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { X_IDX, Y_IDX, Z_IDX }; // arrangement of cartesian coordinates int cidx[3]; // Fill the inputs - gkyl_nodal_ops_m2n(up->n2m, up->cbasis, up->grid, nrange, update_range, 9, dualFld_nodal, dualFld, true); - gkyl_nodal_ops_m2n(up->n2m, up->cbasis, up->grid, nrange, update_range, 3, biFld_nodal, biFld, true); - - for(int ia=nrange->lower[AL_IDX]; ia<=nrange->upper[AL_IDX]; ++ia) { - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { + gkyl_nodal_ops_m2n( + up->n2m, up->cbasis, up->grid, nrange, update_range, 9, dualFld_nodal, dualFld, true + ); + gkyl_nodal_ops_m2n( + up->n2m, up->cbasis, up->grid, nrange, update_range, 3, biFld_nodal, biFld, true + ); + + for (int ia = nrange->lower[AL_IDX]; ia <= nrange->upper[AL_IDX]; ++ia) { + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; - double *biFld_n= gkyl_array_fetch(biFld_nodal, gkyl_range_idx(nrange, cidx)); - double *dualFld_n= gkyl_array_fetch(dualFld_nodal, gkyl_range_idx(nrange, cidx)); + double *biFld_n = gkyl_array_fetch(biFld_nodal, gkyl_range_idx(nrange, cidx)); + double *dualFld_n = gkyl_array_fetch(dualFld_nodal, gkyl_range_idx(nrange, cidx)); double dzdx[3][3]; // duals at node dzdx[0][0] = dualFld_n[0]; dzdx[0][1] = dualFld_n[1]; @@ -1792,21 +2293,22 @@ void gkyl_calc_metric_advance_bcart(gkyl_calc_metric *up, struct gkyl_range *nra dzdx[2][0] = dualFld_n[6]; dzdx[2][1] = dualFld_n[7]; dzdx[2][2] = dualFld_n[8]; - double *bcartFld_n= gkyl_array_fetch(bcartFld_nodal, gkyl_range_idx(nrange, cidx)); - bcartFld_n[0] = dzdx[0][0]*biFld_n[0] + dzdx[1][0]*biFld_n[1] + dzdx[2][0]*biFld_n[2]; - bcartFld_n[1] = dzdx[0][1]*biFld_n[0] + dzdx[1][1]*biFld_n[1] + dzdx[2][1]*biFld_n[2]; - bcartFld_n[2] = dzdx[0][2]*biFld_n[0] + dzdx[1][2]*biFld_n[1] + dzdx[2][2]*biFld_n[2]; + double *bcartFld_n = gkyl_array_fetch(bcartFld_nodal, gkyl_range_idx(nrange, cidx)); + bcartFld_n[0] = dzdx[0][0] * biFld_n[0] + dzdx[1][0] * biFld_n[1] + dzdx[2][0] * biFld_n[2]; + bcartFld_n[1] = dzdx[0][1] * biFld_n[0] + dzdx[1][1] * biFld_n[1] + dzdx[2][1] * biFld_n[2]; + bcartFld_n[2] = dzdx[0][2] * biFld_n[0] + dzdx[1][2] * biFld_n[1] + dzdx[2][2] * biFld_n[2]; } } } - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, nrange, update_range, 3, bcartFld_nodal, bcartFld, false); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, nrange, update_range, 3, bcartFld_nodal, bcartFld, false + ); gkyl_array_release(bcartFld_nodal); gkyl_array_release(biFld_nodal); gkyl_array_release(dualFld_nodal); } -void -gkyl_calc_metric_release(gkyl_calc_metric* up) +void gkyl_calc_metric_release(gkyl_calc_metric *up) { gkyl_nodal_ops_release(up->n2m); gkyl_free(up); diff --git a/gyrokinetic/zero/calc_metric_mirror.c b/gyrokinetic/zero/calc_metric_mirror.c index ad8bbeac0e..1f7c088558 100644 --- a/gyrokinetic/zero/calc_metric_mirror.c +++ b/gyrokinetic/zero/calc_metric_mirror.c @@ -9,9 +9,10 @@ #include #include -gkyl_calc_metric_mirror* -gkyl_calc_metric_mirror_new(const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *local, const struct gkyl_range *local_ext, bool use_gpu) +gkyl_calc_metric_mirror *gkyl_calc_metric_mirror_new( + const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, + const struct gkyl_range *local, const struct gkyl_range *local_ext, bool use_gpu +) { gkyl_calc_metric_mirror *up = gkyl_malloc(sizeof(gkyl_calc_metric_mirror)); up->cbasis = cbasis; @@ -28,45 +29,58 @@ gkyl_calc_metric_mirror_new(const struct gkyl_basis *cbasis, const struct gkyl_r return up; } -static inline double calc_metric(double dxdz[3][3], int i, int j) +static inline double calc_metric(double dxdz[3][3], int i, int j) { double sum = 0; - for (int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) { sum += dxdz[k][i - 1] * dxdz[k][j - 1]; + } return sum; -} +} // Calculates e^1 = e_2 x e_3 /J -static inline void -calc_dual(double J, const double e_2[3], const double e_3[3], double e1[3]) +static inline void calc_dual(double J, const double e_2[3], const double e_3[3], double e1[3]) { - e1[0] = (e_2[1]*e_3[2] - e_2[2]*e_3[1] )/J; - e1[1] = -(e_2[0]*e_3[2] - e_2[2]*e_3[0] )/J; - e1[2] = (e_2[0]*e_3[1] - e_2[1]*e_3[0] )/J; + e1[0] = (e_2[1] * e_3[2] - e_2[2] * e_3[1]) / J; + e1[1] = -(e_2[0] * e_3[2] - e_2[2] * e_3[0]) / J; + e1[2] = (e_2[0] * e_3[1] - e_2[1] * e_3[0]) / J; } void gkyl_calc_metric_mirror_advance( - gkyl_calc_metric_mirror *up, struct gk_geometry *gk_geom, struct gkyl_mirror_grid_gen *mirror_grid) + gkyl_calc_metric_mirror *up, struct gk_geometry *gk_geom, struct gkyl_mirror_grid_gen *mirror_grid +) { enum { PSI_IDX, AL_IDX, TH_IDX }; // Arrangement of computational coordinates. enum { R_IDX, Z_IDX, PHI_IDX }; // Arrangement of cartesian coordinates. int cidx[3]; - for(int ia=gk_geom->nrange_corn.lower[AL_IDX]; ia<=gk_geom->nrange_corn.upper[AL_IDX]; ++ia){ - for (int ip=gk_geom->nrange_corn.lower[PSI_IDX]; ip<=gk_geom->nrange_corn.upper[PSI_IDX]; ++ip) { - for (int it=gk_geom->nrange_corn.lower[TH_IDX]; it<=gk_geom->nrange_corn.upper[TH_IDX]; ++it) { + for (int ia = gk_geom->nrange_corn.lower[AL_IDX]; ia <= gk_geom->nrange_corn.upper[AL_IDX]; + ++ia) { + for (int ip = gk_geom->nrange_corn.lower[PSI_IDX]; ip <= gk_geom->nrange_corn.upper[PSI_IDX]; + ++ip) { + for (int it = gk_geom->nrange_corn.lower[TH_IDX]; it <= gk_geom->nrange_corn.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; // First fetch the mirror stuff at this location - const double *mirror_rza_n = gkyl_array_cfetch(mirror_grid->nodes_rza, gkyl_range_idx(&gk_geom->nrange_corn, cidx)); - const double *mirror_psi_n = gkyl_array_cfetch(mirror_grid->nodes_psi, gkyl_range_idx(&gk_geom->nrange_corn, cidx)); - const struct gkyl_mirror_grid_gen_geom *mirror_geo_n = gkyl_array_cfetch(mirror_grid->nodes_geom, gkyl_range_idx(&gk_geom->nrange_corn, cidx)); + const double *mirror_rza_n = + gkyl_array_cfetch(mirror_grid->nodes_rza, gkyl_range_idx(&gk_geom->nrange_corn, cidx)); + const double *mirror_psi_n = + gkyl_array_cfetch(mirror_grid->nodes_psi, gkyl_range_idx(&gk_geom->nrange_corn, cidx)); + const struct gkyl_mirror_grid_gen_geom *mirror_geo_n = + gkyl_array_cfetch(mirror_grid->nodes_geom, gkyl_range_idx(&gk_geom->nrange_corn, cidx)); // Next fetch the gk_geometry nodal values at this location - double *mc2p_n = gkyl_array_fetch(gk_geom->geo_corn.mc2p_nodal, gkyl_range_idx(&gk_geom->nrange_corn, cidx)); - double *mc2nu_pos_n = gkyl_array_fetch(gk_geom->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(&gk_geom->nrange_corn, cidx)); - double *bmag_n = gkyl_array_fetch(gk_geom->geo_corn.bmag_nodal, gkyl_range_idx(&gk_geom->nrange_corn, cidx)); + double *mc2p_n = gkyl_array_fetch( + gk_geom->geo_corn.mc2p_nodal, gkyl_range_idx(&gk_geom->nrange_corn, cidx) + ); + double *mc2nu_pos_n = gkyl_array_fetch( + gk_geom->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(&gk_geom->nrange_corn, cidx) + ); + double *bmag_n = gkyl_array_fetch( + gk_geom->geo_corn.bmag_nodal, gkyl_range_idx(&gk_geom->nrange_corn, cidx) + ); // Set mapc2p mc2p_n[0] = mirror_rza_n[0]; // R @@ -77,96 +91,140 @@ void gkyl_calc_metric_mirror_advance( mc2nu_pos_n[1] = mirror_rza_n[2]; mc2nu_pos_n[2] = mirror_rza_n[1]; // Set bmag - struct gkyl_vec3 B_cart = gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->B); + struct gkyl_vec3 B_cart = + gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->B); bmag_n[0] = gkyl_vec3_len(B_cart); } } } - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_corn, &gk_geom->local, 3, - gk_geom->geo_corn.mc2p_nodal, gk_geom->geo_corn.mc2p, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_corn, &gk_geom->local, 3, - gk_geom->geo_corn.mc2nu_pos_nodal, gk_geom->geo_corn.mc2nu_pos, false); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_corn, &gk_geom->local, 1, - gk_geom->geo_corn.bmag_nodal, gk_geom->geo_corn.bmag, false); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_corn, &gk_geom->local, 3, + gk_geom->geo_corn.mc2p_nodal, gk_geom->geo_corn.mc2p, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_corn, &gk_geom->local, 3, + gk_geom->geo_corn.mc2nu_pos_nodal, gk_geom->geo_corn.mc2nu_pos, false + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_corn, &gk_geom->local, 1, + gk_geom->geo_corn.bmag_nodal, gk_geom->geo_corn.bmag, false + ); // Need 1/B for LBO collisions, computed weakly. - gkyl_dg_inv_op_range(up->cbasis, 0, gk_geom->geo_corn.bmag_inv, 0, gk_geom->geo_corn.bmag, &gk_geom->local); - + gkyl_dg_inv_op_range( + up->cbasis, 0, gk_geom->geo_corn.bmag_inv, 0, gk_geom->geo_corn.bmag, &gk_geom->local + ); } -void -gkyl_calc_metric_mirror_advance_interior( gkyl_calc_metric_mirror *up, struct gk_geometry *gk_geom, struct gkyl_mirror_grid_gen *mirror_grid) +void gkyl_calc_metric_mirror_advance_interior( + gkyl_calc_metric_mirror *up, struct gk_geometry *gk_geom, struct gkyl_mirror_grid_gen *mirror_grid +) { enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { R_IDX, Z_IDX, PHI_IDX }; // arrangement of cartesian coordinates int cidx[3]; - for(int ia=gk_geom->nrange_int.lower[AL_IDX]; ia<=gk_geom->nrange_int.upper[AL_IDX]; ++ia){ - for (int ip=gk_geom->nrange_int.lower[PSI_IDX]; ip<=gk_geom->nrange_int.upper[PSI_IDX]; ++ip) { - for (int it=gk_geom->nrange_int.lower[TH_IDX]; it<=gk_geom->nrange_int.upper[TH_IDX]; ++it) { + for (int ia = gk_geom->nrange_int.lower[AL_IDX]; ia <= gk_geom->nrange_int.upper[AL_IDX]; ++ia) { + for (int ip = gk_geom->nrange_int.lower[PSI_IDX]; ip <= gk_geom->nrange_int.upper[PSI_IDX]; + ++ip) { + for (int it = gk_geom->nrange_int.lower[TH_IDX]; it <= gk_geom->nrange_int.upper[TH_IDX]; + ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; // First fetch the mirror stuff at this location - const double *mirror_rza_n = gkyl_array_cfetch(mirror_grid->nodes_rza, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - const double *mirror_psi_n = gkyl_array_cfetch(mirror_grid->nodes_psi, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - const struct gkyl_mirror_grid_gen_geom *mirror_geo_n = gkyl_array_cfetch(mirror_grid->nodes_geom, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + const double *mirror_rza_n = + gkyl_array_cfetch(mirror_grid->nodes_rza, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + const double *mirror_psi_n = + gkyl_array_cfetch(mirror_grid->nodes_psi, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + const struct gkyl_mirror_grid_gen_geom *mirror_geo_n = + gkyl_array_cfetch(mirror_grid->nodes_geom, gkyl_range_idx(&gk_geom->nrange_int, cidx)); // Next fetch the gk_geometry nodal values at this location - double *mc2p_n = gkyl_array_fetch(gk_geom->geo_int.mc2p_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *jFld_n= gkyl_array_fetch(gk_geom->geo_int.jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *bmag_n = gkyl_array_fetch(gk_geom->geo_int.bmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *gFld_n= gkyl_array_fetch(gk_geom->geo_int.g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *bcartFld_n= gkyl_array_fetch(gk_geom->geo_int.bcart_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *tanvecFld_n= gkyl_array_fetch(gk_geom->geo_int.dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *dualFld_n= gkyl_array_fetch(gk_geom->geo_int.dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *dualmagFld_n = gkyl_array_fetch(gk_geom->geo_int.dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *normFld_n = gkyl_array_fetch(gk_geom->geo_int.normals_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *curlbhat_n = gkyl_array_fetch(gk_geom->geo_int.curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *dualcurlbhat_n = gkyl_array_fetch(gk_geom->geo_int.dualcurlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *B3_n = gkyl_array_fetch(gk_geom->geo_int.B3_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *dualcurlbhatoverB_n = gkyl_array_fetch(gk_geom->geo_int.dualcurlbhatoverB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *rtg33inv_n = gkyl_array_fetch(gk_geom->geo_int.rtg33inv_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); - double *bioverJB_n = gkyl_array_fetch(gk_geom->geo_int.bioverJB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *mc2p_n = + gkyl_array_fetch(gk_geom->geo_int.mc2p_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *jFld_n = gkyl_array_fetch( + gk_geom->geo_int.jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + double *bmag_n = + gkyl_array_fetch(gk_geom->geo_int.bmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *gFld_n = + gkyl_array_fetch(gk_geom->geo_int.g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *bcartFld_n = gkyl_array_fetch( + gk_geom->geo_int.bcart_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + double *tanvecFld_n = + gkyl_array_fetch(gk_geom->geo_int.dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *dualFld_n = + gkyl_array_fetch(gk_geom->geo_int.dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *dualmagFld_n = gkyl_array_fetch( + gk_geom->geo_int.dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + double *normFld_n = gkyl_array_fetch( + gk_geom->geo_int.normals_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + double *curlbhat_n = gkyl_array_fetch( + gk_geom->geo_int.curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + double *dualcurlbhat_n = gkyl_array_fetch( + gk_geom->geo_int.dualcurlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + double *B3_n = + gkyl_array_fetch(gk_geom->geo_int.B3_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx)); + double *dualcurlbhatoverB_n = gkyl_array_fetch( + gk_geom->geo_int.dualcurlbhatoverB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + double *rtg33inv_n = gkyl_array_fetch( + gk_geom->geo_int.rtg33inv_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); + double *bioverJB_n = gkyl_array_fetch( + gk_geom->geo_int.bioverJB_nodal, gkyl_range_idx(&gk_geom->nrange_int, cidx) + ); // Set mapc2p mc2p_n[0] = mirror_rza_n[0]; // R mc2p_n[1] = mirror_rza_n[1]; // Z mc2p_n[2] = mirror_rza_n[2]; // PHI // Set bmag - struct gkyl_vec3 B_cart = gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->B); + struct gkyl_vec3 B_cart = + gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->B); bmag_n[0] = gkyl_vec3_len(B_cart); // Set Jacobian jFld_n[0] = mirror_geo_n->Jc; // Set curl(bhat) - struct gkyl_vec3 curlbhat_cart = gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->curlbhat); + struct gkyl_vec3 curlbhat_cart = + gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->curlbhat); curlbhat_n[0] = curlbhat_cart.x[0]; curlbhat_n[1] = curlbhat_cart.x[1]; curlbhat_n[2] = curlbhat_cart.x[2]; // Set tangents and duals - for(int ivec=0; ivec<3; ivec++) { - struct gkyl_vec3 tan = gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->tang[ivec]); - struct gkyl_vec3 dual = gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->dual[ivec]); - tanvecFld_n[ivec*3 + 0] = tan.x[0]; - tanvecFld_n[ivec*3 + 1] = tan.x[1]; - tanvecFld_n[ivec*3 + 2] = tan.x[2]; - dualFld_n[ivec*3 + 0] = dual.x[0]; - dualFld_n[ivec*3 + 1] = dual.x[1]; - dualFld_n[ivec*3 + 2] = dual.x[2]; + for (int ivec = 0; ivec < 3; ivec++) { + struct gkyl_vec3 tan = + gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->tang[ivec]); + struct gkyl_vec3 dual = + gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->dual[ivec]); + tanvecFld_n[ivec * 3 + 0] = tan.x[0]; + tanvecFld_n[ivec * 3 + 1] = tan.x[1]; + tanvecFld_n[ivec * 3 + 2] = tan.x[2]; + dualFld_n[ivec * 3 + 0] = dual.x[0]; + dualFld_n[ivec * 3 + 1] = dual.x[1]; + dualFld_n[ivec * 3 + 2] = dual.x[2]; } // Set metric tensor int count = 0; - for (int i=0; i<3; ++i) { - for (int j=0; j<3; ++j) { - if (i > j) + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + if (i > j) { continue; - gFld_n[count] = tanvecFld_n[3*i+0]*tanvecFld_n[3*j+0] + tanvecFld_n[3*i+1]*tanvecFld_n[3*j+1] + tanvecFld_n[3*i+2]*tanvecFld_n[3*j+2]; + } + gFld_n[count] = tanvecFld_n[3 * i + 0] * tanvecFld_n[3 * j + 0] + + tanvecFld_n[3 * i + 1] * tanvecFld_n[3 * j + 1] + + tanvecFld_n[3 * i + 2] * tanvecFld_n[3 * j + 2]; count++; } } - // Now set derived geometric quantities double R = mc2p_n[R_IDX]; double Z = mc2p_n[Z_IDX]; @@ -175,146 +233,245 @@ gkyl_calc_metric_mirror_advance_interior( gkyl_calc_metric_mirror *up, struct gk // Calculate cartesian components of bhat double bi[3]; - bi[0] = gFld_n[2]/sqrt(gFld_n[5]); - bi[1] = gFld_n[4]/sqrt(gFld_n[5]); - bi[2] = gFld_n[5]/sqrt(gFld_n[5]); - bcartFld_n[0] = dualFld_n[0]*bi[0] + dualFld_n[3]*bi[1] + dualFld_n[6]*bi[2]; - bcartFld_n[1] = dualFld_n[1]*bi[0] + dualFld_n[4]*bi[1] + dualFld_n[7]*bi[2]; - bcartFld_n[2] = dualFld_n[2]*bi[0] + dualFld_n[5]*bi[1] + dualFld_n[8]*bi[2]; - - double norm1 = sqrt(dualFld_n[0]*dualFld_n[0] + dualFld_n[1]*dualFld_n[1] + dualFld_n[2]*dualFld_n[2]); - double norm2 = sqrt(dualFld_n[3]*dualFld_n[3] + dualFld_n[4]*dualFld_n[4] + dualFld_n[5]*dualFld_n[5]); - double norm3 = sqrt(dualFld_n[6]*dualFld_n[6] + dualFld_n[7]*dualFld_n[7] + dualFld_n[8]*dualFld_n[8]); + bi[0] = gFld_n[2] / sqrt(gFld_n[5]); + bi[1] = gFld_n[4] / sqrt(gFld_n[5]); + bi[2] = gFld_n[5] / sqrt(gFld_n[5]); + bcartFld_n[0] = dualFld_n[0] * bi[0] + dualFld_n[3] * bi[1] + dualFld_n[6] * bi[2]; + bcartFld_n[1] = dualFld_n[1] * bi[0] + dualFld_n[4] * bi[1] + dualFld_n[7] * bi[2]; + bcartFld_n[2] = dualFld_n[2] * bi[0] + dualFld_n[5] * bi[1] + dualFld_n[8] * bi[2]; + + double norm1 = sqrt( + dualFld_n[0] * dualFld_n[0] + dualFld_n[1] * dualFld_n[1] + dualFld_n[2] * dualFld_n[2] + ); + double norm2 = sqrt( + dualFld_n[3] * dualFld_n[3] + dualFld_n[4] * dualFld_n[4] + dualFld_n[5] * dualFld_n[5] + ); + double norm3 = sqrt( + dualFld_n[6] * dualFld_n[6] + dualFld_n[7] * dualFld_n[7] + dualFld_n[8] * dualFld_n[8] + ); dualmagFld_n[0] = norm1; dualmagFld_n[1] = norm2; dualmagFld_n[2] = norm3; - + // Set normal vectors - normFld_n[0] = dualFld_n[0]/norm1; - normFld_n[1] = dualFld_n[1]/norm1; - normFld_n[2] = dualFld_n[2]/norm1; + normFld_n[0] = dualFld_n[0] / norm1; + normFld_n[1] = dualFld_n[1] / norm1; + normFld_n[2] = dualFld_n[2] / norm1; - normFld_n[3] = dualFld_n[3]/norm2; - normFld_n[4] = dualFld_n[4]/norm2; - normFld_n[5] = dualFld_n[5]/norm2; + normFld_n[3] = dualFld_n[3] / norm2; + normFld_n[4] = dualFld_n[4] / norm2; + normFld_n[5] = dualFld_n[5] / norm2; - normFld_n[6] = dualFld_n[6]/norm3; - normFld_n[7] = dualFld_n[7]/norm3; - normFld_n[8] = dualFld_n[8]/norm3; + normFld_n[6] = dualFld_n[6] / norm3; + normFld_n[7] = dualFld_n[7] / norm3; + normFld_n[8] = dualFld_n[8] / norm3; - // Set e^m \dot curl(bhat) - dualcurlbhat_n[0] = dualFld_n[0]*curlbhat_n[0] + dualFld_n[1]*curlbhat_n[1] + dualFld_n[2]*curlbhat_n[2]; - dualcurlbhat_n[1] = dualFld_n[3]*curlbhat_n[0] + dualFld_n[4]*curlbhat_n[1] + dualFld_n[5]*curlbhat_n[2]; - dualcurlbhat_n[2] = dualFld_n[6]*curlbhat_n[0] + dualFld_n[7]*curlbhat_n[1] + dualFld_n[8]*curlbhat_n[2]; + // Set e^m \dot curl(bhat) + dualcurlbhat_n[0] = dualFld_n[0] * curlbhat_n[0] + dualFld_n[1] * curlbhat_n[1] + + dualFld_n[2] * curlbhat_n[2]; + dualcurlbhat_n[1] = dualFld_n[3] * curlbhat_n[0] + dualFld_n[4] * curlbhat_n[1] + + dualFld_n[5] * curlbhat_n[2]; + dualcurlbhat_n[2] = dualFld_n[6] * curlbhat_n[0] + dualFld_n[7] * curlbhat_n[1] + + dualFld_n[8] * curlbhat_n[2]; - // Set e^3 \dot B - B3_n[0] = bmag_n[0]/sqrt(gFld_n[5]); + // Set e^3 \dot B + B3_n[0] = bmag_n[0] / sqrt(gFld_n[5]); // set e^3 \dot B /|B| - dualcurlbhatoverB_n[0] = dualcurlbhat_n[0]/bmag_n[0]; - dualcurlbhatoverB_n[1] = dualcurlbhat_n[1]/bmag_n[0]; - dualcurlbhatoverB_n[2] = dualcurlbhat_n[2]/bmag_n[0]; + dualcurlbhatoverB_n[0] = dualcurlbhat_n[0] / bmag_n[0]; + dualcurlbhatoverB_n[1] = dualcurlbhat_n[1] / bmag_n[0]; + dualcurlbhatoverB_n[2] = dualcurlbhat_n[2] / bmag_n[0]; // set B^3/B = 1/sqrt(g_33) - rtg33inv_n[0] = 1.0/sqrt(gFld_n[5]); + rtg33inv_n[0] = 1.0 / sqrt(gFld_n[5]); // set b_i/JB - bioverJB_n[0] = gFld_n[2]/sqrt(gFld_n[5])/J/bmag_n[0]; - bioverJB_n[1] = gFld_n[4]/sqrt(gFld_n[5])/J/bmag_n[0]; - bioverJB_n[2] = gFld_n[5]/sqrt(gFld_n[5])/J/bmag_n[0]; + bioverJB_n[0] = gFld_n[2] / sqrt(gFld_n[5]) / J / bmag_n[0]; + bioverJB_n[1] = gFld_n[4] / sqrt(gFld_n[5]) / J / bmag_n[0]; + bioverJB_n[2] = gFld_n[5] / sqrt(gFld_n[5]) / J / bmag_n[0]; } } } - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.mc2p_nodal, gk_geom->geo_int.mc2p, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.bmag_nodal, gk_geom->geo_int.bmag, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 6, gk_geom->geo_int.g_ij_nodal, gk_geom->geo_int.g_ij, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.jacobgeo_nodal, gk_geom->geo_int.jacobgeo, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.bcart_nodal, gk_geom->geo_int.bcart, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, gk_geom->geo_int.dxdz_nodal, gk_geom->geo_int.dxdz, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, gk_geom->geo_int.dzdx_nodal, gk_geom->geo_int.dzdx, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.dualmag_nodal, gk_geom->geo_int.dualmag, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, gk_geom->geo_int.normals_nodal, gk_geom->geo_int.normals, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.dualcurlbhat_nodal, gk_geom->geo_int.dualcurlbhat, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.dualcurlbhatoverB_nodal, gk_geom->geo_int.dualcurlbhatoverB, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.rtg33inv_nodal, gk_geom->geo_int.rtg33inv, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.bioverJB_nodal, gk_geom->geo_int.bioverJB, true); - gkyl_nodal_ops_n2m(up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.B3_nodal, gk_geom->geo_int.B3, true); - + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.mc2p_nodal, gk_geom->geo_int.mc2p, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.bmag_nodal, gk_geom->geo_int.bmag, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 6, + gk_geom->geo_int.g_ij_nodal, gk_geom->geo_int.g_ij, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.jacobgeo_nodal, gk_geom->geo_int.jacobgeo, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.bcart_nodal, gk_geom->geo_int.bcart, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, + gk_geom->geo_int.dxdz_nodal, gk_geom->geo_int.dxdz, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, + gk_geom->geo_int.dzdx_nodal, gk_geom->geo_int.dzdx, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.dualmag_nodal, gk_geom->geo_int.dualmag, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 9, + gk_geom->geo_int.normals_nodal, gk_geom->geo_int.normals, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.dualcurlbhat_nodal, gk_geom->geo_int.dualcurlbhat, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.dualcurlbhatoverB_nodal, gk_geom->geo_int.dualcurlbhatoverB, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.rtg33inv_nodal, gk_geom->geo_int.rtg33inv, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.bioverJB_nodal, gk_geom->geo_int.bioverJB, true + ); + gkyl_nodal_ops_n2m( + up->n2m, up->cbasis, up->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.B3_nodal, gk_geom->geo_int.B3, true + ); } -void gkyl_calc_metric_mirror_advance_surface( gkyl_calc_metric_mirror *up, int dir, struct gk_geometry *gk_geom, struct gkyl_mirror_grid_gen *mirror_grid) +void gkyl_calc_metric_mirror_advance_surface( + gkyl_calc_metric_mirror *up, int dir, struct gk_geometry *gk_geom, + struct gkyl_mirror_grid_gen *mirror_grid +) { enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { R_IDX, Z_IDX, PHI_IDX }; // arrangement of cartesian coordinates int cidx[3]; - for(int ia=gk_geom->nrange_surf[dir].lower[AL_IDX]; ia<=gk_geom->nrange_surf[dir].upper[AL_IDX]; ++ia){ - for (int ip=gk_geom->nrange_surf[dir].lower[PSI_IDX]; ip<=gk_geom->nrange_surf[dir].upper[PSI_IDX]; ++ip) { - for (int it=gk_geom->nrange_surf[dir].lower[TH_IDX]; it<=gk_geom->nrange_surf[dir].upper[TH_IDX]; ++it) { + for (int ia = gk_geom->nrange_surf[dir].lower[AL_IDX]; + ia <= gk_geom->nrange_surf[dir].upper[AL_IDX]; ++ia) { + for (int ip = gk_geom->nrange_surf[dir].lower[PSI_IDX]; + ip <= gk_geom->nrange_surf[dir].upper[PSI_IDX]; ++ip) { + for (int it = gk_geom->nrange_surf[dir].lower[TH_IDX]; + it <= gk_geom->nrange_surf[dir].upper[TH_IDX]; ++it) { cidx[PSI_IDX] = ip; cidx[AL_IDX] = ia; cidx[TH_IDX] = it; // First fetch the mirror stuff at this location - const double *mirror_rza_n = gkyl_array_cfetch(mirror_grid->nodes_rza, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - const double *mirror_psi_n = gkyl_array_cfetch(mirror_grid->nodes_psi, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - const struct gkyl_mirror_grid_gen_geom *mirror_geo_n = gkyl_array_cfetch(mirror_grid->nodes_geom, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + const double *mirror_rza_n = gkyl_array_cfetch( + mirror_grid->nodes_rza, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + const double *mirror_psi_n = gkyl_array_cfetch( + mirror_grid->nodes_psi, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + const struct gkyl_mirror_grid_gen_geom *mirror_geo_n = gkyl_array_cfetch( + mirror_grid->nodes_geom, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); // Next fetch the gk_geometry nodal values at this location - double *mc2p_n = gkyl_array_fetch(gk_geom->geo_surf[dir].mc2p_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *jFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *bmag_n = gkyl_array_fetch(gk_geom->geo_surf[dir].bmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *gFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *biFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].b_i_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *cmagFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].cmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *bcartFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].bcart_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *tanvecFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *dualFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *dualmagFld_n = gkyl_array_fetch(gk_geom->geo_surf[dir].dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *normFld_n = gkyl_array_fetch(gk_geom->geo_surf[dir].normals_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *lenr_n = gkyl_array_fetch(gk_geom->geo_surf[dir].lenr_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *B3_n = gkyl_array_fetch(gk_geom->geo_surf[dir].B3_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *curlbhat_n = gkyl_array_fetch(gk_geom->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - double *normcurlbhat_n = gkyl_array_fetch(gk_geom->geo_surf[dir].normcurlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); + double *mc2p_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].mc2p_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *jFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].jacobgeo_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *bmag_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].bmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *gFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].g_ij_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *biFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].b_i_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *cmagFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].cmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *bcartFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].bcart_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *tanvecFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dxdz_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *dualFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dzdx_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *dualmagFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].dualmag_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *normFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].normals_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *lenr_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].lenr_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *B3_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].B3_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *curlbhat_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + double *normcurlbhat_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].normcurlbhat_nodal, + gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); // Set mapc2p mc2p_n[0] = mirror_rza_n[0]; // R mc2p_n[1] = mirror_rza_n[1]; // Z mc2p_n[2] = mirror_rza_n[2]; // PHI // Set bmag - struct gkyl_vec3 B_cart = gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->B); + struct gkyl_vec3 B_cart = + gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->B); bmag_n[0] = gkyl_vec3_len(B_cart); // Set Jacobian jFld_n[0] = mirror_geo_n->Jc; // Set curl(bhat) - struct gkyl_vec3 curlbhat_cart = gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->curlbhat); + struct gkyl_vec3 curlbhat_cart = + gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->curlbhat); curlbhat_n[0] = curlbhat_cart.x[0]; curlbhat_n[1] = curlbhat_cart.x[1]; curlbhat_n[2] = curlbhat_cart.x[2]; // Set tangents and duals - for(int ivec=0; ivec<3; ivec++) { - struct gkyl_vec3 tan = gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->tang[ivec]); - struct gkyl_vec3 dual = gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->dual[ivec]); - tanvecFld_n[ivec*3 + 0] = tan.x[0]; - tanvecFld_n[ivec*3 + 1] = tan.x[1]; - tanvecFld_n[ivec*3 + 2] = tan.x[2]; - dualFld_n[ivec*3 + 0] = dual.x[0]; - dualFld_n[ivec*3 + 1] = dual.x[1]; - dualFld_n[ivec*3 + 2] = dual.x[2]; + for (int ivec = 0; ivec < 3; ivec++) { + struct gkyl_vec3 tan = + gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->tang[ivec]); + struct gkyl_vec3 dual = + gkyl_vec3_polar_con_to_cart(mirror_rza_n[0], mirror_rza_n[2], mirror_geo_n->dual[ivec]); + tanvecFld_n[ivec * 3 + 0] = tan.x[0]; + tanvecFld_n[ivec * 3 + 1] = tan.x[1]; + tanvecFld_n[ivec * 3 + 2] = tan.x[2]; + dualFld_n[ivec * 3 + 0] = dual.x[0]; + dualFld_n[ivec * 3 + 1] = dual.x[1]; + dualFld_n[ivec * 3 + 2] = dual.x[2]; } // Set metric tensor int count = 0; - for (int i=0; i<3; ++i) { - for (int j=0; j<3; ++j) { - if (i > j) + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + if (i > j) { continue; - gFld_n[count] = tanvecFld_n[3*i+0]*tanvecFld_n[3*j+0] + tanvecFld_n[3*i+1]*tanvecFld_n[3*j+1] + tanvecFld_n[3*i+2]*tanvecFld_n[3*j+2]; + } + gFld_n[count] = tanvecFld_n[3 * i + 0] * tanvecFld_n[3 * j + 0] + + tanvecFld_n[3 * i + 1] * tanvecFld_n[3 * j + 1] + + tanvecFld_n[3 * i + 2] * tanvecFld_n[3 * j + 2]; count++; } } - // Set derived quantities double R = mc2p_n[R_IDX]; double Z = mc2p_n[Z_IDX]; @@ -322,51 +479,60 @@ void gkyl_calc_metric_mirror_advance_surface( gkyl_calc_metric_mirror *up, int d double phi = mc2p_n[PHI_IDX]; // Calculate cmag, bi, and jtot_inv - biFld_n[0] = gFld_n[2]/sqrt(gFld_n[5]); - biFld_n[1] = gFld_n[4]/sqrt(gFld_n[5]); - biFld_n[2] = gFld_n[5]/sqrt(gFld_n[5]); - - cmagFld_n[0] = jFld_n[0]*bmag_n[0]/sqrt(gFld_n[5]); - double *jtotinvFld_n= gkyl_array_fetch(gk_geom->geo_surf[dir].jacobtot_inv_nodal, gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx)); - jtotinvFld_n[0] = 1.0/(jFld_n[0]*bmag_n[0]); - - double norm1 = sqrt(dualFld_n[0]*dualFld_n[0] + dualFld_n[1]*dualFld_n[1] + dualFld_n[2]*dualFld_n[2]); - double norm2 = sqrt(dualFld_n[3]*dualFld_n[3] + dualFld_n[4]*dualFld_n[4] + dualFld_n[5]*dualFld_n[5]); - double norm3 = sqrt(dualFld_n[6]*dualFld_n[6] + dualFld_n[7]*dualFld_n[7] + dualFld_n[8]*dualFld_n[8]); + biFld_n[0] = gFld_n[2] / sqrt(gFld_n[5]); + biFld_n[1] = gFld_n[4] / sqrt(gFld_n[5]); + biFld_n[2] = gFld_n[5] / sqrt(gFld_n[5]); + + cmagFld_n[0] = jFld_n[0] * bmag_n[0] / sqrt(gFld_n[5]); + double *jtotinvFld_n = gkyl_array_fetch( + gk_geom->geo_surf[dir].jacobtot_inv_nodal, + gkyl_range_idx(&gk_geom->nrange_surf[dir], cidx) + ); + jtotinvFld_n[0] = 1.0 / (jFld_n[0] * bmag_n[0]); + + double norm1 = sqrt( + dualFld_n[0] * dualFld_n[0] + dualFld_n[1] * dualFld_n[1] + dualFld_n[2] * dualFld_n[2] + ); + double norm2 = sqrt( + dualFld_n[3] * dualFld_n[3] + dualFld_n[4] * dualFld_n[4] + dualFld_n[5] * dualFld_n[5] + ); + double norm3 = sqrt( + dualFld_n[6] * dualFld_n[6] + dualFld_n[7] * dualFld_n[7] + dualFld_n[8] * dualFld_n[8] + ); dualmagFld_n[0] = norm1; dualmagFld_n[1] = norm2; dualmagFld_n[2] = norm3; - + // Set normal vectors - normFld_n[0] = dualFld_n[0]/norm1; - normFld_n[1] = dualFld_n[1]/norm1; - normFld_n[2] = dualFld_n[2]/norm1; + normFld_n[0] = dualFld_n[0] / norm1; + normFld_n[1] = dualFld_n[1] / norm1; + normFld_n[2] = dualFld_n[2] / norm1; - normFld_n[3] = dualFld_n[3]/norm2; - normFld_n[4] = dualFld_n[4]/norm2; - normFld_n[5] = dualFld_n[5]/norm2; + normFld_n[3] = dualFld_n[3] / norm2; + normFld_n[4] = dualFld_n[4] / norm2; + normFld_n[5] = dualFld_n[5] / norm2; - normFld_n[6] = dualFld_n[6]/norm3; - normFld_n[7] = dualFld_n[7]/norm3; - normFld_n[8] = dualFld_n[8]/norm3; + normFld_n[6] = dualFld_n[6] / norm3; + normFld_n[7] = dualFld_n[7] / norm3; + normFld_n[8] = dualFld_n[8] / norm3; // Set lenr - lenr_n[0] = J*dualmagFld_n[dir]; - - // Set n^3 \dot B - B3_n[0] = bmag_n[0]/sqrt(gFld_n[5])/norm3; + lenr_n[0] = J * dualmagFld_n[dir]; - // Set n^m \dot curl(bhat) - normcurlbhat_n[0] = normFld_n[3*dir+0]*curlbhat_n[0] + normFld_n[3*dir+1]*curlbhat_n[1] + normFld_n[3*dir+2]*curlbhat_n[2]; + // Set n^3 \dot B + B3_n[0] = bmag_n[0] / sqrt(gFld_n[5]) / norm3; + // Set n^m \dot curl(bhat) + normcurlbhat_n[0] = normFld_n[3 * dir + 0] * curlbhat_n[0] + + normFld_n[3 * dir + 1] * curlbhat_n[1] + + normFld_n[3 * dir + 2] * curlbhat_n[2]; } } } } -void -gkyl_calc_metric_mirror_release(gkyl_calc_metric_mirror* up) +void gkyl_calc_metric_mirror_release(gkyl_calc_metric_mirror *up) { gkyl_nodal_ops_release(up->n2m); gkyl_free(up); diff --git a/gyrokinetic/zero/deflate_geo.c b/gyrokinetic/zero/deflate_geo.c index 4a8722a685..8fa5c74da9 100644 --- a/gyrokinetic/zero/deflate_geo.c +++ b/gyrokinetic/zero/deflate_geo.c @@ -6,106 +6,126 @@ #include #include - - -struct gkyl_deflate_geo* gkyl_deflate_geo_new(const struct gkyl_basis *cbasis,const struct gkyl_basis *deflated_cbasis, const struct gkyl_rect_grid *grid, const struct gkyl_rect_grid *deflated_grid, const int *rem_dirs, bool use_gpu){ - +struct gkyl_deflate_geo *gkyl_deflate_geo_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *deflated_cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_rect_grid *deflated_grid, + const int *rem_dirs, bool use_gpu +) +{ gkyl_deflate_geo *up = gkyl_malloc(sizeof(gkyl_deflate_geo)); up->grid = grid; up->deflated_grid = deflated_grid; up->basis = cbasis; up->deflated_basis = deflated_cbasis; - up->rem_dirs = gkyl_malloc(3*sizeof(int)); - for(int i=0; i<3; i++) + up->rem_dirs = gkyl_malloc(3 * sizeof(int)); + for (int i = 0; i < 3; i++) { up->rem_dirs[i] = rem_dirs[i]; // 1 to remove - up->kernel = deflate_geo_choose_kernel(up->rem_dirs, up->deflated_grid->ndim, cbasis->b_type, cbasis->poly_order); + } + up->kernel = deflate_geo_choose_kernel( + up->rem_dirs, up->deflated_grid->ndim, cbasis->b_type, cbasis->poly_order + ); return up; } -struct gkyl_deflate_geo_surf* gkyl_deflate_geo_surf_new(const struct gkyl_basis *cbasis, int deflated_num_basis, const struct gkyl_rect_grid *grid, const struct gkyl_rect_grid *deflated_grid, const int *rem_dirs, int dir, bool use_gpu){ - +struct gkyl_deflate_geo_surf *gkyl_deflate_geo_surf_new( + const struct gkyl_basis *cbasis, int deflated_num_basis, const struct gkyl_rect_grid *grid, + const struct gkyl_rect_grid *deflated_grid, const int *rem_dirs, int dir, bool use_gpu +) +{ struct gkyl_deflate_geo_surf *up = gkyl_malloc(sizeof(struct gkyl_deflate_geo_surf)); up->grid = grid; up->deflated_grid = deflated_grid; up->basis = cbasis; up->deflated_num_basis = deflated_num_basis; - up->rem_dirs = gkyl_malloc(3*sizeof(int)); + up->rem_dirs = gkyl_malloc(3 * sizeof(int)); up->dir = dir; - for(int i=0; i<3; i++) { + for (int i = 0; i < 3; i++) { up->rem_dirs[i] = rem_dirs[i]; // 1 to remove } - up->kernel = deflate_geo_surf_choose_kernel(up->dir, up->deflated_grid->ndim, cbasis->b_type, cbasis->poly_order); + up->kernel = deflate_geo_surf_choose_kernel( + up->dir, up->deflated_grid->ndim, cbasis->b_type, cbasis->poly_order + ); return up; } - -void gkyl_deflate_geo_advance(const gkyl_deflate_geo *up, const struct gkyl_range *range, const struct gkyl_range* deflated_range, const struct gkyl_array *field, struct gkyl_array *deflated_field, int ncomp){ +void gkyl_deflate_geo_advance( + const gkyl_deflate_geo *up, const struct gkyl_range *range, + const struct gkyl_range *deflated_range, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +) +{ // Inflated grid will always be 1 long in other directions - // So deflate reange to the cell at index 1 in the ignored directions (z or x and y). 1 and not 0 because it is a local range + // So deflate reange to the cell at index 1 in the ignored directions (z or x and y). 1 and not 0 because it is a local range int loc_dir[3] = {0.}; - for(int i = 0; i<3; i++){ + for (int i = 0; i < 3; i++) { loc_dir[i] = 1; - if(up->rem_dirs[i] == 1){ + if (up->rem_dirs[i] == 1) { loc_dir[i] = 1; } } int do_idx[3]; - for(int i = 0; i<3; i++) + for (int i = 0; i < 3; i++) { do_idx[i] = loc_dir[i]; + } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, deflated_range); - while(gkyl_range_iter_next(&iter)){ - int count = 0; - for(int i = 0; i<3; i++){ - if(up->rem_dirs[i]==0){ - do_idx[i] = iter.idx[count]; - count += 1; - } + while (gkyl_range_iter_next(&iter)) { + int count = 0; + for (int i = 0; i < 3; i++) { + if (up->rem_dirs[i] == 0) { + do_idx[i] = iter.idx[count]; + count += 1; } + } - long loc = gkyl_range_idx(range, do_idx); - const double *fld = gkyl_array_cfetch(field, loc); - - long loc_deflated = gkyl_range_idx(deflated_range, iter.idx); - double *fld_deflated = gkyl_array_fetch(deflated_field, loc_deflated); - for(int c = 0; ckernel(&fld[c*up->basis->num_basis], &fld_deflated[c*up->deflated_basis->num_basis]); - } - } + long loc = gkyl_range_idx(range, do_idx); + const double *fld = gkyl_array_cfetch(field, loc); + long loc_deflated = gkyl_range_idx(deflated_range, iter.idx); + double *fld_deflated = gkyl_array_fetch(deflated_field, loc_deflated); + for (int c = 0; c < ncomp; c++) { + up->kernel(&fld[c * up->basis->num_basis], &fld_deflated[c * up->deflated_basis->num_basis]); + } + } } -void gkyl_deflate_geo_advance_nodal(const gkyl_deflate_geo *up, const struct gkyl_range *nrange, const struct gkyl_range* deflated_nrange, const struct gkyl_array *field, struct gkyl_array *deflated_field, int ncomp){ +void gkyl_deflate_geo_advance_nodal( + const gkyl_deflate_geo *up, const struct gkyl_range *nrange, + const struct gkyl_range *deflated_nrange, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +) +{ // Inflated nodal range will always be 3 long in other directions // Use middle node (1) to populate deflated fields int loc_dir[3] = {0.}; - for(int i = 0; i<3; i++){ + for (int i = 0; i < 3; i++) { loc_dir[i] = 1; - if(up->rem_dirs[i] == 1){ + if (up->rem_dirs[i] == 1) { loc_dir[i] = 1; } } int do_idx[3]; - for(int i = 0; i<3; i++) + for (int i = 0; i < 3; i++) { do_idx[i] = loc_dir[i]; + } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, deflated_nrange); - while(gkyl_range_iter_next(&iter)){ + while (gkyl_range_iter_next(&iter)) { int count = 0; - for(int i = 0; i<3; i++){ - if(up->rem_dirs[i]==0){ + for (int i = 0; i < 3; i++) { + if (up->rem_dirs[i] == 0) { do_idx[i] = iter.idx[count]; count += 1; } @@ -116,80 +136,88 @@ void gkyl_deflate_geo_advance_nodal(const gkyl_deflate_geo *up, const struct gky long loc_deflated = gkyl_range_idx(deflated_nrange, iter.idx); double *fld_deflated = gkyl_array_fetch(deflated_field, loc_deflated); - for(int c = 0; crem_dirs[i] == 1){ + if (up->rem_dirs[i] == 1) { loc_dir[i] = 1; } } int do_idx[3]; - for(int i = 0; i<3; i++) + for (int i = 0; i < 3; i++) { do_idx[i] = loc_dir[i]; + } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, deflated_range); - while(gkyl_range_iter_next(&iter)){ - int count = 0; - for(int i = 0; i<3; i++){ - if(up->rem_dirs[i]==0){ - do_idx[i] = iter.idx[count]; - count += 1; - } + while (gkyl_range_iter_next(&iter)) { + int count = 0; + for (int i = 0; i < 3; i++) { + if (up->rem_dirs[i] == 0) { + do_idx[i] = iter.idx[count]; + count += 1; } + } - long loc = gkyl_range_idx(range, do_idx); - const double *fld = gkyl_array_cfetch(field, loc); - - long loc_deflated = gkyl_range_idx(deflated_range, iter.idx); - double *fld_deflated = gkyl_array_fetch(deflated_field, loc_deflated); - for(int c = 0; ckernel(&fld[c*up->basis->num_basis], &fld_deflated[c*up->deflated_num_basis]); - } - } + long loc = gkyl_range_idx(range, do_idx); + const double *fld = gkyl_array_cfetch(field, loc); + long loc_deflated = gkyl_range_idx(deflated_range, iter.idx); + double *fld_deflated = gkyl_array_fetch(deflated_field, loc_deflated); + for (int c = 0; c < ncomp; c++) { + up->kernel(&fld[c * up->basis->num_basis], &fld_deflated[c * up->deflated_num_basis]); + } + } } -void gkyl_deflate_geo_surf_advance_nodal(const struct gkyl_deflate_geo_surf *up, const struct gkyl_range *nrange, const struct gkyl_range* deflated_nrange, const struct gkyl_array *field, struct gkyl_array *deflated_field, int ncomp){ +void gkyl_deflate_geo_surf_advance_nodal( + const struct gkyl_deflate_geo_surf *up, const struct gkyl_range *nrange, + const struct gkyl_range *deflated_nrange, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +) +{ // Inflated grid will always be 1 long in other directions - // So deflate reange to the cell at index 1 in the ignored directions (z or x and y). 1 and not 0 because it is a local range + // So deflate reange to the cell at index 1 in the ignored directions (z or x and y). 1 and not 0 because it is a local range int loc_dir[3] = {0.}; - for(int i = 0; i<3; i++){ + for (int i = 0; i < 3; i++) { loc_dir[i] = 1; - if(up->rem_dirs[i] == 1){ + if (up->rem_dirs[i] == 1) { loc_dir[i] = 1; } } int do_idx[3]; - for(int i = 0; i<3; i++) + for (int i = 0; i < 3; i++) { do_idx[i] = loc_dir[i]; + } struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, deflated_nrange); - while(gkyl_range_iter_next(&iter)){ + while (gkyl_range_iter_next(&iter)) { int count = 0; - for(int i = 0; i<3; i++){ - if(up->rem_dirs[i]==0){ + for (int i = 0; i < 3; i++) { + if (up->rem_dirs[i] == 0) { do_idx[i] = iter.idx[count]; count += 1; } @@ -200,21 +228,20 @@ void gkyl_deflate_geo_surf_advance_nodal(const struct gkyl_deflate_geo_surf *up, long loc_deflated = gkyl_range_idx(deflated_nrange, iter.idx); double *fld_deflated = gkyl_array_fetch(deflated_field, loc_deflated); - for(int c = 0; crem_dirs); gkyl_free(up); } -void gkyl_deflate_geo_surf_release(struct gkyl_deflate_geo_surf* up){ +void gkyl_deflate_geo_surf_release(struct gkyl_deflate_geo_surf *up) +{ gkyl_free(up->rem_dirs); gkyl_free(up); } diff --git a/gyrokinetic/zero/deflate_zsurf.c b/gyrokinetic/zero/deflate_zsurf.c index 084f7f596b..fdef6bba48 100644 --- a/gyrokinetic/zero/deflate_zsurf.c +++ b/gyrokinetic/zero/deflate_zsurf.c @@ -6,40 +6,44 @@ #include #include -struct gkyl_deflate_zsurf* -gkyl_deflate_zsurf_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *deflated_cbasis, - int edge, bool use_gpu) +struct gkyl_deflate_zsurf *gkyl_deflate_zsurf_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *deflated_cbasis, int edge, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_deflate_zsurf_cu_dev_new(cbasis, deflated_cbasis, edge); - } -#endif + } +#endif gkyl_deflate_zsurf *up = gkyl_malloc(sizeof(*up)); up->use_gpu = use_gpu; up->num_basis = cbasis->num_basis; up->num_deflated_basis = deflated_cbasis->num_basis; up->cdim = cbasis->ndim; - up->kernel = deflate_zsurf_choose_kernel(cbasis->b_type, cbasis->ndim, edge, cbasis->poly_order); // edge = 0,1 = lo, up + up->kernel = deflate_zsurf_choose_kernel( + cbasis->b_type, cbasis->ndim, edge, + cbasis->poly_order + ); // edge = 0,1 = lo, up up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } - -void -gkyl_deflate_zsurf_advance(const gkyl_deflate_zsurf *up, int zidx, - const struct gkyl_range *range, const struct gkyl_range *deflated_range, - const struct gkyl_array *field, struct gkyl_array *deflated_field, int ncomp) +void gkyl_deflate_zsurf_advance( + const gkyl_deflate_zsurf *up, int zidx, const struct gkyl_range *range, + const struct gkyl_range *deflated_range, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(deflated_field)) { - return gkyl_deflate_zsurf_advance_cu(up, zidx, range, deflated_range, - field, deflated_field, ncomp); + return gkyl_deflate_zsurf_advance_cu( + up, zidx, range, deflated_range, field, deflated_field, ncomp + ); } #endif int do_idx[3]; @@ -47,25 +51,28 @@ gkyl_deflate_zsurf_advance(const gkyl_deflate_zsurf *up, int zidx, gkyl_range_iter_init(&iter, deflated_range); while (gkyl_range_iter_next(&iter)) { - for(int i = 0; i < up->cdim-1; i++) + for (int i = 0; i < up->cdim - 1; i++) { do_idx[i] = iter.idx[i]; - do_idx[up->cdim-1] = zidx; + } + do_idx[up->cdim - 1] = zidx; long loc = gkyl_range_idx(range, do_idx); const double *fld = gkyl_array_cfetch(field, loc); long loc_deflated = gkyl_range_idx(deflated_range, iter.idx); double *fld_deflated = gkyl_array_fetch(deflated_field, loc_deflated); - for(int c = 0; ckernel(&fld[c*up->num_basis], &fld_deflated[c*up->num_deflated_basis]); + for (int c = 0; c < ncomp; c++) { + up->kernel(&fld[c * up->num_basis], &fld_deflated[c * up->num_deflated_basis]); + } } } -void gkyl_deflate_zsurf_release(gkyl_deflate_zsurf* up) +void gkyl_deflate_zsurf_release(gkyl_deflate_zsurf *up) { #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { gkyl_cu_free(up->on_dev); + } #endif gkyl_free(up); } diff --git a/gyrokinetic/zero/deflate_zsurf_cu.cu b/gyrokinetic/zero/deflate_zsurf_cu.cu index 7aef4c44b0..5157c68e60 100644 --- a/gyrokinetic/zero/deflate_zsurf_cu.cu +++ b/gyrokinetic/zero/deflate_zsurf_cu.cu @@ -13,62 +13,67 @@ extern "C" { #include } -__global__ void -gkyl_deflate_zsurf_advance_cu_kernel(const struct gkyl_deflate_zsurf *up, int zidx, - struct gkyl_range range, struct gkyl_range deflated_range, - const struct gkyl_array* field, struct gkyl_array* deflated_field, int ncomp) +__global__ void gkyl_deflate_zsurf_advance_cu_kernel( + const struct gkyl_deflate_zsurf *up, int zidx, struct gkyl_range range, + struct gkyl_range deflated_range, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +) { int idx[GKYL_MAX_DIM]; int do_idx[3]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < deflated_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < deflated_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since deflated_range is a subrange gkyl_sub_range_inv_idx(&deflated_range, linc1, idx); - for(int i = 0; i < up->cdim-1; i++) + for (int i = 0; i < up->cdim - 1; i++) { do_idx[i] = idx[i]; - do_idx[up->cdim-1] = zidx; + } + do_idx[up->cdim - 1] = zidx; long linc = gkyl_range_idx(&range, do_idx); - const double *fld = (const double*) gkyl_array_cfetch(field, linc); + const double *fld = (const double *)gkyl_array_cfetch(field, linc); // convert back to a linear index on the super-range (with ghost cells) // linc will have jumps in it to jump over ghost cells - long linc_deflated = gkyl_range_idx(&deflated_range, idx); - double *fld_deflated = (double*) gkyl_array_fetch(deflated_field, linc_deflated); - for(int c = 0; ckernel(&fld[c*up->num_basis], &fld_deflated[c*up->num_deflated_basis]); + long linc_deflated = gkyl_range_idx(&deflated_range, idx); + double *fld_deflated = (double *)gkyl_array_fetch(deflated_field, linc_deflated); + for (int c = 0; c < ncomp; c++) { + up->kernel(&fld[c * up->num_basis], &fld_deflated[c * up->num_deflated_basis]); + } } } // Host-side wrapper for deflating 2d (x,z) modal expansion to a 1d (x) modal expansion -void -gkyl_deflate_zsurf_advance_cu(const struct gkyl_deflate_zsurf *up, int zidx, - const struct gkyl_range *range, const struct gkyl_range *deflated_range, - const struct gkyl_array *field, struct gkyl_array *deflated_field, int ncomp) +void gkyl_deflate_zsurf_advance_cu( + const struct gkyl_deflate_zsurf *up, int zidx, const struct gkyl_range *range, + const struct gkyl_range *deflated_range, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +) { int nblocks = deflated_range->nblocks; int nthreads = deflated_range->nthreads; - gkyl_deflate_zsurf_advance_cu_kernel<<>>(up->on_dev, zidx, - *range, *deflated_range, field->on_dev, deflated_field->on_dev, ncomp); + gkyl_deflate_zsurf_advance_cu_kernel<< > >( + up->on_dev, zidx, *range, *deflated_range, field->on_dev, deflated_field->on_dev, ncomp + ); } // CUDA kernel to set device pointers to em vars kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -deflate_zsurf_set_cu_dev_ptrs(struct gkyl_deflate_zsurf *up, enum gkyl_basis_type b_type, - int edge, int poly_order) +__global__ static void deflate_zsurf_set_cu_dev_ptrs( + struct gkyl_deflate_zsurf *up, enum gkyl_basis_type b_type, int edge, int poly_order +) { - up->kernel = deflate_zsurf_choose_kernel(b_type, up->cdim, edge, poly_order); // edge = 0,1 = lo, up + up->kernel = + deflate_zsurf_choose_kernel(b_type, up->cdim, edge, poly_order); // edge = 0,1 = lo, up } -struct gkyl_deflate_zsurf* -gkyl_deflate_zsurf_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *deflated_cbasis, int edge) +struct gkyl_deflate_zsurf *gkyl_deflate_zsurf_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *deflated_cbasis, int edge +) { - struct gkyl_deflate_zsurf *up = (struct gkyl_deflate_zsurf*) gkyl_malloc(sizeof(*up)); + struct gkyl_deflate_zsurf *up = (struct gkyl_deflate_zsurf *)gkyl_malloc(sizeof(*up)); up->num_basis = cbasis->num_basis; up->num_deflated_basis = deflated_cbasis->num_basis; @@ -81,13 +86,13 @@ gkyl_deflate_zsurf_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_deflate_zsurf *up_cu = (struct gkyl_deflate_zsurf*) gkyl_cu_malloc(sizeof(*up_cu)); + struct gkyl_deflate_zsurf *up_cu = (struct gkyl_deflate_zsurf *)gkyl_cu_malloc(sizeof(*up_cu)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_deflate_zsurf), GKYL_CU_MEMCPY_H2D); - deflate_zsurf_set_cu_dev_ptrs<<<1,1>>>(up_cu, b_type, edge, poly_order); + deflate_zsurf_set_cu_dev_ptrs<<<1, 1> > >(up_cu, b_type, edge, poly_order); // set parent on_dev pointer up->on_dev = up_cu; - + return up; } diff --git a/gyrokinetic/zero/deflated_dg_bin_ops.c b/gyrokinetic/zero/deflated_dg_bin_ops.c index 0aed221926..f516f75423 100644 --- a/gyrokinetic/zero/deflated_dg_bin_ops.c +++ b/gyrokinetic/zero/deflated_dg_bin_ops.c @@ -5,10 +5,10 @@ #include -struct gkyl_deflated_dg_bin_ops* -gkyl_deflated_dg_bin_ops_new(struct gkyl_rect_grid grid, - struct gkyl_basis *basis_on_dev, struct gkyl_basis basis, - struct gkyl_range local, bool use_gpu) +struct gkyl_deflated_dg_bin_ops *gkyl_deflated_dg_bin_ops_new( + struct gkyl_rect_grid grid, struct gkyl_basis *basis_on_dev, struct gkyl_basis basis, + struct gkyl_range local, bool use_gpu +) { struct gkyl_deflated_dg_bin_ops *up = gkyl_malloc(sizeof(*up)); up->use_gpu = use_gpu; @@ -21,7 +21,7 @@ gkyl_deflated_dg_bin_ops_new(struct gkyl_rect_grid grid, up->local = local; up->cdim = grid.ndim; - up->num_solves_z = up->local.upper[up->cdim-1] - up->local.lower[up->cdim-1] + 2; + up->num_solves_z = up->local.upper[up->cdim - 1] - up->local.lower[up->cdim - 1] + 2; up->d_bop_data = gkyl_malloc(sizeof(struct deflated_dg_bin_ops_data[up->num_solves_z])); int poly_order = up->basis.poly_order; @@ -29,50 +29,55 @@ gkyl_deflated_dg_bin_ops_new(struct gkyl_rect_grid grid, // Create 2d/3d nodal range nodal array to be populated int nodes[GKYL_MAX_DIM]; if (poly_order == 1) { - for (int d=0; dcdim; ++d) + for (int d = 0; d < up->cdim; ++d) { nodes[d] = gkyl_range_shape(&up->local, d) + 1; + } } if (poly_order == 2) { - for (int d=0; dcdim; ++d) - nodes[d] = 2*gkyl_range_shape(&up->local, d) + 1; + for (int d = 0; d < up->cdim; ++d) { + nodes[d] = 2 * gkyl_range_shape(&up->local, d) + 1; + } } gkyl_range_init_from_shape(&up->nrange, up->cdim, nodes); // Create deflated 1d/2d grid, ranges, basis, and nodal range - double deflated_lower[GKYL_MAX_DIM] = { 0.0 } ; - double deflated_upper[GKYL_MAX_DIM] = { 0.0 }; - int deflated_cells[GKYL_MAX_DIM] = { 0 }; - for(int i = 0; i < up->cdim-1; i++){ + double deflated_lower[GKYL_MAX_DIM] = {0.0}; + double deflated_upper[GKYL_MAX_DIM] = {0.0}; + int deflated_cells[GKYL_MAX_DIM] = {0}; + for (int i = 0; i < up->cdim - 1; i++) { deflated_lower[i] = up->grid.lower[i]; deflated_upper[i] = up->grid.upper[i]; deflated_cells[i] = up->grid.cells[i]; } - gkyl_rect_grid_init(&up->deflated_grid, up->cdim-1, deflated_lower, - deflated_upper, deflated_cells); - int deflated_nghost[GKYL_MAX_CDIM] = { 1 }; - gkyl_create_grid_ranges(&up->deflated_grid, deflated_nghost, - &up->deflated_local_ext, &up->deflated_local); - gkyl_cart_modal_serendip(&up->deflated_basis, up->cdim-1, poly_order); + gkyl_rect_grid_init( + &up->deflated_grid, up->cdim - 1, deflated_lower, deflated_upper, deflated_cells + ); + int deflated_nghost[GKYL_MAX_CDIM] = {1}; + gkyl_create_grid_ranges( + &up->deflated_grid, deflated_nghost, &up->deflated_local_ext, &up->deflated_local + ); + gkyl_cart_modal_serendip(&up->deflated_basis, up->cdim - 1, poly_order); if (up->use_gpu) { up->deflated_basis_on_dev = gkyl_cu_malloc(sizeof(struct gkyl_basis)); - gkyl_cart_modal_serendip_cu_dev(up->deflated_basis_on_dev, up->cdim-1, poly_order); + gkyl_cart_modal_serendip_cu_dev(up->deflated_basis_on_dev, up->cdim - 1, poly_order); up->nodal_fld = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->cdim, up->nrange.volume); - } - else { + } else { up->deflated_basis_on_dev = &up->deflated_basis; up->nodal_fld = gkyl_array_new(GKYL_DOUBLE, up->cdim, up->nrange.volume); } int deflated_nodes[up->deflated_grid.ndim]; - if (poly_order == 1){ - for (int d=0; ddeflated_grid.ndim; ++d) + if (poly_order == 1) { + for (int d = 0; d < up->deflated_grid.ndim; ++d) { deflated_nodes[d] = up->deflated_grid.cells[d] + 1; + } } - if (poly_order == 2){ - for (int d=0; ddeflated_grid.ndim; ++d) - deflated_nodes[d] = 2*(up->deflated_grid.cells[d]) + 1; + if (poly_order == 2) { + for (int d = 0; d < up->deflated_grid.ndim; ++d) { + deflated_nodes[d] = 2 * (up->deflated_grid.cells[d]) + 1; + } } gkyl_range_init_from_shape(&up->deflated_nrange, up->deflated_grid.ndim, deflated_nodes); @@ -85,29 +90,34 @@ gkyl_deflated_dg_bin_ops_new(struct gkyl_rect_grid grid, up->n2m_deflated = gkyl_nodal_ops_new(&up->deflated_basis, &up->deflated_grid, use_gpu); // Allocate memory for division - if (up->use_gpu) - up->mem = gkyl_dg_bin_op_mem_cu_dev_new(up->deflated_local.volume, up->deflated_basis.num_basis); - else + if (up->use_gpu) { + up->mem = + gkyl_dg_bin_op_mem_cu_dev_new(up->deflated_local.volume, up->deflated_basis.num_basis); + } else { up->mem = gkyl_dg_bin_op_mem_new(up->deflated_local.volume, up->deflated_basis.num_basis); + } // Allocate necessary fields and solvers for each z slice int ctr = 0; - for (int zidx = up->local.lower[up->cdim-1]; zidx <= up->local.upper[up->cdim-1]+1; zidx++) { + for (int zidx = up->local.lower[up->cdim - 1]; zidx <= up->local.upper[up->cdim - 1] + 1; + zidx++) { if (use_gpu) { - up->d_bop_data[ctr].deflated_lop = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->deflated_basis.num_basis, up->deflated_local_ext.volume); - up->d_bop_data[ctr].deflated_rop = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->deflated_basis.num_basis, up->deflated_local_ext.volume); - up->d_bop_data[ctr].deflated_out = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->deflated_basis.num_basis, up->deflated_local_ext.volume); - } - else { - up->d_bop_data[ctr].deflated_lop = gkyl_array_new(GKYL_DOUBLE, - up->deflated_basis.num_basis, up->deflated_local_ext.volume); - up->d_bop_data[ctr].deflated_rop = gkyl_array_new(GKYL_DOUBLE, - up->deflated_basis.num_basis, up->deflated_local_ext.volume); - up->d_bop_data[ctr].deflated_out = gkyl_array_new(GKYL_DOUBLE, - up->deflated_basis.num_basis, up->deflated_local_ext.volume); + up->d_bop_data[ctr].deflated_lop = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->deflated_basis.num_basis, up->deflated_local_ext.volume + ); + up->d_bop_data[ctr].deflated_rop = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->deflated_basis.num_basis, up->deflated_local_ext.volume + ); + up->d_bop_data[ctr].deflated_out = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->deflated_basis.num_basis, up->deflated_local_ext.volume + ); + } else { + up->d_bop_data[ctr].deflated_lop = + gkyl_array_new(GKYL_DOUBLE, up->deflated_basis.num_basis, up->deflated_local_ext.volume); + up->d_bop_data[ctr].deflated_rop = + gkyl_array_new(GKYL_DOUBLE, up->deflated_basis.num_basis, up->deflated_local_ext.volume); + up->d_bop_data[ctr].deflated_out = + gkyl_array_new(GKYL_DOUBLE, up->deflated_basis.num_basis, up->deflated_local_ext.volume); } ctr += 1; } @@ -115,78 +125,104 @@ gkyl_deflated_dg_bin_ops_new(struct gkyl_rect_grid grid, return up; } -void -deflated_dg_bin_ops_advance(enum deflated_dg_bin_ops_type op_type, struct gkyl_deflated_dg_bin_ops* up, - int c_oop, struct gkyl_array *out, int c_lop, struct gkyl_array *lop, int c_rop, struct gkyl_array* rop) +void deflated_dg_bin_ops_advance( + enum deflated_dg_bin_ops_type op_type, struct gkyl_deflated_dg_bin_ops *up, int c_oop, + struct gkyl_array *out, int c_lop, struct gkyl_array *lop, int c_rop, struct gkyl_array *rop +) { - - int lop_ncomp = lop->ncomp/up->basis.num_basis; - int rop_ncomp = lop->ncomp/up->basis.num_basis; + int lop_ncomp = lop->ncomp / up->basis.num_basis; + int rop_ncomp = lop->ncomp / up->basis.num_basis; int ctr = 0; - for (int zidx = up->local.lower[up->cdim-1]; zidx <= up->local.upper[up->cdim-1]; zidx++) { + for (int zidx = up->local.lower[up->cdim - 1]; zidx <= up->local.upper[up->cdim - 1]; zidx++) { // Deflate lop and rop - gkyl_deflate_zsurf_advance(up->deflator_lo, zidx, - &up->local, &up->deflated_local, lop, up->d_bop_data[ctr].deflated_lop, lop_ncomp); - gkyl_deflate_zsurf_advance(up->deflator_lo, zidx, - &up->local, &up->deflated_local, rop, up->d_bop_data[ctr].deflated_rop, rop_ncomp); + gkyl_deflate_zsurf_advance( + up->deflator_lo, zidx, &up->local, &up->deflated_local, lop, up->d_bop_data[ctr].deflated_lop, + lop_ncomp + ); + gkyl_deflate_zsurf_advance( + up->deflator_lo, zidx, &up->local, &up->deflated_local, rop, up->d_bop_data[ctr].deflated_rop, + rop_ncomp + ); // Divide or Multiply - if (op_type == GKYL_DEFLATED_DIV) - gkyl_dg_div_op_range(up->mem, &up->deflated_basis, c_oop, up->d_bop_data[ctr].deflated_out, - c_lop, up->d_bop_data[ctr].deflated_lop, c_rop, up->d_bop_data[ctr].deflated_rop, &up->deflated_local); - else if (op_type == GKYL_DEFLATED_MUL) - gkyl_dg_mul_op_range(&up->deflated_basis, c_oop, up->d_bop_data[ctr].deflated_out, c_lop, - up->d_bop_data[ctr].deflated_lop, c_rop, up->d_bop_data[ctr].deflated_rop, &up->deflated_local); + if (op_type == GKYL_DEFLATED_DIV) { + gkyl_dg_div_op_range( + up->mem, &up->deflated_basis, c_oop, up->d_bop_data[ctr].deflated_out, c_lop, + up->d_bop_data[ctr].deflated_lop, c_rop, up->d_bop_data[ctr].deflated_rop, + &up->deflated_local + ); + } else if (op_type == GKYL_DEFLATED_MUL) { + gkyl_dg_mul_op_range( + &up->deflated_basis, c_oop, up->d_bop_data[ctr].deflated_out, c_lop, + up->d_bop_data[ctr].deflated_lop, c_rop, up->d_bop_data[ctr].deflated_rop, + &up->deflated_local + ); + } // Modal to Nodal in 1d -> Store the result in the 2d nodal field - gkyl_nodal_ops_m2n_deflated(up->n2m_deflated, up->deflated_basis_on_dev, - &up->deflated_grid, &up->nrange, &up->deflated_nrange, &up->deflated_local, 1, - up->nodal_fld, up->d_bop_data[ctr].deflated_out, ctr); + gkyl_nodal_ops_m2n_deflated( + up->n2m_deflated, up->deflated_basis_on_dev, &up->deflated_grid, &up->nrange, + &up->deflated_nrange, &up->deflated_local, 1, up->nodal_fld, up->d_bop_data[ctr].deflated_out, + ctr + ); ctr += 1; - if (zidx == up->local.upper[up->cdim-1]) { + if (zidx == up->local.upper[up->cdim - 1]) { // Deflate lop and rop - gkyl_deflate_zsurf_advance(up->deflator_up, zidx, - &up->local, &up->deflated_local, lop, up->d_bop_data[ctr].deflated_lop, lop_ncomp); - gkyl_deflate_zsurf_advance(up->deflator_up, zidx, - &up->local, &up->deflated_local, rop, up->d_bop_data[ctr].deflated_rop, rop_ncomp); - + gkyl_deflate_zsurf_advance( + up->deflator_up, zidx, &up->local, &up->deflated_local, lop, + up->d_bop_data[ctr].deflated_lop, lop_ncomp + ); + gkyl_deflate_zsurf_advance( + up->deflator_up, zidx, &up->local, &up->deflated_local, rop, + up->d_bop_data[ctr].deflated_rop, rop_ncomp + ); // Divide or Multiply - if (op_type == GKYL_DEFLATED_DIV) - gkyl_dg_div_op_range(up->mem, &up->deflated_basis, c_oop, up->d_bop_data[ctr].deflated_out, - c_lop, up->d_bop_data[ctr].deflated_lop, c_rop, up->d_bop_data[ctr].deflated_rop, &up->deflated_local); - else if (op_type == GKYL_DEFLATED_MUL) - gkyl_dg_mul_op_range(&up->deflated_basis, c_oop, up->d_bop_data[ctr].deflated_out, - c_lop, up->d_bop_data[ctr].deflated_lop, c_rop, up->d_bop_data[ctr].deflated_rop, &up->deflated_local); + if (op_type == GKYL_DEFLATED_DIV) { + gkyl_dg_div_op_range( + up->mem, &up->deflated_basis, c_oop, up->d_bop_data[ctr].deflated_out, c_lop, + up->d_bop_data[ctr].deflated_lop, c_rop, up->d_bop_data[ctr].deflated_rop, + &up->deflated_local + ); + } else if (op_type == GKYL_DEFLATED_MUL) { + gkyl_dg_mul_op_range( + &up->deflated_basis, c_oop, up->d_bop_data[ctr].deflated_out, c_lop, + up->d_bop_data[ctr].deflated_lop, c_rop, up->d_bop_data[ctr].deflated_rop, + &up->deflated_local + ); + } // Modal to Nodal in 1d -> Store the result in the 2d nodal field - gkyl_nodal_ops_m2n_deflated(up->n2m_deflated, up->deflated_basis_on_dev, - &up->deflated_grid, &up->nrange, &up->deflated_nrange, &up->deflated_local, 1, - up->nodal_fld, up->d_bop_data[ctr].deflated_out, ctr); + gkyl_nodal_ops_m2n_deflated( + up->n2m_deflated, up->deflated_basis_on_dev, &up->deflated_grid, &up->nrange, + &up->deflated_nrange, &up->deflated_local, 1, up->nodal_fld, + up->d_bop_data[ctr].deflated_out, ctr + ); } } - gkyl_nodal_ops_n2m(up->n2m, up->basis_on_dev, &up->grid, &up->nrange, &up->local, 1, up->nodal_fld, out, false); - + gkyl_nodal_ops_n2m( + up->n2m, up->basis_on_dev, &up->grid, &up->nrange, &up->local, 1, up->nodal_fld, out, false + ); } - -void -gkyl_deflated_dg_bin_ops_mul(struct gkyl_deflated_dg_bin_ops* up, int c_oop, struct gkyl_array *out, - int c_lop, struct gkyl_array *lop, int c_rop, struct gkyl_array* rop) +void gkyl_deflated_dg_bin_ops_mul( + struct gkyl_deflated_dg_bin_ops *up, int c_oop, struct gkyl_array *out, int c_lop, + struct gkyl_array *lop, int c_rop, struct gkyl_array *rop +) { deflated_dg_bin_ops_advance(GKYL_DEFLATED_MUL, up, c_oop, out, c_lop, lop, c_rop, rop); } -void -gkyl_deflated_dg_bin_ops_div(struct gkyl_deflated_dg_bin_ops* up, int c_oop, struct gkyl_array *out, - int c_lop, struct gkyl_array *lop, int c_rop, struct gkyl_array* rop) +void gkyl_deflated_dg_bin_ops_div( + struct gkyl_deflated_dg_bin_ops *up, int c_oop, struct gkyl_array *out, int c_lop, + struct gkyl_array *lop, int c_rop, struct gkyl_array *rop +) { deflated_dg_bin_ops_advance(GKYL_DEFLATED_DIV, up, c_oop, out, c_lop, lop, c_rop, rop); } -void -gkyl_deflated_dg_bin_ops_release(struct gkyl_deflated_dg_bin_ops* up) +void gkyl_deflated_dg_bin_ops_release(struct gkyl_deflated_dg_bin_ops *up) { gkyl_array_release(up->nodal_fld); gkyl_nodal_ops_release(up->n2m); @@ -195,7 +231,8 @@ gkyl_deflated_dg_bin_ops_release(struct gkyl_deflated_dg_bin_ops* up) gkyl_deflate_zsurf_release(up->deflator_up); gkyl_dg_bin_op_mem_release(up->mem); int ctr = 0; - for (int zidx = up->local.lower[up->cdim-1]; zidx <= up->local.upper[up->cdim-1] + 1; zidx++) { + for (int zidx = up->local.lower[up->cdim - 1]; zidx <= up->local.upper[up->cdim - 1] + 1; + zidx++) { gkyl_array_release(up->d_bop_data[ctr].deflated_lop); gkyl_array_release(up->d_bop_data[ctr].deflated_rop); gkyl_array_release(up->d_bop_data[ctr].deflated_out); @@ -208,5 +245,3 @@ gkyl_deflated_dg_bin_ops_release(struct gkyl_deflated_dg_bin_ops* up) gkyl_free(up->d_bop_data); gkyl_free(up); } - - diff --git a/gyrokinetic/zero/deflated_fem_poisson.c b/gyrokinetic/zero/deflated_fem_poisson.c index 7f7df57346..aa6527f8de 100644 --- a/gyrokinetic/zero/deflated_fem_poisson.c +++ b/gyrokinetic/zero/deflated_fem_poisson.c @@ -4,18 +4,19 @@ #include // allocate array (filled with zeros) -static inline struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static inline struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { - struct gkyl_array* a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -struct gkyl_deflated_fem_poisson* -gkyl_deflated_fem_poisson_new(struct gkyl_rect_grid grid, struct gkyl_basis *basis_on_dev, struct gkyl_basis basis, - struct gkyl_range local, struct gkyl_range global_sub_range, struct gkyl_array *epsilon, struct gkyl_array *kSq, - struct gkyl_poisson_bc poisson_bc, struct gkyl_poisson_bias_plane_list *bias_plane_list, bool use_gpu) +struct gkyl_deflated_fem_poisson *gkyl_deflated_fem_poisson_new( + struct gkyl_rect_grid grid, struct gkyl_basis *basis_on_dev, struct gkyl_basis basis, + struct gkyl_range local, struct gkyl_range global_sub_range, struct gkyl_array *epsilon, + struct gkyl_array *kSq, struct gkyl_poisson_bc poisson_bc, + struct gkyl_poisson_bias_plane_list *bias_plane_list, bool use_gpu +) { struct gkyl_deflated_fem_poisson *up = gkyl_malloc(sizeof(*up)); up->use_gpu = use_gpu; @@ -32,61 +33,70 @@ gkyl_deflated_fem_poisson_new(struct gkyl_rect_grid grid, struct gkyl_basis *bas up->poisson_bc = poisson_bc; up->bias_plane_list = bias_plane_list; up->cdim = grid.ndim; - up->num_solves_z = up->local.upper[up->cdim-1] - up->local.lower[up->cdim-1] + 2; + up->num_solves_z = up->local.upper[up->cdim - 1] - up->local.lower[up->cdim - 1] + 2; up->d_fem_data = gkyl_malloc(sizeof(struct deflated_fem_data[up->num_solves_z])); // Check if one of the boundaries needs a spatially varying Dirichlet BC. up->isdirichletvar = false; - for (int d=0; dcdim; d++) up->isdirichletvar = up->isdirichletvar || - (poisson_bc.lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING || - poisson_bc.up_type[d] == GKYL_POISSON_DIRICHLET_VARYING); + for (int d = 0; d < up->cdim; d++) { + up->isdirichletvar = up->isdirichletvar || + (poisson_bc.lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING || + poisson_bc.up_type[d] == GKYL_POISSON_DIRICHLET_VARYING); + } int poly_order = up->basis.poly_order; // Create 2d/3d nodal range nodal array to be populated int nodes[GKYL_MAX_DIM]; if (poly_order == 1) { - for (int d=0; dcdim; ++d) + for (int d = 0; d < up->cdim; ++d) { nodes[d] = gkyl_range_shape(&up->local, d) + 1; + } } if (poly_order == 2) { - for (int d=0; dcdim; ++d) - nodes[d] = 2*gkyl_range_shape(&up->local, d) + 1; + for (int d = 0; d < up->cdim; ++d) { + nodes[d] = 2 * gkyl_range_shape(&up->local, d) + 1; + } } gkyl_range_init_from_shape(&up->nrange, up->cdim, nodes); // Create deflated 1d/2d grid, ranges, basis, and nodal range - double deflated_lower[GKYL_MAX_DIM] = { 0.0 } ; - double deflated_upper[GKYL_MAX_DIM] = { 0.0 }; - int deflated_cells[GKYL_MAX_DIM] = { 0 }; - for(int i = 0; i < up->cdim-1; i++){ + double deflated_lower[GKYL_MAX_DIM] = {0.0}; + double deflated_upper[GKYL_MAX_DIM] = {0.0}; + int deflated_cells[GKYL_MAX_DIM] = {0}; + for (int i = 0; i < up->cdim - 1; i++) { deflated_lower[i] = up->grid.lower[i]; deflated_upper[i] = up->grid.upper[i]; deflated_cells[i] = up->grid.cells[i]; } - gkyl_rect_grid_init(&up->deflated_grid, up->cdim-1, deflated_lower, deflated_upper, deflated_cells); - int deflated_nghost[GKYL_MAX_CDIM] = { 1 }; - gkyl_create_grid_ranges(&up->deflated_grid, deflated_nghost, &up->deflated_local_ext, &up->deflated_local); - gkyl_cart_modal_serendip(&up->deflated_basis, up->cdim-1, poly_order); + gkyl_rect_grid_init( + &up->deflated_grid, up->cdim - 1, deflated_lower, deflated_upper, deflated_cells + ); + int deflated_nghost[GKYL_MAX_CDIM] = {1}; + gkyl_create_grid_ranges( + &up->deflated_grid, deflated_nghost, &up->deflated_local_ext, &up->deflated_local + ); + gkyl_cart_modal_serendip(&up->deflated_basis, up->cdim - 1, poly_order); if (up->use_gpu) { up->deflated_basis_on_dev = gkyl_cu_malloc(sizeof(struct gkyl_basis)); - gkyl_cart_modal_serendip_cu_dev(up->deflated_basis_on_dev, up->cdim-1, poly_order); - } - else { + gkyl_cart_modal_serendip_cu_dev(up->deflated_basis_on_dev, up->cdim - 1, poly_order); + } else { up->deflated_basis_on_dev = &up->deflated_basis; } up->nodal_fld = mkarr(up->use_gpu, up->cdim, up->nrange.volume); int deflated_nodes[up->deflated_grid.ndim]; - if (poly_order == 1){ - for (int d=0; ddeflated_grid.ndim; ++d) + if (poly_order == 1) { + for (int d = 0; d < up->deflated_grid.ndim; ++d) { deflated_nodes[d] = up->deflated_grid.cells[d] + 1; + } } - if (poly_order == 2){ - for (int d=0; ddeflated_grid.ndim; ++d) - deflated_nodes[d] = 2*(up->deflated_grid.cells[d]) + 1; + if (poly_order == 2) { + for (int d = 0; d < up->deflated_grid.ndim; ++d) { + deflated_nodes[d] = 2 * (up->deflated_grid.cells[d]) + 1; + } } gkyl_range_init_from_shape(&up->deflated_nrange, up->deflated_grid.ndim, deflated_nodes); @@ -106,37 +116,58 @@ gkyl_deflated_fem_poisson_new(struct gkyl_rect_grid grid, struct gkyl_basis *bas // Allocate necessary fields and solvers for each z slice int ctr = 0; - for (int zidx = up->local.lower[up->cdim-1]; zidx <= up->local.upper[up->cdim-1]+1; zidx++) { + for (int zidx = up->local.lower[up->cdim - 1]; zidx <= up->local.upper[up->cdim - 1] + 1; + zidx++) { int defl_num_basis = up->deflated_basis.num_basis; - up->d_fem_data[ctr].deflated_rhs = mkarr(up->use_gpu, defl_num_basis, up->deflated_local_ext.volume); - up->d_fem_data[ctr].deflated_phi = mkarr(up->use_gpu, defl_num_basis, up->deflated_local_ext.volume); - up->d_fem_data[ctr].deflated_epsilon = mkarr(up->use_gpu, (2*up->deflated_grid.ndim-1)*defl_num_basis, up->deflated_local_ext.volume); - up->d_fem_data[ctr].deflated_nodal_fld = mkarr(up->use_gpu, up->deflated_grid.ndim, up->deflated_nrange.volume); - up->d_fem_data[ctr].deflated_phibc = up->isdirichletvar? - mkarr(up->use_gpu, defl_num_basis, up->deflated_local_ext.volume) : 0; - up->d_fem_data[ctr].deflated_kSq = up->ishelmholtz? - mkarr(up->use_gpu, (2*up->deflated_grid.ndim-1)*defl_num_basis, up->deflated_local_ext.volume) : 0; - - if (zidx == up->local.upper[up->cdim-1] + 1 ) { - gkyl_deflate_zsurf_advance(up->deflator_up, zidx-1, &up->local, &up->deflated_local, - epsilon, up->d_fem_data[ctr].deflated_epsilon, 2*up->deflated_grid.ndim-1); - if (up->ishelmholtz) - gkyl_deflate_zsurf_advance(up->deflator_up, zidx-1, &up->local, &up->deflated_local, - kSq, up->d_fem_data[ctr].deflated_kSq, 2*up->deflated_grid.ndim-1); - } - else { - gkyl_deflate_zsurf_advance(up->deflator_lo, zidx, &up->local, &up->deflated_local, - epsilon, up->d_fem_data[ctr].deflated_epsilon, 2*up->deflated_grid.ndim-1); - if (up->ishelmholtz) - gkyl_deflate_zsurf_advance(up->deflator_lo, zidx, &up->local, &up->deflated_local, - kSq, up->d_fem_data[ctr].deflated_kSq, 2*up->deflated_grid.ndim-1); + up->d_fem_data[ctr].deflated_rhs = + mkarr(up->use_gpu, defl_num_basis, up->deflated_local_ext.volume); + up->d_fem_data[ctr].deflated_phi = + mkarr(up->use_gpu, defl_num_basis, up->deflated_local_ext.volume); + up->d_fem_data[ctr].deflated_epsilon = mkarr( + up->use_gpu, (2 * up->deflated_grid.ndim - 1) * defl_num_basis, up->deflated_local_ext.volume + ); + up->d_fem_data[ctr].deflated_nodal_fld = + mkarr(up->use_gpu, up->deflated_grid.ndim, up->deflated_nrange.volume); + up->d_fem_data[ctr].deflated_phibc = + up->isdirichletvar ? mkarr(up->use_gpu, defl_num_basis, up->deflated_local_ext.volume) : 0; + up->d_fem_data[ctr].deflated_kSq = + up->ishelmholtz ? mkarr( + up->use_gpu, (2 * up->deflated_grid.ndim - 1) * defl_num_basis, + up->deflated_local_ext.volume + ) : + 0; + + if (zidx == up->local.upper[up->cdim - 1] + 1) { + gkyl_deflate_zsurf_advance( + up->deflator_up, zidx - 1, &up->local, &up->deflated_local, epsilon, + up->d_fem_data[ctr].deflated_epsilon, 2 * up->deflated_grid.ndim - 1 + ); + if (up->ishelmholtz) { + gkyl_deflate_zsurf_advance( + up->deflator_up, zidx - 1, &up->local, &up->deflated_local, kSq, + up->d_fem_data[ctr].deflated_kSq, 2 * up->deflated_grid.ndim - 1 + ); + } + } else { + gkyl_deflate_zsurf_advance( + up->deflator_lo, zidx, &up->local, &up->deflated_local, epsilon, + up->d_fem_data[ctr].deflated_epsilon, 2 * up->deflated_grid.ndim - 1 + ); + if (up->ishelmholtz) { + gkyl_deflate_zsurf_advance( + up->deflator_lo, zidx, &up->local, &up->deflated_local, kSq, + up->d_fem_data[ctr].deflated_kSq, 2 * up->deflated_grid.ndim - 1 + ); + } } // we check if we are at an extremal global index of z to apply the bias plane at extremal z values only - int global_zidx = zidx + up->global_sub_range.lower[up->cdim-1]; + int global_zidx = zidx + up->global_sub_range.lower[up->cdim - 1]; // check if the global index is equal to the lower or upper limit of the z grid - bool is_lower_z_edge = (zidx == up->local.lower[up->cdim-1]) && up->poisson_bc.contains_lower_z_edge; - bool is_upper_z_edge = (zidx == up->local.upper[up->cdim-1]+1) && up->poisson_bc.contains_upper_z_edge; + bool is_lower_z_edge = (zidx == up->local.lower[up->cdim - 1]) && + up->poisson_bc.contains_lower_z_edge; + bool is_upper_z_edge = (zidx == up->local.upper[up->cdim - 1] + 1) && + up->poisson_bc.contains_upper_z_edge; // store it in pisson_bc to pass it to gkyl_fem_poisson_new struct gkyl_poisson_bias_plane_list *bias_plane_list; if (is_upper_z_edge || is_lower_z_edge) { @@ -145,75 +176,102 @@ gkyl_deflated_fem_poisson_new(struct gkyl_rect_grid grid, struct gkyl_basis *bas bias_plane_list = NULL; } - up->d_fem_data[ctr].fem_poisson = gkyl_fem_poisson_new(&up->deflated_local, &up->deflated_grid, - up->deflated_basis, &up->poisson_bc, bias_plane_list, up->d_fem_data[ctr].deflated_epsilon, - up->d_fem_data[ctr].deflated_kSq, false, use_gpu); + up->d_fem_data[ctr].fem_poisson = gkyl_fem_poisson_new( + &up->deflated_local, &up->deflated_grid, up->deflated_basis, &up->poisson_bc, bias_plane_list, + up->d_fem_data[ctr].deflated_epsilon, up->d_fem_data[ctr].deflated_kSq, false, use_gpu + ); ctr += 1; } return up; } -void -gkyl_deflated_fem_poisson_advance(struct gkyl_deflated_fem_poisson *up, struct gkyl_array *rhs, - struct gkyl_array *phibc, struct gkyl_array* phi) +void gkyl_deflated_fem_poisson_advance( + struct gkyl_deflated_fem_poisson *up, struct gkyl_array *rhs, struct gkyl_array *phibc, + struct gkyl_array *phi +) { int ctr = 0; - int local_range_ctr = up->local.lower[up->cdim-1]; - for (int zidx = up->global_sub_range.lower[up->cdim-1]; zidx <= up->global_sub_range.upper[up->cdim-1]; zidx++) { + int local_range_ctr = up->local.lower[up->cdim - 1]; + for (int zidx = up->global_sub_range.lower[up->cdim - 1]; + zidx <= up->global_sub_range.upper[up->cdim - 1]; zidx++) { // Deflate rhs indexing global sub-range to fetch correct place in z - gkyl_deflate_zsurf_advance(up->deflator_lo, zidx, - &up->global_sub_range, &up->deflated_local, rhs, up->d_fem_data[ctr].deflated_rhs, 1); + gkyl_deflate_zsurf_advance( + up->deflator_lo, zidx, &up->global_sub_range, &up->deflated_local, rhs, + up->d_fem_data[ctr].deflated_rhs, 1 + ); if (up->isdirichletvar) { // Deflate the BC field. - gkyl_deflate_zsurf_advance(up->deflator_lo, zidx, - &up->global_sub_range, &up->deflated_local, phibc, up->d_fem_data[ctr].deflated_phibc, 1); + gkyl_deflate_zsurf_advance( + up->deflator_lo, zidx, &up->global_sub_range, &up->deflated_local, phibc, + up->d_fem_data[ctr].deflated_phibc, 1 + ); } - // Do the poisson solve - gkyl_fem_poisson_set_rhs(up->d_fem_data[ctr].fem_poisson, up->d_fem_data[ctr].deflated_rhs, up->d_fem_data[ctr].deflated_phibc); + // Do the poisson solve + gkyl_fem_poisson_set_rhs( + up->d_fem_data[ctr].fem_poisson, up->d_fem_data[ctr].deflated_rhs, + up->d_fem_data[ctr].deflated_phibc + ); gkyl_fem_poisson_solve(up->d_fem_data[ctr].fem_poisson, up->d_fem_data[ctr].deflated_phi); // Modal to Nodal in 1d -> Store the result in the 2d nodal field - gkyl_nodal_ops_m2n_deflated(up->n2m_deflated, up->deflated_basis_on_dev, - &up->deflated_grid, &up->nrange, &up->deflated_nrange, &up->deflated_local, 1, - up->nodal_fld, up->d_fem_data[ctr].deflated_phi, ctr); + gkyl_nodal_ops_m2n_deflated( + up->n2m_deflated, up->deflated_basis_on_dev, &up->deflated_grid, &up->nrange, + &up->deflated_nrange, &up->deflated_local, 1, up->nodal_fld, up->d_fem_data[ctr].deflated_phi, + ctr + ); ctr += 1; local_range_ctr += 1; - if (zidx == up->global_sub_range.upper[up->cdim-1]) { + if (zidx == up->global_sub_range.upper[up->cdim - 1]) { // Deflate rhs indexing global sub-range to fetch correct place in z - gkyl_deflate_zsurf_advance(up->deflator_up, zidx, - &up->global_sub_range, &up->deflated_local, rhs, up->d_fem_data[ctr].deflated_rhs, 1); + gkyl_deflate_zsurf_advance( + up->deflator_up, zidx, &up->global_sub_range, &up->deflated_local, rhs, + up->d_fem_data[ctr].deflated_rhs, 1 + ); if (up->isdirichletvar) { // Deflate the BC field. - gkyl_deflate_zsurf_advance(up->deflator_up, zidx, - &up->global_sub_range, &up->deflated_local, phibc, up->d_fem_data[ctr].deflated_phibc, 1); + gkyl_deflate_zsurf_advance( + up->deflator_up, zidx, &up->global_sub_range, &up->deflated_local, phibc, + up->d_fem_data[ctr].deflated_phibc, 1 + ); } - // Do the poisson solve - gkyl_fem_poisson_set_rhs(up->d_fem_data[ctr].fem_poisson, up->d_fem_data[ctr].deflated_rhs, up->d_fem_data[ctr].deflated_phibc); + // Do the poisson solve + gkyl_fem_poisson_set_rhs( + up->d_fem_data[ctr].fem_poisson, up->d_fem_data[ctr].deflated_rhs, + up->d_fem_data[ctr].deflated_phibc + ); gkyl_fem_poisson_solve(up->d_fem_data[ctr].fem_poisson, up->d_fem_data[ctr].deflated_phi); // Modal to Nodal in 1d -> Store the result in the 2d nodal rhs. - gkyl_nodal_ops_m2n_deflated(up->n2m_deflated, up->deflated_basis_on_dev, - &up->deflated_grid, &up->nrange, &up->deflated_nrange, &up->deflated_local, 1, - up->nodal_fld, up->d_fem_data[ctr].deflated_phi, ctr); + gkyl_nodal_ops_m2n_deflated( + up->n2m_deflated, up->deflated_basis_on_dev, &up->deflated_grid, &up->nrange, + &up->deflated_nrange, &up->deflated_local, 1, up->nodal_fld, + up->d_fem_data[ctr].deflated_phi, ctr + ); } } - gkyl_nodal_ops_n2m(up->n2m, up->basis_on_dev, &up->grid, &up->nrange, &up->local, 1, up->nodal_fld, phi, false); + gkyl_nodal_ops_n2m( + up->n2m, up->basis_on_dev, &up->grid, &up->nrange, &up->local, 1, up->nodal_fld, phi, false + ); } -void gkyl_deflated_fem_poisson_release(struct gkyl_deflated_fem_poisson* up){ +void gkyl_deflated_fem_poisson_release(struct gkyl_deflated_fem_poisson *up) +{ gkyl_array_release(up->nodal_fld); gkyl_nodal_ops_release(up->n2m); gkyl_nodal_ops_release(up->n2m_deflated); gkyl_deflate_zsurf_release(up->deflator_lo); gkyl_deflate_zsurf_release(up->deflator_up); int ctr = 0; - for (int zidx = up->local.lower[up->cdim-1]; zidx <= up->local.upper[up->cdim-1] + 1; zidx++) { + for (int zidx = up->local.lower[up->cdim - 1]; zidx <= up->local.upper[up->cdim - 1] + 1; + zidx++) { gkyl_array_release(up->d_fem_data[ctr].deflated_rhs); gkyl_array_release(up->d_fem_data[ctr].deflated_phi); gkyl_array_release(up->d_fem_data[ctr].deflated_epsilon); - if (up->isdirichletvar) + if (up->isdirichletvar) { gkyl_array_release(up->d_fem_data[ctr].deflated_phibc); - if (up->ishelmholtz) + } + if (up->ishelmholtz) { gkyl_array_release(up->d_fem_data[ctr].deflated_kSq); + } gkyl_array_release(up->d_fem_data[ctr].deflated_nodal_fld); gkyl_fem_poisson_release(up->d_fem_data[ctr].fem_poisson); ctr += 1; @@ -225,5 +283,3 @@ void gkyl_deflated_fem_poisson_release(struct gkyl_deflated_fem_poisson* up){ gkyl_free(up->d_fem_data); gkyl_free(up); } - - diff --git a/gyrokinetic/zero/dg_calc_gk_neut_hamil.c b/gyrokinetic/zero/dg_calc_gk_neut_hamil.c index 5674a171b2..ffdc5e22bb 100644 --- a/gyrokinetic/zero/dg_calc_gk_neut_hamil.c +++ b/gyrokinetic/zero/dg_calc_gk_neut_hamil.c @@ -8,16 +8,15 @@ #include #include -gkyl_dg_calc_gk_neut_hamil* -gkyl_dg_calc_gk_neut_hamil_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *basis, int cdim, bool use_gpu) +gkyl_dg_calc_gk_neut_hamil *gkyl_dg_calc_gk_neut_hamil_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *basis, int cdim, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { - return gkyl_dg_calc_gk_neut_hamil_cu_dev_new(phase_grid, - basis, cdim); - } -#endif + if (use_gpu) { + return gkyl_dg_calc_gk_neut_hamil_cu_dev_new(phase_grid, basis, cdim); + } +#endif gkyl_dg_calc_gk_neut_hamil *up = gkyl_malloc(sizeof(*up)); up->phase_grid = *phase_grid; @@ -30,13 +29,14 @@ gkyl_dg_calc_gk_neut_hamil_new(const struct gkyl_rect_grid *phase_grid, up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void gkyl_dg_calc_gk_neut_hamil_calc(struct gkyl_dg_calc_gk_neut_hamil *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* gij, struct gkyl_array* hamil) +void gkyl_dg_calc_gk_neut_hamil_calc( + struct gkyl_dg_calc_gk_neut_hamil *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *gij, struct gkyl_array *hamil +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(gij)) { @@ -45,7 +45,7 @@ void gkyl_dg_calc_gk_neut_hamil_calc(struct gkyl_dg_calc_gk_neut_hamil *up, #endif // Cell center array - double xc[GKYL_MAX_DIM]; + double xc[GKYL_MAX_DIM]; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, phase_range); while (gkyl_range_iter_next(&iter)) { diff --git a/gyrokinetic/zero/dg_calc_gk_neut_hamil_cu.cu b/gyrokinetic/zero/dg_calc_gk_neut_hamil_cu.cu index 0f6977018c..1fbb96b4a1 100644 --- a/gyrokinetic/zero/dg_calc_gk_neut_hamil_cu.cu +++ b/gyrokinetic/zero/dg_calc_gk_neut_hamil_cu.cu @@ -13,25 +13,24 @@ extern "C" { } // CUDA kernel to set device pointers to kernels. -__global__ static void -gkyl_dg_calc_gk_neut_hamil_set_cu_dev_ptrs(struct gkyl_dg_calc_gk_neut_hamil *up, - enum gkyl_basis_type b_type, int cdim, int vdim, int poly_order) +__global__ static void gkyl_dg_calc_gk_neut_hamil_set_cu_dev_ptrs( + struct gkyl_dg_calc_gk_neut_hamil *up, enum gkyl_basis_type b_type, int cdim, int vdim, + int poly_order +) { up->calc_hamil = choose_kern(b_type, cdim, vdim, poly_order); }; -__global__ static void -gkyl_dg_calc_gk_neut_hamil_calc_cu_kernel(struct gkyl_dg_calc_gk_neut_hamil *up, - const struct gkyl_range conf_range, const struct gkyl_range phase_range, - const struct gkyl_array* gij, struct gkyl_array* hamil) +__global__ static void gkyl_dg_calc_gk_neut_hamil_calc_cu_kernel( + struct gkyl_dg_calc_gk_neut_hamil *up, const struct gkyl_range conf_range, + const struct gkyl_range phase_range, const struct gkyl_array *gij, struct gkyl_array *hamil +) { int idx[GKYL_MAX_DIM]; // Cell center array - double xc[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < phase_range.volume; - linc1 += gridDim.x*blockDim.x) - { + double xc[GKYL_MAX_DIM]; + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < phase_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -41,46 +40,47 @@ gkyl_dg_calc_gk_neut_hamil_calc_cu_kernel(struct gkyl_dg_calc_gk_neut_hamil *up, long loc_conf = gkyl_range_idx(&conf_range, idx); long loc_phase = gkyl_range_idx(&phase_range, idx); - const double *gij_d = (const double*) gkyl_array_cfetch(gij, loc_conf); - double *hamil_d = (double*) gkyl_array_fetch(hamil, loc_phase); + const double *gij_d = (const double *)gkyl_array_cfetch(gij, loc_conf); + double *hamil_d = (double *)gkyl_array_fetch(hamil, loc_phase); up->calc_hamil(xc, up->phase_grid.dx, gij_d, hamil_d); } } -void gkyl_dg_calc_gk_neut_hamil_calc_cu(struct gkyl_dg_calc_gk_neut_hamil *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* gij, struct gkyl_array* hamil) +void gkyl_dg_calc_gk_neut_hamil_calc_cu( + struct gkyl_dg_calc_gk_neut_hamil *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *gij, struct gkyl_array *hamil +) { - int nblocks = phase_range->nblocks; int nthreads = phase_range->nthreads; - gkyl_dg_calc_gk_neut_hamil_calc_cu_kernel<<>>(up->on_dev, - *conf_range, *phase_range, gij->on_dev, hamil->on_dev); - + gkyl_dg_calc_gk_neut_hamil_calc_cu_kernel<< > >( + up->on_dev, *conf_range, *phase_range, gij->on_dev, hamil->on_dev + ); } -gkyl_dg_calc_gk_neut_hamil* -gkyl_dg_calc_gk_neut_hamil_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *basis, int cdim) -{ - gkyl_dg_calc_gk_neut_hamil *up = (struct gkyl_dg_calc_gk_neut_hamil*) gkyl_malloc(sizeof(*up)); +gkyl_dg_calc_gk_neut_hamil *gkyl_dg_calc_gk_neut_hamil_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *basis, int cdim +) +{ + gkyl_dg_calc_gk_neut_hamil *up = (struct gkyl_dg_calc_gk_neut_hamil *)gkyl_malloc(sizeof(*up)); up->phase_grid = *phase_grid; - int vdim = 3; + int vdim = 3; int poly_order = basis->poly_order; enum gkyl_basis_type b_type = basis->b_type; up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_calc_gk_neut_hamil *up_cu = (struct gkyl_dg_calc_gk_neut_hamil*) gkyl_cu_malloc(sizeof(*up_cu)); + struct gkyl_dg_calc_gk_neut_hamil *up_cu = + (struct gkyl_dg_calc_gk_neut_hamil *)gkyl_cu_malloc(sizeof(*up_cu)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_calc_gk_neut_hamil), GKYL_CU_MEMCPY_H2D); - gkyl_dg_calc_gk_neut_hamil_set_cu_dev_ptrs<<<1,1>>>(up_cu, b_type, cdim, vdim, poly_order); + gkyl_dg_calc_gk_neut_hamil_set_cu_dev_ptrs<<<1, 1> > >(up_cu, b_type, cdim, vdim, poly_order); // set parent on_dev pointer up->on_dev = up_cu; - + return up; } diff --git a/gyrokinetic/zero/dg_calc_gk_rad_vars.c b/gyrokinetic/zero/dg_calc_gk_rad_vars.c index 66f9919ba3..438306881b 100644 --- a/gyrokinetic/zero/dg_calc_gk_rad_vars.c +++ b/gyrokinetic/zero/dg_calc_gk_rad_vars.c @@ -9,33 +9,34 @@ #include #include -struct gkyl_gk_rad_drag* -gkyl_dg_calc_gk_rad_vars_drag_new(int num_collisions, - const int *num_densities, int ncomp, long sz, bool use_gpu) +struct gkyl_gk_rad_drag *gkyl_dg_calc_gk_rad_vars_drag_new( + int num_collisions, const int *num_densities, int ncomp, long sz, bool use_gpu +) { // Drag coefficient for each species. - struct gkyl_gk_rad_drag *drag_s = gkyl_malloc(num_collisions*sizeof(struct gkyl_gk_rad_drag)); - for (int i=0; idata[n]; - drag->arr = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, ncomp, sz) - : gkyl_array_new(GKYL_DOUBLE, ncomp, sz); + drag->arr = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, ncomp, sz) : + gkyl_array_new(GKYL_DOUBLE, ncomp, sz); } } // Create a temporary drag struct to store the on_dev pointers. - struct gkyl_gk_rad_drag *drag_s_dev = gkyl_malloc(num_collisions*sizeof(struct gkyl_gk_rad_drag)); - for (int i=0; ion_dev[n]; struct gkyl_gk_rad_drag *drag_ho = &drag_ne_ho->data[n]; drag_dev->arr = drag_ho->arr->on_dev; @@ -43,41 +44,45 @@ gkyl_dg_calc_gk_rad_vars_drag_new(int num_collisions, } // Now allocate the drag coeff as a function of density and assign its array to the on_dev pointers. - for (int i=0; idata[n]; gkyl_array_release(drag->arr); } @@ -86,17 +91,19 @@ gkyl_dg_calc_gk_rad_vars_drag_release(struct gkyl_gk_rad_drag *drag_s, int num_c gkyl_free(drag_s); } -gkyl_dg_calc_gk_rad_vars* -gkyl_dg_calc_gk_rad_vars_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, double charge, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu) +gkyl_dg_calc_gk_rad_vars *gkyl_dg_calc_gk_rad_vars_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, double charge, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { - return gkyl_dg_calc_gk_rad_vars_cu_dev_new(phase_grid, conf_basis, phase_basis, - charge, mass, gk_geom, vel_map); - } -#endif + return gkyl_dg_calc_gk_rad_vars_cu_dev_new( + phase_grid, conf_basis, phase_basis, charge, mass, gk_geom, vel_map + ); + } +#endif gkyl_dg_calc_gk_rad_vars *up = gkyl_malloc(sizeof(*up)); @@ -120,20 +127,22 @@ gkyl_dg_calc_gk_rad_vars_new(const struct gkyl_rect_grid *phase_grid, up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void gkyl_dg_calc_gk_rad_vars_nu_advance(const struct gkyl_dg_calc_gk_rad_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - double a, double alpha, double beta, double gamma, double v0, - struct gkyl_array* vnu_surf, struct gkyl_array* vnu, - struct gkyl_array* vsqnu_surf, struct gkyl_array* vsqnu) +void gkyl_dg_calc_gk_rad_vars_nu_advance( + const struct gkyl_dg_calc_gk_rad_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, double a, double alpha, double beta, double gamma, + double v0, struct gkyl_array *vnu_surf, struct gkyl_array *vnu, struct gkyl_array *vsqnu_surf, + struct gkyl_array *vsqnu +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(vnu_surf)) { - return gkyl_dg_calc_gk_rad_vars_nu_advance_cu(up, conf_range, phase_range, - a, alpha, beta, gamma, v0, vnu_surf, vnu, vsqnu_surf, vsqnu); + return gkyl_dg_calc_gk_rad_vars_nu_advance_cu( + up, conf_range, phase_range, a, alpha, beta, gamma, v0, vnu_surf, vnu, vsqnu_surf, vsqnu + ); } #endif int pdim = up->pdim; @@ -144,7 +153,9 @@ void gkyl_dg_calc_gk_rad_vars_nu_advance(const struct gkyl_dg_calc_gk_rad_vars * while (gkyl_range_iter_next(&iter)) { gkyl_copy_int_arr(pdim, iter.idx, idx); - for (int d=cdim; dvel_map->local_vel, idx_vel); @@ -152,35 +163,39 @@ void gkyl_dg_calc_gk_rad_vars_nu_advance(const struct gkyl_dg_calc_gk_rad_vars * const double *bmag_d = gkyl_array_cfetch(up->gk_geom->geo_int.bmag, loc_conf); - double* vnu_surf_d = gkyl_array_fetch(vnu_surf, loc_phase); - double* vnu_d = gkyl_array_fetch(vnu, loc_phase); - double* vsqnu_surf_d = gkyl_array_fetch(vsqnu_surf, loc_phase); - double* vsqnu_d = gkyl_array_fetch(vsqnu, loc_phase); + double *vnu_surf_d = gkyl_array_fetch(vnu_surf, loc_phase); + double *vnu_d = gkyl_array_fetch(vnu, loc_phase); + double *vsqnu_surf_d = gkyl_array_fetch(vsqnu_surf, loc_phase); + double *vsqnu_d = gkyl_array_fetch(vsqnu, loc_phase); const double *vmap_d = gkyl_array_cfetch(up->vel_map->vmap, loc_vel); const double *vmapSq_d = gkyl_array_cfetch(up->vel_map->vmap_sq, loc_vel); - up->rad_nu_vpar(vmap_d, vmapSq_d, up->charge, up->mass, - a, alpha, beta, gamma, v0, bmag_d, vnu_surf_d, vnu_d); - up->rad_nu_mu(vmap_d, vmapSq_d, up->charge, up->mass, - a, alpha, beta, gamma, v0, bmag_d, vsqnu_surf_d, vsqnu_d); + up->rad_nu_vpar( + vmap_d, vmapSq_d, up->charge, up->mass, a, alpha, beta, gamma, v0, bmag_d, vnu_surf_d, vnu_d + ); + up->rad_nu_mu( + vmap_d, vmapSq_d, up->charge, up->mass, a, alpha, beta, gamma, v0, bmag_d, vsqnu_surf_d, + vsqnu_d + ); } } -void gkyl_dg_calc_gk_rad_vars_nI_nu_advance(const struct gkyl_dg_calc_gk_rad_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_gk_rad_drag* vnu_surf, const struct gkyl_gk_rad_drag* vnu, - const struct gkyl_gk_rad_drag* vsqnu_surf, const struct gkyl_gk_rad_drag* vsqnu, - const struct gkyl_array* n_elc_rad, const struct gkyl_array* n_elc, - const struct gkyl_array *nI, - struct gkyl_array* nvnu_surf, struct gkyl_array* nvnu, - struct gkyl_array* nvsqnu_surf, struct gkyl_array* nvsqnu, - struct gkyl_array* vtsq_min_normalized, struct gkyl_array* vtsq) +void gkyl_dg_calc_gk_rad_vars_nI_nu_advance( + const struct gkyl_dg_calc_gk_rad_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_gk_rad_drag *vnu_surf, + const struct gkyl_gk_rad_drag *vnu, const struct gkyl_gk_rad_drag *vsqnu_surf, + const struct gkyl_gk_rad_drag *vsqnu, const struct gkyl_array *n_elc_rad, + const struct gkyl_array *n_elc, const struct gkyl_array *nI, struct gkyl_array *nvnu_surf, + struct gkyl_array *nvnu, struct gkyl_array *nvsqnu_surf, struct gkyl_array *nvsqnu, + struct gkyl_array *vtsq_min_normalized, struct gkyl_array *vtsq +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(nI)) { - return gkyl_dg_calc_gk_rad_vars_nI_nu_advance_cu(up, conf_range, phase_range, - vnu_surf, vnu, vsqnu_surf, vsqnu, n_elc_rad, n_elc, nI, - nvnu_surf, nvnu, nvsqnu_surf, nvsqnu, vtsq_min_normalized, vtsq); + return gkyl_dg_calc_gk_rad_vars_nI_nu_advance_cu( + up, conf_range, phase_range, vnu_surf, vnu, vsqnu_surf, vsqnu, n_elc_rad, n_elc, nI, + nvnu_surf, nvnu, nvsqnu_surf, nvsqnu, vtsq_min_normalized, vtsq + ); } #endif int pdim = up->pdim; // pdim and cdim are constant across densities @@ -195,26 +210,27 @@ void gkyl_dg_calc_gk_rad_vars_nI_nu_advance(const struct gkyl_dg_calc_gk_rad_var long loc_conf = gkyl_range_idx(conf_range, idx); long loc_phase = gkyl_range_idx(phase_range, idx); - const double* vtsq_d = gkyl_array_cfetch(vtsq, loc_conf); + const double *vtsq_d = gkyl_array_cfetch(vtsq, loc_conf); - const double* ne = gkyl_array_cfetch(n_elc, loc_conf); - double ne_cell_avg = ne[0]/pow(2.0, cdim/2.0); + const double *ne = gkyl_array_cfetch(n_elc, loc_conf); + double ne_cell_avg = ne[0] / pow(2.0, cdim / 2.0); int ne_idx = gkyl_dg_rad_gyrokinetic_find_nearest_idx(n_elc_rad, ne_cell_avg); - const double* vtsq_min_d = gkyl_array_cfetch(vtsq_min_normalized, ne_idx); - if ( vtsq_d[0] > vtsq_min_d[0] ) { - const double* vnu_surf_d = gkyl_array_cfetch(vnu_surf->data[ne_idx].arr, loc_phase); - const double* vnu_d = gkyl_array_cfetch(vnu->data[ne_idx].arr, loc_phase); - const double* vsqnu_surf_d = gkyl_array_cfetch(vsqnu_surf->data[ne_idx].arr, loc_phase); - const double* vsqnu_d = gkyl_array_cfetch(vsqnu->data[ne_idx].arr, loc_phase); + const double *vtsq_min_d = gkyl_array_cfetch(vtsq_min_normalized, ne_idx); + if (vtsq_d[0] > vtsq_min_d[0]) { + const double *vnu_surf_d = gkyl_array_cfetch(vnu_surf->data[ne_idx].arr, loc_phase); + const double *vnu_d = gkyl_array_cfetch(vnu->data[ne_idx].arr, loc_phase); + const double *vsqnu_surf_d = gkyl_array_cfetch(vsqnu_surf->data[ne_idx].arr, loc_phase); + const double *vsqnu_d = gkyl_array_cfetch(vsqnu->data[ne_idx].arr, loc_phase); const double *nI_d = gkyl_array_cfetch(nI, loc_conf); - - double* nvnu_surf_d = gkyl_array_fetch(nvnu_surf, loc_phase); - double* nvnu_d = gkyl_array_fetch(nvnu, loc_phase); - double* nvsqnu_surf_d = gkyl_array_fetch(nvsqnu_surf, loc_phase); - double* nvsqnu_d = gkyl_array_fetch(nvsqnu, loc_phase); - - up->rad_nI_nu(vnu_surf_d, vnu_d, vsqnu_surf_d, vsqnu_d, nI_d, - nvnu_surf_d, nvnu_d, nvsqnu_surf_d, nvsqnu_d); + + double *nvnu_surf_d = gkyl_array_fetch(nvnu_surf, loc_phase); + double *nvnu_d = gkyl_array_fetch(nvnu, loc_phase); + double *nvsqnu_surf_d = gkyl_array_fetch(nvsqnu_surf, loc_phase); + double *nvsqnu_d = gkyl_array_fetch(nvsqnu, loc_phase); + + up->rad_nI_nu( + vnu_surf_d, vnu_d, vsqnu_surf_d, vsqnu_d, nI_d, nvnu_surf_d, nvnu_d, nvsqnu_surf_d, nvsqnu_d + ); } } } @@ -223,7 +239,8 @@ void gkyl_dg_calc_gk_rad_vars_release(gkyl_dg_calc_gk_rad_vars *up) { gkyl_gk_geometry_release(up->gk_geom); gkyl_velocity_map_release(up->vel_map); - if (GKYL_IS_CU_ALLOC(up->flags)) + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/gyrokinetic/zero/dg_calc_gk_rad_vars_cu.cu b/gyrokinetic/zero/dg_calc_gk_rad_vars_cu.cu index 3754efb201..04732e8b40 100644 --- a/gyrokinetic/zero/dg_calc_gk_rad_vars_cu.cu +++ b/gyrokinetic/zero/dg_calc_gk_rad_vars_cu.cu @@ -14,26 +14,25 @@ extern "C" { #include } -__global__ void -gkyl_dg_calc_gk_rad_vars_nu_advance_cu_kernel(struct gkyl_dg_calc_gk_rad_vars *up, - struct gkyl_range conf_range, struct gkyl_range phase_range, - double a, double alpha, double beta, double gamma, double v0, - struct gkyl_array* vnu_surf, struct gkyl_array* vnu, - struct gkyl_array* vsqnu_surf, struct gkyl_array* vsqnu) +__global__ void gkyl_dg_calc_gk_rad_vars_nu_advance_cu_kernel( + struct gkyl_dg_calc_gk_rad_vars *up, struct gkyl_range conf_range, struct gkyl_range phase_range, + double a, double alpha, double beta, double gamma, double v0, struct gkyl_array *vnu_surf, + struct gkyl_array *vnu, struct gkyl_array *vsqnu_surf, struct gkyl_array *vsqnu +) { int pdim = up->pdim; int cdim = up->cdim; int idx[GKYL_MAX_DIM], idx_vel[2]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < phase_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < phase_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange gkyl_sub_range_inv_idx(&phase_range, linc1, idx); - for (int d=cdim; dvel_map->local_vel, idx_vel); long loc_phase = gkyl_range_idx(&phase_range, idx); - const double *bmag_d = (const double*) gkyl_array_cfetch(up->gk_geom->geo_int.bmag, loc_conf); - - double* vnu_surf_d = (double*) gkyl_array_fetch(vnu_surf, loc_phase); - double* vnu_d = (double*) gkyl_array_fetch(vnu, loc_phase); - double* vsqnu_surf_d = (double*) gkyl_array_fetch(vsqnu_surf, loc_phase); - double* vsqnu_d = (double*) gkyl_array_fetch(vsqnu, loc_phase); - const double *vmap_d = (const double*) gkyl_array_cfetch(up->vel_map->vmap, loc_vel); - const double *vmapSq_d = (const double*) gkyl_array_cfetch(up->vel_map->vmap_sq, loc_vel); - - up->rad_nu_vpar(vmap_d, vmapSq_d, up->charge, up->mass, - a, alpha, beta, gamma, v0, bmag_d, vnu_surf_d, vnu_d); - up->rad_nu_mu(vmap_d, vmapSq_d, up->charge, up->mass, - a, alpha, beta, gamma, v0, bmag_d, vsqnu_surf_d, vsqnu_d); - } + const double *bmag_d = (const double *)gkyl_array_cfetch(up->gk_geom->geo_int.bmag, loc_conf); + + double *vnu_surf_d = (double *)gkyl_array_fetch(vnu_surf, loc_phase); + double *vnu_d = (double *)gkyl_array_fetch(vnu, loc_phase); + double *vsqnu_surf_d = (double *)gkyl_array_fetch(vsqnu_surf, loc_phase); + double *vsqnu_d = (double *)gkyl_array_fetch(vsqnu, loc_phase); + const double *vmap_d = (const double *)gkyl_array_cfetch(up->vel_map->vmap, loc_vel); + const double *vmapSq_d = (const double *)gkyl_array_cfetch(up->vel_map->vmap_sq, loc_vel); + + up->rad_nu_vpar( + vmap_d, vmapSq_d, up->charge, up->mass, a, alpha, beta, gamma, v0, bmag_d, vnu_surf_d, vnu_d + ); + up->rad_nu_mu( + vmap_d, vmapSq_d, up->charge, up->mass, a, alpha, beta, gamma, v0, bmag_d, vsqnu_surf_d, + vsqnu_d + ); + } } // Host-side wrapper for radiation drag coefficient calculation -void -gkyl_dg_calc_gk_rad_vars_nu_advance_cu(const struct gkyl_dg_calc_gk_rad_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - double a, double alpha, double beta, double gamma, double v0, - struct gkyl_array* vnu_surf, struct gkyl_array* vnu, - struct gkyl_array* vsqnu_surf, struct gkyl_array* vsqnu) +void gkyl_dg_calc_gk_rad_vars_nu_advance_cu( + const struct gkyl_dg_calc_gk_rad_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, double a, double alpha, double beta, double gamma, + double v0, struct gkyl_array *vnu_surf, struct gkyl_array *vnu, struct gkyl_array *vsqnu_surf, + struct gkyl_array *vsqnu +) { int nblocks = phase_range->nblocks; int nthreads = phase_range->nthreads; - gkyl_dg_calc_gk_rad_vars_nu_advance_cu_kernel<<>>(up->on_dev, - *conf_range, *phase_range, a, alpha, beta, gamma, v0, - vnu_surf->on_dev, vnu->on_dev, vsqnu_surf->on_dev, vsqnu->on_dev); + gkyl_dg_calc_gk_rad_vars_nu_advance_cu_kernel<< > >( + up->on_dev, *conf_range, *phase_range, a, alpha, beta, gamma, v0, vnu_surf->on_dev, vnu->on_dev, + vsqnu_surf->on_dev, vsqnu->on_dev + ); } -__global__ void -gkyl_dg_calc_gk_rad_vars_nI_nu_advance_cu_kernel(struct gkyl_dg_calc_gk_rad_vars *up, - struct gkyl_range conf_range, struct gkyl_range phase_range, - const struct gkyl_gk_rad_drag* vnu_surf, const struct gkyl_gk_rad_drag* vnu, - const struct gkyl_gk_rad_drag* vsqnu_surf, const struct gkyl_gk_rad_drag* vsqnu, - const struct gkyl_array* n_elc_rad, const struct gkyl_array* n_elc, - const struct gkyl_array *nI, - struct gkyl_array* nvnu_surf, struct gkyl_array* nvnu, - struct gkyl_array* nvsqnu_surf, struct gkyl_array* nvsqnu, - struct gkyl_array* vtsq_min_normalized, struct gkyl_array* vtsq) +__global__ void gkyl_dg_calc_gk_rad_vars_nI_nu_advance_cu_kernel( + struct gkyl_dg_calc_gk_rad_vars *up, struct gkyl_range conf_range, struct gkyl_range phase_range, + const struct gkyl_gk_rad_drag *vnu_surf, const struct gkyl_gk_rad_drag *vnu, + const struct gkyl_gk_rad_drag *vsqnu_surf, const struct gkyl_gk_rad_drag *vsqnu, + const struct gkyl_array *n_elc_rad, const struct gkyl_array *n_elc, const struct gkyl_array *nI, + struct gkyl_array *nvnu_surf, struct gkyl_array *nvnu, struct gkyl_array *nvsqnu_surf, + struct gkyl_array *nvsqnu, struct gkyl_array *vtsq_min_normalized, struct gkyl_array *vtsq +) { int cdim = up->cdim; int idx[GKYL_MAX_DIM]; - - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < phase_range.volume; - linc1 += gridDim.x*blockDim.x) - { + + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < phase_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -99,73 +98,74 @@ gkyl_dg_calc_gk_rad_vars_nI_nu_advance_cu_kernel(struct gkyl_dg_calc_gk_rad_vars // linc will have jumps in it to jump over ghost cells long loc_conf = gkyl_range_idx(&conf_range, idx); long loc_phase = gkyl_range_idx(&phase_range, idx); - const double* vtsq_d = (const double*) gkyl_array_cfetch(vtsq, loc_conf); + const double *vtsq_d = (const double *)gkyl_array_cfetch(vtsq, loc_conf); + + const double *ne = (const double *)gkyl_array_cfetch(n_elc, loc_conf); + double ne_cell_avg = ne[0] / pow(2.0, cdim / 2.0); - const double* ne = (const double*)gkyl_array_cfetch(n_elc, loc_conf); - double ne_cell_avg = ne[0]/pow(2.0, cdim/2.0); - // Find nearest index int ne_idx = gkyl_dg_rad_gyrokinetic_find_nearest_idx(n_elc_rad, ne_cell_avg); - const double* vtsq_min_d = (const double*) gkyl_array_cfetch(vtsq_min_normalized, ne_idx); - if ( vtsq_d[0] > vtsq_min_d[0] ) { - const double* vnu_surf_d = (const double*) gkyl_array_cfetch(vnu_surf[ne_idx].arr, loc_phase); - const double* vnu_d = (const double*) gkyl_array_cfetch(vnu[ne_idx].arr, loc_phase); - const double* vsqnu_surf_d = (const double*) gkyl_array_cfetch(vsqnu_surf[ne_idx].arr, loc_phase); - const double* vsqnu_d = (const double*) gkyl_array_cfetch(vsqnu[ne_idx].arr, loc_phase); - - const double *nI_d = (const double*) gkyl_array_cfetch(nI, loc_conf); - - double* nvnu_surf_d = (double*) gkyl_array_fetch(nvnu_surf, loc_phase); - double* nvnu_d = (double*) gkyl_array_fetch(nvnu, loc_phase); - double* nvsqnu_surf_d = (double*) gkyl_array_fetch(nvsqnu_surf, loc_phase); - double* nvsqnu_d = (double*) gkyl_array_fetch(nvsqnu, loc_phase); - - up->rad_nI_nu(vnu_surf_d, vnu_d, vsqnu_surf_d, vsqnu_d, nI_d, - nvnu_surf_d, nvnu_d, nvsqnu_surf_d, nvsqnu_d); + const double *vtsq_min_d = (const double *)gkyl_array_cfetch(vtsq_min_normalized, ne_idx); + if (vtsq_d[0] > vtsq_min_d[0]) { + const double *vnu_surf_d = (const double *)gkyl_array_cfetch(vnu_surf[ne_idx].arr, loc_phase); + const double *vnu_d = (const double *)gkyl_array_cfetch(vnu[ne_idx].arr, loc_phase); + const double *vsqnu_surf_d = + (const double *)gkyl_array_cfetch(vsqnu_surf[ne_idx].arr, loc_phase); + const double *vsqnu_d = (const double *)gkyl_array_cfetch(vsqnu[ne_idx].arr, loc_phase); + + const double *nI_d = (const double *)gkyl_array_cfetch(nI, loc_conf); + + double *nvnu_surf_d = (double *)gkyl_array_fetch(nvnu_surf, loc_phase); + double *nvnu_d = (double *)gkyl_array_fetch(nvnu, loc_phase); + double *nvsqnu_surf_d = (double *)gkyl_array_fetch(nvsqnu_surf, loc_phase); + double *nvsqnu_d = (double *)gkyl_array_fetch(nvsqnu, loc_phase); + + up->rad_nI_nu( + vnu_surf_d, vnu_d, vsqnu_surf_d, vsqnu_d, nI_d, nvnu_surf_d, nvnu_d, nvsqnu_surf_d, nvsqnu_d + ); } - } + } } // Host-side wrapper for sum_s n_{i_s} nu_s(v) calculation for a given input n_{i_s} and nu_s(v) -void -gkyl_dg_calc_gk_rad_vars_nI_nu_advance_cu(const struct gkyl_dg_calc_gk_rad_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_gk_rad_drag* vnu_surf, const struct gkyl_gk_rad_drag* vnu, - const struct gkyl_gk_rad_drag* vsqnu_surf, const struct gkyl_gk_rad_drag* vsqnu, - const struct gkyl_array* n_elc_rad, const struct gkyl_array* n_elc, - const struct gkyl_array *nI, - struct gkyl_array* nvnu_surf, struct gkyl_array* nvnu, - struct gkyl_array* nvsqnu_surf, struct gkyl_array* nvsqnu, - struct gkyl_array* vtsq_min_normalized, struct gkyl_array* vtsq) +void gkyl_dg_calc_gk_rad_vars_nI_nu_advance_cu( + const struct gkyl_dg_calc_gk_rad_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_gk_rad_drag *vnu_surf, + const struct gkyl_gk_rad_drag *vnu, const struct gkyl_gk_rad_drag *vsqnu_surf, + const struct gkyl_gk_rad_drag *vsqnu, const struct gkyl_array *n_elc_rad, + const struct gkyl_array *n_elc, const struct gkyl_array *nI, struct gkyl_array *nvnu_surf, + struct gkyl_array *nvnu, struct gkyl_array *nvsqnu_surf, struct gkyl_array *nvsqnu, + struct gkyl_array *vtsq_min_normalized, struct gkyl_array *vtsq +) { int nblocks = phase_range->nblocks; int nthreads = phase_range->nthreads; - gkyl_dg_calc_gk_rad_vars_nI_nu_advance_cu_kernel<<>>(up->on_dev, - *conf_range, *phase_range, - vnu_surf->on_dev, vnu->on_dev, vsqnu_surf->on_dev, vsqnu->on_dev, - n_elc_rad->on_dev, n_elc->on_dev, nI->on_dev, - nvnu_surf->on_dev, nvnu->on_dev, nvsqnu_surf->on_dev, nvsqnu->on_dev, - vtsq_min_normalized->on_dev, vtsq->on_dev); + gkyl_dg_calc_gk_rad_vars_nI_nu_advance_cu_kernel<< > >( + up->on_dev, *conf_range, *phase_range, vnu_surf->on_dev, vnu->on_dev, vsqnu_surf->on_dev, + vsqnu->on_dev, n_elc_rad->on_dev, n_elc->on_dev, nI->on_dev, nvnu_surf->on_dev, nvnu->on_dev, + nvsqnu_surf->on_dev, nvsqnu->on_dev, vtsq_min_normalized->on_dev, vtsq->on_dev + ); } // CUDA kernel to set device pointers to gyrokinetic radiation vars kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_calc_gk_rad_vars_set_cu_dev_ptrs(struct gkyl_dg_calc_gk_rad_vars *up, - int cdim, int vdim, int poly_order) +__global__ static void dg_calc_gk_rad_vars_set_cu_dev_ptrs( + struct gkyl_dg_calc_gk_rad_vars *up, int cdim, int vdim, int poly_order +) { up->rad_nu_vpar = choose_rad_gyrokinetic_nu_vpar_kern(cdim, vdim, poly_order); up->rad_nu_mu = choose_rad_gyrokinetic_nu_mu_kern(cdim, vdim, poly_order); up->rad_nI_nu = choose_rad_gyrokinetic_nI_nu_kern(cdim, vdim, poly_order); } -gkyl_dg_calc_gk_rad_vars* -gkyl_dg_calc_gk_rad_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, double charge, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map) +gkyl_dg_calc_gk_rad_vars *gkyl_dg_calc_gk_rad_vars_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, double charge, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map +) { - struct gkyl_dg_calc_gk_rad_vars *up = (struct gkyl_dg_calc_gk_rad_vars*) gkyl_malloc(sizeof(*up)); + struct gkyl_dg_calc_gk_rad_vars *up = (struct gkyl_dg_calc_gk_rad_vars *)gkyl_malloc(sizeof(*up)); up->phase_grid = *phase_grid; int cdim = conf_basis->ndim; @@ -187,17 +187,18 @@ gkyl_dg_calc_gk_rad_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_calc_gk_rad_vars *up_cu = (struct gkyl_dg_calc_gk_rad_vars*) gkyl_cu_malloc(sizeof(*up_cu)); + struct gkyl_dg_calc_gk_rad_vars *up_cu = + (struct gkyl_dg_calc_gk_rad_vars *)gkyl_cu_malloc(sizeof(*up_cu)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_calc_gk_rad_vars), GKYL_CU_MEMCPY_H2D); - dg_calc_gk_rad_vars_set_cu_dev_ptrs<<<1,1>>>(up_cu, cdim, vdim, poly_order); + dg_calc_gk_rad_vars_set_cu_dev_ptrs<<<1, 1> > >(up_cu, cdim, vdim, poly_order); // set parent on_dev pointer up->on_dev = up_cu; // Updater should store host pointers. - up->gk_geom = geom_ho; - up->vel_map = vel_map_ho; - + up->gk_geom = geom_ho; + up->vel_map = vel_map_ho; + return up; } diff --git a/gyrokinetic/zero/dg_cx.c b/gyrokinetic/zero/dg_cx.c index bb8c8edeaf..1855f57811 100644 --- a/gyrokinetic/zero/dg_cx.c +++ b/gyrokinetic/zero/dg_cx.c @@ -10,14 +10,13 @@ #include #include -gkyl_dg_cx* -gkyl_dg_cx_new(struct gkyl_dg_cx_inp *inp, bool use_gpu) +gkyl_dg_cx *gkyl_dg_cx_new(struct gkyl_dg_cx_inp *inp, bool use_gpu) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_dg_cx_cu_dev_new(inp); - } -#endif + } +#endif gkyl_dg_cx *up = gkyl_malloc(sizeof(struct gkyl_dg_cx)); up->cbasis = inp->cbasis; @@ -34,21 +33,24 @@ gkyl_dg_cx_new(struct gkyl_dg_cx_inp *inp, bool use_gpu) up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; - + return up; } -void gkyl_dg_cx_coll(const struct gkyl_dg_cx *up, - struct gkyl_array *maxwellian_moms_ion, struct gkyl_array *maxwellian_moms_neut, - struct gkyl_array *upar_b_i, struct gkyl_array *coef_cx, struct gkyl_array *cflrate) +void gkyl_dg_cx_coll( + const struct gkyl_dg_cx *up, struct gkyl_array *maxwellian_moms_ion, + struct gkyl_array *maxwellian_moms_neut, struct gkyl_array *upar_b_i, struct gkyl_array *coef_cx, + struct gkyl_array *cflrate +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(coef_cx)) { - return gkyl_dg_cx_coll_cu(up, maxwellian_moms_ion, maxwellian_moms_neut, - upar_b_i, coef_cx, cflrate); + return gkyl_dg_cx_coll_cu( + up, maxwellian_moms_ion, maxwellian_moms_neut, upar_b_i, coef_cx, cflrate + ); } #endif - + struct gkyl_range_iter conf_iter; gkyl_range_iter_init(&conf_iter, up->conf_rng); while (gkyl_range_iter_next(&conf_iter)) { @@ -59,14 +61,15 @@ void gkyl_dg_cx_coll(const struct gkyl_dg_cx *up, const double *upar_b_i_d = gkyl_array_cfetch(upar_b_i, linidx); double *coef_cx_d = gkyl_array_fetch(coef_cx, linidx); - - double cflr = up->react_rate(up->a, up->b, up->vt_sq_ion_min, up->vt_sq_neut_min, - maxwellian_moms_ion_d, maxwellian_moms_neut_d, upar_b_i_d, coef_cx_d); + + double cflr = up->react_rate( + up->a, up->b, up->vt_sq_ion_min, up->vt_sq_neut_min, maxwellian_moms_ion_d, + maxwellian_moms_neut_d, upar_b_i_d, coef_cx_d + ); } } -void -gkyl_dg_cx_release(gkyl_dg_cx* cx) +void gkyl_dg_cx_release(gkyl_dg_cx *cx) { free(cx); } diff --git a/gyrokinetic/zero/dg_cx_cu.cu b/gyrokinetic/zero/dg_cx_cu.cu index c91550ce56..f00f30cafb 100644 --- a/gyrokinetic/zero/dg_cx_cu.cu +++ b/gyrokinetic/zero/dg_cx_cu.cu @@ -13,50 +13,55 @@ extern "C" { } // CUDA kernel to set device pointers to kernels. -__global__ static void -gkyl_dg_cx_set_cu_dev_ptrs(struct gkyl_dg_cx *up, struct gkyl_basis cbasis) +__global__ static void gkyl_dg_cx_set_cu_dev_ptrs(struct gkyl_dg_cx *up, struct gkyl_basis cbasis) { up->react_rate = choose_kern(cbasis); }; -__global__ static void -gkyl_cx_react_rate_cu_ker(struct gkyl_dg_cx *up, const struct gkyl_range conf_rng, +__global__ static void gkyl_cx_react_rate_cu_ker( + struct gkyl_dg_cx *up, const struct gkyl_range conf_rng, const struct gkyl_array *maxwellian_moms_ion, const struct gkyl_array *maxwellian_moms_neut, - const struct gkyl_array *upar_b_i, double vt_sq_ion_min, double vt_sq_neut_min, - struct gkyl_array *coef_cx, double a, double b) + const struct gkyl_array *upar_b_i, double vt_sq_ion_min, double vt_sq_neut_min, + struct gkyl_array *coef_cx, double a, double b +) { int cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_rng.volume; tid += blockDim.x*gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_rng.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_rng, tid, cidx); long linidx = gkyl_range_idx(&conf_rng, cidx); - const double *maxwellian_moms_ion_d = (const double*) gkyl_array_cfetch(maxwellian_moms_ion, linidx); - const double *maxwellian_moms_neut_d = (const double*) gkyl_array_cfetch(maxwellian_moms_neut, linidx); - const double *upar_b_i_d = (const double*) gkyl_array_cfetch(upar_b_i, linidx); + const double *maxwellian_moms_ion_d = + (const double *)gkyl_array_cfetch(maxwellian_moms_ion, linidx); + const double *maxwellian_moms_neut_d = + (const double *)gkyl_array_cfetch(maxwellian_moms_neut, linidx); + const double *upar_b_i_d = (const double *)gkyl_array_cfetch(upar_b_i, linidx); - double *coef_cx_d = (double*) gkyl_array_fetch(coef_cx, linidx); + double *coef_cx_d = (double *)gkyl_array_fetch(coef_cx, linidx); // call the cx kernel - double cflr = up->react_rate(a, b, vt_sq_ion_min, vt_sq_neut_min, - maxwellian_moms_ion_d, maxwellian_moms_neut_d, upar_b_i_d, coef_cx_d); + double cflr = up->react_rate( + a, b, vt_sq_ion_min, vt_sq_neut_min, maxwellian_moms_ion_d, maxwellian_moms_neut_d, + upar_b_i_d, coef_cx_d + ); } } -void gkyl_dg_cx_coll_cu(const struct gkyl_dg_cx *up, - struct gkyl_array *maxwellian_moms_ion, struct gkyl_array *maxwellian_moms_neut, - struct gkyl_array *upar_b_i, struct gkyl_array *coef_cx, struct gkyl_array *cflrate) -{ - gkyl_cx_react_rate_cu_ker<<conf_rng->nblocks, up->conf_rng->nthreads>>>(up->on_dev, *up->conf_rng, - maxwellian_moms_ion->on_dev, maxwellian_moms_neut->on_dev, upar_b_i->on_dev, - up->vt_sq_ion_min, up->vt_sq_neut_min, coef_cx->on_dev, up->a, up->b); +void gkyl_dg_cx_coll_cu( + const struct gkyl_dg_cx *up, struct gkyl_array *maxwellian_moms_ion, + struct gkyl_array *maxwellian_moms_neut, struct gkyl_array *upar_b_i, struct gkyl_array *coef_cx, + struct gkyl_array *cflrate +) +{ + gkyl_cx_react_rate_cu_ker<<conf_rng->nblocks, up->conf_rng->nthreads> > >( + up->on_dev, *up->conf_rng, maxwellian_moms_ion->on_dev, maxwellian_moms_neut->on_dev, + upar_b_i->on_dev, up->vt_sq_ion_min, up->vt_sq_neut_min, coef_cx->on_dev, up->a, up->b + ); } -gkyl_dg_cx* -gkyl_dg_cx_cu_dev_new(struct gkyl_dg_cx_inp *inp) +gkyl_dg_cx *gkyl_dg_cx_cu_dev_new(struct gkyl_dg_cx_inp *inp) { - gkyl_dg_cx *up = (struct gkyl_dg_cx*) gkyl_malloc(sizeof(*up)); + gkyl_dg_cx *up = (struct gkyl_dg_cx *)gkyl_malloc(sizeof(*up)); up->cbasis = inp->cbasis; up->conf_rng = inp->conf_rng; @@ -65,17 +70,17 @@ gkyl_dg_cx_cu_dev_new(struct gkyl_dg_cx_inp *inp) up->vt_sq_neut_min = inp->vt_sq_neut_min; fit_param(up->type_ion, &up->a, &up->b); - + up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_cx *up_cu = (struct gkyl_dg_cx*) gkyl_cu_malloc(sizeof(*up_cu)); + struct gkyl_dg_cx *up_cu = (struct gkyl_dg_cx *)gkyl_cu_malloc(sizeof(*up_cu)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_cx), GKYL_CU_MEMCPY_H2D); - gkyl_dg_cx_set_cu_dev_ptrs<<<1,1>>>(up_cu, *up->cbasis); + gkyl_dg_cx_set_cu_dev_ptrs<<<1, 1> > >(up_cu, *up->cbasis); // Set parent on_dev pointer. up->on_dev = up_cu; - + return up; } diff --git a/gyrokinetic/zero/dg_diffusion_gyrokinetic.c b/gyrokinetic/zero/dg_diffusion_gyrokinetic.c index 96bb97bc3f..a9df427d74 100644 --- a/gyrokinetic/zero/dg_diffusion_gyrokinetic.c +++ b/gyrokinetic/zero/dg_diffusion_gyrokinetic.c @@ -9,23 +9,25 @@ #include #include -void -gkyl_dg_diffusion_gyrokinetic_free(const struct gkyl_ref_count *ref) +void gkyl_dg_diffusion_gyrokinetic_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object - struct dg_diffusion_gyrokinetic *diffusion = container_of(base->on_dev, struct dg_diffusion_gyrokinetic, eqn); + struct dg_diffusion_gyrokinetic *diffusion = + container_of(base->on_dev, struct dg_diffusion_gyrokinetic, eqn); gkyl_cu_free(diffusion); } - - struct dg_diffusion_gyrokinetic *diffusion = container_of(base, struct dg_diffusion_gyrokinetic, eqn); + + struct dg_diffusion_gyrokinetic *diffusion = + container_of(base, struct dg_diffusion_gyrokinetic, eqn); gkyl_free(diffusion); } -void -gkyl_dg_diffusion_gyrokinetic_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_gyrokinetic_auxfields auxin) +void gkyl_dg_diffusion_gyrokinetic_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_gyrokinetic_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(auxin.D) && gkyl_array_is_cu_dev(auxin.jacobgeo_inv)) { @@ -33,22 +35,26 @@ gkyl_dg_diffusion_gyrokinetic_set_auxfields(const struct gkyl_dg_eqn *eqn, struc return; } #endif - - struct dg_diffusion_gyrokinetic *diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); diffusion->auxfields.D = auxin.D; diffusion->auxfields.jacobgeo_inv = auxin.jacobgeo_inv; } -struct gkyl_dg_eqn* -gkyl_dg_diffusion_gyrokinetic_new(const struct gkyl_basis *basis, - const struct gkyl_basis *cbasis, bool is_diff_const, const bool *diff_in_dir, - int diff_order, const struct gkyl_range *diff_range, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_diffusion_gyrokinetic_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, + const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) - return gkyl_dg_diffusion_gyrokinetic_cu_dev_new(basis, cbasis, is_diff_const, diff_in_dir, diff_order, diff_range); + if (use_gpu) { + return gkyl_dg_diffusion_gyrokinetic_cu_dev_new( + basis, cbasis, is_diff_const, diff_in_dir, diff_order, diff_range + ); + } #endif - + struct dg_diffusion_gyrokinetic *diffusion = gkyl_malloc(sizeof(struct dg_diffusion_gyrokinetic)); int cdim = cbasis->ndim; @@ -57,37 +63,54 @@ gkyl_dg_diffusion_gyrokinetic_new(const struct gkyl_basis *basis, diffusion->const_coeff = is_diff_const; diffusion->num_basis = basis->num_basis; - for (int d=0; ddiff_in_dir[d] = diff_in_dir[d]; + for (int d = 0; d < cdim; d++) { + diffusion->diff_in_dir[d] = diff_in_dir[d]; + } const gkyl_dg_diffusion_gyrokinetic_vol_kern_list *vol_kernels; const gkyl_dg_diffusion_gyrokinetic_surf_kern_list *surfx_kernels; const gkyl_dg_diffusion_gyrokinetic_surf_kern_list *surfy_kernels; - const gkyl_dg_diffusion_gyrokinetic_surf_kern_list *surfz_kernels; + const gkyl_dg_diffusion_gyrokinetic_surf_kern_list *surfz_kernels; const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list *boundary_surfx_kernels; const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list *boundary_surfy_kernels; - const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list *boundary_surfz_kernels; + const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list *boundary_surfz_kernels; const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list *boundary_diagx_kernels; const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list *boundary_diagy_kernels; - const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list *boundary_diagz_kernels; + const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list *boundary_diagz_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = diffusion->const_coeff? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff ; - surfx_kernels = diffusion->const_coeff? ser_gyrokinetic_surfx_kernels_constcoeff : ser_gyrokinetic_surfx_kernels_varcoeff ; - surfy_kernels = diffusion->const_coeff? ser_gyrokinetic_surfy_kernels_constcoeff : ser_gyrokinetic_surfy_kernels_varcoeff ; - surfz_kernels = diffusion->const_coeff? ser_gyrokinetic_surfz_kernels_constcoeff : ser_gyrokinetic_surfz_kernels_varcoeff ; - boundary_surfx_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_surfx_kernels_constcoeff : ser_gyrokinetic_boundary_surfx_kernels_varcoeff; - boundary_surfy_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_surfy_kernels_constcoeff : ser_gyrokinetic_boundary_surfy_kernels_varcoeff; - boundary_surfz_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_surfz_kernels_constcoeff : ser_gyrokinetic_boundary_surfz_kernels_varcoeff; - boundary_diagx_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_diagx_kernels_constcoeff : ser_gyrokinetic_boundary_diagx_kernels_varcoeff; - boundary_diagy_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_diagy_kernels_constcoeff : ser_gyrokinetic_boundary_diagy_kernels_varcoeff; - boundary_diagz_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_diagz_kernels_constcoeff : ser_gyrokinetic_boundary_diagz_kernels_varcoeff; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = diffusion->const_coeff ? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff; + surfx_kernels = diffusion->const_coeff ? ser_gyrokinetic_surfx_kernels_constcoeff : + ser_gyrokinetic_surfx_kernels_varcoeff; + surfy_kernels = diffusion->const_coeff ? ser_gyrokinetic_surfy_kernels_constcoeff : + ser_gyrokinetic_surfy_kernels_varcoeff; + surfz_kernels = diffusion->const_coeff ? ser_gyrokinetic_surfz_kernels_constcoeff : + ser_gyrokinetic_surfz_kernels_varcoeff; + boundary_surfx_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_surfx_kernels_constcoeff : + ser_gyrokinetic_boundary_surfx_kernels_varcoeff; + boundary_surfy_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_surfy_kernels_constcoeff : + ser_gyrokinetic_boundary_surfy_kernels_varcoeff; + boundary_surfz_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_surfz_kernels_constcoeff : + ser_gyrokinetic_boundary_surfz_kernels_varcoeff; + boundary_diagx_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_diagx_kernels_constcoeff : + ser_gyrokinetic_boundary_diagx_kernels_varcoeff; + boundary_diagy_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_diagy_kernels_constcoeff : + ser_gyrokinetic_boundary_diagy_kernels_varcoeff; + boundary_diagz_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_diagz_kernels_constcoeff : + ser_gyrokinetic_boundary_diagz_kernels_varcoeff; + break; + + default: + assert(false); + break; + } int dirs_linidx = diffdirs_linidx(diff_in_dir, cdim); @@ -99,25 +122,37 @@ gkyl_dg_diffusion_gyrokinetic_new(const struct gkyl_basis *basis, diffusion->eqn.vol_term = CKVOL(vol_kernels, cdim, diff_order, poly_order, dirs_linidx); diffusion->surf[0] = CKSURF(surfx_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>1) + if (cdim > 1) { diffusion->surf[1] = CKSURF(surfy_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { diffusion->surf[2] = CKSURF(surfz_kernels, diff_order, cdim, vdim, poly_order); + } diffusion->boundary_surf[0] = CKSURF(boundary_surfx_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>1) - diffusion->boundary_surf[1] = CKSURF(boundary_surfy_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>2) - diffusion->boundary_surf[2] = CKSURF(boundary_surfz_kernels, diff_order, cdim, vdim, poly_order); + if (cdim > 1) { + diffusion->boundary_surf[1] = + CKSURF(boundary_surfy_kernels, diff_order, cdim, vdim, poly_order); + } + if (cdim > 2) { + diffusion->boundary_surf[2] = + CKSURF(boundary_surfz_kernels, diff_order, cdim, vdim, poly_order); + } diffusion->boundary_diag[0] = CKSURF(boundary_diagx_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>1) - diffusion->boundary_diag[1] = CKSURF(boundary_diagy_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>2) - diffusion->boundary_diag[2] = CKSURF(boundary_diagz_kernels, diff_order, cdim, vdim, poly_order); + if (cdim > 1) { + diffusion->boundary_diag[1] = + CKSURF(boundary_diagy_kernels, diff_order, cdim, vdim, poly_order); + } + if (cdim > 2) { + diffusion->boundary_diag[2] = + CKSURF(boundary_diagz_kernels, diff_order, cdim, vdim, poly_order); + } // Ensure non-NULL pointers. - for (int i=0; isurf[i]); + for (int i = 0; i < cdim; ++i) { + assert(diffusion->surf[i]); + } diffusion->auxfields.D = 0; diffusion->auxfields.jacobgeo_inv = 0; @@ -126,6 +161,6 @@ gkyl_dg_diffusion_gyrokinetic_new(const struct gkyl_basis *basis, diffusion->eqn.flags = 0; diffusion->eqn.ref_count = gkyl_ref_count_init(gkyl_dg_diffusion_gyrokinetic_free); diffusion->eqn.on_dev = &diffusion->eqn; - + return &diffusion->eqn; } diff --git a/gyrokinetic/zero/dg_diffusion_gyrokinetic_cu.cu b/gyrokinetic/zero/dg_diffusion_gyrokinetic_cu.cu index cab8b83178..e2a06a5447 100644 --- a/gyrokinetic/zero/dg_diffusion_gyrokinetic_cu.cu +++ b/gyrokinetic/zero/dg_diffusion_gyrokinetic_cu.cu @@ -4,7 +4,7 @@ extern "C" { #include #include -#include +#include #include } @@ -13,26 +13,33 @@ extern "C" { // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_dg_diffusion_gyrokinetic_set_auxfields_cu_kernel(const struct gkyl_dg_eqn* eqn, const struct gkyl_array* D, const struct gkyl_array* jacobgeo_inv) +__global__ static void gkyl_dg_diffusion_gyrokinetic_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *D, const struct gkyl_array *jacobgeo_inv +) { - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); diffusion->auxfields.D = D; diffusion->auxfields.jacobgeo_inv = jacobgeo_inv; } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_dg_diffusion_gyrokinetic_set_auxfields_cu(const struct gkyl_dg_eqn* eqn, struct gkyl_dg_diffusion_gyrokinetic_auxfields auxin) +void gkyl_dg_diffusion_gyrokinetic_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_gyrokinetic_auxfields auxin +) { - gkyl_dg_diffusion_gyrokinetic_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.D->on_dev, auxin.jacobgeo_inv->on_dev); + gkyl_dg_diffusion_gyrokinetic_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.D->on_dev, auxin.jacobgeo_inv->on_dev + ); } -__global__ void static -dg_diffusion_gyrokinetic_set_cu_dev_ptrs(struct dg_diffusion_gyrokinetic *diffusion, enum gkyl_basis_type b_type, int cdim, int vdim, int poly_order, int diff_order, int diffdirs_linidx) +__global__ void static dg_diffusion_gyrokinetic_set_cu_dev_ptrs( + struct dg_diffusion_gyrokinetic *diffusion, enum gkyl_basis_type b_type, int cdim, int vdim, + int poly_order, int diff_order, int diffdirs_linidx +) { - diffusion->auxfields.D = 0; - diffusion->auxfields.jacobgeo_inv = 0; + diffusion->auxfields.D = 0; + diffusion->auxfields.jacobgeo_inv = 0; const gkyl_dg_diffusion_gyrokinetic_vol_kern_list *vol_kernels; const gkyl_dg_diffusion_gyrokinetic_surf_kern_list *surfx_kernels; @@ -46,22 +53,37 @@ dg_diffusion_gyrokinetic_set_cu_dev_ptrs(struct dg_diffusion_gyrokinetic *diffus const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list *boundary_diagz_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = diffusion->const_coeff? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff ; - surfx_kernels = diffusion->const_coeff? ser_gyrokinetic_surfx_kernels_constcoeff : ser_gyrokinetic_surfx_kernels_varcoeff ; - surfy_kernels = diffusion->const_coeff? ser_gyrokinetic_surfy_kernels_constcoeff : ser_gyrokinetic_surfy_kernels_varcoeff ; - surfz_kernels = diffusion->const_coeff? ser_gyrokinetic_surfz_kernels_constcoeff : ser_gyrokinetic_surfz_kernels_varcoeff ; - boundary_surfx_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_surfx_kernels_constcoeff : ser_gyrokinetic_boundary_surfx_kernels_varcoeff; - boundary_surfy_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_surfy_kernels_constcoeff : ser_gyrokinetic_boundary_surfy_kernels_varcoeff; - boundary_surfz_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_surfz_kernels_constcoeff : ser_gyrokinetic_boundary_surfz_kernels_varcoeff; - boundary_diagx_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_diagx_kernels_constcoeff : ser_gyrokinetic_boundary_diagx_kernels_varcoeff; - boundary_diagy_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_diagy_kernels_constcoeff : ser_gyrokinetic_boundary_diagy_kernels_varcoeff; - boundary_diagz_kernels = diffusion->const_coeff? ser_gyrokinetic_boundary_diagz_kernels_constcoeff : ser_gyrokinetic_boundary_diagz_kernels_varcoeff; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = diffusion->const_coeff ? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff; + surfx_kernels = diffusion->const_coeff ? ser_gyrokinetic_surfx_kernels_constcoeff : + ser_gyrokinetic_surfx_kernels_varcoeff; + surfy_kernels = diffusion->const_coeff ? ser_gyrokinetic_surfy_kernels_constcoeff : + ser_gyrokinetic_surfy_kernels_varcoeff; + surfz_kernels = diffusion->const_coeff ? ser_gyrokinetic_surfz_kernels_constcoeff : + ser_gyrokinetic_surfz_kernels_varcoeff; + boundary_surfx_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_surfx_kernels_constcoeff : + ser_gyrokinetic_boundary_surfx_kernels_varcoeff; + boundary_surfy_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_surfy_kernels_constcoeff : + ser_gyrokinetic_boundary_surfy_kernels_varcoeff; + boundary_surfz_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_surfz_kernels_constcoeff : + ser_gyrokinetic_boundary_surfz_kernels_varcoeff; + boundary_diagx_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_diagx_kernels_constcoeff : + ser_gyrokinetic_boundary_diagx_kernels_varcoeff; + boundary_diagy_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_diagy_kernels_constcoeff : + ser_gyrokinetic_boundary_diagy_kernels_varcoeff; + boundary_diagz_kernels = diffusion->const_coeff ? + ser_gyrokinetic_boundary_diagz_kernels_constcoeff : + ser_gyrokinetic_boundary_diagz_kernels_varcoeff; + break; + + default: + assert(false); + break; } diffusion->eqn.num_equations = 1; @@ -72,29 +94,41 @@ dg_diffusion_gyrokinetic_set_cu_dev_ptrs(struct dg_diffusion_gyrokinetic *diffus diffusion->eqn.vol_term = CKVOL(vol_kernels, cdim, diff_order, poly_order, diffdirs_linidx); diffusion->surf[0] = CKSURF(surfx_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>1) + if (cdim > 1) { diffusion->surf[1] = CKSURF(surfy_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { diffusion->surf[2] = CKSURF(surfz_kernels, diff_order, cdim, vdim, poly_order); + } diffusion->boundary_surf[0] = CKSURF(boundary_surfx_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>1) - diffusion->boundary_surf[1] = CKSURF(boundary_surfy_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>2) - diffusion->boundary_surf[2] = CKSURF(boundary_surfz_kernels, diff_order, cdim, vdim, poly_order); + if (cdim > 1) { + diffusion->boundary_surf[1] = + CKSURF(boundary_surfy_kernels, diff_order, cdim, vdim, poly_order); + } + if (cdim > 2) { + diffusion->boundary_surf[2] = + CKSURF(boundary_surfz_kernels, diff_order, cdim, vdim, poly_order); + } diffusion->boundary_diag[0] = CKSURF(boundary_diagx_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>1) - diffusion->boundary_diag[1] = CKSURF(boundary_diagy_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>2) - diffusion->boundary_diag[2] = CKSURF(boundary_diagz_kernels, diff_order, cdim, vdim, poly_order); + if (cdim > 1) { + diffusion->boundary_diag[1] = + CKSURF(boundary_diagy_kernels, diff_order, cdim, vdim, poly_order); + } + if (cdim > 2) { + diffusion->boundary_diag[2] = + CKSURF(boundary_diagz_kernels, diff_order, cdim, vdim, poly_order); + } } -struct gkyl_dg_eqn* -gkyl_dg_diffusion_gyrokinetic_cu_dev_new(const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, - bool is_diff_const, const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range) +struct gkyl_dg_eqn *gkyl_dg_diffusion_gyrokinetic_cu_dev_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, + const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range +) { - struct dg_diffusion_gyrokinetic* diffusion = (struct dg_diffusion_gyrokinetic*) gkyl_malloc(sizeof(struct dg_diffusion_gyrokinetic)); + struct dg_diffusion_gyrokinetic *diffusion = + (struct dg_diffusion_gyrokinetic *)gkyl_malloc(sizeof(struct dg_diffusion_gyrokinetic)); int cdim = cbasis->ndim; int vdim = basis->ndim - cdim; @@ -102,7 +136,9 @@ gkyl_dg_diffusion_gyrokinetic_cu_dev_new(const struct gkyl_basis *basis, const s diffusion->const_coeff = is_diff_const; diffusion->num_basis = basis->num_basis; - for (int d=0; ddiff_in_dir[d] = diff_in_dir[d]; + for (int d = 0; d < cdim; d++) { + diffusion->diff_in_dir[d] = diff_in_dir[d]; + } int dirs_linidx = diffdirs_linidx(diff_in_dir, cdim); @@ -113,9 +149,14 @@ gkyl_dg_diffusion_gyrokinetic_cu_dev_new(const struct gkyl_basis *basis, const s diffusion->eqn.ref_count = gkyl_ref_count_init(gkyl_dg_diffusion_gyrokinetic_free); // copy the host struct to device struct - struct dg_diffusion_gyrokinetic* diffusion_cu = (struct dg_diffusion_gyrokinetic*) gkyl_cu_malloc(sizeof(struct dg_diffusion_gyrokinetic)); - gkyl_cu_memcpy(diffusion_cu, diffusion, sizeof(struct dg_diffusion_gyrokinetic), GKYL_CU_MEMCPY_H2D); - dg_diffusion_gyrokinetic_set_cu_dev_ptrs<<<1,1>>>(diffusion_cu, cbasis->b_type, cdim, vdim, poly_order, diff_order, dirs_linidx); + struct dg_diffusion_gyrokinetic *diffusion_cu = + (struct dg_diffusion_gyrokinetic *)gkyl_cu_malloc(sizeof(struct dg_diffusion_gyrokinetic)); + gkyl_cu_memcpy( + diffusion_cu, diffusion, sizeof(struct dg_diffusion_gyrokinetic), GKYL_CU_MEMCPY_H2D + ); + dg_diffusion_gyrokinetic_set_cu_dev_ptrs<<<1, 1> > >( + diffusion_cu, cbasis->b_type, cdim, vdim, poly_order, diff_order, dirs_linidx + ); // set parent on_dev pointer diffusion->eqn.on_dev = &diffusion_cu->eqn; diff --git a/gyrokinetic/zero/dg_gyrokinetic.c b/gyrokinetic/zero/dg_gyrokinetic.c index e0429735d7..7bd2af8cc8 100644 --- a/gyrokinetic/zero/dg_gyrokinetic.c +++ b/gyrokinetic/zero/dg_gyrokinetic.c @@ -10,8 +10,7 @@ #include #include -void -gkyl_gyrokinetic_free(const struct gkyl_ref_count *ref) +void gkyl_gyrokinetic_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); struct dg_gyrokinetic *gyrokinetic = container_of(base, struct dg_gyrokinetic, eqn); @@ -27,8 +26,9 @@ gkyl_gyrokinetic_free(const struct gkyl_ref_count *ref) gkyl_free(gyrokinetic); } -void -gkyl_gyrokinetic_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_auxfields auxin) +void gkyl_gyrokinetic_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_dg_eqn_is_cu_dev(eqn)) { @@ -44,21 +44,24 @@ gkyl_gyrokinetic_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyr gyrokinetic->auxfields.apardot = auxin.apardot; } -struct gkyl_dg_eqn* -gkyl_dg_gyrokinetic_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const double charge, const double mass, enum gkyl_gk_collisionless_type collless_type, - const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_gyrokinetic_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const double charge, + const double mass, enum gkyl_gk_collisionless_type collless_type, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) - return gkyl_dg_gyrokinetic_cu_dev_new(cbasis, pbasis, conf_range, phase_range, - charge, mass, collless_type, gk_geom, vel_map); + if (use_gpu) { + return gkyl_dg_gyrokinetic_cu_dev_new( + cbasis, pbasis, conf_range, phase_range, charge, mass, collless_type, gk_geom, vel_map + ); + } #endif struct dg_gyrokinetic *gyrokinetic = gkyl_malloc(sizeof(struct dg_gyrokinetic)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; gyrokinetic->cdim = cdim; @@ -73,60 +76,67 @@ gkyl_dg_gyrokinetic_new(const struct gkyl_basis *cbasis, const struct gkyl_basis gyrokinetic->eqn.boundary_diag_term = boundary_diag; const gkyl_dg_gyrokinetic_vol_kern_list *vol_kernels, *vol_no_by_kernels; - const gkyl_dg_gyrokinetic_surf_kern_list *surf_x_kernels; - const gkyl_dg_gyrokinetic_surf_kern_list *surf_y_kernels; - const gkyl_dg_gyrokinetic_surf_kern_list *surf_z_kernels; - const gkyl_dg_gyrokinetic_surf_kern_list *surf_vpar_kernels; - const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_x_kernels; - const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_y_kernels; - const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_z_kernels; - const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_vpar_kernels; + const gkyl_dg_gyrokinetic_surf_kern_list *surf_x_kernels; + const gkyl_dg_gyrokinetic_surf_kern_list *surf_y_kernels; + const gkyl_dg_gyrokinetic_surf_kern_list *surf_z_kernels; + const gkyl_dg_gyrokinetic_surf_kern_list *surf_vpar_kernels; + const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_x_kernels; + const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_y_kernels; + const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_z_kernels; + const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_vpar_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - surf_z_kernels = ser_surf_z_kernels; - surf_vpar_kernels = ser_surf_vpar_kernels; - boundary_surf_x_kernels = ser_boundary_surf_x_kernels; - boundary_surf_y_kernels = ser_boundary_surf_y_kernels; - boundary_surf_z_kernels = ser_boundary_surf_z_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; - - vol_no_by_kernels = ser_no_by_vol_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + surf_z_kernels = ser_surf_z_kernels; + surf_vpar_kernels = ser_surf_vpar_kernels; + boundary_surf_x_kernels = ser_boundary_surf_x_kernels; + boundary_surf_y_kernels = ser_boundary_surf_y_kernels; + boundary_surf_z_kernels = ser_boundary_surf_z_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; + + vol_no_by_kernels = ser_no_by_vol_kernels; + break; + + default: + assert(false); + break; } if (collless_type == GKYL_GK_COLLISIONLESS_ES) { - gyrokinetic->eqn.vol_term = CK(vol_kernels,cdim,vdim,poly_order); - } - else if (collless_type == GKYL_GK_COLLISIONLESS_ES_NO_BY) { - gyrokinetic->eqn.vol_term = CK(vol_no_by_kernels,cdim,vdim,poly_order); + gyrokinetic->eqn.vol_term = CK(vol_kernels, cdim, vdim, poly_order); + } else if (collless_type == GKYL_GK_COLLISIONLESS_ES_NO_BY) { + gyrokinetic->eqn.vol_term = CK(vol_no_by_kernels, cdim, vdim, poly_order); } - gyrokinetic->surf[0] = CK(surf_x_kernels,cdim,vdim,poly_order); - if (cdim>1) - gyrokinetic->surf[1] = CK(surf_y_kernels,cdim,vdim,poly_order); - if (cdim>2) - gyrokinetic->surf[2] = CK(surf_z_kernels,cdim,vdim,poly_order); - gyrokinetic->surf[cdim] = CK(surf_vpar_kernels,cdim,vdim,poly_order); + gyrokinetic->surf[0] = CK(surf_x_kernels, cdim, vdim, poly_order); + if (cdim > 1) { + gyrokinetic->surf[1] = CK(surf_y_kernels, cdim, vdim, poly_order); + } + if (cdim > 2) { + gyrokinetic->surf[2] = CK(surf_z_kernels, cdim, vdim, poly_order); + } + gyrokinetic->surf[cdim] = CK(surf_vpar_kernels, cdim, vdim, poly_order); - gyrokinetic->boundary_surf[0] = CK(boundary_surf_x_kernels,cdim,vdim,poly_order); - if (cdim>1) - gyrokinetic->boundary_surf[1] = CK(boundary_surf_y_kernels,cdim,vdim,poly_order); - if (cdim>2) - gyrokinetic->boundary_surf[2] = CK(boundary_surf_z_kernels,cdim,vdim,poly_order); - gyrokinetic->boundary_surf[cdim] = CK(boundary_surf_vpar_kernels,cdim,vdim,poly_order); + gyrokinetic->boundary_surf[0] = CK(boundary_surf_x_kernels, cdim, vdim, poly_order); + if (cdim > 1) { + gyrokinetic->boundary_surf[1] = CK(boundary_surf_y_kernels, cdim, vdim, poly_order); + } + if (cdim > 2) { + gyrokinetic->boundary_surf[2] = CK(boundary_surf_z_kernels, cdim, vdim, poly_order); + } + gyrokinetic->boundary_surf[cdim] = CK(boundary_surf_vpar_kernels, cdim, vdim, poly_order); // Ensure non-NULL pointers. - for (int i=0; isurf[i]); + for (int i = 0; i < cdim; ++i) { + assert(gyrokinetic->surf[i]); + } assert(gyrokinetic->surf[cdim]); - for (int i=0; iboundary_surf[i]); + for (int i = 0; i < cdim + 1; ++i) { + assert(gyrokinetic->boundary_surf[i]); + } gyrokinetic->conf_range = *conf_range; gyrokinetic->phase_range = *phase_range; diff --git a/gyrokinetic/zero/dg_gyrokinetic_cu.cu b/gyrokinetic/zero/dg_gyrokinetic_cu.cu index 09f69e68fe..2e08f5175d 100644 --- a/gyrokinetic/zero/dg_gyrokinetic_cu.cu +++ b/gyrokinetic/zero/dg_gyrokinetic_cu.cu @@ -4,7 +4,7 @@ extern "C" { #include #include -#include +#include #include } @@ -13,10 +13,10 @@ extern "C" { // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_gyrokinetic_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array *flux_surf, - const struct gkyl_array *phi, const struct gkyl_array *apar, const struct gkyl_array *apardot) +__global__ static void gkyl_gyrokinetic_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *flux_surf, const struct gkyl_array *phi, + const struct gkyl_array *apar, const struct gkyl_array *apardot +) { struct dg_gyrokinetic *gyrokinetic = container_of(eqn, struct dg_gyrokinetic, eqn); gyrokinetic->auxfields.flux_surf = flux_surf; @@ -26,92 +26,97 @@ gkyl_gyrokinetic_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_gyrokinetic_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_auxfields auxin) +void gkyl_gyrokinetic_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_auxfields auxin +) { - gkyl_gyrokinetic_set_auxfields_cu_kernel<<<1,1>>>(eqn, - auxin.flux_surf->on_dev, - auxin.phi->on_dev, auxin.apar->on_dev, auxin.apardot->on_dev); + gkyl_gyrokinetic_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.flux_surf->on_dev, auxin.phi->on_dev, auxin.apar->on_dev, auxin.apardot->on_dev + ); } // CUDA kernel to set device pointers to range object and gyrokinetic kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_gyrokinetic_set_cu_dev_ptrs(struct dg_gyrokinetic *gyrokinetic, enum gkyl_basis_type b_type, - int cv_index, int cdim, int vdim, int poly_order, enum gkyl_gk_collisionless_type collless_type) +__global__ static void dg_gyrokinetic_set_cu_dev_ptrs( + struct dg_gyrokinetic *gyrokinetic, enum gkyl_basis_type b_type, int cv_index, int cdim, int vdim, + int poly_order, enum gkyl_gk_collisionless_type collless_type +) { - gyrokinetic->auxfields.flux_surf = 0; - gyrokinetic->auxfields.phi = 0; - gyrokinetic->auxfields.apar = 0; - gyrokinetic->auxfields.apardot= 0; + gyrokinetic->auxfields.flux_surf = 0; + gyrokinetic->auxfields.phi = 0; + gyrokinetic->auxfields.apar = 0; + gyrokinetic->auxfields.apardot = 0; gyrokinetic->eqn.surf_term = surf; gyrokinetic->eqn.boundary_surf_term = boundary_surf; gyrokinetic->eqn.boundary_diag_term = boundary_diag; const gkyl_dg_gyrokinetic_vol_kern_list *vol_kernels, *vol_no_by_kernels; - const gkyl_dg_gyrokinetic_surf_kern_list *surf_x_kernels; - const gkyl_dg_gyrokinetic_surf_kern_list *surf_y_kernels; - const gkyl_dg_gyrokinetic_surf_kern_list *surf_z_kernels; - const gkyl_dg_gyrokinetic_surf_kern_list *surf_vpar_kernels; - const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_x_kernels; - const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_y_kernels; - const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_z_kernels; - const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_vpar_kernels; - + const gkyl_dg_gyrokinetic_surf_kern_list *surf_x_kernels; + const gkyl_dg_gyrokinetic_surf_kern_list *surf_y_kernels; + const gkyl_dg_gyrokinetic_surf_kern_list *surf_z_kernels; + const gkyl_dg_gyrokinetic_surf_kern_list *surf_vpar_kernels; + const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_x_kernels; + const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_y_kernels; + const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_z_kernels; + const gkyl_dg_gyrokinetic_boundary_surf_kern_list *boundary_surf_vpar_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - surf_z_kernels = ser_surf_z_kernels; - surf_vpar_kernels = ser_surf_vpar_kernels; - boundary_surf_x_kernels = ser_boundary_surf_x_kernels; - boundary_surf_y_kernels = ser_boundary_surf_y_kernels; - boundary_surf_z_kernels = ser_boundary_surf_z_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; - - vol_no_by_kernels = ser_no_by_vol_kernels; - - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + surf_z_kernels = ser_surf_z_kernels; + surf_vpar_kernels = ser_surf_vpar_kernels; + boundary_surf_x_kernels = ser_boundary_surf_x_kernels; + boundary_surf_y_kernels = ser_boundary_surf_y_kernels; + boundary_surf_z_kernels = ser_boundary_surf_z_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; + + vol_no_by_kernels = ser_no_by_vol_kernels; + + break; + + default: + assert(false); + break; + } if (collless_type == GKYL_GK_COLLISIONLESS_ES) { gyrokinetic->eqn.vol_term = vol_kernels[cv_index].kernels[poly_order]; - } - else if (collless_type == GKYL_GK_COLLISIONLESS_ES_NO_BY) { + } else if (collless_type == GKYL_GK_COLLISIONLESS_ES_NO_BY) { gyrokinetic->eqn.vol_term = vol_no_by_kernels[cv_index].kernels[poly_order]; } gyrokinetic->surf[0] = surf_x_kernels[cv_index].kernels[poly_order]; - if (cdim>1) + if (cdim > 1) { gyrokinetic->surf[1] = surf_y_kernels[cv_index].kernels[poly_order]; - if (cdim>2) + } + if (cdim > 2) { gyrokinetic->surf[2] = surf_z_kernels[cv_index].kernels[poly_order]; + } gyrokinetic->surf[cdim] = surf_vpar_kernels[cv_index].kernels[poly_order]; gyrokinetic->boundary_surf[0] = boundary_surf_x_kernels[cv_index].kernels[poly_order]; - if (cdim>1) + if (cdim > 1) { gyrokinetic->boundary_surf[1] = boundary_surf_y_kernels[cv_index].kernels[poly_order]; - if (cdim>2) + } + if (cdim > 2) { gyrokinetic->boundary_surf[2] = boundary_surf_z_kernels[cv_index].kernels[poly_order]; + } gyrokinetic->boundary_surf[cdim] = boundary_surf_vpar_kernels[cv_index].kernels[poly_order]; - } -struct gkyl_dg_eqn* -gkyl_dg_gyrokinetic_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const double charge, const double mass, enum gkyl_gk_collisionless_type collless_type, - const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map) +struct gkyl_dg_eqn *gkyl_dg_gyrokinetic_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const double charge, + const double mass, enum gkyl_gk_collisionless_type collless_type, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map +) { - struct dg_gyrokinetic *gyrokinetic = (struct dg_gyrokinetic*) gkyl_malloc(sizeof(*gyrokinetic)); + struct dg_gyrokinetic *gyrokinetic = (struct dg_gyrokinetic *)gkyl_malloc(sizeof(*gyrokinetic)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; gyrokinetic->cdim = cdim; @@ -125,7 +130,7 @@ gkyl_dg_gyrokinetic_cu_dev_new(const struct gkyl_basis *cbasis, const struct gky // Acquire pointers to on_dev objects so memcpy below copies those too. struct gk_geometry *geom_ho = gkyl_gk_geometry_acquire(gk_geom); struct gkyl_velocity_map *vel_map_ho = gkyl_velocity_map_acquire(vel_map); - + gyrokinetic->gk_geom = geom_ho->on_dev; gyrokinetic->vel_map = vel_map_ho->on_dev; @@ -137,17 +142,19 @@ gkyl_dg_gyrokinetic_cu_dev_new(const struct gkyl_basis *cbasis, const struct gky gyrokinetic->eqn.ref_count = gkyl_ref_count_init(gkyl_gyrokinetic_free); // copy the host struct to device struct - struct dg_gyrokinetic *gyrokinetic_cu = (struct dg_gyrokinetic*) gkyl_cu_malloc(sizeof(struct dg_gyrokinetic)); + struct dg_gyrokinetic *gyrokinetic_cu = + (struct dg_gyrokinetic *)gkyl_cu_malloc(sizeof(struct dg_gyrokinetic)); gkyl_cu_memcpy(gyrokinetic_cu, gyrokinetic, sizeof(struct dg_gyrokinetic), GKYL_CU_MEMCPY_H2D); - dg_gyrokinetic_set_cu_dev_ptrs<<<1,1>>>(gyrokinetic_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], - cdim, vdim, poly_order, collless_type); + dg_gyrokinetic_set_cu_dev_ptrs<<<1, 1> > >( + gyrokinetic_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order, collless_type + ); // set parent on_dev pointer gyrokinetic->eqn.on_dev = &gyrokinetic_cu->eqn; - + // Updater should store host pointers. - gyrokinetic->gk_geom = geom_ho; + gyrokinetic->gk_geom = geom_ho; gyrokinetic->vel_map = vel_map_ho; return &gyrokinetic->eqn; diff --git a/gyrokinetic/zero/dg_gyrokinetic_passive.c b/gyrokinetic/zero/dg_gyrokinetic_passive.c index 4e63001d8f..8fbe62df0a 100644 --- a/gyrokinetic/zero/dg_gyrokinetic_passive.c +++ b/gyrokinetic/zero/dg_gyrokinetic_passive.c @@ -10,8 +10,7 @@ #include #include -void -gkyl_gyrokinetic_passive_free(const struct gkyl_ref_count *ref) +void gkyl_gyrokinetic_passive_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); struct dg_gyrokinetic_passive *gkp = container_of(base, struct dg_gyrokinetic_passive, eqn); @@ -20,16 +19,17 @@ gkyl_gyrokinetic_passive_free(const struct gkyl_ref_count *ref) if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object - struct dg_gyrokinetic_passive *gkp_cu = container_of(base->on_dev, struct dg_gyrokinetic_passive, eqn); + struct dg_gyrokinetic_passive *gkp_cu = + container_of(base->on_dev, struct dg_gyrokinetic_passive, eqn); gkyl_cu_free(gkp_cu); } gkyl_free(gkp); } -void -gkyl_gyrokinetic_passive_set_auxfields(const struct gkyl_dg_eqn *eqn, - struct gkyl_dg_gyrokinetic_passive_auxfields auxin) +void gkyl_gyrokinetic_passive_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_passive_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_dg_eqn_is_cu_dev(eqn)) { @@ -39,20 +39,22 @@ gkyl_gyrokinetic_passive_set_auxfields(const struct gkyl_dg_eqn *eqn, #endif struct dg_gyrokinetic_passive *gkp = container_of(eqn, struct dg_gyrokinetic_passive, eqn); gkp->auxfields.flux_surf = auxin.flux_surf; - gkp->auxfields.speeds = auxin.speeds; + gkp->auxfields.speeds = auxin.speeds; } -struct gkyl_dg_eqn* -gkyl_dg_gyrokinetic_passive_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const double charge, const double mass, - const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, - bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_gyrokinetic_passive_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const double charge, + const double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, + bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) - return gkyl_dg_gyrokinetic_passive_cu_dev_new(cbasis, pbasis, conf_range, phase_range, - charge, mass, gk_geom, vel_map); + if (use_gpu) { + return gkyl_dg_gyrokinetic_passive_cu_dev_new( + cbasis, pbasis, conf_range, phase_range, charge, mass, gk_geom, vel_map + ); + } #endif struct dg_gyrokinetic_passive *gkp = gkyl_malloc(sizeof(struct dg_gyrokinetic_passive)); @@ -66,10 +68,10 @@ gkyl_dg_gyrokinetic_passive_new(const struct gkyl_basis *cbasis, const struct gk gkp->pdim = pdim; gkp->charge = charge; - gkp->mass = mass; + gkp->mass = mass; - gkp->eqn.num_equations = 1; - gkp->eqn.surf_term = surf_passive; + gkp->eqn.num_equations = 1; + gkp->eqn.surf_term = surf_passive; gkp->eqn.boundary_surf_term = boundary_surf_passive; gkp->eqn.boundary_diag_term = boundary_diag_passive; @@ -78,37 +80,37 @@ gkyl_dg_gyrokinetic_passive_new(const struct gkyl_basis *cbasis, const struct gk // Conf-space surface and boundary-surface kernels. if (cdim >= 1) { - gkp->surf[0] = CK_PASSIVE(ser_passive_surf_x_kernels, cdim, vdim, poly_order); + gkp->surf[0] = CK_PASSIVE(ser_passive_surf_x_kernels, cdim, vdim, poly_order); gkp->boundary_surf[0] = CK_PASSIVE(ser_passive_boundary_surf_x_kernels, cdim, vdim, poly_order); } if (cdim >= 2) { - gkp->surf[1] = CK_PASSIVE(ser_passive_surf_y_kernels, cdim, vdim, poly_order); + gkp->surf[1] = CK_PASSIVE(ser_passive_surf_y_kernels, cdim, vdim, poly_order); gkp->boundary_surf[1] = CK_PASSIVE(ser_passive_boundary_surf_y_kernels, cdim, vdim, poly_order); } if (cdim >= 3) { - gkp->surf[2] = CK_PASSIVE(ser_passive_surf_z_kernels, cdim, vdim, poly_order); + gkp->surf[2] = CK_PASSIVE(ser_passive_surf_z_kernels, cdim, vdim, poly_order); gkp->boundary_surf[2] = CK_PASSIVE(ser_passive_boundary_surf_z_kernels, cdim, vdim, poly_order); } // Ensure non-NULL pointers. - for (int i=0; isurf[i]); assert(gkp->boundary_surf[i]); } - gkp->conf_range = *conf_range; + gkp->conf_range = *conf_range; gkp->phase_range = *phase_range; - gkp->gk_geom = gkyl_gk_geometry_acquire(gk_geom); - gkp->vel_map = gkyl_velocity_map_acquire(vel_map); + gkp->gk_geom = gkyl_gk_geometry_acquire(gk_geom); + gkp->vel_map = gkyl_velocity_map_acquire(vel_map); gkp->auxfields.flux_surf = 0; - gkp->auxfields.speeds = 0; + gkp->auxfields.speeds = 0; gkp->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(gkp->eqn.flags); gkp->eqn.ref_count = gkyl_ref_count_init(gkyl_gyrokinetic_passive_free); - gkp->eqn.on_dev = &gkp->eqn; + gkp->eqn.on_dev = &gkp->eqn; return &gkp->eqn; } diff --git a/gyrokinetic/zero/dg_gyrokinetic_passive_cu.cu b/gyrokinetic/zero/dg_gyrokinetic_passive_cu.cu index 8260b272d0..48fe137241 100644 --- a/gyrokinetic/zero/dg_gyrokinetic_passive_cu.cu +++ b/gyrokinetic/zero/dg_gyrokinetic_passive_cu.cu @@ -13,82 +13,84 @@ extern "C" { // CUDA kernel to set pointer to auxiliary fields. // Required because the equation object lives on the device and its members // cannot be modified without a __global__ kernel. -__global__ static void -gkyl_gyrokinetic_passive_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array *flux_surf, const struct gkyl_array *speeds) +__global__ static void gkyl_gyrokinetic_passive_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *flux_surf, const struct gkyl_array *speeds +) { struct dg_gyrokinetic_passive *gkp = container_of(eqn, struct dg_gyrokinetic_passive, eqn); gkp->auxfields.flux_surf = flux_surf; - gkp->auxfields.speeds = speeds; + gkp->auxfields.speeds = speeds; } // Host-side wrapper for gkyl_gyrokinetic_passive_set_auxfields_cu_kernel. -void -gkyl_gyrokinetic_passive_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, - struct gkyl_dg_gyrokinetic_passive_auxfields auxin) +void gkyl_gyrokinetic_passive_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_passive_auxfields auxin +) { - gkyl_gyrokinetic_passive_set_auxfields_cu_kernel<<<1,1>>>(eqn, - auxin.flux_surf->on_dev, auxin.speeds->on_dev); + gkyl_gyrokinetic_passive_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.flux_surf->on_dev, auxin.speeds->on_dev + ); } // CUDA kernel to set device function pointers and zero auxfields. // Doing function-pointer work here avoids troublesome cudaMemcpyFromSymbol. -__global__ static void -dg_gyrokinetic_passive_set_cu_dev_ptrs(struct dg_gyrokinetic_passive *gkp, - enum gkyl_basis_type b_type, int cv_index, int cdim, int vdim, int poly_order) +__global__ static void dg_gyrokinetic_passive_set_cu_dev_ptrs( + struct dg_gyrokinetic_passive *gkp, enum gkyl_basis_type b_type, int cv_index, int cdim, int vdim, + int poly_order +) { gkp->auxfields.flux_surf = 0; - gkp->auxfields.speeds = 0; + gkp->auxfields.speeds = 0; - gkp->eqn.surf_term = surf_passive; + gkp->eqn.surf_term = surf_passive; gkp->eqn.boundary_surf_term = boundary_surf_passive; gkp->eqn.boundary_diag_term = boundary_diag_passive; - const gkyl_dg_gyrokinetic_passive_vol_kern_list *vol_kernels; - const gkyl_dg_gyrokinetic_passive_surf_kern_list *surf_x_kernels; - const gkyl_dg_gyrokinetic_passive_surf_kern_list *surf_y_kernels; - const gkyl_dg_gyrokinetic_passive_surf_kern_list *surf_z_kernels; + const gkyl_dg_gyrokinetic_passive_vol_kern_list *vol_kernels; + const gkyl_dg_gyrokinetic_passive_surf_kern_list *surf_x_kernels; + const gkyl_dg_gyrokinetic_passive_surf_kern_list *surf_y_kernels; + const gkyl_dg_gyrokinetic_passive_surf_kern_list *surf_z_kernels; const gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list *boundary_surf_x_kernels; const gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list *boundary_surf_y_kernels; const gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list *boundary_surf_z_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_passive_vol_kernels; - surf_x_kernels = ser_passive_surf_x_kernels; - surf_y_kernels = ser_passive_surf_y_kernels; - surf_z_kernels = ser_passive_surf_z_kernels; - boundary_surf_x_kernels = ser_passive_boundary_surf_x_kernels; - boundary_surf_y_kernels = ser_passive_boundary_surf_y_kernels; - boundary_surf_z_kernels = ser_passive_boundary_surf_z_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_passive_vol_kernels; + surf_x_kernels = ser_passive_surf_x_kernels; + surf_y_kernels = ser_passive_surf_y_kernels; + surf_z_kernels = ser_passive_surf_z_kernels; + boundary_surf_x_kernels = ser_passive_boundary_surf_x_kernels; + boundary_surf_y_kernels = ser_passive_boundary_surf_y_kernels; + boundary_surf_z_kernels = ser_passive_boundary_surf_z_kernels; + break; + + default: + assert(false); + break; } - gkp->eqn.vol_term = vol_kernels[cv_index].kernels[poly_order-1]; + gkp->eqn.vol_term = vol_kernels[cv_index].kernels[poly_order - 1]; - gkp->surf[0] = surf_x_kernels[cv_index].kernels[poly_order-1]; - gkp->boundary_surf[0] = boundary_surf_x_kernels[cv_index].kernels[poly_order-1]; + gkp->surf[0] = surf_x_kernels[cv_index].kernels[poly_order - 1]; + gkp->boundary_surf[0] = boundary_surf_x_kernels[cv_index].kernels[poly_order - 1]; if (cdim > 1) { - gkp->surf[1] = surf_y_kernels[cv_index].kernels[poly_order-1]; - gkp->boundary_surf[1] = boundary_surf_y_kernels[cv_index].kernels[poly_order-1]; + gkp->surf[1] = surf_y_kernels[cv_index].kernels[poly_order - 1]; + gkp->boundary_surf[1] = boundary_surf_y_kernels[cv_index].kernels[poly_order - 1]; } if (cdim > 2) { - gkp->surf[2] = surf_z_kernels[cv_index].kernels[poly_order-1]; - gkp->boundary_surf[2] = boundary_surf_z_kernels[cv_index].kernels[poly_order-1]; + gkp->surf[2] = surf_z_kernels[cv_index].kernels[poly_order - 1]; + gkp->boundary_surf[2] = boundary_surf_z_kernels[cv_index].kernels[poly_order - 1]; } } -struct gkyl_dg_eqn* -gkyl_dg_gyrokinetic_passive_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const double charge, const double mass, - const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map) +struct gkyl_dg_eqn *gkyl_dg_gyrokinetic_passive_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const double charge, + const double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map +) { - struct dg_gyrokinetic_passive *gkp = (struct dg_gyrokinetic_passive*) gkyl_malloc(sizeof(*gkp)); + struct dg_gyrokinetic_passive *gkp = (struct dg_gyrokinetic_passive *)gkyl_malloc(sizeof(*gkp)); int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; @@ -97,31 +99,32 @@ gkyl_dg_gyrokinetic_passive_cu_dev_new(const struct gkyl_basis *cbasis, const st gkp->pdim = pdim; gkp->charge = charge; - gkp->mass = mass; + gkp->mass = mass; gkp->eqn.num_equations = 1; // Acquire on_dev pointers so the memcpy below copies device references. - struct gk_geometry *geom_ho = gkyl_gk_geometry_acquire(gk_geom); + struct gk_geometry *geom_ho = gkyl_gk_geometry_acquire(gk_geom); struct gkyl_velocity_map *vel_map_ho = gkyl_velocity_map_acquire(vel_map); - gkp->gk_geom = geom_ho->on_dev; - gkp->vel_map = vel_map_ho->on_dev; + gkp->gk_geom = geom_ho->on_dev; + gkp->vel_map = vel_map_ho->on_dev; - gkp->conf_range = *conf_range; + gkp->conf_range = *conf_range; gkp->phase_range = *phase_range; - gkp->eqn.flags = 0; + gkp->eqn.flags = 0; GKYL_SET_CU_ALLOC(gkp->eqn.flags); gkp->eqn.ref_count = gkyl_ref_count_init(gkyl_gyrokinetic_passive_free); // Copy host struct to device. struct dg_gyrokinetic_passive *gkp_cu = - (struct dg_gyrokinetic_passive*) gkyl_cu_malloc(sizeof(struct dg_gyrokinetic_passive)); + (struct dg_gyrokinetic_passive *)gkyl_cu_malloc(sizeof(struct dg_gyrokinetic_passive)); gkyl_cu_memcpy(gkp_cu, gkp, sizeof(struct dg_gyrokinetic_passive), GKYL_CU_MEMCPY_H2D); - dg_gyrokinetic_passive_set_cu_dev_ptrs<<<1,1>>>(gkp_cu, - cbasis->b_type, cv_index_gkp[cdim].vdim[vdim], cdim, vdim, poly_order); + dg_gyrokinetic_passive_set_cu_dev_ptrs<<<1, 1> > >( + gkp_cu, cbasis->b_type, cv_index_gkp[cdim].vdim[vdim], cdim, vdim, poly_order + ); // Set on_dev pointer to the device struct. gkp->eqn.on_dev = &gkp_cu->eqn; diff --git a/gyrokinetic/zero/dg_iz.c b/gyrokinetic/zero/dg_iz.c index c3f915e72d..24066ff6cd 100644 --- a/gyrokinetic/zero/dg_iz.c +++ b/gyrokinetic/zero/dg_iz.c @@ -16,8 +16,7 @@ #include #include -struct gkyl_dg_iz* -gkyl_dg_iz_new(struct gkyl_dg_iz_inp *inp, bool use_gpu) +struct gkyl_dg_iz *gkyl_dg_iz_new(struct gkyl_dg_iz_inp *inp, bool use_gpu) { gkyl_dg_iz *up = gkyl_malloc(sizeof(struct gkyl_dg_iz)); @@ -26,7 +25,7 @@ gkyl_dg_iz_new(struct gkyl_dg_iz_inp *inp, bool use_gpu) int charge_state = inp->charge_state; enum gkyl_ion_type type_ion = inp->type_ion; - + int cdim = inp->cbasis->ndim; int poly_order = inp->cbasis->poly_order; up->cdim = cdim; @@ -34,24 +33,30 @@ gkyl_dg_iz_new(struct gkyl_dg_iz_inp *inp, bool use_gpu) up->elem_charge = GKYL_ELEMENTARY_CHARGE; up->mass_elc = GKYL_ELECTRON_MASS; - + // Project ADAS data (H, He, Li) struct adas_field data; read_adas_field_iz(type_ion, &data); - - long sz = data.NT*data.NN; + + long sz = data.NT * data.NN; double minmax[2]; - if (data.logT == NULL) fprintf(stderr, "Unable to load ADAS 'logT_.npy' file. "); - if (data.logN == NULL) fprintf(stderr, "Unable to load ADAS 'logN_.npy' file. "); - if (data.logData == NULL) fprintf(stderr, "Unable to load ADAS 'ioniz_.npy' file. "); + if (data.logT == NULL) { + fprintf(stderr, "Unable to load ADAS 'logT_.npy' file. "); + } + if (data.logN == NULL) { + fprintf(stderr, "Unable to load ADAS 'logN_.npy' file. "); + } + if (data.logData == NULL) { + fprintf(stderr, "Unable to load ADAS 'ioniz_.npy' file. "); + } minmax_from_numpy(data.logT, data.NT, minmax); fclose(data.logT); double logTmin = minmax[0], logTmax = minmax[1]; minmax_from_numpy(data.logN, data.NN, minmax); fclose(data.logN); - double logNmin = minmax[0]+6., logNmax = minmax[1]+6.; //adjust for 1/cm^3 to 1/m^3 conversion + double logNmin = minmax[0] + 6., logNmax = minmax[1] + 6.; //adjust for 1/cm^3 to 1/m^3 conversion struct gkyl_array *adas_nodal = gkyl_array_new(GKYL_DOUBLE, 1, sz); array_from_numpy(data.logData, sz, data.Zmax, charge_state, adas_nodal); @@ -63,36 +68,38 @@ gkyl_dg_iz_new(struct gkyl_dg_iz_inp *inp, bool use_gpu) } struct gkyl_range range_nodal; - gkyl_range_init_from_shape(&range_nodal, 2, (int[]) { data.NT, data.NN } ); + gkyl_range_init_from_shape(&range_nodal, 2, (int[]){data.NT, data.NN}); // Allocate grid and DG array. struct gkyl_rect_grid tn_grid; - gkyl_rect_grid_init(&tn_grid, 2, - (double[]) { logTmin, logNmin}, - (double []) { logTmax, logNmax}, - (int[]) { data.NT-1, data.NN-1 } + gkyl_rect_grid_init( + &tn_grid, 2, (double[]){logTmin, logNmin}, (double[]){logTmax, logNmax}, + (int[]){data.NT - 1, data.NN - 1} ); if (use_gpu) { // Allocate device basis if we are using GPUs. up->basis_on_dev = gkyl_cu_malloc(sizeof(struct gkyl_basis)); - } - else { + } else { up->basis_on_dev = &up->adas_basis; } gkyl_cart_modal_serendip(&up->adas_basis, 2, 1); - if (use_gpu) + if (use_gpu) { gkyl_cart_modal_serendip_cu_dev(up->basis_on_dev, 2, 1); + } - int ghost[GKYL_MAX_DIM] = { 1, 1}; + int ghost[GKYL_MAX_DIM] = {1, 1}; struct gkyl_range modal_range; struct gkyl_range modal_range_ext; gkyl_create_grid_ranges(&tn_grid, ghost, &modal_range_ext, &modal_range); - struct gkyl_array *adas_dg = gkyl_array_new(GKYL_DOUBLE, up->adas_basis.num_basis, modal_range_ext.volume); + struct gkyl_array *adas_dg = + gkyl_array_new(GKYL_DOUBLE, up->adas_basis.num_basis, modal_range_ext.volume); struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&up->adas_basis, &tn_grid, false); - gkyl_nodal_ops_n2m(n2m, &up->adas_basis, &tn_grid, &range_nodal, &modal_range, 1, adas_nodal, adas_dg, false); + gkyl_nodal_ops_n2m( + n2m, &up->adas_basis, &tn_grid, &range_nodal, &modal_range, 1, adas_nodal, adas_dg, false + ); gkyl_nodal_ops_release(n2m); // ADAS data pointers @@ -107,13 +114,15 @@ gkyl_dg_iz_new(struct gkyl_dg_iz_inp *inp, bool use_gpu) up->resM0 = tn_grid.cells[1]; up->adas_rng = modal_range; - if (use_gpu) - up->ioniz_data = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->adas_basis.num_basis, modal_range_ext.volume); - else + if (use_gpu) { + up->ioniz_data = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->adas_basis.num_basis, modal_range_ext.volume); + } else { up->ioniz_data = gkyl_array_new(GKYL_DOUBLE, up->adas_basis.num_basis, modal_range_ext.volume); + } gkyl_array_copy(up->ioniz_data, adas_dg); - + up->on_dev = up; // CPU eqn obj points to itself gkyl_array_release(adas_nodal); @@ -122,21 +131,22 @@ gkyl_dg_iz_new(struct gkyl_dg_iz_inp *inp, bool use_gpu) return up; } -void gkyl_dg_iz_coll(const struct gkyl_dg_iz *up, - const struct gkyl_array *prim_vars_elc, - struct gkyl_array *vtSq_iz1, struct gkyl_array *vtSq_iz2, - struct gkyl_array *coef_iz, struct gkyl_array *cflrate) +void gkyl_dg_iz_coll( + const struct gkyl_dg_iz *up, const struct gkyl_array *prim_vars_elc, struct gkyl_array *vtSq_iz1, + struct gkyl_array *vtSq_iz2, struct gkyl_array *coef_iz, struct gkyl_array *cflrate +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(coef_iz)) { - return gkyl_dg_iz_coll_cu(up, prim_vars_elc, - vtSq_iz1, vtSq_iz2, coef_iz, cflrate); - } + return gkyl_dg_iz_coll_cu(up, prim_vars_elc, vtSq_iz1, vtSq_iz2, coef_iz, cflrate); + } #endif struct gkyl_range_iter conf_iter, vel_iter; - int rem_dir[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dconf_rng->ndim; ++d) rem_dir[d] = 1; + int rem_dir[GKYL_MAX_DIM] = {0}; + for (int d = 0; d < up->conf_rng->ndim; ++d) { + rem_dir[d] = 1; + } gkyl_range_iter_init(&conf_iter, up->conf_rng); while (gkyl_range_iter_next(&conf_iter)) { long loc = gkyl_range_idx(up->conf_rng, conf_iter.idx); @@ -148,79 +158,77 @@ void gkyl_dg_iz_coll(const struct gkyl_dg_iz *up, double *coef_iz_d = gkyl_array_fetch(coef_iz, loc); //Find cell containing value of n,T - double cell_av_fac = pow(1/sqrt(2),up->cdim); - double m0_elc_av = prim_vars_elc_d[0]*cell_av_fac; - double temp_elc_av = prim_vars_elc_d[2*nc]*cell_av_fac*up->mass_elc/up->elem_charge; + double cell_av_fac = pow(1 / sqrt(2), up->cdim); + double m0_elc_av = prim_vars_elc_d[0] * cell_av_fac; + double temp_elc_av = prim_vars_elc_d[2 * nc] * cell_av_fac * up->mass_elc / up->elem_charge; double log_Te_av = log10(temp_elc_av); double log_m0_av = log10(m0_elc_av); int m0_idx, t_idx; double cell_vals_2d[2]; double cell_center; double temp_elc_2; - double temp_flr = 3.0; - + double temp_flr = 3.0; + if (log_Te_av < up->minLogTe) { - t_idx=1; + t_idx = 1; log_Te_av = up->minLogTe; - } - else if (log_Te_av > up->maxLogTe) { - t_idx=up->resTe; + } else if (log_Te_av > up->maxLogTe) { + t_idx = up->resTe; log_Te_av = up->maxLogTe; + } else { + t_idx = (log_Te_av - up->minLogTe) / (up->dlogTe) + 1; } - else t_idx = (log_Te_av - up->minLogTe)/(up->dlogTe)+1; - cell_center = (t_idx - 0.5)*up->dlogTe + up->minLogTe; - cell_vals_2d[0] = 2.0*(log_Te_av - cell_center)/up->dlogTe; // Te value on cell interval - + cell_center = (t_idx - 0.5) * up->dlogTe + up->minLogTe; + cell_vals_2d[0] = 2.0 * (log_Te_av - cell_center) / up->dlogTe; // Te value on cell interval + if (log_m0_av < up->minLogM0) { - m0_idx=1; + m0_idx = 1; log_m0_av = up->minLogM0; - } - else if (log_m0_av > up->maxLogM0) { - m0_idx=up->resM0; + } else if (log_m0_av > up->maxLogM0) { + m0_idx = up->resM0; log_m0_av = up->maxLogM0; + } else { + m0_idx = (log_m0_av - up->minLogM0) / (up->dlogM0) + 1; } - else m0_idx = (log_m0_av - up->minLogM0)/(up->dlogM0)+1; - cell_center = (m0_idx - 0.5)*up->dlogM0 + up->minLogM0; - cell_vals_2d[1] = 2.0*(log_m0_av - cell_center)/up->dlogM0; // M0 value on cell interval + cell_center = (m0_idx - 0.5) * up->dlogM0 + up->minLogM0; + cell_vals_2d[1] = 2.0 * (log_m0_av - cell_center) / up->dlogM0; // M0 value on cell interval if ((m0_elc_av <= 0.) || (temp_elc_av <= 0.)) { coef_iz_d[0] = 0.0; - } - else { - double *iz_dat_d = gkyl_array_fetch(up->ioniz_data, gkyl_range_idx(&up->adas_rng, (int[2]) {t_idx,m0_idx})); + } else { + double *iz_dat_d = + gkyl_array_fetch(up->ioniz_data, gkyl_range_idx(&up->adas_rng, (int[2]){t_idx, m0_idx})); double adas_eval = up->adas_basis.eval_expand(cell_vals_2d, iz_dat_d); - coef_iz_d[0] = pow(10.0,adas_eval)/cell_av_fac; + coef_iz_d[0] = pow(10.0, adas_eval) / cell_av_fac; if (up->type_self == GKYL_SELF_ELC) { // Calculate vtSq_iz at each cell for primary and secondary elc. - if ( 3./2.*temp_elc_av >= 2.*up->E) { + if (3. / 2. * temp_elc_av >= 2. * up->E) { // T_e2 = 1/3*sqrt(3./2.*T_e*E_iz - E_iz) - temp_elc_2 = 1.0/3.0*pow(up->E*(3./2.*temp_elc_av - up->E), 0.5); - vtSq_iz2_d[0] = temp_elc_2*up->elem_charge/(up->mass_elc*cell_av_fac); + temp_elc_2 = 1.0 / 3.0 * pow(up->E * (3. / 2. * temp_elc_av - up->E), 0.5); + vtSq_iz2_d[0] = temp_elc_2 * up->elem_charge / (up->mass_elc * cell_av_fac); // T_e1 = T_e - 2/3*E_iz - T_e2 - array_set2(nc, 2*nc, vtSq_iz1_d, 1.0, prim_vars_elc_d); - vtSq_iz1_d[0] = vtSq_iz1_d[0] - up->elem_charge*(2./3.*up->E + temp_elc_2)/(up->mass_elc*cell_av_fac); - } - else if (3./2.*temp_elc_av >= up->E) { + array_set2(nc, 2 * nc, vtSq_iz1_d, 1.0, prim_vars_elc_d); + vtSq_iz1_d[0] = vtSq_iz1_d[0] - up->elem_charge * (2. / 3. * up->E + temp_elc_2) / + (up->mass_elc * cell_av_fac); + } else if (3. / 2. * temp_elc_av >= up->E) { // T_e2 = 1/3*(3/2*T_e - E_iz) - temp_elc_2 = temp_elc_av/2.0 - up->E/3.0; - vtSq_iz2_d[0] = temp_elc_2*up->elem_charge/(up->mass_elc*cell_av_fac); + temp_elc_2 = temp_elc_av / 2.0 - up->E / 3.0; + vtSq_iz2_d[0] = temp_elc_2 * up->elem_charge / (up->mass_elc * cell_av_fac); // T_e1 = T_e - 2/3*E_iz - T_e2 - array_set2(nc, 2*nc, vtSq_iz1_d, 1.0, prim_vars_elc_d); - vtSq_iz1_d[0] = vtSq_iz1_d[0] - up->elem_charge*(2./3.*up->E + temp_elc_2)/(up->mass_elc*cell_av_fac); - } - else { - vtSq_iz2_d[0] = temp_flr*up->elem_charge/(up->mass_elc*cell_av_fac); - vtSq_iz1_d[0] = temp_flr*up->elem_charge/(up->mass_elc*cell_av_fac); + array_set2(nc, 2 * nc, vtSq_iz1_d, 1.0, prim_vars_elc_d); + vtSq_iz1_d[0] = vtSq_iz1_d[0] - up->elem_charge * (2. / 3. * up->E + temp_elc_2) / + (up->mass_elc * cell_av_fac); + } else { + vtSq_iz2_d[0] = temp_flr * up->elem_charge / (up->mass_elc * cell_av_fac); + vtSq_iz1_d[0] = temp_flr * up->elem_charge / (up->mass_elc * cell_av_fac); } } } } - } -void -gkyl_dg_iz_release(struct gkyl_dg_iz* up) +void gkyl_dg_iz_release(struct gkyl_dg_iz *up) { gkyl_array_release(up->ioniz_data); free(up); diff --git a/gyrokinetic/zero/dg_iz_cu.cu b/gyrokinetic/zero/dg_iz_cu.cu index fec12786f6..5da84232c1 100644 --- a/gyrokinetic/zero/dg_iz_cu.cu +++ b/gyrokinetic/zero/dg_iz_cu.cu @@ -13,110 +13,110 @@ extern "C" { #include } -__global__ static void -gkyl_iz_react_rate_cu_ker(const struct gkyl_dg_iz *up, - const struct gkyl_range conf_rng, const struct gkyl_range adas_rng, - const struct gkyl_basis *adas_basis, const struct gkyl_array* maxwellian_moms_elc, - struct gkyl_array *vtSq_iz1, struct gkyl_array *vtSq_iz2, struct gkyl_array* coef_iz, - struct gkyl_array* ioniz_data, enum gkyl_react_self_type type_self, - double mass_elc, double elem_charge, double E, - double maxLogTe, double minLogTe, double dlogTe, int resTe, - double maxLogM0, double minLogM0, double dlogM0, int resM0) +__global__ static void gkyl_iz_react_rate_cu_ker( + const struct gkyl_dg_iz *up, const struct gkyl_range conf_rng, const struct gkyl_range adas_rng, + const struct gkyl_basis *adas_basis, const struct gkyl_array *maxwellian_moms_elc, + struct gkyl_array *vtSq_iz1, struct gkyl_array *vtSq_iz2, struct gkyl_array *coef_iz, + struct gkyl_array *ioniz_data, enum gkyl_react_self_type type_self, double mass_elc, + double elem_charge, double E, double maxLogTe, double minLogTe, double dlogTe, int resTe, + double maxLogM0, double minLogM0, double dlogM0, int resM0 +) { int cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_rng.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_rng.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_rng, tid, cidx); long loc = gkyl_range_idx(&conf_rng, cidx); long nc = coef_iz->ncomp; int cdim = conf_rng.ndim; - const double *maxwellian_moms_elc_d = (const double*) gkyl_array_cfetch(maxwellian_moms_elc, loc); - double *vtSq_iz1_d = (double*) gkyl_array_fetch(vtSq_iz1, loc); - double *vtSq_iz2_d = (double*) gkyl_array_fetch(vtSq_iz2, loc); - double *coef_iz_d = (double*) gkyl_array_fetch(coef_iz, loc); - + const double *maxwellian_moms_elc_d = + (const double *)gkyl_array_cfetch(maxwellian_moms_elc, loc); + double *vtSq_iz1_d = (double *)gkyl_array_fetch(vtSq_iz1, loc); + double *vtSq_iz2_d = (double *)gkyl_array_fetch(vtSq_iz2, loc); + double *coef_iz_d = (double *)gkyl_array_fetch(coef_iz, loc); + //Find nearest neighbor for n, Te in ADAS interpolated data - double cell_av_fac = pow(1.0/sqrt(2.0),cdim); - double m0_elc_av = maxwellian_moms_elc_d[0]*cell_av_fac; - double temp_elc_av = maxwellian_moms_elc_d[2*nc]*cell_av_fac*mass_elc/elem_charge; + double cell_av_fac = pow(1.0 / sqrt(2.0), cdim); + double m0_elc_av = maxwellian_moms_elc_d[0] * cell_av_fac; + double temp_elc_av = maxwellian_moms_elc_d[2 * nc] * cell_av_fac * mass_elc / elem_charge; double log_Te_av = log10(temp_elc_av); double log_m0_av = log10(m0_elc_av); int m0_idx, t_idx; double cell_vals_2d[2]; double cell_center; double temp_elc_2; - double temp_flr = 3.0; - + double temp_flr = 3.0; + if (log_Te_av < minLogTe) { - t_idx=1; + t_idx = 1; log_Te_av = minLogTe; - } - else if (log_Te_av > maxLogTe) { - t_idx=resTe; + } else if (log_Te_av > maxLogTe) { + t_idx = resTe; log_Te_av = maxLogTe; + } else { + t_idx = (log_Te_av - minLogTe) / (dlogTe) + 1; } - else t_idx = (log_Te_av - minLogTe)/(dlogTe)+1; - cell_center = (t_idx - 0.5)*dlogTe + minLogTe; - cell_vals_2d[0] = 2.0*(log_Te_av - cell_center)/dlogTe; // Te value on cell interval - + cell_center = (t_idx - 0.5) * dlogTe + minLogTe; + cell_vals_2d[0] = 2.0 * (log_Te_av - cell_center) / dlogTe; // Te value on cell interval + if (log_m0_av < minLogM0) { - m0_idx=1; + m0_idx = 1; log_m0_av = minLogM0; - } - else if (log_m0_av > maxLogM0) { - m0_idx=resM0; + } else if (log_m0_av > maxLogM0) { + m0_idx = resM0; log_m0_av = maxLogM0; + } else { + m0_idx = (log_m0_av - minLogM0) / (dlogM0) + 1; } - else m0_idx = (log_m0_av - minLogM0)/(dlogM0)+1; - cell_center = (m0_idx - 0.5)*dlogM0 + minLogM0; - cell_vals_2d[1] = 2.0*(log_m0_av - cell_center)/dlogM0; // M0 value on cell interval - + cell_center = (m0_idx - 0.5) * dlogM0 + minLogM0; + cell_vals_2d[1] = 2.0 * (log_m0_av - cell_center) / dlogM0; // M0 value on cell interval + if ((temp_elc_av <= 0.) || (m0_elc_av <= 0.)) { coef_iz_d[0] = 0.0; - } - else { + } else { int ad_idx[2] = {t_idx, m0_idx}; - double *iz_dat_d = (double*) gkyl_array_fetch(ioniz_data, gkyl_range_idx(&adas_rng, ad_idx)); + double *iz_dat_d = (double *)gkyl_array_fetch(ioniz_data, gkyl_range_idx(&adas_rng, ad_idx)); double adas_eval = adas_basis->eval_expand(cell_vals_2d, iz_dat_d); - coef_iz_d[0] = pow(10.0,adas_eval)/cell_av_fac; + coef_iz_d[0] = pow(10.0, adas_eval) / cell_av_fac; if (type_self == GKYL_SELF_ELC) { //calculate vtSq_iz at each cell for primary and secondary elc - if ( 3./2.*temp_elc_av >= 2.*E) { + if (3. / 2. * temp_elc_av >= 2. * E) { // T_e2 = 1/3*sqrt(3./2.*T_e*E_iz - E_iz) - temp_elc_2 = 1.0/3.0 * pow(E*(3./2.*temp_elc_av - E), 0.5); - vtSq_iz2_d[0] = temp_elc_2*elem_charge/(mass_elc*cell_av_fac); + temp_elc_2 = 1.0 / 3.0 * pow(E * (3. / 2. * temp_elc_av - E), 0.5); + vtSq_iz2_d[0] = temp_elc_2 * elem_charge / (mass_elc * cell_av_fac); // T_e1 = T_e - 2/3*E_iz - T_e2 - array_set2(nc, 2*nc, vtSq_iz1_d, 1.0, maxwellian_moms_elc_d); - vtSq_iz1_d[0] = vtSq_iz1_d[0] - elem_charge*(2./3.*E + temp_elc_2)/(mass_elc*cell_av_fac); - } - else if (3./2.*temp_elc_av >= E) { + array_set2(nc, 2 * nc, vtSq_iz1_d, 1.0, maxwellian_moms_elc_d); + vtSq_iz1_d[0] = + vtSq_iz1_d[0] - elem_charge * (2. / 3. * E + temp_elc_2) / (mass_elc * cell_av_fac); + } else if (3. / 2. * temp_elc_av >= E) { // T_e2 = 1/3*(3/2*T_e - E_iz) - temp_elc_2 = temp_elc_av/2.0 - E/3.0; - vtSq_iz2_d[0] = temp_elc_2*elem_charge/(mass_elc*cell_av_fac); + temp_elc_2 = temp_elc_av / 2.0 - E / 3.0; + vtSq_iz2_d[0] = temp_elc_2 * elem_charge / (mass_elc * cell_av_fac); // T_e1 = T_e - 2/3*E_iz - T_e2 - array_set2(nc, 2*nc, vtSq_iz1_d, 1.0, maxwellian_moms_elc_d); - vtSq_iz1_d[0] = vtSq_iz1_d[0] - elem_charge*(2./3.*E + temp_elc_2)/(mass_elc*cell_av_fac); - } - else { - vtSq_iz2_d[0] = temp_flr*elem_charge/(mass_elc*cell_av_fac); - vtSq_iz1_d[0] = temp_flr*elem_charge/(mass_elc*cell_av_fac); + array_set2(nc, 2 * nc, vtSq_iz1_d, 1.0, maxwellian_moms_elc_d); + vtSq_iz1_d[0] = + vtSq_iz1_d[0] - elem_charge * (2. / 3. * E + temp_elc_2) / (mass_elc * cell_av_fac); + } else { + vtSq_iz2_d[0] = temp_flr * elem_charge / (mass_elc * cell_av_fac); + vtSq_iz1_d[0] = temp_flr * elem_charge / (mass_elc * cell_av_fac); } } } } } -void gkyl_dg_iz_coll_cu(const struct gkyl_dg_iz *up, - const struct gkyl_array *maxwellian_moms_elc, - struct gkyl_array *vtSq_iz1, struct gkyl_array *vtSq_iz2, - struct gkyl_array *coef_iz, struct gkyl_array *cflrate) +void gkyl_dg_iz_coll_cu( + const struct gkyl_dg_iz *up, const struct gkyl_array *maxwellian_moms_elc, + struct gkyl_array *vtSq_iz1, struct gkyl_array *vtSq_iz2, struct gkyl_array *coef_iz, + struct gkyl_array *cflrate +) { - gkyl_iz_react_rate_cu_ker<<conf_rng->nblocks, up->conf_rng->nthreads>>>(up->on_dev, - *up->conf_rng, up->adas_rng, up->basis_on_dev, maxwellian_moms_elc->on_dev, - vtSq_iz1->on_dev, vtSq_iz2->on_dev, coef_iz->on_dev, - up->ioniz_data->on_dev, up->type_self, up->mass_elc, up->elem_charge, up->E, - up->maxLogTe, up->minLogTe, up->dlogTe, up->resTe, - up->maxLogM0, up->minLogM0, up->dlogM0, up->resM0); + gkyl_iz_react_rate_cu_ker<<conf_rng->nblocks, up->conf_rng->nthreads> > >( + up->on_dev, *up->conf_rng, up->adas_rng, up->basis_on_dev, maxwellian_moms_elc->on_dev, + vtSq_iz1->on_dev, vtSq_iz2->on_dev, coef_iz->on_dev, up->ioniz_data->on_dev, up->type_self, + up->mass_elc, up->elem_charge, up->E, up->maxLogTe, up->minLogTe, up->dlogTe, up->resTe, + up->maxLogM0, up->minLogM0, up->dlogM0, up->resM0 + ); } diff --git a/gyrokinetic/zero/dg_lbo_gyrokinetic_diff.c b/gyrokinetic/zero/dg_lbo_gyrokinetic_diff.c index 0af5899b57..8fb8bda430 100644 --- a/gyrokinetic/zero/dg_lbo_gyrokinetic_diff.c +++ b/gyrokinetic/zero/dg_lbo_gyrokinetic_diff.c @@ -9,30 +9,30 @@ #include #include -void -gkyl_lbo_gyrokinetic_diff_free(const struct gkyl_ref_count* ref) +void gkyl_lbo_gyrokinetic_diff_free(const struct gkyl_ref_count *ref) { - struct gkyl_dg_eqn* base = container_of(ref, struct gkyl_dg_eqn, ref_count); - struct dg_lbo_gyrokinetic_diff *lbo = container_of(base, struct dg_lbo_gyrokinetic_diff, eqn); + struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); + struct dg_lbo_gyrokinetic_diff *lbo = container_of(base, struct dg_lbo_gyrokinetic_diff, eqn); gkyl_gk_geometry_release(lbo->gk_geom); gkyl_velocity_map_release(lbo->vel_map); - if (GKYL_IS_CU_ALLOC(lbo->eqn.flags)) + if (GKYL_IS_CU_ALLOC(lbo->eqn.flags)) { gkyl_cu_free(lbo->eqn.on_dev); - + } + gkyl_free(lbo); } -void -gkyl_lbo_gyrokinetic_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_diff_auxfields auxin) +void gkyl_lbo_gyrokinetic_diff_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_diff_auxfields auxin +) { - #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(auxin.nuSum) && - gkyl_array_is_cu_dev(auxin.nuPrimMomsSum) && gkyl_array_is_cu_dev(auxin.m2self)) { - gkyl_lbo_gyrokinetic_diff_set_auxfields_cu(eqn->on_dev, auxin); - return; - } + if (gkyl_array_is_cu_dev(auxin.nuSum) && gkyl_array_is_cu_dev(auxin.nuPrimMomsSum) && + gkyl_array_is_cu_dev(auxin.m2self)) { + gkyl_lbo_gyrokinetic_diff_set_auxfields_cu(eqn->on_dev, auxin); + return; + } #endif struct dg_lbo_gyrokinetic_diff *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_diff, eqn); @@ -41,20 +41,22 @@ gkyl_lbo_gyrokinetic_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gk lbo->auxfields.m2self = auxin.m2self; } -struct gkyl_dg_eqn* -gkyl_dg_lbo_gyrokinetic_diff_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, - bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_lbo_gyrokinetic_diff_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) - return gkyl_dg_lbo_gyrokinetic_diff_cu_dev_new(cbasis, pbasis, conf_range, - pgrid, mass, gk_geom, vel_map); + if (use_gpu) { + return gkyl_dg_lbo_gyrokinetic_diff_cu_dev_new( + cbasis, pbasis, conf_range, pgrid, mass, gk_geom, vel_map + ); + } #endif - struct dg_lbo_gyrokinetic_diff* lbo = gkyl_malloc(sizeof(struct dg_lbo_gyrokinetic_diff)); + struct dg_lbo_gyrokinetic_diff *lbo = gkyl_malloc(sizeof(struct dg_lbo_gyrokinetic_diff)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; lbo->cdim = cdim; @@ -64,49 +66,55 @@ gkyl_dg_lbo_gyrokinetic_diff_new(const struct gkyl_basis* cbasis, const struct g lbo->eqn.surf_term = surf; lbo->eqn.boundary_surf_term = boundary_surf; - lbo->vparMax = GKYL_MAX2(fabs(vel_map->vbounds[0]),vel_map->vbounds[vdim]); - lbo->vparMaxSq = pow(lbo->vparMax,2); + lbo->vparMax = GKYL_MAX2(fabs(vel_map->vbounds[0]), vel_map->vbounds[vdim]); + lbo->vparMaxSq = pow(lbo->vparMax, 2); lbo->num_cbasis = cbasis->num_basis; const gkyl_dg_lbo_gyrokinetic_diff_vol_kern_list *vol_kernels; const gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list *surf_vpar_kernels, *surf_mu_kernels; - const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list *boundary_surf_vpar_kernels, *boundary_surf_mu_kernels; - + const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list *boundary_surf_vpar_kernels, + *boundary_surf_mu_kernels; + switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - if (vel_map->is_identity) { - surf_vpar_kernels = ser_surf_vpar_notmapped_kernels; - surf_mu_kernels = ser_surf_mu_notmapped_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_notmapped_kernels; - boundary_surf_mu_kernels = ser_boundary_surf_mu_notmapped_kernels; - } - else { - surf_vpar_kernels = ser_surf_vpar_mapped_kernels; - surf_mu_kernels = ser_surf_mu_mapped_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_mapped_kernels; - boundary_surf_mu_kernels = ser_boundary_surf_mu_mapped_kernels; - } - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + if (vel_map->is_identity) { + surf_vpar_kernels = ser_surf_vpar_notmapped_kernels; + surf_mu_kernels = ser_surf_mu_notmapped_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_notmapped_kernels; + boundary_surf_mu_kernels = ser_boundary_surf_mu_notmapped_kernels; + } else { + surf_vpar_kernels = ser_surf_vpar_mapped_kernels; + surf_mu_kernels = ser_surf_mu_mapped_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_mapped_kernels; + boundary_surf_mu_kernels = ser_boundary_surf_mu_mapped_kernels; + } + break; + + default: + assert(false); + break; + } lbo->eqn.vol_term = CK(vol_kernels, cdim, vdim, poly_order); lbo->surf[0] = CK(surf_vpar_kernels, cdim, vdim, poly_order); - if (vdim>1) + if (vdim > 1) { lbo->surf[1] = CK(surf_mu_kernels, cdim, vdim, poly_order); + } lbo->boundary_surf[0] = CK(boundary_surf_vpar_kernels, cdim, vdim, poly_order); - if (vdim>1) + if (vdim > 1) { lbo->boundary_surf[1] = CK(boundary_surf_mu_kernels, cdim, vdim, poly_order); + } // ensure non-NULL pointers - for (int i=0; isurf[i]); - for (int i=0; iboundary_surf[i]); + for (int i = 0; i < vdim; ++i) { + assert(lbo->surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(lbo->boundary_surf[i]); + } lbo->mass = mass; lbo->conf_range = *conf_range; @@ -120,6 +128,6 @@ gkyl_dg_lbo_gyrokinetic_diff_new(const struct gkyl_basis* cbasis, const struct g GKYL_CLEAR_CU_ALLOC(lbo->eqn.flags); lbo->eqn.ref_count = gkyl_ref_count_init(gkyl_lbo_gyrokinetic_diff_free); lbo->eqn.on_dev = &lbo->eqn; - + return &lbo->eqn; } diff --git a/gyrokinetic/zero/dg_lbo_gyrokinetic_diff_cu.cu b/gyrokinetic/zero/dg_lbo_gyrokinetic_diff_cu.cu index 4cf2772814..7d78383430 100644 --- a/gyrokinetic/zero/dg_lbo_gyrokinetic_diff_cu.cu +++ b/gyrokinetic/zero/dg_lbo_gyrokinetic_diff_cu.cu @@ -13,9 +13,10 @@ extern "C" { // CUDA kernel to set pointer to nuSum, sum of collisionalities // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_lbo_gyrokinetic_diff_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array *nuSum, const struct gkyl_array *nuPrimMomsSum, const struct gkyl_array *m2self) +__global__ static void gkyl_lbo_gyrokinetic_diff_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nuSum, + const struct gkyl_array *nuPrimMomsSum, const struct gkyl_array *m2self +) { struct dg_lbo_gyrokinetic_diff *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_diff, eqn); lbo->auxfields.nuSum = nuSum; @@ -24,73 +25,77 @@ gkyl_lbo_gyrokinetic_diff_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, } //// Host-side wrapper for device kernels setting nuSum, nuUSum and nuVtSqSum. -void -gkyl_lbo_gyrokinetic_diff_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_diff_auxfields auxin) +void gkyl_lbo_gyrokinetic_diff_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_diff_auxfields auxin +) { - gkyl_lbo_gyrokinetic_diff_set_auxfields_cu_kernel<<<1,1>>>(eqn, - auxin.nuSum->on_dev, auxin.nuPrimMomsSum->on_dev, auxin.m2self->on_dev); + gkyl_lbo_gyrokinetic_diff_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.nuSum->on_dev, auxin.nuPrimMomsSum->on_dev, auxin.m2self->on_dev + ); } // CUDA kernel to set device pointers to range object and gyrokinetic LBO kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_lbo_gyrokinetic_diff_set_cu_dev_ptrs(struct dg_lbo_gyrokinetic_diff *lbo, enum gkyl_basis_type b_type, - int cv_index, int cdim, int vdim, int poly_order, bool is_identity) +__global__ static void dg_lbo_gyrokinetic_diff_set_cu_dev_ptrs( + struct dg_lbo_gyrokinetic_diff *lbo, enum gkyl_basis_type b_type, int cv_index, int cdim, + int vdim, int poly_order, bool is_identity +) { - lbo->auxfields.nuSum = 0; - lbo->auxfields.nuPrimMomsSum = 0; - lbo->auxfields.m2self = 0; + lbo->auxfields.nuSum = 0; + lbo->auxfields.nuPrimMomsSum = 0; + lbo->auxfields.m2self = 0; lbo->eqn.surf_term = surf; lbo->eqn.boundary_surf_term = boundary_surf; const gkyl_dg_lbo_gyrokinetic_diff_vol_kern_list *vol_kernels; const gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list *surf_vpar_kernels, *surf_mu_kernels; - const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list *boundary_surf_vpar_kernels, *boundary_surf_mu_kernels; + const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list *boundary_surf_vpar_kernels, + *boundary_surf_mu_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - if (is_identity) { - surf_vpar_kernels = ser_surf_vpar_notmapped_kernels; - surf_mu_kernels = ser_surf_mu_notmapped_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_notmapped_kernels; - boundary_surf_mu_kernels = ser_boundary_surf_mu_notmapped_kernels; - } - else { - surf_vpar_kernels = ser_surf_vpar_mapped_kernels; - surf_mu_kernels = ser_surf_mu_mapped_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_mapped_kernels; - boundary_surf_mu_kernels = ser_boundary_surf_mu_mapped_kernels; - } - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + if (is_identity) { + surf_vpar_kernels = ser_surf_vpar_notmapped_kernels; + surf_mu_kernels = ser_surf_mu_notmapped_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_notmapped_kernels; + boundary_surf_mu_kernels = ser_boundary_surf_mu_notmapped_kernels; + } else { + surf_vpar_kernels = ser_surf_vpar_mapped_kernels; + surf_mu_kernels = ser_surf_mu_mapped_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_mapped_kernels; + boundary_surf_mu_kernels = ser_boundary_surf_mu_mapped_kernels; + } + break; + + default: + assert(false); + break; + } lbo->eqn.vol_term = vol_kernels[cv_index].kernels[poly_order]; lbo->surf[0] = surf_vpar_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { lbo->surf[1] = surf_mu_kernels[cv_index].kernels[poly_order]; + } lbo->boundary_surf[0] = boundary_surf_vpar_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { lbo->boundary_surf[1] = boundary_surf_mu_kernels[cv_index].kernels[poly_order]; - + } } -struct gkyl_dg_eqn* -gkyl_dg_lbo_gyrokinetic_diff_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map) +struct gkyl_dg_eqn *gkyl_dg_lbo_gyrokinetic_diff_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map +) { - struct dg_lbo_gyrokinetic_diff *lbo = - (struct dg_lbo_gyrokinetic_diff*) gkyl_malloc(sizeof(*lbo)); + struct dg_lbo_gyrokinetic_diff *lbo = (struct dg_lbo_gyrokinetic_diff *)gkyl_malloc(sizeof(*lbo)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; lbo->cdim = cdim; @@ -103,12 +108,12 @@ gkyl_dg_lbo_gyrokinetic_diff_cu_dev_new(const struct gkyl_basis* cbasis, const s // Acquire pointers to on_dev objects so memcpy below copies those too. struct gk_geometry *geom_ho = gkyl_gk_geometry_acquire(gk_geom); struct gkyl_velocity_map *vel_map_ho = gkyl_velocity_map_acquire(vel_map); - + lbo->gk_geom = geom_ho->on_dev; lbo->vel_map = vel_map_ho->on_dev; - lbo->vparMax = GKYL_MAX2(fabs(vel_map->vbounds[0]),vel_map->vbounds[vdim]); - lbo->vparMaxSq = pow(lbo->vparMax,2); + lbo->vparMax = GKYL_MAX2(fabs(vel_map->vbounds[0]), vel_map->vbounds[vdim]); + lbo->vparMaxSq = pow(lbo->vparMax, 2); lbo->num_cbasis = cbasis->num_basis; lbo->eqn.flags = 0; @@ -117,19 +122,19 @@ gkyl_dg_lbo_gyrokinetic_diff_cu_dev_new(const struct gkyl_basis* cbasis, const s // copy the host struct to device struct struct dg_lbo_gyrokinetic_diff *lbo_cu = - (struct dg_lbo_gyrokinetic_diff*) gkyl_cu_malloc(sizeof(struct dg_lbo_gyrokinetic_diff)); + (struct dg_lbo_gyrokinetic_diff *)gkyl_cu_malloc(sizeof(struct dg_lbo_gyrokinetic_diff)); - gkyl_cu_memcpy(lbo_cu, lbo, - sizeof(struct dg_lbo_gyrokinetic_diff), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(lbo_cu, lbo, sizeof(struct dg_lbo_gyrokinetic_diff), GKYL_CU_MEMCPY_H2D); - dg_lbo_gyrokinetic_diff_set_cu_dev_ptrs<<<1,1>>>(lbo_cu, - cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order, vel_map->is_identity); + dg_lbo_gyrokinetic_diff_set_cu_dev_ptrs<<<1, 1> > >( + lbo_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order, vel_map->is_identity + ); - lbo->eqn.on_dev = &lbo_cu->eqn; + lbo->eqn.on_dev = &lbo_cu->eqn; // Updater should store host pointers. lbo->gk_geom = geom_ho; lbo->vel_map = vel_map_ho; - + return &lbo->eqn; } diff --git a/gyrokinetic/zero/dg_lbo_gyrokinetic_drag.c b/gyrokinetic/zero/dg_lbo_gyrokinetic_drag.c index f26dfa2f8a..954a340eeb 100644 --- a/gyrokinetic/zero/dg_lbo_gyrokinetic_drag.c +++ b/gyrokinetic/zero/dg_lbo_gyrokinetic_drag.c @@ -9,30 +9,30 @@ #include #include -void -gkyl_lbo_gyrokinetic_drag_free(const struct gkyl_ref_count* ref) +void gkyl_lbo_gyrokinetic_drag_free(const struct gkyl_ref_count *ref) { - struct gkyl_dg_eqn* base = container_of(ref, struct gkyl_dg_eqn, ref_count); + struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); struct dg_lbo_gyrokinetic_drag *lbo = container_of(base, struct dg_lbo_gyrokinetic_drag, eqn); gkyl_gk_geometry_release(lbo->gk_geom); gkyl_velocity_map_release(lbo->vel_map); - if (GKYL_IS_CU_ALLOC(lbo->eqn.flags)) + if (GKYL_IS_CU_ALLOC(lbo->eqn.flags)) { gkyl_cu_free(lbo->eqn.on_dev); - + } + gkyl_free(lbo); } -void -gkyl_lbo_gyrokinetic_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_drag_auxfields auxin) +void gkyl_lbo_gyrokinetic_drag_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_drag_auxfields auxin +) { - #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(auxin.nuSum) && - gkyl_array_is_cu_dev(auxin.nuPrimMomsSum) && gkyl_array_is_cu_dev(auxin.m2self)) { - gkyl_lbo_gyrokinetic_drag_set_auxfields_cu(eqn->on_dev, auxin); - return; - } + if (gkyl_array_is_cu_dev(auxin.nuSum) && gkyl_array_is_cu_dev(auxin.nuPrimMomsSum) && + gkyl_array_is_cu_dev(auxin.m2self)) { + gkyl_lbo_gyrokinetic_drag_set_auxfields_cu(eqn->on_dev, auxin); + return; + } #endif struct dg_lbo_gyrokinetic_drag *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_drag, eqn); @@ -41,21 +41,22 @@ gkyl_lbo_gyrokinetic_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gk lbo->auxfields.m2self = auxin.m2self; } - -struct gkyl_dg_eqn* -gkyl_dg_lbo_gyrokinetic_drag_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, - bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_lbo_gyrokinetic_drag_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) - return gkyl_dg_lbo_gyrokinetic_drag_cu_dev_new(cbasis, pbasis, - conf_range, pgrid, mass, gk_geom, vel_map); + if (use_gpu) { + return gkyl_dg_lbo_gyrokinetic_drag_cu_dev_new( + cbasis, pbasis, conf_range, pgrid, mass, gk_geom, vel_map + ); + } #endif - struct dg_lbo_gyrokinetic_drag* lbo = gkyl_malloc(sizeof(struct dg_lbo_gyrokinetic_drag)); + struct dg_lbo_gyrokinetic_drag *lbo = gkyl_malloc(sizeof(struct dg_lbo_gyrokinetic_drag)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; lbo->cdim = cdim; @@ -65,47 +66,54 @@ gkyl_dg_lbo_gyrokinetic_drag_new(const struct gkyl_basis* cbasis, const struct g lbo->eqn.surf_term = surf; lbo->eqn.boundary_surf_term = boundary_surf; - lbo->vparMax = GKYL_MAX2(fabs(vel_map->vbounds[0]),vel_map->vbounds[vdim]); - lbo->vparMaxSq = pow(lbo->vparMax,2); + lbo->vparMax = GKYL_MAX2(fabs(vel_map->vbounds[0]), vel_map->vbounds[vdim]); + lbo->vparMaxSq = pow(lbo->vparMax, 2); lbo->num_cbasis = cbasis->num_basis; const gkyl_dg_lbo_gyrokinetic_drag_vol_kern_list *vol_kernels; const gkyl_dg_lbo_gyrokinetic_drag_surf_kern_list *surf_vpar_kernels, *surf_mu_kernels; - const gkyl_dg_lbo_gyrokinetic_drag_boundary_surf_kern_list *boundary_surf_vpar_kernels, *boundary_surf_mu_kernels; - + const gkyl_dg_lbo_gyrokinetic_drag_boundary_surf_kern_list *boundary_surf_vpar_kernels, + *boundary_surf_mu_kernels; + switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vpar_kernels = ser_surf_vpar_kernels; - surf_mu_kernels = ser_surf_mu_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; - boundary_surf_mu_kernels = ser_boundary_surf_mu_kernels; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vpar_kernels = ser_surf_vpar_kernels; + surf_mu_kernels = ser_surf_mu_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; + boundary_surf_mu_kernels = ser_boundary_surf_mu_kernels; + break; + + default: + assert(false); + break; + } lbo->eqn.vol_term = CK(vol_kernels, cdim, vdim, poly_order); lbo->surf[0] = CK(surf_vpar_kernels, cdim, vdim, poly_order); - if (vdim>1) + if (vdim > 1) { lbo->surf[1] = CK(surf_mu_kernels, cdim, vdim, poly_order); + } lbo->boundary_surf[0] = CK(boundary_surf_vpar_kernels, cdim, vdim, poly_order); - if (vdim>1) + if (vdim > 1) { lbo->boundary_surf[1] = CK(boundary_surf_mu_kernels, cdim, vdim, poly_order); + } // ensure non-NULL pointers - for (int i=0; isurf[i]); - for (int i=0; iboundary_surf[i]); + for (int i = 0; i < vdim; ++i) { + assert(lbo->surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(lbo->boundary_surf[i]); + } lbo->mass = mass; lbo->conf_range = *conf_range; lbo->gk_geom = gkyl_gk_geometry_acquire(gk_geom); lbo->vel_map = gkyl_velocity_map_acquire(vel_map); - + lbo->auxfields.nuSum = 0; lbo->auxfields.nuPrimMomsSum = 0; lbo->auxfields.m2self = 0; @@ -114,6 +122,6 @@ gkyl_dg_lbo_gyrokinetic_drag_new(const struct gkyl_basis* cbasis, const struct g GKYL_CLEAR_CU_ALLOC(lbo->eqn.flags); lbo->eqn.ref_count = gkyl_ref_count_init(gkyl_lbo_gyrokinetic_drag_free); lbo->eqn.on_dev = &lbo->eqn; - + return &lbo->eqn; } diff --git a/gyrokinetic/zero/dg_lbo_gyrokinetic_drag_cu.cu b/gyrokinetic/zero/dg_lbo_gyrokinetic_drag_cu.cu index bcbffc04a9..ce7e8019a1 100644 --- a/gyrokinetic/zero/dg_lbo_gyrokinetic_drag_cu.cu +++ b/gyrokinetic/zero/dg_lbo_gyrokinetic_drag_cu.cu @@ -4,7 +4,7 @@ extern "C" { #include #include -#include +#include #include } @@ -13,9 +13,10 @@ extern "C" { // CUDA kernel to set pointer to nuSum, sum of collisionalities // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_lbo_gyrokinetic_drag_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array *nuSum, const struct gkyl_array *nuPrimMomsSum, const struct gkyl_array *m2self) +__global__ static void gkyl_lbo_gyrokinetic_drag_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nuSum, + const struct gkyl_array *nuPrimMomsSum, const struct gkyl_array *m2self +) { struct dg_lbo_gyrokinetic_drag *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_drag, eqn); lbo->auxfields.nuSum = nuSum; @@ -24,65 +25,70 @@ gkyl_lbo_gyrokinetic_drag_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, } //// Host-side wrapper for device kernels setting nuSum, nuUSum and nuVtSqSum. -void -gkyl_lbo_gyrokinetic_drag_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_drag_auxfields auxin) +void gkyl_lbo_gyrokinetic_drag_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_drag_auxfields auxin +) { - gkyl_lbo_gyrokinetic_drag_set_auxfields_cu_kernel<<<1,1>>>(eqn, - auxin.nuSum->on_dev, auxin.nuPrimMomsSum->on_dev, auxin.m2self->on_dev); + gkyl_lbo_gyrokinetic_drag_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.nuSum->on_dev, auxin.nuPrimMomsSum->on_dev, auxin.m2self->on_dev + ); } // CUDA kernel to set device pointers to range object and gyrokinetic LBO kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_lbo_gyrokinetic_drag_set_cu_dev_ptrs(struct dg_lbo_gyrokinetic_drag *lbo, enum gkyl_basis_type b_type, - int cv_index, int cdim, int vdim, int poly_order) +__global__ static void dg_lbo_gyrokinetic_drag_set_cu_dev_ptrs( + struct dg_lbo_gyrokinetic_drag *lbo, enum gkyl_basis_type b_type, int cv_index, int cdim, + int vdim, int poly_order +) { - lbo->auxfields.nuSum = 0; - lbo->auxfields.nuPrimMomsSum = 0; - lbo->auxfields.m2self = 0; + lbo->auxfields.nuSum = 0; + lbo->auxfields.nuPrimMomsSum = 0; + lbo->auxfields.m2self = 0; lbo->eqn.surf_term = surf; lbo->eqn.boundary_surf_term = boundary_surf; const gkyl_dg_lbo_gyrokinetic_drag_vol_kern_list *vol_kernels; const gkyl_dg_lbo_gyrokinetic_drag_surf_kern_list *surf_vpar_kernels, *surf_mu_kernels; - const gkyl_dg_lbo_gyrokinetic_drag_boundary_surf_kern_list *boundary_surf_vpar_kernels, *boundary_surf_mu_kernels; - + const gkyl_dg_lbo_gyrokinetic_drag_boundary_surf_kern_list *boundary_surf_vpar_kernels, + *boundary_surf_mu_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vpar_kernels = ser_surf_vpar_kernels; - surf_mu_kernels = ser_surf_mu_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; - boundary_surf_mu_kernels = ser_boundary_surf_mu_kernels; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vpar_kernels = ser_surf_vpar_kernels; + surf_mu_kernels = ser_surf_mu_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; + boundary_surf_mu_kernels = ser_boundary_surf_mu_kernels; + break; + + default: + assert(false); + break; + } lbo->eqn.vol_term = vol_kernels[cv_index].kernels[poly_order]; lbo->surf[0] = surf_vpar_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { lbo->surf[1] = surf_mu_kernels[cv_index].kernels[poly_order]; + } lbo->boundary_surf[0] = boundary_surf_vpar_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { lbo->boundary_surf[1] = boundary_surf_mu_kernels[cv_index].kernels[poly_order]; - + } } -struct gkyl_dg_eqn* -gkyl_dg_lbo_gyrokinetic_drag_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map) +struct gkyl_dg_eqn *gkyl_dg_lbo_gyrokinetic_drag_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map +) { - struct dg_lbo_gyrokinetic_drag *lbo = - (struct dg_lbo_gyrokinetic_drag*) gkyl_malloc(sizeof(*lbo)); + struct dg_lbo_gyrokinetic_drag *lbo = (struct dg_lbo_gyrokinetic_drag *)gkyl_malloc(sizeof(*lbo)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; lbo->cdim = cdim; @@ -96,12 +102,12 @@ gkyl_dg_lbo_gyrokinetic_drag_cu_dev_new(const struct gkyl_basis* cbasis, const s // Acquire pointers to on_dev objects so memcpy below copies those too. struct gk_geometry *geom_ho = gkyl_gk_geometry_acquire(gk_geom); struct gkyl_velocity_map *vel_map_ho = gkyl_velocity_map_acquire(vel_map); - + lbo->gk_geom = geom_ho->on_dev; lbo->vel_map = vel_map_ho->on_dev; - lbo->vparMax = GKYL_MAX2(fabs(vel_map->vbounds[0]),vel_map->vbounds[vdim]); - lbo->vparMaxSq = pow(lbo->vparMax,2); + lbo->vparMax = GKYL_MAX2(fabs(vel_map->vbounds[0]), vel_map->vbounds[vdim]); + lbo->vparMaxSq = pow(lbo->vparMax, 2); lbo->num_cbasis = cbasis->num_basis; lbo->eqn.flags = 0; @@ -110,19 +116,19 @@ gkyl_dg_lbo_gyrokinetic_drag_cu_dev_new(const struct gkyl_basis* cbasis, const s // copy the host struct to device struct struct dg_lbo_gyrokinetic_drag *lbo_cu = - (struct dg_lbo_gyrokinetic_drag*) gkyl_cu_malloc(sizeof(struct dg_lbo_gyrokinetic_drag)); + (struct dg_lbo_gyrokinetic_drag *)gkyl_cu_malloc(sizeof(struct dg_lbo_gyrokinetic_drag)); - gkyl_cu_memcpy(lbo_cu, lbo, - sizeof(struct dg_lbo_gyrokinetic_drag), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(lbo_cu, lbo, sizeof(struct dg_lbo_gyrokinetic_drag), GKYL_CU_MEMCPY_H2D); - dg_lbo_gyrokinetic_drag_set_cu_dev_ptrs<<<1,1>>>(lbo_cu, - cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order); + dg_lbo_gyrokinetic_drag_set_cu_dev_ptrs<<<1, 1> > >( + lbo_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order + ); - lbo->eqn.on_dev = &lbo_cu->eqn; + lbo->eqn.on_dev = &lbo_cu->eqn; // Updater should store host pointers. lbo->gk_geom = geom_ho; lbo->vel_map = vel_map_ho; - + return &lbo->eqn; } diff --git a/gyrokinetic/zero/dg_rad_gyrokinetic_drag.c b/gyrokinetic/zero/dg_rad_gyrokinetic_drag.c index bd66bcb289..efd47f5d0a 100644 --- a/gyrokinetic/zero/dg_rad_gyrokinetic_drag.c +++ b/gyrokinetic/zero/dg_rad_gyrokinetic_drag.c @@ -9,22 +9,23 @@ #include #include -void -gkyl_rad_gyrokinetic_free(const struct gkyl_ref_count* ref) +void gkyl_rad_gyrokinetic_free(const struct gkyl_ref_count *ref) { - struct gkyl_dg_eqn* base = container_of(ref, struct gkyl_dg_eqn, ref_count); + struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); struct dg_rad_gyrokinetic_drag *grad = container_of(base, struct dg_rad_gyrokinetic_drag, eqn); gkyl_velocity_map_release(grad->vel_map); - if (GKYL_IS_CU_ALLOC(grad->eqn.flags)) + if (GKYL_IS_CU_ALLOC(grad->eqn.flags)) { gkyl_cu_free(grad->eqn.on_dev); - + } + gkyl_free(grad); } -void -gkyl_rad_gyrokinetic_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_rad_gyrokinetic_auxfields auxin) +void gkyl_rad_gyrokinetic_drag_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_rad_gyrokinetic_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_dg_eqn_is_cu_dev(eqn)) { @@ -40,25 +41,29 @@ gkyl_rad_gyrokinetic_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gk grad->auxfields.nvsqnu = auxin.nvsqnu; } -struct gkyl_dg_eqn* -gkyl_dg_rad_gyrokinetic_drag_new(const struct gkyl_basis *conf_basis, - const struct gkyl_basis *phase_basis, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_range, const struct gkyl_velocity_map *vel_map, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_rad_gyrokinetic_drag_new( + const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, + const struct gkyl_velocity_map *vel_map, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) - return gkyl_dg_rad_gyrokinetic_drag_cu_dev_new(conf_basis, phase_basis, phase_range, conf_range, vel_map); + if (use_gpu) { + return gkyl_dg_rad_gyrokinetic_drag_cu_dev_new( + conf_basis, phase_basis, phase_range, conf_range, vel_map + ); + } #endif - + struct dg_rad_gyrokinetic_drag *grad = gkyl_malloc(sizeof(*grad)); - int cdim = conf_basis->ndim, pdim = phase_basis->ndim, vdim = pdim-cdim; + int cdim = conf_basis->ndim, pdim = phase_basis->ndim, vdim = pdim - cdim; int poly_order = conf_basis->poly_order; - + grad->cdim = cdim; grad->pdim = pdim; - grad->cellav_norm_conf = 1.0/pow(sqrt(2.0),cdim); + grad->cellav_norm_conf = 1.0 / pow(sqrt(2.0), cdim); grad->eqn.num_equations = 1; grad->eqn.surf_term = surf; @@ -66,35 +71,42 @@ gkyl_dg_rad_gyrokinetic_drag_new(const struct gkyl_basis *conf_basis, const gkyl_dg_rad_gyrokinetic_vol_kern_list *vol_kernels; const gkyl_dg_rad_gyrokinetic_surf_kern_list *surf_vpar_kernels, *surf_mu_kernels; - const gkyl_dg_rad_gyrokinetic_boundary_surf_kern_list *boundary_surf_vpar_kernels, *boundary_surf_mu_kernels; - + const gkyl_dg_rad_gyrokinetic_boundary_surf_kern_list *boundary_surf_vpar_kernels, + *boundary_surf_mu_kernels; + switch (conf_basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vpar_kernels = ser_surf_vpar_kernels; - surf_mu_kernels = ser_surf_mu_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; - boundary_surf_mu_kernels = ser_boundary_surf_mu_kernels; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vpar_kernels = ser_surf_vpar_kernels; + surf_mu_kernels = ser_surf_mu_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; + boundary_surf_mu_kernels = ser_boundary_surf_mu_kernels; + break; + + default: + assert(false); + break; + } grad->eqn.vol_term = CK(vol_kernels, cdim, vdim, poly_order); grad->surf[0] = CK(surf_vpar_kernels, cdim, vdim, poly_order); - if (vdim>1) + if (vdim > 1) { grad->surf[1] = CK(surf_mu_kernels, cdim, vdim, poly_order); + } grad->boundary_surf[0] = CK(boundary_surf_vpar_kernels, cdim, vdim, poly_order); - if (vdim>1) + if (vdim > 1) { grad->boundary_surf[1] = CK(boundary_surf_mu_kernels, cdim, vdim, poly_order); - + } + // ensure non-NULL pointers - for (int i=0; isurf[i]); - for (int i=0; iboundary_surf[i]); + for (int i = 0; i < vdim; ++i) { + assert(grad->surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(grad->boundary_surf[i]); + } grad->auxfields.nvnu_surf = 0; grad->auxfields.nvnu = 0; @@ -111,4 +123,3 @@ gkyl_dg_rad_gyrokinetic_drag_new(const struct gkyl_basis *conf_basis, return &grad->eqn; } - diff --git a/gyrokinetic/zero/dg_rad_gyrokinetic_drag_cu.cu b/gyrokinetic/zero/dg_rad_gyrokinetic_drag_cu.cu index 30f608cd71..f4ed269af3 100644 --- a/gyrokinetic/zero/dg_rad_gyrokinetic_drag_cu.cu +++ b/gyrokinetic/zero/dg_rad_gyrokinetic_drag_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include } @@ -12,10 +12,10 @@ extern "C" { // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_rad_gyrokinetic_drag_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array* nvnu_surf, const struct gkyl_array* nvnu, - const struct gkyl_array* nvsqnu_surf, const struct gkyl_array* nvsqnu) +__global__ static void gkyl_rad_gyrokinetic_drag_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nvnu_surf, const struct gkyl_array *nvnu, + const struct gkyl_array *nvsqnu_surf, const struct gkyl_array *nvsqnu +) { struct dg_rad_gyrokinetic_drag *grad = container_of(eqn, struct dg_rad_gyrokinetic_drag, eqn); grad->auxfields.nvnu_surf = nvnu_surf; @@ -25,23 +25,26 @@ gkyl_rad_gyrokinetic_drag_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_rad_gyrokinetic_drag_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_rad_gyrokinetic_auxfields auxin) +void gkyl_rad_gyrokinetic_drag_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_rad_gyrokinetic_auxfields auxin +) { - gkyl_rad_gyrokinetic_drag_set_auxfields_cu_kernel<<<1,1>>>(eqn, - auxin.nvnu_surf->on_dev, auxin.nvnu->on_dev, - auxin.nvsqnu_surf->on_dev, auxin.nvsqnu->on_dev); + gkyl_rad_gyrokinetic_drag_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.nvnu_surf->on_dev, auxin.nvnu->on_dev, auxin.nvsqnu_surf->on_dev, + auxin.nvsqnu->on_dev + ); } // CUDA kernel to set device pointers to range object and rad_gyrokinetic_drag kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_rad_gyrokinetic_drag_set_cu_dev_ptrs(struct dg_rad_gyrokinetic_drag *grad, enum gkyl_basis_type b_type, - int cv_index, int cdim, int vdim, int poly_order) +__global__ static void dg_rad_gyrokinetic_drag_set_cu_dev_ptrs( + struct dg_rad_gyrokinetic_drag *grad, enum gkyl_basis_type b_type, int cv_index, int cdim, + int vdim, int poly_order +) { - grad->auxfields.nvnu_surf = 0; - grad->auxfields.nvnu = 0; - grad->auxfields.nvsqnu_surf = 0; + grad->auxfields.nvnu_surf = 0; + grad->auxfields.nvnu = 0; + grad->auxfields.nvsqnu_surf = 0; grad->auxfields.nvsqnu = 0; grad->eqn.surf_term = surf; @@ -49,48 +52,53 @@ dg_rad_gyrokinetic_drag_set_cu_dev_ptrs(struct dg_rad_gyrokinetic_drag *grad, en const gkyl_dg_rad_gyrokinetic_vol_kern_list *vol_kernels; const gkyl_dg_rad_gyrokinetic_surf_kern_list *surf_vpar_kernels, *surf_mu_kernels; - const gkyl_dg_rad_gyrokinetic_boundary_surf_kern_list *boundary_surf_vpar_kernels, *boundary_surf_mu_kernels; - + const gkyl_dg_rad_gyrokinetic_boundary_surf_kern_list *boundary_surf_vpar_kernels, + *boundary_surf_mu_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vpar_kernels = ser_surf_vpar_kernels; - surf_mu_kernels = ser_surf_mu_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; - boundary_surf_mu_kernels = ser_boundary_surf_mu_kernels; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vpar_kernels = ser_surf_vpar_kernels; + surf_mu_kernels = ser_surf_mu_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; + boundary_surf_mu_kernels = ser_boundary_surf_mu_kernels; + break; + + default: + assert(false); + break; + } grad->eqn.vol_term = vol_kernels[cv_index].kernels[poly_order]; grad->surf[0] = surf_vpar_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { grad->surf[1] = surf_mu_kernels[cv_index].kernels[poly_order]; + } grad->boundary_surf[0] = boundary_surf_vpar_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { grad->boundary_surf[1] = boundary_surf_mu_kernels[cv_index].kernels[poly_order]; + } } -struct gkyl_dg_eqn* -gkyl_dg_rad_gyrokinetic_drag_cu_dev_new(const struct gkyl_basis* conf_basis, - const struct gkyl_basis* phase_basis, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_range, const struct gkyl_velocity_map *vel_map) +struct gkyl_dg_eqn *gkyl_dg_rad_gyrokinetic_drag_cu_dev_new( + const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, + const struct gkyl_velocity_map *vel_map +) { - struct dg_rad_gyrokinetic_drag *grad = (struct dg_rad_gyrokinetic_drag*) gkyl_malloc(sizeof(*grad)); + struct dg_rad_gyrokinetic_drag *grad = + (struct dg_rad_gyrokinetic_drag *)gkyl_malloc(sizeof(*grad)); - int cdim = conf_basis->ndim, pdim = phase_basis->ndim, vdim = pdim-cdim; + int cdim = conf_basis->ndim, pdim = phase_basis->ndim, vdim = pdim - cdim; int poly_order = conf_basis->poly_order; - + grad->cdim = cdim; grad->pdim = pdim; grad->phase_range = *phase_range; grad->conf_range = *conf_range; - grad->cellav_norm_conf = 1.0/pow(sqrt(2.0),cdim); + grad->cellav_norm_conf = 1.0 / pow(sqrt(2.0), cdim); // Acquire pointers to on_dev objects so memcpy below copies those too. struct gkyl_velocity_map *vel_map_ho = gkyl_velocity_map_acquire(vel_map); @@ -101,17 +109,19 @@ gkyl_dg_rad_gyrokinetic_drag_cu_dev_new(const struct gkyl_basis* conf_basis, grad->eqn.ref_count = gkyl_ref_count_init(gkyl_rad_gyrokinetic_free); // copy the host struct to device struct - struct dg_rad_gyrokinetic_drag *grad_cu = (struct dg_rad_gyrokinetic_drag*) gkyl_cu_malloc(sizeof(struct dg_rad_gyrokinetic_drag)); + struct dg_rad_gyrokinetic_drag *grad_cu = + (struct dg_rad_gyrokinetic_drag *)gkyl_cu_malloc(sizeof(struct dg_rad_gyrokinetic_drag)); gkyl_cu_memcpy(grad_cu, grad, sizeof(struct dg_rad_gyrokinetic_drag), GKYL_CU_MEMCPY_H2D); - dg_rad_gyrokinetic_drag_set_cu_dev_ptrs<<<1,1>>>(grad_cu, conf_basis->b_type, cv_index[cdim].vdim[vdim], - cdim, vdim, poly_order); + dg_rad_gyrokinetic_drag_set_cu_dev_ptrs<<<1, 1> > >( + grad_cu, conf_basis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order + ); // set parent on_dev pointer grad->eqn.on_dev = &grad_cu->eqn; // Updater should store host pointers. - grad->vel_map = vel_map_ho; + grad->vel_map = vel_map_ho; return &grad->eqn; } diff --git a/gyrokinetic/zero/dg_recomb.c b/gyrokinetic/zero/dg_recomb.c index ad673d8143..004d0d53f6 100644 --- a/gyrokinetic/zero/dg_recomb.c +++ b/gyrokinetic/zero/dg_recomb.c @@ -15,8 +15,7 @@ #include #include -struct gkyl_dg_recomb* -gkyl_dg_recomb_new(struct gkyl_dg_recomb_inp *inp, bool use_gpu) +struct gkyl_dg_recomb *gkyl_dg_recomb_new(struct gkyl_dg_recomb_inp *inp, bool use_gpu) { gkyl_dg_recomb *up = gkyl_malloc(sizeof(struct gkyl_dg_recomb)); @@ -26,7 +25,7 @@ gkyl_dg_recomb_new(struct gkyl_dg_recomb_inp *inp, bool use_gpu) up->conf_rng_ext = inp->conf_rng_ext; up->phase_rng = inp->phase_rng; up->grid = inp->grid; - + int cdim = up->cbasis->ndim; int pdim = up->pbasis->ndim; int vdim = pdim - cdim; @@ -34,31 +33,37 @@ gkyl_dg_recomb_new(struct gkyl_dg_recomb_inp *inp, bool use_gpu) up->cdim = cdim; up->vdim = vdim; up->use_gpu = use_gpu; - + up->elem_charge = GKYL_ELEMENTARY_CHARGE; up->mass_elc = GKYL_ELECTRON_MASS; int charge_state = inp->charge_state; enum gkyl_ion_type type_ion = inp->type_ion; - + // Project ADAS data struct adas_field data; read_adas_field_recomb(type_ion, &data); - - long sz = data.NT*data.NN; + + long sz = data.NT * data.NN; double minmax[2]; - if (data.logT == NULL) fprintf(stderr, "Unable to load ADAS 'logT_.npy' file."); - if (data.logN == NULL) fprintf(stderr, "Unable to load ADAS 'logN_.npy' file."); - if (data.logData == NULL) fprintf(stderr, "Unable to load ADAS 'recomb_.npy' file."); + if (data.logT == NULL) { + fprintf(stderr, "Unable to load ADAS 'logT_.npy' file."); + } + if (data.logN == NULL) { + fprintf(stderr, "Unable to load ADAS 'logN_.npy' file."); + } + if (data.logData == NULL) { + fprintf(stderr, "Unable to load ADAS 'recomb_.npy' file."); + } minmax_from_numpy(data.logT, data.NT, minmax); fclose(data.logT); double logTmin = minmax[0], logTmax = minmax[1]; minmax_from_numpy(data.logN, data.NN, minmax); fclose(data.logN); - double logNmin = minmax[0]+6., logNmax = minmax[1]+6.; //adjust for 1/cm^3 to 1/m^3 conversion + double logNmin = minmax[0] + 6., logNmax = minmax[1] + 6.; //adjust for 1/cm^3 to 1/m^3 conversion struct gkyl_array *adas_nodal = gkyl_array_new(GKYL_DOUBLE, 1, sz); array_from_numpy(data.logData, sz, data.Zmax, charge_state, adas_nodal); @@ -70,38 +75,40 @@ gkyl_dg_recomb_new(struct gkyl_dg_recomb_inp *inp, bool use_gpu) } struct gkyl_range range_nodal; - gkyl_range_init_from_shape(&range_nodal, 2, (int[]) { data.NT, data.NN } ); - + gkyl_range_init_from_shape(&range_nodal, 2, (int[]){data.NT, data.NN}); + // allocate grid and DG array struct gkyl_rect_grid tn_grid; - gkyl_rect_grid_init(&tn_grid, 2, - (double[]) { logTmin, logNmin}, - (double []) { logTmax, logNmax}, - (int[]) { data.NT-1, data.NN-1 } + gkyl_rect_grid_init( + &tn_grid, 2, (double[]){logTmin, logNmin}, (double[]){logTmax, logNmax}, + (int[]){data.NT - 1, data.NN - 1} ); if (use_gpu) { // allocate device basis if we are using GPUs up->basis_on_dev = gkyl_cu_malloc(sizeof(struct gkyl_basis)); - } - else { + } else { up->basis_on_dev = &up->adas_basis; } gkyl_cart_modal_serendip(&up->adas_basis, 2, 1); - if (use_gpu) + if (use_gpu) { gkyl_cart_modal_serendip_cu_dev(up->basis_on_dev, 2, 1); + } - int ghost[GKYL_MAX_DIM] = { 1, 1}; + int ghost[GKYL_MAX_DIM] = {1, 1}; struct gkyl_range modal_range; struct gkyl_range modal_range_ext; gkyl_create_grid_ranges(&tn_grid, ghost, &modal_range_ext, &modal_range); - struct gkyl_array *adas_dg = gkyl_array_new(GKYL_DOUBLE, up->adas_basis.num_basis, modal_range_ext.volume); + struct gkyl_array *adas_dg = + gkyl_array_new(GKYL_DOUBLE, up->adas_basis.num_basis, modal_range_ext.volume); //create_dg_from_nodal(&tn_grid, &range_node, adas_nodal, adas_dg, charge_state); struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&up->adas_basis, &tn_grid, false); - gkyl_nodal_ops_n2m(n2m, &up->adas_basis, &tn_grid, &range_nodal, &modal_range, 1, adas_nodal, adas_dg, false); + gkyl_nodal_ops_n2m( + n2m, &up->adas_basis, &tn_grid, &range_nodal, &modal_range, 1, adas_nodal, adas_dg, false + ); gkyl_nodal_ops_release(n2m); // ADAS data pointers @@ -117,14 +124,14 @@ gkyl_dg_recomb_new(struct gkyl_dg_recomb_inp *inp, bool use_gpu) up->adas_rng = modal_range; if (use_gpu) { - up->recomb_data = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->adas_basis.num_basis, modal_range_ext.volume); + up->recomb_data = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->adas_basis.num_basis, modal_range_ext.volume); gkyl_array_copy(up->recomb_data, adas_dg); - } - else { + } else { up->recomb_data = gkyl_array_new(GKYL_DOUBLE, up->adas_basis.num_basis, modal_range_ext.volume); gkyl_array_copy(up->recomb_data, adas_dg); } - + up->on_dev = up; // CPU eqn obj points to itself gkyl_array_release(adas_nodal); @@ -133,19 +140,22 @@ gkyl_dg_recomb_new(struct gkyl_dg_recomb_inp *inp, bool use_gpu) return up; } -void gkyl_dg_recomb_coll(const struct gkyl_dg_recomb *up, - const struct gkyl_array *prim_vars_elc, - struct gkyl_array *coef_recomb, struct gkyl_array *cflrate) +void gkyl_dg_recomb_coll( + const struct gkyl_dg_recomb *up, const struct gkyl_array *prim_vars_elc, + struct gkyl_array *coef_recomb, struct gkyl_array *cflrate +) { #ifdef GKYL_HAVE_CUDA - if(gkyl_array_is_cu_dev(coef_recomb)) { + if (gkyl_array_is_cu_dev(coef_recomb)) { return gkyl_dg_recomb_coll_cu(up, prim_vars_elc, coef_recomb, cflrate); } #endif struct gkyl_range_iter conf_iter, vel_iter; - int rem_dir[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dconf_rng->ndim; ++d) rem_dir[d] = 1; + int rem_dir[GKYL_MAX_DIM] = {0}; + for (int d = 0; d < up->conf_rng->ndim; ++d) { + rem_dir[d] = 1; + } gkyl_range_iter_init(&conf_iter, up->conf_rng); while (gkyl_range_iter_next(&conf_iter)) { long loc = gkyl_range_idx(up->conf_rng, conf_iter.idx); @@ -155,48 +165,48 @@ void gkyl_dg_recomb_coll(const struct gkyl_dg_recomb *up, double *coef_recomb_d = gkyl_array_fetch(coef_recomb, loc); //Find cell containing value of n,T - double cell_av_fac = pow(1/sqrt(2),up->cdim); - double m0_elc_av = prim_vars_elc_d[0]*cell_av_fac; - double temp_elc_av = prim_vars_elc_d[2*nc]*cell_av_fac*up->mass_elc/up->elem_charge; + double cell_av_fac = pow(1 / sqrt(2), up->cdim); + double m0_elc_av = prim_vars_elc_d[0] * cell_av_fac; + double temp_elc_av = prim_vars_elc_d[2 * nc] * cell_av_fac * up->mass_elc / up->elem_charge; double log_Te_av = log10(temp_elc_av); double log_m0_av = log10(m0_elc_av); double cell_val_t; double cell_val_m0; int m0_idx, t_idx; double cell_vals_2d[2]; - double cell_center; + double cell_center; if (log_Te_av < up->minLogTe) { - t_idx=1; + t_idx = 1; log_Te_av = up->minLogTe; - } - else if (log_Te_av > up->maxLogTe) { - t_idx=up->resTe; + } else if (log_Te_av > up->maxLogTe) { + t_idx = up->resTe; log_Te_av = up->maxLogTe; + } else { + t_idx = (log_Te_av - up->minLogTe) / (up->dlogTe) + 1; } - else t_idx = (log_Te_av - up->minLogTe)/(up->dlogTe)+1; - cell_center = (t_idx - 0.5)*up->dlogTe + up->minLogTe; - cell_vals_2d[0] = 2.0*(log_Te_av - cell_center)/up->dlogTe; // Te value on cell interval - + cell_center = (t_idx - 0.5) * up->dlogTe + up->minLogTe; + cell_vals_2d[0] = 2.0 * (log_Te_av - cell_center) / up->dlogTe; // Te value on cell interval + if (log_m0_av < up->minLogM0) { - m0_idx=1; + m0_idx = 1; log_m0_av = up->minLogM0; - } - else if (log_m0_av > up->maxLogM0) { - m0_idx=up->resM0; + } else if (log_m0_av > up->maxLogM0) { + m0_idx = up->resM0; log_m0_av = up->maxLogM0; + } else { + m0_idx = (log_m0_av - up->minLogM0) / (up->dlogM0) + 1; } - else m0_idx = (log_m0_av - up->minLogM0)/(up->dlogM0)+1; - cell_center = (m0_idx - 0.5)*up->dlogM0 + up->minLogM0; - cell_vals_2d[1] = 2.0*(log_m0_av - cell_center)/up->dlogM0; // M0 value on cell interval + cell_center = (m0_idx - 0.5) * up->dlogM0 + up->minLogM0; + cell_vals_2d[1] = 2.0 * (log_m0_av - cell_center) / up->dlogM0; // M0 value on cell interval if ((m0_elc_av <= 0.) || (temp_elc_av <= 0.)) { - coef_recomb_d[0] = 0.0; - } - else { - double *recomb_dat_d = gkyl_array_fetch(up->recomb_data, gkyl_range_idx(&up->adas_rng, (int[2]) {t_idx,m0_idx})); + coef_recomb_d[0] = 0.0; + } else { + double *recomb_dat_d = + gkyl_array_fetch(up->recomb_data, gkyl_range_idx(&up->adas_rng, (int[2]){t_idx, m0_idx})); double adas_eval = up->adas_basis.eval_expand(cell_vals_2d, recomb_dat_d); - coef_recomb_d[0] = pow(10.0,adas_eval)/cell_av_fac; + coef_recomb_d[0] = pow(10.0, adas_eval) / cell_av_fac; } } //gkyl_grid_sub_array_write(&s->grid, &s->local, react->coef_react[i], "coef_recomb.gkyl"); @@ -213,11 +223,9 @@ void gkyl_dg_recomb_coll(const struct gkyl_dg_recomb *up, /* double *cflrate_d = gkyl_array_fetch(cflrate, cfl_idx); */ /* cflrate_d[0] += cflr; // frequencies are additive */ /* } */ - } -void -gkyl_dg_recomb_release(struct gkyl_dg_recomb* up) +void gkyl_dg_recomb_release(struct gkyl_dg_recomb *up) { gkyl_array_release(up->recomb_data); free(up); diff --git a/gyrokinetic/zero/dg_recomb_cu.cu b/gyrokinetic/zero/dg_recomb_cu.cu index e81b23d2bc..4da2fcfa97 100644 --- a/gyrokinetic/zero/dg_recomb_cu.cu +++ b/gyrokinetic/zero/dg_recomb_cu.cu @@ -12,82 +12,83 @@ extern "C" { #include } -__global__ static void -gkyl_recomb_react_rate_cu_ker(const struct gkyl_dg_recomb *up, - const struct gkyl_range conf_rng, const struct gkyl_range adas_rng, const struct gkyl_basis *adas_basis, - const struct gkyl_array *prim_vars_elc, struct gkyl_array *coef_recomb, - struct gkyl_array *recomb_data, double mass_elc, double elem_charge, - double maxLogTe, double minLogTe, double dlogTe, int resTe, - double maxLogM0, double minLogM0, double dlogM0, int resM0) +__global__ static void gkyl_recomb_react_rate_cu_ker( + const struct gkyl_dg_recomb *up, const struct gkyl_range conf_rng, + const struct gkyl_range adas_rng, const struct gkyl_basis *adas_basis, + const struct gkyl_array *prim_vars_elc, struct gkyl_array *coef_recomb, + struct gkyl_array *recomb_data, double mass_elc, double elem_charge, double maxLogTe, + double minLogTe, double dlogTe, int resTe, double maxLogM0, double minLogM0, double dlogM0, + int resM0 +) { int cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_rng.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_rng.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_rng, tid, cidx); long loc = gkyl_range_idx(&conf_rng, cidx); long nc = coef_recomb->ncomp; int cdim = conf_rng.ndim; - const double *prim_vars_elc_d = (const double*) gkyl_array_cfetch(prim_vars_elc, loc); - double *coef_recomb_d = (double*) gkyl_array_fetch(coef_recomb, loc); + const double *prim_vars_elc_d = (const double *)gkyl_array_cfetch(prim_vars_elc, loc); + double *coef_recomb_d = (double *)gkyl_array_fetch(coef_recomb, loc); //Find nearest neighbor for n, Te in ADAS interpolated data - double cell_av_fac = pow(1.0/sqrt(2.0),cdim); - double m0_elc_av = prim_vars_elc_d[0]*cell_av_fac; - double temp_elc_av = prim_vars_elc_d[2*nc]*cell_av_fac*mass_elc/elem_charge; + double cell_av_fac = pow(1.0 / sqrt(2.0), cdim); + double m0_elc_av = prim_vars_elc_d[0] * cell_av_fac; + double temp_elc_av = prim_vars_elc_d[2 * nc] * cell_av_fac * mass_elc / elem_charge; double log_Te_av = log10(temp_elc_av); double log_m0_av = log10(m0_elc_av); int m0_idx, t_idx; double cell_vals_2d[2]; double cell_center; - + if (log_Te_av < minLogTe) { - t_idx=1; + t_idx = 1; log_Te_av = minLogTe; - } - else if (log_Te_av > maxLogTe) { - t_idx=resTe; + } else if (log_Te_av > maxLogTe) { + t_idx = resTe; log_Te_av = maxLogTe; + } else { + t_idx = (log_Te_av - minLogTe) / (dlogTe) + 1; } - else t_idx = (log_Te_av - minLogTe)/(dlogTe)+1; - cell_center = (t_idx - 0.5)*dlogTe + minLogTe; - cell_vals_2d[0] = 2.0*(log_Te_av - cell_center)/dlogTe; // Te value on cell interval - + cell_center = (t_idx - 0.5) * dlogTe + minLogTe; + cell_vals_2d[0] = 2.0 * (log_Te_av - cell_center) / dlogTe; // Te value on cell interval + if (log_m0_av < minLogM0) { - m0_idx=1; + m0_idx = 1; log_m0_av = minLogM0; - } - else if (log_m0_av > maxLogM0) { - m0_idx=resM0; + } else if (log_m0_av > maxLogM0) { + m0_idx = resM0; log_m0_av = maxLogM0; + } else { + m0_idx = (log_m0_av - minLogM0) / (dlogM0) + 1; } - else m0_idx = (log_m0_av - minLogM0)/(dlogM0)+1; - cell_center = (m0_idx - 0.5)*dlogM0 + minLogM0; - cell_vals_2d[1] = 2.0*(log_m0_av - cell_center)/dlogM0; // M0 value on cell interval + cell_center = (m0_idx - 0.5) * dlogM0 + minLogM0; + cell_vals_2d[1] = 2.0 * (log_m0_av - cell_center) / dlogM0; // M0 value on cell interval int ad_idx[2] = {t_idx, m0_idx}; if ((m0_elc_av <= 0.) || (temp_elc_av <= 0.)) { coef_recomb_d[0] = 0.0; - } - else { - double *recomb_dat_d = (double*) gkyl_array_fetch(recomb_data, gkyl_range_idx(&adas_rng,ad_idx)); + } else { + double *recomb_dat_d = + (double *)gkyl_array_fetch(recomb_data, gkyl_range_idx(&adas_rng, ad_idx)); double adas_eval = adas_basis->eval_expand(cell_vals_2d, recomb_dat_d); - coef_recomb_d[0] = pow(10.0,adas_eval)/cell_av_fac; + coef_recomb_d[0] = pow(10.0, adas_eval) / cell_av_fac; } } } -void gkyl_dg_recomb_coll_cu(const struct gkyl_dg_recomb *up, - const struct gkyl_array *prim_vars_elc, - struct gkyl_array *coef_recomb, struct gkyl_array *cflrate) -{ - gkyl_recomb_react_rate_cu_ker<<conf_rng->nblocks, up->conf_rng->nthreads>>>(up->on_dev, - *up->conf_rng, up->adas_rng, up->basis_on_dev, - prim_vars_elc->on_dev, coef_recomb->on_dev, - up->recomb_data->on_dev, up->mass_elc, up->elem_charge, - up->maxLogTe, up->minLogTe, up->dlogTe, up->resTe, - up->maxLogM0, up->minLogM0, up->dlogM0, up->resM0); +void gkyl_dg_recomb_coll_cu( + const struct gkyl_dg_recomb *up, const struct gkyl_array *prim_vars_elc, + struct gkyl_array *coef_recomb, struct gkyl_array *cflrate +) +{ + gkyl_recomb_react_rate_cu_ker<<conf_rng->nblocks, up->conf_rng->nthreads> > >( + up->on_dev, *up->conf_rng, up->adas_rng, up->basis_on_dev, prim_vars_elc->on_dev, + coef_recomb->on_dev, up->recomb_data->on_dev, up->mass_elc, up->elem_charge, up->maxLogTe, + up->minLogTe, up->dlogTe, up->resTe, up->maxLogM0, up->minLogM0, up->dlogM0, up->resM0 + ); // cfl calculation //struct gkyl_range vel_rng; diff --git a/gyrokinetic/zero/dg_updater_diffusion_gyrokinetic.c b/gyrokinetic/zero/dg_updater_diffusion_gyrokinetic.c index b8eb73a318..cbc331d60b 100644 --- a/gyrokinetic/zero/dg_updater_diffusion_gyrokinetic.c +++ b/gyrokinetic/zero/dg_updater_diffusion_gyrokinetic.c @@ -10,56 +10,70 @@ #include #include -struct gkyl_dg_eqn* -gkyl_dg_updater_diffusion_gyrokinetic_acquire_eqn(const struct gkyl_dg_updater_diffusion_gyrokinetic *up) +struct gkyl_dg_eqn *gkyl_dg_updater_diffusion_gyrokinetic_acquire_eqn( + const struct gkyl_dg_updater_diffusion_gyrokinetic *up +) { return gkyl_dg_eqn_acquire(up->dgeqn); } -struct gkyl_dg_updater_diffusion_gyrokinetic* -gkyl_dg_updater_diffusion_gyrokinetic_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, - const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range, - const bool *is_zero_flux_bc, - const struct gkyl_array *coeff, const struct gkyl_array *jacobgeo_inv, bool use_gpu) +struct gkyl_dg_updater_diffusion_gyrokinetic *gkyl_dg_updater_diffusion_gyrokinetic_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_basis *cbasis, bool is_diff_const, const bool *diff_in_dir, int diff_order, + const struct gkyl_range *diff_range, const bool *is_zero_flux_bc, const struct gkyl_array *coeff, + const struct gkyl_array *jacobgeo_inv, bool use_gpu +) { - struct gkyl_dg_updater_diffusion_gyrokinetic *up = gkyl_malloc(sizeof(struct gkyl_dg_updater_diffusion_gyrokinetic)); + struct gkyl_dg_updater_diffusion_gyrokinetic *up = + gkyl_malloc(sizeof(struct gkyl_dg_updater_diffusion_gyrokinetic)); int pdim = basis->ndim; int cdim = cbasis->ndim; up->use_gpu = use_gpu; bool is_dir_diffusive[GKYL_MAX_CDIM]; - for (int d=0; ddgeqn = gkyl_dg_diffusion_gyrokinetic_new(basis, cbasis, is_diff_const, is_dir_diffusive, - diff_order, diff_range, up->use_gpu); + up->dgeqn = gkyl_dg_diffusion_gyrokinetic_new( + basis, cbasis, is_diff_const, is_dir_diffusive, diff_order, diff_range, up->use_gpu + ); - gkyl_dg_diffusion_gyrokinetic_set_auxfields(up->dgeqn, (struct gkyl_dg_diffusion_gyrokinetic_auxfields) { - .D = coeff, .jacobgeo_inv = jacobgeo_inv }); + gkyl_dg_diffusion_gyrokinetic_set_auxfields( + up->dgeqn, + (struct gkyl_dg_diffusion_gyrokinetic_auxfields){.D = coeff, .jacobgeo_inv = jacobgeo_inv} + ); int num_up_dirs = 0; - for (int d=0; dhyperdg = gkyl_hyper_dg_new(grid, basis, up->dgeqn, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu); + up->hyperdg = gkyl_hyper_dg_new( + grid, basis, up->dgeqn, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu + ); up->diffusion_tm = 0.0; return up; } -void -gkyl_dg_updater_diffusion_gyrokinetic_advance(struct gkyl_dg_updater_diffusion_gyrokinetic *up, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_diffusion_gyrokinetic_advance( + struct gkyl_dg_updater_diffusion_gyrokinetic *up, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(up->hyperdg, update_rng, fIn, cflrate, rhs); @@ -69,13 +83,10 @@ gkyl_dg_updater_diffusion_gyrokinetic_advance(struct gkyl_dg_updater_diffusion_g struct gkyl_dg_updater_diffusion_gyrokinetic_tm gkyl_dg_updater_diffusion_gyrokinetic_get_tm(const struct gkyl_dg_updater_diffusion_gyrokinetic *up) { - return (struct gkyl_dg_updater_diffusion_gyrokinetic_tm) { - .diffusion_tm = up->diffusion_tm, - }; + return (struct gkyl_dg_updater_diffusion_gyrokinetic_tm){.diffusion_tm = up->diffusion_tm}; } -void -gkyl_dg_updater_diffusion_gyrokinetic_release(struct gkyl_dg_updater_diffusion_gyrokinetic *up) +void gkyl_dg_updater_diffusion_gyrokinetic_release(struct gkyl_dg_updater_diffusion_gyrokinetic *up) { gkyl_dg_eqn_release(up->dgeqn); gkyl_hyper_dg_release(up->hyperdg); diff --git a/gyrokinetic/zero/dg_updater_gk_anomalous_diffusion.c b/gyrokinetic/zero/dg_updater_gk_anomalous_diffusion.c index 36e8fa523e..ccd6eebe3a 100644 --- a/gyrokinetic/zero/dg_updater_gk_anomalous_diffusion.c +++ b/gyrokinetic/zero/dg_updater_gk_anomalous_diffusion.c @@ -10,19 +10,22 @@ #include #include -struct gkyl_dg_eqn* -gkyl_dg_updater_gk_anomalous_diffusion_acquire_eqn(const struct gkyl_dg_updater_gk_anomalous_diffusion *up) +struct gkyl_dg_eqn *gkyl_dg_updater_gk_anomalous_diffusion_acquire_eqn( + const struct gkyl_dg_updater_gk_anomalous_diffusion *up +) { return gkyl_dg_eqn_acquire(up->dgeqn); } -struct gkyl_dg_updater_gk_anomalous_diffusion* -gkyl_dg_updater_gk_anomalous_diffusion_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, +struct gkyl_dg_updater_gk_anomalous_diffusion *gkyl_dg_updater_gk_anomalous_diffusion_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, enum gkyl_gyrokinetic_bc_type bc_x_lower, enum gkyl_gyrokinetic_bc_type bc_x_upper, - const struct gkyl_array *nu, const struct gkyl_array *jacobgeo_inv, bool use_gpu) + const struct gkyl_array *nu, const struct gkyl_array *jacobgeo_inv, bool use_gpu +) { - struct gkyl_dg_updater_gk_anomalous_diffusion *up = gkyl_malloc(sizeof(struct gkyl_dg_updater_gk_anomalous_diffusion)); + struct gkyl_dg_updater_gk_anomalous_diffusion *up = + gkyl_malloc(sizeof(struct gkyl_dg_updater_gk_anomalous_diffusion)); int pdim = basis->ndim; int cdim = cbasis->ndim; @@ -41,56 +44,60 @@ gkyl_dg_updater_gk_anomalous_diffusion_new(const struct gkyl_rect_grid *grid, // ZERO_FLUX: zero_flux N/A yes // ELSE: local local yes - up->dgeqn = gkyl_gk_anomalous_diffusion_new(basis, cbasis, - conf_range, bc_x_lower, bc_x_upper, up->use_gpu); + up->dgeqn = + gkyl_gk_anomalous_diffusion_new(basis, cbasis, conf_range, bc_x_lower, bc_x_upper, up->use_gpu); - gkyl_gk_anomalous_diffusion_set_auxfields(up->dgeqn, - (struct gkyl_gk_anomalous_diffusion_auxfields) {.nu = nu, .jacobgeo_inv = jacobgeo_inv }); + gkyl_gk_anomalous_diffusion_set_auxfields( + up->dgeqn, + (struct gkyl_gk_anomalous_diffusion_auxfields){.nu = nu, .jacobgeo_inv = jacobgeo_inv} + ); int num_up_dirs = 1; int up_dirs[GKYL_MAX_DIM]; up_dirs[0] = 0; // Determine if hyper_dg should apply boundary_surf kernels. - int use_boundary_surf[2*GKYL_MAX_DIM] = {0}; - if ( !((bc_x_lower == GKYL_BC_GK_SKIP) || - (bc_x_lower == GKYL_BC_GK_SPECIES_ABSORB) || - (bc_x_lower == GKYL_BC_GK_SPECIES_PERIODIC) || - (bc_x_lower == GKYL_BC_GK_SPECIES_FIXED_FUNC)) ) - use_boundary_surf[0] = 1; - if ( !((bc_x_upper == GKYL_BC_GK_SKIP) || - (bc_x_upper == GKYL_BC_GK_SPECIES_ABSORB) || - (bc_x_upper == GKYL_BC_GK_SPECIES_PERIODIC) || - (bc_x_upper == GKYL_BC_GK_SPECIES_FIXED_FUNC)) ) - use_boundary_surf[0+pdim] = 1; + int use_boundary_surf[2 * GKYL_MAX_DIM] = {0}; + if (!((bc_x_lower == GKYL_BC_GK_SKIP) || (bc_x_lower == GKYL_BC_GK_SPECIES_ABSORB) || + (bc_x_lower == GKYL_BC_GK_SPECIES_PERIODIC) || + (bc_x_lower == GKYL_BC_GK_SPECIES_FIXED_FUNC))) { + use_boundary_surf[0] = 1; + } + if (!((bc_x_upper == GKYL_BC_GK_SKIP) || (bc_x_upper == GKYL_BC_GK_SPECIES_ABSORB) || + (bc_x_upper == GKYL_BC_GK_SPECIES_PERIODIC) || + (bc_x_upper == GKYL_BC_GK_SPECIES_FIXED_FUNC))) { + use_boundary_surf[0 + pdim] = 1; + } - up->hyperdg = gkyl_hyper_dg_new(grid, basis, up->dgeqn, num_up_dirs, up_dirs, use_boundary_surf, 1, up->use_gpu); + up->hyperdg = gkyl_hyper_dg_new( + grid, basis, up->dgeqn, num_up_dirs, up_dirs, use_boundary_surf, 1, up->use_gpu + ); up->diffusion_tm = 0.0; return up; } -void -gkyl_dg_updater_gk_anomalous_diffusion_advance(struct gkyl_dg_updater_gk_anomalous_diffusion *up, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_gk_anomalous_diffusion_advance( + struct gkyl_dg_updater_gk_anomalous_diffusion *up, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(up->hyperdg, update_rng, fIn, cflrate, rhs); up->diffusion_tm += gkyl_time_diff_now_sec(wst); } -struct gkyl_dg_updater_gk_anomalous_diffusion_tm -gkyl_dg_updater_gk_anomalous_diffusion_get_tm(const struct gkyl_dg_updater_gk_anomalous_diffusion *up) +struct gkyl_dg_updater_gk_anomalous_diffusion_tm gkyl_dg_updater_gk_anomalous_diffusion_get_tm( + const struct gkyl_dg_updater_gk_anomalous_diffusion *up +) { - return (struct gkyl_dg_updater_gk_anomalous_diffusion_tm) { - .diffusion_tm = up->diffusion_tm, - }; + return (struct gkyl_dg_updater_gk_anomalous_diffusion_tm){.diffusion_tm = up->diffusion_tm}; } -void -gkyl_dg_updater_gk_anomalous_diffusion_release(struct gkyl_dg_updater_gk_anomalous_diffusion *up) +void gkyl_dg_updater_gk_anomalous_diffusion_release(struct gkyl_dg_updater_gk_anomalous_diffusion *up +) { gkyl_dg_eqn_release(up->dgeqn); gkyl_hyper_dg_release(up->hyperdg); diff --git a/gyrokinetic/zero/dg_updater_gyrokinetic.c b/gyrokinetic/zero/dg_updater_gyrokinetic.c index bffe17f9c6..8dd4179c95 100644 --- a/gyrokinetic/zero/dg_updater_gyrokinetic.c +++ b/gyrokinetic/zero/dg_updater_gyrokinetic.c @@ -9,56 +9,63 @@ #include #include -struct gkyl_dg_eqn* -gkyl_dg_updater_gyrokinetic_acquire_eqn(const gkyl_dg_updater_gyrokinetic* gyrokinetic) +struct gkyl_dg_eqn * +gkyl_dg_updater_gyrokinetic_acquire_eqn(const gkyl_dg_updater_gyrokinetic *gyrokinetic) { return gkyl_dg_eqn_acquire(gyrokinetic->eqn_gyrokinetic); } -struct gkyl_dg_updater_gyrokinetic* -gkyl_dg_updater_gyrokinetic_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const bool *is_zero_flux_bc, double charge, double mass, - enum gkyl_gk_collisionless_type collless_type, const struct gk_geometry *gk_geom, - const struct gkyl_velocity_map *vel_map, void *aux_inp, bool use_gpu) +struct gkyl_dg_updater_gyrokinetic *gkyl_dg_updater_gyrokinetic_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const bool *is_zero_flux_bc, double charge, double mass, + enum gkyl_gk_collisionless_type collless_type, const struct gk_geometry *gk_geom, + const struct gkyl_velocity_map *vel_map, void *aux_inp, bool use_gpu +) { struct gkyl_dg_updater_gyrokinetic *up = gkyl_malloc(sizeof(struct gkyl_dg_updater_gyrokinetic)); up->use_gpu = use_gpu; - up->eqn_gyrokinetic = gkyl_dg_gyrokinetic_new(cbasis, pbasis, conf_range, phase_range, - charge, mass, collless_type, gk_geom, vel_map, up->use_gpu); + up->eqn_gyrokinetic = gkyl_dg_gyrokinetic_new( + cbasis, pbasis, conf_range, phase_range, charge, mass, collless_type, gk_geom, vel_map, + up->use_gpu + ); struct gkyl_dg_gyrokinetic_auxfields *gk_inp = aux_inp; gkyl_gyrokinetic_set_auxfields(up->eqn_gyrokinetic, *gk_inp); int cdim = cbasis->ndim, pdim = pbasis->ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int up_dirs[GKYL_MAX_DIM] = {0}; - int num_up_dirs = cdim+1; - for (int d=0; dup_gyrokinetic = gkyl_hyper_dg_new(grid, pbasis, up->eqn_gyrokinetic, - num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu); + up->up_gyrokinetic = gkyl_hyper_dg_new( + grid, pbasis, up->eqn_gyrokinetic, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu + ); up->gyrokinetic_tm = 0.0; - + return up; } -void -gkyl_dg_updater_gyrokinetic_advance(struct gkyl_dg_updater_gyrokinetic *gyrokinetic, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_gyrokinetic_advance( + struct gkyl_dg_updater_gyrokinetic *gyrokinetic, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(gyrokinetic->up_gyrokinetic, update_rng, fIn, cflrate, rhs); @@ -68,13 +75,10 @@ gkyl_dg_updater_gyrokinetic_advance(struct gkyl_dg_updater_gyrokinetic *gyrokine struct gkyl_dg_updater_gyrokinetic_tm gkyl_dg_updater_gyrokinetic_get_tm(const gkyl_dg_updater_gyrokinetic *gyrokinetic) { - return (struct gkyl_dg_updater_gyrokinetic_tm) { - .gyrokinetic_tm = gyrokinetic->gyrokinetic_tm, - }; + return (struct gkyl_dg_updater_gyrokinetic_tm){.gyrokinetic_tm = gyrokinetic->gyrokinetic_tm}; } -void -gkyl_dg_updater_gyrokinetic_release(struct gkyl_dg_updater_gyrokinetic* gyrokinetic) +void gkyl_dg_updater_gyrokinetic_release(struct gkyl_dg_updater_gyrokinetic *gyrokinetic) { gkyl_dg_eqn_release(gyrokinetic->eqn_gyrokinetic); gkyl_hyper_dg_release(gyrokinetic->up_gyrokinetic); diff --git a/gyrokinetic/zero/dg_updater_gyrokinetic_passive.c b/gyrokinetic/zero/dg_updater_gyrokinetic_passive.c index efdab7a4ff..0c6128bb68 100644 --- a/gyrokinetic/zero/dg_updater_gyrokinetic_passive.c +++ b/gyrokinetic/zero/dg_updater_gyrokinetic_passive.c @@ -9,21 +9,19 @@ #include #include -struct gkyl_dg_eqn* -gkyl_dg_updater_gyrokinetic_passive_acquire_eqn(const gkyl_dg_updater_gyrokinetic_passive* up) +struct gkyl_dg_eqn * +gkyl_dg_updater_gyrokinetic_passive_acquire_eqn(const gkyl_dg_updater_gyrokinetic_passive *up) { return gkyl_dg_eqn_acquire(up->eqn_gyrokinetic_passive); } -gkyl_dg_updater_gyrokinetic_passive* -gkyl_dg_updater_gyrokinetic_passive_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const bool *is_zero_flux_bc, - const double charge, const double mass, - const struct gk_geometry *gk_geom, - const struct gkyl_velocity_map *vel_map, - void *aux_inp, bool use_gpu) +gkyl_dg_updater_gyrokinetic_passive *gkyl_dg_updater_gyrokinetic_passive_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const bool *is_zero_flux_bc, const double charge, + const double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, + void *aux_inp, bool use_gpu +) { struct gkyl_dg_updater_gyrokinetic_passive *up = gkyl_malloc(sizeof(struct gkyl_dg_updater_gyrokinetic_passive)); @@ -31,8 +29,9 @@ gkyl_dg_updater_gyrokinetic_passive_new(const struct gkyl_rect_grid *grid, up->use_gpu = use_gpu; // Create the passive GK equation object. - up->eqn_gyrokinetic_passive = gkyl_dg_gyrokinetic_passive_new(cbasis, pbasis, conf_range, phase_range, - charge, mass, gk_geom, vel_map, use_gpu); + up->eqn_gyrokinetic_passive = gkyl_dg_gyrokinetic_passive_new( + cbasis, pbasis, conf_range, phase_range, charge, mass, gk_geom, vel_map, use_gpu + ); // Set auxiliary fields. struct gkyl_dg_gyrokinetic_passive_auxfields *gkp_inp = aux_inp; @@ -44,29 +43,33 @@ gkyl_dg_updater_gyrokinetic_passive_new(const struct gkyl_rect_grid *grid, // Update only conf-space directions (no vpar advection for passive type). int up_dirs[GKYL_MAX_DIM] = {0}; int num_up_dirs = cdim; - for (int d = 0; d < num_up_dirs; d++) up_dirs[d] = d; + for (int d = 0; d < num_up_dirs; d++) { + up_dirs[d] = d; + } // Zero-flux flags: conf-space BCs from input. - int zero_flux_flags[2*GKYL_MAX_DIM] = {0}; + int zero_flux_flags[2 * GKYL_MAX_DIM] = {0}; for (int d = 0; d < cdim; d++) { - zero_flux_flags[d] = is_zero_flux_bc[d] ? 1 : 0; - zero_flux_flags[d+pdim] = is_zero_flux_bc[d+pdim] ? 1 : 0; + zero_flux_flags[d] = is_zero_flux_bc[d] ? 1 : 0; + zero_flux_flags[d + pdim] = is_zero_flux_bc[d + pdim] ? 1 : 0; + } + for (int d = cdim; d < pdim; d++) { + zero_flux_flags[d] = zero_flux_flags[d + pdim] = 1; // zero-flux BCs in vel-space } - for (int d = cdim; d < pdim; d++) - zero_flux_flags[d] = zero_flux_flags[d+pdim] = 1; // zero-flux BCs in vel-space - up->up_gyrokinetic_passive = gkyl_hyper_dg_new(grid, pbasis, up->eqn_gyrokinetic_passive, - num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu); + up->up_gyrokinetic_passive = gkyl_hyper_dg_new( + grid, pbasis, up->eqn_gyrokinetic_passive, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu + ); up->gyrokinetic_passive_tm = 0.0; return up; } -void -gkyl_dg_updater_gyrokinetic_passive_advance(gkyl_dg_updater_gyrokinetic_passive *up, - const struct gkyl_range *update_rng, const struct gkyl_array *fIn, - struct gkyl_array *cflrate, struct gkyl_array *rhs) +void gkyl_dg_updater_gyrokinetic_passive_advance( + gkyl_dg_updater_gyrokinetic_passive *up, const struct gkyl_range *update_rng, + const struct gkyl_array *fIn, struct gkyl_array *cflrate, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(up->up_gyrokinetic_passive, update_rng, fIn, cflrate, rhs); @@ -76,13 +79,11 @@ gkyl_dg_updater_gyrokinetic_passive_advance(gkyl_dg_updater_gyrokinetic_passive struct gkyl_dg_updater_gyrokinetic_passive_tm gkyl_dg_updater_gyrokinetic_passive_get_tm(const gkyl_dg_updater_gyrokinetic_passive *up) { - return (struct gkyl_dg_updater_gyrokinetic_passive_tm) { - .gyrokinetic_passive_tm = up->gyrokinetic_passive_tm, - }; + return (struct gkyl_dg_updater_gyrokinetic_passive_tm + ){.gyrokinetic_passive_tm = up->gyrokinetic_passive_tm}; } -void -gkyl_dg_updater_gyrokinetic_passive_release(gkyl_dg_updater_gyrokinetic_passive *up) +void gkyl_dg_updater_gyrokinetic_passive_release(gkyl_dg_updater_gyrokinetic_passive *up) { gkyl_dg_eqn_release(up->eqn_gyrokinetic_passive); gkyl_hyper_dg_release(up->up_gyrokinetic_passive); diff --git a/gyrokinetic/zero/dg_updater_lbo_gyrokinetic.c b/gyrokinetic/zero/dg_updater_lbo_gyrokinetic.c index cc370fc918..329dac2a0a 100644 --- a/gyrokinetic/zero/dg_updater_lbo_gyrokinetic.c +++ b/gyrokinetic/zero/dg_updater_lbo_gyrokinetic.c @@ -11,49 +11,59 @@ #include #include -struct gkyl_dg_updater_collisions* -gkyl_dg_updater_lbo_gyrokinetic_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, - struct gkyl_dg_lbo_gyrokinetic_drag_auxfields *drag_inp, struct gkyl_dg_lbo_gyrokinetic_diff_auxfields *diff_inp, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, - bool use_gpu) +struct gkyl_dg_updater_collisions *gkyl_dg_updater_lbo_gyrokinetic_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, + struct gkyl_dg_lbo_gyrokinetic_drag_auxfields *drag_inp, + struct gkyl_dg_lbo_gyrokinetic_diff_auxfields *diff_inp, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu +) { struct gkyl_dg_updater_collisions *up = gkyl_malloc(sizeof(gkyl_dg_updater_collisions)); up->use_gpu = use_gpu; - up->coll_drag = gkyl_dg_lbo_gyrokinetic_drag_new(conf_basis, phase_basis, conf_range, - phase_grid, mass, gk_geom, vel_map, up->use_gpu); + up->coll_drag = gkyl_dg_lbo_gyrokinetic_drag_new( + conf_basis, phase_basis, conf_range, phase_grid, mass, gk_geom, vel_map, up->use_gpu + ); gkyl_lbo_gyrokinetic_drag_set_auxfields(up->coll_drag, *drag_inp); - up->coll_diff = gkyl_dg_lbo_gyrokinetic_diff_new(conf_basis, phase_basis, conf_range, - phase_grid, mass, gk_geom, vel_map, up->use_gpu); + up->coll_diff = gkyl_dg_lbo_gyrokinetic_diff_new( + conf_basis, phase_basis, conf_range, phase_grid, mass, gk_geom, vel_map, up->use_gpu + ); gkyl_lbo_gyrokinetic_diff_set_auxfields(up->coll_diff, *diff_inp); int cdim = conf_basis->ndim, pdim = phase_basis->ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int num_up_dirs = vdim; - int up_dirs[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim - vdim; + } - int zero_flux_flags[2*GKYL_MAX_DIM] = { 0 }; - for (int d=cdim; ddrag = gkyl_hyper_dg_new(phase_grid, phase_basis, up->coll_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu); - up->diff = gkyl_hyper_dg_new(phase_grid, phase_basis, up->coll_diff, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu); + int zero_flux_flags[2 * GKYL_MAX_DIM] = {0}; + for (int d = cdim; d < pdim; ++d) { + zero_flux_flags[d] = zero_flux_flags[d + pdim] = 1; + } - up->diff_tm = 0.0; + up->drag = gkyl_hyper_dg_new( + phase_grid, phase_basis, up->coll_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu + ); + up->diff = gkyl_hyper_dg_new( + phase_grid, phase_basis, up->coll_diff, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu + ); + + up->diff_tm = 0.0; up->drag_tm = 0.0; - + return up; } -void -gkyl_dg_updater_lbo_gyrokinetic_advance(struct gkyl_dg_updater_collisions *lbo, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_lbo_gyrokinetic_advance( + struct gkyl_dg_updater_collisions *lbo, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(lbo->drag, update_rng, fIn, cflrate, rhs); @@ -67,14 +77,11 @@ gkyl_dg_updater_lbo_gyrokinetic_advance(struct gkyl_dg_updater_collisions *lbo, struct gkyl_dg_updater_lbo_gyrokinetic_tm gkyl_dg_updater_lbo_gyrokinetic_get_tm(const gkyl_dg_updater_collisions *coll) { - return (struct gkyl_dg_updater_lbo_gyrokinetic_tm) { - .drag_tm = coll->drag_tm, - .diff_tm = coll->diff_tm - }; + return (struct gkyl_dg_updater_lbo_gyrokinetic_tm + ){.drag_tm = coll->drag_tm, .diff_tm = coll->diff_tm}; } -void -gkyl_dg_updater_lbo_gyrokinetic_release(gkyl_dg_updater_collisions* coll) +void gkyl_dg_updater_lbo_gyrokinetic_release(gkyl_dg_updater_collisions *coll) { gkyl_dg_eqn_release(coll->coll_drag); gkyl_dg_eqn_release(coll->coll_diff); diff --git a/gyrokinetic/zero/dg_updater_moment_gyrokinetic.c b/gyrokinetic/zero/dg_updater_moment_gyrokinetic.c index e5ec10ae77..b72fa1ef12 100644 --- a/gyrokinetic/zero/dg_updater_moment_gyrokinetic.c +++ b/gyrokinetic/zero/dg_updater_moment_gyrokinetic.c @@ -10,63 +10,66 @@ #include #include -struct gkyl_mom_type* -gkyl_dg_updater_moment_gyrokinetic_acquire_type(const gkyl_dg_updater_moment* moment) +struct gkyl_mom_type * +gkyl_dg_updater_moment_gyrokinetic_acquire_type(const gkyl_dg_updater_moment *moment) { return gkyl_mom_type_acquire(moment->type); } -int -gkyl_dg_updater_moment_gyrokinetic_num_mom(const gkyl_dg_updater_moment* moment) +int gkyl_dg_updater_moment_gyrokinetic_num_mom(const gkyl_dg_updater_moment *moment) { return gkyl_mom_type_num_mom(moment->type); } -struct gkyl_dg_updater_moment* -gkyl_dg_updater_moment_gyrokinetic_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *conf_range, double mass, double charge, - const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, - struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool is_integrated, bool use_gpu) +struct gkyl_dg_updater_moment *gkyl_dg_updater_moment_gyrokinetic_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, double mass, + double charge, const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, + struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool is_integrated, bool use_gpu +) { gkyl_dg_updater_moment *up = gkyl_malloc(sizeof(gkyl_dg_updater_moment)); up->use_gpu = use_gpu; - if (is_integrated) - up->type = gkyl_int_mom_gyrokinetic_new(conf_basis, phase_basis, conf_range, mass, charge, vel_map, gk_geom, phi, mom_type, use_gpu); - else - up->type = gkyl_mom_gyrokinetic_new(conf_basis, phase_basis, conf_range, mass, charge, vel_map, gk_geom, phi, mom_type, use_gpu); + if (is_integrated) { + up->type = gkyl_int_mom_gyrokinetic_new( + conf_basis, phase_basis, conf_range, mass, charge, vel_map, gk_geom, phi, mom_type, use_gpu + ); + } else { + up->type = gkyl_mom_gyrokinetic_new( + conf_basis, phase_basis, conf_range, mass, charge, vel_map, gk_geom, phi, mom_type, use_gpu + ); + } up->up_moment = gkyl_mom_calc_new(grid, up->type, use_gpu); up->moment_tm = 0.0; - + return up; } -void -gkyl_dg_updater_moment_gyrokinetic_advance(struct gkyl_dg_updater_moment *moment, - const struct gkyl_range *update_phase_rng, const struct gkyl_range *update_conf_rng, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT mout) -{ +void gkyl_dg_updater_moment_gyrokinetic_advance( + struct gkyl_dg_updater_moment *moment, const struct gkyl_range *update_phase_rng, + const struct gkyl_range *update_conf_rng, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT mout +) +{ struct timespec wst = gkyl_wall_clock(); - if (moment->use_gpu) + if (moment->use_gpu) { gkyl_mom_calc_advance_cu(moment->up_moment, update_phase_rng, update_conf_rng, fIn, mout); - else + } else { gkyl_mom_calc_advance(moment->up_moment, update_phase_rng, update_conf_rng, fIn, mout); + } moment->moment_tm += gkyl_time_diff_now_sec(wst); } struct gkyl_dg_updater_moment_tm gkyl_dg_updater_moment_gyrokinetic_get_tm(const gkyl_dg_updater_moment *moment) { - return (struct gkyl_dg_updater_moment_tm) { - .moment_tm = moment->moment_tm, - }; + return (struct gkyl_dg_updater_moment_tm){.moment_tm = moment->moment_tm}; } -void -gkyl_dg_updater_moment_gyrokinetic_release(gkyl_dg_updater_moment* moment) +void gkyl_dg_updater_moment_gyrokinetic_release(gkyl_dg_updater_moment *moment) { gkyl_mom_type_release(moment->type); gkyl_mom_calc_release(moment->up_moment); diff --git a/gyrokinetic/zero/dg_updater_rad_gyrokinetic.c b/gyrokinetic/zero/dg_updater_rad_gyrokinetic.c index a8230b4fe5..830b97fb2a 100644 --- a/gyrokinetic/zero/dg_updater_rad_gyrokinetic.c +++ b/gyrokinetic/zero/dg_updater_rad_gyrokinetic.c @@ -10,41 +10,48 @@ #include #include -struct gkyl_dg_updater_collisions* -gkyl_dg_updater_rad_gyrokinetic_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_velocity_map *vel_map, void *aux_inp, bool use_gpu) +struct gkyl_dg_updater_collisions *gkyl_dg_updater_rad_gyrokinetic_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_velocity_map *vel_map, void *aux_inp, + bool use_gpu +) { - struct gkyl_dg_updater_collisions *up = gkyl_malloc(sizeof(gkyl_dg_updater_collisions)); up->use_gpu = use_gpu; - up->coll_drag = gkyl_dg_rad_gyrokinetic_drag_new(conf_basis, phase_basis, phase_range, conf_range, vel_map, use_gpu); + up->coll_drag = gkyl_dg_rad_gyrokinetic_drag_new( + conf_basis, phase_basis, phase_range, conf_range, vel_map, use_gpu + ); struct gkyl_dg_rad_gyrokinetic_auxfields *rad_inp = aux_inp; gkyl_rad_gyrokinetic_drag_set_auxfields(up->coll_drag, *rad_inp); int cdim = conf_basis->ndim, pdim = phase_basis->ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int num_up_dirs = vdim; - int up_dirs[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim - vdim; + } + + int zero_flux_flags[2 * GKYL_MAX_DIM] = {0}; + for (int d = cdim; d < pdim; ++d) { + zero_flux_flags[d] = zero_flux_flags[d + pdim] = 1; + } - int zero_flux_flags[2*GKYL_MAX_DIM] = { 0 }; - for (int d=cdim; ddrag = gkyl_hyper_dg_new( + grid, phase_basis, up->coll_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu + ); - up->drag = gkyl_hyper_dg_new(grid, phase_basis, up->coll_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu); - up->drag_tm = 0.0; - + return up; } -void -gkyl_dg_updater_rad_gyrokinetic_advance(struct gkyl_dg_updater_collisions *rad, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_rad_gyrokinetic_advance( + struct gkyl_dg_updater_collisions *rad, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(rad->drag, update_rng, fIn, cflrate, rhs); @@ -54,13 +61,10 @@ gkyl_dg_updater_rad_gyrokinetic_advance(struct gkyl_dg_updater_collisions *rad, struct gkyl_dg_updater_rad_gyrokinetic_tm gkyl_dg_updater_rad_gyrokinetic_get_tm(const struct gkyl_dg_updater_collisions *coll) { - return (struct gkyl_dg_updater_rad_gyrokinetic_tm) { - .drag_tm = coll->drag_tm - }; + return (struct gkyl_dg_updater_rad_gyrokinetic_tm){.drag_tm = coll->drag_tm}; } -void -gkyl_dg_updater_rad_gyrokinetic_release(struct gkyl_dg_updater_collisions* coll) +void gkyl_dg_updater_rad_gyrokinetic_release(struct gkyl_dg_updater_collisions *coll) { gkyl_dg_eqn_release(coll->coll_drag); gkyl_hyper_dg_release(coll->drag); diff --git a/gyrokinetic/zero/efit.c b/gyrokinetic/zero/efit.c index 43032d01e3..0d22b6331b 100644 --- a/gyrokinetic/zero/efit.c +++ b/gyrokinetic/zero/efit.c @@ -16,7 +16,7 @@ #include #include -gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) +gkyl_efit *gkyl_efit_new(const struct gkyl_efit_inp *inp) { gkyl_efit *up = gkyl_calloc(1, sizeof(struct gkyl_efit)); @@ -28,14 +28,14 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) gkyl_cart_modal_tensor(&up->rzbasis_cubic, 2, 3); gkyl_cart_modal_serendip(&up->fluxbasis, 1, inp->flux_poly_order); gkyl_cart_modal_tensor(&up->rzbasis, 2, inp->rz_poly_order); - + // Check if file exists using gkyl_check_file_exists and handle error only on rank 0. if (!gkyl_check_file_exists(up->filepath)) { fprintf(stderr, "efit.c: Failed to open the eqdsk file: %s\n", up->filepath); assert(false); } - FILE *ptr = fopen(up->filepath,"r"); + FILE *ptr = fopen(up->filepath, "r"); // Read the last two ints in the first line, assuming they are N_R and N_Z. int MAX_LINE_LENGTH = 256; @@ -75,11 +75,12 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) // rmaxis,zmaxis,simag,sibry,bcentr; // current,simag,xdum,rmaxis,xdum; // zmaxis,xdum,sibry,xdum,xdum; - size_t status = fscanf(ptr,"%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", - &up->rdim, &up->zdim, &up->rcentr, &up->rleft, &up->zmid, &up-> rmaxis, &up->zmaxis, - &up->simag, &up->sibry, &up->bcentr, &up-> current, &up->simag, &up->xdum, &up->rmaxis, - &up->xdum, &up-> zmaxis, &up->xdum, &up->sibry, &up->xdum, &up->xdum); - + size_t status = fscanf( + ptr, "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", &up->rdim, &up->zdim, + &up->rcentr, &up->rleft, &up->zmid, &up->rmaxis, &up->zmaxis, &up->simag, &up->sibry, + &up->bcentr, &up->current, &up->simag, &up->xdum, &up->rmaxis, &up->xdum, &up->zmaxis, + &up->xdum, &up->sibry, &up->xdum, &up->xdum + ); // Set zmid to 0 for double null if (up->reflect) { @@ -87,32 +88,33 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) up->zmaxis = 0.0; } - // Now we need to make the grid - up->zmin = up->zmid - up->zdim/2; - up->zmax = up->zmid + up->zdim/2; + up->zmin = up->zmid - up->zdim / 2; + up->zmax = up->zmid + up->zdim / 2; up->rmin = up->rleft; - up->rmax = up->rleft+up->rdim; + up->rmax = up->rleft + up->rdim; - double rzlower[2] = {up->rmin, up->zmin }; + double rzlower[2] = {up->rmin, up->zmin}; double rzupper[2] = {up->rmax, up->zmax}; int rzcells[2] = {0}; - int rzghost[2] = {1,1}; - if(up->rzbasis.poly_order==1){ - rzcells[0] = up->nr-1; - rzcells[1]= up->nz-1; + int rzghost[2] = {1, 1}; + if (up->rzbasis.poly_order == 1) { + rzcells[0] = up->nr - 1; + rzcells[1] = up->nz - 1; } - if(up->rzbasis.poly_order==2){ - rzcells[0] = (up->nr-1)/2; - rzcells[1] = (up->nz-1)/2; + if (up->rzbasis.poly_order == 2) { + rzcells[0] = (up->nr - 1) / 2; + rzcells[1] = (up->nz - 1) / 2; } gkyl_rect_grid_init(&up->rzgrid, 2, rzlower, rzupper, rzcells); gkyl_create_grid_ranges(&up->rzgrid, rzghost, &up->rzlocal_ext, &up->rzlocal); - int cells_cubic[2] = {up->nr-1, up->nz-1}; - int rzghost_cubic[2] = {0,0}; + int cells_cubic[2] = {up->nr - 1, up->nz - 1}; + int rzghost_cubic[2] = {0, 0}; gkyl_rect_grid_init(&up->rzgrid_cubic, 2, rzlower, rzupper, cells_cubic); - gkyl_create_grid_ranges(&up->rzgrid_cubic, rzghost_cubic, &up->rzlocal_cubic_ext, &up->rzlocal_cubic); + gkyl_create_grid_ranges( + &up->rzgrid_cubic, rzghost_cubic, &up->rzlocal_cubic_ext, &up->rzlocal_cubic + ); double fluxlower[1]; double fluxupper[1]; @@ -121,20 +123,19 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) step_convention = true; fluxlower[0] = up->sibry; fluxupper[0] = up->simag; - } - else { + } else { step_convention = false; fluxlower[0] = up->simag; fluxupper[0] = up->sibry; } int fluxcells[1] = {0}; - int fluxghost[2] = {1,1}; - if (up->fluxbasis.poly_order==1){ - fluxcells[0] = up->nr-1; + int fluxghost[2] = {1, 1}; + if (up->fluxbasis.poly_order == 1) { + fluxcells[0] = up->nr - 1; } - if (up->fluxbasis.poly_order==2){ - fluxcells[0] = (up->nr-1)/2; + if (up->fluxbasis.poly_order == 2) { + fluxcells[0] = (up->nr - 1) / 2; } gkyl_rect_grid_init(&up->fluxgrid, 1, fluxlower, fluxupper, fluxcells); @@ -142,10 +143,12 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) // allocate the necessary arrays up->psizr = gkyl_array_new(GKYL_DOUBLE, up->rzbasis.num_basis, up->rzlocal_ext.volume); - up->psizr_cubic = gkyl_array_new(GKYL_DOUBLE, up->rzbasis_cubic.num_basis, up->rzlocal_cubic_ext.volume); + up->psizr_cubic = + gkyl_array_new(GKYL_DOUBLE, up->rzbasis_cubic.num_basis, up->rzlocal_cubic_ext.volume); up->bmagzr = gkyl_array_new(GKYL_DOUBLE, up->rzbasis.num_basis, up->rzlocal_ext.volume); up->fpolflux = gkyl_array_new(GKYL_DOUBLE, up->fluxbasis.num_basis, up->fluxlocal_ext.volume); - up->fpolprimeflux = gkyl_array_new(GKYL_DOUBLE, up->fluxbasis.num_basis, up->fluxlocal_ext.volume); + up->fpolprimeflux = + gkyl_array_new(GKYL_DOUBLE, up->fluxbasis.num_basis, up->fluxlocal_ext.volume); up->qflux = gkyl_array_new(GKYL_DOUBLE, up->fluxbasis.num_basis, up->fluxlocal_ext.volume); // Read fpol because we do want that @@ -156,30 +159,31 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) int fidx[1]; // fpol is given on a uniform flux grid from the magnetic axis to plasma boundary if (step_convention) { - for (int i = up->nr-1; i>=0; i--){ + for (int i = up->nr - 1; i >= 0; i--) { fidx[0] = i; - double *fpol_n= gkyl_array_fetch(fpolflux_n, gkyl_range_idx(&flux_nrange, fidx)); - status = fscanf(ptr,"%lf", fpol_n); + double *fpol_n = gkyl_array_fetch(fpolflux_n, gkyl_range_idx(&flux_nrange, fidx)); + status = fscanf(ptr, "%lf", fpol_n); } - } - else { - for(int i = 0; inr; i++){ + } else { + for (int i = 0; i < up->nr; i++) { fidx[0] = i; - double *fpol_n= gkyl_array_fetch(fpolflux_n, gkyl_range_idx(&flux_nrange, fidx)); - status = fscanf(ptr,"%lf", fpol_n); + double *fpol_n = gkyl_array_fetch(fpolflux_n, gkyl_range_idx(&flux_nrange, fidx)); + status = fscanf(ptr, "%lf", fpol_n); } } struct gkyl_nodal_ops *n2m_flux = gkyl_nodal_ops_new(&up->fluxbasis, &up->fluxgrid, false); - gkyl_nodal_ops_n2m(n2m_flux, &up->fluxbasis, &up->fluxgrid, - &flux_nrange, &up->fluxlocal, 1, fpolflux_n, up->fpolflux, false); + gkyl_nodal_ops_n2m( + n2m_flux, &up->fluxbasis, &up->fluxgrid, &flux_nrange, &up->fluxlocal, 1, fpolflux_n, + up->fpolflux, false + ); // Now we have 3 of the 1d arrays, all of length nr : // pres, ffprim, pprime // I don't actually care about pres or pprime, so skip those //skip pres - for(int i = 0; inr; i++){ + for (int i = 0; i < up->nr; i++) { status = fscanf(ptr, "%lf", &up->xdum); } @@ -187,28 +191,29 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) struct gkyl_array *fpolprimeflux_n = gkyl_array_new(GKYL_DOUBLE, 1, flux_nrange.volume); // fpol*fpolprime is given on a uniform flux grid from the magnetic axis to plasma boundary if (step_convention) { - for (int i = up->nr-1; i>=0; i--){ + for (int i = up->nr - 1; i >= 0; i--) { fidx[0] = i; double *fpolprime_n = gkyl_array_fetch(fpolprimeflux_n, gkyl_range_idx(&flux_nrange, fidx)); - status = fscanf(ptr,"%lf", fpolprime_n); + status = fscanf(ptr, "%lf", fpolprime_n); double *fpol_n = gkyl_array_fetch(fpolflux_n, gkyl_range_idx(&flux_nrange, fidx)); - fpolprime_n[0] = fpolprime_n[0]/fpol_n[0]; // divide out fpol + fpolprime_n[0] = fpolprime_n[0] / fpol_n[0]; // divide out fpol } - } - else { - for(int i = 0; inr; i++){ + } else { + for (int i = 0; i < up->nr; i++) { fidx[0] = i; - double *fpolprime_n= gkyl_array_fetch(fpolprimeflux_n, gkyl_range_idx(&flux_nrange, fidx)); - status = fscanf(ptr,"%lf", fpolprime_n); + double *fpolprime_n = gkyl_array_fetch(fpolprimeflux_n, gkyl_range_idx(&flux_nrange, fidx)); + status = fscanf(ptr, "%lf", fpolprime_n); double *fpol_n = gkyl_array_fetch(fpolflux_n, gkyl_range_idx(&flux_nrange, fidx)); - fpolprime_n[0] = fpolprime_n[0]/fpol_n[0]; // divide out fpol + fpolprime_n[0] = fpolprime_n[0] / fpol_n[0]; // divide out fpol } } - gkyl_nodal_ops_n2m(n2m_flux, &up->fluxbasis, &up->fluxgrid, - &flux_nrange, &up->fluxlocal, 1, fpolprimeflux_n, up->fpolprimeflux, false); + gkyl_nodal_ops_n2m( + n2m_flux, &up->fluxbasis, &up->fluxgrid, &flux_nrange, &up->fluxlocal, 1, fpolprimeflux_n, + up->fpolprimeflux, false + ); // skip pprime - for(int i = 0; inr; i++){ + for (int i = 0; i < up->nr; i++) { status = fscanf(ptr, "%lf", &up->xdum); } @@ -221,22 +226,24 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) // Now lets loop through // Not only do we want psi at the nodes, we also want psi/R and psi/R^2 so we can use them for the magnetc field double R = up->rmin; - double dR = up->rdim/(up->nr-1); + double dR = up->rdim / (up->nr - 1); int idx[2]; - for(int iz = 0; iz < up->nz; iz++){ + for (int iz = 0; iz < up->nz; iz++) { idx[1] = iz; - for(int ir = 0; ir < up->nr; ir++){ - R = up->rmin+ir*dR; + for (int ir = 0; ir < up->nr; ir++) { + R = up->rmin + ir * dR; idx[0] = ir; // set psi double *psi_n = gkyl_array_fetch(psizr_n, gkyl_range_idx(&nrange, idx)); - status = fscanf(ptr,"%lf", psi_n); + status = fscanf(ptr, "%lf", psi_n); } } // We filled psizr_nodal struct gkyl_nodal_ops *n2m_rz = gkyl_nodal_ops_new(&up->rzbasis, &up->rzgrid, false); - gkyl_nodal_ops_n2m(n2m_rz, &up->rzbasis, &up->rzgrid, &nrange, &up->rzlocal, 1, psizr_n, up->psizr, false); + gkyl_nodal_ops_n2m( + n2m_rz, &up->rzbasis, &up->rzgrid, &nrange, &up->rzlocal, 1, psizr_n, up->psizr, false + ); // Reflect psi for double null // Reflect DG coeffs rather than nodal data to avoid symmetry errors in n2m conversion @@ -244,56 +251,60 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &up->rzlocal); while (gkyl_range_iter_next(&iter)) { - if (iter.idx[1] < gkyl_range_shape(&up->rzlocal,1)/2 +1 ) { - int idx_change[2] = {iter.idx[0], gkyl_range_shape(&up->rzlocal, 1) - iter.idx[1]+1}; - const double *coeffs_ref = gkyl_array_cfetch(up->psizr, gkyl_range_idx(&up->rzlocal, iter.idx)); - double *coeffs = gkyl_array_fetch(up->psizr, gkyl_range_idx(&up->rzlocal, idx_change)); - up->rzbasis.flip_odd_sign( 1, coeffs_ref, coeffs); + if (iter.idx[1] < gkyl_range_shape(&up->rzlocal, 1) / 2 + 1) { + int idx_change[2] = {iter.idx[0], gkyl_range_shape(&up->rzlocal, 1) - iter.idx[1] + 1}; + const double *coeffs_ref = + gkyl_array_cfetch(up->psizr, gkyl_range_idx(&up->rzlocal, iter.idx)); + double *coeffs = gkyl_array_fetch(up->psizr, gkyl_range_idx(&up->rzlocal, idx_change)); + up->rzbasis.flip_odd_sign(1, coeffs_ref, coeffs); } } } - + // Now lets read the q profile struct gkyl_array *qflux_n = gkyl_array_new(GKYL_DOUBLE, 1, flux_nrange.volume); int geqdsk_sign_convention = up->sibry > up->simag ? 0 : 1; if (geqdsk_sign_convention) { // psi increases toward magnetic axis. - for (int i = up->nr-1; i>=0; i--) { + for (int i = up->nr - 1; i >= 0; i--) { fidx[0] = i; - double *q_n= gkyl_array_fetch(qflux_n, gkyl_range_idx(&flux_nrange, fidx)); + double *q_n = gkyl_array_fetch(qflux_n, gkyl_range_idx(&flux_nrange, fidx)); status = fscanf(ptr, "%lf", q_n); } } else { // psi increases away from magnetic axis. - for (int i = 0; inr; i++) { + for (int i = 0; i < up->nr; i++) { fidx[0] = i; - double *q_n= gkyl_array_fetch(qflux_n, gkyl_range_idx(&flux_nrange, fidx)); + double *q_n = gkyl_array_fetch(qflux_n, gkyl_range_idx(&flux_nrange, fidx)); status = fscanf(ptr, "%lf", q_n); } } - gkyl_nodal_ops_n2m(n2m_flux, &up->fluxbasis, &up->fluxgrid, - &flux_nrange, &up->fluxlocal, 1, qflux_n, up->qflux, false); - + gkyl_nodal_ops_n2m( + n2m_flux, &up->fluxbasis, &up->fluxgrid, &flux_nrange, &up->fluxlocal, 1, qflux_n, up->qflux, + false + ); // Make the cubic interpolator - up->evf = gkyl_dg_basis_ops_evalf_new(&up->rzgrid_cubic, psizr_n); + up->evf = gkyl_dg_basis_ops_evalf_new(&up->rzgrid_cubic, psizr_n); gkyl_dg_basis_op_mem *mem = 0; mem = gkyl_dg_alloc_cubic_2d(cells_cubic); - gkyl_dg_calc_cubic_2d_from_nodal_vals(mem, cells_cubic, up->rzgrid_cubic.dx, psizr_n, up->psizr_cubic); + gkyl_dg_calc_cubic_2d_from_nodal_vals( + mem, cells_cubic, up->rzgrid_cubic.dx, psizr_n, up->psizr_cubic + ); gkyl_dg_basis_op_mem_release(mem); // Calculate B. struct gkyl_array *bpolzr_n = gkyl_array_new(GKYL_DOUBLE, 1, nrange.volume); struct gkyl_array *bphizr_n = gkyl_array_new(GKYL_DOUBLE, 1, nrange.volume); struct gkyl_array *bmagzr_n = gkyl_array_new(GKYL_DOUBLE, 1, nrange.volume); - double dZ = up->zdim/(up->nz-1); - double scale_factorR = 2.0/(up->rzgrid_cubic.dx[0]); - double scale_factorZ = 2.0/(up->rzgrid_cubic.dx[1]); - for (int iz = 0; iz < up->nz; iz++){ + double dZ = up->zdim / (up->nz - 1); + double scale_factorR = 2.0 / (up->rzgrid_cubic.dx[0]); + double scale_factorZ = 2.0 / (up->rzgrid_cubic.dx[1]); + for (int iz = 0; iz < up->nz; iz++) { idx[1] = iz; - double Z = up->zmin+iz*dZ; - for (int ir = 0; ir < up->nr; ir++){ - R = up->rmin+ir*dR; + double Z = up->zmin + iz * dZ; + for (int ir = 0; ir < up->nr; ir++) { + R = up->rmin + ir * dR; idx[0] = ir; // Calculate Bpol. @@ -305,42 +316,45 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) psi_curr = fout[0]; br = fout[3]; bz = -fout[1]; - } - else { + } else { double fout[3]; up->evf->eval_cubic_wgrad(0.0, xn, fout, up->evf->ctx); psi_curr = fout[0]; - br = 1.0/R*fout[2]; - bz = -1.0/R*fout[1]; + br = 1.0 / R * fout[2]; + bz = -1.0 / R * fout[1]; } double *bpol_n = gkyl_array_fetch(bpolzr_n, gkyl_range_idx(&nrange, idx)); - bpol_n[0] = sqrt(br*br + bz*bz); + bpol_n[0] = sqrt(br * br + bz * bz); // Calculate Bphi. - if (psi_curr < up->fluxgrid.lower[0] || psi_curr > up->fluxgrid.upper[0]){ + if (psi_curr < up->fluxgrid.lower[0] || psi_curr > up->fluxgrid.upper[0]) { psi_curr = up->sibry; } - fidx[0] = up->fluxlocal.lower[0] + (int) floor((psi_curr - up->fluxgrid.lower[0])/up->fluxgrid.dx[0]); + fidx[0] = up->fluxlocal.lower[0] + + (int)floor((psi_curr - up->fluxgrid.lower[0]) / up->fluxgrid.dx[0]); fidx[0] = GKYL_MIN2(fidx[0], up->fluxlocal.upper[0]); fidx[0] = GKYL_MAX2(fidx[0], up->fluxlocal.lower[0]); long flux_loc = gkyl_range_idx(&up->fluxlocal, fidx); const double *coeffs = gkyl_array_cfetch(up->fpolflux, flux_loc); double fxc; gkyl_rect_grid_cell_center(&up->fluxgrid, fidx, &fxc); - double fx = (psi_curr - fxc)/(up->fluxgrid.dx[0]*0.5); + double fx = (psi_curr - fxc) / (up->fluxgrid.dx[0] * 0.5); double fpol = up->fluxbasis.eval_expand(&fx, coeffs); double *bphi_n = gkyl_array_fetch(bphizr_n, gkyl_range_idx(&nrange, idx)); - if (fpol == 0.0 && R == 0.0) + if (fpol == 0.0 && R == 0.0) { bphi_n[0] = 0.0; - else - bphi_n[0] = fpol/R; + } else { + bphi_n[0] = fpol / R; + } // Calculate Bmag. double *bmag_n = gkyl_array_fetch(bmagzr_n, gkyl_range_idx(&nrange, idx)); - bmag_n[0] = sqrt(bpol_n[0]*bpol_n[0] + bphi_n[0]*bphi_n[0]); + bmag_n[0] = sqrt(bpol_n[0] * bpol_n[0] + bphi_n[0] * bphi_n[0]); } } - gkyl_nodal_ops_n2m(n2m_rz, &up->rzbasis, &up->rzgrid, &nrange, &up->rzlocal, 1, bmagzr_n, up->bmagzr, false); + gkyl_nodal_ops_n2m( + n2m_rz, &up->rzbasis, &up->rzgrid, &nrange, &up->rzlocal, 1, bmagzr_n, up->bmagzr, false + ); // Reflect B for double null. // Reflect DG coeffs rather than nodal data to avoid symmetry errors in n2m conversion. @@ -348,15 +362,16 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &up->rzlocal); while (gkyl_range_iter_next(&iter)) { - if (iter.idx[1] < gkyl_range_shape(&up->rzlocal,1)/2 +1 ) { - int idx_change[2] = {iter.idx[0], gkyl_range_shape(&up->rzlocal, 1) - iter.idx[1]+1}; - const double *coeffs_ref = gkyl_array_cfetch(up->bmagzr, gkyl_range_idx(&up->rzlocal, iter.idx)); - double *coeffs = gkyl_array_fetch(up->bmagzr, gkyl_range_idx(&up->rzlocal, idx_change)); - up->rzbasis.flip_odd_sign( 1, coeffs_ref, coeffs); + if (iter.idx[1] < gkyl_range_shape(&up->rzlocal, 1) / 2 + 1) { + int idx_change[2] = {iter.idx[0], gkyl_range_shape(&up->rzlocal, 1) - iter.idx[1] + 1}; + const double *coeffs_ref = + gkyl_array_cfetch(up->bmagzr, gkyl_range_idx(&up->rzlocal, iter.idx)); + double *coeffs = gkyl_array_fetch(up->bmagzr, gkyl_range_idx(&up->rzlocal, idx_change)); + up->rzbasis.flip_odd_sign(1, coeffs_ref, coeffs); } } } - + // Free n2m operators gkyl_nodal_ops_release(n2m_flux); gkyl_nodal_ops_release(n2m_rz); @@ -369,7 +384,7 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) gkyl_array_release(bphizr_n); gkyl_array_release(bmagzr_n); // Done, don't care about the rest - + fclose(ptr); int num_max_xpts = 10; @@ -377,8 +392,8 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) double Zxpt[num_max_xpts]; up->num_xpts = find_xpts(up, Rxpt, Zxpt); - up->Rxpt = gkyl_malloc(sizeof(double)*fmax(2, up->num_xpts)); - up->Zxpt = gkyl_malloc(sizeof(double)*fmax(2, up->num_xpts)); + up->Rxpt = gkyl_malloc(sizeof(double) * fmax(2, up->num_xpts)); + up->Zxpt = gkyl_malloc(sizeof(double) * fmax(2, up->num_xpts)); for (int i = 0; i < up->num_xpts; i++) { up->Rxpt[i] = Rxpt[i]; up->Zxpt[i] = Zxpt[i]; @@ -387,8 +402,8 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) } up->num_xpts_cubic = find_xpts_cubic(up, Rxpt, Zxpt); - up->Rxpt_cubic = gkyl_malloc(sizeof(double)*fmax(2, up->num_xpts_cubic)); - up->Zxpt_cubic = gkyl_malloc(sizeof(double)*fmax(2, up->num_xpts_cubic)); + up->Rxpt_cubic = gkyl_malloc(sizeof(double) * fmax(2, up->num_xpts_cubic)); + up->Zxpt_cubic = gkyl_malloc(sizeof(double) * fmax(2, up->num_xpts_cubic)); for (int i = 0; i < up->num_xpts_cubic; i++) { up->Rxpt_cubic[i] = Rxpt[i]; up->Zxpt_cubic[i] = Zxpt[i]; @@ -399,7 +414,8 @@ gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp) return up; } -void gkyl_efit_release(gkyl_efit* up){ +void gkyl_efit_release(gkyl_efit *up) +{ gkyl_free(up->Rxpt); gkyl_free(up->Zxpt); gkyl_free(up->Rxpt_cubic); diff --git a/gyrokinetic/zero/efit_utils.c b/gyrokinetic/zero/efit_utils.c index fa1324bc9b..07411c70ad 100644 --- a/gyrokinetic/zero/efit_utils.c +++ b/gyrokinetic/zero/efit_utils.c @@ -2,52 +2,55 @@ #include #include -static double -eval_laplacian_expand_2d_tensor_p2(int dir, const double *z, const double *f ) +static double eval_laplacian_expand_2d_tensor_p2(int dir, const double *z, const double *f) { const double z0 = z[0]; const double z1 = z[1]; - if (dir == 0) - return 11.25*f[8]*z1*z1+5.809475019311125*f[6]*z1-3.75*f[8]+3.354101966249685*f[4]; - if (dir == 1) - return 11.25*f[8]*z0*z0+5.809475019311125*f[7]*z0-3.75*f[8]+3.354101966249685*f[5]; + if (dir == 0) { + return 11.25 * f[8] * z1 * z1 + 5.809475019311125 * f[6] * z1 - 3.75 * f[8] + + 3.354101966249685 * f[4]; + } + if (dir == 1) { + return 11.25 * f[8] * z0 * z0 + 5.809475019311125 * f[7] * z0 - 3.75 * f[8] + + 3.354101966249685 * f[5]; + } return 0.0; // can't happen, suppresses warning - } -static double -eval_mixedpartial_expand_2d_tensor_p2(const double *z, const double *f ) +static double eval_mixedpartial_expand_2d_tensor_p2(const double *z, const double *f) { const double z0 = z[0]; const double z1 = z[1]; - return 22.5*f[8]*z0*z1+5.809475019311125*f[7]*z1+5.809475019311125*f[6]*z0+1.5*f[3]; - + return 22.5 * f[8] * z0 * z1 + 5.809475019311125 * f[7] * z1 + 5.809475019311125 * f[6] * z0 + + 1.5 * f[3]; } static void print_result(int n, double x[], double dx[], double errx, double errf, int niter) { double x0 = x[0]; double y0 = x[1]; - if (x0 >= -1 && x0 <= 1 && y0 >= -1 && y0 <= 1 ) { + if (x0 >= -1 && x0 <= 1 && y0 >= -1 && y0 <= 1) { printf("x = "); - for(int i=0; irzbasis_cubic.eval_grad_expand(i,x,coeffs); - fjac[0][0] = up->evf->eval_cubic_laplacian(0,x,coeffs); - fjac[0][1] = up->evf->eval_cubic_mixedpartial(x,coeffs); - fjac[1][0] = up->evf->eval_cubic_mixedpartial(x,coeffs); - fjac[1][1] = up->evf->eval_cubic_laplacian(1,x,coeffs); - } - else { - for(int i=0; irzbasis.eval_grad_expand(i,x,coeffs); - fjac[0][0] = eval_laplacian_expand_2d_tensor_p2(0,x,coeffs); - fjac[0][1] = eval_mixedpartial_expand_2d_tensor_p2(x,coeffs); - fjac[1][0] = eval_mixedpartial_expand_2d_tensor_p2(x,coeffs); - fjac[1][1] = eval_laplacian_expand_2d_tensor_p2(1,x,coeffs); + for (int i = 0; i < n; i++) { + fvec[i] = up->rzbasis_cubic.eval_grad_expand(i, x, coeffs); + } + fjac[0][0] = up->evf->eval_cubic_laplacian(0, x, coeffs); + fjac[0][1] = up->evf->eval_cubic_mixedpartial(x, coeffs); + fjac[1][0] = up->evf->eval_cubic_mixedpartial(x, coeffs); + fjac[1][1] = up->evf->eval_cubic_laplacian(1, x, coeffs); + } else { + for (int i = 0; i < n; i++) { + fvec[i] = up->rzbasis.eval_grad_expand(i, x, coeffs); + } + fjac[0][0] = eval_laplacian_expand_2d_tensor_p2(0, x, coeffs); + fjac[0][1] = eval_mixedpartial_expand_2d_tensor_p2(x, coeffs); + fjac[1][0] = eval_mixedpartial_expand_2d_tensor_p2(x, coeffs); + fjac[1][1] = eval_laplacian_expand_2d_tensor_p2(1, x, coeffs); } errf = 0.0; - for (int i=0;irzlocal); while (gkyl_range_iter_next(&iter)) { - if ((iter.idx[1] < gkyl_range_shape(&up->rzlocal,1)/2 + 1) || (!up->reflect)) { - const double* psi = gkyl_array_cfetch(up->psizr, gkyl_range_idx(&up->rzlocal, iter.idx)); + if ((iter.idx[1] < gkyl_range_shape(&up->rzlocal, 1) / 2 + 1) || (!up->reflect)) { + const double *psi = gkyl_array_cfetch(up->psizr, gkyl_range_idx(&up->rzlocal, iter.idx)); double xsol[2]; bool status = newton_raphson(up, psi, xsol, false); double x0 = xsol[0]; @@ -126,8 +139,8 @@ find_xpts(gkyl_efit* up, double *Rxpt, double *Zxpt) found_xpt = true; double xc[2]; gkyl_rect_grid_cell_center(&up->rzgrid, iter.idx, xc); - double R0 = up->rzgrid.dx[0]*x0/2.0 + xc[0]; - double Z0 = up->rzgrid.dx[1]*y0/2.0 + xc[1]; + double R0 = up->rzgrid.dx[0] * x0 / 2.0 + xc[0]; + double Z0 = up->rzgrid.dx[1] * y0 / 2.0 + xc[1]; if (fabs(psi0 - up->sibry) <= fabs(psisep - up->sibry)) { Rsep = R0; Zsep = Z0; @@ -146,8 +159,7 @@ find_xpts(gkyl_efit* up, double *Rxpt, double *Zxpt) Zxpt[0] = Zsep; Zxpt[1] = -Zsep; up->psisep = psisep; - } - else { + } else { num_xpts = 1; Rxpt[0] = Rsep; Zxpt[0] = Zsep; @@ -157,8 +169,7 @@ find_xpts(gkyl_efit* up, double *Rxpt, double *Zxpt) return num_xpts; } -int -find_xpts_cubic(gkyl_efit* up, double *Rxpt, double *Zxpt) +int find_xpts_cubic(gkyl_efit *up, double *Rxpt, double *Zxpt) { bool found_xpt = false; double Rsep, Zsep; @@ -166,8 +177,9 @@ find_xpts_cubic(gkyl_efit* up, double *Rxpt, double *Zxpt) struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &up->rzlocal_cubic); while (gkyl_range_iter_next(&iter)) { - if ((iter.idx[1] < gkyl_range_shape(&up->rzlocal_cubic,1)/2 + 1) || (!up->reflect)) { - const double* psi = gkyl_array_cfetch(up->psizr_cubic, gkyl_range_idx(&up->rzlocal_cubic, iter.idx)); + if ((iter.idx[1] < gkyl_range_shape(&up->rzlocal_cubic, 1) / 2 + 1) || (!up->reflect)) { + const double *psi = + gkyl_array_cfetch(up->psizr_cubic, gkyl_range_idx(&up->rzlocal_cubic, iter.idx)); double xsol[2]; bool status = newton_raphson(up, psi, xsol, true); double x0 = xsol[0]; @@ -177,8 +189,8 @@ find_xpts_cubic(gkyl_efit* up, double *Rxpt, double *Zxpt) found_xpt = true; double xc[2]; gkyl_rect_grid_cell_center(&up->rzgrid_cubic, iter.idx, xc); - double R0 = up->rzgrid_cubic.dx[0]*x0/2.0 + xc[0]; - double Z0 = up->rzgrid_cubic.dx[1]*y0/2.0 + xc[1]; + double R0 = up->rzgrid_cubic.dx[0] * x0 / 2.0 + xc[0]; + double Z0 = up->rzgrid_cubic.dx[1] * y0 / 2.0 + xc[1]; if (fabs(psi0 - up->sibry) <= fabs(psisep - up->sibry)) { Rsep = R0; Zsep = Z0; @@ -197,8 +209,7 @@ find_xpts_cubic(gkyl_efit* up, double *Rxpt, double *Zxpt) Zxpt[0] = Zsep; Zxpt[1] = -Zsep; up->psisep_cubic = psisep; - } - else { + } else { num_xpts = 1; Rxpt[0] = Rsep; Zxpt[0] = Zsep; @@ -208,9 +219,8 @@ find_xpts_cubic(gkyl_efit* up, double *Rxpt, double *Zxpt) return num_xpts; } - -void -get_stripped_filename(const char *filepath, char *out_buffer) { +void get_stripped_filename(const char *filepath, char *out_buffer) +{ const char *last_slash = strrchr(filepath, '/'); const char *filename_start = (last_slash) ? last_slash + 1 : filepath; @@ -218,8 +228,7 @@ get_stripped_filename(const char *filepath, char *out_buffer) { if (!last_dot || last_dot == filename_start) { strcpy(out_buffer, filename_start); - } - else { + } else { size_t len = last_dot - filename_start; strncpy(out_buffer, filename_start, len); out_buffer[len] = '\0'; diff --git a/gyrokinetic/zero/fem_parproj.c b/gyrokinetic/zero/fem_parproj.c index d52d8c8658..4e8bb68d28 100644 --- a/gyrokinetic/zero/fem_parproj.c +++ b/gyrokinetic/zero/fem_parproj.c @@ -1,14 +1,12 @@ #include #include -static void -fem_parproj_bias_src_disabled(gkyl_fem_parproj* up, const struct gkyl_array *rhsin) +static void fem_parproj_bias_src_disabled(gkyl_fem_parproj *up, const struct gkyl_array *rhsin) { // Do nothing. } -static void -fem_parproj_bias_src_enabled(gkyl_fem_parproj* up, const struct gkyl_array *rhsin) +static void fem_parproj_bias_src_enabled(gkyl_fem_parproj *up, const struct gkyl_array *rhsin) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { @@ -30,56 +28,60 @@ fem_parproj_bias_src_enabled(gkyl_fem_parproj* up, const struct gkyl_array *rhsi while (gkyl_range_iter_next(&up->par_iter1d)) { long paridx = gkyl_range_idx(&up->par_range1d, up->par_iter1d.idx); - for (size_t d=0; dpardir; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->pardir; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; - int keri = up->par_iter1d.idx[0] == up->parnum_cells? 1 : 0; + int keri = up->par_iter1d.idx[0] == up->parnum_cells ? 1 : 0; up->kernels->l2g[keri](up->parnum_cells, paridx, up->globalidx); - long perpProbOff = perpidx*up->numnodes_global; + long perpProbOff = perpidx * up->numnodes_global; - for (int i=0; inum_bias_line; i++) { + for (int i = 0; i < up->num_bias_line; i++) { // Index of the cell that abuts the line from below. struct gkyl_poisson_bias_line *bl = &up->bias_lines[i]; int bl_idx_m[up->bl_ndim_perp]; - for (int d=0; dbl_ndim_perp; d++) { + for (int d = 0; d < up->bl_ndim_perp; d++) { int perp_dir = bl->perp_dirs[d]; double dx = up->grid.dx[perp_dir]; - bl_idx_m[d] = (bl->perp_coords[d]-1e-3*dx - up->grid.lower[perp_dir])/dx+1; + bl_idx_m[d] = (bl->perp_coords[d] - 1e-3 * dx - up->grid.lower[perp_dir]) / dx + 1; } - if ( - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) - ) { + if ((idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1]) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1]) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1] + 1) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1] + 1 + )) { int edge[2] = { - -1+2*((bl_idx_m[0]+1)-idx1[bl->perp_dirs[0]]), - -1+2*((bl_idx_m[1]+1)-idx1[bl->perp_dirs[1]]), + -1 + 2 * ((bl_idx_m[0] + 1) - idx1[bl->perp_dirs[0]]), + -1 + 2 * ((bl_idx_m[1] + 1) - idx1[bl->perp_dirs[1]]) }; - up->kernels->bias_src_ker[keri](edge, bl->perp_dirs, bl->val, perpProbOff, up->globalidx, brhs_p); + up->kernels->bias_src_ker[keri]( + edge, bl->perp_dirs, bl->val, perpProbOff, up->globalidx, brhs_p + ); } } } - } } -struct gkyl_fem_parproj* -gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, enum gkyl_fem_parproj_bc_type bctype, struct gkyl_poisson_bias_line_list* bias_lines, - const struct gkyl_array *weight_left, const struct gkyl_array *weight_right, bool use_gpu) +struct gkyl_fem_parproj *gkyl_fem_parproj_new( + const struct gkyl_range *solve_range, const struct gkyl_rect_grid *grid, + const struct gkyl_basis *basis, enum gkyl_fem_parproj_bc_type bctype, + struct gkyl_poisson_bias_line_list *bias_lines, const struct gkyl_array *weight_left, + const struct gkyl_array *weight_right, bool use_gpu +) { struct gkyl_fem_parproj *up = gkyl_malloc(sizeof(struct gkyl_fem_parproj)); up->grid = *grid; up->solve_range = solve_range; up->ndim = solve_range->ndim; - up->num_basis = basis->num_basis; + up->num_basis = basis->num_basis; up->basis_type = basis->b_type; up->poly_order = basis->poly_order; - up->pardir = up->ndim-1; // Assume parallel direction is always the last. + up->pardir = up->ndim - 1; // Assume parallel direction is always the last. up->isperiodic = bctype == GKYL_FEM_PARPROJ_PERIODIC; up->isdirichlet = bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST || GKYL_FEM_PARPROJ_DIRICHLET_SKIN; up->use_gpu = use_gpu; @@ -94,8 +96,8 @@ gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rec struct gkyl_array *weight_left_ho; if (weight_left) { has_weight_lhs = true; - weight_left_ho = use_gpu? gkyl_array_new(GKYL_DOUBLE, weight_left->ncomp, weight_left->size) - : gkyl_array_acquire(weight_left); + weight_left_ho = use_gpu ? gkyl_array_new(GKYL_DOUBLE, weight_left->ncomp, weight_left->size) : + gkyl_array_acquire(weight_left); gkyl_array_copy(weight_left_ho, weight_left); } @@ -104,7 +106,7 @@ gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rec // Range of parallel cells, as a sub-range of up->solve_range. struct gkyl_range par_range; int sublower[GKYL_MAX_CDIM], subupper[GKYL_MAX_CDIM]; - for (int d=0; dndim; d++) { + for (int d = 0; d < up->ndim; d++) { sublower[d] = up->solve_range->lower[d]; subupper[d] = up->solve_range->lower[d]; } @@ -120,26 +122,34 @@ gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rec int lower1d[] = {par_range.lower[up->pardir]}, upper1d[] = {par_range.upper[up->pardir]}; gkyl_range_init(&up->par_range1d, 1, lower1d, upper1d); // 2D range of perpendicular cells. - gkyl_range_init(&up->perp_range2d, up->ndim==3 ? 2 : 1, perp_range.lower, perp_range.upper); + gkyl_range_init(&up->perp_range2d, up->ndim == 3 ? 2 : 1, perp_range.lower, perp_range.upper); // Compute the number of local and global nodes. up->numnodes_local = up->num_basis; up->numnodes_global = gkyl_fem_parproj_global_num_nodes(basis, up->isperiodic, par_range.volume); - up->brhs = gkyl_array_new(GKYL_DOUBLE, 1, up->numnodes_global*perp_range.volume); // Global right side vector. + up->brhs = gkyl_array_new( + GKYL_DOUBLE, 1, + up->numnodes_global * perp_range.volume + ); // Global right side vector. // Allocate struct holding kernel pointers. - struct gkyl_fem_parproj_kernels *kernels_ho = gkyl_malloc(sizeof(struct gkyl_fem_parproj_kernels)); - if (!use_gpu) + struct gkyl_fem_parproj_kernels *kernels_ho = + gkyl_malloc(sizeof(struct gkyl_fem_parproj_kernels)); + if (!use_gpu) { up->kernels = gkyl_malloc(sizeof(struct gkyl_fem_parproj_kernels)); + } #ifdef GKYL_HAVE_CUDA - if (use_gpu) + if (use_gpu) { up->kernels = gkyl_cu_malloc(sizeof(struct gkyl_fem_parproj_kernels)); + } #endif // Choose kernels. - fem_parproj_choose_kernels(basis, has_weight_lhs, up->has_weight_rhs, bctype, use_gpu, up->kernels); + fem_parproj_choose_kernels( + basis, has_weight_lhs, up->has_weight_rhs, bctype, use_gpu, up->kernels + ); // Select kernels for building LHS matrix on host: fem_parproj_choose_kernels(basis, has_weight_lhs, up->has_weight_rhs, bctype, false, kernels_ho); @@ -151,36 +161,41 @@ gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rec if (bias_lines->num_bias_line > 0) { // Check if any bias lines are in solve_range, and copy their info into updater. bl_in_solve_range = gkyl_malloc(bias_lines->num_bias_line * sizeof(bool)); - for (int i=0; inum_bias_line; i++) + for (int i = 0; i < bias_lines->num_bias_line; i++) { bl_in_solve_range[i] = false; + } - for (int i=0; inum_bias_line; i++) { + for (int i = 0; i < bias_lines->num_bias_line; i++) { struct gkyl_poisson_bias_line *bl = &bias_lines->bl[i]; // MF 2025/11/10: For now limit ourselves to lines perpendicular to x and z. up->bl_ndim_perp = 2; - assert(bl->perp_dirs[0] == 0 && bl->perp_dirs[1] == up->ndim-1); + assert(bl->perp_dirs[0] == 0 && bl->perp_dirs[1] == up->ndim - 1); double line_coords[up->ndim]; - for (int d=0; dndim; d++) - line_coords[d] = grid->lower[d]+grid->dx[d]/2.0; + for (int d = 0; d < up->ndim; d++) { + line_coords[d] = grid->lower[d] + grid->dx[d] / 2.0; + } - for (int d=0; dbl_ndim_perp; d++) + for (int d = 0; d < up->bl_ndim_perp; d++) { line_coords[bl->perp_dirs[d]] = bl->perp_coords[d]; + } // If biased line is at domain boundary, shift it minimally so it is inside the domain. - for (int d=0; dndim; d++) { - if (fabs(line_coords[d] - grid->lower[d]) < 1e-3*grid->dx[d]) { - line_coords[d] += 1e-3*grid->dx[d]; + for (int d = 0; d < up->ndim; d++) { + if (fabs(line_coords[d] - grid->lower[d]) < 1e-3 * grid->dx[d]) { + line_coords[d] += 1e-3 * grid->dx[d]; } - if (fabs(line_coords[d] - grid->upper[d]) < 1e-3*grid->dx[d]) { - line_coords[d] += -1e-3*grid->dx[d]; + if (fabs(line_coords[d] - grid->upper[d]) < 1e-3 * grid->dx[d]) { + line_coords[d] += -1e-3 * grid->dx[d]; } } - bool pick_lower[3] = {true, true, true}; // If at a cell boundary, pick the cell lower than the biased line. + bool pick_lower[3] = { + true, true, true + }; // If at a cell boundary, pick the cell lower than the biased line. int line_idx[GKYL_MAX_CDIM]; - gkyl_rect_grid_find_cell(grid, line_coords, pick_lower, (int[3]){-1,-1,-1}, line_idx); + gkyl_rect_grid_find_cell(grid, line_coords, pick_lower, (int[3]){-1, -1, -1}, line_idx); bl_in_solve_range[i] = gkyl_range_contains_idx(solve_range, line_idx); if (!bl_in_solve_range[i]) { @@ -189,20 +204,22 @@ gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rec bool on_upper_cell_boundary = false; double xc[GKYL_MAX_CDIM]; gkyl_rect_grid_cell_center(grid, line_idx, xc); - for (int d=0; dndim; d++) { - if (fabs(line_coords[d] - (xc[d]+0.5*grid->dx[d])) < 1e-3*grid->dx[d]) { + for (int d = 0; d < up->ndim; d++) { + if (fabs(line_coords[d] - (xc[d] + 0.5 * grid->dx[d])) < 1e-3 * grid->dx[d]) { on_upper_cell_boundary = true; } } if (on_upper_cell_boundary) { - pick_lower[0] = pick_lower[1] = pick_lower[2] = false; // If at a cell boundary, pick the cell upper than the biased line. - gkyl_rect_grid_find_cell(grid, line_coords, pick_lower, (int[3]){-1,-1,-1}, line_idx); + pick_lower[0] = pick_lower[1] = pick_lower[2] = + false; // If at a cell boundary, pick the cell upper than the biased line. + gkyl_rect_grid_find_cell(grid, line_coords, pick_lower, (int[3]){-1, -1, -1}, line_idx); bl_in_solve_range[i] = gkyl_range_contains_idx(solve_range, line_idx); } } - if (bl_in_solve_range[i]) + if (bl_in_solve_range[i]) { up->num_bias_line++; + } } if (up->num_bias_line) { @@ -210,7 +227,7 @@ gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rec size_t bl_sz = up->num_bias_line * sizeof(struct gkyl_poisson_bias_line); struct gkyl_poisson_bias_line *bias_lines_buff = gkyl_malloc(bl_sz); int blc = 0; - for (int i=0; inum_bias_line; i++) { + for (int i = 0; i < bias_lines->num_bias_line; i++) { if (bl_in_solve_range[i]) { struct gkyl_poisson_bias_line *bl = &bias_lines->bl[i]; memcpy(&bias_lines_buff[blc], &bias_lines->bl[i], sizeof(struct gkyl_poisson_bias_line)); @@ -221,8 +238,7 @@ gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rec if (up->use_gpu) { up->bias_lines = gkyl_cu_malloc(bl_sz); gkyl_cu_memcpy(up->bias_lines, bias_lines_buff, bl_sz, GKYL_CU_MEMCPY_H2D); - } - else { + } else { up->bias_lines = gkyl_malloc(bl_sz); memcpy(up->bias_lines, bias_lines_buff, bl_sz); } @@ -243,33 +259,40 @@ gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rec if (up->ndim == 1) { nrhs = 1; gkyl_range_init(&prob_range, 1, &((int){1}), &((int){1})); - } - else { + } else { if (has_weight_lhs || up->num_bias_line) { nrhs = 1; - gkyl_range_init(&prob_range, up->perp_range2d.ndim, up->perp_range2d.lower, up->perp_range2d.upper); - } - else { + gkyl_range_init( + &prob_range, up->perp_range2d.ndim, up->perp_range2d.lower, up->perp_range2d.upper + ); + } else { nrhs = perp_range.volume; gkyl_range_init(&prob_range, 1, &((int){1}), &((int){1})); } } #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) - up->prob_cu = gkyl_culinsolver_prob_new(prob_range.volume, up->numnodes_global, up->numnodes_global, nrhs); - else - up->prob = gkyl_superlu_prob_new(prob_range.volume, up->numnodes_global, up->numnodes_global, nrhs); + if (up->use_gpu) { + up->prob_cu = + gkyl_culinsolver_prob_new(prob_range.volume, up->numnodes_global, up->numnodes_global, nrhs); + } else { + up->prob = + gkyl_superlu_prob_new(prob_range.volume, up->numnodes_global, up->numnodes_global, nrhs); + } #else - up->prob = gkyl_superlu_prob_new(prob_range.volume, up->numnodes_global, up->numnodes_global, nrhs); + up->prob = + gkyl_superlu_prob_new(prob_range.volume, up->numnodes_global, up->numnodes_global, nrhs); #endif // Assign non-zero elements in A. - struct gkyl_mat_triples **tri = gkyl_malloc(prob_range.volume*sizeof(struct gkyl_mat_triples *)); - for (size_t i=0; inumnodes_global, up->numnodes_global); #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) gkyl_mat_triples_set_rowmaj_order(tri[i]); + if (up->use_gpu) { + gkyl_mat_triples_set_rowmaj_order(tri[i]); + } #endif } @@ -284,13 +307,15 @@ gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rec const double *wgt_p = NULL; if (has_weight_lhs) { - for (size_t d=0; dpardir; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->pardir; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; long linidx = gkyl_range_idx(up->solve_range, idx1); wgt_p = gkyl_array_cfetch(weight_left_ho, linidx); } - int keri = up->par_iter1d.idx[0] == up->parnum_cells? 1 : 0; + int keri = up->par_iter1d.idx[0] == up->parnum_cells ? 1 : 0; kernels_ho->l2g[keri](up->parnum_cells, paridx, up->globalidx); // Apply the wgt*phi*basis stencil. @@ -310,32 +335,35 @@ gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rec while (gkyl_range_iter_next(&up->par_iter1d)) { long paridx = gkyl_range_idx(&up->par_range1d, up->par_iter1d.idx); - for (size_t d=0; dpardir; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->pardir; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; - int keri = up->par_iter1d.idx[0] == up->parnum_cells? 1 : 0; + int keri = up->par_iter1d.idx[0] == up->parnum_cells ? 1 : 0; kernels_ho->l2g[keri](up->parnum_cells, paridx, up->globalidx); - for (int i=0; inum_bias_line; i++) { + for (int i = 0; i < bias_lines->num_bias_line; i++) { if (bl_in_solve_range[i]) { // Index of the cell that abuts the line from below. struct gkyl_poisson_bias_line *bl = &bias_lines->bl[i]; int bl_idx_m[up->bl_ndim_perp]; - for (int d=0; dbl_ndim_perp; d++) { + for (int d = 0; d < up->bl_ndim_perp; d++) { int perp_dir = bl->perp_dirs[d]; double dx = up->grid.dx[perp_dir]; - bl_idx_m[d] = (bl->perp_coords[d]-1e-3*dx - up->grid.lower[perp_dir])/dx+1; + bl_idx_m[d] = (bl->perp_coords[d] - 1e-3 * dx - up->grid.lower[perp_dir]) / dx + 1; } - if ( - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) - ) { + if ((idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1]) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1] + ) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1] + 1 + ) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && + idx1[bl->perp_dirs[1]] == bl_idx_m[1] + 1)) { int edge[2] = { - -1+2*((bl_idx_m[0]+1)-idx1[bl->perp_dirs[0]]), - -1+2*((bl_idx_m[1]+1)-idx1[bl->perp_dirs[1]]), + -1 + 2 * ((bl_idx_m[0] + 1) - idx1[bl->perp_dirs[0]]), + -1 + 2 * ((bl_idx_m[1] + 1) - idx1[bl->perp_dirs[1]]) }; kernels_ho->bias_lhs_ker[keri](edge, bl->perp_dirs, up->globalidx, tri[perpidx]); } @@ -345,41 +373,46 @@ gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rec } up->bias_line_src = fem_parproj_bias_src_enabled; - } - else { + } else { up->bias_line_src = fem_parproj_bias_src_disabled; } - if (bl_in_solve_range) + if (bl_in_solve_range) { gkyl_free(bl_in_solve_range); + } - if (!(up->use_gpu)) + if (!(up->use_gpu)) { gkyl_superlu_amat_from_triples(up->prob, tri); + } #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { gkyl_culinsolver_amat_from_triples(up->prob_cu, tri); + } #endif - for (size_t i=0; iuse_gpu) { assert(gkyl_array_is_cu_dev(rhsin)); - if (phibc) + if (phibc) { assert(gkyl_array_is_cu_dev(phibc)); + } gkyl_fem_parproj_set_rhs_cu(up, rhsin, phibc); return; @@ -398,17 +431,21 @@ gkyl_fem_parproj_set_rhs(struct gkyl_fem_parproj* up, const struct gkyl_array *r while (gkyl_range_iter_next(&up->par_iter1d)) { long paridx = gkyl_range_idx(&up->par_range1d, up->par_iter1d.idx); - for (size_t d=0; dpardir; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->pardir; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; long linidx = gkyl_range_idx(up->solve_range, idx1); - const double *wgt_p = up->has_weight_rhs? gkyl_array_cfetch(up->weight_rhs, linidx) : NULL; + const double *wgt_p = up->has_weight_rhs ? gkyl_array_cfetch(up->weight_rhs, linidx) : NULL; const double *rhsin_p = gkyl_array_cfetch(rhsin, linidx); - const double *phibc_p = up->kernels->get_dirichlet_value(up->pardir, up->parnum_cells, idx1, up->solve_range, phibc); + const double *phibc_p = up->kernels->get_dirichlet_value( + up->pardir, up->parnum_cells, idx1, up->solve_range, phibc + ); - long perpProbOff = perpidx*up->numnodes_global; + long perpProbOff = perpidx * up->numnodes_global; - int keri = up->par_iter1d.idx[0] == up->parnum_cells? 1 : 0; + int keri = up->par_iter1d.idx[0] == up->parnum_cells ? 1 : 0; up->kernels->l2g[keri](up->parnum_cells, paridx, up->globalidx); keri = idx_to_inloup_ker(up->parnum_cells, up->par_iter1d.idx[0]); @@ -420,11 +457,10 @@ gkyl_fem_parproj_set_rhs(struct gkyl_fem_parproj* up, const struct gkyl_array *r up->bias_line_src(up, rhsin); gkyl_superlu_brhs_from_array(up->prob, brhs_p); - } -void -gkyl_fem_parproj_solve(struct gkyl_fem_parproj* up, struct gkyl_array *phiout) { +void gkyl_fem_parproj_solve(struct gkyl_fem_parproj *up, struct gkyl_array *phiout) +{ #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { assert(gkyl_array_is_cu_dev(phiout)); @@ -444,21 +480,24 @@ gkyl_fem_parproj_solve(struct gkyl_fem_parproj* up, struct gkyl_array *phiout) { while (gkyl_range_iter_next(&up->par_iter1d)) { long paridx = gkyl_range_idx(&up->par_range1d, up->par_iter1d.idx); - for (size_t d=0; dpardir; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->pardir; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; long linidx = gkyl_range_idx(up->solve_range, idx1); double *phiout_p = gkyl_array_fetch(phiout, linidx); - long perpProbOff = perpidx*up->numnodes_global; + long perpProbOff = perpidx * up->numnodes_global; - int keri = up->par_iter1d.idx[0] == up->parnum_cells? 1 : 0; + int keri = up->par_iter1d.idx[0] == up->parnum_cells ? 1 : 0; up->kernels->l2g[keri](up->parnum_cells, paridx, up->globalidx); - up->kernels->solker(gkyl_superlu_get_rhs_ptr(up->prob, 0), perpProbOff, up->globalidx, phiout_p); + up->kernels->solker( + gkyl_superlu_get_rhs_ptr(up->prob, 0), perpProbOff, up->globalidx, phiout_p + ); } } - } void gkyl_fem_parproj_release(struct gkyl_fem_parproj *up) @@ -469,15 +508,17 @@ void gkyl_fem_parproj_release(struct gkyl_fem_parproj *up) if (!up->use_gpu) { gkyl_free(up->kernels); gkyl_superlu_prob_release(up->prob); - if (up->num_bias_line > 0) + if (up->num_bias_line > 0) { gkyl_free(up->bias_lines); + } } #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { gkyl_cu_free(up->kernels); gkyl_culinsolver_prob_release(up->prob_cu); - if (up->num_bias_line > 0) + if (up->num_bias_line > 0) { gkyl_cu_free(up->bias_lines); + } } #endif gkyl_array_release(up->brhs); diff --git a/gyrokinetic/zero/fem_parproj_cu.cu b/gyrokinetic/zero/fem_parproj_cu.cu index cbb000e5a5..d8fcb888a7 100644 --- a/gyrokinetic/zero/fem_parproj_cu.cu +++ b/gyrokinetic/zero/fem_parproj_cu.cu @@ -10,99 +10,105 @@ extern "C" { // CUDA kernel to set device pointers to l2g, RHS src and solution // kernels. Doing function pointer stuff in here avoids troublesome // cudaMemcpyFromSymbol. -__global__ static void -fem_parproj_set_cu_ker_ptrs(struct gkyl_fem_parproj_kernels* kers, enum gkyl_basis_type b_type, - int dim, int poly_order, bool has_weight_lhs, bool has_weight_rhs, - enum gkyl_fem_parproj_bc_type bctype) +__global__ static void fem_parproj_set_cu_ker_ptrs( + struct gkyl_fem_parproj_kernels *kers, enum gkyl_basis_type b_type, int dim, int poly_order, + bool has_weight_lhs, bool has_weight_rhs, enum gkyl_fem_parproj_bc_type bctype +) { // Set l2g kernels. - int bckey_periodic = bctype == GKYL_FEM_PARPROJ_PERIODIC? 0 : 1; + int bckey_periodic = bctype == GKYL_FEM_PARPROJ_PERIODIC ? 0 : 1; const local2global_kern_list *local2global_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - local2global_kernels = ser_loc2glob_list; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + local2global_kernels = ser_loc2glob_list; + break; + default: + assert(false); + break; } - for (int k=0; k<2; k++) + for (int k = 0; k < 2; k++) { kers->l2g[k] = CK(local2global_kernels, dim, bckey_periodic, poly_order, k); + } // Set RHS stencil kernels. int bckey_dirichlet; - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) { bckey_dirichlet = 1; - else if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) + } else if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) { bckey_dirichlet = 2; - else + } else { bckey_dirichlet = 0; + } const srcstencil_kern_list *srcstencil_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - srcstencil_kernels = has_weight_rhs? ser_srcstencil_list_weighted : ser_srcstencil_list_noweight; - break; - default: - assert(false); + case GKYL_BASIS_MODAL_SERENDIPITY: + srcstencil_kernels = has_weight_rhs ? ser_srcstencil_list_weighted : + ser_srcstencil_list_noweight; + break; + default: + assert(false); } - for (int k=0; k<3; k++) + for (int k = 0; k < 3; k++) { kers->srcker[k] = CK(srcstencil_kernels, dim, bckey_dirichlet, poly_order, k); + } // Set the get solution stencil kernel. const solstencil_kern_list *solstencil_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - solstencil_kernels = ser_solstencil_list; - break; - default: - assert(false); + case GKYL_BASIS_MODAL_SERENDIPITY: + solstencil_kernels = ser_solstencil_list; + break; + default: + assert(false); } - kers->solker = solstencil_kernels[dim-1].kernels[poly_order-1]; + kers->solker = solstencil_kernels[dim - 1].kernels[poly_order - 1]; - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) { kers->get_dirichlet_value = get_dirichlet_value_enabled_ghost; - else if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) + } else if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) { kers->get_dirichlet_value = get_dirichlet_value_enabled_skin; - else + } else { kers->get_dirichlet_value = get_dirichlet_value_disabled; + } switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<2; k++) - kers->bias_src_ker[k] = CK(ser_bias_src_list, dim, bckey_periodic, poly_order, k); - - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < 2; k++) { + kers->bias_src_ker[k] = CK(ser_bias_src_list, dim, bckey_periodic, poly_order, k); + } + + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } } -void -fem_parproj_choose_kernels_cu(const struct gkyl_basis *basis, bool has_weight_lhs, bool has_weight_rhs, - enum gkyl_fem_parproj_bc_type bctype, struct gkyl_fem_parproj_kernels *kers) +void fem_parproj_choose_kernels_cu( + const struct gkyl_basis *basis, bool has_weight_lhs, bool has_weight_rhs, + enum gkyl_fem_parproj_bc_type bctype, struct gkyl_fem_parproj_kernels *kers +) { - fem_parproj_set_cu_ker_ptrs<<<1,1>>>(kers, basis->b_type, basis->ndim, - basis->poly_order, has_weight_lhs, has_weight_rhs, bctype); + fem_parproj_set_cu_ker_ptrs<<<1, 1> > >( + kers, basis->b_type, basis->ndim, basis->poly_order, has_weight_lhs, has_weight_rhs, bctype + ); } -__global__ void -gkyl_fem_parproj_set_rhs_kernel(double *rhs_global, const struct gkyl_array *rhsin, - const struct gkyl_array *weight, const struct gkyl_array *phibc, - struct gkyl_range range, struct gkyl_range perp_range2d, struct gkyl_range par_range1d, - struct gkyl_fem_parproj_kernels *kers, long numnodes_global) +__global__ void gkyl_fem_parproj_set_rhs_kernel( + double *rhs_global, const struct gkyl_array *rhsin, const struct gkyl_array *weight, + const struct gkyl_array *phibc, struct gkyl_range range, struct gkyl_range perp_range2d, + struct gkyl_range par_range1d, struct gkyl_fem_parproj_kernels *kers, long numnodes_global +) { int idx[GKYL_MAX_CDIM]; long globalidx[32]; - int parnum_cells = range.upper[range.ndim-1]-range.lower[range.ndim-1]+1; + int parnum_cells = range.upper[range.ndim - 1] - range.lower[range.ndim - 1] + 1; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -112,19 +118,22 @@ gkyl_fem_parproj_set_rhs_kernel(double *rhs_global, const struct gkyl_array *rhs // linc will have jumps in it to jump over ghost cells long linidx = gkyl_range_idx(&range, idx); - const double *wgt_p = weight? (const double *) gkyl_array_cfetch(weight, linidx) : NULL; - const double *rhsin_p = (const double*) gkyl_array_cfetch(rhsin, linidx); - const double *phibc_p = kers->get_dirichlet_value(range.ndim-1, parnum_cells, idx, &range, phibc); + const double *wgt_p = weight ? (const double *)gkyl_array_cfetch(weight, linidx) : NULL; + const double *rhsin_p = (const double *)gkyl_array_cfetch(rhsin, linidx); + const double *phibc_p = + kers->get_dirichlet_value(range.ndim - 1, parnum_cells, idx, &range, phibc); - int idx1d[] = {idx[range.ndim-1]}; + int idx1d[] = {idx[range.ndim - 1]}; long paridx = gkyl_range_idx(&par_range1d, idx1d); - int keri = idx1d[0] == parnum_cells? 1 : 0; + int keri = idx1d[0] == parnum_cells ? 1 : 0; kers->l2g[keri](parnum_cells, paridx, globalidx); int idx2d[] = {perp_range2d.lower[0], perp_range2d.lower[0]}; - for (int d=0; dprob_cu, 0); double *rhs_cu = gkyl_culinsolver_get_rhs_ptr(up->prob_cu, 0); - const struct gkyl_array *phibc_cu = phibc? phibc->on_dev : NULL; - const struct gkyl_array *wgt_cu = up->has_weight_rhs? up->weight_rhs->on_dev : NULL; + const struct gkyl_array *phibc_cu = phibc ? phibc->on_dev : NULL; + const struct gkyl_array *wgt_cu = up->has_weight_rhs ? up->weight_rhs->on_dev : NULL; - gkyl_fem_parproj_set_rhs_kernel<<nblocks, rhsin->nthreads>>>(rhs_cu, rhsin->on_dev, wgt_cu, phibc_cu, - *up->solve_range, up->perp_range2d, up->par_range1d, up->kernels, up->numnodes_global); + gkyl_fem_parproj_set_rhs_kernel<<nblocks, rhsin->nthreads> > >( + rhs_cu, rhsin->on_dev, wgt_cu, phibc_cu, *up->solve_range, up->perp_range2d, up->par_range1d, + up->kernels, up->numnodes_global + ); // Set the corresponding entries to the biasing potential. up->bias_line_src(up, rhsin); } -__global__ void -gkyl_fem_parproj_bias_src_kernel(double *rhs_global, struct gkyl_rect_grid grid, - struct gkyl_range range, struct gkyl_range perp_range2d, struct gkyl_range par_range1d, - struct gkyl_fem_parproj_kernels *kers, long numnodes_global, - int num_bias_line, struct gkyl_poisson_bias_line *bias_lines) +__global__ void gkyl_fem_parproj_bias_src_kernel( + double *rhs_global, struct gkyl_rect_grid grid, struct gkyl_range range, + struct gkyl_range perp_range2d, struct gkyl_range par_range1d, + struct gkyl_fem_parproj_kernels *kers, long numnodes_global, int num_bias_line, + struct gkyl_poisson_bias_line *bias_lines +) { const int bl_ndim_perp = 2; - int ndim_perp = range.ndim-1; - int parnum_cells = range.upper[ndim_perp]-range.lower[ndim_perp]+1; + int ndim_perp = range.ndim - 1; + int parnum_cells = range.upper[ndim_perp] - range.lower[ndim_perp] + 1; int idx[GKYL_MAX_CDIM]; long globalidx[32]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // Inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -173,34 +185,34 @@ gkyl_fem_parproj_bias_src_kernel(double *rhs_global, struct gkyl_rect_grid grid, int idx1d[] = {idx[ndim_perp]}; long paridx = gkyl_range_idx(&par_range1d, idx1d); - int keri = idx1d[0] == parnum_cells? 1 : 0; + int keri = idx1d[0] == parnum_cells ? 1 : 0; kers->l2g[keri](parnum_cells, paridx, globalidx); // Modify the RHS source to enforce biasing of the solution. int idx2d[] = {perp_range2d.lower[0], perp_range2d.lower[0]}; - for (int d=0; dperp_dirs[d]; double dx = grid.dx[perp_dir]; - bl_idx_m[d] = (bl->perp_coords[d]-1e-3*dx - grid.lower[perp_dir])/dx+1; + bl_idx_m[d] = (bl->perp_coords[d] - 1e-3 * dx - grid.lower[perp_dir]) / dx + 1; } - if ( - ( idx[bl->perp_dirs[0]] == bl_idx_m[0] && idx[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx[bl->perp_dirs[0]] == bl_idx_m[0] && idx[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) || - ( idx[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) - ) { + if ((idx[bl->perp_dirs[0]] == bl_idx_m[0] && idx[bl->perp_dirs[1]] == bl_idx_m[1]) || + (idx[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && idx[bl->perp_dirs[1]] == bl_idx_m[1]) || + (idx[bl->perp_dirs[0]] == bl_idx_m[0] && idx[bl->perp_dirs[1]] == bl_idx_m[1] + 1) || + (idx[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && idx[bl->perp_dirs[1]] == bl_idx_m[1] + 1)) { int edge[2] = { - -1+2*((bl_idx_m[0]+1)-idx[bl->perp_dirs[0]]), - -1+2*((bl_idx_m[1]+1)-idx[bl->perp_dirs[1]]), + -1 + 2 * ((bl_idx_m[0] + 1) - idx[bl->perp_dirs[0]]), + -1 + 2 * ((bl_idx_m[1] + 1) - idx[bl->perp_dirs[1]]) }; kers->bias_src_ker[keri](edge, bl->perp_dirs, bl->val, perpProbOff, globalidx, rhs_global); } @@ -208,28 +220,27 @@ gkyl_fem_parproj_bias_src_kernel(double *rhs_global, struct gkyl_rect_grid grid, } } -void -gkyl_fem_parproj_bias_src_enabled_cu(gkyl_fem_parproj *up, const struct gkyl_array *rhsin) +void gkyl_fem_parproj_bias_src_enabled_cu(gkyl_fem_parproj *up, const struct gkyl_array *rhsin) { double *rhs_cu = gkyl_culinsolver_get_rhs_ptr(up->prob_cu, 0); - gkyl_fem_parproj_bias_src_kernel<<nblocks, rhsin->nthreads>>>(rhs_cu, up->grid, - *up->solve_range, up->perp_range2d, up->par_range1d, up->kernels, up->numnodes_global, - up->num_bias_line, up->bias_lines); + gkyl_fem_parproj_bias_src_kernel<<nblocks, rhsin->nthreads> > >( + rhs_cu, up->grid, *up->solve_range, up->perp_range2d, up->par_range1d, up->kernels, + up->numnodes_global, up->num_bias_line, up->bias_lines + ); } -__global__ void -gkyl_fem_parproj_get_sol_kernel(struct gkyl_array *phiout, const double *x_global, struct gkyl_range range, - struct gkyl_range perp_range2d, struct gkyl_range par_range1d, struct gkyl_fem_parproj_kernels *kers, - long numnodes_global) +__global__ void gkyl_fem_parproj_get_sol_kernel( + struct gkyl_array *phiout, const double *x_global, struct gkyl_range range, + struct gkyl_range perp_range2d, struct gkyl_range par_range1d, + struct gkyl_fem_parproj_kernels *kers, long numnodes_global +) { int idx[GKYL_MAX_DIM]; long globalidx[32]; - int parnum_cells = range.upper[range.ndim-1]-range.lower[range.ndim-1]+1; + int parnum_cells = range.upper[range.ndim - 1] - range.lower[range.ndim - 1] + 1; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -238,17 +249,19 @@ gkyl_fem_parproj_get_sol_kernel(struct gkyl_array *phiout, const double *x_globa // convert back to a linear index on the super-range (with ghost cells) // linc will have jumps in it to jump over ghost cells long linidx = gkyl_range_idx(&range, idx); - double *phiout_p = (double*) gkyl_array_cfetch(phiout, linidx); + double *phiout_p = (double *)gkyl_array_cfetch(phiout, linidx); - int idx1d[] = {idx[range.ndim-1]}; + int idx1d[] = {idx[range.ndim - 1]}; long paridx = gkyl_range_idx(&par_range1d, idx1d); - int keri = idx1d[0] == parnum_cells? 1 : 0; + int keri = idx1d[0] == parnum_cells ? 1 : 0; kers->l2g[keri](parnum_cells, paridx, globalidx); int idx2d[] = {perp_range2d.lower[0], perp_range2d.lower[0]}; - for (int d=0; dprob_cu); double *x_cu = gkyl_culinsolver_get_sol_ptr(up->prob_cu, 0); - gkyl_fem_parproj_get_sol_kernel<<nblocks, phiout->nthreads>>>(phiout->on_dev, x_cu, - *up->solve_range, up->perp_range2d, up->par_range1d, up->kernels, up->numnodes_global); + gkyl_fem_parproj_get_sol_kernel<<nblocks, phiout->nthreads> > >( + phiout->on_dev, x_cu, *up->solve_range, up->perp_range2d, up->par_range1d, up->kernels, + up->numnodes_global + ); } diff --git a/gyrokinetic/zero/fem_poisson_perp.c b/gyrokinetic/zero/fem_poisson_perp.c index ae2e41d20b..61fd10a09f 100644 --- a/gyrokinetic/zero/fem_poisson_perp.c +++ b/gyrokinetic/zero/fem_poisson_perp.c @@ -2,14 +2,12 @@ #include #include -static void -fem_poisson_perp_bias_src_disabled(gkyl_fem_poisson_perp* up, struct gkyl_array *rhsin) +static void fem_poisson_perp_bias_src_disabled(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsin) { // Do nothing. } -static void -fem_poisson_perp_bias_src_enabled(gkyl_fem_poisson_perp* up, struct gkyl_array *rhsin) +static void fem_poisson_perp_bias_src_enabled(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsin) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { @@ -31,69 +29,75 @@ fem_poisson_perp_bias_src_enabled(gkyl_fem_poisson_perp* up, struct gkyl_array * while (gkyl_range_iter_next(&up->perp_iter2d)) { long perpidx = gkyl_range_idx(&up->perp_range2d, up->perp_iter2d.idx); - for (size_t d=0; dndim_perp; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->ndim_perp; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; int keri = idx_to_inup_ker(up->ndim_perp, up->num_cells, up->perp_iter2d.idx); - for (size_t d=0; dndim; d++) idx0[d] = idx1[d] - 1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = idx1[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); - long parProbOff = paridx*up->numnodes_global; + long parProbOff = paridx * up->numnodes_global; - for (int i=0; inum_bias_line; i++) { + for (int i = 0; i < up->num_bias_line; i++) { // Index of the cell that abuts the line from below. struct gkyl_poisson_bias_line *bl = &up->bias_lines[i]; int bl_idx_m[up->bl_ndim_perp]; - for (int d=0; dbl_ndim_perp; d++) { + for (int d = 0; d < up->bl_ndim_perp; d++) { int perp_dir = bl->perp_dirs[d]; double dx = up->grid.dx[perp_dir]; - bl_idx_m[d] = (bl->perp_coords[d]-1e-3*dx - up->grid.lower[perp_dir])/dx+1; + bl_idx_m[d] = (bl->perp_coords[d] - 1e-3 * dx - up->grid.lower[perp_dir]) / dx + 1; } - if ( - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) - ) { + if ((idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1]) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1]) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1] + 1) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1] + 1 + )) { int edge[2] = { - -1+2*((bl_idx_m[0]+1)-idx1[bl->perp_dirs[0]]), - -1+2*((bl_idx_m[1]+1)-idx1[bl->perp_dirs[1]]), + -1 + 2 * ((bl_idx_m[0] + 1) - idx1[bl->perp_dirs[0]]), + -1 + 2 * ((bl_idx_m[1] + 1) - idx1[bl->perp_dirs[1]]) }; - up->kernels->bias_src_ker[keri](edge, bl->perp_dirs, bl->val, parProbOff, up->globalidx, brhs_p); + up->kernels->bias_src_ker[keri]( + edge, bl->perp_dirs, bl->val, parProbOff, up->globalidx, brhs_p + ); } } } - } } -struct gkyl_fem_poisson_perp* -gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gkyl_rect_grid *grid, - const struct gkyl_basis basis, struct gkyl_poisson_bc *bcs, struct gkyl_poisson_bias_line_list *bias_lines, - struct gkyl_array *epsilon, struct gkyl_array *kSq, bool use_gpu) +struct gkyl_fem_poisson_perp *gkyl_fem_poisson_perp_new( + const struct gkyl_range *solve_range, const struct gkyl_rect_grid *grid, + const struct gkyl_basis basis, struct gkyl_poisson_bc *bcs, + struct gkyl_poisson_bias_line_list *bias_lines, struct gkyl_array *epsilon, + struct gkyl_array *kSq, bool use_gpu +) { - struct gkyl_fem_poisson_perp *up = gkyl_malloc(sizeof(struct gkyl_fem_poisson_perp)); up->solve_range = solve_range; up->ndim = grid->ndim; - up->ndim_perp = up->ndim-1; + up->ndim_perp = up->ndim - 1; up->grid = *grid; - up->num_basis = basis.num_basis; + up->num_basis = basis.num_basis; up->basis_type = basis.b_type; up->poly_order = basis.poly_order; - up->pardir = grid->ndim-1; // Assume parallel direction is always the last. + up->pardir = grid->ndim - 1; // Assume parallel direction is always the last. up->basis = basis; up->use_gpu = use_gpu; up->epsilon = gkyl_array_acquire(epsilon); assert(up->ndim > 1); - assert(up->epsilon->ncomp == (2*(up->ndim-1)-1)*basis.num_basis); + assert(up->epsilon->ncomp == (2 * (up->ndim - 1) - 1) * basis.num_basis); // We assume epsilon and kSq live on the device, and we create a host-side // copies temporarily to compute the LHS matrix. This also works for CPU solves. - struct gkyl_array *epsilon_ho = gkyl_array_new(GKYL_DOUBLE, up->epsilon->ncomp, up->epsilon->size); + struct gkyl_array *epsilon_ho = + gkyl_array_new(GKYL_DOUBLE, up->epsilon->ncomp, up->epsilon->size); gkyl_array_copy(epsilon_ho, up->epsilon); struct gkyl_array *kSq_ho; if (kSq) { @@ -105,34 +109,39 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky kSq_ho = gkyl_array_new(GKYL_DOUBLE, up->num_basis, 1); gkyl_array_clear(kSq_ho, 0.0); - up->kSq_null = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, kSq_ho->ncomp, kSq_ho->size) - : gkyl_array_acquire(kSq_ho); + up->kSq_null = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, kSq_ho->ncomp, kSq_ho->size) : + gkyl_array_acquire(kSq_ho); gkyl_array_clear(up->kSq_null, 0.0); } - up->globalidx = gkyl_malloc(sizeof(long[up->num_basis])); // global index, one for each basis in a cell. + up->globalidx = + gkyl_malloc(sizeof(long[up->num_basis])); // global index, one for each basis in a cell. - for (int d=0; dndim; d++) up->num_cells[d] = up->solve_range->upper[d]-up->solve_range->lower[d]+1; + for (int d = 0; d < up->ndim; d++) { + up->num_cells[d] = up->solve_range->upper[d] - up->solve_range->lower[d] + 1; + } // 2D range of perpendicular cells. gkyl_range_init(&up->perp_range2d, up->ndim_perp, up->solve_range->lower, up->solve_range->upper); // 1D range of parallel cells. - int lower1d[] = {up->solve_range->lower[up->pardir]}, upper1d[] = {up->solve_range->upper[up->pardir]}; + int lower1d[] = {up->solve_range->lower[up->pardir]}, + upper1d[] = {up->solve_range->upper[up->pardir]}; gkyl_range_init(&up->par_range1d, 1, lower1d, upper1d); // Range of perpendicular cells at each parallel location. - up->perp_range = (struct gkyl_range *) gkyl_malloc(up->par_range1d.volume * sizeof(struct gkyl_range)); + up->perp_range = + (struct gkyl_range *)gkyl_malloc(up->par_range1d.volume * sizeof(struct gkyl_range)); gkyl_range_iter_init(&up->par_iter1d, &up->par_range1d); while (gkyl_range_iter_next(&up->par_iter1d)) { long paridx = gkyl_range_idx(&up->par_range1d, up->par_iter1d.idx); - int removeDim[] = {0,0,0}, loc[] = {0,0,0}; + int removeDim[] = {0, 0, 0}, loc[] = {0, 0, 0}; removeDim[up->pardir] = 1; loc[up->pardir] = paridx; gkyl_range_deflate(&up->perp_range[paridx], up->solve_range, removeDim, loc); } // Range of parallel cells. int sublower[GKYL_MAX_CDIM], subupper[GKYL_MAX_CDIM]; - for (int d=0; dndim; d++) { + for (int d = 0; d < up->ndim; d++) { sublower[d] = up->solve_range->lower[d]; subupper[d] = up->solve_range->lower[d]; } @@ -140,78 +149,98 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky gkyl_sub_range_init(&up->par_range, up->solve_range, sublower, subupper); // Prepare for periodic domain case. - for (int d=0; dndim_perp; d++) { + for (int d = 0; d < up->ndim_perp; d++) { // Sanity check. if ((bcs->lo_type[d] == GKYL_POISSON_PERIODIC && bcs->up_type[d] != GKYL_POISSON_PERIODIC) || - (bcs->lo_type[d] != GKYL_POISSON_PERIODIC && bcs->up_type[d] == GKYL_POISSON_PERIODIC)) + (bcs->lo_type[d] != GKYL_POISSON_PERIODIC && bcs->up_type[d] == GKYL_POISSON_PERIODIC)) { assert(false); + } + } + for (int d = 0; d < up->ndim_perp; d++) { + up->isdirperiodic[d] = bcs->lo_type[d] == GKYL_POISSON_PERIODIC; } - for (int d=0; dndim_perp; d++) up->isdirperiodic[d] = bcs->lo_type[d] == GKYL_POISSON_PERIODIC; up->isdomperiodic = true; - for (int d=0; dndim_perp; d++) up->isdomperiodic = up->isdomperiodic && up->isdirperiodic[d]; -// assert(up->isdomperiodic == false); // MF 2023/06/29: there's an error in -// // the periodic domain case I have not -// // solved. + for (int d = 0; d < up->ndim_perp; d++) { + up->isdomperiodic = up->isdomperiodic && up->isdirperiodic[d]; + } + // assert(up->isdomperiodic == false); // MF 2023/06/29: there's an error in + // // the periodic domain case I have not + // // solved. if (up->isdomperiodic) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { up->rhs_cellavg = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, epsilon->size); - up->rhs_avg_cu = (double*) gkyl_cu_malloc(sizeof(double)); + up->rhs_avg_cu = (double *)gkyl_cu_malloc(sizeof(double)); } else { up->rhs_cellavg = gkyl_array_new(GKYL_DOUBLE, 1, epsilon->size); } #else up->rhs_cellavg = gkyl_array_new(GKYL_DOUBLE, 1, epsilon->size); #endif - up->rhs_avg = (double*) gkyl_malloc(sizeof(double)); + up->rhs_avg = (double *)gkyl_malloc(sizeof(double)); gkyl_array_clear(up->rhs_cellavg, 0.0); // Factor accounting for normalization when subtracting a constant from a // DG field and the 1/N to properly compute the volume averaged RHS. - up->mavgfac = -pow(sqrt(2.),up->ndim)/up->perp_range2d.volume; + up->mavgfac = -pow(sqrt(2.), up->ndim) / up->perp_range2d.volume; } // Pack BC values into a single array for easier use in kernels. - for (int d=0; dndim_perp; d++) { - for (int k=0; k<6; k++) up->bcvals[d*2*3+k] = 0.0; // default. Not used in some cases (e.g. periodic). + for (int d = 0; d < up->ndim_perp; d++) { + for (int k = 0; k < 6; k++) { + up->bcvals[d * 2 * 3 + k] = 0.0; // default. Not used in some cases (e.g. periodic). + } if (bcs->lo_type[d] != GKYL_POISSON_PERIODIC) { int vnum, voff; vnum = 1; voff = 2; - for (int k=0; kbcvals[d*2*3+voff+k] = bcs->lo_value[d].v[k]; + for (int k = 0; k < vnum; k++) { + up->bcvals[d * 2 * 3 + voff + k] = bcs->lo_value[d].v[k]; + } vnum = 1; voff = 2; - for (int k=0; kbcvals[d*2*3+voff+3+k] = bcs->up_value[d].v[k]; + for (int k = 0; k < vnum; k++) { + up->bcvals[d * 2 * 3 + voff + 3 + k] = bcs->up_value[d].v[k]; + } } } #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - up->bcvals_cu = (double *) gkyl_cu_malloc(sizeof(double[PERP_DIM_MAX*3*2])); - gkyl_cu_memcpy(up->bcvals_cu, up->bcvals, sizeof(double[PERP_DIM_MAX*3*2]), GKYL_CU_MEMCPY_H2D); + up->bcvals_cu = (double *)gkyl_cu_malloc(sizeof(double[PERP_DIM_MAX * 3 * 2])); + gkyl_cu_memcpy( + up->bcvals_cu, up->bcvals, sizeof(double[PERP_DIM_MAX * 3 * 2]), GKYL_CU_MEMCPY_H2D + ); } #endif // Compute the number of local and global nodes. up->numnodes_local = up->num_basis; - up->numnodes_global = gkyl_fem_poisson_perp_global_num_nodes(up->ndim, up->poly_order, basis.b_type, up->num_cells, up->isdirperiodic); + up->numnodes_global = gkyl_fem_poisson_perp_global_num_nodes( + up->ndim, up->poly_order, basis.b_type, up->num_cells, up->isdirperiodic + ); - for (int d=0; dndim; d++) up->dx[d] = up->grid.dx[d]; // Cell lengths. + for (int d = 0; d < up->ndim; d++) { + up->dx[d] = up->grid.dx[d]; // Cell lengths. + } #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - up->dx_cu = (double *) gkyl_cu_malloc(sizeof(double[GKYL_MAX_CDIM])); + up->dx_cu = (double *)gkyl_cu_malloc(sizeof(double[GKYL_MAX_CDIM])); gkyl_cu_memcpy(up->dx_cu, up->dx, sizeof(double[GKYL_MAX_CDIM]), GKYL_CU_MEMCPY_H2D); } #endif - up->brhs = gkyl_array_new(GKYL_DOUBLE, 1, up->numnodes_global*up->par_range.volume); // Global right side vector. + up->brhs = gkyl_array_new( + GKYL_DOUBLE, 1, up->numnodes_global * up->par_range.volume + ); // Global right side vector. up->kernels = gkyl_malloc(sizeof(struct gkyl_fem_poisson_perp_kernels)); #ifdef GKYL_HAVE_CUDA - if (use_gpu) + if (use_gpu) { up->kernels_cu = gkyl_cu_malloc(sizeof(struct gkyl_fem_poisson_perp_kernels)); - else + } else { up->kernels_cu = up->kernels; + } #else up->kernels_cu = up->kernels; #endif @@ -229,8 +258,9 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky up->kernels->solker = fem_poisson_perp_choose_sol_kernels(&basis); #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { fem_poisson_perp_choose_kernels_cu(&basis, bcs, up->isdirperiodic, up->kernels_cu); + } #endif // Copy the biasing line list (bias_lines) into this updater. @@ -240,40 +270,46 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky if (bias_lines->num_bias_line > 0) { // Check if any bias lines are in solve_range, and copy their info into updater. bl_in_solve_range = gkyl_malloc(bias_lines->num_bias_line * sizeof(bool)); - for (int i=0; inum_bias_line; i++) + for (int i = 0; i < bias_lines->num_bias_line; i++) { bl_in_solve_range[i] = false; + } - for (int i=0; inum_bias_line; i++) { + for (int i = 0; i < bias_lines->num_bias_line; i++) { struct gkyl_poisson_bias_line *bl = &bias_lines->bl[i]; // MF 2025/11/10: For now limit ourselves to lines perpendicular to x and z. up->bl_ndim_perp = 2; - assert(bl->perp_dirs[0] == 0 && bl->perp_dirs[1] == up->ndim-1); + assert(bl->perp_dirs[0] == 0 && bl->perp_dirs[1] == up->ndim - 1); double line_coords[up->ndim]; - for (int d=0; dndim; d++) - line_coords[d] = grid->lower[d]+grid->dx[d]/2.0; + for (int d = 0; d < up->ndim; d++) { + line_coords[d] = grid->lower[d] + grid->dx[d] / 2.0; + } - for (int d=0; dbl_ndim_perp; d++) + for (int d = 0; d < up->bl_ndim_perp; d++) { line_coords[bl->perp_dirs[d]] = bl->perp_coords[d]; + } // If biased line is at domain boundary, shift it minimally so it is inside the domain. - for (int d=0; dndim; d++) { - if (fabs(line_coords[d] - grid->lower[d]) < 1e-3*grid->dx[d]) { - line_coords[d] += 1e-3*grid->dx[d]; + for (int d = 0; d < up->ndim; d++) { + if (fabs(line_coords[d] - grid->lower[d]) < 1e-3 * grid->dx[d]) { + line_coords[d] += 1e-3 * grid->dx[d]; } - if (fabs(line_coords[d] - grid->upper[d]) < 1e-3*grid->dx[d]) { - line_coords[d] += -1e-3*grid->dx[d]; + if (fabs(line_coords[d] - grid->upper[d]) < 1e-3 * grid->dx[d]) { + line_coords[d] += -1e-3 * grid->dx[d]; } } - bool pick_lower[3] = {true, true, true}; // If at a cell boundary, pick the cell lower than the biased line. + bool pick_lower[3] = { + true, true, true + }; // If at a cell boundary, pick the cell lower than the biased line. int line_idx[GKYL_MAX_CDIM]; - gkyl_rect_grid_find_cell(grid, line_coords, pick_lower, (int[3]){-1,-1,-1}, line_idx); + gkyl_rect_grid_find_cell(grid, line_coords, pick_lower, (int[3]){-1, -1, -1}, line_idx); bl_in_solve_range[i] = gkyl_range_contains_idx(solve_range, line_idx); - if (bl_in_solve_range[i]) + if (bl_in_solve_range[i]) { up->num_bias_line++; + } } if (up->num_bias_line) { @@ -281,7 +317,7 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky size_t bl_sz = up->num_bias_line * sizeof(struct gkyl_poisson_bias_line); struct gkyl_poisson_bias_line *bias_lines_buff = gkyl_malloc(bl_sz); int blc = 0; - for (int i=0; inum_bias_line; i++) { + for (int i = 0; i < bias_lines->num_bias_line; i++) { if (bl_in_solve_range[i]) { struct gkyl_poisson_bias_line *bl = &bias_lines->bl[i]; memcpy(&bias_lines_buff[blc], &bias_lines->bl[i], sizeof(struct gkyl_poisson_bias_line)); @@ -292,16 +328,19 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky if (up->use_gpu) { up->bias_lines = gkyl_cu_malloc(bl_sz); gkyl_cu_memcpy(up->bias_lines, bias_lines_buff, bl_sz, GKYL_CU_MEMCPY_H2D); - } - else { + } else { up->bias_lines = gkyl_malloc(bl_sz); memcpy(up->bias_lines, bias_lines_buff, bl_sz); } gkyl_free(bias_lines_buff); // Select biasing kernels: - fem_poisson_perp_choose_bias_lhs_kernels(&basis, up->isdirperiodic, up->kernels->bias_lhs_ker); - fem_poisson_perp_choose_bias_src_kernels(&basis, up->isdirperiodic, up->kernels->bias_src_ker); + fem_poisson_perp_choose_bias_lhs_kernels( + &basis, up->isdirperiodic, up->kernels->bias_lhs_ker + ); + fem_poisson_perp_choose_bias_src_kernels( + &basis, up->isdirperiodic, up->kernels->bias_src_ker + ); } } } @@ -312,24 +351,29 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky // structure for the GPU solve. #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - up->prob_cu = gkyl_culinsolver_prob_new(up->par_range.volume, up->numnodes_global, up->numnodes_global, 1); + up->prob_cu = + gkyl_culinsolver_prob_new(up->par_range.volume, up->numnodes_global, up->numnodes_global, 1); } else { - up->prob = gkyl_superlu_prob_new(up->par_range.volume, up->numnodes_global, up->numnodes_global, 1); + up->prob = + gkyl_superlu_prob_new(up->par_range.volume, up->numnodes_global, up->numnodes_global, 1); } #else - up->prob = gkyl_superlu_prob_new(up->par_range.volume, up->numnodes_global, up->numnodes_global, 1); + up->prob = + gkyl_superlu_prob_new(up->par_range.volume, up->numnodes_global, up->numnodes_global, 1); #endif - up->tri = gkyl_malloc(up->par_range.volume*sizeof(struct gkyl_mat_triples *)); - for (size_t i=0; ipar_range.volume; i++) { + up->tri = gkyl_malloc(up->par_range.volume * sizeof(struct gkyl_mat_triples *)); + for (size_t i = 0; i < up->par_range.volume; i++) { up->tri[i] = gkyl_mat_triples_new(up->numnodes_global, up->numnodes_global); #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) gkyl_mat_triples_set_rowmaj_order(up->tri[i]); + if (up->use_gpu) { + gkyl_mat_triples_set_rowmaj_order(up->tri[i]); + } #endif } // Assign non-zero elements in A. - int idx0[GKYL_MAX_CDIM], idx1[GKYL_MAX_CDIM]; + int idx0[GKYL_MAX_CDIM], idx1[GKYL_MAX_CDIM]; gkyl_range_iter_init(&up->par_iter1d, &up->par_range1d); while (gkyl_range_iter_next(&up->par_iter1d)) { long paridx = gkyl_range_idx(&up->par_range1d, up->par_iter1d.idx); @@ -338,16 +382,21 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky while (gkyl_range_iter_next(&up->perp_iter2d)) { long perpidx = gkyl_range_idx(&up->perp_range2d, up->perp_iter2d.idx); - for (size_t d=0; dndim_perp; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->ndim_perp; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; long linidx = gkyl_range_idx(up->solve_range, idx1); double *eps_p = gkyl_array_fetch(epsilon_ho, linidx); - double *kSq_p = up->ishelmholtz? gkyl_array_fetch(kSq_ho, linidx) : gkyl_array_fetch(kSq_ho,0); + double *kSq_p = up->ishelmholtz ? gkyl_array_fetch(kSq_ho, linidx) : + gkyl_array_fetch(kSq_ho, 0); int keri = idx_to_inup_ker(up->ndim_perp, up->num_cells, up->perp_iter2d.idx); - for (size_t d=0; dndim; d++) idx0[d] = idx1[d] - 1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = idx1[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); // Apply the -nabla . (epsilon*nabla_perp)-kSq stencil. @@ -367,33 +416,38 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky while (gkyl_range_iter_next(&up->perp_iter2d)) { long perpidx = gkyl_range_idx(&up->perp_range2d, up->perp_iter2d.idx); - for (size_t d=0; dndim_perp; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->ndim_perp; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; int keri = idx_to_inup_ker(up->ndim_perp, up->num_cells, up->perp_iter2d.idx); - for (size_t d=0; dndim; d++) idx0[d] = idx1[d] - 1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = idx1[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); - for (int i=0; inum_bias_line; i++) { + for (int i = 0; i < bias_lines->num_bias_line; i++) { if (bl_in_solve_range[i]) { // Index of the cell that abuts the line from below. struct gkyl_poisson_bias_line *bl = &bias_lines->bl[i]; int bl_idx_m[up->bl_ndim_perp]; - for (int d=0; dbl_ndim_perp; d++) { + for (int d = 0; d < up->bl_ndim_perp; d++) { int perp_dir = bl->perp_dirs[d]; double dx = up->grid.dx[perp_dir]; - bl_idx_m[d] = (bl->perp_coords[d]-1e-3*dx - up->grid.lower[perp_dir])/dx+1; + bl_idx_m[d] = (bl->perp_coords[d] - 1e-3 * dx - up->grid.lower[perp_dir]) / dx + 1; } - if ( - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) || - ( idx1[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) - ) { + if ((idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1]) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && idx1[bl->perp_dirs[1]] == bl_idx_m[1] + ) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] && idx1[bl->perp_dirs[1]] == bl_idx_m[1] + 1 + ) || + (idx1[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && + idx1[bl->perp_dirs[1]] == bl_idx_m[1] + 1)) { int edge[2] = { - -1+2*((bl_idx_m[0]+1)-idx1[bl->perp_dirs[0]]), - -1+2*((bl_idx_m[1]+1)-idx1[bl->perp_dirs[1]]), + -1 + 2 * ((bl_idx_m[0] + 1) - idx1[bl->perp_dirs[0]]), + -1 + 2 * ((bl_idx_m[1] + 1) - idx1[bl->perp_dirs[1]]) }; up->kernels->bias_lhs_ker[keri](edge, bl->perp_dirs, up->globalidx, up->tri[paridx]); } @@ -403,26 +457,30 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky } up->bias_line_src = fem_poisson_perp_bias_src_enabled; - } - else { + } else { up->bias_line_src = fem_poisson_perp_bias_src_disabled; } - if (bl_in_solve_range) + if (bl_in_solve_range) { gkyl_free(bl_in_solve_range); + } - if (!(up->use_gpu)) + if (!(up->use_gpu)) { gkyl_superlu_amat_from_triples(up->prob, up->tri); + } #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { gkyl_culinsolver_amat_from_triples(up->prob_cu, up->tri); + } #endif #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { // Store offsets into csr_val in cudss_ops.cu so we can update the LHS matrix on the GPU. - up->csr_val_idx = gkyl_array_cu_dev_new(GKYL_LONG, pow(up->basis.num_basis, 2), up->epsilon->size); - struct gkyl_array *csr_val_idx_ho = gkyl_array_new(GKYL_LONG, up->csr_val_idx->ncomp, up->csr_val_idx->size); + up->csr_val_idx = + gkyl_array_cu_dev_new(GKYL_LONG, pow(up->basis.num_basis, 2), up->epsilon->size); + struct gkyl_array *csr_val_idx_ho = + gkyl_array_new(GKYL_LONG, up->csr_val_idx->ncomp, up->csr_val_idx->size); gkyl_range_iter_init(&up->par_iter1d, &up->par_range1d); while (gkyl_range_iter_next(&up->par_iter1d)) { @@ -432,7 +490,9 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky while (gkyl_range_iter_next(&up->perp_iter2d)) { long perpidx = gkyl_range_idx(&up->perp_range2d, up->perp_iter2d.idx); - for (size_t d=0; dndim_perp; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->ndim_perp; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; long linidx = gkyl_range_idx(up->solve_range, idx1); @@ -440,17 +500,19 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky long *csr_val_idx_p = gkyl_array_fetch(csr_val_idx_ho, linidx); int keri = idx_to_inup_ker(up->ndim_perp, up->num_cells, up->perp_iter2d.idx); - for (size_t d=0; dndim; d++) idx0[d] = idx1[d] - 1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = idx1[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); - for (int k=0; kbasis.num_basis; k++) { - for (int l=0; lbasis.num_basis; l++) { + for (int k = 0; k < up->basis.num_basis; k++) { + for (int l = 0; l < up->basis.num_basis; l++) { size_t nnz = gkyl_mat_triples_size(up->tri[paridx]); // Number of nonzero elements. - // Given the global i,j (row-col) place in the LHS matrix, find the linear index into the mat_triples list. + // Given the global i,j (row-col) place in the LHS matrix, find the linear index into the mat_triples list. // Here we do a brute-force search as we are unsure of the order, and this is done only once at t=0. long off = -1; gkyl_mat_triples_iter *mtt_iter = gkyl_mat_triples_iter_new(up->tri[paridx]); - for (size_t m=0; mglobalidx[k] == mt.row) && (up->globalidx[l] == mt.col)) { @@ -458,7 +520,7 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky break; } } - csr_val_idx_p[k*up->basis.num_basis+l] = paridx*nnz + off; + csr_val_idx_p[k * up->basis.num_basis + l] = paridx * nnz + off; } } } @@ -470,8 +532,9 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky #endif if (up->use_gpu) { - for (size_t i=0; ipar_range.volume; i++) + for (size_t i = 0; i < up->par_range.volume; i++) { gkyl_mat_triples_release(up->tri[i]); + } gkyl_free(up->tri); } @@ -482,10 +545,8 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky return up; } -void -gkyl_fem_poisson_perp_set_rhs(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsin) +void gkyl_fem_poisson_perp_set_rhs(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsin) { - if (up->isdomperiodic && !(up->ishelmholtz)) { // Subtract the volume averaged RHS from the RHS. gkyl_array_clear(up->rhs_cellavg, 0.0); @@ -498,7 +559,9 @@ gkyl_fem_poisson_perp_set_rhs(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsi #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - gkyl_array_reduce_range(up->rhs_avg_cu, up->rhs_cellavg, GKYL_SUM, &(up->perp_range[paridx])); + gkyl_array_reduce_range( + up->rhs_avg_cu, up->rhs_cellavg, GKYL_SUM, &(up->perp_range[paridx]) + ); gkyl_cu_memcpy(up->rhs_avg, up->rhs_avg_cu, sizeof(double), GKYL_CU_MEMCPY_D2H); } else { gkyl_array_reduce_range(up->rhs_avg, up->rhs_cellavg, GKYL_SUM, &(up->perp_range[paridx])); @@ -506,11 +569,10 @@ gkyl_fem_poisson_perp_set_rhs(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsi #else gkyl_array_reduce_range(up->rhs_avg, up->rhs_cellavg, GKYL_SUM, &(up->perp_range[paridx])); #endif - gkyl_array_shiftc_range(rhsin, up->mavgfac*up->rhs_avg[0], 0, &(up->perp_range[paridx])); + gkyl_array_shiftc_range(rhsin, up->mavgfac * up->rhs_avg[0], 0, &(up->perp_range[paridx])); } } - #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { assert(gkyl_array_is_cu_dev(rhsin)); @@ -532,7 +594,9 @@ gkyl_fem_poisson_perp_set_rhs(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsi while (gkyl_range_iter_next(&up->perp_iter2d)) { long perpidx = gkyl_range_idx(&up->perp_range2d, up->perp_iter2d.idx); - for (size_t d=0; dndim_perp; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->ndim_perp; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; long linidx = gkyl_range_idx(up->solve_range, idx1); @@ -541,29 +605,31 @@ gkyl_fem_poisson_perp_set_rhs(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsi double *rhsin_p = gkyl_array_fetch(rhsin, linidx); int keri = idx_to_inup_ker(up->ndim_perp, up->num_cells, up->perp_iter2d.idx); - for (size_t d=0; dndim; d++) idx0[d] = idx1[d] - 1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = idx1[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); // Apply the RHS source stencil. It's mostly the mass matrix times a // modal-to-nodal operator times the source, modified by BCs in skin cells. keri = idx_to_inloup_ker(up->ndim_perp, up->num_cells, idx1); - long parProbOff = paridx*up->numnodes_global; + long parProbOff = paridx * up->numnodes_global; - up->kernels->srcker[keri](eps_p, up->dx, rhsin_p, up->bcvals, parProbOff, up->globalidx, brhs_p); + up->kernels->srcker[keri]( + eps_p, up->dx, rhsin_p, up->bcvals, parProbOff, up->globalidx, brhs_p + ); } - } // Set the corresponding entries to the biasing potential. up->bias_line_src(up, rhsin); gkyl_superlu_brhs_from_array(up->prob, brhs_p); - } -void -gkyl_fem_poisson_perp_solve(gkyl_fem_poisson_perp *up, struct gkyl_array *phiout) { +void gkyl_fem_poisson_perp_solve(gkyl_fem_poisson_perp *up, struct gkyl_array *phiout) +{ #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { assert(gkyl_array_is_cu_dev(phiout)); @@ -580,12 +646,14 @@ gkyl_fem_poisson_perp_solve(gkyl_fem_poisson_perp *up, struct gkyl_array *phiout gkyl_range_iter_init(&up->par_iter1d, &up->par_range1d); while (gkyl_range_iter_next(&up->par_iter1d)) { long paridx = gkyl_range_idx(&up->par_range1d, up->par_iter1d.idx); - + gkyl_range_iter_init(&up->perp_iter2d, &up->perp_range2d); while (gkyl_range_iter_next(&up->perp_iter2d)) { long perpidx = gkyl_range_idx(&up->perp_range2d, up->perp_iter2d.idx); - for (size_t d=0; dndim_perp; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->ndim_perp; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; long linidx = gkyl_range_idx(up->solve_range, idx1); @@ -593,33 +661,38 @@ gkyl_fem_poisson_perp_solve(gkyl_fem_poisson_perp *up, struct gkyl_array *phiout double *phiout_p = gkyl_array_fetch(phiout, linidx); int keri = idx_to_inup_ker(up->ndim_perp, up->num_cells, up->perp_iter2d.idx); - for (size_t d=0; dndim; d++) idx0[d] = idx1[d]-1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = idx1[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); - long parProbOff = paridx*up->numnodes_global; + long parProbOff = paridx * up->numnodes_global; - up->kernels->solker(gkyl_superlu_get_rhs_ptr(up->prob, 0), parProbOff, up->globalidx, phiout_p); + up->kernels->solker( + gkyl_superlu_get_rhs_ptr(up->prob, 0), parProbOff, up->globalidx, phiout_p + ); } } - } -void -gkyl_fem_poisson_perp_update_lhs(gkyl_fem_poisson_perp *up, struct gkyl_array *epsilon, struct gkyl_array *kSq) +void gkyl_fem_poisson_perp_update_lhs( + gkyl_fem_poisson_perp *up, struct gkyl_array *epsilon, struct gkyl_array *kSq +) { assert(up->num_bias_line == 0); // Have not accounted for bias in csr_val_idx. #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { assert(gkyl_array_is_cu_dev(epsilon)); - if (up->ishelmholtz) + if (up->ishelmholtz) { assert(gkyl_array_is_cu_dev(kSq)); + } gkyl_fem_poisson_perp_update_lhs_cu(up, epsilon, kSq); return; } #endif - int idx0[GKYL_MAX_CDIM], idx1[GKYL_MAX_CDIM]; + int idx0[GKYL_MAX_CDIM], idx1[GKYL_MAX_CDIM]; gkyl_range_iter_init(&up->par_iter1d, &up->par_range1d); while (gkyl_range_iter_next(&up->par_iter1d)) { long paridx = gkyl_range_idx(&up->par_range1d, up->par_iter1d.idx); @@ -631,16 +704,21 @@ gkyl_fem_poisson_perp_update_lhs(gkyl_fem_poisson_perp *up, struct gkyl_array *e while (gkyl_range_iter_next(&up->perp_iter2d)) { long perpidx = gkyl_range_idx(&up->perp_range2d, up->perp_iter2d.idx); - for (size_t d=0; dndim_perp; d++) idx1[d] = up->perp_iter2d.idx[d]; + for (size_t d = 0; d < up->ndim_perp; d++) { + idx1[d] = up->perp_iter2d.idx[d]; + } idx1[up->pardir] = up->par_iter1d.idx[0]; long linidx = gkyl_range_idx(up->solve_range, idx1); double *eps_p = gkyl_array_fetch(epsilon, linidx); - double *kSq_p = up->ishelmholtz? gkyl_array_fetch(kSq, linidx) : gkyl_array_fetch(up->kSq_null,0); + double *kSq_p = up->ishelmholtz ? gkyl_array_fetch(kSq, linidx) : + gkyl_array_fetch(up->kSq_null, 0); int keri = idx_to_inup_ker(up->ndim_perp, up->num_cells, up->perp_iter2d.idx); - for (size_t d=0; dndim; d++) idx0[d] = idx1[d] - 1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = idx1[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); // Apply the -nabla . (epsilon*nabla_perp)-kSq stencil. @@ -659,31 +737,36 @@ void gkyl_fem_poisson_perp_release(struct gkyl_fem_poisson_perp *up) gkyl_free(up->rhs_avg); } - if (!(up->ishelmholtz)) + if (!(up->ishelmholtz)) { gkyl_array_release(up->kSq_null); + } if (!(up->use_gpu)) { - for (size_t i=0; ipar_range.volume; i++) + for (size_t i = 0; i < up->par_range.volume; i++) { gkyl_mat_triples_release(up->tri[i]); + } gkyl_free(up->tri); gkyl_superlu_prob_release(up->prob); - if (up->num_bias_line > 0) + if (up->num_bias_line > 0) { gkyl_free(up->bias_lines); + } } #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { gkyl_cu_free(up->kernels_cu); gkyl_cu_free(up->dx_cu); - if (up->isdomperiodic) + if (up->isdomperiodic) { gkyl_cu_free(up->rhs_avg_cu); + } gkyl_cu_free(up->bcvals_cu); gkyl_array_release(up->csr_val_idx); gkyl_culinsolver_prob_release(up->prob_cu); - if (up->num_bias_line > 0) + if (up->num_bias_line > 0) { gkyl_cu_free(up->bias_lines); + } } #endif diff --git a/gyrokinetic/zero/fem_poisson_perp_cu.cu b/gyrokinetic/zero/fem_poisson_perp_cu.cu index 8ca522353d..81987b7f74 100644 --- a/gyrokinetic/zero/fem_poisson_perp_cu.cu +++ b/gyrokinetic/zero/fem_poisson_perp_cu.cu @@ -10,49 +10,53 @@ extern "C" { // CUDA kernel to set device pointers to l2g kernel function. // Doing function pointer stuff in here avoids troublesome // cudaMemcpyFromSymbol. -__global__ static void -fem_poisson_perp_set_cu_l2gker_ptrs(struct gkyl_fem_poisson_perp_kernels* kers, int ndim, enum gkyl_basis_type b_type, - int poly_order, const int *bckey) +__global__ static void fem_poisson_perp_set_cu_l2gker_ptrs( + struct gkyl_fem_poisson_perp_kernels *kers, int ndim, enum gkyl_basis_type b_type, int poly_order, + const int *bckey +) { - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; // Set l2g kernels. const local2global_kern_bcx_list_2x *local2global_2x_kernels; const local2global_kern_bcx_list_3x *local2global_3x_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - local2global_2x_kernels = ser_loc2glob_list_2x; - local2global_3x_kernels = ser_loc2glob_list_3x; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + local2global_2x_kernels = ser_loc2glob_list_2x; + local2global_3x_kernels = ser_loc2glob_list_3x; + break; + default: + assert(false); + break; } - for (int k=0; kl2g[k] = ndim == 2? CK2x(local2global_2x_kernels, poly_order, k, bckey[0]) - : CK3x(local2global_3x_kernels, poly_order, k, bckey[0], bckey[1]); + for (int k = 0; k < GKYL_IPOW(2, ndim_perp); k++) { + kers->l2g[k] = ndim == 2 ? CK2x(local2global_2x_kernels, poly_order, k, bckey[0]) : + CK3x(local2global_3x_kernels, poly_order, k, bckey[0], bckey[1]); + } } // CUDA kernel to set device pointers to RHS src and solution kernels. -__global__ static void -fem_poisson_perp_set_cu_ker_ptrs(struct gkyl_fem_poisson_perp_kernels* kers, enum gkyl_basis_type b_type, - int ndim, int poly_order, const int *bckey) +__global__ static void fem_poisson_perp_set_cu_ker_ptrs( + struct gkyl_fem_poisson_perp_kernels *kers, enum gkyl_basis_type b_type, int ndim, int poly_order, + const int *bckey +) { - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; klhsker[k] = ndim == 2? CK2x(ser_lhsstencil_list_2x, poly_order, k, bckey[0]) - : CK3x(ser_lhsstencil_list_3x, poly_order, k, bckey[0], bckey[1]); - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < GKYL_IPOW(3, ndim_perp); k++) { + kers->lhsker[k] = ndim == 2 ? CK2x(ser_lhsstencil_list_2x, poly_order, k, bckey[0]) : + CK3x(ser_lhsstencil_list_3x, poly_order, k, bckey[0], bckey[1]); + } + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } // Set RHS stencil kernels. @@ -60,115 +64,130 @@ fem_poisson_perp_set_cu_ker_ptrs(struct gkyl_fem_poisson_perp_kernels* kers, enu const srcstencil_kern_bcx_list_3x *srcstencil_3x_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - srcstencil_2x_kernels = ser_srcstencil_list_2x; - srcstencil_3x_kernels = ser_srcstencil_list_3x; - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); + case GKYL_BASIS_MODAL_SERENDIPITY: + srcstencil_2x_kernels = ser_srcstencil_list_2x; + srcstencil_3x_kernels = ser_srcstencil_list_3x; + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); } - for (int k=0; ksrcker[k] = ndim == 2? CK2x(srcstencil_2x_kernels, poly_order, k, bckey[0]) - : CK3x(srcstencil_3x_kernels, poly_order, k, bckey[0], bckey[1]); + for (int k = 0; k < GKYL_IPOW(3, ndim_perp); k++) { + kers->srcker[k] = ndim == 2 ? CK2x(srcstencil_2x_kernels, poly_order, k, bckey[0]) : + CK3x(srcstencil_3x_kernels, poly_order, k, bckey[0], bckey[1]); + } // Set the get solution stencil kernel. const solstencil_kern_list *solstencil_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - solstencil_kernels = ser_solstencil_list; - break; - case GKYL_BASIS_MODAL_TENSOR: - break; - default: - assert(false); + case GKYL_BASIS_MODAL_SERENDIPITY: + solstencil_kernels = ser_solstencil_list; + break; + case GKYL_BASIS_MODAL_TENSOR: + break; + default: + assert(false); } kers->solker = solstencil_kernels[ndim].kernels[poly_order]; } -__global__ static void -fem_poisson_perp_set_cu_biasker_ptrs(struct gkyl_fem_poisson_perp_kernels* kers, - int ndim, enum gkyl_basis_type b_type, int poly_order, const int *bckey) +__global__ static void fem_poisson_perp_set_cu_biasker_ptrs( + struct gkyl_fem_poisson_perp_kernels *kers, int ndim, enum gkyl_basis_type b_type, int poly_order, + const int *bckey +) { - // Set biasing kernels. - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; const bias_src_kern_bcx_list_2x *bias_plane_2x_kernels; const bias_src_kern_bcx_list_3x *bias_plane_3x_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - bias_plane_2x_kernels = ser_bias_src_list_2x; - bias_plane_3x_kernels = ser_bias_src_list_3x; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + bias_plane_2x_kernels = ser_bias_src_list_2x; + bias_plane_3x_kernels = ser_bias_src_list_3x; + break; + default: + assert(false); + break; } - for (int k=0; k<(int)(pow(2,ndim_perp)+0.5); k++) { + for (int k = 0; k < (int)(pow(2, ndim_perp) + 0.5); k++) { if (ndim == 2) { kers->bias_src_ker[k] = CK2x(bias_plane_2x_kernels, poly_order, k, bckey[0]); - } else if ( ndim == 3) { + } else if (ndim == 3) { kers->bias_src_ker[k] = CK3x(bias_plane_3x_kernels, poly_order, k, bckey[0], bckey[1]); } } - } -void -fem_poisson_perp_choose_kernels_cu(const struct gkyl_basis* basis, const struct gkyl_poisson_bc *bcs, - const bool *isdirperiodic, struct gkyl_fem_poisson_perp_kernels *kers) +void fem_poisson_perp_choose_kernels_cu( + const struct gkyl_basis *basis, const struct gkyl_poisson_bc *bcs, const bool *isdirperiodic, + struct gkyl_fem_poisson_perp_kernels *kers +) { - int poly_order = basis->poly_order; int ndim = basis->ndim; - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; - int bckey[GKYL_MAX_CDIM] = {-1,-1,-1}; - for (int d=0; d>>(kers, ndim, basis->b_type, poly_order, bckey_d); + fem_poisson_perp_set_cu_l2gker_ptrs<<<1, 1> > >(kers, ndim, basis->b_type, poly_order, bckey_d); // Biasing kernels (set this before redefining bckey_d below). - fem_poisson_perp_set_cu_biasker_ptrs<<<1,1>>>(kers, ndim, basis->b_type, poly_order, bckey_d); - - for (int d=0; dlo_type[d]==GKYL_POISSON_PERIODIC && bcs->up_type[d]==GKYL_POISSON_PERIODIC ) { bckey[d] = 0; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_DIRICHLET) { bckey[d] = 1; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_NEUMANN ) { bckey[d] = 2; } - else if (bcs->lo_type[d]==GKYL_POISSON_NEUMANN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET) { bckey[d] = 3; } - else { assert(false); } + fem_poisson_perp_set_cu_biasker_ptrs<<<1, 1> > >(kers, ndim, basis->b_type, poly_order, bckey_d); + + for (int d = 0; d < ndim_perp; d++) { + if (bcs->lo_type[d] == GKYL_POISSON_PERIODIC && bcs->up_type[d] == GKYL_POISSON_PERIODIC) { + bckey[d] = 0; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 1; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_NEUMANN) { + bckey[d] = 2; + } else if (bcs->lo_type[d] == GKYL_POISSON_NEUMANN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 3; + } else { + assert(false); + } }; - gkyl_cu_memcpy(bckey_d, bckey, GKYL_MAX_CDIM*sizeof(int), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy(bckey_d, bckey, GKYL_MAX_CDIM * sizeof(int), GKYL_CU_MEMCPY_H2D); - fem_poisson_perp_set_cu_ker_ptrs<<<1,1>>>(kers, basis->b_type, ndim, poly_order, bckey_d); + fem_poisson_perp_set_cu_ker_ptrs<<<1, 1> > >(kers, basis->b_type, ndim, poly_order, bckey_d); gkyl_cu_free(bckey_d); } -__global__ void -gkyl_fem_poisson_perp_set_rhs_kernel(struct gkyl_array *epsilon, const double *dx, double *rhs_global, - struct gkyl_array *rhs_local, const struct gkyl_range range, struct gkyl_range par_range1d, - const double *bcvals, struct gkyl_fem_poisson_perp_kernels *kers, long numnodes_global) +__global__ void gkyl_fem_poisson_perp_set_rhs_kernel( + struct gkyl_array *epsilon, const double *dx, double *rhs_global, struct gkyl_array *rhs_local, + const struct gkyl_range range, struct gkyl_range par_range1d, const double *bcvals, + struct gkyl_fem_poisson_perp_kernels *kers, long numnodes_global +) { - int idx[GKYL_MAX_CDIM]; int idx0[GKYL_MAX_CDIM]; int num_cells[GKYL_MAX_CDIM]; + int idx[GKYL_MAX_CDIM]; + int idx0[GKYL_MAX_CDIM]; + int num_cells[GKYL_MAX_CDIM]; long globalidx[32]; int ndim = range.ndim; - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; - for (int d=0; dl2g[keri](num_cells, idx0, globalidx); // Apply the RHS source stencil. It's mostly the mass matrix times a // modal-to-nodal operator times the source, modified by BCs in skin cells. keri = idx_to_inloup_ker(ndim_perp, num_cells, idx); - int idx1d[] = {idx[ndim-1]}; + int idx1d[] = {idx[ndim - 1]}; long paridx = gkyl_range_idx(&par_range1d, idx1d); - long parProbOff = paridx*numnodes_global; + long parProbOff = paridx * numnodes_global; kers->srcker[keri](epsilon_d, dx, local_d, bcvals, parProbOff, globalidx, rhs_global); } } -void -gkyl_fem_poisson_perp_set_rhs_cu(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsin) +void gkyl_fem_poisson_perp_set_rhs_cu(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsin) { gkyl_culinsolver_clear_rhs(up->prob_cu, 0); double *rhs_cu = gkyl_culinsolver_get_rhs_ptr(up->prob_cu, 0); - gkyl_fem_poisson_perp_set_rhs_kernel<<nblocks, rhsin->nthreads>>>(up->epsilon->on_dev, up->dx_cu, - rhs_cu, rhsin->on_dev, *up->solve_range, up->par_range1d, up->bcvals_cu, up->kernels_cu, up->numnodes_global); + gkyl_fem_poisson_perp_set_rhs_kernel<<nblocks, rhsin->nthreads> > >( + up->epsilon->on_dev, up->dx_cu, rhs_cu, rhsin->on_dev, *up->solve_range, up->par_range1d, + up->bcvals_cu, up->kernels_cu, up->numnodes_global + ); // Set the corresponding entries to the biasing potential. up->bias_line_src(up, rhsin); } -__global__ void -gkyl_fem_poisson_perp_bias_src_kernel(double *rhs_global, struct gkyl_rect_grid grid, - const struct gkyl_range range, struct gkyl_range par_range1d, - struct gkyl_fem_poisson_perp_kernels *kers, long numnodes_global, - int num_bias_line, struct gkyl_poisson_bias_line *bias_lines) +__global__ void gkyl_fem_poisson_perp_bias_src_kernel( + double *rhs_global, struct gkyl_rect_grid grid, const struct gkyl_range range, + struct gkyl_range par_range1d, struct gkyl_fem_poisson_perp_kernels *kers, long numnodes_global, + int num_bias_line, struct gkyl_poisson_bias_line *bias_lines +) { const int bl_ndim_perp = 2; - int idx[GKYL_MAX_CDIM]; int idx0[GKYL_MAX_CDIM]; int num_cells[GKYL_MAX_CDIM]; + int idx[GKYL_MAX_CDIM]; + int idx0[GKYL_MAX_CDIM]; + int num_cells[GKYL_MAX_CDIM]; long globalidx[32]; int ndim = range.ndim; - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; - for (int d=0; dl2g[keri](num_cells, idx0, globalidx); // Modify the RHS source to enforce biasing of the solution. - int idx1d[] = {idx[ndim-1]}; + int idx1d[] = {idx[ndim - 1]}; long paridx = gkyl_range_idx(&par_range1d, idx1d); - long parProbOff = paridx*numnodes_global; + long parProbOff = paridx * numnodes_global; - for (int i=0; iperp_dirs[d]; double dx = grid.dx[perp_dir]; - bl_idx_m[d] = (bl->perp_coords[d]-1e-3*dx - grid.lower[perp_dir])/dx+1; + bl_idx_m[d] = (bl->perp_coords[d] - 1e-3 * dx - grid.lower[perp_dir]) / dx + 1; } - if ( - ( idx[bl->perp_dirs[0]] == bl_idx_m[0] && idx[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx[bl->perp_dirs[1]] == bl_idx_m[1] ) || - ( idx[bl->perp_dirs[0]] == bl_idx_m[0] && idx[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) || - ( idx[bl->perp_dirs[0]] == bl_idx_m[0]+1 && idx[bl->perp_dirs[1]] == bl_idx_m[1]+1 ) - ) { + if ((idx[bl->perp_dirs[0]] == bl_idx_m[0] && idx[bl->perp_dirs[1]] == bl_idx_m[1]) || + (idx[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && idx[bl->perp_dirs[1]] == bl_idx_m[1]) || + (idx[bl->perp_dirs[0]] == bl_idx_m[0] && idx[bl->perp_dirs[1]] == bl_idx_m[1] + 1) || + (idx[bl->perp_dirs[0]] == bl_idx_m[0] + 1 && idx[bl->perp_dirs[1]] == bl_idx_m[1] + 1)) { int edge[2] = { - -1+2*((bl_idx_m[0]+1)-idx[bl->perp_dirs[0]]), - -1+2*((bl_idx_m[1]+1)-idx[bl->perp_dirs[1]]), + -1 + 2 * ((bl_idx_m[0] + 1) - idx[bl->perp_dirs[0]]), + -1 + 2 * ((bl_idx_m[1] + 1) - idx[bl->perp_dirs[1]]) }; kers->bias_src_ker[keri](edge, bl->perp_dirs, bl->val, parProbOff, globalidx, rhs_global); } @@ -267,29 +292,34 @@ gkyl_fem_poisson_perp_bias_src_kernel(double *rhs_global, struct gkyl_rect_grid } } -void -gkyl_fem_poisson_perp_bias_src_enabled_cu(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsin) +void gkyl_fem_poisson_perp_bias_src_enabled_cu(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsin) { double *rhs_cu = gkyl_culinsolver_get_rhs_ptr(up->prob_cu, 0); - gkyl_fem_poisson_perp_bias_src_kernel<<nblocks, rhsin->nthreads>>>(rhs_cu, up->grid, - *up->solve_range, up->par_range1d, up->kernels_cu, up->numnodes_global, up->num_bias_line, up->bias_lines); + gkyl_fem_poisson_perp_bias_src_kernel<<nblocks, rhsin->nthreads> > >( + rhs_cu, up->grid, *up->solve_range, up->par_range1d, up->kernels_cu, up->numnodes_global, + up->num_bias_line, up->bias_lines + ); } -__global__ void -gkyl_fem_poisson_perp_get_sol_kernel(struct gkyl_array *x_local, const double *x_global, struct gkyl_range range, - struct gkyl_range par_range1d, struct gkyl_fem_poisson_perp_kernels *kers, long numnodes_global) +__global__ void gkyl_fem_poisson_perp_get_sol_kernel( + struct gkyl_array *x_local, const double *x_global, struct gkyl_range range, + struct gkyl_range par_range1d, struct gkyl_fem_poisson_perp_kernels *kers, long numnodes_global +) { - int idx[GKYL_MAX_CDIM]; int idx0[GKYL_MAX_CDIM]; int num_cells[GKYL_MAX_CDIM]; + int idx[GKYL_MAX_CDIM]; + int idx0[GKYL_MAX_CDIM]; + int num_cells[GKYL_MAX_CDIM]; long globalidx[32]; int ndim = range.ndim; - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; - for (int d=0; dl2g[keri](num_cells, idx0, globalidx); // Apply the RHS source stencil. It's mostly the mass matrix times a // modal-to-nodal operator times the source, modified by BCs in skin cells. - int idx1d[] = {idx[ndim-1]}; + int idx1d[] = {idx[ndim - 1]}; long paridx = gkyl_range_idx(&par_range1d, idx1d); - long parProbOff = paridx*numnodes_global; + long parProbOff = paridx * numnodes_global; kers->solker(x_global, parProbOff, globalidx, local_d); } } -void -gkyl_fem_poisson_perp_solve_cu(struct gkyl_fem_poisson_perp *up, struct gkyl_array *phiout) +void gkyl_fem_poisson_perp_solve_cu(struct gkyl_fem_poisson_perp *up, struct gkyl_array *phiout) { gkyl_culinsolver_solve(up->prob_cu); double *x_cu = gkyl_culinsolver_get_sol_ptr(up->prob_cu, 0); - gkyl_fem_poisson_perp_get_sol_kernel<<nblocks, phiout->nthreads>>>(phiout->on_dev, - x_cu, *up->solve_range, up->par_range1d, up->kernels_cu, up->numnodes_global); + gkyl_fem_poisson_perp_get_sol_kernel<<nblocks, phiout->nthreads> > >( + phiout->on_dev, x_cu, *up->solve_range, up->par_range1d, up->kernels_cu, up->numnodes_global + ); } -__global__ void -gkyl_fem_poisson_perp_update_lhs_kernel(bool is_helmholtz, const double *dx, const double *bcvals, - const struct gkyl_range range, struct gkyl_range par_range1d, - struct gkyl_fem_poisson_perp_kernels *kers, long numnodes_global, - struct gkyl_array *csr_val_idx, struct gkyl_array *epsilon, struct gkyl_array *kSq, double *csr_values) +__global__ void gkyl_fem_poisson_perp_update_lhs_kernel( + bool is_helmholtz, const double *dx, const double *bcvals, const struct gkyl_range range, + struct gkyl_range par_range1d, struct gkyl_fem_poisson_perp_kernels *kers, long numnodes_global, + struct gkyl_array *csr_val_idx, struct gkyl_array *epsilon, struct gkyl_array *kSq, + double *csr_values +) { - int idx[GKYL_MAX_CDIM]; int idx0[GKYL_MAX_CDIM]; int num_cells[GKYL_MAX_CDIM]; + int idx[GKYL_MAX_CDIM]; + int idx0[GKYL_MAX_CDIM]; + int num_cells[GKYL_MAX_CDIM]; long globalidx[32]; int ndim = range.ndim; - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; - for (int d=0; dl2g[keri](num_cells, idx0, globalidx); - int idx1d[] = {idx[ndim-1]}; + int idx1d[] = {idx[ndim - 1]}; long paridx = gkyl_range_idx(&par_range1d, idx1d); // Apply the RHS source stencil. It's mostly the mass matrix times a @@ -371,21 +409,24 @@ gkyl_fem_poisson_perp_update_lhs_kernel(bool is_helmholtz, const double *dx, con } } -void -gkyl_fem_poisson_perp_update_lhs_cu(gkyl_fem_poisson_perp *up, struct gkyl_array *epsilon, struct gkyl_array *kSq) +void gkyl_fem_poisson_perp_update_lhs_cu( + gkyl_fem_poisson_perp *up, struct gkyl_array *epsilon, struct gkyl_array *kSq +) { gkyl_culinsolver_clear_csr_values(up->prob_cu, 0); double *csr_val_cu = gkyl_culinsolver_get_csr_values_ptr(up->prob_cu, 0); struct gkyl_array *kSq_on_dev; - if (up->ishelmholtz) + if (up->ishelmholtz) { kSq_on_dev = kSq->on_dev; - else + } else { kSq_on_dev = up->kSq_null->on_dev; + } - gkyl_fem_poisson_perp_update_lhs_kernel<<nblocks, epsilon->nthreads>>>(up->ishelmholtz, up->dx_cu, - up->bcvals_cu, *up->solve_range, up->par_range1d, up->kernels_cu, up->numnodes_global, - up->csr_val_idx->on_dev, epsilon->on_dev, kSq_on_dev, csr_val_cu); + gkyl_fem_poisson_perp_update_lhs_kernel<<nblocks, epsilon->nthreads> > >( + up->ishelmholtz, up->dx_cu, up->bcvals_cu, *up->solve_range, up->par_range1d, up->kernels_cu, + up->numnodes_global, up->csr_val_idx->on_dev, epsilon->on_dev, kSq_on_dev, csr_val_cu + ); gkyl_culinsolver_amat_update(up->prob_cu, csr_val_cu); } diff --git a/gyrokinetic/zero/gk_anomalous_diffusion.c b/gyrokinetic/zero/gk_anomalous_diffusion.c index fe4f0b8a84..ab26a1cd52 100644 --- a/gyrokinetic/zero/gk_anomalous_diffusion.c +++ b/gyrokinetic/zero/gk_anomalous_diffusion.c @@ -8,22 +8,23 @@ #include #include -void -gkyl_gk_anomalous_diffusion_free(const struct gkyl_ref_count *ref) +void gkyl_gk_anomalous_diffusion_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object - struct gk_anomalous_diffusion *diffusion = container_of(base->on_dev, struct gk_anomalous_diffusion, eqn); + struct gk_anomalous_diffusion *diffusion = + container_of(base->on_dev, struct gk_anomalous_diffusion, eqn); gkyl_cu_free(diffusion); } struct gk_anomalous_diffusion *diffusion = container_of(base, struct gk_anomalous_diffusion, eqn); gkyl_free(diffusion); } -void -gkyl_gk_anomalous_diffusion_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_gk_anomalous_diffusion_auxfields auxin) +void gkyl_gk_anomalous_diffusion_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_gk_anomalous_diffusion_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(auxin.nu) && gkyl_array_is_cu_dev(auxin.jacobgeo_inv)) { @@ -31,21 +32,24 @@ gkyl_gk_anomalous_diffusion_set_auxfields(const struct gkyl_dg_eqn *eqn, struct return; } #endif - + struct gk_anomalous_diffusion *diffusion = container_of(eqn, struct gk_anomalous_diffusion, eqn); diffusion->auxfields.nu = auxin.nu; diffusion->auxfields.jacobgeo_inv = auxin.jacobgeo_inv; } -struct gkyl_dg_eqn* -gkyl_gk_anomalous_diffusion_new(const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, - const struct gkyl_range *conf_range, enum gkyl_gyrokinetic_bc_type bc_x_lower, enum gkyl_gyrokinetic_bc_type bc_x_upper, bool use_gpu) +struct gkyl_dg_eqn *gkyl_gk_anomalous_diffusion_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, + const struct gkyl_range *conf_range, enum gkyl_gyrokinetic_bc_type bc_x_lower, + enum gkyl_gyrokinetic_bc_type bc_x_upper, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) + if (use_gpu) { return gkyl_gk_anomalous_diffusion_cu_dev_new(basis, cbasis, conf_range, bc_x_lower, bc_x_upper); + } #endif - + struct gk_anomalous_diffusion *diffusion = gkyl_malloc(sizeof(struct gk_anomalous_diffusion)); int cdim = cbasis->ndim; @@ -55,8 +59,10 @@ gkyl_gk_anomalous_diffusion_new(const struct gkyl_basis *basis, const struct gky const gkyl_gk_anomalous_diffusion_vol_kern_list *vol_kernels; const gkyl_gk_anomalous_diffusion_surf_kern_list *surfx_kernels; - const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list *boundary_surfx_lower_kernels, *boundary_surfx_upper_kernels; - const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list *boundary_diagx_lower_kernels, *boundary_diagx_upper_kernels; + const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list *boundary_surfx_lower_kernels, + *boundary_surfx_upper_kernels; + const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list *boundary_diagx_lower_kernels, + *boundary_diagx_upper_kernels; // Choice of boundary_surf and boundary_diag kernels: // boundary_surf: zero_flux or local @@ -72,76 +78,68 @@ gkyl_gk_anomalous_diffusion_new(const struct gkyl_basis *basis, const struct gky // ELSE: local local yes switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surfx_kernels = ser_gyrokinetic_surfx_kernels; - if ((bc_x_lower == GKYL_BC_GK_SKIP) || - (bc_x_lower == GKYL_BC_GK_SPECIES_PERIODIC)) { - // Boundary surf and diag kernels not used. - boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; - boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; - } - else if (bc_x_lower == GKYL_BC_GK_SPECIES_ZERO_FLUX) { - boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; - // Boundary diag kernel not used. - boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; - } - else if ((bc_x_lower == GKYL_BC_GK_SPECIES_ABSORB) || + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surfx_kernels = ser_gyrokinetic_surfx_kernels; + if ((bc_x_lower == GKYL_BC_GK_SKIP) || (bc_x_lower == GKYL_BC_GK_SPECIES_PERIODIC)) { + // Boundary surf and diag kernels not used. + boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; + boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; + } else if (bc_x_lower == GKYL_BC_GK_SPECIES_ZERO_FLUX) { + boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; + // Boundary diag kernel not used. + boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; + } else if ((bc_x_lower == GKYL_BC_GK_SPECIES_ABSORB) || (bc_x_lower == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { - // Boundary surf kernel not used. - boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; - boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; - } - else { - boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_boundlocal_kernels; - boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundlocal_kernels; - } - - if ((bc_x_upper == GKYL_BC_GK_SKIP) || - (bc_x_upper == GKYL_BC_GK_SPECIES_PERIODIC)) { - // Boundary surf and diag kernels not used. - boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; - boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; - } - else if (bc_x_upper == GKYL_BC_GK_SPECIES_ZERO_FLUX) { - boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; - // Boundary diag kernel not used. - boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; - } - else if ((bc_x_upper == GKYL_BC_GK_SPECIES_ABSORB) || + // Boundary surf kernel not used. + boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; + boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; + } else { + boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_boundlocal_kernels; + boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundlocal_kernels; + } + + if ((bc_x_upper == GKYL_BC_GK_SKIP) || (bc_x_upper == GKYL_BC_GK_SPECIES_PERIODIC)) { + // Boundary surf and diag kernels not used. + boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; + boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; + } else if (bc_x_upper == GKYL_BC_GK_SPECIES_ZERO_FLUX) { + boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; + // Boundary diag kernel not used. + boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; + } else if ((bc_x_upper == GKYL_BC_GK_SPECIES_ABSORB) || (bc_x_upper == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { - // Boundary surf kernel not used. - boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; - boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; - } - else { - boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_boundlocal_kernels; - boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundlocal_kernels; - } - - break; - - default: - assert(false); - break; - } + // Boundary surf kernel not used. + boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; + boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; + } else { + boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_boundlocal_kernels; + boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundlocal_kernels; + } + + break; + + default: + assert(false); + break; + } diffusion->eqn.num_equations = 1; diffusion->eqn.surf_term = surf; diffusion->eqn.boundary_surf_term = boundary_surf; diffusion->eqn.boundary_diag_term = boundary_diag; - diffusion->eqn.vol_term = CKVOL(vol_kernels, cdim+vdim, poly_order); - diffusion->surf = CKSURF(surfx_kernels, cdim+vdim, poly_order); - diffusion->boundary_surf[0] = CKSURF(boundary_surfx_lower_kernels, pdim, poly_order); - diffusion->boundary_surf[1] = CKSURF(boundary_surfx_upper_kernels, pdim, poly_order); - diffusion->boundary_diag[0] = CKSURF(boundary_diagx_lower_kernels, pdim, poly_order); - diffusion->boundary_diag[1] = CKSURF(boundary_diagx_upper_kernels, pdim, poly_order); + diffusion->eqn.vol_term = CKVOL(vol_kernels, cdim + vdim, poly_order); + diffusion->surf = CKSURF(surfx_kernels, cdim + vdim, poly_order); + diffusion->boundary_surf[0] = CKSURF(boundary_surfx_lower_kernels, pdim, poly_order); + diffusion->boundary_surf[1] = CKSURF(boundary_surfx_upper_kernels, pdim, poly_order); + diffusion->boundary_diag[0] = CKSURF(boundary_diagx_lower_kernels, pdim, poly_order); + diffusion->boundary_diag[1] = CKSURF(boundary_diagx_upper_kernels, pdim, poly_order); // Ensure non-NULL pointers. assert(diffusion->eqn.vol_term); assert(diffusion->surf); - for (int i=0; i<2; i++) { + for (int i = 0; i < 2; i++) { assert(diffusion->boundary_surf[i]); assert(diffusion->boundary_diag[i]); } @@ -153,6 +151,6 @@ gkyl_gk_anomalous_diffusion_new(const struct gkyl_basis *basis, const struct gky diffusion->eqn.flags = 0; diffusion->eqn.ref_count = gkyl_ref_count_init(gkyl_gk_anomalous_diffusion_free); diffusion->eqn.on_dev = &diffusion->eqn; - + return &diffusion->eqn; } diff --git a/gyrokinetic/zero/gk_anomalous_diffusion_cu.cu b/gyrokinetic/zero/gk_anomalous_diffusion_cu.cu index 8f818bdca0..f65fff5cd0 100644 --- a/gyrokinetic/zero/gk_anomalous_diffusion_cu.cu +++ b/gyrokinetic/zero/gk_anomalous_diffusion_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include } @@ -12,36 +12,41 @@ extern "C" { // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_gk_anomalous_diffusion_set_auxfields_cu_kernel(const struct gkyl_dg_eqn* eqn, - const struct gkyl_array* nu, const struct gkyl_array* jacobgeo_inv) +__global__ static void gkyl_gk_anomalous_diffusion_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nu, const struct gkyl_array *jacobgeo_inv +) { - struct gk_anomalous_diffusion* diffusion = container_of(eqn, struct gk_anomalous_diffusion, eqn); + struct gk_anomalous_diffusion *diffusion = container_of(eqn, struct gk_anomalous_diffusion, eqn); diffusion->auxfields.nu = nu; diffusion->auxfields.jacobgeo_inv = jacobgeo_inv; } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_gk_anomalous_diffusion_set_auxfields_cu(const struct gkyl_dg_eqn* eqn, - struct gkyl_gk_anomalous_diffusion_auxfields auxin) +void gkyl_gk_anomalous_diffusion_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_gk_anomalous_diffusion_auxfields auxin +) { - gkyl_gk_anomalous_diffusion_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.nu->on_dev, auxin.jacobgeo_inv->on_dev); + gkyl_gk_anomalous_diffusion_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.nu->on_dev, auxin.jacobgeo_inv->on_dev + ); } -__global__ void static -gk_anomalous_diffusion_set_cu_dev_ptrs(struct gk_anomalous_diffusion *diffusion, enum gkyl_basis_type b_type, - int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc_x_lower, enum gkyl_gyrokinetic_bc_type bc_x_upper) +__global__ void static gk_anomalous_diffusion_set_cu_dev_ptrs( + struct gk_anomalous_diffusion *diffusion, enum gkyl_basis_type b_type, int cdim, int vdim, + int poly_order, enum gkyl_gyrokinetic_bc_type bc_x_lower, enum gkyl_gyrokinetic_bc_type bc_x_upper +) { int pdim = cdim + vdim; - diffusion->auxfields.nu = 0; - diffusion->auxfields.jacobgeo_inv = 0; + diffusion->auxfields.nu = 0; + diffusion->auxfields.jacobgeo_inv = 0; const gkyl_gk_anomalous_diffusion_vol_kern_list *vol_kernels; const gkyl_gk_anomalous_diffusion_surf_kern_list *surfx_kernels; - const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list *boundary_surfx_lower_kernels, *boundary_surfx_upper_kernels; - const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list *boundary_diagx_lower_kernels, *boundary_diagx_upper_kernels; + const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list *boundary_surfx_lower_kernels, + *boundary_surfx_upper_kernels; + const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list *boundary_diagx_lower_kernels, + *boundary_diagx_upper_kernels; // Choice of boundary_surf and boundary_diag kernels: // boundary_surf: zero_flux or local @@ -55,57 +60,49 @@ gk_anomalous_diffusion_set_cu_dev_ptrs(struct gk_anomalous_diffusion *diffusion, // ELSE: local local yes switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surfx_kernels = ser_gyrokinetic_surfx_kernels; - if ((bc_x_lower == GKYL_BC_GK_SKIP) || - (bc_x_lower == GKYL_BC_GK_SPECIES_PERIODIC)) { - // Boundary surf kernel not used. - boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; - boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; - } - else if (bc_x_lower == GKYL_BC_GK_SPECIES_ZERO_FLUX) { - boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; - // Boundary diag kernel not used. - boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; - } - else if ((bc_x_lower == GKYL_BC_GK_SPECIES_ABSORB) || + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surfx_kernels = ser_gyrokinetic_surfx_kernels; + if ((bc_x_lower == GKYL_BC_GK_SKIP) || (bc_x_lower == GKYL_BC_GK_SPECIES_PERIODIC)) { + // Boundary surf kernel not used. + boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; + boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; + } else if (bc_x_lower == GKYL_BC_GK_SPECIES_ZERO_FLUX) { + boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; + // Boundary diag kernel not used. + boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; + } else if ((bc_x_lower == GKYL_BC_GK_SPECIES_ABSORB) || (bc_x_lower == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { - // Boundary surf kernel not used. - boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; - boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; - } - else { - boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_boundlocal_kernels; - boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundlocal_kernels; - } - - if ((bc_x_upper == GKYL_BC_GK_SKIP) || - (bc_x_upper == GKYL_BC_GK_SPECIES_PERIODIC)) { - // Boundary surf and diag kernels not used. - boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; - boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; - } - else if (bc_x_upper == GKYL_BC_GK_SPECIES_ZERO_FLUX) { - boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; - // Boundary diag kernel not used. - boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; - } - else if ((bc_x_upper == GKYL_BC_GK_SPECIES_ABSORB) || + // Boundary surf kernel not used. + boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels; + boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels; + } else { + boundary_surfx_lower_kernels = ser_gyrokinetic_boundary_surfx_lower_boundlocal_kernels; + boundary_diagx_lower_kernels = ser_gyrokinetic_boundary_diagx_lower_boundlocal_kernels; + } + + if ((bc_x_upper == GKYL_BC_GK_SKIP) || (bc_x_upper == GKYL_BC_GK_SPECIES_PERIODIC)) { + // Boundary surf and diag kernels not used. + boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; + boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; + } else if (bc_x_upper == GKYL_BC_GK_SPECIES_ZERO_FLUX) { + boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; + // Boundary diag kernel not used. + boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; + } else if ((bc_x_upper == GKYL_BC_GK_SPECIES_ABSORB) || (bc_x_upper == GKYL_BC_GK_SPECIES_FIXED_FUNC)) { - // Boundary surf kernel not used. - boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; - boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; - } - else { - boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_boundlocal_kernels; - boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundlocal_kernels; - } - break; - - default: - assert(false); - break; + // Boundary surf kernel not used. + boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels; + boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels; + } else { + boundary_surfx_upper_kernels = ser_gyrokinetic_boundary_surfx_upper_boundlocal_kernels; + boundary_diagx_upper_kernels = ser_gyrokinetic_boundary_diagx_upper_boundlocal_kernels; + } + break; + + default: + assert(false); + break; } diffusion->eqn.num_equations = 1; @@ -115,25 +112,28 @@ gk_anomalous_diffusion_set_cu_dev_ptrs(struct gk_anomalous_diffusion *diffusion, diffusion->eqn.vol_term = CKVOL(vol_kernels, pdim, poly_order); diffusion->surf = CKSURF(surfx_kernels, pdim, poly_order); - diffusion->boundary_surf[0] = CKSURF(boundary_surfx_lower_kernels, pdim, poly_order); - diffusion->boundary_surf[1] = CKSURF(boundary_surfx_upper_kernels, pdim, poly_order); - diffusion->boundary_diag[0] = CKSURF(boundary_diagx_lower_kernels, pdim, poly_order); - diffusion->boundary_diag[1] = CKSURF(boundary_diagx_upper_kernels, pdim, poly_order); + diffusion->boundary_surf[0] = CKSURF(boundary_surfx_lower_kernels, pdim, poly_order); + diffusion->boundary_surf[1] = CKSURF(boundary_surfx_upper_kernels, pdim, poly_order); + diffusion->boundary_diag[0] = CKSURF(boundary_diagx_lower_kernels, pdim, poly_order); + diffusion->boundary_diag[1] = CKSURF(boundary_diagx_upper_kernels, pdim, poly_order); // Ensure non-NULL pointers. assert(diffusion->eqn.vol_term); assert(diffusion->surf); - for (int i=0; i<2; i++) { + for (int i = 0; i < 2; i++) { assert(diffusion->boundary_surf[i]); assert(diffusion->boundary_diag[i]); } } -struct gkyl_dg_eqn* -gkyl_gk_anomalous_diffusion_cu_dev_new(const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, - const struct gkyl_range *conf_range, enum gkyl_gyrokinetic_bc_type bc_x_lower, enum gkyl_gyrokinetic_bc_type bc_x_upper) +struct gkyl_dg_eqn *gkyl_gk_anomalous_diffusion_cu_dev_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, + const struct gkyl_range *conf_range, enum gkyl_gyrokinetic_bc_type bc_x_lower, + enum gkyl_gyrokinetic_bc_type bc_x_upper +) { - struct gk_anomalous_diffusion* diffusion = (struct gk_anomalous_diffusion*) gkyl_malloc(sizeof(struct gk_anomalous_diffusion)); + struct gk_anomalous_diffusion *diffusion = + (struct gk_anomalous_diffusion *)gkyl_malloc(sizeof(struct gk_anomalous_diffusion)); int cdim = cbasis->ndim; int vdim = basis->ndim - cdim; @@ -146,10 +146,13 @@ gkyl_gk_anomalous_diffusion_cu_dev_new(const struct gkyl_basis *basis, const str diffusion->eqn.ref_count = gkyl_ref_count_init(gkyl_gk_anomalous_diffusion_free); // Copy the host struct to device struct. - struct gk_anomalous_diffusion* diffusion_cu = (struct gk_anomalous_diffusion*) gkyl_cu_malloc(sizeof(struct gk_anomalous_diffusion)); + struct gk_anomalous_diffusion *diffusion_cu = + (struct gk_anomalous_diffusion *)gkyl_cu_malloc(sizeof(struct gk_anomalous_diffusion)); gkyl_cu_memcpy(diffusion_cu, diffusion, sizeof(struct gk_anomalous_diffusion), GKYL_CU_MEMCPY_H2D); - gk_anomalous_diffusion_set_cu_dev_ptrs<<<1,1>>>(diffusion_cu, cbasis->b_type, cdim, vdim, poly_order, bc_x_lower, bc_x_upper); + gk_anomalous_diffusion_set_cu_dev_ptrs<<<1, 1> > >( + diffusion_cu, cbasis->b_type, cdim, vdim, poly_order, bc_x_lower, bc_x_upper + ); // Set parent on_dev pointer. diffusion->eqn.on_dev = &diffusion_cu->eqn; diff --git a/gyrokinetic/zero/gk_collisionless_flux.c b/gyrokinetic/zero/gk_collisionless_flux.c index 7a495ec415..1e0862d667 100644 --- a/gyrokinetic/zero/gk_collisionless_flux.c +++ b/gyrokinetic/zero/gk_collisionless_flux.c @@ -10,20 +10,23 @@ #include #include -gkyl_gk_collisionless_flux* -gkyl_gk_collisionless_flux_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const double charge, const double mass, - enum gkyl_gk_collisionless_type type, - const struct gk_geometry *gk_geom, const struct gkyl_dg_geom *dg_geom, - const struct gkyl_gk_dg_geom *gk_dg_geom, const struct gkyl_velocity_map *vel_map, - const enum gkyl_gyrokinetic_bc_type *bctype_conf, bool use_gpu) +gkyl_gk_collisionless_flux *gkyl_gk_collisionless_flux_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const double charge, const double mass, + enum gkyl_gk_collisionless_type type, const struct gk_geometry *gk_geom, + const struct gkyl_dg_geom *dg_geom, const struct gkyl_gk_dg_geom *gk_dg_geom, + const struct gkyl_velocity_map *vel_map, const enum gkyl_gyrokinetic_bc_type *bctype_conf, + bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) - return gkyl_gk_collisionless_flux_cu_dev_new(phase_grid, conf_basis, phase_basis, - charge, mass, type, gk_geom, dg_geom, gk_dg_geom, vel_map, bctype_conf); -#endif + if (use_gpu) { + return gkyl_gk_collisionless_flux_cu_dev_new( + phase_grid, conf_basis, phase_basis, charge, mass, type, gk_geom, dg_geom, gk_dg_geom, + vel_map, bctype_conf + ); + } +#endif gkyl_gk_collisionless_flux *up = gkyl_malloc(sizeof(gkyl_gk_collisionless_flux)); @@ -44,44 +47,54 @@ gkyl_gk_collisionless_flux_new(const struct gkyl_rect_grid *phase_grid, up->vel_map = gkyl_velocity_map_acquire(vel_map); if (type == GKYL_GK_COLLISIONLESS_ES) { - for (int d=0; dflux_surf kernel doesn't matter as long as it's not SKIP. - up->flux_surf[d] = choose_gk_collisionless_flux_surf_conf_kern(d, cdim, vdim, poly_order, GKYL_BC_GK_SPECIES_ABSORB); - up->flux_surf_edge_lo[d] = choose_gk_collisionless_flux_surf_conf_kern(d, cdim, vdim, - poly_order, bctype_conf[d]); - up->flux_surf_edge_up[d] = choose_gk_collisionless_flux_edge_surf_conf_kern(d, cdim, vdim, - poly_order, bctype_conf[GKYL_MAX_CDIM+d]); + up->flux_surf[d] = choose_gk_collisionless_flux_surf_conf_kern( + d, cdim, vdim, poly_order, GKYL_BC_GK_SPECIES_ABSORB + ); + up->flux_surf_edge_lo[d] = + choose_gk_collisionless_flux_surf_conf_kern(d, cdim, vdim, poly_order, bctype_conf[d]); + up->flux_surf_edge_up[d] = choose_gk_collisionless_flux_edge_surf_conf_kern( + d, cdim, vdim, poly_order, bctype_conf[GKYL_MAX_CDIM + d] + ); } up->flux_surfvpar[0] = choose_gk_collisionless_flux_surf_vpar_kern(cdim, vdim, poly_order); - } - else if (type == GKYL_GK_COLLISIONLESS_ES_NO_BY) { - for (int d=0; dflux_surf kernel doesn't matter as long as it's not SKIP. - up->flux_surf[d] = choose_gk_collisionless_flux_no_by_surf_conf_kern(d, cdim, vdim, poly_order, GKYL_BC_GK_SPECIES_ABSORB); - up->flux_surf_edge_lo[d] = choose_gk_collisionless_flux_no_by_surf_conf_kern(d, cdim, vdim, - poly_order, bctype_conf[d]); - up->flux_surf_edge_up[d] = choose_gk_collisionless_flux_no_by_edge_surf_conf_kern(d, cdim, vdim, - poly_order, bctype_conf[GKYL_MAX_CDIM+d]); + up->flux_surf[d] = choose_gk_collisionless_flux_no_by_surf_conf_kern( + d, cdim, vdim, poly_order, GKYL_BC_GK_SPECIES_ABSORB + ); + up->flux_surf_edge_lo[d] = choose_gk_collisionless_flux_no_by_surf_conf_kern( + d, cdim, vdim, poly_order, bctype_conf[d] + ); + up->flux_surf_edge_up[d] = choose_gk_collisionless_flux_no_by_edge_surf_conf_kern( + d, cdim, vdim, poly_order, bctype_conf[GKYL_MAX_CDIM + d] + ); } - up->flux_surfvpar[0] = choose_gk_collisionless_flux_no_by_surf_vpar_kern(cdim, vdim, poly_order); + up->flux_surfvpar[0] = + choose_gk_collisionless_flux_no_by_surf_vpar_kern(cdim, vdim, poly_order); } up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void gkyl_gk_collisionless_flux_surf(struct gkyl_gk_collisionless_flux *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_ext_range, const struct gkyl_range *phase_ext_range, const struct gkyl_array *phi, - const struct gkyl_array *fin, struct gkyl_array* flux_surf, struct gkyl_array *cflrate) +void gkyl_gk_collisionless_flux_surf( + struct gkyl_gk_collisionless_flux *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_range *phase_ext_range, const struct gkyl_array *phi, + const struct gkyl_array *fin, struct gkyl_array *flux_surf, struct gkyl_array *cflrate +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(flux_surf)) { - return gkyl_gk_collisionless_flux_surf_cu(up, conf_range, phase_range, - conf_ext_range, phase_ext_range, phi, fin, flux_surf, cflrate); + return gkyl_gk_collisionless_flux_surf_cu( + up, conf_range, phase_range, conf_ext_range, phase_ext_range, phi, fin, flux_surf, cflrate + ); } #endif int pdim = up->pdim; @@ -102,7 +115,9 @@ void gkyl_gk_collisionless_flux_surf(struct gkyl_gk_collisionless_flux *up, while (gkyl_range_iter_next(&iter)) { gkyl_copy_int_arr(pdim, iter.idx, idx); - for (int d=cdim; dvel_map->local_vel, idx_vel); @@ -118,7 +133,7 @@ void gkyl_gk_collisionless_flux_surf(struct gkyl_gk_collisionless_flux *up, double *flux_surf_d = gkyl_array_fetch(flux_surf, loc_phase); double *cflrate_d = gkyl_array_fetch(cflrate, loc_phase); - for (int dir = 0; dirdg_geom, dir, idx); const struct gkyl_gk_dg_surf_geom *gkdgs = gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx); - const double *jacgeo_rat_surfL_d = gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_confL); - const double *jacgeo_rat_surfR_d = gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); + const double *jacgeo_rat_surfL_d = + gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_confL); + const double *jacgeo_rat_surfR_d = + gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); if (idx[dir] == phase_range->lower[dir]) { // Lower domain/block boundary. - cflrate_d[0] += up->flux_surf_edge_lo[dir](xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, - dgs, gkdgs, bmag_d, jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_d); + cflrate_d[0] += up->flux_surf_edge_lo[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs, gkdgs, bmag_d, + jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_d + ); } else { // Interior, lower cell surface. - cflrate_d[0] += up->flux_surf[dir](xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, - dgs, gkdgs, bmag_d, jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_d); + cflrate_d[0] += up->flux_surf[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs, gkdgs, bmag_d, + jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_d + ); } // Upper domain/block boundary. // If the phase space index is at the local configuration space upper value, we - // we are at the configuration space upper edge and we also need to evaluate - // alpha = +1 to avoid evaluating the geometry information in the ghost cells + // we are at the configuration space upper edge and we also need to evaluate + // alpha = +1 to avoid evaluating the geometry information in the ghost cells // where it is not defined when computing the final surface alpha we need // (since the surface alpha array stores only the *lower* surface expansion) if (idx[dir] == phase_range->upper[dir]) { gkyl_copy_int_arr(pdim, idx, idx_edge); - idx_edge[dir] = idx_edge[dir]+1; + idx_edge[dir] = idx_edge[dir] + 1; long loc_conf_ext = gkyl_range_idx(conf_ext_range, idx_edge); long loc_phase_ext = gkyl_range_idx(phase_ext_range, idx_edge); @@ -158,19 +179,27 @@ void gkyl_gk_collisionless_flux_surf(struct gkyl_gk_collisionless_flux *up, const double *fL = gkyl_array_cfetch(fin, loc_phase); const double *fR = gkyl_array_cfetch(fin, loc_phase_ext); const struct gkyl_dg_surf_geom *dgs = gkyl_dg_geom_get_surf(up->dg_geom, dir, idx_edge); - const struct gkyl_gk_dg_surf_geom *gkdgs = gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx_edge); + const struct gkyl_gk_dg_surf_geom *gkdgs = + gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx_edge); - const double *jacgeo_rat_surfL_d = gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); - const double *jacgeo_rat_surfR_d = gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf_ext); + const double *jacgeo_rat_surfL_d = + gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); + const double *jacgeo_rat_surfR_d = + gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf_ext); - double* flux_surf_ext_d = gkyl_array_fetch(flux_surf, loc_phase_ext); + double *flux_surf_ext_d = gkyl_array_fetch(flux_surf, loc_phase_ext); // Write into the skin cell's own cflrate (not the ghost cell's, which is excluded // from the CFL reduction range). Use a max instead of accumulating since cflrate_d // already holds this cell's lower-surface contribution from earlier in this dir loop. - cflrate_ext_d[0] = GKYL_MAX2(cflrate_ext_d[0], up->flux_surf_edge_up[dir](xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, - dgs, gkdgs, bmag_d, jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_ext_d)); - } + cflrate_ext_d[0] = GKYL_MAX2( + cflrate_ext_d[0], + up->flux_surf_edge_up[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs, gkdgs, bmag_d, + jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_ext_d + ) + ); + } } } @@ -178,7 +207,9 @@ void gkyl_gk_collisionless_flux_surf(struct gkyl_gk_collisionless_flux *up, while (gkyl_range_iter_next(&iter)) { gkyl_copy_int_arr(pdim, iter.idx, idx); - for (int d=cdim; dvel_map->local_vel, idx_vel); @@ -194,11 +225,11 @@ void gkyl_gk_collisionless_flux_surf(struct gkyl_gk_collisionless_flux *up, double *flux_surf_d = gkyl_array_fetch(flux_surf, loc_phase); double *cflrate_d = gkyl_array_fetch(cflrate, loc_phase); - int dir=cdim; + int dir = cdim; gkyl_copy_int_arr(pdim, idx, idxL); idxL[dir] = idx[dir] - 1; - gkyl_copy_int_arr(pdim-cdim, idx_vel, idx_velL); - idx_velL[0] = idx_velL[0]-1; + gkyl_copy_int_arr(pdim - cdim, idx_vel, idx_velL); + idx_velL[0] = idx_velL[0] - 1; long locL = gkyl_range_idx(phase_range, idxL); long loc_velL = gkyl_range_idx(&up->vel_map->local_vel, idx_velL); const double *fL = gkyl_array_cfetch(fin, locL); @@ -209,8 +240,10 @@ void gkyl_gk_collisionless_flux_surf(struct gkyl_gk_collisionless_flux *up, const struct gkyl_dg_vol_geom *dgv = gkyl_dg_geom_get_vol(up->dg_geom, idx); const struct gkyl_gk_dg_vol_geom *gkdgv = gkyl_gk_dg_geom_get_vol(up->gk_dg_geom, idx); - cflrate_d[0] += up->flux_surfvpar[0](xc, up->phase_grid.dx, vpL, vpR, vmap_d, vmapSq_d, up->charge, up->mass, - dgv, gkdgv, bmag_d, phi_d, fL, fR, flux_surf_d); + cflrate_d[0] += up->flux_surfvpar[0]( + xc, up->phase_grid.dx, vpL, vpR, vmap_d, vmapSq_d, up->charge, up->mass, dgv, gkdgv, bmag_d, + phi_d, fL, fR, flux_surf_d + ); } } @@ -220,8 +253,9 @@ void gkyl_gk_collisionless_flux_release(gkyl_gk_collisionless_flux *up) gkyl_dg_geom_release(up->dg_geom); gkyl_gk_dg_geom_release(up->gk_dg_geom); gkyl_velocity_map_release(up->vel_map); - - if (GKYL_IS_CU_ALLOC(up->flags)) + + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/gyrokinetic/zero/gk_collisionless_flux_cu.cu b/gyrokinetic/zero/gk_collisionless_flux_cu.cu index 90444864d6..66fe7df996 100644 --- a/gyrokinetic/zero/gk_collisionless_flux_cu.cu +++ b/gyrokinetic/zero/gk_collisionless_flux_cu.cu @@ -15,12 +15,13 @@ extern "C" { #include } -__global__ void -gkyl_gk_collisionless_flux_surf_conf_cu_kernel(struct gkyl_gk_collisionless_flux *up, - struct gkyl_range conf_range, struct gkyl_range phase_range, - struct gkyl_range conf_ext_range, struct gkyl_range phase_ext_range, const struct gkyl_array *phi, - const struct gkyl_array *fin, struct gkyl_array* flux_surf, struct gkyl_array *cflrate) -{ +__global__ void gkyl_gk_collisionless_flux_surf_conf_cu_kernel( + struct gkyl_gk_collisionless_flux *up, struct gkyl_range conf_range, + struct gkyl_range phase_range, struct gkyl_range conf_ext_range, + struct gkyl_range phase_ext_range, const struct gkyl_array *phi, const struct gkyl_array *fin, + struct gkyl_array *flux_surf, struct gkyl_array *cflrate +) +{ int pdim = up->pdim; int cdim = up->cdim; int idx[GKYL_MAX_DIM], idx_edge[GKYL_MAX_DIM], idx_vel[2]; @@ -28,17 +29,17 @@ gkyl_gk_collisionless_flux_surf_conf_cu_kernel(struct gkyl_gk_collisionless_flux double xc[GKYL_MAX_DIM]; // 2D thread grid - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < phase_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < phase_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange gkyl_sub_range_inv_idx(&phase_range, linc1, idx); gkyl_rect_grid_cell_center(&up->phase_grid, idx, xc); - for (int d=cdim; dvel_map->local_vel, idx_vel); long loc_phase = gkyl_range_idx(&phase_range, idx); - const double *bmag_d = (const double*) gkyl_array_cfetch(up->gk_geom->geo_corn.bmag, loc_conf); - const double *phi_d = (const double*) gkyl_array_cfetch(phi, loc_conf); - const double *vmap_d = (const double*) gkyl_array_cfetch(up->vel_map->vmap, loc_vel); - const double *vmapSq_d = (const double*) gkyl_array_cfetch(up->vel_map->vmap_sq, loc_vel); + const double *bmag_d = (const double *)gkyl_array_cfetch(up->gk_geom->geo_corn.bmag, loc_conf); + const double *phi_d = (const double *)gkyl_array_cfetch(phi, loc_conf); + const double *vmap_d = (const double *)gkyl_array_cfetch(up->vel_map->vmap, loc_vel); + const double *vmapSq_d = (const double *)gkyl_array_cfetch(up->vel_map->vmap_sq, loc_vel); - double* flux_surf_d = (double*) gkyl_array_fetch(flux_surf, loc_phase); - double *cflrate_d = (double*) gkyl_array_fetch(cflrate, loc_phase); + double *flux_surf_d = (double *)gkyl_array_fetch(flux_surf, loc_phase); + double *cflrate_d = (double *)gkyl_array_fetch(cflrate, loc_phase); - for (int dir = 0; dirdg_geom, dir, idx); const struct gkyl_gk_dg_surf_geom *gkdgs = gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx); - const double *jacgeo_rat_surfL_d = (const double *) gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_confL); - const double *jacgeo_rat_surfR_d = (const double *) gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); + const double *jacgeo_rat_surfL_d = + (const double *)gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_confL); + const double *jacgeo_rat_surfR_d = + (const double *)gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); if (idx[dir] == phase_range.lower[dir]) { // Lower domain/block boundary. - cflrate_d[0] += up->flux_surf_edge_lo[dir](xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, - dgs, gkdgs, bmag_d, jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_d); + cflrate_d[0] += up->flux_surf_edge_lo[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs, gkdgs, bmag_d, + jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_d + ); } else { // Interior, lower cell surface. - cflrate_d[0] += up->flux_surf[dir](xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, - dgs, gkdgs, bmag_d, jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_d); + cflrate_d[0] += up->flux_surf[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs, gkdgs, bmag_d, + jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_d + ); } // If the phase space index is at the local configuration space upper value, we - // we are at the configuration space upper edge and we also need to evaluate - // alpha = +1 to avoid evaluating the geometry information in the ghost cells + // we are at the configuration space upper edge and we also need to evaluate + // alpha = +1 to avoid evaluating the geometry information in the ghost cells // where it is not defined when computing the final surface alpha we need // (since the surface alpha array stores only the *lower* surface expansion) if (idx[dir] == phase_range.upper[dir]) { gkyl_copy_int_arr(pdim, idx, idx_edge); - idx_edge[dir] = idx_edge[dir]+1; + idx_edge[dir] = idx_edge[dir] + 1; long loc_conf_ext = gkyl_range_idx(&conf_ext_range, idx_edge); long loc_phase_ext = gkyl_range_idx(&phase_ext_range, idx_edge); - double *cflrate_ext_d = (double*) gkyl_array_fetch(cflrate, loc_phase); - const double *fL = (const double*) gkyl_array_cfetch(fin, loc_phase); - const double *fR = (const double*) gkyl_array_cfetch(fin, loc_phase_ext); + double *cflrate_ext_d = (double *)gkyl_array_fetch(cflrate, loc_phase); + const double *fL = (const double *)gkyl_array_cfetch(fin, loc_phase); + const double *fR = (const double *)gkyl_array_cfetch(fin, loc_phase_ext); const struct gkyl_dg_surf_geom *dgs = gkyl_dg_geom_get_surf(up->dg_geom, dir, idx_edge); - const struct gkyl_gk_dg_surf_geom *gkdgs = gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx_edge); + const struct gkyl_gk_dg_surf_geom *gkdgs = + gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx_edge); - const double *jacgeo_rat_surfL_d = (const double *) gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); - const double *jacgeo_rat_surfR_d = (const double *) gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf_ext); + const double *jacgeo_rat_surfL_d = + (const double *)gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); + const double *jacgeo_rat_surfR_d = (const double *)gkyl_array_cfetch( + up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf_ext + ); - double* flux_surf_ext_d = (double*) gkyl_array_fetch(flux_surf, loc_phase_ext); + double *flux_surf_ext_d = (double *)gkyl_array_fetch(flux_surf, loc_phase_ext); // Write into the skin cell's own cflrate (not the ghost cell's, which is excluded // from the CFL reduction range). Use a max instead of accumulating since cflrate_d // already holds this cell's lower-surface contribution from earlier in this dir loop. - cflrate_ext_d[0] = GKYL_MAX2(cflrate_ext_d[0], up->flux_surf_edge_up[dir](xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, - dgs, gkdgs, bmag_d, jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_ext_d)); - } + cflrate_ext_d[0] = GKYL_MAX2( + cflrate_ext_d[0], + up->flux_surf_edge_up[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs, gkdgs, bmag_d, + jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, phi_d, fL, fR, flux_surf_ext_d + ) + ); + } } } } -__global__ void -gkyl_gk_collisionless_flux_surf_surfvpar_cu_kernel(struct gkyl_gk_collisionless_flux *up, - struct gkyl_range conf_range, struct gkyl_range phase_range, - struct gkyl_range conf_ext_range, struct gkyl_range phase_ext_range, struct gkyl_range vpar_range, - const struct gkyl_array *phi, const struct gkyl_array *fin, - struct gkyl_array* flux_surf, struct gkyl_array *cflrate) -{ +__global__ void gkyl_gk_collisionless_flux_surf_surfvpar_cu_kernel( + struct gkyl_gk_collisionless_flux *up, struct gkyl_range conf_range, + struct gkyl_range phase_range, struct gkyl_range conf_ext_range, + struct gkyl_range phase_ext_range, struct gkyl_range vpar_range, const struct gkyl_array *phi, + const struct gkyl_array *fin, struct gkyl_array *flux_surf, struct gkyl_array *cflrate +) +{ int pdim = up->pdim; int cdim = up->cdim; int idx[GKYL_MAX_DIM], idx_vel[2]; @@ -125,17 +141,17 @@ gkyl_gk_collisionless_flux_surf_surfvpar_cu_kernel(struct gkyl_gk_collisionless_ double xc[GKYL_MAX_DIM]; // 2D thread grid - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < vpar_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < vpar_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange gkyl_sub_range_inv_idx(&vpar_range, linc1, idx); gkyl_rect_grid_cell_center(&up->phase_grid, idx, xc); - for (int d=cdim; dvel_map->local_vel, idx_vel); long loc_phase = gkyl_range_idx(&phase_range, idx); - const double *bmag_d = (const double*) gkyl_array_cfetch(up->gk_geom->geo_corn.bmag, loc_conf); - const double *phi_d = (const double*) gkyl_array_cfetch(phi, loc_conf); - const double *vmap_d = (const double*) gkyl_array_cfetch(up->vel_map->vmap, loc_vel); - const double *vmapSq_d = (const double*) gkyl_array_cfetch(up->vel_map->vmap_sq, loc_vel); + const double *bmag_d = (const double *)gkyl_array_cfetch(up->gk_geom->geo_corn.bmag, loc_conf); + const double *phi_d = (const double *)gkyl_array_cfetch(phi, loc_conf); + const double *vmap_d = (const double *)gkyl_array_cfetch(up->vel_map->vmap, loc_vel); + const double *vmapSq_d = (const double *)gkyl_array_cfetch(up->vel_map->vmap_sq, loc_vel); - double* flux_surf_d = (double*) gkyl_array_fetch(flux_surf, loc_phase); - double *cflrate_d = (double*) gkyl_array_fetch(cflrate, loc_phase); + double *flux_surf_d = (double *)gkyl_array_fetch(flux_surf, loc_phase); + double *cflrate_d = (double *)gkyl_array_fetch(cflrate, loc_phase); int dir = cdim; gkyl_copy_int_arr(pdim, idx, idxL); idxL[dir] = idx[dir] - 1; - gkyl_copy_int_arr(pdim-cdim, idx_vel, idx_velL); - idx_velL[0] = idx_velL[0]-1; + gkyl_copy_int_arr(pdim - cdim, idx_vel, idx_velL); + idx_velL[0] = idx_velL[0] - 1; long locL = gkyl_range_idx(&phase_range, idxL); long loc_velL = gkyl_range_idx(&up->vel_map->local_vel, idx_velL); - const double *fL = (const double*) gkyl_array_cfetch(fin, locL); - const double *fR = (const double*) gkyl_array_cfetch(fin, loc_phase); + const double *fL = (const double *)gkyl_array_cfetch(fin, locL); + const double *fR = (const double *)gkyl_array_cfetch(fin, loc_phase); - const double *vpL = (const double*) gkyl_array_cfetch(up->vel_map->vmap_prime, loc_velL); - const double *vpR = (const double*) gkyl_array_cfetch(up->vel_map->vmap_prime, loc_vel); + const double *vpL = (const double *)gkyl_array_cfetch(up->vel_map->vmap_prime, loc_velL); + const double *vpR = (const double *)gkyl_array_cfetch(up->vel_map->vmap_prime, loc_vel); const struct gkyl_dg_vol_geom *dgv = gkyl_dg_geom_get_vol(up->dg_geom, idx); const struct gkyl_gk_dg_vol_geom *gkdgv = gkyl_gk_dg_geom_get_vol(up->gk_dg_geom, idx); - cflrate_d[0] += up->flux_surfvpar[0](xc, up->phase_grid.dx, - vpL, vpR, - vmap_d, vmapSq_d, up->charge, up->mass, - dgv, gkdgv, bmag_d, phi_d, fL, fR, flux_surf_d); + cflrate_d[0] += up->flux_surfvpar[0]( + xc, up->phase_grid.dx, vpL, vpR, vmap_d, vmapSq_d, up->charge, up->mass, dgv, gkdgv, bmag_d, + phi_d, fL, fR, flux_surf_d + ); } } // Host-side wrapper for gyrokinetic surface alpha calculation -void gkyl_gk_collisionless_flux_surf_cu(struct gkyl_gk_collisionless_flux *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_ext_range, const struct gkyl_range *phase_ext_range, const struct gkyl_array *phi, - const struct gkyl_array *fin, struct gkyl_array* flux_surf, struct gkyl_array* cflrate) +void gkyl_gk_collisionless_flux_surf_cu( + struct gkyl_gk_collisionless_flux *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_range *phase_ext_range, const struct gkyl_array *phi, + const struct gkyl_array *fin, struct gkyl_array *flux_surf, struct gkyl_array *cflrate +) { - gkyl_gk_collisionless_flux_surf_conf_cu_kernel<<volume, GKYL_DEFAULT_NUM_THREADS>>>(up->on_dev, - *conf_range, *phase_range, *conf_ext_range, *phase_ext_range, phi->on_dev, fin->on_dev, - flux_surf->on_dev, cflrate->on_dev); + gkyl_gk_collisionless_flux_surf_conf_cu_kernel<<volume, GKYL_DEFAULT_NUM_THREADS> > >( + up->on_dev, *conf_range, *phase_range, *conf_ext_range, *phase_ext_range, phi->on_dev, + fin->on_dev, flux_surf->on_dev, cflrate->on_dev + ); struct gkyl_range vpar_range; int sublower[GKYL_MAX_DIM]; int subupper[GKYL_MAX_DIM]; - for(int i = 0; i < up->pdim; i++) { - sublower[i] = phase_range->lower[i]; - subupper[i] = phase_range->upper[i]; + for (int i = 0; i < up->pdim; i++) { + sublower[i] = phase_range->lower[i]; + subupper[i] = phase_range->upper[i]; } sublower[up->cdim] += 1; gkyl_sub_range_init(&vpar_range, phase_ext_range, sublower, subupper); - gkyl_gk_collisionless_flux_surf_surfvpar_cu_kernel<<>>(up->on_dev, - *conf_range, *phase_range, *conf_ext_range, *phase_ext_range, vpar_range, phi->on_dev, fin->on_dev, - flux_surf->on_dev, cflrate->on_dev); - + gkyl_gk_collisionless_flux_surf_surfvpar_cu_kernel<< > >( + up->on_dev, *conf_range, *phase_range, *conf_ext_range, *phase_ext_range, vpar_range, + phi->on_dev, fin->on_dev, flux_surf->on_dev, cflrate->on_dev + ); } // CUDA kernel to set device pointers to gyrokinetic vars kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -gk_collisionless_flux_set_cu_dev_ptrs(struct gkyl_gk_collisionless_flux *up, - int cdim, int vdim, int poly_order, enum gkyl_gk_collisionless_type type, - const enum gkyl_gyrokinetic_bc_type *bctype_conf) +__global__ static void gk_collisionless_flux_set_cu_dev_ptrs( + struct gkyl_gk_collisionless_flux *up, int cdim, int vdim, int poly_order, + enum gkyl_gk_collisionless_type type, const enum gkyl_gyrokinetic_bc_type *bctype_conf +) { if (type == GKYL_GK_COLLISIONLESS_ES) { - for (int d=0; dflux_surf kernel doesn't matter as long as it's not SKIP. - up->flux_surf[d] = choose_gk_collisionless_flux_surf_conf_kern(d, cdim, vdim, poly_order, GKYL_BC_GK_SPECIES_ABSORB); - up->flux_surf_edge_lo[d] = choose_gk_collisionless_flux_surf_conf_kern(d, cdim, vdim, - poly_order, bctype_conf[d]); - up->flux_surf_edge_up[d] = choose_gk_collisionless_flux_edge_surf_conf_kern(d, cdim, vdim, - poly_order, bctype_conf[GKYL_MAX_CDIM+d]); + up->flux_surf[d] = choose_gk_collisionless_flux_surf_conf_kern( + d, cdim, vdim, poly_order, GKYL_BC_GK_SPECIES_ABSORB + ); + up->flux_surf_edge_lo[d] = + choose_gk_collisionless_flux_surf_conf_kern(d, cdim, vdim, poly_order, bctype_conf[d]); + up->flux_surf_edge_up[d] = choose_gk_collisionless_flux_edge_surf_conf_kern( + d, cdim, vdim, poly_order, bctype_conf[GKYL_MAX_CDIM + d] + ); } up->flux_surfvpar[0] = choose_gk_collisionless_flux_surf_vpar_kern(cdim, vdim, poly_order); - } - else if (type == GKYL_GK_COLLISIONLESS_ES_NO_BY) { - for (int d=0; dflux_surf kernel doesn't matter as long as it's not SKIP. - up->flux_surf[d] = choose_gk_collisionless_flux_no_by_surf_conf_kern(d, cdim, vdim, poly_order, GKYL_BC_GK_SPECIES_ABSORB); - up->flux_surf_edge_lo[d] = choose_gk_collisionless_flux_no_by_surf_conf_kern(d, cdim, vdim, - poly_order, bctype_conf[d]); - up->flux_surf_edge_up[d] = choose_gk_collisionless_flux_no_by_edge_surf_conf_kern(d, cdim, vdim, - poly_order, bctype_conf[GKYL_MAX_CDIM+d]); + up->flux_surf[d] = choose_gk_collisionless_flux_no_by_surf_conf_kern( + d, cdim, vdim, poly_order, GKYL_BC_GK_SPECIES_ABSORB + ); + up->flux_surf_edge_lo[d] = choose_gk_collisionless_flux_no_by_surf_conf_kern( + d, cdim, vdim, poly_order, bctype_conf[d] + ); + up->flux_surf_edge_up[d] = choose_gk_collisionless_flux_no_by_edge_surf_conf_kern( + d, cdim, vdim, poly_order, bctype_conf[GKYL_MAX_CDIM + d] + ); } - up->flux_surfvpar[0] = choose_gk_collisionless_flux_no_by_surf_vpar_kern(cdim, vdim, poly_order); + up->flux_surfvpar[0] = + choose_gk_collisionless_flux_no_by_surf_vpar_kern(cdim, vdim, poly_order); } } -gkyl_gk_collisionless_flux* -gkyl_gk_collisionless_flux_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const double charge, const double mass, - enum gkyl_gk_collisionless_type type, - const struct gk_geometry *gk_geom, const struct gkyl_dg_geom *dg_geom, - const struct gkyl_gk_dg_geom *gk_dg_geom, const struct gkyl_velocity_map *vel_map, - const enum gkyl_gyrokinetic_bc_type *bctype_conf) +gkyl_gk_collisionless_flux *gkyl_gk_collisionless_flux_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const double charge, const double mass, + enum gkyl_gk_collisionless_type type, const struct gk_geometry *gk_geom, + const struct gkyl_dg_geom *dg_geom, const struct gkyl_gk_dg_geom *gk_dg_geom, + const struct gkyl_velocity_map *vel_map, const enum gkyl_gyrokinetic_bc_type *bctype_conf +) { - struct gkyl_gk_collisionless_flux *up = (struct gkyl_gk_collisionless_flux*) gkyl_malloc(sizeof(*up)); + struct gkyl_gk_collisionless_flux *up = + (struct gkyl_gk_collisionless_flux *)gkyl_malloc(sizeof(*up)); up->phase_grid = *phase_grid; int cdim = conf_basis->ndim; @@ -257,7 +283,7 @@ gkyl_gk_collisionless_flux_cu_dev_new(const struct gkyl_rect_grid *phase_grid, struct gkyl_dg_geom *dg_geom_ho = gkyl_dg_geom_acquire(dg_geom); struct gkyl_gk_dg_geom *gk_dg_geom_ho = gkyl_gk_dg_geom_acquire(gk_dg_geom); struct gkyl_velocity_map *vel_map_ho = gkyl_velocity_map_acquire(vel_map); - + up->gk_geom = geom_ho->on_dev; up->dg_geom = dg_geom_ho->on_dev; up->gk_dg_geom = gk_dg_geom_ho->on_dev; @@ -267,13 +293,21 @@ gkyl_gk_collisionless_flux_cu_dev_new(const struct gkyl_rect_grid *phase_grid, GKYL_SET_CU_ALLOC(up->flags); // Temporarily copy array of BCs to device for kernel selection. - enum gkyl_gyrokinetic_bc_type *bctype_conf_dev = (enum gkyl_gyrokinetic_bc_type *) gkyl_cu_malloc(2*GKYL_MAX_CDIM*sizeof(enum gkyl_gyrokinetic_bc_type)); - gkyl_cu_memcpy(bctype_conf_dev, bctype_conf, 2*GKYL_MAX_CDIM*sizeof(enum gkyl_gyrokinetic_bc_type), GKYL_CU_MEMCPY_H2D); - - struct gkyl_gk_collisionless_flux *up_cu = (struct gkyl_gk_collisionless_flux*) gkyl_cu_malloc(sizeof(*up_cu)); + enum gkyl_gyrokinetic_bc_type *bctype_conf_dev = (enum gkyl_gyrokinetic_bc_type *)gkyl_cu_malloc( + 2 * GKYL_MAX_CDIM * sizeof(enum gkyl_gyrokinetic_bc_type) + ); + gkyl_cu_memcpy( + bctype_conf_dev, bctype_conf, 2 * GKYL_MAX_CDIM * sizeof(enum gkyl_gyrokinetic_bc_type), + GKYL_CU_MEMCPY_H2D + ); + + struct gkyl_gk_collisionless_flux *up_cu = + (struct gkyl_gk_collisionless_flux *)gkyl_cu_malloc(sizeof(*up_cu)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_gk_collisionless_flux), GKYL_CU_MEMCPY_H2D); - gk_collisionless_flux_set_cu_dev_ptrs<<<1,1>>>(up_cu, cdim, vdim, poly_order, type, bctype_conf_dev); + gk_collisionless_flux_set_cu_dev_ptrs<<<1, 1> > >( + up_cu, cdim, vdim, poly_order, type, bctype_conf_dev + ); gkyl_cu_free(bctype_conf_dev); @@ -281,10 +315,10 @@ gkyl_gk_collisionless_flux_cu_dev_new(const struct gkyl_rect_grid *phase_grid, up->on_dev = up_cu; // Updater should store host pointers. - up->gk_geom = geom_ho; - up->dg_geom = dg_geom_ho; - up->gk_dg_geom = gk_dg_geom_ho; - up->vel_map = vel_map_ho; - + up->gk_geom = geom_ho; + up->dg_geom = dg_geom_ho; + up->gk_dg_geom = gk_dg_geom_ho; + up->vel_map = vel_map_ho; + return up; } diff --git a/gyrokinetic/zero/gk_collisionless_passive_flux.c b/gyrokinetic/zero/gk_collisionless_passive_flux.c index b458dd7633..643f462c85 100644 --- a/gyrokinetic/zero/gk_collisionless_passive_flux.c +++ b/gyrokinetic/zero/gk_collisionless_passive_flux.c @@ -8,19 +8,22 @@ #include #include -gkyl_gk_collisionless_passive_flux* -gkyl_gk_collisionless_passive_flux_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_array *passive_speeds, - const double charge, const double mass, - const struct gk_geometry *gk_geom, const struct gkyl_dg_geom *dg_geom, - const struct gkyl_gk_dg_geom *gk_dg_geom, const struct gkyl_velocity_map *vel_map, - const enum gkyl_gyrokinetic_bc_type *bctype_conf, bool use_gpu) +gkyl_gk_collisionless_passive_flux *gkyl_gk_collisionless_passive_flux_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_array *passive_speeds, + const double charge, const double mass, const struct gk_geometry *gk_geom, + const struct gkyl_dg_geom *dg_geom, const struct gkyl_gk_dg_geom *gk_dg_geom, + const struct gkyl_velocity_map *vel_map, const enum gkyl_gyrokinetic_bc_type *bctype_conf, + bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) - return gkyl_gk_collisionless_passive_flux_cu_dev_new(phase_grid, conf_basis, phase_basis, - passive_speeds, charge, mass, gk_geom, dg_geom, gk_dg_geom, vel_map, bctype_conf); + if (use_gpu) { + return gkyl_gk_collisionless_passive_flux_cu_dev_new( + phase_grid, conf_basis, phase_basis, passive_speeds, charge, mass, gk_geom, dg_geom, + gk_dg_geom, vel_map, bctype_conf + ); + } #endif gkyl_gk_collisionless_passive_flux *up = gkyl_malloc(sizeof(gkyl_gk_collisionless_passive_flux)); @@ -39,16 +42,21 @@ gkyl_gk_collisionless_passive_flux_new(const struct gkyl_rect_grid *phase_grid, // Store pointers to the projected passive-speed arrays (not owned here). up->passive_speeds = passive_speeds; - up->gk_geom = gkyl_gk_geometry_acquire(gk_geom); - up->dg_geom = gkyl_dg_geom_acquire(dg_geom); + up->gk_geom = gkyl_gk_geometry_acquire(gk_geom); + up->dg_geom = gkyl_dg_geom_acquire(dg_geom); up->gk_dg_geom = gkyl_gk_dg_geom_acquire(gk_dg_geom); - up->vel_map = gkyl_velocity_map_acquire(vel_map); + up->vel_map = gkyl_velocity_map_acquire(vel_map); // Select kernels for each conf-space direction. for (int d = 0; d < cdim; d++) { - up->flux_surf[d] = choose_gk_collisionless_passive_flux_surf_conf_kern(d, cdim, vdim, poly_order); - up->flux_surf_edge_lo[d] = choose_gk_collisionless_passive_flux_edge_lo_surf_conf_kern(d, cdim, vdim, poly_order, bctype_conf[d]); - up->flux_surf_edge_up[d] = choose_gk_collisionless_passive_flux_edge_up_surf_conf_kern(d, cdim, vdim, poly_order, bctype_conf[GKYL_MAX_CDIM+d]); + up->flux_surf[d] = + choose_gk_collisionless_passive_flux_surf_conf_kern(d, cdim, vdim, poly_order); + up->flux_surf_edge_lo[d] = choose_gk_collisionless_passive_flux_edge_lo_surf_conf_kern( + d, cdim, vdim, poly_order, bctype_conf[d] + ); + up->flux_surf_edge_up[d] = choose_gk_collisionless_passive_flux_edge_up_surf_conf_kern( + d, cdim, vdim, poly_order, bctype_conf[GKYL_MAX_CDIM + d] + ); } up->flags = 0; @@ -58,17 +66,18 @@ gkyl_gk_collisionless_passive_flux_new(const struct gkyl_rect_grid *phase_grid, return up; } -void -gkyl_gk_collisionless_passive_flux_surf(gkyl_gk_collisionless_passive_flux *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_ext_range, const struct gkyl_range *phase_ext_range, - const struct gkyl_array *fin, - struct gkyl_array *flux_surf, struct gkyl_array *cflrate) +void gkyl_gk_collisionless_passive_flux_surf( + gkyl_gk_collisionless_passive_flux *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_range *phase_ext_range, const struct gkyl_array *fin, + struct gkyl_array *flux_surf, struct gkyl_array *cflrate +) { #ifdef GKYL_HAVE_CUDA if (GKYL_IS_CU_ALLOC(up->flags)) { - gkyl_gk_collisionless_passive_flux_surf_cu(up, conf_range, phase_range, - conf_ext_range, phase_ext_range, fin, flux_surf, cflrate); + gkyl_gk_collisionless_passive_flux_surf_cu( + up, conf_range, phase_range, conf_ext_range, phase_ext_range, fin, flux_surf, cflrate + ); return; } #endif @@ -84,34 +93,38 @@ gkyl_gk_collisionless_passive_flux_surf(gkyl_gk_collisionless_passive_flux *up, while (gkyl_range_iter_next(&iter)) { gkyl_copy_int_arr(pdim, iter.idx, idx); - for (int d = cdim; d < pdim; d++) idx_vel[d-cdim] = iter.idx[d]; + for (int d = cdim; d < pdim; d++) { + idx_vel[d - cdim] = iter.idx[d]; + } - long loc_conf = gkyl_range_idx(conf_range, idx); - long loc_vel = gkyl_range_idx(&up->vel_map->local_vel, idx_vel); + long loc_conf = gkyl_range_idx(conf_range, idx); + long loc_vel = gkyl_range_idx(&up->vel_map->local_vel, idx_vel); long loc_phase = gkyl_range_idx(phase_range, idx); gkyl_rect_grid_cell_center(&up->phase_grid, idx, xc); - const double *bmag_d = gkyl_array_cfetch(up->gk_geom->geo_corn.bmag, loc_conf); - const double *vmap_d = gkyl_array_cfetch(up->vel_map->vmap, loc_vel); - const double *vmapSq_d = gkyl_array_cfetch(up->vel_map->vmap_sq, loc_vel); + const double *bmag_d = gkyl_array_cfetch(up->gk_geom->geo_corn.bmag, loc_conf); + const double *vmap_d = gkyl_array_cfetch(up->vel_map->vmap, loc_vel); + const double *vmapSq_d = gkyl_array_cfetch(up->vel_map->vmap_sq, loc_vel); double *flux_surf_d = gkyl_array_fetch(flux_surf, loc_phase); - double *cflrate_d = gkyl_array_fetch(cflrate, loc_phase); + double *cflrate_d = gkyl_array_fetch(cflrate, loc_phase); for (int dir = 0; dir < cdim; dir++) { gkyl_copy_int_arr(pdim, idx, idxL); idxL[dir] = idx[dir] - 1; - long loc_confL = gkyl_range_idx(conf_range, idxL); - long locL = gkyl_range_idx(phase_range, idxL); + long loc_confL = gkyl_range_idx(conf_range, idxL); + long locL = gkyl_range_idx(phase_range, idxL); const double *fL = gkyl_array_cfetch(fin, locL); const double *fR = gkyl_array_cfetch(fin, loc_phase); - const struct gkyl_dg_surf_geom *dgs = gkyl_dg_geom_get_surf(up->dg_geom, dir, idx); + const struct gkyl_dg_surf_geom *dgs = gkyl_dg_geom_get_surf(up->dg_geom, dir, idx); const struct gkyl_gk_dg_surf_geom *gkdgs = gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx); - const double *jacgeo_rat_surfL_d = gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_confL); - const double *jacgeo_rat_surfR_d = gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); + const double *jacgeo_rat_surfL_d = + gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_confL); + const double *jacgeo_rat_surfR_d = + gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); // Fetch passive speed DG coefficients at the left and right conf cells. const double *speeds_L = gkyl_array_cfetch(up->passive_speeds, loc_confL); @@ -119,16 +132,16 @@ gkyl_gk_collisionless_passive_flux_surf(gkyl_gk_collisionless_passive_flux *up, if (idx[dir] == phase_range->lower[dir]) { // Lower domain boundary. - cflrate_d[0] += up->flux_surf_edge_lo[dir](xc, up->phase_grid.dx, - vmap_d, vmapSq_d, up->charge, up->mass, - dgs, gkdgs, bmag_d, jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, - speeds_L, speeds_R, fL, fR, flux_surf_d); + cflrate_d[0] += up->flux_surf_edge_lo[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs, gkdgs, bmag_d, + jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, speeds_L, speeds_R, fL, fR, flux_surf_d + ); } else { // Interior lower surface. - cflrate_d[0] += up->flux_surf[dir](xc, up->phase_grid.dx, - vmap_d, vmapSq_d, up->charge, up->mass, - dgs, gkdgs, bmag_d, jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, - speeds_L, speeds_R, fL, fR, flux_surf_d); + cflrate_d[0] += up->flux_surf[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs, gkdgs, bmag_d, + jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, speeds_L, speeds_R, fL, fR, flux_surf_d + ); } // Upper domain boundary: also compute the upper-edge surface expansion @@ -136,51 +149,56 @@ gkyl_gk_collisionless_passive_flux_surf(gkyl_gk_collisionless_passive_flux *up, if (idx[dir] == phase_range->upper[dir]) { gkyl_copy_int_arr(pdim, idx, idx_ghost); idx_ghost[dir] += 1; - long loc_conf_ghost = gkyl_range_idx(conf_ext_range, idx_ghost); + long loc_conf_ghost = gkyl_range_idx(conf_ext_range, idx_ghost); long loc_phase_ghost = gkyl_range_idx(phase_ext_range, idx_ghost); // Write into the skin cell's own cflrate (not the ghost cell's, which is excluded // from the CFL reduction range). Use a max instead of accumulating since cflrate_d // already holds this cell's lower-surface contribution from earlier in this dir loop. - double *cflrate_ghost_d = gkyl_array_fetch(cflrate, loc_phase); - const double *f_skin = gkyl_array_cfetch(fin, loc_phase); + double *cflrate_ghost_d = gkyl_array_fetch(cflrate, loc_phase); + const double *f_skin = gkyl_array_cfetch(fin, loc_phase); const double *f_ghost = gkyl_array_cfetch(fin, loc_phase_ghost); - const struct gkyl_dg_surf_geom *dgs_ghost = gkyl_dg_geom_get_surf(up->dg_geom, dir, idx_ghost); - const struct gkyl_gk_dg_surf_geom *gkdgs_ghost = gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx_ghost); + const struct gkyl_dg_surf_geom *dgs_ghost = + gkyl_dg_geom_get_surf(up->dg_geom, dir, idx_ghost); + const struct gkyl_gk_dg_surf_geom *gkdgs_ghost = + gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx_ghost); - const double *jacgeo_rat_surf_skin = gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); - const double *jacgeo_rat_surf_ghost = gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf_ghost); + const double *jacgeo_rat_surf_skin = + gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); + const double *jacgeo_rat_surf_ghost = + gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf_ghost); // Passive speeds at the upper edge: right cell is the ghost cell, // so use the skin-cell speed for both sides (speeds are not defined in ghosts). - const double *speeds_skin = gkyl_array_cfetch(up->passive_speeds, loc_conf); + const double *speeds_skin = gkyl_array_cfetch(up->passive_speeds, loc_conf); const double *speeds_ghost = gkyl_array_cfetch(up->passive_speeds, loc_conf_ghost); double *flux_surf_ghost_d = gkyl_array_fetch(flux_surf, loc_phase_ghost); - cflrate_ghost_d[0] = GKYL_MAX2(cflrate_ghost_d[0], up->flux_surf_edge_up[dir](xc, up->phase_grid.dx, - vmap_d, vmapSq_d, up->charge, up->mass, - dgs_ghost, gkdgs_ghost, bmag_d, - jacgeo_rat_surf_skin, jacgeo_rat_surf_ghost, - speeds_skin, speeds_ghost, - f_skin, f_ghost, flux_surf_ghost_d)); - + cflrate_ghost_d[0] = GKYL_MAX2( + cflrate_ghost_d[0], + up->flux_surf_edge_up[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs_ghost, gkdgs_ghost, + bmag_d, jacgeo_rat_surf_skin, jacgeo_rat_surf_ghost, speeds_skin, speeds_ghost, f_skin, + f_ghost, flux_surf_ghost_d + ) + ); } } // No vpar loop: passive advection has no velocity-space component. } } -void -gkyl_gk_collisionless_passive_flux_release(gkyl_gk_collisionless_passive_flux *up) +void gkyl_gk_collisionless_passive_flux_release(gkyl_gk_collisionless_passive_flux *up) { gkyl_gk_geometry_release(up->gk_geom); gkyl_dg_geom_release(up->dg_geom); gkyl_gk_dg_geom_release(up->gk_dg_geom); gkyl_velocity_map_release(up->vel_map); - if (GKYL_IS_CU_ALLOC(up->flags)) + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/gyrokinetic/zero/gk_collisionless_passive_flux_cu.cu b/gyrokinetic/zero/gk_collisionless_passive_flux_cu.cu index 88351efc35..4bb40db51a 100644 --- a/gyrokinetic/zero/gk_collisionless_passive_flux_cu.cu +++ b/gyrokinetic/zero/gk_collisionless_passive_flux_cu.cu @@ -13,12 +13,12 @@ extern "C" { #include } -__global__ void -gkyl_gk_collisionless_passive_flux_surf_conf_cu_kernel(struct gkyl_gk_collisionless_passive_flux *up, - struct gkyl_range conf_range, struct gkyl_range phase_range, - struct gkyl_range conf_ext_range, struct gkyl_range phase_ext_range, - const struct gkyl_array *fin, - struct gkyl_array *flux_surf, struct gkyl_array *cflrate) +__global__ void gkyl_gk_collisionless_passive_flux_surf_conf_cu_kernel( + struct gkyl_gk_collisionless_passive_flux *up, struct gkyl_range conf_range, + struct gkyl_range phase_range, struct gkyl_range conf_ext_range, + struct gkyl_range phase_ext_range, const struct gkyl_array *fin, struct gkyl_array *flux_surf, + struct gkyl_array *cflrate +) { int pdim = up->pdim; int cdim = up->cdim; @@ -26,55 +26,57 @@ gkyl_gk_collisionless_passive_flux_surf_conf_cu_kernel(struct gkyl_gk_collisionl int idxL[GKYL_MAX_DIM]; double xc[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < phase_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < phase_range.volume; + linc1 += gridDim.x * blockDim.x) { gkyl_sub_range_inv_idx(&phase_range, linc1, idx); gkyl_rect_grid_cell_center(&up->phase_grid, idx, xc); - for (int d = cdim; d < pdim; d++) idx_vel[d-cdim] = idx[d]; + for (int d = cdim; d < pdim; d++) { + idx_vel[d - cdim] = idx[d]; + } - long loc_conf = gkyl_range_idx(&conf_range, idx); - long loc_vel = gkyl_range_idx(&up->vel_map->local_vel, idx_vel); + long loc_conf = gkyl_range_idx(&conf_range, idx); + long loc_vel = gkyl_range_idx(&up->vel_map->local_vel, idx_vel); long loc_phase = gkyl_range_idx(&phase_range, idx); - const double *bmag_d = (const double*) gkyl_array_cfetch(up->gk_geom->geo_corn.bmag, loc_conf); - const double *vmap_d = (const double*) gkyl_array_cfetch(up->vel_map->vmap, loc_vel); - const double *vmapSq_d = (const double*) gkyl_array_cfetch(up->vel_map->vmap_sq, loc_vel); + const double *bmag_d = (const double *)gkyl_array_cfetch(up->gk_geom->geo_corn.bmag, loc_conf); + const double *vmap_d = (const double *)gkyl_array_cfetch(up->vel_map->vmap, loc_vel); + const double *vmapSq_d = (const double *)gkyl_array_cfetch(up->vel_map->vmap_sq, loc_vel); - double *flux_surf_d = (double*) gkyl_array_fetch(flux_surf, loc_phase); - double *cflrate_d = (double*) gkyl_array_fetch(cflrate, loc_phase); + double *flux_surf_d = (double *)gkyl_array_fetch(flux_surf, loc_phase); + double *cflrate_d = (double *)gkyl_array_fetch(cflrate, loc_phase); for (int dir = 0; dir < cdim; dir++) { gkyl_copy_int_arr(pdim, idx, idxL); idxL[dir] = idx[dir] - 1; long loc_confL = gkyl_range_idx(&conf_range, idxL); - long locL = gkyl_range_idx(&phase_range, idxL); - const double *fL = (const double*) gkyl_array_cfetch(fin, locL); - const double *fR = (const double*) gkyl_array_cfetch(fin, loc_phase); + long locL = gkyl_range_idx(&phase_range, idxL); + const double *fL = (const double *)gkyl_array_cfetch(fin, locL); + const double *fR = (const double *)gkyl_array_cfetch(fin, loc_phase); - const struct gkyl_dg_surf_geom *dgs = gkyl_dg_geom_get_surf(up->dg_geom, dir, idx); + const struct gkyl_dg_surf_geom *dgs = gkyl_dg_geom_get_surf(up->dg_geom, dir, idx); const struct gkyl_gk_dg_surf_geom *gkdgs = gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx); - const double *jacgeo_rat_surfL_d = (const double*) gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_confL); - const double *jacgeo_rat_surfR_d = (const double*) gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); + const double *jacgeo_rat_surfL_d = + (const double *)gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_confL); + const double *jacgeo_rat_surfR_d = + (const double *)gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); - const double *speeds_L = (const double*) gkyl_array_cfetch(up->passive_speeds, loc_confL); - const double *speeds_R = (const double*) gkyl_array_cfetch(up->passive_speeds, loc_conf); + const double *speeds_L = (const double *)gkyl_array_cfetch(up->passive_speeds, loc_confL); + const double *speeds_R = (const double *)gkyl_array_cfetch(up->passive_speeds, loc_conf); if (idx[dir] == phase_range.lower[dir]) { // Lower domain/block boundary. - cflrate_d[0] += up->flux_surf_edge_lo[dir](xc, up->phase_grid.dx, - vmap_d, vmapSq_d, up->charge, up->mass, - dgs, gkdgs, bmag_d, jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, - speeds_L, speeds_R, fL, fR, flux_surf_d); + cflrate_d[0] += up->flux_surf_edge_lo[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs, gkdgs, bmag_d, + jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, speeds_L, speeds_R, fL, fR, flux_surf_d + ); } else { // Interior, lower cell surface. - cflrate_d[0] += up->flux_surf[dir](xc, up->phase_grid.dx, - vmap_d, vmapSq_d, up->charge, up->mass, - dgs, gkdgs, bmag_d, jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, - speeds_L, speeds_R, fL, fR, flux_surf_d); + cflrate_d[0] += up->flux_surf[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs, gkdgs, bmag_d, + jacgeo_rat_surfL_d, jacgeo_rat_surfR_d, speeds_L, speeds_R, fL, fR, flux_surf_d + ); } // Upper domain boundary: compute the upper-edge surface expansion stored @@ -82,33 +84,41 @@ gkyl_gk_collisionless_passive_flux_surf_conf_cu_kernel(struct gkyl_gk_collisionl if (idx[dir] == phase_range.upper[dir]) { gkyl_copy_int_arr(pdim, idx, idx_ghost); idx_ghost[dir] = idx_ghost[dir] + 1; - long loc_conf_ghost = gkyl_range_idx(&conf_ext_range, idx_ghost); + long loc_conf_ghost = gkyl_range_idx(&conf_ext_range, idx_ghost); long loc_phase_ghost = gkyl_range_idx(&phase_ext_range, idx_ghost); // Write into the skin cell's own cflrate (not the ghost cell's, which is excluded // from the CFL reduction range). Use a max instead of accumulating since cflrate_d // already holds this cell's lower-surface contribution from earlier in this dir loop. - double *cflrate_ghost_d = (double*) gkyl_array_fetch(cflrate, loc_phase); - const double *f_skin = (const double*) gkyl_array_cfetch(fin, loc_phase); - const double *f_ghost = (const double*) gkyl_array_cfetch(fin, loc_phase_ghost); - - const struct gkyl_dg_surf_geom *dgs_ghost = gkyl_dg_geom_get_surf(up->dg_geom, dir, idx_ghost); - const struct gkyl_gk_dg_surf_geom *gkdgs_ghost = gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx_ghost); - - const double *jacgeo_rat_surf_skin = (const double*) gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); - const double *jacgeo_rat_surf_ghost = (const double*) gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf_ghost); - - const double *speeds_skin = (const double*) gkyl_array_cfetch(up->passive_speeds, loc_conf); - const double *speeds_ghost = (const double*) gkyl_array_cfetch(up->passive_speeds, loc_conf_ghost); - - double *flux_surf_ghost_d = (double*) gkyl_array_fetch(flux_surf, loc_phase_ghost); - - cflrate_ghost_d[0] = GKYL_MAX2(cflrate_ghost_d[0], up->flux_surf_edge_up[dir](xc, up->phase_grid.dx, - vmap_d, vmapSq_d, up->charge, up->mass, - dgs_ghost, gkdgs_ghost, bmag_d, - jacgeo_rat_surf_skin, jacgeo_rat_surf_ghost, - speeds_skin, speeds_ghost, - f_skin, f_ghost, flux_surf_ghost_d)); + double *cflrate_ghost_d = (double *)gkyl_array_fetch(cflrate, loc_phase); + const double *f_skin = (const double *)gkyl_array_cfetch(fin, loc_phase); + const double *f_ghost = (const double *)gkyl_array_cfetch(fin, loc_phase_ghost); + + const struct gkyl_dg_surf_geom *dgs_ghost = + gkyl_dg_geom_get_surf(up->dg_geom, dir, idx_ghost); + const struct gkyl_gk_dg_surf_geom *gkdgs_ghost = + gkyl_gk_dg_geom_get_surf(up->gk_dg_geom, dir, idx_ghost); + + const double *jacgeo_rat_surf_skin = + (const double *)gkyl_array_cfetch(up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf); + const double *jacgeo_rat_surf_ghost = (const double *)gkyl_array_cfetch( + up->gk_geom->geo_surf[dir].jacobgeo_ratio, loc_conf_ghost + ); + + const double *speeds_skin = (const double *)gkyl_array_cfetch(up->passive_speeds, loc_conf); + const double *speeds_ghost = + (const double *)gkyl_array_cfetch(up->passive_speeds, loc_conf_ghost); + + double *flux_surf_ghost_d = (double *)gkyl_array_fetch(flux_surf, loc_phase_ghost); + + cflrate_ghost_d[0] = GKYL_MAX2( + cflrate_ghost_d[0], + up->flux_surf_edge_up[dir]( + xc, up->phase_grid.dx, vmap_d, vmapSq_d, up->charge, up->mass, dgs_ghost, gkdgs_ghost, + bmag_d, jacgeo_rat_surf_skin, jacgeo_rat_surf_ghost, speeds_skin, speeds_ghost, f_skin, + f_ghost, flux_surf_ghost_d + ) + ); } } // No vpar loop: passive advection is conf-space only. @@ -116,42 +126,49 @@ gkyl_gk_collisionless_passive_flux_surf_conf_cu_kernel(struct gkyl_gk_collisionl } // Host-side wrapper for the passive surface flux kernel. -void -gkyl_gk_collisionless_passive_flux_surf_cu(gkyl_gk_collisionless_passive_flux *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_ext_range, const struct gkyl_range *phase_ext_range, - const struct gkyl_array *fin, - struct gkyl_array *flux_surf, struct gkyl_array *cflrate) +void gkyl_gk_collisionless_passive_flux_surf_cu( + gkyl_gk_collisionless_passive_flux *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_range *phase_ext_range, const struct gkyl_array *fin, + struct gkyl_array *flux_surf, struct gkyl_array *cflrate +) { - gkyl_gk_collisionless_passive_flux_surf_conf_cu_kernel<<volume, GKYL_DEFAULT_NUM_THREADS>>>( - up->on_dev, *conf_range, *phase_range, *conf_ext_range, *phase_ext_range, - fin->on_dev, flux_surf->on_dev, cflrate->on_dev); + gkyl_gk_collisionless_passive_flux_surf_conf_cu_kernel<<< + phase_range->volume, GKYL_DEFAULT_NUM_THREADS> > >( + up->on_dev, *conf_range, *phase_range, *conf_ext_range, *phase_ext_range, fin->on_dev, + flux_surf->on_dev, cflrate->on_dev + ); } // CUDA kernel to set device function pointers. // Doing function-pointer work here avoids troublesome cudaMemcpyFromSymbol. -__global__ static void -gk_collisionless_passive_flux_set_cu_dev_ptrs(struct gkyl_gk_collisionless_passive_flux *up, - int cdim, int vdim, int poly_order, const enum gkyl_gyrokinetic_bc_type *bctype_conf) +__global__ static void gk_collisionless_passive_flux_set_cu_dev_ptrs( + struct gkyl_gk_collisionless_passive_flux *up, int cdim, int vdim, int poly_order, + const enum gkyl_gyrokinetic_bc_type *bctype_conf +) { for (int d = 0; d < cdim; d++) { - up->flux_surf[d] = choose_gk_collisionless_passive_flux_surf_conf_kern(d, cdim, vdim, poly_order); - up->flux_surf_edge_lo[d] = choose_gk_collisionless_passive_flux_edge_lo_surf_conf_kern(d, cdim, vdim, poly_order, bctype_conf[d]); - up->flux_surf_edge_up[d] = choose_gk_collisionless_passive_flux_edge_up_surf_conf_kern(d, cdim, vdim, poly_order, bctype_conf[GKYL_MAX_CDIM+d]); + up->flux_surf[d] = + choose_gk_collisionless_passive_flux_surf_conf_kern(d, cdim, vdim, poly_order); + up->flux_surf_edge_lo[d] = choose_gk_collisionless_passive_flux_edge_lo_surf_conf_kern( + d, cdim, vdim, poly_order, bctype_conf[d] + ); + up->flux_surf_edge_up[d] = choose_gk_collisionless_passive_flux_edge_up_surf_conf_kern( + d, cdim, vdim, poly_order, bctype_conf[GKYL_MAX_CDIM + d] + ); } } -gkyl_gk_collisionless_passive_flux* -gkyl_gk_collisionless_passive_flux_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_array *passive_speeds, - const double charge, const double mass, - const struct gk_geometry *gk_geom, const struct gkyl_dg_geom *dg_geom, - const struct gkyl_gk_dg_geom *gk_dg_geom, const struct gkyl_velocity_map *vel_map, - const enum gkyl_gyrokinetic_bc_type *bctype_conf) +gkyl_gk_collisionless_passive_flux *gkyl_gk_collisionless_passive_flux_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_array *passive_speeds, + const double charge, const double mass, const struct gk_geometry *gk_geom, + const struct gkyl_dg_geom *dg_geom, const struct gkyl_gk_dg_geom *gk_dg_geom, + const struct gkyl_velocity_map *vel_map, const enum gkyl_gyrokinetic_bc_type *bctype_conf +) { gkyl_gk_collisionless_passive_flux *up = - (gkyl_gk_collisionless_passive_flux*) gkyl_malloc(sizeof(*up)); + (gkyl_gk_collisionless_passive_flux *)gkyl_malloc(sizeof(*up)); up->phase_grid = *phase_grid; int cdim = conf_basis->ndim; @@ -162,35 +179,42 @@ gkyl_gk_collisionless_passive_flux_cu_dev_new(const struct gkyl_rect_grid *phase up->pdim = pdim; up->charge = charge; - up->mass = mass; + up->mass = mass; // Store on_dev pointers so the memcpy below carries device-side array references. up->passive_speeds = passive_speeds->on_dev; // Acquire geometry/vel_map and use their on_dev pointers for the device copy. - struct gk_geometry *geom_ho = gkyl_gk_geometry_acquire(gk_geom); - struct gkyl_dg_geom *dg_geom_ho = gkyl_dg_geom_acquire(dg_geom); - struct gkyl_gk_dg_geom *gk_dg_geom_ho = gkyl_gk_dg_geom_acquire(gk_dg_geom); - struct gkyl_velocity_map *vel_map_ho = gkyl_velocity_map_acquire(vel_map); + struct gk_geometry *geom_ho = gkyl_gk_geometry_acquire(gk_geom); + struct gkyl_dg_geom *dg_geom_ho = gkyl_dg_geom_acquire(dg_geom); + struct gkyl_gk_dg_geom *gk_dg_geom_ho = gkyl_gk_dg_geom_acquire(gk_dg_geom); + struct gkyl_velocity_map *vel_map_ho = gkyl_velocity_map_acquire(vel_map); - up->gk_geom = geom_ho->on_dev; - up->dg_geom = dg_geom_ho->on_dev; + up->gk_geom = geom_ho->on_dev; + up->dg_geom = dg_geom_ho->on_dev; up->gk_dg_geom = gk_dg_geom_ho->on_dev; - up->vel_map = vel_map_ho->on_dev; + up->vel_map = vel_map_ho->on_dev; up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); // Temporarily copy array of BCs to device for kernel selection. - enum gkyl_gyrokinetic_bc_type *bctype_conf_dev = (enum gkyl_gyrokinetic_bc_type *) gkyl_cu_malloc(2*GKYL_MAX_CDIM*sizeof(enum gkyl_gyrokinetic_bc_type)); - gkyl_cu_memcpy(bctype_conf_dev, bctype_conf, 2*GKYL_MAX_CDIM*sizeof(enum gkyl_gyrokinetic_bc_type), GKYL_CU_MEMCPY_H2D); + enum gkyl_gyrokinetic_bc_type *bctype_conf_dev = (enum gkyl_gyrokinetic_bc_type *)gkyl_cu_malloc( + 2 * GKYL_MAX_CDIM * sizeof(enum gkyl_gyrokinetic_bc_type) + ); + gkyl_cu_memcpy( + bctype_conf_dev, bctype_conf, 2 * GKYL_MAX_CDIM * sizeof(enum gkyl_gyrokinetic_bc_type), + GKYL_CU_MEMCPY_H2D + ); // Copy host struct to device and select kernels. struct gkyl_gk_collisionless_passive_flux *up_cu = - (struct gkyl_gk_collisionless_passive_flux*) gkyl_cu_malloc(sizeof(*up_cu)); + (struct gkyl_gk_collisionless_passive_flux *)gkyl_cu_malloc(sizeof(*up_cu)); gkyl_cu_memcpy(up_cu, up, sizeof(*up), GKYL_CU_MEMCPY_H2D); - gk_collisionless_passive_flux_set_cu_dev_ptrs<<<1,1>>>(up_cu, cdim, vdim, poly_order, bctype_conf_dev); + gk_collisionless_passive_flux_set_cu_dev_ptrs<<<1, 1> > >( + up_cu, cdim, vdim, poly_order, bctype_conf_dev + ); gkyl_cu_free(bctype_conf_dev); @@ -199,10 +223,10 @@ gkyl_gk_collisionless_passive_flux_cu_dev_new(const struct gkyl_rect_grid *phase // Restore host-side pointers for the host updater. up->passive_speeds = passive_speeds; - up->gk_geom = geom_ho; - up->dg_geom = dg_geom_ho; + up->gk_geom = geom_ho; + up->dg_geom = dg_geom_ho; up->gk_dg_geom = gk_dg_geom_ho; - up->vel_map = vel_map_ho; + up->vel_map = vel_map_ho; return up; } diff --git a/gyrokinetic/zero/gk_dg_geom.c b/gyrokinetic/zero/gk_dg_geom.c index 43edc7fd6a..7eaf93ffb7 100644 --- a/gyrokinetic/zero/gk_dg_geom.c +++ b/gyrokinetic/zero/gk_dg_geom.c @@ -11,31 +11,29 @@ #include #include -static bool -gk_dg_geom_is_cu_dev(const struct gkyl_gk_dg_geom* dgg) +static bool gk_dg_geom_is_cu_dev(const struct gkyl_gk_dg_geom *dgg) { return GKYL_IS_CU_ALLOC(dgg->flags); } -void -gk_dg_geom_free(const struct gkyl_ref_count *ref) +void gk_dg_geom_free(const struct gkyl_ref_count *ref) { struct gkyl_gk_dg_geom *dgg = container_of(ref, struct gkyl_gk_dg_geom, ref_count); - for (int d=0; drange.ndim; ++d) + for (int d = 0; d < dgg->range.ndim; ++d) { gkyl_array_release(dgg->surf_geom[d]); + } gkyl_array_release(dgg->vol_geom); - if (gk_dg_geom_is_cu_dev(dgg)) - gkyl_cu_free(dgg->on_dev); + if (gk_dg_geom_is_cu_dev(dgg)) { + gkyl_cu_free(dgg->on_dev); + } gkyl_free(dgg); } - -struct gkyl_gk_dg_geom * -gkyl_gk_dg_geom_new(const struct gkyl_gk_dg_geom_inp *inp) +struct gkyl_gk_dg_geom *gkyl_gk_dg_geom_new(const struct gkyl_gk_dg_geom_inp *inp) { struct gkyl_gk_dg_geom *dgg = gkyl_malloc(sizeof *dgg); @@ -43,69 +41,68 @@ gkyl_gk_dg_geom_new(const struct gkyl_gk_dg_geom_inp *inp) int ndim = dgg->range.ndim; int shape[GKYL_MAX_CDIM]; - for (int d=0; dnquad; + for (int d = 0; d < ndim; ++d) { + shape[d] = inp->nquad; + } // NOTE: surfaces are ndim-1 objects - gkyl_range_init_from_shape(&dgg->surf_quad_range, ndim-1, shape); + gkyl_range_init_from_shape(&dgg->surf_quad_range, ndim - 1, shape); gkyl_range_init_from_shape(&dgg->vol_quad_range, ndim, shape); - for (int d=0; dsurf_geom[d] = gkyl_array_new(GKYL_USER, - sizeof(struct gkyl_gk_dg_surf_geom[dgg->surf_quad_range.volume]), dgg->range.volume); + for (int d = 0; d < ndim; ++d) { + dgg->surf_geom[d] = gkyl_array_new( + GKYL_USER, sizeof(struct gkyl_gk_dg_surf_geom[dgg->surf_quad_range.volume]), dgg->range.volume + ); + } - dgg->vol_geom = gkyl_array_new(GKYL_USER, - sizeof(struct gkyl_gk_dg_vol_geom[dgg->vol_quad_range.volume]), dgg->range.volume); + dgg->vol_geom = gkyl_array_new( + GKYL_USER, sizeof(struct gkyl_gk_dg_vol_geom[dgg->vol_quad_range.volume]), dgg->range.volume + ); - dgg->flags = 0; GKYL_CLEAR_CU_ALLOC(dgg->flags); dgg->ref_count = gkyl_ref_count_init(gk_dg_geom_free); dgg->on_dev = dgg; // CPU eqn obj points to itself - + return dgg; } -struct gkyl_gk_dg_geom * -gkyl_gk_dg_geom_new_from_host(const struct gkyl_gk_dg_geom_inp *inp, struct gkyl_gk_dg_geom *up_host, bool use_gpu) +struct gkyl_gk_dg_geom *gkyl_gk_dg_geom_new_from_host( + const struct gkyl_gk_dg_geom_inp *inp, struct gkyl_gk_dg_geom *up_host, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_gk_dg_geom_cu_dev_new_from_host(inp, up_host); - } -#endif + } +#endif return up_host; } - -struct gkyl_gk_dg_geom* -gkyl_gk_dg_geom_acquire(const struct gkyl_gk_dg_geom* dgg) +struct gkyl_gk_dg_geom *gkyl_gk_dg_geom_acquire(const struct gkyl_gk_dg_geom *dgg) { gkyl_ref_count_inc(&dgg->ref_count); - return (struct gkyl_gk_dg_geom*) dgg; + return (struct gkyl_gk_dg_geom *)dgg; } -void -gkyl_gk_dg_geom_write(const struct gkyl_gk_dg_geom* dgg, const char *fname) +void gkyl_gk_dg_geom_write(const struct gkyl_gk_dg_geom *dgg, const char *fname) { - } -void -gkyl_gk_dg_geom_release(const struct gkyl_gk_dg_geom *dgg) +void gkyl_gk_dg_geom_release(const struct gkyl_gk_dg_geom *dgg) { gkyl_ref_count_dec(&dgg->ref_count); } - -void -gkyl_gk_dg_geom_populate_vol(struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_geom *gk_dg_geom, struct gk_geometry* gk_geom) +void gkyl_gk_dg_geom_populate_vol( + struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_geom *gk_dg_geom, struct gk_geometry *gk_geom +) { int ndim = gk_geom->grid.ndim; // Populate volume nodes struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &gk_geom->local); - while(gkyl_range_iter_next(&iter)){ - + while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&gk_geom->local, iter.idx); struct gkyl_dg_vol_geom *dgv = gkyl_array_fetch(dg_geom->vol_geom, loc); struct gkyl_gk_dg_vol_geom *gkdgv = gkyl_array_fetch(gk_dg_geom->vol_geom, loc); @@ -113,9 +110,10 @@ gkyl_gk_dg_geom_populate_vol(struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_geo struct gkyl_range_iter qviter; gkyl_range_iter_init(&qviter, &dg_geom->vol_quad_range); int global_nodal_idx[ndim]; - while(gkyl_range_iter_next(&qviter)){ - for (int d=0; dlocal.lower[d])*2 + qviter.idx[d]; + while (gkyl_range_iter_next(&qviter)) { + for (int d = 0; d < ndim; ++d) { + global_nodal_idx[d] = (iter.idx[d] - gk_geom->local.lower[d]) * 2 + qviter.idx[d]; + } long qvloc = gkyl_range_idx(&dg_geom->vol_quad_range, qviter.idx); long global_loc = gkyl_range_idx(&gk_geom->nrange_int, global_nodal_idx); @@ -153,7 +151,7 @@ gkyl_gk_dg_geom_populate_vol(struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_geo // set B3 = e^3 \dot B global_val = gkyl_array_cfetch(gk_geom->geo_int.B3_nodal, global_loc); - gkdgv[qvloc].B3= global_val[0]; + gkdgv[qvloc].B3 = global_val[0]; // set e^i \dot curl(bhat) global_val = gkyl_array_cfetch(gk_geom->geo_int.dualcurlbhat_nodal, global_loc); @@ -164,36 +162,38 @@ gkyl_gk_dg_geom_populate_vol(struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_geo } } -void -gkyl_gk_dg_geom_populate_surf(struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_geom *gk_dg_geom, struct gk_geometry* gk_geom) +void gkyl_gk_dg_geom_populate_surf( + struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_geom *gk_dg_geom, struct gk_geometry *gk_geom +) { int ndim = gk_geom->grid.ndim; // Populate surface nodes - for (int dir=0; dirlocal.lower[0], gk_geom->local.lower[1], gk_geom->local.lower[2]}; int upper[3] = {gk_geom->local.upper[0], gk_geom->local.upper[1], gk_geom->local.upper[2]}; - upper[dir]+=1; + upper[dir] += 1; gkyl_sub_range_init(&local_ext_in_dir, &gk_geom->local_ext, lower, upper); struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local_ext_in_dir); - while(gkyl_range_iter_next(&iter)){ - + while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&local_ext_in_dir, iter.idx); struct gkyl_dg_surf_geom *dgs = gkyl_array_fetch(dg_geom->surf_geom[dir], loc); struct gkyl_gk_dg_surf_geom *gkdgs = gkyl_array_fetch(gk_dg_geom->surf_geom[dir], loc); - struct gkyl_range_iter qsiter; gkyl_range_iter_init(&qsiter, &dg_geom->surf_quad_range); int global_nodal_idx[ndim]; - while(gkyl_range_iter_next(&qsiter)){ + while (gkyl_range_iter_next(&qsiter)) { int count = 0; - for (int d=0; dlocal.lower[d] : (iter.idx[d]-gk_geom->local.lower[d])*2 + qsiter.idx[count]; - if (d != dir) count+=1; + for (int d = 0; d < ndim; ++d) { + global_nodal_idx[d] = d == dir ? + iter.idx[d] - gk_geom->local.lower[d] : + (iter.idx[d] - gk_geom->local.lower[d]) * 2 + qsiter.idx[count]; + if (d != dir) { + count += 1; + } } long qsloc = gkyl_range_idx(&dg_geom->surf_quad_range, qsiter.idx); long global_loc = gkyl_range_idx(&gk_geom->nrange_surf[dir], global_nodal_idx); @@ -204,20 +204,20 @@ gkyl_gk_dg_geom_populate_surf(struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_ge // set normals global_val = gkyl_array_cfetch(gk_geom->geo_surf[dir].normals_nodal, global_loc); - dgs[qsloc].norm.x[0] = global_val[dir*3+0]; - dgs[qsloc].norm.x[1] = global_val[dir*3+1]; - dgs[qsloc].norm.x[2] = global_val[dir*3+2]; - + dgs[qsloc].norm.x[0] = global_val[dir * 3 + 0]; + dgs[qsloc].norm.x[1] = global_val[dir * 3 + 1]; + dgs[qsloc].norm.x[2] = global_val[dir * 3 + 2]; + // set e3hat \dot B = B^3/sqrt(g_33} global_val = gkyl_array_cfetch(gk_geom->geo_surf[dir].B3_nodal, global_loc); - gkdgs[qsloc].B3 = global_val[0]; + gkdgs[qsloc].B3 = global_val[0]; // set n \dot curl(bhat) global_val = gkyl_array_cfetch(gk_geom->geo_surf[dir].normcurlbhat_nodal, global_loc); - gkdgs[qsloc].normcurlbhat = global_val[0]; + gkdgs[qsloc].normcurlbhat = global_val[0]; // set |B| global_val = gkyl_array_cfetch(gk_geom->geo_surf[dir].bmag_nodal, global_loc); - gkdgs[qsloc].bmag = global_val[0]; + gkdgs[qsloc].bmag = global_val[0]; // set Jacobgeo global_val = gkyl_array_cfetch(gk_geom->geo_surf[dir].jacobgeo_nodal, global_loc); @@ -225,12 +225,10 @@ gkyl_gk_dg_geom_populate_surf(struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_ge // set bhat global_val = gkyl_array_cfetch(gk_geom->geo_surf[dir].b_i_nodal, global_loc); - gkdgs[qsloc].bhat.x[0] = global_val[0]; - gkdgs[qsloc].bhat.x[1] = global_val[1]; - gkdgs[qsloc].bhat.x[2] = global_val[2]; - + gkdgs[qsloc].bhat.x[0] = global_val[0]; + gkdgs[qsloc].bhat.x[1] = global_val[1]; + gkdgs[qsloc].bhat.x[2] = global_val[2]; } } } } - diff --git a/gyrokinetic/zero/gk_dg_geom_cu.cu b/gyrokinetic/zero/gk_dg_geom_cu.cu index 8417ee81d1..c983311422 100644 --- a/gyrokinetic/zero/gk_dg_geom_cu.cu +++ b/gyrokinetic/zero/gk_dg_geom_cu.cu @@ -13,56 +13,64 @@ extern "C" { #include } -struct gkyl_gk_dg_geom * -gkyl_gk_dg_geom_cu_dev_new_from_host(const struct gkyl_gk_dg_geom_inp *inp, struct gkyl_gk_dg_geom *up_host) +struct gkyl_gk_dg_geom *gkyl_gk_dg_geom_cu_dev_new_from_host( + const struct gkyl_gk_dg_geom_inp *inp, struct gkyl_gk_dg_geom *up_host +) { - struct gkyl_gk_dg_geom *dgg = (struct gkyl_gk_dg_geom *) gkyl_malloc(sizeof *dgg); + struct gkyl_gk_dg_geom *dgg = (struct gkyl_gk_dg_geom *)gkyl_malloc(sizeof *dgg); dgg->range = *inp->range; int ndim = dgg->range.ndim; int shape[GKYL_MAX_CDIM]; - for (int d=0; dnquad; + for (int d = 0; d < ndim; ++d) { + shape[d] = inp->nquad; + } // NOTE: surfaces are ndim-1 objects - gkyl_range_init_from_shape(&dgg->surf_quad_range, ndim-1, shape); + gkyl_range_init_from_shape(&dgg->surf_quad_range, ndim - 1, shape); gkyl_range_init_from_shape(&dgg->vol_quad_range, ndim, shape); // Copy the host-side initialized geometry object to the device - struct gkyl_array *vol_geom_dev = gkyl_array_cu_dev_new(GKYL_USER, - sizeof(struct gkyl_gk_dg_vol_geom[dgg->vol_quad_range.volume]), dgg->range.volume); + struct gkyl_array *vol_geom_dev = gkyl_array_cu_dev_new( + GKYL_USER, sizeof(struct gkyl_gk_dg_vol_geom[dgg->vol_quad_range.volume]), dgg->range.volume + ); struct gkyl_array *surf_geom_dev[ndim]; - for (int dir=0; dirsurf_quad_range.volume]), dgg->range.volume); + for (int dir = 0; dir < ndim; ++dir) { + surf_geom_dev[dir] = gkyl_array_cu_dev_new( + GKYL_USER, sizeof(struct gkyl_gk_dg_surf_geom[dgg->surf_quad_range.volume]), dgg->range.volume + ); } gkyl_array_copy(vol_geom_dev, up_host->vol_geom); - for (int dir=0; dirsurf_geom[dir]); + } // this is for the memcpy below dgg->vol_geom = vol_geom_dev->on_dev; - for (int dir=0; dirsurf_geom[dir] = surf_geom_dev[dir]->on_dev; + for (int dir = 0; dir < ndim; ++dir) { + dgg->surf_geom[dir] = surf_geom_dev[dir]->on_dev; + } dgg->flags = 0; GKYL_SET_CU_ALLOC(dgg->flags); dgg->ref_count = gkyl_ref_count_init(gk_dg_geom_free); // Initialize the device geometry object - struct gkyl_gk_dg_geom *dgg_cu = (struct gkyl_gk_dg_geom*) gkyl_cu_malloc(sizeof(struct gkyl_gk_dg_geom)); + struct gkyl_gk_dg_geom *dgg_cu = + (struct gkyl_gk_dg_geom *)gkyl_cu_malloc(sizeof(struct gkyl_gk_dg_geom)); gkyl_cu_memcpy(dgg_cu, dgg, sizeof(struct gkyl_gk_dg_geom), GKYL_CU_MEMCPY_H2D); dgg->on_dev = dgg_cu; // geometry object should store host pointer dgg->vol_geom = vol_geom_dev; - for (int dir=0; dirsurf_geom[dir] = surf_geom_dev[dir]; + } - return dgg; } diff --git a/gyrokinetic/zero/gk_geometry.c b/gyrokinetic/zero/gk_geometry.c index a85d251843..6229950e3d 100644 --- a/gyrokinetic/zero/gk_geometry.c +++ b/gyrokinetic/zero/gk_geometry.c @@ -15,16 +15,15 @@ #include #include - -struct gk_geometry* -gkyl_gk_geometry_new(struct gk_geometry* geo_host, struct gkyl_gk_geometry_inp *geometry_inp, bool use_gpu) +struct gk_geometry *gkyl_gk_geometry_new( + struct gk_geometry *geo_host, struct gkyl_gk_geometry_inp *geometry_inp, bool use_gpu +) { - #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_gk_geometry_cu_dev_new(geo_host, geometry_inp); - } -#endif + } +#endif struct gk_geometry *up = gkyl_malloc(sizeof(struct gk_geometry)); up->geometry_id = geometry_inp->geometry_id; @@ -34,7 +33,7 @@ gkyl_gk_geometry_new(struct gk_geometry* geo_host, struct gkyl_gk_geometry_inp * up->global = geometry_inp->global; up->global_ext = geometry_inp->global_ext; up->grid = geometry_inp->grid; - gk_geometry_set_nodal_ranges(up) ; + gk_geometry_set_nodal_ranges(up); up->has_LCFS = geometry_inp->has_LCFS; if (up->has_LCFS) { @@ -42,16 +41,14 @@ gkyl_gk_geometry_new(struct gk_geometry* geo_host, struct gkyl_gk_geometry_inp * // Check that the split happens within the domain. assert((up->grid.lower[0] <= up->x_LCFS) && (up->x_LCFS <= up->grid.upper[0])); // Check that the split happens at a cell boundary; - double needint = (up->x_LCFS - up->grid.lower[0])/up->grid.dx[0]; - double rem_floor = fabs(needint-floor(needint)); - double rem_ceil = fabs(needint-ceil(needint)); + double needint = (up->x_LCFS - up->grid.lower[0]) / up->grid.dx[0]; + double rem_floor = fabs(needint - floor(needint)); + double rem_ceil = fabs(needint - ceil(needint)); if (rem_floor < 1.0e-12) { - up->idx_LCFS_lo = (int) floor(needint); - } - else if (rem_ceil < 1.0e-12) { - up->idx_LCFS_lo = (int) ceil(needint); - } - else { + up->idx_LCFS_lo = (int)floor(needint); + } else if (rem_ceil < 1.0e-12) { + up->idx_LCFS_lo = (int)ceil(needint); + } else { fprintf(stderr, "x_LCFS = %.9e must be at a cell boundary.\n", up->x_LCFS); assert(false); } @@ -60,14 +57,13 @@ gkyl_gk_geometry_new(struct gk_geometry* geo_host, struct gkyl_gk_geometry_inp * // Function pointers to twistshift function. up->parallel_lower_bc_shift_func = geometry_inp->parallel_lower_bc_shift_func; up->parallel_upper_bc_shift_func = geometry_inp->parallel_upper_bc_shift_func; - up->parallel_lower_bc_shift_ctx = geometry_inp->parallel_lower_bc_shift_ctx; - up->parallel_upper_bc_shift_ctx = geometry_inp->parallel_upper_bc_shift_ctx; + up->parallel_lower_bc_shift_ctx = geometry_inp->parallel_lower_bc_shift_ctx; + up->parallel_upper_bc_shift_ctx = geometry_inp->parallel_upper_bc_shift_ctx; if (up->grid.ndim > 1) { - gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim-1, up->basis.poly_order); + gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim - 1, up->basis.poly_order); up->num_surf_basis = up->surf_basis.num_basis; - } - else { + } else { up->num_surf_basis = 1; } @@ -75,7 +71,7 @@ gkyl_gk_geometry_new(struct gk_geometry* geo_host, struct gkyl_gk_geometry_inp * gk_geometry_corn_alloc_nodal(up); gk_geometry_int_alloc_expansions(up); gk_geometry_int_alloc_nodal(up); - for (int dir=0; dirgrid.ndim; ++dir) { + for (int dir = 0; dir < up->grid.ndim; ++dir) { gk_geometry_surf_alloc_expansions(up, dir); gk_geometry_surf_alloc_nodal(up, dir); } @@ -83,26 +79,28 @@ gkyl_gk_geometry_new(struct gk_geometry* geo_host, struct gkyl_gk_geometry_inp * // Store metadata for I/O. if (up->geometry_id == GKYL_GEOMETRY_TOKAMAK) { struct gkyl_msgpack_map_elem io_meta_basic[] = { - { .key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id }, - { .key = "geqdsk_sign_convention", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geqdsk_sign_convention }, - { .key = "half_domain", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->half_domain }, + {.key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id}, + {.key = "geqdsk_sign_convention", + .elem_type = GKYL_MP_UNSIGNED_INT, + .uval = up->geqdsk_sign_convention}, + {.key = "half_domain", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->half_domain} }; - up->io_meta_basic_len = sizeof(io_meta_basic)/sizeof(io_meta_basic[0]); + up->io_meta_basic_len = sizeof(io_meta_basic) / sizeof(io_meta_basic[0]); up->io_meta_basic = gkyl_msgpack_map_elem_clone(up->io_meta_basic_len, io_meta_basic); - } - else if (up->geometry_id == GKYL_GEOMETRY_MIRROR) { + } else if (up->geometry_id == GKYL_GEOMETRY_MIRROR) { struct gkyl_msgpack_map_elem io_meta_basic[] = { - { .key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id }, - { .key = "geqdsk_sign_convention", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geqdsk_sign_convention }, + {.key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id}, + {.key = "geqdsk_sign_convention", + .elem_type = GKYL_MP_UNSIGNED_INT, + .uval = up->geqdsk_sign_convention} }; - up->io_meta_basic_len = sizeof(io_meta_basic)/sizeof(io_meta_basic[0]); + up->io_meta_basic_len = sizeof(io_meta_basic) / sizeof(io_meta_basic[0]); up->io_meta_basic = gkyl_msgpack_map_elem_clone(up->io_meta_basic_len, io_meta_basic); - } - else { + } else { struct gkyl_msgpack_map_elem io_meta_basic[] = { - { .key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id }, + {.key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id} }; - up->io_meta_basic_len = sizeof(io_meta_basic)/sizeof(io_meta_basic[0]); + up->io_meta_basic_len = sizeof(io_meta_basic) / sizeof(io_meta_basic[0]); up->io_meta_basic = gkyl_msgpack_map_elem_clone(up->io_meta_basic_len, io_meta_basic); } @@ -110,61 +108,80 @@ gkyl_gk_geometry_new(struct gk_geometry* geo_host, struct gkyl_gk_geometry_inp * GKYL_CLEAR_CU_ALLOC(up->flags); up->ref_count = gkyl_ref_count_init(gkyl_gk_geometry_free); up->on_dev = up; // CPU eqn obj points to itself - + return up; } void gkyl_gk_geometry_reset_io_meta(struct gk_geometry *up) { - gkyl_msgpack_map_elem_set_uint(up->io_meta_basic_len, up->io_meta_basic, "geometry_type", up->geometry_id); + gkyl_msgpack_map_elem_set_uint( + up->io_meta_basic_len, up->io_meta_basic, "geometry_type", up->geometry_id + ); if (up->geometry_id == GKYL_GEOMETRY_TOKAMAK || up->geometry_id == GKYL_GEOMETRY_MIRROR) { - if (gkyl_msgpack_map_elem_has_key(up->io_meta_basic_len, up->io_meta_basic, "geqdsk_sign_convention")) { + if (gkyl_msgpack_map_elem_has_key( + up->io_meta_basic_len, up->io_meta_basic, "geqdsk_sign_convention" + )) { // Element list has this key. Update its value. - gkyl_msgpack_map_elem_set_uint(up->io_meta_basic_len, up->io_meta_basic, "geqdsk_sign_convention", up->geqdsk_sign_convention); - } - else { + gkyl_msgpack_map_elem_set_uint( + up->io_meta_basic_len, up->io_meta_basic, "geqdsk_sign_convention", + up->geqdsk_sign_convention + ); + } else { // Element list doesn't have this key. Create a new list with it. struct gkyl_msgpack_map_elem io_meta_basic_new[] = { - { .key = "geqdsk_sign_convention", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geqdsk_sign_convention }, + {.key = "geqdsk_sign_convention", + .elem_type = GKYL_MP_UNSIGNED_INT, + .uval = up->geqdsk_sign_convention} }; - int io_meta_basic_new_len = sizeof(io_meta_basic_new)/sizeof(io_meta_basic_new[0]); + int io_meta_basic_new_len = sizeof(io_meta_basic_new) / sizeof(io_meta_basic_new[0]); - struct gkyl_msgpack_map_elem *io_meta_basic_buffer = gkyl_msgpack_map_elem_clone(up->io_meta_basic_len, up->io_meta_basic); + struct gkyl_msgpack_map_elem *io_meta_basic_buffer = + gkyl_msgpack_map_elem_clone(up->io_meta_basic_len, up->io_meta_basic); int io_meta_basic_buffer_len = up->io_meta_basic_len; - gkyl_msgpack_map_elem_release(io_meta_basic_buffer_len, up->io_meta_basic); + gkyl_msgpack_map_elem_release(io_meta_basic_buffer_len, up->io_meta_basic); int io_meta_basic_list_len[] = {io_meta_basic_new_len, io_meta_basic_buffer_len}; - const struct gkyl_msgpack_map_elem* io_meta_basic_list[] = {io_meta_basic_new, io_meta_basic_buffer}; - up->io_meta_basic = gkyl_msgpack_map_elem_union(sizeof(io_meta_basic_list_len)/sizeof(int), - io_meta_basic_list_len, io_meta_basic_list, &up->io_meta_basic_len); + const struct gkyl_msgpack_map_elem *io_meta_basic_list[] = { + io_meta_basic_new, io_meta_basic_buffer + }; + up->io_meta_basic = gkyl_msgpack_map_elem_union( + sizeof(io_meta_basic_list_len) / sizeof(int), io_meta_basic_list_len, io_meta_basic_list, + &up->io_meta_basic_len + ); - gkyl_msgpack_map_elem_release(io_meta_basic_buffer_len, io_meta_basic_buffer); + gkyl_msgpack_map_elem_release(io_meta_basic_buffer_len, io_meta_basic_buffer); } } if (up->geometry_id == GKYL_GEOMETRY_TOKAMAK) { if (gkyl_msgpack_map_elem_has_key(up->io_meta_basic_len, up->io_meta_basic, "half_domain")) { // Element list has this key. Update its value. - gkyl_msgpack_map_elem_set_uint(up->io_meta_basic_len, up->io_meta_basic, "half_domain", up->half_domain); - } - else { + gkyl_msgpack_map_elem_set_uint( + up->io_meta_basic_len, up->io_meta_basic, "half_domain", up->half_domain + ); + } else { // Element list doesn't have this key. Create a new list with it. struct gkyl_msgpack_map_elem io_meta_basic_new[] = { - { .key = "half_domain", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->half_domain }, + {.key = "half_domain", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->half_domain} }; - int io_meta_basic_new_len = sizeof(io_meta_basic_new)/sizeof(io_meta_basic_new[0]); + int io_meta_basic_new_len = sizeof(io_meta_basic_new) / sizeof(io_meta_basic_new[0]); - struct gkyl_msgpack_map_elem *io_meta_basic_buffer = gkyl_msgpack_map_elem_clone(up->io_meta_basic_len, up->io_meta_basic); + struct gkyl_msgpack_map_elem *io_meta_basic_buffer = + gkyl_msgpack_map_elem_clone(up->io_meta_basic_len, up->io_meta_basic); int io_meta_basic_buffer_len = up->io_meta_basic_len; - gkyl_msgpack_map_elem_release(io_meta_basic_buffer_len, up->io_meta_basic); + gkyl_msgpack_map_elem_release(io_meta_basic_buffer_len, up->io_meta_basic); int io_meta_basic_list_len[] = {io_meta_basic_new_len, io_meta_basic_buffer_len}; - const struct gkyl_msgpack_map_elem* io_meta_basic_list[] = {io_meta_basic_new, io_meta_basic_buffer}; - up->io_meta_basic = gkyl_msgpack_map_elem_union(sizeof(io_meta_basic_list_len)/sizeof(int), - io_meta_basic_list_len, io_meta_basic_list, &up->io_meta_basic_len); + const struct gkyl_msgpack_map_elem *io_meta_basic_list[] = { + io_meta_basic_new, io_meta_basic_buffer + }; + up->io_meta_basic = gkyl_msgpack_map_elem_union( + sizeof(io_meta_basic_list_len) / sizeof(int), io_meta_basic_list_len, io_meta_basic_list, + &up->io_meta_basic_len + ); - gkyl_msgpack_map_elem_release(io_meta_basic_buffer_len, io_meta_basic_buffer); + gkyl_msgpack_map_elem_release(io_meta_basic_buffer_len, io_meta_basic_buffer); } } } @@ -173,70 +190,121 @@ void gkyl_gk_geometry_populate_nodal(struct gk_geometry *gk_geom) { // Populate nodal arrays for vpar surface terms struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&gk_geom->basis, &gk_geom->grid, false); - gkyl_nodal_ops_m2n(n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.jacobgeo_nodal, gk_geom->geo_int.jacobgeo, true); - gkyl_nodal_ops_m2n(n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 9, gk_geom->geo_int.dxdz_nodal, gk_geom->geo_int.dxdz, true); - gkyl_nodal_ops_m2n(n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 9, gk_geom->geo_int.dzdx_nodal, gk_geom->geo_int.dzdx, true); - gkyl_nodal_ops_m2n(n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.bmag_nodal, gk_geom->geo_int.bmag, true); - gkyl_nodal_ops_m2n(n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 1, gk_geom->geo_int.B3_nodal, gk_geom->geo_int.B3, true); - gkyl_nodal_ops_m2n(n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 3, gk_geom->geo_int.dualcurlbhat_nodal, gk_geom->geo_int.dualcurlbhat, true); + gkyl_nodal_ops_m2n( + n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.jacobgeo_nodal, gk_geom->geo_int.jacobgeo, true + ); + gkyl_nodal_ops_m2n( + n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 9, + gk_geom->geo_int.dxdz_nodal, gk_geom->geo_int.dxdz, true + ); + gkyl_nodal_ops_m2n( + n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 9, + gk_geom->geo_int.dzdx_nodal, gk_geom->geo_int.dzdx, true + ); + gkyl_nodal_ops_m2n( + n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.bmag_nodal, gk_geom->geo_int.bmag, true + ); + gkyl_nodal_ops_m2n( + n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 1, + gk_geom->geo_int.B3_nodal, gk_geom->geo_int.B3, true + ); + gkyl_nodal_ops_m2n( + n2m, &gk_geom->basis, &gk_geom->grid, &gk_geom->nrange_int, &gk_geom->local, 3, + gk_geom->geo_int.dualcurlbhat_nodal, gk_geom->geo_int.dualcurlbhat, true + ); // Populate nodal arrays for config space surface terms int lower[gk_geom->grid.ndim]; int upper[gk_geom->grid.ndim]; - for (int dir =0; dir < gk_geom->grid.ndim; dir++) { + for (int dir = 0; dir < gk_geom->grid.ndim; dir++) { struct gk_geom_surf up_surf = gk_geom->geo_surf[dir]; struct gkyl_range local_ext_in_dir; - for (int i = 0; i grid.ndim; i++) { + for (int i = 0; i < gk_geom->grid.ndim; i++) { lower[i] = gk_geom->local.lower[i]; upper[i] = gk_geom->local.upper[i]; } - upper[dir]+=1; + upper[dir] += 1; gkyl_sub_range_init(&local_ext_in_dir, &gk_geom->local_ext, lower, upper); - gkyl_nodal_ops_m2n_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, up_surf.bmag_nodal, up_surf.bmag, dir); - gkyl_nodal_ops_m2n_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, up_surf.jacobgeo_nodal, up_surf.jacobgeo, dir); - gkyl_nodal_ops_m2n_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 3, up_surf.b_i_nodal, up_surf.b_i, dir); - gkyl_nodal_ops_m2n_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, up_surf.cmag_nodal, up_surf.cmag, dir); - gkyl_nodal_ops_m2n_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, up_surf.jacobtot_inv_nodal, up_surf.jacobtot_inv, dir); - gkyl_nodal_ops_m2n_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, up_surf.B3_nodal, up_surf.B3, dir); - gkyl_nodal_ops_m2n_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, up_surf.normcurlbhat_nodal, up_surf.normcurlbhat, dir); - gkyl_nodal_ops_m2n_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 9, up_surf.normals_nodal, up_surf.normals, dir); - gkyl_nodal_ops_m2n_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, up_surf.lenr_nodal, up_surf.lenr, dir); - gkyl_nodal_ops_m2n_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, up_surf.deltats_nodal, up_surf.deltats, dir); - gkyl_nodal_ops_m2n_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, up_surf.bimpactangle_nodal, up_surf.bimpactangle, dir); + gkyl_nodal_ops_m2n_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, + up_surf.bmag_nodal, up_surf.bmag, dir + ); + gkyl_nodal_ops_m2n_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, + up_surf.jacobgeo_nodal, up_surf.jacobgeo, dir + ); + gkyl_nodal_ops_m2n_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 3, + up_surf.b_i_nodal, up_surf.b_i, dir + ); + gkyl_nodal_ops_m2n_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, + up_surf.cmag_nodal, up_surf.cmag, dir + ); + gkyl_nodal_ops_m2n_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, + up_surf.jacobtot_inv_nodal, up_surf.jacobtot_inv, dir + ); + gkyl_nodal_ops_m2n_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, + up_surf.B3_nodal, up_surf.B3, dir + ); + gkyl_nodal_ops_m2n_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, + up_surf.normcurlbhat_nodal, up_surf.normcurlbhat, dir + ); + gkyl_nodal_ops_m2n_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 9, + up_surf.normals_nodal, up_surf.normals, dir + ); + gkyl_nodal_ops_m2n_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, + up_surf.lenr_nodal, up_surf.lenr, dir + ); + gkyl_nodal_ops_m2n_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, + up_surf.deltats_nodal, up_surf.deltats, dir + ); + gkyl_nodal_ops_m2n_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &gk_geom->nrange_surf[dir], &local_ext_in_dir, 1, + up_surf.bimpactangle_nodal, up_surf.bimpactangle, dir + ); } gkyl_nodal_ops_release(n2m); - } -bool -gkyl_gk_geometry_is_cu_dev(const struct gk_geometry* up) +bool gkyl_gk_geometry_is_cu_dev(const struct gk_geometry *up) { return GKYL_IS_CU_ALLOC(up->flags); } -struct gkyl_rect_grid gkyl_gk_geometry_augment_grid(struct gkyl_rect_grid grid, struct gkyl_gk_geometry_inp geometry) +struct gkyl_rect_grid +gkyl_gk_geometry_augment_grid(struct gkyl_rect_grid grid, struct gkyl_gk_geometry_inp geometry) { struct gkyl_rect_grid augmented_grid; int cells[3]; double lower[3]; double upper[3]; - if (grid.ndim==1) { + if (grid.ndim == 1) { cells[0] = 1; cells[1] = 1; cells[2] = grid.cells[0]; - lower[0] = geometry.world[0] - (geometry.world[0]>1e-14? fmin(1e-5, geometry.world[0]*0.1) : 1e-5); + lower[0] = + geometry.world[0] - (geometry.world[0] > 1e-14 ? fmin(1e-5, geometry.world[0] * 0.1) : 1e-5); lower[1] = geometry.world[1] - 1e-1; lower[2] = grid.lower[0]; - upper[0] = geometry.world[0] + (geometry.world[0]>1e-14? fmin(1e-5, geometry.world[0]*0.1) : 1e-5); + upper[0] = + geometry.world[0] + (geometry.world[0] > 1e-14 ? fmin(1e-5, geometry.world[0] * 0.1) : 1e-5); upper[1] = geometry.world[1] + 1e-1; upper[2] = grid.upper[0]; - } - else if (grid.ndim==2) { + } else if (grid.ndim == 2) { cells[0] = grid.cells[0]; cells[1] = 1; cells[2] = grid.cells[1]; @@ -254,16 +322,17 @@ struct gkyl_rect_grid gkyl_gk_geometry_augment_grid(struct gkyl_rect_grid grid, return augmented_grid; } - -void gkyl_gk_geometry_augment_local(const struct gkyl_range *inrange, - const int *nghost, struct gkyl_range *ext_range, struct gkyl_range *range) +void gkyl_gk_geometry_augment_local( + const struct gkyl_range *inrange, const int *nghost, struct gkyl_range *ext_range, + struct gkyl_range *range +) { if (inrange->ndim == 2) { int lower_ext[GKYL_MAX_DIM], upper_ext[GKYL_MAX_DIM]; int lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - - lower_ext[0] = inrange->lower[0]-nghost[0]; - upper_ext[0] = inrange->upper[0]+nghost[0]; + + lower_ext[0] = inrange->lower[0] - nghost[0]; + upper_ext[0] = inrange->upper[0] + nghost[0]; lower[0] = inrange->lower[0]; upper[0] = inrange->upper[0]; @@ -272,19 +341,17 @@ void gkyl_gk_geometry_augment_local(const struct gkyl_range *inrange, lower[1] = 1; upper[1] = 1; - lower_ext[2] = inrange->lower[1]-nghost[1]; - upper_ext[2] = inrange->upper[1]+nghost[1]; + lower_ext[2] = inrange->lower[1] - nghost[1]; + upper_ext[2] = inrange->upper[1] + nghost[1]; lower[2] = inrange->lower[1]; upper[2] = inrange->upper[1]; - - gkyl_range_init(ext_range, inrange->ndim+1, lower_ext, upper_ext); - gkyl_sub_range_init(range, ext_range, lower, upper); - } - else if (inrange->ndim == 1) { + gkyl_range_init(ext_range, inrange->ndim + 1, lower_ext, upper_ext); + gkyl_sub_range_init(range, ext_range, lower, upper); + } else if (inrange->ndim == 1) { int lower_ext[GKYL_MAX_DIM], upper_ext[GKYL_MAX_DIM]; int lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - + lower_ext[0] = 1 - 1; upper_ext[0] = 1 + 1; lower[0] = 1; @@ -295,34 +362,33 @@ void gkyl_gk_geometry_augment_local(const struct gkyl_range *inrange, lower[1] = 1; upper[1] = 1; - lower_ext[2] = inrange->lower[0]-nghost[0]; - upper_ext[2] = inrange->upper[0]+nghost[0]; + lower_ext[2] = inrange->lower[0] - nghost[0]; + upper_ext[2] = inrange->upper[0] + nghost[0]; lower[2] = inrange->lower[0]; upper[2] = inrange->upper[0]; - - - gkyl_range_init(ext_range, inrange->ndim+2, lower_ext, upper_ext); - gkyl_sub_range_init(range, ext_range, lower, upper); + gkyl_range_init(ext_range, inrange->ndim + 2, lower_ext, upper_ext); + gkyl_sub_range_init(range, ext_range, lower, upper); } } -double -gkyl_gk_geometry_reduce_bmag(struct gk_geometry* up, enum gkyl_array_op op) +double gkyl_gk_geometry_reduce_bmag(struct gk_geometry *up, enum gkyl_array_op op) { int cdim = up->grid.ndim; double b_m; - if (op == GKYL_MIN) + if (op == GKYL_MIN) { b_m = DBL_MAX; - else if (op == GKYL_MAX) + } else if (op == GKYL_MAX) { b_m = -DBL_MAX; - else + } else { assert(false); + } struct gkyl_array *nodes = gkyl_array_new(GKYL_DOUBLE, cdim, up->basis.num_basis); up->basis.node_list(gkyl_array_fetch(nodes, 0)); - struct gkyl_array *bmag_ho = gkyl_array_new(GKYL_DOUBLE, up->geo_int.bmag->ncomp, up->geo_int.bmag->size); + struct gkyl_array *bmag_ho = + gkyl_array_new(GKYL_DOUBLE, up->geo_int.bmag->ncomp, up->geo_int.bmag->size); gkyl_array_copy(bmag_ho, up->geo_int.bmag); struct gkyl_range_iter iter; @@ -332,12 +398,13 @@ gkyl_gk_geometry_reduce_bmag(struct gk_geometry* up, enum gkyl_array_op op) double *b_d = gkyl_array_fetch(bmag_ho, linidx); double nod_log[cdim]; for (int n = 0; n < up->basis.num_basis; n++) { - const double *nod_log = gkyl_array_cfetch(nodes,n); + const double *nod_log = gkyl_array_cfetch(nodes, n); double b = up->basis.eval_expand(nod_log, b_d); - if (op == GKYL_MIN) + if (op == GKYL_MIN) { b_m = GKYL_MIN2(b_m, b); - else if (op == GKYL_MAX) + } else if (op == GKYL_MAX) { b_m = GKYL_MAX2(b_m, b); + } } } @@ -347,34 +414,39 @@ gkyl_gk_geometry_reduce_bmag(struct gk_geometry* up, enum gkyl_array_op op) return b_m; } -static inline void -log_to_comp(int ndim, const double *eta, - const double * GKYL_RESTRICT dx, const double * GKYL_RESTRICT xc, - double* GKYL_RESTRICT xout) +static inline void log_to_comp( + int ndim, const double *eta, const double *GKYL_RESTRICT dx, const double *GKYL_RESTRICT xc, + double *GKYL_RESTRICT xout +) { // Convert logical to computational coordinates. - for (int d=0; dgrid.ndim; - for (int d=0; dbasis.num_basis); up->basis.node_list(gkyl_array_fetch(nodes, 0)); - struct gkyl_array *bmag_ho = gkyl_array_new(GKYL_DOUBLE, up->geo_int.bmag->ncomp, up->geo_int.bmag->size); + struct gkyl_array *bmag_ho = + gkyl_array_new(GKYL_DOUBLE, up->geo_int.bmag->ncomp, up->geo_int.bmag->size); gkyl_array_copy(bmag_ho, up->geo_int.bmag); struct gkyl_range_iter iter; @@ -388,7 +460,7 @@ gkyl_gk_geometry_reduce_arg_bmag(struct gk_geometry* up, enum gkyl_array_op op, double nod_log[cdim], nod_phys[cdim]; for (int n = 0; n < up->basis.num_basis; n++) { - const double *nod_log = gkyl_array_cfetch(nodes,n); + const double *nod_log = gkyl_array_cfetch(nodes, n); double b = up->basis.eval_expand(nod_log, b_d); log_to_comp(cdim, nod_log, up->grid.dx, xc, nod_phys); @@ -396,15 +468,16 @@ gkyl_gk_geometry_reduce_arg_bmag(struct gk_geometry* up, enum gkyl_array_op op, if (op == GKYL_MIN) { if (b < b_m) { b_m = b; - for (int d=0; dndim; ++d) - nodes[d] = gkyl_range_shape(range, d) + 1; + int nodes[GKYL_MAX_DIM]; + if (poly_order == 1) { + for (int d = 0; d < range->ndim; ++d) { + nodes[d] = gkyl_range_shape(range, d) + 1; } - if (poly_order == 2) { - for (int d=0; dndim; ++d) - nodes[d] = 2*gkyl_range_shape(range, d) + 1; + } + if (poly_order == 2) { + for (int d = 0; d < range->ndim; ++d) { + nodes[d] = 2 * gkyl_range_shape(range, d) + 1; } - gkyl_range_init_from_shape(nrange, range->ndim, nodes); - + } + gkyl_range_init_from_shape(nrange, range->ndim, nodes); } -void -gkyl_gk_geometry_init_nodal_grid(struct gkyl_rect_grid *ngrid, struct gkyl_rect_grid *grid, struct gkyl_range *nrange) +void gkyl_gk_geometry_init_nodal_grid( + struct gkyl_rect_grid *ngrid, struct gkyl_rect_grid *grid, struct gkyl_range *nrange +) { - double lower[GKYL_MAX_DIM]; - double upper[GKYL_MAX_DIM]; - int cells[GKYL_MAX_DIM]; - for (int i=0; indim; ++i) { - lower[i] = grid->lower[i]; - upper[i] = grid->upper[i]; - cells[i] = gkyl_range_shape(nrange, i); - } - gkyl_rect_grid_init(ngrid, nrange->ndim, lower, upper, cells); + double lower[GKYL_MAX_DIM]; + double upper[GKYL_MAX_DIM]; + int cells[GKYL_MAX_DIM]; + for (int i = 0; i < nrange->ndim; ++i) { + lower[i] = grid->lower[i]; + upper[i] = grid->upper[i]; + cells[i] = gkyl_range_shape(nrange, i); + } + gkyl_rect_grid_init(ngrid, nrange->ndim, lower, upper, cells); } -struct gk_geometry* -gkyl_gk_geometry_deflate(const struct gk_geometry* up_3d, struct gkyl_gk_geometry_inp *geometry_inp) +struct gk_geometry * +gkyl_gk_geometry_deflate(const struct gk_geometry *up_3d, struct gkyl_gk_geometry_inp *geometry_inp) { struct gk_geometry *up = gkyl_malloc(sizeof(struct gk_geometry)); up->geometry_id = geometry_inp->geometry_id; @@ -455,12 +531,11 @@ gkyl_gk_geometry_deflate(const struct gk_geometry* up_3d, struct gkyl_gk_geometr up->local = geometry_inp->local; up->local_ext = geometry_inp->local_ext; up->grid = geometry_inp->grid; - gk_geometry_set_nodal_ranges(up) ; + gk_geometry_set_nodal_ranges(up); if (up->grid.ndim > 1) { - gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim-1, up->basis.poly_order); + gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim - 1, up->basis.poly_order); up->num_surf_basis = up->surf_basis.num_basis; - } - else { + } else { up->num_surf_basis = 1; } up->geqdsk_sign_convention = up_3d->geqdsk_sign_convention; @@ -473,85 +548,177 @@ gkyl_gk_geometry_deflate(const struct gk_geometry* up_3d, struct gkyl_gk_geometr gk_geometry_corn_alloc_nodal(up); gk_geometry_int_alloc_expansions(up); gk_geometry_int_alloc_nodal(up); - for (int dir=0; dirgrid.ndim; ++dir) { + for (int dir = 0; dir < up->grid.ndim; ++dir) { gk_geometry_surf_alloc_expansions(up, dir); gk_geometry_surf_alloc_nodal(up, dir); } // Now fill the arrays by deflation int rem_dirs[3] = {0}; - if (up->grid.ndim==1) { + if (up->grid.ndim == 1) { rem_dirs[0] = 1; rem_dirs[1] = 1; - } - else if (up->grid.ndim==2) { + } else if (up->grid.ndim == 2) { rem_dirs[1] = 1; } - struct gkyl_deflate_geo* deflator = gkyl_deflate_geo_new(&up_3d->basis, &up->basis, &up_3d->grid, &up->grid, rem_dirs, false); - - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_corn.mc2p, up->geo_corn.mc2p, 3); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_corn.mc2nu_pos, up->geo_corn.mc2nu_pos, 3); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_corn.bmag, up->geo_corn.bmag, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_corn.bmag_inv, up->geo_corn.bmag_inv, 1); - - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.mc2p, up->geo_int.mc2p, 3); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.bmag, up->geo_int.bmag, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.g_ij, up->geo_int.g_ij, 6); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.g_ij_neut, up->geo_int.g_ij_neut, 6); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.dxdz, up->geo_int.dxdz, 9); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.dzdx, up->geo_int.dzdx, 9); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.dualmag, up->geo_int.dualmag, 3); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.normals, up->geo_int.normals, 9); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.jacobgeo, up->geo_int.jacobgeo, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.jacobgeo_ghost, up->geo_int.jacobgeo_ghost, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.jacobgeo_inv, up->geo_int.jacobgeo_inv, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.gij, up->geo_int.gij, 6); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.gij_neut, up->geo_int.gij_neut, 6); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.b_i, up->geo_int.b_i, 3); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.bcart, up->geo_int.bcart, 3); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.cmag, up->geo_int.cmag, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.jacobtot, up->geo_int.jacobtot, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.jacobtot_inv, up->geo_int.jacobtot_inv, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.gxxj, up->geo_int.gxxj, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.gxyj, up->geo_int.gxyj, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.gyyj, up->geo_int.gyyj, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.gxzj, up->geo_int.gxzj, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.eps2, up->geo_int.eps2, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.dualcurlbhat, up->geo_int.dualcurlbhat, 3); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.dualcurlbhatoverB, up->geo_int.dualcurlbhatoverB, 3); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.rtg33inv, up->geo_int.rtg33inv, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.bioverJB, up->geo_int.bioverJB, 3); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.B3, up->geo_int.B3, 1); - gkyl_deflate_geo_advance(deflator, &up_3d->local, &up->local, up_3d->geo_int.qprofile, up->geo_int.qprofile, 1); + struct gkyl_deflate_geo *deflator = + gkyl_deflate_geo_new(&up_3d->basis, &up->basis, &up_3d->grid, &up->grid, rem_dirs, false); + + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_corn.mc2p, up->geo_corn.mc2p, 3 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_corn.mc2nu_pos, up->geo_corn.mc2nu_pos, 3 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_corn.bmag, up->geo_corn.bmag, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_corn.bmag_inv, up->geo_corn.bmag_inv, 1 + ); + + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.mc2p, up->geo_int.mc2p, 3 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.bmag, up->geo_int.bmag, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.g_ij, up->geo_int.g_ij, 6 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.g_ij_neut, up->geo_int.g_ij_neut, 6 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.dxdz, up->geo_int.dxdz, 9 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.dzdx, up->geo_int.dzdx, 9 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.dualmag, up->geo_int.dualmag, 3 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.normals, up->geo_int.normals, 9 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.jacobgeo, up->geo_int.jacobgeo, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.jacobgeo_ghost, up->geo_int.jacobgeo_ghost, + 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.jacobgeo_inv, up->geo_int.jacobgeo_inv, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.gij, up->geo_int.gij, 6 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.gij_neut, up->geo_int.gij_neut, 6 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.b_i, up->geo_int.b_i, 3 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.bcart, up->geo_int.bcart, 3 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.cmag, up->geo_int.cmag, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.jacobtot, up->geo_int.jacobtot, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.jacobtot_inv, up->geo_int.jacobtot_inv, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.gxxj, up->geo_int.gxxj, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.gxyj, up->geo_int.gxyj, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.gyyj, up->geo_int.gyyj, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.gxzj, up->geo_int.gxzj, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.eps2, up->geo_int.eps2, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.dualcurlbhat, up->geo_int.dualcurlbhat, 3 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.dualcurlbhatoverB, + up->geo_int.dualcurlbhatoverB, 3 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.rtg33inv, up->geo_int.rtg33inv, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.bioverJB, up->geo_int.bioverJB, 3 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.B3, up->geo_int.B3, 1 + ); + gkyl_deflate_geo_advance( + deflator, &up_3d->local, &up->local, up_3d->geo_int.qprofile, up->geo_int.qprofile, 1 + ); // Done deflating modal // Deflate nodal quantities - gkyl_deflate_geo_advance_nodal(deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.jacobgeo_nodal, up->geo_int.jacobgeo_nodal, 1); - gkyl_deflate_geo_advance_nodal(deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.dxdz_nodal, up->geo_int.dxdz_nodal, 9); - gkyl_deflate_geo_advance_nodal(deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.dzdx_nodal, up->geo_int.dzdx_nodal, 9); - gkyl_deflate_geo_advance_nodal(deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.B3_nodal, up->geo_int.B3_nodal, 1); - gkyl_deflate_geo_advance_nodal(deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.bmag_nodal, up->geo_int.bmag_nodal, 1); - gkyl_deflate_geo_advance_nodal(deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.dualcurlbhat_nodal, up->geo_int.dualcurlbhat_nodal, 3); + gkyl_deflate_geo_advance_nodal( + deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.jacobgeo_nodal, + up->geo_int.jacobgeo_nodal, 1 + ); + gkyl_deflate_geo_advance_nodal( + deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.dxdz_nodal, + up->geo_int.dxdz_nodal, 9 + ); + gkyl_deflate_geo_advance_nodal( + deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.dzdx_nodal, + up->geo_int.dzdx_nodal, 9 + ); + gkyl_deflate_geo_advance_nodal( + deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.B3_nodal, up->geo_int.B3_nodal, 1 + ); + gkyl_deflate_geo_advance_nodal( + deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.bmag_nodal, + up->geo_int.bmag_nodal, 1 + ); + gkyl_deflate_geo_advance_nodal( + deflator, &up_3d->nrange_int, &up->nrange_int, up_3d->geo_int.dualcurlbhat_nodal, + up->geo_int.dualcurlbhat_nodal, 3 + ); gkyl_deflate_geo_release(deflator); - if (up->grid.ndim==1) { + if (up->grid.ndim == 1) { // In 1D geometry, make mapc2p a function of only Z and mc2nu_pos only a function of length along field line - gkyl_array_set_offset(up->geo_corn.mc2p_deflated, 1.0, up->geo_corn.mc2p, 1 * up->basis.num_basis); - gkyl_array_set_offset(up->geo_corn.mc2nu_pos_deflated, 1.0, up->geo_corn.mc2nu_pos, 2 * up->basis.num_basis); - } - else if (up->grid.ndim==2) { - // In 2D geometry, make mapc2p a function of only R and Z + gkyl_array_set_offset( + up->geo_corn.mc2p_deflated, 1.0, up->geo_corn.mc2p, 1 * up->basis.num_basis + ); + gkyl_array_set_offset( + up->geo_corn.mc2nu_pos_deflated, 1.0, up->geo_corn.mc2nu_pos, 2 * up->basis.num_basis + ); + } else if (up->grid.ndim == 2) { + // In 2D geometry, make mapc2p a function of only R and Z // and mc2nu_pos only a function of psi and length along field line - struct gkyl_array *temp = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); - gkyl_array_set_offset(up->geo_corn.mc2p_deflated , 1.0, up->geo_corn.mc2p , 0*up->basis.num_basis); - gkyl_array_set_offset(temp , 1.0, up->geo_corn.mc2p , 1*up->basis.num_basis); - gkyl_array_set_offset(up->geo_corn.mc2p_deflated , 1.0, temp , 1*up->basis.num_basis); - gkyl_array_set_offset(up->geo_corn.mc2nu_pos_deflated, 1.0, up->geo_corn.mc2nu_pos, 0*up->basis.num_basis); - gkyl_array_set_offset(temp , 1.0, up->geo_corn.mc2nu_pos, 2*up->basis.num_basis); - gkyl_array_set_offset(up->geo_corn.mc2nu_pos_deflated, 1.0, temp , 1*up->basis.num_basis); + struct gkyl_array *temp = + gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); + gkyl_array_set_offset( + up->geo_corn.mc2p_deflated, 1.0, up->geo_corn.mc2p, 0 * up->basis.num_basis + ); + gkyl_array_set_offset(temp, 1.0, up->geo_corn.mc2p, 1 * up->basis.num_basis); + gkyl_array_set_offset(up->geo_corn.mc2p_deflated, 1.0, temp, 1 * up->basis.num_basis); + gkyl_array_set_offset( + up->geo_corn.mc2nu_pos_deflated, 1.0, up->geo_corn.mc2nu_pos, 0 * up->basis.num_basis + ); + gkyl_array_set_offset(temp, 1.0, up->geo_corn.mc2nu_pos, 2 * up->basis.num_basis); + gkyl_array_set_offset(up->geo_corn.mc2nu_pos_deflated, 1.0, temp, 1 * up->basis.num_basis); gkyl_array_release(temp); - } - else if (up->grid.ndim==3) { + } else if (up->grid.ndim == 3) { // In 3D geoemtry, these are identical gkyl_array_copy(up->geo_corn.mc2p_deflated, up->geo_corn.mc2p); gkyl_array_copy(up->geo_corn.mc2nu_pos_deflated, up->geo_corn.mc2nu_pos); @@ -559,47 +726,112 @@ gkyl_gk_geometry_deflate(const struct gk_geometry* up_3d, struct gkyl_gk_geometr // Deflate surface geo int count = 0; for (int dir = 0; dir < 3; dir++) { - if(rem_dirs[dir] == 0) { + if (rem_dirs[dir] == 0) { struct gkyl_range local_ext_in_dir_3d; int lower_3d[3] = {up_3d->local.lower[0], up_3d->local.lower[1], up_3d->local.lower[2]}; int upper_3d[3] = {up_3d->local.upper[0], up_3d->local.upper[1], up_3d->local.upper[2]}; - upper_3d[dir]+=1; + upper_3d[dir] += 1; gkyl_sub_range_init(&local_ext_in_dir_3d, &up_3d->local_ext, lower_3d, upper_3d); struct gkyl_range local_ext_in_dir; int lower[up->grid.ndim]; int upper[up->grid.ndim]; - for(int j=0; jgrid.ndim; j++) { + for (int j = 0; j < up->grid.ndim; j++) { lower[j] = up->local.lower[j]; upper[j] = up->local.upper[j]; } - upper[count]+=1; + upper[count] += 1; gkyl_sub_range_init(&local_ext_in_dir, &up->local_ext, lower, upper); - struct gkyl_deflate_geo_surf* deflator_surf = gkyl_deflate_geo_surf_new(&up_3d->surf_basis, up->num_surf_basis, &up_3d->grid, &up->grid, rem_dirs, count, false); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].bmag, up->geo_surf[count].bmag, 1); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].jacobgeo, up->geo_surf[count].jacobgeo, 1); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].jacobgeo_ratio, up->geo_surf[count].jacobgeo_ratio, 1); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].jacobtot_inv, up->geo_surf[count].jacobtot_inv, 1); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].b_i, up->geo_surf[count].b_i, 3); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].cmag, up->geo_surf[count].cmag, 1); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].B3, up->geo_surf[count].B3, 1); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].normcurlbhat, up->geo_surf[count].normcurlbhat, 1); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].normals, up->geo_surf[count].normals, 9); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].lenr, up->geo_surf[count].lenr, 1); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].deltats, up->geo_surf[count].deltats, 1); - gkyl_deflate_geo_surf_advance(deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].bimpactangle, up->geo_surf[count].bimpactangle, 1); - // deflate nodal quantities - gkyl_deflate_geo_surf_advance_nodal(deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], up_3d->geo_surf[dir].bmag_nodal, up->geo_surf[count].bmag_nodal, 1); - gkyl_deflate_geo_surf_advance_nodal(deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], up_3d->geo_surf[dir].jacobgeo_nodal, up->geo_surf[count].jacobgeo_nodal, 1); - gkyl_deflate_geo_surf_advance_nodal(deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], up_3d->geo_surf[dir].B3_nodal, up->geo_surf[count].B3_nodal, 1); - gkyl_deflate_geo_surf_advance_nodal(deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], up_3d->geo_surf[dir].normcurlbhat_nodal, up->geo_surf[count].normcurlbhat_nodal, 1); - gkyl_deflate_geo_surf_advance_nodal(deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], up_3d->geo_surf[dir].b_i_nodal, up->geo_surf[count].b_i_nodal, 3); - gkyl_deflate_geo_surf_advance_nodal(deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], up_3d->geo_surf[dir].normals_nodal, up->geo_surf[count].normals_nodal, 9); - gkyl_deflate_geo_surf_advance_nodal(deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], up_3d->geo_surf[dir].lenr_nodal, up->geo_surf[count].lenr_nodal, 1); - gkyl_deflate_geo_surf_advance_nodal(deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], up_3d->geo_surf[dir].deltats_nodal, up->geo_surf[count].deltats_nodal, 1); - gkyl_deflate_geo_surf_advance_nodal(deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], up_3d->geo_surf[dir].bimpactangle_nodal, up->geo_surf[count].bimpactangle_nodal, 1); - count+=1; + struct gkyl_deflate_geo_surf *deflator_surf = gkyl_deflate_geo_surf_new( + &up_3d->surf_basis, up->num_surf_basis, &up_3d->grid, &up->grid, rem_dirs, count, false + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].bmag, + up->geo_surf[count].bmag, 1 + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].jacobgeo, + up->geo_surf[count].jacobgeo, 1 + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].jacobgeo_ratio, + up->geo_surf[count].jacobgeo_ratio, 1 + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].jacobtot_inv, + up->geo_surf[count].jacobtot_inv, 1 + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].b_i, + up->geo_surf[count].b_i, 3 + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].cmag, + up->geo_surf[count].cmag, 1 + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].B3, + up->geo_surf[count].B3, 1 + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].normcurlbhat, + up->geo_surf[count].normcurlbhat, 1 + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].normals, + up->geo_surf[count].normals, 9 + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].lenr, + up->geo_surf[count].lenr, 1 + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].deltats, + up->geo_surf[count].deltats, 1 + ); + gkyl_deflate_geo_surf_advance( + deflator_surf, &local_ext_in_dir_3d, &local_ext_in_dir, up_3d->geo_surf[dir].bimpactangle, + up->geo_surf[count].bimpactangle, 1 + ); + // deflate nodal quantities + gkyl_deflate_geo_surf_advance_nodal( + deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], + up_3d->geo_surf[dir].bmag_nodal, up->geo_surf[count].bmag_nodal, 1 + ); + gkyl_deflate_geo_surf_advance_nodal( + deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], + up_3d->geo_surf[dir].jacobgeo_nodal, up->geo_surf[count].jacobgeo_nodal, 1 + ); + gkyl_deflate_geo_surf_advance_nodal( + deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], + up_3d->geo_surf[dir].B3_nodal, up->geo_surf[count].B3_nodal, 1 + ); + gkyl_deflate_geo_surf_advance_nodal( + deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], + up_3d->geo_surf[dir].normcurlbhat_nodal, up->geo_surf[count].normcurlbhat_nodal, 1 + ); + gkyl_deflate_geo_surf_advance_nodal( + deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], + up_3d->geo_surf[dir].b_i_nodal, up->geo_surf[count].b_i_nodal, 3 + ); + gkyl_deflate_geo_surf_advance_nodal( + deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], + up_3d->geo_surf[dir].normals_nodal, up->geo_surf[count].normals_nodal, 9 + ); + gkyl_deflate_geo_surf_advance_nodal( + deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], + up_3d->geo_surf[dir].lenr_nodal, up->geo_surf[count].lenr_nodal, 1 + ); + gkyl_deflate_geo_surf_advance_nodal( + deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], + up_3d->geo_surf[dir].deltats_nodal, up->geo_surf[count].deltats_nodal, 1 + ); + gkyl_deflate_geo_surf_advance_nodal( + deflator_surf, &up_3d->nrange_surf[dir], &up->nrange_surf[count], + up_3d->geo_surf[dir].bimpactangle_nodal, up->geo_surf[count].bimpactangle_nodal, 1 + ); + count += 1; gkyl_deflate_geo_surf_release(deflator_surf); } } @@ -607,7 +839,7 @@ gkyl_gk_geometry_deflate(const struct gk_geometry* up_3d, struct gkyl_gk_geometr // Copy metadata. up->io_meta_basic = gkyl_msgpack_map_elem_clone(up_3d->io_meta_basic_len, up_3d->io_meta_basic); up->io_meta_basic_len = up_3d->io_meta_basic_len; - + up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->ref_count = gkyl_ref_count_init(gkyl_gk_geometry_free); @@ -616,47 +848,49 @@ gkyl_gk_geometry_deflate(const struct gk_geometry* up_3d, struct gkyl_gk_geometr return up; } -void -gkyl_gk_geometry_write_efit(struct gkyl_gk_geometry_inp *geometry_inp, - struct gkyl_msgpack_map_elem* io_meta_basic_basic, int io_meta_basic_basic_len) +void gkyl_gk_geometry_write_efit( + struct gkyl_gk_geometry_inp *geometry_inp, struct gkyl_msgpack_map_elem *io_meta_basic_basic, + int io_meta_basic_basic_len +) { struct gkyl_efit *efit = gkyl_efit_new(&geometry_inp->efit_info); const char *fmt = "%s-psi.gkyl"; int sz = gkyl_calc_strlen(fmt, efit->name); - char fileNm[sz+1]; + char fileNm[sz + 1]; snprintf(fileNm, sizeof fileNm, fmt, efit->name); // Set extra metadata char geqdsk_file_name[128]; get_filename_from_path(efit->filepath, geqdsk_file_name, sizeof(geqdsk_file_name)); struct gkyl_msgpack_map_elem io_meta_basic_rz[] = { - { .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = efit->rzbasis.poly_order}, - { .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = efit->rzbasis.id}, - { .key = "geqdsk_file", .elem_type = GKYL_MP_STRING, .cval = geqdsk_file_name}, - { .key = "psisep", .elem_type = GKYL_MP_DOUBLE, .dval = efit->psisep}, - { .key = "sibry", .elem_type = GKYL_MP_DOUBLE, .dval = efit->sibry}, - { .key = "simag", .elem_type = GKYL_MP_DOUBLE, .dval = efit->simag}, - { .key = "bcentr", .elem_type = GKYL_MP_DOUBLE, .dval = efit->bcentr}, - { .key = "current", .elem_type = GKYL_MP_DOUBLE, .dval = efit->current}, - { .key = "rmaxis", .elem_type = GKYL_MP_DOUBLE, .dval = efit->rmaxis}, - { .key = "rcentr", .elem_type = GKYL_MP_DOUBLE, .dval = efit->zmaxis}, - { .key = "rleft", .elem_type = GKYL_MP_DOUBLE, .dval = efit->rleft}, - { .key = "rdim", .elem_type = GKYL_MP_DOUBLE, .dval = efit->rdim}, - { .key = "zmaxis", .elem_type = GKYL_MP_DOUBLE, .dval = efit->zmaxis}, - { .key = "zmid", .elem_type = GKYL_MP_DOUBLE, .dval = efit->zmid}, - { .key = "zdim", .elem_type = GKYL_MP_DOUBLE, .dval = efit->zdim}, + {.key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = efit->rzbasis.poly_order}, + {.key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = efit->rzbasis.id}, + {.key = "geqdsk_file", .elem_type = GKYL_MP_STRING, .cval = geqdsk_file_name}, + {.key = "psisep", .elem_type = GKYL_MP_DOUBLE, .dval = efit->psisep}, + {.key = "sibry", .elem_type = GKYL_MP_DOUBLE, .dval = efit->sibry}, + {.key = "simag", .elem_type = GKYL_MP_DOUBLE, .dval = efit->simag}, + {.key = "bcentr", .elem_type = GKYL_MP_DOUBLE, .dval = efit->bcentr}, + {.key = "current", .elem_type = GKYL_MP_DOUBLE, .dval = efit->current}, + {.key = "rmaxis", .elem_type = GKYL_MP_DOUBLE, .dval = efit->rmaxis}, + {.key = "rcentr", .elem_type = GKYL_MP_DOUBLE, .dval = efit->zmaxis}, + {.key = "rleft", .elem_type = GKYL_MP_DOUBLE, .dval = efit->rleft}, + {.key = "rdim", .elem_type = GKYL_MP_DOUBLE, .dval = efit->rdim}, + {.key = "zmaxis", .elem_type = GKYL_MP_DOUBLE, .dval = efit->zmaxis}, + {.key = "zmid", .elem_type = GKYL_MP_DOUBLE, .dval = efit->zmid}, + {.key = "zdim", .elem_type = GKYL_MP_DOUBLE, .dval = efit->zdim} }; - int io_meta_basic_rz_len = sizeof(io_meta_basic_rz)/sizeof(io_meta_basic_rz[0]); + int io_meta_basic_rz_len = sizeof(io_meta_basic_rz) / sizeof(io_meta_basic_rz[0]); int io_meta_basic_len[] = {io_meta_basic_basic_len, io_meta_basic_rz_len}; - const struct gkyl_msgpack_map_elem* io_meta_basic[] = {io_meta_basic_basic, io_meta_basic_rz}; - struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_basic_len)/sizeof(int), io_meta_basic_len, io_meta_basic); + const struct gkyl_msgpack_map_elem *io_meta_basic[] = {io_meta_basic_basic, io_meta_basic_rz}; + struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union( + sizeof(io_meta_basic_len) / sizeof(int), io_meta_basic_len, io_meta_basic + ); gkyl_grid_sub_array_write(&efit->rzgrid, &efit->rzlocal, mt, efit->psizr, fileNm); gkyl_msgpack_data_release(mt); } -void -gkyl_gk_geometry_free(const struct gkyl_ref_count *ref) +void gkyl_gk_geometry_free(const struct gkyl_ref_count *ref) { struct gk_geometry *up = container_of(ref, struct gk_geometry, ref_count); gkyl_array_release(up->geo_corn.mc2p); @@ -714,29 +948,26 @@ gkyl_gk_geometry_free(const struct gkyl_ref_count *ref) // Release nodal data gk_geometry_corn_release_nodal(up); gk_geometry_int_release_nodal(up); - for (int dir=0; dirgrid.ndim; ++dir) + for (int dir = 0; dir < up->grid.ndim; ++dir) { gk_geometry_surf_release_nodal(up, dir); + } - gkyl_msgpack_map_elem_release(up->io_meta_basic_len, up->io_meta_basic); + gkyl_msgpack_map_elem_release(up->io_meta_basic_len, up->io_meta_basic); - if (gkyl_gk_geometry_is_cu_dev(up)) - gkyl_cu_free(up->on_dev); + if (gkyl_gk_geometry_is_cu_dev(up)) { + gkyl_cu_free(up->on_dev); + } gkyl_free(up); } -struct gk_geometry* -gkyl_gk_geometry_acquire(const struct gk_geometry* up) +struct gk_geometry *gkyl_gk_geometry_acquire(const struct gk_geometry *up) { gkyl_ref_count_inc(&up->ref_count); - return (struct gk_geometry*) up; + return (struct gk_geometry *)up; } -void -gkyl_gk_geometry_release(const struct gk_geometry *up) +void gkyl_gk_geometry_release(const struct gk_geometry *up) { gkyl_ref_count_dec(&up->ref_count); } - - - diff --git a/gyrokinetic/zero/gk_geometry_cu.cu b/gyrokinetic/zero/gk_geometry_cu.cu index a192ad347a..4d72891c13 100644 --- a/gyrokinetic/zero/gk_geometry_cu.cu +++ b/gyrokinetic/zero/gk_geometry_cu.cu @@ -12,12 +12,12 @@ extern "C" { #include } -__global__ static void -gk_geometry_set_corn_cu_kernel(struct gk_geometry *gk_geom, - struct gkyl_array *mc2p, struct gkyl_array *mc2nu_pos, struct gkyl_array *bmag, struct gkyl_array *bmag_inv, - struct gkyl_array *mc2p_nodal, struct gkyl_array *mc2nu_pos_nodal, struct gkyl_array *bmag_nodal, +__global__ static void gk_geometry_set_corn_cu_kernel( + struct gk_geometry *gk_geom, struct gkyl_array *mc2p, struct gkyl_array *mc2nu_pos, + struct gkyl_array *bmag, struct gkyl_array *bmag_inv, struct gkyl_array *mc2p_nodal, + struct gkyl_array *mc2nu_pos_nodal, struct gkyl_array *bmag_nodal, struct gkyl_array *mc2p_deflated, struct gkyl_array *mc2nu_pos_deflated - ) +) { // Expansions. gk_geom->geo_corn.mc2p = mc2p; @@ -33,24 +33,27 @@ gk_geometry_set_corn_cu_kernel(struct gk_geometry *gk_geom, gk_geom->geo_corn.mc2nu_pos_deflated = mc2nu_pos_deflated; } -__global__ static void -gk_geometry_set_int_cu_kernel(struct gk_geometry *gk_geom, - struct gkyl_array *mc2p, struct gkyl_array *bmag, struct gkyl_array *g_ij, struct gkyl_array *g_ij_neut, - struct gkyl_array *dxdz, struct gkyl_array *dzdx, struct gkyl_array *dualmag, struct gkyl_array *normals, - struct gkyl_array *jacobgeo, struct gkyl_array *jacobgeo_ghost, struct gkyl_array *jacobgeo_inv, struct gkyl_array *gij, - struct gkyl_array *gij_neut, struct gkyl_array *b_i, struct gkyl_array *bcart, struct gkyl_array *cmag, - struct gkyl_array *jacobtot, struct gkyl_array *jacobtot_inv, - struct gkyl_array *gxxj, struct gkyl_array *gxyj, struct gkyl_array *gyyj, struct gkyl_array *gxzj, - struct gkyl_array *eps2, struct gkyl_array *rtg33inv, struct gkyl_array *dualcurlbhatoverB, struct gkyl_array *bioverJB, - struct gkyl_array *B3, struct gkyl_array *dualcurlbhat, struct gkyl_array *mc2p_nodal_fd, struct gkyl_array *mc2p_nodal, - struct gkyl_array *bmag_nodal, struct gkyl_array *ddtheta_nodal, struct gkyl_array *ddpsi_nodal, struct gkyl_array *curlbhat_nodal, - struct gkyl_array *dualcurlbhat_nodal, struct gkyl_array *jacobgeo_nodal, struct gkyl_array *g_ij_nodal, - struct gkyl_array *g_ij_neut_nodal, struct gkyl_array *dxdz_nodal, struct gkyl_array *dzdx_nodal, - struct gkyl_array *dualmag_nodal, struct gkyl_array *normals_nodal, struct gkyl_array *gij_neut_nodal, - struct gkyl_array *b_i_nodal, struct gkyl_array *b_i_nodal_fd, struct gkyl_array *bcart_nodal, - struct gkyl_array *B3_nodal, struct gkyl_array *dualcurlbhatoverB_nodal, struct gkyl_array *rtg33inv_nodal, +__global__ static void gk_geometry_set_int_cu_kernel( + struct gk_geometry *gk_geom, struct gkyl_array *mc2p, struct gkyl_array *bmag, + struct gkyl_array *g_ij, struct gkyl_array *g_ij_neut, struct gkyl_array *dxdz, + struct gkyl_array *dzdx, struct gkyl_array *dualmag, struct gkyl_array *normals, + struct gkyl_array *jacobgeo, struct gkyl_array *jacobgeo_ghost, struct gkyl_array *jacobgeo_inv, + struct gkyl_array *gij, struct gkyl_array *gij_neut, struct gkyl_array *b_i, + struct gkyl_array *bcart, struct gkyl_array *cmag, struct gkyl_array *jacobtot, + struct gkyl_array *jacobtot_inv, struct gkyl_array *gxxj, struct gkyl_array *gxyj, + struct gkyl_array *gyyj, struct gkyl_array *gxzj, struct gkyl_array *eps2, + struct gkyl_array *rtg33inv, struct gkyl_array *dualcurlbhatoverB, struct gkyl_array *bioverJB, + struct gkyl_array *B3, struct gkyl_array *dualcurlbhat, struct gkyl_array *mc2p_nodal_fd, + struct gkyl_array *mc2p_nodal, struct gkyl_array *bmag_nodal, struct gkyl_array *ddtheta_nodal, + struct gkyl_array *ddpsi_nodal, struct gkyl_array *curlbhat_nodal, + struct gkyl_array *dualcurlbhat_nodal, struct gkyl_array *jacobgeo_nodal, + struct gkyl_array *g_ij_nodal, struct gkyl_array *g_ij_neut_nodal, struct gkyl_array *dxdz_nodal, + struct gkyl_array *dzdx_nodal, struct gkyl_array *dualmag_nodal, struct gkyl_array *normals_nodal, + struct gkyl_array *gij_neut_nodal, struct gkyl_array *b_i_nodal, struct gkyl_array *b_i_nodal_fd, + struct gkyl_array *bcart_nodal, struct gkyl_array *B3_nodal, + struct gkyl_array *dualcurlbhatoverB_nodal, struct gkyl_array *rtg33inv_nodal, struct gkyl_array *bioverJB_nodal, struct gkyl_array *qprofile - ) +) { // Expansions. gk_geom->geo_int.mc2p = mc2p; @@ -107,21 +110,22 @@ gk_geometry_set_int_cu_kernel(struct gk_geometry *gk_geom, gk_geom->geo_int.bioverJB_nodal = bioverJB_nodal; } -__global__ static void -gk_geometry_set_surf_cu_kernel(struct gk_geometry *gk_geom, int dir, - struct gkyl_array *bmag, struct gkyl_array *jacobgeo, struct gkyl_array *jacobgeo_ratio, - struct gkyl_array *b_i, struct gkyl_array *cmag, struct gkyl_array *jacobtot_inv, - struct gkyl_array *B3, struct gkyl_array *normcurlbhat, struct gkyl_array *normals, struct gkyl_array *lenr, - struct gkyl_array *bimpactangle, struct gkyl_array *deltats, - struct gkyl_array *mc2p_nodal_fd, struct gkyl_array *mc2p_nodal, struct gkyl_array *bmag_nodal, - struct gkyl_array *curlbhat_nodal, struct gkyl_array *normcurlbhat_nodal, struct gkyl_array *ddtheta_nodal, - struct gkyl_array *ddpsi_nodal, - struct gkyl_array *jacobgeo_nodal, struct gkyl_array *b_i_nodal, struct gkyl_array *b_i_nodal_fd, - struct gkyl_array *cmag_nodal, struct gkyl_array *jacobtot_inv_nodal, struct gkyl_array *g_ij_nodal, +__global__ static void gk_geometry_set_surf_cu_kernel( + struct gk_geometry *gk_geom, int dir, struct gkyl_array *bmag, struct gkyl_array *jacobgeo, + struct gkyl_array *jacobgeo_ratio, struct gkyl_array *b_i, struct gkyl_array *cmag, + struct gkyl_array *jacobtot_inv, struct gkyl_array *B3, struct gkyl_array *normcurlbhat, + struct gkyl_array *normals, struct gkyl_array *lenr, struct gkyl_array *bimpactangle, + struct gkyl_array *deltats, struct gkyl_array *mc2p_nodal_fd, struct gkyl_array *mc2p_nodal, + struct gkyl_array *bmag_nodal, struct gkyl_array *curlbhat_nodal, + struct gkyl_array *normcurlbhat_nodal, struct gkyl_array *ddtheta_nodal, + struct gkyl_array *ddpsi_nodal, struct gkyl_array *jacobgeo_nodal, struct gkyl_array *b_i_nodal, + struct gkyl_array *b_i_nodal_fd, struct gkyl_array *cmag_nodal, + struct gkyl_array *jacobtot_inv_nodal, struct gkyl_array *g_ij_nodal, struct gkyl_array *dxdz_nodal, struct gkyl_array *dzdx_nodal, struct gkyl_array *normals_nodal, struct gkyl_array *dualmag_nodal, struct gkyl_array *bcart_nodal, struct gkyl_array *B3_nodal, - struct gkyl_array *lenr_nodal, struct gkyl_array *bimpactangle_nodal, struct gkyl_array *deltats_nodal - ) + struct gkyl_array *lenr_nodal, struct gkyl_array *bimpactangle_nodal, + struct gkyl_array *deltats_nodal +) { // Expansions. gk_geom->geo_surf[dir].bmag = bmag; @@ -162,275 +166,390 @@ gk_geometry_set_surf_cu_kernel(struct gk_geometry *gk_geom, int dir, } // Host-side wrapper for set_corn_cu_kernel -void -gkyl_geometry_set_corn_cu(struct gk_geometry *gk_geom, struct gk_geom_corn *geo_corn) +void gkyl_geometry_set_corn_cu(struct gk_geometry *gk_geom, struct gk_geom_corn *geo_corn) { - gk_geometry_set_corn_cu_kernel<<<1,1>>>(gk_geom, - geo_corn->mc2p->on_dev, geo_corn->mc2nu_pos->on_dev, geo_corn->bmag->on_dev, geo_corn->bmag_inv->on_dev, - geo_corn->mc2p_nodal->on_dev, geo_corn->mc2nu_pos_nodal->on_dev, geo_corn->bmag_nodal->on_dev, - geo_corn->mc2p_deflated->on_dev, geo_corn->mc2nu_pos_deflated->on_dev); + gk_geometry_set_corn_cu_kernel<<<1, 1> > >( + gk_geom, geo_corn->mc2p->on_dev, geo_corn->mc2nu_pos->on_dev, geo_corn->bmag->on_dev, + geo_corn->bmag_inv->on_dev, geo_corn->mc2p_nodal->on_dev, geo_corn->mc2nu_pos_nodal->on_dev, + geo_corn->bmag_nodal->on_dev, geo_corn->mc2p_deflated->on_dev, + geo_corn->mc2nu_pos_deflated->on_dev + ); } // Host-side wrapper for set_int_cu_kernel -void -gkyl_geometry_set_int_cu(struct gk_geometry *gk_geom, struct gk_geom_int *geo_int) +void gkyl_geometry_set_int_cu(struct gk_geometry *gk_geom, struct gk_geom_int *geo_int) { - gk_geometry_set_int_cu_kernel<<<1,1>>>(gk_geom, - geo_int->mc2p->on_dev, geo_int->bmag->on_dev, geo_int->g_ij->on_dev, geo_int->g_ij_neut->on_dev, - geo_int->dxdz->on_dev, geo_int->dzdx->on_dev, geo_int->dualmag->on_dev, geo_int->normals->on_dev, - geo_int->jacobgeo->on_dev, geo_int->jacobgeo_ghost->on_dev, geo_int->jacobgeo_inv->on_dev, geo_int->gij->on_dev, + gk_geometry_set_int_cu_kernel<<<1, 1> > >( + gk_geom, geo_int->mc2p->on_dev, geo_int->bmag->on_dev, geo_int->g_ij->on_dev, + geo_int->g_ij_neut->on_dev, geo_int->dxdz->on_dev, geo_int->dzdx->on_dev, + geo_int->dualmag->on_dev, geo_int->normals->on_dev, geo_int->jacobgeo->on_dev, + geo_int->jacobgeo_ghost->on_dev, geo_int->jacobgeo_inv->on_dev, geo_int->gij->on_dev, geo_int->gij_neut->on_dev, geo_int->b_i->on_dev, geo_int->bcart->on_dev, geo_int->cmag->on_dev, - geo_int->jacobtot->on_dev, geo_int->jacobtot_inv->on_dev, - geo_int->gxxj->on_dev, geo_int->gxyj->on_dev, geo_int->gyyj->on_dev, geo_int->gxzj->on_dev, - geo_int->eps2->on_dev, geo_int->rtg33inv->on_dev, geo_int->dualcurlbhatoverB->on_dev, geo_int->bioverJB->on_dev, - geo_int->B3->on_dev, geo_int->dualcurlbhat->on_dev, - geo_int->mc2p_nodal_fd->on_dev, geo_int->mc2p_nodal->on_dev, geo_int->bmag_nodal->on_dev, - geo_int->ddtheta_nodal->on_dev, geo_int->ddpsi_nodal->on_dev, geo_int->curlbhat_nodal->on_dev, geo_int->dualcurlbhat_nodal->on_dev, - geo_int->jacobgeo_nodal->on_dev, geo_int->g_ij_nodal->on_dev, geo_int->g_ij_neut_nodal->on_dev, - geo_int->dxdz_nodal->on_dev, geo_int->dzdx_nodal->on_dev, geo_int->dualmag_nodal->on_dev, - geo_int->normals_nodal->on_dev, geo_int->gij_neut_nodal->on_dev, geo_int->b_i_nodal->on_dev, - geo_int->b_i_nodal_fd->on_dev, geo_int->bcart_nodal->on_dev, geo_int->B3_nodal->on_dev, - geo_int->dualcurlbhatoverB_nodal->on_dev, geo_int->rtg33inv_nodal->on_dev, geo_int->bioverJB_nodal->on_dev, - geo_int->qprofile->on_dev); + geo_int->jacobtot->on_dev, geo_int->jacobtot_inv->on_dev, geo_int->gxxj->on_dev, + geo_int->gxyj->on_dev, geo_int->gyyj->on_dev, geo_int->gxzj->on_dev, geo_int->eps2->on_dev, + geo_int->rtg33inv->on_dev, geo_int->dualcurlbhatoverB->on_dev, geo_int->bioverJB->on_dev, + geo_int->B3->on_dev, geo_int->dualcurlbhat->on_dev, geo_int->mc2p_nodal_fd->on_dev, + geo_int->mc2p_nodal->on_dev, geo_int->bmag_nodal->on_dev, geo_int->ddtheta_nodal->on_dev, + geo_int->ddpsi_nodal->on_dev, geo_int->curlbhat_nodal->on_dev, + geo_int->dualcurlbhat_nodal->on_dev, geo_int->jacobgeo_nodal->on_dev, + geo_int->g_ij_nodal->on_dev, geo_int->g_ij_neut_nodal->on_dev, geo_int->dxdz_nodal->on_dev, + geo_int->dzdx_nodal->on_dev, geo_int->dualmag_nodal->on_dev, geo_int->normals_nodal->on_dev, + geo_int->gij_neut_nodal->on_dev, geo_int->b_i_nodal->on_dev, geo_int->b_i_nodal_fd->on_dev, + geo_int->bcart_nodal->on_dev, geo_int->B3_nodal->on_dev, + geo_int->dualcurlbhatoverB_nodal->on_dev, geo_int->rtg33inv_nodal->on_dev, + geo_int->bioverJB_nodal->on_dev, geo_int->qprofile->on_dev + ); } // Host-side wrapper for set_surf_cu_kernel -void -gkyl_geometry_set_surf_cu(struct gk_geometry *gk_geom, struct gk_geom_surf *geo_surf, int dir) +void gkyl_geometry_set_surf_cu(struct gk_geometry *gk_geom, struct gk_geom_surf *geo_surf, int dir) { - gk_geometry_set_surf_cu_kernel<<<1,1>>>(gk_geom, dir, - geo_surf->bmag->on_dev, geo_surf->jacobgeo->on_dev, geo_surf->jacobgeo_ratio->on_dev, - geo_surf->b_i->on_dev, geo_surf->cmag->on_dev, geo_surf->jacobtot_inv->on_dev, geo_surf->B3->on_dev, - geo_surf->normcurlbhat->on_dev, geo_surf->normals->on_dev, geo_surf->lenr->on_dev, geo_surf->bimpactangle->on_dev, geo_surf->deltats->on_dev, - geo_surf->mc2p_nodal_fd->on_dev, geo_surf->mc2p_nodal->on_dev, geo_surf->bmag_nodal->on_dev, - geo_surf->curlbhat_nodal->on_dev, geo_surf->normcurlbhat_nodal->on_dev, geo_surf->ddtheta_nodal->on_dev, geo_surf->ddpsi_nodal->on_dev, - geo_surf->jacobgeo_nodal->on_dev, geo_surf->b_i_nodal->on_dev, geo_surf->b_i_nodal_fd->on_dev, - geo_surf->cmag_nodal->on_dev, geo_surf->jacobtot_inv_nodal->on_dev, geo_surf->g_ij_nodal->on_dev, + gk_geometry_set_surf_cu_kernel<<<1, 1> > >( + gk_geom, dir, geo_surf->bmag->on_dev, geo_surf->jacobgeo->on_dev, + geo_surf->jacobgeo_ratio->on_dev, geo_surf->b_i->on_dev, geo_surf->cmag->on_dev, + geo_surf->jacobtot_inv->on_dev, geo_surf->B3->on_dev, geo_surf->normcurlbhat->on_dev, + geo_surf->normals->on_dev, geo_surf->lenr->on_dev, geo_surf->bimpactangle->on_dev, + geo_surf->deltats->on_dev, geo_surf->mc2p_nodal_fd->on_dev, geo_surf->mc2p_nodal->on_dev, + geo_surf->bmag_nodal->on_dev, geo_surf->curlbhat_nodal->on_dev, + geo_surf->normcurlbhat_nodal->on_dev, geo_surf->ddtheta_nodal->on_dev, + geo_surf->ddpsi_nodal->on_dev, geo_surf->jacobgeo_nodal->on_dev, geo_surf->b_i_nodal->on_dev, + geo_surf->b_i_nodal_fd->on_dev, geo_surf->cmag_nodal->on_dev, + geo_surf->jacobtot_inv_nodal->on_dev, geo_surf->g_ij_nodal->on_dev, geo_surf->dxdz_nodal->on_dev, geo_surf->dzdx_nodal->on_dev, geo_surf->normals_nodal->on_dev, geo_surf->dualmag_nodal->on_dev, geo_surf->bcart_nodal->on_dev, geo_surf->B3_nodal->on_dev, - geo_surf->lenr_nodal->on_dev, geo_surf->bimpactangle->on_dev, geo_surf->deltats_nodal->on_dev); + geo_surf->lenr_nodal->on_dev, geo_surf->bimpactangle->on_dev, geo_surf->deltats_nodal->on_dev + ); } -struct gk_geom_corn* -gk_geometry_corn_cu_dev_alloc(struct gk_geom_corn up_corn_host) +struct gk_geom_corn *gk_geometry_corn_cu_dev_alloc(struct gk_geom_corn up_corn_host) { - struct gk_geom_corn *up_corn_dev = (struct gk_geom_corn*) gkyl_malloc(sizeof(struct gk_geom_corn)); + struct gk_geom_corn *up_corn_dev = + (struct gk_geom_corn *)gkyl_malloc(sizeof(struct gk_geom_corn)); // Expansions. - up_corn_dev->mc2p = gkyl_array_cu_dev_new(up_corn_host.mc2p->type, - up_corn_host.mc2p->ncomp, up_corn_host.mc2p->size); - up_corn_dev->mc2nu_pos = gkyl_array_cu_dev_new(up_corn_host.mc2nu_pos->type, - up_corn_host.mc2nu_pos->ncomp, up_corn_host.mc2nu_pos->size); - up_corn_dev->bmag = gkyl_array_cu_dev_new(up_corn_host.bmag->type, - up_corn_host.bmag->ncomp, up_corn_host.bmag->size); - up_corn_dev->bmag_inv = gkyl_array_cu_dev_new(up_corn_host.bmag_inv->type, - up_corn_host.bmag_inv->ncomp, up_corn_host.bmag_inv->size); - up_corn_dev->mc2p_deflated = gkyl_array_cu_dev_new(up_corn_host.mc2p_deflated->type, - up_corn_host.mc2p_deflated->ncomp, up_corn_host.mc2p_deflated->size); - up_corn_dev->mc2nu_pos_deflated = gkyl_array_cu_dev_new(up_corn_host.mc2nu_pos_deflated->type, - up_corn_host.mc2nu_pos_deflated->ncomp, up_corn_host.mc2nu_pos_deflated->size); + up_corn_dev->mc2p = gkyl_array_cu_dev_new( + up_corn_host.mc2p->type, up_corn_host.mc2p->ncomp, up_corn_host.mc2p->size + ); + up_corn_dev->mc2nu_pos = gkyl_array_cu_dev_new( + up_corn_host.mc2nu_pos->type, up_corn_host.mc2nu_pos->ncomp, up_corn_host.mc2nu_pos->size + ); + up_corn_dev->bmag = gkyl_array_cu_dev_new( + up_corn_host.bmag->type, up_corn_host.bmag->ncomp, up_corn_host.bmag->size + ); + up_corn_dev->bmag_inv = gkyl_array_cu_dev_new( + up_corn_host.bmag_inv->type, up_corn_host.bmag_inv->ncomp, up_corn_host.bmag_inv->size + ); + up_corn_dev->mc2p_deflated = gkyl_array_cu_dev_new( + up_corn_host.mc2p_deflated->type, up_corn_host.mc2p_deflated->ncomp, + up_corn_host.mc2p_deflated->size + ); + up_corn_dev->mc2nu_pos_deflated = gkyl_array_cu_dev_new( + up_corn_host.mc2nu_pos_deflated->type, up_corn_host.mc2nu_pos_deflated->ncomp, + up_corn_host.mc2nu_pos_deflated->size + ); // Nodal. - up_corn_dev->mc2p_nodal = gkyl_array_cu_dev_new(up_corn_host.mc2p_nodal->type, - up_corn_host.mc2p_nodal->ncomp, up_corn_host.mc2p_nodal->size); - up_corn_dev->mc2nu_pos_nodal = gkyl_array_cu_dev_new(up_corn_host.mc2nu_pos_nodal->type, - up_corn_host.mc2nu_pos_nodal->ncomp, up_corn_host.mc2nu_pos_nodal->size); - up_corn_dev->bmag_nodal = gkyl_array_cu_dev_new(up_corn_host.bmag_nodal->type, - up_corn_host.bmag_nodal->ncomp, up_corn_host.bmag_nodal->size); + up_corn_dev->mc2p_nodal = gkyl_array_cu_dev_new( + up_corn_host.mc2p_nodal->type, up_corn_host.mc2p_nodal->ncomp, up_corn_host.mc2p_nodal->size + ); + up_corn_dev->mc2nu_pos_nodal = gkyl_array_cu_dev_new( + up_corn_host.mc2nu_pos_nodal->type, up_corn_host.mc2nu_pos_nodal->ncomp, + up_corn_host.mc2nu_pos_nodal->size + ); + up_corn_dev->bmag_nodal = gkyl_array_cu_dev_new( + up_corn_host.bmag_nodal->type, up_corn_host.bmag_nodal->ncomp, up_corn_host.bmag_nodal->size + ); return up_corn_dev; } -struct gk_geom_int* -gk_geometry_int_cu_dev_alloc(struct gk_geom_int up_int_host) +struct gk_geom_int *gk_geometry_int_cu_dev_alloc(struct gk_geom_int up_int_host) { - struct gk_geom_int *up_int_dev = (struct gk_geom_int*) gkyl_malloc(sizeof(struct gk_geom_int)); + struct gk_geom_int *up_int_dev = (struct gk_geom_int *)gkyl_malloc(sizeof(struct gk_geom_int)); // Expansions. - up_int_dev->mc2p = gkyl_array_cu_dev_new(up_int_host.mc2p->type, - up_int_host.mc2p->ncomp, up_int_host.mc2p->size); - up_int_dev->bmag = gkyl_array_cu_dev_new(up_int_host.bmag->type, - up_int_host.bmag->ncomp, up_int_host.bmag->size); - up_int_dev->g_ij = gkyl_array_cu_dev_new(up_int_host.g_ij->type, - up_int_host.g_ij->ncomp, up_int_host.g_ij->size); - up_int_dev->g_ij_neut = gkyl_array_cu_dev_new(up_int_host.g_ij_neut->type, - up_int_host.g_ij_neut->ncomp, up_int_host.g_ij_neut->size); - up_int_dev->dxdz = gkyl_array_cu_dev_new(up_int_host.dxdz->type, - up_int_host.dxdz->ncomp, up_int_host.dxdz->size); - up_int_dev->dzdx = gkyl_array_cu_dev_new(up_int_host.dzdx->type, - up_int_host.dzdx->ncomp, up_int_host.dzdx->size); - up_int_dev->dualmag = gkyl_array_cu_dev_new(up_int_host.dualmag->type, - up_int_host.dualmag->ncomp, up_int_host.dualmag->size); - up_int_dev->normals = gkyl_array_cu_dev_new(up_int_host.normals->type, - up_int_host.normals->ncomp, up_int_host.normals->size); - up_int_dev->jacobgeo = gkyl_array_cu_dev_new(up_int_host.jacobgeo->type, - up_int_host.jacobgeo->ncomp, up_int_host.jacobgeo->size); - up_int_dev->jacobgeo_ghost = gkyl_array_cu_dev_new(up_int_host.jacobgeo_ghost->type, - up_int_host.jacobgeo_ghost->ncomp, up_int_host.jacobgeo_ghost->size); - up_int_dev->jacobgeo_inv = gkyl_array_cu_dev_new(up_int_host.jacobgeo_inv->type, - up_int_host.jacobgeo_inv->ncomp, up_int_host.jacobgeo_inv->size); - up_int_dev->gij = gkyl_array_cu_dev_new(up_int_host.gij->type, - up_int_host.gij->ncomp, up_int_host.gij->size); - up_int_dev->gij_neut = gkyl_array_cu_dev_new(up_int_host.gij_neut->type, - up_int_host.gij_neut->ncomp, up_int_host.gij_neut->size); - up_int_dev->b_i = gkyl_array_cu_dev_new(up_int_host.b_i->type, - up_int_host.b_i->ncomp, up_int_host.b_i->size); - up_int_dev->bcart = gkyl_array_cu_dev_new(up_int_host.bcart->type, - up_int_host.bcart->ncomp, up_int_host.bcart->size); - up_int_dev->cmag = gkyl_array_cu_dev_new(up_int_host.cmag->type, - up_int_host.cmag->ncomp, up_int_host.cmag->size); - up_int_dev->jacobtot = gkyl_array_cu_dev_new(up_int_host.jacobtot->type, - up_int_host.jacobtot->ncomp, up_int_host.jacobtot->size); - up_int_dev->jacobtot_inv = gkyl_array_cu_dev_new(up_int_host.jacobtot_inv->type, - up_int_host.jacobtot_inv->ncomp, up_int_host.jacobtot_inv->size); - up_int_dev->gxxj = gkyl_array_cu_dev_new(up_int_host.gxxj->type, - up_int_host.gxxj->ncomp, up_int_host.gxxj->size); - up_int_dev->gxyj = gkyl_array_cu_dev_new(up_int_host.gxyj->type, - up_int_host.gxyj->ncomp, up_int_host.gxyj->size); - up_int_dev->gyyj = gkyl_array_cu_dev_new(up_int_host.gyyj->type, - up_int_host.gyyj->ncomp, up_int_host.gyyj->size); - up_int_dev->gxzj = gkyl_array_cu_dev_new(up_int_host.gxzj->type, - up_int_host.gxzj->ncomp, up_int_host.gxzj->size); - up_int_dev->eps2 = gkyl_array_cu_dev_new(up_int_host.eps2->type, - up_int_host.eps2->ncomp, up_int_host.eps2->size); - up_int_dev->rtg33inv = gkyl_array_cu_dev_new(up_int_host.rtg33inv->type, - up_int_host.rtg33inv->ncomp, up_int_host.rtg33inv->size); - up_int_dev->dualcurlbhatoverB = gkyl_array_cu_dev_new(up_int_host.dualcurlbhatoverB->type, - up_int_host.dualcurlbhatoverB->ncomp, up_int_host.dualcurlbhatoverB->size); - up_int_dev->bioverJB = gkyl_array_cu_dev_new(up_int_host.bioverJB->type, - up_int_host.bioverJB->ncomp, up_int_host.bioverJB->size); - up_int_dev->B3 = gkyl_array_cu_dev_new(up_int_host.B3->type, - up_int_host.B3->ncomp, up_int_host.B3->size); - up_int_dev->dualcurlbhat = gkyl_array_cu_dev_new(up_int_host.dualcurlbhat->type, - up_int_host.dualcurlbhat->ncomp, up_int_host.dualcurlbhat->size); - up_int_dev->qprofile = gkyl_array_cu_dev_new(up_int_host.qprofile->type, - up_int_host.qprofile->ncomp, up_int_host.qprofile->size); + up_int_dev->mc2p = + gkyl_array_cu_dev_new(up_int_host.mc2p->type, up_int_host.mc2p->ncomp, up_int_host.mc2p->size); + up_int_dev->bmag = + gkyl_array_cu_dev_new(up_int_host.bmag->type, up_int_host.bmag->ncomp, up_int_host.bmag->size); + up_int_dev->g_ij = + gkyl_array_cu_dev_new(up_int_host.g_ij->type, up_int_host.g_ij->ncomp, up_int_host.g_ij->size); + up_int_dev->g_ij_neut = gkyl_array_cu_dev_new( + up_int_host.g_ij_neut->type, up_int_host.g_ij_neut->ncomp, up_int_host.g_ij_neut->size + ); + up_int_dev->dxdz = + gkyl_array_cu_dev_new(up_int_host.dxdz->type, up_int_host.dxdz->ncomp, up_int_host.dxdz->size); + up_int_dev->dzdx = + gkyl_array_cu_dev_new(up_int_host.dzdx->type, up_int_host.dzdx->ncomp, up_int_host.dzdx->size); + up_int_dev->dualmag = gkyl_array_cu_dev_new( + up_int_host.dualmag->type, up_int_host.dualmag->ncomp, up_int_host.dualmag->size + ); + up_int_dev->normals = gkyl_array_cu_dev_new( + up_int_host.normals->type, up_int_host.normals->ncomp, up_int_host.normals->size + ); + up_int_dev->jacobgeo = gkyl_array_cu_dev_new( + up_int_host.jacobgeo->type, up_int_host.jacobgeo->ncomp, up_int_host.jacobgeo->size + ); + up_int_dev->jacobgeo_ghost = gkyl_array_cu_dev_new( + up_int_host.jacobgeo_ghost->type, up_int_host.jacobgeo_ghost->ncomp, + up_int_host.jacobgeo_ghost->size + ); + up_int_dev->jacobgeo_inv = gkyl_array_cu_dev_new( + up_int_host.jacobgeo_inv->type, up_int_host.jacobgeo_inv->ncomp, up_int_host.jacobgeo_inv->size + ); + up_int_dev->gij = + gkyl_array_cu_dev_new(up_int_host.gij->type, up_int_host.gij->ncomp, up_int_host.gij->size); + up_int_dev->gij_neut = gkyl_array_cu_dev_new( + up_int_host.gij_neut->type, up_int_host.gij_neut->ncomp, up_int_host.gij_neut->size + ); + up_int_dev->b_i = + gkyl_array_cu_dev_new(up_int_host.b_i->type, up_int_host.b_i->ncomp, up_int_host.b_i->size); + up_int_dev->bcart = gkyl_array_cu_dev_new( + up_int_host.bcart->type, up_int_host.bcart->ncomp, up_int_host.bcart->size + ); + up_int_dev->cmag = + gkyl_array_cu_dev_new(up_int_host.cmag->type, up_int_host.cmag->ncomp, up_int_host.cmag->size); + up_int_dev->jacobtot = gkyl_array_cu_dev_new( + up_int_host.jacobtot->type, up_int_host.jacobtot->ncomp, up_int_host.jacobtot->size + ); + up_int_dev->jacobtot_inv = gkyl_array_cu_dev_new( + up_int_host.jacobtot_inv->type, up_int_host.jacobtot_inv->ncomp, up_int_host.jacobtot_inv->size + ); + up_int_dev->gxxj = + gkyl_array_cu_dev_new(up_int_host.gxxj->type, up_int_host.gxxj->ncomp, up_int_host.gxxj->size); + up_int_dev->gxyj = + gkyl_array_cu_dev_new(up_int_host.gxyj->type, up_int_host.gxyj->ncomp, up_int_host.gxyj->size); + up_int_dev->gyyj = + gkyl_array_cu_dev_new(up_int_host.gyyj->type, up_int_host.gyyj->ncomp, up_int_host.gyyj->size); + up_int_dev->gxzj = + gkyl_array_cu_dev_new(up_int_host.gxzj->type, up_int_host.gxzj->ncomp, up_int_host.gxzj->size); + up_int_dev->eps2 = + gkyl_array_cu_dev_new(up_int_host.eps2->type, up_int_host.eps2->ncomp, up_int_host.eps2->size); + up_int_dev->rtg33inv = gkyl_array_cu_dev_new( + up_int_host.rtg33inv->type, up_int_host.rtg33inv->ncomp, up_int_host.rtg33inv->size + ); + up_int_dev->dualcurlbhatoverB = gkyl_array_cu_dev_new( + up_int_host.dualcurlbhatoverB->type, up_int_host.dualcurlbhatoverB->ncomp, + up_int_host.dualcurlbhatoverB->size + ); + up_int_dev->bioverJB = gkyl_array_cu_dev_new( + up_int_host.bioverJB->type, up_int_host.bioverJB->ncomp, up_int_host.bioverJB->size + ); + up_int_dev->B3 = + gkyl_array_cu_dev_new(up_int_host.B3->type, up_int_host.B3->ncomp, up_int_host.B3->size); + up_int_dev->dualcurlbhat = gkyl_array_cu_dev_new( + up_int_host.dualcurlbhat->type, up_int_host.dualcurlbhat->ncomp, up_int_host.dualcurlbhat->size + ); + up_int_dev->qprofile = gkyl_array_cu_dev_new( + up_int_host.qprofile->type, up_int_host.qprofile->ncomp, up_int_host.qprofile->size + ); // Nodal. - up_int_dev->mc2p_nodal_fd = gkyl_array_cu_dev_new(up_int_host.mc2p_nodal_fd->type, - up_int_host.mc2p_nodal_fd->ncomp, up_int_host.mc2p_nodal_fd->size); - up_int_dev->mc2p_nodal = gkyl_array_cu_dev_new(up_int_host.mc2p_nodal->type, - up_int_host.mc2p_nodal->ncomp, up_int_host.mc2p_nodal->size); - up_int_dev->bmag_nodal = gkyl_array_cu_dev_new(up_int_host.bmag_nodal->type, - up_int_host.bmag_nodal->ncomp, up_int_host.bmag_nodal->size); - up_int_dev->ddtheta_nodal = gkyl_array_cu_dev_new(up_int_host.ddtheta_nodal->type, - up_int_host.ddtheta_nodal->ncomp, up_int_host.ddtheta_nodal->size); - up_int_dev->ddpsi_nodal = gkyl_array_cu_dev_new(up_int_host.ddpsi_nodal->type, - up_int_host.ddpsi_nodal->ncomp, up_int_host.ddpsi_nodal->size); - up_int_dev->curlbhat_nodal = gkyl_array_cu_dev_new(up_int_host.curlbhat_nodal->type, - up_int_host.curlbhat_nodal->ncomp, up_int_host.curlbhat_nodal->size); - up_int_dev->dualcurlbhat_nodal = gkyl_array_cu_dev_new(up_int_host.dualcurlbhat_nodal->type, - up_int_host.dualcurlbhat_nodal->ncomp, up_int_host.dualcurlbhat_nodal->size); - up_int_dev->jacobgeo_nodal = gkyl_array_cu_dev_new(up_int_host.jacobgeo_nodal->type, - up_int_host.jacobgeo_nodal->ncomp, up_int_host.jacobgeo_nodal->size); - up_int_dev->g_ij_nodal = gkyl_array_cu_dev_new(up_int_host.g_ij_nodal->type, - up_int_host.g_ij_nodal->ncomp, up_int_host.g_ij_nodal->size); - up_int_dev->g_ij_neut_nodal = gkyl_array_cu_dev_new(up_int_host.g_ij_neut_nodal->type, - up_int_host.g_ij_neut_nodal->ncomp, up_int_host.g_ij_neut_nodal->size); - up_int_dev->dxdz_nodal = gkyl_array_cu_dev_new(up_int_host.dxdz_nodal->type, - up_int_host.dxdz_nodal->ncomp, up_int_host.dxdz_nodal->size); - up_int_dev->dzdx_nodal = gkyl_array_cu_dev_new(up_int_host.dzdx_nodal->type, - up_int_host.dzdx_nodal->ncomp, up_int_host.dzdx_nodal->size); - up_int_dev->dualmag_nodal = gkyl_array_cu_dev_new(up_int_host.dualmag_nodal->type, - up_int_host.dualmag_nodal->ncomp, up_int_host.dualmag_nodal->size); - up_int_dev->normals_nodal = gkyl_array_cu_dev_new(up_int_host.normals_nodal->type, - up_int_host.normals_nodal->ncomp, up_int_host.normals_nodal->size); - up_int_dev->gij_neut_nodal = gkyl_array_cu_dev_new(up_int_host.gij_neut_nodal->type, - up_int_host.gij_neut_nodal->ncomp, up_int_host.gij_neut_nodal->size); - up_int_dev->b_i_nodal = gkyl_array_cu_dev_new(up_int_host.b_i_nodal->type, - up_int_host.b_i_nodal->ncomp, up_int_host.b_i_nodal->size); - up_int_dev->b_i_nodal_fd = gkyl_array_cu_dev_new(up_int_host.b_i_nodal_fd->type, - up_int_host.b_i_nodal_fd->ncomp, up_int_host.b_i_nodal_fd->size); - up_int_dev->bcart_nodal = gkyl_array_cu_dev_new(up_int_host.bcart_nodal->type, - up_int_host.bcart_nodal->ncomp, up_int_host.bcart_nodal->size); - up_int_dev->B3_nodal = gkyl_array_cu_dev_new(up_int_host.B3_nodal->type, - up_int_host.B3_nodal->ncomp, up_int_host.B3_nodal->size); - up_int_dev->dualcurlbhatoverB_nodal = gkyl_array_cu_dev_new(up_int_host.dualcurlbhatoverB_nodal->type, - up_int_host.dualcurlbhatoverB_nodal->ncomp, up_int_host.dualcurlbhatoverB_nodal->size); - up_int_dev->rtg33inv_nodal = gkyl_array_cu_dev_new(up_int_host.rtg33inv_nodal->type, - up_int_host.rtg33inv_nodal->ncomp, up_int_host.rtg33inv_nodal->size); - up_int_dev->bioverJB_nodal = gkyl_array_cu_dev_new(up_int_host.bioverJB_nodal->type, - up_int_host.bioverJB_nodal->ncomp, up_int_host.bioverJB_nodal->size); + up_int_dev->mc2p_nodal_fd = gkyl_array_cu_dev_new( + up_int_host.mc2p_nodal_fd->type, up_int_host.mc2p_nodal_fd->ncomp, + up_int_host.mc2p_nodal_fd->size + ); + up_int_dev->mc2p_nodal = gkyl_array_cu_dev_new( + up_int_host.mc2p_nodal->type, up_int_host.mc2p_nodal->ncomp, up_int_host.mc2p_nodal->size + ); + up_int_dev->bmag_nodal = gkyl_array_cu_dev_new( + up_int_host.bmag_nodal->type, up_int_host.bmag_nodal->ncomp, up_int_host.bmag_nodal->size + ); + up_int_dev->ddtheta_nodal = gkyl_array_cu_dev_new( + up_int_host.ddtheta_nodal->type, up_int_host.ddtheta_nodal->ncomp, + up_int_host.ddtheta_nodal->size + ); + up_int_dev->ddpsi_nodal = gkyl_array_cu_dev_new( + up_int_host.ddpsi_nodal->type, up_int_host.ddpsi_nodal->ncomp, up_int_host.ddpsi_nodal->size + ); + up_int_dev->curlbhat_nodal = gkyl_array_cu_dev_new( + up_int_host.curlbhat_nodal->type, up_int_host.curlbhat_nodal->ncomp, + up_int_host.curlbhat_nodal->size + ); + up_int_dev->dualcurlbhat_nodal = gkyl_array_cu_dev_new( + up_int_host.dualcurlbhat_nodal->type, up_int_host.dualcurlbhat_nodal->ncomp, + up_int_host.dualcurlbhat_nodal->size + ); + up_int_dev->jacobgeo_nodal = gkyl_array_cu_dev_new( + up_int_host.jacobgeo_nodal->type, up_int_host.jacobgeo_nodal->ncomp, + up_int_host.jacobgeo_nodal->size + ); + up_int_dev->g_ij_nodal = gkyl_array_cu_dev_new( + up_int_host.g_ij_nodal->type, up_int_host.g_ij_nodal->ncomp, up_int_host.g_ij_nodal->size + ); + up_int_dev->g_ij_neut_nodal = gkyl_array_cu_dev_new( + up_int_host.g_ij_neut_nodal->type, up_int_host.g_ij_neut_nodal->ncomp, + up_int_host.g_ij_neut_nodal->size + ); + up_int_dev->dxdz_nodal = gkyl_array_cu_dev_new( + up_int_host.dxdz_nodal->type, up_int_host.dxdz_nodal->ncomp, up_int_host.dxdz_nodal->size + ); + up_int_dev->dzdx_nodal = gkyl_array_cu_dev_new( + up_int_host.dzdx_nodal->type, up_int_host.dzdx_nodal->ncomp, up_int_host.dzdx_nodal->size + ); + up_int_dev->dualmag_nodal = gkyl_array_cu_dev_new( + up_int_host.dualmag_nodal->type, up_int_host.dualmag_nodal->ncomp, + up_int_host.dualmag_nodal->size + ); + up_int_dev->normals_nodal = gkyl_array_cu_dev_new( + up_int_host.normals_nodal->type, up_int_host.normals_nodal->ncomp, + up_int_host.normals_nodal->size + ); + up_int_dev->gij_neut_nodal = gkyl_array_cu_dev_new( + up_int_host.gij_neut_nodal->type, up_int_host.gij_neut_nodal->ncomp, + up_int_host.gij_neut_nodal->size + ); + up_int_dev->b_i_nodal = gkyl_array_cu_dev_new( + up_int_host.b_i_nodal->type, up_int_host.b_i_nodal->ncomp, up_int_host.b_i_nodal->size + ); + up_int_dev->b_i_nodal_fd = gkyl_array_cu_dev_new( + up_int_host.b_i_nodal_fd->type, up_int_host.b_i_nodal_fd->ncomp, up_int_host.b_i_nodal_fd->size + ); + up_int_dev->bcart_nodal = gkyl_array_cu_dev_new( + up_int_host.bcart_nodal->type, up_int_host.bcart_nodal->ncomp, up_int_host.bcart_nodal->size + ); + up_int_dev->B3_nodal = gkyl_array_cu_dev_new( + up_int_host.B3_nodal->type, up_int_host.B3_nodal->ncomp, up_int_host.B3_nodal->size + ); + up_int_dev->dualcurlbhatoverB_nodal = gkyl_array_cu_dev_new( + up_int_host.dualcurlbhatoverB_nodal->type, up_int_host.dualcurlbhatoverB_nodal->ncomp, + up_int_host.dualcurlbhatoverB_nodal->size + ); + up_int_dev->rtg33inv_nodal = gkyl_array_cu_dev_new( + up_int_host.rtg33inv_nodal->type, up_int_host.rtg33inv_nodal->ncomp, + up_int_host.rtg33inv_nodal->size + ); + up_int_dev->bioverJB_nodal = gkyl_array_cu_dev_new( + up_int_host.bioverJB_nodal->type, up_int_host.bioverJB_nodal->ncomp, + up_int_host.bioverJB_nodal->size + ); return up_int_dev; } -struct gk_geom_surf* -gk_geometry_surf_cu_dev_alloc(struct gk_geom_surf up_surf_host) +struct gk_geom_surf *gk_geometry_surf_cu_dev_alloc(struct gk_geom_surf up_surf_host) { - struct gk_geom_surf *up_surf_dev = (struct gk_geom_surf*) gkyl_malloc(sizeof(struct gk_geom_surf)); + struct gk_geom_surf *up_surf_dev = + (struct gk_geom_surf *)gkyl_malloc(sizeof(struct gk_geom_surf)); // Expansions. - up_surf_dev->bmag = gkyl_array_cu_dev_new(up_surf_host.bmag->type, - up_surf_host.bmag->ncomp, up_surf_host.bmag->size); - up_surf_dev->jacobgeo = gkyl_array_cu_dev_new(up_surf_host.jacobgeo->type, - up_surf_host.jacobgeo->ncomp, up_surf_host.jacobgeo->size); - up_surf_dev->jacobgeo_ratio = gkyl_array_cu_dev_new(up_surf_host.jacobgeo_ratio->type, - up_surf_host.jacobgeo_ratio->ncomp, up_surf_host.jacobgeo_ratio->size); - up_surf_dev->b_i = gkyl_array_cu_dev_new(up_surf_host.b_i->type, - up_surf_host.b_i->ncomp, up_surf_host.b_i->size); - up_surf_dev->cmag = gkyl_array_cu_dev_new(up_surf_host.cmag->type, - up_surf_host.cmag->ncomp, up_surf_host.cmag->size); - up_surf_dev->jacobtot_inv = gkyl_array_cu_dev_new(up_surf_host.jacobtot_inv->type, - up_surf_host.jacobtot_inv->ncomp, up_surf_host.jacobtot_inv->size); - up_surf_dev->B3 = gkyl_array_cu_dev_new(up_surf_host.B3->type, - up_surf_host.B3->ncomp, up_surf_host.B3->size); - up_surf_dev->normcurlbhat = gkyl_array_cu_dev_new(up_surf_host.normcurlbhat->type, - up_surf_host.normcurlbhat->ncomp, up_surf_host.normcurlbhat->size); - up_surf_dev->normals = gkyl_array_cu_dev_new(up_surf_host.normals->type, - up_surf_host.normals->ncomp, up_surf_host.normals->size); - up_surf_dev->lenr = gkyl_array_cu_dev_new(up_surf_host.lenr->type, - up_surf_host.lenr->ncomp, up_surf_host.lenr->size); - up_surf_dev->bimpactangle = gkyl_array_cu_dev_new(up_surf_host.bimpactangle->type, - up_surf_host.bimpactangle->ncomp, up_surf_host.bimpactangle->size); - up_surf_dev->deltats = gkyl_array_cu_dev_new(up_surf_host.deltats->type, - up_surf_host.deltats->ncomp, up_surf_host.deltats->size); + up_surf_dev->bmag = gkyl_array_cu_dev_new( + up_surf_host.bmag->type, up_surf_host.bmag->ncomp, up_surf_host.bmag->size + ); + up_surf_dev->jacobgeo = gkyl_array_cu_dev_new( + up_surf_host.jacobgeo->type, up_surf_host.jacobgeo->ncomp, up_surf_host.jacobgeo->size + ); + up_surf_dev->jacobgeo_ratio = gkyl_array_cu_dev_new( + up_surf_host.jacobgeo_ratio->type, up_surf_host.jacobgeo_ratio->ncomp, + up_surf_host.jacobgeo_ratio->size + ); + up_surf_dev->b_i = + gkyl_array_cu_dev_new(up_surf_host.b_i->type, up_surf_host.b_i->ncomp, up_surf_host.b_i->size); + up_surf_dev->cmag = gkyl_array_cu_dev_new( + up_surf_host.cmag->type, up_surf_host.cmag->ncomp, up_surf_host.cmag->size + ); + up_surf_dev->jacobtot_inv = gkyl_array_cu_dev_new( + up_surf_host.jacobtot_inv->type, up_surf_host.jacobtot_inv->ncomp, + up_surf_host.jacobtot_inv->size + ); + up_surf_dev->B3 = + gkyl_array_cu_dev_new(up_surf_host.B3->type, up_surf_host.B3->ncomp, up_surf_host.B3->size); + up_surf_dev->normcurlbhat = gkyl_array_cu_dev_new( + up_surf_host.normcurlbhat->type, up_surf_host.normcurlbhat->ncomp, + up_surf_host.normcurlbhat->size + ); + up_surf_dev->normals = gkyl_array_cu_dev_new( + up_surf_host.normals->type, up_surf_host.normals->ncomp, up_surf_host.normals->size + ); + up_surf_dev->lenr = gkyl_array_cu_dev_new( + up_surf_host.lenr->type, up_surf_host.lenr->ncomp, up_surf_host.lenr->size + ); + up_surf_dev->bimpactangle = gkyl_array_cu_dev_new( + up_surf_host.bimpactangle->type, up_surf_host.bimpactangle->ncomp, + up_surf_host.bimpactangle->size + ); + up_surf_dev->deltats = gkyl_array_cu_dev_new( + up_surf_host.deltats->type, up_surf_host.deltats->ncomp, up_surf_host.deltats->size + ); // Nodal. - up_surf_dev->mc2p_nodal_fd = gkyl_array_cu_dev_new(up_surf_host.mc2p_nodal_fd->type, - up_surf_host.mc2p_nodal_fd->ncomp, up_surf_host.mc2p_nodal_fd->size); - up_surf_dev->mc2p_nodal = gkyl_array_cu_dev_new(up_surf_host.mc2p_nodal->type, - up_surf_host.mc2p_nodal->ncomp, up_surf_host.mc2p_nodal->size); - up_surf_dev->bmag_nodal = gkyl_array_cu_dev_new(up_surf_host.bmag_nodal->type, - up_surf_host.bmag_nodal->ncomp, up_surf_host.bmag_nodal->size); - up_surf_dev->curlbhat_nodal = gkyl_array_cu_dev_new(up_surf_host.curlbhat_nodal->type, - up_surf_host.curlbhat_nodal->ncomp, up_surf_host.curlbhat_nodal->size); - up_surf_dev->normcurlbhat_nodal = gkyl_array_cu_dev_new(up_surf_host.normcurlbhat_nodal->type, - up_surf_host.normcurlbhat_nodal->ncomp, up_surf_host.normcurlbhat_nodal->size); - up_surf_dev->ddtheta_nodal = gkyl_array_cu_dev_new(up_surf_host.ddtheta_nodal->type, - up_surf_host.ddtheta_nodal->ncomp, up_surf_host.ddtheta_nodal->size); - up_surf_dev->ddpsi_nodal = gkyl_array_cu_dev_new(up_surf_host.ddpsi_nodal->type, - up_surf_host.ddpsi_nodal->ncomp, up_surf_host.ddpsi_nodal->size); - up_surf_dev->jacobgeo_nodal = gkyl_array_cu_dev_new(up_surf_host.jacobgeo_nodal->type, - up_surf_host.jacobgeo_nodal->ncomp, up_surf_host.jacobgeo_nodal->size); - up_surf_dev->b_i_nodal = gkyl_array_cu_dev_new(up_surf_host.b_i_nodal->type, - up_surf_host.b_i_nodal->ncomp, up_surf_host.b_i_nodal->size); - up_surf_dev->b_i_nodal_fd = gkyl_array_cu_dev_new(up_surf_host.b_i_nodal_fd->type, - up_surf_host.b_i_nodal_fd->ncomp, up_surf_host.b_i_nodal_fd->size); - up_surf_dev->cmag_nodal = gkyl_array_cu_dev_new(up_surf_host.cmag_nodal->type, - up_surf_host.cmag_nodal->ncomp, up_surf_host.cmag_nodal->size); - up_surf_dev->jacobtot_inv_nodal = gkyl_array_cu_dev_new(up_surf_host.jacobtot_inv_nodal->type, - up_surf_host.jacobtot_inv_nodal->ncomp, up_surf_host.jacobtot_inv_nodal->size); - up_surf_dev->g_ij_nodal = gkyl_array_cu_dev_new(up_surf_host.g_ij_nodal->type, - up_surf_host.g_ij_nodal->ncomp, up_surf_host.g_ij_nodal->size); - up_surf_dev->dxdz_nodal = gkyl_array_cu_dev_new(up_surf_host.dxdz_nodal->type, - up_surf_host.dxdz_nodal->ncomp, up_surf_host.dxdz_nodal->size); - up_surf_dev->dzdx_nodal = gkyl_array_cu_dev_new(up_surf_host.dzdx_nodal->type, - up_surf_host.dzdx_nodal->ncomp, up_surf_host.dzdx_nodal->size); - up_surf_dev->normals_nodal = gkyl_array_cu_dev_new(up_surf_host.normals_nodal->type, - up_surf_host.normals_nodal->ncomp, up_surf_host.normals_nodal->size); - up_surf_dev->dualmag_nodal = gkyl_array_cu_dev_new(up_surf_host.dualmag_nodal->type, - up_surf_host.dualmag_nodal->ncomp, up_surf_host.dualmag_nodal->size); - up_surf_dev->bcart_nodal = gkyl_array_cu_dev_new(up_surf_host.bcart_nodal->type, - up_surf_host.bcart_nodal->ncomp, up_surf_host.bcart_nodal->size); - up_surf_dev->B3_nodal = gkyl_array_cu_dev_new(up_surf_host.B3_nodal->type, - up_surf_host.B3_nodal->ncomp, up_surf_host.B3_nodal->size); - up_surf_dev->lenr_nodal = gkyl_array_cu_dev_new(up_surf_host.lenr_nodal->type, - up_surf_host.lenr_nodal->ncomp, up_surf_host.lenr_nodal->size); - up_surf_dev->bimpactangle_nodal = gkyl_array_cu_dev_new(up_surf_host.bimpactangle_nodal->type, - up_surf_host.bimpactangle_nodal->ncomp, up_surf_host.bimpactangle_nodal->size); - up_surf_dev->deltats_nodal = gkyl_array_cu_dev_new(up_surf_host.deltats_nodal->type, - up_surf_host.deltats_nodal->ncomp, up_surf_host.deltats_nodal->size); + up_surf_dev->mc2p_nodal_fd = gkyl_array_cu_dev_new( + up_surf_host.mc2p_nodal_fd->type, up_surf_host.mc2p_nodal_fd->ncomp, + up_surf_host.mc2p_nodal_fd->size + ); + up_surf_dev->mc2p_nodal = gkyl_array_cu_dev_new( + up_surf_host.mc2p_nodal->type, up_surf_host.mc2p_nodal->ncomp, up_surf_host.mc2p_nodal->size + ); + up_surf_dev->bmag_nodal = gkyl_array_cu_dev_new( + up_surf_host.bmag_nodal->type, up_surf_host.bmag_nodal->ncomp, up_surf_host.bmag_nodal->size + ); + up_surf_dev->curlbhat_nodal = gkyl_array_cu_dev_new( + up_surf_host.curlbhat_nodal->type, up_surf_host.curlbhat_nodal->ncomp, + up_surf_host.curlbhat_nodal->size + ); + up_surf_dev->normcurlbhat_nodal = gkyl_array_cu_dev_new( + up_surf_host.normcurlbhat_nodal->type, up_surf_host.normcurlbhat_nodal->ncomp, + up_surf_host.normcurlbhat_nodal->size + ); + up_surf_dev->ddtheta_nodal = gkyl_array_cu_dev_new( + up_surf_host.ddtheta_nodal->type, up_surf_host.ddtheta_nodal->ncomp, + up_surf_host.ddtheta_nodal->size + ); + up_surf_dev->ddpsi_nodal = gkyl_array_cu_dev_new( + up_surf_host.ddpsi_nodal->type, up_surf_host.ddpsi_nodal->ncomp, up_surf_host.ddpsi_nodal->size + ); + up_surf_dev->jacobgeo_nodal = gkyl_array_cu_dev_new( + up_surf_host.jacobgeo_nodal->type, up_surf_host.jacobgeo_nodal->ncomp, + up_surf_host.jacobgeo_nodal->size + ); + up_surf_dev->b_i_nodal = gkyl_array_cu_dev_new( + up_surf_host.b_i_nodal->type, up_surf_host.b_i_nodal->ncomp, up_surf_host.b_i_nodal->size + ); + up_surf_dev->b_i_nodal_fd = gkyl_array_cu_dev_new( + up_surf_host.b_i_nodal_fd->type, up_surf_host.b_i_nodal_fd->ncomp, + up_surf_host.b_i_nodal_fd->size + ); + up_surf_dev->cmag_nodal = gkyl_array_cu_dev_new( + up_surf_host.cmag_nodal->type, up_surf_host.cmag_nodal->ncomp, up_surf_host.cmag_nodal->size + ); + up_surf_dev->jacobtot_inv_nodal = gkyl_array_cu_dev_new( + up_surf_host.jacobtot_inv_nodal->type, up_surf_host.jacobtot_inv_nodal->ncomp, + up_surf_host.jacobtot_inv_nodal->size + ); + up_surf_dev->g_ij_nodal = gkyl_array_cu_dev_new( + up_surf_host.g_ij_nodal->type, up_surf_host.g_ij_nodal->ncomp, up_surf_host.g_ij_nodal->size + ); + up_surf_dev->dxdz_nodal = gkyl_array_cu_dev_new( + up_surf_host.dxdz_nodal->type, up_surf_host.dxdz_nodal->ncomp, up_surf_host.dxdz_nodal->size + ); + up_surf_dev->dzdx_nodal = gkyl_array_cu_dev_new( + up_surf_host.dzdx_nodal->type, up_surf_host.dzdx_nodal->ncomp, up_surf_host.dzdx_nodal->size + ); + up_surf_dev->normals_nodal = gkyl_array_cu_dev_new( + up_surf_host.normals_nodal->type, up_surf_host.normals_nodal->ncomp, + up_surf_host.normals_nodal->size + ); + up_surf_dev->dualmag_nodal = gkyl_array_cu_dev_new( + up_surf_host.dualmag_nodal->type, up_surf_host.dualmag_nodal->ncomp, + up_surf_host.dualmag_nodal->size + ); + up_surf_dev->bcart_nodal = gkyl_array_cu_dev_new( + up_surf_host.bcart_nodal->type, up_surf_host.bcart_nodal->ncomp, up_surf_host.bcart_nodal->size + ); + up_surf_dev->B3_nodal = gkyl_array_cu_dev_new( + up_surf_host.B3_nodal->type, up_surf_host.B3_nodal->ncomp, up_surf_host.B3_nodal->size + ); + up_surf_dev->lenr_nodal = gkyl_array_cu_dev_new( + up_surf_host.lenr_nodal->type, up_surf_host.lenr_nodal->ncomp, up_surf_host.lenr_nodal->size + ); + up_surf_dev->bimpactangle_nodal = gkyl_array_cu_dev_new( + up_surf_host.bimpactangle_nodal->type, up_surf_host.bimpactangle_nodal->ncomp, + up_surf_host.bimpactangle_nodal->size + ); + up_surf_dev->deltats_nodal = gkyl_array_cu_dev_new( + up_surf_host.deltats_nodal->type, up_surf_host.deltats_nodal->ncomp, + up_surf_host.deltats_nodal->size + ); return up_surf_dev; } // CPU interface to create and track a GPU object -struct gk_geometry* -gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometry_inp *geometry_inp) +struct gk_geometry * +gkyl_gk_geometry_cu_dev_new(struct gk_geometry *geo_host, struct gkyl_gk_geometry_inp *geometry_inp) { - struct gk_geometry *up = (struct gk_geometry*) gkyl_malloc(sizeof(struct gk_geometry)); + struct gk_geometry *up = (struct gk_geometry *)gkyl_malloc(sizeof(struct gk_geometry)); up->geometry_id = geometry_inp->geometry_id; up->basis = geometry_inp->basis; @@ -439,12 +558,11 @@ gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometr up->global = geometry_inp->global; up->global_ext = geometry_inp->global_ext; up->grid = geometry_inp->grid; - gk_geometry_set_nodal_ranges(up) ; + gk_geometry_set_nodal_ranges(up); if (up->grid.ndim > 1) { - gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim-1, up->basis.poly_order); + gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim - 1, up->basis.poly_order); up->num_surf_basis = up->surf_basis.num_basis; - } - else { + } else { up->num_surf_basis = 1; } up->geqdsk_sign_convention = geo_host->geqdsk_sign_convention; @@ -455,16 +573,14 @@ gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometr // Check that the split happens within the domain. assert((up->grid.lower[0] <= up->x_LCFS) && (up->x_LCFS <= up->grid.upper[0])); // Check that the split happens at a cell boundary; - double needint = (up->x_LCFS - up->grid.lower[0])/up->grid.dx[0]; - double rem_floor = fabs(needint-floor(needint)); - double rem_ceil = fabs(needint-ceil(needint)); + double needint = (up->x_LCFS - up->grid.lower[0]) / up->grid.dx[0]; + double rem_floor = fabs(needint - floor(needint)); + double rem_ceil = fabs(needint - ceil(needint)); if (rem_floor < 1.0e-12) { - up->idx_LCFS_lo = (int) floor(needint); - } - else if (rem_ceil < 1.0e-12) { - up->idx_LCFS_lo = (int) ceil(needint); - } - else { + up->idx_LCFS_lo = (int)floor(needint); + } else if (rem_ceil < 1.0e-12) { + up->idx_LCFS_lo = (int)ceil(needint); + } else { fprintf(stderr, "x_LCFS = %.9e must be at a cell boundary.\n", up->x_LCFS); assert(false); } @@ -473,14 +589,15 @@ gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometr // Function pointers to twistshift function. up->parallel_lower_bc_shift_func = geometry_inp->parallel_lower_bc_shift_func; up->parallel_upper_bc_shift_func = geometry_inp->parallel_upper_bc_shift_func; - up->parallel_lower_bc_shift_ctx = geometry_inp->parallel_lower_bc_shift_ctx ; - up->parallel_upper_bc_shift_ctx = geometry_inp->parallel_upper_bc_shift_ctx ; + up->parallel_lower_bc_shift_ctx = geometry_inp->parallel_lower_bc_shift_ctx; + up->parallel_upper_bc_shift_ctx = geometry_inp->parallel_upper_bc_shift_ctx; struct gk_geom_corn *geo_corn_dev = gk_geometry_corn_cu_dev_alloc(geo_host->geo_corn); struct gk_geom_int *geo_int_dev = gk_geometry_int_cu_dev_alloc(geo_host->geo_int); struct gk_geom_surf *geo_surf_dev[up->grid.ndim]; - for (int dir=0; dirgrid.ndim; ++dir) + for (int dir = 0; dir < up->grid.ndim; ++dir) { geo_surf_dev[dir] = gk_geometry_surf_cu_dev_alloc(geo_host->geo_surf[dir]); + } // Expansions. gkyl_array_copy(geo_corn_dev->mc2p, geo_host->geo_corn.mc2p); @@ -525,30 +642,30 @@ gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometr gkyl_array_copy(geo_int_dev->dualcurlbhat, geo_host->geo_int.dualcurlbhat); gkyl_array_copy(geo_int_dev->qprofile, geo_host->geo_int.qprofile); // Nodal. - gkyl_array_copy(geo_int_dev->mc2p_nodal_fd, geo_host->geo_int.mc2p_nodal_fd); - gkyl_array_copy(geo_int_dev->mc2p_nodal, geo_host->geo_int.mc2p_nodal); - gkyl_array_copy(geo_int_dev->bmag_nodal, geo_host->geo_int.bmag_nodal); - gkyl_array_copy(geo_int_dev->ddtheta_nodal, geo_host->geo_int.ddtheta_nodal); - gkyl_array_copy(geo_int_dev->ddpsi_nodal, geo_host->geo_int.ddpsi_nodal); - gkyl_array_copy(geo_int_dev->curlbhat_nodal, geo_host->geo_int.curlbhat_nodal); - gkyl_array_copy(geo_int_dev->dualcurlbhat_nodal, geo_host->geo_int.dualcurlbhat_nodal); - gkyl_array_copy(geo_int_dev->jacobgeo_nodal, geo_host->geo_int.jacobgeo_nodal); - gkyl_array_copy(geo_int_dev->g_ij_nodal, geo_host->geo_int.g_ij_nodal); - gkyl_array_copy(geo_int_dev->g_ij_neut_nodal, geo_host->geo_int.g_ij_neut_nodal); - gkyl_array_copy(geo_int_dev->dxdz_nodal, geo_host->geo_int.dxdz_nodal); - gkyl_array_copy(geo_int_dev->dzdx_nodal, geo_host->geo_int.dzdx_nodal); - gkyl_array_copy(geo_int_dev->dualmag_nodal, geo_host->geo_int.dualmag_nodal); - gkyl_array_copy(geo_int_dev->normals_nodal, geo_host->geo_int.normals_nodal); - gkyl_array_copy(geo_int_dev->gij_neut_nodal, geo_host->geo_int.gij_neut_nodal); - gkyl_array_copy(geo_int_dev->b_i_nodal, geo_host->geo_int.b_i_nodal); - gkyl_array_copy(geo_int_dev->b_i_nodal_fd, geo_host->geo_int.b_i_nodal_fd); - gkyl_array_copy(geo_int_dev->bcart_nodal, geo_host->geo_int.bcart_nodal); - gkyl_array_copy(geo_int_dev->B3_nodal, geo_host->geo_int.B3_nodal); - gkyl_array_copy(geo_int_dev->dualcurlbhatoverB_nodal, geo_host->geo_int.dualcurlbhatoverB_nodal); - gkyl_array_copy(geo_int_dev->rtg33inv_nodal, geo_host->geo_int.rtg33inv_nodal); - gkyl_array_copy(geo_int_dev->bioverJB_nodal, geo_host->geo_int.bioverJB_nodal); + gkyl_array_copy(geo_int_dev->mc2p_nodal_fd, geo_host->geo_int.mc2p_nodal_fd); + gkyl_array_copy(geo_int_dev->mc2p_nodal, geo_host->geo_int.mc2p_nodal); + gkyl_array_copy(geo_int_dev->bmag_nodal, geo_host->geo_int.bmag_nodal); + gkyl_array_copy(geo_int_dev->ddtheta_nodal, geo_host->geo_int.ddtheta_nodal); + gkyl_array_copy(geo_int_dev->ddpsi_nodal, geo_host->geo_int.ddpsi_nodal); + gkyl_array_copy(geo_int_dev->curlbhat_nodal, geo_host->geo_int.curlbhat_nodal); + gkyl_array_copy(geo_int_dev->dualcurlbhat_nodal, geo_host->geo_int.dualcurlbhat_nodal); + gkyl_array_copy(geo_int_dev->jacobgeo_nodal, geo_host->geo_int.jacobgeo_nodal); + gkyl_array_copy(geo_int_dev->g_ij_nodal, geo_host->geo_int.g_ij_nodal); + gkyl_array_copy(geo_int_dev->g_ij_neut_nodal, geo_host->geo_int.g_ij_neut_nodal); + gkyl_array_copy(geo_int_dev->dxdz_nodal, geo_host->geo_int.dxdz_nodal); + gkyl_array_copy(geo_int_dev->dzdx_nodal, geo_host->geo_int.dzdx_nodal); + gkyl_array_copy(geo_int_dev->dualmag_nodal, geo_host->geo_int.dualmag_nodal); + gkyl_array_copy(geo_int_dev->normals_nodal, geo_host->geo_int.normals_nodal); + gkyl_array_copy(geo_int_dev->gij_neut_nodal, geo_host->geo_int.gij_neut_nodal); + gkyl_array_copy(geo_int_dev->b_i_nodal, geo_host->geo_int.b_i_nodal); + gkyl_array_copy(geo_int_dev->b_i_nodal_fd, geo_host->geo_int.b_i_nodal_fd); + gkyl_array_copy(geo_int_dev->bcart_nodal, geo_host->geo_int.bcart_nodal); + gkyl_array_copy(geo_int_dev->B3_nodal, geo_host->geo_int.B3_nodal); + gkyl_array_copy(geo_int_dev->dualcurlbhatoverB_nodal, geo_host->geo_int.dualcurlbhatoverB_nodal); + gkyl_array_copy(geo_int_dev->rtg33inv_nodal, geo_host->geo_int.rtg33inv_nodal); + gkyl_array_copy(geo_int_dev->bioverJB_nodal, geo_host->geo_int.bioverJB_nodal); - for (int dir=0; dirgrid.ndim; ++dir) { + for (int dir = 0; dir < up->grid.ndim; ++dir) { // Expansions. gkyl_array_copy(geo_surf_dev[dir]->bmag, geo_host->geo_surf[dir].bmag); gkyl_array_copy(geo_surf_dev[dir]->jacobgeo, geo_host->geo_surf[dir].jacobgeo); @@ -567,14 +684,18 @@ gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometr gkyl_array_copy(geo_surf_dev[dir]->mc2p_nodal, geo_host->geo_surf[dir].mc2p_nodal); gkyl_array_copy(geo_surf_dev[dir]->bmag_nodal, geo_host->geo_surf[dir].bmag_nodal); gkyl_array_copy(geo_surf_dev[dir]->curlbhat_nodal, geo_host->geo_surf[dir].curlbhat_nodal); - gkyl_array_copy(geo_surf_dev[dir]->normcurlbhat_nodal, geo_host->geo_surf[dir].normcurlbhat_nodal); + gkyl_array_copy( + geo_surf_dev[dir]->normcurlbhat_nodal, geo_host->geo_surf[dir].normcurlbhat_nodal + ); gkyl_array_copy(geo_surf_dev[dir]->ddtheta_nodal, geo_host->geo_surf[dir].ddtheta_nodal); gkyl_array_copy(geo_surf_dev[dir]->ddpsi_nodal, geo_host->geo_surf[dir].ddpsi_nodal); gkyl_array_copy(geo_surf_dev[dir]->jacobgeo_nodal, geo_host->geo_surf[dir].jacobgeo_nodal); gkyl_array_copy(geo_surf_dev[dir]->b_i_nodal, geo_host->geo_surf[dir].b_i_nodal); gkyl_array_copy(geo_surf_dev[dir]->b_i_nodal_fd, geo_host->geo_surf[dir].b_i_nodal_fd); gkyl_array_copy(geo_surf_dev[dir]->cmag_nodal, geo_host->geo_surf[dir].cmag_nodal); - gkyl_array_copy(geo_surf_dev[dir]->jacobtot_inv_nodal, geo_host->geo_surf[dir].jacobtot_inv_nodal); + gkyl_array_copy( + geo_surf_dev[dir]->jacobtot_inv_nodal, geo_host->geo_surf[dir].jacobtot_inv_nodal + ); gkyl_array_copy(geo_surf_dev[dir]->g_ij_nodal, geo_host->geo_surf[dir].g_ij_nodal); gkyl_array_copy(geo_surf_dev[dir]->dxdz_nodal, geo_host->geo_surf[dir].dxdz_nodal); gkyl_array_copy(geo_surf_dev[dir]->dzdx_nodal, geo_host->geo_surf[dir].dzdx_nodal); @@ -583,7 +704,9 @@ gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometr gkyl_array_copy(geo_surf_dev[dir]->bcart_nodal, geo_host->geo_surf[dir].bcart_nodal); gkyl_array_copy(geo_surf_dev[dir]->B3_nodal, geo_host->geo_surf[dir].B3_nodal); gkyl_array_copy(geo_surf_dev[dir]->lenr_nodal, geo_host->geo_surf[dir].lenr_nodal); - gkyl_array_copy(geo_surf_dev[dir]->bimpactangle_nodal, geo_host->geo_surf[dir].bimpactangle_nodal); + gkyl_array_copy( + geo_surf_dev[dir]->bimpactangle_nodal, geo_host->geo_surf[dir].bimpactangle_nodal + ); gkyl_array_copy(geo_surf_dev[dir]->deltats_nodal, geo_host->geo_surf[dir].deltats_nodal); } @@ -592,12 +715,13 @@ gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometr up->ref_count = gkyl_ref_count_init(gkyl_gk_geometry_free); // Initialize the device geometry object - struct gk_geometry *up_cu = (struct gk_geometry*) gkyl_cu_malloc(sizeof(struct gk_geometry)); + struct gk_geometry *up_cu = (struct gk_geometry *)gkyl_cu_malloc(sizeof(struct gk_geometry)); gkyl_cu_memcpy(up_cu, up, sizeof(struct gk_geometry), GKYL_CU_MEMCPY_H2D); gkyl_geometry_set_corn_cu(up_cu, geo_corn_dev); gkyl_geometry_set_int_cu(up_cu, geo_int_dev); - for (int dir=0; dirgrid.ndim; ++dir) + for (int dir = 0; dir < up->grid.ndim; ++dir) { gkyl_geometry_set_surf_cu(up_cu, geo_surf_dev[dir], dir); + } up->on_dev = up_cu; @@ -670,7 +794,7 @@ gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometr up->geo_int.bioverJB_nodal = geo_int_dev->bioverJB_nodal; gkyl_free(geo_int_dev); - for (int dir=0; dirgrid.ndim; ++dir) { + for (int dir = 0; dir < up->grid.ndim; ++dir) { // Expansions. up->geo_surf[dir].bmag = geo_surf_dev[dir]->bmag; up->geo_surf[dir].jacobgeo = geo_surf_dev[dir]->jacobgeo; @@ -711,9 +835,9 @@ gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometr } // Copy metadata. - up->io_meta_basic = gkyl_msgpack_map_elem_clone(geo_host->io_meta_basic_len, geo_host->io_meta_basic); + up->io_meta_basic = + gkyl_msgpack_map_elem_clone(geo_host->io_meta_basic_len, geo_host->io_meta_basic); up->io_meta_basic_len = geo_host->io_meta_basic_len; - + return up; } - diff --git a/gyrokinetic/zero/gk_geometry_mapc2p.c b/gyrokinetic/zero/gk_geometry_mapc2p.c index 0f2aec8203..4ee0019a48 100644 --- a/gyrokinetic/zero/gk_geometry_mapc2p.c +++ b/gyrokinetic/zero/gk_geometry_mapc2p.c @@ -17,42 +17,48 @@ #include #include -static -void gk_geometry_mapc2p_advance(struct gk_geometry* up, struct gkyl_range *nrange, double dzc[3], - evalf_t mapc2p_func, void* mapc2p_ctx, evalf_t bfield_func, void *bfield_ctx, struct gkyl_position_map *position_map) +static void gk_geometry_mapc2p_advance( + struct gk_geometry *up, struct gkyl_range *nrange, double dzc[3], evalf_t mapc2p_func, + void *mapc2p_ctx, evalf_t bfield_func, void *bfield_ctx, struct gkyl_position_map *position_map +) { //Now project mapc2p and the FD array enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { X_IDX, Y_IDX, Z_IDX }; // arrangement of cartesian coordinates - - double dtheta = up->grid.dx[TH_IDX], - dpsi = up->grid.dx[PSI_IDX], - dalpha = up->grid.dx[AL_IDX]; - double theta_lo = up->grid.lower[TH_IDX] + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX])*up->grid.dx[TH_IDX], - psi_lo = up->grid.lower[PSI_IDX] + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX])*up->grid.dx[PSI_IDX], - alpha_lo = up->grid.lower[AL_IDX] + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX])*up->grid.dx[AL_IDX]; + double dtheta = up->grid.dx[TH_IDX], dpsi = up->grid.dx[PSI_IDX], dalpha = up->grid.dx[AL_IDX]; + + double theta_lo = up->grid.lower[TH_IDX] + + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX]) * up->grid.dx[TH_IDX], + psi_lo = up->grid.lower[PSI_IDX] + + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX]) * up->grid.dx[PSI_IDX], + alpha_lo = up->grid.lower[AL_IDX] + + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX]) * up->grid.dx[AL_IDX]; double dx_fact = up->basis.poly_order == 1 ? 1 : 0.5; - dtheta *= dx_fact; dpsi *= dx_fact; dalpha *= dx_fact; - - int cidx[3] = { 0 }; - for(int ia=nrange->lower[AL_IDX]; ia<=nrange->upper[AL_IDX]; ++ia){ + dtheta *= dx_fact; + dpsi *= dx_fact; + dalpha *= dx_fact; + + int cidx[3] = {0}; + for (int ia = nrange->lower[AL_IDX]; ia <= nrange->upper[AL_IDX]; ++ia) { cidx[AL_IDX] = ia; - double alpha_curr = alpha_lo + ia*dalpha; + double alpha_curr = alpha_lo + ia * dalpha; position_map->maps[1](0.0, &alpha_curr, &alpha_curr, position_map->ctxs[1]); - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { - double psi_curr = psi_lo + ip*dpsi; - position_map->maps[0](0.0, &psi_curr, &psi_curr, position_map->ctxs[0]); + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { + double psi_curr = psi_lo + ip * dpsi; + position_map->maps[0](0.0, &psi_curr, &psi_curr, position_map->ctxs[0]); cidx[PSI_IDX] = ip; // set node coordinates - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { - double theta_curr = theta_lo + it*dtheta; + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { + double theta_curr = theta_lo + it * dtheta; position_map->maps[2](0.0, &theta_curr, &theta_curr, position_map->ctxs[2]); cidx[TH_IDX] = it; - double *mc2p_n = (double *) gkyl_array_fetch(up->geo_corn.mc2p_nodal, gkyl_range_idx(nrange, cidx)); - double *bmag_n = (double *) gkyl_array_fetch(up->geo_corn.bmag_nodal, gkyl_range_idx(nrange, cidx)); + double *mc2p_n = + (double *)gkyl_array_fetch(up->geo_corn.mc2p_nodal, gkyl_range_idx(nrange, cidx)); + double *bmag_n = + (double *)gkyl_array_fetch(up->geo_corn.bmag_nodal, gkyl_range_idx(nrange, cidx)); double xyz[3] = {psi_curr, alpha_curr, theta_curr}; double XYZ[3] = {0.}; double B[3] = {0.}; @@ -62,9 +68,10 @@ void gk_geometry_mapc2p_advance(struct gk_geometry* up, struct gkyl_range *nrang mc2p_n[X_IDX] = XYZ[X_IDX]; mc2p_n[Y_IDX] = XYZ[Y_IDX]; mc2p_n[Z_IDX] = XYZ[Z_IDX]; - bmag_n[0] = sqrt(B[0]*B[0] + B[1]*B[1] + B[2]*B[2]); + bmag_n[0] = sqrt(B[0] * B[0] + B[1] * B[1] + B[2] * B[2]); - double *mc2nu_n = gkyl_array_fetch(up->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(nrange, cidx)); + double *mc2nu_n = + gkyl_array_fetch(up->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(nrange, cidx)); mc2nu_n[X_IDX] = psi_curr; mc2nu_n[Y_IDX] = alpha_curr; mc2nu_n[Z_IDX] = theta_curr; @@ -73,87 +80,110 @@ void gk_geometry_mapc2p_advance(struct gk_geometry* up, struct gkyl_range *nrang } struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&up->basis, &up->grid, false); - gkyl_nodal_ops_n2m(n2m, &up->basis, &up->grid, nrange, &up->local, 3, up->geo_corn.mc2p_nodal, up->geo_corn.mc2p, false); - gkyl_nodal_ops_n2m(n2m, &up->basis, &up->grid, nrange, &up->local, 3, up->geo_corn.mc2nu_pos_nodal, up->geo_corn.mc2nu_pos, false); - gkyl_nodal_ops_n2m(n2m, &up->basis, &up->grid, nrange, &up->local, 1, up->geo_corn.bmag_nodal, up->geo_corn.bmag, false); + gkyl_nodal_ops_n2m( + n2m, &up->basis, &up->grid, nrange, &up->local, 3, up->geo_corn.mc2p_nodal, up->geo_corn.mc2p, + false + ); + gkyl_nodal_ops_n2m( + n2m, &up->basis, &up->grid, nrange, &up->local, 3, up->geo_corn.mc2nu_pos_nodal, + up->geo_corn.mc2nu_pos, false + ); + gkyl_nodal_ops_n2m( + n2m, &up->basis, &up->grid, nrange, &up->local, 1, up->geo_corn.bmag_nodal, up->geo_corn.bmag, + false + ); gkyl_nodal_ops_release(n2m); // Need 1/B for LBO collisions, computed weakly. gkyl_dg_inv_op_range(&up->basis, 0, up->geo_corn.bmag_inv, 0, up->geo_corn.bmag, &up->local); - } -static -void gk_geometry_mapc2p_advance_interior(struct gk_geometry* up, struct gkyl_range *nrange, double dzc[3], - evalf_t mapc2p_func, void* mapc2p_ctx, evalf_t bfield_func, void *bfield_ctx, struct gkyl_position_map *position_map) +static void gk_geometry_mapc2p_advance_interior( + struct gk_geometry *up, struct gkyl_range *nrange, double dzc[3], evalf_t mapc2p_func, + void *mapc2p_ctx, evalf_t bfield_func, void *bfield_ctx, struct gkyl_position_map *position_map +) { - //Now project mapc2p and the FD array enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { X_IDX, Y_IDX, Z_IDX }; // arrangement of cartesian coordinates - - double dtheta = up->grid.dx[TH_IDX], - dpsi = up->grid.dx[PSI_IDX], - dalpha = up->grid.dx[AL_IDX]; - double theta_lo = up->grid.lower[TH_IDX] + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX])*up->grid.dx[TH_IDX], - psi_lo = up->grid.lower[PSI_IDX] + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX])*up->grid.dx[PSI_IDX], - alpha_lo = up->grid.lower[AL_IDX] + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX])*up->grid.dx[AL_IDX]; + double dtheta = up->grid.dx[TH_IDX], dpsi = up->grid.dx[PSI_IDX], dalpha = up->grid.dx[AL_IDX]; - double dels[2] = {1.0/sqrt(3), 1.0-1.0/sqrt(3) }; - theta_lo = theta_lo + dels[1]*dtheta/2.0; - psi_lo = psi_lo + dels[1]*dpsi/2.0; - alpha_lo = alpha_lo + dels[1]*dalpha/2.0; + double theta_lo = up->grid.lower[TH_IDX] + + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX]) * up->grid.dx[TH_IDX], + psi_lo = up->grid.lower[PSI_IDX] + + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX]) * up->grid.dx[PSI_IDX], + alpha_lo = up->grid.lower[AL_IDX] + + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX]) * up->grid.dx[AL_IDX]; - double dx_fact = up->basis.poly_order == 1 ? 1 : 0.5; - dtheta *= dx_fact; dpsi *= dx_fact; dalpha *= dx_fact; + double dels[2] = {1.0 / sqrt(3), 1.0 - 1.0 / sqrt(3)}; + theta_lo = theta_lo + dels[1] * dtheta / 2.0; + psi_lo = psi_lo + dels[1] * dpsi / 2.0; + alpha_lo = alpha_lo + dels[1] * dalpha / 2.0; - // used for finite differences - double delta_alpha = dalpha*1e-2; - double delta_psi = dpsi*1e-2; - double delta_theta = dtheta*1e-2; + double dx_fact = up->basis.poly_order == 1 ? 1 : 0.5; + dtheta *= dx_fact; + dpsi *= dx_fact; + dalpha *= dx_fact; + + // used for finite differences + double delta_alpha = dalpha * 1e-2; + double delta_psi = dpsi * 1e-2; + double delta_theta = dtheta * 1e-2; dzc[0] = delta_psi; dzc[1] = delta_alpha; dzc[2] = delta_theta; int modifiers[5] = {0, -1, 1, -2, 2}; - - int cidx[3] = { 0 }; - for(int ia=nrange->lower[AL_IDX]; ia<=nrange->upper[AL_IDX]; ++ia){ + + int cidx[3] = {0}; + for (int ia = nrange->lower[AL_IDX]; ia <= nrange->upper[AL_IDX]; ++ia) { cidx[AL_IDX] = ia; - for(int ia_delta = 0; ia_delta < 3; ia_delta++){ // interior stencil - double alpha_curr = calc_running_coord(alpha_lo, ia-nrange->lower[AL_IDX], dalpha) + modifiers[ia_delta]*delta_alpha; - position_map->maps[1](0.0, &alpha_curr, &alpha_curr, position_map->ctxs[1]); + for (int ia_delta = 0; ia_delta < 3; ia_delta++) { // interior stencil + double alpha_curr = calc_running_coord(alpha_lo, ia - nrange->lower[AL_IDX], dalpha) + + modifiers[ia_delta] * delta_alpha; + position_map->maps[1](0.0, &alpha_curr, &alpha_curr, position_map->ctxs[1]); - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { - int ip_delta_max = 3;// interior - if(ia_delta != 0) + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { + int ip_delta_max = 3; // interior + if (ia_delta != 0) { ip_delta_max = 1; - for(int ip_delta = 0; ip_delta < ip_delta_max; ip_delta++){ - double psi_curr = calc_running_coord(psi_lo, ip-nrange->lower[PSI_IDX], dpsi) + modifiers[ip_delta]*delta_psi; - position_map->maps[0](0.0, &psi_curr, &psi_curr, position_map->ctxs[0]); + } + for (int ip_delta = 0; ip_delta < ip_delta_max; ip_delta++) { + double psi_curr = calc_running_coord(psi_lo, ip - nrange->lower[PSI_IDX], dpsi) + + modifiers[ip_delta] * delta_psi; + position_map->maps[0](0.0, &psi_curr, &psi_curr, position_map->ctxs[0]); cidx[PSI_IDX] = ip; // set node coordinates - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { int it_delta_max = 3; // interior - if(ia_delta != 0 || ip_delta != 0 ) + if (ia_delta != 0 || ip_delta != 0) { it_delta_max = 1; - for(int it_delta = 0; it_delta < it_delta_max; it_delta++){ - double theta_curr = calc_running_coord(theta_lo, it-nrange->lower[TH_IDX], dtheta) + modifiers[it_delta]*delta_theta; + } + for (int it_delta = 0; it_delta < it_delta_max; it_delta++) { + double theta_curr = calc_running_coord(theta_lo, it - nrange->lower[TH_IDX], dtheta) + + modifiers[it_delta] * delta_theta; position_map->maps[2](0.0, &theta_curr, &theta_curr, position_map->ctxs[2]); cidx[TH_IDX] = it; int lidx = 0; - if (ip_delta != 0) - lidx = 3 + 3*(ip_delta-1); - if (ia_delta != 0) - lidx = 15 + 3*(ia_delta-1); - if (it_delta != 0) - lidx = 27 + 3*(it_delta-1); - - double *mc2p_quad_fd_n = (double *) gkyl_array_fetch(up->geo_int.mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); - double *mc2p_quad_n = (double *) gkyl_array_fetch(up->geo_int.mc2p_nodal, gkyl_range_idx(nrange, cidx)); - double *bmag_n = (double *) gkyl_array_fetch(up->geo_int.bmag_nodal, gkyl_range_idx(nrange, cidx)); - double *bhat_quad_fd_n = (double *) gkyl_array_fetch(up->geo_int.b_i_nodal_fd, gkyl_range_idx(nrange, cidx)); + if (ip_delta != 0) { + lidx = 3 + 3 * (ip_delta - 1); + } + if (ia_delta != 0) { + lidx = 15 + 3 * (ia_delta - 1); + } + if (it_delta != 0) { + lidx = 27 + 3 * (it_delta - 1); + } + + double *mc2p_quad_fd_n = + (double *)gkyl_array_fetch(up->geo_int.mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); + double *mc2p_quad_n = + (double *)gkyl_array_fetch(up->geo_int.mc2p_nodal, gkyl_range_idx(nrange, cidx)); + double *bmag_n = + (double *)gkyl_array_fetch(up->geo_int.bmag_nodal, gkyl_range_idx(nrange, cidx)); + double *bhat_quad_fd_n = + (double *)gkyl_array_fetch(up->geo_int.b_i_nodal_fd, gkyl_range_idx(nrange, cidx)); double xyz[3] = {psi_curr, alpha_curr, theta_curr}; double XYZ[3] = {0.}; @@ -161,17 +191,16 @@ void gk_geometry_mapc2p_advance_interior(struct gk_geometry* up, struct gkyl_ran mapc2p_func(0.0, xyz, XYZ, mapc2p_ctx); bfield_func(0.0, xyz, B, bfield_ctx); - mc2p_quad_fd_n[lidx+X_IDX] = XYZ[X_IDX]; - mc2p_quad_fd_n[lidx+Y_IDX] = XYZ[Y_IDX]; - mc2p_quad_fd_n[lidx+Z_IDX] = XYZ[Z_IDX]; + mc2p_quad_fd_n[lidx + X_IDX] = XYZ[X_IDX]; + mc2p_quad_fd_n[lidx + Y_IDX] = XYZ[Y_IDX]; + mc2p_quad_fd_n[lidx + Z_IDX] = XYZ[Z_IDX]; - double bmag = sqrt(B[0]*B[0] + B[1]*B[1] + B[2]*B[2]); - bhat_quad_fd_n[lidx+X_IDX] = B[X_IDX]/bmag; - bhat_quad_fd_n[lidx+Y_IDX] = B[Y_IDX]/bmag; - bhat_quad_fd_n[lidx+Z_IDX] = B[Z_IDX]/bmag; + double bmag = sqrt(B[0] * B[0] + B[1] * B[1] + B[2] * B[2]); + bhat_quad_fd_n[lidx + X_IDX] = B[X_IDX] / bmag; + bhat_quad_fd_n[lidx + Y_IDX] = B[Y_IDX] / bmag; + bhat_quad_fd_n[lidx + Z_IDX] = B[Z_IDX] / bmag; - - if(ip_delta==0 && ia_delta==0 && it_delta==0){ + if (ip_delta == 0 && ia_delta == 0 && it_delta == 0) { mc2p_quad_n[X_IDX] = XYZ[X_IDX]; mc2p_quad_n[Y_IDX] = XYZ[Y_IDX]; mc2p_quad_n[Z_IDX] = XYZ[Z_IDX]; @@ -185,137 +214,181 @@ void gk_geometry_mapc2p_advance_interior(struct gk_geometry* up, struct gkyl_ran } struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&up->basis, &up->grid, false); - gkyl_nodal_ops_n2m(n2m, &up->basis, &up->grid, nrange, &up->local, 3, up->geo_int.mc2p_nodal, up->geo_int.mc2p, true); - gkyl_nodal_ops_n2m(n2m, &up->basis, &up->grid, nrange, &up->local, 1, up->geo_int.bmag_nodal, up->geo_int.bmag, true); + gkyl_nodal_ops_n2m( + n2m, &up->basis, &up->grid, nrange, &up->local, 3, up->geo_int.mc2p_nodal, up->geo_int.mc2p, + true + ); + gkyl_nodal_ops_n2m( + n2m, &up->basis, &up->grid, nrange, &up->local, 1, up->geo_int.bmag_nodal, up->geo_int.bmag, + true + ); gkyl_nodal_ops_release(n2m); // Now calculate the metrics. - struct gkyl_calc_metric* mcalc = gkyl_calc_metric_new(&up->basis, &up->grid, - &up->global, &up->global_ext, &up->local, &up->local_ext, false, false); + struct gkyl_calc_metric *mcalc = gkyl_calc_metric_new( + &up->basis, &up->grid, &up->global, &up->global_ext, &up->local, &up->local_ext, false, false + ); gkyl_calc_metric_advance_interior(mcalc, up); gkyl_array_copy(up->geo_int.g_ij_neut, up->geo_int.g_ij); - + // Calculate the derived geometric quantities. - struct gkyl_calc_derived_geo *jcalculator = gkyl_calc_derived_geo_new(&up->basis, &up->grid, 1, false); - gkyl_calc_derived_geo_advance(jcalculator, &up->local, up->geo_int.g_ij, up->geo_int.bmag, - up->geo_int.jacobgeo, up->geo_int.jacobgeo_inv, up->geo_int.gij, up->geo_int.b_i, up->geo_int.cmag, up->geo_int.jacobtot, up->geo_int.jacobtot_inv, - up->geo_int.gxxj, up->geo_int.gxyj, up->geo_int.gyyj, up->geo_int.gxzj, up->geo_int.eps2); + struct gkyl_calc_derived_geo *jcalculator = + gkyl_calc_derived_geo_new(&up->basis, &up->grid, 1, false); + gkyl_calc_derived_geo_advance( + jcalculator, &up->local, up->geo_int.g_ij, up->geo_int.bmag, up->geo_int.jacobgeo, + up->geo_int.jacobgeo_inv, up->geo_int.gij, up->geo_int.b_i, up->geo_int.cmag, + up->geo_int.jacobtot, up->geo_int.jacobtot_inv, up->geo_int.gxxj, up->geo_int.gxyj, + up->geo_int.gyyj, up->geo_int.gxzj, up->geo_int.eps2 + ); gkyl_array_copy(up->geo_int.gij_neut, up->geo_int.gij); gkyl_calc_derived_geo_release(jcalculator); - gkyl_calc_metric_advance_bcart(mcalc, nrange, up->geo_int.b_i, up->geo_int.dzdx, up->geo_int.bcart, &up->local); + gkyl_calc_metric_advance_bcart( + mcalc, nrange, up->geo_int.b_i, up->geo_int.dzdx, up->geo_int.bcart, &up->local + ); gkyl_calc_metric_release(mcalc); } -void gk_geometry_mapc2p_advance_surface(struct gk_geometry* up, int dir, struct gkyl_range *nrange, double dzc[3], - evalf_t mapc2p_func, void* mapc2p_ctx, evalf_t bfield_func, void *bfield_ctx, - struct gkyl_position_map *position_map) +void gk_geometry_mapc2p_advance_surface( + struct gk_geometry *up, int dir, struct gkyl_range *nrange, double dzc[3], evalf_t mapc2p_func, + void *mapc2p_ctx, evalf_t bfield_func, void *bfield_ctx, struct gkyl_position_map *position_map +) { - //Now project mapc2p and the FD array enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { X_IDX, Y_IDX, Z_IDX }; // arrangement of cartesian coordinates - - double dtheta = up->grid.dx[TH_IDX], - dpsi = up->grid.dx[PSI_IDX], - dalpha = up->grid.dx[AL_IDX]; - double theta_lo = up->grid.lower[TH_IDX] + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX])*up->grid.dx[TH_IDX], - psi_lo = up->grid.lower[PSI_IDX] + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX])*up->grid.dx[PSI_IDX], - alpha_lo = up->grid.lower[AL_IDX] + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX])*up->grid.dx[AL_IDX]; + double dtheta = up->grid.dx[TH_IDX], dpsi = up->grid.dx[PSI_IDX], dalpha = up->grid.dx[AL_IDX]; - double dels[2] = {1.0/sqrt(3), 1.0-1.0/sqrt(3) }; - theta_lo += dir == 2 ? 0.0 : dels[1]*dtheta/2.0; - psi_lo += dir == 0 ? 0.0 : dels[1]*dpsi/2.0; - alpha_lo += dir == 1 ? 0. : dels[1]*dalpha/2.0; + double theta_lo = up->grid.lower[TH_IDX] + + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX]) * up->grid.dx[TH_IDX], + psi_lo = up->grid.lower[PSI_IDX] + + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX]) * up->grid.dx[PSI_IDX], + alpha_lo = up->grid.lower[AL_IDX] + + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX]) * up->grid.dx[AL_IDX]; - double dx_fact = up->basis.poly_order == 1 ? 1 : 0.5; - dtheta *= dx_fact; dpsi *= dx_fact; dalpha *= dx_fact; + double dels[2] = {1.0 / sqrt(3), 1.0 - 1.0 / sqrt(3)}; + theta_lo += dir == 2 ? 0.0 : dels[1] * dtheta / 2.0; + psi_lo += dir == 0 ? 0.0 : dels[1] * dpsi / 2.0; + alpha_lo += dir == 1 ? 0. : dels[1] * dalpha / 2.0; - // used for finite differences - double delta_alpha = dalpha*1e-2; - double delta_psi = dpsi*1e-2; - double delta_theta = dtheta*1e-2; + double dx_fact = up->basis.poly_order == 1 ? 1 : 0.5; + dtheta *= dx_fact; + dpsi *= dx_fact; + dalpha *= dx_fact; + + // used for finite differences + double delta_alpha = dalpha * 1e-2; + double delta_psi = dpsi * 1e-2; + double delta_theta = dtheta * 1e-2; dzc[0] = delta_psi; dzc[1] = delta_alpha; dzc[2] = delta_theta; int modifiers[5] = {0, -1, 1, -2, 2}; - - int cidx[3] = { 0 }; - for(int ia=nrange->lower[AL_IDX]; ia<=nrange->upper[AL_IDX]; ++ia){ + + int cidx[3] = {0}; + for (int ia = nrange->lower[AL_IDX]; ia <= nrange->upper[AL_IDX]; ++ia) { cidx[AL_IDX] = ia; - for(int ia_delta = 0; ia_delta < 5; ia_delta++){ // should be <5 - if((ia == nrange->lower[AL_IDX]) && (up->local.lower[AL_IDX]== up->global.lower[AL_IDX]) && dir==1){ - if(ia_delta == 1 || ia_delta == 3) + for (int ia_delta = 0; ia_delta < 5; ia_delta++) { // should be <5 + if ((ia == nrange->lower[AL_IDX]) && (up->local.lower[AL_IDX] == up->global.lower[AL_IDX]) && + dir == 1) { + if (ia_delta == 1 || ia_delta == 3) { continue; // want to use one sided stencils at edge - } - else if((ia == nrange->upper[AL_IDX]) && (up->local.upper[AL_IDX]== up->global.upper[AL_IDX])&& dir==1){ - if(ia_delta == 2 || ia_delta == 4) - continue; // want to use one sided stencils at edge - } - else{ //interior - if( ia_delta == 3 || ia_delta == 4) + } + } else if ((ia == nrange->upper[AL_IDX]) && + (up->local.upper[AL_IDX] == up->global.upper[AL_IDX]) && dir == 1) { + if (ia_delta == 2 || ia_delta == 4) { + continue; // want to use one sided stencils at edge + } + } else { //interior + if (ia_delta == 3 || ia_delta == 4) { continue; //dont do two away + } } - double alpha_curr = dir==1 ? alpha_lo + ia*dalpha : calc_running_coord(alpha_lo, ia-nrange->lower[AL_IDX], dalpha); - alpha_curr += modifiers[ia_delta]*delta_alpha; + double alpha_curr = dir == 1 ? + alpha_lo + ia * dalpha : + calc_running_coord(alpha_lo, ia - nrange->lower[AL_IDX], dalpha); + alpha_curr += modifiers[ia_delta] * delta_alpha; position_map->maps[1](0.0, &alpha_curr, &alpha_curr, position_map->ctxs[1]); - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { - int ip_delta_max = 5;// should be 5 - if(ia_delta != 0) + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { + int ip_delta_max = 5; // should be 5 + if (ia_delta != 0) { ip_delta_max = 1; - for(int ip_delta = 0; ip_delta < ip_delta_max; ip_delta++){ - if((ip == nrange->lower[PSI_IDX]) && (up->local.lower[PSI_IDX]== up->global.lower[PSI_IDX]) && dir==0){ - if(ip_delta == 1 || ip_delta == 3) + } + for (int ip_delta = 0; ip_delta < ip_delta_max; ip_delta++) { + if ((ip == nrange->lower[PSI_IDX]) && + (up->local.lower[PSI_IDX] == up->global.lower[PSI_IDX]) && dir == 0) { + if (ip_delta == 1 || ip_delta == 3) { continue; // want to use one sided stencils at edge - } - else if((ip == nrange->upper[PSI_IDX]) && (up->local.upper[PSI_IDX]== up->global.upper[PSI_IDX]) && dir==0){ - if(ip_delta == 2 || ip_delta == 4) + } + } else if ((ip == nrange->upper[PSI_IDX]) && + (up->local.upper[PSI_IDX] == up->global.upper[PSI_IDX]) && dir == 0) { + if (ip_delta == 2 || ip_delta == 4) { continue; // want to use one sided stencils at edge - } - else{ // interior - if( ip_delta == 3 || ip_delta == 4) + } + } else { // interior + if (ip_delta == 3 || ip_delta == 4) { continue; //dont do two away + } } - double psi_curr = dir == 0 ? psi_lo + ip*dpsi : calc_running_coord(psi_lo, ip-nrange->lower[PSI_IDX], dpsi) ; - psi_curr += modifiers[ip_delta]*delta_psi; - position_map->maps[0](0.0, &psi_curr, &psi_curr, position_map->ctxs[0]); + double psi_curr = dir == 0 ? + psi_lo + ip * dpsi : + calc_running_coord(psi_lo, ip - nrange->lower[PSI_IDX], dpsi); + psi_curr += modifiers[ip_delta] * delta_psi; + position_map->maps[0](0.0, &psi_curr, &psi_curr, position_map->ctxs[0]); cidx[PSI_IDX] = ip; // set node coordinates - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { int it_delta_max = 5; // should be 5 - if(ia_delta != 0 || ip_delta != 0 ) + if (ia_delta != 0 || ip_delta != 0) { it_delta_max = 1; - for(int it_delta = 0; it_delta < it_delta_max; it_delta++){ - if((it == nrange->lower[TH_IDX]) && (up->local.lower[TH_IDX]== up->global.lower[TH_IDX]) && dir==2){ - if(it_delta == 1 || it_delta == 3) + } + for (int it_delta = 0; it_delta < it_delta_max; it_delta++) { + if ((it == nrange->lower[TH_IDX]) && + (up->local.lower[TH_IDX] == up->global.lower[TH_IDX]) && dir == 2) { + if (it_delta == 1 || it_delta == 3) { continue; // want to use one sided stencils at edge - } - else if((it == nrange->upper[TH_IDX]) && (up->local.upper[TH_IDX]== up->global.upper[TH_IDX]) && dir==2){ - if(it_delta == 2 || it_delta == 4) + } + } else if ((it == nrange->upper[TH_IDX]) && + (up->local.upper[TH_IDX] == up->global.upper[TH_IDX]) && dir == 2) { + if (it_delta == 2 || it_delta == 4) { continue; // want to use one sided stencils at edge - } - else{ - if( it_delta == 3 || it_delta == 4) + } + } else { + if (it_delta == 3 || it_delta == 4) { continue; //dont do two away + } } - double theta_curr = dir==2 ? theta_lo + it*dtheta: calc_running_coord(theta_lo, it-nrange->lower[TH_IDX], dtheta); - theta_curr += modifiers[it_delta]*delta_theta; + double theta_curr = + dir == 2 ? theta_lo + it * dtheta : + calc_running_coord(theta_lo, it - nrange->lower[TH_IDX], dtheta); + theta_curr += modifiers[it_delta] * delta_theta; position_map->maps[2](0.0, &theta_curr, &theta_curr, position_map->ctxs[2]); cidx[TH_IDX] = it; int lidx = 0; - if (ip_delta != 0) - lidx = 3 + 3*(ip_delta-1); - if (ia_delta != 0) - lidx = 15 + 3*(ia_delta-1); - if (it_delta != 0) - lidx = 27 + 3*(it_delta-1); - - double *mc2p_fd_n = (double *) gkyl_array_fetch(up->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); - double *mc2p_n = (double *) gkyl_array_fetch(up->geo_surf[dir].mc2p_nodal, gkyl_range_idx(nrange, cidx)); - double *bmag_n = (double *) gkyl_array_fetch(up->geo_surf[dir].bmag_nodal, gkyl_range_idx(nrange, cidx)); - double *bhat_fd_n = (double *) gkyl_array_fetch(up->geo_surf[dir].b_i_nodal_fd, gkyl_range_idx(nrange, cidx)); + if (ip_delta != 0) { + lidx = 3 + 3 * (ip_delta - 1); + } + if (ia_delta != 0) { + lidx = 15 + 3 * (ia_delta - 1); + } + if (it_delta != 0) { + lidx = 27 + 3 * (it_delta - 1); + } + + double *mc2p_fd_n = (double *)gkyl_array_fetch( + up->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(nrange, cidx) + ); + double *mc2p_n = (double *)gkyl_array_fetch( + up->geo_surf[dir].mc2p_nodal, gkyl_range_idx(nrange, cidx) + ); + double *bmag_n = (double *)gkyl_array_fetch( + up->geo_surf[dir].bmag_nodal, gkyl_range_idx(nrange, cidx) + ); + double *bhat_fd_n = (double *)gkyl_array_fetch( + up->geo_surf[dir].b_i_nodal_fd, gkyl_range_idx(nrange, cidx) + ); double xyz[3] = {psi_curr, alpha_curr, theta_curr}; double XYZ[3] = {0.}; @@ -323,16 +396,16 @@ void gk_geometry_mapc2p_advance_surface(struct gk_geometry* up, int dir, struct mapc2p_func(0.0, xyz, XYZ, mapc2p_ctx); bfield_func(0.0, xyz, B, bfield_ctx); - mc2p_fd_n[lidx+X_IDX] = XYZ[X_IDX]; - mc2p_fd_n[lidx+Y_IDX] = XYZ[Y_IDX]; - mc2p_fd_n[lidx+Z_IDX] = XYZ[Z_IDX]; + mc2p_fd_n[lidx + X_IDX] = XYZ[X_IDX]; + mc2p_fd_n[lidx + Y_IDX] = XYZ[Y_IDX]; + mc2p_fd_n[lidx + Z_IDX] = XYZ[Z_IDX]; - double bmag = sqrt(B[0]*B[0] + B[1]*B[1] + B[2]*B[2]); - bhat_fd_n[lidx+X_IDX] = B[X_IDX]/bmag; - bhat_fd_n[lidx+Y_IDX] = B[Y_IDX]/bmag; - bhat_fd_n[lidx+Z_IDX] = B[Z_IDX]/bmag; + double bmag = sqrt(B[0] * B[0] + B[1] * B[1] + B[2] * B[2]); + bhat_fd_n[lidx + X_IDX] = B[X_IDX] / bmag; + bhat_fd_n[lidx + Y_IDX] = B[Y_IDX] / bmag; + bhat_fd_n[lidx + Z_IDX] = B[Z_IDX] / bmag; - if(ip_delta==0 && ia_delta==0 && it_delta==0){ + if (ip_delta == 0 && ia_delta == 0 && it_delta == 0) { mc2p_n[X_IDX] = XYZ[X_IDX]; mc2p_n[Y_IDX] = XYZ[Y_IDX]; mc2p_n[Z_IDX] = XYZ[Z_IDX]; @@ -346,17 +419,16 @@ void gk_geometry_mapc2p_advance_surface(struct gk_geometry* up, int dir, struct } // Now calculate the metrics. - struct gkyl_calc_metric* mcalc = gkyl_calc_metric_new(&up->basis, &up->grid, - &up->global, &up->global_ext, &up->local, &up->local_ext, false, false); + struct gkyl_calc_metric *mcalc = gkyl_calc_metric_new( + &up->basis, &up->grid, &up->global, &up->global_ext, &up->local, &up->local_ext, false, false + ); gkyl_calc_metric_advance_surface(mcalc, dir, up); gkyl_calc_metric_release(mcalc); gk_geometry_surf_calc_expansions(up, dir, *nrange); } -struct gk_geometry* -gk_geometry_mapc2p_init(struct gkyl_gk_geometry_inp *geometry_inp) +struct gk_geometry *gk_geometry_mapc2p_init(struct gkyl_gk_geometry_inp *geometry_inp) { - struct gk_geometry *up = gkyl_malloc(sizeof(struct gk_geometry)); up->geometry_id = geometry_inp->geometry_id; up->basis = geometry_inp->geo_basis; @@ -375,16 +447,14 @@ gk_geometry_mapc2p_init(struct gkyl_gk_geometry_inp *geometry_inp) // Check that the split happens within the domain. assert((up->grid.lower[0] <= up->x_LCFS) && (up->x_LCFS <= up->grid.upper[0])); // Check that the split happens at a cell boundary; - double needint = (up->x_LCFS - up->grid.lower[0])/up->grid.dx[0]; - double rem_floor = fabs(needint-floor(needint)); - double rem_ceil = fabs(needint-ceil(needint)); + double needint = (up->x_LCFS - up->grid.lower[0]) / up->grid.dx[0]; + double rem_floor = fabs(needint - floor(needint)); + double rem_ceil = fabs(needint - ceil(needint)); if (rem_floor < 1.0e-12) { - up->idx_LCFS_lo = (int) floor(needint); - } - else if (rem_ceil < 1.0e-12) { - up->idx_LCFS_lo = (int) ceil(needint); - } - else { + up->idx_LCFS_lo = (int)floor(needint); + } else if (rem_ceil < 1.0e-12) { + up->idx_LCFS_lo = (int)ceil(needint); + } else { fprintf(stderr, "x_LCFS = %.9e must be at a cell boundary.\n", up->x_LCFS); assert(false); } @@ -393,13 +463,13 @@ gk_geometry_mapc2p_init(struct gkyl_gk_geometry_inp *geometry_inp) // Function pointers to twistshift function. up->parallel_lower_bc_shift_func = geometry_inp->parallel_lower_bc_shift_func; up->parallel_upper_bc_shift_func = geometry_inp->parallel_upper_bc_shift_func; - up->parallel_lower_bc_shift_ctx = geometry_inp->parallel_lower_bc_shift_ctx ; - up->parallel_upper_bc_shift_ctx = geometry_inp->parallel_upper_bc_shift_ctx ; + up->parallel_lower_bc_shift_ctx = geometry_inp->parallel_lower_bc_shift_ctx; + up->parallel_upper_bc_shift_ctx = geometry_inp->parallel_upper_bc_shift_ctx; - gk_geometry_set_nodal_ranges(up) ; + gk_geometry_set_nodal_ranges(up); // Initialize surface basis abd allocate surface geo - gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim-1, up->basis.poly_order); + gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim - 1, up->basis.poly_order); up->num_surf_basis = up->surf_basis.num_basis; // Allocate nodal and modal arrays for corner, interior, and surface geo @@ -407,7 +477,7 @@ gk_geometry_mapc2p_init(struct gkyl_gk_geometry_inp *geometry_inp) gk_geometry_corn_alloc_expansions(up); gk_geometry_int_alloc_nodal(up); gk_geometry_int_alloc_expansions(up); - for (int dir=0; dirgrid.ndim; ++dir) { + for (int dir = 0; dir < up->grid.ndim; ++dir) { gk_geometry_surf_alloc_nodal(up, dir); gk_geometry_surf_alloc_expansions(up, dir); } @@ -416,23 +486,29 @@ gk_geometry_mapc2p_init(struct gkyl_gk_geometry_inp *geometry_inp) // calculate mapc2p in cartesian coords at corner nodes for // getting cell coordinates (used only for plotting) - gk_geometry_mapc2p_advance(up, &up->nrange_corn, up->dzc, geometry_inp->mapc2p, geometry_inp->c2p_ctx, - geometry_inp->bfield_func, geometry_inp->bfield_ctx, geometry_inp->position_map); + gk_geometry_mapc2p_advance( + up, &up->nrange_corn, up->dzc, geometry_inp->mapc2p, geometry_inp->c2p_ctx, + geometry_inp->bfield_func, geometry_inp->bfield_ctx, geometry_inp->position_map + ); // calculate mapc2p in cartesian coords at interior nodes for - // calculating geo quantity volume expansions - gk_geometry_mapc2p_advance_interior(up, &up->nrange_int, up->dzc, geometry_inp->mapc2p, geometry_inp->c2p_ctx, - geometry_inp->bfield_func, geometry_inp->bfield_ctx, geometry_inp->position_map); + // calculating geo quantity volume expansions + gk_geometry_mapc2p_advance_interior( + up, &up->nrange_int, up->dzc, geometry_inp->mapc2p, geometry_inp->c2p_ctx, + geometry_inp->bfield_func, geometry_inp->bfield_ctx, geometry_inp->position_map + ); // calculate mapc2p in cylindrical coords at surfaces - for (int dir = 0; dir grid.ndim; dir++) { - gk_geometry_mapc2p_advance_surface(up, dir, &up->nrange_surf[dir], up->dzc, geometry_inp->mapc2p, - geometry_inp->c2p_ctx, geometry_inp->bfield_func, geometry_inp->bfield_ctx, geometry_inp->position_map); + for (int dir = 0; dir < up->grid.ndim; dir++) { + gk_geometry_mapc2p_advance_surface( + up, dir, &up->nrange_surf[dir], up->dzc, geometry_inp->mapc2p, geometry_inp->c2p_ctx, + geometry_inp->bfield_func, geometry_inp->bfield_ctx, geometry_inp->position_map + ); } // Store metadata for I/O. struct gkyl_msgpack_map_elem io_meta_basic[] = { - { .key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id }, + {.key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id} }; - up->io_meta_basic_len = sizeof(io_meta_basic)/sizeof(io_meta_basic[0]); + up->io_meta_basic_len = sizeof(io_meta_basic) / sizeof(io_meta_basic[0]); up->io_meta_basic = gkyl_msgpack_map_elem_clone(up->io_meta_basic_len, io_meta_basic); up->flags = 0; @@ -443,25 +519,26 @@ gk_geometry_mapc2p_init(struct gkyl_gk_geometry_inp *geometry_inp) return up; } -struct gk_geometry* -gkyl_gk_geometry_mapc2p_new(struct gkyl_gk_geometry_inp *geometry_inp) +struct gk_geometry *gkyl_gk_geometry_mapc2p_new(struct gkyl_gk_geometry_inp *geometry_inp) { - struct gk_geometry* gk_geom_3d; - struct gk_geometry* gk_geom; + struct gk_geometry *gk_geom_3d; + struct gk_geometry *gk_geom; // First construct the uniform 3d geometry gk_geom_3d = gk_geometry_mapc2p_init(geometry_inp); - if (geometry_inp->position_map->id == GKYL_PMAP_CONSTANT_DB_POLYNOMIAL || \ + if (geometry_inp->position_map->id == GKYL_PMAP_CONSTANT_DB_POLYNOMIAL || geometry_inp->position_map->id == GKYL_PMAP_CONSTANT_DB_NUMERIC) { // The array mc2nu is computed using the uniform geometry, so we need to deflate it // Must deflate the 3D uniform geometry in order for the allgather to work - if (geometry_inp->grid.ndim < 3) + if (geometry_inp->grid.ndim < 3) { gk_geom = gkyl_gk_geometry_deflate(gk_geom_3d, geometry_inp); - else + } else { gk_geom = gkyl_gk_geometry_acquire(gk_geom_3d); + } - gkyl_position_map_set_bmag(geometry_inp->position_map, geometry_inp->comm, \ - gk_geom->geo_int.bmag); + gkyl_position_map_set_bmag( + geometry_inp->position_map, geometry_inp->comm, gk_geom->geo_int.bmag + ); gkyl_gk_geometry_release(gk_geom_3d); // release temporary 3d geometry gkyl_gk_geometry_release(gk_geom); // release 3d geometry diff --git a/gyrokinetic/zero/gk_geometry_mirror.c b/gyrokinetic/zero/gk_geometry_mirror.c index 74f8ab5d8d..dee540da52 100644 --- a/gyrokinetic/zero/gk_geometry_mirror.c +++ b/gyrokinetic/zero/gk_geometry_mirror.c @@ -10,8 +10,7 @@ #include #include -struct gk_geometry* -gk_geometry_mirror_init(struct gkyl_gk_geometry_inp *geometry_inp) +struct gk_geometry *gk_geometry_mirror_init(struct gkyl_gk_geometry_inp *geometry_inp) { struct gk_geometry *up = gkyl_malloc(sizeof(struct gk_geometry)); up->geometry_id = geometry_inp->geometry_id; @@ -21,32 +20,36 @@ gk_geometry_mirror_init(struct gkyl_gk_geometry_inp *geometry_inp) up->global = geometry_inp->geo_global; up->global_ext = geometry_inp->geo_global_ext; up->grid = geometry_inp->geo_grid; - up->geqdsk_sign_convention = 0.0; // Hardcoded 0. Means psi increases from axis. Always true for mirror geometry. + up->geqdsk_sign_convention = + 0.0; // Hardcoded 0. Means psi increases from axis. Always true for mirror geometry. up->half_domain = 0; up->has_LCFS = false; // MF 2025/09/19: Hardcodded for now. // Initialize nodal ranges for corner, interior, and surface geometry - gk_geometry_set_nodal_ranges(up) ; + gk_geometry_set_nodal_ranges(up); // Initialize surface basis - gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim-1, up->basis.poly_order); + gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim - 1, up->basis.poly_order); up->num_surf_basis = up->surf_basis.num_basis; // Allocate nodal and modal arrays for corner, interior, and surface geo gk_geometry_corn_alloc_nodal(up); gk_geometry_corn_alloc_expansions(up); gk_geometry_int_alloc_nodal(up); gk_geometry_int_alloc_expansions(up); - for (int dir=0; dirgrid.ndim; ++dir) { + for (int dir = 0; dir < up->grid.ndim; ++dir) { gk_geometry_surf_alloc_nodal(up, dir); gk_geometry_surf_alloc_expansions(up, dir); } // read psi(R,Z) from file struct gkyl_rect_grid psi_grid; - struct gkyl_array *psi = gkyl_grid_array_new_from_file(&psi_grid, geometry_inp->mirror_grid_info.filename_psi); + struct gkyl_array *psi = + gkyl_grid_array_new_from_file(&psi_grid, geometry_inp->mirror_grid_info.filename_psi); // Check if file exists using gkyl_check_file_exists and handle error only on rank 0 if (!gkyl_check_file_exists(geometry_inp->mirror_grid_info.filename_psi)) { - fprintf(stderr, "Failed to open the eqdsk file: %s\n", geometry_inp->mirror_grid_info.filename_psi); + fprintf( + stderr, "Failed to open the eqdsk file: %s\n", geometry_inp->mirror_grid_info.filename_psi + ); assert(false); } @@ -54,103 +57,104 @@ gk_geometry_mirror_init(struct gkyl_gk_geometry_inp *geometry_inp) // Create mirror geometry for corners. struct gkyl_mirror_grid_gen *mirror_grid_corn = - gkyl_mirror_grid_gen_inew(&(struct gkyl_mirror_grid_gen_inp) { - .comp_grid = &up->grid, - .nrange = up->nrange_corn, - .local = up->local, - .global = up->global, - .position_map = geometry_inp->position_map, - - .R = { psi_grid.lower[0], psi_grid.upper[0] }, - .Z = { psi_grid.lower[1], psi_grid.upper[1] }, - - // psi(R,Z) grid size - .nrcells = psi_grid.cells[0]-1, // Cells and not nodes. - .nzcells = psi_grid.cells[1]-1, // Cells and not nodes. - - .psiRZ = psi, - .fl_coord = geometry_inp->mirror_grid_info.fl_coord, - .include_axis = geometry_inp->mirror_grid_info.include_axis, - .write_psi_cubic = false, - } - ); + gkyl_mirror_grid_gen_inew(&(struct gkyl_mirror_grid_gen_inp + ){.comp_grid = &up->grid, + .nrange = up->nrange_corn, + .local = up->local, + .global = up->global, + .position_map = geometry_inp->position_map, + + .R = {psi_grid.lower[0], psi_grid.upper[0]}, + .Z = {psi_grid.lower[1], psi_grid.upper[1]}, + + // psi(R,Z) grid size + .nrcells = psi_grid.cells[0] - 1, // Cells and not nodes. + .nzcells = psi_grid.cells[1] - 1, // Cells and not nodes. + + .psiRZ = psi, + .fl_coord = geometry_inp->mirror_grid_info.fl_coord, + .include_axis = geometry_inp->mirror_grid_info.include_axis, + .write_psi_cubic = false}); // Create mirror geometry for interior. struct gkyl_mirror_grid_gen *mirror_grid_int = - gkyl_mirror_grid_gen_int_inew(&(struct gkyl_mirror_grid_gen_inp) { - .comp_grid = &up->grid, - .nrange = up->nrange_int, - .local = up->local, - .global = up->global, - .position_map = geometry_inp->position_map, - - .R = { psi_grid.lower[0], psi_grid.upper[0] }, - .Z = { psi_grid.lower[1], psi_grid.upper[1] }, - - // psi(R,Z) grid size. - .nrcells = psi_grid.cells[0]-1, // Cells and not nodes. - .nzcells = psi_grid.cells[1]-1, // Cells and not nodes. - - .psiRZ = psi, - .fl_coord = geometry_inp->mirror_grid_info.fl_coord, - .include_axis = geometry_inp->mirror_grid_info.include_axis, - .write_psi_cubic = false, - } - ); + gkyl_mirror_grid_gen_int_inew(&(struct gkyl_mirror_grid_gen_inp + ){.comp_grid = &up->grid, + .nrange = up->nrange_int, + .local = up->local, + .global = up->global, + .position_map = geometry_inp->position_map, + + .R = {psi_grid.lower[0], psi_grid.upper[0]}, + .Z = {psi_grid.lower[1], psi_grid.upper[1]}, + + // psi(R,Z) grid size. + .nrcells = psi_grid.cells[0] - 1, // Cells and not nodes. + .nzcells = psi_grid.cells[1] - 1, // Cells and not nodes. + + .psiRZ = psi, + .fl_coord = geometry_inp->mirror_grid_info.fl_coord, + .include_axis = geometry_inp->mirror_grid_info.include_axis, + .write_psi_cubic = false}); // create mirror geometry for surfaces struct gkyl_mirror_grid_gen *mirror_grid_surf[3]; - for (int dir = 0; dir grid.ndim; dir++) { - mirror_grid_surf[dir] = - gkyl_mirror_grid_gen_surf_inew(&(struct gkyl_mirror_grid_gen_inp) { - .comp_grid = &up->grid, - .nrange = up->nrange_surf[dir], - .local = up->local, - .global = up->global, - .dir = dir, - .position_map = geometry_inp->position_map, - - .R = { psi_grid.lower[0], psi_grid.upper[0] }, - .Z = { psi_grid.lower[1], psi_grid.upper[1] }, - - // psi(R,Z) grid size. - .nrcells = psi_grid.cells[0]-1, // Cells and not nodes. - .nzcells = psi_grid.cells[1]-1, // Cells and not nodes. - - .psiRZ = psi, - .fl_coord = geometry_inp->mirror_grid_info.fl_coord, - .include_axis = geometry_inp->mirror_grid_info.include_axis, - .write_psi_cubic = false, - } - ); + for (int dir = 0; dir < up->grid.ndim; dir++) { + mirror_grid_surf[dir] = gkyl_mirror_grid_gen_surf_inew(&(struct gkyl_mirror_grid_gen_inp + ){.comp_grid = &up->grid, + .nrange = up->nrange_surf[dir], + .local = up->local, + .global = up->global, + .dir = dir, + .position_map = geometry_inp->position_map, + + .R = {psi_grid.lower[0], psi_grid.upper[0]}, + .Z = {psi_grid.lower[1], psi_grid.upper[1]}, + + // psi(R,Z) grid size. + .nrcells = psi_grid.cells[0] - 1, // Cells and not nodes. + .nzcells = psi_grid.cells[1] - 1, // Cells and not nodes. + + .psiRZ = psi, + .fl_coord = geometry_inp->mirror_grid_info.fl_coord, + .include_axis = geometry_inp->mirror_grid_info.include_axis, + .write_psi_cubic = false}); } // Now calculate the derived geometric coefficients at necessary nodes and compute modal expansions where required. // Now calculate the metrics at corner and interior nodes. - struct gkyl_calc_metric_mirror* mcalc = gkyl_calc_metric_mirror_new(&up->basis, &up->grid, &up->local, &up->local_ext, false); + struct gkyl_calc_metric_mirror *mcalc = + gkyl_calc_metric_mirror_new(&up->basis, &up->grid, &up->local, &up->local_ext, false); gkyl_calc_metric_mirror_advance(mcalc, up, mirror_grid_corn); gkyl_calc_metric_mirror_advance_interior(mcalc, up, mirror_grid_int); // Calculate the derived geometric quantities at interior nodes. - gkyl_rz_calc_derived_geo *jcalculator = gkyl_rz_calc_derived_geo_new(&up->basis, &up->grid, 1, false); - gkyl_rz_calc_derived_geo_advance(jcalculator, &up->local, up->geo_int.g_ij, up->geo_int.bmag, - up->geo_int.jacobgeo, up->geo_int.jacobgeo_inv, up->geo_int.gij, up->geo_int.b_i, up->geo_int.cmag, up->geo_int.jacobtot, - up->geo_int.jacobtot_inv, up->geo_int.gxxj, up->geo_int.gxyj, up->geo_int.gyyj, up->geo_int.gxzj, up->geo_int.eps2); + gkyl_rz_calc_derived_geo *jcalculator = + gkyl_rz_calc_derived_geo_new(&up->basis, &up->grid, 1, false); + gkyl_rz_calc_derived_geo_advance( + jcalculator, &up->local, up->geo_int.g_ij, up->geo_int.bmag, up->geo_int.jacobgeo, + up->geo_int.jacobgeo_inv, up->geo_int.gij, up->geo_int.b_i, up->geo_int.cmag, + up->geo_int.jacobtot, up->geo_int.jacobtot_inv, up->geo_int.gxxj, up->geo_int.gxyj, + up->geo_int.gyyj, up->geo_int.gxzj, up->geo_int.eps2 + ); gkyl_rz_calc_derived_geo_release(jcalculator); // Calculate metrics/derived geo quantities at surface. - for (int dir = 0; dir grid.ndim; dir++) { - gkyl_calc_metric_mirror_advance_surface(mcalc, dir, up, mirror_grid_surf[dir]); + for (int dir = 0; dir < up->grid.ndim; dir++) { + gkyl_calc_metric_mirror_advance_surface(mcalc, dir, up, mirror_grid_surf[dir]); } gkyl_calc_metric_mirror_release(mcalc); // Calculate surface expansions. - for (int dir = 0; dir grid.ndim; dir++) + for (int dir = 0; dir < up->grid.ndim; dir++) { gk_geometry_surf_calc_expansions(up, dir, up->nrange_surf[dir]); + } // Store metadata for I/O. struct gkyl_msgpack_map_elem io_meta_basic[] = { - { .key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id }, - { .key = "geqdsk_sign_convention", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geqdsk_sign_convention }, + {.key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id}, + {.key = "geqdsk_sign_convention", + .elem_type = GKYL_MP_UNSIGNED_INT, + .uval = up->geqdsk_sign_convention} }; - up->io_meta_basic_len = sizeof(io_meta_basic)/sizeof(io_meta_basic[0]); + up->io_meta_basic_len = sizeof(io_meta_basic) / sizeof(io_meta_basic[0]); up->io_meta_basic = gkyl_msgpack_map_elem_clone(up->io_meta_basic_len, io_meta_basic); up->flags = 0; @@ -160,32 +164,34 @@ gk_geometry_mirror_init(struct gkyl_gk_geometry_inp *geometry_inp) gkyl_mirror_grid_gen_release(mirror_grid_corn); gkyl_mirror_grid_gen_release(mirror_grid_int); - for (int dir = 0; dir grid.ndim; dir++) + for (int dir = 0; dir < up->grid.ndim; dir++) { gkyl_mirror_grid_gen_release(mirror_grid_surf[dir]); + } gkyl_array_release(psi); return up; } -struct gk_geometry* -gkyl_gk_geometry_mirror_new(struct gkyl_gk_geometry_inp *geometry_inp) +struct gk_geometry *gkyl_gk_geometry_mirror_new(struct gkyl_gk_geometry_inp *geometry_inp) { - struct gk_geometry* gk_geom_3d; - struct gk_geometry* gk_geom; + struct gk_geometry *gk_geom_3d; + struct gk_geometry *gk_geom; // First construct the uniform 3d geometry gk_geom_3d = gk_geometry_mirror_init(geometry_inp); - if (geometry_inp->position_map->id == GKYL_PMAP_CONSTANT_DB_POLYNOMIAL || \ + if (geometry_inp->position_map->id == GKYL_PMAP_CONSTANT_DB_POLYNOMIAL || geometry_inp->position_map->id == GKYL_PMAP_CONSTANT_DB_NUMERIC) { // The array mc2nu is computed using the uniform geometry, so we need to deflate it // Must deflate the 3D uniform geometry in order for the allgather to work - if(geometry_inp->grid.ndim < 3) + if (geometry_inp->grid.ndim < 3) { gk_geom = gkyl_gk_geometry_deflate(gk_geom_3d, geometry_inp); - else + } else { gk_geom = gkyl_gk_geometry_acquire(gk_geom_3d); + } - gkyl_position_map_set_bmag(geometry_inp->position_map, geometry_inp->comm, \ - gk_geom->geo_int.bmag); + gkyl_position_map_set_bmag( + geometry_inp->position_map, geometry_inp->comm, gk_geom->geo_int.bmag + ); gkyl_gk_geometry_release(gk_geom_3d); // release temporary 3d geometry gkyl_gk_geometry_release(gk_geom); // release 3d geometry diff --git a/gyrokinetic/zero/gk_geometry_tok.c b/gyrokinetic/zero/gk_geometry_tok.c index a56304a218..464d629db2 100644 --- a/gyrokinetic/zero/gk_geometry_tok.c +++ b/gyrokinetic/zero/gk_geometry_tok.c @@ -18,11 +18,9 @@ #include #include -struct gk_geometry* -gk_geometry_tok_init(struct gkyl_gk_geometry_inp *geometry_inp) +struct gk_geometry *gk_geometry_tok_init(struct gkyl_gk_geometry_inp *geometry_inp) { - - struct gk_geometry *up = gkyl_calloc(1,sizeof(struct gk_geometry)); + struct gk_geometry *up = gkyl_calloc(1, sizeof(struct gk_geometry)); up->geometry_id = geometry_inp->geometry_id; up->basis = geometry_inp->geo_basis; up->local = geometry_inp->geo_local; @@ -36,25 +34,23 @@ gk_geometry_tok_init(struct gkyl_gk_geometry_inp *geometry_inp) // Check that the split happens within the domain. assert((up->grid.lower[0] <= up->x_LCFS) && (up->x_LCFS <= up->grid.upper[0])); // Check that the split happens at a cell boundary; - double needint = (up->x_LCFS - up->grid.lower[0])/up->grid.dx[0]; - double rem_floor = fabs(needint-floor(needint)); - double rem_ceil = fabs(needint-ceil(needint)); + double needint = (up->x_LCFS - up->grid.lower[0]) / up->grid.dx[0]; + double rem_floor = fabs(needint - floor(needint)); + double rem_ceil = fabs(needint - ceil(needint)); if (rem_floor < 1.0e-12) { - up->idx_LCFS_lo = (int) floor(needint); - } - else if (rem_ceil < 1.0e-12) { - up->idx_LCFS_lo = (int) ceil(needint); - } - else { + up->idx_LCFS_lo = (int)floor(needint); + } else if (rem_ceil < 1.0e-12) { + up->idx_LCFS_lo = (int)ceil(needint); + } else { fprintf(stderr, "x_LCFS = %.9e must be at a cell boundary.\n", up->x_LCFS); assert(false); } } - gk_geometry_set_nodal_ranges(up) ; + gk_geometry_set_nodal_ranges(up); // Initialize surface basis - gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim-1, up->basis.poly_order); + gkyl_cart_modal_serendip(&up->surf_basis, up->grid.ndim - 1, up->basis.poly_order); up->num_surf_basis = up->surf_basis.num_basis; // Initialize tokamak geometry object from EFIT @@ -71,7 +67,7 @@ gk_geometry_tok_init(struct gkyl_gk_geometry_inp *geometry_inp) gk_geometry_corn_alloc_expansions(up); gk_geometry_int_alloc_nodal(up); gk_geometry_int_alloc_expansions(up); - for (int dir=0; dirgrid.ndim; ++dir) { + for (int dir = 0; dir < up->grid.ndim; ++dir) { gk_geometry_surf_alloc_nodal(up, dir); gk_geometry_surf_alloc_expansions(up, dir); } @@ -85,41 +81,52 @@ gk_geometry_tok_init(struct gkyl_gk_geometry_inp *geometry_inp) // calculating geo quantity volume expansions. gkyl_tok_geo_calc_interior(up, &up->nrange_int, up->dzc, geo, &ginp, geometry_inp->position_map); // Calculate bmag and mapc2p in cylindrical coords at surfaces. - for (int dir = 0; dir grid.ndim; dir++) - gkyl_tok_geo_calc_surface(up, dir, &up->nrange_surf[dir], up->dzc, geo, &ginp, geometry_inp->position_map); + for (int dir = 0; dir < up->grid.ndim; dir++) { + gkyl_tok_geo_calc_surface( + up, dir, &up->nrange_surf[dir], up->dzc, geo, &ginp, geometry_inp->position_map + ); + } // Now calculate the metrics at interior nodes. - struct gkyl_calc_metric* mcalc = gkyl_calc_metric_new(&up->basis, &up->grid, - &up->global, &up->global_ext, &up->local, &up->local_ext, true, false); + struct gkyl_calc_metric *mcalc = gkyl_calc_metric_new( + &up->basis, &up->grid, &up->global, &up->global_ext, &up->local, &up->local_ext, true, false + ); gkyl_calc_metric_advance_rz_interior(mcalc, up); gkyl_array_copy(up->geo_int.jacobgeo_ghost, up->geo_int.jacobgeo); // Calculate neutral metrics at interior nodes. gkyl_calc_metric_advance_rz_neut_interior(mcalc, up); // Calculate the derived geometric quantities at interior nodes. - gkyl_rz_calc_derived_geo *jcalculator = gkyl_rz_calc_derived_geo_new(&up->basis, &up->grid, 1, false); - gkyl_rz_calc_derived_geo_advance(jcalculator, &up->local, up->geo_int.g_ij, up->geo_int.bmag, - up->geo_int.jacobgeo, up->geo_int.jacobgeo_inv, up->geo_int.gij, up->geo_int.b_i, up->geo_int.cmag, up->geo_int.jacobtot, - up->geo_int.jacobtot_inv, up->geo_int.gxxj, up->geo_int.gxyj, up->geo_int.gyyj, up->geo_int.gxzj, up->geo_int.eps2); + gkyl_rz_calc_derived_geo *jcalculator = + gkyl_rz_calc_derived_geo_new(&up->basis, &up->grid, 1, false); + gkyl_rz_calc_derived_geo_advance( + jcalculator, &up->local, up->geo_int.g_ij, up->geo_int.bmag, up->geo_int.jacobgeo, + up->geo_int.jacobgeo_inv, up->geo_int.gij, up->geo_int.b_i, up->geo_int.cmag, + up->geo_int.jacobtot, up->geo_int.jacobtot_inv, up->geo_int.gxxj, up->geo_int.gxyj, + up->geo_int.gyyj, up->geo_int.gxzj, up->geo_int.eps2 + ); gkyl_rz_calc_derived_geo_release(jcalculator); // Calculate metrics/derived geo quantities at surface. - for (int dir = 0; dir grid.ndim; dir++) { - gkyl_calc_metric_advance_rz_surface(mcalc, dir, up); + for (int dir = 0; dir < up->grid.ndim; dir++) { + gkyl_calc_metric_advance_rz_surface(mcalc, dir, up); } gkyl_calc_metric_release(mcalc); // Calculate surface expansions. - for (int dir = 0; dir grid.ndim; dir++) + for (int dir = 0; dir < up->grid.ndim; dir++) { gk_geometry_surf_calc_expansions(up, dir, up->nrange_surf[dir]); + } // Store metadata for I/O. char geqdsk_file_name[128]; get_filename_from_path(geo->efit->filepath, geqdsk_file_name, sizeof(geqdsk_file_name)); struct gkyl_msgpack_map_elem io_meta_basic[] = { - { .key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id }, - { .key = "geqdsk_sign_convention", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geqdsk_sign_convention }, - { .key = "geqdsk_file", .elem_type = GKYL_MP_STRING, .cval = geqdsk_file_name}, - { .key = "half_domain", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->half_domain }, + {.key = "geometry_type", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->geometry_id}, + {.key = "geqdsk_sign_convention", + .elem_type = GKYL_MP_UNSIGNED_INT, + .uval = up->geqdsk_sign_convention}, + {.key = "geqdsk_file", .elem_type = GKYL_MP_STRING, .cval = geqdsk_file_name}, + {.key = "half_domain", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = up->half_domain} }; - up->io_meta_basic_len = sizeof(io_meta_basic)/sizeof(io_meta_basic[0]); + up->io_meta_basic_len = sizeof(io_meta_basic) / sizeof(io_meta_basic[0]); up->io_meta_basic = gkyl_msgpack_map_elem_clone(up->io_meta_basic_len, io_meta_basic); up->flags = 0; @@ -132,57 +139,62 @@ gk_geometry_tok_init(struct gkyl_gk_geometry_inp *geometry_inp) return up; } -struct gk_geometry* -gkyl_gk_geometry_tok_new(struct gkyl_gk_geometry_inp *geometry_inp) +struct gk_geometry *gkyl_gk_geometry_tok_new(struct gkyl_gk_geometry_inp *geometry_inp) { - struct gk_geometry* gk_geom_3d; - struct gk_geometry* gk_geom; + struct gk_geometry *gk_geom_3d; + struct gk_geometry *gk_geom; if (geometry_inp->position_map->id == GKYL_PMAP_XPT_COMPRESSION) { double zcenter, zcut, len; - switch(geometry_inp->tok_grid_info.ftype) - { - case GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID: - case GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID: - len = geometry_inp->tok_grid_info.half_domain ? 2.0*(geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]) - : geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]; - zcut = len/2.0; - zcenter = 0.0; - break; - case GKYL_GEOMETRY_TOKAMAK_CORE_R: - case GKYL_GEOMETRY_TOKAMAK_CORE: - case GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID: - len = geometry_inp->tok_grid_info.half_domain ? 2.0*(geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]) - : geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]; - zcenter = geometry_inp->geo_grid.lower[2] + len/2.0; - zcut = len/2.0; - break; - case GKYL_GEOMETRY_TOKAMAK_CORE_L: - len = geometry_inp->tok_grid_info.half_domain ? 2.0*(geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]) - : geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]; - zcenter = geometry_inp->geo_grid.upper[2] - len/2.0; - zcut = len/2.0; - break; - case GKYL_GEOMETRY_TOKAMAK_PF_LO_R: - case GKYL_GEOMETRY_TOKAMAK_PF_UP_L: - case GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO: - case GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP: - case GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO: - len = geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]; - zcenter = geometry_inp->position_map->xpt_ctx->compress_divertor ? geometry_inp->geo_grid.lower[2] + len/2.0 : geometry_inp->geo_grid.lower[2]; - zcut = geometry_inp->position_map->xpt_ctx->compress_divertor ? len/2.0 : len; - break; - case GKYL_GEOMETRY_TOKAMAK_PF_LO_L: - case GKYL_GEOMETRY_TOKAMAK_PF_UP_R: - case GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP: - case GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO: - case GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP: - len = geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]; - zcenter = geometry_inp->position_map->xpt_ctx->compress_divertor ? geometry_inp->geo_grid.upper[2] - len/2.0 : geometry_inp->geo_grid.upper[2]; - zcut = geometry_inp->position_map->xpt_ctx->compress_divertor ? len/2.0 : len; - break; - default: - break; + switch (geometry_inp->tok_grid_info.ftype) { + case GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID: + case GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID: + len = geometry_inp->tok_grid_info.half_domain ? + 2.0 * (geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]) : + geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]; + zcut = len / 2.0; + zcenter = 0.0; + break; + case GKYL_GEOMETRY_TOKAMAK_CORE_R: + case GKYL_GEOMETRY_TOKAMAK_CORE: + case GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID: + len = geometry_inp->tok_grid_info.half_domain ? + 2.0 * (geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]) : + geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]; + zcenter = geometry_inp->geo_grid.lower[2] + len / 2.0; + zcut = len / 2.0; + break; + case GKYL_GEOMETRY_TOKAMAK_CORE_L: + len = geometry_inp->tok_grid_info.half_domain ? + 2.0 * (geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]) : + geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]; + zcenter = geometry_inp->geo_grid.upper[2] - len / 2.0; + zcut = len / 2.0; + break; + case GKYL_GEOMETRY_TOKAMAK_PF_LO_R: + case GKYL_GEOMETRY_TOKAMAK_PF_UP_L: + case GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO: + case GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP: + case GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO: + len = geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]; + zcenter = geometry_inp->position_map->xpt_ctx->compress_divertor ? + geometry_inp->geo_grid.lower[2] + len / 2.0 : + geometry_inp->geo_grid.lower[2]; + zcut = geometry_inp->position_map->xpt_ctx->compress_divertor ? len / 2.0 : len; + break; + case GKYL_GEOMETRY_TOKAMAK_PF_LO_L: + case GKYL_GEOMETRY_TOKAMAK_PF_UP_R: + case GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP: + case GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO: + case GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP: + len = geometry_inp->geo_grid.upper[2] - geometry_inp->geo_grid.lower[2]; + zcenter = geometry_inp->position_map->xpt_ctx->compress_divertor ? + geometry_inp->geo_grid.upper[2] - len / 2.0 : + geometry_inp->geo_grid.upper[2]; + zcut = geometry_inp->position_map->xpt_ctx->compress_divertor ? len / 2.0 : len; + break; + default: + break; } double w = geometry_inp->geo_grid.upper[0] - geometry_inp->geo_grid.lower[0]; @@ -190,20 +202,21 @@ gkyl_gk_geometry_tok_new(struct gkyl_gk_geometry_inp *geometry_inp) double psisep = efit->psisep; gkyl_efit_release(efit); gkyl_position_map_set_compression(geometry_inp->position_map, zcut, zcenter, w, psisep); - } - else if (geometry_inp->position_map->id == GKYL_PMAP_CONSTANT_DB_POLYNOMIAL || \ - geometry_inp->position_map->id == GKYL_PMAP_CONSTANT_DB_NUMERIC) { + } else if (geometry_inp->position_map->id == GKYL_PMAP_CONSTANT_DB_POLYNOMIAL || + geometry_inp->position_map->id == GKYL_PMAP_CONSTANT_DB_NUMERIC) { // First construct the uniform 3d geometry gk_geom_3d = gk_geometry_tok_init(geometry_inp); // The array mc2nu is computed using the uniform geometry, so we need to deflate it // Must deflate the 3D uniform geometry in order for the allgather to work - if(geometry_inp->grid.ndim < 3) + if (geometry_inp->grid.ndim < 3) { gk_geom = gkyl_gk_geometry_deflate(gk_geom_3d, geometry_inp); - else + } else { gk_geom = gkyl_gk_geometry_acquire(gk_geom_3d); + } - gkyl_position_map_set_bmag(geometry_inp->position_map, geometry_inp->comm, \ - gk_geom->geo_int.bmag); + gkyl_position_map_set_bmag( + geometry_inp->position_map, geometry_inp->comm, gk_geom->geo_int.bmag + ); gkyl_gk_geometry_release(gk_geom_3d); // release temporary 3d geometry gkyl_gk_geometry_release(gk_geom); // release 3d geometry @@ -213,9 +226,11 @@ gkyl_gk_geometry_tok_new(struct gkyl_gk_geometry_inp *geometry_inp) return gk_geom_3d; } - -void -gkyl_gk_geometry_tok_set_grid_extents(struct gkyl_efit_inp efit_info, struct gkyl_tok_geo_grid_inp grid_info, double *theta_lo, double *theta_up) { +void gkyl_gk_geometry_tok_set_grid_extents( + struct gkyl_efit_inp efit_info, struct gkyl_tok_geo_grid_inp grid_info, double *theta_lo, + double *theta_up +) +{ struct gkyl_tok_geo *geo = gkyl_tok_geo_new(&efit_info, &grid_info); gkyl_tok_geo_set_extent(&grid_info, geo, theta_lo, theta_up); gkyl_tok_geo_release(geo); diff --git a/gyrokinetic/zero/gk_maxwellian_correct.c b/gyrokinetic/zero/gk_maxwellian_correct.c index c28e122efa..81d84dfb16 100644 --- a/gyrokinetic/zero/gk_maxwellian_correct.c +++ b/gyrokinetic/zero/gk_maxwellian_correct.c @@ -13,7 +13,7 @@ #include -struct gkyl_gk_maxwellian_correct* +struct gkyl_gk_maxwellian_correct * gkyl_gk_maxwellian_correct_inew(const struct gkyl_gk_maxwellian_correct_inp *inp) { gkyl_gk_maxwellian_correct *up = gkyl_malloc(sizeof(*up)); @@ -23,7 +23,7 @@ gkyl_gk_maxwellian_correct_inew(const struct gkyl_gk_maxwellian_correct_inp *inp up->use_gpu = inp->use_gpu; up->num_conf_basis = inp->conf_basis->num_basis; - + long conf_range_ncells = inp->conf_range->volume; long conf_range_ext_ncells = inp->conf_range_ext->volume; @@ -34,39 +34,47 @@ gkyl_gk_maxwellian_correct_inew(const struct gkyl_gk_maxwellian_correct_inp *inp } // Individual moment memory: the iteration of the moments, the differences (d) and differences of differences (dd) - // In the gyrokinetic system, we are correcting three moments for Maxwellian corrections: n, u_par, T/m + // In the gyrokinetic system, we are correcting three moments for Maxwellian corrections: n, u_par, T/m // or if we are correcting a BiMaxwellian, we correct four moments: n, u_par, T_par/m, T_perp/m if (up->use_gpu) { - up->moms_iter = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_comp*inp->conf_basis->num_basis, conf_range_ext_ncells); - up->d_moms = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_comp*inp->conf_basis->num_basis, conf_range_ext_ncells); - up->dd_moms = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_comp*inp->conf_basis->num_basis, conf_range_ext_ncells); - // Two additional GPU-specific allocations for iterating over the grid to find the absolute value of + up->moms_iter = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->num_comp * inp->conf_basis->num_basis, conf_range_ext_ncells + ); + up->d_moms = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->num_comp * inp->conf_basis->num_basis, conf_range_ext_ncells + ); + up->dd_moms = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->num_comp * inp->conf_basis->num_basis, conf_range_ext_ncells + ); + // Two additional GPU-specific allocations for iterating over the grid to find the absolute value of // the difference between the target and iterative moments, and the GPU-side array for performing the // thread-safe reduction to find the maximum error on the grid. up->abs_diff_moms = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_comp, conf_range_ext_ncells); up->error_cu = gkyl_cu_malloc(sizeof(double[up->num_comp])); - } - else { - up->moms_iter = gkyl_array_new(GKYL_DOUBLE, up->num_comp*inp->conf_basis->num_basis, conf_range_ext_ncells); - up->d_moms = gkyl_array_new(GKYL_DOUBLE, up->num_comp*inp->conf_basis->num_basis, conf_range_ext_ncells); - up->dd_moms = gkyl_array_new(GKYL_DOUBLE, up->num_comp*inp->conf_basis->num_basis, conf_range_ext_ncells); + } else { + up->moms_iter = + gkyl_array_new(GKYL_DOUBLE, up->num_comp * inp->conf_basis->num_basis, conf_range_ext_ncells); + up->d_moms = + gkyl_array_new(GKYL_DOUBLE, up->num_comp * inp->conf_basis->num_basis, conf_range_ext_ncells); + up->dd_moms = + gkyl_array_new(GKYL_DOUBLE, up->num_comp * inp->conf_basis->num_basis, conf_range_ext_ncells); } up->error = gkyl_malloc(sizeof(double[up->num_comp])); - // Moments structure + // Moments structure struct gkyl_gk_maxwellian_moments_inp inp_mom = { .phase_grid = inp->phase_grid, .conf_basis = inp->conf_basis, .phase_basis = inp->phase_basis, - .conf_range = inp->conf_range, + .conf_range = inp->conf_range, .conf_range_ext = inp->conf_range_ext, - .mass = inp->mass, - .gk_geom = inp->gk_geom, + .mass = inp->mass, + .gk_geom = inp->gk_geom, .vel_map = inp->vel_map, - .divide_jacobgeo = inp->divide_jacobgeo, - .use_gpu = inp->use_gpu, + .divide_jacobgeo = inp->divide_jacobgeo, + .use_gpu = inp->use_gpu }; - up->moments_up = gkyl_gk_maxwellian_moments_inew( &inp_mom ); + up->moments_up = gkyl_gk_maxwellian_moments_inew(&inp_mom); // Create a projection updater for projecting the gyrokinetic Maxwellian or bi-Maxwellian struct gkyl_gk_maxwellian_proj_on_basis_inp inp_proj = { @@ -76,26 +84,26 @@ gkyl_gk_maxwellian_correct_inew(const struct gkyl_gk_maxwellian_correct_inp *inp .conf_range = inp->conf_range, .conf_range_ext = inp->conf_range_ext, .vel_range = inp->vel_range, - .gk_geom = inp->gk_geom, + .gk_geom = inp->gk_geom, .vel_map = inp->vel_map, - .mass = inp->mass, - .bimaxwellian = inp->bimaxwellian, - .divide_jacobgeo = inp->divide_jacobgeo, - .use_gpu = inp->use_gpu, + .mass = inp->mass, + .bimaxwellian = inp->bimaxwellian, + .divide_jacobgeo = inp->divide_jacobgeo, + .use_gpu = inp->use_gpu }; up->proj_max = gkyl_gk_maxwellian_proj_on_basis_inew(&inp_proj); return up; } -struct gkyl_gk_maxwellian_correct_status -gkyl_gk_maxwellian_correct_all_moments(gkyl_gk_maxwellian_correct *up, - struct gkyl_array *f_max, const struct gkyl_array *moms_target, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range) +struct gkyl_gk_maxwellian_correct_status gkyl_gk_maxwellian_correct_all_moments( + gkyl_gk_maxwellian_correct *up, struct gkyl_array *f_max, const struct gkyl_array *moms_target, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_range +) { int num_comp = up->num_comp; int nc = up->num_conf_basis; - double tol = up->eps; // tolerance of the iterative scheme + double tol = up->eps; // tolerance of the iterative scheme int max_iter = up->max_iter; int niter = 0; @@ -104,7 +112,7 @@ gkyl_gk_maxwellian_correct_all_moments(gkyl_gk_maxwellian_correct *up, // Set initial max error to start the iteration. double max_error = 1.0; - for (int i=0; ierror[i] = 1.0; } // Copy the initial max error to GPU so initial error is set correctly (no uninitialized values). @@ -121,12 +129,13 @@ gkyl_gk_maxwellian_correct_all_moments(gkyl_gk_maxwellian_correct *up, // 1. Calculate the needed moments from the projected distribution // either Maxwellian (n, u_par, T/m) or bi-Maxwellian (n, u_par, Tpar/m, Tperp/m) moments if (up->bimaxwellian) { - gkyl_gk_bimaxwellian_moments_advance(up->moments_up, phase_range, conf_range, - f_max, up->moms_iter); - } - else { - gkyl_gk_maxwellian_moments_advance(up->moments_up, phase_range, conf_range, - f_max, up->moms_iter); + gkyl_gk_bimaxwellian_moments_advance( + up->moments_up, phase_range, conf_range, f_max, up->moms_iter + ); + } else { + gkyl_gk_maxwellian_moments_advance( + up->moments_up, phase_range, conf_range, f_max, up->moms_iter + ); } // a. Calculate ddMi^(k+1) = Mi_corr - Mi_new @@ -143,18 +152,18 @@ gkyl_gk_maxwellian_correct_all_moments(gkyl_gk_maxwellian_correct *up, if ((niter % 1) == 0) { if (up->use_gpu) { // We insure the reduction to find the maximum error is thread-safe on GPUs - // by first calling a specialized kernel for computing the absolute value + // by first calling a specialized kernel for computing the absolute value // of the difference of the cell averages, then calling reduce_range. - gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu(conf_range, - num_comp, nc, moms_target, up->moms_iter, up->abs_diff_moms); + gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu( + conf_range, num_comp, nc, moms_target, up->moms_iter, up->abs_diff_moms + ); gkyl_array_reduce_range(up->error_cu, up->abs_diff_moms, GKYL_MAX, conf_range); gkyl_cu_memcpy(up->error, up->error_cu, sizeof(double[num_comp]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { struct gkyl_range_iter biter; // Reset the maximum error - for (int i=0; ierror[i] = 0.0; } // Iterate over the input configuration-space range to find the maximum error @@ -166,31 +175,47 @@ gkyl_gk_maxwellian_correct_all_moments(gkyl_gk_maxwellian_correct *up, // Check the error in the absolute value of the cell average // Note: for density and temperature(s), this error is a relative error compared to the target moment value // so that we can converge to the correct target moments in SI units and minimize finite precision issues. - up->error[0] = fmax(fabs(moms_local[0*nc] - moms_target_local[0*nc])/moms_target_local[0*nc],fabs(up->error[0])); - up->error[2] = fmax(fabs(moms_local[2*nc] - moms_target_local[2*nc])/moms_target_local[2*nc],fabs(up->error[2])); + up->error[0] = fmax( + fabs(moms_local[0 * nc] - moms_target_local[0 * nc]) / moms_target_local[0 * nc], + fabs(up->error[0]) + ); + up->error[2] = fmax( + fabs(moms_local[2 * nc] - moms_target_local[2 * nc]) / moms_target_local[2 * nc], + fabs(up->error[2]) + ); // However, u_par may be ~ 0 and if it is, we normalize it with the target thermal veocity instead. - if (fabs(moms_target_local[1*nc]) < sqrt(moms_target_local[2*nc])) { - up->error[1] = fmax(fabs(moms_local[1*nc] - moms_target_local[1*nc])/sqrt(moms_target_local[2*nc]),fabs(up->error[1])); + if (fabs(moms_target_local[1 * nc]) < sqrt(moms_target_local[2 * nc])) { + up->error[1] = fmax( + fabs(moms_local[1 * nc] - moms_target_local[1 * nc]) / + sqrt(moms_target_local[2 * nc]), + fabs(up->error[1]) + ); + } else { + up->error[1] = fmax( + fabs(moms_local[1 * nc] - moms_target_local[1 * nc]) / + fabs(moms_target_local[1 * nc]), + fabs(up->error[1]) + ); } - else { - up->error[1] = fmax(fabs(moms_local[1*nc] - moms_target_local[1*nc])/fabs(moms_target_local[1*nc]),fabs(up->error[1])); - } - // Check if density and temperature (or parallel temperature) are positive, + // Check if density and temperature (or parallel temperature) are positive, // if they aren't we will break out of the iteration - ispositive_f_lte = (moms_local[0*nc]>0.0) && ispositive_f_lte; - ispositive_f_lte = (moms_local[2*nc]>0.0) && ispositive_f_lte; + ispositive_f_lte = (moms_local[0 * nc] > 0.0) && ispositive_f_lte; + ispositive_f_lte = (moms_local[2 * nc] > 0.0) && ispositive_f_lte; // Also compute the error in Tperp/m if we are correcting a bi-Maxwellian if (up->bimaxwellian) { - up->error[3] = fmax(fabs(moms_local[3*nc] - moms_target_local[3*nc])/moms_target_local[3*nc],fabs(up->error[3])); - ispositive_f_lte = (moms_local[3*nc]>0.0) && ispositive_f_lte; + up->error[3] = fmax( + fabs(moms_local[3 * nc] - moms_target_local[3 * nc]) / moms_target_local[3 * nc], + fabs(up->error[3]) + ); + ispositive_f_lte = (moms_local[3 * nc] > 0.0) && ispositive_f_lte; } } } } // Find the maximum error looping over the error in each component - max_error = 0.0; // reset maximum error - for (int d=0; derror[d]); } @@ -200,16 +225,16 @@ gkyl_gk_maxwellian_correct_all_moments(gkyl_gk_maxwellian_correct *up, gkyl_array_accumulate(up->moms_iter, 1.0, up->d_moms); // 2. Update the gyrokinetic Maxwellian distribution function using the corrected moments. - gkyl_gk_maxwellian_proj_on_basis_advance(up->proj_max, - phase_range, conf_range, up->moms_iter, false, f_max); + gkyl_gk_maxwellian_proj_on_basis_advance( + up->proj_max, phase_range, conf_range, up->moms_iter, false, f_max + ); niter += 1; } if ((niter < max_iter) && (ispositive_f_lte) && (max_error < tol)) { corr_status = 0; - } - else { + } else { corr_status = 1; } @@ -217,32 +242,34 @@ gkyl_gk_maxwellian_correct_all_moments(gkyl_gk_maxwellian_correct *up, // we project the distribution function with the target moments. // We correct the density and then recompute moments/errors for this new projection. if (corr_status == 1 && !up->use_last_converged) { - gkyl_gk_maxwellian_proj_on_basis_advance(up->proj_max, - phase_range, conf_range, moms_target, false, f_max); + gkyl_gk_maxwellian_proj_on_basis_advance( + up->proj_max, phase_range, conf_range, moms_target, false, f_max + ); if (up->bimaxwellian) { - gkyl_gk_bimaxwellian_moments_advance(up->moments_up, phase_range, conf_range, - f_max, up->moms_iter); - } - else { - gkyl_gk_maxwellian_moments_advance(up->moments_up, phase_range, conf_range, - f_max, up->moms_iter); + gkyl_gk_bimaxwellian_moments_advance( + up->moments_up, phase_range, conf_range, f_max, up->moms_iter + ); + } else { + gkyl_gk_maxwellian_moments_advance( + up->moments_up, phase_range, conf_range, f_max, up->moms_iter + ); } if (up->use_gpu) { // We insure the reduction to find the maximum error is thread-safe on GPUs - // by first calling a specialized kernel for computing the absolute value + // by first calling a specialized kernel for computing the absolute value // of the difference of the cell averages, then calling reduce_range. - gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu(conf_range, - num_comp, nc, moms_target, up->moms_iter, up->abs_diff_moms); + gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu( + conf_range, num_comp, nc, moms_target, up->moms_iter, up->abs_diff_moms + ); gkyl_array_reduce_range(up->error_cu, up->abs_diff_moms, GKYL_MAX, conf_range); gkyl_cu_memcpy(up->error, up->error_cu, sizeof(double[num_comp]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { struct gkyl_range_iter biter; // Reset the maximum error - for (int i=0; ierror[i] = 0.0; } // Iterate over the input configuration-space range to find the maximum error @@ -254,21 +281,33 @@ gkyl_gk_maxwellian_correct_all_moments(gkyl_gk_maxwellian_correct *up, // Check the error in the absolute value of the cell average // Note: for density and temperature, this error is a relative error compared to the target moment value // so that we can converge to the correct target moments in SI units and minimize finite precision issues. - up->error[0] = fmax(fabs(moms_local[0*nc] - moms_target_local[0*nc])/moms_target_local[0*nc],fabs(up->error[0])); - up->error[2] = fmax(fabs(moms_local[2*nc] - moms_target_local[2*nc])/moms_target_local[2*nc],fabs(up->error[2])); + up->error[0] = fmax( + fabs(moms_local[0 * nc] - moms_target_local[0 * nc]) / moms_target_local[0 * nc], + fabs(up->error[0]) + ); + up->error[2] = fmax( + fabs(moms_local[2 * nc] - moms_target_local[2 * nc]) / moms_target_local[2 * nc], + fabs(up->error[2]) + ); // However, u_par may be ~ 0 and if it is, we need to use absolute error. We can converge safely using - // absolute error if u_par ~ O(1). Otherwise, we use relative error for u_par. - if (fabs(moms_target_local[1*nc]) < 1.0) { - up->error[1] = fmax(fabs(moms_local[1*nc] - moms_target_local[1*nc]),fabs(up->error[1])); - } - else { - up->error[1] = fmax(fabs(moms_local[1*nc] - moms_target_local[1*nc])/moms_target_local[1*nc],fabs(up->error[1])); + // absolute error if u_par ~ O(1). Otherwise, we use relative error for u_par. + if (fabs(moms_target_local[1 * nc]) < 1.0) { + up->error[1] = + fmax(fabs(moms_local[1 * nc] - moms_target_local[1 * nc]), fabs(up->error[1])); + } else { + up->error[1] = fmax( + fabs(moms_local[1 * nc] - moms_target_local[1 * nc]) / moms_target_local[1 * nc], + fabs(up->error[1]) + ); } // Also compute the error in Tperp/m if we are correcting a bi-Maxwellian if (up->bimaxwellian) { - up->error[3] = fmax(fabs(moms_local[3*nc] - moms_target_local[3*nc])/moms_target_local[3*nc],fabs(up->error[3])); - ispositive_f_lte = (moms_local[3*nc]>0.0) && ispositive_f_lte; + up->error[3] = fmax( + fabs(moms_local[3 * nc] - moms_target_local[3 * nc]) / moms_target_local[3 * nc], + fabs(up->error[3]) + ); + ispositive_f_lte = (moms_local[3 * nc] > 0.0) && ispositive_f_lte; } } } @@ -277,14 +316,13 @@ gkyl_gk_maxwellian_correct_all_moments(gkyl_gk_maxwellian_correct *up, struct gkyl_gk_maxwellian_correct_status status; status.iter_converged = corr_status; status.num_iter = niter; - for (int i=0; ierror[i]; } return status; } -void -gkyl_gk_maxwellian_correct_release(gkyl_gk_maxwellian_correct *up) +void gkyl_gk_maxwellian_correct_release(gkyl_gk_maxwellian_correct *up) { gkyl_array_release(up->moms_iter); gkyl_array_release(up->d_moms); @@ -303,11 +341,10 @@ gkyl_gk_maxwellian_correct_release(gkyl_gk_maxwellian_correct *up) #ifndef GKYL_HAVE_CUDA -void -gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu(const struct gkyl_range *conf_range, - int num_comp, int nc, - const struct gkyl_array *moms_target, const struct gkyl_array *moms_iter, - struct gkyl_array *moms_abs_diff) +void gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu( + const struct gkyl_range *conf_range, int num_comp, int nc, const struct gkyl_array *moms_target, + const struct gkyl_array *moms_iter, struct gkyl_array *moms_abs_diff +) { assert(false); } diff --git a/gyrokinetic/zero/gk_maxwellian_correct_cu.cu b/gyrokinetic/zero/gk_maxwellian_correct_cu.cu index d48caac909..d2a24bf122 100644 --- a/gyrokinetic/zero/gk_maxwellian_correct_cu.cu +++ b/gyrokinetic/zero/gk_maxwellian_correct_cu.cu @@ -6,32 +6,30 @@ extern "C" { #include } -static void -gkyl_parallelize_components_kernel_launch_dims(dim3* dimGrid, dim3* dimBlock, gkyl_range range, int ncomp) +static void gkyl_parallelize_components_kernel_launch_dims( + dim3 *dimGrid, dim3 *dimBlock, gkyl_range range, int ncomp +) { // Create a 2D thread grid so we launch ncomp*range.volume number of threads and can parallelize over components too dimBlock->y = ncomp; dimGrid->y = 1; - dimBlock->x = gkyl_int_div_up(252, ncomp); // ncomp is always 3 or 4 so use closest - // integer multiple to 256 of both 3 and 4 + dimBlock->x = gkyl_int_div_up(252, ncomp); // ncomp is always 3 or 4 so use closest + // integer multiple to 256 of both 3 and 4 dimGrid->x = gkyl_int_div_up(range.volume, dimBlock->x); } -__global__ static void -gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu_ker(struct gkyl_range conf_range, - int num_comp, int nc, - const struct gkyl_array *moms_target, const struct gkyl_array *moms_iter, - struct gkyl_array *abs_diff_moms) +__global__ static void gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu_ker( + struct gkyl_range conf_range, int num_comp, int nc, const struct gkyl_array *moms_target, + const struct gkyl_array *moms_iter, struct gkyl_array *abs_diff_moms +) { int idx[GKYL_MAX_DIM]; // 2D thread grid - // linc2 = c where c is the component index - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + // linc2 = c where c is the component index + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -41,34 +39,35 @@ gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu_ker(struct gkyl_range conf_ra // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *moms_local = (const double*) gkyl_array_cfetch(moms_iter, loc); - const double *moms_target_local = (const double*) gkyl_array_cfetch(moms_target, loc); - double *abs_diff_moms_local = (double*) gkyl_array_fetch(abs_diff_moms, loc); + const double *moms_local = (const double *)gkyl_array_cfetch(moms_iter, loc); + const double *moms_target_local = (const double *)gkyl_array_cfetch(moms_target, loc); + double *abs_diff_moms_local = (double *)gkyl_array_fetch(abs_diff_moms, loc); - // Compute the absolute value of the difference of cell averages + // Compute the absolute value of the difference of cell averages // Note: max error found by follow-up thread-safe reduction operation - // Also: for density and temperature(s), this error is a relative error - // compared to the target moment value so that we can converge to the + // Also: for density and temperature(s), this error is a relative error + // compared to the target moment value so that we can converge to the // correct target moments in SI units and minimize finite precision issues. - // However, upar (1st component) may be ~ 0 and if it is, + // However, upar (1st component) may be ~ 0 and if it is, // we normalize it with the target thermal veocity instead. - if (linc2 == 1 && moms_target_local[linc2*nc] < sqrt(moms_target_local[2*nc])) { - abs_diff_moms_local[linc2] = fabs(moms_local[linc2*nc] - moms_target_local[linc2*nc])/sqrt(moms_target_local[2*nc]); - } - else { - abs_diff_moms_local[linc2] = fabs(moms_local[linc2*nc] - moms_target_local[linc2*nc])/fabs(moms_target_local[linc2*nc]); + if (linc2 == 1 && moms_target_local[linc2 * nc] < sqrt(moms_target_local[2 * nc])) { + abs_diff_moms_local[linc2] = fabs(moms_local[linc2 * nc] - moms_target_local[linc2 * nc]) / + sqrt(moms_target_local[2 * nc]); + } else { + abs_diff_moms_local[linc2] = fabs(moms_local[linc2 * nc] - moms_target_local[linc2 * nc]) / + fabs(moms_target_local[linc2 * nc]); } } } -void -gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu(const struct gkyl_range *conf_range, - int num_comp, int nc, - const struct gkyl_array *moms_target, const struct gkyl_array *moms_iter, - struct gkyl_array *moms_abs_diff) +void gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu( + const struct gkyl_range *conf_range, int num_comp, int nc, const struct gkyl_array *moms_target, + const struct gkyl_array *moms_iter, struct gkyl_array *moms_abs_diff +) { dim3 dimGrid, dimBlock; gkyl_parallelize_components_kernel_launch_dims(&dimGrid, &dimBlock, *conf_range, num_comp); - gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu_ker<<>>(*conf_range, - num_comp, nc, moms_target->on_dev, moms_iter->on_dev, moms_abs_diff->on_dev); + gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu_ker<< > >( + *conf_range, num_comp, nc, moms_target->on_dev, moms_iter->on_dev, moms_abs_diff->on_dev + ); } diff --git a/gyrokinetic/zero/gk_maxwellian_moments.c b/gyrokinetic/zero/gk_maxwellian_moments.c index bc8c4999eb..fbe76a161b 100644 --- a/gyrokinetic/zero/gk_maxwellian_moments.c +++ b/gyrokinetic/zero/gk_maxwellian_moments.c @@ -10,7 +10,7 @@ #include #include -struct gkyl_gk_maxwellian_moments* +struct gkyl_gk_maxwellian_moments * gkyl_gk_maxwellian_moments_inew(const struct gkyl_gk_maxwellian_moments_inp *inp) { gkyl_gk_maxwellian_moments *up = gkyl_malloc(sizeof(*up)); @@ -22,7 +22,7 @@ gkyl_gk_maxwellian_moments_inew(const struct gkyl_gk_maxwellian_moments_inp *inp // Determine factor to divide out of temperature computation // If 1x1v, up->vdim_phys = 1, otherwise up->vdim_phys = 3. - up->vdim_phys = 2*vdim-1; + up->vdim_phys = 2 * vdim - 1; up->gk_geom = gkyl_gk_geometry_acquire(inp->gk_geom); up->divide_jacobgeo = inp->divide_jacobgeo; @@ -33,7 +33,8 @@ gkyl_gk_maxwellian_moments_inew(const struct gkyl_gk_maxwellian_moments_inp *inp up->M0 = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); up->M1 = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); up->u_par = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); - up->u_par_dot_M1 = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); + up->u_par_dot_M1 = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); up->pressure = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); up->temperature = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); // Bin op memory for needed weak divisions @@ -41,12 +42,11 @@ gkyl_gk_maxwellian_moments_inew(const struct gkyl_gk_maxwellian_moments_inp *inp if (vdim == 2) { // Additional moments if computing Bi-Maxwellian moments (Tpar, Tperp) up->p_par = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); - up->t_par = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); + up->t_par = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); up->p_perp = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); - up->t_perp = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); + up->t_perp = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); } - } - else { + } else { up->M0 = gkyl_array_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); up->M1 = gkyl_array_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); up->u_par = gkyl_array_new(GKYL_DOUBLE, up->num_conf_basis, conf_range_ext_ncells); @@ -65,142 +65,145 @@ gkyl_gk_maxwellian_moments_inew(const struct gkyl_gk_maxwellian_moments_inp *inp } // Moment calculator for needed moments (M0, M1, and M2) - up->M0_calc = gkyl_dg_updater_moment_gyrokinetic_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->mass, 0, inp->vel_map, inp->gk_geom, NULL, GKYL_F_MOMENT_M0, 0, inp->use_gpu); - up->M1_calc = gkyl_dg_updater_moment_gyrokinetic_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->mass, 0, inp->vel_map, inp->gk_geom, NULL, GKYL_F_MOMENT_M1, 0, inp->use_gpu); - up->M2_calc = gkyl_dg_updater_moment_gyrokinetic_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->mass, 0, inp->vel_map, inp->gk_geom, NULL, GKYL_F_MOMENT_M2, 0, inp->use_gpu); + up->M0_calc = gkyl_dg_updater_moment_gyrokinetic_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->mass, 0, inp->vel_map, + inp->gk_geom, NULL, GKYL_F_MOMENT_M0, 0, inp->use_gpu + ); + up->M1_calc = gkyl_dg_updater_moment_gyrokinetic_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->mass, 0, inp->vel_map, + inp->gk_geom, NULL, GKYL_F_MOMENT_M1, 0, inp->use_gpu + ); + up->M2_calc = gkyl_dg_updater_moment_gyrokinetic_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->mass, 0, inp->vel_map, + inp->gk_geom, NULL, GKYL_F_MOMENT_M2, 0, inp->use_gpu + ); if (vdim == 2) { - // Additional moment calculators for Bi-Maxwellian moments (M2par, M2perp) - up->M2_par_calc = gkyl_dg_updater_moment_gyrokinetic_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->mass, 0, inp->vel_map, inp->gk_geom, NULL, GKYL_F_MOMENT_M2PAR, 0, inp->use_gpu); - up->M2_perp_calc = gkyl_dg_updater_moment_gyrokinetic_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->mass, 0, inp->vel_map, inp->gk_geom, NULL, GKYL_F_MOMENT_M2PERP, 0, inp->use_gpu); - } + // Additional moment calculators for Bi-Maxwellian moments (M2par, M2perp) + up->M2_par_calc = gkyl_dg_updater_moment_gyrokinetic_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->mass, 0, + inp->vel_map, inp->gk_geom, NULL, GKYL_F_MOMENT_M2PAR, 0, inp->use_gpu + ); + up->M2_perp_calc = gkyl_dg_updater_moment_gyrokinetic_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->mass, 0, + inp->vel_map, inp->gk_geom, NULL, GKYL_F_MOMENT_M2PERP, 0, inp->use_gpu + ); + } return up; } -void -gkyl_gk_maxwellian_density_moment_advance(struct gkyl_gk_maxwellian_moments *up, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *fin, struct gkyl_array *density_out) +void gkyl_gk_maxwellian_density_moment_advance( + struct gkyl_gk_maxwellian_moments *up, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *fin, struct gkyl_array *density_out +) { // compute J*M0 where J is the configurations-space Jacobian - gkyl_dg_updater_moment_gyrokinetic_advance(up->M0_calc, phase_range, conf_range, - fin, up->M0); + gkyl_dg_updater_moment_gyrokinetic_advance(up->M0_calc, phase_range, conf_range, fin, up->M0); if (up->divide_jacobgeo) { // Rescale moment by the inverse of the Jacobian - gkyl_dg_div_op_range(up->mem, &up->conf_basis, - 0, density_out, 0, up->M0, 0, up->gk_geom->geo_int.jacobgeo, conf_range); - } - else { + gkyl_dg_div_op_range( + up->mem, &up->conf_basis, 0, density_out, 0, up->M0, 0, up->gk_geom->geo_int.jacobgeo, + conf_range + ); + } else { gkyl_array_set_range(density_out, 1.0, up->M0, conf_range); } } -void -gkyl_gk_maxwellian_moments_advance(struct gkyl_gk_maxwellian_moments *up, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *fin, struct gkyl_array *moms_out) +void gkyl_gk_maxwellian_moments_advance( + struct gkyl_gk_maxwellian_moments *up, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *fin, struct gkyl_array *moms_out +) { // compute J*M0 and J*M1 where J is the configurations-space Jacobian - gkyl_dg_updater_moment_gyrokinetic_advance(up->M0_calc, phase_range, conf_range, - fin, up->M0); - gkyl_dg_updater_moment_gyrokinetic_advance(up->M1_calc, phase_range, conf_range, - fin, up->M1); + gkyl_dg_updater_moment_gyrokinetic_advance(up->M0_calc, phase_range, conf_range, fin, up->M0); + gkyl_dg_updater_moment_gyrokinetic_advance(up->M1_calc, phase_range, conf_range, fin, up->M1); // Isolate u_par by dividing J*M1 by J*M0 - gkyl_dg_div_op_range(up->mem, &up->conf_basis, - 0, up->u_par, 0, up->M1, 0, up->M0, conf_range); + gkyl_dg_div_op_range(up->mem, &up->conf_basis, 0, up->u_par, 0, up->M1, 0, up->M0, conf_range); // Compute J*M1*upar (needed to compute T/m). - gkyl_dg_mul_op_range(&up->conf_basis, - 0, up->u_par_dot_M1, 0, up->u_par, 0, up->M1, conf_range); + gkyl_dg_mul_op_range(&up->conf_basis, 0, up->u_par_dot_M1, 0, up->u_par, 0, up->M1, conf_range); // Compute J*M2 = vdim_phys*J*n*T/m + J*M1*upar. - gkyl_dg_updater_moment_gyrokinetic_advance(up->M2_calc, phase_range, conf_range, - fin, up->pressure); + gkyl_dg_updater_moment_gyrokinetic_advance( + up->M2_calc, phase_range, conf_range, fin, up->pressure + ); // Subtract off J*M1*upar from total J*M2 - gkyl_array_accumulate_range(up->pressure, -1.0, - up->u_par_dot_M1, conf_range); + gkyl_array_accumulate_range(up->pressure, -1.0, up->u_par_dot_M1, conf_range); - // Rescale J*n*T by 1.0/vdim_phys and divide out J*M0 to get T/m, T/m = J*P/(m J*M0). - gkyl_array_scale(up->pressure, 1.0/up->vdim_phys); - gkyl_dg_div_op_range(up->mem, &up->conf_basis, - 0, up->temperature, 0, up->pressure, 0, up->M0, conf_range); + // Rescale J*n*T by 1.0/vdim_phys and divide out J*M0 to get T/m, T/m = J*P/(m J*M0). + gkyl_array_scale(up->pressure, 1.0 / up->vdim_phys); + gkyl_dg_div_op_range( + up->mem, &up->conf_basis, 0, up->temperature, 0, up->pressure, 0, up->M0, conf_range + ); if (up->divide_jacobgeo) { // Rescale moment by the inverse of the Jacobian and store in moms_out - gkyl_dg_div_op_range(up->mem, &up->conf_basis, - 0, moms_out, 0, up->M0, 0, up->gk_geom->geo_int.jacobgeo, conf_range); - } - else { + gkyl_dg_div_op_range( + up->mem, &up->conf_basis, 0, moms_out, 0, up->M0, 0, up->gk_geom->geo_int.jacobgeo, conf_range + ); + } else { gkyl_array_set_range(moms_out, 1.0, up->M0, conf_range); } // Save the other outputs to moms_out (n, V_drift, T/m): int num_conf_basis = up->num_conf_basis; - gkyl_array_set_offset_range(moms_out, 1.0, up->u_par, 1*num_conf_basis, conf_range); - gkyl_array_set_offset_range(moms_out, 1.0, up->temperature, 2*num_conf_basis, conf_range); + gkyl_array_set_offset_range(moms_out, 1.0, up->u_par, 1 * num_conf_basis, conf_range); + gkyl_array_set_offset_range(moms_out, 1.0, up->temperature, 2 * num_conf_basis, conf_range); } -void -gkyl_gk_bimaxwellian_moments_advance(struct gkyl_gk_maxwellian_moments *up, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *fin, struct gkyl_array *moms_out) +void gkyl_gk_bimaxwellian_moments_advance( + struct gkyl_gk_maxwellian_moments *up, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *fin, struct gkyl_array *moms_out +) { // compute J*M0 and J*M1 where J is the configurations-space Jacobian - gkyl_dg_updater_moment_gyrokinetic_advance(up->M0_calc, phase_range, conf_range, - fin, up->M0); - gkyl_dg_updater_moment_gyrokinetic_advance(up->M1_calc, phase_range, conf_range, - fin, up->M1); + gkyl_dg_updater_moment_gyrokinetic_advance(up->M0_calc, phase_range, conf_range, fin, up->M0); + gkyl_dg_updater_moment_gyrokinetic_advance(up->M1_calc, phase_range, conf_range, fin, up->M1); // Isolate u_par by dividing J*M1 by J*M0 - gkyl_dg_div_op_range(up->mem, &up->conf_basis, - 0, up->u_par, 0, up->M1, 0, up->M0, conf_range); + gkyl_dg_div_op_range(up->mem, &up->conf_basis, 0, up->u_par, 0, up->M1, 0, up->M0, conf_range); // Compute J*M1*upar (needed to compute T_par/m). - gkyl_dg_mul_op_range(&up->conf_basis, - 0, up->u_par_dot_M1, 0, up->u_par, 0, up->M1, conf_range); + gkyl_dg_mul_op_range(&up->conf_basis, 0, up->u_par_dot_M1, 0, up->u_par, 0, up->M1, conf_range); // Compute J*M2_par = J*n*T_par/m + J*M1*upar. - gkyl_dg_updater_moment_gyrokinetic_advance(up->M2_par_calc, phase_range, conf_range, - fin, up->p_par); + gkyl_dg_updater_moment_gyrokinetic_advance( + up->M2_par_calc, phase_range, conf_range, fin, up->p_par + ); // Subtract off J*M1*upar from total J*M2_par - gkyl_array_accumulate_range(up->p_par, -1.0, - up->u_par_dot_M1, conf_range); + gkyl_array_accumulate_range(up->p_par, -1.0, up->u_par_dot_M1, conf_range); // Compute J*M2_perp = 2*J*n*T_perp/m. - gkyl_dg_updater_moment_gyrokinetic_advance(up->M2_perp_calc, phase_range, conf_range, - fin, up->p_perp); + gkyl_dg_updater_moment_gyrokinetic_advance( + up->M2_perp_calc, phase_range, conf_range, fin, up->p_perp + ); // Rescale J*n*T_perp by 1/2 and divide out J*M0 to get T_par/m, T_perp/m // from n*T_par/m, n*T_perp/m. gkyl_array_scale(up->p_perp, 0.5); - gkyl_dg_div_op_range(up->mem, &up->conf_basis, - 0, up->t_par, 0, up->p_par, 0, up->M0, conf_range); - gkyl_dg_div_op_range(up->mem, &up->conf_basis, - 0, up->t_perp, 0, up->p_perp, 0, up->M0, conf_range); + gkyl_dg_div_op_range(up->mem, &up->conf_basis, 0, up->t_par, 0, up->p_par, 0, up->M0, conf_range); + gkyl_dg_div_op_range( + up->mem, &up->conf_basis, 0, up->t_perp, 0, up->p_perp, 0, up->M0, conf_range + ); if (up->divide_jacobgeo) { // Rescale moment by the inverse of the Jacobian and store in moms_out - gkyl_dg_div_op_range(up->mem, &up->conf_basis, - 0, moms_out, 0, up->M0, 0, up->gk_geom->geo_int.jacobgeo, conf_range); - } - else { + gkyl_dg_div_op_range( + up->mem, &up->conf_basis, 0, moms_out, 0, up->M0, 0, up->gk_geom->geo_int.jacobgeo, conf_range + ); + } else { gkyl_array_set_range(moms_out, 1.0, up->M0, conf_range); } // Save the other outputs to moms_out (n, u_par, T_par/m, T_perp/m): int num_conf_basis = up->num_conf_basis; - gkyl_array_set_offset_range(moms_out, 1.0, up->u_par, 1*num_conf_basis, conf_range); - gkyl_array_set_offset_range(moms_out, 1.0, up->t_par, 2*num_conf_basis, conf_range); - gkyl_array_set_offset_range(moms_out, 1.0, up->t_perp, 3*num_conf_basis, conf_range); + gkyl_array_set_offset_range(moms_out, 1.0, up->u_par, 1 * num_conf_basis, conf_range); + gkyl_array_set_offset_range(moms_out, 1.0, up->t_par, 2 * num_conf_basis, conf_range); + gkyl_array_set_offset_range(moms_out, 1.0, up->t_perp, 3 * num_conf_basis, conf_range); } -void -gkyl_gk_maxwellian_moments_release(gkyl_gk_maxwellian_moments *up) +void gkyl_gk_maxwellian_moments_release(gkyl_gk_maxwellian_moments *up) { gkyl_gk_geometry_release(up->gk_geom); gkyl_array_release(up->M0); diff --git a/gyrokinetic/zero/gk_maxwellian_proj_on_basis.c b/gyrokinetic/zero/gk_maxwellian_proj_on_basis.c index 118acbecf9..c4c71bc2a0 100644 --- a/gyrokinetic/zero/gk_maxwellian_proj_on_basis.c +++ b/gyrokinetic/zero/gk_maxwellian_proj_on_basis.c @@ -18,8 +18,12 @@ static inline struct gkyl_range get_qrange(int cdim, int dim, int num_quad, int num_quad_v, bool *is_vdim_p2) { int qshape[GKYL_MAX_DIM]; - for (int i=0; indim; - int vdim = ndim-cdim; + int vdim = ndim - cdim; int num_quad_v = num_quad; // hybrid basis have p=2 in velocity space. - bool is_vdim_p2[2] = {false}; // 2 is the max vdim for GK. + bool is_vdim_p2[2] = {false}; // 2 is the max vdim for GK. if (basis->b_type == GKYL_BASIS_MODAL_GKHYBRID) { - num_quad_v = num_quad+1; - is_vdim_p2[0] = true; // only vpar is quadratic in GK hybrid. + num_quad_v = num_quad + 1; + is_vdim_p2[0] = true; // only vpar is quadratic in GK hybrid. } double ordinates1[num_quad], weights1[num_quad]; @@ -49,45 +53,41 @@ init_quad_values(int cdim, const struct gkyl_basis *basis, if (quad_type == GKYL_POSITIVITY_QUAD) { // Positivity nodes are -1/3, 1/3 and have weights 1.0. All other // weights are set to zero. - for (int i=0; inum_basis, tot_quad); if (use_gpu) { *basis_at_ords = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis->num_basis, tot_quad); - } - else { + } else { *basis_at_ords = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, tot_quad); } - for (int n=0; neval(gkyl_array_fetch(ordinates_ho, n), gkyl_array_fetch(basis_at_ords_ho, n)); } @@ -161,21 +159,21 @@ init_quad_values(int cdim, const struct gkyl_basis *basis, return tot_quad; } -static void -gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars(gkyl_gk_maxwellian_proj_on_basis *up, - const struct gkyl_range *conf_range, - const struct gkyl_array *bmag, const struct gkyl_array *jacobtot) +static void gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars( + gkyl_gk_maxwellian_proj_on_basis *up, const struct gkyl_range *conf_range, + const struct gkyl_array *bmag, const struct gkyl_array *jacobtot +) { -// Setup the intial geometric vars, on GPU +// Setup the intial geometric vars, on GPU #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) - return gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars_cu(up, conf_range, - bmag, jacobtot); + if (up->use_gpu) { + return gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars_cu(up, conf_range, bmag, jacobtot); + } #endif // Otherwise run the CPU Version to setup bmag, jacobtot int cdim = up->cdim, pdim = up->pdim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int tot_conf_quad = up->tot_conf_quad; int num_conf_basis = up->num_conf_basis; @@ -193,19 +191,19 @@ gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars(gkyl_gk_maxwellian_proj_on_basis double *bmag_quad = gkyl_array_fetch(up->bmag_quad, midx); double *jacobtot_quad = gkyl_array_fetch(up->jacobtot_quad, midx); - // Sum over basis - for (int n=0; nconf_basis_at_ords, n); - for (int k=0; kuse_gpu = inp->use_gpu; up->vel_map = gkyl_velocity_map_acquire(inp->vel_map); - int num_quad = up->conf_basis.poly_order+1; - // initialize data needed for conf-space quadrature - up->tot_conf_quad = init_quad_values(up->cdim, &up->conf_basis, - inp->quad_type, num_quad, - &up->conf_ordinates, &up->conf_weights, &up->conf_basis_at_ords, false); + int num_quad = up->conf_basis.poly_order + 1; + // initialize data needed for conf-space quadrature + up->tot_conf_quad = init_quad_values( + up->cdim, &up->conf_basis, inp->quad_type, num_quad, &up->conf_ordinates, &up->conf_weights, + &up->conf_basis_at_ords, false + ); - // initialize data needed for phase-space quadrature - up->tot_quad = init_quad_values(up->cdim, &up->phase_basis, - inp->quad_type, num_quad, - &up->ordinates, &up->weights, &up->basis_at_ords, false); + // initialize data needed for phase-space quadrature + up->tot_quad = init_quad_values( + up->cdim, &up->phase_basis, inp->quad_type, num_quad, &up->ordinates, &up->weights, + &up->basis_at_ords, false + ); - up->fun_at_ords = gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad); // Only used in CPU implementation. + up->fun_at_ords = + gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad); // Only used in CPU implementation. // To avoid creating iterators over ranges in device kernel, we'll // create a map between phase-space and conf-space ordinates. - int num_quad_v = num_quad; // Hybrid basis have p=2 in velocity space. + int num_quad_v = num_quad; // Hybrid basis have p=2 in velocity space. // hybrid basis have p=2 in velocity space. - bool is_vdim_p2[2] = {false}; // 2 is the max vdim for GK. + bool is_vdim_p2[2] = {false}; // 2 is the max vdim for GK. if (up->phase_basis.b_type == GKYL_BASIS_MODAL_GKHYBRID) { - num_quad_v = num_quad+1; - is_vdim_p2[0] = true; // only vpar is quadratic in GK hybrid. + num_quad_v = num_quad + 1; + is_vdim_p2[0] = true; // only vpar is quadratic in GK hybrid. } up->conf_qrange = get_qrange(up->cdim, up->cdim, num_quad, num_quad_v, is_vdim_p2); up->phase_qrange = get_qrange(up->cdim, up->pdim, num_quad, num_quad_v, is_vdim_p2); @@ -255,8 +256,7 @@ gkyl_gk_maxwellian_proj_on_basis_inew(const struct gkyl_gk_maxwellian_proj_on_ba if (inp->bimaxwellian) { up->bimaxwellian = true; up->num_comp = 4; - } - else { + } else { up->num_comp = 3; } @@ -265,141 +265,152 @@ gkyl_gk_maxwellian_proj_on_basis_inew(const struct gkyl_gk_maxwellian_proj_on_ba // Allocate device copies of arrays needed for quadrature. int p2c_qidx_ho[up->phase_qrange.volume]; - up->p2c_qidx = (int*) gkyl_cu_malloc(sizeof(int)*up->phase_qrange.volume); + up->p2c_qidx = (int *)gkyl_cu_malloc(sizeof(int) * up->phase_qrange.volume); // Allocate f_maxwellian_quad at phase-space quadrature points // moms_maxwellian_quad (n, upar, T/m) at configuration-space quadrature points. // expamp_quad, the exponential pre-factor in the Maxwellian distribution, at quadrature points. - up->f_maxwellian_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->tot_quad, inp->conf_range_ext->volume*inp->vel_range->volume); - up->moms_maxwellian_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->tot_conf_quad*up->num_comp, inp->conf_range_ext->volume); - up->expamp_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->tot_conf_quad, inp->conf_range_ext->volume); + up->f_maxwellian_quad = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->tot_quad, inp->conf_range_ext->volume * inp->vel_range->volume + ); + up->moms_maxwellian_quad = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->tot_conf_quad * up->num_comp, inp->conf_range_ext->volume + ); + up->expamp_quad = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->tot_conf_quad, inp->conf_range_ext->volume); // Allocate the memory for computing the specific phase nodal to modal calculation struct gkyl_mat_mm_array_mem *phase_nodal_to_modal_mem_ho; - phase_nodal_to_modal_mem_ho = gkyl_mat_mm_array_mem_new(up->num_phase_basis, up->tot_quad, 1.0, 0.0, - GKYL_NO_TRANS, GKYL_NO_TRANS, false); + phase_nodal_to_modal_mem_ho = gkyl_mat_mm_array_mem_new( + up->num_phase_basis, up->tot_quad, 1.0, 0.0, GKYL_NO_TRANS, GKYL_NO_TRANS, false + ); // Compute the matrix A for the phase nodal to modal memory - const double *phase_w = (const double*) up->weights->data; - const double *phaseb_o = (const double*) up->basis_at_ords->data; - for (int n=0; ntot_quad; ++n){ - for (int k=0; knum_phase_basis; ++k){ - gkyl_mat_set(phase_nodal_to_modal_mem_ho->A, k, n, phase_w[n]*phaseb_o[k+up->num_phase_basis*n]); + const double *phase_w = (const double *)up->weights->data; + const double *phaseb_o = (const double *)up->basis_at_ords->data; + for (int n = 0; n < up->tot_quad; ++n) { + for (int k = 0; k < up->num_phase_basis; ++k) { + gkyl_mat_set( + phase_nodal_to_modal_mem_ho->A, k, n, phase_w[n] * phaseb_o[k + up->num_phase_basis * n] + ); } } - + // copy to device - up->phase_nodal_to_modal_mem = gkyl_mat_mm_array_mem_new(up->num_phase_basis, up->tot_quad, 1.0, 0.0, - GKYL_NO_TRANS, GKYL_NO_TRANS, up->use_gpu); + up->phase_nodal_to_modal_mem = gkyl_mat_mm_array_mem_new( + up->num_phase_basis, up->tot_quad, 1.0, 0.0, GKYL_NO_TRANS, GKYL_NO_TRANS, up->use_gpu + ); gkyl_mat_copy(up->phase_nodal_to_modal_mem->A, phase_nodal_to_modal_mem_ho->A); gkyl_mat_mm_array_mem_release(phase_nodal_to_modal_mem_ho); - // initialize data needed for conf-space quadrature on device - up->tot_conf_quad = init_quad_values(up->cdim, &up->conf_basis, - inp->quad_type, num_quad, - &up->conf_ordinates, &up->conf_weights, &up->conf_basis_at_ords, up->use_gpu); + // initialize data needed for conf-space quadrature on device + up->tot_conf_quad = init_quad_values( + up->cdim, &up->conf_basis, inp->quad_type, num_quad, &up->conf_ordinates, &up->conf_weights, + &up->conf_basis_at_ords, up->use_gpu + ); - // initialize data needed for phase-space quadrature on device - up->tot_quad = init_quad_values(up->cdim, &up->phase_basis, - inp->quad_type, num_quad, - &up->ordinates, &up->weights, &up->basis_at_ords, up->use_gpu); + // initialize data needed for phase-space quadrature on device + up->tot_quad = init_quad_values( + up->cdim, &up->phase_basis, inp->quad_type, num_quad, &up->ordinates, &up->weights, + &up->basis_at_ords, up->use_gpu + ); int pidx[GKYL_MAX_DIM]; - for (int n=0; ntot_quad; ++n) { + for (int n = 0; n < up->tot_quad; ++n) { gkyl_range_inv_idx(&up->phase_qrange, n, pidx); int cqidx = gkyl_range_idx(&up->conf_qrange, pidx); p2c_qidx_ho[n] = cqidx; } - gkyl_cu_memcpy(up->p2c_qidx, p2c_qidx_ho, sizeof(int)*up->phase_qrange.volume, GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + up->p2c_qidx, p2c_qidx_ho, sizeof(int) * up->phase_qrange.volume, GKYL_CU_MEMCPY_H2D + ); } #endif // Allocate and obtain geometric variables at quadrature points // since these quantities are time-independent. - // Also allocate number density ratio: num_ratio = n_target/n0 + // Also allocate number density ratio: num_ratio = n_target/n0 // and bin_op memory to compute ratio for fixing the density with simple rescaling. - if (up->use_gpu) { - up->bmag_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->tot_conf_quad, inp->conf_range_ext->volume); - up->jacobtot_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->tot_conf_quad, inp->conf_range_ext->volume); - up->num_ratio = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->conf_basis.num_basis, conf_local_ext_ncells); + if (up->use_gpu) { + up->bmag_quad = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->tot_conf_quad, inp->conf_range_ext->volume); + up->jacobtot_quad = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->tot_conf_quad, inp->conf_range_ext->volume); + up->num_ratio = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->conf_basis.num_basis, conf_local_ext_ncells); up->mem = gkyl_dg_bin_op_mem_cu_dev_new(conf_local_ncells, up->conf_basis.num_basis); - } - else { - up->bmag_quad = gkyl_array_new(GKYL_DOUBLE, - up->tot_conf_quad, inp->conf_range_ext->volume); - up->jacobtot_quad = gkyl_array_new(GKYL_DOUBLE, - up->tot_conf_quad, inp->conf_range_ext->volume); - up->num_ratio = gkyl_array_new(GKYL_DOUBLE, - up->conf_basis.num_basis, conf_local_ext_ncells); + } else { + up->bmag_quad = gkyl_array_new(GKYL_DOUBLE, up->tot_conf_quad, inp->conf_range_ext->volume); + up->jacobtot_quad = gkyl_array_new(GKYL_DOUBLE, up->tot_conf_quad, inp->conf_range_ext->volume); + up->num_ratio = gkyl_array_new(GKYL_DOUBLE, up->conf_basis.num_basis, conf_local_ext_ncells); up->mem = gkyl_dg_bin_op_mem_new(conf_local_ncells, up->conf_basis.num_basis); } - gkyl_array_clear(up->bmag_quad, 0.0); - gkyl_array_clear(up->jacobtot_quad, 0.0); - gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars(up, inp->conf_range, - inp->gk_geom->geo_int.bmag, inp->gk_geom->geo_int.jacobtot); - + gkyl_array_clear(up->bmag_quad, 0.0); + gkyl_array_clear(up->jacobtot_quad, 0.0); + gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars( + up, inp->conf_range, inp->gk_geom->geo_int.bmag, inp->gk_geom->geo_int.jacobtot + ); + // Store a Maxwellian moment calculation updater to compute and correct the density struct gkyl_gk_maxwellian_moments_inp inp_mom = { .phase_grid = inp->phase_grid, .conf_basis = inp->conf_basis, .phase_basis = inp->phase_basis, - .conf_range = inp->conf_range, + .conf_range = inp->conf_range, .conf_range_ext = inp->conf_range_ext, - .mass = inp->mass, - .gk_geom = inp->gk_geom, + .mass = inp->mass, + .gk_geom = inp->gk_geom, .vel_map = inp->vel_map, - .divide_jacobgeo = inp->divide_jacobgeo, - .use_gpu = inp->use_gpu, + .divide_jacobgeo = inp->divide_jacobgeo, + .use_gpu = inp->use_gpu }; - up->moments_up = gkyl_gk_maxwellian_moments_inew( &inp_mom ); + up->moments_up = gkyl_gk_maxwellian_moments_inew(&inp_mom); return up; } -static void -proj_on_basis(const gkyl_gk_maxwellian_proj_on_basis *up, const struct gkyl_array *fun_at_ords, double* f) +static void proj_on_basis( + const gkyl_gk_maxwellian_proj_on_basis *up, const struct gkyl_array *fun_at_ords, double *f +) { int num_basis = up->num_phase_basis; int tot_quad = up->tot_quad; - const double* GKYL_RESTRICT weights = up->weights->data; - const double* GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; - const double* GKYL_RESTRICT func_at_ords = fun_at_ords->data; + const double *GKYL_RESTRICT weights = up->weights->data; + const double *GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; + const double *GKYL_RESTRICT func_at_ords = fun_at_ords->data; + + for (int k = 0; k < num_basis; ++k) { + f[k] = 0.0; + } - for (int k=0; kuse_gpu) - return gkyl_gk_maxwellian_proj_on_basis_advance_cu(up, phase_range, conf_range, - moms_maxwellian, use_jacobtot, f_maxwellian); + if (up->use_gpu) { + return gkyl_gk_maxwellian_proj_on_basis_advance_cu( + up, phase_range, conf_range, moms_maxwellian, use_jacobtot, f_maxwellian + ); + } #endif - double f_floor = 1.e-40; + double f_floor = 1.e-40; int cdim = up->cdim, pdim = up->pdim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int vdim_phys = vdim == 1 ? 1 : 3; int tot_quad = up->tot_quad; - int num_phase_basis = up->num_phase_basis; + int num_phase_basis = up->num_phase_basis; int tot_conf_quad = up->tot_conf_quad; int num_conf_basis = up->num_conf_basis; @@ -407,8 +418,10 @@ gkyl_gk_maxwellian_proj_on_basis_advance(gkyl_gk_maxwellian_proj_on_basis *up, struct gkyl_range vel_rng; struct gkyl_range_iter conf_iter, vel_iter; - int pidx[GKYL_MAX_DIM], rem_dir[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim; ++d) rem_dir[d] = 1; + int pidx[GKYL_MAX_DIM], rem_dir[GKYL_MAX_DIM] = {0}; + for (int d = 0; d < conf_range->ndim; ++d) { + rem_dir[d] = 1; + } double xc[GKYL_MAX_DIM], xmu[GKYL_MAX_DIM] = {0.0}; double n_quad[tot_conf_quad], upar_quad[tot_conf_quad], T_over_m_quad[tot_conf_quad]; @@ -424,14 +437,14 @@ gkyl_gk_maxwellian_proj_on_basis_advance(gkyl_gk_maxwellian_proj_on_basis *up, const double *moms_maxwellian_d = gkyl_array_cfetch(moms_maxwellian, midx); const double *n_d = moms_maxwellian_d; const double *upar_d = &moms_maxwellian_d[num_conf_basis]; - const double *T_over_m_d = &moms_maxwellian_d[num_conf_basis*2]; + const double *T_over_m_d = &moms_maxwellian_d[num_conf_basis * 2]; // Fetch bmag and total Jacobian const double *bmag_quad = gkyl_array_cfetch(up->bmag_quad, midx); const double *jacobtot_quad = gkyl_array_cfetch(up->jacobtot_quad, midx); - // Sum over basis for given Maxwellian moments (n, upar, T/m) - for (int n=0; nconf_basis_at_ords, n); // Zero out quadrature values @@ -440,37 +453,35 @@ gkyl_gk_maxwellian_proj_on_basis_advance(gkyl_gk_maxwellian_proj_on_basis *up, T_over_m_quad[n] = 0.0; // Compute the configuration-space quadrature - for (int k=0; k 0.0) && (T_over_m_quad[n] > 0.0)) { if (up->bimaxwellian) { - const double *Tperp_over_m_d = &moms_maxwellian_d[num_conf_basis*3]; + const double *Tperp_over_m_d = &moms_maxwellian_d[num_conf_basis * 3]; Tperp_over_m_quad[n] = 0.0; - for (int k=0; kndim, phase_range->ndim, conf_iter.idx, vel_iter.idx, pidx); gkyl_rect_grid_cell_center(&up->phase_grid, pidx, xc); long lidx = gkyl_range_idx(&vel_rng, vel_iter.idx); @@ -488,7 +498,6 @@ gkyl_gk_maxwellian_proj_on_basis_advance(gkyl_gk_maxwellian_proj_on_basis *up, // compute Maxwellian distribution function at phase-space quadrature nodes gkyl_range_iter_init(&qiter, &up->phase_qrange); while (gkyl_range_iter_next(&qiter)) { - int cqidx = gkyl_range_idx(&up->conf_qrange, qiter.idx); int pqidx = gkyl_range_idx(&up->phase_qrange, qiter.idx); @@ -500,47 +509,51 @@ gkyl_gk_maxwellian_proj_on_basis_advance(gkyl_gk_maxwellian_proj_on_basis *up, const double *vmap_d = gkyl_array_cfetch(gvm->vmap, vlinidx); double xcomp[1]; for (int vd = 0; vd < vdim; vd++) { - xcomp[0] = xcomp_d[cdim+vd]; - xmu[cdim+vd] = gvm->vmap_basis->eval_expand(xcomp, vmap_d+vd*gvm->vmap_basis->num_basis); + xcomp[0] = xcomp_d[cdim + vd]; + xmu[cdim + vd] = + gvm->vmap_basis->eval_expand(xcomp, vmap_d + vd * gvm->vmap_basis->num_basis); } // Fetch velocity space Jacobian for scaling distribution function const double *jacobvel_d = gkyl_array_cfetch(gvm->jacobvel, lidx); - double efact = 0.0; + double efact = 0.0; // vpar term. - efact += pow(xmu[cdim]-upar_quad[cqidx], 2.0)/(2.0*T_over_m_quad[cqidx]); - // mu term (only for 2v). + efact += pow(xmu[cdim] - upar_quad[cqidx], 2.0) / (2.0 * T_over_m_quad[cqidx]); + // mu term (only for 2v). if (up->bimaxwellian) { - efact += xmu[cdim+1]*bmag_quad[cqidx]/(up->mass*Tperp_over_m_quad[cqidx]); - } - else { - efact += xmu[cdim+1]*bmag_quad[cqidx]/(up->mass*T_over_m_quad[cqidx]); + efact += xmu[cdim + 1] * bmag_quad[cqidx] / (up->mass * Tperp_over_m_quad[cqidx]); + } else { + efact += xmu[cdim + 1] * bmag_quad[cqidx] / (up->mass * T_over_m_quad[cqidx]); } double *fq = gkyl_array_fetch(up->fun_at_ords, pqidx); - fq[0] = T_over_m_quad[cqidx] > 0.0 ? f_floor + - jacobvel_d[0]*expamp_quad[cqidx]*exp(-efact) : f_floor; + fq[0] = T_over_m_quad[cqidx] > 0.0 ? + f_floor + jacobvel_d[0] * expamp_quad[cqidx] * exp(-efact) : + f_floor; } // Compute expansion coefficients of Maxwellian distribution function on basis. proj_on_basis(up, up->fun_at_ords, gkyl_array_fetch(f_maxwellian, lidx)); } } - // Correct the density of the projected Maxwellian distribution function through rescaling. - gkyl_gk_maxwellian_density_moment_advance(up->moments_up, phase_range, conf_range, - f_maxwellian, up->num_ratio); + // Correct the density of the projected Maxwellian distribution function through rescaling. + gkyl_gk_maxwellian_density_moment_advance( + up->moments_up, phase_range, conf_range, f_maxwellian, up->num_ratio + ); // Compute number density ratio: num_ratio = n/n0. // The 0th component of moms_target is the target density. - gkyl_dg_div_op_range(up->mem, &up->conf_basis, 0, up->num_ratio, - 0, moms_maxwellian, 0, up->num_ratio, conf_range); + gkyl_dg_div_op_range( + up->mem, &up->conf_basis, 0, up->num_ratio, 0, moms_maxwellian, 0, up->num_ratio, conf_range + ); // Rescale distribution function. - gkyl_dg_mul_conf_phase_op_range(&up->conf_basis, &up->phase_basis, - f_maxwellian, up->num_ratio, f_maxwellian, conf_range, phase_range); + gkyl_dg_mul_conf_phase_op_range( + &up->conf_basis, &up->phase_basis, f_maxwellian, up->num_ratio, f_maxwellian, conf_range, + phase_range + ); } -void -gkyl_gk_maxwellian_proj_on_basis_release(gkyl_gk_maxwellian_proj_on_basis* up) +void gkyl_gk_maxwellian_proj_on_basis_release(gkyl_gk_maxwellian_proj_on_basis *up) { gkyl_velocity_map_release(up->vel_map); diff --git a/gyrokinetic/zero/gk_maxwellian_proj_on_basis_cu.cu b/gyrokinetic/zero/gk_maxwellian_proj_on_basis_cu.cu index 46417696e6..a4c5692f1a 100644 --- a/gyrokinetic/zero/gk_maxwellian_proj_on_basis_cu.cu +++ b/gyrokinetic/zero/gk_maxwellian_proj_on_basis_cu.cu @@ -16,140 +16,140 @@ extern "C" { #include } -__global__ static void -gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars_cu_ker(struct gkyl_range conf_range, - const struct gkyl_array* conf_basis_at_ords, - const struct gkyl_array* bmag, const struct gkyl_array* jacobtot, - struct gkyl_array* bmag_quad_d, struct gkyl_array* jacobtot_quad_d) -{ +__global__ static void gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars_cu_ker( + struct gkyl_range conf_range, const struct gkyl_array *conf_basis_at_ords, + const struct gkyl_array *bmag, const struct gkyl_array *jacobtot, struct gkyl_array *bmag_quad_d, + struct gkyl_array *jacobtot_quad_d +) +{ int num_conf_basis = conf_basis_at_ords->ncomp; int tot_conf_quad = conf_basis_at_ords->size; int cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_range.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_range, tid, cidx); long lincC = gkyl_range_idx(&conf_range, cidx); - const double *bmag_d = (const double*) gkyl_array_cfetch(bmag, lincC); - const double *jacobtot_d = (const double*) gkyl_array_cfetch(jacobtot, lincC); + const double *bmag_d = (const double *)gkyl_array_cfetch(bmag, lincC); + const double *jacobtot_d = (const double *)gkyl_array_cfetch(jacobtot, lincC); - double *bmag_quad = (double*) gkyl_array_fetch(bmag_quad_d, lincC); - double *jacobtot_quad = (double*) gkyl_array_fetch(jacobtot_quad_d, lincC); + double *bmag_quad = (double *)gkyl_array_fetch(bmag_quad_d, lincC); + double *jacobtot_quad = (double *)gkyl_array_fetch(jacobtot_quad_d, lincC); - // Sum over basis for the geometric quantities at configuration-space quadrature points. - for (int n=0; nnblocks, nthreads = conf_range->nthreads; - gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars_cu_ker<<>>(*conf_range, - up->conf_basis_at_ords->on_dev, - bmag->on_dev, jacobtot->on_dev, - up->bmag_quad->on_dev, up->jacobtot_quad->on_dev); + gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars_cu_ker<< > >( + *conf_range, up->conf_basis_at_ords->on_dev, bmag->on_dev, jacobtot->on_dev, + up->bmag_quad->on_dev, up->jacobtot_quad->on_dev + ); } -static void -gkyl_parallelize_components_kernel_launch_dims(dim3* dimGrid, dim3* dimBlock, gkyl_range range, int ncomp) +static void gkyl_parallelize_components_kernel_launch_dims( + dim3 *dimGrid, dim3 *dimBlock, gkyl_range range, int ncomp +) { - // Create a 2D thread grid so we launch ncomp*range.volume number of threads + // Create a 2D thread grid so we launch ncomp*range.volume number of threads // so we can parallelize over components too dimBlock->y = ncomp; // ncomp *must* be less than 256 dimGrid->y = 1; - dimBlock->x = GKYL_DEFAULT_NUM_THREADS/ncomp; + dimBlock->x = GKYL_DEFAULT_NUM_THREADS / ncomp; dimGrid->x = gkyl_int_div_up(range.volume, dimBlock->x); } -__global__ static void -gkyl_gk_maxwellian_proj_on_basis_moms_quad_ker(struct gkyl_range conf_range, - int vdim_phys, int num_comp, bool bimaxwellian, bool use_jacobtot, - const struct gkyl_array* conf_basis_at_ords, - const struct gkyl_array* moms_maxwellian, - const struct gkyl_array* bmag_quad, const struct gkyl_array* jacobtot_quad, - struct gkyl_array* moms_maxwellian_quad, struct gkyl_array* expamp_quad) +__global__ static void gkyl_gk_maxwellian_proj_on_basis_moms_quad_ker( + struct gkyl_range conf_range, int vdim_phys, int num_comp, bool bimaxwellian, bool use_jacobtot, + const struct gkyl_array *conf_basis_at_ords, const struct gkyl_array *moms_maxwellian, + const struct gkyl_array *bmag_quad, const struct gkyl_array *jacobtot_quad, + struct gkyl_array *moms_maxwellian_quad, struct gkyl_array *expamp_quad +) { int num_conf_basis = conf_basis_at_ords->ncomp; - int tot_conf_quad = conf_basis_at_ords->size; + int tot_conf_quad = conf_basis_at_ords->size; int cidx[GKYL_MAX_CDIM]; // 2D thread grid // linc2 goes from 0 to tot_conf_quad - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_range.volume; tid += blockDim.x*gridDim.x) { + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_range, tid, cidx); long lincC = gkyl_range_idx(&conf_range, cidx); - const double *moms_maxwellian_d = (const double*) gkyl_array_cfetch(moms_maxwellian, lincC); - const double *bmag_quad_d = (const double*) gkyl_array_cfetch(bmag_quad, lincC); - const double *jacobtot_quad_d = (const double*) gkyl_array_cfetch(jacobtot_quad, lincC); + const double *moms_maxwellian_d = (const double *)gkyl_array_cfetch(moms_maxwellian, lincC); + const double *bmag_quad_d = (const double *)gkyl_array_cfetch(bmag_quad, lincC); + const double *jacobtot_quad_d = (const double *)gkyl_array_cfetch(jacobtot_quad, lincC); - double *moms_maxwellian_quad_d = (double*) gkyl_array_fetch(moms_maxwellian_quad, lincC); + double *moms_maxwellian_quad_d = (double *)gkyl_array_fetch(moms_maxwellian_quad, lincC); - // Sum over basis for given Maxwellian moments (n, upar, T/m) or (n, upar, Tpar/m, Tperp/m) - // at configuration-space quadrature points. - const double *b_ord = (const double*) gkyl_array_cfetch(conf_basis_at_ords, linc2); - for (int k=0; k 0.0) && (T_over_m_quad[linc2] > 0.0)) { if (bimaxwellian) { - const double *Tperp_over_m_quad = &moms_maxwellian_quad_d[tot_conf_quad*3]; - expamp_quad_d[linc2] = n_quad[linc2]/(sqrt(pow(2.0*GKYL_PI, 3.0)*T_over_m_quad[linc2])*Tperp_over_m_quad[linc2]); + const double *Tperp_over_m_quad = &moms_maxwellian_quad_d[tot_conf_quad * 3]; + expamp_quad_d[linc2] = + n_quad[linc2] / + (sqrt(pow(2.0 * GKYL_PI, 3.0) * T_over_m_quad[linc2]) * Tperp_over_m_quad[linc2]); + } else { + expamp_quad_d[linc2] = + n_quad[linc2] / (sqrt(pow(2.0 * GKYL_PI * T_over_m_quad[linc2], vdim_phys))); } - else { - expamp_quad_d[linc2] = n_quad[linc2]/(sqrt(pow(2.0*GKYL_PI*T_over_m_quad[linc2], vdim_phys))); - } - } - else { + } else { expamp_quad_d[linc2] = 0.0; } - // Scale amplitude of the exponential by desired Jacobian factor + // Scale amplitude of the exponential by desired Jacobian factor // Either the total Jacobian or just the velocity-space Jacobian bmag if (use_jacobtot) { expamp_quad_d[linc2] *= jacobtot_quad_d[linc2]; - } - else { + } else { expamp_quad_d[linc2] *= bmag_quad_d[linc2]; - } + } } } -__global__ static void -gkyl_gk_maxwellian_proj_on_basis_f_quad_ker(struct gkyl_rect_grid phase_grid, - struct gkyl_range phase_range, struct gkyl_range conf_range, struct gkyl_range vel_range, - bool bimaxwellian, double mass, - const struct gkyl_array* conf_basis_at_ords, const struct gkyl_array* phase_ordinates, - const struct gkyl_array* moms_maxwellian_quad, const struct gkyl_array* expamp_quad, - const struct gkyl_array* bmag_quad, const int *p2c_qidx, - struct gkyl_array* vmap, struct gkyl_array* jacobvel, struct gkyl_basis* vmap_basis, - struct gkyl_array* f_maxwellian_quad) +__global__ static void gkyl_gk_maxwellian_proj_on_basis_f_quad_ker( + struct gkyl_rect_grid phase_grid, struct gkyl_range phase_range, struct gkyl_range conf_range, + struct gkyl_range vel_range, bool bimaxwellian, double mass, + const struct gkyl_array *conf_basis_at_ords, const struct gkyl_array *phase_ordinates, + const struct gkyl_array *moms_maxwellian_quad, const struct gkyl_array *expamp_quad, + const struct gkyl_array *bmag_quad, const int *p2c_qidx, struct gkyl_array *vmap, + struct gkyl_array *jacobvel, struct gkyl_basis *vmap_basis, struct gkyl_array *f_maxwellian_quad +) { double f_floor = 1.0e-40; int pdim = phase_range.ndim, cdim = conf_range.ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int tot_conf_quad = conf_basis_at_ords->size; double xc[GKYL_MAX_DIM], xmu[GKYL_MAX_DIM] = {0.0}; @@ -157,9 +157,9 @@ gkyl_gk_maxwellian_proj_on_basis_f_quad_ker(struct gkyl_rect_grid phase_grid, // 2D thread grid // linc2 goes from 0 to tot_phase_quad - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < phase_range.volume; tid += blockDim.x*gridDim.x) { + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < phase_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&phase_range, tid, pidx); // get configuration-space linear index. @@ -169,99 +169,103 @@ gkyl_gk_maxwellian_proj_on_basis_f_quad_ker(struct gkyl_rect_grid phase_grid, long lincC = gkyl_range_idx(&conf_range, cidx); // Fetch upar and T/m; density dependence already included in expamp_quad - const double *moms_maxwellian_quad_d = (const double*) gkyl_array_cfetch(moms_maxwellian_quad, lincC); + const double *moms_maxwellian_quad_d = + (const double *)gkyl_array_cfetch(moms_maxwellian_quad, lincC); const double *upar_quad = &moms_maxwellian_quad_d[tot_conf_quad]; - const double *T_over_m_quad = &moms_maxwellian_quad_d[tot_conf_quad*2]; + const double *T_over_m_quad = &moms_maxwellian_quad_d[tot_conf_quad * 2]; - const double *bmag_quad_d = (const double*) gkyl_array_cfetch(bmag_quad, lincC); + const double *bmag_quad_d = (const double *)gkyl_array_cfetch(bmag_quad, lincC); - const double *expamp_quad_d = (const double*) gkyl_array_cfetch(expamp_quad, lincC); + const double *expamp_quad_d = (const double *)gkyl_array_cfetch(expamp_quad, lincC); gkyl_rect_grid_cell_center(&phase_grid, pidx, xc); long lidx = gkyl_range_idx(&phase_range, pidx); // Select for a phase space index fq - double *fq = (double*) gkyl_array_fetch(f_maxwellian_quad, lidx); + double *fq = (double *)gkyl_array_fetch(f_maxwellian_quad, lidx); int cqidx = p2c_qidx[linc2]; for (int d = cdim; d < pdim; d++) { - vidx[d-cdim] = pidx[d]; + vidx[d - cdim] = pidx[d]; } long vlinidx = gkyl_range_idx(&vel_range, vidx); - const double *vmap_d = (const double*) gkyl_array_cfetch(vmap, vlinidx); - const double *xcomp_d = (const double*) gkyl_array_cfetch(phase_ordinates, linc2); + const double *vmap_d = (const double *)gkyl_array_cfetch(vmap, vlinidx); + const double *xcomp_d = (const double *)gkyl_array_cfetch(phase_ordinates, linc2); // Convert comp velocity coordinate to phys velocity coord. double xcomp[1]; for (int vd = 0; vd < vdim; vd++) { - xcomp[0] = xcomp_d[cdim+vd]; - xmu[cdim+vd] = vmap_basis->eval_expand(xcomp, vmap_d+vd*vmap_basis->num_basis); + xcomp[0] = xcomp_d[cdim + vd]; + xmu[cdim + vd] = vmap_basis->eval_expand(xcomp, vmap_d + vd * vmap_basis->num_basis); } // Fetch velocity space Jacobian for scaling distribution function - const double *jacobvel_d = (const double*) gkyl_array_cfetch(jacobvel, lidx); + const double *jacobvel_d = (const double *)gkyl_array_cfetch(jacobvel, lidx); double efact = 0.0; // vpar term. - efact += pow(xmu[cdim]-upar_quad[cqidx],2)/(2.0*T_over_m_quad[cqidx]); + efact += pow(xmu[cdim] - upar_quad[cqidx], 2) / (2.0 * T_over_m_quad[cqidx]); // mu term (only for 2v). if (bimaxwellian) { - const double *Tperp_over_m_quad = &moms_maxwellian_quad_d[tot_conf_quad*3]; - efact += xmu[cdim+1]*bmag_quad_d[cqidx]/(mass*Tperp_over_m_quad[cqidx]); - } - else { - efact += xmu[cdim+1]*bmag_quad_d[cqidx]/(mass*T_over_m_quad[cqidx]); + const double *Tperp_over_m_quad = &moms_maxwellian_quad_d[tot_conf_quad * 3]; + efact += xmu[cdim + 1] * bmag_quad_d[cqidx] / (mass * Tperp_over_m_quad[cqidx]); + } else { + efact += xmu[cdim + 1] * bmag_quad_d[cqidx] / (mass * T_over_m_quad[cqidx]); } - fq[linc2] = T_over_m_quad[cqidx] > 0.0 ? f_floor + - jacobvel_d[0]*expamp_quad_d[cqidx]*exp(-efact) : f_floor; + fq[linc2] = T_over_m_quad[cqidx] > 0.0 ? + f_floor + jacobvel_d[0] * expamp_quad_d[cqidx] * exp(-efact) : + f_floor; } } -void -gkyl_gk_maxwellian_proj_on_basis_advance_cu(gkyl_gk_maxwellian_proj_on_basis *up, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *moms_maxwellian, bool use_jacobtot, - struct gkyl_array *f_maxwellian) +void gkyl_gk_maxwellian_proj_on_basis_advance_cu( + gkyl_gk_maxwellian_proj_on_basis *up, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *moms_maxwellian, bool use_jacobtot, + struct gkyl_array *f_maxwellian +) { int vdim = up->pdim - up->cdim; int vdim_phys = vdim == 1 ? 1 : 3; - gkyl_array_clear(up->moms_maxwellian_quad, 0.0); + gkyl_array_clear(up->moms_maxwellian_quad, 0.0); dim3 dimGrid_conf, dimBlock_conf; int tot_conf_quad = up->conf_basis_at_ords->size; - gkyl_parallelize_components_kernel_launch_dims(&dimGrid_conf, &dimBlock_conf, *conf_range, tot_conf_quad); - gkyl_gk_maxwellian_proj_on_basis_moms_quad_ker<<>>(*conf_range, - vdim_phys, up->num_comp, up->bimaxwellian, use_jacobtot, up->conf_basis_at_ords->on_dev, - moms_maxwellian->on_dev, - up->bmag_quad->on_dev, up->jacobtot_quad->on_dev, - up->moms_maxwellian_quad->on_dev, up->expamp_quad->on_dev); - + gkyl_parallelize_components_kernel_launch_dims( + &dimGrid_conf, &dimBlock_conf, *conf_range, tot_conf_quad + ); + gkyl_gk_maxwellian_proj_on_basis_moms_quad_ker<< > >( + *conf_range, vdim_phys, up->num_comp, up->bimaxwellian, use_jacobtot, + up->conf_basis_at_ords->on_dev, moms_maxwellian->on_dev, up->bmag_quad->on_dev, + up->jacobtot_quad->on_dev, up->moms_maxwellian_quad->on_dev, up->expamp_quad->on_dev + ); const struct gkyl_velocity_map *gvm = up->vel_map; dim3 dimGrid, dimBlock; int tot_phase_quad = up->basis_at_ords->size; gkyl_parallelize_components_kernel_launch_dims(&dimGrid, &dimBlock, *phase_range, tot_phase_quad); - gkyl_gk_maxwellian_proj_on_basis_f_quad_ker<<>>(up->phase_grid, - *phase_range, *conf_range, gvm->local_ext_vel, - up->bimaxwellian, up->mass, - up->conf_basis_at_ords->on_dev, up->ordinates->on_dev, - up->moms_maxwellian_quad->on_dev, up->expamp_quad->on_dev, - up->bmag_quad->on_dev, - up->p2c_qidx, gvm->vmap->on_dev, gvm->jacobvel->on_dev, gvm->vmap_basis, - up->f_maxwellian_quad->on_dev); + gkyl_gk_maxwellian_proj_on_basis_f_quad_ker<< > >( + up->phase_grid, *phase_range, *conf_range, gvm->local_ext_vel, up->bimaxwellian, up->mass, + up->conf_basis_at_ords->on_dev, up->ordinates->on_dev, up->moms_maxwellian_quad->on_dev, + up->expamp_quad->on_dev, up->bmag_quad->on_dev, up->p2c_qidx, gvm->vmap->on_dev, + gvm->jacobvel->on_dev, gvm->vmap_basis, up->f_maxwellian_quad->on_dev + ); // Call cublas to do the matrix multiplication nodal to modal conversion gkyl_mat_mm_array(up->phase_nodal_to_modal_mem, up->f_maxwellian_quad, f_maxwellian); - // Correct the density of the projected Maxwellian (or bi-Maxwellian) - // distribution function through rescaling. - gkyl_gk_maxwellian_density_moment_advance(up->moments_up, phase_range, conf_range, - f_maxwellian, up->num_ratio); + // Correct the density of the projected Maxwellian (or bi-Maxwellian) + // distribution function through rescaling. + gkyl_gk_maxwellian_density_moment_advance( + up->moments_up, phase_range, conf_range, f_maxwellian, up->num_ratio + ); // compute number density ratio: num_ratio = n/n0 // 0th component of moms_target is the target density - gkyl_dg_div_op_range(up->mem, &up->conf_basis, 0, up->num_ratio, - 0, moms_maxwellian, 0, up->num_ratio, conf_range); + gkyl_dg_div_op_range( + up->mem, &up->conf_basis, 0, up->num_ratio, 0, moms_maxwellian, 0, up->num_ratio, conf_range + ); // rescale distribution function - gkyl_dg_mul_conf_phase_op_range(&up->conf_basis, &up->phase_basis, - f_maxwellian, up->num_ratio, f_maxwellian, conf_range, phase_range); + gkyl_dg_mul_conf_phase_op_range( + &up->conf_basis, &up->phase_basis, f_maxwellian, up->num_ratio, f_maxwellian, conf_range, + phase_range + ); } diff --git a/gyrokinetic/zero/gk_neut_fluid_prim_vars.c b/gyrokinetic/zero/gk_neut_fluid_prim_vars.c index 64d9e0f5a1..e0adee66e0 100644 --- a/gyrokinetic/zero/gk_neut_fluid_prim_vars.c +++ b/gyrokinetic/zero/gk_neut_fluid_prim_vars.c @@ -8,11 +8,13 @@ #include #include -void gkyl_gk_neut_fluid_prim_vars_udrift_advance(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_udrift_advance( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { int nprob = up->udrift_ncomp; - assert(up->As->num == nprob*up->mem_range.volume); + assert(up->As->num == nprob * up->mem_range.volume); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -39,32 +41,35 @@ void gkyl_gk_neut_fluid_prim_vars_udrift_advance(struct gkyl_gk_neut_fluid_prim_ assert(status); } - double prim_vars_buff[up->udrift_ncomp*up->num_basis]; // Buffer needed for integrated moms. + double prim_vars_buff[up->udrift_ncomp * up->num_basis]; // Buffer needed for integrated moms. gkyl_range_iter_init(&iter, &up->mem_range); count = 0; while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&up->mem_range, iter.idx); - double* out_d = gkyl_array_fetch(out, linidx); + double *out_d = gkyl_array_fetch(out, linidx); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->udrift_get_sol_ker(count, up->xs, prim_vars_d); if (up->is_integrated) { - for (int i=0; iudrift_ncomp; i++) - out_d[out_coff+i] = up->integrated_fac * prim_vars_d[i*up->num_basis]; + for (int i = 0; i < up->udrift_ncomp; i++) { + out_d[out_coff + i] = up->integrated_fac * prim_vars_d[i * up->num_basis]; + } } count += nprob; } } -void gkyl_gk_neut_fluid_prim_vars_pressure_advance(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_pressure_advance( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { int nprob = up->udrift_ncomp; - assert(up->As->num == nprob*up->mem_range.volume); + assert(up->As->num == nprob * up->mem_range.volume); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -97,20 +102,22 @@ void gkyl_gk_neut_fluid_prim_vars_pressure_advance(struct gkyl_gk_neut_fluid_pri while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&up->mem_range, iter.idx); - double udrift_d[up->udrift_ncomp*up->num_basis]; - for (int i=0; inum_basis; i++) + double udrift_d[up->udrift_ncomp * up->num_basis]; + for (int i = 0; i < up->num_basis; i++) { udrift_d[i] = 0.0; + } const double *moms_d = gkyl_array_cfetch(moms, linidx); - double* out_d = gkyl_array_fetch(out, linidx); + double *out_d = gkyl_array_fetch(out, linidx); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->udrift_get_sol_ker(count, up->xs, udrift_d); up->pressure_ker(up->gas_gamma, moms_d, udrift_d, prim_vars_d); - for (int i=0; inum_basis; i++) + for (int i = 0; i < up->num_basis; i++) { prim_vars_d[i] *= up->thermalE_fac; + } if (up->is_integrated) { out_d[out_coff] = up->integrated_fac * prim_vars_d[0]; @@ -120,11 +127,13 @@ void gkyl_gk_neut_fluid_prim_vars_pressure_advance(struct gkyl_gk_neut_fluid_pri } } -void gkyl_gk_neut_fluid_prim_vars_temp_advance(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_temp_advance( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { int nprob = 1; - assert(up->As->num == nprob*up->mem_range.volume); + assert(up->As->num == nprob * up->mem_range.volume); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -157,9 +166,9 @@ void gkyl_gk_neut_fluid_prim_vars_temp_advance(struct gkyl_gk_neut_fluid_prim_va while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&up->mem_range, iter.idx); - double* out_d = gkyl_array_fetch(out, linidx); + double *out_d = gkyl_array_fetch(out, linidx); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->temp_get_sol_ker(count, up->xs, prim_vars_d); @@ -171,11 +180,13 @@ void gkyl_gk_neut_fluid_prim_vars_temp_advance(struct gkyl_gk_neut_fluid_prim_va } } -void gkyl_gk_neut_fluid_prim_vars_udrift_pressure_advance(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_udrift_pressure_advance( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { int nprob = up->udrift_ncomp; - assert(up->As->num == nprob*up->mem_range.volume); + assert(up->As->num == nprob * up->mem_range.volume); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -202,36 +213,39 @@ void gkyl_gk_neut_fluid_prim_vars_udrift_pressure_advance(struct gkyl_gk_neut_fl assert(status); } - double prim_vars_buff[(up->udrift_ncomp+1)*up->num_basis]; // Buffer needed for integrated moms. + double prim_vars_buff[(up->udrift_ncomp + 1) * up->num_basis]; // Buffer needed for integrated moms. gkyl_range_iter_init(&iter, &up->mem_range); count = 0; while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&up->mem_range, iter.idx); const double *moms_d = gkyl_array_cfetch(moms, linidx); - double* out_d = gkyl_array_fetch(out, linidx); + double *out_d = gkyl_array_fetch(out, linidx); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; - double* udrift_d = prim_vars_d; - double* pressure_d = &prim_vars_d[up->udrift_ncomp*up->num_basis]; + double *udrift_d = prim_vars_d; + double *pressure_d = &prim_vars_d[up->udrift_ncomp * up->num_basis]; up->udrift_get_sol_ker(count, up->xs, udrift_d); up->pressure_ker(up->gas_gamma, moms_d, udrift_d, pressure_d); if (up->is_integrated) { - for (int i=0; iudrift_ncomp+1; i++) - out_d[out_coff+i] = up->integrated_fac * prim_vars_d[i*up->num_basis]; + for (int i = 0; i < up->udrift_ncomp + 1; i++) { + out_d[out_coff + i] = up->integrated_fac * prim_vars_d[i * up->num_basis]; + } } count += nprob; } } -void gkyl_gk_neut_fluid_prim_vars_udrift_temp_advance(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_udrift_temp_advance( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { - int nprob = up->udrift_ncomp+1; - assert(up->As->num == nprob*up->mem_range.volume); + int nprob = up->udrift_ncomp + 1; + assert(up->As->num == nprob * up->mem_range.volume); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -258,32 +272,35 @@ void gkyl_gk_neut_fluid_prim_vars_udrift_temp_advance(struct gkyl_gk_neut_fluid_ assert(status); } - double prim_vars_buff[(up->udrift_ncomp+1)*up->num_basis]; // Buffer needed for integrated moms. + double prim_vars_buff[(up->udrift_ncomp + 1) * up->num_basis]; // Buffer needed for integrated moms. gkyl_range_iter_init(&iter, &up->mem_range); count = 0; while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&up->mem_range, iter.idx); const double *moms_d = gkyl_array_cfetch(moms, linidx); - double* out_d = gkyl_array_fetch(out, linidx); + double *out_d = gkyl_array_fetch(out, linidx); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->udrift_temp_get_sol_ker(count, up->xs, prim_vars_d); if (up->is_integrated) { - for (int i=0; iudrift_ncomp+1; i++) - out_d[out_coff+i] = up->integrated_fac * prim_vars_d[i*up->num_basis]; + for (int i = 0; i < up->udrift_ncomp + 1; i++) { + out_d[out_coff + i] = up->integrated_fac * prim_vars_d[i * up->num_basis]; + } } count += nprob; } } -void gkyl_gk_neut_fluid_prim_vars_lte_advance(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_lte_advance( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { - int nprob = up->udrift_ncomp+1; - assert(up->As->num == nprob*up->mem_range.volume); + int nprob = up->udrift_ncomp + 1; + assert(up->As->num == nprob * up->mem_range.volume); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -310,40 +327,42 @@ void gkyl_gk_neut_fluid_prim_vars_lte_advance(struct gkyl_gk_neut_fluid_prim_var assert(status); } - double prim_vars_buff[(up->udrift_ncomp+2)*up->num_basis]; // Buffer needed for integrated moms. + double prim_vars_buff[(up->udrift_ncomp + 2) * up->num_basis]; // Buffer needed for integrated moms. gkyl_range_iter_init(&iter, &up->mem_range); count = 0; while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&up->mem_range, iter.idx); const double *moms_d = gkyl_array_cfetch(moms, linidx); - double* out_d = gkyl_array_fetch(out, linidx); - - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + double *out_d = gkyl_array_fetch(out, linidx); + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->udrift_temp_get_sol_ker(count, up->xs, &prim_vars_d[up->num_basis]); // Scale rho and temp by 1/m. - for (int i=0; inum_basis; i++) { - prim_vars_d[out_coff+i] = moms_d[i]/up->mass; - prim_vars_d[out_coff+(up->udrift_ncomp+1)*up->num_basis+i] *= 1.0/up->mass; + for (int i = 0; i < up->num_basis; i++) { + prim_vars_d[out_coff + i] = moms_d[i] / up->mass; + prim_vars_d[out_coff + (up->udrift_ncomp + 1) * up->num_basis + i] *= 1.0 / up->mass; } if (up->is_integrated) { - for (int i=0; iudrift_ncomp+2; i++) - out_d[out_coff+i] = up->integrated_fac * prim_vars_d[i*up->num_basis]; + for (int i = 0; i < up->udrift_ncomp + 2; i++) { + out_d[out_coff + i] = up->integrated_fac * prim_vars_d[i * up->num_basis]; + } } count += nprob; } } -void gkyl_gk_neut_fluid_prim_vars_flow_energy_advance(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_flow_energy_advance( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { int nprob = 1; - assert(up->As->num == nprob*up->mem_range.volume); + assert(up->As->num == nprob * up->mem_range.volume); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -377,9 +396,9 @@ void gkyl_gk_neut_fluid_prim_vars_flow_energy_advance(struct gkyl_gk_neut_fluid_ long linidx = gkyl_range_idx(&up->mem_range, iter.idx); const double *moms_d = gkyl_array_cfetch(moms, linidx); - double* out_d = gkyl_array_fetch(out, linidx); + double *out_d = gkyl_array_fetch(out, linidx); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->flowE_get_sol_ker(count, up->xs, prim_vars_d); @@ -391,15 +410,19 @@ void gkyl_gk_neut_fluid_prim_vars_flow_energy_advance(struct gkyl_gk_neut_fluid_ } } -void gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_advance(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_advance( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { int nprob = 1; - assert(up->As->num == nprob*up->mem_range.volume); + assert(up->As->num == nprob * up->mem_range.volume); #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { - return gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_advance_cu(up, moms, out, out_coff); + return gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_advance_cu( + up, moms, out, out_coff + ); } #endif @@ -422,43 +445,50 @@ void gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_advance(stru assert(status); } - double prim_vars_buff[(up->udrift_ncomp+3)*up->num_basis]; // Buffer needed for integrated moms. + double prim_vars_buff[(up->udrift_ncomp + 3) * up->num_basis]; // Buffer needed for integrated moms. gkyl_range_iter_init(&iter, &up->mem_range); count = 0; while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&up->mem_range, iter.idx); const double *moms_d = gkyl_array_cfetch(moms, linidx); - double* out_d = gkyl_array_fetch(out, linidx); + double *out_d = gkyl_array_fetch(out, linidx); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; - int fourth_comp_off = 4*up->num_basis; - for (int i=0; inum_basis; + for (int i = 0; i < fourth_comp_off; i++) { prim_vars_d[i] = moms_d[i]; + } up->flowE_get_sol_ker(count, up->xs, &prim_vars_d[fourth_comp_off]); - for (int i=0; inum_basis; i++) - prim_vars_d[5*up->num_basis+i] = moms_d[fourth_comp_off+i] - prim_vars_d[fourth_comp_off+i]; + for (int i = 0; i < up->num_basis; i++) { + prim_vars_d[5 * up->num_basis + i] = + moms_d[fourth_comp_off + i] - prim_vars_d[fourth_comp_off + i]; + } if (up->is_integrated) { - for (int i=0; iudrift_ncomp+3; i++) - out_d[out_coff+i] = up->integrated_fac * prim_vars_d[i*up->num_basis]; + for (int i = 0; i < up->udrift_ncomp + 3; i++) { + out_d[out_coff + i] = up->integrated_fac * prim_vars_d[i * up->num_basis]; + } } count += nprob; } } -gkyl_gk_neut_fluid_prim_vars* -gkyl_gk_neut_fluid_prim_vars_new(double gas_gamma, double mass, const struct gkyl_basis* cbasis, - struct gkyl_rect_grid *grid, const struct gkyl_range *mem_range, - enum gkyl_gk_neut_fluid_prim_vars_type prim_vars_type, bool is_integrated, bool use_gpu) +gkyl_gk_neut_fluid_prim_vars *gkyl_gk_neut_fluid_prim_vars_new( + double gas_gamma, double mass, const struct gkyl_basis *cbasis, struct gkyl_rect_grid *grid, + const struct gkyl_range *mem_range, enum gkyl_gk_neut_fluid_prim_vars_type prim_vars_type, + bool is_integrated, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { - return gkyl_gk_neut_fluid_prim_vars_cu_dev_new(gas_gamma, mass, cbasis, grid, mem_range, prim_vars_type, is_integrated); + return gkyl_gk_neut_fluid_prim_vars_cu_dev_new( + gas_gamma, mass, cbasis, grid, mem_range, prim_vars_type, is_integrated + ); } #endif gkyl_gk_neut_fluid_prim_vars *up = gkyl_malloc(sizeof(gkyl_gk_neut_fluid_prim_vars)); @@ -475,47 +505,42 @@ gkyl_gk_neut_fluid_prim_vars_new(double gas_gamma, double mass, const struct gky up->udrift_ncomp = 3; up->mem_range = *mem_range; up->is_integrated = is_integrated; - + up->integrated_fac = 0.0; if (up->is_integrated) { up->integrated_fac = 1.0; - for (int d=0; dcdim; d++) - up->integrated_fac *= (grid->dx[d]/2.0)*sqrt(2.0); + for (int d = 0; d < up->cdim; d++) { + up->integrated_fac *= (grid->dx[d] / 2.0) * sqrt(2.0); + } } int nprob; up->thermalE_fac = 0.0; if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_UDRIFT) { nprob = up->udrift_ncomp; - } - else if ( (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_PRESSURE) || - (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_THERMAL_ENERGY) ) { + } else if ((prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_PRESSURE) || + (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_THERMAL_ENERGY)) { nprob = up->udrift_ncomp; - up->thermalE_fac = prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_PRESSURE? 1.0 : 1.0/(up->gas_gamma-1.0); - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_TEMP) { + up->thermalE_fac = + prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_PRESSURE ? 1.0 : 1.0 / (up->gas_gamma - 1.0); + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_TEMP) { nprob = 1; - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_UDRIFT_PRESSURE) { + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_UDRIFT_PRESSURE) { nprob = up->udrift_ncomp; - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_UDRIFT_TEMP) { - nprob = up->udrift_ncomp+1; - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_LTE) { - nprob = up->udrift_ncomp+1; - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_FLOW_ENERGY) { + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_UDRIFT_TEMP) { + nprob = up->udrift_ncomp + 1; + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_LTE) { + nprob = up->udrift_ncomp + 1; + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_FLOW_ENERGY) { nprob = 1; - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_MASS_MOMENTUM_FLOW_THERMAL_ENERGY) { + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_MASS_MOMENTUM_FLOW_THERMAL_ENERGY) { nprob = 1; } // There are udrift_ncomp*range->volume linear systems to be solved // for 3 components of u: ux, uy, uz. - up->As = gkyl_nmat_new(nprob*mem_range->volume, up->num_basis, up->num_basis); - up->xs = gkyl_nmat_new(nprob*mem_range->volume, up->num_basis, 1); + up->As = gkyl_nmat_new(nprob * mem_range->volume, up->num_basis, up->num_basis); + up->xs = gkyl_nmat_new(nprob * mem_range->volume, up->num_basis, 1); if (up->poly_order > 1) { up->mem = gkyl_nmat_linsolve_lu_new(up->As->num, up->As->nr); } @@ -546,8 +571,9 @@ void gkyl_gk_neut_fluid_prim_vars_release(gkyl_gk_neut_fluid_prim_vars *up) gkyl_nmat_linsolve_lu_release(up->mem); } - if (GKYL_IS_CU_ALLOC(up->flags)) + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/gyrokinetic/zero/gk_neut_fluid_prim_vars_cu.cu b/gyrokinetic/zero/gk_neut_fluid_prim_vars_cu.cu index 5655bb4557..82086c481e 100644 --- a/gyrokinetic/zero/gk_neut_fluid_prim_vars_cu.cu +++ b/gyrokinetic/zero/gk_neut_fluid_prim_vars_cu.cu @@ -10,17 +10,15 @@ extern "C" { #include } -__global__ static void -gkyl_gk_neut_fluid_prim_vars_udrift_set_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* moms) +__global__ static void gkyl_gk_neut_fluid_prim_vars_udrift_set_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, const struct gkyl_array *moms +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. // Must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange. @@ -30,27 +28,25 @@ gkyl_gk_neut_fluid_prim_vars_udrift_set_cu_kernel(gkyl_gk_neut_fluid_prim_vars* // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->udrift_ncomp; + long count = linc1 * up->udrift_ncomp; - const double *moms_d = (const double*) gkyl_array_cfetch(moms, loc); + const double *moms_d = (const double *)gkyl_array_cfetch(moms, loc); up->udrift_set_prob_ker(count, As, xs, moms_d); } } -__global__ static void -gkyl_gk_neut_fluid_prim_vars_udrift_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, - struct gkyl_array* out, int out_coff) +__global__ static void gkyl_gk_neut_fluid_prim_vars_udrift_copy_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + struct gkyl_array *out, int out_coff +) { int idx[GKYL_MAX_DIM]; - double prim_vars_buff[3*20]; // udrift_comp=3 for 3D p=2. + double prim_vars_buff[3 * 20]; // udrift_comp=3 for 3D p=2. - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. // Must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange. @@ -60,51 +56,54 @@ gkyl_gk_neut_fluid_prim_vars_udrift_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->udrift_ncomp; + long count = linc1 * up->udrift_ncomp; - double* out_d = (double*) gkyl_array_fetch(out, loc); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + double *out_d = (double *)gkyl_array_fetch(out, loc); + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->udrift_get_sol_ker(count, xs, prim_vars_d); if (up->is_integrated) { - for (int i=0; iudrift_ncomp; i++) - out_d[out_coff+i] = up->integrated_fac * prim_vars_d[i*up->num_basis]; + for (int i = 0; i < up->udrift_ncomp; i++) { + out_d[out_coff + i] = up->integrated_fac * prim_vars_d[i * up->num_basis]; + } } } } -void gkyl_gk_neut_fluid_prim_vars_udrift_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_udrift_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { struct gkyl_range conf_range = up->mem_range; - gkyl_gk_neut_fluid_prim_vars_udrift_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev); + gkyl_gk_neut_fluid_prim_vars_udrift_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_gk_neut_fluid_prim_vars_udrift_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, out->on_dev, out_coff); + gkyl_gk_neut_fluid_prim_vars_udrift_copy_cu_kernel<< > >( + up->on_dev, up->xs->on_dev, conf_range, out->on_dev, out_coff + ); } -__global__ static void -gkyl_gk_neut_fluid_prim_vars_pressure_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, const struct gkyl_array* moms, - struct gkyl_array* out, int out_coff) +__global__ static void gkyl_gk_neut_fluid_prim_vars_pressure_copy_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + const struct gkyl_array *moms, struct gkyl_array *out, int out_coff +) { int idx[GKYL_MAX_DIM]; double prim_vars_buff[20]; // 3D p=2. - double udrift_d[3*20]; // udrift_comp=3 for 3D p=2. + double udrift_d[3 * 20]; // udrift_comp=3 for 3D p=2. - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. // Must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange. @@ -114,17 +113,18 @@ gkyl_gk_neut_fluid_prim_vars_pressure_copy_cu_kernel(gkyl_gk_neut_fluid_prim_var // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->udrift_ncomp; + long count = linc1 * up->udrift_ncomp; - const double *moms_d = (const double*) gkyl_array_cfetch(moms, loc); - double* out_d = (double*) gkyl_array_fetch(out, loc); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + const double *moms_d = (const double *)gkyl_array_cfetch(moms, loc); + double *out_d = (double *)gkyl_array_fetch(out, loc); + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->udrift_get_sol_ker(count, xs, prim_vars_d); up->pressure_ker(up->gas_gamma, moms_d, udrift_d, prim_vars_d); - for (int i=0; inum_basis; i++) + for (int i = 0; i < up->num_basis; i++) { prim_vars_d[i] *= up->thermalE_fac; + } if (up->is_integrated) { out_d[out_coff] = up->integrated_fac * prim_vars_d[0]; @@ -132,34 +132,36 @@ gkyl_gk_neut_fluid_prim_vars_pressure_copy_cu_kernel(gkyl_gk_neut_fluid_prim_var } } -void gkyl_gk_neut_fluid_prim_vars_pressure_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_pressure_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { struct gkyl_range conf_range = up->mem_range; - gkyl_gk_neut_fluid_prim_vars_udrift_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev); + gkyl_gk_neut_fluid_prim_vars_udrift_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_gk_neut_fluid_prim_vars_pressure_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff); + gkyl_gk_neut_fluid_prim_vars_pressure_copy_cu_kernel<< > >( + up->on_dev, up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff + ); } -__global__ static void -gkyl_gk_neut_fluid_prim_vars_temp_set_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* moms) +__global__ static void gkyl_gk_neut_fluid_prim_vars_temp_set_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, const struct gkyl_array *moms +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. // Must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange. @@ -171,25 +173,23 @@ gkyl_gk_neut_fluid_prim_vars_temp_set_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up // fetch the correct count in the matrix (since we solve 1 system in each cell) long count = linc1; - const double *moms_d = (const double*) gkyl_array_cfetch(moms, loc); + const double *moms_d = (const double *)gkyl_array_cfetch(moms, loc); up->temp_set_prob_ker(count, As, xs, moms_d, up->gas_gamma, up->mass); } } -__global__ static void -gkyl_gk_neut_fluid_prim_vars_temp_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, const struct gkyl_array* moms, - struct gkyl_array* out, int out_coff) +__global__ static void gkyl_gk_neut_fluid_prim_vars_temp_copy_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + const struct gkyl_array *moms, struct gkyl_array *out, int out_coff +) { int idx[GKYL_MAX_DIM]; double prim_vars_buff[20]; // 3D p=2. - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. // Must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange. @@ -201,8 +201,8 @@ gkyl_gk_neut_fluid_prim_vars_temp_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* u // Fetch the correct count in the matrix (since we solve 1 system in each cell) long count = linc1; - double* out_d = (double*) gkyl_array_fetch(out, loc); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + double *out_d = (double *)gkyl_array_fetch(out, loc); + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->temp_get_sol_ker(count, xs, prim_vars_d); @@ -212,36 +212,38 @@ gkyl_gk_neut_fluid_prim_vars_temp_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* u } } -void gkyl_gk_neut_fluid_prim_vars_temp_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_temp_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { struct gkyl_range conf_range = up->mem_range; - gkyl_gk_neut_fluid_prim_vars_temp_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev); + gkyl_gk_neut_fluid_prim_vars_temp_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_gk_neut_fluid_prim_vars_temp_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff); + gkyl_gk_neut_fluid_prim_vars_temp_copy_cu_kernel<< > >( + up->on_dev, up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff + ); } -__global__ static void -gkyl_gk_neut_fluid_prim_vars_udrift_pressure_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, const struct gkyl_array* moms, - struct gkyl_array* out, int out_coff) +__global__ static void gkyl_gk_neut_fluid_prim_vars_udrift_pressure_copy_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + const struct gkyl_array *moms, struct gkyl_array *out, int out_coff +) { int idx[GKYL_MAX_DIM]; - double prim_vars_buff[(3+1)*20]; // udrift_comp=3 for 3D p=2. + double prim_vars_buff[(3 + 1) * 20]; // udrift_comp=3 for 3D p=2. - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. // Must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange. @@ -251,53 +253,57 @@ gkyl_gk_neut_fluid_prim_vars_udrift_pressure_copy_cu_kernel(gkyl_gk_neut_fluid_p // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->udrift_ncomp; + long count = linc1 * up->udrift_ncomp; - const double *moms_d = (const double*) gkyl_array_cfetch(moms, loc); - double* out_d = (double*) gkyl_array_fetch(out, loc); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + const double *moms_d = (const double *)gkyl_array_cfetch(moms, loc); + double *out_d = (double *)gkyl_array_fetch(out, loc); + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; - double* udrift_d = prim_vars_d; - double* pressure_d = &prim_vars_d[up->udrift_ncomp*up->num_basis]; + double *udrift_d = prim_vars_d; + double *pressure_d = &prim_vars_d[up->udrift_ncomp * up->num_basis]; up->udrift_get_sol_ker(count, xs, udrift_d); up->pressure_ker(up->gas_gamma, moms_d, udrift_d, pressure_d); if (up->is_integrated) { - for (int i=0; iudrift_ncomp+1; i++) - out_d[out_coff+i] = up->integrated_fac * prim_vars_d[i*up->num_basis]; + for (int i = 0; i < up->udrift_ncomp + 1; i++) { + out_d[out_coff + i] = up->integrated_fac * prim_vars_d[i * up->num_basis]; + } } } } -void gkyl_gk_neut_fluid_prim_vars_udrift_pressure_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_udrift_pressure_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { struct gkyl_range conf_range = up->mem_range; - gkyl_gk_neut_fluid_prim_vars_udrift_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev); + gkyl_gk_neut_fluid_prim_vars_udrift_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_gk_neut_fluid_prim_vars_udrift_pressure_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff); + gkyl_gk_neut_fluid_prim_vars_udrift_pressure_copy_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff + ); } -__global__ static void -gkyl_gk_neut_fluid_prim_vars_udrift_temp_set_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* moms) +__global__ static void gkyl_gk_neut_fluid_prim_vars_udrift_temp_set_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, const struct gkyl_array *moms +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. // Must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange. @@ -307,27 +313,25 @@ gkyl_gk_neut_fluid_prim_vars_udrift_temp_set_cu_kernel(gkyl_gk_neut_fluid_prim_v // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*(up->udrift_ncomp+1); + long count = linc1 * (up->udrift_ncomp + 1); - const double *moms_d = (const double*) gkyl_array_cfetch(moms, loc); + const double *moms_d = (const double *)gkyl_array_cfetch(moms, loc); up->udrift_temp_set_prob_ker(count, As, xs, moms_d, up->gas_gamma, up->mass); } } -__global__ static void -gkyl_gk_neut_fluid_prim_vars_udrift_temp_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, const struct gkyl_array* moms, - struct gkyl_array* out, int out_coff) +__global__ static void gkyl_gk_neut_fluid_prim_vars_udrift_temp_copy_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + const struct gkyl_array *moms, struct gkyl_array *out, int out_coff +) { int idx[GKYL_MAX_DIM]; - double prim_vars_buff[(3+1)*20]; // udrift_comp=3 for 3D p=2. + double prim_vars_buff[(3 + 1) * 20]; // udrift_comp=3 for 3D p=2. - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. // Must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange. @@ -337,50 +341,55 @@ gkyl_gk_neut_fluid_prim_vars_udrift_temp_copy_cu_kernel(gkyl_gk_neut_fluid_prim_ // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*(up->udrift_ncomp+1); + long count = linc1 * (up->udrift_ncomp + 1); - const double* moms_d = (const double*) gkyl_array_cfetch(moms, loc); - double* out_d = (double*) gkyl_array_fetch(out, loc); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + const double *moms_d = (const double *)gkyl_array_cfetch(moms, loc); + double *out_d = (double *)gkyl_array_fetch(out, loc); + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->udrift_temp_get_sol_ker(count, xs, prim_vars_d); if (up->is_integrated) { - for (int i=0; iudrift_ncomp+1; i++) - out_d[out_coff+i] = up->integrated_fac * prim_vars_d[i*up->num_basis]; + for (int i = 0; i < up->udrift_ncomp + 1; i++) { + out_d[out_coff + i] = up->integrated_fac * prim_vars_d[i * up->num_basis]; + } } } } -void gkyl_gk_neut_fluid_prim_vars_udrift_temp_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_udrift_temp_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { struct gkyl_range conf_range = up->mem_range; - gkyl_gk_neut_fluid_prim_vars_udrift_temp_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev); + gkyl_gk_neut_fluid_prim_vars_udrift_temp_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_gk_neut_fluid_prim_vars_udrift_temp_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff); + gkyl_gk_neut_fluid_prim_vars_udrift_temp_copy_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff + ); } -__global__ static void -gkyl_gk_neut_fluid_prim_vars_lte_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, const struct gkyl_array* moms, - struct gkyl_array* out, int out_coff) +__global__ static void gkyl_gk_neut_fluid_prim_vars_lte_copy_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + const struct gkyl_array *moms, struct gkyl_array *out, int out_coff +) { int idx[GKYL_MAX_DIM]; - double prim_vars_buff[(3+2)*20]; // udrift_comp=3 for 3D p=2. + double prim_vars_buff[(3 + 2) * 20]; // udrift_comp=3 for 3D p=2. - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. @@ -392,55 +401,58 @@ gkyl_gk_neut_fluid_prim_vars_lte_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*(up->udrift_ncomp+1); + long count = linc1 * (up->udrift_ncomp + 1); - const double* moms_d = (const double*) gkyl_array_cfetch(moms, loc); - double* out_d = (double*) gkyl_array_fetch(out, loc); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + const double *moms_d = (const double *)gkyl_array_cfetch(moms, loc); + double *out_d = (double *)gkyl_array_fetch(out, loc); + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->udrift_temp_get_sol_ker(count, xs, &prim_vars_d[up->num_basis]); // Scale rho and temp by 1/m. - for (int i=0; inum_basis; i++) { - prim_vars_d[out_coff+i] = moms_d[i]/up->mass; - prim_vars_d[out_coff+(up->udrift_ncomp+1)*up->num_basis+i] *= 1.0/up->mass; + for (int i = 0; i < up->num_basis; i++) { + prim_vars_d[out_coff + i] = moms_d[i] / up->mass; + prim_vars_d[out_coff + (up->udrift_ncomp + 1) * up->num_basis + i] *= 1.0 / up->mass; } if (up->is_integrated) { - for (int i=0; iudrift_ncomp+2; i++) - out_d[out_coff+i] = up->integrated_fac * prim_vars_d[i*up->num_basis]; + for (int i = 0; i < up->udrift_ncomp + 2; i++) { + out_d[out_coff + i] = up->integrated_fac * prim_vars_d[i * up->num_basis]; + } } } } -void gkyl_gk_neut_fluid_prim_vars_lte_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_lte_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { struct gkyl_range conf_range = up->mem_range; - gkyl_gk_neut_fluid_prim_vars_udrift_temp_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev); + gkyl_gk_neut_fluid_prim_vars_udrift_temp_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_gk_neut_fluid_prim_vars_lte_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff); + gkyl_gk_neut_fluid_prim_vars_lte_copy_cu_kernel<< > >( + up->on_dev, up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff + ); } -__global__ static void -gkyl_gk_neut_fluid_prim_vars_flow_energy_set_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* moms) +__global__ static void gkyl_gk_neut_fluid_prim_vars_flow_energy_set_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, const struct gkyl_array *moms +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. // Must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange. @@ -452,25 +464,23 @@ gkyl_gk_neut_fluid_prim_vars_flow_energy_set_cu_kernel(gkyl_gk_neut_fluid_prim_v // Fetch the correct count in the matrix (since we solve 1 system in each cell). long count = linc1; - const double *moms_d = (const double*) gkyl_array_cfetch(moms, loc); + const double *moms_d = (const double *)gkyl_array_cfetch(moms, loc); up->flowE_set_prob_ker(count, As, xs, moms_d); } } -__global__ static void -gkyl_gk_neut_fluid_prim_vars_flow_energy_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, const struct gkyl_array* moms, - struct gkyl_array* out, int out_coff) +__global__ static void gkyl_gk_neut_fluid_prim_vars_flow_energy_copy_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + const struct gkyl_array *moms, struct gkyl_array *out, int out_coff +) { int idx[GKYL_MAX_DIM]; double prim_vars_buff[20]; // 3D p=2. - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. // Must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange. @@ -482,9 +492,9 @@ gkyl_gk_neut_fluid_prim_vars_flow_energy_copy_cu_kernel(gkyl_gk_neut_fluid_prim_ // Fetch the correct count in the matrix (since we solve 1 system in each cell) long count = linc1; - const double* moms_d = (const double*) gkyl_array_cfetch(moms, loc); - double* out_d = (double*) gkyl_array_fetch(out, loc); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + const double *moms_d = (const double *)gkyl_array_cfetch(moms, loc); + double *out_d = (double *)gkyl_array_fetch(out, loc); + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; up->flowE_get_sol_ker(count, xs, prim_vars_d); @@ -494,36 +504,40 @@ gkyl_gk_neut_fluid_prim_vars_flow_energy_copy_cu_kernel(gkyl_gk_neut_fluid_prim_ } } -void gkyl_gk_neut_fluid_prim_vars_flow_energy_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_flow_energy_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { struct gkyl_range conf_range = up->mem_range; - gkyl_gk_neut_fluid_prim_vars_flow_energy_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev); + gkyl_gk_neut_fluid_prim_vars_flow_energy_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_gk_neut_fluid_prim_vars_flow_energy_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff); + gkyl_gk_neut_fluid_prim_vars_flow_energy_copy_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff + ); } __global__ static void -gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_copy_cu_kernel(gkyl_gk_neut_fluid_prim_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, const struct gkyl_array* moms, - struct gkyl_array* out, int out_coff) +gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_copy_cu_kernel( + gkyl_gk_neut_fluid_prim_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + const struct gkyl_array *moms, struct gkyl_array *out, int out_coff +) { int idx[GKYL_MAX_DIM]; - double prim_vars_buff[(3+3)*20]; // udrift_ncomp=3 for 3D p=2. + double prim_vars_buff[(3 + 3) * 20]; // udrift_ncomp=3 for 3D p=2. - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // Invert index from linc1 to idx. // Must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange. @@ -535,48 +549,57 @@ gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_copy_cu_kernel(gk // Fetch the correct count in the matrix (since we solve 1 system in each cell) long count = linc1; - const double* moms_d = (const double*) gkyl_array_cfetch(moms, loc); - double* out_d = (double*) gkyl_array_fetch(out, loc); - double* prim_vars_d = up->is_integrated? prim_vars_buff : &out_d[out_coff]; + const double *moms_d = (const double *)gkyl_array_cfetch(moms, loc); + double *out_d = (double *)gkyl_array_fetch(out, loc); + double *prim_vars_d = up->is_integrated ? prim_vars_buff : &out_d[out_coff]; - int fourth_comp_off = 4*up->num_basis; - for (int i=0; inum_basis; + for (int i = 0; i < fourth_comp_off; i++) { prim_vars_d[i] = moms_d[i]; + } up->flowE_get_sol_ker(count, xs, &prim_vars_d[fourth_comp_off]); - for (int i=0; inum_basis; i++) - prim_vars_d[5*up->num_basis+i] = moms_d[fourth_comp_off+i] - prim_vars_d[fourth_comp_off+i]; + for (int i = 0; i < up->num_basis; i++) { + prim_vars_d[5 * up->num_basis + i] = + moms_d[fourth_comp_off + i] - prim_vars_d[fourth_comp_off + i]; + } if (up->is_integrated) { - for (int i=0; iudrift_ncomp+3; i++) - out_d[out_coff+i] = up->integrated_fac * prim_vars_d[i*up->num_basis]; + for (int i = 0; i < up->udrift_ncomp + 3; i++) { + out_d[out_coff + i] = up->integrated_fac * prim_vars_d[i * up->num_basis]; + } } } } -void gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff) +void gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +) { struct gkyl_range conf_range = up->mem_range; - gkyl_gk_neut_fluid_prim_vars_flow_energy_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev); + gkyl_gk_neut_fluid_prim_vars_flow_energy_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, moms->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff); + gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_copy_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->xs->on_dev, conf_range, moms->on_dev, out->on_dev, out_coff + ); } // CUDA kernel to set device pointers to fluid vars kernel functions. // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol. -__global__ static void -gk_neut_fluid_prim_vars_set_cu_dev_ptrs(struct gkyl_gk_neut_fluid_prim_vars *up, - enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ static void gk_neut_fluid_prim_vars_set_cu_dev_ptrs( + struct gkyl_gk_neut_fluid_prim_vars *up, enum gkyl_basis_type b_type, int cdim, int poly_order +) { up->udrift_set_prob_ker = choose_udrift_set_prob_ker(b_type, cdim, poly_order); up->udrift_get_sol_ker = choose_udrift_get_sol_ker(b_type, cdim, poly_order); @@ -589,13 +612,14 @@ gk_neut_fluid_prim_vars_set_cu_dev_ptrs(struct gkyl_gk_neut_fluid_prim_vars *up, up->flowE_get_sol_ker = choose_flowE_get_sol_ker(b_type, cdim, poly_order); } -gkyl_gk_neut_fluid_prim_vars* -gkyl_gk_neut_fluid_prim_vars_cu_dev_new(double gas_gamma, double mass, const struct gkyl_basis* cbasis, - struct gkyl_rect_grid *grid, const struct gkyl_range *mem_range, - enum gkyl_gk_neut_fluid_prim_vars_type prim_vars_type, bool is_integrated) +gkyl_gk_neut_fluid_prim_vars *gkyl_gk_neut_fluid_prim_vars_cu_dev_new( + double gas_gamma, double mass, const struct gkyl_basis *cbasis, struct gkyl_rect_grid *grid, + const struct gkyl_range *mem_range, enum gkyl_gk_neut_fluid_prim_vars_type prim_vars_type, + bool is_integrated +) { - - struct gkyl_gk_neut_fluid_prim_vars *up = (struct gkyl_gk_neut_fluid_prim_vars*) gkyl_malloc(sizeof(gkyl_gk_neut_fluid_prim_vars)); + struct gkyl_gk_neut_fluid_prim_vars *up = + (struct gkyl_gk_neut_fluid_prim_vars *)gkyl_malloc(sizeof(gkyl_gk_neut_fluid_prim_vars)); up->gas_gamma = gas_gamma; up->mass = mass; @@ -609,47 +633,42 @@ gkyl_gk_neut_fluid_prim_vars_cu_dev_new(double gas_gamma, double mass, const str up->udrift_ncomp = 3; up->mem_range = *mem_range; up->is_integrated = is_integrated; - + up->integrated_fac = 0.0; if (up->is_integrated) { up->integrated_fac = 1.0; - for (int d=0; dcdim; d++) - up->integrated_fac *= (grid->dx[d]/2.0)*sqrt(2.0); + for (int d = 0; d < up->cdim; d++) { + up->integrated_fac *= (grid->dx[d] / 2.0) * sqrt(2.0); + } } int nprob; up->thermalE_fac = 0.0; if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_UDRIFT) { nprob = up->udrift_ncomp; - } - else if ( (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_PRESSURE) || - (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_THERMAL_ENERGY) ) { + } else if ((prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_PRESSURE) || + (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_THERMAL_ENERGY)) { nprob = up->udrift_ncomp; - up->thermalE_fac = prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_PRESSURE? 1.0 : 1.0/(up->gas_gamma-1.0); - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_TEMP) { + up->thermalE_fac = + prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_PRESSURE ? 1.0 : 1.0 / (up->gas_gamma - 1.0); + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_TEMP) { nprob = 1; - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_UDRIFT_PRESSURE) { + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_UDRIFT_PRESSURE) { nprob = up->udrift_ncomp; - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_UDRIFT_TEMP) { - nprob = up->udrift_ncomp+1; - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_LTE) { - nprob = up->udrift_ncomp+1; - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_FLOW_ENERGY) { + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_UDRIFT_TEMP) { + nprob = up->udrift_ncomp + 1; + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_LTE) { + nprob = up->udrift_ncomp + 1; + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_FLOW_ENERGY) { nprob = 1; - } - else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_MASS_MOMENTUM_FLOW_THERMAL_ENERGY) { + } else if (prim_vars_type == GKYL_GK_NEUT_FLUID_PRIM_VARS_MASS_MOMENTUM_FLOW_THERMAL_ENERGY) { nprob = 1; } // There are udrift_ncomp*range->volume linear systems to be solved // for 3 components of u: ux, uy, uz. - up->As = gkyl_nmat_cu_dev_new(nprob*mem_range->volume, up->num_basis, up->num_basis); - up->xs = gkyl_nmat_cu_dev_new(nprob*mem_range->volume, up->num_basis, 1); + up->As = gkyl_nmat_cu_dev_new(nprob * mem_range->volume, up->num_basis, up->num_basis); + up->xs = gkyl_nmat_cu_dev_new(nprob * mem_range->volume, up->num_basis, 1); if (up->poly_order > 1) { up->mem = gkyl_nmat_linsolve_lu_cu_dev_new(up->As->num, up->As->nr); } @@ -657,14 +676,14 @@ gkyl_gk_neut_fluid_prim_vars_cu_dev_new(double gas_gamma, double mass, const str up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_gk_neut_fluid_prim_vars *up_cu = (struct gkyl_gk_neut_fluid_prim_vars*) gkyl_cu_malloc(sizeof(gkyl_gk_neut_fluid_prim_vars)); + struct gkyl_gk_neut_fluid_prim_vars *up_cu = + (struct gkyl_gk_neut_fluid_prim_vars *)gkyl_cu_malloc(sizeof(gkyl_gk_neut_fluid_prim_vars)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_gk_neut_fluid_prim_vars), GKYL_CU_MEMCPY_H2D); - gk_neut_fluid_prim_vars_set_cu_dev_ptrs<<<1,1>>>(up_cu, b_type, cdim, poly_order); + gk_neut_fluid_prim_vars_set_cu_dev_ptrs<<<1, 1> > >(up_cu, b_type, cdim, poly_order); // set parent on_dev pointer up->on_dev = up_cu; return up; - } diff --git a/gyrokinetic/zero/gkgeom.c b/gyrokinetic/zero/gkgeom.c index c936990779..740d503f57 100644 --- a/gyrokinetic/zero/gkgeom.c +++ b/gyrokinetic/zero/gkgeom.c @@ -16,30 +16,39 @@ struct gkyl_gkgeom { struct gkyl_range rzlocal; // local range over which psiRZ is defined int num_rzbasis; // number of basis functions in RZ - struct { int max_iter; double eps; } root_param; - struct { int max_level; double eps; } quad_param; + struct { + int max_iter; + double eps; + } root_param; + struct { + int max_level; + double eps; + } quad_param; // pointer to root finder (depends on polyorder) - struct RdRdZ_sol (*calc_roots)(const double *psi, double psi0, double Z, - double xc[2], double dx[2]); + struct RdRdZ_sol (*calc_roots)( + const double *psi, double psi0, double Z, double xc[2], double dx[2] + ); - struct gkyl_gkgeom_stat stat; + struct gkyl_gkgeom_stat stat; }; // some helper functions -static inline double -choose_closest(double ref, double R[2], double out[2]) +static inline double choose_closest(double ref, double R[2], double out[2]) { - return fabs(R[0]-ref) < fabs(R[1]-ref) ? out[0] : out[1]; + return fabs(R[0] - ref) < fabs(R[1] - ref) ? out[0] : out[1]; } -static inline double SQ(double x) { return x*x; } +static inline double SQ(double x) +{ + return x * x; +} static inline int get_idx(int dir, double x, const struct gkyl_rect_grid *grid, const struct gkyl_range *range) { double xlower = grid->lower[dir], dx = grid->dx[dir]; - int idx = range->lower[dir] + (int) floor((x-xlower)/dx); + int idx = range->lower[dir] + (int)floor((x - xlower) / dx); return idx <= range->upper[dir] ? idx : range->upper[dir]; } @@ -53,18 +62,22 @@ struct RdRdZ_sol { static inline struct RdRdZ_sol calc_RdR_p1(const double *psi, double psi0, double Z, double xc[2], double dx[2]) { - struct RdRdZ_sol sol = { .nsol = 0 }; + struct RdRdZ_sol sol = {.nsol = 0}; + + double y = (Z - xc[1]) / (dx[1] * 0.5); - double y = (Z-xc[1])/(dx[1]*0.5); - - double rnorm = (-(1.732050807568877*psi[2]*y)/(3.0*psi[3]*y+1.732050807568877*psi[1]))+(2.0*psi0)/(3.0*psi[3]*y+1.732050807568877*psi[1])-(1.0*psi[0])/(3.0*psi[3]*y+1.732050807568877*psi[1]) ; + double rnorm = + (-(1.732050807568877 * psi[2] * y) / (3.0 * psi[3] * y + 1.732050807568877 * psi[1])) + + (2.0 * psi0) / (3.0 * psi[3] * y + 1.732050807568877 * psi[1]) - + (1.0 * psi[0]) / (3.0 * psi[3] * y + 1.732050807568877 * psi[1]); + + if ((-1 <= rnorm) && (rnorm < 1)) { + double drdznorm = -(3.0 * (2.0 * psi[3] * psi0 - 1.0 * psi[0] * psi[3] + psi[1] * psi[2])) / + SQ(3.0 * psi[3] * y + 1.732050807568877 * psi[1]); - if ((-1<=rnorm) && (rnorm < 1)) { - double drdznorm = -(3.0*(2.0*psi[3]*psi0-1.0*psi[0]*psi[3]+psi[1]*psi[2]))/SQ(3.0*psi[3]*y+1.732050807568877*psi[1]) ; - sol.nsol = 1; - sol.R[0] = rnorm*dx[0]*0.5 + xc[0]; - sol.dRdZ[0] = drdznorm*dx[0]/dx[1]; + sol.R[0] = rnorm * dx[0] * 0.5 + xc[0]; + sol.dRdZ[0] = drdznorm * dx[0] / dx[1]; } return sol; } @@ -73,48 +86,58 @@ calc_RdR_p1(const double *psi, double psi0, double Z, double xc[2], double dx[2] static inline struct RdRdZ_sol calc_RdR_ser_p2(const double *psi, double psi0, double Z, double xc[2], double dx[2]) { - struct RdRdZ_sol sol = { .nsol = 0 }; - double y = (Z-xc[1])/(dx[1]*0.5); + struct RdRdZ_sol sol = {.nsol = 0}; + double y = (Z - xc[1]) / (dx[1] * 0.5); - double aq = 2.904737509655563*psi[6]*y+1.677050983124842*psi[4]; - double bq = 2.904737509655563*psi[7]*SQ(y)+1.5*psi[3]*y-0.9682458365518543*psi[7]+0.8660254037844386*psi[1]; - double cq = 1.677050983124842*psi[5]*SQ(y)-0.9682458365518543*psi[6]*y+0.8660254037844386*psi[2]*y-1.0*psi0-0.5590169943749475*psi[5]-0.5590169943749475*psi[4]+0.5*psi[0]; - double delta2 = bq*bq - 4*aq*cq; + double aq = 2.904737509655563 * psi[6] * y + 1.677050983124842 * psi[4]; + double bq = 2.904737509655563 * psi[7] * SQ(y) + 1.5 * psi[3] * y - 0.9682458365518543 * psi[7] + + 0.8660254037844386 * psi[1]; + double cq = 1.677050983124842 * psi[5] * SQ(y) - 0.9682458365518543 * psi[6] * y + + 0.8660254037844386 * psi[2] * y - 1.0 * psi0 - 0.5590169943749475 * psi[5] - + 0.5590169943749475 * psi[4] + 0.5 * psi[0]; + double delta2 = bq * bq - 4 * aq * cq; if (delta2 > 0) { double r1, r2; double delta = sqrt(delta2); // compute both roots - if (bq>=0) { - r1 = (-bq-delta)/(2*aq); - r2 = 2*cq/(-bq-delta); - } - else { - r1 = 2*cq/(-bq+delta); - r2 = (-bq+delta)/(2*aq); + if (bq >= 0) { + r1 = (-bq - delta) / (2 * aq); + r2 = 2 * cq / (-bq - delta); + } else { + r1 = 2 * cq / (-bq + delta); + r2 = (-bq + delta) / (2 * aq); } int sidx = 0; - if ((-1<=r1) && (r1 < 1)) { + if ((-1 <= r1) && (r1 < 1)) { sol.nsol += 1; - sol.R[sidx] = r1*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r1 * dx[0] * 0.5 + xc[0]; double x = r1; - double C = 5.809475019311126*psi[7]*x*y+3.354101966249685*psi[5]*y+2.904737509655563*psi[6]*SQ(x)+1.5*psi[3]*x-0.9682458365518543*psi[6]+0.8660254037844386*psi[2]; - double A = 2.904737509655563*psi[7]*SQ(y)+5.809475019311126*psi[6]*x*y+1.5*psi[3]*y+3.354101966249685*psi[4]*x-0.9682458365518543*psi[7]+0.8660254037844386*psi[1]; - sol.dRdZ[sidx] = -C/A*dx[0]/dx[1]; - + double C = 5.809475019311126 * psi[7] * x * y + 3.354101966249685 * psi[5] * y + + 2.904737509655563 * psi[6] * SQ(x) + 1.5 * psi[3] * x - + 0.9682458365518543 * psi[6] + 0.8660254037844386 * psi[2]; + double A = 2.904737509655563 * psi[7] * SQ(y) + 5.809475019311126 * psi[6] * x * y + + 1.5 * psi[3] * y + 3.354101966249685 * psi[4] * x - 0.9682458365518543 * psi[7] + + 0.8660254037844386 * psi[1]; + sol.dRdZ[sidx] = -C / A * dx[0] / dx[1]; + sidx += 1; } - if ((-1<=r2) && (r2 < 1)) { + if ((-1 <= r2) && (r2 < 1)) { sol.nsol += 1; - sol.R[sidx] = r2*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r2 * dx[0] * 0.5 + xc[0]; double x = r2; - double C = 5.809475019311126*psi[7]*x*y+3.354101966249685*psi[5]*y+2.904737509655563*psi[6]*SQ(x)+1.5*psi[3]*x-0.9682458365518543*psi[6]+0.8660254037844386*psi[2]; - double A = 2.904737509655563*psi[7]*SQ(y)+5.809475019311126*psi[6]*x*y+1.5*psi[3]*y+3.354101966249685*psi[4]*x-0.9682458365518543*psi[7]+0.8660254037844386*psi[1]; - sol.dRdZ[sidx] = -C/A*dx[0]/dx[1]; - + double C = 5.809475019311126 * psi[7] * x * y + 3.354101966249685 * psi[5] * y + + 2.904737509655563 * psi[6] * SQ(x) + 1.5 * psi[3] * x - + 0.9682458365518543 * psi[6] + 0.8660254037844386 * psi[2]; + double A = 2.904737509655563 * psi[7] * SQ(y) + 5.809475019311126 * psi[6] * x * y + + 1.5 * psi[3] * y + 3.354101966249685 * psi[4] * x - 0.9682458365518543 * psi[7] + + 0.8660254037844386 * psi[1]; + sol.dRdZ[sidx] = -C / A * dx[0] / dx[1]; + sidx += 1; } } @@ -125,48 +148,58 @@ calc_RdR_ser_p2(const double *psi, double psi0, double Z, double xc[2], double d static inline struct RdRdZ_sol calc_RdR_ten_p2(const double *psi, double psi0, double Z, double xc[2], double dx[2]) { - struct RdRdZ_sol sol = { .nsol = 0 }; - double y = (Z-xc[1])/(dx[1]*0.5); + struct RdRdZ_sol sol = {.nsol = 0}; + double y = (Z - xc[1]) / (dx[1] * 0.5); - double aq = 2.904737509655563*psi[6]*y+1.677050983124842*psi[4]; - double bq = 2.904737509655563*psi[7]*SQ(y)+1.5*psi[3]*y-0.9682458365518543*psi[7]+0.8660254037844386*psi[1]; - double cq = 1.677050983124842*psi[5]*SQ(y)-0.9682458365518543*psi[6]*y+0.8660254037844386*psi[2]*y-1.0*psi0-0.5590169943749475*psi[5]-0.5590169943749475*psi[4]+0.5*psi[0]; - double delta2 = bq*bq - 4*aq*cq; + double aq = 2.904737509655563 * psi[6] * y + 1.677050983124842 * psi[4]; + double bq = 2.904737509655563 * psi[7] * SQ(y) + 1.5 * psi[3] * y - 0.9682458365518543 * psi[7] + + 0.8660254037844386 * psi[1]; + double cq = 1.677050983124842 * psi[5] * SQ(y) - 0.9682458365518543 * psi[6] * y + + 0.8660254037844386 * psi[2] * y - 1.0 * psi0 - 0.5590169943749475 * psi[5] - + 0.5590169943749475 * psi[4] + 0.5 * psi[0]; + double delta2 = bq * bq - 4 * aq * cq; if (delta2 > 0) { double r1, r2; double delta = sqrt(delta2); // compute both roots - if (bq>=0) { - r1 = (-bq-delta)/(2*aq); - r2 = 2*cq/(-bq-delta); - } - else { - r1 = 2*cq/(-bq+delta); - r2 = (-bq+delta)/(2*aq); + if (bq >= 0) { + r1 = (-bq - delta) / (2 * aq); + r2 = 2 * cq / (-bq - delta); + } else { + r1 = 2 * cq / (-bq + delta); + r2 = (-bq + delta) / (2 * aq); } int sidx = 0; - if ((-1<=r1) && (r1 < 1)) { + if ((-1 <= r1) && (r1 < 1)) { sol.nsol += 1; - sol.R[sidx] = r1*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r1 * dx[0] * 0.5 + xc[0]; double x = r1; - double C = 5.809475019311126*psi[7]*x*y+3.354101966249685*psi[5]*y+2.904737509655563*psi[6]*SQ(x)+1.5*psi[3]*x-0.9682458365518543*psi[6]+0.8660254037844386*psi[2]; - double A = 2.904737509655563*psi[7]*SQ(y)+5.809475019311126*psi[6]*x*y+1.5*psi[3]*y+3.354101966249685*psi[4]*x-0.9682458365518543*psi[7]+0.8660254037844386*psi[1]; - sol.dRdZ[sidx] = -C/A*dx[0]/dx[1]; - + double C = 5.809475019311126 * psi[7] * x * y + 3.354101966249685 * psi[5] * y + + 2.904737509655563 * psi[6] * SQ(x) + 1.5 * psi[3] * x - + 0.9682458365518543 * psi[6] + 0.8660254037844386 * psi[2]; + double A = 2.904737509655563 * psi[7] * SQ(y) + 5.809475019311126 * psi[6] * x * y + + 1.5 * psi[3] * y + 3.354101966249685 * psi[4] * x - 0.9682458365518543 * psi[7] + + 0.8660254037844386 * psi[1]; + sol.dRdZ[sidx] = -C / A * dx[0] / dx[1]; + sidx += 1; } - if ((-1<=r2) && (r2 < 1)) { + if ((-1 <= r2) && (r2 < 1)) { sol.nsol += 1; - sol.R[sidx] = r2*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r2 * dx[0] * 0.5 + xc[0]; double x = r2; - double C = 5.809475019311126*psi[7]*x*y+3.354101966249685*psi[5]*y+2.904737509655563*psi[6]*SQ(x)+1.5*psi[3]*x-0.9682458365518543*psi[6]+0.8660254037844386*psi[2]; - double A = 2.904737509655563*psi[7]*SQ(y)+5.809475019311126*psi[6]*x*y+1.5*psi[3]*y+3.354101966249685*psi[4]*x-0.9682458365518543*psi[7]+0.8660254037844386*psi[1]; - sol.dRdZ[sidx] = -C/A*dx[0]/dx[1]; - + double C = 5.809475019311126 * psi[7] * x * y + 3.354101966249685 * psi[5] * y + + 2.904737509655563 * psi[6] * SQ(x) + 1.5 * psi[3] * x - + 0.9682458365518543 * psi[6] + 0.8660254037844386 * psi[2]; + double A = 2.904737509655563 * psi[7] * SQ(y) + 5.809475019311126 * psi[6] * x * y + + 1.5 * psi[3] * y + 3.354101966249685 * psi[4] * x - 0.9682458365518543 * psi[7] + + 0.8660254037844386 * psi[1]; + sol.dRdZ[sidx] = -C / A * dx[0] / dx[1]; + sidx += 1; } } @@ -178,23 +211,22 @@ calc_RdR_ten_p2(const double *psi, double psi0, double Z, double xc[2], double d // copied in the array R and dR. The calling function must ensure that // these arrays are big enough to hold all roots required static int -R_psiZ(const gkyl_gkgeom *geo, double psi, double Z, int nmaxroots, - double *R, double *dR) +R_psiZ(const gkyl_gkgeom *geo, double psi, double Z, int nmaxroots, double *R, double *dR) { int zcell = get_idx(1, Z, &geo->rzgrid, &geo->rzlocal); int sidx = 0; - int idx[2] = { 0, zcell }; - double dx[2] = { geo->rzgrid.dx[0], geo->rzgrid.dx[1] }; - + int idx[2] = {0, zcell}; + double dx[2] = {geo->rzgrid.dx[0], geo->rzgrid.dx[1]}; + struct gkyl_range rangeR; - gkyl_range_deflate(&rangeR, &geo->rzlocal, (int[]) { 0, 1 }, (int[]) { 0, zcell }); + gkyl_range_deflate(&rangeR, &geo->rzlocal, (int[]){0, 1}, (int[]){0, zcell}); struct gkyl_range_iter riter; gkyl_range_iter_init(&riter, &rangeR); - + // loop over all R cells to find psi crossing - while (gkyl_range_iter_next(&riter) && sidx<=nmaxroots) { + while (gkyl_range_iter_next(&riter) && sidx <= nmaxroots) { long loc = gkyl_range_idx(&rangeR, riter.idx); const double *psih = gkyl_array_cfetch(geo->psiRZ, loc); @@ -203,13 +235,14 @@ R_psiZ(const gkyl_gkgeom *geo, double psi, double Z, int nmaxroots, gkyl_rect_grid_cell_center(&geo->rzgrid, idx, xc); struct RdRdZ_sol sol = geo->calc_roots(psih, psi, Z, xc, dx); - - if (sol.nsol > 0) - for (int s=0; s 0) { + for (int s = 0; s < sol.nsol; ++s) { R[sidx] = sol.R[s]; dR[sidx] = sol.dRdZ[s]; sidx += 1; } + } } return sidx; } @@ -222,17 +255,16 @@ struct contour_ctx { }; // Function to pass to numerical quadrature to integrate along a contour -static inline double -contour_func(double Z, void *ctx) +static inline double contour_func(double Z, void *ctx) { struct contour_ctx *c = ctx; c->ncall += 1; - double R[2] = { 0 }, dR[2] = { 0 }; - + double R[2] = {0}, dR[2] = {0}; + int nr = R_psiZ(c->geo, c->psi, Z, 2, R, dR); double dRdZ = nr == 1 ? dR[0] : choose_closest(c->last_R, R, dR); - - return nr>0 ? sqrt(1+dRdZ*dRdZ) : 0.0; + + return nr > 0 ? sqrt(1 + dRdZ * dRdZ) : 0.0; } // Integrates along a specified contour, optionally using a "memory" @@ -241,55 +273,44 @@ contour_func(double Z, void *ctx) // over z-cells. This needs to be done as the DG representation is, // well, discontinuous, and adaptive quadrature struggles with such // functions. -static double -integrate_psi_contour_memo(const gkyl_gkgeom *geo, double psi, - double zmin, double zmax, double rclose, - bool use_memo, bool fill_memo, double *memo) +static double integrate_psi_contour_memo( + const gkyl_gkgeom *geo, double psi, double zmin, double zmax, double rclose, bool use_memo, + bool fill_memo, double *memo +) { - struct contour_ctx ctx = { - .geo = geo, - .psi = psi, - .ncall = 0, - .last_R = rclose - }; + struct contour_ctx ctx = {.geo = geo, .psi = psi, .ncall = 0, .last_R = rclose}; int nlevels = geo->quad_param.max_level; double eps = geo->quad_param.eps; - + double dz = geo->rzgrid.dx[1]; double zlo = geo->rzgrid.lower[1]; int izlo = geo->rzlocal.lower[1], izup = geo->rzlocal.upper[1]; - + int ilo = get_idx(1, zmin, &geo->rzgrid, &geo->rzlocal); int iup = get_idx(1, zmax, &geo->rzgrid, &geo->rzlocal); double res = 0.0; - for (int i=ilo; i<=iup; ++i) { - double z1 = gkyl_median(zmin, zlo+(i-izlo)*dz, zlo+(i-izlo+1)*dz); - double z2 = gkyl_median(zmax, zlo+(i-izlo)*dz, zlo+(i-izlo+1)*dz); - + for (int i = ilo; i <= iup; ++i) { + double z1 = gkyl_median(zmin, zlo + (i - izlo) * dz, zlo + (i - izlo + 1) * dz); + double z2 = gkyl_median(zmax, zlo + (i - izlo) * dz, zlo + (i - izlo + 1) * dz); + if (z1 < z2) { if (use_memo) { if (fill_memo) { - struct gkyl_qr_res res_local = - gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); - memo[i-izlo] = res_local.res; + struct gkyl_qr_res res_local = gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); + memo[i - izlo] = res_local.res; res += res_local.res; - } - else { - if (z2-z1 == dz) { - res += memo[i-izlo]; - } - else { - struct gkyl_qr_res res_local = - gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); + } else { + if (z2 - z1 == dz) { + res += memo[i - izlo]; + } else { + struct gkyl_qr_res res_local = gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); res += res_local.res; } } - } - else { - struct gkyl_qr_res res_local = - gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); + } else { + struct gkyl_qr_res res_local = gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); res += res_local.res; } } @@ -306,21 +327,18 @@ struct arc_length_ctx { double psi, rclose, zmin, arcL; }; - // Function to pass to root-finder to find Z location for given arc-length -static inline double -arc_length_func(double Z, void *ctx) +static inline double arc_length_func(double Z, void *ctx) { struct arc_length_ctx *actx = ctx; double *arc_memo = actx->arc_memo; double psi = actx->psi, rclose = actx->rclose, zmin = actx->zmin, arcL = actx->arcL; - double ival = integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, - true, false, arc_memo) - arcL; + double ival = + integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, true, false, arc_memo) - arcL; return ival; } -gkyl_gkgeom* -gkyl_gkgeom_new(const struct gkyl_gkgeom_inp *inp) +gkyl_gkgeom *gkyl_gkgeom_new(const struct gkyl_gkgeom_inp *inp) { struct gkyl_gkgeom *geo = gkyl_malloc(sizeof(*geo)); @@ -329,114 +347,109 @@ gkyl_gkgeom_new(const struct gkyl_gkgeom_inp *inp) geo->num_rzbasis = inp->rzbasis->num_basis; memcpy(&geo->rzlocal, inp->rzlocal, sizeof(struct gkyl_range)); - geo->root_param.eps = - inp->root_param.eps > 0 ? inp->root_param.eps : 1e-10; - geo->root_param.max_iter = - inp->root_param.max_iter > 0 ? inp->root_param.max_iter : 100; + geo->root_param.eps = inp->root_param.eps > 0 ? inp->root_param.eps : 1e-10; + geo->root_param.max_iter = inp->root_param.max_iter > 0 ? inp->root_param.max_iter : 100; - geo->quad_param.max_level = - inp->quad_param.max_levels > 0 ? inp->quad_param.max_levels : 10; - geo->quad_param.eps = - inp->quad_param.eps > 0 ? inp->quad_param.eps : 1e-10; + geo->quad_param.max_level = inp->quad_param.max_levels > 0 ? inp->quad_param.max_levels : 10; + geo->quad_param.eps = inp->quad_param.eps > 0 ? inp->quad_param.eps : 1e-10; if (inp->rzbasis->poly_order == 1) { geo->calc_roots = calc_RdR_p1; - } - else if (inp->rzbasis->poly_order == 2) { - if (inp->rzbasis->b_type == GKYL_BASIS_MODAL_SERENDIPITY) + } else if (inp->rzbasis->poly_order == 2) { + if (inp->rzbasis->b_type == GKYL_BASIS_MODAL_SERENDIPITY) { geo->calc_roots = calc_RdR_ser_p2; - else + } else { geo->calc_roots = calc_RdR_ten_p2; + } } - geo->stat = (struct gkyl_gkgeom_stat) { }; - + geo->stat = (struct gkyl_gkgeom_stat){}; + return geo; } -double -gkyl_gkgeom_integrate_psi_contour(const gkyl_gkgeom *geo, double psi, - double zmin, double zmax, double rclose) +double gkyl_gkgeom_integrate_psi_contour( + const gkyl_gkgeom *geo, double psi, double zmin, double zmax, double rclose +) { - return integrate_psi_contour_memo(geo, psi, zmin, zmax, rclose, - false, false, 0); + return integrate_psi_contour_memo(geo, psi, zmin, zmax, rclose, false, false, 0); } -int -gkyl_gkgeom_R_psiZ(const gkyl_gkgeom *geo, double psi, double Z, int nmaxroots, - double *R, double *dR) +int gkyl_gkgeom_R_psiZ( + const gkyl_gkgeom *geo, double psi, double Z, int nmaxroots, double *R, double *dR +) { return R_psiZ(geo, psi, Z, nmaxroots, R, dR); } -// write out nodal coordinates +// write out nodal coordinates static void -write_nodal_coordinates(const char *nm, struct gkyl_range *nrange, - struct gkyl_array *nodes) +write_nodal_coordinates(const char *nm, struct gkyl_range *nrange, struct gkyl_array *nodes) { - double lower[3] = { 0.0, 0.0, 0.0 }; - double upper[3] = { 1.0, 1.0, 1.0 }; + double lower[3] = {0.0, 0.0, 0.0}; + double upper[3] = {1.0, 1.0, 1.0}; int cells[3]; - for (int i=0; indim; ++i) + for (int i = 0; i < nrange->ndim; ++i) { cells[i] = gkyl_range_shape(nrange, i); - + } + struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, 2, lower, upper, cells); gkyl_grid_sub_array_write(&grid, nrange, 0, nodes, nm); } -void -gkyl_gkgeom_calcgeom(const gkyl_gkgeom *geo, - const struct gkyl_gkgeom_geo_inp *inp, struct gkyl_array *mapc2p) +void gkyl_gkgeom_calcgeom( + const gkyl_gkgeom *geo, const struct gkyl_gkgeom_geo_inp *inp, struct gkyl_array *mapc2p +) { int poly_order = inp->cbasis->poly_order; - int nodes[3] = { 1, 1, 1 }; - if (poly_order == 1) - for (int d=0; dcgrid->ndim; ++d) - nodes[d] = inp->cgrid->cells[d]+1; - if (poly_order == 2) - for (int d=0; dcgrid->ndim; ++d) - nodes[d] = 2*inp->cgrid->cells[d]+1; + int nodes[3] = {1, 1, 1}; + if (poly_order == 1) { + for (int d = 0; d < inp->cgrid->ndim; ++d) { + nodes[d] = inp->cgrid->cells[d] + 1; + } + } + if (poly_order == 2) { + for (int d = 0; d < inp->cgrid->ndim; ++d) { + nodes[d] = 2 * inp->cgrid->cells[d] + 1; + } + } struct gkyl_range nrange; gkyl_range_init_from_shape(&nrange, inp->cgrid->ndim, nodes); struct gkyl_array *mc2p = gkyl_array_new(GKYL_DOUBLE, inp->cgrid->ndim, nrange.volume); enum { TH_IDX, PH_IDX, AL_IDX }; // arrangement of computational coordinates - enum { R_IDX, Z_IDX }; // arrangement of physical coordinates - - double dtheta = inp->cgrid->dx[TH_IDX], - dphi = inp->cgrid->dx[PH_IDX], - dalpha = inp->cgrid->dx[AL_IDX]; - - double theta_lo = inp->cgrid->lower[TH_IDX], - phi_lo = inp->cgrid->lower[PH_IDX], - alpha_lo = inp->cgrid->lower[AL_IDX]; + enum { R_IDX, Z_IDX }; // arrangement of physical coordinates + + double dtheta = inp->cgrid->dx[TH_IDX], dphi = inp->cgrid->dx[PH_IDX], + dalpha = inp->cgrid->dx[AL_IDX]; + + double theta_lo = inp->cgrid->lower[TH_IDX], phi_lo = inp->cgrid->lower[PH_IDX], + alpha_lo = inp->cgrid->lower[AL_IDX]; double dx_fact = poly_order == 1 ? 1 : 0.5; - dtheta *= dx_fact; dphi *= dx_fact; dalpha *= dx_fact; + dtheta *= dx_fact; + dphi *= dx_fact; + dalpha *= dx_fact; double rclose = inp->rclose; int nzcells = geo->rzgrid.cells[1]; double *arc_memo = gkyl_malloc(sizeof(double[nzcells])); - struct arc_length_ctx arc_ctx = { - .geo = geo, - .arc_memo = arc_memo - }; - - int cidx[2] = { 0 }; - for (int ip=nrange.lower[PH_IDX]; ip<=nrange.upper[PH_IDX]; ++ip) { + struct arc_length_ctx arc_ctx = {.geo = geo, .arc_memo = arc_memo}; + int cidx[2] = {0}; + for (int ip = nrange.lower[PH_IDX]; ip <= nrange.upper[PH_IDX]; ++ip) { double zmin = inp->zmin, zmax = inp->zmax; - double psi_curr = phi_lo + ip*dphi; - double arcL = integrate_psi_contour_memo(geo, psi_curr, zmin, zmax, rclose, - true, true, arc_memo); + double psi_curr = phi_lo + ip * dphi; + double arcL = + integrate_psi_contour_memo(geo, psi_curr, zmin, zmax, rclose, true, true, arc_memo); - double delta_arcL = arcL/(poly_order*inp->cgrid->cells[TH_IDX]); + double delta_arcL = arcL / (poly_order * inp->cgrid->cells[TH_IDX]); cidx[PH_IDX] = ip; @@ -445,14 +458,14 @@ gkyl_gkgeom_calcgeom(const gkyl_gkgeom *geo, cidx[TH_IDX] = nrange.lower[TH_IDX]; double *mc2p_n = gkyl_array_fetch(mc2p, gkyl_range_idx(&nrange, cidx)); mc2p_n[Z_IDX] = zmin; - double R[2] = { 0 }, dR[2] = { 0 }; + double R[2] = {0}, dR[2] = {0}; int nr = R_psiZ(geo, psi_curr, zmin, 2, R, dR); mc2p_n[R_IDX] = choose_closest(rclose, R, R); - } while(0); + } while (0); // set node coordinates of rest of nodes double arcL_curr = 0.0; - for (int it=nrange.lower[TH_IDX]+1; itroot_param.max_iter, 1e-10); + struct gkyl_qr_res res = gkyl_ridders( + arc_length_func, &arc_ctx, zmin, zmax, -arcL_curr, arcL - arcL_curr, + geo->root_param.max_iter, 1e-10 + ); double z_curr = res.res; ((gkyl_gkgeom *)geo)->stat.nroot_cont_calls += res.nevals; - double R[2] = { 0 }, dR[2] = { 0 }; + double R[2] = {0}, dR[2] = {0}; int nr = R_psiZ(geo, psi_curr, z_curr, 2, R, dR); double r_curr = choose_closest(rclose, R, R); @@ -481,27 +495,26 @@ gkyl_gkgeom_calcgeom(const gkyl_gkgeom *geo, cidx[TH_IDX] = nrange.upper[TH_IDX]; double *mc2p_n = gkyl_array_fetch(mc2p, gkyl_range_idx(&nrange, cidx)); mc2p_n[Z_IDX] = zmax; - double R[2] = { 0 }, dR[2] = { 0 }; + double R[2] = {0}, dR[2] = {0}; int nr = R_psiZ(geo, psi_curr, zmax, 2, R, dR); mc2p_n[R_IDX] = choose_closest(rclose, R, R); } while (0); } - if (inp->write_node_coord_array) + if (inp->write_node_coord_array) { write_nodal_coordinates(inp->node_file_nm, &nrange, mc2p); + } gkyl_free(arc_memo); - gkyl_array_release(mc2p); + gkyl_array_release(mc2p); } -struct gkyl_gkgeom_stat -gkyl_gkgeom_get_stat(const gkyl_gkgeom *geo) +struct gkyl_gkgeom_stat gkyl_gkgeom_get_stat(const gkyl_gkgeom *geo) { return geo->stat; } -void -gkyl_gkgeom_release(gkyl_gkgeom *geo) +void gkyl_gkgeom_release(gkyl_gkgeom *geo) { gkyl_array_release(geo->psiRZ); gkyl_free(geo); diff --git a/gyrokinetic/zero/gkyl_ambi_bolt_potential.h b/gyrokinetic/zero/gkyl_ambi_bolt_potential.h index 02c9bfdde9..cda32c718b 100644 --- a/gyrokinetic/zero/gkyl_ambi_bolt_potential.h +++ b/gyrokinetic/zero/gkyl_ambi_bolt_potential.h @@ -20,9 +20,10 @@ typedef struct gkyl_ambi_bolt_potential gkyl_ambi_bolt_potential; * @param use_gpu Boolean indicating whether to use the GPU. * @return New updater pointer. */ -gkyl_ambi_bolt_potential* gkyl_ambi_bolt_potential_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, double mass_e, double charge_e, double temp_e, - bool use_gpu); +gkyl_ambi_bolt_potential *gkyl_ambi_bolt_potential_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, double mass_e, double charge_e, + double temp_e, bool use_gpu +); /** * Compute the ion density and electrostatic potential at the sheath entrance. @@ -44,12 +45,12 @@ gkyl_ambi_bolt_potential* gkyl_ambi_bolt_potential_new(const struct gkyl_rect_gr * @param Jm0i Ion number density times the conf-space Jacobian. * @param sheath_vals Ion number density and potential at the sheath entrance. */ -void -gkyl_ambi_bolt_potential_sheath_calc(struct gkyl_ambi_bolt_potential *up, enum gkyl_edge_loc edge, - const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, - const struct gkyl_array *cmag, const struct gkyl_array *jacobtot_inv, - const struct gkyl_array *gammai, const struct gkyl_array *m0i, const struct gkyl_array *Jm0i, - struct gkyl_array *sheath_vals); +void gkyl_ambi_bolt_potential_sheath_calc( + struct gkyl_ambi_bolt_potential *up, enum gkyl_edge_loc edge, const struct gkyl_range *skin_r, + const struct gkyl_range *ghost_r, const struct gkyl_array *cmag, + const struct gkyl_array *jacobtot_inv, const struct gkyl_array *gammai, + const struct gkyl_array *m0i, const struct gkyl_array *Jm0i, struct gkyl_array *sheath_vals +); /** * Compute the electrostatic potential in the domain as @@ -63,11 +64,11 @@ gkyl_ambi_bolt_potential_sheath_calc(struct gkyl_ambi_bolt_potential *up, enum g * @param sheath_vals Ion number density and potential at the sheath entrance. * @param phi electrostatic potential. */ -void -gkyl_ambi_bolt_potential_phi_calc(struct gkyl_ambi_bolt_potential *up, - const struct gkyl_range *local_r, const struct gkyl_range *extlocal_r, - const struct gkyl_array *m0i, const struct gkyl_array *sheath_vals, - struct gkyl_array *phi); +void gkyl_ambi_bolt_potential_phi_calc( + struct gkyl_ambi_bolt_potential *up, const struct gkyl_range *local_r, + const struct gkyl_range *extlocal_r, const struct gkyl_array *m0i, + const struct gkyl_array *sheath_vals, struct gkyl_array *phi +); /** * Delete updater. diff --git a/gyrokinetic/zero/gkyl_ambi_bolt_potential_priv.h b/gyrokinetic/zero/gkyl_ambi_bolt_potential_priv.h index a6bc479b95..77731f3415 100644 --- a/gyrokinetic/zero/gkyl_ambi_bolt_potential_priv.h +++ b/gyrokinetic/zero/gkyl_ambi_bolt_potential_priv.h @@ -7,42 +7,56 @@ #include // Function pointer type for sheath entrance calculations. -typedef void (*sheathker_t)(const double sheathDirDx, double q_e, double m_e, double T_e, - const double *cmag, const double *jacobtotInv, - const double *GammaJac_i, const double *m0Ion, const double *m0JacIon, double *out); +typedef void (*sheathker_t)( + const double sheathDirDx, double q_e, double m_e, double T_e, const double *cmag, + const double *jacobtotInv, const double *GammaJac_i, const double *m0Ion, const double *m0JacIon, + double *out +); // Function pointer type for phi calculation. -typedef void (*phiker_t)(double q_e, double T_e, - const double *m0JacIon, const double *sheathvals, double *phi); +typedef void (*phiker_t)( + double q_e, double T_e, const double *m0JacIon, const double *sheathvals, double *phi +); -typedef struct { sheathker_t kernels[2]; } sheath_calc_kern_loc_list; -typedef struct { sheath_calc_kern_loc_list list[2]; } sheath_calc_kern_edge_list; +typedef struct { + sheathker_t kernels[2]; +} sheath_calc_kern_loc_list; +typedef struct { + sheath_calc_kern_loc_list list[2]; +} sheath_calc_kern_edge_list; -typedef struct { phiker_t kernels[2]; } phi_calc_kern_list; +typedef struct { + phiker_t kernels[2]; +} phi_calc_kern_list; // Serendipity sheath_calc kernels. -GKYL_CU_D -static const sheath_calc_kern_edge_list ser_sheath_calc_list[] = { - // 1x - { .list = {{ambi_bolt_potential_sheath_calc_lower_1x_ser_p1, ambi_bolt_potential_sheath_calc_upper_1x_ser_p1}, - {ambi_bolt_potential_sheath_calc_lower_1x_ser_p2, ambi_bolt_potential_sheath_calc_upper_1x_ser_p2}}, }, +GKYL_CU_D static const sheath_calc_kern_edge_list ser_sheath_calc_list[] = { // 1x + {.list = + {{ambi_bolt_potential_sheath_calc_lower_1x_ser_p1, + ambi_bolt_potential_sheath_calc_upper_1x_ser_p1}, + {ambi_bolt_potential_sheath_calc_lower_1x_ser_p2, + ambi_bolt_potential_sheath_calc_upper_1x_ser_p2}}}, // 2x - { .list = {{ambi_bolt_potential_sheath_calc_lower_2x_ser_p1, ambi_bolt_potential_sheath_calc_upper_2x_ser_p1}, - {ambi_bolt_potential_sheath_calc_lower_2x_ser_p2, ambi_bolt_potential_sheath_calc_upper_2x_ser_p2}}, }, -// // 3x - { .list = {{ambi_bolt_potential_sheath_calc_lower_3x_ser_p1, ambi_bolt_potential_sheath_calc_upper_3x_ser_p1}, - {ambi_bolt_potential_sheath_calc_lower_3x_ser_p2, ambi_bolt_potential_sheath_calc_upper_3x_ser_p2}}, }, + {.list = + {{ambi_bolt_potential_sheath_calc_lower_2x_ser_p1, + ambi_bolt_potential_sheath_calc_upper_2x_ser_p1}, + {ambi_bolt_potential_sheath_calc_lower_2x_ser_p2, + ambi_bolt_potential_sheath_calc_upper_2x_ser_p2}}}, + // // 3x + {.list = + {{ambi_bolt_potential_sheath_calc_lower_3x_ser_p1, + ambi_bolt_potential_sheath_calc_upper_3x_ser_p1}, + {ambi_bolt_potential_sheath_calc_lower_3x_ser_p2, + ambi_bolt_potential_sheath_calc_upper_3x_ser_p2}}} }; // Serendipity phi_calc kernels. -GKYL_CU_D -static const phi_calc_kern_list ser_phi_calc_list[] = { - // 1x kernels - { ambi_bolt_potential_phi_calc_1x_ser_p1, ambi_bolt_potential_phi_calc_1x_ser_p2 }, +GKYL_CU_D static const phi_calc_kern_list ser_phi_calc_list[] = { // 1x kernels + {ambi_bolt_potential_phi_calc_1x_ser_p1, ambi_bolt_potential_phi_calc_1x_ser_p2}, // 2x kernels - { ambi_bolt_potential_phi_calc_2x_ser_p1, ambi_bolt_potential_phi_calc_2x_ser_p2 }, + {ambi_bolt_potential_phi_calc_2x_ser_p1, ambi_bolt_potential_phi_calc_2x_ser_p2}, // 3x kernels - { ambi_bolt_potential_phi_calc_3x_ser_p1, ambi_bolt_potential_phi_calc_3x_ser_p2 }, + {ambi_bolt_potential_phi_calc_3x_ser_p1, ambi_bolt_potential_phi_calc_3x_ser_p2} }; // Struct containing pointers to the various kernels. Needed to create a similar struct on the GPU. @@ -61,53 +75,54 @@ struct gkyl_ambi_bolt_potential { double num_basis; bool use_gpu; double dz; - double mass_e; // Electron mass. - double charge_e; // Electron charge. - double temp_e; // Electron temperature. - struct gkyl_ambi_bolt_potential_kernels *kernels; // sheath_calc and phi_calc kernels. - struct gkyl_ambi_bolt_potential_kernels *kernels_cu; // device copy. + double mass_e; // Electron mass. + double charge_e; // Electron charge. + double temp_e; // Electron temperature. + struct gkyl_ambi_bolt_potential_kernels *kernels; // sheath_calc and phi_calc kernels. + struct gkyl_ambi_bolt_potential_kernels *kernels_cu; // device copy. }; // "Choose Kernel" based on cdim, vdim and polyorder -#define CSHEATHK(lst,dim,poly_order,loc) lst[dim-1].list[poly_order-1].kernels[loc] -#define CPHIK(lst,dim,poly_order) lst[dim-1].kernels[poly_order-1] +#define CSHEATHK(lst, dim, poly_order, loc) lst[dim - 1].list[poly_order - 1].kernels[loc] +#define CPHIK(lst, dim, poly_order) lst[dim - 1].kernels[poly_order - 1] -GKYL_CU_D -static void -ambi_bolt_potential_choose_kernels(const struct gkyl_basis* basis, struct gkyl_ambi_bolt_potential_kernels *kers) +GKYL_CU_D static void ambi_bolt_potential_choose_kernels( + const struct gkyl_basis *basis, struct gkyl_ambi_bolt_potential_kernels *kers +) { int dim = basis->ndim; int poly_order = basis->poly_order; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<2; k++) { - kers->sheath_calc[k] = CSHEATHK(ser_sheath_calc_list, dim, poly_order, k); - } - kers->phi_calc = CPHIK(ser_phi_calc_list, dim, poly_order); - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < 2; k++) { + kers->sheath_calc[k] = CSHEATHK(ser_sheath_calc_list, dim, poly_order, k); + } + kers->phi_calc = CPHIK(ser_phi_calc_list, dim, poly_order); + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } } #ifdef GKYL_HAVE_CUDA -void -ambi_bolt_potential_choose_kernels_cu(const struct gkyl_basis *basis, struct gkyl_ambi_bolt_potential_kernels *kers); - -void -gkyl_ambi_bolt_potential_sheath_calc_cu(struct gkyl_ambi_bolt_potential *up, enum gkyl_edge_loc edge, - const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, - const struct gkyl_array *cmag, const struct gkyl_array *jacobtot_inv, - const struct gkyl_array *gammai, const struct gkyl_array *m0i, const struct gkyl_array *Jm0i, - struct gkyl_array *sheath_vals); - -void -gkyl_ambi_bolt_potential_phi_calc_cu(struct gkyl_ambi_bolt_potential *up, - const struct gkyl_range *local_r, const struct gkyl_range *extlocal_r, - const struct gkyl_array *m0i, const struct gkyl_array *sheath_vals, - struct gkyl_array *phi); +void ambi_bolt_potential_choose_kernels_cu( + const struct gkyl_basis *basis, struct gkyl_ambi_bolt_potential_kernels *kers +); + +void gkyl_ambi_bolt_potential_sheath_calc_cu( + struct gkyl_ambi_bolt_potential *up, enum gkyl_edge_loc edge, const struct gkyl_range *skin_r, + const struct gkyl_range *ghost_r, const struct gkyl_array *cmag, + const struct gkyl_array *jacobtot_inv, const struct gkyl_array *gammai, + const struct gkyl_array *m0i, const struct gkyl_array *Jm0i, struct gkyl_array *sheath_vals +); + +void gkyl_ambi_bolt_potential_phi_calc_cu( + struct gkyl_ambi_bolt_potential *up, const struct gkyl_range *local_r, + const struct gkyl_range *extlocal_r, const struct gkyl_array *m0i, + const struct gkyl_array *sheath_vals, struct gkyl_array *phi +); #endif diff --git a/gyrokinetic/zero/gkyl_bc_basic_gyrokinetic.h b/gyrokinetic/zero/gkyl_bc_basic_gyrokinetic.h index 9508fbeedf..1ea5d5663c 100644 --- a/gyrokinetic/zero/gkyl_bc_basic_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_bc_basic_gyrokinetic.h @@ -25,9 +25,11 @@ typedef struct gkyl_bc_basic_gyrokinetic gkyl_bc_basic_gyrokinetic; * @param use_gpu Boolean to indicate whether to use the GPU. * @return New updater pointer. */ -struct gkyl_bc_basic_gyrokinetic* gkyl_bc_basic_gyrokinetic_new(int dir, enum gkyl_edge_loc edge, - enum gkyl_gyrokinetic_bc_type bctype, const struct gkyl_basis *basis, const struct gkyl_range *skin_r, - const struct gkyl_range *ghost_r, int num_comp, int cdim, bool use_gpu); +struct gkyl_bc_basic_gyrokinetic *gkyl_bc_basic_gyrokinetic_new( + int dir, enum gkyl_edge_loc edge, enum gkyl_gyrokinetic_bc_type bctype, + const struct gkyl_basis *basis, const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, + int num_comp, int cdim, bool use_gpu +); /** * Advance boundary conditions *in special case where buffer is fixed in time*. @@ -38,8 +40,9 @@ struct gkyl_bc_basic_gyrokinetic* gkyl_bc_basic_gyrokinetic_new(int dir, enum gk * @param buff_arr Buffer array, big enough for ghost cells at this boundary. * @param f_arr Field array to apply BC to. */ -void gkyl_bc_basic_gyrokinetic_buffer_fixed_func(const struct gkyl_bc_basic_gyrokinetic *up, - struct gkyl_array *buff_arr, struct gkyl_array *f_arr); +void gkyl_bc_basic_gyrokinetic_buffer_fixed_func( + const struct gkyl_bc_basic_gyrokinetic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr +); /** * Advance boundary conditions. Fill buffer array based on boundary conditions and copy @@ -49,8 +52,9 @@ void gkyl_bc_basic_gyrokinetic_buffer_fixed_func(const struct gkyl_bc_basic_gyro * @param buff_arr Buffer array, big enough for ghost cells at this boundary. * @param f_arr Field array to apply BC to. */ -void gkyl_bc_basic_gyrokinetic_advance(const struct gkyl_bc_basic_gyrokinetic *up, - struct gkyl_array *buff_arr, struct gkyl_array *f_arr); +void gkyl_bc_basic_gyrokinetic_advance( + const struct gkyl_bc_basic_gyrokinetic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr +); /** * Free memory associated with bc_basic_gyrokinetic updater. diff --git a/gyrokinetic/zero/gkyl_bc_basic_gyrokinetic_priv.h b/gyrokinetic/zero/gkyl_bc_basic_gyrokinetic_priv.h index 9aa5be9834..b82ff595ec 100644 --- a/gyrokinetic/zero/gkyl_bc_basic_gyrokinetic_priv.h +++ b/gyrokinetic/zero/gkyl_bc_basic_gyrokinetic_priv.h @@ -31,9 +31,10 @@ struct gkyl_bc_basic_gyrokinetic { * @param num_comp Number of components (DOFs) within a cell. * @return Pointer to array_copy_func which can be passed to array_copy_fn methods. */ -struct gkyl_array_copy_func* gkyl_bc_basic_gyrokinetic_create_arr_copy_func_cu(int dir, - enum gkyl_edge_loc edge, int cdim, enum gkyl_gyrokinetic_bc_type bctype, - const struct gkyl_basis *basis, int num_comp); +struct gkyl_array_copy_func *gkyl_bc_basic_gyrokinetic_create_arr_copy_func_cu( + int dir, enum gkyl_edge_loc edge, int cdim, enum gkyl_gyrokinetic_bc_type bctype, + const struct gkyl_basis *basis, int num_comp +); #endif @@ -46,136 +47,121 @@ struct dg_bc_ctx { const struct gkyl_basis *basis; // basis function. }; -GKYL_CU_D -static void -copy_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void copy_bc(size_t nc, double *out, const double *inp, void *ctx) { // Copy skin cell into ghost cell - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int num_comp = mc->ncomp; - for (int c=0; cncomp; - for (int c=0; cdir, cdim = mc->cdim; mc->basis->flip_odd_sign(dir, inp, out); mc->basis->flip_odd_sign(cdim, out, out); } -GKYL_CU_D -static void -conf_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void conf_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) { // Fill the ghost cell with the skin cell evaluated at the boundary, // so it has no variation in the direction of the BC. - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int dir = mc->dir; int cdim = mc->cdim; enum gkyl_edge_loc edge = mc->edge; if (cdim == 1) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[1]; - } - else { - out[0] = inp[0]+1.7320508075688772*inp[1]; + out[0] = inp[0] - 1.7320508075688772 * inp[1]; + } else { + out[0] = inp[0] + 1.7320508075688772 * inp[1]; } out[1] = 0.0; - } - else if (cdim == 2) { + } else if (cdim == 2) { if (dir == 0) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[1]; - out[2] = inp[2]-1.7320508075688772*inp[3]; - } - else { - out[0] = inp[0]+1.7320508075688772*inp[1]; - out[2] = inp[2]+1.7320508075688772*inp[3]; + out[0] = inp[0] - 1.7320508075688772 * inp[1]; + out[2] = inp[2] - 1.7320508075688772 * inp[3]; + } else { + out[0] = inp[0] + 1.7320508075688772 * inp[1]; + out[2] = inp[2] + 1.7320508075688772 * inp[3]; } out[1] = 0.0; out[3] = 0.0; - } - else if (dir == 1) { + } else if (dir == 1) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[2]; - out[1] = inp[1]-1.7320508075688772*inp[3]; - } - else { - out[0] = inp[0]+1.7320508075688772*inp[2]; - out[1] = inp[1]+1.7320508075688772*inp[3]; + out[0] = inp[0] - 1.7320508075688772 * inp[2]; + out[1] = inp[1] - 1.7320508075688772 * inp[3]; + } else { + out[0] = inp[0] + 1.7320508075688772 * inp[2]; + out[1] = inp[1] + 1.7320508075688772 * inp[3]; } out[2] = 0.0; out[3] = 0.0; } - } - else if (cdim == 3) { + } else if (cdim == 3) { if (dir == 0) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[1]; - out[2] = inp[2]-1.7320508075688772*inp[4]; - out[3] = inp[3]-1.7320508075688772*inp[5]; - out[6] = inp[6]-1.7320508075688772*inp[7]; - } - else { - out[0] = inp[0]+1.7320508075688772*inp[1]; - out[2] = inp[2]+1.7320508075688772*inp[4]; - out[3] = inp[3]+1.7320508075688772*inp[5]; - out[6] = inp[6]+1.7320508075688772*inp[7]; + out[0] = inp[0] - 1.7320508075688772 * inp[1]; + out[2] = inp[2] - 1.7320508075688772 * inp[4]; + out[3] = inp[3] - 1.7320508075688772 * inp[5]; + out[6] = inp[6] - 1.7320508075688772 * inp[7]; + } else { + out[0] = inp[0] + 1.7320508075688772 * inp[1]; + out[2] = inp[2] + 1.7320508075688772 * inp[4]; + out[3] = inp[3] + 1.7320508075688772 * inp[5]; + out[6] = inp[6] + 1.7320508075688772 * inp[7]; } out[1] = 0.0; out[4] = 0.0; out[5] = 0.0; out[7] = 0.0; - } - else if (dir == 1) { + } else if (dir == 1) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[2]; - out[1] = inp[1]-1.7320508075688772*inp[4]; - out[3] = inp[3]-1.7320508075688772*inp[6]; - out[5] = inp[5]-1.7320508075688772*inp[7]; - } - else { - out[0] = inp[0]+1.7320508075688772*inp[2]; - out[1] = inp[1]+1.7320508075688772*inp[4]; - out[3] = inp[3]+1.7320508075688772*inp[6]; - out[5] = inp[5]+1.7320508075688772*inp[7]; + out[0] = inp[0] - 1.7320508075688772 * inp[2]; + out[1] = inp[1] - 1.7320508075688772 * inp[4]; + out[3] = inp[3] - 1.7320508075688772 * inp[6]; + out[5] = inp[5] - 1.7320508075688772 * inp[7]; + } else { + out[0] = inp[0] + 1.7320508075688772 * inp[2]; + out[1] = inp[1] + 1.7320508075688772 * inp[4]; + out[3] = inp[3] + 1.7320508075688772 * inp[6]; + out[5] = inp[5] + 1.7320508075688772 * inp[7]; } out[2] = 0.0; out[4] = 0.0; out[6] = 0.0; out[7] = 0.0; - } - else if (dir == 2) { + } else if (dir == 2) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[3]; - out[1] = inp[1]-1.7320508075688772*inp[5]; - out[2] = inp[2]-1.7320508075688772*inp[6]; - out[4] = inp[4]-1.7320508075688772*inp[7]; - } - else { - out[0] = inp[0]+1.7320508075688772*inp[3]; - out[1] = inp[1]+1.7320508075688772*inp[5]; - out[2] = inp[2]+1.7320508075688772*inp[6]; - out[4] = inp[4]+1.7320508075688772*inp[7]; + out[0] = inp[0] - 1.7320508075688772 * inp[3]; + out[1] = inp[1] - 1.7320508075688772 * inp[5]; + out[2] = inp[2] - 1.7320508075688772 * inp[6]; + out[4] = inp[4] - 1.7320508075688772 * inp[7]; + } else { + out[0] = inp[0] + 1.7320508075688772 * inp[3]; + out[1] = inp[1] + 1.7320508075688772 * inp[5]; + out[2] = inp[2] + 1.7320508075688772 * inp[6]; + out[4] = inp[4] + 1.7320508075688772 * inp[7]; } out[3] = 0.0; out[5] = 0.0; @@ -185,13 +171,11 @@ conf_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) } } -GKYL_CU_D -static void -phase_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void phase_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) { // Fill the ghost cell with the skin cell evaluated at the boundary, // so it has no variation in the direction of the BC. - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int dir = mc->dir; int pdim = mc->basis->ndim; enum gkyl_edge_loc edge = mc->edge; @@ -199,96 +183,89 @@ phase_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) if (pdim == 2) { // 1x1v if (dir == 0) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[1]; + out[0] = inp[0] - 1.7320508075688772 * inp[1]; out[1] = 0.0; - out[2] = inp[2]-1.7320508075688772*inp[3]; + out[2] = inp[2] - 1.7320508075688772 * inp[3]; out[3] = 0.0; - out[4] = inp[4]-1.7320508075688774*inp[5]; + out[4] = inp[4] - 1.7320508075688774 * inp[5]; out[5] = 0.0; - } - else { - out[0] = 1.7320508075688772*inp[1]+inp[0]; + } else { + out[0] = 1.7320508075688772 * inp[1] + inp[0]; out[1] = 0.0; - out[2] = 1.7320508075688772*inp[3]+inp[2]; + out[2] = 1.7320508075688772 * inp[3] + inp[2]; out[3] = 0.0; - out[4] = 1.7320508075688774*inp[5]+inp[4]; + out[4] = 1.7320508075688774 * inp[5] + inp[4]; out[5] = 0.0; } - } - else if (dir == 1) { + } else if (dir == 1) { if (edge == GKYL_LOWER_EDGE) { - out[0] = 2.23606797749979*inp[4]-1.7320508075688772*inp[2]+inp[0]; - out[1] = 2.2360679774997902*inp[5]-1.7320508075688772*inp[3]+inp[1]; + out[0] = 2.23606797749979 * inp[4] - 1.7320508075688772 * inp[2] + inp[0]; + out[1] = 2.2360679774997902 * inp[5] - 1.7320508075688772 * inp[3] + inp[1]; out[2] = 0.0; out[3] = 0.0; out[4] = 0.0; out[5] = 0.0; - } - else { - out[0] = 2.23606797749979*inp[4]+1.7320508075688772*inp[2]+inp[0]; - out[1] = 2.2360679774997902*inp[5]+1.7320508075688772*inp[3]+inp[1]; + } else { + out[0] = 2.23606797749979 * inp[4] + 1.7320508075688772 * inp[2] + inp[0]; + out[1] = 2.2360679774997902 * inp[5] + 1.7320508075688772 * inp[3] + inp[1]; out[2] = 0.0; out[3] = 0.0; out[4] = 0.0; out[5] = 0.0; } - } - else + } else { assert(false); - } - else if (pdim == 3) { // 1x2v + } + } else if (pdim == 3) { // 1x2v if (dir == 0) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[1]; + out[0] = inp[0] - 1.7320508075688772 * inp[1]; out[1] = 0.0; - out[2] = inp[2]-1.7320508075688772*inp[4]; - out[3] = inp[3]-1.7320508075688772*inp[5]; + out[2] = inp[2] - 1.7320508075688772 * inp[4]; + out[3] = inp[3] - 1.7320508075688772 * inp[5]; out[4] = 0.0; out[5] = 0.0; - out[6] = inp[6]-1.7320508075688772*inp[7]; + out[6] = inp[6] - 1.7320508075688772 * inp[7]; out[7] = 0.0; - out[8] = inp[8]-1.7320508075688774*inp[9]; + out[8] = inp[8] - 1.7320508075688774 * inp[9]; out[9] = 0.0; - out[10] = inp[10]-1.7320508075688774*inp[11]; + out[10] = inp[10] - 1.7320508075688774 * inp[11]; out[11] = 0.0; - } - else { - out[0] = 1.7320508075688772*inp[1]+inp[0]; + } else { + out[0] = 1.7320508075688772 * inp[1] + inp[0]; out[1] = 0.0; - out[2] = 1.7320508075688772*inp[4]+inp[2]; - out[3] = 1.7320508075688772*inp[5]+inp[3]; + out[2] = 1.7320508075688772 * inp[4] + inp[2]; + out[3] = 1.7320508075688772 * inp[5] + inp[3]; out[4] = 0.0; out[5] = 0.0; - out[6] = 1.7320508075688772*inp[7]+inp[6]; + out[6] = 1.7320508075688772 * inp[7] + inp[6]; out[7] = 0.0; - out[8] = 1.7320508075688774*inp[9]+inp[8]; + out[8] = 1.7320508075688774 * inp[9] + inp[8]; out[9] = 0.0; - out[10] = 1.7320508075688774*inp[11]+inp[10]; + out[10] = 1.7320508075688774 * inp[11] + inp[10]; out[11] = 0.0; } - } - else if (dir == 1) { + } else if (dir == 1) { if (edge == GKYL_LOWER_EDGE) { - out[0] = 2.23606797749979*inp[8]-1.7320508075688772*inp[2]+inp[0]; - out[1] = 2.2360679774997902*inp[9]-1.7320508075688772*inp[4]+inp[1]; + out[0] = 2.23606797749979 * inp[8] - 1.7320508075688772 * inp[2] + inp[0]; + out[1] = 2.2360679774997902 * inp[9] - 1.7320508075688772 * inp[4] + inp[1]; out[2] = 0.0; - out[3] = 2.2360679774997902*inp[10]-1.7320508075688772*inp[6]+inp[3]; + out[3] = 2.2360679774997902 * inp[10] - 1.7320508075688772 * inp[6] + inp[3]; out[4] = 0.0; - out[5] = 2.23606797749979*inp[11]-1.7320508075688772*inp[7]+inp[5]; + out[5] = 2.23606797749979 * inp[11] - 1.7320508075688772 * inp[7] + inp[5]; out[6] = 0.0; out[7] = 0.0; out[8] = 0.0; out[9] = 0.0; out[10] = 0.0; out[11] = 0.0; - } - else { - out[0] = 2.23606797749979*inp[8]+1.7320508075688772*inp[2]+inp[0]; - out[1] = 2.2360679774997902*inp[9]+1.7320508075688772*inp[4]+inp[1]; + } else { + out[0] = 2.23606797749979 * inp[8] + 1.7320508075688772 * inp[2] + inp[0]; + out[1] = 2.2360679774997902 * inp[9] + 1.7320508075688772 * inp[4] + inp[1]; out[2] = 0.0; - out[3] = 2.2360679774997902*inp[10]+1.7320508075688772*inp[6]+inp[3]; + out[3] = 2.2360679774997902 * inp[10] + 1.7320508075688772 * inp[6] + inp[3]; out[4] = 0.0; - out[5] = 2.23606797749979*inp[11]+1.7320508075688772*inp[7]+inp[5]; + out[5] = 2.23606797749979 * inp[11] + 1.7320508075688772 * inp[7] + inp[5]; out[6] = 0.0; out[7] = 0.0; out[8] = 0.0; @@ -296,162 +273,155 @@ phase_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) out[10] = 0.0; out[11] = 0.0; } - } - else if (dir == 2) { + } else if (dir == 2) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[3]; - out[1] = inp[1]-1.7320508075688772*inp[5]; - out[2] = inp[2]-1.7320508075688772*inp[6]; + out[0] = inp[0] - 1.7320508075688772 * inp[3]; + out[1] = inp[1] - 1.7320508075688772 * inp[5]; + out[2] = inp[2] - 1.7320508075688772 * inp[6]; out[3] = 0.0; - out[4] = inp[4]-1.7320508075688772*inp[7]; + out[4] = inp[4] - 1.7320508075688772 * inp[7]; out[5] = 0.0; out[6] = 0.0; out[7] = 0.0; - out[8] = inp[8]-1.7320508075688774*inp[10]; - out[9] = inp[9]-1.7320508075688774*inp[11]; + out[8] = inp[8] - 1.7320508075688774 * inp[10]; + out[9] = inp[9] - 1.7320508075688774 * inp[11]; out[10] = 0.0; out[11] = 0.0; - } - else { - out[0] = 1.7320508075688772*inp[3]+inp[0]; - out[1] = 1.7320508075688772*inp[5]+inp[1]; - out[2] = 1.7320508075688772*inp[6]+inp[2]; + } else { + out[0] = 1.7320508075688772 * inp[3] + inp[0]; + out[1] = 1.7320508075688772 * inp[5] + inp[1]; + out[2] = 1.7320508075688772 * inp[6] + inp[2]; out[3] = 0.0; - out[4] = 1.7320508075688772*inp[7]+inp[4]; + out[4] = 1.7320508075688772 * inp[7] + inp[4]; out[5] = 0.0; out[6] = 0.0; out[7] = 0.0; - out[8] = 1.7320508075688774*inp[10]+inp[8]; - out[9] = 1.7320508075688774*inp[11]+inp[9]; + out[8] = 1.7320508075688774 * inp[10] + inp[8]; + out[9] = 1.7320508075688774 * inp[11] + inp[9]; out[10] = 0.0; out[11] = 0.0; } } - } - else if (pdim == 4) { // 2x2v + } else if (pdim == 4) { // 2x2v if (dir == 0) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[1]; + out[0] = inp[0] - 1.7320508075688772 * inp[1]; out[1] = 0.0; - out[2] = inp[2]-1.7320508075688772*inp[5]; - out[3] = inp[3]-1.7320508075688772*inp[6]; - out[4] = inp[4]-1.7320508075688772*inp[8]; + out[2] = inp[2] - 1.7320508075688772 * inp[5]; + out[3] = inp[3] - 1.7320508075688772 * inp[6]; + out[4] = inp[4] - 1.7320508075688772 * inp[8]; out[5] = 0.0; out[6] = 0.0; - out[7] = inp[7]-1.7320508075688772*inp[11]; + out[7] = inp[7] - 1.7320508075688772 * inp[11]; out[8] = 0.0; - out[9] = inp[9]-1.7320508075688772*inp[12]; - out[10] = inp[10]-1.7320508075688772*inp[13]; + out[9] = inp[9] - 1.7320508075688772 * inp[12]; + out[10] = inp[10] - 1.7320508075688772 * inp[13]; out[11] = 0.0; out[12] = 0.0; out[13] = 0.0; - out[14] = inp[14]-1.7320508075688772*inp[15]; + out[14] = inp[14] - 1.7320508075688772 * inp[15]; out[15] = 0.0; - out[16] = inp[16]-1.7320508075688774*inp[17]; + out[16] = inp[16] - 1.7320508075688774 * inp[17]; out[17] = 0.0; - out[18] = inp[18]-1.7320508075688774*inp[20]; - out[19] = inp[19]-1.7320508075688774*inp[21]; + out[18] = inp[18] - 1.7320508075688774 * inp[20]; + out[19] = inp[19] - 1.7320508075688774 * inp[21]; out[20] = 0.0; out[21] = 0.0; - out[22] = inp[22]-1.7320508075688774*inp[23]; + out[22] = inp[22] - 1.7320508075688774 * inp[23]; out[23] = 0.0; - } - else { - out[0] = 1.7320508075688772*inp[1]+inp[0]; + } else { + out[0] = 1.7320508075688772 * inp[1] + inp[0]; out[1] = 0.0; - out[2] = 1.7320508075688772*inp[5]+inp[2]; - out[3] = 1.7320508075688772*inp[6]+inp[3]; - out[4] = 1.7320508075688772*inp[8]+inp[4]; + out[2] = 1.7320508075688772 * inp[5] + inp[2]; + out[3] = 1.7320508075688772 * inp[6] + inp[3]; + out[4] = 1.7320508075688772 * inp[8] + inp[4]; out[5] = 0.0; out[6] = 0.0; - out[7] = 1.7320508075688772*inp[11]+inp[7]; + out[7] = 1.7320508075688772 * inp[11] + inp[7]; out[8] = 0.0; - out[9] = 1.7320508075688772*inp[12]+inp[9]; - out[10] = 1.7320508075688772*inp[13]+inp[10]; + out[9] = 1.7320508075688772 * inp[12] + inp[9]; + out[10] = 1.7320508075688772 * inp[13] + inp[10]; out[11] = 0.0; out[12] = 0.0; out[13] = 0.0; - out[14] = 1.7320508075688772*inp[15]+inp[14]; + out[14] = 1.7320508075688772 * inp[15] + inp[14]; out[15] = 0.0; - out[16] = 1.7320508075688774*inp[17]+inp[16]; + out[16] = 1.7320508075688774 * inp[17] + inp[16]; out[17] = 0.0; - out[18] = 1.7320508075688774*inp[20]+inp[18]; - out[19] = 1.7320508075688774*inp[21]+inp[19]; + out[18] = 1.7320508075688774 * inp[20] + inp[18]; + out[19] = 1.7320508075688774 * inp[21] + inp[19]; out[20] = 0.0; out[21] = 0.0; - out[22] = 1.7320508075688774*inp[23]+inp[22]; + out[22] = 1.7320508075688774 * inp[23] + inp[22]; out[23] = 0.0; } - } - else if (dir == 1) { + } else if (dir == 1) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[2]; - out[1] = inp[1]-1.7320508075688772*inp[5]; + out[0] = inp[0] - 1.7320508075688772 * inp[2]; + out[1] = inp[1] - 1.7320508075688772 * inp[5]; out[2] = 0.0; - out[3] = inp[3]-1.7320508075688772*inp[7]; - out[4] = inp[4]-1.7320508075688772*inp[9]; + out[3] = inp[3] - 1.7320508075688772 * inp[7]; + out[4] = inp[4] - 1.7320508075688772 * inp[9]; out[5] = 0.0; - out[6] = inp[6]-1.7320508075688772*inp[11]; + out[6] = inp[6] - 1.7320508075688772 * inp[11]; out[7] = 0.0; - out[8] = inp[8]-1.7320508075688772*inp[12]; + out[8] = inp[8] - 1.7320508075688772 * inp[12]; out[9] = 0.0; - out[10] = inp[10]-1.7320508075688772*inp[14]; + out[10] = inp[10] - 1.7320508075688772 * inp[14]; out[11] = 0.0; out[12] = 0.0; - out[13] = inp[13]-1.7320508075688772*inp[15]; + out[13] = inp[13] - 1.7320508075688772 * inp[15]; out[14] = 0.0; out[15] = 0.0; - out[16] = inp[16]-1.7320508075688774*inp[18]; - out[17] = inp[17]-1.7320508075688774*inp[20]; + out[16] = inp[16] - 1.7320508075688774 * inp[18]; + out[17] = inp[17] - 1.7320508075688774 * inp[20]; out[18] = 0.0; - out[19] = inp[19]-1.7320508075688774*inp[22]; + out[19] = inp[19] - 1.7320508075688774 * inp[22]; out[20] = 0.0; - out[21] = inp[21]-1.7320508075688774*inp[23]; + out[21] = inp[21] - 1.7320508075688774 * inp[23]; out[22] = 0.0; out[23] = 0.0; - } - else { - out[0] = 1.7320508075688772*inp[2]+inp[0]; - out[1] = 1.7320508075688772*inp[5]+inp[1]; + } else { + out[0] = 1.7320508075688772 * inp[2] + inp[0]; + out[1] = 1.7320508075688772 * inp[5] + inp[1]; out[2] = 0.0; - out[3] = 1.7320508075688772*inp[7]+inp[3]; - out[4] = 1.7320508075688772*inp[9]+inp[4]; + out[3] = 1.7320508075688772 * inp[7] + inp[3]; + out[4] = 1.7320508075688772 * inp[9] + inp[4]; out[5] = 0.0; - out[6] = 1.7320508075688772*inp[11]+inp[6]; + out[6] = 1.7320508075688772 * inp[11] + inp[6]; out[7] = 0.0; - out[8] = 1.7320508075688772*inp[12]+inp[8]; + out[8] = 1.7320508075688772 * inp[12] + inp[8]; out[9] = 0.0; - out[10] = 1.7320508075688772*inp[14]+inp[10]; + out[10] = 1.7320508075688772 * inp[14] + inp[10]; out[11] = 0.0; out[12] = 0.0; - out[13] = 1.7320508075688772*inp[15]+inp[13]; + out[13] = 1.7320508075688772 * inp[15] + inp[13]; out[14] = 0.0; out[15] = 0.0; - out[16] = 1.7320508075688774*inp[18]+inp[16]; - out[17] = 1.7320508075688774*inp[20]+inp[17]; + out[16] = 1.7320508075688774 * inp[18] + inp[16]; + out[17] = 1.7320508075688774 * inp[20] + inp[17]; out[18] = 0.0; - out[19] = 1.7320508075688774*inp[22]+inp[19]; + out[19] = 1.7320508075688774 * inp[22] + inp[19]; out[20] = 0.0; - out[21] = 1.7320508075688774*inp[23]+inp[21]; + out[21] = 1.7320508075688774 * inp[23] + inp[21]; out[22] = 0.0; out[23] = 0.0; } - } - else if (dir == 2) { + } else if (dir == 2) { if (edge == GKYL_LOWER_EDGE) { - out[0] = 2.23606797749979*inp[16]-1.7320508075688772*inp[3]+inp[0]; - out[1] = 2.2360679774997902*inp[17]-1.7320508075688772*inp[6]+inp[1]; - out[2] = 2.2360679774997902*inp[18]-1.7320508075688772*inp[7]+inp[2]; + out[0] = 2.23606797749979 * inp[16] - 1.7320508075688772 * inp[3] + inp[0]; + out[1] = 2.2360679774997902 * inp[17] - 1.7320508075688772 * inp[6] + inp[1]; + out[2] = 2.2360679774997902 * inp[18] - 1.7320508075688772 * inp[7] + inp[2]; out[3] = 0.0; - out[4] = 2.2360679774997902*inp[19]-1.7320508075688772*inp[10]+inp[4]; - out[5] = 2.23606797749979*inp[20]-1.7320508075688772*inp[11]+inp[5]; + out[4] = 2.2360679774997902 * inp[19] - 1.7320508075688772 * inp[10] + inp[4]; + out[5] = 2.23606797749979 * inp[20] - 1.7320508075688772 * inp[11] + inp[5]; out[6] = 0.0; out[7] = 0.0; - out[8] = 2.23606797749979*inp[21]-1.7320508075688772*inp[13]+inp[8]; - out[9] = 2.23606797749979*inp[22]-1.7320508075688772*inp[14]+inp[9]; + out[8] = 2.23606797749979 * inp[21] - 1.7320508075688772 * inp[13] + inp[8]; + out[9] = 2.23606797749979 * inp[22] - 1.7320508075688772 * inp[14] + inp[9]; out[10] = 0.0; out[11] = 0.0; - out[12] = 2.2360679774997902*inp[23]-1.7320508075688772*inp[15]+inp[12]; + out[12] = 2.2360679774997902 * inp[23] - 1.7320508075688772 * inp[15] + inp[12]; out[13] = 0.0; out[14] = 0.0; out[15] = 0.0; @@ -463,21 +433,20 @@ phase_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) out[21] = 0.0; out[22] = 0.0; out[23] = 0.0; - } - else { - out[0] = 2.23606797749979*inp[16]+1.7320508075688772*inp[3]+inp[0]; - out[1] = 2.2360679774997902*inp[17]+1.7320508075688772*inp[6]+inp[1]; - out[2] = 2.2360679774997902*inp[18]+1.7320508075688772*inp[7]+inp[2]; + } else { + out[0] = 2.23606797749979 * inp[16] + 1.7320508075688772 * inp[3] + inp[0]; + out[1] = 2.2360679774997902 * inp[17] + 1.7320508075688772 * inp[6] + inp[1]; + out[2] = 2.2360679774997902 * inp[18] + 1.7320508075688772 * inp[7] + inp[2]; out[3] = 0.0; - out[4] = 2.2360679774997902*inp[19]+1.7320508075688772*inp[10]+inp[4]; - out[5] = 2.23606797749979*inp[20]+1.7320508075688772*inp[11]+inp[5]; + out[4] = 2.2360679774997902 * inp[19] + 1.7320508075688772 * inp[10] + inp[4]; + out[5] = 2.23606797749979 * inp[20] + 1.7320508075688772 * inp[11] + inp[5]; out[6] = 0.0; out[7] = 0.0; - out[8] = 2.23606797749979*inp[21]+1.7320508075688772*inp[13]+inp[8]; - out[9] = 2.23606797749979*inp[22]+1.7320508075688772*inp[14]+inp[9]; + out[8] = 2.23606797749979 * inp[21] + 1.7320508075688772 * inp[13] + inp[8]; + out[9] = 2.23606797749979 * inp[22] + 1.7320508075688772 * inp[14] + inp[9]; out[10] = 0.0; out[11] = 0.0; - out[12] = 2.2360679774997902*inp[23]+1.7320508075688772*inp[15]+inp[12]; + out[12] = 2.2360679774997902 * inp[23] + 1.7320508075688772 * inp[15] + inp[12]; out[13] = 0.0; out[14] = 0.0; out[15] = 0.0; @@ -490,571 +459,559 @@ phase_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) out[22] = 0.0; out[23] = 0.0; } - } - else if (dir == 3) { + } else if (dir == 3) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[4]; - out[1] = inp[1]-1.7320508075688772*inp[8]; - out[2] = inp[2]-1.7320508075688772*inp[9]; - out[3] = inp[3]-1.7320508075688772*inp[10]; + out[0] = inp[0] - 1.7320508075688772 * inp[4]; + out[1] = inp[1] - 1.7320508075688772 * inp[8]; + out[2] = inp[2] - 1.7320508075688772 * inp[9]; + out[3] = inp[3] - 1.7320508075688772 * inp[10]; out[4] = 0.0; - out[5] = inp[5]-1.7320508075688772*inp[12]; - out[6] = inp[6]-1.7320508075688772*inp[13]; - out[7] = inp[7]-1.7320508075688772*inp[14]; + out[5] = inp[5] - 1.7320508075688772 * inp[12]; + out[6] = inp[6] - 1.7320508075688772 * inp[13]; + out[7] = inp[7] - 1.7320508075688772 * inp[14]; out[8] = 0.0; out[9] = 0.0; out[10] = 0.0; - out[11] = inp[11]-1.7320508075688772*inp[15]; + out[11] = inp[11] - 1.7320508075688772 * inp[15]; out[12] = 0.0; out[13] = 0.0; out[14] = 0.0; out[15] = 0.0; - out[16] = inp[16]-1.7320508075688774*inp[19]; - out[17] = inp[17]-1.7320508075688774*inp[21]; - out[18] = inp[18]-1.7320508075688774*inp[22]; + out[16] = inp[16] - 1.7320508075688774 * inp[19]; + out[17] = inp[17] - 1.7320508075688774 * inp[21]; + out[18] = inp[18] - 1.7320508075688774 * inp[22]; out[19] = 0.0; - out[20] = inp[20]-1.7320508075688774*inp[23]; + out[20] = inp[20] - 1.7320508075688774 * inp[23]; out[21] = 0.0; out[22] = 0.0; out[23] = 0.0; - } - else { - out[0] = 1.7320508075688772*inp[4]+inp[0]; - out[1] = 1.7320508075688772*inp[8]+inp[1]; - out[2] = 1.7320508075688772*inp[9]+inp[2]; - out[3] = 1.7320508075688772*inp[10]+inp[3]; + } else { + out[0] = 1.7320508075688772 * inp[4] + inp[0]; + out[1] = 1.7320508075688772 * inp[8] + inp[1]; + out[2] = 1.7320508075688772 * inp[9] + inp[2]; + out[3] = 1.7320508075688772 * inp[10] + inp[3]; out[4] = 0.0; - out[5] = 1.7320508075688772*inp[12]+inp[5]; - out[6] = 1.7320508075688772*inp[13]+inp[6]; - out[7] = 1.7320508075688772*inp[14]+inp[7]; + out[5] = 1.7320508075688772 * inp[12] + inp[5]; + out[6] = 1.7320508075688772 * inp[13] + inp[6]; + out[7] = 1.7320508075688772 * inp[14] + inp[7]; out[8] = 0.0; out[9] = 0.0; out[10] = 0.0; - out[11] = 1.7320508075688772*inp[15]+inp[11]; + out[11] = 1.7320508075688772 * inp[15] + inp[11]; out[12] = 0.0; out[13] = 0.0; out[14] = 0.0; out[15] = 0.0; - out[16] = 1.7320508075688774*inp[19]+inp[16]; - out[17] = 1.7320508075688774*inp[21]+inp[17]; - out[18] = 1.7320508075688774*inp[22]+inp[18]; + out[16] = 1.7320508075688774 * inp[19] + inp[16]; + out[17] = 1.7320508075688774 * inp[21] + inp[17]; + out[18] = 1.7320508075688774 * inp[22] + inp[18]; out[19] = 0.0; - out[20] = 1.7320508075688774*inp[23]+inp[20]; + out[20] = 1.7320508075688774 * inp[23] + inp[20]; out[21] = 0.0; out[22] = 0.0; out[23] = 0.0; } } - } - else if (pdim == 5) { // 3x2v + } else if (pdim == 5) { // 3x2v if (dir == 0) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[1]; - out[1] = 0.0; - out[2] = inp[2]-1.7320508075688772*inp[6]; - out[3] = inp[3]-1.7320508075688772*inp[7]; - out[4] = inp[4]-1.7320508075688772*inp[9]; - out[5] = inp[5]-1.7320508075688772*inp[12]; - out[6] = 0.0; - out[7] = 0.0; - out[8] = inp[8]-1.7320508075688772*inp[16]; - out[9] = 0.0; - out[10] = inp[10]-1.7320508075688772*inp[17]; - out[11] = inp[11]-1.7320508075688772*inp[18]; - out[12] = 0.0; - out[13] = inp[13]-1.7320508075688772*inp[20]; - out[14] = inp[14]-1.7320508075688772*inp[21]; - out[15] = inp[15]-1.7320508075688772*inp[23]; - out[16] = 0.0; - out[17] = 0.0; - out[18] = 0.0; - out[19] = inp[19]-1.7320508075688772*inp[26]; - out[20] = 0.0; - out[21] = 0.0; - out[22] = inp[22]-1.7320508075688772*inp[27]; - out[23] = 0.0; - out[24] = inp[24]-1.7320508075688772*inp[28]; - out[25] = inp[25]-1.7320508075688772*inp[29]; - out[26] = 0.0; - out[27] = 0.0; - out[28] = 0.0; - out[29] = 0.0; - out[30] = inp[30]-1.7320508075688772*inp[31]; - out[31] = 0.0; - out[32] = inp[32]-1.7320508075688774*inp[33]; - out[33] = 0.0; - out[34] = inp[34]-1.7320508075688774*inp[37]; - out[35] = inp[35]-1.7320508075688774*inp[38]; - out[36] = inp[36]-1.7320508075688774*inp[40]; - out[37] = 0.0; - out[38] = 0.0; - out[39] = inp[39]-1.7320508075688774*inp[43]; - out[40] = 0.0; - out[41] = inp[41]-1.7320508075688774*inp[44]; - out[42] = inp[42]-1.7320508075688774*inp[45]; - out[43] = 0.0; - out[44] = 0.0; - out[45] = 0.0; - out[46] = inp[46]-1.7320508075688774*inp[47]; - out[47] = 0.0; - } - else { - out[0] = 1.7320508075688772*inp[1]+inp[0]; - out[1] = 0.0; - out[2] = 1.7320508075688772*inp[6]+inp[2]; - out[3] = 1.7320508075688772*inp[7]+inp[3]; - out[4] = 1.7320508075688772*inp[9]+inp[4]; - out[5] = 1.7320508075688772*inp[12]+inp[5]; - out[6] = 0.0; - out[7] = 0.0; - out[8] = 1.7320508075688772*inp[16]+inp[8]; - out[9] = 0.0; - out[10] = 1.7320508075688772*inp[17]+inp[10]; - out[11] = 1.7320508075688772*inp[18]+inp[11]; - out[12] = 0.0; - out[13] = 1.7320508075688772*inp[20]+inp[13]; - out[14] = 1.7320508075688772*inp[21]+inp[14]; - out[15] = 1.7320508075688772*inp[23]+inp[15]; - out[16] = 0.0; - out[17] = 0.0; - out[18] = 0.0; - out[19] = 1.7320508075688772*inp[26]+inp[19]; - out[20] = 0.0; - out[21] = 0.0; - out[22] = 1.7320508075688772*inp[27]+inp[22]; - out[23] = 0.0; - out[24] = 1.7320508075688772*inp[28]+inp[24]; - out[25] = 1.7320508075688772*inp[29]+inp[25]; - out[26] = 0.0; - out[27] = 0.0; - out[28] = 0.0; - out[29] = 0.0; - out[30] = 1.7320508075688772*inp[31]+inp[30]; - out[31] = 0.0; - out[32] = 1.7320508075688774*inp[33]+inp[32]; - out[33] = 0.0; - out[34] = 1.7320508075688774*inp[37]+inp[34]; - out[35] = 1.7320508075688774*inp[38]+inp[35]; - out[36] = 1.7320508075688774*inp[40]+inp[36]; - out[37] = 0.0; - out[38] = 0.0; - out[39] = 1.7320508075688774*inp[43]+inp[39]; - out[40] = 0.0; - out[41] = 1.7320508075688774*inp[44]+inp[41]; - out[42] = 1.7320508075688774*inp[45]+inp[42]; - out[43] = 0.0; - out[44] = 0.0; - out[45] = 0.0; - out[46] = 1.7320508075688774*inp[47]+inp[46]; - out[47] = 0.0; - } - } - else if (dir == 1) { + out[0] = inp[0] - 1.7320508075688772 * inp[1]; + out[1] = 0.0; + out[2] = inp[2] - 1.7320508075688772 * inp[6]; + out[3] = inp[3] - 1.7320508075688772 * inp[7]; + out[4] = inp[4] - 1.7320508075688772 * inp[9]; + out[5] = inp[5] - 1.7320508075688772 * inp[12]; + out[6] = 0.0; + out[7] = 0.0; + out[8] = inp[8] - 1.7320508075688772 * inp[16]; + out[9] = 0.0; + out[10] = inp[10] - 1.7320508075688772 * inp[17]; + out[11] = inp[11] - 1.7320508075688772 * inp[18]; + out[12] = 0.0; + out[13] = inp[13] - 1.7320508075688772 * inp[20]; + out[14] = inp[14] - 1.7320508075688772 * inp[21]; + out[15] = inp[15] - 1.7320508075688772 * inp[23]; + out[16] = 0.0; + out[17] = 0.0; + out[18] = 0.0; + out[19] = inp[19] - 1.7320508075688772 * inp[26]; + out[20] = 0.0; + out[21] = 0.0; + out[22] = inp[22] - 1.7320508075688772 * inp[27]; + out[23] = 0.0; + out[24] = inp[24] - 1.7320508075688772 * inp[28]; + out[25] = inp[25] - 1.7320508075688772 * inp[29]; + out[26] = 0.0; + out[27] = 0.0; + out[28] = 0.0; + out[29] = 0.0; + out[30] = inp[30] - 1.7320508075688772 * inp[31]; + out[31] = 0.0; + out[32] = inp[32] - 1.7320508075688774 * inp[33]; + out[33] = 0.0; + out[34] = inp[34] - 1.7320508075688774 * inp[37]; + out[35] = inp[35] - 1.7320508075688774 * inp[38]; + out[36] = inp[36] - 1.7320508075688774 * inp[40]; + out[37] = 0.0; + out[38] = 0.0; + out[39] = inp[39] - 1.7320508075688774 * inp[43]; + out[40] = 0.0; + out[41] = inp[41] - 1.7320508075688774 * inp[44]; + out[42] = inp[42] - 1.7320508075688774 * inp[45]; + out[43] = 0.0; + out[44] = 0.0; + out[45] = 0.0; + out[46] = inp[46] - 1.7320508075688774 * inp[47]; + out[47] = 0.0; + } else { + out[0] = 1.7320508075688772 * inp[1] + inp[0]; + out[1] = 0.0; + out[2] = 1.7320508075688772 * inp[6] + inp[2]; + out[3] = 1.7320508075688772 * inp[7] + inp[3]; + out[4] = 1.7320508075688772 * inp[9] + inp[4]; + out[5] = 1.7320508075688772 * inp[12] + inp[5]; + out[6] = 0.0; + out[7] = 0.0; + out[8] = 1.7320508075688772 * inp[16] + inp[8]; + out[9] = 0.0; + out[10] = 1.7320508075688772 * inp[17] + inp[10]; + out[11] = 1.7320508075688772 * inp[18] + inp[11]; + out[12] = 0.0; + out[13] = 1.7320508075688772 * inp[20] + inp[13]; + out[14] = 1.7320508075688772 * inp[21] + inp[14]; + out[15] = 1.7320508075688772 * inp[23] + inp[15]; + out[16] = 0.0; + out[17] = 0.0; + out[18] = 0.0; + out[19] = 1.7320508075688772 * inp[26] + inp[19]; + out[20] = 0.0; + out[21] = 0.0; + out[22] = 1.7320508075688772 * inp[27] + inp[22]; + out[23] = 0.0; + out[24] = 1.7320508075688772 * inp[28] + inp[24]; + out[25] = 1.7320508075688772 * inp[29] + inp[25]; + out[26] = 0.0; + out[27] = 0.0; + out[28] = 0.0; + out[29] = 0.0; + out[30] = 1.7320508075688772 * inp[31] + inp[30]; + out[31] = 0.0; + out[32] = 1.7320508075688774 * inp[33] + inp[32]; + out[33] = 0.0; + out[34] = 1.7320508075688774 * inp[37] + inp[34]; + out[35] = 1.7320508075688774 * inp[38] + inp[35]; + out[36] = 1.7320508075688774 * inp[40] + inp[36]; + out[37] = 0.0; + out[38] = 0.0; + out[39] = 1.7320508075688774 * inp[43] + inp[39]; + out[40] = 0.0; + out[41] = 1.7320508075688774 * inp[44] + inp[41]; + out[42] = 1.7320508075688774 * inp[45] + inp[42]; + out[43] = 0.0; + out[44] = 0.0; + out[45] = 0.0; + out[46] = 1.7320508075688774 * inp[47] + inp[46]; + out[47] = 0.0; + } + } else if (dir == 1) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[2]; - out[1] = inp[1]-1.7320508075688772*inp[6]; - out[2] = 0.0; - out[3] = inp[3]-1.7320508075688772*inp[8]; - out[4] = inp[4]-1.7320508075688772*inp[10]; - out[5] = inp[5]-1.7320508075688772*inp[13]; - out[6] = 0.0; - out[7] = inp[7]-1.7320508075688772*inp[16]; - out[8] = 0.0; - out[9] = inp[9]-1.7320508075688772*inp[17]; - out[10] = 0.0; - out[11] = inp[11]-1.7320508075688772*inp[19]; - out[12] = inp[12]-1.7320508075688772*inp[20]; - out[13] = 0.0; - out[14] = inp[14]-1.7320508075688772*inp[22]; - out[15] = inp[15]-1.7320508075688772*inp[24]; - out[16] = 0.0; - out[17] = 0.0; - out[18] = inp[18]-1.7320508075688772*inp[26]; - out[19] = 0.0; - out[20] = 0.0; - out[21] = inp[21]-1.7320508075688772*inp[27]; - out[22] = 0.0; - out[23] = inp[23]-1.7320508075688772*inp[28]; - out[24] = 0.0; - out[25] = inp[25]-1.7320508075688772*inp[30]; - out[26] = 0.0; - out[27] = 0.0; - out[28] = 0.0; - out[29] = inp[29]-1.7320508075688772*inp[31]; - out[30] = 0.0; - out[31] = 0.0; - out[32] = inp[32]-1.7320508075688774*inp[34]; - out[33] = inp[33]-1.7320508075688774*inp[37]; - out[34] = 0.0; - out[35] = inp[35]-1.7320508075688774*inp[39]; - out[36] = inp[36]-1.7320508075688774*inp[41]; - out[37] = 0.0; - out[38] = inp[38]-1.7320508075688774*inp[43]; - out[39] = 0.0; - out[40] = inp[40]-1.7320508075688774*inp[44]; - out[41] = 0.0; - out[42] = inp[42]-1.7320508075688774*inp[46]; - out[43] = 0.0; - out[44] = 0.0; - out[45] = inp[45]-1.7320508075688774*inp[47]; - out[46] = 0.0; - out[47] = 0.0; - } - else { - out[0] = 1.7320508075688772*inp[2]+inp[0]; - out[1] = 1.7320508075688772*inp[6]+inp[1]; - out[2] = 0.0; - out[3] = 1.7320508075688772*inp[8]+inp[3]; - out[4] = 1.7320508075688772*inp[10]+inp[4]; - out[5] = 1.7320508075688772*inp[13]+inp[5]; - out[6] = 0.0; - out[7] = 1.7320508075688772*inp[16]+inp[7]; - out[8] = 0.0; - out[9] = 1.7320508075688772*inp[17]+inp[9]; - out[10] = 0.0; - out[11] = 1.7320508075688772*inp[19]+inp[11]; - out[12] = 1.7320508075688772*inp[20]+inp[12]; - out[13] = 0.0; - out[14] = 1.7320508075688772*inp[22]+inp[14]; - out[15] = 1.7320508075688772*inp[24]+inp[15]; - out[16] = 0.0; - out[17] = 0.0; - out[18] = 1.7320508075688772*inp[26]+inp[18]; - out[19] = 0.0; - out[20] = 0.0; - out[21] = 1.7320508075688772*inp[27]+inp[21]; - out[22] = 0.0; - out[23] = 1.7320508075688772*inp[28]+inp[23]; - out[24] = 0.0; - out[25] = 1.7320508075688772*inp[30]+inp[25]; - out[26] = 0.0; - out[27] = 0.0; - out[28] = 0.0; - out[29] = 1.7320508075688772*inp[31]+inp[29]; - out[30] = 0.0; - out[31] = 0.0; - out[32] = 1.7320508075688774*inp[34]+inp[32]; - out[33] = 1.7320508075688774*inp[37]+inp[33]; - out[34] = 0.0; - out[35] = 1.7320508075688774*inp[39]+inp[35]; - out[36] = 1.7320508075688774*inp[41]+inp[36]; - out[37] = 0.0; - out[38] = 1.7320508075688774*inp[43]+inp[38]; - out[39] = 0.0; - out[40] = 1.7320508075688774*inp[44]+inp[40]; - out[41] = 0.0; - out[42] = 1.7320508075688774*inp[46]+inp[42]; - out[43] = 0.0; - out[44] = 0.0; - out[45] = 1.7320508075688774*inp[47]+inp[45]; - out[46] = 0.0; - out[47] = 0.0; - } - } - else if (dir == 2) { + out[0] = inp[0] - 1.7320508075688772 * inp[2]; + out[1] = inp[1] - 1.7320508075688772 * inp[6]; + out[2] = 0.0; + out[3] = inp[3] - 1.7320508075688772 * inp[8]; + out[4] = inp[4] - 1.7320508075688772 * inp[10]; + out[5] = inp[5] - 1.7320508075688772 * inp[13]; + out[6] = 0.0; + out[7] = inp[7] - 1.7320508075688772 * inp[16]; + out[8] = 0.0; + out[9] = inp[9] - 1.7320508075688772 * inp[17]; + out[10] = 0.0; + out[11] = inp[11] - 1.7320508075688772 * inp[19]; + out[12] = inp[12] - 1.7320508075688772 * inp[20]; + out[13] = 0.0; + out[14] = inp[14] - 1.7320508075688772 * inp[22]; + out[15] = inp[15] - 1.7320508075688772 * inp[24]; + out[16] = 0.0; + out[17] = 0.0; + out[18] = inp[18] - 1.7320508075688772 * inp[26]; + out[19] = 0.0; + out[20] = 0.0; + out[21] = inp[21] - 1.7320508075688772 * inp[27]; + out[22] = 0.0; + out[23] = inp[23] - 1.7320508075688772 * inp[28]; + out[24] = 0.0; + out[25] = inp[25] - 1.7320508075688772 * inp[30]; + out[26] = 0.0; + out[27] = 0.0; + out[28] = 0.0; + out[29] = inp[29] - 1.7320508075688772 * inp[31]; + out[30] = 0.0; + out[31] = 0.0; + out[32] = inp[32] - 1.7320508075688774 * inp[34]; + out[33] = inp[33] - 1.7320508075688774 * inp[37]; + out[34] = 0.0; + out[35] = inp[35] - 1.7320508075688774 * inp[39]; + out[36] = inp[36] - 1.7320508075688774 * inp[41]; + out[37] = 0.0; + out[38] = inp[38] - 1.7320508075688774 * inp[43]; + out[39] = 0.0; + out[40] = inp[40] - 1.7320508075688774 * inp[44]; + out[41] = 0.0; + out[42] = inp[42] - 1.7320508075688774 * inp[46]; + out[43] = 0.0; + out[44] = 0.0; + out[45] = inp[45] - 1.7320508075688774 * inp[47]; + out[46] = 0.0; + out[47] = 0.0; + } else { + out[0] = 1.7320508075688772 * inp[2] + inp[0]; + out[1] = 1.7320508075688772 * inp[6] + inp[1]; + out[2] = 0.0; + out[3] = 1.7320508075688772 * inp[8] + inp[3]; + out[4] = 1.7320508075688772 * inp[10] + inp[4]; + out[5] = 1.7320508075688772 * inp[13] + inp[5]; + out[6] = 0.0; + out[7] = 1.7320508075688772 * inp[16] + inp[7]; + out[8] = 0.0; + out[9] = 1.7320508075688772 * inp[17] + inp[9]; + out[10] = 0.0; + out[11] = 1.7320508075688772 * inp[19] + inp[11]; + out[12] = 1.7320508075688772 * inp[20] + inp[12]; + out[13] = 0.0; + out[14] = 1.7320508075688772 * inp[22] + inp[14]; + out[15] = 1.7320508075688772 * inp[24] + inp[15]; + out[16] = 0.0; + out[17] = 0.0; + out[18] = 1.7320508075688772 * inp[26] + inp[18]; + out[19] = 0.0; + out[20] = 0.0; + out[21] = 1.7320508075688772 * inp[27] + inp[21]; + out[22] = 0.0; + out[23] = 1.7320508075688772 * inp[28] + inp[23]; + out[24] = 0.0; + out[25] = 1.7320508075688772 * inp[30] + inp[25]; + out[26] = 0.0; + out[27] = 0.0; + out[28] = 0.0; + out[29] = 1.7320508075688772 * inp[31] + inp[29]; + out[30] = 0.0; + out[31] = 0.0; + out[32] = 1.7320508075688774 * inp[34] + inp[32]; + out[33] = 1.7320508075688774 * inp[37] + inp[33]; + out[34] = 0.0; + out[35] = 1.7320508075688774 * inp[39] + inp[35]; + out[36] = 1.7320508075688774 * inp[41] + inp[36]; + out[37] = 0.0; + out[38] = 1.7320508075688774 * inp[43] + inp[38]; + out[39] = 0.0; + out[40] = 1.7320508075688774 * inp[44] + inp[40]; + out[41] = 0.0; + out[42] = 1.7320508075688774 * inp[46] + inp[42]; + out[43] = 0.0; + out[44] = 0.0; + out[45] = 1.7320508075688774 * inp[47] + inp[45]; + out[46] = 0.0; + out[47] = 0.0; + } + } else if (dir == 2) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[3]; - out[1] = inp[1]-1.7320508075688772*inp[7]; - out[2] = inp[2]-1.7320508075688772*inp[8]; - out[3] = 0.0; - out[4] = inp[4]-1.7320508075688772*inp[11]; - out[5] = inp[5]-1.7320508075688772*inp[14]; - out[6] = inp[6]-1.7320508075688772*inp[16]; - out[7] = 0.0; - out[8] = 0.0; - out[9] = inp[9]-1.7320508075688772*inp[18]; - out[10] = inp[10]-1.7320508075688772*inp[19]; - out[11] = 0.0; - out[12] = inp[12]-1.7320508075688772*inp[21]; - out[13] = inp[13]-1.7320508075688772*inp[22]; - out[14] = 0.0; - out[15] = inp[15]-1.7320508075688772*inp[25]; - out[16] = 0.0; - out[17] = inp[17]-1.7320508075688772*inp[26]; - out[18] = 0.0; - out[19] = 0.0; - out[20] = inp[20]-1.7320508075688772*inp[27]; - out[21] = 0.0; - out[22] = 0.0; - out[23] = inp[23]-1.7320508075688772*inp[29]; - out[24] = inp[24]-1.7320508075688772*inp[30]; - out[25] = 0.0; - out[26] = 0.0; - out[27] = 0.0; - out[28] = inp[28]-1.7320508075688772*inp[31]; - out[29] = 0.0; - out[30] = 0.0; - out[31] = 0.0; - out[32] = inp[32]-1.7320508075688774*inp[35]; - out[33] = inp[33]-1.7320508075688774*inp[38]; - out[34] = inp[34]-1.7320508075688774*inp[39]; - out[35] = 0.0; - out[36] = inp[36]-1.7320508075688774*inp[42]; - out[37] = inp[37]-1.7320508075688774*inp[43]; - out[38] = 0.0; - out[39] = 0.0; - out[40] = inp[40]-1.7320508075688774*inp[45]; - out[41] = inp[41]-1.7320508075688774*inp[46]; - out[42] = 0.0; - out[43] = 0.0; - out[44] = inp[44]-1.7320508075688774*inp[47]; - out[45] = 0.0; - out[46] = 0.0; - out[47] = 0.0; - } - else { - out[0] = 1.7320508075688772*inp[3]+inp[0]; - out[1] = 1.7320508075688772*inp[7]+inp[1]; - out[2] = 1.7320508075688772*inp[8]+inp[2]; - out[3] = 0.0; - out[4] = 1.7320508075688772*inp[11]+inp[4]; - out[5] = 1.7320508075688772*inp[14]+inp[5]; - out[6] = 1.7320508075688772*inp[16]+inp[6]; - out[7] = 0.0; - out[8] = 0.0; - out[9] = 1.7320508075688772*inp[18]+inp[9]; - out[10] = 1.7320508075688772*inp[19]+inp[10]; - out[11] = 0.0; - out[12] = 1.7320508075688772*inp[21]+inp[12]; - out[13] = 1.7320508075688772*inp[22]+inp[13]; - out[14] = 0.0; - out[15] = 1.7320508075688772*inp[25]+inp[15]; - out[16] = 0.0; - out[17] = 1.7320508075688772*inp[26]+inp[17]; - out[18] = 0.0; - out[19] = 0.0; - out[20] = 1.7320508075688772*inp[27]+inp[20]; - out[21] = 0.0; - out[22] = 0.0; - out[23] = 1.7320508075688772*inp[29]+inp[23]; - out[24] = 1.7320508075688772*inp[30]+inp[24]; - out[25] = 0.0; - out[26] = 0.0; - out[27] = 0.0; - out[28] = 1.7320508075688772*inp[31]+inp[28]; - out[29] = 0.0; - out[30] = 0.0; - out[31] = 0.0; - out[32] = 1.7320508075688774*inp[35]+inp[32]; - out[33] = 1.7320508075688774*inp[38]+inp[33]; - out[34] = 1.7320508075688774*inp[39]+inp[34]; - out[35] = 0.0; - out[36] = 1.7320508075688774*inp[42]+inp[36]; - out[37] = 1.7320508075688774*inp[43]+inp[37]; - out[38] = 0.0; - out[39] = 0.0; - out[40] = 1.7320508075688774*inp[45]+inp[40]; - out[41] = 1.7320508075688774*inp[46]+inp[41]; - out[42] = 0.0; - out[43] = 0.0; - out[44] = 1.7320508075688774*inp[47]+inp[44]; - out[45] = 0.0; - out[46] = 0.0; - out[47] = 0.0; - } - } - else if (dir == 3) { + out[0] = inp[0] - 1.7320508075688772 * inp[3]; + out[1] = inp[1] - 1.7320508075688772 * inp[7]; + out[2] = inp[2] - 1.7320508075688772 * inp[8]; + out[3] = 0.0; + out[4] = inp[4] - 1.7320508075688772 * inp[11]; + out[5] = inp[5] - 1.7320508075688772 * inp[14]; + out[6] = inp[6] - 1.7320508075688772 * inp[16]; + out[7] = 0.0; + out[8] = 0.0; + out[9] = inp[9] - 1.7320508075688772 * inp[18]; + out[10] = inp[10] - 1.7320508075688772 * inp[19]; + out[11] = 0.0; + out[12] = inp[12] - 1.7320508075688772 * inp[21]; + out[13] = inp[13] - 1.7320508075688772 * inp[22]; + out[14] = 0.0; + out[15] = inp[15] - 1.7320508075688772 * inp[25]; + out[16] = 0.0; + out[17] = inp[17] - 1.7320508075688772 * inp[26]; + out[18] = 0.0; + out[19] = 0.0; + out[20] = inp[20] - 1.7320508075688772 * inp[27]; + out[21] = 0.0; + out[22] = 0.0; + out[23] = inp[23] - 1.7320508075688772 * inp[29]; + out[24] = inp[24] - 1.7320508075688772 * inp[30]; + out[25] = 0.0; + out[26] = 0.0; + out[27] = 0.0; + out[28] = inp[28] - 1.7320508075688772 * inp[31]; + out[29] = 0.0; + out[30] = 0.0; + out[31] = 0.0; + out[32] = inp[32] - 1.7320508075688774 * inp[35]; + out[33] = inp[33] - 1.7320508075688774 * inp[38]; + out[34] = inp[34] - 1.7320508075688774 * inp[39]; + out[35] = 0.0; + out[36] = inp[36] - 1.7320508075688774 * inp[42]; + out[37] = inp[37] - 1.7320508075688774 * inp[43]; + out[38] = 0.0; + out[39] = 0.0; + out[40] = inp[40] - 1.7320508075688774 * inp[45]; + out[41] = inp[41] - 1.7320508075688774 * inp[46]; + out[42] = 0.0; + out[43] = 0.0; + out[44] = inp[44] - 1.7320508075688774 * inp[47]; + out[45] = 0.0; + out[46] = 0.0; + out[47] = 0.0; + } else { + out[0] = 1.7320508075688772 * inp[3] + inp[0]; + out[1] = 1.7320508075688772 * inp[7] + inp[1]; + out[2] = 1.7320508075688772 * inp[8] + inp[2]; + out[3] = 0.0; + out[4] = 1.7320508075688772 * inp[11] + inp[4]; + out[5] = 1.7320508075688772 * inp[14] + inp[5]; + out[6] = 1.7320508075688772 * inp[16] + inp[6]; + out[7] = 0.0; + out[8] = 0.0; + out[9] = 1.7320508075688772 * inp[18] + inp[9]; + out[10] = 1.7320508075688772 * inp[19] + inp[10]; + out[11] = 0.0; + out[12] = 1.7320508075688772 * inp[21] + inp[12]; + out[13] = 1.7320508075688772 * inp[22] + inp[13]; + out[14] = 0.0; + out[15] = 1.7320508075688772 * inp[25] + inp[15]; + out[16] = 0.0; + out[17] = 1.7320508075688772 * inp[26] + inp[17]; + out[18] = 0.0; + out[19] = 0.0; + out[20] = 1.7320508075688772 * inp[27] + inp[20]; + out[21] = 0.0; + out[22] = 0.0; + out[23] = 1.7320508075688772 * inp[29] + inp[23]; + out[24] = 1.7320508075688772 * inp[30] + inp[24]; + out[25] = 0.0; + out[26] = 0.0; + out[27] = 0.0; + out[28] = 1.7320508075688772 * inp[31] + inp[28]; + out[29] = 0.0; + out[30] = 0.0; + out[31] = 0.0; + out[32] = 1.7320508075688774 * inp[35] + inp[32]; + out[33] = 1.7320508075688774 * inp[38] + inp[33]; + out[34] = 1.7320508075688774 * inp[39] + inp[34]; + out[35] = 0.0; + out[36] = 1.7320508075688774 * inp[42] + inp[36]; + out[37] = 1.7320508075688774 * inp[43] + inp[37]; + out[38] = 0.0; + out[39] = 0.0; + out[40] = 1.7320508075688774 * inp[45] + inp[40]; + out[41] = 1.7320508075688774 * inp[46] + inp[41]; + out[42] = 0.0; + out[43] = 0.0; + out[44] = 1.7320508075688774 * inp[47] + inp[44]; + out[45] = 0.0; + out[46] = 0.0; + out[47] = 0.0; + } + } else if (dir == 3) { if (edge == GKYL_LOWER_EDGE) { - out[0] = 2.23606797749979*inp[32]-1.7320508075688772*inp[4]+inp[0]; - out[1] = 2.2360679774997902*inp[33]-1.7320508075688772*inp[9]+inp[1]; - out[2] = 2.2360679774997902*inp[34]-1.7320508075688772*inp[10]+inp[2]; - out[3] = 2.2360679774997902*inp[35]-1.7320508075688772*inp[11]+inp[3]; - out[4] = 0.0; - out[5] = 2.2360679774997902*inp[36]-1.7320508075688772*inp[15]+inp[5]; - out[6] = 2.23606797749979*inp[37]-1.7320508075688772*inp[17]+inp[6]; - out[7] = 2.23606797749979*inp[38]-1.7320508075688772*inp[18]+inp[7]; - out[8] = 2.23606797749979*inp[39]-1.7320508075688772*inp[19]+inp[8]; - out[9] = 0.0; - out[10] = 0.0; - out[11] = 0.0; - out[12] = 2.23606797749979*inp[40]-1.7320508075688772*inp[23]+inp[12]; - out[13] = 2.23606797749979*inp[41]-1.7320508075688772*inp[24]+inp[13]; - out[14] = 2.23606797749979*inp[42]-1.7320508075688772*inp[25]+inp[14]; - out[15] = 0.0; - out[16] = 2.2360679774997902*inp[43]-1.7320508075688772*inp[26]+inp[16]; - out[17] = 0.0; - out[18] = 0.0; - out[19] = 0.0; - out[20] = 2.2360679774997902*inp[44]-1.7320508075688772*inp[28]+inp[20]; - out[21] = 2.2360679774997902*inp[45]-1.7320508075688772*inp[29]+inp[21]; - out[22] = 2.2360679774997902*inp[46]-1.7320508075688772*inp[30]+inp[22]; - out[23] = 0.0; - out[24] = 0.0; - out[25] = 0.0; - out[26] = 0.0; - out[27] = 2.23606797749979*inp[47]-1.7320508075688772*inp[31]+inp[27]; - out[28] = 0.0; - out[29] = 0.0; - out[30] = 0.0; - out[31] = 0.0; - out[32] = 0.0; - out[33] = 0.0; - out[34] = 0.0; - out[35] = 0.0; - out[36] = 0.0; - out[37] = 0.0; - out[38] = 0.0; - out[39] = 0.0; - out[40] = 0.0; - out[41] = 0.0; - out[42] = 0.0; - out[43] = 0.0; - out[44] = 0.0; - out[45] = 0.0; - out[46] = 0.0; - out[47] = 0.0; - } - else { - out[0] = 2.23606797749979*inp[32]+1.7320508075688772*inp[4]+inp[0]; - out[1] = 2.2360679774997902*inp[33]+1.7320508075688772*inp[9]+inp[1]; - out[2] = 2.2360679774997902*inp[34]+1.7320508075688772*inp[10]+inp[2]; - out[3] = 2.2360679774997902*inp[35]+1.7320508075688772*inp[11]+inp[3]; - out[4] = 0.0; - out[5] = 2.2360679774997902*inp[36]+1.7320508075688772*inp[15]+inp[5]; - out[6] = 2.23606797749979*inp[37]+1.7320508075688772*inp[17]+inp[6]; - out[7] = 2.23606797749979*inp[38]+1.7320508075688772*inp[18]+inp[7]; - out[8] = 2.23606797749979*inp[39]+1.7320508075688772*inp[19]+inp[8]; - out[9] = 0.0; - out[10] = 0.0; - out[11] = 0.0; - out[12] = 2.23606797749979*inp[40]+1.7320508075688772*inp[23]+inp[12]; - out[13] = 2.23606797749979*inp[41]+1.7320508075688772*inp[24]+inp[13]; - out[14] = 2.23606797749979*inp[42]+1.7320508075688772*inp[25]+inp[14]; - out[15] = 0.0; - out[16] = 2.2360679774997902*inp[43]+1.7320508075688772*inp[26]+inp[16]; - out[17] = 0.0; - out[18] = 0.0; - out[19] = 0.0; - out[20] = 2.2360679774997902*inp[44]+1.7320508075688772*inp[28]+inp[20]; - out[21] = 2.2360679774997902*inp[45]+1.7320508075688772*inp[29]+inp[21]; - out[22] = 2.2360679774997902*inp[46]+1.7320508075688772*inp[30]+inp[22]; - out[23] = 0.0; - out[24] = 0.0; - out[25] = 0.0; - out[26] = 0.0; - out[27] = 2.23606797749979*inp[47]+1.7320508075688772*inp[31]+inp[27]; - out[28] = 0.0; - out[29] = 0.0; - out[30] = 0.0; - out[31] = 0.0; - out[32] = 0.0; - out[33] = 0.0; - out[34] = 0.0; - out[35] = 0.0; - out[36] = 0.0; - out[37] = 0.0; - out[38] = 0.0; - out[39] = 0.0; - out[40] = 0.0; - out[41] = 0.0; - out[42] = 0.0; - out[43] = 0.0; - out[44] = 0.0; - out[45] = 0.0; - out[46] = 0.0; - out[47] = 0.0; - } - } - else if (dir == 4) { + out[0] = 2.23606797749979 * inp[32] - 1.7320508075688772 * inp[4] + inp[0]; + out[1] = 2.2360679774997902 * inp[33] - 1.7320508075688772 * inp[9] + inp[1]; + out[2] = 2.2360679774997902 * inp[34] - 1.7320508075688772 * inp[10] + inp[2]; + out[3] = 2.2360679774997902 * inp[35] - 1.7320508075688772 * inp[11] + inp[3]; + out[4] = 0.0; + out[5] = 2.2360679774997902 * inp[36] - 1.7320508075688772 * inp[15] + inp[5]; + out[6] = 2.23606797749979 * inp[37] - 1.7320508075688772 * inp[17] + inp[6]; + out[7] = 2.23606797749979 * inp[38] - 1.7320508075688772 * inp[18] + inp[7]; + out[8] = 2.23606797749979 * inp[39] - 1.7320508075688772 * inp[19] + inp[8]; + out[9] = 0.0; + out[10] = 0.0; + out[11] = 0.0; + out[12] = 2.23606797749979 * inp[40] - 1.7320508075688772 * inp[23] + inp[12]; + out[13] = 2.23606797749979 * inp[41] - 1.7320508075688772 * inp[24] + inp[13]; + out[14] = 2.23606797749979 * inp[42] - 1.7320508075688772 * inp[25] + inp[14]; + out[15] = 0.0; + out[16] = 2.2360679774997902 * inp[43] - 1.7320508075688772 * inp[26] + inp[16]; + out[17] = 0.0; + out[18] = 0.0; + out[19] = 0.0; + out[20] = 2.2360679774997902 * inp[44] - 1.7320508075688772 * inp[28] + inp[20]; + out[21] = 2.2360679774997902 * inp[45] - 1.7320508075688772 * inp[29] + inp[21]; + out[22] = 2.2360679774997902 * inp[46] - 1.7320508075688772 * inp[30] + inp[22]; + out[23] = 0.0; + out[24] = 0.0; + out[25] = 0.0; + out[26] = 0.0; + out[27] = 2.23606797749979 * inp[47] - 1.7320508075688772 * inp[31] + inp[27]; + out[28] = 0.0; + out[29] = 0.0; + out[30] = 0.0; + out[31] = 0.0; + out[32] = 0.0; + out[33] = 0.0; + out[34] = 0.0; + out[35] = 0.0; + out[36] = 0.0; + out[37] = 0.0; + out[38] = 0.0; + out[39] = 0.0; + out[40] = 0.0; + out[41] = 0.0; + out[42] = 0.0; + out[43] = 0.0; + out[44] = 0.0; + out[45] = 0.0; + out[46] = 0.0; + out[47] = 0.0; + } else { + out[0] = 2.23606797749979 * inp[32] + 1.7320508075688772 * inp[4] + inp[0]; + out[1] = 2.2360679774997902 * inp[33] + 1.7320508075688772 * inp[9] + inp[1]; + out[2] = 2.2360679774997902 * inp[34] + 1.7320508075688772 * inp[10] + inp[2]; + out[3] = 2.2360679774997902 * inp[35] + 1.7320508075688772 * inp[11] + inp[3]; + out[4] = 0.0; + out[5] = 2.2360679774997902 * inp[36] + 1.7320508075688772 * inp[15] + inp[5]; + out[6] = 2.23606797749979 * inp[37] + 1.7320508075688772 * inp[17] + inp[6]; + out[7] = 2.23606797749979 * inp[38] + 1.7320508075688772 * inp[18] + inp[7]; + out[8] = 2.23606797749979 * inp[39] + 1.7320508075688772 * inp[19] + inp[8]; + out[9] = 0.0; + out[10] = 0.0; + out[11] = 0.0; + out[12] = 2.23606797749979 * inp[40] + 1.7320508075688772 * inp[23] + inp[12]; + out[13] = 2.23606797749979 * inp[41] + 1.7320508075688772 * inp[24] + inp[13]; + out[14] = 2.23606797749979 * inp[42] + 1.7320508075688772 * inp[25] + inp[14]; + out[15] = 0.0; + out[16] = 2.2360679774997902 * inp[43] + 1.7320508075688772 * inp[26] + inp[16]; + out[17] = 0.0; + out[18] = 0.0; + out[19] = 0.0; + out[20] = 2.2360679774997902 * inp[44] + 1.7320508075688772 * inp[28] + inp[20]; + out[21] = 2.2360679774997902 * inp[45] + 1.7320508075688772 * inp[29] + inp[21]; + out[22] = 2.2360679774997902 * inp[46] + 1.7320508075688772 * inp[30] + inp[22]; + out[23] = 0.0; + out[24] = 0.0; + out[25] = 0.0; + out[26] = 0.0; + out[27] = 2.23606797749979 * inp[47] + 1.7320508075688772 * inp[31] + inp[27]; + out[28] = 0.0; + out[29] = 0.0; + out[30] = 0.0; + out[31] = 0.0; + out[32] = 0.0; + out[33] = 0.0; + out[34] = 0.0; + out[35] = 0.0; + out[36] = 0.0; + out[37] = 0.0; + out[38] = 0.0; + out[39] = 0.0; + out[40] = 0.0; + out[41] = 0.0; + out[42] = 0.0; + out[43] = 0.0; + out[44] = 0.0; + out[45] = 0.0; + out[46] = 0.0; + out[47] = 0.0; + } + } else if (dir == 4) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-1.7320508075688772*inp[5]; - out[1] = inp[1]-1.7320508075688772*inp[12]; - out[2] = inp[2]-1.7320508075688772*inp[13]; - out[3] = inp[3]-1.7320508075688772*inp[14]; - out[4] = inp[4]-1.7320508075688772*inp[15]; - out[5] = 0.0; - out[6] = inp[6]-1.7320508075688772*inp[20]; - out[7] = inp[7]-1.7320508075688772*inp[21]; - out[8] = inp[8]-1.7320508075688772*inp[22]; - out[9] = inp[9]-1.7320508075688772*inp[23]; - out[10] = inp[10]-1.7320508075688772*inp[24]; - out[11] = inp[11]-1.7320508075688772*inp[25]; - out[12] = 0.0; - out[13] = 0.0; - out[14] = 0.0; - out[15] = 0.0; - out[16] = inp[16]-1.7320508075688772*inp[27]; - out[17] = inp[17]-1.7320508075688772*inp[28]; - out[18] = inp[18]-1.7320508075688772*inp[29]; - out[19] = inp[19]-1.7320508075688772*inp[30]; - out[20] = 0.0; - out[21] = 0.0; - out[22] = 0.0; - out[23] = 0.0; - out[24] = 0.0; - out[25] = 0.0; - out[26] = inp[26]-1.7320508075688772*inp[31]; - out[27] = 0.0; - out[28] = 0.0; - out[29] = 0.0; - out[30] = 0.0; - out[31] = 0.0; - out[32] = inp[32]-1.7320508075688774*inp[36]; - out[33] = inp[33]-1.7320508075688774*inp[40]; - out[34] = inp[34]-1.7320508075688774*inp[41]; - out[35] = inp[35]-1.7320508075688774*inp[42]; - out[36] = 0.0; - out[37] = inp[37]-1.7320508075688774*inp[44]; - out[38] = inp[38]-1.7320508075688774*inp[45]; - out[39] = inp[39]-1.7320508075688774*inp[46]; - out[40] = 0.0; - out[41] = 0.0; - out[42] = 0.0; - out[43] = inp[43]-1.7320508075688774*inp[47]; - out[44] = 0.0; - out[45] = 0.0; - out[46] = 0.0; - out[47] = 0.0; - } - else { - out[0] = 1.7320508075688772*inp[5]+inp[0]; - out[1] = 1.7320508075688772*inp[12]+inp[1]; - out[2] = 1.7320508075688772*inp[13]+inp[2]; - out[3] = 1.7320508075688772*inp[14]+inp[3]; - out[4] = 1.7320508075688772*inp[15]+inp[4]; - out[5] = 0.0; - out[6] = 1.7320508075688772*inp[20]+inp[6]; - out[7] = 1.7320508075688772*inp[21]+inp[7]; - out[8] = 1.7320508075688772*inp[22]+inp[8]; - out[9] = 1.7320508075688772*inp[23]+inp[9]; - out[10] = 1.7320508075688772*inp[24]+inp[10]; - out[11] = 1.7320508075688772*inp[25]+inp[11]; - out[12] = 0.0; - out[13] = 0.0; - out[14] = 0.0; - out[15] = 0.0; - out[16] = 1.7320508075688772*inp[27]+inp[16]; - out[17] = 1.7320508075688772*inp[28]+inp[17]; - out[18] = 1.7320508075688772*inp[29]+inp[18]; - out[19] = 1.7320508075688772*inp[30]+inp[19]; - out[20] = 0.0; - out[21] = 0.0; - out[22] = 0.0; - out[23] = 0.0; - out[24] = 0.0; - out[25] = 0.0; - out[26] = 1.7320508075688772*inp[31]+inp[26]; - out[27] = 0.0; - out[28] = 0.0; - out[29] = 0.0; - out[30] = 0.0; - out[31] = 0.0; - out[32] = 1.7320508075688774*inp[36]+inp[32]; - out[33] = 1.7320508075688774*inp[40]+inp[33]; - out[34] = 1.7320508075688774*inp[41]+inp[34]; - out[35] = 1.7320508075688774*inp[42]+inp[35]; - out[36] = 0.0; - out[37] = 1.7320508075688774*inp[44]+inp[37]; - out[38] = 1.7320508075688774*inp[45]+inp[38]; - out[39] = 1.7320508075688774*inp[46]+inp[39]; - out[40] = 0.0; - out[41] = 0.0; - out[42] = 0.0; - out[43] = 1.7320508075688774*inp[47]+inp[43]; - out[44] = 0.0; - out[45] = 0.0; - out[46] = 0.0; - out[47] = 0.0; + out[0] = inp[0] - 1.7320508075688772 * inp[5]; + out[1] = inp[1] - 1.7320508075688772 * inp[12]; + out[2] = inp[2] - 1.7320508075688772 * inp[13]; + out[3] = inp[3] - 1.7320508075688772 * inp[14]; + out[4] = inp[4] - 1.7320508075688772 * inp[15]; + out[5] = 0.0; + out[6] = inp[6] - 1.7320508075688772 * inp[20]; + out[7] = inp[7] - 1.7320508075688772 * inp[21]; + out[8] = inp[8] - 1.7320508075688772 * inp[22]; + out[9] = inp[9] - 1.7320508075688772 * inp[23]; + out[10] = inp[10] - 1.7320508075688772 * inp[24]; + out[11] = inp[11] - 1.7320508075688772 * inp[25]; + out[12] = 0.0; + out[13] = 0.0; + out[14] = 0.0; + out[15] = 0.0; + out[16] = inp[16] - 1.7320508075688772 * inp[27]; + out[17] = inp[17] - 1.7320508075688772 * inp[28]; + out[18] = inp[18] - 1.7320508075688772 * inp[29]; + out[19] = inp[19] - 1.7320508075688772 * inp[30]; + out[20] = 0.0; + out[21] = 0.0; + out[22] = 0.0; + out[23] = 0.0; + out[24] = 0.0; + out[25] = 0.0; + out[26] = inp[26] - 1.7320508075688772 * inp[31]; + out[27] = 0.0; + out[28] = 0.0; + out[29] = 0.0; + out[30] = 0.0; + out[31] = 0.0; + out[32] = inp[32] - 1.7320508075688774 * inp[36]; + out[33] = inp[33] - 1.7320508075688774 * inp[40]; + out[34] = inp[34] - 1.7320508075688774 * inp[41]; + out[35] = inp[35] - 1.7320508075688774 * inp[42]; + out[36] = 0.0; + out[37] = inp[37] - 1.7320508075688774 * inp[44]; + out[38] = inp[38] - 1.7320508075688774 * inp[45]; + out[39] = inp[39] - 1.7320508075688774 * inp[46]; + out[40] = 0.0; + out[41] = 0.0; + out[42] = 0.0; + out[43] = inp[43] - 1.7320508075688774 * inp[47]; + out[44] = 0.0; + out[45] = 0.0; + out[46] = 0.0; + out[47] = 0.0; + } else { + out[0] = 1.7320508075688772 * inp[5] + inp[0]; + out[1] = 1.7320508075688772 * inp[12] + inp[1]; + out[2] = 1.7320508075688772 * inp[13] + inp[2]; + out[3] = 1.7320508075688772 * inp[14] + inp[3]; + out[4] = 1.7320508075688772 * inp[15] + inp[4]; + out[5] = 0.0; + out[6] = 1.7320508075688772 * inp[20] + inp[6]; + out[7] = 1.7320508075688772 * inp[21] + inp[7]; + out[8] = 1.7320508075688772 * inp[22] + inp[8]; + out[9] = 1.7320508075688772 * inp[23] + inp[9]; + out[10] = 1.7320508075688772 * inp[24] + inp[10]; + out[11] = 1.7320508075688772 * inp[25] + inp[11]; + out[12] = 0.0; + out[13] = 0.0; + out[14] = 0.0; + out[15] = 0.0; + out[16] = 1.7320508075688772 * inp[27] + inp[16]; + out[17] = 1.7320508075688772 * inp[28] + inp[17]; + out[18] = 1.7320508075688772 * inp[29] + inp[18]; + out[19] = 1.7320508075688772 * inp[30] + inp[19]; + out[20] = 0.0; + out[21] = 0.0; + out[22] = 0.0; + out[23] = 0.0; + out[24] = 0.0; + out[25] = 0.0; + out[26] = 1.7320508075688772 * inp[31] + inp[26]; + out[27] = 0.0; + out[28] = 0.0; + out[29] = 0.0; + out[30] = 0.0; + out[31] = 0.0; + out[32] = 1.7320508075688774 * inp[36] + inp[32]; + out[33] = 1.7320508075688774 * inp[40] + inp[33]; + out[34] = 1.7320508075688774 * inp[41] + inp[34]; + out[35] = 1.7320508075688774 * inp[42] + inp[35]; + out[36] = 0.0; + out[37] = 1.7320508075688774 * inp[44] + inp[37]; + out[38] = 1.7320508075688774 * inp[45] + inp[38]; + out[39] = 1.7320508075688774 * inp[46] + inp[39]; + out[40] = 0.0; + out[41] = 0.0; + out[42] = 0.0; + out[43] = 1.7320508075688774 * inp[47] + inp[43]; + out[44] = 0.0; + out[45] = 0.0; + out[46] = 0.0; + out[47] = 0.0; } } } diff --git a/gyrokinetic/zero/gkyl_bc_block_tensor.h b/gyrokinetic/zero/gkyl_bc_block_tensor.h index c78770f4df..8f2f078d9b 100644 --- a/gyrokinetic/zero/gkyl_bc_block_tensor.h +++ b/gyrokinetic/zero/gkyl_bc_block_tensor.h @@ -3,8 +3,7 @@ #include #include -typedef struct bc_block_tensor bc_block_tensor; - +typedef struct bc_block_tensor bc_block_tensor; /** * Create a new updater to compute the transformation required to pass fluxes from another block with different @@ -15,10 +14,10 @@ typedef struct bc_block_tensor bc_block_tensor; * @param basis configuration space basis * @param use_gpu whether or not to use a gpu */ -struct bc_block_tensor* -gkyl_bc_block_tensor_new(const struct gkyl_rect_grid* grid, const struct gkyl_range *range, const struct gkyl_range* range_ext, - const struct gkyl_basis* basis, bool use_gpu); - +struct bc_block_tensor *gkyl_bc_block_tensor_new( + const struct gkyl_rect_grid *grid, const struct gkyl_range *range, + const struct gkyl_range *range_ext, const struct gkyl_basis *basis, bool use_gpu +); /** * Take in modal expansions of duals of one block and tangents of the other (cartesian components) @@ -32,8 +31,10 @@ gkyl_bc_block_tensor_new(const struct gkyl_rect_grid* grid, const struct gkyl_ra * @param ej duals of block which fluxes enter * @param e_i tangent vectors of block which fluxes leave */ -void calc_tensor(struct bc_block_tensor *up, int dir, int edge1, int edge2, const double *ej, const double *e_i, double *tj_i); - +void calc_tensor( + struct bc_block_tensor *up, int dir, int edge1, int edge2, const double *ej, const double *e_i, + double *tj_i +); /** * Take in modal expansions of duals of one block and tangents of the other (cartesian components) @@ -44,13 +45,13 @@ void calc_tensor(struct bc_block_tensor *up, int dir, int edge1, int edge2, cons * @param ej duals of block which fluxes enter * @param e_i tangent vectors of block which fluxes leave */ -void gkyl_bc_block_tensor_advance(struct bc_block_tensor* up, int dir, int edge1, int edge2, - struct gkyl_array* dxdz1, struct gkyl_array* dzdx2, struct gkyl_range *range1, struct gkyl_range *range2); - - +void gkyl_bc_block_tensor_advance( + struct bc_block_tensor *up, int dir, int edge1, int edge2, struct gkyl_array *dxdz1, + struct gkyl_array *dzdx2, struct gkyl_range *range1, struct gkyl_range *range2 +); /** * Free the bc_block_tensor updater * @param up updater to be freed */ -void gkyl_bc_block_tensor_release(struct bc_block_tensor* up); +void gkyl_bc_block_tensor_release(struct bc_block_tensor *up); diff --git a/gyrokinetic/zero/gkyl_bc_block_tensor_priv.h b/gyrokinetic/zero/gkyl_bc_block_tensor_priv.h index 38bebce596..e9315ff909 100644 --- a/gyrokinetic/zero/gkyl_bc_block_tensor_priv.h +++ b/gyrokinetic/zero/gkyl_bc_block_tensor_priv.h @@ -9,47 +9,40 @@ typedef double (*modal_to_quad_kernel)(const double *f); - -typedef struct { modal_to_quad_kernel kernels[4]; } modal_to_quad_kernel_list; -typedef struct { modal_to_quad_kernel_list list[6]; } modal_to_quad_kernel_dim_list; - - - -GKYL_CU_D -static const modal_to_quad_kernel_dim_list ser_modal_to_quad_kernel_dim_list[] = { - { .list = { - {NULL, NULL, NULL}, - {NULL, NULL, NULL}, - } - }, - { .list = { - {NULL, NULL, NULL}, - {NULL, NULL, NULL}, - } - }, +typedef struct { + modal_to_quad_kernel kernels[4]; +} modal_to_quad_kernel_list; +typedef struct { + modal_to_quad_kernel_list list[6]; +} modal_to_quad_kernel_dim_list; + +GKYL_CU_D static const modal_to_quad_kernel_dim_list ser_modal_to_quad_kernel_dim_list[] = { + {.list = {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}, + {.list = {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}, // 2X - { .list = { - {ser_2x_p1_surfx1_eval_quad_node_0_l, ser_2x_p1_surfx1_eval_quad_node_1_l, NULL, NULL}, + {.list = + {{ser_2x_p1_surfx1_eval_quad_node_0_l, ser_2x_p1_surfx1_eval_quad_node_1_l, NULL, NULL}, {ser_2x_p1_surfx1_eval_quad_node_0_r, ser_2x_p1_surfx1_eval_quad_node_1_r, NULL, NULL}, {ser_2x_p1_surfx2_eval_quad_node_0_l, ser_2x_p1_surfx2_eval_quad_node_1_l, NULL, NULL}, {ser_2x_p1_surfx2_eval_quad_node_0_r, ser_2x_p1_surfx2_eval_quad_node_1_r, NULL, NULL}, - {NULL, NULL, NULL , NULL}, - {NULL, NULL, NULL , NULL}, - } - }, + {NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}}}, // 3X - { .list = { - {ser_3x_p1_surfx1_eval_quad_node_0_l, ser_3x_p1_surfx1_eval_quad_node_1_l, ser_3x_p1_surfx1_eval_quad_node_2_l, ser_3x_p1_surfx1_eval_quad_node_3_l}, - {ser_3x_p1_surfx1_eval_quad_node_0_r, ser_3x_p1_surfx1_eval_quad_node_1_r, ser_3x_p1_surfx1_eval_quad_node_2_r, ser_3x_p1_surfx1_eval_quad_node_3_r}, - {ser_3x_p1_surfx2_eval_quad_node_0_l, ser_3x_p1_surfx2_eval_quad_node_1_l, ser_3x_p1_surfx2_eval_quad_node_2_l, ser_3x_p1_surfx2_eval_quad_node_3_l}, - {ser_3x_p1_surfx2_eval_quad_node_0_r, ser_3x_p1_surfx2_eval_quad_node_1_r, ser_3x_p1_surfx2_eval_quad_node_2_r, ser_3x_p1_surfx2_eval_quad_node_3_r}, - {ser_3x_p1_surfx3_eval_quad_node_0_l, ser_3x_p1_surfx3_eval_quad_node_1_l, ser_3x_p1_surfx3_eval_quad_node_2_l, ser_3x_p1_surfx3_eval_quad_node_3_l}, - {ser_3x_p1_surfx3_eval_quad_node_0_r, ser_3x_p1_surfx3_eval_quad_node_1_r, ser_3x_p1_surfx3_eval_quad_node_2_r, ser_3x_p1_surfx3_eval_quad_node_3_r}, - } - }, + {.list = + {{ser_3x_p1_surfx1_eval_quad_node_0_l, ser_3x_p1_surfx1_eval_quad_node_1_l, + ser_3x_p1_surfx1_eval_quad_node_2_l, ser_3x_p1_surfx1_eval_quad_node_3_l}, + {ser_3x_p1_surfx1_eval_quad_node_0_r, ser_3x_p1_surfx1_eval_quad_node_1_r, + ser_3x_p1_surfx1_eval_quad_node_2_r, ser_3x_p1_surfx1_eval_quad_node_3_r}, + {ser_3x_p1_surfx2_eval_quad_node_0_l, ser_3x_p1_surfx2_eval_quad_node_1_l, + ser_3x_p1_surfx2_eval_quad_node_2_l, ser_3x_p1_surfx2_eval_quad_node_3_l}, + {ser_3x_p1_surfx2_eval_quad_node_0_r, ser_3x_p1_surfx2_eval_quad_node_1_r, + ser_3x_p1_surfx2_eval_quad_node_2_r, ser_3x_p1_surfx2_eval_quad_node_3_r}, + {ser_3x_p1_surfx3_eval_quad_node_0_l, ser_3x_p1_surfx3_eval_quad_node_1_l, + ser_3x_p1_surfx3_eval_quad_node_2_l, ser_3x_p1_surfx3_eval_quad_node_3_l}, + {ser_3x_p1_surfx3_eval_quad_node_0_r, ser_3x_p1_surfx3_eval_quad_node_1_r, + ser_3x_p1_surfx3_eval_quad_node_2_r, ser_3x_p1_surfx3_eval_quad_node_3_r}}} }; - struct bc_block_tensor { struct gkyl_range range; struct gkyl_range range_ext; @@ -58,19 +51,13 @@ struct bc_block_tensor { int cdim; int poly_order; int num_surf_nodes; - struct gkyl_array* tensor; + struct gkyl_array *tensor; modal_to_quad_kernel_list kernels_lo; modal_to_quad_kernel_list kernels_up; }; - -GKYL_CU_D -static modal_to_quad_kernel +GKYL_CU_D static modal_to_quad_kernel bc_block_tensor_choose_kernel(int cdim, int edge, int dir, int node_num) { - return ser_modal_to_quad_kernel_dim_list[cdim].list[2*dir + edge].kernels[node_num]; + return ser_modal_to_quad_kernel_dim_list[cdim].list[2 * dir + edge].kernels[node_num]; } - - - - diff --git a/gyrokinetic/zero/gkyl_bc_sheath_gyrokinetic.h b/gyrokinetic/zero/gkyl_bc_sheath_gyrokinetic.h index 0d613e4ab3..55e1c7f129 100644 --- a/gyrokinetic/zero/gkyl_bc_sheath_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_bc_sheath_gyrokinetic.h @@ -23,9 +23,11 @@ typedef struct gkyl_bc_sheath_gyrokinetic gkyl_bc_sheath_gyrokinetic; * @param use_gpu Boolean to indicate whether to use the GPU. * @return New updater pointer. */ -struct gkyl_bc_sheath_gyrokinetic* gkyl_bc_sheath_gyrokinetic_new(int dir, enum gkyl_edge_loc edge, - const struct gkyl_basis *basis, const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, - const struct gkyl_velocity_map *vel_map, int cdim, double q2Dm, bool use_gpu); +struct gkyl_bc_sheath_gyrokinetic *gkyl_bc_sheath_gyrokinetic_new( + int dir, enum gkyl_edge_loc edge, const struct gkyl_basis *basis, const struct gkyl_range *skin_r, + const struct gkyl_range *ghost_r, const struct gkyl_velocity_map *vel_map, int cdim, double q2Dm, + bool use_gpu +); /** * Apply the sheath BC with the bc_sheath_gyrokinetic object. @@ -36,8 +38,10 @@ struct gkyl_bc_sheath_gyrokinetic* gkyl_bc_sheath_gyrokinetic_new(int dir, enum * @param distf Distribution function array to apply BC to. * @param conf_r Configuration space range (to index phi). */ -void gkyl_bc_sheath_gyrokinetic_advance(const struct gkyl_bc_sheath_gyrokinetic *up, const struct gkyl_array *phi, - const struct gkyl_array *phi_wall, struct gkyl_array *distf, const struct gkyl_range *conf_r); +void gkyl_bc_sheath_gyrokinetic_advance( + const struct gkyl_bc_sheath_gyrokinetic *up, const struct gkyl_array *phi, + const struct gkyl_array *phi_wall, struct gkyl_array *distf, const struct gkyl_range *conf_r +); /** * Free memory associated with bc_sheath_gyrokinetic updater. diff --git a/gyrokinetic/zero/gkyl_bc_sheath_gyrokinetic_priv.h b/gyrokinetic/zero/gkyl_bc_sheath_gyrokinetic_priv.h index b76ed35d6e..5d94e38911 100644 --- a/gyrokinetic/zero/gkyl_bc_sheath_gyrokinetic_priv.h +++ b/gyrokinetic/zero/gkyl_bc_sheath_gyrokinetic_priv.h @@ -7,33 +7,34 @@ #include // Function pointer type for sheath reflection kernels. -typedef void (*sheath_reflectedf_t)(const double *vmap, const double q2Dm, - const double *phi, const double *phiWall, const double *f, double *fRefl); +typedef void (*sheath_reflectedf_t)( + const double *vmap, const double q2Dm, const double *phi, const double *phiWall, const double *f, + double *fRefl +); -typedef struct { sheath_reflectedf_t kernels[3]; } sheath_reflectedf_kern_list; // For use in kernel tables. -typedef struct { sheath_reflectedf_kern_list list[4]; } edged_sheath_reflectedf_kern_list; +typedef struct { + sheath_reflectedf_t kernels[3]; +} sheath_reflectedf_kern_list; // For use in kernel tables. +typedef struct { + sheath_reflectedf_kern_list list[4]; +} edged_sheath_reflectedf_kern_list; // Serendipity kernels. -GKYL_CU_D -static const edged_sheath_reflectedf_kern_list ser_sheath_reflect_list[] = { - { .list={ - { bc_sheath_gyrokinetic_reflectedf_lower_1x1v_ser_p1, NULL }, - { bc_sheath_gyrokinetic_reflectedf_lower_1x2v_ser_p1, NULL }, - { bc_sheath_gyrokinetic_reflectedf_lower_2x2v_ser_p1, NULL }, - { bc_sheath_gyrokinetic_reflectedf_lower_3x2v_ser_p1, NULL }, - }, - }, - { .list={ - { bc_sheath_gyrokinetic_reflectedf_upper_1x1v_ser_p1, NULL }, - { bc_sheath_gyrokinetic_reflectedf_upper_1x2v_ser_p1, NULL }, - { bc_sheath_gyrokinetic_reflectedf_upper_2x2v_ser_p1, NULL }, - { bc_sheath_gyrokinetic_reflectedf_upper_3x2v_ser_p1, NULL }, - }, - }, +GKYL_CU_D static const edged_sheath_reflectedf_kern_list ser_sheath_reflect_list[] = { + {.list = + {{bc_sheath_gyrokinetic_reflectedf_lower_1x1v_ser_p1, NULL}, + {bc_sheath_gyrokinetic_reflectedf_lower_1x2v_ser_p1, NULL}, + {bc_sheath_gyrokinetic_reflectedf_lower_2x2v_ser_p1, NULL}, + {bc_sheath_gyrokinetic_reflectedf_lower_3x2v_ser_p1, NULL}}}, + {.list = + {{bc_sheath_gyrokinetic_reflectedf_upper_1x1v_ser_p1, NULL}, + {bc_sheath_gyrokinetic_reflectedf_upper_1x2v_ser_p1, NULL}, + {bc_sheath_gyrokinetic_reflectedf_upper_2x2v_ser_p1, NULL}, + {bc_sheath_gyrokinetic_reflectedf_upper_3x2v_ser_p1, NULL}}} }; struct gkyl_bc_sheath_gyrokinetic_kernels { - sheath_reflectedf_t reflectedf; // reflectedf kernel. + sheath_reflectedf_t reflectedf; // reflectedf kernel. }; // Primary struct in this updater. @@ -44,36 +45,37 @@ struct gkyl_bc_sheath_gyrokinetic { const struct gkyl_basis *basis; // Phase-space basis. bool use_gpu; // Whether to run on GPU. double q2Dm; // charge-to-mass ratio times 2. - struct gkyl_bc_sheath_gyrokinetic_kernels *kernels; // reflectedf kernel. - struct gkyl_bc_sheath_gyrokinetic_kernels *kernels_cu; // device copy. + struct gkyl_bc_sheath_gyrokinetic_kernels *kernels; // reflectedf kernel. + struct gkyl_bc_sheath_gyrokinetic_kernels *kernels_cu; // device copy. const struct gkyl_range *skin_r, *ghost_r; // Skin and ghost ranges. const struct gkyl_velocity_map *vel_map; // Velocity space mapping. }; -void -gkyl_bc_gksheath_choose_reflectedf_kernel_cu(const struct gkyl_basis *basis, enum gkyl_edge_loc edge, struct gkyl_bc_sheath_gyrokinetic_kernels *kers); +void gkyl_bc_gksheath_choose_reflectedf_kernel_cu( + const struct gkyl_basis *basis, enum gkyl_edge_loc edge, + struct gkyl_bc_sheath_gyrokinetic_kernels *kers +); -GKYL_CU_D -static sheath_reflectedf_t +GKYL_CU_D static sheath_reflectedf_t bc_gksheath_choose_reflectedf_kernel(const struct gkyl_basis *basis, enum gkyl_edge_loc edge) { int dim = basis->ndim; enum gkyl_basis_type basis_type = basis->b_type; int poly_order = basis->poly_order; switch (basis_type) { - case GKYL_BASIS_MODAL_GKHYBRID: - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_sheath_reflect_list[edge].list[dim-2].kernels[poly_order-1]; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_GKHYBRID: + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_sheath_reflect_list[edge].list[dim - 2].kernels[poly_order - 1]; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static void -bc_gksheath_reflect(int dir, const struct gkyl_basis *basis, int cdim, double *out, const double *inp) +GKYL_CU_D static void bc_gksheath_reflect( + int dir, const struct gkyl_basis *basis, int cdim, double *out, const double *inp +) { basis->flip_odd_sign(dir, inp, out); basis->flip_odd_sign(cdim, out, out); // cdim is the vpar direction. @@ -90,7 +92,9 @@ bc_gksheath_reflect(int dir, const struct gkyl_basis *basis, int cdim, double *o * @param distf Distribution function array to apply BC to. * @param conf_r Configuration space range (to index phi). */ -void gkyl_bc_sheath_gyrokinetic_advance_cu(const struct gkyl_bc_sheath_gyrokinetic *up, const struct gkyl_array *phi, - const struct gkyl_array *phi_wall, struct gkyl_array *distf, const struct gkyl_range *conf_r); +void gkyl_bc_sheath_gyrokinetic_advance_cu( + const struct gkyl_bc_sheath_gyrokinetic *up, const struct gkyl_array *phi, + const struct gkyl_array *phi_wall, struct gkyl_array *distf, const struct gkyl_range *conf_r +); #endif diff --git a/gyrokinetic/zero/gkyl_bc_twistshift.h b/gyrokinetic/zero/gkyl_bc_twistshift.h index cb6ccec89d..333879f1b2 100644 --- a/gyrokinetic/zero/gkyl_bc_twistshift.h +++ b/gyrokinetic/zero/gkyl_bc_twistshift.h @@ -34,8 +34,8 @@ struct gkyl_bc_twistshift_inp { * @param inp bc_twistshift_inp struct containing the inputs to the updater. * @return New updater pointer. */ -struct gkyl_bc_twistshift* gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp); - +struct gkyl_bc_twistshift *gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshift_inp *inp); + /** * Create a new updater to apply twist-shift BCs, passing each argument separately. * @@ -55,10 +55,12 @@ struct gkyl_bc_twistshift* gkyl_bc_twistshift_inew(const struct gkyl_bc_twistshi * @param use_gpu Whether to apply the BC using the GPU. * @return New updater pointer. */ -struct gkyl_bc_twistshift* gkyl_bc_twistshift_new(int bc_dir, int shift_dir, int shear_dir, - enum gkyl_edge_loc edge, int cdim, const struct gkyl_range *bcdir_ext_update_r, const int *num_ghost, - const struct gkyl_basis *basis, const struct gkyl_rect_grid *grid, evalf_t shift_func, void *shift_func_ctx, - struct gkyl_array *shift_dg, int shift_poly_order, bool use_gpu); +struct gkyl_bc_twistshift *gkyl_bc_twistshift_new( + int bc_dir, int shift_dir, int shear_dir, enum gkyl_edge_loc edge, int cdim, + const struct gkyl_range *bcdir_ext_update_r, const int *num_ghost, const struct gkyl_basis *basis, + const struct gkyl_rect_grid *grid, evalf_t shift_func, void *shift_func_ctx, + struct gkyl_array *shift_dg, int shift_poly_order, bool use_gpu +); /** * Apply the twist-shift. It assumes that periodicity along bc_dir has been @@ -68,7 +70,9 @@ struct gkyl_bc_twistshift* gkyl_bc_twistshift_new(int bc_dir, int shift_dir, int * @param fdo Donor field. * @param ftar Target field. */ -void gkyl_bc_twistshift_advance(struct gkyl_bc_twistshift *up, struct gkyl_array *fdo, struct gkyl_array *ftar); +void gkyl_bc_twistshift_advance( + struct gkyl_bc_twistshift *up, struct gkyl_array *fdo, struct gkyl_array *ftar +); /** * Return pointers to the discretized shift, its range, and grid and basis. @@ -81,8 +85,10 @@ void gkyl_bc_twistshift_advance(struct gkyl_bc_twistshift *up, struct gkyl_array * @param shift_b Basis shift_dg coefficients are expanded on. * @return Discretized shift. */ -struct gkyl_array* gkyl_bc_twistshift_get_shift_objects(struct gkyl_bc_twistshift *up, - struct gkyl_rect_grid *shear_grid, struct gkyl_range *shear_r, struct gkyl_basis *shift_b); +struct gkyl_array *gkyl_bc_twistshift_get_shift_objects( + struct gkyl_bc_twistshift *up, struct gkyl_rect_grid *shear_grid, struct gkyl_range *shear_r, + struct gkyl_basis *shift_b +); /** * Free memory associated with bc_twistshift updater. diff --git a/gyrokinetic/zero/gkyl_bc_twistshift_priv.h b/gyrokinetic/zero/gkyl_bc_twistshift_priv.h index f66ffe186d..240773972b 100644 --- a/gyrokinetic/zero/gkyl_bc_twistshift_priv.h +++ b/gyrokinetic/zero/gkyl_bc_twistshift_priv.h @@ -11,76 +11,84 @@ #include // memcpy // Function pointer type for twistshift kernels. -typedef void (*twistshift_xlimdg_t)(double sFac, const double *xLimLo, - const double *xLimUp, double yLimLo, double yLimUp, - double dyDo, double yOff, const double *ySh, struct gkyl_mat *tsmat); - -typedef void (*twistshift_ylimdg_t)(double sFac, double xLimLo, - double xLimUp, const double *yLimLo, const double *yLimUp, - double dyDo, double yOff, const double *ySh, struct gkyl_mat *tsmat); - -typedef void (*twistshift_fullcell_t)(double dyDo, double yOff, - const double *ySh, struct gkyl_mat *tsmat); - -typedef struct { twistshift_xlimdg_t kernels[3]; } twistshift_xlimdg_kern_list; // For use in kernel tables. -typedef struct { twistshift_ylimdg_t kernels[3]; } twistshift_ylimdg_kern_list; // For use in kernel tables. -typedef struct { twistshift_fullcell_t kernels[3]; } twistshift_fullcell_kern_list; // For use in kernel tables. +typedef void (*twistshift_xlimdg_t)( + double sFac, const double *xLimLo, const double *xLimUp, double yLimLo, double yLimUp, + double dyDo, double yOff, const double *ySh, struct gkyl_mat *tsmat +); + +typedef void (*twistshift_ylimdg_t)( + double sFac, double xLimLo, double xLimUp, const double *yLimLo, const double *yLimUp, + double dyDo, double yOff, const double *ySh, struct gkyl_mat *tsmat +); + +typedef void (*twistshift_fullcell_t)( + double dyDo, double yOff, const double *ySh, struct gkyl_mat *tsmat +); + +typedef struct { + twistshift_xlimdg_t kernels[3]; +} twistshift_xlimdg_kern_list; // For use in kernel tables. +typedef struct { + twistshift_ylimdg_t kernels[3]; +} twistshift_ylimdg_kern_list; // For use in kernel tables. +typedef struct { + twistshift_fullcell_t kernels[3]; +} twistshift_fullcell_kern_list; // For use in kernel tables. // Serendipity kernels. // p=1 representation of the shift: static const twistshift_xlimdg_kern_list ser_twistshift_xlimdg_list_0v_yShp1[] = { - {NULL, twistshift_xlimdg_2x_ser_p1_yshift_p1, NULL,}, - {NULL, twistshift_xlimdg_3x_ser_p1_yshift_p1, NULL,}, + {NULL, twistshift_xlimdg_2x_ser_p1_yshift_p1, NULL}, + {NULL, twistshift_xlimdg_3x_ser_p1_yshift_p1, NULL} }; static const twistshift_ylimdg_kern_list ser_twistshift_ylimdg_list_0v_yShp1[] = { - {NULL, twistshift_ylimdg_2x_ser_p1_yshift_p1, NULL,}, - {NULL, twistshift_ylimdg_3x_ser_p1_yshift_p1, NULL,}, + {NULL, twistshift_ylimdg_2x_ser_p1_yshift_p1, NULL}, + {NULL, twistshift_ylimdg_3x_ser_p1_yshift_p1, NULL} }; static const twistshift_fullcell_kern_list ser_twistshift_fullcell_list_0v_yShp1[] = { - {NULL, twistshift_fullcell_2x_ser_p1_yshift_p1, NULL,}, - {NULL, twistshift_fullcell_3x_ser_p1_yshift_p1, NULL,}, + {NULL, twistshift_fullcell_2x_ser_p1_yshift_p1, NULL}, + {NULL, twistshift_fullcell_3x_ser_p1_yshift_p1, NULL} }; static const twistshift_xlimdg_kern_list ser_twistshift_xlimdg_list_2v_yShp1[] = { - {NULL, NULL, NULL,}, - {NULL, twistshift_xlimdg_3x2v_ser_p1_yshift_p1, NULL,}, + {NULL, NULL, NULL}, + {NULL, twistshift_xlimdg_3x2v_ser_p1_yshift_p1, NULL} }; static const twistshift_ylimdg_kern_list ser_twistshift_ylimdg_list_2v_yShp1[] = { - {NULL, NULL, NULL,}, - {NULL, twistshift_ylimdg_3x2v_ser_p1_yshift_p1, NULL,}, + {NULL, NULL, NULL}, + {NULL, twistshift_ylimdg_3x2v_ser_p1_yshift_p1, NULL} }; static const twistshift_fullcell_kern_list ser_twistshift_fullcell_list_2v_yShp1[] = { - {NULL, NULL, NULL,}, - {NULL, twistshift_fullcell_3x2v_ser_p1_yshift_p1, NULL,}, + {NULL, NULL, NULL}, + {NULL, twistshift_fullcell_3x2v_ser_p1_yshift_p1, NULL} }; // p=2 representation of the shift: static const twistshift_xlimdg_kern_list ser_twistshift_xlimdg_list_0v_yShp2[] = { - {NULL, twistshift_xlimdg_2x_ser_p1_yshift_p2, NULL,}, - {NULL, twistshift_xlimdg_3x_ser_p1_yshift_p2, NULL,}, + {NULL, twistshift_xlimdg_2x_ser_p1_yshift_p2, NULL}, + {NULL, twistshift_xlimdg_3x_ser_p1_yshift_p2, NULL} }; static const twistshift_ylimdg_kern_list ser_twistshift_ylimdg_list_0v_yShp2[] = { - {NULL, twistshift_ylimdg_2x_ser_p1_yshift_p2, NULL,}, - {NULL, twistshift_ylimdg_3x_ser_p1_yshift_p2, NULL,}, + {NULL, twistshift_ylimdg_2x_ser_p1_yshift_p2, NULL}, + {NULL, twistshift_ylimdg_3x_ser_p1_yshift_p2, NULL} }; static const twistshift_fullcell_kern_list ser_twistshift_fullcell_list_0v_yShp2[] = { - {NULL, twistshift_fullcell_2x_ser_p1_yshift_p2, NULL,}, - {NULL, twistshift_fullcell_3x_ser_p1_yshift_p2, NULL,}, + {NULL, twistshift_fullcell_2x_ser_p1_yshift_p2, NULL}, + {NULL, twistshift_fullcell_3x_ser_p1_yshift_p2, NULL} }; static const twistshift_xlimdg_kern_list ser_twistshift_xlimdg_list_2v_yShp2[] = { - {NULL, NULL, NULL,}, - {NULL, NULL, NULL,}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL} }; static const twistshift_ylimdg_kern_list ser_twistshift_ylimdg_list_2v_yShp2[] = { - {NULL, NULL, NULL,}, - {NULL, NULL, NULL,}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL} }; static const twistshift_fullcell_kern_list ser_twistshift_fullcell_list_2v_yShp2[] = { - {NULL, NULL, NULL,}, - {NULL, NULL, NULL,}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL} }; - struct gkyl_bc_twistshift_kernels { twistshift_xlimdg_t xlimdg; twistshift_ylimdg_t ylimdg; @@ -125,9 +133,9 @@ struct gkyl_bc_twistshift { int *num_do; // Number of donors at each cell in shear_dir; int *shift_dir_idx_do; // Indices of donor cells, in the direction of the - // shift, for each cell in the TS grid. + // shift, for each cell in the TS grid. - struct gkyl_bc_twistshift_kernels *kernels; // kernels for sub-cell integrals. + struct gkyl_bc_twistshift_kernels *kernels; // kernels for sub-cell integrals. // Projection object used in constructing the matrices. struct gkyl_eval_on_nodes *ev_on_nod1d; @@ -139,16 +147,16 @@ struct gkyl_bc_twistshift { struct gkyl_nmat *mm_contr; // Contribution resulting from a mat-mat mult. long *num_numcol_fidx_do; // 1D indexer, from a index identitying the num-numcol - // plane (in the num-numcol-num_basis space), to a - // linear index into the donor distribution function f. + // plane (in the num-numcol-num_basis space), to a + // linear index into the donor distribution function f. long *num_numcol_fidx_tar; // 1D indexer, from a index identitying the num-numcol - // plane (in the num-numcol-num_basis space), to a - // linear index into the target distribution function f. + // plane (in the num-numcol-num_basis space), to a + // linear index into the target distribution function f. int *num_do_cum; // Cumulative number of donors up to a give cell in shear_dir; struct gkyl_range permutted_ghost_r; // Ghost range to populate in the target - // field, with some dimensions permutted. + // field, with some dimensions permutted. struct gkyl_range ghost_r; // Ghost range this BC fills. }; @@ -161,5 +169,7 @@ struct gkyl_bc_twistshift { * @param fdo Donor field. * @param ftar Target field. */ -void gkyl_bc_twistshift_advance_cu(struct gkyl_bc_twistshift *up, struct gkyl_array *fdo, struct gkyl_array *ftar); +void gkyl_bc_twistshift_advance_cu( + struct gkyl_bc_twistshift *up, struct gkyl_array *fdo, struct gkyl_array *ftar +); #endif diff --git a/gyrokinetic/zero/gkyl_boundary_flux.h b/gyrokinetic/zero/gkyl_boundary_flux.h index f8a6414d4b..70a1691f06 100644 --- a/gyrokinetic/zero/gkyl_boundary_flux.h +++ b/gyrokinetic/zero/gkyl_boundary_flux.h @@ -23,9 +23,11 @@ typedef struct gkyl_boundary_flux gkyl_boundary_flux; * @param use_gpu Boolean to indicate whether to use the GPU. * @return New updater pointer. */ -struct gkyl_boundary_flux* gkyl_boundary_flux_new(int dir, enum gkyl_edge_loc edge, - const struct gkyl_rect_grid *grid, const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, - int num_equations, const struct gkyl_dg_eqn **eqns, bool use_gpu); +struct gkyl_boundary_flux *gkyl_boundary_flux_new( + int dir, enum gkyl_edge_loc edge, const struct gkyl_rect_grid *grid, + const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, int num_equations, + const struct gkyl_dg_eqn **eqns, bool use_gpu +); /** * Compute the boundary flux. @@ -34,12 +36,13 @@ struct gkyl_boundary_flux* gkyl_boundary_flux_new(int dir, enum gkyl_edge_loc ed * @param fIn Input distribution function. * @param rhs Output flux. */ -void gkyl_boundary_flux_advance(gkyl_boundary_flux *up, - const struct gkyl_array *fIn, struct gkyl_array *fluxOut); +void gkyl_boundary_flux_advance( + gkyl_boundary_flux *up, const struct gkyl_array *fIn, struct gkyl_array *fluxOut +); /** * Free memory associated with this updater. * * @param up Updater to delete. */ -void gkyl_boundary_flux_release(gkyl_boundary_flux* up); +void gkyl_boundary_flux_release(gkyl_boundary_flux *up); diff --git a/gyrokinetic/zero/gkyl_boundary_flux_priv.h b/gyrokinetic/zero/gkyl_boundary_flux_priv.h index 099ebe5c48..8489112df5 100644 --- a/gyrokinetic/zero/gkyl_boundary_flux_priv.h +++ b/gyrokinetic/zero/gkyl_boundary_flux_priv.h @@ -16,7 +16,6 @@ struct gkyl_boundary_flux { struct gkyl_boundary_flux *on_dev; // pointer to itself or device data }; - #ifdef GKYL_HAVE_CUDA /** * Create new boundary_flux updater on the GPU. @@ -30,10 +29,11 @@ struct gkyl_boundary_flux { * @param eqns Equation objects. * @return New updater pointer. */ -gkyl_boundary_flux* -gkyl_boundary_flux_cu_dev_new(int dir, enum gkyl_edge_loc edge, - const struct gkyl_rect_grid *grid, const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, - int num_eqns, const struct gkyl_dg_eqn **eqns); +gkyl_boundary_flux *gkyl_boundary_flux_cu_dev_new( + int dir, enum gkyl_edge_loc edge, const struct gkyl_rect_grid *grid, + const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, int num_eqns, + const struct gkyl_dg_eqn **eqns +); /** * Compute the boundary flux on the GPU. @@ -42,6 +42,7 @@ gkyl_boundary_flux_cu_dev_new(int dir, enum gkyl_edge_loc edge, * @param fIn Input distribution function. * @param fluxOut Output flux. */ -void gkyl_boundary_flux_advance_cu(gkyl_boundary_flux *up, - const struct gkyl_array *fIn, struct gkyl_array *fluxOut); +void gkyl_boundary_flux_advance_cu( + gkyl_boundary_flux *up, const struct gkyl_array *fIn, struct gkyl_array *fluxOut +); #endif diff --git a/gyrokinetic/zero/gkyl_calc_bmag.h b/gyrokinetic/zero/gkyl_calc_bmag.h index 15dc953f9f..a0bc529550 100644 --- a/gyrokinetic/zero/gkyl_calc_bmag.h +++ b/gyrokinetic/zero/gkyl_calc_bmag.h @@ -10,17 +10,17 @@ typedef struct gkyl_calc_bmag gkyl_calc_bmag; // Context object for computing bmag -struct gkyl_bmag_ctx{ - const struct gkyl_rect_grid* grid; // Physical RZ grid - const struct gkyl_rect_grid* cgrid; // Computational grid - const struct gkyl_range* range; // Physical RZ range - const struct gkyl_range* crange; // Computational range - const struct gkyl_range* crange_global; // Global computational range - const struct gkyl_basis* basis; // Physical RZ basis - const struct gkyl_basis* cbasis; // Computational basis - const struct gkyl_array* bmagdg; // DG representation of bmag in physical RZ coordinates - const struct gkyl_array* bmag; // DG representation of bmag in computational coordinates - const struct gkyl_array* mapc2p; // DG representation of mapc2p +struct gkyl_bmag_ctx { + const struct gkyl_rect_grid *grid; // Physical RZ grid + const struct gkyl_rect_grid *cgrid; // Computational grid + const struct gkyl_range *range; // Physical RZ range + const struct gkyl_range *crange; // Computational range + const struct gkyl_range *crange_global; // Global computational range + const struct gkyl_basis *basis; // Physical RZ basis + const struct gkyl_basis *cbasis; // Computational basis + const struct gkyl_array *bmagdg; // DG representation of bmag in physical RZ coordinates + const struct gkyl_array *bmag; // DG representation of bmag in computational coordinates + const struct gkyl_array *mapc2p; // DG representation of mapc2p }; /** @@ -33,9 +33,10 @@ struct gkyl_bmag_ctx{ * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -gkyl_calc_bmag* -gkyl_calc_bmag_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_rect_grid *cgrid, const struct gkyl_rect_grid *pgrid, bool use_gpu); +gkyl_calc_bmag *gkyl_calc_bmag_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_rect_grid *cgrid, const struct gkyl_rect_grid *pgrid, bool use_gpu +); /** * Computes the magnitude of the magnetic field using a global field aligned representation. @@ -47,7 +48,6 @@ gkyl_calc_bmag_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pba */ void gkyl_calc_bmag_global(double t, const double *xn, double *fout, void *ctx); - /** * Advance calc_bmag (Convert B to computational grid from RZ grid) * @@ -61,14 +61,16 @@ void gkyl_calc_bmag_global(double t, const double *xn, double *fout, void *ctx); * @param bool use_quad flag to indicate whether to use quadrature points or not */ -void gkyl_calc_bmag_advance(const gkyl_calc_bmag *up, const struct gkyl_range *crange, - const struct gkyl_range *crange_ext, const struct gkyl_range *crange_global, - const struct gkyl_range *prange, const struct gkyl_range *prange_ext, - const struct gkyl_array *bmagrz, struct gkyl_array* bmag_compdg, struct gkyl_array* mapc2p, bool use_quad); +void gkyl_calc_bmag_advance( + const gkyl_calc_bmag *up, const struct gkyl_range *crange, const struct gkyl_range *crange_ext, + const struct gkyl_range *crange_global, const struct gkyl_range *prange, + const struct gkyl_range *prange_ext, const struct gkyl_array *bmagrz, + struct gkyl_array *bmag_compdg, struct gkyl_array *mapc2p, bool use_quad +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_calc_bmag_release(gkyl_calc_bmag* up); +void gkyl_calc_bmag_release(gkyl_calc_bmag *up); diff --git a/gyrokinetic/zero/gkyl_calc_bmag_priv.h b/gyrokinetic/zero/gkyl_calc_bmag_priv.h index bb3e95aa8b..b9b4cb272f 100644 --- a/gyrokinetic/zero/gkyl_calc_bmag_priv.h +++ b/gyrokinetic/zero/gkyl_calc_bmag_priv.h @@ -3,11 +3,10 @@ #include struct gkyl_calc_bmag { - const struct gkyl_basis* cbasis; //comp basis - const struct gkyl_basis* pbasis; //physical RZ basis - const struct gkyl_rect_grid* cgrid; // computational grid - const struct gkyl_rect_grid* pgrid; // physical RZ grid + const struct gkyl_basis *cbasis; //comp basis + const struct gkyl_basis *pbasis; //physical RZ basis + const struct gkyl_rect_grid *cgrid; // computational grid + const struct gkyl_rect_grid *pgrid; // physical RZ grid bool use_gpu; - struct gkyl_bmag_ctx* bmag_ctx; + struct gkyl_bmag_ctx *bmag_ctx; }; - diff --git a/gyrokinetic/zero/gkyl_calc_derived_geo.h b/gyrokinetic/zero/gkyl_calc_derived_geo.h index 3a0286e647..ab24143f03 100644 --- a/gyrokinetic/zero/gkyl_calc_derived_geo.h +++ b/gyrokinetic/zero/gkyl_calc_derived_geo.h @@ -17,8 +17,9 @@ typedef struct gkyl_calc_derived_geo gkyl_calc_derived_geo; * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -gkyl_calc_derived_geo* gkyl_calc_derived_geo_new(const struct gkyl_basis *cbasis, - const struct gkyl_rect_grid *grid, int node_type, bool use_gpu); +gkyl_calc_derived_geo *gkyl_calc_derived_geo_new( + const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, int node_type, bool use_gpu +); /** * Advance calc_derived_geo (compute the derived_geo coefficients) under the constraint @@ -42,15 +43,18 @@ gkyl_calc_derived_geo* gkyl_calc_derived_geo_new(const struct gkyl_basis *cbasis * @param eps2Fld DG representation of eps2 = Jg^33 - J/g_33 */ -void gkyl_calc_derived_geo_advance(const gkyl_calc_derived_geo *up, const struct gkyl_range *crange, - struct gkyl_array *gFld, struct gkyl_array *bmagFld, struct gkyl_array *jFld, struct gkyl_array *jinvFld, - struct gkyl_array *grFld, struct gkyl_array *biFld, struct gkyl_array *cmagFld, struct gkyl_array *jtotFld, - struct gkyl_array *jtotinvFld, struct gkyl_array *gxxJFld, struct gkyl_array *gxyJFld, - struct gkyl_array *gyyJFld, struct gkyl_array *gxzJFld, struct gkyl_array *eps2Fld); +void gkyl_calc_derived_geo_advance( + const gkyl_calc_derived_geo *up, const struct gkyl_range *crange, struct gkyl_array *gFld, + struct gkyl_array *bmagFld, struct gkyl_array *jFld, struct gkyl_array *jinvFld, + struct gkyl_array *grFld, struct gkyl_array *biFld, struct gkyl_array *cmagFld, + struct gkyl_array *jtotFld, struct gkyl_array *jtotinvFld, struct gkyl_array *gxxJFld, + struct gkyl_array *gxyJFld, struct gkyl_array *gyyJFld, struct gkyl_array *gxzJFld, + struct gkyl_array *eps2Fld +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_calc_derived_geo_release(gkyl_calc_derived_geo* up); +void gkyl_calc_derived_geo_release(gkyl_calc_derived_geo *up); diff --git a/gyrokinetic/zero/gkyl_calc_derived_geo_priv.h b/gyrokinetic/zero/gkyl_calc_derived_geo_priv.h index 968b33200d..2befca35d9 100644 --- a/gyrokinetic/zero/gkyl_calc_derived_geo_priv.h +++ b/gyrokinetic/zero/gkyl_calc_derived_geo_priv.h @@ -3,54 +3,52 @@ #include #include -typedef void (*derived_geo_kernel)(const double *gij, const double *bmag, double *J, double *Jinv, double *grij, double *bi, double *cmag, double *Jtot, double *Jtotinv, double *gxxJ, double *gxyJ, double *gyyJ, double *gxzJ, double *eps2); - -typedef struct { derived_geo_kernel kernels[3]; } derived_geo_kernel_list; // For use in kernel tables. -typedef struct { derived_geo_kernel_list list[4]; } derived_geo_node_list; // For use in kernel tables. - -GKYL_CU_DH -static const derived_geo_node_list ser_derived_geo_kernel_list[] = { - { .list = { - { NULL, NULL, NULL }, // 0x No 0D basis functions - { NULL, NULL, NULL}, // 1x Not tested yet - { NULL, NULL, NULL}, // 2x Not tested yet - { NULL, derived_geo_3x_Ser_p1, derived_geo_3x_Ser_p2} - } - }, - { .list = { - { NULL, NULL, NULL }, // 0x No 0D basis functions - { NULL, NULL, NULL}, // 1x Not tested yet - { NULL, NULL, NULL}, // 2x Not tested yet - { NULL, derived_geo_quad_3x_Ser_p1, NULL} - } - }, +typedef void (*derived_geo_kernel)( + const double *gij, const double *bmag, double *J, double *Jinv, double *grij, double *bi, + double *cmag, double *Jtot, double *Jtotinv, double *gxxJ, double *gxyJ, double *gyyJ, + double *gxzJ, double *eps2 +); + +typedef struct { + derived_geo_kernel kernels[3]; +} derived_geo_kernel_list; // For use in kernel tables. +typedef struct { + derived_geo_kernel_list list[4]; +} derived_geo_node_list; // For use in kernel tables. + +GKYL_CU_DH static const derived_geo_node_list ser_derived_geo_kernel_list[] = { + {.list = + {{NULL, NULL, NULL}, // 0x No 0D basis functions + {NULL, NULL, NULL}, // 1x Not tested yet + {NULL, NULL, NULL}, // 2x Not tested yet + {NULL, derived_geo_3x_Ser_p1, derived_geo_3x_Ser_p2}}}, + {.list = + {{NULL, NULL, NULL}, // 0x No 0D basis functions + {NULL, NULL, NULL}, // 1x Not tested yet + {NULL, NULL, NULL}, // 2x Not tested yet + {NULL, derived_geo_quad_3x_Ser_p1, NULL}}} }; -struct gkyl_calc_derived_geo{ +struct gkyl_calc_derived_geo { unsigned cdim; // Configuration-space dimension. unsigned cnum_basis; // Number of conf-space basis functions. unsigned poly_order; // Polynomial order of the basis. struct gkyl_basis cbasis; // configuration space basis - const struct gkyl_rect_grid* grid; + const struct gkyl_rect_grid *grid; bool use_gpu; derived_geo_kernel kernel; }; -GKYL_CU_DH -static derived_geo_kernel +GKYL_CU_DH static derived_geo_kernel derived_geo_choose_kernel(int dim, int basis_type, int node_type, int poly_order) { switch (basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_derived_geo_kernel_list[node_type].list[dim].kernels[poly_order]; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_derived_geo_kernel_list[node_type].list[dim].kernels[poly_order]; + default: + assert(false); + break; } return 0; } - - - - diff --git a/gyrokinetic/zero/gkyl_calc_metric.h b/gyrokinetic/zero/gkyl_calc_metric.h index 28cb5c9a37..5d972ede41 100644 --- a/gyrokinetic/zero/gkyl_calc_metric.h +++ b/gyrokinetic/zero/gkyl_calc_metric.h @@ -20,10 +20,12 @@ typedef struct gkyl_calc_metric gkyl_calc_metric; * @param use_gpu Boolean indicating whether to use the GPU. * @return New updater pointer. */ -gkyl_calc_metric* gkyl_calc_metric_new(const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, - const struct gkyl_range *global, const struct gkyl_range *global_ext, - const struct gkyl_range *local, const struct gkyl_range *local_ext, - bool exit_at_checks, bool use_gpu); +gkyl_calc_metric *gkyl_calc_metric_new( + const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, + const struct gkyl_range *global, const struct gkyl_range *global_ext, + const struct gkyl_range *local, const struct gkyl_range *local_ext, bool exit_at_checks, + bool use_gpu +); /** * Use finite differences to calculate metric coefficients and tangent vectors at nodes @@ -50,10 +52,11 @@ gkyl_calc_metric* gkyl_calc_metric_new(const struct gkyl_basis *cbasis, const st * @param normFld output field where dual vector modal coefficients will be placed * @param update range. Modal range over which metric coefficients and tangent vectors will be calculated */ -void gkyl_calc_metric_advance(gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, - double *dzc, struct gkyl_array *gFld, struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, - struct gkyl_array *dualmagFld, struct gkyl_array* normFld, const struct gkyl_range *update_range); - +void gkyl_calc_metric_advance( + gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, double *dzc, + struct gkyl_array *gFld, struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, + struct gkyl_array *dualmagFld, struct gkyl_array *normFld, const struct gkyl_range *update_range +); /** * Use finite differences to calculate metric coefficients and tangent vectors at @@ -82,7 +85,6 @@ void gkyl_calc_metric_advance_interior(gkyl_calc_metric *up, struct gk_geometry */ void gkyl_calc_metric_advance_surface(gkyl_calc_metric *up, int dir, struct gk_geometry *gk_geom); - /** * Use finite differences to calculate metric coefficients and jacobian at nodes * Using the explicit in Eq. 66-73 of the GK coordinates document @@ -103,10 +105,13 @@ void gkyl_calc_metric_advance_surface(gkyl_calc_metric *up, int dir, struct gk_g * @param bcartFld output field where cartesian compnents of b modal coefficients will be placed * @param update range. Modal range over which metric coefficients and tangent vectors will be calculated */ -void gkyl_calc_metric_advance_rz(gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, - struct gkyl_array *ddtheta_nodal, struct gkyl_array *bmag_nodal, double *dzc, struct gkyl_array *gFld, - struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, struct gkyl_array *dualmagFld, struct gkyl_array *normFld, - struct gkyl_array *jFld, struct gkyl_array* bcartFld, const struct gkyl_range *update_range); +void gkyl_calc_metric_advance_rz( + gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, + struct gkyl_array *ddtheta_nodal, struct gkyl_array *bmag_nodal, double *dzc, + struct gkyl_array *gFld, struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, + struct gkyl_array *dualmagFld, struct gkyl_array *normFld, struct gkyl_array *jFld, + struct gkyl_array *bcartFld, const struct gkyl_range *update_range +); /** * Use finite differences to calculate metric coefficients and jacobian at @@ -150,7 +155,7 @@ void gkyl_calc_metric_advance_rz_interior(gkyl_calc_metric *up, struct gk_geomet * @param jtotinvFld_nodal output field where jtotinv nodal valued will be placed * @param update range. Modal range over which metric coefficients and tangent vectors will be calculated */ -void gkyl_calc_metric_advance_rz_surface( gkyl_calc_metric *up, int dir, struct gk_geometry* gk_geom); +void gkyl_calc_metric_advance_rz_surface(gkyl_calc_metric *up, int dir, struct gk_geometry *gk_geom); /** * Use finite differences to calculate metric coefficients and jacobian at interior nodes @@ -167,7 +172,7 @@ void gkyl_calc_metric_advance_rz_surface( gkyl_calc_metric *up, int dir, struct * @param grFld output field where contravariant metric modal coefficients will be placed * @param update range. Modal range over which metric coefficients and tangent vectors will be calculated */ -void gkyl_calc_metric_advance_rz_neut_interior( gkyl_calc_metric *up, struct gk_geometry* gk_geom); +void gkyl_calc_metric_advance_rz_neut_interior(gkyl_calc_metric *up, struct gk_geometry *gk_geom); /** * Use finite differences to calculate metric coefficients and jacobian at nodes @@ -189,10 +194,13 @@ void gkyl_calc_metric_advance_rz_neut_interior( gkyl_calc_metric *up, struct gk_ * @param bcartFld output field where cartesian compnents of b modal coefficients will be placed * @param update range. Modal range over which metric coefficients and tangent vectors will be calculated */ -void gkyl_calc_metric_advance_mirror(gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, - struct gkyl_array *ddtheta_nodal, struct gkyl_array *bmag_nodal, double *dzc, struct gkyl_array *gFld, - struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, struct gkyl_array *dualmagFld, struct gkyl_array *normFld, - struct gkyl_array *jFld, struct gkyl_array* bcartFld, const struct gkyl_range *update_range); +void gkyl_calc_metric_advance_mirror( + gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, + struct gkyl_array *ddtheta_nodal, struct gkyl_array *bmag_nodal, double *dzc, + struct gkyl_array *gFld, struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, + struct gkyl_array *dualmagFld, struct gkyl_array *normFld, struct gkyl_array *jFld, + struct gkyl_array *bcartFld, const struct gkyl_range *update_range +); /** * Use finite differences to calculate metric coefficients and jacobian at @@ -216,7 +224,13 @@ void gkyl_calc_metric_advance_mirror(gkyl_calc_metric *up, struct gkyl_range *nr * @param bcartFld output field where cartesian compnents of b modal coefficients will be placed * @param update range. Modal range over which metric coefficients and tangent vectors will be calculated */ -void gkyl_calc_metric_advance_mirror_interior(gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, struct gkyl_array *ddtheta_nodal, struct gkyl_array *bmag_nodal, double *dzc, struct gkyl_array *gFld, struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, struct gkyl_array *dualmagFld, struct gkyl_array *normFld, struct gkyl_array *jFld, struct gkyl_array* bcartFld, const struct gkyl_range *update_range); +void gkyl_calc_metric_advance_mirror_interior( + gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, + struct gkyl_array *ddtheta_nodal, struct gkyl_array *bmag_nodal, double *dzc, + struct gkyl_array *gFld, struct gkyl_array *tanvecFld, struct gkyl_array *dualFld, + struct gkyl_array *dualmagFld, struct gkyl_array *normFld, struct gkyl_array *jFld, + struct gkyl_array *bcartFld, const struct gkyl_range *update_range +); /** * Use finite differences to calculate metric coefficients and jacobian at @@ -239,14 +253,11 @@ void gkyl_calc_metric_advance_mirror_interior(gkyl_calc_metric *up, struct gkyl_ * @param update range. Modal range over which metric coefficients and tangent vectors will be calculated */ void gkyl_calc_metric_advance_mirror_surface( - gkyl_calc_metric *up, int dir, struct gkyl_range *nrange, - struct gkyl_array *mc2p_nodal_fd, struct gkyl_array *ddtheta_nodal, - struct gkyl_array *bmag_nodal, double *dzc, - struct gkyl_array *jFld_nodal, - struct gkyl_array *biFld_nodal, - struct gkyl_array *cmagFld_nodal, - struct gkyl_array *jtotinvFld_nodal, - const struct gkyl_range *update_range); + gkyl_calc_metric *up, int dir, struct gkyl_range *nrange, struct gkyl_array *mc2p_nodal_fd, + struct gkyl_array *ddtheta_nodal, struct gkyl_array *bmag_nodal, double *dzc, + struct gkyl_array *jFld_nodal, struct gkyl_array *biFld_nodal, struct gkyl_array *cmagFld_nodal, + struct gkyl_array *jtotinvFld_nodal, const struct gkyl_range *update_range +); /** * Calculate cartesian components of bhat @@ -256,12 +267,14 @@ void gkyl_calc_metric_advance_mirror_surface( * @param dualFld input field containing dual vectors DG expansion * @param bcartFld output field containing DG expansion of cartesian components of bhat */ -void gkyl_calc_metric_advance_bcart(gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *biFld, - struct gkyl_array *dualFld, struct gkyl_array *bcartFld, const struct gkyl_range *update_range); +void gkyl_calc_metric_advance_bcart( + gkyl_calc_metric *up, struct gkyl_range *nrange, struct gkyl_array *biFld, + struct gkyl_array *dualFld, struct gkyl_array *bcartFld, const struct gkyl_range *update_range +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_calc_metric_release(gkyl_calc_metric* up); +void gkyl_calc_metric_release(gkyl_calc_metric *up); diff --git a/gyrokinetic/zero/gkyl_calc_metric_mirror.h b/gyrokinetic/zero/gkyl_calc_metric_mirror.h index 944e15b0c6..51f2e269c5 100644 --- a/gyrokinetic/zero/gkyl_calc_metric_mirror.h +++ b/gyrokinetic/zero/gkyl_calc_metric_mirror.h @@ -19,9 +19,10 @@ typedef struct gkyl_calc_metric_mirror gkyl_calc_metric_mirror; * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -gkyl_calc_metric_mirror* gkyl_calc_metric_mirror_new(const struct gkyl_basis *cbasis, - const struct gkyl_rect_grid *grid, const struct gkyl_range *local, - const struct gkyl_range *local_ext, bool use_gpu); +gkyl_calc_metric_mirror *gkyl_calc_metric_mirror_new( + const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, + const struct gkyl_range *local, const struct gkyl_range *local_ext, bool use_gpu +); /** * Calculate metric coefficients and jacobian at nodes @@ -32,7 +33,9 @@ gkyl_calc_metric_mirror* gkyl_calc_metric_mirror_new(const struct gkyl_basis *cb * @param gk_geom gk_geom objet to be populated * @param mirror_grid mirr_grid object with coordinates, tangents, duals, Jc, and B at nodes */ -void gkyl_calc_metric_mirror_advance(gkyl_calc_metric_mirror *up, struct gk_geometry *gk_geom, struct gkyl_mirror_grid_gen *mirror_grid); +void gkyl_calc_metric_mirror_advance( + gkyl_calc_metric_mirror *up, struct gk_geometry *gk_geom, struct gkyl_mirror_grid_gen *mirror_grid +); /** * calculate metric coefficients and jacobian at @@ -44,7 +47,9 @@ void gkyl_calc_metric_mirror_advance(gkyl_calc_metric_mirror *up, struct gk_geom * @param gk_geom gk_geom objet to be populated * @param mirror_grid mirr_grid object with coordinates, tangents, duals, Jc, and B at nodes */ -void gkyl_calc_metric_mirror_advance_interior(gkyl_calc_metric_mirror *up, struct gk_geometry *gk_geom, struct gkyl_mirror_grid_gen *mirror_grid); +void gkyl_calc_metric_mirror_advance_interior( + gkyl_calc_metric_mirror *up, struct gk_geometry *gk_geom, struct gkyl_mirror_grid_gen *mirror_grid +); /** * Use finite differences to calculate metric coefficients and jacobian at @@ -57,11 +62,14 @@ void gkyl_calc_metric_mirror_advance_interior(gkyl_calc_metric_mirror *up, struc * @param gk_geom gk_geom objet to be populated * @param mirror_grid mirr_grid object with coordinates, tangents, duals, Jc, and B at nodes */ -void gkyl_calc_metric_mirror_advance_surface( gkyl_calc_metric_mirror *up, int dir, struct gk_geometry* gk_geom, struct gkyl_mirror_grid_gen *mirror_grid); +void gkyl_calc_metric_mirror_advance_surface( + gkyl_calc_metric_mirror *up, int dir, struct gk_geometry *gk_geom, + struct gkyl_mirror_grid_gen *mirror_grid +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_calc_metric_mirror_release(gkyl_calc_metric_mirror* up); +void gkyl_calc_metric_mirror_release(gkyl_calc_metric_mirror *up); diff --git a/gyrokinetic/zero/gkyl_calc_metric_mirror_priv.h b/gyrokinetic/zero/gkyl_calc_metric_mirror_priv.h index 7222b52261..413045553b 100644 --- a/gyrokinetic/zero/gkyl_calc_metric_mirror_priv.h +++ b/gyrokinetic/zero/gkyl_calc_metric_mirror_priv.h @@ -8,12 +8,11 @@ struct gkyl_calc_metric_mirror { unsigned cdim; // Configuration-space dimension. unsigned cnum_basis; // Number of conf-space basis functions. unsigned poly_order; // Polynomial order of the basis. - const struct gkyl_rect_grid* grid; + const struct gkyl_rect_grid *grid; bool use_gpu; const int *num_cells; - const struct gkyl_basis* cbasis; + const struct gkyl_basis *cbasis; struct gkyl_nodal_ops *n2m; struct gkyl_range local; struct gkyl_range local_ext; }; - diff --git a/gyrokinetic/zero/gkyl_calc_metric_priv.h b/gyrokinetic/zero/gkyl_calc_metric_priv.h index a41f81b0d2..31c951c0ac 100644 --- a/gyrokinetic/zero/gkyl_calc_metric_priv.h +++ b/gyrokinetic/zero/gkyl_calc_metric_priv.h @@ -8,15 +8,14 @@ struct gkyl_calc_metric { unsigned cdim; // Configuration-space dimension. unsigned cnum_basis; // Number of conf-space basis functions. unsigned poly_order; // Polynomial order of the basis. - const struct gkyl_rect_grid* grid; + const struct gkyl_rect_grid *grid; bool exit_at_checks; // Whether to terminate if consistency checks fail. bool use_gpu; const int *num_cells; - const struct gkyl_basis* cbasis; + const struct gkyl_basis *cbasis; struct gkyl_nodal_ops *n2m; struct gkyl_range global; struct gkyl_range global_ext; struct gkyl_range local; struct gkyl_range local_ext; }; - diff --git a/gyrokinetic/zero/gkyl_deflate_geo.h b/gyrokinetic/zero/gkyl_deflate_geo.h index 631be57292..0292f50890 100644 --- a/gyrokinetic/zero/gkyl_deflate_geo.h +++ b/gyrokinetic/zero/gkyl_deflate_geo.h @@ -20,9 +20,11 @@ typedef struct gkyl_deflate_geo gkyl_deflate_geo; * @return New updater pointer. */ - -gkyl_deflate_geo* gkyl_deflate_geo_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *deflated_cbasis, - const struct gkyl_rect_grid *grid, const struct gkyl_rect_grid *deflated_grid, const int *rem_dirs, bool use_gpu); +gkyl_deflate_geo *gkyl_deflate_geo_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *deflated_cbasis, + const struct gkyl_rect_grid *grid, const struct gkyl_rect_grid *deflated_grid, + const int *rem_dirs, bool use_gpu +); /** * Create new updater to compute the deflated surface geo * @@ -36,7 +38,10 @@ gkyl_deflate_geo* gkyl_deflate_geo_new(const struct gkyl_basis *cbasis, const st * @return New updater pointer. */ -struct gkyl_deflate_geo_surf* gkyl_deflate_geo_surf_new(const struct gkyl_basis *cbasis, int deflated_num_basis, const struct gkyl_rect_grid *grid, const struct gkyl_rect_grid *deflated_grid, const int *rem_dirs, int dir, bool use_gpu); +struct gkyl_deflate_geo_surf *gkyl_deflate_geo_surf_new( + const struct gkyl_basis *cbasis, int deflated_num_basis, const struct gkyl_rect_grid *grid, + const struct gkyl_rect_grid *deflated_grid, const int *rem_dirs, int dir, bool use_gpu +); /** * Advance deflate_geo @@ -49,9 +54,11 @@ struct gkyl_deflate_geo_surf* gkyl_deflate_geo_surf_new(const struct gkyl_basis * @param ncomp number of components */ - -void gkyl_deflate_geo_advance(const gkyl_deflate_geo *up, const struct gkyl_range *range, const struct gkyl_range* deflated_range, const struct gkyl_array *field, struct gkyl_array *deflated_field, int ncomp); - +void gkyl_deflate_geo_advance( + const gkyl_deflate_geo *up, const struct gkyl_range *range, + const struct gkyl_range *deflated_range, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +); /** * Advance deflate_geo on nodal quantities @@ -64,9 +71,11 @@ void gkyl_deflate_geo_advance(const gkyl_deflate_geo *up, const struct gkyl_rang * @param ncomp number of components */ - -void gkyl_deflate_geo_advance_nodal(const gkyl_deflate_geo *up, const struct gkyl_range *range, const struct gkyl_range* deflated_range, const struct gkyl_array *field, struct gkyl_array *deflated_field, int ncomp); - +void gkyl_deflate_geo_advance_nodal( + const gkyl_deflate_geo *up, const struct gkyl_range *range, + const struct gkyl_range *deflated_range, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +); /** * Advance deflate_geo_surf @@ -78,7 +87,11 @@ void gkyl_deflate_geo_advance_nodal(const gkyl_deflate_geo *up, const struct gky * @param deflated_field 2d field on output * @param ncomp number of components */ -void gkyl_deflate_geo_surf_advance(const struct gkyl_deflate_geo_surf *up, const struct gkyl_range *range, const struct gkyl_range* deflated_range, const struct gkyl_array *field, struct gkyl_array *deflated_field, int ncomp); +void gkyl_deflate_geo_surf_advance( + const struct gkyl_deflate_geo_surf *up, const struct gkyl_range *range, + const struct gkyl_range *deflated_range, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +); /** * Advance deflate_geo_surf on nodal quantities @@ -90,20 +103,22 @@ void gkyl_deflate_geo_surf_advance(const struct gkyl_deflate_geo_surf *up, const * @param deflated_field 2d field on output * @param ncomp number of components */ -void gkyl_deflate_geo_surf_advance_nodal(const struct gkyl_deflate_geo_surf *up, const struct gkyl_range *range, const struct gkyl_range* deflated_range, const struct gkyl_array *field, struct gkyl_array *deflated_field, int ncomp); - +void gkyl_deflate_geo_surf_advance_nodal( + const struct gkyl_deflate_geo_surf *up, const struct gkyl_range *range, + const struct gkyl_range *deflated_range, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_deflate_geo_release(gkyl_deflate_geo* up); - +void gkyl_deflate_geo_release(gkyl_deflate_geo *up); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_deflate_geo_surf_release(struct gkyl_deflate_geo_surf* up); +void gkyl_deflate_geo_surf_release(struct gkyl_deflate_geo_surf *up); diff --git a/gyrokinetic/zero/gkyl_deflate_geo_priv.h b/gyrokinetic/zero/gkyl_deflate_geo_priv.h index 188908d2f9..c2a1e9ef1f 100644 --- a/gyrokinetic/zero/gkyl_deflate_geo_priv.h +++ b/gyrokinetic/zero/gkyl_deflate_geo_priv.h @@ -5,141 +5,117 @@ #include #include -typedef void (*deflate_geo_kernel)(const double *fld, double* deflated_fld); - - -typedef struct { deflate_geo_kernel kernels[3]; } deflate_geo_kernel_list; -typedef struct { deflate_geo_kernel_list list[4]; } deflate_geo_kernel_remy_list; -typedef struct { deflate_geo_kernel_remy_list list[2]; } deflate_geo_kernel_remx_list; - -typedef struct { deflate_geo_kernel_list list[3]; } deflate_geo_surf_kernel_dim_list; - +typedef void (*deflate_geo_kernel)(const double *fld, double *deflated_fld); + +typedef struct { + deflate_geo_kernel kernels[3]; +} deflate_geo_kernel_list; +typedef struct { + deflate_geo_kernel_list list[4]; +} deflate_geo_kernel_remy_list; +typedef struct { + deflate_geo_kernel_remy_list list[2]; +} deflate_geo_kernel_remx_list; + +typedef struct { + deflate_geo_kernel_list list[3]; +} deflate_geo_surf_kernel_dim_list; static const deflate_geo_surf_kernel_dim_list ser_deflate_surf_geo_kernel_list[] = { - { .list = { - {NULL, NULL, NULL}, - {NULL, NULL, NULL }, - {NULL, NULL, NULL}, - } - }, - { .list = { - {NULL, deflate_geo_surfx_1x_ser_p1, NULL}, - {NULL, NULL, NULL }, - {NULL, NULL, NULL}, - } - }, - { .list = { - {NULL, deflate_geo_surfx_2x_ser_p1, NULL}, - {NULL, deflate_geo_surfy_2x_ser_p1, NULL }, - {NULL, NULL, NULL}, - } - }, + {.list = {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}}, + {.list = {{NULL, deflate_geo_surfx_1x_ser_p1, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}}, + {.list = + {{NULL, deflate_geo_surfx_2x_ser_p1, NULL}, + {NULL, deflate_geo_surfy_2x_ser_p1, NULL}, + {NULL, NULL, NULL}}} }; -GKYL_CU_DH -static const deflate_geo_kernel_remx_list ser_deflate_geo_kernel_rem_list[] = { -// don't remove x -{ .list = { - // don't remove y - { .list = { - {NULL, NULL, NULL}, - {NULL, NULL, NULL}, - {NULL, NULL, NULL}, - {NULL, NULL, NULL} - } - }, - - // remove y - { .list = { - {NULL, NULL, NULL}, - {NULL, NULL, NULL}, - {NULL, deflate_geo_2x_ser_p1_remy, deflate_geo_2x_ser_p2_remy}, - {NULL, NULL, NULL} - } - }, - - +GKYL_CU_DH static const deflate_geo_kernel_remx_list ser_deflate_geo_kernel_rem_list[] = + { + // don't remove x + {.list = + {// don't remove y + {.list = {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}}, + + // remove y + {.list = + {{NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, deflate_geo_2x_ser_p1_remy, deflate_geo_2x_ser_p2_remy}, + {NULL, NULL, NULL}}} + + }}, + // remove x + { + .list = + { + // don't remove y + {.list = + {{NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, deflate_geo_2x_ser_p1_remx, deflate_geo_2x_ser_p2_remx}, + {NULL, NULL, NULL}}}, + + // remove y + {.list = + {{NULL, NULL, NULL}, + {NULL, deflate_geo_1x_ser_p1_remxy, deflate_geo_1x_ser_p2_remxy}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}}} + + } } - }, -// remove x -{ .list = { - // don't remove y - { .list = { - {NULL, NULL, NULL}, - {NULL, NULL, NULL}, - {NULL, deflate_geo_2x_ser_p1_remx, deflate_geo_2x_ser_p2_remx}, - {NULL, NULL, NULL} - } - }, - - // remove y - { .list = { - {NULL, NULL, NULL}, - {NULL, deflate_geo_1x_ser_p1_remxy, deflate_geo_1x_ser_p2_remxy}, - {NULL, NULL, NULL}, - {NULL, NULL, NULL} - } - }, - - - } - }, - }; - -struct gkyl_deflate_geo{ +struct gkyl_deflate_geo { const struct gkyl_basis *basis; const struct gkyl_basis *deflated_basis; - const struct gkyl_rect_grid* grid; - const struct gkyl_rect_grid* deflated_grid; + const struct gkyl_rect_grid *grid; + const struct gkyl_rect_grid *deflated_grid; deflate_geo_kernel kernel; int *rem_dirs; bool use_gpu; }; -struct gkyl_deflate_geo_surf{ +struct gkyl_deflate_geo_surf { const struct gkyl_basis *basis; int deflated_num_basis; - const struct gkyl_rect_grid* grid; - const struct gkyl_rect_grid* deflated_grid; + const struct gkyl_rect_grid *grid; + const struct gkyl_rect_grid *deflated_grid; deflate_geo_kernel kernel; int *rem_dirs; int dir; bool use_gpu; }; -GKYL_CU_DH -static deflate_geo_kernel -deflate_geo_choose_kernel(const int *rem_dirs, const int cdim, const int basis_type, const int poly_order) +GKYL_CU_DH static deflate_geo_kernel deflate_geo_choose_kernel( + const int *rem_dirs, const int cdim, const int basis_type, const int poly_order +) { switch (basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_deflate_geo_kernel_rem_list[rem_dirs[0]].list[rem_dirs[1]].list[cdim].kernels[poly_order]; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_deflate_geo_kernel_rem_list[rem_dirs[0]] + .list[rem_dirs[1]] + .list[cdim] + .kernels[poly_order]; + + default: + assert(false); + break; } } -GKYL_CU_DH -static deflate_geo_kernel -deflate_geo_surf_choose_kernel(const int dir, const int cdim, const int basis_type, const int poly_order) +GKYL_CU_DH static deflate_geo_kernel deflate_geo_surf_choose_kernel( + const int dir, const int cdim, const int basis_type, const int poly_order +) { switch (basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_deflate_surf_geo_kernel_list[cdim].list[dir].kernels[poly_order]; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_deflate_surf_geo_kernel_list[cdim].list[dir].kernels[poly_order]; - default: - assert(false); - break; + default: + assert(false); + break; } } - - - - - - diff --git a/gyrokinetic/zero/gkyl_deflate_zsurf.h b/gyrokinetic/zero/gkyl_deflate_zsurf.h index 4c796893e6..92b84236c6 100644 --- a/gyrokinetic/zero/gkyl_deflate_zsurf.h +++ b/gyrokinetic/zero/gkyl_deflate_zsurf.h @@ -19,9 +19,9 @@ typedef struct gkyl_deflate_zsurf gkyl_deflate_zsurf; * @return New updater pointer. */ -struct gkyl_deflate_zsurf* -gkyl_deflate_zsurf_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *deflated_cbasis, - int edge, bool use_gpu); +struct gkyl_deflate_zsurf *gkyl_deflate_zsurf_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *deflated_cbasis, int edge, bool use_gpu +); /** * Advance deflate_zsurf (compute the derived_zsurf coefficients). @@ -35,21 +35,25 @@ gkyl_deflate_zsurf_new(const struct gkyl_basis *cbasis, const struct gkyl_basis * @param ncomp Number of components being deflated */ -void gkyl_deflate_zsurf_advance(const struct gkyl_deflate_zsurf *up, int zidx, - const struct gkyl_range *range, const struct gkyl_range *deflated_range, - const struct gkyl_array *field, struct gkyl_array *deflated_field, int ncomp); +void gkyl_deflate_zsurf_advance( + const struct gkyl_deflate_zsurf *up, int zidx, const struct gkyl_range *range, + const struct gkyl_range *deflated_range, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_deflate_zsurf_release(struct gkyl_deflate_zsurf* up); +void gkyl_deflate_zsurf_release(struct gkyl_deflate_zsurf *up); /** * Host-side wrappers for deflation operations on device */ -void gkyl_deflate_zsurf_advance_cu(const struct gkyl_deflate_zsurf *up, int zidx, - const struct gkyl_range *range, const struct gkyl_range *deflated_range, - const struct gkyl_array *field, struct gkyl_array *deflated_field, int ncomp); +void gkyl_deflate_zsurf_advance_cu( + const struct gkyl_deflate_zsurf *up, int zidx, const struct gkyl_range *range, + const struct gkyl_range *deflated_range, const struct gkyl_array *field, + struct gkyl_array *deflated_field, int ncomp +); diff --git a/gyrokinetic/zero/gkyl_deflate_zsurf_priv.h b/gyrokinetic/zero/gkyl_deflate_zsurf_priv.h index 5f492cb8e3..2298e3000b 100644 --- a/gyrokinetic/zero/gkyl_deflate_zsurf_priv.h +++ b/gyrokinetic/zero/gkyl_deflate_zsurf_priv.h @@ -5,36 +5,26 @@ #include #include -typedef void (*deflate_zsurf_kernel)(const double *fld, double* deflated_fld); - -typedef struct { deflate_zsurf_kernel kernels[3]; } deflate_zsurf_kernel_list; -typedef struct { deflate_zsurf_kernel_list list[2]; } deflate_zsurf_kernel_dim_list; - -GKYL_CU_D -static const deflate_zsurf_kernel_dim_list ser_deflate_zsurf_kernel_dim_list[] = { - { .list = { - {NULL, NULL, NULL}, - {NULL, NULL, NULL}, - } - }, - { .list = { - {NULL, NULL, NULL}, - {NULL, NULL, NULL}, - } - }, - { .list = { - {NULL, deflate_surfy_lower_2x_ser_p1, deflate_surfy_lower_2x_ser_p2}, - {NULL, deflate_surfy_upper_2x_ser_p1, deflate_surfy_upper_2x_ser_p2}, - } - }, - { .list = { - {NULL, deflate_surfz_lower_3x_ser_p1, deflate_surfz_lower_3x_ser_p2}, - {NULL, deflate_surfz_upper_3x_ser_p1, deflate_surfz_upper_3x_ser_p2}, - } - }, +typedef void (*deflate_zsurf_kernel)(const double *fld, double *deflated_fld); + +typedef struct { + deflate_zsurf_kernel kernels[3]; +} deflate_zsurf_kernel_list; +typedef struct { + deflate_zsurf_kernel_list list[2]; +} deflate_zsurf_kernel_dim_list; + +GKYL_CU_D static const deflate_zsurf_kernel_dim_list ser_deflate_zsurf_kernel_dim_list[] = { + {.list = {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}, + {.list = {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}, + {.list = + {{NULL, deflate_surfy_lower_2x_ser_p1, deflate_surfy_lower_2x_ser_p2}, + {NULL, deflate_surfy_upper_2x_ser_p1, deflate_surfy_upper_2x_ser_p2}}}, + {.list = + {{NULL, deflate_surfz_lower_3x_ser_p1, deflate_surfz_lower_3x_ser_p2}, + {NULL, deflate_surfz_upper_3x_ser_p1, deflate_surfz_upper_3x_ser_p2}}} }; - struct gkyl_deflate_zsurf { int num_basis; // Number of basis functions in full basis int num_deflated_basis; // Number of basis functions in deflated basis @@ -45,17 +35,16 @@ struct gkyl_deflate_zsurf { bool use_gpu; }; -GKYL_CU_D -static deflate_zsurf_kernel +GKYL_CU_D static deflate_zsurf_kernel deflate_zsurf_choose_kernel(enum gkyl_basis_type basis_type, int dim, int edge, int poly_order) { switch (basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_deflate_zsurf_kernel_dim_list[dim].list[edge].kernels[poly_order]; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_deflate_zsurf_kernel_dim_list[dim].list[edge].kernels[poly_order]; - default: - assert(false); - break; + default: + assert(false); + break; } return 0; @@ -65,6 +54,6 @@ deflate_zsurf_choose_kernel(enum gkyl_basis_type basis_type, int dim, int edge, * Create new updater deflate a 2d (x,z) or 3d (x,y,z) modal expansion to a 1d (x) modal expansion or 2d (x,y) * NV-GPU. See new() method for documentation. */ -struct gkyl_deflate_zsurf* -gkyl_deflate_zsurf_cu_dev_new(const struct gkyl_basis *cbasis, - const struct gkyl_basis *deflated_cbasis, int edge); +struct gkyl_deflate_zsurf *gkyl_deflate_zsurf_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *deflated_cbasis, int edge +); diff --git a/gyrokinetic/zero/gkyl_deflated_dg_bin_ops.h b/gyrokinetic/zero/gkyl_deflated_dg_bin_ops.h index 4ea231338e..c5a3ddf94c 100644 --- a/gyrokinetic/zero/gkyl_deflated_dg_bin_ops.h +++ b/gyrokinetic/zero/gkyl_deflated_dg_bin_ops.h @@ -32,8 +32,10 @@ typedef struct gkyl_deflated_dg_bin_ops gkyl_deflated_dg_bin_ops; * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -struct gkyl_deflated_dg_bin_ops* gkyl_deflated_dg_bin_ops_new(struct gkyl_rect_grid grid, - struct gkyl_basis *basis_on_dev, struct gkyl_basis basis, struct gkyl_range local, bool use_gpu); +struct gkyl_deflated_dg_bin_ops *gkyl_deflated_dg_bin_ops_new( + struct gkyl_rect_grid grid, struct gkyl_basis *basis_on_dev, struct gkyl_basis basis, + struct gkyl_range local, bool use_gpu +); /** * Multiply the two input fields on surfaces constant in the last dimension @@ -51,8 +53,10 @@ struct gkyl_deflated_dg_bin_ops* gkyl_deflated_dg_bin_ops_new(struct gkyl_rect_g * @param rop Right operand DG field * */ -void gkyl_deflated_dg_bin_ops_mul(struct gkyl_deflated_dg_bin_ops* up, int c_oop, - struct gkyl_array *out, int c_lop, struct gkyl_array *lop, int c_rop, struct gkyl_array* rop); +void gkyl_deflated_dg_bin_ops_mul( + struct gkyl_deflated_dg_bin_ops *up, int c_oop, struct gkyl_array *out, int c_lop, + struct gkyl_array *lop, int c_rop, struct gkyl_array *rop +); /** * Divide the two input fields on surfaces constant in the last dimension @@ -70,12 +74,14 @@ void gkyl_deflated_dg_bin_ops_mul(struct gkyl_deflated_dg_bin_ops* up, int c_oop * @param rop Right operand DG field * */ -void gkyl_deflated_dg_bin_ops_div(struct gkyl_deflated_dg_bin_ops* up, int c_oop, - struct gkyl_array *out, int c_lop, struct gkyl_array *lop, int c_rop, struct gkyl_array* rop); +void gkyl_deflated_dg_bin_ops_div( + struct gkyl_deflated_dg_bin_ops *up, int c_oop, struct gkyl_array *out, int c_lop, + struct gkyl_array *lop, int c_rop, struct gkyl_array *rop +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_deflated_dg_bin_ops_release(struct gkyl_deflated_dg_bin_ops* up); +void gkyl_deflated_dg_bin_ops_release(struct gkyl_deflated_dg_bin_ops *up); diff --git a/gyrokinetic/zero/gkyl_deflated_dg_bin_ops_priv.h b/gyrokinetic/zero/gkyl_deflated_dg_bin_ops_priv.h index 8845acf35b..4fa82ae8bc 100644 --- a/gyrokinetic/zero/gkyl_deflated_dg_bin_ops_priv.h +++ b/gyrokinetic/zero/gkyl_deflated_dg_bin_ops_priv.h @@ -5,7 +5,7 @@ #include #include -// Struct containing all fields +// Struct containing all fields // needed to do the div or mul on a // surface which is constant in the last coordinate // of the configuration space grid @@ -15,44 +15,40 @@ struct deflated_dg_bin_ops_data { struct gkyl_array *deflated_out; }; -enum deflated_dg_bin_ops_type { - GKYL_DEFLATED_MUL = 0, - GKYL_DEFLATED_DIV = 1, -}; - +enum deflated_dg_bin_ops_type { GKYL_DEFLATED_MUL = 0, GKYL_DEFLATED_DIV = 1 }; // Updater type struct gkyl_deflated_dg_bin_ops { struct gkyl_rect_grid grid; // Conf space grid struct gkyl_rect_grid deflated_grid; // Conf space grid with last - // dimension removed + // dimension removed struct gkyl_basis basis; // Basis object struct gkyl_basis *basis_on_dev; // Basis object on GPU struct gkyl_basis deflated_basis; // Basis object with one - // less dimension than basis + // less dimension than basis struct gkyl_basis *deflated_basis_on_dev; // deflated basis on GPU struct gkyl_range local; // Local range where operation should hapen struct gkyl_range deflated_local; // Local range with last dim removed struct gkyl_range deflated_local_ext; // extended deflated local range struct gkyl_range nrange; // nodal range corresponding to - // local range + // local range struct gkyl_range deflated_nrange; // nodal range corresponding to - // deflated local range + // deflated local range struct gkyl_dg_bin_op_mem *mem; // memory fir division of deflated fields struct deflated_dg_bin_ops_data *d_bop_data; // Array of deflated_dem_data - // to be used for individual surface solves + // to be used for individual surface solves struct gkyl_array *nodal_fld; // Nodal field which holds solution int num_solves_z; // Number of surfaces to solve on int cdim; // Dimension of configureation space struct gkyl_nodal_ops *n2m; // Nodal to modal operator to be - // used to construct the final DG solution + // used to construct the final DG solution struct gkyl_nodal_ops *n2m_deflated; // Nodal to modal operator to - // be used at each surface + // be used at each surface struct gkyl_deflate_zsurf *deflator_lo; // Deflation operator used to - // evaluate fields at a lower surface + // evaluate fields at a lower surface struct gkyl_deflate_zsurf *deflator_up; // Deflation operator used to - // evaluate fields at an upper surface + // evaluate fields at an upper surface bool use_gpu; // Whether to use the GPU }; diff --git a/gyrokinetic/zero/gkyl_deflated_fem_poisson.h b/gyrokinetic/zero/gkyl_deflated_fem_poisson.h index 79ea7d26e0..2253223868 100644 --- a/gyrokinetic/zero/gkyl_deflated_fem_poisson.h +++ b/gyrokinetic/zero/gkyl_deflated_fem_poisson.h @@ -9,7 +9,6 @@ #include #include - // Object type typedef struct gkyl_deflated_fem_poisson gkyl_deflated_fem_poisson; @@ -40,10 +39,12 @@ typedef struct gkyl_deflated_fem_poisson gkyl_deflated_fem_poisson; * @param use_gpu Boolean indicating whether to use the GPU. * @return New updater pointer. */ -struct gkyl_deflated_fem_poisson* gkyl_deflated_fem_poisson_new(struct gkyl_rect_grid grid, - struct gkyl_basis *basis_on_dev, struct gkyl_basis basis, struct gkyl_range local, - struct gkyl_range global_sub_range, struct gkyl_array *epsilon, struct gkyl_array *kSq, - struct gkyl_poisson_bc poisson_bc, struct gkyl_poisson_bias_plane_list *bias_plane_list, bool use_gpu); +struct gkyl_deflated_fem_poisson *gkyl_deflated_fem_poisson_new( + struct gkyl_rect_grid grid, struct gkyl_basis *basis_on_dev, struct gkyl_basis basis, + struct gkyl_range local, struct gkyl_range global_sub_range, struct gkyl_array *epsilon, + struct gkyl_array *kSq, struct gkyl_poisson_bc poisson_bc, + struct gkyl_poisson_bias_plane_list *bias_plane_list, bool use_gpu +); /** * Solve the poisson equation for the given charge density @@ -53,12 +54,14 @@ struct gkyl_deflated_fem_poisson* gkyl_deflated_fem_poisson_new(struct gkyl_rect * @param phibc Spatially varying BC as a DG (volume) field, defined in the whole domain. * @param phi DG field solution to poison problem (phi). */ -void gkyl_deflated_fem_poisson_advance(struct gkyl_deflated_fem_poisson* up, struct gkyl_array *rhs, - struct gkyl_array *phibc, struct gkyl_array* phi); +void gkyl_deflated_fem_poisson_advance( + struct gkyl_deflated_fem_poisson *up, struct gkyl_array *rhs, struct gkyl_array *phibc, + struct gkyl_array *phi +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_deflated_fem_poisson_release(struct gkyl_deflated_fem_poisson* up); +void gkyl_deflated_fem_poisson_release(struct gkyl_deflated_fem_poisson *up); diff --git a/gyrokinetic/zero/gkyl_deflated_fem_poisson_priv.h b/gyrokinetic/zero/gkyl_deflated_fem_poisson_priv.h index a17e3b360f..6ec54ad798 100644 --- a/gyrokinetic/zero/gkyl_deflated_fem_poisson_priv.h +++ b/gyrokinetic/zero/gkyl_deflated_fem_poisson_priv.h @@ -26,36 +26,36 @@ struct gkyl_deflated_fem_poisson { struct gkyl_rect_grid grid; // Conf space grid struct gkyl_rect_grid deflated_grid; // Conf space grid with last - // dimension removed + // dimension removed struct gkyl_basis basis; // Basis object struct gkyl_basis *basis_on_dev; // Basis object on GPU struct gkyl_basis deflated_basis; // Basis object with one - // less dimension than basis + // less dimension than basis struct gkyl_basis *deflated_basis_on_dev; // deflated basis on GPU struct gkyl_range local; // Local range where poisson problem - // should be solved + // should be solved struct gkyl_range deflated_local; // Local range with last dim removed struct gkyl_range global_sub_range; // Local range as a - // sub range of the global range + // sub range of the global range struct gkyl_range deflated_local_ext; // extended deflated local range struct gkyl_range nrange; // nodal range corresponding to - // local range + // local range struct gkyl_range deflated_nrange; // nodal range corresponding to - // deflated local range + // deflated local range struct gkyl_poisson_bc poisson_bc; // Boundary conditions struct gkyl_poisson_bias_plane_list *bias_plane_list; // Biased planes struct deflated_fem_data *d_fem_data; // Array of deflated_dem_data - // to be used for individual surface solves + // to be used for individual surface solves struct gkyl_array *nodal_fld; // Nodal field which holds solution int num_solves_z; // Number of surfaces to solve on int cdim; // Dimension of configureation space struct gkyl_nodal_ops *n2m; // Nodal to modal operator to be - // used to construct the final DG solution + // used to construct the final DG solution struct gkyl_nodal_ops *n2m_deflated; // Nodal to modal operator to - // be used at each surface + // be used at each surface struct gkyl_deflate_zsurf *deflator_lo; // Deflation operator used to - // evaluate fields at a lower surface + // evaluate fields at a lower surface struct gkyl_deflate_zsurf *deflator_up; // Deflation operator used to - // evaluate fields at an upper surface + // evaluate fields at an upper surface bool use_gpu; // Whether to use the GPU }; diff --git a/gyrokinetic/zero/gkyl_dg_calc_gk_neut_hamil.h b/gyrokinetic/zero/gkyl_dg_calc_gk_neut_hamil.h index 2100ba8d4c..c0b0e7b2f3 100644 --- a/gyrokinetic/zero/gkyl_dg_calc_gk_neut_hamil.h +++ b/gyrokinetic/zero/gkyl_dg_calc_gk_neut_hamil.h @@ -21,9 +21,9 @@ typedef struct gkyl_dg_calc_gk_neut_hamil gkyl_dg_calc_gk_neut_hamil; * @param cdim Configuration space dimension * @return New updater pointer. */ -struct gkyl_dg_calc_gk_neut_hamil* -gkyl_dg_calc_gk_neut_hamil_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *basis, int cdim, bool use_gpu); +struct gkyl_dg_calc_gk_neut_hamil *gkyl_dg_calc_gk_neut_hamil_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *basis, int cdim, bool use_gpu +); /** * Compute the Hamiltonian @@ -34,9 +34,10 @@ gkyl_dg_calc_gk_neut_hamil_new(const struct gkyl_rect_grid *phase_grid, * @param gij Input array (6-vector) of geometric coefficients * @param hamil Output array of Hamiltonian in phase space grid */ -void gkyl_dg_calc_gk_neut_hamil_calc(struct gkyl_dg_calc_gk_neut_hamil *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* gij, struct gkyl_array* hamil); +void gkyl_dg_calc_gk_neut_hamil_calc( + struct gkyl_dg_calc_gk_neut_hamil *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *gij, struct gkyl_array *hamil +); /** * Delete pointer to updater. diff --git a/gyrokinetic/zero/gkyl_dg_calc_gk_neut_hamil_priv.h b/gyrokinetic/zero/gkyl_dg_calc_gk_neut_hamil_priv.h index 70b366de87..d37b288e9d 100644 --- a/gyrokinetic/zero/gkyl_dg_calc_gk_neut_hamil_priv.h +++ b/gyrokinetic/zero/gkyl_dg_calc_gk_neut_hamil_priv.h @@ -11,56 +11,58 @@ #include #include -typedef void (*hamil_t)(const double *w, const double *dv, - const double* gij, double* GKYL_RESTRICT hamil); +typedef void (*hamil_t)( + const double *w, const double *dv, const double *gij, double *GKYL_RESTRICT hamil +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -GKYL_CU_D -static struct { int vdim[4]; } cv_index[] = { +GKYL_CU_D static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // for use in kernel tables -typedef struct { hamil_t kernels[3]; } gkyl_dg_calc_gk_neut_hamil_kern_list; +typedef struct { + hamil_t kernels[3]; +} gkyl_dg_calc_gk_neut_hamil_kern_list; struct gkyl_dg_calc_gk_neut_hamil { - struct gkyl_rect_grid phase_grid; // Phase-space grid for cell spacing and cell center + struct gkyl_rect_grid phase_grid; // Phase-space grid for cell spacing and cell center hamil_t calc_hamil; // kernel for computing hamiltonian. - + uint32_t flags; struct gkyl_dg_calc_gk_neut_hamil *on_dev; // pointer to itself or device data. }; // Calculate hamiltonian -GKYL_CU_D -static const gkyl_dg_calc_gk_neut_hamil_kern_list tensor_gk_neut_hamil_kernels[] = { +GKYL_CU_D static const gkyl_dg_calc_gk_neut_hamil_kern_list tensor_gk_neut_hamil_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_neut_hamil_1x3v_tensor_p1, NULL }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_neut_hamil_1x3v_tensor_p1, NULL}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, gk_neut_hamil_2x3v_tensor_p1, NULL }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, gk_neut_hamil_2x3v_tensor_p1, NULL}, // 4 // 3x kernels - { NULL, gk_neut_hamil_3x3v_tensor_p1, NULL }, // 5 + {NULL, gk_neut_hamil_3x3v_tensor_p1, NULL} // 5 }; -GKYL_CU_D -static hamil_t +GKYL_CU_D static hamil_t choose_kern(enum gkyl_basis_type b_type, int cdim, int vdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_TENSOR: - return tensor_gk_neut_hamil_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_TENSOR: + return tensor_gk_neut_hamil_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; + break; + default: + assert(false); + break; } return 0; } @@ -70,15 +72,16 @@ choose_kern(enum gkyl_basis_type b_type, int cdim, int vdim, int poly_order) * Create new updater to compute relativistic variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_dg_calc_gk_neut_hamil* -gkyl_dg_calc_gk_neut_hamil_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *basis, int cdim); +struct gkyl_dg_calc_gk_neut_hamil *gkyl_dg_calc_gk_neut_hamil_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *basis, int cdim +); /** * Host-side wrappers for sr vars operations on device */ - void gkyl_dg_calc_gk_neut_hamil_calc_cu(struct gkyl_dg_calc_gk_neut_hamil *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* gij, struct gkyl_array* hamil); +void gkyl_dg_calc_gk_neut_hamil_calc_cu( + struct gkyl_dg_calc_gk_neut_hamil *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *gij, struct gkyl_array *hamil +); #endif diff --git a/gyrokinetic/zero/gkyl_dg_calc_gk_rad_vars.h b/gyrokinetic/zero/gkyl_dg_calc_gk_rad_vars.h index e2b64206be..f5fa1ccf16 100644 --- a/gyrokinetic/zero/gkyl_dg_calc_gk_rad_vars.h +++ b/gyrokinetic/zero/gkyl_dg_calc_gk_rad_vars.h @@ -18,7 +18,8 @@ struct gkyl_gk_rad_drag { struct gkyl_array *arr; // Array with drag coeff. int num_dens; // Number of densities drag coeffs computed for. struct gkyl_gk_rad_drag *on_dev; // on_dev.arr has on_dev pointers. - struct gkyl_gk_rad_drag *data; // data.arr has host pointer with array data and ->on_dev on the GPU (use_gpu=true). + struct gkyl_gk_rad_drag + *data; // data.arr has host pointer with array data and ->on_dev on the GPU (use_gpu=true). }; /** @@ -30,8 +31,9 @@ struct gkyl_gk_rad_drag { * @param sz Number of cells/size * @param use_gpu Whether to store drag coefficient on the gpu. */ -struct gkyl_gk_rad_drag* gkyl_dg_calc_gk_rad_vars_drag_new(int num_collisions, - const int *num_densities, int ncomp, long sz, bool use_gpu); +struct gkyl_gk_rad_drag *gkyl_dg_calc_gk_rad_vars_drag_new( + int num_collisions, const int *num_densities, int ncomp, long sz, bool use_gpu +); /** * Free memory associated with a gkyl_gk_rad_drag struct. @@ -40,8 +42,9 @@ struct gkyl_gk_rad_drag* gkyl_dg_calc_gk_rad_vars_drag_new(int num_collisions, * @param num_collision Number of radiating collisions. * @param use_gpu Whether data was stored on the GPU. */ -void gkyl_dg_calc_gk_rad_vars_drag_release(struct gkyl_gk_rad_drag *drag, - int num_collisions, bool use_gpu); +void gkyl_dg_calc_gk_rad_vars_drag_release( + struct gkyl_gk_rad_drag *drag, int num_collisions, bool use_gpu +); /** * Create new updater to compute the drag coefficients needed for @@ -64,10 +67,11 @@ void gkyl_dg_calc_gk_rad_vars_drag_release(struct gkyl_gk_rad_drag *drag, * @param vel_map Velocity space mapping object. * @return New updater pointer. */ -struct gkyl_dg_calc_gk_rad_vars* -gkyl_dg_calc_gk_rad_vars_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, double charge, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu); +struct gkyl_dg_calc_gk_rad_vars *gkyl_dg_calc_gk_rad_vars_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, double charge, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu +); /** * Compute drag coefficients needed for radiation in gyrokinetic equations @@ -81,11 +85,12 @@ gkyl_dg_calc_gk_rad_vars_new(const struct gkyl_rect_grid *phase_grid, * @param vsqnu_surf Output surface expansion of mu drag coefficient * @param vsqnu Output volume expansion of mu drag coefficient */ -void gkyl_dg_calc_gk_rad_vars_nu_advance(const struct gkyl_dg_calc_gk_rad_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - double a, double alpha, double beta, double gamma, double v0, - struct gkyl_array* vnu_surf, struct gkyl_array* vnu, - struct gkyl_array* vsqnu_surf, struct gkyl_array* vsqnu); +void gkyl_dg_calc_gk_rad_vars_nu_advance( + const struct gkyl_dg_calc_gk_rad_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, double a, double alpha, double beta, double gamma, + double v0, struct gkyl_array *vnu_surf, struct gkyl_array *vnu, struct gkyl_array *vsqnu_surf, + struct gkyl_array *vsqnu +); /** * Compute sum_s n_{i_s} nu_s(v) total drag coefficient for drag due to radiation in gyrokinetic equations @@ -108,14 +113,15 @@ void gkyl_dg_calc_gk_rad_vars_nu_advance(const struct gkyl_dg_calc_gk_rad_vars * * @param vtsq_min_normalized Minimum vtsq for each fit divided by configuration space normalization * @param vtsq vtsq */ -void gkyl_dg_calc_gk_rad_vars_nI_nu_advance(const struct gkyl_dg_calc_gk_rad_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_gk_rad_drag* vnu_surf, const struct gkyl_gk_rad_drag* vnu, - const struct gkyl_gk_rad_drag* vsqnu_surf, const struct gkyl_gk_rad_drag* vsqnu, - const struct gkyl_array* n_elc_rad, const struct gkyl_array* n_elc, - const struct gkyl_array* nI, struct gkyl_array* nvnu_surf, struct gkyl_array* nvnu, - struct gkyl_array* nvsqnu_surf, struct gkyl_array* nvsqnu, - struct gkyl_array* vtsq_min_normalized, struct gkyl_array* vtsq); +void gkyl_dg_calc_gk_rad_vars_nI_nu_advance( + const struct gkyl_dg_calc_gk_rad_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_gk_rad_drag *vnu_surf, + const struct gkyl_gk_rad_drag *vnu, const struct gkyl_gk_rad_drag *vsqnu_surf, + const struct gkyl_gk_rad_drag *vsqnu, const struct gkyl_array *n_elc_rad, + const struct gkyl_array *n_elc, const struct gkyl_array *nI, struct gkyl_array *nvnu_surf, + struct gkyl_array *nvnu, struct gkyl_array *nvsqnu_surf, struct gkyl_array *nvsqnu, + struct gkyl_array *vtsq_min_normalized, struct gkyl_array *vtsq +); /** * Delete pointer to updater to compute gyrokinetic variables. diff --git a/gyrokinetic/zero/gkyl_dg_calc_gk_rad_vars_priv.h b/gyrokinetic/zero/gkyl_dg_calc_gk_rad_vars_priv.h index 7d32911949..4da502dffc 100644 --- a/gyrokinetic/zero/gkyl_dg_calc_gk_rad_vars_priv.h +++ b/gyrokinetic/zero/gkyl_dg_calc_gk_rad_vars_priv.h @@ -10,35 +10,45 @@ #include #include -typedef void (*rad_gyrokinetic_nu_t)(const double *vmap, const double *vmapSq, - double charge, double mass, double a, double alpha, double beta, double gamma, double v0, - const double *bmag, double* GKYL_RESTRICT drag_rad_surf, double* GKYL_RESTRICT drag_rad); - -typedef void (*rad_gyrokinetic_nI_nu_t)(const double *vnu_surf, const double *vnu, - const double *vsqnu_surf, const double *vsqnu, const double *nI, - double* GKYL_RESTRICT nvnu_surf, double* GKYL_RESTRICT nvnu, - double* GKYL_RESTRICT nvsqnu_surf, double* GKYL_RESTRICT nvsqnu); +typedef void (*rad_gyrokinetic_nu_t)( + const double *vmap, const double *vmapSq, double charge, double mass, double a, double alpha, + double beta, double gamma, double v0, const double *bmag, double *GKYL_RESTRICT drag_rad_surf, + double *GKYL_RESTRICT drag_rad +); + +typedef void (*rad_gyrokinetic_nI_nu_t)( + const double *vnu_surf, const double *vnu, const double *vsqnu_surf, const double *vsqnu, + const double *nI, double *GKYL_RESTRICT nvnu_surf, double *GKYL_RESTRICT nvnu, + double *GKYL_RESTRICT nvsqnu_surf, double *GKYL_RESTRICT nvsqnu +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below. -GKYL_CU_D -static struct { int vdim[3]; } cv_index[] = { +GKYL_CU_D static struct { + int vdim[3]; +} cv_index[] = { {-1, -1, -1}, // 0x makes no sense. - {-1, 0, 1}, // 1x kernel indices. - {-1, -1, 2}, // 2x kernel indices. - {-1, -1, 3}, // 3x kernel indices. + {-1, 0, 1}, // 1x kernel indices. + {-1, -1, 2}, // 2x kernel indices. + {-1, -1, 3} // 3x kernel indices. }; // for use in kernel tables -typedef struct { rad_gyrokinetic_nu_t kernels[3]; } gkyl_dg_rad_gyrokinetic_nu_kern_list; -typedef struct { rad_gyrokinetic_nI_nu_t kernels[3]; } gkyl_dg_rad_gyrokinetic_nI_nu_kern_list; +typedef struct { + rad_gyrokinetic_nu_t kernels[3]; +} gkyl_dg_rad_gyrokinetic_nu_kern_list; +typedef struct { + rad_gyrokinetic_nI_nu_t kernels[3]; +} gkyl_dg_rad_gyrokinetic_nI_nu_kern_list; struct gkyl_dg_calc_gk_rad_vars { struct gkyl_rect_grid phase_grid; // Phase space grid for cell spacing and cell center int cdim; // Configuration space dimensionality int pdim; // Phase space dimensionality - rad_gyrokinetic_nu_t rad_nu_vpar; // kernel for computing surface and volume expansions of vpar radiation drag - rad_gyrokinetic_nu_t rad_nu_mu; // kernel for computing surface and volume expansions of mu radiation drag + rad_gyrokinetic_nu_t + rad_nu_vpar; // kernel for computing surface and volume expansions of vpar radiation drag + rad_gyrokinetic_nu_t + rad_nu_mu; // kernel for computing surface and volume expansions of mu radiation drag rad_gyrokinetic_nI_nu_t rad_nI_nu; // kernel for density weighted radiation drag double charge, mass; @@ -52,48 +62,43 @@ struct gkyl_dg_calc_gk_rad_vars { }; // Radiation drag surface and volume expansions in vpar (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_rad_gyrokinetic_nu_kern_list ser_rad_gyrokinetic_nu_vpar_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, rad_gyrokinetic_drag_nuvpar_1x2v_ser_p1, NULL }, // 1 - { NULL, rad_gyrokinetic_drag_nuvpar_2x2v_ser_p1, NULL }, // 2 - { NULL, rad_gyrokinetic_drag_nuvpar_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_rad_gyrokinetic_nu_kern_list ser_rad_gyrokinetic_nu_vpar_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, rad_gyrokinetic_drag_nuvpar_1x2v_ser_p1, NULL}, // 1 + {NULL, rad_gyrokinetic_drag_nuvpar_2x2v_ser_p1, NULL}, // 2 + {NULL, rad_gyrokinetic_drag_nuvpar_3x2v_ser_p1, NULL} // 3 }; // Radiation drag surface and volume expansions in mu (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_rad_gyrokinetic_nu_kern_list ser_rad_gyrokinetic_nu_mu_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, rad_gyrokinetic_drag_numu_1x2v_ser_p1, NULL }, // 1 - { NULL, rad_gyrokinetic_drag_numu_2x2v_ser_p1, NULL }, // 2 - { NULL, rad_gyrokinetic_drag_numu_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_rad_gyrokinetic_nu_kern_list ser_rad_gyrokinetic_nu_mu_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, rad_gyrokinetic_drag_numu_1x2v_ser_p1, NULL}, // 1 + {NULL, rad_gyrokinetic_drag_numu_2x2v_ser_p1, NULL}, // 2 + {NULL, rad_gyrokinetic_drag_numu_3x2v_ser_p1, NULL} // 3 }; // Density-weighted radiation drag surface and volume expansions (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_rad_gyrokinetic_nI_nu_kern_list ser_rad_gyrokinetic_nI_nu_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, rad_gyrokinetic_drag_nI_nu_1x2v_ser_p1, NULL }, // 1 - { NULL, rad_gyrokinetic_drag_nI_nu_2x2v_ser_p1, NULL }, // 2 - { NULL, rad_gyrokinetic_drag_nI_nu_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_rad_gyrokinetic_nI_nu_kern_list ser_rad_gyrokinetic_nI_nu_kernels[] = + { + {NULL, NULL, NULL}, // 0 + {NULL, rad_gyrokinetic_drag_nI_nu_1x2v_ser_p1, NULL}, // 1 + {NULL, rad_gyrokinetic_drag_nI_nu_2x2v_ser_p1, NULL}, // 2 + {NULL, rad_gyrokinetic_drag_nI_nu_3x2v_ser_p1, NULL} // 3 }; -GKYL_CU_D -static rad_gyrokinetic_nu_t +GKYL_CU_D static rad_gyrokinetic_nu_t choose_rad_gyrokinetic_nu_vpar_kern(int cdim, int vdim, int poly_order) { return ser_rad_gyrokinetic_nu_vpar_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; } -GKYL_CU_D -static rad_gyrokinetic_nu_t +GKYL_CU_D static rad_gyrokinetic_nu_t choose_rad_gyrokinetic_nu_mu_kern(int cdim, int vdim, int poly_order) { return ser_rad_gyrokinetic_nu_mu_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; } -GKYL_CU_D -static rad_gyrokinetic_nI_nu_t +GKYL_CU_D static rad_gyrokinetic_nI_nu_t choose_rad_gyrokinetic_nI_nu_kern(int cdim, int vdim, int poly_order) { return ser_rad_gyrokinetic_nI_nu_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; @@ -105,18 +110,16 @@ choose_rad_gyrokinetic_nI_nu_kern(int cdim, int vdim, int poly_order) * @param target The value to find the closest index to * @return The index of the array with the value closest to target */ -GKYL_CU_D -static inline int gkyl_dg_rad_gyrokinetic_find_nearest_idx(const struct gkyl_array* arr, double target) +GKYL_CU_D static inline int +gkyl_dg_rad_gyrokinetic_find_nearest_idx(const struct gkyl_array *arr, double target) { int left = 0; int right = arr->size - 1; - double *data = (double*)arr->data; + double *data = (double *)arr->data; while (left < right) { - if (fabs(data[left] - target) - <= fabs(data[right] - target)) { + if (fabs(data[left] - target) <= fabs(data[right] - target)) { right--; - } - else { + } else { left++; } } @@ -128,32 +131,34 @@ static inline int gkyl_dg_rad_gyrokinetic_find_nearest_idx(const struct gkyl_arr * Create new updater to compute gyrokinetic variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_dg_calc_gk_rad_vars* -gkyl_dg_calc_gk_rad_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - double charge, double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map); +struct gkyl_dg_calc_gk_rad_vars *gkyl_dg_calc_gk_rad_vars_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, double charge, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map +); /** * Compute drag coefficients for drag due to * radiation in gyrokinetics on the GPU. */ -void gkyl_dg_calc_gk_rad_vars_nu_advance_cu(const struct gkyl_dg_calc_gk_rad_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - double a, double alpha, double beta, double gamma, double v0, - struct gkyl_array* vnu_surf, struct gkyl_array* vnu, - struct gkyl_array* vsqnu_surf, struct gkyl_array* vsqnu); +void gkyl_dg_calc_gk_rad_vars_nu_advance_cu( + const struct gkyl_dg_calc_gk_rad_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, double a, double alpha, double beta, double gamma, + double v0, struct gkyl_array *vnu_surf, struct gkyl_array *vnu, struct gkyl_array *vsqnu_surf, + struct gkyl_array *vsqnu +); /** * Compute sum_s n_{i_s} nu_s(v) total drag coefficient for drag due to * radiation in gyrokinetics on the GPU. */ -void gkyl_dg_calc_gk_rad_vars_nI_nu_advance_cu(const struct gkyl_dg_calc_gk_rad_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_gk_rad_drag* vnu_surf, const struct gkyl_gk_rad_drag* vnu, - const struct gkyl_gk_rad_drag* vsqnu_surf, const struct gkyl_gk_rad_drag* vsqnu, - const struct gkyl_array* n_elc_rad, const struct gkyl_array* n_elc, - const struct gkyl_array* nI, - struct gkyl_array* nvnu_surf, struct gkyl_array* nvnu, - struct gkyl_array* nvsqnu_surf, struct gkyl_array* nvsqnu, - struct gkyl_array* vtsq_min_normalized, struct gkyl_array* vtsq); +void gkyl_dg_calc_gk_rad_vars_nI_nu_advance_cu( + const struct gkyl_dg_calc_gk_rad_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_gk_rad_drag *vnu_surf, + const struct gkyl_gk_rad_drag *vnu, const struct gkyl_gk_rad_drag *vsqnu_surf, + const struct gkyl_gk_rad_drag *vsqnu, const struct gkyl_array *n_elc_rad, + const struct gkyl_array *n_elc, const struct gkyl_array *nI, struct gkyl_array *nvnu_surf, + struct gkyl_array *nvnu, struct gkyl_array *nvsqnu_surf, struct gkyl_array *nvsqnu, + struct gkyl_array *vtsq_min_normalized, struct gkyl_array *vtsq +); #endif diff --git a/gyrokinetic/zero/gkyl_dg_cx.h b/gyrokinetic/zero/gkyl_dg_cx.h index efa0097269..58ef03176e 100644 --- a/gyrokinetic/zero/gkyl_dg_cx.h +++ b/gyrokinetic/zero/gkyl_dg_cx.h @@ -9,7 +9,7 @@ #include struct gkyl_dg_cx_inp { - struct gkyl_basis* cbasis; // Configuration-space basis-functions + struct gkyl_basis *cbasis; // Configuration-space basis-functions const struct gkyl_range *conf_rng; // Configuration-space range const struct gkyl_range *conf_rng_ext; // Configuration-space extended range double vt_sq_ion_min; // Min vtSq that can be represented on ion grid @@ -25,8 +25,7 @@ typedef struct gkyl_dg_cx gkyl_dg_cx; * @param gkyl_dg_cx_inp * @param use_gpu Boolean for whether struct is on host or device */ -struct gkyl_dg_cx* gkyl_dg_cx_new(struct gkyl_dg_cx_inp *inp, bool use_gpu); - +struct gkyl_dg_cx *gkyl_dg_cx_new(struct gkyl_dg_cx_inp *inp, bool use_gpu); /** * Compute CX reaction rate coefficient for use in neutral reactions. @@ -42,9 +41,11 @@ struct gkyl_dg_cx* gkyl_dg_cx_new(struct gkyl_dg_cx_inp *inp, bool use_gpu); * @param coef_cx Output reaction rate coefficient * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) */ -void gkyl_dg_cx_coll(const struct gkyl_dg_cx *up, - struct gkyl_array *maxwellian_moms_ion, struct gkyl_array *maxwellian_moms_neut, - struct gkyl_array *upar_b_i, struct gkyl_array *coef_cx, struct gkyl_array *cflrate); +void gkyl_dg_cx_coll( + const struct gkyl_dg_cx *up, struct gkyl_array *maxwellian_moms_ion, + struct gkyl_array *maxwellian_moms_neut, struct gkyl_array *upar_b_i, struct gkyl_array *coef_cx, + struct gkyl_array *cflrate +); /** * Delete updater. diff --git a/gyrokinetic/zero/gkyl_dg_cx_priv.h b/gyrokinetic/zero/gkyl_dg_cx_priv.h index be518d78b4..eb477d3ca6 100644 --- a/gyrokinetic/zero/gkyl_dg_cx_priv.h +++ b/gyrokinetic/zero/gkyl_dg_cx_priv.h @@ -6,79 +6,75 @@ #include #include -typedef double (*dg_cx_react_ratef_t)(const double a, const double b, double vt_sq_ion_min, double vt_sq_neut_min, +typedef double (*dg_cx_react_ratef_t)( + const double a, const double b, double vt_sq_ion_min, double vt_sq_neut_min, const double *maxwellian_moms_ion, const double *maxwellian_moms_neut, const double *u_ion, - double* GKYL_RESTRICT v_sigma_cx) ; + double *GKYL_RESTRICT v_sigma_cx +); // for use in kernel tables -typedef struct { dg_cx_react_ratef_t kernels[3]; } gkyl_cx_react_rate_kern_list; +typedef struct { + dg_cx_react_ratef_t kernels[3]; +} gkyl_cx_react_rate_kern_list; // CX reaction rate kernel list // // Serendipity basis kernels -// -GKYL_CU_D -static const gkyl_cx_react_rate_kern_list ser_cx_react_rate_kernels[] = { - { sigma_cx_1x_ser_p1, sigma_cx_1x_ser_p2 }, // 0 - { sigma_cx_2x_ser_p1, sigma_cx_2x_ser_p2 }, // 4 - { sigma_cx_3x_ser_p1, NULL }, // 5 +// +GKYL_CU_D static const gkyl_cx_react_rate_kern_list ser_cx_react_rate_kernels[] = { + {sigma_cx_1x_ser_p1, sigma_cx_1x_ser_p2}, // 0 + {sigma_cx_2x_ser_p1, sigma_cx_2x_ser_p2}, // 4 + {sigma_cx_3x_ser_p1, NULL} // 5 }; struct gkyl_dg_cx { struct gkyl_basis *cbasis; const struct gkyl_range *conf_rng; - + double a; // Fitting function coefficient. double b; // Fitting function coefficient. double vt_sq_ion_min; - double vt_sq_neut_min; - + double vt_sq_neut_min; + enum gkyl_ion_type type_ion; uint32_t flags; dg_cx_react_ratef_t react_rate; // pointer to reaction rate kernel struct gkyl_dg_cx *on_dev; // pointer to itself or device data - }; -GKYL_CU_D -static dg_cx_react_ratef_t -choose_kern(struct gkyl_basis cbasis) +GKYL_CU_D static dg_cx_react_ratef_t choose_kern(struct gkyl_basis cbasis) { int cdim = cbasis.ndim; int poly_order = cbasis.poly_order; enum gkyl_basis_type b_type = cbasis.b_type; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_cx_react_rate_kernels[cdim-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_cx_react_rate_kernels[cdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } return 0; } -static void -fit_param(enum gkyl_ion_type type_ion, double *a, double *b) +static void fit_param(enum gkyl_ion_type type_ion, double *a, double *b) { // These values are from E. Meier's PhD Thesis if (type_ion == GKYL_ION_H) { a[0] = 1.12e-18; b[0] = 7.15e-20; - } - else if (type_ion == GKYL_ION_D) { + } else if (type_ion == GKYL_ION_D) { a[0] = 1.09e-18; b[0] = 7.15e-20; - } - else if (type_ion == GKYL_ION_HE) { + } else if (type_ion == GKYL_ION_HE) { a[0] = 6.484e-19; b[0] = 4.350e-20; - } - else if (type_ion == GKYL_ION_NE) { + } else if (type_ion == GKYL_ION_NE) { a[0] = 7.95e-19; b[0] = 5.65e-20; } @@ -89,7 +85,7 @@ fit_param(enum gkyl_ion_type type_ion, double *a, double *b) * Create new charge exchange updater type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_dg_cx* gkyl_dg_cx_cu_dev_new(struct gkyl_dg_cx_inp *inp); +struct gkyl_dg_cx *gkyl_dg_cx_cu_dev_new(struct gkyl_dg_cx_inp *inp); /** * Compute CX reaction rate coefficient for use in neutral reactions @@ -105,7 +101,9 @@ struct gkyl_dg_cx* gkyl_dg_cx_cu_dev_new(struct gkyl_dg_cx_inp *inp); * @param coef_cx Output reaction rate coefficient * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) */ -void gkyl_dg_cx_coll_cu(const struct gkyl_dg_cx *up, - struct gkyl_array *maxwellian_moms_ion, struct gkyl_array *maxwellian_moms_neut, - struct gkyl_array *upar_b_i, struct gkyl_array *coef_cx, struct gkyl_array *cflrate); +void gkyl_dg_cx_coll_cu( + const struct gkyl_dg_cx *up, struct gkyl_array *maxwellian_moms_ion, + struct gkyl_array *maxwellian_moms_neut, struct gkyl_array *upar_b_i, struct gkyl_array *coef_cx, + struct gkyl_array *cflrate +); #endif diff --git a/gyrokinetic/zero/gkyl_dg_diffusion_gyrokinetic.h b/gyrokinetic/zero/gkyl_dg_diffusion_gyrokinetic.h index b34b800a9b..916d450f84 100644 --- a/gyrokinetic/zero/gkyl_dg_diffusion_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_dg_diffusion_gyrokinetic.h @@ -7,7 +7,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_diffusion_gyrokinetic_auxfields { +struct gkyl_dg_diffusion_gyrokinetic_auxfields { const struct gkyl_array *D; const struct gkyl_array *jacobgeo_inv; }; @@ -24,9 +24,10 @@ struct gkyl_dg_diffusion_gyrokinetic_auxfields { * @param use_gpu Whether to run on host or device. * @return Pointer to diffusion equation object */ -struct gkyl_dg_eqn* gkyl_dg_diffusion_gyrokinetic_new(const struct gkyl_basis *basis, - const struct gkyl_basis *cbasis, bool is_diff_const, const bool *diff_in_dir, - int diff_order, const struct gkyl_range *diff_range, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_diffusion_gyrokinetic_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, + const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range, bool use_gpu +); /** * Set the auxiliary fields (e.g. diffusion tensor D) needed in updating diffusion equation. @@ -34,7 +35,9 @@ struct gkyl_dg_eqn* gkyl_dg_diffusion_gyrokinetic_new(const struct gkyl_basis *b * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_dg_diffusion_gyrokinetic_set_auxfields(const struct gkyl_dg_eqn* eqn, struct gkyl_dg_diffusion_gyrokinetic_auxfields auxin); +void gkyl_dg_diffusion_gyrokinetic_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_gyrokinetic_auxfields auxin +); #ifdef GKYL_HAVE_CUDA @@ -44,6 +47,8 @@ void gkyl_dg_diffusion_gyrokinetic_set_auxfields(const struct gkyl_dg_eqn* eqn, * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_dg_diffusion_gyrokinetic_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_gyrokinetic_auxfields auxin); +void gkyl_dg_diffusion_gyrokinetic_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_gyrokinetic_auxfields auxin +); #endif diff --git a/gyrokinetic/zero/gkyl_dg_diffusion_gyrokinetic_priv.h b/gyrokinetic/zero/gkyl_dg_diffusion_gyrokinetic_priv.h index 3ed767bc54..e806d8b16e 100644 --- a/gyrokinetic/zero/gkyl_dg_diffusion_gyrokinetic_priv.h +++ b/gyrokinetic/zero/gkyl_dg_diffusion_gyrokinetic_priv.h @@ -7,33 +7,44 @@ // private header for use in diffusion DG equation object creation // functions -static inline int diffdirs_linidx(const bool *isdirdiff, int cdim) { +static inline int diffdirs_linidx(const bool *isdirdiff, int cdim) +{ // Compute the linear index into the array of volume kernels (one // kernel for each combination of diffusive directions). bool diff_in_dir[GKYL_MAX_CDIM]; - if (isdirdiff) - for (int d=0; dconst_coeff? (const double *) gkyl_array_cfetch(diffusion->auxfields.D, 0) : (const double *) gkyl_array_cfetch(diffusion->auxfields.D, gkyl_range_idx(&diffusion->diff_range, idx)) +#define _cfD(idx) \ + diffusion->const_coeff ? (const double *)gkyl_array_cfetch(diffusion->auxfields.D, 0) : \ + (const double *)gkyl_array_cfetch( \ + diffusion->auxfields.D, gkyl_range_idx(&diffusion->diff_range, idx) \ + ) -#define _cfJacInv(idx) (const double *) gkyl_array_cfetch(diffusion->auxfields.jacobgeo_inv, gkyl_range_idx(&diffusion->diff_range, idx)) +#define _cfJacInv(idx) \ + (const double *)gkyl_array_cfetch( \ + diffusion->auxfields.jacobgeo_inv, gkyl_range_idx(&diffusion->diff_range, idx) \ + ) // for use in kernel tables -typedef struct { vol_termf_t kernels[7]; } gkyl_dg_diffusion_gyrokinetic_vol_kern_list_diffdir; -typedef struct { gkyl_dg_diffusion_gyrokinetic_vol_kern_list_diffdir list[2]; } gkyl_dg_diffusion_gyrokinetic_vol_kern_list_polyOrder; -typedef struct { gkyl_dg_diffusion_gyrokinetic_vol_kern_list_polyOrder list[3]; } gkyl_dg_diffusion_gyrokinetic_vol_kern_list; +typedef struct { + vol_termf_t kernels[7]; +} gkyl_dg_diffusion_gyrokinetic_vol_kern_list_diffdir; +typedef struct { + gkyl_dg_diffusion_gyrokinetic_vol_kern_list_diffdir list[2]; +} gkyl_dg_diffusion_gyrokinetic_vol_kern_list_polyOrder; +typedef struct { + gkyl_dg_diffusion_gyrokinetic_vol_kern_list_polyOrder list[3]; +} gkyl_dg_diffusion_gyrokinetic_vol_kern_list; // for use in kernel tables -typedef struct { diffusion_surf_t kernels[2]; } gkyl_dg_diffusion_gyrokinetic_surf_kernels_polyOrder; -typedef struct { gkyl_dg_diffusion_gyrokinetic_surf_kernels_polyOrder list[6]; } gkyl_dg_diffusion_gyrokinetic_surf_kern_list; +typedef struct { + diffusion_surf_t kernels[2]; +} gkyl_dg_diffusion_gyrokinetic_surf_kernels_polyOrder; +typedef struct { + gkyl_dg_diffusion_gyrokinetic_surf_kernels_polyOrder list[6]; +} gkyl_dg_diffusion_gyrokinetic_surf_kern_list; -typedef struct { diffusion_boundary_surf_t kernels[2]; } gkyl_dg_diffusion_gyrokinetic_boundary_surf_kernels_polyOrder; -typedef struct { gkyl_dg_diffusion_gyrokinetic_boundary_surf_kernels_polyOrder list[6]; } gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list; +typedef struct { + diffusion_boundary_surf_t kernels[2]; +} gkyl_dg_diffusion_gyrokinetic_boundary_surf_kernels_polyOrder; +typedef struct { + gkyl_dg_diffusion_gyrokinetic_boundary_surf_kernels_polyOrder list[6]; +} gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list; // ............... Homogeneous (constant) diffusion coefficient ............... // @@ -69,678 +101,1010 @@ typedef struct { gkyl_dg_diffusion_gyrokinetic_boundary_surf_kernels_polyOrder l // Need to be separated like this for GPU build // 1x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // 1x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_1x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_1x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_1x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_1x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_1x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_1x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_1x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_1x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // 1x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_1x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_1x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order6_vol_1x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order6_vol_1x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // 2x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // 2x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // 2x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // 3x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // 3x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // 3x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // Volume kernel list. -GKYL_CU_D -static const gkyl_dg_diffusion_gyrokinetic_vol_kern_list ser_vol_kernels_constcoeff[] = { - // 1x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {ker_dg_diffusion_gyrokinetic_order4_vol_1x_ser_p1_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_gyrokinetic_order4_vol_1x_ser_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_gyrokinetic_order6_vol_1x_ser_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 2x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_vol_kern_list + ser_vol_kernels_constcoeff[] = + { // 1x + { + .list = + {// 2nd order diffusion. + {.list = + {{ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_constcoeff_diffdirsx, NULL, NULL, + NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_constcoeff_diffdirsx, NULL, NULL, + NULL, NULL, NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{ker_dg_diffusion_gyrokinetic_order4_vol_1x_ser_p1_constcoeff_diffdirsx, NULL, NULL, NULL, NULL, NULL, NULL}, {ker_dg_diffusion_gyrokinetic_order4_vol_1x_ser_p2_constcoeff_diffdirsx, NULL, NULL, NULL, NULL, NULL, NULL}} + }, + // 6th order diffusion. + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {ker_dg_diffusion_gyrokinetic_order6_vol_1x_ser_p2_constcoeff_diffdirsx, NULL, NULL, NULL, NULL, NULL, NULL}} + } + } }, - // 4th order diffusion. - {.list={ - {ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, + // 2x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_constcoeff_diffdirsxy, NULL, + NULL, NULL, NULL}, + {ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_constcoeff_diffdirsxy, NULL, + NULL, NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p1_constcoeff_diffdirsxy, NULL, + NULL, NULL, NULL}, + {ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order4_vol_2x_ser_p2_constcoeff_diffdirsxy, NULL, + NULL, NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsxy, NULL, + NULL, NULL, NULL}}} + } }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order6_vol_2x_ser_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 3x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxy,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsyz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz}, - {ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxy,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsyz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz},}, - }, - // 4th order diffusion. - {.list={ - {ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxy,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsz,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxz,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsyz,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz}, - {ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxy,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsz,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxz,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsyz,ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxy,ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsz,ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxz,ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsyz,ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz},}, - }, - }, - }, + // 3x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxy, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsyz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz}, + {ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz}}}, + // 4th order diffusion. + {.list = + {{ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxy, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsz, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxz, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsyz, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz}, + {ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsz, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_gyrokinetic_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsz, + ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_gyrokinetic_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz}}} + } + } }; // Surface kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list ser_gyrokinetic_surfx_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { dg_diffusion_gyrokinetic_order2_surfx_1x1v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_surfx_1x1v_ser_p2_constcoeff }, - { dg_diffusion_gyrokinetic_order2_surfx_1x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_surfx_1x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_surfx_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_surfx_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_surfx_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_surfx_3x2v_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { dg_diffusion_gyrokinetic_order4_surfx_1x1v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_surfx_1x1v_ser_p2_constcoeff }, - { dg_diffusion_gyrokinetic_order4_surfx_1x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_surfx_1x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_surfx_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_surfx_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_surfx_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_surfx_3x2v_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, dg_diffusion_gyrokinetic_order6_surfx_1x1v_ser_p2_constcoeff }, - { NULL, dg_diffusion_gyrokinetic_order6_surfx_1x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_surfx_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_surfx_3x2v_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list + ser_gyrokinetic_surfx_kernels_constcoeff[] = { // 2nd order diffusion. + {.list = + {{dg_diffusion_gyrokinetic_order2_surfx_1x1v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_surfx_1x1v_ser_p2_constcoeff}, + {dg_diffusion_gyrokinetic_order2_surfx_1x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_surfx_1x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_surfx_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_surfx_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_surfx_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_surfx_3x2v_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{dg_diffusion_gyrokinetic_order4_surfx_1x1v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_surfx_1x1v_ser_p2_constcoeff}, + {dg_diffusion_gyrokinetic_order4_surfx_1x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_surfx_1x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_surfx_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_surfx_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_surfx_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_surfx_3x2v_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, dg_diffusion_gyrokinetic_order6_surfx_1x1v_ser_p2_constcoeff}, + {NULL, dg_diffusion_gyrokinetic_order6_surfx_1x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_surfx_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_surfx_3x2v_ser_p2_constcoeff}}} }; // Surface kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list ser_gyrokinetic_surfy_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_surfy_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_surfy_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_surfy_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_surfy_3x2v_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_surfy_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_surfy_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_surfy_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_surfy_3x2v_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_surfy_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_surfy_3x2v_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list + ser_gyrokinetic_surfy_kernels_constcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_surfy_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_surfy_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_surfy_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_surfy_3x2v_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_surfy_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_surfy_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_surfy_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_surfy_3x2v_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_surfy_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_surfy_3x2v_ser_p2_constcoeff}}} }; // Surface kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list ser_gyrokinetic_surfz_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_surfz_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_surfz_3x2v_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_surfz_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_surfz_3x2v_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_surfz_3x2v_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list + ser_gyrokinetic_surfz_kernels_constcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_surfz_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_surfz_3x2v_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_surfz_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_surfz_3x2v_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_surfz_3x2v_ser_p2_constcoeff}}} }; // Boundary surface kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_surfx_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { dg_diffusion_gyrokinetic_order2_boundary_surfx_1x1v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfx_1x1v_ser_p2_constcoeff }, - { dg_diffusion_gyrokinetic_order2_boundary_surfx_1x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfx_1x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_surfx_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfx_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_surfx_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfx_3x2v_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { dg_diffusion_gyrokinetic_order4_boundary_surfx_1x1v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_surfx_1x1v_ser_p2_constcoeff }, - { dg_diffusion_gyrokinetic_order4_boundary_surfx_1x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_surfx_1x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_boundary_surfx_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_surfx_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_boundary_surfx_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_surfx_3x2v_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, dg_diffusion_gyrokinetic_order6_boundary_surfx_1x1v_ser_p2_constcoeff }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_surfx_1x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_surfx_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_surfx_3x2v_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_surfx_kernels_constcoeff[] = { // 2nd order diffusion. + {.list = + {{dg_diffusion_gyrokinetic_order2_boundary_surfx_1x1v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfx_1x1v_ser_p2_constcoeff}, + {dg_diffusion_gyrokinetic_order2_boundary_surfx_1x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfx_1x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_surfx_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfx_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_surfx_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfx_3x2v_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{dg_diffusion_gyrokinetic_order4_boundary_surfx_1x1v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_surfx_1x1v_ser_p2_constcoeff}, + {dg_diffusion_gyrokinetic_order4_boundary_surfx_1x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_surfx_1x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_boundary_surfx_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_surfx_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_boundary_surfx_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_surfx_3x2v_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, dg_diffusion_gyrokinetic_order6_boundary_surfx_1x1v_ser_p2_constcoeff}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_surfx_1x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_surfx_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_surfx_3x2v_ser_p2_constcoeff}}} }; // Boundary surface kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_surfy_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_surfy_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfy_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_surfy_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfy_3x2v_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_boundary_surfy_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_surfy_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_boundary_surfy_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_surfy_3x2v_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_surfy_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_surfy_3x2v_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_surfy_kernels_constcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_surfy_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfy_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_surfy_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfy_3x2v_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_boundary_surfy_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_surfy_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_boundary_surfy_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_surfy_3x2v_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_surfy_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_surfy_3x2v_ser_p2_constcoeff}}} }; // Boundary surface kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_surfz_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_surfz_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfz_3x2v_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_boundary_surfz_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_surfz_3x2v_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_surfz_3x2v_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_surfz_kernels_constcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_surfz_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfz_3x2v_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_boundary_surfz_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_surfz_3x2v_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_surfz_3x2v_ser_p2_constcoeff}}} }; // Boundary diagnostic kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_diagx_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { dg_diffusion_gyrokinetic_order2_boundary_diagx_1x1v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagx_1x1v_ser_p2_constcoeff }, - { dg_diffusion_gyrokinetic_order2_boundary_diagx_1x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagx_1x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_diagx_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagx_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_diagx_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagx_3x2v_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { dg_diffusion_gyrokinetic_order4_boundary_diagx_1x1v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_diagx_1x1v_ser_p2_constcoeff }, - { dg_diffusion_gyrokinetic_order4_boundary_diagx_1x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_diagx_1x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_boundary_diagx_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_diagx_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_boundary_diagx_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_diagx_3x2v_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, dg_diffusion_gyrokinetic_order6_boundary_diagx_1x1v_ser_p2_constcoeff }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_diagx_1x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_diagx_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_diagx_3x2v_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_diagx_kernels_constcoeff[] = { // 2nd order diffusion. + {.list = + {{dg_diffusion_gyrokinetic_order2_boundary_diagx_1x1v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagx_1x1v_ser_p2_constcoeff}, + {dg_diffusion_gyrokinetic_order2_boundary_diagx_1x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagx_1x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_diagx_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagx_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_diagx_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagx_3x2v_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{dg_diffusion_gyrokinetic_order4_boundary_diagx_1x1v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_diagx_1x1v_ser_p2_constcoeff}, + {dg_diffusion_gyrokinetic_order4_boundary_diagx_1x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_diagx_1x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_boundary_diagx_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_diagx_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_boundary_diagx_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_diagx_3x2v_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, dg_diffusion_gyrokinetic_order6_boundary_diagx_1x1v_ser_p2_constcoeff}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_diagx_1x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_diagx_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_diagx_3x2v_ser_p2_constcoeff}}} }; // Boundary diagnostic kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_diagy_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_diagy_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagy_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_diagy_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagy_3x2v_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_boundary_diagy_2x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_diagy_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_boundary_diagy_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_diagy_3x2v_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_diagy_2x2v_ser_p2_constcoeff }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_diagy_3x2v_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_diagy_kernels_constcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_diagy_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagy_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_diagy_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagy_3x2v_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_boundary_diagy_2x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_diagy_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_boundary_diagy_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_diagy_3x2v_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_diagy_2x2v_ser_p2_constcoeff}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_diagy_3x2v_ser_p2_constcoeff}}} }; // Boundary diagnostic kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_diagz_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_diagz_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagz_3x2v_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order4_boundary_diagz_3x2v_ser_p1_constcoeff, dg_diffusion_gyrokinetic_order4_boundary_diagz_3x2v_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_gyrokinetic_order6_boundary_diagz_3x2v_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_diagz_kernels_constcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_diagz_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagz_3x2v_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order4_boundary_diagz_3x2v_ser_p1_constcoeff, + dg_diffusion_gyrokinetic_order4_boundary_diagz_3x2v_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_gyrokinetic_order6_boundary_diagz_3x2v_ser_p2_constcoeff}}} }; // ............... Inhomogeneous (spatially varying) diffusion coefficient ............... // @@ -749,524 +1113,546 @@ GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser // Need to be separated like this for GPU build // 1x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_varcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_varcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_varcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // 2x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // 3x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxy(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz(xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsx( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + return dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz( + xc, dx, _cfD(idx), _cfJacInv(idx), qIn, qRhsOut + ); } // Volume kernel list. -GKYL_CU_D -static const gkyl_dg_diffusion_gyrokinetic_vol_kern_list ser_vol_kernels_varcoeff[] = { - // 1x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_varcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_varcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_vol_kern_list + ser_vol_kernels_varcoeff[] = + { // 1x + { + .list = + {// 2nd order diffusion. + {.list = + {{ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p1_varcoeff_diffdirsx, NULL, NULL, + NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_gyrokinetic_order2_vol_1x_ser_p2_varcoeff_diffdirsx, NULL, NULL, + NULL, NULL, NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL, NULL}} + }, + // 6th order diffusion. + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL, NULL}} + } + } }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, + // 2x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}, + {ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}} + } }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 2x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p1_varcoeff_diffdirsxy,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order2_vol_2x_ser_p2_varcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 3x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxy,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsyz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz}, - {ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsx,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsy,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxy,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsyz,ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz},}, - }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, + // 3x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxy, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsyz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz}, + {ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsx, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsy, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxy, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsyz, + ker_dg_diffusion_gyrokinetic_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}} + } + } }; // Surface kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list ser_gyrokinetic_surfx_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { dg_diffusion_gyrokinetic_order2_surfx_1x1v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_surfx_1x1v_ser_p2_varcoeff }, - { dg_diffusion_gyrokinetic_order2_surfx_1x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_surfx_1x2v_ser_p2_varcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_surfx_2x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_surfx_2x2v_ser_p2_varcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_surfx_3x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_surfx_3x2v_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list + ser_gyrokinetic_surfx_kernels_varcoeff[] = { // 2nd order diffusion. + {.list = + {{dg_diffusion_gyrokinetic_order2_surfx_1x1v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_surfx_1x1v_ser_p2_varcoeff}, + {dg_diffusion_gyrokinetic_order2_surfx_1x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_surfx_1x2v_ser_p2_varcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_surfx_2x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_surfx_2x2v_ser_p2_varcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_surfx_3x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_surfx_3x2v_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Surface kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list ser_gyrokinetic_surfy_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_surfy_2x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_surfy_2x2v_ser_p2_varcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_surfy_3x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_surfy_3x2v_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list + ser_gyrokinetic_surfy_kernels_varcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_surfy_2x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_surfy_2x2v_ser_p2_varcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_surfy_3x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_surfy_3x2v_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Surface kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list ser_gyrokinetic_surfz_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_surfz_3x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_surfz_3x2v_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_surf_kern_list + ser_gyrokinetic_surfz_kernels_varcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_surfz_3x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_surfz_3x2v_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_surfx_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { dg_diffusion_gyrokinetic_order2_boundary_surfx_1x1v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfx_1x1v_ser_p2_varcoeff }, - { dg_diffusion_gyrokinetic_order2_boundary_surfx_1x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfx_1x2v_ser_p2_varcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_surfx_2x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfx_2x2v_ser_p2_varcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_surfx_3x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfx_3x2v_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_surfx_kernels_varcoeff[] = { // 2nd order diffusion. + {.list = + {{dg_diffusion_gyrokinetic_order2_boundary_surfx_1x1v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfx_1x1v_ser_p2_varcoeff}, + {dg_diffusion_gyrokinetic_order2_boundary_surfx_1x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfx_1x2v_ser_p2_varcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_surfx_2x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfx_2x2v_ser_p2_varcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_surfx_3x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfx_3x2v_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_surfy_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_surfy_2x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfy_2x2v_ser_p2_varcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_surfy_3x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfy_3x2v_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_surfy_kernels_varcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_surfy_2x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfy_2x2v_ser_p2_varcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_surfy_3x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfy_3x2v_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_surfz_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_surfz_3x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_surfz_3x2v_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_surfz_kernels_varcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_surfz_3x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_surfz_3x2v_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary diagnostic kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_diagx_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { dg_diffusion_gyrokinetic_order2_boundary_diagx_1x1v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagx_1x1v_ser_p2_varcoeff }, - { dg_diffusion_gyrokinetic_order2_boundary_diagx_1x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagx_1x2v_ser_p2_varcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_diagx_2x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagx_2x2v_ser_p2_varcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_diagx_3x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagx_3x2v_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_diagx_kernels_varcoeff[] = { // 2nd order diffusion. + {.list = + {{dg_diffusion_gyrokinetic_order2_boundary_diagx_1x1v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagx_1x1v_ser_p2_varcoeff}, + {dg_diffusion_gyrokinetic_order2_boundary_diagx_1x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagx_1x2v_ser_p2_varcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_diagx_2x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagx_2x2v_ser_p2_varcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_diagx_3x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagx_3x2v_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary diagnostic kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_diagy_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_diagy_2x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagy_2x2v_ser_p2_varcoeff }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_diagy_3x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagy_3x2v_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_diagy_kernels_varcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_diagy_2x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagy_2x2v_ser_p2_varcoeff}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_diagy_3x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagy_3x2v_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary diagnostic kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list ser_gyrokinetic_boundary_diagz_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_gyrokinetic_order2_boundary_diagz_3x2v_ser_p1_varcoeff, dg_diffusion_gyrokinetic_order2_boundary_diagz_3x2v_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_gyrokinetic_boundary_surf_kern_list + ser_gyrokinetic_boundary_diagz_kernels_varcoeff[] = { // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_gyrokinetic_order2_boundary_diagz_3x2v_ser_p1_varcoeff, + dg_diffusion_gyrokinetic_order2_boundary_diagz_3x2v_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; -#define SURFKERIDX(cdim,vdim) (cdim-1+vdim-1)*2-(vdim-1) +#define SURFKERIDX(cdim, vdim) (cdim - 1 + vdim - 1) * 2 - (vdim - 1) // Macro for choosing volume and surface kernels. -#define CKVOL(lst,cdim,diff_order,poly_order,diffdir_linidx) lst[cdim-1].list[diff_order/2-1].list[poly_order-1].kernels[diffdir_linidx] -#define CKSURF(lst,diff_order,cdim,vdim,poly_order) lst[diff_order/2-1].list[SURFKERIDX(cdim,vdim)].kernels[poly_order-1] +#define CKVOL(lst, cdim, diff_order, poly_order, diffdir_linidx) \ + lst[cdim - 1].list[diff_order / 2 - 1].list[poly_order - 1].kernels[diffdir_linidx] +#define CKSURF(lst, diff_order, cdim, vdim, poly_order) \ + lst[diff_order / 2 - 1].list[SURFKERIDX(cdim, vdim)].kernels[poly_order - 1] -GKYL_CU_D static double surf(const struct gkyl_dg_eqn* eqn, int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, - double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); if (diffusion->diff_in_dir[dir]) { diffusion->surf[dir](xcC, dxC, _cfD(idxC), _cfJacInv(idxC), qInL, qInC, qInR, qRhsOut); } - return 0.; // CFL frequency computed in volume term. + return 0.; // CFL frequency computed in volume term. } -GKYL_CU_D static double boundary_surf(const struct gkyl_dg_eqn* eqn, int dir, - const double* xcEdge, const double* xcSkin, const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + if (diffusion->diff_in_dir[dir]) { - diffusion->boundary_surf[dir](xcSkin, dxSkin, _cfD(idxSkin), _cfJacInv(idxSkin), edge, qInEdge, qInSkin, qRhsOut); + diffusion->boundary_surf[dir]( + xcSkin, dxSkin, _cfD(idxSkin), _cfJacInv(idxSkin), edge, qInEdge, qInSkin, qRhsOut + ); } - return 0.; // CFL frequency computed in volume term. + return 0.; // CFL frequency computed in volume term. } -GKYL_CU_D static double boundary_diag(const struct gkyl_dg_eqn* eqn, int dir, - const double* xcEdge, const double* xcSkin, const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) -{ +GKYL_CU_D static double boundary_diag( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) +{ // This function is based on boundary_surf above, but notice we use Edge // where the boundary_surf used Skin, because we assume this kernel is called // in the ghost range (e.g. by the boundary_flux updater). - struct dg_diffusion_gyrokinetic* diffusion = container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); - + struct dg_diffusion_gyrokinetic *diffusion = + container_of(eqn, struct dg_diffusion_gyrokinetic, eqn); + if (diffusion->diff_in_dir[dir]) { - diffusion->boundary_diag[dir](xcEdge, dxEdge, _cfD(idxEdge), _cfJacInv(idxEdge), edge, qInSkin, qInEdge, qRhsOut); + diffusion->boundary_diag[dir]( + xcEdge, dxEdge, _cfD(idxEdge), _cfJacInv(idxEdge), edge, qInSkin, qInEdge, qRhsOut + ); } - return 0.; // CFL frequency computed in volume term. + return 0.; // CFL frequency computed in volume term. } #undef _cfD @@ -1277,7 +1663,7 @@ GKYL_CU_D static double boundary_diag(const struct gkyl_dg_eqn* eqn, int dir, * * @param ref Reference counter for constant diffusion equation */ -void gkyl_dg_diffusion_gyrokinetic_free(const struct gkyl_ref_count* ref); +void gkyl_dg_diffusion_gyrokinetic_free(const struct gkyl_ref_count *ref); #ifdef GKYL_HAVE_CUDA /** @@ -1291,7 +1677,8 @@ void gkyl_dg_diffusion_gyrokinetic_free(const struct gkyl_ref_count* ref); * @param diff_range Range object to index the diffusion coefficient. * @return Pointer to diffusion equation object */ -struct gkyl_dg_eqn* -gkyl_dg_diffusion_gyrokinetic_cu_dev_new(const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, - bool is_diff_const, const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range); +struct gkyl_dg_eqn *gkyl_dg_diffusion_gyrokinetic_cu_dev_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, + const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range +); #endif diff --git a/gyrokinetic/zero/gkyl_dg_gyrokinetic.h b/gyrokinetic/zero/gkyl_dg_gyrokinetic.h index 19648cb6d9..69174a277b 100644 --- a/gyrokinetic/zero/gkyl_dg_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_dg_gyrokinetic.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include @@ -32,11 +32,12 @@ struct gkyl_dg_gyrokinetic_auxfields { * @param use_gpu Boolean to determine if gyrokinetic equation object is on device * @return Pointer to Gyrokinetic equation object */ -struct gkyl_dg_eqn* gkyl_dg_gyrokinetic_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const double charge, const double mass, - enum gkyl_gk_collisionless_type collless_type, const struct gk_geometry *gk_geom, - const struct gkyl_velocity_map *vel_map, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_gyrokinetic_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const double charge, + const double mass, enum gkyl_gk_collisionless_type collless_type, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu +); /** * Set the auxiliary fields (e.g. EM fields) needed in computing @@ -45,6 +46,6 @@ struct gkyl_dg_eqn* gkyl_dg_gyrokinetic_new(const struct gkyl_basis *cbasis, con * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_gyrokinetic_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_auxfields auxin); - - +void gkyl_gyrokinetic_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_auxfields auxin +); diff --git a/gyrokinetic/zero/gkyl_dg_gyrokinetic_passive.h b/gyrokinetic/zero/gkyl_dg_gyrokinetic_passive.h index 2b119877c0..c82b0bacd7 100644 --- a/gyrokinetic/zero/gkyl_dg_gyrokinetic_passive.h +++ b/gyrokinetic/zero/gkyl_dg_gyrokinetic_passive.h @@ -11,7 +11,7 @@ // Auxiliary fields for the passive gyrokinetic DG equation. struct gkyl_dg_gyrokinetic_passive_auxfields { const struct gkyl_array *flux_surf; // Surface expansion of the passive phase-space flux. - const struct gkyl_array *speeds; // Conf-space passive advection speeds (all directions packed). + const struct gkyl_array *speeds; // Conf-space passive advection speeds (all directions packed). }; /** @@ -32,12 +32,12 @@ struct gkyl_dg_gyrokinetic_passive_auxfields { * @param use_gpu Boolean to determine if equation object is on device. * @return Pointer to passive gyrokinetic equation object. */ -struct gkyl_dg_eqn* -gkyl_dg_gyrokinetic_passive_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const double charge, const double mass, - const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, - bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_gyrokinetic_passive_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const double charge, + const double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, + bool use_gpu +); /** * Set the auxiliary fields for the passive gyrokinetic equation. @@ -45,5 +45,6 @@ gkyl_dg_gyrokinetic_passive_new(const struct gkyl_basis *cbasis, const struct gk * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_gyrokinetic_passive_set_auxfields(const struct gkyl_dg_eqn *eqn, - struct gkyl_dg_gyrokinetic_passive_auxfields auxin); +void gkyl_gyrokinetic_passive_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_passive_auxfields auxin +); diff --git a/gyrokinetic/zero/gkyl_dg_gyrokinetic_passive_priv.h b/gyrokinetic/zero/gkyl_dg_gyrokinetic_passive_priv.h index 7d18d7de27..dcf5a351a0 100644 --- a/gyrokinetic/zero/gkyl_dg_gyrokinetic_passive_priv.h +++ b/gyrokinetic/zero/gkyl_dg_gyrokinetic_passive_priv.h @@ -10,37 +10,48 @@ #include #include -typedef double (*dg_gyrokinetic_passive_surf_t)(const double *w, const double *dxv, - const double *vmap_prime_l, const double *vmap_prime_c, const double *vmap_prime_r, - const double *flux_surf_l, const double *flux_surf_r, double *GKYL_RESTRICT out); - -typedef double (*dg_gyrokinetic_passive_boundary_surf_t)(const double *w, const double *dxv, - const double *vmap_prime_edge, const double *vmap_prime_skin, - const double *flux_surf_edge, const double *flux_surf_skin, - const int edge, double *GKYL_RESTRICT out); +typedef double (*dg_gyrokinetic_passive_surf_t)( + const double *w, const double *dxv, const double *vmap_prime_l, const double *vmap_prime_c, + const double *vmap_prime_r, const double *flux_surf_l, const double *flux_surf_r, + double *GKYL_RESTRICT out +); + +typedef double (*dg_gyrokinetic_passive_boundary_surf_t)( + const double *w, const double *dxv, const double *vmap_prime_edge, const double *vmap_prime_skin, + const double *flux_surf_edge, const double *flux_surf_skin, const int edge, + double *GKYL_RESTRICT out +); // The cv_index_gkp[cd].vdim[vd] maps (cdim, vdim) to a kernel-list index. -static struct { int vdim[3]; } cv_index_gkp[] = { +static struct { + int vdim[3]; +} cv_index_gkp[] = { {-1, -1, -1}, // 0x makes no sense. - {-1, 0, 1}, // 1x kernel indices. - {-1, -1, 2}, // 2x kernel indices. - {-1, -1, 3}, // 3x kernel indices. + {-1, 0, 1}, // 1x kernel indices. + {-1, -1, 2}, // 2x kernel indices. + {-1, -1, 3} // 3x kernel indices. }; // For use in kernel tables. -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_gyrokinetic_passive_vol_kern_list; -typedef struct { dg_gyrokinetic_passive_surf_t kernels[3]; } gkyl_dg_gyrokinetic_passive_surf_kern_list; -typedef struct { dg_gyrokinetic_passive_boundary_surf_t kernels[3]; } gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_gyrokinetic_passive_vol_kern_list; +typedef struct { + dg_gyrokinetic_passive_surf_t kernels[3]; +} gkyl_dg_gyrokinetic_passive_surf_kern_list; +typedef struct { + dg_gyrokinetic_passive_boundary_surf_t kernels[3]; +} gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list; // Private equation struct. struct dg_gyrokinetic_passive { - struct gkyl_dg_eqn eqn; // Base object (must be first). - int cdim; // Config-space dimensions. - int pdim; // Phase-space dimensions. + struct gkyl_dg_eqn eqn; // Base object (must be first). + int cdim; // Config-space dimensions. + int pdim; // Phase-space dimensions. dg_gyrokinetic_passive_surf_t surf[GKYL_MAX_CDIM]; // Conf-space surface kernels. dg_gyrokinetic_passive_boundary_surf_t boundary_surf[GKYL_MAX_CDIM]; - struct gkyl_range conf_range; // Configuration space range. - struct gkyl_range phase_range; // Phase space range. + struct gkyl_range conf_range; // Configuration space range. + struct gkyl_range phase_range; // Phase space range. double charge, mass; const struct gk_geometry *gk_geom; const struct gkyl_velocity_map *vel_map; @@ -52,117 +63,116 @@ struct dg_gyrokinetic_passive { // function pointer in gkyl_dg_eqn. // -GKYL_CU_DH -static double -kernel_dg_gyrokinetic_passive_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, - const double *xc, const double *dx, const int *idx, - const double *qIn, double *GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_gyrokinetic_passive_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic_passive *gkp = container_of(eqn, struct dg_gyrokinetic_passive, eqn); int vel_idx[2]; - for (int d = gkp->cdim; d < gkp->pdim; d++) vel_idx[d-gkp->cdim] = idx[d]; + for (int d = gkp->cdim; d < gkp->pdim; d++) { + vel_idx[d - gkp->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&gkp->conf_range, idx); long vidx = gkyl_range_idx(&gkp->vel_map->local_vel, vel_idx); - return dg_gyrokinetic_passive_vol_1x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(gkp->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(gkp->vel_map->vmap_sq, vidx), - gkp->charge, gkp->mass, - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(gkp->auxfields.speeds, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.dualcurlbhatoverB, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.rtg33inv, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.bioverJB, cidx), - qIn, qRhsOut); + return dg_gyrokinetic_passive_vol_1x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(gkp->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(gkp->vel_map->vmap_sq, vidx), gkp->charge, gkp->mass, + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(gkp->auxfields.speeds, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.dualcurlbhatoverB, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.rtg33inv, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.bioverJB, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_dg_gyrokinetic_passive_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, - const double *xc, const double *dx, const int *idx, - const double *qIn, double *GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_gyrokinetic_passive_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic_passive *gkp = container_of(eqn, struct dg_gyrokinetic_passive, eqn); int vel_idx[2]; - for (int d = gkp->cdim; d < gkp->pdim; d++) vel_idx[d-gkp->cdim] = idx[d]; + for (int d = gkp->cdim; d < gkp->pdim; d++) { + vel_idx[d - gkp->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&gkp->conf_range, idx); long vidx = gkyl_range_idx(&gkp->vel_map->local_vel, vel_idx); - return dg_gyrokinetic_passive_vol_1x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(gkp->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(gkp->vel_map->vmap_sq, vidx), - gkp->charge, gkp->mass, - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(gkp->auxfields.speeds, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.dualcurlbhatoverB, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.rtg33inv, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.bioverJB, cidx), - qIn, qRhsOut); + return dg_gyrokinetic_passive_vol_1x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(gkp->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(gkp->vel_map->vmap_sq, vidx), gkp->charge, gkp->mass, + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(gkp->auxfields.speeds, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.dualcurlbhatoverB, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.rtg33inv, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.bioverJB, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_dg_gyrokinetic_passive_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, - const double *xc, const double *dx, const int *idx, - const double *qIn, double *GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_gyrokinetic_passive_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic_passive *gkp = container_of(eqn, struct dg_gyrokinetic_passive, eqn); int vel_idx[2]; - for (int d = gkp->cdim; d < gkp->pdim; d++) vel_idx[d-gkp->cdim] = idx[d]; + for (int d = gkp->cdim; d < gkp->pdim; d++) { + vel_idx[d - gkp->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&gkp->conf_range, idx); long vidx = gkyl_range_idx(&gkp->vel_map->local_vel, vel_idx); - return dg_gyrokinetic_passive_vol_2x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(gkp->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(gkp->vel_map->vmap_sq, vidx), - gkp->charge, gkp->mass, - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(gkp->auxfields.speeds, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.dualcurlbhatoverB, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.rtg33inv, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.bioverJB, cidx), - qIn, qRhsOut); + return dg_gyrokinetic_passive_vol_2x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(gkp->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(gkp->vel_map->vmap_sq, vidx), gkp->charge, gkp->mass, + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(gkp->auxfields.speeds, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.dualcurlbhatoverB, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.rtg33inv, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.bioverJB, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_dg_gyrokinetic_passive_vol_3x2v_ser_p1(const struct gkyl_dg_eqn *eqn, - const double *xc, const double *dx, const int *idx, - const double *qIn, double *GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_gyrokinetic_passive_vol_3x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic_passive *gkp = container_of(eqn, struct dg_gyrokinetic_passive, eqn); int vel_idx[2]; - for (int d = gkp->cdim; d < gkp->pdim; d++) vel_idx[d-gkp->cdim] = idx[d]; + for (int d = gkp->cdim; d < gkp->pdim; d++) { + vel_idx[d - gkp->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&gkp->conf_range, idx); long vidx = gkyl_range_idx(&gkp->vel_map->local_vel, vel_idx); - return dg_gyrokinetic_passive_vol_3x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(gkp->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(gkp->vel_map->vmap_sq, vidx), - gkp->charge, gkp->mass, - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(gkp->auxfields.speeds, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.dualcurlbhatoverB, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.rtg33inv, cidx), - (const double*) gkyl_array_cfetch(gkp->gk_geom->geo_int.bioverJB, cidx), - qIn, qRhsOut); + return dg_gyrokinetic_passive_vol_3x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(gkp->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(gkp->vel_map->vmap_sq, vidx), gkp->charge, gkp->mass, + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(gkp->auxfields.speeds, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.dualcurlbhatoverB, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.rtg33inv, cidx), + (const double *)gkyl_array_cfetch(gkp->gk_geom->geo_int.bioverJB, cidx), qIn, qRhsOut + ); } // Volume kernel list. -GKYL_CU_D -static const gkyl_dg_gyrokinetic_passive_vol_kern_list ser_passive_vol_kernels[] = { - { kernel_dg_gyrokinetic_passive_vol_1x1v_ser_p1, NULL }, - { kernel_dg_gyrokinetic_passive_vol_1x2v_ser_p1, NULL }, - { kernel_dg_gyrokinetic_passive_vol_2x2v_ser_p1, NULL }, - { kernel_dg_gyrokinetic_passive_vol_3x2v_ser_p1, NULL }, +GKYL_CU_D static const gkyl_dg_gyrokinetic_passive_vol_kern_list ser_passive_vol_kernels[] = { + {kernel_dg_gyrokinetic_passive_vol_1x1v_ser_p1, NULL}, + {kernel_dg_gyrokinetic_passive_vol_1x2v_ser_p1, NULL}, + {kernel_dg_gyrokinetic_passive_vol_2x2v_ser_p1, NULL}, + {kernel_dg_gyrokinetic_passive_vol_3x2v_ser_p1, NULL} }; // @@ -170,65 +180,59 @@ static const gkyl_dg_gyrokinetic_passive_vol_kern_list ser_passive_vol_kernels[] // // x-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_passive_surf_kern_list ser_passive_surf_x_kernels[] = { - { dg_gyrokinetic_passive_surfx_1x1v_ser_p1, NULL }, - { dg_gyrokinetic_passive_surfx_1x2v_ser_p1, NULL }, - { dg_gyrokinetic_passive_surfx_2x2v_ser_p1, NULL }, - { dg_gyrokinetic_passive_surfx_3x2v_ser_p1, NULL }, +GKYL_CU_D static const gkyl_dg_gyrokinetic_passive_surf_kern_list ser_passive_surf_x_kernels[] = { + {dg_gyrokinetic_passive_surfx_1x1v_ser_p1, NULL}, + {dg_gyrokinetic_passive_surfx_1x2v_ser_p1, NULL}, + {dg_gyrokinetic_passive_surfx_2x2v_ser_p1, NULL}, + {dg_gyrokinetic_passive_surfx_3x2v_ser_p1, NULL} }; // y-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_passive_surf_kern_list ser_passive_surf_y_kernels[] = { - { NULL, NULL }, - { NULL, NULL }, - { dg_gyrokinetic_passive_surfy_2x2v_ser_p1, NULL }, - { dg_gyrokinetic_passive_surfy_3x2v_ser_p1, NULL }, +GKYL_CU_D static const gkyl_dg_gyrokinetic_passive_surf_kern_list ser_passive_surf_y_kernels[] = { + {NULL, NULL}, + {NULL, NULL}, + {dg_gyrokinetic_passive_surfy_2x2v_ser_p1, NULL}, + {dg_gyrokinetic_passive_surfy_3x2v_ser_p1, NULL} }; // z-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_passive_surf_kern_list ser_passive_surf_z_kernels[] = { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_gyrokinetic_passive_surfz_3x2v_ser_p1, NULL }, -}; +GKYL_CU_D static const gkyl_dg_gyrokinetic_passive_surf_kern_list ser_passive_surf_z_kernels[] = + {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {dg_gyrokinetic_passive_surfz_3x2v_ser_p1, NULL}}; // // Boundary-surface kernel lists. // // x-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list ser_passive_boundary_surf_x_kernels[] = { - { dg_gyrokinetic_passive_boundary_surfx_1x1v_ser_p1, NULL }, - { dg_gyrokinetic_passive_boundary_surfx_1x2v_ser_p1, NULL }, - { dg_gyrokinetic_passive_boundary_surfx_2x2v_ser_p1, NULL }, - { dg_gyrokinetic_passive_boundary_surfx_3x2v_ser_p1, NULL }, +GKYL_CU_D static const gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list + ser_passive_boundary_surf_x_kernels[] = { + {dg_gyrokinetic_passive_boundary_surfx_1x1v_ser_p1, NULL}, + {dg_gyrokinetic_passive_boundary_surfx_1x2v_ser_p1, NULL}, + {dg_gyrokinetic_passive_boundary_surfx_2x2v_ser_p1, NULL}, + {dg_gyrokinetic_passive_boundary_surfx_3x2v_ser_p1, NULL} }; // y-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list ser_passive_boundary_surf_y_kernels[] = { - { NULL, NULL }, - { NULL, NULL }, - { dg_gyrokinetic_passive_boundary_surfy_2x2v_ser_p1, NULL }, - { dg_gyrokinetic_passive_boundary_surfy_3x2v_ser_p1, NULL }, +GKYL_CU_D static const gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list + ser_passive_boundary_surf_y_kernels[] = { + {NULL, NULL}, + {NULL, NULL}, + {dg_gyrokinetic_passive_boundary_surfy_2x2v_ser_p1, NULL}, + {dg_gyrokinetic_passive_boundary_surfy_3x2v_ser_p1, NULL} }; // z-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list ser_passive_boundary_surf_z_kernels[] = { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_gyrokinetic_passive_boundary_surfz_3x2v_ser_p1, NULL }, +GKYL_CU_D static const gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list + ser_passive_boundary_surf_z_kernels[] = { + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_gyrokinetic_passive_boundary_surfz_3x2v_ser_p1, NULL} }; // Macro to select a kernel from a list. -#define CK_PASSIVE(lst,cdim,vd,poly_order) lst[cv_index_gkp[cdim].vdim[vd]].kernels[poly_order-1] +#define CK_PASSIVE(lst, cdim, vd, poly_order) \ + lst[cv_index_gkp[cdim].vdim[vd]].kernels[poly_order - 1] /** * Free passive gyrokinetic equation object. @@ -236,15 +240,12 @@ static const gkyl_dg_gyrokinetic_passive_boundary_surf_kern_list ser_passive_bou void gkyl_gyrokinetic_passive_free(const struct gkyl_ref_count *ref); // Surface dispatch: called by hyper_dg for each surface. -GKYL_CU_D -static double -surf_passive(const struct gkyl_dg_eqn *eqn, - int dir, - const double *xcL, const double *xcC, const double *xcR, - const double *dxL, const double *dxC, const double *dxR, - const int *idxL, const int *idxC, const int *idxR, - const double *qInL, const double *qInC, const double *qInR, - double *GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf_passive( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic_passive *gkp = container_of(eqn, struct dg_gyrokinetic_passive, eqn); @@ -252,9 +253,9 @@ surf_passive(const struct gkyl_dg_eqn *eqn, if (dir < gkp->cdim) { int vel_idxL[2], vel_idxC[2], vel_idxR[2]; for (int d = gkp->cdim; d < gkp->pdim; d++) { - vel_idxL[d-gkp->cdim] = idxL[d]; - vel_idxC[d-gkp->cdim] = idxC[d]; - vel_idxR[d-gkp->cdim] = idxR[d]; + vel_idxL[d - gkp->cdim] = idxL[d]; + vel_idxC[d - gkp->cdim] = idxC[d]; + vel_idxR[d - gkp->cdim] = idxR[d]; } long vidxL = gkyl_range_idx(&gkp->vel_map->local_vel, vel_idxL); long vidxC = gkyl_range_idx(&gkp->vel_map->local_vel, vel_idxC); @@ -263,35 +264,31 @@ surf_passive(const struct gkyl_dg_eqn *eqn, long pidxC = gkyl_range_idx(&gkp->phase_range, idxC); long pidxR = gkyl_range_idx(&gkp->phase_range, idxR); - return gkp->surf[dir](xcC, dxC, - (const double*) gkyl_array_cfetch(gkp->vel_map->vmap_prime, vidxL), - (const double*) gkyl_array_cfetch(gkp->vel_map->vmap_prime, vidxC), - (const double*) gkyl_array_cfetch(gkp->vel_map->vmap_prime, vidxR), - (const double*) gkyl_array_cfetch(gkp->auxfields.flux_surf, pidxC), - (const double*) gkyl_array_cfetch(gkp->auxfields.flux_surf, pidxR), - qRhsOut); + return gkp->surf[dir]( + xcC, dxC, (const double *)gkyl_array_cfetch(gkp->vel_map->vmap_prime, vidxL), + (const double *)gkyl_array_cfetch(gkp->vel_map->vmap_prime, vidxC), + (const double *)gkyl_array_cfetch(gkp->vel_map->vmap_prime, vidxR), + (const double *)gkyl_array_cfetch(gkp->auxfields.flux_surf, pidxC), + (const double *)gkyl_array_cfetch(gkp->auxfields.flux_surf, pidxR), qRhsOut + ); } return 0.0; } // Boundary-surface dispatch. -GKYL_CU_D -static double -boundary_surf_passive(const struct gkyl_dg_eqn *eqn, - int dir, - const double *xcEdge, const double *xcSkin, - const double *dxEdge, const double *dxSkin, - const int *idxEdge, const int *idxSkin, const int edge, - const double *qInEdge, const double *qInSkin, - double *GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf_passive( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic_passive *gkp = container_of(eqn, struct dg_gyrokinetic_passive, eqn); if (dir < gkp->cdim) { int vel_idxEdge[2], vel_idxSkin[2]; for (int d = gkp->cdim; d < gkp->pdim; d++) { - vel_idxEdge[d-gkp->cdim] = idxEdge[d]; - vel_idxSkin[d-gkp->cdim] = idxSkin[d]; + vel_idxEdge[d - gkp->cdim] = idxEdge[d]; + vel_idxSkin[d - gkp->cdim] = idxSkin[d]; } long vidxEdge = gkyl_range_idx(&gkp->vel_map->local_vel, vel_idxEdge); long vidxSkin = gkyl_range_idx(&gkp->vel_map->local_vel, vel_idxSkin); @@ -299,38 +296,37 @@ boundary_surf_passive(const struct gkyl_dg_eqn *eqn, long pidxEdge = gkyl_range_idx(&gkp->phase_range, idxEdge); long pidxSkin = gkyl_range_idx(&gkp->phase_range, idxSkin); - return gkp->boundary_surf[dir](xcSkin, dxSkin, - (const double *) gkyl_array_cfetch(gkp->vel_map->vmap_prime, vidxEdge), - (const double *) gkyl_array_cfetch(gkp->vel_map->vmap_prime, vidxSkin), - (const double *) gkyl_array_cfetch(gkp->auxfields.flux_surf, pidxEdge), - (const double *) gkyl_array_cfetch(gkp->auxfields.flux_surf, pidxSkin), - edge, qRhsOut); + return gkp->boundary_surf[dir]( + xcSkin, dxSkin, (const double *)gkyl_array_cfetch(gkp->vel_map->vmap_prime, vidxEdge), + (const double *)gkyl_array_cfetch(gkp->vel_map->vmap_prime, vidxSkin), + (const double *)gkyl_array_cfetch(gkp->auxfields.flux_surf, pidxEdge), + (const double *)gkyl_array_cfetch(gkp->auxfields.flux_surf, pidxSkin), edge, qRhsOut + ); } return 0.0; } // boundary_diag mirrors boundary_surf. -GKYL_CU_D -static double -boundary_diag_passive(const struct gkyl_dg_eqn *eqn, - int dir, - const double *xcEdge, const double *xcSkin, - const double *dxEdge, const double *dxSkin, - const int *idxEdge, const int *idxSkin, const int edge, - const double *qInEdge, const double *qInSkin, - double *GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_diag_passive( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { - return boundary_surf_passive(eqn, dir, xcEdge, xcSkin, dxEdge, dxSkin, - idxEdge, idxSkin, edge, qInEdge, qInSkin, qRhsOut); + return boundary_surf_passive( + eqn, dir, xcEdge, xcSkin, dxEdge, dxSkin, idxEdge, idxSkin, edge, qInEdge, qInSkin, qRhsOut + ); } #ifdef GKYL_HAVE_CUDA // GPU-only functions (defined in dg_gyrokinetic_passive_cu.cu). -struct gkyl_dg_eqn* gkyl_dg_gyrokinetic_passive_cu_dev_new(const struct gkyl_basis *cbasis, - const struct gkyl_basis *pbasis, const struct gkyl_range *conf_range, - const struct gkyl_range *phase_range, const double charge, const double mass, - const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map); - -void gkyl_gyrokinetic_passive_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, - struct gkyl_dg_gyrokinetic_passive_auxfields auxin); +struct gkyl_dg_eqn *gkyl_dg_gyrokinetic_passive_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const double charge, + const double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map +); + +void gkyl_gyrokinetic_passive_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_passive_auxfields auxin +); #endif diff --git a/gyrokinetic/zero/gkyl_dg_gyrokinetic_priv.h b/gyrokinetic/zero/gkyl_dg_gyrokinetic_priv.h index ae8f5660ce..60593d74a3 100644 --- a/gyrokinetic/zero/gkyl_dg_gyrokinetic_priv.h +++ b/gyrokinetic/zero/gkyl_dg_gyrokinetic_priv.h @@ -12,29 +12,39 @@ #include // Types for various kernels. -typedef double (*dg_gyrokinetic_surf_t)( const double *w, const double *dxv, - const double *vmap_prime_l, const double *vmap_prime_c, const double *vmap_prime_r, - const double *flux_surf_l, const double *flux_surf_r, double* GKYL_RESTRICT out -); - -typedef double (*dg_gyrokinetic_boundary_surf_t)(const double *w, const double *dxv, - const double *vmap_prime_edge, const double *vmap_prime_skin, - const double *flux_surf_edge, const double *flux_surf_skin, - const int edge, double* GKYL_RESTRICT out); +typedef double (*dg_gyrokinetic_surf_t)( + const double *w, const double *dxv, const double *vmap_prime_l, const double *vmap_prime_c, + const double *vmap_prime_r, const double *flux_surf_l, const double *flux_surf_r, + double *GKYL_RESTRICT out +); + +typedef double (*dg_gyrokinetic_boundary_surf_t)( + const double *w, const double *dxv, const double *vmap_prime_edge, const double *vmap_prime_skin, + const double *flux_surf_edge, const double *flux_surf_skin, const int edge, + double *GKYL_RESTRICT out +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below. -static struct { int vdim[3]; } cv_index[] = { +static struct { + int vdim[3]; +} cv_index[] = { {-1, -1, -1}, // 0x makes no sense. - {-1, 0, 1}, // 1x kernel indices. - {-1, -1, 2}, // 2x kernel indices. - {-1, -1, 3}, // 3x kernel indices. + {-1, 0, 1}, // 1x kernel indices. + {-1, -1, 2}, // 2x kernel indices. + {-1, -1, 3} // 3x kernel indices. }; // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_gyrokinetic_vol_kern_list; -typedef struct { dg_gyrokinetic_surf_t kernels[3]; } gkyl_dg_gyrokinetic_surf_kern_list; -typedef struct { dg_gyrokinetic_boundary_surf_t kernels[3]; } gkyl_dg_gyrokinetic_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_gyrokinetic_vol_kern_list; +typedef struct { + dg_gyrokinetic_surf_t kernels[3]; +} gkyl_dg_gyrokinetic_surf_kern_list; +typedef struct { + dg_gyrokinetic_boundary_surf_t kernels[3]; +} gkyl_dg_gyrokinetic_boundary_surf_kern_list; struct dg_gyrokinetic { struct gkyl_dg_eqn eqn; // Base object. @@ -55,117 +65,119 @@ struct dg_gyrokinetic { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_dg_gyrokinetic_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_gyrokinetic_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_gyrokinetic *gyrokinetic = container_of(eqn, struct dg_gyrokinetic, eqn); int vel_idx[2]; - for (int d=gyrokinetic->cdim; dpdim; d++) vel_idx[d-gyrokinetic->cdim] = idx[d]; + for (int d = gyrokinetic->cdim; d < gyrokinetic->pdim; d++) { + vel_idx[d - gyrokinetic->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&gyrokinetic->conf_range, idx); long vidx = gkyl_range_idx(&gyrokinetic->vel_map->local_vel, vel_idx); long pidx = gkyl_range_idx(&gyrokinetic->phase_range, idx); - return dg_gyrokinetic_vol_1x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), - gyrokinetic->charge, gyrokinetic->mass, - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), - qIn, qRhsOut); + return dg_gyrokinetic_vol_1x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), gyrokinetic->charge, + gyrokinetic->mass, (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_dg_gyrokinetic_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_gyrokinetic_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic *gyrokinetic = container_of(eqn, struct dg_gyrokinetic, eqn); int vel_idx[2]; - for (int d=gyrokinetic->cdim; dpdim; d++) vel_idx[d-gyrokinetic->cdim] = idx[d]; + for (int d = gyrokinetic->cdim; d < gyrokinetic->pdim; d++) { + vel_idx[d - gyrokinetic->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&gyrokinetic->conf_range, idx); long vidx = gkyl_range_idx(&gyrokinetic->vel_map->local_vel, vel_idx); long pidx = gkyl_range_idx(&gyrokinetic->phase_range, idx); - return dg_gyrokinetic_vol_1x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), - gyrokinetic->charge, gyrokinetic->mass, - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), - qIn, qRhsOut); + return dg_gyrokinetic_vol_1x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), gyrokinetic->charge, + gyrokinetic->mass, (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_dg_gyrokinetic_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_gyrokinetic_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic *gyrokinetic = container_of(eqn, struct dg_gyrokinetic, eqn); int vel_idx[2]; - for (int d=gyrokinetic->cdim; dpdim; d++) vel_idx[d-gyrokinetic->cdim] = idx[d]; + for (int d = gyrokinetic->cdim; d < gyrokinetic->pdim; d++) { + vel_idx[d - gyrokinetic->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&gyrokinetic->conf_range, idx); long vidx = gkyl_range_idx(&gyrokinetic->vel_map->local_vel, vel_idx); long pidx = gkyl_range_idx(&gyrokinetic->phase_range, idx); - return dg_gyrokinetic_vol_2x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), - gyrokinetic->charge, gyrokinetic->mass, - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), - qIn, qRhsOut); + return dg_gyrokinetic_vol_2x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), gyrokinetic->charge, + gyrokinetic->mass, (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_dg_gyrokinetic_vol_3x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_gyrokinetic_vol_3x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic *gyrokinetic = container_of(eqn, struct dg_gyrokinetic, eqn); int vel_idx[2]; - for (int d=gyrokinetic->cdim; dpdim; d++) vel_idx[d-gyrokinetic->cdim] = idx[d]; + for (int d = gyrokinetic->cdim; d < gyrokinetic->pdim; d++) { + vel_idx[d - gyrokinetic->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&gyrokinetic->conf_range, idx); long vidx = gkyl_range_idx(&gyrokinetic->vel_map->local_vel, vel_idx); long pidx = gkyl_range_idx(&gyrokinetic->phase_range, idx); - return dg_gyrokinetic_vol_3x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), - gyrokinetic->charge, gyrokinetic->mass, - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), - qIn, qRhsOut); + return dg_gyrokinetic_vol_3x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), gyrokinetic->charge, + gyrokinetic->mass, (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), qIn, qRhsOut + ); } // Volume kernel list. -GKYL_CU_D -static const gkyl_dg_gyrokinetic_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_gyrokinetic_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, kernel_dg_gyrokinetic_vol_1x1v_ser_p1, NULL }, // 0 - { NULL, kernel_dg_gyrokinetic_vol_1x2v_ser_p1, NULL }, // 1 + {NULL, kernel_dg_gyrokinetic_vol_1x1v_ser_p1, NULL}, // 0 + {NULL, kernel_dg_gyrokinetic_vol_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, kernel_dg_gyrokinetic_vol_2x2v_ser_p1, NULL }, // 2 + {NULL, kernel_dg_gyrokinetic_vol_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, kernel_dg_gyrokinetic_vol_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_dg_gyrokinetic_vol_3x2v_ser_p1, NULL} // 3 }; // @@ -173,169 +185,163 @@ static const gkyl_dg_gyrokinetic_vol_kern_list ser_vol_kernels[] = { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_dg_gyrokinetic_no_by_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_gyrokinetic_no_by_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic *gyrokinetic = container_of(eqn, struct dg_gyrokinetic, eqn); int vel_idx[2]; - for (int d=gyrokinetic->cdim; dpdim; d++) vel_idx[d-gyrokinetic->cdim] = idx[d]; + for (int d = gyrokinetic->cdim; d < gyrokinetic->pdim; d++) { + vel_idx[d - gyrokinetic->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&gyrokinetic->conf_range, idx); long vidx = gkyl_range_idx(&gyrokinetic->vel_map->local_vel, vel_idx); long pidx = gkyl_range_idx(&gyrokinetic->phase_range, idx); - return dg_gyrokinetic_no_by_vol_2x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), - gyrokinetic->charge, gyrokinetic->mass, - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), - qIn, qRhsOut); + return dg_gyrokinetic_no_by_vol_2x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), gyrokinetic->charge, + gyrokinetic->mass, (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_dg_gyrokinetic_no_by_vol_3x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_gyrokinetic_no_by_vol_3x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic *gyrokinetic = container_of(eqn, struct dg_gyrokinetic, eqn); - + int vel_idx[2]; - for (int d=gyrokinetic->cdim; dpdim; d++) vel_idx[d-gyrokinetic->cdim] = idx[d]; + for (int d = gyrokinetic->cdim; d < gyrokinetic->pdim; d++) { + vel_idx[d - gyrokinetic->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&gyrokinetic->conf_range, idx); long vidx = gkyl_range_idx(&gyrokinetic->vel_map->local_vel, vel_idx); long pidx = gkyl_range_idx(&gyrokinetic->phase_range, idx); - return dg_gyrokinetic_no_by_vol_3x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), - gyrokinetic->charge, gyrokinetic->mass, - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), - (const double*) gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), - qIn, qRhsOut); + return dg_gyrokinetic_no_by_vol_3x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap_sq, vidx), gyrokinetic->charge, + gyrokinetic->mass, (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->auxfields.phi, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.dualcurlbhatoverB, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.rtg33inv, cidx), + (const double *)gkyl_array_cfetch(gyrokinetic->gk_geom->geo_int.bioverJB, cidx), qIn, qRhsOut + ); } // Volume kernel list. -GKYL_CU_D -static const gkyl_dg_gyrokinetic_vol_kern_list ser_no_by_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_gyrokinetic_vol_kern_list ser_no_by_vol_kernels[] = { // 1x kernels - { NULL, kernel_dg_gyrokinetic_vol_1x1v_ser_p1, NULL }, // 0 - { NULL, kernel_dg_gyrokinetic_vol_1x2v_ser_p1, NULL }, // 1 + {NULL, kernel_dg_gyrokinetic_vol_1x1v_ser_p1, NULL}, // 0 + {NULL, kernel_dg_gyrokinetic_vol_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, kernel_dg_gyrokinetic_no_by_vol_2x2v_ser_p1, NULL }, // 2 + {NULL, kernel_dg_gyrokinetic_no_by_vol_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, kernel_dg_gyrokinetic_no_by_vol_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_dg_gyrokinetic_no_by_vol_3x2v_ser_p1, NULL} // 3 }; // // Serendipity surface kernels general geometry // // Surface kernel list: x-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_surf_kern_list ser_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_gyrokinetic_surf_kern_list ser_surf_x_kernels[] = { // 1x kernels - { NULL, dg_gyrokinetic_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, dg_gyrokinetic_surfx_1x2v_ser_p1, NULL }, // 1 + {NULL, dg_gyrokinetic_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, dg_gyrokinetic_surfx_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, dg_gyrokinetic_surfx_2x2v_ser_p1, NULL }, // 2 + {NULL, dg_gyrokinetic_surfx_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, dg_gyrokinetic_surfx_3x2v_ser_p1, NULL }, // 3 + {NULL, dg_gyrokinetic_surfx_3x2v_ser_p1, NULL} // 3 }; // Surface kernel list: y-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_surf_kern_list ser_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_gyrokinetic_surf_kern_list ser_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 // 2x kernels - { NULL, dg_gyrokinetic_surfy_2x2v_ser_p1, NULL }, // 2 + {NULL, dg_gyrokinetic_surfy_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, dg_gyrokinetic_surfy_3x2v_ser_p1, NULL }, // 3 + {NULL, dg_gyrokinetic_surfy_3x2v_ser_p1, NULL} // 3 }; // Surface kernel list: z-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_surf_kern_list ser_surf_z_kernels[] = { +GKYL_CU_D static const gkyl_dg_gyrokinetic_surf_kern_list ser_surf_z_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 // 2x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 2 // 3x kernels - { NULL, dg_gyrokinetic_surfz_3x2v_ser_p1, NULL }, // 3 + {NULL, dg_gyrokinetic_surfz_3x2v_ser_p1, NULL} // 3 }; // Acceleration surface kernel list: vpar-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_surf_kern_list ser_surf_vpar_kernels[] = { +GKYL_CU_D static const gkyl_dg_gyrokinetic_surf_kern_list ser_surf_vpar_kernels[] = { // 1x kernels - { NULL, dg_gyrokinetic_surfvpar_1x1v_ser_p1, NULL }, // 0 - { NULL, dg_gyrokinetic_surfvpar_1x2v_ser_p1, NULL }, // 1 + {NULL, dg_gyrokinetic_surfvpar_1x1v_ser_p1, NULL}, // 0 + {NULL, dg_gyrokinetic_surfvpar_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, dg_gyrokinetic_surfvpar_2x2v_ser_p1, NULL }, // 2 + {NULL, dg_gyrokinetic_surfvpar_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, dg_gyrokinetic_surfvpar_3x2v_ser_p1, NULL }, // 3 + {NULL, dg_gyrokinetic_surfvpar_3x2v_ser_p1, NULL} // 3 }; // Conf-space advection boundary surface kernel list: x-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_boundary_surf_kern_list ser_boundary_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_gyrokinetic_boundary_surf_kern_list ser_boundary_surf_x_kernels[] = { // 1x kernels - { NULL, dg_gyrokinetic_boundary_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, dg_gyrokinetic_boundary_surfx_1x2v_ser_p1, NULL }, // 1 + {NULL, dg_gyrokinetic_boundary_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, dg_gyrokinetic_boundary_surfx_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, dg_gyrokinetic_boundary_surfx_2x2v_ser_p1, NULL }, // 2 + {NULL, dg_gyrokinetic_boundary_surfx_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, dg_gyrokinetic_boundary_surfx_3x2v_ser_p1, NULL }, // 3 + {NULL, dg_gyrokinetic_boundary_surfx_3x2v_ser_p1, NULL} // 3 }; // Conf-space advection boundary surface kernel list: y-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_boundary_surf_kern_list ser_boundary_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_gyrokinetic_boundary_surf_kern_list ser_boundary_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 // 2x kernels - { NULL, dg_gyrokinetic_boundary_surfy_2x2v_ser_p1, NULL }, // 2 + {NULL, dg_gyrokinetic_boundary_surfy_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, dg_gyrokinetic_boundary_surfy_3x2v_ser_p1, NULL }, // 3 + {NULL, dg_gyrokinetic_boundary_surfy_3x2v_ser_p1, NULL} // 3 }; // Conf-space advection boundary surface kernel list: z-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_boundary_surf_kern_list ser_boundary_surf_z_kernels[] = { +GKYL_CU_D static const gkyl_dg_gyrokinetic_boundary_surf_kern_list ser_boundary_surf_z_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 // 2x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 2 // 3x kernels - { NULL, dg_gyrokinetic_boundary_surfz_3x2v_ser_p1, NULL }, // 3 + {NULL, dg_gyrokinetic_boundary_surfz_3x2v_ser_p1, NULL} // 3 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vpar-direction -GKYL_CU_D -static const gkyl_dg_gyrokinetic_boundary_surf_kern_list ser_boundary_surf_vpar_kernels[] = { - // 1x kernels - { NULL, dg_gyrokinetic_boundary_surfvpar_1x1v_ser_p1, NULL }, // 0 - { NULL, dg_gyrokinetic_boundary_surfvpar_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, dg_gyrokinetic_boundary_surfvpar_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, dg_gyrokinetic_boundary_surfvpar_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_gyrokinetic_boundary_surf_kern_list + ser_boundary_surf_vpar_kernels[] = { + // 1x kernels + {NULL, dg_gyrokinetic_boundary_surfvpar_1x1v_ser_p1, NULL}, // 0 + {NULL, dg_gyrokinetic_boundary_surfvpar_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, dg_gyrokinetic_boundary_surfvpar_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, dg_gyrokinetic_boundary_surfvpar_3x2v_ser_p1, NULL} // 3 }; // "Choose Kernel" based on cdim, vdim and polyorder -#define CK(lst,cdim,vd,poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] +#define CK(lst, cdim, vd, poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] /** * Free gyrokinetic eqn object. @@ -344,24 +350,22 @@ static const gkyl_dg_gyrokinetic_boundary_surf_kern_list ser_boundary_surf_vpar_ */ void gkyl_gyrokinetic_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic *gyrokinetic = container_of(eqn, struct dg_gyrokinetic, eqn); // Only in x,y,z,vpar directions. if (dir <= gyrokinetic->cdim) { int vel_idxL[2], vel_idxC[2], vel_idxR[2]; - for (int d=gyrokinetic->cdim; dpdim; d++) { - vel_idxL[d-gyrokinetic->cdim] = idxL[d]; - vel_idxC[d-gyrokinetic->cdim] = idxC[d]; - vel_idxR[d-gyrokinetic->cdim] = idxR[d]; + for (int d = gyrokinetic->cdim; d < gyrokinetic->pdim; d++) { + vel_idxL[d - gyrokinetic->cdim] = idxL[d]; + vel_idxC[d - gyrokinetic->cdim] = idxC[d]; + vel_idxR[d - gyrokinetic->cdim] = idxR[d]; } long vidxL = gkyl_range_idx(&gyrokinetic->vel_map->local_vel, vel_idxL); long vidxC = gkyl_range_idx(&gyrokinetic->vel_map->local_vel, vel_idxC); @@ -372,34 +376,31 @@ surf(const struct gkyl_dg_eqn *eqn, // and fetch alpha_surf in right cell for upper edge long pidxC = gkyl_range_idx(&gyrokinetic->phase_range, idxC); long pidxR = gkyl_range_idx(&gyrokinetic->phase_range, idxR); - return gyrokinetic->surf[dir](xcC, dxC, - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap_prime, vidxL), - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap_prime, vidxC), - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap_prime, vidxR), - (const double*) gkyl_array_cfetch(gyrokinetic->auxfields.flux_surf, pidxC), - (const double*) gkyl_array_cfetch(gyrokinetic->auxfields.flux_surf, pidxR), - qRhsOut); + return gyrokinetic->surf[dir]( + xcC, dxC, (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap_prime, vidxL), + (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap_prime, vidxC), + (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap_prime, vidxR), + (const double *)gkyl_array_cfetch(gyrokinetic->auxfields.flux_surf, pidxC), + (const double *)gkyl_array_cfetch(gyrokinetic->auxfields.flux_surf, pidxR), qRhsOut + ); } return 0.; } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_gyrokinetic *gyrokinetic = container_of(eqn, struct dg_gyrokinetic, eqn); // Only in x,y,z,vpar directions. if (dir <= gyrokinetic->cdim) { int vel_idxEdge[2], vel_idxSkin[2]; - for (int d=gyrokinetic->cdim; dpdim; d++) { - vel_idxEdge[d-gyrokinetic->cdim] = idxEdge[d]; - vel_idxSkin[d-gyrokinetic->cdim] = idxSkin[d]; + for (int d = gyrokinetic->cdim; d < gyrokinetic->pdim; d++) { + vel_idxEdge[d - gyrokinetic->cdim] = idxEdge[d]; + vel_idxSkin[d - gyrokinetic->cdim] = idxSkin[d]; } long vidxEdge = gkyl_range_idx(&gyrokinetic->vel_map->local_vel, vel_idxEdge); long vidxSkin = gkyl_range_idx(&gyrokinetic->vel_map->local_vel, vel_idxSkin); @@ -407,26 +408,25 @@ boundary_surf(const struct gkyl_dg_eqn *eqn, // Each cell owns the *lower* edge surface alpha long pidxEdge = gkyl_range_idx(&gyrokinetic->phase_range, idxEdge); long pidxSkin = gkyl_range_idx(&gyrokinetic->phase_range, idxSkin); - return gyrokinetic->boundary_surf[dir](xcSkin, dxSkin, - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap_prime, vidxEdge), - (const double*) gkyl_array_cfetch(gyrokinetic->vel_map->vmap_prime, vidxSkin), - (const double*) gkyl_array_cfetch(gyrokinetic->auxfields.flux_surf, pidxEdge), - (const double*) gkyl_array_cfetch(gyrokinetic->auxfields.flux_surf, pidxSkin), - edge, qRhsOut); + return gyrokinetic->boundary_surf[dir]( + xcSkin, dxSkin, (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap_prime, vidxEdge), + (const double *)gkyl_array_cfetch(gyrokinetic->vel_map->vmap_prime, vidxSkin), + (const double *)gkyl_array_cfetch(gyrokinetic->auxfields.flux_surf, pidxEdge), + (const double *)gkyl_array_cfetch(gyrokinetic->auxfields.flux_surf, pidxSkin), edge, qRhsOut + ); } return 0.; } -GKYL_CU_D -static double -boundary_diag(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_diag( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { - return boundary_surf(eqn, dir, xcEdge, xcSkin, dxEdge, dxSkin, idxEdge, idxSkin, edge, qInEdge, qInSkin, qRhsOut); + return boundary_surf( + eqn, dir, xcEdge, xcSkin, dxEdge, dxSkin, idxEdge, idxSkin, edge, qInEdge, qInSkin, qRhsOut + ); } #ifdef GKYL_HAVE_CUDA @@ -434,10 +434,12 @@ boundary_diag(const struct gkyl_dg_eqn *eqn, * Create new Gyrokinetic equation object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_dg_eqn* gkyl_dg_gyrokinetic_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const double charge, const double mass, enum gkyl_gk_collisionless_type collless_type, - const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map); +struct gkyl_dg_eqn *gkyl_dg_gyrokinetic_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const double charge, + const double mass, enum gkyl_gk_collisionless_type collless_type, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map +); /** * CUDA device function to set the auxiliary fields (e.g. geometry & EM fields) @@ -446,5 +448,7 @@ struct gkyl_dg_eqn* gkyl_dg_gyrokinetic_cu_dev_new(const struct gkyl_basis *cbas * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_gyrokinetic_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_auxfields auxin); +void gkyl_gyrokinetic_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_gyrokinetic_auxfields auxin +); #endif diff --git a/gyrokinetic/zero/gkyl_dg_iz.h b/gyrokinetic/zero/gkyl_dg_iz.h index 59f4a414e2..01c51c55a0 100644 --- a/gyrokinetic/zero/gkyl_dg_iz.h +++ b/gyrokinetic/zero/gkyl_dg_iz.h @@ -8,7 +8,7 @@ #include struct gkyl_dg_iz_inp { - struct gkyl_basis* cbasis; // Configuration-space basis-functions. + struct gkyl_basis *cbasis; // Configuration-space basis-functions. const struct gkyl_range *conf_rng; // Configuration-space range. enum gkyl_ion_type type_ion; // Enum for type of ion for ionization (H thru O, Ar). int charge_state; // Ion charge state. @@ -24,7 +24,7 @@ typedef struct gkyl_dg_iz gkyl_dg_iz; * @param gkyl_dg_iz_inp * @param use_gpu Boolean for whether struct is on host or device */ -struct gkyl_dg_iz* gkyl_dg_iz_new(struct gkyl_dg_iz_inp *inp, bool use_gpu); +struct gkyl_dg_iz *gkyl_dg_iz_new(struct gkyl_dg_iz_inp *inp, bool use_gpu); /** * Compute ionization collision term for use in neutral reactions. @@ -37,10 +37,12 @@ struct gkyl_dg_iz* gkyl_dg_iz_new(struct gkyl_dg_iz_inp *inp, bool use_gpu); * @param coef_iz Output reaction rate coefficient * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) */ -void gkyl_dg_iz_coll(const struct gkyl_dg_iz *up, const struct gkyl_array *maxwellian_moms_elc, - struct gkyl_array *vtSq_iz1, struct gkyl_array *vtSq_iz2, - struct gkyl_array *coef_iz, struct gkyl_array *cflrate); - +void gkyl_dg_iz_coll( + const struct gkyl_dg_iz *up, const struct gkyl_array *maxwellian_moms_elc, + struct gkyl_array *vtSq_iz1, struct gkyl_array *vtSq_iz2, struct gkyl_array *coef_iz, + struct gkyl_array *cflrate +); + /** * Delete updater. * diff --git a/gyrokinetic/zero/gkyl_dg_iz_priv.h b/gyrokinetic/zero/gkyl_dg_iz_priv.h index 3cb5181800..919c1f86ba 100644 --- a/gyrokinetic/zero/gkyl_dg_iz_priv.h +++ b/gyrokinetic/zero/gkyl_dg_iz_priv.h @@ -12,7 +12,7 @@ struct gkyl_dg_iz { const struct gkyl_range *conf_rng; // Configuration-space range bool use_gpu; - + double elem_charge; // elementary charge value double mass_elc; // mass of the electron @@ -39,7 +39,7 @@ struct gkyl_dg_iz { * Create new ionization updater type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_dg_iz* gkyl_dg_iz_cu_dev_new(struct gkyl_dg_iz_inp *inp); +struct gkyl_dg_iz *gkyl_dg_iz_cu_dev_new(struct gkyl_dg_iz_inp *inp); /** * Compute ionization collision term for use in neutral reactions. @@ -52,8 +52,9 @@ struct gkyl_dg_iz* gkyl_dg_iz_cu_dev_new(struct gkyl_dg_iz_inp *inp); * @param coef_iz Output reaction rate coefficient. * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]). */ -void gkyl_dg_iz_coll_cu(const struct gkyl_dg_iz *up, - const struct gkyl_array *maxwellian_moms_elc, - struct gkyl_array *vtSq_iz1, struct gkyl_array *vtSq_iz2, - struct gkyl_array *coef_iz, struct gkyl_array *cflrate); +void gkyl_dg_iz_coll_cu( + const struct gkyl_dg_iz *up, const struct gkyl_array *maxwellian_moms_elc, + struct gkyl_array *vtSq_iz1, struct gkyl_array *vtSq_iz2, struct gkyl_array *coef_iz, + struct gkyl_array *cflrate +); #endif diff --git a/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_diff.h b/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_diff.h index 5646d15c5f..048c422159 100644 --- a/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_diff.h +++ b/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_diff.h @@ -9,7 +9,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_lbo_gyrokinetic_diff_auxfields { +struct gkyl_dg_lbo_gyrokinetic_diff_auxfields { const struct gkyl_array *nuSum; const struct gkyl_array *nuPrimMomsSum; const struct gkyl_array *m2self; @@ -27,9 +27,11 @@ struct gkyl_dg_lbo_gyrokinetic_diff_auxfields { * @param vel_map Velocity space mapping object. * @return Pointer to LBO equation object */ -struct gkyl_dg_eqn* gkyl_dg_lbo_gyrokinetic_diff_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, double mass, const struct gk_geometry *gk_geom, - const struct gkyl_velocity_map *vel_map, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_lbo_gyrokinetic_diff_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu +); /** * Set auxiliary fields needed in updating the diffusion flux term. @@ -38,4 +40,6 @@ struct gkyl_dg_eqn* gkyl_dg_lbo_gyrokinetic_diff_new(const struct gkyl_basis* cb * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_lbo_gyrokinetic_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_diff_auxfields auxin); +void gkyl_lbo_gyrokinetic_diff_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_diff_auxfields auxin +); diff --git a/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_diff_priv.h b/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_diff_priv.h index e57d4c4c49..bfe5b99440 100644 --- a/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_diff_priv.h +++ b/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_diff_priv.h @@ -7,31 +7,42 @@ #include // Types for various kernels -typedef double (*lbo_gyrokinetic_diff_surf_t)(const double *dxv, - const double *vmapl, const double *vmapc, const double *vmapr, const double *vmap_prime, - const double *jacobvell, const double *jacobvelc, const double *jacobvelr, const double m_, - const double *bmag_inv, const double *nuSum, const double *nuPrimMomsSum, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); - -typedef double (*lbo_gyrokinetic_diff_boundary_surf_t)(const double *dxv, - const double *vmap_edge, const double *vmap_skin, const double *vmap_prime, - const double *jacobvel_edge, const double *jacobvel_skin, const double m_, - const double *bmag_inv, const double *nuSum, const double *nuPrimMomsSum, - const int edge, const double *fEdge, const double *fSkin, double* GKYL_RESTRICT out); +typedef double (*lbo_gyrokinetic_diff_surf_t)( + const double *dxv, const double *vmapl, const double *vmapc, const double *vmapr, + const double *vmap_prime, const double *jacobvell, const double *jacobvelc, + const double *jacobvelr, const double m_, const double *bmag_inv, const double *nuSum, + const double *nuPrimMomsSum, const double *fl, const double *fc, const double *fr, + double *GKYL_RESTRICT out +); + +typedef double (*lbo_gyrokinetic_diff_boundary_surf_t)( + const double *dxv, const double *vmap_edge, const double *vmap_skin, const double *vmap_prime, + const double *jacobvel_edge, const double *jacobvel_skin, const double m_, const double *bmag_inv, + const double *nuSum, const double *nuPrimMomsSum, const int edge, const double *fEdge, + const double *fSkin, double *GKYL_RESTRICT out +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below. -static struct { int vdim[3]; } cv_index[] = { +static struct { + int vdim[3]; +} cv_index[] = { {-1, -1, -1}, // 0x makes no sense - {-1, 0, 1}, // 1x kernel indices - {-1, -1, 2}, // 2x kernel indices - {-1, -1, 3}, // 3x kernel indices + {-1, 0, 1}, // 1x kernel indices + {-1, -1, 2}, // 2x kernel indices + {-1, -1, 3} // 3x kernel indices }; // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_lbo_gyrokinetic_diff_vol_kern_list; -typedef struct { lbo_gyrokinetic_diff_surf_t kernels[3]; } gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list; -typedef struct { lbo_gyrokinetic_diff_boundary_surf_t kernels[3]; } gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_lbo_gyrokinetic_diff_vol_kern_list; +typedef struct { + lbo_gyrokinetic_diff_surf_t kernels[3]; +} gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list; +typedef struct { + lbo_gyrokinetic_diff_boundary_surf_t kernels[3]; +} gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list; // "Choose Kernel" based on cdim, vdim and polyorder #define CK(lst, cdim, vd, poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] @@ -56,259 +67,265 @@ struct dg_lbo_gyrokinetic_diff { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_lbo_gyrokinetic_diff_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_gyrokinetic_diff_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_diff *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_diff, eqn); int vel_idx[2]; - for (int d=lbo->cdim; dpdim; d++) vel_idx[d-lbo->cdim] = idx[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idx[d - lbo->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&lbo->conf_range, idx); long vidx = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) { - return lbo_gyrokinetic_diff_vol_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && (nuVtSqSum_p[0] > 0.) && + (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && (m2self_p[0] > 0.)) { + return lbo_gyrokinetic_diff_vol_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, qIn, qRhsOut + ); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_gyrokinetic_diff_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_gyrokinetic_diff_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_diff *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_diff, eqn); int vel_idx[2]; - for (int d=lbo->cdim; dpdim; d++) vel_idx[d-lbo->cdim] = idx[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idx[d - lbo->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&lbo->conf_range, idx); long vidx = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) { - return lbo_gyrokinetic_diff_vol_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && (nuVtSqSum_p[0] > 0.) && + (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && (m2self_p[0] > 0.)) { + return lbo_gyrokinetic_diff_vol_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, qIn, qRhsOut + ); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_gyrokinetic_diff_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_gyrokinetic_diff_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_diff *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_diff, eqn); - + int vel_idx[2]; - for (int d=lbo->cdim; dpdim; d++) vel_idx[d-lbo->cdim] = idx[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idx[d - lbo->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&lbo->conf_range, idx); long vidx = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) { - return lbo_gyrokinetic_diff_vol_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && (nuVtSqSum_p[0] > 0.) && + (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && (m2self_p[0] > 0.)) { + return lbo_gyrokinetic_diff_vol_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, qIn, qRhsOut + ); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_gyrokinetic_diff_vol_3x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_gyrokinetic_diff_vol_3x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_diff *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_diff, eqn); int vel_idx[2]; - for (int d=lbo->cdim; dpdim; d++) vel_idx[d-lbo->cdim] = idx[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idx[d - lbo->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&lbo->conf_range, idx); long vidx = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) { - return lbo_gyrokinetic_diff_vol_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && (nuVtSqSum_p[0] > 0.) && + (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && (m2self_p[0] > 0.)) { + return lbo_gyrokinetic_diff_vol_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, qIn, qRhsOut + ); } else { return 0.; } } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_diff_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_diff_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, kernel_lbo_gyrokinetic_diff_vol_1x1v_ser_p1, NULL }, // 0 - { NULL, kernel_lbo_gyrokinetic_diff_vol_1x2v_ser_p1, NULL }, // 1 + {NULL, kernel_lbo_gyrokinetic_diff_vol_1x1v_ser_p1, NULL}, // 0 + {NULL, kernel_lbo_gyrokinetic_diff_vol_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, kernel_lbo_gyrokinetic_diff_vol_2x2v_ser_p1, NULL }, // 3 + {NULL, kernel_lbo_gyrokinetic_diff_vol_2x2v_ser_p1, NULL}, // 3 // 3x kernels - { NULL, kernel_lbo_gyrokinetic_diff_vol_3x2v_ser_p1, NULL }, // 4 + {NULL, kernel_lbo_gyrokinetic_diff_vol_3x2v_ser_p1, NULL} // 4 }; // Surface kernel list: vpar-direction -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list ser_surf_vpar_mapped_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list ser_surf_vpar_mapped_kernels[] = { // 1x kernels - { NULL, lbo_gyrokinetic_diff_mapped_surfvpar_1x1v_ser_p1, NULL }, // 0 - { NULL, lbo_gyrokinetic_diff_mapped_surfvpar_1x2v_ser_p1, NULL }, // 1 + {NULL, lbo_gyrokinetic_diff_mapped_surfvpar_1x1v_ser_p1, NULL}, // 0 + {NULL, lbo_gyrokinetic_diff_mapped_surfvpar_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, lbo_gyrokinetic_diff_mapped_surfvpar_2x2v_ser_p1, NULL }, // 2 + {NULL, lbo_gyrokinetic_diff_mapped_surfvpar_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, lbo_gyrokinetic_diff_mapped_surfvpar_3x2v_ser_p1, NULL }, // 3 + {NULL, lbo_gyrokinetic_diff_mapped_surfvpar_3x2v_ser_p1, NULL} // 3 }; -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list ser_surf_vpar_notmapped_kernels[] = { - // 1x kernels - { NULL, lbo_gyrokinetic_diff_notmapped_surfvpar_1x1v_ser_p1, NULL }, // 0 - { NULL, lbo_gyrokinetic_diff_notmapped_surfvpar_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, lbo_gyrokinetic_diff_notmapped_surfvpar_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, lbo_gyrokinetic_diff_notmapped_surfvpar_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list + ser_surf_vpar_notmapped_kernels[] = { + // 1x kernels + {NULL, lbo_gyrokinetic_diff_notmapped_surfvpar_1x1v_ser_p1, NULL}, // 0 + {NULL, lbo_gyrokinetic_diff_notmapped_surfvpar_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, lbo_gyrokinetic_diff_notmapped_surfvpar_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, lbo_gyrokinetic_diff_notmapped_surfvpar_3x2v_ser_p1, NULL} // 3 }; // Surface kernel list: mu-direction -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list ser_surf_mu_mapped_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list ser_surf_mu_mapped_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, lbo_gyrokinetic_diff_mapped_surfmu_1x2v_ser_p1, NULL }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, lbo_gyrokinetic_diff_mapped_surfmu_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, lbo_gyrokinetic_diff_mapped_surfmu_2x2v_ser_p1, NULL }, // 2 + {NULL, lbo_gyrokinetic_diff_mapped_surfmu_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, lbo_gyrokinetic_diff_mapped_surfmu_3x2v_ser_p1, NULL }, // 3 + {NULL, lbo_gyrokinetic_diff_mapped_surfmu_3x2v_ser_p1, NULL} // 3 }; -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list ser_surf_mu_notmapped_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, lbo_gyrokinetic_diff_notmapped_surfmu_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, lbo_gyrokinetic_diff_notmapped_surfmu_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, lbo_gyrokinetic_diff_notmapped_surfmu_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_diff_surf_kern_list ser_surf_mu_notmapped_kernels[] = + { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, lbo_gyrokinetic_diff_notmapped_surfmu_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, lbo_gyrokinetic_diff_notmapped_surfmu_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, lbo_gyrokinetic_diff_notmapped_surfmu_3x2v_ser_p1, NULL} // 3 }; // Boundary surface kernel (zero-flux BCs) list: vpar-direction -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list ser_boundary_surf_vpar_mapped_kernels[] = { - // 1x kernels - { NULL, lbo_gyrokinetic_diff_mapped_boundary_surfvpar_1x1v_ser_p1, NULL }, // 0 - { NULL, lbo_gyrokinetic_diff_mapped_boundary_surfvpar_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, lbo_gyrokinetic_diff_mapped_boundary_surfvpar_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, lbo_gyrokinetic_diff_mapped_boundary_surfvpar_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list + ser_boundary_surf_vpar_mapped_kernels[] = { + // 1x kernels + {NULL, lbo_gyrokinetic_diff_mapped_boundary_surfvpar_1x1v_ser_p1, NULL}, // 0 + {NULL, lbo_gyrokinetic_diff_mapped_boundary_surfvpar_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, lbo_gyrokinetic_diff_mapped_boundary_surfvpar_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, lbo_gyrokinetic_diff_mapped_boundary_surfvpar_3x2v_ser_p1, NULL} // 3 }; -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list ser_boundary_surf_vpar_notmapped_kernels[] = { - // 1x kernels - { NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfvpar_1x1v_ser_p1, NULL }, // 0 - { NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfvpar_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfvpar_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfvpar_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list + ser_boundary_surf_vpar_notmapped_kernels[] = { + // 1x kernels + {NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfvpar_1x1v_ser_p1, NULL}, // 0 + {NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfvpar_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfvpar_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfvpar_3x2v_ser_p1, NULL} // 3 }; // Constant nu boundary surface kernel (zero-flux BCs) list: mu-direction -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list ser_boundary_surf_mu_mapped_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, lbo_gyrokinetic_diff_mapped_boundary_surfmu_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, lbo_gyrokinetic_diff_mapped_boundary_surfmu_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, lbo_gyrokinetic_diff_mapped_boundary_surfmu_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list + ser_boundary_surf_mu_mapped_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, lbo_gyrokinetic_diff_mapped_boundary_surfmu_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, lbo_gyrokinetic_diff_mapped_boundary_surfmu_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, lbo_gyrokinetic_diff_mapped_boundary_surfmu_3x2v_ser_p1, NULL} // 3 }; -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list ser_boundary_surf_mu_notmapped_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfmu_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfmu_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfmu_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_diff_boundary_surf_kern_list + ser_boundary_surf_mu_notmapped_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfmu_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfmu_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, lbo_gyrokinetic_diff_notmapped_boundary_surfmu_3x2v_ser_p1, NULL} // 3 }; -void gkyl_lbo_gyrokinetic_diff_free(const struct gkyl_ref_count* ref); +void gkyl_lbo_gyrokinetic_diff_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_diff *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_diff, eqn); long cidx = gkyl_range_idx(&lbo->conf_range, idxC); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((dir >= lbo->cdim) && - (fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) - { + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((dir >= lbo->cdim) && (fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && + (nuVtSqSum_p[0] > 0.) && (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && + (m2self_p[0] > 0.)) { int vel_idxL[2], vel_idxC[2], vel_idxR[2]; - for (int d=lbo->cdim; dpdim; d++) { - vel_idxL[d-lbo->cdim] = idxL[d]; - vel_idxC[d-lbo->cdim] = idxC[d]; - vel_idxR[d-lbo->cdim] = idxR[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idxL[d - lbo->cdim] = idxL[d]; + vel_idxC[d - lbo->cdim] = idxC[d]; + vel_idxR[d - lbo->cdim] = idxR[d]; } long vidxL = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idxL); long vidxC = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idxC); @@ -318,46 +335,43 @@ surf(const struct gkyl_dg_eqn *eqn, long pidxC = gkyl_range_idx(&lbo->vel_map->local, idxC); long pidxR = gkyl_range_idx(&lbo->vel_map->local, idxR); - return lbo->surf[dir-lbo->cdim](dxC, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidxL), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidxC), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidxR), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxC), - (const double*) gkyl_array_cfetch(lbo->vel_map->jacobvel, pidxL), - (const double*) gkyl_array_cfetch(lbo->vel_map->jacobvel, pidxC), - (const double*) gkyl_array_cfetch(lbo->vel_map->jacobvel, pidxR), - lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut); + return lbo->surf[dir - lbo->cdim]( + dxC, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidxL), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidxC), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidxR), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxC), + (const double *)gkyl_array_cfetch(lbo->vel_map->jacobvel, pidxL), + (const double *)gkyl_array_cfetch(lbo->vel_map->jacobvel, pidxC), + (const double *)gkyl_array_cfetch(lbo->vel_map->jacobvel, pidxR), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut + ); } return 0.; } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_diff *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_diff, eqn); long cidx = gkyl_range_idx(&lbo->conf_range, idxSkin); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((dir >= lbo->cdim) && - (fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) - { + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((dir >= lbo->cdim) && (fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && + (nuVtSqSum_p[0] > 0.) && (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && + (m2self_p[0] > 0.)) { int vel_idxEdge[2], vel_idxSkin[2]; - for (int d=lbo->cdim; dpdim; d++) { - vel_idxEdge[d-lbo->cdim] = idxEdge[d]; - vel_idxSkin[d-lbo->cdim] = idxSkin[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idxEdge[d - lbo->cdim] = idxEdge[d]; + vel_idxSkin[d - lbo->cdim] = idxSkin[d]; } long vidxEdge = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idxEdge); long vidxSkin = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idxSkin); @@ -365,14 +379,15 @@ boundary_surf(const struct gkyl_dg_eqn *eqn, int dir, long pidxEdge = gkyl_range_idx(&lbo->vel_map->local, idxEdge); long pidxSkin = gkyl_range_idx(&lbo->vel_map->local, idxSkin); - return lbo->boundary_surf[dir-lbo->cdim](dxSkin, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidxEdge), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidxSkin), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxSkin), - (const double*) gkyl_array_cfetch(lbo->vel_map->jacobvel, pidxEdge), - (const double*) gkyl_array_cfetch(lbo->vel_map->jacobvel, pidxSkin), lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, edge, qInEdge, qInSkin, qRhsOut); + return lbo->boundary_surf[dir - lbo->cdim]( + dxSkin, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidxEdge), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidxSkin), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxSkin), + (const double *)gkyl_array_cfetch(lbo->vel_map->jacobvel, pidxEdge), + (const double *)gkyl_array_cfetch(lbo->vel_map->jacobvel, pidxSkin), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, edge, qInEdge, qInSkin, qRhsOut + ); } return 0.; } @@ -382,14 +397,17 @@ boundary_surf(const struct gkyl_dg_eqn *eqn, int dir, /** * Create a new LBO equation object that lives on NV-GPU */ -struct gkyl_dg_eqn* gkyl_dg_lbo_gyrokinetic_diff_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map); +struct gkyl_dg_eqn *gkyl_dg_lbo_gyrokinetic_diff_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map +); /** * CUDA device function to set auxiliary fields needed in updating the diffusion flux term. */ -void gkyl_lbo_gyrokinetic_diff_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_diff_auxfields auxin); +void gkyl_lbo_gyrokinetic_diff_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_diff_auxfields auxin +); #endif - diff --git a/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_drag.h b/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_drag.h index daa29e4159..7ebe34364f 100644 --- a/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_drag.h +++ b/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_drag.h @@ -9,7 +9,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_lbo_gyrokinetic_drag_auxfields { +struct gkyl_dg_lbo_gyrokinetic_drag_auxfields { const struct gkyl_array *nuSum; const struct gkyl_array *nuPrimMomsSum; const struct gkyl_array *m2self; @@ -27,10 +27,11 @@ struct gkyl_dg_lbo_gyrokinetic_drag_auxfields { * @param vel_map Velocity space mapping object. * @return Pointer to LBO equation object */ -struct gkyl_dg_eqn* gkyl_dg_lbo_gyrokinetic_drag_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, - bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_lbo_gyrokinetic_drag_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu +); /** * Set auxiliary fields needed in updating the drag flux term. @@ -39,4 +40,6 @@ struct gkyl_dg_eqn* gkyl_dg_lbo_gyrokinetic_drag_new(const struct gkyl_basis* cb * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_lbo_gyrokinetic_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_drag_auxfields auxin); +void gkyl_lbo_gyrokinetic_drag_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_drag_auxfields auxin +); diff --git a/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_drag_priv.h b/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_drag_priv.h index e7424b46d5..99e9da2bfb 100644 --- a/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_drag_priv.h +++ b/gyrokinetic/zero/gkyl_dg_lbo_gyrokinetic_drag_priv.h @@ -7,29 +7,41 @@ #include // Types for various kernels -typedef double (*lbo_gyrokinetic_drag_surf_t)(const double *dxv, const double *vmap, - const double *vmap_prime_l, const double *vmap_prime_c, const double *vmap_prime_r, const double m_, - const double *bmag_inv, const double *nuSum, const double *nuPrimMomsSum, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); - -typedef double (*lbo_gyrokinetic_drag_boundary_surf_t)(const double *dxv, const double *vmap, - const double *vmap_prime_edge, const double *vmap_prime_skin, const double m_, - const double *bmag_inv, const double *nuSum, const double *nuPrimMomsSum, - const int edge, const double *fEdge, const double *fSkin, double* GKYL_RESTRICT out); +typedef double (*lbo_gyrokinetic_drag_surf_t)( + const double *dxv, const double *vmap, const double *vmap_prime_l, const double *vmap_prime_c, + const double *vmap_prime_r, const double m_, const double *bmag_inv, const double *nuSum, + const double *nuPrimMomsSum, const double *fl, const double *fc, const double *fr, + double *GKYL_RESTRICT out +); + +typedef double (*lbo_gyrokinetic_drag_boundary_surf_t)( + const double *dxv, const double *vmap, const double *vmap_prime_edge, + const double *vmap_prime_skin, const double m_, const double *bmag_inv, const double *nuSum, + const double *nuPrimMomsSum, const int edge, const double *fEdge, const double *fSkin, + double *GKYL_RESTRICT out +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below. -static struct { int vdim[3]; } cv_index[] = { +static struct { + int vdim[3]; +} cv_index[] = { {-1, -1, -1}, // 0x makes no sense - {-1, 0, 1}, // 1x kernel indices - {-1, -1, 2}, // 2x kernel indices - {-1, -1, 3}, // 3x kernel indices + {-1, 0, 1}, // 1x kernel indices + {-1, -1, 2}, // 2x kernel indices + {-1, -1, 3} // 3x kernel indices }; // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_lbo_gyrokinetic_drag_vol_kern_list; -typedef struct { lbo_gyrokinetic_drag_surf_t kernels[3]; } gkyl_dg_lbo_gyrokinetic_drag_surf_kern_list; -typedef struct { lbo_gyrokinetic_drag_boundary_surf_t kernels[3]; } gkyl_dg_lbo_gyrokinetic_drag_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_lbo_gyrokinetic_drag_vol_kern_list; +typedef struct { + lbo_gyrokinetic_drag_surf_t kernels[3]; +} gkyl_dg_lbo_gyrokinetic_drag_surf_kern_list; +typedef struct { + lbo_gyrokinetic_drag_boundary_surf_t kernels[3]; +} gkyl_dg_lbo_gyrokinetic_drag_boundary_surf_kern_list; // "Choose Kernel" based on cdim, vdim and polyorder #define CK(lst, cdim, vd, poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] @@ -54,271 +66,275 @@ struct dg_lbo_gyrokinetic_drag { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_lbo_gyrokinetic_drag_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_gyrokinetic_drag_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_drag *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_drag, eqn); int vel_idx[2]; - for (int d=lbo->cdim; dpdim; d++) vel_idx[d-lbo->cdim] = idx[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idx[d - lbo->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&lbo->conf_range, idx); long vidx = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) { - return lbo_gyrokinetic_drag_vol_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && (nuVtSqSum_p[0] > 0.) && + (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && (m2self_p[0] > 0.)) { + return lbo_gyrokinetic_drag_vol_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, qIn, qRhsOut + ); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_gyrokinetic_drag_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_gyrokinetic_drag_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_drag *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_drag, eqn); int vel_idx[2]; - for (int d=lbo->cdim; dpdim; d++) vel_idx[d-lbo->cdim] = idx[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idx[d - lbo->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&lbo->conf_range, idx); long vidx = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) { - return lbo_gyrokinetic_drag_vol_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && (nuVtSqSum_p[0] > 0.) && + (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && (m2self_p[0] > 0.)) { + return lbo_gyrokinetic_drag_vol_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, qIn, qRhsOut + ); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_gyrokinetic_drag_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_gyrokinetic_drag_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_drag *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_drag, eqn); int vel_idx[2]; - for (int d=lbo->cdim; dpdim; d++) vel_idx[d-lbo->cdim] = idx[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idx[d - lbo->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&lbo->conf_range, idx); long vidx = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) { - return lbo_gyrokinetic_drag_vol_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && (nuVtSqSum_p[0] > 0.) && + (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && (m2self_p[0] > 0.)) { + return lbo_gyrokinetic_drag_vol_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, qIn, qRhsOut + ); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_gyrokinetic_drag_vol_3x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_gyrokinetic_drag_vol_3x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_drag *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_drag, eqn); int vel_idx[2]; - for (int d=lbo->cdim; dpdim; d++) vel_idx[d-lbo->cdim] = idx[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idx[d - lbo->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&lbo->conf_range, idx); long vidx = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) { - return lbo_gyrokinetic_drag_vol_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidx), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && (nuVtSqSum_p[0] > 0.) && + (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && (m2self_p[0] > 0.)) { + return lbo_gyrokinetic_drag_vol_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidx), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidx), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, qIn, qRhsOut + ); } else { return 0.; } } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_drag_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_drag_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, kernel_lbo_gyrokinetic_drag_vol_1x1v_ser_p1, NULL }, // 0 - { NULL, kernel_lbo_gyrokinetic_drag_vol_1x2v_ser_p1, NULL }, // 1 + {NULL, kernel_lbo_gyrokinetic_drag_vol_1x1v_ser_p1, NULL}, // 0 + {NULL, kernel_lbo_gyrokinetic_drag_vol_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, kernel_lbo_gyrokinetic_drag_vol_2x2v_ser_p1, NULL }, // 3 + {NULL, kernel_lbo_gyrokinetic_drag_vol_2x2v_ser_p1, NULL}, // 3 // 3x kernels - { NULL, kernel_lbo_gyrokinetic_drag_vol_3x2v_ser_p1, NULL }, // 4 + {NULL, kernel_lbo_gyrokinetic_drag_vol_3x2v_ser_p1, NULL} // 4 }; // Surface kernel list: vpar-direction -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_drag_surf_kern_list ser_surf_vpar_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_drag_surf_kern_list ser_surf_vpar_kernels[] = { // 1x kernels - { NULL, lbo_gyrokinetic_drag_surfvpar_1x1v_ser_p1, NULL }, // 0 - { NULL, lbo_gyrokinetic_drag_surfvpar_1x2v_ser_p1, NULL }, // 1 + {NULL, lbo_gyrokinetic_drag_surfvpar_1x1v_ser_p1, NULL}, // 0 + {NULL, lbo_gyrokinetic_drag_surfvpar_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, lbo_gyrokinetic_drag_surfvpar_2x2v_ser_p1, NULL }, // 2 + {NULL, lbo_gyrokinetic_drag_surfvpar_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, lbo_gyrokinetic_drag_surfvpar_3x2v_ser_p1, NULL }, // 3 + {NULL, lbo_gyrokinetic_drag_surfvpar_3x2v_ser_p1, NULL} // 3 }; // Surface kernel list: mu-direction -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_drag_surf_kern_list ser_surf_mu_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_drag_surf_kern_list ser_surf_mu_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, lbo_gyrokinetic_drag_surfmu_1x2v_ser_p1, NULL }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, lbo_gyrokinetic_drag_surfmu_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, lbo_gyrokinetic_drag_surfmu_2x2v_ser_p1, NULL }, // 2 + {NULL, lbo_gyrokinetic_drag_surfmu_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, lbo_gyrokinetic_drag_surfmu_3x2v_ser_p1, NULL }, // 3 + {NULL, lbo_gyrokinetic_drag_surfmu_3x2v_ser_p1, NULL} // 3 }; // Boundary surface kernel (zero-flux BCs) list: vpar-direction -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_drag_boundary_surf_kern_list ser_boundary_surf_vpar_kernels[] = { - // 1x kernels - { NULL, lbo_gyrokinetic_drag_boundary_surfvpar_1x1v_ser_p1, NULL }, // 0 - { NULL, lbo_gyrokinetic_drag_boundary_surfvpar_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, lbo_gyrokinetic_drag_boundary_surfvpar_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, lbo_gyrokinetic_drag_boundary_surfvpar_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_drag_boundary_surf_kern_list + ser_boundary_surf_vpar_kernels[] = { + // 1x kernels + {NULL, lbo_gyrokinetic_drag_boundary_surfvpar_1x1v_ser_p1, NULL}, // 0 + {NULL, lbo_gyrokinetic_drag_boundary_surfvpar_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, lbo_gyrokinetic_drag_boundary_surfvpar_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, lbo_gyrokinetic_drag_boundary_surfvpar_3x2v_ser_p1, NULL} // 3 }; // Constant nu boundary surface kernel (zero-flux BCs) list: mu-direction -GKYL_CU_D -static const gkyl_dg_lbo_gyrokinetic_drag_boundary_surf_kern_list ser_boundary_surf_mu_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, lbo_gyrokinetic_drag_boundary_surfmu_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, lbo_gyrokinetic_drag_boundary_surfmu_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, lbo_gyrokinetic_drag_boundary_surfmu_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_lbo_gyrokinetic_drag_boundary_surf_kern_list + ser_boundary_surf_mu_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, lbo_gyrokinetic_drag_boundary_surfmu_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, lbo_gyrokinetic_drag_boundary_surfmu_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, lbo_gyrokinetic_drag_boundary_surfmu_3x2v_ser_p1, NULL} // 3 }; -void gkyl_lbo_gyrokinetic_drag_free(const struct gkyl_ref_count* ref); +void gkyl_lbo_gyrokinetic_drag_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_drag *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_drag, eqn); long cidx = gkyl_range_idx(&lbo->conf_range, idxC); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((dir >= lbo->cdim) && - (fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) - { + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((dir >= lbo->cdim) && (fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && + (nuVtSqSum_p[0] > 0.) && (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && + (m2self_p[0] > 0.)) { int vel_idxL[2], vel_idxC[2], vel_idxR[2]; - for (int d=lbo->cdim; dpdim; d++) { - vel_idxL[d-lbo->cdim] = idxL[d]; - vel_idxC[d-lbo->cdim] = idxC[d]; - vel_idxR[d-lbo->cdim] = idxR[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idxL[d - lbo->cdim] = idxL[d]; + vel_idxC[d - lbo->cdim] = idxC[d]; + vel_idxR[d - lbo->cdim] = idxR[d]; } long vidxL = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idxL); long vidxC = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idxC); long vidxR = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idxR); - return lbo->surf[dir-lbo->cdim](dxC, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidxC), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxL), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxC), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxR), lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut); + return lbo->surf[dir - lbo->cdim]( + dxC, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidxC), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxL), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxC), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxR), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut + ); } return 0.; } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_gyrokinetic_drag *lbo = container_of(eqn, struct dg_lbo_gyrokinetic_drag, eqn); long cidx = gkyl_range_idx(&lbo->conf_range, idxSkin); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); - const double* m2self_p = (const double*) gkyl_array_cfetch(lbo->auxfields.m2self, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; - if ((dir >= lbo->cdim) && - (fabs(nuUSum_p[0]/nuSum_p[0]) < lbo->vparMax) && - (nuVtSqSum_p[0]>0.) && (nuVtSqSum_p[0]/nuSum_p[0] < lbo->vparMaxSq) && - (m2self_p[0]>0.)) - { + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo->auxfields.nuPrimMomsSum, cidx); + const double *m2self_p = (const double *)gkyl_array_cfetch(lbo->auxfields.m2self, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo->num_cbasis]; + if ((dir >= lbo->cdim) && (fabs(nuUSum_p[0] / nuSum_p[0]) < lbo->vparMax) && + (nuVtSqSum_p[0] > 0.) && (nuVtSqSum_p[0] / nuSum_p[0] < lbo->vparMaxSq) && + (m2self_p[0] > 0.)) { int vel_idxEdge[2], vel_idxSkin[2]; - for (int d=lbo->cdim; dpdim; d++) { - vel_idxEdge[d-lbo->cdim] = idxEdge[d]; - vel_idxSkin[d-lbo->cdim] = idxSkin[d]; + for (int d = lbo->cdim; d < lbo->pdim; d++) { + vel_idxEdge[d - lbo->cdim] = idxEdge[d]; + vel_idxSkin[d - lbo->cdim] = idxSkin[d]; } long vidxEdge = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idxEdge); long vidxSkin = gkyl_range_idx(&lbo->vel_map->local_vel, vel_idxSkin); - return lbo->boundary_surf[dir-lbo->cdim](dxSkin, - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap, vidxSkin), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxEdge), - (const double*) gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxSkin), lbo->mass, - (const double*) gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), - nuSum_p, nuPrimMomsSum_p, edge, qInEdge, qInSkin, qRhsOut); + return lbo->boundary_surf[dir - lbo->cdim]( + dxSkin, (const double *)gkyl_array_cfetch(lbo->vel_map->vmap, vidxSkin), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxEdge), + (const double *)gkyl_array_cfetch(lbo->vel_map->vmap_prime, vidxSkin), lbo->mass, + (const double *)gkyl_array_cfetch(lbo->gk_geom->geo_corn.bmag_inv, cidx), nuSum_p, + nuPrimMomsSum_p, edge, qInEdge, qInSkin, qRhsOut + ); } return 0.; } @@ -328,14 +344,17 @@ boundary_surf(const struct gkyl_dg_eqn *eqn, /** * Create a new LBO equation object that lives on NV-GPU */ -struct gkyl_dg_eqn* gkyl_dg_lbo_gyrokinetic_drag_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map); +struct gkyl_dg_eqn *gkyl_dg_lbo_gyrokinetic_drag_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map +); /** * CUDA device function to set auxiliary fields needed in updating the drag flux term. */ -void gkyl_lbo_gyrokinetic_drag_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_drag_auxfields auxin); +void gkyl_lbo_gyrokinetic_drag_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_gyrokinetic_drag_auxfields auxin +); #endif - diff --git a/gyrokinetic/zero/gkyl_dg_rad_gyrokinetic_drag.h b/gyrokinetic/zero/gkyl_dg_rad_gyrokinetic_drag.h index 2937a88478..82a863f9e5 100644 --- a/gyrokinetic/zero/gkyl_dg_rad_gyrokinetic_drag.h +++ b/gyrokinetic/zero/gkyl_dg_rad_gyrokinetic_drag.h @@ -14,10 +14,10 @@ struct gkyl_dg_rad_gyrokinetic_auxfields { // D = A*(alpha+beta)/C // vmag = sqrt(vpar^2 + 2*B*mu/mass) // nu(vpar,mu) = D*vmag^(gamma)/(beta*(vmag/V0)^-alpha + alpha*(vmag/V0)^beta) - const struct gkyl_array *nvnu_surf; // surface drag for vpar direction: n*vpar*nu(vpar,mu) - const struct gkyl_array *nvnu; // volume drag for vpar direction: n*vpar*nu(vpar,mu) - const struct gkyl_array *nvsqnu_surf; // surface drag for mu direction: 2*n*mu*nu(vpar,mu) - const struct gkyl_array *nvsqnu; // volume drag for mu direction: 2*n*mu*nu(vpar,mu) + const struct gkyl_array *nvnu_surf; // surface drag for vpar direction: n*vpar*nu(vpar,mu) + const struct gkyl_array *nvnu; // volume drag for vpar direction: n*vpar*nu(vpar,mu) + const struct gkyl_array *nvsqnu_surf; // surface drag for mu direction: 2*n*mu*nu(vpar,mu) + const struct gkyl_array *nvsqnu; // volume drag for mu direction: 2*n*mu*nu(vpar,mu) }; /** @@ -31,9 +31,11 @@ struct gkyl_dg_rad_gyrokinetic_auxfields { * @param use_gpu Whether to create and run this object on the GPU. * @return Pointer to RAD equation object */ -struct gkyl_dg_eqn* gkyl_dg_rad_gyrokinetic_drag_new(const struct gkyl_basis* conf_basis, - const struct gkyl_basis* phase_basis, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_range, const struct gkyl_velocity_map *vel_map, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_rad_gyrokinetic_drag_new( + const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, + const struct gkyl_velocity_map *vel_map, bool use_gpu +); /** * Set auxiliary fields needed in updating the drag flux term. @@ -42,4 +44,6 @@ struct gkyl_dg_eqn* gkyl_dg_rad_gyrokinetic_drag_new(const struct gkyl_basis* co * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_rad_gyrokinetic_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_rad_gyrokinetic_auxfields auxin); +void gkyl_rad_gyrokinetic_drag_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_rad_gyrokinetic_auxfields auxin +); diff --git a/gyrokinetic/zero/gkyl_dg_rad_gyrokinetic_drag_priv.h b/gyrokinetic/zero/gkyl_dg_rad_gyrokinetic_drag_priv.h index 3353b2a3aa..dd9b8c56f7 100644 --- a/gyrokinetic/zero/gkyl_dg_rad_gyrokinetic_drag_priv.h +++ b/gyrokinetic/zero/gkyl_dg_rad_gyrokinetic_drag_priv.h @@ -6,30 +6,41 @@ #include // Types for various kernels -typedef double (*rad_gyrokinetic_surf_t)(const double *w, const double *dxv, const double *vmap, - const double *vmap_prime_l, const double *vmap_prime_c, const double *vmap_prime_r, - const double *nvnu_l, const double *nvnu_r, const double *nvsqnu_l, const double *nvsqnu_r, - const double *fl, const double *fc, const double *fr, - double* GKYL_RESTRICT out); - -typedef double (*rad_gyrokinetic_boundary_surf_t)(const double *w, const double *dxv, const double *vmap, - const double *vmap_prime_edge, const double *vmap_prime_skin, - const double *nvnu_edge, const double *nvnu_skin, const double *nvsqnu_edge, const double *nvsqnu_skin, - const int edge, const double *fedge, const double *fskin, double* GKYL_RESTRICT out); +typedef double (*rad_gyrokinetic_surf_t)( + const double *w, const double *dxv, const double *vmap, const double *vmap_prime_l, + const double *vmap_prime_c, const double *vmap_prime_r, const double *nvnu_l, + const double *nvnu_r, const double *nvsqnu_l, const double *nvsqnu_r, const double *fl, + const double *fc, const double *fr, double *GKYL_RESTRICT out +); + +typedef double (*rad_gyrokinetic_boundary_surf_t)( + const double *w, const double *dxv, const double *vmap, const double *vmap_prime_edge, + const double *vmap_prime_skin, const double *nvnu_edge, const double *nvnu_skin, + const double *nvsqnu_edge, const double *nvsqnu_skin, const int edge, const double *fedge, + const double *fskin, double *GKYL_RESTRICT out +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below. -static struct { int vdim[3]; } cv_index[] = { +static struct { + int vdim[3]; +} cv_index[] = { {-1, -1, -1}, // 0x makes no sense - {-1, 0, 1}, // 1x kernel indices - {-1, -1, 2}, // 2x kernel indices - {-1, -1, 3}, // 3x kernel indices + {-1, 0, 1}, // 1x kernel indices + {-1, -1, 2}, // 2x kernel indices + {-1, -1, 3} // 3x kernel indices }; // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_rad_gyrokinetic_vol_kern_list; -typedef struct { rad_gyrokinetic_surf_t kernels[3]; } gkyl_dg_rad_gyrokinetic_surf_kern_list; -typedef struct { rad_gyrokinetic_boundary_surf_t kernels[3]; } gkyl_dg_rad_gyrokinetic_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_rad_gyrokinetic_vol_kern_list; +typedef struct { + rad_gyrokinetic_surf_t kernels[3]; +} gkyl_dg_rad_gyrokinetic_surf_kern_list; +typedef struct { + rad_gyrokinetic_boundary_surf_t kernels[3]; +} gkyl_dg_rad_gyrokinetic_boundary_surf_kern_list; // "Choose Kernel" based on cdim, vdim and polyorder #define CK(lst, cdim, vd, poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] @@ -52,148 +63,153 @@ struct dg_rad_gyrokinetic_drag { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_rad_gyrokinetic_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_rad_gyrokinetic_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_rad_gyrokinetic_drag *grad_drag = container_of(eqn, struct dg_rad_gyrokinetic_drag, eqn); + struct dg_rad_gyrokinetic_drag *grad_drag = + container_of(eqn, struct dg_rad_gyrokinetic_drag, eqn); long cidx = gkyl_range_idx(&grad_drag->conf_range, idx); int vel_idx[2]; - for (int d=grad_drag->cdim; dpdim; d++) vel_idx[d-grad_drag->cdim] = idx[d]; - + for (int d = grad_drag->cdim; d < grad_drag->pdim; d++) { + vel_idx[d - grad_drag->cdim] = idx[d]; + } + long vidx = gkyl_range_idx(&grad_drag->vel_map->local_vel, vel_idx); long pidx = gkyl_range_idx(&grad_drag->phase_range, idx); - - return rad_gyrokinetic_vol_1x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidx), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvnu, pidx), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvsqnu, pidx), - qIn, qRhsOut); + + return rad_gyrokinetic_vol_1x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidx), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvnu, pidx), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvsqnu, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_rad_gyrokinetic_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_rad_gyrokinetic_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_rad_gyrokinetic_drag *grad_drag = container_of(eqn, struct dg_rad_gyrokinetic_drag, eqn); + struct dg_rad_gyrokinetic_drag *grad_drag = + container_of(eqn, struct dg_rad_gyrokinetic_drag, eqn); long cidx = gkyl_range_idx(&grad_drag->conf_range, idx); int vel_idx[2]; - for (int d=grad_drag->cdim; dpdim; d++) vel_idx[d-grad_drag->cdim] = idx[d]; + for (int d = grad_drag->cdim; d < grad_drag->pdim; d++) { + vel_idx[d - grad_drag->cdim] = idx[d]; + } long vidx = gkyl_range_idx(&grad_drag->vel_map->local_vel, vel_idx); long pidx = gkyl_range_idx(&grad_drag->phase_range, idx); - return rad_gyrokinetic_vol_2x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidx), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvnu, pidx), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvsqnu, pidx), - qIn, qRhsOut); + return rad_gyrokinetic_vol_2x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidx), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvnu, pidx), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvsqnu, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_rad_gyrokinetic_vol_3x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_rad_gyrokinetic_vol_3x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_rad_gyrokinetic_drag *grad_drag = container_of(eqn, struct dg_rad_gyrokinetic_drag, eqn); + struct dg_rad_gyrokinetic_drag *grad_drag = + container_of(eqn, struct dg_rad_gyrokinetic_drag, eqn); long cidx = gkyl_range_idx(&grad_drag->conf_range, idx); int vel_idx[2]; - for (int d=grad_drag->cdim; dpdim; d++) vel_idx[d-grad_drag->cdim] = idx[d]; + for (int d = grad_drag->cdim; d < grad_drag->pdim; d++) { + vel_idx[d - grad_drag->cdim] = idx[d]; + } long vidx = gkyl_range_idx(&grad_drag->vel_map->local_vel, vel_idx); long pidx = gkyl_range_idx(&grad_drag->phase_range, idx); - return rad_gyrokinetic_vol_3x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidx), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvnu, pidx), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvsqnu, pidx), - qIn, qRhsOut); + return rad_gyrokinetic_vol_3x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidx), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvnu, pidx), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvsqnu, pidx), qIn, qRhsOut + ); } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_rad_gyrokinetic_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_rad_gyrokinetic_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, kernel_rad_gyrokinetic_vol_1x2v_ser_p1, NULL }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, kernel_rad_gyrokinetic_vol_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, kernel_rad_gyrokinetic_vol_2x2v_ser_p1, NULL }, // 3 + {NULL, kernel_rad_gyrokinetic_vol_2x2v_ser_p1, NULL}, // 3 // 3x kernels - { NULL, kernel_rad_gyrokinetic_vol_3x2v_ser_p1, NULL }, // 4 + {NULL, kernel_rad_gyrokinetic_vol_3x2v_ser_p1, NULL} // 4 }; // Surface kernel list: vpar-direction -GKYL_CU_D -static const gkyl_dg_rad_gyrokinetic_surf_kern_list ser_surf_vpar_kernels[] = { +GKYL_CU_D static const gkyl_dg_rad_gyrokinetic_surf_kern_list ser_surf_vpar_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, rad_gyrokinetic_surfvpar_1x2v_ser_p1, NULL }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, rad_gyrokinetic_surfvpar_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, rad_gyrokinetic_surfvpar_2x2v_ser_p1, NULL }, // 2 + {NULL, rad_gyrokinetic_surfvpar_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, rad_gyrokinetic_surfvpar_3x2v_ser_p1, NULL }, // 3 + {NULL, rad_gyrokinetic_surfvpar_3x2v_ser_p1, NULL} // 3 }; // Surface kernel list: mu-direction -GKYL_CU_D -static const gkyl_dg_rad_gyrokinetic_surf_kern_list ser_surf_mu_kernels[] = { +GKYL_CU_D static const gkyl_dg_rad_gyrokinetic_surf_kern_list ser_surf_mu_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, rad_gyrokinetic_surfmu_1x2v_ser_p1, NULL }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, rad_gyrokinetic_surfmu_1x2v_ser_p1, NULL}, // 1 // 2x kernels - { NULL, rad_gyrokinetic_surfmu_2x2v_ser_p1, NULL }, // 2 + {NULL, rad_gyrokinetic_surfmu_2x2v_ser_p1, NULL}, // 2 // 3x kernels - { NULL, rad_gyrokinetic_surfmu_3x2v_ser_p1, NULL }, // 3 + {NULL, rad_gyrokinetic_surfmu_3x2v_ser_p1, NULL} // 3 }; // Boundary surface kernel (zero-flux BCs) list: vpar-direction -GKYL_CU_D -static const gkyl_dg_rad_gyrokinetic_boundary_surf_kern_list ser_boundary_surf_vpar_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, rad_gyrokinetic_boundary_surfvpar_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, rad_gyrokinetic_boundary_surfvpar_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, rad_gyrokinetic_boundary_surfvpar_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_rad_gyrokinetic_boundary_surf_kern_list + ser_boundary_surf_vpar_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, rad_gyrokinetic_boundary_surfvpar_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, rad_gyrokinetic_boundary_surfvpar_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, rad_gyrokinetic_boundary_surfvpar_3x2v_ser_p1, NULL} // 3 }; // Constant nu boundary surface kernel (zero-flux BCs) list: mu-direction -GKYL_CU_D -static const gkyl_dg_rad_gyrokinetic_boundary_surf_kern_list ser_boundary_surf_mu_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, rad_gyrokinetic_boundary_surfmu_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, rad_gyrokinetic_boundary_surfmu_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, rad_gyrokinetic_boundary_surfmu_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_dg_rad_gyrokinetic_boundary_surf_kern_list + ser_boundary_surf_mu_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, rad_gyrokinetic_boundary_surfmu_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, rad_gyrokinetic_boundary_surfmu_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, rad_gyrokinetic_boundary_surfmu_3x2v_ser_p1, NULL} // 3 }; -void gkyl_rad_gyrokinetic_free(const struct gkyl_ref_count* ref); +void gkyl_rad_gyrokinetic_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { - struct dg_rad_gyrokinetic_drag *grad_drag = container_of(eqn, struct dg_rad_gyrokinetic_drag, eqn); + struct dg_rad_gyrokinetic_drag *grad_drag = + container_of(eqn, struct dg_rad_gyrokinetic_drag, eqn); // Only in vpar,mu directions. if (dir >= grad_drag->cdim) { int vel_idxL[2], vel_idxC[2], vel_idxR[2]; - for (int d=grad_drag->cdim; dpdim; d++) { - vel_idxL[d-grad_drag->cdim] = idxL[d]; - vel_idxC[d-grad_drag->cdim] = idxC[d]; - vel_idxR[d-grad_drag->cdim] = idxR[d]; + for (int d = grad_drag->cdim; d < grad_drag->pdim; d++) { + vel_idxL[d - grad_drag->cdim] = idxL[d]; + vel_idxC[d - grad_drag->cdim] = idxC[d]; + vel_idxR[d - grad_drag->cdim] = idxR[d]; } long vidxL = gkyl_range_idx(&grad_drag->vel_map->local_vel, vel_idxL); long vidxC = gkyl_range_idx(&grad_drag->vel_map->local_vel, vel_idxC); @@ -205,57 +221,55 @@ surf(const struct gkyl_dg_eqn *eqn, long pidxC = gkyl_range_idx(&grad_drag->phase_range, idxC); long pidxR = gkyl_range_idx(&grad_drag->phase_range, idxR); long cidx = gkyl_range_idx(&grad_drag->conf_range, idxR); - return grad_drag->surf[dir-grad_drag->cdim](xcC, dxC, - (const double*) gkyl_array_cfetch(grad_drag->vel_map->vmap, vidxC), - (const double*) gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidxL), - (const double*) gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidxC), - (const double*) gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidxR), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvnu_surf, pidxC), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvnu_surf, pidxR), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvsqnu_surf, pidxC), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvsqnu_surf, pidxR), - qInL, qInC, qInR, qRhsOut); - + return grad_drag->surf[dir - grad_drag->cdim]( + xcC, dxC, (const double *)gkyl_array_cfetch(grad_drag->vel_map->vmap, vidxC), + (const double *)gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidxL), + (const double *)gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidxC), + (const double *)gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidxR), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvnu_surf, pidxC), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvnu_surf, pidxR), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvsqnu_surf, pidxC), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvsqnu_surf, pidxR), qInL, qInC, qInR, + qRhsOut + ); } return 0.; } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { - struct dg_rad_gyrokinetic_drag *grad_drag = container_of(eqn, struct dg_rad_gyrokinetic_drag, eqn); + struct dg_rad_gyrokinetic_drag *grad_drag = + container_of(eqn, struct dg_rad_gyrokinetic_drag, eqn); // Only in vpar,mu directions. if (dir >= grad_drag->cdim) { long cidx = gkyl_range_idx(&grad_drag->conf_range, idxSkin); int vel_idxEdge[2], vel_idxSkin[2]; - for (int d=grad_drag->cdim; dpdim; d++) { - vel_idxEdge[d-grad_drag->cdim] = idxEdge[d]; - vel_idxSkin[d-grad_drag->cdim] = idxSkin[d]; + for (int d = grad_drag->cdim; d < grad_drag->pdim; d++) { + vel_idxEdge[d - grad_drag->cdim] = idxEdge[d]; + vel_idxSkin[d - grad_drag->cdim] = idxSkin[d]; } long vidxEdge = gkyl_range_idx(&grad_drag->vel_map->local_vel, vel_idxEdge); long vidxSkin = gkyl_range_idx(&grad_drag->vel_map->local_vel, vel_idxSkin); - + // Each cell owns the *lower* edge surface alpha long pidxEdge = gkyl_range_idx(&grad_drag->phase_range, idxEdge); long pidxSkin = gkyl_range_idx(&grad_drag->phase_range, idxSkin); - - return grad_drag->boundary_surf[dir-grad_drag->cdim](xcSkin, dxSkin, - (const double*) gkyl_array_cfetch(grad_drag->vel_map->vmap, vidxSkin), - (const double*) gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidxEdge), - (const double*) gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidxSkin), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvnu_surf, pidxEdge), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvnu_surf, pidxSkin), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvsqnu_surf, pidxEdge), - (const double*) gkyl_array_cfetch(grad_drag->auxfields.nvsqnu_surf, pidxSkin), - edge, qInEdge, qInSkin, qRhsOut); - + + return grad_drag->boundary_surf[dir - grad_drag->cdim]( + xcSkin, dxSkin, (const double *)gkyl_array_cfetch(grad_drag->vel_map->vmap, vidxSkin), + (const double *)gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidxEdge), + (const double *)gkyl_array_cfetch(grad_drag->vel_map->vmap_prime, vidxSkin), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvnu_surf, pidxEdge), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvnu_surf, pidxSkin), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvsqnu_surf, pidxEdge), + (const double *)gkyl_array_cfetch(grad_drag->auxfields.nvsqnu_surf, pidxSkin), edge, qInEdge, + qInSkin, qRhsOut + ); } return 0.; } @@ -271,13 +285,16 @@ boundary_surf(const struct gkyl_dg_eqn *eqn, * @param vel_map Velocity space mapping object. * @return Pointer to RAD equation object */ -struct gkyl_dg_eqn* -gkyl_dg_rad_gyrokinetic_drag_cu_dev_new(const struct gkyl_basis* conf_basis, - const struct gkyl_basis* phase_basis, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_range, const struct gkyl_velocity_map *vel_map); +struct gkyl_dg_eqn *gkyl_dg_rad_gyrokinetic_drag_cu_dev_new( + const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, + const struct gkyl_velocity_map *vel_map +); /** * CUDA device function to set auxiliary fields needed in updating the drag flux term. */ -void gkyl_rad_gyrokinetic_drag_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_rad_gyrokinetic_auxfields auxin); +void gkyl_rad_gyrokinetic_drag_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_rad_gyrokinetic_auxfields auxin +); #endif diff --git a/gyrokinetic/zero/gkyl_dg_recomb.h b/gyrokinetic/zero/gkyl_dg_recomb.h index 1a0f6e06b6..f0e0a2e899 100644 --- a/gyrokinetic/zero/gkyl_dg_recomb.h +++ b/gyrokinetic/zero/gkyl_dg_recomb.h @@ -9,9 +9,9 @@ #include struct gkyl_dg_recomb_inp { - const struct gkyl_rect_grid* grid; // Grid object needed for fmax - struct gkyl_basis* cbasis; // Configuration-space basis-functions - struct gkyl_basis* pbasis; // Phase-space basis-functions + const struct gkyl_rect_grid *grid; // Grid object needed for fmax + struct gkyl_basis *cbasis; // Configuration-space basis-functions + struct gkyl_basis *pbasis; // Phase-space basis-functions const struct gkyl_range *conf_rng; // Configuration-space range const struct gkyl_range *conf_rng_ext; // Configuration-space extended range const struct gkyl_range *phase_rng; // Phase-space range @@ -21,7 +21,6 @@ struct gkyl_dg_recomb_inp { enum gkyl_react_self_type type_self; // Species type (ion, electron, or receiver) }; - // Object type typedef struct gkyl_dg_recomb gkyl_dg_recomb; @@ -30,7 +29,7 @@ typedef struct gkyl_dg_recomb gkyl_dg_recomb; * @param gkyl_dg_recomb_inp * @param use_gpu Boolean for whether struct is on host or device */ -struct gkyl_dg_recomb* gkyl_dg_recomb_new(struct gkyl_dg_recomb_inp *inp, bool use_gpu); +struct gkyl_dg_recomb *gkyl_dg_recomb_new(struct gkyl_dg_recomb_inp *inp, bool use_gpu); /** * Compute recombination collision term for use in neutral reactions. @@ -40,13 +39,15 @@ struct gkyl_dg_recomb* gkyl_dg_recomb_new(struct gkyl_dg_recomb_inp *inp, bool u * @param coef_recomb Output reaction rate coefficient * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) */ -void gkyl_dg_recomb_coll(const struct gkyl_dg_recomb *up, - const struct gkyl_array *prim_vars_elc, - struct gkyl_array *coef_recomb, struct gkyl_array *cflrate); - -void gkyl_dg_recomb_coll_cu(const struct gkyl_dg_recomb *up, - const struct gkyl_array *prim_vars_elc, - struct gkyl_array *coef_recomb, struct gkyl_array *cflrate); +void gkyl_dg_recomb_coll( + const struct gkyl_dg_recomb *up, const struct gkyl_array *prim_vars_elc, + struct gkyl_array *coef_recomb, struct gkyl_array *cflrate +); + +void gkyl_dg_recomb_coll_cu( + const struct gkyl_dg_recomb *up, const struct gkyl_array *prim_vars_elc, + struct gkyl_array *coef_recomb, struct gkyl_array *cflrate +); /** * Delete updater. diff --git a/gyrokinetic/zero/gkyl_dg_recomb_priv.h b/gyrokinetic/zero/gkyl_dg_recomb_priv.h index 61d1af5009..23fdfc7496 100644 --- a/gyrokinetic/zero/gkyl_dg_recomb_priv.h +++ b/gyrokinetic/zero/gkyl_dg_recomb_priv.h @@ -15,7 +15,7 @@ struct gkyl_dg_recomb { const struct gkyl_range *conf_rng_ext; // Configuration-space extended range const struct gkyl_range *phase_rng; // Phase-space range bool use_gpu; - + double elem_charge; // elementary charge value double mass_elc; // mass of the electron @@ -34,11 +34,9 @@ struct gkyl_dg_recomb { struct gkyl_range adas_rng; struct gkyl_basis adas_basis; struct gkyl_basis *basis_on_dev; - + struct gkyl_array *recomb_data; struct gkyl_array *vtSq_elc; struct gkyl_dg_recomb *on_dev; // pointer to itself or device data }; - - diff --git a/gyrokinetic/zero/gkyl_dg_updater_diffusion_gyrokinetic.h b/gyrokinetic/zero/gkyl_dg_updater_diffusion_gyrokinetic.h index 2cae7d3667..345dc41db8 100644 --- a/gyrokinetic/zero/gkyl_dg_updater_diffusion_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_dg_updater_diffusion_gyrokinetic.h @@ -30,10 +30,12 @@ struct gkyl_dg_updater_diffusion_gyrokinetic_tm { * @param use_gpu Whether to run on host or device. * @return New diff updater object */ -struct gkyl_dg_updater_diffusion_gyrokinetic* gkyl_dg_updater_diffusion_gyrokinetic_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, const bool *diff_in_dir, - int diff_order, const struct gkyl_range *diff_range, const bool *is_zero_flux_bc, - const struct gkyl_array *coeff, const struct gkyl_array *jacobgeo_inv, bool use_gpu); +struct gkyl_dg_updater_diffusion_gyrokinetic *gkyl_dg_updater_diffusion_gyrokinetic_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_basis *cbasis, bool is_diff_const, const bool *diff_in_dir, int diff_order, + const struct gkyl_range *diff_range, const bool *is_zero_flux_bc, const struct gkyl_array *coeff, + const struct gkyl_array *jacobgeo_inv, bool use_gpu +); /** * Acquire gyrokinetic diffusion equation object. @@ -42,8 +44,8 @@ struct gkyl_dg_updater_diffusion_gyrokinetic* gkyl_dg_updater_diffusion_gyrokine * * @return gyrokinetic diffusion equation object. */ -struct gkyl_dg_eqn* -gkyl_dg_updater_diffusion_gyrokinetic_acquire_eqn(const gkyl_dg_updater_diffusion_gyrokinetic* up); +struct gkyl_dg_eqn * +gkyl_dg_updater_diffusion_gyrokinetic_acquire_eqn(const gkyl_dg_updater_diffusion_gyrokinetic *up); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -57,9 +59,11 @@ gkyl_dg_updater_diffusion_gyrokinetic_acquire_eqn(const gkyl_dg_updater_diffusio * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_diffusion_gyrokinetic_advance(struct gkyl_dg_updater_diffusion_gyrokinetic *up, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_diffusion_gyrokinetic_advance( + struct gkyl_dg_updater_diffusion_gyrokinetic *up, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in diffusion terms @@ -67,11 +71,14 @@ void gkyl_dg_updater_diffusion_gyrokinetic_advance(struct gkyl_dg_updater_diffus * @param diffusion Updater object * @return timers */ -struct gkyl_dg_updater_diffusion_gyrokinetic_tm gkyl_dg_updater_diffusion_gyrokinetic_get_tm(const struct gkyl_dg_updater_diffusion_gyrokinetic *up); +struct gkyl_dg_updater_diffusion_gyrokinetic_tm +gkyl_dg_updater_diffusion_gyrokinetic_get_tm(const struct gkyl_dg_updater_diffusion_gyrokinetic *up +); /** * Delete updater. * * @param diffusion Updater to delete. */ -void gkyl_dg_updater_diffusion_gyrokinetic_release(struct gkyl_dg_updater_diffusion_gyrokinetic *up); +void gkyl_dg_updater_diffusion_gyrokinetic_release(struct gkyl_dg_updater_diffusion_gyrokinetic *up +); diff --git a/gyrokinetic/zero/gkyl_dg_updater_gk_anomalous_diffusion.h b/gyrokinetic/zero/gkyl_dg_updater_gk_anomalous_diffusion.h index 797ecdda47..ca27645d88 100644 --- a/gyrokinetic/zero/gkyl_dg_updater_gk_anomalous_diffusion.h +++ b/gyrokinetic/zero/gkyl_dg_updater_gk_anomalous_diffusion.h @@ -29,10 +29,12 @@ struct gkyl_dg_updater_gk_anomalous_diffusion_tm { * @param use_gpu Whether to run on host or device. * @return New diff updater object */ -struct gkyl_dg_updater_gk_anomalous_diffusion* gkyl_dg_updater_gk_anomalous_diffusion_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, +struct gkyl_dg_updater_gk_anomalous_diffusion *gkyl_dg_updater_gk_anomalous_diffusion_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, enum gkyl_gyrokinetic_bc_type bc_x_lower, enum gkyl_gyrokinetic_bc_type bc_x_upper, - const struct gkyl_array *nu, const struct gkyl_array *jacobgeo_inv, bool use_gpu); + const struct gkyl_array *nu, const struct gkyl_array *jacobgeo_inv, bool use_gpu +); /** * Acquire anomalous gyrokinetic diffusion equation object. @@ -41,8 +43,9 @@ struct gkyl_dg_updater_gk_anomalous_diffusion* gkyl_dg_updater_gk_anomalous_diff * * @return anomalous gyrokinetic diffusion equation object. */ -struct gkyl_dg_eqn* -gkyl_dg_updater_gk_anomalous_diffusion_acquire_eqn(const gkyl_dg_updater_gk_anomalous_diffusion* up); +struct gkyl_dg_eqn * +gkyl_dg_updater_gk_anomalous_diffusion_acquire_eqn(const gkyl_dg_updater_gk_anomalous_diffusion *up +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -56,9 +59,11 @@ gkyl_dg_updater_gk_anomalous_diffusion_acquire_eqn(const gkyl_dg_updater_gk_anom * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_gk_anomalous_diffusion_advance(struct gkyl_dg_updater_gk_anomalous_diffusion *up, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_gk_anomalous_diffusion_advance( + struct gkyl_dg_updater_gk_anomalous_diffusion *up, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in anomalous diffusion terms. @@ -66,11 +71,14 @@ void gkyl_dg_updater_gk_anomalous_diffusion_advance(struct gkyl_dg_updater_gk_an * @param diffusion Updater object * @return timers */ -struct gkyl_dg_updater_gk_anomalous_diffusion_tm gkyl_dg_updater_gk_anomalous_diffusion_get_tm(const struct gkyl_dg_updater_gk_anomalous_diffusion *up); +struct gkyl_dg_updater_gk_anomalous_diffusion_tm gkyl_dg_updater_gk_anomalous_diffusion_get_tm( + const struct gkyl_dg_updater_gk_anomalous_diffusion *up +); /** * Delete updater. * * @param diffusion Updater to delete. */ -void gkyl_dg_updater_gk_anomalous_diffusion_release(struct gkyl_dg_updater_gk_anomalous_diffusion *up); +void gkyl_dg_updater_gk_anomalous_diffusion_release(struct gkyl_dg_updater_gk_anomalous_diffusion *up +); diff --git a/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic.h b/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic.h index 304444287c..d41b46e256 100644 --- a/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic.h @@ -16,7 +16,6 @@ struct gkyl_dg_updater_gyrokinetic_tm { double gyrokinetic_tm; // time for gyrokinetic updates }; - /** * Create new updater to update gyrokinetic equations using hyper dg. * @@ -35,12 +34,13 @@ struct gkyl_dg_updater_gyrokinetic_tm { * @param use_gpu Boolean to determine if gyrokinetic equation object is on device * @return Pointer to updater object for Gyrokinetic equation */ -gkyl_dg_updater_gyrokinetic* gkyl_dg_updater_gyrokinetic_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const bool *is_zero_flux_bc, double charge, double mass, +gkyl_dg_updater_gyrokinetic *gkyl_dg_updater_gyrokinetic_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const bool *is_zero_flux_bc, double charge, double mass, enum gkyl_gk_collisionless_type collless_type, const struct gk_geometry *gk_geom, - const struct gkyl_velocity_map *vel_map, void *aux_inp, bool use_gpu); + const struct gkyl_velocity_map *vel_map, void *aux_inp, bool use_gpu +); /** * Acquire gyrokinetic equation object. @@ -49,8 +49,7 @@ gkyl_dg_updater_gyrokinetic* gkyl_dg_updater_gyrokinetic_new(const struct gkyl_r * * @return gyrokinetic equation object. */ -struct gkyl_dg_eqn* -gkyl_dg_updater_gyrokinetic_acquire_eqn(const gkyl_dg_updater_gyrokinetic* up); +struct gkyl_dg_eqn *gkyl_dg_updater_gyrokinetic_acquire_eqn(const gkyl_dg_updater_gyrokinetic *up); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -64,9 +63,11 @@ gkyl_dg_updater_gyrokinetic_acquire_eqn(const gkyl_dg_updater_gyrokinetic* up); * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_gyrokinetic_advance(gkyl_dg_updater_gyrokinetic *gyrokinetic, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_gyrokinetic_advance( + gkyl_dg_updater_gyrokinetic *gyrokinetic, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in gyrokinetic equation @@ -74,11 +75,12 @@ void gkyl_dg_updater_gyrokinetic_advance(gkyl_dg_updater_gyrokinetic *gyrokineti * @param gyrokinetic Updater object * @return timers */ -struct gkyl_dg_updater_gyrokinetic_tm gkyl_dg_updater_gyrokinetic_get_tm(const gkyl_dg_updater_gyrokinetic *gyrokinetic); +struct gkyl_dg_updater_gyrokinetic_tm +gkyl_dg_updater_gyrokinetic_get_tm(const gkyl_dg_updater_gyrokinetic *gyrokinetic); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_dg_updater_gyrokinetic_release(gkyl_dg_updater_gyrokinetic* up); +void gkyl_dg_updater_gyrokinetic_release(gkyl_dg_updater_gyrokinetic *up); diff --git a/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic_passive.h b/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic_passive.h index 474ba83199..a2b7a37705 100644 --- a/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic_passive.h +++ b/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic_passive.h @@ -35,15 +35,13 @@ struct gkyl_dg_updater_gyrokinetic_passive_tm { * @param use_gpu Boolean to determine if on device. * @return Pointer to new updater object. */ -gkyl_dg_updater_gyrokinetic_passive* -gkyl_dg_updater_gyrokinetic_passive_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const bool *is_zero_flux_bc, - const double charge, const double mass, - const struct gk_geometry *gk_geom, - const struct gkyl_velocity_map *vel_map, - void *aux_inp, bool use_gpu); +gkyl_dg_updater_gyrokinetic_passive *gkyl_dg_updater_gyrokinetic_passive_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const bool *is_zero_flux_bc, const double charge, + const double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, + void *aux_inp, bool use_gpu +); /** * Acquire passive gyrokinetic equation object. @@ -52,8 +50,8 @@ gkyl_dg_updater_gyrokinetic_passive_new(const struct gkyl_rect_grid *grid, * * @return Passive gyrokinetic equation object. */ -struct gkyl_dg_eqn* -gkyl_dg_updater_gyrokinetic_passive_acquire_eqn(const gkyl_dg_updater_gyrokinetic_passive* up); +struct gkyl_dg_eqn * +gkyl_dg_updater_gyrokinetic_passive_acquire_eqn(const gkyl_dg_updater_gyrokinetic_passive *up); /** * Compute the RHS DG update. @@ -64,9 +62,10 @@ gkyl_dg_updater_gyrokinetic_passive_acquire_eqn(const gkyl_dg_updater_gyrokineti * @param cflrate CFL rate array (units of 1/[T]). * @param rhs RHS output. */ -void gkyl_dg_updater_gyrokinetic_passive_advance(gkyl_dg_updater_gyrokinetic_passive *up, - const struct gkyl_range *update_rng, const struct gkyl_array *fIn, - struct gkyl_array *cflrate, struct gkyl_array *rhs); +void gkyl_dg_updater_gyrokinetic_passive_advance( + gkyl_dg_updater_gyrokinetic_passive *up, const struct gkyl_range *update_rng, + const struct gkyl_array *fIn, struct gkyl_array *cflrate, struct gkyl_array *rhs +); /** * Return total time spent in the passive gyrokinetic equation. diff --git a/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic_passive_priv.h b/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic_passive_priv.h index 1c28cb82a7..5ed1e06569 100644 --- a/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic_passive_priv.h +++ b/gyrokinetic/zero/gkyl_dg_updater_gyrokinetic_passive_priv.h @@ -6,7 +6,7 @@ struct gkyl_dg_updater_gyrokinetic_passive { bool use_gpu; - struct gkyl_dg_eqn *eqn_gyrokinetic_passive; // Passive GK equation object. - struct gkyl_hyper_dg *up_gyrokinetic_passive; // hyper_dg solver (conf-space only). - double gyrokinetic_passive_tm; // Total time in advance calls. + struct gkyl_dg_eqn *eqn_gyrokinetic_passive; // Passive GK equation object. + struct gkyl_hyper_dg *up_gyrokinetic_passive; // hyper_dg solver (conf-space only). + double gyrokinetic_passive_tm; // Total time in advance calls. }; diff --git a/gyrokinetic/zero/gkyl_dg_updater_lbo_gyrokinetic.h b/gyrokinetic/zero/gkyl_dg_updater_lbo_gyrokinetic.h index 350ce234a2..3e4a690833 100644 --- a/gyrokinetic/zero/gkyl_dg_updater_lbo_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_dg_updater_lbo_gyrokinetic.h @@ -33,12 +33,13 @@ struct gkyl_dg_updater_lbo_gyrokinetic_tm { * @param use_gpu Bool for whether updater is on host or device * @return New gyrokinetic LBO updater object */ -struct gkyl_dg_updater_collisions* -gkyl_dg_updater_lbo_gyrokinetic_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, - struct gkyl_dg_lbo_gyrokinetic_drag_auxfields *drag_inp, struct gkyl_dg_lbo_gyrokinetic_diff_auxfields *diff_inp, - double mass, const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, - bool use_gpu); +struct gkyl_dg_updater_collisions *gkyl_dg_updater_lbo_gyrokinetic_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, + struct gkyl_dg_lbo_gyrokinetic_drag_auxfields *drag_inp, + struct gkyl_dg_lbo_gyrokinetic_diff_auxfields *diff_inp, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, bool use_gpu +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -52,9 +53,11 @@ gkyl_dg_updater_lbo_gyrokinetic_new(const struct gkyl_rect_grid *phase_grid, * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_lbo_gyrokinetic_advance(struct gkyl_dg_updater_collisions *lbo, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_lbo_gyrokinetic_advance( + struct gkyl_dg_updater_collisions *lbo, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in drag and diffusion terms @@ -62,11 +65,12 @@ void gkyl_dg_updater_lbo_gyrokinetic_advance(struct gkyl_dg_updater_collisions * * @param lbo Updater object * @return timers */ -struct gkyl_dg_updater_lbo_gyrokinetic_tm gkyl_dg_updater_lbo_gyrokinetic_get_tm(const struct gkyl_dg_updater_collisions *coll); +struct gkyl_dg_updater_lbo_gyrokinetic_tm +gkyl_dg_updater_lbo_gyrokinetic_get_tm(const struct gkyl_dg_updater_collisions *coll); /** * Delete updater. * * @param lbo Updater to delete. */ -void gkyl_dg_updater_lbo_gyrokinetic_release(struct gkyl_dg_updater_collisions* coll); +void gkyl_dg_updater_lbo_gyrokinetic_release(struct gkyl_dg_updater_collisions *coll); diff --git a/gyrokinetic/zero/gkyl_dg_updater_moment_gyrokinetic.h b/gyrokinetic/zero/gkyl_dg_updater_moment_gyrokinetic.h index b24878359b..5673a4fd39 100644 --- a/gyrokinetic/zero/gkyl_dg_updater_moment_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_dg_updater_moment_gyrokinetic.h @@ -34,12 +34,12 @@ typedef struct gkyl_dg_updater_moment_tm gkyl_dg_updater_moment_tm; * * @return New moment updater object */ -struct gkyl_dg_updater_moment* -gkyl_dg_updater_moment_gyrokinetic_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *conf_range, double mass, double charge, - const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, - struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool is_integrated, bool use_gpu); +struct gkyl_dg_updater_moment *gkyl_dg_updater_moment_gyrokinetic_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, double mass, + double charge, const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, + struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool is_integrated, bool use_gpu +); /** * Acquire moment object @@ -48,8 +48,8 @@ gkyl_dg_updater_moment_gyrokinetic_new(const struct gkyl_rect_grid *grid, * * @return moment type object */ -struct gkyl_mom_type* -gkyl_dg_updater_moment_gyrokinetic_acquire_type(const struct gkyl_dg_updater_moment* moment); +struct gkyl_mom_type * +gkyl_dg_updater_moment_gyrokinetic_acquire_type(const struct gkyl_dg_updater_moment *moment); /** * Acquire number of moments @@ -58,8 +58,7 @@ gkyl_dg_updater_moment_gyrokinetic_acquire_type(const struct gkyl_dg_updater_mom * * @return number of moments */ -int -gkyl_dg_updater_moment_gyrokinetic_num_mom(const struct gkyl_dg_updater_moment* moment); +int gkyl_dg_updater_moment_gyrokinetic_num_mom(const struct gkyl_dg_updater_moment *moment); /** * Compute moment. The update_phase_rng and update_conf_rng MUST be a sub-range of the @@ -73,10 +72,11 @@ gkyl_dg_updater_moment_gyrokinetic_num_mom(const struct gkyl_dg_updater_moment* * @param fIn Input to updater * @param mout Output moment */ -void -gkyl_dg_updater_moment_gyrokinetic_advance(struct gkyl_dg_updater_moment *moment, - const struct gkyl_range *update_phase_rng, const struct gkyl_range *update_conf_rng, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT mout); +void gkyl_dg_updater_moment_gyrokinetic_advance( + struct gkyl_dg_updater_moment *moment, const struct gkyl_range *update_phase_rng, + const struct gkyl_range *update_conf_rng, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT mout +); /** * Return total time spent in computing moments @@ -84,11 +84,12 @@ gkyl_dg_updater_moment_gyrokinetic_advance(struct gkyl_dg_updater_moment *moment * @param moment Updater object * @return timers */ -struct gkyl_dg_updater_moment_tm gkyl_dg_updater_moment_gyrokinetic_get_tm(const struct gkyl_dg_updater_moment *moment); +struct gkyl_dg_updater_moment_tm +gkyl_dg_updater_moment_gyrokinetic_get_tm(const struct gkyl_dg_updater_moment *moment); /** * Delete updater. * * @param moment Updater to delete. */ -void gkyl_dg_updater_moment_gyrokinetic_release(struct gkyl_dg_updater_moment* moment); +void gkyl_dg_updater_moment_gyrokinetic_release(struct gkyl_dg_updater_moment *moment); diff --git a/gyrokinetic/zero/gkyl_dg_updater_rad_gyrokinetic.h b/gyrokinetic/zero/gkyl_dg_updater_rad_gyrokinetic.h index 631e1044bc..cd90af232f 100644 --- a/gyrokinetic/zero/gkyl_dg_updater_rad_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_dg_updater_rad_gyrokinetic.h @@ -28,12 +28,12 @@ struct gkyl_dg_updater_rad_gyrokinetic_tm { * @param use_gpu Boolean to determine if gyrokinetic equation object is on device * @return Pointer to updater object for Radiation operator in Gyrokinetic equation */ -struct gkyl_dg_updater_collisions* -gkyl_dg_updater_rad_gyrokinetic_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_velocity_map *vel_map, void *aux_inp, bool use_gpu); - +struct gkyl_dg_updater_collisions *gkyl_dg_updater_rad_gyrokinetic_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_velocity_map *vel_map, void *aux_inp, + bool use_gpu +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -47,9 +47,11 @@ gkyl_dg_updater_rad_gyrokinetic_new(const struct gkyl_rect_grid *grid, * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_rad_gyrokinetic_advance(struct gkyl_dg_updater_collisions *rad, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_rad_gyrokinetic_advance( + struct gkyl_dg_updater_collisions *rad, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in drag and diffusion terms @@ -57,11 +59,12 @@ void gkyl_dg_updater_rad_gyrokinetic_advance(struct gkyl_dg_updater_collisions * * @param rad Updater object * @return timers */ -struct gkyl_dg_updater_rad_gyrokinetic_tm gkyl_dg_updater_rad_gyrokinetic_get_tm(const struct gkyl_dg_updater_collisions *coll); +struct gkyl_dg_updater_rad_gyrokinetic_tm +gkyl_dg_updater_rad_gyrokinetic_get_tm(const struct gkyl_dg_updater_collisions *coll); /** * Delete updater. * * @param rad Updater to delete. */ -void gkyl_dg_updater_rad_gyrokinetic_release(struct gkyl_dg_updater_collisions* coll); +void gkyl_dg_updater_rad_gyrokinetic_release(struct gkyl_dg_updater_collisions *coll); diff --git a/gyrokinetic/zero/gkyl_efit.h b/gyrokinetic/zero/gkyl_efit.h index a698b596b7..ea3556c001 100644 --- a/gyrokinetic/zero/gkyl_efit.h +++ b/gyrokinetic/zero/gkyl_efit.h @@ -18,8 +18,8 @@ struct gkyl_efit_inp { bool use_gpu; // whether to use the GPU }; -struct gkyl_efit{ - const char* filepath; +struct gkyl_efit { + const char *filepath; char name[1024]; // name (filepath stripped of full path and extension) int nr, nz; double rdim, zdim, rcentr, rleft, zmid, rmaxis, zmaxis, simag, sibry, bcentr, current, xdum; @@ -27,8 +27,8 @@ struct gkyl_efit{ double psisep; // Separatrix psi for our DG representation double psisep_cubic; // Separatrix psi for our cubic DG representation - // Can differ from sibry, but we need to keep sibry - // because fpol, q, etc. are defined based on it + // Can differ from sibry, but we need to keep sibry + // because fpol, q, etc. are defined based on it struct gkyl_basis rzbasis; struct gkyl_basis rzbasis_cubic; @@ -41,15 +41,15 @@ struct gkyl_efit{ struct gkyl_array *psizr; struct gkyl_array *psizr_cubic; struct gkyl_array *bmagzr; - struct gkyl_basis_ops_evalf *evf ; + struct gkyl_basis_ops_evalf *evf; struct gkyl_basis fluxbasis; struct gkyl_rect_grid fluxgrid; struct gkyl_range fluxlocal; struct gkyl_range fluxlocal_ext; - struct gkyl_array* fpolflux; - struct gkyl_array* fpolprimeflux; - struct gkyl_array* qflux; + struct gkyl_array *fpolflux; + struct gkyl_array *fpolprimeflux; + struct gkyl_array *qflux; int num_xpts; // Number of X-points double *Rxpt; // R coordinates of X points @@ -75,7 +75,6 @@ struct gkyl_efit{ * @return New updater pointer. */ -gkyl_efit* gkyl_efit_new(const struct gkyl_efit_inp *inp); +gkyl_efit *gkyl_efit_new(const struct gkyl_efit_inp *inp); - -void gkyl_efit_release(gkyl_efit* up); +void gkyl_efit_release(gkyl_efit *up); diff --git a/gyrokinetic/zero/gkyl_efit_priv.h b/gyrokinetic/zero/gkyl_efit_priv.h index 30c360a979..82be445cae 100644 --- a/gyrokinetic/zero/gkyl_efit_priv.h +++ b/gyrokinetic/zero/gkyl_efit_priv.h @@ -1,16 +1,12 @@ #include #include -bool -newton_raphson(struct gkyl_efit *up, const double *coeffs, double *xsol, bool cubics); +bool newton_raphson(struct gkyl_efit *up, const double *coeffs, double *xsol, bool cubics); -int -find_xpts(gkyl_efit* up, double *Rxpt, double *Zxpt); +int find_xpts(gkyl_efit *up, double *Rxpt, double *Zxpt); -int -find_xpts_cubic(gkyl_efit* up, double *Rxpt, double *Zxpt); +int find_xpts_cubic(gkyl_efit *up, double *Rxpt, double *Zxpt); // Strips a filepath of everything through the last forward slash // and the extension to give just the name -void -get_stripped_filename(const char *filepath, char *out_buffer); +void get_stripped_filename(const char *filepath, char *out_buffer); diff --git a/gyrokinetic/zero/gkyl_fem_parproj.h b/gyrokinetic/zero/gkyl_fem_parproj.h index b19fb150fc..12bb508745 100644 --- a/gyrokinetic/zero/gkyl_fem_parproj.h +++ b/gyrokinetic/zero/gkyl_fem_parproj.h @@ -14,7 +14,7 @@ enum gkyl_fem_parproj_bc_type { GKYL_FEM_PARPROJ_PERIODIC = 0, GKYL_FEM_PARPROJ_DIRICHLET_GHOST, // Solution = ghost evaluated at the boundary. GKYL_FEM_PARPROJ_DIRICHLET_SKIN, // Solution = skin evaluated at the boundary. - GKYL_FEM_PARPROJ_NONE, // does not enforce a BC. + GKYL_FEM_PARPROJ_NONE // does not enforce a BC. }; /** @@ -38,10 +38,12 @@ enum gkyl_fem_parproj_bc_type { * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -struct gkyl_fem_parproj* gkyl_fem_parproj_new(const struct gkyl_range *solve_range, const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, enum gkyl_fem_parproj_bc_type bctype, struct gkyl_poisson_bias_line_list* bias_line_list, - const struct gkyl_array *weight_left, const struct gkyl_array *weight_right, - bool use_gpu); +struct gkyl_fem_parproj *gkyl_fem_parproj_new( + const struct gkyl_range *solve_range, const struct gkyl_rect_grid *grid, + const struct gkyl_basis *basis, enum gkyl_fem_parproj_bc_type bctype, + struct gkyl_poisson_bias_line_list *bias_line_list, const struct gkyl_array *weight_left, + const struct gkyl_array *weight_right, bool use_gpu +); /** * Assign the right-side vector with the discontinuous (DG) source field. @@ -50,15 +52,16 @@ struct gkyl_fem_parproj* gkyl_fem_parproj_new(const struct gkyl_range *solve_ran * @param rhsin DG field to set as RHS source. * @param phibc Potential to use for Dirichlet BCs. */ -void gkyl_fem_parproj_set_rhs(struct gkyl_fem_parproj* up, - const struct gkyl_array *rhsin, const struct gkyl_array *phibc); +void gkyl_fem_parproj_set_rhs( + struct gkyl_fem_parproj *up, const struct gkyl_array *rhsin, const struct gkyl_array *phibc +); /** * Solve the linear problem. * * @param up FEM project updater to run. */ -void gkyl_fem_parproj_solve(struct gkyl_fem_parproj* up, struct gkyl_array *phiout); +void gkyl_fem_parproj_solve(struct gkyl_fem_parproj *up, struct gkyl_array *phiout); /** * Delete updater. diff --git a/gyrokinetic/zero/gkyl_fem_parproj_priv.h b/gyrokinetic/zero/gkyl_fem_parproj_priv.h index f5460351d5..cb5eecc17d 100644 --- a/gyrokinetic/zero/gkyl_fem_parproj_priv.h +++ b/gyrokinetic/zero/gkyl_fem_parproj_priv.h @@ -16,36 +16,36 @@ gkyl_fem_parproj_global_num_nodes(const struct gkyl_basis *basis, bool isperiodi int poly_order = basis->poly_order; enum gkyl_basis_type basis_type = basis->b_type; - if (dim==1) { + if (dim == 1) { if (poly_order == 1) { - return isperiodic? fem_parproj_num_nodes_global_1x_ser_p1_periodicx(parnum_cells) - : fem_parproj_num_nodes_global_1x_ser_p1_nonperiodicx(parnum_cells); + return isperiodic ? fem_parproj_num_nodes_global_1x_ser_p1_periodicx(parnum_cells) : + fem_parproj_num_nodes_global_1x_ser_p1_nonperiodicx(parnum_cells); } else if (poly_order == 2) { - return isperiodic? fem_parproj_num_nodes_global_1x_ser_p2_periodicx(parnum_cells) - : fem_parproj_num_nodes_global_1x_ser_p2_nonperiodicx(parnum_cells); + return isperiodic ? fem_parproj_num_nodes_global_1x_ser_p2_periodicx(parnum_cells) : + fem_parproj_num_nodes_global_1x_ser_p2_nonperiodicx(parnum_cells); } - } else if (dim==2) { + } else if (dim == 2) { if (basis_type == GKYL_BASIS_MODAL_SERENDIPITY) { if (poly_order == 1) { - return isperiodic? fem_parproj_num_nodes_global_2x_ser_p1_periodicy(parnum_cells) - : fem_parproj_num_nodes_global_2x_ser_p1_nonperiodicy(parnum_cells); + return isperiodic ? fem_parproj_num_nodes_global_2x_ser_p1_periodicy(parnum_cells) : + fem_parproj_num_nodes_global_2x_ser_p1_nonperiodicy(parnum_cells); } else if (poly_order == 2) { - return isperiodic? fem_parproj_num_nodes_global_2x_ser_p2_periodicy(parnum_cells) - : fem_parproj_num_nodes_global_2x_ser_p2_nonperiodicy(parnum_cells); + return isperiodic ? fem_parproj_num_nodes_global_2x_ser_p2_periodicy(parnum_cells) : + fem_parproj_num_nodes_global_2x_ser_p2_nonperiodicy(parnum_cells); } } - } else if (dim==3) { + } else if (dim == 3) { if (basis_type == GKYL_BASIS_MODAL_SERENDIPITY) { if (poly_order == 1) { - return isperiodic? fem_parproj_num_nodes_global_3x_ser_p1_periodicz(parnum_cells) - : fem_parproj_num_nodes_global_3x_ser_p1_nonperiodicz(parnum_cells); + return isperiodic ? fem_parproj_num_nodes_global_3x_ser_p1_periodicz(parnum_cells) : + fem_parproj_num_nodes_global_3x_ser_p1_nonperiodicz(parnum_cells); } else if (poly_order == 2) { - return isperiodic? fem_parproj_num_nodes_global_3x_ser_p2_periodicz(parnum_cells) - : fem_parproj_num_nodes_global_3x_ser_p2_nonperiodicz(parnum_cells); + return isperiodic ? fem_parproj_num_nodes_global_3x_ser_p2_periodicz(parnum_cells) : + fem_parproj_num_nodes_global_3x_ser_p2_nonperiodicz(parnum_cells); } } } - assert(false); // Other dimensionalities or basis not supported. + assert(false); // Other dimensionalities or basis not supported. return -1; } @@ -53,519 +53,530 @@ gkyl_fem_parproj_global_num_nodes(const struct gkyl_basis *basis, bool isperiodi typedef void (*local2global_t)(int numCellsPar, int parIdx, long *globalIdxs); // For use in kernel tables. -typedef struct { local2global_t kernels[2]; } local2global_kern_loc_list; -typedef struct { local2global_kern_loc_list list[2]; } local2global_kern_bc_list; -typedef struct { local2global_kern_bc_list list[2]; } local2global_kern_list; +typedef struct { + local2global_t kernels[2]; +} local2global_kern_loc_list; +typedef struct { + local2global_kern_loc_list list[2]; +} local2global_kern_bc_list; +typedef struct { + local2global_kern_bc_list list[2]; +} local2global_kern_list; // Serendipity local-to-global kernels. -GKYL_CU_D -static const local2global_kern_list ser_loc2glob_list[] = { - // 1x - {.list={ - // periodicx - {.list={ - {fem_parproj_local_to_global_1x_ser_p1_inx_periodicx, fem_parproj_local_to_global_1x_ser_p1_upx_periodicx,}, - {fem_parproj_local_to_global_1x_ser_p2_inx_periodicx, fem_parproj_local_to_global_1x_ser_p2_upx_periodicx,}, - }, - }, +GKYL_CU_D static const local2global_kern_list + ser_loc2glob_list[] = + { // 1x + {.list = + {// periodicx + {.list = + {{fem_parproj_local_to_global_1x_ser_p1_inx_periodicx, + fem_parproj_local_to_global_1x_ser_p1_upx_periodicx}, + {fem_parproj_local_to_global_1x_ser_p2_inx_periodicx, + fem_parproj_local_to_global_1x_ser_p2_upx_periodicx}}}, // nonperiodicx - {.list={ - {fem_parproj_local_to_global_1x_ser_p1_inx_nonperiodicx, fem_parproj_local_to_global_1x_ser_p1_upx_nonperiodicx,}, - {fem_parproj_local_to_global_1x_ser_p2_inx_nonperiodicx, fem_parproj_local_to_global_1x_ser_p2_upx_nonperiodicx,}, - }, - }, - } - }, - // 2x - {.list={ - // periodicy - {.list={ - {fem_parproj_local_to_global_2x_ser_p1_iny_periodicy, fem_parproj_local_to_global_2x_ser_p1_upy_periodicy,}, - {fem_parproj_local_to_global_2x_ser_p2_iny_periodicy, fem_parproj_local_to_global_2x_ser_p2_upy_periodicy,}, - }, - }, + {.list = + {{fem_parproj_local_to_global_1x_ser_p1_inx_nonperiodicx, + fem_parproj_local_to_global_1x_ser_p1_upx_nonperiodicx}, + {fem_parproj_local_to_global_1x_ser_p2_inx_nonperiodicx, + fem_parproj_local_to_global_1x_ser_p2_upx_nonperiodicx}}} + }}, + // 2x + {.list = + {// periodicy + {.list = + {{fem_parproj_local_to_global_2x_ser_p1_iny_periodicy, + fem_parproj_local_to_global_2x_ser_p1_upy_periodicy}, + {fem_parproj_local_to_global_2x_ser_p2_iny_periodicy, + fem_parproj_local_to_global_2x_ser_p2_upy_periodicy}}}, // nonperiodicy - {.list={ - {fem_parproj_local_to_global_2x_ser_p1_iny_nonperiodicy, fem_parproj_local_to_global_2x_ser_p1_upy_nonperiodicy,}, - {fem_parproj_local_to_global_2x_ser_p2_iny_nonperiodicy, fem_parproj_local_to_global_2x_ser_p2_upy_nonperiodicy,}, - }, - }, - } - }, - // 3x - {.list={ - // periodicz - {.list={ - {fem_parproj_local_to_global_3x_ser_p1_inz_periodicz, fem_parproj_local_to_global_3x_ser_p1_upz_periodicz,}, - {fem_parproj_local_to_global_3x_ser_p2_inz_periodicz, fem_parproj_local_to_global_3x_ser_p2_upz_periodicz,}, - }, - }, - // nonperiodicz - {.list={ - {fem_parproj_local_to_global_3x_ser_p1_inz_nonperiodicz, fem_parproj_local_to_global_3x_ser_p1_upz_nonperiodicz,}, - {fem_parproj_local_to_global_3x_ser_p2_inz_nonperiodicz, fem_parproj_local_to_global_3x_ser_p2_upz_nonperiodicz,}, - }, - }, - } - }, + {.list = + {{fem_parproj_local_to_global_2x_ser_p1_iny_nonperiodicy, + fem_parproj_local_to_global_2x_ser_p1_upy_nonperiodicy}, + {fem_parproj_local_to_global_2x_ser_p2_iny_nonperiodicy, + fem_parproj_local_to_global_2x_ser_p2_upy_nonperiodicy}}} + }}, + // 3x + { + .list = + {// periodicz + {.list = + {{fem_parproj_local_to_global_3x_ser_p1_inz_periodicz, + fem_parproj_local_to_global_3x_ser_p1_upz_periodicz}, + {fem_parproj_local_to_global_3x_ser_p2_inz_periodicz, + fem_parproj_local_to_global_3x_ser_p2_upz_periodicz}}}, + // nonperiodicz + {.list = + {{fem_parproj_local_to_global_3x_ser_p1_inz_nonperiodicz, fem_parproj_local_to_global_3x_ser_p1_upz_nonperiodicz}, {fem_parproj_local_to_global_3x_ser_p2_inz_nonperiodicz, fem_parproj_local_to_global_3x_ser_p2_upz_nonperiodicz}} + } + } + } }; // Function pointer type for lhs kernels. -typedef void (*lhsstencil_t)(const double *weight, const long *globalIdxs, struct gkyl_mat_triples *tri); +typedef void (*lhsstencil_t)( + const double *weight, const long *globalIdxs, struct gkyl_mat_triples *tri +); // For use in kernel tables. -typedef struct { lhsstencil_t kernels[3]; } lhsstencil_kern_loc_list; -typedef struct { lhsstencil_kern_loc_list list[2]; } lhsstencil_kern_bc_list; -typedef struct { lhsstencil_kern_bc_list list[2]; } lhsstencil_kern_list; +typedef struct { + lhsstencil_t kernels[3]; +} lhsstencil_kern_loc_list; +typedef struct { + lhsstencil_kern_loc_list list[2]; +} lhsstencil_kern_bc_list; +typedef struct { + lhsstencil_kern_bc_list list[2]; +} lhsstencil_kern_list; // Serendipity unweighted lhs kernels. -static const lhsstencil_kern_list ser_lhsstencil_list_noweight[] = { - // 1x - {.list={ - // nondirichletx - {.list={ - {fem_parproj_lhs_stencil_noweight_1x_ser_p1_inx_nondirichletx, fem_parproj_lhs_stencil_noweight_1x_ser_p1_lox_nondirichletx, fem_parproj_lhs_stencil_noweight_1x_ser_p1_upx_nondirichletx,}, - {fem_parproj_lhs_stencil_noweight_1x_ser_p2_inx_nondirichletx, fem_parproj_lhs_stencil_noweight_1x_ser_p2_lox_nondirichletx, fem_parproj_lhs_stencil_noweight_1x_ser_p2_upx_nondirichletx,}, - }, - }, +static const lhsstencil_kern_list + ser_lhsstencil_list_noweight[] = + { // 1x + {.list = + {// nondirichletx + {.list = + {{fem_parproj_lhs_stencil_noweight_1x_ser_p1_inx_nondirichletx, + fem_parproj_lhs_stencil_noweight_1x_ser_p1_lox_nondirichletx, + fem_parproj_lhs_stencil_noweight_1x_ser_p1_upx_nondirichletx}, + {fem_parproj_lhs_stencil_noweight_1x_ser_p2_inx_nondirichletx, + fem_parproj_lhs_stencil_noweight_1x_ser_p2_lox_nondirichletx, + fem_parproj_lhs_stencil_noweight_1x_ser_p2_upx_nondirichletx}}}, // dirichletx - {.list={ - {fem_parproj_lhs_stencil_noweight_1x_ser_p1_inx_nondirichletx, fem_parproj_lhs_stencil_noweight_1x_ser_p1_lox_dirichletx, fem_parproj_lhs_stencil_noweight_1x_ser_p1_upx_dirichletx,}, - {fem_parproj_lhs_stencil_noweight_1x_ser_p2_inx_nondirichletx, fem_parproj_lhs_stencil_noweight_1x_ser_p2_lox_dirichletx, fem_parproj_lhs_stencil_noweight_1x_ser_p2_upx_dirichletx,}, - }, - }, - }, - }, - // 2x - {.list={ - // nondirichlety - {.list={ - {fem_parproj_lhs_stencil_noweight_2x_ser_p1_iny_nondirichlety, fem_parproj_lhs_stencil_noweight_2x_ser_p1_loy_nondirichlety, fem_parproj_lhs_stencil_noweight_2x_ser_p1_upy_nondirichlety,}, - {fem_parproj_lhs_stencil_noweight_2x_ser_p2_iny_nondirichlety, fem_parproj_lhs_stencil_noweight_2x_ser_p2_loy_nondirichlety, fem_parproj_lhs_stencil_noweight_2x_ser_p2_upy_nondirichlety,}, - }, - }, + {.list = + {{fem_parproj_lhs_stencil_noweight_1x_ser_p1_inx_nondirichletx, + fem_parproj_lhs_stencil_noweight_1x_ser_p1_lox_dirichletx, + fem_parproj_lhs_stencil_noweight_1x_ser_p1_upx_dirichletx}, + {fem_parproj_lhs_stencil_noweight_1x_ser_p2_inx_nondirichletx, + fem_parproj_lhs_stencil_noweight_1x_ser_p2_lox_dirichletx, + fem_parproj_lhs_stencil_noweight_1x_ser_p2_upx_dirichletx}}} + }}, + // 2x + {.list = + {// nondirichlety + {.list = + {{fem_parproj_lhs_stencil_noweight_2x_ser_p1_iny_nondirichlety, + fem_parproj_lhs_stencil_noweight_2x_ser_p1_loy_nondirichlety, + fem_parproj_lhs_stencil_noweight_2x_ser_p1_upy_nondirichlety}, + {fem_parproj_lhs_stencil_noweight_2x_ser_p2_iny_nondirichlety, + fem_parproj_lhs_stencil_noweight_2x_ser_p2_loy_nondirichlety, + fem_parproj_lhs_stencil_noweight_2x_ser_p2_upy_nondirichlety}}}, // dirichlety - {.list={ - {fem_parproj_lhs_stencil_noweight_2x_ser_p1_iny_nondirichlety, fem_parproj_lhs_stencil_noweight_2x_ser_p1_loy_dirichlety, fem_parproj_lhs_stencil_noweight_2x_ser_p1_upy_dirichlety,}, - {fem_parproj_lhs_stencil_noweight_2x_ser_p2_iny_nondirichlety, fem_parproj_lhs_stencil_noweight_2x_ser_p2_loy_dirichlety, fem_parproj_lhs_stencil_noweight_2x_ser_p2_upy_dirichlety,}, - }, - }, - } - }, - // 3x - {.list={ - // nondirichletz - {.list={ - {fem_parproj_lhs_stencil_noweight_3x_ser_p1_inz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p1_loz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p1_upz_nondirichletz,}, - {fem_parproj_lhs_stencil_noweight_3x_ser_p2_inz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p2_loz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p2_upz_nondirichletz,}, - }, - }, - // dirichletz - {.list={ - {fem_parproj_lhs_stencil_noweight_3x_ser_p1_inz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p1_loz_dirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p1_upz_dirichletz,}, - {fem_parproj_lhs_stencil_noweight_3x_ser_p2_inz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p2_loz_dirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p2_upz_dirichletz,}, - }, - }, - } - }, + {.list = + {{fem_parproj_lhs_stencil_noweight_2x_ser_p1_iny_nondirichlety, + fem_parproj_lhs_stencil_noweight_2x_ser_p1_loy_dirichlety, + fem_parproj_lhs_stencil_noweight_2x_ser_p1_upy_dirichlety}, + {fem_parproj_lhs_stencil_noweight_2x_ser_p2_iny_nondirichlety, + fem_parproj_lhs_stencil_noweight_2x_ser_p2_loy_dirichlety, + fem_parproj_lhs_stencil_noweight_2x_ser_p2_upy_dirichlety}}} + }}, + // 3x + { + .list = + {// nondirichletz + {.list = + {{fem_parproj_lhs_stencil_noweight_3x_ser_p1_inz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p1_loz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p1_upz_nondirichletz}, {fem_parproj_lhs_stencil_noweight_3x_ser_p2_inz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p2_loz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p2_upz_nondirichletz}} + }, + // dirichletz + {.list = {{fem_parproj_lhs_stencil_noweight_3x_ser_p1_inz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p1_loz_dirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p1_upz_dirichletz}, {fem_parproj_lhs_stencil_noweight_3x_ser_p2_inz_nondirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p2_loz_dirichletz, fem_parproj_lhs_stencil_noweight_3x_ser_p2_upz_dirichletz}} + } + } + } }; // Serendipity weighted lhs kernels. -static const lhsstencil_kern_list ser_lhsstencil_list_weighted[] = { - // 1x - {.list={ - // nondirichletx - {.list={ - {fem_parproj_lhs_stencil_weighted_1x_ser_p1_inx_nondirichletx, fem_parproj_lhs_stencil_weighted_1x_ser_p1_lox_nondirichletx, fem_parproj_lhs_stencil_weighted_1x_ser_p1_upx_nondirichletx,}, - {fem_parproj_lhs_stencil_weighted_1x_ser_p2_inx_nondirichletx, fem_parproj_lhs_stencil_weighted_1x_ser_p2_lox_nondirichletx, fem_parproj_lhs_stencil_weighted_1x_ser_p2_upx_nondirichletx,}, - }, - }, +static const lhsstencil_kern_list + ser_lhsstencil_list_weighted[] = + { // 1x + {.list = + {// nondirichletx + {.list = + {{fem_parproj_lhs_stencil_weighted_1x_ser_p1_inx_nondirichletx, + fem_parproj_lhs_stencil_weighted_1x_ser_p1_lox_nondirichletx, + fem_parproj_lhs_stencil_weighted_1x_ser_p1_upx_nondirichletx}, + {fem_parproj_lhs_stencil_weighted_1x_ser_p2_inx_nondirichletx, + fem_parproj_lhs_stencil_weighted_1x_ser_p2_lox_nondirichletx, + fem_parproj_lhs_stencil_weighted_1x_ser_p2_upx_nondirichletx}}}, // dirichletx - {.list={ - {fem_parproj_lhs_stencil_weighted_1x_ser_p1_inx_nondirichletx, fem_parproj_lhs_stencil_weighted_1x_ser_p1_lox_dirichletx, fem_parproj_lhs_stencil_weighted_1x_ser_p1_upx_dirichletx,}, - {fem_parproj_lhs_stencil_weighted_1x_ser_p2_inx_nondirichletx, fem_parproj_lhs_stencil_weighted_1x_ser_p2_lox_dirichletx, fem_parproj_lhs_stencil_weighted_1x_ser_p2_upx_dirichletx,}, - }, - }, - } - }, - // 2x - {.list={ - // nondirichlety - {.list={ - {fem_parproj_lhs_stencil_weighted_2x_ser_p1_iny_nondirichlety, fem_parproj_lhs_stencil_weighted_2x_ser_p1_loy_nondirichlety, fem_parproj_lhs_stencil_weighted_2x_ser_p1_upy_nondirichlety,}, - {fem_parproj_lhs_stencil_weighted_2x_ser_p2_iny_nondirichlety, fem_parproj_lhs_stencil_weighted_2x_ser_p2_loy_nondirichlety, fem_parproj_lhs_stencil_weighted_2x_ser_p2_upy_nondirichlety,}, - }, - }, + {.list = + {{fem_parproj_lhs_stencil_weighted_1x_ser_p1_inx_nondirichletx, + fem_parproj_lhs_stencil_weighted_1x_ser_p1_lox_dirichletx, + fem_parproj_lhs_stencil_weighted_1x_ser_p1_upx_dirichletx}, + {fem_parproj_lhs_stencil_weighted_1x_ser_p2_inx_nondirichletx, + fem_parproj_lhs_stencil_weighted_1x_ser_p2_lox_dirichletx, + fem_parproj_lhs_stencil_weighted_1x_ser_p2_upx_dirichletx}}} + }}, + // 2x + {.list = + {// nondirichlety + {.list = + {{fem_parproj_lhs_stencil_weighted_2x_ser_p1_iny_nondirichlety, + fem_parproj_lhs_stencil_weighted_2x_ser_p1_loy_nondirichlety, + fem_parproj_lhs_stencil_weighted_2x_ser_p1_upy_nondirichlety}, + {fem_parproj_lhs_stencil_weighted_2x_ser_p2_iny_nondirichlety, + fem_parproj_lhs_stencil_weighted_2x_ser_p2_loy_nondirichlety, + fem_parproj_lhs_stencil_weighted_2x_ser_p2_upy_nondirichlety}}}, // dirichlety - {.list={ - {fem_parproj_lhs_stencil_weighted_2x_ser_p1_iny_nondirichlety, fem_parproj_lhs_stencil_weighted_2x_ser_p1_loy_dirichlety, fem_parproj_lhs_stencil_weighted_2x_ser_p1_upy_dirichlety,}, - {fem_parproj_lhs_stencil_weighted_2x_ser_p2_iny_nondirichlety, fem_parproj_lhs_stencil_weighted_2x_ser_p2_loy_dirichlety, fem_parproj_lhs_stencil_weighted_2x_ser_p2_upy_dirichlety,}, - }, - }, - } - }, - // 3x - {.list={ - // nondirichletz - {.list={ - {fem_parproj_lhs_stencil_weighted_3x_ser_p1_inz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p1_loz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p1_upz_nondirichletz,}, - {fem_parproj_lhs_stencil_weighted_3x_ser_p2_inz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p2_loz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p2_upz_nondirichletz,}, - }, - }, - // dirichletz - {.list={ - {fem_parproj_lhs_stencil_weighted_3x_ser_p1_inz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p1_loz_dirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p1_upz_dirichletz,}, - {fem_parproj_lhs_stencil_weighted_3x_ser_p2_inz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p2_loz_dirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p2_upz_dirichletz,}, - }, - }, - } - }, + {.list = + {{fem_parproj_lhs_stencil_weighted_2x_ser_p1_iny_nondirichlety, + fem_parproj_lhs_stencil_weighted_2x_ser_p1_loy_dirichlety, + fem_parproj_lhs_stencil_weighted_2x_ser_p1_upy_dirichlety}, + {fem_parproj_lhs_stencil_weighted_2x_ser_p2_iny_nondirichlety, + fem_parproj_lhs_stencil_weighted_2x_ser_p2_loy_dirichlety, + fem_parproj_lhs_stencil_weighted_2x_ser_p2_upy_dirichlety}}} + }}, + // 3x + { + .list = + {// nondirichletz + {.list = + {{fem_parproj_lhs_stencil_weighted_3x_ser_p1_inz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p1_loz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p1_upz_nondirichletz}, {fem_parproj_lhs_stencil_weighted_3x_ser_p2_inz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p2_loz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p2_upz_nondirichletz}} + }, + // dirichletz + {.list = {{fem_parproj_lhs_stencil_weighted_3x_ser_p1_inz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p1_loz_dirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p1_upz_dirichletz}, {fem_parproj_lhs_stencil_weighted_3x_ser_p2_inz_nondirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p2_loz_dirichletz, fem_parproj_lhs_stencil_weighted_3x_ser_p2_upz_dirichletz}} + } + } + } }; // Function pointer type for rhs source kernels. -typedef void (*srcstencil_t)(const double *weight, const double *rho, const double *phiBC, long nodeOff, const long *globalIdxs, - double *bsrc); - -typedef struct { srcstencil_t kernels[3]; } srcstencil_kern_loc_list; // For use in kernel tables. -typedef struct { srcstencil_kern_loc_list list[2]; } srcstencil_kern_bc_list; // For use in kernel tables. -typedef struct { srcstencil_kern_bc_list list[3]; } srcstencil_kern_list; // For use in kernel tables. +typedef void (*srcstencil_t)( + const double *weight, const double *rho, const double *phiBC, long nodeOff, + const long *globalIdxs, double *bsrc +); + +typedef struct { + srcstencil_t kernels[3]; +} srcstencil_kern_loc_list; // For use in kernel tables. +typedef struct { + srcstencil_kern_loc_list list[2]; +} srcstencil_kern_bc_list; // For use in kernel tables. +typedef struct { + srcstencil_kern_bc_list list[3]; +} srcstencil_kern_list; // For use in kernel tables. // Serendipity src kernels. -GKYL_CU_D -static const srcstencil_kern_list ser_srcstencil_list_noweight[] = { - // 1x - {.list={ - // nondirichletx - {.list={ - {fem_parproj_src_stencil_noweight_1x_ser_p1_inx_nondirichletx, fem_parproj_src_stencil_noweight_1x_ser_p1_lox_nondirichletx, fem_parproj_src_stencil_noweight_1x_ser_p1_upx_nondirichletx,}, - {fem_parproj_src_stencil_noweight_1x_ser_p2_inx_nondirichletx, fem_parproj_src_stencil_noweight_1x_ser_p2_lox_nondirichletx, fem_parproj_src_stencil_noweight_1x_ser_p2_upx_nondirichletx,}, - }, - }, - // dirichletx ghost - {.list={ - {fem_parproj_src_stencil_noweight_1x_ser_p1_inx_nondirichletx, fem_parproj_src_stencil_noweight_1x_ser_p1_lox_dirichlet_ghostx, fem_parproj_src_stencil_noweight_1x_ser_p1_upx_dirichlet_ghostx,}, - {fem_parproj_src_stencil_noweight_1x_ser_p2_inx_nondirichletx, fem_parproj_src_stencil_noweight_1x_ser_p2_lox_dirichlet_ghostx, fem_parproj_src_stencil_noweight_1x_ser_p2_upx_dirichlet_ghostx,}, - }, - }, - // dirichletx skin - {.list={ - {fem_parproj_src_stencil_noweight_1x_ser_p1_inx_nondirichletx, fem_parproj_src_stencil_noweight_1x_ser_p1_lox_dirichlet_skinx, fem_parproj_src_stencil_noweight_1x_ser_p1_upx_dirichlet_skinx,}, - {fem_parproj_src_stencil_noweight_1x_ser_p2_inx_nondirichletx, fem_parproj_src_stencil_noweight_1x_ser_p2_lox_dirichlet_skinx, fem_parproj_src_stencil_noweight_1x_ser_p2_upx_dirichlet_skinx,}, - }, - }, - } - }, +GKYL_CU_D static const srcstencil_kern_list ser_srcstencil_list_noweight[] = { // 1x + {.list = + {// nondirichletx + {.list = {{fem_parproj_src_stencil_noweight_1x_ser_p1_inx_nondirichletx, + fem_parproj_src_stencil_noweight_1x_ser_p1_lox_nondirichletx, + fem_parproj_src_stencil_noweight_1x_ser_p1_upx_nondirichletx}, + {fem_parproj_src_stencil_noweight_1x_ser_p2_inx_nondirichletx, + fem_parproj_src_stencil_noweight_1x_ser_p2_lox_nondirichletx, + fem_parproj_src_stencil_noweight_1x_ser_p2_upx_nondirichletx}}}, + // dirichletx ghost + {.list = {{fem_parproj_src_stencil_noweight_1x_ser_p1_inx_nondirichletx, + fem_parproj_src_stencil_noweight_1x_ser_p1_lox_dirichlet_ghostx, + fem_parproj_src_stencil_noweight_1x_ser_p1_upx_dirichlet_ghostx}, + {fem_parproj_src_stencil_noweight_1x_ser_p2_inx_nondirichletx, + fem_parproj_src_stencil_noweight_1x_ser_p2_lox_dirichlet_ghostx, + fem_parproj_src_stencil_noweight_1x_ser_p2_upx_dirichlet_ghostx}}}, + // dirichletx skin + {.list = {{fem_parproj_src_stencil_noweight_1x_ser_p1_inx_nondirichletx, + fem_parproj_src_stencil_noweight_1x_ser_p1_lox_dirichlet_skinx, + fem_parproj_src_stencil_noweight_1x_ser_p1_upx_dirichlet_skinx}, + {fem_parproj_src_stencil_noweight_1x_ser_p2_inx_nondirichletx, + fem_parproj_src_stencil_noweight_1x_ser_p2_lox_dirichlet_skinx, + fem_parproj_src_stencil_noweight_1x_ser_p2_upx_dirichlet_skinx}}}}}, // 2x - {.list={ - // nondirichlety - {.list={ - {fem_parproj_src_stencil_noweight_2x_ser_p1_iny_nondirichlety, fem_parproj_src_stencil_noweight_2x_ser_p1_loy_nondirichlety, fem_parproj_src_stencil_noweight_2x_ser_p1_upy_nondirichlety,}, - {fem_parproj_src_stencil_noweight_2x_ser_p2_iny_nondirichlety, fem_parproj_src_stencil_noweight_2x_ser_p2_loy_nondirichlety, fem_parproj_src_stencil_noweight_2x_ser_p2_upy_nondirichlety,}, - }, - }, - // dirichlety ghost - {.list={ - {fem_parproj_src_stencil_noweight_2x_ser_p1_iny_nondirichlety, fem_parproj_src_stencil_noweight_2x_ser_p1_loy_dirichlet_ghosty, fem_parproj_src_stencil_noweight_2x_ser_p1_upy_dirichlet_ghosty,}, - {fem_parproj_src_stencil_noweight_2x_ser_p2_iny_nondirichlety, fem_parproj_src_stencil_noweight_2x_ser_p2_loy_dirichlet_ghosty, fem_parproj_src_stencil_noweight_2x_ser_p2_upy_dirichlet_ghosty,}, - }, - }, - // dirichlety skin - {.list={ - {fem_parproj_src_stencil_noweight_2x_ser_p1_iny_nondirichlety, fem_parproj_src_stencil_noweight_2x_ser_p1_loy_dirichlet_skiny, fem_parproj_src_stencil_noweight_2x_ser_p1_upy_dirichlet_skiny,}, - {fem_parproj_src_stencil_noweight_2x_ser_p2_iny_nondirichlety, fem_parproj_src_stencil_noweight_2x_ser_p2_loy_dirichlet_skiny, fem_parproj_src_stencil_noweight_2x_ser_p2_upy_dirichlet_skiny,}, - }, - }, - } - }, + {.list = + {// nondirichlety + {.list = {{fem_parproj_src_stencil_noweight_2x_ser_p1_iny_nondirichlety, + fem_parproj_src_stencil_noweight_2x_ser_p1_loy_nondirichlety, + fem_parproj_src_stencil_noweight_2x_ser_p1_upy_nondirichlety}, + {fem_parproj_src_stencil_noweight_2x_ser_p2_iny_nondirichlety, + fem_parproj_src_stencil_noweight_2x_ser_p2_loy_nondirichlety, + fem_parproj_src_stencil_noweight_2x_ser_p2_upy_nondirichlety}}}, + // dirichlety ghost + {.list = {{fem_parproj_src_stencil_noweight_2x_ser_p1_iny_nondirichlety, + fem_parproj_src_stencil_noweight_2x_ser_p1_loy_dirichlet_ghosty, + fem_parproj_src_stencil_noweight_2x_ser_p1_upy_dirichlet_ghosty}, + {fem_parproj_src_stencil_noweight_2x_ser_p2_iny_nondirichlety, + fem_parproj_src_stencil_noweight_2x_ser_p2_loy_dirichlet_ghosty, + fem_parproj_src_stencil_noweight_2x_ser_p2_upy_dirichlet_ghosty}}}, + // dirichlety skin + {.list = {{fem_parproj_src_stencil_noweight_2x_ser_p1_iny_nondirichlety, + fem_parproj_src_stencil_noweight_2x_ser_p1_loy_dirichlet_skiny, + fem_parproj_src_stencil_noweight_2x_ser_p1_upy_dirichlet_skiny}, + {fem_parproj_src_stencil_noweight_2x_ser_p2_iny_nondirichlety, + fem_parproj_src_stencil_noweight_2x_ser_p2_loy_dirichlet_skiny, + fem_parproj_src_stencil_noweight_2x_ser_p2_upy_dirichlet_skiny}}}}}, // 3x - {.list={ - // nondirichletz - {.list={ - {fem_parproj_src_stencil_noweight_3x_ser_p1_inz_nondirichletz, fem_parproj_src_stencil_noweight_3x_ser_p1_loz_nondirichletz, fem_parproj_src_stencil_noweight_3x_ser_p1_upz_nondirichletz,}, - {fem_parproj_src_stencil_noweight_3x_ser_p2_inz_nondirichletz, fem_parproj_src_stencil_noweight_3x_ser_p2_loz_nondirichletz, fem_parproj_src_stencil_noweight_3x_ser_p2_upz_nondirichletz,}, - }, - }, - // dirichletz ghost - {.list={ - {fem_parproj_src_stencil_noweight_3x_ser_p1_inz_nondirichletz, fem_parproj_src_stencil_noweight_3x_ser_p1_loz_dirichlet_ghostz, fem_parproj_src_stencil_noweight_3x_ser_p1_upz_dirichlet_ghostz,}, - {fem_parproj_src_stencil_noweight_3x_ser_p2_inz_nondirichletz, fem_parproj_src_stencil_noweight_3x_ser_p2_loz_dirichlet_ghostz, fem_parproj_src_stencil_noweight_3x_ser_p2_upz_dirichlet_ghostz,}, - }, - }, - // dirichletz skin - {.list={ - {fem_parproj_src_stencil_noweight_3x_ser_p1_inz_nondirichletz, fem_parproj_src_stencil_noweight_3x_ser_p1_loz_dirichlet_skinz, fem_parproj_src_stencil_noweight_3x_ser_p1_upz_dirichlet_skinz,}, - {fem_parproj_src_stencil_noweight_3x_ser_p2_inz_nondirichletz, fem_parproj_src_stencil_noweight_3x_ser_p2_loz_dirichlet_skinz, fem_parproj_src_stencil_noweight_3x_ser_p2_upz_dirichlet_skinz,}, - }, - }, - } - }, -}; - -GKYL_CU_D -static const srcstencil_kern_list ser_srcstencil_list_weighted[] = { - // 1x - {.list={ - // nondirichletx - {.list={ - {fem_parproj_src_stencil_weighted_1x_ser_p1_inx_nondirichletx, fem_parproj_src_stencil_weighted_1x_ser_p1_lox_nondirichletx, fem_parproj_src_stencil_weighted_1x_ser_p1_upx_nondirichletx,}, - {fem_parproj_src_stencil_weighted_1x_ser_p2_inx_nondirichletx, fem_parproj_src_stencil_weighted_1x_ser_p2_lox_nondirichletx, fem_parproj_src_stencil_weighted_1x_ser_p2_upx_nondirichletx,}, - }, - }, - // dirichletx ghost - {.list={ - {fem_parproj_src_stencil_weighted_1x_ser_p1_inx_nondirichletx, fem_parproj_src_stencil_weighted_1x_ser_p1_lox_dirichlet_ghostx, fem_parproj_src_stencil_weighted_1x_ser_p1_upx_dirichlet_ghostx,}, - {fem_parproj_src_stencil_weighted_1x_ser_p2_inx_nondirichletx, fem_parproj_src_stencil_weighted_1x_ser_p2_lox_dirichlet_ghostx, fem_parproj_src_stencil_weighted_1x_ser_p2_upx_dirichlet_ghostx,}, - }, - }, - // dirichletx skin - {.list={ - {fem_parproj_src_stencil_weighted_1x_ser_p1_inx_nondirichletx, fem_parproj_src_stencil_weighted_1x_ser_p1_lox_dirichlet_skinx, fem_parproj_src_stencil_weighted_1x_ser_p1_upx_dirichlet_skinx,}, - {fem_parproj_src_stencil_weighted_1x_ser_p2_inx_nondirichletx, fem_parproj_src_stencil_weighted_1x_ser_p2_lox_dirichlet_skinx, fem_parproj_src_stencil_weighted_1x_ser_p2_upx_dirichlet_skinx,}, - }, - }, - } - }, + {.list = {// nondirichletz + {.list = {{fem_parproj_src_stencil_noweight_3x_ser_p1_inz_nondirichletz, + fem_parproj_src_stencil_noweight_3x_ser_p1_loz_nondirichletz, + fem_parproj_src_stencil_noweight_3x_ser_p1_upz_nondirichletz}, + {fem_parproj_src_stencil_noweight_3x_ser_p2_inz_nondirichletz, + fem_parproj_src_stencil_noweight_3x_ser_p2_loz_nondirichletz, + fem_parproj_src_stencil_noweight_3x_ser_p2_upz_nondirichletz}}}, + // dirichletz ghost + {.list = {{fem_parproj_src_stencil_noweight_3x_ser_p1_inz_nondirichletz, + fem_parproj_src_stencil_noweight_3x_ser_p1_loz_dirichlet_ghostz, + fem_parproj_src_stencil_noweight_3x_ser_p1_upz_dirichlet_ghostz}, + {fem_parproj_src_stencil_noweight_3x_ser_p2_inz_nondirichletz, + fem_parproj_src_stencil_noweight_3x_ser_p2_loz_dirichlet_ghostz, + fem_parproj_src_stencil_noweight_3x_ser_p2_upz_dirichlet_ghostz}}}, + // dirichletz skin + {.list = {{fem_parproj_src_stencil_noweight_3x_ser_p1_inz_nondirichletz, + fem_parproj_src_stencil_noweight_3x_ser_p1_loz_dirichlet_skinz, + fem_parproj_src_stencil_noweight_3x_ser_p1_upz_dirichlet_skinz}, + {fem_parproj_src_stencil_noweight_3x_ser_p2_inz_nondirichletz, + fem_parproj_src_stencil_noweight_3x_ser_p2_loz_dirichlet_skinz, + fem_parproj_src_stencil_noweight_3x_ser_p2_upz_dirichlet_skinz}}}}}}; + +GKYL_CU_D static const srcstencil_kern_list ser_srcstencil_list_weighted[] = { // 1x + {.list = + {// nondirichletx + {.list = {{fem_parproj_src_stencil_weighted_1x_ser_p1_inx_nondirichletx, + fem_parproj_src_stencil_weighted_1x_ser_p1_lox_nondirichletx, + fem_parproj_src_stencil_weighted_1x_ser_p1_upx_nondirichletx}, + {fem_parproj_src_stencil_weighted_1x_ser_p2_inx_nondirichletx, + fem_parproj_src_stencil_weighted_1x_ser_p2_lox_nondirichletx, + fem_parproj_src_stencil_weighted_1x_ser_p2_upx_nondirichletx}}}, + // dirichletx ghost + {.list = {{fem_parproj_src_stencil_weighted_1x_ser_p1_inx_nondirichletx, + fem_parproj_src_stencil_weighted_1x_ser_p1_lox_dirichlet_ghostx, + fem_parproj_src_stencil_weighted_1x_ser_p1_upx_dirichlet_ghostx}, + {fem_parproj_src_stencil_weighted_1x_ser_p2_inx_nondirichletx, + fem_parproj_src_stencil_weighted_1x_ser_p2_lox_dirichlet_ghostx, + fem_parproj_src_stencil_weighted_1x_ser_p2_upx_dirichlet_ghostx}}}, + // dirichletx skin + {.list = {{fem_parproj_src_stencil_weighted_1x_ser_p1_inx_nondirichletx, + fem_parproj_src_stencil_weighted_1x_ser_p1_lox_dirichlet_skinx, + fem_parproj_src_stencil_weighted_1x_ser_p1_upx_dirichlet_skinx}, + {fem_parproj_src_stencil_weighted_1x_ser_p2_inx_nondirichletx, + fem_parproj_src_stencil_weighted_1x_ser_p2_lox_dirichlet_skinx, + fem_parproj_src_stencil_weighted_1x_ser_p2_upx_dirichlet_skinx}}}}}, // 2x - {.list={ - // nondirichlety - {.list={ - {fem_parproj_src_stencil_weighted_2x_ser_p1_iny_nondirichlety, fem_parproj_src_stencil_weighted_2x_ser_p1_loy_nondirichlety, fem_parproj_src_stencil_weighted_2x_ser_p1_upy_nondirichlety,}, - {fem_parproj_src_stencil_weighted_2x_ser_p2_iny_nondirichlety, fem_parproj_src_stencil_weighted_2x_ser_p2_loy_nondirichlety, fem_parproj_src_stencil_weighted_2x_ser_p2_upy_nondirichlety,}, - }, - }, - // dirichlety ghost - {.list={ - {fem_parproj_src_stencil_weighted_2x_ser_p1_iny_nondirichlety, fem_parproj_src_stencil_weighted_2x_ser_p1_loy_dirichlet_ghosty, fem_parproj_src_stencil_weighted_2x_ser_p1_upy_dirichlet_ghosty,}, - {fem_parproj_src_stencil_weighted_2x_ser_p2_iny_nondirichlety, fem_parproj_src_stencil_weighted_2x_ser_p2_loy_dirichlet_ghosty, fem_parproj_src_stencil_weighted_2x_ser_p2_upy_dirichlet_ghosty,}, - }, - }, - // dirichlety skin - {.list={ - {fem_parproj_src_stencil_weighted_2x_ser_p1_iny_nondirichlety, fem_parproj_src_stencil_weighted_2x_ser_p1_loy_dirichlet_skiny, fem_parproj_src_stencil_weighted_2x_ser_p1_upy_dirichlet_skiny,}, - {fem_parproj_src_stencil_weighted_2x_ser_p2_iny_nondirichlety, fem_parproj_src_stencil_weighted_2x_ser_p2_loy_dirichlet_skiny, fem_parproj_src_stencil_weighted_2x_ser_p2_upy_dirichlet_skiny,}, - }, - }, - } - }, + {.list = + {// nondirichlety + {.list = {{fem_parproj_src_stencil_weighted_2x_ser_p1_iny_nondirichlety, + fem_parproj_src_stencil_weighted_2x_ser_p1_loy_nondirichlety, + fem_parproj_src_stencil_weighted_2x_ser_p1_upy_nondirichlety}, + {fem_parproj_src_stencil_weighted_2x_ser_p2_iny_nondirichlety, + fem_parproj_src_stencil_weighted_2x_ser_p2_loy_nondirichlety, + fem_parproj_src_stencil_weighted_2x_ser_p2_upy_nondirichlety}}}, + // dirichlety ghost + {.list = {{fem_parproj_src_stencil_weighted_2x_ser_p1_iny_nondirichlety, + fem_parproj_src_stencil_weighted_2x_ser_p1_loy_dirichlet_ghosty, + fem_parproj_src_stencil_weighted_2x_ser_p1_upy_dirichlet_ghosty}, + {fem_parproj_src_stencil_weighted_2x_ser_p2_iny_nondirichlety, + fem_parproj_src_stencil_weighted_2x_ser_p2_loy_dirichlet_ghosty, + fem_parproj_src_stencil_weighted_2x_ser_p2_upy_dirichlet_ghosty}}}, + // dirichlety skin + {.list = {{fem_parproj_src_stencil_weighted_2x_ser_p1_iny_nondirichlety, + fem_parproj_src_stencil_weighted_2x_ser_p1_loy_dirichlet_skiny, + fem_parproj_src_stencil_weighted_2x_ser_p1_upy_dirichlet_skiny}, + {fem_parproj_src_stencil_weighted_2x_ser_p2_iny_nondirichlety, + fem_parproj_src_stencil_weighted_2x_ser_p2_loy_dirichlet_skiny, + fem_parproj_src_stencil_weighted_2x_ser_p2_upy_dirichlet_skiny}}}}}, // 3x - {.list={ - // nondirichletz - {.list={ - {fem_parproj_src_stencil_weighted_3x_ser_p1_inz_nondirichletz, fem_parproj_src_stencil_weighted_3x_ser_p1_loz_nondirichletz, fem_parproj_src_stencil_weighted_3x_ser_p1_upz_nondirichletz,}, - {fem_parproj_src_stencil_weighted_3x_ser_p2_inz_nondirichletz, fem_parproj_src_stencil_weighted_3x_ser_p2_loz_nondirichletz, fem_parproj_src_stencil_weighted_3x_ser_p2_upz_nondirichletz,}, - }, - }, - // dirichletz ghost - {.list={ - {fem_parproj_src_stencil_weighted_3x_ser_p1_inz_nondirichletz, fem_parproj_src_stencil_weighted_3x_ser_p1_loz_dirichlet_ghostz, fem_parproj_src_stencil_weighted_3x_ser_p1_upz_dirichlet_ghostz,}, - {fem_parproj_src_stencil_weighted_3x_ser_p2_inz_nondirichletz, fem_parproj_src_stencil_weighted_3x_ser_p2_loz_dirichlet_ghostz, fem_parproj_src_stencil_weighted_3x_ser_p2_upz_dirichlet_ghostz,}, - }, - }, - // dirichletz skin - {.list={ - {fem_parproj_src_stencil_weighted_3x_ser_p1_inz_nondirichletz, fem_parproj_src_stencil_weighted_3x_ser_p1_loz_dirichlet_skinz, fem_parproj_src_stencil_weighted_3x_ser_p1_upz_dirichlet_skinz,}, - {fem_parproj_src_stencil_weighted_3x_ser_p2_inz_nondirichletz, fem_parproj_src_stencil_weighted_3x_ser_p2_loz_dirichlet_skinz, fem_parproj_src_stencil_weighted_3x_ser_p2_upz_dirichlet_skinz,}, - }, - }, - } - }, -}; + {.list = {// nondirichletz + {.list = {{fem_parproj_src_stencil_weighted_3x_ser_p1_inz_nondirichletz, + fem_parproj_src_stencil_weighted_3x_ser_p1_loz_nondirichletz, + fem_parproj_src_stencil_weighted_3x_ser_p1_upz_nondirichletz}, + {fem_parproj_src_stencil_weighted_3x_ser_p2_inz_nondirichletz, + fem_parproj_src_stencil_weighted_3x_ser_p2_loz_nondirichletz, + fem_parproj_src_stencil_weighted_3x_ser_p2_upz_nondirichletz}}}, + // dirichletz ghost + {.list = {{fem_parproj_src_stencil_weighted_3x_ser_p1_inz_nondirichletz, + fem_parproj_src_stencil_weighted_3x_ser_p1_loz_dirichlet_ghostz, + fem_parproj_src_stencil_weighted_3x_ser_p1_upz_dirichlet_ghostz}, + {fem_parproj_src_stencil_weighted_3x_ser_p2_inz_nondirichletz, + fem_parproj_src_stencil_weighted_3x_ser_p2_loz_dirichlet_ghostz, + fem_parproj_src_stencil_weighted_3x_ser_p2_upz_dirichlet_ghostz}}}, + // dirichletz skin + {.list = {{fem_parproj_src_stencil_weighted_3x_ser_p1_inz_nondirichletz, + fem_parproj_src_stencil_weighted_3x_ser_p1_loz_dirichlet_skinz, + fem_parproj_src_stencil_weighted_3x_ser_p1_upz_dirichlet_skinz}, + {fem_parproj_src_stencil_weighted_3x_ser_p2_inz_nondirichletz, + fem_parproj_src_stencil_weighted_3x_ser_p2_loz_dirichlet_skinz, + fem_parproj_src_stencil_weighted_3x_ser_p2_upz_dirichlet_skinz}}}}}}; // Function pointer type for kernels that convert the solution from nodal to // modal. -typedef void (*solstencil_t)(const double *sol_nodal_global, long nodeOff, - const long *globalIdxs, double *sol_modal_local); +typedef void (*solstencil_t)( + const double *sol_nodal_global, long nodeOff, const long *globalIdxs, double *sol_modal_local +); -typedef struct { solstencil_t kernels[3]; } solstencil_kern_list; // For use in kernel tables. +typedef struct { + solstencil_t kernels[3]; +} solstencil_kern_list; // For use in kernel tables. // Serendipity sol kernels. -GKYL_CU_D -static const solstencil_kern_list ser_solstencil_list[] = { - { fem_parproj_sol_stencil_1x_ser_p1, fem_parproj_sol_stencil_1x_ser_p2 }, - { fem_parproj_sol_stencil_2x_ser_p1, fem_parproj_sol_stencil_2x_ser_p2 }, - { fem_parproj_sol_stencil_3x_ser_p1, fem_parproj_sol_stencil_3x_ser_p2 } +GKYL_CU_D static const solstencil_kern_list ser_solstencil_list[] = { + {fem_parproj_sol_stencil_1x_ser_p1, fem_parproj_sol_stencil_1x_ser_p2}, + {fem_parproj_sol_stencil_2x_ser_p1, fem_parproj_sol_stencil_2x_ser_p2}, + {fem_parproj_sol_stencil_3x_ser_p1, fem_parproj_sol_stencil_3x_ser_p2} }; // Function pointer type for kernels that enforce biasing in LHS matrix. -typedef void (*bias_lhs_t)(const int *edge, const int *perp_dirs, const long *globalIdxs, gkyl_mat_triples *tri); +typedef void (*bias_lhs_t)( + const int *edge, const int *perp_dirs, const long *globalIdxs, gkyl_mat_triples *tri +); // For use in kernel tables. -typedef struct { bias_lhs_t kernels[2]; } bias_lhs_kern_loc_list; -typedef struct { bias_lhs_kern_loc_list list[2]; } bias_lhs_kern_bc_list; -typedef struct { bias_lhs_kern_bc_list list[2]; } bias_lhs_kern_dim_list; +typedef struct { + bias_lhs_t kernels[2]; +} bias_lhs_kern_loc_list; +typedef struct { + bias_lhs_kern_loc_list list[2]; +} bias_lhs_kern_bc_list; +typedef struct { + bias_lhs_kern_bc_list list[2]; +} bias_lhs_kern_dim_list; // Serendipity bias_lhs kernels. -static const bias_lhs_kern_dim_list ser_bias_lhs_list[] = { - // 1x - {.list = - { - // periodicy - { .list = { - {NULL, NULL}, - {NULL, NULL}, - }, - }, - // nonperiodicy - { .list = { - {NULL, NULL}, - {NULL, NULL}, - }, - }, - }, - }, - // 2x - {.list = - { - // periodicy - { .list = { - {fem_parproj_bias_line_lhs_2x_ser_p1_iny_periodicy, fem_parproj_bias_line_lhs_2x_ser_p1_upy_periodicy}, - {NULL, NULL}, - }, - }, - // nonperiodicy - { .list = { - {fem_parproj_bias_line_lhs_2x_ser_p1_iny_periodicy, fem_parproj_bias_line_lhs_2x_ser_p1_upy_nonperiodicy}, - {NULL, NULL}, - }, - }, - }, - }, - // 3x - {.list = - { - // periodicz - { .list = { - {fem_parproj_bias_line_lhs_3x_ser_p1_inz_periodicz, fem_parproj_bias_line_lhs_3x_ser_p1_upz_periodicz}, - {NULL, NULL}, - }, - }, - // nonperiodicz - { .list = { - {fem_parproj_bias_line_lhs_3x_ser_p1_inz_periodicz, fem_parproj_bias_line_lhs_3x_ser_p1_upz_nonperiodicz}, - {NULL, NULL}, - }, - }, - }, - }, - +static const bias_lhs_kern_dim_list + ser_bias_lhs_list[] = + { // 1x + {.list = + {// periodicy + {.list = {{NULL, NULL}, {NULL, NULL}}}, + // nonperiodicy + {.list = {{NULL, NULL}, {NULL, NULL}}} + }}, + // 2x + {.list = + {// periodicy + {.list = + {{fem_parproj_bias_line_lhs_2x_ser_p1_iny_periodicy, + fem_parproj_bias_line_lhs_2x_ser_p1_upy_periodicy}, + {NULL, NULL}}}, + // nonperiodicy + {.list = + {{fem_parproj_bias_line_lhs_2x_ser_p1_iny_periodicy, + fem_parproj_bias_line_lhs_2x_ser_p1_upy_nonperiodicy}, + {NULL, NULL}}} + }}, + // 3x + { + .list = + {// periodicz + {.list = + {{fem_parproj_bias_line_lhs_3x_ser_p1_inz_periodicz, + fem_parproj_bias_line_lhs_3x_ser_p1_upz_periodicz}, + {NULL, NULL}}}, + // nonperiodicz + {.list = + {{fem_parproj_bias_line_lhs_3x_ser_p1_inz_periodicz, fem_parproj_bias_line_lhs_3x_ser_p1_upz_nonperiodicz}, {NULL, NULL}} + } + } + } + }; // Function pointer type for kernels that enforce biasing in RHS source. -typedef void (*bias_src_t)(const int *edge, const int *perp_dirs, double val, long nodeOff, const long *globalIdxs, double *bsrc); +typedef void (*bias_src_t)( + const int *edge, const int *perp_dirs, double val, long nodeOff, const long *globalIdxs, + double *bsrc +); // For use in kernel tables. -typedef struct { bias_src_t kernels[2]; } bias_src_kern_loc_list; -typedef struct { bias_src_kern_loc_list list[2]; } bias_src_kern_bc_list; -typedef struct { bias_src_kern_bc_list list[2]; } bias_src_kern_dim_list; +typedef struct { + bias_src_t kernels[2]; +} bias_src_kern_loc_list; +typedef struct { + bias_src_kern_loc_list list[2]; +} bias_src_kern_bc_list; +typedef struct { + bias_src_kern_bc_list list[2]; +} bias_src_kern_dim_list; // Serendipity bias_src kernels. -GKYL_CU_D -static const bias_src_kern_dim_list ser_bias_src_list[] = { - // 1x - {.list = - { - // periodicy - { .list = - { - {NULL, NULL}, - {NULL, NULL}, - }, - }, - // nonperiodicy - { .list = - { - {NULL, NULL}, - {NULL, NULL}, - }, - }, - }, - }, - // 2x - {.list = - { - // periodicy - { .list = - { - {fem_parproj_bias_line_src_2x_ser_p1_iny_periodicy, fem_parproj_bias_line_src_2x_ser_p1_upy_periodicy}, - {NULL, NULL}, - }, - }, - // nonperiodicy - { .list = - { - {fem_parproj_bias_line_src_2x_ser_p1_iny_periodicy, fem_parproj_bias_line_src_2x_ser_p1_upy_nonperiodicy}, - {NULL, NULL}, - }, - }, - }, - }, - // 3x - {.list = - { - // periodicz - { .list = - { - {fem_parproj_bias_line_src_3x_ser_p1_inz_periodicz, fem_parproj_bias_line_src_3x_ser_p1_upz_periodicz}, - {NULL, NULL}, - }, - }, - // nonperiodicz - { .list = - { - {fem_parproj_bias_line_src_3x_ser_p1_inz_periodicz, fem_parproj_bias_line_src_3x_ser_p1_upz_nonperiodicz}, - {NULL, NULL}, - }, +GKYL_CU_D static const bias_src_kern_dim_list + ser_bias_src_list[] = + { // 1x + {.list = + {// periodicy + {.list = {{NULL, NULL}, {NULL, NULL}}}, + // nonperiodicy + {.list = {{NULL, NULL}, {NULL, NULL}}} + }}, + // 2x + {.list = + {// periodicy + {.list = + {{fem_parproj_bias_line_src_2x_ser_p1_iny_periodicy, + fem_parproj_bias_line_src_2x_ser_p1_upy_periodicy}, + {NULL, NULL}}}, + // nonperiodicy + {.list = + {{fem_parproj_bias_line_src_2x_ser_p1_iny_periodicy, + fem_parproj_bias_line_src_2x_ser_p1_upy_nonperiodicy}, + {NULL, NULL}}} + }}, + // 3x + { + .list = + {// periodicz + {.list = + {{fem_parproj_bias_line_src_3x_ser_p1_inz_periodicz, + fem_parproj_bias_line_src_3x_ser_p1_upz_periodicz}, + {NULL, NULL}}}, + // nonperiodicz + {.list = + {{fem_parproj_bias_line_src_3x_ser_p1_inz_periodicz, fem_parproj_bias_line_src_3x_ser_p1_upz_nonperiodicz}, {NULL, NULL}} + } + } } - } - }, }; // Functions that return the value to impose as Dirichlet BC. -typedef const double *(*get_diri_val_t)(int par_dir, int par_num_cells, - const int *idx, const struct gkyl_range *solve_range, const struct gkyl_array *phibc); +typedef const double *(*get_diri_val_t)( + int par_dir, int par_num_cells, const int *idx, const struct gkyl_range *solve_range, + const struct gkyl_array *phibc +); // No Dirichlet BC. -GKYL_CU_D -static const double *get_dirichlet_value_disabled(int par_dir, int par_num_cells, - const int *idx, const struct gkyl_range *solve_range, const struct gkyl_array *phibc) +GKYL_CU_D static const double *get_dirichlet_value_disabled( + int par_dir, int par_num_cells, const int *idx, const struct gkyl_range *solve_range, + const struct gkyl_array *phibc +) { return 0; } // Dirichlet BC using the ghost value. -GKYL_CU_D -static const double *get_dirichlet_value_enabled_ghost(int par_dir, int par_num_cells, - const int *idx, const struct gkyl_range *solve_range, const struct gkyl_array *phibc) +GKYL_CU_D static const double *get_dirichlet_value_enabled_ghost( + int par_dir, int par_num_cells, const int *idx, const struct gkyl_range *solve_range, + const struct gkyl_array *phibc +) { int dirichlet_idx[GKYL_MAX_CDIM]; - for (size_t d=0; db_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<2; k++) - l2gout[k] = CK(ser_loc2glob_list, basis->ndim, bckey[0], basis->poly_order, k); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < 2; k++) { + l2gout[k] = CK(ser_loc2glob_list, basis->ndim, bckey[0], basis->poly_order, k); + } + break; + default: + assert(false); + break; } } -GKYL_CU_D -static void -fem_parproj_choose_lhs_kernel(const struct gkyl_basis *basis, - enum gkyl_fem_parproj_bc_type bctype, bool isweighted, lhsstencil_t *lhsout) +GKYL_CU_D static void fem_parproj_choose_lhs_kernel( + const struct gkyl_basis *basis, enum gkyl_fem_parproj_bc_type bctype, bool isweighted, + lhsstencil_t *lhsout +) { int bckey[1] = {-1}; - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST || bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) { bckey[0] = 1; - else + } else { bckey[0] = 0; + } switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<3; k++) - lhsout[k] = isweighted? CK(ser_lhsstencil_list_weighted, basis->ndim, bckey[0], basis->poly_order, k) - : CK(ser_lhsstencil_list_noweight, basis->ndim, bckey[0], basis->poly_order, k); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < 3; k++) { + lhsout[k] = isweighted ? + CK(ser_lhsstencil_list_weighted, basis->ndim, bckey[0], basis->poly_order, k) : + CK(ser_lhsstencil_list_noweight, basis->ndim, bckey[0], basis->poly_order, k); + } + break; + default: + assert(false); + break; } } -GKYL_CU_D -static void -fem_parproj_choose_srcstencil_kernel(const struct gkyl_basis *basis, - enum gkyl_fem_parproj_bc_type bctype, bool isweighted, srcstencil_t *srcout) +GKYL_CU_D static void fem_parproj_choose_srcstencil_kernel( + const struct gkyl_basis *basis, enum gkyl_fem_parproj_bc_type bctype, bool isweighted, + srcstencil_t *srcout +) { int bckey[1] = {-1}; - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) { bckey[0] = 1; - else if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) + } else if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) { bckey[0] = 2; - else + } else { bckey[0] = 0; + } switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<3; k++) - srcout[k] = isweighted? CK(ser_srcstencil_list_weighted, basis->ndim, bckey[0], basis->poly_order, k) - : CK(ser_srcstencil_list_noweight, basis->ndim, bckey[0], basis->poly_order, k); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < 3; k++) { + srcout[k] = isweighted ? + CK(ser_srcstencil_list_weighted, basis->ndim, bckey[0], basis->poly_order, k) : + CK(ser_srcstencil_list_noweight, basis->ndim, bckey[0], basis->poly_order, k); + } + break; + default: + assert(false); + break; } } -GKYL_CU_D -static solstencil_t -fem_parproj_choose_solstencil_kernel(const struct gkyl_basis *basis) +GKYL_CU_D static solstencil_t fem_parproj_choose_solstencil_kernel(const struct gkyl_basis *basis) { switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_solstencil_list[basis->ndim-1].kernels[basis->poly_order-1]; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_solstencil_list[basis->ndim - 1].kernels[basis->poly_order - 1]; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static void -fem_parproj_choose_bias_lhs_kernels(const struct gkyl_basis* basis, - enum gkyl_fem_parproj_bc_type bctype, bias_lhs_t *blhs_out) +GKYL_CU_D static void fem_parproj_choose_bias_lhs_kernels( + const struct gkyl_basis *basis, enum gkyl_fem_parproj_bc_type bctype, bias_lhs_t *blhs_out +) { int poly_order = basis->poly_order; int ndim = basis->ndim; int bckey[1]; - bckey[0] = bctype == GKYL_FEM_PARPROJ_PERIODIC? 0 : 1; + bckey[0] = bctype == GKYL_FEM_PARPROJ_PERIODIC ? 0 : 1; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<2; k++) - blhs_out[k] = CK(ser_bias_lhs_list, ndim, bckey[0], poly_order, k); - - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < 2; k++) { + blhs_out[k] = CK(ser_bias_lhs_list, ndim, bckey[0], poly_order, k); + } + + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } } -GKYL_CU_D -static void -fem_parproj_choose_bias_src_kernels(const struct gkyl_basis* basis, - enum gkyl_fem_parproj_bc_type bctype, bias_src_t *bsrc_out) +GKYL_CU_D static void fem_parproj_choose_bias_src_kernels( + const struct gkyl_basis *basis, enum gkyl_fem_parproj_bc_type bctype, bias_src_t *bsrc_out +) { int poly_order = basis->poly_order; int ndim = basis->ndim; int bckey[1]; - bckey[0] = bctype == GKYL_FEM_PARPROJ_PERIODIC? 0 : 1; + bckey[0] = bctype == GKYL_FEM_PARPROJ_PERIODIC ? 0 : 1; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<2; k++) - bsrc_out[k] = CK(ser_bias_src_list, ndim, bckey[0], poly_order, k); - - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < 2; k++) { + bsrc_out[k] = CK(ser_bias_src_list, ndim, bckey[0], poly_order, k); + } + + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } } -GKYL_CU_D -static void -fem_parproj_choose_kernels(const struct gkyl_basis* basis, bool has_weight_lhs, bool has_weight_rhs, - enum gkyl_fem_parproj_bc_type bctype, bool use_gpu, struct gkyl_fem_parproj_kernels *kers) +GKYL_CU_D static void fem_parproj_choose_kernels( + const struct gkyl_basis *basis, bool has_weight_lhs, bool has_weight_rhs, + enum gkyl_fem_parproj_bc_type bctype, bool use_gpu, struct gkyl_fem_parproj_kernels *kers +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { @@ -809,27 +827,29 @@ fem_parproj_choose_kernels(const struct gkyl_basis* basis, bool has_weight_lhs, kers->solker = fem_parproj_choose_solstencil_kernel(basis); // Select function that obtains the value to impose as Dirichlet BC. - if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) + if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_GHOST) { kers->get_dirichlet_value = get_dirichlet_value_enabled_ghost; - else if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) + } else if (bctype == GKYL_FEM_PARPROJ_DIRICHLET_SKIN) { kers->get_dirichlet_value = get_dirichlet_value_enabled_skin; - else + } else { kers->get_dirichlet_value = get_dirichlet_value_disabled; + } // Select biasing kernels: fem_parproj_choose_bias_lhs_kernels(basis, bctype, kers->bias_lhs_ker); fem_parproj_choose_bias_src_kernels(basis, bctype, kers->bias_src_ker); } -GKYL_CU_DH -static inline int idx_to_inloup_ker(int num_cells, int idx) { +GKYL_CU_DH static inline int idx_to_inloup_ker(int num_cells, int idx) +{ // Return the index of the kernel (in the array of kernels) needed given the grid index. // This function is for kernels that differentiate between lower, interior // and upper cells. int iout = 0; - if (idx == 1) + if (idx == 1) { iout = 1; - else if (idx == num_cells) + } else if (idx == num_cells) { iout = 2; + } return iout; } diff --git a/gyrokinetic/zero/gkyl_fem_poisson_perp.h b/gyrokinetic/zero/gkyl_fem_poisson_perp.h index d68db9e9f8..2017356ff5 100644 --- a/gyrokinetic/zero/gkyl_fem_poisson_perp.h +++ b/gyrokinetic/zero/gkyl_fem_poisson_perp.h @@ -36,10 +36,12 @@ typedef struct gkyl_fem_poisson_perp gkyl_fem_poisson_perp; * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -struct gkyl_fem_poisson_perp* gkyl_fem_poisson_perp_new( +struct gkyl_fem_poisson_perp *gkyl_fem_poisson_perp_new( const struct gkyl_range *solve_range, const struct gkyl_rect_grid *grid, - const struct gkyl_basis basis, struct gkyl_poisson_bc *bcs, struct gkyl_poisson_bias_line_list* bias_line_list, - struct gkyl_array *epsilon, struct gkyl_array *kSq, bool use_gpu); + const struct gkyl_basis basis, struct gkyl_poisson_bc *bcs, + struct gkyl_poisson_bias_line_list *bias_line_list, struct gkyl_array *epsilon, + struct gkyl_array *kSq, bool use_gpu +); /** * Assign the right-side vector with the discontinuous (DG) source field. @@ -47,14 +49,14 @@ struct gkyl_fem_poisson_perp* gkyl_fem_poisson_perp_new( * @param up FEM poisson updater to run. * @param rhsin DG field to set as RHS source. */ -void gkyl_fem_poisson_perp_set_rhs(gkyl_fem_poisson_perp* up, struct gkyl_array *rhsin); +void gkyl_fem_poisson_perp_set_rhs(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsin); /** * Solve the linear problem. * * @param up FEM project updater to run. */ -void gkyl_fem_poisson_perp_solve(gkyl_fem_poisson_perp* up, struct gkyl_array *phiout); +void gkyl_fem_poisson_perp_solve(gkyl_fem_poisson_perp *up, struct gkyl_array *phiout); /** * Assign the left-side matrix. @@ -63,7 +65,9 @@ void gkyl_fem_poisson_perp_solve(gkyl_fem_poisson_perp* up, struct gkyl_array *p * @param epsilon Weight in Laplacian term. * @param kSq Linear factor in Helmholtz term. */ -void gkyl_fem_poisson_perp_update_lhs(gkyl_fem_poisson_perp* up, struct gkyl_array *epsilon, struct gkyl_array *kSq); +void gkyl_fem_poisson_perp_update_lhs( + gkyl_fem_poisson_perp *up, struct gkyl_array *epsilon, struct gkyl_array *kSq +); /** * Delete updater. diff --git a/gyrokinetic/zero/gkyl_fem_poisson_perp_priv.h b/gyrokinetic/zero/gkyl_fem_poisson_perp_priv.h index 3ed0c771d3..d5361abf51 100644 --- a/gyrokinetic/zero/gkyl_fem_poisson_perp_priv.h +++ b/gyrokinetic/zero/gkyl_fem_poisson_perp_priv.h @@ -8,536 +8,764 @@ #endif #ifndef GKYL_IPOW -# define GKYL_IPOW(a,e) (int)(pow(a,e)+0.5) +#define GKYL_IPOW(a, e) (int)(pow(a, e) + 0.5) #endif #define PERP_DIM_MAX 2 // Function pointer type for local-to-global mapping. -typedef void (*local2global_t)(const int *numCells, const int *idx, - long *globalIdxs); +typedef void (*local2global_t)(const int *numCells, const int *idx, long *globalIdxs); // For use in kernel tables. -typedef struct { local2global_t kernels[2]; } local2global_kern_loc_list_2x; -typedef struct { local2global_kern_loc_list_2x list[3]; } local2global_kern_bcx_list_2x; - -typedef struct { local2global_t kernels[4]; } local2global_kern_loc_list_3x; -typedef struct { local2global_kern_loc_list_3x list[3]; } local2global_kern_bcy_list_3x; -typedef struct { local2global_kern_bcy_list_3x list[2]; } local2global_kern_bcx_list_3x; +typedef struct { + local2global_t kernels[2]; +} local2global_kern_loc_list_2x; +typedef struct { + local2global_kern_loc_list_2x list[3]; +} local2global_kern_bcx_list_2x; + +typedef struct { + local2global_t kernels[4]; +} local2global_kern_loc_list_3x; +typedef struct { + local2global_kern_loc_list_3x list[3]; +} local2global_kern_bcy_list_3x; +typedef struct { + local2global_kern_bcy_list_3x list[2]; +} local2global_kern_bcx_list_3x; // Serendipity local-to-global kernels. -GKYL_CU_D -static const local2global_kern_bcx_list_2x ser_loc2glob_list_2x[] = { - // periodicx - { .list = - { - {NULL, NULL}, - {fem_poisson_perp_local_to_global_2x_ser_p1_inx_periodicx, fem_poisson_perp_local_to_global_2x_ser_p1_upx_periodicx}, - {NULL, NULL}, - }, - }, +GKYL_CU_D static const local2global_kern_bcx_list_2x ser_loc2glob_list_2x[] = { // periodicx + {.list = + {{NULL, NULL}, + {fem_poisson_perp_local_to_global_2x_ser_p1_inx_periodicx, + fem_poisson_perp_local_to_global_2x_ser_p1_upx_periodicx}, + {NULL, NULL}}}, // nonperiodicx - { .list = - { - {NULL, NULL}, - {fem_poisson_perp_local_to_global_2x_ser_p1_inx_nonperiodicx, fem_poisson_perp_local_to_global_2x_ser_p1_upx_nonperiodicx}, - {NULL, NULL}, - }, - }, + {.list = + {{NULL, NULL}, + {fem_poisson_perp_local_to_global_2x_ser_p1_inx_nonperiodicx, + fem_poisson_perp_local_to_global_2x_ser_p1_upx_nonperiodicx}, + {NULL, NULL}}} }; -GKYL_CU_D -static const local2global_kern_bcx_list_3x ser_loc2glob_list_3x[] = { - // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_local_to_global_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_perp_local_to_global_3x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_periodicx_upy_periodicy}, - {NULL, NULL, NULL, NULL}, - }, - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_local_to_global_3x_ser_p1_inx_periodicx_iny_nonperiodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_periodicx_iny_nonperiodicy, fem_poisson_perp_local_to_global_3x_ser_p1_inx_periodicx_upy_nonperiodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_periodicx_upy_nonperiodicy}, - {NULL, NULL, NULL, NULL}, - } - }} - }, - // nonperiodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_local_to_global_3x_ser_p1_inx_nonperiodicx_iny_periodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_nonperiodicx_iny_periodicy, fem_poisson_perp_local_to_global_3x_ser_p1_inx_nonperiodicx_upy_periodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_nonperiodicx_upy_periodicy}, - {NULL, NULL, NULL, NULL}, - } - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_local_to_global_3x_ser_p1_inx_nonperiodicx_iny_nonperiodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_nonperiodicx_iny_nonperiodicy, fem_poisson_perp_local_to_global_3x_ser_p1_inx_nonperiodicx_upy_nonperiodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, - {NULL, NULL, NULL, NULL}, - } - }} - } +GKYL_CU_D static const local2global_kern_bcx_list_3x + ser_loc2glob_list_3x[] = + { // periodicx + {.list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_perp_local_to_global_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_local_to_global_3x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_perp_local_to_global_3x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_perp_local_to_global_3x_ser_p1_upx_periodicx_upy_periodicy}, + {NULL, NULL, NULL, NULL}}}, + // nonperiodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_perp_local_to_global_3x_ser_p1_inx_periodicx_iny_nonperiodicy, + fem_poisson_perp_local_to_global_3x_ser_p1_upx_periodicx_iny_nonperiodicy, + fem_poisson_perp_local_to_global_3x_ser_p1_inx_periodicx_upy_nonperiodicy, + fem_poisson_perp_local_to_global_3x_ser_p1_upx_periodicx_upy_nonperiodicy}, + {NULL, NULL, NULL, NULL}}} + }}, + // nonperiodicx + { + .list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, {fem_poisson_perp_local_to_global_3x_ser_p1_inx_nonperiodicx_iny_periodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_nonperiodicx_iny_periodicy, fem_poisson_perp_local_to_global_3x_ser_p1_inx_nonperiodicx_upy_periodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_nonperiodicx_upy_periodicy}, {NULL, NULL, NULL, NULL}} + }, + // nonperiodicy + {.list = {{NULL, NULL, NULL, NULL}, {fem_poisson_perp_local_to_global_3x_ser_p1_inx_nonperiodicx_iny_nonperiodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_nonperiodicx_iny_nonperiodicy, fem_poisson_perp_local_to_global_3x_ser_p1_inx_nonperiodicx_upy_nonperiodicy, fem_poisson_perp_local_to_global_3x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, {NULL, NULL, NULL, NULL}} + } + } + } }; // Function pointer type for lhs kernels. -typedef void (*lhsstencil_t)(const double *epsilon, const double *kSq, const double *dx, const double *bcVals, - const long *globalIdxs, void *out); +typedef void (*lhsstencil_t)( + const double *epsilon, const double *kSq, const double *dx, const double *bcVals, + const long *globalIdxs, void *out +); // For use in kernel tables. -typedef struct { lhsstencil_t kernels[3]; } lhsstencil_kern_loc_list_2x; -typedef struct { lhsstencil_kern_loc_list_2x list[3]; } lhsstencil_kern_bcx_list_2x; - -typedef struct { lhsstencil_t kernels[9]; } lhsstencil_kern_loc_list_3x; -typedef struct { lhsstencil_kern_loc_list_3x list[3]; } lhsstencil_kern_bcy_list_3x; -typedef struct { lhsstencil_kern_bcy_list_3x list[9]; } lhsstencil_kern_bcx_list_3x; +typedef struct { + lhsstencil_t kernels[3]; +} lhsstencil_kern_loc_list_2x; +typedef struct { + lhsstencil_kern_loc_list_2x list[3]; +} lhsstencil_kern_bcx_list_2x; + +typedef struct { + lhsstencil_t kernels[9]; +} lhsstencil_kern_loc_list_3x; +typedef struct { + lhsstencil_kern_loc_list_3x list[3]; +} lhsstencil_kern_bcy_list_3x; +typedef struct { + lhsstencil_kern_bcy_list_3x list[9]; +} lhsstencil_kern_bcx_list_3x; // Serendipity lhs kernels. -GKYL_CU_D -static const lhsstencil_kern_bcx_list_2x ser_lhsstencil_list_2x[] = { - // periodicx - { .list = - { - {NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_2x_ser_p1_inx_periodicx, fem_poisson_perp_lhs_stencil_2x_ser_p1_lox_periodicx, fem_poisson_perp_lhs_stencil_2x_ser_p1_upx_periodicx}, - {NULL, NULL, NULL}, - }, - }, +GKYL_CU_D static const lhsstencil_kern_bcx_list_2x ser_lhsstencil_list_2x[] = { // periodicx + {.list = + {{NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_2x_ser_p1_inx_periodicx, + fem_poisson_perp_lhs_stencil_2x_ser_p1_lox_periodicx, + fem_poisson_perp_lhs_stencil_2x_ser_p1_upx_periodicx}, + {NULL, NULL, NULL}}}, // dirichletx-dirichletx - { .list = - { - {NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_2x_ser_p1_inx_periodicx, fem_poisson_perp_lhs_stencil_2x_ser_p1_lox_dirichletx, fem_poisson_perp_lhs_stencil_2x_ser_p1_upx_dirichletx}, - {NULL, NULL, NULL}, - }, - }, + {.list = + {{NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_2x_ser_p1_inx_periodicx, + fem_poisson_perp_lhs_stencil_2x_ser_p1_lox_dirichletx, + fem_poisson_perp_lhs_stencil_2x_ser_p1_upx_dirichletx}, + {NULL, NULL, NULL}}}, // dirichletx-neumannx - { .list = - { - {NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_2x_ser_p1_inx_periodicx, fem_poisson_perp_lhs_stencil_2x_ser_p1_lox_dirichletx, fem_poisson_perp_lhs_stencil_2x_ser_p1_upx_neumannx}, - {NULL, NULL, NULL}, - }, - }, + {.list = + {{NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_2x_ser_p1_inx_periodicx, + fem_poisson_perp_lhs_stencil_2x_ser_p1_lox_dirichletx, + fem_poisson_perp_lhs_stencil_2x_ser_p1_upx_neumannx}, + {NULL, NULL, NULL}}}, // neumannx-dirichletx - { .list = - { - {NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_2x_ser_p1_inx_periodicx, fem_poisson_perp_lhs_stencil_2x_ser_p1_lox_neumannx, fem_poisson_perp_lhs_stencil_2x_ser_p1_upx_dirichletx}, - {NULL, NULL, NULL}, - } - }, + {.list = + {{NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_2x_ser_p1_inx_periodicx, + fem_poisson_perp_lhs_stencil_2x_ser_p1_lox_neumannx, + fem_poisson_perp_lhs_stencil_2x_ser_p1_upx_dirichletx}, + {NULL, NULL, NULL}}} }; -GKYL_CU_D -static const lhsstencil_kern_bcx_list_3x ser_lhsstencil_list_3x[] = { - // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_upy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_upy_periodicy}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_upy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_upy_neumanny}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - } - }, +GKYL_CU_D static const lhsstencil_kern_bcx_list_3x ser_lhsstencil_list_3x[] = { // periodicx + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_upy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_upy_periodicy}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_upy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_upy_neumanny}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_periodicx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}}}, // dirichletx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_periodicy}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_neumanny}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_periodicy}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_neumanny}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}}}, // dirichletx-neumannx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_upy_periodicy}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_upy_neumanny}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_upy_periodicy}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_upy_neumanny}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_neumannx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}}}, // neumannx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_upy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_periodicy}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_neumanny}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - } - }, -}; + {.list = {// periodicy + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_upy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_periodicy}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_neumanny}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_perp_lhs_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}}}}; // Function pointer type for rhs source kernels. -typedef void (*srcstencil_t)(const double *epsilon, const double *dx, const double *rho, const double *bcVals, long perpOff, const long *globalIdxs, - double *bsrc); +typedef void (*srcstencil_t)( + const double *epsilon, const double *dx, const double *rho, const double *bcVals, long perpOff, + const long *globalIdxs, double *bsrc +); // For use in kernel tables. -typedef struct { srcstencil_t kernels[3]; } srcstencil_kern_loc_list_2x; -typedef struct { srcstencil_kern_loc_list_2x list[3]; } srcstencil_kern_bcx_list_2x; - -typedef struct { srcstencil_t kernels[9]; } srcstencil_kern_loc_list_3x; -typedef struct { srcstencil_kern_loc_list_3x list[3]; } srcstencil_kern_bcy_list_3x; -typedef struct { srcstencil_kern_bcy_list_3x list[9]; } srcstencil_kern_bcx_list_3x; +typedef struct { + srcstencil_t kernels[3]; +} srcstencil_kern_loc_list_2x; +typedef struct { + srcstencil_kern_loc_list_2x list[3]; +} srcstencil_kern_bcx_list_2x; + +typedef struct { + srcstencil_t kernels[9]; +} srcstencil_kern_loc_list_3x; +typedef struct { + srcstencil_kern_loc_list_3x list[3]; +} srcstencil_kern_bcy_list_3x; +typedef struct { + srcstencil_kern_bcy_list_3x list[9]; +} srcstencil_kern_bcx_list_3x; // Serendipity src kernels. -GKYL_CU_D -static const srcstencil_kern_bcx_list_2x ser_srcstencil_list_2x[] = { - // periodicx - { .list = - { - {NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_2x_ser_p1_inx_periodicx, fem_poisson_perp_src_stencil_2x_ser_p1_lox_periodicx, fem_poisson_perp_src_stencil_2x_ser_p1_upx_periodicx}, - {NULL, NULL, NULL}, - }, - }, +GKYL_CU_D static const srcstencil_kern_bcx_list_2x ser_srcstencil_list_2x[] = { // periodicx + {.list = + {{NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_2x_ser_p1_inx_periodicx, + fem_poisson_perp_src_stencil_2x_ser_p1_lox_periodicx, + fem_poisson_perp_src_stencil_2x_ser_p1_upx_periodicx}, + {NULL, NULL, NULL}}}, // dirichletx-dirichletx - { .list = - { - {NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_2x_ser_p1_inx_periodicx, fem_poisson_perp_src_stencil_2x_ser_p1_lox_dirichletx, fem_poisson_perp_src_stencil_2x_ser_p1_upx_dirichletx}, - {NULL, NULL, NULL}, - }, - }, + {.list = + {{NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_2x_ser_p1_inx_periodicx, + fem_poisson_perp_src_stencil_2x_ser_p1_lox_dirichletx, + fem_poisson_perp_src_stencil_2x_ser_p1_upx_dirichletx}, + {NULL, NULL, NULL}}}, // dirichletx-neumannx - { .list = - { - {NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_2x_ser_p1_inx_periodicx, fem_poisson_perp_src_stencil_2x_ser_p1_lox_dirichletx, fem_poisson_perp_src_stencil_2x_ser_p1_upx_neumannx}, - {NULL, NULL, NULL}, - }, - }, + {.list = + {{NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_2x_ser_p1_inx_periodicx, + fem_poisson_perp_src_stencil_2x_ser_p1_lox_dirichletx, + fem_poisson_perp_src_stencil_2x_ser_p1_upx_neumannx}, + {NULL, NULL, NULL}}}, // neumannx-dirichletx - { .list = - { - {NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_2x_ser_p1_inx_periodicx, fem_poisson_perp_src_stencil_2x_ser_p1_lox_neumannx, fem_poisson_perp_src_stencil_2x_ser_p1_upx_dirichletx}, - {NULL, NULL, NULL}, - }, - }, + {.list = + {{NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_2x_ser_p1_inx_periodicx, + fem_poisson_perp_src_stencil_2x_ser_p1_lox_neumannx, + fem_poisson_perp_src_stencil_2x_ser_p1_upx_dirichletx}, + {NULL, NULL, NULL}}} }; -GKYL_CU_D -static const srcstencil_kern_bcx_list_3x ser_srcstencil_list_3x[] = { - // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_upy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_upy_periodicy}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_upy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_upy_neumanny}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - } - }, +GKYL_CU_D static const srcstencil_kern_bcx_list_3x ser_srcstencil_list_3x[] = { // periodicx + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_upy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_upy_periodicy}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_upy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_upy_neumanny}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_periodicx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}}}, // dirichletx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_periodicy}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_neumanny}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_periodicy}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_neumanny}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}}}, // dirichletx-neumannx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_upy_periodicy}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_upy_neumanny}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_upy_periodicy}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_upy_neumanny}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_neumannx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}}}, // neumannx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_upy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_periodicy}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_neumanny}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, - }, - }, - } - }, -}; + {.list = {// periodicy + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_upy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_periodicy}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_neumanny}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_perp_src_stencil_3x_ser_p1_upx_dirichletx_upy_dirichlety}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}}}}; // Function pointer type for sol kernels. -typedef void (*solstencil_t)(const double *sol_nodal_global, long perpOff, const long *globalIdxs, double *sol_modal_local); +typedef void (*solstencil_t)( + const double *sol_nodal_global, long perpOff, const long *globalIdxs, double *sol_modal_local +); -typedef struct { solstencil_t kernels[3]; } solstencil_kern_list; +typedef struct { + solstencil_t kernels[3]; +} solstencil_kern_list; -GKYL_CU_D -static const solstencil_kern_list ser_solstencil_list[] = { - { NULL, NULL, NULL }, +GKYL_CU_D static const solstencil_kern_list ser_solstencil_list[] = { + {NULL, NULL, NULL}, // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, fem_poisson_perp_sol_stencil_2x_ser_p1, NULL }, // 1 + {NULL, fem_poisson_perp_sol_stencil_2x_ser_p1, NULL}, // 1 // 3x kernels - { NULL, fem_poisson_perp_sol_stencil_3x_ser_p1, NULL }, // 2 + {NULL, fem_poisson_perp_sol_stencil_3x_ser_p1, NULL} // 2 }; // Function pointer type for kernels that enforce biasing in LHS matrix. -typedef void (*bias_lhs_t)(const int *edge, const int *perp_dirs, const long *globalIdxs, gkyl_mat_triples *tri); +typedef void (*bias_lhs_t)( + const int *edge, const int *perp_dirs, const long *globalIdxs, gkyl_mat_triples *tri +); // For use in kernel tables. -typedef struct { bias_lhs_t kernels[2]; } bias_lhs_kern_loc_list_2x; -typedef struct { bias_lhs_kern_loc_list_2x list[3]; } bias_lhs_kern_bcx_list_2x; - -typedef struct { bias_lhs_t kernels[4]; } bias_lhs_kern_loc_list_3x; -typedef struct { bias_lhs_kern_loc_list_3x list[3]; } bias_lhs_kern_bcy_list_3x; -typedef struct { bias_lhs_kern_bcy_list_3x list[2]; } bias_lhs_kern_bcx_list_3x; +typedef struct { + bias_lhs_t kernels[2]; +} bias_lhs_kern_loc_list_2x; +typedef struct { + bias_lhs_kern_loc_list_2x list[3]; +} bias_lhs_kern_bcx_list_2x; + +typedef struct { + bias_lhs_t kernels[4]; +} bias_lhs_kern_loc_list_3x; +typedef struct { + bias_lhs_kern_loc_list_3x list[3]; +} bias_lhs_kern_bcy_list_3x; +typedef struct { + bias_lhs_kern_bcy_list_3x list[2]; +} bias_lhs_kern_bcx_list_3x; // Serendipity bias_lhs kernels. -static const bias_lhs_kern_bcx_list_2x ser_bias_lhs_list_2x[] = { - // periodicx - { .list = {{NULL, NULL}, - {fem_poisson_perp_bias_line_lhs_2x_ser_p1_inx, fem_poisson_perp_bias_line_lhs_2x_ser_p1_upx_periodicx}, - {NULL, NULL}}, }, +static const bias_lhs_kern_bcx_list_2x ser_bias_lhs_list_2x[] = { // periodicx + {.list = + {{NULL, NULL}, + {fem_poisson_perp_bias_line_lhs_2x_ser_p1_inx, + fem_poisson_perp_bias_line_lhs_2x_ser_p1_upx_periodicx}, + {NULL, NULL}}}, // nonperiodicx - { .list = {{NULL, NULL}, - {fem_poisson_perp_bias_line_lhs_2x_ser_p1_inx, fem_poisson_perp_bias_line_lhs_2x_ser_p1_upx_nonperiodicx}, - {NULL, NULL}}, } + {.list = + {{NULL, NULL}, + {fem_poisson_perp_bias_line_lhs_2x_ser_p1_inx, + fem_poisson_perp_bias_line_lhs_2x_ser_p1_upx_nonperiodicx}, + {NULL, NULL}}} }; -static const bias_lhs_kern_bcx_list_3x ser_bias_lhs_list_3x[] = { - // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_periodicx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_upy_periodicy, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_periodicx_upy_periodicy}, - {NULL, NULL, NULL, NULL}}, - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_periodicx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_upy_nonperiodicy, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_periodicx_upy_nonperiodicy}, - {NULL, NULL, NULL, NULL},} - }} - }, - // nonperiodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_nonperiodicx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_upy_periodicy, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_nonperiodicx_upy_periodicy}, - {NULL, NULL, NULL, NULL}}, - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_nonperiodicx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_upy_nonperiodicy, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, - {NULL, NULL, NULL, NULL},} - }} - } +static const bias_lhs_kern_bcx_list_3x + ser_bias_lhs_list_3x[] = + { // periodicx + {.list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_iny, + fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_periodicx_iny, + fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_upy_periodicy, + fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_periodicx_upy_periodicy}, + {NULL, NULL, NULL, NULL}}}, + // nonperiodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_iny, + fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_periodicx_iny, + fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_upy_nonperiodicy, + fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_periodicx_upy_nonperiodicy}, + {NULL, NULL, NULL, NULL}}} + }}, + // nonperiodicx + { + .list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, {fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_nonperiodicx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_upy_periodicy, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_nonperiodicx_upy_periodicy}, {NULL, NULL, NULL, NULL}} + }, + // nonperiodicy + {.list = {{NULL, NULL, NULL, NULL}, {fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_nonperiodicx_iny, fem_poisson_perp_bias_line_lhs_3x_ser_p1_inx_upy_nonperiodicy, fem_poisson_perp_bias_line_lhs_3x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, {NULL, NULL, NULL, NULL}} + } + } + } }; // Function pointer type for kernels that enforce biasing in RHS source. -typedef void (*bias_src_t)(const int *edge, const int *perp_dirs, double val, long perpOff, const long *globalIdxs, double *bsrc); +typedef void (*bias_src_t)( + const int *edge, const int *perp_dirs, double val, long perpOff, const long *globalIdxs, + double *bsrc +); // For use in kernel tables. -typedef struct { bias_src_t kernels[2]; } bias_src_kern_loc_list_2x; -typedef struct { bias_src_kern_loc_list_2x list[3]; } bias_src_kern_bcx_list_2x; - -typedef struct { bias_src_t kernels[4]; } bias_src_kern_loc_list_3x; -typedef struct { bias_src_kern_loc_list_3x list[3]; } bias_src_kern_bcy_list_3x; -typedef struct { bias_src_kern_bcy_list_3x list[2]; } bias_src_kern_bcx_list_3x; +typedef struct { + bias_src_t kernels[2]; +} bias_src_kern_loc_list_2x; +typedef struct { + bias_src_kern_loc_list_2x list[3]; +} bias_src_kern_bcx_list_2x; + +typedef struct { + bias_src_t kernels[4]; +} bias_src_kern_loc_list_3x; +typedef struct { + bias_src_kern_loc_list_3x list[3]; +} bias_src_kern_bcy_list_3x; +typedef struct { + bias_src_kern_bcy_list_3x list[2]; +} bias_src_kern_bcx_list_3x; // Serendipity bias_src kernels. -GKYL_CU_D -static const bias_src_kern_bcx_list_2x ser_bias_src_list_2x[] = { - // periodicx - { .list = {{NULL, NULL}, - {fem_poisson_perp_bias_line_src_2x_ser_p1_inx, fem_poisson_perp_bias_line_src_2x_ser_p1_upx_periodicx}, - {NULL, NULL}}, }, +GKYL_CU_D static const bias_src_kern_bcx_list_2x ser_bias_src_list_2x[] = { // periodicx + {.list = + {{NULL, NULL}, + {fem_poisson_perp_bias_line_src_2x_ser_p1_inx, + fem_poisson_perp_bias_line_src_2x_ser_p1_upx_periodicx}, + {NULL, NULL}}}, // nonperiodicx - { .list = {{NULL, NULL}, - {fem_poisson_perp_bias_line_src_2x_ser_p1_inx, fem_poisson_perp_bias_line_src_2x_ser_p1_upx_nonperiodicx}, - {NULL, NULL}}, } + {.list = + {{NULL, NULL}, + {fem_poisson_perp_bias_line_src_2x_ser_p1_inx, + fem_poisson_perp_bias_line_src_2x_ser_p1_upx_nonperiodicx}, + {NULL, NULL}}} }; -GKYL_CU_D -static const bias_src_kern_bcx_list_3x ser_bias_src_list_3x[] = { - // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_bias_line_src_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_periodicx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_inx_upy_periodicy, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_periodicx_upy_periodicy}, - {NULL, NULL, NULL, NULL}}, - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_bias_line_src_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_periodicx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_inx_upy_nonperiodicy, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_periodicx_upy_nonperiodicy}, - {NULL, NULL, NULL, NULL},} - }} - }, - // nonperiodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_bias_line_src_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_nonperiodicx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_inx_upy_periodicy, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_nonperiodicx_upy_periodicy}, - {NULL, NULL, NULL, NULL}}, - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_perp_bias_line_src_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_nonperiodicx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_inx_upy_nonperiodicy, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, - {NULL, NULL, NULL, NULL},} - }} - } +GKYL_CU_D static const bias_src_kern_bcx_list_3x + ser_bias_src_list_3x[] = + { // periodicx + {.list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_perp_bias_line_src_3x_ser_p1_inx_iny, + fem_poisson_perp_bias_line_src_3x_ser_p1_upx_periodicx_iny, + fem_poisson_perp_bias_line_src_3x_ser_p1_inx_upy_periodicy, + fem_poisson_perp_bias_line_src_3x_ser_p1_upx_periodicx_upy_periodicy}, + {NULL, NULL, NULL, NULL}}}, + // nonperiodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_perp_bias_line_src_3x_ser_p1_inx_iny, + fem_poisson_perp_bias_line_src_3x_ser_p1_upx_periodicx_iny, + fem_poisson_perp_bias_line_src_3x_ser_p1_inx_upy_nonperiodicy, + fem_poisson_perp_bias_line_src_3x_ser_p1_upx_periodicx_upy_nonperiodicy}, + {NULL, NULL, NULL, NULL}}} + }}, + // nonperiodicx + { + .list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, {fem_poisson_perp_bias_line_src_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_nonperiodicx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_inx_upy_periodicy, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_nonperiodicx_upy_periodicy}, {NULL, NULL, NULL, NULL}} + }, + // nonperiodicy + {.list = {{NULL, NULL, NULL, NULL}, {fem_poisson_perp_bias_line_src_3x_ser_p1_inx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_nonperiodicx_iny, fem_poisson_perp_bias_line_src_3x_ser_p1_inx_upy_nonperiodicy, fem_poisson_perp_bias_line_src_3x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, {NULL, NULL, NULL, NULL}} + } + } + } }; // "Choose Kernel" based on polyorder, stencil location and BCs. -#define CK2x(lst,poly_order,loc,bcx) lst[bcx].list[poly_order].kernels[loc] -#define CK3x(lst,poly_order,loc,bcx,bcy) lst[bcx].list[bcy].list[poly_order].kernels[loc] +#define CK2x(lst, poly_order, loc, bcx) lst[bcx].list[poly_order].kernels[loc] +#define CK3x(lst, poly_order, loc, bcx, bcy) lst[bcx].list[bcy].list[poly_order].kernels[loc] // Struct containing pointers to the various kernels. Needed to create a similar struct on the GPU. -struct gkyl_fem_poisson_perp_kernels { +struct gkyl_fem_poisson_perp_kernels { // Pointer to local-to-global kernels. 2^3, 2 (interior and upper) in each direction. local2global_t l2g[8]; @@ -555,7 +783,7 @@ struct gkyl_fem_poisson_perp_kernels { }; // Type of function used to enforce biasing in the RHS src. -typedef void (*bias_src_func_t)(gkyl_fem_poisson_perp* up, struct gkyl_array *rhsin); +typedef void (*bias_src_func_t)(gkyl_fem_poisson_perp *up, struct gkyl_array *rhsin); // Updater type struct gkyl_fem_poisson_perp { @@ -583,7 +811,8 @@ struct gkyl_fem_poisson_perp { double *rhs_avg, mavgfac; double *rhs_avg_cu; - double bcvals[PERP_DIM_MAX*2*3]; // BC values, bc[0]*phi+bc[1]*d(phi)/dx=phi[3] at each boundary. + double + bcvals[PERP_DIM_MAX * 2 * 3]; // BC values, bc[0]*phi+bc[1]*d(phi)/dx=phi[3] at each boundary. double *bcvals_cu; // BC values, bc[0]*phi+bc[1]*d(phi)/dx=phi[3] at each boundary. const struct gkyl_range *solve_range; @@ -605,7 +834,8 @@ struct gkyl_fem_poisson_perp { #ifdef GKYL_HAVE_CUDA struct gkyl_culinsolver_prob *prob_cu; struct gkyl_array *brhs_cu; - struct gkyl_array *csr_val_idx; // Indices into the csr_val array in cudss_ops.cu, to reset the LHS matrix. + struct gkyl_array + *csr_val_idx; // Indices into the csr_val array in cudss_ops.cu, to reset the LHS matrix. #endif long *globalidx; @@ -623,11 +853,14 @@ struct gkyl_fem_poisson_perp { bias_src_func_t bias_line_src; // Function to enforce biasing in RHS source. }; -void -fem_poisson_perp_choose_kernels_cu(const struct gkyl_basis* basis, const struct gkyl_poisson_bc* bcs, const bool *isdirperiodic, struct gkyl_fem_poisson_perp_kernels *kers); +void fem_poisson_perp_choose_kernels_cu( + const struct gkyl_basis *basis, const struct gkyl_poisson_bc *bcs, const bool *isdirperiodic, + struct gkyl_fem_poisson_perp_kernels *kers +); -static long -gkyl_fem_poisson_perp_global_num_nodes(int ndim, int poly_order, int basis_type, const int *num_cells, bool *isdirperiodic) +static long gkyl_fem_poisson_perp_global_num_nodes( + int ndim, int poly_order, int basis_type, const int *num_cells, bool *isdirperiodic +) { if (ndim == 2) { if (poly_order == 1) { @@ -637,8 +870,7 @@ gkyl_fem_poisson_perp_global_num_nodes(int ndim, int poly_order, int basis_type, return fem_poisson_perp_num_nodes_global_2x_ser_p1_nonperiodicx(num_cells); } } - } - else { + } else { if (poly_order == 1) { if (isdirperiodic[0] && isdirperiodic[1]) { return fem_poisson_perp_num_nodes_global_3x_ser_p1_periodicx_periodicy(num_cells); @@ -651,201 +883,226 @@ gkyl_fem_poisson_perp_global_num_nodes(int ndim, int poly_order, int basis_type, } } } - assert(false); // Other dimensionalities not supported. + assert(false); // Other dimensionalities not supported. return -1; } -GKYL_CU_D -static void -fem_poisson_perp_choose_local2global_kernels(const struct gkyl_basis* basis, const bool *isdirperiodic, local2global_t *l2gout) +GKYL_CU_D static void fem_poisson_perp_choose_local2global_kernels( + const struct gkyl_basis *basis, const bool *isdirperiodic, local2global_t *l2gout +) { int poly_order = basis->poly_order; int ndim = basis->ndim; - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; int bckey[GKYL_MAX_CDIM] = {-1}; - for (int d=0; db_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; kpoly_order; int ndim = basis->ndim; - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; int bckey[GKYL_MAX_CDIM] = {-1, -1, -1}; - for (int d=0; dlo_type[d]==GKYL_POISSON_PERIODIC && bcs->up_type[d]==GKYL_POISSON_PERIODIC ) { bckey[d] = 0; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_DIRICHLET) { bckey[d] = 1; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_NEUMANN ) { bckey[d] = 2; } - else if (bcs->lo_type[d]==GKYL_POISSON_NEUMANN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET) { bckey[d] = 3; } - else { assert(false); } + for (int d = 0; d < ndim_perp; d++) { + if (bcs->lo_type[d] == GKYL_POISSON_PERIODIC && bcs->up_type[d] == GKYL_POISSON_PERIODIC) { + bckey[d] = 0; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 1; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_NEUMANN) { + bckey[d] = 2; + } else if (bcs->lo_type[d] == GKYL_POISSON_NEUMANN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 3; + } else { + assert(false); + } }; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; kpoly_order; int ndim = basis->ndim; - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; int bckey[GKYL_MAX_CDIM] = {-1, -1, -1}; - for (int d=0; dlo_type[d]==GKYL_POISSON_PERIODIC && bcs->up_type[d]==GKYL_POISSON_PERIODIC ) { bckey[d] = 0; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_DIRICHLET) { bckey[d] = 1; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_NEUMANN ) { bckey[d] = 2; } - else if (bcs->lo_type[d]==GKYL_POISSON_NEUMANN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET) { bckey[d] = 3; } - else { assert(false); } + for (int d = 0; d < ndim_perp; d++) { + if (bcs->lo_type[d] == GKYL_POISSON_PERIODIC && bcs->up_type[d] == GKYL_POISSON_PERIODIC) { + bckey[d] = 0; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 1; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_NEUMANN) { + bckey[d] = 2; + } else if (bcs->lo_type[d] == GKYL_POISSON_NEUMANN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 3; + } else { + assert(false); + } }; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; kndim; int poly_order = basis->poly_order; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_solstencil_list[dim].kernels[poly_order]; - - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_solstencil_list[dim].kernels[poly_order]; + + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static void -fem_poisson_perp_choose_bias_lhs_kernels(const struct gkyl_basis* basis, - const bool *isdirperiodic, bias_lhs_t *blhs_out) +GKYL_CU_D static void fem_poisson_perp_choose_bias_lhs_kernels( + const struct gkyl_basis *basis, const bool *isdirperiodic, bias_lhs_t *blhs_out +) { int poly_order = basis->poly_order; int ndim = basis->ndim; - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; int bckey[GKYL_MAX_CDIM] = {-1}; - for (int d=0; db_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<(int)(pow(2,ndim_perp)+0.5); k++) { - if (ndim == 2) { - blhs_out[k] = CK2x(ser_bias_lhs_list_2x, poly_order, k, bckey[0]); - } else if (ndim == 3) { - blhs_out[k] = CK3x(ser_bias_lhs_list_3x, poly_order, k, bckey[0], bckey[1]); - } + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < (int)(pow(2, ndim_perp) + 0.5); k++) { + if (ndim == 2) { + blhs_out[k] = CK2x(ser_bias_lhs_list_2x, poly_order, k, bckey[0]); + } else if (ndim == 3) { + blhs_out[k] = CK3x(ser_bias_lhs_list_3x, poly_order, k, bckey[0], bckey[1]); } - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + } + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } } -GKYL_CU_D -static void -fem_poisson_perp_choose_bias_src_kernels(const struct gkyl_basis* basis, - const bool *isdirperiodic, bias_src_t *bsrc_out) +GKYL_CU_D static void fem_poisson_perp_choose_bias_src_kernels( + const struct gkyl_basis *basis, const bool *isdirperiodic, bias_src_t *bsrc_out +) { int poly_order = basis->poly_order; int ndim = basis->ndim; - int ndim_perp = ndim-1; + int ndim_perp = ndim - 1; int bckey[GKYL_MAX_CDIM] = {-1}; - for (int d=0; db_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<(int)(pow(2,ndim_perp)+0.5); k++) { - if (ndim == 2) { - bsrc_out[k] = CK2x(ser_bias_src_list_2x, poly_order, k, bckey[0]); - } else if (ndim == 3) { - bsrc_out[k] = CK3x(ser_bias_src_list_3x, poly_order, k, bckey[0], bckey[1]); - } + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < (int)(pow(2, ndim_perp) + 0.5); k++) { + if (ndim == 2) { + bsrc_out[k] = CK2x(ser_bias_src_list_2x, poly_order, k, bckey[0]); + } else if (ndim == 3) { + bsrc_out[k] = CK3x(ser_bias_src_list_3x, poly_order, k, bckey[0], bckey[1]); } - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + } + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } } -GKYL_CU_DH -static inline int idx_to_inup_ker(const int dim, const int *num_cells, const int *idx) { +GKYL_CU_DH static inline int idx_to_inup_ker(const int dim, const int *num_cells, const int *idx) +{ // Return the index of the kernel (in the array of kernels) needed given the grid index. // This function is for kernels that differentiate between upper cells and // elsewhere. int iout = 0; - for (int d=0; d // Struct containing the pointers to auxiliary fields. -struct gkyl_gk_anomalous_diffusion_auxfields { +struct gkyl_gk_anomalous_diffusion_auxfields { const struct gkyl_array *nu; // Diffusivity. const struct gkyl_array *jacobgeo_inv; // Reciprocal of the conf-space Jacobian. }; @@ -24,9 +24,11 @@ struct gkyl_gk_anomalous_diffusion_auxfields { * @param use_gpu Whether to run on host or device. * @return Pointer to diffusion equation object */ -struct gkyl_dg_eqn* gkyl_gk_anomalous_diffusion_new(const struct gkyl_basis *basis, - const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, - enum gkyl_gyrokinetic_bc_type bc_x_lower, enum gkyl_gyrokinetic_bc_type bc_x_upper, bool use_gpu); +struct gkyl_dg_eqn *gkyl_gk_anomalous_diffusion_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, + const struct gkyl_range *conf_range, enum gkyl_gyrokinetic_bc_type bc_x_lower, + enum gkyl_gyrokinetic_bc_type bc_x_upper, bool use_gpu +); /** * Set the auxiliary fields (e.g. diffusivity). @@ -34,5 +36,6 @@ struct gkyl_dg_eqn* gkyl_gk_anomalous_diffusion_new(const struct gkyl_basis *bas * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_gk_anomalous_diffusion_set_auxfields(const struct gkyl_dg_eqn* eqn, - struct gkyl_gk_anomalous_diffusion_auxfields auxin); +void gkyl_gk_anomalous_diffusion_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_gk_anomalous_diffusion_auxfields auxin +); diff --git a/gyrokinetic/zero/gkyl_gk_anomalous_diffusion_priv.h b/gyrokinetic/zero/gkyl_gk_anomalous_diffusion_priv.h index 31f3609b32..fbbd8e88ab 100644 --- a/gyrokinetic/zero/gkyl_gk_anomalous_diffusion_priv.h +++ b/gyrokinetic/zero/gkyl_gk_anomalous_diffusion_priv.h @@ -5,14 +5,17 @@ #include // Types for various kernels -typedef double (*gk_anom_diff_surf_t)(const double *wc, const double *dxc, - const double *nul, const double *nuc, const double *nur, +typedef double (*gk_anom_diff_surf_t)( + const double *wc, const double *dxc, const double *nul, const double *nuc, const double *nur, const double *jacobgeo_invl, const double *jacobgeo_invc, const double *jacobgeo_invr, - const double *Jfl, const double *Jfc, const double *Jfr, double* GKYL_RESTRICT out); + const double *Jfl, const double *Jfc, const double *Jfr, double *GKYL_RESTRICT out +); -typedef double (*gk_anom_diff_boundary_surf_t)(const double *wSkin, const double *dxSkin, - const double *nuEdge, const double *nuSkin, const double *jacobgeo_invEdge, const double *jacobgeo_invSkin, - int edge, const double *JfEdge, const double *JfSkin, double* GKYL_RESTRICT out); +typedef double (*gk_anom_diff_boundary_surf_t)( + const double *wSkin, const double *dxSkin, const double *nuEdge, const double *nuSkin, + const double *jacobgeo_invEdge, const double *jacobgeo_invSkin, int edge, const double *JfEdge, + const double *JfSkin, double *GKYL_RESTRICT out +); struct gk_anomalous_diffusion { struct gkyl_dg_eqn eqn; @@ -24,14 +27,24 @@ struct gk_anomalous_diffusion { int num_basis; }; -#define _cfnu(idx) (const double *) gkyl_array_cfetch(gkad->auxfields.nu, gkyl_range_idx(&gkad->conf_range, idx)) +#define _cfnu(idx) \ + (const double *)gkyl_array_cfetch(gkad->auxfields.nu, gkyl_range_idx(&gkad->conf_range, idx)) -#define _cfJacInv(idx) (const double *) gkyl_array_cfetch(gkad->auxfields.jacobgeo_inv, gkyl_range_idx(&gkad->conf_range, idx)) +#define _cfJacInv(idx) \ + (const double *)gkyl_array_cfetch( \ + gkad->auxfields.jacobgeo_inv, gkyl_range_idx(&gkad->conf_range, idx) \ + ) // for use in kernel tables -typedef struct { vol_termf_t kernels[2]; } gkyl_gk_anomalous_diffusion_vol_kern_list; -typedef struct { gk_anom_diff_surf_t kernels[2]; } gkyl_gk_anomalous_diffusion_surf_kern_list; -typedef struct { gk_anom_diff_boundary_surf_t kernels[2]; } gkyl_gk_anomalous_diffusion_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[2]; +} gkyl_gk_anomalous_diffusion_vol_kern_list; +typedef struct { + gk_anom_diff_surf_t kernels[2]; +} gkyl_gk_anomalous_diffusion_surf_kern_list; +typedef struct { + gk_anom_diff_boundary_surf_t kernels[2]; +} gkyl_gk_anomalous_diffusion_boundary_surf_kern_list; // ............... Inhomogeneous (spatially varying) diffusion coefficient ............... // @@ -39,142 +52,166 @@ typedef struct { gk_anom_diff_boundary_surf_t kernels[2]; } gkyl_gk_anomalous_di // Need to be separated like this for GPU build // 2x2v -GKYL_CU_DH static double ker_gk_anomalous_diffusion_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_gk_anomalous_diffusion_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct gk_anomalous_diffusion* gkad = container_of(eqn, struct gk_anomalous_diffusion, eqn); + struct gk_anomalous_diffusion *gkad = container_of(eqn, struct gk_anomalous_diffusion, eqn); return gk_anomalous_diffusion_vol_2x2v_ser_p1(xc, dx, _cfnu(idx), _cfJacInv(idx), qIn, qRhsOut); } // Volume kernel list. -GKYL_CU_D -static const gkyl_gk_anomalous_diffusion_vol_kern_list ser_vol_kernels[] = { - { NULL, NULL }, // 1x1v - { NULL, NULL }, // 1x2v - {ker_gk_anomalous_diffusion_vol_2x2v_ser_p1,NULL}, // 2x2v - { NULL, NULL }, // 3x2v +GKYL_CU_D static const gkyl_gk_anomalous_diffusion_vol_kern_list ser_vol_kernels[] = { + {NULL, NULL}, // 1x1v + {NULL, NULL}, // 1x2v + {ker_gk_anomalous_diffusion_vol_2x2v_ser_p1, NULL}, // 2x2v + {NULL, NULL} // 3x2v }; // Surface kernel list: x-direction GKYL_CU_D static const gkyl_gk_anomalous_diffusion_surf_kern_list ser_gyrokinetic_surfx_kernels[] = { - { NULL, NULL }, // 1x1v - { NULL, NULL }, // 1x2v - { gk_anomalous_diffusion_surfx_2x2v_ser_p1, NULL }, // 2x2v - { NULL, NULL }, // 3x2v + {NULL, NULL}, // 1x1v + {NULL, NULL}, // 1x2v + {gk_anomalous_diffusion_surfx_2x2v_ser_p1, NULL}, // 2x2v + {NULL, NULL} // 3x2v }; // Zero-flux boundary surface kernel list: x-direction -GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels[] = { - { NULL, NULL }, // 1x1v - { NULL, NULL }, // 1x2v - { gk_anomalous_diffusion_boundary_surfx_lower_zero_flux_2x2v_ser_p1, NULL }, // 2x2v - { NULL, NULL }, // 3x2v +GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list + ser_gyrokinetic_boundary_surfx_lower_zeroflux_kernels[] = { + {NULL, NULL}, // 1x1v + {NULL, NULL}, // 1x2v + {gk_anomalous_diffusion_boundary_surfx_lower_zero_flux_2x2v_ser_p1, NULL}, // 2x2v + {NULL, NULL} // 3x2v }; -GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels[] = { - { NULL, NULL }, // 1x1v - { NULL, NULL }, // 1x2v - { gk_anomalous_diffusion_boundary_surfx_upper_zero_flux_2x2v_ser_p1, NULL }, // 2x2v - { NULL, NULL }, // 3x2v +GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list + ser_gyrokinetic_boundary_surfx_upper_zeroflux_kernels[] = { + {NULL, NULL}, // 1x1v + {NULL, NULL}, // 1x2v + {gk_anomalous_diffusion_boundary_surfx_upper_zero_flux_2x2v_ser_p1, NULL}, // 2x2v + {NULL, NULL} // 3x2v }; // Boundary-local boundary surface kernel list: x-direction -GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list ser_gyrokinetic_boundary_surfx_lower_boundlocal_kernels[] = { - { NULL, NULL }, // 1x1v - { NULL, NULL }, // 1x2v - { gk_anomalous_diffusion_boundary_surfx_lower_bound_local_2x2v_ser_p1, NULL }, // 2x2v - { NULL, NULL }, // 3x2v +GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list + ser_gyrokinetic_boundary_surfx_lower_boundlocal_kernels[] = { + {NULL, NULL}, // 1x1v + {NULL, NULL}, // 1x2v + {gk_anomalous_diffusion_boundary_surfx_lower_bound_local_2x2v_ser_p1, NULL}, // 2x2v + {NULL, NULL} // 3x2v }; -GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list ser_gyrokinetic_boundary_surfx_upper_boundlocal_kernels[] = { - { NULL, NULL }, // 1x1v - { NULL, NULL }, // 1x2v - { gk_anomalous_diffusion_boundary_surfx_upper_bound_local_2x2v_ser_p1, NULL }, // 2x2v - { NULL, NULL }, // 3x2v +GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list + ser_gyrokinetic_boundary_surfx_upper_boundlocal_kernels[] = { + {NULL, NULL}, // 1x1v + {NULL, NULL}, // 1x2v + {gk_anomalous_diffusion_boundary_surfx_upper_bound_local_2x2v_ser_p1, NULL}, // 2x2v + {NULL, NULL} // 3x2v }; // Bound-local boundary diagnostic kernel list: x-direction -GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list ser_gyrokinetic_boundary_diagx_lower_boundlocal_kernels[] = { - { NULL, NULL }, // 1x1v - { NULL, NULL }, // 1x2v - { gk_anomalous_diffusion_boundary_diagx_lower_bound_local_2x2v_ser_p1, NULL }, // 2x2v - { NULL, NULL }, // 3x2v +GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list + ser_gyrokinetic_boundary_diagx_lower_boundlocal_kernels[] = { + {NULL, NULL}, // 1x1v + {NULL, NULL}, // 1x2v + {gk_anomalous_diffusion_boundary_diagx_lower_bound_local_2x2v_ser_p1, NULL}, // 2x2v + {NULL, NULL} // 3x2v }; -GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list ser_gyrokinetic_boundary_diagx_upper_boundlocal_kernels[] = { - { NULL, NULL }, // 1x1v - { NULL, NULL }, // 1x2v - { gk_anomalous_diffusion_boundary_diagx_upper_bound_local_2x2v_ser_p1, NULL }, // 2x2v - { NULL, NULL }, // 3x2v +GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list + ser_gyrokinetic_boundary_diagx_upper_boundlocal_kernels[] = { + {NULL, NULL}, // 1x1v + {NULL, NULL}, // 1x2v + {gk_anomalous_diffusion_boundary_diagx_upper_bound_local_2x2v_ser_p1, NULL}, // 2x2v + {NULL, NULL} // 3x2v }; // Bound-recovery boundary diagnostic kernel list: x-direction -GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels[] = { - { NULL, NULL }, // 1x1v - { NULL, NULL }, // 1x2v - { gk_anomalous_diffusion_boundary_diagx_lower_bound_recovery_2x2v_ser_p1, NULL }, // 2x2v - { NULL, NULL }, // 3x2v +GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list + ser_gyrokinetic_boundary_diagx_lower_boundrecovery_kernels[] = { + {NULL, NULL}, // 1x1v + {NULL, NULL}, // 1x2v + {gk_anomalous_diffusion_boundary_diagx_lower_bound_recovery_2x2v_ser_p1, NULL}, // 2x2v + {NULL, NULL} // 3x2v }; -GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels[] = { - { NULL, NULL }, // 1x1v - { NULL, NULL }, // 1x2v - { gk_anomalous_diffusion_boundary_diagx_upper_bound_recovery_2x2v_ser_p1, NULL }, // 2x2v - { NULL, NULL }, // 3x2v +GKYL_CU_D static const gkyl_gk_anomalous_diffusion_boundary_surf_kern_list + ser_gyrokinetic_boundary_diagx_upper_boundrecovery_kernels[] = { + {NULL, NULL}, // 1x1v + {NULL, NULL}, // 1x2v + {gk_anomalous_diffusion_boundary_diagx_upper_bound_recovery_2x2v_ser_p1, NULL}, // 2x2v + {NULL, NULL} // 3x2v }; // Macro for choosing volume and surface kernels. -#define CKVOL(lst,pdim,poly_order) lst[pdim-2].kernels[poly_order-1] -#define CKSURF(lst,pdim,poly_order) lst[pdim-2].kernels[poly_order-1] - -GKYL_CU_D static double surf(const struct gkyl_dg_eqn* eqn, int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, - double* GKYL_RESTRICT qRhsOut) +#define CKVOL(lst, pdim, poly_order) lst[pdim - 2].kernels[poly_order - 1] +#define CKSURF(lst, pdim, poly_order) lst[pdim - 2].kernels[poly_order - 1] + +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { - struct gk_anomalous_diffusion* gkad = container_of(eqn, struct gk_anomalous_diffusion, eqn); + struct gk_anomalous_diffusion *gkad = container_of(eqn, struct gk_anomalous_diffusion, eqn); if (dir == 0) { - gkad->surf(xcC, dxC, _cfnu(idxL), _cfnu(idxC), _cfnu(idxR), _cfJacInv(idxL), _cfJacInv(idxC), _cfJacInv(idxR), qInL, qInC, qInR, qRhsOut); + gkad->surf( + xcC, dxC, _cfnu(idxL), _cfnu(idxC), _cfnu(idxR), _cfJacInv(idxL), _cfJacInv(idxC), + _cfJacInv(idxR), qInL, qInC, qInR, qRhsOut + ); } - return 0.; // CFL frequency computed in volume term. + return 0.; // CFL frequency computed in volume term. } -GKYL_CU_D static double boundary_surf(const struct gkyl_dg_eqn* eqn, int dir, - const double* xcEdge, const double* xcSkin, const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) -{ - struct gk_anomalous_diffusion* gkad = container_of(eqn, struct gk_anomalous_diffusion, eqn); - +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) +{ + struct gk_anomalous_diffusion *gkad = container_of(eqn, struct gk_anomalous_diffusion, eqn); + if (dir == 0) { if (edge == -1) { - gkad->boundary_surf[0](xcSkin, dxSkin, _cfnu(idxEdge), _cfnu(idxSkin), _cfJacInv(idxEdge), _cfJacInv(idxSkin), edge, qInEdge, qInSkin, qRhsOut); - } - else { - gkad->boundary_surf[1](xcSkin, dxSkin, _cfnu(idxEdge), _cfnu(idxSkin), _cfJacInv(idxEdge), _cfJacInv(idxSkin), edge, qInEdge, qInSkin, qRhsOut); + gkad->boundary_surf[0]( + xcSkin, dxSkin, _cfnu(idxEdge), _cfnu(idxSkin), _cfJacInv(idxEdge), _cfJacInv(idxSkin), + edge, qInEdge, qInSkin, qRhsOut + ); + } else { + gkad->boundary_surf[1]( + xcSkin, dxSkin, _cfnu(idxEdge), _cfnu(idxSkin), _cfJacInv(idxEdge), _cfJacInv(idxSkin), + edge, qInEdge, qInSkin, qRhsOut + ); } } - return 0.; // CFL frequency computed in volume term. + return 0.; // CFL frequency computed in volume term. } -GKYL_CU_D static double boundary_diag(const struct gkyl_dg_eqn* eqn, int dir, - const double* xcSkin, const double* xcGhost, const double* dxSkin, const double* dxGhost, - const int* idxSkin, const int* idxGhost, const int edge, - const double* qInSkin, const double* qInGhost, double* GKYL_RESTRICT qRhsGhost) -{ +GKYL_CU_D static double boundary_diag( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcSkin, const double *xcGhost, + const double *dxSkin, const double *dxGhost, const int *idxSkin, const int *idxGhost, + const int edge, const double *qInSkin, const double *qInGhost, double *GKYL_RESTRICT qRhsGhost +) +{ // This function is based on boundary_surf above, but notice we use Skin // where the boundary_surf used Ghost, because we assume this kernel is called // in the ghost range (e.g. by the boundary_flux updater). - struct gk_anomalous_diffusion* gkad = container_of(eqn, struct gk_anomalous_diffusion, eqn); + struct gk_anomalous_diffusion *gkad = container_of(eqn, struct gk_anomalous_diffusion, eqn); if (dir == 0) { if (edge == -1) { - gkad->boundary_diag[0](xcSkin, dxSkin, _cfnu(idxSkin), _cfnu(idxGhost), _cfJacInv(idxSkin), _cfJacInv(idxGhost), edge, qInSkin, qInGhost, qRhsGhost); - } - else { - gkad->boundary_diag[1](xcSkin, dxSkin, _cfnu(idxSkin), _cfnu(idxGhost), _cfJacInv(idxSkin), _cfJacInv(idxGhost), edge, qInSkin, qInGhost, qRhsGhost); + gkad->boundary_diag[0]( + xcSkin, dxSkin, _cfnu(idxSkin), _cfnu(idxGhost), _cfJacInv(idxSkin), _cfJacInv(idxGhost), + edge, qInSkin, qInGhost, qRhsGhost + ); + } else { + gkad->boundary_diag[1]( + xcSkin, dxSkin, _cfnu(idxSkin), _cfnu(idxGhost), _cfJacInv(idxSkin), _cfJacInv(idxGhost), + edge, qInSkin, qInGhost, qRhsGhost + ); } } - return 0.; // CFL frequency computed in volume term. + return 0.; // CFL frequency computed in volume term. } #undef _cfnu @@ -185,7 +222,7 @@ GKYL_CU_D static double boundary_diag(const struct gkyl_dg_eqn* eqn, int dir, * * @param ref Reference counter for constant diffusion equation */ -void gkyl_gk_anomalous_diffusion_free(const struct gkyl_ref_count* ref); +void gkyl_gk_anomalous_diffusion_free(const struct gkyl_ref_count *ref); #ifdef GKYL_HAVE_CUDA /** @@ -198,9 +235,11 @@ void gkyl_gk_anomalous_diffusion_free(const struct gkyl_ref_count* ref); * @param bc_x_upper Boundary condition at upper x boundary. * @return Pointer to diffusion equation object */ -struct gkyl_dg_eqn* -gkyl_gk_anomalous_diffusion_cu_dev_new(const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, - const struct gkyl_range *conf_range, enum gkyl_gyrokinetic_bc_type bc_x_lower, enum gkyl_gyrokinetic_bc_type bc_x_upper); +struct gkyl_dg_eqn *gkyl_gk_anomalous_diffusion_cu_dev_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, + const struct gkyl_range *conf_range, enum gkyl_gyrokinetic_bc_type bc_x_lower, + enum gkyl_gyrokinetic_bc_type bc_x_upper +); /** * CUDA device function to set auxiliary fields (e.g. diffusion tensor D) needed in updating diffusion equation. @@ -208,7 +247,8 @@ gkyl_gk_anomalous_diffusion_cu_dev_new(const struct gkyl_basis *basis, const str * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_gk_anomalous_diffusion_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, - struct gkyl_gk_anomalous_diffusion_auxfields auxin); +void gkyl_gk_anomalous_diffusion_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_gk_anomalous_diffusion_auxfields auxin +); #endif diff --git a/gyrokinetic/zero/gkyl_gk_bc_type.h b/gyrokinetic/zero/gkyl_gk_bc_type.h index 05be67186e..1861a6df63 100644 --- a/gyrokinetic/zero/gkyl_gk_bc_type.h +++ b/gyrokinetic/zero/gkyl_gk_bc_type.h @@ -7,7 +7,7 @@ // Boundary conditions on fields and particles in the gyrokinetic solver. enum gkyl_gyrokinetic_bc_type { // Particle BCs. - GKYL_BC_GK_SKIP = 0, // Do not apply any BCs + GKYL_BC_GK_SKIP = 0, // Do not apply any BCs GKYL_BC_GK_SPECIES_COPY, // Copy skin into ghost. GKYL_BC_GK_SPECIES_REFLECT, // Reflect particles. GKYL_BC_GK_SPECIES_ABSORB, // Absorbing BCs. @@ -25,7 +25,7 @@ enum gkyl_gyrokinetic_bc_type { GKYL_BC_GK_FIELD_NEUMANN, // Nemann. GKYL_BC_GK_FIELD_DIRICHLET_VARYING, // Spatially varying Dirichlet. GKYL_BC_GK_FIELD_BOUNDARY_VALUE, // Skin value at the boundary. - GKYL_BC_GK_FIELD_TWISTSHIFT, // Twist-shift. + GKYL_BC_GK_FIELD_TWISTSHIFT // Twist-shift. }; // Translates field BC types in gkyl_gyrokinetic_bc_type to @@ -36,7 +36,7 @@ enum gkyl_gyrokinetic_bc_type { // GKYL_POISSON_PERIODIC = 0, // GKYL_POISSON_DIRICHLET, // sets the value. // GKYL_POISSON_NEUMANN, // sets the slope normal to the boundary. -// GKYL_POISSON_ROBIN, // a combination of dirichlet and neumann. +// GKYL_POISSON_ROBIN, // a combination of dirichlet and neumann. // GKYL_POISSON_DIRICHLET_VARYING, // sets the value, spatially varying. // }; static inline enum gkyl_poisson_bc_type @@ -44,21 +44,21 @@ gkyl_gyrokinetic_translate_poisson_bc_type(enum gkyl_gyrokinetic_bc_type bc_type { enum gkyl_poisson_bc_type poisson_bc_type; switch (bc_type) { - case GKYL_BC_GK_FIELD_PERIODIC: - poisson_bc_type = GKYL_POISSON_PERIODIC; - break; - case GKYL_BC_GK_FIELD_DIRICHLET: - poisson_bc_type = GKYL_POISSON_DIRICHLET; - break; - case GKYL_BC_GK_FIELD_NEUMANN: - poisson_bc_type = GKYL_POISSON_NEUMANN; - break; - case GKYL_BC_GK_FIELD_DIRICHLET_VARYING: - poisson_bc_type = GKYL_POISSON_DIRICHLET_VARYING; - break; - default: - assert(false); - break; + case GKYL_BC_GK_FIELD_PERIODIC: + poisson_bc_type = GKYL_POISSON_PERIODIC; + break; + case GKYL_BC_GK_FIELD_DIRICHLET: + poisson_bc_type = GKYL_POISSON_DIRICHLET; + break; + case GKYL_BC_GK_FIELD_NEUMANN: + poisson_bc_type = GKYL_POISSON_NEUMANN; + break; + case GKYL_BC_GK_FIELD_DIRICHLET_VARYING: + poisson_bc_type = GKYL_POISSON_DIRICHLET_VARYING; + break; + default: + assert(false); + break; } return poisson_bc_type; } @@ -68,33 +68,33 @@ gkyl_gyrokinetic_translate_poisson_bc_type(enum gkyl_gyrokinetic_bc_type bc_type // This translation needs to match the types in vlasov/zero/gkyl_bc_basic.h // which at the moment are: // BC types in this updater. -// enum gkyl_bc_basic_type { -// GKYL_BC_COPY = 0, -// GKYL_BC_ABSORB, -// GKYL_BC_DISTF_REFLECT, +// enum gkyl_bc_basic_type { +// GKYL_BC_COPY = 0, +// GKYL_BC_ABSORB, +// GKYL_BC_DISTF_REFLECT, // GKYL_BC_FIXED_FUNC, -// GKYL_BC_CONF_BOUNDARY_VALUE, +// GKYL_BC_CONF_BOUNDARY_VALUE, // }; static inline enum gkyl_bc_basic_type gkyl_gyrokinetic_translate_bc_basic_type(enum gkyl_gyrokinetic_bc_type bc_type) { enum gkyl_bc_basic_type bc_basic_type; switch (bc_type) { - case GKYL_BC_GK_SPECIES_COPY: - bc_basic_type = GKYL_BC_COPY; - break; - case GKYL_BC_GK_SPECIES_ABSORB: - bc_basic_type = GKYL_BC_ABSORB; - break; - case GKYL_BC_GK_SPECIES_REFLECT: - bc_basic_type = GKYL_BC_DISTF_REFLECT; - break; - case GKYL_BC_GK_SPECIES_FIXED_FUNC: - bc_basic_type = GKYL_BC_FIXED_FUNC; - break; - default: - assert(false); - break; + case GKYL_BC_GK_SPECIES_COPY: + bc_basic_type = GKYL_BC_COPY; + break; + case GKYL_BC_GK_SPECIES_ABSORB: + bc_basic_type = GKYL_BC_ABSORB; + break; + case GKYL_BC_GK_SPECIES_REFLECT: + bc_basic_type = GKYL_BC_DISTF_REFLECT; + break; + case GKYL_BC_GK_SPECIES_FIXED_FUNC: + bc_basic_type = GKYL_BC_FIXED_FUNC; + break; + default: + assert(false); + break; } return bc_basic_type; } diff --git a/gyrokinetic/zero/gkyl_gk_collisionless_flux.h b/gyrokinetic/zero/gkyl_gk_collisionless_flux.h index 8e12164c81..971cae5d07 100644 --- a/gyrokinetic/zero/gkyl_gk_collisionless_flux.h +++ b/gyrokinetic/zero/gkyl_gk_collisionless_flux.h @@ -31,14 +31,14 @@ typedef struct gkyl_gk_collisionless_flux gkyl_gk_collisionless_flux; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_gk_collisionless_flux* -gkyl_gk_collisionless_flux_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const double charge, const double mass, - enum gkyl_gk_collisionless_type collless_type, - const struct gk_geometry *gk_geom, const struct gkyl_dg_geom *dg_geom, - const struct gkyl_gk_dg_geom *gk_dg_geom, const struct gkyl_velocity_map *vel_map, - const enum gkyl_gyrokinetic_bc_type *bctype_conf, bool use_gpu); +struct gkyl_gk_collisionless_flux *gkyl_gk_collisionless_flux_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const double charge, const double mass, + enum gkyl_gk_collisionless_type collless_type, const struct gk_geometry *gk_geom, + const struct gkyl_dg_geom *dg_geom, const struct gkyl_gk_dg_geom *gk_dg_geom, + const struct gkyl_velocity_map *vel_map, const enum gkyl_gyrokinetic_bc_type *bctype_conf, + bool use_gpu +); /** * Compute surface expansion of phase space flux alpha @@ -57,10 +57,12 @@ gkyl_gk_collisionless_flux_new(const struct gkyl_rect_grid *phase_grid, * @param flux_surf Output surface expansion in a cell on the *lower* edge in each direction. * @param clfrate Output CFL rate. */ -void gkyl_gk_collisionless_flux_surf(struct gkyl_gk_collisionless_flux *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_ext_range, const struct gkyl_range *phase_ext_range, const struct gkyl_array *phi, - const struct gkyl_array *fin, struct gkyl_array* flux_surf, struct gkyl_array *cflrate); +void gkyl_gk_collisionless_flux_surf( + struct gkyl_gk_collisionless_flux *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_range *phase_ext_range, const struct gkyl_array *phi, + const struct gkyl_array *fin, struct gkyl_array *flux_surf, struct gkyl_array *cflrate +); /** * Delete pointer to updater to compute gyrokinetic variables. diff --git a/gyrokinetic/zero/gkyl_gk_collisionless_flux_priv.h b/gyrokinetic/zero/gkyl_gk_collisionless_flux_priv.h index 9a3f94f2b8..ff82a89823 100644 --- a/gyrokinetic/zero/gkyl_gk_collisionless_flux_priv.h +++ b/gyrokinetic/zero/gkyl_gk_collisionless_flux_priv.h @@ -10,42 +10,52 @@ #include #include -typedef double (*gk_collisionless_flux_surf_t)(const double *w, const double *dxv, - const double *vmap, const double *vmapSq, const double q_, const double m_, - const struct gkyl_dg_surf_geom *dgs, const struct gkyl_gk_dg_surf_geom *gkdgs, - const double *bmag, const double *jacobgeo_rat_surfL, const double *jacobgeo_rat_surfR, const double *phi, - const double *JfL, const double *JfR, double* GKYL_RESTRICT flux_surf); - -typedef double (*gk_collisionless_flux_surfvpar_t)( - const double *w, const double *dxv, - const double *vmap_prime_l, const double *vmap_prime_r, - const double *vmap, const double *vmapSq, const double q_, const double m_, - const struct gkyl_dg_vol_geom *dgv, const struct gkyl_gk_dg_vol_geom *gkdgv, - const double *bmag, const double *phi, const double *JfL, const double *JfR, double* GKYL_RESTRICT flux_surf); +typedef double (*gk_collisionless_flux_surf_t)( + const double *w, const double *dxv, const double *vmap, const double *vmapSq, const double q_, + const double m_, const struct gkyl_dg_surf_geom *dgs, const struct gkyl_gk_dg_surf_geom *gkdgs, + const double *bmag, const double *jacobgeo_rat_surfL, const double *jacobgeo_rat_surfR, + const double *phi, const double *JfL, const double *JfR, double *GKYL_RESTRICT flux_surf +); + +typedef double (*gk_collisionless_flux_surfvpar_t)( + const double *w, const double *dxv, const double *vmap_prime_l, const double *vmap_prime_r, + const double *vmap, const double *vmapSq, const double q_, const double m_, + const struct gkyl_dg_vol_geom *dgv, const struct gkyl_gk_dg_vol_geom *gkdgv, const double *bmag, + const double *phi, const double *JfL, const double *JfR, double *GKYL_RESTRICT flux_surf +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below. -GKYL_CU_D -static struct { int vdim[3]; } cv_index[] = { +GKYL_CU_D static struct { + int vdim[3]; +} cv_index[] = { {-1, -1, -1}, // 0x makes no sense. - {-1, 0, 1}, // 1x kernel indices. - {-1, -1, 2}, // 2x kernel indices. - {-1, -1, 3}, // 3x kernel indices. + {-1, 0, 1}, // 1x kernel indices. + {-1, -1, 2}, // 2x kernel indices. + {-1, -1, 3} // 3x kernel indices. }; // for use in kernel tables -typedef struct { gk_collisionless_flux_surf_t kernels[3]; } gkyl_gk_collisionless_flux_surf_kern_list; -typedef struct { gk_collisionless_flux_surfvpar_t kernels[3]; } gkyl_gk_collisionless_flux_surfvpar_kern_list; +typedef struct { + gk_collisionless_flux_surf_t kernels[3]; +} gkyl_gk_collisionless_flux_surf_kern_list; +typedef struct { + gk_collisionless_flux_surfvpar_t kernels[3]; +} gkyl_gk_collisionless_flux_surfvpar_kern_list; struct gkyl_gk_collisionless_flux { struct gkyl_rect_grid phase_grid; // Phase space grid for cell spacing and cell center int cdim; // Configuration space dimensionality int pdim; // Phase space dimensionality - gk_collisionless_flux_surf_t flux_surf[GKYL_MAX_CDIM]; // kernel for computing surface expansion of phase space flux. - gk_collisionless_flux_surf_t flux_surf_edge_lo[GKYL_MAX_CDIM]; // kernel for computing surface expansion of phase space flux. - gk_collisionless_flux_surf_t flux_surf_edge_up[GKYL_MAX_CDIM]; // kernel for computing surface expansion of phase space flux. - // at upper configuration space edge - gk_collisionless_flux_surfvpar_t flux_surfvpar[1]; // kernel for computing surface expansion of phase space flux alpha + gk_collisionless_flux_surf_t + flux_surf[GKYL_MAX_CDIM]; // kernel for computing surface expansion of phase space flux. + gk_collisionless_flux_surf_t + flux_surf_edge_lo[GKYL_MAX_CDIM]; // kernel for computing surface expansion of phase space flux. + gk_collisionless_flux_surf_t + flux_surf_edge_up[GKYL_MAX_CDIM]; // kernel for computing surface expansion of phase space flux. + // at upper configuration space edge + gk_collisionless_flux_surfvpar_t + flux_surfvpar[1]; // kernel for computing surface expansion of phase space flux alpha double charge, mass; const struct gk_geometry *gk_geom; // Pointer to geometry struct. const struct gkyl_dg_geom *dg_geom; // Pointer to vol dg geometry struct. @@ -60,66 +70,66 @@ struct gkyl_gk_collisionless_flux { // Serendipity surface kernels. // // Gyrokinetic phase space flux alpha surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_surfx_kernels[] = { - { NULL, gk_collisionless_flux_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_flux_surfx_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_flux_surfx_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_surfx_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_surfx_kernels[] = { + {NULL, gk_collisionless_flux_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_flux_surfx_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_flux_surfx_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_surfx_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha edge surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_edge_surfx_kernels[] = { - { NULL, gk_collisionless_flux_edge_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_flux_edge_surfx_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_flux_edge_surfx_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_edge_surfx_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_edge_surfx_kernels[] = { + {NULL, gk_collisionless_flux_edge_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_flux_edge_surfx_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_flux_edge_surfx_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_edge_surfx_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_collisionless_flux_surfy_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_surfy_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_collisionless_flux_surfy_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_surfy_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux edge surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_edge_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_collisionless_flux_edge_surfy_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_edge_surfy_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_edge_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_collisionless_flux_edge_surfy_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_edge_surfy_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_flux_surfz_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_flux_surfz_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux edge surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_edge_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_flux_edge_surfz_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_edge_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_flux_edge_surfz_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha surface expansions in vpar (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surfvpar_kern_list ser_gk_collisionless_flux_surfvpar_kernels[] = { - { NULL, gk_collisionless_flux_surfvpar_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_flux_surfvpar_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_flux_surfvpar_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_surfvpar_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surfvpar_kern_list + ser_gk_collisionless_flux_surfvpar_kernels[] = { + {NULL, gk_collisionless_flux_surfvpar_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_flux_surfvpar_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_flux_surfvpar_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_surfvpar_3x2v_ser_p1, NULL} // 3 }; // @@ -127,124 +137,123 @@ static const gkyl_gk_collisionless_flux_surfvpar_kern_list ser_gk_collisionless_ // // Gyrokinetic phase space flux alpha surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_multib_boundary_surfx_kernels[] = { - { NULL, gk_collisionless_flux_multib_boundary_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_flux_multib_boundary_surfx_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_flux_multib_boundary_surfx_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_multib_boundary_surfx_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_multib_boundary_surfx_kernels[] = { + {NULL, gk_collisionless_flux_multib_boundary_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_flux_multib_boundary_surfx_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_flux_multib_boundary_surfx_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_multib_boundary_surfx_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha edge surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_multib_boundary_edge_surfx_kernels[] = { - { NULL, gk_collisionless_flux_multib_boundary_edge_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_flux_multib_boundary_edge_surfx_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_flux_multib_boundary_edge_surfx_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_multib_boundary_edge_surfx_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_multib_boundary_edge_surfx_kernels[] = { + {NULL, gk_collisionless_flux_multib_boundary_edge_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_flux_multib_boundary_edge_surfx_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_flux_multib_boundary_edge_surfx_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_multib_boundary_edge_surfx_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_multib_boundary_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_collisionless_flux_multib_boundary_surfy_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_multib_boundary_surfy_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_multib_boundary_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_collisionless_flux_multib_boundary_surfy_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_multib_boundary_surfy_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux edge surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_multib_boundary_edge_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_collisionless_flux_multib_boundary_edge_surfy_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_multib_boundary_edge_surfy_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_multib_boundary_edge_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_collisionless_flux_multib_boundary_edge_surfy_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_multib_boundary_edge_surfy_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_multib_boundary_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_flux_multib_boundary_surfz_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_multib_boundary_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_flux_multib_boundary_surfz_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux edge surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_multib_boundary_edge_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_flux_multib_boundary_edge_surfz_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_multib_boundary_edge_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_flux_multib_boundary_edge_surfz_3x2v_ser_p1, NULL} // 3 }; - // // Serendipity surface kernels without toroidal field (by=0) // // Gyrokinetic phase space flux alpha surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_surfx_kernels[] = { - { NULL, gk_collisionless_flux_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_flux_surfx_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_flux_no_by_surfx_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_surfx_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_surfx_kernels[] = { + {NULL, gk_collisionless_flux_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_flux_surfx_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_flux_no_by_surfx_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_surfx_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha edge surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_edge_surfx_kernels[] = { - { NULL, gk_collisionless_flux_edge_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_flux_edge_surfx_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_flux_no_by_edge_surfx_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_edge_surfx_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_edge_surfx_kernels[] = { + {NULL, gk_collisionless_flux_edge_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_flux_edge_surfx_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_flux_no_by_edge_surfx_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_edge_surfx_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_collisionless_flux_no_by_surfy_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_surfy_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_collisionless_flux_no_by_surfy_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_surfy_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha edge surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_edge_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_collisionless_flux_no_by_edge_surfy_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_edge_surfy_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_edge_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_collisionless_flux_no_by_edge_surfy_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_edge_surfy_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_surfz_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_surfz_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha edge surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_edge_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_edge_surfz_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_edge_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_edge_surfz_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha surface expansions in vpar (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surfvpar_kern_list ser_gk_collisionless_flux_no_by_surfvpar_kernels[] = { - { NULL, gk_collisionless_flux_surfvpar_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_flux_surfvpar_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_flux_no_by_surfvpar_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_surfvpar_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surfvpar_kern_list + ser_gk_collisionless_flux_no_by_surfvpar_kernels[] = { + {NULL, gk_collisionless_flux_surfvpar_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_flux_surfvpar_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_flux_no_by_surfvpar_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_surfvpar_3x2v_ser_p1, NULL} // 3 }; // @@ -252,176 +261,203 @@ static const gkyl_gk_collisionless_flux_surfvpar_kern_list ser_gk_collisionless_ // // Gyrokinetic phase space flux alpha surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_multib_boundary_surfx_kernels[] = { - { NULL, gk_collisionless_flux_multib_boundary_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_flux_multib_boundary_surfx_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_flux_no_by_multib_boundary_surfx_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_multib_boundary_surfx_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_multib_boundary_surfx_kernels[] = { + {NULL, gk_collisionless_flux_multib_boundary_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_flux_multib_boundary_surfx_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_flux_no_by_multib_boundary_surfx_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_multib_boundary_surfx_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha edge surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfx_kernels[] = { - { NULL, gk_collisionless_flux_multib_boundary_edge_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_flux_multib_boundary_edge_surfx_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_flux_no_by_multib_boundary_edge_surfx_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_multib_boundary_edge_surfx_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfx_kernels[] = { + {NULL, gk_collisionless_flux_multib_boundary_edge_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_flux_multib_boundary_edge_surfx_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_flux_no_by_multib_boundary_edge_surfx_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_multib_boundary_edge_surfx_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_multib_boundary_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_collisionless_flux_no_by_multib_boundary_surfy_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_multib_boundary_surfy_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_multib_boundary_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_collisionless_flux_no_by_multib_boundary_surfy_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_multib_boundary_surfy_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha edge surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_collisionless_flux_no_by_multib_boundary_edge_surfy_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_multib_boundary_edge_surfy_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_collisionless_flux_no_by_multib_boundary_edge_surfy_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_multib_boundary_edge_surfy_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_multib_boundary_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_multib_boundary_surfz_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_multib_boundary_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_multib_boundary_surfz_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha edge surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_flux_surf_kern_list ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_flux_no_by_multib_boundary_edge_surfz_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_flux_surf_kern_list + ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_flux_no_by_multib_boundary_edge_surfz_3x2v_ser_p1, NULL} // 3 }; - -GKYL_CU_D -static gk_collisionless_flux_surf_t -choose_gk_collisionless_flux_surf_conf_kern(int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc) +GKYL_CU_D static gk_collisionless_flux_surf_t choose_gk_collisionless_flux_surf_conf_kern( + int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc +) { if (bc == GKYL_BC_GK_SKIP) { - if (dir == 0) - return ser_gk_collisionless_flux_multib_boundary_surfx_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_flux_multib_boundary_surfy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_flux_multib_boundary_surfz_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else + if (dir == 0) { + return ser_gk_collisionless_flux_multib_boundary_surfx_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_flux_multib_boundary_surfy_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_flux_multib_boundary_surfz_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else { return NULL; - } - else { - if (dir == 0) + } + } else { + if (dir == 0) { return ser_gk_collisionless_flux_surfx_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) + } else if (dir == 1) { return ser_gk_collisionless_flux_surfy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) + } else if (dir == 2) { return ser_gk_collisionless_flux_surfz_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else + } else { return NULL; + } } } -GKYL_CU_D -static gk_collisionless_flux_surf_t -choose_gk_collisionless_flux_edge_surf_conf_kern(int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc) +GKYL_CU_D static gk_collisionless_flux_surf_t choose_gk_collisionless_flux_edge_surf_conf_kern( + int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc +) { if (bc == GKYL_BC_GK_SKIP) { - if (dir == 0) - return ser_gk_collisionless_flux_multib_boundary_edge_surfx_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_flux_multib_boundary_edge_surfy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_flux_multib_boundary_edge_surfz_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else + if (dir == 0) { + return ser_gk_collisionless_flux_multib_boundary_edge_surfx_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_flux_multib_boundary_edge_surfy_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_flux_multib_boundary_edge_surfz_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else { return NULL; - } - else { - if (dir == 0) - return ser_gk_collisionless_flux_edge_surfx_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_flux_edge_surfy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_flux_edge_surfz_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else + } + } else { + if (dir == 0) { + return ser_gk_collisionless_flux_edge_surfx_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_flux_edge_surfy_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_flux_edge_surfz_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else { return NULL; + } } } -GKYL_CU_D -static gk_collisionless_flux_surfvpar_t +GKYL_CU_D static gk_collisionless_flux_surfvpar_t choose_gk_collisionless_flux_surf_vpar_kern(int cdim, int vdim, int poly_order) { return ser_gk_collisionless_flux_surfvpar_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; } -GKYL_CU_D -static gk_collisionless_flux_surf_t -choose_gk_collisionless_flux_no_by_surf_conf_kern(int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc) +GKYL_CU_D static gk_collisionless_flux_surf_t choose_gk_collisionless_flux_no_by_surf_conf_kern( + int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc +) { if (bc == GKYL_BC_GK_SKIP) { - if (dir == 0) - return ser_gk_collisionless_flux_no_by_multib_boundary_surfx_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_flux_no_by_multib_boundary_surfy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_flux_no_by_multib_boundary_surfz_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else + if (dir == 0) { + return ser_gk_collisionless_flux_no_by_multib_boundary_surfx_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_flux_no_by_multib_boundary_surfy_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_flux_no_by_multib_boundary_surfz_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else { return NULL; - } - else { - if (dir == 0) - return ser_gk_collisionless_flux_no_by_surfx_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_flux_no_by_surfy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_flux_no_by_surfz_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else + } + } else { + if (dir == 0) { + return ser_gk_collisionless_flux_no_by_surfx_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_flux_no_by_surfy_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_flux_no_by_surfz_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else { return NULL; + } } } -GKYL_CU_D -static gk_collisionless_flux_surf_t -choose_gk_collisionless_flux_no_by_edge_surf_conf_kern(int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc) +GKYL_CU_D static gk_collisionless_flux_surf_t +choose_gk_collisionless_flux_no_by_edge_surf_conf_kern( + int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc +) { if (bc == GKYL_BC_GK_SKIP) { - if (dir == 0) - return ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfx_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfz_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else + if (dir == 0) { + return ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfx_kernels[cv_index[cdim] + .vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfy_kernels[cv_index[cdim] + .vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_flux_no_by_multib_boundary_edge_surfz_kernels[cv_index[cdim] + .vdim[vdim]] + .kernels[poly_order]; + } else { return NULL; - } - else { - if (dir == 0) - return ser_gk_collisionless_flux_no_by_edge_surfx_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_flux_no_by_edge_surfy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_flux_no_by_edge_surfz_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - else + } + } else { + if (dir == 0) { + return ser_gk_collisionless_flux_no_by_edge_surfx_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_flux_no_by_edge_surfy_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_flux_no_by_edge_surfz_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; + } else { return NULL; + } } } -GKYL_CU_D -static gk_collisionless_flux_surfvpar_t +GKYL_CU_D static gk_collisionless_flux_surfvpar_t choose_gk_collisionless_flux_no_by_surf_vpar_kern(int cdim, int vdim, int poly_order) { - return ser_gk_collisionless_flux_no_by_surfvpar_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; + return ser_gk_collisionless_flux_no_by_surfvpar_kernels[cv_index[cdim].vdim[vdim]] + .kernels[poly_order]; } #ifdef GKYL_HAVE_CUDA @@ -429,20 +465,21 @@ choose_gk_collisionless_flux_no_by_surf_vpar_kern(int cdim, int vdim, int poly_o * Create new updater to compute gyrokinetic variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_gk_collisionless_flux* -gkyl_gk_collisionless_flux_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - double charge, double mass, - enum gkyl_gk_collisionless_type collless_type, - const struct gk_geometry *gk_geom, const struct gkyl_dg_geom *dg_geom, - const struct gkyl_gk_dg_geom *gk_dg_geom, const struct gkyl_velocity_map *vel_map, - const enum gkyl_gyrokinetic_bc_type *bctype_conf); +struct gkyl_gk_collisionless_flux *gkyl_gk_collisionless_flux_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, double charge, double mass, + enum gkyl_gk_collisionless_type collless_type, const struct gk_geometry *gk_geom, + const struct gkyl_dg_geom *dg_geom, const struct gkyl_gk_dg_geom *gk_dg_geom, + const struct gkyl_velocity_map *vel_map, const enum gkyl_gyrokinetic_bc_type *bctype_conf +); /** * Host-side wrappers for gyrokinetic vars operations on device */ -void gkyl_gk_collisionless_flux_surf_cu(struct gkyl_gk_collisionless_flux *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_ext_range, const struct gkyl_range *phase_ext_range, const struct gkyl_array *phi, - const struct gkyl_array* fin, struct gkyl_array* flux_surf, struct gkyl_array* cflrate); +void gkyl_gk_collisionless_flux_surf_cu( + struct gkyl_gk_collisionless_flux *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_range *phase_ext_range, const struct gkyl_array *phi, + const struct gkyl_array *fin, struct gkyl_array *flux_surf, struct gkyl_array *cflrate +); #endif diff --git a/gyrokinetic/zero/gkyl_gk_collisionless_passive_flux.h b/gyrokinetic/zero/gkyl_gk_collisionless_passive_flux.h index d4ccbf9cca..037e928795 100644 --- a/gyrokinetic/zero/gkyl_gk_collisionless_passive_flux.h +++ b/gyrokinetic/zero/gkyl_gk_collisionless_passive_flux.h @@ -32,14 +32,14 @@ typedef struct gkyl_gk_collisionless_passive_flux gkyl_gk_collisionless_passive_ * @param use_gpu Whether to allocate on GPU. * @return New updater pointer. */ -gkyl_gk_collisionless_passive_flux* -gkyl_gk_collisionless_passive_flux_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_array *passive_speeds, - const double charge, const double mass, - const struct gk_geometry *gk_geom, const struct gkyl_dg_geom *dg_geom, - const struct gkyl_gk_dg_geom *gk_dg_geom, const struct gkyl_velocity_map *vel_map, - const enum gkyl_gyrokinetic_bc_type *bctype_conf, bool use_gpu); +gkyl_gk_collisionless_passive_flux *gkyl_gk_collisionless_passive_flux_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_array *passive_speeds, + const double charge, const double mass, const struct gk_geometry *gk_geom, + const struct gkyl_dg_geom *dg_geom, const struct gkyl_gk_dg_geom *gk_dg_geom, + const struct gkyl_velocity_map *vel_map, const enum gkyl_gyrokinetic_bc_type *bctype_conf, + bool use_gpu +); /** * Compute the surface expansion of the passive phase-space flux. @@ -55,11 +55,12 @@ gkyl_gk_collisionless_passive_flux_new(const struct gkyl_rect_grid *phase_grid, * @param flux_surf Output surface expansion (lower edge in each direction). * @param cflrate Output CFL rate. */ -void gkyl_gk_collisionless_passive_flux_surf(gkyl_gk_collisionless_passive_flux *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_ext_range, const struct gkyl_range *phase_ext_range, - const struct gkyl_array *fin, - struct gkyl_array *flux_surf, struct gkyl_array *cflrate); +void gkyl_gk_collisionless_passive_flux_surf( + gkyl_gk_collisionless_passive_flux *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_range *phase_ext_range, const struct gkyl_array *fin, + struct gkyl_array *flux_surf, struct gkyl_array *cflrate +); /** * Delete pointer to passive flux updater. diff --git a/gyrokinetic/zero/gkyl_gk_collisionless_passive_flux_priv.h b/gyrokinetic/zero/gkyl_gk_collisionless_passive_flux_priv.h index 869a28e5a0..9546a901fb 100644 --- a/gyrokinetic/zero/gkyl_gk_collisionless_passive_flux_priv.h +++ b/gyrokinetic/zero/gkyl_gk_collisionless_passive_flux_priv.h @@ -10,24 +10,28 @@ #include #include -typedef double (*gk_collisionless_passive_flux_surf_t)(const double *w, const double *dxv, - const double *vmap, const double *vmapSq, const double q_, const double m_, - const struct gkyl_dg_surf_geom *dgs, const struct gkyl_gk_dg_surf_geom *gkdgs, +typedef double (*gk_collisionless_passive_flux_surf_t)( + const double *w, const double *dxv, const double *vmap, const double *vmapSq, const double q_, + const double m_, const struct gkyl_dg_surf_geom *dgs, const struct gkyl_gk_dg_surf_geom *gkdgs, const double *bmag, const double *jacobgeo_rat_surfL, const double *jacobgeo_rat_surfR, - const double *speeds_L, const double *speeds_R, - const double *JfL, const double *JfR, double *GKYL_RESTRICT flux_surf); + const double *speeds_L, const double *speeds_R, const double *JfL, const double *JfR, + double *GKYL_RESTRICT flux_surf +); // The cv_index[cd].vdim[vd] is used to index the various lists of kernels below. -GKYL_CU_D -static struct { int vdim[3]; } cv_index_passive[] = { +GKYL_CU_D static struct { + int vdim[3]; +} cv_index_passive[] = { {-1, -1, -1}, // 0x makes no sense. - {-1, 0, 1}, // 1x kernel indices. - {-1, -1, 2}, // 2x kernel indices. - {-1, -1, 3}, // 3x kernel indices. + {-1, 0, 1}, // 1x kernel indices. + {-1, -1, 2}, // 2x kernel indices. + {-1, -1, 3} // 3x kernel indices. }; // For use in kernel tables. -typedef struct { gk_collisionless_passive_flux_surf_t kernels[3]; } gkyl_gk_collisionless_passive_flux_surf_kern_list; +typedef struct { + gk_collisionless_passive_flux_surf_t kernels[3]; +} gkyl_gk_collisionless_passive_flux_surf_kern_list; struct gkyl_gk_collisionless_passive_flux { struct gkyl_rect_grid phase_grid; // Phase space grid for cell spacing and cell center. @@ -52,61 +56,61 @@ struct gkyl_gk_collisionless_passive_flux { // // Serendipity surface kernels — x-direction (interior) // -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_surfx_kernels[] = { - { NULL, gk_collisionless_passive_flux_surfx_1x1v_ser_p1, NULL }, // 0: 1x1v - { NULL, gk_collisionless_passive_flux_surfx_1x2v_ser_p1, NULL }, // 1: 1x2v - { NULL, gk_collisionless_passive_flux_surfx_2x2v_ser_p1, NULL }, // 2: 2x2v - { NULL, gk_collisionless_passive_flux_surfx_3x2v_ser_p1, NULL }, // 3: 3x2v +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_surfx_kernels[] = { + {NULL, gk_collisionless_passive_flux_surfx_1x1v_ser_p1, NULL}, // 0: 1x1v + {NULL, gk_collisionless_passive_flux_surfx_1x2v_ser_p1, NULL}, // 1: 1x2v + {NULL, gk_collisionless_passive_flux_surfx_2x2v_ser_p1, NULL}, // 2: 2x2v + {NULL, gk_collisionless_passive_flux_surfx_3x2v_ser_p1, NULL} // 3: 3x2v }; // x-direction edge (lower boundary) -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_edge_surfx_kernels[] = { - { NULL, gk_collisionless_passive_flux_edge_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_passive_flux_edge_surfx_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_passive_flux_edge_surfx_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_passive_flux_edge_surfx_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_edge_surfx_kernels[] = { + {NULL, gk_collisionless_passive_flux_edge_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_passive_flux_edge_surfx_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_passive_flux_edge_surfx_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_passive_flux_edge_surfx_3x2v_ser_p1, NULL} // 3 }; // // y-direction (interior) // -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0: 1x — no y - { NULL, NULL, NULL }, // 1: 1x — no y - { NULL, gk_collisionless_passive_flux_surfy_2x2v_ser_p1, NULL }, // 2: 2x2v - { NULL, gk_collisionless_passive_flux_surfy_3x2v_ser_p1, NULL }, // 3: 3x2v +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0: 1x — no y + {NULL, NULL, NULL}, // 1: 1x — no y + {NULL, gk_collisionless_passive_flux_surfy_2x2v_ser_p1, NULL}, // 2: 2x2v + {NULL, gk_collisionless_passive_flux_surfy_3x2v_ser_p1, NULL} // 3: 3x2v }; // y-direction edge -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_edge_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_collisionless_passive_flux_edge_surfy_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_passive_flux_edge_surfy_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_edge_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_collisionless_passive_flux_edge_surfy_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_passive_flux_edge_surfy_3x2v_ser_p1, NULL} // 3 }; // // z-direction (interior) // -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_passive_flux_surfz_3x2v_ser_p1, NULL }, // 3: 3x2v +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_passive_flux_surfz_3x2v_ser_p1, NULL} // 3: 3x2v }; // z-direction edge -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_edge_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_passive_flux_edge_surfz_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_edge_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_passive_flux_edge_surfz_3x2v_ser_p1, NULL} // 3 }; // @@ -114,125 +118,150 @@ static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionl // // Gyrokinetic phase space flux alpha surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_multib_boundary_surfx_kernels[] = { - { NULL, gk_collisionless_passive_flux_multib_boundary_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_passive_flux_multib_boundary_surfx_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_passive_flux_multib_boundary_surfx_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_passive_flux_multib_boundary_surfx_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_multib_boundary_surfx_kernels[] = { + {NULL, gk_collisionless_passive_flux_multib_boundary_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_passive_flux_multib_boundary_surfx_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_passive_flux_multib_boundary_surfx_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_passive_flux_multib_boundary_surfx_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux alpha edge surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_multib_boundary_edge_surfx_kernels[] = { - { NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfx_1x1v_ser_p1, NULL }, // 0 - { NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfx_1x2v_ser_p1, NULL }, // 1 - { NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfx_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfx_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_multib_boundary_edge_surfx_kernels[] = { + {NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfx_1x1v_ser_p1, NULL}, // 0 + {NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfx_1x2v_ser_p1, NULL}, // 1 + {NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfx_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfx_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_multib_boundary_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_collisionless_passive_flux_multib_boundary_surfy_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_passive_flux_multib_boundary_surfy_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_multib_boundary_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_collisionless_passive_flux_multib_boundary_surfy_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_passive_flux_multib_boundary_surfy_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux edge surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_multib_boundary_edge_surfy_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfy_2x2v_ser_p1, NULL }, // 2 - { NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfy_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_multib_boundary_edge_surfy_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfy_2x2v_ser_p1, NULL}, // 2 + {NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfy_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_multib_boundary_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_passive_flux_multib_boundary_surfz_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_multib_boundary_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_passive_flux_multib_boundary_surfz_3x2v_ser_p1, NULL} // 3 }; // Gyrokinetic phase space flux flux edge surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_collisionless_passive_flux_surf_kern_list ser_gk_collisionless_passive_flux_multib_boundary_edge_surfz_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - { NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfz_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_gk_collisionless_passive_flux_surf_kern_list + ser_gk_collisionless_passive_flux_multib_boundary_edge_surfz_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + {NULL, gk_collisionless_passive_flux_multib_boundary_edge_surfz_3x2v_ser_p1, NULL} // 3 }; // Helper: choose interior conf-surface kernel for a given direction. -GKYL_CU_D -static gk_collisionless_passive_flux_surf_t +GKYL_CU_D static gk_collisionless_passive_flux_surf_t choose_gk_collisionless_passive_flux_surf_conf_kern(int dir, int cdim, int vdim, int poly_order) { - if (dir == 0) - return ser_gk_collisionless_passive_flux_surfx_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_passive_flux_surfy_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_passive_flux_surfz_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; + if (dir == 0) { + return ser_gk_collisionless_passive_flux_surfx_kernels[cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_passive_flux_surfy_kernels[cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_passive_flux_surfz_kernels[cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } return NULL; } // Helper: choose lower-edge conf-surface kernel for a given direction. -GKYL_CU_D -static gk_collisionless_passive_flux_surf_t -choose_gk_collisionless_passive_flux_edge_lo_surf_conf_kern(int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc) +GKYL_CU_D static gk_collisionless_passive_flux_surf_t +choose_gk_collisionless_passive_flux_edge_lo_surf_conf_kern( + int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc +) { if (bc == GKYL_BC_GK_SKIP) { - if (dir == 0) - return ser_gk_collisionless_passive_flux_multib_boundary_surfx_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_passive_flux_multib_boundary_surfy_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_passive_flux_multib_boundary_surfz_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else + if (dir == 0) { + return ser_gk_collisionless_passive_flux_multib_boundary_surfx_kernels[cv_index_passive[cdim] + .vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_passive_flux_multib_boundary_surfy_kernels[cv_index_passive[cdim] + .vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_passive_flux_multib_boundary_surfz_kernels[cv_index_passive[cdim] + .vdim[vdim]] + .kernels[poly_order]; + } else { return NULL; - } - else { - if (dir == 0) - return ser_gk_collisionless_passive_flux_surfx_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_passive_flux_surfy_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_passive_flux_surfz_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else + } + } else { + if (dir == 0) { + return ser_gk_collisionless_passive_flux_surfx_kernels[cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_passive_flux_surfy_kernels[cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_passive_flux_surfz_kernels[cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } else { return NULL; + } } return NULL; } // Helper: choose upper-edge conf-surface kernel for a given direction. -GKYL_CU_D -static gk_collisionless_passive_flux_surf_t -choose_gk_collisionless_passive_flux_edge_up_surf_conf_kern(int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc) +GKYL_CU_D static gk_collisionless_passive_flux_surf_t +choose_gk_collisionless_passive_flux_edge_up_surf_conf_kern( + int dir, int cdim, int vdim, int poly_order, enum gkyl_gyrokinetic_bc_type bc +) { if (bc == GKYL_BC_GK_SKIP) { - if (dir == 0) - return ser_gk_collisionless_passive_flux_multib_boundary_edge_surfx_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_passive_flux_multib_boundary_edge_surfy_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_passive_flux_multib_boundary_edge_surfz_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else + if (dir == 0) { + return ser_gk_collisionless_passive_flux_multib_boundary_edge_surfx_kernels + [cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_passive_flux_multib_boundary_edge_surfy_kernels + [cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_passive_flux_multib_boundary_edge_surfz_kernels + [cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } else { return NULL; - } - else { - if (dir == 0) - return ser_gk_collisionless_passive_flux_edge_surfx_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 1) - return ser_gk_collisionless_passive_flux_edge_surfy_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; - else if (dir == 2) - return ser_gk_collisionless_passive_flux_edge_surfz_kernels[cv_index_passive[cdim].vdim[vdim]].kernels[poly_order]; + } + } else { + if (dir == 0) { + return ser_gk_collisionless_passive_flux_edge_surfx_kernels[cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 1) { + return ser_gk_collisionless_passive_flux_edge_surfy_kernels[cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } else if (dir == 2) { + return ser_gk_collisionless_passive_flux_edge_surfz_kernels[cv_index_passive[cdim].vdim[vdim]] + .kernels[poly_order]; + } return NULL; } @@ -240,17 +269,17 @@ choose_gk_collisionless_passive_flux_edge_up_surf_conf_kern(int dir, int cdim, i } // GPU-only functions (defined in gk_collisionless_passive_flux_cu.cu). -gkyl_gk_collisionless_passive_flux* -gkyl_gk_collisionless_passive_flux_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_array *passive_speeds, - const double charge, const double mass, - const struct gk_geometry *gk_geom, const struct gkyl_dg_geom *dg_geom, - const struct gkyl_gk_dg_geom *gk_dg_geom, const struct gkyl_velocity_map *vel_map, - const enum gkyl_gyrokinetic_bc_type *bctype_conf); +gkyl_gk_collisionless_passive_flux *gkyl_gk_collisionless_passive_flux_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_array *passive_speeds, + const double charge, const double mass, const struct gk_geometry *gk_geom, + const struct gkyl_dg_geom *dg_geom, const struct gkyl_gk_dg_geom *gk_dg_geom, + const struct gkyl_velocity_map *vel_map, const enum gkyl_gyrokinetic_bc_type *bctype_conf +); -void gkyl_gk_collisionless_passive_flux_surf_cu(gkyl_gk_collisionless_passive_flux *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_range *conf_ext_range, const struct gkyl_range *phase_ext_range, - const struct gkyl_array *fin, - struct gkyl_array *flux_surf, struct gkyl_array *cflrate); +void gkyl_gk_collisionless_passive_flux_surf_cu( + gkyl_gk_collisionless_passive_flux *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_range *phase_ext_range, const struct gkyl_array *fin, + struct gkyl_array *flux_surf, struct gkyl_array *cflrate +); diff --git a/gyrokinetic/zero/gkyl_gk_dg_geom.h b/gyrokinetic/zero/gkyl_gk_dg_geom.h index b846e69be9..eefe50da61 100644 --- a/gyrokinetic/zero/gkyl_gk_dg_geom.h +++ b/gyrokinetic/zero/gkyl_gk_dg_geom.h @@ -9,12 +9,11 @@ #include #include - // Geometry information for lower surfaces (left, bottom, front) for a cell struct gkyl_gk_dg_surf_geom { double B3; // n^3 \cdot \vec{B} double normcurlbhat; // normal to face perp to direction 'd' dotted with curl(bhat) - double bmag; // |B| + double bmag; // |B| struct gkyl_vec3 bhat; // Covariant components of bhat (b_i) double Jc; // J_c }; @@ -26,19 +25,17 @@ struct gkyl_gk_dg_vol_geom { struct gkyl_vec3 dualcurlbhat; // duals dotted with curl(bhat) }; - -// geometry information over a range of cells: +// geometry information over a range of cells: struct gkyl_gk_dg_geom { struct gkyl_range range; // range over which geometry is defined struct gkyl_range surf_quad_range; // range for indexing surface nodes - struct gkyl_range vol_quad_range; // range for indexing volume nodes + struct gkyl_range vol_quad_range; // range for indexing volume nodes - struct gkyl_array *surf_geom[GKYL_MAX_CDIM]; // surface geometry in dir 'd' in each cell struct gkyl_array *vol_geom; // cell geometry - + uint32_t flags; - struct gkyl_ref_count ref_count; + struct gkyl_ref_count ref_count; struct gkyl_gk_dg_geom *on_dev; // pointer to itself or device object }; @@ -58,7 +55,7 @@ struct gkyl_gk_dg_geom_inp { * * @param inp Inputs for use in constructing geometry */ -struct gkyl_gk_dg_geom* gkyl_gk_dg_geom_new(const struct gkyl_gk_dg_geom_inp *inp); +struct gkyl_gk_dg_geom *gkyl_gk_dg_geom_new(const struct gkyl_gk_dg_geom_inp *inp); /** * Create a new DG geometry object from host object. @@ -67,9 +64,13 @@ struct gkyl_gk_dg_geom* gkyl_gk_dg_geom_new(const struct gkyl_gk_dg_geom_inp *in * @param inp Inputs for use in constructing geometry * @param use_gpu whether to use gpu */ -struct gkyl_gk_dg_geom* gkyl_gk_dg_geom_new_from_host(const struct gkyl_gk_dg_geom_inp *inp, struct gkyl_gk_dg_geom *up_host, bool use_gpu); +struct gkyl_gk_dg_geom *gkyl_gk_dg_geom_new_from_host( + const struct gkyl_gk_dg_geom_inp *inp, struct gkyl_gk_dg_geom *up_host, bool use_gpu +); -struct gkyl_gk_dg_geom* gkyl_gk_dg_geom_cu_dev_new_from_host(const struct gkyl_gk_dg_geom_inp *inp, struct gkyl_gk_dg_geom *up_host); +struct gkyl_gk_dg_geom *gkyl_gk_dg_geom_cu_dev_new_from_host( + const struct gkyl_gk_dg_geom_inp *inp, struct gkyl_gk_dg_geom *up_host +); /** * Acquire pointer to geometry object. The pointer must be released @@ -78,7 +79,7 @@ struct gkyl_gk_dg_geom* gkyl_gk_dg_geom_cu_dev_new_from_host(const struct gkyl_g * @param dgg Geometry to which a pointer is needed * @return Pointer to acquired geometry */ -struct gkyl_gk_dg_geom* gkyl_gk_dg_geom_acquire(const struct gkyl_gk_dg_geom* dgg); +struct gkyl_gk_dg_geom *gkyl_gk_dg_geom_acquire(const struct gkyl_gk_dg_geom *dgg); /** * Write out geometry data to file. The "fprefix" is the prefix of the @@ -87,7 +88,7 @@ struct gkyl_gk_dg_geom* gkyl_gk_dg_geom_acquire(const struct gkyl_gk_dg_geom* dg * @param dgg Geometry to which a pointer is needed * @param fname Name of output file to write */ -void gkyl_gk_dg_geom_write(const struct gkyl_gk_dg_geom* dgg, const char *fprefix); +void gkyl_gk_dg_geom_write(const struct gkyl_gk_dg_geom *dgg, const char *fprefix); /** * Get pointer to geometry on the surface normal to 'd' given by idx @@ -100,11 +101,12 @@ void gkyl_gk_dg_geom_write(const struct gkyl_gk_dg_geom* dgg, const char *fprefi * @param idx Index into grid * @return Pointer to surface geometry at all quadrature nodes in cell @a idx */ -GKYL_CU_DH -static inline const struct gkyl_gk_dg_surf_geom* +GKYL_CU_DH static inline const struct gkyl_gk_dg_surf_geom * gkyl_gk_dg_geom_get_surf(const struct gkyl_gk_dg_geom *dgg, int d, const int *idx) { - return (const struct gkyl_gk_dg_surf_geom*) gkyl_array_cfetch(dgg->surf_geom[d], gkyl_range_idx(&dgg->range, idx)); + return (const struct gkyl_gk_dg_surf_geom *)gkyl_array_cfetch( + dgg->surf_geom[d], gkyl_range_idx(&dgg->range, idx) + ); } /** @@ -115,8 +117,7 @@ gkyl_gk_dg_geom_get_surf(const struct gkyl_gk_dg_geom *dgg, int d, const int *id * @param idx Index (ndim-1) of surface quadrature node * @return Linear index for indexing surface quadrature array */ -GKYL_CU_DH -static inline long +GKYL_CU_DH static inline long gkyl_gk_dg_geom_surf_quad_idx(const struct gkyl_gk_dg_geom *dgg, const int *idx) { return gkyl_range_idx(&dgg->surf_quad_range, idx); @@ -131,11 +132,12 @@ gkyl_gk_dg_geom_surf_quad_idx(const struct gkyl_gk_dg_geom *dgg, const int *idx) * @param idx Index into grid * @return Pointer to cell geometry at all quadrature nodes in cell @a idx */ -GKYL_CU_DH -static inline const struct gkyl_gk_dg_vol_geom* +GKYL_CU_DH static inline const struct gkyl_gk_dg_vol_geom * gkyl_gk_dg_geom_get_vol(const struct gkyl_gk_dg_geom *dgg, const int *idx) { - return (const struct gkyl_gk_dg_vol_geom*) gkyl_array_cfetch(dgg->vol_geom, gkyl_range_idx(&dgg->range, idx)); + return (const struct gkyl_gk_dg_vol_geom *)gkyl_array_cfetch( + dgg->vol_geom, gkyl_range_idx(&dgg->range, idx) + ); } /** @@ -146,8 +148,7 @@ gkyl_gk_dg_geom_get_vol(const struct gkyl_gk_dg_geom *dgg, const int *idx) * @param vidx Index of volume quadrature node * @return Linear index for indexing volume quadrature array */ -GKYL_CU_DH -static inline long +GKYL_CU_DH static inline long gkyl_gk_dg_geom_vol_quad_idx(const struct gkyl_gk_dg_geom *dgg, const int *vidx) { return gkyl_range_idx(&dgg->vol_quad_range, vidx); @@ -175,7 +176,9 @@ void gk_dg_geom_free(const struct gkyl_ref_count *ref); * @param gk_dg_geom gk_dg_geom object (stores geo specific to gyrokinetics) * @param gk_geom gk_geom object from which to populate dg geom objects */ -void gkyl_gk_dg_geom_populate_vol(struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_geom *gk_dg_geom, struct gk_geometry* gk_geom); +void gkyl_gk_dg_geom_populate_vol( + struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_geom *gk_dg_geom, struct gk_geometry *gk_geom +); /** * Populate surface quad point DG geometry objects @@ -185,4 +188,6 @@ void gkyl_gk_dg_geom_populate_vol(struct gkyl_dg_geom *dg_geom, struct gkyl_gk_d * @param gk_dg_geom gk_dg_geom object (stores geo specific to gyrokinetics) * @param gk_geom gk_geom object from which to populate dg geom objects */ -void gkyl_gk_dg_geom_populate_surf(struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_geom *gk_dg_geom, struct gk_geometry* gk_geom); +void gkyl_gk_dg_geom_populate_surf( + struct gkyl_dg_geom *dg_geom, struct gkyl_gk_dg_geom *gk_dg_geom, struct gk_geometry *gk_geom +); diff --git a/gyrokinetic/zero/gkyl_gk_geometry.h b/gyrokinetic/zero/gkyl_gk_geometry.h index 1d6ce9e177..5a8c755213 100644 --- a/gyrokinetic/zero/gkyl_gk_geometry.h +++ b/gyrokinetic/zero/gkyl_gk_geometry.h @@ -11,44 +11,51 @@ #include #include - typedef struct gk_geometry gk_geometry; struct gk_geom_surf { - struct gkyl_array *jacobgeo; // 1 component. Configuration space jacobian J. - struct gkyl_array *jacobgeo_ratio; // 1 component. Ratio of jacobgeo from neigboring blocks (valid only at the boundary, stored in ghost cell). + struct gkyl_array * + jacobgeo_ratio; // 1 component. Ratio of jacobgeo from neigboring blocks (valid only at the boundary, stored in ghost cell). struct gkyl_array *bmag; // 1 component. B Magnitude of magnetic field. - struct gkyl_array *b_i; // 3 components. Contravariant components of magnetic field vector b_1, b_2, b_3. + struct gkyl_array + *b_i; // 3 components. Contravariant components of magnetic field vector b_1, b_2, b_3. struct gkyl_array *cmag; // 1 component. C = JB/sqrt(g_33). struct gkyl_array *jacobtot_inv; // 1 component. 1/(JB). struct gkyl_array *B3; // 1 component n^3 \dot \vec{B} = 1/g_33. struct gkyl_array *normcurlbhat; // 1 component, n^m \dot curl(bhat). - struct gkyl_array *normals; // 9 components Cartesian components of normal. vectors in order n^1, n^2, n^3. + struct gkyl_array + *normals; // 9 components Cartesian components of normal. vectors in order n^1, n^2, n^3. struct gkyl_array *lenr; // 1 components Jc|n^i|. struct gkyl_array *bimpactangle; // 1 component arcsin(1/sqrt(g_33 * g^33)) struct gkyl_array *deltats; // 1 component. Function of psi-alpha. // Arrays below are just for computation of arrays above - struct gkyl_array *mc2p_nodal_fd; // 3 components. Cartesian X,Y, and Z at surf quad nodes and nodes epsilon away. + struct gkyl_array + *mc2p_nodal_fd; // 3 components. Cartesian X,Y, and Z at surf quad nodes and nodes epsilon away. struct gkyl_array *mc2p_nodal; // 3 components. Cartesian X,Y, and Z at surf quad nodes. struct gkyl_array *bmag_nodal; // 1 component. B Magnitude of magnetic field. struct gkyl_array *curlbhat_nodal; // Cartesian components of curl(bhat). struct gkyl_array *normcurlbhat_nodal; // 1 component, n^m \dot curl(bhat). struct gkyl_array *jacobgeo_nodal; // 1 component. Configuration space jacobian J. - struct gkyl_array *b_i_nodal; // 3 components. Contravariant components of magnetic field vector b_1, b_2, b_3. + struct gkyl_array + *b_i_nodal; // 3 components. Contravariant components of magnetic field vector b_1, b_2, b_3. struct gkyl_array *b_i_nodal_fd; // 3 components. b_i at surf quad nodes and nodes epsilon away. struct gkyl_array *cmag_nodal; // 1 component. C = JB/sqrt(g_33). struct gkyl_array *jacobtot_inv_nodal; // 1 component. 1/(JB). struct gkyl_array *ddtheta_nodal; // dphi/dtheta, dR/dtheta, dz/dtheta at surf quad nodes. struct gkyl_array *ddpsi_nodal; // dPsi/dpsi at surf quad nodes. struct gkyl_array *g_ij_nodal; // g_{ij}. - struct gkyl_array *dxdz_nodal; // 9 components. Cartesian components of tangent Vectors stored in order e_1, e_2, e_3. - struct gkyl_array *dzdx_nodal; // 9 components. Cartesian components of dual vectors stroed in order e^1, e^2, e^3. + struct gkyl_array * + dxdz_nodal; // 9 components. Cartesian components of tangent Vectors stored in order e_1, e_2, e_3. + struct gkyl_array * + dzdx_nodal; // 9 components. Cartesian components of dual vectors stroed in order e^1, e^2, e^3. struct gkyl_array *dualmag_nodal; // 3 components norms of the dual vectors : sqrt(e^i.e^i). - struct gkyl_array *normals_nodal; // 9 components Cartesian components of normal vectors in order n^1,, n^2, n^3. - struct gkyl_array *bcart_nodal; // 3 components. Cartesian components of magnetic field unit vector b_X, b_Y, b_Z. - + struct gkyl_array + *normals_nodal; // 9 components Cartesian components of normal vectors in order n^1,, n^2, n^3. + struct gkyl_array + *bcart_nodal; // 3 components. Cartesian components of magnetic field unit vector b_X, b_Y, b_Z. + struct gkyl_array *B3_nodal; // 1 component n^3 \dot \vec{B} = 1/g_33. struct gkyl_array *lenr_nodal; // 1 components Jc|n^i|. struct gkyl_array *bimpactangle_nodal; // 1 component arcsin(1/sqrt(g_33 * g^33)) @@ -57,37 +64,47 @@ struct gk_geom_surf { struct gk_geom_corn { struct gkyl_array *mc2p; // 3 components. Cartesian X,Y, and Z. - struct gkyl_array *mc2p_deflated; // cdim components. Component removed (Z in 1x, R,Z in 2x, R,Z,phi in 3x). - struct gkyl_array *mc2nu_pos; // 3 components. Uniform computational space to non-uniform computational space mapping. - struct gkyl_array *mc2nu_pos_deflated; // cdim components. Uniform computational space to non-uniform computational space mapping. + struct gkyl_array + *mc2p_deflated; // cdim components. Component removed (Z in 1x, R,Z in 2x, R,Z,phi in 3x). + struct gkyl_array * + mc2nu_pos; // 3 components. Uniform computational space to non-uniform computational space mapping. + struct gkyl_array * + mc2nu_pos_deflated; // cdim components. Uniform computational space to non-uniform computational space mapping. struct gkyl_array *bmag; // 1 component. B Magnitude of magnetic field. struct gkyl_array *bmag_inv; // 1 component. 1/bmag. // Arrays below are just for computation of arrays above. struct gkyl_array *mc2p_nodal; // 3 components. Cartesian X,Y, and Z. - struct gkyl_array *mc2nu_pos_nodal; // 3 components. Uniform computational space to non-uniform computational space mapping + struct gkyl_array * + mc2nu_pos_nodal; // 3 components. Uniform computational space to non-uniform computational space mapping struct gkyl_array *bmag_nodal; // 1 components. Magnitude of Magnetic Field. - }; struct gk_geom_int { struct gkyl_array *mc2p; // 3 components. Cartesian X, Y and Z, struct gkyl_array *bmag; // 1 component. B Magnitude of magnetic field. - struct gkyl_array *g_ij; // 6 components. Metric coefficients g_{ij} Stored in order g_11, g12, g_13, g_22, g_23, g_33. - struct gkyl_array *g_ij_neut; // 6 components. Metric coefficients g_{ij} Stored in order g_11, g12, g_13, g_22, g_23, g_33. - // Calculated with coord definition alpha = phi for tokamak geometry. - struct gkyl_array *dxdz; // 9 components. Cartesian components of tangent Vectors stored in order e_1, e_2, e_3. - struct gkyl_array *dzdx; // 9 components. Cartesian components of dual vectors stored in order e^1, e^2, e^3. + struct gkyl_array * + g_ij; // 6 components. Metric coefficients g_{ij} Stored in order g_11, g12, g_13, g_22, g_23, g_33. + struct gkyl_array * + g_ij_neut; // 6 components. Metric coefficients g_{ij} Stored in order g_11, g12, g_13, g_22, g_23, g_33. + // Calculated with coord definition alpha = phi for tokamak geometry. + struct gkyl_array + *dxdz; // 9 components. Cartesian components of tangent Vectors stored in order e_1, e_2, e_3. + struct gkyl_array + *dzdx; // 9 components. Cartesian components of dual vectors stored in order e^1, e^2, e^3. struct gkyl_array *dualmag; // 3 components. Norms of the dual vectors: sqrt(e^i.e^i). - struct gkyl_array *normals; // 9 components. Cartesian components of normal vectors in order n^1,, n^2, n^3. + struct gkyl_array + *normals; // 9 components. Cartesian components of normal vectors in order n^1,, n^2, n^3. struct gkyl_array *jacobgeo; // 1 component. Configuration space jacobian J. struct gkyl_array *jacobgeo_ghost; // 1 component. Configuration space jacobian J. struct gkyl_array *jacobgeo_inv; // 1 component. 1/J struct gkyl_array *gij; // Metric coefficients g^{ij}. See g_ij for order. struct gkyl_array *gij_neut; // Metric coefficients g^{ij}. See g_ij for order. - // Calculated with coord definition alpha = phi for tokamak geometry. - struct gkyl_array *b_i; // 3 components. Covariant components of magnetic field unit vector b_1, b_2, b_3. - struct gkyl_array *bcart; // 3 components. Cartesian components of magnetic field unit vector b_X, b_Y, b_Z. + // Calculated with coord definition alpha = phi for tokamak geometry. + struct gkyl_array + *b_i; // 3 components. Covariant components of magnetic field unit vector b_1, b_2, b_3. + struct gkyl_array + *bcart; // 3 components. Cartesian components of magnetic field unit vector b_X, b_Y, b_Z. struct gkyl_array *cmag; // 1 component. C = JB/sqrt(g_33). struct gkyl_array *jacobtot; // 1 component. Phase space Jacobian = JB. struct gkyl_array *jacobtot_inv; // 1 component. 1/(JB). @@ -95,7 +112,8 @@ struct gk_geom_int { struct gkyl_array *gxyj; // 1 component. g^{xy} * J. For poisson solve. struct gkyl_array *gyyj; // 1 component. g^{yy} * J. For poisson solve. struct gkyl_array *gxzj; // 1 component. g^{xz} * J. For poisson solve if z derivatives are kept. - struct gkyl_array *eps2; // 1 component. eps2 = Jg^33 - J/g_33. For poisson if z derivatives are kept. + struct gkyl_array + *eps2; // 1 component. eps2 = Jg^33 - J/g_33. For poisson if z derivatives are kept. struct gkyl_array *dualcurlbhat; // 3 components, e^m \dot curl(bhat). struct gkyl_array *dualcurlbhatoverB; // 3 components, e^m \dot curl(bhat)/|B|. struct gkyl_array *rtg33inv; // 1 component 1/sqrt(g_33). @@ -106,7 +124,7 @@ struct gk_geom_int { // Arrays below are just for computation of arrays above struct gkyl_array *bmag_nodal; struct gkyl_array *ddtheta_nodal; - struct gkyl_array *ddpsi_nodal;// dPsi/dpsi at interior quad nodes + struct gkyl_array *ddpsi_nodal; // dPsi/dpsi at interior quad nodes struct gkyl_array *mc2p_nodal; // 3 components. Cartesian X,Y, and Z struct gkyl_array *mc2p_nodal_fd; // 39 components. Cartesian X,Y, and Z at nodes and FD nodes. /* Array containing cartesian coordinates at nodes and nearby nodes (epsilon and 2 epsilon away) used for FD @@ -123,26 +141,28 @@ struct gk_geom_int { */ struct gkyl_array *curlbhat_nodal; // Cartesian components of curl(bhat) struct gkyl_array *dualcurlbhat_nodal; // 3 components, e^m \dot curl(bhat) - struct gkyl_array *jacobgeo_nodal; // jacobian - struct gkyl_array *g_ij_nodal; // 6 components. - // Metric coefficients g_{ij} Stored in order g_11, g12, g_13, g_22, g_23, g_33 - struct gkyl_array *g_ij_neut_nodal; // 6 components. - // Metric coefficients g_{ij} Stored in order g_11, g12, g_13, g_22, g_23, g_33 - // Calculated with coord definition alpha = phi for tokamak geometry + struct gkyl_array *jacobgeo_nodal; // jacobian + struct gkyl_array *g_ij_nodal; // 6 components. + // Metric coefficients g_{ij} Stored in order g_11, g12, g_13, g_22, g_23, g_33 + struct gkyl_array *g_ij_neut_nodal; // 6 components. + // Metric coefficients g_{ij} Stored in order g_11, g12, g_13, g_22, g_23, g_33 + // Calculated with coord definition alpha = phi for tokamak geometry struct gkyl_array *dxdz_nodal; // 9 components. - // Cartesian components of tangent Vectors stored in order e_1, e_2, e_3 + // Cartesian components of tangent Vectors stored in order e_1, e_2, e_3 struct gkyl_array *dzdx_nodal; // 9 components. - // Cartesian components of dual vectors stroed in order e^1, e^2, e^3 + // Cartesian components of dual vectors stroed in order e^1, e^2, e^3 struct gkyl_array *dualmag_nodal; // 3 components - // norms of the dual vectors : sqrt(e^i.e^i) + // norms of the dual vectors : sqrt(e^i.e^i) struct gkyl_array *normals_nodal; // 9 components - // Cartesian components of normal vectors in order n^1,, n^2, n^3 - struct gkyl_array *gij_neut_nodal; // Metric coefficients g^{ij}. See g_ij for order. - // Calculated with coord definition alpha = phi for tokamak geometry - struct gkyl_array *b_i_nodal; // 3 components. Covariant components of magnetic field unit vector b_1, b_2, b_3. + // Cartesian components of normal vectors in order n^1,, n^2, n^3 + struct gkyl_array *gij_neut_nodal; // Metric coefficients g^{ij}. See g_ij for order. + // Calculated with coord definition alpha = phi for tokamak geometry + struct gkyl_array + *b_i_nodal; // 3 components. Covariant components of magnetic field unit vector b_1, b_2, b_3. struct gkyl_array *b_i_nodal_fd; // 3 components. b_i at interior quad nodes and nodes epsilon away - struct gkyl_array *bcart_nodal; // 3 components. Cartesian components of magnetic field unit vector b_X, b_Y, b_Z. - struct gkyl_array *B3_nodal; // 1 component e^3 \dot \vec{B} = 1/g_33 + struct gkyl_array + *bcart_nodal; // 3 components. Cartesian components of magnetic field unit vector b_X, b_Y, b_Z. + struct gkyl_array *B3_nodal; // 1 component e^3 \dot \vec{B} = 1/g_33 struct gkyl_array *dualcurlbhatoverB_nodal; // 3 components, e^m \dot curl(bhat)/|B| struct gkyl_array *rtg33inv_nodal; // 1 component 1/sqrt(g_33) struct gkyl_array *bioverJB_nodal; // 3 components b_i/J/|B| @@ -174,14 +194,14 @@ struct gk_geometry { struct gk_geom_surf geo_surf[3]; // Surface geometry. int geqdsk_sign_convention; // 0 if psi increases away from magnetic axis. - // 1 if psi increases toward magnetic axis. + // 1 if psi increases toward magnetic axis. int half_domain; // For double null geometry. 0 for full domain 1 for lower half domain. bool has_LCFS; // Whether the geometry has an LCFS. double x_LCFS; // For mapc2p IWL geometry, the user has to provide the - // location of the LCFS. For numerical IWL, it may be stored - // in the eqdsk. + // location of the LCFS. For numerical IWL, it may be stored + // in the eqdsk. int idx_LCFS_lo; // Index of the cell that abuts the LCFS from below. // Functions defining the twistshift for parallel BCs. @@ -190,15 +210,14 @@ struct gk_geometry { void *parallel_lower_bc_shift_ctx; // Context for parallel_lower_bc_shift_func. void *parallel_upper_bc_shift_ctx; // Context for parallel_upper_bc_shift_func. - struct gkyl_msgpack_map_elem* io_meta_basic; // Metadata for I/O. + struct gkyl_msgpack_map_elem *io_meta_basic; // Metadata for I/O. int io_meta_basic_len; // Number of elements in io_meta_basic. - + uint32_t flags; - struct gkyl_ref_count ref_count; + struct gkyl_ref_count ref_count; struct gk_geometry *on_dev; // Pointer to itself or device object. }; - // Inputs to create geometry for a specific computational grid. struct gkyl_mirror_geo_grid_inp { char filename_psi[256]; // File with psi(R,Z) data. @@ -232,8 +251,10 @@ struct gkyl_gk_geometry_inp { void *parallel_upper_bc_shift_ctx; // Context for parallel_upper_bc_shift_func. struct gkyl_efit_inp efit_info; // Context with RZ data such as efit file for a tokamak or mirror. - struct gkyl_tok_geo_grid_inp tok_grid_info; // Context for tokamak geometry with computational domain info. - struct gkyl_mirror_geo_grid_inp mirror_grid_info; // Context for mirror geometry with computational domain info. + struct gkyl_tok_geo_grid_inp + tok_grid_info; // Context for tokamak geometry with computational domain info. + struct gkyl_mirror_geo_grid_inp + mirror_grid_info; // Context for mirror geometry with computational domain info. struct gkyl_position_map *position_map; // Position map object. struct gkyl_comm *comm; // Communicator object. @@ -257,7 +278,6 @@ struct gkyl_gk_geometry_inp { struct gkyl_range global; struct gkyl_range global_ext; struct gkyl_basis basis; - }; /** @@ -272,15 +292,16 @@ struct gkyl_gk_geometry_inp { * @param geometry_inp geometry input struct containing grid, range, and other geo info * @param use_gpu whether or not to use gpu */ -struct gk_geometry* -gkyl_gk_geometry_new(struct gk_geometry* geo_host, struct gkyl_gk_geometry_inp *geometry_inp, bool use_gpu); +struct gk_geometry *gkyl_gk_geometry_new( + struct gk_geometry *geo_host, struct gkyl_gk_geometry_inp *geometry_inp, bool use_gpu +); /** * Create a new gk geometry object that lives on NV-GPU from a host geometry object: see new() method * above for documentation. */ -struct gk_geometry* -gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometry_inp *geometry_inp); +struct gk_geometry * +gkyl_gk_geometry_cu_dev_new(struct gk_geometry *geo_host, struct gkyl_gk_geometry_inp *geometry_inp); /** * Augment a grid with dim < 3 to 3d by adding 1 cell in the other directions @@ -290,10 +311,9 @@ gkyl_gk_geometry_cu_dev_new(struct gk_geometry* geo_host, struct gkyl_gk_geometr * @param grid Input grid with dim <3. * @param geometry Geometry input struct with context for augmenting grid. */ -struct gkyl_rect_grid +struct gkyl_rect_grid gkyl_gk_geometry_augment_grid(struct gkyl_rect_grid grid, struct gkyl_gk_geometry_inp geometry); - /** * Augment a range with dim < 3 to 3d by adding 1 cell in the other directions * If dim=1, the input range is assumed to be in z @@ -304,8 +324,10 @@ gkyl_gk_geometry_augment_grid(struct gkyl_rect_grid grid, struct gkyl_gk_geometr * @param ext_range Output, augmented extended range. * @param range Output, augmented range. */ -void -gkyl_gk_geometry_augment_local(const struct gkyl_range *inrange, const int *nghost, struct gkyl_range *ext_range, struct gkyl_range *range); +void gkyl_gk_geometry_augment_local( + const struct gkyl_range *inrange, const int *nghost, struct gkyl_range *ext_range, + struct gkyl_range *range +); /** * Reduce bmag to get min or max value, by evaluating bmag at basis nodes. @@ -314,7 +336,7 @@ gkyl_gk_geometry_augment_local(const struct gkyl_range *inrange, const int *ngho * @param up gk_geometry object. * @param op Pperation to perform (GKYL_MAX or GKYL_MIN). */ -double gkyl_gk_geometry_reduce_bmag(struct gk_geometry* up, enum gkyl_array_op op); +double gkyl_gk_geometry_reduce_bmag(struct gk_geometry *up, enum gkyl_array_op op); /** * Reduce bmag to get min or max value, by evaluating bmag at basis nodes, @@ -325,7 +347,8 @@ double gkyl_gk_geometry_reduce_bmag(struct gk_geometry* up, enum gkyl_array_op o * @param op Operation to perform (GKYL_MAX or GKYL_MIN). * @param op Coordinate where extrema occurs. */ -double gkyl_gk_geometry_reduce_arg_bmag(struct gk_geometry* up, enum gkyl_array_op op, double *coord); +double +gkyl_gk_geometry_reduce_arg_bmag(struct gk_geometry *up, enum gkyl_array_op op, double *coord); /** * Init nodal range from modal range @@ -334,8 +357,9 @@ double gkyl_gk_geometry_reduce_arg_bmag(struct gk_geometry* up, enum gkyl_array_ * @param range modal Range. * @param poly_order Polynomial order. */ -void -gkyl_gk_geometry_init_nodal_range( struct gkyl_range *nrange, struct gkyl_range *range, int poly_order); +void gkyl_gk_geometry_init_nodal_range( + struct gkyl_range *nrange, struct gkyl_range *range, int poly_order +); /** * Init nodal grid from modal grid @@ -344,8 +368,9 @@ gkyl_gk_geometry_init_nodal_range( struct gkyl_range *nrange, struct gkyl_range * @param grid Modal grid. * @param nrange Nodal range. */ -void -gkyl_gk_geometry_init_nodal_grid(struct gkyl_rect_grid *ngrid, struct gkyl_rect_grid *grid, struct gkyl_range *nrange); +void gkyl_gk_geometry_init_nodal_grid( + struct gkyl_rect_grid *ngrid, struct gkyl_rect_grid *grid, struct gkyl_range *nrange +); /** * Deflate geometry to lower dimensionality. @@ -357,7 +382,8 @@ gkyl_gk_geometry_init_nodal_grid(struct gkyl_rect_grid *ngrid, struct gkyl_rect_ * @param basis deflated basis * @param use_gpu whether or not to use gpu */ -struct gk_geometry* gkyl_gk_geometry_deflate(const struct gk_geometry* up_3d, struct gkyl_gk_geometry_inp *geometry_inp); +struct gk_geometry * +gkyl_gk_geometry_deflate(const struct gk_geometry *up_3d, struct gkyl_gk_geometry_inp *geometry_inp); /** * Populate nodal arrays from modal geometry @@ -371,7 +397,10 @@ void gkyl_gk_geometry_populate_nodal(struct gk_geometry *gk_geom); * @param io_meta_basic_basic basic metadata * @param io_meta_basic_basic_len length of basic metadata */ -void gkyl_gk_geometry_write_efit(struct gkyl_gk_geometry_inp *geometry_inp, struct gkyl_msgpack_map_elem* io_meta_basic_basic, int io_meta_basic_basic_len); +void gkyl_gk_geometry_write_efit( + struct gkyl_gk_geometry_inp *geometry_inp, struct gkyl_msgpack_map_elem *io_meta_basic_basic, + int io_meta_basic_basic_len +); /** * Reset the metadata values with corresponding values in GK geometry object @@ -388,7 +417,7 @@ void gkyl_gk_geometry_reset_io_meta(struct gk_geometry *up); * @param up Geometry to which a pointer is needed * @return Pointer to acquired geometry */ -struct gk_geometry* gkyl_gk_geometry_acquire(const struct gk_geometry* up); +struct gk_geometry *gkyl_gk_geometry_acquire(const struct gk_geometry *up); void gkyl_gk_geometry_free(const struct gkyl_ref_count *ref); diff --git a/gyrokinetic/zero/gkyl_gk_geometry_mapc2p.h b/gyrokinetic/zero/gkyl_gk_geometry_mapc2p.h index bec15bd968..55b8a4a152 100644 --- a/gyrokinetic/zero/gkyl_gk_geometry_mapc2p.h +++ b/gyrokinetic/zero/gkyl_gk_geometry_mapc2p.h @@ -7,7 +7,4 @@ * @param geometry_inp geometry input struct containing grid, range, and other geo info */ -struct gk_geometry* gkyl_gk_geometry_mapc2p_new(struct gkyl_gk_geometry_inp *geometry_inp); - - - +struct gk_geometry *gkyl_gk_geometry_mapc2p_new(struct gkyl_gk_geometry_inp *geometry_inp); diff --git a/gyrokinetic/zero/gkyl_gk_geometry_mirror.h b/gyrokinetic/zero/gkyl_gk_geometry_mirror.h index 215d56530e..88aec4b48a 100644 --- a/gyrokinetic/zero/gkyl_gk_geometry_mirror.h +++ b/gyrokinetic/zero/gkyl_gk_geometry_mirror.h @@ -6,4 +6,4 @@ * * @param geometry_inp geometry input struct containing grid, range, and other geo info */ -struct gk_geometry* gkyl_gk_geometry_mirror_new(struct gkyl_gk_geometry_inp *geometry_inp); \ No newline at end of file +struct gk_geometry *gkyl_gk_geometry_mirror_new(struct gkyl_gk_geometry_inp *geometry_inp); \ No newline at end of file diff --git a/gyrokinetic/zero/gkyl_gk_geometry_priv.h b/gyrokinetic/zero/gkyl_gk_geometry_priv.h index 53815616a1..eb3bb8e055 100644 --- a/gyrokinetic/zero/gkyl_gk_geometry_priv.h +++ b/gyrokinetic/zero/gkyl_gk_geometry_priv.h @@ -1,8 +1,7 @@ #include #include -static inline void -get_filename_from_path(const char *filepath, char *out_buffer, size_t out_size) +static inline void get_filename_from_path(const char *filepath, char *out_buffer, size_t out_size) { // Remove path from 'filepath' and output only the file name (including its extension) // to the buffer 'out_buffer' of size 'out_size'. @@ -15,103 +14,146 @@ get_filename_from_path(const char *filepath, char *out_buffer, size_t out_size) } } -static double calc_running_coord(double coord_lo, int i, double dx) { - double dels[2] = {1.0/sqrt(3), 1.0-1.0/sqrt(3) }; +static double calc_running_coord(double coord_lo, int i, double dx) +{ + double dels[2] = {1.0 / sqrt(3), 1.0 - 1.0 / sqrt(3)}; double coord = coord_lo; - for(int j = 0; j < i; j++) - coord+=dels[j%2]*dx; + for (int j = 0; j < i; j++) { + coord += dels[j % 2] * dx; + } return coord; } -static double calc_running_surf_coord(double coord_lo, int i, double dx) { - double dels[3] = {(1.0-1.0/sqrt(3))/2.0, 1.0/sqrt(3), (1.0-1.0/sqrt(3))/2.0 }; +static double calc_running_surf_coord(double coord_lo, int i, double dx) +{ + double dels[3] = {(1.0 - 1.0 / sqrt(3)) / 2.0, 1.0 / sqrt(3), (1.0 - 1.0 / sqrt(3)) / 2.0}; double coord = coord_lo; - for(int j = 0; j < i; j++) - coord+=dels[j%3]*dx; + for (int j = 0; j < i; j++) { + coord += dels[j % 3] * dx; + } return coord; } -static void gk_geometry_set_nodal_ranges(struct gk_geometry* up) +static void gk_geometry_set_nodal_ranges(struct gk_geometry *up) { int poly_order = up->basis.poly_order; // nodes tensor int num_nodes_corners[GKYL_MAX_CDIM]; if (poly_order == 1) { - for (int d=0; dgrid.ndim; ++d) + for (int d = 0; d < up->grid.ndim; ++d) { num_nodes_corners[d] = gkyl_range_shape(&up->local, d) + 1; + } } if (poly_order == 2) { - for (int d=0; dgrid.ndim; ++d) - num_nodes_corners[d] = 2*gkyl_range_shape(&up->local, d) + 1; + for (int d = 0; d < up->grid.ndim; ++d) { + num_nodes_corners[d] = 2 * gkyl_range_shape(&up->local, d) + 1; + } } - int num_quad_points = poly_order+1; + int num_quad_points = poly_order + 1; int num_nodes_quad_interior[GKYL_MAX_CDIM]; - for (int d=0; dgrid.ndim; ++d) - num_nodes_quad_interior[d] = gkyl_range_shape(&up->local, d)*num_quad_points; + for (int d = 0; d < up->grid.ndim; ++d) { + num_nodes_quad_interior[d] = gkyl_range_shape(&up->local, d) * num_quad_points; + } int num_nodes_quad_surf_in_dir[up->grid.ndim][GKYL_MAX_CDIM]; - for (int dir=0; dirgrid.ndim; ++dir) - for (int d=0; dgrid.ndim; ++d) - num_nodes_quad_surf_in_dir[dir][d] = d == dir ? gkyl_range_shape(&up->local, d)+1 : gkyl_range_shape(&up->local, d)*num_quad_points; + for (int dir = 0; dir < up->grid.ndim; ++dir) { + for (int d = 0; d < up->grid.ndim; ++d) { + num_nodes_quad_surf_in_dir[dir][d] = d == dir ? + gkyl_range_shape(&up->local, d) + 1 : + gkyl_range_shape(&up->local, d) * num_quad_points; + } + } gkyl_range_init_from_shape(&up->nrange_corn, up->grid.ndim, num_nodes_corners); gkyl_range_init_from_shape(&up->nrange_int, up->grid.ndim, num_nodes_quad_interior); - for (int dir=0; dirgrid.ndim; ++dir) - gkyl_range_init_from_shape(&up->nrange_surf[dir], up->grid.ndim, num_nodes_quad_surf_in_dir[dir]); + for (int dir = 0; dir < up->grid.ndim; ++dir) { + gkyl_range_init_from_shape( + &up->nrange_surf[dir], up->grid.ndim, num_nodes_quad_surf_in_dir[dir] + ); + } } -static void -gk_geometry_surf_alloc_nodal(struct gk_geometry* gk_geom, int dir) +static void gk_geometry_surf_alloc_nodal(struct gk_geometry *gk_geom, int dir) { // mapc2p for calculations of tangents int num_fd_nodes = 13; - gk_geom->geo_surf[dir].mc2p_nodal_fd = gkyl_array_new(GKYL_DOUBLE, 3*num_fd_nodes, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].mc2p_nodal_fd = + gkyl_array_new(GKYL_DOUBLE, 3 * num_fd_nodes, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].mc2p_nodal = + gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); // bmag,metrics and derived geo quantities - gk_geom->geo_surf[dir].bmag_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].ddtheta_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].ddpsi_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].curlbhat_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].normcurlbhat_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].jacobgeo_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].b_i_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].b_i_nodal_fd = gkyl_array_new(GKYL_DOUBLE, 3*num_fd_nodes, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].cmag_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].jacobtot_inv_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].g_ij_nodal = gkyl_array_new(GKYL_DOUBLE, 6, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].dxdz_nodal = gkyl_array_new(GKYL_DOUBLE, 9, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].dzdx_nodal = gkyl_array_new(GKYL_DOUBLE, 9, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].normals_nodal = gkyl_array_new(GKYL_DOUBLE, 9, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].dualmag_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].bcart_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].B3_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].lenr_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].bimpactangle_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); - gk_geom->geo_surf[dir].deltats_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].bmag_nodal = + gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].ddtheta_nodal = + gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].ddpsi_nodal = + gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].curlbhat_nodal = + gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].normcurlbhat_nodal = + gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].jacobgeo_nodal = + gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].b_i_nodal = + gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].b_i_nodal_fd = + gkyl_array_new(GKYL_DOUBLE, 3 * num_fd_nodes, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].cmag_nodal = + gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].jacobtot_inv_nodal = + gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].g_ij_nodal = + gkyl_array_new(GKYL_DOUBLE, 6, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].dxdz_nodal = + gkyl_array_new(GKYL_DOUBLE, 9, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].dzdx_nodal = + gkyl_array_new(GKYL_DOUBLE, 9, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].normals_nodal = + gkyl_array_new(GKYL_DOUBLE, 9, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].dualmag_nodal = + gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].bcart_nodal = + gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].B3_nodal = + gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].lenr_nodal = + gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].bimpactangle_nodal = + gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); + gk_geom->geo_surf[dir].deltats_nodal = + gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_surf[dir].volume); } -static void -gk_geometry_surf_alloc_expansions(struct gk_geometry* up, int dir) +static void gk_geometry_surf_alloc_expansions(struct gk_geometry *up, int dir) { - up->geo_surf[dir].bmag = gkyl_array_new(GKYL_DOUBLE, 1*up->num_surf_basis, up->local_ext.volume); - up->geo_surf[dir].jacobgeo = gkyl_array_new(GKYL_DOUBLE, 1*up->num_surf_basis, up->local_ext.volume); - up->geo_surf[dir].jacobgeo_ratio = gkyl_array_new(GKYL_DOUBLE, 1*up->num_surf_basis, up->local_ext.volume); - up->geo_surf[dir].b_i = gkyl_array_new(GKYL_DOUBLE, 3*up->num_surf_basis, up->local_ext.volume); - up->geo_surf[dir].cmag = gkyl_array_new(GKYL_DOUBLE, 1*up->num_surf_basis, up->local_ext.volume); - up->geo_surf[dir].jacobtot_inv = gkyl_array_new(GKYL_DOUBLE, 1*up->num_surf_basis, up->local_ext.volume); - up->geo_surf[dir].B3 = gkyl_array_new(GKYL_DOUBLE, 1*up->num_surf_basis, up->local_ext.volume); - up->geo_surf[dir].normcurlbhat = gkyl_array_new(GKYL_DOUBLE, 1*up->num_surf_basis, up->local_ext.volume); - up->geo_surf[dir].normals = gkyl_array_new(GKYL_DOUBLE, 9*up->num_surf_basis, up->local_ext.volume); - up->geo_surf[dir].lenr = gkyl_array_new(GKYL_DOUBLE, 1*up->num_surf_basis, up->local_ext.volume); - up->geo_surf[dir].bimpactangle = gkyl_array_new(GKYL_DOUBLE, 1*up->num_surf_basis, up->local_ext.volume); - up->geo_surf[dir].deltats = gkyl_array_new(GKYL_DOUBLE, 1*up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].bmag = + gkyl_array_new(GKYL_DOUBLE, 1 * up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].jacobgeo = + gkyl_array_new(GKYL_DOUBLE, 1 * up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].jacobgeo_ratio = + gkyl_array_new(GKYL_DOUBLE, 1 * up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].b_i = gkyl_array_new(GKYL_DOUBLE, 3 * up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].cmag = + gkyl_array_new(GKYL_DOUBLE, 1 * up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].jacobtot_inv = + gkyl_array_new(GKYL_DOUBLE, 1 * up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].B3 = gkyl_array_new(GKYL_DOUBLE, 1 * up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].normcurlbhat = + gkyl_array_new(GKYL_DOUBLE, 1 * up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].normals = + gkyl_array_new(GKYL_DOUBLE, 9 * up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].lenr = + gkyl_array_new(GKYL_DOUBLE, 1 * up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].bimpactangle = + gkyl_array_new(GKYL_DOUBLE, 1 * up->num_surf_basis, up->local_ext.volume); + up->geo_surf[dir].deltats = + gkyl_array_new(GKYL_DOUBLE, 1 * up->num_surf_basis, up->local_ext.volume); } -static void -gk_geometry_surf_release_nodal(struct gk_geometry* gk_geom, int dir) +static void gk_geometry_surf_release_nodal(struct gk_geometry *gk_geom, int dir) { gkyl_array_release(gk_geom->geo_surf[dir].mc2p_nodal_fd); gkyl_array_release(gk_geom->geo_surf[dir].mc2p_nodal); @@ -137,12 +179,12 @@ gk_geometry_surf_release_nodal(struct gk_geometry* gk_geom, int dir) gkyl_array_release(gk_geom->geo_surf[dir].deltats_nodal); } -static void -gk_geometry_int_alloc_nodal(struct gk_geometry* gk_geom) +static void gk_geometry_int_alloc_nodal(struct gk_geometry *gk_geom) { // mapc2p for calculations of tangents int num_fd_nodes = 13; - gk_geom->geo_int.mc2p_nodal_fd = gkyl_array_new(GKYL_DOUBLE, 3*num_fd_nodes, gk_geom->nrange_int.volume); + gk_geom->geo_int.mc2p_nodal_fd = + gkyl_array_new(GKYL_DOUBLE, 3 * num_fd_nodes, gk_geom->nrange_int.volume); gk_geom->geo_int.mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_int.volume); // bmag.metrics and derived geo quantities gk_geom->geo_int.bmag_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_int.volume); @@ -159,52 +201,56 @@ gk_geometry_int_alloc_nodal(struct gk_geometry* gk_geom) gk_geom->geo_int.normals_nodal = gkyl_array_new(GKYL_DOUBLE, 9, gk_geom->nrange_int.volume); gk_geom->geo_int.gij_neut_nodal = gkyl_array_new(GKYL_DOUBLE, 6, gk_geom->nrange_int.volume); gk_geom->geo_int.b_i_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_int.volume); - gk_geom->geo_int.b_i_nodal_fd = gkyl_array_new(GKYL_DOUBLE, 3*num_fd_nodes, gk_geom->nrange_int.volume); + gk_geom->geo_int.b_i_nodal_fd = + gkyl_array_new(GKYL_DOUBLE, 3 * num_fd_nodes, gk_geom->nrange_int.volume); gk_geom->geo_int.bcart_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_int.volume); gk_geom->geo_int.B3_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_int.volume); - gk_geom->geo_int.dualcurlbhatoverB_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_int.volume); + gk_geom->geo_int.dualcurlbhatoverB_nodal = + gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_int.volume); gk_geom->geo_int.rtg33inv_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_int.volume); gk_geom->geo_int.bioverJB_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_int.volume); } -static void -gk_geometry_int_alloc_expansions(struct gk_geometry* up) +static void gk_geometry_int_alloc_expansions(struct gk_geometry *up) { // mapc2p - up->geo_int.mc2p = gkyl_array_new(GKYL_DOUBLE, 3*up->basis.num_basis, up->local_ext.volume); + up->geo_int.mc2p = gkyl_array_new(GKYL_DOUBLE, 3 * up->basis.num_basis, up->local_ext.volume); // bmag, metrics and derived geo quantities up->geo_int.bmag = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); - up->geo_int.g_ij = gkyl_array_new(GKYL_DOUBLE, 6*up->basis.num_basis, up->local_ext.volume); - up->geo_int.g_ij_neut = gkyl_array_new(GKYL_DOUBLE, 6*up->basis.num_basis, up->local_ext.volume); - up->geo_int.dxdz = gkyl_array_new(GKYL_DOUBLE, 9*up->basis.num_basis, up->local_ext.volume); - up->geo_int.dzdx = gkyl_array_new(GKYL_DOUBLE, 9*up->basis.num_basis, up->local_ext.volume); - up->geo_int.dualmag = gkyl_array_new(GKYL_DOUBLE, 3*up->basis.num_basis, up->local_ext.volume); - up->geo_int.normals = gkyl_array_new(GKYL_DOUBLE, 9*up->basis.num_basis, up->local_ext.volume); + up->geo_int.g_ij = gkyl_array_new(GKYL_DOUBLE, 6 * up->basis.num_basis, up->local_ext.volume); + up->geo_int.g_ij_neut = + gkyl_array_new(GKYL_DOUBLE, 6 * up->basis.num_basis, up->local_ext.volume); + up->geo_int.dxdz = gkyl_array_new(GKYL_DOUBLE, 9 * up->basis.num_basis, up->local_ext.volume); + up->geo_int.dzdx = gkyl_array_new(GKYL_DOUBLE, 9 * up->basis.num_basis, up->local_ext.volume); + up->geo_int.dualmag = gkyl_array_new(GKYL_DOUBLE, 3 * up->basis.num_basis, up->local_ext.volume); + up->geo_int.normals = gkyl_array_new(GKYL_DOUBLE, 9 * up->basis.num_basis, up->local_ext.volume); up->geo_int.jacobgeo = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); - up->geo_int.jacobgeo_ghost = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); + up->geo_int.jacobgeo_ghost = + gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); up->geo_int.jacobgeo_inv = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); - up->geo_int.gij = gkyl_array_new(GKYL_DOUBLE, 6*up->basis.num_basis, up->local_ext.volume); - up->geo_int.gij_neut = gkyl_array_new(GKYL_DOUBLE, 6*up->basis.num_basis, up->local_ext.volume); - up->geo_int.b_i = gkyl_array_new(GKYL_DOUBLE, 3*up->basis.num_basis, up->local_ext.volume); - up->geo_int.bcart = gkyl_array_new(GKYL_DOUBLE, 3*up->basis.num_basis, up->local_ext.volume); + up->geo_int.gij = gkyl_array_new(GKYL_DOUBLE, 6 * up->basis.num_basis, up->local_ext.volume); + up->geo_int.gij_neut = gkyl_array_new(GKYL_DOUBLE, 6 * up->basis.num_basis, up->local_ext.volume); + up->geo_int.b_i = gkyl_array_new(GKYL_DOUBLE, 3 * up->basis.num_basis, up->local_ext.volume); + up->geo_int.bcart = gkyl_array_new(GKYL_DOUBLE, 3 * up->basis.num_basis, up->local_ext.volume); up->geo_int.cmag = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); up->geo_int.jacobtot = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); up->geo_int.jacobtot_inv = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); - up->geo_int.gxxj= gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); - up->geo_int.gxyj= gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); - up->geo_int.gyyj= gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); - up->geo_int.gxzj= gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); - up->geo_int.eps2= gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); - up->geo_int.dualcurlbhat = gkyl_array_new(GKYL_DOUBLE, 3*up->basis.num_basis, up->local_ext.volume); - up->geo_int.dualcurlbhatoverB = gkyl_array_new(GKYL_DOUBLE, 3*up->basis.num_basis, up->local_ext.volume); - up->geo_int.rtg33inv = gkyl_array_new(GKYL_DOUBLE, 1*up->basis.num_basis, up->local_ext.volume); - up->geo_int.bioverJB = gkyl_array_new(GKYL_DOUBLE, 3*up->basis.num_basis, up->local_ext.volume); + up->geo_int.gxxj = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); + up->geo_int.gxyj = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); + up->geo_int.gyyj = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); + up->geo_int.gxzj = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); + up->geo_int.eps2 = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); + up->geo_int.dualcurlbhat = + gkyl_array_new(GKYL_DOUBLE, 3 * up->basis.num_basis, up->local_ext.volume); + up->geo_int.dualcurlbhatoverB = + gkyl_array_new(GKYL_DOUBLE, 3 * up->basis.num_basis, up->local_ext.volume); + up->geo_int.rtg33inv = gkyl_array_new(GKYL_DOUBLE, 1 * up->basis.num_basis, up->local_ext.volume); + up->geo_int.bioverJB = gkyl_array_new(GKYL_DOUBLE, 3 * up->basis.num_basis, up->local_ext.volume); up->geo_int.B3 = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); up->geo_int.qprofile = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); } -static void -gk_geometry_int_release_nodal(struct gk_geometry* gk_geom) +static void gk_geometry_int_release_nodal(struct gk_geometry *gk_geom) { gkyl_array_release(gk_geom->geo_int.mc2p_nodal_fd); gkyl_array_release(gk_geom->geo_int.mc2p_nodal); @@ -230,8 +276,7 @@ gk_geometry_int_release_nodal(struct gk_geometry* gk_geom) gkyl_array_release(gk_geom->geo_int.bioverJB_nodal); } -static void -gk_geometry_corn_alloc_nodal(struct gk_geometry* gk_geom) +static void gk_geometry_corn_alloc_nodal(struct gk_geometry *gk_geom) { // mapc2p gk_geom->geo_corn.mc2p_nodal = gkyl_array_new(GKYL_DOUBLE, 3, gk_geom->nrange_corn.volume); @@ -239,31 +284,32 @@ gk_geometry_corn_alloc_nodal(struct gk_geometry* gk_geom) gk_geom->geo_corn.bmag_nodal = gkyl_array_new(GKYL_DOUBLE, 1, gk_geom->nrange_corn.volume); } -static void -gk_geometry_corn_alloc_expansions(struct gk_geometry* up) +static void gk_geometry_corn_alloc_expansions(struct gk_geometry *up) { // mapc2p - up->geo_corn.mc2p = gkyl_array_new(GKYL_DOUBLE, 3*up->basis.num_basis, up->local_ext.volume); - up->geo_corn.mc2nu_pos = gkyl_array_new(GKYL_DOUBLE, 3*up->basis.num_basis, up->local_ext.volume); + up->geo_corn.mc2p = gkyl_array_new(GKYL_DOUBLE, 3 * up->basis.num_basis, up->local_ext.volume); + up->geo_corn.mc2nu_pos = + gkyl_array_new(GKYL_DOUBLE, 3 * up->basis.num_basis, up->local_ext.volume); // bmag up->geo_corn.bmag = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); up->geo_corn.bmag_inv = gkyl_array_new(GKYL_DOUBLE, up->basis.num_basis, up->local_ext.volume); // deflated quantities for plotting - up->geo_corn.mc2p_deflated = gkyl_array_new(GKYL_DOUBLE, up->grid.ndim*up->basis.num_basis, up->local_ext.volume); - up->geo_corn.mc2nu_pos_deflated = gkyl_array_new(GKYL_DOUBLE, up->grid.ndim*up->basis.num_basis, up->local_ext.volume); + up->geo_corn.mc2p_deflated = + gkyl_array_new(GKYL_DOUBLE, up->grid.ndim * up->basis.num_basis, up->local_ext.volume); + up->geo_corn.mc2nu_pos_deflated = + gkyl_array_new(GKYL_DOUBLE, up->grid.ndim * up->basis.num_basis, up->local_ext.volume); } -static void -gk_geometry_corn_release_nodal(struct gk_geometry* gk_geom) +static void gk_geometry_corn_release_nodal(struct gk_geometry *gk_geom) { gkyl_array_release(gk_geom->geo_corn.mc2p_nodal); gkyl_array_release(gk_geom->geo_corn.mc2nu_pos_nodal); gkyl_array_release(gk_geom->geo_corn.bmag_nodal); } -static void -gk_geometry_surf_calc_expansions(struct gk_geometry* gk_geom, int dir, - struct gkyl_range nrange_quad_surf) +static void gk_geometry_surf_calc_expansions( + struct gk_geometry *gk_geom, int dir, struct gkyl_range nrange_quad_surf +) { struct gk_geom_surf up_surf = gk_geom->geo_surf[dir]; struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&gk_geom->basis, &gk_geom->grid, false); @@ -274,24 +320,55 @@ gk_geometry_surf_calc_expansions(struct gk_geometry* gk_geom, int dir, upper[dir] += 1; gkyl_sub_range_init(&local_ext_in_dir, &gk_geom->local_ext, lower, upper); - gkyl_nodal_ops_n2m_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, up_surf.bmag_nodal, up_surf.bmag, dir); - gkyl_nodal_ops_n2m_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, up_surf.jacobgeo_nodal, up_surf.jacobgeo, dir); - gkyl_nodal_ops_n2m_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 3, up_surf.b_i_nodal, up_surf.b_i, dir); - gkyl_nodal_ops_n2m_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, up_surf.cmag_nodal, up_surf.cmag, dir); - gkyl_nodal_ops_n2m_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, up_surf.jacobtot_inv_nodal, up_surf.jacobtot_inv, dir); - gkyl_nodal_ops_n2m_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, up_surf.B3_nodal, up_surf.B3, dir); - gkyl_nodal_ops_n2m_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, up_surf.normcurlbhat_nodal, up_surf.normcurlbhat, dir); - gkyl_nodal_ops_n2m_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 9, up_surf.normals_nodal, up_surf.normals, dir); - gkyl_nodal_ops_n2m_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, up_surf.lenr_nodal, up_surf.lenr, dir); - gkyl_nodal_ops_n2m_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, up_surf.bimpactangle_nodal, up_surf.bimpactangle, dir); - gkyl_nodal_ops_n2m_surface(n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, up_surf.deltats_nodal, up_surf.deltats, dir); + gkyl_nodal_ops_n2m_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, + up_surf.bmag_nodal, up_surf.bmag, dir + ); + gkyl_nodal_ops_n2m_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, + up_surf.jacobgeo_nodal, up_surf.jacobgeo, dir + ); + gkyl_nodal_ops_n2m_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 3, + up_surf.b_i_nodal, up_surf.b_i, dir + ); + gkyl_nodal_ops_n2m_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, + up_surf.cmag_nodal, up_surf.cmag, dir + ); + gkyl_nodal_ops_n2m_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, + up_surf.jacobtot_inv_nodal, up_surf.jacobtot_inv, dir + ); + gkyl_nodal_ops_n2m_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, + up_surf.B3_nodal, up_surf.B3, dir + ); + gkyl_nodal_ops_n2m_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, + up_surf.normcurlbhat_nodal, up_surf.normcurlbhat, dir + ); + gkyl_nodal_ops_n2m_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 9, + up_surf.normals_nodal, up_surf.normals, dir + ); + gkyl_nodal_ops_n2m_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, + up_surf.lenr_nodal, up_surf.lenr, dir + ); + gkyl_nodal_ops_n2m_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, + up_surf.bimpactangle_nodal, up_surf.bimpactangle, dir + ); + gkyl_nodal_ops_n2m_surface( + n2m, &gk_geom->surf_basis, &gk_geom->grid, &nrange_quad_surf, &local_ext_in_dir, 1, + up_surf.deltats_nodal, up_surf.deltats, dir + ); // jacobgeo_ratio is not used in single block. int cdim = gk_geom->grid.ndim; gkyl_array_clear(up_surf.jacobgeo_ratio, 0.0); - gkyl_array_shiftc(up_surf.jacobgeo_ratio, pow(sqrt(2.0),cdim), 0); + gkyl_array_shiftc(up_surf.jacobgeo_ratio, pow(sqrt(2.0), cdim), 0); gkyl_nodal_ops_release(n2m); } - - diff --git a/gyrokinetic/zero/gkyl_gk_geometry_tok.h b/gyrokinetic/zero/gkyl_gk_geometry_tok.h index ea0fd03463..3bc0a8ae0f 100644 --- a/gyrokinetic/zero/gkyl_gk_geometry_tok.h +++ b/gyrokinetic/zero/gkyl_gk_geometry_tok.h @@ -6,7 +6,7 @@ * * @param geometry_inp geometry input struct containing grid, range, and other geo info */ -struct gk_geometry* gkyl_gk_geometry_tok_new(struct gkyl_gk_geometry_inp *geometry_inp); +struct gk_geometry *gkyl_gk_geometry_tok_new(struct gkyl_gk_geometry_inp *geometry_inp); /* * Set the lower and upper z-direction grid extents of a tokamak block @@ -16,9 +16,7 @@ struct gk_geometry* gkyl_gk_geometry_tok_new(struct gkyl_gk_geometry_inp *geomet * @param theta_lo on output lower extent in z direction * @param theta_up on output upper extent in z direction * */ -void -gkyl_gk_geometry_tok_set_grid_extents(struct gkyl_efit_inp efit_info, - struct gkyl_tok_geo_grid_inp grid_info, double *theta_lo, double *theta_up); - - - +void gkyl_gk_geometry_tok_set_grid_extents( + struct gkyl_efit_inp efit_info, struct gkyl_tok_geo_grid_inp grid_info, double *theta_lo, + double *theta_up +); diff --git a/gyrokinetic/zero/gkyl_gk_maxwellian_correct.h b/gyrokinetic/zero/gkyl_gk_maxwellian_correct.h index eea3c6c895..6a80f3767e 100644 --- a/gyrokinetic/zero/gkyl_gk_maxwellian_correct.h +++ b/gyrokinetic/zero/gkyl_gk_maxwellian_correct.h @@ -16,7 +16,8 @@ struct gkyl_gk_maxwellian_correct_inp { const struct gkyl_basis *conf_basis; // Configuration-space basis functions const struct gkyl_basis *phase_basis; // Phase-space basis functions const struct gkyl_range *conf_range; // Configuration-space range - const struct gkyl_range *conf_range_ext; // Extended configuration-space range (for internal memory allocations) + const struct gkyl_range + *conf_range_ext; // Extended configuration-space range (for internal memory allocations) const struct gkyl_range *vel_range; // velocity space range const struct gk_geometry *gk_geom; // Geometry object. const struct gkyl_velocity_map *vel_map; // Velocity space mapping object. @@ -24,7 +25,7 @@ struct gkyl_gk_maxwellian_correct_inp { bool bimaxwellian; // Bool for whether we are projecting a bi-Maxwellian instead of a Maxwellian. bool divide_jacobgeo; // Bool for whether to divide out the conf-space Jacobian from density. bool use_last_converged; // Boolean for if we are using the results of the iterative scheme - // *even if* the scheme fails to converge. + // *even if* the scheme fails to converge. bool use_gpu; // Bool for gpu useage. double eps; // Tolerance for the iterator. int max_iter; // Number of total iterations. @@ -35,7 +36,7 @@ struct gkyl_gk_maxwellian_correct_status { bool iter_converged; // true if iterations converged int num_iter; // number of iterations for the correction double error[4]; // error in each moment (n, u_par, T/m) or (n, u_par, T_par/m, T_perp/m) -}; +}; /** * Create new updater to correct the gyrokinetic Maxwellian (or bi-Maxwellian) @@ -44,7 +45,7 @@ struct gkyl_gk_maxwellian_correct_status { * @param inp Input parameters defined in gkyl_gk_maxwellian_correct_inp struct. * @return New updater pointer. */ -struct gkyl_gk_maxwellian_correct* +struct gkyl_gk_maxwellian_correct * gkyl_gk_maxwellian_correct_inew(const struct gkyl_gk_maxwellian_correct_inp *inp); /** @@ -61,10 +62,10 @@ gkyl_gk_maxwellian_correct_inew(const struct gkyl_gk_maxwellian_correct_inp *inp * @param conf_local Local configuration space range * @return Status of correction */ -struct gkyl_gk_maxwellian_correct_status -gkyl_gk_maxwellian_correct_all_moments(gkyl_gk_maxwellian_correct *up, - struct gkyl_array *f_max, const struct gkyl_array *moms_target, - const struct gkyl_range *phase_local, const struct gkyl_range *conf_local); +struct gkyl_gk_maxwellian_correct_status gkyl_gk_maxwellian_correct_all_moments( + gkyl_gk_maxwellian_correct *up, struct gkyl_array *f_max, const struct gkyl_array *moms_target, + const struct gkyl_range *phase_local, const struct gkyl_range *conf_local +); /** * Host-side wrapper for computing the absolute value of the @@ -78,10 +79,10 @@ gkyl_gk_maxwellian_correct_all_moments(gkyl_gk_maxwellian_correct *up, * @param moms_iter Iterative moments used in fixed-point iteration * @param moms_abs_diff Absolute value of the difference between the cell averages of moms_iter and moms_target */ -void gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu(const struct gkyl_range *conf_range, - int num_comp, int nc, - const struct gkyl_array *moms_target, const struct gkyl_array *moms_iter, - struct gkyl_array *moms_abs_diff); +void gkyl_gk_maxwellian_correct_all_moments_abs_diff_cu( + const struct gkyl_range *conf_range, int num_comp, int nc, const struct gkyl_array *moms_target, + const struct gkyl_array *moms_iter, struct gkyl_array *moms_abs_diff +); /** * Delete updater. diff --git a/gyrokinetic/zero/gkyl_gk_maxwellian_correct_priv.h b/gyrokinetic/zero/gkyl_gk_maxwellian_correct_priv.h index bf287918fd..a6f1414fd9 100644 --- a/gyrokinetic/zero/gkyl_gk_maxwellian_correct_priv.h +++ b/gyrokinetic/zero/gkyl_gk_maxwellian_correct_priv.h @@ -9,11 +9,10 @@ #include #include -struct gkyl_gk_maxwellian_correct -{ +struct gkyl_gk_maxwellian_correct { int num_conf_basis; // Number of configuration-space basis functions - int num_comp; // Number of components being corrected - // 3 for a Maxwellian (n, upar, T/m), 4 for a bi-Maxwellian (n, upar, Tpar/m, Tperp/m) + int num_comp; // Number of components being corrected + // 3 for a Maxwellian (n, upar, T/m), 4 for a bi-Maxwellian (n, upar, Tpar/m, Tperp/m) bool bimaxwellian; // Bool for whether we are correcting a bi-Maxwellian's moments. struct gkyl_velocity_map *vel_map; // Velocity space mapping object. @@ -30,9 +29,9 @@ struct gkyl_gk_maxwellian_correct double eps; // tolerance for the iterator int max_iter; // number of total iterations bool use_last_converged; // Boolean for if we are using the results of the iterative scheme - // *even if* the scheme fails to converge. + // *even if* the scheme fails to converge. bool use_gpu; // Boolean if we are performing projection on device. - double *error_cu; // error on device if using GPUs + double *error_cu; // error on device if using GPUs struct gkyl_array *abs_diff_moms; }; diff --git a/gyrokinetic/zero/gkyl_gk_maxwellian_moments.h b/gyrokinetic/zero/gkyl_gk_maxwellian_moments.h index dc650a526b..d409bf7477 100644 --- a/gyrokinetic/zero/gkyl_gk_maxwellian_moments.h +++ b/gyrokinetic/zero/gkyl_gk_maxwellian_moments.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include // Object type typedef struct gkyl_gk_maxwellian_moments gkyl_gk_maxwellian_moments; @@ -15,10 +15,11 @@ struct gkyl_gk_maxwellian_moments_inp { const struct gkyl_basis *conf_basis; // Configuration-space basis functions. const struct gkyl_basis *phase_basis; // Phase-space basis functions. const struct gkyl_range *conf_range; // Configuration-space range. - const struct gkyl_range *conf_range_ext; // Extended configuration-space range (for internal memory allocations) + const struct gkyl_range + *conf_range_ext; // Extended configuration-space range (for internal memory allocations) const struct gk_geometry *gk_geom; // Geometry object. const struct gkyl_velocity_map *vel_map; // Velocity mapping object. - double mass; // Mass factor. + double mass; // Mass factor. bool divide_jacobgeo; // Whether to divide out the conf-space Jacobian from density. bool use_gpu; // bool for gpu useage }; @@ -34,7 +35,7 @@ struct gkyl_gk_maxwellian_moments_inp { * @param inp Input parameters defined in gkyl_gk_maxwellian_moments_inp struct. * @return New updater pointer. */ -struct gkyl_gk_maxwellian_moments* +struct gkyl_gk_maxwellian_moments * gkyl_gk_maxwellian_moments_inew(const struct gkyl_gk_maxwellian_moments_inp *inp); /** @@ -48,9 +49,10 @@ gkyl_gk_maxwellian_moments_inew(const struct gkyl_gk_maxwellian_moments_inp *inp * @param fin Input distribution function * @param density_out Output density */ -void gkyl_gk_maxwellian_density_moment_advance(struct gkyl_gk_maxwellian_moments *up, - const struct gkyl_range *phase_local, const struct gkyl_range *conf_local, - const struct gkyl_array *fin, struct gkyl_array *density_out); +void gkyl_gk_maxwellian_density_moment_advance( + struct gkyl_gk_maxwellian_moments *up, const struct gkyl_range *phase_local, + const struct gkyl_range *conf_local, const struct gkyl_array *fin, struct gkyl_array *density_out +); /** * Compute the moments of an arbitrary distribution function for the equivalent @@ -66,9 +68,10 @@ void gkyl_gk_maxwellian_density_moment_advance(struct gkyl_gk_maxwellian_moments * @param fin Input distribution function * @param moms_out Output Maxwellian moments (n, u_par, T/m) */ -void gkyl_gk_maxwellian_moments_advance(struct gkyl_gk_maxwellian_moments *up, - const struct gkyl_range *phase_local, const struct gkyl_range *conf_local, - const struct gkyl_array *fin, struct gkyl_array *moms_out); +void gkyl_gk_maxwellian_moments_advance( + struct gkyl_gk_maxwellian_moments *up, const struct gkyl_range *phase_local, + const struct gkyl_range *conf_local, const struct gkyl_array *fin, struct gkyl_array *moms_out +); /** * Compute the moments of an arbitrary distribution function for the equivalent @@ -84,13 +87,14 @@ void gkyl_gk_maxwellian_moments_advance(struct gkyl_gk_maxwellian_moments *up, * @param fin Input distribution function * @param moms_out Output Maxwellian moments (n, u_par, T_par/m, T_perp/m) */ -void gkyl_gk_bimaxwellian_moments_advance(struct gkyl_gk_maxwellian_moments *up, - const struct gkyl_range *phase_local, const struct gkyl_range *conf_local, - const struct gkyl_array *fin, struct gkyl_array *moms_out); +void gkyl_gk_bimaxwellian_moments_advance( + struct gkyl_gk_maxwellian_moments *up, const struct gkyl_range *phase_local, + const struct gkyl_range *conf_local, const struct gkyl_array *fin, struct gkyl_array *moms_out +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_gk_maxwellian_moments_release(gkyl_gk_maxwellian_moments* up); +void gkyl_gk_maxwellian_moments_release(gkyl_gk_maxwellian_moments *up); diff --git a/gyrokinetic/zero/gkyl_gk_maxwellian_moments_priv.h b/gyrokinetic/zero/gkyl_gk_maxwellian_moments_priv.h index 73a0cc4d05..43e8d24513 100644 --- a/gyrokinetic/zero/gkyl_gk_maxwellian_moments_priv.h +++ b/gyrokinetic/zero/gkyl_gk_maxwellian_moments_priv.h @@ -7,20 +7,20 @@ #include #include -struct gkyl_gk_maxwellian_moments -{ +struct gkyl_gk_maxwellian_moments { struct gkyl_basis conf_basis; // Configuration-space basis struct gkyl_basis phase_basis; // Phase-space basis int num_conf_basis; // Number of configuration-space basis functions int vdim_phys; // Number of physical velocity dimensions captured. const struct gk_geometry *gk_geom; // Geometry struct - bool divide_jacobgeo; // Boolean for if we are dividing out the configuration-space Jacobian from density + bool + divide_jacobgeo; // Boolean for if we are dividing out the configuration-space Jacobian from density double mass; // Species mass - - struct gkyl_array *M0; - struct gkyl_array *M1; + + struct gkyl_array *M0; + struct gkyl_array *M1; struct gkyl_array *u_par; - struct gkyl_array *u_par_dot_M1; + struct gkyl_array *u_par_dot_M1; struct gkyl_array *pressure; struct gkyl_array *temperature; struct gkyl_array *p_par; @@ -29,7 +29,7 @@ struct gkyl_gk_maxwellian_moments struct gkyl_array *t_perp; struct gkyl_dg_bin_op_mem *mem; - struct gkyl_dg_updater_moment *M0_calc; + struct gkyl_dg_updater_moment *M0_calc; struct gkyl_dg_updater_moment *M1_calc; struct gkyl_dg_updater_moment *M2_calc; struct gkyl_dg_updater_moment *M2_par_calc; diff --git a/gyrokinetic/zero/gkyl_gk_maxwellian_proj_on_basis.h b/gyrokinetic/zero/gkyl_gk_maxwellian_proj_on_basis.h index f4a72a0321..f2b89c8814 100644 --- a/gyrokinetic/zero/gkyl_gk_maxwellian_proj_on_basis.h +++ b/gyrokinetic/zero/gkyl_gk_maxwellian_proj_on_basis.h @@ -16,7 +16,8 @@ struct gkyl_gk_maxwellian_proj_on_basis_inp { const struct gkyl_basis *conf_basis; // Configuration-space basis functions const struct gkyl_basis *phase_basis; // Phase-space basis functions const struct gkyl_range *conf_range; // Configuration-space range - const struct gkyl_range *conf_range_ext; // Extended configuration-space range (for internal memory allocations) + const struct gkyl_range + *conf_range_ext; // Extended configuration-space range (for internal memory allocations) const struct gkyl_range *vel_range; // Velocity space range const struct gk_geometry *gk_geom; // Geometry object. const struct gkyl_velocity_map *vel_map; // Velocity space mapping object. @@ -35,7 +36,7 @@ struct gkyl_gk_maxwellian_proj_on_basis_inp { * @param inp Input parameters defined in gkyl_gk_maxwellian_proj_on_basis_inp struct. * @return New updater pointer. */ -struct gkyl_gk_maxwellian_proj_on_basis* +struct gkyl_gk_maxwellian_proj_on_basis * gkyl_gk_maxwellian_proj_on_basis_inew(const struct gkyl_gk_maxwellian_proj_on_basis_inp *inp); /** @@ -53,29 +54,32 @@ gkyl_gk_maxwellian_proj_on_basis_inew(const struct gkyl_gk_maxwellian_proj_on_ba * the velocity-space Jacobian in the exponential weighting. * @param f_maxwellian Output Maxwellian (or bi-Maxwellian) distribution function */ -void gkyl_gk_maxwellian_proj_on_basis_advance(gkyl_gk_maxwellian_proj_on_basis *up, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *moms_maxwellian, bool use_jacobtot, - struct gkyl_array *f_maxwellian); +void gkyl_gk_maxwellian_proj_on_basis_advance( + gkyl_gk_maxwellian_proj_on_basis *up, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *moms_maxwellian, bool use_jacobtot, + struct gkyl_array *f_maxwellian +); /** * Host-side wrapper for geometry variables (bmag and jacobtot) at quadrature points */ -void gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars_cu(gkyl_gk_maxwellian_proj_on_basis *up, - const struct gkyl_range *conf_range, - const struct gkyl_array *bmag, const struct gkyl_array *jacobtot); +void gkyl_gk_maxwellian_proj_on_basis_geom_quad_vars_cu( + gkyl_gk_maxwellian_proj_on_basis *up, const struct gkyl_range *conf_range, + const struct gkyl_array *bmag, const struct gkyl_array *jacobtot +); /** * Host-side wrapper for projection of Maxwellian distribution function on device */ -void gkyl_gk_maxwellian_proj_on_basis_advance_cu(gkyl_gk_maxwellian_proj_on_basis *up, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *moms_maxwellian, bool use_jacobtot, - struct gkyl_array *f_maxwellian); +void gkyl_gk_maxwellian_proj_on_basis_advance_cu( + gkyl_gk_maxwellian_proj_on_basis *up, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *moms_maxwellian, bool use_jacobtot, + struct gkyl_array *f_maxwellian +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_gk_maxwellian_proj_on_basis_release(gkyl_gk_maxwellian_proj_on_basis* up); +void gkyl_gk_maxwellian_proj_on_basis_release(gkyl_gk_maxwellian_proj_on_basis *up); diff --git a/gyrokinetic/zero/gkyl_gk_maxwellian_proj_on_basis_priv.h b/gyrokinetic/zero/gkyl_gk_maxwellian_proj_on_basis_priv.h index f3220ca156..65fa744e77 100644 --- a/gyrokinetic/zero/gkyl_gk_maxwellian_proj_on_basis_priv.h +++ b/gyrokinetic/zero/gkyl_gk_maxwellian_proj_on_basis_priv.h @@ -10,26 +10,28 @@ #include #include #include -#include +#include #include #include -GKYL_CU_DH -static inline void -comp_to_phys(int ndim, const double *eta, - const double * GKYL_RESTRICT dx, const double * GKYL_RESTRICT xc, - double* GKYL_RESTRICT xout) +GKYL_CU_DH static inline void comp_to_phys( + int ndim, const double *eta, const double *GKYL_RESTRICT dx, const double *GKYL_RESTRICT xc, + double *GKYL_RESTRICT xout +) { - for (int d=0; d #include -typedef void (*gk_nf_udrift_set_prob_t)(int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, - const double *moms); +typedef void (*gk_nf_udrift_set_prob_t)( + int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, const double *moms +); -typedef void (*gk_nf_udrift_get_sol_t)(int count, struct gkyl_nmat *xsol, - double* GKYL_RESTRICT out); +typedef void (*gk_nf_udrift_get_sol_t)(int count, struct gkyl_nmat *xsol, double *GKYL_RESTRICT out); -typedef void (*gk_nf_pressure_t)(double gas_gamma, const double *moms, const double *u, - double* GKYL_RESTRICT out); +typedef void (*gk_nf_pressure_t)( + double gas_gamma, const double *moms, const double *u, double *GKYL_RESTRICT out +); -typedef void (*gk_nf_temp_set_prob_t)(int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, - const double *moms, double gas_gamma, double mass); +typedef void (*gk_nf_temp_set_prob_t)( + int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, const double *moms, double gas_gamma, + double mass +); -typedef void (*gk_nf_temp_get_sol_t)(int count, struct gkyl_nmat *xsol, - double* GKYL_RESTRICT out); +typedef void (*gk_nf_temp_get_sol_t)(int count, struct gkyl_nmat *xsol, double *GKYL_RESTRICT out); -typedef void (*gk_nf_udrift_temp_set_prob_t)(int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, - const double *moms, double gas_gamma, double mass); +typedef void (*gk_nf_udrift_temp_set_prob_t)( + int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, const double *moms, double gas_gamma, + double mass +); -typedef void (*gk_nf_udrift_temp_get_sol_t)(int count, struct gkyl_nmat *xsol, - double* GKYL_RESTRICT out); +typedef void (*gk_nf_udrift_temp_get_sol_t)( + int count, struct gkyl_nmat *xsol, double *GKYL_RESTRICT out +); -typedef void (*gk_nf_flowE_set_prob_t)(int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, - const double *moms); +typedef void (*gk_nf_flowE_set_prob_t)( + int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, const double *moms +); -typedef void (*gk_nf_flowE_get_sol_t)(int count, struct gkyl_nmat *xsol, - double* GKYL_RESTRICT out); +typedef void (*gk_nf_flowE_get_sol_t)(int count, struct gkyl_nmat *xsol, double *GKYL_RESTRICT out); // For use in kernel tables. -typedef struct { gk_nf_udrift_set_prob_t kernels[4]; } gkyl_gk_nf_prim_vars_udrift_set_prob_kern_list; -typedef struct { gk_nf_udrift_get_sol_t kernels[4]; } gkyl_gk_nf_prim_vars_udrift_get_sol_kern_list; -typedef struct { gk_nf_pressure_t kernels[4]; } gkyl_gk_nf_prim_vars_pressure_kern_list; -typedef struct { gk_nf_temp_set_prob_t kernels[4]; } gkyl_gk_nf_prim_vars_temp_set_prob_kern_list; -typedef struct { gk_nf_temp_get_sol_t kernels[4]; } gkyl_gk_nf_prim_vars_temp_get_sol_kern_list; -typedef struct { gk_nf_udrift_temp_set_prob_t kernels[4]; } gkyl_gk_nf_prim_vars_udrift_temp_set_prob_kern_list; -typedef struct { gk_nf_udrift_temp_get_sol_t kernels[4]; } gkyl_gk_nf_prim_vars_udrift_temp_get_sol_kern_list; -typedef struct { gk_nf_flowE_set_prob_t kernels[4]; } gkyl_gk_nf_prim_vars_flowE_set_prob_kern_list; -typedef struct { gk_nf_flowE_get_sol_t kernels[4]; } gkyl_gk_nf_prim_vars_flowE_get_sol_kern_list; +typedef struct { + gk_nf_udrift_set_prob_t kernels[4]; +} gkyl_gk_nf_prim_vars_udrift_set_prob_kern_list; +typedef struct { + gk_nf_udrift_get_sol_t kernels[4]; +} gkyl_gk_nf_prim_vars_udrift_get_sol_kern_list; +typedef struct { + gk_nf_pressure_t kernels[4]; +} gkyl_gk_nf_prim_vars_pressure_kern_list; +typedef struct { + gk_nf_temp_set_prob_t kernels[4]; +} gkyl_gk_nf_prim_vars_temp_set_prob_kern_list; +typedef struct { + gk_nf_temp_get_sol_t kernels[4]; +} gkyl_gk_nf_prim_vars_temp_get_sol_kern_list; +typedef struct { + gk_nf_udrift_temp_set_prob_t kernels[4]; +} gkyl_gk_nf_prim_vars_udrift_temp_set_prob_kern_list; +typedef struct { + gk_nf_udrift_temp_get_sol_t kernels[4]; +} gkyl_gk_nf_prim_vars_udrift_temp_get_sol_kern_list; +typedef struct { + gk_nf_flowE_set_prob_t kernels[4]; +} gkyl_gk_nf_prim_vars_flowE_set_prob_kern_list; +typedef struct { + gk_nf_flowE_get_sol_t kernels[4]; +} gkyl_gk_nf_prim_vars_flowE_get_sol_kern_list; struct gkyl_gk_neut_fluid_prim_vars { double gas_gamma; // Adiabatic index. @@ -72,7 +95,8 @@ struct gkyl_gk_neut_fluid_prim_vars { gk_nf_pressure_t pressure_ker; // Kernel for computing pressure. gk_nf_temp_set_prob_t temp_set_prob_ker; // Kernel for setting matrices for linear solve. gk_nf_temp_get_sol_t temp_get_sol_ker; // Kernel for copying solution to output. - gk_nf_udrift_temp_set_prob_t udrift_temp_set_prob_ker; // Kernel for setting matrices for linear solve. + gk_nf_udrift_temp_set_prob_t + udrift_temp_set_prob_ker; // Kernel for setting matrices for linear solve. gk_nf_udrift_temp_get_sol_t udrift_temp_get_sol_ker; // Kernel for copying solution to output. gk_nf_flowE_set_prob_t flowE_set_prob_ker; // Kernel for setting matrices for linear solve. gk_nf_flowE_get_sol_t flowE_get_sol_ker; // Kernel for copying solution to output. @@ -81,213 +105,214 @@ struct gkyl_gk_neut_fluid_prim_vars { struct gkyl_gk_neut_fluid_prim_vars *on_dev; // Pointer to itself or device data. // Method chosen at runtime. - void (*advance_func)(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff); + void (*advance_func)( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff + ); }; // Set matrices for computing fluid flow velocity (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_nf_prim_vars_udrift_set_prob_kern_list ser_gk_nf_prim_vars_udrift_set_prob_kernels[] = { - { gk_neut_fluid_prim_vars_udrift_set_prob_1x_ser_p1, gk_neut_fluid_prim_vars_udrift_set_prob_1x_ser_p2, NULL }, - { gk_neut_fluid_prim_vars_udrift_set_prob_2x_ser_p1, NULL, NULL }, - { gk_neut_fluid_prim_vars_udrift_set_prob_3x_ser_p1, NULL, NULL }, +GKYL_CU_D static const gkyl_gk_nf_prim_vars_udrift_set_prob_kern_list + ser_gk_nf_prim_vars_udrift_set_prob_kernels[] = { + {gk_neut_fluid_prim_vars_udrift_set_prob_1x_ser_p1, + gk_neut_fluid_prim_vars_udrift_set_prob_1x_ser_p2, NULL}, + {gk_neut_fluid_prim_vars_udrift_set_prob_2x_ser_p1, NULL, NULL}, + {gk_neut_fluid_prim_vars_udrift_set_prob_3x_ser_p1, NULL, NULL} }; // Copy solution for fluid flow velocity (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_nf_prim_vars_udrift_get_sol_kern_list ser_gk_nf_prim_vars_udrift_get_sol_kernels[] = { - { gk_neut_fluid_prim_vars_udrift_get_sol_1x_ser_p1, gk_neut_fluid_prim_vars_udrift_get_sol_1x_ser_p2, NULL }, - { gk_neut_fluid_prim_vars_udrift_get_sol_2x_ser_p1, NULL, NULL }, - { gk_neut_fluid_prim_vars_udrift_get_sol_3x_ser_p1, NULL, NULL }, +GKYL_CU_D static const gkyl_gk_nf_prim_vars_udrift_get_sol_kern_list + ser_gk_nf_prim_vars_udrift_get_sol_kernels[] = { + {gk_neut_fluid_prim_vars_udrift_get_sol_1x_ser_p1, + gk_neut_fluid_prim_vars_udrift_get_sol_1x_ser_p2, NULL}, + {gk_neut_fluid_prim_vars_udrift_get_sol_2x_ser_p1, NULL, NULL}, + {gk_neut_fluid_prim_vars_udrift_get_sol_3x_ser_p1, NULL, NULL} }; // Scalar pressure p = (gas_gamma - 1)*(E - 1/2 rho u^2) (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_nf_prim_vars_pressure_kern_list ser_gk_nf_prim_vars_pressure_kernels[] = { - { gk_neut_fluid_prim_vars_pressure_1x_ser_p1, gk_neut_fluid_prim_vars_pressure_1x_ser_p2, NULL }, - { gk_neut_fluid_prim_vars_pressure_2x_ser_p1, NULL, NULL }, - { gk_neut_fluid_prim_vars_pressure_3x_ser_p1, NULL, NULL }, +GKYL_CU_D static const gkyl_gk_nf_prim_vars_pressure_kern_list + ser_gk_nf_prim_vars_pressure_kernels[] = { + {gk_neut_fluid_prim_vars_pressure_1x_ser_p1, gk_neut_fluid_prim_vars_pressure_1x_ser_p2, NULL}, + {gk_neut_fluid_prim_vars_pressure_2x_ser_p1, NULL, NULL}, + {gk_neut_fluid_prim_vars_pressure_3x_ser_p1, NULL, NULL} }; // Set matrices for computing temperature (Serendipity kernels). -GKYL_CU_D -static const gkyl_gk_nf_prim_vars_temp_set_prob_kern_list ser_gk_nf_prim_vars_temp_set_prob_kernels[] = { - { gk_neut_fluid_prim_vars_temp_set_prob_1x_ser_p1, gk_neut_fluid_prim_vars_temp_set_prob_1x_ser_p2, NULL }, - { gk_neut_fluid_prim_vars_temp_set_prob_2x_ser_p1, NULL, NULL }, - { gk_neut_fluid_prim_vars_temp_set_prob_3x_ser_p1, NULL, NULL }, +GKYL_CU_D static const gkyl_gk_nf_prim_vars_temp_set_prob_kern_list + ser_gk_nf_prim_vars_temp_set_prob_kernels[] = { + {gk_neut_fluid_prim_vars_temp_set_prob_1x_ser_p1, + gk_neut_fluid_prim_vars_temp_set_prob_1x_ser_p2, NULL}, + {gk_neut_fluid_prim_vars_temp_set_prob_2x_ser_p1, NULL, NULL}, + {gk_neut_fluid_prim_vars_temp_set_prob_3x_ser_p1, NULL, NULL} }; // Copy solution for temperature. (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_nf_prim_vars_temp_get_sol_kern_list ser_gk_nf_prim_vars_temp_get_sol_kernels[] = { - { gk_neut_fluid_prim_vars_temp_get_sol_1x_ser_p1, gk_neut_fluid_prim_vars_temp_get_sol_1x_ser_p2, NULL }, - { gk_neut_fluid_prim_vars_temp_get_sol_2x_ser_p1, NULL, NULL }, - { gk_neut_fluid_prim_vars_temp_get_sol_3x_ser_p1, NULL, NULL }, +GKYL_CU_D static const gkyl_gk_nf_prim_vars_temp_get_sol_kern_list + ser_gk_nf_prim_vars_temp_get_sol_kernels[] = { + {gk_neut_fluid_prim_vars_temp_get_sol_1x_ser_p1, gk_neut_fluid_prim_vars_temp_get_sol_1x_ser_p2, + NULL}, + {gk_neut_fluid_prim_vars_temp_get_sol_2x_ser_p1, NULL, NULL}, + {gk_neut_fluid_prim_vars_temp_get_sol_3x_ser_p1, NULL, NULL} }; // Set matrices for computing temperature (Serendipity kernels). -GKYL_CU_D -static const gkyl_gk_nf_prim_vars_udrift_temp_set_prob_kern_list ser_gk_nf_prim_vars_udrift_temp_set_prob_kernels[] = { - { gk_neut_fluid_prim_vars_udrift_temp_set_prob_1x_ser_p1, gk_neut_fluid_prim_vars_udrift_temp_set_prob_1x_ser_p2, NULL }, - { gk_neut_fluid_prim_vars_udrift_temp_set_prob_2x_ser_p1, NULL, NULL }, - { gk_neut_fluid_prim_vars_udrift_temp_set_prob_3x_ser_p1, NULL, NULL }, +GKYL_CU_D static const gkyl_gk_nf_prim_vars_udrift_temp_set_prob_kern_list + ser_gk_nf_prim_vars_udrift_temp_set_prob_kernels[] = { + {gk_neut_fluid_prim_vars_udrift_temp_set_prob_1x_ser_p1, + gk_neut_fluid_prim_vars_udrift_temp_set_prob_1x_ser_p2, NULL}, + {gk_neut_fluid_prim_vars_udrift_temp_set_prob_2x_ser_p1, NULL, NULL}, + {gk_neut_fluid_prim_vars_udrift_temp_set_prob_3x_ser_p1, NULL, NULL} }; // Copy solution for temperature. (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_nf_prim_vars_udrift_temp_get_sol_kern_list ser_gk_nf_prim_vars_udrift_temp_get_sol_kernels[] = { - { gk_neut_fluid_prim_vars_udrift_temp_get_sol_1x_ser_p1, gk_neut_fluid_prim_vars_udrift_temp_get_sol_1x_ser_p2, NULL }, - { gk_neut_fluid_prim_vars_udrift_temp_get_sol_2x_ser_p1, NULL, NULL }, - { gk_neut_fluid_prim_vars_udrift_temp_get_sol_3x_ser_p1, NULL, NULL }, +GKYL_CU_D static const gkyl_gk_nf_prim_vars_udrift_temp_get_sol_kern_list + ser_gk_nf_prim_vars_udrift_temp_get_sol_kernels[] = { + {gk_neut_fluid_prim_vars_udrift_temp_get_sol_1x_ser_p1, + gk_neut_fluid_prim_vars_udrift_temp_get_sol_1x_ser_p2, NULL}, + {gk_neut_fluid_prim_vars_udrift_temp_get_sol_2x_ser_p1, NULL, NULL}, + {gk_neut_fluid_prim_vars_udrift_temp_get_sol_3x_ser_p1, NULL, NULL} }; // Set matrices for computing fluid flow energy (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_nf_prim_vars_flowE_set_prob_kern_list ser_gk_nf_prim_vars_flowE_set_prob_kernels[] = { - { gk_neut_fluid_prim_vars_flowE_set_prob_1x_ser_p1, gk_neut_fluid_prim_vars_flowE_set_prob_1x_ser_p2, NULL }, - { gk_neut_fluid_prim_vars_flowE_set_prob_2x_ser_p1, NULL, NULL }, - { gk_neut_fluid_prim_vars_flowE_set_prob_3x_ser_p1, NULL, NULL }, +GKYL_CU_D static const gkyl_gk_nf_prim_vars_flowE_set_prob_kern_list + ser_gk_nf_prim_vars_flowE_set_prob_kernels[] = { + {gk_neut_fluid_prim_vars_flowE_set_prob_1x_ser_p1, + gk_neut_fluid_prim_vars_flowE_set_prob_1x_ser_p2, NULL}, + {gk_neut_fluid_prim_vars_flowE_set_prob_2x_ser_p1, NULL, NULL}, + {gk_neut_fluid_prim_vars_flowE_set_prob_3x_ser_p1, NULL, NULL} }; // Copy solution for fluid flow energy (Serendipity kernels) -GKYL_CU_D -static const gkyl_gk_nf_prim_vars_flowE_get_sol_kern_list ser_gk_nf_prim_vars_flowE_get_sol_kernels[] = { - { gk_neut_fluid_prim_vars_flowE_get_sol_1x_ser_p1, gk_neut_fluid_prim_vars_flowE_get_sol_1x_ser_p2, NULL }, - { gk_neut_fluid_prim_vars_flowE_get_sol_2x_ser_p1, NULL, NULL }, - { gk_neut_fluid_prim_vars_flowE_get_sol_3x_ser_p1, NULL, NULL }, +GKYL_CU_D static const gkyl_gk_nf_prim_vars_flowE_get_sol_kern_list + ser_gk_nf_prim_vars_flowE_get_sol_kernels[] = { + {gk_neut_fluid_prim_vars_flowE_get_sol_1x_ser_p1, + gk_neut_fluid_prim_vars_flowE_get_sol_1x_ser_p2, NULL}, + {gk_neut_fluid_prim_vars_flowE_get_sol_2x_ser_p1, NULL, NULL}, + {gk_neut_fluid_prim_vars_flowE_get_sol_3x_ser_p1, NULL, NULL} }; -GKYL_CU_D -static gk_nf_udrift_set_prob_t +GKYL_CU_D static gk_nf_udrift_set_prob_t choose_udrift_set_prob_ker(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_gk_nf_prim_vars_udrift_set_prob_kernels[cdim-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_gk_nf_prim_vars_udrift_set_prob_kernels[cdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static gk_nf_udrift_get_sol_t +GKYL_CU_D static gk_nf_udrift_get_sol_t choose_udrift_get_sol_ker(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_gk_nf_prim_vars_udrift_get_sol_kernels[cdim-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_gk_nf_prim_vars_udrift_get_sol_kernels[cdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static gk_nf_pressure_t +GKYL_CU_D static gk_nf_pressure_t choose_pressure_ker(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_gk_nf_prim_vars_pressure_kernels[cdim-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_gk_nf_prim_vars_pressure_kernels[cdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static gk_nf_temp_set_prob_t +GKYL_CU_D static gk_nf_temp_set_prob_t choose_temp_set_prob_ker(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_gk_nf_prim_vars_temp_set_prob_kernels[cdim-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_gk_nf_prim_vars_temp_set_prob_kernels[cdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static gk_nf_temp_get_sol_t +GKYL_CU_D static gk_nf_temp_get_sol_t choose_temp_get_sol_ker(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_gk_nf_prim_vars_temp_get_sol_kernels[cdim-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_gk_nf_prim_vars_temp_get_sol_kernels[cdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static gk_nf_udrift_temp_set_prob_t +GKYL_CU_D static gk_nf_udrift_temp_set_prob_t choose_udrift_temp_set_prob_ker(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_gk_nf_prim_vars_udrift_temp_set_prob_kernels[cdim-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_gk_nf_prim_vars_udrift_temp_set_prob_kernels[cdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static gk_nf_udrift_temp_get_sol_t +GKYL_CU_D static gk_nf_udrift_temp_get_sol_t choose_udrift_temp_get_sol_ker(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_gk_nf_prim_vars_udrift_temp_get_sol_kernels[cdim-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_gk_nf_prim_vars_udrift_temp_get_sol_kernels[cdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static gk_nf_flowE_set_prob_t +GKYL_CU_D static gk_nf_flowE_set_prob_t choose_flowE_set_prob_ker(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_gk_nf_prim_vars_flowE_set_prob_kernels[cdim-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_gk_nf_prim_vars_flowE_set_prob_kernels[cdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static gk_nf_flowE_get_sol_t +GKYL_CU_D static gk_nf_flowE_get_sol_t choose_flowE_get_sol_ker(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_gk_nf_prim_vars_flowE_get_sol_kernels[cdim-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_gk_nf_prim_vars_flowE_get_sol_kernels[cdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } return 0; } @@ -314,10 +339,11 @@ choose_flowE_get_sol_ker(enum gkyl_basis_type b_type, int cdim, int poly_order) * @param use_gpu Whether to run on the GPU. * @return New updater pointer. */ -struct gkyl_gk_neut_fluid_prim_vars* -gkyl_gk_neut_fluid_prim_vars_cu_dev_new(double gas_gamma, double mass, const struct gkyl_basis* cbasis, - struct gkyl_rect_grid *grid, const struct gkyl_range *mem_range, - enum gkyl_gk_neut_fluid_prim_vars_type prim_vars_type, bool is_integrated); +struct gkyl_gk_neut_fluid_prim_vars *gkyl_gk_neut_fluid_prim_vars_cu_dev_new( + double gas_gamma, double mass, const struct gkyl_basis *cbasis, struct gkyl_rect_grid *grid, + const struct gkyl_range *mem_range, enum gkyl_gk_neut_fluid_prim_vars_type prim_vars_type, + bool is_integrated +); /** * Compute the drift velocity vector (ux, uy, uz) on NVIDIA GPU. @@ -327,8 +353,10 @@ gkyl_gk_neut_fluid_prim_vars_cu_dev_new(double gas_gamma, double mass, const str * @param out Output drift velocity. * @param out_coff Offset in out where to place drift velocity. */ -void gkyl_gk_neut_fluid_prim_vars_udrift_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff); +void gkyl_gk_neut_fluid_prim_vars_udrift_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +); /** * Compute the pressure p = (gas_gamma - 1)*(E - 1/2 rho u^2) on NVIDIA GPU. @@ -337,8 +365,10 @@ void gkyl_gk_neut_fluid_prim_vars_udrift_advance_cu(struct gkyl_gk_neut_fluid_pr * @param out Output pressure. * @param out_coff Offset in out where to place pressure. */ -void gkyl_gk_neut_fluid_prim_vars_pressure_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff); +void gkyl_gk_neut_fluid_prim_vars_pressure_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +); /** * Compute the temperature T = p/n = (gas_gamma - 1)*(mass * E - 1/2 (rho u)^2)/rho @@ -349,8 +379,10 @@ void gkyl_gk_neut_fluid_prim_vars_pressure_advance_cu(struct gkyl_gk_neut_fluid_ * @param out Output temperature. * @param out_coff Offset in out where to place temperature. */ -void gkyl_gk_neut_fluid_prim_vars_temp_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff); +void gkyl_gk_neut_fluid_prim_vars_temp_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +); /** * Compute the thermal energy p/(gas_gamma - 1) = E - 1/2 rho u^2 on NVIDIA GPU. @@ -359,8 +391,10 @@ void gkyl_gk_neut_fluid_prim_vars_temp_advance_cu(struct gkyl_gk_neut_fluid_prim * @param out Output thermal energy. * @param out_coff Offset in out where to place thermal energy. */ -void gkyl_gk_neut_fluid_prim_vars_thermal_energy_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff); +void gkyl_gk_neut_fluid_prim_vars_thermal_energy_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +); /** * Compute the drift velocity vector (ux, uy, uz) @@ -371,8 +405,10 @@ void gkyl_gk_neut_fluid_prim_vars_thermal_energy_advance_cu(struct gkyl_gk_neut_ * @param out Output primitive moments. * @param out_coff Offset in out where to place primitive moments. */ -void gkyl_gk_neut_fluid_prim_vars_udrift_pressure_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff); +void gkyl_gk_neut_fluid_prim_vars_udrift_pressure_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +); /** * Compute the drift velocity vector (ux, uy, uz) @@ -384,8 +420,10 @@ void gkyl_gk_neut_fluid_prim_vars_udrift_pressure_advance_cu(struct gkyl_gk_neut * @param out Output primitive moments. * @param out_coff Offset in out where to place primitive moments. */ -void gkyl_gk_neut_fluid_prim_vars_udrift_temp_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff); +void gkyl_gk_neut_fluid_prim_vars_udrift_temp_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +); /** * Compute the LTE moments: density, drift velocity vector (ux, uy, uz) @@ -397,8 +435,10 @@ void gkyl_gk_neut_fluid_prim_vars_udrift_temp_advance_cu(struct gkyl_gk_neut_flu * @param out Output primitive moments. * @param out_coff Offset in out where to place primitive moments. */ -void gkyl_gk_neut_fluid_prim_vars_lte_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff); +void gkyl_gk_neut_fluid_prim_vars_lte_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +); /** * Compute the moments flow energy 0.5 rho u^2 on NVIDIA GPU. @@ -407,8 +447,10 @@ void gkyl_gk_neut_fluid_prim_vars_lte_advance_cu(struct gkyl_gk_neut_fluid_prim_ * @param out Output thermal energy. * @param out_coff Offset in out where to place thermal energy. */ -void gkyl_gk_neut_fluid_prim_vars_flow_energy_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff); +void gkyl_gk_neut_fluid_prim_vars_flow_energy_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +); /** * Compute the moments: @@ -424,6 +466,8 @@ void gkyl_gk_neut_fluid_prim_vars_flow_energy_advance_cu(struct gkyl_gk_neut_flu * @param out Output thermal energy. * @param out_coff Offset in out where to place thermal energy. */ -void gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_advance_cu(struct gkyl_gk_neut_fluid_prim_vars *up, - const struct gkyl_array* moms, struct gkyl_array *out, int out_coff); +void gkyl_gk_neut_fluid_prim_vars_mass_momentum_flow_thermal_energy_advance_cu( + struct gkyl_gk_neut_fluid_prim_vars *up, const struct gkyl_array *moms, struct gkyl_array *out, + int out_coff +); #endif diff --git a/gyrokinetic/zero/gkyl_gkgeom.h b/gyrokinetic/zero/gkyl_gkgeom.h index 684b838baf..54320d91eb 100644 --- a/gyrokinetic/zero/gkyl_gkgeom.h +++ b/gyrokinetic/zero/gkyl_gkgeom.h @@ -11,11 +11,11 @@ enum gkyl_gkgeom_type { GKYL_GEOM_SOL_SN, // SOL of single-null configuration GKYL_GEOM_PF, // Private flux region GKYL_GEOM_CORE // Core (closed flux-surface) -}; +}; // Inputs to create a new GK geometry creation object struct gkyl_gkgeom_inp { - // psiRZ and related inputs + // psiRZ and related inputs const struct gkyl_rect_grid *rzgrid; // RZ grid on which psi(R,Z) is defined const struct gkyl_basis *rzbasis; // basis functions for R,Z grid const struct gkyl_array *psiRZ; // psi(R,Z) DG representation @@ -29,7 +29,7 @@ struct gkyl_gkgeom_inp { // Parameters for nmumerical quadrature: leave unset to use default struct { - int max_levels; // typically 6-7 + int max_levels; // typically 6-7 double eps; // typically 1e-10 } quad_param; }; @@ -40,7 +40,7 @@ struct gkyl_gkgeom_geo_inp { const struct gkyl_basis *cbasis; enum gkyl_gkgeom_type ftype; // type of geometry - + double rclose; // closest R to discrimate double zmin, zmax; // extents of Z for integration @@ -52,7 +52,7 @@ struct gkyl_gkgeom_geo_inp { struct gkyl_gkgeom_stat { long nquad_cont_calls; // num calls from quadrature long nroot_cont_calls; // num calls from root-finder -}; +}; /** * Create new updater to compute the geometry (mapc2p) needed in GK @@ -75,8 +75,9 @@ gkyl_gkgeom *gkyl_gkgeom_new(const struct gkyl_gkgeom_inp *inp); * @param R on output, R(psi,Z) * @param dR on output, dR/dZ */ -int gkyl_gkgeom_R_psiZ(const gkyl_gkgeom *geo, double psi, double Z, int nmaxroots, - double *R, double *dR); +int gkyl_gkgeom_R_psiZ( + const gkyl_gkgeom *geo, double psi, double Z, int nmaxroots, double *R, double *dR +); /** * Integrate along a specified psi countour and return its length. The @@ -94,8 +95,9 @@ int gkyl_gkgeom_R_psiZ(const gkyl_gkgeom *geo, double psi, double Z, int nmaxroo * contours * @return Length of contour */ -double gkyl_gkgeom_integrate_psi_contour(const gkyl_gkgeom *geo, double psi, - double zmin, double zmax, double rclose); +double gkyl_gkgeom_integrate_psi_contour( + const gkyl_gkgeom *geo, double psi, double zmin, double zmax, double rclose +); /** * Compute geometry (mapc2p) on a specified computational grid. The @@ -105,8 +107,9 @@ double gkyl_gkgeom_integrate_psi_contour(const gkyl_gkgeom *geo, double psi, * @param ginp Input structure for creating mapc2p * @param mapc2p On output, the DG representation of mapc2p */ -void gkyl_gkgeom_calcgeom(const gkyl_gkgeom *geo, - const struct gkyl_gkgeom_geo_inp *ginp, struct gkyl_array *mapc2p); +void gkyl_gkgeom_calcgeom( + const gkyl_gkgeom *geo, const struct gkyl_gkgeom_geo_inp *ginp, struct gkyl_array *mapc2p +); /** * Return cumulative statistics from geometry computations diff --git a/gyrokinetic/zero/gkyl_gyrokinetic_cross_prim_moms_bgk.h b/gyrokinetic/zero/gkyl_gyrokinetic_cross_prim_moms_bgk.h index d236225c72..d76843e286 100644 --- a/gyrokinetic/zero/gkyl_gyrokinetic_cross_prim_moms_bgk.h +++ b/gyrokinetic/zero/gkyl_gyrokinetic_cross_prim_moms_bgk.h @@ -4,7 +4,7 @@ #include #include -// Type for storing preallocated memory +// Type for storing preallocated memory typedef struct gkyl_gyrokinetic_cross_prim_moms_bgk gkyl_gyrokinetic_cross_prim_moms_bgk; /** @@ -14,8 +14,9 @@ typedef struct gkyl_gyrokinetic_cross_prim_moms_bgk gkyl_gyrokinetic_cross_prim_ * @param conf_basis Configuration space basis functions. * @param use_gpu Boolian to determine if on GPU. */ -gkyl_gyrokinetic_cross_prim_moms_bgk* gkyl_gyrokinetic_cross_prim_moms_bgk_new( - const struct gkyl_basis *phase_basis, const struct gkyl_basis *conf_basis, bool use_gpu); +gkyl_gyrokinetic_cross_prim_moms_bgk *gkyl_gyrokinetic_cross_prim_moms_bgk_new( + const struct gkyl_basis *phase_basis, const struct gkyl_basis *conf_basis, bool use_gpu +); /** * Compute the cross moments with moments of each species. @@ -30,10 +31,11 @@ gkyl_gyrokinetic_cross_prim_moms_bgk* gkyl_gyrokinetic_cross_prim_moms_bgk_new( * @param moms_other Moments of the other species. * @param moms_cross Six output moments. */ -void gkyl_gyrokinetic_cross_prim_moms_bgk_advance( gkyl_gyrokinetic_cross_prim_moms_bgk *up, - const struct gkyl_range *conf_rng, double delta_sr, double betap1, - double m_self, const struct gkyl_array *prim_moms_self, double m_other, const struct gkyl_array *prim_moms_other, - struct gkyl_array *prim_moms_cross); +void gkyl_gyrokinetic_cross_prim_moms_bgk_advance( + gkyl_gyrokinetic_cross_prim_moms_bgk *up, const struct gkyl_range *conf_rng, double delta_sr, + double betap1, double m_self, const struct gkyl_array *prim_moms_self, double m_other, + const struct gkyl_array *prim_moms_other, struct gkyl_array *prim_moms_cross +); /** * Release memory needed in the cross moments calculation. @@ -41,4 +43,3 @@ void gkyl_gyrokinetic_cross_prim_moms_bgk_advance( gkyl_gyrokinetic_cross_prim_m * @param up Memory to release. */ void gkyl_gyrokinetic_cross_prim_moms_bgk_release(gkyl_gyrokinetic_cross_prim_moms_bgk *up); - diff --git a/gyrokinetic/zero/gkyl_gyrokinetic_cross_prim_moms_bgk_priv.h b/gyrokinetic/zero/gkyl_gyrokinetic_cross_prim_moms_bgk_priv.h index 3ec1900a90..ff38805524 100644 --- a/gyrokinetic/zero/gkyl_gyrokinetic_cross_prim_moms_bgk_priv.h +++ b/gyrokinetic/zero/gkyl_gyrokinetic_cross_prim_moms_bgk_priv.h @@ -12,47 +12,54 @@ #include // Function pointer type for cross moments calculation -typedef void (*gyrokinetic_cross_prim_moms_bgk_t)(const double delta_sr, const double betap1, - const double m_self, const double *prim_moms_self, const double m_other, const double *prim_moms_other, - double *prim_moms_cross); +typedef void (*gyrokinetic_cross_prim_moms_bgk_t)( + const double delta_sr, const double betap1, const double m_self, const double *prim_moms_self, + const double m_other, const double *prim_moms_other, double *prim_moms_cross +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below. -GKYL_CU_D -static struct { int vdim[3]; } cv_index[] = { +GKYL_CU_D static struct { + int vdim[3]; +} cv_index[] = { {-1, -1, -1}, // 0x makes no sense - {-1, 0, 1}, // 1x kernel indices - {-1, -1, 2}, // 2x kernel indices - {-1, -1, 3}, // 3x kernel indices + {-1, 0, 1}, // 1x kernel indices + {-1, -1, 2}, // 2x kernel indices + {-1, -1, 3} // 3x kernel indices }; // For use in kernel tables -typedef struct { gyrokinetic_cross_prim_moms_bgk_t kernels[3]; } gkyl_gyrokinetic_cross_prim_moms_bgk_kern_list; +typedef struct { + gyrokinetic_cross_prim_moms_bgk_t kernels[3]; +} gkyl_gyrokinetic_cross_prim_moms_bgk_kern_list; // Cross moments kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_cross_prim_moms_bgk_kern_list ser_gyrokinetic_cross_prim_moms_bgk_list[] = { - // 1x kernels - { NULL, gyrokinetic_cross_prim_moms_bgk_1x1v_ser_p1, NULL }, //0 - { NULL, gyrokinetic_cross_prim_moms_bgk_1x2v_ser_p1, NULL }, //1 - // 2x kernels - { NULL, gyrokinetic_cross_prim_moms_bgk_2x2v_ser_p1, NULL }, // no gyrokinetic_cross_prim_moms_bgk_2x2v_ser_p2 due to the lack of gkyl_basis_ser_2x_p2_inv.h //2 - // 3x kernels - { NULL, gyrokinetic_cross_prim_moms_bgk_3x2v_ser_p1, NULL }, // no gyrokinetic_cross_prim_moms_bgk_2x2v_ser_p2 due to the lack of gkyl_basis_ser_3x_p2_inv.h //3 +GKYL_CU_D static const gkyl_gyrokinetic_cross_prim_moms_bgk_kern_list + ser_gyrokinetic_cross_prim_moms_bgk_list[] = { + // 1x kernels + {NULL, gyrokinetic_cross_prim_moms_bgk_1x1v_ser_p1, NULL}, //0 + {NULL, gyrokinetic_cross_prim_moms_bgk_1x2v_ser_p1, NULL}, //1 + // 2x kernels + {NULL, gyrokinetic_cross_prim_moms_bgk_2x2v_ser_p1, NULL + }, // no gyrokinetic_cross_prim_moms_bgk_2x2v_ser_p2 due to the lack of gkyl_basis_ser_2x_p2_inv.h //2 + // 3x kernels + {NULL, gyrokinetic_cross_prim_moms_bgk_3x2v_ser_p1, NULL + } // no gyrokinetic_cross_prim_moms_bgk_2x2v_ser_p2 due to the lack of gkyl_basis_ser_3x_p2_inv.h //3 }; -GKYL_CU_D -static gyrokinetic_cross_prim_moms_bgk_t -choose_gyrokinetic_cross_prim_moms_bgk_kern(int cdim, int vdim, int poly_order){ +GKYL_CU_D static gyrokinetic_cross_prim_moms_bgk_t +choose_gyrokinetic_cross_prim_moms_bgk_kern(int cdim, int vdim, int poly_order) +{ return ser_gyrokinetic_cross_prim_moms_bgk_list[cv_index[cdim].vdim[vdim]].kernels[poly_order]; } // Primary struct in this updater struct gkyl_gyrokinetic_cross_prim_moms_bgk { bool use_gpu; - gyrokinetic_cross_prim_moms_bgk_t cross_prim_moms_calc; // a pointer to the cross primitive moments kernel + gyrokinetic_cross_prim_moms_bgk_t + cross_prim_moms_calc; // a pointer to the cross primitive moments kernel - struct gkyl_gyrokinetic_cross_prim_moms_bgk *on_dev; + struct gkyl_gyrokinetic_cross_prim_moms_bgk *on_dev; }; #ifdef GKYL_HAVE_CUDA @@ -60,14 +67,16 @@ struct gkyl_gyrokinetic_cross_prim_moms_bgk { * Create new updater to compute cross BGK moments on * NV-GPU. See new() method for documentation. */ -gkyl_gyrokinetic_cross_prim_moms_bgk* gkyl_gyrokinetic_cross_prim_moms_bgk_cu_dev_new( - const struct gkyl_basis *phase_basis, const struct gkyl_basis *conf_basis); +gkyl_gyrokinetic_cross_prim_moms_bgk *gkyl_gyrokinetic_cross_prim_moms_bgk_cu_dev_new( + const struct gkyl_basis *phase_basis, const struct gkyl_basis *conf_basis +); /** * Host-side wrappers for cross BGK moments operations on device */ -void gkyl_gyrokinetic_cross_prim_moms_bgk_advance_cu(gkyl_gyrokinetic_cross_prim_moms_bgk *up, - const struct gkyl_range *conf_rng, double delta_sr, double betap1, - double m_self, const struct gkyl_array *prim_moms_self, double m_other, const struct gkyl_array *prim_moms_other, - struct gkyl_array *prim_moms_cross); +void gkyl_gyrokinetic_cross_prim_moms_bgk_advance_cu( + gkyl_gyrokinetic_cross_prim_moms_bgk *up, const struct gkyl_range *conf_rng, double delta_sr, + double betap1, double m_self, const struct gkyl_array *prim_moms_self, double m_other, + const struct gkyl_array *prim_moms_other, struct gkyl_array *prim_moms_cross +); #endif diff --git a/gyrokinetic/zero/gkyl_gyrokinetic_pol_density.h b/gyrokinetic/zero/gkyl_gyrokinetic_pol_density.h index 2ca632651d..ac3b560567 100644 --- a/gyrokinetic/zero/gkyl_gyrokinetic_pol_density.h +++ b/gyrokinetic/zero/gkyl_gyrokinetic_pol_density.h @@ -22,9 +22,9 @@ typedef struct gkyl_gyrokinetic_pol_density gkyl_gyrokinetic_pol_density; * @param use_gpu bool to determine if on GPU. * @return New polarization density updater pointer. */ -struct gkyl_gyrokinetic_pol_density* -gkyl_gyrokinetic_pol_density_new(struct gkyl_basis cbasis, struct gkyl_rect_grid cgrid, - bool use_gpu); +struct gkyl_gyrokinetic_pol_density *gkyl_gyrokinetic_pol_density_new( + struct gkyl_basis cbasis, struct gkyl_rect_grid cgrid, bool use_gpu +); /** * Run the polarization density updater in the indicated range. @@ -35,15 +35,15 @@ gkyl_gyrokinetic_pol_density_new(struct gkyl_basis cbasis, struct gkyl_rect_grid * @param phi Electrostatic potential (represented with a p+1 tensor basis). * @param npol Polarization density. */ -void -gkyl_gyrokinetic_pol_density_advance(gkyl_gyrokinetic_pol_density* up, - const struct gkyl_range *conf_rng, const struct gkyl_array *GKYL_RESTRICT pol_weight, - const struct gkyl_array *GKYL_RESTRICT phi, struct gkyl_array *GKYL_RESTRICT npol); +void gkyl_gyrokinetic_pol_density_advance( + gkyl_gyrokinetic_pol_density *up, const struct gkyl_range *conf_rng, + const struct gkyl_array *GKYL_RESTRICT pol_weight, const struct gkyl_array *GKYL_RESTRICT phi, + struct gkyl_array *GKYL_RESTRICT npol +); /** * Release the memory associated with this polarization density updater. * * @param up Positivity shift updater. */ -void -gkyl_gyrokinetic_pol_density_release(gkyl_gyrokinetic_pol_density* up); +void gkyl_gyrokinetic_pol_density_release(gkyl_gyrokinetic_pol_density *up); diff --git a/gyrokinetic/zero/gkyl_gyrokinetic_pol_density_priv.h b/gyrokinetic/zero/gkyl_gyrokinetic_pol_density_priv.h index 9ceca88532..b6711bab2c 100644 --- a/gyrokinetic/zero/gkyl_gyrokinetic_pol_density_priv.h +++ b/gyrokinetic/zero/gkyl_gyrokinetic_pol_density_priv.h @@ -8,26 +8,26 @@ #include // Function pointer type for sheath reflection kernels. -typedef void (*gkpolden_t)(const double *dx, - const double *epsilon, const double *phi, double *out); +typedef void (*gkpolden_t)(const double *dx, const double *epsilon, const double *phi, double *out); -typedef struct { gkpolden_t kernels[3]; } gk_pol_den_kern_list; // For use in kernel tables. +typedef struct { + gkpolden_t kernels[3]; +} gk_pol_den_kern_list; // For use in kernel tables. // Serendipity kernels. -GKYL_CU_D -static const gk_pol_den_kern_list gk_pol_density_kern_list_ser[] = { - { gkyl_gyrokinetic_pol_density_1x_ser_p1, NULL, NULL }, - { gkyl_gyrokinetic_pol_density_2x_ser_p1, NULL, NULL }, - { gkyl_gyrokinetic_pol_density_3x_ser_p1, NULL, NULL }, +GKYL_CU_D static const gk_pol_den_kern_list gk_pol_density_kern_list_ser[] = { + {gkyl_gyrokinetic_pol_density_1x_ser_p1, NULL, NULL}, + {gkyl_gyrokinetic_pol_density_2x_ser_p1, NULL, NULL}, + {gkyl_gyrokinetic_pol_density_3x_ser_p1, NULL, NULL} }; struct gkyl_gyrokinetic_pol_density_kernels { - gkpolden_t pol_den; // Kernel that computes the polarization density. + gkpolden_t pol_den; // Kernel that computes the polarization density. }; // Primary struct in this updater. struct gkyl_gyrokinetic_pol_density { - struct gkyl_rect_grid grid; // Phase-space grid. + struct gkyl_rect_grid grid; // Phase-space grid. bool use_gpu; struct gkyl_gyrokinetic_pol_density_kernels *kernels; }; @@ -35,17 +35,20 @@ struct gkyl_gyrokinetic_pol_density { #ifdef GKYL_HAVE_CUDA // Declaration of cuda device functions. -void gk_pol_den_choose_kernel_cu(struct gkyl_gyrokinetic_pol_density_kernels *kernels, - struct gkyl_basis cbasis); +void gk_pol_den_choose_kernel_cu( + struct gkyl_gyrokinetic_pol_density_kernels *kernels, struct gkyl_basis cbasis +); -void gkyl_gyrokinetic_pol_density_advance_cu(gkyl_gyrokinetic_pol_density* up, - const struct gkyl_range *conf_rng, const struct gkyl_array *GKYL_RESTRICT pol_weight, - const struct gkyl_array *GKYL_RESTRICT phi, struct gkyl_array *GKYL_RESTRICT npol); +void gkyl_gyrokinetic_pol_density_advance_cu( + gkyl_gyrokinetic_pol_density *up, const struct gkyl_range *conf_rng, + const struct gkyl_array *GKYL_RESTRICT pol_weight, const struct gkyl_array *GKYL_RESTRICT phi, + struct gkyl_array *GKYL_RESTRICT npol +); #endif -GKYL_CU_D -static void gk_pol_den_choose_kernel(struct gkyl_gyrokinetic_pol_density_kernels *kernels, - struct gkyl_basis cbasis, bool use_gpu) +GKYL_CU_D static void gk_pol_den_choose_kernel( + struct gkyl_gyrokinetic_pol_density_kernels *kernels, struct gkyl_basis cbasis, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { @@ -59,11 +62,11 @@ static void gk_pol_den_choose_kernel(struct gkyl_gyrokinetic_pol_density_kernels int poly_order = cbasis.poly_order; switch (basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - kernels->pol_den = gk_pol_density_kern_list_ser[cdim-1].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + kernels->pol_den = gk_pol_density_kern_list_ser[cdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } } diff --git a/gyrokinetic/zero/gkyl_loss_cone_mask_gyrokinetic.h b/gyrokinetic/zero/gkyl_loss_cone_mask_gyrokinetic.h index 36e12300c3..5df707ac46 100644 --- a/gyrokinetic/zero/gkyl_loss_cone_mask_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_loss_cone_mask_gyrokinetic.h @@ -24,7 +24,8 @@ struct gkyl_loss_cone_mask_gyrokinetic_inp { const struct gkyl_basis *conf_basis; // Configuration-space basis functions. const struct gkyl_basis *phase_basis; // Phase-space basis functions. const struct gkyl_range *conf_range; // Configuration-space range. - const struct gkyl_range *conf_range_ext; // Extended configuration-space range (for internal memory allocations). + const struct gkyl_range + *conf_range_ext; // Extended configuration-space range (for internal memory allocations). const struct gkyl_range *vel_range; // Velocity space range. const struct gkyl_velocity_map *vel_map; // Velocity space mapping object. const struct gkyl_array *bmag; // Magnetic field magnitude. @@ -35,9 +36,9 @@ struct gkyl_loss_cone_mask_gyrokinetic_inp { enum gkyl_quad_type qtype; // Quadrature rule/nodes. int num_quad; // Number of quad points in each direction to use (default: poly_order+1). bool cellwise_trap_loss; // =True takes a whole cell to be either trapped or passing, - // so not high-order distinction within the cell is made. + // so not high-order distinction within the cell is made. loss_cone_mask_gyrokinetic_c2p_t c2p_pos_func; // Function that transforms a set of cdim - // position-space computational coordinates to physical ones. + // position-space computational coordinates to physical ones. void *c2p_pos_func_ctx; // Context for c2p_pos_func. bool use_gpu; // Whether to run on GPU. }; @@ -54,7 +55,7 @@ struct gkyl_loss_cone_mask_gyrokinetic_inp { * @param inp Input parameters defined in gkyl_loss_cone_mask_gyrokinetic_inp struct. * @return New updater pointer. */ -struct gkyl_loss_cone_mask_gyrokinetic* +struct gkyl_loss_cone_mask_gyrokinetic * gkyl_loss_cone_mask_gyrokinetic_inew(const struct gkyl_loss_cone_mask_gyrokinetic_inp *inp); /** @@ -67,13 +68,15 @@ gkyl_loss_cone_mask_gyrokinetic_inew(const struct gkyl_loss_cone_mask_gyrokineti * @param phi_m Electrostatic potential at the mirror throat (on GPU if use_gpu=true). * @param mask_out Output masking function. */ -void gkyl_loss_cone_mask_gyrokinetic_advance(gkyl_loss_cone_mask_gyrokinetic *up, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *phi, const double *phi_m, struct gkyl_array *mask_out); +void gkyl_loss_cone_mask_gyrokinetic_advance( + gkyl_loss_cone_mask_gyrokinetic *up, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *phi, const double *phi_m, + struct gkyl_array *mask_out +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_loss_cone_mask_gyrokinetic_release(gkyl_loss_cone_mask_gyrokinetic* up); +void gkyl_loss_cone_mask_gyrokinetic_release(gkyl_loss_cone_mask_gyrokinetic *up); diff --git a/gyrokinetic/zero/gkyl_loss_cone_mask_gyrokinetic_priv.h b/gyrokinetic/zero/gkyl_loss_cone_mask_gyrokinetic_priv.h index 03e57dec97..a2207f2806 100644 --- a/gyrokinetic/zero/gkyl_loss_cone_mask_gyrokinetic_priv.h +++ b/gyrokinetic/zero/gkyl_loss_cone_mask_gyrokinetic_priv.h @@ -8,26 +8,28 @@ #include #include #include -#include +#include #include #include -GKYL_CU_DH -static inline void -log_to_comp(int ndim, const double *eta, - const double * GKYL_RESTRICT dx, const double * GKYL_RESTRICT xc, - double* GKYL_RESTRICT xout) +GKYL_CU_DH static inline void log_to_comp( + int ndim, const double *eta, const double *GKYL_RESTRICT dx, const double *GKYL_RESTRICT xc, + double *GKYL_RESTRICT xout +) { - for (int d=0; d #include -typedef void (*lbo_gyrokinetic_momf_t)(const int *idx, enum gkyl_vel_edge edge, const double *vBoundary, - const double *dxv, const double *vmap_prime, double _m, const double *fIn, double* GKYL_RESTRICT out); +typedef void (*lbo_gyrokinetic_momf_t)( + const int *idx, enum gkyl_vel_edge edge, const double *vBoundary, const double *dxv, + const double *vmap_prime, double _m, const double *fIn, double *GKYL_RESTRICT out +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -static struct { int vdim[3]; } cv_index[] = { +static struct { + int vdim[3]; +} cv_index[] = { {-1, -1, -1}, // 0x makes no sense - {-1, 0, 1}, // 1x kernel indices - {-1, -1, 2}, // 2x kernel indices - {-1, -1, 3}, // 3x kernel indices + {-1, 0, 1}, // 1x kernel indices + {-1, -1, 2}, // 2x kernel indices + {-1, -1, 3} // 3x kernel indices }; // for use in kernel tables -typedef struct { lbo_gyrokinetic_momf_t kernels[3]; } gkyl_mom_bcorr_lbo_gyrokinetic_kern_list; +typedef struct { + lbo_gyrokinetic_momf_t kernels[3]; +} gkyl_mom_bcorr_lbo_gyrokinetic_kern_list; // // Serendipity basis kernels // // boundary integral moment correction kernel lists (both momentum and energy) -GKYL_CU_D -static const gkyl_mom_bcorr_lbo_gyrokinetic_kern_list ser_mom_bcorr_lbo_gyrokinetic_kernels[] = { - // 1x kernels - { NULL, mom_bcorr_lbo_gyrokinetic_1x1v_ser_p1, NULL }, // 0 - { NULL, mom_bcorr_lbo_gyrokinetic_1x2v_ser_p1, NULL }, // 1 - // 2x kernels - { NULL, mom_bcorr_lbo_gyrokinetic_2x2v_ser_p1, NULL }, // 2 - // 3x kernels - { NULL, mom_bcorr_lbo_gyrokinetic_3x2v_ser_p1, NULL }, // 3 +GKYL_CU_D static const gkyl_mom_bcorr_lbo_gyrokinetic_kern_list + ser_mom_bcorr_lbo_gyrokinetic_kernels[] = { + // 1x kernels + {NULL, mom_bcorr_lbo_gyrokinetic_1x1v_ser_p1, NULL}, // 0 + {NULL, mom_bcorr_lbo_gyrokinetic_1x2v_ser_p1, NULL}, // 1 + // 2x kernels + {NULL, mom_bcorr_lbo_gyrokinetic_2x2v_ser_p1, NULL}, // 2 + // 3x kernels + {NULL, mom_bcorr_lbo_gyrokinetic_3x2v_ser_p1, NULL} // 3 }; // @@ -63,21 +69,27 @@ struct mom_type_bcorr_lbo_gyrokinetic { void gk_mom_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static void -kernel(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_D static void kernel( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - struct mom_type_bcorr_lbo_gyrokinetic *mom_bcorr = container_of(momt, struct mom_type_bcorr_lbo_gyrokinetic, momt); + struct mom_type_bcorr_lbo_gyrokinetic *mom_bcorr = + container_of(momt, struct mom_type_bcorr_lbo_gyrokinetic, momt); enum gkyl_vel_edge edge = *(enum gkyl_vel_edge *)param; int vidx[2]; - for (int d=momt->cdim; dpdim; d++) vidx[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + vidx[d - momt->cdim] = idx[d]; + } long vlinidx = gkyl_range_idx(&mom_bcorr->vel_map->local_vel, vidx); - - return mom_bcorr->kernel(idx, edge, mom_bcorr->vel_map->vbounds, dx, - (const double *) gkyl_array_cfetch(mom_bcorr->vel_map->vmap_prime, vlinidx), mom_bcorr->_m, f, out); + + return mom_bcorr->kernel( + idx, edge, mom_bcorr->vel_map->vbounds, dx, + (const double *)gkyl_array_cfetch(mom_bcorr->vel_map->vmap_prime, vlinidx), mom_bcorr->_m, f, + out + ); } #ifdef GKYL_HAVE_CUDA @@ -86,8 +98,9 @@ kernel(const struct gkyl_mom_type *momt, const double *xc, const double *dx, * Create new LBO Gyrokinetic boundary correction moment type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, double mass, const struct gkyl_velocity_map *vel_map); +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_gyrokinetic_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, double mass, + const struct gkyl_velocity_map *vel_map +); #endif diff --git a/gyrokinetic/zero/gkyl_mom_gyrokinetic.h b/gyrokinetic/zero/gkyl_mom_gyrokinetic.h index 7bd772c173..0d71b1e38b 100644 --- a/gyrokinetic/zero/gkyl_mom_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_mom_gyrokinetic.h @@ -23,11 +23,12 @@ * @param mom_type Name of moment to compute. * @param use_gpu bool to determine if on GPU. */ -struct gkyl_mom_type* -gkyl_mom_gyrokinetic_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - double mass, double charge, const struct gkyl_velocity_map *vel_map, - const struct gk_geometry *gk_geom, struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool use_gpu); +struct gkyl_mom_type *gkyl_mom_gyrokinetic_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, double mass, double charge, + const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, + struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool use_gpu +); /** * Create new integrated gyrokinetic moment type object. @@ -43,8 +44,9 @@ gkyl_mom_gyrokinetic_new(const struct gkyl_basis* cbasis, * @param mom_type Name of moment to compute. * @param use_gpu bool to determine if on GPU. */ -struct gkyl_mom_type* -gkyl_int_mom_gyrokinetic_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - double mass, double charge, const struct gkyl_velocity_map* vel_map, - const struct gk_geometry *gk_geom, struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool use_gpu); +struct gkyl_mom_type *gkyl_int_mom_gyrokinetic_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, double mass, double charge, + const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, + struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool use_gpu +); diff --git a/gyrokinetic/zero/gkyl_mom_gyrokinetic_priv.h b/gyrokinetic/zero/gkyl_mom_gyrokinetic_priv.h index 38f7015355..3bcbafdb8e 100644 --- a/gyrokinetic/zero/gkyl_mom_gyrokinetic_priv.h +++ b/gyrokinetic/zero/gkyl_mom_gyrokinetic_priv.h @@ -11,7 +11,6 @@ #include #include - struct mom_type_gyrokinetic { struct gkyl_mom_type momt; double mass; // Mass of species. @@ -24,11 +23,13 @@ struct mom_type_gyrokinetic { // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -static struct { int vdim[3]; } cv_index[] = { +static struct { + int vdim[3]; +} cv_index[] = { {-1, -1, -1}, // 0x makes no sense - {-1, 0, 1}, // 1x kernel indices - {-1, -1, 2}, // 2x kernel indices - {-1, -1, 3}, // 3x kernel indices + {-1, 0, 1}, // 1x kernel indices + {-1, -1, 2}, // 2x kernel indices + {-1, -1, 3} // 3x kernel indices }; // for use in kernel tables @@ -36,2322 +37,2658 @@ typedef struct { momf_t kernels[3]; } gkyl_gyrokinetic_mom_kern_list; -GKYL_CU_DH -static void -kernel_gyrokinetic_M0_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M0_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M0_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M0_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M0_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M0_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M0_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M0_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M0_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M0_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M0_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M0_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M0_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M0_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M0_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M0_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M0_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M0_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M0_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M0_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M0_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M0_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M0_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M0_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M0_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M0_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M0_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M0_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M1_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M1_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M1_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M1_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M1_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M1_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M1_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M1_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M1_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M1_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M1_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M1_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M1_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M1_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M1_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M1_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M1_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M1_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M1_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M1_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M1_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M1_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M1_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M1_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M1_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M1_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M1_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M1_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_par_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_par_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_par_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_par_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_par_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_par_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_par_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_par_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_par_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_par_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_par_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_par_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_par_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_par_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_par_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_par_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_par_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_par_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_par_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_par_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_par_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_par_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_par_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_par_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_par_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_par_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_par_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_par_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_perp_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_perp_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_perp_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_perp_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_perp_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_perp_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_perp_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_perp_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_perp_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_perp_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_perp_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_perp_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_perp_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_perp_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_perp_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_perp_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M2_perp_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M2_perp_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M2_perp_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M2_perp_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_par_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_par_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_par_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_par_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_par_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_par_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_par_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_par_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_par_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_par_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_par_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_par_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_par_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_par_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_par_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_par_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_par_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_par_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_par_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_par_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_par_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_par_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_par_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_par_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_par_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_par_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_par_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_par_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_perp_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_perp_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_perp_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_perp_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_perp_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_perp_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_perp_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_perp_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_perp_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_perp_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_perp_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_perp_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_perp_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_perp_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_perp_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_perp_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_M3_perp_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_M3_perp_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_M3_perp_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_M3_perp_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_three_moments_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_three_moments_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_three_moments_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_three_moments_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_three_moments_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_three_moments_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_three_moments_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_three_moments_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_three_moments_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_three_moments_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_three_moments_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_three_moments_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_three_moments_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_three_moments_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_three_moments_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_three_moments_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_three_moments_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_three_moments_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_three_moments_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_three_moments_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_three_moments_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_three_moments_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_three_moments_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_three_moments_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_three_moments_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_three_moments_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_three_moments_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_three_moments_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_four_moments_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_four_moments_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_four_moments_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_four_moments_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_four_moments_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_four_moments_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_four_moments_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_four_moments_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_four_moments_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_four_moments_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_four_moments_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_four_moments_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_four_moments_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_four_moments_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_four_moments_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_four_moments_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_four_moments_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_four_moments_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_four_moments_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_four_moments_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_four_moments_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_four_moments_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_four_moments_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_four_moments_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_four_moments_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_four_moments_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_four_moments_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out); + return gyrokinetic_four_moments_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_hamiltonian_moments_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_hamiltonian_moments_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_hamiltonian_moments_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_hamiltonian_moments_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_hamiltonian_moments_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_hamiltonian_moments_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_hamiltonian_moments_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_hamiltonian_moments_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_hamiltonian_moments_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_hamiltonian_moments_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_hamiltonian_moments_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_hamiltonian_moments_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_hamiltonian_moments_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_hamiltonian_moments_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_hamiltonian_moments_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_hamiltonian_moments_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_hamiltonian_moments_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_hamiltonian_moments_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_hamiltonian_moments_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_hamiltonian_moments_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_hamiltonian_moments_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_hamiltonian_moments_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_hamiltonian_moments_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_hamiltonian_moments_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_hamiltonian_moments_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_hamiltonian_moments_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_hamiltonian_moments_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_hamiltonian_moments_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M0_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M0_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M0_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M0_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M0_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M0_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M0_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M0_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M0_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M0_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M0_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M0_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M0_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M0_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M0_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M0_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M0_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M0_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M0_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M0_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M0_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M0_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M0_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M0_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M0_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M0_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M0_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M0_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M1_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M1_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M1_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M1_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M1_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M1_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M1_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M1_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M1_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M1_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M1_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M1_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M1_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M1_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M1_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M1_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M1_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M1_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M1_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M1_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M1_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M1_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M1_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M1_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M1_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M1_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M1_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M1_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_par_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_par_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_par_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_par_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_par_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_par_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_par_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_par_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_par_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_par_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_par_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_par_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_par_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_par_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_par_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_par_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_par_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_par_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_par_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_par_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_par_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_par_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_par_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_par_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_par_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_par_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_par_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_par_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_perp_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_perp_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_perp_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_perp_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_perp_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_perp_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_perp_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_perp_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_perp_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_perp_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_perp_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_perp_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_perp_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_perp_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_perp_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_perp_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_perp_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_perp_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_perp_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_perp_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } - -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M2_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M2_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M2_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M2_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_par_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_par_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_par_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_par_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_par_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_par_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_par_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_par_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_par_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_par_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_par_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_par_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_par_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_par_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_par_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_par_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_par_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_par_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_par_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_par_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_par_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_par_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_par_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_par_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_par_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_par_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_par_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_par_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_perp_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_perp_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_perp_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_perp_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_perp_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_perp_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_perp_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_perp_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_perp_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_perp_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_perp_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_perp_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_perp_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_perp_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_perp_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_perp_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_M3_perp_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_M3_perp_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_M3_perp_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_M3_perp_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_three_moments_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_three_moments_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_three_moments_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_three_moments_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_three_moments_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_three_moments_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_three_moments_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_three_moments_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_three_moments_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_three_moments_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_three_moments_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_three_moments_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_three_moments_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_three_moments_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_three_moments_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_three_moments_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_three_moments_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_three_moments_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_three_moments_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_three_moments_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_three_moments_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_three_moments_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_three_moments_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_three_moments_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_three_moments_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_three_moments_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_three_moments_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_three_moments_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_four_moments_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_four_moments_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_four_moments_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_four_moments_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_four_moments_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_four_moments_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_four_moments_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_four_moments_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_four_moments_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_four_moments_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_four_moments_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_four_moments_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_four_moments_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_four_moments_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_four_moments_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_four_moments_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_four_moments_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_four_moments_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_four_moments_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_four_moments_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_four_moments_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_four_moments_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_four_moments_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_four_moments_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_four_moments_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_four_moments_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_four_moments_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - f, out); + return gyrokinetic_int_four_moments_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_hamiltonian_moments_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_hamiltonian_moments_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_hamiltonian_moments_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_int_hamiltonian_moments_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_hamiltonian_moments_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_hamiltonian_moments_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_hamiltonian_moments_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_int_hamiltonian_moments_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_hamiltonian_moments_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_hamiltonian_moments_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_hamiltonian_moments_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_int_hamiltonian_moments_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_hamiltonian_moments_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_hamiltonian_moments_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_hamiltonian_moments_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_int_hamiltonian_moments_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_hamiltonian_moments_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_hamiltonian_moments_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_hamiltonian_moments_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_int_hamiltonian_moments_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_hamiltonian_moments_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_hamiltonian_moments_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_hamiltonian_moments_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_int_hamiltonian_moments_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } -GKYL_CU_DH -static void -kernel_gyrokinetic_int_hamiltonian_moments_3x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_gyrokinetic_int_hamiltonian_moments_3x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_gyrokinetic *mom_gk = container_of(momt, struct mom_type_gyrokinetic, momt); int idx_vel[2]; - for (int d=momt->cdim; dpdim; d++) idx_vel[d-momt->cdim] = idx[d]; + for (int d = momt->cdim; d < momt->pdim; d++) { + idx_vel[d - momt->cdim] = idx[d]; + } long cidx = gkyl_range_idx(&mom_gk->conf_range, idx); long vidx = gkyl_range_idx(&mom_gk->vel_map->local_vel, idx_vel); - return gyrokinetic_int_hamiltonian_moments_3x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, mom_gk->charge, - (const double*) gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), - (const double*) gkyl_array_cfetch(mom_gk->phi, cidx), f, out); + return gyrokinetic_int_hamiltonian_moments_3x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_gk->vel_map->vmap, vidx), mom_gk->mass, + mom_gk->charge, (const double *)gkyl_array_cfetch(mom_gk->gk_geom->geo_corn.bmag, cidx), + (const double *)gkyl_array_cfetch(mom_gk->phi, cidx), f, out + ); } // @@ -2359,243 +2696,245 @@ kernel_gyrokinetic_int_hamiltonian_moments_3x2v_ser_p1(const struct gkyl_mom_typ // // M0 kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_m0_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_m0_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_M0_1x1v_ser_p1, kernel_gyrokinetic_M0_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_M0_1x2v_ser_p1, kernel_gyrokinetic_M0_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_M0_1x1v_ser_p1, kernel_gyrokinetic_M0_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_M0_1x2v_ser_p1, kernel_gyrokinetic_M0_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_M0_2x2v_ser_p1, kernel_gyrokinetic_M0_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_M0_2x2v_ser_p1, kernel_gyrokinetic_M0_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_M0_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_M0_3x2v_ser_p1, NULL} // 3 }; // M1 kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_m1_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_m1_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_M1_1x1v_ser_p1, kernel_gyrokinetic_M1_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_M1_1x2v_ser_p1, kernel_gyrokinetic_M1_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_M1_1x1v_ser_p1, kernel_gyrokinetic_M1_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_M1_1x2v_ser_p1, kernel_gyrokinetic_M1_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_M1_2x2v_ser_p1, kernel_gyrokinetic_M1_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_M1_2x2v_ser_p1, kernel_gyrokinetic_M1_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_M1_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_M1_3x2v_ser_p1, NULL} // 3 }; // M2 kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_m2_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_m2_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_M2_1x1v_ser_p1, kernel_gyrokinetic_M2_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_M2_1x2v_ser_p1, kernel_gyrokinetic_M2_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_M2_1x1v_ser_p1, kernel_gyrokinetic_M2_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_M2_1x2v_ser_p1, kernel_gyrokinetic_M2_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_M2_2x2v_ser_p1, kernel_gyrokinetic_M2_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_M2_2x2v_ser_p1, kernel_gyrokinetic_M2_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_M2_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_M2_3x2v_ser_p1, NULL} // 3 }; // M2 parallel kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_m2_par_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_m2_par_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_M2_par_1x1v_ser_p1, kernel_gyrokinetic_M2_par_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_M2_par_1x2v_ser_p1, kernel_gyrokinetic_M2_par_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_M2_par_1x1v_ser_p1, kernel_gyrokinetic_M2_par_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_M2_par_1x2v_ser_p1, kernel_gyrokinetic_M2_par_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_M2_par_2x2v_ser_p1, kernel_gyrokinetic_M2_par_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_M2_par_2x2v_ser_p1, kernel_gyrokinetic_M2_par_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_M2_par_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_M2_par_3x2v_ser_p1, NULL} // 3 }; // M2 perpendicular kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_m2_perp_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_m2_perp_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, kernel_gyrokinetic_M2_perp_1x2v_ser_p1, kernel_gyrokinetic_M2_perp_1x2v_ser_p2 }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, kernel_gyrokinetic_M2_perp_1x2v_ser_p1, kernel_gyrokinetic_M2_perp_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_M2_perp_2x2v_ser_p1, kernel_gyrokinetic_M2_perp_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_M2_perp_2x2v_ser_p1, kernel_gyrokinetic_M2_perp_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_M2_perp_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_M2_perp_3x2v_ser_p1, NULL} // 3 }; // M3 parallel kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_m3_par_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_m3_par_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_M3_par_1x1v_ser_p1, kernel_gyrokinetic_M3_par_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_M3_par_1x2v_ser_p1, kernel_gyrokinetic_M3_par_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_M3_par_1x1v_ser_p1, kernel_gyrokinetic_M3_par_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_M3_par_1x2v_ser_p1, kernel_gyrokinetic_M3_par_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_M3_par_2x2v_ser_p1, kernel_gyrokinetic_M3_par_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_M3_par_2x2v_ser_p1, kernel_gyrokinetic_M3_par_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_M3_par_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_M3_par_3x2v_ser_p1, NULL} // 3 }; // M3 perpendicular kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_m3_perp_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_m3_perp_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, kernel_gyrokinetic_M3_perp_1x2v_ser_p1, kernel_gyrokinetic_M3_perp_1x2v_ser_p2 }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, kernel_gyrokinetic_M3_perp_1x2v_ser_p1, kernel_gyrokinetic_M3_perp_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_M3_perp_2x2v_ser_p1, kernel_gyrokinetic_M3_perp_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_M3_perp_2x2v_ser_p1, kernel_gyrokinetic_M3_perp_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_M3_perp_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_M3_perp_3x2v_ser_p1, NULL} // 3 }; // Density), parallel momentum and kinetic energy computed together. -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_three_moments_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_three_moments_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_three_moments_1x1v_ser_p1, kernel_gyrokinetic_three_moments_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_three_moments_1x2v_ser_p1, kernel_gyrokinetic_three_moments_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_three_moments_1x1v_ser_p1, kernel_gyrokinetic_three_moments_1x1v_ser_p2 + }, // 0 + {NULL, kernel_gyrokinetic_three_moments_1x2v_ser_p1, kernel_gyrokinetic_three_moments_1x2v_ser_p2 + }, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_three_moments_2x2v_ser_p1, kernel_gyrokinetic_three_moments_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_three_moments_2x2v_ser_p1, kernel_gyrokinetic_three_moments_2x2v_ser_p2 + }, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_three_moments_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_three_moments_3x2v_ser_p1, NULL} // 3 }; // Density), parallel momentum, and parallel and perpendicular kinetic energy computed together. -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_four_moments_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_four_moments_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_four_moments_1x1v_ser_p1, kernel_gyrokinetic_four_moments_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_four_moments_1x2v_ser_p1, kernel_gyrokinetic_four_moments_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_four_moments_1x1v_ser_p1, kernel_gyrokinetic_four_moments_1x1v_ser_p2 + }, // 0 + {NULL, kernel_gyrokinetic_four_moments_1x2v_ser_p1, kernel_gyrokinetic_four_moments_1x2v_ser_p2 + }, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_four_moments_2x2v_ser_p1, kernel_gyrokinetic_four_moments_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_four_moments_2x2v_ser_p1, kernel_gyrokinetic_four_moments_2x2v_ser_p2 + }, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_four_moments_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_four_moments_3x2v_ser_p1, NULL} // 3 }; // Hamiltonian moment kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_hamiltonian_moments_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_hamiltonian_moments_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_hamiltonian_moments_1x1v_ser_p1, kernel_gyrokinetic_hamiltonian_moments_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_hamiltonian_moments_1x2v_ser_p1, kernel_gyrokinetic_hamiltonian_moments_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_hamiltonian_moments_1x1v_ser_p1, + kernel_gyrokinetic_hamiltonian_moments_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_hamiltonian_moments_1x2v_ser_p1, + kernel_gyrokinetic_hamiltonian_moments_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_hamiltonian_moments_2x2v_ser_p1, kernel_gyrokinetic_hamiltonian_moments_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_hamiltonian_moments_2x2v_ser_p1, + kernel_gyrokinetic_hamiltonian_moments_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_hamiltonian_moments_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_hamiltonian_moments_3x2v_ser_p1, NULL} // 3 }; // Integrated M0 kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_int_m0_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_int_m0_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_int_M0_1x1v_ser_p1, kernel_gyrokinetic_int_M0_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_int_M0_1x2v_ser_p1, kernel_gyrokinetic_int_M0_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_int_M0_1x1v_ser_p1, kernel_gyrokinetic_int_M0_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_int_M0_1x2v_ser_p1, kernel_gyrokinetic_int_M0_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_int_M0_2x2v_ser_p1, kernel_gyrokinetic_int_M0_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_int_M0_2x2v_ser_p1, kernel_gyrokinetic_int_M0_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_int_M0_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_int_M0_3x2v_ser_p1, NULL} // 3 }; // Integrated M1 kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_int_m1_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_int_m1_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_int_M1_1x1v_ser_p1, kernel_gyrokinetic_int_M1_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_int_M1_1x2v_ser_p1, kernel_gyrokinetic_int_M1_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_int_M1_1x1v_ser_p1, kernel_gyrokinetic_int_M1_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_int_M1_1x2v_ser_p1, kernel_gyrokinetic_int_M1_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_int_M1_2x2v_ser_p1, kernel_gyrokinetic_int_M1_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_int_M1_2x2v_ser_p1, kernel_gyrokinetic_int_M1_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_int_M1_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_int_M1_3x2v_ser_p1, NULL} // 3 }; // Integrated M2 parallel kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_int_m2_par_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_int_m2_par_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_int_M2_par_1x1v_ser_p1, kernel_gyrokinetic_int_M2_par_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_int_M2_par_1x2v_ser_p1, kernel_gyrokinetic_int_M2_par_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_int_M2_par_1x1v_ser_p1, kernel_gyrokinetic_int_M2_par_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_int_M2_par_1x2v_ser_p1, kernel_gyrokinetic_int_M2_par_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_int_M2_par_2x2v_ser_p1, kernel_gyrokinetic_int_M2_par_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_int_M2_par_2x2v_ser_p1, kernel_gyrokinetic_int_M2_par_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_int_M2_par_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_int_M2_par_3x2v_ser_p1, NULL} // 3 }; // Integrated M2 perpendicular kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_int_m2_perp_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_int_m2_perp_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, kernel_gyrokinetic_int_M2_perp_1x2v_ser_p1, kernel_gyrokinetic_int_M2_perp_1x2v_ser_p2 }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, kernel_gyrokinetic_int_M2_perp_1x2v_ser_p1, kernel_gyrokinetic_int_M2_perp_1x2v_ser_p2 + }, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_int_M2_perp_2x2v_ser_p1, kernel_gyrokinetic_int_M2_perp_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_int_M2_perp_2x2v_ser_p1, kernel_gyrokinetic_int_M2_perp_2x2v_ser_p2 + }, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_int_M2_perp_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_int_M2_perp_3x2v_ser_p1, NULL} // 3 }; // Integrated M2 kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_int_m2_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_int_m2_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_int_M2_1x1v_ser_p1, kernel_gyrokinetic_int_M2_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_int_M2_1x2v_ser_p1, kernel_gyrokinetic_int_M2_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_int_M2_1x1v_ser_p1, kernel_gyrokinetic_int_M2_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_int_M2_1x2v_ser_p1, kernel_gyrokinetic_int_M2_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_int_M2_2x2v_ser_p1, kernel_gyrokinetic_int_M2_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_int_M2_2x2v_ser_p1, kernel_gyrokinetic_int_M2_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_int_M2_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_int_M2_3x2v_ser_p1, NULL} // 3 }; // Integrated M3 parallel kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_int_m3_par_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_int_m3_par_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_int_M3_par_1x1v_ser_p1, kernel_gyrokinetic_int_M3_par_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_int_M3_par_1x2v_ser_p1, kernel_gyrokinetic_int_M3_par_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_int_M3_par_1x1v_ser_p1, kernel_gyrokinetic_int_M3_par_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_int_M3_par_1x2v_ser_p1, kernel_gyrokinetic_int_M3_par_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_int_M3_par_2x2v_ser_p1, kernel_gyrokinetic_int_M3_par_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_int_M3_par_2x2v_ser_p1, kernel_gyrokinetic_int_M3_par_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_int_M3_par_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_int_M3_par_3x2v_ser_p1, NULL} // 3 }; // Integrated M3 perpendicular kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_int_m3_perp_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_int_m3_perp_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, kernel_gyrokinetic_int_M3_perp_1x2v_ser_p1, kernel_gyrokinetic_int_M3_perp_1x2v_ser_p2 }, // 1 + {NULL, NULL, NULL}, // 0 + {NULL, kernel_gyrokinetic_int_M3_perp_1x2v_ser_p1, kernel_gyrokinetic_int_M3_perp_1x2v_ser_p2 + }, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_int_M3_perp_2x2v_ser_p1, kernel_gyrokinetic_int_M3_perp_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_int_M3_perp_2x2v_ser_p1, kernel_gyrokinetic_int_M3_perp_2x2v_ser_p2 + }, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_int_M3_perp_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_int_M3_perp_3x2v_ser_p1, NULL} // 3 }; // Integrated three_moments kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_int_three_moments_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_int_three_moments_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_int_three_moments_1x1v_ser_p1, kernel_gyrokinetic_int_three_moments_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_int_three_moments_1x2v_ser_p1, kernel_gyrokinetic_int_three_moments_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_int_three_moments_1x1v_ser_p1, + kernel_gyrokinetic_int_three_moments_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_int_three_moments_1x2v_ser_p1, + kernel_gyrokinetic_int_three_moments_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_int_three_moments_2x2v_ser_p1, kernel_gyrokinetic_int_three_moments_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_int_three_moments_2x2v_ser_p1, + kernel_gyrokinetic_int_three_moments_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_int_three_moments_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_int_three_moments_3x2v_ser_p1, NULL} // 3 }; // Integrated four_moments kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_int_four_moments_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_int_four_moments_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_int_four_moments_1x1v_ser_p1, kernel_gyrokinetic_int_four_moments_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_int_four_moments_1x2v_ser_p1, kernel_gyrokinetic_int_four_moments_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_int_four_moments_1x1v_ser_p1, + kernel_gyrokinetic_int_four_moments_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_int_four_moments_1x2v_ser_p1, + kernel_gyrokinetic_int_four_moments_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_int_four_moments_2x2v_ser_p1, kernel_gyrokinetic_int_four_moments_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_int_four_moments_2x2v_ser_p1, + kernel_gyrokinetic_int_four_moments_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_int_four_moments_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_int_four_moments_3x2v_ser_p1, NULL} // 3 }; // Integrated four_moments kernel list -GKYL_CU_D -static const gkyl_gyrokinetic_mom_kern_list ser_int_hamiltonian_moments_kernels[] = { +GKYL_CU_D static const gkyl_gyrokinetic_mom_kern_list ser_int_hamiltonian_moments_kernels[] = { // 1x kernels - { NULL, kernel_gyrokinetic_int_hamiltonian_moments_1x1v_ser_p1, kernel_gyrokinetic_int_hamiltonian_moments_1x1v_ser_p2 }, // 0 - { NULL, kernel_gyrokinetic_int_hamiltonian_moments_1x2v_ser_p1, kernel_gyrokinetic_int_hamiltonian_moments_1x2v_ser_p2 }, // 1 + {NULL, kernel_gyrokinetic_int_hamiltonian_moments_1x1v_ser_p1, + kernel_gyrokinetic_int_hamiltonian_moments_1x1v_ser_p2}, // 0 + {NULL, kernel_gyrokinetic_int_hamiltonian_moments_1x2v_ser_p1, + kernel_gyrokinetic_int_hamiltonian_moments_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, kernel_gyrokinetic_int_hamiltonian_moments_2x2v_ser_p1, kernel_gyrokinetic_int_hamiltonian_moments_2x2v_ser_p2 }, // 2 + {NULL, kernel_gyrokinetic_int_hamiltonian_moments_2x2v_ser_p1, + kernel_gyrokinetic_int_hamiltonian_moments_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, kernel_gyrokinetic_int_hamiltonian_moments_3x2v_ser_p1, NULL }, // 3 + {NULL, kernel_gyrokinetic_int_hamiltonian_moments_3x2v_ser_p1, NULL} // 3 }; /** @@ -2610,19 +2949,21 @@ void gkyl_gk_mom_free(const struct gkyl_ref_count *ref); * Create new gyrokinetic moment type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_mom_type* -gkyl_mom_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - double mass, double charge, const struct gkyl_velocity_map *vel_map, - const struct gk_geometry *gk_geom, struct gkyl_array *phi, enum gkyl_distribution_moments mom_type); +struct gkyl_mom_type *gkyl_mom_gyrokinetic_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, double mass, double charge, + const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, + struct gkyl_array *phi, enum gkyl_distribution_moments mom_type +); /** * Create new integrated Gyrokinetic moment type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_mom_type* -gkyl_int_mom_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - double mass, double charge, const struct gkyl_velocity_map *vel_map, - const struct gk_geometry *gk_geom, struct gkyl_array *phi, enum gkyl_distribution_moments mom_type); -#endif +struct gkyl_mom_type *gkyl_int_mom_gyrokinetic_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, double mass, double charge, + const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, + struct gkyl_array *phi, enum gkyl_distribution_moments mom_type +); +#endif diff --git a/gyrokinetic/zero/gkyl_position_map.h b/gyrokinetic/zero/gkyl_position_map.h index 8d88742e85..7eea52b70d 100644 --- a/gyrokinetic/zero/gkyl_position_map.h +++ b/gyrokinetic/zero/gkyl_position_map.h @@ -12,27 +12,35 @@ enum gkyl_position_map_id { GKYL_PMAP_USER_INPUT_W_DERIVATIVE, // Function projection and derivative user specified GKYL_PMAP_CONSTANT_DB_POLYNOMIAL, // Makes a uniform dB in each cell. Polynomial approximation, assuming 2 local maxima in Bmag GKYL_PMAP_CONSTANT_DB_NUMERIC, // Makes a uniform dB in each cell, but calculates the dB numerically - GKYL_PMAP_XPT_COMPRESSION, // Compresses cells near X-point (For use in MB Tokamaks) + GKYL_PMAP_XPT_COMPRESSION // Compresses cells near X-point (For use in MB Tokamaks) }; -typedef void (*mc2nu_t)(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx); +typedef void (*mc2nu_t)( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +); struct gkyl_position_map_inp { enum gkyl_position_map_id id; - mc2nu_t maps[3]; // Position mapping in each position direction. This is defined in full 3x, + mc2nu_t maps[3]; // Position mapping in each position direction. This is defined in full 3x, // not in deflated coordinates. - mc2nu_t map_derivs[3]; // Derivative of mapping in each position direction. This is defined in full 3x, + mc2nu_t + map_derivs[3]; // Derivative of mapping in each position direction. This is defined in full 3x, // not in deflated coordinates. void *ctxs[3]; // Context for each position mapping function. - double map_strength; // Zero is uniform mapping, one is fully nonuniform mapping. How strong the nonuniformity is + double + map_strength; // Zero is uniform mapping, one is fully nonuniform mapping. How strong the nonuniformity is // Call map_strength = s, xc computational coordinate, and xnu the nonuniform coordinate // xnu' = xnu * s + xc * (1-s) - double maximum_slope_at_min_B; // The maximum slope of the mapping at a magnetic field minimum. A number > 1. Hard limits on cell sizes - double maximum_slope_at_max_B; // The maximum slope of the mapping at a magnetic field maximum. A number > 1. Hard limits on cell sizes - double gaussian_std; // The width of the moving average for the map to smooth it. Units of normalized field line length - double gaussian_max_integration_width; // The maximum width to integrate the Gaussian filter. Units of normalized field line length + double + maximum_slope_at_min_B; // The maximum slope of the mapping at a magnetic field minimum. A number > 1. Hard limits on cell sizes + double + maximum_slope_at_max_B; // The maximum slope of the mapping at a magnetic field maximum. A number > 1. Hard limits on cell sizes + double + gaussian_std; // The width of the moving average for the map to smooth it. Units of normalized field line length + double + gaussian_max_integration_width; // The maximum width to integrate the Gaussian filter. Units of normalized field line length double compression_factor; // For PMAP_XPT_Compression. Specifies how much smaller the cells are - // near the X-point + // near the X-point double radial_compression_factor; // Factor by which cells are compressed radially near xpt bool compress_divertor; // Whether to apply compression at divertor plates for PMAP_XPT compression }; @@ -41,7 +49,7 @@ struct gkyl_position_map_inew_inp { struct gkyl_rect_grid grid; // Position space grid. struct gkyl_range local, local_ext; // Local & extended local position-space range. struct gkyl_range global, global_ext; // Global & extended global position-space range. - struct gkyl_basis basis; // Basis for position mapping. + struct gkyl_basis basis; // Basis for position mapping. }; struct gkyl_position_map { @@ -52,8 +60,9 @@ struct gkyl_position_map { double cdim; // Number of computational dimensions. struct gkyl_rect_grid grid; // Position space grid. - struct gkyl_range local, local_ext, global, global_ext; // Local & extended local position-space range. - struct gkyl_basis basis; // Basis for position mapping. + struct gkyl_range local, local_ext, global, + global_ext; // Local & extended local position-space range. + struct gkyl_basis basis; // Basis for position mapping. struct gkyl_array *mc2nu; // Position mapping in each position direction. struct gkyl_ref_count ref_count; bool to_optimize; // Whether to optimize the position map for constant B mapping. @@ -62,20 +71,24 @@ struct gkyl_position_map { // Stuff for constant B mapping struct gkyl_bmag_ctx *bmag_ctx; // Context for magnetic field calculation struct gkyl_position_map_const_B_ctx *constB_ctx; // Context for constant B mapping - struct gkyl_position_map_xpt_ctx *xpt_ctx; // Context for X-point compression mapping + struct gkyl_position_map_xpt_ctx *xpt_ctx; // Context for X-point compression mapping }; struct gkyl_position_map_const_B_ctx { mc2nu_t maps_backup[3]; // Backup of the position mapping functions. void *ctxs_backup[3]; // Backup of the context for each position mapping function. - - double psi, alpha; // The psi and alpha values for the middle flux surface to identify the 1D line we are optimizing + + double psi, + alpha; // The psi and alpha values for the middle flux surface to identify the 1D line we are optimizing double psi_min, psi_max; // The max and min psi values for the simulation double alpha_min, alpha_max; // The max and min alpha values for the simulation double theta_min, theta_max; // The max and min theta values for the simulation - double map_strength; // Zero is uniform mapping, one is fully nonuniform mapping. How strong the nonuniformity is - bool enable_maximum_slope_limits_at_min_B; // Whether to enable the maximum slope limits at a magnetic field minimum - bool enable_maximum_slope_limits_at_max_B; // Whether to enable the maximum slope limits at a magnetic field maximum + double + map_strength; // Zero is uniform mapping, one is fully nonuniform mapping. How strong the nonuniformity is + bool + enable_maximum_slope_limits_at_min_B; // Whether to enable the maximum slope limits at a magnetic field minimum + bool + enable_maximum_slope_limits_at_max_B; // Whether to enable the maximum slope limits at a magnetic field maximum double maximum_slope_at_min_B; // The maximum slope of the mapping at a magnetic field minimum double maximum_slope_at_max_B; // The maximum slope of the mapping at a magnetic field maximum double gaussian_std; // The standard deviation of the Gaussian filter used for smoothing the mapping @@ -98,7 +111,8 @@ struct gkyl_position_map_xpt_ctx { mc2nu_t maps_backup[3]; // Backup of the position mapping functions. void *ctxs_backup[3]; // Backup of the context for each position mapping function. double compression_factor; // Factor by which cells near X-point are compressed - double radial_compression_factor; // Factor by which cells are compressed in radial direction at separatrix + double + radial_compression_factor; // Factor by which cells are compressed in radial direction at separatrix bool compress_divertor; // Whether to apply compression at divertor plates double zcut; // Half-wavelength of sinusoidal mapping double zcenter; // Location of largest cells @@ -120,25 +134,24 @@ struct gkyl_position_map_xpt_ctx { * @param use_gpu Whether to create a device copy of this new object. * @return New position map object. */ -struct gkyl_position_map* gkyl_position_map_new(struct gkyl_position_map_inp pmap_info, - struct gkyl_rect_grid grid, struct gkyl_range local, struct gkyl_range local_ext, - struct gkyl_range global, struct gkyl_range global_ext, struct gkyl_basis basis); +struct gkyl_position_map *gkyl_position_map_new( + struct gkyl_position_map_inp pmap_info, struct gkyl_rect_grid grid, struct gkyl_range local, + struct gkyl_range local_ext, struct gkyl_range global, struct gkyl_range global_ext, + struct gkyl_basis basis +); /** * Create a new position map object using the input structure. * @param inp Input structure (see definition of gkyl_position_map_inew_inp). * @return New position map object. */ -struct gkyl_position_map* -gkyl_position_map_inew(struct gkyl_position_map_inew_inp inp); - +struct gkyl_position_map *gkyl_position_map_inew(struct gkyl_position_map_inew_inp inp); /** Create a new null position map object. This is a position map that does nothing. * All maps are identity maps. * @return New null position map object. */ -struct gkyl_position_map* -gkyl_position_map_null_new(); +struct gkyl_position_map *gkyl_position_map_null_new(); /** * Set the position map object. Copy the non-uniform map array to the position map object. @@ -148,7 +161,7 @@ gkyl_position_map_null_new(); * * @note This function is used to set the position map array in the position map object. */ -void gkyl_position_map_set_mc2nu(struct gkyl_position_map* gpm, struct gkyl_array* mc2nu); +void gkyl_position_map_set_mc2nu(struct gkyl_position_map *gpm, struct gkyl_array *mc2nu); /** * Set the magnetic field array in the position map object. This is used to set the magnetic field @@ -158,9 +171,9 @@ void gkyl_position_map_set_mc2nu(struct gkyl_position_map* gpm, struct gkyl_arra * @param comm Communicator object. * @param bmag Magnetic field array. */ -void -gkyl_position_map_set_bmag(struct gkyl_position_map* gpm, struct gkyl_comm* comm, - struct gkyl_array* bmag); +void gkyl_position_map_set_bmag( + struct gkyl_position_map *gpm, struct gkyl_comm *comm, struct gkyl_array *bmag +); /** * Set the function paramters for the map object. @@ -171,9 +184,9 @@ gkyl_position_map_set_bmag(struct gkyl_position_map* gpm, struct gkyl_comm* comm * @param w radial width of domain in psi * @param psisep separatrix psi value. */ -void -gkyl_position_map_set_compression(struct gkyl_position_map* gpm, double zcut, - double zcenter, double w, double psisep); +void gkyl_position_map_set_compression( + struct gkyl_position_map *gpm, double zcut, double zcenter, double w, double psisep +); /** * Evaluate the position mapping at a specific computational (position) coordinate. @@ -183,8 +196,9 @@ gkyl_position_map_set_compression(struct gkyl_position_map* gpm, double zcut, * @param xc Computational position coordinates. * @param xnu Resulting non-uniform position coordinates. */ -void -gkyl_position_map_eval_mc2nu(const struct gkyl_position_map* gpm, const double *xc, double *xnu); +void gkyl_position_map_eval_mc2nu( + const struct gkyl_position_map *gpm, const double *xc, double *xnu +); /** * Evaluate the slope of the position mapping at a specific computational (position) coordinate. @@ -197,9 +211,10 @@ gkyl_position_map_eval_mc2nu(const struct gkyl_position_map* gpm, const double * * @param nrange Range of the computational coordinates. * @return Slope of the position mapping. */ -double -gkyl_position_map_slope(const struct gkyl_position_map* gpm, int ix_map, - double x, double dx, int ix_comp, const struct gkyl_range *nrange); +double gkyl_position_map_slope( + const struct gkyl_position_map *gpm, int ix_map, double x, double dx, int ix_comp, + const struct gkyl_range *nrange +); /** * Create a new pointer to the position map object. @@ -207,7 +222,7 @@ gkyl_position_map_slope(const struct gkyl_position_map* gpm, int ix_map, * * @param gpm Position map object. */ -struct gkyl_position_map* gkyl_position_map_acquire(const struct gkyl_position_map* gpm); +struct gkyl_position_map *gkyl_position_map_acquire(const struct gkyl_position_map *gpm); /** * Optimize the position map object for constant B mapping. @@ -216,9 +231,9 @@ struct gkyl_position_map* gkyl_position_map_acquire(const struct gkyl_position_m * @param grid 3D Position space grid. * @param global 3D Global position range. */ -void gkyl_position_map_optimize(struct gkyl_position_map* gpm, struct gkyl_rect_grid grid, - struct gkyl_range global); - +void gkyl_position_map_optimize( + struct gkyl_position_map *gpm, struct gkyl_rect_grid grid, struct gkyl_range global +); /** * Release pointer to (and eventually memory associated with) diff --git a/gyrokinetic/zero/gkyl_position_map_priv.h b/gyrokinetic/zero/gkyl_position_map_priv.h index ab3b3ae3c5..5f8eadaecf 100644 --- a/gyrokinetic/zero/gkyl_position_map_priv.h +++ b/gyrokinetic/zero/gkyl_position_map_priv.h @@ -2,8 +2,7 @@ #include // Context for numeric root finding B mapping -struct opt_Theta_ctx -{ +struct opt_Theta_ctx { struct gkyl_position_map *gpm; struct gkyl_bmag_ctx *bmag_ctx; double dB_target; // How much B should change in 1 cell @@ -28,8 +27,9 @@ static void gkyl_position_map_free(const struct gkyl_ref_count *ref); * @param constB_ctx Context for the constant B mapping * @param bmag_ctx Context for the magnetic field calculation */ -static void -calculate_mirror_throat_location_polynomial(struct gkyl_position_map_const_B_ctx *constB_ctx, struct gkyl_bmag_ctx *bmag_ctx) +static void calculate_mirror_throat_location_polynomial( + struct gkyl_position_map_const_B_ctx *constB_ctx, struct gkyl_bmag_ctx *bmag_ctx +) { // Parameters to use for the midpoint rule root finding algorithm to find the throat of the mirror int itterations = 10; @@ -48,19 +48,16 @@ calculate_mirror_throat_location_polynomial(struct gkyl_position_map_const_B_ctx double maximum_Bmag = 0.0; double maximum_Bmag_location = 0.0; double fout[3]; - for (int j = 0; j < itterations; j++) - { + for (int j = 0; j < itterations; j++) { double dz = (interval_right - interval_left) / points_per_level; maximum_Bmag = 0.0; maximum_Bmag_location = 0.0; - for (int i = 0; i < points_per_level; i++) - { + for (int i = 0; i < points_per_level; i++) { double z = interval_left + i * dz; xp[Z_IDX] = z; gkyl_calc_bmag_global(0.0, xp, fout, bmag_ctx); double Bmag = fout[0]; - if (Bmag > maximum_Bmag) - { + if (Bmag > maximum_Bmag) { maximum_Bmag = Bmag; maximum_Bmag_location = z; } @@ -82,8 +79,7 @@ calculate_mirror_throat_location_polynomial(struct gkyl_position_map_const_B_ctx * @param fout Non-uniform coordinate * @param ctx position_map_constB_ctx context for the constant B mapping */ -static void -position_map_constB_z_polynomial(double t, const double *xn, double *fout, void *ctx) +static void position_map_constB_z_polynomial(double t, const double *xn, double *fout, void *ctx) { struct gkyl_position_map_const_B_ctx *app = ctx; int n_ex = app->map_order_expander; @@ -95,36 +91,28 @@ position_map_constB_z_polynomial(double t, const double *xn, double *fout, void double uniform_coordinate = xn[0]; double nonuniform_coordinate, left, right; int n; - if (uniform_coordinate >= z_min && uniform_coordinate <= z_max) - { - if (uniform_coordinate <= -z_m) - { + if (uniform_coordinate >= z_min && uniform_coordinate <= z_max) { + if (uniform_coordinate <= -z_m) { left = -z_m; right = z_min; n = n_ex; - } - else if (uniform_coordinate <= 0.0) - { + } else if (uniform_coordinate <= 0.0) { left = -z_m; right = 0.0; n = n_ct; - } - else if (uniform_coordinate <= z_m) - { + } else if (uniform_coordinate <= z_m) { left = z_m; right = 0.0; n = n_ct; - } - else - { + } else { left = z_m; right = z_max; n = n_ex; } - nonuniform_coordinate = (pow(right - left, 1 - n) * pow(uniform_coordinate - left, n) + left) * frac + uniform_coordinate * (1 - frac); - } - else - { + nonuniform_coordinate = + (pow(right - left, 1 - n) * pow(uniform_coordinate - left, n) + left) * frac + + uniform_coordinate * (1 - frac); + } else { nonuniform_coordinate = uniform_coordinate; } fout[0] = nonuniform_coordinate; @@ -137,8 +125,9 @@ position_map_constB_z_polynomial(double t, const double *xn, double *fout, void * @param constB_ctx Context for the constant B mapping * @param bmag_ctx Context for the magnetic field calculation */ -static void -calculate_optimal_mapping_polynomial(struct gkyl_position_map_const_B_ctx *constB_ctx, struct gkyl_bmag_ctx *bmag_ctx) +static void calculate_optimal_mapping_polynomial( + struct gkyl_position_map_const_B_ctx *constB_ctx, struct gkyl_bmag_ctx *bmag_ctx +) { // Could be refined further by doing midpoint root finding for maximum dB/dz // Expander region @@ -158,12 +147,10 @@ calculate_optimal_mapping_polynomial(struct gkyl_position_map_const_B_ctx *const double max_dB_dCell_prior = 99999999.99; double max_dB_dCell; double max_dB_dCell_order1 = 0.0; - while (1) - { + while (1) { max_dB_dCell = 0.0; constB_ctx->map_order_expander = expander_order; - for (int iz = 0; iz < scan_cells; iz++) - { + for (int iz = 0; iz < scan_cells; iz++) { double left_xi = scan_left + iz * scan_dxi; double right_xi = scan_left + (iz + 1) * scan_dxi; double psi = constB_ctx->psi; @@ -180,28 +167,21 @@ calculate_optimal_mapping_polynomial(struct gkyl_position_map_const_B_ctx *const gkyl_calc_bmag_global(0.0, xp, fout, bmag_ctx); double Bmag_right = fout[0]; double dB_dCell = (Bmag_right - Bmag_left); - if (fabs(dB_dCell) > max_dB_dCell) - { + if (fabs(dB_dCell) > max_dB_dCell) { max_dB_dCell = fabs(dB_dCell); } } double improvement = max_dB_dCell_prior - max_dB_dCell; - if (improvement > 1e-3) - { + if (improvement > 1e-3) { expander_order++; max_dB_dCell_prior = max_dB_dCell; - } - else if (improvement < 0) - { + } else if (improvement < 0) { expander_order--; constB_ctx->map_order_expander = expander_order; break; - } - else - { + } else { break; } - } double max_dB_dCell_expander = max_dB_dCell; //Center region @@ -210,12 +190,10 @@ calculate_optimal_mapping_polynomial(struct gkyl_position_map_const_B_ctx *const scan_dxi = (scan_right - scan_left) / scan_cells; int center_order = 1; max_dB_dCell_prior = 99999999.99; - while (1) - { + while (1) { max_dB_dCell = 0.0; constB_ctx->map_order_center = center_order; - for (int iz = 0; iz < scan_cells; iz++) - { + for (int iz = 0; iz < scan_cells; iz++) { double left_xi = scan_left + iz * scan_dxi; double right_xi = scan_left + (iz + 1) * scan_dxi; @@ -231,31 +209,24 @@ calculate_optimal_mapping_polynomial(struct gkyl_position_map_const_B_ctx *const double Bmag_right = fout[0]; double dB_dCell = (Bmag_right - Bmag_left); - if (fabs(dB_dCell) > max_dB_dCell) - { + if (fabs(dB_dCell) > max_dB_dCell) { max_dB_dCell = fabs(dB_dCell); } } double improvement = max_dB_dCell_prior - max_dB_dCell; - if (improvement > 1e-3) - { + if (improvement > 1e-3) { center_order++; max_dB_dCell_prior = max_dB_dCell; - } - else if (improvement < 0) - { + } else if (improvement < 0) { center_order--; constB_ctx->map_order_center = center_order; break; - } - else - { + } else { break; } } } - // Utility functions for numeric root finding B mapping /** @@ -265,12 +236,12 @@ calculate_optimal_mapping_polynomial(struct gkyl_position_map_const_B_ctx *const * @param theta The theta value to calculate the derivative at * @param ctx The context for the position map */ -static double -calc_bmag_global_derivative(double theta, void *ctx) +static double calc_bmag_global_derivative(double theta, void *ctx) { struct gkyl_position_map *gpm = ctx; struct gkyl_bmag_ctx *bmag_ctx = gpm->bmag_ctx; - double dtheta_cell = (gpm->constB_ctx->theta_max - gpm->constB_ctx->theta_min)/gpm->constB_ctx->N_theta_boundaries; + double dtheta_cell = + (gpm->constB_ctx->theta_max - gpm->constB_ctx->theta_min) / gpm->constB_ctx->N_theta_boundaries; double h = 1e-2 * dtheta_cell; double xh[3]; double fout[3]; @@ -279,7 +250,7 @@ calc_bmag_global_derivative(double theta, void *ctx) xh[2] = theta - h; gkyl_calc_bmag_global(0.0, xh, fout, bmag_ctx); double Bmag_plus = fout[0]; - xh[2] = theta - 2*h; + xh[2] = theta - 2 * h; gkyl_calc_bmag_global(0.0, xh, fout, bmag_ctx); double Bmag_minus = fout[0]; return (Bmag_plus - Bmag_minus) / (h); @@ -291,8 +262,7 @@ calc_bmag_global_derivative(double theta, void *ctx) * * @param gpm The position map object */ -static void -find_B_field_extrema(struct gkyl_position_map *gpm) +static void find_B_field_extrema(struct gkyl_position_map *gpm) { // Assumes we are P1 in z, which means maxima and minima can only be in the center or edge of cells struct gkyl_position_map_const_B_ctx *constB_ctx = gpm->constB_ctx; @@ -314,46 +284,42 @@ find_B_field_extrema(struct gkyl_position_map *gpm) double *theta_extrema = gkyl_malloc(sizeof(double) * (npts + 1)); double *bmag_extrema = gkyl_malloc(sizeof(double) * (npts + 1)); - for (int i = 0; i <= npts; i++){ + for (int i = 0; i <= npts; i++) { double theta = theta_lo + i * theta_dxi; xp[Z_IDX] = theta; gkyl_calc_bmag_global(0.0, xp, &bmag_vals[i], bmag_ctx); dbmag_vals[i] = calc_bmag_global_derivative(theta, gpm); - if (i==0) continue; + if (i == 0) { + continue; + } // Minima - if (dbmag_vals[i] > 0 && dbmag_vals[i-1] < 0){ - if (bmag_vals[i] < bmag_vals[i-1]) - { + if (dbmag_vals[i] > 0 && dbmag_vals[i - 1] < 0) { + if (bmag_vals[i] < bmag_vals[i - 1]) { theta_extrema[extrema] = theta; bmag_extrema[extrema] = bmag_vals[i]; extrema++; - } - else - { + } else { theta_extrema[extrema] = theta - theta_dxi; - bmag_extrema[extrema] = bmag_vals[i-1]; + bmag_extrema[extrema] = bmag_vals[i - 1]; extrema++; } } // Maxima - if (dbmag_vals[i] < 0 && dbmag_vals[i-1] > 0){ - if (bmag_vals[i] > bmag_vals[i-1]) - { + if (dbmag_vals[i] < 0 && dbmag_vals[i - 1] > 0) { + if (bmag_vals[i] > bmag_vals[i - 1]) { theta_extrema[extrema] = theta; bmag_extrema[extrema] = bmag_vals[i]; extrema++; - } - else - { + } else { theta_extrema[extrema] = theta - theta_dxi; - bmag_extrema[extrema] = bmag_vals[i-1]; + bmag_extrema[extrema] = bmag_vals[i - 1]; extrema++; } } } - + // Set final extrema after the loop. MR April 22 2025 theta_extrema[0] = constB_ctx->theta_min; xp[Z_IDX] = constB_ctx->theta_min; @@ -365,8 +331,7 @@ find_B_field_extrema(struct gkyl_position_map *gpm) extrema++; gpm->constB_ctx->num_extrema = extrema; - for (int i = 0; i < extrema; i++) - { + for (int i = 0; i < extrema; i++) { gpm->constB_ctx->theta_extrema[i] = theta_extrema[i]; gpm->constB_ctx->bmag_extrema[i] = bmag_extrema[i]; } @@ -374,31 +339,39 @@ find_B_field_extrema(struct gkyl_position_map *gpm) // Identify 1 for maxima, 0 for minima // Left edge - if (bmag_extrema[0] > bmag_extrema[1]) - { gpm->constB_ctx->min_or_max[0] = 1; } // Maximum - else if (bmag_extrema[0] < bmag_extrema[1]) - { gpm->constB_ctx->min_or_max[0] = 0; } // Minimum - else - { printf("Error: Extrema is not an extrema. Position_map optimization failed\n"); } + if (bmag_extrema[0] > bmag_extrema[1]) { + gpm->constB_ctx->min_or_max[0] = 1; + } // Maximum + else if (bmag_extrema[0] < bmag_extrema[1]) { + gpm->constB_ctx->min_or_max[0] = 0; + } // Minimum + else { + printf("Error: Extrema is not an extrema. Position_map optimization failed\n"); + } // Middle points - for (int i = 1; i < extrema - 1; i++) - { - if (bmag_extrema[i] > bmag_extrema[i-1] && bmag_extrema[i] > bmag_extrema[i+1]) - { gpm->constB_ctx->min_or_max[i] = 1; } // Maximum - else if (bmag_extrema[i] < bmag_extrema[i-1] && bmag_extrema[i] < bmag_extrema[i+1]) - { gpm->constB_ctx->min_or_max[i] = 0; } // Minimum - else - { printf("Error: Extrema is not an extrema. Position_map optimization failed\n"); } + for (int i = 1; i < extrema - 1; i++) { + if (bmag_extrema[i] > bmag_extrema[i - 1] && bmag_extrema[i] > bmag_extrema[i + 1]) { + gpm->constB_ctx->min_or_max[i] = 1; + } // Maximum + else if (bmag_extrema[i] < bmag_extrema[i - 1] && bmag_extrema[i] < bmag_extrema[i + 1]) { + gpm->constB_ctx->min_or_max[i] = 0; + } // Minimum + else { + printf("Error: Extrema is not an extrema. Position_map optimization failed\n"); + } } // Right edge - if (bmag_extrema[extrema-1] > bmag_extrema[extrema-2]) - { gpm->constB_ctx->min_or_max[extrema-1] = 1; } // Maximum - else if (bmag_extrema[extrema-1] < bmag_extrema[extrema-2]) - { gpm->constB_ctx->min_or_max[extrema-1] = 0; } // Minimum - else - { printf("Error: Extrema is not an extrema. Position_map optimization failed\n"); } + if (bmag_extrema[extrema - 1] > bmag_extrema[extrema - 2]) { + gpm->constB_ctx->min_or_max[extrema - 1] = 1; + } // Maximum + else if (bmag_extrema[extrema - 1] < bmag_extrema[extrema - 2]) { + gpm->constB_ctx->min_or_max[extrema - 1] = 0; + } // Minimum + else { + printf("Error: Extrema is not an extrema. Position_map optimization failed\n"); + } // Free mallocs gkyl_free(bmag_vals); @@ -413,8 +386,7 @@ find_B_field_extrema(struct gkyl_position_map *gpm) * * @param gpm The position map object */ -static void -refine_B_field_extrema(struct gkyl_position_map *gpm) +static void refine_B_field_extrema(struct gkyl_position_map *gpm) { int num_points_per_level = 10; // Number of points to evaluate per level for midpoint rule int num_iterations = 22; // Number of iterations to refine the extrema with midpoint rule @@ -432,8 +404,7 @@ refine_B_field_extrema(struct gkyl_position_map *gpm) double theta_hi = constB_ctx->theta_max; double theta_dxi = (theta_hi - theta_lo) / npts; - for (int i = 1; i < gpm->constB_ctx->num_extrema - 1; i++) - { + for (int i = 1; i < gpm->constB_ctx->num_extrema - 1; i++) { double theta = gpm->constB_ctx->theta_extrema[i]; xp[Z_IDX] = theta; double bmag_cent, bmag_left, bmag_right; @@ -449,38 +420,36 @@ refine_B_field_extrema(struct gkyl_position_map *gpm) double extrema_Bmag_location; double bmag_out; bool is_maximum; - if (bmag_cent > bmag_left && bmag_cent > bmag_right) - { is_maximum = true; } // Local maxima - else if (bmag_cent < bmag_left && bmag_cent < bmag_right) - { is_maximum = false; } // Local minima - else - { printf("Error: Extrema is not an extrema. Position_map optimization failed\n"); + if (bmag_cent > bmag_left && bmag_cent > bmag_right) { + is_maximum = true; + } // Local maxima + else if (bmag_cent < bmag_left && bmag_cent < bmag_right) { + is_maximum = false; + } // Local minima + else { + printf("Error: Extrema is not an extrema. Position_map optimization failed\n"); break; } // Midpoint rule refinement - for (int j = 0; j < num_iterations; j++) - { + for (int j = 0; j < num_iterations; j++) { double dz = (interval_right - interval_left) / num_points_per_level; - if (is_maximum) - { extrema_Bmag = 0.0; } - else - { extrema_Bmag = 99999999999999999.; } + if (is_maximum) { + extrema_Bmag = 0.0; + } else { + extrema_Bmag = 99999999999999999.; + } extrema_Bmag_location = 0.0; - for (int k = 0; k <= num_points_per_level; k++) - { + for (int k = 0; k <= num_points_per_level; k++) { double z = interval_left + k * dz; xp[Z_IDX] = z; gkyl_calc_bmag_global(0.0, xp, &bmag_out, bmag_ctx); - if (is_maximum && bmag_out > extrema_Bmag) - { + if (is_maximum && bmag_out > extrema_Bmag) { extrema_Bmag = bmag_out; extrema_Bmag_location = z; - } - else if (!is_maximum && bmag_out < extrema_Bmag) - { + } else if (!is_maximum && bmag_out < extrema_Bmag) { extrema_Bmag = bmag_out; extrema_Bmag_location = z; } @@ -494,9 +463,8 @@ refine_B_field_extrema(struct gkyl_position_map *gpm) // Find the change in B over each cell double B_total_change = 0.0; // Total change in magnetic field - for (int i = 1; i < gpm->constB_ctx->num_extrema; i++) - { - B_total_change += fabs(gpm->constB_ctx->bmag_extrema[i] - gpm->constB_ctx->bmag_extrema[i-1]); + for (int i = 1; i < gpm->constB_ctx->num_extrema; i++) { + B_total_change += fabs(gpm->constB_ctx->bmag_extrema[i] - gpm->constB_ctx->bmag_extrema[i - 1]); } gpm->constB_ctx->dB_cell = B_total_change / (gpm->constB_ctx->N_theta_boundaries); } @@ -508,8 +476,7 @@ refine_B_field_extrema(struct gkyl_position_map *gpm) * @param theta The theta value to evaluate * @param ctx The context for the root finder. Type opt_Theta_ctx */ -static double -position_map_numeric_optimization_function(double theta, void *ctx) +static double position_map_numeric_optimization_function(double theta, void *ctx) { struct opt_Theta_ctx *ridders_ctx = ctx; struct gkyl_position_map *gpm = ridders_ctx->gpm; @@ -541,10 +508,8 @@ position_map_numeric_optimization_function(double theta, void *ctx) * @param fout Non-uniform coordinate * @param ctx The context for the position map */ -static void -position_map_constB_z_numeric(double t, const double *xn, double *fout, void *ctx) +static void position_map_constB_z_numeric(double t, const double *xn, double *fout, void *ctx) { - struct gkyl_position_map *gpm = ctx; int num_boundaries = gpm->constB_ctx->N_theta_boundaries; double *theta_extrema = gpm->constB_ctx->theta_extrema; @@ -560,8 +525,7 @@ position_map_constB_z_numeric(double t, const double *xn, double *fout, void *ct // Set strict floor and ceiling limits for theta // This is to prevent the root finding algorithm from going out of bounds // Not fout[0] = theta because of the finite differences and can lead to jumps - if (it <= 0 || it >= num_boundaries) - { + if (it <= 0 || it >= num_boundaries) { fout[0] = (it <= 0) ? theta_lo : theta_hi; return; } @@ -571,33 +535,25 @@ position_map_constB_z_numeric(double t, const double *xn, double *fout, void *ct // Initial guess is not accurate because the theta_extrema are not Theta_extrema // We use itteration to further refine this, but it's a good initial guess int region = 0; - for (int i = 1; i <= num_extrema-2; i++) - { - if (theta >= theta_extrema[i]) - { + for (int i = 1; i <= num_extrema - 2; i++) { + if (theta >= theta_extrema[i]) { region = i; - } - else - { + } else { break; } } double dB_target, dB_global_lower, B_lower_region; double interval_lower, interval_upper, interval_lower_eval, interval_upper_eval; - struct opt_Theta_ctx ridders_ctx = { - .gpm = gpm, - .bmag_ctx = gpm->bmag_ctx, - }; + struct opt_Theta_ctx ridders_ctx = {.gpm = gpm, .bmag_ctx = gpm->bmag_ctx}; dB_target = dB_cell * it; bool outside_region = true; // Asuume that we identified the region incorrectly - while (outside_region) - { + while (outside_region) { dB_global_lower = 0.0; - for (int i = 0; i < region; i++) - { - dB_global_lower += fabs(gpm->constB_ctx->bmag_extrema[i+1] - gpm->constB_ctx->bmag_extrema[i]); + for (int i = 0; i < region; i++) { + dB_global_lower += + fabs(gpm->constB_ctx->bmag_extrema[i + 1] - gpm->constB_ctx->bmag_extrema[i]); } B_lower_region = gpm->constB_ctx->bmag_extrema[region]; @@ -606,15 +562,14 @@ position_map_constB_z_numeric(double t, const double *xn, double *fout, void *ct ridders_ctx.B_lower_region = B_lower_region; interval_lower = theta_extrema[region]; - interval_upper = theta_extrema[region+1]; + interval_upper = theta_extrema[region + 1]; interval_lower_eval = position_map_numeric_optimization_function(interval_lower, &ridders_ctx); interval_upper_eval = position_map_numeric_optimization_function(interval_upper, &ridders_ctx); if (interval_lower_eval * interval_upper_eval < 0) { // If the interval changes sign, then there is a zero in between. We can find the root and are in the correct region outside_region = false; - } - else if (fabs(interval_lower_eval) < 1e-10 || fabs(interval_upper_eval) < 1e-10) { + } else if (fabs(interval_lower_eval) < 1e-10 || fabs(interval_upper_eval) < 1e-10) { // If either evaluation is very close to zero, we're at or very near the solution // Just use the corresponding endpoint if (fabs(interval_lower_eval) < fabs(interval_upper_eval)) { @@ -623,8 +578,7 @@ position_map_constB_z_numeric(double t, const double *xn, double *fout, void *ct fout[0] = interval_upper; } return; - } - else { + } else { // It means we are in the wrong region if (interval_lower_eval > 0.0 && interval_upper_eval > 0.0) { // If the bounds on the interval are both positive, we should move down a region to make it pass through zero @@ -634,59 +588,58 @@ position_map_constB_z_numeric(double t, const double *xn, double *fout, void *ct fout[0] = theta_lo; return; } - } - else if (interval_lower_eval < 0.0 && interval_upper_eval < 0.0) { + } else if (interval_lower_eval < 0.0 && interval_upper_eval < 0.0) { // If the bounds on the interval are both negative, we should move up a region to make it pass through zero region++; - if (region > num_extrema-2) { + if (region > num_extrema - 2) { // If we can't move up any regions and leave the simulation domain, we are likely on the upper limit of the domain and should just return the input theta fout[0] = theta_hi; return; } - } - else if (fabs(interval_lower_eval) < 1e-14) { + } else if (fabs(interval_lower_eval) < 1e-14) { // Lower evaluation is very close to zero fout[0] = interval_lower; return; - } - else if (fabs(interval_upper_eval) < 1e-14) { + } else if (fabs(interval_upper_eval) < 1e-14) { // Upper evaluation is very close to zero fout[0] = interval_upper; return; - } - else { - fprintf(stderr, "Warning: Unexpected interval evaluation state in position_map_constB_z_numeric. Using theta directly.\n"); + } else { + fprintf( + stderr, + "Warning: Unexpected interval evaluation state in position_map_constB_z_numeric. Using " + "theta directly.\n" + ); fout[0] = theta; return; } } } - struct gkyl_qr_res res = gkyl_ridders(position_map_numeric_optimization_function, &ridders_ctx, - interval_lower, interval_upper, interval_lower_eval, interval_upper_eval, 10, 1e-6); + struct gkyl_qr_res res = gkyl_ridders( + position_map_numeric_optimization_function, &ridders_ctx, interval_lower, interval_upper, + interval_lower_eval, interval_upper_eval, 10, 1e-6 + ); double Theta = res.res; - fout[0] = Theta*gpm->constB_ctx->map_strength + theta*(1-gpm->constB_ctx->map_strength); + fout[0] = Theta * gpm->constB_ctx->map_strength + theta * (1 - gpm->constB_ctx->map_strength); bool enable_limits_min_B = gpm->constB_ctx->enable_maximum_slope_limits_at_min_B; bool enable_limits_max_B = gpm->constB_ctx->enable_maximum_slope_limits_at_max_B; - if (enable_limits_min_B || enable_limits_max_B) - { + if (enable_limits_min_B || enable_limits_max_B) { // Set a minimum cell size on the edges // Assume that at inflection points, Theta = theta. This should be true - double Theta_left = interval_lower; + double Theta_left = interval_lower; double Theta_right = interval_upper; double theta_middle = 0.5 * (interval_lower + interval_upper); bool left_is_maximum = gpm->constB_ctx->min_or_max[region]; - bool right_is_maximum = gpm->constB_ctx->min_or_max[region+1]; + bool right_is_maximum = gpm->constB_ctx->min_or_max[region + 1]; - if (theta > theta_middle && left_is_maximum) - { + if (theta > theta_middle && left_is_maximum) { enable_limits_max_B = false; } - if (theta < theta_middle && right_is_maximum) - { + if (theta < theta_middle && right_is_maximum) { enable_limits_max_B = false; } @@ -694,68 +647,59 @@ position_map_constB_z_numeric(double t, const double *xn, double *fout, void *ct double max_slope_max_B = gpm->constB_ctx->maximum_slope_at_max_B; double right_straight_line_value, left_straight_line_value; - if (left_is_maximum){ - left_straight_line_value = max_slope_max_B * theta + (1-max_slope_max_B) * Theta_left; - } - else { - left_straight_line_value = max_slope_min_B * theta + (1-max_slope_min_B) * Theta_left; + if (left_is_maximum) { + left_straight_line_value = max_slope_max_B * theta + (1 - max_slope_max_B) * Theta_left; + } else { + left_straight_line_value = max_slope_min_B * theta + (1 - max_slope_min_B) * Theta_left; } - if (right_is_maximum){ - right_straight_line_value = max_slope_max_B * theta + (1-max_slope_max_B) * Theta_right; - } - else { - right_straight_line_value = max_slope_min_B * theta + (1-max_slope_min_B) * Theta_right; + if (right_is_maximum) { + right_straight_line_value = max_slope_max_B * theta + (1 - max_slope_max_B) * Theta_right; + } else { + right_straight_line_value = max_slope_min_B * theta + (1 - max_slope_min_B) * Theta_right; } - if ( fout[0] < right_straight_line_value && - ((right_is_maximum && enable_limits_max_B) || - ((!right_is_maximum) && enable_limits_min_B))) - { + if (fout[0] < right_straight_line_value && ((right_is_maximum && enable_limits_max_B) || + ((!right_is_maximum) && enable_limits_min_B))) { fout[0] = right_straight_line_value; } - if (fout[0] > left_straight_line_value && - ((left_is_maximum && enable_limits_max_B) || - ((!left_is_maximum) && enable_limits_min_B))) - { + if (fout[0] > left_straight_line_value && + ((left_is_maximum && enable_limits_max_B) || ((!left_is_maximum) && enable_limits_min_B))) { fout[0] = left_straight_line_value; } } } // Context for Gaussian-weighted integration -struct gaussian_weight_ctx -{ +struct gaussian_weight_ctx { struct gkyl_position_map *gpm; double theta_c; // Center point for Gaussian double wd2; // Half-width of averaging window double sigma; // Standard deviation for Gaussian weight }; -double -position_map_constB_z_numeric_dbl_exp_wrapper(double z, void *ctx) +double position_map_constB_z_numeric_dbl_exp_wrapper(double z, void *ctx) { struct gaussian_weight_ctx *gw_ctx = ctx; double fout[3]; position_map_constB_z_numeric(0.0, &z, fout, gw_ctx->gpm); - + // Apply Gaussian weight: exp(-(z-theta_c)^2 / (2*sigma^2)) double dz = z - gw_ctx->theta_c; double weight = exp(-dz * dz / (2.0 * gw_ctx->sigma * gw_ctx->sigma)); - + return fout[0] * weight; } -double -gaussian_norm_wrapper(double z, void *ctx) +double gaussian_norm_wrapper(double z, void *ctx) { struct gaussian_weight_ctx *gw_ctx = ctx; - + // Return just the Gaussian weight for normalization double dz = z - gw_ctx->theta_c; double weight = exp(-dz * dz / (2.0 * gw_ctx->sigma * gw_ctx->sigma)); - + return weight; } @@ -772,8 +716,7 @@ static void position_map_constB_z_numeric_moving_average(double t, const double *xn, double *fout, void *ctx) { struct gkyl_position_map *gpm = ctx; - if (gpm->constB_ctx->gaussian_std == 0.0) - { + if (gpm->constB_ctx->gaussian_std == 0.0) { position_map_constB_z_numeric(t, xn, fout, ctx); return; } @@ -783,40 +726,32 @@ position_map_constB_z_numeric_moving_average(double t, const double *xn, double const double max_width = gpm->constB_ctx->gaussian_max_integration_width; const double tmin = gpm->constB_ctx->theta_min; const double tmax = gpm->constB_ctx->theta_max; - + // Shrink the half-width symmetrically to stay within bounds // This ensures the integration window is always centered at theta_c double dist_to_min = theta_c - tmin; double dist_to_max = tmax - theta_c; - double wd2 = fmin(fmin(dist_to_min, dist_to_max) * 0.99, max_width/2); - + double wd2 = fmin(fmin(dist_to_min, dist_to_max) * 0.99, max_width / 2); + // If the symmetric window is too small, fall back to unsmoothed - if (wd2 < 1e-6) - { + if (wd2 < 1e-6) { position_map_constB_z_numeric(t, xn, fout, ctx); return; } - + double rng_lo = theta_c - wd2; double rng_up = theta_c + wd2; // Keep sigma fixed at the original gaussian_std // This maintains consistent smoothing behavior even at boundaries - struct gaussian_weight_ctx gw_ctx = { - .gpm = gpm, - .theta_c = theta_c, - .wd2 = wd2, - .sigma = sigma, - }; + struct gaussian_weight_ctx gw_ctx = {.gpm = gpm, .theta_c = theta_c, .wd2 = wd2, .sigma = sigma}; - struct gkyl_qr_res res = gkyl_dbl_exp( - position_map_constB_z_numeric_dbl_exp_wrapper, &gw_ctx, - rng_lo, rng_up, 7, 1e-16); + struct gkyl_qr_res res = + gkyl_dbl_exp(position_map_constB_z_numeric_dbl_exp_wrapper, &gw_ctx, rng_lo, rng_up, 7, 1e-16); // Normalize by the integral of the Gaussian weight over the symmetric range - struct gkyl_qr_res norm_res = gkyl_dbl_exp( - gaussian_norm_wrapper, &gw_ctx, - rng_lo, rng_up, 7, 1e-16); + struct gkyl_qr_res norm_res = + gkyl_dbl_exp(gaussian_norm_wrapper, &gw_ctx, rng_lo, rng_up, 7, 1e-16); double theta_avg = res.res / norm_res.res; fout[0] = theta_avg; @@ -831,16 +766,16 @@ position_map_constB_z_numeric_moving_average(double t, const double *xn, double * @param fout Non-uniform coordinate * @param ctx position_map_constB_ctx context for the constant B mapping */ -static void -position_map_xpt_compression(double t, const double *xn, double *fout, void *ctx) +static void position_map_xpt_compression(double t, const double *xn, double *fout, void *ctx) { struct gkyl_position_map_xpt_ctx *app = ctx; - double uniform_coordinate = xn[0]; + double uniform_coordinate = xn[0]; double F = 1.0 / (1.0 - app->compression_factor); - double A = 1.0/F; + double A = 1.0 / F; double zcut = app->zcut; double zshift = uniform_coordinate - app->zcenter; - double nonuniform_coordinate = A * (sin(M_PI*zshift/zcut)*zcut/M_PI + F*zshift) + app->zcenter; + double nonuniform_coordinate = + A * (sin(M_PI * zshift / zcut) * zcut / M_PI + F * zshift) + app->zcenter; fout[0] = nonuniform_coordinate; } @@ -853,16 +788,16 @@ position_map_xpt_compression(double t, const double *xn, double *fout, void *ctx * @param fout Non-uniform coordinate * @param ctx position_map_constB_ctx context for the constant B mapping */ -static void -position_map_sep_compression(double t, const double *xn, double *fout, void *ctx) +static void position_map_sep_compression(double t, const double *xn, double *fout, void *ctx) { struct gkyl_position_map_xpt_ctx *app = ctx; - double uniform_coordinate = xn[0]; + double uniform_coordinate = xn[0]; double F = 1.0 / (1.0 - app->compression_factor); - double A = 1.0/F; + double A = 1.0 / F; double w = app->w; double xshift = uniform_coordinate - app->psisep; - double nonuniform_coordinate = A * (-sin(M_PI*xshift/w)*w/M_PI + F*xshift) + app->psisep; + double nonuniform_coordinate = + A * (-sin(M_PI * xshift / w) * w / M_PI + F * xshift) + app->psisep; fout[0] = nonuniform_coordinate; } @@ -875,16 +810,15 @@ position_map_sep_compression(double t, const double *xn, double *fout, void *ctx * @param fout Non-uniform coordinate * @param ctx position_map_constB_ctx context for the constant B mapping */ -static void -position_map_deriv_xpt_compression(double t, const double *xn, double *fout, void *ctx) +static void position_map_deriv_xpt_compression(double t, const double *xn, double *fout, void *ctx) { struct gkyl_position_map_xpt_ctx *app = ctx; - double uniform_coordinate = xn[0]; + double uniform_coordinate = xn[0]; double F = 1.0 / (1.0 - app->compression_factor); - double A = 1.0/F; + double A = 1.0 / F; double zcut = app->zcut; double zshift = uniform_coordinate - app->zcenter; - double deriv = A * (cos(M_PI*zshift/zcut) + F); + double deriv = A * (cos(M_PI * zshift / zcut) + F); fout[0] = deriv; } @@ -897,16 +831,14 @@ position_map_deriv_xpt_compression(double t, const double *xn, double *fout, voi * @param fout Non-uniform coordinate * @param ctx position_map_constB_ctx context for the constant B mapping */ -static void -position_map_deriv_sep_compression(double t, const double *xn, double *fout, void *ctx) +static void position_map_deriv_sep_compression(double t, const double *xn, double *fout, void *ctx) { struct gkyl_position_map_xpt_ctx *app = ctx; - double uniform_coordinate = xn[0]; + double uniform_coordinate = xn[0]; double F = 1.0 / (1.0 - app->compression_factor); - double A = 1.0/F; + double A = 1.0 / F; double w = app->w; double xshift = uniform_coordinate - app->psisep; - double deriv = A * (-cos(M_PI*xshift/w) + F); + double deriv = A * (-cos(M_PI * xshift / w) + F); fout[0] = deriv; } - diff --git a/gyrokinetic/zero/gkyl_positivity_shift_gyrokinetic.h b/gyrokinetic/zero/gkyl_positivity_shift_gyrokinetic.h index 86f473c848..a01b9e4116 100644 --- a/gyrokinetic/zero/gkyl_positivity_shift_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_positivity_shift_gyrokinetic.h @@ -26,11 +26,11 @@ typedef struct gkyl_positivity_shift_gyrokinetic gkyl_positivity_shift_gyrokinet * @param use_gpu bool to determine if on GPU. * @return New positivity shift updater pointer. */ -struct gkyl_positivity_shift_gyrokinetic* -gkyl_positivity_shift_gyrokinetic_new(struct gkyl_basis cbasis, struct gkyl_basis pbasis, - struct gkyl_rect_grid grid, double mass, - const struct gk_geometry *gk_geom, - const struct gkyl_velocity_map *vel_map, const struct gkyl_range *conf_rng_ext, bool use_gpu); +struct gkyl_positivity_shift_gyrokinetic *gkyl_positivity_shift_gyrokinetic_new( + struct gkyl_basis cbasis, struct gkyl_basis pbasis, struct gkyl_rect_grid grid, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, + const struct gkyl_range *conf_rng_ext, bool use_gpu +); /** * Run the positivity shift updater in the indicated range. @@ -42,11 +42,11 @@ gkyl_positivity_shift_gyrokinetic_new(struct gkyl_basis cbasis, struct gkyl_basi * @param m0 Output M0 moment array. * @param delta_m0 M0 moment of the shift in f. */ -void -gkyl_positivity_shift_gyrokinetic_advance(gkyl_positivity_shift_gyrokinetic* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - struct gkyl_array *GKYL_RESTRICT distf, struct gkyl_array *GKYL_RESTRICT m0, - struct gkyl_array *GKYL_RESTRICT delta_m0); +void gkyl_positivity_shift_gyrokinetic_advance( + gkyl_positivity_shift_gyrokinetic *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, struct gkyl_array *GKYL_RESTRICT distf, + struct gkyl_array *GKYL_RESTRICT m0, struct gkyl_array *GKYL_RESTRICT delta_m0 +); /** * Scale the distribution function in the indicated range after applying the @@ -61,17 +61,17 @@ gkyl_positivity_shift_gyrokinetic_advance(gkyl_positivity_shift_gyrokinetic* up, * @param m0s M0 moment of fs. * @param fs Distribution function of the species we wish to scale. */ -void -gkyl_positivity_shift_gyrokinetic_quasineutrality_scale(gkyl_positivity_shift_gyrokinetic* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - const struct gkyl_array *GKYL_RESTRICT delta_m0s, const struct gkyl_array *GKYL_RESTRICT delta_m0s_tot, +void gkyl_positivity_shift_gyrokinetic_quasineutrality_scale( + gkyl_positivity_shift_gyrokinetic *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, const struct gkyl_array *GKYL_RESTRICT delta_m0s, + const struct gkyl_array *GKYL_RESTRICT delta_m0s_tot, const struct gkyl_array *GKYL_RESTRICT delta_m0r_tot, const struct gkyl_array *GKYL_RESTRICT m0s, - struct gkyl_array *GKYL_RESTRICT fs); + struct gkyl_array *GKYL_RESTRICT fs +); /** * Release the memory associated with this positivity shift updater. * * @param up Positivity shift updater. */ -void -gkyl_positivity_shift_gyrokinetic_release(gkyl_positivity_shift_gyrokinetic* up); +void gkyl_positivity_shift_gyrokinetic_release(gkyl_positivity_shift_gyrokinetic *up); diff --git a/gyrokinetic/zero/gkyl_positivity_shift_gyrokinetic_priv.h b/gyrokinetic/zero/gkyl_positivity_shift_gyrokinetic_priv.h index a19e996dd6..79d592ac5c 100644 --- a/gyrokinetic/zero/gkyl_positivity_shift_gyrokinetic_priv.h +++ b/gyrokinetic/zero/gkyl_positivity_shift_gyrokinetic_priv.h @@ -12,55 +12,60 @@ enum gkyl_positivity_shift_type { GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY = 0, - GKYL_POSITIVITY_SHIFT_TYPE_MRS_LIMITER, // Moe-Rossmanith-Seal limiter. + GKYL_POSITIVITY_SHIFT_TYPE_MRS_LIMITER // Moe-Rossmanith-Seal limiter. }; // Function pointer type for sheath reflection kernels. typedef bool (*m0_pos_check_t)(const double *m0); typedef bool (*shift_t)(double ffloor, double *distf); -typedef void (*m0_t)(const double *dxv, const double *vmap, - double m_, const double *bmag, const double *f, double* GKYL_RESTRICT out); - -typedef struct { m0_pos_check_t kernels[3]; } pos_shift_gk_kern_list_m0_pos_check; // For use in kernel tables. -typedef struct { shift_t kernels[3]; } pos_shift_gk_kern_list_shift; // For use in kernel tables. -typedef struct { m0_t kernels[3]; } pos_shift_gk_kern_list_m0; // For use in kernel tables. +typedef void (*m0_t)( + const double *dxv, const double *vmap, double m_, const double *bmag, const double *f, + double *GKYL_RESTRICT out +); + +typedef struct { + m0_pos_check_t kernels[3]; +} pos_shift_gk_kern_list_m0_pos_check; // For use in kernel tables. +typedef struct { + shift_t kernels[3]; +} pos_shift_gk_kern_list_shift; // For use in kernel tables. +typedef struct { + m0_t kernels[3]; +} pos_shift_gk_kern_list_m0; // For use in kernel tables. // Serendipity kernels. -GKYL_CU_D -static const pos_shift_gk_kern_list_m0_pos_check pos_shift_gk_kern_list_m0_pos_check_ser[] = { - { positivity_shift_gyrokinetic_conf_pos_check_1x_ser_p1, NULL, NULL }, - { positivity_shift_gyrokinetic_conf_pos_check_2x_ser_p1, NULL, NULL }, - { positivity_shift_gyrokinetic_conf_pos_check_3x_ser_p1, NULL, NULL }, +GKYL_CU_D static const pos_shift_gk_kern_list_m0_pos_check + pos_shift_gk_kern_list_m0_pos_check_ser[] = { + {positivity_shift_gyrokinetic_conf_pos_check_1x_ser_p1, NULL, NULL}, + {positivity_shift_gyrokinetic_conf_pos_check_2x_ser_p1, NULL, NULL}, + {positivity_shift_gyrokinetic_conf_pos_check_3x_ser_p1, NULL, NULL} }; -GKYL_CU_D -static const pos_shift_gk_kern_list_shift pos_shift_gk_kern_list_shift_ser[] = { - { positivity_shift_gyrokinetic_shift_only_1x1v_ser_p1, NULL, NULL }, - { positivity_shift_gyrokinetic_shift_only_1x2v_ser_p1, NULL, NULL }, - { positivity_shift_gyrokinetic_shift_only_2x2v_ser_p1, NULL, NULL }, - { positivity_shift_gyrokinetic_shift_only_3x2v_ser_p1, NULL, NULL }, +GKYL_CU_D static const pos_shift_gk_kern_list_shift pos_shift_gk_kern_list_shift_ser[] = { + {positivity_shift_gyrokinetic_shift_only_1x1v_ser_p1, NULL, NULL}, + {positivity_shift_gyrokinetic_shift_only_1x2v_ser_p1, NULL, NULL}, + {positivity_shift_gyrokinetic_shift_only_2x2v_ser_p1, NULL, NULL}, + {positivity_shift_gyrokinetic_shift_only_3x2v_ser_p1, NULL, NULL} }; -GKYL_CU_D -static const pos_shift_gk_kern_list_shift pos_shift_gk_kern_list_MRSlimiter_ser[] = { - { positivity_shift_gyrokinetic_MRS_limiter_1x1v_ser_p1, NULL, NULL }, - { positivity_shift_gyrokinetic_MRS_limiter_1x2v_ser_p1, NULL, NULL }, - { positivity_shift_gyrokinetic_MRS_limiter_2x2v_ser_p1, NULL, NULL }, - { positivity_shift_gyrokinetic_MRS_limiter_3x2v_ser_p1, NULL, NULL }, +GKYL_CU_D static const pos_shift_gk_kern_list_shift pos_shift_gk_kern_list_MRSlimiter_ser[] = { + {positivity_shift_gyrokinetic_MRS_limiter_1x1v_ser_p1, NULL, NULL}, + {positivity_shift_gyrokinetic_MRS_limiter_1x2v_ser_p1, NULL, NULL}, + {positivity_shift_gyrokinetic_MRS_limiter_2x2v_ser_p1, NULL, NULL}, + {positivity_shift_gyrokinetic_MRS_limiter_3x2v_ser_p1, NULL, NULL} }; -GKYL_CU_D -static const pos_shift_gk_kern_list_m0 pos_shift_gk_kern_list_m0_ser[] = { - { gyrokinetic_M0_1x1v_ser_p1, gyrokinetic_M0_1x1v_ser_p2, NULL }, - { gyrokinetic_M0_1x2v_ser_p1, gyrokinetic_M0_1x2v_ser_p2, NULL }, - { gyrokinetic_M0_2x2v_ser_p1, gyrokinetic_M0_2x2v_ser_p2, NULL }, - { gyrokinetic_M0_3x2v_ser_p1, NULL, NULL }, +GKYL_CU_D static const pos_shift_gk_kern_list_m0 pos_shift_gk_kern_list_m0_ser[] = { + {gyrokinetic_M0_1x1v_ser_p1, gyrokinetic_M0_1x1v_ser_p2, NULL}, + {gyrokinetic_M0_1x2v_ser_p1, gyrokinetic_M0_1x2v_ser_p2, NULL}, + {gyrokinetic_M0_2x2v_ser_p1, gyrokinetic_M0_2x2v_ser_p2, NULL}, + {gyrokinetic_M0_3x2v_ser_p1, NULL, NULL} }; struct gkyl_positivity_shift_gyrokinetic_kernels { m0_pos_check_t is_m0_positive; // Kernels that checks if m0 is positive. - shift_t shift; // Kernel that shifts f to enforce positivity if needed. - m0_t m0; // Kernel that computes the number density. + shift_t shift; // Kernel that shifts f to enforce positivity if needed. + m0_t m0; // Kernel that computes the number density. inv_op_t conf_inv_op; // Conf-space weak inversion (1/A) kernel (p=1 only). mul_op_t conf_mul_op; // Conf-space weak multiplication kernel. mul_op_t conf_phase_mul_op; // Conf-phase weak multiplication kernel. @@ -68,11 +73,11 @@ struct gkyl_positivity_shift_gyrokinetic_kernels { // Primary struct in this updater. struct gkyl_positivity_shift_gyrokinetic { - int num_cbasis; // Number of conf-space basis monomials. - struct gkyl_rect_grid grid; // Phase-space grid. - double mass; // Species mass. - double *ffloor; // Minimum f to shift distribution to when it's <0. - double ffloor_fac; // ffloor = max(f)*ffloor_fac. + int num_cbasis; // Number of conf-space basis monomials. + struct gkyl_rect_grid grid; // Phase-space grid. + double mass; // Species mass. + double *ffloor; // Minimum f to shift distribution to when it's <0. + double ffloor_fac; // ffloor = max(f)*ffloor_fac. double cellav_fac; // Factor multiplying 0th DG coefficient to give cellav. const struct gk_geometry *gk_geom; // Pointer to geometry object. const struct gkyl_velocity_map *vel_map; // Pointer to velocity mapping object. @@ -84,28 +89,30 @@ struct gkyl_positivity_shift_gyrokinetic { #ifdef GKYL_HAVE_CUDA // Declaration of cuda device functions. -void -pos_shift_gk_choose_shift_kernel_cu(struct gkyl_positivity_shift_gyrokinetic_kernels *kernels, - struct gkyl_basis cbasis, struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype); - -void -gkyl_positivity_shift_gyrokinetic_advance_cu(gkyl_positivity_shift_gyrokinetic* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - struct gkyl_array *GKYL_RESTRICT distf, struct gkyl_array *GKYL_RESTRICT m0, - struct gkyl_array *GKYL_RESTRICT delta_m0); - -void -gkyl_positivity_shift_gyrokinetic_quasineutrality_scale_cu(gkyl_positivity_shift_gyrokinetic* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - const struct gkyl_array *GKYL_RESTRICT delta_m0s, const struct gkyl_array *GKYL_RESTRICT delta_m0s_tot, +void pos_shift_gk_choose_shift_kernel_cu( + struct gkyl_positivity_shift_gyrokinetic_kernels *kernels, struct gkyl_basis cbasis, + struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype +); + +void gkyl_positivity_shift_gyrokinetic_advance_cu( + gkyl_positivity_shift_gyrokinetic *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, struct gkyl_array *GKYL_RESTRICT distf, + struct gkyl_array *GKYL_RESTRICT m0, struct gkyl_array *GKYL_RESTRICT delta_m0 +); + +void gkyl_positivity_shift_gyrokinetic_quasineutrality_scale_cu( + gkyl_positivity_shift_gyrokinetic *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, const struct gkyl_array *GKYL_RESTRICT delta_m0s, + const struct gkyl_array *GKYL_RESTRICT delta_m0s_tot, const struct gkyl_array *GKYL_RESTRICT delta_m0r, const struct gkyl_array *GKYL_RESTRICT m0s, - struct gkyl_array *GKYL_RESTRICT fs); + struct gkyl_array *GKYL_RESTRICT fs +); #endif -GKYL_CU_D -static void pos_shift_gk_choose_shift_kernel(struct gkyl_positivity_shift_gyrokinetic_kernels *kernels, - struct gkyl_basis cbasis, struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype, - bool use_gpu) +GKYL_CU_D static void pos_shift_gk_choose_shift_kernel( + struct gkyl_positivity_shift_gyrokinetic_kernels *kernels, struct gkyl_basis cbasis, + struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { @@ -119,28 +126,29 @@ static void pos_shift_gk_choose_shift_kernel(struct gkyl_positivity_shift_gyroki int poly_order = pbasis.poly_order; switch (pbasis_type) { - case GKYL_BASIS_MODAL_GKHYBRID: - case GKYL_BASIS_MODAL_SERENDIPITY: - kernels->is_m0_positive = pos_shift_gk_kern_list_m0_pos_check_ser[cdim-1].kernels[poly_order-1]; - kernels->shift = stype == GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY? - pos_shift_gk_kern_list_shift_ser[pdim-2].kernels[poly_order-1] : - pos_shift_gk_kern_list_MRSlimiter_ser[pdim-2].kernels[poly_order-1]; - kernels->m0 = pos_shift_gk_kern_list_m0_ser[pdim-2].kernels[poly_order-1]; - kernels->conf_phase_mul_op = choose_mul_conf_phase_kern(pbasis_type, cdim, pdim-cdim, poly_order); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_GKHYBRID: + case GKYL_BASIS_MODAL_SERENDIPITY: + kernels->is_m0_positive = + pos_shift_gk_kern_list_m0_pos_check_ser[cdim - 1].kernels[poly_order - 1]; + kernels->shift = stype == GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY ? + pos_shift_gk_kern_list_shift_ser[pdim - 2].kernels[poly_order - 1] : + pos_shift_gk_kern_list_MRSlimiter_ser[pdim - 2].kernels[poly_order - 1]; + kernels->m0 = pos_shift_gk_kern_list_m0_ser[pdim - 2].kernels[poly_order - 1]; + kernels->conf_phase_mul_op = + choose_mul_conf_phase_kern(pbasis_type, cdim, pdim - cdim, poly_order); + break; + default: + assert(false); + break; } switch (cbasis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - kernels->conf_inv_op = choose_ser_inv_kern(cdim, poly_order); - kernels->conf_mul_op = choose_ser_mul_kern(cdim, poly_order); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + kernels->conf_inv_op = choose_ser_inv_kern(cdim, poly_order); + kernels->conf_mul_op = choose_ser_mul_kern(cdim, poly_order); + break; + default: + assert(false); + break; } - } diff --git a/gyrokinetic/zero/gkyl_prim_lbo_gyrokinetic.h b/gyrokinetic/zero/gkyl_prim_lbo_gyrokinetic.h index 78f2102d3a..886c11efae 100644 --- a/gyrokinetic/zero/gkyl_prim_lbo_gyrokinetic.h +++ b/gyrokinetic/zero/gkyl_prim_lbo_gyrokinetic.h @@ -11,14 +11,14 @@ * @param use_gpu bool to determine if on GPU * @return Pointer to Gyrokinetic primitive moment object */ -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_gyrokinetic_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, bool use_gpu); +struct gkyl_prim_lbo_type *gkyl_prim_lbo_gyrokinetic_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, bool use_gpu +); /** * Create a new Gyrokinetic primitive type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis); +struct gkyl_prim_lbo_type *gkyl_prim_lbo_gyrokinetic_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis +); diff --git a/gyrokinetic/zero/gkyl_prim_lbo_gyrokinetic_priv.h b/gyrokinetic/zero/gkyl_prim_lbo_gyrokinetic_priv.h index 2511508bf6..1c06baebea 100644 --- a/gyrokinetic/zero/gkyl_prim_lbo_gyrokinetic_priv.h +++ b/gyrokinetic/zero/gkyl_prim_lbo_gyrokinetic_priv.h @@ -6,44 +6,54 @@ #include #include -typedef void (*gyrokinetic_self_prim_t)(struct gkyl_mat *A, struct gkyl_mat *rhs, - const double *moms, const double *boundary_corrections, const double *nu); - -typedef void (*gyrokinetic_cross_prim_t)(struct gkyl_mat *A, struct gkyl_mat *rhs, const double *alpha_E, - const double m_self, const double *moms_self, const double *prim_moms_self, - const double m_other, const double *moms_other, const double *prim_moms_other, - const double *boundary_corrections, const double *nu); +typedef void (*gyrokinetic_self_prim_t)( + struct gkyl_mat *A, struct gkyl_mat *rhs, const double *moms, const double *boundary_corrections, + const double *nu +); + +typedef void (*gyrokinetic_cross_prim_t)( + struct gkyl_mat *A, struct gkyl_mat *rhs, const double *alpha_E, const double m_self, + const double *moms_self, const double *prim_moms_self, const double m_other, + const double *moms_other, const double *prim_moms_other, const double *boundary_corrections, + const double *nu +); // for use in kernel tables -typedef struct { gyrokinetic_self_prim_t kernels[3]; } gkyl_prim_lbo_gyrokinetic_kern_list; -typedef struct { gyrokinetic_cross_prim_t kernels[3]; } gkyl_prim_lbo_gyrokinetic_cross_kern_list; +typedef struct { + gyrokinetic_self_prim_t kernels[3]; +} gkyl_prim_lbo_gyrokinetic_kern_list; +typedef struct { + gyrokinetic_cross_prim_t kernels[3]; +} gkyl_prim_lbo_gyrokinetic_cross_kern_list; // // Serendipity basis kernels // // self primitive moment kernel list -GKYL_CU_D -static const gkyl_prim_lbo_gyrokinetic_kern_list ser_self_prim_kernels[] = { +GKYL_CU_D static const gkyl_prim_lbo_gyrokinetic_kern_list ser_self_prim_kernels[] = { // 1x kernels - { NULL, gyrokinetic_self_prim_moments_1x1v_ser_p1, gyrokinetic_self_prim_moments_1x1v_ser_p2 }, // 0 - { NULL, gyrokinetic_self_prim_moments_1x2v_ser_p1, gyrokinetic_self_prim_moments_1x2v_ser_p2 }, // 1 + {NULL, gyrokinetic_self_prim_moments_1x1v_ser_p1, gyrokinetic_self_prim_moments_1x1v_ser_p2}, // 0 + {NULL, gyrokinetic_self_prim_moments_1x2v_ser_p1, gyrokinetic_self_prim_moments_1x2v_ser_p2}, // 1 // 2x kernels - { NULL, gyrokinetic_self_prim_moments_2x2v_ser_p1, gyrokinetic_self_prim_moments_2x2v_ser_p2 }, // 2 + {NULL, gyrokinetic_self_prim_moments_2x2v_ser_p1, gyrokinetic_self_prim_moments_2x2v_ser_p2}, // 2 // 3x kernels - { NULL, gyrokinetic_self_prim_moments_3x2v_ser_p1, gyrokinetic_self_prim_moments_3x2v_ser_p2 }, // 3 + {NULL, gyrokinetic_self_prim_moments_3x2v_ser_p1, gyrokinetic_self_prim_moments_3x2v_ser_p2} // 3 }; // cross primitive moment kernel list -GKYL_CU_D -static const gkyl_prim_lbo_gyrokinetic_cross_kern_list ser_cross_prim_kernels[] = { +GKYL_CU_D static const gkyl_prim_lbo_gyrokinetic_cross_kern_list ser_cross_prim_kernels[] = { // 1x kernels - { NULL, gyrokinetic_cross_prim_moments_1x1v_ser_p1, gyrokinetic_cross_prim_moments_1x1v_ser_p2 }, // 0 - { NULL, gyrokinetic_cross_prim_moments_1x2v_ser_p1, gyrokinetic_cross_prim_moments_1x2v_ser_p2 }, // 1 + {NULL, gyrokinetic_cross_prim_moments_1x1v_ser_p1, gyrokinetic_cross_prim_moments_1x1v_ser_p2 + }, // 0 + {NULL, gyrokinetic_cross_prim_moments_1x2v_ser_p1, gyrokinetic_cross_prim_moments_1x2v_ser_p2 + }, // 1 // 2x kernels - { NULL, gyrokinetic_cross_prim_moments_2x2v_ser_p1, gyrokinetic_cross_prim_moments_2x2v_ser_p2 }, // 2 + {NULL, gyrokinetic_cross_prim_moments_2x2v_ser_p1, gyrokinetic_cross_prim_moments_2x2v_ser_p2 + }, // 2 // 3x kernels - { NULL, gyrokinetic_cross_prim_moments_3x2v_ser_p1, gyrokinetic_cross_prim_moments_3x2v_ser_p2 }, // 3 + {NULL, gyrokinetic_cross_prim_moments_3x2v_ser_p1, gyrokinetic_cross_prim_moments_3x2v_ser_p2 + } // 3 }; struct prim_lbo_type_gyrokinetic { @@ -59,34 +69,37 @@ struct prim_lbo_type_gyrokinetic { */ void prim_lbo_gyrokinetic_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static void -self_prim(const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, - const int* idx, const double *moms, const double *boundary_corrections, const double *nu) +GKYL_CU_D static void self_prim( + const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, const int *idx, + const double *moms, const double *boundary_corrections, const double *nu +) { - struct prim_lbo_type_gyrokinetic *prim_gyrokinetic = container_of(prim, struct prim_lbo_type_gyrokinetic, prim); + struct prim_lbo_type_gyrokinetic *prim_gyrokinetic = + container_of(prim, struct prim_lbo_type_gyrokinetic, prim); return prim_gyrokinetic->self_prim(A, rhs, moms, boundary_corrections, nu); } -GKYL_CU_D -static void -cross_prim(const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, - const int *idx, const double *alpha_E, - const double m_self, const double *moms_self, const double *prim_moms_self, +GKYL_CU_D static void cross_prim( + const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, const int *idx, + const double *alpha_E, const double m_self, const double *moms_self, const double *prim_moms_self, const double m_other, const double *moms_other, const double *prim_moms_other, - const double *boundary_corrections, const double *nu) + const double *boundary_corrections, const double *nu +) { - struct prim_lbo_type_gyrokinetic *prim_gyrokinetic = container_of(prim, struct prim_lbo_type_gyrokinetic, prim); + struct prim_lbo_type_gyrokinetic *prim_gyrokinetic = + container_of(prim, struct prim_lbo_type_gyrokinetic, prim); - return prim_gyrokinetic->cross_prim(A, rhs, alpha_E, m_self, moms_self, prim_moms_self, - m_other, moms_other, prim_moms_other, boundary_corrections, nu); + return prim_gyrokinetic->cross_prim( + A, rhs, alpha_E, m_self, moms_self, prim_moms_self, m_other, moms_other, prim_moms_other, + boundary_corrections, nu + ); } #ifdef GKYL_HAVE_CUDA -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis); +struct gkyl_prim_lbo_type *gkyl_prim_lbo_gyrokinetic_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis +); #endif diff --git a/gyrokinetic/zero/gkyl_proj_exp_on_basis.h b/gyrokinetic/zero/gkyl_proj_exp_on_basis.h index 25dcc31a3d..e84b09b9a0 100644 --- a/gyrokinetic/zero/gkyl_proj_exp_on_basis.h +++ b/gyrokinetic/zero/gkyl_proj_exp_on_basis.h @@ -15,8 +15,8 @@ typedef struct gkyl_proj_exp_on_basis gkyl_proj_exp_on_basis; * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -gkyl_proj_exp_on_basis* gkyl_proj_exp_on_basis_new( - const struct gkyl_basis *basis, int num_quad, bool use_gpu); +gkyl_proj_exp_on_basis * +gkyl_proj_exp_on_basis_new(const struct gkyl_basis *basis, int num_quad, bool use_gpu); /** * Compute alpha*exp(beta*fIn) via quadrature. @@ -26,13 +26,14 @@ gkyl_proj_exp_on_basis* gkyl_proj_exp_on_basis_new( * @param fIn Input scalar field. * @param fOut Ouput scalar field. */ -void gkyl_proj_exp_on_basis_advance(const gkyl_proj_exp_on_basis *up, - const struct gkyl_range *range, double alpha, double beta, - const struct gkyl_array *fIn, struct gkyl_array *fOut); +void gkyl_proj_exp_on_basis_advance( + const gkyl_proj_exp_on_basis *up, const struct gkyl_range *range, double alpha, double beta, + const struct gkyl_array *fIn, struct gkyl_array *fOut +); /** * Delete updater. * * @param pob Updater to delete. */ -void gkyl_proj_exp_on_basis_release(gkyl_proj_exp_on_basis* up); +void gkyl_proj_exp_on_basis_release(gkyl_proj_exp_on_basis *up); diff --git a/gyrokinetic/zero/gkyl_proj_exp_on_basis_priv.h b/gyrokinetic/zero/gkyl_proj_exp_on_basis_priv.h index 023f57918a..7a1c2df680 100644 --- a/gyrokinetic/zero/gkyl_proj_exp_on_basis_priv.h +++ b/gyrokinetic/zero/gkyl_proj_exp_on_basis_priv.h @@ -14,10 +14,10 @@ struct gkyl_proj_exp_on_basis { struct gkyl_array *basis_at_ords; // conf-space basis functions at ordinates struct gkyl_array *fun_at_ords; // function (Maxwellian) evaluated at - // ordinates in a cell. + // ordinates in a cell. }; -void -gkyl_proj_exp_on_basis_advance_cu(const gkyl_proj_exp_on_basis *up, - const struct gkyl_range *range, double alpha, double beta, - const struct gkyl_array *fIn, struct gkyl_array *fOut); +void gkyl_proj_exp_on_basis_advance_cu( + const gkyl_proj_exp_on_basis *up, const struct gkyl_range *range, double alpha, double beta, + const struct gkyl_array *fIn, struct gkyl_array *fOut +); diff --git a/gyrokinetic/zero/gkyl_radiation_read.h b/gyrokinetic/zero/gkyl_radiation_read.h index 4b9534ba9c..5072c639b9 100644 --- a/gyrokinetic/zero/gkyl_radiation_read.h +++ b/gyrokinetic/zero/gkyl_radiation_read.h @@ -13,15 +13,15 @@ struct rad_fit_parameters { // D = A*(alpha+beta)/C // vmag = sqrt(vpar^2 + 2*B*mu/mass) // nu(vpar,mu) = D*vmag^(gamma)/(beta*(vmag/V0)^-alpha + alpha*(vmag/V0)^beta) - double electron_density; // Electron density at which this fit is at + double electron_density; // Electron density at which this fit is at double A; double alpha; double beta; double gamma; double V0; - int te_intervals; // Number of temperature intervals for fit emissivity - double *te; // electron temperatures at which the fit emissivity is calculated - double *Lz; // fit emissivity when assuming a maxwellian of corresponding temperature + int te_intervals; // Number of temperature intervals for fit emissivity + double *te; // electron temperatures at which the fit emissivity is calculated + double *Lz; // fit emissivity when assuming a maxwellian of corresponding temperature }; // Radiation data for a single charge state (for all electron densities). @@ -45,7 +45,7 @@ struct all_radiation_states { * * @return pointer to structure of all_radiation_states */ -struct all_radiation_states* gkyl_radiation_read_rad_fit_params(); +struct all_radiation_states *gkyl_radiation_read_rad_fit_params(); /** * Get the number of densities used in the fits. @@ -58,8 +58,10 @@ struct all_radiation_states* gkyl_radiation_read_rad_fit_params(); * @param num_densities: maximum number of densities to return fit parameters for. * @return 1 if fit doesn't exist */ -int gkyl_radiation_read_get_num_densities(const struct all_radiation_states rad_data, - int atomic_z, int charge_state, double min_ne, double max_ne, int *num_densities); +int gkyl_radiation_read_get_num_densities( + const struct all_radiation_states rad_data, int atomic_z, int charge_state, double min_ne, + double max_ne, int *num_densities +); /** * Function to return the fit information for a specfied atomic number, charge state, and ne. @@ -75,9 +77,11 @@ int gkyl_radiation_read_get_num_densities(const struct all_radiation_states rad_ * @param max_ne: Desired maximum density (closest density is used) * @return 1 if fit doesn't exist */ -int gkyl_radiation_read_get_fit_params(const struct all_radiation_states rad_data, int atomic_z, - int charge_state, double *a, double *alpha, double *beta, double *gamma, double *V0, - int *num_densities, double *electron_densities, double ref_dens, double min_ne, double max_ne); +int gkyl_radiation_read_get_fit_params( + const struct all_radiation_states rad_data, int atomic_z, int charge_state, double *a, + double *alpha, double *beta, double *gamma, double *V0, int *num_densities, + double *electron_densities, double ref_dens, double min_ne, double max_ne +); /** * Function to return the fit emissivity (Lz) and temperature closest to a given input temperature. @@ -89,8 +93,10 @@ int gkyl_radiation_read_get_fit_params(const struct all_radiation_states rad_dat * @param te: returns closest fit temperature to input te * @param Lz: returns Lz for closest temperature to input te */ -int gkyl_radiation_read_get_fit_lz(const struct all_radiation_states rad_data, - int atomic_z, int charge_state, double ne, double* te, double* Lz); +int gkyl_radiation_read_get_fit_lz( + const struct all_radiation_states rad_data, int atomic_z, int charge_state, double ne, double *te, + double *Lz +); /** * Free memory of all_radiation_states. @@ -105,16 +111,15 @@ void gkyl_radiation_read_release_fit_params(struct all_radiation_states *rad_dat * @param target The value to find the closest index to * @return The index of the array with the value closest to target */ -static inline int gkyl_radiation_read_find_nearest_idx(const struct gkyl_array* arr, double target){ +static inline int gkyl_radiation_read_find_nearest_idx(const struct gkyl_array *arr, double target) +{ int left = 0; int right = arr->size - 1; - double *data = (double*)arr->data; + double *data = (double *)arr->data; while (left < right) { - if (fabs(data[left] - target) - <= fabs(data[right] - target)) { + if (fabs(data[left] - target) <= fabs(data[right] - target)) { right--; - } - else { + } else { left++; } } diff --git a/gyrokinetic/zero/gkyl_rz_calc_derived_geo.h b/gyrokinetic/zero/gkyl_rz_calc_derived_geo.h index a36fb6075e..5a4db5724a 100644 --- a/gyrokinetic/zero/gkyl_rz_calc_derived_geo.h +++ b/gyrokinetic/zero/gkyl_rz_calc_derived_geo.h @@ -17,8 +17,9 @@ typedef struct gkyl_rz_calc_derived_geo gkyl_rz_calc_derived_geo; * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -gkyl_rz_calc_derived_geo* gkyl_rz_calc_derived_geo_new(const struct gkyl_basis *cbasis, - const struct gkyl_rect_grid *grid, int node_type, bool use_gpu); +gkyl_rz_calc_derived_geo *gkyl_rz_calc_derived_geo_new( + const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, int node_type, bool use_gpu +); /** * Advance rz_calc_derived_geo (compute the derived_geo coefficients). @@ -37,14 +38,17 @@ gkyl_rz_calc_derived_geo* gkyl_rz_calc_derived_geo_new(const struct gkyl_basis * * @param gxzj output field with DG rep of Jg^xz * @param eps2 output field with DG rep of eps2 = Jg^33 - J/g_33 */ -void gkyl_rz_calc_derived_geo_advance(const gkyl_rz_calc_derived_geo *up, const struct gkyl_range *crange, - struct gkyl_array *g_ij, struct gkyl_array *bmag, struct gkyl_array *jacobgeo, struct gkyl_array *jacobgeo_inv, - struct gkyl_array *gij, struct gkyl_array *b_i, struct gkyl_array *cmag, struct gkyl_array *jacobtot, struct gkyl_array *jacobtot_inv, - struct gkyl_array *gxxj, struct gkyl_array *gxyj, struct gkyl_array *gyyj, struct gkyl_array *gxzj, struct gkyl_array *eps2); +void gkyl_rz_calc_derived_geo_advance( + const gkyl_rz_calc_derived_geo *up, const struct gkyl_range *crange, struct gkyl_array *g_ij, + struct gkyl_array *bmag, struct gkyl_array *jacobgeo, struct gkyl_array *jacobgeo_inv, + struct gkyl_array *gij, struct gkyl_array *b_i, struct gkyl_array *cmag, + struct gkyl_array *jacobtot, struct gkyl_array *jacobtot_inv, struct gkyl_array *gxxj, + struct gkyl_array *gxyj, struct gkyl_array *gyyj, struct gkyl_array *gxzj, struct gkyl_array *eps2 +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_rz_calc_derived_geo_release(gkyl_rz_calc_derived_geo* up); +void gkyl_rz_calc_derived_geo_release(gkyl_rz_calc_derived_geo *up); diff --git a/gyrokinetic/zero/gkyl_rz_calc_derived_geo_priv.h b/gyrokinetic/zero/gkyl_rz_calc_derived_geo_priv.h index c4b89d5661..a915a45795 100644 --- a/gyrokinetic/zero/gkyl_rz_calc_derived_geo_priv.h +++ b/gyrokinetic/zero/gkyl_rz_calc_derived_geo_priv.h @@ -3,55 +3,51 @@ #include #include -typedef void (*rz_derived_geo_kernel)(const double *gij, const double *bmag, const double *J, double *Jinv, - double *grij, double *bi, double *cmag, double *Jtot, double *Jtotinv, double *gxxJ, double *gxyJ, double *gyyJ, - double *gxzJ, double *eps2); - -typedef struct { rz_derived_geo_kernel kernels[3]; } rz_derived_geo_kernel_list; // For use in kernel tables. -typedef struct { rz_derived_geo_kernel_list list[4]; } rz_derived_geo_node_list; // For use in kernel tables. - -GKYL_CU_DH -static const rz_derived_geo_node_list ser_rz_derived_geo_kernel_list[] = { - { .list = { - { NULL, NULL, NULL }, // 0x No 0D basis functions - { NULL, NULL, NULL}, // 1x Not tested yet - { NULL, NULL, NULL}, // 2x Not tested yet - { NULL, rz_derived_geo_3x_Ser_p1, rz_derived_geo_3x_Ser_p2} - } - }, - { .list = { - { NULL, NULL, NULL }, // 0x No 0D basis functions - { NULL, NULL, NULL}, // 1x Not tested yet - { NULL, NULL, NULL}, // 2x Not tested yet - { NULL, rz_derived_geo_quad_3x_Ser_p1, NULL} - } - }, +typedef void (*rz_derived_geo_kernel)( + const double *gij, const double *bmag, const double *J, double *Jinv, double *grij, double *bi, + double *cmag, double *Jtot, double *Jtotinv, double *gxxJ, double *gxyJ, double *gyyJ, + double *gxzJ, double *eps2 +); + +typedef struct { + rz_derived_geo_kernel kernels[3]; +} rz_derived_geo_kernel_list; // For use in kernel tables. +typedef struct { + rz_derived_geo_kernel_list list[4]; +} rz_derived_geo_node_list; // For use in kernel tables. + +GKYL_CU_DH static const rz_derived_geo_node_list ser_rz_derived_geo_kernel_list[] = { + {.list = + {{NULL, NULL, NULL}, // 0x No 0D basis functions + {NULL, NULL, NULL}, // 1x Not tested yet + {NULL, NULL, NULL}, // 2x Not tested yet + {NULL, rz_derived_geo_3x_Ser_p1, rz_derived_geo_3x_Ser_p2}}}, + {.list = + {{NULL, NULL, NULL}, // 0x No 0D basis functions + {NULL, NULL, NULL}, // 1x Not tested yet + {NULL, NULL, NULL}, // 2x Not tested yet + {NULL, rz_derived_geo_quad_3x_Ser_p1, NULL}}} }; -struct gkyl_rz_calc_derived_geo{ +struct gkyl_rz_calc_derived_geo { unsigned cdim; // Configuration-space dimension. unsigned cnum_basis; // Number of conf-space basis functions. unsigned poly_order; // Polynomial order of the basis. struct gkyl_basis cbasis; // configuration space basis - const struct gkyl_rect_grid* grid; + const struct gkyl_rect_grid *grid; bool use_gpu; rz_derived_geo_kernel kernel; }; -GKYL_CU_DH -static rz_derived_geo_kernel +GKYL_CU_DH static rz_derived_geo_kernel rz_derived_geo_choose_kernel(int dim, int basis_type, int node_type, int poly_order) { switch (basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_rz_derived_geo_kernel_list[node_type].list[dim].kernels[poly_order]; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_rz_derived_geo_kernel_list[node_type].list[dim].kernels[poly_order]; + default: + assert(false); + break; } } - - - - diff --git a/gyrokinetic/zero/gkyl_tok_geo.h b/gyrokinetic/zero/gkyl_tok_geo.h index 3fe462978c..5f3ef5b433 100644 --- a/gyrokinetic/zero/gkyl_tok_geo.h +++ b/gyrokinetic/zero/gkyl_tok_geo.h @@ -13,16 +13,15 @@ #include #include - typedef struct gk_geometry gk_geometry; // Some cumulative statistics struct gkyl_tok_geo_stat { long nquad_cont_calls; // num calls from quadrature long nroot_cont_calls; // num calls from root-finder -}; +}; -typedef void (*plate_func)(double s, double* RZ); +typedef void (*plate_func)(double s, double *RZ); // Type of flux surface enum gkyl_tok_geo_type { @@ -34,13 +33,13 @@ enum gkyl_tok_geo_type { GKYL_GEOMETRY_TOKAMAK_CORE, // Full core // 6 SOL Block Types for DN multi-block simulations - GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, // Section of outboard SOL below lower xpt + GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO, // Section of outboard SOL below lower xpt GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID, // Section of outboard SOL between xpts - GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, // Section of outboard SOL above upper xpt - GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO, // Section of inboard SOL below lower xpt - GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID, // Section of inboard SOL between xpts - GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP, // Section of inboard SOL above upper xpt - + GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP, // Section of outboard SOL above upper xpt + GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO, // Section of inboard SOL below lower xpt + GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID, // Section of inboard SOL between xpts + GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP, // Section of inboard SOL above upper xpt + // 3 SOL Block Types for LSN multi-block simulations GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO, // Outboard divertor leg of LSN GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID, // Middle portion of LSN SOL between X-points @@ -52,15 +51,15 @@ enum gkyl_tok_geo_type { GKYL_GEOMETRY_TOKAMAK_PF_LO_L, // Left half of Private flux region at bottom (lower xpt to inboard lower plate) GKYL_GEOMETRY_TOKAMAK_PF_LO_R, // Right half of Private flux region at bottom (outboard lower plate to lower xpt) - // Core Block types that can be used with SN or DN configurations in multi-block simulations + // Core Block types that can be used with SN or DN configurations in multi-block simulations GKYL_GEOMETRY_TOKAMAK_CORE_L, // Left half of core (lower to upper xpt) GKYL_GEOMETRY_TOKAMAK_CORE_R, // Right half of core (upper to lower xpt) - GKYL_GEOMETRY_TOKAMAK_IWL, // Inner Wall Limited -}; + GKYL_GEOMETRY_TOKAMAK_IWL // Inner Wall Limited +}; struct gkyl_tok_geo { - struct gkyl_efit* efit; + struct gkyl_efit *efit; struct gkyl_rect_grid rzgrid; // RZ grid on which psi(R,Z) is defined struct gkyl_range rzlocal; // local range over which psiRZ is defined @@ -73,15 +72,15 @@ struct gkyl_tok_geo { int num_rzbasis; // number of basis functions in RZ const struct gkyl_array *psiRZ; // psi(R,Z) DG representation const struct gkyl_array *psiRZ_cubic; // cubic psi(R,Z) DG representation - struct gkyl_basis_ops_evalf *evf ; // wrapper for cubic evaluation - + struct gkyl_basis_ops_evalf *evf; // wrapper for cubic evaluation + struct gkyl_rect_grid fgrid; // flux grid for fpol struct gkyl_range frange; // flux range struct gkyl_range frange_ext; // extended range struct gkyl_basis fbasis; // psi basis for fpol const struct gkyl_array *fpoldg; // fpol(psi) dg rep const struct gkyl_array *fpolprimedg; // fpol'(psi) dg rep - const struct gkyl_array *qdg; // q(psi) dg rep + const struct gkyl_array *qdg; // q(psi) dg rep double sibry; // psi of separatrix as given by EFIT double psisep; // psi of separatrix as calculated from the DG psi(R,Z) @@ -89,7 +88,7 @@ struct gkyl_tok_geo { // rleft : If you are in a circular kind of region (like a single null SOL or the core) and // theta is greater than theta of the upper turning point (so we have already traced the // entire right half of the surface), nodes/roots with R closest to rleft will be chosen. - double rleft; + double rleft; double rright; // rmin : No root with R < rmin will ever be chosen. rmin is interpreted as maybe a machine // boundary. So, no node will be placed at r < rmin. @@ -105,39 +104,44 @@ struct gkyl_tok_geo { plate_func plate_func_lower; plate_func plate_func_upper; - struct { int max_iter; double eps; } root_param; - struct { int max_level; double eps; } quad_param; + struct { + int max_iter; + double eps; + } root_param; + struct { + int max_level; + double eps; + } quad_param; bool inexact_roots; // If true we will allow approximate roots when no root is found bool use_cubics; // If true will use the cubic rep of psi rather than the quadratic representation - bool use_hyperbolic_numbers; // If true will use the hyperbolic numbers to do cubic root finding (much faster) + bool + use_hyperbolic_numbers; // If true will use the hyperbolic numbers to do cubic root finding (much faster) // pointer to root finder (depends on polyorder) - struct RdRdZ_sol (*calc_roots)(const double *psi, double psi0, double Z, - double xc[2], double dx[2]); + struct RdRdZ_sol (*calc_roots)( + const double *psi, double psi0, double Z, double xc[2], double dx[2] + ); double (*calc_grad_psi)(const double *psih, const double eta[2], const double dx[2]); - struct gkyl_tok_geo_stat stat; - struct gkyl_array* mc2p_nodal_fd; - struct gkyl_range* nrange; - double* dzc; + struct gkyl_tok_geo_stat stat; + struct gkyl_array *mc2p_nodal_fd; + struct gkyl_range *nrange; + double *dzc; }; - - // Inputs to create a new GK geometry creation object - // Inputs to create geometry for a specific computational grid struct gkyl_tok_geo_grid_inp { struct gkyl_rect_grid cgrid; struct gkyl_basis cbasis; enum gkyl_tok_geo_type ftype; // type of geometry bool half_domain; // For use in double null simulations - // If true, will set the domain to be the lower - // half of the tokamak (below Z=0) - + // If true, will set the domain to be the lower + // half of the tokamak (below Z=0) + double rclose; // closest R to region of interest to discriminate double rleft; // closest R to inboard SOL double rright; // closest R to outboard SOL @@ -150,12 +154,13 @@ struct gkyl_tok_geo_grid_inp { bool plate_spec; // whether a shape function is provided for divertor plates plate_func plate_func_lower; // lower plate specification. Gives R,Z in terms of s \in [0,1] plate_func plate_func_upper; // upper plate specification. Gives R,Z in terms of s \in [0,1] - // In a lower single null "lower" is the outer divertor and - // "upper" is the inner divertor + // In a lower single null "lower" is the outer divertor and + // "upper" is the inner divertor bool inexact_roots; // If true we will allow approximate roots when no root is found bool use_cubics; // If true will use the cubic rep of psi rather than the quadratic representation - bool use_hyperbolic_numbers; // If true will use the hyperbolic numbers to do cubic root finding (much faster) + bool + use_hyperbolic_numbers; // If true will use the hyperbolic numbers to do cubic root finding (much faster) // Parameters for root finder: leave unset to use defaults struct { @@ -164,12 +169,11 @@ struct gkyl_tok_geo_grid_inp { } root_param; // Parameters for nmumerical quadrature: leave unset to use default struct { - int max_levels; // typically 6-7 + int max_levels; // typically 6-7 double eps; // typically 1e-10 } quad_param; }; - /** * Create new updater to compute the geometry needed in GK * simulations. @@ -177,7 +181,8 @@ struct gkyl_tok_geo_grid_inp { * @param efit_inp Input parameters related to EFIT data * @param grid_inp Input parameters related to computational grid */ -struct gkyl_tok_geo *gkyl_tok_geo_new(const struct gkyl_efit_inp *inp, const struct gkyl_tok_geo_grid_inp *grid_inp); +struct gkyl_tok_geo * +gkyl_tok_geo_new(const struct gkyl_efit_inp *inp, const struct gkyl_tok_geo_grid_inp *grid_inp); /** * Get R(psi,Z) for a specified psi and Z value. Multiple values may @@ -191,8 +196,10 @@ struct gkyl_tok_geo *gkyl_tok_geo_new(const struct gkyl_efit_inp *inp, const str * @param R on output, R(psi,Z) * @param dR on output, dR/dZ */ -int gkyl_tok_geo_R_psiZ(const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, - double *R, double *dRdZ, double *dR, double *dZ); +int gkyl_tok_geo_R_psiZ( + const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, double *R, double *dRdZ, + double *dR, double *dZ +); /** * Integrate along a specified psi countour and return its length. The @@ -210,8 +217,9 @@ int gkyl_tok_geo_R_psiZ(const struct gkyl_tok_geo *geo, double psi, double Z, in * contours * @return Length of contour */ -double gkyl_tok_geo_integrate_psi_contour(const struct gkyl_tok_geo *geo, double psi, - double zmin, double zmax, double rclose); +double gkyl_tok_geo_integrate_psi_contour( + const struct gkyl_tok_geo *geo, double psi, double zmin, double zmax, double rclose +); /** * Compute physical coordinates (mapc2p) given computational coordinates @@ -220,8 +228,10 @@ double gkyl_tok_geo_integrate_psi_contour(const struct gkyl_tok_geo *geo, double * @param xn computational coordinates * @param ret physical coordinates */ -void gkyl_tok_geo_mapc2p(const struct gkyl_tok_geo *geo, const struct gkyl_tok_geo_grid_inp *inp, - const double *xn, double *ret); +void gkyl_tok_geo_mapc2p( + const struct gkyl_tok_geo *geo, const struct gkyl_tok_geo_grid_inp *inp, const double *xn, + double *ret +); /** * Compute geometry (mapc2p) on a specified computational grid. @@ -233,8 +243,10 @@ void gkyl_tok_geo_mapc2p(const struct gkyl_tok_geo *geo, const struct gkyl_tok_g * @param inp tok_geo_grid_inp Input structure for creating mapc2p * @param position_map position map object */ -void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, - struct gkyl_tok_geo* geo, struct gkyl_tok_geo_grid_inp *inp, struct gkyl_position_map *position_map); +void gkyl_tok_geo_calc( + struct gk_geometry *up, struct gkyl_range *nrange, struct gkyl_tok_geo *geo, + struct gkyl_tok_geo_grid_inp *inp, struct gkyl_position_map *position_map +); /** * Compute geometry (mapc2p) on a specified computational grid. @@ -246,8 +258,10 @@ void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, * @param inp tok_geo_grid_inp Input structure for creating mapc2p * @param position_map position map object */ -void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrange, double dzc[3], - struct gkyl_tok_geo* geo, struct gkyl_tok_geo_grid_inp *inp, struct gkyl_position_map *position_map); +void gkyl_tok_geo_calc_interior( + struct gk_geometry *up, struct gkyl_range *nrange, double dzc[3], struct gkyl_tok_geo *geo, + struct gkyl_tok_geo_grid_inp *inp, struct gkyl_position_map *position_map +); /** * Compute geometry (mapc2p) on a specified computational grid. @@ -259,9 +273,11 @@ void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrang * @param inp tok_geo_grid_inp Input structure for creating mapc2p * @param position_map position map object */ -void gkyl_tok_geo_calc_surface(struct gk_geometry* up, int dir, struct gkyl_range *nrange, double dzc[3], - struct gkyl_tok_geo* geo, struct gkyl_tok_geo_grid_inp *inp, struct gkyl_position_map *position_map); - +void gkyl_tok_geo_calc_surface( + struct gk_geometry *up, int dir, struct gkyl_range *nrange, double dzc[3], + struct gkyl_tok_geo *geo, struct gkyl_tok_geo_grid_inp *inp, + struct gkyl_position_map *position_map +); /* * Get grid extents for a block type based on a global normalization factor @@ -271,8 +287,9 @@ void gkyl_tok_geo_calc_surface(struct gk_geometry* up, int dir, struct gkyl_rang * @param theta_lo on output the lower grid extent * @param theta_up on output the upper grid extent * */ -void -gkyl_tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, double *theta_lo, double *theta_up); +void gkyl_tok_geo_set_extent( + struct gkyl_tok_geo_grid_inp *inp, struct gkyl_tok_geo *geo, double *theta_lo, double *theta_up +); /** * Return cumulative statistics from geometry computations diff --git a/gyrokinetic/zero/gkyl_tok_geo_priv.h b/gyrokinetic/zero/gkyl_tok_geo_priv.h index 7a768f4ad2..5421a8467f 100644 --- a/gyrokinetic/zero/gkyl_tok_geo_priv.h +++ b/gyrokinetic/zero/gkyl_tok_geo_priv.h @@ -19,7 +19,7 @@ struct arc_length_ctx { double arcL_left; // this is for when we need to switch sides double arcL_tot; // total arc length double arcL_start; // For core bloks only. arc length between theta=0 and lower turning point - // measured counterclockwise from left side + // measured counterclockwise from left side double phi_right; // this is for when we need to switch sides double phi_left; // this is for when we need to switch sides double phi_bot; // For new way of trying to do core @@ -34,23 +34,21 @@ struct arc_length_ctx { enum gkyl_tok_geo_type ftype; // type of geometry }; - // Context to pass to endpoint finder -struct plate_ctx{ - const struct gkyl_tok_geo* geo; +struct plate_ctx { + const struct gkyl_tok_geo *geo; double psi_curr; bool lower; }; // some helper functions -static double -choose_closest(double ref, double* R, double* out, int nr) +static double choose_closest(double ref, double *R, double *out, int nr) { //return fabs(R[0]-ref) < fabs(R[1]-ref) ? out[0] : out[1]; int imin = 0; - double min = fabs(R[0]-ref); - for(int i = 1; i< nr; i++){ - if( fabs(R[i] - ref) < min){ + double min = fabs(R[0] - ref); + for (int i = 1; i < nr; i++) { + if (fabs(R[i] - ref) < min) { imin = i; min = fabs(R[i] - ref); } @@ -58,18 +56,33 @@ choose_closest(double ref, double* R, double* out, int nr) return out[imin]; } -static inline double SQ(double x) { return x*x; } -static inline double CUB(double x) { return x*x*x; } -static inline double complex cSQ(double complex x) { return cpow(x,2.0+0.0*I); } -static double complex cCUB(double complex x) { return cpow(x,3.0+0.0*I); } -static double complex croot(double complex x, double n) { double complex power = 1.0/n + 0.0*I; return cpow(x,power); } - +static inline double SQ(double x) +{ + return x * x; +} +static inline double CUB(double x) +{ + return x * x * x; +} +static inline double complex cSQ(double complex x) +{ + return cpow(x, 2.0 + 0.0 * I); +} +static double complex cCUB(double complex x) +{ + return cpow(x, 3.0 + 0.0 * I); +} +static double complex croot(double complex x, double n) +{ + double complex power = 1.0 / n + 0.0 * I; + return cpow(x, power); +} static inline int get_idx(int dir, double x, const struct gkyl_rect_grid *grid, const struct gkyl_range *range) { double xlower = grid->lower[dir], dx = grid->dx[dir]; - int idx = range->lower[dir] + (int) floor((x-xlower)/dx); + int idx = range->lower[dir] + (int)floor((x - xlower) / dx); return idx <= range->upper[dir] ? idx : range->upper[dir]; } @@ -85,18 +98,22 @@ struct RdRdZ_sol { static inline struct RdRdZ_sol calc_RdR_p1(const double *psi, double psi0, double Z, double xc[2], double dx[2]) { - struct RdRdZ_sol sol = { .nsol = 0 }; + struct RdRdZ_sol sol = {.nsol = 0}; - double y = (Z-xc[1])/(dx[1]*0.5); - - double rnorm = (-(1.732050807568877*psi[2]*y)/(3.0*psi[3]*y+1.732050807568877*psi[1]))+(2.0*psi0)/(3.0*psi[3]*y+1.732050807568877*psi[1])-(1.0*psi[0])/(3.0*psi[3]*y+1.732050807568877*psi[1]) ; + double y = (Z - xc[1]) / (dx[1] * 0.5); + + double rnorm = + (-(1.732050807568877 * psi[2] * y) / (3.0 * psi[3] * y + 1.732050807568877 * psi[1])) + + (2.0 * psi0) / (3.0 * psi[3] * y + 1.732050807568877 * psi[1]) - + (1.0 * psi[0]) / (3.0 * psi[3] * y + 1.732050807568877 * psi[1]); + + if ((-1 <= rnorm) && (rnorm < 1)) { + double drdznorm = -(3.0 * (2.0 * psi[3] * psi0 - 1.0 * psi[0] * psi[3] + psi[1] * psi[2])) / + SQ(3.0 * psi[3] * y + 1.732050807568877 * psi[1]); - if ((-1<=rnorm) && (rnorm < 1)) { - double drdznorm = -(3.0*(2.0*psi[3]*psi0-1.0*psi[0]*psi[3]+psi[1]*psi[2]))/SQ(3.0*psi[3]*y+1.732050807568877*psi[1]) ; - sol.nsol = 1; - sol.R[0] = rnorm*dx[0]*0.5 + xc[0]; - sol.dRdZ[0] = drdznorm*dx[0]/dx[1]; + sol.R[0] = rnorm * dx[0] * 0.5 + xc[0]; + sol.dRdZ[0] = drdznorm * dx[0] / dx[1]; } return sol; } @@ -105,49 +122,68 @@ calc_RdR_p1(const double *psi, double psi0, double Z, double xc[2], double dx[2] static inline struct RdRdZ_sol calc_RdR_p2_tensor(const double *psi, double psi0, double Z, double xc[2], double dx[2]) { - struct RdRdZ_sol sol = { .nsol = 0 }; - double y = (Z-xc[1])/(dx[1]*0.5); + struct RdRdZ_sol sol = {.nsol = 0}; + double y = (Z - xc[1]) / (dx[1] * 0.5); - double aq = 0.125*(45.0*psi[8]*SQ(y)+23.2379000772445*psi[6]*y-15.0*psi[8]+13.41640786499874*psi[4]); - double bq = 0.125*(23.2379000772445*psi[7]*SQ(y)+12.0*psi[3]*y-7.745966692414834*psi[7]+6.928203230275509*psi[1]) ; - double cq = 0.125*((13.41640786499874*psi[5]-15.0*psi[8])*SQ(y)+(6.928203230275509*psi[2]-7.745966692414834*psi[6])*y+5.0*psi[8]- 4.47213595499958*psi[5]-4.47213595499958*psi[4]+4.0*psi[0] ) - psi0; + double aq = 0.125 * (45.0 * psi[8] * SQ(y) + 23.2379000772445 * psi[6] * y - 15.0 * psi[8] + + 13.41640786499874 * psi[4]); + double bq = 0.125 * (23.2379000772445 * psi[7] * SQ(y) + 12.0 * psi[3] * y - + 7.745966692414834 * psi[7] + 6.928203230275509 * psi[1]); + double cq = + 0.125 * ((13.41640786499874 * psi[5] - 15.0 * psi[8]) * SQ(y) + + (6.928203230275509 * psi[2] - 7.745966692414834 * psi[6]) * y + 5.0 * psi[8] - + 4.47213595499958 * psi[5] - 4.47213595499958 * psi[4] + 4.0 * psi[0]) - + psi0; - double delta2 = bq*bq - 4*aq*cq; + double delta2 = bq * bq - 4 * aq * cq; if (delta2 > 0) { double r1, r2; double delta = sqrt(delta2); // compute both roots - if (bq>=0) { - r1 = (-bq-delta)/(2*aq); - r2 = 2*cq/(-bq-delta); - } - else { - r1 = 2*cq/(-bq+delta); - r2 = (-bq+delta)/(2*aq); + if (bq >= 0) { + r1 = (-bq - delta) / (2 * aq); + r2 = 2 * cq / (-bq - delta); + } else { + r1 = 2 * cq / (-bq + delta); + r2 = (-bq + delta) / (2 * aq); } int sidx = 0; - if ((-1<=r1) && (r1 < 1)) { + if ((-1 <= r1) && (r1 < 1)) { sol.nsol += 1; - sol.R[sidx] = r1*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r1 * dx[0] * 0.5 + xc[0]; double x = r1; - double C = 0.125*(SQ(x)*(90.0*psi[8]*y+23.2379000772445*psi[6])+x*(46.47580015448901*psi[7]*y+12.0*psi[3])+2* (13.41640786499874*psi[5]-15.0*psi[8])*y-7.745966692414834*psi[6]+6.928203230275509*psi[2]) ; - double A = 0.125*(2*x*(45.0*psi[8]*SQ(y)+23.2379000772445*psi[6]*y-15.0*psi[8]+13.41640786499874*psi[4])+23.2379000772445*psi[7]*SQ(y)+12.0*psi[3]*y-7.745966692414834*psi[7]+6.928203230275509*psi[1]); - sol.dRdZ[sidx] = -C/A*dx[0]/dx[1]; - + double C = 0.125 * (SQ(x) * (90.0 * psi[8] * y + 23.2379000772445 * psi[6]) + + x * (46.47580015448901 * psi[7] * y + 12.0 * psi[3]) + + 2 * (13.41640786499874 * psi[5] - 15.0 * psi[8]) * y - + 7.745966692414834 * psi[6] + 6.928203230275509 * psi[2]); + double A = 0.125 * (2 * x * + (45.0 * psi[8] * SQ(y) + 23.2379000772445 * psi[6] * y - 15.0 * psi[8] + + 13.41640786499874 * psi[4]) + + 23.2379000772445 * psi[7] * SQ(y) + 12.0 * psi[3] * y - + 7.745966692414834 * psi[7] + 6.928203230275509 * psi[1]); + sol.dRdZ[sidx] = -C / A * dx[0] / dx[1]; + sidx += 1; } - if ((-1<=r2) && (r2 < 1)) { + if ((-1 <= r2) && (r2 < 1)) { sol.nsol += 1; - sol.R[sidx] = r2*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r2 * dx[0] * 0.5 + xc[0]; double x = r2; - double C = 0.125*(SQ(x)*(90.0*psi[8]*y+23.2379000772445*psi[6])+x*(46.47580015448901*psi[7]*y+12.0*psi[3])+2* (13.41640786499874*psi[5]-15.0*psi[8])*y-7.745966692414834*psi[6]+6.928203230275509*psi[2]) ; - double A = 0.125*(2*x*(45.0*psi[8]*SQ(y)+23.2379000772445*psi[6]*y-15.0*psi[8]+13.41640786499874*psi[4])+23.2379000772445*psi[7]*SQ(y)+12.0*psi[3]*y-7.745966692414834*psi[7]+6.928203230275509*psi[1]); - sol.dRdZ[sidx] = -C/A*dx[0]/dx[1]; - + double C = 0.125 * (SQ(x) * (90.0 * psi[8] * y + 23.2379000772445 * psi[6]) + + x * (46.47580015448901 * psi[7] * y + 12.0 * psi[3]) + + 2 * (13.41640786499874 * psi[5] - 15.0 * psi[8]) * y - + 7.745966692414834 * psi[6] + 6.928203230275509 * psi[2]); + double A = 0.125 * (2 * x * + (45.0 * psi[8] * SQ(y) + 23.2379000772445 * psi[6] * y - 15.0 * psi[8] + + 13.41640786499874 * psi[4]) + + 23.2379000772445 * psi[7] * SQ(y) + 12.0 * psi[3] * y - + 7.745966692414834 * psi[7] + 6.928203230275509 * psi[1]); + sol.dRdZ[sidx] = -C / A * dx[0] / dx[1]; + sidx += 1; } } @@ -159,48 +195,68 @@ calc_RdR_p2_tensor(const double *psi, double psi0, double Z, double xc[2], doubl static inline struct RdRdZ_sol calc_RdR_p2_tensor_nrc(const double *psi, double psi0, double Z, double xc[2], double dx[2]) { - struct RdRdZ_sol sol = { .nsol = 0 }; - double y = (Z-xc[1])/(dx[1]*0.5); + struct RdRdZ_sol sol = {.nsol = 0}; + double y = (Z - xc[1]) / (dx[1] * 0.5); - double aq = 0.125*(45.0*psi[8]*SQ(y)+23.2379000772445*psi[6]*y-15.0*psi[8]+13.41640786499874*psi[4]); - double bq = 0.125*(23.2379000772445*psi[7]*SQ(y)+12.0*psi[3]*y-7.745966692414834*psi[7]+6.928203230275509*psi[1]) ; - double cq = 0.125*((13.41640786499874*psi[5]-15.0*psi[8])*SQ(y)+(6.928203230275509*psi[2]-7.745966692414834*psi[6])*y+5.0*psi[8]- 4.47213595499958*psi[5]-4.47213595499958*psi[4]+4.0*psi[0] ) - psi0; + double aq = 0.125 * (45.0 * psi[8] * SQ(y) + 23.2379000772445 * psi[6] * y - 15.0 * psi[8] + + 13.41640786499874 * psi[4]); + double bq = 0.125 * (23.2379000772445 * psi[7] * SQ(y) + 12.0 * psi[3] * y - + 7.745966692414834 * psi[7] + 6.928203230275509 * psi[1]); + double cq = + 0.125 * ((13.41640786499874 * psi[5] - 15.0 * psi[8]) * SQ(y) + + (6.928203230275509 * psi[2] - 7.745966692414834 * psi[6]) * y + 5.0 * psi[8] - + 4.47213595499958 * psi[5] - 4.47213595499958 * psi[4] + 4.0 * psi[0]) - + psi0; - double delta2 = bq*bq - 4*aq*cq; + double delta2 = bq * bq - 4 * aq * cq; if (delta2 > 0) { double r1, r2; double delta = sqrt(delta2); //// compute both roots - double qq = -0.5*(bq + (bq/fabs(bq)) * delta); - r1 = qq/aq; - r2 = cq/qq; + double qq = -0.5 * (bq + (bq / fabs(bq)) * delta); + r1 = qq / aq; + r2 = cq / qq; int sidx = 0; - if ((-1<=r1) && (r1 < 1)) { + if ((-1 <= r1) && (r1 < 1)) { sol.nsol += 1; - sol.R[sidx] = r1*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r1 * dx[0] * 0.5 + xc[0]; double x = r1; - double C = 0.125*(SQ(x)*(90.0*psi[8]*y+23.2379000772445*psi[6])+x*(46.47580015448901*psi[7]*y+12.0*psi[3])+2* (13.41640786499874*psi[5]-15.0*psi[8])*y-7.745966692414834*psi[6]+6.928203230275509*psi[2]) ; - double A = 0.125*(2*x*(45.0*psi[8]*SQ(y)+23.2379000772445*psi[6]*y-15.0*psi[8]+13.41640786499874*psi[4])+23.2379000772445*psi[7]*SQ(y)+12.0*psi[3]*y-7.745966692414834*psi[7]+6.928203230275509*psi[1]); - sol.dRdZ[sidx] = -C/A*dx[0]/dx[1]; - sol.dR[sidx] = -C*dx[0]; - sol.dZ[sidx] = A*dx[1]; - + double C = 0.125 * (SQ(x) * (90.0 * psi[8] * y + 23.2379000772445 * psi[6]) + + x * (46.47580015448901 * psi[7] * y + 12.0 * psi[3]) + + 2 * (13.41640786499874 * psi[5] - 15.0 * psi[8]) * y - + 7.745966692414834 * psi[6] + 6.928203230275509 * psi[2]); + double A = 0.125 * (2 * x * + (45.0 * psi[8] * SQ(y) + 23.2379000772445 * psi[6] * y - 15.0 * psi[8] + + 13.41640786499874 * psi[4]) + + 23.2379000772445 * psi[7] * SQ(y) + 12.0 * psi[3] * y - + 7.745966692414834 * psi[7] + 6.928203230275509 * psi[1]); + sol.dRdZ[sidx] = -C / A * dx[0] / dx[1]; + sol.dR[sidx] = -C * dx[0]; + sol.dZ[sidx] = A * dx[1]; + sidx += 1; } - if ((-1<=r2) && (r2 < 1)) { + if ((-1 <= r2) && (r2 < 1)) { sol.nsol += 1; - sol.R[sidx] = r2*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r2 * dx[0] * 0.5 + xc[0]; double x = r2; - double C = 0.125*(SQ(x)*(90.0*psi[8]*y+23.2379000772445*psi[6])+x*(46.47580015448901*psi[7]*y+12.0*psi[3])+2* (13.41640786499874*psi[5]-15.0*psi[8])*y-7.745966692414834*psi[6]+6.928203230275509*psi[2]) ; - double A = 0.125*(2*x*(45.0*psi[8]*SQ(y)+23.2379000772445*psi[6]*y-15.0*psi[8]+13.41640786499874*psi[4])+23.2379000772445*psi[7]*SQ(y)+12.0*psi[3]*y-7.745966692414834*psi[7]+6.928203230275509*psi[1]); - sol.dRdZ[sidx] = -C/A*dx[0]/dx[1]; - sol.dR[sidx] = -C*dx[0]; - sol.dZ[sidx] = A*dx[1]; - + double C = 0.125 * (SQ(x) * (90.0 * psi[8] * y + 23.2379000772445 * psi[6]) + + x * (46.47580015448901 * psi[7] * y + 12.0 * psi[3]) + + 2 * (13.41640786499874 * psi[5] - 15.0 * psi[8]) * y - + 7.745966692414834 * psi[6] + 6.928203230275509 * psi[2]); + double A = 0.125 * (2 * x * + (45.0 * psi[8] * SQ(y) + 23.2379000772445 * psi[6] * y - 15.0 * psi[8] + + 13.41640786499874 * psi[4]) + + 23.2379000772445 * psi[7] * SQ(y) + 12.0 * psi[3] * y - + 7.745966692414834 * psi[7] + 6.928203230275509 * psi[1]); + sol.dRdZ[sidx] = -C / A * dx[0] / dx[1]; + sol.dR[sidx] = -C * dx[0]; + sol.dZ[sidx] = A * dx[1]; + sidx += 1; } } @@ -208,36 +264,50 @@ calc_RdR_p2_tensor_nrc(const double *psi, double psi0, double Z, double xc[2], d } // Compute roots R(psi,Z) and dR/dZ(psi,Z) in a p=2 DG cell with tensor basis if delta2 is negative but very small -static inline struct RdRdZ_sol -calc_RdR_p2_tensor_with_tolerance(const double *psi, double psi0, double Z, double xc[2], double dx[2]) +static inline struct RdRdZ_sol calc_RdR_p2_tensor_with_tolerance( + const double *psi, double psi0, double Z, double xc[2], double dx[2] +) { - struct RdRdZ_sol sol = { .nsol = 0 }; - double y = (Z-xc[1])/(dx[1]*0.5); - - double aq = 0.125*(45.0*psi[8]*SQ(y)+23.2379000772445*psi[6]*y-15.0*psi[8]+13.41640786499874*psi[4]); - double bq = 0.125*(23.2379000772445*psi[7]*SQ(y)+12.0*psi[3]*y-7.745966692414834*psi[7]+6.928203230275509*psi[1]) ; - double cq = 0.125*((13.41640786499874*psi[5]-15.0*psi[8])*SQ(y)+(6.928203230275509*psi[2]-7.745966692414834*psi[6])*y+5.0*psi[8]- 4.47213595499958*psi[5]-4.47213595499958*psi[4]+4.0*psi[0] ) - psi0; - - double delta2 = bq*bq - 4*aq*cq; - if(delta2 > 0) + struct RdRdZ_sol sol = {.nsol = 0}; + double y = (Z - xc[1]) / (dx[1] * 0.5); + + double aq = 0.125 * (45.0 * psi[8] * SQ(y) + 23.2379000772445 * psi[6] * y - 15.0 * psi[8] + + 13.41640786499874 * psi[4]); + double bq = 0.125 * (23.2379000772445 * psi[7] * SQ(y) + 12.0 * psi[3] * y - + 7.745966692414834 * psi[7] + 6.928203230275509 * psi[1]); + double cq = + 0.125 * ((13.41640786499874 * psi[5] - 15.0 * psi[8]) * SQ(y) + + (6.928203230275509 * psi[2] - 7.745966692414834 * psi[6]) * y + 5.0 * psi[8] - + 4.47213595499958 * psi[5] - 4.47213595499958 * psi[4] + 4.0 * psi[0]) - + psi0; + + double delta2 = bq * bq - 4 * aq * cq; + if (delta2 > 0) { return sol; - + } if (fabs(delta2) < 1.0e-20) { // x = [-b +/- sqrt(b^2 - 4ac)] / 2a // If b^2-4ac = 0 then we have one root x = -b/2a - double r = -bq/2.0/aq; + double r = -bq / 2.0 / aq; int sidx = 0; - if ((-1<=r) && (r < 1)) { + if ((-1 <= r) && (r < 1)) { sol.nsol += 1; - sol.R[sidx] = r*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r * dx[0] * 0.5 + xc[0]; double x = r; - double C = 0.125*(SQ(x)*(90.0*psi[8]*y+23.2379000772445*psi[6])+x*(46.47580015448901*psi[7]*y+12.0*psi[3])+2* (13.41640786499874*psi[5]-15.0*psi[8])*y-7.745966692414834*psi[6]+6.928203230275509*psi[2]) ; - double A = 0.125*(2*x*(45.0*psi[8]*SQ(y)+23.2379000772445*psi[6]*y-15.0*psi[8]+13.41640786499874*psi[4])+23.2379000772445*psi[7]*SQ(y)+12.0*psi[3]*y-7.745966692414834*psi[7]+6.928203230275509*psi[1]); - sol.dRdZ[sidx] = -C/A*dx[0]/dx[1]; - + double C = 0.125 * (SQ(x) * (90.0 * psi[8] * y + 23.2379000772445 * psi[6]) + + x * (46.47580015448901 * psi[7] * y + 12.0 * psi[3]) + + 2 * (13.41640786499874 * psi[5] - 15.0 * psi[8]) * y - + 7.745966692414834 * psi[6] + 6.928203230275509 * psi[2]); + double A = 0.125 * (2 * x * + (45.0 * psi[8] * SQ(y) + 23.2379000772445 * psi[6] * y - 15.0 * psi[8] + + 13.41640786499874 * psi[4]) + + 23.2379000772445 * psi[7] * SQ(y) + 12.0 * psi[3] * y - + 7.745966692414834 * psi[7] + 6.928203230275509 * psi[1]); + sol.dRdZ[sidx] = -C / A * dx[0] / dx[1]; + sidx += 1; } } @@ -248,38 +318,83 @@ calc_RdR_p2_tensor_with_tolerance(const double *psi, double psi0, double Z, doub static inline struct RdRdZ_sol calc_RdR_p3(const double *psi, double psi0, double Z, double xc[2], double dx[2]) { - struct RdRdZ_sol sol = { .nsol = 0 }; - double y = (Z-xc[1])/(dx[1]*0.5); + struct RdRdZ_sol sol = {.nsol = 0}; + double y = (Z - xc[1]) / (dx[1] * 0.5); double coeffs[4]; // coeffs = [x^0, x^1, x^2, x^3] - coeffs[3] = 0.125*(175.0*psi[15]*CUB(y)+88.74119674649424*psi[13]*SQ(y)+(45.8257569495584*psi[11]-105.0*psi[15])*y+26.45751311064591*psi[8]-29.58039891549808*psi[13]); - coeffs[2] = 0.125*(88.74119674649424*psi[14]*CUB(y)+45.0*psi[10]*SQ(y)+(23.2379000772445*psi[6]-53.24471804789655*psi[14])*y+13.41640786499874*psi[4]-15.0*psi[10]); - coeffs[1] = 0.125*((45.8257569495584*psi[12]-105.0*psi[15])*CUB(y)+(23.2379000772445*psi[7]-53.24471804789655*psi[13])*SQ(y)+(12.0*psi[3]+63.0*psi[15]-27.49545416973504*psi[12]-27.49545416973504*psi[11])*y-15.87450786638754*psi[8]-7.745966692414834*psi[7]+17.74823934929885*psi[13]+6.928203230275509*psi[1]); - coeffs[0] = 0.125*((26.45751311064591*psi[9]-29.58039891549808*psi[14])*CUB(y)+(13.41640786499874*psi[5]-15.0*psi[10])*SQ(y)+(-15.87450786638754*psi[9]-7.745966692414834*psi[6]+6.928203230275509*psi[2]+17.74823934929885*psi[14])*y-4.47213595499958*psi[5]-4.47213595499958*psi[4]+5.0*psi[10]+4.0*psi[0]) - psi0; - - coeffs[0] = coeffs[0]/coeffs[3]; - coeffs[1] = coeffs[1]/coeffs[3]; - coeffs[2] = coeffs[2]/coeffs[3]; - coeffs[3] = coeffs[3]/coeffs[3]; + coeffs[3] = 0.125 * (175.0 * psi[15] * CUB(y) + 88.74119674649424 * psi[13] * SQ(y) + + (45.8257569495584 * psi[11] - 105.0 * psi[15]) * y + + 26.45751311064591 * psi[8] - 29.58039891549808 * psi[13]); + coeffs[2] = 0.125 * (88.74119674649424 * psi[14] * CUB(y) + 45.0 * psi[10] * SQ(y) + + (23.2379000772445 * psi[6] - 53.24471804789655 * psi[14]) * y + + 13.41640786499874 * psi[4] - 15.0 * psi[10]); + coeffs[1] = 0.125 * ((45.8257569495584 * psi[12] - 105.0 * psi[15]) * CUB(y) + + (23.2379000772445 * psi[7] - 53.24471804789655 * psi[13]) * SQ(y) + + (12.0 * psi[3] + 63.0 * psi[15] - 27.49545416973504 * psi[12] - + 27.49545416973504 * psi[11]) * + y - + 15.87450786638754 * psi[8] - 7.745966692414834 * psi[7] + + 17.74823934929885 * psi[13] + 6.928203230275509 * psi[1]); + coeffs[0] = + 0.125 * ((26.45751311064591 * psi[9] - 29.58039891549808 * psi[14]) * CUB(y) + + (13.41640786499874 * psi[5] - 15.0 * psi[10]) * SQ(y) + + (-15.87450786638754 * psi[9] - 7.745966692414834 * psi[6] + + 6.928203230275509 * psi[2] + 17.74823934929885 * psi[14]) * + y - + 4.47213595499958 * psi[5] - 4.47213595499958 * psi[4] + 5.0 * psi[10] + 4.0 * psi[0]) - + psi0; + + coeffs[0] = coeffs[0] / coeffs[3]; + coeffs[1] = coeffs[1] / coeffs[3]; + coeffs[2] = coeffs[2] / coeffs[3]; + coeffs[3] = coeffs[3] / coeffs[3]; struct gkyl_lo_poly_roots rts; rts = gkyl_calc_lo_poly_roots(GKYL_LO_POLY_3, coeffs); int sidx = 0; - for(int i =0; i<3; i++){ - if(rts.rpart[i] < 1.0 && rts.rpart[i] > -1.0 && fabs(rts.impart[i])<1e-16){ + for (int i = 0; i < 3; i++) { + if (rts.rpart[i] < 1.0 && rts.rpart[i] > -1.0 && fabs(rts.impart[i]) < 1e-16) { sol.nsol += 1; - sol.R[sidx] = rts.rpart[i]*dx[0]*0.5 + xc[0]; + sol.R[sidx] = rts.rpart[i] * dx[0] * 0.5 + xc[0]; double x = rts.rpart[i]; - double dpsidx = 6.5625000000000000e+01*(x*x)*(y*y*y)*psi[15]+-9.6824583655185426e-01*psi[7]+-6.6555897559870685e+00*(y*y)*psi[13]+5.7282196186947996e+00*(y*y*y)*psi[12]+2.9047375096555625e+00*psi[7]*(y*y)+3.3277948779935343e+01*(x*x)*(y*y)*psi[13]+5.8094750193111251e+00*psi[6]*x*y+-1.3125000000000000e+01*(y*y*y)*psi[15]+9.9215674164922145e+00*(x*x)*psi[8]+-3.7500000000000000e+00*x*psi[10]+8.6602540378443860e-01*psi[1]+-3.4369317712168801e+00*y*psi[12]+-1.3311179511974137e+01*x*psi[14]*y+-1.9843134832984430e+00*psi[8]+-3.4369317712168801e+00*y*psi[11]+-3.9375000000000000e+01*(x*x)*y*psi[15]+1.7184658856084400e+01*(x*x)*y*psi[11]+2.2185299186623562e+00*psi[13]+2.2185299186623560e+01*x*psi[14]*(y*y*y)+1.5000000000000000e+00*y*psi[3]+-1.1092649593311780e+01*(x*x)*psi[13]+1.1250000000000000e+01*x*(y*y)*psi[10]+7.8750000000000000e+00*y*psi[15]+3.3541019662496847e+00*x*psi[4]; - double dpsidy = -9.6824583655185426e-01*psi[6]+1.5000000000000000e+00*x*psi[3]+2.2185299186623560e+01*(x*x*x)*y*psi[13]+7.8750000000000000e+00*x*psi[15]+3.3277948779935343e+01*(x*x)*psi[14]*(y*y)+2.2185299186623562e+00*psi[14]+-3.4369317712168801e+00*x*psi[12]+9.9215674164922145e+00*(y*y)*psi[9]+-3.4369317712168801e+00*x*psi[11]+-1.3311179511974137e+01*x*y*psi[13]+-1.1092649593311780e+01*psi[14]*(y*y)+-3.9375000000000000e+01*x*(y*y)*psi[15]+-1.3125000000000000e+01*(x*x*x)*psi[15]+-3.7500000000000000e+00*y*psi[10]+2.9047375096555625e+00*psi[6]*(x*x)+5.8094750193111251e+00*psi[7]*x*y+-6.6555897559870685e+00*(x*x)*psi[14]+5.7282196186947996e+00*(x*x*x)*psi[11]+-1.9843134832984430e+00*psi[9]+6.5625000000000000e+01*(x*x*x)*(y*y)*psi[15]+3.3541019662496847e+00*psi[5]*y+1.1250000000000000e+01*(x*x)*y*psi[10]+1.7184658856084400e+01*x*(y*y)*psi[12]+8.6602540378443860e-01*psi[2]; - - sol.dRdZ[sidx] = -dpsidy/dpsidx*dx[0]/dx[1]; - sol.dR[sidx] = -dpsidy*dx[0]; - sol.dZ[sidx] = dpsidx*dx[1]; - sidx+=1; + double dpsidx = + 6.5625000000000000e+01 * (x * x) * (y * y * y) * psi[15] + + -9.6824583655185426e-01 * psi[7] + -6.6555897559870685e+00 * (y * y) * psi[13] + + 5.7282196186947996e+00 * (y * y * y) * psi[12] + 2.9047375096555625e+00 * psi[7] * (y * y) + + 3.3277948779935343e+01 * (x * x) * (y * y) * psi[13] + + 5.8094750193111251e+00 * psi[6] * x * y + -1.3125000000000000e+01 * (y * y * y) * psi[15] + + 9.9215674164922145e+00 * (x * x) * psi[8] + -3.7500000000000000e+00 * x * psi[10] + + 8.6602540378443860e-01 * psi[1] + -3.4369317712168801e+00 * y * psi[12] + + -1.3311179511974137e+01 * x * psi[14] * y + -1.9843134832984430e+00 * psi[8] + + -3.4369317712168801e+00 * y * psi[11] + -3.9375000000000000e+01 * (x * x) * y * psi[15] + + 1.7184658856084400e+01 * (x * x) * y * psi[11] + 2.2185299186623562e+00 * psi[13] + + 2.2185299186623560e+01 * x * psi[14] * (y * y * y) + 1.5000000000000000e+00 * y * psi[3] + + -1.1092649593311780e+01 * (x * x) * psi[13] + + 1.1250000000000000e+01 * x * (y * y) * psi[10] + 7.8750000000000000e+00 * y * psi[15] + + 3.3541019662496847e+00 * x * psi[4]; + double dpsidy = + -9.6824583655185426e-01 * psi[6] + 1.5000000000000000e+00 * x * psi[3] + + 2.2185299186623560e+01 * (x * x * x) * y * psi[13] + 7.8750000000000000e+00 * x * psi[15] + + 3.3277948779935343e+01 * (x * x) * psi[14] * (y * y) + 2.2185299186623562e+00 * psi[14] + + -3.4369317712168801e+00 * x * psi[12] + 9.9215674164922145e+00 * (y * y) * psi[9] + + -3.4369317712168801e+00 * x * psi[11] + -1.3311179511974137e+01 * x * y * psi[13] + + -1.1092649593311780e+01 * psi[14] * (y * y) + + -3.9375000000000000e+01 * x * (y * y) * psi[15] + + -1.3125000000000000e+01 * (x * x * x) * psi[15] + -3.7500000000000000e+00 * y * psi[10] + + 2.9047375096555625e+00 * psi[6] * (x * x) + 5.8094750193111251e+00 * psi[7] * x * y + + -6.6555897559870685e+00 * (x * x) * psi[14] + + 5.7282196186947996e+00 * (x * x * x) * psi[11] + -1.9843134832984430e+00 * psi[9] + + 6.5625000000000000e+01 * (x * x * x) * (y * y) * psi[15] + + 3.3541019662496847e+00 * psi[5] * y + 1.1250000000000000e+01 * (x * x) * y * psi[10] + + 1.7184658856084400e+01 * x * (y * y) * psi[12] + 8.6602540378443860e-01 * psi[2]; + + sol.dRdZ[sidx] = -dpsidy / dpsidx * dx[0] / dx[1]; + sol.dR[sidx] = -dpsidy * dx[0]; + sol.dZ[sidx] = dpsidx * dx[1]; + sidx += 1; } } @@ -290,111 +405,221 @@ calc_RdR_p3(const double *psi, double psi0, double Z, double xc[2], double dx[2] static inline struct RdRdZ_sol calc_RdR_p3_hyperbolic(const double *psi, double psi0, double Z, double xc[2], double dx[2]) { - struct RdRdZ_sol sol = { .nsol = 0 }; - double y = (Z-xc[1])/(dx[1]*0.5); + struct RdRdZ_sol sol = {.nsol = 0}; + double y = (Z - xc[1]) / (dx[1] * 0.5); double coeffs[4]; // coeffs = [x^0, x^1, x^2, x^3] - coeffs[3] = 0.125*(175.0*psi[15]*CUB(y)+88.74119674649424*psi[13]*SQ(y)+(45.8257569495584*psi[11]-105.0*psi[15])*y+26.45751311064591*psi[8]-29.58039891549808*psi[13]); - coeffs[2] = 0.125*(88.74119674649424*psi[14]*CUB(y)+45.0*psi[10]*SQ(y)+(23.2379000772445*psi[6]-53.24471804789655*psi[14])*y+13.41640786499874*psi[4]-15.0*psi[10]); - coeffs[1] = 0.125*((45.8257569495584*psi[12]-105.0*psi[15])*CUB(y)+(23.2379000772445*psi[7]-53.24471804789655*psi[13])*SQ(y)+(12.0*psi[3]+63.0*psi[15]-27.49545416973504*psi[12]-27.49545416973504*psi[11])*y-15.87450786638754*psi[8]-7.745966692414834*psi[7]+17.74823934929885*psi[13]+6.928203230275509*psi[1]); - coeffs[0] = 0.125*((26.45751311064591*psi[9]-29.58039891549808*psi[14])*CUB(y)+(13.41640786499874*psi[5]-15.0*psi[10])*SQ(y)+(-15.87450786638754*psi[9]-7.745966692414834*psi[6]+6.928203230275509*psi[2]+17.74823934929885*psi[14])*y-4.47213595499958*psi[5]-4.47213595499958*psi[4]+5.0*psi[10]+4.0*psi[0]) - psi0; + coeffs[3] = 0.125 * (175.0 * psi[15] * CUB(y) + 88.74119674649424 * psi[13] * SQ(y) + + (45.8257569495584 * psi[11] - 105.0 * psi[15]) * y + + 26.45751311064591 * psi[8] - 29.58039891549808 * psi[13]); + coeffs[2] = 0.125 * (88.74119674649424 * psi[14] * CUB(y) + 45.0 * psi[10] * SQ(y) + + (23.2379000772445 * psi[6] - 53.24471804789655 * psi[14]) * y + + 13.41640786499874 * psi[4] - 15.0 * psi[10]); + coeffs[1] = 0.125 * ((45.8257569495584 * psi[12] - 105.0 * psi[15]) * CUB(y) + + (23.2379000772445 * psi[7] - 53.24471804789655 * psi[13]) * SQ(y) + + (12.0 * psi[3] + 63.0 * psi[15] - 27.49545416973504 * psi[12] - + 27.49545416973504 * psi[11]) * + y - + 15.87450786638754 * psi[8] - 7.745966692414834 * psi[7] + + 17.74823934929885 * psi[13] + 6.928203230275509 * psi[1]); + coeffs[0] = + 0.125 * ((26.45751311064591 * psi[9] - 29.58039891549808 * psi[14]) * CUB(y) + + (13.41640786499874 * psi[5] - 15.0 * psi[10]) * SQ(y) + + (-15.87450786638754 * psi[9] - 7.745966692414834 * psi[6] + + 6.928203230275509 * psi[2] + 17.74823934929885 * psi[14]) * + y - + 4.47213595499958 * psi[5] - 4.47213595499958 * psi[4] + 5.0 * psi[10] + 4.0 * psi[0]) - + psi0; double A = coeffs[3]; - double B = coeffs[2]/3.0; + double B = coeffs[2] / 3.0; double C = coeffs[1]; double D = coeffs[0]; - if(A<1e-10) { // We have a quadratic, use quadratic solve + if (A < 1e-10) { // We have a quadratic, use quadratic solve double aq = coeffs[2]; double bq = coeffs[1]; double cq = coeffs[0]; - double delta2 = bq*bq - 4*aq*cq; + double delta2 = bq * bq - 4 * aq * cq; if (delta2 > 0) { double r1, r2; double delta = sqrt(delta2); //// compute both roots - double qq = -0.5*(bq + (bq/fabs(bq)) * delta); - r1 = qq/aq; - r2 = cq/qq; + double qq = -0.5 * (bq + (bq / fabs(bq)) * delta); + r1 = qq / aq; + r2 = cq / qq; int sidx = 0; - if ((-1<=r1) && (r1 < 1)) { + if ((-1 <= r1) && (r1 < 1)) { sol.nsol += 1; - sol.R[sidx] = r1*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r1 * dx[0] * 0.5 + xc[0]; double x = r1; - double dpsidx = 6.5625000000000000e+01*(x*x)*(y*y*y)*psi[15]+-9.6824583655185426e-01*psi[7]+-6.6555897559870685e+00*(y*y)*psi[13]+5.7282196186947996e+00*(y*y*y)*psi[12]+2.9047375096555625e+00*psi[7]*(y*y)+3.3277948779935343e+01*(x*x)*(y*y)*psi[13]+5.8094750193111251e+00*psi[6]*x*y+-1.3125000000000000e+01*(y*y*y)*psi[15]+9.9215674164922145e+00*(x*x)*psi[8]+-3.7500000000000000e+00*x*psi[10]+8.6602540378443860e-01*psi[1]+-3.4369317712168801e+00*y*psi[12]+-1.3311179511974137e+01*x*psi[14]*y+-1.9843134832984430e+00*psi[8]+-3.4369317712168801e+00*y*psi[11]+-3.9375000000000000e+01*(x*x)*y*psi[15]+1.7184658856084400e+01*(x*x)*y*psi[11]+2.2185299186623562e+00*psi[13]+2.2185299186623560e+01*x*psi[14]*(y*y*y)+1.5000000000000000e+00*y*psi[3]+-1.1092649593311780e+01*(x*x)*psi[13]+1.1250000000000000e+01*x*(y*y)*psi[10]+7.8750000000000000e+00*y*psi[15]+3.3541019662496847e+00*x*psi[4]; - double dpsidy = -9.6824583655185426e-01*psi[6]+1.5000000000000000e+00*x*psi[3]+2.2185299186623560e+01*(x*x*x)*y*psi[13]+7.8750000000000000e+00*x*psi[15]+3.3277948779935343e+01*(x*x)*psi[14]*(y*y)+2.2185299186623562e+00*psi[14]+-3.4369317712168801e+00*x*psi[12]+9.9215674164922145e+00*(y*y)*psi[9]+-3.4369317712168801e+00*x*psi[11]+-1.3311179511974137e+01*x*y*psi[13]+-1.1092649593311780e+01*psi[14]*(y*y)+-3.9375000000000000e+01*x*(y*y)*psi[15]+-1.3125000000000000e+01*(x*x*x)*psi[15]+-3.7500000000000000e+00*y*psi[10]+2.9047375096555625e+00*psi[6]*(x*x)+5.8094750193111251e+00*psi[7]*x*y+-6.6555897559870685e+00*(x*x)*psi[14]+5.7282196186947996e+00*(x*x*x)*psi[11]+-1.9843134832984430e+00*psi[9]+6.5625000000000000e+01*(x*x*x)*(y*y)*psi[15]+3.3541019662496847e+00*psi[5]*y+1.1250000000000000e+01*(x*x)*y*psi[10]+1.7184658856084400e+01*x*(y*y)*psi[12]+8.6602540378443860e-01*psi[2]; - sol.dRdZ[sidx] = -dpsidy/dpsidx*dx[0]/dx[1]; + double dpsidx = + 6.5625000000000000e+01 * (x * x) * (y * y * y) * psi[15] + + -9.6824583655185426e-01 * psi[7] + -6.6555897559870685e+00 * (y * y) * psi[13] + + 5.7282196186947996e+00 * (y * y * y) * psi[12] + + 2.9047375096555625e+00 * psi[7] * (y * y) + + 3.3277948779935343e+01 * (x * x) * (y * y) * psi[13] + + 5.8094750193111251e+00 * psi[6] * x * y + + -1.3125000000000000e+01 * (y * y * y) * psi[15] + + 9.9215674164922145e+00 * (x * x) * psi[8] + -3.7500000000000000e+00 * x * psi[10] + + 8.6602540378443860e-01 * psi[1] + -3.4369317712168801e+00 * y * psi[12] + + -1.3311179511974137e+01 * x * psi[14] * y + -1.9843134832984430e+00 * psi[8] + + -3.4369317712168801e+00 * y * psi[11] + -3.9375000000000000e+01 * (x * x) * y * psi[15] + + 1.7184658856084400e+01 * (x * x) * y * psi[11] + 2.2185299186623562e+00 * psi[13] + + 2.2185299186623560e+01 * x * psi[14] * (y * y * y) + 1.5000000000000000e+00 * y * psi[3] + + -1.1092649593311780e+01 * (x * x) * psi[13] + + 1.1250000000000000e+01 * x * (y * y) * psi[10] + 7.8750000000000000e+00 * y * psi[15] + + 3.3541019662496847e+00 * x * psi[4]; + double dpsidy = + -9.6824583655185426e-01 * psi[6] + 1.5000000000000000e+00 * x * psi[3] + + 2.2185299186623560e+01 * (x * x * x) * y * psi[13] + + 7.8750000000000000e+00 * x * psi[15] + + 3.3277948779935343e+01 * (x * x) * psi[14] * (y * y) + 2.2185299186623562e+00 * psi[14] + + -3.4369317712168801e+00 * x * psi[12] + 9.9215674164922145e+00 * (y * y) * psi[9] + + -3.4369317712168801e+00 * x * psi[11] + -1.3311179511974137e+01 * x * y * psi[13] + + -1.1092649593311780e+01 * psi[14] * (y * y) + + -3.9375000000000000e+01 * x * (y * y) * psi[15] + + -1.3125000000000000e+01 * (x * x * x) * psi[15] + -3.7500000000000000e+00 * y * psi[10] + + 2.9047375096555625e+00 * psi[6] * (x * x) + 5.8094750193111251e+00 * psi[7] * x * y + + -6.6555897559870685e+00 * (x * x) * psi[14] + + 5.7282196186947996e+00 * (x * x * x) * psi[11] + -1.9843134832984430e+00 * psi[9] + + 6.5625000000000000e+01 * (x * x * x) * (y * y) * psi[15] + + 3.3541019662496847e+00 * psi[5] * y + 1.1250000000000000e+01 * (x * x) * y * psi[10] + + 1.7184658856084400e+01 * x * (y * y) * psi[12] + 8.6602540378443860e-01 * psi[2]; + sol.dRdZ[sidx] = -dpsidy / dpsidx * dx[0] / dx[1]; sidx += 1; } - if ((-1<=r2) && (r2 < 1)) { + if ((-1 <= r2) && (r2 < 1)) { sol.nsol += 1; - sol.R[sidx] = r2*dx[0]*0.5 + xc[0]; + sol.R[sidx] = r2 * dx[0] * 0.5 + xc[0]; double x = r2; - double dpsidx = 6.5625000000000000e+01*(x*x)*(y*y*y)*psi[15]+-9.6824583655185426e-01*psi[7]+-6.6555897559870685e+00*(y*y)*psi[13]+5.7282196186947996e+00*(y*y*y)*psi[12]+2.9047375096555625e+00*psi[7]*(y*y)+3.3277948779935343e+01*(x*x)*(y*y)*psi[13]+5.8094750193111251e+00*psi[6]*x*y+-1.3125000000000000e+01*(y*y*y)*psi[15]+9.9215674164922145e+00*(x*x)*psi[8]+-3.7500000000000000e+00*x*psi[10]+8.6602540378443860e-01*psi[1]+-3.4369317712168801e+00*y*psi[12]+-1.3311179511974137e+01*x*psi[14]*y+-1.9843134832984430e+00*psi[8]+-3.4369317712168801e+00*y*psi[11]+-3.9375000000000000e+01*(x*x)*y*psi[15]+1.7184658856084400e+01*(x*x)*y*psi[11]+2.2185299186623562e+00*psi[13]+2.2185299186623560e+01*x*psi[14]*(y*y*y)+1.5000000000000000e+00*y*psi[3]+-1.1092649593311780e+01*(x*x)*psi[13]+1.1250000000000000e+01*x*(y*y)*psi[10]+7.8750000000000000e+00*y*psi[15]+3.3541019662496847e+00*x*psi[4]; - double dpsidy = -9.6824583655185426e-01*psi[6]+1.5000000000000000e+00*x*psi[3]+2.2185299186623560e+01*(x*x*x)*y*psi[13]+7.8750000000000000e+00*x*psi[15]+3.3277948779935343e+01*(x*x)*psi[14]*(y*y)+2.2185299186623562e+00*psi[14]+-3.4369317712168801e+00*x*psi[12]+9.9215674164922145e+00*(y*y)*psi[9]+-3.4369317712168801e+00*x*psi[11]+-1.3311179511974137e+01*x*y*psi[13]+-1.1092649593311780e+01*psi[14]*(y*y)+-3.9375000000000000e+01*x*(y*y)*psi[15]+-1.3125000000000000e+01*(x*x*x)*psi[15]+-3.7500000000000000e+00*y*psi[10]+2.9047375096555625e+00*psi[6]*(x*x)+5.8094750193111251e+00*psi[7]*x*y+-6.6555897559870685e+00*(x*x)*psi[14]+5.7282196186947996e+00*(x*x*x)*psi[11]+-1.9843134832984430e+00*psi[9]+6.5625000000000000e+01*(x*x*x)*(y*y)*psi[15]+3.3541019662496847e+00*psi[5]*y+1.1250000000000000e+01*(x*x)*y*psi[10]+1.7184658856084400e+01*x*(y*y)*psi[12]+8.6602540378443860e-01*psi[2]; - sol.dRdZ[sidx] = -dpsidy/dpsidx*dx[0]/dx[1]; + double dpsidx = + 6.5625000000000000e+01 * (x * x) * (y * y * y) * psi[15] + + -9.6824583655185426e-01 * psi[7] + -6.6555897559870685e+00 * (y * y) * psi[13] + + 5.7282196186947996e+00 * (y * y * y) * psi[12] + + 2.9047375096555625e+00 * psi[7] * (y * y) + + 3.3277948779935343e+01 * (x * x) * (y * y) * psi[13] + + 5.8094750193111251e+00 * psi[6] * x * y + + -1.3125000000000000e+01 * (y * y * y) * psi[15] + + 9.9215674164922145e+00 * (x * x) * psi[8] + -3.7500000000000000e+00 * x * psi[10] + + 8.6602540378443860e-01 * psi[1] + -3.4369317712168801e+00 * y * psi[12] + + -1.3311179511974137e+01 * x * psi[14] * y + -1.9843134832984430e+00 * psi[8] + + -3.4369317712168801e+00 * y * psi[11] + -3.9375000000000000e+01 * (x * x) * y * psi[15] + + 1.7184658856084400e+01 * (x * x) * y * psi[11] + 2.2185299186623562e+00 * psi[13] + + 2.2185299186623560e+01 * x * psi[14] * (y * y * y) + 1.5000000000000000e+00 * y * psi[3] + + -1.1092649593311780e+01 * (x * x) * psi[13] + + 1.1250000000000000e+01 * x * (y * y) * psi[10] + 7.8750000000000000e+00 * y * psi[15] + + 3.3541019662496847e+00 * x * psi[4]; + double dpsidy = + -9.6824583655185426e-01 * psi[6] + 1.5000000000000000e+00 * x * psi[3] + + 2.2185299186623560e+01 * (x * x * x) * y * psi[13] + + 7.8750000000000000e+00 * x * psi[15] + + 3.3277948779935343e+01 * (x * x) * psi[14] * (y * y) + 2.2185299186623562e+00 * psi[14] + + -3.4369317712168801e+00 * x * psi[12] + 9.9215674164922145e+00 * (y * y) * psi[9] + + -3.4369317712168801e+00 * x * psi[11] + -1.3311179511974137e+01 * x * y * psi[13] + + -1.1092649593311780e+01 * psi[14] * (y * y) + + -3.9375000000000000e+01 * x * (y * y) * psi[15] + + -1.3125000000000000e+01 * (x * x * x) * psi[15] + -3.7500000000000000e+00 * y * psi[10] + + 2.9047375096555625e+00 * psi[6] * (x * x) + 5.8094750193111251e+00 * psi[7] * x * y + + -6.6555897559870685e+00 * (x * x) * psi[14] + + 5.7282196186947996e+00 * (x * x * x) * psi[11] + -1.9843134832984430e+00 * psi[9] + + 6.5625000000000000e+01 * (x * x * x) * (y * y) * psi[15] + + 3.3541019662496847e+00 * psi[5] * y + 1.1250000000000000e+01 * (x * x) * y * psi[10] + + 1.7184658856084400e+01 * x * (y * y) * psi[12] + 8.6602540378443860e-01 * psi[2]; + sol.dRdZ[sidx] = -dpsidy / dpsidx * dx[0] / dx[1]; sidx += 1; } } return sol; } - double gamma = B/A; - double a = C/3/A - SQ(gamma); - double b = 2*CUB(gamma) -C*gamma/A + D/A; - double complex rho = -4.0*a + 0.0*I; - double complex s = -4.0*b + 0.0*I; + double gamma = B / A; + double a = C / 3 / A - SQ(gamma); + double b = 2 * CUB(gamma) - C * gamma / A + D / A; + double complex rho = -4.0 * a + 0.0 * I; + double complex s = -4.0 * b + 0.0 * I; double complex t = csqrt(cSQ(s) - cCUB(rho)); - double complex alpha = -0.5 + 0.5*sqrt(3.0)*I; + double complex alpha = -0.5 + 0.5 * sqrt(3.0) * I; double complex alpha_0 = 1.0; double complex alpha_1 = alpha; double complex alpha_2 = cSQ(alpha); - double complex x_0 = (0.5 + 0.0*I)* (alpha_0*croot(s+t, 3.0) + rho/alpha_0/croot(s+t,3.0) ); - double complex x_1 = (0.5 + 0.0*I)* (alpha_1*croot(s+t, 3.0) + rho/alpha_1/croot(s+t,3.0) ); - double complex x_2 = (0.5 + 0.0*I)* (alpha_2*croot(s+t, 3.0) + rho/alpha_2/croot(s+t,3.0) ); - double complex r0 = x_0 - (gamma + 0.0*I); - double complex r1 = x_1 - (gamma + 0.0*I); - double complex r2 = x_2 - (gamma + 0.0*I); + double complex x_0 = + (0.5 + 0.0 * I) * (alpha_0 * croot(s + t, 3.0) + rho / alpha_0 / croot(s + t, 3.0)); + double complex x_1 = + (0.5 + 0.0 * I) * (alpha_1 * croot(s + t, 3.0) + rho / alpha_1 / croot(s + t, 3.0)); + double complex x_2 = + (0.5 + 0.0 * I) * (alpha_2 * croot(s + t, 3.0) + rho / alpha_2 / croot(s + t, 3.0)); + double complex r0 = x_0 - (gamma + 0.0 * I); + double complex r1 = x_1 - (gamma + 0.0 * I); + double complex r2 = x_2 - (gamma + 0.0 * I); double complex roots[3] = {r0, r1, r2}; int sidx = 0; - for(int i =0; i<3; i++){ + for (int i = 0; i < 3; i++) { double rpart = creal(roots[i]); double impart = cimag(roots[i]); - if(rpart < 1.0 && rpart > -1.0 && fabs(impart)<1e-10){ + if (rpart < 1.0 && rpart > -1.0 && fabs(impart) < 1e-10) { sol.nsol += 1; - sol.R[sidx] = rpart*dx[0]*0.5 + xc[0]; + sol.R[sidx] = rpart * dx[0] * 0.5 + xc[0]; double x = rpart; - double dpsidx = 6.5625000000000000e+01*(x*x)*(y*y*y)*psi[15]+-9.6824583655185426e-01*psi[7]+-6.6555897559870685e+00*(y*y)*psi[13]+5.7282196186947996e+00*(y*y*y)*psi[12]+2.9047375096555625e+00*psi[7]*(y*y)+3.3277948779935343e+01*(x*x)*(y*y)*psi[13]+5.8094750193111251e+00*psi[6]*x*y+-1.3125000000000000e+01*(y*y*y)*psi[15]+9.9215674164922145e+00*(x*x)*psi[8]+-3.7500000000000000e+00*x*psi[10]+8.6602540378443860e-01*psi[1]+-3.4369317712168801e+00*y*psi[12]+-1.3311179511974137e+01*x*psi[14]*y+-1.9843134832984430e+00*psi[8]+-3.4369317712168801e+00*y*psi[11]+-3.9375000000000000e+01*(x*x)*y*psi[15]+1.7184658856084400e+01*(x*x)*y*psi[11]+2.2185299186623562e+00*psi[13]+2.2185299186623560e+01*x*psi[14]*(y*y*y)+1.5000000000000000e+00*y*psi[3]+-1.1092649593311780e+01*(x*x)*psi[13]+1.1250000000000000e+01*x*(y*y)*psi[10]+7.8750000000000000e+00*y*psi[15]+3.3541019662496847e+00*x*psi[4]; - double dpsidy = -9.6824583655185426e-01*psi[6]+1.5000000000000000e+00*x*psi[3]+2.2185299186623560e+01*(x*x*x)*y*psi[13]+7.8750000000000000e+00*x*psi[15]+3.3277948779935343e+01*(x*x)*psi[14]*(y*y)+2.2185299186623562e+00*psi[14]+-3.4369317712168801e+00*x*psi[12]+9.9215674164922145e+00*(y*y)*psi[9]+-3.4369317712168801e+00*x*psi[11]+-1.3311179511974137e+01*x*y*psi[13]+-1.1092649593311780e+01*psi[14]*(y*y)+-3.9375000000000000e+01*x*(y*y)*psi[15]+-1.3125000000000000e+01*(x*x*x)*psi[15]+-3.7500000000000000e+00*y*psi[10]+2.9047375096555625e+00*psi[6]*(x*x)+5.8094750193111251e+00*psi[7]*x*y+-6.6555897559870685e+00*(x*x)*psi[14]+5.7282196186947996e+00*(x*x*x)*psi[11]+-1.9843134832984430e+00*psi[9]+6.5625000000000000e+01*(x*x*x)*(y*y)*psi[15]+3.3541019662496847e+00*psi[5]*y+1.1250000000000000e+01*(x*x)*y*psi[10]+1.7184658856084400e+01*x*(y*y)*psi[12]+8.6602540378443860e-01*psi[2]; - sol.dRdZ[sidx] = -dpsidy/dpsidx*dx[0]/dx[1]; - sol.dR[sidx] = -dpsidy*dx[0]; - sol.dZ[sidx] = dpsidx*dx[1]; - sidx+=1; + double dpsidx = + 6.5625000000000000e+01 * (x * x) * (y * y * y) * psi[15] + + -9.6824583655185426e-01 * psi[7] + -6.6555897559870685e+00 * (y * y) * psi[13] + + 5.7282196186947996e+00 * (y * y * y) * psi[12] + 2.9047375096555625e+00 * psi[7] * (y * y) + + 3.3277948779935343e+01 * (x * x) * (y * y) * psi[13] + + 5.8094750193111251e+00 * psi[6] * x * y + -1.3125000000000000e+01 * (y * y * y) * psi[15] + + 9.9215674164922145e+00 * (x * x) * psi[8] + -3.7500000000000000e+00 * x * psi[10] + + 8.6602540378443860e-01 * psi[1] + -3.4369317712168801e+00 * y * psi[12] + + -1.3311179511974137e+01 * x * psi[14] * y + -1.9843134832984430e+00 * psi[8] + + -3.4369317712168801e+00 * y * psi[11] + -3.9375000000000000e+01 * (x * x) * y * psi[15] + + 1.7184658856084400e+01 * (x * x) * y * psi[11] + 2.2185299186623562e+00 * psi[13] + + 2.2185299186623560e+01 * x * psi[14] * (y * y * y) + 1.5000000000000000e+00 * y * psi[3] + + -1.1092649593311780e+01 * (x * x) * psi[13] + + 1.1250000000000000e+01 * x * (y * y) * psi[10] + 7.8750000000000000e+00 * y * psi[15] + + 3.3541019662496847e+00 * x * psi[4]; + double dpsidy = + -9.6824583655185426e-01 * psi[6] + 1.5000000000000000e+00 * x * psi[3] + + 2.2185299186623560e+01 * (x * x * x) * y * psi[13] + 7.8750000000000000e+00 * x * psi[15] + + 3.3277948779935343e+01 * (x * x) * psi[14] * (y * y) + 2.2185299186623562e+00 * psi[14] + + -3.4369317712168801e+00 * x * psi[12] + 9.9215674164922145e+00 * (y * y) * psi[9] + + -3.4369317712168801e+00 * x * psi[11] + -1.3311179511974137e+01 * x * y * psi[13] + + -1.1092649593311780e+01 * psi[14] * (y * y) + + -3.9375000000000000e+01 * x * (y * y) * psi[15] + + -1.3125000000000000e+01 * (x * x * x) * psi[15] + -3.7500000000000000e+00 * y * psi[10] + + 2.9047375096555625e+00 * psi[6] * (x * x) + 5.8094750193111251e+00 * psi[7] * x * y + + -6.6555897559870685e+00 * (x * x) * psi[14] + + 5.7282196186947996e+00 * (x * x * x) * psi[11] + -1.9843134832984430e+00 * psi[9] + + 6.5625000000000000e+01 * (x * x * x) * (y * y) * psi[15] + + 3.3541019662496847e+00 * psi[5] * y + 1.1250000000000000e+01 * (x * x) * y * psi[10] + + 1.7184658856084400e+01 * x * (y * y) * psi[12] + 8.6602540378443860e-01 * psi[2]; + sol.dRdZ[sidx] = -dpsidy / dpsidx * dx[0] / dx[1]; + sol.dR[sidx] = -dpsidy * dx[0]; + sol.dZ[sidx] = dpsidx * dx[1]; + sidx += 1; } } return sol; } - // Compute R(psi,Z) given a psi and Z. Can return multiple solutions // or no solutions. The number of roots found is returned and are // copied in the array R and dR. The calling function must ensure that // these arrays are big enough to hold all roots required -static int -R_psiZ(const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, - double *R, double *dRdZ, double* dR, double *dZ) +static int R_psiZ( + const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, double *R, double *dRdZ, + double *dR, double *dZ +) { int zcell = get_idx(1, Z, &geo->rzgrid, &geo->rzlocal); int sidx = 0; - int idx[2] = { 0, zcell }; - double dx[2] = { geo->rzgrid.dx[0], geo->rzgrid.dx[1] }; - + int idx[2] = {0, zcell}; + double dx[2] = {geo->rzgrid.dx[0], geo->rzgrid.dx[1]}; + struct gkyl_range rangeR; - gkyl_range_deflate(&rangeR, &geo->rzlocal, (int[]) { 0, 1 }, (int[]) { 0, zcell }); + gkyl_range_deflate(&rangeR, &geo->rzlocal, (int[]){0, 1}, (int[]){0, zcell}); struct gkyl_range_iter riter; gkyl_range_iter_init(&riter, &rangeR); - + // loop over all R cells to find psi crossing - while (gkyl_range_iter_next(&riter) && sidx<=nmaxroots) { + while (gkyl_range_iter_next(&riter) && sidx <= nmaxroots) { long loc = gkyl_range_idx(&rangeR, riter.idx); const double *psih = gkyl_array_cfetch(geo->psiRZ, loc); @@ -403,10 +628,10 @@ R_psiZ(const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, gkyl_rect_grid_cell_center(&geo->rzgrid, idx, xc); struct RdRdZ_sol sol = geo->calc_roots(psih, psi, Z, xc, dx); - - if (sol.nsol > 0) - for (int s=0; s geo->rmin) && (sol.R[s] < geo->rmax) ) { + + if (sol.nsol > 0) { + for (int s = 0; s < sol.nsol; ++s) { + if ((sol.R[s] > geo->rmin) && (sol.R[s] < geo->rmax)) { R[sidx] = sol.R[s]; dRdZ[sidx] = sol.dRdZ[s]; dR[sidx] = sol.dR[s]; @@ -414,12 +639,13 @@ R_psiZ(const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, sidx += 1; } } + } } // Try again if we didn't find any - if (sidx==0 && geo->inexact_roots) { + if (sidx == 0 && geo->inexact_roots) { gkyl_range_iter_init(&riter, &rangeR); - while (gkyl_range_iter_next(&riter) && sidx<=nmaxroots) { + while (gkyl_range_iter_next(&riter) && sidx <= nmaxroots) { long loc = gkyl_range_idx(&rangeR, riter.idx); const double *psih = gkyl_array_cfetch(geo->psiRZ, loc); @@ -428,10 +654,10 @@ R_psiZ(const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, gkyl_rect_grid_cell_center(&geo->rzgrid, idx, xc); struct RdRdZ_sol sol = calc_RdR_p2_tensor_with_tolerance(psih, psi, Z, xc, dx); - - if (sol.nsol > 0) - for (int s=0; s geo->rmin) && (sol.R[s] < geo->rmax) ) { + + if (sol.nsol > 0) { + for (int s = 0; s < sol.nsol; ++s) { + if ((sol.R[s] > geo->rmin) && (sol.R[s] < geo->rmax)) { R[sidx] = sol.R[s]; dRdZ[sidx] = sol.dRdZ[s]; dR[sidx] = sol.dR[s]; @@ -439,6 +665,7 @@ R_psiZ(const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, sidx += 1; } } + } } } @@ -449,24 +676,25 @@ R_psiZ(const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, // or no solutions. The number of roots found is returned and are // copied in the array R and dR. The calling function must ensure that // these arrays are big enough to hold all roots required -static int -R_psiZ_cubic(const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, - double *R, double *dRdZ, double* dR, double *dZ) +static int R_psiZ_cubic( + const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, double *R, double *dRdZ, + double *dR, double *dZ +) { int zcell = get_idx(1, Z, &geo->rzgrid_cubic, &geo->rzlocal_cubic); int sidx = 0; - int idx[2] = { 0, zcell }; - double dx[2] = { geo->rzgrid_cubic.dx[0], geo->rzgrid_cubic.dx[1] }; + int idx[2] = {0, zcell}; + double dx[2] = {geo->rzgrid_cubic.dx[0], geo->rzgrid_cubic.dx[1]}; struct gkyl_range rangeR; - gkyl_range_deflate(&rangeR, &geo->rzlocal_cubic, (int[]) { 0, 1 }, (int[]) { 0, zcell }); + gkyl_range_deflate(&rangeR, &geo->rzlocal_cubic, (int[]){0, 1}, (int[]){0, zcell}); struct gkyl_range_iter riter; gkyl_range_iter_init(&riter, &rangeR); // loop over all R cells to find psi crossing - while (gkyl_range_iter_next(&riter) && sidx<=nmaxroots) { + while (gkyl_range_iter_next(&riter) && sidx <= nmaxroots) { long loc = gkyl_range_idx(&rangeR, riter.idx); const double *psih = gkyl_array_cfetch(geo->psiRZ_cubic, loc); @@ -475,58 +703,87 @@ R_psiZ_cubic(const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots gkyl_rect_grid_cell_center(&geo->rzgrid_cubic, idx, xc); struct RdRdZ_sol sol = geo->calc_roots(psih, psi, Z, xc, dx); - - if (sol.nsol > 0) - for (int s=0; s geo->rmin) && (sol.R[s] < geo->rmax) ) { + + if (sol.nsol > 0) { + for (int s = 0; s < sol.nsol; ++s) { + if ((sol.R[s] > geo->rmin) && (sol.R[s] < geo->rmax)) { dRdZ[sidx] = sol.dRdZ[s]; dR[sidx] = sol.dR[s]; dZ[sidx] = sol.dZ[s]; sidx += 1; } } + } } return sidx; } -static double -calc_grad_psi_p1(const double *psih, const double eta[2], const double dx[2]) +static double calc_grad_psi_p1(const double *psih, const double eta[2], const double dx[2]) { double x = eta[0]; double y = eta[1]; - double dpsidx = 1.5*psih[3]*y+0.8660254037844386*psih[1]; - double dpsidy = 1.5*psih[3]*x+0.8660254037844386*psih[2]; - dpsidx = dpsidx*2.0/dx[0]; - dpsidy = dpsidy*2.0/dx[1]; - return sqrt(dpsidx*dpsidx + dpsidy*dpsidy); + double dpsidx = 1.5 * psih[3] * y + 0.8660254037844386 * psih[1]; + double dpsidy = 1.5 * psih[3] * x + 0.8660254037844386 * psih[2]; + dpsidx = dpsidx * 2.0 / dx[0]; + dpsidy = dpsidy * 2.0 / dx[1]; + return sqrt(dpsidx * dpsidx + dpsidy * dpsidy); } -static double -calc_grad_psi_p2_tensor(const double *psih, const double eta[2], const double dx[2]) +static double calc_grad_psi_p2_tensor(const double *psih, const double eta[2], const double dx[2]) { double x = eta[0]; double y = eta[1]; - double dpsidx = 5.625*psih[8]*(2.0*x*SQ(y)-0.6666666666666666*x)+2.904737509655563*psih[7]*(SQ(y)-0.3333333333333333)+5.809475019311126*psih[6]*x*y+1.5*psih[3]*y+3.354101966249684*psih[4]*x+0.8660254037844386*psih[1]; - double dpsidy = 5.625*psih[8]*(2.0*SQ(x)*y-0.6666666666666666*y)+5.809475019311126*psih[7]*x*y+3.354101966249684*psih[5]*y+2.904737509655563*psih[6]*(SQ(x)-0.3333333333333333)+1.5*psih[3]*x+0.8660254037844386*psih[2]; - dpsidx = dpsidx*2.0/dx[0]; - dpsidy = dpsidy*2.0/dx[1]; - return sqrt(dpsidx*dpsidx + dpsidy*dpsidy); + double dpsidx = 5.625 * psih[8] * (2.0 * x * SQ(y) - 0.6666666666666666 * x) + + 2.904737509655563 * psih[7] * (SQ(y) - 0.3333333333333333) + + 5.809475019311126 * psih[6] * x * y + 1.5 * psih[3] * y + + 3.354101966249684 * psih[4] * x + 0.8660254037844386 * psih[1]; + double dpsidy = 5.625 * psih[8] * (2.0 * SQ(x) * y - 0.6666666666666666 * y) + + 5.809475019311126 * psih[7] * x * y + 3.354101966249684 * psih[5] * y + + 2.904737509655563 * psih[6] * (SQ(x) - 0.3333333333333333) + 1.5 * psih[3] * x + + 0.8660254037844386 * psih[2]; + dpsidx = dpsidx * 2.0 / dx[0]; + dpsidy = dpsidy * 2.0 / dx[1]; + return sqrt(dpsidx * dpsidx + dpsidy * dpsidy); } -static double -calc_grad_psi_p3(const double *psih, const double eta[2], const double dx[2]) +static double calc_grad_psi_p3(const double *psih, const double eta[2], const double dx[2]) { double x = eta[0]; double y = eta[1]; - double dpsidx = 6.5625000000000000e+01*(x*x)*(y*y*y)*psih[15]+-9.6824583655185426e-01*psih[7]+-6.6555897559870685e+00*(y*y)*psih[13]+5.7282196186947996e+00*(y*y*y)*psih[12]+2.9047375096555625e+00*psih[7]*(y*y)+3.3277948779935343e+01*(x*x)*(y*y)*psih[13]+5.8094750193111251e+00*psih[6]*x*y+-1.3125000000000000e+01*(y*y*y)*psih[15]+9.9215674164922145e+00*(x*x)*psih[8]+-3.7500000000000000e+00*x*psih[10]+8.6602540378443860e-01*psih[1]+-3.4369317712168801e+00*y*psih[12]+-1.3311179511974137e+01*x*psih[14]*y+-1.9843134832984430e+00*psih[8]+-3.4369317712168801e+00*y*psih[11]+-3.9375000000000000e+01*(x*x)*y*psih[15]+1.7184658856084400e+01*(x*x)*y*psih[11]+2.2185299186623562e+00*psih[13]+2.2185299186623560e+01*x*psih[14]*(y*y*y)+1.5000000000000000e+00*y*psih[3]+-1.1092649593311780e+01*(x*x)*psih[13]+1.1250000000000000e+01*x*(y*y)*psih[10]+7.8750000000000000e+00*y*psih[15]+3.3541019662496847e+00*x*psih[4]; - double dpsidy = -9.6824583655185426e-01*psih[6]+1.5000000000000000e+00*x*psih[3]+2.2185299186623560e+01*(x*x*x)*y*psih[13]+7.8750000000000000e+00*x*psih[15]+3.3277948779935343e+01*(x*x)*psih[14]*(y*y)+2.2185299186623562e+00*psih[14]+-3.4369317712168801e+00*x*psih[12]+9.9215674164922145e+00*(y*y)*psih[9]+-3.4369317712168801e+00*x*psih[11]+-1.3311179511974137e+01*x*y*psih[13]+-1.1092649593311780e+01*psih[14]*(y*y)+-3.9375000000000000e+01*x*(y*y)*psih[15]+-1.3125000000000000e+01*(x*x*x)*psih[15]+-3.7500000000000000e+00*y*psih[10]+2.9047375096555625e+00*psih[6]*(x*x)+5.8094750193111251e+00*psih[7]*x*y+-6.6555897559870685e+00*(x*x)*psih[14]+5.7282196186947996e+00*(x*x*x)*psih[11]+-1.9843134832984430e+00*psih[9]+6.5625000000000000e+01*(x*x*x)*(y*y)*psih[15]+3.3541019662496847e+00*psih[5]*y+1.1250000000000000e+01*(x*x)*y*psih[10]+1.7184658856084400e+01*x*(y*y)*psih[12]+8.6602540378443860e-01*psih[2]; - dpsidx = dpsidx*2.0/dx[0]; - dpsidy = dpsidy*2.0/dx[1]; - return sqrt(dpsidx*dpsidx + dpsidy*dpsidy); + double dpsidx = + 6.5625000000000000e+01 * (x * x) * (y * y * y) * psih[15] + -9.6824583655185426e-01 * psih[7] + + -6.6555897559870685e+00 * (y * y) * psih[13] + 5.7282196186947996e+00 * (y * y * y) * psih[12] + + 2.9047375096555625e+00 * psih[7] * (y * y) + + 3.3277948779935343e+01 * (x * x) * (y * y) * psih[13] + + 5.8094750193111251e+00 * psih[6] * x * y + -1.3125000000000000e+01 * (y * y * y) * psih[15] + + 9.9215674164922145e+00 * (x * x) * psih[8] + -3.7500000000000000e+00 * x * psih[10] + + 8.6602540378443860e-01 * psih[1] + -3.4369317712168801e+00 * y * psih[12] + + -1.3311179511974137e+01 * x * psih[14] * y + -1.9843134832984430e+00 * psih[8] + + -3.4369317712168801e+00 * y * psih[11] + -3.9375000000000000e+01 * (x * x) * y * psih[15] + + 1.7184658856084400e+01 * (x * x) * y * psih[11] + 2.2185299186623562e+00 * psih[13] + + 2.2185299186623560e+01 * x * psih[14] * (y * y * y) + 1.5000000000000000e+00 * y * psih[3] + + -1.1092649593311780e+01 * (x * x) * psih[13] + 1.1250000000000000e+01 * x * (y * y) * psih[10] + + 7.8750000000000000e+00 * y * psih[15] + 3.3541019662496847e+00 * x * psih[4]; + double dpsidy = + -9.6824583655185426e-01 * psih[6] + 1.5000000000000000e+00 * x * psih[3] + + 2.2185299186623560e+01 * (x * x * x) * y * psih[13] + 7.8750000000000000e+00 * x * psih[15] + + 3.3277948779935343e+01 * (x * x) * psih[14] * (y * y) + 2.2185299186623562e+00 * psih[14] + + -3.4369317712168801e+00 * x * psih[12] + 9.9215674164922145e+00 * (y * y) * psih[9] + + -3.4369317712168801e+00 * x * psih[11] + -1.3311179511974137e+01 * x * y * psih[13] + + -1.1092649593311780e+01 * psih[14] * (y * y) + + -3.9375000000000000e+01 * x * (y * y) * psih[15] + + -1.3125000000000000e+01 * (x * x * x) * psih[15] + -3.7500000000000000e+00 * y * psih[10] + + 2.9047375096555625e+00 * psih[6] * (x * x) + 5.8094750193111251e+00 * psih[7] * x * y + + -6.6555897559870685e+00 * (x * x) * psih[14] + 5.7282196186947996e+00 * (x * x * x) * psih[11] + + -1.9843134832984430e+00 * psih[9] + 6.5625000000000000e+01 * (x * x * x) * (y * y) * psih[15] + + 3.3541019662496847e+00 * psih[5] * y + 1.1250000000000000e+01 * (x * x) * y * psih[10] + + 1.7184658856084400e+01 * x * (y * y) * psih[12] + 8.6602540378443860e-01 * psih[2]; + dpsidx = dpsidx * 2.0 / dx[0]; + dpsidy = dpsidy * 2.0 / dx[1]; + return sqrt(dpsidx * dpsidx + dpsidy * dpsidy); } - // Function context to pass to coutour integration function struct contour_ctx { const struct gkyl_tok_geo *geo; @@ -535,28 +792,26 @@ struct contour_ctx { }; // Function to pass to numerical quadrature to integrate along a contour -static inline double -contour_func(double Z, void *ctx) +static inline double contour_func(double Z, void *ctx) { struct contour_ctx *c = ctx; c->ncall += 1; - double R[4] = { 0 }, dRdZ[4] = { 0 }; - double dR[4] = { 0 }, dZ[4] = { 0 }; - + double R[4] = {0}, dRdZ[4] = {0}; + double dR[4] = {0}, dZ[4] = {0}; + int nr = gkyl_tok_geo_R_psiZ(c->geo, c->psi, Z, 4, R, dRdZ, dR, dZ); - double drdz = nr == 1 ? dRdZ[0] : choose_closest(c->last_R, R, dRdZ,nr); - - return nr>0 ? sqrt(1+drdz*drdz) : 0.0; + double drdz = nr == 1 ? dRdZ[0] : choose_closest(c->last_R, R, dRdZ, nr); + + return nr > 0 ? sqrt(1 + drdz * drdz) : 0.0; } -static inline double -phi_contour_func(double Z, void *ctx) +static inline double phi_contour_func(double Z, void *ctx) { struct contour_ctx *c = ctx; c->ncall += 1; - double R[4] = { 0 }, dRdZ[4] = { 0 }; - double dR[4] = { 0 }, dZ[4] = { 0 }; - + double R[4] = {0}, dRdZ[4] = {0}; + double dR[4] = {0}, dZ[4] = {0}; + int nr = gkyl_tok_geo_R_psiZ(c->geo, c->psi, Z, 4, R, dRdZ, dR, dZ); double drdz = nr == 1 ? dRdZ[0] : choose_closest(c->last_R, R, dRdZ, nr); double r_curr = nr == 1 ? R[0] : choose_closest(c->last_R, R, R, nr); @@ -566,19 +821,20 @@ phi_contour_func(double Z, void *ctx) double fout[3]; c->geo->efit->evf->eval_cubic_wgrad(0.0, xn, fout, c->geo->efit->evf->ctx); double dpsidR = fout[1]; - double dpsidZ = fout[2]; - double grad_psi_mag = sqrt(dpsidR*dpsidR + dpsidZ*dpsidZ); + double dpsidZ = fout[2]; + double grad_psi_mag = sqrt(dpsidR * dpsidR + dpsidZ * dpsidZ); - double result = (1/r_curr/grad_psi_mag) *sqrt(1+drdz*drdz) ; - return nr>0 ? result : 0.0; - } - else { + double result = (1 / r_curr / grad_psi_mag) * sqrt(1 + drdz * drdz); + return nr > 0 ? result : 0.0; + } else { int rzidx[2]; - int idxtemp = c->geo->rzlocal.lower[0] + (int) floor((r_curr - c->geo->rzgrid.lower[0])/c->geo->rzgrid.dx[0]); + int idxtemp = c->geo->rzlocal.lower[0] + + (int)floor((r_curr - c->geo->rzgrid.lower[0]) / c->geo->rzgrid.dx[0]); idxtemp = GKYL_MIN2(idxtemp, c->geo->rzlocal.upper[0]); idxtemp = GKYL_MAX2(idxtemp, c->geo->rzlocal.lower[0]); rzidx[0] = idxtemp; - idxtemp = c->geo->rzlocal.lower[1] + (int) floor((Z - c->geo->rzgrid.lower[1])/c->geo->rzgrid.dx[1]); + idxtemp = + c->geo->rzlocal.lower[1] + (int)floor((Z - c->geo->rzgrid.lower[1]) / c->geo->rzgrid.dx[1]); idxtemp = GKYL_MIN2(idxtemp, c->geo->rzlocal.upper[1]); idxtemp = GKYL_MAX2(idxtemp, c->geo->rzlocal.lower[1]); rzidx[1] = idxtemp; @@ -588,25 +844,24 @@ phi_contour_func(double Z, void *ctx) double xc[2]; gkyl_rect_grid_cell_center((&c->geo->rzgrid), rzidx, xc); - double x = (r_curr-xc[0])/(c->geo->rzgrid.dx[0]*0.5); - double y = (Z-xc[1])/(c->geo->rzgrid.dx[1]*0.5); + double x = (r_curr - xc[0]) / (c->geo->rzgrid.dx[0] * 0.5); + double y = (Z - xc[1]) / (c->geo->rzgrid.dx[1] * 0.5); - double eta[2] = {x,y}; + double eta[2] = {x, y}; double grad_psi_mag = c->geo->calc_grad_psi(psih, eta, c->geo->rzgrid.dx); - double result = (1/r_curr/grad_psi_mag) *sqrt(1+drdz*drdz) ; - return nr>0 ? result : 0.0; + double result = (1 / r_curr / grad_psi_mag) * sqrt(1 + drdz * drdz); + return nr > 0 ? result : 0.0; } } -static inline double -dphidtheta_integrand(double Z, void *ctx) +static inline double dphidtheta_integrand(double Z, void *ctx) { struct contour_ctx *c = ctx; c->ncall += 1; - double R[4] = { 0 }, dRdZ[4] = { 0 }; - double dR[4] = { 0 }, dZ[4] = { 0 }; - + double R[4] = {0}, dRdZ[4] = {0}; + double dR[4] = {0}, dZ[4] = {0}; + int nr = gkyl_tok_geo_R_psiZ(c->geo, c->psi, Z, 4, R, dRdZ, dR, dZ); double drdz = nr == 1 ? dRdZ[0] : choose_closest(c->last_R, R, dRdZ, nr); double r_curr = nr == 1 ? R[0] : choose_closest(c->last_R, R, R, nr); @@ -617,18 +872,19 @@ dphidtheta_integrand(double Z, void *ctx) c->geo->efit->evf->eval_cubic_wgrad(0.0, xn, fout, c->geo->efit->evf->ctx); double dpsidR = fout[1]; double dpsidZ = fout[2]; - double grad_psi_mag = sqrt(dpsidR*dpsidR + dpsidZ*dpsidZ); + double grad_psi_mag = sqrt(dpsidR * dpsidR + dpsidZ * dpsidZ); - double result = (1/r_curr/grad_psi_mag); - return nr>0 ? result : 0.0; - } - else { + double result = (1 / r_curr / grad_psi_mag); + return nr > 0 ? result : 0.0; + } else { int rzidx[2]; - int idxtemp = c->geo->rzlocal.lower[0] + (int) floor((r_curr - c->geo->rzgrid.lower[0])/c->geo->rzgrid.dx[0]); + int idxtemp = c->geo->rzlocal.lower[0] + + (int)floor((r_curr - c->geo->rzgrid.lower[0]) / c->geo->rzgrid.dx[0]); idxtemp = GKYL_MIN2(idxtemp, c->geo->rzlocal.upper[0]); idxtemp = GKYL_MAX2(idxtemp, c->geo->rzlocal.lower[0]); rzidx[0] = idxtemp; - idxtemp = c->geo->rzlocal.lower[1] + (int) floor((Z - c->geo->rzgrid.lower[1])/c->geo->rzgrid.dx[1]); + idxtemp = + c->geo->rzlocal.lower[1] + (int)floor((Z - c->geo->rzgrid.lower[1]) / c->geo->rzgrid.dx[1]); idxtemp = GKYL_MIN2(idxtemp, c->geo->rzlocal.upper[1]); idxtemp = GKYL_MAX2(idxtemp, c->geo->rzlocal.lower[1]); rzidx[1] = idxtemp; @@ -638,13 +894,13 @@ dphidtheta_integrand(double Z, void *ctx) double xc[2]; gkyl_rect_grid_cell_center((&c->geo->rzgrid), rzidx, xc); - double x = (r_curr-xc[0])/(c->geo->rzgrid.dx[0]*0.5); - double y = (Z-xc[1])/(c->geo->rzgrid.dx[1]*0.5); + double x = (r_curr - xc[0]) / (c->geo->rzgrid.dx[0] * 0.5); + double y = (Z - xc[1]) / (c->geo->rzgrid.dx[1] * 0.5); - double eta[2] = {x,y}; + double eta[2] = {x, y}; double grad_psi_mag = c->geo->calc_grad_psi(psih, eta, c->geo->rzgrid.dx); - double result = (1/r_curr/grad_psi_mag); - return nr>0 ? result : 0.0; + double result = (1 / r_curr / grad_psi_mag); + return nr > 0 ? result : 0.0; } } @@ -654,66 +910,54 @@ dphidtheta_integrand(double Z, void *ctx) // over z-cells. This needs to be done as the DG representation is, // well, discontinuous, and adaptive quadrature struggles with such // functions. -static double -integrate_psi_contour_memo(const struct gkyl_tok_geo *geo, double psi, - double zmin, double zmax, double rclose, - bool use_memo, bool fill_memo, double *memo) +static double integrate_psi_contour_memo( + const struct gkyl_tok_geo *geo, double psi, double zmin, double zmax, double rclose, + bool use_memo, bool fill_memo, double *memo +) { - struct contour_ctx ctx = { - .geo = geo, - .psi = psi, - .ncall = 0, - .last_R = rclose - }; + struct contour_ctx ctx = {.geo = geo, .psi = psi, .ncall = 0, .last_R = rclose}; int nlevels = geo->quad_param.max_level; double eps = geo->quad_param.eps; - struct gkyl_rect_grid rzgrid ; + struct gkyl_rect_grid rzgrid; struct gkyl_range rzlocal; - if(geo->use_cubics) { + if (geo->use_cubics) { rzgrid = geo->rzgrid_cubic; rzlocal = geo->rzlocal_cubic; - } - else { + } else { rzgrid = geo->rzgrid; rzlocal = geo->rzlocal; } - + double dz = rzgrid.dx[1]; double zlo = rzgrid.lower[1]; int izlo = rzlocal.lower[1], izup = rzlocal.upper[1]; - + int ilo = get_idx(1, zmin, &rzgrid, &rzlocal); int iup = get_idx(1, zmax, &rzgrid, &rzlocal); double res = 0.0; - for (int i=ilo; i<=iup; ++i) { - double z1 = gkyl_median(zmin, zlo+(i-izlo)*dz, zlo+(i-izlo+1)*dz); - double z2 = gkyl_median(zmax, zlo+(i-izlo)*dz, zlo+(i-izlo+1)*dz); - + for (int i = ilo; i <= iup; ++i) { + double z1 = gkyl_median(zmin, zlo + (i - izlo) * dz, zlo + (i - izlo + 1) * dz); + double z2 = gkyl_median(zmax, zlo + (i - izlo) * dz, zlo + (i - izlo + 1) * dz); + if (z1 < z2) { if (use_memo) { if (fill_memo) { - struct gkyl_qr_res res_local = - gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); - memo[i-izlo] = res_local.res; + struct gkyl_qr_res res_local = gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); + memo[i - izlo] = res_local.res; res += res_local.res; - } - else { - if (z2-z1 == dz) { - res += memo[i-izlo]; - } - else { - struct gkyl_qr_res res_local = - gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); + } else { + if (z2 - z1 == dz) { + res += memo[i - izlo]; + } else { + struct gkyl_qr_res res_local = gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); res += res_local.res; } } - } - else { - struct gkyl_qr_res res_local = - gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); + } else { + struct gkyl_qr_res res_local = gkyl_dbl_exp(contour_func, &ctx, z1, z2, nlevels, eps); res += res_local.res; } } @@ -723,66 +967,55 @@ integrate_psi_contour_memo(const struct gkyl_tok_geo *geo, double psi, return res; } -static double -integrate_phi_along_psi_contour_memo(const struct gkyl_tok_geo *geo, double psi, - double zmin, double zmax, double rclose, - bool use_memo, bool fill_memo, double *memo) +static double integrate_phi_along_psi_contour_memo( + const struct gkyl_tok_geo *geo, double psi, double zmin, double zmax, double rclose, + bool use_memo, bool fill_memo, double *memo +) { - struct contour_ctx ctx = { - .geo = geo, - .psi = psi, - .ncall = 0, - .last_R = rclose - }; + struct contour_ctx ctx = {.geo = geo, .psi = psi, .ncall = 0, .last_R = rclose}; int nlevels = geo->quad_param.max_level; double eps = geo->quad_param.eps; - struct gkyl_rect_grid rzgrid ; + struct gkyl_rect_grid rzgrid; struct gkyl_range rzlocal; - if(geo->use_cubics) { + if (geo->use_cubics) { rzgrid = geo->rzgrid_cubic; rzlocal = geo->rzlocal_cubic; - } - else { + } else { rzgrid = geo->rzgrid; rzlocal = geo->rzlocal; } - + double dz = rzgrid.dx[1]; double zlo = rzgrid.lower[1]; int izlo = rzlocal.lower[1], izup = rzlocal.upper[1]; - + int ilo = get_idx(1, zmin, &rzgrid, &rzlocal); int iup = get_idx(1, zmax, &rzgrid, &rzlocal); double res = 0.0; - for (int i=ilo; i<=iup; ++i) { - double z1 = gkyl_median(zmin, zlo+(i-izlo)*dz, zlo+(i-izlo+1)*dz); - double z2 = gkyl_median(zmax, zlo+(i-izlo)*dz, zlo+(i-izlo+1)*dz); - + for (int i = ilo; i <= iup; ++i) { + double z1 = gkyl_median(zmin, zlo + (i - izlo) * dz, zlo + (i - izlo + 1) * dz); + double z2 = gkyl_median(zmax, zlo + (i - izlo) * dz, zlo + (i - izlo + 1) * dz); + if (z1 < z2) { if (use_memo) { if (fill_memo) { - struct gkyl_qr_res res_local = - gkyl_dbl_exp(phi_contour_func, &ctx, z1, z2, nlevels, eps); - memo[i-izlo] = res_local.res; + struct gkyl_qr_res res_local = gkyl_dbl_exp(phi_contour_func, &ctx, z1, z2, nlevels, eps); + memo[i - izlo] = res_local.res; res += res_local.res; - } - else { - if (z2-z1 == dz) { - res += memo[i-izlo]; - } - else { + } else { + if (z2 - z1 == dz) { + res += memo[i - izlo]; + } else { struct gkyl_qr_res res_local = gkyl_dbl_exp(phi_contour_func, &ctx, z1, z2, nlevels, eps); res += res_local.res; } } - } - else { - struct gkyl_qr_res res_local = - gkyl_dbl_exp(phi_contour_func, &ctx, z1, z2, nlevels, eps); + } else { + struct gkyl_qr_res res_local = gkyl_dbl_exp(phi_contour_func, &ctx, z1, z2, nlevels, eps); res += res_local.res; } } @@ -792,23 +1025,29 @@ integrate_phi_along_psi_contour_memo(const struct gkyl_tok_geo *geo, double psi, return res; } - double phi_func(double alpha_curr, double Z, void *ctx); double tok_plate_psi_func(double s, void *ctx); /* * Used to set zmin and zmax and attributes of arc_ctx before looping over arc length */ -void tok_find_endpoints(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, struct arc_length_ctx* arc_ctx, struct plate_ctx* pctx, double psi_curr, double alpha_curr, double* arc_memo, double* arc_memo_left, double* arc_memo_right); +void tok_find_endpoints( + struct gkyl_tok_geo_grid_inp *inp, struct gkyl_tok_geo *geo, struct arc_length_ctx *arc_ctx, + struct plate_ctx *pctx, double psi_curr, double alpha_curr, double *arc_memo, + double *arc_memo_left, double *arc_memo_right +); /* * Used to set theta extents when using a global normalization factor * */ -void tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, double *theta_lo, double *theta_up); - +void tok_geo_set_extent( + struct gkyl_tok_geo_grid_inp *inp, struct gkyl_tok_geo *geo, double *theta_lo, double *theta_up +); /* * Used to set arc_ctx attributes before using ridders to find z */ -void tok_set_ridders(struct gkyl_tok_geo_grid_inp* inp, struct arc_length_ctx* arc_ctx, double psi_curr, double arcL_curr, double* rclose, double *ridders_min, double* ridders_max); - +void tok_set_ridders( + struct gkyl_tok_geo_grid_inp *inp, struct arc_length_ctx *arc_ctx, double psi_curr, + double arcL_curr, double *rclose, double *ridders_min, double *ridders_max +); diff --git a/gyrokinetic/zero/gkyl_translate_dim.h b/gyrokinetic/zero/gkyl_translate_dim.h index 0ca93cd762..b1a1e293e2 100644 --- a/gyrokinetic/zero/gkyl_translate_dim.h +++ b/gyrokinetic/zero/gkyl_translate_dim.h @@ -43,10 +43,10 @@ typedef struct gkyl_translate_dim gkyl_translate_dim; * cdim_tar < cdim_do (lower boundary, center, or upper boundary). * @param use_gpu Whether to run it on the GPU or not. */ -struct gkyl_translate_dim* -gkyl_translate_dim_new(int cdim_do, struct gkyl_basis basis_do, - int cdim_tar, struct gkyl_basis basis_tar, int dir, - enum gkyl_edge_loc edge, bool use_gpu); +struct gkyl_translate_dim *gkyl_translate_dim_new( + int cdim_do, struct gkyl_basis basis_do, int cdim_tar, struct gkyl_basis basis_tar, int dir, + enum gkyl_edge_loc edge, bool use_gpu +); /** * Run the updater that translates the DG coefficients of a donor @@ -59,16 +59,14 @@ gkyl_translate_dim_new(int cdim_do, struct gkyl_basis basis_do, * @param ncomp Number of scalar fields in fdo/ftar. * @param ftar target field. */ -void -gkyl_translate_dim_advance(gkyl_translate_dim* up, - const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, - const struct gkyl_array *GKYL_RESTRICT fdo, int ncomp, - struct gkyl_array *GKYL_RESTRICT ftar); +void gkyl_translate_dim_advance( + gkyl_translate_dim *up, const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, + const struct gkyl_array *GKYL_RESTRICT fdo, int ncomp, struct gkyl_array *GKYL_RESTRICT ftar +); /** * Release the memory associated with the translate_dim updater. * * @param up translate_dim updater. */ -void -gkyl_translate_dim_release(gkyl_translate_dim* up); +void gkyl_translate_dim_release(gkyl_translate_dim *up); diff --git a/gyrokinetic/zero/gkyl_translate_dim_priv.h b/gyrokinetic/zero/gkyl_translate_dim_priv.h index b8198b057a..1f5411af94 100644 --- a/gyrokinetic/zero/gkyl_translate_dim_priv.h +++ b/gyrokinetic/zero/gkyl_translate_dim_priv.h @@ -7,12 +7,13 @@ #include #include -static void -translate_dim_range_check_conf_deflate(int dir, int cdim_do, int cdim_tar, int vdim, - const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar) +static void translate_dim_range_check_conf_deflate( + int dir, int cdim_do, int cdim_tar, int vdim, const struct gkyl_range *rng_do, + const struct gkyl_range *rng_tar +) { int c = 0; - for (int d=0; dlower[c] == rng_do->lower[d]); assert(rng_tar->upper[c] == rng_do->upper[d]); @@ -21,137 +22,141 @@ translate_dim_range_check_conf_deflate(int dir, int cdim_do, int cdim_tar, int v } } -static void -translate_dim_range_check_conf_inflate(int dir, int cdim_do, int cdim_tar, int vdim, - const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar) +static void translate_dim_range_check_conf_inflate( + int dir, int cdim_do, int cdim_tar, int vdim, const struct gkyl_range *rng_do, + const struct gkyl_range *rng_tar +) { - for (int d=0; dlower[d] == rng_tar->lower[d]); assert(rng_do->upper[d] == rng_tar->upper[d]); } - assert(rng_do->lower[cdim_do-1] == rng_tar->lower[cdim_tar-1]); - assert(rng_do->upper[cdim_do-1] == rng_tar->upper[cdim_tar-1]); + assert(rng_do->lower[cdim_do - 1] == rng_tar->lower[cdim_tar - 1]); + assert(rng_do->upper[cdim_do - 1] == rng_tar->upper[cdim_tar - 1]); } -static void -translate_dim_range_check_phase_deflate(int dir, int cdim_do, int cdim_tar, int vdim, - const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar) +static void translate_dim_range_check_phase_deflate( + int dir, int cdim_do, int cdim_tar, int vdim, const struct gkyl_range *rng_do, + const struct gkyl_range *rng_tar +) { - translate_dim_range_check_conf_deflate(dir, cdim_do, cdim_tar, vdim, - rng_do, rng_tar); - for (int d=0; dlower[cdim_do+d] == rng_tar->lower[cdim_tar+d]); - assert(rng_do->upper[cdim_do+d] == rng_tar->upper[cdim_tar+d]); + translate_dim_range_check_conf_deflate(dir, cdim_do, cdim_tar, vdim, rng_do, rng_tar); + for (int d = 0; d < vdim; d++) { + assert(rng_do->lower[cdim_do + d] == rng_tar->lower[cdim_tar + d]); + assert(rng_do->upper[cdim_do + d] == rng_tar->upper[cdim_tar + d]); }; } -static void -translate_dim_range_check_phase_inflate(int dir, int cdim_do, int cdim_tar, int vdim, - const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar) +static void translate_dim_range_check_phase_inflate( + int dir, int cdim_do, int cdim_tar, int vdim, const struct gkyl_range *rng_do, + const struct gkyl_range *rng_tar +) { - translate_dim_range_check_conf_inflate(dir, cdim_do, cdim_tar, vdim, - rng_do, rng_tar); - for (int d=0; dlower[cdim_do+d] == rng_tar->lower[cdim_tar+d]); - assert(rng_do->upper[cdim_do+d] == rng_tar->upper[cdim_tar+d]); + translate_dim_range_check_conf_inflate(dir, cdim_do, cdim_tar, vdim, rng_do, rng_tar); + for (int d = 0; d < vdim; d++) { + assert(rng_do->lower[cdim_do + d] == rng_tar->lower[cdim_tar + d]); + assert(rng_do->upper[cdim_do + d] == rng_tar->upper[cdim_tar + d]); }; } // Function pointer type for sheath reflection kernels. typedef void (*translate_dim_t)(const double *fdo, double *ftar); -typedef struct {translate_dim_t kernels[3];} trans_dim_kern_list; // For use in kernel tables. -typedef struct {trans_dim_kern_list list[9];} trans_dim_kern_list_updown; // For use in kernel tables. +typedef struct { + translate_dim_t kernels[3]; +} trans_dim_kern_list; // For use in kernel tables. +typedef struct { + trans_dim_kern_list list[9]; +} trans_dim_kern_list_updown; // For use in kernel tables. // Serendipity kernels. -GKYL_CU_D -static const trans_dim_kern_list_updown trans_dim_kern_list_ser[] = { - // 1x - { .list = { - {NULL, NULL, NULL }, - {NULL, NULL, NULL }, - {NULL, NULL, NULL }, - {translate_dim_1x_ser_p1_to_2x_p1, NULL, NULL }, - {NULL, NULL, NULL }, - {NULL, NULL, NULL }, - {NULL, NULL, NULL }, - {NULL, NULL, NULL }, - {NULL, NULL, NULL }, - }, - }, +GKYL_CU_D static const trans_dim_kern_list_updown trans_dim_kern_list_ser[] = { // 1x + {.list = + {{NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {translate_dim_1x_ser_p1_to_2x_p1, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}}}, // 2x - { .list = { - { translate_dim_2x_ser_p1_to_1x_p1_dirx_lo , NULL, NULL }, - { translate_dim_2x_ser_p1_to_1x_p1_dirx_mid, NULL, NULL }, - { translate_dim_2x_ser_p1_to_1x_p1_dirx_up , NULL, NULL }, - { translate_dim_2x_ser_p1_to_1x_p1_diry_lo , NULL, NULL }, - { translate_dim_2x_ser_p1_to_1x_p1_diry_mid, NULL, NULL }, - { translate_dim_2x_ser_p1_to_1x_p1_diry_up , NULL, NULL }, - { translate_dim_2x_ser_p1_to_3x_p1, NULL, NULL }, - {NULL, NULL, NULL }, - {NULL, NULL, NULL }, - }, - }, + {.list = + {{translate_dim_2x_ser_p1_to_1x_p1_dirx_lo, NULL, NULL}, + {translate_dim_2x_ser_p1_to_1x_p1_dirx_mid, NULL, NULL}, + {translate_dim_2x_ser_p1_to_1x_p1_dirx_up, NULL, NULL}, + {translate_dim_2x_ser_p1_to_1x_p1_diry_lo, NULL, NULL}, + {translate_dim_2x_ser_p1_to_1x_p1_diry_mid, NULL, NULL}, + {translate_dim_2x_ser_p1_to_1x_p1_diry_up, NULL, NULL}, + {translate_dim_2x_ser_p1_to_3x_p1, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}}}, // 3x - { .list = { - { translate_dim_3x_ser_p1_to_2x_p1_dirx_lo , NULL, NULL }, - { translate_dim_3x_ser_p1_to_2x_p1_dirx_mid, NULL, NULL }, - { translate_dim_3x_ser_p1_to_2x_p1_dirx_up , NULL, NULL }, - { translate_dim_3x_ser_p1_to_2x_p1_diry_lo , NULL, NULL }, - { translate_dim_3x_ser_p1_to_2x_p1_diry_mid, NULL, NULL }, - { translate_dim_3x_ser_p1_to_2x_p1_diry_up , NULL, NULL }, - { translate_dim_3x_ser_p1_to_2x_p1_dirz_lo , NULL, NULL }, - { translate_dim_3x_ser_p1_to_2x_p1_dirz_mid, NULL, NULL }, - { translate_dim_3x_ser_p1_to_2x_p1_dirz_up , NULL, NULL }, - }, - }, + {.list = + {{translate_dim_3x_ser_p1_to_2x_p1_dirx_lo, NULL, NULL}, + {translate_dim_3x_ser_p1_to_2x_p1_dirx_mid, NULL, NULL}, + {translate_dim_3x_ser_p1_to_2x_p1_dirx_up, NULL, NULL}, + {translate_dim_3x_ser_p1_to_2x_p1_diry_lo, NULL, NULL}, + {translate_dim_3x_ser_p1_to_2x_p1_diry_mid, NULL, NULL}, + {translate_dim_3x_ser_p1_to_2x_p1_diry_up, NULL, NULL}, + {translate_dim_3x_ser_p1_to_2x_p1_dirz_lo, NULL, NULL}, + {translate_dim_3x_ser_p1_to_2x_p1_dirz_mid, NULL, NULL}, + {translate_dim_3x_ser_p1_to_2x_p1_dirz_up, NULL, NULL}}} }; // GkHybrid kernels. -GKYL_CU_D -static const trans_dim_kern_list trans_dim_kern_list_gkhyb[] = { - { translate_dim_gyrokinetic_2x2v_ser_p1_from_1x2v_p1, NULL, NULL }, - { translate_dim_gyrokinetic_3x2v_ser_p1_from_1x2v_p1, NULL, NULL }, - { translate_dim_gyrokinetic_3x2v_ser_p1_from_2x2v_p1, NULL, NULL }, +GKYL_CU_D static const trans_dim_kern_list trans_dim_kern_list_gkhyb[] = { + {translate_dim_gyrokinetic_2x2v_ser_p1_from_1x2v_p1, NULL, NULL}, + {translate_dim_gyrokinetic_3x2v_ser_p1_from_1x2v_p1, NULL, NULL}, + {translate_dim_gyrokinetic_3x2v_ser_p1_from_2x2v_p1, NULL, NULL} }; struct gkyl_translate_dim_kernels { - translate_dim_t translate; // Kernel that translate the DG coefficients. - void (*get_idx_do)(int cdim_tar, int vdim, const int *idx_tar, - const struct gkyl_range *rng_do, int cdim_do, int *idx_do, int dir); + translate_dim_t translate; // Kernel that translate the DG coefficients. + void (*get_idx_do)( + int cdim_tar, int vdim, const int *idx_tar, const struct gkyl_range *rng_do, int cdim_do, + int *idx_do, int dir + ); }; -GKYL_CU_DH -static void -translate_dim_get_idx_do_gk(int cdim_tar, int vdim, const int *idx_tar, - const struct gkyl_range *rng_do, int cdim_do, int *idx_do, int dir) +GKYL_CU_DH static void translate_dim_get_idx_do_gk( + int cdim_tar, int vdim, const int *idx_tar, const struct gkyl_range *rng_do, int cdim_do, + int *idx_do, int dir +) { - for (int d=0; dlower[dir]; } -GKYL_CU_DH -static void -translate_dim_get_idx_do_conf_up(int cdim_tar, int vdim, const int *idx_tar, - const struct gkyl_range *rng_do, int cdim_do, int *idx_do, int dir) +GKYL_CU_DH static void translate_dim_get_idx_do_conf_up( + int cdim_tar, int vdim, const int *idx_tar, const struct gkyl_range *rng_do, int cdim_do, + int *idx_do, int dir +) { - for (int d=0; dtranslate = trans_dim_kern_list_gkhyb[cdim_tar+cdim_do-3].kernels[poly_order-1]; - break; - case GKYL_BASIS_MODAL_SERENDIPITY: - kernels->translate = trans_dim_kern_list_ser[cdim_do-1].list[dir_idx*3+edge_idx].kernels[poly_order-1]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_GKHYBRID: + kernels->translate = trans_dim_kern_list_gkhyb[cdim_tar + cdim_do - 3].kernels[poly_order - 1]; + break; + case GKYL_BASIS_MODAL_SERENDIPITY: + kernels->translate = + trans_dim_kern_list_ser[cdim_do - 1].list[dir_idx * 3 + edge_idx].kernels[poly_order - 1]; + break; + default: + assert(false); + break; } // Choose the function that populates the donor index. int vdim = basis_do.ndim - cdim_do; if (vdim > 0) { kernels->get_idx_do = translate_dim_get_idx_do_gk; - } - else { - if (cdim_tar < cdim_do) + } else { + if (cdim_tar < cdim_do) { kernels->get_idx_do = translate_dim_get_idx_do_conf_down; - else + } else { kernels->get_idx_do = translate_dim_get_idx_do_conf_up; + } } } diff --git a/gyrokinetic/zero/gyrokinetic_cross_prim_moms_bgk.c b/gyrokinetic/zero/gyrokinetic_cross_prim_moms_bgk.c index 653f3064ff..3ca2ce6267 100644 --- a/gyrokinetic/zero/gyrokinetic_cross_prim_moms_bgk.c +++ b/gyrokinetic/zero/gyrokinetic_cross_prim_moms_bgk.c @@ -4,39 +4,43 @@ #include #include -gkyl_gyrokinetic_cross_prim_moms_bgk* -gkyl_gyrokinetic_cross_prim_moms_bgk_new(const struct gkyl_basis *phase_basis, - const struct gkyl_basis *conf_basis, bool use_gpu) +gkyl_gyrokinetic_cross_prim_moms_bgk *gkyl_gyrokinetic_cross_prim_moms_bgk_new( + const struct gkyl_basis *phase_basis, const struct gkyl_basis *conf_basis, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { - return gkyl_gyrokinetic_cross_prim_moms_bgk_cu_dev_new(phase_basis, conf_basis); + return gkyl_gyrokinetic_cross_prim_moms_bgk_cu_dev_new(phase_basis, conf_basis); } #endif gkyl_gyrokinetic_cross_prim_moms_bgk *up = gkyl_malloc(sizeof(*up)); up->use_gpu = use_gpu; // Select the kernel. - up->cross_prim_moms_calc = choose_gyrokinetic_cross_prim_moms_bgk_kern(conf_basis->ndim, - phase_basis->ndim-conf_basis->ndim, phase_basis->poly_order); - + up->cross_prim_moms_calc = choose_gyrokinetic_cross_prim_moms_bgk_kern( + conf_basis->ndim, phase_basis->ndim - conf_basis->ndim, phase_basis->poly_order + ); + up->on_dev = up; // host-side points to itself - return up; + return up; } -void gkyl_gyrokinetic_cross_prim_moms_bgk_advance(gkyl_gyrokinetic_cross_prim_moms_bgk *up, - const struct gkyl_range *conf_rng, double delta_sr, double betap1, - double m_self, const struct gkyl_array *prim_moms_self, double m_other, const struct gkyl_array *prim_moms_other, - struct gkyl_array *prim_moms_cross) +void gkyl_gyrokinetic_cross_prim_moms_bgk_advance( + gkyl_gyrokinetic_cross_prim_moms_bgk *up, const struct gkyl_range *conf_rng, double delta_sr, + double betap1, double m_self, const struct gkyl_array *prim_moms_self, double m_other, + const struct gkyl_array *prim_moms_other, struct gkyl_array *prim_moms_cross +) { #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) { - return gkyl_gyrokinetic_cross_prim_moms_bgk_advance_cu(up, conf_rng, delta_sr, betap1, - m_self, prim_moms_self, m_other, prim_moms_other, prim_moms_cross); + if (up->use_gpu) { + return gkyl_gyrokinetic_cross_prim_moms_bgk_advance_cu( + up, conf_rng, delta_sr, betap1, m_self, prim_moms_self, m_other, prim_moms_other, + prim_moms_cross + ); } #endif - struct gkyl_range_iter conf_iter; - + struct gkyl_range_iter conf_iter; + // loop over configuration space cells gkyl_range_iter_init(&conf_iter, conf_rng); while (gkyl_range_iter_next(&conf_iter)) { @@ -45,15 +49,17 @@ void gkyl_gyrokinetic_cross_prim_moms_bgk_advance(gkyl_gyrokinetic_cross_prim_mo const double *prim_moms_other_d = gkyl_array_cfetch(prim_moms_other, midx); double *out_d = gkyl_array_fetch(prim_moms_cross, midx); - up->cross_prim_moms_calc(delta_sr, betap1, m_self, prim_moms_self_d, - m_other, prim_moms_other_d, out_d); + up->cross_prim_moms_calc( + delta_sr, betap1, m_self, prim_moms_self_d, m_other, prim_moms_other_d, out_d + ); } } void gkyl_gyrokinetic_cross_prim_moms_bgk_release(gkyl_gyrokinetic_cross_prim_moms_bgk *up) { - if (up->use_gpu) + if (up->use_gpu) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/gyrokinetic/zero/gyrokinetic_cross_prim_moms_bgk_cu.cu b/gyrokinetic/zero/gyrokinetic_cross_prim_moms_bgk_cu.cu index 05ba437512..3247a7a126 100644 --- a/gyrokinetic/zero/gyrokinetic_cross_prim_moms_bgk_cu.cu +++ b/gyrokinetic/zero/gyrokinetic_cross_prim_moms_bgk_cu.cu @@ -12,18 +12,16 @@ extern "C" { #include } -__global__ void -gkyl_gyrokinetic_cross_prim_moms_bgk_advance_cu_kernel(gkyl_gyrokinetic_cross_prim_moms_bgk *up, - struct gkyl_range conf_range, double delta_sr, double betap1, - double m_self, const struct gkyl_array *prim_moms_self, double m_other, const struct gkyl_array *prim_moms_other, - struct gkyl_array *prim_moms_cross) -{ +__global__ void gkyl_gyrokinetic_cross_prim_moms_bgk_advance_cu_kernel( + gkyl_gyrokinetic_cross_prim_moms_bgk *up, struct gkyl_range conf_range, double delta_sr, + double betap1, double m_self, const struct gkyl_array *prim_moms_self, double m_other, + const struct gkyl_array *prim_moms_other, struct gkyl_array *prim_moms_cross +) +{ int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -33,47 +31,54 @@ gkyl_gyrokinetic_cross_prim_moms_bgk_advance_cu_kernel(gkyl_gyrokinetic_cross_pr // linc will have jumps in it to jump over ghost cells long loc_conf = gkyl_range_idx(&conf_range, idx); - const double *prim_moms_self_d = (const double*) gkyl_array_cfetch(prim_moms_self, loc_conf); - const double *prim_moms_other_d = (const double*) gkyl_array_cfetch(prim_moms_other, loc_conf); - double *out_d = (double*) gkyl_array_fetch(prim_moms_cross, loc_conf); + const double *prim_moms_self_d = (const double *)gkyl_array_cfetch(prim_moms_self, loc_conf); + const double *prim_moms_other_d = (const double *)gkyl_array_cfetch(prim_moms_other, loc_conf); + double *out_d = (double *)gkyl_array_fetch(prim_moms_cross, loc_conf); - up->cross_prim_moms_calc(delta_sr, betap1, m_self, prim_moms_self_d, m_other, prim_moms_other_d, out_d); + up->cross_prim_moms_calc( + delta_sr, betap1, m_self, prim_moms_self_d, m_other, prim_moms_other_d, out_d + ); } } // Host-side wrapper for cross BGK moments -void -gkyl_gyrokinetic_cross_prim_moms_bgk_advance_cu(gkyl_gyrokinetic_cross_prim_moms_bgk *up, - const struct gkyl_range *conf_range, double delta_sr, double betap1, - double m_self, const struct gkyl_array *prim_moms_self, double m_other, const struct gkyl_array *prim_moms_other, - struct gkyl_array *prim_moms_cross) +void gkyl_gyrokinetic_cross_prim_moms_bgk_advance_cu( + gkyl_gyrokinetic_cross_prim_moms_bgk *up, const struct gkyl_range *conf_range, double delta_sr, + double betap1, double m_self, const struct gkyl_array *prim_moms_self, double m_other, + const struct gkyl_array *prim_moms_other, struct gkyl_array *prim_moms_cross +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_gyrokinetic_cross_prim_moms_bgk_advance_cu_kernel<<>>(up->on_dev, - *conf_range, delta_sr, betap1, m_self, prim_moms_self->on_dev, m_other, prim_moms_other->on_dev, - prim_moms_cross->on_dev); + gkyl_gyrokinetic_cross_prim_moms_bgk_advance_cu_kernel<< > >( + up->on_dev, *conf_range, delta_sr, betap1, m_self, prim_moms_self->on_dev, m_other, + prim_moms_other->on_dev, prim_moms_cross->on_dev + ); } -__global__ -static void -set_gyrokinetic_cross_prim_moms_bgk_cu_ptrs(struct gkyl_gyrokinetic_cross_prim_moms_bgk *up, int cdim, int vdim, int poly_order) +__global__ static void set_gyrokinetic_cross_prim_moms_bgk_cu_ptrs( + struct gkyl_gyrokinetic_cross_prim_moms_bgk *up, int cdim, int vdim, int poly_order +) { - up->cross_prim_moms_calc = choose_gyrokinetic_cross_prim_moms_bgk_kern(cdim, vdim, poly_order); + up->cross_prim_moms_calc = choose_gyrokinetic_cross_prim_moms_bgk_kern(cdim, vdim, poly_order); } -gkyl_gyrokinetic_cross_prim_moms_bgk* -gkyl_gyrokinetic_cross_prim_moms_bgk_cu_dev_new(const struct gkyl_basis *phase_basis, const struct gkyl_basis *conf_basis) +gkyl_gyrokinetic_cross_prim_moms_bgk *gkyl_gyrokinetic_cross_prim_moms_bgk_cu_dev_new( + const struct gkyl_basis *phase_basis, const struct gkyl_basis *conf_basis +) { - struct gkyl_gyrokinetic_cross_prim_moms_bgk *up = (struct gkyl_gyrokinetic_cross_prim_moms_bgk*) gkyl_malloc(sizeof(*up)); + struct gkyl_gyrokinetic_cross_prim_moms_bgk *up = + (struct gkyl_gyrokinetic_cross_prim_moms_bgk *)gkyl_malloc(sizeof(*up)); up->use_gpu = true; - + // copy struct to device - struct gkyl_gyrokinetic_cross_prim_moms_bgk *up_cu = (struct gkyl_gyrokinetic_cross_prim_moms_bgk*) gkyl_cu_malloc(sizeof(*up_cu)); - - set_gyrokinetic_cross_prim_moms_bgk_cu_ptrs<<<1,1>>>(up_cu, conf_basis->ndim, - phase_basis->ndim-conf_basis->ndim, phase_basis->poly_order); + struct gkyl_gyrokinetic_cross_prim_moms_bgk *up_cu = + (struct gkyl_gyrokinetic_cross_prim_moms_bgk *)gkyl_cu_malloc(sizeof(*up_cu)); + + set_gyrokinetic_cross_prim_moms_bgk_cu_ptrs<<<1, 1> > >( + up_cu, conf_basis->ndim, phase_basis->ndim - conf_basis->ndim, phase_basis->poly_order + ); - up->on_dev = up_cu; - return up; + up->on_dev = up_cu; + return up; } diff --git a/gyrokinetic/zero/gyrokinetic_pol_density.c b/gyrokinetic/zero/gyrokinetic_pol_density.c index 56fdec224e..b0e4470774 100644 --- a/gyrokinetic/zero/gyrokinetic_pol_density.c +++ b/gyrokinetic/zero/gyrokinetic_pol_density.c @@ -2,9 +2,8 @@ #include #include -struct gkyl_gyrokinetic_pol_density* -gkyl_gyrokinetic_pol_density_new(struct gkyl_basis cbasis, struct gkyl_rect_grid cgrid, - bool use_gpu) +struct gkyl_gyrokinetic_pol_density * +gkyl_gyrokinetic_pol_density_new(struct gkyl_basis cbasis, struct gkyl_rect_grid cgrid, bool use_gpu) { // Allocate space for new updater. struct gkyl_gyrokinetic_pol_density *up = gkyl_malloc(sizeof(*up)); @@ -28,10 +27,11 @@ gkyl_gyrokinetic_pol_density_new(struct gkyl_basis cbasis, struct gkyl_rect_grid return up; } -void -gkyl_gyrokinetic_pol_density_advance(gkyl_gyrokinetic_pol_density* up, - const struct gkyl_range *conf_rng, const struct gkyl_array *GKYL_RESTRICT pol_weight, - const struct gkyl_array *GKYL_RESTRICT phi, struct gkyl_array *GKYL_RESTRICT npol) +void gkyl_gyrokinetic_pol_density_advance( + gkyl_gyrokinetic_pol_density *up, const struct gkyl_range *conf_rng, + const struct gkyl_array *GKYL_RESTRICT pol_weight, const struct gkyl_array *GKYL_RESTRICT phi, + struct gkyl_array *GKYL_RESTRICT npol +) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { @@ -51,11 +51,9 @@ gkyl_gyrokinetic_pol_density_advance(gkyl_gyrokinetic_pol_density* up, up->kernels->pol_den(up->grid.dx, pol_weight_d, phi_d, npol_d); } - } -void -gkyl_gyrokinetic_pol_density_release(gkyl_gyrokinetic_pol_density* up) +void gkyl_gyrokinetic_pol_density_release(gkyl_gyrokinetic_pol_density *up) { // Release memory associated with this updater. if (!up->use_gpu) { diff --git a/gyrokinetic/zero/gyrokinetic_pol_density_cu.cu b/gyrokinetic/zero/gyrokinetic_pol_density_cu.cu index bcbd7a100c..b68b7d34e8 100644 --- a/gyrokinetic/zero/gyrokinetic_pol_density_cu.cu +++ b/gyrokinetic/zero/gyrokinetic_pol_density_cu.cu @@ -6,60 +6,61 @@ extern "C" { } // CUDA kernel to set device pointers to kernels. -__global__ static void -gkyl_gk_pol_den_set_cu_ker_ptrs(struct gkyl_gyrokinetic_pol_density_kernels *kernels, - struct gkyl_basis cbasis) +__global__ static void gkyl_gk_pol_den_set_cu_ker_ptrs( + struct gkyl_gyrokinetic_pol_density_kernels *kernels, struct gkyl_basis cbasis +) { int pdim = cbasis.ndim; enum gkyl_basis_type b_type = cbasis.b_type; int poly_order = cbasis.poly_order; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - kernels->pol_den = gk_pol_density_kern_list_ser[pdim-1].kernels[poly_order-1]; - break; - default: - assert(false); + case GKYL_BASIS_MODAL_SERENDIPITY: + kernels->pol_den = gk_pol_density_kern_list_ser[pdim - 1].kernels[poly_order - 1]; + break; + default: + assert(false); } }; -void -gk_pol_den_choose_kernel_cu(struct gkyl_gyrokinetic_pol_density_kernels *kernels, - struct gkyl_basis cbasis) +void gk_pol_den_choose_kernel_cu( + struct gkyl_gyrokinetic_pol_density_kernels *kernels, struct gkyl_basis cbasis +) { - gkyl_gk_pol_den_set_cu_ker_ptrs<<<1,1>>>(kernels, cbasis); + gkyl_gk_pol_den_set_cu_ker_ptrs<<<1, 1> > >(kernels, cbasis); } -__global__ static void -gkyl_gyrokinetic_pol_density_advance_cu_ker( - struct gkyl_gyrokinetic_pol_density_kernels *kers, - const struct gkyl_rect_grid grid, const struct gkyl_range conf_range, - const struct gkyl_array* GKYL_RESTRICT pol_weight, const struct gkyl_array* GKYL_RESTRICT phi, - struct gkyl_array* GKYL_RESTRICT npol) +__global__ static void gkyl_gyrokinetic_pol_density_advance_cu_ker( + struct gkyl_gyrokinetic_pol_density_kernels *kers, const struct gkyl_rect_grid grid, + const struct gkyl_range conf_range, const struct gkyl_array *GKYL_RESTRICT pol_weight, + const struct gkyl_array *GKYL_RESTRICT phi, struct gkyl_array *GKYL_RESTRICT npol +) { int cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_range.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_range, tid, cidx); long linidx = gkyl_range_idx(&conf_range, cidx); - const double *pol_weight_d = (const double*) gkyl_array_cfetch(pol_weight, linidx); - const double *phi_d = (const double*) gkyl_array_cfetch(phi, linidx); - double *npol_d = (double*) gkyl_array_fetch(npol, linidx); + const double *pol_weight_d = (const double *)gkyl_array_cfetch(pol_weight, linidx); + const double *phi_d = (const double *)gkyl_array_cfetch(phi, linidx); + double *npol_d = (double *)gkyl_array_fetch(npol, linidx); // Compute the polarization density. kers->pol_den(grid.dx, pol_weight_d, phi_d, npol_d); } } -void -gkyl_gyrokinetic_pol_density_advance_cu(gkyl_gyrokinetic_pol_density* up, - const struct gkyl_range *conf_rng, const struct gkyl_array *GKYL_RESTRICT pol_weight, - const struct gkyl_array *GKYL_RESTRICT phi, struct gkyl_array *GKYL_RESTRICT npol) +void gkyl_gyrokinetic_pol_density_advance_cu( + gkyl_gyrokinetic_pol_density *up, const struct gkyl_range *conf_rng, + const struct gkyl_array *GKYL_RESTRICT pol_weight, const struct gkyl_array *GKYL_RESTRICT phi, + struct gkyl_array *GKYL_RESTRICT npol +) { int nblocks = conf_rng->nblocks, nthreads = conf_rng->nthreads; - gkyl_gyrokinetic_pol_density_advance_cu_ker<<>> - (up->kernels, up->grid, *conf_rng, pol_weight->on_dev, phi->on_dev, npol->on_dev); + gkyl_gyrokinetic_pol_density_advance_cu_ker<< > >( + up->kernels, up->grid, *conf_rng, pol_weight->on_dev, phi->on_dev, npol->on_dev + ); } diff --git a/gyrokinetic/zero/loss_cone_mask_gyrokinetic.c b/gyrokinetic/zero/loss_cone_mask_gyrokinetic.c index 8eee0f3ef6..470bc237a8 100644 --- a/gyrokinetic/zero/loss_cone_mask_gyrokinetic.c +++ b/gyrokinetic/zero/loss_cone_mask_gyrokinetic.c @@ -23,8 +23,12 @@ static inline struct gkyl_range get_qrange(int cdim, int dim, int num_quad, int num_quad_v, bool *is_vdim_p2) { int qshape[GKYL_MAX_DIM]; - for (int i=0; indim; int num_quad_v = num_quad; // Hybrid basis have p=2 in velocity space. - bool is_vdim_p2[2] = {false}; // 2 is the max vdim for GK. + bool is_vdim_p2[2] = {false}; // 2 is the max vdim for GK. if (num_quad > 1 && basis->b_type == GKYL_BASIS_MODAL_GKHYBRID) { - num_quad_v = num_quad+1; - is_vdim_p2[0] = true; // only vpar is quadratic in GK hybrid. + num_quad_v = num_quad + 1; + is_vdim_p2[0] = true; // only vpar is quadratic in GK hybrid. } double ordinates1[num_quad], weights1[num_quad]; @@ -54,29 +59,25 @@ init_quad_values(int cdim, const struct gkyl_basis *basis, enum gkyl_quad_type q // Use pre-computed values if possible (these are more accurate than computing them on the fly). memcpy(ordinates1, gkyl_gauss_ordinates[num_quad], sizeof(double[num_quad])); memcpy(weights1, gkyl_gauss_weights[num_quad], sizeof(double[num_quad])); - } - else { + } else { gkyl_gauleg(-1, 1, ordinates1, weights1, num_quad); } if (num_quad_v <= gkyl_gauss_max) { memcpy(ordinates1_v, gkyl_gauss_ordinates[num_quad_v], sizeof(double[num_quad_v])); memcpy(weights1_v, gkyl_gauss_weights[num_quad_v], sizeof(double[num_quad_v])); - } - else { + } else { gkyl_gauleg(-1, 1, ordinates1_v, weights1_v, num_quad_v); } - } - else if (qtype == GKYL_GAUSS_LOBATTO_QUAD) { - assert( (num_quad > 1) && (num_quad <= gkyl_gauss_max) ); + } else if (qtype == GKYL_GAUSS_LOBATTO_QUAD) { + assert((num_quad > 1) && (num_quad <= gkyl_gauss_max)); // Gauss-Lobatto quadrature memcpy(ordinates1, gkyl_gauss_lobatto_ordinates[num_quad], sizeof(double[num_quad])); memcpy(weights1, gkyl_gauss_lobatto_weights[num_quad], sizeof(double[num_quad])); - assert( (num_quad_v > 1) && (num_quad_v <= gkyl_gauss_max) ); + assert((num_quad_v > 1) && (num_quad_v <= gkyl_gauss_max)); memcpy(ordinates1_v, gkyl_gauss_lobatto_ordinates[num_quad_v], sizeof(double[num_quad_v])); memcpy(weights1_v, gkyl_gauss_lobatto_weights[num_quad_v], sizeof(double[num_quad_v])); - } - else { + } else { fprintf(stderr, "Quadrature rule not available.\n"); assert(false); } @@ -91,8 +92,7 @@ init_quad_values(int cdim, const struct gkyl_basis *basis, enum gkyl_quad_type q if (use_gpu) { *ordinates = gkyl_array_cu_dev_new(GKYL_DOUBLE, ndim, tot_quad); *weights = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, tot_quad); - } - else { + } else { *ordinates = gkyl_array_new(GKYL_DOUBLE, ndim, tot_quad); *weights = gkyl_array_new(GKYL_DOUBLE, 1, tot_quad); } @@ -102,36 +102,42 @@ init_quad_values(int cdim, const struct gkyl_basis *basis, enum gkyl_quad_type q while (gkyl_range_iter_next(&iter)) { int node = gkyl_range_idx(&qrange, iter.idx); - + // set ordinates double *ord = gkyl_array_fetch(ordinates_ho, node); - for (int i=0; inum_basis, tot_quad); - if (use_gpu) + if (use_gpu) { *basis_at_ords = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis->num_basis, tot_quad); - else + } else { *basis_at_ords = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, tot_quad); + } - for (int n=0; neval(gkyl_array_fetch(ordinates_ho, n), gkyl_array_fetch(basis_at_ords_ho, n)); + } // Copy host array to device array. gkyl_array_copy(*ordinates, ordinates_ho); @@ -145,14 +151,16 @@ init_quad_values(int cdim, const struct gkyl_basis *basis, enum gkyl_quad_type q return tot_quad; } -static void -gkyl_loss_cone_mask_gyrokinetic_Dbmag_quad(gkyl_loss_cone_mask_gyrokinetic *up, - const struct gkyl_range *conf_range, const struct gkyl_array *bmag, const double *bmag_max) +static void gkyl_loss_cone_mask_gyrokinetic_Dbmag_quad( + gkyl_loss_cone_mask_gyrokinetic *up, const struct gkyl_range *conf_range, + const struct gkyl_array *bmag, const double *bmag_max +) { // Get bmag_max-bmag at quadrature nodes. #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { return gkyl_loss_cone_mask_gyrokinetic_Dbmag_quad_cu(up, conf_range, bmag, bmag_max); + } #endif int cdim = up->cdim, pdim = up->pdim; @@ -168,18 +176,19 @@ gkyl_loss_cone_mask_gyrokinetic_Dbmag_quad(gkyl_loss_cone_mask_gyrokinetic *up, const double *bmag_d = gkyl_array_cfetch(bmag, linidx); double *Dbmag_quad = gkyl_array_fetch(up->Dbmag_quad, linidx); - // Sum over basis - for (int n=0; nbasis_at_ords_conf, n); - for (int k=0; kpdim = inp->phase_basis->ndim; up->cellwise_trap_loss = inp->cellwise_trap_loss; - int num_quad = inp->num_quad? inp->num_quad : inp->phase_basis->poly_order+1; + int num_quad = inp->num_quad ? inp->num_quad : inp->phase_basis->poly_order + 1; up->norm_fac = 1; - if (!up->cellwise_trap_loss) - up->norm_fac = num_quad == 1? 1.0/pow(sqrt(2.0),up->pdim) : 1.0; + if (!up->cellwise_trap_loss) { + up->norm_fac = num_quad == 1 ? 1.0 / pow(sqrt(2.0), up->pdim) : 1.0; + } if (num_quad == 1) { up->num_basis_conf = 1; up->num_basis_phase = 1; - } - else { + } else { up->num_basis_conf = inp->conf_basis->num_basis; up->num_basis_phase = inp->phase_basis->num_basis; } up->use_gpu = inp->use_gpu; // Initialize data needed for conf-space quadrature. - up->tot_quad_conf = init_quad_values(up->cdim, inp->conf_basis, inp->qtype, num_quad, - &up->ordinates_conf, &up->weights_conf, &up->basis_at_ords_conf, false); + up->tot_quad_conf = init_quad_values( + up->cdim, inp->conf_basis, inp->qtype, num_quad, &up->ordinates_conf, &up->weights_conf, + &up->basis_at_ords_conf, false + ); // Initialize data needed for phase-space quadrature. - up->tot_quad_phase = init_quad_values(up->cdim, inp->phase_basis, inp->qtype, num_quad, - &up->ordinates_phase, &up->weights_phase, &up->basis_at_ords_phase, false); + up->tot_quad_phase = init_quad_values( + up->cdim, inp->phase_basis, inp->qtype, num_quad, &up->ordinates_phase, &up->weights_phase, + &up->basis_at_ords_phase, false + ); - up->fun_at_ords = gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad_phase); // Only used in CPU implementation. + up->fun_at_ords = + gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad_phase); // Only used in CPU implementation. // To avoid creating iterators over ranges in device kernel, we'll // create a map between phase-space and conf-space ordinates. - int num_quad_v = num_quad; // Hybrid basis have p=2 in velocity space. + int num_quad_v = num_quad; // Hybrid basis have p=2 in velocity space. // hybrid basis have p=2 in velocity space. - bool is_vdim_p2[2] = {false}; // 2 is the max vdim for GK. + bool is_vdim_p2[2] = {false}; // 2 is the max vdim for GK. if (num_quad > 1 && inp->phase_basis->b_type == GKYL_BASIS_MODAL_GKHYBRID) { - num_quad_v = num_quad+1; - is_vdim_p2[0] = true; // only vpar is quadratic in GK hybrid. + num_quad_v = num_quad + 1; + is_vdim_p2[0] = true; // only vpar is quadratic in GK hybrid. } up->conf_qrange = get_qrange(up->cdim, up->cdim, num_quad, num_quad_v, is_vdim_p2); up->phase_qrange = get_qrange(up->cdim, up->pdim, num_quad, num_quad_v, is_vdim_p2); @@ -238,107 +252,130 @@ gkyl_loss_cone_mask_gyrokinetic_inew(const struct gkyl_loss_cone_mask_gyrokineti // Allocate device copies of arrays needed for quadrature. int p2c_qidx_ho[up->phase_qrange.volume]; - up->p2c_qidx = (int*) gkyl_cu_malloc(sizeof(int)*up->phase_qrange.volume); + up->p2c_qidx = (int *)gkyl_cu_malloc(sizeof(int) * up->phase_qrange.volume); // Allocate mask_quad at phase-space quadrature points. // Dbmag_quad at configuration-space quadrature points. // qDphiDbmag_quad, the term proportional to (phi-phi_m)/(bmag_max-bmag), at quadrature points. - up->mask_out_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->tot_quad_phase, - inp->conf_range_ext->volume*inp->vel_range->volume); - up->qDphiDbmag_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->tot_quad_conf, inp->conf_range_ext->volume); + up->mask_out_quad = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->tot_quad_phase, inp->conf_range_ext->volume * inp->vel_range->volume + ); + up->qDphiDbmag_quad = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->tot_quad_conf, inp->conf_range_ext->volume); // Allocate the memory for computing the specific phase nodal to modal calculation struct gkyl_mat_mm_array_mem *phase_nodal_to_modal_mem_ho; - phase_nodal_to_modal_mem_ho = gkyl_mat_mm_array_mem_new(up->num_basis_phase, up->tot_quad_phase, 1.0, 0.0, - GKYL_NO_TRANS, GKYL_NO_TRANS, false); + phase_nodal_to_modal_mem_ho = gkyl_mat_mm_array_mem_new( + up->num_basis_phase, up->tot_quad_phase, 1.0, 0.0, GKYL_NO_TRANS, GKYL_NO_TRANS, false + ); // Compute the matrix A for the phase nodal to modal memory - const double *phase_w = (const double*) up->weights_phase->data; - const double *phaseb_o = (const double*) up->basis_at_ords_phase->data; - for (int n=0; ntot_quad_phase; ++n) { - for (int k=0; knum_basis_phase; ++k) - gkyl_mat_set(phase_nodal_to_modal_mem_ho->A, k, n, phase_w[n]*phaseb_o[k+up->num_basis_phase*n]); + const double *phase_w = (const double *)up->weights_phase->data; + const double *phaseb_o = (const double *)up->basis_at_ords_phase->data; + for (int n = 0; n < up->tot_quad_phase; ++n) { + for (int k = 0; k < up->num_basis_phase; ++k) { + gkyl_mat_set( + phase_nodal_to_modal_mem_ho->A, k, n, phase_w[n] * phaseb_o[k + up->num_basis_phase * n] + ); + } } - + // Copy to device - up->phase_nodal_to_modal_mem = gkyl_mat_mm_array_mem_new(up->num_basis_phase, up->tot_quad_phase, 1.0, 0.0, - GKYL_NO_TRANS, GKYL_NO_TRANS, up->use_gpu); + up->phase_nodal_to_modal_mem = gkyl_mat_mm_array_mem_new( + up->num_basis_phase, up->tot_quad_phase, 1.0, 0.0, GKYL_NO_TRANS, GKYL_NO_TRANS, up->use_gpu + ); gkyl_mat_copy(up->phase_nodal_to_modal_mem->A, phase_nodal_to_modal_mem_ho->A); gkyl_mat_mm_array_mem_release(phase_nodal_to_modal_mem_ho); // Initialize data needed for conf-space quadrature on device. - up->tot_quad_conf = init_quad_values(up->cdim, inp->conf_basis, inp->qtype, num_quad, - &up->ordinates_conf, &up->weights_conf, &up->basis_at_ords_conf, up->use_gpu); + up->tot_quad_conf = init_quad_values( + up->cdim, inp->conf_basis, inp->qtype, num_quad, &up->ordinates_conf, &up->weights_conf, + &up->basis_at_ords_conf, up->use_gpu + ); // Initialize data needed for phase-space quadrature on device. - up->tot_quad_phase = init_quad_values(up->cdim, inp->phase_basis, inp->qtype, num_quad, - &up->ordinates_phase, &up->weights_phase, &up->basis_at_ords_phase, up->use_gpu); + up->tot_quad_phase = init_quad_values( + up->cdim, inp->phase_basis, inp->qtype, num_quad, &up->ordinates_phase, &up->weights_phase, + &up->basis_at_ords_phase, up->use_gpu + ); int pidx[GKYL_MAX_DIM]; - for (int n=0; ntot_quad_phase; ++n) { + for (int n = 0; n < up->tot_quad_phase; ++n) { gkyl_range_inv_idx(&up->phase_qrange, n, pidx); int cqidx = gkyl_range_idx(&up->conf_qrange, pidx); p2c_qidx_ho[n] = cqidx; } - gkyl_cu_memcpy(up->p2c_qidx, p2c_qidx_ho, sizeof(int)*up->phase_qrange.volume, GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + up->p2c_qidx, p2c_qidx_ho, sizeof(int) * up->phase_qrange.volume, GKYL_CU_MEMCPY_H2D + ); } #endif // Allocate and obtain bmag_max-bmag at quadrature points. - if (up->use_gpu) - up->Dbmag_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->tot_quad_conf, inp->conf_range_ext->volume); - else + if (up->use_gpu) { + up->Dbmag_quad = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->tot_quad_conf, inp->conf_range_ext->volume); + } else { up->Dbmag_quad = gkyl_array_new(GKYL_DOUBLE, up->tot_quad_conf, inp->conf_range_ext->volume); + } - gkyl_array_clear(up->Dbmag_quad, 0.0); + gkyl_array_clear(up->Dbmag_quad, 0.0); gkyl_loss_cone_mask_gyrokinetic_Dbmag_quad(up, inp->conf_range, inp->bmag, inp->bmag_max); // Save the location of bmag_max in this updater. if (up->use_gpu) { - up->bmag_max_loc = gkyl_cu_malloc(sizeof(double)*up->cdim); - gkyl_cu_memcpy(up->bmag_max_loc, inp->bmag_max_loc, sizeof(double)*up->cdim, GKYL_CU_MEMCPY_D2D); + up->bmag_max_loc = gkyl_cu_malloc(sizeof(double) * up->cdim); + gkyl_cu_memcpy( + up->bmag_max_loc, inp->bmag_max_loc, sizeof(double) * up->cdim, GKYL_CU_MEMCPY_D2D + ); + } else { + up->bmag_max_loc = gkyl_malloc(sizeof(double) * up->cdim); + memcpy(up->bmag_max_loc, inp->bmag_max_loc, sizeof(double) * up->cdim); } - else { - up->bmag_max_loc = gkyl_malloc(sizeof(double)*up->cdim); - memcpy(up->bmag_max_loc, inp->bmag_max_loc, sizeof(double)*up->cdim); - } - + return up; } -static void -proj_on_basis(const gkyl_loss_cone_mask_gyrokinetic *up, const struct gkyl_array *fun_at_ords, double* f) +static void proj_on_basis( + const gkyl_loss_cone_mask_gyrokinetic *up, const struct gkyl_array *fun_at_ords, double *f +) { int num_basis = up->num_basis_phase; int tot_quad = up->tot_quad_phase; - const double* GKYL_RESTRICT weights = up->weights_phase->data; - const double* GKYL_RESTRICT basis_at_ords = up->basis_at_ords_phase->data; - const double* GKYL_RESTRICT func_at_ords = fun_at_ords->data; + const double *GKYL_RESTRICT weights = up->weights_phase->data; + const double *GKYL_RESTRICT basis_at_ords = up->basis_at_ords_phase->data; + const double *GKYL_RESTRICT func_at_ords = fun_at_ords->data; - for (int k=0; knum_basis_phase; int tot_quad = up->tot_quad_phase; - const double* GKYL_RESTRICT weights = up->weights_phase->data; - const double* GKYL_RESTRICT basis_at_ords = up->basis_at_ords_phase->data; - const double* GKYL_RESTRICT func_at_ords = fun_at_ords->data; + const double *GKYL_RESTRICT weights = up->weights_phase->data; + const double *GKYL_RESTRICT basis_at_ords = up->basis_at_ords_phase->data; + const double *GKYL_RESTRICT func_at_ords = fun_at_ords->data; - for (int k=0; kuse_gpu) - return gkyl_loss_cone_mask_gyrokinetic_advance_cu(up, phase_range, conf_range, - phi, phi_m, mask_out); + if (up->use_gpu) { + return gkyl_loss_cone_mask_gyrokinetic_advance_cu( + up, phase_range, conf_range, phi, phi_m, mask_out + ); + } #endif int cdim = up->cdim, pdim = up->pdim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int tot_quad_conf = up->tot_quad_conf; int num_basis_conf = up->num_basis_conf; @@ -367,8 +406,10 @@ gkyl_loss_cone_mask_gyrokinetic_advance(gkyl_loss_cone_mask_gyrokinetic *up, struct gkyl_range vel_rng; struct gkyl_range_iter conf_iter, vel_iter; - int pidx[GKYL_MAX_DIM], rem_dir[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim; ++d) rem_dir[d] = 1; + int pidx[GKYL_MAX_DIM], rem_dir[GKYL_MAX_DIM] = {0}; + for (int d = 0; d < conf_range->ndim; ++d) { + rem_dir[d] = 1; + } double xc[GKYL_MAX_DIM], xmu[GKYL_MAX_DIM] = {0.0}; double phi_quad[tot_quad_conf]; @@ -384,25 +425,26 @@ gkyl_loss_cone_mask_gyrokinetic_advance(gkyl_loss_cone_mask_gyrokinetic *up, const double *Dbmag_quad = gkyl_array_cfetch(up->Dbmag_quad, linidx_conf); // Sum over basis for given potential phi. - for (int n=0; nbasis_at_ords_conf, n); // Compute the configuration-space quadrature phi_quad[n] = 0.0; - for (int k=0; k 0.0) - qDphiDbmag_quad[n] = up->charge*(phi_quad[n]-phi_m[0])/Dbmag_quad[n]; - else + if (Dbmag_quad[n] > 0.0) { + qDphiDbmag_quad[n] = up->charge * (phi_quad[n] - phi_m[0]) / Dbmag_quad[n]; + } else { qDphiDbmag_quad[n] = 0.0; + } } // Inner loop over velocity space. gkyl_range_deflate(&vel_rng, phase_range, rem_dir, conf_iter.idx); gkyl_range_iter_no_split_init(&vel_iter, &vel_rng); while (gkyl_range_iter_next(&vel_iter)) { - copy_idx_arrays(conf_range->ndim, phase_range->ndim, conf_iter.idx, vel_iter.idx, pidx); long linidx_phase = gkyl_range_idx(&vel_rng, vel_iter.idx); @@ -410,7 +452,6 @@ gkyl_loss_cone_mask_gyrokinetic_advance(gkyl_loss_cone_mask_gyrokinetic *up, struct gkyl_range_iter qiter; gkyl_range_iter_init(&qiter, &up->phase_qrange); while (gkyl_range_iter_next(&qiter)) { - int cqidx = gkyl_range_idx(&up->conf_qrange, qiter.idx); int pqidx = gkyl_range_idx(&up->phase_qrange, qiter.idx); @@ -426,36 +467,39 @@ gkyl_loss_cone_mask_gyrokinetic_advance(gkyl_loss_cone_mask_gyrokinetic *up, const double *vmap_d = gkyl_array_cfetch(gvm->vmap, linidx_vel); double xcomp[1]; for (int vd = 0; vd < vdim; vd++) { - xcomp[0] = xcomp_d[cdim+vd]; - xmu[cdim+vd] = gvm->vmap_basis->eval_expand(xcomp, vmap_d+vd*gvm->vmap_basis->num_basis); + xcomp[0] = xcomp_d[cdim + vd]; + xmu[cdim + vd] = + gvm->vmap_basis->eval_expand(xcomp, vmap_d + vd * gvm->vmap_basis->num_basis); } // KEparDbmag = 0.5*mass*pow(vpar,2)/(bmag_max-bmag[0]). double KEparDbmag = 0.0; - if (Dbmag_quad[cqidx] > 0.0) - KEparDbmag = 0.5*up->mass*pow(xmu[cdim], 2.0)/Dbmag_quad[cqidx]; - else + if (Dbmag_quad[cqidx] > 0.0) { + KEparDbmag = 0.5 * up->mass * pow(xmu[cdim], 2.0) / Dbmag_quad[cqidx]; + } else { KEparDbmag = 0.0; + } - double mu_bound = GKYL_MAX2(0.0, KEparDbmag+qDphiDbmag_quad[cqidx]); + double mu_bound = GKYL_MAX2(0.0, KEparDbmag + qDphiDbmag_quad[cqidx]); double *fq = gkyl_array_fetch(up->fun_at_ords, pqidx); - if (mu_bound < xmu[cdim+1] && fabs(xmu[cdim-1]) < fabs(up->bmag_max_loc[cdim-1])) + if (mu_bound < xmu[cdim + 1] && fabs(xmu[cdim - 1]) < fabs(up->bmag_max_loc[cdim - 1])) { fq[0] = 1.0 * up->norm_fac; - else + } else { fq[0] = 0.0; + } } // Compute DG expansion coefficients of the mask. - if (up->cellwise_trap_loss) + if (up->cellwise_trap_loss) { nod_to_mod_reduce(up, up->fun_at_ords, gkyl_array_fetch(mask_out, linidx_phase)); - else + } else { proj_on_basis(up, up->fun_at_ords, gkyl_array_fetch(mask_out, linidx_phase)); + } } } } -void -gkyl_loss_cone_mask_gyrokinetic_release(gkyl_loss_cone_mask_gyrokinetic* up) +void gkyl_loss_cone_mask_gyrokinetic_release(gkyl_loss_cone_mask_gyrokinetic *up) { gkyl_velocity_map_release(up->vel_map); @@ -476,8 +520,7 @@ gkyl_loss_cone_mask_gyrokinetic_release(gkyl_loss_cone_mask_gyrokinetic* up) gkyl_array_release(up->qDphiDbmag_quad); gkyl_mat_mm_array_mem_release(up->phase_nodal_to_modal_mem); gkyl_cu_free(up->bmag_max_loc); - } - else { + } else { gkyl_free(up->bmag_max_loc); } diff --git a/gyrokinetic/zero/loss_cone_mask_gyrokinetic_cu.cu b/gyrokinetic/zero/loss_cone_mask_gyrokinetic_cu.cu index e38c8780c5..48c90fcf47 100644 --- a/gyrokinetic/zero/loss_cone_mask_gyrokinetic_cu.cu +++ b/gyrokinetic/zero/loss_cone_mask_gyrokinetic_cu.cu @@ -16,61 +16,65 @@ extern "C" { #include } -__global__ static void -gkyl_loss_cone_mask_gyrokinetic_Dbmag_quad_cu_ker(struct gkyl_range conf_range, - const struct gkyl_array* basis_at_ords_conf, const struct gkyl_array* bmag, const double *bmag_max, - struct gkyl_array* Dbmag_quad_d) -{ +__global__ static void gkyl_loss_cone_mask_gyrokinetic_Dbmag_quad_cu_ker( + struct gkyl_range conf_range, const struct gkyl_array *basis_at_ords_conf, + const struct gkyl_array *bmag, const double *bmag_max, struct gkyl_array *Dbmag_quad_d +) +{ int num_basis_conf = basis_at_ords_conf->ncomp; int tot_quad_conf = basis_at_ords_conf->size; int cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_range.volume; tid += blockDim.x*gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_range, tid, cidx); long linidx = gkyl_range_idx(&conf_range, cidx); - const double *bmag_d = (const double*) gkyl_array_cfetch(bmag, linidx); + const double *bmag_d = (const double *)gkyl_array_cfetch(bmag, linidx); - double *bmag_quad = (double*) gkyl_array_fetch(Dbmag_quad_d, linidx); + double *bmag_quad = (double *)gkyl_array_fetch(Dbmag_quad_d, linidx); - for (int n=0; nnblocks, nthreads = conf_range->nthreads; - gkyl_loss_cone_mask_gyrokinetic_Dbmag_quad_cu_ker<<>>(*conf_range, - up->basis_at_ords_conf->on_dev, bmag->on_dev, bmag_max, up->Dbmag_quad->on_dev); + gkyl_loss_cone_mask_gyrokinetic_Dbmag_quad_cu_ker<< > >( + *conf_range, up->basis_at_ords_conf->on_dev, bmag->on_dev, bmag_max, up->Dbmag_quad->on_dev + ); } -static void -gkyl_parallelize_components_kernel_launch_dims(dim3* dimGrid, dim3* dimBlock, gkyl_range range, int ncomp) +static void gkyl_parallelize_components_kernel_launch_dims( + dim3 *dimGrid, dim3 *dimBlock, gkyl_range range, int ncomp +) { - // Create a 2D thread grid so we launch ncomp*range.volume number of threads + // Create a 2D thread grid so we launch ncomp*range.volume number of threads // so we can parallelize over components too dimBlock->y = ncomp; // ncomp *must* be less than 256 dimGrid->y = 1; - dimBlock->x = GKYL_DEFAULT_NUM_THREADS/ncomp; + dimBlock->x = GKYL_DEFAULT_NUM_THREADS / ncomp; dimGrid->x = gkyl_int_div_up(range.volume, dimBlock->x); } -__global__ static void -gkyl_loss_cone_mask_gyrokinetic_qDphiDbmag_quad_ker(struct gkyl_range conf_range, - const struct gkyl_array* basis_at_ords_conf, double charge, const struct gkyl_array* phi, - const double *phi_m, const struct gkyl_array* Dbmag_quad, struct gkyl_array* qDphiDbmag_quad) +__global__ static void gkyl_loss_cone_mask_gyrokinetic_qDphiDbmag_quad_ker( + struct gkyl_range conf_range, const struct gkyl_array *basis_at_ords_conf, double charge, + const struct gkyl_array *phi, const double *phi_m, const struct gkyl_array *Dbmag_quad, + struct gkyl_array *qDphiDbmag_quad +) { int num_basis_conf = basis_at_ords_conf->ncomp; @@ -78,92 +82,101 @@ gkyl_loss_cone_mask_gyrokinetic_qDphiDbmag_quad_ker(struct gkyl_range conf_range // 2D thread grid // linc2 goes from 0 to tot_quad_conf= basis_at_ords_conf->size. - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_range.volume; tid += blockDim.x*gridDim.x) { + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_range, tid, cidx); long linidx = gkyl_range_idx(&conf_range, cidx); - const double *phi_d = (const double*) gkyl_array_cfetch(phi, linidx); - const double *Dbmag_quad_d = (const double*) gkyl_array_cfetch(Dbmag_quad, linidx); + const double *phi_d = (const double *)gkyl_array_cfetch(phi, linidx); + const double *Dbmag_quad_d = (const double *)gkyl_array_cfetch(Dbmag_quad, linidx); - // Sum over basis at configuration-space quadrature points. - const double *b_ord = (const double*) gkyl_array_cfetch(basis_at_ords_conf, linc2); + // Sum over basis at configuration-space quadrature points. + const double *b_ord = (const double *)gkyl_array_cfetch(basis_at_ords_conf, linc2); double phi_quad = 0; - for (int k=0; k 0.0) - qDphiDbmag_quad_d[linc2] = charge*(phi_quad-phi_m[0])/Dbmag_quad_d[linc2]; - else + double *qDphiDbmag_quad_d = (double *)gkyl_array_fetch(qDphiDbmag_quad, linidx); + if (Dbmag_quad_d[linc2] > 0.0) { + qDphiDbmag_quad_d[linc2] = charge * (phi_quad - phi_m[0]) / Dbmag_quad_d[linc2]; + } else { qDphiDbmag_quad_d[linc2] = 0.0; + } } } -__global__ static void -gkyl_loss_cone_mask_gyrokinetic_ker(struct gkyl_rect_grid grid_phase, - struct gkyl_range phase_range, struct gkyl_range conf_range, struct gkyl_range vel_range, - double mass, const struct gkyl_array* phase_ordinates, - const double *bmag_max_loc, const struct gkyl_array* qDphiDbmag_quad, const struct gkyl_array* Dbmag_quad, - const int *p2c_qidx, struct gkyl_array* vmap, struct gkyl_basis* vmap_basis, struct gkyl_array* mask_out) +__global__ static void gkyl_loss_cone_mask_gyrokinetic_ker( + struct gkyl_rect_grid grid_phase, struct gkyl_range phase_range, struct gkyl_range conf_range, + struct gkyl_range vel_range, double mass, const struct gkyl_array *phase_ordinates, + const double *bmag_max_loc, const struct gkyl_array *qDphiDbmag_quad, + const struct gkyl_array *Dbmag_quad, const int *p2c_qidx, struct gkyl_array *vmap, + struct gkyl_basis *vmap_basis, struct gkyl_array *mask_out +) { int pdim = phase_range.ndim, cdim = conf_range.ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; double xc[GKYL_MAX_DIM], xmu[GKYL_MAX_DIM] = {0.0}; int pidx[GKYL_MAX_DIM], cidx[GKYL_MAX_CDIM], vidx[2]; int tot_phase_quad = phase_ordinates->size; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < phase_range.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < phase_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&phase_range, tid, pidx); // Get configuration-space linear index. - for (unsigned int k = 0; k < cdim; k++) cidx[k] = pidx[k]; + for (unsigned int k = 0; k < cdim; k++) { + cidx[k] = pidx[k]; + } long linidx_conf = gkyl_range_idx(&conf_range, cidx); - const double *Dbmag_quad_d = (const double*) gkyl_array_cfetch(Dbmag_quad, linidx_conf); - const double *qDphiDbmag_quad_d = (const double*) gkyl_array_cfetch(qDphiDbmag_quad, linidx_conf); + const double *Dbmag_quad_d = (const double *)gkyl_array_cfetch(Dbmag_quad, linidx_conf); + const double *qDphiDbmag_quad_d = + (const double *)gkyl_array_cfetch(qDphiDbmag_quad, linidx_conf); gkyl_rect_grid_cell_center(&grid_phase, pidx, xc); long linidx_phase = gkyl_range_idx(&phase_range, pidx); - double *mask_d = (double*) gkyl_array_fetch(mask_out, linidx_phase); + double *mask_d = (double *)gkyl_array_fetch(mask_out, linidx_phase); - for (int d = cdim; d < pdim; d++) vidx[d-cdim] = pidx[d]; + for (int d = cdim; d < pdim; d++) { + vidx[d - cdim] = pidx[d]; + } long linidx_vel = gkyl_range_idx(&vel_range, vidx); - const double *vmap_d = (const double*) gkyl_array_cfetch(vmap, linidx_vel); + const double *vmap_d = (const double *)gkyl_array_cfetch(vmap, linidx_vel); mask_d[0] = 1.0; // In this case the mask has ncomp=1. - for (int n=0; neval_expand(xcomp, vmap_d+vd*vmap_basis->num_basis); + xcomp[0] = xcomp_d[cdim + vd]; + xmu[cdim + vd] = vmap_basis->eval_expand(xcomp, vmap_d + vd * vmap_basis->num_basis); } - + // KEparDbmag = 0.5*mass*pow(vpar,2)/(bmag_max-bmag[0]). double KEparDbmag = 0.0; - if (Dbmag_quad_d[cqidx] > 0.0) - KEparDbmag = 0.5*mass*pow(xmu[cdim], 2.0)/Dbmag_quad_d[cqidx]; - else + if (Dbmag_quad_d[cqidx] > 0.0) { + KEparDbmag = 0.5 * mass * pow(xmu[cdim], 2.0) / Dbmag_quad_d[cqidx]; + } else { KEparDbmag = 0.0; - - double mu_bound = GKYL_MAX2(0.0, KEparDbmag+qDphiDbmag_quad_d[cqidx]); - - if ( !(mu_bound < xmu[cdim+1] && fabs(xmu[cdim-1]) < fabs(bmag_max_loc[cdim-1])) ) { + } + + double mu_bound = GKYL_MAX2(0.0, KEparDbmag + qDphiDbmag_quad_d[cqidx]); + + if (!(mu_bound < xmu[cdim + 1] && fabs(xmu[cdim - 1]) < fabs(bmag_max_loc[cdim - 1]))) { mask_d[0] = 0.0; break; } @@ -171,43 +184,50 @@ gkyl_loss_cone_mask_gyrokinetic_ker(struct gkyl_rect_grid grid_phase, } } -__global__ static void -gkyl_loss_cone_mask_gyrokinetic_quad_ker(struct gkyl_rect_grid grid_phase, - struct gkyl_range phase_range, struct gkyl_range conf_range, struct gkyl_range vel_range, - double mass, double norm_fac, const struct gkyl_array* phase_ordinates, - const double *bmag_max_loc, const struct gkyl_array* qDphiDbmag_quad, const struct gkyl_array* Dbmag_quad, - const int *p2c_qidx, struct gkyl_array* vmap, struct gkyl_basis* vmap_basis, struct gkyl_array* mask_out_quad) +__global__ static void gkyl_loss_cone_mask_gyrokinetic_quad_ker( + struct gkyl_rect_grid grid_phase, struct gkyl_range phase_range, struct gkyl_range conf_range, + struct gkyl_range vel_range, double mass, double norm_fac, + const struct gkyl_array *phase_ordinates, const double *bmag_max_loc, + const struct gkyl_array *qDphiDbmag_quad, const struct gkyl_array *Dbmag_quad, + const int *p2c_qidx, struct gkyl_array *vmap, struct gkyl_basis *vmap_basis, + struct gkyl_array *mask_out_quad +) { int pdim = phase_range.ndim, cdim = conf_range.ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; double xc[GKYL_MAX_DIM], xmu[GKYL_MAX_DIM] = {0.0}; int pidx[GKYL_MAX_DIM], cidx[GKYL_MAX_CDIM], vidx[2]; // 2D thread grid // linc2 goes from 0 to tot_quad_phase - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < phase_range.volume; tid += blockDim.x*gridDim.x) { + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < phase_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&phase_range, tid, pidx); // Get configuration-space linear index. - for (unsigned int k = 0; k < cdim; k++) cidx[k] = pidx[k]; + for (unsigned int k = 0; k < cdim; k++) { + cidx[k] = pidx[k]; + } long linidx_conf = gkyl_range_idx(&conf_range, cidx); - const double *Dbmag_quad_d = (const double*) gkyl_array_cfetch(Dbmag_quad, linidx_conf); - const double *qDphiDbmag_quad_d = (const double*) gkyl_array_cfetch(qDphiDbmag_quad, linidx_conf); + const double *Dbmag_quad_d = (const double *)gkyl_array_cfetch(Dbmag_quad, linidx_conf); + const double *qDphiDbmag_quad_d = + (const double *)gkyl_array_cfetch(qDphiDbmag_quad, linidx_conf); gkyl_rect_grid_cell_center(&grid_phase, pidx, xc); long linidx_phase = gkyl_range_idx(&phase_range, pidx); int cqidx = p2c_qidx[linc2]; - for (int d = cdim; d < pdim; d++) vidx[d-cdim] = pidx[d]; + for (int d = cdim; d < pdim; d++) { + vidx[d - cdim] = pidx[d]; + } long linidx_vel = gkyl_range_idx(&vel_range, vidx); - const double *vmap_d = (const double*) gkyl_array_cfetch(vmap, linidx_vel); - const double *xcomp_d = (const double*) gkyl_array_cfetch(phase_ordinates, linc2); + const double *vmap_d = (const double *)gkyl_array_cfetch(vmap, linidx_vel); + const double *xcomp_d = (const double *)gkyl_array_cfetch(phase_ordinates, linc2); // Convert comp position coordinate to phys pos coord. gkyl_rect_grid_cell_center(&grid_phase, pidx, xc); @@ -216,60 +236,70 @@ gkyl_loss_cone_mask_gyrokinetic_quad_ker(struct gkyl_rect_grid grid_phase, // Convert comp velocity coordinate to phys velocity coord. double xcomp[1]; for (int vd = 0; vd < vdim; vd++) { - xcomp[0] = xcomp_d[cdim+vd]; - xmu[cdim+vd] = vmap_basis->eval_expand(xcomp, vmap_d+vd*vmap_basis->num_basis); + xcomp[0] = xcomp_d[cdim + vd]; + xmu[cdim + vd] = vmap_basis->eval_expand(xcomp, vmap_d + vd * vmap_basis->num_basis); } // KEparDbmag = 0.5*mass*pow(vpar,2)/(bmag_max-bmag[0]). double KEparDbmag = 0.0; - if (Dbmag_quad_d[cqidx] > 0.0) - KEparDbmag = 0.5*mass*pow(xmu[cdim], 2.0)/Dbmag_quad_d[cqidx]; - else + if (Dbmag_quad_d[cqidx] > 0.0) { + KEparDbmag = 0.5 * mass * pow(xmu[cdim], 2.0) / Dbmag_quad_d[cqidx]; + } else { KEparDbmag = 0.0; + } - double mu_bound = GKYL_MAX2(0.0, KEparDbmag+qDphiDbmag_quad_d[cqidx]); + double mu_bound = GKYL_MAX2(0.0, KEparDbmag + qDphiDbmag_quad_d[cqidx]); - double *fq = (double*) gkyl_array_fetch(mask_out_quad, linidx_phase); - if (mu_bound < xmu[cdim+1] && fabs(xmu[cdim-1]) < fabs(bmag_max_loc[cdim-1])) + double *fq = (double *)gkyl_array_fetch(mask_out_quad, linidx_phase); + if (mu_bound < xmu[cdim + 1] && fabs(xmu[cdim - 1]) < fabs(bmag_max_loc[cdim - 1])) { fq[linc2] = norm_fac; - else + } else { fq[linc2] = 0.0; + } } } -void -gkyl_loss_cone_mask_gyrokinetic_advance_cu(gkyl_loss_cone_mask_gyrokinetic *up, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *phi, const double *phi_m, struct gkyl_array *mask_out) +void gkyl_loss_cone_mask_gyrokinetic_advance_cu( + gkyl_loss_cone_mask_gyrokinetic *up, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *phi, const double *phi_m, + struct gkyl_array *mask_out +) { dim3 dimGrid_conf, dimBlock_conf; int tot_quad_conf = up->basis_at_ords_conf->size; - gkyl_parallelize_components_kernel_launch_dims(&dimGrid_conf, &dimBlock_conf, *conf_range, tot_quad_conf); + gkyl_parallelize_components_kernel_launch_dims( + &dimGrid_conf, &dimBlock_conf, *conf_range, tot_quad_conf + ); - gkyl_loss_cone_mask_gyrokinetic_qDphiDbmag_quad_ker<<>>(*conf_range, - up->basis_at_ords_conf->on_dev, up->charge, phi->on_dev, phi_m, up->Dbmag_quad->on_dev, - up->qDphiDbmag_quad->on_dev); + gkyl_loss_cone_mask_gyrokinetic_qDphiDbmag_quad_ker<< > >( + *conf_range, up->basis_at_ords_conf->on_dev, up->charge, phi->on_dev, phi_m, + up->Dbmag_quad->on_dev, up->qDphiDbmag_quad->on_dev + ); const struct gkyl_velocity_map *gvm = up->vel_map; if (up->cellwise_trap_loss) { // Don't do quadrature. int nblocks = phase_range->nblocks, nthreads = phase_range->nthreads; - gkyl_loss_cone_mask_gyrokinetic_ker<<>>(*up->grid_phase, *phase_range, *conf_range, - gvm->local_ext_vel, up->mass, up->ordinates_phase->on_dev, - up->bmag_max_loc, up->qDphiDbmag_quad->on_dev, up->Dbmag_quad->on_dev, up->p2c_qidx, gvm->vmap->on_dev, - gvm->vmap_basis, mask_out->on_dev); - } - else { + gkyl_loss_cone_mask_gyrokinetic_ker<< > >( + *up->grid_phase, *phase_range, *conf_range, gvm->local_ext_vel, up->mass, + up->ordinates_phase->on_dev, up->bmag_max_loc, up->qDphiDbmag_quad->on_dev, + up->Dbmag_quad->on_dev, up->p2c_qidx, gvm->vmap->on_dev, gvm->vmap_basis, mask_out->on_dev + ); + } else { // Use quadrature. dim3 dimGrid, dimBlock; int tot_quad_phase = up->basis_at_ords_phase->size; - gkyl_parallelize_components_kernel_launch_dims(&dimGrid, &dimBlock, *phase_range, tot_quad_phase); - - gkyl_loss_cone_mask_gyrokinetic_quad_ker<<>>(*up->grid_phase, *phase_range, *conf_range, - gvm->local_ext_vel, up->mass, up->norm_fac, up->ordinates_phase->on_dev, - up->bmag_max_loc, up->qDphiDbmag_quad->on_dev, up->Dbmag_quad->on_dev, up->p2c_qidx, gvm->vmap->on_dev, - gvm->vmap_basis, up->mask_out_quad->on_dev); + gkyl_parallelize_components_kernel_launch_dims( + &dimGrid, &dimBlock, *phase_range, tot_quad_phase + ); + + gkyl_loss_cone_mask_gyrokinetic_quad_ker<< > >( + *up->grid_phase, *phase_range, *conf_range, gvm->local_ext_vel, up->mass, up->norm_fac, + up->ordinates_phase->on_dev, up->bmag_max_loc, up->qDphiDbmag_quad->on_dev, + up->Dbmag_quad->on_dev, up->p2c_qidx, gvm->vmap->on_dev, gvm->vmap_basis, + up->mask_out_quad->on_dev + ); // Call cublas to do the matrix multiplication nodal to modal conversion gkyl_mat_mm_array(up->phase_nodal_to_modal_mem, up->mask_out_quad, mask_out); diff --git a/gyrokinetic/zero/mirror_grid_gen.c b/gyrokinetic/zero/mirror_grid_gen.c index e4eb540ede..c297a3fd11 100644 --- a/gyrokinetic/zero/mirror_grid_gen.c +++ b/gyrokinetic/zero/mirror_grid_gen.c @@ -18,33 +18,35 @@ struct psirz_ctx { double psi; // psi to match }; -static inline double -floor_sqrt(double x) +static inline double floor_sqrt(double x) { - return sqrt( fmax(x, 1e-14) ); + return sqrt(fmax(x, 1e-14)); } -static -double psirz(double R, void *ctx) +static double psirz(double R, void *ctx) { struct psirz_ctx *rctx = ctx; double Z = rctx->Z; - double xn[2] = { R, Z }; + double xn[2] = {R, Z}; double fout[1]; rctx->evcub->eval_cubic(0, xn, fout, rctx->evcub->ctx); return fout[0] - rctx->psi; } -static double calc_running_coord(double coord_lo, int i, double dx) { - double dels[2] = {1.0/sqrt(3), 1.0-1.0/sqrt(3) }; +static double calc_running_coord(double coord_lo, int i, double dx) +{ + double dels[2] = {1.0 / sqrt(3), 1.0 - 1.0 / sqrt(3)}; double coord = coord_lo; - for(int j = 0; j < i; j++) - coord+=dels[j%2]*dx; + for (int j = 0; j < i; j++) { + coord += dels[j % 2] * dx; + } return coord; } -static void -curlbhat_func(double r_curr, double Z, double phi, struct gkyl_basis_ops_evalf *evcub, struct gkyl_vec3 *curlbhat) +static void curlbhat_func( + double r_curr, double Z, double phi, struct gkyl_basis_ops_evalf *evcub, + struct gkyl_vec3 *curlbhat +) { // Calculate psi's various derivatives double Br = 0.0, Bz = 0.0, bmag = 0.0; @@ -64,27 +66,26 @@ curlbhat_func(double r_curr, double Z, double phi, struct gkyl_basis_ops_evalf * d2psidZ2 = fout[2]; d2psidRdZ = fout[3]; - Br = 1.0/r_curr*dpsidZ; - Bz = -1.0/r_curr*dpsidR; - bmag = sqrt(Br*Br+Bz*Bz); + Br = 1.0 / r_curr * dpsidZ; + Bz = -1.0 / r_curr * dpsidR; + bmag = sqrt(Br * Br + Bz * Bz); - dBrdR = 1.0/r_curr*d2psidRdZ; - dBrdZ = 1.0/r_curr*d2psidZ2; - dBzdR = -1.0/r_curr*d2psidR2; - dBzdZ = -1.0/r_curr*d2psidRdZ; + dBrdR = 1.0 / r_curr * d2psidRdZ; + dBrdZ = 1.0 / r_curr * d2psidZ2; + dBzdR = -1.0 / r_curr * d2psidR2; + dBzdZ = -1.0 / r_curr * d2psidRdZ; - dBdR = 1/bmag*(Br*dBrdR + Bz*dBzdR); - dBdZ = 1/bmag*(Br*dBrdZ + Bz*dBzdZ); + dBdR = 1 / bmag * (Br * dBrdR + Bz * dBzdR); + dBdZ = 1 / bmag * (Br * dBrdZ + Bz * dBzdZ); // Get the polar components (contravariant, upperscript components on tangent basis) - curlbhat->x[0] = 0.0; // R component ^1 - curlbhat->x[1] = 1.0/bmag*1.0/r_curr*(dBrdZ - dBzdR) + (-dBdR*Bz/r_curr + dBdZ*Br/r_curr); // Phi component ^2 + curlbhat->x[0] = 0.0; // R component ^1 + curlbhat->x[1] = 1.0 / bmag * 1.0 / r_curr * (dBrdZ - dBzdR) + + (-dBdR * Bz / r_curr + dBdZ * Br / r_curr); // Phi component ^2 curlbhat->x[2] = 0.0; } - -struct gkyl_mirror_grid_gen * -gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) +struct gkyl_mirror_grid_gen *gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) { struct gkyl_mirror_grid_gen *geo = gkyl_malloc(sizeof *geo); geo->gg_x = gkyl_malloc(sizeof *geo->gg_x); @@ -93,30 +94,30 @@ gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) geo->gg_x->include_axis = inp->include_axis; int nr = inp->nrcells, nz = inp->nzcells; - int cells[] = { nr, nz }; - double lower[2] = { inp->R[0], inp->Z[0] }; - double upper[2] = { inp->R[1], inp->Z[1] }; + int cells[] = {nr, nz}; + double lower[2] = {inp->R[0], inp->Z[0]}; + double upper[2] = {inp->R[1], inp->Z[1]}; struct gkyl_rect_grid gridRZ; gkyl_rect_grid_init(&gridRZ, 2, lower, upper, cells); - struct gkyl_basis_ops_evalf *evcub = - gkyl_dg_basis_ops_evalf_new(&gridRZ, inp->psiRZ); + struct gkyl_basis_ops_evalf *evcub = gkyl_dg_basis_ops_evalf_new(&gridRZ, inp->psiRZ); do { const char *fname = inp->psi_cubic_fname ? inp->psi_cubic_fname : "psi_cubic.gkyl"; - if (inp->write_psi_cubic) + if (inp->write_psi_cubic) { gkyl_dg_basis_ops_evalf_write_cubic(evcub, fname); + } } while (0); // Construct grid in RZ plane - + enum { NPSI, NAL, NZ }; - + geo->nodes_rza = gkyl_array_new(GKYL_DOUBLE, 3, inp->nrange.volume); geo->nodes_psi = gkyl_array_new(GKYL_DOUBLE, 1, inp->nrange.volume); - geo->nodes_geom = gkyl_array_new(GKYL_USER, sizeof(struct gkyl_mirror_grid_gen_geom), inp->nrange.volume); - + geo->nodes_geom = + gkyl_array_new(GKYL_USER, sizeof(struct gkyl_mirror_grid_gen_geom), inp->nrange.volume); // Take special care for setting dpsi double psi_lo = inp->comp_grid->lower[0]; @@ -129,15 +130,19 @@ gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) psic_lo = inc_axis ? 0.0 : sqrt(psi_lo); psic_up = sqrt(psi_up); } - double dpsi = (psic_up-psic_lo)/(gkyl_range_shape(&inp->global,0)); + double dpsi = (psic_up - psic_lo) / (gkyl_range_shape(&inp->global, 0)); double dz = inp->comp_grid->dx[NZ]; double dalpha = inp->comp_grid->dx[NAL]; - double z_lo = inp->comp_grid->lower[NZ] + (inp->local.lower[NZ] - inp->global.lower[NZ])*inp->comp_grid->dx[NZ]; - double alpha_lo = inp->comp_grid->lower[NAL] + (inp->local.lower[NAL] - inp->global.lower[NAL])*inp->comp_grid->dx[NAL]; - psi_lo = inp->comp_grid->lower[NPSI] + (inp->local.lower[NPSI] - inp->global.lower[NPSI])*inp->comp_grid->dx[NPSI]; - psi_up = inp->comp_grid->lower[NPSI] + (inp->local.upper[NPSI] - inp->global.lower[NPSI])*inp->comp_grid->dx[NPSI]; + double z_lo = inp->comp_grid->lower[NZ] + + (inp->local.lower[NZ] - inp->global.lower[NZ]) * inp->comp_grid->dx[NZ]; + double alpha_lo = inp->comp_grid->lower[NAL] + + (inp->local.lower[NAL] - inp->global.lower[NAL]) * inp->comp_grid->dx[NAL]; + psi_lo = inp->comp_grid->lower[NPSI] + + (inp->local.lower[NPSI] - inp->global.lower[NPSI]) * inp->comp_grid->dx[NPSI]; + psi_up = inp->comp_grid->lower[NPSI] + + (inp->local.upper[NPSI] - inp->global.lower[NPSI]) * inp->comp_grid->dx[NPSI]; // Adjust if we are using sqrt(psi) as radial coordinate psic_lo = psi_lo; @@ -149,58 +154,61 @@ gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) } double rlow = lower[0], rup = upper[0]; - double rmin = rlow + 1e-8*(rup-rlow); + double rmin = rlow + 1e-8 * (rup - rlow); - struct psirz_ctx pctx = { .evcub = evcub }; + struct psirz_ctx pctx = {.evcub = evcub}; // Compute node locations bool status = true; - for (int iz=inp->nrange.lower[NZ]; iz<=inp->nrange.upper[NZ]; ++iz) { - double zcurr = z_lo + iz*dz; + for (int iz = inp->nrange.lower[NZ]; iz <= inp->nrange.upper[NZ]; ++iz) { + double zcurr = z_lo + iz * dz; double Zcurr; - inp->position_map->maps[2](0.0, &zcurr, &Zcurr, inp->position_map->ctxs[2]); + inp->position_map->maps[2](0.0, &zcurr, &Zcurr, inp->position_map->ctxs[2]); zcurr = Zcurr; // update zcurr to be the mapped value double psi_min[1], psi_max[1]; - evcub->eval_cubic(0.0, (double[2]) { rmin, zcurr }, psi_min, evcub->ctx); - evcub->eval_cubic(0.0, (double[2]) { rup, zcurr }, psi_max, evcub->ctx); - - for (int ipsi=inp->nrange.lower[NPSI]; ipsi<=inp->nrange.upper[NPSI]; ++ipsi) { + evcub->eval_cubic(0.0, (double[2]){rmin, zcurr}, psi_min, evcub->ctx); + evcub->eval_cubic(0.0, (double[2]){rup, zcurr}, psi_max, evcub->ctx); + for (int ipsi = inp->nrange.lower[NPSI]; ipsi <= inp->nrange.upper[NPSI]; ++ipsi) { if (inc_axis && (ipsi == 0)) { - for (int ia=inp->nrange.lower[NAL]; ia<=inp->nrange.upper[NAL]; ++ia){ - double alpha_curr = alpha_lo + ia*dalpha; - int idx[3] = { ipsi, ia, iz }; + for (int ia = inp->nrange.lower[NAL]; ia <= inp->nrange.upper[NAL]; ++ia) { + double alpha_curr = alpha_lo + ia * dalpha; + int idx[3] = {ipsi, ia, iz}; double *rz = gkyl_array_fetch(geo->nodes_rza, gkyl_range_idx(&inp->nrange, idx)); - rz[0] = 0.0; rz[1] = zcurr; rz[2] = alpha_curr; + rz[0] = 0.0; + rz[1] = zcurr; + rz[2] = alpha_curr; } - } - else { - double psic_curr = psic_lo + ipsi*dpsi; + } else { + double psic_curr = psic_lo + ipsi * dpsi; pctx.Z = zcurr; // We continue to do root-finding for psi and not sqrt(psi) double psi_curr = psic_curr; - if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) - psi_curr = psic_curr*psic_curr; - - pctx.psi = psi_curr; - - struct gkyl_qr_res root = gkyl_ridders(psirz, &pctx, rmin, rup, - psi_min[0]-psi_curr, psi_max[0]-psi_curr, - 100, 1e-10); + if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { + psi_curr = psic_curr * psic_curr; + } + + pctx.psi = psi_curr; + + struct gkyl_qr_res root = gkyl_ridders( + psirz, &pctx, rmin, rup, psi_min[0] - psi_curr, psi_max[0] - psi_curr, 100, 1e-10 + ); if (root.status) { status = false; goto cleanup; } - - for (int ia=inp->nrange.lower[NAL]; ia<=inp->nrange.upper[NAL]; ++ia){ - double alpha_curr = alpha_lo + ia*dalpha; - int idx[3] = { ipsi, ia, iz }; + + for (int ia = inp->nrange.lower[NAL]; ia <= inp->nrange.upper[NAL]; ++ia) { + double alpha_curr = alpha_lo + ia * dalpha; + int idx[3] = {ipsi, ia, iz}; double *rz = gkyl_array_fetch(geo->nodes_rza, gkyl_range_idx(&inp->nrange, idx)); - rz[0] = root.res; rz[1] = zcurr; rz[2] = alpha_curr; + rz[0] = root.res; + rz[1] = zcurr; + rz[2] = alpha_curr; double *psi_coord = gkyl_array_fetch(geo->nodes_psi, gkyl_range_idx(&inp->nrange, idx)); psi_coord[0] = psi_curr; // store psi coordinate } @@ -209,24 +217,24 @@ gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) } enum { PSI_I, DPSI_R_I, DPSI_Z_I }; - - // Compute geometry at nodes - for (int iz=inp->nrange.lower[NZ]; iz<=inp->nrange.upper[NZ]; ++iz) { - - for (int ipsi=inp->nrange.lower[NPSI]; ipsi<=inp->nrange.upper[NPSI]; ++ipsi) { - for (int ia=inp->nrange.lower[NAL]; ia<=inp->nrange.upper[NAL]; ++ia){ - int idx[3] = { ipsi, ia, iz }; + // Compute geometry at nodes + for (int iz = inp->nrange.lower[NZ]; iz <= inp->nrange.upper[NZ]; ++iz) { + for (int ipsi = inp->nrange.lower[NPSI]; ipsi <= inp->nrange.upper[NPSI]; ++ipsi) { + for (int ia = inp->nrange.lower[NAL]; ia <= inp->nrange.upper[NAL]; ++ia) { + int idx[3] = {ipsi, ia, iz}; long loc = gkyl_range_idx(&inp->nrange, idx); - + const double *rzp = gkyl_array_cfetch(geo->nodes_rza, loc); - double rz[2] = { rzp[0], rzp[1] }; + double rz[2] = {rzp[0], rzp[1]}; + + double dZ_dz = gkyl_position_map_slope( + inp->position_map, 2, rzp[1], dz, iz, + &inp->nrange + ); // derivative of the position map in Z direction - double dZ_dz = gkyl_position_map_slope(inp->position_map, 2, rzp[1], - dz, iz, &inp->nrange); // derivative of the position map in Z direction - struct gkyl_mirror_grid_gen_geom *g = gkyl_array_fetch(geo->nodes_geom, loc); - + if (inc_axis && (ipsi == 0)) { double fout2[4]; // second derivative of psi is needed evcub->eval_cubic_wgrad2(0.0, rz, fout2, evcub->ctx); @@ -236,7 +244,7 @@ gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) // duals. However, the Jacobians and magnetic field are // correct and computed using the estimated asymptotic // behavior of psi as r -> 0. - + g->dual[0].x[0] = 1.0; g->dual[0].x[1] = 0.0; g->dual[0].x[2] = 0.0; @@ -247,24 +255,25 @@ gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) g->dual[2].x[0] = 0; g->dual[2].x[1] = 0.0; - g->dual[2].x[2] = 1.0 / dZ_dz; - + g->dual[2].x[2] = 1.0 / dZ_dz; + g->tang[0].x[0] = 1.0; g->tang[0].x[1] = 0.0; g->tang[0].x[2] = 0.0; g->tang[1].x[0] = 0.0; g->tang[1].x[1] = 1.0; - g->tang[1].x[2] = 0.0; - + g->tang[1].x[2] = 0.0; + g->tang[2].x[0] = 0; g->tang[2].x[1] = 0.0; g->tang[2].x[2] = 1.0 * dZ_dz; - - if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) + + if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { g->Jc = 0; // assumes asymptotics of psi ~ r^2 as r -> 0 - else - g->Jc = 1/fout2[DPSI_R_I] * dZ_dz; + } else { + g->Jc = 1 / fout2[DPSI_R_I] * dZ_dz; + } g->B.x[0] = 0.0; // no radial component g->B.x[1] = 0.0; @@ -274,25 +283,24 @@ gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) g->curlbhat.x[0] = 0.0; g->curlbhat.x[1] = 0.0; g->curlbhat.x[2] = 0.0; - } - else { + } else { double fout[3]; // first derivative of psi is needed evcub->eval_cubic_wgrad(0.0, rz, fout, evcub->ctx); - + // e^1 g->dual[0].x[0] = fout[DPSI_R_I]; // dpsi/dr g->dual[0].x[1] = 0.0; // no toroidal component g->dual[0].x[2] = fout[DPSI_Z_I]; // dspi/dz - + if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { // for sqrt(psi) as radial coordinate e^1 = grad(psi)/2*sqrt(psi) - g->dual[0].x[0] = g->dual[0].x[0]/(2*floor_sqrt(fout[0])); - g->dual[0].x[2] = g->dual[0].x[2]/(2*floor_sqrt(fout[0])); + g->dual[0].x[0] = g->dual[0].x[0] / (2 * floor_sqrt(fout[0])); + g->dual[0].x[2] = g->dual[0].x[2] / (2 * floor_sqrt(fout[0])); } // e^2 is just e^phi g->dual[1].x[0] = 0; - g->dual[1].x[1] = 1.0/(rz[0]*rz[0]); + g->dual[1].x[1] = 1.0 / (rz[0] * rz[0]); g->dual[1].x[2] = 0.0; // e^3 is just sigma_3 @@ -301,7 +309,7 @@ gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) g->dual[2].x[2] = 1.0 / dZ_dz; // e_1 points along the radial direction - g->tang[0].x[0] = 1/g->dual[0].x[0]; + g->tang[0].x[0] = 1 / g->dual[0].x[0]; g->tang[0].x[1] = 0.0; g->tang[0].x[2] = 0.0; @@ -311,18 +319,19 @@ gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) g->tang[1].x[2] = 0.0; // e_3 - g->tang[2].x[0] = -fout[DPSI_Z_I]/fout[DPSI_R_I]; + g->tang[2].x[0] = -fout[DPSI_Z_I] / fout[DPSI_R_I]; g->tang[2].x[1] = 0.0; g->tang[2].x[2] = 1.0 * dZ_dz; - - if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) - g->Jc = 2*floor_sqrt(fout[PSI_I])*rz[0]/fout[DPSI_R_I] * dZ_dz; - else - g->Jc = rz[0]/fout[DPSI_R_I] * dZ_dz; - - g->B.x[0] = -fout[DPSI_Z_I]/rz[0]; + + if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { + g->Jc = 2 * floor_sqrt(fout[PSI_I]) * rz[0] / fout[DPSI_R_I] * dZ_dz; + } else { + g->Jc = rz[0] / fout[DPSI_R_I] * dZ_dz; + } + + g->B.x[0] = -fout[DPSI_Z_I] / rz[0]; g->B.x[1] = 0.0; - g->B.x[2] = fout[DPSI_R_I]/rz[0]; + g->B.x[2] = fout[DPSI_R_I] / rz[0]; // \nabla X \hat{b} curlbhat_func(rz[0], rz[1], rzp[2], evcub, &g->curlbhat); @@ -330,17 +339,17 @@ gkyl_mirror_grid_gen_inew(const struct gkyl_mirror_grid_gen_inp *inp) } } } - - cleanup: + +cleanup: if (true != status) { gkyl_mirror_grid_gen_release(geo); geo = 0; fprintf(stderr, "gkyl_mirror_grid_gen_inew failed to generate a grid\n"); } - + gkyl_dg_basis_ops_evalf_release(evcub); - + return geo; } @@ -354,29 +363,30 @@ gkyl_mirror_grid_gen_int_inew(const struct gkyl_mirror_grid_gen_inp *inp) geo->gg_x->include_axis = inp->include_axis; int nr = inp->nrcells, nz = inp->nzcells; - int cells[] = { nr, nz }; - double lower[2] = { inp->R[0], inp->Z[0] }; - double upper[2] = { inp->R[1], inp->Z[1] }; + int cells[] = {nr, nz}; + double lower[2] = {inp->R[0], inp->Z[0]}; + double upper[2] = {inp->R[1], inp->Z[1]}; struct gkyl_rect_grid gridRZ; gkyl_rect_grid_init(&gridRZ, 2, lower, upper, cells); - struct gkyl_basis_ops_evalf *evcub = - gkyl_dg_basis_ops_evalf_new(&gridRZ, inp->psiRZ); + struct gkyl_basis_ops_evalf *evcub = gkyl_dg_basis_ops_evalf_new(&gridRZ, inp->psiRZ); do { const char *fname = inp->psi_cubic_fname ? inp->psi_cubic_fname : "psi_cubic.gkyl"; - if (inp->write_psi_cubic) + if (inp->write_psi_cubic) { gkyl_dg_basis_ops_evalf_write_cubic(evcub, fname); + } } while (0); // Construct grid in RZ plane - + enum { NPSI, NAL, NZ }; - + geo->nodes_rza = gkyl_array_new(GKYL_DOUBLE, 3, inp->nrange.volume); geo->nodes_psi = gkyl_array_new(GKYL_DOUBLE, 1, inp->nrange.volume); - geo->nodes_geom = gkyl_array_new(GKYL_USER, sizeof(struct gkyl_mirror_grid_gen_geom), inp->nrange.volume); + geo->nodes_geom = + gkyl_array_new(GKYL_USER, sizeof(struct gkyl_mirror_grid_gen_geom), inp->nrange.volume); // Take special care for setting dpsi double psi_lo = inp->comp_grid->lower[0]; @@ -389,15 +399,19 @@ gkyl_mirror_grid_gen_int_inew(const struct gkyl_mirror_grid_gen_inp *inp) psic_lo = inc_axis ? 0.0 : sqrt(psi_lo); psic_up = sqrt(psi_up); } - double dpsi = (psic_up-psic_lo)/(gkyl_range_shape(&inp->global,0)); + double dpsi = (psic_up - psic_lo) / (gkyl_range_shape(&inp->global, 0)); double dz = inp->comp_grid->dx[NZ]; double dalpha = inp->comp_grid->dx[NAL]; - double z_lo = inp->comp_grid->lower[NZ] + (inp->local.lower[NZ] - inp->global.lower[NZ])*inp->comp_grid->dx[NZ]; - double alpha_lo = inp->comp_grid->lower[NAL] + (inp->local.lower[NAL] - inp->global.lower[NAL])*inp->comp_grid->dx[NAL]; - psi_lo = inp->comp_grid->lower[NPSI] + (inp->local.lower[NPSI] - inp->global.lower[NPSI])*inp->comp_grid->dx[NPSI]; - psi_up = inp->comp_grid->lower[NPSI] + (inp->local.upper[NPSI] - inp->global.lower[NPSI])*inp->comp_grid->dx[NPSI]; + double z_lo = inp->comp_grid->lower[NZ] + + (inp->local.lower[NZ] - inp->global.lower[NZ]) * inp->comp_grid->dx[NZ]; + double alpha_lo = inp->comp_grid->lower[NAL] + + (inp->local.lower[NAL] - inp->global.lower[NAL]) * inp->comp_grid->dx[NAL]; + psi_lo = inp->comp_grid->lower[NPSI] + + (inp->local.lower[NPSI] - inp->global.lower[NPSI]) * inp->comp_grid->dx[NPSI]; + psi_up = inp->comp_grid->lower[NPSI] + + (inp->local.upper[NPSI] - inp->global.lower[NPSI]) * inp->comp_grid->dx[NPSI]; // Adjust if we are using sqrt(psi) as radial coordinate psic_lo = psi_lo; @@ -408,55 +422,57 @@ gkyl_mirror_grid_gen_int_inew(const struct gkyl_mirror_grid_gen_inp *inp) psic_up = sqrt(psi_up); } - double dels[2] = {1.0/sqrt(3), 1.0-1.0/sqrt(3) }; - z_lo = z_lo + dels[1]*dz/2.0; - psic_lo = psic_lo + dels[1]*dpsi/2.0; - alpha_lo = alpha_lo + dels[1]*dalpha/2.0; + double dels[2] = {1.0 / sqrt(3), 1.0 - 1.0 / sqrt(3)}; + z_lo = z_lo + dels[1] * dz / 2.0; + psic_lo = psic_lo + dels[1] * dpsi / 2.0; + alpha_lo = alpha_lo + dels[1] * dalpha / 2.0; double rlow = lower[0], rup = upper[0]; - double rmin = rlow + 1e-8*(rup-rlow); + double rmin = rlow + 1e-8 * (rup - rlow); - struct psirz_ctx pctx = { .evcub = evcub }; + struct psirz_ctx pctx = {.evcub = evcub}; // Compute node locations bool status = true; - for (int iz=inp->nrange.lower[NZ]; iz<=inp->nrange.upper[NZ]; ++iz) { - double zcurr = calc_running_coord(z_lo, iz-inp->nrange.lower[NZ], dz); + for (int iz = inp->nrange.lower[NZ]; iz <= inp->nrange.upper[NZ]; ++iz) { + double zcurr = calc_running_coord(z_lo, iz - inp->nrange.lower[NZ], dz); double Zcurr; - inp->position_map->maps[2](0.0, &zcurr, &Zcurr, inp->position_map->ctxs[2]); + inp->position_map->maps[2](0.0, &zcurr, &Zcurr, inp->position_map->ctxs[2]); zcurr = Zcurr; // update zcurr to be the mapped value double psi_min[1], psi_max[1]; - evcub->eval_cubic(0.0, (double[2]) { rmin, zcurr }, psi_min, evcub->ctx); - evcub->eval_cubic(0.0, (double[2]) { rup, zcurr }, psi_max, evcub->ctx); - - for (int ipsi=inp->nrange.lower[NPSI]; ipsi<=inp->nrange.upper[NPSI]; ++ipsi) { + evcub->eval_cubic(0.0, (double[2]){rmin, zcurr}, psi_min, evcub->ctx); + evcub->eval_cubic(0.0, (double[2]){rup, zcurr}, psi_max, evcub->ctx); - double psic_curr = calc_running_coord(psic_lo, ipsi-inp->nrange.lower[NPSI], dpsi); + for (int ipsi = inp->nrange.lower[NPSI]; ipsi <= inp->nrange.upper[NPSI]; ++ipsi) { + double psic_curr = calc_running_coord(psic_lo, ipsi - inp->nrange.lower[NPSI], dpsi); pctx.Z = zcurr; // We continue to do root-finding for psi and not sqrt(psi) double psi_curr = psic_curr; - if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) - psi_curr = psic_curr*psic_curr; - - pctx.psi = psi_curr; - - struct gkyl_qr_res root = gkyl_ridders(psirz, &pctx, rmin, rup, - psi_min[0]-psi_curr, psi_max[0]-psi_curr, - 100, 1e-10); + if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { + psi_curr = psic_curr * psic_curr; + } + + pctx.psi = psi_curr; + + struct gkyl_qr_res root = gkyl_ridders( + psirz, &pctx, rmin, rup, psi_min[0] - psi_curr, psi_max[0] - psi_curr, 100, 1e-10 + ); if (root.status) { status = false; goto cleanup; } - - for (int ia=inp->nrange.lower[NAL]; ia<=inp->nrange.upper[NAL]; ++ia){ - double alpha_curr = calc_running_coord(alpha_lo, ia-inp->nrange.lower[NAL], dalpha); - int idx[3] = { ipsi, ia, iz }; + + for (int ia = inp->nrange.lower[NAL]; ia <= inp->nrange.upper[NAL]; ++ia) { + double alpha_curr = calc_running_coord(alpha_lo, ia - inp->nrange.lower[NAL], dalpha); + int idx[3] = {ipsi, ia, iz}; double *rz = gkyl_array_fetch(geo->nodes_rza, gkyl_range_idx(&inp->nrange, idx)); - rz[0] = root.res; rz[1] = zcurr; rz[2] = alpha_curr; + rz[0] = root.res; + rz[1] = zcurr; + rz[2] = alpha_curr; double *psi_coord = gkyl_array_fetch(geo->nodes_psi, gkyl_range_idx(&inp->nrange, idx)); psi_coord[0] = psi_curr; // store psi coordinate } @@ -464,50 +480,50 @@ gkyl_mirror_grid_gen_int_inew(const struct gkyl_mirror_grid_gen_inp *inp) } enum { PSI_I, DPSI_R_I, DPSI_Z_I }; - - // Compute geometry at nodes - for (int iz=inp->nrange.lower[NZ]; iz<=inp->nrange.upper[NZ]; ++iz) { - - for (int ipsi=inp->nrange.lower[NPSI]; ipsi<=inp->nrange.upper[NPSI]; ++ipsi) { - for (int ia=inp->nrange.lower[NAL]; ia<=inp->nrange.upper[NAL]; ++ia){ - int idx[3] = { ipsi, ia, iz }; + // Compute geometry at nodes + for (int iz = inp->nrange.lower[NZ]; iz <= inp->nrange.upper[NZ]; ++iz) { + for (int ipsi = inp->nrange.lower[NPSI]; ipsi <= inp->nrange.upper[NPSI]; ++ipsi) { + for (int ia = inp->nrange.lower[NAL]; ia <= inp->nrange.upper[NAL]; ++ia) { + int idx[3] = {ipsi, ia, iz}; long loc = gkyl_range_idx(&inp->nrange, idx); - + const double *rzp = gkyl_array_cfetch(geo->nodes_rza, loc); - double rz[2] = { rzp[0], rzp[1] }; + double rz[2] = {rzp[0], rzp[1]}; + + double dZ_dz = gkyl_position_map_slope( + inp->position_map, 2, rzp[1], dz, iz, + &inp->nrange + ); // derivative of the position map in Z direction - double dZ_dz = gkyl_position_map_slope(inp->position_map, 2, rzp[1], - dz, iz, &inp->nrange); // derivative of the position map in Z direction - struct gkyl_mirror_grid_gen_geom *g = gkyl_array_fetch(geo->nodes_geom, loc); - + double fout[3]; // first derivative of psi is needed evcub->eval_cubic_wgrad(0.0, rz, fout, evcub->ctx); - + // e^1 g->dual[0].x[0] = fout[DPSI_R_I]; // dpsi/dr g->dual[0].x[1] = 0.0; // no toroidal component g->dual[0].x[2] = fout[DPSI_Z_I]; // dspi/dz - + if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { // for sqrt(psi) as radial coordinate e^1 = grad(psi)/2*sqrt(psi) - g->dual[0].x[0] = g->dual[0].x[0]/(2*floor_sqrt(fout[0])); - g->dual[0].x[2] = g->dual[0].x[2]/(2*floor_sqrt(fout[0])); + g->dual[0].x[0] = g->dual[0].x[0] / (2 * floor_sqrt(fout[0])); + g->dual[0].x[2] = g->dual[0].x[2] / (2 * floor_sqrt(fout[0])); } // e^2 is just e^phi g->dual[1].x[0] = 0; - g->dual[1].x[1] = 1.0/(rz[0]*rz[0]); + g->dual[1].x[1] = 1.0 / (rz[0] * rz[0]); g->dual[1].x[2] = 0.0; // e^3 is just sigma_3 g->dual[2].x[0] = 0; g->dual[2].x[1] = 0.0; - g->dual[2].x[2] = 1.0 / dZ_dz; + g->dual[2].x[2] = 1.0 / dZ_dz; // e_1 points along the radial direction - g->tang[0].x[0] = 1/g->dual[0].x[0]; + g->tang[0].x[0] = 1 / g->dual[0].x[0]; g->tang[0].x[1] = 0.0; g->tang[0].x[2] = 0.0; @@ -517,35 +533,36 @@ gkyl_mirror_grid_gen_int_inew(const struct gkyl_mirror_grid_gen_inp *inp) g->tang[1].x[2] = 0.0; // e_3 - g->tang[2].x[0] = -fout[DPSI_Z_I]/fout[DPSI_R_I]; + g->tang[2].x[0] = -fout[DPSI_Z_I] / fout[DPSI_R_I]; g->tang[2].x[1] = 0.0; g->tang[2].x[2] = 1.0 * dZ_dz; - - if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) - g->Jc = 2*floor_sqrt(fout[PSI_I])*rz[0]/fout[DPSI_R_I] * dZ_dz; - else - g->Jc = rz[0]/fout[DPSI_R_I] * dZ_dz; - - g->B.x[0] = -fout[DPSI_Z_I]/rz[0]; + + if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { + g->Jc = 2 * floor_sqrt(fout[PSI_I]) * rz[0] / fout[DPSI_R_I] * dZ_dz; + } else { + g->Jc = rz[0] / fout[DPSI_R_I] * dZ_dz; + } + + g->B.x[0] = -fout[DPSI_Z_I] / rz[0]; g->B.x[1] = 0.0; - g->B.x[2] = fout[DPSI_R_I]/rz[0]; + g->B.x[2] = fout[DPSI_R_I] / rz[0]; // \nabla X \hat{b} curlbhat_func(rz[0], rz[1], rzp[2], evcub, &g->curlbhat); } } } - - cleanup: + +cleanup: if (true != status) { gkyl_mirror_grid_gen_release(geo); geo = 0; fprintf(stderr, "gkyl_mirror_grid_gen_inew failed to generate a grid\n"); } - + gkyl_dg_basis_ops_evalf_release(evcub); - + return geo; } @@ -559,29 +576,30 @@ gkyl_mirror_grid_gen_surf_inew(const struct gkyl_mirror_grid_gen_inp *inp) geo->gg_x->include_axis = inp->include_axis; int nr = inp->nrcells, nz = inp->nzcells; - int cells[] = { nr, nz }; - double lower[2] = { inp->R[0], inp->Z[0] }; - double upper[2] = { inp->R[1], inp->Z[1] }; + int cells[] = {nr, nz}; + double lower[2] = {inp->R[0], inp->Z[0]}; + double upper[2] = {inp->R[1], inp->Z[1]}; struct gkyl_rect_grid gridRZ; gkyl_rect_grid_init(&gridRZ, 2, lower, upper, cells); - struct gkyl_basis_ops_evalf *evcub = - gkyl_dg_basis_ops_evalf_new(&gridRZ, inp->psiRZ); + struct gkyl_basis_ops_evalf *evcub = gkyl_dg_basis_ops_evalf_new(&gridRZ, inp->psiRZ); do { const char *fname = inp->psi_cubic_fname ? inp->psi_cubic_fname : "psi_cubic.gkyl"; - if (inp->write_psi_cubic) + if (inp->write_psi_cubic) { gkyl_dg_basis_ops_evalf_write_cubic(evcub, fname); + } } while (0); // Construct grid in RZ plane - + enum { NPSI, NAL, NZ }; - + geo->nodes_rza = gkyl_array_new(GKYL_DOUBLE, 3, inp->nrange.volume); geo->nodes_psi = gkyl_array_new(GKYL_DOUBLE, 1, inp->nrange.volume); - geo->nodes_geom = gkyl_array_new(GKYL_USER, sizeof(struct gkyl_mirror_grid_gen_geom), inp->nrange.volume); + geo->nodes_geom = + gkyl_array_new(GKYL_USER, sizeof(struct gkyl_mirror_grid_gen_geom), inp->nrange.volume); // Take special care for setting dpsi double psi_lo = inp->comp_grid->lower[0]; @@ -594,84 +612,96 @@ gkyl_mirror_grid_gen_surf_inew(const struct gkyl_mirror_grid_gen_inp *inp) psic_lo = inc_axis ? 0.0 : sqrt(psi_lo); psic_up = sqrt(psi_up); } - double dpsi = (psic_up-psic_lo)/(gkyl_range_shape(&inp->global,0)); + double dpsi = (psic_up - psic_lo) / (gkyl_range_shape(&inp->global, 0)); double dz = inp->comp_grid->dx[NZ]; double dalpha = inp->comp_grid->dx[NAL]; - double z_lo = inp->comp_grid->lower[NZ] + (inp->local.lower[NZ] - inp->global.lower[NZ])*inp->comp_grid->dx[NZ]; - double alpha_lo = inp->comp_grid->lower[NAL] + (inp->local.lower[NAL] - inp->global.lower[NAL])*inp->comp_grid->dx[NAL]; - psi_lo = inp->comp_grid->lower[NPSI] + (inp->local.lower[NPSI] - inp->global.lower[NPSI])*inp->comp_grid->dx[NPSI]; - psi_up = inp->comp_grid->lower[NPSI] + (inp->local.upper[NPSI] - inp->global.lower[NPSI])*inp->comp_grid->dx[NPSI]; + double z_lo = inp->comp_grid->lower[NZ] + + (inp->local.lower[NZ] - inp->global.lower[NZ]) * inp->comp_grid->dx[NZ]; + double alpha_lo = inp->comp_grid->lower[NAL] + + (inp->local.lower[NAL] - inp->global.lower[NAL]) * inp->comp_grid->dx[NAL]; + psi_lo = inp->comp_grid->lower[NPSI] + + (inp->local.lower[NPSI] - inp->global.lower[NPSI]) * inp->comp_grid->dx[NPSI]; + psi_up = inp->comp_grid->lower[NPSI] + + (inp->local.upper[NPSI] - inp->global.lower[NPSI]) * inp->comp_grid->dx[NPSI]; // Adjust if we are using sqrt(psi) as radial coordinate psic_lo = psi_lo; psic_up = psi_up; if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { // When we include axis, psi_lo is ignored - psic_lo = inp->dir==0 && inc_axis ? 0.0 : sqrt(psi_lo); + psic_lo = inp->dir == 0 && inc_axis ? 0.0 : sqrt(psi_lo); psic_up = sqrt(psi_up); } - double dels[2] = {1.0/sqrt(3), 1.0-1.0/sqrt(3) }; - z_lo += inp->dir == 2 ? 0.0 : dels[1]*dz/2.0; - psic_lo += inp->dir == 0 ? 0.0 : dels[1]*dpsi/2.0; - alpha_lo += inp->dir == 1 ? 0. : dels[1]*dalpha/2.0; + double dels[2] = {1.0 / sqrt(3), 1.0 - 1.0 / sqrt(3)}; + z_lo += inp->dir == 2 ? 0.0 : dels[1] * dz / 2.0; + psic_lo += inp->dir == 0 ? 0.0 : dels[1] * dpsi / 2.0; + alpha_lo += inp->dir == 1 ? 0. : dels[1] * dalpha / 2.0; double rlow = lower[0], rup = upper[0]; - double rmin = rlow + 1e-8*(rup-rlow); + double rmin = rlow + 1e-8 * (rup - rlow); - struct psirz_ctx pctx = { .evcub = evcub }; + struct psirz_ctx pctx = {.evcub = evcub}; // Compute node locations bool status = true; - for (int iz=inp->nrange.lower[NZ]; iz<=inp->nrange.upper[NZ]; ++iz) { - double zcurr = calc_running_coord(z_lo, iz-inp->nrange.lower[NZ], dz); - zcurr = inp->dir==2 ? z_lo + iz*dz: calc_running_coord(z_lo, iz-inp->nrange.lower[NZ], dz); + for (int iz = inp->nrange.lower[NZ]; iz <= inp->nrange.upper[NZ]; ++iz) { + double zcurr = calc_running_coord(z_lo, iz - inp->nrange.lower[NZ], dz); + zcurr = inp->dir == 2 ? z_lo + iz * dz : + calc_running_coord(z_lo, iz - inp->nrange.lower[NZ], dz); double Zcurr; - inp->position_map->maps[2](0.0, &zcurr, &Zcurr, inp->position_map->ctxs[2]); + inp->position_map->maps[2](0.0, &zcurr, &Zcurr, inp->position_map->ctxs[2]); zcurr = Zcurr; // update zcurr to be the mapped value double psi_min[1], psi_max[1]; - evcub->eval_cubic(0.0, (double[2]) { rmin, zcurr }, psi_min, evcub->ctx); - evcub->eval_cubic(0.0, (double[2]) { rup, zcurr }, psi_max, evcub->ctx); - - for (int ipsi=inp->nrange.lower[NPSI]; ipsi<=inp->nrange.upper[NPSI]; ++ipsi) { - - if (inc_axis && (ipsi == 0) && inp->dir==0) { - for (int ia=inp->nrange.lower[NAL]; ia<=inp->nrange.upper[NAL]; ++ia){ - double alpha_curr = calc_running_coord(alpha_lo, ia-inp->nrange.lower[NAL], dalpha); - int idx[3] = { ipsi, ia, iz }; + evcub->eval_cubic(0.0, (double[2]){rmin, zcurr}, psi_min, evcub->ctx); + evcub->eval_cubic(0.0, (double[2]){rup, zcurr}, psi_max, evcub->ctx); + + for (int ipsi = inp->nrange.lower[NPSI]; ipsi <= inp->nrange.upper[NPSI]; ++ipsi) { + if (inc_axis && (ipsi == 0) && inp->dir == 0) { + for (int ia = inp->nrange.lower[NAL]; ia <= inp->nrange.upper[NAL]; ++ia) { + double alpha_curr = calc_running_coord(alpha_lo, ia - inp->nrange.lower[NAL], dalpha); + int idx[3] = {ipsi, ia, iz}; double *rz = gkyl_array_fetch(geo->nodes_rza, gkyl_range_idx(&inp->nrange, idx)); - rz[0] = 0.0; rz[1] = zcurr; rz[2] = alpha_curr; + rz[0] = 0.0; + rz[1] = zcurr; + rz[2] = alpha_curr; } - } - else { - double psic_curr = inp->dir == 0 ? psic_lo + ipsi*dpsi : calc_running_coord(psic_lo, ipsi-inp->nrange.lower[NPSI], dpsi) ; + } else { + double psic_curr = inp->dir == 0 ? + psic_lo + ipsi * dpsi : + calc_running_coord(psic_lo, ipsi - inp->nrange.lower[NPSI], dpsi); pctx.Z = zcurr; // We continue to do root-finding for psi and not sqrt(psi) double psi_curr = psic_curr; - if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) - psi_curr = psic_curr*psic_curr; - - pctx.psi = psi_curr; - - struct gkyl_qr_res root = gkyl_ridders(psirz, &pctx, rmin, rup, - psi_min[0]-psi_curr, psi_max[0]-psi_curr, - 100, 1e-10); + if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { + psi_curr = psic_curr * psic_curr; + } + + pctx.psi = psi_curr; + + struct gkyl_qr_res root = gkyl_ridders( + psirz, &pctx, rmin, rup, psi_min[0] - psi_curr, psi_max[0] - psi_curr, 100, 1e-10 + ); if (root.status) { status = false; goto cleanup; } - - for (int ia=inp->nrange.lower[NAL]; ia<=inp->nrange.upper[NAL]; ++ia){ - double alpha_curr = inp->dir==1 ? alpha_lo + ia*dalpha : calc_running_coord(alpha_lo, ia-inp->nrange.lower[NAL], dalpha); - int idx[3] = { ipsi, ia, iz }; + + for (int ia = inp->nrange.lower[NAL]; ia <= inp->nrange.upper[NAL]; ++ia) { + double alpha_curr = inp->dir == 1 ? + alpha_lo + ia * dalpha : + calc_running_coord(alpha_lo, ia - inp->nrange.lower[NAL], dalpha); + int idx[3] = {ipsi, ia, iz}; double *rz = gkyl_array_fetch(geo->nodes_rza, gkyl_range_idx(&inp->nrange, idx)); - rz[0] = root.res; rz[1] = zcurr; rz[2] = alpha_curr; + rz[0] = root.res; + rz[1] = zcurr; + rz[2] = alpha_curr; double *psi_coord = gkyl_array_fetch(geo->nodes_psi, gkyl_range_idx(&inp->nrange, idx)); psi_coord[0] = psi_curr; // store psi coordinate } @@ -680,25 +710,25 @@ gkyl_mirror_grid_gen_surf_inew(const struct gkyl_mirror_grid_gen_inp *inp) } enum { PSI_I, DPSI_R_I, DPSI_Z_I }; - - // Compute geometry at nodes - for (int iz=inp->nrange.lower[NZ]; iz<=inp->nrange.upper[NZ]; ++iz) { - - for (int ipsi=inp->nrange.lower[NPSI]; ipsi<=inp->nrange.upper[NPSI]; ++ipsi) { - for (int ia=inp->nrange.lower[NAL]; ia<=inp->nrange.upper[NAL]; ++ia){ - int idx[3] = { ipsi, ia, iz }; + // Compute geometry at nodes + for (int iz = inp->nrange.lower[NZ]; iz <= inp->nrange.upper[NZ]; ++iz) { + for (int ipsi = inp->nrange.lower[NPSI]; ipsi <= inp->nrange.upper[NPSI]; ++ipsi) { + for (int ia = inp->nrange.lower[NAL]; ia <= inp->nrange.upper[NAL]; ++ia) { + int idx[3] = {ipsi, ia, iz}; long loc = gkyl_range_idx(&inp->nrange, idx); - + const double *rzp = gkyl_array_cfetch(geo->nodes_rza, loc); - double rz[2] = { rzp[0], rzp[1] }; + double rz[2] = {rzp[0], rzp[1]}; + + double dZ_dz = gkyl_position_map_slope( + inp->position_map, 2, rzp[1], dz, iz, + &inp->nrange + ); // derivative of the position map in Z direction - double dZ_dz = gkyl_position_map_slope(inp->position_map, 2, rzp[1], - dz, iz, &inp->nrange); // derivative of the position map in Z direction - struct gkyl_mirror_grid_gen_geom *g = gkyl_array_fetch(geo->nodes_geom, loc); - - if (inc_axis && (ipsi == 0) && inp->dir==0) { + + if (inc_axis && (ipsi == 0) && inp->dir == 0) { double fout2[4]; // second derivative of psi is needed evcub->eval_cubic_wgrad2(0.0, rz, fout2, evcub->ctx); @@ -707,7 +737,7 @@ gkyl_mirror_grid_gen_surf_inew(const struct gkyl_mirror_grid_gen_inp *inp) // duals. However, the Jacobians and magnetic field are // correct and computed using the estimated asymptotic // behavior of psi as r -> 0. - + g->dual[0].x[0] = 1.0; g->dual[0].x[1] = 0.0; g->dual[0].x[2] = 0.0; @@ -726,16 +756,17 @@ gkyl_mirror_grid_gen_surf_inew(const struct gkyl_mirror_grid_gen_inp *inp) g->tang[1].x[0] = 0.0; g->tang[1].x[1] = 1.0; - g->tang[1].x[2] = 0.0; - + g->tang[1].x[2] = 0.0; + g->tang[2].x[0] = 0; g->tang[2].x[1] = 0.0; g->tang[2].x[2] = 1.0 * dZ_dz; - - if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) + + if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { g->Jc = 0; // assumes asymptotics of psi ~ r^2 as r -> 0 - else - g->Jc = 1/fout2[DPSI_R_I] * dZ_dz; + } else { + g->Jc = 1 / fout2[DPSI_R_I] * dZ_dz; + } g->B.x[0] = 0.0; // no radial component g->B.x[1] = 0.0; @@ -745,25 +776,24 @@ gkyl_mirror_grid_gen_surf_inew(const struct gkyl_mirror_grid_gen_inp *inp) g->curlbhat.x[0] = 0.0; g->curlbhat.x[1] = 0.0; g->curlbhat.x[2] = 0.0; - } - else { + } else { double fout[3]; // first derivative of psi is needed evcub->eval_cubic_wgrad(0.0, rz, fout, evcub->ctx); - + // e^1 g->dual[0].x[0] = fout[DPSI_R_I]; // dpsi/dr g->dual[0].x[1] = 0.0; // no toroidal component g->dual[0].x[2] = fout[DPSI_Z_I]; // dspi/dz - + if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { // for sqrt(psi) as radial coordinate e^1 = grad(psi)/2*sqrt(psi) - g->dual[0].x[0] = g->dual[0].x[0]/(2*floor_sqrt(fout[0])); - g->dual[0].x[2] = g->dual[0].x[2]/(2*floor_sqrt(fout[0])); + g->dual[0].x[0] = g->dual[0].x[0] / (2 * floor_sqrt(fout[0])); + g->dual[0].x[2] = g->dual[0].x[2] / (2 * floor_sqrt(fout[0])); } // e^2 is just e^phi g->dual[1].x[0] = 0; - g->dual[1].x[1] = 1.0/(rz[0]*rz[0]); + g->dual[1].x[1] = 1.0 / (rz[0] * rz[0]); g->dual[1].x[2] = 0.0; // e^3 is just sigma_3 @@ -772,7 +802,7 @@ gkyl_mirror_grid_gen_surf_inew(const struct gkyl_mirror_grid_gen_inp *inp) g->dual[2].x[2] = 1.0 / dZ_dz; // e_1 points along the radial direction - g->tang[0].x[0] = 1/g->dual[0].x[0]; + g->tang[0].x[0] = 1 / g->dual[0].x[0]; g->tang[0].x[1] = 0.0; g->tang[0].x[2] = 0.0; @@ -782,18 +812,19 @@ gkyl_mirror_grid_gen_surf_inew(const struct gkyl_mirror_grid_gen_inp *inp) g->tang[1].x[2] = 0.0; // e_3 - g->tang[2].x[0] = -fout[DPSI_Z_I]/fout[DPSI_R_I]; + g->tang[2].x[0] = -fout[DPSI_Z_I] / fout[DPSI_R_I]; g->tang[2].x[1] = 0.0; g->tang[2].x[2] = 1.0 * dZ_dz; - - if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) - g->Jc = 2*floor_sqrt(fout[PSI_I])*rz[0]/fout[DPSI_R_I] * dZ_dz; - else - g->Jc = rz[0]/fout[DPSI_R_I] * dZ_dz; - - g->B.x[0] = -fout[DPSI_Z_I]/rz[0]; + + if (inp->fl_coord == GKYL_GEOMETRY_MIRROR_GRID_GEN_SQRT_PSI_CART_Z) { + g->Jc = 2 * floor_sqrt(fout[PSI_I]) * rz[0] / fout[DPSI_R_I] * dZ_dz; + } else { + g->Jc = rz[0] / fout[DPSI_R_I] * dZ_dz; + } + + g->B.x[0] = -fout[DPSI_Z_I] / rz[0]; g->B.x[1] = 0.0; - g->B.x[2] = fout[DPSI_R_I]/rz[0]; + g->B.x[2] = fout[DPSI_R_I] / rz[0]; // \nabla X \hat{b} curlbhat_func(rz[0], rz[1], rzp[2], evcub, &g->curlbhat); @@ -801,35 +832,32 @@ gkyl_mirror_grid_gen_surf_inew(const struct gkyl_mirror_grid_gen_inp *inp) } } } - - cleanup: + +cleanup: if (true != status) { gkyl_mirror_grid_gen_release(geo); geo = 0; fprintf(stderr, "gkyl_mirror_grid_gen_inew failed to generate a grid\n"); } - + gkyl_dg_basis_ops_evalf_release(evcub); - + return geo; } - -bool -gkyl_mirror_grid_gen_is_include_axis(const struct gkyl_mirror_grid_gen *geom) +bool gkyl_mirror_grid_gen_is_include_axis(const struct gkyl_mirror_grid_gen *geom) { return geom->gg_x->include_axis; } enum gkyl_mirror_grid_gen_field_line_coord - gkyl_mirror_grid_gen_fl_coord(const struct gkyl_mirror_grid_gen *geom) +gkyl_mirror_grid_gen_fl_coord(const struct gkyl_mirror_grid_gen *geom) { return geom->gg_x->fl_coord; } - -void -gkyl_mirror_grid_gen_release(struct gkyl_mirror_grid_gen *geom) + +void gkyl_mirror_grid_gen_release(struct gkyl_mirror_grid_gen *geom) { gkyl_array_release(geom->nodes_rza); gkyl_array_release(geom->nodes_psi); diff --git a/gyrokinetic/zero/mom_bcorr_lbo_gyrokinetic.c b/gyrokinetic/zero/mom_bcorr_lbo_gyrokinetic.c index ad876b23c4..67a8bab63a 100644 --- a/gyrokinetic/zero/mom_bcorr_lbo_gyrokinetic.c +++ b/gyrokinetic/zero/mom_bcorr_lbo_gyrokinetic.c @@ -8,33 +8,35 @@ #include #include -void -gk_mom_free(const struct gkyl_ref_count *ref) +void gk_mom_free(const struct gkyl_ref_count *ref) { struct gkyl_mom_type *momt = container_of(ref, struct gkyl_mom_type, ref_count); - struct mom_type_bcorr_lbo_gyrokinetic *mom_bcorr = container_of(momt, struct mom_type_bcorr_lbo_gyrokinetic, momt); + struct mom_type_bcorr_lbo_gyrokinetic *mom_bcorr = + container_of(momt, struct mom_type_bcorr_lbo_gyrokinetic, momt); gkyl_velocity_map_release(mom_bcorr->vel_map); - if (GKYL_IS_CU_ALLOC(momt->flags)) + if (GKYL_IS_CU_ALLOC(momt->flags)) { gkyl_cu_free(momt->on_dev); + } gkyl_free(momt); } - -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_gyrokinetic_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - double mass, const struct gkyl_velocity_map *vel_map, bool use_gpu) +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_gyrokinetic_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, double mass, + const struct gkyl_velocity_map *vel_map, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_mom_bcorr_lbo_gyrokinetic_cu_dev_new(cbasis, pbasis, mass, vel_map); - } -#endif - struct mom_type_bcorr_lbo_gyrokinetic *mom_bcorr = gkyl_malloc(sizeof(struct mom_type_bcorr_lbo_gyrokinetic)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + } +#endif + struct mom_type_bcorr_lbo_gyrokinetic *mom_bcorr = + gkyl_malloc(sizeof(struct mom_type_bcorr_lbo_gyrokinetic)); + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_bcorr->momt.cdim = cdim; @@ -48,32 +50,33 @@ gkyl_mom_bcorr_lbo_gyrokinetic_new(const struct gkyl_basis* cbasis, const struct const gkyl_mom_bcorr_lbo_gyrokinetic_kern_list *mom_bcorr_lbo_gyrokinetic_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - mom_bcorr_lbo_gyrokinetic_kernels = ser_mom_bcorr_lbo_gyrokinetic_kernels; - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + mom_bcorr_lbo_gyrokinetic_kernels = ser_mom_bcorr_lbo_gyrokinetic_kernels; + break; /* case GKYL_BASIS_MODAL_TENSOR: */ /* mom_bcorr_lbo_gyrokinetic_kernels = ten_mom_bcorr_lbo_gyrokinetic_kernels; */ /* break; */ - default: - assert(false); - break; + default: + assert(false); + break; } assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != mom_bcorr_lbo_gyrokinetic_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - mom_bcorr->kernel = mom_bcorr_lbo_gyrokinetic_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; + mom_bcorr->kernel = + mom_bcorr_lbo_gyrokinetic_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_bcorr->momt.num_mom = 2; mom_bcorr->_m = mass; mom_bcorr->vel_map = gkyl_velocity_map_acquire(vel_map); - + mom_bcorr->momt.flags = 0; GKYL_CLEAR_CU_ALLOC(mom_bcorr->momt.flags); mom_bcorr->momt.ref_count = gkyl_ref_count_init(gk_mom_free); mom_bcorr->momt.on_dev = &mom_bcorr->momt; - + return &mom_bcorr->momt; } diff --git a/gyrokinetic/zero/mom_bcorr_lbo_gyrokinetic_cu.cu b/gyrokinetic/zero/mom_bcorr_lbo_gyrokinetic_cu.cu index 27b40da46d..10151369c8 100644 --- a/gyrokinetic/zero/mom_bcorr_lbo_gyrokinetic_cu.cu +++ b/gyrokinetic/zero/mom_bcorr_lbo_gyrokinetic_cu.cu @@ -10,9 +10,10 @@ extern "C" { #include } -__global__ -static void -gkyl_mom_bcorr_lbo_gyrokinetic_set_cu_dev_ptrs(struct mom_type_bcorr_lbo_gyrokinetic* mom_bcorr, enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx) +__global__ static void gkyl_mom_bcorr_lbo_gyrokinetic_set_cu_dev_ptrs( + struct mom_type_bcorr_lbo_gyrokinetic *mom_bcorr, enum gkyl_basis_type b_type, int vdim, + int poly_order, int tblidx +) { mom_bcorr->momt.kernel = kernel; @@ -24,9 +25,9 @@ gkyl_mom_bcorr_lbo_gyrokinetic_set_cu_dev_ptrs(struct mom_type_bcorr_lbo_gyrokin mom_bcorr_lbo_gyrokinetic_kernels = ser_mom_bcorr_lbo_gyrokinetic_kernels; break; - // case GKYL_BASIS_MODAL_TENSOR: - // mom_bcorr_lbo_gyrokinetic_kernels = ten_mom_bcorr_lbo_gyrokinetic_kernels; - // break; + // case GKYL_BASIS_MODAL_TENSOR: + // mom_bcorr_lbo_gyrokinetic_kernels = ten_mom_bcorr_lbo_gyrokinetic_kernels; + // break; default: assert(false); @@ -36,15 +37,17 @@ gkyl_mom_bcorr_lbo_gyrokinetic_set_cu_dev_ptrs(struct mom_type_bcorr_lbo_gyrokin mom_bcorr->momt.num_mom = 2; } -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - double mass, const struct gkyl_velocity_map *vel_map) +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_gyrokinetic_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, double mass, + const struct gkyl_velocity_map *vel_map +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_bcorr_lbo_gyrokinetic *mom_bcorr = (struct mom_type_bcorr_lbo_gyrokinetic*) gkyl_malloc(sizeof(*mom_bcorr)); + struct mom_type_bcorr_lbo_gyrokinetic *mom_bcorr = + (struct mom_type_bcorr_lbo_gyrokinetic *)gkyl_malloc(sizeof(*mom_bcorr)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_bcorr->momt.cdim = cdim; @@ -64,14 +67,17 @@ gkyl_mom_bcorr_lbo_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, const mom_bcorr->momt.ref_count = gkyl_ref_count_init(gk_mom_free); // copy struct to device - struct mom_type_bcorr_lbo_gyrokinetic *mom_bcorr_cu = (struct mom_type_bcorr_lbo_gyrokinetic*) + struct mom_type_bcorr_lbo_gyrokinetic *mom_bcorr_cu = (struct mom_type_bcorr_lbo_gyrokinetic *) gkyl_cu_malloc(sizeof(struct mom_type_bcorr_lbo_gyrokinetic)); - gkyl_cu_memcpy(mom_bcorr_cu, mom_bcorr, sizeof(struct mom_type_bcorr_lbo_gyrokinetic), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + mom_bcorr_cu, mom_bcorr, sizeof(struct mom_type_bcorr_lbo_gyrokinetic), GKYL_CU_MEMCPY_H2D + ); assert(cv_index[cdim].vdim[vdim] != -1); - gkyl_mom_bcorr_lbo_gyrokinetic_set_cu_dev_ptrs<<<1,1>>>(mom_bcorr_cu, cbasis->b_type, - vdim, poly_order, cv_index[cdim].vdim[vdim]); + gkyl_mom_bcorr_lbo_gyrokinetic_set_cu_dev_ptrs<<<1, 1> > >( + mom_bcorr_cu, cbasis->b_type, vdim, poly_order, cv_index[cdim].vdim[vdim] + ); mom_bcorr->momt.on_dev = &mom_bcorr_cu->momt; diff --git a/gyrokinetic/zero/mom_calc_bcorr_gyrokinetic.c b/gyrokinetic/zero/mom_calc_bcorr_gyrokinetic.c index 3a132047f9..1e3c264b57 100644 --- a/gyrokinetic/zero/mom_calc_bcorr_gyrokinetic.c +++ b/gyrokinetic/zero/mom_calc_bcorr_gyrokinetic.c @@ -12,14 +12,15 @@ #include // "derived" class constructors -struct gkyl_mom_calc_bcorr* -gkyl_mom_calc_bcorr_lbo_gyrokinetic_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - double mass, const struct gkyl_velocity_map *vel_map, bool use_gpu) +struct gkyl_mom_calc_bcorr *gkyl_mom_calc_bcorr_lbo_gyrokinetic_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, double mass, const struct gkyl_velocity_map *vel_map, + bool use_gpu +) { struct gkyl_mom_type *bcorr_type; // LBO boundary corrections moment type bcorr_type = gkyl_mom_bcorr_lbo_gyrokinetic_new(cbasis, pbasis, mass, vel_map, use_gpu); - struct gkyl_mom_calc_bcorr* calc = gkyl_mom_calc_bcorr_new(grid, bcorr_type, use_gpu); + struct gkyl_mom_calc_bcorr *calc = gkyl_mom_calc_bcorr_new(grid, bcorr_type, use_gpu); // Since calc now has pointer to specific type, decrease reference counter of type // so that eventual gkyl_mom_calc_bcorr_release method on calculator deallocates specific type data gkyl_mom_type_release(bcorr_type); diff --git a/gyrokinetic/zero/mom_gyrokinetic.c b/gyrokinetic/zero/mom_gyrokinetic.c index 5aa5574a7d..30cfbdf94b 100644 --- a/gyrokinetic/zero/mom_gyrokinetic.c +++ b/gyrokinetic/zero/mom_gyrokinetic.c @@ -8,39 +8,45 @@ #include #include -void -gkyl_gk_mom_free(const struct gkyl_ref_count *ref) +void gkyl_gk_mom_free(const struct gkyl_ref_count *ref) { struct gkyl_mom_type *base = container_of(ref, struct gkyl_mom_type, ref_count); struct mom_type_gyrokinetic *mom_gk = container_of(base, struct mom_type_gyrokinetic, momt); gkyl_velocity_map_release(mom_gk->vel_map); gkyl_gk_geometry_release(mom_gk->gk_geom); - if (mom_gk->phi != 0) + if (mom_gk->phi != 0) { gkyl_array_release(mom_gk->phi); + } if (gkyl_mom_type_is_cu_dev(base)) { // free inner on_dev object - struct mom_type_gyrokinetic *mom_gk_cu = container_of(base->on_dev, struct mom_type_gyrokinetic, momt); + struct mom_type_gyrokinetic *mom_gk_cu = + container_of(base->on_dev, struct mom_type_gyrokinetic, momt); gkyl_cu_free(mom_gk_cu); } gkyl_free(mom_gk); } -struct gkyl_mom_type* -gkyl_mom_gyrokinetic_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, double mass, double charge, const struct gkyl_velocity_map* vel_map, - const struct gk_geometry *gk_geom, struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool use_gpu) +struct gkyl_mom_type *gkyl_mom_gyrokinetic_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, double mass, double charge, + const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, + struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA - if (use_gpu) - return gkyl_mom_gyrokinetic_cu_dev_new(cbasis, pbasis, conf_range, mass, charge, vel_map, gk_geom, phi, mom_type); -#endif + if (use_gpu) { + return gkyl_mom_gyrokinetic_cu_dev_new( + cbasis, pbasis, conf_range, mass, charge, vel_map, gk_geom, phi, mom_type + ); + } +#endif struct mom_type_gyrokinetic *mom_gk = gkyl_malloc(sizeof(struct mom_type_gyrokinetic)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_gk->momt.cdim = cdim; @@ -50,102 +56,94 @@ gkyl_mom_gyrokinetic_new(const struct gkyl_basis* cbasis, const struct gkyl_basi mom_gk->momt.num_phase = pbasis->num_basis; // choose kernel tables based on basis-function type - const gkyl_gyrokinetic_mom_kern_list *m0_kernels, *m1_kernels, *m2_kernels, - *m2_par_kernels, *m2_perp_kernels, *m3_par_kernels, *m3_perp_kernels, - *three_moments_kernels, *four_moments_kernels, *hamiltonian_moments_kernels; + const gkyl_gyrokinetic_mom_kern_list *m0_kernels, *m1_kernels, *m2_kernels, *m2_par_kernels, + *m2_perp_kernels, *m3_par_kernels, *m3_perp_kernels, *three_moments_kernels, + *four_moments_kernels, *hamiltonian_moments_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - m0_kernels = ser_m0_kernels; - m1_kernels = ser_m1_kernels; - m2_kernels = ser_m2_kernels; - m2_par_kernels = ser_m2_par_kernels; - m2_perp_kernels = ser_m2_perp_kernels; - m3_par_kernels = ser_m3_par_kernels; - m3_perp_kernels = ser_m3_perp_kernels; - three_moments_kernels = ser_three_moments_kernels; - four_moments_kernels = ser_four_moments_kernels; - hamiltonian_moments_kernels = ser_hamiltonian_moments_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + m0_kernels = ser_m0_kernels; + m1_kernels = ser_m1_kernels; + m2_kernels = ser_m2_kernels; + m2_par_kernels = ser_m2_par_kernels; + m2_perp_kernels = ser_m2_perp_kernels; + m3_par_kernels = ser_m3_par_kernels; + m3_perp_kernels = ser_m3_perp_kernels; + three_moments_kernels = ser_three_moments_kernels; + four_moments_kernels = ser_four_moments_kernels; + hamiltonian_moments_kernels = ser_hamiltonian_moments_kernels; + break; + + default: + assert(false); + break; } if (mom_type == GKYL_F_MOMENT_M0) { // density assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m0_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = m0_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M1) { // parallel momentum + } else if (mom_type == GKYL_F_MOMENT_M1) { // parallel momentum assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m1_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = m1_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M2) { // total kinetic energy + } else if (mom_type == GKYL_F_MOMENT_M2) { // total kinetic energy assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m2_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = m2_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M2PAR) { // parallel energy + } else if (mom_type == GKYL_F_MOMENT_M2PAR) { // parallel energy assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m2_par_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = m2_par_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M2PERP) { // perpendicular energy + } else if (mom_type == GKYL_F_MOMENT_M2PERP) { // perpendicular energy assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m2_perp_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = m2_perp_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M3PAR) { // parallel heat flux + } else if (mom_type == GKYL_F_MOMENT_M3PAR) { // parallel heat flux assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m3_par_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = m3_par_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M3PERP) { // perpendicular heat flux + } else if (mom_type == GKYL_F_MOMENT_M3PERP) { // perpendicular heat flux assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m3_perp_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = m3_perp_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M0M1M2) { + } else if (mom_type == GKYL_F_MOMENT_M0M1M2) { // Density, parallel momentum, and total energy computed together. - assert(cv_index[cdim].vdim[vdim] != -1); + assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != three_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = three_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 3; - } - else if (mom_type == GKYL_F_MOMENT_M0M1M2PARM2PERP) { // Density, parallel momentum, parallel and perpendicular - // kinetic energy computed together. + } else if (mom_type == + GKYL_F_MOMENT_M0M1M2PARM2PERP) { // Density, parallel momentum, parallel and perpendicular + // kinetic energy computed together. assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != four_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = four_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - mom_gk->momt.num_mom = vdim+2; - } - else if (mom_type == GKYL_F_MOMENT_HAMILTONIAN) { // M0, mass*M0 and total particle energy + mom_gk->momt.num_mom = vdim + 2; + } else if (mom_type == GKYL_F_MOMENT_HAMILTONIAN) { // M0, mass*M0 and total particle energy assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != hamiltonian_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - - mom_gk->momt.kernel = hamiltonian_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; + + mom_gk->momt.kernel = + hamiltonian_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 3; - } - else { + } else { // string not recognized printf("Error: requested moment %d.\n", mom_type); gkyl_exit("gkyl_mom_type_gyrokinetic: Unrecognized moment requested!"); @@ -157,32 +155,38 @@ gkyl_mom_gyrokinetic_new(const struct gkyl_basis* cbasis, const struct gkyl_basi mom_gk->vel_map = gkyl_velocity_map_acquire(vel_map); mom_gk->gk_geom = gkyl_gk_geometry_acquire(gk_geom); mom_gk->phi = 0; - if (phi) + if (phi) { mom_gk->phi = gkyl_array_acquire(phi); - + } + mom_gk->momt.flags = 0; GKYL_CLEAR_CU_ALLOC(mom_gk->momt.flags); mom_gk->momt.ref_count = gkyl_ref_count_init(gkyl_gk_mom_free); - + mom_gk->momt.on_dev = &mom_gk->momt; // on host, self-reference - + return &mom_gk->momt; } -struct gkyl_mom_type* -gkyl_int_mom_gyrokinetic_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, double mass, double charge, const struct gkyl_velocity_map* vel_map, - const struct gk_geometry *gk_geom, struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool use_gpu) +struct gkyl_mom_type *gkyl_int_mom_gyrokinetic_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, double mass, double charge, + const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, + struct gkyl_array *phi, enum gkyl_distribution_moments mom_type, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA - if(use_gpu) - return gkyl_int_mom_gyrokinetic_cu_dev_new(cbasis, pbasis, conf_range, mass, charge, vel_map, gk_geom, phi, mom_type); + if (use_gpu) { + return gkyl_int_mom_gyrokinetic_cu_dev_new( + cbasis, pbasis, conf_range, mass, charge, vel_map, gk_geom, phi, mom_type + ); + } #endif struct mom_type_gyrokinetic *mom_gk = gkyl_malloc(sizeof(struct mom_type_gyrokinetic)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_gk->momt.cdim = cdim; @@ -190,104 +194,95 @@ gkyl_int_mom_gyrokinetic_new(const struct gkyl_basis* cbasis, const struct gkyl_ mom_gk->momt.poly_order = poly_order; mom_gk->momt.num_config = cbasis->num_basis; mom_gk->momt.num_phase = pbasis->num_basis; - + // Choose kernel tables based on basis-function type. - const gkyl_gyrokinetic_mom_kern_list *int_three_moments_kernels, *int_four_moments_kernels, *int_hamiltonian_moments_kernels, - *int_m0_kernels, *int_m1_kernels, *int_m2_par_kernels, *int_m2_perp_kernels, - *int_m2_kernels, *int_m3_par_kernels, *int_m3_perp_kernels; + const gkyl_gyrokinetic_mom_kern_list *int_three_moments_kernels, *int_four_moments_kernels, + *int_hamiltonian_moments_kernels, *int_m0_kernels, *int_m1_kernels, *int_m2_par_kernels, + *int_m2_perp_kernels, *int_m2_kernels, *int_m3_par_kernels, *int_m3_perp_kernels; // Set kernel pointer. switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - int_m0_kernels = ser_int_m0_kernels; - int_m1_kernels = ser_int_m1_kernels; - int_m2_par_kernels = ser_int_m2_par_kernels; - int_m2_perp_kernels = ser_int_m2_perp_kernels; - int_m2_kernels = ser_int_m2_kernels; - int_three_moments_kernels = ser_int_three_moments_kernels; - int_four_moments_kernels = ser_int_four_moments_kernels; - int_hamiltonian_moments_kernels = ser_int_hamiltonian_moments_kernels; - break; - - default: - assert(false); - break; - } - - assert(cv_index[cdim].vdim[vdim] != -1); + case GKYL_BASIS_MODAL_SERENDIPITY: + int_m0_kernels = ser_int_m0_kernels; + int_m1_kernels = ser_int_m1_kernels; + int_m2_par_kernels = ser_int_m2_par_kernels; + int_m2_perp_kernels = ser_int_m2_perp_kernels; + int_m2_kernels = ser_int_m2_kernels; + int_three_moments_kernels = ser_int_three_moments_kernels; + int_four_moments_kernels = ser_int_four_moments_kernels; + int_hamiltonian_moments_kernels = ser_int_hamiltonian_moments_kernels; + break; + + default: + assert(false); + break; + } + + assert(cv_index[cdim].vdim[vdim] != -1); if (mom_type == GKYL_F_MOMENT_M0) { // Density moment only. assert(NULL != int_m0_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = int_m0_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M1) { + } else if (mom_type == GKYL_F_MOMENT_M1) { // Parallel momentum moment only. assert(NULL != int_m1_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = int_m1_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M2PAR) { + } else if (mom_type == GKYL_F_MOMENT_M2PAR) { // Parallel kinetic energy moment only. assert(NULL != int_m2_par_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = int_m2_par_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M2PERP) { + } else if (mom_type == GKYL_F_MOMENT_M2PERP) { // Perpendicular kinetic energy moment only. assert(NULL != int_m2_perp_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = int_m2_perp_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M2) { + } else if (mom_type == GKYL_F_MOMENT_M2) { // Kinetic energy moment only. assert(NULL != int_m2_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = int_m2_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M3PAR) { + } else if (mom_type == GKYL_F_MOMENT_M3PAR) { // Parallel heat flux moment only. assert(NULL != int_m3_par_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = int_m3_par_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M3PERP) { + } else if (mom_type == GKYL_F_MOMENT_M3PERP) { // Perpendicular heat flux moment only. assert(NULL != int_m3_perp_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = int_m3_perp_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M0M1M2) { + } else if (mom_type == GKYL_F_MOMENT_M0M1M2) { // Density, parallel momentum, and kinetic energy computed together. assert(NULL != int_three_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = int_three_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 3; - } - else if (mom_type == GKYL_F_MOMENT_M0M1M2PARM2PERP) { + } else if (mom_type == GKYL_F_MOMENT_M0M1M2PARM2PERP) { // Density, parallel momentum, and parallel and perpendicular kinetic energy. assert(NULL != int_four_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_gk->momt.kernel = int_four_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - mom_gk->momt.num_mom = vdim+2; - } - else if (mom_type == GKYL_F_MOMENT_HAMILTONIAN) { + mom_gk->momt.num_mom = vdim + 2; + } else if (mom_type == GKYL_F_MOMENT_HAMILTONIAN) { // Density), parallel momentum, and total energy computed together. assert(NULL != int_hamiltonian_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - - mom_gk->momt.kernel = int_hamiltonian_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; + + mom_gk->momt.kernel = + int_hamiltonian_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_gk->momt.num_mom = 3; - } - else { - fprintf(stderr,"Moment option %d not available.\n",mom_type); + } else { + fprintf(stderr, "Moment option %d not available.\n", mom_type); assert(false); } @@ -297,15 +292,15 @@ gkyl_int_mom_gyrokinetic_new(const struct gkyl_basis* cbasis, const struct gkyl_ mom_gk->vel_map = gkyl_velocity_map_acquire(vel_map); mom_gk->gk_geom = gkyl_gk_geometry_acquire(gk_geom); mom_gk->phi = 0; - if (phi) + if (phi) { mom_gk->phi = gkyl_array_acquire(phi); + } mom_gk->momt.flags = 0; GKYL_CLEAR_CU_ALLOC(mom_gk->momt.flags); mom_gk->momt.ref_count = gkyl_ref_count_init(gkyl_gk_mom_free); - + mom_gk->momt.on_dev = &mom_gk->momt; // on host, self-reference - - return &mom_gk->momt; -} + return &mom_gk->momt; +} diff --git a/gyrokinetic/zero/mom_gyrokinetic_cu.cu b/gyrokinetic/zero/mom_gyrokinetic_cu.cu index a23aadafe7..78f948f6c4 100644 --- a/gyrokinetic/zero/mom_gyrokinetic_cu.cu +++ b/gyrokinetic/zero/mom_gyrokinetic_cu.cu @@ -12,139 +12,140 @@ extern "C" { #include } -static int -gk_num_mom(int vdim, enum gkyl_distribution_moments mom_type) +static int gk_num_mom(int vdim, enum gkyl_distribution_moments mom_type) { int num_mom = 0; - + switch (mom_type) { - case GKYL_F_MOMENT_M0: - case GKYL_F_MOMENT_M1: - case GKYL_F_MOMENT_M2: - case GKYL_F_MOMENT_M2PAR: - case GKYL_F_MOMENT_M2PERP: - case GKYL_F_MOMENT_M3PAR: - case GKYL_F_MOMENT_M3PERP: - num_mom = 1; - break; - - case GKYL_F_MOMENT_M0M1M2: - num_mom = 3; - break; - - case GKYL_F_MOMENT_M0M1M2PARM2PERP: - num_mom = vdim+2; - break; - - case GKYL_F_MOMENT_HAMILTONIAN: - num_mom = 3; - break; - - default: // can't happen - fprintf(stderr,"Moment option %d not available.\n",mom_type); - assert(false); - break; + case GKYL_F_MOMENT_M0: + case GKYL_F_MOMENT_M1: + case GKYL_F_MOMENT_M2: + case GKYL_F_MOMENT_M2PAR: + case GKYL_F_MOMENT_M2PERP: + case GKYL_F_MOMENT_M3PAR: + case GKYL_F_MOMENT_M3PERP: + num_mom = 1; + break; + + case GKYL_F_MOMENT_M0M1M2: + num_mom = 3; + break; + + case GKYL_F_MOMENT_M0M1M2PARM2PERP: + num_mom = vdim + 2; + break; + + case GKYL_F_MOMENT_HAMILTONIAN: + num_mom = 3; + break; + + default: // can't happen + fprintf(stderr, "Moment option %d not available.\n", mom_type); + assert(false); + break; } return num_mom; } -__global__ -static void -set_cu_ptrs(struct mom_type_gyrokinetic *mom_gk, enum gkyl_distribution_moments mom_type, - enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx) +__global__ static void set_cu_ptrs( + struct mom_type_gyrokinetic *mom_gk, enum gkyl_distribution_moments mom_type, + enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx +) { // choose kernel tables based on basis-function type - const gkyl_gyrokinetic_mom_kern_list *m0_kernels, *m1_kernels, *m2_kernels, - *m2_par_kernels, *m2_perp_kernels, *m3_par_kernels, *m3_perp_kernels, - *three_moments_kernels, *four_moments_kernels, *hamiltonian_moments_kernels; - + const gkyl_gyrokinetic_mom_kern_list *m0_kernels, *m1_kernels, *m2_kernels, *m2_par_kernels, + *m2_perp_kernels, *m3_par_kernels, *m3_perp_kernels, *three_moments_kernels, + *four_moments_kernels, *hamiltonian_moments_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - m0_kernels = ser_m0_kernels; - m1_kernels = ser_m1_kernels; - m2_kernels = ser_m2_kernels; - m2_par_kernels = ser_m2_par_kernels; - m2_perp_kernels = ser_m2_perp_kernels; - m3_par_kernels = ser_m3_par_kernels; - m3_perp_kernels = ser_m3_perp_kernels; - three_moments_kernels = ser_three_moments_kernels; - four_moments_kernels = ser_four_moments_kernels; - hamiltonian_moments_kernels = ser_hamiltonian_moments_kernels; - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + m0_kernels = ser_m0_kernels; + m1_kernels = ser_m1_kernels; + m2_kernels = ser_m2_kernels; + m2_par_kernels = ser_m2_par_kernels; + m2_perp_kernels = ser_m2_perp_kernels; + m3_par_kernels = ser_m3_par_kernels; + m3_perp_kernels = ser_m3_perp_kernels; + three_moments_kernels = ser_three_moments_kernels; + four_moments_kernels = ser_four_moments_kernels; + hamiltonian_moments_kernels = ser_hamiltonian_moments_kernels; + break; + + default: + assert(false); + break; + } + switch (mom_type) { - case GKYL_F_MOMENT_M0: - mom_gk->momt.kernel = m0_kernels[tblidx].kernels[poly_order]; - mom_gk->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M1: - mom_gk->momt.kernel = m1_kernels[tblidx].kernels[poly_order]; - mom_gk->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M2: - mom_gk->momt.kernel = m2_kernels[tblidx].kernels[poly_order]; - mom_gk->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M2PAR: - mom_gk->momt.kernel = m2_par_kernels[tblidx].kernels[poly_order]; - mom_gk->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M2PERP: - mom_gk->momt.kernel = m2_perp_kernels[tblidx].kernels[poly_order]; - mom_gk->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M3PAR: - mom_gk->momt.kernel = m3_par_kernels[tblidx].kernels[poly_order]; - mom_gk->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M3PERP: - mom_gk->momt.kernel = m3_perp_kernels[tblidx].kernels[poly_order]; - mom_gk->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M0M1M2: - mom_gk->momt.kernel = three_moments_kernels[tblidx].kernels[poly_order]; - mom_gk->momt.num_mom = 3; - break; - - case GKYL_F_MOMENT_M0M1M2PARM2PERP: - mom_gk->momt.kernel = four_moments_kernels[tblidx].kernels[poly_order]; - mom_gk->momt.num_mom = vdim+2; - break; - - case GKYL_F_MOMENT_HAMILTONIAN: - mom_gk->momt.kernel = hamiltonian_moments_kernels[tblidx].kernels[poly_order]; - mom_gk->momt.num_mom = 3; - break; - - default: // can't happen - break; + case GKYL_F_MOMENT_M0: + mom_gk->momt.kernel = m0_kernels[tblidx].kernels[poly_order]; + mom_gk->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M1: + mom_gk->momt.kernel = m1_kernels[tblidx].kernels[poly_order]; + mom_gk->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M2: + mom_gk->momt.kernel = m2_kernels[tblidx].kernels[poly_order]; + mom_gk->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M2PAR: + mom_gk->momt.kernel = m2_par_kernels[tblidx].kernels[poly_order]; + mom_gk->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M2PERP: + mom_gk->momt.kernel = m2_perp_kernels[tblidx].kernels[poly_order]; + mom_gk->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M3PAR: + mom_gk->momt.kernel = m3_par_kernels[tblidx].kernels[poly_order]; + mom_gk->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M3PERP: + mom_gk->momt.kernel = m3_perp_kernels[tblidx].kernels[poly_order]; + mom_gk->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M0M1M2: + mom_gk->momt.kernel = three_moments_kernels[tblidx].kernels[poly_order]; + mom_gk->momt.num_mom = 3; + break; + + case GKYL_F_MOMENT_M0M1M2PARM2PERP: + mom_gk->momt.kernel = four_moments_kernels[tblidx].kernels[poly_order]; + mom_gk->momt.num_mom = vdim + 2; + break; + + case GKYL_F_MOMENT_HAMILTONIAN: + mom_gk->momt.kernel = hamiltonian_moments_kernels[tblidx].kernels[poly_order]; + mom_gk->momt.num_mom = 3; + break; + + default: // can't happen + break; } } -struct gkyl_mom_type* -gkyl_mom_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, double mass, double charge, const struct gkyl_velocity_map* vel_map, - const struct gk_geometry *gk_geom, struct gkyl_array *phi, enum gkyl_distribution_moments mom_type) +struct gkyl_mom_type *gkyl_mom_gyrokinetic_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, double mass, double charge, + const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, + struct gkyl_array *phi, enum gkyl_distribution_moments mom_type +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_gyrokinetic *mom_gk = (struct mom_type_gyrokinetic*) - gkyl_malloc(sizeof(struct mom_type_gyrokinetic)); - - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + struct mom_type_gyrokinetic *mom_gk = + (struct mom_type_gyrokinetic *)gkyl_malloc(sizeof(struct mom_type_gyrokinetic)); + + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_gk->momt.cdim = cdim; @@ -175,116 +176,120 @@ gkyl_mom_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, const struct gk mom_gk->momt.flags = 0; GKYL_SET_CU_ALLOC(mom_gk->momt.flags); mom_gk->momt.ref_count = gkyl_ref_count_init(gkyl_gk_mom_free); - + // Copy struct to device. - struct mom_type_gyrokinetic *mom_gk_cu = (struct mom_type_gyrokinetic*) - gkyl_cu_malloc(sizeof(struct mom_type_gyrokinetic)); + struct mom_type_gyrokinetic *mom_gk_cu = + (struct mom_type_gyrokinetic *)gkyl_cu_malloc(sizeof(struct mom_type_gyrokinetic)); gkyl_cu_memcpy(mom_gk_cu, mom_gk, sizeof(struct mom_type_gyrokinetic), GKYL_CU_MEMCPY_H2D); assert(cv_index[cdim].vdim[vdim] != -1); - set_cu_ptrs<<<1,1>>>(mom_gk_cu, mom_type, cbasis->b_type, - vdim, poly_order, cv_index[cdim].vdim[vdim]); + set_cu_ptrs<<<1, 1> > >( + mom_gk_cu, mom_type, cbasis->b_type, vdim, poly_order, cv_index[cdim].vdim[vdim] + ); mom_gk->momt.on_dev = &mom_gk_cu->momt; // Updater should store host pointers. - mom_gk->gk_geom = geom_ho; - mom_gk->vel_map = vel_map_ho; - mom_gk->phi = phi_ho; - + mom_gk->gk_geom = geom_ho; + mom_gk->vel_map = vel_map_ho; + mom_gk->phi = phi_ho; + return &mom_gk->momt; } -__global__ -static void -set_int_cu_ptrs(struct mom_type_gyrokinetic* momt, enum gkyl_distribution_moments mom_type, - enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx) +__global__ static void set_int_cu_ptrs( + struct mom_type_gyrokinetic *momt, enum gkyl_distribution_moments mom_type, + enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx +) { // Choose kernel tables based on basis-function type. - const gkyl_gyrokinetic_mom_kern_list *int_m0_kernels, *int_m1_kernels, *int_m2_par_kernel, *int_m2_perp_kernel, *int_m2_kernels, - *int_m3_par_kernels, *int_m3_perp_kernels, *int_three_moments_kernels, *int_four_moments_kernels, *int_hamiltonian_moments_kernels; + const gkyl_gyrokinetic_mom_kern_list *int_m0_kernels, *int_m1_kernels, *int_m2_par_kernel, + *int_m2_perp_kernel, *int_m2_kernels, *int_m3_par_kernels, *int_m3_perp_kernels, + *int_three_moments_kernels, *int_four_moments_kernels, *int_hamiltonian_moments_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - int_m0_kernels = ser_int_m0_kernels; - int_m1_kernels = ser_int_m1_kernels; - int_m2_par_kernel = ser_int_m2_par_kernels; - int_m2_perp_kernel = ser_int_m2_perp_kernels; - int_m2_kernels = ser_int_m2_kernels; - int_m3_par_kernels = ser_int_m3_par_kernels; - int_m3_perp_kernels = ser_int_m3_perp_kernels; - int_three_moments_kernels = ser_int_three_moments_kernels; - int_four_moments_kernels = ser_int_four_moments_kernels; - int_hamiltonian_moments_kernels = ser_int_hamiltonian_moments_kernels; - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + int_m0_kernels = ser_int_m0_kernels; + int_m1_kernels = ser_int_m1_kernels; + int_m2_par_kernel = ser_int_m2_par_kernels; + int_m2_perp_kernel = ser_int_m2_perp_kernels; + int_m2_kernels = ser_int_m2_kernels; + int_m3_par_kernels = ser_int_m3_par_kernels; + int_m3_perp_kernels = ser_int_m3_perp_kernels; + int_three_moments_kernels = ser_int_three_moments_kernels; + int_four_moments_kernels = ser_int_four_moments_kernels; + int_hamiltonian_moments_kernels = ser_int_hamiltonian_moments_kernels; + break; + + default: + assert(false); + break; + } + switch (mom_type) { - case GKYL_F_MOMENT_M0: - momt->momt.kernel = int_m0_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = 1; - break; - case GKYL_F_MOMENT_M1: - momt->momt.kernel = int_m1_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = 1; - break; - case GKYL_F_MOMENT_M2PAR: - momt->momt.kernel = int_m2_par_kernel[tblidx].kernels[poly_order]; - momt->momt.num_mom = 1; - break; - case GKYL_F_MOMENT_M2PERP: - momt->momt.kernel = int_m2_perp_kernel[tblidx].kernels[poly_order]; - momt->momt.num_mom = 1; - break; - case GKYL_F_MOMENT_M2: - momt->momt.kernel = int_m2_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = 1; - break; - case GKYL_F_MOMENT_M3PAR: - momt->momt.kernel = int_m3_par_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = 1; - break; - case GKYL_F_MOMENT_M3PERP: - momt->momt.kernel = int_m3_perp_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = 1; - break; - case GKYL_F_MOMENT_M0M1M2: - momt->momt.kernel = int_three_moments_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = 3; - break; - - case GKYL_F_MOMENT_M0M1M2PARM2PERP: - momt->momt.kernel = int_four_moments_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = vdim+2; - break; - - case GKYL_F_MOMENT_HAMILTONIAN: - momt->momt.kernel = int_hamiltonian_moments_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = 3; - break; - - default: // Can't happen. - assert(false); - break; + case GKYL_F_MOMENT_M0: + momt->momt.kernel = int_m0_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = 1; + break; + case GKYL_F_MOMENT_M1: + momt->momt.kernel = int_m1_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = 1; + break; + case GKYL_F_MOMENT_M2PAR: + momt->momt.kernel = int_m2_par_kernel[tblidx].kernels[poly_order]; + momt->momt.num_mom = 1; + break; + case GKYL_F_MOMENT_M2PERP: + momt->momt.kernel = int_m2_perp_kernel[tblidx].kernels[poly_order]; + momt->momt.num_mom = 1; + break; + case GKYL_F_MOMENT_M2: + momt->momt.kernel = int_m2_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = 1; + break; + case GKYL_F_MOMENT_M3PAR: + momt->momt.kernel = int_m3_par_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = 1; + break; + case GKYL_F_MOMENT_M3PERP: + momt->momt.kernel = int_m3_perp_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = 1; + break; + case GKYL_F_MOMENT_M0M1M2: + momt->momt.kernel = int_three_moments_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = 3; + break; + + case GKYL_F_MOMENT_M0M1M2PARM2PERP: + momt->momt.kernel = int_four_moments_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = vdim + 2; + break; + + case GKYL_F_MOMENT_HAMILTONIAN: + momt->momt.kernel = int_hamiltonian_moments_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = 3; + break; + + default: // Can't happen. + assert(false); + break; } } -struct gkyl_mom_type* -gkyl_int_mom_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, double mass, double charge, const struct gkyl_velocity_map* vel_map, - const struct gk_geometry *gk_geom, struct gkyl_array *phi, enum gkyl_distribution_moments mom_type) +struct gkyl_mom_type *gkyl_int_mom_gyrokinetic_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, double mass, double charge, + const struct gkyl_velocity_map *vel_map, const struct gk_geometry *gk_geom, + struct gkyl_array *phi, enum gkyl_distribution_moments mom_type +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_gyrokinetic *momt = (struct mom_type_gyrokinetic*) - gkyl_malloc(sizeof(struct mom_type_gyrokinetic)); - - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + struct mom_type_gyrokinetic *momt = + (struct mom_type_gyrokinetic *)gkyl_malloc(sizeof(struct mom_type_gyrokinetic)); + + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; momt->momt.cdim = cdim; @@ -315,21 +320,22 @@ gkyl_int_mom_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, const struc momt->momt.flags = 0; GKYL_SET_CU_ALLOC(momt->momt.flags); momt->momt.ref_count = gkyl_ref_count_init(gkyl_gk_mom_free); - + // Copy struct to device. - struct mom_type_gyrokinetic *momt_cu = (struct mom_type_gyrokinetic*) - gkyl_cu_malloc(sizeof(struct mom_type_gyrokinetic)); + struct mom_type_gyrokinetic *momt_cu = + (struct mom_type_gyrokinetic *)gkyl_cu_malloc(sizeof(struct mom_type_gyrokinetic)); gkyl_cu_memcpy(momt_cu, momt, sizeof(struct mom_type_gyrokinetic), GKYL_CU_MEMCPY_H2D); - set_int_cu_ptrs<<<1,1>>>(momt_cu, mom_type, cbasis->b_type, - vdim, poly_order, cv_index[cdim].vdim[vdim]); + set_int_cu_ptrs<<<1, 1> > >( + momt_cu, mom_type, cbasis->b_type, vdim, poly_order, cv_index[cdim].vdim[vdim] + ); momt->momt.on_dev = &momt_cu->momt; // Updater should store host pointers. - momt->gk_geom = geom_ho; - momt->vel_map = vel_map_ho; - momt->phi = phi_ho; - + momt->gk_geom = geom_ho; + momt->vel_map = vel_map_ho; + momt->phi = phi_ho; + return &momt->momt; } diff --git a/gyrokinetic/zero/position_map.c b/gyrokinetic/zero/position_map.c index 47b0e95230..c9ccb6594c 100644 --- a/gyrokinetic/zero/position_map.c +++ b/gyrokinetic/zero/position_map.c @@ -13,21 +13,17 @@ // Remove with the print statements at the bottom #include -void -gkyl_position_map_identity(double t, const double *xn, double *fout, void *ctx) +void gkyl_position_map_identity(double t, const double *xn, double *fout, void *ctx) { fout[0] = xn[0]; } -void -gkyl_position_map_identity_slope(double t, const double *xn, double *fout, void *ctx) +void gkyl_position_map_identity_slope(double t, const double *xn, double *fout, void *ctx) { fout[0] = 1.0; } - -struct gkyl_position_map* -gkyl_position_map_null_new() +struct gkyl_position_map *gkyl_position_map_null_new() { struct gkyl_position_map *gpm = gkyl_malloc(sizeof(*gpm)); gpm->id = GKYL_PMAP_USER_INPUT; @@ -40,8 +36,8 @@ gkyl_position_map_null_new() gpm->bmag_ctx = gkyl_malloc(sizeof(struct gkyl_bmag_ctx)); gpm->bmag_ctx->bmag = gkyl_array_new(GKYL_DOUBLE, 1, 1); gpm->ref_count = gkyl_ref_count_init(gkyl_position_map_free); - - for (int i = 0; i < 3; i++){ + + for (int i = 0; i < 3; i++) { gpm->maps[i] = gkyl_position_map_identity; gpm->map_derivs[i] = gkyl_position_map_identity_slope; gpm->ctxs[i] = 0; @@ -53,17 +49,18 @@ gkyl_position_map_null_new() return gpm; } -struct gkyl_position_map* -gkyl_position_map_inew(struct gkyl_position_map_inew_inp inp) +struct gkyl_position_map *gkyl_position_map_inew(struct gkyl_position_map_inew_inp inp) { - return gkyl_position_map_new(inp.pmap_info, inp.grid, inp.local, inp.local_ext, - inp.global, inp.global_ext, inp.basis); + return gkyl_position_map_new( + inp.pmap_info, inp.grid, inp.local, inp.local_ext, inp.global, inp.global_ext, inp.basis + ); } -struct gkyl_position_map* -gkyl_position_map_new(struct gkyl_position_map_inp pmap_info, struct gkyl_rect_grid grid, - struct gkyl_range local, struct gkyl_range local_ext, struct gkyl_range global, struct gkyl_range global_ext, - struct gkyl_basis basis) +struct gkyl_position_map *gkyl_position_map_new( + struct gkyl_position_map_inp pmap_info, struct gkyl_rect_grid grid, struct gkyl_range local, + struct gkyl_range local_ext, struct gkyl_range global, struct gkyl_range global_ext, + struct gkyl_basis basis +) { struct gkyl_position_map *gpm = gkyl_malloc(sizeof(*gpm)); gpm->id = pmap_info.id; @@ -71,13 +68,15 @@ gkyl_position_map_new(struct gkyl_position_map_inp pmap_info, struct gkyl_rect_g gpm->bmag_ctx = gkyl_malloc(sizeof(struct gkyl_bmag_ctx)); gpm->bmag_ctx->bmag = gkyl_array_new(GKYL_DOUBLE, basis.num_basis, global_ext.volume); gpm->to_optimize = false; - gpm->use_map_derivs = (pmap_info.id == GKYL_PMAP_XPT_COMPRESSION || pmap_info.id == GKYL_PMAP_USER_INPUT_W_DERIVATIVE) ? true : false; - + gpm->use_map_derivs = (pmap_info.id == GKYL_PMAP_XPT_COMPRESSION || + pmap_info.id == GKYL_PMAP_USER_INPUT_W_DERIVATIVE) ? + true : + false; gpm->constB_ctx = gkyl_malloc(sizeof(struct gkyl_position_map_const_B_ctx)); gpm->xpt_ctx = gkyl_malloc(sizeof(struct gkyl_position_map_xpt_ctx)); - for (int i = 0; i < 3; i++){ + for (int i = 0; i < 3; i++) { gpm->maps[i] = gkyl_position_map_identity; gpm->map_derivs[i] = gkyl_position_map_identity_slope; gpm->ctxs[i] = 0; @@ -87,70 +86,71 @@ gkyl_position_map_new(struct gkyl_position_map_inp pmap_info, struct gkyl_rect_g gpm->xpt_ctx->ctxs_backup[i] = 0; } - switch (pmap_info.id) - { - case GKYL_PMAP_USER_INPUT: - for (int i = 0; i < 3; i++){ - if (pmap_info.maps[i] != 0) - { gpm->maps[i] = pmap_info.maps[i]; - gpm->ctxs[i] = pmap_info.ctxs[i]; - } + switch (pmap_info.id) { + case GKYL_PMAP_USER_INPUT: + for (int i = 0; i < 3; i++) { + if (pmap_info.maps[i] != 0) { + gpm->maps[i] = pmap_info.maps[i]; + gpm->ctxs[i] = pmap_info.ctxs[i]; } - - case GKYL_PMAP_USER_INPUT_W_DERIVATIVE: - for (int i = 0; i < 3; i++){ - if (pmap_info.maps[i] != 0) - { gpm->maps[i] = pmap_info.maps[i]; - gpm->map_derivs[i] = pmap_info.map_derivs[i]; - gpm->ctxs[i] = pmap_info.ctxs[i]; - } + } + + case GKYL_PMAP_USER_INPUT_W_DERIVATIVE: + for (int i = 0; i < 3; i++) { + if (pmap_info.maps[i] != 0) { + gpm->maps[i] = pmap_info.maps[i]; + gpm->map_derivs[i] = pmap_info.map_derivs[i]; + gpm->ctxs[i] = pmap_info.ctxs[i]; } + } - case GKYL_PMAP_CONSTANT_DB_POLYNOMIAL: + case GKYL_PMAP_CONSTANT_DB_POLYNOMIAL: - for (int i = 0; i < 2; i++){ - if (pmap_info.maps[i] != 0) - { gpm->constB_ctx->maps_backup[i] = pmap_info.maps[i]; - gpm->constB_ctx->ctxs_backup[i] = pmap_info.ctxs[i]; - } + for (int i = 0; i < 2; i++) { + if (pmap_info.maps[i] != 0) { + gpm->constB_ctx->maps_backup[i] = pmap_info.maps[i]; + gpm->constB_ctx->ctxs_backup[i] = pmap_info.ctxs[i]; } - gpm->constB_ctx->map_strength = pmap_info.map_strength; + } + gpm->constB_ctx->map_strength = pmap_info.map_strength; - case GKYL_PMAP_CONSTANT_DB_NUMERIC: + case GKYL_PMAP_CONSTANT_DB_NUMERIC: - for (int i = 0; i < 2; i++){ - if (pmap_info.maps[i] != 0) - { gpm->constB_ctx->maps_backup[i] = pmap_info.maps[i]; - gpm->constB_ctx->ctxs_backup[i] = pmap_info.ctxs[i]; - } + for (int i = 0; i < 2; i++) { + if (pmap_info.maps[i] != 0) { + gpm->constB_ctx->maps_backup[i] = pmap_info.maps[i]; + gpm->constB_ctx->ctxs_backup[i] = pmap_info.ctxs[i]; } - gpm->constB_ctx->map_strength = pmap_info.map_strength; - - if (pmap_info.maximum_slope_at_min_B == 0.) - { gpm->constB_ctx->enable_maximum_slope_limits_at_min_B = false; } - else - { gpm->constB_ctx->enable_maximum_slope_limits_at_min_B = true; } - gpm->constB_ctx->maximum_slope_at_min_B = pmap_info.maximum_slope_at_min_B; - - if (pmap_info.maximum_slope_at_max_B == 0.) - { gpm->constB_ctx->enable_maximum_slope_limits_at_max_B = false; } - else - { gpm->constB_ctx->enable_maximum_slope_limits_at_max_B = true; } - gpm->constB_ctx->maximum_slope_at_max_B = pmap_info.maximum_slope_at_max_B; - gpm->constB_ctx->gaussian_std = pmap_info.gaussian_std; - gpm->constB_ctx->gaussian_max_integration_width = pmap_info.gaussian_max_integration_width; - - case GKYL_PMAP_XPT_COMPRESSION: - - for (int i = 0; i < 2; i++){ - if (pmap_info.maps[i] != 0) - { gpm->xpt_ctx->maps_backup[i] = pmap_info.maps[i]; - gpm->xpt_ctx->ctxs_backup[i] = pmap_info.ctxs[i]; - } + } + gpm->constB_ctx->map_strength = pmap_info.map_strength; + + if (pmap_info.maximum_slope_at_min_B == 0.) { + gpm->constB_ctx->enable_maximum_slope_limits_at_min_B = false; + } else { + gpm->constB_ctx->enable_maximum_slope_limits_at_min_B = true; + } + gpm->constB_ctx->maximum_slope_at_min_B = pmap_info.maximum_slope_at_min_B; + + if (pmap_info.maximum_slope_at_max_B == 0.) { + gpm->constB_ctx->enable_maximum_slope_limits_at_max_B = false; + } else { + gpm->constB_ctx->enable_maximum_slope_limits_at_max_B = true; + } + gpm->constB_ctx->maximum_slope_at_max_B = pmap_info.maximum_slope_at_max_B; + gpm->constB_ctx->gaussian_std = pmap_info.gaussian_std; + gpm->constB_ctx->gaussian_max_integration_width = pmap_info.gaussian_max_integration_width; + + case GKYL_PMAP_XPT_COMPRESSION: + + for (int i = 0; i < 2; i++) { + if (pmap_info.maps[i] != 0) { + gpm->xpt_ctx->maps_backup[i] = pmap_info.maps[i]; + gpm->xpt_ctx->ctxs_backup[i] = pmap_info.ctxs[i]; } - gpm->xpt_ctx->compression_factor = pmap_info.compression_factor; - gpm->xpt_ctx->radial_compression_factor = pmap_info.radial_compression_factor; - gpm->xpt_ctx->compress_divertor = pmap_info.compress_divertor; + } + gpm->xpt_ctx->compression_factor = pmap_info.compression_factor; + gpm->xpt_ctx->radial_compression_factor = pmap_info.radial_compression_factor; + gpm->xpt_ctx->compress_divertor = pmap_info.compress_divertor; } gpm->grid = grid; @@ -159,23 +159,22 @@ gkyl_position_map_new(struct gkyl_position_map_inp pmap_info, struct gkyl_rect_g gpm->global = global; gpm->global_ext = global_ext; gpm->basis = basis; - gpm->cdim = grid.ndim; - gpm->mc2nu = gkyl_array_new(GKYL_DOUBLE, 3*gpm->basis.num_basis, gpm->local_ext.volume); + gpm->cdim = grid.ndim; + gpm->mc2nu = gkyl_array_new(GKYL_DOUBLE, 3 * gpm->basis.num_basis, gpm->local_ext.volume); gpm->ref_count = gkyl_ref_count_init(gkyl_position_map_free); struct gkyl_position_map *gpm_out = gpm; return gpm_out; } -void -gkyl_position_map_set_mc2nu(struct gkyl_position_map* gpm, struct gkyl_array* mc2nu) +void gkyl_position_map_set_mc2nu(struct gkyl_position_map *gpm, struct gkyl_array *mc2nu) { gkyl_array_copy(gpm->mc2nu, mc2nu); } -void -gkyl_position_map_set_bmag(struct gkyl_position_map* gpm, struct gkyl_comm* comm, - struct gkyl_array* bmag) +void gkyl_position_map_set_bmag( + struct gkyl_position_map *gpm, struct gkyl_comm *comm, struct gkyl_array *bmag +) { gpm->to_optimize = true; int N_boundaries = gpm->constB_ctx->N_theta_boundaries; @@ -186,27 +185,27 @@ gkyl_position_map_set_bmag(struct gkyl_position_map* gpm, struct gkyl_comm* comm gkyl_array_release(gpm->bmag_ctx->bmag); gpm->bmag_ctx->bmag = gkyl_array_acquire(bmag); return; - } - else { - gkyl_comm_array_allgather_host(comm, &gpm->local, \ - &gpm->global, bmag, (struct gkyl_array*) gpm->bmag_ctx->bmag); + } else { + gkyl_comm_array_allgather_host( + comm, &gpm->local, &gpm->global, bmag, (struct gkyl_array *)gpm->bmag_ctx->bmag + ); } } -void -gkyl_position_map_set_compression(struct gkyl_position_map* gpm, double zcut, double zcenter, double w, double psisep) +void gkyl_position_map_set_compression( + struct gkyl_position_map *gpm, double zcut, double zcenter, double w, double psisep +) { gpm->xpt_ctx->zcut = zcut; gpm->xpt_ctx->zcenter = zcenter; gpm->xpt_ctx->w = w; gpm->xpt_ctx->psisep = psisep; - if (gpm->xpt_ctx->radial_compression_factor!=0.0) { + if (gpm->xpt_ctx->radial_compression_factor != 0.0) { gpm->maps[0] = position_map_sep_compression; gpm->map_derivs[0] = position_map_deriv_sep_compression; gpm->ctxs[0] = gpm->xpt_ctx; - } - else { + } else { gpm->maps[0] = gpm->xpt_ctx->maps_backup[0]; gpm->ctxs[0] = gpm->xpt_ctx->ctxs_backup[0]; } @@ -214,23 +213,24 @@ gkyl_position_map_set_compression(struct gkyl_position_map* gpm, double zcut, do gpm->maps[1] = gpm->xpt_ctx->maps_backup[1]; gpm->ctxs[1] = gpm->xpt_ctx->ctxs_backup[1]; - if (gpm->xpt_ctx->compression_factor!=0.0) { + if (gpm->xpt_ctx->compression_factor != 0.0) { gpm->maps[2] = position_map_xpt_compression; gpm->map_derivs[2] = position_map_deriv_xpt_compression; gpm->ctxs[2] = gpm->xpt_ctx; - } - else { + } else { gpm->maps[2] = gpm->xpt_ctx->maps_backup[2]; gpm->ctxs[2] = gpm->xpt_ctx->ctxs_backup[2]; } } -void -gkyl_position_map_eval_mc2nu(const struct gkyl_position_map* gpm, const double *x_comp, double *x_fa) +void gkyl_position_map_eval_mc2nu( + const struct gkyl_position_map *gpm, const double *x_comp, double *x_fa +) { int cidx[GKYL_MAX_CDIM]; - for(int i = 0; i < gpm->grid.ndim; i++){ - int idxtemp = gpm->global.lower[i] + (int) floor((x_comp[i] - (gpm->grid.lower[i]) )/gpm->grid.dx[i]); + for (int i = 0; i < gpm->grid.ndim; i++) { + int idxtemp = + gpm->global.lower[i] + (int)floor((x_comp[i] - (gpm->grid.lower[i])) / gpm->grid.dx[i]); idxtemp = GKYL_MAX2(GKYL_MIN2(idxtemp, gpm->local.upper[i]), gpm->local.lower[i]); cidx[i] = idxtemp; } @@ -239,34 +239,33 @@ gkyl_position_map_eval_mc2nu(const struct gkyl_position_map* gpm, const double * double cxc[gpm->grid.ndim]; double x_log[gpm->grid.ndim]; gkyl_rect_grid_cell_center(&gpm->grid, cidx, cxc); - for(int i = 0; i < gpm->grid.ndim; i++){ - x_log[i] = (x_comp[i]-cxc[i])/(gpm->grid.dx[i]*0.5); + for (int i = 0; i < gpm->grid.ndim; i++) { + x_log[i] = (x_comp[i] - cxc[i]) / (gpm->grid.dx[i] * 0.5); } double xyz_fa[3]; - for(int i = 0; i < 3; i++){ - xyz_fa[i] = gpm->basis.eval_expand(x_log, &pmap_coeffs[i*gpm->basis.num_basis]); + for (int i = 0; i < 3; i++) { + xyz_fa[i] = gpm->basis.eval_expand(x_log, &pmap_coeffs[i * gpm->basis.num_basis]); } - for (int i=0; igrid.ndim; i++) { + for (int i = 0; i < gpm->grid.ndim; i++) { x_fa[i] = xyz_fa[i]; } - x_fa[gpm->grid.ndim-1] = xyz_fa[2]; + x_fa[gpm->grid.ndim - 1] = xyz_fa[2]; } -void -gkyl_position_map_optimize(struct gkyl_position_map* gpm, struct gkyl_rect_grid grid, - struct gkyl_range global) +void gkyl_position_map_optimize( + struct gkyl_position_map *gpm, struct gkyl_rect_grid grid, struct gkyl_range global +) { enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates - gpm->constB_ctx->psi_max = grid.upper[PSI_IDX]; - gpm->constB_ctx->psi_min = grid.lower[PSI_IDX]; + gpm->constB_ctx->psi_max = grid.upper[PSI_IDX]; + gpm->constB_ctx->psi_min = grid.lower[PSI_IDX]; gpm->constB_ctx->alpha_max = grid.upper[AL_IDX]; gpm->constB_ctx->alpha_min = grid.lower[AL_IDX]; gpm->constB_ctx->theta_max = grid.upper[TH_IDX]; gpm->constB_ctx->theta_min = grid.lower[TH_IDX]; gpm->constB_ctx->N_theta_boundaries = global.upper[TH_IDX] - global.lower[TH_IDX] + 2; - if (gpm->id == GKYL_PMAP_CONSTANT_DB_POLYNOMIAL && gpm->to_optimize == true) - { + if (gpm->id == GKYL_PMAP_CONSTANT_DB_POLYNOMIAL && gpm->to_optimize == true) { double psi_center = 0.5 * (gpm->constB_ctx->psi_min + gpm->constB_ctx->psi_max); double alpha_center = 0.5 * (gpm->constB_ctx->alpha_min + gpm->constB_ctx->alpha_max); @@ -281,15 +280,14 @@ gkyl_position_map_optimize(struct gkyl_position_map* gpm, struct gkyl_rect_grid gpm->bmag_ctx->cbasis = &gpm->basis; gpm->bmag_ctx->cgrid = &gpm->grid; - gpm->constB_ctx->psi = psi_center; - gpm->constB_ctx->alpha = alpha_center; + gpm->constB_ctx->psi = psi_center; + gpm->constB_ctx->alpha = alpha_center; calculate_mirror_throat_location_polynomial(gpm->constB_ctx, gpm->bmag_ctx); calculate_optimal_mapping_polynomial(gpm->constB_ctx, gpm->bmag_ctx); - } - else if (gpm->id == GKYL_PMAP_CONSTANT_DB_NUMERIC && gpm->to_optimize == true) - { - double psi_center = pow(0.5 * (sqrt(gpm->constB_ctx->psi_min) + sqrt(gpm->constB_ctx->psi_max)), 2.0); + } else if (gpm->id == GKYL_PMAP_CONSTANT_DB_NUMERIC && gpm->to_optimize == true) { + double psi_center = + pow(0.5 * (sqrt(gpm->constB_ctx->psi_min) + sqrt(gpm->constB_ctx->psi_max)), 2.0); double alpha_center = 0.5 * (gpm->constB_ctx->alpha_min + gpm->constB_ctx->alpha_max); gpm->maps[0] = gpm->constB_ctx->maps_backup[0]; @@ -300,23 +298,23 @@ gkyl_position_map_optimize(struct gkyl_position_map* gpm, struct gkyl_rect_grid gpm->ctxs[2] = gpm; gpm->bmag_ctx->crange_global = &gpm->global; - gpm->bmag_ctx->cbasis = &gpm->basis; - gpm->bmag_ctx->cgrid = &gpm->grid; + gpm->bmag_ctx->cbasis = &gpm->basis; + gpm->bmag_ctx->cgrid = &gpm->grid; - gpm->constB_ctx->psi = psi_center; - gpm->constB_ctx->alpha = alpha_center; + gpm->constB_ctx->psi = psi_center; + gpm->constB_ctx->alpha = alpha_center; find_B_field_extrema(gpm); refine_B_field_extrema(gpm); } } -double -gkyl_position_map_slope(const struct gkyl_position_map* gpm, int ix_map, - double x, double dx, int ix_comp, const struct gkyl_range *nrange) +double gkyl_position_map_slope( + const struct gkyl_position_map *gpm, int ix_map, double x, double dx, int ix_comp, + const struct gkyl_range *nrange +) { - if (gpm->use_map_derivs) - { + if (gpm->use_map_derivs) { double slope; gpm->map_derivs[ix_map](0.0, &x, &slope, gpm->ctxs[ix_map]); return slope; @@ -328,44 +326,35 @@ gkyl_position_map_slope(const struct gkyl_position_map* gpm, int ix_map, gpm->maps[ix_map](0.0, &x_left, &f_left, gpm->ctxs[ix_map]); gpm->maps[ix_map](0.0, &x_right, &f_right, gpm->ctxs[ix_map]); double slope; - if (ix_comp == nrange->lower[ix_map]) - { + if (ix_comp == nrange->lower[ix_map]) { gpm->maps[ix_map](0.0, &x, &f, gpm->ctxs[ix_map]); slope = (f_right - f) / dx; - } - else if (ix_comp == nrange->upper[ix_map]) - { + } else if (ix_comp == nrange->upper[ix_map]) { gpm->maps[ix_map](0.0, &x, &f, gpm->ctxs[ix_map]); slope = (f - f_left) / dx; - } - else - { + } else { slope = (f_right - f_left) / (2.0 * dx); } return slope; } -struct gkyl_position_map* -gkyl_position_map_acquire(const struct gkyl_position_map* gpm) +struct gkyl_position_map *gkyl_position_map_acquire(const struct gkyl_position_map *gpm) { gkyl_ref_count_inc(&gpm->ref_count); - return (struct gkyl_position_map*) gpm; + return (struct gkyl_position_map *)gpm; } -void -gkyl_position_map_release(const struct gkyl_position_map *gpm) +void gkyl_position_map_release(const struct gkyl_position_map *gpm) { gkyl_ref_count_dec(&gpm->ref_count); } -void -gkyl_position_map_free(const struct gkyl_ref_count *ref) +void gkyl_position_map_free(const struct gkyl_ref_count *ref) { struct gkyl_position_map *gpm = container_of(ref, struct gkyl_position_map, ref_count); gkyl_array_release(gpm->mc2nu); gkyl_array_release(gpm->bmag_ctx->bmag); - if (gpm->to_optimize == true) - { + if (gpm->to_optimize == true) { gkyl_free(gpm->constB_ctx->theta_extrema); gkyl_free(gpm->constB_ctx->bmag_extrema); gkyl_free(gpm->constB_ctx->min_or_max); diff --git a/gyrokinetic/zero/positivity_shift_gyrokinetic.c b/gyrokinetic/zero/positivity_shift_gyrokinetic.c index 9f6559adfc..d1d66316fe 100644 --- a/gyrokinetic/zero/positivity_shift_gyrokinetic.c +++ b/gyrokinetic/zero/positivity_shift_gyrokinetic.c @@ -4,17 +4,17 @@ #include #include -struct gkyl_positivity_shift_gyrokinetic* -gkyl_positivity_shift_gyrokinetic_new(struct gkyl_basis cbasis, struct gkyl_basis pbasis, - struct gkyl_rect_grid grid, double mass, - const struct gk_geometry *gk_geom, - const struct gkyl_velocity_map *vel_map, const struct gkyl_range *conf_rng_ext, bool use_gpu) +struct gkyl_positivity_shift_gyrokinetic *gkyl_positivity_shift_gyrokinetic_new( + struct gkyl_basis cbasis, struct gkyl_basis pbasis, struct gkyl_rect_grid grid, double mass, + const struct gk_geometry *gk_geom, const struct gkyl_velocity_map *vel_map, + const struct gkyl_range *conf_rng_ext, bool use_gpu +) { // Allocate space for new updater. struct gkyl_positivity_shift_gyrokinetic *up = gkyl_malloc(sizeof(*up)); assert(pbasis.poly_order == 1); // Because of the way a rescale/division is - // done in advance. + // done in advance. up->ffloor_fac = 0.0; // ffloor will be set to max(f)*ffloor_fac. up->grid = grid; @@ -24,20 +24,20 @@ gkyl_positivity_shift_gyrokinetic_new(struct gkyl_basis cbasis, struct gkyl_basi up->gk_geom = gkyl_gk_geometry_acquire(gk_geom); up->vel_map = gkyl_velocity_map_acquire(vel_map); up->use_gpu = use_gpu; - up->cellav_fac = 1./pow(sqrt(2.),pbasis.ndim); + up->cellav_fac = 1. / pow(sqrt(2.), pbasis.ndim); if (!use_gpu) { up->kernels = gkyl_malloc(sizeof(struct gkyl_positivity_shift_gyrokinetic_kernels)); up->ffloor = gkyl_malloc(sizeof(double[1])); - up->ffloor[0] = 0.0; // Gets updated after 1st call to _advance. + up->ffloor[0] = 0.0; // Gets updated after 1st call to _advance. } #ifdef GKYL_HAVE_CUDA if (use_gpu) { up->kernels = gkyl_cu_malloc(sizeof(struct gkyl_positivity_shift_gyrokinetic_kernels)); up->ffloor = gkyl_cu_malloc(sizeof(double[1])); - double ffloor_zero[] = {0.}; // Gets updated after 1st call to _advance. + double ffloor_zero[] = {0.}; // Gets updated after 1st call to _advance. gkyl_cu_memcpy(up->ffloor, ffloor_zero, sizeof(double[1]), GKYL_CU_MEMCPY_H2D); up->shiftedf = gkyl_array_cu_dev_new(GKYL_INT, 1, conf_rng_ext->volume); @@ -45,23 +45,22 @@ gkyl_positivity_shift_gyrokinetic_new(struct gkyl_basis cbasis, struct gkyl_basi #endif // Choose kernels that shift f and compute int moms of Deltaf. - + enum gkyl_positivity_shift_type shift_type = GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY; pos_shift_gk_choose_shift_kernel(up->kernels, cbasis, pbasis, shift_type, use_gpu); return up; } -void -gkyl_positivity_shift_gyrokinetic_advance(gkyl_positivity_shift_gyrokinetic* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - struct gkyl_array *GKYL_RESTRICT distf, struct gkyl_array *GKYL_RESTRICT m0, - struct gkyl_array *GKYL_RESTRICT delta_m0) +void gkyl_positivity_shift_gyrokinetic_advance( + gkyl_positivity_shift_gyrokinetic *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, struct gkyl_array *GKYL_RESTRICT distf, + struct gkyl_array *GKYL_RESTRICT m0, struct gkyl_array *GKYL_RESTRICT delta_m0 +) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - gkyl_positivity_shift_gyrokinetic_advance_cu(up, conf_rng, phase_rng, - distf, m0, delta_m0); + gkyl_positivity_shift_gyrokinetic_advance_cu(up, conf_rng, phase_rng, distf, m0, delta_m0); return; } #endif @@ -74,7 +73,9 @@ gkyl_positivity_shift_gyrokinetic_advance(gkyl_positivity_shift_gyrokinetic* up, struct gkyl_range_iter conf_iter, vel_iter; int rem_dir[GKYL_MAX_DIM] = {0}; - for (int d=0; dndim; ++d) rem_dir[d] = 1; + for (int d = 0; d < conf_rng->ndim; ++d) { + rem_dir[d] = 1; + } gkyl_range_iter_init(&conf_iter, conf_rng); while (gkyl_range_iter_next(&conf_iter)) { @@ -87,7 +88,7 @@ gkyl_positivity_shift_gyrokinetic_advance(gkyl_positivity_shift_gyrokinetic* up, double *m0_c = gkyl_array_fetch(m0, clinidx); double *delta_m0_c = gkyl_array_fetch(delta_m0, clinidx); double m0in_c[num_cbasis]; - for (int k=0; kkernels->m0(up->grid.dx, vmap_c, up->mass, bmag_c, distf_c, m0phase_in_c); // Add to the old number density. - for (int k=0; kkernels->conf_phase_mul_op(jacobtot_inv_c, distf_c, distf_c); - for (int k=0; kncomp; k++) + for (int k = 0; k < distf->ncomp; k++) { distf_c[k] /= jacobvel_c[0]; + } // Shift f to enforce positivity if needed. shifted_node = up->kernels->shift(up->ffloor[0], distf_c); // Multiply by jacobtot and jacobvel to compute M0. up->kernels->conf_phase_mul_op(jacobtot_c, distf_c, distf_c); - for (int k=0; kncomp; k++) + for (int k = 0; k < distf->ncomp; k++) { distf_c[k] *= jacobvel_c[0]; + } if (shifted_node) { // Compute the new number density in this phase-space cell. double m0phase_out_c[num_cbasis]; - for (int k=0; kkernels->m0(up->grid.dx, vmap_c, up->mass, bmag_c, distf_c, m0phase_out_c); if (m0phase_in_c[0] > 0.0 && m0phase_out_c[0] > 0.0) { // Rescale f in this cell so it keeps the same cell-averaged density. - double m0ratio = m0phase_in_c[0]/m0phase_out_c[0]; + double m0ratio = m0phase_in_c[0] / m0phase_out_c[0]; - for (unsigned int k=0; kncomp; ++k) + for (unsigned int k = 0; k < distf->ncomp; ++k) { distf_c[k] *= m0ratio; + } // Add contribution from this phase-space cell to the new number density. - for (unsigned int k = 0; k < m0->ncomp; ++k) - m0_c[k] += m0ratio*m0phase_out_c[k]; - } - else { + for (unsigned int k = 0; k < m0->ncomp; ++k) { + m0_c[k] += m0ratio * m0phase_out_c[k]; + } + } else { // Add contribution from this phase-space cell to the new number density. - for (int k=0; kkernels->conf_phase_mul_op(m0ratio_c, distf_c, distf_c); } - for (int k=0; kffloor[0] = up->ffloor_fac * distf_max * up->cellav_fac; } -void -gkyl_positivity_shift_gyrokinetic_quasineutrality_scale(gkyl_positivity_shift_gyrokinetic* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - const struct gkyl_array *GKYL_RESTRICT delta_m0s, const struct gkyl_array *GKYL_RESTRICT delta_m0s_tot, +void gkyl_positivity_shift_gyrokinetic_quasineutrality_scale( + gkyl_positivity_shift_gyrokinetic *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, const struct gkyl_array *GKYL_RESTRICT delta_m0s, + const struct gkyl_array *GKYL_RESTRICT delta_m0s_tot, const struct gkyl_array *GKYL_RESTRICT delta_m0r_tot, const struct gkyl_array *GKYL_RESTRICT m0s, - struct gkyl_array *GKYL_RESTRICT fs) + struct gkyl_array *GKYL_RESTRICT fs +) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - gkyl_positivity_shift_gyrokinetic_quasineutrality_scale_cu(up, conf_rng, phase_rng, - delta_m0s, delta_m0s_tot, delta_m0r_tot, m0s, fs); + gkyl_positivity_shift_gyrokinetic_quasineutrality_scale_cu( + up, conf_rng, phase_rng, delta_m0s, delta_m0s_tot, delta_m0r_tot, m0s, fs + ); return; } #endif @@ -211,7 +222,9 @@ gkyl_positivity_shift_gyrokinetic_quasineutrality_scale(gkyl_positivity_shift_gy struct gkyl_range_iter conf_iter, vel_iter; int rem_dir[GKYL_MAX_DIM] = {0}; - for (int d=0; dndim; ++d) rem_dir[d] = 1; + for (int d = 0; d < conf_rng->ndim; ++d) { + rem_dir[d] = 1; + } int num_cbasis = up->num_cbasis; @@ -225,9 +238,7 @@ gkyl_positivity_shift_gyrokinetic_quasineutrality_scale(gkyl_positivity_shift_gy // First condition in this if-statement is equivalent to // max((delta_m0r_tot_c[0]-delta_m0s_tot_c[0])/abs(delta_m0r_tot_c[0]-delta_m0s_tot_c[0])) // and the second condition is to avoid division by 0. - if (delta_m0r_tot_c[0] > delta_m0s_tot_c[0] && - delta_m0s_tot_c[0] > 0.0) { - + if (delta_m0r_tot_c[0] > delta_m0s_tot_c[0] && delta_m0s_tot_c[0] > 0.0) { const double *delta_m0s_c = gkyl_array_cfetch(delta_m0s, clinidx); const double *m0s_c = gkyl_array_cfetch(m0s, clinidx); @@ -236,8 +247,9 @@ gkyl_positivity_shift_gyrokinetic_quasineutrality_scale(gkyl_positivity_shift_gy // - Delta n_s,tot = sum of Delta n for species with same charge sign. // - Delta n_r,tot = sum of Delta n for species with opposite charge sign. double delta_m0fac_c[num_cbasis]; - for (int k=0; kkernels->conf_mul_op(delta_m0fac_c, delta_m0s_c, delta_m0fac_c); @@ -246,8 +258,9 @@ gkyl_positivity_shift_gyrokinetic_quasineutrality_scale(gkyl_positivity_shift_gy up->kernels->conf_mul_op(delta_m0fac_c, delta_m0s_tot_inv_c, delta_m0fac_c); - for (int k=0; kkernels->conf_inv_op(m0s_c, m0s_inv_c); @@ -265,12 +278,10 @@ gkyl_positivity_shift_gyrokinetic_quasineutrality_scale(gkyl_positivity_shift_gy up->kernels->conf_phase_mul_op(delta_m0fac_c, fs_c, fs_c); } } - } } -void -gkyl_positivity_shift_gyrokinetic_release(gkyl_positivity_shift_gyrokinetic* up) +void gkyl_positivity_shift_gyrokinetic_release(gkyl_positivity_shift_gyrokinetic *up) { // Release memory associated with this updater. gkyl_gk_geometry_release(up->gk_geom); diff --git a/gyrokinetic/zero/positivity_shift_gyrokinetic_cu.cu b/gyrokinetic/zero/positivity_shift_gyrokinetic_cu.cu index c5e488cce6..ece2c48084 100644 --- a/gyrokinetic/zero/positivity_shift_gyrokinetic_cu.cu +++ b/gyrokinetic/zero/positivity_shift_gyrokinetic_cu.cu @@ -8,80 +8,87 @@ extern "C" { } // CUDA kernel to set device pointers to kernels. -__global__ static void -gkyl_pos_shift_gk_set_cu_ker_ptrs(struct gkyl_positivity_shift_gyrokinetic_kernels *kernels, - struct gkyl_basis cbasis, struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype) +__global__ static void gkyl_pos_shift_gk_set_cu_ker_ptrs( + struct gkyl_positivity_shift_gyrokinetic_kernels *kernels, struct gkyl_basis cbasis, + struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype +) { int cdim = cbasis.ndim, pdim = pbasis.ndim; enum gkyl_basis_type cbasis_type = cbasis.b_type, pbasis_type = pbasis.b_type; int poly_order = pbasis.poly_order; switch (pbasis_type) { - case GKYL_BASIS_MODAL_GKHYBRID: - case GKYL_BASIS_MODAL_SERENDIPITY: - kernels->is_m0_positive = pos_shift_gk_kern_list_m0_pos_check_ser[cdim-1].kernels[poly_order-1]; - kernels->shift = stype == GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY? - pos_shift_gk_kern_list_shift_ser[pdim-2].kernels[poly_order-1] : - pos_shift_gk_kern_list_MRSlimiter_ser[pdim-2].kernels[poly_order-1]; - kernels->m0 = pos_shift_gk_kern_list_m0_ser[pdim-2].kernels[poly_order-1]; - kernels->conf_phase_mul_op = choose_mul_conf_phase_kern(pbasis_type, cdim, pdim-cdim, poly_order); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_GKHYBRID: + case GKYL_BASIS_MODAL_SERENDIPITY: + kernels->is_m0_positive = + pos_shift_gk_kern_list_m0_pos_check_ser[cdim - 1].kernels[poly_order - 1]; + kernels->shift = stype == GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY ? + pos_shift_gk_kern_list_shift_ser[pdim - 2].kernels[poly_order - 1] : + pos_shift_gk_kern_list_MRSlimiter_ser[pdim - 2].kernels[poly_order - 1]; + kernels->m0 = pos_shift_gk_kern_list_m0_ser[pdim - 2].kernels[poly_order - 1]; + kernels->conf_phase_mul_op = + choose_mul_conf_phase_kern(pbasis_type, cdim, pdim - cdim, poly_order); + break; + default: + assert(false); + break; } switch (cbasis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - kernels->conf_inv_op = choose_ser_inv_kern(cdim, poly_order); - kernels->conf_mul_op = choose_ser_mul_kern(cdim, poly_order); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + kernels->conf_inv_op = choose_ser_inv_kern(cdim, poly_order); + kernels->conf_mul_op = choose_ser_mul_kern(cdim, poly_order); + break; + default: + assert(false); + break; } }; -void -pos_shift_gk_choose_shift_kernel_cu(struct gkyl_positivity_shift_gyrokinetic_kernels *kernels, - struct gkyl_basis cbasis, struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype) +void pos_shift_gk_choose_shift_kernel_cu( + struct gkyl_positivity_shift_gyrokinetic_kernels *kernels, struct gkyl_basis cbasis, + struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype +) { - gkyl_pos_shift_gk_set_cu_ker_ptrs<<<1,1>>>(kernels, cbasis, pbasis, stype); + gkyl_pos_shift_gk_set_cu_ker_ptrs<<<1, 1> > >(kernels, cbasis, pbasis, stype); } // Function borrowed from array_reduce_cu.cu. -__device__ static __forceinline__ double -pos_shift_atomicMax_double(double *address, double val) +__device__ static __forceinline__ double pos_shift_atomicMax_double(double *address, double val) { unsigned long long int ret = __double_as_longlong(*address); - while(val > __longlong_as_double(ret)) - { + while (val > __longlong_as_double(ret)) { unsigned long long int old = ret; - if((ret = atomicCAS((unsigned long long int*)address, old, __double_as_longlong(val))) == old) + if ((ret = atomicCAS((unsigned long long int *)address, old, __double_as_longlong(val))) == + old) { break; + } } return __longlong_as_double(ret); } __global__ void -gkyl_positivity_shift_gyrokinetic_advance_int_array_clear_cu_ker(struct gkyl_array* out, int val) +gkyl_positivity_shift_gyrokinetic_advance_int_array_clear_cu_ker(struct gkyl_array *out, int val) { - int *out_d = (int*) out->data; - unsigned long start_id = threadIdx.x + blockIdx.x*blockDim.x; - unsigned long nelm = out->size*out->ncomp; - for (unsigned long linc = start_id; linc < nelm; linc += blockDim.x*gridDim.x) + int *out_d = (int *)out->data; + unsigned long start_id = threadIdx.x + blockIdx.x * blockDim.x; + unsigned long nelm = out->size * out->ncomp; + for (unsigned long linc = start_id; linc < nelm; linc += blockDim.x * gridDim.x) { out_d[linc] = val; + } } -__global__ static void -gkyl_positivity_shift_gyrokinetic_advance_shift_cu_ker( +__global__ static void gkyl_positivity_shift_gyrokinetic_advance_shift_cu_ker( struct gkyl_positivity_shift_gyrokinetic_kernels *kers, const struct gkyl_rect_grid grid, - const struct gkyl_range conf_range, const struct gkyl_range vel_range, const struct gkyl_range phase_range, - double *ffloor, double ffloor_fac, double cellav_fac, double mass, - const struct gkyl_array* GKYL_RESTRICT bmag, - const struct gkyl_array* GKYL_RESTRICT jacobtot, const struct gkyl_array* GKYL_RESTRICT jacobtot_inv, - const struct gkyl_array *vmap, const struct gkyl_array *jacobvel, struct gkyl_array* GKYL_RESTRICT shiftedf, - struct gkyl_array* GKYL_RESTRICT distf, struct gkyl_array* GKYL_RESTRICT m0, struct gkyl_array* GKYL_RESTRICT delta_m0) + const struct gkyl_range conf_range, const struct gkyl_range vel_range, + const struct gkyl_range phase_range, double *ffloor, double ffloor_fac, double cellav_fac, + double mass, const struct gkyl_array *GKYL_RESTRICT bmag, + const struct gkyl_array *GKYL_RESTRICT jacobtot, + const struct gkyl_array *GKYL_RESTRICT jacobtot_inv, const struct gkyl_array *vmap, + const struct gkyl_array *jacobvel, struct gkyl_array *GKYL_RESTRICT shiftedf, + struct gkyl_array *GKYL_RESTRICT distf, struct gkyl_array *GKYL_RESTRICT m0, + struct gkyl_array *GKYL_RESTRICT delta_m0 +) { int pidx[GKYL_MAX_DIM]; double distf_max = -DBL_MAX; @@ -89,143 +96,149 @@ gkyl_positivity_shift_gyrokinetic_advance_shift_cu_ker( const int num_cbasis = 20; // MF 2024/09/03: Hardcoded to p=2 3x ser for now. - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < phase_range.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < phase_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&phase_range, tid, pidx); int vidx[2]; - for (int d=cdim; dncomp; ++k) + for (unsigned int k = 0; k < delta_m0->ncomp; ++k) { m0phase_in_c[k] = 0.0; + } kers->m0(grid.dx, vmap_c, mass, bmag_c, distf_c, m0phase_in_c); // Add to the old number density. - for (unsigned int k = 0; k < delta_m0->ncomp; ++k) + for (unsigned int k = 0; k < delta_m0->ncomp; ++k) { atomicAdd(&delta_m0_c[k], m0phase_in_c[k]); + } - // Shift f if needed. bool shifted_node = false; // Divide by jacobtot and jacobvel so that we are shifting just f. kers->conf_phase_mul_op(jacobtot_inv_c, distf_c, distf_c); - for (int k=0; kncomp; k++) + for (int k = 0; k < distf->ncomp; k++) { distf_c[k] /= jacobvel_c[0]; + } // Shift f to enforce positivity if needed. shifted_node = kers->shift(ffloor[0], distf_c); // Multiply by jacobtot and jacobvel to compute M0. kers->conf_phase_mul_op(jacobtot_c, distf_c, distf_c); - for (int k=0; kncomp; k++) + for (int k = 0; k < distf->ncomp; k++) { distf_c[k] *= jacobvel_c[0]; - + } if (shifted_node) { // Compute the new number density local to this phase-space cell. double m0phase_out_c[num_cbasis]; - for (unsigned int k=0; kncomp; ++k) + for (unsigned int k = 0; k < m0->ncomp; ++k) { m0phase_out_c[k] = 0.0; + } kers->m0(grid.dx, vmap_c, mass, bmag_c, distf_c, m0phase_out_c); if (m0phase_in_c[0] > 0.0 && m0phase_out_c[0] > 0.0) { // Rescale f in this cell so it keeps the same cell-averaged density. - double m0ratio = m0phase_in_c[0]/m0phase_out_c[0]; + double m0ratio = m0phase_in_c[0] / m0phase_out_c[0]; - for (unsigned int k=0; kncomp; ++k) + for (unsigned int k = 0; k < distf->ncomp; ++k) { distf_c[k] *= m0ratio; + } // Add contribution from this phase-space cell to the new number density. - for (unsigned int k = 0; k < m0->ncomp; ++k) - atomicAdd(&m0_c[k], m0ratio*m0phase_out_c[k]); - } - else { + for (unsigned int k = 0; k < m0->ncomp; ++k) { + atomicAdd(&m0_c[k], m0ratio * m0phase_out_c[k]); + } + } else { // Add contribution from this phase-space cell to the new number density. - for (unsigned int k = 0; k < m0->ncomp; ++k) + for (unsigned int k = 0; k < m0->ncomp; ++k) { atomicAdd(&m0_c[k], m0phase_out_c[k]); + } atomicOr(shiftedf_c, shifted_node); } - } - else { + } else { // Add contribution from this phase-space cell to the new number density. - for (unsigned int k = 0; k < m0->ncomp; ++k) + for (unsigned int k = 0; k < m0->ncomp; ++k) { atomicAdd(&m0_c[k], m0phase_in_c[k]); + } } distf_max = fmax(distf_max, distf_c[0]); - } pos_shift_atomicMax_double(ffloor, ffloor_fac * distf_max * cellav_fac); } -__global__ static void -gkyl_positivity_shift_gyrokinetic_advance_scalef_cu_ker( - struct gkyl_positivity_shift_gyrokinetic_kernels *kers, - const struct gkyl_range conf_range, const struct gkyl_range phase_range, - const struct gkyl_array* GKYL_RESTRICT shiftedf, const struct gkyl_array* GKYL_RESTRICT m0, - const struct gkyl_array* GKYL_RESTRICT delta_m0, struct gkyl_array* GKYL_RESTRICT distf) +__global__ static void gkyl_positivity_shift_gyrokinetic_advance_scalef_cu_ker( + struct gkyl_positivity_shift_gyrokinetic_kernels *kers, const struct gkyl_range conf_range, + const struct gkyl_range phase_range, const struct gkyl_array *GKYL_RESTRICT shiftedf, + const struct gkyl_array *GKYL_RESTRICT m0, const struct gkyl_array *GKYL_RESTRICT delta_m0, + struct gkyl_array *GKYL_RESTRICT distf +) { int pidx[GKYL_MAX_DIM]; const int num_cbasis = 20; // MF 2024/09/03: Hardcoded to p=2 3x ser for now. - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < phase_range.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < phase_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&phase_range, tid, pidx); long clinidx = gkyl_range_idx(&conf_range, pidx); - const int *shiftedf_c = (const int*) gkyl_array_cfetch(shiftedf, clinidx); + const int *shiftedf_c = (const int *)gkyl_array_cfetch(shiftedf, clinidx); if (shiftedf_c[0]) { - const double *delta_m0_c = (const double*) gkyl_array_cfetch(delta_m0, clinidx); + const double *delta_m0_c = (const double *)gkyl_array_cfetch(delta_m0, clinidx); if (kers->is_m0_positive(delta_m0_c)) { // Rescale f so it has the same m0 at this conf-space cell. - const double *m0_c = (const double*) gkyl_array_cfetch(m0, clinidx); + const double *m0_c = (const double *)gkyl_array_cfetch(m0, clinidx); double m0ratio_c[num_cbasis]; kers->conf_inv_op(m0_c, m0ratio_c); kers->conf_mul_op(delta_m0_c, m0ratio_c, m0ratio_c); long plinidx = gkyl_range_idx(&phase_range, pidx); - double *distf_c = (double*) gkyl_array_fetch(distf, plinidx); + double *distf_c = (double *)gkyl_array_fetch(distf, plinidx); kers->conf_phase_mul_op(m0ratio_c, distf_c, distf_c); } } } } -__global__ static void -gkyl_positivity_shift_gyrokinetic_advance_m0fix_cu_ker( - struct gkyl_positivity_shift_gyrokinetic_kernels *kers, - const struct gkyl_range conf_range, const struct gkyl_array* GKYL_RESTRICT shiftedf, - struct gkyl_array* GKYL_RESTRICT m0, struct gkyl_array* GKYL_RESTRICT delta_m0) +__global__ static void gkyl_positivity_shift_gyrokinetic_advance_m0fix_cu_ker( + struct gkyl_positivity_shift_gyrokinetic_kernels *kers, const struct gkyl_range conf_range, + const struct gkyl_array *GKYL_RESTRICT shiftedf, struct gkyl_array *GKYL_RESTRICT m0, + struct gkyl_array *GKYL_RESTRICT delta_m0 +) { int cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_range.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_range, tid, cidx); long clinidx = gkyl_range_idx(&conf_range, cidx); - const int *shiftedf_c = (const int*) gkyl_array_cfetch(shiftedf, clinidx); - double *delta_m0_c = (double*) gkyl_array_fetch(delta_m0, clinidx); + const int *shiftedf_c = (const int *)gkyl_array_cfetch(shiftedf, clinidx); + double *delta_m0_c = (double *)gkyl_array_fetch(delta_m0, clinidx); if (shiftedf_c[0]) { double *m0_c = (double *)gkyl_array_fetch(m0, clinidx); @@ -234,24 +247,24 @@ gkyl_positivity_shift_gyrokinetic_advance_m0fix_cu_ker( m0_c[k] = delta_m0_c[k]; delta_m0_c[k] = 0.0; } - } - else { - for (int k = 0; k < m0->ncomp; k++) + } else { + for (int k = 0; k < m0->ncomp; k++) { delta_m0_c[k] = m0_c[k] - delta_m0_c[k]; + } } - } - else { - for (int k = 0; k < m0->ncomp; k++) + } else { + for (int k = 0; k < m0->ncomp; k++) { delta_m0_c[k] = 0.0; + } } } } -void -gkyl_positivity_shift_gyrokinetic_advance_cu(gkyl_positivity_shift_gyrokinetic* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - struct gkyl_array *GKYL_RESTRICT distf, struct gkyl_array *GKYL_RESTRICT m0, - struct gkyl_array *GKYL_RESTRICT delta_m0) +void gkyl_positivity_shift_gyrokinetic_advance_cu( + gkyl_positivity_shift_gyrokinetic *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, struct gkyl_array *GKYL_RESTRICT distf, + struct gkyl_array *GKYL_RESTRICT m0, struct gkyl_array *GKYL_RESTRICT delta_m0 +) { int nblocks_phase = phase_rng->nblocks, nthreads_phase = phase_rng->nthreads; int nblocks_conf = conf_rng->nblocks, nthreads_conf = conf_rng->nthreads; @@ -260,63 +273,67 @@ gkyl_positivity_shift_gyrokinetic_advance_cu(gkyl_positivity_shift_gyrokinetic* gkyl_array_clear_range(delta_m0, 0.0, conf_rng); // Set shiftedf boolean (int) to 0s. - gkyl_positivity_shift_gyrokinetic_advance_int_array_clear_cu_ker<<>> - (up->shiftedf->on_dev, 0); + gkyl_positivity_shift_gyrokinetic_advance_int_array_clear_cu_ker<< > >( + up->shiftedf->on_dev, 0 + ); // Shift f is needed & scale f locally if initial local contribution to M0 was >0. - gkyl_positivity_shift_gyrokinetic_advance_shift_cu_ker<<>> - (up->kernels, up->grid, *conf_rng, up->vel_map->local_vel, *phase_rng, up->ffloor, up->ffloor_fac, - up->cellav_fac, up->mass, - up->gk_geom->geo_int.bmag->on_dev, up->gk_geom->geo_int.jacobtot->on_dev, - up->gk_geom->geo_int.jacobtot_inv->on_dev, up->vel_map->vmap->on_dev, up->vel_map->jacobvel->on_dev, - up->shiftedf->on_dev, distf->on_dev, m0->on_dev, delta_m0->on_dev); + gkyl_positivity_shift_gyrokinetic_advance_shift_cu_ker<< > >( + up->kernels, up->grid, *conf_rng, up->vel_map->local_vel, *phase_rng, up->ffloor, + up->ffloor_fac, up->cellav_fac, up->mass, up->gk_geom->geo_int.bmag->on_dev, + up->gk_geom->geo_int.jacobtot->on_dev, up->gk_geom->geo_int.jacobtot_inv->on_dev, + up->vel_map->vmap->on_dev, up->vel_map->jacobvel->on_dev, up->shiftedf->on_dev, distf->on_dev, + m0->on_dev, delta_m0->on_dev + ); // If a shift took place, rescale f so it keeps the same M0. - gkyl_positivity_shift_gyrokinetic_advance_scalef_cu_ker<<>> - (up->kernels, *conf_rng, *phase_rng, up->shiftedf->on_dev, m0->on_dev, delta_m0->on_dev, distf->on_dev); + gkyl_positivity_shift_gyrokinetic_advance_scalef_cu_ker<< > >( + up->kernels, *conf_rng, *phase_rng, up->shiftedf->on_dev, m0->on_dev, delta_m0->on_dev, + distf->on_dev + ); // Ensure m0 and delta_m0 are correct based on whether a shift took place. - gkyl_positivity_shift_gyrokinetic_advance_m0fix_cu_ker<<>> - (up->kernels, *conf_rng, up->shiftedf->on_dev, m0->on_dev, delta_m0->on_dev); + gkyl_positivity_shift_gyrokinetic_advance_m0fix_cu_ker<< > >( + up->kernels, *conf_rng, up->shiftedf->on_dev, m0->on_dev, delta_m0->on_dev + ); } -__global__ static void -gkyl_positivity_shift_gyrokinetic_quasineutrily_scale_cu_ker( - struct gkyl_positivity_shift_gyrokinetic_kernels *kers, - const struct gkyl_range conf_rng, const struct gkyl_range phase_rng, - const struct gkyl_array *GKYL_RESTRICT delta_m0s, const struct gkyl_array *GKYL_RESTRICT delta_m0s_tot, +__global__ static void gkyl_positivity_shift_gyrokinetic_quasineutrily_scale_cu_ker( + struct gkyl_positivity_shift_gyrokinetic_kernels *kers, const struct gkyl_range conf_rng, + const struct gkyl_range phase_rng, const struct gkyl_array *GKYL_RESTRICT delta_m0s, + const struct gkyl_array *GKYL_RESTRICT delta_m0s_tot, const struct gkyl_array *GKYL_RESTRICT delta_m0r_tot, const struct gkyl_array *GKYL_RESTRICT m0s, - struct gkyl_array *GKYL_RESTRICT fs) + struct gkyl_array *GKYL_RESTRICT fs +) { int pidx[GKYL_MAX_DIM]; const int num_cbasis = 20; // MF 2024/09/03: Hardcoded to p=2 3x ser for now. - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < phase_rng.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < phase_rng.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&phase_rng, tid, pidx); long clinidx = gkyl_range_idx(&conf_rng, pidx); - const double *delta_m0r_tot_c = (const double*) gkyl_array_cfetch(delta_m0r_tot, clinidx); - const double *delta_m0s_tot_c = (const double*) gkyl_array_cfetch(delta_m0s_tot, clinidx); + const double *delta_m0r_tot_c = (const double *)gkyl_array_cfetch(delta_m0r_tot, clinidx); + const double *delta_m0s_tot_c = (const double *)gkyl_array_cfetch(delta_m0s_tot, clinidx); // First condition in this if-statement is equivalent to // max((delta_m0r_tot_c[0]-delta_m0s_tot_c[0])/abs(delta_m0r_tot_c[0]-delta_m0s_tot_c[0])) // and the second condition is to avoid division by 0. - if (delta_m0r_tot_c[0] > delta_m0s_tot_c[0] && - delta_m0s_tot_c[0] > 0.0) { - - const double *delta_m0s_c = (const double*) gkyl_array_cfetch(delta_m0s, clinidx); - const double *m0s_c = (const double*) gkyl_array_cfetch(m0s, clinidx); + if (delta_m0r_tot_c[0] > delta_m0s_tot_c[0] && delta_m0s_tot_c[0] > 0.0) { + const double *delta_m0s_c = (const double *)gkyl_array_cfetch(delta_m0s, clinidx); + const double *m0s_c = (const double *)gkyl_array_cfetch(m0s, clinidx); // Compute the scaling factor (n_s+h)/n_s with h=(Delta n_r,tot - Delta_n_s,tot) * Delta n_s/Delta_n_s,tot // - Delta n_s = shift in density of this species due to positivity shift. // - Delta n_s,tot = sum of Delta n for species with same charge sign. // - Delta n_r,tot = sum of Delta n for species with opposite charge sign. double delta_m0fac_c[num_cbasis]; - for (int k=0; kncomp; k++) + for (int k = 0; k < delta_m0r_tot->ncomp; k++) { delta_m0fac_c[k] = delta_m0r_tot_c[k] - delta_m0s_tot_c[k]; + } kers->conf_mul_op(delta_m0fac_c, delta_m0s_c, delta_m0fac_c); @@ -325,8 +342,9 @@ gkyl_positivity_shift_gyrokinetic_quasineutrily_scale_cu_ker( kers->conf_mul_op(delta_m0fac_c, inv_c, delta_m0fac_c); - for (int k=0; kncomp; k++) + for (int k = 0; k < m0s->ncomp; k++) { delta_m0fac_c[k] += m0s_c[k]; + } kers->conf_inv_op(m0s_c, inv_c); @@ -334,21 +352,23 @@ gkyl_positivity_shift_gyrokinetic_quasineutrily_scale_cu_ker( // Scale the distribution function. long plinidx = gkyl_range_idx(&phase_rng, pidx); - double *fs_c = (double*) gkyl_array_fetch(fs, plinidx); + double *fs_c = (double *)gkyl_array_fetch(fs, plinidx); kers->conf_phase_mul_op(delta_m0fac_c, fs_c, fs_c); } } } -void -gkyl_positivity_shift_gyrokinetic_quasineutrality_scale_cu(gkyl_positivity_shift_gyrokinetic* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - const struct gkyl_array *GKYL_RESTRICT delta_m0s, const struct gkyl_array *GKYL_RESTRICT delta_m0s_tot, +void gkyl_positivity_shift_gyrokinetic_quasineutrality_scale_cu( + gkyl_positivity_shift_gyrokinetic *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, const struct gkyl_array *GKYL_RESTRICT delta_m0s, + const struct gkyl_array *GKYL_RESTRICT delta_m0s_tot, const struct gkyl_array *GKYL_RESTRICT delta_m0r_tot, const struct gkyl_array *GKYL_RESTRICT m0s, - struct gkyl_array *GKYL_RESTRICT fs) + struct gkyl_array *GKYL_RESTRICT fs +) { int nblocks = phase_rng->nblocks, nthreads = phase_rng->nthreads; - gkyl_positivity_shift_gyrokinetic_quasineutrily_scale_cu_ker<<>>( + gkyl_positivity_shift_gyrokinetic_quasineutrily_scale_cu_ker<< > >( up->kernels, *conf_rng, *phase_rng, delta_m0s->on_dev, delta_m0s_tot->on_dev, - delta_m0r_tot->on_dev, m0s->on_dev, fs->on_dev); + delta_m0r_tot->on_dev, m0s->on_dev, fs->on_dev + ); } diff --git a/gyrokinetic/zero/prim_lbo_calc_gyrokinetic.c b/gyrokinetic/zero/prim_lbo_calc_gyrokinetic.c index b5be1448c4..668ba43495 100644 --- a/gyrokinetic/zero/prim_lbo_calc_gyrokinetic.c +++ b/gyrokinetic/zero/prim_lbo_calc_gyrokinetic.c @@ -9,10 +9,10 @@ #include // "derived" class constructors -struct gkyl_prim_lbo_calc* -gkyl_prim_lbo_gyrokinetic_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_rng, bool use_gpu) +struct gkyl_prim_lbo_calc *gkyl_prim_lbo_gyrokinetic_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_rng, bool use_gpu +) { struct gkyl_prim_lbo_type *prim; // LBO primitive moments type prim = gkyl_prim_lbo_gyrokinetic_new(cbasis, pbasis, use_gpu); diff --git a/gyrokinetic/zero/prim_lbo_cross_calc_gyrokinetic.c b/gyrokinetic/zero/prim_lbo_cross_calc_gyrokinetic.c index 8edb0e84f2..aa5d85005e 100644 --- a/gyrokinetic/zero/prim_lbo_cross_calc_gyrokinetic.c +++ b/gyrokinetic/zero/prim_lbo_cross_calc_gyrokinetic.c @@ -9,10 +9,10 @@ #include // "derived" class constructors -struct gkyl_prim_lbo_cross_calc* -gkyl_prim_lbo_gyrokinetic_cross_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_rng, bool use_gpu) +struct gkyl_prim_lbo_cross_calc *gkyl_prim_lbo_gyrokinetic_cross_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_rng, bool use_gpu +) { struct gkyl_prim_lbo_type *prim; // LBO primitive moments type prim = gkyl_prim_lbo_gyrokinetic_new(cbasis, pbasis, use_gpu); diff --git a/gyrokinetic/zero/prim_lbo_gyrokinetic.c b/gyrokinetic/zero/prim_lbo_gyrokinetic.c index 1d75c3e2c6..f1ee4c4d16 100644 --- a/gyrokinetic/zero/prim_lbo_gyrokinetic.c +++ b/gyrokinetic/zero/prim_lbo_gyrokinetic.c @@ -8,32 +8,34 @@ #include #include -void -prim_lbo_gyrokinetic_free(const struct gkyl_ref_count *ref) +void prim_lbo_gyrokinetic_free(const struct gkyl_ref_count *ref) { struct gkyl_prim_lbo_type *prim_ty = container_of(ref, struct gkyl_prim_lbo_type, ref_count); - if (GKYL_IS_CU_ALLOC(prim_ty->flag)) + if (GKYL_IS_CU_ALLOC(prim_ty->flag)) { gkyl_cu_free(prim_ty->on_dev); + } - struct prim_lbo_type_gyrokinetic *gk = container_of(prim_ty, struct prim_lbo_type_gyrokinetic, prim); + struct prim_lbo_type_gyrokinetic *gk = + container_of(prim_ty, struct prim_lbo_type_gyrokinetic, prim); gkyl_free(gk); } -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_gyrokinetic_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, bool use_gpu) +struct gkyl_prim_lbo_type *gkyl_prim_lbo_gyrokinetic_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_prim_lbo_gyrokinetic_cu_dev_new(cbasis, pbasis); - } -#endif - struct prim_lbo_type_gyrokinetic *prim_gyrokinetic = gkyl_malloc(sizeof(struct prim_lbo_type_gyrokinetic)); + } +#endif + struct prim_lbo_type_gyrokinetic *prim_gyrokinetic = + gkyl_malloc(sizeof(struct prim_lbo_type_gyrokinetic)); int cdim = prim_gyrokinetic->prim.cdim = cbasis->ndim; int pdim = prim_gyrokinetic->prim.pdim = pbasis->ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int poly_order = prim_gyrokinetic->prim.poly_order = cbasis->poly_order; prim_gyrokinetic->prim.num_config = cbasis->num_basis; prim_gyrokinetic->prim.num_phase = pbasis->num_basis; @@ -46,26 +48,26 @@ gkyl_prim_lbo_gyrokinetic_new(const struct gkyl_basis* cbasis, const gkyl_prim_lbo_gyrokinetic_cross_kern_list *cross_prim_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - self_prim_kernels = ser_self_prim_kernels; - cross_prim_kernels = ser_cross_prim_kernels; - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + self_prim_kernels = ser_self_prim_kernels; + cross_prim_kernels = ser_cross_prim_kernels; + break; - default: - assert(false); - break; + default: + assert(false); + break; } - assert(NULL != self_prim_kernels[pdim-2].kernels[poly_order]); - assert(NULL != cross_prim_kernels[pdim-2].kernels[poly_order]); - - prim_gyrokinetic->self_prim = self_prim_kernels[pdim-2].kernels[poly_order]; - prim_gyrokinetic->cross_prim = cross_prim_kernels[pdim-2].kernels[poly_order]; + assert(NULL != self_prim_kernels[pdim - 2].kernels[poly_order]); + assert(NULL != cross_prim_kernels[pdim - 2].kernels[poly_order]); + + prim_gyrokinetic->self_prim = self_prim_kernels[pdim - 2].kernels[poly_order]; + prim_gyrokinetic->cross_prim = cross_prim_kernels[pdim - 2].kernels[poly_order]; prim_gyrokinetic->prim.flag = 0; GKYL_CLEAR_CU_ALLOC(prim_gyrokinetic->prim.flag); prim_gyrokinetic->prim.ref_count = gkyl_ref_count_init(prim_lbo_gyrokinetic_free); prim_gyrokinetic->prim.on_dev = &prim_gyrokinetic->prim; - + return &prim_gyrokinetic->prim; } diff --git a/gyrokinetic/zero/prim_lbo_gyrokinetic_cu.cu b/gyrokinetic/zero/prim_lbo_gyrokinetic_cu.cu index f648f3fcd4..c07a662470 100644 --- a/gyrokinetic/zero/prim_lbo_gyrokinetic_cu.cu +++ b/gyrokinetic/zero/prim_lbo_gyrokinetic_cu.cu @@ -10,42 +10,44 @@ extern "C" { #include } -__global__ static void -gkyl_prim_lbo_gyrokinetic_set_cu_dev_ptrs(struct prim_lbo_type_gyrokinetic *prim_gyrokinetic, int cdim, int vdim, int poly_order, enum gkyl_basis_type b_type) +__global__ static void gkyl_prim_lbo_gyrokinetic_set_cu_dev_ptrs( + struct prim_lbo_type_gyrokinetic *prim_gyrokinetic, int cdim, int vdim, int poly_order, + enum gkyl_basis_type b_type +) { - int pdim = cdim+vdim; + int pdim = cdim + vdim; prim_gyrokinetic->prim.self_prim = self_prim; prim_gyrokinetic->prim.cross_prim = cross_prim; - + // choose kernel tables based on basis-function type const gkyl_prim_lbo_gyrokinetic_kern_list *self_prim_kernels; const gkyl_prim_lbo_gyrokinetic_cross_kern_list *cross_prim_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - self_prim_kernels = ser_self_prim_kernels; - cross_prim_kernels = ser_cross_prim_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + self_prim_kernels = ser_self_prim_kernels; + cross_prim_kernels = ser_cross_prim_kernels; + break; + + default: + assert(false); + break; } - prim_gyrokinetic->self_prim = self_prim_kernels[pdim-2].kernels[poly_order]; - prim_gyrokinetic->cross_prim = cross_prim_kernels[pdim-2].kernels[poly_order]; + prim_gyrokinetic->self_prim = self_prim_kernels[pdim - 2].kernels[poly_order]; + prim_gyrokinetic->cross_prim = cross_prim_kernels[pdim - 2].kernels[poly_order]; } -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis) +struct gkyl_prim_lbo_type *gkyl_prim_lbo_gyrokinetic_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis +) { assert(cbasis->poly_order == pbasis->poly_order); - + struct prim_lbo_type_gyrokinetic *prim_gyrokinetic = - (struct prim_lbo_type_gyrokinetic*) gkyl_malloc(sizeof(struct prim_lbo_type_gyrokinetic)); - + (struct prim_lbo_type_gyrokinetic *)gkyl_malloc(sizeof(struct prim_lbo_type_gyrokinetic)); + int cdim = prim_gyrokinetic->prim.cdim = cbasis->ndim; int pdim = prim_gyrokinetic->prim.pdim = pbasis->ndim; int vdim = pdim - cdim; @@ -57,16 +59,20 @@ gkyl_prim_lbo_gyrokinetic_cu_dev_new(const struct gkyl_basis* cbasis, prim_gyrokinetic->prim.flag = 0; GKYL_SET_CU_ALLOC(prim_gyrokinetic->prim.flag); prim_gyrokinetic->prim.ref_count = gkyl_ref_count_init(prim_lbo_gyrokinetic_free); - + // copy the host struct to device struct - struct prim_lbo_type_gyrokinetic *prim_gyrokinetic_cu = (struct prim_lbo_type_gyrokinetic*) - gkyl_cu_malloc(sizeof(struct prim_lbo_type_gyrokinetic)); - gkyl_cu_memcpy(prim_gyrokinetic_cu, prim_gyrokinetic, sizeof(struct prim_lbo_type_gyrokinetic), GKYL_CU_MEMCPY_H2D); + struct prim_lbo_type_gyrokinetic *prim_gyrokinetic_cu = + (struct prim_lbo_type_gyrokinetic *)gkyl_cu_malloc(sizeof(struct prim_lbo_type_gyrokinetic)); + gkyl_cu_memcpy( + prim_gyrokinetic_cu, prim_gyrokinetic, sizeof(struct prim_lbo_type_gyrokinetic), + GKYL_CU_MEMCPY_H2D + ); - gkyl_prim_lbo_gyrokinetic_set_cu_dev_ptrs<<<1,1>>>(prim_gyrokinetic_cu, cdim, vdim, poly_order, - cbasis->b_type); + gkyl_prim_lbo_gyrokinetic_set_cu_dev_ptrs<<<1, 1> > >( + prim_gyrokinetic_cu, cdim, vdim, poly_order, cbasis->b_type + ); prim_gyrokinetic->prim.on_dev = &prim_gyrokinetic_cu->prim; - + return &prim_gyrokinetic->prim; } diff --git a/gyrokinetic/zero/proj_exp_on_basis.c b/gyrokinetic/zero/proj_exp_on_basis.c index 3a50f8ddde..47d49e464b 100644 --- a/gyrokinetic/zero/proj_exp_on_basis.c +++ b/gyrokinetic/zero/proj_exp_on_basis.c @@ -10,9 +10,12 @@ #include // create range to loop over quadrature points. -static inline struct gkyl_range get_qrange(int dim, int num_quad) { +static inline struct gkyl_range get_qrange(int dim, int num_quad) +{ int qshape[GKYL_MAX_DIM]; - for (int i=0; indim; double ordinates1[num_quad], weights1[num_quad]; @@ -32,8 +36,7 @@ init_quad_values(const struct gkyl_basis *basis, int num_quad, // than computing them on the fly) memcpy(ordinates1, gkyl_gauss_ordinates[num_quad], sizeof(double[num_quad])); memcpy(weights1, gkyl_gauss_weights[num_quad], sizeof(double[num_quad])); - } - else { + } else { gkyl_gauleg(-1, 1, ordinates1, weights1, num_quad); } @@ -58,24 +61,28 @@ init_quad_values(const struct gkyl_basis *basis, int num_quad, // set ordinates double *ord = gkyl_array_fetch(ordinates_ho, node); - for (int i=0; inum_basis, tot_quad); - if (use_gpu) + if (use_gpu) { *basis_at_ords = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis->num_basis, tot_quad); - else + } else { *basis_at_ords = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, tot_quad); - for (int n=0; neval(gkyl_array_fetch(ordinates_ho, n), gkyl_array_fetch(basis_at_ords_ho, n)); + } // copy host array to device array gkyl_array_copy(*weights, weights_ho); @@ -88,7 +95,7 @@ init_quad_values(const struct gkyl_basis *basis, int num_quad, return tot_quad; } -gkyl_proj_exp_on_basis* +gkyl_proj_exp_on_basis * gkyl_proj_exp_on_basis_new(const struct gkyl_basis *basis, int num_quad, bool use_gpu) { gkyl_proj_exp_on_basis *up = gkyl_malloc(sizeof(gkyl_proj_exp_on_basis)); @@ -99,44 +106,49 @@ gkyl_proj_exp_on_basis_new(const struct gkyl_basis *basis, int num_quad, bool us up->use_gpu = use_gpu; // initialize data needed for quadrature - up->tot_quad = init_quad_values(basis, num_quad, &up->weights, - &up->basis_at_ords, use_gpu); + up->tot_quad = init_quad_values(basis, num_quad, &up->weights, &up->basis_at_ords, use_gpu); - if (up->use_gpu) + if (up->use_gpu) { up->fun_at_ords = NULL; - else - up->fun_at_ords = gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad); // Only used in CPU implementation. + } else { + up->fun_at_ords = + gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad); // Only used in CPU implementation. + } return up; } static void -proj_on_basis(const gkyl_proj_exp_on_basis *up, const struct gkyl_array *fun_at_ords, double* f) +proj_on_basis(const gkyl_proj_exp_on_basis *up, const struct gkyl_array *fun_at_ords, double *f) { int num_basis = up->num_basis; int tot_quad = up->tot_quad; - const double* GKYL_RESTRICT weights = up->weights->data; - const double* GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; - const double* GKYL_RESTRICT func_at_ords = fun_at_ords->data; + const double *GKYL_RESTRICT weights = up->weights->data; + const double *GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; + const double *GKYL_RESTRICT func_at_ords = fun_at_ords->data; - for (int k=0; kuse_gpu) + if (up->use_gpu) { return gkyl_proj_exp_on_basis_advance_cu(up, range, alpha, beta, fIn, fOut); + } #endif // Create range to loop over quadrature points. @@ -152,33 +164,32 @@ gkyl_proj_exp_on_basis_advance(const gkyl_proj_exp_on_basis *up, struct gkyl_range_iter qiter; gkyl_range_iter_init(&qiter, &qrange); while (gkyl_range_iter_next(&qiter)) { - int qidx = gkyl_range_idx(&qrange, qiter.idx); // Evaluate input function f at quad point. const double *b_ord = gkyl_array_cfetch(up->basis_at_ords, qidx); - double fIn_q=0.; - for (int k=0; knum_basis; ++k) - fIn_q += fIn_d[k]*b_ord[k]; + double fIn_q = 0.; + for (int k = 0; k < up->num_basis; ++k) { + fIn_q += fIn_d[k] * b_ord[k]; + } double *fOut_q = gkyl_array_fetch(up->fun_at_ords, qidx); // Evaluate exp at quad point. - fOut_q[0] = alpha*exp(beta*fIn_q); + fOut_q[0] = alpha * exp(beta * fIn_q); } // Compute expansion coefficients. proj_on_basis(up, up->fun_at_ords, gkyl_array_fetch(fOut, linidx)); } - } -void -gkyl_proj_exp_on_basis_release(gkyl_proj_exp_on_basis* up) +void gkyl_proj_exp_on_basis_release(gkyl_proj_exp_on_basis *up) { gkyl_array_release(up->weights); gkyl_array_release(up->basis_at_ords); - if (!up->use_gpu) + if (!up->use_gpu) { gkyl_array_release(up->fun_at_ords); + } gkyl_free(up); } diff --git a/gyrokinetic/zero/proj_exp_on_basis_cu.cu b/gyrokinetic/zero/proj_exp_on_basis_cu.cu index 1249e9f674..1bcfe67862 100644 --- a/gyrokinetic/zero/proj_exp_on_basis_cu.cu +++ b/gyrokinetic/zero/proj_exp_on_basis_cu.cu @@ -7,60 +7,62 @@ extern "C" { #include } -__global__ static void -gkyl_proj_exp_on_basis_advance_cu_ker(int num_quad, - const struct gkyl_range range, const struct gkyl_array* GKYL_RESTRICT basis_at_ords, - const struct gkyl_array* GKYL_RESTRICT weights, double alpha, double beta, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT fOut) +__global__ static void gkyl_proj_exp_on_basis_advance_cu_ker( + int num_quad, const struct gkyl_range range, const struct gkyl_array *GKYL_RESTRICT basis_at_ords, + const struct gkyl_array *GKYL_RESTRICT weights, double alpha, double beta, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT fOut +) { int num_basis = basis_at_ords->ncomp; int tot_quad = basis_at_ords->size; int idx[GKYL_MAX_DIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < range.volume; tid += blockDim.x*gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&range, tid, idx); long linidx = gkyl_range_idx(&range, idx); - const double *fIn_d = (const double *) gkyl_array_cfetch(fIn, linidx); + const double *fIn_d = (const double *)gkyl_array_cfetch(fIn, linidx); - double *fOut_d = (double *) gkyl_array_fetch(fOut, linidx); - for (int k=0; kdata; - const double *bo_d = (const double *) basis_at_ords->data; + const double *w_d = (const double *)weights->data; + const double *bo_d = (const double *)basis_at_ords->data; - for (int n=0; nnblocks, nthreads = range->nthreads; - gkyl_proj_exp_on_basis_advance_cu_ker<<>> - (up->num_quad, *range, up->basis_at_ords->on_dev, - up->weights->on_dev, alpha, beta, fIn->on_dev, fOut->on_dev); + gkyl_proj_exp_on_basis_advance_cu_ker<< > >( + up->num_quad, *range, up->basis_at_ords->on_dev, up->weights->on_dev, alpha, beta, fIn->on_dev, + fOut->on_dev + ); } diff --git a/gyrokinetic/zero/radiation_read.c b/gyrokinetic/zero/radiation_read.c index 6afc22512c..afe573fa65 100644 --- a/gyrokinetic/zero/radiation_read.c +++ b/gyrokinetic/zero/radiation_read.c @@ -8,28 +8,26 @@ * STRING 'DELIM' #1 'DELIM' STRING 'DELIM' #2 * DELIM can be any of: ,:;= */ -static inline void -gkyl_radiation_read_two_numbers(FILE *fptr, int *num1, int *num2) +static inline void gkyl_radiation_read_two_numbers(FILE *fptr, int *num1, int *num2) { char str[BUFFER_LEN]; - char delim[5]="=,;:"; - if (fgets(str,BUFFER_LEN,fptr)!=NULL) { - strtok(str,delim); - *num1=atoi(strtok(NULL,delim)); - strtok(NULL,delim); - *num2=atoi(strtok(NULL,delim)); + char delim[5] = "=,;:"; + if (fgets(str, BUFFER_LEN, fptr) != NULL) { + strtok(str, delim); + *num1 = atoi(strtok(NULL, delim)); + strtok(NULL, delim); + *num2 = atoi(strtok(NULL, delim)); } } -struct all_radiation_states* -gkyl_radiation_read_rad_fit_params() +struct all_radiation_states *gkyl_radiation_read_rad_fit_params() { char fname[4000]; const char *fmt = "%s/%s"; snprintf(fname, sizeof fname, fmt, GKYL_SHARE_DIR, "adas/radiation_fit_parameters.txt"); - FILE *fptr = fopen(fname,"r"); - if (fptr == NULL){ + FILE *fptr = fopen(fname, "r"); + if (fptr == NULL) { printf("Error opening radiation fit file: %s\n", fname); exit(EXIT_FAILURE); } @@ -40,78 +38,86 @@ gkyl_radiation_read_rad_fit_params() struct all_radiation_states *rad_data = malloc(sizeof(struct all_radiation_states)); rad_data->max_atomic_number = max_atomic_number; - + /* allocate pointers for each species. Unphysical states of charge_state>atomic_number * are allocated but not used for simplicity */ - rad_data->all_states = - (struct radiating_state*) malloc(max_atomic_number*max_charge_state*sizeof(struct radiating_state)); - for (int i=0; iall_states[i*max_charge_state+j].atomic_number = i+1; - rad_data->all_states[i*max_charge_state+j].charge_state = j; - rad_data->all_states[i*max_charge_state+j].state_exists = false; - rad_data->all_states[i*max_charge_state+j].number_of_densities = 0; - rad_data->all_states[i*max_charge_state+j].rad_fits = NULL; - rad_data->all_states[i*max_charge_state+j].electron_densities = NULL; + rad_data->all_states = (struct radiating_state *)malloc( + max_atomic_number * max_charge_state * sizeof(struct radiating_state) + ); + for (int i = 0; i < max_atomic_number; i++) { + for (int j = 0; j < max_charge_state; j++) { + rad_data->all_states[i * max_charge_state + j].atomic_number = i + 1; + rad_data->all_states[i * max_charge_state + j].charge_state = j; + rad_data->all_states[i * max_charge_state + j].state_exists = false; + rad_data->all_states[i * max_charge_state + j].number_of_densities = 0; + rad_data->all_states[i * max_charge_state + j].rad_fits = NULL; + rad_data->all_states[i * max_charge_state + j].electron_densities = NULL; } } int atomic_number; int num_of_charge_states; int density_intervals; int charge_state; - for (int i=0; i0) { - int index = atomic_number*max_charge_state+charge_state; - rad_data->all_states[index].number_of_densities = density_intervals; - rad_data->all_states[index].state_exists = true; - rad_data->all_states[index].electron_densities = gkyl_array_new(GKYL_DOUBLE, 1, density_intervals); - rad_data->all_states[index].rad_fits = - (struct rad_fit_parameters*) malloc(density_intervals*sizeof(struct rad_fit_parameters)); - char buf[1000*15]; - for (int k=0; kall_states[index].electron_densities, k); - if (fgets(buf,1000*15, fptr) == NULL) { - rad_data->all_states[index].number_of_densities = rad_data->all_states[index].number_of_densities-1; - ne[0] = 0; - } else { - sscanf(buf, "%lf%lf%lf%lf%lf%lf%d",&ne[0], - &rad_data->all_states[index].rad_fits[k].A, - &rad_data->all_states[index].rad_fits[k].alpha, - &rad_data->all_states[index].rad_fits[k].beta, - &rad_data->all_states[index].rad_fits[k].V0, - &rad_data->all_states[index].rad_fits[k].gamma, - &rad_data->all_states[index].rad_fits[k].te_intervals); - int te_intervals = rad_data->all_states[index].rad_fits[k].te_intervals; - rad_data->all_states[index].rad_fits[k].te = (double*) malloc(te_intervals*sizeof(double)); - rad_data->all_states[index].rad_fits[k].Lz = (double*) malloc(te_intervals*sizeof(double)); - int offset=0; - if (fgets(buf, 1000*15, fptr)!=NULL) { - char *data = buf; - for (int l=0; lall_states[index].rad_fits[k].te[l], &offset); - data += offset; - } - } - if (fgets(buf, 1000*15, fptr) !=NULL) { - char *data2 = buf; - for (int l=0; lall_states[index].rad_fits[k].Lz[l], &offset); - data2 += offset; - } - } - } - } + charge_state = charge_state - 1; // convert to based 0 array + if (density_intervals > 0) { + int index = atomic_number * max_charge_state + charge_state; + rad_data->all_states[index].number_of_densities = density_intervals; + rad_data->all_states[index].state_exists = true; + rad_data->all_states[index].electron_densities = + gkyl_array_new(GKYL_DOUBLE, 1, density_intervals); + rad_data->all_states[index].rad_fits = (struct rad_fit_parameters *)malloc( + density_intervals * sizeof(struct rad_fit_parameters) + ); + char buf[1000 * 15]; + for (int k = 0; k < density_intervals; k++) { + double *ne = gkyl_array_fetch(rad_data->all_states[index].electron_densities, k); + if (fgets(buf, 1000 * 15, fptr) == NULL) { + rad_data->all_states[index].number_of_densities = + rad_data->all_states[index].number_of_densities - 1; + ne[0] = 0; + } else { + sscanf( + buf, "%lf%lf%lf%lf%lf%lf%d", &ne[0], &rad_data->all_states[index].rad_fits[k].A, + &rad_data->all_states[index].rad_fits[k].alpha, + &rad_data->all_states[index].rad_fits[k].beta, + &rad_data->all_states[index].rad_fits[k].V0, + &rad_data->all_states[index].rad_fits[k].gamma, + &rad_data->all_states[index].rad_fits[k].te_intervals + ); + int te_intervals = rad_data->all_states[index].rad_fits[k].te_intervals; + rad_data->all_states[index].rad_fits[k].te = + (double *)malloc(te_intervals * sizeof(double)); + rad_data->all_states[index].rad_fits[k].Lz = + (double *)malloc(te_intervals * sizeof(double)); + int offset = 0; + if (fgets(buf, 1000 * 15, fptr) != NULL) { + char *data = buf; + for (int l = 0; l < te_intervals; l++) { + sscanf(data, " %lf%n", &rad_data->all_states[index].rad_fits[k].te[l], &offset); + data += offset; + } + } + if (fgets(buf, 1000 * 15, fptr) != NULL) { + char *data2 = buf; + for (int l = 0; l < te_intervals; l++) { + sscanf(data2, " %lf%n", &rad_data->all_states[index].rad_fits[k].Lz[l], &offset); + data2 += offset; + } + } + } + } } } } @@ -119,57 +125,77 @@ gkyl_radiation_read_rad_fit_params() return rad_data; } -int -gkyl_radiation_read_get_num_densities(const struct all_radiation_states rad_data, - int atomic_z, int charge_state, double min_ne, double max_ne, int *num_densities) +int gkyl_radiation_read_get_num_densities( + const struct all_radiation_states rad_data, int atomic_z, int charge_state, double min_ne, + double max_ne, int *num_densities +) { - atomic_z = atomic_z-1; - int index = atomic_z*rad_data.max_atomic_number+charge_state; - if (rad_data.all_states[index].number_of_densitiesmax_atomic_number; - for (int i=0; iall_states[i*max_Z+j].state_exists) { - gkyl_array_release(rad_data->all_states[i*max_Z+j].electron_densities); - for (int k=0; kall_states[i*max_Z+j].number_of_densities; k++){ - free(rad_data->all_states[i*max_Z+j].rad_fits[k].te); - free(rad_data->all_states[i*max_Z+j].rad_fits[k].Lz); - } + for (int i = 0; i < max_Z; i++) { + for (int j = 0; j < max_Z; j++) { + if (rad_data->all_states[i * max_Z + j].state_exists) { + gkyl_array_release(rad_data->all_states[i * max_Z + j].electron_densities); + for (int k = 0; k < rad_data->all_states[i * max_Z + j].number_of_densities; k++) { + free(rad_data->all_states[i * max_Z + j].rad_fits[k].te); + free(rad_data->all_states[i * max_Z + j].rad_fits[k].Lz); + } } - free(rad_data->all_states[i*max_Z+j].rad_fits); + free(rad_data->all_states[i * max_Z + j].rad_fits); } } free(rad_data->all_states); diff --git a/gyrokinetic/zero/rz_calc_derived_geo.c b/gyrokinetic/zero/rz_calc_derived_geo.c index cb0ab31f07..4ccddc7c6d 100644 --- a/gyrokinetic/zero/rz_calc_derived_geo.c +++ b/gyrokinetic/zero/rz_calc_derived_geo.c @@ -6,8 +6,9 @@ #include #include -gkyl_rz_calc_derived_geo* -gkyl_rz_calc_derived_geo_new(const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, int node_type, bool use_gpu) +gkyl_rz_calc_derived_geo *gkyl_rz_calc_derived_geo_new( + const struct gkyl_basis *cbasis, const struct gkyl_rect_grid *grid, int node_type, bool use_gpu +) { gkyl_rz_calc_derived_geo *up = gkyl_malloc(sizeof(gkyl_rz_calc_derived_geo)); up->cdim = cbasis->ndim; @@ -20,12 +21,13 @@ gkyl_rz_calc_derived_geo_new(const struct gkyl_basis *cbasis, const struct gkyl_ return up; } - -void -gkyl_rz_calc_derived_geo_advance(const gkyl_rz_calc_derived_geo *up, const struct gkyl_range *crange, - struct gkyl_array *g_ij, struct gkyl_array *bmag, struct gkyl_array *jacobgeo, struct gkyl_array *jacobgeo_inv, - struct gkyl_array *gij, struct gkyl_array *b_i, struct gkyl_array *cmag, struct gkyl_array *jacobtot, struct gkyl_array *jacobtot_inv, - struct gkyl_array *gxxj, struct gkyl_array *gxyj, struct gkyl_array *gyyj, struct gkyl_array *gxzj, struct gkyl_array *eps2) +void gkyl_rz_calc_derived_geo_advance( + const gkyl_rz_calc_derived_geo *up, const struct gkyl_range *crange, struct gkyl_array *g_ij, + struct gkyl_array *bmag, struct gkyl_array *jacobgeo, struct gkyl_array *jacobgeo_inv, + struct gkyl_array *gij, struct gkyl_array *b_i, struct gkyl_array *cmag, + struct gkyl_array *jacobtot, struct gkyl_array *jacobtot_inv, struct gkyl_array *gxxj, + struct gkyl_array *gxyj, struct gkyl_array *gyyj, struct gkyl_array *gxzj, struct gkyl_array *eps2 +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, crange); @@ -40,18 +42,19 @@ gkyl_rz_calc_derived_geo_advance(const gkyl_rz_calc_derived_geo *up, const struc double *cmag_i = gkyl_array_fetch(cmag, loc); double *jacobtot_i = gkyl_array_fetch(jacobtot, loc); double *jacobtot_inv_i = gkyl_array_fetch(jacobtot_inv, loc); - double *gxxj_i= gkyl_array_fetch(gxxj, loc); - double *gxyj_i= gkyl_array_fetch(gxyj, loc); - double *gyyj_i= gkyl_array_fetch(gyyj, loc); - double *gxzj_i= gkyl_array_fetch(gxzj, loc); - double *eps2_i= gkyl_array_fetch(eps2, loc); - up->kernel(g_ij_i, bmag_i, jacobgeo_i, jacobgeo_inv_i, gij_i, bi_i, cmag_i, jacobtot_i, jacobtot_inv_i, - gxxj_i, gxyj_i, gyyj_i, gxzj_i, eps2_i); + double *gxxj_i = gkyl_array_fetch(gxxj, loc); + double *gxyj_i = gkyl_array_fetch(gxyj, loc); + double *gyyj_i = gkyl_array_fetch(gyyj, loc); + double *gxzj_i = gkyl_array_fetch(gxzj, loc); + double *eps2_i = gkyl_array_fetch(eps2, loc); + up->kernel( + g_ij_i, bmag_i, jacobgeo_i, jacobgeo_inv_i, gij_i, bi_i, cmag_i, jacobtot_i, jacobtot_inv_i, + gxxj_i, gxyj_i, gyyj_i, gxzj_i, eps2_i + ); } } -void -gkyl_rz_calc_derived_geo_release(gkyl_rz_calc_derived_geo* up) +void gkyl_rz_calc_derived_geo_release(gkyl_rz_calc_derived_geo *up) { gkyl_free(up); } diff --git a/gyrokinetic/zero/tok_geo.c b/gyrokinetic/zero/tok_geo.c index 173e3c32ca..849ca0f315 100644 --- a/gyrokinetic/zero/tok_geo.c +++ b/gyrokinetic/zero/tok_geo.c @@ -16,18 +16,19 @@ #include #include -double -tok_plate_psi_func(double s, void *ctx){ +double tok_plate_psi_func(double s, void *ctx) +{ // uses a pointer to the plate function to get R(s), Z(s) // Then calculates psi(R, Z) // will be used by ridders later - + struct plate_ctx *gc = ctx; double RZ[2]; - if(gc->lower==true) + if (gc->lower == true) { gc->geo->plate_func_lower(s, RZ); - else + } else { gc->geo->plate_func_upper(s, RZ); + } double R = RZ[0]; double Z = RZ[1]; @@ -38,29 +39,33 @@ tok_plate_psi_func(double s, void *ctx){ double psi; gc->geo->efit->evf->eval_cubic(0.0, xn, &psi, gc->geo->efit->evf->ctx); return psi - gc->psi_curr; - } - else { + } else { int rzidx[2]; - rzidx[0] = fmin(gc->geo->rzlocal.lower[0] + (int) floor((R - gc->geo->rzgrid.lower[0])/gc->geo->rzgrid.dx[0]), gc->geo->rzlocal.upper[0]); - rzidx[1] = fmin(gc->geo->rzlocal.lower[1] + (int) floor((Z - gc->geo->rzgrid.lower[1])/gc->geo->rzgrid.dx[1]), gc->geo->rzlocal.upper[1]); + rzidx[0] = fmin( + gc->geo->rzlocal.lower[0] + + (int)floor((R - gc->geo->rzgrid.lower[0]) / gc->geo->rzgrid.dx[0]), + gc->geo->rzlocal.upper[0] + ); + rzidx[1] = fmin( + gc->geo->rzlocal.lower[1] + + (int)floor((Z - gc->geo->rzgrid.lower[1]) / gc->geo->rzgrid.dx[1]), + gc->geo->rzlocal.upper[1] + ); long loc = gkyl_range_idx(&gc->geo->rzlocal, rzidx); - const double *coeffs = gkyl_array_cfetch(gc->geo->psiRZ,loc); + const double *coeffs = gkyl_array_cfetch(gc->geo->psiRZ, loc); double xc[2]; gkyl_rect_grid_cell_center(&gc->geo->rzgrid, rzidx, xc); double xy[2]; - xy[0] = (R-xc[0])/(gc->geo->rzgrid.dx[0]*0.5); - xy[1] = (Z-xc[1])/(gc->geo->rzgrid.dx[1]*0.5); + xy[0] = (R - xc[0]) / (gc->geo->rzgrid.dx[0] * 0.5); + xy[1] = (Z - xc[1]) / (gc->geo->rzgrid.dx[1] * 0.5); double psi = gc->geo->rzbasis.eval_expand(xy, coeffs); return psi - gc->psi_curr; } } - - // Function to pass to root-finder to find Z location for given arc-length -static inline double -arc_length_func(double Z, void *ctx) +static inline double arc_length_func(double Z, void *ctx) { struct arc_length_ctx *actx = ctx; double *arc_memo; @@ -68,103 +73,125 @@ arc_length_func(double Z, void *ctx) double zmax = actx->zmax; double ival = 0.0; - if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_CORE){ - if(actx->right==true){ + if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) { + if (actx->right == true) { double *arc_memo = actx->arc_memo_right; - ival = integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, true, false, arc_memo) - arcL; - } - else{ + ival = + integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, true, false, arc_memo) - arcL; + } else { double *arc_memo = actx->arc_memo_left; - ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, true, false, arc_memo) - arcL + actx->arcL_right; + ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, true, false, arc_memo) - + arcL + actx->arcL_right; } } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_CORE_L || actx->ftype==GKYL_GEOMETRY_TOKAMAK_CORE_R){ - if(actx->pre==true){ - ival = actx->arcL_start - integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo) - arcL ; - } - else if(actx->right==true){ + else if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R) { + if (actx->pre == true) { + ival = actx->arcL_start - + integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo) - + arcL; + } else if (actx->right == true) { double *arc_memo = actx->arc_memo_right; - ival = integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, true, false, arc_memo) - arcL + actx->arcL_start; - } - else{ + ival = integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, true, false, arc_memo) - + arcL + actx->arcL_start; + } else { double *arc_memo = actx->arc_memo_left; - ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, true, false, arc_memo) - arcL + actx->arcL_right + actx->arcL_start; + ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, true, false, arc_memo) - + arcL + actx->arcL_right + actx->arcL_start; } } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_PF_LO_L || actx->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R){ - if(actx->right==true){ + else if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R) { + if (actx->right == true) { double *arc_memo = actx->arc_memo_right; - ival = integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, true, false, arc_memo) - arcL; - } - else{ + ival = + integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, true, false, arc_memo) - arcL; + } else { double *arc_memo = actx->arc_memo_left; - ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, true, false, arc_memo) - arcL + actx->arcL_right; + ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, true, false, arc_memo) - + arcL + actx->arcL_right; } } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_PF_UP_L || actx->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R){ - if(actx->right==false){ + else if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_L || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R) { + if (actx->right == false) { double *arc_memo = actx->arc_memo_left; - ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, true, false, arc_memo) - arcL; - } - else{ + ival = + integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, true, false, arc_memo) - arcL; + } else { double *arc_memo = actx->arc_memo_right; - ival = integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, true, false, arc_memo) - arcL + actx->arcL_left; + ival = integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, true, false, arc_memo) - + arcL + actx->arcL_left; } } - else if( (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT) || (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO) || (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID) || (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP) ){ + else if ((actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT) || + (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO) || + (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID) || + (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP)) { double *arc_memo = actx->arc_memo; - ival = integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, true, false, arc_memo) - arcL; - } - else if( (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN) || (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN) || (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO) || (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) || (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP) ){ + ival = + integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, true, false, arc_memo) - arcL; + } else if ((actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN) || + (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN) || + (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO) || + (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) || + (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP)) { double *arc_memo = actx->arc_memo; - ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, true, false, arc_memo) - arcL; + ival = + integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, true, false, arc_memo) - arcL; } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_LSN_SOL || actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP){ - if(actx->right==true){ + else if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP) { + if (actx->right == true) { double *arc_memo = actx->arc_memo_right; - ival = integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo) - arcL; - } - else{ + ival = + integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo) - arcL; + } else { double *arc_memo = actx->arc_memo_left; - ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo) - arcL + actx->arcL_right; + ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo) - + arcL + actx->arcL_right; } } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_IWL){ - if(actx->q3) { + else if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_IWL) { + if (actx->q3) { double *arc_memo = actx->arc_memo; - ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo) - arcL; - } - else if (actx->q4) { + ival = + integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo) - arcL; + } else if (actx->q4) { double *arc_memo = actx->arc_memo; - ival = integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo) - arcL + actx->arcL_q3; - } - else if (actx->q1) { + ival = integrate_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo) - + arcL + actx->arcL_q3; + } else if (actx->q1) { double *arc_memo = actx->arc_memo; - ival = integrate_psi_contour_memo(actx->geo, psi, actx->geo->zmaxis, Z, rclose, false, false, arc_memo) - arcL + actx->arcL_q3 +actx->arcL_q4; - } - else { + ival = integrate_psi_contour_memo( + actx->geo, psi, actx->geo->zmaxis, Z, rclose, false, false, arc_memo + ) - + arcL + actx->arcL_q3 + actx->arcL_q4; + } else { double *arc_memo = actx->arc_memo; - ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo) - arcL + actx->arcL_q3 +actx->arcL_q4 + actx->arcL_q1; + ival = integrate_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo) - + arcL + actx->arcL_q3 + actx->arcL_q4 + actx->arcL_q1; } - } return ival; } // Function to calculate phi given alpha -double -phi_func(double alpha_curr, double Z, void *ctx) +double phi_func(double alpha_curr, double Z, void *ctx) { struct arc_length_ctx *actx = ctx; double *arc_memo = actx->arc_memo; - double psi = actx->psi, rclose = actx->rclose, zmin = actx->zmin, arcL = actx->arcL, zmax = actx->zmax; + double psi = actx->psi, rclose = actx->rclose, zmin = actx->zmin, arcL = actx->arcL, + zmax = actx->zmax; // Here we will abandon conventions about alpha and phi except for full core and full SN cases // The convention for phi only affects b_x - it does not affect any quantities used in axisymmetric simulations @@ -172,103 +199,158 @@ phi_func(double alpha_curr, double Z, void *ctx) // The idea for axisymmetry is that I am avoiding starting integrals at the x-point to minimize issues double ival = 0; double phi_ref = 0.0; - if (actx->ftype==GKYL_GEOMETRY_TOKAMAK_CORE){ // phi = alpha at outboard midplane - if(actx->right==true){ - if(Zzmaxis) - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo); - else - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo); - } - else{ - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, actx->zmax, rclose, false, false, arc_memo); + if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) { // phi = alpha at outboard midplane + if (actx->right == true) { + if (Z < actx->zmaxis) { + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo + ); + } else { + ival = integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo + ); + } + } else { + ival = integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, actx->zmax, rclose, false, false, arc_memo + ); phi_ref = actx->phi_right; } - } - else if (actx->ftype==GKYL_GEOMETRY_TOKAMAK_CORE_L){ // alpha = phi at inboard midplane - if(Zzmaxis) - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo); - else - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo); + } else if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L) { // alpha = phi at inboard midplane + if (Z < actx->zmaxis) { + ival = integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo + ); + } else { + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo + ); + } } - else if (actx->ftype==GKYL_GEOMETRY_TOKAMAK_CORE_R){ // alpha = phi at outboard midplane - if(Zzmaxis) - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo); - else - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo); + else if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R) { // alpha = phi at outboard midplane + if (Z < actx->zmaxis) { + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo + ); + } else { + ival = integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo + ); + } } - else if( (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT) || (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID)){ // alpha = phi at outboard midplane - if (Zzmaxis) - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo); - else - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo); - } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO){ // alpha = phi at lower plate and increases towards xpt - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo); - } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP){ //alpha = phi at upper plate and decreases towards xpt - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo); - } - if( (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN) || (actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) ){ // alpha = phi at inboard midplane - if (Zzmaxis) - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo); - else - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo); - } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO){ // alpha = phi at lower plate and decreases towards xpt - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo); - } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP){// alpha = phi at upper plate and increases towards xpt - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo); + else if ((actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT) || + (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID + )) { // alpha = phi at outboard midplane + if (Z < actx->zmaxis) { + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo + ); + } else { + ival = integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo + ); + } + } else if (actx->ftype == + GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO) { // alpha = phi at lower plate and increases towards xpt + ival = + integrate_phi_along_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo); + } else if (actx->ftype == + GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP) { //alpha = phi at upper plate and decreases towards xpt + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, zmax, rclose, false, false, arc_memo + ); } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_LSN_SOL || actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID){ - // alpha = phi at outboard midplane - if (actx->right==true){ - if (Zzmaxis) - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo); - else - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo); + if ((actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN) || + (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID)) { // alpha = phi at inboard midplane + if (Z < actx->zmaxis) { + ival = integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo + ); + } else { + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo + ); } - else{ - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, actx->zmax, rclose, false, false, arc_memo); + } else if (actx->ftype == + GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO) { // alpha = phi at lower plate and decreases towards xpt + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, zmin, Z, rclose, false, false, arc_memo + ); + } else if (actx->ftype == + GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP) { // alpha = phi at upper plate and increases towards xpt + ival = + integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo); + } else if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID) { + // alpha = phi at outboard midplane + if (actx->right == true) { + if (Z < actx->zmaxis) { + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo + ); + } else { + ival = integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo + ); + } + } else { + ival = integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, actx->zmax, rclose, false, false, arc_memo + ); phi_ref = actx->phi_right; } - } - else if(actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO){ //alpha = phi at outer plate and increases towards xpt - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo); - } - else if(actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP){ //alpha = phi at inner plate and decreases towards xpt - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo); - } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_PF_LO_R){ // alpha = phi at outer plate and increases towards xpt - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo); - } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_PF_LO_L){ //alpha = phi at inner plate and decreases towards xpt - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo); - } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_PF_UP_R){ // alpha = phi at outer plate and decreases towards Xpt - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo); - } - else if(actx->ftype==GKYL_GEOMETRY_TOKAMAK_PF_UP_L){ // alpha = phi at inner plate and increases towards xpt - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo); - } - else if (actx->ftype==GKYL_GEOMETRY_TOKAMAK_IWL) { + } else if (actx->ftype == + GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO) { //alpha = phi at outer plate and increases towards xpt + ival = + integrate_phi_along_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo); + } else if (actx->ftype == + GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP) { //alpha = phi at inner plate and decreases towards xpt + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, zmin, Z, rclose, false, false, arc_memo + ); + } else if (actx->ftype == + GKYL_GEOMETRY_TOKAMAK_PF_LO_R) { // alpha = phi at outer plate and increases towards xpt + ival = + integrate_phi_along_psi_contour_memo(actx->geo, psi, zmin, Z, rclose, false, false, arc_memo); + } else if (actx->ftype == + GKYL_GEOMETRY_TOKAMAK_PF_LO_L) { //alpha = phi at inner plate and decreases towards xpt + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, zmin, Z, rclose, false, false, arc_memo + ); + } else if (actx->ftype == + GKYL_GEOMETRY_TOKAMAK_PF_UP_R) { // alpha = phi at outer plate and decreases towards Xpt + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, zmax, rclose, false, false, arc_memo + ); + } else if (actx->ftype == + GKYL_GEOMETRY_TOKAMAK_PF_UP_L) { // alpha = phi at inner plate and increases towards xpt + ival = + integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, zmax, rclose, false, false, arc_memo); + } else if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_IWL) { // phi = alpha at outboard midplane - if(actx->right==true){ - if(Zzmaxis) - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo); - else - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo); - } - else{ - if (Zzmaxis) { - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmin, Z, rclose, false, false, arc_memo) ; - phi_ref = -actx->phi_right; + if (actx->right == true) { + if (Z < actx->zmaxis) { + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, actx->zmaxis, rclose, false, false, arc_memo + ); + } else { + ival = integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmaxis, Z, rclose, false, false, arc_memo + ); } - else { - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, Z, actx->zmax, rclose, false, false, arc_memo) ; - phi_ref = actx->phi_right; + } else { + if (Z < actx->zmaxis) { + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmin, Z, rclose, false, false, arc_memo + ); + phi_ref = -actx->phi_right; + } else { + ival = integrate_phi_along_psi_contour_memo( + actx->geo, psi, Z, actx->zmax, rclose, false, false, arc_memo + ); + phi_ref = actx->phi_right; } } } @@ -280,16 +362,22 @@ phi_func(double alpha_curr, double Z, void *ctx) int nr = gkyl_tok_geo_R_psiZ(actx->geo, psi, Z, 4, R, dRdZ, dR, dZ); double r_curr = nr == 1 ? R[0] : choose_closest(rclose, R, R, nr); double psi_fpol = psi; - if ( (psi_fpol < actx->geo->fgrid.lower[0]) || (psi_fpol > actx->geo->fgrid.upper[0]) ) // F = F(psi_sep) in the SOL. + if ((psi_fpol < actx->geo->fgrid.lower[0]) || + (psi_fpol > actx->geo->fgrid.upper[0])) { // F = F(psi_sep) in the SOL. psi_fpol = actx->geo->sibry; - int idx = fmin(actx->geo->frange.lower[0] + (int) floor((psi_fpol - actx->geo->fgrid.lower[0])/actx->geo->fgrid.dx[0]), actx->geo->frange.upper[0]); + } + int idx = fmin( + actx->geo->frange.lower[0] + + (int)floor((psi_fpol - actx->geo->fgrid.lower[0]) / actx->geo->fgrid.dx[0]), + actx->geo->frange.upper[0] + ); long loc = gkyl_range_idx(&actx->geo->frange, &idx); - const double *coeffs = gkyl_array_cfetch(actx->geo->fpoldg,loc); + const double *coeffs = gkyl_array_cfetch(actx->geo->fpoldg, loc); double fxc; gkyl_rect_grid_cell_center(&actx->geo->fgrid, &idx, &fxc); - double fx = (psi_fpol-fxc)/(actx->geo->fgrid.dx[0]*0.5); + double fx = (psi_fpol - fxc) / (actx->geo->fgrid.dx[0] * 0.5); double fpol = actx->geo->fbasis.eval_expand(&fx, coeffs); - ival = ival*fpol; + ival = ival * fpol; //while(ival < -M_PI){ // ival +=2*M_PI; @@ -300,60 +388,88 @@ phi_func(double alpha_curr, double Z, void *ctx) return alpha_curr + ival + phi_ref; } -double -qprofile_func(void *ctx) +double qprofile_func(void *ctx) { // Function to calculate the flux surface averaged q profile. struct arc_length_ctx *actx = ctx; double *arc_memo = actx->arc_memo; - double psi = actx->psi, rclose = actx->rclose, zmin = actx->zmin, arcL = actx->arcL, zmax = actx->zmax; - double rleft = actx->rleft, rright = actx->rright; + double psi = actx->psi, rclose = actx->rclose, zmin = actx->zmin, arcL = actx->arcL, + zmax = actx->zmax; + double rleft = actx->rleft, rright = actx->rright; // Calculate q(psi) = -F(psi)/2pi * integral_zmin^zmax 1/Rgrad(psi). double ival = 0; double phi_ref = 0.0; if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) { - double ival1 = integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmin, actx->zmax, rright, false, false, arc_memo); - double ival2 = -integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmin, actx->zmax, rleft, false, false, arc_memo); + double ival1 = integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmin, actx->zmax, rright, false, false, arc_memo + ); + double ival2 = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmin, actx->zmax, rleft, false, false, arc_memo + ); ival = ival1 + ival2; } if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_IWL) { - double ival1 = integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmin, actx->zmax, rright, false, false, arc_memo); - double ival2 = -integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmin, actx->zmax, rleft, false, false, arc_memo); + double ival1 = integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmin, actx->zmax, rright, false, false, arc_memo + ); + double ival2 = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmin, actx->zmax, rleft, false, false, arc_memo + ); ival = ival1 + ival2; } if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL) { - double ival1 = integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmin_right, actx->zmax, rright, false, false, arc_memo); - double ival2 = -integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmin_left, actx->zmax, rleft, false, false, arc_memo); + double ival1 = integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmin_right, actx->zmax, rright, false, false, arc_memo + ); + double ival2 = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmin_left, actx->zmax, rleft, false, false, arc_memo + ); ival = ival1 + ival2; } - if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT || actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID || actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO || actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP){ - ival = integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmin, actx->zmax, rclose, false, false, arc_memo); + if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP) { + ival = integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmin, actx->zmax, rclose, false, false, arc_memo + ); } - if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN || actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID || actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO || actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP) { - ival = -integrate_phi_along_psi_contour_memo(actx->geo, psi, actx->zmin, actx->zmax, rclose, false, false, arc_memo); + if (actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO || + actx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP) { + ival = -integrate_phi_along_psi_contour_memo( + actx->geo, psi, actx->zmin, actx->zmax, rclose, false, false, arc_memo + ); } // Now multiply by fpol/2pi. double R[4] = {0}; double dR[4] = {0}; double psi_fpol = psi; - if ( (psi_fpol < actx->geo->fgrid.lower[0]) || (psi_fpol > actx->geo->fgrid.upper[0]) ) // F = F(psi_sep) in the SOL. + if ((psi_fpol < actx->geo->fgrid.lower[0]) || + (psi_fpol > actx->geo->fgrid.upper[0])) { // F = F(psi_sep) in the SOL. psi_fpol = actx->geo->sibry; - int idx = fmin(actx->geo->frange.lower[0] + (int) floor((psi_fpol - actx->geo->fgrid.lower[0])/actx->geo->fgrid.dx[0]), actx->geo->frange.upper[0]); + } + int idx = fmin( + actx->geo->frange.lower[0] + + (int)floor((psi_fpol - actx->geo->fgrid.lower[0]) / actx->geo->fgrid.dx[0]), + actx->geo->frange.upper[0] + ); long loc = gkyl_range_idx(&actx->geo->frange, &idx); - const double *coeffs = gkyl_array_cfetch(actx->geo->fpoldg,loc); + const double *coeffs = gkyl_array_cfetch(actx->geo->fpoldg, loc); double fxc; gkyl_rect_grid_cell_center(&actx->geo->fgrid, &idx, &fxc); - double fx = (psi_fpol-fxc)/(actx->geo->fgrid.dx[0]*0.5); + double fx = (psi_fpol - fxc) / (actx->geo->fgrid.dx[0] * 0.5); double fpol = actx->geo->fbasis.eval_expand(&fx, coeffs); - double qout = -ival*fpol/M_PI; + double qout = -ival * fpol / M_PI; // AS 1/15/25: The 3 lines below are a useful check to compare against q from efit. //coeffs = gkyl_array_cfetch(actx->geo->qdg,loc); @@ -363,21 +479,16 @@ qprofile_func(void *ctx) return qout; } -static double -dphidtheta_func(double Z, void *ctx) +static double dphidtheta_func(double Z, void *ctx) { struct arc_length_ctx *actx = ctx; double *arc_memo = actx->arc_memo; - double psi = actx->psi, rclose = actx->rclose, zmin = actx->zmin, arcL = actx->arcL, zmax = actx->zmax; + double psi = actx->psi, rclose = actx->rclose, zmin = actx->zmin, arcL = actx->arcL, + zmax = actx->zmax; // Get the integrand double integrand = 0.0; - struct contour_ctx cctx = { - .geo = actx->geo, - .psi = psi, - .ncall = 0, - .last_R = rclose - }; + struct contour_ctx cctx = {.geo = actx->geo, .psi = psi, .ncall = 0, .last_R = rclose}; integrand = dphidtheta_integrand(Z, &cctx); // Now multiply by fpol double R[4] = {0}; @@ -387,57 +498,70 @@ dphidtheta_func(double Z, void *ctx) int nr = gkyl_tok_geo_R_psiZ(actx->geo, psi, Z, 4, R, dRdZ, dR, dZ); double r_curr = nr == 1 ? R[0] : choose_closest(rclose, R, R, nr); double psi_fpol = psi; - if ( (psi_fpol < actx->geo->fgrid.lower[0]) || (psi_fpol > actx->geo->fgrid.upper[0]) ) // F = F(psi_sep) in the SOL. + if ((psi_fpol < actx->geo->fgrid.lower[0]) || + (psi_fpol > actx->geo->fgrid.upper[0])) { // F = F(psi_sep) in the SOL. psi_fpol = actx->geo->sibry; - int idx = fmin(actx->geo->frange.lower[0] + (int) floor((psi_fpol - actx->geo->fgrid.lower[0])/actx->geo->fgrid.dx[0]), actx->geo->frange.upper[0]); + } + int idx = fmin( + actx->geo->frange.lower[0] + + (int)floor((psi_fpol - actx->geo->fgrid.lower[0]) / actx->geo->fgrid.dx[0]), + actx->geo->frange.upper[0] + ); long loc = gkyl_range_idx(&actx->geo->frange, &idx); - const double *coeffs = gkyl_array_cfetch(actx->geo->fpoldg,loc); + const double *coeffs = gkyl_array_cfetch(actx->geo->fpoldg, loc); double fxc; gkyl_rect_grid_cell_center(&actx->geo->fgrid, &idx, &fxc); - double fx = (psi_fpol-fxc)/(actx->geo->fgrid.dx[0]*0.5); + double fx = (psi_fpol - fxc) / (actx->geo->fgrid.dx[0] * 0.5); double fpol = actx->geo->fbasis.eval_expand(&fx, coeffs); - integrand = integrand*fpol; - integrand = integrand*actx->arcL_tot/2/M_PI; + integrand = integrand * fpol; + integrand = integrand * actx->arcL_tot / 2 / M_PI; return integrand; } -static double -bmag_func(double r_curr, double Z, void *ctx) +static double bmag_func(double r_curr, double Z, void *ctx) { struct arc_length_ctx *actx = ctx; double *arc_memo = actx->arc_memo; - double psi = actx->psi, rclose = actx->rclose, zmin = actx->zmin, arcL = actx->arcL, zmax = actx->zmax; + double psi = actx->psi, rclose = actx->rclose, zmin = actx->zmin, arcL = actx->arcL, + zmax = actx->zmax; // Calculate fpol double psi_fpol = psi; - if ( (psi_fpol < actx->geo->fgrid.lower[0]) || (psi_fpol > actx->geo->fgrid.upper[0]) ) // F = F(psi_sep) in the SOL. + if ((psi_fpol < actx->geo->fgrid.lower[0]) || + (psi_fpol > actx->geo->fgrid.upper[0])) { // F = F(psi_sep) in the SOL. psi_fpol = actx->geo->sibry; - int idx = fmin(actx->geo->frange.lower[0] + (int) floor((psi_fpol - actx->geo->fgrid.lower[0])/actx->geo->fgrid.dx[0]), actx->geo->frange.upper[0]); + } + int idx = fmin( + actx->geo->frange.lower[0] + + (int)floor((psi_fpol - actx->geo->fgrid.lower[0]) / actx->geo->fgrid.dx[0]), + actx->geo->frange.upper[0] + ); long loc = gkyl_range_idx(&actx->geo->frange, &idx); - const double *coeffs = gkyl_array_cfetch(actx->geo->fpoldg,loc); + const double *coeffs = gkyl_array_cfetch(actx->geo->fpoldg, loc); double fxc; gkyl_rect_grid_cell_center(&actx->geo->fgrid, &idx, &fxc); - double fx = (psi_fpol-fxc)/(actx->geo->fgrid.dx[0]*0.5); + double fx = (psi_fpol - fxc) / (actx->geo->fgrid.dx[0] * 0.5); double fpol = actx->geo->fbasis.eval_expand(&fx, coeffs); - double Bphi = fpol/r_curr; + double Bphi = fpol / r_curr; double Br = 0.0, Bz = 0.0, bmag = 0.0; if (actx->geo->use_cubics) { - double xn[2] = {r_curr, Z}; - double fout[3]; - actx->geo->efit->evf->eval_cubic_wgrad(0.0, xn, fout, actx->geo->efit->evf->ctx); - double dpsidR = fout[1]; - double dpsidZ = fout[2]; - - Br = 1.0/r_curr*dpsidZ; - Bz = -1.0/r_curr*dpsidR; - } - else { + double xn[2] = {r_curr, Z}; + double fout[3]; + actx->geo->efit->evf->eval_cubic_wgrad(0.0, xn, fout, actx->geo->efit->evf->ctx); + double dpsidR = fout[1]; + double dpsidZ = fout[2]; + + Br = 1.0 / r_curr * dpsidZ; + Bz = -1.0 / r_curr * dpsidR; + } else { int rzidx[2]; - int idxtemp = actx->geo->rzlocal.lower[0] + (int) floor((r_curr - actx->geo->rzgrid.lower[0])/actx->geo->rzgrid.dx[0]); + int idxtemp = actx->geo->rzlocal.lower[0] + + (int)floor((r_curr - actx->geo->rzgrid.lower[0]) / actx->geo->rzgrid.dx[0]); idxtemp = GKYL_MIN2(idxtemp, actx->geo->rzlocal.upper[0]); idxtemp = GKYL_MAX2(idxtemp, actx->geo->rzlocal.lower[0]); rzidx[0] = idxtemp; - idxtemp = actx->geo->rzlocal.lower[1] + (int) floor((Z - actx->geo->rzgrid.lower[1])/actx->geo->rzgrid.dx[1]); + idxtemp = actx->geo->rzlocal.lower[1] + + (int)floor((Z - actx->geo->rzgrid.lower[1]) / actx->geo->rzgrid.dx[1]); idxtemp = GKYL_MIN2(idxtemp, actx->geo->rzlocal.upper[1]); idxtemp = GKYL_MAX2(idxtemp, actx->geo->rzlocal.lower[1]); rzidx[1] = idxtemp; @@ -447,17 +571,23 @@ bmag_func(double r_curr, double Z, void *ctx) double xc[2]; gkyl_rect_grid_cell_center((&actx->geo->rzgrid), rzidx, xc); - double x = (r_curr-xc[0])/(actx->geo->rzgrid.dx[0]*0.5); - double y = (Z-xc[1])/(actx->geo->rzgrid.dx[1]*0.5); - - double dpsidx = 5.625*psih[8]*(2.0*x*SQ(y)-0.6666666666666666*x)+2.904737509655563*psih[7]*(SQ(y)-0.3333333333333333)+5.809475019311126*psih[6]*x*y+1.5*psih[3]*y+3.354101966249684*psih[4]*x+0.8660254037844386*psih[1]; - double dpsidy = 5.625*psih[8]*(2.0*SQ(x)*y-0.6666666666666666*y)+5.809475019311126*psih[7]*x*y+3.354101966249684*psih[5]*y+2.904737509655563*psih[6]*(SQ(x)-0.3333333333333333)+1.5*psih[3]*x+0.8660254037844386*psih[2]; - double dpsidR = dpsidx*2.0/actx->geo->rzgrid.dx[0]; - double dpsidZ = dpsidy*2.0/actx->geo->rzgrid.dx[1]; - Br = 1.0/r_curr*dpsidZ; - Bz = -1.0/r_curr*dpsidR; + double x = (r_curr - xc[0]) / (actx->geo->rzgrid.dx[0] * 0.5); + double y = (Z - xc[1]) / (actx->geo->rzgrid.dx[1] * 0.5); + + double dpsidx = 5.625 * psih[8] * (2.0 * x * SQ(y) - 0.6666666666666666 * x) + + 2.904737509655563 * psih[7] * (SQ(y) - 0.3333333333333333) + + 5.809475019311126 * psih[6] * x * y + 1.5 * psih[3] * y + + 3.354101966249684 * psih[4] * x + 0.8660254037844386 * psih[1]; + double dpsidy = 5.625 * psih[8] * (2.0 * SQ(x) * y - 0.6666666666666666 * y) + + 5.809475019311126 * psih[7] * x * y + 3.354101966249684 * psih[5] * y + + 2.904737509655563 * psih[6] * (SQ(x) - 0.3333333333333333) + 1.5 * psih[3] * x + + 0.8660254037844386 * psih[2]; + double dpsidR = dpsidx * 2.0 / actx->geo->rzgrid.dx[0]; + double dpsidZ = dpsidy * 2.0 / actx->geo->rzgrid.dx[1]; + Br = 1.0 / r_curr * dpsidZ; + Bz = -1.0 / r_curr * dpsidR; } - bmag = sqrt(Br*Br+Bz*Bz+Bphi*Bphi); + bmag = sqrt(Br * Br + Bz * Bz + Bphi * Bphi); return bmag; } @@ -469,22 +599,27 @@ curlbhat_func(double psi, double r_curr, double Z, double phi, double *curlbhat, // Calculate fpol and fpolprime // First get the location on the flux grid double psi_fpol = psi; - if ( (psi_fpol < actx->geo->fgrid.lower[0]) || (psi_fpol > actx->geo->fgrid.upper[0]) ) // F = F(psi_sep) in the SOL. + if ((psi_fpol < actx->geo->fgrid.lower[0]) || + (psi_fpol > actx->geo->fgrid.upper[0])) { // F = F(psi_sep) in the SOL. psi_fpol = actx->geo->sibry; - int idx = fmin(actx->geo->frange.lower[0] + (int) floor((psi_fpol - actx->geo->fgrid.lower[0])/actx->geo->fgrid.dx[0]), actx->geo->frange.upper[0]); + } + int idx = fmin( + actx->geo->frange.lower[0] + + (int)floor((psi_fpol - actx->geo->fgrid.lower[0]) / actx->geo->fgrid.dx[0]), + actx->geo->frange.upper[0] + ); long loc = gkyl_range_idx(&actx->geo->frange, &idx); - const double *coeffs = gkyl_array_cfetch(actx->geo->fpoldg,loc); + const double *coeffs = gkyl_array_cfetch(actx->geo->fpoldg, loc); double fxc; gkyl_rect_grid_cell_center(&actx->geo->fgrid, &idx, &fxc); - double fx = (psi_fpol-fxc)/(actx->geo->fgrid.dx[0]*0.5); - // Second calculate fpol and bphi + double fx = (psi_fpol - fxc) / (actx->geo->fgrid.dx[0] * 0.5); + // Second calculate fpol and bphi double fpol = actx->geo->fbasis.eval_expand(&fx, coeffs); - double Bphi = fpol/r_curr; + double Bphi = fpol / r_curr; // Third calculate fpolprime - coeffs = gkyl_array_cfetch(actx->geo->fpolprimedg,loc); + coeffs = gkyl_array_cfetch(actx->geo->fpolprimedg, loc); double fpolprime = actx->geo->fbasis.eval_expand(&fx, coeffs); - // Now calculate psi's various derivatives double Br = 0.0, Bz = 0.0, bmag = 0.0; double dpsidR = 0.0, dpsidZ = 0.0; @@ -503,14 +638,15 @@ curlbhat_func(double psi, double r_curr, double Z, double phi, double *curlbhat, d2psidR2 = fout[1]; d2psidZ2 = fout[2]; d2psidRdZ = fout[3]; - } - else { + } else { int rzidx[2]; - int idxtemp = actx->geo->rzlocal.lower[0] + (int) floor((r_curr - actx->geo->rzgrid.lower[0])/actx->geo->rzgrid.dx[0]); + int idxtemp = actx->geo->rzlocal.lower[0] + + (int)floor((r_curr - actx->geo->rzgrid.lower[0]) / actx->geo->rzgrid.dx[0]); idxtemp = GKYL_MIN2(idxtemp, actx->geo->rzlocal.upper[0]); idxtemp = GKYL_MAX2(idxtemp, actx->geo->rzlocal.lower[0]); rzidx[0] = idxtemp; - idxtemp = actx->geo->rzlocal.lower[1] + (int) floor((Z - actx->geo->rzgrid.lower[1])/actx->geo->rzgrid.dx[1]); + idxtemp = actx->geo->rzlocal.lower[1] + + (int)floor((Z - actx->geo->rzgrid.lower[1]) / actx->geo->rzgrid.dx[1]); idxtemp = GKYL_MIN2(idxtemp, actx->geo->rzlocal.upper[1]); idxtemp = GKYL_MAX2(idxtemp, actx->geo->rzlocal.lower[1]); rzidx[1] = idxtemp; @@ -520,41 +656,52 @@ curlbhat_func(double psi, double r_curr, double Z, double phi, double *curlbhat, double xc[2]; gkyl_rect_grid_cell_center((&actx->geo->rzgrid), rzidx, xc); - double x = (r_curr-xc[0])/(actx->geo->rzgrid.dx[0]*0.5); - double y = (Z-xc[1])/(actx->geo->rzgrid.dx[1]*0.5); - - double dpsidx = 5.625*psih[8]*(2.0*x*SQ(y)-0.6666666666666666*x)+2.904737509655563*psih[7]*(SQ(y)-0.3333333333333333)+5.809475019311126*psih[6]*x*y+1.5*psih[3]*y+3.354101966249684*psih[4]*x+0.8660254037844386*psih[1]; - double dpsidy = 5.625*psih[8]*(2.0*SQ(x)*y-0.6666666666666666*y)+5.809475019311126*psih[7]*x*y+3.354101966249684*psih[5]*y+2.904737509655563*psih[6]*(SQ(x)-0.3333333333333333)+1.5*psih[3]*x+0.8660254037844386*psih[2]; - dpsidR = dpsidx*2.0/actx->geo->rzgrid.dx[0]; - dpsidZ = dpsidy*2.0/actx->geo->rzgrid.dx[1]; - double d2psidx2 = 11.25*psih[8]*y*y+5.809475019311125*psih[6]*y-3.75*psih[8]+3.354101966249685*psih[4]; - double d2psidy2 = 11.25*psih[8]*x*x+5.809475019311125*psih[7]*x-3.75*psih[8]+3.354101966249685*psih[5]; - double d2psidxdy = 22.5*psih[8]*x*y+5.809475019311125*psih[7]*y+5.809475019311125*psih[6]*x+1.5*psih[3]; - d2psidR2 = d2psidx2*(2.0/actx->geo->rzgrid.dx[0])*(2.0/actx->geo->rzgrid.dx[0]); - d2psidZ2 = d2psidy2*(2.0/actx->geo->rzgrid.dx[1])*(2.0/actx->geo->rzgrid.dx[1]); - d2psidRdZ = d2psidxdy*(2.0/actx->geo->rzgrid.dx[0])*(2.0/actx->geo->rzgrid.dx[1]); + double x = (r_curr - xc[0]) / (actx->geo->rzgrid.dx[0] * 0.5); + double y = (Z - xc[1]) / (actx->geo->rzgrid.dx[1] * 0.5); + + double dpsidx = 5.625 * psih[8] * (2.0 * x * SQ(y) - 0.6666666666666666 * x) + + 2.904737509655563 * psih[7] * (SQ(y) - 0.3333333333333333) + + 5.809475019311126 * psih[6] * x * y + 1.5 * psih[3] * y + + 3.354101966249684 * psih[4] * x + 0.8660254037844386 * psih[1]; + double dpsidy = 5.625 * psih[8] * (2.0 * SQ(x) * y - 0.6666666666666666 * y) + + 5.809475019311126 * psih[7] * x * y + 3.354101966249684 * psih[5] * y + + 2.904737509655563 * psih[6] * (SQ(x) - 0.3333333333333333) + 1.5 * psih[3] * x + + 0.8660254037844386 * psih[2]; + dpsidR = dpsidx * 2.0 / actx->geo->rzgrid.dx[0]; + dpsidZ = dpsidy * 2.0 / actx->geo->rzgrid.dx[1]; + double d2psidx2 = 11.25 * psih[8] * y * y + 5.809475019311125 * psih[6] * y - 3.75 * psih[8] + + 3.354101966249685 * psih[4]; + double d2psidy2 = 11.25 * psih[8] * x * x + 5.809475019311125 * psih[7] * x - 3.75 * psih[8] + + 3.354101966249685 * psih[5]; + double d2psidxdy = 22.5 * psih[8] * x * y + 5.809475019311125 * psih[7] * y + + 5.809475019311125 * psih[6] * x + 1.5 * psih[3]; + d2psidR2 = d2psidx2 * (2.0 / actx->geo->rzgrid.dx[0]) * (2.0 / actx->geo->rzgrid.dx[0]); + d2psidZ2 = d2psidy2 * (2.0 / actx->geo->rzgrid.dx[1]) * (2.0 / actx->geo->rzgrid.dx[1]); + d2psidRdZ = d2psidxdy * (2.0 / actx->geo->rzgrid.dx[0]) * (2.0 / actx->geo->rzgrid.dx[1]); } - Br = 1.0/r_curr*dpsidZ; - Bz = -1.0/r_curr*dpsidR; - bmag = sqrt(Br*Br+Bz*Bz+Bphi*Bphi); + Br = 1.0 / r_curr * dpsidZ; + Bz = -1.0 / r_curr * dpsidR; + bmag = sqrt(Br * Br + Bz * Bz + Bphi * Bphi); - dBrdR = 1.0/r_curr*d2psidRdZ; - dBrdZ = 1.0/r_curr*d2psidZ2; - dBzdR = -1.0/r_curr*d2psidR2; - dBzdZ = -1.0/r_curr*d2psidRdZ; + dBrdR = 1.0 / r_curr * d2psidRdZ; + dBrdZ = 1.0 / r_curr * d2psidZ2; + dBzdR = -1.0 / r_curr * d2psidR2; + dBzdZ = -1.0 / r_curr * d2psidRdZ; - - double dFdR = fpolprime*dpsidR; - double dFdZ = fpolprime*dpsidZ; - dBdR = 1/bmag*(Br*dBrdR + Bz*dBzdR + fpol/r_curr*(dFdR/r_curr - fpol/r_curr/r_curr)); - dBdZ = 1/bmag*(Br*dBrdZ + Bz*dBzdZ + fpol/r_curr*dFdZ); + double dFdR = fpolprime * dpsidR; + double dFdZ = fpolprime * dpsidZ; + dBdR = + 1 / bmag * (Br * dBrdR + Bz * dBzdR + fpol / r_curr * (dFdR / r_curr - fpol / r_curr / r_curr)); + dBdZ = 1 / bmag * (Br * dBrdZ + Bz * dBzdZ + fpol / r_curr * dFdZ); // Get the polar components (contravariant, upperscript components on tangent basis) double polar_comp[3] = {0.0}; - polar_comp[0] = 1.0/bmag*-1.0/r_curr*dFdZ - 1.0/bmag*1.0/bmag*dBdZ*fpol/r_curr; // R component ^1 - polar_comp[1] = 1.0/bmag*1.0/r_curr*(dBrdZ - dBzdR) + (-dBdR*Bz/r_curr + dBdZ*Br/r_curr); // Phi component ^2 - polar_comp[2] = 1.0/bmag*1.0/r_curr*dFdR + 1.0/bmag*1.0/bmag*dBdR*fpol/r_curr; + polar_comp[0] = 1.0 / bmag * -1.0 / r_curr * dFdZ - + 1.0 / bmag * 1.0 / bmag * dBdZ * fpol / r_curr; // R component ^1 + polar_comp[1] = 1.0 / bmag * 1.0 / r_curr * (dBrdZ - dBzdR) + + (-dBdR * Bz / r_curr + dBdZ * Br / r_curr); // Phi component ^2 + polar_comp[2] = 1.0 / bmag * 1.0 / r_curr * dFdR + 1.0 / bmag * 1.0 / bmag * dBdR * fpol / r_curr; // Convert to cartesian curlbhat[0] = polar_comp[0] * cos(phi) - polar_comp[1] * sin(phi) * r_curr; @@ -562,16 +709,11 @@ curlbhat_func(double psi, double r_curr, double Z, double phi, double *curlbhat, curlbhat[2] = polar_comp[2]; } - - - - - -struct gkyl_tok_geo* +struct gkyl_tok_geo * gkyl_tok_geo_new(const struct gkyl_efit_inp *inp, const struct gkyl_tok_geo_grid_inp *ginp) { struct gkyl_tok_geo *geo = gkyl_malloc(sizeof(*geo)); - *geo = (struct gkyl_tok_geo) {}; + *geo = (struct gkyl_tok_geo){}; geo->efit = gkyl_efit_new(inp); @@ -595,69 +737,65 @@ gkyl_tok_geo_new(const struct gkyl_efit_inp *inp, const struct gkyl_tok_geo_grid geo->fbasis = geo->efit->fluxbasis; geo->frange = geo->efit->fluxlocal; geo->frange_ext = geo->efit->fluxlocal_ext; - geo->fpoldg= gkyl_array_acquire(geo->efit->fpolflux); - geo->fpolprimedg= gkyl_array_acquire(geo->efit->fpolprimeflux); - geo->qdg= gkyl_array_acquire(geo->efit->qflux); + geo->fpoldg = gkyl_array_acquire(geo->efit->fpolflux); + geo->fpolprimedg = gkyl_array_acquire(geo->efit->fpolprimeflux); + geo->qdg = gkyl_array_acquire(geo->efit->qflux); geo->sibry = geo->efit->sibry; geo->psisep = geo->efit->psisep; geo->zmaxis = geo->efit->zmaxis; geo->use_cubics = ginp->use_cubics; geo->use_hyperbolic_numbers = ginp->use_hyperbolic_numbers; - geo->root_param.eps = - ginp->root_param.eps > 0 ? ginp->root_param.eps : 1e-10; - geo->root_param.max_iter = - ginp->root_param.max_iter > 0 ? ginp->root_param.max_iter : 100; + geo->root_param.eps = ginp->root_param.eps > 0 ? ginp->root_param.eps : 1e-10; + geo->root_param.max_iter = ginp->root_param.max_iter > 0 ? ginp->root_param.max_iter : 100; - geo->quad_param.max_level = - ginp->quad_param.max_levels > 0 ? ginp->quad_param.max_levels : 10; - geo->quad_param.eps = - ginp->quad_param.eps > 0 ? ginp->quad_param.eps : 1e-10; + geo->quad_param.max_level = ginp->quad_param.max_levels > 0 ? ginp->quad_param.max_levels : 10; + geo->quad_param.eps = ginp->quad_param.eps > 0 ? ginp->quad_param.eps : 1e-10; if (geo->use_cubics) { - if(geo->use_hyperbolic_numbers) + if (geo->use_hyperbolic_numbers) { geo->calc_roots = calc_RdR_p3_hyperbolic; - else + } else { geo->calc_roots = calc_RdR_p3; + } geo->calc_grad_psi = calc_grad_psi_p3; - } - else if (geo->efit->rzbasis.poly_order == 1) { + } else if (geo->efit->rzbasis.poly_order == 1) { geo->calc_roots = calc_RdR_p1; geo->calc_grad_psi = calc_grad_psi_p1; - } - else if (geo->efit->rzbasis.poly_order == 2){ + } else if (geo->efit->rzbasis.poly_order == 2) { geo->calc_roots = calc_RdR_p2_tensor_nrc; geo->calc_grad_psi = calc_grad_psi_p2_tensor; } - geo->stat = (struct gkyl_tok_geo_stat) { }; + geo->stat = (struct gkyl_tok_geo_stat){}; - return geo; } -double -gkyl_tok_geo_integrate_psi_contour(const struct gkyl_tok_geo *geo, double psi, - double zmin, double zmax, double rclose) +double gkyl_tok_geo_integrate_psi_contour( + const struct gkyl_tok_geo *geo, double psi, double zmin, double zmax, double rclose +) { - return integrate_psi_contour_memo(geo, psi, zmin, zmax, rclose, - false, false, 0); + return integrate_psi_contour_memo(geo, psi, zmin, zmax, rclose, false, false, 0); } -int -gkyl_tok_geo_R_psiZ(const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, - double *R, double *dRdZ, double *dR, double *dZ) +int gkyl_tok_geo_R_psiZ( + const struct gkyl_tok_geo *geo, double psi, double Z, int nmaxroots, double *R, double *dRdZ, + double *dR, double *dZ +) { - if(geo->use_cubics) + if (geo->use_cubics) { return R_psiZ_cubic(geo, psi, Z, nmaxroots, R, dRdZ, dR, dZ); - else + } else { return R_psiZ(geo, psi, Z, nmaxroots, R, dRdZ, dR, dZ); + } } -void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, struct gkyl_tok_geo *geo, - struct gkyl_tok_geo_grid_inp *inp, struct gkyl_position_map *position_map) +void gkyl_tok_geo_calc( + struct gk_geometry *up, struct gkyl_range *nrange, struct gkyl_tok_geo *geo, + struct gkyl_tok_geo_grid_inp *inp, struct gkyl_position_map *position_map +) { - geo->rleft = inp->rleft; geo->rright = inp->rright; @@ -668,27 +806,32 @@ void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, struct enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { X_IDX, Y_IDX, Z_IDX }; // arrangement of cartesian coordinates - - double dtheta = inp->cgrid.dx[TH_IDX], - dpsi = inp->cgrid.dx[PSI_IDX], - dalpha = inp->cgrid.dx[AL_IDX]; - - double theta_lo = up->grid.lower[TH_IDX] + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX])*up->grid.dx[TH_IDX], - psi_lo = up->grid.lower[PSI_IDX] + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX])*up->grid.dx[PSI_IDX], - alpha_lo = up->grid.lower[AL_IDX] + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX])*up->grid.dx[AL_IDX]; - - double dx_fact = up->basis.poly_order == 1.0/up->basis.poly_order; - dtheta *= dx_fact; dpsi *= dx_fact; dalpha *= dx_fact; + + double dtheta = inp->cgrid.dx[TH_IDX], dpsi = inp->cgrid.dx[PSI_IDX], + dalpha = inp->cgrid.dx[AL_IDX]; + + double theta_lo = up->grid.lower[TH_IDX] + + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX]) * up->grid.dx[TH_IDX], + psi_lo = up->grid.lower[PSI_IDX] + + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX]) * up->grid.dx[PSI_IDX], + alpha_lo = up->grid.lower[AL_IDX] + + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX]) * up->grid.dx[AL_IDX]; + + double dx_fact = up->basis.poly_order == 1.0 / up->basis.poly_order; + dtheta *= dx_fact; + dpsi *= dx_fact; + dalpha *= dx_fact; double rclose = inp->rclose; double rright = inp->rright; double rleft = inp->rleft; int nzcells; - if(geo->use_cubics) + if (geo->use_cubics) { nzcells = geo->rzgrid_cubic.cells[1]; - else + } else { nzcells = geo->rzgrid.cells[1]; + } double *arc_memo = gkyl_malloc(sizeof(double[nzcells])); double *arc_memo_left = gkyl_malloc(sizeof(double[nzcells])); double *arc_memo_right = gkyl_malloc(sizeof(double[nzcells])); @@ -701,20 +844,18 @@ void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, struct .ftype = inp->ftype, .zmaxis = geo->zmaxis }; - struct plate_ctx pctx = { - .geo = geo - }; + struct plate_ctx pctx = {.geo = geo}; - int cidx[3] = { 0 }; - for (int ia=nrange->lower[AL_IDX]; ia<=nrange->lower[AL_IDX]+1; ++ia){ + int cidx[3] = {0}; + for (int ia = nrange->lower[AL_IDX]; ia <= nrange->lower[AL_IDX] + 1; ++ia) { cidx[AL_IDX] = ia; - double alpha_curr = alpha_lo + ia*dalpha; + double alpha_curr = alpha_lo + ia * dalpha; - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { - double psi_curr = psi_lo + ip*dpsi; + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { + double psi_curr = psi_lo + ip * dpsi; // Non-uniform psi. Finite differences are calculated in calc_metric.c - position_map->maps[0](0.0, &psi_curr, &psi_curr, position_map->ctxs[0]); + position_map->maps[0](0.0, &psi_curr, &psi_curr, position_map->ctxs[0]); double darcL, arcL_curr, arcL_lo; @@ -723,21 +864,23 @@ void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, struct // For a full core case: // also set phi_right and arcL_right // For a single null case: - // also set zmin_left and zmin_right - tok_find_endpoints(inp, geo, &arc_ctx, &pctx, psi_curr, alpha_curr, arc_memo, arc_memo_left, arc_memo_right); + // also set zmin_left and zmin_right + tok_find_endpoints( + inp, geo, &arc_ctx, &pctx, psi_curr, alpha_curr, arc_memo, arc_memo_left, arc_memo_right + ); - darcL = arc_ctx.arcL_tot/(up->basis.poly_order*inp->cgrid.cells[TH_IDX]) - * (inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX])/2/M_PI; + darcL = arc_ctx.arcL_tot / (up->basis.poly_order * inp->cgrid.cells[TH_IDX]) * + (inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX]) / 2 / M_PI; // At the beginning of each theta loop we need to reset things. cidx[PSI_IDX] = ip; arcL_curr = 0.0; - arcL_lo = (theta_lo + M_PI)/2/M_PI*arc_ctx.arcL_tot; + arcL_lo = (theta_lo + M_PI) / 2 / M_PI * arc_ctx.arcL_tot; double ridders_min, ridders_max; // Set node coordinates. - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { int it_delta = 0; - arcL_curr = arcL_lo + it*darcL; - double theta_curr = arcL_curr*(2*M_PI/arc_ctx.arcL_tot) - M_PI ; + arcL_curr = arcL_lo + it * darcL; + double theta_curr = arcL_curr * (2 * M_PI / arc_ctx.arcL_tot) - M_PI; // Calculate derivatives using finite difference for ddtheta, // as well as transform the computational coordiante to the non-uniform field-aligned value @@ -745,74 +888,110 @@ void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, struct // We cannot do non-uniform alpha because we are modeling axisymmetric systems // Non-uniform theta double Theta_curr; - position_map->maps[2](0.0, &theta_curr, &Theta_curr, position_map->ctxs[2]); + position_map->maps[2](0.0, &theta_curr, &Theta_curr, position_map->ctxs[2]); theta_curr = Theta_curr; - arcL_curr = (theta_curr + M_PI) / (2*M_PI/arc_ctx.arcL_tot); + arcL_curr = (theta_curr + M_PI) / (2 * M_PI / arc_ctx.arcL_tot); tok_set_ridders(inp, &arc_ctx, psi_curr, arcL_curr, &rclose, &ridders_min, &ridders_max); - struct gkyl_qr_res res = gkyl_ridders(arc_length_func, &arc_ctx, - arc_ctx.zmin, arc_ctx.zmax, ridders_min, ridders_max, - geo->root_param.max_iter, 1e-10); + struct gkyl_qr_res res = gkyl_ridders( + arc_length_func, &arc_ctx, arc_ctx.zmin, arc_ctx.zmax, ridders_min, ridders_max, + geo->root_param.max_iter, 1e-10 + ); double z_curr = res.res; ((struct gkyl_tok_geo *)geo)->stat.nroot_cont_calls += res.nevals; if (inp->half_domain) { //Alternative for half domain if (psi_curr == geo->psisep) { - if (it == nrange->upper[TH_IDX] && (up->local.upper[TH_IDX]== up->global.upper[TH_IDX])) { - if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L || inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO|| inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) + if (it == nrange->upper[TH_IDX] && + (up->local.upper[TH_IDX] == up->global.upper[TH_IDX])) { + if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) { z_curr = geo->efit->Zxpt[0]; - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) { z_curr = geo->efit->Zxpt[0]; + } } - if (it == nrange->lower[TH_IDX] && (up->local.lower[TH_IDX]== up->global.lower[TH_IDX])) { - if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID|| inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO) + if (it == nrange->lower[TH_IDX] && + (up->local.lower[TH_IDX] == up->global.lower[TH_IDX])) { + if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO) { z_curr = geo->efit->Zxpt[0]; - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP || inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) { z_curr = geo->efit->Zxpt[0]; + } } } - } - else { // For full domain + } else { // For full domain if (psi_curr == geo->psisep) { - if (it == nrange->upper[TH_IDX] && (up->local.upper[TH_IDX]== up->global.upper[TH_IDX])) { - if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_L || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID || inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP) + if (it == nrange->upper[TH_IDX] && + (up->local.upper[TH_IDX] == up->global.upper[TH_IDX])) { + if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_L || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP) { z_curr = geo->efit->Zxpt[1]; - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L || inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO|| inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) { z_curr = geo->efit->Zxpt[0]; - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) { z_curr = geo->efit->Zxpt[0]; + } } - if (it == nrange->lower[TH_IDX] && (up->local.lower[TH_IDX]== up->global.lower[TH_IDX])) { - if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L || inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP|| inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) + if (it == nrange->lower[TH_IDX] && + (up->local.lower[TH_IDX] == up->global.lower[TH_IDX])) { + if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) { z_curr = geo->efit->Zxpt[1]; - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID|| inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO) + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO) { z_curr = geo->efit->Zxpt[0]; - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP || inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) { z_curr = geo->efit->Zxpt[0]; + } } } } // Ensure that node at the lower Xpt (lower end of right core/upper end of left core) is at the same location if (psi_curr != geo->psisep) { - if (it == nrange->upper[TH_IDX] && inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L && up->local.upper[TH_IDX]== up->global.upper[TH_IDX]) { + if (it == nrange->upper[TH_IDX] && inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L && + up->local.upper[TH_IDX] == up->global.upper[TH_IDX]) { z_curr = arc_ctx.zmin; } - if (it == nrange->lower[TH_IDX] && inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R && up->local.lower[TH_IDX]== up->global.lower[TH_IDX]) { + if (it == nrange->lower[TH_IDX] && inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R && + up->local.lower[TH_IDX] == up->global.lower[TH_IDX]) { z_curr = arc_ctx.zmin; } } - double R[4] = { 0 }, dRdZ[4] = { 0 }; - double dR[4] = { 0 }, dZ[4] = { 0 }; + double R[4] = {0}, dRdZ[4] = {0}; + double dR[4] = {0}, dZ[4] = {0}; int nr = gkyl_tok_geo_R_psiZ(geo, psi_curr, z_curr, 4, R, dRdZ, dR, dZ); double r_curr = choose_closest(rclose, R, R, nr); double drdz_curr = choose_closest(rclose, R, dRdZ, nr); double dr_curr = choose_closest(rclose, R, dR, nr); double dz_curr = choose_closest(rclose, R, dZ, nr); - if (psi_curr==geo->psisep) { + if (psi_curr == geo->psisep) { if (z_curr == geo->efit->Zxpt[0]) { nr = 1; r_curr = geo->efit->Rxpt[0]; @@ -823,9 +1002,12 @@ void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, struct } } - if (nr==0) { + if (nr == 0) { printf(" ip = %d, it = %d, ia = %d\n", ip, it, ia); - printf("Block Type = %d | Failed to find a root at psi = %g, Z = %1.16f\n", inp->ftype, psi_curr, z_curr); + printf( + "Block Type = %d | Failed to find a root at psi = %g, Z = %1.16f\n", inp->ftype, + psi_curr, z_curr + ); assert(false); } @@ -834,7 +1016,8 @@ void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, struct double phi_curr = phi_func(alpha_curr, z_curr, &arc_ctx); double *mc2p_n = gkyl_array_fetch(up->geo_corn.mc2p_nodal, gkyl_range_idx(nrange, cidx)); - double *mc2nu_n = gkyl_array_fetch(up->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(nrange, cidx)); + double *mc2nu_n = + gkyl_array_fetch(up->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(nrange, cidx)); double *bmag_n = gkyl_array_fetch(up->geo_corn.bmag_nodal, gkyl_range_idx(nrange, cidx)); mc2p_n[X_IDX] = r_curr; @@ -849,28 +1032,32 @@ void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, struct } // Populate other alpha indices by using axisymmetry - for (int ia=nrange->lower[AL_IDX]+1; ia<=nrange->upper[AL_IDX]; ++ia){ + for (int ia = nrange->lower[AL_IDX] + 1; ia <= nrange->upper[AL_IDX]; ++ia) { cidx[AL_IDX] = ia; - double alpha_curr = alpha_lo + ia*dalpha; - double alpha_donor = alpha_lo + nrange->lower[AL_IDX]*dalpha; - double alpha_diff = alpha_curr - alpha_donor; - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { + double alpha_curr = alpha_lo + ia * dalpha; + double alpha_donor = alpha_lo + nrange->lower[AL_IDX] * dalpha; + double alpha_diff = alpha_curr - alpha_donor; + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { cidx[PSI_IDX] = ip; - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { cidx[TH_IDX] = it; double *mc2p_n = gkyl_array_fetch(up->geo_corn.mc2p_nodal, gkyl_range_idx(nrange, cidx)); - double *mc2nu_n = gkyl_array_fetch(up->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(nrange, cidx)); + double *mc2nu_n = + gkyl_array_fetch(up->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(nrange, cidx)); double *bmag_n = gkyl_array_fetch(up->geo_corn.bmag_nodal, gkyl_range_idx(nrange, cidx)); - int donor_cidx[3] ; + int donor_cidx[3]; donor_cidx[AL_IDX] = nrange->lower[AL_IDX]; donor_cidx[PSI_IDX] = ip; donor_cidx[TH_IDX] = it; - double *donor_mc2p_n = gkyl_array_fetch(up->geo_corn.mc2p_nodal, gkyl_range_idx(nrange, donor_cidx)); - double *donor_mc2nu_n = gkyl_array_fetch(up->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(nrange, donor_cidx)); - double *donor_bmag_n = gkyl_array_fetch(up->geo_corn.bmag_nodal, gkyl_range_idx(nrange, donor_cidx)); + double *donor_mc2p_n = + gkyl_array_fetch(up->geo_corn.mc2p_nodal, gkyl_range_idx(nrange, donor_cidx)); + double *donor_mc2nu_n = + gkyl_array_fetch(up->geo_corn.mc2nu_pos_nodal, gkyl_range_idx(nrange, donor_cidx)); + double *donor_bmag_n = + gkyl_array_fetch(up->geo_corn.bmag_nodal, gkyl_range_idx(nrange, donor_cidx)); mc2p_n[X_IDX] = donor_mc2p_n[X_IDX]; mc2p_n[Y_IDX] = donor_mc2p_n[Y_IDX]; @@ -883,10 +1070,19 @@ void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, struct } } - struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&inp->cbasis, &inp->cgrid, false); - gkyl_nodal_ops_n2m(n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 3, up->geo_corn.mc2p_nodal, up->geo_corn.mc2p, false); - gkyl_nodal_ops_n2m(n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 3, up->geo_corn.mc2nu_pos_nodal, up->geo_corn.mc2nu_pos, false); - gkyl_nodal_ops_n2m(n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 1, up->geo_corn.bmag_nodal, up->geo_corn.bmag, false); + struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&inp->cbasis, &inp->cgrid, false); + gkyl_nodal_ops_n2m( + n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 3, up->geo_corn.mc2p_nodal, + up->geo_corn.mc2p, false + ); + gkyl_nodal_ops_n2m( + n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 3, up->geo_corn.mc2nu_pos_nodal, + up->geo_corn.mc2nu_pos, false + ); + gkyl_nodal_ops_n2m( + n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 1, up->geo_corn.bmag_nodal, + up->geo_corn.bmag, false + ); gkyl_nodal_ops_release(n2m); // Need 1/B for LBO collisions, computed weakly. @@ -897,10 +1093,11 @@ void gkyl_tok_geo_calc(struct gk_geometry* up, struct gkyl_range *nrange, struct gkyl_free(arc_memo_right); } -void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrange, double dzc[3], - struct gkyl_tok_geo *geo, struct gkyl_tok_geo_grid_inp *inp, struct gkyl_position_map *position_map) +void gkyl_tok_geo_calc_interior( + struct gk_geometry *up, struct gkyl_range *nrange, double dzc[3], struct gkyl_tok_geo *geo, + struct gkyl_tok_geo_grid_inp *inp, struct gkyl_position_map *position_map +) { - geo->rleft = inp->rleft; geo->rright = inp->rright; @@ -911,27 +1108,31 @@ void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrang enum { PSI_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { X_IDX, Y_IDX, Z_IDX }; // arrangement of cartesian coordinates - - double dtheta = inp->cgrid.dx[TH_IDX], - dpsi = inp->cgrid.dx[PSI_IDX], - dalpha = inp->cgrid.dx[AL_IDX]; - - double theta_lo = up->grid.lower[TH_IDX] + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX])*up->grid.dx[TH_IDX], - psi_lo = up->grid.lower[PSI_IDX] + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX])*up->grid.dx[PSI_IDX], - alpha_lo = up->grid.lower[AL_IDX] + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX])*up->grid.dx[AL_IDX]; - - double dels[2] = {1.0/sqrt(3), 1.0-1.0/sqrt(3) }; - theta_lo = theta_lo + dels[1]*dtheta/2.0; - psi_lo = psi_lo + dels[1]*dpsi/2.0; - alpha_lo = alpha_lo + dels[1]*dalpha/2.0; - - double dx_fact = up->basis.poly_order == 1.0/up->basis.poly_order; - dtheta *= dx_fact; dpsi *= dx_fact; dalpha *= dx_fact; - - // used for finite differences - double delta_alpha = dalpha*1e-2; - double delta_psi = dpsi*1e-2; - double delta_theta = dtheta*1e-2; + + double dtheta = inp->cgrid.dx[TH_IDX], dpsi = inp->cgrid.dx[PSI_IDX], + dalpha = inp->cgrid.dx[AL_IDX]; + + double theta_lo = up->grid.lower[TH_IDX] + + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX]) * up->grid.dx[TH_IDX], + psi_lo = up->grid.lower[PSI_IDX] + + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX]) * up->grid.dx[PSI_IDX], + alpha_lo = up->grid.lower[AL_IDX] + + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX]) * up->grid.dx[AL_IDX]; + + double dels[2] = {1.0 / sqrt(3), 1.0 - 1.0 / sqrt(3)}; + theta_lo = theta_lo + dels[1] * dtheta / 2.0; + psi_lo = psi_lo + dels[1] * dpsi / 2.0; + alpha_lo = alpha_lo + dels[1] * dalpha / 2.0; + + double dx_fact = up->basis.poly_order == 1.0 / up->basis.poly_order; + dtheta *= dx_fact; + dpsi *= dx_fact; + dalpha *= dx_fact; + + // used for finite differences + double delta_alpha = dalpha * 1e-2; + double delta_psi = dpsi * 1e-2; + double delta_theta = dtheta * 1e-2; dzc[0] = delta_psi; dzc[1] = delta_alpha; dzc[2] = delta_theta; @@ -942,10 +1143,11 @@ void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrang double rleft = inp->rleft; int nzcells; - if(geo->use_cubics) + if (geo->use_cubics) { nzcells = geo->rzgrid_cubic.cells[1]; - else + } else { nzcells = geo->rzgrid.cells[1]; + } double *arc_memo = gkyl_malloc(sizeof(double[nzcells])); double *arc_memo_left = gkyl_malloc(sizeof(double[nzcells])); double *arc_memo_right = gkyl_malloc(sizeof(double[nzcells])); @@ -958,30 +1160,30 @@ void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrang .ftype = inp->ftype, .zmaxis = geo->zmaxis }; - struct plate_ctx pctx = { - .geo = geo - }; + struct plate_ctx pctx = {.geo = geo}; // Temporary array to store nodal q profile. - struct gkyl_array *qprofile_nodal = gkyl_array_new(GKYL_DOUBLE, up->geo_int.bmag_nodal->ncomp, up->geo_int.bmag_nodal->size); + struct gkyl_array *qprofile_nodal = + gkyl_array_new(GKYL_DOUBLE, up->geo_int.bmag_nodal->ncomp, up->geo_int.bmag_nodal->size); - int cidx[3] = { 0 }; - for(int ia=nrange->lower[AL_IDX]; ialower[AL_IDX]+1; ++ia){ + int cidx[3] = {0}; + for (int ia = nrange->lower[AL_IDX]; ia < nrange->lower[AL_IDX] + 1; ++ia) { cidx[AL_IDX] = ia; - double alpha_curr = calc_running_coord(alpha_lo, ia-nrange->lower[AL_IDX], dalpha); + double alpha_curr = calc_running_coord(alpha_lo, ia - nrange->lower[AL_IDX], dalpha); - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { int ip_delta_max = 3; for (int ip_delta = 0; ip_delta < ip_delta_max; ip_delta++) { - - double psi_curr = calc_running_coord(psi_lo, ip-nrange->lower[PSI_IDX], dpsi) + modifiers[ip_delta]*delta_psi; + double psi_curr = calc_running_coord(psi_lo, ip - nrange->lower[PSI_IDX], dpsi) + + modifiers[ip_delta] * delta_psi; // Non-uniform psi. Finite differences are calculated in calc_metric.c double Psi_curr; - position_map->maps[0](0.0, &psi_curr, &Psi_curr, position_map->ctxs[0]); - double dPsi_dpsi = gkyl_position_map_slope(position_map, 0, psi_curr, delta_psi, ip, nrange); + position_map->maps[0](0.0, &psi_curr, &Psi_curr, position_map->ctxs[0]); + double dPsi_dpsi = + gkyl_position_map_slope(position_map, 0, psi_curr, delta_psi, ip, nrange); psi_curr = Psi_curr; - + double darcL, arcL_curr, arcL_lo; // For double null blocks this should set arc_ctx : @@ -989,8 +1191,10 @@ void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrang // For a full core case: // also set phi_right and arcL_right // For a single null case: - // also set zmin_left and zmin_right - tok_find_endpoints(inp, geo, &arc_ctx, &pctx, psi_curr, alpha_curr, arc_memo, arc_memo_left, arc_memo_right); + // also set zmin_left and zmin_right + tok_find_endpoints( + inp, geo, &arc_ctx, &pctx, psi_curr, alpha_curr, arc_memo, arc_memo_left, arc_memo_right + ); // Calculate the q profile // qhat = - F(psi) * s(psi) / (R * grad(psi)) @@ -999,17 +1203,17 @@ void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrang // = 1/s(psi) * integral (dphidtheta) ; dphidtheta = F(psi)/(R*grad(psi)) double qprofile = qprofile_func(&arc_ctx); - darcL = arc_ctx.arcL_tot/(up->basis.poly_order*inp->cgrid.cells[TH_IDX]) - * (inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX])/2/M_PI; + darcL = arc_ctx.arcL_tot / (up->basis.poly_order * inp->cgrid.cells[TH_IDX]) * + (inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX]) / 2 / M_PI; // at the beginning of each theta loop we need to reset things cidx[PSI_IDX] = ip; arcL_curr = 0.0; - arcL_lo = (theta_lo + M_PI)/2/M_PI*arc_ctx.arcL_tot; + arcL_lo = (theta_lo + M_PI) / 2 / M_PI * arc_ctx.arcL_tot; double ridders_min, ridders_max; - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { - arcL_curr = calc_running_coord(arcL_lo, it-nrange->lower[TH_IDX], darcL); - double theta_curr = arcL_curr*(2*M_PI/arc_ctx.arcL_tot) - M_PI ; + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { + arcL_curr = calc_running_coord(arcL_lo, it - nrange->lower[TH_IDX], darcL); + double theta_curr = arcL_curr * (2 * M_PI / arc_ctx.arcL_tot) - M_PI; // Calculate derivatives using finite difference for ddtheta, // as well as transform the computational coordiante to the non-uniform field-aligned value @@ -1017,29 +1221,30 @@ void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrang // We cannot do non-uniform alpha because we are modeling axisymmetric systems // Non-uniform theta double Theta_curr; - position_map->maps[2](0.0, &theta_curr, &Theta_curr, position_map->ctxs[2]); - double dTheta_dtheta = gkyl_position_map_slope(position_map, 2, theta_curr,\ - delta_theta, it, nrange); + position_map->maps[2](0.0, &theta_curr, &Theta_curr, position_map->ctxs[2]); + double dTheta_dtheta = + gkyl_position_map_slope(position_map, 2, theta_curr, delta_theta, it, nrange); theta_curr = Theta_curr; - arcL_curr = (theta_curr + M_PI) / (2*M_PI/arc_ctx.arcL_tot); + arcL_curr = (theta_curr + M_PI) / (2 * M_PI / arc_ctx.arcL_tot); tok_set_ridders(inp, &arc_ctx, psi_curr, arcL_curr, &rclose, &ridders_min, &ridders_max); - struct gkyl_qr_res res = gkyl_ridders(arc_length_func, &arc_ctx, - arc_ctx.zmin, arc_ctx.zmax, ridders_min, ridders_max, - geo->root_param.max_iter, 1e-10); + struct gkyl_qr_res res = gkyl_ridders( + arc_length_func, &arc_ctx, arc_ctx.zmin, arc_ctx.zmax, ridders_min, ridders_max, + geo->root_param.max_iter, 1e-10 + ); double z_curr = res.res; ((struct gkyl_tok_geo *)geo)->stat.nroot_cont_calls += res.nevals; - double R[4] = { 0 }, dRdZ[4] = { 0 }; - double dR[4] = { 0 }, dZ[4] = { 0 }; + double R[4] = {0}, dRdZ[4] = {0}; + double dR[4] = {0}, dZ[4] = {0}; int nr = gkyl_tok_geo_R_psiZ(geo, psi_curr, z_curr, 4, R, dRdZ, dR, dZ); double r_curr = choose_closest(rclose, R, R, nr); double drdz_curr = choose_closest(rclose, R, dRdZ, nr); double dr_curr = choose_closest(rclose, R, dR, nr); double dz_curr = choose_closest(rclose, R, dZ, nr); - if (psi_curr==geo->psisep && ip_delta==0) { + if (psi_curr == geo->psisep && ip_delta == 0) { if (z_curr == geo->efit->Zxpt[0]) { nr = 1; r_curr = geo->efit->Rxpt[0]; @@ -1050,38 +1255,47 @@ void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrang } } - if (nr==0) { + if (nr == 0) { printf("ip = %d, it = %d, ia = %d, ip_delta = %d\n", ip, it, ia, ip_delta); - printf("Block Type = %d | Failed to find a root at psi = %g, Z = %1.16f\n", inp->ftype, psi_curr, z_curr); + printf( + "Block Type = %d | Failed to find a root at psi = %g, Z = %1.16f\n", inp->ftype, + psi_curr, z_curr + ); assert(false); } cidx[TH_IDX] = it; int lidx = 0; - if (ip_delta != 0) - lidx = 3 + 3*(ip_delta-1); + if (ip_delta != 0) { + lidx = 3 + 3 * (ip_delta - 1); + } double phi_curr = phi_func(alpha_curr, z_curr, &arc_ctx); - double *mc2p_fd_n = gkyl_array_fetch(up->geo_int.mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); - double *ddtheta_n = gkyl_array_fetch(up->geo_int.ddtheta_nodal, gkyl_range_idx(nrange, cidx)); + double *mc2p_fd_n = + gkyl_array_fetch(up->geo_int.mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); + double *ddtheta_n = + gkyl_array_fetch(up->geo_int.ddtheta_nodal, gkyl_range_idx(nrange, cidx)); double *ddpsi_n = gkyl_array_fetch(up->geo_int.ddpsi_nodal, gkyl_range_idx(nrange, cidx)); double *mc2p_n = gkyl_array_fetch(up->geo_int.mc2p_nodal, gkyl_range_idx(nrange, cidx)); double *bmag_n = gkyl_array_fetch(up->geo_int.bmag_nodal, gkyl_range_idx(nrange, cidx)); - double *curlbhat_n = gkyl_array_fetch(up->geo_int.curlbhat_nodal, gkyl_range_idx(nrange, cidx)); + double *curlbhat_n = + gkyl_array_fetch(up->geo_int.curlbhat_nodal, gkyl_range_idx(nrange, cidx)); double *qprofile_n = gkyl_array_fetch(qprofile_nodal, gkyl_range_idx(nrange, cidx)); - mc2p_fd_n[lidx+X_IDX] = r_curr; - mc2p_fd_n[lidx+Y_IDX] = z_curr; - mc2p_fd_n[lidx+Z_IDX] = phi_curr; + mc2p_fd_n[lidx + X_IDX] = r_curr; + mc2p_fd_n[lidx + Y_IDX] = z_curr; + mc2p_fd_n[lidx + Z_IDX] = phi_curr; - if(ip_delta==0){ - ddtheta_n[0] = sin(atan2(dr_curr, dz_curr))*arc_ctx.arcL_tot/2.0/M_PI*dTheta_dtheta; - ddtheta_n[1] = cos(atan2(dr_curr, dz_curr))*arc_ctx.arcL_tot/2.0/M_PI*dTheta_dtheta; - ddtheta_n[2] = dphidtheta_func(z_curr, &arc_ctx)*dTheta_dtheta; + if (ip_delta == 0) { + ddtheta_n[0] = + sin(atan2(dr_curr, dz_curr)) * arc_ctx.arcL_tot / 2.0 / M_PI * dTheta_dtheta; + ddtheta_n[1] = + cos(atan2(dr_curr, dz_curr)) * arc_ctx.arcL_tot / 2.0 / M_PI * dTheta_dtheta; + ddtheta_n[2] = dphidtheta_func(z_curr, &arc_ctx) * dTheta_dtheta; ddpsi_n[0] = dPsi_dpsi; - mc2p_n[lidx+X_IDX] = r_curr; - mc2p_n[lidx+Y_IDX] = z_curr; - mc2p_n[lidx+Z_IDX] = phi_curr; + mc2p_n[lidx + X_IDX] = r_curr; + mc2p_n[lidx + Y_IDX] = z_curr; + mc2p_n[lidx + Z_IDX] = phi_curr; bmag_n[0] = bmag_func(r_curr, z_curr, &arc_ctx); qprofile_n[0] = qprofile; curlbhat_func(psi_curr, r_curr, z_curr, phi_curr, curlbhat_n, &arc_ctx); @@ -1092,64 +1306,87 @@ void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrang } // Populate other alpha indices by using axisymmetry - for (int ia=nrange->lower[AL_IDX]+1; ia<=nrange->upper[AL_IDX]; ++ia){ + for (int ia = nrange->lower[AL_IDX] + 1; ia <= nrange->upper[AL_IDX]; ++ia) { cidx[AL_IDX] = ia; - double alpha_curr = calc_running_coord(alpha_lo, ia-nrange->lower[AL_IDX], dalpha); + double alpha_curr = calc_running_coord(alpha_lo, ia - nrange->lower[AL_IDX], dalpha); double alpha_donor = calc_running_coord(alpha_lo, 0, dalpha); - double alpha_diff = alpha_curr - alpha_donor; - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { + double alpha_diff = alpha_curr - alpha_donor; + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { cidx[PSI_IDX] = ip; int ip_delta_max = 3; - for(int ip_delta = 0; ip_delta < ip_delta_max; ip_delta++){ - double psi_curr = calc_running_coord(psi_lo, ip-nrange->lower[PSI_IDX], dpsi) + modifiers[ip_delta]*delta_psi; - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { + for (int ip_delta = 0; ip_delta < ip_delta_max; ip_delta++) { + double psi_curr = calc_running_coord(psi_lo, ip - nrange->lower[PSI_IDX], dpsi) + + modifiers[ip_delta] * delta_psi; + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { cidx[TH_IDX] = it; - int lidx = 0; - if (ip_delta != 0) - lidx = 3 + 3*(ip_delta-1); + int lidx = 0; + if (ip_delta != 0) { + lidx = 3 + 3 * (ip_delta - 1); + } - double *mc2p_fd_n = gkyl_array_fetch(up->geo_int.mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); - double *ddtheta_n = gkyl_array_fetch(up->geo_int.ddtheta_nodal, gkyl_range_idx(nrange, cidx)); + double *mc2p_fd_n = + gkyl_array_fetch(up->geo_int.mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); + double *ddtheta_n = + gkyl_array_fetch(up->geo_int.ddtheta_nodal, gkyl_range_idx(nrange, cidx)); double *ddpsi_n = gkyl_array_fetch(up->geo_int.ddpsi_nodal, gkyl_range_idx(nrange, cidx)); double *mc2p_n = gkyl_array_fetch(up->geo_int.mc2p_nodal, gkyl_range_idx(nrange, cidx)); double *bmag_n = gkyl_array_fetch(up->geo_int.bmag_nodal, gkyl_range_idx(nrange, cidx)); - double *curlbhat_n = gkyl_array_fetch(up->geo_int.curlbhat_nodal, gkyl_range_idx(nrange, cidx)); + double *curlbhat_n = + gkyl_array_fetch(up->geo_int.curlbhat_nodal, gkyl_range_idx(nrange, cidx)); - int donor_cidx[3] ; + int donor_cidx[3]; donor_cidx[AL_IDX] = nrange->lower[AL_IDX]; donor_cidx[PSI_IDX] = ip; donor_cidx[TH_IDX] = it; - double *donor_mc2p_fd_n = gkyl_array_fetch(up->geo_int.mc2p_nodal_fd, gkyl_range_idx(nrange, donor_cidx)); - double *donor_ddtheta_n = gkyl_array_fetch(up->geo_int.ddtheta_nodal, gkyl_range_idx(nrange, donor_cidx)); - double *donor_ddpsi_n = gkyl_array_fetch(up->geo_int.ddpsi_nodal, gkyl_range_idx(nrange, donor_cidx)); - double *donor_mc2p_n = gkyl_array_fetch(up->geo_int.mc2p_nodal, gkyl_range_idx(nrange, donor_cidx)); - double *donor_bmag_n = gkyl_array_fetch(up->geo_int.bmag_nodal, gkyl_range_idx(nrange, donor_cidx)); - double *donor_curlbhat_n = gkyl_array_fetch(up->geo_int.curlbhat_nodal, gkyl_range_idx(nrange, donor_cidx)); - - mc2p_fd_n[lidx+X_IDX] = donor_mc2p_fd_n[lidx+X_IDX]; - mc2p_fd_n[lidx+Y_IDX] = donor_mc2p_fd_n[lidx+Y_IDX]; - mc2p_fd_n[lidx+Z_IDX] = donor_mc2p_fd_n[lidx+Z_IDX] + alpha_diff; - if(ip_delta==0){ + double *donor_mc2p_fd_n = + gkyl_array_fetch(up->geo_int.mc2p_nodal_fd, gkyl_range_idx(nrange, donor_cidx)); + double *donor_ddtheta_n = + gkyl_array_fetch(up->geo_int.ddtheta_nodal, gkyl_range_idx(nrange, donor_cidx)); + double *donor_ddpsi_n = + gkyl_array_fetch(up->geo_int.ddpsi_nodal, gkyl_range_idx(nrange, donor_cidx)); + double *donor_mc2p_n = + gkyl_array_fetch(up->geo_int.mc2p_nodal, gkyl_range_idx(nrange, donor_cidx)); + double *donor_bmag_n = + gkyl_array_fetch(up->geo_int.bmag_nodal, gkyl_range_idx(nrange, donor_cidx)); + double *donor_curlbhat_n = + gkyl_array_fetch(up->geo_int.curlbhat_nodal, gkyl_range_idx(nrange, donor_cidx)); + + mc2p_fd_n[lidx + X_IDX] = donor_mc2p_fd_n[lidx + X_IDX]; + mc2p_fd_n[lidx + Y_IDX] = donor_mc2p_fd_n[lidx + Y_IDX]; + mc2p_fd_n[lidx + Z_IDX] = donor_mc2p_fd_n[lidx + Z_IDX] + alpha_diff; + if (ip_delta == 0) { ddtheta_n[0] = donor_ddtheta_n[0]; ddtheta_n[1] = donor_ddtheta_n[1]; ddtheta_n[2] = donor_ddtheta_n[2]; ddpsi_n[0] = donor_ddpsi_n[0]; - mc2p_n[lidx+X_IDX] = donor_mc2p_n[lidx+X_IDX]; - mc2p_n[lidx+Y_IDX] = donor_mc2p_n[lidx+Y_IDX]; - mc2p_n[lidx+Z_IDX] = donor_mc2p_n[lidx+Z_IDX] + alpha_diff; + mc2p_n[lidx + X_IDX] = donor_mc2p_n[lidx + X_IDX]; + mc2p_n[lidx + Y_IDX] = donor_mc2p_n[lidx + Y_IDX]; + mc2p_n[lidx + Z_IDX] = donor_mc2p_n[lidx + Z_IDX] + alpha_diff; bmag_n[0] = donor_bmag_n[0]; - curlbhat_func(psi_curr, mc2p_n[lidx+X_IDX], mc2p_n[lidx+Y_IDX], mc2p_n[lidx+Z_IDX], curlbhat_n, &arc_ctx); + curlbhat_func( + psi_curr, mc2p_n[lidx + X_IDX], mc2p_n[lidx + Y_IDX], mc2p_n[lidx + Z_IDX], + curlbhat_n, &arc_ctx + ); } } } } } - struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&inp->cbasis, &inp->cgrid, false); - gkyl_nodal_ops_n2m(n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 3, up->geo_int.mc2p_nodal, up->geo_int.mc2p, true); - gkyl_nodal_ops_n2m(n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 1, up->geo_int.bmag_nodal, up->geo_int.bmag, true); - gkyl_nodal_ops_n2m(n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 1, qprofile_nodal, up->geo_int.qprofile, true); + struct gkyl_nodal_ops *n2m = gkyl_nodal_ops_new(&inp->cbasis, &inp->cgrid, false); + gkyl_nodal_ops_n2m( + n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 3, up->geo_int.mc2p_nodal, up->geo_int.mc2p, + true + ); + gkyl_nodal_ops_n2m( + n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 1, up->geo_int.bmag_nodal, up->geo_int.bmag, + true + ); + gkyl_nodal_ops_n2m( + n2m, &inp->cbasis, &inp->cgrid, nrange, &up->local, 1, qprofile_nodal, up->geo_int.qprofile, + true + ); gkyl_nodal_ops_release(n2m); gkyl_array_release(qprofile_nodal); @@ -1158,10 +1395,12 @@ void gkyl_tok_geo_calc_interior(struct gk_geometry* up, struct gkyl_range *nrang gkyl_free(arc_memo_right); } -void gkyl_tok_geo_calc_surface(struct gk_geometry* up, int dir, struct gkyl_range *nrange, double dzc[3], - struct gkyl_tok_geo *geo, struct gkyl_tok_geo_grid_inp *inp, struct gkyl_position_map *position_map) +void gkyl_tok_geo_calc_surface( + struct gk_geometry *up, int dir, struct gkyl_range *nrange, double dzc[3], + struct gkyl_tok_geo *geo, struct gkyl_tok_geo_grid_inp *inp, + struct gkyl_position_map *position_map +) { - geo->rleft = inp->rleft; geo->rright = inp->rright; @@ -1172,28 +1411,31 @@ void gkyl_tok_geo_calc_surface(struct gk_geometry* up, int dir, struct gkyl_rang enum { PSI_IDX, AL_IDX, TH_IDX }; // Arrangement of computational coordinates. enum { X_IDX, Y_IDX, Z_IDX }; // Arrangement of cartesian coordinates. - - double dtheta = inp->cgrid.dx[TH_IDX], - dpsi = inp->cgrid.dx[PSI_IDX], - dalpha = inp->cgrid.dx[AL_IDX]; - - double theta_lo = up->grid.lower[TH_IDX] + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX])*up->grid.dx[TH_IDX], - psi_lo = up->grid.lower[PSI_IDX] + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX])*up->grid.dx[PSI_IDX], - alpha_lo = up->grid.lower[AL_IDX] + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX])*up->grid.dx[AL_IDX]; - - double dels[2] = {1.0/sqrt(3), 1.0-1.0/sqrt(3) }; - theta_lo += dir == 2 ? 0.0 : dels[1]*dtheta/2.0; - psi_lo += dir == 0 ? 0.0 : dels[1]*dpsi/2.0; - alpha_lo += dir == 1 ? 0. : dels[1]*dalpha/2.0; - - - double dx_fact = up->basis.poly_order == 1.0/up->basis.poly_order; - dtheta *= dx_fact; dpsi *= dx_fact; dalpha *= dx_fact; + + double dtheta = inp->cgrid.dx[TH_IDX], dpsi = inp->cgrid.dx[PSI_IDX], + dalpha = inp->cgrid.dx[AL_IDX]; + + double theta_lo = up->grid.lower[TH_IDX] + + (up->local.lower[TH_IDX] - up->global.lower[TH_IDX]) * up->grid.dx[TH_IDX], + psi_lo = up->grid.lower[PSI_IDX] + + (up->local.lower[PSI_IDX] - up->global.lower[PSI_IDX]) * up->grid.dx[PSI_IDX], + alpha_lo = up->grid.lower[AL_IDX] + + (up->local.lower[AL_IDX] - up->global.lower[AL_IDX]) * up->grid.dx[AL_IDX]; + + double dels[2] = {1.0 / sqrt(3), 1.0 - 1.0 / sqrt(3)}; + theta_lo += dir == 2 ? 0.0 : dels[1] * dtheta / 2.0; + psi_lo += dir == 0 ? 0.0 : dels[1] * dpsi / 2.0; + alpha_lo += dir == 1 ? 0. : dels[1] * dalpha / 2.0; + + double dx_fact = up->basis.poly_order == 1.0 / up->basis.poly_order; + dtheta *= dx_fact; + dpsi *= dx_fact; + dalpha *= dx_fact; // Used for finite differences. - double delta_alpha = dalpha*1e-2; - double delta_psi = dpsi*1e-2; - double delta_theta = dtheta*1e-2; + double delta_alpha = dalpha * 1e-2; + double delta_psi = dpsi * 1e-2; + double delta_theta = dtheta * 1e-2; dzc[0] = delta_psi; dzc[1] = delta_alpha; dzc[2] = delta_theta; @@ -1203,12 +1445,12 @@ void gkyl_tok_geo_calc_surface(struct gk_geometry* up, int dir, struct gkyl_rang double rright = inp->rright; double rleft = inp->rleft; - int nzcells; - if (geo->use_cubics) + if (geo->use_cubics) { nzcells = geo->rzgrid_cubic.cells[1]; - else + } else { nzcells = geo->rzgrid.cells[1]; + } double *arc_memo = gkyl_malloc(sizeof(double[nzcells])); double *arc_memo_left = gkyl_malloc(sizeof(double[nzcells])); double *arc_memo_right = gkyl_malloc(sizeof(double[nzcells])); @@ -1221,39 +1463,43 @@ void gkyl_tok_geo_calc_surface(struct gk_geometry* up, int dir, struct gkyl_rang .ftype = inp->ftype, .zmaxis = geo->zmaxis }; - struct plate_ctx pctx = { - .geo = geo - }; + struct plate_ctx pctx = {.geo = geo}; - int cidx[3] = { 0 }; - for(int ia=nrange->lower[AL_IDX]; ialower[AL_IDX]+1; ++ia){ + int cidx[3] = {0}; + for (int ia = nrange->lower[AL_IDX]; ia < nrange->lower[AL_IDX] + 1; ++ia) { cidx[AL_IDX] = ia; - double alpha_curr = dir==1 ? alpha_lo + ia*dalpha : calc_running_coord(alpha_lo, ia-nrange->lower[AL_IDX], dalpha); + double alpha_curr = dir == 1 ? alpha_lo + ia * dalpha : + calc_running_coord(alpha_lo, ia - nrange->lower[AL_IDX], dalpha); - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { int ip_delta_max = 5; - for(int ip_delta = 0; ip_delta < ip_delta_max; ip_delta++){ - if((ip == nrange->lower[PSI_IDX]) && (up->local.lower[PSI_IDX]== up->global.lower[PSI_IDX]) && dir==0){ - if(ip_delta == 1 || ip_delta == 3) + for (int ip_delta = 0; ip_delta < ip_delta_max; ip_delta++) { + if ((ip == nrange->lower[PSI_IDX]) && + (up->local.lower[PSI_IDX] == up->global.lower[PSI_IDX]) && dir == 0) { + if (ip_delta == 1 || ip_delta == 3) { continue; // one sided stencils at edge - } - else if((ip == nrange->upper[PSI_IDX]) && (up->local.upper[PSI_IDX]== up->global.upper[PSI_IDX]) && dir==0){ - if(ip_delta == 2 || ip_delta == 4) + } + } else if ((ip == nrange->upper[PSI_IDX]) && + (up->local.upper[PSI_IDX] == up->global.upper[PSI_IDX]) && dir == 0) { + if (ip_delta == 2 || ip_delta == 4) { continue; // one sided stencils at edge - } - else{ // interior - if( ip_delta == 3 || ip_delta == 4) + } + } else { // interior + if (ip_delta == 3 || ip_delta == 4) { continue; + } } - double psi_curr = dir == 0 ? psi_lo + ip*dpsi : calc_running_coord(psi_lo, ip-nrange->lower[PSI_IDX], dpsi) ; - psi_curr += modifiers[ip_delta]*delta_psi; + double psi_curr = dir == 0 ? psi_lo + ip * dpsi : + calc_running_coord(psi_lo, ip - nrange->lower[PSI_IDX], dpsi); + psi_curr += modifiers[ip_delta] * delta_psi; // Non-uniform psi. Finite differences are calculated in calc_metric.c double Psi_curr; - position_map->maps[0](0.0, &psi_curr, &Psi_curr, position_map->ctxs[0]); - double dPsi_dpsi = gkyl_position_map_slope(position_map, 0, psi_curr, delta_psi, ip, nrange); + position_map->maps[0](0.0, &psi_curr, &Psi_curr, position_map->ctxs[0]); + double dPsi_dpsi = + gkyl_position_map_slope(position_map, 0, psi_curr, delta_psi, ip, nrange); psi_curr = Psi_curr; - + double darcL, arcL_curr, arcL_lo; // For double null blocks this should set arc_ctx : @@ -1261,19 +1507,23 @@ void gkyl_tok_geo_calc_surface(struct gk_geometry* up, int dir, struct gkyl_rang // For a full core case: // also set phi_right and arcL_right // For a single null case: - // also set zmin_left and zmin_right - tok_find_endpoints(inp, geo, &arc_ctx, &pctx, psi_curr, alpha_curr, arc_memo, arc_memo_left, arc_memo_right); + // also set zmin_left and zmin_right + tok_find_endpoints( + inp, geo, &arc_ctx, &pctx, psi_curr, alpha_curr, arc_memo, arc_memo_left, arc_memo_right + ); - darcL = arc_ctx.arcL_tot/(up->basis.poly_order*inp->cgrid.cells[TH_IDX]) * (inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX])/2/M_PI; + darcL = arc_ctx.arcL_tot / (up->basis.poly_order * inp->cgrid.cells[TH_IDX]) * + (inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX]) / 2 / M_PI; // at the beginning of each theta loop we need to reset things cidx[PSI_IDX] = ip; arcL_curr = 0.0; - arcL_lo = (theta_lo + M_PI)/2/M_PI*arc_ctx.arcL_tot; + arcL_lo = (theta_lo + M_PI) / 2 / M_PI * arc_ctx.arcL_tot; double ridders_min, ridders_max; - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { - arcL_curr = dir==2 ? arcL_lo + it*darcL: calc_running_coord(arcL_lo, it-nrange->lower[TH_IDX], darcL); - double theta_curr = arcL_curr*(2*M_PI/arc_ctx.arcL_tot) - M_PI ; + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { + arcL_curr = dir == 2 ? arcL_lo + it * darcL : + calc_running_coord(arcL_lo, it - nrange->lower[TH_IDX], darcL); + double theta_curr = arcL_curr * (2 * M_PI / arc_ctx.arcL_tot) - M_PI; // Calculate derivatives using finite difference for ddtheta, // as well as transform the computational coordiante to the non-uniform field-aligned value @@ -1281,39 +1531,42 @@ void gkyl_tok_geo_calc_surface(struct gk_geometry* up, int dir, struct gkyl_rang // We cannot do non-uniform alpha because we are modeling axisymmetric systems // Non-uniform theta double Theta_curr; - position_map->maps[2](0.0, &theta_curr, &Theta_curr, position_map->ctxs[2]); - double dTheta_dtheta = gkyl_position_map_slope(position_map, 2, theta_curr,\ - delta_theta, it, nrange); + position_map->maps[2](0.0, &theta_curr, &Theta_curr, position_map->ctxs[2]); + double dTheta_dtheta = + gkyl_position_map_slope(position_map, 2, theta_curr, delta_theta, it, nrange); theta_curr = Theta_curr; - arcL_curr = (theta_curr + M_PI) / (2*M_PI/arc_ctx.arcL_tot); + arcL_curr = (theta_curr + M_PI) / (2 * M_PI / arc_ctx.arcL_tot); tok_set_ridders(inp, &arc_ctx, psi_curr, arcL_curr, &rclose, &ridders_min, &ridders_max); - struct gkyl_qr_res res = gkyl_ridders(arc_length_func, &arc_ctx, - arc_ctx.zmin, arc_ctx.zmax, ridders_min, ridders_max, - geo->root_param.max_iter, 1e-10); + struct gkyl_qr_res res = gkyl_ridders( + arc_length_func, &arc_ctx, arc_ctx.zmin, arc_ctx.zmax, ridders_min, ridders_max, + geo->root_param.max_iter, 1e-10 + ); double z_curr = res.res; ((struct gkyl_tok_geo *)geo)->stat.nroot_cont_calls += res.nevals; // Ensure that node at the lower Xpt (lower end of right core/upper end of left core) is at the same location if (psi_curr != geo->psisep) { - if (it == nrange->upper[TH_IDX] && inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L && up->local.upper[TH_IDX]== up->global.upper[TH_IDX]) { + if (it == nrange->upper[TH_IDX] && inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L && + up->local.upper[TH_IDX] == up->global.upper[TH_IDX]) { z_curr = arc_ctx.zmin; } - if (it == nrange->lower[TH_IDX] && inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R && up->local.lower[TH_IDX]== up->global.lower[TH_IDX]) { + if (it == nrange->lower[TH_IDX] && inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R && + up->local.lower[TH_IDX] == up->global.lower[TH_IDX]) { z_curr = arc_ctx.zmin; } } - double R[4] = { 0 }, dRdZ[4] = { 0 }; - double dR[4] = { 0 }, dZ[4] = { 0 }; + double R[4] = {0}, dRdZ[4] = {0}; + double dR[4] = {0}, dZ[4] = {0}; int nr = gkyl_tok_geo_R_psiZ(geo, psi_curr, z_curr, 4, R, dRdZ, dR, dZ); double r_curr = choose_closest(rclose, R, R, nr); double drdz_curr = choose_closest(rclose, R, dRdZ, nr); double dr_curr = choose_closest(rclose, R, dR, nr); double dz_curr = choose_closest(rclose, R, dZ, nr); - if (psi_curr==geo->psisep && ip_delta==0) { + if (psi_curr == geo->psisep && ip_delta == 0) { if (z_curr == geo->efit->Zxpt[0]) { nr = 1; r_curr = geo->efit->Rxpt[0]; @@ -1324,33 +1577,45 @@ void gkyl_tok_geo_calc_surface(struct gk_geometry* up, int dir, struct gkyl_rang } } - if(nr==0){ + if (nr == 0) { printf("ip = %d, it = %d, ia = %d, ip_delta = %d\n", ip, it, ia, ip_delta); - printf("Block Type = %d | Failed to find a root at psi = %g, Z = %1.16f\n", inp->ftype, psi_curr, z_curr); + printf( + "Block Type = %d | Failed to find a root at psi = %g, Z = %1.16f\n", inp->ftype, + psi_curr, z_curr + ); assert(false); } cidx[TH_IDX] = it; int lidx = 0; - if (ip_delta != 0) - lidx = 3 + 3*(ip_delta-1); + if (ip_delta != 0) { + lidx = 3 + 3 * (ip_delta - 1); + } double phi_curr = phi_func(alpha_curr, z_curr, &arc_ctx); - double *mc2p_fd_n = gkyl_array_fetch(up->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); - double *ddtheta_n = gkyl_array_fetch(up->geo_surf[dir].ddtheta_nodal, gkyl_range_idx(nrange, cidx)); - double *ddpsi_n = gkyl_array_fetch(up->geo_surf[dir].ddpsi_nodal, gkyl_range_idx(nrange, cidx)); - double *bmag_n = gkyl_array_fetch(up->geo_surf[dir].bmag_nodal, gkyl_range_idx(nrange, cidx)); - double *curlbhat_n = gkyl_array_fetch(up->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(nrange, cidx)); - double *deltats_n = gkyl_array_fetch(up->geo_surf[dir].deltats_nodal, gkyl_range_idx(nrange, cidx)); - - mc2p_fd_n[lidx+X_IDX] = r_curr; - mc2p_fd_n[lidx+Y_IDX] = z_curr; - mc2p_fd_n[lidx+Z_IDX] = phi_curr; - - if(ip_delta==0){ - ddtheta_n[0] = sin(atan2(dr_curr,dz_curr))*arc_ctx.arcL_tot/2.0/M_PI*dTheta_dtheta; - ddtheta_n[1] = cos(atan2(dr_curr,dz_curr))*arc_ctx.arcL_tot/2.0/M_PI*dTheta_dtheta; - ddtheta_n[2] = dphidtheta_func(z_curr, &arc_ctx)*dTheta_dtheta; + double *mc2p_fd_n = + gkyl_array_fetch(up->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); + double *ddtheta_n = + gkyl_array_fetch(up->geo_surf[dir].ddtheta_nodal, gkyl_range_idx(nrange, cidx)); + double *ddpsi_n = + gkyl_array_fetch(up->geo_surf[dir].ddpsi_nodal, gkyl_range_idx(nrange, cidx)); + double *bmag_n = + gkyl_array_fetch(up->geo_surf[dir].bmag_nodal, gkyl_range_idx(nrange, cidx)); + double *curlbhat_n = + gkyl_array_fetch(up->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(nrange, cidx)); + double *deltats_n = + gkyl_array_fetch(up->geo_surf[dir].deltats_nodal, gkyl_range_idx(nrange, cidx)); + + mc2p_fd_n[lidx + X_IDX] = r_curr; + mc2p_fd_n[lidx + Y_IDX] = z_curr; + mc2p_fd_n[lidx + Z_IDX] = phi_curr; + + if (ip_delta == 0) { + ddtheta_n[0] = + sin(atan2(dr_curr, dz_curr)) * arc_ctx.arcL_tot / 2.0 / M_PI * dTheta_dtheta; + ddtheta_n[1] = + cos(atan2(dr_curr, dz_curr)) * arc_ctx.arcL_tot / 2.0 / M_PI * dTheta_dtheta; + ddtheta_n[2] = dphidtheta_func(z_curr, &arc_ctx) * dTheta_dtheta; ddpsi_n[0] = dPsi_dpsi; bmag_n[0] = bmag_func(r_curr, z_curr, &arc_ctx); curlbhat_func(psi_curr, r_curr, z_curr, phi_curr, curlbhat_n, &arc_ctx); @@ -1362,64 +1627,83 @@ void gkyl_tok_geo_calc_surface(struct gk_geometry* up, int dir, struct gkyl_rang } // Populate other alpha indices by using axisymmetry - for (int ia=nrange->lower[AL_IDX]+1; ia<=nrange->upper[AL_IDX]; ++ia){ + for (int ia = nrange->lower[AL_IDX] + 1; ia <= nrange->upper[AL_IDX]; ++ia) { cidx[AL_IDX] = ia; - double alpha_curr = dir==1 ? alpha_lo + ia*dalpha : calc_running_coord(alpha_lo, ia-nrange->lower[AL_IDX], dalpha); - double alpha_donor= dir==1 ? alpha_lo + nrange->lower[AL_IDX]*dalpha : calc_running_coord(alpha_lo, 0, dalpha); - double alpha_diff = alpha_curr - alpha_donor; + double alpha_curr = dir == 1 ? alpha_lo + ia * dalpha : + calc_running_coord(alpha_lo, ia - nrange->lower[AL_IDX], dalpha); + double alpha_donor = dir == 1 ? alpha_lo + nrange->lower[AL_IDX] * dalpha : + calc_running_coord(alpha_lo, 0, dalpha); + double alpha_diff = alpha_curr - alpha_donor; - for (int ip=nrange->lower[PSI_IDX]; ip<=nrange->upper[PSI_IDX]; ++ip) { + for (int ip = nrange->lower[PSI_IDX]; ip <= nrange->upper[PSI_IDX]; ++ip) { cidx[PSI_IDX] = ip; int ip_delta_max = 5; - for(int ip_delta = 0; ip_delta < ip_delta_max; ip_delta++){ - if((ip == nrange->lower[PSI_IDX]) && (up->local.lower[PSI_IDX]== up->global.lower[PSI_IDX]) && dir==0){ - if(ip_delta == 1 || ip_delta == 3) + for (int ip_delta = 0; ip_delta < ip_delta_max; ip_delta++) { + if ((ip == nrange->lower[PSI_IDX]) && + (up->local.lower[PSI_IDX] == up->global.lower[PSI_IDX]) && dir == 0) { + if (ip_delta == 1 || ip_delta == 3) { continue; // one sided stencils at edge - } - else if((ip == nrange->upper[PSI_IDX]) && (up->local.upper[PSI_IDX]== up->global.upper[PSI_IDX]) && dir==0){ - if(ip_delta == 2 || ip_delta == 4) + } + } else if ((ip == nrange->upper[PSI_IDX]) && + (up->local.upper[PSI_IDX] == up->global.upper[PSI_IDX]) && dir == 0) { + if (ip_delta == 2 || ip_delta == 4) { continue; // one sided stencils at edge - } - else{ // interior - if( ip_delta == 3 || ip_delta == 4) + } + } else { // interior + if (ip_delta == 3 || ip_delta == 4) { continue; + } } - double psi_curr = dir == 0 ? psi_lo + ip*dpsi : calc_running_coord(psi_lo, ip-nrange->lower[PSI_IDX], dpsi) ; - psi_curr += modifiers[ip_delta]*delta_psi; + double psi_curr = dir == 0 ? psi_lo + ip * dpsi : + calc_running_coord(psi_lo, ip - nrange->lower[PSI_IDX], dpsi); + psi_curr += modifiers[ip_delta] * delta_psi; - for (int it=nrange->lower[TH_IDX]; it<=nrange->upper[TH_IDX]; ++it) { + for (int it = nrange->lower[TH_IDX]; it <= nrange->upper[TH_IDX]; ++it) { cidx[TH_IDX] = it; - int lidx = 0; - if (ip_delta != 0) - lidx = 3 + 3*(ip_delta-1); - - double *mc2p_fd_n = gkyl_array_fetch(up->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); - double *ddtheta_n = gkyl_array_fetch(up->geo_surf[dir].ddtheta_nodal, gkyl_range_idx(nrange, cidx)); - double *ddpsi_n = gkyl_array_fetch(up->geo_surf[dir].ddpsi_nodal, gkyl_range_idx(nrange, cidx)); - double *bmag_n = gkyl_array_fetch(up->geo_surf[dir].bmag_nodal, gkyl_range_idx(nrange, cidx)); - double *curlbhat_n = gkyl_array_fetch(up->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(nrange, cidx)); - double *deltats_n = gkyl_array_fetch(up->geo_surf[dir].deltats_nodal, gkyl_range_idx(nrange, cidx)); - - int donor_cidx[3] ; + int lidx = 0; + if (ip_delta != 0) { + lidx = 3 + 3 * (ip_delta - 1); + } + + double *mc2p_fd_n = + gkyl_array_fetch(up->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(nrange, cidx)); + double *ddtheta_n = + gkyl_array_fetch(up->geo_surf[dir].ddtheta_nodal, gkyl_range_idx(nrange, cidx)); + double *ddpsi_n = + gkyl_array_fetch(up->geo_surf[dir].ddpsi_nodal, gkyl_range_idx(nrange, cidx)); + double *bmag_n = + gkyl_array_fetch(up->geo_surf[dir].bmag_nodal, gkyl_range_idx(nrange, cidx)); + double *curlbhat_n = + gkyl_array_fetch(up->geo_surf[dir].curlbhat_nodal, gkyl_range_idx(nrange, cidx)); + double *deltats_n = + gkyl_array_fetch(up->geo_surf[dir].deltats_nodal, gkyl_range_idx(nrange, cidx)); + + int donor_cidx[3]; donor_cidx[AL_IDX] = nrange->lower[AL_IDX]; donor_cidx[PSI_IDX] = ip; donor_cidx[TH_IDX] = it; - double *donor_mc2p_fd_n = gkyl_array_fetch(up->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(nrange, donor_cidx)); - double *donor_ddtheta_n = gkyl_array_fetch(up->geo_surf[dir].ddtheta_nodal, gkyl_range_idx(nrange, donor_cidx)); - double *donor_ddpsi_n = gkyl_array_fetch(up->geo_surf[dir].ddpsi_nodal, gkyl_range_idx(nrange, donor_cidx)); - double *donor_bmag_n = gkyl_array_fetch(up->geo_surf[dir].bmag_nodal, gkyl_range_idx(nrange, donor_cidx)); - - mc2p_fd_n[lidx+X_IDX] = donor_mc2p_fd_n[lidx+X_IDX]; - mc2p_fd_n[lidx+Y_IDX] = donor_mc2p_fd_n[lidx+Y_IDX]; - mc2p_fd_n[lidx+Z_IDX] = donor_mc2p_fd_n[lidx+Z_IDX] + alpha_diff; - if(ip_delta==0){ + double *donor_mc2p_fd_n = + gkyl_array_fetch(up->geo_surf[dir].mc2p_nodal_fd, gkyl_range_idx(nrange, donor_cidx)); + double *donor_ddtheta_n = + gkyl_array_fetch(up->geo_surf[dir].ddtheta_nodal, gkyl_range_idx(nrange, donor_cidx)); + double *donor_ddpsi_n = + gkyl_array_fetch(up->geo_surf[dir].ddpsi_nodal, gkyl_range_idx(nrange, donor_cidx)); + double *donor_bmag_n = + gkyl_array_fetch(up->geo_surf[dir].bmag_nodal, gkyl_range_idx(nrange, donor_cidx)); + + mc2p_fd_n[lidx + X_IDX] = donor_mc2p_fd_n[lidx + X_IDX]; + mc2p_fd_n[lidx + Y_IDX] = donor_mc2p_fd_n[lidx + Y_IDX]; + mc2p_fd_n[lidx + Z_IDX] = donor_mc2p_fd_n[lidx + Z_IDX] + alpha_diff; + if (ip_delta == 0) { ddtheta_n[0] = donor_ddtheta_n[0]; ddtheta_n[1] = donor_ddtheta_n[1]; ddtheta_n[2] = donor_ddtheta_n[2]; ddpsi_n[0] = donor_ddpsi_n[0]; bmag_n[0] = donor_bmag_n[0]; - curlbhat_func(psi_curr, mc2p_fd_n[X_IDX], mc2p_fd_n[Y_IDX], mc2p_fd_n[Z_IDX], curlbhat_n, &arc_ctx); + curlbhat_func( + psi_curr, mc2p_fd_n[X_IDX], mc2p_fd_n[Y_IDX], mc2p_fd_n[Z_IDX], curlbhat_n, &arc_ctx + ); deltats_n[0] = mc2p_fd_n[Z_IDX] - alpha_curr; } } @@ -1432,21 +1716,19 @@ void gkyl_tok_geo_calc_surface(struct gk_geometry* up, int dir, struct gkyl_rang gkyl_free(arc_memo_right); } - -void -gkyl_tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, double *theta_lo, double *theta_up) +void gkyl_tok_geo_set_extent( + struct gkyl_tok_geo_grid_inp *inp, struct gkyl_tok_geo *geo, double *theta_lo, double *theta_up +) { tok_geo_set_extent(inp, geo, theta_lo, theta_up); } -struct gkyl_tok_geo_stat -gkyl_tok_geo_get_stat(const struct gkyl_tok_geo *geo) +struct gkyl_tok_geo_stat gkyl_tok_geo_get_stat(const struct gkyl_tok_geo *geo) { return geo->stat; } -void -gkyl_tok_geo_release(struct gkyl_tok_geo *geo) +void gkyl_tok_geo_release(struct gkyl_tok_geo *geo) { gkyl_array_release(geo->psiRZ); gkyl_array_release(geo->psiRZ_cubic); diff --git a/gyrokinetic/zero/tok_geo_utils.c b/gyrokinetic/zero/tok_geo_utils.c index e258e68cfe..405206aec1 100644 --- a/gyrokinetic/zero/tok_geo_utils.c +++ b/gyrokinetic/zero/tok_geo_utils.c @@ -3,237 +3,250 @@ // Helper functions for finding turning points when necessary - // This function will set zmax to be the upper turning point location -void find_upper_turning_point(struct gkyl_tok_geo *geo, double psi_curr, double zlo, double *zmax, double tolerance) +void find_upper_turning_point( + struct gkyl_tok_geo *geo, double psi_curr, double zlo, double *zmax, double tolerance +) { - double tol = tolerance ? tolerance : 1e-12 ; - //Find the turning points - double zlo_last; - double zup=*zmax; - zlo_last = zlo; - double R[4], dRdZ[4]; - double dR[4], dZ[4]; - double Rup[4], dRdZup[4]; - double dRup[4], dZup[4]; - while(true){ - int nlo = R_psiZ(geo, psi_curr, zlo, 4, R, dRdZ, dR, dZ); - int nup = R_psiZ(geo, psi_curr, zup, 4, Rup, dRdZup, dRup, dZup); - //printf("nlo, nup = %d %d; zlo, zup = %g %g\n", nlo, nup, zlo, zup); - if (nup > 0) { // This is for the PF_LO regions. Does not seem to break core_L or core_R - // However I need to think thos through more. I think it is ok only when xpt - // is known quite precisely. - *zmax = zup; + double tol = tolerance ? tolerance : 1e-12; + //Find the turning points + double zlo_last; + double zup = *zmax; + zlo_last = zlo; + double R[4], dRdZ[4]; + double dR[4], dZ[4]; + double Rup[4], dRdZup[4]; + double dRup[4], dZup[4]; + while (true) { + int nlo = R_psiZ(geo, psi_curr, zlo, 4, R, dRdZ, dR, dZ); + int nup = R_psiZ(geo, psi_curr, zup, 4, Rup, dRdZup, dRup, dZup); + //printf("nlo, nup = %d %d; zlo, zup = %g %g\n", nlo, nup, zlo, zup); + if (nup > 0) { // This is for the PF_LO regions. Does not seem to break core_L or core_R + // However I need to think thos through more. I think it is ok only when xpt + // is known quite precisely. + *zmax = zup; + break; + } + if (nlo >= 1) { + if (fabs(zlo - zup) < tol) { + *zmax = zlo; break; } - if (nlo>=1){ - if(fabs(zlo-zup) 0) { - *zmin = zlo; + double tol = tolerance ? tolerance : 1e-12; + int nup = 0; + double zlo = *zmin; + double zup_last = zup; + double R[4], dRdZ[4]; + double dR[4], dZ[4]; + double Rlo[4], dRdZlo[4]; + double dRlo[4], dZlo[4]; + while (true) { + int nup = R_psiZ(geo, psi_curr, zup, 4, R, dRdZ, dR, dZ); + int nlo = R_psiZ(geo, psi_curr, zlo, 4, Rlo, dRdZlo, dRlo, dZlo); + //printf("psi = %g;lo, nup = %d %d; zlo, zup = %g %g\n", psi_curr, nlo, nup, zlo, zup); + if (nlo > 0) { + *zmin = zlo; + break; + } + if (nup >= 1) { + if (fabs(zlo - zup) < tol) { + *zmin = zup; break; } - if(nup>=1){ - if(fabs(zlo-zup)rleft) - // nlo=0; - //} - if (nlo > 0) { - *zmin = zlo; + int nup = 0; + double zlo = *zmin; + double zup_last = zup; + double R[4], dRdZ[4]; + double dR[4], dZ[4]; + double Rlo[4], dRdZlo[4]; + double dRlo[4], dZlo[4]; + while (true) { + int nup = R_psiZ(geo, psi_curr, zup, 4, R, dRdZ, dR, dZ); + int nlo = R_psiZ(geo, psi_curr, zlo, 4, Rlo, dRlo, dRlo, dZlo); + //if(nlo==1){ + // if (Rlo[0] < geo->rleft) + // nlo=0; + //} + if (nlo > 0) { + *zmin = zlo; + break; + } + if (nup >= 2) { + if (fabs(zlo - zup) < 1e-12) { + *zmin = zup; break; } - if(nup>=2){ - if(fabs(zlo-zup)<1e-12){ - *zmin = zup; - break; - } - zup_last = zup; - zup = (zlo+zup)/2; - } - if(nup==1){ - zlo = zup; - zup = zup_last; - } - if(nup==0){ - zlo = zup; - zup = zup_last; - } + zup_last = zup; + zup = (zlo + zup) / 2; } + if (nup == 1) { + zlo = zup; + zup = zup_last; + } + if (nup == 0) { + zlo = zup; + zup = zup_last; + } + } } // This function will set zmax to be the upper turning point location -void find_upper_turning_point_pf_lo(struct gkyl_tok_geo *geo, double psi_curr, double zlo, double *zmax) +void find_upper_turning_point_pf_lo( + struct gkyl_tok_geo *geo, double psi_curr, double zlo, double *zmax +) { - //Find the turning points - double zlo_last; - double zup=*zmax; - zlo_last = zlo; - double R[4], dRdZ[4]; - double dR[4], dZ[4]; - double Rup[4], dRdZup[4]; - double dRup[4], dZup[4]; - while(true){ - int nlo = R_psiZ(geo, psi_curr, zlo, 4, R, dRdZ, dR, dZ); - int nup = R_psiZ(geo, psi_curr, zup, 4, Rup, dRdZup, dRup, dZup); - if(nup==1){ - if (Rup[0] < geo->rleft) - nup=0; + //Find the turning points + double zlo_last; + double zup = *zmax; + zlo_last = zlo; + double R[4], dRdZ[4]; + double dR[4], dZ[4]; + double Rup[4], dRdZup[4]; + double dRup[4], dZup[4]; + while (true) { + int nlo = R_psiZ(geo, psi_curr, zlo, 4, R, dRdZ, dR, dZ); + int nup = R_psiZ(geo, psi_curr, zup, 4, Rup, dRdZup, dRup, dZup); + if (nup == 1) { + if (Rup[0] < geo->rleft) { + nup = 0; } - if (nup > 0) { // This is for the PF_LO regions. Does not seem to break core_L or core_R - // However I need to think thos through more. I think it is ok only when xpt - // is known quite precisely. - *zmax = zup; + } + if (nup > 0) { // This is for the PF_LO regions. Does not seem to break core_L or core_R + // However I need to think thos through more. I think it is ok only when xpt + // is known quite precisely. + *zmax = zup; + break; + } + if (nlo >= 2) { + if (fabs(zlo - zup) < 1e-12) { + *zmax = zlo; break; } - if (nlo>=2){ - if(fabs(zlo-zup)<1e-12){ - *zmax = zlo; - break; - } - zlo_last = zlo; - zlo = (zlo+zup)/2; - } - if(nlo==1){ - zup = zlo; - zlo = zlo_last; - } - if(nlo==0){ - zup = zlo; - zlo = zlo_last; - } + zlo_last = zlo; + zlo = (zlo + zup) / 2; } + if (nlo == 1) { + zup = zlo; + zlo = zlo_last; + } + if (nlo == 0) { + zup = zlo; + zlo = zlo_last; + } + } } - - - // Sets zmax if plate is specified -void set_upper_plate(struct gkyl_tok_geo *geo, struct arc_length_ctx* arc_ctx, struct plate_ctx* pctx, double psi_curr) +void set_upper_plate( + struct gkyl_tok_geo *geo, struct arc_length_ctx *arc_ctx, struct plate_ctx *pctx, double psi_curr +) { - double rzplate[2]; - pctx->psi_curr = psi_curr; - pctx->lower=false; - double a = 0; - double b = 1; - double fa = tok_plate_psi_func(a, pctx); - double fb = tok_plate_psi_func(b, pctx); - struct gkyl_qr_res res = gkyl_ridders(tok_plate_psi_func, pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); - double smax = res.res; - geo->plate_func_upper(smax, rzplate); - arc_ctx->zmax = rzplate[1]; + double rzplate[2]; + pctx->psi_curr = psi_curr; + pctx->lower = false; + double a = 0; + double b = 1; + double fa = tok_plate_psi_func(a, pctx); + double fb = tok_plate_psi_func(b, pctx); + struct gkyl_qr_res res = + gkyl_ridders(tok_plate_psi_func, pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); + double smax = res.res; + geo->plate_func_upper(smax, rzplate); + arc_ctx->zmax = rzplate[1]; } // Sets zmin if plate is specified -void set_lower_plate(struct gkyl_tok_geo *geo, struct arc_length_ctx* arc_ctx, struct plate_ctx* pctx, double psi_curr) +void set_lower_plate( + struct gkyl_tok_geo *geo, struct arc_length_ctx *arc_ctx, struct plate_ctx *pctx, double psi_curr +) { - double rzplate[2]; - pctx->psi_curr = psi_curr; - pctx->lower=true; - double a = 0; - double b = 1; - double fa = tok_plate_psi_func(a, pctx); - double fb = tok_plate_psi_func(b, pctx); - struct gkyl_qr_res res = gkyl_ridders(tok_plate_psi_func, pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); - double smin = res.res; - geo->plate_func_lower(smin, rzplate); - arc_ctx->zmin = rzplate[1]; + double rzplate[2]; + pctx->psi_curr = psi_curr; + pctx->lower = true; + double a = 0; + double b = 1; + double fa = tok_plate_psi_func(a, pctx); + double fb = tok_plate_psi_func(b, pctx); + struct gkyl_qr_res res = + gkyl_ridders(tok_plate_psi_func, pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); + double smin = res.res; + geo->plate_func_lower(smin, rzplate); + arc_ctx->zmin = rzplate[1]; } // Sets zmax if plate is specified -void set_upper_iwl_plate(struct gkyl_tok_geo *geo, struct arc_length_ctx* arc_ctx, struct plate_ctx* pctx, double psi_curr) +void set_upper_iwl_plate( + struct gkyl_tok_geo *geo, struct arc_length_ctx *arc_ctx, struct plate_ctx *pctx, double psi_curr +) { - double rzplate[2]; - pctx->psi_curr = psi_curr; - pctx->lower=false; - double a = 0; - double b = 1; - double fa = tok_plate_psi_func(a, pctx); - double fb = tok_plate_psi_func(b, pctx); - struct gkyl_qr_res res = gkyl_ridders(tok_plate_psi_func, pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); - double smax = res.res; - geo->plate_func_upper(smax, rzplate); - arc_ctx->zmax_iwl_plate = rzplate[1]; - geo->rmin = rzplate[0]; + double rzplate[2]; + pctx->psi_curr = psi_curr; + pctx->lower = false; + double a = 0; + double b = 1; + double fa = tok_plate_psi_func(a, pctx); + double fb = tok_plate_psi_func(b, pctx); + struct gkyl_qr_res res = + gkyl_ridders(tok_plate_psi_func, pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); + double smax = res.res; + geo->plate_func_upper(smax, rzplate); + arc_ctx->zmax_iwl_plate = rzplate[1]; + geo->rmin = rzplate[0]; } // Sets zmin if plate is specified -void set_lower_iwl_plate(struct gkyl_tok_geo *geo, struct arc_length_ctx* arc_ctx, struct plate_ctx* pctx, double psi_curr) +void set_lower_iwl_plate( + struct gkyl_tok_geo *geo, struct arc_length_ctx *arc_ctx, struct plate_ctx *pctx, double psi_curr +) { - double rzplate[2]; - pctx->psi_curr = psi_curr; - pctx->lower=true; - double a = 0; - double b = 1; - double fa = tok_plate_psi_func(a, pctx); - double fb = tok_plate_psi_func(b, pctx); - struct gkyl_qr_res res = gkyl_ridders(tok_plate_psi_func, pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); - double smin = res.res; - geo->plate_func_lower(smin, rzplate); - arc_ctx->zmin_iwl_plate = rzplate[1]; - geo->rmin = rzplate[0]; + double rzplate[2]; + pctx->psi_curr = psi_curr; + pctx->lower = true; + double a = 0; + double b = 1; + double fa = tok_plate_psi_func(a, pctx); + double fb = tok_plate_psi_func(b, pctx); + struct gkyl_qr_res res = + gkyl_ridders(tok_plate_psi_func, pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); + double smin = res.res; + geo->plate_func_lower(smin, rzplate); + arc_ctx->zmin_iwl_plate = rzplate[1]; + geo->rmin = rzplate[0]; } -void -tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, double *theta_lo, double *theta_up) +void tok_geo_set_extent( + struct gkyl_tok_geo_grid_inp *inp, struct gkyl_tok_geo *geo, double *theta_lo, double *theta_up +) { geo->rleft = inp->rleft; geo->rright = inp->rright; @@ -243,10 +256,11 @@ tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, geo->rmax = inp->rmax; geo->rmin = inp->rmin; int nzcells; - if(geo->use_cubics) + if (geo->use_cubics) { nzcells = geo->rzgrid_cubic.cells[1]; - else + } else { nzcells = geo->rzgrid.cells[1]; + } double *arc_memo = gkyl_malloc(sizeof(double[nzcells])); double *arc_memo_left = gkyl_malloc(sizeof(double[nzcells])); double *arc_memo_right = gkyl_malloc(sizeof(double[nzcells])); @@ -259,86 +273,99 @@ tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, .ftype = inp->ftype, .zmaxis = geo->zmaxis }; - struct plate_ctx pctx = { - .geo = geo - }; + struct plate_ctx pctx = {.geo = geo}; double del = 1.0e-14; - if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT || inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO || inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID || inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP) { + if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP) { // Immediately set rclose arc_ctx.rclose = inp->rright; // Set zmin and zmax either fixed or with plate - if (geo->plate_spec){ + if (geo->plate_spec) { set_upper_plate(geo, &arc_ctx, &pctx, geo->psisep); set_lower_plate(geo, &arc_ctx, &pctx, geo->psisep); - } - else{ + } else { arc_ctx.zmin = inp->zmin; arc_ctx.zmax = inp->zmax; } double zxpt_up = geo->use_cubics ? geo->efit->Zxpt_cubic[1] : geo->efit->Zxpt[1]; double zxpt_lo = geo->use_cubics ? geo->efit->Zxpt_cubic[0] : geo->efit->Zxpt[0]; // Set the arc length - double arcL_tot = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax, arc_ctx.rclose, false, false, arc_memo); - double arcL_lo = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin, zxpt_lo, arc_ctx.rclose, false, false, arc_memo); - double arcL_mid = integrate_psi_contour_memo(geo, geo->psisep, zxpt_lo, zxpt_up, arc_ctx.rclose, false, false, arc_memo); - double arcL_up = integrate_psi_contour_memo(geo, geo->psisep, zxpt_up, arc_ctx.zmax, arc_ctx.rclose, false, false, arc_memo); + double arcL_tot = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax, arc_ctx.rclose, false, false, arc_memo + ); + double arcL_lo = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin, zxpt_lo, arc_ctx.rclose, false, false, arc_memo + ); + double arcL_mid = integrate_psi_contour_memo( + geo, geo->psisep, zxpt_lo, zxpt_up, arc_ctx.rclose, false, false, arc_memo + ); + double arcL_up = integrate_psi_contour_memo( + geo, geo->psisep, zxpt_up, arc_ctx.zmax, arc_ctx.rclose, false, false, arc_memo + ); if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT) { - *theta_lo = -M_PI+del; - *theta_up = M_PI-del; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO) { - *theta_lo = -M_PI+del; - *theta_up = -M_PI+del + arcL_lo/arcL_tot*2.0*M_PI; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID) { - *theta_lo = -M_PI+del + arcL_lo/arcL_tot*2.0*M_PI; - *theta_up = inp->half_domain ? 0.0 : M_PI-del - arcL_up/arcL_tot*2.0*M_PI; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP) { - *theta_lo = M_PI-del - arcL_up/arcL_tot*2.0*M_PI; - *theta_up = M_PI-del; + *theta_lo = -M_PI + del; + *theta_up = M_PI - del; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO) { + *theta_lo = -M_PI + del; + *theta_up = -M_PI + del + arcL_lo / arcL_tot * 2.0 * M_PI; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID) { + *theta_lo = -M_PI + del + arcL_lo / arcL_tot * 2.0 * M_PI; + *theta_up = inp->half_domain ? 0.0 : M_PI - del - arcL_up / arcL_tot * 2.0 * M_PI; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP) { + *theta_lo = M_PI - del - arcL_up / arcL_tot * 2.0 * M_PI; + *theta_up = M_PI - del; } } - else if(inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN || inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO || inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID || inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP){ + else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP) { // Immediately set rclose arc_ctx.rclose = inp->rleft; // Set zmin and zmax either fixed or with plate - if (geo->plate_spec){ + if (geo->plate_spec) { set_upper_plate(geo, &arc_ctx, &pctx, geo->psisep); set_lower_plate(geo, &arc_ctx, &pctx, geo->psisep); - } - else{ + } else { arc_ctx.zmin = inp->zmin; arc_ctx.zmax = inp->zmax; } double zxpt_up = geo->use_cubics ? geo->efit->Zxpt_cubic[1] : geo->efit->Zxpt[1]; double zxpt_lo = geo->use_cubics ? geo->efit->Zxpt_cubic[0] : geo->efit->Zxpt[0]; // Set the arc Length - double arcL_tot = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax, arc_ctx.rclose, false, false, arc_memo); - double arcL_lo = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin, zxpt_lo, arc_ctx.rclose, false, false, arc_memo); - double arcL_mid = integrate_psi_contour_memo(geo, geo->psisep, zxpt_lo, zxpt_up, arc_ctx.rclose, false, false, arc_memo); - double arcL_up = integrate_psi_contour_memo(geo, geo->psisep, zxpt_up, arc_ctx.zmax, arc_ctx.rclose, false, false, arc_memo); + double arcL_tot = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax, arc_ctx.rclose, false, false, arc_memo + ); + double arcL_lo = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin, zxpt_lo, arc_ctx.rclose, false, false, arc_memo + ); + double arcL_mid = integrate_psi_contour_memo( + geo, geo->psisep, zxpt_lo, zxpt_up, arc_ctx.rclose, false, false, arc_memo + ); + double arcL_up = integrate_psi_contour_memo( + geo, geo->psisep, zxpt_up, arc_ctx.zmax, arc_ctx.rclose, false, false, arc_memo + ); if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN) { - *theta_lo = -M_PI+del; - *theta_up = M_PI-del; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP) { - *theta_lo = -M_PI+del; - *theta_up = -M_PI+del + arcL_lo/arcL_tot*2.0*M_PI; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) { - *theta_lo = inp->half_domain ? 0.0 : -M_PI+del + arcL_lo/arcL_tot*2.0*M_PI; - *theta_up = M_PI-del - arcL_up/arcL_tot*2.0*M_PI; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO) { - *theta_lo = M_PI-del - arcL_up/arcL_tot*2.0*M_PI; - *theta_up = M_PI-del; - } - } - else if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L){ + *theta_lo = -M_PI + del; + *theta_up = M_PI - del; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP) { + *theta_lo = -M_PI + del; + *theta_up = -M_PI + del + arcL_lo / arcL_tot * 2.0 * M_PI; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) { + *theta_lo = inp->half_domain ? 0.0 : -M_PI + del + arcL_lo / arcL_tot * 2.0 * M_PI; + *theta_up = M_PI - del - arcL_up / arcL_tot * 2.0 * M_PI; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO) { + *theta_lo = M_PI - del - arcL_up / arcL_tot * 2.0 * M_PI; + *theta_up = M_PI - del; + } + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L) { // Immediately set rleft and rright. Will need both arc_ctx.rright = inp->rright; arc_ctx.rleft = inp->rleft; @@ -346,7 +373,7 @@ tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, double zxpt_up = geo->use_cubics ? geo->efit->Zxpt_cubic[1] : geo->efit->Zxpt[1]; double zxpt_lo = geo->use_cubics ? geo->efit->Zxpt_cubic[0] : geo->efit->Zxpt[0]; arc_ctx.zmax = inp->zmax ? inp->zmax : zxpt_up; // Initial guess. - // zmax is specified for single null full core + // zmax is specified for single null full core double zlo = geo->zmaxis; find_upper_turning_point(geo, geo->psisep, zlo, &arc_ctx.zmax, 0); arc_ctx.zmin = zxpt_lo; // Initial guess @@ -354,27 +381,31 @@ tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, find_lower_turning_point(geo, geo->psisep, zup, &arc_ctx.zmin, 0); // Done finding turning points arc_ctx.right = true; - double arcL_r = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax, arc_ctx.rright, - false, false, arc_memo_right); + double arcL_r = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax, arc_ctx.rright, false, false, arc_memo_right + ); arc_ctx.right = false; - double arcL_l = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax, arc_ctx.rleft, - false, false, arc_memo_left); + double arcL_l = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax, arc_ctx.rleft, false, false, arc_memo_left + ); double arcL_tot = arcL_l + arcL_r; if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) { - *theta_lo = -M_PI+del; - *theta_up = M_PI-del; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R) { - *theta_lo = -M_PI+del; - *theta_up = inp->half_domain? -M_PI+del + arcL_r/arcL_tot*2.0*M_PI/2.0 : -M_PI+del + arcL_r/arcL_tot*2.0*M_PI; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L) { - *theta_lo = inp->half_domain ? M_PI-del - arcL_l/arcL_tot*2.0*M_PI/2.0 : M_PI-del - arcL_l/arcL_tot*2.0*M_PI; - *theta_up = M_PI-del; - } - } - else if(inp->ftype==GKYL_GEOMETRY_TOKAMAK_LSN_SOL || inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP){ + *theta_lo = -M_PI + del; + *theta_up = M_PI - del; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R) { + *theta_lo = -M_PI + del; + *theta_up = inp->half_domain ? -M_PI + del + arcL_r / arcL_tot * 2.0 * M_PI / 2.0 : + -M_PI + del + arcL_r / arcL_tot * 2.0 * M_PI; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L) { + *theta_lo = inp->half_domain ? M_PI - del - arcL_l / arcL_tot * 2.0 * M_PI / 2.0 : + M_PI - del - arcL_l / arcL_tot * 2.0 * M_PI; + *theta_up = M_PI - del; + } + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP) { // Immediately set rleft and rright. Will need both arc_ctx.rright = inp->rright; arc_ctx.rleft = inp->rleft; @@ -386,32 +417,30 @@ tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, // Set zmin left and zmin right wither with plate or fixed // This one can't be used with the general func for setting upper and lower plates because it uses zmin left and zmin right - if (geo->plate_spec){ + if (geo->plate_spec) { double rzplate[2]; pctx.psi_curr = geo->psisep; - pctx.lower=false; + pctx.lower = false; double a = 0; double b = 1; double fa = tok_plate_psi_func(a, &pctx); double fb = tok_plate_psi_func(b, &pctx); - struct gkyl_qr_res res = gkyl_ridders(tok_plate_psi_func, &pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + struct gkyl_qr_res res = + gkyl_ridders(tok_plate_psi_func, &pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smax = res.res; geo->plate_func_upper(smax, rzplate); arc_ctx.zmin_left = rzplate[1]; - pctx.lower=true; + pctx.lower = true; a = 0; b = 1; fa = tok_plate_psi_func(a, &pctx); fb = tok_plate_psi_func(b, &pctx); - res = gkyl_ridders(tok_plate_psi_func, &pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + res = gkyl_ridders(tok_plate_psi_func, &pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smin = res.res; geo->plate_func_lower(smin, rzplate); arc_ctx.zmin_right = rzplate[1]; - } - else{ + } else { arc_ctx.zmin_left = inp->zmin_left; arc_ctx.zmin_right = inp->zmin_right; } @@ -420,36 +449,38 @@ tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, double zxpt = geo->use_cubics ? geo->efit->Zxpt_cubic[0] : geo->efit->Zxpt[0]; arc_ctx.right = true; - double arcL_mid_r = integrate_psi_contour_memo(geo, geo->psisep, zxpt, arc_ctx.zmax, arc_ctx.rright, - false, false, arc_memo_right); - double arcL_lo = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin_right, zxpt, arc_ctx.rright, - false, false, arc_memo_right); + double arcL_mid_r = integrate_psi_contour_memo( + geo, geo->psisep, zxpt, arc_ctx.zmax, arc_ctx.rright, false, false, arc_memo_right + ); + double arcL_lo = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin_right, zxpt, arc_ctx.rright, false, false, arc_memo_right + ); arc_ctx.right = false; - double arcL_mid_l = integrate_psi_contour_memo(geo, geo->psisep, zxpt, arc_ctx.zmax, arc_ctx.rleft, - false, false, arc_memo_right); - double arcL_up = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin_left, zxpt, arc_ctx.rleft, - false, false, arc_memo_left); + double arcL_mid_l = integrate_psi_contour_memo( + geo, geo->psisep, zxpt, arc_ctx.zmax, arc_ctx.rleft, false, false, arc_memo_right + ); + double arcL_up = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin_left, zxpt, arc_ctx.rleft, false, false, arc_memo_left + ); double arcL_tot = arcL_lo + arcL_mid_l + arcL_mid_r + arcL_up; if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL) { - *theta_lo = -M_PI+del; - *theta_up = M_PI-del; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO) { - *theta_lo = -M_PI+del; - *theta_up = -M_PI+del + arcL_lo/arcL_tot*2.0*M_PI; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID) { - *theta_lo = -M_PI+del + arcL_lo/arcL_tot*2.0*M_PI; - *theta_up = M_PI+del - arcL_up/arcL_tot*2.0*M_PI; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP) { - *theta_lo = M_PI+del - arcL_up/arcL_tot*2.0*M_PI; - *theta_up = M_PI-del; + *theta_lo = -M_PI + del; + *theta_up = M_PI - del; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO) { + *theta_lo = -M_PI + del; + *theta_up = -M_PI + del + arcL_lo / arcL_tot * 2.0 * M_PI; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID) { + *theta_lo = -M_PI + del + arcL_lo / arcL_tot * 2.0 * M_PI; + *theta_up = M_PI + del - arcL_up / arcL_tot * 2.0 * M_PI; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP) { + *theta_lo = M_PI + del - arcL_up / arcL_tot * 2.0 * M_PI; + *theta_up = M_PI - del; } } - else if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R || inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L){ + else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L) { arc_ctx.rright = inp->rright; arc_ctx.rleft = inp->rleft; @@ -461,33 +492,30 @@ tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, // Set zmin left and zmin right wither with plate or fixed // This one can't be used with the general func for setting upper and lower plates because it uses zmin left and zmin right - if (geo->plate_spec){ + if (geo->plate_spec) { double rzplate[2]; pctx.psi_curr = geo->psisep; - pctx.lower=false; + pctx.lower = false; double a = 0; double b = 1; double fa = tok_plate_psi_func(a, &pctx); double fb = tok_plate_psi_func(b, &pctx); - struct gkyl_qr_res res = gkyl_ridders(tok_plate_psi_func, &pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + struct gkyl_qr_res res = + gkyl_ridders(tok_plate_psi_func, &pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smax = res.res; geo->plate_func_upper(smax, rzplate); arc_ctx.zmin_left = rzplate[1]; - - pctx.lower=true; + pctx.lower = true; a = 0; b = 1; fa = tok_plate_psi_func(a, &pctx); fb = tok_plate_psi_func(b, &pctx); - res = gkyl_ridders(tok_plate_psi_func, &pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + res = gkyl_ridders(tok_plate_psi_func, &pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smin = res.res; geo->plate_func_lower(smin, rzplate); arc_ctx.zmin_right = rzplate[1]; - } - else{ + } else { arc_ctx.zmin_left = inp->zmin_left; arc_ctx.zmin_right = inp->zmin_right; } @@ -495,64 +523,65 @@ tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, // Set arc length arc_ctx.rclose = inp->rright; arc_ctx.right = true; - double arcL_r = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin_right, arc_ctx.zmax, arc_ctx.rright, - false, false, arc_memo_right); + double arcL_r = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin_right, arc_ctx.zmax, arc_ctx.rright, false, false, + arc_memo_right + ); // Immediately set rclose arc_ctx.rclose = inp->rleft; arc_ctx.right = false; - double arcL_l = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin_left, arc_ctx.zmax, arc_ctx.rleft, - false, false, arc_memo_left); + double arcL_l = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin_left, arc_ctx.zmax, arc_ctx.rleft, false, false, arc_memo_left + ); double arcL_tot = arcL_l + arcL_r; if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R) { - *theta_lo = -M_PI+del; - *theta_up = -M_PI+del + arcL_r/arcL_tot*2.0*M_PI; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L) { - *theta_lo = M_PI-del - arcL_l/arcL_tot*2.0*M_PI; - *theta_up = M_PI-del; + *theta_lo = -M_PI + del; + *theta_up = -M_PI + del + arcL_r / arcL_tot * 2.0 * M_PI; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L) { + *theta_lo = M_PI - del - arcL_l / arcL_tot * 2.0 * M_PI; + *theta_up = M_PI - del; } } - else if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_L || inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R){ + else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_L || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R) { arc_ctx.rright = inp->rright; arc_ctx.rleft = inp->rleft; //Find the lower turning point to set zmin double zxpt_up = geo->use_cubics ? geo->efit->Zxpt_cubic[1] : geo->efit->Zxpt[1]; arc_ctx.zmin = zxpt_up; // Initial guess - double zup = fmax(inp->zmax_left, inp->zmax_right); + double zup = fmax(inp->zmax_left, inp->zmax_right); find_lower_turning_point(geo, geo->psisep, zup, &arc_ctx.zmin, 1e-15); // Done finding turning point // Set zmax left and zmax right wither with plate or fixed // This one can't be used with the general func for setting upper and lower plates because it uses zmax left and zmax right - if (geo->plate_spec){ + if (geo->plate_spec) { double rzplate[2]; pctx.psi_curr = geo->psisep; - pctx.lower=false; + pctx.lower = false; double a = 0; double b = 1; double fa = tok_plate_psi_func(a, &pctx); double fb = tok_plate_psi_func(b, &pctx); - struct gkyl_qr_res res = gkyl_ridders(tok_plate_psi_func, &pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + struct gkyl_qr_res res = + gkyl_ridders(tok_plate_psi_func, &pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smax = res.res; geo->plate_func_upper(smax, rzplate); - arc_ctx.zmax_right= rzplate[1]; + arc_ctx.zmax_right = rzplate[1]; - pctx.lower=true; + pctx.lower = true; a = 0; b = 1; fa = tok_plate_psi_func(a, &pctx); fb = tok_plate_psi_func(b, &pctx); - res = gkyl_ridders(tok_plate_psi_func, &pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + res = gkyl_ridders(tok_plate_psi_func, &pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smin = res.res; geo->plate_func_lower(smin, rzplate); - arc_ctx.zmax_left= rzplate[1]; - } - else{ + arc_ctx.zmax_left = rzplate[1]; + } else { arc_ctx.zmax_left = inp->zmax_left; arc_ctx.zmax_right = inp->zmax_right; } @@ -560,43 +589,47 @@ tok_geo_set_extent(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, // Immediately set rclose arc_ctx.rclose = inp->rleft; arc_ctx.right = false; - double arcL_l = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax_left, arc_ctx.rleft, - false, false, arc_memo_left); + double arcL_l = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax_left, arc_ctx.rleft, false, false, arc_memo_left + ); // Immediately set rclose arc_ctx.rclose = inp->rright; arc_ctx.right = true; - double arcL_r = integrate_psi_contour_memo(geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax_right, arc_ctx.rright, - false, false, arc_memo_right); + double arcL_r = integrate_psi_contour_memo( + geo, geo->psisep, arc_ctx.zmin, arc_ctx.zmax_right, arc_ctx.rright, false, false, + arc_memo_right + ); double arcL_tot = arcL_r + arcL_l; if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_L) { - *theta_lo = -M_PI+del; - *theta_up = -M_PI+del + arcL_l/arcL_tot*2.0*M_PI; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R) { - *theta_lo = M_PI-del - arcL_r/arcL_tot*2.0*M_PI; - *theta_up = M_PI-del; + *theta_lo = -M_PI + del; + *theta_up = -M_PI + del + arcL_l / arcL_tot * 2.0 * M_PI; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R) { + *theta_lo = M_PI - del - arcL_r / arcL_tot * 2.0 * M_PI; + *theta_up = M_PI - del; } - } gkyl_free(arc_memo); gkyl_free(arc_memo_left); gkyl_free(arc_memo_right); - } -void -tok_find_endpoints(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, struct arc_length_ctx* arc_ctx, struct plate_ctx* pctx, double psi_curr, double alpha_curr, double* arc_memo, double* arc_memo_left, double* arc_memo_right){ +void tok_find_endpoints( + struct gkyl_tok_geo_grid_inp *inp, struct gkyl_tok_geo *geo, struct arc_length_ctx *arc_ctx, + struct plate_ctx *pctx, double psi_curr, double alpha_curr, double *arc_memo, + double *arc_memo_left, double *arc_memo_right +) +{ enum { PH_IDX, AL_IDX, TH_IDX }; // arrangement of computational coordinates enum { X_IDX, Y_IDX, Z_IDX }; // arrangement of cartesian coordinates - // Set psicurr no matter what arc_ctx->psi = psi_curr; - if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L){ + if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L) { // Immediately set rleft and rright. Will need both arc_ctx->rright = inp->rright; arc_ctx->rleft = inp->rleft; @@ -604,51 +637,55 @@ tok_find_endpoints(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, double zxpt_up = geo->use_cubics ? geo->efit->Zxpt_cubic[1] : geo->efit->Zxpt[1]; double zxpt_lo = geo->use_cubics ? geo->efit->Zxpt_cubic[0] : geo->efit->Zxpt[0]; arc_ctx->zmax = inp->zmax ? inp->zmax : zxpt_up; // Initial guess. - // zmax is specified for single null full core + // zmax is specified for single null full core double zlo = geo->zmaxis; find_upper_turning_point(geo, psi_curr, zlo, &arc_ctx->zmax, 0); arc_ctx->zmin = zxpt_lo; // Initial guess double zup = geo->zmaxis; find_lower_turning_point(geo, psi_curr, zup, &arc_ctx->zmin, 0); // Done finding turning points - arc_ctx->arcL_right = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax, arc_ctx->rright, - true, true, arc_memo_right); + arc_ctx->arcL_right = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax, arc_ctx->rright, true, true, arc_memo_right + ); arc_ctx->right = false; - arc_ctx->arcL_left = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax, arc_ctx->rleft, - true, true, arc_memo_left); + arc_ctx->arcL_left = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax, arc_ctx->rleft, true, true, arc_memo_left + ); arc_ctx->arcL_tot = arc_ctx->arcL_left + arc_ctx->arcL_right; - // Adjust the starting point (theta=0) so that the core blocks // are up-down symmetric if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R) { - double theta_extent = inp->half_domain ? 2.0*(inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX]) : inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX]; - double arcL_extent = theta_extent/(2.0*M_PI)*arc_ctx->arcL_tot; + double theta_extent = inp->half_domain ? + 2.0 * (inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX]) : + inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX]; + double arcL_extent = theta_extent / (2.0 * M_PI) * arc_ctx->arcL_tot; double extra_arcL = arcL_extent - arc_ctx->arcL_right; - arc_ctx->arcL_start = extra_arcL/2.0; - } - else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L){ - double theta_extent = inp->half_domain ? 2.0*M_PI - 2.0*(inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX]) : 2.0*M_PI - (inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX]); - double arcL_extent = theta_extent/(2.0*M_PI)*arc_ctx->arcL_tot; + arc_ctx->arcL_start = extra_arcL / 2.0; + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L) { + double theta_extent = + inp->half_domain ? + 2.0 * M_PI - 2.0 * (inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX]) : + 2.0 * M_PI - (inp->cgrid.upper[TH_IDX] - inp->cgrid.lower[TH_IDX]); + double arcL_extent = theta_extent / (2.0 * M_PI) * arc_ctx->arcL_tot; double extra_arcL = arcL_extent - arc_ctx->arcL_right; - arc_ctx->arcL_start = extra_arcL/2.0; + arc_ctx->arcL_start = extra_arcL / 2.0; } - - arc_ctx->right = true; arc_ctx->phi_right = 0.0; arc_ctx->rclose = arc_ctx->rright; arc_ctx->phi_right = phi_func(alpha_curr, arc_ctx->zmax, arc_ctx) - alpha_curr; - if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L) { + if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L) { arc_ctx->right = false; arc_ctx->rclose = inp->rleft; } } - else if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R || inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L){ + else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L) { arc_ctx->rright = inp->rright; arc_ctx->rleft = inp->rleft; @@ -660,32 +697,30 @@ tok_find_endpoints(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, // Set zmin left and zmin right wither with plate or fixed // This one can't be used with the general func for setting upper and lower plates because it uses zmin left and zmin right - if (geo->plate_spec){ + if (geo->plate_spec) { double rzplate[2]; pctx->psi_curr = psi_curr; - pctx->lower=false; + pctx->lower = false; double a = 0; double b = 1; double fa = tok_plate_psi_func(a, pctx); double fb = tok_plate_psi_func(b, pctx); - struct gkyl_qr_res res = gkyl_ridders(tok_plate_psi_func, pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + struct gkyl_qr_res res = + gkyl_ridders(tok_plate_psi_func, pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smax = res.res; geo->plate_func_upper(smax, rzplate); arc_ctx->zmin_left = rzplate[1]; - pctx->lower=true; + pctx->lower = true; a = 0; b = 1; fa = tok_plate_psi_func(a, pctx); fb = tok_plate_psi_func(b, pctx); - res = gkyl_ridders(tok_plate_psi_func, pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + res = gkyl_ridders(tok_plate_psi_func, pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smin = res.res; geo->plate_func_lower(smin, rzplate); arc_ctx->zmin_right = rzplate[1]; - } - else{ + } else { arc_ctx->zmin_left = inp->zmin_left; arc_ctx->zmin_right = inp->zmin_right; } @@ -694,125 +729,136 @@ tok_find_endpoints(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, arc_ctx->rclose = inp->rright; arc_ctx->right = true; // Set arc length - arc_ctx->arcL_right = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin_right, arc_ctx->zmax, arc_ctx->rright, - true, true, arc_memo_right); + arc_ctx->arcL_right = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin_right, arc_ctx->zmax, arc_ctx->rright, true, true, arc_memo_right + ); // Immediately set rclose arc_ctx->right = false; arc_ctx->rclose = inp->rleft; - double arcL_l = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin_left, arc_ctx->zmax, arc_ctx->rleft, - true, true, arc_memo_left); + double arcL_l = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin_left, arc_ctx->zmax, arc_ctx->rleft, true, true, arc_memo_left + ); arc_ctx->arcL_tot = arcL_l + arc_ctx->arcL_right; - if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R) { + if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R) { arc_ctx->right = true; arc_ctx->rclose = inp->rright; - } - else if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L) { + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L) { arc_ctx->right = false; arc_ctx->rclose = inp->rleft; } } - else if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_L || inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R){ + else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_L || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R) { arc_ctx->rright = inp->rright; arc_ctx->rleft = inp->rleft; //Find the lower turning point to set zmin double zxpt_up = geo->use_cubics ? geo->efit->Zxpt_cubic[1] : geo->efit->Zxpt[1]; arc_ctx->zmin = zxpt_up; // Initial guess - double zup = fmax(inp->zmax_left, inp->zmax_right); + double zup = fmax(inp->zmax_left, inp->zmax_right); find_lower_turning_point(geo, psi_curr, zup, &arc_ctx->zmin, 1e-15); // Done finding turning point // Set zmax left and zmax right wither with plate or fixed // This one can't be used with the general func for setting upper and lower plates because it uses zmax left and zmax right - if (geo->plate_spec){ + if (geo->plate_spec) { double rzplate[2]; pctx->psi_curr = psi_curr; - pctx->lower=false; + pctx->lower = false; double a = 0; double b = 1; double fa = tok_plate_psi_func(a, pctx); double fb = tok_plate_psi_func(b, pctx); - struct gkyl_qr_res res = gkyl_ridders(tok_plate_psi_func, pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + struct gkyl_qr_res res = + gkyl_ridders(tok_plate_psi_func, pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smax = res.res; geo->plate_func_upper(smax, rzplate); - arc_ctx->zmax_right= rzplate[1]; + arc_ctx->zmax_right = rzplate[1]; - pctx->lower=true; + pctx->lower = true; a = 0; b = 1; fa = tok_plate_psi_func(a, pctx); fb = tok_plate_psi_func(b, pctx); - res = gkyl_ridders(tok_plate_psi_func, pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + res = gkyl_ridders(tok_plate_psi_func, pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smin = res.res; geo->plate_func_lower(smin, rzplate); - arc_ctx->zmax_left= rzplate[1]; - } - else{ + arc_ctx->zmax_left = rzplate[1]; + } else { arc_ctx->zmax_left = inp->zmax_left; arc_ctx->zmax_right = inp->zmax_right; } - // Immediately set rclose arc_ctx->rclose = inp->rleft; arc_ctx->right = false; - arc_ctx->arcL_left = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax_left, arc_ctx->rleft, - true, true, arc_memo_left); + arc_ctx->arcL_left = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax_left, arc_ctx->rleft, true, true, arc_memo_left + ); // Immediately set rclose arc_ctx->rclose = inp->rright; arc_ctx->right = true; - double arcL_r = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax_right, arc_ctx->rright, - true, true, arc_memo_right); + double arcL_r = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax_right, arc_ctx->rright, true, true, arc_memo_right + ); arc_ctx->arcL_tot = arcL_r + arc_ctx->arcL_left; - if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R) { + if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R) { arc_ctx->right = true; arc_ctx->rclose = inp->rright; - } - else if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_L) { + } else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_L) { arc_ctx->right = false; arc_ctx->rclose = inp->rleft; } } - else if(inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT || inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO || inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID || inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP){ + else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP) { // Immediately set rclose arc_ctx->rclose = inp->rright; // Set zmin and zmax either fixed or with plate - if (geo->plate_spec){ + if (geo->plate_spec) { set_upper_plate(geo, arc_ctx, pctx, arc_ctx->psi); set_lower_plate(geo, arc_ctx, pctx, arc_ctx->psi); - } - else{ + } else { arc_ctx->zmin = inp->zmin; arc_ctx->zmax = inp->zmax; } // Set the arc length - arc_ctx->arcL_tot = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax, arc_ctx->rclose, true, true, arc_memo); + arc_ctx->arcL_tot = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax, arc_ctx->rclose, true, true, arc_memo + ); } - else if(inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN || inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO || inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID || inp->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP){ + else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP) { // Immediately set rclose arc_ctx->rclose = inp->rleft; // Set zmin and zmax either fixed or with plate - if (geo->plate_spec){ + if (geo->plate_spec) { set_upper_plate(geo, arc_ctx, pctx, arc_ctx->psi); set_lower_plate(geo, arc_ctx, pctx, arc_ctx->psi); - } - else{ + } else { arc_ctx->zmin = inp->zmin; arc_ctx->zmax = inp->zmax; } // Set the arc Length - arc_ctx->arcL_tot = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax, arc_ctx->rclose, true, true, arc_memo); + arc_ctx->arcL_tot = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax, arc_ctx->rclose, true, true, arc_memo + ); } - else if(inp->ftype==GKYL_GEOMETRY_TOKAMAK_LSN_SOL || inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP){ + else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP) { // Immediately set rleft and rright. Will need both arc_ctx->rright = inp->rright; arc_ctx->rleft = inp->rleft; @@ -823,42 +869,42 @@ tok_find_endpoints(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, // Set zmin left and zmin right wither with plate or fixed // This one can't be used with the general func for setting upper and lower plates because it uses zmin left and zmin right - if (geo->plate_spec){ + if (geo->plate_spec) { double rzplate[2]; pctx->psi_curr = psi_curr; - pctx->lower=false; + pctx->lower = false; double a = 0; double b = 1; double fa = tok_plate_psi_func(a, pctx); double fb = tok_plate_psi_func(b, pctx); - struct gkyl_qr_res res = gkyl_ridders(tok_plate_psi_func, pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + struct gkyl_qr_res res = + gkyl_ridders(tok_plate_psi_func, pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smax = res.res; geo->plate_func_upper(smax, rzplate); arc_ctx->zmin_left = rzplate[1]; - pctx->lower=true; + pctx->lower = true; a = 0; b = 1; fa = tok_plate_psi_func(a, pctx); fb = tok_plate_psi_func(b, pctx); - res = gkyl_ridders(tok_plate_psi_func, pctx, - a, b, fa, fb, geo->root_param.max_iter, 1e-10); + res = gkyl_ridders(tok_plate_psi_func, pctx, a, b, fa, fb, geo->root_param.max_iter, 1e-10); double smin = res.res; geo->plate_func_lower(smin, rzplate); arc_ctx->zmin_right = rzplate[1]; - } - else{ + } else { arc_ctx->zmin_left = inp->zmin_left; arc_ctx->zmin_right = inp->zmin_right; } // Done finding turning point - arc_ctx->arcL_right = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin_right, arc_ctx->zmax, arc_ctx->rright, - true, true, arc_memo_right); + arc_ctx->arcL_right = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin_right, arc_ctx->zmax, arc_ctx->rright, true, true, arc_memo_right + ); arc_ctx->right = false; - double arcL_l = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin_left, arc_ctx->zmax, arc_ctx->rleft, - true, true, arc_memo_left); + double arcL_l = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin_left, arc_ctx->zmax, arc_ctx->rleft, true, true, arc_memo_left + ); arc_ctx->arcL_tot = arcL_l + arc_ctx->arcL_right; arc_ctx->right = true; @@ -869,37 +915,49 @@ tok_find_endpoints(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, arc_ctx->phi_right = phi_func(alpha_curr, arc_ctx->zmax, arc_ctx) - alpha_curr; } - else if(inp->ftype == GKYL_GEOMETRY_TOKAMAK_IWL){ + else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_IWL) { // Immediately set rleft and rright. Will need both arc_ctx->rright = inp->rright; arc_ctx->rleft = inp->rleft; double R_lcfs[4], dRdZ_lcfs[4]; double dR_lcfs[4], dZ_lcfs[4]; - int nr_lcfs = gkyl_tok_geo_R_psiZ(geo, geo->efit->sibry, geo->efit->zmaxis, 4, R_lcfs, dRdZ_lcfs, dR_lcfs, dZ_lcfs); - double r_lcfs = nr_lcfs == 1 ? R_lcfs[0] : choose_closest(arc_ctx->rleft, R_lcfs, R_lcfs, nr_lcfs); + int nr_lcfs = gkyl_tok_geo_R_psiZ( + geo, geo->efit->sibry, geo->efit->zmaxis, 4, R_lcfs, dRdZ_lcfs, dR_lcfs, dZ_lcfs + ); + double r_lcfs = nr_lcfs == 1 ? R_lcfs[0] : + choose_closest(arc_ctx->rleft, R_lcfs, R_lcfs, nr_lcfs); double rz_lcfs[2]; double rmin_old = geo->rmin; if (geo->plate_spec) { geo->plate_func_upper(0.0, rz_lcfs); - if(fabs(rz_lcfs[0] - r_lcfs) > 1e-6) { - fprintf(stderr, "The upper plate function has an error. It must return (R(s=0),Z(s=0)) = (%1.16f, %1.16f). \n", R_lcfs[0], geo->efit->zmaxis); + if (fabs(rz_lcfs[0] - r_lcfs) > 1e-6) { + fprintf( + stderr, + "The upper plate function has an error. It must return (R(s=0),Z(s=0)) = (%1.16f, " + "%1.16f). \n", + R_lcfs[0], geo->efit->zmaxis + ); assert(false); } geo->plate_func_lower(0.0, rz_lcfs); - if(fabs(rz_lcfs[0] - r_lcfs) > 1e-6) { - fprintf(stderr, "The lower plate function has an error. It must return (R(s=0),Z(s=0)) = (%1.16f, %1.16f). \n", R_lcfs[0], geo->efit->zmaxis); + if (fabs(rz_lcfs[0] - r_lcfs) > 1e-6) { + fprintf( + stderr, + "The lower plate function has an error. It must return (R(s=0),Z(s=0)) = (%1.16f, " + "%1.16f). \n", + R_lcfs[0], geo->efit->zmaxis + ); assert(false); } - - if ( (arc_ctx->psi >= geo->efit->sibry && geo->efit->sibry >= geo->efit->simag) || - (arc_ctx->psi <= geo->efit->sibry && geo->efit->sibry <= geo->efit->simag) ) { + + if ((arc_ctx->psi >= geo->efit->sibry && geo->efit->sibry >= geo->efit->simag) || + (arc_ctx->psi <= geo->efit->sibry && geo->efit->sibry <= geo->efit->simag)) { set_upper_iwl_plate(geo, arc_ctx, pctx, arc_ctx->psi); set_lower_iwl_plate(geo, arc_ctx, pctx, arc_ctx->psi); } - } - else { + } else { arc_ctx->zmin_iwl_plate = geo->zmaxis; arc_ctx->zmax_iwl_plate = geo->zmaxis; } @@ -917,13 +975,21 @@ tok_find_endpoints(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, geo->rmin = rmin_old; arc_ctx->right = true; - arc_ctx->arcL_q1 = integrate_psi_contour_memo(geo, psi_curr, geo->zmaxis, arc_ctx->zmax, arc_ctx->rright, false, false, arc_memo); + arc_ctx->arcL_q1 = integrate_psi_contour_memo( + geo, psi_curr, geo->zmaxis, arc_ctx->zmax, arc_ctx->rright, false, false, arc_memo + ); arc_ctx->right = false; - arc_ctx->arcL_q2 = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin_iwl_plate, arc_ctx->zmax, arc_ctx->rleft, false, false, arc_memo); + arc_ctx->arcL_q2 = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin_iwl_plate, arc_ctx->zmax, arc_ctx->rleft, false, false, arc_memo + ); arc_ctx->right = false; - arc_ctx->arcL_q3 = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax_iwl_plate, arc_ctx->rleft, false, false, arc_memo); + arc_ctx->arcL_q3 = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin, arc_ctx->zmax_iwl_plate, arc_ctx->rleft, false, false, arc_memo + ); arc_ctx->right = true; - arc_ctx->arcL_q4 = integrate_psi_contour_memo(geo, psi_curr, arc_ctx->zmin, geo->zmaxis, arc_ctx->rright, false, false, arc_memo); + arc_ctx->arcL_q4 = integrate_psi_contour_memo( + geo, psi_curr, arc_ctx->zmin, geo->zmaxis, arc_ctx->rright, false, false, arc_memo + ); arc_ctx->arcL_tot = arc_ctx->arcL_q1 + arc_ctx->arcL_q2 + arc_ctx->arcL_q3 + arc_ctx->arcL_q4; @@ -931,23 +997,20 @@ tok_find_endpoints(struct gkyl_tok_geo_grid_inp* inp, struct gkyl_tok_geo *geo, arc_ctx->rclose = arc_ctx->rright; arc_ctx->phi_right = phi_func(alpha_curr, arc_ctx->zmax, arc_ctx) - alpha_curr; } - } - - -void -tok_set_ridders(struct gkyl_tok_geo_grid_inp* inp, struct arc_length_ctx* arc_ctx, double psi_curr, double arcL_curr,double* rclose, double *ridders_min, double* ridders_max){ - - - if(inp->ftype==GKYL_GEOMETRY_TOKAMAK_CORE){ - if(arcL_curr <= arc_ctx->arcL_right){ +void tok_set_ridders( + struct gkyl_tok_geo_grid_inp *inp, struct arc_length_ctx *arc_ctx, double psi_curr, + double arcL_curr, double *rclose, double *ridders_min, double *ridders_max +) +{ + if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE) { + if (arcL_curr <= arc_ctx->arcL_right) { *rclose = arc_ctx->rright; arc_ctx->right = true; *ridders_min = -arcL_curr; - *ridders_max = arc_ctx->arcL_tot-arcL_curr; - } - else{ + *ridders_max = arc_ctx->arcL_tot - arcL_curr; + } else { *rclose = arc_ctx->rleft; arc_ctx->right = false; *ridders_min = arc_ctx->arcL_tot - arcL_curr; @@ -955,40 +1018,37 @@ tok_set_ridders(struct gkyl_tok_geo_grid_inp* inp, struct arc_length_ctx* arc_ct } } - if(inp->ftype==GKYL_GEOMETRY_TOKAMAK_CORE_R || inp->ftype==GKYL_GEOMETRY_TOKAMAK_CORE_L){ - if(arcL_curr <= arc_ctx->arcL_start){ + if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_R || inp->ftype == GKYL_GEOMETRY_TOKAMAK_CORE_L) { + if (arcL_curr <= arc_ctx->arcL_start) { *rclose = arc_ctx->rleft; arc_ctx->right = false; - arc_ctx->pre= true; - *ridders_min = arc_ctx->arcL_start-arcL_curr; + arc_ctx->pre = true; + *ridders_min = arc_ctx->arcL_start - arcL_curr; *ridders_max = arc_ctx->arcL_start - arc_ctx->arcL_left - arcL_curr; - } - else if(arcL_curr <= arc_ctx->arcL_right + arc_ctx->arcL_start){ + } else if (arcL_curr <= arc_ctx->arcL_right + arc_ctx->arcL_start) { *rclose = arc_ctx->rright; arc_ctx->right = true; - arc_ctx->pre= false; - *ridders_min = arc_ctx->arcL_start -arcL_curr; + arc_ctx->pre = false; + *ridders_min = arc_ctx->arcL_start - arcL_curr; *ridders_max = arc_ctx->arcL_right + arc_ctx->arcL_start - arcL_curr; - } - else{ + } else { *rclose = arc_ctx->rleft; arc_ctx->right = false; - arc_ctx->pre= false; + arc_ctx->pre = false; *ridders_min = arc_ctx->arcL_tot + arc_ctx->arcL_start - arcL_curr; - *ridders_max = -arcL_curr + arc_ctx->arcL_right+arc_ctx->arcL_start; + *ridders_max = -arcL_curr + arc_ctx->arcL_right + arc_ctx->arcL_start; } } - - else if(inp->ftype==GKYL_GEOMETRY_TOKAMAK_PF_LO_R || inp->ftype==GKYL_GEOMETRY_TOKAMAK_PF_LO_L){ - if(arcL_curr <= arc_ctx->arcL_right){ + else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_LO_L) { + if (arcL_curr <= arc_ctx->arcL_right) { *rclose = arc_ctx->rright; arc_ctx->right = true; *ridders_min = -arcL_curr; - *ridders_max = arc_ctx->arcL_tot-arcL_curr; + *ridders_max = arc_ctx->arcL_tot - arcL_curr; arc_ctx->zmin = arc_ctx->zmin_right; - } - else{ + } else { *rclose = arc_ctx->rleft; arc_ctx->right = false; *ridders_min = arc_ctx->arcL_tot - arcL_curr; @@ -997,15 +1057,15 @@ tok_set_ridders(struct gkyl_tok_geo_grid_inp* inp, struct arc_length_ctx* arc_ct } } - else if(inp->ftype==GKYL_GEOMETRY_TOKAMAK_PF_UP_R || inp->ftype==GKYL_GEOMETRY_TOKAMAK_PF_UP_L){ - if(arcL_curr <= arc_ctx->arcL_left){ + else if (inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_R || + inp->ftype == GKYL_GEOMETRY_TOKAMAK_PF_UP_L) { + if (arcL_curr <= arc_ctx->arcL_left) { *rclose = arc_ctx->rleft; arc_ctx->right = false; *ridders_min = -arcL_curr + arc_ctx->arcL_left; *ridders_max = -arcL_curr; arc_ctx->zmax = arc_ctx->zmax_left; - } - else{ + } else { *rclose = arc_ctx->rright; arc_ctx->right = true; *ridders_min = arc_ctx->arcL_left - arcL_curr; @@ -1014,25 +1074,33 @@ tok_set_ridders(struct gkyl_tok_geo_grid_inp* inp, struct arc_length_ctx* arc_ct } } - else if( (arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT) || (arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT) || (arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO) || (arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID) || (arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP) ){ + else if ((arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT) || + (arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT) || + (arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_LO) || + (arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_MID) || + (arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_OUT_UP)) { *ridders_min = -arcL_curr; - *ridders_max = arc_ctx->arcL_tot-arcL_curr; + *ridders_max = arc_ctx->arcL_tot - arcL_curr; *rclose = arc_ctx->rclose; - } - else if( (arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN) || (arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN) || (arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO) || (arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) || (arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP) ){ - *ridders_min = arc_ctx->arcL_tot-arcL_curr; + } else if ((arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN) || + (arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN) || + (arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_LO) || + (arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_MID) || + (arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_DN_SOL_IN_UP)) { + *ridders_min = arc_ctx->arcL_tot - arcL_curr; *ridders_max = -arcL_curr; *rclose = arc_ctx->rclose; - } - else if(arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_LSN_SOL || arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP){ - if(arcL_curr <= arc_ctx->arcL_right){ + } else if (arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL || + arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_LO || + arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_MID || + arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_LSN_SOL_UP) { + if (arcL_curr <= arc_ctx->arcL_right) { *rclose = arc_ctx->rright; arc_ctx->right = true; *ridders_min = -arcL_curr; - *ridders_max = arc_ctx->arcL_tot-arcL_curr; + *ridders_max = arc_ctx->arcL_tot - arcL_curr; arc_ctx->zmin = arc_ctx->zmin_right; - } - else{ + } else { *rclose = arc_ctx->rleft; arc_ctx->right = false; *ridders_min = arc_ctx->arcL_tot - arcL_curr; @@ -1041,12 +1109,12 @@ tok_set_ridders(struct gkyl_tok_geo_grid_inp* inp, struct arc_length_ctx* arc_ct } } - else if (arc_ctx->ftype==GKYL_GEOMETRY_TOKAMAK_IWL) { + else if (arc_ctx->ftype == GKYL_GEOMETRY_TOKAMAK_IWL) { arc_ctx->q1 = false; arc_ctx->q2 = false; arc_ctx->q3 = false; arc_ctx->q4 = false; - if(arcL_curr <= arc_ctx->arcL_q3) { + if (arcL_curr <= arc_ctx->arcL_q3) { arc_ctx->q3 = true; *rclose = arc_ctx->rleft; arc_ctx->right = false; @@ -1056,7 +1124,7 @@ tok_set_ridders(struct gkyl_tok_geo_grid_inp* inp, struct arc_length_ctx* arc_ct arc_ctx->zmax = arc_ctx->zmax_iwl_plate; } - else if(arcL_curr <= ( arc_ctx->arcL_q3 + arc_ctx->arcL_q4) ) { + else if (arcL_curr <= (arc_ctx->arcL_q3 + arc_ctx->arcL_q4)) { arc_ctx->q4 = true; *rclose = arc_ctx->rright; arc_ctx->right = true; @@ -1066,7 +1134,7 @@ tok_set_ridders(struct gkyl_tok_geo_grid_inp* inp, struct arc_length_ctx* arc_ct arc_ctx->zmax = arc_ctx->geo->zmaxis; } - else if(arcL_curr <= (arc_ctx->arcL_q3 + arc_ctx->arcL_q4 + arc_ctx->arcL_q1) ) { + else if (arcL_curr <= (arc_ctx->arcL_q3 + arc_ctx->arcL_q4 + arc_ctx->arcL_q1)) { arc_ctx->q1 = true; *rclose = arc_ctx->rright; arc_ctx->right = true; @@ -1080,7 +1148,8 @@ tok_set_ridders(struct gkyl_tok_geo_grid_inp* inp, struct arc_length_ctx* arc_ct arc_ctx->q2 = true; *rclose = arc_ctx->rleft; arc_ctx->right = false; - *ridders_min = arc_ctx->arcL_q3 + arc_ctx->arcL_q4 + arc_ctx->arcL_q1 + arc_ctx->arcL_q2 - arcL_curr; + *ridders_min = + arc_ctx->arcL_q3 + arc_ctx->arcL_q4 + arc_ctx->arcL_q1 + arc_ctx->arcL_q2 - arcL_curr; *ridders_max = arc_ctx->arcL_q3 + arc_ctx->arcL_q4 + arc_ctx->arcL_q1 - arcL_curr; arc_ctx->zmin = arc_ctx->zmin_iwl_plate; arc_ctx->zmax = arc_ctx->zmax_iwl; @@ -1088,5 +1157,6 @@ tok_set_ridders(struct gkyl_tok_geo_grid_inp* inp, struct arc_length_ctx* arc_ct } arc_ctx->arcL = arcL_curr; - arc_ctx->rclose = *rclose; // This would be unnecessary for all double null block cases. Only needed for SN and full core + arc_ctx->rclose = + *rclose; // This would be unnecessary for all double null block cases. Only needed for SN and full core } diff --git a/gyrokinetic/zero/translate_dim.c b/gyrokinetic/zero/translate_dim.c index 90039f1012..12577ff20c 100644 --- a/gyrokinetic/zero/translate_dim.c +++ b/gyrokinetic/zero/translate_dim.c @@ -2,9 +2,10 @@ #include #include -struct gkyl_translate_dim* -gkyl_translate_dim_new(int cdim_do, struct gkyl_basis basis_do, int cdim_tar, - struct gkyl_basis basis_tar, int dir, enum gkyl_edge_loc edge, bool use_gpu) +struct gkyl_translate_dim *gkyl_translate_dim_new( + int cdim_do, struct gkyl_basis basis_do, int cdim_tar, struct gkyl_basis basis_tar, int dir, + enum gkyl_edge_loc edge, bool use_gpu +) { // Allocate space for new updater. struct gkyl_translate_dim *up = gkyl_malloc(sizeof(*up)); @@ -24,19 +25,20 @@ gkyl_translate_dim_new(int cdim_do, struct gkyl_basis basis_do, int cdim_tar, assert(basis_do.poly_order == basis_tar.poly_order); // Set pointer to the function performing basic checks on the ranges in advance method. if (up->vdim_do == 0) { - up->range_check_func = cdim_do > cdim_tar? translate_dim_range_check_conf_deflate - : translate_dim_range_check_conf_inflate; - } - else { - up->range_check_func = cdim_do > cdim_tar? translate_dim_range_check_phase_deflate - : translate_dim_range_check_phase_inflate; + up->range_check_func = cdim_do > cdim_tar ? translate_dim_range_check_conf_deflate : + translate_dim_range_check_conf_inflate; + } else { + up->range_check_func = cdim_do > cdim_tar ? translate_dim_range_check_phase_deflate : + translate_dim_range_check_phase_inflate; } - if (!use_gpu) + if (!use_gpu) { up->kernels = gkyl_malloc(sizeof(struct gkyl_translate_dim_kernels)); + } #ifdef GKYL_HAVE_CUDA - if (use_gpu) + if (use_gpu) { up->kernels = gkyl_cu_malloc(sizeof(struct gkyl_translate_dim_kernels)); + } #endif // Choose kernels that translates the DG coefficients. @@ -45,11 +47,10 @@ gkyl_translate_dim_new(int cdim_do, struct gkyl_basis basis_do, int cdim_tar, return up; } -void -gkyl_translate_dim_advance(gkyl_translate_dim* up, - const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, - const struct gkyl_array *GKYL_RESTRICT fdo, int ncomp, - struct gkyl_array *GKYL_RESTRICT ftar) +void gkyl_translate_dim_advance( + gkyl_translate_dim *up, const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, + const struct gkyl_array *GKYL_RESTRICT fdo, int ncomp, struct gkyl_array *GKYL_RESTRICT ftar +) { // Perform some basic checks. up->range_check_func(up->dir, up->cdim_do, up->cdim_tar, up->vdim_do, rng_do, rng_tar); @@ -66,9 +67,10 @@ gkyl_translate_dim_advance(gkyl_translate_dim* up, struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, rng_tar); while (gkyl_range_iter_next(&iter)) { - // Translate the target idx to the donor idx: - up->kernels->get_idx_do(up->cdim_tar, up->vdim_do, iter.idx, rng_do, up->cdim_do, idx_do, up->dir); + up->kernels->get_idx_do( + up->cdim_tar, up->vdim_do, iter.idx, rng_do, up->cdim_do, idx_do, up->dir + ); long linidx_do = gkyl_range_idx(rng_do, idx_do); long linidx_tar = gkyl_range_idx(rng_tar, iter.idx); @@ -76,21 +78,22 @@ gkyl_translate_dim_advance(gkyl_translate_dim* up, const double *fdo_c = gkyl_array_cfetch(fdo, linidx_do); double *ftar_c = gkyl_array_fetch(ftar, linidx_tar); - for (int n=0; nkernels->translate(&fdo_c[n*up->num_basis_do], &ftar_c[n*up->num_basis_tar]); + for (int n = 0; n < ncomp; n++) { + up->kernels->translate(&fdo_c[n * up->num_basis_do], &ftar_c[n * up->num_basis_tar]); } } } -void -gkyl_translate_dim_release(gkyl_translate_dim* up) +void gkyl_translate_dim_release(gkyl_translate_dim *up) { // Release memory associated with this updater. - if (!up->use_gpu) + if (!up->use_gpu) { gkyl_free(up->kernels); + } #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { gkyl_cu_free(up->kernels); + } #endif gkyl_free(up); } diff --git a/gyrokinetic/zero/translate_dim_cu.cu b/gyrokinetic/zero/translate_dim_cu.cu index eb9a1c3d1b..233dbf4ce5 100644 --- a/gyrokinetic/zero/translate_dim_cu.cu +++ b/gyrokinetic/zero/translate_dim_cu.cu @@ -8,73 +8,78 @@ extern "C" { } // CUDA kernel to set device pointers to kernels. -__global__ static void -gkyl_trans_dim_set_cu_ker_ptrs(struct gkyl_translate_dim_kernels *kernels, int cdim_do, - struct gkyl_basis basis_do, int cdim_tar, struct gkyl_basis basis_tar, int dir, enum gkyl_edge_loc edge) +__global__ static void gkyl_trans_dim_set_cu_ker_ptrs( + struct gkyl_translate_dim_kernels *kernels, int cdim_do, struct gkyl_basis basis_do, int cdim_tar, + struct gkyl_basis basis_tar, int dir, enum gkyl_edge_loc edge +) { enum gkyl_basis_type basis_type = basis_tar.b_type; int poly_order = basis_tar.poly_order; - int dir_idx = cdim_tar-1; + int dir_idx = cdim_tar - 1; int edge_idx = 0; if (cdim_tar < cdim_do) { dir_idx = dir; switch (edge) { - case GKYL_LOWER_EDGE: - edge_idx = 0; - break; - case GKYL_NO_EDGE: - edge_idx = 1; - break; - case GKYL_UPPER_EDGE: - edge_idx = 2; - break; + case GKYL_LOWER_EDGE: + edge_idx = 0; + break; + case GKYL_NO_EDGE: + edge_idx = 1; + break; + case GKYL_UPPER_EDGE: + edge_idx = 2; + break; } } // Choose kernel that translates DG coefficients. switch (basis_type) { - case GKYL_BASIS_MODAL_GKHYBRID: - kernels->translate = trans_dim_kern_list_gkhyb[cdim_tar+cdim_do-3].kernels[poly_order-1]; - break; - case GKYL_BASIS_MODAL_SERENDIPITY: - kernels->translate = trans_dim_kern_list_ser[cdim_do-1].list[dir_idx*3+edge_idx].kernels[poly_order-1]; - break; - default: - assert(false); + case GKYL_BASIS_MODAL_GKHYBRID: + kernels->translate = trans_dim_kern_list_gkhyb[cdim_tar + cdim_do - 3].kernels[poly_order - 1]; + break; + case GKYL_BASIS_MODAL_SERENDIPITY: + kernels->translate = + trans_dim_kern_list_ser[cdim_do - 1].list[dir_idx * 3 + edge_idx].kernels[poly_order - 1]; + break; + default: + assert(false); } // Choose the function that populates the donor index. int vdim = basis_do.ndim - cdim_do; if (vdim > 0) { kernels->get_idx_do = translate_dim_get_idx_do_gk; - } - else { - if (cdim_tar < cdim_do) + } else { + if (cdim_tar < cdim_do) { kernels->get_idx_do = translate_dim_get_idx_do_conf_down; - else + } else { kernels->get_idx_do = translate_dim_get_idx_do_conf_up; + } } }; -void -trans_dim_choose_kernel_cu(struct gkyl_translate_dim_kernels *kernels, int cdim_do, - struct gkyl_basis basis_do, int cdim_tar, struct gkyl_basis basis_tar, int dir, enum gkyl_edge_loc edge) +void trans_dim_choose_kernel_cu( + struct gkyl_translate_dim_kernels *kernels, int cdim_do, struct gkyl_basis basis_do, int cdim_tar, + struct gkyl_basis basis_tar, int dir, enum gkyl_edge_loc edge +) { - gkyl_trans_dim_set_cu_ker_ptrs<<<1,1>>>(kernels, cdim_do, basis_do, cdim_tar, basis_tar, dir, edge); + gkyl_trans_dim_set_cu_ker_ptrs<<<1, 1> > >( + kernels, cdim_do, basis_do, cdim_tar, basis_tar, dir, edge + ); } -__global__ static void -gkyl_translate_dim_advance_cu_ker(int cdim_do, int cdim_tar, int vdim_do, int vdim_tar, - int num_basis_do, int num_basis_tar, int dir, struct gkyl_translate_dim_kernels *kernels, - const struct gkyl_range rng_do, const struct gkyl_range rng_tar, - const struct gkyl_array *GKYL_RESTRICT fdo, int ncomp, - struct gkyl_array *GKYL_RESTRICT ftar) +__global__ static void gkyl_translate_dim_advance_cu_ker( + int cdim_do, int cdim_tar, int vdim_do, int vdim_tar, int num_basis_do, int num_basis_tar, + int dir, struct gkyl_translate_dim_kernels *kernels, const struct gkyl_range rng_do, + const struct gkyl_range rng_tar, const struct gkyl_array *GKYL_RESTRICT fdo, int ncomp, + struct gkyl_array *GKYL_RESTRICT ftar +) { int idx_do[GKYL_MAX_DIM] = {0}; int idx_tar[GKYL_MAX_DIM] = {0}; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < rng_tar.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < rng_tar.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&rng_tar, tid, idx_tar); // Translate the target idx to the donor idx: @@ -83,25 +88,24 @@ gkyl_translate_dim_advance_cu_ker(int cdim_do, int cdim_tar, int vdim_do, int vd long linidx_do = gkyl_range_idx(&rng_do, idx_do); long linidx_tar = gkyl_range_idx(&rng_tar, idx_tar); - const double *fdo_c = (const double *) gkyl_array_cfetch(fdo, linidx_do); - double *ftar_c = (double *) gkyl_array_fetch(ftar, linidx_tar); + const double *fdo_c = (const double *)gkyl_array_cfetch(fdo, linidx_do); + double *ftar_c = (double *)gkyl_array_fetch(ftar, linidx_tar); - for (int n=0; ntranslate(&fdo_c[n*num_basis_do], &ftar_c[n*num_basis_tar]); + for (int n = 0; n < ncomp; n++) { + kernels->translate(&fdo_c[n * num_basis_do], &ftar_c[n * num_basis_tar]); } - } } -void -gkyl_translate_dim_advance_cu(gkyl_translate_dim* up, - const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, - const struct gkyl_array *GKYL_RESTRICT fdo, int ncomp, - struct gkyl_array *GKYL_RESTRICT ftar) +void gkyl_translate_dim_advance_cu( + gkyl_translate_dim *up, const struct gkyl_range *rng_do, const struct gkyl_range *rng_tar, + const struct gkyl_array *GKYL_RESTRICT fdo, int ncomp, struct gkyl_array *GKYL_RESTRICT ftar +) { int nblocks = rng_tar->nblocks, nthreads = rng_tar->nthreads; - gkyl_translate_dim_advance_cu_ker<<>> - (up->cdim_do, up->cdim_tar, up->vdim_do, up->vdim_tar, up->num_basis_do, up->num_basis_tar, - up->dir, up->kernels, *rng_do, *rng_tar, fdo->on_dev, ncomp, ftar->on_dev); + gkyl_translate_dim_advance_cu_ker<< > >( + up->cdim_do, up->cdim_tar, up->vdim_do, up->vdim_tar, up->num_basis_do, up->num_basis_tar, + up->dir, up->kernels, *rng_do, *rng_tar, fdo->on_dev, ncomp, ftar->on_dev + ); } diff --git a/moments/amr/amr_block.c b/moments/amr/amr_block.c index f67dcb0738..5e480a7567 100644 --- a/moments/amr/amr_block.c +++ b/moments/amr/amr_block.c @@ -1,19 +1,26 @@ #include #include -void -skin_ghost_ranges_init_block(struct skin_ghost_ranges_block* sgr, const struct gkyl_range* parent, const int* ghost) +void skin_ghost_ranges_init_block( + struct skin_ghost_ranges_block *sgr, const struct gkyl_range *parent, const int *ghost +) { int ndim = parent->ndim; for (int d = 0; d < ndim; d++) { - gkyl_skin_ghost_ranges(&sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost); + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } -void -euler_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void euler_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { for (int i = 0; i < 5; i++) { ghost[i] = skin[i]; @@ -22,8 +29,10 @@ euler_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKY ghost[1] = -ghost[1]; } -void -gr_euler_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void gr_euler_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { for (int i = 0; i < 29; i++) { ghost[i] = skin[i]; @@ -32,8 +41,10 @@ gr_euler_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* ghost[1] = -ghost[1]; } -void -euler_mixture_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void euler_mixture_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -45,24 +56,30 @@ euler_mixture_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const dou ghost[1] = -ghost[1]; } -void -euler_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void euler_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { for (int i = 0; i < 5; i++) { ghost[i] = skin[i]; } } -void -gr_euler_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void gr_euler_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { for (int i = 0; i < 29; i++) { ghost[i] = skin[i]; } } -void -euler_mixture_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void euler_mixture_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -72,8 +89,10 @@ euler_mixture_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const dou } } -void -euler_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn) +void euler_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +) { int nghost[9]; for (int i = 0; i < 9; i++) { @@ -91,24 +110,27 @@ euler_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_d if ((d == 0 && wall_x) || (d == 1 && wall_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - euler_wall_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, euler_wall_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - euler_wall_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, euler_wall_bc, 0 + ); } - } - else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { + } else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - euler_copy_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, euler_copy_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - euler_copy_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, euler_copy_bc, 0 + ); } } } @@ -127,8 +149,10 @@ euler_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_d bdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); } -void -euler_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn) +void euler_nested_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +) { int nghost[25]; for (int i = 0; i < 25; i++) { @@ -146,24 +170,27 @@ euler_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_ if ((d == 0 && wall_x) || (d == 1 && wall_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - euler_wall_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, euler_wall_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - euler_wall_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, euler_wall_bc, 0 + ); } - } - else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { + } else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - euler_copy_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, euler_copy_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - euler_copy_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, euler_copy_bc, 0 + ); } } } @@ -182,8 +209,10 @@ euler_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_ bdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); } -void -gr_euler_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn) +void gr_euler_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +) { int nghost[9]; for (int i = 0; i < 9; i++) { @@ -201,24 +230,27 @@ gr_euler_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_bloc if ((d == 0 && wall_x) || (d == 1 && wall_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - gr_euler_wall_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, gr_euler_wall_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - gr_euler_wall_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, gr_euler_wall_bc, 0 + ); } - } - else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { + } else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - gr_euler_copy_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, gr_euler_copy_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - gr_euler_copy_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, gr_euler_copy_bc, 0 + ); } } } @@ -237,8 +269,10 @@ gr_euler_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_bloc bdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 29, buff_sz); } -void -gr_euler_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn) +void gr_euler_nested_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +) { int nghost[25]; for (int i = 0; i < 25; i++) { @@ -256,24 +290,27 @@ gr_euler_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct eul if ((d == 0 && wall_x) || (d == 1 && wall_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - gr_euler_wall_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, gr_euler_wall_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - gr_euler_wall_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, gr_euler_wall_bc, 0 + ); } - } - else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { + } else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - gr_euler_copy_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, gr_euler_copy_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - gr_euler_copy_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, gr_euler_copy_bc, 0 + ); } } } @@ -292,8 +329,10 @@ gr_euler_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct eul bdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 29, buff_sz); } -void -euler_mixture_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn) +void euler_mixture_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -314,24 +353,31 @@ euler_mixture_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler if ((d == 0 && wall_x) || (d == 1 && wall_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - euler_mixture_wall_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + euler_mixture_wall_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - euler_mixture_wall_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + euler_mixture_wall_bc, 0 + ); } - } - else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { + } else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - euler_mixture_copy_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + euler_mixture_copy_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - euler_mixture_copy_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + euler_mixture_copy_bc, 0 + ); } } } @@ -350,8 +396,10 @@ euler_mixture_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler bdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), buff_sz); } -void -euler_mixture_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn) +void euler_mixture_nested_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -372,24 +420,31 @@ euler_mixture_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struc if ((d == 0 && wall_x) || (d == 1 && wall_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - euler_mixture_wall_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + euler_mixture_wall_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - euler_mixture_wall_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + euler_mixture_wall_bc, 0 + ); } - } - else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { + } else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - euler_mixture_copy_bc, 0); + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + euler_mixture_copy_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - euler_mixture_copy_bc, 0); + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + euler_mixture_copy_bc, 0 + ); } } } @@ -408,8 +463,7 @@ euler_mixture_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struc bdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), buff_sz); } -void -euler_block_bc_updaters_release(struct euler_block_data* bdata) +void euler_block_bc_updaters_release(struct euler_block_data *bdata) { for (int d = 0; d < 2; d++) { if (bdata->lower_bc[d]) { @@ -424,8 +478,9 @@ euler_block_bc_updaters_release(struct euler_block_data* bdata) gkyl_array_release(bdata->bc_buffer); } -void -euler_block_bc_updaters_apply(const struct euler_block_data* bdata, double tm, struct gkyl_array* fld) +void euler_block_bc_updaters_apply( + const struct euler_block_data *bdata, double tm, struct gkyl_array *fld +) { for (int d = 0; d < 2; d++) { if (bdata->lower_bc[d]) { @@ -438,212 +493,286 @@ euler_block_bc_updaters_apply(const struct euler_block_data* bdata, double tm, s } } -void -block_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void block_ll_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + double ref_factor_inv = + ((double)bdata[i].skin_ghost.lower_skin[d].volume / + (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), + fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -block_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void block_ll_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / + bdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -block_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void block_lu_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + double ref_factor_inv = + ((double)bdata[i].skin_ghost.lower_skin[d].volume / + (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), + fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -block_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void block_lu_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / + bdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -block_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void block_ul_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + double ref_factor_inv = + ((double)bdata[i].skin_ghost.upper_skin[d].volume / + (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), + fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -block_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void block_ul_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / + bdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -block_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void block_uu_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + double ref_factor_inv = + ((double)bdata[i].skin_ghost.upper_skin[d].volume / + (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), + fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -block_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void block_uu_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / + bdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_data bdata[], struct gkyl_array* fld[]) +void euler_sync_blocks( + const struct gkyl_block_topo *btopo, const struct euler_block_data bdata[], + struct gkyl_array *fld[] +) { int num_blocks = btopo->num_blocks; int ndim = btopo->ndim; - + for (int i = 0; i < num_blocks; i++) { for (int d = 0; d < ndim; d++) { const struct gkyl_target_edge *te = btopo->conn[i].connections[d]; @@ -657,24 +786,29 @@ euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_ int tdir = te[0].dir; if (te[0].edge == GKYL_LOWER_POSITIVE) { - if (bdata[i].skin_ghost.lower_skin[d].volume == bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (bdata[i].skin_ghost.lower_skin[d].volume > bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + if (bdata[i].skin_ghost.lower_skin[d].volume == + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + } else if (bdata[i].skin_ghost.lower_skin[d].volume > + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { block_ll_restriction_op(tbid, tdir, i, d, bdata, bc_buffer, fld); - } - else if (bdata[i].skin_ghost.lower_skin[d].volume < bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + } else if (bdata[i].skin_ghost.lower_skin[d].volume < + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { block_ll_projection_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } - } - else if (te[0].edge == GKYL_UPPER_POSITIVE) { - if (bdata[i].skin_ghost.lower_skin[d].volume == bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - } - else if (bdata[i].skin_ghost.lower_skin[d].volume > bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + } else if (te[0].edge == GKYL_UPPER_POSITIVE) { + if (bdata[i].skin_ghost.lower_skin[d].volume == + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + } else if (bdata[i].skin_ghost.lower_skin[d].volume > + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { block_lu_restriction_op(tbid, tdir, i, d, bdata, bc_buffer, fld); - } - else if (bdata[i].skin_ghost.lower_skin[d].volume < bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + } else if (bdata[i].skin_ghost.lower_skin[d].volume < + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { block_lu_projection_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } } @@ -689,24 +823,29 @@ euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_ int tdir = te[1].dir; if (te[1].edge == GKYL_LOWER_POSITIVE) { - if (bdata[i].skin_ghost.upper_skin[d].volume == bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (bdata[i].skin_ghost.upper_skin[d].volume > bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + if (bdata[i].skin_ghost.upper_skin[d].volume == + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + } else if (bdata[i].skin_ghost.upper_skin[d].volume > + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { block_ul_restriction_op(tbid, tdir, i, d, bdata, bc_buffer, fld); - } - else if (bdata[i].skin_ghost.upper_skin[d].volume < bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + } else if (bdata[i].skin_ghost.upper_skin[d].volume < + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { block_ul_projection_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } - } - else if (te[1].edge == GKYL_UPPER_POSITIVE) { - if (bdata[i].skin_ghost.upper_skin[d].volume == bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - } - else if (bdata[i].skin_ghost.upper_skin[d].volume > bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + } else if (te[1].edge == GKYL_UPPER_POSITIVE) { + if (bdata[i].skin_ghost.upper_skin[d].volume == + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + } else if (bdata[i].skin_ghost.upper_skin[d].volume > + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { block_uu_restriction_op(tbid, tdir, i, d, bdata, bc_buffer, fld); - } - else if (bdata[i].skin_ghost.upper_skin[d].volume < bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + } else if (bdata[i].skin_ghost.upper_skin[d].volume < + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { block_uu_projection_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } } @@ -715,14 +854,12 @@ euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_ } } -void -euler_block_data_write(const char* file_nm, const struct euler_block_data* bdata) +void euler_block_data_write(const char *file_nm, const struct euler_block_data *bdata) { gkyl_grid_sub_array_write(&bdata->grid, &bdata->range, 0, bdata->f[0], file_nm); } -double -euler_block_data_max_dt(const struct euler_block_data* bdata) +double euler_block_data_max_dt(const struct euler_block_data *bdata) { double dt = DBL_MAX; @@ -733,8 +870,7 @@ euler_block_data_max_dt(const struct euler_block_data* bdata) return dt; } -void -euler_update_block_job_func(void* ctx) +void euler_update_block_job_func(void *ctx) { struct euler_update_block_ctx *ub_ctx = ctx; const struct euler_block_data *bdata = ub_ctx->bdata; @@ -743,31 +879,29 @@ euler_update_block_job_func(void* ctx) double t_curr = ub_ctx->t_curr; double dt = ub_ctx->dt; - ub_ctx->stat = gkyl_wave_prop_advance(bdata->slvr[d], t_curr, dt, &bdata->range, NULL, bdata->f[d], bdata->f[d + 1]); + ub_ctx->stat = gkyl_wave_prop_advance( + bdata->slvr[d], t_curr, dt, &bdata->range, NULL, bdata->f[d], bdata->f[d + 1] + ); euler_block_bc_updaters_apply(bdata, t_curr, bdata->f[d + 1]); } -struct gkyl_update_status -euler_update_all_blocks(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* btopo, - const struct euler_block_data bdata[], double t_curr, double dt) +struct gkyl_update_status euler_update_all_blocks( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct euler_block_data bdata[], double t_curr, double dt +) { - int num_blocks = btopo->num_blocks; + int num_blocks = btopo->num_blocks; int ndim = btopo->ndim; double dt_suggested = DBL_MAX; for (int d = 0; d < ndim; d++) { struct euler_update_block_ctx euler_block_ctx[num_blocks]; - + for (int i = 0; i < num_blocks; i++) { - euler_block_ctx[i] = (struct euler_update_block_ctx) { - .bdata = &bdata[i], - .t_curr = t_curr, - .dir = d, - .dt = dt, - .bidx = i, - }; + euler_block_ctx[i] = (struct euler_update_block_ctx + ){.bdata = &bdata[i], .t_curr = t_curr, .dir = d, .dt = dt, .bidx = i}; } #ifdef AMR_USETHREADS @@ -785,10 +919,8 @@ euler_update_all_blocks(const struct gkyl_job_pool* job_pool, const struct gkyl_ for (int i = 0; i < num_blocks; i++) { if (euler_block_ctx[i].stat.success == false) { - return (struct gkyl_update_status) { - .success = false, - .dt_suggested = euler_block_ctx[i].stat.dt_suggested, - }; + return (struct gkyl_update_status + ){.success = false, .dt_suggested = euler_block_ctx[i].stat.dt_suggested}; } dt_suggested = fmin(dt_suggested, euler_block_ctx[i].stat.dt_suggested); @@ -798,42 +930,32 @@ euler_update_all_blocks(const struct gkyl_job_pool* job_pool, const struct gkyl_ euler_sync_blocks(btopo, bdata, fld); } - return (struct gkyl_update_status) { - .success = true, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status){.success = true, .dt_suggested = dt_suggested}; } -void -euler_init_job_func_block(void* ctx) +void euler_init_job_func_block(void *ctx) { struct euler_block_data *bdata = ctx; gkyl_fv_proj_advance(bdata->fv_proj, 0.0, &bdata->ext_range, bdata->f[0]); } -void -copy_job_func(void* ctx) +void copy_job_func(void *ctx) { struct copy_job_ctx *j_ctx = ctx; gkyl_array_copy(j_ctx->out, j_ctx->inp); } -struct gkyl_update_status -euler_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* btopo, - const struct euler_block_data bdata[], double t_curr, double dt0, struct sim_stats* stats) +struct gkyl_update_status euler_update_block( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct euler_block_data bdata[], double t_curr, double dt0, struct sim_stats *stats +) { int num_blocks = btopo->num_blocks; double dt_suggested = DBL_MAX; - enum { - UPDATE_DONE = 0, - PRE_UPDATE, - POST_UPDATE, - FLUID_UPDATE, - UPDATE_REDO, - } state = PRE_UPDATE; + enum { UPDATE_DONE = 0, PRE_UPDATE, POST_UPDATE, FLUID_UPDATE, UPDATE_REDO } state = PRE_UPDATE; struct copy_job_ctx euler_copy_ctx[num_blocks]; double dt = dt0; @@ -843,11 +965,8 @@ euler_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl_block state = FLUID_UPDATE; for (int i = 0; i < num_blocks; i++) { - euler_copy_ctx[i] = (struct copy_job_ctx) { - .bidx = i, - .inp = bdata[i].f[0], - .out = bdata[i].fdup, - }; + euler_copy_ctx[i] = + (struct copy_job_ctx){.bidx = i, .inp = bdata[i].f[0], .out = bdata[i].fdup}; } #ifdef AMR_USETHREADS @@ -860,8 +979,7 @@ euler_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl_block copy_job_func(&euler_copy_ctx[i]); } #endif - } - else if (state == FLUID_UPDATE) { + } else if (state == FLUID_UPDATE) { state = POST_UPDATE; struct gkyl_update_status s = euler_update_all_blocks(job_pool, btopo, bdata, t_curr, dt); @@ -870,20 +988,15 @@ euler_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl_block stats->nfail += 1; dt = s.dt_suggested; state = UPDATE_REDO; - } - else { + } else { dt_suggested = fmin(dt_suggested, s.dt_suggested); } - } - else if (state == POST_UPDATE) { + } else if (state == POST_UPDATE) { state = UPDATE_DONE; for (int i = 0; i < num_blocks; i++) { - euler_copy_ctx[i] = (struct copy_job_ctx) { - .bidx = i, - .inp = bdata[i].f[2], - .out = bdata[i].f[0], - }; + euler_copy_ctx[i] = + (struct copy_job_ctx){.bidx = i, .inp = bdata[i].f[2], .out = bdata[i].f[0]}; } #ifdef AMR_USETHREADS @@ -896,16 +1009,12 @@ euler_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl_block copy_job_func(&euler_copy_ctx[i]); } #endif - } - else if (state == UPDATE_REDO) { + } else if (state == UPDATE_REDO) { state = PRE_UPDATE; for (int i = 0; i < num_blocks; i++) { - euler_copy_ctx[i] = (struct copy_job_ctx) { - .bidx = i, - .inp = bdata[i].fdup, - .out = bdata[i].f[0], - }; + euler_copy_ctx[i] = + (struct copy_job_ctx){.bidx = i, .inp = bdata[i].fdup, .out = bdata[i].f[0]}; } #ifdef AMR_USETHREADS @@ -921,15 +1030,11 @@ euler_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl_block } } - return (struct gkyl_update_status) { - .success = true, - .dt_actual = dt, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status + ){.success = true, .dt_actual = dt, .dt_suggested = dt_suggested}; } -void -euler_write_sol_block(const char* fbase, int num_blocks, const struct euler_block_data bdata[]) +void euler_write_sol_block(const char *fbase, int num_blocks, const struct euler_block_data bdata[]) { for (int i = 0; i < num_blocks; i++) { const char *fmt = "%s_b%d.gkyl"; @@ -941,8 +1046,7 @@ euler_write_sol_block(const char* fbase, int num_blocks, const struct euler_bloc } } -double -euler_max_dt_block(int num_blocks, const struct euler_block_data bdata[]) +double euler_max_dt_block(int num_blocks, const struct euler_block_data bdata[]) { double dt = DBL_MAX; @@ -953,188 +1057,310 @@ euler_max_dt_block(int num_blocks, const struct euler_block_data bdata[]) return dt; } -struct gkyl_block_topo* -create_block_topo() +struct gkyl_block_topo *create_block_topo() { struct gkyl_block_topo *btopo = gkyl_block_topo_new(2, 9); - btopo->conn[0] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 4, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 5, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 7, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[1] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 4, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, - }; - - btopo->conn[2] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 3, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, - }; - - btopo->conn[3] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, - .connections[1] = { { .bid = 5, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, - }; - - btopo->conn[4] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 6, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 1, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[5] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, - .connections[1] = { { .bid = 8, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 3, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[6] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 7, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[7] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 6, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 8, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[8] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 7, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, - .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 5, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; + btopo->conn[0] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 4, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 5, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 7, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[1] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 4, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }}; + + btopo->conn[2] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }}; + + btopo->conn[3] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}}, + .connections[1] = { + {.bid = 5, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }}; + + btopo->conn[4] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, + {.bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 6, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 1, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[5] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}}, + .connections[1] = { + {.bid = 8, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[6] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, + {.bid = 7, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, {.bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[7] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 6, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 8, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, {.bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[8] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 7, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}}, + .connections[1] = { + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, {.bid = 5, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; return btopo; } -struct gkyl_block_topo* -create_nested_block_topo() +struct gkyl_block_topo *create_nested_block_topo() { struct gkyl_block_topo *btopo = gkyl_block_topo_new(2, 25); - btopo->conn[0] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 4, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 5, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 7, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[1] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 14, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 4, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 10, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[2] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 3, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 11, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[3] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 15, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 5, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 12, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[4] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 16, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 6, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 1, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[5] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 17, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 8, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 3, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[6] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 18, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 7, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 21, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[7] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 6, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 8, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 22, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[8] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 7, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 19, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 23, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 5, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[9] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 10, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 14, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, - }; - - btopo->conn[10] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 9, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 11, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, - }; - - btopo->conn[11] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 10, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 12, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 2, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, - }; - - btopo->conn[12] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 11, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 13, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 3, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, - }; - - btopo->conn[13] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 12, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, - .connections[1] = { { .bid = 15, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, - }; - - btopo->conn[14] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 16, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 9, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[15] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, - .connections[1] = { { .bid = 17, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 13, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[16] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 4, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 18, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 14, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[17] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 5, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, - .connections[1] = { { .bid = 19, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 15, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[18] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 6, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 20, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 16, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[19] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 8, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, - .connections[1] = { { .bid = 24, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 17, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[20] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 21, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 18, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[21] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 20, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 22, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 6, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[22] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 21, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 23, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 7, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[23] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 22, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 24, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 8, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; - - btopo->conn[24] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 23, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, - .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 19, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, - }; + btopo->conn[0] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 4, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 5, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 7, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[1] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 14, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 4, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 10, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[2] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 11, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[3] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 15, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 5, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 12, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[4] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 16, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 6, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 1, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[5] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 17, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 8, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 3, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[6] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 18, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 7, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 21, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[7] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 6, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 8, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 22, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[8] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 7, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 19, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 23, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 5, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[9] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, + {.bid = 10, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 14, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }}; + + btopo->conn[10] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 9, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 11, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }}; + + btopo->conn[11] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 10, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 12, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 2, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }}; + + btopo->conn[12] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 11, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 13, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 3, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }}; + + btopo->conn[13] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 12, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}}, + .connections[1] = { + {.bid = 15, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} + }}; + + btopo->conn[14] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, + {.bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 16, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 9, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[15] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}}, + .connections[1] = { + {.bid = 17, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 13, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[16] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, + {.bid = 4, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 18, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 14, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[17] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 5, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}}, + .connections[1] = { + {.bid = 19, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 15, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[18] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, + {.bid = 6, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 20, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 16, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[19] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 8, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}}, + .connections[1] = { + {.bid = 24, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 17, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[20] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, + {.bid = 21, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 18, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[21] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 20, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 22, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, {.bid = 6, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[22] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 21, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 23, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, {.bid = 7, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[23] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 22, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 24, .dir = 0, .edge = GKYL_LOWER_POSITIVE}}, + .connections[1] = { + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, {.bid = 8, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; + + btopo->conn[24] = (struct gkyl_block_connections + ){.connections[0] = + {{.bid = 23, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}}, + .connections[1] = { + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, + {.bid = 19, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; return btopo; } diff --git a/moments/amr/amr_block_coupled.c b/moments/amr/amr_block_coupled.c index 86ea19b4c1..022978e486 100644 --- a/moments/amr/amr_block_coupled.c +++ b/moments/amr/amr_block_coupled.c @@ -1,7 +1,9 @@ #include -void -five_moment_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void five_moment_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { for (int i = 0; i < 5; i++) { ghost[i] = skin[i]; @@ -10,58 +12,67 @@ five_moment_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const doubl ghost[1] = -ghost[1]; } -void -ten_moment_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void ten_moment_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { for (int i = 0; i < 10; i++) { if (i == 1 || i == 5 || i == 6) { ghost[i] = -skin[i]; - } - else { + } else { ghost[i] = skin[i]; } } } -void -maxwell_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void maxwell_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { for (int i = 0; i < 8; i++) { if (i == 1 || i == 2 || i == 3 || i == 6) { ghost[i] = -skin[i]; - } - else { + } else { ghost[i] = skin[i]; } } } -void -five_moment_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void five_moment_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { for (int i = 0; i < 5; i++) { ghost[i] = skin[i]; } } -void -ten_moment_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void ten_moment_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { for (int i = 0; i < 10; i++) { ghost[i] = skin[i]; } } -void -maxwell_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +void maxwell_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +) { for (int i = 0; i < 8; i++) { ghost[i] = skin[i]; } } -void -five_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn) +void five_moment_block_bc_updaters_init( + struct five_moment_block_data *bdata, const struct gkyl_block_connections *conn +) { int nghost[9]; for (int i = 0; i < 9; i++) { @@ -81,40 +92,59 @@ five_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const s if ((d == 0 && wall_x) || (d == 1 && wall_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_wall_bc, 0); - bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_wall_bc, 0); - bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_wall_bc, 0); + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_wall_bc, 0 + ); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_wall_bc, 0 + ); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, maxwell_wall_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_wall_bc, 0); - bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_wall_bc, 0); - bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_wall_bc, 0); + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_wall_bc, 0 + ); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_wall_bc, 0 + ); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, maxwell_wall_bc, 0 + ); } - } - else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { + } else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_copy_bc, 0); - bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_copy_bc, 0); - bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_copy_bc, 0); + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_copy_bc, 0 + ); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_copy_bc, 0 + ); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, maxwell_copy_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_copy_bc, 0); - bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_copy_bc, 0); - bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_copy_bc, 0); + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_copy_bc, 0 + ); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_copy_bc, 0 + ); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, maxwell_copy_bc, 0 + ); } } } @@ -124,7 +154,7 @@ five_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const s for (int d = 0; d < 2; d++) { long vol = bdata->skin_ghost.lower_skin[d].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -135,8 +165,9 @@ five_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const s bdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } -void -five_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn) +void five_moment_nested_block_bc_updaters_init( + struct five_moment_block_data *bdata, const struct gkyl_block_connections *conn +) { int nghost[25]; for (int i = 0; i < 25; i++) { @@ -156,40 +187,59 @@ five_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, if ((d == 0 && wall_x) || (d == 1 && wall_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_wall_bc, 0); - bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_wall_bc, 0); - bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_wall_bc, 0); + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_wall_bc, 0 + ); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_wall_bc, 0 + ); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, maxwell_wall_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_wall_bc, 0); - bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_wall_bc, 0); - bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_wall_bc, 0); + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_wall_bc, 0 + ); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_wall_bc, 0 + ); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, maxwell_wall_bc, 0 + ); } - } - else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { + } else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_copy_bc, 0); - bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_copy_bc, 0); - bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_copy_bc, 0); + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_copy_bc, 0 + ); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_copy_bc, 0 + ); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, maxwell_copy_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_copy_bc, 0); - bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_copy_bc, 0); - bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_copy_bc, 0); + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_copy_bc, 0 + ); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_copy_bc, 0 + ); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, maxwell_copy_bc, 0 + ); } } } @@ -199,7 +249,7 @@ five_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, for (int d = 0; d < 2; d++) { long vol = bdata->skin_ghost.lower_skin[d].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -210,8 +260,9 @@ five_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, bdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } -void -ten_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn) +void ten_moment_block_bc_updaters_init( + struct five_moment_block_data *bdata, const struct gkyl_block_connections *conn +) { int nghost[9]; for (int i = 0; i < 9; i++) { @@ -231,40 +282,59 @@ ten_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const st if ((d == 0 && wall_x) || (d == 1 && wall_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_wall_bc, 0); - bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_wall_bc, 0); - bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_wall_bc, 0); + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_wall_bc, 0 + ); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_wall_bc, 0 + ); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, maxwell_wall_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_wall_bc, 0); - bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_wall_bc, 0); - bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_wall_bc, 0); + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_wall_bc, 0 + ); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_wall_bc, 0 + ); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, maxwell_wall_bc, 0 + ); } - } - else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { + } else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_copy_bc, 0); - bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_copy_bc, 0); - bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_copy_bc, 0); + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_copy_bc, 0 + ); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_copy_bc, 0 + ); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, maxwell_copy_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_copy_bc, 0); - bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_copy_bc, 0); - bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_copy_bc, 0); + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_copy_bc, 0 + ); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_copy_bc, 0 + ); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, maxwell_copy_bc, 0 + ); } } } @@ -274,7 +344,7 @@ ten_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const st for (int d = 0; d < 2; d++) { long vol = bdata->skin_ghost.lower_skin[d].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -285,8 +355,9 @@ ten_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const st bdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } -void -ten_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn) +void ten_moment_nested_block_bc_updaters_init( + struct five_moment_block_data *bdata, const struct gkyl_block_connections *conn +) { int nghost[25]; for (int i = 0; i < 25; i++) { @@ -306,40 +377,59 @@ ten_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, c if ((d == 0 && wall_x) || (d == 1 && wall_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_wall_bc, 0); - bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_wall_bc, 0); - bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_wall_bc, 0); + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_wall_bc, 0 + ); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_wall_bc, 0 + ); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, maxwell_wall_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_wall_bc, 0); - bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_wall_bc, 0); - bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_wall_bc, 0); + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_wall_bc, 0 + ); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_wall_bc, 0 + ); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, maxwell_wall_bc, 0 + ); } - } - else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { + } else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { - bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_copy_bc, 0); - bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_copy_bc, 0); - bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_copy_bc, 0); + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_copy_bc, 0 + ); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_copy_bc, 0 + ); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, maxwell_copy_bc, 0 + ); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { - bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_copy_bc, 0); - bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_copy_bc, 0); - bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_copy_bc, 0); + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_copy_bc, 0 + ); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_copy_bc, 0 + ); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, maxwell_copy_bc, 0 + ); } } } @@ -349,7 +439,7 @@ ten_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, c for (int d = 0; d < 2; d++) { long vol = bdata->skin_ghost.lower_skin[d].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -360,8 +450,7 @@ ten_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, c bdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } -void -five_moment_block_bc_updaters_release(struct five_moment_block_data* bdata) +void five_moment_block_bc_updaters_release(struct five_moment_block_data *bdata) { for (int d = 0; d < 2; d++) { if (bdata->lower_bc_elc[d]) { @@ -390,9 +479,10 @@ five_moment_block_bc_updaters_release(struct five_moment_block_data* bdata) gkyl_array_release(bdata->bc_buffer_maxwell); } -void -five_moment_block_bc_updaters_apply(const struct five_moment_block_data* bdata, double tm, - struct gkyl_array* fld_elc, struct gkyl_array* fld_ion, struct gkyl_array* fld_maxwell) +void five_moment_block_bc_updaters_apply( + const struct five_moment_block_data *bdata, double tm, struct gkyl_array *fld_elc, + struct gkyl_array *fld_ion, struct gkyl_array *fld_maxwell +) { for (int d = 0; d < 2; d++) { if (bdata->lower_bc_elc[d]) { @@ -417,289 +507,490 @@ five_moment_block_bc_updaters_apply(const struct five_moment_block_data* bdata, } } -void -block_coupled_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void block_coupled_ll_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + double ref_factor_inv = + ((double)bdata[i].skin_ghost.lower_skin[d].volume / + (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -block_coupled_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void block_coupled_ll_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / + bdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -block_coupled_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void block_coupled_lu_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + double ref_factor_inv = + ((double)bdata[i].skin_ghost.lower_skin[d].volume / + (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -block_coupled_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void block_coupled_lu_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / + bdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -block_coupled_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void block_coupled_ul_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + double ref_factor_inv = + ((double)bdata[i].skin_ghost.upper_skin[d].volume / + (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -block_coupled_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void block_coupled_ul_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / + bdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -block_coupled_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void block_coupled_uu_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + double ref_factor_inv = + ((double)bdata[i].skin_ghost.upper_skin[d].volume / + (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -block_coupled_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void block_coupled_uu_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / + bdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_moment_block_data bdata[], - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void five_moment_sync_blocks( + const struct gkyl_block_topo *btopo, const struct five_moment_block_data bdata[], + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { int num_blocks = btopo->num_blocks; int ndim = btopo->ndim; @@ -713,41 +1004,70 @@ five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_m struct gkyl_array *bc_buffer_ion = bdata[i].bc_buffer_ion; struct gkyl_array *bc_buffer_maxwell = bdata[i].bc_buffer_maxwell; - gkyl_array_copy_to_buffer(bc_buffer_elc->data, fld_elc[i], &(bdata[i].skin_ghost.lower_skin[d])); - gkyl_array_copy_to_buffer(bc_buffer_ion->data, fld_ion[i], &(bdata[i].skin_ghost.lower_skin[d])); - gkyl_array_copy_to_buffer(bc_buffer_maxwell->data, fld_maxwell[i], &(bdata[i].skin_ghost.lower_skin[d])); + gkyl_array_copy_to_buffer( + bc_buffer_elc->data, fld_elc[i], &(bdata[i].skin_ghost.lower_skin[d]) + ); + gkyl_array_copy_to_buffer( + bc_buffer_ion->data, fld_ion[i], &(bdata[i].skin_ghost.lower_skin[d]) + ); + gkyl_array_copy_to_buffer( + bc_buffer_maxwell->data, fld_maxwell[i], &(bdata[i].skin_ghost.lower_skin[d]) + ); int tbid = te[0].bid; int tdir = te[0].dir; if (te[0].edge == GKYL_LOWER_POSITIVE) { - if (bdata[i].skin_ghost.lower_skin[d].volume == bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (bdata[i].skin_ghost.lower_skin[d].volume > bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - block_coupled_ll_restriction_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); + if (bdata[i].skin_ghost.lower_skin[d].volume == + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_maxwell[tbid], bc_buffer_maxwell->data, + &(bdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + } else if (bdata[i].skin_ghost.lower_skin[d].volume > + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + block_coupled_ll_restriction_op( + tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); + } else if (bdata[i].skin_ghost.lower_skin[d].volume < + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + block_coupled_ll_projection_op( + tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); } - else if (bdata[i].skin_ghost.lower_skin[d].volume < bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - block_coupled_ll_projection_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); - } - } - else if (te[0].edge == GKYL_UPPER_POSITIVE) { - if (bdata[i].skin_ghost.lower_skin[d].volume == bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - } - else if (bdata[i].skin_ghost.lower_skin[d].volume > bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - block_coupled_lu_restriction_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); - } - else if (bdata[i].skin_ghost.lower_skin[d].volume < bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - block_coupled_lu_projection_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); + } else if (te[0].edge == GKYL_UPPER_POSITIVE) { + if (bdata[i].skin_ghost.lower_skin[d].volume == + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_maxwell[tbid], bc_buffer_maxwell->data, + &(bdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + } else if (bdata[i].skin_ghost.lower_skin[d].volume > + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + block_coupled_lu_restriction_op( + tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); + } else if (bdata[i].skin_ghost.lower_skin[d].volume < + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + block_coupled_lu_projection_op( + tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); } } } @@ -757,41 +1077,70 @@ five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_m struct gkyl_array *bc_buffer_ion = bdata[i].bc_buffer_ion; struct gkyl_array *bc_buffer_maxwell = bdata[i].bc_buffer_maxwell; - gkyl_array_copy_to_buffer(bc_buffer_elc->data, fld_elc[i], &(bdata[i].skin_ghost.upper_skin[d])); - gkyl_array_copy_to_buffer(bc_buffer_ion->data, fld_ion[i], &(bdata[i].skin_ghost.upper_skin[d])); - gkyl_array_copy_to_buffer(bc_buffer_maxwell->data, fld_maxwell[i], &(bdata[i].skin_ghost.upper_skin[d])); + gkyl_array_copy_to_buffer( + bc_buffer_elc->data, fld_elc[i], &(bdata[i].skin_ghost.upper_skin[d]) + ); + gkyl_array_copy_to_buffer( + bc_buffer_ion->data, fld_ion[i], &(bdata[i].skin_ghost.upper_skin[d]) + ); + gkyl_array_copy_to_buffer( + bc_buffer_maxwell->data, fld_maxwell[i], &(bdata[i].skin_ghost.upper_skin[d]) + ); int tbid = te[1].bid; int tdir = te[1].dir; if (te[1].edge == GKYL_LOWER_POSITIVE) { - if (bdata[i].skin_ghost.upper_skin[d].volume == bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (bdata[i].skin_ghost.upper_skin[d].volume > bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - block_coupled_ul_restriction_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); - } - else if (bdata[i].skin_ghost.upper_skin[d].volume < bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - block_coupled_ul_projection_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); - } - } - else if (te[1].edge == GKYL_UPPER_POSITIVE) { - if (bdata[i].skin_ghost.upper_skin[d].volume == bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - } - else if (bdata[i].skin_ghost.upper_skin[d].volume > bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - block_coupled_uu_restriction_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); + if (bdata[i].skin_ghost.upper_skin[d].volume == + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_maxwell[tbid], bc_buffer_maxwell->data, + &(bdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + } else if (bdata[i].skin_ghost.upper_skin[d].volume > + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + block_coupled_ul_restriction_op( + tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); + } else if (bdata[i].skin_ghost.upper_skin[d].volume < + bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + block_coupled_ul_projection_op( + tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); } - else if (bdata[i].skin_ghost.upper_skin[d].volume < bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - block_coupled_uu_projection_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); + } else if (te[1].edge == GKYL_UPPER_POSITIVE) { + if (bdata[i].skin_ghost.upper_skin[d].volume == + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_maxwell[tbid], bc_buffer_maxwell->data, + &(bdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + } else if (bdata[i].skin_ghost.upper_skin[d].volume > + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + block_coupled_uu_restriction_op( + tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); + } else if (bdata[i].skin_ghost.upper_skin[d].volume < + bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + block_coupled_uu_projection_op( + tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); } } } @@ -799,30 +1148,31 @@ five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_m } } -void -five_moment_block_data_write(const char* file_nm_elc, const char* file_nm_ion, const char* file_nm_maxwell, const struct five_moment_block_data* bdata) +void five_moment_block_data_write( + const char *file_nm_elc, const char *file_nm_ion, const char *file_nm_maxwell, + const struct five_moment_block_data *bdata +) { gkyl_grid_sub_array_write(&bdata->grid, &bdata->range, 0, bdata->f_elc[0], file_nm_elc); gkyl_grid_sub_array_write(&bdata->grid, &bdata->range, 0, bdata->f_ion[0], file_nm_ion); gkyl_grid_sub_array_write(&bdata->grid, &bdata->range, 0, bdata->f_maxwell[0], file_nm_maxwell); } -double -five_moment_block_data_max_dt(const struct five_moment_block_data* bdata) +double five_moment_block_data_max_dt(const struct five_moment_block_data *bdata) { double dt = DBL_MAX; for (int d = 0; d < 2; d++) { dt = fmin(dt, gkyl_wave_prop_max_dt(bdata->slvr_elc[d], &bdata->range, bdata->f_elc[0])); dt = fmin(dt, gkyl_wave_prop_max_dt(bdata->slvr_ion[d], &bdata->range, bdata->f_ion[0])); - dt = fmin(dt, gkyl_wave_prop_max_dt(bdata->slvr_maxwell[d], &bdata->range, bdata->f_maxwell[0])); + dt = + fmin(dt, gkyl_wave_prop_max_dt(bdata->slvr_maxwell[d], &bdata->range, bdata->f_maxwell[0])); } return dt; } -void -five_moment_update_block_job_func(void* ctx) +void five_moment_update_block_job_func(void *ctx) { struct five_moment_update_block_ctx *ub_ctx = ctx; const struct five_moment_block_data *bdata = ub_ctx->bdata; @@ -831,15 +1181,23 @@ five_moment_update_block_job_func(void* ctx) double t_curr = ub_ctx->t_curr; double dt = ub_ctx->dt; - ub_ctx->stat_elc = gkyl_wave_prop_advance(bdata->slvr_elc[d], t_curr, dt, &bdata->range, NULL, bdata->f_elc[d], bdata->f_elc[d + 1]); - ub_ctx->stat_ion = gkyl_wave_prop_advance(bdata->slvr_ion[d], t_curr, dt, &bdata->range, NULL, bdata->f_ion[d], bdata->f_ion[d + 1]); - ub_ctx->stat_maxwell = gkyl_wave_prop_advance(bdata->slvr_maxwell[d], t_curr, dt, &bdata->range, NULL, bdata->f_maxwell[d], bdata->f_maxwell[d + 1]); - - five_moment_block_bc_updaters_apply(bdata, t_curr, bdata->f_elc[d + 1], bdata->f_ion[d + 1], bdata->f_maxwell[d + 1]); + ub_ctx->stat_elc = gkyl_wave_prop_advance( + bdata->slvr_elc[d], t_curr, dt, &bdata->range, NULL, bdata->f_elc[d], bdata->f_elc[d + 1] + ); + ub_ctx->stat_ion = gkyl_wave_prop_advance( + bdata->slvr_ion[d], t_curr, dt, &bdata->range, NULL, bdata->f_ion[d], bdata->f_ion[d + 1] + ); + ub_ctx->stat_maxwell = gkyl_wave_prop_advance( + bdata->slvr_maxwell[d], t_curr, dt, &bdata->range, NULL, bdata->f_maxwell[d], + bdata->f_maxwell[d + 1] + ); + + five_moment_block_bc_updaters_apply( + bdata, t_curr, bdata->f_elc[d + 1], bdata->f_ion[d + 1], bdata->f_maxwell[d + 1] + ); } -void -five_moment_update_block_job_func_source(void* ctx) +void five_moment_update_block_job_func_source(void *ctx) { struct five_moment_update_block_ctx *ub_ctx = ctx; const struct five_moment_block_data *bdata = ub_ctx->bdata; @@ -865,15 +1223,20 @@ five_moment_update_block_job_func_source(void* ctx) nT_source[0] = bdata->nT_source_elc; nT_source[1] = bdata->nT_source_ion; - gkyl_moment_em_coupling_implicit_advance(bdata->src_slvr, t_curr, dt, &bdata->range, fluids, app_accel, rhs_source, - bdata->f_maxwell[nstrang], bdata->app_current, bdata->ext_em, nT_source); + gkyl_moment_em_coupling_implicit_advance( + bdata->src_slvr, t_curr, dt, &bdata->range, fluids, app_accel, rhs_source, + bdata->f_maxwell[nstrang], bdata->app_current, bdata->ext_em, nT_source + ); - five_moment_block_bc_updaters_apply(bdata, t_curr, bdata->f_elc[nstrang], bdata->f_ion[nstrang], bdata->f_maxwell[nstrang]); + five_moment_block_bc_updaters_apply( + bdata, t_curr, bdata->f_elc[nstrang], bdata->f_ion[nstrang], bdata->f_maxwell[nstrang] + ); } -struct gkyl_update_status -five_moment_update_all_blocks(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* btopo, - const struct five_moment_block_data bdata[], double t_curr, double dt) +struct gkyl_update_status five_moment_update_all_blocks( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct five_moment_block_data bdata[], double t_curr, double dt +) { int num_blocks = btopo->num_blocks; int ndim = btopo->ndim; @@ -884,14 +1247,8 @@ five_moment_update_all_blocks(const struct gkyl_job_pool* job_pool, const struct struct five_moment_update_block_ctx five_moment_block_ctx[num_blocks]; for (int i = 0; i < num_blocks; i++) { - five_moment_block_ctx[i] = (struct five_moment_update_block_ctx) { - .bdata = &bdata[i], - .t_curr = t_curr, - .dir = d, - .dt = dt, - .bidx = i, - .nstrang = 0, - }; + five_moment_block_ctx[i] = (struct five_moment_update_block_ctx + ){.bdata = &bdata[i], .t_curr = t_curr, .dir = d, .dt = dt, .bidx = i, .nstrang = 0}; } #ifdef AMR_USETHREADS @@ -910,15 +1267,14 @@ five_moment_update_all_blocks(const struct gkyl_job_pool* job_pool, const struct struct gkyl_array *fld_maxwell[num_blocks]; for (int i = 0; i < num_blocks; i++) { - if (five_moment_block_ctx[i].stat_elc.success == false || five_moment_block_ctx[i].stat_ion.success == false || five_moment_block_ctx[i].stat_maxwell.success == false) { + if (five_moment_block_ctx[i].stat_elc.success == false || + five_moment_block_ctx[i].stat_ion.success == false || + five_moment_block_ctx[i].stat_maxwell.success == false) { dt_suggested = fmin(dt_suggested, five_moment_block_ctx[i].stat_elc.dt_suggested); dt_suggested = fmin(dt_suggested, five_moment_block_ctx[i].stat_ion.dt_suggested); dt_suggested = fmin(dt_suggested, five_moment_block_ctx[i].stat_maxwell.dt_suggested); - return (struct gkyl_update_status) { - .success = false, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status){.success = false, .dt_suggested = dt_suggested}; } dt_suggested = fmin(dt_suggested, five_moment_block_ctx[i].stat_elc.dt_suggested); @@ -933,34 +1289,28 @@ five_moment_update_all_blocks(const struct gkyl_job_pool* job_pool, const struct five_moment_sync_blocks(btopo, bdata, fld_elc, fld_ion, fld_maxwell); } - return (struct gkyl_update_status) { - .success = true, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status){.success = true, .dt_suggested = dt_suggested}; } -void -five_moment_update_all_blocks_source(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* btopo, - const struct five_moment_block_data bdata[], double t_curr, double dt, int nstrang) +void five_moment_update_all_blocks_source( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct five_moment_block_data bdata[], double t_curr, double dt, int nstrang +) { int num_blocks = btopo->num_blocks; struct five_moment_update_block_ctx five_moment_block_ctx[num_blocks]; for (int i = 0; i < num_blocks; i++) { - five_moment_block_ctx[i] = (struct five_moment_update_block_ctx) { - .bdata = &bdata[i], - .t_curr = t_curr, - .dir = 0, - .dt = dt, - .bidx = i, - .nstrang = nstrang, - }; + five_moment_block_ctx[i] = (struct five_moment_update_block_ctx + ){.bdata = &bdata[i], .t_curr = t_curr, .dir = 0, .dt = dt, .bidx = i, .nstrang = nstrang}; } #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(job_pool, five_moment_update_block_job_func_source, &five_moment_block_ctx[i]); + gkyl_job_pool_add_work( + job_pool, five_moment_update_block_job_func_source, &five_moment_block_ctx[i] + ); } gkyl_job_pool_wait(job_pool); #else @@ -982,8 +1332,7 @@ five_moment_update_all_blocks_source(const struct gkyl_job_pool* job_pool, const five_moment_sync_blocks(btopo, bdata, fld_elc, fld_ion, fld_maxwell); } -void -five_moment_init_job_func_block(void* ctx) +void five_moment_init_job_func_block(void *ctx) { struct five_moment_block_data *bdata = ctx; @@ -992,8 +1341,7 @@ five_moment_init_job_func_block(void* ctx) gkyl_fv_proj_advance(bdata->fv_proj_maxwell, 0.0, &bdata->ext_range, bdata->f_maxwell[0]); } -void -five_moment_copy_job_func(void* ctx) +void five_moment_copy_job_func(void *ctx) { struct five_moment_copy_job_ctx *j_ctx = ctx; @@ -1002,9 +1350,10 @@ five_moment_copy_job_func(void* ctx) gkyl_array_copy(j_ctx->out_maxwell, j_ctx->inp_maxwell); } -struct gkyl_update_status -five_moment_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* btopo, - const struct five_moment_block_data bdata[], double t_curr, double dt0, struct sim_stats* stats) +struct gkyl_update_status five_moment_update_block( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct five_moment_block_data bdata[], double t_curr, double dt0, struct sim_stats *stats +) { int num_blocks = btopo->num_blocks; double dt_suggested = DBL_MAX; @@ -1016,7 +1365,7 @@ five_moment_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl FIRST_COUPLING_UPDATE, BLOCK_UPDATE, SECOND_COUPLING_UPDATE, - UPDATE_REDO, + UPDATE_REDO } state = PRE_UPDATE; struct five_moment_copy_job_ctx five_moment_copy_ctx[num_blocks]; @@ -1027,15 +1376,14 @@ five_moment_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl state = FIRST_COUPLING_UPDATE; for (int i = 0; i < num_blocks; i++) { - five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx) { - .bidx = i, + five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx + ){.bidx = i, .inp_elc = bdata[i].f_elc[0], .inp_ion = bdata[i].f_ion[0], .inp_maxwell = bdata[i].f_maxwell[0], .out_elc = bdata[i].fdup_elc, .out_ion = bdata[i].fdup_ion, - .out_maxwell = bdata[i].fdup_maxwell, - }; + .out_maxwell = bdata[i].fdup_maxwell}; } #ifdef AMR_USETHREADS @@ -1048,44 +1396,39 @@ five_moment_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl five_moment_copy_job_func(&five_moment_copy_ctx[i]); } #endif - } - else if (state == FIRST_COUPLING_UPDATE) { + } else if (state == FIRST_COUPLING_UPDATE) { state = BLOCK_UPDATE; five_moment_update_all_blocks_source(job_pool, btopo, bdata, t_curr, 0.5 * dt, 0); - } - else if (state == BLOCK_UPDATE) { + } else if (state == BLOCK_UPDATE) { state = SECOND_COUPLING_UPDATE; - struct gkyl_update_status s = five_moment_update_all_blocks(job_pool, btopo, bdata, t_curr, dt); + struct gkyl_update_status s = + five_moment_update_all_blocks(job_pool, btopo, bdata, t_curr, dt); if (!s.success) { stats->nfail += 1; dt = s.dt_suggested; state = UPDATE_REDO; - } - else { + } else { dt_suggested = fmin(dt_suggested, s.dt_suggested); } - } - else if (state == SECOND_COUPLING_UPDATE) { + } else if (state == SECOND_COUPLING_UPDATE) { state = POST_UPDATE; five_moment_update_all_blocks_source(job_pool, btopo, bdata, t_curr, 0.5 * dt, 2); - } - else if (state == POST_UPDATE) { + } else if (state == POST_UPDATE) { state = UPDATE_DONE; for (int i = 0; i < num_blocks; i++) { - five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx) { - .bidx = i, + five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx + ){.bidx = i, .inp_elc = bdata[i].f_elc[2], .inp_ion = bdata[i].f_ion[2], .inp_maxwell = bdata[i].f_maxwell[2], .out_elc = bdata[i].f_elc[0], .out_ion = bdata[i].f_ion[0], - .out_maxwell = bdata[i].f_maxwell[0], - }; + .out_maxwell = bdata[i].f_maxwell[0]}; } #ifdef AMR_USETHREADS @@ -1098,20 +1441,18 @@ five_moment_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl five_moment_copy_job_func(&five_moment_copy_ctx[i]); } #endif - } - else if (state == UPDATE_REDO) { + } else if (state == UPDATE_REDO) { state = PRE_UPDATE; for (int i = 0; i < num_blocks; i++) { - five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx) { - .bidx = i, + five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx + ){.bidx = i, .inp_elc = bdata[i].fdup_elc, .inp_ion = bdata[i].fdup_ion, .inp_maxwell = bdata[i].fdup_maxwell, .out_elc = bdata[i].f_elc[0], .out_ion = bdata[i].f_ion[0], - .out_maxwell = bdata[i].f_maxwell[0], - }; + .out_maxwell = bdata[i].f_maxwell[0]}; } #ifdef AMR_USETHREADS @@ -1127,15 +1468,13 @@ five_moment_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl } } - return (struct gkyl_update_status) { - .success = true, - .dt_actual = dt, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status + ){.success = true, .dt_actual = dt, .dt_suggested = dt_suggested}; } -void -five_moment_write_sol_block(const char* fbase, int num_blocks, const struct five_moment_block_data bdata[]) +void five_moment_write_sol_block( + const char *fbase, int num_blocks, const struct five_moment_block_data bdata[] +) { for (int i = 0; i < num_blocks; i++) { const char *fmt_elc = "%s_elc_b%d.gkyl"; @@ -1158,8 +1497,7 @@ five_moment_write_sol_block(const char* fbase, int num_blocks, const struct five } } -double -five_moment_max_dt_block(int num_blocks, const struct five_moment_block_data bdata[]) +double five_moment_max_dt_block(int num_blocks, const struct five_moment_block_data bdata[]) { double dt = DBL_MAX; diff --git a/moments/amr/amr_core_euler.c b/moments/amr/amr_core_euler.c index 5f016a10b5..607359ac35 100644 --- a/moments/amr/amr_core_euler.c +++ b/moments/amr/amr_core_euler.c @@ -4,8 +4,7 @@ #include #include -void -euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) +void euler1d_run_single(int argc, char **argv, struct euler1d_single_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -44,43 +43,47 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) struct euler_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - - gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); - + gkyl_rect_grid_init( + &mesh_pdata[0].grid, 1, (double[]){refined_x1}, (double[]){refined_x2}, (int[]){Nx * ref_factor} + ); + + gkyl_rect_grid_init( + &mesh_pdata[1].grid, 1, (double[]){coarse_x1}, (double[]){refined_x1}, (int[]){Nx} + ); + gkyl_rect_grid_init( + &mesh_pdata[2].grid, 1, (double[]){refined_x2}, (double[]){coarse_x2}, (int[]){Nx} + ); + for (int i = 0; i < num_patches; i++) { mesh_pdata[i].fv_proj = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 5, eval, 0); } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range ); - mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_pdata[i].grid, (int[]){2}, &mesh_pdata[i].ext_range, &mesh_pdata[i].range + ); + mesh_pdata[i].geom = + gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { if (low_order_flux) { struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, + .gas_gamma = gas_gamma, .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu }; mesh_pdata[i].euler = gkyl_wv_euler_inew(&inp); - } - else { + } else { mesh_pdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } - mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); + mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); } struct gkyl_block_topo *ptopo = create_patch_topo(); @@ -118,7 +121,7 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) double fine_dt = (1.0 / ref_factor) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -132,7 +135,8 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -149,7 +153,8 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", euler_output, i); @@ -162,8 +167,7 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -174,8 +178,7 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -209,8 +212,7 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) gkyl_job_pool_release(mesh_job_pool); } -void -euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) +void euler1d_run_double(int argc, char **argv, struct euler1d_double_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -253,46 +255,57 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) struct euler_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * (ref_factor1 * ref_factor2) } ); - - gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { intermediate_x1 }, (double []) { refined_x1 }, (int []) { Nx * ref_factor1 } ); - gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { intermediate_x2 }, (int []) { Nx * ref_factor1 } ); + gkyl_rect_grid_init( + &mesh_pdata[0].grid, 1, (double[]){refined_x1}, (double[]){refined_x2}, + (int[]){Nx * (ref_factor1 * ref_factor2)} + ); + + gkyl_rect_grid_init( + &mesh_pdata[1].grid, 1, (double[]){intermediate_x1}, (double[]){refined_x1}, + (int[]){Nx * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_pdata[2].grid, 1, (double[]){refined_x2}, (double[]){intermediate_x2}, + (int[]){Nx * ref_factor1} + ); + + gkyl_rect_grid_init( + &mesh_pdata[3].grid, 1, (double[]){coarse_x1}, (double[]){intermediate_x1}, (int[]){Nx} + ); + gkyl_rect_grid_init( + &mesh_pdata[4].grid, 1, (double[]){intermediate_x2}, (double[]){coarse_x2}, (int[]){Nx} + ); - gkyl_rect_grid_init(&mesh_pdata[3].grid, 1, (double []) { coarse_x1 }, (double []) { intermediate_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&mesh_pdata[4].grid, 1, (double []) { intermediate_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); - for (int i = 0; i < num_patches; i++) { mesh_pdata[i].fv_proj = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 5, eval, 0); } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range ); - mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_pdata[i].grid, (int[]){2}, &mesh_pdata[i].ext_range, &mesh_pdata[i].range + ); + mesh_pdata[i].geom = + gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { if (low_order_flux) { struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, + .gas_gamma = gas_gamma, .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu }; mesh_pdata[i].euler = gkyl_wv_euler_inew(&inp); - } - else { + } else { mesh_pdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } - mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); + mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); } struct gkyl_block_topo *ptopo = create_nested_patch_topo(); @@ -332,7 +345,7 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -346,7 +359,8 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -355,7 +369,10 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { - printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf( + " Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, + intermediate_t_curr + ); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { @@ -371,7 +388,8 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", euler_output, i); @@ -384,8 +402,7 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -396,8 +413,7 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -431,8 +447,7 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) gkyl_job_pool_release(mesh_job_pool); } -void -euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) +void euler2d_run_single(int argc, char **argv, struct euler2d_single_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -466,7 +481,7 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) char euler_output[64]; strcpy(euler_output, init->euler_output); - + bool low_order_flux = init->low_order_flux; int num_frames = init->num_frames; @@ -483,33 +498,54 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) struct euler_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - - gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx, Ny }); + gkyl_rect_grid_init( + &mesh_bdata[0].grid, 2, (double[]){refined_x1, refined_y1}, (double[]){refined_x2, refined_y2}, + (int[]){Nx * ref_factor, Ny * ref_factor} + ); + + gkyl_rect_grid_init( + &mesh_bdata[1].grid, 2, (double[]){coarse_x1, refined_y2}, (double[]){refined_x1, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[2].grid, 2, (double[]){refined_x1, refined_y2}, (double[]){refined_x2, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[3].grid, 2, (double[]){refined_x2, refined_y2}, (double[]){coarse_x2, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[4].grid, 2, (double[]){coarse_x1, refined_y1}, (double[]){refined_x1, refined_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[5].grid, 2, (double[]){refined_x2, refined_y1}, (double[]){coarse_x2, refined_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[6].grid, 2, (double[]){coarse_x1, coarse_y1}, (double[]){refined_x1, refined_y1}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[7].grid, 2, (double[]){refined_x1, coarse_y1}, (double[]){refined_x2, refined_y1}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[8].grid, 2, (double[]){refined_x2, coarse_y1}, (double[]){coarse_x2, refined_y1}, + (int[]){Nx, Ny} + ); for (int i = 0; i < num_blocks; i++) { mesh_bdata[i].fv_proj = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 5, eval, 0); } - + for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); - mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_bdata[i].grid, (int[]){2, 2}, &mesh_bdata[i].ext_range, &mesh_bdata[i].range + ); + mesh_bdata[i].geom = + gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); mesh_bdata[i].copy_x = copy_x; mesh_bdata[i].copy_y = copy_y; @@ -521,27 +557,22 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) for (int i = 0; i < num_blocks; i++) { if (low_order_flux) { struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, + .gas_gamma = gas_gamma, .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu }; mesh_bdata[i].euler = gkyl_wv_euler_inew(&inp); - } - else { + } else { mesh_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } for (int d = 0; d < ndim; d++) { - mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); + mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); } } @@ -580,7 +611,7 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) double fine_dt = (1.0 / ref_factor) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -594,7 +625,8 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -611,7 +643,8 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", euler_output, i); @@ -624,8 +657,7 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -636,8 +668,7 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -665,9 +696,9 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) for (int d = 0; d < ndim; d++) { gkyl_wave_prop_release(mesh_bdata[i].slvr[d]); } - + gkyl_array_release(mesh_bdata[i].fdup); - + for (int d = 0; d < ndim; d++) { gkyl_array_release(mesh_bdata[i].f[d]); } @@ -677,8 +708,7 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) gkyl_job_pool_release(mesh_job_pool); } -void -euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) +void euler2d_run_double(int argc, char **argv, struct euler2d_double_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -712,13 +742,13 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) bool copy_x = init->copy_x; bool copy_y = init->copy_y; - + bool wall_x = init->wall_x; bool wall_y = init->wall_y; char euler_output[64]; strcpy(euler_output, init->euler_output); - + bool low_order_flux = init->low_order_flux; int num_frames = init->num_frames; @@ -735,66 +765,119 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) struct euler_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&mesh_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx, Ny }); + gkyl_rect_grid_init( + &mesh_bdata[0].grid, 2, (double[]){refined_x1, refined_y1}, (double[]){refined_x2, refined_y2}, + (int[]){Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2)} + ); + + gkyl_rect_grid_init( + &mesh_bdata[1].grid, 2, (double[]){intermediate_x1, refined_y2}, + (double[]){refined_x1, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[2].grid, 2, (double[]){refined_x1, refined_y2}, + (double[]){refined_x2, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[3].grid, 2, (double[]){refined_x2, refined_y2}, + (double[]){intermediate_x2, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[4].grid, 2, (double[]){intermediate_x1, refined_y1}, + (double[]){refined_x1, refined_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[5].grid, 2, (double[]){refined_x2, refined_y1}, + (double[]){intermediate_x2, refined_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[6].grid, 2, (double[]){intermediate_x1, intermediate_y1}, + (double[]){refined_x1, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[7].grid, 2, (double[]){refined_x1, intermediate_y1}, + (double[]){refined_x2, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[8].grid, 2, (double[]){refined_x2, intermediate_y1}, + (double[]){intermediate_x2, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + + gkyl_rect_grid_init( + &mesh_bdata[9].grid, 2, (double[]){coarse_x1, intermediate_y2}, + (double[]){intermediate_x1, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[10].grid, 2, (double[]){intermediate_x1, intermediate_y2}, + (double[]){refined_x1, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[11].grid, 2, (double[]){refined_x1, intermediate_y2}, + (double[]){refined_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[12].grid, 2, (double[]){refined_x2, intermediate_y2}, + (double[]){intermediate_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[13].grid, 2, (double[]){intermediate_x2, intermediate_y2}, + (double[]){coarse_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[14].grid, 2, (double[]){coarse_x1, refined_y2}, + (double[]){intermediate_x1, intermediate_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[15].grid, 2, (double[]){intermediate_x2, refined_y2}, + (double[]){coarse_x2, intermediate_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[16].grid, 2, (double[]){coarse_x1, refined_y1}, + (double[]){intermediate_x1, refined_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[17].grid, 2, (double[]){intermediate_x2, refined_y1}, + (double[]){coarse_x2, refined_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[18].grid, 2, (double[]){coarse_x1, intermediate_y1}, + (double[]){intermediate_x1, refined_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[19].grid, 2, (double[]){intermediate_x2, intermediate_y1}, + (double[]){coarse_x2, refined_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[20].grid, 2, (double[]){coarse_x1, coarse_y1}, + (double[]){intermediate_x1, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[21].grid, 2, (double[]){intermediate_x1, coarse_y1}, + (double[]){refined_x1, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[22].grid, 2, (double[]){refined_x1, coarse_y1}, + (double[]){refined_x2, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[23].grid, 2, (double[]){refined_x2, coarse_y1}, + (double[]){intermediate_x2, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[24].grid, 2, (double[]){intermediate_x2, coarse_y1}, + (double[]){coarse_x2, intermediate_y1}, (int[]){Nx, Ny} + ); for (int i = 0; i < num_blocks; i++) { mesh_bdata[i].fv_proj = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 5, eval, 0); } - + for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); - mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_bdata[i].grid, (int[]){2, 2}, &mesh_bdata[i].ext_range, &mesh_bdata[i].range + ); + mesh_bdata[i].geom = + gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); mesh_bdata[i].copy_x = copy_x; mesh_bdata[i].copy_y = copy_y; @@ -806,27 +889,22 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) for (int i = 0; i < num_blocks; i++) { if (low_order_flux) { struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, + .gas_gamma = gas_gamma, .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu }; mesh_bdata[i].euler = gkyl_wv_euler_inew(&inp); - } - else { + } else { mesh_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } for (int d = 0; d < ndim; d++) { - mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); + mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); } } @@ -867,7 +945,7 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -881,7 +959,8 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -890,7 +969,10 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { - printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf( + " Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, + intermediate_t_curr + ); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { @@ -906,7 +988,8 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", euler_output, i); @@ -919,8 +1002,7 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -931,8 +1013,7 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -960,9 +1041,9 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) for (int d = 0; d < ndim; d++) { gkyl_wave_prop_release(mesh_bdata[i].slvr[d]); } - + gkyl_array_release(mesh_bdata[i].fdup); - + for (int d = 0; d < ndim; d++) { gkyl_array_release(mesh_bdata[i].f[d]); } diff --git a/moments/amr/amr_core_euler_mixture.c b/moments/amr/amr_core_euler_mixture.c index 6cd1d6e9cc..7256571d8b 100644 --- a/moments/amr/amr_core_euler_mixture.c +++ b/moments/amr/amr_core_euler_mixture.c @@ -4,8 +4,7 @@ #include #include -void -euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_init* init) +void euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -45,33 +44,41 @@ euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_ struct euler_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - - gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); - + gkyl_rect_grid_init( + &mesh_pdata[0].grid, 1, (double[]){refined_x1}, (double[]){refined_x2}, (int[]){Nx * ref_factor} + ); + + gkyl_rect_grid_init( + &mesh_pdata[1].grid, 1, (double[]){coarse_x1}, (double[]){refined_x1}, (int[]){Nx} + ); + gkyl_rect_grid_init( + &mesh_pdata[2].grid, 1, (double[]){refined_x2}, (double[]){coarse_x2}, (int[]){Nx} + ); + for (int i = 0; i < num_patches; i++) { - mesh_pdata[i].fv_proj = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 4 + (2 * num_species), eval, 0); + mesh_pdata[i].fv_proj = + gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 4 + (2 * num_species), eval, 0); } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range ); - mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_pdata[i].grid, (int[]){2}, &mesh_pdata[i].ext_range, &mesh_pdata[i].range + ); + mesh_pdata[i].geom = + gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { mesh_pdata[i].euler = gkyl_wv_euler_mixture_new(num_species, gas_gamma_s, app_args.use_gpu); - mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); + mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); } struct gkyl_block_topo *ptopo = create_patch_topo(); @@ -81,10 +88,12 @@ euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_ } for (int i = 0; i < num_patches; i++) { - mesh_pdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_pdata[i].ext_range.volume); + mesh_pdata[i].fdup = + gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_pdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - mesh_pdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_pdata[i].ext_range.volume); + mesh_pdata[i].f[d] = + gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_pdata[i].ext_range.volume); } } @@ -109,7 +118,7 @@ euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_ double fine_dt = (1.0 / ref_factor) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -123,7 +132,8 @@ euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_ while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -140,7 +150,8 @@ euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_ } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", euler_mixture_output, i); @@ -153,8 +164,7 @@ euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_ if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -165,8 +175,7 @@ euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_ printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -200,8 +209,7 @@ euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_ gkyl_job_pool_release(mesh_job_pool); } -void -euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_init* init) +void euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -245,49 +253,68 @@ euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_ struct euler_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * (ref_factor1 * ref_factor2) } ); - - gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { intermediate_x1 }, (double []) { refined_x1 }, (int []) { Nx * ref_factor1 } ); - gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { intermediate_x2 }, (int []) { Nx * ref_factor1 } ); + gkyl_rect_grid_init( + &mesh_pdata[0].grid, 1, (double[]){refined_x1}, (double[]){refined_x2}, + (int[]){Nx * (ref_factor1 * ref_factor2)} + ); + + gkyl_rect_grid_init( + &mesh_pdata[1].grid, 1, (double[]){intermediate_x1}, (double[]){refined_x1}, + (int[]){Nx * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_pdata[2].grid, 1, (double[]){refined_x2}, (double[]){intermediate_x2}, + (int[]){Nx * ref_factor1} + ); + + gkyl_rect_grid_init( + &mesh_pdata[3].grid, 1, (double[]){coarse_x1}, (double[]){intermediate_x1}, (int[]){Nx} + ); + gkyl_rect_grid_init( + &mesh_pdata[4].grid, 1, (double[]){intermediate_x2}, (double[]){coarse_x2}, (int[]){Nx} + ); - gkyl_rect_grid_init(&mesh_pdata[3].grid, 1, (double []) { coarse_x1 }, (double []) { intermediate_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&mesh_pdata[4].grid, 1, (double []) { intermediate_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); - for (int i = 0; i < num_patches; i++) { - mesh_pdata[i].fv_proj = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 4 + (2 * num_species), eval, 0); + mesh_pdata[i].fv_proj = + gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 4 + (2 * num_species), eval, 0); } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range ); - mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_pdata[i].grid, (int[]){2}, &mesh_pdata[i].ext_range, &mesh_pdata[i].range + ); + mesh_pdata[i].geom = + gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { mesh_pdata[i].euler = gkyl_wv_euler_mixture_new(num_species, gas_gamma_s, app_args.use_gpu); - mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); + mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); } struct gkyl_block_topo *ptopo = create_nested_patch_topo(); for (int i = 0; i < num_patches; i++) { - euler_mixture_nested_patch_bc_updaters_init(mesh_pdata[i].euler, &mesh_pdata[i], &ptopo->conn[i]); + euler_mixture_nested_patch_bc_updaters_init( + mesh_pdata[i].euler, &mesh_pdata[i], &ptopo->conn[i] + ); } for (int i = 0; i < num_patches; i++) { - mesh_pdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_pdata[i].ext_range.volume); + mesh_pdata[i].fdup = + gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_pdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - mesh_pdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_pdata[i].ext_range.volume); + mesh_pdata[i].f[d] = + gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_pdata[i].ext_range.volume); } } @@ -314,7 +341,7 @@ euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_ double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -328,7 +355,8 @@ euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_ while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -337,7 +365,10 @@ euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_ } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { - printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf( + " Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, + intermediate_t_curr + ); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { @@ -353,7 +384,8 @@ euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_ } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", euler_mixture_output, i); @@ -366,8 +398,7 @@ euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_ if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -378,8 +409,7 @@ euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_ printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -413,8 +443,7 @@ euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_ gkyl_job_pool_release(mesh_job_pool); } -void -euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_init* init) +void euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -443,13 +472,13 @@ euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_ bool copy_x = init->copy_x; bool copy_y = init->copy_y; - + bool wall_x = init->wall_x; bool wall_y = init->wall_y; char euler_mixture_output[64]; strcpy(euler_mixture_output, init->euler_mixture_output); - + bool low_order_flux = init->low_order_flux; int num_frames = init->num_frames; @@ -466,33 +495,55 @@ euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_ struct euler_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - - gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx, Ny }); + gkyl_rect_grid_init( + &mesh_bdata[0].grid, 2, (double[]){refined_x1, refined_y1}, (double[]){refined_x2, refined_y2}, + (int[]){Nx * ref_factor, Ny * ref_factor} + ); + + gkyl_rect_grid_init( + &mesh_bdata[1].grid, 2, (double[]){coarse_x1, refined_y2}, (double[]){refined_x1, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[2].grid, 2, (double[]){refined_x1, refined_y2}, (double[]){refined_x2, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[3].grid, 2, (double[]){refined_x2, refined_y2}, (double[]){coarse_x2, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[4].grid, 2, (double[]){coarse_x1, refined_y1}, (double[]){refined_x1, refined_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[5].grid, 2, (double[]){refined_x2, refined_y1}, (double[]){coarse_x2, refined_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[6].grid, 2, (double[]){coarse_x1, coarse_y1}, (double[]){refined_x1, refined_y1}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[7].grid, 2, (double[]){refined_x1, coarse_y1}, (double[]){refined_x2, refined_y1}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[8].grid, 2, (double[]){refined_x2, coarse_y1}, (double[]){coarse_x2, refined_y1}, + (int[]){Nx, Ny} + ); for (int i = 0; i < num_blocks; i++) { - mesh_bdata[i].fv_proj = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 4 + (2 * num_species), eval, 0); + mesh_bdata[i].fv_proj = + gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 4 + (2 * num_species), eval, 0); } - + for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); - mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_bdata[i].grid, (int[]){2, 2}, &mesh_bdata[i].ext_range, &mesh_bdata[i].range + ); + mesh_bdata[i].geom = + gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); mesh_bdata[i].copy_x = copy_x; mesh_bdata[i].copy_y = copy_y; @@ -505,16 +556,14 @@ euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_ mesh_bdata[i].euler = gkyl_wv_euler_mixture_new(num_species, gas_gamma_s, app_args.use_gpu); for (int d = 0; d < ndim; d++) { - mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); + mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); } } @@ -525,10 +574,12 @@ euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_ } for (int i = 0; i < num_blocks; i++) { - mesh_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_bdata[i].ext_range.volume); + mesh_bdata[i].fdup = + gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_bdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - mesh_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_bdata[i].ext_range.volume); + mesh_bdata[i].f[d] = + gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_bdata[i].ext_range.volume); } } @@ -553,7 +604,7 @@ euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_ double fine_dt = (1.0 / ref_factor) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -567,7 +618,8 @@ euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_ while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -584,7 +636,8 @@ euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_ } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", euler_mixture_output, i); @@ -597,8 +650,7 @@ euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_ if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -609,8 +661,7 @@ euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_ printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -638,9 +689,9 @@ euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_ for (int d = 0; d < ndim; d++) { gkyl_wave_prop_release(mesh_bdata[i].slvr[d]); } - + gkyl_array_release(mesh_bdata[i].fdup); - + for (int d = 0; d < ndim; d++) { gkyl_array_release(mesh_bdata[i].f[d]); } @@ -650,8 +701,7 @@ euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_ gkyl_job_pool_release(mesh_job_pool); } -void -euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_init* init) +void euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -692,7 +742,7 @@ euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_ char euler_mixture_output[64]; strcpy(euler_mixture_output, init->euler_mixture_output); - + bool low_order_flux = init->low_order_flux; int num_frames = init->num_frames; @@ -709,66 +759,120 @@ euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_ struct euler_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&mesh_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx, Ny }); + gkyl_rect_grid_init( + &mesh_bdata[0].grid, 2, (double[]){refined_x1, refined_y1}, (double[]){refined_x2, refined_y2}, + (int[]){Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2)} + ); + + gkyl_rect_grid_init( + &mesh_bdata[1].grid, 2, (double[]){intermediate_x1, refined_y2}, + (double[]){refined_x1, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[2].grid, 2, (double[]){refined_x1, refined_y2}, + (double[]){refined_x2, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[3].grid, 2, (double[]){refined_x2, refined_y2}, + (double[]){intermediate_x2, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[4].grid, 2, (double[]){intermediate_x1, refined_y1}, + (double[]){refined_x1, refined_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[5].grid, 2, (double[]){refined_x2, refined_y1}, + (double[]){intermediate_x2, refined_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[6].grid, 2, (double[]){intermediate_x1, intermediate_y1}, + (double[]){refined_x1, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[7].grid, 2, (double[]){refined_x1, intermediate_y1}, + (double[]){refined_x2, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[8].grid, 2, (double[]){refined_x2, intermediate_y1}, + (double[]){intermediate_x2, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + + gkyl_rect_grid_init( + &mesh_bdata[9].grid, 2, (double[]){coarse_x1, intermediate_y2}, + (double[]){intermediate_x1, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[10].grid, 2, (double[]){intermediate_x1, intermediate_y2}, + (double[]){refined_x1, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[11].grid, 2, (double[]){refined_x1, intermediate_y2}, + (double[]){refined_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[12].grid, 2, (double[]){refined_x2, intermediate_y2}, + (double[]){intermediate_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[13].grid, 2, (double[]){intermediate_x2, intermediate_y2}, + (double[]){coarse_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[14].grid, 2, (double[]){coarse_x1, refined_y2}, + (double[]){intermediate_x1, intermediate_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[15].grid, 2, (double[]){intermediate_x2, refined_y2}, + (double[]){coarse_x2, intermediate_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[16].grid, 2, (double[]){coarse_x1, refined_y1}, + (double[]){intermediate_x1, refined_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[17].grid, 2, (double[]){intermediate_x2, refined_y1}, + (double[]){coarse_x2, refined_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[18].grid, 2, (double[]){coarse_x1, intermediate_y1}, + (double[]){intermediate_x1, refined_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[19].grid, 2, (double[]){intermediate_x2, intermediate_y1}, + (double[]){coarse_x2, refined_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[20].grid, 2, (double[]){coarse_x1, coarse_y1}, + (double[]){intermediate_x1, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[21].grid, 2, (double[]){intermediate_x1, coarse_y1}, + (double[]){refined_x1, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[22].grid, 2, (double[]){refined_x1, coarse_y1}, + (double[]){refined_x2, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[23].grid, 2, (double[]){refined_x2, coarse_y1}, + (double[]){intermediate_x2, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[24].grid, 2, (double[]){intermediate_x2, coarse_y1}, + (double[]){coarse_x2, intermediate_y1}, (int[]){Nx, Ny} + ); for (int i = 0; i < num_blocks; i++) { - mesh_bdata[i].fv_proj = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 4 + (2 * num_species), eval, 0); + mesh_bdata[i].fv_proj = + gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 4 + (2 * num_species), eval, 0); } - + for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); - mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_bdata[i].grid, (int[]){2, 2}, &mesh_bdata[i].ext_range, &mesh_bdata[i].range + ); + mesh_bdata[i].geom = + gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); mesh_bdata[i].copy_x = copy_x; mesh_bdata[i].copy_y = copy_y; @@ -781,30 +885,32 @@ euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_ mesh_bdata[i].euler = gkyl_wv_euler_mixture_new(num_species, gas_gamma_s, app_args.use_gpu); for (int d = 0; d < ndim; d++) { - mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); + mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); } } struct gkyl_block_topo *btopo = create_nested_block_topo(); for (int i = 0; i < num_blocks; i++) { - euler_mixture_nested_block_bc_updaters_init(mesh_bdata[i].euler, &mesh_bdata[i], &btopo->conn[i]); + euler_mixture_nested_block_bc_updaters_init( + mesh_bdata[i].euler, &mesh_bdata[i], &btopo->conn[i] + ); } for (int i = 0; i < num_blocks; i++) { - mesh_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_bdata[i].ext_range.volume); + mesh_bdata[i].fdup = + gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_bdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - mesh_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_bdata[i].ext_range.volume); + mesh_bdata[i].f[d] = + gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), mesh_bdata[i].ext_range.volume); } } @@ -831,7 +937,7 @@ euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_ double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -845,7 +951,8 @@ euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_ while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -854,7 +961,10 @@ euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_ } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { - printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf( + " Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, + intermediate_t_curr + ); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { @@ -870,7 +980,8 @@ euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_ } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", euler_mixture_output, i); @@ -883,8 +994,7 @@ euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_ if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -895,8 +1005,7 @@ euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_ printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -924,9 +1033,9 @@ euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_ for (int d = 0; d < ndim; d++) { gkyl_wave_prop_release(mesh_bdata[i].slvr[d]); } - + gkyl_array_release(mesh_bdata[i].fdup); - + for (int d = 0; d < ndim; d++) { gkyl_array_release(mesh_bdata[i].f[d]); } diff --git a/moments/amr/amr_core_five_moment.c b/moments/amr/amr_core_five_moment.c index 2abc1ef213..08a1e07eea 100644 --- a/moments/amr/amr_core_five_moment.c +++ b/moments/amr/amr_core_five_moment.c @@ -4,8 +4,7 @@ #include #include -void -five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_init* init) +void five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -59,11 +58,16 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in struct five_moment_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - - gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); + gkyl_rect_grid_init( + &mesh_pdata[0].grid, 1, (double[]){refined_x1}, (double[]){refined_x2}, (int[]){Nx * ref_factor} + ); + gkyl_rect_grid_init( + &mesh_pdata[1].grid, 1, (double[]){coarse_x1}, (double[]){refined_x1}, (int[]){Nx} + ); + gkyl_rect_grid_init( + &mesh_pdata[2].grid, 1, (double[]){refined_x2}, (double[]){coarse_x2}, (int[]){Nx} + ); for (int i = 0; i < num_patches; i++) { mesh_pdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 5, eval_elc, 0); @@ -72,75 +76,59 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range); - mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_pdata[i].grid, (int[]){2}, &mesh_pdata[i].ext_range, &mesh_pdata[i].range + ); + mesh_pdata[i].geom = + gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { if (low_order_flux) { struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, + .gas_gamma = gas_gamma, .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu }; mesh_pdata[i].euler_elc = gkyl_wv_euler_inew(&inp); mesh_pdata[i].euler_ion = gkyl_wv_euler_inew(&inp); - } - else { + } else { mesh_pdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); mesh_pdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } mesh_pdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact, app_args.use_gpu); - mesh_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); - mesh_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); - mesh_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); + mesh_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); + mesh_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); + mesh_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); struct gkyl_moment_em_coupling_inp mesh_src_inp = { - .grid = &mesh_pdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, + .grid = &mesh_pdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0 }; - mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_pdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_pdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_pdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc}; + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_pdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion}; mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } @@ -193,7 +181,7 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in double fine_dt = (1.0 / ref_factor) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -207,7 +195,8 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + five_moment_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -224,7 +213,8 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", five_moment_output, i); @@ -237,8 +227,7 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -249,8 +238,7 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -307,8 +295,7 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in gkyl_job_pool_release(mesh_job_pool); } -void -five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_init* init) +void five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -366,13 +353,26 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in struct five_moment_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * (ref_factor1 * ref_factor2) } ); - - gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { intermediate_x1 }, (double []) { refined_x1 }, (int []) { Nx * ref_factor1 } ); - gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { intermediate_x2 }, (int []) { Nx * ref_factor1 } ); - - gkyl_rect_grid_init(&mesh_pdata[3].grid, 1, (double []) { coarse_x1 }, (double []) { intermediate_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&mesh_pdata[4].grid, 1, (double []) { intermediate_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); + gkyl_rect_grid_init( + &mesh_pdata[0].grid, 1, (double[]){refined_x1}, (double[]){refined_x2}, + (int[]){Nx * (ref_factor1 * ref_factor2)} + ); + + gkyl_rect_grid_init( + &mesh_pdata[1].grid, 1, (double[]){intermediate_x1}, (double[]){refined_x1}, + (int[]){Nx * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_pdata[2].grid, 1, (double[]){refined_x2}, (double[]){intermediate_x2}, + (int[]){Nx * ref_factor1} + ); + + gkyl_rect_grid_init( + &mesh_pdata[3].grid, 1, (double[]){coarse_x1}, (double[]){intermediate_x1}, (int[]){Nx} + ); + gkyl_rect_grid_init( + &mesh_pdata[4].grid, 1, (double[]){intermediate_x2}, (double[]){coarse_x2}, (int[]){Nx} + ); for (int i = 0; i < num_patches; i++) { mesh_pdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 5, eval_elc, 0); @@ -381,75 +381,59 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range); - mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_pdata[i].grid, (int[]){2}, &mesh_pdata[i].ext_range, &mesh_pdata[i].range + ); + mesh_pdata[i].geom = + gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { if (low_order_flux) { struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, + .gas_gamma = gas_gamma, .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu }; mesh_pdata[i].euler_elc = gkyl_wv_euler_inew(&inp); mesh_pdata[i].euler_ion = gkyl_wv_euler_inew(&inp); - } - else { + } else { mesh_pdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); mesh_pdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } mesh_pdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact, app_args.use_gpu); - mesh_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); - mesh_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); - mesh_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); + mesh_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); + mesh_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); + mesh_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); struct gkyl_moment_em_coupling_inp mesh_src_inp = { - .grid = &mesh_pdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, + .grid = &mesh_pdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0 }; - mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_pdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_pdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_pdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc}; + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_pdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion}; mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } @@ -504,7 +488,7 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -518,7 +502,8 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + five_moment_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -527,7 +512,10 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { - printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf( + " Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, + intermediate_t_curr + ); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { @@ -543,7 +531,8 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", five_moment_output, i); @@ -556,8 +545,7 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -568,8 +556,7 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -626,8 +613,7 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in gkyl_job_pool_release(mesh_job_pool); } -void -five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_init* init) +void five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -679,7 +665,7 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in bool low_order_flux = init->low_order_flux; int num_frames = init->num_frames; - + double cfl_frac = init->cfl_frac; double t_end = init->t_end; double dt_failure_tol = init->dt_failure_tol; @@ -693,25 +679,43 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in struct five_moment_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - - gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx, Ny }); + gkyl_rect_grid_init( + &mesh_bdata[0].grid, 2, (double[]){refined_x1, refined_y1}, (double[]){refined_x2, refined_y2}, + (int[]){Nx * ref_factor, Ny * ref_factor} + ); + + gkyl_rect_grid_init( + &mesh_bdata[1].grid, 2, (double[]){coarse_x1, refined_y2}, (double[]){refined_x1, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[2].grid, 2, (double[]){refined_x1, refined_y2}, (double[]){refined_x2, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[3].grid, 2, (double[]){refined_x2, refined_y2}, (double[]){coarse_x2, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[4].grid, 2, (double[]){coarse_x1, refined_y1}, (double[]){refined_x1, refined_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[5].grid, 2, (double[]){refined_x2, refined_y1}, (double[]){coarse_x2, refined_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[6].grid, 2, (double[]){coarse_x1, coarse_y1}, (double[]){refined_x1, refined_y1}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[7].grid, 2, (double[]){refined_x1, coarse_y1}, (double[]){refined_x2, refined_y1}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[8].grid, 2, (double[]){refined_x2, coarse_y1}, (double[]){coarse_x2, refined_y1}, + (int[]){Nx, Ny} + ); for (int i = 0; i < num_blocks; i++) { mesh_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 5, eval_elc, 0); @@ -720,9 +724,12 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); - mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - + gkyl_create_grid_ranges( + &mesh_bdata[i].grid, (int[]){2, 2}, &mesh_bdata[i].ext_range, &mesh_bdata[i].range + ); + mesh_bdata[i].geom = + gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); + mesh_bdata[i].copy_x = copy_x; mesh_bdata[i].copy_y = copy_y; @@ -733,70 +740,51 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in for (int i = 0; i < num_blocks; i++) { if (low_order_flux) { struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, + .gas_gamma = gas_gamma, .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu }; mesh_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); mesh_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); - } - else { + } else { mesh_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); mesh_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } mesh_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact, app_args.use_gpu); for (int d = 0; d < ndim; d++) { - mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); - mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); - mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); + mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); + mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); + mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); } struct gkyl_moment_em_coupling_inp mesh_src_inp = { - .grid = &mesh_bdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, + .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0 }; - mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_bdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_bdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc}; + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion}; mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } @@ -849,7 +837,7 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in double fine_dt = (1.0 / ref_factor) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -863,7 +851,8 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -880,7 +869,8 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", five_moment_output, i); @@ -893,8 +883,7 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -905,8 +894,7 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -947,7 +935,7 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in gkyl_array_release(mesh_bdata[i].fdup_ion); gkyl_array_release(mesh_bdata[i].fdup_maxwell); - for(int d = 0; d < ndim; d++) { + for (int d = 0; d < ndim; d++) { gkyl_array_release(mesh_bdata[i].f_elc[d]); gkyl_array_release(mesh_bdata[i].f_ion[d]); gkyl_array_release(mesh_bdata[i].f_maxwell[d]); @@ -967,8 +955,7 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in gkyl_job_pool_release(mesh_job_pool); } -void -five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_init* init) +void five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -1026,7 +1013,7 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in bool low_order_flux = init->low_order_flux; int num_frames = init->num_frames; - + double cfl_frac = init->cfl_frac; double t_end = init->t_end; double dt_failure_tol = init->dt_failure_tol; @@ -1040,58 +1027,108 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in struct five_moment_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&mesh_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx, Ny }); + gkyl_rect_grid_init( + &mesh_bdata[0].grid, 2, (double[]){refined_x1, refined_y1}, (double[]){refined_x2, refined_y2}, + (int[]){Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2)} + ); + + gkyl_rect_grid_init( + &mesh_bdata[1].grid, 2, (double[]){intermediate_x1, refined_y2}, + (double[]){refined_x1, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[2].grid, 2, (double[]){refined_x1, refined_y2}, + (double[]){refined_x2, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[3].grid, 2, (double[]){refined_x2, refined_y2}, + (double[]){intermediate_x2, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[4].grid, 2, (double[]){intermediate_x1, refined_y1}, + (double[]){refined_x1, refined_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[5].grid, 2, (double[]){refined_x2, refined_y1}, + (double[]){intermediate_x2, refined_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[6].grid, 2, (double[]){intermediate_x1, intermediate_y1}, + (double[]){refined_x1, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[7].grid, 2, (double[]){refined_x1, intermediate_y1}, + (double[]){refined_x2, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[8].grid, 2, (double[]){refined_x2, intermediate_y1}, + (double[]){intermediate_x2, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + + gkyl_rect_grid_init( + &mesh_bdata[9].grid, 2, (double[]){coarse_x1, intermediate_y2}, + (double[]){intermediate_x1, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[10].grid, 2, (double[]){intermediate_x1, intermediate_y2}, + (double[]){refined_x1, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[11].grid, 2, (double[]){refined_x1, intermediate_y2}, + (double[]){refined_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[12].grid, 2, (double[]){refined_x2, intermediate_y2}, + (double[]){intermediate_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[13].grid, 2, (double[]){intermediate_x2, intermediate_y2}, + (double[]){coarse_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[14].grid, 2, (double[]){coarse_x1, refined_y2}, + (double[]){intermediate_x1, intermediate_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[15].grid, 2, (double[]){intermediate_x2, refined_y2}, + (double[]){coarse_x2, intermediate_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[16].grid, 2, (double[]){coarse_x1, refined_y1}, + (double[]){intermediate_x1, refined_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[17].grid, 2, (double[]){intermediate_x2, refined_y1}, + (double[]){coarse_x2, refined_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[18].grid, 2, (double[]){coarse_x1, intermediate_y1}, + (double[]){intermediate_x1, refined_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[19].grid, 2, (double[]){intermediate_x2, intermediate_y1}, + (double[]){coarse_x2, refined_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[20].grid, 2, (double[]){coarse_x1, coarse_y1}, + (double[]){intermediate_x1, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[21].grid, 2, (double[]){intermediate_x1, coarse_y1}, + (double[]){refined_x1, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[22].grid, 2, (double[]){refined_x1, coarse_y1}, + (double[]){refined_x2, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[23].grid, 2, (double[]){refined_x2, coarse_y1}, + (double[]){intermediate_x2, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[24].grid, 2, (double[]){intermediate_x2, coarse_y1}, + (double[]){coarse_x2, intermediate_y1}, (int[]){Nx, Ny} + ); for (int i = 0; i < num_blocks; i++) { mesh_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 5, eval_elc, 0); @@ -1100,9 +1137,12 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); - mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - + gkyl_create_grid_ranges( + &mesh_bdata[i].grid, (int[]){2, 2}, &mesh_bdata[i].ext_range, &mesh_bdata[i].range + ); + mesh_bdata[i].geom = + gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); + mesh_bdata[i].copy_x = copy_x; mesh_bdata[i].copy_y = copy_y; @@ -1113,70 +1153,51 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in for (int i = 0; i < num_blocks; i++) { if (low_order_flux) { struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, + .gas_gamma = gas_gamma, .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu }; mesh_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); mesh_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); - } - else { + } else { mesh_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); mesh_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } mesh_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact, app_args.use_gpu); for (int d = 0; d < ndim; d++) { - mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); - mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); - mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); + mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); + mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); + mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); } struct gkyl_moment_em_coupling_inp mesh_src_inp = { - .grid = &mesh_bdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, + .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0 }; - mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_bdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_bdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc}; + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion}; mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } @@ -1231,7 +1252,7 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -1245,7 +1266,8 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -1254,7 +1276,10 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { - printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf( + " Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, + intermediate_t_curr + ); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { @@ -1270,7 +1295,8 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", five_moment_output, i); @@ -1283,8 +1309,7 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -1295,8 +1320,7 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -1337,7 +1361,7 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in gkyl_array_release(mesh_bdata[i].fdup_ion); gkyl_array_release(mesh_bdata[i].fdup_maxwell); - for(int d = 0; d < ndim; d++) { + for (int d = 0; d < ndim; d++) { gkyl_array_release(mesh_bdata[i].f_elc[d]); gkyl_array_release(mesh_bdata[i].f_ion[d]); gkyl_array_release(mesh_bdata[i].f_maxwell[d]); diff --git a/moments/amr/amr_core_gr_euler.c b/moments/amr/amr_core_gr_euler.c index 325c0ea57c..bd6d8fdec9 100644 --- a/moments/amr/amr_core_gr_euler.c +++ b/moments/amr/amr_core_gr_euler.c @@ -4,8 +4,7 @@ #include #include -void -gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init) +void gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -45,33 +44,41 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init struct euler_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - - gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); - + gkyl_rect_grid_init( + &mesh_pdata[0].grid, 1, (double[]){refined_x1}, (double[]){refined_x2}, (int[]){Nx * ref_factor} + ); + + gkyl_rect_grid_init( + &mesh_pdata[1].grid, 1, (double[]){coarse_x1}, (double[]){refined_x1}, (int[]){Nx} + ); + gkyl_rect_grid_init( + &mesh_pdata[2].grid, 1, (double[]){refined_x2}, (double[]){coarse_x2}, (int[]){Nx} + ); + for (int i = 0; i < num_patches; i++) { mesh_pdata[i].fv_proj = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 29, eval, 0); } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range ); - mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_pdata[i].grid, (int[]){2}, &mesh_pdata[i].ext_range, &mesh_pdata[i].range + ); + mesh_pdata[i].geom = + gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { - mesh_pdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 100, spacetime, app_args.use_gpu); - - mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); + mesh_pdata[i].euler = + gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 100, spacetime, app_args.use_gpu); + + mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); } struct gkyl_block_topo *ptopo = create_patch_topo(); @@ -109,7 +116,7 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init double fine_dt = (1.0 / ref_factor) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -123,7 +130,8 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -140,7 +148,8 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", gr_euler_output, i); @@ -153,8 +162,7 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -165,8 +173,7 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -201,8 +208,7 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init gkyl_job_pool_release(mesh_job_pool); } -void -gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init) +void gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -246,36 +252,51 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init struct euler_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * (ref_factor1 * ref_factor2) } ); - - gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { intermediate_x1 }, (double []) { refined_x1 }, (int []) { Nx * ref_factor1 } ); - gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { intermediate_x2 }, (int []) { Nx * ref_factor1 } ); + gkyl_rect_grid_init( + &mesh_pdata[0].grid, 1, (double[]){refined_x1}, (double[]){refined_x2}, + (int[]){Nx * (ref_factor1 * ref_factor2)} + ); + + gkyl_rect_grid_init( + &mesh_pdata[1].grid, 1, (double[]){intermediate_x1}, (double[]){refined_x1}, + (int[]){Nx * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_pdata[2].grid, 1, (double[]){refined_x2}, (double[]){intermediate_x2}, + (int[]){Nx * ref_factor1} + ); + + gkyl_rect_grid_init( + &mesh_pdata[3].grid, 1, (double[]){coarse_x1}, (double[]){intermediate_x1}, (int[]){Nx} + ); + gkyl_rect_grid_init( + &mesh_pdata[4].grid, 1, (double[]){intermediate_x2}, (double[]){coarse_x2}, (int[]){Nx} + ); - gkyl_rect_grid_init(&mesh_pdata[3].grid, 1, (double []) { coarse_x1 }, (double []) { intermediate_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&mesh_pdata[4].grid, 1, (double []) { intermediate_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); - for (int i = 0; i < num_patches; i++) { mesh_pdata[i].fv_proj = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 29, eval, 0); } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range ); - mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_pdata[i].grid, (int[]){2}, &mesh_pdata[i].ext_range, &mesh_pdata[i].range + ); + mesh_pdata[i].geom = + gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { - mesh_pdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 100, spacetime, app_args.use_gpu); - - mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); + mesh_pdata[i].euler = + gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 100, spacetime, app_args.use_gpu); + + mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); } struct gkyl_block_topo *ptopo = create_nested_patch_topo(); @@ -315,7 +336,7 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -329,7 +350,8 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -338,7 +360,10 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { - printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf( + " Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, + intermediate_t_curr + ); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { @@ -354,7 +379,8 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", gr_euler_output, i); @@ -367,8 +393,7 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -379,8 +404,7 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -415,8 +439,7 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init gkyl_job_pool_release(mesh_job_pool); } -void -gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init) +void gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -445,13 +468,13 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init bool copy_x = init->copy_x; bool copy_y = init->copy_y; - + bool wall_x = init->wall_x; bool wall_y = init->wall_y; char gr_euler_output[64]; strcpy(gr_euler_output, init->gr_euler_output); - + bool low_order_flux = init->low_order_flux; int num_frames = init->num_frames; @@ -468,33 +491,54 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init struct euler_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - - gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx, Ny }); + gkyl_rect_grid_init( + &mesh_bdata[0].grid, 2, (double[]){refined_x1, refined_y1}, (double[]){refined_x2, refined_y2}, + (int[]){Nx * ref_factor, Ny * ref_factor} + ); + + gkyl_rect_grid_init( + &mesh_bdata[1].grid, 2, (double[]){coarse_x1, refined_y2}, (double[]){refined_x1, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[2].grid, 2, (double[]){refined_x1, refined_y2}, (double[]){refined_x2, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[3].grid, 2, (double[]){refined_x2, refined_y2}, (double[]){coarse_x2, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[4].grid, 2, (double[]){coarse_x1, refined_y1}, (double[]){refined_x1, refined_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[5].grid, 2, (double[]){refined_x2, refined_y1}, (double[]){coarse_x2, refined_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[6].grid, 2, (double[]){coarse_x1, coarse_y1}, (double[]){refined_x1, refined_y1}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[7].grid, 2, (double[]){refined_x1, coarse_y1}, (double[]){refined_x2, refined_y1}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[8].grid, 2, (double[]){refined_x2, coarse_y1}, (double[]){coarse_x2, refined_y1}, + (int[]){Nx, Ny} + ); for (int i = 0; i < num_blocks; i++) { mesh_bdata[i].fv_proj = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 29, eval, 0); } - + for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); - mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_bdata[i].grid, (int[]){2, 2}, &mesh_bdata[i].ext_range, &mesh_bdata[i].range + ); + mesh_bdata[i].geom = + gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); mesh_bdata[i].copy_x = copy_x; mesh_bdata[i].copy_y = copy_y; @@ -504,19 +548,18 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init } for (int i = 0; i < num_blocks; i++) { - mesh_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 100, spacetime, app_args.use_gpu); + mesh_bdata[i].euler = + gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 100, spacetime, app_args.use_gpu); for (int d = 0; d < ndim; d++) { - mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); + mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); } } @@ -555,7 +598,7 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init double fine_dt = (1.0 / ref_factor) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -569,7 +612,8 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -586,7 +630,8 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", gr_euler_output, i); @@ -599,8 +644,7 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -611,8 +655,7 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -640,9 +683,9 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init for (int d = 0; d < ndim; d++) { gkyl_wave_prop_release(mesh_bdata[i].slvr[d]); } - + gkyl_array_release(mesh_bdata[i].fdup); - + for (int d = 0; d < ndim; d++) { gkyl_array_release(mesh_bdata[i].f[d]); } @@ -653,8 +696,7 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init gkyl_job_pool_release(mesh_job_pool); } -void -gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init) +void gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -689,13 +731,13 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init bool copy_x = init->copy_x; bool copy_y = init->copy_y; - + bool wall_x = init->wall_x; bool wall_y = init->wall_y; char gr_euler_output[64]; strcpy(gr_euler_output, init->gr_euler_output); - + bool low_order_flux = init->low_order_flux; int num_frames = init->num_frames; @@ -712,67 +754,120 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init struct euler_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&mesh_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx, Ny }); + gkyl_rect_grid_init( + &mesh_bdata[0].grid, 2, (double[]){refined_x1, refined_y1}, (double[]){refined_x2, refined_y2}, + (int[]){Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2)} + ); + + gkyl_rect_grid_init( + &mesh_bdata[1].grid, 2, (double[]){intermediate_x1, refined_y2}, + (double[]){refined_x1, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[2].grid, 2, (double[]){refined_x1, refined_y2}, + (double[]){refined_x2, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[3].grid, 2, (double[]){refined_x2, refined_y2}, + (double[]){intermediate_x2, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[4].grid, 2, (double[]){intermediate_x1, refined_y1}, + (double[]){refined_x1, refined_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[5].grid, 2, (double[]){refined_x2, refined_y1}, + (double[]){intermediate_x2, refined_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[6].grid, 2, (double[]){intermediate_x1, intermediate_y1}, + (double[]){refined_x1, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[7].grid, 2, (double[]){refined_x1, intermediate_y1}, + (double[]){refined_x2, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[8].grid, 2, (double[]){refined_x2, intermediate_y1}, + (double[]){intermediate_x2, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + + gkyl_rect_grid_init( + &mesh_bdata[9].grid, 2, (double[]){coarse_x1, intermediate_y2}, + (double[]){intermediate_x1, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[10].grid, 2, (double[]){intermediate_x1, intermediate_y2}, + (double[]){refined_x1, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[11].grid, 2, (double[]){refined_x1, intermediate_y2}, + (double[]){refined_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[12].grid, 2, (double[]){refined_x2, intermediate_y2}, + (double[]){intermediate_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[13].grid, 2, (double[]){intermediate_x2, intermediate_y2}, + (double[]){coarse_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[14].grid, 2, (double[]){coarse_x1, refined_y2}, + (double[]){intermediate_x1, intermediate_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[15].grid, 2, (double[]){intermediate_x2, refined_y2}, + (double[]){coarse_x2, intermediate_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[16].grid, 2, (double[]){coarse_x1, refined_y1}, + (double[]){intermediate_x1, refined_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[17].grid, 2, (double[]){intermediate_x2, refined_y1}, + (double[]){coarse_x2, refined_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[18].grid, 2, (double[]){coarse_x1, intermediate_y1}, + (double[]){intermediate_x1, refined_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[19].grid, 2, (double[]){intermediate_x2, intermediate_y1}, + (double[]){coarse_x2, refined_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[20].grid, 2, (double[]){coarse_x1, coarse_y1}, + (double[]){intermediate_x1, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[21].grid, 2, (double[]){intermediate_x1, coarse_y1}, + (double[]){refined_x1, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[22].grid, 2, (double[]){refined_x1, coarse_y1}, + (double[]){refined_x2, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[23].grid, 2, (double[]){refined_x2, coarse_y1}, + (double[]){intermediate_x2, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[24].grid, 2, (double[]){intermediate_x2, coarse_y1}, + (double[]){coarse_x2, intermediate_y1}, (int[]){Nx, Ny} + ); for (int i = 0; i < num_blocks; i++) { mesh_bdata[i].fv_proj = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 29, eval, 0); } - + for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); - mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - + gkyl_create_grid_ranges( + &mesh_bdata[i].grid, (int[]){2, 2}, &mesh_bdata[i].ext_range, &mesh_bdata[i].range + ); + mesh_bdata[i].geom = + gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); + mesh_bdata[i].copy_x = copy_x; mesh_bdata[i].copy_y = copy_y; @@ -781,19 +876,18 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init } for (int i = 0; i < num_blocks; i++) { - mesh_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 100, spacetime, app_args.use_gpu); + mesh_bdata[i].euler = + gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 100, spacetime, app_args.use_gpu); for (int d = 0; d < ndim; d++) { - mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); + mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); } } @@ -834,7 +928,7 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -848,7 +942,8 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -857,7 +952,10 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { - printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf( + " Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, + intermediate_t_curr + ); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { @@ -873,7 +971,8 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", gr_euler_output, i); @@ -886,8 +985,7 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -898,8 +996,7 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -927,9 +1024,9 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init for (int d = 0; d < ndim; d++) { gkyl_wave_prop_release(mesh_bdata[i].slvr[d]); } - + gkyl_array_release(mesh_bdata[i].fdup); - + for (int d = 0; d < ndim; d++) { gkyl_array_release(mesh_bdata[i].f[d]); } diff --git a/moments/amr/amr_core_ten_moment.c b/moments/amr/amr_core_ten_moment.c index c9b5fd9e6b..1df3b782a1 100644 --- a/moments/amr/amr_core_ten_moment.c +++ b/moments/amr/amr_core_ten_moment.c @@ -4,8 +4,7 @@ #include #include -void -ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init* init) +void ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -58,11 +57,16 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init struct five_moment_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - - gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); + gkyl_rect_grid_init( + &mesh_pdata[0].grid, 1, (double[]){refined_x1}, (double[]){refined_x2}, (int[]){Nx * ref_factor} + ); + gkyl_rect_grid_init( + &mesh_pdata[1].grid, 1, (double[]){coarse_x1}, (double[]){refined_x1}, (int[]){Nx} + ); + gkyl_rect_grid_init( + &mesh_pdata[2].grid, 1, (double[]){refined_x2}, (double[]){coarse_x2}, (int[]){Nx} + ); for (int i = 0; i < num_patches; i++) { mesh_pdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 10, eval_elc, 0); @@ -71,8 +75,11 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range); - mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges( + &mesh_pdata[i].grid, (int[]){2}, &mesh_pdata[i].ext_range, &mesh_pdata[i].range + ); + mesh_pdata[i].geom = + gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { @@ -80,57 +87,47 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init mesh_pdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion, false, false, 0, 0, app_args.use_gpu); mesh_pdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact, app_args.use_gpu); - mesh_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); - mesh_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); - mesh_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_pdata[i].grid, - .equation = mesh_pdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = mesh_pdata[i].geom, - } - ); + mesh_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); + mesh_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); + mesh_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {0}, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom}); struct gkyl_moment_em_coupling_inp mesh_src_inp = { - .grid = &mesh_pdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, + .grid = &mesh_pdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0 }; - mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_pdata[i].euler_elc->type, + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_pdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, //.k0 = k0_elc, - .k0 = 0.0, - }; - mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_pdata[i].euler_ion->type, + .k0 = 0.0}; + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_pdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, //.k0 = k0_ion, - .k0 = 0.0, - }; + .k0 = 0.0}; mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } @@ -183,7 +180,7 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init double fine_dt = (1.0 / ref_factor) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -197,7 +194,8 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + five_moment_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -214,7 +212,8 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", ten_moment_output, i); @@ -227,8 +226,7 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -239,8 +237,7 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -297,8 +294,7 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init gkyl_job_pool_release(mesh_job_pool); } -void -ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init* init) +void ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -363,25 +359,43 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init struct five_moment_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - - gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx, Ny }); + gkyl_rect_grid_init( + &mesh_bdata[0].grid, 2, (double[]){refined_x1, refined_y1}, (double[]){refined_x2, refined_y2}, + (int[]){Nx * ref_factor, Ny * ref_factor} + ); + + gkyl_rect_grid_init( + &mesh_bdata[1].grid, 2, (double[]){coarse_x1, refined_y2}, (double[]){refined_x1, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[2].grid, 2, (double[]){refined_x1, refined_y2}, (double[]){refined_x2, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[3].grid, 2, (double[]){refined_x2, refined_y2}, (double[]){coarse_x2, coarse_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[4].grid, 2, (double[]){coarse_x1, refined_y1}, (double[]){refined_x1, refined_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[5].grid, 2, (double[]){refined_x2, refined_y1}, (double[]){coarse_x2, refined_y2}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[6].grid, 2, (double[]){coarse_x1, coarse_y1}, (double[]){refined_x1, refined_y1}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[7].grid, 2, (double[]){refined_x1, coarse_y1}, (double[]){refined_x2, refined_y1}, + (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[8].grid, 2, (double[]){refined_x2, coarse_y1}, (double[]){coarse_x2, refined_y1}, + (int[]){Nx, Ny} + ); for (int i = 0; i < num_blocks; i++) { mesh_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 10, eval_elc, 0); @@ -390,9 +404,12 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); - mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - + gkyl_create_grid_ranges( + &mesh_bdata[i].grid, (int[]){2, 2}, &mesh_bdata[i].ext_range, &mesh_bdata[i].range + ); + mesh_bdata[i].geom = + gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); + mesh_bdata[i].copy_x = copy_x; mesh_bdata[i].copy_y = copy_y; @@ -406,56 +423,40 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init mesh_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact, app_args.use_gpu); for (int d = 0; d < ndim; d++) { - mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); - mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); - mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); + mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); + mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); + mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); } struct gkyl_moment_em_coupling_inp mesh_src_inp = { - .grid = &mesh_bdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, + .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0 }; - mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_bdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_bdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc}; + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion}; mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } @@ -508,7 +509,7 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init double fine_dt = (1.0 / ref_factor) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -522,7 +523,8 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -539,7 +541,8 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", ten_moment_output, i); @@ -552,8 +555,7 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -564,8 +566,7 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -606,7 +607,7 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init gkyl_array_release(mesh_bdata[i].fdup_ion); gkyl_array_release(mesh_bdata[i].fdup_maxwell); - for(int d = 0; d < ndim; d++) { + for (int d = 0; d < ndim; d++) { gkyl_array_release(mesh_bdata[i].f_elc[d]); gkyl_array_release(mesh_bdata[i].f_ion[d]); gkyl_array_release(mesh_bdata[i].f_maxwell[d]); @@ -626,8 +627,7 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init gkyl_job_pool_release(mesh_job_pool); } -void -ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init* init) +void ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init *init) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -685,7 +685,7 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init bool low_order_flux = init->low_order_flux; int num_frames = init->num_frames; - + double cfl_frac = init->cfl_frac; double t_end = init->t_end; double dt_failure_tol = init->dt_failure_tol; @@ -699,58 +699,108 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init struct five_moment_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); - gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&mesh_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&mesh_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx, Ny }); + gkyl_rect_grid_init( + &mesh_bdata[0].grid, 2, (double[]){refined_x1, refined_y1}, (double[]){refined_x2, refined_y2}, + (int[]){Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2)} + ); + + gkyl_rect_grid_init( + &mesh_bdata[1].grid, 2, (double[]){intermediate_x1, refined_y2}, + (double[]){refined_x1, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[2].grid, 2, (double[]){refined_x1, refined_y2}, + (double[]){refined_x2, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[3].grid, 2, (double[]){refined_x2, refined_y2}, + (double[]){intermediate_x2, intermediate_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[4].grid, 2, (double[]){intermediate_x1, refined_y1}, + (double[]){refined_x1, refined_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[5].grid, 2, (double[]){refined_x2, refined_y1}, + (double[]){intermediate_x2, refined_y2}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[6].grid, 2, (double[]){intermediate_x1, intermediate_y1}, + (double[]){refined_x1, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[7].grid, 2, (double[]){refined_x1, intermediate_y1}, + (double[]){refined_x2, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + gkyl_rect_grid_init( + &mesh_bdata[8].grid, 2, (double[]){refined_x2, intermediate_y1}, + (double[]){intermediate_x2, refined_y1}, (int[]){Nx * ref_factor1, Ny * ref_factor1} + ); + + gkyl_rect_grid_init( + &mesh_bdata[9].grid, 2, (double[]){coarse_x1, intermediate_y2}, + (double[]){intermediate_x1, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[10].grid, 2, (double[]){intermediate_x1, intermediate_y2}, + (double[]){refined_x1, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[11].grid, 2, (double[]){refined_x1, intermediate_y2}, + (double[]){refined_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[12].grid, 2, (double[]){refined_x2, intermediate_y2}, + (double[]){intermediate_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[13].grid, 2, (double[]){intermediate_x2, intermediate_y2}, + (double[]){coarse_x2, coarse_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[14].grid, 2, (double[]){coarse_x1, refined_y2}, + (double[]){intermediate_x1, intermediate_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[15].grid, 2, (double[]){intermediate_x2, refined_y2}, + (double[]){coarse_x2, intermediate_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[16].grid, 2, (double[]){coarse_x1, refined_y1}, + (double[]){intermediate_x1, refined_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[17].grid, 2, (double[]){intermediate_x2, refined_y1}, + (double[]){coarse_x2, refined_y2}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[18].grid, 2, (double[]){coarse_x1, intermediate_y1}, + (double[]){intermediate_x1, refined_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[19].grid, 2, (double[]){intermediate_x2, intermediate_y1}, + (double[]){coarse_x2, refined_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[20].grid, 2, (double[]){coarse_x1, coarse_y1}, + (double[]){intermediate_x1, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[21].grid, 2, (double[]){intermediate_x1, coarse_y1}, + (double[]){refined_x1, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[22].grid, 2, (double[]){refined_x1, coarse_y1}, + (double[]){refined_x2, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[23].grid, 2, (double[]){refined_x2, coarse_y1}, + (double[]){intermediate_x2, intermediate_y1}, (int[]){Nx, Ny} + ); + gkyl_rect_grid_init( + &mesh_bdata[24].grid, 2, (double[]){intermediate_x2, coarse_y1}, + (double[]){coarse_x2, intermediate_y1}, (int[]){Nx, Ny} + ); for (int i = 0; i < num_blocks; i++) { mesh_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 10, eval_elc, 0); @@ -759,9 +809,12 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); - mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - + gkyl_create_grid_ranges( + &mesh_bdata[i].grid, (int[]){2, 2}, &mesh_bdata[i].ext_range, &mesh_bdata[i].range + ); + mesh_bdata[i].geom = + gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); + mesh_bdata[i].copy_x = copy_x; mesh_bdata[i].copy_y = copy_y; @@ -775,56 +828,40 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init mesh_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact, app_args.use_gpu); for (int d = 0; d < ndim; d++) { - mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); - mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); - mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &mesh_bdata[i].grid, - .equation = mesh_bdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = mesh_bdata[i].geom, - } - ); + mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); + mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); + mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = {d}, + .cfl = cfl_frac, + .geom = mesh_bdata[i].geom}); } struct gkyl_moment_em_coupling_inp mesh_src_inp = { - .grid = &mesh_bdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, + .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0 }; - mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_bdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = mesh_bdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc}; + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data + ){.type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion}; mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } @@ -879,7 +916,7 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; - struct sim_stats stats = { }; + struct sim_stats stats = {}; struct timespec tm_start = gkyl_wall_clock(); @@ -893,7 +930,8 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = + five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -902,7 +940,10 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { - printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf( + " Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, + intermediate_t_curr + ); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { @@ -918,7 +959,8 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init } for (int i = 1; i < num_frames; i++) { - if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + if (coarse_t_curr < (i * io_trigger) && + (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { char buf[64]; snprintf(buf, 64, "%s_%d", ten_moment_output, i); @@ -931,8 +973,7 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init if (dt_init < 0.0) { dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + } else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); @@ -943,8 +984,7 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); break; } - } - else { + } else { num_failures = 0; } @@ -985,7 +1025,7 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init gkyl_array_release(mesh_bdata[i].fdup_ion); gkyl_array_release(mesh_bdata[i].fdup_maxwell); - for(int d = 0; d < ndim; d++) { + for (int d = 0; d < ndim; d++) { gkyl_array_release(mesh_bdata[i].f_elc[d]); gkyl_array_release(mesh_bdata[i].f_ion[d]); gkyl_array_release(mesh_bdata[i].f_maxwell[d]); diff --git a/moments/amr/amr_patch.c b/moments/amr/amr_patch.c index c9131c0d98..91356d9cb7 100644 --- a/moments/amr/amr_patch.c +++ b/moments/amr/amr_patch.c @@ -1,15 +1,22 @@ #include #include -void -skin_ghost_ranges_init_patch(struct skin_ghost_ranges_patch* sgr, const struct gkyl_range* parent, const int* ghost) +void skin_ghost_ranges_init_patch( + struct skin_ghost_ranges_patch *sgr, const struct gkyl_range *parent, const int *ghost +) { - gkyl_skin_ghost_ranges(&sgr->lower_skin[0], &sgr->lower_ghost[0], 0, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[0], &sgr->upper_ghost[0], 0, GKYL_UPPER_EDGE, parent, ghost); + gkyl_skin_ghost_ranges( + &sgr->lower_skin[0], &sgr->lower_ghost[0], 0, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[0], &sgr->upper_ghost[0], 0, GKYL_UPPER_EDGE, parent, ghost + ); } -void -euler_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn) +void euler_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +) { int nghost[3]; for (int i = 0; i < 3; i++) { @@ -19,20 +26,22 @@ euler_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_d pdata->lower_bc[0] = pdata->upper_bc[0] = 0; if (conn->connections[0][0].edge == GKYL_PHYSICAL) { - pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - euler_copy_bc, 0); + pdata->lower_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, euler_copy_bc, 0 + ); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { - pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - euler_copy_bc, 0); + pdata->upper_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, euler_copy_bc, 0 + ); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); long buff_sz = 0; long vol = pdata->skin_ghost.lower_skin[0].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -40,8 +49,10 @@ euler_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_d pdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); } -void -euler_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn) +void euler_nested_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +) { int nghost[5]; for (int i = 0; i < 5; i++) { @@ -51,20 +62,22 @@ euler_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_ pdata->lower_bc[0] = pdata->upper_bc[0] = 0; if (conn->connections[0][0].edge == GKYL_PHYSICAL) { - pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - euler_copy_bc, 0); + pdata->lower_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, euler_copy_bc, 0 + ); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { - pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - euler_copy_bc, 0); + pdata->upper_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, euler_copy_bc, 0 + ); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); long buff_sz = 0; long vol = pdata->skin_ghost.lower_skin[0].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -72,8 +85,10 @@ euler_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_ pdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); } -void -gr_euler_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn) +void gr_euler_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +) { int nghost[3]; for (int i = 0; i < 3; i++) { @@ -83,20 +98,22 @@ gr_euler_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patc pdata->lower_bc[0] = pdata->upper_bc[0] = 0; if (conn->connections[0][0].edge == GKYL_PHYSICAL) { - pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - gr_euler_copy_bc, 0); + pdata->lower_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, gr_euler_copy_bc, 0 + ); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { - pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - gr_euler_copy_bc, 0); + pdata->upper_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, gr_euler_copy_bc, 0 + ); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); long buff_sz = 0; long vol = pdata->skin_ghost.lower_skin[0].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -104,8 +121,10 @@ gr_euler_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patc pdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 29, buff_sz); } -void -gr_euler_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn) +void gr_euler_nested_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +) { int nghost[5]; for (int i = 0; i < 5; i++) { @@ -115,20 +134,22 @@ gr_euler_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct eul pdata->lower_bc[0] = pdata->upper_bc[0] = 0; if (conn->connections[0][0].edge == GKYL_PHYSICAL) { - pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - gr_euler_copy_bc, 0); + pdata->lower_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, gr_euler_copy_bc, 0 + ); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { - pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - gr_euler_copy_bc, 0); + pdata->upper_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, gr_euler_copy_bc, 0 + ); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); long buff_sz = 0; long vol = pdata->skin_ghost.lower_skin[0].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -136,8 +157,10 @@ gr_euler_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct eul pdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 29, buff_sz); } -void -euler_mixture_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn) +void euler_mixture_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -150,20 +173,22 @@ euler_mixture_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler pdata->lower_bc[0] = pdata->upper_bc[0] = 0; if (conn->connections[0][0].edge == GKYL_PHYSICAL) { - pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - euler_mixture_copy_bc, 0); + pdata->lower_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, euler_mixture_copy_bc, 0 + ); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { - pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - euler_mixture_copy_bc, 0); + pdata->upper_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, euler_mixture_copy_bc, 0 + ); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); long buff_sz = 0; long vol = pdata->skin_ghost.lower_skin[0].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -171,8 +196,10 @@ euler_mixture_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler pdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), buff_sz); } -void -euler_mixture_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn) +void euler_mixture_nested_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -185,20 +212,22 @@ euler_mixture_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struc pdata->lower_bc[0] = pdata->upper_bc[0] = 0; if (conn->connections[0][0].edge == GKYL_PHYSICAL) { - pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - euler_mixture_copy_bc, 0); + pdata->lower_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, euler_mixture_copy_bc, 0 + ); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { - pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - euler_mixture_copy_bc, 0); + pdata->upper_bc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, euler_mixture_copy_bc, 0 + ); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); long buff_sz = 0; long vol = pdata->skin_ghost.lower_skin[0].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -206,13 +235,12 @@ euler_mixture_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struc pdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 4 + (2 * num_species), buff_sz); } -void -euler_patch_bc_updaters_release(struct euler_patch_data* pdata) +void euler_patch_bc_updaters_release(struct euler_patch_data *pdata) { if (pdata->lower_bc[0]) { gkyl_wv_apply_bc_release(pdata->lower_bc[0]); } - + if (pdata->upper_bc[0]) { gkyl_wv_apply_bc_release(pdata->upper_bc[0]); } @@ -220,8 +248,9 @@ euler_patch_bc_updaters_release(struct euler_patch_data* pdata) gkyl_array_release(pdata->bc_buffer); } -void -euler_patch_bc_updaters_apply(const struct euler_patch_data* pdata, double tm, struct gkyl_array* fld) +void euler_patch_bc_updaters_apply( + const struct euler_patch_data *pdata, double tm, struct gkyl_array *fld +) { if (pdata->lower_bc[0]) { gkyl_wv_apply_bc_advance(pdata->lower_bc[0], tm, &pdata->range, fld); @@ -232,208 +261,282 @@ euler_patch_bc_updaters_apply(const struct euler_patch_data* pdata, double tm, s } } -void -patch_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void patch_ll_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[d].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + double ref_factor_inv = + ((double)pdata[i].skin_ghost.lower_skin[d].volume / + (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), + fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -patch_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void patch_ll_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / + pdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -patch_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void patch_lu_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[d].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + double ref_factor_inv = + ((double)pdata[i].skin_ghost.lower_skin[d].volume / + (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), + fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -patch_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void patch_lu_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / + pdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -patch_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void patch_ul_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[d].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + double ref_factor_inv = + ((double)pdata[i].skin_ghost.upper_skin[d].volume / + (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), + fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -patch_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void patch_ul_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / + pdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -patch_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void patch_uu_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[d].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + double ref_factor_inv = + ((double)pdata[i].skin_ghost.upper_skin[d].volume / + (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), + fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -patch_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +void patch_uu_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / + pdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc + ); + } else { + memcpy( + gkyl_array_fetch(fld[tbid], start), + ((char *)bc_buffer->data) + + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld[tbid]->esznc + ); count += 1; } } } -void -euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch_data pdata[], struct gkyl_array* fld[]) +void euler_sync_patches( + const struct gkyl_block_topo *ptopo, const struct euler_patch_data pdata[], + struct gkyl_array *fld[] +) { int num_patches = ptopo->num_blocks; @@ -442,31 +545,36 @@ euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch if (te[0].edge != GKYL_PHYSICAL) { struct gkyl_array *bc_buffer = pdata[i].bc_buffer; - + gkyl_array_copy_to_buffer(bc_buffer->data, fld[i], &(pdata[i].skin_ghost.lower_skin[0])); int tbid = te[0].bid; int tdir = te[0].dir; if (te[0].edge == GKYL_LOWER_POSITIVE) { - if (pdata[i].skin_ghost.lower_skin[0].volume == pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (pdata[i].skin_ghost.lower_skin[0].volume > pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + if (pdata[i].skin_ghost.lower_skin[0].volume == + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + } else if (pdata[i].skin_ghost.lower_skin[0].volume > + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { patch_ll_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); - } - else if (pdata[i].skin_ghost.lower_skin[0].volume < pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + } else if (pdata[i].skin_ghost.lower_skin[0].volume < + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { patch_ll_projection_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } - } - else if (te[0].edge == GKYL_UPPER_POSITIVE) { - if (pdata[i].skin_ghost.lower_skin[0].volume == pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - } - else if (pdata[i].skin_ghost.lower_skin[0].volume > pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + } else if (te[0].edge == GKYL_UPPER_POSITIVE) { + if (pdata[i].skin_ghost.lower_skin[0].volume == + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + } else if (pdata[i].skin_ghost.lower_skin[0].volume > + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { patch_lu_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); - } - else if (pdata[i].skin_ghost.lower_skin[0].volume < pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + } else if (pdata[i].skin_ghost.lower_skin[0].volume < + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { patch_lu_projection_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } } @@ -481,24 +589,29 @@ euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch int tdir = te[1].dir; if (te[1].edge == GKYL_LOWER_POSITIVE) { - if (pdata[i].skin_ghost.upper_skin[0].volume == pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (pdata[i].skin_ghost.upper_skin[0].volume > pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + if (pdata[i].skin_ghost.upper_skin[0].volume == + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + } else if (pdata[i].skin_ghost.upper_skin[0].volume > + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { patch_ul_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); - } - else if (pdata[i].skin_ghost.upper_skin[0].volume < pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + } else if (pdata[i].skin_ghost.upper_skin[0].volume < + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { patch_ul_projection_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } - } - else if (te[1].edge == GKYL_UPPER_POSITIVE) { - if (pdata[i].skin_ghost.upper_skin[0].volume == pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - } - else if (pdata[i].skin_ghost.upper_skin[0].volume > pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + } else if (te[1].edge == GKYL_UPPER_POSITIVE) { + if (pdata[i].skin_ghost.upper_skin[0].volume == + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + } else if (pdata[i].skin_ghost.upper_skin[0].volume > + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { patch_uu_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); - } - else if (pdata[i].skin_ghost.upper_skin[0].volume < pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + } else if (pdata[i].skin_ghost.upper_skin[0].volume < + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { patch_uu_projection_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } } @@ -506,14 +619,12 @@ euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch } } -void -euler_patch_data_write(const char* file_nm, const struct euler_patch_data* pdata) +void euler_patch_data_write(const char *file_nm, const struct euler_patch_data *pdata) { gkyl_grid_sub_array_write(&pdata->grid, &pdata->range, 0, pdata->f[0], file_nm); } -double -euler_patch_data_max_dt(const struct euler_patch_data* pdata) +double euler_patch_data_max_dt(const struct euler_patch_data *pdata) { double dt = DBL_MAX; @@ -522,8 +633,7 @@ euler_patch_data_max_dt(const struct euler_patch_data* pdata) return dt; } -void -euler_update_patch_job_func(void* ctx) +void euler_update_patch_job_func(void *ctx) { struct euler_update_patch_ctx *up_ctx = ctx; const struct euler_patch_data *pdata = up_ctx->pdata; @@ -532,14 +642,17 @@ euler_update_patch_job_func(void* ctx) double t_curr = up_ctx->t_curr; double dt = up_ctx->dt; - up_ctx->stat = gkyl_wave_prop_advance(pdata->slvr[d], t_curr, dt, &pdata->range, NULL, pdata->f[d], pdata->f[d + 1]); + up_ctx->stat = gkyl_wave_prop_advance( + pdata->slvr[d], t_curr, dt, &pdata->range, NULL, pdata->f[d], pdata->f[d + 1] + ); euler_patch_bc_updaters_apply(pdata, t_curr, pdata->f[d + 1]); } -struct gkyl_update_status -euler_update_all_patches(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* ptopo, - const struct euler_patch_data pdata[], double t_curr, double dt) +struct gkyl_update_status euler_update_all_patches( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *ptopo, + const struct euler_patch_data pdata[], double t_curr, double dt +) { int num_patches = ptopo->num_blocks; double dt_suggested = DBL_MAX; @@ -547,13 +660,8 @@ euler_update_all_patches(const struct gkyl_job_pool* job_pool, const struct gkyl struct euler_update_patch_ctx euler_patch_ctx[num_patches]; for (int i = 0; i < num_patches; i++) { - euler_patch_ctx[i] = (struct euler_update_patch_ctx) { - .pdata = &pdata[i], - .t_curr = t_curr, - .dir = 0, - .dt = dt, - .pidx = i, - }; + euler_patch_ctx[i] = (struct euler_update_patch_ctx + ){.pdata = &pdata[i], .t_curr = t_curr, .dir = 0, .dt = dt, .pidx = i}; } #ifdef AMR_USETHREADS @@ -566,15 +674,13 @@ euler_update_all_patches(const struct gkyl_job_pool* job_pool, const struct gkyl euler_update_patch_job_func(&euler_patch_ctx[i]); } #endif - + struct gkyl_array *fld[num_patches]; for (int i = 0; i < num_patches; i++) { if (euler_patch_ctx[i].stat.success == false) { - return (struct gkyl_update_status) { - .success = false, - .dt_suggested = euler_patch_ctx[i].stat.dt_suggested, - }; + return (struct gkyl_update_status + ){.success = false, .dt_suggested = euler_patch_ctx[i].stat.dt_suggested}; } dt_suggested = fmin(dt_suggested, euler_patch_ctx[i].stat.dt_suggested); @@ -583,34 +689,25 @@ euler_update_all_patches(const struct gkyl_job_pool* job_pool, const struct gkyl euler_sync_patches(ptopo, pdata, fld); - return (struct gkyl_update_status) { - .success = true, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status){.success = true, .dt_suggested = dt_suggested}; } -void -euler_init_job_func_patch(void* ctx) +void euler_init_job_func_patch(void *ctx) { struct euler_patch_data *pdata = ctx; gkyl_fv_proj_advance(pdata->fv_proj, 0.0, &pdata->ext_range, pdata->f[0]); } -struct gkyl_update_status -euler_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* ptopo, - const struct euler_patch_data pdata[], double t_curr, double dt0, struct sim_stats* stats) +struct gkyl_update_status euler_update_patch( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *ptopo, + const struct euler_patch_data pdata[], double t_curr, double dt0, struct sim_stats *stats +) { int num_patches = ptopo->num_blocks; double dt_suggested = DBL_MAX; - enum { - UPDATE_DONE = 0, - PRE_UPDATE, - POST_UPDATE, - FLUID_UPDATE, - UPDATE_REDO, - } state = PRE_UPDATE; + enum { UPDATE_DONE = 0, PRE_UPDATE, POST_UPDATE, FLUID_UPDATE, UPDATE_REDO } state = PRE_UPDATE; struct copy_job_ctx euler_copy_ctx[num_patches]; double dt = dt0; @@ -620,11 +717,8 @@ euler_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl_block state = FLUID_UPDATE; for (int i = 0; i < num_patches; i++) { - euler_copy_ctx[i] = (struct copy_job_ctx) { - .bidx = i, - .inp = pdata[i].f[0], - .out = pdata[i].fdup, - }; + euler_copy_ctx[i] = + (struct copy_job_ctx){.bidx = i, .inp = pdata[i].f[0], .out = pdata[i].fdup}; } #ifdef AMR_USETHREADS @@ -637,8 +731,7 @@ euler_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl_block copy_job_func(&euler_copy_ctx[i]); } #endif - } - else if (state == FLUID_UPDATE) { + } else if (state == FLUID_UPDATE) { state = POST_UPDATE; struct gkyl_update_status s = euler_update_all_patches(job_pool, ptopo, pdata, t_curr, dt); @@ -647,20 +740,15 @@ euler_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl_block stats->nfail += 1; dt = s.dt_suggested; state = UPDATE_REDO; - } - else { + } else { dt_suggested = fmin(dt_suggested, s.dt_suggested); } - } - else if (state == POST_UPDATE) { + } else if (state == POST_UPDATE) { state = UPDATE_DONE; for (int i = 0; i < num_patches; i++) { - euler_copy_ctx[i] = (struct copy_job_ctx) { - .bidx = i, - .inp = pdata[i].f[1], - .out = pdata[i].f[0], - }; + euler_copy_ctx[i] = + (struct copy_job_ctx){.bidx = i, .inp = pdata[i].f[1], .out = pdata[i].f[0]}; } #ifdef AMR_USETHREADAS @@ -673,16 +761,12 @@ euler_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl_block copy_job_func(&euler_copy_ctx[i]); } #endif - } - else if (state == UPDATE_REDO) { + } else if (state == UPDATE_REDO) { state = PRE_UPDATE; for (int i = 0; i < num_patches; i++) { - euler_copy_ctx[i] = (struct copy_job_ctx) { - .bidx = i, - .inp = pdata[i].fdup, - .out = pdata[i].f[0], - }; + euler_copy_ctx[i] = + (struct copy_job_ctx){.bidx = i, .inp = pdata[i].fdup, .out = pdata[i].f[0]}; } #ifdef AMR_USETHREADS @@ -698,15 +782,11 @@ euler_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl_block } } - return (struct gkyl_update_status) { - .success = true, - .dt_actual = dt, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status + ){.success = true, .dt_actual = dt, .dt_suggested = dt_suggested}; } -void -euler_write_sol_patch(const char* fbase, int num_patches, const struct euler_patch_data pdata[]) +void euler_write_sol_patch(const char *fbase, int num_patches, const struct euler_patch_data pdata[]) { for (int i = 0; i < num_patches; i++) { const char *fmt = "%s_p%d.gkyl"; @@ -718,8 +798,7 @@ euler_write_sol_patch(const char* fbase, int num_patches, const struct euler_pat } } -double -euler_max_dt_patch(int num_patches, const struct euler_patch_data pdata[]) +double euler_max_dt_patch(int num_patches, const struct euler_patch_data pdata[]) { double dt = DBL_MAX; @@ -730,44 +809,54 @@ euler_max_dt_patch(int num_patches, const struct euler_patch_data pdata[]) return dt; } -struct gkyl_block_topo* -create_patch_topo() +struct gkyl_block_topo *create_patch_topo() { struct gkyl_block_topo *ptopo = gkyl_block_topo_new(1, 3); - ptopo->conn[0] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - }; - ptopo->conn[1] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - }; - ptopo->conn[2] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, - }; + ptopo->conn[0] = (struct gkyl_block_connections + ){.connections[0] = { + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }}; + ptopo->conn[1] = (struct gkyl_block_connections + ){.connections[0] = { + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, {.bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }}; + ptopo->conn[2] = (struct gkyl_block_connections + ){.connections[0] = { + {.bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} + }}; return ptopo; } -struct gkyl_block_topo* -create_nested_patch_topo() +struct gkyl_block_topo *create_nested_patch_topo() { struct gkyl_block_topo *ptopo = gkyl_block_topo_new(1, 5); - ptopo->conn[0] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - }; - ptopo->conn[1] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - }; - ptopo->conn[2] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 4, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - }; - ptopo->conn[3] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - }; - ptopo->conn[4] = (struct gkyl_block_connections) { - .connections[0] = { { .bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, - }; + ptopo->conn[0] = (struct gkyl_block_connections + ){.connections[0] = { + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }}; + ptopo->conn[1] = (struct gkyl_block_connections + ){.connections[0] = { + {.bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }}; + ptopo->conn[2] = (struct gkyl_block_connections + ){.connections[0] = { + {.bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 4, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }}; + ptopo->conn[3] = (struct gkyl_block_connections + ){.connections[0] = { + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, {.bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }}; + ptopo->conn[4] = (struct gkyl_block_connections + ){.connections[0] = { + {.bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} + }}; return ptopo; } diff --git a/moments/amr/amr_patch_coupled.c b/moments/amr/amr_patch_coupled.c index df9a50a2c7..51129ece67 100644 --- a/moments/amr/amr_patch_coupled.c +++ b/moments/amr/amr_patch_coupled.c @@ -1,8 +1,9 @@ #include #include -void -five_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn) +void five_moment_patch_bc_updaters_init( + struct five_moment_patch_data *pdata, const struct gkyl_block_connections *conn +) { int nghost[3]; for (int i = 0; i < 3; i++) { @@ -14,28 +15,38 @@ five_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const s pdata->lower_bc_maxwell[0] = pdata->upper_bc_maxwell[0] = 0; if (conn->connections[0][0].edge == GKYL_PHYSICAL) { - pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - five_moment_copy_bc, 0); - pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - five_moment_copy_bc, 0); - pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - maxwell_copy_bc, 0); + pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, five_moment_copy_bc, + 0 + ); + pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, five_moment_copy_bc, + 0 + ); + pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, maxwell_copy_bc, 0 + ); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { - pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - five_moment_copy_bc, 0); - pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - five_moment_copy_bc, 0); - pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - maxwell_copy_bc, 0); + pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, five_moment_copy_bc, + 0 + ); + pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, five_moment_copy_bc, + 0 + ); + pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, maxwell_copy_bc, 0 + ); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); long buff_sz = 0; long vol = pdata->skin_ghost.lower_skin[0].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -45,8 +56,9 @@ five_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const s pdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } -void -five_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn) +void five_moment_nested_patch_bc_updaters_init( + struct five_moment_patch_data *pdata, const struct gkyl_block_connections *conn +) { int nghost[5]; for (int i = 0; i < 5; i++) { @@ -58,28 +70,38 @@ five_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, pdata->lower_bc_maxwell[0] = pdata->upper_bc_maxwell[0] = 0; if (conn->connections[0][0].edge == GKYL_PHYSICAL) { - pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - five_moment_copy_bc, 0); - pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - five_moment_copy_bc, 0); - pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - maxwell_copy_bc, 0); + pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, five_moment_copy_bc, + 0 + ); + pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, five_moment_copy_bc, + 0 + ); + pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, maxwell_copy_bc, 0 + ); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { - pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - five_moment_copy_bc, 0); - pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - five_moment_copy_bc, 0); - pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - maxwell_copy_bc, 0); + pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, five_moment_copy_bc, + 0 + ); + pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, five_moment_copy_bc, + 0 + ); + pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, maxwell_copy_bc, 0 + ); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); long buff_sz = 0; long vol = pdata->skin_ghost.lower_skin[0].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -89,8 +111,9 @@ five_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, pdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } -void -ten_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn) +void ten_moment_patch_bc_updaters_init( + struct five_moment_patch_data *pdata, const struct gkyl_block_connections *conn +) { int nghost[3]; for (int i = 0; i < 3; i++) { @@ -102,28 +125,34 @@ ten_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const st pdata->lower_bc_maxwell[0] = pdata->upper_bc_maxwell[0] = 0; if (conn->connections[0][0].edge == GKYL_PHYSICAL) { - pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - ten_moment_copy_bc, 0); - pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - ten_moment_copy_bc, 0); - pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - maxwell_copy_bc, 0); + pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, ten_moment_copy_bc, 0 + ); + pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, ten_moment_copy_bc, 0 + ); + pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, maxwell_copy_bc, 0 + ); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { - pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - ten_moment_copy_bc, 0); - pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - ten_moment_copy_bc, 0); - pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - maxwell_copy_bc, 0); + pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, ten_moment_copy_bc, 0 + ); + pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, ten_moment_copy_bc, 0 + ); + pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, maxwell_copy_bc, 0 + ); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); long buff_sz = 0; long vol = pdata->skin_ghost.lower_skin[0].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -133,8 +162,9 @@ ten_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const st pdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } -void -ten_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn) +void ten_moment_nested_patch_bc_updaters_init( + struct five_moment_patch_data *pdata, const struct gkyl_block_connections *conn +) { int nghost[5]; for (int i = 0; i < 5; i++) { @@ -146,28 +176,34 @@ ten_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, c pdata->lower_bc_maxwell[0] = pdata->upper_bc_maxwell[0] = 0; if (conn->connections[0][0].edge == GKYL_PHYSICAL) { - pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - ten_moment_copy_bc, 0); - pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - ten_moment_copy_bc, 0); - pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - maxwell_copy_bc, 0); + pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, ten_moment_copy_bc, 0 + ); + pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, ten_moment_copy_bc, 0 + ); + pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, maxwell_copy_bc, 0 + ); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { - pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - ten_moment_copy_bc, 0); - pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - ten_moment_copy_bc, 0); - pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - maxwell_copy_bc, 0); + pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, ten_moment_copy_bc, 0 + ); + pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, ten_moment_copy_bc, 0 + ); + pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new( + &pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, maxwell_copy_bc, 0 + ); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); long buff_sz = 0; long vol = pdata->skin_ghost.lower_skin[0].volume; - + if (buff_sz <= vol) { buff_sz = vol; } @@ -177,8 +213,7 @@ ten_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, c pdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } -void -five_moment_patch_bc_updaters_release(struct five_moment_patch_data* pdata) +void five_moment_patch_bc_updaters_release(struct five_moment_patch_data *pdata) { if (pdata->lower_bc_elc[0]) { gkyl_wv_apply_bc_release(pdata->lower_bc_elc[0]); @@ -189,7 +224,7 @@ five_moment_patch_bc_updaters_release(struct five_moment_patch_data* pdata) if (pdata->lower_bc_maxwell[0]) { gkyl_wv_apply_bc_release(pdata->lower_bc_maxwell[0]); } - + if (pdata->upper_bc_elc[0]) { gkyl_wv_apply_bc_release(pdata->upper_bc_elc[0]); } @@ -205,9 +240,10 @@ five_moment_patch_bc_updaters_release(struct five_moment_patch_data* pdata) gkyl_array_release(pdata->bc_buffer_maxwell); } -void -five_moment_patch_bc_updaters_apply(const struct five_moment_patch_data* pdata, double tm, - struct gkyl_array* fld_elc, struct gkyl_array* fld_ion, struct gkyl_array* fld_maxwell) +void five_moment_patch_bc_updaters_apply( + const struct five_moment_patch_data *pdata, double tm, struct gkyl_array *fld_elc, + struct gkyl_array *fld_ion, struct gkyl_array *fld_maxwell +) { if (pdata->lower_bc_elc[0]) { gkyl_wv_apply_bc_advance(pdata->lower_bc_elc[0], tm, &pdata->range, fld_elc); @@ -218,7 +254,7 @@ five_moment_patch_bc_updaters_apply(const struct five_moment_patch_data* pdata, if (pdata->lower_bc_maxwell[0]) { gkyl_wv_apply_bc_advance(pdata->lower_bc_maxwell[0], tm, &pdata->range, fld_maxwell); } - + if (pdata->upper_bc_elc[0]) { gkyl_wv_apply_bc_advance(pdata->upper_bc_elc[0], tm, &pdata->range, fld_elc); } @@ -230,289 +266,490 @@ five_moment_patch_bc_updaters_apply(const struct five_moment_patch_data* pdata, } } -void -patch_coupled_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void patch_coupled_ll_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[d].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + double ref_factor_inv = + ((double)pdata[i].skin_ghost.lower_skin[d].volume / + (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -patch_coupled_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void patch_coupled_ll_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / + pdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -patch_coupled_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void patch_coupled_lu_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[d].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + double ref_factor_inv = + ((double)pdata[i].skin_ghost.lower_skin[d].volume / + (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -patch_coupled_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void patch_coupled_lu_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / + pdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -patch_coupled_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void patch_coupled_ul_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[d].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + double ref_factor_inv = + ((double)pdata[i].skin_ghost.upper_skin[d].volume / + (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -patch_coupled_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void patch_coupled_ul_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / + pdata[tbid].skin_ghost.lower_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -patch_coupled_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void patch_coupled_uu_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[d].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + double ref_factor_inv = + ((double)pdata[i].skin_ghost.upper_skin[d].volume / + (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -patch_coupled_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void patch_coupled_uu_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / + pdata[tbid].skin_ghost.upper_ghost[tdir].volume); long count = 0; while (gkyl_range_iter_next(&iter)) { long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - + pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), + fld_maxwell[tbid]->esznc + ); count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + } else { + memcpy( + gkyl_array_fetch(fld_elc[tbid], start), + ((char *)bc_buffer_elc->data) + + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_elc[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_ion[tbid], start), + ((char *)bc_buffer_ion->data) + + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_ion[tbid]->esznc + ); + memcpy( + gkyl_array_fetch(fld_maxwell[tbid], start), + ((char *)bc_buffer_maxwell->data) + + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), + fld_maxwell[tbid]->esznc + ); count += 1; } } } -void -five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct five_moment_patch_data pdata[], - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +void five_moment_sync_patches( + const struct gkyl_block_topo *ptopo, const struct five_moment_patch_data pdata[], + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +) { int num_patches = ptopo->num_blocks; @@ -524,41 +761,68 @@ five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct five_ struct gkyl_array *bc_buffer_ion = pdata[i].bc_buffer_ion; struct gkyl_array *bc_buffer_maxwell = pdata[i].bc_buffer_maxwell; - gkyl_array_copy_to_buffer(bc_buffer_elc->data, fld_elc[i], &(pdata[i].skin_ghost.lower_skin[0])); - gkyl_array_copy_to_buffer(bc_buffer_ion->data, fld_ion[i], &(pdata[i].skin_ghost.lower_skin[0])); - gkyl_array_copy_to_buffer(bc_buffer_maxwell->data, fld_maxwell[i], &(pdata[i].skin_ghost.lower_skin[0])); + gkyl_array_copy_to_buffer( + bc_buffer_elc->data, fld_elc[i], &(pdata[i].skin_ghost.lower_skin[0]) + ); + gkyl_array_copy_to_buffer( + bc_buffer_ion->data, fld_ion[i], &(pdata[i].skin_ghost.lower_skin[0]) + ); + gkyl_array_copy_to_buffer( + bc_buffer_maxwell->data, fld_maxwell[i], &(pdata[i].skin_ghost.lower_skin[0]) + ); int tbid = te[0].bid; int tdir = te[0].dir; if (te[0].edge == GKYL_LOWER_POSITIVE) { - if (pdata[i].skin_ghost.lower_skin[0].volume == pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (pdata[i].skin_ghost.lower_skin[0].volume > pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - patch_coupled_ll_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); + if (pdata[i].skin_ghost.lower_skin[0].volume == + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + } else if (pdata[i].skin_ghost.lower_skin[0].volume > + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + patch_coupled_ll_restriction_op( + tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); + } else if (pdata[i].skin_ghost.lower_skin[0].volume < + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + patch_coupled_ll_projection_op( + tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); } - else if (pdata[i].skin_ghost.lower_skin[0].volume < pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - patch_coupled_ll_projection_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); - } - } - else if (te[0].edge == GKYL_UPPER_POSITIVE) { - if (pdata[i].skin_ghost.lower_skin[0].volume == pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - } - else if (pdata[i].skin_ghost.lower_skin[0].volume > pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - patch_coupled_lu_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); - } - else if (pdata[i].skin_ghost.lower_skin[0].volume < pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - patch_coupled_lu_projection_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); + } else if (te[0].edge == GKYL_UPPER_POSITIVE) { + if (pdata[i].skin_ghost.lower_skin[0].volume == + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + } else if (pdata[i].skin_ghost.lower_skin[0].volume > + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + patch_coupled_lu_restriction_op( + tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); + } else if (pdata[i].skin_ghost.lower_skin[0].volume < + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + patch_coupled_lu_projection_op( + tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); } } } @@ -568,57 +832,85 @@ five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct five_ struct gkyl_array *bc_buffer_ion = pdata[i].bc_buffer_ion; struct gkyl_array *bc_buffer_maxwell = pdata[i].bc_buffer_maxwell; - gkyl_array_copy_to_buffer(bc_buffer_elc->data, fld_elc[i], &(pdata[i].skin_ghost.upper_skin[0])); - gkyl_array_copy_to_buffer(bc_buffer_ion->data, fld_ion[i], &(pdata[i].skin_ghost.upper_skin[0])); - gkyl_array_copy_to_buffer(bc_buffer_maxwell->data, fld_maxwell[i], &(pdata[i].skin_ghost.upper_skin[0])); + gkyl_array_copy_to_buffer( + bc_buffer_elc->data, fld_elc[i], &(pdata[i].skin_ghost.upper_skin[0]) + ); + gkyl_array_copy_to_buffer( + bc_buffer_ion->data, fld_ion[i], &(pdata[i].skin_ghost.upper_skin[0]) + ); + gkyl_array_copy_to_buffer( + bc_buffer_maxwell->data, fld_maxwell[i], &(pdata[i].skin_ghost.upper_skin[0]) + ); int tbid = te[1].bid; int tdir = te[1].dir; if (te[1].edge == GKYL_LOWER_POSITIVE) { - if (pdata[i].skin_ghost.upper_skin[0].volume == pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (pdata[i].skin_ghost.upper_skin[0].volume > pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - patch_coupled_ul_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); - } - else if (pdata[i].skin_ghost.upper_skin[0].volume < pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - patch_coupled_ul_projection_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); - } - } - else if (te[1].edge == GKYL_UPPER_POSITIVE) { - if (pdata[i].skin_ghost.upper_skin[0].volume == pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - } - else if (pdata[i].skin_ghost.upper_skin[0].volume > pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - patch_coupled_uu_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); + if (pdata[i].skin_ghost.upper_skin[0].volume == + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + } else if (pdata[i].skin_ghost.upper_skin[0].volume > + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + patch_coupled_ul_restriction_op( + tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); + } else if (pdata[i].skin_ghost.upper_skin[0].volume < + pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { + patch_coupled_ul_projection_op( + tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); } - else if (pdata[i].skin_ghost.upper_skin[0].volume < pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - patch_coupled_uu_projection_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, - fld_elc, fld_ion, fld_maxwell); + } else if (te[1].edge == GKYL_UPPER_POSITIVE) { + if (pdata[i].skin_ghost.upper_skin[0].volume == + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + gkyl_array_copy_from_buffer( + fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + gkyl_array_copy_from_buffer( + fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + } else if (pdata[i].skin_ghost.upper_skin[0].volume > + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + patch_coupled_uu_restriction_op( + tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); + } else if (pdata[i].skin_ghost.upper_skin[0].volume < + pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { + patch_coupled_uu_projection_op( + tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, fld_elc, + fld_ion, fld_maxwell + ); } } } } } -void -five_moment_patch_data_write(const char* file_nm_elc, const char* file_nm_ion, const char* file_nm_maxwell, const struct five_moment_patch_data* pdata) +void five_moment_patch_data_write( + const char *file_nm_elc, const char *file_nm_ion, const char *file_nm_maxwell, + const struct five_moment_patch_data *pdata +) { gkyl_grid_sub_array_write(&pdata->grid, &pdata->range, 0, pdata->f_elc[0], file_nm_elc); gkyl_grid_sub_array_write(&pdata->grid, &pdata->range, 0, pdata->f_ion[0], file_nm_ion); gkyl_grid_sub_array_write(&pdata->grid, &pdata->range, 0, pdata->f_maxwell[0], file_nm_maxwell); } -double -five_moment_patch_data_max_dt(const struct five_moment_patch_data* pdata) +double five_moment_patch_data_max_dt(const struct five_moment_patch_data *pdata) { double dt = DBL_MAX; @@ -629,8 +921,7 @@ five_moment_patch_data_max_dt(const struct five_moment_patch_data* pdata) return dt; } -void -five_moment_update_patch_job_func(void* ctx) +void five_moment_update_patch_job_func(void *ctx) { struct five_moment_update_patch_ctx *up_ctx = ctx; const struct five_moment_patch_data *pdata = up_ctx->pdata; @@ -639,15 +930,23 @@ five_moment_update_patch_job_func(void* ctx) double t_curr = up_ctx->t_curr; double dt = up_ctx->dt; - up_ctx->stat_elc = gkyl_wave_prop_advance(pdata->slvr_elc[d], t_curr, dt, &pdata->range, NULL, pdata->f_elc[d], pdata->f_elc[d + 1]); - up_ctx->stat_ion = gkyl_wave_prop_advance(pdata->slvr_ion[d], t_curr, dt, &pdata->range, NULL, pdata->f_ion[d], pdata->f_ion[d + 1]); - up_ctx->stat_maxwell = gkyl_wave_prop_advance(pdata->slvr_maxwell[d], t_curr, dt, &pdata->range, NULL, pdata->f_maxwell[d], pdata->f_maxwell[d + 1]); - - five_moment_patch_bc_updaters_apply(pdata, t_curr, pdata->f_elc[d + 1], pdata->f_ion[d + 1], pdata->f_maxwell[d + 1]); + up_ctx->stat_elc = gkyl_wave_prop_advance( + pdata->slvr_elc[d], t_curr, dt, &pdata->range, NULL, pdata->f_elc[d], pdata->f_elc[d + 1] + ); + up_ctx->stat_ion = gkyl_wave_prop_advance( + pdata->slvr_ion[d], t_curr, dt, &pdata->range, NULL, pdata->f_ion[d], pdata->f_ion[d + 1] + ); + up_ctx->stat_maxwell = gkyl_wave_prop_advance( + pdata->slvr_maxwell[d], t_curr, dt, &pdata->range, NULL, pdata->f_maxwell[d], + pdata->f_maxwell[d + 1] + ); + + five_moment_patch_bc_updaters_apply( + pdata, t_curr, pdata->f_elc[d + 1], pdata->f_ion[d + 1], pdata->f_maxwell[d + 1] + ); } -void -five_moment_update_patch_job_func_source(void* ctx) +void five_moment_update_patch_job_func_source(void *ctx) { struct five_moment_update_patch_ctx *up_ctx = ctx; const struct five_moment_patch_data *pdata = up_ctx->pdata; @@ -672,16 +971,21 @@ five_moment_update_patch_job_func_source(void* ctx) const struct gkyl_array *nT_source[2]; nT_source[0] = pdata->nT_source_elc; nT_source[1] = pdata->nT_source_ion; - - gkyl_moment_em_coupling_implicit_advance(pdata->src_slvr, t_curr, dt, &pdata->range, fluids, app_accel, rhs_source, - pdata->f_maxwell[nstrang], pdata->app_current, pdata->ext_em, nT_source); - five_moment_patch_bc_updaters_apply(pdata, t_curr, pdata->f_elc[nstrang], pdata->f_ion[nstrang], pdata->f_maxwell[nstrang]); + gkyl_moment_em_coupling_implicit_advance( + pdata->src_slvr, t_curr, dt, &pdata->range, fluids, app_accel, rhs_source, + pdata->f_maxwell[nstrang], pdata->app_current, pdata->ext_em, nT_source + ); + + five_moment_patch_bc_updaters_apply( + pdata, t_curr, pdata->f_elc[nstrang], pdata->f_ion[nstrang], pdata->f_maxwell[nstrang] + ); } -struct gkyl_update_status -five_moment_update_all_patches(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* ptopo, - const struct five_moment_patch_data pdata[], double t_curr, double dt) +struct gkyl_update_status five_moment_update_all_patches( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *ptopo, + const struct five_moment_patch_data pdata[], double t_curr, double dt +) { int num_patches = ptopo->num_blocks; double dt_suggested = DBL_MAX; @@ -689,14 +993,8 @@ five_moment_update_all_patches(const struct gkyl_job_pool* job_pool, const struc struct five_moment_update_patch_ctx five_moment_patch_ctx[num_patches]; for (int i = 0; i < num_patches; i++) { - five_moment_patch_ctx[i] = (struct five_moment_update_patch_ctx) { - .pdata = &pdata[i], - .t_curr = t_curr, - .dir = 0, - .dt = dt, - .pidx = i, - .nstrang = 0, - }; + five_moment_patch_ctx[i] = (struct five_moment_update_patch_ctx + ){.pdata = &pdata[i], .t_curr = t_curr, .dir = 0, .dt = dt, .pidx = i, .nstrang = 0}; } #ifdef AMR_USETHREADS @@ -715,15 +1013,14 @@ five_moment_update_all_patches(const struct gkyl_job_pool* job_pool, const struc struct gkyl_array *fld_maxwell[num_patches]; for (int i = 0; i < num_patches; i++) { - if (five_moment_patch_ctx[i].stat_elc.success == false || five_moment_patch_ctx[i].stat_ion.success == false || five_moment_patch_ctx[i].stat_maxwell.success == false) { + if (five_moment_patch_ctx[i].stat_elc.success == false || + five_moment_patch_ctx[i].stat_ion.success == false || + five_moment_patch_ctx[i].stat_maxwell.success == false) { dt_suggested = fmin(dt_suggested, five_moment_patch_ctx[i].stat_elc.dt_suggested); dt_suggested = fmin(dt_suggested, five_moment_patch_ctx[i].stat_ion.dt_suggested); dt_suggested = fmin(dt_suggested, five_moment_patch_ctx[i].stat_maxwell.dt_suggested); - return (struct gkyl_update_status) { - .success = false, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status){.success = false, .dt_suggested = dt_suggested}; } dt_suggested = fmin(dt_suggested, five_moment_patch_ctx[i].stat_elc.dt_suggested); @@ -737,34 +1034,28 @@ five_moment_update_all_patches(const struct gkyl_job_pool* job_pool, const struc five_moment_sync_patches(ptopo, pdata, fld_elc, fld_ion, fld_maxwell); - return (struct gkyl_update_status) { - .success = true, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status){.success = true, .dt_suggested = dt_suggested}; } -void -five_moment_update_all_patches_source(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* ptopo, - const struct five_moment_patch_data pdata[], double t_curr, double dt, int nstrang) +void five_moment_update_all_patches_source( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *ptopo, + const struct five_moment_patch_data pdata[], double t_curr, double dt, int nstrang +) { int num_patches = ptopo->num_blocks; struct five_moment_update_patch_ctx five_moment_patch_ctx[num_patches]; for (int i = 0; i < num_patches; i++) { - five_moment_patch_ctx[i] = (struct five_moment_update_patch_ctx) { - .pdata = &pdata[i], - .t_curr = t_curr, - .dir = 0, - .dt = dt, - .pidx = i, - .nstrang = nstrang, - }; + five_moment_patch_ctx[i] = (struct five_moment_update_patch_ctx + ){.pdata = &pdata[i], .t_curr = t_curr, .dir = 0, .dt = dt, .pidx = i, .nstrang = nstrang}; } #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(job_pool, five_moment_update_patch_job_func_source, &five_moment_patch_ctx[i]); + gkyl_job_pool_add_work( + job_pool, five_moment_update_patch_job_func_source, &five_moment_patch_ctx[i] + ); } gkyl_job_pool_wait(job_pool); #else @@ -786,8 +1077,7 @@ five_moment_update_all_patches_source(const struct gkyl_job_pool* job_pool, cons five_moment_sync_patches(ptopo, pdata, fld_elc, fld_ion, fld_maxwell); } -void -five_moment_init_job_func_patch(void* ctx) +void five_moment_init_job_func_patch(void *ctx) { struct five_moment_patch_data *pdata = ctx; @@ -796,9 +1086,10 @@ five_moment_init_job_func_patch(void* ctx) gkyl_fv_proj_advance(pdata->fv_proj_maxwell, 0.0, &pdata->ext_range, pdata->f_maxwell[0]); } -struct gkyl_update_status -five_moment_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* ptopo, - const struct five_moment_patch_data pdata[], double t_curr, double dt0, struct sim_stats* stats) +struct gkyl_update_status five_moment_update_patch( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *ptopo, + const struct five_moment_patch_data pdata[], double t_curr, double dt0, struct sim_stats *stats +) { int num_patches = ptopo->num_blocks; double dt_suggested = DBL_MAX; @@ -810,7 +1101,7 @@ five_moment_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl FIRST_COUPLING_UPDATE, PATCH_UPDATE, SECOND_COUPLING_UPDATE, - UPDATE_REDO, + UPDATE_REDO } state = PRE_UPDATE; struct five_moment_copy_job_ctx five_moment_copy_ctx[num_patches]; @@ -821,15 +1112,14 @@ five_moment_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl state = FIRST_COUPLING_UPDATE; for (int i = 0; i < num_patches; i++) { - five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx) { - .bidx = i, + five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx + ){.bidx = i, .inp_elc = pdata[i].f_elc[0], .inp_ion = pdata[i].f_ion[0], .inp_maxwell = pdata[i].f_maxwell[0], .out_elc = pdata[i].fdup_elc, .out_ion = pdata[i].fdup_ion, - .out_maxwell = pdata[i].fdup_maxwell, - }; + .out_maxwell = pdata[i].fdup_maxwell}; } #ifdef AMR_USETHREADS @@ -842,44 +1132,39 @@ five_moment_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl five_moment_copy_job_func(&five_moment_copy_ctx[i]); } #endif - } - else if (state == FIRST_COUPLING_UPDATE) { + } else if (state == FIRST_COUPLING_UPDATE) { state = PATCH_UPDATE; five_moment_update_all_patches_source(job_pool, ptopo, pdata, t_curr, 0.5 * dt, 0); - } - else if (state == PATCH_UPDATE) { + } else if (state == PATCH_UPDATE) { state = SECOND_COUPLING_UPDATE; - struct gkyl_update_status s = five_moment_update_all_patches(job_pool, ptopo, pdata, t_curr, dt); + struct gkyl_update_status s = + five_moment_update_all_patches(job_pool, ptopo, pdata, t_curr, dt); if (!s.success) { stats->nfail += 1; dt = s.dt_suggested; state = UPDATE_REDO; - } - else { + } else { dt_suggested = fmin(dt_suggested, s.dt_suggested); } - } - else if (state == SECOND_COUPLING_UPDATE) { + } else if (state == SECOND_COUPLING_UPDATE) { state = POST_UPDATE; five_moment_update_all_patches_source(job_pool, ptopo, pdata, t_curr, 0.5 * dt, 2); - } - else if (state == POST_UPDATE) { + } else if (state == POST_UPDATE) { state = UPDATE_DONE; for (int i = 0; i < num_patches; i++) { - five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx) { - .bidx = i, + five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx + ){.bidx = i, .inp_elc = pdata[i].f_elc[1], .inp_ion = pdata[i].f_ion[1], .inp_maxwell = pdata[i].f_maxwell[1], .out_elc = pdata[i].f_elc[0], .out_ion = pdata[i].f_ion[0], - .out_maxwell = pdata[i].f_maxwell[0], - }; + .out_maxwell = pdata[i].f_maxwell[0]}; } #ifdef AMR_USETHREADS @@ -892,20 +1177,18 @@ five_moment_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl five_moment_copy_job_func(&five_moment_copy_ctx[i]); } #endif - } - else if (state == UPDATE_REDO) { + } else if (state == UPDATE_REDO) { state = PRE_UPDATE; for (int i = 0; i < num_patches; i++) { - five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx) { - .bidx = i, + five_moment_copy_ctx[i] = (struct five_moment_copy_job_ctx + ){.bidx = i, .inp_elc = pdata[i].fdup_elc, .inp_ion = pdata[i].fdup_ion, .inp_maxwell = pdata[i].fdup_maxwell, .out_elc = pdata[i].f_elc[0], .out_ion = pdata[i].f_ion[0], - .out_maxwell = pdata[i].f_maxwell[0], - }; + .out_maxwell = pdata[i].f_maxwell[0]}; } #ifdef AMR_USETHREADS @@ -921,15 +1204,13 @@ five_moment_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl } } - return (struct gkyl_update_status) { - .success = true, - .dt_actual = dt, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status + ){.success = true, .dt_actual = dt, .dt_suggested = dt_suggested}; } -void -five_moment_write_sol_patch(const char* fbase, int num_patches, const struct five_moment_patch_data pdata[]) +void five_moment_write_sol_patch( + const char *fbase, int num_patches, const struct five_moment_patch_data pdata[] +) { for (int i = 0; i < num_patches; i++) { const char *fmt_elc = "%s_elc_p%d.gkyl"; @@ -952,8 +1233,7 @@ five_moment_write_sol_patch(const char* fbase, int num_patches, const struct fiv } } -double -five_moment_max_dt_patch(int num_patches, const struct five_moment_patch_data pdata[]) +double five_moment_max_dt_patch(int num_patches, const struct five_moment_patch_data pdata[]) { double dt = DBL_MAX; diff --git a/moments/amr/gkyl_amr_block_coupled_priv.h b/moments/amr/gkyl_amr_block_coupled_priv.h index 2549e3051f..c1976e3ba4 100644 --- a/moments/amr/gkyl_amr_block_coupled_priv.h +++ b/moments/amr/gkyl_amr_block_coupled_priv.h @@ -106,7 +106,10 @@ struct five_moment_copy_job_ctx { * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void five_moment_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void five_moment_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Boundary condition function for applying wall boundary conditions for the coupled ten-moment equations. @@ -118,7 +121,10 @@ void five_moment_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void ten_moment_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void ten_moment_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Boundary condition function for applying wall boundary conditions for the Maxwell equations. @@ -130,7 +136,10 @@ void ten_moment_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const d * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void maxwell_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void maxwell_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Boundary condition function for applying copy boundary conditions for the coupled five-moment equations. @@ -142,7 +151,10 @@ void maxwell_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const doub * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void five_moment_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void five_moment_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Boundary condition function for applying copy boundary conditions for the coupled ten-moment equations. @@ -154,7 +166,10 @@ void five_moment_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void ten_moment_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void ten_moment_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Boundary condition function for applying copy boundary conditions for the Maxwell equations. @@ -166,7 +181,10 @@ void ten_moment_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const d * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void maxwell_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void maxwell_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Initialize block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the coupled five-moment equations. @@ -174,7 +192,9 @@ void maxwell_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const doub * @param bdata Block-structured data for the coupled five-moment equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void five_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn); +void five_moment_block_bc_updaters_init( + struct five_moment_block_data *bdata, const struct gkyl_block_connections *conn +); /** * Initialize nested block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the coupled five-moment equations. @@ -182,7 +202,9 @@ void five_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, co * @param bdata Block-structured data for the coupled five-moment equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void five_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn); +void five_moment_nested_block_bc_updaters_init( + struct five_moment_block_data *bdata, const struct gkyl_block_connections *conn +); /** * Initialize block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the coupled ten-moment equations. @@ -190,7 +212,9 @@ void five_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bd * @param bdata Block-structured data for the coupled ten-moment equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void ten_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn); +void ten_moment_block_bc_updaters_init( + struct five_moment_block_data *bdata, const struct gkyl_block_connections *conn +); /** * Initialize nested block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the coupled ten-moment equations. @@ -198,14 +222,16 @@ void ten_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, con * @param bdata Block-structured data for the coupled ten-moment equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void ten_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn); +void ten_moment_nested_block_bc_updaters_init( + struct five_moment_block_data *bdata, const struct gkyl_block_connections *conn +); /** * Release block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the coupled five-moment equations. * * @param bdata Block-structured data for the coupled five-moment equations. */ -void five_moment_block_bc_updaters_release(struct five_moment_block_data* bdata); +void five_moment_block_bc_updaters_release(struct five_moment_block_data *bdata); /** * Apply both physical (outer-block) and non-physical (inter-block) block AMR boundary conditions for the coupled five-moment equations. @@ -216,8 +242,10 @@ void five_moment_block_bc_updaters_release(struct five_moment_block_data* bdata) * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void five_moment_block_bc_updaters_apply(const struct five_moment_block_data* bdata, double tm, - struct gkyl_array* fld_elc, struct gkyl_array *fld_ion, struct gkyl_array* fld_maxwell); +void five_moment_block_bc_updaters_apply( + const struct five_moment_block_data *bdata, double tm, struct gkyl_array *fld_elc, + struct gkyl_array *fld_ion, struct gkyl_array *fld_maxwell +); /** * Coarse-to-fine projection operator for coupled, block-structured AMR, assuming a lower coarse block and a lower fine block. @@ -234,9 +262,12 @@ void five_moment_block_bc_updaters_apply(const struct five_moment_block_data* bd * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void block_coupled_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void block_coupled_ll_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Fine-to-coarse restriction operator for coupled, block-structured AMR, assuming a lower fine block and a lower coarse block. @@ -253,9 +284,12 @@ void block_coupled_ll_projection_op(const int tbid, const int tdir, const int i, * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void block_coupled_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void block_coupled_ll_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Coarse-to-fine projection operator for coupled, block-structured AMR, assuming a lower coarse block and an upper fine block. @@ -272,9 +306,12 @@ void block_coupled_ll_restriction_op(const int tbid, const int tdir, const int i * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void block_coupled_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void block_coupled_lu_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Fine-to-coarse restriction operator for coupled, block-structured AMR, assuming a lower fine block and an upper coarse block. @@ -291,9 +328,12 @@ void block_coupled_lu_projection_op(const int tbid, const int tdir, const int i, * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void block_coupled_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void block_coupled_lu_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Coarse-to-fine projection operator for coupled, block-structured AMR, assuming an upper coarse block and a lower fine block. @@ -310,9 +350,12 @@ void block_coupled_lu_restriction_op(const int tbid, const int tdir, const int i * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void block_coupled_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void block_coupled_ul_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Fine-to-coarse restriction operator for coupled, block-structured AMR, assuming an upper fine block and a lower coarse block. @@ -329,9 +372,12 @@ void block_coupled_ul_projection_op(const int tbid, const int tdir, const int i, * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void block_coupled_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void block_coupled_ul_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Coarse-to-fine projection operator for coupled, block-structured AMR, assuming an upper coarse block and an upper fine block. @@ -348,9 +394,12 @@ void block_coupled_ul_restriction_op(const int tbid, const int tdir, const int i * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void block_coupled_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void block_coupled_uu_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Fine-to-coarse restriction operator for coupled, block-structured AMR, assuming an upper fine block and an upper coarse block. @@ -367,9 +416,12 @@ void block_coupled_uu_projection_op(const int tbid, const int tdir, const int i, * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void block_coupled_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void block_coupled_uu_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_block_data bdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Synchronize all blocks in the block AMR hierarchy by applying all appropriate physical (outer-block) and non-physical (inter-block) @@ -381,8 +433,10 @@ void block_coupled_uu_restriction_op(const int tbid, const int tdir, const int i * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_moment_block_data bdata[], - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void five_moment_sync_blocks( + const struct gkyl_block_topo *btopo, const struct five_moment_block_data bdata[], + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Write block-structured AMR simulation data for the coupled five-moment equations onto disk. @@ -392,7 +446,10 @@ void five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct f * @param file_nm_maxwell File name schema to use for the Maxwell field simulation output. * @param bdata Block-structured data for the coupled five-moment equations. */ -void five_moment_block_data_write(const char* file_nm_elc, const char* file_nm_ion, const char* file_nm_maxwell, const struct five_moment_block_data* bdata); +void five_moment_block_data_write( + const char *file_nm_elc, const char *file_nm_ion, const char *file_nm_maxwell, + const struct five_moment_block_data *bdata +); /** * Calculate the maximum stable time-step for the block-structured, coupled five-moment equations. @@ -400,21 +457,21 @@ void five_moment_block_data_write(const char* file_nm_elc, const char* file_nm_i * @param bdata Block-structured data for the coupled five-moment equations. * @return Maximum stable time-step. */ -double five_moment_block_data_max_dt(const struct five_moment_block_data* bdata); +double five_moment_block_data_max_dt(const struct five_moment_block_data *bdata); /** * Update the block-structured AMR simulation data for the coupled five-moment equations using the thread-based job pool. * * @param ctx Context to pass to the function. */ -void five_moment_update_block_job_func(void* ctx); +void five_moment_update_block_job_func(void *ctx); /** * Update the source terms of the block-structured AMR simulation data for the coupled five-moment equations using the thread-based job pool. * * @param ctx Context to pass to the function. */ -void five_moment_update_block_job_func_source(void* ctx); +void five_moment_update_block_job_func_source(void *ctx); /** * Update all blocks in the block AMR hierarchy by using the thread-based job pool for the coupled five-moment equations. @@ -426,8 +483,10 @@ void five_moment_update_block_job_func_source(void* ctx); * @param dt Current stable time-step for the simulation. * @return Status of the update (success and suggested time-step). */ -struct gkyl_update_status five_moment_update_all_blocks(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* btopo, - const struct five_moment_block_data bdata[], double t_curr, double dt); +struct gkyl_update_status five_moment_update_all_blocks( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct five_moment_block_data bdata[], double t_curr, double dt +); /** * Update the source terms for all blocks in the block AMR hierarchy by using the thread-based job pool for the coupled five-moment equations. @@ -439,22 +498,24 @@ struct gkyl_update_status five_moment_update_all_blocks(const struct gkyl_job_po * @param dt Current stable time-step for the simulation. * @param nstrang Iteration number in the Strang splitting. */ -void five_moment_update_all_blocks_source(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* btopo, - const struct five_moment_block_data bdata[], double t_curr, double dt, int nstrang); +void five_moment_update_all_blocks_source( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct five_moment_block_data bdata[], double t_curr, double dt, int nstrang +); /** * Initialize a new job in the thread-based job pool for updating the block-structured AMR simulation data for the coupled five-moment equations. * * @param ctx Context to pass to the function. */ -void five_moment_init_job_func_block(void* ctx); +void five_moment_init_job_func_block(void *ctx); /** * Copy an existing job between two thread-based job pools for updating the coupled five-moment equations. * * @param ctx Context to pass to the function. */ -void five_moment_copy_job_func(void* ctx); +void five_moment_copy_job_func(void *ctx); /** * Take a single time-step across the entire block AMR hierarchy for the coupled five-moment equations. @@ -467,8 +528,10 @@ void five_moment_copy_job_func(void* ctx); * @param stats Simulation statistics (allowing for tracking of the number of failed time-steps). * @return Status of the update (success, suggested time-step and actual time-step). */ -struct gkyl_update_status five_moment_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* btopo, - const struct five_moment_block_data bdata[], double t_curr, double dt0, struct sim_stats* stats); +struct gkyl_update_status five_moment_update_block( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct five_moment_block_data bdata[], double t_curr, double dt0, struct sim_stats *stats +); /** * Write the complete simulation output for the entire block AMR hierarchy for the coupled five-moment equations onto disk. @@ -477,7 +540,9 @@ struct gkyl_update_status five_moment_update_block(const struct gkyl_job_pool* j * @param num_blocks Number of blocks in the block hierarchy. * @param bdata Array of block-structured data for the coupled five-moment equations. */ -void five_moment_write_sol_block(const char* fbase, int num_blocks, const struct five_moment_block_data bdata[]); +void five_moment_write_sol_block( + const char *fbase, int num_blocks, const struct five_moment_block_data bdata[] +); /** * Calculate the maximum stable time-step across all blocks in the block AMR hierarchy for the coupled five-moment equations. diff --git a/moments/amr/gkyl_amr_block_priv.h b/moments/amr/gkyl_amr_block_priv.h index 33ec9c813c..e9eef74239 100644 --- a/moments/amr/gkyl_amr_block_priv.h +++ b/moments/amr/gkyl_amr_block_priv.h @@ -41,7 +41,7 @@ struct skin_ghost_ranges_block { struct gkyl_range lower_skin[2]; struct gkyl_range lower_ghost[2]; - + struct gkyl_range upper_skin[2]; struct gkyl_range upper_ghost[2]; }; @@ -69,7 +69,7 @@ struct euler_block_data { bool copy_x; bool copy_y; - + bool wall_x; bool wall_y; }; @@ -103,7 +103,9 @@ struct sim_stats { * @param parent Ranges for the parent regions (of which the skin and ghost regions are subregions). * @param ghost Number of ghost (and therefore skin) cells. */ -void skin_ghost_ranges_init_block(struct skin_ghost_ranges_block* sgr, const struct gkyl_range* parent, const int* ghost); +void skin_ghost_ranges_init_block( + struct skin_ghost_ranges_block *sgr, const struct gkyl_range *parent, const int *ghost +); /** * Boundary condition function for applying wall boundary conditions for the Euler equations. @@ -115,7 +117,10 @@ void skin_ghost_ranges_init_block(struct skin_ghost_ranges_block* sgr, const str * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void euler_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void euler_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Boundary condition function for applying wall boundary conditions for the general relativistic Euler equations. @@ -127,7 +132,10 @@ void euler_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void gr_euler_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void gr_euler_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Boundary condition function for applying wall boundary conditions for the Euler mixture equations. @@ -139,7 +147,10 @@ void gr_euler_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const dou * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void euler_mixture_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void euler_mixture_wall_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Boundary condition function for applying copy boundary conditions for the Euler equations. @@ -151,7 +162,10 @@ void euler_mixture_wall_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, cons * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void euler_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void euler_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Boundary condition function for applying copy boundary conditions for the general relativistic Euler equations. @@ -163,7 +177,10 @@ void euler_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void gr_euler_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void gr_euler_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Boundary condition function for applying copy boundary conditions for the Euler mixture equations. @@ -175,7 +192,10 @@ void gr_euler_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const dou * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void euler_mixture_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void euler_mixture_copy_bc( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *GKYL_RESTRICT skin, + double *GKYL_RESTRICT ghost, void *ctx +); /** * Initialize block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the Euler equations. @@ -184,7 +204,10 @@ void euler_mixture_copy_bc(const struct gkyl_wv_eqn* eqn, double t, int nc, cons * @param bdata Block-structured data for the Euler equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void euler_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn); +void euler_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +); /** * Initialize nested block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the Euler equations. @@ -193,7 +216,10 @@ void euler_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_bl * @param bdata Block-structured data for the Euler equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void euler_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn); +void euler_nested_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +); /** * Initialize block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the general relativistic Euler equations. @@ -202,7 +228,10 @@ void euler_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct e * @param bdata Block-structured data for the general relativistic Euler equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void gr_euler_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn); +void gr_euler_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +); /** * Initialize nested block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the general relativistic Euler equations. @@ -211,7 +240,10 @@ void gr_euler_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler * @param bdata Block-structured data for the general relativistic Euler equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void gr_euler_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn); +void gr_euler_nested_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +); /** * Initialize block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the Euler mixture equations. @@ -220,7 +252,10 @@ void gr_euler_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struc * @param bdata Block-structured data for the Euler mixture equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void euler_mixture_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn); +void euler_mixture_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +); /** * Initialize nested block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the Euler mixture equations. @@ -229,14 +264,17 @@ void euler_mixture_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct * @param bdata Block-structured data for the Euler mixture equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void euler_mixture_nested_block_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_block_data* bdata, const struct gkyl_block_connections* conn); +void euler_mixture_nested_block_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_block_data *bdata, + const struct gkyl_block_connections *conn +); /** * Release block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the Euler equations. * * @param bdata Block-structured data for the Euler equations. */ -void euler_block_bc_updaters_release(struct euler_block_data* bdata); +void euler_block_bc_updaters_release(struct euler_block_data *bdata); /** * Apply both physical (outer-block) and non-physical (inter-block) block AMR boundary conditions for the Euler equations. @@ -245,7 +283,9 @@ void euler_block_bc_updaters_release(struct euler_block_data* bdata); * @param tm Simulation time at which the boundary conditions are applied. * @param fld Output array. */ -void euler_block_bc_updaters_apply(const struct euler_block_data* bdata, double tm, struct gkyl_array* fld); +void euler_block_bc_updaters_apply( + const struct euler_block_data *bdata, double tm, struct gkyl_array *fld +); /** * Coarse-to-fine projection operator for block-structured AMR, assuming a lower coarse block and a lower fine block. @@ -258,8 +298,10 @@ void euler_block_bc_updaters_apply(const struct euler_block_data* bdata, double * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void block_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void block_ll_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Fine-to-coarse restriction operator for block-structured AMR, assuming a lower fine block and a lower coarse block. @@ -272,8 +314,10 @@ void block_ll_projection_op(const int tbid, const int tdir, const int i, const i * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void block_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void block_ll_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Coarse-to-fine projection operator for block-structured AMR, assuming a lower coarse block and an upper fine block. @@ -286,8 +330,10 @@ void block_ll_restriction_op(const int tbid, const int tdir, const int i, const * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void block_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void block_lu_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Fine-to-coarse restriction operator for block-structured AMR, assuming a lower fine block and an upper coarse block. @@ -300,10 +346,12 @@ void block_lu_projection_op(const int tbid, const int tdir, const int i, const i * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void block_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void block_lu_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); - /** +/** * Coarse-to-fine projection operator for block-structured AMR, assuming an upper coarse block and a lower fine block. * * @param tbid Target (fine) block ID. @@ -314,8 +362,10 @@ void block_lu_restriction_op(const int tbid, const int tdir, const int i, const * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void block_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void block_ul_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Fine-to-coarse restriction operator for block-structured AMR, assuming an upper fine block and a lower coarse block. @@ -328,8 +378,10 @@ void block_ul_projection_op(const int tbid, const int tdir, const int i, const i * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void block_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void block_ul_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Coarse-to-fine projection operator for block-structured AMR, assuming an upper coarse block and an upper fine block. @@ -342,8 +394,10 @@ void block_ul_restriction_op(const int tbid, const int tdir, const int i, const * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void block_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void block_uu_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Fine-to-coarse restriction operator for block-structured AMR, assuming an upper fine block and an upper coarse block. @@ -356,8 +410,10 @@ void block_uu_projection_op(const int tbid, const int tdir, const int i, const i * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void block_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void block_uu_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Synchronize all blocks in the block AMR hierarchy by applying all appropriate physical (outer-block) and non-physical (inter-block) @@ -367,7 +423,10 @@ void block_uu_restriction_op(const int tbid, const int tdir, const int i, const * @param bdata Block-structured data for the Euler equations. * @param fld Output array. */ -void euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_data bdata[], struct gkyl_array* fld[]); +void euler_sync_blocks( + const struct gkyl_block_topo *btopo, const struct euler_block_data bdata[], + struct gkyl_array *fld[] +); /** * Write block-structured AMR simulation data for the Euler equations onto disk. @@ -375,7 +434,7 @@ void euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_b * @param file_nm File name schema to use for the simulation output. * @param bdata Block-structured data for the Euler equations. */ -void euler_block_data_write(const char* file_nm, const struct euler_block_data* bdata); +void euler_block_data_write(const char *file_nm, const struct euler_block_data *bdata); /** * Calculate the maximum stable time-step for the block-structured Euler equations. @@ -383,14 +442,14 @@ void euler_block_data_write(const char* file_nm, const struct euler_block_data* * @param bdata Block-structured data for the Euler equations. * @return Maximum stable time-step. */ -double euler_block_data_max_dt(const struct euler_block_data* bdata); +double euler_block_data_max_dt(const struct euler_block_data *bdata); /** * Update the block-structured AMR simulation data for the Euler equations using the thread-based job pool. * * @param ctx Context to pass to the function. */ -void euler_update_block_job_func(void* ctx); +void euler_update_block_job_func(void *ctx); /** * Update all blocks in the block AMR hierarchy by using the thread-based job pool for the Euler equations. @@ -402,22 +461,24 @@ void euler_update_block_job_func(void* ctx); * @param dt Current stable time-step for the simulation. * @return Status of the update (success and suggested time-step). */ -struct gkyl_update_status euler_update_all_blocks(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* btopo, - const struct euler_block_data bdata[], double t_curr, double dt); +struct gkyl_update_status euler_update_all_blocks( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct euler_block_data bdata[], double t_curr, double dt +); /** * Initialize a new job in the thread-based job pool for updating the block-structured AMR simulation data for the Euler equations. * * @param ctx Context to pass to the function. */ -void euler_init_job_func_block(void* ctx); +void euler_init_job_func_block(void *ctx); /** * Copy an existing job between two arbitrary thread-based job pools. * * @param ctx Context to pass to the function. */ -void copy_job_func(void* ctx); +void copy_job_func(void *ctx); /** * Take a single time-step across the entire block AMR hierarchy for the Euler equations. @@ -430,8 +491,10 @@ void copy_job_func(void* ctx); * @param stats Simulation statistics (allowing for tracking of the number of failed time-steps). * @return Status of the update (success, suggested time-step and actual time-step). */ -struct gkyl_update_status euler_update_block(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* btopo, - const struct euler_block_data bdata[], double t_curr, double dt0, struct sim_stats* stats); +struct gkyl_update_status euler_update_block( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct euler_block_data bdata[], double t_curr, double dt0, struct sim_stats *stats +); /** * Write the complete simulation output for the entire block AMR hierarchy for the Euler equations onto disk. @@ -440,7 +503,7 @@ struct gkyl_update_status euler_update_block(const struct gkyl_job_pool* job_poo * @param num_blocks Number of blocks in the block hierarchy. * @param bdata Array of block-structured data for the Euler equations. */ -void euler_write_sol_block(const char* fbase, int num_blocks, const struct euler_block_data bdata[]); +void euler_write_sol_block(const char *fbase, int num_blocks, const struct euler_block_data bdata[]); /** * Calculate the maximum stable time-step across all blocks in the block AMR hierarchy for the Euler equations. @@ -454,9 +517,9 @@ double euler_max_dt_block(int num_blocks, const struct euler_block_data bdata[]) /** * Set up the topology/connectivity information for the block AMR hierarchy for a mesh containing a single refinement patch. */ -struct gkyl_block_topo* create_block_topo(); +struct gkyl_block_topo *create_block_topo(); /** * Set up the topology/connectivity information for the block AMR hierarchy for a mesh containing a doubly-nested refinement patch. */ -struct gkyl_block_topo* create_nested_block_topo(); \ No newline at end of file +struct gkyl_block_topo *create_nested_block_topo(); \ No newline at end of file diff --git a/moments/amr/gkyl_amr_core.h b/moments/amr/gkyl_amr_core.h index cc6264e526..0e6bd5a2f4 100644 --- a/moments/amr/gkyl_amr_core.h +++ b/moments/amr/gkyl_amr_core.h @@ -10,7 +10,7 @@ struct euler1d_single_init { double coarse_x1; double coarse_x2; - + double refined_x1; double refined_x2; @@ -35,7 +35,7 @@ struct euler1d_single_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 1D Euler equations. */ -void euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init); +void euler1d_run_single(int argc, char **argv, struct euler1d_single_init *init); // Initialization data for a 1D simulation using the general relativistic Euler equations, run with static, patch-structured mesh refinement with a single refinement patch. struct gr_euler1d_single_init { @@ -44,7 +44,7 @@ struct gr_euler1d_single_init { double coarse_x1; double coarse_x2; - + double refined_x1; double refined_x2; @@ -70,7 +70,7 @@ struct gr_euler1d_single_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 1D general relativistic Euler equations. */ -void gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init); +void gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init *init); // Initialization data for a 1D simulation using the Euler mixture equations, run with static, patch-structured mesh refinement with a single refinement patch. struct euler_mixture1d_single_init { @@ -79,7 +79,7 @@ struct euler_mixture1d_single_init { double coarse_x1; double coarse_x2; - + double refined_x1; double refined_x2; @@ -105,7 +105,7 @@ struct euler_mixture1d_single_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 1D Euler mixture equations. */ -void euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_init* init); +void euler_mixture1d_run_single(int argc, char **argv, struct euler_mixture1d_single_init *init); // Initialization data for a 1D simulation using the Euler equations, run with static, patch-structured mesh refinement with a doubly-nested refinement patch. struct euler1d_double_init { @@ -118,7 +118,7 @@ struct euler1d_double_init { double intermediate_x1; double intermediate_x2; - + double refined_x1; double refined_x2; @@ -143,7 +143,7 @@ struct euler1d_double_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 1D Euler equations. */ -void euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init); +void euler1d_run_double(int argc, char **argv, struct euler1d_double_init *init); // Initialization data for a 1D simulation using the general relativistic Euler equations, run with static, patch-structured mesh refinement with a doubly-nested refinement patch. struct gr_euler1d_double_init { @@ -156,7 +156,7 @@ struct gr_euler1d_double_init { double intermediate_x1; double intermediate_x2; - + double refined_x1; double refined_x2; @@ -182,7 +182,7 @@ struct gr_euler1d_double_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 1D general relativistic Euler equations. */ -void gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init); +void gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init *init); // Initialization data for a 1D simulation using the Euler mixture equations, run with static, patch-structured mesh refinement with a doubly-nested refinement patch. struct euler_mixture1d_double_init { @@ -195,7 +195,7 @@ struct euler_mixture1d_double_init { double intermediate_x1; double intermediate_x2; - + double refined_x1; double refined_x2; @@ -221,7 +221,7 @@ struct euler_mixture1d_double_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 1D Euler mixture equations. */ -void euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_init* init); +void euler_mixture1d_run_double(int argc, char **argv, struct euler_mixture1d_double_init *init); // Initialization data for a 2D simulation using the Euler equations, run with static, block-structured mesh refinement with a single refinement patch. struct euler2d_single_init { @@ -266,7 +266,7 @@ struct euler2d_single_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D Euler equations. */ -void euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init); +void euler2d_run_single(int argc, char **argv, struct euler2d_single_init *init); // Initialization data for a 2D simulation using the general relativistic Euler equations, run with static, block-structured mesh refinement with a single refinement patch. struct gr_euler2d_single_init { @@ -312,7 +312,7 @@ struct gr_euler2d_single_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D general relativistic Euler equations. */ -void gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init); +void gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init *init); // Initialization data for a 2D simulation using the Euler mixture equations, run with static, block-structured mesh refinement with a single refinement patch. struct euler_mixture2d_single_init { @@ -332,11 +332,11 @@ struct euler_mixture2d_single_init { evalf_t eval; int num_species; - double* gas_gamma_s; + double *gas_gamma_s; bool copy_x; bool copy_y; - + bool wall_x; bool wall_y; @@ -358,7 +358,7 @@ struct euler_mixture2d_single_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D Euler mixture equations. */ -void euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_init* init); +void euler_mixture2d_run_single(int argc, char **argv, struct euler_mixture2d_single_init *init); // Initialization data for a 2D simulation using the Euler equations, run with static, block-structured mesh refinement with a doubly-nested refinement patch. struct euler2d_double_init { @@ -409,7 +409,7 @@ struct euler2d_double_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D Euler equations. */ -void euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init); +void euler2d_run_double(int argc, char **argv, struct euler2d_double_init *init); // Initialization data for a 2D simulation using the general relativistic Euler equations, run with static, block-structured mesh refinement with a doubly-nested refinement patch. struct gr_euler2d_double_init { @@ -461,7 +461,7 @@ struct gr_euler2d_double_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D general relativistic Euler equations. */ -void gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init); +void gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init *init); // Initialization data for a 2D simulation using the Euler mixture equations, run with static, block-structured mesh refinement with a doubly-nested refinement patch. struct euler_mixture2d_double_init { @@ -487,7 +487,7 @@ struct euler_mixture2d_double_init { evalf_t eval; int num_species; - double* gas_gamma_s; + double *gas_gamma_s; bool copy_x; bool copy_y; @@ -513,7 +513,7 @@ struct euler_mixture2d_double_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D Euler mixture equations. */ -void euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_init* init); +void euler_mixture2d_run_double(int argc, char **argv, struct euler_mixture2d_double_init *init); // Initialization data for a 1D simulation using the coupled five-moment equations, run with static, patch-structured mesh refinement with a single refinement patch. struct five_moment_1d_single_init { @@ -562,7 +562,7 @@ struct five_moment_1d_single_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 1D coupled five-moment equations. */ -void five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_init* init); +void five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_init *init); // Initialization data for a 1D simulation using the coupled ten-moment equations, run with static, patch-structured mesh refinement with a single refinement patch. struct ten_moment_1d_single_init { @@ -610,7 +610,7 @@ struct ten_moment_1d_single_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 1D coupled ten-moment equations. */ -void ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init* init); +void ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init *init); // Initialization data for a 1D simulation using the coupled five-moment equations, run with static, patch-structured mesh refinement with a doubly-nested refinement patch. struct five_moment_1d_double_init { @@ -663,7 +663,7 @@ struct five_moment_1d_double_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 1D coupled five-moment equations. */ -void five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_init* init); +void five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_init *init); // Initialization data for a 2D simulation using the coupled five-moment equations, run with static, block-structured mesh refinement with a single refinement patch. struct five_moment_2d_single_init { @@ -723,7 +723,7 @@ struct five_moment_2d_single_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D coupled five-moment equations. */ -void five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_init* init); +void five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_init *init); // Initialization data for a 2D simulation using the coupled five-moment equations, run with static, block-structured mesh refinement with a single refinement patch. struct ten_moment_2d_single_init { @@ -782,7 +782,7 @@ struct ten_moment_2d_single_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D coupled ten-moment equations. */ -void ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init* init); +void ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init *init); // Initialization data for a 2D simulation using the coupled five-moment equations, run with static, block-structured mesh refinement with a doubly-nested refinement patch. struct five_moment_2d_double_init { @@ -848,7 +848,7 @@ struct five_moment_2d_double_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D coupled five-moment equations. */ -void five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_init* init); +void five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_init *init); // Initialization data for a 2D simulation using the coupled ten-moment equations, run with static, block-structured mesh refinement with a doubly-nested refinement patch. struct ten_moment_2d_double_init { @@ -914,4 +914,4 @@ struct ten_moment_2d_double_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D coupled ten-moment equations. */ -void ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init* init); \ No newline at end of file +void ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init *init); \ No newline at end of file diff --git a/moments/amr/gkyl_amr_patch_coupled_priv.h b/moments/amr/gkyl_amr_patch_coupled_priv.h index fc72b6f9d1..7c194fc221 100644 --- a/moments/amr/gkyl_amr_patch_coupled_priv.h +++ b/moments/amr/gkyl_amr_patch_coupled_priv.h @@ -84,7 +84,9 @@ struct five_moment_update_patch_ctx { * @param pdata Patch-structured data for the coupled five-moment equations. * @param conn Topology/connectivity data for the patch hierarchy. */ -void five_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn); +void five_moment_patch_bc_updaters_init( + struct five_moment_patch_data *pdata, const struct gkyl_block_connections *conn +); /** * Initialize nested patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the coupled five-moment equations. @@ -92,7 +94,9 @@ void five_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, co * @param pdata Patch-structured data for the coupled five-moment equations. * @param conn Topology/connectivity data for the patch hierarchy. */ -void five_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn); +void five_moment_nested_patch_bc_updaters_init( + struct five_moment_patch_data *pdata, const struct gkyl_block_connections *conn +); /** * Initialize patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the coupled ten-moment equations. @@ -100,7 +104,9 @@ void five_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pd * @param pdata Patch-structured data for the coupled ten-moment equations. * @param conn Topology/connectivity data for the patch hierarchy. */ -void ten_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn); +void ten_moment_patch_bc_updaters_init( + struct five_moment_patch_data *pdata, const struct gkyl_block_connections *conn +); /** * Initialize nested patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the coupled ten-moment equations. @@ -108,14 +114,16 @@ void ten_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, con * @param pdata Patch-structured data for the coupled ten-moment equations. * @param conn Topology/connectivity data for the patch hierarchy. */ -void ten_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn); +void ten_moment_nested_patch_bc_updaters_init( + struct five_moment_patch_data *pdata, const struct gkyl_block_connections *conn +); /** * Release patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the coupled five-moment equations. * * @param pdata Patch-structured data for the coupled five-moment equations. */ -void five_moment_patch_bc_updaters_release(struct five_moment_patch_data* pdata); +void five_moment_patch_bc_updaters_release(struct five_moment_patch_data *pdata); /** * Apply both physical (outer-patch) and non-physical (inter-patch) patch AMR boundary conditions for the coupled five-moment equations. @@ -126,8 +134,10 @@ void five_moment_patch_bc_updaters_release(struct five_moment_patch_data* pdata) * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void five_moment_patch_bc_updaters_apply(const struct five_moment_patch_data* pdata, double tm, - struct gkyl_array* fld_elc, struct gkyl_array *fld_ion, struct gkyl_array* fld_maxwell); +void five_moment_patch_bc_updaters_apply( + const struct five_moment_patch_data *pdata, double tm, struct gkyl_array *fld_elc, + struct gkyl_array *fld_ion, struct gkyl_array *fld_maxwell +); /** * Coarse-to-fine projection operator for coupled, patch-structured AMR, assuming a lower coarse patch and a lower fine patch. @@ -144,9 +154,12 @@ void five_moment_patch_bc_updaters_apply(const struct five_moment_patch_data* pd * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void patch_coupled_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void patch_coupled_ll_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Fine-to-coarse restriction operator for coupled, patch-structured AMR, assuming a lower fine patch and a lower coarse patch. @@ -163,9 +176,12 @@ void patch_coupled_ll_projection_op(const int tbid, const int tdir, const int i, * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void patch_coupled_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void patch_coupled_ll_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Coarse-to-fine projection operator for coupled, patch-structured AMR, assuming a lower coarse patch and an upper fine patch. @@ -182,9 +198,12 @@ void patch_coupled_ll_restriction_op(const int tbid, const int tdir, const int i * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void patch_coupled_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void patch_coupled_lu_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Fine-to-coarse restriction operator for coupled, patch-structured AMR, assuming a lower fine patch and an upper coarse patch. @@ -201,9 +220,12 @@ void patch_coupled_lu_projection_op(const int tbid, const int tdir, const int i, * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void patch_coupled_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void patch_coupled_lu_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Coarse-to-fine projection operator for coupled, patch-structured AMR, assuming an upper coarse patch and a lower fine patch. @@ -220,9 +242,12 @@ void patch_coupled_lu_restriction_op(const int tbid, const int tdir, const int i * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void patch_coupled_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void patch_coupled_ul_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Fine-to-coarse restriction operator for coupled, patch-structured AMR, assuming an upper fine patch and a lower coarse patch. @@ -239,9 +264,12 @@ void patch_coupled_ul_projection_op(const int tbid, const int tdir, const int i, * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void patch_coupled_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void patch_coupled_ul_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Coarse-to-fine projection operator for coupled, patch-structured AMR, assuming an upper coarse patch and an upper fine patch. @@ -258,9 +286,12 @@ void patch_coupled_ul_restriction_op(const int tbid, const int tdir, const int i * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void patch_coupled_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void patch_coupled_uu_projection_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Fine-to-coarse restriction operator for coupled, patch-structured AMR, assuming an upper fine patch and an upper coarse patch. @@ -277,9 +308,12 @@ void patch_coupled_uu_projection_op(const int tbid, const int tdir, const int i, * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void patch_coupled_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], - const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void patch_coupled_uu_restriction_op( + const int tbid, const int tdir, const int i, const int d, + const struct five_moment_patch_data pdata[], const struct gkyl_array *bc_buffer_elc, + const struct gkyl_array *bc_buffer_ion, const struct gkyl_array *bc_buffer_maxwell, + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Synchronize all patches in the patch AMR hierarchy by applying all appropriate physical (outer-patch) and non-physical (inter-patch) @@ -291,8 +325,10 @@ void patch_coupled_uu_restriction_op(const int tbid, const int tdir, const int i * @param fld_ion Output array (ions). * @param fld_maxwell Output array (Maxwell field). */ -void five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct five_moment_patch_data pdata[], - struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); +void five_moment_sync_patches( + const struct gkyl_block_topo *ptopo, const struct five_moment_patch_data pdata[], + struct gkyl_array *fld_elc[], struct gkyl_array *fld_ion[], struct gkyl_array *fld_maxwell[] +); /** * Write patch-structured AMR simulation data for the coupled five-moment equations onto disk. @@ -302,7 +338,10 @@ void five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct * @param file_nm_maxwell File name schema to use for the Maxwell field simulation output. * @param pdata Patch-structured data for the coupled five-moment equations. */ -void five_moment_patch_data_write(const char* file_nm_elc, const char* file_nm_ion, const char* file_nm_maxwell, const struct five_moment_patch_data* pdata); +void five_moment_patch_data_write( + const char *file_nm_elc, const char *file_nm_ion, const char *file_nm_maxwell, + const struct five_moment_patch_data *pdata +); /** * Calculate the maximum stable time-step for the patch-structured, coupled five-moment equations. @@ -310,21 +349,21 @@ void five_moment_patch_data_write(const char* file_nm_elc, const char* file_nm_i * @param pdata Patch-structured data for the coupled five-moment equations. * @return Maximum stable time-step. */ -double five_moment_patch_data_max_dt(const struct five_moment_patch_data* pdata); +double five_moment_patch_data_max_dt(const struct five_moment_patch_data *pdata); /** * Update the patch-structured AMR simulation data for the coupled five-moment equations using the thread-based job pool. * * @param ctx Context to pass to the function. */ -void five_moment_update_patch_job_func(void* ctx); +void five_moment_update_patch_job_func(void *ctx); /** * Update the source terms of the patch-structured AMR simulation data for the coupled five-moment equations using the thread-based job pool. * * @param ctx Context to pass to the function. */ -void five_moment_update_patch_job_func_source(void* ctx); +void five_moment_update_patch_job_func_source(void *ctx); /** * Update all patches in the patch AMR hierarchy by using the thread-based job pool for the coupled five-moment equations. @@ -336,8 +375,10 @@ void five_moment_update_patch_job_func_source(void* ctx); * @param dt Current stable time-step for the simulation. * @return Status of the update (success and suggested time-step). */ -struct gkyl_update_status five_moment_update_all_patches(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* ptopo, - const struct five_moment_patch_data pdata[], double t_curr, double dt); +struct gkyl_update_status five_moment_update_all_patches( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *ptopo, + const struct five_moment_patch_data pdata[], double t_curr, double dt +); /** * Update the source terms for all patches in the patch AMR hierarchy by using the thread-based job pool for the coupled five-moment equations. @@ -349,15 +390,17 @@ struct gkyl_update_status five_moment_update_all_patches(const struct gkyl_job_p * @param dt Current stable time-step for the simulation. * @param nstrang Iteration number in the Strang splitting. */ -void five_moment_update_all_patches_source(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* ptopo, - const struct five_moment_patch_data pdata[], double t_curr, double dt, int nstrang); +void five_moment_update_all_patches_source( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *ptopo, + const struct five_moment_patch_data pdata[], double t_curr, double dt, int nstrang +); /** * Initialize a new job in the thread-based job pool for updating the patch-structured AMR simulation data for the coupled five-moment equations. * * @param ctx Context to pass to the function. */ -void five_moment_init_job_func_patch(void* ctx); +void five_moment_init_job_func_patch(void *ctx); /** * Take a single time-step across the entire patch AMR hierarchy for the coupled five-moment equations. @@ -370,8 +413,10 @@ void five_moment_init_job_func_patch(void* ctx); * @param stats Simulation statistics (allowing for tracking of the number of failed time-steps). * @return Status of the update (success, suggested time-step and actual time-step). */ -struct gkyl_update_status five_moment_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* ptopo, - const struct five_moment_patch_data pdata[], double t_curr, double dt0, struct sim_stats* stats); +struct gkyl_update_status five_moment_update_patch( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *ptopo, + const struct five_moment_patch_data pdata[], double t_curr, double dt0, struct sim_stats *stats +); /** * Write the complete simulation output for the entire patch AMR hierarchy for the coupled five-moment equations onto disk. @@ -380,7 +425,9 @@ struct gkyl_update_status five_moment_update_patch(const struct gkyl_job_pool* j * @param num_patches Number of patches in the patch hierarchy. * @param pdata Array of patch-structured data for the coupled five-moment equations. */ -void five_moment_write_sol_patch(const char* fbase, int num_patches, const struct five_moment_patch_data pdata[]); +void five_moment_write_sol_patch( + const char *fbase, int num_patches, const struct five_moment_patch_data pdata[] +); /** * Calculate the maximum stable time-step across all patches in the patch AMR hierarchy for the coupled five-moment equations. diff --git a/moments/amr/gkyl_amr_patch_priv.h b/moments/amr/gkyl_amr_patch_priv.h index 38df2ae743..f59f2e73cc 100644 --- a/moments/amr/gkyl_amr_patch_priv.h +++ b/moments/amr/gkyl_amr_patch_priv.h @@ -24,7 +24,7 @@ struct euler_patch_data { struct gkyl_array *f[2]; struct gkyl_wave_geom *geom; - + struct gkyl_wv_eqn *euler; gkyl_wave_prop *slvr[1]; @@ -52,7 +52,9 @@ struct euler_update_patch_ctx { * @param parent Ranges for the parent regions (of which the skin and ghost regions are subregions). * @param ghost Number of ghost (and therefore skin) cells. */ -void skin_ghost_ranges_init_patch(struct skin_ghost_ranges_patch* sgr, const struct gkyl_range* parent, const int* ghost); +void skin_ghost_ranges_init_patch( + struct skin_ghost_ranges_patch *sgr, const struct gkyl_range *parent, const int *ghost +); /** * Initialize patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the Euler equations. @@ -61,7 +63,10 @@ void skin_ghost_ranges_init_patch(struct skin_ghost_ranges_patch* sgr, const str * @param pdata Patch-structured data for the Euler equations. * @param conn Topology/connectivity data for the patch hierarchy. */ -void euler_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn); +void euler_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +); /** * Initialize nested patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the Euler equations. @@ -70,7 +75,10 @@ void euler_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_pa * @param pdata Patch-structured data for the Euler equations. * @param conn Topology/connectivity data for the patch hierarchy. */ -void euler_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn); +void euler_nested_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +); /** * Initialize patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the general relativistic Euler equations. @@ -79,7 +87,10 @@ void euler_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct e * @param pdata Patch-structured data for the general relativistic Euler equations. * @param conn Topology/connectivity data for the patch hierarchy. */ -void gr_euler_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn); +void gr_euler_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +); /** * Initialize nested patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the general relativistic Euler equations. @@ -88,7 +99,10 @@ void gr_euler_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler * @param pdata Patch-structured data for the general relativistic Euler equations. * @param conn Topology/connectivity data for the patch hierarchy. */ -void gr_euler_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn); +void gr_euler_nested_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +); /** * Initialize patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the Euler mixture equations. @@ -97,7 +111,10 @@ void gr_euler_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struc * @param pdata Patch-structured data for the Euler mixture equations. * @param conn Topology/connectivity data for the patch hierarchy. */ -void euler_mixture_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn); +void euler_mixture_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +); /** * Initialize nested patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the Euler mixture equations. @@ -106,14 +123,17 @@ void euler_mixture_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct * @param pdata Patch-structured data for the Euler mixture equations. * @param conn Topology/connectivity data for the patch hierarchy. */ -void euler_mixture_nested_patch_bc_updaters_init(const struct gkyl_wv_eqn* eqn, struct euler_patch_data* pdata, const struct gkyl_block_connections* conn); +void euler_mixture_nested_patch_bc_updaters_init( + const struct gkyl_wv_eqn *eqn, struct euler_patch_data *pdata, + const struct gkyl_block_connections *conn +); /** * Release patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the Euler equations. * * @param pdata Patch-structured data for the Euler equations. */ -void euler_patch_bc_updaters_release(struct euler_patch_data* pdata); +void euler_patch_bc_updaters_release(struct euler_patch_data *pdata); /** * Apply both physical (outer-patch) and non-physical (inter-patch) patch AMR boundary conditions for the Euler equations. @@ -122,7 +142,9 @@ void euler_patch_bc_updaters_release(struct euler_patch_data* pdata); * @param tm Simulation time at which the boundary conditions are applied. * @param fld Output array. */ -void euler_patch_bc_updaters_apply(const struct euler_patch_data* pdata, double tm, struct gkyl_array* fld); +void euler_patch_bc_updaters_apply( + const struct euler_patch_data *pdata, double tm, struct gkyl_array *fld +); /** * Coarse-to-fine projection operator for patch-structured AMR, assuming a lower coarse patch and a lower fine patch. @@ -135,8 +157,10 @@ void euler_patch_bc_updaters_apply(const struct euler_patch_data* pdata, double * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void patch_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void patch_ll_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Fine-to-coarse restriction operator for patch-structured AMR, assuming a lower fine patch and a lower coarse patch. @@ -149,8 +173,10 @@ void patch_ll_projection_op(const int tbid, const int tdir, const int i, const i * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void patch_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void patch_ll_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Coarse-to-fine projection operator for patch-structured AMR, assuming a lower coarse patch and an upper fine patch. @@ -163,8 +189,10 @@ void patch_ll_restriction_op(const int tbid, const int tdir, const int i, const * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void patch_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void patch_lu_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Fine-to-coarse restriction operator for patch-structured AMR, assuming a lower fine patch and an upper coarse patch. @@ -177,10 +205,12 @@ void patch_lu_projection_op(const int tbid, const int tdir, const int i, const i * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void patch_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void patch_lu_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); - /** +/** * Coarse-to-fine projection operator for patch-structured AMR, assuming an upper coarse patch and a lower fine patch. * * @param tbid Target (fine) patch ID. @@ -191,8 +221,10 @@ void patch_lu_restriction_op(const int tbid, const int tdir, const int i, const * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void patch_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void patch_ul_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Fine-to-coarse restriction operator for patch-structured AMR, assuming an upper fine patch and a lower coarse patch. @@ -205,8 +237,10 @@ void patch_ul_projection_op(const int tbid, const int tdir, const int i, const i * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void patch_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void patch_ul_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Coarse-to-fine projection operator for patch-structured AMR, assuming an upper coarse patch and an upper fine patch. @@ -219,8 +253,10 @@ void patch_ul_restriction_op(const int tbid, const int tdir, const int i, const * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void patch_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void patch_uu_projection_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Fine-to-coarse restriction operator for patch-structured AMR, assuming an upper fine patch and an upper coarse patch. @@ -233,8 +269,10 @@ void patch_uu_projection_op(const int tbid, const int tdir, const int i, const i * @param bc_buffer Buffer for applying boundary conditions. * @param fld Output array. */ -void patch_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], - const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); +void patch_uu_restriction_op( + const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array *bc_buffer, struct gkyl_array *fld[] +); /** * Synchronize all patches in the patch AMR hierarchy by applying all appropriate physical (outer-patch) and non-physical (inter-patch) @@ -244,7 +282,10 @@ void patch_uu_restriction_op(const int tbid, const int tdir, const int i, const * @param pdata Patch=structured data for the Euler equations. * @param fld Output array. */ -void euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch_data pdata[], struct gkyl_array* fld[]); +void euler_sync_patches( + const struct gkyl_block_topo *ptopo, const struct euler_patch_data pdata[], + struct gkyl_array *fld[] +); /** * Write patch-structured AMR simulation data for the Euler equations onto disk. @@ -252,7 +293,7 @@ void euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_ * @param file_nm File name schema to use for the simulation output. * @param pdata Patch-structured data for the Euler equations. */ -void euler_patch_data_write(const char* file_nm, const struct euler_patch_data* pdata); +void euler_patch_data_write(const char *file_nm, const struct euler_patch_data *pdata); /** * Calculate the maximum stable time-step for the patch-structured Euler equations. @@ -260,14 +301,14 @@ void euler_patch_data_write(const char* file_nm, const struct euler_patch_data* * @param pdata Patch-structured data for the Euler equations. * @return Maximum stable time-step. */ -double euler_patch_data_max_dt(const struct euler_patch_data* pdata); +double euler_patch_data_max_dt(const struct euler_patch_data *pdata); /** * Update the patch-structured AMR simulation data for the Euler equations using the thread-based job pool. * * @param ctx Context to pass to the function. */ -void euler_update_patch_job_func(void* ctx); +void euler_update_patch_job_func(void *ctx); /** * Update all patches in the patch AMR hierarchy by using the thread-based job pool for the Euler equations. @@ -279,15 +320,17 @@ void euler_update_patch_job_func(void* ctx); * @param dt Current stable time-step for the simulation. * @return Status of the update (success and suggested time-step). */ -struct gkyl_update_status euler_update_all_patches(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* ptopo, - const struct euler_patch_data pdata[], double t_curr, double dt); +struct gkyl_update_status euler_update_all_patches( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *ptopo, + const struct euler_patch_data pdata[], double t_curr, double dt +); /** * Initialize a new job in the thread-based job pool for updating the patch-structured AMR simulation data for the Euler equations. * * @param ctx Context to pass to the function. */ -void euler_init_job_func_patch(void* ctx); +void euler_init_job_func_patch(void *ctx); /** * Take a single time-step across the entire patch AMR hierarchy for the Euler equations. @@ -300,8 +343,10 @@ void euler_init_job_func_patch(void* ctx); * @param stats Simulation statistics (allowing for tracking of the number of failed time-steps). * @return Status of the update (success, suggested time-step and actual time-step). */ -struct gkyl_update_status euler_update_patch(const struct gkyl_job_pool* job_pool, const struct gkyl_block_topo* ptopo, - const struct euler_patch_data pdata[], double t_curr, double dt0, struct sim_stats* stats); +struct gkyl_update_status euler_update_patch( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *ptopo, + const struct euler_patch_data pdata[], double t_curr, double dt0, struct sim_stats *stats +); /** * Write the complete simulation output for the entire patch AMR hierarchy for the Euler equations onto disk. @@ -310,7 +355,9 @@ struct gkyl_update_status euler_update_patch(const struct gkyl_job_pool* job_poo * @param num_patches Number of patches in the patch hierarchy. * @param pdata Array of patch-structured data for the Euler equations. */ -void euler_write_sol_patch(const char* fbase, int num_patches, const struct euler_patch_data pdata[]); +void euler_write_sol_patch( + const char *fbase, int num_patches, const struct euler_patch_data pdata[] +); /** * Calculate the maximum stable time-step across all patches in the patch AMR hierarchy for the Euler equations. @@ -324,9 +371,9 @@ double euler_max_dt_patch(int num_patches, const struct euler_patch_data pdata[] /** * Set up the topology/connectivity information for the patch AMR hierarchy for a mesh containing a single refinement patch. */ -struct gkyl_block_topo* create_patch_topo(); +struct gkyl_block_topo *create_patch_topo(); /** * Set up the topology/connectivity information for the patch AMR hierarchy for a mesh containing a doubly-nested refinement patch. */ -struct gkyl_block_topo* create_nested_patch_topo(); \ No newline at end of file +struct gkyl_block_topo *create_nested_patch_topo(); \ No newline at end of file diff --git a/moments/amr_creg/rt_amr_10m_gem_l1.c b/moments/amr_creg/rt_amr_10m_gem_l1.c index e5554d5cfb..bacdb40aff 100644 --- a/moments/amr_creg/rt_amr_10m_gem_l1.c +++ b/moments/amr_creg/rt_amr_10m_gem_l1.c @@ -6,11 +6,10 @@ #include -struct amr_10m_gem_ctx -{ +struct amr_10m_gem_ctx { // Mathematical constants (dimensionless). double pi; - + // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -27,7 +26,7 @@ struct amr_10m_gem_ctx double k0_elc; // Electron closure parameter. double k0_ion; // Ion closure parameter. - + // Derived physical quantities (using normalized code units). double psi0; // Reference magnetic scalar potential. @@ -51,8 +50,7 @@ struct amr_10m_gem_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_10m_gem_ctx -create_ctx(void) +struct amr_10m_gem_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -73,7 +71,7 @@ create_ctx(void) double k0_elc = 5.0; // Electron closure parameter. double k0_ion = 5.0; // Ion closure parameter. - + // Derived physical quantities (using normalized code units). double psi0 = 0.1 * B0; // Reference magnetic scalar potential. @@ -127,14 +125,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_10m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -151,7 +148,8 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Te_frac = app->Te_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -163,14 +161,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = momze; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = momze; // Set electron pressure tensor. - fout[4] = pre; fout[5] = 0.0; fout[6] = 0.0; - fout[7] = pre; fout[8] = 0.0; fout[9] = pre + momze * momze / rhoe; + fout[4] = pre; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = pre; + fout[8] = 0.0; + fout[9] = pre + momze * momze / rhoe; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_10m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -187,7 +190,8 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Ti_frac = app->Ti_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -199,14 +203,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = momzi; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = momzi; // Set ion pressure tensor. - fout[4] = pri; fout[5] = 0.0; fout[6] = 0.0; - fout[7] = pri; fout[8] = 0.0; fout[9] = pri + momzi * momzi / rhoi; + fout[4] = pri; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = pri; + fout[8] = 0.0; + fout[9] = pri + momzi * momzi / rhoi; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_10m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -223,16 +232,21 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ly = app->Ly; double Bxb = B0 * tanh(y / lambda); // Total magnetic field strength. - double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * sin(pi * y / Ly); // Total magnetic field (x-direction). - double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * cos(pi * y / Ly); // Total magnetic field (y-direction). + double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * + sin(pi * y / Ly); // Total magnetic field (x-direction). + double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * + cos(pi * y / Ly); // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } int main(int argc, char **argv) @@ -285,7 +299,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; ten_moment_2d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_10m_gem_l2.c b/moments/amr_creg/rt_amr_10m_gem_l2.c index d416a96afe..6c2efccc17 100644 --- a/moments/amr_creg/rt_amr_10m_gem_l2.c +++ b/moments/amr_creg/rt_amr_10m_gem_l2.c @@ -6,11 +6,10 @@ #include -struct amr_10m_gem_ctx -{ +struct amr_10m_gem_ctx { // Mathematical constants (dimensionless). double pi; - + // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -27,7 +26,7 @@ struct amr_10m_gem_ctx double k0_elc; // Electron closure parameter. double k0_ion; // Ion closure parameter. - + // Derived physical quantities (using normalized code units). double psi0; // Reference magnetic scalar potential. @@ -54,8 +53,7 @@ struct amr_10m_gem_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_10m_gem_ctx -create_ctx(void) +struct amr_10m_gem_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -76,7 +74,7 @@ create_ctx(void) double k0_elc = 5.0; // Electron closure parameter. double k0_ion = 5.0; // Ion closure parameter. - + // Derived physical quantities (using normalized code units). double psi0 = 0.1 * B0; // Reference magnetic scalar potential. @@ -136,14 +134,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_10m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -160,7 +157,8 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Te_frac = app->Te_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -172,14 +170,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = momze; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = momze; // Set electron pressure tensor. - fout[4] = pre; fout[5] = 0.0; fout[6] = 0.0; - fout[7] = pre; fout[8] = 0.0; fout[9] = pre + momze * momze / rhoe; + fout[4] = pre; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = pre; + fout[8] = 0.0; + fout[9] = pre + momze * momze / rhoe; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_10m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -196,7 +199,8 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Ti_frac = app->Ti_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -208,14 +212,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = momzi; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = momzi; // Set ion pressure tensor. - fout[4] = pri; fout[5] = 0.0; fout[6] = 0.0; - fout[7] = pri; fout[8] = 0.0; fout[9] = pri + momzi * momzi / rhoi; + fout[4] = pri; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = pri; + fout[8] = 0.0; + fout[9] = pri + momzi * momzi / rhoi; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_10m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -232,16 +241,21 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ly = app->Ly; double Bxb = B0 * tanh(y / lambda); // Total magnetic field strength. - double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * sin(pi * y / Ly); // Total magnetic field (x-direction). - double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * cos(pi * y / Ly); // Total magnetic field (y-direction). + double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * + sin(pi * y / Ly); // Total magnetic field (x-direction). + double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * + cos(pi * y / Ly); // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } int main(int argc, char **argv) @@ -300,7 +314,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; ten_moment_2d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_10m_riem_l1.c b/moments/amr_creg/rt_amr_10m_riem_l1.c index e1250780f7..7121dbc12f 100644 --- a/moments/amr_creg/rt_amr_10m_riem_l1.c +++ b/moments/amr_creg/rt_amr_10m_riem_l1.c @@ -6,8 +6,7 @@ #include -struct amr_10m_riem_ctx -{ +struct amr_10m_riem_ctx { // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -48,8 +47,7 @@ struct amr_10m_riem_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_10m_riem_ctx -create_ctx(void) +struct amr_10m_riem_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -119,14 +117,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_10m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -144,8 +141,7 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_elc; // Electron mass density (left). p = pl; // Electron pressure (left). - } - else { + } else { rho = rhor_elc; // Electron mass density (right). p = pr; // Electron pressure (right). } @@ -153,14 +149,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho; // Set electron momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set electron pressure tensor. - fout[4] = p; fout[5] = 0.0; fout[6] = 0.0; - fout[7] = p; fout[8] = 0.0; fout[9] = 0.0; + fout[4] = p; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = p; + fout[8] = 0.0; + fout[9] = 0.0; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_10m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -178,8 +179,7 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_ion; // Ion mass density (left). p = pl; // Ion pressure (left). - } - else { + } else { rho = rhor_ion; // Ion mass density (right). p = pr; // Ion pressure (right). } @@ -187,14 +187,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rho; // Set ion momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set ion pressure tensor. - fout[4] = p; fout[5] = 0.0; fout[6] = 0.0; - fout[7] = p; fout[8] = 0.0; fout[9] = p; + fout[4] = p; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = p; + fout[8] = 0.0; + fout[9] = p; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_10m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -208,17 +213,19 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo if (x < 0.5) { Bz = Bzl; // Total magnetic field (z-direction, left). - } - else { + } else { Bz = Bzr; // Total magnetic field (z-direction, right). } // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = Bx, fout[4] = 0.0; fout[5] = Bz; + fout[3] = Bx, fout[4] = 0.0; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } int main(int argc, char **argv) @@ -260,7 +267,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; ten_moment_1d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_5m_gem_l1.c b/moments/amr_creg/rt_amr_5m_gem_l1.c index 8feb8aeed2..6f884bd93a 100644 --- a/moments/amr_creg/rt_amr_5m_gem_l1.c +++ b/moments/amr_creg/rt_amr_5m_gem_l1.c @@ -6,11 +6,10 @@ #include -struct amr_5m_gem_ctx -{ +struct amr_5m_gem_ctx { // Mathematical constants (dimensionless). double pi; - + // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double epsilon0; // Permittivity of free space. @@ -28,7 +27,7 @@ struct amr_5m_gem_ctx double k0_elc; // Electron closure parameter. double k0_ion; // Ion closure parameter. - + // Derived physical quantities (using normalized code units). double psi0; // Reference magnetic scalar potential. @@ -52,8 +51,7 @@ struct amr_5m_gem_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_5m_gem_ctx -create_ctx(void) +struct amr_5m_gem_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -75,7 +73,7 @@ create_ctx(void) double k0_elc = 0.0; // Electron closure parameter. double k0_ion = 0.0; // Ion closure parameter. - + // Derived physical quantities (using normalized code units). double psi0 = 0.1 * B0; // Reference magnetic scalar potential. @@ -130,14 +128,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_5m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -155,25 +152,28 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Te_frac = app->Te_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). double rhoe = n * mass_elc; // Electron mass density. double momze = (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). - double Ee_tot = n * T_tot * Te_frac / (gas_gamma - 1.0) + 0.5 * momze * momze / rhoe; // Electron total energy density. + double Ee_tot = n * T_tot * Te_frac / (gas_gamma - 1.0) + + 0.5 * momze * momze / rhoe; // Electron total energy density. // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = momze; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = momze; // Set electron total energy density. fout[4] = Ee_tot; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_5m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -191,25 +191,28 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Ti_frac = app->Ti_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). double rhoi = n * mass_ion; // Ion mass density. double momzi = (mass_ion / charge_ion) * Jz * Ti_frac; // Ion momentum density (z-direction). - double Ei_tot = n * T_tot * Ti_frac / (gas_gamma - 1.0) + 0.5 * momzi * momzi / rhoi; // Ion total energy density. + double Ei_tot = n * T_tot * Ti_frac / (gas_gamma - 1.0) + + 0.5 * momzi * momzi / rhoi; // Ion total energy density. // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = momzi; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = momzi; // Set ion total energy density. fout[4] = Ei_tot; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_5m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -226,16 +229,23 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ly = app->Ly; double Bxb = B0 * tanh(y / lambda); // Total magnetic field strength. - double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * sin(pi * y / Ly); // Total magnetic field (x-direction). - double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * cos(pi * y / Ly); // Total magnetic field (y-direction). + double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * + sin(pi * y / Ly); // Total magnetic field (x-direction). + double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * + cos(pi * y / Ly); // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } int main(int argc, char **argv) @@ -289,7 +299,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; five_moment_2d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_5m_gem_l2.c b/moments/amr_creg/rt_amr_5m_gem_l2.c index dd602568b7..e152136547 100644 --- a/moments/amr_creg/rt_amr_5m_gem_l2.c +++ b/moments/amr_creg/rt_amr_5m_gem_l2.c @@ -6,11 +6,10 @@ #include -struct amr_5m_gem_ctx -{ +struct amr_5m_gem_ctx { // Mathematical constants (dimensionless). double pi; - + // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double epsilon0; // Permittivity of free space. @@ -28,7 +27,7 @@ struct amr_5m_gem_ctx double k0_elc; // Electron closure parameter. double k0_ion; // Ion closure parameter. - + // Derived physical quantities (using normalized code units). double psi0; // Reference magnetic scalar potential. @@ -55,8 +54,7 @@ struct amr_5m_gem_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_5m_gem_ctx -create_ctx(void) +struct amr_5m_gem_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -78,7 +76,7 @@ create_ctx(void) double k0_elc = 0.0; // Electron closure parameter. double k0_ion = 0.0; // Ion closure parameter. - + // Derived physical quantities (using normalized code units). double psi0 = 0.1 * B0; // Reference magnetic scalar potential. @@ -139,14 +137,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_5m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -164,25 +161,28 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Te_frac = app->Te_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). double rhoe = n * mass_elc; // Electron mass density. double momze = (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). - double Ee_tot = n * T_tot * Te_frac / (gas_gamma - 1.0) + 0.5 * momze * momze / rhoe; // Electron total energy density. + double Ee_tot = n * T_tot * Te_frac / (gas_gamma - 1.0) + + 0.5 * momze * momze / rhoe; // Electron total energy density. // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = momze; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = momze; // Set electron total energy density. fout[4] = Ee_tot; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_5m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -200,25 +200,28 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Ti_frac = app->Ti_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). double rhoi = n * mass_ion; // Ion mass density. double momzi = (mass_ion / charge_ion) * Jz * Ti_frac; // Ion momentum density (z-direction). - double Ei_tot = n * T_tot * Ti_frac / (gas_gamma - 1.0) + 0.5 * momzi * momzi / rhoi; // Ion total energy density. + double Ei_tot = n * T_tot * Ti_frac / (gas_gamma - 1.0) + + 0.5 * momzi * momzi / rhoi; // Ion total energy density. // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = momzi; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = momzi; // Set ion total energy density. fout[4] = Ei_tot; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_5m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -235,16 +238,23 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ly = app->Ly; double Bxb = B0 * tanh(y / lambda); // Total magnetic field strength. - double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * sin(pi * y / Ly); // Total magnetic field (x-direction). - double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * cos(pi * y / Ly); // Total magnetic field (y-direction). + double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * + sin(pi * y / Ly); // Total magnetic field (x-direction). + double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * + cos(pi * y / Ly); // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } int main(int argc, char **argv) @@ -304,7 +314,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; five_moment_2d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_5m_riem_l1.c b/moments/amr_creg/rt_amr_5m_riem_l1.c index 625c3abf50..19e7ec884d 100644 --- a/moments/amr_creg/rt_amr_5m_riem_l1.c +++ b/moments/amr_creg/rt_amr_5m_riem_l1.c @@ -6,8 +6,7 @@ #include -struct amr_5m_riem_ctx -{ +struct amr_5m_riem_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double epsilon0; // Permittivity of free space. @@ -49,8 +48,7 @@ struct amr_5m_riem_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_5m_riem_ctx -create_ctx(void) +struct amr_5m_riem_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -121,14 +119,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_5m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -148,8 +145,7 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_elc; // Electron mass density (left). p = pl; // Electron pressure (left). - } - else { + } else { rho = rhor_elc; // Electron mass density (right). p = pr; // Electron pressure (right). } @@ -157,13 +153,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho; // Set electron momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set electron total energy density. - fout[4] = p / (gas_gamma - 1.0); + fout[4] = p / (gas_gamma - 1.0); } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_5m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -182,8 +179,7 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_ion; // Ion mass density (left). p = pl; // Ion pressure (left). - } - else { + } else { rho = rhor_ion; // Ion mass density (right). p = pr; // Ion pressure (right). } @@ -191,13 +187,14 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rho; // Set ion momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set ion total energy density. - fout[4] = p / (gas_gamma - 1.0); + fout[4] = p / (gas_gamma - 1.0); } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_5m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -211,17 +208,19 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo if (x < 0.5) { Bz = Bzl; // Total magnetic field (z-direction, left). - } - else { + } else { Bz = Bzr; // Total magnetic field (z-direction, right). } // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = Bx, fout[4] = 0.0; fout[5] = Bz; + fout[3] = Bx, fout[4] = 0.0; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } int main(int argc, char **argv) @@ -264,7 +263,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; five_moment_1d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_5m_riem_l2.c b/moments/amr_creg/rt_amr_5m_riem_l2.c index d7daa905f3..34defb6bef 100644 --- a/moments/amr_creg/rt_amr_5m_riem_l2.c +++ b/moments/amr_creg/rt_amr_5m_riem_l2.c @@ -6,8 +6,7 @@ #include -struct amr_5m_riem_ctx -{ +struct amr_5m_riem_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double epsilon0; // Permittivity of free space. @@ -51,8 +50,7 @@ struct amr_5m_riem_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_5m_riem_ctx -create_ctx(void) +struct amr_5m_riem_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -127,14 +125,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_5m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -154,8 +151,7 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_elc; // Electron mass density (left). p = pl; // Electron pressure (left). - } - else { + } else { rho = rhor_elc; // Electron mass density (right). p = pr; // Electron pressure (right). } @@ -163,13 +159,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho; // Set electron momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set electron total energy density. - fout[4] = p / (gas_gamma - 1.0); + fout[4] = p / (gas_gamma - 1.0); } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_5m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -188,8 +185,7 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_ion; // Ion mass density (left). p = pl; // Ion pressure (left). - } - else { + } else { rho = rhor_ion; // Ion mass density (right). p = pr; // Ion pressure (right). } @@ -197,13 +193,14 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rho; // Set ion momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set ion total energy density. - fout[4] = p / (gas_gamma - 1.0); + fout[4] = p / (gas_gamma - 1.0); } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_5m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -217,17 +214,19 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo if (x < 0.5) { Bz = Bzl; // Total magnetic field (z-direction, left). - } - else { + } else { Bz = Bzr; // Total magnetic field (z-direction, right). } // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = Bx, fout[4] = 0.0; fout[5] = Bz; + fout[3] = Bx, fout[4] = 0.0; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } int main(int argc, char **argv) @@ -274,7 +273,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; five_moment_1d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_cart_axi_sodshock_l1.c b/moments/amr_creg/rt_amr_euler_cart_axi_sodshock_l1.c index 0b0e78a9a1..3660a37fe1 100644 --- a/moments/amr_creg/rt_amr_euler_cart_axi_sodshock_l1.c +++ b/moments/amr_creg/rt_amr_euler_cart_axi_sodshock_l1.c @@ -6,8 +6,7 @@ #include -struct amr_euler_cart_axi_sodshock_ctx -{ +struct amr_euler_cart_axi_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -40,8 +39,7 @@ struct amr_euler_cart_axi_sodshock_ctx double rloc; // Fluid boundary (radial coordinate). }; -struct amr_euler_cart_axi_sodshock_ctx -create_ctx(void) +struct amr_euler_cart_axi_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -95,17 +93,17 @@ create_ctx(void) .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .rloc = rloc, + .rloc = rloc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; - struct amr_euler_cart_axi_sodshock_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_euler_cart_axi_sodshock_ctx new_ctx = + create_ctx(); // Context for initialization functions. struct amr_euler_cart_axi_sodshock_ctx *app = &new_ctx; double gas_gamma = app->gas_gamma; @@ -130,24 +128,26 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left/inner). u = ul; // Fluid velocity (left/inner). p = pl; // Fluid pressure (left/inner). - } - else { + } else { rho = rhor; // Fluid mass density (right/outer). u = ur; // Fluid velocity (right/outer). p = pr; // Fluid pressure (right/outer). } - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = rho * u; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = rho * u; + fout[2] = 0.0; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * u * u; } int main(int argc, char **argv) { - struct amr_euler_cart_axi_sodshock_ctx ctx = create_ctx(); // Context for initialization functions. + struct amr_euler_cart_axi_sodshock_ctx ctx = + create_ctx(); // Context for initialization functions. struct euler2d_single_init init = { .base_Nx = ctx.Nx, @@ -181,7 +181,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler2d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_cart_axi_sodshock_l2.c b/moments/amr_creg/rt_amr_euler_cart_axi_sodshock_l2.c index c30ecd938c..c839070027 100644 --- a/moments/amr_creg/rt_amr_euler_cart_axi_sodshock_l2.c +++ b/moments/amr_creg/rt_amr_euler_cart_axi_sodshock_l2.c @@ -6,8 +6,7 @@ #include -struct amr_euler_cart_axi_sodshock_ctx -{ +struct amr_euler_cart_axi_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -43,8 +42,7 @@ struct amr_euler_cart_axi_sodshock_ctx double rloc; // Fluid boundary (radial coordinate). }; -struct amr_euler_cart_axi_sodshock_ctx -create_ctx(void) +struct amr_euler_cart_axi_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -104,17 +102,17 @@ create_ctx(void) .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .rloc = rloc, + .rloc = rloc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; - struct amr_euler_cart_axi_sodshock_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_euler_cart_axi_sodshock_ctx new_ctx = + create_ctx(); // Context for initialization functions. struct amr_euler_cart_axi_sodshock_ctx *app = &new_ctx; double gas_gamma = app->gas_gamma; @@ -139,24 +137,26 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left/inner). u = ul; // Fluid velocity (left/inner). p = pl; // Fluid pressure (left/inner). - } - else { + } else { rho = rhor; // Fluid mass density (right/outer). u = ur; // Fluid velocity (right/outer). p = pr; // Fluid pressure (right/outer). } - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = rho * u; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = rho * u; + fout[2] = 0.0; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * u * u; } int main(int argc, char **argv) { - struct amr_euler_cart_axi_sodshock_ctx ctx = create_ctx(); // Context for initialization functions. + struct amr_euler_cart_axi_sodshock_ctx ctx = + create_ctx(); // Context for initialization functions. struct euler2d_double_init init = { .base_Nx = ctx.Nx, @@ -196,7 +196,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler2d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_mixture_fedkiw_shock_l1.c b/moments/amr_creg/rt_amr_euler_mixture_fedkiw_shock_l1.c index 219df6d103..be0e926b67 100644 --- a/moments/amr_creg/rt_amr_euler_mixture_fedkiw_shock_l1.c +++ b/moments/amr_creg/rt_amr_euler_mixture_fedkiw_shock_l1.c @@ -2,8 +2,7 @@ #include #include -struct amr_fedkiw_shock_ctx -{ +struct amr_fedkiw_shock_ctx { // Physical constants (using normalized code units). double gas_gamma1; // First species adiabatic index. double gas_gamma2; // Second species adiabatic index. @@ -36,8 +35,7 @@ struct amr_fedkiw_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_fedkiw_shock_ctx -create_ctx(void) +struct amr_fedkiw_shock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma1 = 1.4; // First species adiabatic index. @@ -93,14 +91,15 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerMixtureInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct amr_fedkiw_shock_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -140,16 +139,14 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST vx_total = ul; // Total mixture velocity (left). p_total = pl; // Total mixture pressure (left). - } - else if (x < 0.5) { + } else if (x < 0.5) { rho1 = rhoc; // First species fluid mass density (central). rho2 = rhor; // Second species fluid mass density (right). alpha1 = alpha1_c; // First species volume fraction (central). vx_total = uc; // Total mixture velocity (central). p_total = pc; // Total mixture pressure (central). - } - else { + } else { rho1 = rhoc; // First species fluid mass density (central). rho2 = rhor; // Second species fluid mass density (right). alpha1 = alpha1_r; // First species volume fraction (right). @@ -159,20 +156,25 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST } double rho_total = (alpha1 * rho1) + ((1.0 - alpha1) * rho2); // Total mixture density. - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. + double E1 = (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. + double E2 = (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. double E_total = (alpha1 * E1) + ((1.0 - alpha1) * E2); // Total mixture energy. // Set fluid mixture total mass density. fout[0] = rho_total; // Set fluid mixture total momentum density. - fout[1] = rho_total * vx_total; fout[2] = rho_total * vy_total; fout[3] = rho_total * vz_total; + fout[1] = rho_total * vx_total; + fout[2] = rho_total * vy_total; + fout[3] = rho_total * vz_total; // Set fluid mixture total energy density. fout[4] = E_total; // Set fluid mixture weighted volume fraction (first species). fout[5] = rho_total * alpha1; // Set fluid mixture volume-weighted mass densities (first and second species). - fout[6] = alpha1 * rho1; fout[7] = (1.0 - alpha1) * rho2; + fout[6] = alpha1 * rho1; + fout[7] = (1.0 - alpha1) * rho2; } int main(int argc, char **argv) @@ -205,7 +207,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler_mixture1d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_mixture_fedkiw_shock_l2.c b/moments/amr_creg/rt_amr_euler_mixture_fedkiw_shock_l2.c index 279fb11885..0ac07868de 100644 --- a/moments/amr_creg/rt_amr_euler_mixture_fedkiw_shock_l2.c +++ b/moments/amr_creg/rt_amr_euler_mixture_fedkiw_shock_l2.c @@ -2,8 +2,7 @@ #include #include -struct amr_fedkiw_shock_ctx -{ +struct amr_fedkiw_shock_ctx { // Physical constants (using normalized code units). double gas_gamma1; // First species adiabatic index. double gas_gamma2; // Second species adiabatic index. @@ -38,8 +37,7 @@ struct amr_fedkiw_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_fedkiw_shock_ctx -create_ctx(void) +struct amr_fedkiw_shock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma1 = 1.4; // First species adiabatic index. @@ -99,14 +97,15 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerMixtureInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct amr_fedkiw_shock_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -146,16 +145,14 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST vx_total = ul; // Total mixture velocity (left). p_total = pl; // Total mixture pressure (left). - } - else if (x < 0.5) { + } else if (x < 0.5) { rho1 = rhoc; // First species fluid mass density (central). rho2 = rhor; // Second species fluid mass density (right). alpha1 = alpha1_c; // First species volume fraction (central). vx_total = uc; // Total mixture velocity (central). p_total = pc; // Total mixture pressure (central). - } - else { + } else { rho1 = rhoc; // First species fluid mass density (central). rho2 = rhor; // Second species fluid mass density (right). alpha1 = alpha1_r; // First species volume fraction (right). @@ -165,20 +162,25 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST } double rho_total = (alpha1 * rho1) + ((1.0 - alpha1) * rho2); // Total mixture density. - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. + double E1 = (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. + double E2 = (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. double E_total = (alpha1 * E1) + ((1.0 - alpha1) * E2); // Total mixture energy. // Set fluid mixture total mass density. fout[0] = rho_total; // Set fluid mixture total momentum density. - fout[1] = rho_total * vx_total; fout[2] = rho_total * vy_total; fout[3] = rho_total * vz_total; + fout[1] = rho_total * vx_total; + fout[2] = rho_total * vy_total; + fout[3] = rho_total * vz_total; // Set fluid mixture total energy density. fout[4] = E_total; // Set fluid mixture weighted volume fraction (first species). fout[5] = rho_total * alpha1; // Set fluid mixture volume-weighted mass densities (first and second species). - fout[6] = alpha1 * rho1; fout[7] = (1.0 - alpha1) * rho2; + fout[6] = alpha1 * rho1; + fout[7] = (1.0 - alpha1) * rho2; } int main(int argc, char **argv) @@ -215,7 +217,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler_mixture1d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_mixture_shock_bubble_l1.c b/moments/amr_creg/rt_amr_euler_mixture_shock_bubble_l1.c index 2848e8af26..74ba1cc1bc 100644 --- a/moments/amr_creg/rt_amr_euler_mixture_shock_bubble_l1.c +++ b/moments/amr_creg/rt_amr_euler_mixture_shock_bubble_l1.c @@ -1,8 +1,7 @@ #include #include -struct amr_shock_bubble_ctx -{ +struct amr_shock_bubble_ctx { // Physical constants (using normalized code units). double gas_gamma1; // First species adiabatic index. double gas_gamma2; // Second species adiabatic index. @@ -45,8 +44,7 @@ struct amr_shock_bubble_ctx double bub_rad; // Bubble radius. }; -struct amr_shock_bubble_ctx -create_ctx(void) +struct amr_shock_bubble_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma1 = 1.4; // First species adiabatic index. @@ -119,14 +117,15 @@ create_ctx(void) .x_loc = x_loc, .bub_loc_x = bub_loc_x, .bub_loc_y = bub_loc_y, - .bub_rad = bub_rad, + .bub_rad = bub_rad }; return ctx; } -void -evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerMixtureInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct amr_shock_bubble_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -174,8 +173,7 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST vx_total = u_post; // Total mixture velocity (post-shock). p_total = p_post; // Total mixture pressure (post-shock). - } - else { + } else { rho1 = rho_pre; // First species fluid mass density (pre-shock). rho2 = rho_bub; // Second species fluid mass density (bubble). alpha1 = alpha1_pre; // First species volume fraction (pre-shock). @@ -195,20 +193,25 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST double rho_total = (alpha1 * rho1) + ((1.0 - alpha1) * rho2); // Total mixture density. - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. + double E1 = (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. + double E2 = (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. double E_total = (alpha1 * E1) + ((1.0 - alpha1) * E2); // Total mixture energy. // Set fluid mixture total mass density. fout[0] = rho_total; // Set fluid mixture total momentum density. - fout[1] = rho_total * vx_total; fout[2] = rho_total * vy_total; fout[3] = rho_total * vz_total; + fout[1] = rho_total * vx_total; + fout[2] = rho_total * vy_total; + fout[3] = rho_total * vz_total; // Set fluid mixture total energy density. fout[4] = E_total; // Set fluid mixture weighted volume fraction (first species). fout[5] = rho_total * alpha1; // Set fluid mixture volume-weighted mass densities (first and second species). - fout[6] = alpha1 * rho1; fout[7] = (1.0 - alpha1) * rho2; + fout[6] = alpha1 * rho1; + fout[7] = (1.0 - alpha1) * rho2; } int main(int argc, char **argv) @@ -252,7 +255,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler_mixture2d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_mixture_shock_bubble_l2.c b/moments/amr_creg/rt_amr_euler_mixture_shock_bubble_l2.c index 5eab22eae2..f411ee5359 100644 --- a/moments/amr_creg/rt_amr_euler_mixture_shock_bubble_l2.c +++ b/moments/amr_creg/rt_amr_euler_mixture_shock_bubble_l2.c @@ -1,8 +1,7 @@ #include #include -struct amr_shock_bubble_ctx -{ +struct amr_shock_bubble_ctx { // Physical constants (using normalized code units). double gas_gamma1; // First species adiabatic index. double gas_gamma2; // Second species adiabatic index. @@ -48,8 +47,7 @@ struct amr_shock_bubble_ctx double bub_rad; // Bubble radius. }; -struct amr_shock_bubble_ctx -create_ctx(void) +struct amr_shock_bubble_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma1 = 1.4; // First species adiabatic index. @@ -128,14 +126,15 @@ create_ctx(void) .x_loc = x_loc, .bub_loc_x = bub_loc_x, .bub_loc_y = bub_loc_y, - .bub_rad = bub_rad, + .bub_rad = bub_rad }; return ctx; } -void -evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerMixtureInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct amr_shock_bubble_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -183,8 +182,7 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST vx_total = u_post; // Total mixture velocity (post-shock). p_total = p_post; // Total mixture pressure (post-shock). - } - else { + } else { rho1 = rho_pre; // First species fluid mass density (pre-shock). rho2 = rho_bub; // Second species fluid mass density (bubble). alpha1 = alpha1_pre; // First species volume fraction (pre-shock). @@ -204,20 +202,25 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST double rho_total = (alpha1 * rho1) + ((1.0 - alpha1) * rho2); // Total mixture density. - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. + double E1 = (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. + double E2 = (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. double E_total = (alpha1 * E1) + ((1.0 - alpha1) * E2); // Total mixture energy. // Set fluid mixture total mass density. fout[0] = rho_total; // Set fluid mixture total momentum density. - fout[1] = rho_total * vx_total; fout[2] = rho_total * vy_total; fout[3] = rho_total * vz_total; + fout[1] = rho_total * vx_total; + fout[2] = rho_total * vy_total; + fout[3] = rho_total * vz_total; // Set fluid mixture total energy density. fout[4] = E_total; // Set fluid mixture weighted volume fraction (first species). fout[5] = rho_total * alpha1; // Set fluid mixture volume-weighted mass densities (first and second species). - fout[6] = alpha1 * rho1; fout[7] = (1.0 - alpha1) * rho2; + fout[6] = alpha1 * rho1; + fout[7] = (1.0 - alpha1) * rho2; } int main(int argc, char **argv) @@ -267,7 +270,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler_mixture2d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_riem_2d_l1.c b/moments/amr_creg/rt_amr_euler_riem_2d_l1.c index 0c3e232a36..09aa073f42 100644 --- a/moments/amr_creg/rt_amr_euler_riem_2d_l1.c +++ b/moments/amr_creg/rt_amr_euler_riem_2d_l1.c @@ -6,8 +6,7 @@ #include -struct amr_euler_riem_2d_ctx -{ +struct amr_euler_riem_2d_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -20,7 +19,7 @@ struct amr_euler_riem_2d_ctx double u_ur; // Upper right fluid x-velocity. double v_ur; // Upper right fluid y-velocity. double p_ur; // Upper left fluid pressure. - + double rho_ll; // Lower left fluid mass density. double u_ll; // Lower left fluid x-velocity. double v_ll; // Lower left fluid y-velocity. @@ -49,8 +48,7 @@ struct amr_euler_riem_2d_ctx double loc; // Fluid boundaries (both x and y coordinates). }; -struct amr_euler_riem_2d_ctx -create_ctx(void) +struct amr_euler_riem_2d_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -64,7 +62,7 @@ create_ctx(void) double u_ur = 0.0; // Upper-right fluid x-velocity. double v_ur = 0.0; // Upper-right fluid y-velocity. double p_ur = 1.5; // Upper-right fluid pressure. - + double rho_ll = 0.138; // Lower-left fluid mass density. double u_ll = 1.206; // Lower-left fluid x-velocity. double v_ll = 1.206; // Lower-left fluid y-velocity. @@ -122,14 +120,13 @@ create_ctx(void) .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .loc = loc, + .loc = loc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_euler_riem_2d_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -170,33 +167,32 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo u = u_ul; // Fluid x-velocity (upper-left). v = v_ul; // Fluid y-velocity (upper-left). p = p_ul; // Fluid pressure (upper-left). - } - else { + } else { rho = rho_ur; // Fluid mass density (upper-right). u = u_ur; // Fluid x-velocity (upper-right). v = v_ur; // Fluid y-velocity (upper-right). p = p_ur; // Fluid pressure (upper-right). } - } - else { + } else { if (x < loc) { rho = rho_ll; // Fluid mass density (lower-left). u = u_ll; // Fluid x-velocity (lower-left). v = v_ll; // Fluid y-velocity (lower-left). p = p_ll; // Fluid pressure (lower-left). - } - else { + } else { rho = rho_lr; // Fluid mass density (lower-right). u = u_lr; // Fluid x-velocity (lower-right). v = v_lr; // Fluid y-velocity (lower-right). p = p_lr; // Fluid pressure (lower-right). } } - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = rho * u; fout[2] = rho * v; fout[3] = 0.0; + fout[1] = rho * u; + fout[2] = rho * v; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * (u * u + v * v); } @@ -237,7 +233,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler2d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_riem_2d_l2.c b/moments/amr_creg/rt_amr_euler_riem_2d_l2.c index 66bbaa82af..04abfee112 100644 --- a/moments/amr_creg/rt_amr_euler_riem_2d_l2.c +++ b/moments/amr_creg/rt_amr_euler_riem_2d_l2.c @@ -6,8 +6,7 @@ #include -struct amr_euler_riem_2d_ctx -{ +struct amr_euler_riem_2d_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -20,7 +19,7 @@ struct amr_euler_riem_2d_ctx double u_ur; // Upper right fluid x-velocity. double v_ur; // Upper right fluid y-velocity. double p_ur; // Upper left fluid pressure. - + double rho_ll; // Lower left fluid mass density. double u_ll; // Lower left fluid x-velocity. double v_ll; // Lower left fluid y-velocity. @@ -52,8 +51,7 @@ struct amr_euler_riem_2d_ctx double loc; // Fluid boundaries (both x and y coordinates). }; -struct amr_euler_riem_2d_ctx -create_ctx(void) +struct amr_euler_riem_2d_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -67,7 +65,7 @@ create_ctx(void) double u_ur = 0.0; // Upper-right fluid x-velocity. double v_ur = 0.0; // Upper-right fluid y-velocity. double p_ur = 1.5; // Upper-right fluid pressure. - + double rho_ll = 0.138; // Lower-left fluid mass density. double u_ll = 1.206; // Lower-left fluid x-velocity. double v_ll = 1.206; // Lower-left fluid y-velocity. @@ -131,14 +129,13 @@ create_ctx(void) .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .loc = loc, + .loc = loc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_euler_riem_2d_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -179,33 +176,32 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo u = u_ul; // Fluid x-velocity (upper-left). v = v_ul; // Fluid y-velocity (upper-left). p = p_ul; // Fluid pressure (upper-left). - } - else { + } else { rho = rho_ur; // Fluid mass density (upper-right). u = u_ur; // Fluid x-velocity (upper-right). v = v_ur; // Fluid y-velocity (upper-right). p = p_ur; // Fluid pressure (upper-right). } - } - else { + } else { if (x < loc) { rho = rho_ll; // Fluid mass density (lower-left). u = u_ll; // Fluid x-velocity (lower-left). v = v_ll; // Fluid y-velocity (lower-left). p = p_ll; // Fluid pressure (lower-left). - } - else { + } else { rho = rho_lr; // Fluid mass density (lower-right). u = u_lr; // Fluid x-velocity (lower-right). v = v_lr; // Fluid y-velocity (lower-right). p = p_lr; // Fluid pressure (lower-right). } } - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = rho * u; fout[2] = rho * v; fout[3] = 0.0; + fout[1] = rho * u; + fout[2] = rho * v; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * (u * u + v * v); } @@ -252,7 +248,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler2d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_shock_bubble_l1.c b/moments/amr_creg/rt_amr_euler_shock_bubble_l1.c index fb2dbbe0df..1087b2dc87 100644 --- a/moments/amr_creg/rt_amr_euler_shock_bubble_l1.c +++ b/moments/amr_creg/rt_amr_euler_shock_bubble_l1.c @@ -1,7 +1,6 @@ #include -struct amr_euler_shock_bubble_ctx -{ +struct amr_euler_shock_bubble_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -37,8 +36,7 @@ struct amr_euler_shock_bubble_ctx double bub_rad; // Bubble radius. }; -struct amr_euler_shock_bubble_ctx -create_ctx(void) +struct amr_euler_shock_bubble_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -99,14 +97,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .x_loc = x_loc, .bub_loc = bub_loc, - .bub_rad = bub_rad, + .bub_rad = bub_rad }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_euler_shock_bubble_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -140,8 +137,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rho_post; // Fluid mass density (post-shock). u = u_post; // Fluid velocity (post-shock). p = p_post; // Fluid pressure (post-shock). - } - else { + } else { rho = rho_pre; // Fluid mass density (pre-shock). u = u_pre; // Fluid velocity (pre-shock). p = p_pre; // Fluid pressure (pre-shock). @@ -152,11 +148,13 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo u = u_bub; // Fluid velocity (bubble). p = p_bub; // Fluid pressure (bubble). } - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = rho * u; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = rho * u; + fout[2] = 0.0; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * u * u; } @@ -197,7 +195,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler2d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_shock_bubble_l2.c b/moments/amr_creg/rt_amr_euler_shock_bubble_l2.c index dd9f7571cc..707083fe5b 100644 --- a/moments/amr_creg/rt_amr_euler_shock_bubble_l2.c +++ b/moments/amr_creg/rt_amr_euler_shock_bubble_l2.c @@ -1,7 +1,6 @@ #include -struct amr_euler_shock_bubble_ctx -{ +struct amr_euler_shock_bubble_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -40,8 +39,7 @@ struct amr_euler_shock_bubble_ctx double bub_rad; // Bubble radius. }; -struct amr_euler_shock_bubble_ctx -create_ctx(void) +struct amr_euler_shock_bubble_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -108,14 +106,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .x_loc = x_loc, .bub_loc = bub_loc, - .bub_rad = bub_rad, + .bub_rad = bub_rad }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_euler_shock_bubble_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -149,8 +146,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rho_post; // Fluid mass density (post-shock). u = u_post; // Fluid velocity (post-shock). p = p_post; // Fluid pressure (post-shock). - } - else { + } else { rho = rho_pre; // Fluid mass density (pre-shock). u = u_pre; // Fluid velocity (pre-shock). p = p_pre; // Fluid pressure (pre-shock). @@ -161,11 +157,13 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo u = u_bub; // Fluid velocity (bubble). p = p_bub; // Fluid pressure (bubble). } - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = rho * u; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = rho * u; + fout[2] = 0.0; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * u * u; } @@ -212,7 +210,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler2d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_sodshock_l1.c b/moments/amr_creg/rt_amr_euler_sodshock_l1.c index 12a6afcb79..017af52e1d 100644 --- a/moments/amr_creg/rt_amr_euler_sodshock_l1.c +++ b/moments/amr_creg/rt_amr_euler_sodshock_l1.c @@ -6,8 +6,7 @@ #include -struct amr_euler_sodshock_ctx -{ +struct amr_euler_sodshock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -32,8 +31,7 @@ struct amr_euler_sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_euler_sodshock_ctx -create_ctx(void) +struct amr_euler_sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -74,14 +72,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_euler_sodshock_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -105,17 +102,18 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = rho * u; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = rho * u; + fout[2] = 0.0; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * u * u; } @@ -145,7 +143,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler1d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_euler_sodshock_l2.c b/moments/amr_creg/rt_amr_euler_sodshock_l2.c index ca8e07ca4b..c56d8abdde 100644 --- a/moments/amr_creg/rt_amr_euler_sodshock_l2.c +++ b/moments/amr_creg/rt_amr_euler_sodshock_l2.c @@ -6,8 +6,7 @@ #include -struct amr_euler_sodshock_ctx -{ +struct amr_euler_sodshock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -34,8 +33,7 @@ struct amr_euler_sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_euler_sodshock_ctx -create_ctx(void) +struct amr_euler_sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -80,14 +78,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_euler_sodshock_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -111,17 +108,18 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = rho * u; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = rho * u; + fout[2] = 0.0; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * u * u; } @@ -155,7 +153,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; euler1d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_bhl_spinning_l1.c b/moments/amr_creg/rt_amr_gr_bhl_spinning_l1.c index ce6325361f..74ce6323ad 100644 --- a/moments/amr_creg/rt_amr_gr_bhl_spinning_l1.c +++ b/moments/amr_creg/rt_amr_gr_bhl_spinning_l1.c @@ -9,8 +9,7 @@ #include #include -struct amr_gr_bhl_spinning_ctx -{ +struct amr_gr_bhl_spinning_ctx { // Mathematical constants (dimensionless). double pi; @@ -54,8 +53,7 @@ struct amr_gr_bhl_spinning_ctx double x_loc; // Shock location (x-direction). }; -struct amr_gr_bhl_spinning_ctx -create_ctx(void) +struct amr_gr_bhl_spinning_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -80,7 +78,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 32; // Coarse cell count (x-direction). @@ -126,14 +125,13 @@ create_ctx(void) .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_gr_bhl_spinning_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -164,23 +162,22 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -189,13 +186,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -209,7 +208,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + // Set fluid mass density. fout[0] = sqrt(spatial_det) * rho * W; // Set fluid momentum density. @@ -224,17 +223,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -243,8 +256,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -296,7 +308,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler2d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_bhl_spinning_l2.c b/moments/amr_creg/rt_amr_gr_bhl_spinning_l2.c index 1e8cf42dda..95b0f0327a 100644 --- a/moments/amr_creg/rt_amr_gr_bhl_spinning_l2.c +++ b/moments/amr_creg/rt_amr_gr_bhl_spinning_l2.c @@ -9,8 +9,7 @@ #include #include -struct amr_gr_bhl_spinning_ctx -{ +struct amr_gr_bhl_spinning_ctx { // Mathematical constants (dimensionless). double pi; @@ -57,8 +56,7 @@ struct amr_gr_bhl_spinning_ctx double x_loc; // Shock location (x-direction). }; -struct amr_gr_bhl_spinning_ctx -create_ctx(void) +struct amr_gr_bhl_spinning_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -83,7 +81,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 8; // Coarse cell count (x-direction). @@ -135,14 +134,13 @@ create_ctx(void) .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_gr_bhl_spinning_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -173,23 +171,22 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -198,13 +195,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -218,7 +217,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + // Set fluid mass density. fout[0] = sqrt(spatial_det) * rho * W; // Set fluid momentum density. @@ -233,17 +232,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -252,8 +265,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -311,7 +323,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler2d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_bhl_static_l1.c b/moments/amr_creg/rt_amr_gr_bhl_static_l1.c index e33837de59..ef94b1dd90 100644 --- a/moments/amr_creg/rt_amr_gr_bhl_static_l1.c +++ b/moments/amr_creg/rt_amr_gr_bhl_static_l1.c @@ -9,8 +9,7 @@ #include #include -struct amr_gr_bhl_static_ctx -{ +struct amr_gr_bhl_static_ctx { // Mathematical constants (dimensionless). double pi; @@ -54,8 +53,7 @@ struct amr_gr_bhl_static_ctx double x_loc; // Shock location (x-direction). }; -struct amr_gr_bhl_static_ctx -create_ctx(void) +struct amr_gr_bhl_static_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -80,7 +78,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 32; // Coarse cell count (x-direction). @@ -91,7 +90,7 @@ create_ctx(void) double fine_Lx = 2.5; // Fine domain size (x-direction). double fine_Ly = 2.5; // Fine domain size (y-direction). double cfl_frac = 0.95; // CFL coefficient. - + double t_end = 15.0; // Final simulation time. int num_frames = 1; // Number of output frames. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. @@ -126,14 +125,13 @@ create_ctx(void) .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_gr_bhl_static_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -164,23 +162,22 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -189,13 +186,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -209,7 +208,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + // Set fluid mass density. fout[0] = sqrt(spatial_det) * rho * W; // Set fluid momentum density. @@ -224,17 +223,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -243,8 +256,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -296,7 +308,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler2d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_bhl_static_l2.c b/moments/amr_creg/rt_amr_gr_bhl_static_l2.c index 4f577f577f..8946c1b561 100644 --- a/moments/amr_creg/rt_amr_gr_bhl_static_l2.c +++ b/moments/amr_creg/rt_amr_gr_bhl_static_l2.c @@ -9,8 +9,7 @@ #include #include -struct amr_gr_bhl_static_ctx -{ +struct amr_gr_bhl_static_ctx { // Mathematical constants (dimensionless). double pi; @@ -57,8 +56,7 @@ struct amr_gr_bhl_static_ctx double x_loc; // Shock location (x-direction). }; -struct amr_gr_bhl_static_ctx -create_ctx(void) +struct amr_gr_bhl_static_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -83,7 +81,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 8; // Coarse cell count (x-direction). @@ -97,7 +96,7 @@ create_ctx(void) double fine_Lx = 2.5; // Fine domain size (x-direction). double fine_Ly = 2.0; // Fine domain size (y-direction). double cfl_frac = 0.95; // CFL coefficient. - + double t_end = 15.0; // Final simulation time. int num_frames = 1; // Number of output frames. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. @@ -135,14 +134,13 @@ create_ctx(void) .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_gr_bhl_static_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -173,23 +171,22 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -198,13 +195,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -218,7 +217,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + // Set fluid mass density. fout[0] = sqrt(spatial_det) * rho * W; // Set fluid momentum density. @@ -233,17 +232,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -252,8 +265,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -311,7 +323,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler2d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_blackhole_spinning_l1.c b/moments/amr_creg/rt_amr_gr_blackhole_spinning_l1.c index dc3386565e..281bb084f3 100644 --- a/moments/amr_creg/rt_amr_gr_blackhole_spinning_l1.c +++ b/moments/amr_creg/rt_amr_gr_blackhole_spinning_l1.c @@ -5,8 +5,7 @@ #include #include -struct amr_gr_blackhole_spinning_ctx -{ +struct amr_gr_blackhole_spinning_ctx { // Mathematical constants (dimensionless). double pi; @@ -55,8 +54,7 @@ struct amr_gr_blackhole_spinning_ctx double r_outer; // Ring outer radius. }; -struct amr_gr_blackhole_spinning_ctx -create_ctx(void) +struct amr_gr_blackhole_spinning_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -85,7 +83,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 32; // Coarse cell count (x-direction). @@ -136,17 +135,17 @@ create_ctx(void) .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, .r_inner = r_inner, - .r_outer = r_outer, + .r_outer = r_outer }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; - struct amr_gr_blackhole_spinning_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_blackhole_spinning_ctx new_ctx = + create_ctx(); // Context for initialization functions. struct amr_gr_blackhole_spinning_ctx *app = &new_ctx; double gas_gamma = app->gas_gamma; @@ -182,29 +181,27 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left ring). u = ul; // Fluid velocity (left ring). p = pl; // Fluid pressure (left ring). - } - else { + } else { rho = rhor; // Fluid mass density (right ring). u = ur; // Fluid velocity (right ring). p = pr; // Fluid pressure (right ring). } - } - else { + } else { rho = rhob; // Fluid mass density (background). u = ub; // Fluid velocity (background). p = pb; // Fluid pressure (background). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -213,13 +210,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -233,7 +232,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + // Set fluid mass density. fout[0] = sqrt(spatial_det) * rho * W; // Set fluid momentum density. @@ -248,17 +247,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -267,8 +280,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -320,7 +332,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler2d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_blackhole_spinning_l2.c b/moments/amr_creg/rt_amr_gr_blackhole_spinning_l2.c index f007845921..5f70ea3356 100644 --- a/moments/amr_creg/rt_amr_gr_blackhole_spinning_l2.c +++ b/moments/amr_creg/rt_amr_gr_blackhole_spinning_l2.c @@ -5,8 +5,7 @@ #include #include -struct amr_gr_blackhole_spinning_ctx -{ +struct amr_gr_blackhole_spinning_ctx { // Mathematical constants (dimensionless). double pi; @@ -58,8 +57,7 @@ struct amr_gr_blackhole_spinning_ctx double r_outer; // Ring outer radius. }; -struct amr_gr_blackhole_spinning_ctx -create_ctx(void) +struct amr_gr_blackhole_spinning_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -88,7 +86,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 8; // Coarse cell count (x-direction). @@ -145,17 +144,17 @@ create_ctx(void) .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, .r_inner = r_inner, - .r_outer = r_outer, + .r_outer = r_outer }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; - struct amr_gr_blackhole_spinning_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_blackhole_spinning_ctx new_ctx = + create_ctx(); // Context for initialization functions. struct amr_gr_blackhole_spinning_ctx *app = &new_ctx; double gas_gamma = app->gas_gamma; @@ -191,29 +190,27 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left ring). u = ul; // Fluid velocity (left ring). p = pl; // Fluid pressure (left ring). - } - else { + } else { rho = rhor; // Fluid mass density (right ring). u = ur; // Fluid velocity (right ring). p = pr; // Fluid pressure (right ring). } - } - else { + } else { rho = rhob; // Fluid mass density (background). u = ub; // Fluid velocity (background). p = pb; // Fluid pressure (background). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -222,13 +219,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -242,7 +241,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + // Set fluid mass density. fout[0] = sqrt(spatial_det) * rho * W; // Set fluid momentum density. @@ -257,17 +256,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -276,8 +289,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -335,7 +347,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler2d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_blackhole_static_l1.c b/moments/amr_creg/rt_amr_gr_blackhole_static_l1.c index 032dc1dbb4..137dd854ac 100644 --- a/moments/amr_creg/rt_amr_gr_blackhole_static_l1.c +++ b/moments/amr_creg/rt_amr_gr_blackhole_static_l1.c @@ -5,8 +5,7 @@ #include #include -struct amr_gr_blackhole_static_ctx -{ +struct amr_gr_blackhole_static_ctx { // Mathematical constants (dimensionless). double pi; @@ -55,8 +54,7 @@ struct amr_gr_blackhole_static_ctx double r_outer; // Ring outer radius. }; -struct amr_gr_blackhole_static_ctx -create_ctx(void) +struct amr_gr_blackhole_static_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -85,7 +83,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 32; // Coarse cell count (x-direction). @@ -136,17 +135,17 @@ create_ctx(void) .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, .r_inner = r_inner, - .r_outer = r_outer, + .r_outer = r_outer }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; - struct amr_gr_blackhole_static_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_blackhole_static_ctx new_ctx = + create_ctx(); // Context for initialization functions. struct amr_gr_blackhole_static_ctx *app = &new_ctx; double gas_gamma = app->gas_gamma; @@ -182,29 +181,27 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left ring). u = ul; // Fluid velocity (left ring). p = pl; // Fluid pressure (left ring). - } - else { + } else { rho = rhor; // Fluid mass density (right ring). u = ur; // Fluid velocity (right ring). p = pr; // Fluid pressure (right ring). } - } - else { + } else { rho = rhob; // Fluid mass density (background). u = ub; // Fluid velocity (background). p = pb; // Fluid pressure (background). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -213,13 +210,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -233,7 +232,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + // Set fluid mass density. fout[0] = sqrt(spatial_det) * rho * W; // Set fluid momentum density. @@ -248,17 +247,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -267,8 +280,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -320,7 +332,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler2d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_blackhole_static_l2.c b/moments/amr_creg/rt_amr_gr_blackhole_static_l2.c index 42d2281e9e..681974348a 100644 --- a/moments/amr_creg/rt_amr_gr_blackhole_static_l2.c +++ b/moments/amr_creg/rt_amr_gr_blackhole_static_l2.c @@ -5,8 +5,7 @@ #include #include -struct amr_gr_blackhole_static_ctx -{ +struct amr_gr_blackhole_static_ctx { // Mathematical constants (dimensionless). double pi; @@ -58,8 +57,7 @@ struct amr_gr_blackhole_static_ctx double r_outer; // Ring outer radius. }; -struct amr_gr_blackhole_static_ctx -create_ctx(void) +struct amr_gr_blackhole_static_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -88,7 +86,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 8; // Coarse cell count (x-direction). @@ -145,17 +144,17 @@ create_ctx(void) .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, .r_inner = r_inner, - .r_outer = r_outer, + .r_outer = r_outer }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; - struct amr_gr_blackhole_static_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_blackhole_static_ctx new_ctx = + create_ctx(); // Context for initialization functions. struct amr_gr_blackhole_static_ctx *app = &new_ctx; double gas_gamma = app->gas_gamma; @@ -191,29 +190,27 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left ring). u = ul; // Fluid velocity (left ring). p = pl; // Fluid pressure (left ring). - } - else { + } else { rho = rhor; // Fluid mass density (right ring). u = ur; // Fluid velocity (right ring). p = pr; // Fluid pressure (right ring). } - } - else { + } else { rho = rhob; // Fluid mass density (background). u = ub; // Fluid velocity (background). p = pb; // Fluid pressure (background). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -222,13 +219,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -242,7 +241,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + // Set fluid mass density. fout[0] = sqrt(spatial_det) * rho * W; // Set fluid momentum density. @@ -257,17 +256,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -276,8 +289,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -335,7 +347,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler2d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_mild_shock_l1.c b/moments/amr_creg/rt_amr_gr_mild_shock_l1.c index ad84b3eb37..47f3aa4acd 100644 --- a/moments/amr_creg/rt_amr_gr_mild_shock_l1.c +++ b/moments/amr_creg/rt_amr_gr_mild_shock_l1.c @@ -8,8 +8,7 @@ #include #include -struct amr_gr_mild_shock_ctx -{ +struct amr_gr_mild_shock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -37,8 +36,7 @@ struct amr_gr_mild_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_gr_mild_shock_ctx -create_ctx(void) +struct amr_gr_mild_shock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -83,14 +81,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_gr_mild_shock_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -116,8 +113,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -127,12 +123,12 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -141,13 +137,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -176,17 +174,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -195,8 +207,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -237,7 +248,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler1d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_mild_shock_l2.c b/moments/amr_creg/rt_amr_gr_mild_shock_l2.c index 7adc9b1e1d..4abf6ae0f7 100644 --- a/moments/amr_creg/rt_amr_gr_mild_shock_l2.c +++ b/moments/amr_creg/rt_amr_gr_mild_shock_l2.c @@ -8,8 +8,7 @@ #include #include -struct amr_gr_mild_shock_ctx -{ +struct amr_gr_mild_shock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -39,8 +38,7 @@ struct amr_gr_mild_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_gr_mild_shock_ctx -create_ctx(void) +struct amr_gr_mild_shock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -89,14 +87,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_gr_mild_shock_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -122,8 +119,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -133,12 +129,12 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -147,13 +143,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -182,17 +180,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -201,8 +213,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -247,7 +258,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler1d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_perturbed_density_l1.c b/moments/amr_creg/rt_amr_gr_perturbed_density_l1.c index 10166865fb..52f543af08 100644 --- a/moments/amr_creg/rt_amr_gr_perturbed_density_l1.c +++ b/moments/amr_creg/rt_amr_gr_perturbed_density_l1.c @@ -8,8 +8,7 @@ #include #include -struct amr_gr_perturbed_density_ctx -{ +struct amr_gr_perturbed_density_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -37,8 +36,7 @@ struct amr_gr_perturbed_density_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_gr_perturbed_density_ctx -create_ctx(void) +struct amr_gr_perturbed_density_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -83,17 +81,17 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; - struct amr_gr_perturbed_density_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_perturbed_density_ctx new_ctx = + create_ctx(); // Context for initialization functions. struct amr_gr_perturbed_density_ctx *app = &new_ctx; double gas_gamma = app->gas_gamma; @@ -116,8 +114,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor + 0.3 * sin(50.0 * x); // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -127,12 +124,12 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -141,13 +138,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -176,17 +175,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -195,8 +208,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -237,7 +249,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler1d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_perturbed_density_l2.c b/moments/amr_creg/rt_amr_gr_perturbed_density_l2.c index 74b78a5562..0677750dd7 100644 --- a/moments/amr_creg/rt_amr_gr_perturbed_density_l2.c +++ b/moments/amr_creg/rt_amr_gr_perturbed_density_l2.c @@ -8,8 +8,7 @@ #include #include -struct amr_gr_perturbed_density_ctx -{ +struct amr_gr_perturbed_density_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -39,8 +38,7 @@ struct amr_gr_perturbed_density_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_gr_perturbed_density_ctx -create_ctx(void) +struct amr_gr_perturbed_density_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -89,17 +87,17 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; - struct amr_gr_perturbed_density_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_perturbed_density_ctx new_ctx = + create_ctx(); // Context for initialization functions. struct amr_gr_perturbed_density_ctx *app = &new_ctx; double gas_gamma = app->gas_gamma; @@ -122,8 +120,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor + 0.3 * sin(50.0 * x); // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -133,12 +130,12 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -147,13 +144,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -182,17 +181,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -201,8 +214,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -247,7 +259,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler1d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_quadrants_2d_l1.c b/moments/amr_creg/rt_amr_gr_quadrants_2d_l1.c index 0ee0800ec2..6bcce30066 100644 --- a/moments/amr_creg/rt_amr_gr_quadrants_2d_l1.c +++ b/moments/amr_creg/rt_amr_gr_quadrants_2d_l1.c @@ -8,8 +8,7 @@ #include #include -struct amr_gr_quadrants_2d_ctx -{ +struct amr_gr_quadrants_2d_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -22,7 +21,7 @@ struct amr_gr_quadrants_2d_ctx double u_ur; // Upper right fluid x-velocity. double v_ur; // Upper right fluid y-velocity. double p_ur; // Upper left fluid pressure. - + double rho_ll; // Lower left fluid mass density. double u_ll; // Lower left fluid x-velocity. double v_ll; // Lower left fluid y-velocity. @@ -54,8 +53,7 @@ struct amr_gr_quadrants_2d_ctx double loc; // Fluid boundaries (both x and y coordinates). }; -struct amr_gr_quadrants_2d_ctx -create_ctx(void) +struct amr_gr_quadrants_2d_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -69,7 +67,7 @@ create_ctx(void) double u_ur = 0.0; // Upper-right fluid x-velocity. double v_ur = 0.0; // Upper-right fluid y-velocity. double p_ur = 0.01; // Upper-right fluid pressure. - + double rho_ll = 0.5; // Lower-left fluid mass density. double u_ll = 0.0; // Lower-left fluid x-velocity. double v_ll = 0.0; // Lower-left fluid y-velocity. @@ -131,14 +129,13 @@ create_ctx(void) .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .loc = loc, + .loc = loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_gr_quadrants_2d_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -181,22 +178,19 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT u = u_ul; // Fluid x-velocity (upper-left). v = v_ul; // Fluid y-velocity (upper-left). p = p_ul; // Fluid pressure (upper-left). - } - else { + } else { rho = rho_ur; // Fluid mass density (upper-right). u = u_ur; // Fluid x-velocity (upper-right). v = v_ur; // Fluid y-velocity (upper-right). p = p_ur; // Fluid pressure (upper-right). } - } - else { + } else { if (x < loc) { rho = rho_ll; // Fluid mass density (lower-left). u = u_ll; // Fluid x-velocity (lower-left). v = v_ll; // Fluid y-velocity (lower-left). p = p_ll; // Fluid pressure (lower-left). - } - else { + } else { rho = rho_lr; // Fluid mass density (lower-right). u = u_lr; // Fluid x-velocity (lower-right). v = v_lr; // Fluid y-velocity (lower-right). @@ -208,12 +202,12 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -222,13 +216,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = v; vel[2] = 0.0; + vel[0] = u; + vel[1] = v; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -242,7 +238,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + // Set fluid mass density. fout[0] = sqrt(spatial_det) * rho * W; // Set fluid momentum density. @@ -257,17 +253,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -276,8 +286,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -329,7 +338,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler2d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_quadrants_2d_l2.c b/moments/amr_creg/rt_amr_gr_quadrants_2d_l2.c index 4a1b1bf69e..d8ef3e4545 100644 --- a/moments/amr_creg/rt_amr_gr_quadrants_2d_l2.c +++ b/moments/amr_creg/rt_amr_gr_quadrants_2d_l2.c @@ -8,8 +8,7 @@ #include #include -struct amr_gr_quadrants_2d_ctx -{ +struct amr_gr_quadrants_2d_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -22,7 +21,7 @@ struct amr_gr_quadrants_2d_ctx double u_ur; // Upper right fluid x-velocity. double v_ur; // Upper right fluid y-velocity. double p_ur; // Upper left fluid pressure. - + double rho_ll; // Lower left fluid mass density. double u_ll; // Lower left fluid x-velocity. double v_ll; // Lower left fluid y-velocity. @@ -57,8 +56,7 @@ struct amr_gr_quadrants_2d_ctx double loc; // Fluid boundaries (both x and y coordinates). }; -struct amr_gr_quadrants_2d_ctx -create_ctx(void) +struct amr_gr_quadrants_2d_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -72,7 +70,7 @@ create_ctx(void) double u_ur = 0.0; // Upper-right fluid x-velocity. double v_ur = 0.0; // Upper-right fluid y-velocity. double p_ur = 0.01; // Upper-right fluid pressure. - + double rho_ll = 0.5; // Lower-left fluid mass density. double u_ll = 0.0; // Lower-left fluid x-velocity. double v_ll = 0.0; // Lower-left fluid y-velocity. @@ -139,14 +137,13 @@ create_ctx(void) .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .loc = loc, + .loc = loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct amr_gr_quadrants_2d_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -189,22 +186,19 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT u = u_ul; // Fluid x-velocity (upper-left). v = v_ul; // Fluid y-velocity (upper-left). p = p_ul; // Fluid pressure (upper-left). - } - else { + } else { rho = rho_ur; // Fluid mass density (upper-right). u = u_ur; // Fluid x-velocity (upper-right). v = v_ur; // Fluid y-velocity (upper-right). p = p_ur; // Fluid pressure (upper-right). } - } - else { + } else { if (x < loc) { rho = rho_ll; // Fluid mass density (lower-left). u = u_ll; // Fluid x-velocity (lower-left). v = v_ll; // Fluid y-velocity (lower-left). p = p_ll; // Fluid pressure (lower-left). - } - else { + } else { rho = rho_lr; // Fluid mass density (lower-right). u = u_lr; // Fluid x-velocity (lower-right). v = v_lr; // Fluid y-velocity (lower-right). @@ -216,12 +210,12 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -230,13 +224,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = v; vel[2] = 0.0; + vel[0] = u; + vel[1] = v; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -250,7 +246,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + // Set fluid mass density. fout[0] = sqrt(spatial_det) * rho * W; // Set fluid momentum density. @@ -265,17 +261,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -284,8 +294,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -343,7 +352,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler2d_run_double(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_strong_blast_l1.c b/moments/amr_creg/rt_amr_gr_strong_blast_l1.c index 5c31f18cd3..c9f976d211 100644 --- a/moments/amr_creg/rt_amr_gr_strong_blast_l1.c +++ b/moments/amr_creg/rt_amr_gr_strong_blast_l1.c @@ -8,8 +8,7 @@ #include #include -struct amr_gr_strong_blast_ctx -{ +struct amr_gr_strong_blast_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -37,8 +36,7 @@ struct amr_gr_strong_blast_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_gr_strong_blast_ctx -create_ctx(void) +struct amr_gr_strong_blast_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -83,14 +81,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_gr_strong_blast_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -116,8 +113,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -127,12 +123,12 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -141,13 +137,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -176,17 +174,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -195,8 +207,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -237,7 +248,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler1d_run_single(argc, argv, &init); diff --git a/moments/amr_creg/rt_amr_gr_strong_blast_l2.c b/moments/amr_creg/rt_amr_gr_strong_blast_l2.c index 301ccab925..567a649196 100644 --- a/moments/amr_creg/rt_amr_gr_strong_blast_l2.c +++ b/moments/amr_creg/rt_amr_gr_strong_blast_l2.c @@ -8,8 +8,7 @@ #include #include -struct amr_gr_strong_blast_ctx -{ +struct amr_gr_strong_blast_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -39,8 +38,7 @@ struct amr_gr_strong_blast_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct amr_gr_strong_blast_ctx -create_ctx(void) +struct amr_gr_strong_blast_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -89,14 +87,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct amr_gr_strong_blast_ctx new_ctx = create_ctx(); // Context for initialization functions. @@ -122,8 +119,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -133,12 +129,12 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -147,13 +143,15 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &inv_spatial_metric); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -182,17 +180,31 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set lapse gauge variable. fout[6] = lapse; // Set shift gauge variables. - fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + fout[7] = shift[0]; + fout[8] = shift[1]; + fout[9] = shift[2]; // Set spatial metric tensor. - fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; - fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; - fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + fout[10] = spatial_metric[0][0]; + fout[11] = spatial_metric[0][1]; + fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; + fout[14] = spatial_metric[1][1]; + fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; + fout[17] = spatial_metric[2][1]; + fout[18] = spatial_metric[2][2]; // Set inverse spatial metric tensor. - fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; - fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; - fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + fout[19] = inv_spatial_metric[0][0]; + fout[20] = inv_spatial_metric[0][1]; + fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; + fout[23] = inv_spatial_metric[1][1]; + fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; + fout[26] = inv_spatial_metric[2][1]; + fout[27] = inv_spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { @@ -201,8 +213,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } fout[28] = -1.0; - } - else { + } else { fout[28] = 1.0; } @@ -247,7 +258,7 @@ int main(int argc, char **argv) .t_end = ctx.t_end, .num_frames = ctx.num_frames, .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, + .num_failures_max = ctx.num_failures_max }; gr_euler1d_run_double(argc, argv, &init); diff --git a/moments/apps/gkyl_moment.h b/moments/apps/gkyl_moment.h index e77cab7f71..fa8add35d5 100644 --- a/moments/apps/gkyl_moment.h +++ b/moments/apps/gkyl_moment.h @@ -17,7 +17,7 @@ struct gkyl_moment_species { char name[128]; // species name double charge, mass; // charge and mass - + bool is_static; // set to true if moment species does not change in time struct gkyl_wv_eqn *equation; // equation object @@ -35,7 +35,8 @@ struct gkyl_moment_species { bool has_volume_sources; // Run with volume-based geometrical sources. double volume_gas_gamma; // Adiabatic index for volume-based geometrical sources. double volume_U0; // Initial comoving plasma velocity for volume-based geometrical sources. - double volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. + double + volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. bool has_reactivity; // Run with reactive sources. double reactivity_gas_gamma; // Adiabatic index for reactive sources. @@ -45,35 +46,52 @@ struct gkyl_moment_species { double reactivity_reaction_rate; // Reaction rate for reactive sources. bool has_einstein_medium; // Run with coupled fluid-Einstein sources in plane-symmetric spacetimes. - double medium_gas_gamma; // Adiabatic index for coupled fluid-Einstein sources in plane-symmetric spacetimes. - double medium_kappa; // Stress-energy prefactor for coupled fluid-Einstein sources in plane-symmetric spacetimes. + double + medium_gas_gamma; // Adiabatic index for coupled fluid-Einstein sources in plane-symmetric spacetimes. + double + medium_kappa; // Stress-energy prefactor for coupled fluid-Einstein sources in plane-symmetric spacetimes. - bool has_gr_ultra_rel; // Run with general relativistic source terms (Euler equations, ultra-relativistic equation of state). - double gr_ultra_rel_gas_gamma; // Adiabatic index for general relativistic Euler equations (ultra-relativistic equation of state). + bool + has_gr_ultra_rel; // Run with general relativistic source terms (Euler equations, ultra-relativistic equation of state). + double + gr_ultra_rel_gas_gamma; // Adiabatic index for general relativistic Euler equations (ultra-relativistic equation of state). - bool has_gr_euler; // Run with general relativistic source terms (Euler equations, ideal gas equation of state). - double gr_euler_gas_gamma; // Adiabatic index for general relativistic Euler equations (ideal gas equation of state). + bool + has_gr_euler; // Run with general relativistic source terms (Euler equations, ideal gas equation of state). + double + gr_euler_gas_gamma; // Adiabatic index for general relativistic Euler equations (ideal gas equation of state). bool has_gr_twofluid; // Run with general relativistic two-fluid source terms. double gr_twofluid_mass_elc; // Electron mass for general relativistic two-fluid equations. double gr_twofluid_mass_ion; // Ion mass for general relativistic two-fluid equations. double gr_twofluid_charge_elc; // Electron charge for general relativistic two-fluid equations. double gr_twofluid_charge_ion; // Ion charge for general relativistic two-fluid equations. - double gr_twofluid_gas_gamma_elc; // Adiabatic index for electrons in general relativistic two-fluid equations. - double gr_twofluid_gas_gamma_ion; // Adiabatic index for ions in general relativistic two-fluid equations. - double gr_twofluid_e_fact; // Electric field divergence error propagation speed for general relativistic two-fluid equations. + double + gr_twofluid_gas_gamma_elc; // Adiabatic index for electrons in general relativistic two-fluid equations. + double + gr_twofluid_gas_gamma_ion; // Adiabatic index for ions in general relativistic two-fluid equations. + double + gr_twofluid_e_fact; // Electric field divergence error propagation speed for general relativistic two-fluid equations. bool has_vacuum_einstein; // Run with vacuum Einstein sources using the Bona-Masso formalism. - double vacuum_einstein_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the Bona-Masso formalism. - enum gkyl_spacetime_slicing vacuum_einstein_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the Bona-Masso formalism. - enum gkyl_spacetime_evolution vacuum_einstein_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the Bona-Masso formalism. - - bool has_vacuum_einstein_conformal; // Run with vacuum Einstein sources using the conformal Bona-Masso formalism. - double vacuum_einstein_conformal_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the conformal Bona-Masso formalism. - enum gkyl_spacetime_slicing vacuum_einstein_conformal_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the conformal Bona-Masso formalism. - enum gkyl_spacetime_evolution vacuum_einstein_conformal_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the conformal Bona-Masso formalism. - - bool has_gr_mhd; // Run with general relativistic source terms (general relativistic magnetohydrodynamics equations). + double + vacuum_einstein_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the Bona-Masso formalism. + enum gkyl_spacetime_slicing + vacuum_einstein_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the Bona-Masso formalism. + enum gkyl_spacetime_evolution + vacuum_einstein_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the Bona-Masso formalism. + + bool + has_vacuum_einstein_conformal; // Run with vacuum Einstein sources using the conformal Bona-Masso formalism. + double + vacuum_einstein_conformal_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the conformal Bona-Masso formalism. + enum gkyl_spacetime_slicing + vacuum_einstein_conformal_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the conformal Bona-Masso formalism. + enum gkyl_spacetime_evolution + vacuum_einstein_conformal_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the conformal Bona-Masso formalism. + + bool + has_gr_mhd; // Run with general relativistic source terms (general relativistic magnetohydrodynamics equations). double gr_mhd_gas_gamma; // Adiabatic index for general relativistic magnetohydrodynamics equations. bool force_low_order_flux; // should we force low-order flux? @@ -95,7 +113,7 @@ struct gkyl_moment_species { // boundary conditions enum gkyl_species_bc_type bcx[2], bcy[2], bcz[2]; // for function BCs these should be set - wv_bc_func_t bcx_func[2], bcy_func[2], bcz_func[2]; + wv_bc_func_t bcx_func[2], bcy_func[2], bcz_func[2]; }; // Parameter for EM field @@ -118,7 +136,7 @@ struct gkyl_moment_field { double t_ramp_E; // linear ramp for turning on external E field struct gkyl_wv_embed_geo *embed_geo; - + void *app_current_ctx; // context for external electromagnetic fields function // pointer to external electromagnetic fields function void (*app_current)(double t, const double *xn, double *app_current_out, void *ctx); @@ -130,7 +148,8 @@ struct gkyl_moment_field { bool has_volume_sources; // Run with volume-based geometrical sources. double volume_gas_gamma; // Adiabatic index for volume-based geometrical sources. double volume_U0; // Initial comoving plasma velocity for volume-based geometrical sources. - double volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. + double + volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. // boundary conditions enum gkyl_field_bc_type bcx[2], bcy[2], bcz[2]; @@ -165,7 +184,7 @@ struct gkyl_moment { double cfl_frac; // CFL fraction to use enum gkyl_moment_scheme scheme_type; // scheme to update fluid and moment eqns - + enum gkyl_mp_recon mp_recon; // reconstruction scheme to use bool skip_mp_limiter; // should MP limiter be skipped? bool use_hybrid_flux_kep; // should shock-hybrid scheme be used when using KEP? @@ -188,7 +207,7 @@ struct gkyl_moment { bool has_nT_sources; bool has_braginskii; // has Braginskii transport - double coll_fac; // multiplicative collisionality factor for Braginskii + double coll_fac; // multiplicative collisionality factor for Braginskii struct gkyl_app_parallelism_inp parallelism; // Parallelism-related inputs. }; @@ -197,7 +216,7 @@ struct gkyl_moment { struct gkyl_moment_stat { long nup; // calls to update double total_tm; // time for simulation (not including ICs) - + long nfail; // number of failed time-steps //// wave_prop stuff @@ -207,13 +226,13 @@ struct gkyl_moment_stat { //// stuff for MP-XX/SSP-RK schemes long nfeuler; // calls to forward-Euler method - + long nstage_2_fail; // number of failed RK stage-2s long nstage_3_fail; // number of failed RK stage-3s double stage_2_dt_diff[2]; // [min,max] rel-diff for stage-2 failure double stage_3_dt_diff[2]; // [min,max] rel-diff for stage-3 failure - + double init_species_tm; // time to initialize all species double init_field_tm; // time to initialize fields @@ -233,7 +252,7 @@ typedef struct gkyl_moment_app gkyl_moment_app; * @param vm App inputs. See struct docs. * @return New moment app object. */ -gkyl_moment_app* gkyl_moment_app_new(struct gkyl_moment *mom); +gkyl_moment_app *gkyl_moment_app_new(struct gkyl_moment *mom); /** * Compute maximum estimated stable dt wtih current app state. Call @@ -242,7 +261,7 @@ gkyl_moment_app* gkyl_moment_app_new(struct gkyl_moment *mom); * @param app App object. * @retuen maximum estimated stable dt */ -double gkyl_moment_app_max_dt(gkyl_moment_app* app); +double gkyl_moment_app_max_dt(gkyl_moment_app *app); /** * Initialize species and field. @@ -250,7 +269,7 @@ double gkyl_moment_app_max_dt(gkyl_moment_app* app); * @param app App object. * @param t0 Time for initial conditions. */ -void gkyl_moment_app_apply_ic(gkyl_moment_app* app, double t0); +void gkyl_moment_app_apply_ic(gkyl_moment_app *app, double t0); /** * Initialize field. @@ -258,7 +277,7 @@ void gkyl_moment_app_apply_ic(gkyl_moment_app* app, double t0); * @param app App object. * @param t0 Time for initial conditions */ -void gkyl_moment_app_apply_ic_field(gkyl_moment_app* app, double t0); +void gkyl_moment_app_apply_ic_field(gkyl_moment_app *app, double t0); /** * Initialize species. @@ -267,7 +286,7 @@ void gkyl_moment_app_apply_ic_field(gkyl_moment_app* app, double t0); * @param sidx Index of species to initialize. * @param t0 Time for initial conditions */ -void gkyl_moment_app_apply_ic_species(gkyl_moment_app* app, int sidx, double t0); +void gkyl_moment_app_apply_ic_species(gkyl_moment_app *app, int sidx, double t0); /** * Initialize embedded geometry. @@ -275,7 +294,7 @@ void gkyl_moment_app_apply_ic_species(gkyl_moment_app* app, int sidx, double t0) * @param app App object. * @param t0 Time for initial conditions */ -void gkyl_moment_app_apply_ic_embed(gkyl_moment_app* app, double t0); +void gkyl_moment_app_apply_ic_embed(gkyl_moment_app *app, double t0); /** * Read field data from .gkyl file. @@ -284,8 +303,8 @@ void gkyl_moment_app_apply_ic_embed(gkyl_moment_app* app, double t0); * @param fname File to read from. * @return Status of read */ -struct gkyl_app_restart_status gkyl_moment_app_from_file_field(gkyl_moment_app *app, - const char *fname); +struct gkyl_app_restart_status +gkyl_moment_app_from_file_field(gkyl_moment_app *app, const char *fname); /** * Read species data from .gkyl file. @@ -295,8 +314,8 @@ struct gkyl_app_restart_status gkyl_moment_app_from_file_field(gkyl_moment_app * * @param fname File to read from. * @return Status of read */ -struct gkyl_app_restart_status gkyl_moment_app_from_file_species(gkyl_moment_app *app, - int sidx, const char *fname); +struct gkyl_app_restart_status +gkyl_moment_app_from_file_species(gkyl_moment_app *app, int sidx, const char *fname); /** * Read field data from specified frame of previous simulation. @@ -305,8 +324,7 @@ struct gkyl_app_restart_status gkyl_moment_app_from_file_species(gkyl_moment_app * @param frame Frame number to read from * @return Status of read */ -struct gkyl_app_restart_status gkyl_moment_app_from_frame_field(gkyl_moment_app *app, - int frame); +struct gkyl_app_restart_status gkyl_moment_app_from_frame_field(gkyl_moment_app *app, int frame); /** * Read species data from specified frame of previous simulation. @@ -316,8 +334,8 @@ struct gkyl_app_restart_status gkyl_moment_app_from_frame_field(gkyl_moment_app * @param frame Frame number to read from * @return Status of read */ -struct gkyl_app_restart_status gkyl_moment_app_from_frame_species(gkyl_moment_app *app, - int sidx, int frame); +struct gkyl_app_restart_status +gkyl_moment_app_from_frame_species(gkyl_moment_app *app, int sidx, int frame); /** * Initialize the Moment app from a specific frame. @@ -325,8 +343,7 @@ struct gkyl_app_restart_status gkyl_moment_app_from_frame_species(gkyl_moment_ap * @param app App object. * @param frame Frame to read. */ -struct gkyl_app_restart_status -gkyl_moment_app_read_from_frame(gkyl_moment_app *app, int frame); +struct gkyl_app_restart_status gkyl_moment_app_read_from_frame(gkyl_moment_app *app, int frame); /** * Write output to console: this is mainly for diagnostic messages the @@ -338,7 +355,7 @@ gkyl_moment_app_read_from_frame(gkyl_moment_app *app, int frame); * @param fmt Format string for console output * @param argp Objects to write */ -void gkyl_moment_app_cout(const gkyl_moment_app* app, FILE *fp, const char *fmt, ...); +void gkyl_moment_app_cout(const gkyl_moment_app *app, FILE *fp, const char *fmt, ...); /** * Write field and species data to file. @@ -347,7 +364,7 @@ void gkyl_moment_app_cout(const gkyl_moment_app* app, FILE *fp, const char *fmt, * @param tm Time-stamp * @param frame Frame number */ -void gkyl_moment_app_write(const gkyl_moment_app* app, double tm, int frame); +void gkyl_moment_app_write(const gkyl_moment_app *app, double tm, int frame); /** * Write field data to file. @@ -366,7 +383,7 @@ void gkyl_moment_app_write_field(const gkyl_moment_app *app, double tm, int fram * @param tm Time-stamp * @param frame Frame number */ -void gkyl_moment_app_write_species(const gkyl_moment_app* app, int sidx, double tm, int frame); +void gkyl_moment_app_write_species(const gkyl_moment_app *app, int sidx, double tm, int frame); /** * Write field energy to file. @@ -452,7 +469,7 @@ void gkyl_moment_app_get_integrated_mom(gkyl_moment_app *app, double *vals); * @param sidx Species index * @return pointer to the species array for output */ -struct gkyl_array* gkyl_moment_app_get_write_array_species(const gkyl_moment_app* app, int sidx); +struct gkyl_array *gkyl_moment_app_get_write_array_species(const gkyl_moment_app *app, int sidx); /** * Get a pointer to the field array that needs to be written out. If @@ -463,7 +480,7 @@ struct gkyl_array* gkyl_moment_app_get_write_array_species(const gkyl_moment_app * @param app App object. * @return pointer to the field array for output */ -struct gkyl_array* gkyl_moment_app_get_write_array_field(const gkyl_moment_app* app); +struct gkyl_array *gkyl_moment_app_get_write_array_field(const gkyl_moment_app *app); /** * Return simulation statistics. @@ -477,4 +494,4 @@ struct gkyl_moment_stat gkyl_moment_app_stat(gkyl_moment_app *app); * * @param app App to release. */ -void gkyl_moment_app_release(gkyl_moment_app* app); +void gkyl_moment_app_release(gkyl_moment_app *app); diff --git a/moments/apps/gkyl_moment_lw.h b/moments/apps/gkyl_moment_lw.h index a19c63b82e..58b1c0982c 100644 --- a/moments/apps/gkyl_moment_lw.h +++ b/moments/apps/gkyl_moment_lw.h @@ -16,71 +16,62 @@ void gkyl_moment_lw_openlibs(lua_State *L); * * @param L Lua state to use. */ -void -gkyl_register_moment_scheme_types(lua_State *L); +void gkyl_register_moment_scheme_types(lua_State *L); /** * Add wave limiter type flags for fluid solvers into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_wave_limiter_types(lua_State *L); +void gkyl_register_wave_limiter_types(lua_State *L); /** * Add Riemann problem type flags for Euler equations into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_euler_rp_types(lua_State *L); +void gkyl_register_euler_rp_types(lua_State *L); /** * Add Riemann problem type flags for MHD equations into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_mhd_rp_types(lua_State *L); +void gkyl_register_mhd_rp_types(lua_State *L); /** * Add divergence correction type flags for MHD equations into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_mhd_divb_types(lua_State *L); +void gkyl_register_mhd_divb_types(lua_State *L); /** * Add Braginskii type flags for moment equations into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_braginskii_types(lua_State *L); +void gkyl_register_braginskii_types(lua_State *L); /** * Add spacetime gauge type flags for moment equations into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_spacetime_gauge_types(lua_State *L); +void gkyl_register_spacetime_gauge_types(lua_State *L); /** * Add spacetime slicing type flags for Einstein equations into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_spacetime_slicing_types(lua_State *L); +void gkyl_register_spacetime_slicing_types(lua_State *L); /** * Add spacetime evolution type flags for Einstein equations into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_spacetime_evolution_types(lua_State *L); +void gkyl_register_spacetime_evolution_types(lua_State *L); #endif diff --git a/moments/apps/gkyl_moment_multib.h b/moments/apps/gkyl_moment_multib.h index bd086f1872..f93ca5e549 100644 --- a/moments/apps/gkyl_moment_multib.h +++ b/moments/apps/gkyl_moment_multib.h @@ -8,7 +8,7 @@ typedef struct gkyl_moment_multib_app gkyl_moment_multib_app; // Species input per-block struct gkyl_moment_multib_species_pb { int block_id; // block ID - + void *ctx; // context for initial condition init function // pointer to initialization function void (*init)(double t, const double *xn, double *fout, void *ctx); @@ -24,7 +24,7 @@ struct gkyl_moment_multib_species_pb { bool nT_source_set_only_once; }; -// Species input +// Species input struct gkyl_moment_multib_species { char name[128]; // species name double charge, mass; // charge and mass @@ -37,9 +37,9 @@ struct gkyl_moment_multib_species { bool force_low_order_flux; // should we force low-order flux? - bool duplicate_across_blocks; // set to true if all blocks are identical + bool duplicate_across_blocks; // set to true if all blocks are identical // species inputs per-block: only one is needed is are_all_blocks_same = true - const struct gkyl_moment_multib_species_pb *blocks; + const struct gkyl_moment_multib_species_pb *blocks; int num_physical_bcs; const struct gkyl_block_physical_bcs *bcs; @@ -48,7 +48,7 @@ struct gkyl_moment_multib_species { // Field input per-block struct gkyl_moment_multib_field_pb { int block_id; // block ID - + void *ctx; // context for initial condition init function // pointer to initialization function void (*init)(double t, const double *xn, double *fout, void *ctx); @@ -58,14 +58,14 @@ struct gkyl_moment_multib_field_pb { void (*ext_em)(double t, const double *xn, double *ext_em_out, void *ctx); bool ext_em_evolve; // set to true if external electromagnetic field function is time dependent double t_ramp_E; // linear ramp for turning on external E field - + void *app_current_ctx; // context for external electromagnetic fields function // pointer to external electromagnetic fields function void (*app_current)(double t, const double *xn, double *app_current_out, void *ctx); bool app_current_evolve; // set to true if applied current function is time dependent double t_ramp_curr; // linear ramp for turning on applied currents - bool use_explicit_em_coupling; // flag to indicate if using explicit em-coupling + bool use_explicit_em_coupling; // flag to indicate if using explicit em-coupling }; // Field input @@ -84,20 +84,20 @@ struct gkyl_moment_multib_field { const struct gkyl_moment_multib_field_pb *blocks; int num_physical_bcs; - const struct gkyl_block_physical_bcs *bcs; + const struct gkyl_block_physical_bcs *bcs; }; // Top-level app parameters: this struct gkyl_moment_multib { char name[128]; // name of app - // geometry and for blocks in simulation + // geometry and for blocks in simulation struct gkyl_block_geom *block_geom; - // CFL fraction to use + // CFL fraction to use double cfl_frac; enum gkyl_moment_scheme scheme_type; // scheme to update fluid and moment eqns - + enum gkyl_mp_recon mp_recon; // reconstruction scheme to use bool skip_mp_limiter; // should MP limiter be skipped? bool use_hybrid_flux_kep; // should shock-hybrid scheme be used when using KEP? @@ -105,15 +105,15 @@ struct gkyl_moment_multib { int num_skip_dirs; // number of directions to skip int skip_dirs[3]; // directions to skip - // number of species + // number of species int num_species; // species inputs struct gkyl_moment_multib_species species[GKYL_MAX_SPECIES]; - + // field inputs struct gkyl_moment_multib_field field; - // communicator to used + // communicator to used struct gkyl_comm *comm; }; @@ -123,8 +123,8 @@ struct gkyl_moment_multib { * @param mbinp Multi-block App inputs. See struct docs. * @return New multi-block moment app object. */ -struct gkyl_moment_multib_app* gkyl_moment_multib_app_new(const struct gkyl_moment_multib *mbinp); - +struct gkyl_moment_multib_app *gkyl_moment_multib_app_new(const struct gkyl_moment_multib *mbinp); + /** * Compute maximum estimated stable dt wtih current app state. Call * after app initialized and after initial conditions set. @@ -132,7 +132,7 @@ struct gkyl_moment_multib_app* gkyl_moment_multib_app_new(const struct gkyl_mome * @param app App object. * @retuen maximum estimated stable dt */ -double gkyl_moment_multib_app_max_dt(gkyl_moment_multib_app* app); +double gkyl_moment_multib_app_max_dt(gkyl_moment_multib_app *app); /** * Initialize species and field. @@ -140,7 +140,7 @@ double gkyl_moment_multib_app_max_dt(gkyl_moment_multib_app* app); * @param app App object. * @param t0 Time for initial conditions. */ -void gkyl_moment_multib_app_apply_ic(gkyl_moment_multib_app* app, double t0); +void gkyl_moment_multib_app_apply_ic(gkyl_moment_multib_app *app, double t0); /** * Initialize field. @@ -148,7 +148,7 @@ void gkyl_moment_multib_app_apply_ic(gkyl_moment_multib_app* app, double t0); * @param app App object. * @param t0 Time for initial conditions */ -void gkyl_moment_multib_app_apply_ic_field(gkyl_moment_multib_app* app, double t0); +void gkyl_moment_multib_app_apply_ic_field(gkyl_moment_multib_app *app, double t0); /** * Initialize species. @@ -157,7 +157,7 @@ void gkyl_moment_multib_app_apply_ic_field(gkyl_moment_multib_app* app, double t * @param sidx Index of species to initialize. * @param t0 Time for initial conditions */ -void gkyl_moment_multib_app_apply_ic_species(gkyl_moment_multib_app* app, int sidx, double t0); +void gkyl_moment_multib_app_apply_ic_species(gkyl_moment_multib_app *app, int sidx, double t0); /** * Read field data from specified frame of previous simulation. @@ -166,8 +166,8 @@ void gkyl_moment_multib_app_apply_ic_species(gkyl_moment_multib_app* app, int si * @param frame Frame number to read from * @return Status of read */ -struct gkyl_app_restart_status gkyl_moment_multib_app_from_frame_field(gkyl_moment_multib_app *app, - int frame); +struct gkyl_app_restart_status +gkyl_moment_multib_app_from_frame_field(gkyl_moment_multib_app *app, int frame); /** * Read species data from specified frame of previous simulation. @@ -177,8 +177,8 @@ struct gkyl_app_restart_status gkyl_moment_multib_app_from_frame_field(gkyl_mome * @param frame Frame number to read from * @return Status of read */ -struct gkyl_app_restart_status gkyl_moment_multib_app_from_frame_species(gkyl_moment_multib_app *app, - int sidx, int frame); +struct gkyl_app_restart_status +gkyl_moment_multib_app_from_frame_species(gkyl_moment_multib_app *app, int sidx, int frame); /** * Write output to console: this is mainly for diagnostic messages the @@ -190,14 +190,14 @@ struct gkyl_app_restart_status gkyl_moment_multib_app_from_frame_species(gkyl_mo * @param fmt Format string for console output * @param argp Objects to write */ -void gkyl_moment_multib_app_cout(const gkyl_moment_multib_app* app, FILE *fp, const char *fmt, ...); +void gkyl_moment_multib_app_cout(const gkyl_moment_multib_app *app, FILE *fp, const char *fmt, ...); /** * Write block topology to file. * * @param app App object. */ -void gkyl_moment_multib_app_write_topo(const gkyl_moment_multib_app* app); +void gkyl_moment_multib_app_write_topo(const gkyl_moment_multib_app *app); /** * Write field and species data to file. @@ -206,7 +206,7 @@ void gkyl_moment_multib_app_write_topo(const gkyl_moment_multib_app* app); * @param tm Time-stamp * @param frame Frame number */ -void gkyl_moment_multib_app_write(const gkyl_moment_multib_app* app, double tm, int frame); +void gkyl_moment_multib_app_write(const gkyl_moment_multib_app *app, double tm, int frame); /** * Write field data to file. @@ -225,7 +225,9 @@ void gkyl_moment_multib_app_write_field(const gkyl_moment_multib_app *app, doubl * @param tm Time-stamp * @param frame Frame number */ -void gkyl_moment_multib_app_write_species(const gkyl_moment_multib_app* app, int sidx, double tm, int frame); +void gkyl_moment_multib_app_write_species( + const gkyl_moment_multib_app *app, int sidx, double tm, int frame +); /** * Write field energy to file. @@ -297,4 +299,4 @@ struct gkyl_moment_stat gkyl_moment_multib_app_stat(gkyl_moment_multib_app *app) * * @param app App to release. */ -void gkyl_moment_multib_app_release(gkyl_moment_multib_app* app); +void gkyl_moment_multib_app_release(gkyl_moment_multib_app *app); diff --git a/moments/apps/gkyl_moment_multib_priv.h b/moments/apps/gkyl_moment_multib_priv.h index cc71e2f869..4bfb5bf526 100644 --- a/moments/apps/gkyl_moment_multib_priv.h +++ b/moments/apps/gkyl_moment_multib_priv.h @@ -11,11 +11,11 @@ struct gkyl_moment_multib_app { char name[128]; // name of app struct gkyl_comm *comm; // global communicator to use struct gkyl_comm **block_comms; // list of block-communicators - - // geometry and topology of all blocks in simulation + + // geometry and topology of all blocks in simulation struct gkyl_block_geom *block_geom; struct gkyl_block_topo *block_topo; - + double cfl_frac; // CFL fraction to use int num_species; // number of species @@ -34,7 +34,7 @@ struct gkyl_moment_multib_app { struct gkyl_rect_decomp **decomp; // list of decomps (num_blocks) double tcurr; // current time - + struct gkyl_moment_stat stat; // statistics }; diff --git a/moments/apps/gkyl_moment_priv.h b/moments/apps/gkyl_moment_priv.h index 0be9d71da3..f50eb115a0 100644 --- a/moments/apps/gkyl_moment_priv.h +++ b/moments/apps/gkyl_moment_priv.h @@ -63,16 +63,16 @@ struct moment_species { bool is_static; // is the fluid static? // Does this fluid require source terms? - // Set to true if any term which requires source terms is detected + // Set to true if any term which requires source terms is detected // including app->has_field (because the fluids couple to EM fields via sources) - // and various moment_species inputs such as has_friction, has_volume_sources, - // has_reactivity, has_app_accel, etc. + // and various moment_species inputs such as has_friction, has_volume_sources, + // has_reactivity, has_app_accel, etc. bool update_sources; - + double k0; // Closure parameter (default is 0.0, used by 10 moment). bool has_grad_closure; // Has gradient-based closure (only for 10 moment). bool has_nn_closure; // Has neural network-based closure (only for 10 moment). - struct gkyl_kann_net* ann; // Neural network architecture. + struct gkyl_kann_net *ann; // Neural network architecture. int poly_order; // Polynomial order of learned DG coefficients. enum gkyl_braginskii_type type_brag; // which Braginskii equations @@ -85,7 +85,8 @@ struct moment_species { bool has_volume_sources; // Run with volume-based geometrical sources. double volume_gas_gamma; // Adiabatic index for volume-based geometrical sources. double volume_U0; // Initial comoving plasma velocity for volume-based geometrical sources. - double volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. + double + volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. bool has_reactivity; // Run with reactive sources. double reactivity_gas_gamma; // Adiabatic index for reactive sources. @@ -95,35 +96,52 @@ struct moment_species { double reactivity_reaction_rate; // Reaction rate for reactive sources. bool has_einstein_medium; // Run with coupled fluid-Einstein sources in plane-symmetric spacetimes. - double medium_gas_gamma; // Adiabatic index for coupled fluid-Einstein sources in plane-symmetric spacetimes. - double medium_kappa; // Stress-energy prefactor for coupled fluid-Einstein sources in plane-symmetric spacetimes. + double + medium_gas_gamma; // Adiabatic index for coupled fluid-Einstein sources in plane-symmetric spacetimes. + double + medium_kappa; // Stress-energy prefactor for coupled fluid-Einstein sources in plane-symmetric spacetimes. - bool has_gr_ultra_rel; // Run with general relativistic source terms (Euler equations, ultra-relativistic equation of state). - double gr_ultra_rel_gas_gamma; // Adiabatic index for general relativistic Euler equations (ultra-relativistic equation of state). + bool + has_gr_ultra_rel; // Run with general relativistic source terms (Euler equations, ultra-relativistic equation of state). + double + gr_ultra_rel_gas_gamma; // Adiabatic index for general relativistic Euler equations (ultra-relativistic equation of state). - bool has_gr_euler; // Run with general relativistic source terms (Euler equations, ideal gas equation of state). - double gr_euler_gas_gamma; // Adiabatic index for general relativistic Euler equations (ideal gas equation of state). + bool + has_gr_euler; // Run with general relativistic source terms (Euler equations, ideal gas equation of state). + double + gr_euler_gas_gamma; // Adiabatic index for general relativistic Euler equations (ideal gas equation of state). bool has_gr_twofluid; // Run with general relativistic two-fluid source terms. double gr_twofluid_mass_elc; // Electron mass for general relativistic two-fluid equations. double gr_twofluid_mass_ion; // Ion mass for general relativistic two-fluid equations. double gr_twofluid_charge_elc; // Electron charge for general relativistic two-fluid equations. double gr_twofluid_charge_ion; // Ion charge for general relativistic two-fluid equations. - double gr_twofluid_gas_gamma_elc; // Adiabatic index for electrons in general relativistic two-fluid equations. - double gr_twofluid_gas_gamma_ion; // Adiabatic index for ions in general relativistic two-fluid equations. - double gr_twofluid_e_fact; // Electric field divergence error propagation speed for general relativistic two-fluid equations. + double + gr_twofluid_gas_gamma_elc; // Adiabatic index for electrons in general relativistic two-fluid equations. + double + gr_twofluid_gas_gamma_ion; // Adiabatic index for ions in general relativistic two-fluid equations. + double + gr_twofluid_e_fact; // Electric field divergence error propagation speed for general relativistic two-fluid equations. bool has_vacuum_einstein; // Run with vacuum Einstein sources using the Bona-Masso formalism. - double vacuum_einstein_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the Bona-Masso formalism. - enum gkyl_spacetime_slicing vacuum_einstein_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the Bona-Masso formalism. - enum gkyl_spacetime_evolution vacuum_einstein_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the Bona-Masso formalism. - - bool has_vacuum_einstein_conformal; // Run with vacuum Einstein sources using the conformal Bona-Masso formalism. - double vacuum_einstein_conformal_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the conformal Bona-Masso formalism. - enum gkyl_spacetime_slicing vacuum_einstein_conformal_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the conformal Bona-Masso formalism. - enum gkyl_spacetime_evolution vacuum_einstein_conformal_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the conformal Bona-Masso formalism. - - bool has_gr_mhd; // Run with general relativistic source terms (general relativistic magnetohydrodynamics equations). + double + vacuum_einstein_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the Bona-Masso formalism. + enum gkyl_spacetime_slicing + vacuum_einstein_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the Bona-Masso formalism. + enum gkyl_spacetime_evolution + vacuum_einstein_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the Bona-Masso formalism. + + bool + has_vacuum_einstein_conformal; // Run with vacuum Einstein sources using the conformal Bona-Masso formalism. + double + vacuum_einstein_conformal_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the conformal Bona-Masso formalism. + enum gkyl_spacetime_slicing + vacuum_einstein_conformal_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the conformal Bona-Masso formalism. + enum gkyl_spacetime_evolution + vacuum_einstein_conformal_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the conformal Bona-Masso formalism. + + bool + has_gr_mhd; // Run with general relativistic source terms (general relativistic magnetohydrodynamics equations). double gr_mhd_gas_gamma; // Adiabatic index for general relativistic magnetohydrodynamics equations. void *ctx; // context for initial condition init function @@ -145,27 +163,27 @@ struct moment_species { struct gkyl_array *embed_mask; - enum gkyl_eqn_type eqn_type; // type ID of equation - int num_equations; // number of equations in species + enum gkyl_eqn_type eqn_type; // type ID of equation + int num_equations; // number of equations in species struct gkyl_wv_eqn *equation; // equation object enum gkyl_moment_scheme scheme_type; // scheme to update equations - // + // // solvers and data to update fluid equations union { struct { - gkyl_wave_prop *slvr[3]; // wave-prop solver in each direction + gkyl_wave_prop *slvr[3]; // wave-prop solver in each direction struct gkyl_array *fdup, *f[4]; // arrays for updates }; struct { union { - gkyl_mp_scheme *mp_slvr; // monotonicity-preserving scheme + gkyl_mp_scheme *mp_slvr; // monotonicity-preserving scheme gkyl_kep_scheme *kep_slvr; // KEP scheme }; struct gkyl_array *f0, *f1, *fnew; // arrays for updates - struct gkyl_array *cflrate; // CFL rate in each cell - struct gkyl_array *alpha; // for shock detector + struct gkyl_array *cflrate; // CFL rate in each cell + struct gkyl_array *alpha; // for shock detector }; }; struct gkyl_array *fcurr; // points to current solution (depends on scheme) @@ -194,30 +212,34 @@ struct moment_field { bool has_ext_em; // flag to indicate there is external electromagnetic field bool ext_em_evolve; // flag to indicate external electromagnetic field is time dependent struct gkyl_array *ext_em; // external electromagnetic field - gkyl_fv_proj *ext_em_proj; // projector for external electromagnetic field + gkyl_fv_proj *ext_em_proj; // projector for external electromagnetic field double t_ramp_E; // linear ramp for turning on external E field - bool has_app_current; // flag to indicate there is an applied current - bool app_current_evolve; // flag to indicate applied current is time dependent + bool has_app_current; // flag to indicate there is an applied current + bool app_current_evolve; // flag to indicate applied current is time dependent struct gkyl_array *app_current; // applied current - gkyl_fv_proj *app_current_proj; // projector for applied current + gkyl_fv_proj *app_current_proj; // projector for applied current double t_ramp_curr; // linear ramp for turning on applied currents - bool use_explicit_em_coupling; // flag to indicate if em coupling should be explicit, defaults implicit - struct gkyl_array *app_current1; // additional array for applied currents (for use_explicit_em_coupling stages) - struct gkyl_array *app_current2; // additional array for applied currents (for use_explicit_em_coupling stages) + bool + use_explicit_em_coupling; // flag to indicate if em coupling should be explicit, defaults implicit + struct gkyl_array + *app_current1; // additional array for applied currents (for use_explicit_em_coupling stages) + struct gkyl_array + *app_current2; // additional array for applied currents (for use_explicit_em_coupling stages) bool has_volume_sources; // Run with volume-based geometrical sources. double volume_gas_gamma; // Adiabatic index for volume-based geometrical sources. double volume_U0; // Initial comoving plasma velocity for volume-based geometrical sources. - double volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. + double + volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. struct gkyl_array *bc_buffer; // buffer for periodic BCs struct gkyl_array *embed_mask; - // scheme to update equations solvers and data to update fluid - // equations + // scheme to update equations solvers and data to update fluid + // equations enum gkyl_moment_scheme scheme_type; union { struct { @@ -243,9 +265,9 @@ struct moment_field { // Source data struct moment_coupling { - // grid for braginskii variables (braginskii variables located at cell nodes) + // grid for braginskii variables (braginskii variables located at cell nodes) struct gkyl_rect_grid non_ideal_grid; - // local, local-ext ranges for braginskii variables (loop over nodes) + // local, local-ext ranges for braginskii variables (loop over nodes) struct gkyl_range non_ideal_local, non_ideal_local_ext; // Gradient-based closure solver (if present). @@ -253,15 +275,15 @@ struct moment_coupling { // Neural network-based closure solver (if present). struct gkyl_ten_moment_nn_closure *nn_closure_slvr[GKYL_MAX_SPECIES]; // Braginskii solver (if present). - struct gkyl_moment_braginskii *brag_slvr; + struct gkyl_moment_braginskii *brag_slvr; - // array for stable time-step from non-ideal terms + // array for stable time-step from non-ideal terms struct gkyl_array *non_ideal_cflrate[GKYL_MAX_SPECIES]; - // array for non-ideal variables + // array for non-ideal variables // Braginskii variables, viscous stress tensor and heat-flux vector for Euler/Isothermal Euler - // heat-flux tensor for ten-moment + // heat-flux tensor for ten-moment struct gkyl_array *non_ideal_vars[GKYL_MAX_SPECIES]; - // array for storing RHS of each species from non-ideal term updates + // array for storing RHS of each species from non-ideal term updates // Braginskii tranport for Euler/Isothermal Euler // Gradient-based closure for ten-moment struct gkyl_array *pr_rhs[GKYL_MAX_SPECIES]; @@ -283,14 +305,14 @@ struct gkyl_moment_app { double cfl; // CFL number enum gkyl_moment_scheme scheme_type; // scheme to use - enum gkyl_wave_split_type split_type; // edge splitting to use - // + enum gkyl_wave_split_type split_type; // edge splitting to use + // enum gkyl_mp_recon mp_recon; // reconstruction scheme to use - // should shock-hybrid scheme be used when using KEP? + // should shock-hybrid scheme be used when using KEP? bool use_hybrid_flux_kep; bool has_braginskii; // has Braginskii transport - double coll_fac; // multiplicative collisionality factor for Braginskii + double coll_fac; // multiplicative collisionality factor for Braginskii int num_periodic_dir; // number of periodic directions int periodic_dirs[3]; // list of periodic directions @@ -303,10 +325,10 @@ struct gkyl_moment_app { struct gkyl_range global, global_ext; // global, global-ext ranges struct gkyl_rect_decomp *decomp; // decomposition object - struct gkyl_comm *comm; // communicator object + struct gkyl_comm *comm; // communicator object bool has_mapc2p; // flag to indicate if we have mapc2p - void *c2p_ctx; // context for mapc2p function + void *c2p_ctx; // context for mapc2p function // pointer to mapc2p function void (*mapc2p)(double t, const double *xc, double *xp, void *ctx); @@ -324,10 +346,10 @@ struct gkyl_moment_app { // work arrays for use in the KEP and MP scheme: these are stored // here so they can be reused struct { - struct gkyl_array *ql, *qr; // expansions on left/right edge of cell + struct gkyl_array *ql, *qr; // expansions on left/right edge of cell struct gkyl_array *amdq, *apdq; // minus/plus fluctuations }; - + int update_sources; // flag to indicate if sources are to be updated struct moment_coupling sources; // sources @@ -354,55 +376,56 @@ struct moment_output_meta { /** Some common functions to species and fields */ // functions for use in integrated quantities calculation -static inline void -integ_unit(int nc, const double *qin, double *integ_out) +static inline void integ_unit(int nc, const double *qin, double *integ_out) { - for (int i = 0; i < nc; ++i) + for (int i = 0; i < nc; ++i) { integ_out[i] = qin[i]; + } } -static inline void -integ_sq(int nc, const double *qin, double *integ_out) +static inline void integ_sq(int nc, const double *qin, double *integ_out) { - for (int i = 0; i < nc; ++i) + for (int i = 0; i < nc; ++i) { integ_out[i] = qin[i] * qin[i]; + } } // function for copy BC -static inline void -bc_copy(const struct gkyl_wv_eqn* eqn, double t, int nc, const double *skin, - double *GKYL_RESTRICT ghost, void *ctx) +static inline void bc_copy( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { - for (int c = 0; c < nc; ++c) + for (int c = 0; c < nc; ++c) { ghost[c] = skin[c]; + } } // function for skip BCs -static inline void -bc_skip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double *skin, - double *GKYL_RESTRICT ghost, void *ctx) +static inline void bc_skip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { } // Compute integrated quantities specified by i_func -void calc_integ_quant(const struct gkyl_wv_eqn *eqn, double vol, - const struct gkyl_array *q, - const struct gkyl_wave_geom *geom, - struct gkyl_range update_rng, double *integ_q); +void calc_integ_quant( + const struct gkyl_wv_eqn *eqn, double vol, const struct gkyl_array *q, + const struct gkyl_wave_geom *geom, struct gkyl_range update_rng, double *integ_q +); // Check array "q" for nans bool check_for_nans(const struct gkyl_array *q, struct gkyl_range update_rng); // Apply periodic BCs to corner cells of "f" (ONLY WORKS IN 2D) -void moment_apply_periodic_corner_sync_2d(const gkyl_moment_app *app, - struct gkyl_array *f); +void moment_apply_periodic_corner_sync_2d(const gkyl_moment_app *app, struct gkyl_array *f); // Apply wedge-periodic BCs to array "f" -void moment_apply_wedge_bc(const gkyl_moment_app *app, double tcurr, - const struct gkyl_range *update_rng, - struct gkyl_array *bc_buffer, int dir, - const struct gkyl_wv_apply_bc *lo, - const struct gkyl_wv_apply_bc *up, - struct gkyl_array *f); +void moment_apply_wedge_bc( + const gkyl_moment_app *app, double tcurr, const struct gkyl_range *update_rng, + struct gkyl_array *bc_buffer, int dir, const struct gkyl_wv_apply_bc *lo, + const struct gkyl_wv_apply_bc *up, struct gkyl_array *f +); /** * Return ghost cell layout for grid. @@ -416,28 +439,28 @@ void gkyl_moment_app_nghost(gkyl_moment_app *app, int nghost[3]); /** moment_species API */ // Initialize the moment species object -void moment_species_init(const struct gkyl_moment *mom, - const struct gkyl_moment_species *mom_sp, - struct gkyl_moment_app *app, - struct moment_species *sp); +void moment_species_init( + const struct gkyl_moment *mom, const struct gkyl_moment_species *mom_sp, + struct gkyl_moment_app *app, struct moment_species *sp +); // Apply BCs to species data "f" -void moment_species_apply_bc(gkyl_moment_app *app, double tcurr, - const struct moment_species *sp, - struct gkyl_array *f); +void moment_species_apply_bc( + gkyl_moment_app *app, double tcurr, const struct moment_species *sp, struct gkyl_array *f +); // Maximum stable time-step from species -double moment_species_max_dt(const gkyl_moment_app *app, - const struct moment_species *sp); +double moment_species_max_dt(const gkyl_moment_app *app, const struct moment_species *sp); // Advance solution of species by time-step dt to tcurr+dt -struct gkyl_update_status moment_species_update(gkyl_moment_app *app, - struct moment_species *sp, - double tcurr, double dt); +struct gkyl_update_status +moment_species_update(gkyl_moment_app *app, struct moment_species *sp, double tcurr, double dt); // Compute RHS of moment equations -double moment_species_rhs(gkyl_moment_app *app, struct moment_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs); +double moment_species_rhs( + gkyl_moment_app *app, struct moment_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs +); // Free memory allocated by species void moment_species_release(const struct moment_species *sp); @@ -445,27 +468,28 @@ void moment_species_release(const struct moment_species *sp); /** moment_field API */ // Initialize EM field -void moment_field_init(const struct gkyl_moment *mom, - const struct gkyl_moment_field *mom_fld, - struct gkyl_moment_app *app, struct moment_field *fld); +void moment_field_init( + const struct gkyl_moment *mom, const struct gkyl_moment_field *mom_fld, + struct gkyl_moment_app *app, struct moment_field *fld +); // Apply BCs to EM field -void moment_field_apply_bc(gkyl_moment_app *app, double tcurr, - const struct moment_field *field, - struct gkyl_array *f); +void moment_field_apply_bc( + gkyl_moment_app *app, double tcurr, const struct moment_field *field, struct gkyl_array *f +); // Maximum stable time-step due to EM fields -double moment_field_max_dt(const gkyl_moment_app *app, - const struct moment_field *fld); +double moment_field_max_dt(const gkyl_moment_app *app, const struct moment_field *fld); // Update EM field from tcurr to tcurr+dt -struct gkyl_update_status moment_field_update(gkyl_moment_app *app, - const struct moment_field *fld, - double tcurr, double dt); +struct gkyl_update_status +moment_field_update(gkyl_moment_app *app, const struct moment_field *fld, double tcurr, double dt); // Compute RHS of EM equations -double moment_field_rhs(gkyl_moment_app *app, struct moment_field *fld, - const struct gkyl_array *fin, struct gkyl_array *rhs); +double moment_field_rhs( + gkyl_moment_app *app, struct moment_field *fld, const struct gkyl_array *fin, + struct gkyl_array *rhs +); // Release the EM field object void moment_field_release(const struct moment_field *fld); @@ -474,39 +498,36 @@ void moment_field_release(const struct moment_field *fld); // initialize source solver: this should be called after all species // and fields are initialized -void moment_coupling_init(const struct gkyl_moment_app *app, - struct moment_coupling *src); +void moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling *src); /** mhd_src functions */ -void mhd_src_init(const struct gkyl_moment_app *app, - const struct gkyl_moment_species *sp, struct mhd_src *src); +void mhd_src_init( + const struct gkyl_moment_app *app, const struct gkyl_moment_species *sp, struct mhd_src *src +); // update sources: 'nstrang' is 0 for the first Strang step and 1 for // the second step -void mhd_src_update(gkyl_moment_app *app, struct mhd_src *src, int nstrang, - double tcurr, double dt); +void mhd_src_update(gkyl_moment_app *app, struct mhd_src *src, int nstrang, double tcurr, double dt); void mhd_src_release(const struct mhd_src *src); // update sources: 'nstrang' is 0 for the first Strang step and 1 for // the second step -struct gkyl_update_status moment_coupling_update(gkyl_moment_app *app, - struct moment_coupling *src, int nstrang, double tcurr, double dt); +struct gkyl_update_status moment_coupling_update( + gkyl_moment_app *app, struct moment_coupling *src, int nstrang, double tcurr, double dt +); // Release coupling sources -void moment_coupling_release(const struct gkyl_moment_app *app, - const struct moment_coupling *src); +void moment_coupling_release(const struct gkyl_moment_app *app, const struct moment_coupling *src); /** Top-level app API */ // Take a single time-step using a single-step time-stepper -struct gkyl_update_status moment_update_one_step(gkyl_moment_app *app, - double dt0); +struct gkyl_update_status moment_update_one_step(gkyl_moment_app *app, double dt0); // Take a single time-step using a SSP-RK3 stepper -struct gkyl_update_status moment_update_ssp_rk3(gkyl_moment_app *app, - double dt0); +struct gkyl_update_status moment_update_ssp_rk3(gkyl_moment_app *app, double dt0); /** * Create new array meta header from input struct. Free returned @@ -515,7 +536,7 @@ struct gkyl_update_status moment_update_ssp_rk3(gkyl_moment_app *app, * @param meta Meta-data for output. * @return New meta object to pass to write method. */ -struct gkyl_msgpack_data* moment_array_meta_new(struct moment_output_meta meta); +struct gkyl_msgpack_data *moment_array_meta_new(struct moment_output_meta meta); /** * Release meta struct diff --git a/moments/apps/mom_coupling.c b/moments/apps/mom_coupling.c index cfbd167469..72c6096e47 100644 --- a/moments/apps/mom_coupling.c +++ b/moments/apps/mom_coupling.c @@ -2,61 +2,67 @@ // initialize source solver: this should be called after all species // and fields are initialized -void -moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling *src) +void moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling *src) { struct gkyl_moment_em_coupling_inp src_inp = { .grid = &app->grid, .nfluids = app->num_species, // if there is a field, need to update electric field too, otherwise just updating fluid - .epsilon0 = app->field.epsilon0 ? app->field.epsilon0 : 0.0, - .mu0 = app->field.mu0 ? app->field.mu0 : 0.0, + .epsilon0 = app->field.epsilon0 ? app->field.epsilon0 : 0.0, + .mu0 = app->field.mu0 ? app->field.mu0 : 0.0, // is the field static? - .static_field = app->field.is_static, + .static_field = app->field.is_static, // linear ramping function for slowing turning on applied accelerations, E fields, or currents .t_ramp_E = app->field.t_ramp_E ? app->field.t_ramp_E : 0.0, - .t_ramp_curr = app->field.t_ramp_curr ? app->field.t_ramp_curr : 0.0, + .t_ramp_curr = app->field.t_ramp_curr ? app->field.t_ramp_curr : 0.0 }; - for (int i=0; inum_species; ++i) - src_inp.param[i] = (struct gkyl_moment_em_coupling_data) { - .type = app->species[i].eqn_type, + for (int i = 0; i < app->num_species; ++i) { + src_inp.param[i] = (struct gkyl_moment_em_coupling_data + ){.type = app->species[i].eqn_type, .charge = app->species[i].charge, .mass = app->species[i].mass, // The gradient-based closure defines its heat flux through k0, so k0=0.0 in the source solve to avoid double-applying it. // The neural-network closure supplies the heat flux directly, so k0 is retained here as the integrating-factor relaxation rate. - .k0 = (app->species[i].has_grad_closure) ? 0.0 : app->species[i].k0, - }; + .k0 = (app->species[i].has_grad_closure) ? 0.0 : app->species[i].k0}; + } src_inp.has_collision = app->has_collision; - for (int s=0; snum_species; ++s) - for (int r=0; rnum_species; ++r) + for (int s = 0; s < app->num_species; ++s) { + for (int r = 0; r < app->num_species; ++r) { src_inp.nu_base[s][r] = app->nu_base[s][r]; + } + } src_inp.has_nT_sources = false; - for (int i=0; inum_species; ++i) - if (app->species[i].proj_nT_source) + for (int i = 0; i < app->num_species; ++i) { + if (app->species[i].proj_nT_source) { src_inp.has_nT_sources = true; + } + } // check for relativistic-species bool use_rel = 0; - for (int n=0; nnum_species; ++n) - use_rel = use_rel || (app->species[n].eqn_type == GKYL_EQN_COLDFLUID_SR) || app->field.use_explicit_em_coupling; + for (int n = 0; n < app->num_species; ++n) { + use_rel = use_rel || (app->species[n].eqn_type == GKYL_EQN_COLDFLUID_SR) || + app->field.use_explicit_em_coupling; + } src_inp.has_frictional_sources = false; src_inp.use_explicit_friction = false; for (int i = 0; i < app->num_species; i++) { - if(app->species[i].has_friction) { + if (app->species[i].has_friction) { src_inp.has_frictional_sources = true; - if (app->species[i].friction_Z != 0.0 || app->species[i].friction_T_elc != 0.0 || app->species[i].friction_Lambda_ee != 0.0) { + if (app->species[i].friction_Z != 0.0 || app->species[i].friction_T_elc != 0.0 || + app->species[i].friction_Lambda_ee != 0.0) { src_inp.friction_Z = app->species[i].friction_Z; src_inp.friction_T_elc = app->species[i].friction_T_elc; src_inp.friction_Lambda_ee = app->species[i].friction_Lambda_ee; } } - if(app->species[i].use_explicit_friction) { + if (app->species[i].use_explicit_friction) { src_inp.use_explicit_friction = true; } } @@ -66,17 +72,19 @@ moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling * if (app->species[i].has_volume_sources) { src_inp.has_volume_sources = true; - if(app->species[i].volume_gas_gamma != 0.0 || app->species[i].volume_U0 != 0.0 || app->species[i].volume_R0 != 0.0) { + if (app->species[i].volume_gas_gamma != 0.0 || app->species[i].volume_U0 != 0.0 || + app->species[i].volume_R0 != 0.0) { src_inp.volume_gas_gamma = app->species[i].volume_gas_gamma; src_inp.volume_U0 = app->species[i].volume_U0; src_inp.volume_R0 = app->species[i].volume_R0; } } } - if(app->field.has_volume_sources) { + if (app->field.has_volume_sources) { src_inp.has_volume_sources = true; - if(app->field.volume_gas_gamma != 0.0 || app->field.volume_U0 != 0.0 || app->field.volume_R0 != 0.0) { + if (app->field.volume_gas_gamma != 0.0 || app->field.volume_U0 != 0.0 || + app->field.volume_R0 != 0.0) { src_inp.volume_gas_gamma = app->field.volume_gas_gamma; src_inp.volume_U0 = app->field.volume_U0; src_inp.volume_R0 = app->field.volume_R0; @@ -88,19 +96,21 @@ moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling * if (app->species[i].has_reactivity) { src_inp.has_reactive_sources = true; - if (app->species[i].reactivity_gas_gamma != 0.0 || app->species[i].reactivity_specific_heat_capacity != 0.0 || - app->species[i].reactivity_energy_of_formation != 0.0 || app->species[i].reactivity_ignition_temperature != 0.0 || - app->species[i].reactivity_reaction_rate != 0.0) { - + if (app->species[i].reactivity_gas_gamma != 0.0 || + app->species[i].reactivity_specific_heat_capacity != 0.0 || + app->species[i].reactivity_energy_of_formation != 0.0 || + app->species[i].reactivity_ignition_temperature != 0.0 || + app->species[i].reactivity_reaction_rate != 0.0) { src_inp.reactivity_gas_gamma = app->species[i].reactivity_gas_gamma; - src_inp.reactivity_specific_heat_capacity = app->species[i].reactivity_specific_heat_capacity; + src_inp.reactivity_specific_heat_capacity = + app->species[i].reactivity_specific_heat_capacity; src_inp.reactivity_energy_of_formation = app->species[i].reactivity_energy_of_formation; src_inp.reactivity_ignition_temperature = app->species[i].reactivity_ignition_temperature; src_inp.reactivity_reaction_rate = app->species[i].reactivity_reaction_rate; } } } - + src_inp.has_einstein_medium_sources = false; for (int i = 0; i < app->num_species; i++) { if (app->species[i].has_einstein_medium) { @@ -140,9 +150,13 @@ moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling * if (app->species[i].has_gr_twofluid) { src_inp.has_gr_twofluid_sources = true; - if (app->species[i].gr_twofluid_mass_elc != 0.0 || app->species[i].gr_twofluid_mass_ion != 0.0 || app->species[i].gr_twofluid_charge_elc != 0.0 || - app->species[i].gr_twofluid_charge_ion != 0.0 || app->species[i].gr_twofluid_gas_gamma_elc != 0.0 || app->species[i].gr_twofluid_gas_gamma_ion != 0.0 || - app->species[i].gr_twofluid_e_fact != 0.0) { + if (app->species[i].gr_twofluid_mass_elc != 0.0 || + app->species[i].gr_twofluid_mass_ion != 0.0 || + app->species[i].gr_twofluid_charge_elc != 0.0 || + app->species[i].gr_twofluid_charge_ion != 0.0 || + app->species[i].gr_twofluid_gas_gamma_elc != 0.0 || + app->species[i].gr_twofluid_gas_gamma_ion != 0.0 || + app->species[i].gr_twofluid_e_fact != 0.0) { src_inp.gr_twofluid_mass_elc = app->species[i].gr_twofluid_mass_elc; src_inp.gr_twofluid_mass_ion = app->species[i].gr_twofluid_mass_ion; src_inp.gr_twofluid_charge_elc = app->species[i].gr_twofluid_charge_elc; @@ -170,9 +184,11 @@ moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling * if (app->species[i].has_vacuum_einstein) { src_inp.has_vacuum_einstein_sources = true; - src_inp.vacuum_einstein_excision_threshold = app->species[i].vacuum_einstein_excision_threshold; + src_inp.vacuum_einstein_excision_threshold = + app->species[i].vacuum_einstein_excision_threshold; src_inp.vacuum_einstein_spacetime_slicing = app->species[i].vacuum_einstein_spacetime_slicing; - src_inp.vacuum_einstein_spacetime_evolution = app->species[i].vacuum_einstein_spacetime_evolution; + src_inp.vacuum_einstein_spacetime_evolution = + app->species[i].vacuum_einstein_spacetime_evolution; } } @@ -181,9 +197,12 @@ moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling * if (app->species[i].has_vacuum_einstein_conformal) { src_inp.has_vacuum_einstein_conformal_sources = true; - src_inp.vacuum_einstein_conformal_excision_threshold = app->species[i].vacuum_einstein_conformal_excision_threshold; - src_inp.vacuum_einstein_conformal_spacetime_slicing = app->species[i].vacuum_einstein_conformal_spacetime_slicing; - src_inp.vacuum_einstein_conformal_spacetime_evolution = app->species[i].vacuum_einstein_conformal_spacetime_evolution; + src_inp.vacuum_einstein_conformal_excision_threshold = + app->species[i].vacuum_einstein_conformal_excision_threshold; + src_inp.vacuum_einstein_conformal_spacetime_slicing = + app->species[i].vacuum_einstein_conformal_spacetime_slicing; + src_inp.vacuum_einstein_conformal_spacetime_evolution = + app->species[i].vacuum_einstein_conformal_spacetime_evolution; } } @@ -192,38 +211,38 @@ moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling * // check for explicit em-coupling src_inp.use_explicit_em_coupling = 0; - if (app->field.use_explicit_em_coupling) + if (app->field.use_explicit_em_coupling) { src_inp.use_explicit_em_coupling = 1; + } // create updater to solve for sources src->slvr = gkyl_moment_em_coupling_new(src_inp); - for (int n=0; nnum_species; ++n) { + for (int n = 0; n < app->num_species; ++n) { int meqn = app->species[n].num_equations; src->pr_rhs[n] = mkarr(false, meqn, app->local_ext.volume); src->non_ideal_cflrate[n] = mkarr(false, 1, app->local_ext.volume); } - int ghost[3] = { 1, 1, 1 }; + int ghost[3] = {1, 1, 1}; // create non-ideal local extended range from local range // has one additional cell in each direction because non-ideal // variables are stored at cell vertices - gkyl_create_vertex_ranges(&app->local, ghost, &src->non_ideal_local_ext, - &src->non_ideal_local); + gkyl_create_vertex_ranges(&app->local, ghost, &src->non_ideal_local_ext, &src->non_ideal_local); // check if gradient-closure is present - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { if (app->species[i].eqn_type == GKYL_EQN_TEN_MOMENT && app->species[i].has_grad_closure) { - int nadj[3] = { 1, 4, 8 }; // cells adjacent to a vertex - src->non_ideal_vars[i] = mkarr(false, nadj[app->ndim - 1]*10, - src->non_ideal_local_ext.volume); + int nadj[3] = {1, 4, 8}; // cells adjacent to a vertex + src->non_ideal_vars[i] = + mkarr(false, nadj[app->ndim - 1] * 10, src->non_ideal_local_ext.volume); struct gkyl_ten_moment_grad_closure_inp grad_closure_inp = { .grid = &app->grid, .k0 = app->species[i].k0, .cfl = app->cfl, .comm = app->comm, .update_range = &app->local, - .heat_flux_range = &src->non_ideal_local, + .heat_flux_range = &src->non_ideal_local }; src->grad_closure_slvr[i] = gkyl_ten_moment_grad_closure_new(&grad_closure_inp); } @@ -236,7 +255,7 @@ moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling * .grid = &app->grid, .k0 = app->species[i].k0, .poly_order = app->species[i].poly_order, - .ann = app->species[i].ann, + .ann = app->species[i].ann }; src->nn_closure_slvr[i] = gkyl_ten_moment_nn_closure_new(nn_closure_inp); } @@ -249,25 +268,23 @@ moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling * .nfluids = app->num_species, .epsilon0 = app->field.epsilon0, // Check for multiplicative collisionality factor, default is 1.0 - .coll_fac = app->coll_fac == 0 ? 1.0 : app->coll_fac, + .coll_fac = app->coll_fac == 0 ? 1.0 : app->coll_fac }; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { // Braginskii coefficients depend on pressure and coefficient to obtain // pressure is different for different equation systems (gasGamma, vt, Tr(P)) double p_fac = 1.0; if (app->species[i].eqn_type == GKYL_EQN_EULER) { - p_fac = gkyl_wv_euler_gas_gamma(app->species[i].equation); + p_fac = gkyl_wv_euler_gas_gamma(app->species[i].equation); + } else if (app->species[i].eqn_type == GKYL_EQN_ISO_EULER) { + p_fac = gkyl_wv_iso_euler_vt(app->species[i].equation); } - else if (app->species[i].eqn_type == GKYL_EQN_ISO_EULER) { - p_fac = gkyl_wv_iso_euler_vt(app->species[i].equation); - } - brag_inp.param[i] = (struct gkyl_moment_braginskii_data) { - .type_eqn = app->species[i].eqn_type, + brag_inp.param[i] = (struct gkyl_moment_braginskii_data + ){.type_eqn = app->species[i].eqn_type, .type_brag = app->species[i].type_brag, .charge = app->species[i].charge, .mass = app->species[i].mass, - .p_fac = p_fac, - }; + .p_fac = p_fac}; } src->brag_slvr = gkyl_moment_braginskii_new(brag_inp); } @@ -275,11 +292,11 @@ moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling * // update sources: 'nstrang' is 0 for the first Strang step and 1 for // the second step -struct gkyl_update_status -moment_coupling_update(gkyl_moment_app *app, struct moment_coupling *src, - int nstrang, double tcurr, double dt) +struct gkyl_update_status moment_coupling_update( + gkyl_moment_app *app, struct moment_coupling *src, int nstrang, double tcurr, double dt +) { - int sidx[] = { 0, app->ndim }; + int sidx[] = {0, app->ndim}; struct gkyl_array *fluids[GKYL_MAX_SPECIES]; const struct gkyl_array *app_accels[GKYL_MAX_SPECIES]; const struct gkyl_array *pr_rhs_const[GKYL_MAX_SPECIES]; @@ -288,27 +305,28 @@ moment_coupling_update(gkyl_moment_app *app, struct moment_coupling *src, double dt_suggested = DBL_MAX; struct gkyl_ten_moment_grad_closure_status stat; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { fluids[i] = app->species[i].f[sidx[nstrang]]; if (app->species[i].app_accel_evolve) { - gkyl_fv_proj_advance(app->species[i].app_accel_proj, tcurr, &app->local, app->species[i].app_accel); + gkyl_fv_proj_advance( + app->species[i].app_accel_proj, tcurr, &app->local, app->species[i].app_accel + ); } app_accels[i] = app->species[i].app_accel; if (app->species[i].eqn_type == GKYL_EQN_TEN_MOMENT && app->species[i].has_grad_closure) { // Non-ideal variables are defined on an extended range with one additional "cell" in each direction. // This additional cell accounts for the fact that non-ideal variables are stored at cell vertices. - stat = gkyl_ten_moment_grad_closure_advance(src->grad_closure_slvr[i], - &src->non_ideal_local, &app->local, - app->species[i].f[sidx[nstrang]], app->field.f[sidx[nstrang]], - src->non_ideal_cflrate[i], dt, src->non_ideal_vars[i], src->pr_rhs[i]); - - if (!stat.success) - return (struct gkyl_update_status) { - .success = false, - .dt_suggested = stat.dt_suggested - }; + stat = gkyl_ten_moment_grad_closure_advance( + src->grad_closure_slvr[i], &src->non_ideal_local, &app->local, + app->species[i].f[sidx[nstrang]], app->field.f[sidx[nstrang]], src->non_ideal_cflrate[i], + dt, src->non_ideal_vars[i], src->pr_rhs[i] + ); + + if (!stat.success) { + return (struct gkyl_update_status){.success = false, .dt_suggested = stat.dt_suggested}; + } dt_suggested = fmin(dt_suggested, stat.dt_suggested); } @@ -316,16 +334,19 @@ moment_coupling_update(gkyl_moment_app *app, struct moment_coupling *src, if (app->species[i].eqn_type == GKYL_EQN_TEN_MOMENT && app->species[i].has_nn_closure) { // Non-ideal variables are defined on an extended range with one additional "cell" in each direction. // This additional cell accounts for the fact that non-ideal variables are stored at cell vertices. - gkyl_ten_moment_nn_closure_advance(src->nn_closure_slvr[i], &src->non_ideal_local, &app->local, app->species[i].f[sidx[nstrang]], - app->field.f[sidx[nstrang]], src->non_ideal_vars[i], src->pr_rhs[i]); + gkyl_ten_moment_nn_closure_advance( + src->nn_closure_slvr[i], &src->non_ideal_local, &app->local, + app->species[i].f[sidx[nstrang]], app->field.f[sidx[nstrang]], src->non_ideal_vars[i], + src->pr_rhs[i] + ); } } if (app->has_braginskii) { - gkyl_moment_braginskii_advance(src->brag_slvr, - src->non_ideal_local, app->local, - fluids, app->field.f[sidx[nstrang]], - src->non_ideal_cflrate, src->non_ideal_vars, src->pr_rhs); + gkyl_moment_braginskii_advance( + src->brag_slvr, src->non_ideal_local, app->local, fluids, app->field.f[sidx[nstrang]], + src->non_ideal_cflrate, src->non_ideal_vars, src->pr_rhs + ); } if (app->field.ext_em_evolve) { @@ -335,63 +356,60 @@ moment_coupling_update(gkyl_moment_app *app, struct moment_coupling *src, if (app->field.app_current_evolve) { if (app->field.use_explicit_em_coupling) { gkyl_fv_proj_advance(app->field.app_current_proj, tcurr, &app->local, app->field.app_current); - gkyl_fv_proj_advance(app->field.app_current_proj, tcurr + dt*2, &app->local, app->field.app_current1); - gkyl_fv_proj_advance(app->field.app_current_proj, tcurr + 2*dt/2.0, &app->local, app->field.app_current2); - } - else { + gkyl_fv_proj_advance( + app->field.app_current_proj, tcurr + dt * 2, &app->local, app->field.app_current1 + ); + gkyl_fv_proj_advance( + app->field.app_current_proj, tcurr + 2 * dt / 2.0, &app->local, app->field.app_current2 + ); + } else { gkyl_fv_proj_advance(app->field.app_current_proj, tcurr, &app->local, app->field.app_current); } } // Get the RHS pointer for accumulation during source update - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { pr_rhs_const[i] = src->pr_rhs[i]; } - for (int i=0; inum_species; ++i) { - if (app->species[i].proj_nT_source - && !(app->species[i].nT_source_set_only_once - && app->species[i].nT_source_is_set)) - { - gkyl_fv_proj_advance(app->species[i].proj_nT_source, tcurr, - &app->local, app->species[i].nT_source); + for (int i = 0; i < app->num_species; ++i) { + if (app->species[i].proj_nT_source && + !(app->species[i].nT_source_set_only_once && app->species[i].nT_source_is_set)) { + gkyl_fv_proj_advance( + app->species[i].proj_nT_source, tcurr, &app->local, app->species[i].nT_source + ); } nT_sources[i] = app->species[i].nT_source; app->species[i].nT_source_is_set = true; } if (app->field.use_explicit_em_coupling) { - gkyl_moment_em_coupling_explicit_advance(src->slvr, tcurr, dt, &app->local, - fluids, app_accels, pr_rhs_const, + gkyl_moment_em_coupling_explicit_advance( + src->slvr, tcurr, dt, &app->local, fluids, app_accels, pr_rhs_const, app->field.f[sidx[nstrang]], app->field.app_current, app->field.app_current1, - app->field.app_current2, app->field.ext_em, - nT_sources, app->field.app_current_proj,nstrang); - } - else { - gkyl_moment_em_coupling_implicit_advance(src->slvr, tcurr, dt, &app->local, - fluids, app_accels, pr_rhs_const, - app->field.f[sidx[nstrang]], app->field.app_current, app->field.ext_em, - nT_sources); + app->field.app_current2, app->field.ext_em, nT_sources, app->field.app_current_proj, nstrang + ); + } else { + gkyl_moment_em_coupling_implicit_advance( + src->slvr, tcurr, dt, &app->local, fluids, app_accels, pr_rhs_const, + app->field.f[sidx[nstrang]], app->field.app_current, app->field.ext_em, nT_sources + ); } - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { moment_species_apply_bc(app, tcurr, &app->species[i], fluids[i]); } if (app->has_field) { moment_field_apply_bc(app, tcurr, &app->field, app->field.f[sidx[nstrang]]); } - return (struct gkyl_update_status) { - .success = true, - .dt_suggested = dt_suggested - }; + return (struct gkyl_update_status){.success = true, .dt_suggested = dt_suggested}; } // free sources -void -moment_coupling_release(const struct gkyl_moment_app *app, const struct moment_coupling *src) +void moment_coupling_release(const struct gkyl_moment_app *app, const struct moment_coupling *src) { gkyl_moment_em_coupling_release(src->slvr); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_array_release(src->pr_rhs[i]); gkyl_array_release(src->non_ideal_cflrate[i]); gkyl_array_release(src->non_ideal_vars[i]); @@ -402,7 +420,7 @@ moment_coupling_release(const struct gkyl_moment_app *app, const struct moment_c gkyl_ten_moment_nn_closure_release(src->nn_closure_slvr[i]); } } - if (app->has_braginskii) + if (app->has_braginskii) { gkyl_moment_braginskii_release(src->brag_slvr); + } } - diff --git a/moments/apps/mom_field.c b/moments/apps/mom_field.c index fc55175db2..793c572c64 100644 --- a/moments/apps/mom_field.c +++ b/moments/apps/mom_field.c @@ -1,91 +1,87 @@ #include // initialize field -void -moment_field_init(const struct gkyl_moment *mom, const struct gkyl_moment_field *mom_fld, - struct gkyl_moment_app *app, struct moment_field *fld) +void moment_field_init( + const struct gkyl_moment *mom, const struct gkyl_moment_field *mom_fld, + struct gkyl_moment_app *app, struct moment_field *fld +) { fld->ndim = mom->ndim; double epsilon0 = fld->epsilon0 = mom_fld->epsilon0; double mu0 = fld->mu0 = mom_fld->mu0; - bool is_static = fld->is_static = mom_fld->is_static; + bool is_static = fld->is_static = mom_fld->is_static; fld->ctx = mom_fld->ctx; fld->init = mom_fld->init; fld->scheme_type = mom->scheme_type; - + // choose default limiter - enum gkyl_wave_limiter limiter = - mom_fld->limiter == 0 ? GKYL_MONOTONIZED_CENTERED : mom_fld->limiter; - - double c = 1/sqrt(epsilon0*mu0); - struct gkyl_wv_eqn *maxwell = gkyl_wv_maxwell_inew(&(struct gkyl_wv_maxwell_inp) { - .c = c, - .e_fact = mom_fld->elc_error_speed_fact, - .b_fact = mom_fld->mag_error_speed_fact, - .rp_type = WV_MAXWELL_RP_ROE, - .embed_geo = mom_fld->embed_geo, - .use_gpu = false, - } - ); + enum gkyl_wave_limiter limiter = mom_fld->limiter == 0 ? GKYL_MONOTONIZED_CENTERED : + mom_fld->limiter; + + double c = 1 / sqrt(epsilon0 * mu0); + struct gkyl_wv_eqn *maxwell = gkyl_wv_maxwell_inew(&(struct gkyl_wv_maxwell_inp + ){.c = c, + .e_fact = mom_fld->elc_error_speed_fact, + .b_fact = mom_fld->mag_error_speed_fact, + .rp_type = WV_MAXWELL_RP_ROE, + .embed_geo = mom_fld->embed_geo, + .use_gpu = false}); fld->maxwell = gkyl_wv_eqn_acquire(maxwell); - + int ndim = mom->ndim; if (fld->scheme_type == GKYL_MOMENT_WAVE_PROP) { // create updaters for each directional update - for (int d=0; dslvr[d] = gkyl_wave_prop_new( &(struct gkyl_wave_prop_inp) { - .grid = &app->grid, - .equation = maxwell, - .split_type = GKYL_WAVE_QWAVE, // q-waves is fine for linear systems - .limiter = limiter, - .num_up_dirs = app->is_dir_skipped[d] ? 0 : 1, - .update_dirs = { d }, - .check_inv_domain = false, - .cfl = app->cfl, - .geom = app->geom, - .comm = app->comm - } - ); + for (int d = 0; d < ndim; ++d) { + fld->slvr[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &app->grid, + .equation = maxwell, + .split_type = GKYL_WAVE_QWAVE, // q-waves is fine for linear systems + .limiter = limiter, + .num_up_dirs = app->is_dir_skipped[d] ? 0 : 1, + .update_dirs = {d}, + .check_inv_domain = false, + .cfl = app->cfl, + .geom = app->geom, + .comm = app->comm}); + } // allocate arrays fld->fdup = mkarr(false, 8, app->local_ext.volume); - for (int d=0; df[d] = mkarr(false, 8, app->local_ext.volume); + } // set current solution so ICs and IO work properly fld->fcurr = fld->f[0]; - } - else if (fld->scheme_type == GKYL_MOMENT_MP || fld->scheme_type == GKYL_MOMENT_KEP) { + } else if (fld->scheme_type == GKYL_MOMENT_MP || fld->scheme_type == GKYL_MOMENT_KEP) { // NOTE: there is no KEP scheme for Maxwell, and we simply use MP scheme instead - + // determine directions to update - int num_up_dirs = 0, update_dirs[GKYL_MAX_CDIM] = { 0 }; - for (int d=0; dis_dir_skipped[d]) { update_dirs[num_up_dirs] = d; num_up_dirs += 1; } + } // choose U3 as field reconstruction if using KEP - enum gkyl_mp_recon mp_recon = - fld->scheme_type == GKYL_MOMENT_KEP ? GKYL_MP_U3 : app->mp_recon; - + enum gkyl_mp_recon mp_recon = fld->scheme_type == GKYL_MOMENT_KEP ? GKYL_MP_U3 : app->mp_recon; + // single MP updater updates all directions - fld->mp_slvr = gkyl_mp_scheme_new( &(struct gkyl_mp_scheme_inp) { - .grid = &app->grid, - .equation = maxwell, - .mp_recon = mp_recon, - .skip_mp_limiter = mom->skip_mp_limiter, - .num_up_dirs = num_up_dirs, - .update_dirs = { update_dirs[0], update_dirs[1], update_dirs[2] } , - .cfl = app->cfl, - .geom = app->geom, - } - ); + fld->mp_slvr = gkyl_mp_scheme_new(&(struct gkyl_mp_scheme_inp + ){.grid = &app->grid, + .equation = maxwell, + .mp_recon = mp_recon, + .skip_mp_limiter = mom->skip_mp_limiter, + .num_up_dirs = num_up_dirs, + .update_dirs = {update_dirs[0], update_dirs[1], update_dirs[2]}, + .cfl = app->cfl, + .geom = app->geom}); // allocate arrays fld->f0 = mkarr(false, 8, app->local_ext.volume); @@ -99,103 +95,107 @@ moment_field_init(const struct gkyl_moment *mom, const struct gkyl_moment_field // determine which directions are not periodic int num_periodic_dir = app->num_periodic_dir, is_np[3] = {1, 1, 1}; - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { fld->lower_bc[i] = 0; fld->upper_bc[i] = 0; } int nghost[3] = {2, 2, 2}; - for (int dir=0; dirndim; ++dir) { + for (int dir = 0; dir < app->ndim; ++dir) { if (is_np[dir]) { const enum gkyl_field_bc_type *bc; - if (dir == 0) + if (dir == 0) { bc = mom_fld->bcx; - else if (dir == 1) + } else if (dir == 1) { bc = mom_fld->bcy; - else + } else { bc = mom_fld->bcz; - + } + wv_bc_func_t bc_lower_func; - if (dir == 0) + if (dir == 0) { bc_lower_func = mom_fld->bcx_func[0]; - else if (dir == 1) + } else if (dir == 1) { bc_lower_func = mom_fld->bcy_func[0]; - else + } else { bc_lower_func = mom_fld->bcz_func[0]; + } wv_bc_func_t bc_upper_func; - if (dir == 0) + if (dir == 0) { bc_upper_func = mom_fld->bcx_func[1]; - else if (dir == 1) + } else if (dir == 1) { bc_upper_func = mom_fld->bcy_func[1]; - else + } else { bc_upper_func = mom_fld->bcz_func[1]; + } fld->lower_bct[dir] = bc[0]; fld->upper_bct[dir] = bc[1]; switch (bc[0]) { - case GKYL_FIELD_PEC_WALL: - fld->lower_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, maxwell, app->geom, dir, GKYL_LOWER_EDGE, nghost, - maxwell->wall_bc_func, 0); - break; - - case GKYL_FIELD_FUNC: - fld->lower_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, maxwell, app->geom, dir, GKYL_LOWER_EDGE, nghost, - bc_lower_func, mom_fld->ctx); - - case GKYL_FIELD_COPY: - case GKYL_FIELD_WEDGE: - fld->lower_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, maxwell, app->geom, dir, GKYL_LOWER_EDGE, nghost, - bc_copy, 0); - break; - - case GKYL_FIELD_SKIP: - fld->lower_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, maxwell, app->geom, dir, GKYL_LOWER_EDGE, nghost, - bc_skip, 0); - break; - - default: - assert(false); - break; + case GKYL_FIELD_PEC_WALL: + fld->lower_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, maxwell, app->geom, dir, GKYL_LOWER_EDGE, nghost, maxwell->wall_bc_func, 0 + ); + break; + + case GKYL_FIELD_FUNC: + fld->lower_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, maxwell, app->geom, dir, GKYL_LOWER_EDGE, nghost, bc_lower_func, mom_fld->ctx + ); + + case GKYL_FIELD_COPY: + case GKYL_FIELD_WEDGE: + fld->lower_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, maxwell, app->geom, dir, GKYL_LOWER_EDGE, nghost, bc_copy, 0 + ); + break; + + case GKYL_FIELD_SKIP: + fld->lower_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, maxwell, app->geom, dir, GKYL_LOWER_EDGE, nghost, bc_skip, 0 + ); + break; + + default: + assert(false); + break; } switch (bc[1]) { - case GKYL_FIELD_PEC_WALL: - fld->upper_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, maxwell, app->geom, dir, GKYL_UPPER_EDGE, nghost, - maxwell->wall_bc_func, 0); - break; - - case GKYL_FIELD_FUNC: - fld->upper_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, maxwell, app->geom, dir, GKYL_UPPER_EDGE, nghost, - bc_upper_func, mom_fld->ctx); - break; - - case GKYL_FIELD_COPY: - case GKYL_FIELD_WEDGE: - fld->upper_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, maxwell, app->geom, dir, GKYL_UPPER_EDGE, - nghost, bc_copy, 0); - break; - - case GKYL_FIELD_SKIP: - fld->upper_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, maxwell, app->geom, dir, GKYL_UPPER_EDGE, - nghost, bc_skip, 0); - break; - - default: - assert(false); - break; + case GKYL_FIELD_PEC_WALL: + fld->upper_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, maxwell, app->geom, dir, GKYL_UPPER_EDGE, nghost, maxwell->wall_bc_func, 0 + ); + break; + + case GKYL_FIELD_FUNC: + fld->upper_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, maxwell, app->geom, dir, GKYL_UPPER_EDGE, nghost, bc_upper_func, mom_fld->ctx + ); + break; + + case GKYL_FIELD_COPY: + case GKYL_FIELD_WEDGE: + fld->upper_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, maxwell, app->geom, dir, GKYL_UPPER_EDGE, nghost, bc_copy, 0 + ); + break; + + case GKYL_FIELD_SKIP: + fld->upper_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, maxwell, app->geom, dir, GKYL_UPPER_EDGE, nghost, bc_skip, 0 + ); + break; + + default: + assert(false); + break; } } } @@ -206,8 +206,7 @@ moment_field_init(const struct gkyl_moment *mom, const struct gkyl_moment_field gkyl_array_clear(fld->embed_mask, 1.0); if (maxwell->embed_geo) { - gkyl_wv_embed_geo_new_mask(maxwell->embed_geo, &app->grid, - &app->local, fld->embed_mask); + gkyl_wv_embed_geo_new_mask(maxwell->embed_geo, &app->grid, &app->local, fld->embed_mask); } fld->ext_em = mkarr(false, 6, app->local_ext.volume); @@ -218,20 +217,21 @@ moment_field_init(const struct gkyl_moment *mom, const struct gkyl_moment_field // setup external electromagnetic field if (mom_fld->ext_em) { fld->has_ext_em = true; - // Only set the external field to evolve if a user asks for + // Only set the external field to evolve if a user asks for // dynamic external field and t_ramp_E = 0.0, otherwise // we project the external field once and any variation - // in time is encoded linearly in t_ramp_E. + // in time is encoded linearly in t_ramp_E. if (mom_fld->ext_em_evolve && mom_fld->t_ramp_E == 0.0) { fld->ext_em_evolve = mom_fld->ext_em_evolve; } - fld->ext_em_proj = gkyl_fv_proj_new(&app->grid, 2, GKYL_MOM_APP_NUM_EXT_EM, - mom_fld->ext_em, mom_fld->ext_em_ctx); - } + fld->ext_em_proj = gkyl_fv_proj_new( + &app->grid, 2, GKYL_MOM_APP_NUM_EXT_EM, mom_fld->ext_em, mom_fld->ext_em_ctx + ); + } fld->app_current = mkarr(false, 3, app->local_ext.volume); gkyl_array_clear(fld->app_current, 0.0); - if(mom_fld->use_explicit_em_coupling){ + if (mom_fld->use_explicit_em_coupling) { fld->app_current1 = mkarr(false, 3, app->local_ext.volume); gkyl_array_clear(fld->app_current1, 0.0); fld->app_current2 = mkarr(false, 3, app->local_ext.volume); @@ -241,15 +241,17 @@ moment_field_init(const struct gkyl_moment *mom, const struct gkyl_moment_field fld->app_current_evolve = false; if (mom_fld->app_current) { fld->has_app_current = true; - // Only set the applied current to evolve if a user asks for + // Only set the applied current to evolve if a user asks for // dynamic applied current and t_ramp_curr = 0.0, otherwise // we project the applied current once and any variation - // in time is encoded linearly in t_ramp_curr. - if (mom_fld->app_current_evolve && mom_fld->t_ramp_curr == 0.0) { + // in time is encoded linearly in t_ramp_curr. + if (mom_fld->app_current_evolve && mom_fld->t_ramp_curr == 0.0) { fld->app_current_evolve = mom_fld->app_current_evolve; } - fld->app_current_proj = gkyl_fv_proj_new(&app->grid, 2, GKYL_MOM_APP_NUM_APPLIED_CURRENT, - mom_fld->app_current, mom_fld->app_current_ctx); + fld->app_current_proj = gkyl_fv_proj_new( + &app->grid, 2, GKYL_MOM_APP_NUM_APPLIED_CURRENT, mom_fld->app_current, + mom_fld->app_current_ctx + ); } fld->has_volume_sources = mom_fld->has_volume_sources; @@ -260,7 +262,7 @@ moment_field_init(const struct gkyl_moment *mom, const struct gkyl_moment_field // allocate buffer for applying BCs (used for periodic BCs) long buff_sz = 0; // compute buffer size needed - for (int d=0; dndim; ++d) { + for (int d = 0; d < app->ndim; ++d) { long vol = app->skin_ghost.lower_skin[d].volume; buff_sz = buff_sz > vol ? buff_sz : vol; } @@ -273,49 +275,55 @@ moment_field_init(const struct gkyl_moment *mom, const struct gkyl_moment_field } // apply BCs to EM field -void -moment_field_apply_bc(gkyl_moment_app *app, double tcurr, - const struct moment_field *field, struct gkyl_array *f) +void moment_field_apply_bc( + gkyl_moment_app *app, double tcurr, const struct moment_field *field, struct gkyl_array *f +) { struct timespec wst = gkyl_wall_clock(); - + int num_periodic_dir = app->num_periodic_dir, ndim = app->ndim, is_non_periodic[3] = {1, 1, 1}; - - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int d=0; dlower_bct[d] != GKYL_FIELD_WEDGE) + if (field->lower_bct[d] != GKYL_FIELD_WEDGE) { gkyl_wv_apply_bc_advance(field->lower_bc[d], tcurr, &app->local, f); - if (field->upper_bct[d] != GKYL_FIELD_WEDGE) + } + if (field->upper_bct[d] != GKYL_FIELD_WEDGE) { gkyl_wv_apply_bc_advance(field->upper_bc[d], tcurr, &app->local, f); + } // wedge BCs for upper/lower must be handled in one shot - if (field->lower_bct[d] == GKYL_FIELD_WEDGE) - moment_apply_wedge_bc(app, tcurr, &app->local, - field->bc_buffer, d, field->lower_bc[d], field->upper_bc[d], f); + if (field->lower_bct[d] == GKYL_FIELD_WEDGE) { + moment_apply_wedge_bc( + app, tcurr, &app->local, field->bc_buffer, d, field->lower_bc[d], field->upper_bc[d], f + ); + } } + } // sync interior ghost cells gkyl_comm_array_sync(app->comm, &app->local, &app->local_ext, f); // sync periodic ghost cells - gkyl_comm_array_per_sync(app->comm, &app->local, &app->local_ext, num_periodic_dir, - app->periodic_dirs, f); + gkyl_comm_array_per_sync( + app->comm, &app->local, &app->local_ext, num_periodic_dir, app->periodic_dirs, f + ); - app->stat.field_bc_tm += gkyl_time_diff_now_sec(wst); + app->stat.field_bc_tm += gkyl_time_diff_now_sec(wst); } -double -moment_field_max_dt(const gkyl_moment_app *app, const struct moment_field *fld) +double moment_field_max_dt(const gkyl_moment_app *app, const struct moment_field *fld) { double max_dt = DBL_MAX; - if (fld->scheme_type == GKYL_MOMENT_WAVE_PROP) { - for (int d=0; dndim; ++d) + if (fld->scheme_type == GKYL_MOMENT_WAVE_PROP) { + for (int d = 0; d < app->ndim; ++d) { max_dt = fmin(max_dt, gkyl_wave_prop_max_dt(fld->slvr[d], &app->local, fld->f[0])); - } - else if (fld->scheme_type == GKYL_MOMENT_MP || fld->scheme_type == GKYL_MOMENT_KEP) { + } + } else if (fld->scheme_type == GKYL_MOMENT_MP || fld->scheme_type == GKYL_MOMENT_KEP) { max_dt = fmin(max_dt, gkyl_mp_scheme_max_dt(fld->mp_slvr, &app->local, fld->f0)); } return max_dt; @@ -324,77 +332,77 @@ moment_field_max_dt(const gkyl_moment_app *app, const struct moment_field *fld) // update solution: initial solution is in fld->f[0] and updated // solution in fld->f[ndim] struct gkyl_update_status -moment_field_update(gkyl_moment_app *app, - const struct moment_field *fld, double tcurr, double dt) +moment_field_update(gkyl_moment_app *app, const struct moment_field *fld, double tcurr, double dt) { int ndim = fld->ndim; - struct gkyl_wave_prop_status stat = { true, DBL_MAX }; + struct gkyl_wave_prop_status stat = {true, DBL_MAX}; if (!fld->is_static) { - for (int d=0; dslvr[d], tcurr, dt, &app->local, fld->embed_mask, fld->f[d], fld->f[d+1]); + stat = gkyl_wave_prop_advance( + fld->slvr[d], tcurr, dt, &app->local, fld->embed_mask, fld->f[d], fld->f[d + 1] + ); - if (!stat.success) - return (struct gkyl_update_status) { - .success = false, - .dt_suggested = stat.dt_suggested - }; + if (!stat.success) { + return (struct gkyl_update_status){.success = false, .dt_suggested = stat.dt_suggested}; + } // apply BC - moment_field_apply_bc(app, tcurr, fld, fld->f[d+1]); + moment_field_apply_bc(app, tcurr, fld, fld->f[d + 1]); } } - return (struct gkyl_update_status) { - .success = true, - .dt_suggested = stat.dt_suggested - }; + return (struct gkyl_update_status){.success = true, .dt_suggested = stat.dt_suggested}; } // Compute RHS of EM equations -double -moment_field_rhs(gkyl_moment_app *app, struct moment_field *fld, - const struct gkyl_array *fin, struct gkyl_array *rhs) +double moment_field_rhs( + gkyl_moment_app *app, struct moment_field *fld, const struct gkyl_array *fin, + struct gkyl_array *rhs +) { struct timespec tm = gkyl_wall_clock(); - + gkyl_array_clear(fld->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); - gkyl_mp_scheme_advance(fld->mp_slvr, &app->local, fin, - app->ql, app->qr, app->amdq, app->apdq, - fld->cflrate, fld->embed_mask, rhs); + gkyl_mp_scheme_advance( + fld->mp_slvr, &app->local, fin, app->ql, app->qr, app->amdq, app->apdq, fld->cflrate, + fld->embed_mask, rhs + ); double omegaCfl[1]; gkyl_array_reduce_range(omegaCfl, fld->cflrate, GKYL_MAX, &(app->local)); app->stat.field_rhs_tm += gkyl_time_diff_now_sec(tm); - - return app->cfl/omegaCfl[0]; + + return app->cfl / omegaCfl[0]; } // free field -void -moment_field_release(const struct moment_field *fld) +void moment_field_release(const struct moment_field *fld) { gkyl_wv_eqn_release(fld->maxwell); - - for (int d=0; dndim; ++d) { - if (fld->lower_bc[d]) + + for (int d = 0; d < fld->ndim; ++d) { + if (fld->lower_bc[d]) { gkyl_wv_apply_bc_release(fld->lower_bc[d]); - if (fld->upper_bc[d]) + } + if (fld->upper_bc[d]) { gkyl_wv_apply_bc_release(fld->upper_bc[d]); + } } if (fld->scheme_type == GKYL_MOMENT_WAVE_PROP) { - for (int d=0; dndim; ++d) + for (int d = 0; d < fld->ndim; ++d) { gkyl_wave_prop_release(fld->slvr[d]); - + } + gkyl_array_release(fld->fdup); - for (int d=0; dndim+1; ++d) + for (int d = 0; d < fld->ndim + 1; ++d) { gkyl_array_release(fld->f[d]); - } - else if (fld->scheme_type == GKYL_MOMENT_MP || fld->scheme_type == GKYL_MOMENT_KEP) { + } + } else if (fld->scheme_type == GKYL_MOMENT_MP || fld->scheme_type == GKYL_MOMENT_KEP) { gkyl_mp_scheme_release(fld->mp_slvr); gkyl_array_release(fld->f0); gkyl_array_release(fld->f1); @@ -405,10 +413,10 @@ moment_field_release(const struct moment_field *fld) gkyl_array_release(fld->ext_em); if (fld->has_ext_em) { gkyl_fv_proj_release(fld->ext_em_proj); - } + } gkyl_array_release(fld->app_current); - if(fld->use_explicit_em_coupling) { + if (fld->use_explicit_em_coupling) { gkyl_array_release(fld->app_current1); gkyl_array_release(fld->app_current2); } @@ -421,4 +429,3 @@ moment_field_release(const struct moment_field *fld) gkyl_dynvec_release(fld->integ_energy); gkyl_array_release(fld->bc_buffer); } - diff --git a/moments/apps/mom_priv.c b/moments/apps/mom_priv.c index 94308c9123..1603e1d037 100644 --- a/moments/apps/mom_priv.c +++ b/moments/apps/mom_priv.c @@ -2,13 +2,16 @@ // Compute the nc intergated values over the update_rgn, storing the // result in the integ_q -void -calc_integ_quant(const struct gkyl_wv_eqn *eqn, double vol, const struct gkyl_array *q, const struct gkyl_wave_geom *geom, - struct gkyl_range update_rng, double *integ_q) +void calc_integ_quant( + const struct gkyl_wv_eqn *eqn, double vol, const struct gkyl_array *q, + const struct gkyl_wave_geom *geom, struct gkyl_range update_rng, double *integ_q +) { int nc = eqn->num_diag; double integ_out[nc]; - for (int i=0; icons_to_diag(eqn, qcell, integ_out); - for (int i=0; ikappa*integ_out[i]; + for (int i = 0; i < nc; ++i) { + integ_q[i] += vol * cg->kappa * integ_out[i]; + } } } // Check if nan occurs in the array, returning true if they do and // false otherwise -bool -check_for_nans(const struct gkyl_array *q, struct gkyl_range update_rng) +bool check_for_nans(const struct gkyl_array *q, struct gkyl_range update_rng) { struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &update_rng); while (gkyl_range_iter_next(&iter)) { const double *qcell = gkyl_array_cfetch(q, gkyl_range_idx(&update_rng, iter.idx)); - for (int i=0; incomp; ++i) - if (isnan(qcell[i])) return true; + for (int i = 0; i < q->ncomp; ++i) { + if (isnan(qcell[i])) { + return true; + } + } } return false; } -void -moment_apply_periodic_corner_sync_2d(const gkyl_moment_app *app, struct gkyl_array *f) +void moment_apply_periodic_corner_sync_2d(const gkyl_moment_app *app, struct gkyl_array *f) { long idx_src, idx_dest; double *out; const double *inp; if (app->ndim == 2) { // LL skin cell -> UU ghost cell - idx_src = gkyl_range_idx(&app->local, (int[]) {app->local.lower[0],app->local.lower[1]}); - idx_dest = gkyl_range_idx(&app->local_ext, (int[]) {app->local.upper[0]+1,app->local.upper[1]+1}); + idx_src = gkyl_range_idx(&app->local, (int[]){app->local.lower[0], app->local.lower[1]}); + idx_dest = + gkyl_range_idx(&app->local_ext, (int[]){app->local.upper[0] + 1, app->local.upper[1] + 1}); - out = (double*) gkyl_array_fetch(f, idx_dest); - inp = (const double*) gkyl_array_cfetch(f, idx_src); + out = (double *)gkyl_array_fetch(f, idx_dest); + inp = (const double *)gkyl_array_cfetch(f, idx_src); gkyl_copy_double_arr(f->ncomp, inp, out); // LU skin cell -> UL ghost cell - idx_src = gkyl_range_idx(&app->local, (int[]) {app->local.lower[0],app->local.upper[1]}); - idx_dest = gkyl_range_idx(&app->local_ext, (int[]) {app->local.upper[0]+1,app->local.lower[1]-1}); + idx_src = gkyl_range_idx(&app->local, (int[]){app->local.lower[0], app->local.upper[1]}); + idx_dest = + gkyl_range_idx(&app->local_ext, (int[]){app->local.upper[0] + 1, app->local.lower[1] - 1}); - out = (double*) gkyl_array_fetch(f, idx_dest); - inp = (const double*) gkyl_array_cfetch(f, idx_src); + out = (double *)gkyl_array_fetch(f, idx_dest); + inp = (const double *)gkyl_array_cfetch(f, idx_src); gkyl_copy_double_arr(f->ncomp, inp, out); // UL skin cell -> LU ghost cell - idx_src = gkyl_range_idx(&app->local, (int[]) {app->local.upper[0],app->local.lower[1]}); - idx_dest = gkyl_range_idx(&app->local_ext, (int[]) {app->local.lower[0]-1,app->local.upper[1]+1}); + idx_src = gkyl_range_idx(&app->local, (int[]){app->local.upper[0], app->local.lower[1]}); + idx_dest = + gkyl_range_idx(&app->local_ext, (int[]){app->local.lower[0] - 1, app->local.upper[1] + 1}); - out = (double*) gkyl_array_fetch(f, idx_dest); - inp = (const double*) gkyl_array_cfetch(f, idx_src); + out = (double *)gkyl_array_fetch(f, idx_dest); + inp = (const double *)gkyl_array_cfetch(f, idx_src); gkyl_copy_double_arr(f->ncomp, inp, out); // UU skin cell -> LL ghost cell - idx_src = gkyl_range_idx(&app->local, (int[]) {app->local.upper[0],app->local.upper[1]}); - idx_dest = gkyl_range_idx(&app->local_ext, (int[]) {app->local.lower[0]-1,app->local.lower[1]-1}); + idx_src = gkyl_range_idx(&app->local, (int[]){app->local.upper[0], app->local.upper[1]}); + idx_dest = + gkyl_range_idx(&app->local_ext, (int[]){app->local.lower[0] - 1, app->local.lower[1] - 1}); - out = (double*) gkyl_array_fetch(f, idx_dest); - inp = (const double*) gkyl_array_cfetch(f, idx_src); + out = (double *)gkyl_array_fetch(f, idx_dest); + inp = (const double *)gkyl_array_cfetch(f, idx_src); gkyl_copy_double_arr(f->ncomp, inp, out); } } // apply wedge BCs -void -moment_apply_wedge_bc(const gkyl_moment_app *app, double tcurr, - const struct gkyl_range *update_rng, struct gkyl_array *bc_buffer, - int dir, const struct gkyl_wv_apply_bc *lo, const struct gkyl_wv_apply_bc *up, - struct gkyl_array *f) +void moment_apply_wedge_bc( + const gkyl_moment_app *app, double tcurr, const struct gkyl_range *update_rng, + struct gkyl_array *bc_buffer, int dir, const struct gkyl_wv_apply_bc *lo, + const struct gkyl_wv_apply_bc *up, struct gkyl_array *f +) { gkyl_wv_apply_bc_to_buff(lo, tcurr, update_rng, f, bc_buffer->data); gkyl_array_copy_from_buffer(f, bc_buffer->data, &(app->skin_ghost.upper_ghost[dir])); @@ -90,4 +100,3 @@ moment_apply_wedge_bc(const gkyl_moment_app *app, double tcurr, gkyl_wv_apply_bc_to_buff(up, tcurr, update_rng, f, bc_buffer->data); gkyl_array_copy_from_buffer(f, bc_buffer->data, &(app->skin_ghost.lower_ghost[dir])); } - diff --git a/moments/apps/mom_species.c b/moments/apps/mom_species.c index d2b81cac56..4567925f2a 100644 --- a/moments/apps/mom_species.c +++ b/moments/apps/mom_species.c @@ -3,15 +3,16 @@ #include // initialize species -void -moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_species *mom_sp, - struct gkyl_moment_app *app, struct moment_species *sp) +void moment_species_init( + const struct gkyl_moment *mom, const struct gkyl_moment_species *mom_sp, + struct gkyl_moment_app *app, struct moment_species *sp +) { sp->ndim = mom->ndim; strcpy(sp->name, mom_sp->name); sp->charge = mom_sp->charge; sp->mass = mom_sp->mass; - sp->is_static = mom_sp->is_static; + sp->is_static = mom_sp->is_static; sp->ctx = mom_sp->ctx; sp->init = mom_sp->init; @@ -21,17 +22,17 @@ moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_spec // Do we need to update source terms for this fluid? // Sources can be electromagnetic fields, closure-related, applied accelerations - // volume expansion, friction, reactivity, etc. - sp->update_sources = false; + // volume expansion, friction, reactivity, etc. + sp->update_sources = false; if (app->has_field) { - sp->update_sources = true; + sp->update_sources = true; } sp->k0 = 0.0; sp->has_grad_closure = false; sp->has_nn_closure = false; if (mom_sp->equation->type == GKYL_EQN_TEN_MOMENT) { - sp->update_sources = true; + sp->update_sources = true; sp->k0 = gkyl_wv_ten_moment_k0(mom_sp->equation); sp->has_grad_closure = gkyl_wv_ten_moment_use_grad_closure(mom_sp->equation); sp->has_nn_closure = gkyl_wv_ten_moment_use_nn_closure(mom_sp->equation); @@ -41,27 +42,26 @@ moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_spec // check if we are running with Braginskii transport and fetch Braginskii type if (app->has_braginskii) { - sp->update_sources = true; + sp->update_sources = true; sp->type_brag = mom_sp->type_brag; } if (mom_sp->has_friction) { - sp->update_sources = true; + sp->update_sources = true; sp->has_friction = true; sp->use_explicit_friction = mom_sp->use_explicit_friction; sp->friction_Z = mom_sp->friction_Z; sp->friction_T_elc = mom_sp->friction_T_elc; sp->friction_Lambda_ee = mom_sp->friction_Lambda_ee; - } - else { + } else { sp->has_friction = false; sp->use_explicit_friction = false; } sp->has_volume_sources = false; if (mom_sp->has_volume_sources) { - sp->update_sources = true; + sp->update_sources = true; sp->has_volume_sources = true; sp->volume_gas_gamma = mom_sp->volume_gas_gamma; @@ -71,7 +71,7 @@ moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_spec sp->has_reactivity = false; if (mom_sp->has_reactivity) { - sp->update_sources = true; + sp->update_sources = true; sp->has_reactivity = true; sp->reactivity_gas_gamma = mom_sp->reactivity_gas_gamma; @@ -83,7 +83,7 @@ moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_spec sp->has_einstein_medium = false; if (mom_sp->has_einstein_medium) { - sp->update_sources = true; + sp->update_sources = true; sp->has_einstein_medium = true; sp->medium_gas_gamma = mom_sp->medium_gas_gamma; @@ -92,7 +92,7 @@ moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_spec sp->has_gr_ultra_rel = false; if (mom_sp->has_gr_ultra_rel) { - sp->update_sources = true; + sp->update_sources = true; sp->has_gr_ultra_rel = true; sp->gr_ultra_rel_gas_gamma = mom_sp->gr_ultra_rel_gas_gamma; @@ -100,7 +100,7 @@ moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_spec sp->has_gr_euler = false; if (mom_sp->has_gr_euler) { - sp->update_sources = true; + sp->update_sources = true; sp->has_gr_euler = true; sp->gr_euler_gas_gamma = mom_sp->gr_euler_gas_gamma; @@ -108,7 +108,7 @@ moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_spec sp->has_gr_twofluid = false; if (mom_sp->has_gr_twofluid) { - sp->update_sources = true; + sp->update_sources = true; sp->has_gr_twofluid = true; sp->gr_twofluid_mass_elc = mom_sp->gr_twofluid_mass_elc; @@ -135,14 +135,17 @@ moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_spec sp->update_sources = true; sp->has_vacuum_einstein_conformal = true; - sp->vacuum_einstein_conformal_excision_threshold = mom_sp->vacuum_einstein_conformal_excision_threshold; - sp->vacuum_einstein_conformal_spacetime_slicing = mom_sp->vacuum_einstein_conformal_spacetime_slicing; - sp->vacuum_einstein_conformal_spacetime_evolution = mom_sp->vacuum_einstein_conformal_spacetime_evolution; + sp->vacuum_einstein_conformal_excision_threshold = + mom_sp->vacuum_einstein_conformal_excision_threshold; + sp->vacuum_einstein_conformal_spacetime_slicing = + mom_sp->vacuum_einstein_conformal_spacetime_slicing; + sp->vacuum_einstein_conformal_spacetime_evolution = + mom_sp->vacuum_einstein_conformal_spacetime_evolution; } - + sp->has_gr_mhd = false; if (mom_sp->has_gr_mhd) { - sp->update_sources = true; + sp->update_sources = true; sp->has_gr_mhd = true; sp->gr_mhd_gas_gamma = mom_sp->gr_mhd_gas_gamma; @@ -151,200 +154,207 @@ moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_spec sp->scheme_type = mom->scheme_type; // choose default limiter - enum gkyl_wave_limiter limiter = - mom_sp->limiter == 0 ? GKYL_MONOTONIZED_CENTERED : mom_sp->limiter; + enum gkyl_wave_limiter limiter = mom_sp->limiter == 0 ? GKYL_MONOTONIZED_CENTERED : + mom_sp->limiter; - enum gkyl_wave_split_type split_type = mom_sp->split_type; + enum gkyl_wave_split_type split_type = mom_sp->split_type; int ndim = mom->ndim; - int meqn = sp->num_equations; + int meqn = sp->num_equations; if (sp->scheme_type == GKYL_MOMENT_WAVE_PROP) { // create updaters for each directional update - for (int d=0; dslvr[d] = gkyl_wave_prop_new( &(struct gkyl_wave_prop_inp) { - .grid = &app->grid, - .equation = mom_sp->equation, - .split_type = split_type, - .limiter = limiter, - .num_up_dirs = app->is_dir_skipped[d] ? 0 : 1, - .force_low_order_flux = mom_sp->force_low_order_flux, - .check_inv_domain = true, - .update_dirs = { d }, - .cfl = app->cfl, - .geom = app->geom, - .comm = app->comm - } - ); - + for (int d = 0; d < ndim; ++d) { + sp->slvr[d] = gkyl_wave_prop_new(&(struct gkyl_wave_prop_inp + ){.grid = &app->grid, + .equation = mom_sp->equation, + .split_type = split_type, + .limiter = limiter, + .num_up_dirs = app->is_dir_skipped[d] ? 0 : 1, + .force_low_order_flux = mom_sp->force_low_order_flux, + .check_inv_domain = true, + .update_dirs = {d}, + .cfl = app->cfl, + .geom = app->geom, + .comm = app->comm}); + } + sp->fdup = mkarr(false, meqn, app->local_ext.volume); // allocate arrays - for (int d=0; df[d] = mkarr(false, meqn, app->local_ext.volume); - + } + // set current solution so ICs and IO work properly sp->fcurr = sp->f[0]; - } - else if ( sp->scheme_type == GKYL_MOMENT_MP || sp->scheme_type == GKYL_MOMENT_KEP ) { + } else if (sp->scheme_type == GKYL_MOMENT_MP || sp->scheme_type == GKYL_MOMENT_KEP) { // determine directions to update - int num_up_dirs = 0, update_dirs[GKYL_MAX_CDIM] = { 0 }; - for (int d=0; dis_dir_skipped[d]) { update_dirs[num_up_dirs] = d; num_up_dirs += 1; } + } - if (sp->scheme_type == GKYL_MOMENT_MP) + if (sp->scheme_type == GKYL_MOMENT_MP) { // single MP updater updates all directions - sp->mp_slvr = gkyl_mp_scheme_new( &(struct gkyl_mp_scheme_inp) { - .grid = &app->grid, - .equation = mom_sp->equation, - .mp_recon = app->mp_recon, - .skip_mp_limiter = mom->skip_mp_limiter, - .num_up_dirs = num_up_dirs, - .update_dirs = { update_dirs[0], update_dirs[1], update_dirs[2] } , - .cfl = app->cfl, - .geom = app->geom, - } - ); - else + sp->mp_slvr = gkyl_mp_scheme_new(&(struct gkyl_mp_scheme_inp + ){.grid = &app->grid, + .equation = mom_sp->equation, + .mp_recon = app->mp_recon, + .skip_mp_limiter = mom->skip_mp_limiter, + .num_up_dirs = num_up_dirs, + .update_dirs = {update_dirs[0], update_dirs[1], update_dirs[2]}, + .cfl = app->cfl, + .geom = app->geom}); + } else { // single KEP updater updates all directions - sp->kep_slvr = gkyl_kep_scheme_new( &(struct gkyl_kep_scheme_inp) { - .grid = &app->grid, - .equation = mom_sp->equation, - .use_hybrid_flux = app->use_hybrid_flux_kep, - .num_up_dirs = num_up_dirs, - .update_dirs = { update_dirs[0], update_dirs[1], update_dirs[2] } , - .cfl = app->cfl, - .geom = app->geom, - } - ); - + sp->kep_slvr = gkyl_kep_scheme_new(&(struct gkyl_kep_scheme_inp + ){.grid = &app->grid, + .equation = mom_sp->equation, + .use_hybrid_flux = app->use_hybrid_flux_kep, + .num_up_dirs = num_up_dirs, + .update_dirs = {update_dirs[0], update_dirs[1], update_dirs[2]}, + .cfl = app->cfl, + .geom = app->geom}); + } + // allocate arrays sp->f0 = mkarr(false, meqn, app->local_ext.volume); sp->f1 = mkarr(false, meqn, app->local_ext.volume); sp->fnew = mkarr(false, meqn, app->local_ext.volume); sp->cflrate = mkarr(false, 1, app->local_ext.volume); sp->alpha = mkarr(false, 1, app->local_ext.volume); - + // set current solution so ICs and IO work properly sp->fcurr = sp->f0; } // determine which directions are not periodic int num_periodic_dir = app->num_periodic_dir, is_np[3] = {1, 1, 1}; - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { sp->lower_bc[i] = 0; sp->upper_bc[i] = 0; } int nghost[3] = {2, 2, 2}; - for (int dir=0; dirndim; ++dir) { + for (int dir = 0; dir < app->ndim; ++dir) { if (is_np[dir]) { const enum gkyl_species_bc_type *bc; - if (dir == 0) + if (dir == 0) { bc = mom_sp->bcx; - else if (dir == 1) + } else if (dir == 1) { bc = mom_sp->bcy; - else + } else { bc = mom_sp->bcz; + } wv_bc_func_t bc_lower_func; - if (dir == 0) + if (dir == 0) { bc_lower_func = mom_sp->bcx_func[0]; - else if (dir == 1) + } else if (dir == 1) { bc_lower_func = mom_sp->bcy_func[0]; - else + } else { bc_lower_func = mom_sp->bcz_func[0]; + } wv_bc_func_t bc_upper_func; - if (dir == 0) + if (dir == 0) { bc_upper_func = mom_sp->bcx_func[1]; - else if (dir == 1) + } else if (dir == 1) { bc_upper_func = mom_sp->bcy_func[1]; - else + } else { bc_upper_func = mom_sp->bcz_func[1]; + } sp->lower_bct[dir] = bc[0]; sp->upper_bct[dir] = bc[1]; // lower BCs switch (bc[0]) { - case GKYL_SPECIES_REFLECT: - sp->lower_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, mom_sp->equation, app->geom, dir, GKYL_LOWER_EDGE, nghost, - mom_sp->equation->wall_bc_func, 0); - break; - - case GKYL_SPECIES_NO_SLIP: - sp->lower_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, mom_sp->equation, app->geom, dir, GKYL_LOWER_EDGE, nghost, - mom_sp->equation->no_slip_bc_func, 0); - break; - - case GKYL_SPECIES_FUNC: - sp->lower_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, mom_sp->equation, app->geom, dir, GKYL_LOWER_EDGE, nghost, - bc_lower_func, mom_sp->ctx); - break; - - case GKYL_SPECIES_COPY: - case GKYL_SPECIES_WEDGE: // wedge also uses bc_copy - sp->lower_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, mom_sp->equation, app->geom, dir, GKYL_LOWER_EDGE, nghost, - bc_copy, 0); - break; - - case GKYL_SPECIES_SKIP: - sp->lower_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, mom_sp->equation, app->geom, dir, GKYL_LOWER_EDGE, nghost, - bc_skip, 0); - break; - - default: - assert(false); - break; + case GKYL_SPECIES_REFLECT: + sp->lower_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, mom_sp->equation, app->geom, dir, GKYL_LOWER_EDGE, nghost, + mom_sp->equation->wall_bc_func, 0 + ); + break; + + case GKYL_SPECIES_NO_SLIP: + sp->lower_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, mom_sp->equation, app->geom, dir, GKYL_LOWER_EDGE, nghost, + mom_sp->equation->no_slip_bc_func, 0 + ); + break; + + case GKYL_SPECIES_FUNC: + sp->lower_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, mom_sp->equation, app->geom, dir, GKYL_LOWER_EDGE, nghost, bc_lower_func, + mom_sp->ctx + ); + break; + + case GKYL_SPECIES_COPY: + case GKYL_SPECIES_WEDGE: // wedge also uses bc_copy + sp->lower_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, mom_sp->equation, app->geom, dir, GKYL_LOWER_EDGE, nghost, bc_copy, 0 + ); + break; + + case GKYL_SPECIES_SKIP: + sp->lower_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, mom_sp->equation, app->geom, dir, GKYL_LOWER_EDGE, nghost, bc_skip, 0 + ); + break; + + default: + assert(false); + break; } - + // upper BCs switch (bc[1]) { - case GKYL_SPECIES_REFLECT: - sp->upper_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, mom_sp->equation, app->geom, dir, GKYL_UPPER_EDGE, nghost, - mom_sp->equation->wall_bc_func, 0); - break; - - case GKYL_SPECIES_NO_SLIP: - sp->upper_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, mom_sp->equation, app->geom, dir, GKYL_UPPER_EDGE, nghost, - mom_sp->equation->no_slip_bc_func, 0); - break; - - case GKYL_SPECIES_FUNC: - sp->upper_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, mom_sp->equation, app->geom, dir, GKYL_UPPER_EDGE, nghost, - bc_upper_func, mom_sp->ctx); - break; - - case GKYL_SPECIES_COPY: - case GKYL_SPECIES_WEDGE: - sp->upper_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, mom_sp->equation, app->geom, dir, GKYL_UPPER_EDGE, nghost, - bc_copy, 0); - break; - - case GKYL_SPECIES_SKIP: - sp->upper_bc[dir] = gkyl_wv_apply_bc_new( - &app->grid, mom_sp->equation, app->geom, dir, GKYL_UPPER_EDGE, nghost, - bc_skip, 0); - break; - - default: - assert(false); - break; + case GKYL_SPECIES_REFLECT: + sp->upper_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, mom_sp->equation, app->geom, dir, GKYL_UPPER_EDGE, nghost, + mom_sp->equation->wall_bc_func, 0 + ); + break; + + case GKYL_SPECIES_NO_SLIP: + sp->upper_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, mom_sp->equation, app->geom, dir, GKYL_UPPER_EDGE, nghost, + mom_sp->equation->no_slip_bc_func, 0 + ); + break; + + case GKYL_SPECIES_FUNC: + sp->upper_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, mom_sp->equation, app->geom, dir, GKYL_UPPER_EDGE, nghost, bc_upper_func, + mom_sp->ctx + ); + break; + + case GKYL_SPECIES_COPY: + case GKYL_SPECIES_WEDGE: + sp->upper_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, mom_sp->equation, app->geom, dir, GKYL_UPPER_EDGE, nghost, bc_copy, 0 + ); + break; + + case GKYL_SPECIES_SKIP: + sp->upper_bc[dir] = gkyl_wv_apply_bc_new( + &app->grid, mom_sp->equation, app->geom, dir, GKYL_UPPER_EDGE, nghost, bc_skip, 0 + ); + break; + + default: + assert(false); + break; } } } @@ -355,137 +365,143 @@ moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_spec sp->has_app_accel = false; sp->app_accel_evolve = false; if (mom_sp->app_accel) { - sp->update_sources = true; + sp->update_sources = true; sp->has_app_accel = true; if (mom_sp->app_accel_evolve) { sp->app_accel_evolve = mom_sp->app_accel_evolve; } - sp->app_accel_proj = gkyl_fv_proj_new(&app->grid, 2, GKYL_MOM_APP_NUM_APPLIED_ACCELERATION, - mom_sp->app_accel, mom_sp->app_accel_ctx); + sp->app_accel_proj = gkyl_fv_proj_new( + &app->grid, 2, GKYL_MOM_APP_NUM_APPLIED_ACCELERATION, mom_sp->app_accel, mom_sp->app_accel_ctx + ); } sp->embed_mask = mkarr(false, 1, app->local_ext.volume); gkyl_array_clear(sp->embed_mask, 1.0); if (mom_sp->equation->embed_geo) { - gkyl_wv_embed_geo_new_mask(mom_sp->equation->embed_geo, &app->grid, - &app->local, sp->embed_mask); + gkyl_wv_embed_geo_new_mask(mom_sp->equation->embed_geo, &app->grid, &app->local, sp->embed_mask); } sp->nT_source = mkarr(false, 2, app->local_ext.volume); sp->nT_source_is_set = false; sp->proj_nT_source = 0; if (mom_sp->nT_source_func) { - sp->update_sources = true; + sp->update_sources = true; void *ctx = sp->ctx; - if (mom_sp->nT_source_ctx) + if (mom_sp->nT_source_ctx) { ctx = mom_sp->nT_source_ctx; - - sp->proj_nT_source = gkyl_fv_proj_new(&app->grid, 2, GKYL_MOM_APP_NUM_NT_SOURCE, - mom_sp->nT_source_func, ctx); + } + + sp->proj_nT_source = + gkyl_fv_proj_new(&app->grid, 2, GKYL_MOM_APP_NUM_NT_SOURCE, mom_sp->nT_source_func, ctx); sp->nT_source_set_only_once = mom_sp->nT_source_set_only_once; } // allocate buffer for applying BCs (used for periodic BCs) long buff_sz = 0; // compute buffer size needed - for (int d=0; dndim; ++d) { + for (int d = 0; d < app->ndim; ++d) { long vol = app->skin_ghost.lower_skin[d].volume; buff_sz = buff_sz > vol ? buff_sz : vol; } sp->bc_buffer = mkarr(false, meqn, buff_sz); - if (mom_sp->equation->type == GKYL_EQN_EULER) + if (mom_sp->equation->type == GKYL_EQN_EULER) { sp->integ_q = gkyl_dynvec_new(GKYL_DOUBLE, 6); // KE and PE are stored independently - else + } else { sp->integ_q = gkyl_dynvec_new(GKYL_DOUBLE, meqn); - + } + sp->is_first_q_write_call = true; } // apply BCs to species -void -moment_species_apply_bc(gkyl_moment_app *app, double tcurr, - const struct moment_species *sp, struct gkyl_array *f) +void moment_species_apply_bc( + gkyl_moment_app *app, double tcurr, const struct moment_species *sp, struct gkyl_array *f +) { struct timespec wst = gkyl_wall_clock(); - + int num_periodic_dir = app->num_periodic_dir, ndim = app->ndim, is_non_periodic[3] = {1, 1, 1}; - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int d=0; dlower_bct[d] != GKYL_SPECIES_WEDGE) + if (sp->lower_bct[d] != GKYL_SPECIES_WEDGE) { gkyl_wv_apply_bc_advance(sp->lower_bc[d], tcurr, &app->local, f); - if (sp->upper_bct[d] != GKYL_SPECIES_WEDGE) + } + if (sp->upper_bct[d] != GKYL_SPECIES_WEDGE) { gkyl_wv_apply_bc_advance(sp->upper_bc[d], tcurr, &app->local, f); + } // wedge BCs for upper/lower must be handled in one shot - if (sp->lower_bct[d] == GKYL_SPECIES_WEDGE) - moment_apply_wedge_bc(app, tcurr, &app->local, - sp->bc_buffer, d, sp->lower_bc[d], sp->upper_bc[d], f); + if (sp->lower_bct[d] == GKYL_SPECIES_WEDGE) { + moment_apply_wedge_bc( + app, tcurr, &app->local, sp->bc_buffer, d, sp->lower_bc[d], sp->upper_bc[d], f + ); + } } + } // sync interior ghost cells gkyl_comm_array_sync(app->comm, &app->local, &app->local_ext, f); // sync periodic ghost cells - gkyl_comm_array_per_sync(app->comm, &app->local, &app->local_ext, num_periodic_dir, - app->periodic_dirs, f); + gkyl_comm_array_per_sync( + app->comm, &app->local, &app->local_ext, num_periodic_dir, app->periodic_dirs, f + ); app->stat.species_bc_tm += gkyl_time_diff_now_sec(wst); } // maximum stable time-step -double -moment_species_max_dt(const gkyl_moment_app *app, const struct moment_species *sp) +double moment_species_max_dt(const gkyl_moment_app *app, const struct moment_species *sp) { double max_dt = DBL_MAX; if (sp->scheme_type == GKYL_MOMENT_WAVE_PROP) { - for (int d=0; dndim; ++d) + for (int d = 0; d < app->ndim; ++d) { max_dt = fmin(max_dt, gkyl_wave_prop_max_dt(sp->slvr[d], &app->local, sp->f[0])); - } - else if (sp->scheme_type == GKYL_MOMENT_MP) { + } + } else if (sp->scheme_type == GKYL_MOMENT_MP) { max_dt = fmin(max_dt, gkyl_mp_scheme_max_dt(sp->mp_slvr, &app->local, sp->f0)); - } - else if (sp->scheme_type == GKYL_MOMENT_KEP) { + } else if (sp->scheme_type == GKYL_MOMENT_KEP) { max_dt = fmin(max_dt, gkyl_kep_scheme_max_dt(sp->kep_slvr, &app->local, sp->f0)); - } + } return max_dt; } // update solution: initial solution is in sp->f[0] and updated // solution in sp->f[ndim] struct gkyl_update_status -moment_species_update(gkyl_moment_app *app, - struct moment_species *sp, double tcurr, double dt) +moment_species_update(gkyl_moment_app *app, struct moment_species *sp, double tcurr, double dt) { int ndim = sp->ndim; double dt_suggested = DBL_MAX; double max_speed = 0.0; struct gkyl_wave_prop_status stat; - for (int d=0; dslvr[d], tcurr, dt, &app->local, sp->embed_mask, sp->f[d], sp->f[d+1]); + for (int d = 0; d < ndim; ++d) { + stat = gkyl_wave_prop_advance( + sp->slvr[d], tcurr, dt, &app->local, sp->embed_mask, sp->f[d], sp->f[d + 1] + ); double my_max_speed = stat.max_speed; max_speed = max_speed > my_max_speed ? max_speed : my_max_speed; - if (!stat.success) - return (struct gkyl_update_status) { - .success = false, - .dt_suggested = stat.dt_suggested - }; - + if (!stat.success) { + return (struct gkyl_update_status){.success = false, .dt_suggested = stat.dt_suggested}; + } + dt_suggested = fmin(dt_suggested, stat.dt_suggested); - moment_species_apply_bc(app, tcurr, sp, sp->f[d+1]); + moment_species_apply_bc(app, tcurr, sp, sp->f[d + 1]); } - for (int d=0; dequation; - if (eqn->type==GKYL_EQN_MHD) { + if (eqn->type == GKYL_EQN_MHD) { gkyl_wv_mhd_set_glm_ch(eqn, max_speed); } } @@ -494,66 +510,69 @@ moment_species_update(gkyl_moment_app *app, // gkyl_mhd_src_set_glm_ch(app->mhd_source.slvr, max_speed); } - return (struct gkyl_update_status) { - .success = true, - .dt_suggested = dt_suggested - }; + return (struct gkyl_update_status){.success = true, .dt_suggested = dt_suggested}; } // Compute RHS of moment equations -double -moment_species_rhs(gkyl_moment_app *app, struct moment_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs) +double moment_species_rhs( + gkyl_moment_app *app, struct moment_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs +) { struct timespec tm = gkyl_wall_clock(); - + gkyl_array_clear(species->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); - if (app->scheme_type == GKYL_MOMENT_MP) - gkyl_mp_scheme_advance(species->mp_slvr, &app->local, fin, - app->ql, app->qr, app->amdq, app->apdq, - species->cflrate, species->embed_mask, rhs); - else - gkyl_kep_scheme_advance(species->kep_slvr, &app->local, fin, species->alpha, - species->cflrate, rhs); + if (app->scheme_type == GKYL_MOMENT_MP) { + gkyl_mp_scheme_advance( + species->mp_slvr, &app->local, fin, app->ql, app->qr, app->amdq, app->apdq, species->cflrate, + species->embed_mask, rhs + ); + } else { + gkyl_kep_scheme_advance( + species->kep_slvr, &app->local, fin, species->alpha, species->cflrate, rhs + ); + } double omegaCfl[1]; gkyl_array_reduce_range(omegaCfl, species->cflrate, GKYL_MAX, &(app->local)); app->stat.species_rhs_tm += gkyl_time_diff_now_sec(tm); - - return app->cfl/omegaCfl[0]; + + return app->cfl / omegaCfl[0]; } // free species -void -moment_species_release(const struct moment_species *sp) +void moment_species_release(const struct moment_species *sp) { gkyl_wv_eqn_release(sp->equation); - - for (int d=0; dndim; ++d) { - if (sp->lower_bc[d]) + + for (int d = 0; d < sp->ndim; ++d) { + if (sp->lower_bc[d]) { gkyl_wv_apply_bc_release(sp->lower_bc[d]); - if (sp->upper_bc[d]) + } + if (sp->upper_bc[d]) { gkyl_wv_apply_bc_release(sp->upper_bc[d]); + } } if (sp->scheme_type == GKYL_MOMENT_WAVE_PROP) { - for (int d=0; dndim; ++d) + for (int d = 0; d < sp->ndim; ++d) { gkyl_wave_prop_release(sp->slvr[d]); - + } + gkyl_array_release(sp->fdup); - for (int d=0; dndim+1; ++d) + for (int d = 0; d < sp->ndim + 1; ++d) { gkyl_array_release(sp->f[d]); - } - else if (sp->scheme_type == GKYL_MOMENT_MP || sp->scheme_type == GKYL_MOMENT_KEP) { - - if (sp->scheme_type == GKYL_MOMENT_MP) + } + } else if (sp->scheme_type == GKYL_MOMENT_MP || sp->scheme_type == GKYL_MOMENT_KEP) { + if (sp->scheme_type == GKYL_MOMENT_MP) { gkyl_mp_scheme_release(sp->mp_slvr); - else + } else { gkyl_kep_scheme_release(sp->kep_slvr); - + } + gkyl_array_release(sp->f0); gkyl_array_release(sp->f1); gkyl_array_release(sp->fnew); @@ -580,13 +599,12 @@ moment_species_release(const struct moment_species *sp) /** mhd_src functions */ -void -mhd_src_init(const struct gkyl_moment_app *app, - const struct gkyl_moment_species *sp, - struct mhd_src *src) +void mhd_src_init( + const struct gkyl_moment_app *app, const struct gkyl_moment_species *sp, struct mhd_src *src +) { double dxyz_min = DBL_MAX; - for (int d=0; dgrid.ndim; ++d) { + for (int d = 0; d < app->grid.ndim; ++d) { double dx = app->grid.dx[d]; dxyz_min = dx < dxyz_min ? dx : dxyz_min; } @@ -596,7 +614,7 @@ mhd_src_init(const struct gkyl_moment_app *app, .divergence_constraint = gkyl_wv_mhd_divergence_constraint(sp->equation), .glm_ch = gkyl_wv_mhd_glm_ch(sp->equation), .glm_alpha = gkyl_wv_mhd_glm_ch(sp->equation), - .dxyz_min = dxyz_min, + .dxyz_min = dxyz_min }; src->slvr = gkyl_mhd_src_new(src_inp, &app->local_ext); @@ -604,30 +622,27 @@ mhd_src_init(const struct gkyl_moment_app *app, // update sources: 'nstrang' is 0 for the first Strang step and 1 for // the second step -void -mhd_src_update(gkyl_moment_app *app, struct mhd_src *src, int nstrang, - double tcurr, double dt) +void mhd_src_update(gkyl_moment_app *app, struct mhd_src *src, int nstrang, double tcurr, double dt) { - int sidx[] = { 0, app->ndim }; + int sidx[] = {0, app->ndim}; int i = 0; // mhd has only one 'species' struct gkyl_array *fluid = app->species[i].f[sidx[nstrang]]; - if (app->species[i].app_accel_proj) - gkyl_fv_proj_advance(app->species[i].app_accel_proj, tcurr, &app->local, - app->species[i].app_accel); + if (app->species[i].app_accel_proj) { + gkyl_fv_proj_advance( + app->species[i].app_accel_proj, tcurr, &app->local, app->species[i].app_accel + ); + } // FIXME presently needed for computing divB etc moment_species_apply_bc(app, tcurr, &app->species[i], fluid); - gkyl_mhd_src_advance(src->slvr, dt, &app->local, fluid, - app->species[i].app_accel); + gkyl_mhd_src_advance(src->slvr, dt, &app->local, fluid, app->species[i].app_accel); moment_species_apply_bc(app, tcurr, &app->species[i], fluid); - } -void -mhd_src_release(const struct mhd_src *src) +void mhd_src_release(const struct mhd_src *src) { gkyl_mhd_src_release(src->slvr); } diff --git a/moments/apps/mom_update_one_step.c b/moments/apps/mom_update_one_step.c index 1386c6ae67..5432515368 100644 --- a/moments/apps/mom_update_one_step.c +++ b/moments/apps/mom_update_one_step.c @@ -2,14 +2,13 @@ // internal function that takes a single time-step using a single-step // Strang-split scheme -struct gkyl_update_status -moment_update_one_step(gkyl_moment_app* app, double dt0) +struct gkyl_update_status moment_update_one_step(gkyl_moment_app *app, double dt0) { int ns = app->num_species, ndim = app->ndim; bool have_nans_occured = false; - + double dt_suggested = DBL_MAX; - + // time-stepper states enum { UPDATE_DONE = 0, @@ -19,138 +18,139 @@ moment_update_one_step(gkyl_moment_app* app, double dt0) FIELD_UPDATE, SPECIES_UPDATE, SECOND_COUPLING_UPDATE, - UPDATE_REDO, + UPDATE_REDO } state = PRE_UPDATE; double tcurr = app->tcurr, dt = dt0; while (state != UPDATE_DONE) { switch (state) { - case PRE_UPDATE: - state = FIRST_COUPLING_UPDATE; // next state - - // copy old solution in case we need to redo this step - for (int i=0; ispecies[i].fdup, app->species[i].f[0]); - if (app->has_field) - gkyl_array_copy(app->field.fdup, app->field.f[0]); - - break; - - case FIRST_COUPLING_UPDATE: - state = FIELD_UPDATE; // next state - - if (app->update_sources) { - struct timespec src1_tm = gkyl_wall_clock(); - struct gkyl_update_status s = moment_coupling_update(app, &app->sources, - 0, tcurr, dt/2); - if (!s.success) { - app->stat.nfail += 1; - dt = s.dt_suggested; - state = UPDATE_REDO; - break; - } - dt_suggested = fmin(dt_suggested, s.dt_suggested); - app->stat.sources_tm += gkyl_time_diff_now_sec(src1_tm); + case PRE_UPDATE: + state = FIRST_COUPLING_UPDATE; // next state + + // copy old solution in case we need to redo this step + for (int i = 0; i < ns; ++i) { + gkyl_array_copy(app->species[i].fdup, app->species[i].f[0]); + } + if (app->has_field) { + gkyl_array_copy(app->field.fdup, app->field.f[0]); + } + + break; + + case FIRST_COUPLING_UPDATE: + state = FIELD_UPDATE; // next state + + if (app->update_sources) { + struct timespec src1_tm = gkyl_wall_clock(); + struct gkyl_update_status s = moment_coupling_update(app, &app->sources, 0, tcurr, dt / 2); + if (!s.success) { + app->stat.nfail += 1; + dt = s.dt_suggested; + state = UPDATE_REDO; + break; } - if (app->update_mhd_source) { - struct timespec src1_tm = gkyl_wall_clock(); - mhd_src_update(app, &app->mhd_source, 0, tcurr, dt/2); - app->stat.sources_tm += gkyl_time_diff_now_sec(src1_tm); + dt_suggested = fmin(dt_suggested, s.dt_suggested); + app->stat.sources_tm += gkyl_time_diff_now_sec(src1_tm); + } + if (app->update_mhd_source) { + struct timespec src1_tm = gkyl_wall_clock(); + mhd_src_update(app, &app->mhd_source, 0, tcurr, dt / 2); + app->stat.sources_tm += gkyl_time_diff_now_sec(src1_tm); + } + + break; + + case FIELD_UPDATE: + state = SPECIES_UPDATE; // next state + + if (app->has_field) { + struct timespec fl_tm = gkyl_wall_clock(); + struct gkyl_update_status s = moment_field_update(app, &app->field, tcurr, dt); + if (!s.success) { + app->stat.nfail += 1; + dt = s.dt_suggested; + state = UPDATE_REDO; + break; } - break; - - case FIELD_UPDATE: - state = SPECIES_UPDATE; // next state - - if (app->has_field) { - struct timespec fl_tm = gkyl_wall_clock(); - struct gkyl_update_status s = moment_field_update(app, &app->field, tcurr, dt); - if (!s.success) { - app->stat.nfail += 1; - dt = s.dt_suggested; - state = UPDATE_REDO; - break; - } - - dt_suggested = fmin(dt_suggested, s.dt_suggested); - app->stat.field_tm += gkyl_time_diff_now_sec(fl_tm); - } - - break; - - case SPECIES_UPDATE: - state = SECOND_COUPLING_UPDATE; // next state - - struct timespec sp_tm = gkyl_wall_clock(); - for (int i=0; ispecies[i], tcurr, dt); - - if (!s.success) { - app->stat.nfail += 1; - dt = s.dt_suggested; - state = UPDATE_REDO; - break; - } - dt_suggested = fmin(dt_suggested, s.dt_suggested); - } - app->stat.species_tm += gkyl_time_diff_now_sec(sp_tm); - - break; + dt_suggested = fmin(dt_suggested, s.dt_suggested); + app->stat.field_tm += gkyl_time_diff_now_sec(fl_tm); + } + + break; - case SECOND_COUPLING_UPDATE: - state = POST_UPDATE; // next state + case SPECIES_UPDATE: + state = SECOND_COUPLING_UPDATE; // next state - if (app->update_sources) { - struct timespec src2_tm = gkyl_wall_clock(); - moment_coupling_update(app, &app->sources, 1, tcurr, dt/2); - app->stat.sources_tm += gkyl_time_diff_now_sec(src2_tm); + struct timespec sp_tm = gkyl_wall_clock(); + for (int i = 0; i < ns; ++i) { + struct gkyl_update_status s = moment_species_update(app, &app->species[i], tcurr, dt); + + if (!s.success) { + app->stat.nfail += 1; + dt = s.dt_suggested; + state = UPDATE_REDO; + break; } - if (app->update_mhd_source) { - struct timespec src2_tm = gkyl_wall_clock(); - mhd_src_update(app, &app->mhd_source, 1, tcurr, dt/2); - app->stat.sources_tm += gkyl_time_diff_now_sec(src2_tm); + dt_suggested = fmin(dt_suggested, s.dt_suggested); + } + app->stat.species_tm += gkyl_time_diff_now_sec(sp_tm); + + break; + + case SECOND_COUPLING_UPDATE: + state = POST_UPDATE; // next state + + if (app->update_sources) { + struct timespec src2_tm = gkyl_wall_clock(); + moment_coupling_update(app, &app->sources, 1, tcurr, dt / 2); + app->stat.sources_tm += gkyl_time_diff_now_sec(src2_tm); + } + if (app->update_mhd_source) { + struct timespec src2_tm = gkyl_wall_clock(); + mhd_src_update(app, &app->mhd_source, 1, tcurr, dt / 2); + app->stat.sources_tm += gkyl_time_diff_now_sec(src2_tm); + } + + break; + + case POST_UPDATE: + state = UPDATE_DONE; + + // copy solution in prep for next time-step + for (int i = 0; i < ns; ++i) { + // check for nans before copying + if (check_for_nans(app->species[i].f[ndim], app->local)) { + have_nans_occured = true; + } else { // only copy in case no nans, so old solution can be written out + gkyl_array_copy(app->species[i].f[0], app->species[i].f[ndim]); } + } - break; + if (app->has_field) { + gkyl_array_copy(app->field.f[0], app->field.f[ndim]); + } - case POST_UPDATE: - state = UPDATE_DONE; + break; - // copy solution in prep for next time-step - for (int i=0; ispecies[i].f[ndim], app->local)) - have_nans_occured = true; - else // only copy in case no nans, so old solution can be written out - gkyl_array_copy(app->species[i].f[0], app->species[i].f[ndim]); - } - - if (app->has_field) - gkyl_array_copy(app->field.f[0], app->field.f[ndim]); - - break; - - case UPDATE_REDO: - state = PRE_UPDATE; // start all-over again - - // restore solution and retake step - for (int i=0; ispecies[i].f[0], app->species[i].fdup); - if (app->has_field) - gkyl_array_copy(app->field.f[0], app->field.fdup); - - break; - - case UPDATE_DONE: // unreachable code! (suppresses warning) - break; + case UPDATE_REDO: + state = PRE_UPDATE; // start all-over again + + // restore solution and retake step + for (int i = 0; i < ns; ++i) { + gkyl_array_copy(app->species[i].f[0], app->species[i].fdup); + } + if (app->has_field) { + gkyl_array_copy(app->field.f[0], app->field.fdup); + } + + break; + + case UPDATE_DONE: // unreachable code! (suppresses warning) + break; } } - return (struct gkyl_update_status) { - .success = have_nans_occured ? false : true, - .dt_actual = dt, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status + ){.success = have_nans_occured ? false : true, .dt_actual = dt, .dt_suggested = dt_suggested}; } diff --git a/moments/apps/mom_update_ssp_rk.c b/moments/apps/mom_update_ssp_rk.c index a78e05b407..4bff9cf44e 100644 --- a/moments/apps/mom_update_ssp_rk.c +++ b/moments/apps/mom_update_ssp_rk.c @@ -5,17 +5,17 @@ // take a time-step larger than dt even if it is allowed by // stability. The actual time-step and dt_suggested are returned in // the status object. -static void -forward_euler(gkyl_moment_app* app, double tcurr, double dt, - const struct gkyl_array *fin[], const struct gkyl_array *emin, - struct gkyl_array *fout[], struct gkyl_array *emout, - struct gkyl_update_status *st) +static void forward_euler( + gkyl_moment_app *app, double tcurr, double dt, const struct gkyl_array *fin[], + const struct gkyl_array *emin, struct gkyl_array *fout[], struct gkyl_array *emout, + struct gkyl_update_status *st +) { app->stat.nfeuler += 1; double dtmin = DBL_MAX; // compute RHS of fluid equations - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { double dt1 = moment_species_rhs(app, &app->species[i], fin[i], fout[i]); dtmin = fmin(dtmin, dt1); } @@ -23,43 +23,45 @@ forward_euler(gkyl_moment_app* app, double tcurr, double dt, if (app->has_field) { double dt1 = moment_field_rhs(app, &app->field, emin, emout); dtmin = fmin(dtmin, dt1); - } + } double dt_max_rel_diff = 0.01; // check if dtmin is slightly smaller than dt. Use dt if it is // (avoids retaking steps if dt changes are very small). - double dt_rel_diff = (dt-dtmin)/dt; - if (dt_rel_diff > 0 && dt_rel_diff < dt_max_rel_diff) + double dt_rel_diff = (dt - dtmin) / dt; + if (dt_rel_diff > 0 && dt_rel_diff < dt_max_rel_diff) { dtmin = dt; + } // don't take a time-step larger that input dt double dta = st->dt_actual = dt < dtmin ? dt : dtmin; st->dt_suggested = dtmin; // complete update of species - for (int i=0; inum_species; ++i) { - gkyl_array_accumulate_range(gkyl_array_scale_range(fout[i], dta, &(app->local)), - 1.0, fin[i], &(app->local)); + for (int i = 0; i < app->num_species; ++i) { + gkyl_array_accumulate_range( + gkyl_array_scale_range(fout[i], dta, &(app->local)), 1.0, fin[i], &(app->local) + ); moment_species_apply_bc(app, tcurr, &app->species[i], fout[i]); } if (app->has_field) { // complete update of field (even when field is static, it is // safest to do this accumulate as it ensure emout = emin) - gkyl_array_accumulate_range(gkyl_array_scale_range(emout, dta, &(app->local)), - 1.0, emin, &(app->local)); - + gkyl_array_accumulate_range( + gkyl_array_scale_range(emout, dta, &(app->local)), 1.0, emin, &(app->local) + ); + moment_field_apply_bc(app, tcurr, &app->field, emout); } } // internal function that takes a single time-step using a single-step // Strang-split scheme -struct gkyl_update_status -moment_update_ssp_rk3(gkyl_moment_app* app, double dt0) +struct gkyl_update_status moment_update_ssp_rk3(gkyl_moment_app *app, double dt0) { const struct gkyl_array *fin[app->num_species]; struct gkyl_array *fout[app->num_species]; - struct gkyl_update_status st = { .success = true }; + struct gkyl_update_status st = {.success = true}; // time-stepper state enum { RK_STAGE_1, RK_STAGE_2, RK_STAGE_3, RK_COMPLETE } state = RK_STAGE_1; @@ -67,93 +69,98 @@ moment_update_ssp_rk3(gkyl_moment_app* app, double dt0) double tcurr = app->tcurr, dt = dt0; while (state != RK_COMPLETE) { switch (state) { - case RK_STAGE_1: - for (int i=0; inum_species; ++i) { - fin[i] = app->species[i].f0; - fout[i] = app->species[i].f1; - } - forward_euler(app, tcurr, dt, fin, app->has_field ? app->field.f0 : 0, - fout, app->has_field ? app->field.f1 : 0, - &st); - dt = st.dt_actual; - state = RK_STAGE_2; - break; - - case RK_STAGE_2: - for (int i=0; inum_species; ++i) { - fin[i] = app->species[i].f1; - fout[i] = app->species[i].fnew; + case RK_STAGE_1: + for (int i = 0; i < app->num_species; ++i) { + fin[i] = app->species[i].f0; + fout[i] = app->species[i].f1; + } + forward_euler( + app, tcurr, dt, fin, app->has_field ? app->field.f0 : 0, fout, + app->has_field ? app->field.f1 : 0, &st + ); + dt = st.dt_actual; + state = RK_STAGE_2; + break; + + case RK_STAGE_2: + for (int i = 0; i < app->num_species; ++i) { + fin[i] = app->species[i].f1; + fout[i] = app->species[i].fnew; + } + forward_euler( + app, tcurr + dt, dt, fin, app->has_field ? app->field.f1 : 0, fout, + app->has_field ? app->field.fnew : 0, &st + ); + if (st.dt_actual < dt) { + // collect stats + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], dt_rel_diff); + app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], dt_rel_diff); + app->stat.nstage_2_fail += 1; + + dt = st.dt_actual; + state = RK_STAGE_1; // restart from stage 1 + + } else { + for (int i = 0; i < app->num_species; ++i) { + array_combine( + app->species[i].f1, 3.0 / 4.0, app->species[i].f0, 1.0 / 4.0, app->species[i].fnew, + &app->local_ext + ); } - forward_euler(app, tcurr+dt, dt, fin, app->has_field ? app->field.f1 : 0, - fout, app->has_field ? app->field.fnew : 0, - &st); - if (st.dt_actual < dt) { - - // collect stats - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], - dt_rel_diff); - app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], - dt_rel_diff); - app->stat.nstage_2_fail += 1; - - dt = st.dt_actual; - state = RK_STAGE_1; // restart from stage 1 - - } else { - for (int i=0; inum_species; ++i) - array_combine(app->species[i].f1, - 3.0/4.0, app->species[i].f0, 1.0/4.0, app->species[i].fnew, &app->local_ext); - if (app->has_field) - array_combine(app->field.f1, - 3.0/4.0, app->field.f0, 1.0/4.0, app->field.fnew, &app->local_ext); - - state = RK_STAGE_3; + if (app->has_field) { + array_combine( + app->field.f1, 3.0 / 4.0, app->field.f0, 1.0 / 4.0, app->field.fnew, &app->local_ext + ); } - break; - case RK_STAGE_3: - for (int i=0; inum_species; ++i) { - fin[i] = app->species[i].f1; - fout[i] = app->species[i].fnew; - } - forward_euler(app, tcurr+dt/2, dt, fin, app->has_field ? app->field.f1 : 0, - fout, app->has_field ? app->field.fnew : 0, - &st); - if (st.dt_actual < dt) { - // collect stats - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], - dt_rel_diff); - app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], - dt_rel_diff); - app->stat.nstage_3_fail += 1; - - dt = st.dt_actual; - state = RK_STAGE_1; // restart from stage 1 - - app->stat.nstage_2_fail += 1; + state = RK_STAGE_3; + } + break; + + case RK_STAGE_3: + for (int i = 0; i < app->num_species; ++i) { + fin[i] = app->species[i].f1; + fout[i] = app->species[i].fnew; + } + forward_euler( + app, tcurr + dt / 2, dt, fin, app->has_field ? app->field.f1 : 0, fout, + app->has_field ? app->field.fnew : 0, &st + ); + if (st.dt_actual < dt) { + // collect stats + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], dt_rel_diff); + app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], dt_rel_diff); + app->stat.nstage_3_fail += 1; + + dt = st.dt_actual; + state = RK_STAGE_1; // restart from stage 1 + + app->stat.nstage_2_fail += 1; + } else { + for (int i = 0; i < app->num_species; ++i) { + array_combine( + app->species[i].f1, 1.0 / 3.0, app->species[i].f0, 2.0 / 3.0, app->species[i].fnew, + &app->local_ext + ); + gkyl_array_copy_range(app->species[i].f0, app->species[i].f1, &app->local_ext); } - else { - for (int i=0; inum_species; ++i) { - array_combine(app->species[i].f1, - 1.0/3.0, app->species[i].f0, 2.0/3.0, app->species[i].fnew, &app->local_ext); - gkyl_array_copy_range(app->species[i].f0, app->species[i].f1, &app->local_ext); - } - if (app->has_field) { - array_combine(app->field.f1, - 1.0/3.0, app->field.f0, 2.0/3.0, app->field.fnew, &app->local_ext); - gkyl_array_copy_range(app->field.f0, app->field.f1, &app->local_ext); - } - - state = RK_COMPLETE; + if (app->has_field) { + array_combine( + app->field.f1, 1.0 / 3.0, app->field.f0, 2.0 / 3.0, app->field.fnew, &app->local_ext + ); + gkyl_array_copy_range(app->field.f0, app->field.f1, &app->local_ext); } - break; - case RK_COMPLETE: // can't happen: suppresses warning - break; + state = RK_COMPLETE; + } + break; + + case RK_COMPLETE: // can't happen: suppresses warning + break; } } - + return st; } diff --git a/moments/apps/moment.c b/moments/apps/moment.c index 77d646a92d..350c12d06b 100644 --- a/moments/apps/moment.c +++ b/moments/apps/moment.c @@ -5,10 +5,12 @@ #include -static inline int int_max(int a, int b) { return a > b ? a : b; } +static inline int int_max(int a, int b) +{ + return a > b ? a : b; +} -struct gkyl_msgpack_data* -moment_array_meta_new(struct moment_output_meta meta) +struct gkyl_msgpack_data *moment_array_meta_new(struct moment_output_meta meta) { struct gkyl_msgpack_data *mt = gkyl_malloc(sizeof(*mt)); @@ -18,7 +20,7 @@ moment_array_meta_new(struct moment_output_meta meta) // add some data to mpack mpack_build_map(&writer); - + mpack_write_cstr(&writer, "time"); mpack_write_double(&writer, meta.stime); @@ -38,18 +40,18 @@ moment_array_meta_new(struct moment_output_meta meta) return mt; } -void -moment_array_meta_release(struct gkyl_msgpack_data *mt) +void moment_array_meta_release(struct gkyl_msgpack_data *mt) { - if (!mt) return; + if (!mt) { + return; + } MPACK_FREE(mt->meta); gkyl_free(mt); } -struct moment_output_meta -moment_meta_from_mpack(struct gkyl_msgpack_data *mt) +struct moment_output_meta moment_meta_from_mpack(struct gkyl_msgpack_data *mt) { - struct moment_output_meta meta = { .frame = 0, .stime = 0.0 }; + struct moment_output_meta meta = {.frame = 0, .stime = 0.0}; if (mt->meta_sz > 0) { mpack_tree_t tree; @@ -65,11 +67,10 @@ moment_meta_from_mpack(struct gkyl_msgpack_data *mt) return meta; } -gkyl_moment_app* -gkyl_moment_app_new(struct gkyl_moment *mom) +gkyl_moment_app *gkyl_moment_app_new(struct gkyl_moment *mom) { disable_denorm_float(); - + struct gkyl_moment_app *app = gkyl_calloc(1, sizeof(*app)); int ndim = app->ndim = mom->ndim; @@ -77,41 +78,46 @@ gkyl_moment_app_new(struct gkyl_moment *mom) app->tcurr = 0.0; // reset on init app->scheme_type = mom->scheme_type; - + app->mp_recon = mom->mp_recon; app->use_hybrid_flux_kep = mom->use_hybrid_flux_kep; - - if (app->scheme_type == GKYL_MOMENT_WAVE_PROP) + + if (app->scheme_type == GKYL_MOMENT_WAVE_PROP) { app->update_func = moment_update_one_step; - else if (app->scheme_type == GKYL_MOMENT_MP) + } else if (app->scheme_type == GKYL_MOMENT_MP) { app->update_func = moment_update_ssp_rk3; - else if (app->scheme_type == GKYL_MOMENT_KEP) + } else if (app->scheme_type == GKYL_MOMENT_KEP) { app->update_func = moment_update_ssp_rk3; + } - int ghost[3] = { 2, 2, 2 }; // 2 ghost-cells for wave - if (mom->scheme_type != GKYL_MOMENT_WAVE_PROP) - for (int d=0; d<3; ++d) ghost[d] = 3; // 3 for MP scheme and KEP + int ghost[3] = {2, 2, 2}; // 2 ghost-cells for wave + if (mom->scheme_type != GKYL_MOMENT_WAVE_PROP) { + for (int d = 0; d < 3; ++d) { + ghost[d] = 3; // 3 for MP scheme and KEP + } + } + + for (int d = 0; d < 3; ++d) { + app->nghost[d] = ghost[d]; + } - for (int d=0; d<3; ++d) app->nghost[d] = ghost[d]; - gkyl_rect_grid_init(&app->grid, ndim, mom->lower, mom->upper, mom->cells); gkyl_create_grid_ranges(&app->grid, ghost, &app->global_ext, &app->global); if (mom->parallelism.comm == 0) { - int cuts[3] = { 1, 1, 1 }; + int cuts[3] = {1, 1, 1}; app->decomp = gkyl_rect_decomp_new_from_cuts(app->ndim, cuts, &app->global); - - app->comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = app->decomp, - .sync_corners = true, // If no communicator, since some moment apps need corner syncs, turn on corner syncs. - } - ); - + + app->comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){ + .decomp = app->decomp, + .sync_corners = + true // If no communicator, since some moment apps need corner syncs, turn on corner syncs. + }); + // Global and local ranges are same, and so just copy them. memcpy(&app->local, &app->global, sizeof(struct gkyl_range)); memcpy(&app->local_ext, &app->global_ext, sizeof(struct gkyl_range)); - } - else { + } else { // Create decomp. app->decomp = gkyl_rect_decomp_new_from_cuts(app->ndim, mom->parallelism.cuts, &app->global); @@ -124,9 +130,9 @@ gkyl_moment_app_new(struct gkyl_moment *mom) gkyl_create_ranges(&app->decomp->ranges[rank], ghost, &app->local_ext, &app->local); } - skin_ghost_ranges_init(&app->skin_ghost, &app->local_ext, ghost); - - app->c2p_ctx = app->mapc2p = 0; + skin_ghost_ranges_init(&app->skin_ghost, &app->local_ext, ghost); + + app->c2p_ctx = app->mapc2p = 0; app->has_mapc2p = mom->mapc2p ? true : false; if (app->has_mapc2p) { @@ -139,8 +145,9 @@ gkyl_moment_app_new(struct gkyl_moment *mom) gkyl_cart_modal_tensor(&basis, ndim, 1); // initialize DG field representing mapping - struct gkyl_array *c2p = mkarr(false, ndim*basis.num_basis, app->local_ext.volume); - gkyl_eval_on_nodes *ev_c2p = gkyl_eval_on_nodes_new(&app->grid, &basis, ndim, mom->mapc2p, mom->c2p_ctx); + struct gkyl_array *c2p = mkarr(false, ndim * basis.num_basis, app->local_ext.volume); + gkyl_eval_on_nodes *ev_c2p = + gkyl_eval_on_nodes_new(&app->grid, &basis, ndim, mom->mapc2p, mom->c2p_ctx); gkyl_eval_on_nodes_advance(ev_c2p, 0.0, &app->local_ext, c2p); // write DG projection of mapc2p to file @@ -153,23 +160,26 @@ gkyl_moment_app_new(struct gkyl_moment *mom) } // create geometry object (no GPU support in fluids right now JJ: 11/26/23) - app->geom = gkyl_wave_geom_new(&app->grid, &app->local_ext, - app->mapc2p, app->c2p_ctx, false); + app->geom = gkyl_wave_geom_new(&app->grid, &app->local_ext, app->mapc2p, app->c2p_ctx, false); double cfl_frac = mom->cfl_frac == 0 ? 0.95 : mom->cfl_frac; - app->cfl = 1.0*cfl_frac; - if (app->scheme_type == GKYL_MOMENT_MP) - app->cfl = 0.4*cfl_frac; // this should be 1/(1+alpha) = 0.2 but is set to a larger value + app->cfl = 1.0 * cfl_frac; + if (app->scheme_type == GKYL_MOMENT_MP) { + app->cfl = 0.4 * cfl_frac; // this should be 1/(1+alpha) = 0.2 but is set to a larger value + } app->num_periodic_dir = mom->num_periodic_dir; - for (int d=0; dperiodic_dirs[d] = mom->periodic_dirs[d]; + } // construct list of directions to skip - for (int d=0; d<3; ++d) + for (int d = 0; d < 3; ++d) { app->is_dir_skipped[d] = 0; - for (int i=0; inum_skip_dirs; ++i) + } + for (int i = 0; i < mom->num_skip_dirs; ++i) { app->is_dir_skipped[mom->skip_dirs[i]] = 1; + } app->has_field = 0; // Are we running with a field? @@ -185,34 +195,36 @@ gkyl_moment_app_new(struct gkyl_moment *mom) int ns = app->num_species = mom->num_species; // allocate space to store species objects - app->species = ns>0 ? gkyl_calloc(ns, sizeof(struct moment_species)) : 0; + app->species = ns > 0 ? gkyl_calloc(ns, sizeof(struct moment_species)) : 0; // create species - for (int i=0; ispecies[i], app, &app->species[i]); } // specify collision parameters in the exposed app app->has_collision = mom->has_collision; - int num_entries = app->num_species * (app->num_species-1) / 2; - for (int s=0; snum_species; ++s) - for (int r=0; rnum_species; ++r) + int num_entries = app->num_species * (app->num_species - 1) / 2; + for (int s = 0; s < app->num_species; ++s) { + for (int r = 0; r < app->num_species; ++r) { app->nu_base[s][r] = mom->nu_base[s][r]; + } + } // There are a significant number of options which necessitate the source solve in fluids // (e.g. applied acceleration, geometric sources, multi-species transport, electromagnetic coupling, etc.). - // To facilitate these options, each fluid species stores a boolean for whether or not it will require a + // To facilitate these options, each fluid species stores a boolean for whether or not it will require a // a source update and sets the value to true if any input parameter would necessitate a source, from // app->has_field (because the field couples to the fluid via sources) to whether an applied accerleation - // pointer is set to various closure-related input parameters. + // pointer is set to various closure-related input parameters. // We also check if there are sources in EM-only simulations, such as volume expansion or applied current - // simulations. + // simulations. app->update_sources = false; if (app->field.has_volume_sources || app->field.has_app_current) { - app->update_sources = true; + app->update_sources = true; } - for (int s=0; snum_species; ++s) { + for (int s = 0; s < app->num_species; ++s) { if (app->species[s].update_sources) { - app->update_sources = true; + app->update_sources = true; } } if (app->update_sources) { @@ -220,7 +232,7 @@ gkyl_moment_app_new(struct gkyl_moment *mom) } app->update_mhd_source = false; - if (ns==1 && mom->species[0].equation->type==GKYL_EQN_MHD) { + if (ns == 1 && mom->species[0].equation->type == GKYL_EQN_MHD) { app->update_mhd_source = true; mhd_src_init(app, &mom->species[0], &app->mhd_source); } @@ -228,10 +240,12 @@ gkyl_moment_app_new(struct gkyl_moment *mom) // allocate work array for use in MP scheme if (app->scheme_type == GKYL_MOMENT_MP || app->scheme_type == GKYL_MOMENT_KEP) { int max_eqn = 0; - for (int i=0; ispecies[i].num_equations); - if (app->has_field) + } + if (app->has_field) { max_eqn = int_max(max_eqn, 8); // maxwell equations have 8 components + } app->ql = mkarr(false, max_eqn, app->local_ext.volume); app->qr = mkarr(false, max_eqn, app->local_ext.volume); @@ -240,21 +254,21 @@ gkyl_moment_app_new(struct gkyl_moment *mom) } // initialize stat object to all zeros - app->stat = (struct gkyl_moment_stat) { - }; + app->stat = (struct gkyl_moment_stat){}; return app; } -double -gkyl_moment_app_max_dt(gkyl_moment_app* app) +double gkyl_moment_app_max_dt(gkyl_moment_app *app) { double max_dt = DBL_MAX; - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { max_dt = fmin(max_dt, moment_species_max_dt(app, &app->species[i])); + } - if (app->has_field) + if (app->has_field) { max_dt = fmin(max_dt, moment_field_max_dt(app, &app->field)); + } double max_dt_global; gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_MIN, 1, &max_dt, &max_dt_global); @@ -262,24 +276,25 @@ gkyl_moment_app_max_dt(gkyl_moment_app* app) return max_dt_global; } -void -gkyl_moment_app_apply_ic(gkyl_moment_app* app, double t0) +void gkyl_moment_app_apply_ic(gkyl_moment_app *app, double t0) { app->tcurr = t0; gkyl_moment_app_apply_ic_field(app, t0); - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { gkyl_moment_app_apply_ic_species(app, i, t0); + } } -void -gkyl_moment_app_apply_ic_field(gkyl_moment_app* app, double t0) +void gkyl_moment_app_apply_ic_field(gkyl_moment_app *app, double t0) { - if (app->has_field != 1) return; - + if (app->has_field != 1) { + return; + } + app->tcurr = t0; int num_quad = app->scheme_type == GKYL_MOMENT_MP ? 4 : 2; gkyl_fv_proj *proj = gkyl_fv_proj_new(&app->grid, num_quad, 8, app->field.init, app->field.ctx); - + gkyl_fv_proj_advance(proj, t0, &app->local, app->field.fcurr); gkyl_fv_proj_release(proj); @@ -293,44 +308,45 @@ gkyl_moment_app_apply_ic_field(gkyl_moment_app* app, double t0) moment_field_apply_bc(app, t0, &app->field, app->field.fcurr); } -void -gkyl_moment_app_apply_ic_species(gkyl_moment_app* app, int sidx, double t0) +void gkyl_moment_app_apply_ic_species(gkyl_moment_app *app, int sidx, double t0) { assert(sidx < app->num_species); app->tcurr = t0; - int num_quad = app->scheme_type == GKYL_MOMENT_MP ? 4 : 2; - gkyl_fv_proj *proj = gkyl_fv_proj_new(&app->grid, num_quad, app->species[sidx].num_equations, - app->species[sidx].init, app->species[sidx].ctx); - + int num_quad = app->scheme_type == GKYL_MOMENT_MP ? 4 : 2; + gkyl_fv_proj *proj = gkyl_fv_proj_new( + &app->grid, num_quad, app->species[sidx].num_equations, app->species[sidx].init, + app->species[sidx].ctx + ); + gkyl_fv_proj_advance(proj, t0, &app->local, app->species[sidx].fcurr); gkyl_fv_proj_release(proj); if (app->species[sidx].has_app_accel) { - gkyl_fv_proj_advance(app->species[sidx].app_accel_proj, t0, &app->local, app->species[sidx].app_accel); + gkyl_fv_proj_advance( + app->species[sidx].app_accel_proj, t0, &app->local, app->species[sidx].app_accel + ); } moment_species_apply_bc(app, t0, &app->species[sidx], app->species[sidx].fcurr); } -void -gkyl_moment_app_write(const gkyl_moment_app* app, double tm, int frame) +void gkyl_moment_app_write(const gkyl_moment_app *app, double tm, int frame) { gkyl_moment_app_write_field(app, tm, frame); - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { gkyl_moment_app_write_species(app, i, tm, frame); + } } -void -gkyl_moment_app_write_field(const gkyl_moment_app* app, double tm, int frame) +void gkyl_moment_app_write_field(const gkyl_moment_app *app, double tm, int frame) { - if (app->has_field != 1) return; + if (app->has_field != 1) { + return; + } - struct gkyl_msgpack_data *mt = moment_array_meta_new( (struct moment_output_meta) { - .frame = frame, - .stime= tm - } - ); + struct gkyl_msgpack_data *mt = + moment_array_meta_new((struct moment_output_meta){.frame = frame, .stime = tm}); cstr fileNm = cstr_from_fmt("%s-%s_%d.gkyl", app->name, "field", frame); gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, app->field.fcurr, fileNm.str); @@ -349,7 +365,9 @@ gkyl_moment_app_write_field(const gkyl_moment_app* app, double tm, int frame) if (app->field.app_current_proj) { if (app->field.app_current_evolve || frame == 0) { cstr fileNm = cstr_from_fmt("%s-%s_%d.gkyl", app->name, "app_current", frame); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, app->field.app_current, fileNm.str); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, app->field.app_current, fileNm.str + ); cstr_drop(&fileNm); } } @@ -357,8 +375,7 @@ gkyl_moment_app_write_field(const gkyl_moment_app* app, double tm, int frame) moment_array_meta_release(mt); } -void -gkyl_moment_app_write_field_energy(gkyl_moment_app *app) +void gkyl_moment_app_write_field_energy(gkyl_moment_app *app) { if (app->has_field) { int rank; @@ -366,13 +383,12 @@ gkyl_moment_app_write_field_energy(gkyl_moment_app *app) if (rank == 0) { // write out field energy cstr fileNm = cstr_from_fmt("%s-field-energy.gkyl", app->name); - + if (app->field.is_first_energy_write_call) { // write to a new file (this ensure previous output is removed) gkyl_dynvec_write(app->field.integ_energy, fileNm.str); app->field.is_first_energy_write_call = false; - } - else { + } else { // append to existing file gkyl_dynvec_awrite(app->field.integ_energy, fileNm.str); } @@ -382,22 +398,19 @@ gkyl_moment_app_write_field_energy(gkyl_moment_app *app) } } -void -gkyl_moment_app_write_integrated_mom(gkyl_moment_app *app) +void gkyl_moment_app_write_integrated_mom(gkyl_moment_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { int rank; gkyl_comm_get_rank(app->comm, &rank); if (rank == 0) { // write out diagnostic moments - cstr fileNm = cstr_from_fmt("%s-%s-%s.gkyl", app->name, app->species[i].name, - "imom"); - + cstr fileNm = cstr_from_fmt("%s-%s-%s.gkyl", app->name, app->species[i].name, "imom"); + if (app->species[i].is_first_q_write_call) { gkyl_dynvec_write(app->species[i].integ_q, fileNm.str); app->species[i].is_first_q_write_call = false; - } - else { + } else { gkyl_dynvec_awrite(app->species[i].integ_q, fileNm.str); } cstr_drop(&fileNm); @@ -406,94 +419,94 @@ gkyl_moment_app_write_integrated_mom(gkyl_moment_app *app) } } -void -gkyl_moment_app_write_species(const gkyl_moment_app* app, int sidx, double tm, int frame) +void gkyl_moment_app_write_species(const gkyl_moment_app *app, int sidx, double tm, int frame) { - struct gkyl_msgpack_data *mt = moment_array_meta_new( (struct moment_output_meta) { - .frame = frame, - .stime = tm - } - ); - + struct gkyl_msgpack_data *mt = + moment_array_meta_new((struct moment_output_meta){.frame = frame, .stime = tm}); + cstr fileNm = cstr_from_fmt("%s-%s_%d.gkyl", app->name, app->species[sidx].name, frame); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, app->species[sidx].fcurr, fileNm.str); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, app->species[sidx].fcurr, fileNm.str + ); cstr_drop(&fileNm); if (app->scheme_type == GKYL_MOMENT_KEP) { cstr fileNm = cstr_from_fmt("%s-%s-alpha_%d.gkyl", app->name, app->species[sidx].name, frame); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, app->species[sidx].alpha, fileNm.str); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, app->species[sidx].alpha, fileNm.str + ); cstr_drop(&fileNm); } if (app->species[sidx].has_app_accel) { if (app->species[sidx].app_accel_evolve || frame == 0) { - cstr fileNm = cstr_from_fmt("%s-%s-app_accel_%d.gkyl", app->name, app->species[sidx].name, frame); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, app->species[sidx].app_accel, fileNm.str); - cstr_drop(&fileNm); + cstr fileNm = + cstr_from_fmt("%s-%s-app_accel_%d.gkyl", app->name, app->species[sidx].name, frame); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, app->species[sidx].app_accel, fileNm.str + ); + cstr_drop(&fileNm); } } moment_array_meta_release(mt); } -struct gkyl_update_status -gkyl_moment_update(gkyl_moment_app* app, double dt) +struct gkyl_update_status gkyl_moment_update(gkyl_moment_app *app, double dt) { gkyl_comm_barrier(app->comm); - + app->stat.nup += 1; - + struct timespec wst = gkyl_wall_clock(); struct gkyl_update_status status = app->update_func(app, dt); app->tcurr += status.dt_actual; - + app->stat.total_tm += gkyl_time_diff_now_sec(wst); - + return status; } -int -gkyl_moment_app_field_energy_ndiag(gkyl_moment_app *app) +int gkyl_moment_app_field_energy_ndiag(gkyl_moment_app *app) { return 6; } -void -gkyl_moment_app_get_field_energy(gkyl_moment_app *app, double *vals) +void gkyl_moment_app_get_field_energy(gkyl_moment_app *app, double *vals) { - double energy_global[6] = { 0.0 }; + double energy_global[6] = {0.0}; if (app->has_field) { double energy[6]; - calc_integ_quant(app->field.maxwell, app->grid.cellVolume, app->field.fcurr, app->geom, - app->local, energy); - + calc_integ_quant( + app->field.maxwell, app->grid.cellVolume, app->field.fcurr, app->geom, app->local, energy + ); + gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, 6, energy, energy_global); } - for (int i=0; i<6; ++i) + for (int i = 0; i < 6; ++i) { vals[i] = energy_global[i]; + } } -void -gkyl_moment_app_calc_field_energy(gkyl_moment_app* app, double tm) +void gkyl_moment_app_calc_field_energy(gkyl_moment_app *app, double tm) { if (app->has_field) { - double energy[6] = { 0.0 }; + double energy[6] = {0.0}; gkyl_moment_app_get_field_energy(app, energy); gkyl_dynvec_append(app->field.integ_energy, tm, energy); - } } -void -gkyl_moment_app_calc_integrated_mom(gkyl_moment_app *app, double tm) +void gkyl_moment_app_calc_integrated_mom(gkyl_moment_app *app, double tm) { - for (int sidx=0; sidxnum_species; ++sidx) { - + for (int sidx = 0; sidx < app->num_species; ++sidx) { int num_diag = app->species[sidx].equation->num_diag; double q_integ[num_diag]; - calc_integ_quant(app->species[sidx].equation, app->grid.cellVolume, app->species[sidx].fcurr, app->geom, - app->local, q_integ); + calc_integ_quant( + app->species[sidx].equation, app->grid.cellVolume, app->species[sidx].fcurr, app->geom, + app->local, q_integ + ); double q_integ_global[num_diag]; gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, num_diag, q_integ, q_integ_global); @@ -501,38 +514,37 @@ gkyl_moment_app_calc_integrated_mom(gkyl_moment_app *app, double tm) } } -void -gkyl_moment_app_nghost(gkyl_moment_app *app, int nghost[3]) +void gkyl_moment_app_nghost(gkyl_moment_app *app, int nghost[3]) { - for (int i=0; indim; ++i) + for (int i = 0; i < app->ndim; ++i) { nghost[i] = app->nghost[i]; + } } -struct gkyl_array* -gkyl_moment_app_get_write_array_species(const gkyl_moment_app* app, int sidx) +struct gkyl_array *gkyl_moment_app_get_write_array_species(const gkyl_moment_app *app, int sidx) { // this needs to be consistent with the write_species method return app->species[sidx].fcurr; } -struct gkyl_array* -gkyl_moment_app_get_write_array_field(const gkyl_moment_app* app) +struct gkyl_array *gkyl_moment_app_get_write_array_field(const gkyl_moment_app *app) { - if (app->has_field != 1) return 0; -// this needs to be consistent with the write_field method + if (app->has_field != 1) { + return 0; + } + // this needs to be consistent with the write_field method return app->field.fcurr; } -struct gkyl_moment_stat -gkyl_moment_app_stat(gkyl_moment_app* app) +struct gkyl_moment_stat gkyl_moment_app_stat(gkyl_moment_app *app) { return app->stat; } // ensure stats across processors are made consistent -static void -comm_reduce_app_stat(const gkyl_moment_app* app, const struct gkyl_moment_stat *local, - struct gkyl_moment_stat *global) +static void comm_reduce_app_stat( + const gkyl_moment_app *app, const struct gkyl_moment_stat *local, struct gkyl_moment_stat *global +) { int comm_sz; gkyl_comm_get_size(app->comm, &comm_sz); @@ -559,8 +571,17 @@ comm_reduce_app_stat(const gkyl_moment_app* app, const struct gkyl_moment_stat * global->nstage_2_fail = l_red_global[NSTAGE_2_FAIL]; global->nstage_3_fail = l_red_global[NSTAGE_3_FAIL]; - enum { TOTAL_TM, SPECIES_TM, FIELD_TM, SOURCES_TM, INIT_SPECIES_TM, INIT_FIELD_TM, - SPECIES_RHS_TM, FIELD_RHS_TM, SPECIES_BC_TM, FIELD_BC_TM, + enum { + TOTAL_TM, + SPECIES_TM, + FIELD_TM, + SOURCES_TM, + INIT_SPECIES_TM, + INIT_FIELD_TM, + SPECIES_RHS_TM, + FIELD_RHS_TM, + SPECIES_BC_TM, + FIELD_BC_TM, D_END }; @@ -592,9 +613,10 @@ comm_reduce_app_stat(const gkyl_moment_app* app, const struct gkyl_moment_stat * global->field_bc_tm = d_red_global[FIELD_BC_TM]; } -static void -comm_reduce_wave_prop_stats(const gkyl_moment_app* app, const struct gkyl_wave_prop_stats *local, - struct gkyl_wave_prop_stats *global) +static void comm_reduce_wave_prop_stats( + const gkyl_moment_app *app, const struct gkyl_wave_prop_stats *local, + struct gkyl_wave_prop_stats *global +) { int comm_sz; gkyl_comm_get_size(app->comm, &comm_sz); @@ -611,20 +633,19 @@ comm_reduce_wave_prop_stats(const gkyl_moment_app* app, const struct gkyl_wave_p }; int64_t l_red_global[L_END]; - gkyl_comm_allreduce(app->comm, GKYL_INT_64, GKYL_MAX, L_END, l_red, l_red_global); + gkyl_comm_allreduce(app->comm, GKYL_INT_64, GKYL_MAX, L_END, l_red, l_red_global); global->n_calls = l_red_global[N_CALLS]; global->n_bad_advance_calls = l_red_global[N_BAD_ADVANCE_CALLS]; global->n_max_bad_cells = l_red_global[N_MAX_BAD_CELLS]; int64_t n_bad_cells_local = local->n_bad_cells, n_bad_cells = 0; - + gkyl_comm_allreduce(app->comm, GKYL_INT_64, GKYL_SUM, 1, &n_bad_cells_local, &n_bad_cells); global->n_bad_cells = n_bad_cells; } -void -gkyl_moment_app_stat_write(const gkyl_moment_app* app) +void gkyl_moment_app_stat_write(const gkyl_moment_app *app) { cstr fileNm = cstr_from_fmt("%s-%s", app->name, "stat.json"); @@ -633,9 +654,9 @@ gkyl_moment_app_stat_write(const gkyl_moment_app* app) struct tm curr_tm = *localtime(&t); // total number of cells updated in simulation - long tot_cells_up = app->global.volume*app->num_species*app->ndim*app->stat.nup; + long tot_cells_up = app->global.volume * app->num_species * app->ndim * app->stat.nup; - struct gkyl_moment_stat stat = { }; + struct gkyl_moment_stat stat = {}; comm_reduce_app_stat(app, &app->stat, &stat); int rank; @@ -646,15 +667,18 @@ gkyl_moment_app_stat_write(const gkyl_moment_app* app) // append to existing file so we have a history of different runs FILE *fp = 0; - if (rank == 0) fp = fopen(fileNm.str, "a"); + if (rank == 0) { + fp = fopen(fileNm.str, "a"); + } gkyl_moment_app_cout(app, fp, "{\n"); - if (strftime(buff, sizeof buff, "%c", &curr_tm)) + if (strftime(buff, sizeof buff, "%c", &curr_tm)) { gkyl_moment_app_cout(app, fp, " date : %s\n", buff); + } gkyl_moment_app_cout(app, fp, " num_ranks : %d,\n", num_ranks); - + gkyl_moment_app_cout(app, fp, " nup : %ld,\n", stat.nup); gkyl_moment_app_cout(app, fp, " nfail : %ld,\n", stat.nfail); gkyl_moment_app_cout(app, fp, " total_tm : %lg,\n", stat.total_tm); @@ -663,106 +687,113 @@ gkyl_moment_app_stat_write(const gkyl_moment_app* app) gkyl_moment_app_cout(app, fp, " species_tm : %lg,\n", stat.species_tm); gkyl_moment_app_cout(app, fp, " field_tm : %lg,\n", stat.field_tm); gkyl_moment_app_cout(app, fp, " sources_tm : %lg\n", stat.sources_tm); - } - else if (app->scheme_type == GKYL_MOMENT_MP || app->scheme_type == GKYL_MOMENT_KEP) { - + } else if (app->scheme_type == GKYL_MOMENT_MP || app->scheme_type == GKYL_MOMENT_KEP) { gkyl_moment_app_cout(app, fp, " nfeuler : %ld,\n", stat.nfeuler); gkyl_moment_app_cout(app, fp, " nstage_2_fail : %ld,\n", stat.nstage_2_fail); gkyl_moment_app_cout(app, fp, " nstage_3_fail : %ld,\n", stat.nstage_3_fail); - gkyl_moment_app_cout(app, fp, " stage_2_dt_diff : [ %lg, %lg ],\n", - stat.stage_2_dt_diff[0], stat.stage_2_dt_diff[1]); - gkyl_moment_app_cout(app, fp, " stage_3_dt_diff : [ %lg, %lg ],\n", - stat.stage_3_dt_diff[0], stat.stage_3_dt_diff[1]); + gkyl_moment_app_cout( + app, fp, " stage_2_dt_diff : [ %lg, %lg ],\n", stat.stage_2_dt_diff[0], + stat.stage_2_dt_diff[1] + ); + gkyl_moment_app_cout( + app, fp, " stage_3_dt_diff : [ %lg, %lg ],\n", stat.stage_3_dt_diff[0], + stat.stage_3_dt_diff[1] + ); gkyl_moment_app_cout(app, fp, " total_tm : %lg,\n", stat.total_tm); gkyl_moment_app_cout(app, fp, " init_species_tm : %lg,\n", stat.init_species_tm); - if (app->has_field) + if (app->has_field) { gkyl_moment_app_cout(app, fp, " init_field_tm : %lg,\n", stat.init_field_tm); + } gkyl_moment_app_cout(app, fp, " species_rhs_tm : %lg,\n", stat.species_rhs_tm); - if (app->has_field) + if (app->has_field) { gkyl_moment_app_cout(app, fp, " field_rhs_tm : %lg,\n", stat.field_rhs_tm); + } } gkyl_moment_app_cout(app, fp, " species_bc_tm : %lg,\n", stat.species_bc_tm); - gkyl_moment_app_cout(app, fp, " field_bc_tm : %lg,\n", stat.field_bc_tm); + gkyl_moment_app_cout(app, fp, " field_bc_tm : %lg,\n", stat.field_bc_tm); for (int i = 0; i < app->num_species; ++i) { long tot_bad_cells = 0L; - + if (app->scheme_type == GKYL_MOMENT_WAVE_PROP) { for (int d = 0; d < app->ndim; ++d) { struct gkyl_wave_prop_stats wvs_local = gkyl_wave_prop_stats(app->species[i].slvr[d]); struct gkyl_wave_prop_stats wvs = {}; comm_reduce_wave_prop_stats(app, &wvs_local, &wvs); - gkyl_moment_app_cout(app, fp, " %s_n_bad_1D_sweeps[%d] = %ld\n", - app->species[i].name, d, wvs.n_bad_advance_calls); - gkyl_moment_app_cout(app, fp, " %s_n_bad_cells[%d] = %ld\n", - app->species[i].name, d, wvs.n_bad_cells); - gkyl_moment_app_cout(app, fp, " %s_n_max_bad_cells[%d] = %ld\n", - app->species[i].name, d, wvs.n_max_bad_cells); + gkyl_moment_app_cout( + app, fp, " %s_n_bad_1D_sweeps[%d] = %ld\n", app->species[i].name, d, + wvs.n_bad_advance_calls + ); + gkyl_moment_app_cout( + app, fp, " %s_n_bad_cells[%d] = %ld\n", app->species[i].name, d, wvs.n_bad_cells + ); + gkyl_moment_app_cout( + app, fp, " %s_n_max_bad_cells[%d] = %ld\n", app->species[i].name, d, wvs.n_max_bad_cells + ); tot_bad_cells += wvs.n_bad_cells; } } - gkyl_moment_app_cout(app, fp, " %s_bad_cell_frac = %lg\n", - app->species[i].name, (double)tot_bad_cells/tot_cells_up); + gkyl_moment_app_cout( + app, fp, " %s_bad_cell_frac = %lg\n", app->species[i].name, + (double)tot_bad_cells / tot_cells_up + ); } gkyl_moment_app_cout(app, fp, "}\n"); - if (rank == 0) + if (rank == 0) { fclose(fp); + } cstr_drop(&fileNm); } -static struct gkyl_app_restart_status -header_from_file(gkyl_moment_app *app, const char *fname) +static struct gkyl_app_restart_status header_from_file(gkyl_moment_app *app, const char *fname) { - struct gkyl_app_restart_status rstat = { .io_status = 0 }; - + struct gkyl_app_restart_status rstat = {.io_status = 0}; + FILE *fp = 0; - with_file(fp, fname, "r") { + with_file(fp, fname, "r") + { struct gkyl_rect_grid grid; struct gkyl_array_header_info hdr; rstat.io_status = gkyl_grid_sub_array_header_read_fp(&grid, &hdr, fp); if (GKYL_ARRAY_RIO_SUCCESS == rstat.io_status) { - if (!gkyl_rect_grid_cmp(&app->grid, &grid)) + if (!gkyl_rect_grid_cmp(&app->grid, &grid)) { rstat.io_status = GKYL_ARRAY_RIO_DATA_MISMATCH; - if (hdr.etype != GKYL_DOUBLE) + } + if (hdr.etype != GKYL_DOUBLE) { rstat.io_status = GKYL_ARRAY_RIO_DATA_MISMATCH; + } } - struct moment_output_meta meta = - moment_meta_from_mpack( &(struct gkyl_msgpack_data) { - .meta = hdr.meta, - .meta_sz = hdr.meta_size - } - ); + struct moment_output_meta meta = moment_meta_from_mpack(&(struct gkyl_msgpack_data + ){.meta = hdr.meta, .meta_sz = hdr.meta_size}); rstat.frame = meta.frame; rstat.stime = meta.stime; gkyl_grid_sub_array_header_release(&hdr); } - + return rstat; } struct gkyl_app_restart_status gkyl_moment_app_from_file_field(gkyl_moment_app *app, const char *fname) { - if (app->has_field != 1) - return (struct gkyl_app_restart_status) { - .io_status = GKYL_ARRAY_RIO_SUCCESS, - .frame = 0, - .stime = 0.0 - }; + if (app->has_field != 1) { + return (struct gkyl_app_restart_status + ){.io_status = GKYL_ARRAY_RIO_SUCCESS, .frame = 0, .stime = 0.0}; + } struct gkyl_app_restart_status rstat = header_from_file(app, fname); @@ -777,23 +808,24 @@ gkyl_moment_app_from_file_field(gkyl_moment_app *app, const char *fname) // Compute external EM field and applied current if present // Computation necessary in case external EM field or applied current // are time-independent and not computed in the time-stepping loop - // since they are not read-in as part of restarts. + // since they are not read-in as part of restarts. if (app->field.has_ext_em) { gkyl_fv_proj_advance(app->field.ext_em_proj, rstat.stime, &app->local, app->field.ext_em); } if (app->field.has_app_current) { - gkyl_fv_proj_advance(app->field.app_current_proj, rstat.stime, &app->local, app->field.app_current); - } + gkyl_fv_proj_advance( + app->field.app_current_proj, rstat.stime, &app->local, app->field.app_current + ); + } return rstat; } -struct gkyl_app_restart_status -gkyl_moment_app_from_file_species(gkyl_moment_app *app, int sidx, - const char *fname) +struct gkyl_app_restart_status +gkyl_moment_app_from_file_species(gkyl_moment_app *app, int sidx, const char *fname) { struct gkyl_app_restart_status rstat = header_from_file(app, fname); - + if (GKYL_ARRAY_RIO_SUCCESS == rstat.io_status) { rstat.io_status = gkyl_comm_array_read(app->comm, &app->grid, &app->local, app->species[sidx].fcurr, fname); @@ -805,22 +837,23 @@ gkyl_moment_app_from_file_species(gkyl_moment_app *app, int sidx, // Compute applied acceleration if present. // Computation necessary in case applied acceleration // is time-independent and not computed in the time-stepping loop - // since it is not read-in as part of restarts. + // since it is not read-in as part of restarts. if (app->species[sidx].has_app_accel) { - gkyl_fv_proj_advance(app->species[sidx].app_accel_proj, rstat.stime, &app->local, app->species[sidx].app_accel); - } + gkyl_fv_proj_advance( + app->species[sidx].app_accel_proj, rstat.stime, &app->local, app->species[sidx].app_accel + ); + } return rstat; } -struct gkyl_app_restart_status -gkyl_moment_app_from_frame_field(gkyl_moment_app *app, int frame) +struct gkyl_app_restart_status gkyl_moment_app_from_frame_field(gkyl_moment_app *app, int frame) { cstr fileNm = cstr_from_fmt("%s-%s_%d.gkyl", app->name, "field", frame); struct gkyl_app_restart_status rstat = gkyl_moment_app_from_file_field(app, fileNm.str); app->field.is_first_energy_write_call = false; // append to existing diagnostic cstr_drop(&fileNm); - + return rstat; } @@ -831,12 +864,11 @@ gkyl_moment_app_from_frame_species(gkyl_moment_app *app, int sidx, int frame) struct gkyl_app_restart_status rstat = gkyl_moment_app_from_file_species(app, sidx, fileNm.str); app->species[sidx].is_first_q_write_call = false; // append to existing diagnostic cstr_drop(&fileNm); - + return rstat; } -struct gkyl_app_restart_status -gkyl_moment_app_read_from_frame(gkyl_moment_app *app, int frame) +struct gkyl_app_restart_status gkyl_moment_app_read_from_frame(gkyl_moment_app *app, int frame) { struct gkyl_app_restart_status rstat; @@ -850,8 +882,7 @@ gkyl_moment_app_read_from_frame(gkyl_moment_app *app, int frame) } // private function to handle variable argument list for printing -static void -v_moment_app_cout(const gkyl_moment_app* app, FILE *fp, const char *fmt, va_list argp) +static void v_moment_app_cout(const gkyl_moment_app *app, FILE *fp, const char *fmt, va_list argp) { int rank; gkyl_comm_get_rank(app->comm, &rank); @@ -861,8 +892,7 @@ v_moment_app_cout(const gkyl_moment_app* app, FILE *fp, const char *fmt, va_list } } -void -gkyl_moment_app_cout(const gkyl_moment_app* app, FILE *fp, const char *fmt, ...) +void gkyl_moment_app_cout(const gkyl_moment_app *app, FILE *fp, const char *fmt, ...) { va_list argp; va_start(argp, fmt); @@ -870,23 +900,25 @@ gkyl_moment_app_cout(const gkyl_moment_app* app, FILE *fp, const char *fmt, ...) va_end(argp); } -void -gkyl_moment_app_release(gkyl_moment_app* app) +void gkyl_moment_app_release(gkyl_moment_app *app) { - if (app->update_sources) + if (app->update_sources) { moment_coupling_release(app, &app->sources); + } gkyl_comm_release(app->comm); gkyl_rect_decomp_release(app->decomp); - - for (int i=0; inum_species; ++i) + + for (int i = 0; i < app->num_species; ++i) { moment_species_release(&app->species[i]); + } gkyl_free(app->species); moment_field_release(&app->field); - if (app->update_mhd_source) + if (app->update_mhd_source) { mhd_src_release(&app->mhd_source); + } gkyl_wave_geom_release(app->geom); @@ -899,4 +931,3 @@ gkyl_moment_app_release(gkyl_moment_app* app) gkyl_free(app); } - diff --git a/moments/apps/moment_lw.c b/moments/apps/moment_lw.c index 4122ffe782..a9d633051d 100644 --- a/moments/apps/moment_lw.c +++ b/moments/apps/moment_lw.c @@ -59,148 +59,118 @@ #endif // Moment scheme type -> enum map. -static const struct gkyl_str_int_pair moment_scheme_type[] = { - { "WaveProp", GKYL_MOMENT_WAVE_PROP }, - { "MP", GKYL_MOMENT_MP }, - { "KEP", GKYL_MOMENT_KEP }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair moment_scheme_type[] = + {{"WaveProp", GKYL_MOMENT_WAVE_PROP}, {"MP", GKYL_MOMENT_MP}, {"KEP", GKYL_MOMENT_KEP}, {0, 0}}; // Wave limiter -> enum map. static const struct gkyl_str_int_pair wave_limiter[] = { - { "NoLimiter", GKYL_NO_LIMITER }, - { "MonotonizedCentered", GKYL_MONOTONIZED_CENTERED }, - { "MinMod", GKYL_MIN_MOD }, - { "SuperBee", GKYL_SUPERBEE }, - { "VanLeer", GKYL_VAN_LEER }, - { "BeamWarming", GKYL_BEAM_WARMING }, - { "Zero", GKYL_ZERO }, - { 0, 0 } + {"NoLimiter", GKYL_NO_LIMITER}, + {"MonotonizedCentered", GKYL_MONOTONIZED_CENTERED}, + {"MinMod", GKYL_MIN_MOD}, + {"SuperBee", GKYL_SUPERBEE}, + {"VanLeer", GKYL_VAN_LEER}, + {"BeamWarming", GKYL_BEAM_WARMING}, + {"Zero", GKYL_ZERO}, + {0, 0} }; // Euler Riemann problem -> enum map. static const struct gkyl_str_int_pair euler_rp_type[] = { - { "Roe", WV_EULER_RP_ROE }, - { "HLLC", WV_EULER_RP_HLLC }, - { "Lax", WV_EULER_RP_LAX }, - { "HLL", WV_EULER_RP_HLL }, - { 0, 0 } + {"Roe", WV_EULER_RP_ROE}, + {"HLLC", WV_EULER_RP_HLLC}, + {"Lax", WV_EULER_RP_LAX}, + {"HLL", WV_EULER_RP_HLL}, + {0, 0} }; // MHD Riemann problem -> enum map. -static const struct gkyl_str_int_pair mhd_rp_type[] = { - { "Roe", WV_MHD_RP_ROE }, - { "HLLD", WV_MHD_RP_HLLD }, - { "Lax", WV_MHD_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair mhd_rp_type[] = + {{"Roe", WV_MHD_RP_ROE}, {"HLLD", WV_MHD_RP_HLLD}, {"Lax", WV_MHD_RP_LAX}, {0, 0}}; // MHD divergence correction -> enum map. static const struct gkyl_str_int_pair mhd_divb_type[] = { - { "None", GKYL_MHD_DIVB_NONE }, - { "GLM", GKYL_MHD_DIVB_GLM }, - { "EightWaves", GKYL_MHD_DIVB_EIGHT_WAVES }, - { 0, 0 } + {"None", GKYL_MHD_DIVB_NONE}, + {"GLM", GKYL_MHD_DIVB_GLM}, + {"EightWaves", GKYL_MHD_DIVB_EIGHT_WAVES}, + {0, 0} }; // Braginskii type -> enum map. -static const struct gkyl_str_int_pair braginskii_type[] = { - { "Mag", GKYL_BRAG_MAG }, - { "Visc", GKYL_BRAG_VISC }, - { "HeatFlux", GKYL_BRAG_HEATFLUX }, - { "UnmagFull", GKYL_BRAG_UNMAG_FULL }, - { "MagFull", GKYL_BRAG_MAG_FULL }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair braginskii_type[] = {{"Mag", GKYL_BRAG_MAG}, + {"Visc", GKYL_BRAG_VISC}, + {"HeatFlux", GKYL_BRAG_HEATFLUX}, + {"UnmagFull", GKYL_BRAG_UNMAG_FULL}, + {"MagFull", GKYL_BRAG_MAG_FULL}, + {0, 0}}; // Spacetime gauge type -> enum map. -static const struct gkyl_str_int_pair spacetime_gauge_type[] = { - { "Static", GKYL_STATIC_GAUGE }, - { "BlackHoleCollapse", GKYL_BLACKHOLE_COLLAPSE_GAUGE }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair spacetime_gauge_type[] = + {{"Static", GKYL_STATIC_GAUGE}, {"BlackHoleCollapse", GKYL_BLACKHOLE_COLLAPSE_GAUGE}, {0, 0}}; // Spacetime slicing type -> enum map. static const struct gkyl_str_int_pair spacetime_slicing_type[] = { - { "Geodesic", GKYL_GEODESIC_SLICING }, - { "Harmonic", GKYL_HARMONIC_SLICING }, - { "OnePlusLog", GKYL_1PLUSLOG_SLICING }, - { 0, 0 } + {"Geodesic", GKYL_GEODESIC_SLICING}, + {"Harmonic", GKYL_HARMONIC_SLICING}, + {"OnePlusLog", GKYL_1PLUSLOG_SLICING}, + {0, 0} }; // Spacetime evolution type -> enum map. -static const struct gkyl_str_int_pair spacetime_evolution_type[] = { - { "Ricci", GKYL_RICCI_EVOLUTION }, - { "Einstein", GKYL_EINSTEIN_EVOLUTION }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair spacetime_evolution_type[] = + {{"Ricci", GKYL_RICCI_EVOLUTION}, {"Einstein", GKYL_EINSTEIN_EVOLUTION}, {0, 0}}; // Embedded boundary type -> enum map. static const struct gkyl_str_int_pair embed_geo_type[] = { - { "Absorb", GKYL_EMBED_ABSORB }, - { "Reflect", GKYL_EMBED_REFLECT }, - { "CopyB", GKYL_EMBED_COPY_B }, - { "PEC", GKYL_EMBED_PEC }, - { "Func", GKYL_EMBED_FUNC }, - { 0, 0 } + {"Absorb", GKYL_EMBED_ABSORB}, {"Reflect", GKYL_EMBED_REFLECT}, {"CopyB", GKYL_EMBED_COPY_B}, + {"PEC", GKYL_EMBED_PEC}, {"Func", GKYL_EMBED_FUNC}, {0, 0} }; -void -gkyl_register_moment_scheme_types(lua_State *L) +void gkyl_register_moment_scheme_types(lua_State *L) { register_types(L, moment_scheme_type, "SchemeType"); } -void -gkyl_register_wave_limiter_types(lua_State *L) +void gkyl_register_wave_limiter_types(lua_State *L) { register_types(L, wave_limiter, "WaveLimiter"); } -void -gkyl_register_euler_rp_types(lua_State *L) +void gkyl_register_euler_rp_types(lua_State *L) { register_types(L, euler_rp_type, "EulerRP"); } -void -gkyl_register_mhd_rp_types(lua_State *L) +void gkyl_register_mhd_rp_types(lua_State *L) { register_types(L, mhd_rp_type, "MHDRP"); } -void -gkyl_register_mhd_divb_types(lua_State *L) +void gkyl_register_mhd_divb_types(lua_State *L) { register_types(L, mhd_divb_type, "DivB"); } -void -gkyl_register_braginskii_types(lua_State *L) +void gkyl_register_braginskii_types(lua_State *L) { register_types(L, braginskii_type, "Braginskii"); } -void -gkyl_register_spacetime_gauge_types(lua_State *L) +void gkyl_register_spacetime_gauge_types(lua_State *L) { register_types(L, spacetime_gauge_type, "SpacetimeGauge"); } -void -gkyl_register_spacetime_slicing_types(lua_State *L) +void gkyl_register_spacetime_slicing_types(lua_State *L) { register_types(L, spacetime_slicing_type, "SpacetimeSlicing"); } -void -gkyl_register_spacetime_evolution_types(lua_State *L) +void gkyl_register_spacetime_evolution_types(lua_State *L) { register_types(L, spacetime_evolution_type, "SpacetimeEvolution"); } -void -gkyl_register_embed_geo_types(lua_State *L) +void gkyl_register_embed_geo_types(lua_State *L) { register_types(L, embed_geo_type, "EmbedBC"); } @@ -210,136 +180,93 @@ enum moment_magic_ids { MOMENT_SPECIES_DEFAULT = 100, // Fluid species. MOMENT_FIELD_DEFAULT, // Maxwell equations. MOMENT_EQN_DEFAULT, // Equation object. - MOMENT_SPACETIME_DEFAULT, // Spacetime object. + MOMENT_SPACETIME_DEFAULT // Spacetime object. }; // Edge-splitting -> enum map. -static const struct gkyl_str_int_pair wave_split_type[] = { - { "qwave", GKYL_WAVE_QWAVE }, - { "fwave", GKYL_WAVE_FWAVE }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair wave_split_type[] = + {{"qwave", GKYL_WAVE_QWAVE}, {"fwave", GKYL_WAVE_FWAVE}, {0, 0}}; // Reactive Euler Riemann problem -> enum map. -static const struct gkyl_str_int_pair reactive_euler_rp_type[] = { - { "roe", WV_REACTIVE_EULER_RP_ROE }, - { "lax", WV_REACTIVE_EULER_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair reactive_euler_rp_type[] = + {{"roe", WV_REACTIVE_EULER_RP_ROE}, {"lax", WV_REACTIVE_EULER_RP_LAX}, {0, 0}}; // Euler mixture Riemann problem -> enum map. -static const struct gkyl_str_int_pair euler_mixture_rp_type[] = { - { "roe", WV_EULER_MIXTURE_RP_ROE }, - { "lax", WV_EULER_MIXTURE_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair euler_mixture_rp_type[] = + {{"roe", WV_EULER_MIXTURE_RP_ROE}, {"lax", WV_EULER_MIXTURE_RP_LAX}, {0, 0}}; // Euler RGFM Riemann problem -> enum map. -static const struct gkyl_str_int_pair euler_rgfm_rp_type[] = { - { "lax", WV_EULER_RGFM_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair euler_rgfm_rp_type[] = {{"lax", WV_EULER_RGFM_RP_LAX}, {0, 0}}; // Isothermal Euler mixture Riemann problem -> enum map. -static const struct gkyl_str_int_pair iso_euler_mixture_rp_type[] = { - { "roe", WV_ISO_EULER_MIXTURE_RP_ROE }, - { "lax", WV_ISO_EULER_MIXTURE_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair iso_euler_mixture_rp_type[] = + {{"roe", WV_ISO_EULER_MIXTURE_RP_ROE}, {"lax", WV_ISO_EULER_MIXTURE_RP_LAX}, {0, 0}}; // General relativistic Maxwell Riemann problem -> enum map. -static const struct gkyl_str_int_pair gr_maxwell_rp_type[] = { - { "roe", WV_GR_MAXWELL_RP_ROE }, - { "lax", WV_GR_MAXWELL_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair gr_maxwell_rp_type[] = + {{"roe", WV_GR_MAXWELL_RP_ROE}, {"lax", WV_GR_MAXWELL_RP_LAX}, {0, 0}}; // General relativistic Maxwell Riemann problem in the tetrad basis -> enum map. -static const struct gkyl_str_int_pair gr_maxwell_tetrad_rp_type[] = { - { "roe", WV_GR_MAXWELL_TETRAD_RP_ROE }, - { "lax", WV_GR_MAXWELL_TETRAD_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair gr_maxwell_tetrad_rp_type[] = + {{"roe", WV_GR_MAXWELL_TETRAD_RP_ROE}, {"lax", WV_GR_MAXWELL_TETRAD_RP_LAX}, {0, 0}}; // General relativistic Euler Riemann problem (ultra-relativistic equation of state) -> enum map. static const struct gkyl_str_int_pair gr_ultra_rel_euler_rp_type[] = { - { "hll", WV_GR_ULTRA_REL_EULER_RP_HLL }, - { "roe", WV_GR_ULTRA_REL_EULER_RP_ROE }, - { "lax", WV_GR_ULTRA_REL_EULER_RP_LAX }, - { 0, 0 } + {"hll", WV_GR_ULTRA_REL_EULER_RP_HLL}, + {"roe", WV_GR_ULTRA_REL_EULER_RP_ROE}, + {"lax", WV_GR_ULTRA_REL_EULER_RP_LAX}, + {0, 0} }; // General relativistic Euler Riemann problem in the tetrad basis (ultra-relativistic equation of state) -> enum map. static const struct gkyl_str_int_pair gr_ultra_rel_euler_tetrad_rp_type[] = { - { "hll", WV_GR_ULTRA_REL_EULER_TETRAD_RP_HLL }, - { "roe", WV_GR_ULTRA_REL_EULER_TETRAD_RP_ROE }, - { "lax", WV_GR_ULTRA_REL_EULER_TETRAD_RP_LAX }, - { 0, 0 } + {"hll", WV_GR_ULTRA_REL_EULER_TETRAD_RP_HLL}, + {"roe", WV_GR_ULTRA_REL_EULER_TETRAD_RP_ROE}, + {"lax", WV_GR_ULTRA_REL_EULER_TETRAD_RP_LAX}, + {0, 0} }; // General relativistic Euler Riemann problem (general equation of state) -> enum map. -static const struct gkyl_str_int_pair gr_euler_rp_type[] = { - { "hll", WV_GR_EULER_RP_HLL }, - { "roe", WV_GR_EULER_RP_ROE }, - { "lax", WV_GR_EULER_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair gr_euler_rp_type[] = + {{"hll", WV_GR_EULER_RP_HLL}, {"roe", WV_GR_EULER_RP_ROE}, {"lax", WV_GR_EULER_RP_LAX}, {0, 0}}; // General relativistic Euler Riemann problem in the tetrad basis (general equation of state) -> enum map. static const struct gkyl_str_int_pair gr_euler_tetrad_rp_type[] = { - { "hll", WV_GR_EULER_TETRAD_RP_HLL }, - { "roe", WV_GR_EULER_TETRAD_RP_ROE }, - { "lax", WV_GR_EULER_TETRAD_RP_LAX }, - { 0, 0 } + {"hll", WV_GR_EULER_TETRAD_RP_HLL}, + {"roe", WV_GR_EULER_TETRAD_RP_ROE}, + {"lax", WV_GR_EULER_TETRAD_RP_LAX}, + {0, 0} }; // Coupled fluid-Einstein Riemann problem (plane-polarized Gowdy spacetimes) -> enum map. -static const struct gkyl_str_int_pair gr_medium_rp_type[] = { - { "lax", WV_GR_MEDIUM_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair gr_medium_rp_type[] = {{"lax", WV_GR_MEDIUM_RP_LAX}, {0, 0}}; // Vacuum Einstein Riemann problem (Bona-Masso formalism) -> enum map. -static const struct gkyl_str_int_pair vacuum_einstein_rp_type[] = { - { "hll", WV_VACUUM_EINSTEIN_RP_HLL }, - { "lax", WV_VACUUM_EINSTEIN_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair vacuum_einstein_rp_type[] = + {{"hll", WV_VACUUM_EINSTEIN_RP_HLL}, {"lax", WV_VACUUM_EINSTEIN_RP_LAX}, {0, 0}}; // Vacuum Einstein Riemann problem (Conformal Bona-Masso formalism) -> enum map. static const struct gkyl_str_int_pair vacuum_einstein_conformal_rp_type[] = { - { "hll", WV_VACUUM_EINSTEIN_CONFORMAL_RP_HLL }, - { "lax", WV_VACUUM_EINSTEIN_CONFORMAL_RP_LAX }, - { 0, 0 } + {"hll", WV_VACUUM_EINSTEIN_CONFORMAL_RP_HLL}, + {"lax", WV_VACUUM_EINSTEIN_CONFORMAL_RP_LAX}, + {0, 0} }; // General relativistic two-fluid Riemann problem -> enum map. -static const struct gkyl_str_int_pair gr_twofluid_rp_type[] = { - { "hll", WV_GR_TWOFLUID_RP_HLL }, - { "lax", WV_GR_TWOFLUID_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair gr_twofluid_rp_type[] = + {{"hll", WV_GR_TWOFLUID_RP_HLL}, {"lax", WV_GR_TWOFLUID_RP_LAX}, {0, 0}}; // General relativistic two-fluid Riemann problem in the tetrad basis -> enum map. -static const struct gkyl_str_int_pair gr_twofluid_tetrad_rp_type[] = { - { "hll", WV_GR_TWOFLUID_TETRAD_RP_HLL }, - { "lax", WV_GR_TWOFLUID_TETRAD_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair gr_twofluid_tetrad_rp_type[] = + {{"hll", WV_GR_TWOFLUID_TETRAD_RP_HLL}, {"lax", WV_GR_TWOFLUID_TETRAD_RP_LAX}, {0, 0}}; // General relativistic magnetohydrodynamics Riemann problem -> enum map. -static const struct gkyl_str_int_pair gr_mhd_rp_type[] = { - { "hll", WV_GR_MHD_RP_HLL }, - { "lax", WV_GR_MHD_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair gr_mhd_rp_type[] = + {{"hll", WV_GR_MHD_RP_HLL}, {"lax", WV_GR_MHD_RP_LAX}, {0, 0}}; // General relativistic magnetohydrodynamics Riemann problem in the tetrad basis -> enum map. -static const struct gkyl_str_int_pair gr_mhd_tetrad_rp_type[] = { - { "hll", WV_GR_MHD_TETRAD_RP_HLL }, - { "lax", WV_GR_MHD_TETRAD_RP_LAX }, - { 0, 0 } -}; +static const struct gkyl_str_int_pair gr_mhd_tetrad_rp_type[] = + {{"hll", WV_GR_MHD_TETRAD_RP_HLL}, {"lax", WV_GR_MHD_TETRAD_RP_LAX}, {0, 0}}; // Metatable name for equation object input struct. #define MOMENT_WAVE_EQN_METATABLE_NM "GkeyllZero.App.Moments.Eq" @@ -357,8 +284,7 @@ struct wv_eqn_lw { }; // Clean up memory allocated for equation object. -static int -wv_eqn_lw_gc(lua_State *L) +static int wv_eqn_lw_gc(lua_State *L) { struct wv_eqn_lw **l_wv_lw = GKYL_CHECK_UDATA(L, MOMENT_WAVE_EQN_METATABLE_NM); struct wv_eqn_lw *wv_lw = *l_wv_lw; @@ -371,13 +297,12 @@ wv_eqn_lw_gc(lua_State *L) gkyl_gr_spacetime_release(wv_lw->spacetime); } gkyl_free(*l_wv_lw); - + return 0; } // Acquire equation object. -static struct gkyl_wv_eqn* -wv_eqn_get(lua_State *L) +static struct gkyl_wv_eqn *wv_eqn_get(lua_State *L) { struct wv_eqn_lw **l_wv_lw = luaL_checkudata(L, -1, MOMENT_WAVE_EQN_METATABLE_NM); struct wv_eqn_lw *wv_lw = *l_wv_lw; @@ -391,8 +316,7 @@ wv_eqn_get(lua_State *L) // Euler.new { gasGamma = 1.4, rpType = G0.EulerRP.Roe } // where rpType is one of G0.EulerRP.Roe, G0.EulerRP.Lax, G0.EulerRP.HLL or G0.EulerRP.HLLC. -static int -eqn_euler_lw_new(lua_State *L) +static int eqn_euler_lw_new(lua_State *L) { struct wv_eqn_lw *euler_lw = gkyl_malloc(sizeof(*euler_lw)); @@ -400,41 +324,33 @@ eqn_euler_lw_new(lua_State *L) enum gkyl_wv_euler_rp rp_type = glua_tbl_get_integer(L, "rpType", WV_EULER_RP_ROE); euler_lw->magic = MOMENT_EQN_DEFAULT; - euler_lw->eqn = gkyl_wv_euler_inew( &(struct gkyl_wv_euler_inp) { - .gas_gamma = gas_gamma, - .rp_type = rp_type, - .use_gpu = false - } - ); + euler_lw->eqn = gkyl_wv_euler_inew(&(struct gkyl_wv_euler_inp + ){.gas_gamma = gas_gamma, .rp_type = rp_type, .use_gpu = false}); euler_lw->has_nn = false; euler_lw->ann = 0; euler_lw->has_spacetime = false; euler_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_euler_lw = euler_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, MOMENT_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_euler_ctor[] = { - { "new", eqn_euler_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_euler_ctor[] = {{"new", eqn_euler_lw_new}, {0, 0}}; /* ************************** */ /* Isothermal Euler Equations */ /* ************************** */ // IsoEuler.new { vThermal = 1.0 } -static int -eqn_iso_euler_lw_new(lua_State *L) +static int eqn_iso_euler_lw_new(lua_State *L) { struct wv_eqn_lw *iso_euler_lw = gkyl_malloc(sizeof(*iso_euler_lw)); @@ -442,7 +358,7 @@ eqn_iso_euler_lw_new(lua_State *L) if (vt < 0) { return luaL_error(L, "Thermal velocity \"vThermal\" not specified properly!"); } - + iso_euler_lw->magic = MOMENT_EQN_DEFAULT; iso_euler_lw->eqn = gkyl_wv_iso_euler_new(vt, false); iso_euler_lw->has_nn = false; @@ -451,29 +367,25 @@ eqn_iso_euler_lw_new(lua_State *L) iso_euler_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_iso_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_iso_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_iso_euler_lw = iso_euler_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, MOMENT_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_iso_euler_ctor[] = { - { "new", eqn_iso_euler_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_iso_euler_ctor[] = {{"new", eqn_iso_euler_lw_new}, {0, 0}}; /* ************************************ */ /* Special Relativistic Euler Equations */ /* ************************************ */ // SrEuler.new { gasgamma = 1.4 } -static int -eqn_sr_euler_lw_new(lua_State *L) +static int eqn_sr_euler_lw_new(lua_State *L) { struct wv_eqn_lw *sr_euler_lw = gkyl_malloc(sizeof(*sr_euler_lw)); @@ -487,29 +399,25 @@ eqn_sr_euler_lw_new(lua_State *L) sr_euler_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_sr_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_sr_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_sr_euler_lw = sr_euler_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, MOMENT_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_sr_euler_ctor[] = { - { "new", eqn_sr_euler_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_sr_euler_ctor[] = {{"new", eqn_sr_euler_lw_new}, {0, 0}}; /* ******************** */ /* Cold Fluid Equations */ /* ******************** */ // ColdFluid.new { } -static int -eqn_coldfluid_lw_new(lua_State *L) +static int eqn_coldfluid_lw_new(lua_State *L) { struct wv_eqn_lw *coldfluid_lw = gkyl_malloc(sizeof(*coldfluid_lw)); @@ -521,29 +429,25 @@ eqn_coldfluid_lw_new(lua_State *L) coldfluid_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_coldfluid_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_coldfluid_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_coldfluid_lw = coldfluid_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, MOMENT_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_coldfluid_ctor[] = { - { "new", eqn_coldfluid_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_coldfluid_ctor[] = {{"new", eqn_coldfluid_lw_new}, {0, 0}}; /* ******************** */ /* Ten-moment Equations */ /* ******************** */ // TenMoment.new { k0 = 1, hasGradClosure = false } -static int -eqn_tenmoment_lw_new(lua_State *L) +static int eqn_tenmoment_lw_new(lua_State *L) { struct wv_eqn_lw *tenm_lw = gkyl_malloc(sizeof(*tenm_lw)); @@ -551,9 +455,9 @@ eqn_tenmoment_lw_new(lua_State *L) bool has_grad_closure = glua_tbl_get_bool(L, "hasGradClosure", false); bool has_nn_closure = glua_tbl_get_bool(L, "hasNNClosure", false); int poly_order = glua_tbl_get_integer(L, "polyOrder", 1); - const char* nn_species_name = glua_tbl_get_string(L, "NNSpeciesName", ""); - const char* nn_closure_file = glua_tbl_get_string(L, "NNClosureFile", ""); - + const char *nn_species_name = glua_tbl_get_string(L, "NNSpeciesName", ""); + const char *nn_closure_file = glua_tbl_get_string(L, "NNClosureFile", ""); + struct gkyl_kann_net *ann = 0; if (has_nn_closure) { const char *fmt = "%s-%s.dat"; @@ -564,37 +468,37 @@ eqn_tenmoment_lw_new(lua_State *L) if (file != NULL) { ann = gkyl_kann_net_load(fileNm, false); fclose(file); - } - else { + } else { ann = 0; has_nn_closure = false; - fprintf(stderr, "Neural network for %s species not found! Disabling NN-based closure.\n", nn_species_name); + fprintf( + stderr, "Neural network for %s species not found! Disabling NN-based closure.\n", + nn_species_name + ); } } tenm_lw->magic = MOMENT_EQN_DEFAULT; - tenm_lw->eqn = gkyl_wv_ten_moment_new(k0, has_grad_closure, has_nn_closure, poly_order, ann, false); + tenm_lw->eqn = + gkyl_wv_ten_moment_new(k0, has_grad_closure, has_nn_closure, poly_order, ann, false); tenm_lw->has_nn = has_nn_closure; tenm_lw->ann = ann; tenm_lw->has_spacetime = false; tenm_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_tenm_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_tenm_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_tenm_lw = tenm_lw; // Point userdata to the equation object. - + // Set metatable luaL_getmetatable(L, MOMENT_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_tenmoment_ctor[] = { - { "new", eqn_tenmoment_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_tenmoment_ctor[] = {{"new", eqn_tenmoment_lw_new}, {0, 0}}; /* ************* */ /* MHD Equations */ @@ -603,49 +507,44 @@ static struct luaL_Reg eqn_tenmoment_ctor[] = { // Mhd.new { gasgamma = 1.4, rpType = "roe", divB = "glm", glmCh = 0.0, glmAlpha = 0.0 } // rpType is one of "roe", "hlld", "lax" // divB is "none", "glm", "eight_waves" -static int -eqn_mhd_lw_new(lua_State *L) +static int eqn_mhd_lw_new(lua_State *L) { struct wv_eqn_lw *mhd_lw = gkyl_malloc(sizeof(*mhd_lw)); double gas_gamma = glua_tbl_get_number(L, "gasGamma", 1.4); - + enum gkyl_wv_mhd_rp rp_type = glua_tbl_get_integer(L, "rpType", WV_MHD_RP_ROE); - enum gkyl_wv_mhd_div_constraint divb = glua_tbl_get_integer(L, "divergenceConstraint", GKYL_MHD_DIVB_NONE); + enum gkyl_wv_mhd_div_constraint divb = + glua_tbl_get_integer(L, "divergenceConstraint", GKYL_MHD_DIVB_NONE); double glm_ch = glua_tbl_get_number(L, "glmCh", 1.0); double glm_alpha = glua_tbl_get_number(L, "glmAlpha", 0.4); mhd_lw->magic = MOMENT_EQN_DEFAULT; - mhd_lw->eqn = gkyl_wv_mhd_new( &(struct gkyl_wv_mhd_inp) { - .gas_gamma = gas_gamma, - .rp_type = rp_type, - .divergence_constraint = divb, - .glm_alpha = glm_alpha, - .glm_ch = glm_ch - } - ); + mhd_lw->eqn = gkyl_wv_mhd_new(&(struct gkyl_wv_mhd_inp + ){.gas_gamma = gas_gamma, + .rp_type = rp_type, + .divergence_constraint = divb, + .glm_alpha = glm_alpha, + .glm_ch = glm_ch}); mhd_lw->has_nn = false; mhd_lw->ann = 0; mhd_lw->has_spacetime = false; mhd_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_mhd_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_mhd_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_mhd_lw = mhd_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, MOMENT_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_mhd_ctor[] = { - { "new", eqn_mhd_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_mhd_ctor[] = {{"new", eqn_mhd_lw_new}, {0, 0}}; /* ************************ */ /* Reactive Euler Equations */ @@ -653,8 +552,7 @@ static struct luaL_Reg eqn_mhd_ctor[] = { // ReactiveEuler.new { gasGamma = 1.4, specificHeatCapacity = 2.5, energyOfFormation = 1.0, ignitionTemperature = 0.25, reactionRate = 250.0, rpType = "roe" } // where rpType is one of "roe" or "lax". -static int -eqn_reactive_euler_lw_new(lua_State *L) +static int eqn_reactive_euler_lw_new(lua_State *L) { struct wv_eqn_lw *reactive_euler_lw = gkyl_malloc(sizeof(*reactive_euler_lw)); @@ -665,40 +563,36 @@ eqn_reactive_euler_lw_new(lua_State *L) double reaction_rate = glua_tbl_get_number(L, "reactionRate", 250.0); const char *rp_str = glua_tbl_get_string(L, "rpType", "lax"); - enum gkyl_wv_reactive_euler_rp rp_type = gkyl_search_str_int_pair_by_str(reactive_euler_rp_type, rp_str, WV_REACTIVE_EULER_RP_LAX); + enum gkyl_wv_reactive_euler_rp rp_type = + gkyl_search_str_int_pair_by_str(reactive_euler_rp_type, rp_str, WV_REACTIVE_EULER_RP_LAX); reactive_euler_lw->magic = MOMENT_EQN_DEFAULT; - reactive_euler_lw->eqn = gkyl_wv_reactive_euler_inew( &(struct gkyl_wv_reactive_euler_inp) { - .gas_gamma = gas_gamma, - .specific_heat_capacity = specific_heat_capacity, - .energy_of_formation = energy_of_formation, - .ignition_temperature = ignition_temperature, - .reaction_rate = reaction_rate, - .rp_type = rp_type, - .use_gpu = false - } - ); + reactive_euler_lw->eqn = gkyl_wv_reactive_euler_inew(&(struct gkyl_wv_reactive_euler_inp + ){.gas_gamma = gas_gamma, + .specific_heat_capacity = specific_heat_capacity, + .energy_of_formation = energy_of_formation, + .ignition_temperature = ignition_temperature, + .reaction_rate = reaction_rate, + .rp_type = rp_type, + .use_gpu = false}); reactive_euler_lw->has_nn = false; reactive_euler_lw->ann = 0; reactive_euler_lw->has_spacetime = false; reactive_euler_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_reactive_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_reactive_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_reactive_euler_lw = reactive_euler_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, MOMENT_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_reactive_euler_ctor[] = { - { "new", eqn_reactive_euler_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_reactive_euler_ctor[] = {{"new", eqn_reactive_euler_lw_new}, {0, 0}}; /* *********************** */ /* Euler Mixture Equations */ @@ -706,30 +600,27 @@ static struct luaL_Reg eqn_reactive_euler_ctor[] = { // EulerMixture.new { numComponents = 2, gasGamma = {1.4, 1.4}, rpType = "roe" } // where rpType is one of "roe" or "lax". -static int -eqn_euler_mixture_lw_new(lua_State *L) +static int eqn_euler_mixture_lw_new(lua_State *L) { struct wv_eqn_lw *euler_mixture_lw = gkyl_malloc(sizeof(*euler_mixture_lw)); int num_components = glua_tbl_get_integer(L, "numComponents", 2); double *gas_gamma_s = gkyl_malloc(sizeof(double[num_components])); - with_lua_tbl_tbl(L, "gasGamma") { + with_lua_tbl_tbl(L, "gasGamma") + { for (int i = 0; i < num_components; i++) { gas_gamma_s[i] = glua_tbl_iget_number(L, i + 1, 1.4); } } - + const char *rp_str = glua_tbl_get_string(L, "rpType", "lax"); - enum gkyl_wv_euler_mixture_rp rp_type = gkyl_search_str_int_pair_by_str(euler_mixture_rp_type, rp_str, WV_EULER_MIXTURE_RP_LAX); + enum gkyl_wv_euler_mixture_rp rp_type = + gkyl_search_str_int_pair_by_str(euler_mixture_rp_type, rp_str, WV_EULER_MIXTURE_RP_LAX); euler_mixture_lw->magic = MOMENT_EQN_DEFAULT; - euler_mixture_lw->eqn = gkyl_wv_euler_mixture_inew( & (struct gkyl_wv_euler_mixture_inp) { - .num_species = num_components, - .gas_gamma_s = gas_gamma_s, - .rp_type = rp_type, - .use_gpu = false - } + euler_mixture_lw->eqn = gkyl_wv_euler_mixture_inew(&(struct gkyl_wv_euler_mixture_inp + ){.num_species = num_components, .gas_gamma_s = gas_gamma_s, .rp_type = rp_type, .use_gpu = false} ); euler_mixture_lw->has_nn = false; euler_mixture_lw->ann = 0; @@ -737,7 +628,7 @@ eqn_euler_mixture_lw_new(lua_State *L) euler_mixture_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_euler_mixture_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_euler_mixture_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_euler_mixture_lw = euler_mixture_lw; // Point userdata to the equation object. // Set metatable. @@ -748,10 +639,7 @@ eqn_euler_mixture_lw_new(lua_State *L) } // Equation constructor. -static const luaL_Reg eqn_euler_mixture_ctor[] = { - { "new", eqn_euler_mixture_lw_new }, - { 0, 0 } -}; +static const luaL_Reg eqn_euler_mixture_ctor[] = {{"new", eqn_euler_mixture_lw_new}, {0, 0}}; /* *********************** */ /* Euler RGFM Equations */ @@ -759,40 +647,39 @@ static const luaL_Reg eqn_euler_mixture_ctor[] = { // EulerRGFM.new { numComponents = 2, gasGamma = {1.4, 1.4}, reinitFreq = 3, rpType = "lax" } // where rpType is "lax". -static int -eqn_euler_rgfm_lw_new(lua_State *L) +static int eqn_euler_rgfm_lw_new(lua_State *L) { struct wv_eqn_lw *euler_rgfm_lw = gkyl_malloc(sizeof(*euler_rgfm_lw)); int num_components = glua_tbl_get_integer(L, "numComponents", 2); double *gas_gamma_s = gkyl_malloc(sizeof(double[num_components])); - with_lua_tbl_tbl(L, "gasGamma") { + with_lua_tbl_tbl(L, "gasGamma") + { for (int i = 0; i < num_components; i++) { gas_gamma_s[i] = glua_tbl_iget_number(L, i + 1, 1.4); } } int reinit_freq = glua_tbl_get_integer(L, "reinitFreq", 3); - + const char *rp_str = glua_tbl_get_string(L, "rpType", "lax"); - enum gkyl_wv_euler_rgfm_rp rp_type = gkyl_search_str_int_pair_by_str(euler_rgfm_rp_type, rp_str, WV_EULER_RGFM_RP_LAX); + enum gkyl_wv_euler_rgfm_rp rp_type = + gkyl_search_str_int_pair_by_str(euler_rgfm_rp_type, rp_str, WV_EULER_RGFM_RP_LAX); euler_rgfm_lw->magic = MOMENT_EQN_DEFAULT; - euler_rgfm_lw->eqn = gkyl_wv_euler_rgfm_inew( & (struct gkyl_wv_euler_rgfm_inp) { - .num_species = num_components, - .gas_gamma_s = gas_gamma_s, - .reinit_freq = reinit_freq, - .rp_type = rp_type, - .use_gpu = false - } - ); + euler_rgfm_lw->eqn = gkyl_wv_euler_rgfm_inew(&(struct gkyl_wv_euler_rgfm_inp + ){.num_species = num_components, + .gas_gamma_s = gas_gamma_s, + .reinit_freq = reinit_freq, + .rp_type = rp_type, + .use_gpu = false}); euler_rgfm_lw->has_nn = false; euler_rgfm_lw->ann = 0; euler_rgfm_lw->has_spacetime = false; euler_rgfm_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_euler_rgfm_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_euler_rgfm_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_euler_rgfm_lw = euler_rgfm_lw; // Point userdata to the equation object. // Set metatable. @@ -803,10 +690,7 @@ eqn_euler_rgfm_lw_new(lua_State *L) } // Equation constructor. -static const luaL_Reg eqn_euler_rgfm_ctor[] = { - { "new", eqn_euler_rgfm_lw_new }, - { 0, 0 } -}; +static const luaL_Reg eqn_euler_rgfm_ctor[] = {{"new", eqn_euler_rgfm_lw_new}, {0, 0}}; /* ********************************** */ /* Isothermal Euler Mixture Equations */ @@ -814,38 +698,34 @@ static const luaL_Reg eqn_euler_rgfm_ctor[] = { // IsoEulerMixture.new { numComponents = 2, vThermal = {1.0, 1.0}, rpType = "roe" } // where rpType is one of "roe" or "lax". -static int -eqn_iso_euler_mixture_lw_new(lua_State *L) +static int eqn_iso_euler_mixture_lw_new(lua_State *L) { struct wv_eqn_lw *iso_euler_mixture_lw = gkyl_malloc(sizeof(*iso_euler_mixture_lw)); int num_components = glua_tbl_get_integer(L, "numComponents", 2); double *vt_s = gkyl_malloc(sizeof(double[num_components])); - with_lua_tbl_tbl(L, "vThermal") { + with_lua_tbl_tbl(L, "vThermal") + { for (int i = 0; i < num_components; i++) { vt_s[i] = glua_tbl_iget_number(L, i + 1, 1.0); } } - + const char *rp_str = glua_tbl_get_string(L, "rpType", "lax"); - enum gkyl_wv_iso_euler_mixture_rp rp_type = gkyl_search_str_int_pair_by_str(iso_euler_mixture_rp_type, rp_str, WV_ISO_EULER_MIXTURE_RP_LAX); + enum gkyl_wv_iso_euler_mixture_rp rp_type = + gkyl_search_str_int_pair_by_str(iso_euler_mixture_rp_type, rp_str, WV_ISO_EULER_MIXTURE_RP_LAX); iso_euler_mixture_lw->magic = MOMENT_EQN_DEFAULT; - iso_euler_mixture_lw->eqn = gkyl_wv_iso_euler_mixture_inew( & (struct gkyl_wv_iso_euler_mixture_inp) { - .num_species = num_components, - .vt_s = vt_s, - .rp_type = rp_type, - .use_gpu = false - } - ); + iso_euler_mixture_lw->eqn = gkyl_wv_iso_euler_mixture_inew(&(struct gkyl_wv_iso_euler_mixture_inp + ){.num_species = num_components, .vt_s = vt_s, .rp_type = rp_type, .use_gpu = false}); iso_euler_mixture_lw->has_nn = false; iso_euler_mixture_lw->ann = 0; iso_euler_mixture_lw->has_spacetime = false; iso_euler_mixture_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_iso_euler_mixture_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_iso_euler_mixture_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_iso_euler_mixture_lw = iso_euler_mixture_lw; // Point userdata to the equation object. // Set metatable. @@ -856,10 +736,7 @@ eqn_iso_euler_mixture_lw_new(lua_State *L) } // Equation constructor. -static const luaL_Reg eqn_iso_euler_mixture_ctor[] = { - { "new", eqn_iso_euler_mixture_lw_new }, - { 0, 0 } -}; +static const luaL_Reg eqn_iso_euler_mixture_ctor[] = {{"new", eqn_iso_euler_mixture_lw_new}, {0, 0}}; /* ************************************** */ /* General Relativistic Maxwell Equations */ @@ -867,8 +744,7 @@ static const luaL_Reg eqn_iso_euler_mixture_ctor[] = { // GRMaxwell.new { lightSpeed = 1.0, elcErrorSpeedFactor = 0.0, mgnErrorSpeedFactor = 0.0, rpType = "roe" } // where rpType is one of "roe" or "lax". -static int -eqn_gr_maxwell_lw_new(lua_State *L) +static int eqn_gr_maxwell_lw_new(lua_State *L) { struct wv_eqn_lw *gr_maxwell_lw = gkyl_malloc(sizeof(*gr_maxwell_lw)); @@ -877,12 +753,14 @@ eqn_gr_maxwell_lw_new(lua_State *L) double b_fact = glua_tbl_get_number(L, "mgnErrorSpeedFactor", 0.0); const char *rp_str = glua_tbl_get_string(L, "rpType", "lax"); - enum gkyl_wv_gr_maxwell_rp rp_type = gkyl_search_str_int_pair_by_str(gr_maxwell_rp_type, rp_str, WV_GR_MAXWELL_RP_LAX); + enum gkyl_wv_gr_maxwell_rp rp_type = + gkyl_search_str_int_pair_by_str(gr_maxwell_rp_type, rp_str, WV_GR_MAXWELL_RP_LAX); struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); int reinit_freq = glua_tbl_get_integer(L, "reinitFreq", 100); - with_lua_tbl_tbl(L, "blackHoleParameters") { + with_lua_tbl_tbl(L, "blackHoleParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double pos_x = glua_tbl_get_number(L, "posX", 0.0); @@ -892,7 +770,8 @@ eqn_gr_maxwell_lw_new(lua_State *L) spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); } - with_lua_tbl_tbl(L, "neutronStarParameters") { + with_lua_tbl_tbl(L, "neutronStarParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double mass_quadrupole = glua_tbl_get_number(L, "massQuadrupole", 0.0); @@ -902,27 +781,27 @@ eqn_gr_maxwell_lw_new(lua_State *L) double pos_y = glua_tbl_get_number(L, "posY", 0.0); double pos_z = glua_tbl_get_number(L, "posZ", 0.0); - spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); } gr_maxwell_lw->magic = MOMENT_EQN_DEFAULT; - gr_maxwell_lw->eqn = gkyl_wv_gr_maxwell_inew( &(struct gkyl_wv_gr_maxwell_inp) { - .light_speed = light_speed, - .e_fact = e_fact, - .b_fact = b_fact, - .spacetime = spacetime, - .reinit_freq = reinit_freq, - .rp_type = rp_type, - .use_gpu = false, - } - ); + gr_maxwell_lw->eqn = gkyl_wv_gr_maxwell_inew(&(struct gkyl_wv_gr_maxwell_inp + ){.light_speed = light_speed, + .e_fact = e_fact, + .b_fact = b_fact, + .spacetime = spacetime, + .reinit_freq = reinit_freq, + .rp_type = rp_type, + .use_gpu = false}); gr_maxwell_lw->has_nn = false; gr_maxwell_lw->ann = 0; gr_maxwell_lw->has_spacetime = true; gr_maxwell_lw->spacetime = spacetime; // Create Lua userdata. - struct wv_eqn_lw **l_gr_maxwell_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_gr_maxwell_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_gr_maxwell_lw = gr_maxwell_lw; // Set metatable. @@ -933,10 +812,7 @@ eqn_gr_maxwell_lw_new(lua_State *L) } // Equation constructor. -static struct luaL_Reg eqn_gr_maxwell_ctor[] = { - { "new", eqn_gr_maxwell_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_gr_maxwell_ctor[] = {{"new", eqn_gr_maxwell_lw_new}, {0, 0}}; /* ********************************************************** */ /* General Relativistic Maxwell Equations in the Tetrad Basis */ @@ -944,8 +820,7 @@ static struct luaL_Reg eqn_gr_maxwell_ctor[] = { // GRMaxwellTetrad.new { lightSpeed = 1.0, elcErrorSpeedFactor = 0.0, mgnErrorSpeedFactor = 0.0, rpType = "roe" } // where rpType is one of "roe" or "lax". -static int -eqn_gr_maxwell_tetrad_lw_new(lua_State *L) +static int eqn_gr_maxwell_tetrad_lw_new(lua_State *L) { struct wv_eqn_lw *gr_maxwell_tetrad_lw = gkyl_malloc(sizeof(*gr_maxwell_tetrad_lw)); @@ -954,12 +829,14 @@ eqn_gr_maxwell_tetrad_lw_new(lua_State *L) double b_fact = glua_tbl_get_number(L, "mgnErrorSpeedFactor", 0.0); const char *rp_str = glua_tbl_get_string(L, "rpType", "lax"); - enum gkyl_wv_gr_maxwell_tetrad_rp rp_type = gkyl_search_str_int_pair_by_str(gr_maxwell_tetrad_rp_type, rp_str, WV_GR_MAXWELL_TETRAD_RP_LAX); + enum gkyl_wv_gr_maxwell_tetrad_rp rp_type = + gkyl_search_str_int_pair_by_str(gr_maxwell_tetrad_rp_type, rp_str, WV_GR_MAXWELL_TETRAD_RP_LAX); struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); int reinit_freq = glua_tbl_get_integer(L, "reinitFreq", 100); - with_lua_tbl_tbl(L, "blackHoleParameters") { + with_lua_tbl_tbl(L, "blackHoleParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double pos_x = glua_tbl_get_number(L, "posX", 0.0); @@ -969,7 +846,8 @@ eqn_gr_maxwell_tetrad_lw_new(lua_State *L) spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); } - with_lua_tbl_tbl(L, "neutronStarParameters") { + with_lua_tbl_tbl(L, "neutronStarParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double mass_quadrupole = glua_tbl_get_number(L, "massQuadrupole", 0.0); @@ -979,27 +857,27 @@ eqn_gr_maxwell_tetrad_lw_new(lua_State *L) double pos_y = glua_tbl_get_number(L, "posY", 0.0); double pos_z = glua_tbl_get_number(L, "posZ", 0.0); - spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); } gr_maxwell_tetrad_lw->magic = MOMENT_EQN_DEFAULT; - gr_maxwell_tetrad_lw->eqn = gkyl_wv_gr_maxwell_tetrad_inew( &(struct gkyl_wv_gr_maxwell_tetrad_inp) { - .light_speed = light_speed, - .e_fact = e_fact, - .b_fact = b_fact, - .spacetime = spacetime, - .reinit_freq = reinit_freq, - .rp_type = rp_type, - .use_gpu = false, - } - ); + gr_maxwell_tetrad_lw->eqn = gkyl_wv_gr_maxwell_tetrad_inew(&(struct gkyl_wv_gr_maxwell_tetrad_inp + ){.light_speed = light_speed, + .e_fact = e_fact, + .b_fact = b_fact, + .spacetime = spacetime, + .reinit_freq = reinit_freq, + .rp_type = rp_type, + .use_gpu = false}); gr_maxwell_tetrad_lw->has_nn = false; gr_maxwell_tetrad_lw->ann = 0; gr_maxwell_tetrad_lw->has_spacetime = true; gr_maxwell_tetrad_lw->spacetime = spacetime; // Create Lua userdata. - struct wv_eqn_lw **l_gr_maxwell_tetrad_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_gr_maxwell_tetrad_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_gr_maxwell_tetrad_lw = gr_maxwell_tetrad_lw; // Set metatable. @@ -1011,8 +889,8 @@ eqn_gr_maxwell_tetrad_lw_new(lua_State *L) // Equation constructor. static struct luaL_Reg eqn_gr_maxwell_tetrad_ctor[] = { - { "new", eqn_gr_maxwell_tetrad_lw_new }, - { 0, 0 } + {"new", eqn_gr_maxwell_tetrad_lw_new}, + {0, 0} }; /* *************************************************************************** */ @@ -1021,20 +899,22 @@ static struct luaL_Reg eqn_gr_maxwell_tetrad_ctor[] = { // GRUltraRelativisticEuler.new { gasGamma = 4.0 / 3.0, rpType = "hll" } // where rpType is one of "hll", "roe" or "lax". -static int -eqn_gr_ultra_rel_euler_lw_new(lua_State *L) +static int eqn_gr_ultra_rel_euler_lw_new(lua_State *L) { struct wv_eqn_lw *gr_ultra_rel_euler_lw = gkyl_malloc(sizeof(*gr_ultra_rel_euler_lw)); double gas_gamma = glua_tbl_get_number(L, "gasGamma", 4.0 / 3.0); const char *rp_str = glua_tbl_get_string(L, "rpType", "hll"); - enum gkyl_wv_gr_ultra_rel_euler_rp rp_type = gkyl_search_str_int_pair_by_str(gr_ultra_rel_euler_rp_type, rp_str, WV_GR_ULTRA_REL_EULER_RP_HLL); + enum gkyl_wv_gr_ultra_rel_euler_rp rp_type = gkyl_search_str_int_pair_by_str( + gr_ultra_rel_euler_rp_type, rp_str, WV_GR_ULTRA_REL_EULER_RP_HLL + ); struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); int reinit_freq = glua_tbl_get_integer(L, "reinitFreq", 100); - with_lua_tbl_tbl(L, "blackHoleParameters") { + with_lua_tbl_tbl(L, "blackHoleParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double pos_x = glua_tbl_get_number(L, "posX", 0.0); @@ -1044,7 +924,8 @@ eqn_gr_ultra_rel_euler_lw_new(lua_State *L) spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); } - with_lua_tbl_tbl(L, "neutronStarParameters") { + with_lua_tbl_tbl(L, "neutronStarParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double mass_quadrupole = glua_tbl_get_number(L, "massQuadrupole", 0.0); @@ -1054,25 +935,26 @@ eqn_gr_ultra_rel_euler_lw_new(lua_State *L) double pos_y = glua_tbl_get_number(L, "posY", 0.0); double pos_z = glua_tbl_get_number(L, "posZ", 0.0); - spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); } gr_ultra_rel_euler_lw->magic = MOMENT_EQN_DEFAULT; - gr_ultra_rel_euler_lw->eqn = gkyl_wv_gr_ultra_rel_euler_inew( &(struct gkyl_wv_gr_ultra_rel_euler_inp) { - .gas_gamma = gas_gamma, + gr_ultra_rel_euler_lw->eqn = + gkyl_wv_gr_ultra_rel_euler_inew(&(struct gkyl_wv_gr_ultra_rel_euler_inp + ){.gas_gamma = gas_gamma, .spacetime = spacetime, .reinit_freq = reinit_freq, .rp_type = rp_type, - .use_gpu = false, - } - ); + .use_gpu = false}); gr_ultra_rel_euler_lw->has_nn = false; gr_ultra_rel_euler_lw->ann = 0; gr_ultra_rel_euler_lw->has_spacetime = true; gr_ultra_rel_euler_lw->spacetime = spacetime; // Create Lua userdata. - struct wv_eqn_lw **l_gr_ultra_rel_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_gr_ultra_rel_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_gr_ultra_rel_euler_lw = gr_ultra_rel_euler_lw; // Set metatable. @@ -1084,8 +966,8 @@ eqn_gr_ultra_rel_euler_lw_new(lua_State *L) // Equation constructor. static struct luaL_Reg eqn_gr_ultra_rel_euler_ctor[] = { - { "new", eqn_gr_ultra_rel_euler_lw_new }, - { 0, 0 } + {"new", eqn_gr_ultra_rel_euler_lw_new}, + {0, 0} }; /* *********************************************************************************************** */ @@ -1094,20 +976,23 @@ static struct luaL_Reg eqn_gr_ultra_rel_euler_ctor[] = { // GRUltraRelativisticEulerTetrad.new { gasGamma = 4.0 / 3.0, rpType = "hll" } // where rpType is one of "hll", "roe" or "lax". -static int -eqn_gr_ultra_rel_euler_tetrad_lw_new(lua_State *L) +static int eqn_gr_ultra_rel_euler_tetrad_lw_new(lua_State *L) { - struct wv_eqn_lw *gr_ultra_rel_euler_tetrad_lw = gkyl_malloc(sizeof(*gr_ultra_rel_euler_tetrad_lw)); + struct wv_eqn_lw *gr_ultra_rel_euler_tetrad_lw = + gkyl_malloc(sizeof(*gr_ultra_rel_euler_tetrad_lw)); double gas_gamma = glua_tbl_get_number(L, "gasGamma", 4.0 / 3.0); const char *rp_str = glua_tbl_get_string(L, "rpType", "hll"); - enum gkyl_wv_gr_ultra_rel_euler_tetrad_rp rp_type = gkyl_search_str_int_pair_by_str(gr_ultra_rel_euler_tetrad_rp_type, rp_str, WV_GR_ULTRA_REL_EULER_TETRAD_RP_HLL); + enum gkyl_wv_gr_ultra_rel_euler_tetrad_rp rp_type = gkyl_search_str_int_pair_by_str( + gr_ultra_rel_euler_tetrad_rp_type, rp_str, WV_GR_ULTRA_REL_EULER_TETRAD_RP_HLL + ); struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); int reinit_freq = glua_tbl_get_integer(L, "reinitFreq", 100); - with_lua_tbl_tbl(L, "blackHoleParameters") { + with_lua_tbl_tbl(L, "blackHoleParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double pos_x = glua_tbl_get_number(L, "posX", 0.0); @@ -1117,7 +1002,8 @@ eqn_gr_ultra_rel_euler_tetrad_lw_new(lua_State *L) spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); } - with_lua_tbl_tbl(L, "neutronStarParameters") { + with_lua_tbl_tbl(L, "neutronStarParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double mass_quadrupole = glua_tbl_get_number(L, "massQuadrupole", 0.0); @@ -1127,25 +1013,27 @@ eqn_gr_ultra_rel_euler_tetrad_lw_new(lua_State *L) double pos_y = glua_tbl_get_number(L, "posY", 0.0); double pos_z = glua_tbl_get_number(L, "posZ", 0.0); - spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); } gr_ultra_rel_euler_tetrad_lw->magic = MOMENT_EQN_DEFAULT; - gr_ultra_rel_euler_tetrad_lw->eqn = gkyl_wv_gr_ultra_rel_euler_tetrad_inew( &(struct gkyl_wv_gr_ultra_rel_euler_tetrad_inp) { - .gas_gamma = gas_gamma, + gr_ultra_rel_euler_tetrad_lw->eqn = + gkyl_wv_gr_ultra_rel_euler_tetrad_inew(&(struct gkyl_wv_gr_ultra_rel_euler_tetrad_inp + ){.gas_gamma = gas_gamma, .spacetime = spacetime, .reinit_freq = reinit_freq, .rp_type = rp_type, - .use_gpu = false, - } - ); + .use_gpu = false}); gr_ultra_rel_euler_tetrad_lw->has_nn = false; gr_ultra_rel_euler_tetrad_lw->ann = 0; gr_ultra_rel_euler_tetrad_lw->has_spacetime = true; gr_ultra_rel_euler_tetrad_lw->spacetime = spacetime; // Create Lua userdata. - struct wv_eqn_lw **l_gr_ultra_rel_euler_tetrad_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_gr_ultra_rel_euler_tetrad_lw = + lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_gr_ultra_rel_euler_tetrad_lw = gr_ultra_rel_euler_tetrad_lw; // Set metatable. @@ -1157,8 +1045,8 @@ eqn_gr_ultra_rel_euler_tetrad_lw_new(lua_State *L) // Equation constructor. static struct luaL_Reg eqn_gr_ultra_rel_euler_tetrad_ctor[] = { - { "new", eqn_gr_ultra_rel_euler_tetrad_lw_new }, - { 0, 0 } + {"new", eqn_gr_ultra_rel_euler_tetrad_lw_new}, + {0, 0} }; /* **************************************************************** */ @@ -1167,20 +1055,21 @@ static struct luaL_Reg eqn_gr_ultra_rel_euler_tetrad_ctor[] = { // GREuler.new { gasGamma = 5.0 / 3.0, rpType = "hll" } // where rpType is one of "hll", "roe" or "lax". -static int -eqn_gr_euler_lw_new(lua_State *L) +static int eqn_gr_euler_lw_new(lua_State *L) { struct wv_eqn_lw *gr_euler_lw = gkyl_malloc(sizeof(*gr_euler_lw)); double gas_gamma = glua_tbl_get_number(L, "gasGamma", 5.0 / 3.0); const char *rp_str = glua_tbl_get_string(L, "rpType", "hll"); - enum gkyl_wv_gr_euler_rp rp_type = gkyl_search_str_int_pair_by_str(gr_euler_rp_type, rp_str, WV_GR_EULER_RP_HLL); + enum gkyl_wv_gr_euler_rp rp_type = + gkyl_search_str_int_pair_by_str(gr_euler_rp_type, rp_str, WV_GR_EULER_RP_HLL); struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); int reinit_freq = glua_tbl_get_integer(L, "reinitFreq", 100); - with_lua_tbl_tbl(L, "blackHoleParameters") { + with_lua_tbl_tbl(L, "blackHoleParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double pos_x = glua_tbl_get_number(L, "posX", 0.0); @@ -1190,7 +1079,8 @@ eqn_gr_euler_lw_new(lua_State *L) spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); } - with_lua_tbl_tbl(L, "neutronStarParameters") { + with_lua_tbl_tbl(L, "neutronStarParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double mass_quadrupole = glua_tbl_get_number(L, "massQuadrupole", 0.0); @@ -1200,25 +1090,25 @@ eqn_gr_euler_lw_new(lua_State *L) double pos_y = glua_tbl_get_number(L, "posY", 0.0); double pos_z = glua_tbl_get_number(L, "posZ", 0.0); - spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); } gr_euler_lw->magic = MOMENT_EQN_DEFAULT; - gr_euler_lw->eqn = gkyl_wv_gr_euler_inew( &(struct gkyl_wv_gr_euler_inp) { - .gas_gamma = gas_gamma, - .spacetime = spacetime, - .reinit_freq = reinit_freq, - .rp_type = rp_type, - .use_gpu = false, - } - ); + gr_euler_lw->eqn = gkyl_wv_gr_euler_inew(&(struct gkyl_wv_gr_euler_inp + ){.gas_gamma = gas_gamma, + .spacetime = spacetime, + .reinit_freq = reinit_freq, + .rp_type = rp_type, + .use_gpu = false}); gr_euler_lw->has_nn = false; gr_euler_lw->ann = 0; gr_euler_lw->has_spacetime = true; gr_euler_lw->spacetime = spacetime; // Create Lua userdata. - struct wv_eqn_lw **l_gr_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_gr_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_gr_euler_lw = gr_euler_lw; // Set metatable. @@ -1229,10 +1119,7 @@ eqn_gr_euler_lw_new(lua_State *L) } // Equation constructor. -static struct luaL_Reg eqn_gr_euler_ctor[] = { - { "new", eqn_gr_euler_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_gr_euler_ctor[] = {{"new", eqn_gr_euler_lw_new}, {0, 0}}; /* ************************************************************************************ */ /* General Relativistic Euler Equations in the Tetrad Basis (General Equation of State) */ @@ -1240,20 +1127,21 @@ static struct luaL_Reg eqn_gr_euler_ctor[] = { // GREulerTetrad.new { gasGamma = 5.0 / 3.0, rpType = "hll" } // where rpType is one of "hll", "roe" or "lax". -static int -eqn_gr_euler_tetrad_lw_new(lua_State *L) +static int eqn_gr_euler_tetrad_lw_new(lua_State *L) { struct wv_eqn_lw *gr_euler_tetrad_lw = gkyl_malloc(sizeof(*gr_euler_tetrad_lw)); double gas_gamma = glua_tbl_get_number(L, "gasGamma", 5.0 / 3.0); const char *rp_str = glua_tbl_get_string(L, "rpType", "hll"); - enum gkyl_wv_gr_euler_tetrad_rp rp_type = gkyl_search_str_int_pair_by_str(gr_euler_tetrad_rp_type, rp_str, WV_GR_EULER_TETRAD_RP_HLL); + enum gkyl_wv_gr_euler_tetrad_rp rp_type = + gkyl_search_str_int_pair_by_str(gr_euler_tetrad_rp_type, rp_str, WV_GR_EULER_TETRAD_RP_HLL); struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); int reinit_freq = glua_tbl_get_integer(L, "reinitFreq", 100); - with_lua_tbl_tbl(L, "blackHoleParameters") { + with_lua_tbl_tbl(L, "blackHoleParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double pos_x = glua_tbl_get_number(L, "posX", 0.0); @@ -1263,7 +1151,8 @@ eqn_gr_euler_tetrad_lw_new(lua_State *L) spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); } - with_lua_tbl_tbl(L, "neutronStarParameters") { + with_lua_tbl_tbl(L, "neutronStarParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double mass_quadrupole = glua_tbl_get_number(L, "massQuadrupole", 0.0); @@ -1273,25 +1162,25 @@ eqn_gr_euler_tetrad_lw_new(lua_State *L) double pos_y = glua_tbl_get_number(L, "posY", 0.0); double pos_z = glua_tbl_get_number(L, "posZ", 0.0); - spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); } gr_euler_tetrad_lw->magic = MOMENT_EQN_DEFAULT; - gr_euler_tetrad_lw->eqn = gkyl_wv_gr_euler_tetrad_inew( &(struct gkyl_wv_gr_euler_tetrad_inp) { - .gas_gamma = gas_gamma, - .spacetime = spacetime, - .reinit_freq = reinit_freq, - .rp_type = rp_type, - .use_gpu = false, - } - ); + gr_euler_tetrad_lw->eqn = gkyl_wv_gr_euler_tetrad_inew(&(struct gkyl_wv_gr_euler_tetrad_inp + ){.gas_gamma = gas_gamma, + .spacetime = spacetime, + .reinit_freq = reinit_freq, + .rp_type = rp_type, + .use_gpu = false}); gr_euler_tetrad_lw->has_nn = false; gr_euler_tetrad_lw->ann = 0; gr_euler_tetrad_lw->has_spacetime = true; gr_euler_tetrad_lw->spacetime = spacetime; // Create Lua userdata. - struct wv_eqn_lw **l_gr_euler_tetrad_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_gr_euler_tetrad_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_gr_euler_tetrad_lw = gr_euler_tetrad_lw; // Set metatable. @@ -1302,18 +1191,14 @@ eqn_gr_euler_tetrad_lw_new(lua_State *L) } // Equation constructor. -static struct luaL_Reg eqn_gr_euler_tetrad_ctor[] = { - { "new", eqn_gr_euler_tetrad_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_gr_euler_tetrad_ctor[] = {{"new", eqn_gr_euler_tetrad_lw_new}, {0, 0}}; /* ******************************************************************* */ /* Coupled Fluid-Einstein Equations (Plane-Polarized Gowdy Spacetimes) */ /* ******************************************************************* */ // GRMedium.new { gasGamma = 4.0 / 3.0, kappa = 8.0 * pi, rpType = "lax" }. -static int -eqn_gr_medium_lw_new(lua_State *L) +static int eqn_gr_medium_lw_new(lua_State *L) { struct wv_eqn_lw *gr_medium_lw = gkyl_malloc(sizeof(*gr_medium_lw)); @@ -1321,23 +1206,19 @@ eqn_gr_medium_lw_new(lua_State *L) double kappa = glua_tbl_get_number(L, "kappa", 8.0 * M_PI); const char *rp_str = glua_tbl_get_string(L, "rpType", "lax"); - enum gkyl_wv_gr_medium_rp rp_type = gkyl_search_str_int_pair_by_str(gr_medium_rp_type, rp_str, WV_GR_MEDIUM_RP_LAX); + enum gkyl_wv_gr_medium_rp rp_type = + gkyl_search_str_int_pair_by_str(gr_medium_rp_type, rp_str, WV_GR_MEDIUM_RP_LAX); gr_medium_lw->magic = MOMENT_EQN_DEFAULT; - gr_medium_lw->eqn = gkyl_wv_gr_medium_inew( &(struct gkyl_wv_gr_medium_inp) { - .gas_gamma = gas_gamma, - .kappa = kappa, - .rp_type = rp_type, - .use_gpu = false, - } - ); + gr_medium_lw->eqn = gkyl_wv_gr_medium_inew(&(struct gkyl_wv_gr_medium_inp + ){.gas_gamma = gas_gamma, .kappa = kappa, .rp_type = rp_type, .use_gpu = false}); gr_medium_lw->has_nn = false; gr_medium_lw->ann = 0; gr_medium_lw->has_spacetime = false; gr_medium_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_gr_medium_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_gr_medium_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_gr_medium_lw = gr_medium_lw; // Set metatable. @@ -1348,42 +1229,39 @@ eqn_gr_medium_lw_new(lua_State *L) } // Equation constructor. -static struct luaL_Reg eqn_gr_medium_ctor[] = { - { "new", eqn_gr_medium_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_gr_medium_ctor[] = {{"new", eqn_gr_medium_lw_new}, {0, 0}}; /* ************************************************ */ /* Vacuum Einstein Equations (Bona-Masso Formalism) */ /* ************************************************ */ // VacuumEinstein.new { excisionThreshold = 0.3, rpType = "hll" }. -static int -eqn_vacuum_einstein_lw_new(lua_State *L) +static int eqn_vacuum_einstein_lw_new(lua_State *L) { struct wv_eqn_lw *vacuum_einstein_lw = gkyl_malloc(sizeof(*vacuum_einstein_lw)); double excision_threshold = glua_tbl_get_number(L, "excisionThreshold", 0.3); const char *rp_str = glua_tbl_get_string(L, "rpType", "hll"); - enum gkyl_wv_vacuum_einstein_rp rp_type = gkyl_search_str_int_pair_by_str(vacuum_einstein_rp_type, rp_str, WV_VACUUM_EINSTEIN_RP_HLL); - enum gkyl_spacetime_slicing spacetime_slicing = glua_tbl_get_integer(L, "spacetimeSlicing", GKYL_GEODESIC_SLICING); - enum gkyl_spacetime_evolution spacetime_evolution = glua_tbl_get_integer(L, "spacetimeEvolution", GKYL_RICCI_EVOLUTION); + enum gkyl_wv_vacuum_einstein_rp rp_type = + gkyl_search_str_int_pair_by_str(vacuum_einstein_rp_type, rp_str, WV_VACUUM_EINSTEIN_RP_HLL); + enum gkyl_spacetime_slicing spacetime_slicing = + glua_tbl_get_integer(L, "spacetimeSlicing", GKYL_GEODESIC_SLICING); + enum gkyl_spacetime_evolution spacetime_evolution = + glua_tbl_get_integer(L, "spacetimeEvolution", GKYL_RICCI_EVOLUTION); vacuum_einstein_lw->magic = MOMENT_EQN_DEFAULT; - vacuum_einstein_lw->eqn = gkyl_wv_vacuum_einstein_inew( &(struct gkyl_wv_vacuum_einstein_inp) { - .excision_threshold = excision_threshold, - .spacetime_slicing = spacetime_slicing, - .spacetime_evolution = spacetime_evolution, - .rp_type = rp_type, - .use_gpu = false, - } - ); + vacuum_einstein_lw->eqn = gkyl_wv_vacuum_einstein_inew(&(struct gkyl_wv_vacuum_einstein_inp + ){.excision_threshold = excision_threshold, + .spacetime_slicing = spacetime_slicing, + .spacetime_evolution = spacetime_evolution, + .rp_type = rp_type, + .use_gpu = false}); vacuum_einstein_lw->has_nn = false; vacuum_einstein_lw->ann = 0; // Create Lua userdata. - struct wv_eqn_lw **l_vacuum_einstein_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_vacuum_einstein_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_vacuum_einstein_lw = vacuum_einstein_lw; // Set metatable. @@ -1394,42 +1272,43 @@ eqn_vacuum_einstein_lw_new(lua_State *L) } // Equation constructor. -static struct luaL_Reg eqn_vacuum_einstein_ctor[] = { - { "new", eqn_vacuum_einstein_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_vacuum_einstein_ctor[] = {{"new", eqn_vacuum_einstein_lw_new}, {0, 0}}; /* ********************************************************** */ /* Vacuum Einstein Equations (Conformal Bona-Masso Formalism) */ /* ********************************************************** */ // VacuumEinsteinConformal.new { excisionThreshold = 0.3, rpType = "hll" }. -static int -eqn_vacuum_einstein_conformal_lw_new(lua_State *L) +static int eqn_vacuum_einstein_conformal_lw_new(lua_State *L) { - struct wv_eqn_lw *vacuum_einstein_conformal_lw = gkyl_malloc(sizeof(*vacuum_einstein_conformal_lw)); + struct wv_eqn_lw *vacuum_einstein_conformal_lw = + gkyl_malloc(sizeof(*vacuum_einstein_conformal_lw)); double excision_threshold = glua_tbl_get_number(L, "excisionThreshold", 0.3); const char *rp_str = glua_tbl_get_string(L, "rpType", "hll"); - enum gkyl_wv_vacuum_einstein_conformal_rp rp_type = gkyl_search_str_int_pair_by_str(vacuum_einstein_conformal_rp_type, rp_str, WV_VACUUM_EINSTEIN_CONFORMAL_RP_HLL); - enum gkyl_spacetime_slicing spacetime_slicing = glua_tbl_get_integer(L, "spacetimeSlicing", GKYL_GEODESIC_SLICING); - enum gkyl_spacetime_evolution spacetime_evolution = glua_tbl_get_integer(L, "spacetimeEvolution", GKYL_RICCI_EVOLUTION); + enum gkyl_wv_vacuum_einstein_conformal_rp rp_type = gkyl_search_str_int_pair_by_str( + vacuum_einstein_conformal_rp_type, rp_str, WV_VACUUM_EINSTEIN_CONFORMAL_RP_HLL + ); + enum gkyl_spacetime_slicing spacetime_slicing = + glua_tbl_get_integer(L, "spacetimeSlicing", GKYL_GEODESIC_SLICING); + enum gkyl_spacetime_evolution spacetime_evolution = + glua_tbl_get_integer(L, "spacetimeEvolution", GKYL_RICCI_EVOLUTION); vacuum_einstein_conformal_lw->magic = MOMENT_EQN_DEFAULT; - vacuum_einstein_conformal_lw->eqn = gkyl_wv_vacuum_einstein_conformal_inew( &(struct gkyl_wv_vacuum_einstein_conformal_inp) { - .excision_threshold = excision_threshold, + vacuum_einstein_conformal_lw->eqn = + gkyl_wv_vacuum_einstein_conformal_inew(&(struct gkyl_wv_vacuum_einstein_conformal_inp + ){.excision_threshold = excision_threshold, .spacetime_slicing = spacetime_slicing, .spacetime_evolution = spacetime_evolution, .rp_type = rp_type, - .use_gpu = false, - } - ); + .use_gpu = false}); vacuum_einstein_conformal_lw->has_nn = false; vacuum_einstein_conformal_lw->ann = 0; // Create Lua userdata. - struct wv_eqn_lw **l_vacuum_einstein_conformal_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_vacuum_einstein_conformal_lw = + lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_vacuum_einstein_conformal_lw = vacuum_einstein_conformal_lw; // Set metatable. @@ -1441,8 +1320,8 @@ eqn_vacuum_einstein_conformal_lw_new(lua_State *L) // Equation constructor. static struct luaL_Reg eqn_vacuum_einstein_conformal_ctor[] = { - { "new", eqn_vacuum_einstein_conformal_lw_new }, - { 0, 0 } + {"new", eqn_vacuum_einstein_conformal_lw_new}, + {0, 0} }; /* ******************************************************************** */ @@ -1452,8 +1331,7 @@ static struct luaL_Reg eqn_vacuum_einstein_conformal_ctor[] = { // GRTwoFluid.new { massElc = 1.0 / 1836.2, massIon = 1.0, chargeElc = -1.0, chargeIon = 1.0, gasGammaElc = 5.0 / 3.0, gasGammaIon = 5.0 / 3.0, // lightSpeed = 1.0, elcErrorSpeedFactor = 0.0, mgnErrorSpeedFactor = 0.0, rpType = "hll" } // where rpType is one of "hll" or "lax". -static int -eqn_gr_twofluid_lw_new(lua_State *L) +static int eqn_gr_twofluid_lw_new(lua_State *L) { struct wv_eqn_lw *gr_twofluid_lw = gkyl_malloc(sizeof(*gr_twofluid_lw)); @@ -1469,12 +1347,14 @@ eqn_gr_twofluid_lw_new(lua_State *L) double b_fact = glua_tbl_get_number(L, "mgnErrorSpeedFactor", 0.0); const char *rp_str = glua_tbl_get_string(L, "rpType", "hll"); - enum gkyl_wv_gr_twofluid_rp rp_type = gkyl_search_str_int_pair_by_str(gr_twofluid_rp_type, rp_str, WV_GR_TWOFLUID_RP_HLL); + enum gkyl_wv_gr_twofluid_rp rp_type = + gkyl_search_str_int_pair_by_str(gr_twofluid_rp_type, rp_str, WV_GR_TWOFLUID_RP_HLL); struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); int reinit_freq = glua_tbl_get_integer(L, "reinitFreq", 100); - with_lua_tbl_tbl(L, "blackHoleParameters") { + with_lua_tbl_tbl(L, "blackHoleParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double pos_x = glua_tbl_get_number(L, "posX", 0.0); @@ -1484,7 +1364,8 @@ eqn_gr_twofluid_lw_new(lua_State *L) spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); } - with_lua_tbl_tbl(L, "neutronStarParameters") { + with_lua_tbl_tbl(L, "neutronStarParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double mass_quadrupole = glua_tbl_get_number(L, "massQuadrupole", 0.0); @@ -1494,33 +1375,33 @@ eqn_gr_twofluid_lw_new(lua_State *L) double pos_y = glua_tbl_get_number(L, "posY", 0.0); double pos_z = glua_tbl_get_number(L, "posZ", 0.0); - spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); } gr_twofluid_lw->magic = MOMENT_EQN_DEFAULT; - gr_twofluid_lw->eqn = gkyl_wv_gr_twofluid_inew( &(struct gkyl_wv_gr_twofluid_inp) { - .mass_elc = mass_elc, - .mass_ion = mass_ion, - .charge_elc = charge_elc, - .charge_ion = charge_ion, - .gas_gamma_elc = gas_gamma_elc, - .gas_gamma_ion = gas_gamma_ion, - .light_speed = light_speed, - .e_fact = e_fact, - .b_fact = b_fact, - .spacetime = spacetime, - .reinit_freq = reinit_freq, - .rp_type = rp_type, - .use_gpu = false, - } - ); + gr_twofluid_lw->eqn = gkyl_wv_gr_twofluid_inew(&(struct gkyl_wv_gr_twofluid_inp + ){.mass_elc = mass_elc, + .mass_ion = mass_ion, + .charge_elc = charge_elc, + .charge_ion = charge_ion, + .gas_gamma_elc = gas_gamma_elc, + .gas_gamma_ion = gas_gamma_ion, + .light_speed = light_speed, + .e_fact = e_fact, + .b_fact = b_fact, + .spacetime = spacetime, + .reinit_freq = reinit_freq, + .rp_type = rp_type, + .use_gpu = false}); gr_twofluid_lw->has_nn = false; gr_twofluid_lw->ann = 0; gr_twofluid_lw->has_spacetime = true; gr_twofluid_lw->spacetime = spacetime; // Create Lua userdata. - struct wv_eqn_lw **l_gr_twofluid_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_gr_twofluid_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_gr_twofluid_lw = gr_twofluid_lw; // Set metatable. @@ -1531,10 +1412,7 @@ eqn_gr_twofluid_lw_new(lua_State *L) } // Equation constructor. -static struct luaL_Reg eqn_gr_twofluid_ctor[] = { - { "new", eqn_gr_twofluid_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_gr_twofluid_ctor[] = {{"new", eqn_gr_twofluid_lw_new}, {0, 0}}; /* **************************************************************************************** */ /* General Relativistic Two-Fluid Equations in the Tetrad Basis (General Equation of State) */ @@ -1543,8 +1421,7 @@ static struct luaL_Reg eqn_gr_twofluid_ctor[] = { // GRTwoFluidTetrad.new { massElc = 1.0 / 1836.2, massIon = 1.0, chargeElc = -1.0, chargeIon = 1.0, gasGammaElc = 5.0 / 3.0, gasGammaIon = 5.0 / 3.0, // lightSpeed = 1.0, elcErrorSpeedFactor = 0.0, mgnErrorSpeedFactor = 0.0, rpType = "hll" } // where rpType is one of "hll" or "lax". -static int -eqn_gr_twofluid_tetrad_lw_new(lua_State *L) +static int eqn_gr_twofluid_tetrad_lw_new(lua_State *L) { struct wv_eqn_lw *gr_twofluid_tetrad_lw = gkyl_malloc(sizeof(*gr_twofluid_tetrad_lw)); @@ -1560,12 +1437,15 @@ eqn_gr_twofluid_tetrad_lw_new(lua_State *L) double b_fact = glua_tbl_get_number(L, "mgnErrorSpeedFactor", 0.0); const char *rp_str = glua_tbl_get_string(L, "rpType", "hll"); - enum gkyl_wv_gr_twofluid_tetrad_rp rp_type = gkyl_search_str_int_pair_by_str(gr_twofluid_tetrad_rp_type, rp_str, WV_GR_TWOFLUID_TETRAD_RP_HLL); + enum gkyl_wv_gr_twofluid_tetrad_rp rp_type = gkyl_search_str_int_pair_by_str( + gr_twofluid_tetrad_rp_type, rp_str, WV_GR_TWOFLUID_TETRAD_RP_HLL + ); struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); int reinit_freq = glua_tbl_get_integer(L, "reinitFreq", 100); - with_lua_tbl_tbl(L, "blackHoleParameters") { + with_lua_tbl_tbl(L, "blackHoleParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double pos_x = glua_tbl_get_number(L, "posX", 0.0); @@ -1575,7 +1455,8 @@ eqn_gr_twofluid_tetrad_lw_new(lua_State *L) spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); } - with_lua_tbl_tbl(L, "neutronStarParameters") { + with_lua_tbl_tbl(L, "neutronStarParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double mass_quadrupole = glua_tbl_get_number(L, "massQuadrupole", 0.0); @@ -1585,12 +1466,15 @@ eqn_gr_twofluid_tetrad_lw_new(lua_State *L) double pos_y = glua_tbl_get_number(L, "posY", 0.0); double pos_z = glua_tbl_get_number(L, "posZ", 0.0); - spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); } gr_twofluid_tetrad_lw->magic = MOMENT_EQN_DEFAULT; - gr_twofluid_tetrad_lw->eqn = gkyl_wv_gr_twofluid_tetrad_inew( &(struct gkyl_wv_gr_twofluid_tetrad_inp) { - .mass_elc = mass_elc, + gr_twofluid_tetrad_lw->eqn = + gkyl_wv_gr_twofluid_tetrad_inew(&(struct gkyl_wv_gr_twofluid_tetrad_inp + ){.mass_elc = mass_elc, .mass_ion = mass_ion, .charge_elc = charge_elc, .charge_ion = charge_ion, @@ -1602,16 +1486,14 @@ eqn_gr_twofluid_tetrad_lw_new(lua_State *L) .spacetime = spacetime, .reinit_freq = reinit_freq, .rp_type = rp_type, - .use_gpu = false, - } - ); + .use_gpu = false}); gr_twofluid_tetrad_lw->has_nn = false; gr_twofluid_tetrad_lw->ann = 0; gr_twofluid_tetrad_lw->has_spacetime = true; gr_twofluid_tetrad_lw->spacetime = spacetime; // Create Lua userdata. - struct wv_eqn_lw **l_gr_twofluid_tetrad_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_gr_twofluid_tetrad_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_gr_twofluid_tetrad_lw = gr_twofluid_tetrad_lw; // Set metatable. @@ -1623,8 +1505,8 @@ eqn_gr_twofluid_tetrad_lw_new(lua_State *L) // Equation constructor. static struct luaL_Reg eqn_gr_twofluid_tetrad_ctor[] = { - { "new", eqn_gr_twofluid_tetrad_lw_new }, - { 0, 0 } + {"new", eqn_gr_twofluid_tetrad_lw_new}, + {0, 0} }; /* ********************************************************************************* */ @@ -1633,8 +1515,7 @@ static struct luaL_Reg eqn_gr_twofluid_tetrad_ctor[] = { // GRMHD.new { gasGamma = 5.0 / 3.0, lightSpeed = 1.0, mgnErrorSpeedFactor = 0.0, rpType = "hll" } // where rpType is one of "hll" or "lax". -static int -eqn_gr_mhd_lw_new(lua_State *L) +static int eqn_gr_mhd_lw_new(lua_State *L) { struct wv_eqn_lw *gr_mhd_lw = gkyl_malloc(sizeof(*gr_mhd_lw)); @@ -1643,12 +1524,14 @@ eqn_gr_mhd_lw_new(lua_State *L) double b_fact = glua_tbl_get_number(L, "mgnErrorSpeedFactor", 0.0); const char *rp_str = glua_tbl_get_string(L, "rpType", "hll"); - enum gkyl_wv_gr_mhd_rp rp_type = gkyl_search_str_int_pair_by_str(gr_mhd_rp_type, rp_str, WV_GR_MHD_RP_HLL); + enum gkyl_wv_gr_mhd_rp rp_type = + gkyl_search_str_int_pair_by_str(gr_mhd_rp_type, rp_str, WV_GR_MHD_RP_HLL); struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); int reinit_freq = glua_tbl_get_integer(L, "reinitFreq", 100); - with_lua_tbl_tbl(L, "blackHoleParameters") { + with_lua_tbl_tbl(L, "blackHoleParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double pos_x = glua_tbl_get_number(L, "posX", 0.0); @@ -1658,7 +1541,8 @@ eqn_gr_mhd_lw_new(lua_State *L) spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); } - with_lua_tbl_tbl(L, "neutronStarParameters") { + with_lua_tbl_tbl(L, "neutronStarParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double mass_quadrupole = glua_tbl_get_number(L, "massQuadrupole", 0.0); @@ -1668,30 +1552,30 @@ eqn_gr_mhd_lw_new(lua_State *L) double pos_y = glua_tbl_get_number(L, "posY", 0.0); double pos_z = glua_tbl_get_number(L, "posZ", 0.0); - spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); } int spacetime_gauge = glua_tbl_get_integer(L, "spacetimeGauge", GKYL_STATIC_GAUGE); gr_mhd_lw->magic = MOMENT_EQN_DEFAULT; - gr_mhd_lw->eqn = gkyl_wv_gr_mhd_inew( &(struct gkyl_wv_gr_mhd_inp) { - .gas_gamma = gas_gamma, - .light_speed = light_speed, - .b_fact = b_fact, - .spacetime = spacetime, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .rp_type = rp_type, - .use_gpu = false, - } - ); + gr_mhd_lw->eqn = gkyl_wv_gr_mhd_inew(&(struct gkyl_wv_gr_mhd_inp + ){.gas_gamma = gas_gamma, + .light_speed = light_speed, + .b_fact = b_fact, + .spacetime = spacetime, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .rp_type = rp_type, + .use_gpu = false}); gr_mhd_lw->has_nn = false; gr_mhd_lw->ann = 0; gr_mhd_lw->has_spacetime = true; gr_mhd_lw->spacetime = spacetime; // Create Lua userdata. - struct wv_eqn_lw **l_gr_mhd_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_gr_mhd_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_gr_mhd_lw = gr_mhd_lw; // Set metatable. @@ -1702,10 +1586,7 @@ eqn_gr_mhd_lw_new(lua_State *L) } // Equation constructor. -static struct luaL_Reg eqn_gr_mhd_ctor[] = { - { "new", eqn_gr_mhd_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_gr_mhd_ctor[] = {{"new", eqn_gr_mhd_lw_new}, {0, 0}}; /* ***************************************************************************************************** */ /* General Relativistic Magnetohydrodynamics Equations in the Tetrad Basis (Ideal Gas Equation of State) */ @@ -1713,8 +1594,7 @@ static struct luaL_Reg eqn_gr_mhd_ctor[] = { // GRMHDTetrad.new { gasGamma = 5.0 / 3.0, lightSpeed = 1.0, mgnErrorSpeedFactor = 0.0, rpType = "hll" } // where rpType is one of "hll" or "lax". -static int -eqn_gr_mhd_tetrad_lw_new(lua_State *L) +static int eqn_gr_mhd_tetrad_lw_new(lua_State *L) { struct wv_eqn_lw *gr_mhd_tetrad_lw = gkyl_malloc(sizeof(*gr_mhd_tetrad_lw)); @@ -1723,12 +1603,14 @@ eqn_gr_mhd_tetrad_lw_new(lua_State *L) double b_fact = glua_tbl_get_number(L, "mgnErrorSpeedFactor", 0.0); const char *rp_str = glua_tbl_get_string(L, "rpType", "hll"); - enum gkyl_wv_gr_mhd_tetrad_rp rp_type = gkyl_search_str_int_pair_by_str(gr_mhd_tetrad_rp_type, rp_str, WV_GR_MHD_TETRAD_RP_HLL); + enum gkyl_wv_gr_mhd_tetrad_rp rp_type = + gkyl_search_str_int_pair_by_str(gr_mhd_tetrad_rp_type, rp_str, WV_GR_MHD_TETRAD_RP_HLL); struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); int reinit_freq = glua_tbl_get_integer(L, "reinitFreq", 100); - with_lua_tbl_tbl(L, "blackHoleParameters") { + with_lua_tbl_tbl(L, "blackHoleParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double pos_x = glua_tbl_get_number(L, "posX", 0.0); @@ -1738,7 +1620,8 @@ eqn_gr_mhd_tetrad_lw_new(lua_State *L) spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); } - with_lua_tbl_tbl(L, "neutronStarParameters") { + with_lua_tbl_tbl(L, "neutronStarParameters") + { double mass = glua_tbl_get_number(L, "mass", 1.0); double spin = glua_tbl_get_number(L, "spin", 0.0); double mass_quadrupole = glua_tbl_get_number(L, "massQuadrupole", 0.0); @@ -1748,30 +1631,30 @@ eqn_gr_mhd_tetrad_lw_new(lua_State *L) double pos_y = glua_tbl_get_number(L, "posY", 0.0); double pos_z = glua_tbl_get_number(L, "posZ", 0.0); - spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); } int spacetime_gauge = glua_tbl_get_integer(L, "spacetimeGauge", GKYL_STATIC_GAUGE); gr_mhd_tetrad_lw->magic = MOMENT_EQN_DEFAULT; - gr_mhd_tetrad_lw->eqn = gkyl_wv_gr_mhd_tetrad_inew( &(struct gkyl_wv_gr_mhd_tetrad_inp) { - .gas_gamma = gas_gamma, - .light_speed = light_speed, - .b_fact = b_fact, - .spacetime = spacetime, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .rp_type = rp_type, - .use_gpu = false, - } - ); + gr_mhd_tetrad_lw->eqn = gkyl_wv_gr_mhd_tetrad_inew(&(struct gkyl_wv_gr_mhd_tetrad_inp + ){.gas_gamma = gas_gamma, + .light_speed = light_speed, + .b_fact = b_fact, + .spacetime = spacetime, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .rp_type = rp_type, + .use_gpu = false}); gr_mhd_tetrad_lw->has_nn = false; gr_mhd_tetrad_lw->ann = 0; gr_mhd_tetrad_lw->has_spacetime = true; gr_mhd_tetrad_lw->spacetime = spacetime; // Create Lua userdata. - struct wv_eqn_lw **l_gr_mhd_tetrad_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_gr_mhd_tetrad_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_gr_mhd_tetrad_lw = gr_mhd_tetrad_lw; // Set metatable. @@ -1782,18 +1665,14 @@ eqn_gr_mhd_tetrad_lw_new(lua_State *L) } // Equation constructor. -static struct luaL_Reg eqn_gr_mhd_tetrad_ctor[] = { - { "new", eqn_gr_mhd_tetrad_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_gr_mhd_tetrad_ctor[] = {{"new", eqn_gr_mhd_tetrad_lw_new}, {0, 0}}; /* ************************* */ /* Linear Advection Equation */ /* ************************* */ // Advection.new { advectionSpeed = 1.0 } -static int -eqn_advect_lw_new(lua_State *L) +static int eqn_advect_lw_new(lua_State *L) { struct wv_eqn_lw *advect_lw = gkyl_malloc(sizeof(*advect_lw)); @@ -1807,29 +1686,25 @@ eqn_advect_lw_new(lua_State *L) advect_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_advect_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_advect_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_advect_lw = advect_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, MOMENT_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_advect_ctor[] = { - { "new", eqn_advect_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_advect_ctor[] = {{"new", eqn_advect_lw_new}, {0, 0}}; /* ************************* */ /* Inviscid Burgers Equation */ /* ************************* */ // Burgers.new { } -static int -eqn_burgers_lw_new(lua_State *L) +static int eqn_burgers_lw_new(lua_State *L) { struct wv_eqn_lw *burgers_lw = gkyl_malloc(sizeof(*burgers_lw)); @@ -1841,25 +1716,21 @@ eqn_burgers_lw_new(lua_State *L) burgers_lw->spacetime = 0; // Create Lua userdata. - struct wv_eqn_lw **l_burgers_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_burgers_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_burgers_lw = burgers_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, MOMENT_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_burgers_ctor[] = { - { "new", eqn_burgers_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_burgers_ctor[] = {{"new", eqn_burgers_lw_new}, {0, 0}}; // Register and load all wave equation objects. -static void -eqn_openlibs(lua_State *L) +static void eqn_openlibs(lua_State *L) { luaL_newmetatable(L, MOMENT_WAVE_EQN_METATABLE_NM); @@ -1871,7 +1742,7 @@ eqn_openlibs(lua_State *L) luaL_register(L, "G0.Moments.Eq.IsoEuler", eqn_iso_euler_ctor); luaL_register(L, "G0.Moments.Eq.SrEuler", eqn_sr_euler_ctor); luaL_register(L, "G0.Moments.Eq.ColdFluid", eqn_coldfluid_ctor); - luaL_register(L, "G0.Moments.Eq.TenMoment", eqn_tenmoment_ctor); + luaL_register(L, "G0.Moments.Eq.TenMoment", eqn_tenmoment_ctor); luaL_register(L, "G0.Moments.Eq.MHD", eqn_mhd_ctor); luaL_register(L, "G0.Moments.Eq.ReactiveEuler", eqn_reactive_euler_ctor); luaL_register(L, "G0.Moments.Eq.EulerMixture", eqn_euler_mixture_ctor); @@ -1906,8 +1777,7 @@ struct gr_spacetime_lw { }; // Clean up memory allocated for spacetime object. -static int -gr_spacetime_lw_gc(lua_State *L) +static int gr_spacetime_lw_gc(lua_State *L) { struct gr_spacetime_lw **l_gr_lw = GKYL_CHECK_UDATA(L, MOMENT_SPACETIME_METATABLE_NM); struct gr_spacetime_lw *gr_lw = *l_gr_lw; @@ -1919,8 +1789,7 @@ gr_spacetime_lw_gc(lua_State *L) } // Acquire spacetime object. -static struct gkyl_gr_spacetime* -gr_spacetime_get(lua_State *L) +static struct gkyl_gr_spacetime *gr_spacetime_get(lua_State *L) { struct gr_spacetime_lw **l_gr_lw = luaL_checkudata(L, -1, MOMENT_SPACETIME_METATABLE_NM); struct gr_spacetime_lw *gr_lw = *l_gr_lw; @@ -1932,19 +1801,16 @@ gr_spacetime_get(lua_State *L) /* Minkowski Spacetime */ /* ******************* */ -static int -spacetime_minkowski_lw_new(lua_State *L) +static int spacetime_minkowski_lw_new(lua_State *L) { struct gr_spacetime_lw *minkowski_lw = gkyl_malloc(sizeof(*minkowski_lw)); minkowski_lw->magic = MOMENT_SPACETIME_DEFAULT; - minkowski_lw->spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + minkowski_lw->spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); // Create Lua userdata. - struct gr_spacetime_lw **l_minkowski_lw = lua_newuserdata(L, sizeof(struct gr_spacetime_lw*)); + struct gr_spacetime_lw **l_minkowski_lw = lua_newuserdata(L, sizeof(struct gr_spacetime_lw *)); *l_minkowski_lw = minkowski_lw; // Set metatable. @@ -1954,20 +1820,17 @@ spacetime_minkowski_lw_new(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_spatial_metric_tensor(lua_State *L) +static int spacetime_minkowski_lw_spatial_metric_tensor(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); double y = luaL_checknumber(L, 3); double z = luaL_checknumber(L, 4); - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -1999,20 +1862,17 @@ spacetime_minkowski_lw_spatial_metric_tensor(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_inv_spatial_metric_tensor(lua_State *L) +static int spacetime_minkowski_lw_inv_spatial_metric_tensor(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); double y = luaL_checknumber(L, 3); double z = luaL_checknumber(L, 4); - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -2044,13 +1904,10 @@ spacetime_minkowski_lw_inv_spatial_metric_tensor(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_spatial_metric_det(lua_State *L) +static int spacetime_minkowski_lw_spatial_metric_det(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2067,13 +1924,10 @@ spacetime_minkowski_lw_spatial_metric_det(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_lapse_function(lua_State *L) +static int spacetime_minkowski_lw_lapse_function(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2090,13 +1944,10 @@ spacetime_minkowski_lw_lapse_function(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_shift_vector(lua_State *L) +static int spacetime_minkowski_lw_shift_vector(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2120,13 +1971,10 @@ spacetime_minkowski_lw_shift_vector(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_extrinsic_curvature_tensor(lua_State *L) +static int spacetime_minkowski_lw_extrinsic_curvature_tensor(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2137,12 +1985,14 @@ spacetime_minkowski_lw_extrinsic_curvature_tensor(lua_State *L) double dy = luaL_checknumber(L, 6); double dz = luaL_checknumber(L, 7); - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } - spacetime->extrinsic_curvature_tensor_func(spacetime, t, x, y, z, dx, dy, dz, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, t, x, y, z, dx, dy, dz, &extrinsic_curvature + ); lua_createtable(L, 3, 0); @@ -2169,13 +2019,10 @@ spacetime_minkowski_lw_extrinsic_curvature_tensor(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_lapse_function_der(lua_State *L) +static int spacetime_minkowski_lw_lapse_function_der(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2203,13 +2050,10 @@ spacetime_minkowski_lw_lapse_function_der(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_shift_vector_der(lua_State *L) +static int spacetime_minkowski_lw_shift_vector_der(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2220,7 +2064,7 @@ spacetime_minkowski_lw_shift_vector_der(lua_State *L) double dy = luaL_checknumber(L, 6); double dz = luaL_checknumber(L, 7); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } @@ -2252,13 +2096,10 @@ spacetime_minkowski_lw_shift_vector_der(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_spatial_metric_tensor_der(lua_State *L) +static int spacetime_minkowski_lw_spatial_metric_tensor_der(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2269,9 +2110,9 @@ spacetime_minkowski_lw_spatial_metric_tensor_der(lua_State *L) double dy = luaL_checknumber(L, 6); double dz = luaL_checknumber(L, 7); - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -2315,13 +2156,10 @@ spacetime_minkowski_lw_spatial_metric_tensor_der(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_excision_region(lua_State *L) +static int spacetime_minkowski_lw_excision_region(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2338,13 +2176,10 @@ spacetime_minkowski_lw_excision_region(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_conformal_factor(lua_State *L) +static int spacetime_minkowski_lw_conformal_factor(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2361,13 +2196,10 @@ spacetime_minkowski_lw_conformal_factor(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_bssn_conformal_factor(lua_State *L) +static int spacetime_minkowski_lw_bssn_conformal_factor(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2384,13 +2216,10 @@ spacetime_minkowski_lw_bssn_conformal_factor(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_conformal_factor_der(lua_State *L) +static int spacetime_minkowski_lw_conformal_factor_der(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2418,13 +2247,10 @@ spacetime_minkowski_lw_conformal_factor_der(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_bssn_conformal_factor_der(lua_State *L) +static int spacetime_minkowski_lw_bssn_conformal_factor_der(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2436,7 +2262,9 @@ spacetime_minkowski_lw_bssn_conformal_factor_der(lua_State *L) double dz = luaL_checknumber(L, 7); double *bssn_conformal_factor_der = gkyl_malloc(sizeof(double[3])); - spacetime->bssn_conformal_factor_der_func(spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der); + spacetime->bssn_conformal_factor_der_func( + spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der + ); lua_createtable(L, 3, 0); @@ -2452,13 +2280,10 @@ spacetime_minkowski_lw_bssn_conformal_factor_der(lua_State *L) return 1; } -static int -spacetime_minkowski_lw_bssn_conformal_factor_der2(lua_State *L) +static int spacetime_minkowski_lw_bssn_conformal_factor_der2(lua_State *L) { - struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_inew( &(struct gkyl_gr_minkowski_inp) { - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = false}); double t = luaL_checknumber(L, 1); double x = luaL_checknumber(L, 2); @@ -2469,12 +2294,14 @@ spacetime_minkowski_lw_bssn_conformal_factor_der2(lua_State *L) double dy = luaL_checknumber(L, 6); double dz = luaL_checknumber(L, 7); - double **bssn_conformal_factor_der2 = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_factor_der2 = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_factor_der2[i] = gkyl_malloc(sizeof(double[3])); } - spacetime->bssn_conformal_factor_der2_func(spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der2); + spacetime->bssn_conformal_factor_der2_func( + spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der2 + ); lua_createtable(L, 3, 0); @@ -2503,31 +2330,30 @@ spacetime_minkowski_lw_bssn_conformal_factor_der2(lua_State *L) // Spacetime constructor. static struct luaL_Reg spacetime_minkowski_ctor[] = { - { "new", spacetime_minkowski_lw_new }, - { "spatialMetricTensor", spacetime_minkowski_lw_spatial_metric_tensor }, - { "invSpatialMetricTensor", spacetime_minkowski_lw_inv_spatial_metric_tensor }, - { "spatialMetricDeterminant", spacetime_minkowski_lw_spatial_metric_det }, - { "lapseFunction", spacetime_minkowski_lw_lapse_function }, - { "shiftVector", spacetime_minkowski_lw_shift_vector }, - { "extrinsicCurvatureTensor", spacetime_minkowski_lw_extrinsic_curvature_tensor }, - { "excisionRegion", spacetime_minkowski_lw_excision_region }, - { "lapseFunctionDer", spacetime_minkowski_lw_lapse_function_der }, - { "shiftVectorDer", spacetime_minkowski_lw_shift_vector_der }, - { "spatialMetricTensorDer", spacetime_minkowski_lw_spatial_metric_tensor_der }, - { "conformalFactor", spacetime_minkowski_lw_conformal_factor }, - { "bssnConformalFactor", spacetime_minkowski_lw_bssn_conformal_factor }, - { "conformalFactorDer", spacetime_minkowski_lw_conformal_factor_der }, - { "bssnConformalFactorDer", spacetime_minkowski_lw_bssn_conformal_factor_der }, - { "bssnConformalFactorDer2", spacetime_minkowski_lw_bssn_conformal_factor_der2 }, - { 0, 0 } + {"new", spacetime_minkowski_lw_new}, + {"spatialMetricTensor", spacetime_minkowski_lw_spatial_metric_tensor}, + {"invSpatialMetricTensor", spacetime_minkowski_lw_inv_spatial_metric_tensor}, + {"spatialMetricDeterminant", spacetime_minkowski_lw_spatial_metric_det}, + {"lapseFunction", spacetime_minkowski_lw_lapse_function}, + {"shiftVector", spacetime_minkowski_lw_shift_vector}, + {"extrinsicCurvatureTensor", spacetime_minkowski_lw_extrinsic_curvature_tensor}, + {"excisionRegion", spacetime_minkowski_lw_excision_region}, + {"lapseFunctionDer", spacetime_minkowski_lw_lapse_function_der}, + {"shiftVectorDer", spacetime_minkowski_lw_shift_vector_der}, + {"spatialMetricTensorDer", spacetime_minkowski_lw_spatial_metric_tensor_der}, + {"conformalFactor", spacetime_minkowski_lw_conformal_factor}, + {"bssnConformalFactor", spacetime_minkowski_lw_bssn_conformal_factor}, + {"conformalFactorDer", spacetime_minkowski_lw_conformal_factor_der}, + {"bssnConformalFactorDer", spacetime_minkowski_lw_bssn_conformal_factor_der}, + {"bssnConformalFactorDer2", spacetime_minkowski_lw_bssn_conformal_factor_der2}, + {0, 0} }; /* ******************** */ /* Black Hole Spacetime */ /* ******************** */ -static int -spacetime_blackhole_lw_new(lua_State *L) +static int spacetime_blackhole_lw_new(lua_State *L) { struct gr_spacetime_lw *blackhole_lw = gkyl_malloc(sizeof(*blackhole_lw)); @@ -2538,18 +2364,11 @@ spacetime_blackhole_lw_new(lua_State *L) double pos_z = luaL_checknumber(L, 5); blackhole_lw->magic = MOMENT_SPACETIME_DEFAULT; - blackhole_lw->spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + blackhole_lw->spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); // Create Lua userdata. - struct gr_spacetime_lw **l_blackhole_lw = lua_newuserdata(L, sizeof(struct gr_spacetime_lw*)); + struct gr_spacetime_lw **l_blackhole_lw = lua_newuserdata(L, sizeof(struct gr_spacetime_lw *)); *l_blackhole_lw = blackhole_lw; // Set metatable. @@ -2559,8 +2378,7 @@ spacetime_blackhole_lw_new(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_spatial_metric_tensor(lua_State *L) +static int spacetime_blackhole_lw_spatial_metric_tensor(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -2568,22 +2386,15 @@ spacetime_blackhole_lw_spatial_metric_tensor(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); double y = luaL_checknumber(L, 8); double z = luaL_checknumber(L, 9); - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -2615,8 +2426,7 @@ spacetime_blackhole_lw_spatial_metric_tensor(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_inv_spatial_metric_tensor(lua_State *L) +static int spacetime_blackhole_lw_inv_spatial_metric_tensor(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -2624,22 +2434,15 @@ spacetime_blackhole_lw_inv_spatial_metric_tensor(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); double y = luaL_checknumber(L, 8); double z = luaL_checknumber(L, 9); - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -2671,8 +2474,7 @@ spacetime_blackhole_lw_inv_spatial_metric_tensor(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_spatial_metric_det(lua_State *L) +static int spacetime_blackhole_lw_spatial_metric_det(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -2680,15 +2482,8 @@ spacetime_blackhole_lw_spatial_metric_det(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -2705,8 +2500,7 @@ spacetime_blackhole_lw_spatial_metric_det(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_lapse_function(lua_State *L) +static int spacetime_blackhole_lw_lapse_function(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -2714,15 +2508,8 @@ spacetime_blackhole_lw_lapse_function(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -2739,8 +2526,7 @@ spacetime_blackhole_lw_lapse_function(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_shift_vector(lua_State *L) +static int spacetime_blackhole_lw_shift_vector(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -2748,15 +2534,8 @@ spacetime_blackhole_lw_shift_vector(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -2780,8 +2559,7 @@ spacetime_blackhole_lw_shift_vector(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_extrinsic_curvature_tensor(lua_State *L) +static int spacetime_blackhole_lw_extrinsic_curvature_tensor(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -2789,15 +2567,8 @@ spacetime_blackhole_lw_extrinsic_curvature_tensor(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -2808,12 +2579,14 @@ spacetime_blackhole_lw_extrinsic_curvature_tensor(lua_State *L) double dy = luaL_checknumber(L, 11); double dz = luaL_checknumber(L, 12); - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } - spacetime->extrinsic_curvature_tensor_func(spacetime, t, x, y, z, dx, dy, dz, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, t, x, y, z, dx, dy, dz, &extrinsic_curvature + ); lua_createtable(L, 3, 0); @@ -2840,8 +2613,7 @@ spacetime_blackhole_lw_extrinsic_curvature_tensor(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_lapse_function_der(lua_State *L) +static int spacetime_blackhole_lw_lapse_function_der(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -2849,15 +2621,8 @@ spacetime_blackhole_lw_lapse_function_der(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -2885,8 +2650,7 @@ spacetime_blackhole_lw_lapse_function_der(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_shift_vector_der(lua_State *L) +static int spacetime_blackhole_lw_shift_vector_der(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -2894,15 +2658,8 @@ spacetime_blackhole_lw_shift_vector_der(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -2913,7 +2670,7 @@ spacetime_blackhole_lw_shift_vector_der(lua_State *L) double dy = luaL_checknumber(L, 11); double dz = luaL_checknumber(L, 12); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } @@ -2945,8 +2702,7 @@ spacetime_blackhole_lw_shift_vector_der(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_spatial_metric_tensor_der(lua_State *L) +static int spacetime_blackhole_lw_spatial_metric_tensor_der(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -2954,15 +2710,8 @@ spacetime_blackhole_lw_spatial_metric_tensor_der(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -2973,9 +2722,9 @@ spacetime_blackhole_lw_spatial_metric_tensor_der(lua_State *L) double dy = luaL_checknumber(L, 11); double dz = luaL_checknumber(L, 12); - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -3019,8 +2768,7 @@ spacetime_blackhole_lw_spatial_metric_tensor_der(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_excision_region(lua_State *L) +static int spacetime_blackhole_lw_excision_region(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3028,15 +2776,8 @@ spacetime_blackhole_lw_excision_region(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -3053,8 +2794,7 @@ spacetime_blackhole_lw_excision_region(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_conformal_factor(lua_State *L) +static int spacetime_blackhole_lw_conformal_factor(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3062,15 +2802,8 @@ spacetime_blackhole_lw_conformal_factor(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -3087,8 +2820,7 @@ spacetime_blackhole_lw_conformal_factor(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_bssn_conformal_factor(lua_State *L) +static int spacetime_blackhole_lw_bssn_conformal_factor(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3096,15 +2828,8 @@ spacetime_blackhole_lw_bssn_conformal_factor(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -3121,8 +2846,7 @@ spacetime_blackhole_lw_bssn_conformal_factor(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_conformal_factor_der(lua_State *L) +static int spacetime_blackhole_lw_conformal_factor_der(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3130,15 +2854,8 @@ spacetime_blackhole_lw_conformal_factor_der(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -3166,8 +2883,7 @@ spacetime_blackhole_lw_conformal_factor_der(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_bssn_conformal_factor_der(lua_State *L) +static int spacetime_blackhole_lw_bssn_conformal_factor_der(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3175,15 +2891,8 @@ spacetime_blackhole_lw_bssn_conformal_factor_der(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -3195,7 +2904,9 @@ spacetime_blackhole_lw_bssn_conformal_factor_der(lua_State *L) double dz = luaL_checknumber(L, 12); double *bssn_conformal_factor_der = gkyl_malloc(sizeof(double[3])); - spacetime->bssn_conformal_factor_der_func(spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der); + spacetime->bssn_conformal_factor_der_func( + spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der + ); lua_createtable(L, 3, 0); @@ -3211,8 +2922,7 @@ spacetime_blackhole_lw_bssn_conformal_factor_der(lua_State *L) return 1; } -static int -spacetime_blackhole_lw_bssn_conformal_factor_der2(lua_State *L) +static int spacetime_blackhole_lw_bssn_conformal_factor_der2(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3220,15 +2930,8 @@ spacetime_blackhole_lw_bssn_conformal_factor_der2(lua_State *L) double pos_y = luaL_checknumber(L, 4); double pos_z = luaL_checknumber(L, 5); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew( &(struct gkyl_gr_blackhole_inp) { - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z, .use_gpu = false}); double t = luaL_checknumber(L, 6); double x = luaL_checknumber(L, 7); @@ -3239,12 +2942,14 @@ spacetime_blackhole_lw_bssn_conformal_factor_der2(lua_State *L) double dy = luaL_checknumber(L, 11); double dz = luaL_checknumber(L, 12); - double **bssn_conformal_factor_der2 = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_factor_der2 = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_factor_der2[i] = gkyl_malloc(sizeof(double[3])); } - spacetime->bssn_conformal_factor_der2_func(spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der2); + spacetime->bssn_conformal_factor_der2_func( + spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der2 + ); lua_createtable(L, 3, 0); @@ -3273,31 +2978,30 @@ spacetime_blackhole_lw_bssn_conformal_factor_der2(lua_State *L) // Spacetime constructor. static struct luaL_Reg spacetime_blackhole_ctor[] = { - { "new", spacetime_blackhole_lw_new }, - { "spatialMetricTensor", spacetime_blackhole_lw_spatial_metric_tensor }, - { "invSpatialMetricTensor", spacetime_blackhole_lw_inv_spatial_metric_tensor }, - { "spatialMetricDeterminant", spacetime_blackhole_lw_spatial_metric_det }, - { "lapseFunction", spacetime_blackhole_lw_lapse_function }, - { "shiftVector", spacetime_blackhole_lw_shift_vector }, - { "extrinsicCurvatureTensor", spacetime_blackhole_lw_extrinsic_curvature_tensor }, - { "lapseFunctionDer", spacetime_blackhole_lw_lapse_function_der }, - { "shiftVectorDer", spacetime_blackhole_lw_shift_vector_der }, - { "spatialMetricTensorDer", spacetime_blackhole_lw_spatial_metric_tensor_der }, - { "excisionRegion", spacetime_blackhole_lw_excision_region }, - { "conformalFactor", spacetime_blackhole_lw_conformal_factor }, - { "bssnConformalFactor", spacetime_blackhole_lw_bssn_conformal_factor }, - { "conformalFactorDer", spacetime_blackhole_lw_conformal_factor_der }, - { "bssnConformalFactorDer", spacetime_blackhole_lw_bssn_conformal_factor_der }, - { "bssnConformalFactorDer2", spacetime_blackhole_lw_bssn_conformal_factor_der2 }, - { 0, 0 } + {"new", spacetime_blackhole_lw_new}, + {"spatialMetricTensor", spacetime_blackhole_lw_spatial_metric_tensor}, + {"invSpatialMetricTensor", spacetime_blackhole_lw_inv_spatial_metric_tensor}, + {"spatialMetricDeterminant", spacetime_blackhole_lw_spatial_metric_det}, + {"lapseFunction", spacetime_blackhole_lw_lapse_function}, + {"shiftVector", spacetime_blackhole_lw_shift_vector}, + {"extrinsicCurvatureTensor", spacetime_blackhole_lw_extrinsic_curvature_tensor}, + {"lapseFunctionDer", spacetime_blackhole_lw_lapse_function_der}, + {"shiftVectorDer", spacetime_blackhole_lw_shift_vector_der}, + {"spatialMetricTensorDer", spacetime_blackhole_lw_spatial_metric_tensor_der}, + {"excisionRegion", spacetime_blackhole_lw_excision_region}, + {"conformalFactor", spacetime_blackhole_lw_conformal_factor}, + {"bssnConformalFactor", spacetime_blackhole_lw_bssn_conformal_factor}, + {"conformalFactorDer", spacetime_blackhole_lw_conformal_factor_der}, + {"bssnConformalFactorDer", spacetime_blackhole_lw_bssn_conformal_factor_der}, + {"bssnConformalFactorDer2", spacetime_blackhole_lw_bssn_conformal_factor_der2}, + {0, 0} }; /* ********************** */ /* Neutron Star Spacetime */ /* ********************** */ -static int -spacetime_neutronstar_lw_new(lua_State *L) +static int spacetime_neutronstar_lw_new(lua_State *L) { struct gr_spacetime_lw *neutronstar_lw = gkyl_malloc(sizeof(*neutronstar_lw)); @@ -3311,21 +3015,19 @@ spacetime_neutronstar_lw_new(lua_State *L) double pos_z = luaL_checknumber(L, 8); neutronstar_lw->magic = MOMENT_SPACETIME_DEFAULT; - neutronstar_lw->spacetime = gkyl_gr_neutronstar_inew( &(struct gkyl_gr_neutronstar_inp) { - .mass = mass, - .spin = spin, - .mass_quadrupole = mass_quadrupole, - .spin_octupole = spin_octupole, - .mass_hexadecapole = mass_hexadecapole, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + neutronstar_lw->spacetime = gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp + ){.mass = mass, + .spin = spin, + .mass_quadrupole = mass_quadrupole, + .spin_octupole = spin_octupole, + .mass_hexadecapole = mass_hexadecapole, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .use_gpu = false}); // Create Lua userdata. - struct gr_spacetime_lw **l_neutronstar_lw = lua_newuserdata(L, sizeof(struct gr_spacetime_lw*)); + struct gr_spacetime_lw **l_neutronstar_lw = lua_newuserdata(L, sizeof(struct gr_spacetime_lw *)); *l_neutronstar_lw = neutronstar_lw; // Set metatable. @@ -3335,8 +3037,7 @@ spacetime_neutronstar_lw_new(lua_State *L) return 1; } -static int -spacetime_neutronstar_lw_spatial_metric_tensor(lua_State *L) +static int spacetime_neutronstar_lw_spatial_metric_tensor(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3347,25 +3048,23 @@ spacetime_neutronstar_lw_spatial_metric_tensor(lua_State *L) double pos_y = luaL_checknumber(L, 7); double pos_z = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew( &(struct gkyl_gr_neutronstar_inp) { - .mass = mass, - .spin = spin, - .mass_quadrupole = mass_quadrupole, - .spin_octupole = spin_octupole, - .mass_hexadecapole = mass_hexadecapole, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp + ){.mass = mass, + .spin = spin, + .mass_quadrupole = mass_quadrupole, + .spin_octupole = spin_octupole, + .mass_hexadecapole = mass_hexadecapole, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); double y = luaL_checknumber(L, 11); double z = luaL_checknumber(L, 12); - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -3397,8 +3096,7 @@ spacetime_neutronstar_lw_spatial_metric_tensor(lua_State *L) return 1; } -static int -spacetime_neutronstar_lw_spatial_metric_det(lua_State *L) +static int spacetime_neutronstar_lw_spatial_metric_det(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3409,18 +3107,16 @@ spacetime_neutronstar_lw_spatial_metric_det(lua_State *L) double pos_y = luaL_checknumber(L, 7); double pos_z = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew( &(struct gkyl_gr_neutronstar_inp) { - .mass = mass, - .spin = spin, - .mass_quadrupole = mass_quadrupole, - .spin_octupole = spin_octupole, - .mass_hexadecapole = mass_hexadecapole, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp + ){.mass = mass, + .spin = spin, + .mass_quadrupole = mass_quadrupole, + .spin_octupole = spin_octupole, + .mass_hexadecapole = mass_hexadecapole, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -3437,8 +3133,7 @@ spacetime_neutronstar_lw_spatial_metric_det(lua_State *L) return 1; } -static int -spacetime_neutronstar_lw_lapse_function(lua_State *L) +static int spacetime_neutronstar_lw_lapse_function(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3449,18 +3144,16 @@ spacetime_neutronstar_lw_lapse_function(lua_State *L) double pos_y = luaL_checknumber(L, 7); double pos_z = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew( &(struct gkyl_gr_neutronstar_inp) { - .mass = mass, - .spin = spin, - .mass_quadrupole = mass_quadrupole, - .spin_octupole = spin_octupole, - .mass_hexadecapole = mass_hexadecapole, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp + ){.mass = mass, + .spin = spin, + .mass_quadrupole = mass_quadrupole, + .spin_octupole = spin_octupole, + .mass_hexadecapole = mass_hexadecapole, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -3477,8 +3170,7 @@ spacetime_neutronstar_lw_lapse_function(lua_State *L) return 1; } -static int -spacetime_neutronstar_lw_shift_vector(lua_State *L) +static int spacetime_neutronstar_lw_shift_vector(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3489,18 +3181,16 @@ spacetime_neutronstar_lw_shift_vector(lua_State *L) double pos_y = luaL_checknumber(L, 7); double pos_z = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew( &(struct gkyl_gr_neutronstar_inp) { - .mass = mass, - .spin = spin, - .mass_quadrupole = mass_quadrupole, - .spin_octupole = spin_octupole, - .mass_hexadecapole = mass_hexadecapole, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp + ){.mass = mass, + .spin = spin, + .mass_quadrupole = mass_quadrupole, + .spin_octupole = spin_octupole, + .mass_hexadecapole = mass_hexadecapole, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -3524,8 +3214,7 @@ spacetime_neutronstar_lw_shift_vector(lua_State *L) return 1; } -static int -spacetime_neutronstar_lw_extrinsic_curvature_tensor(lua_State *L) +static int spacetime_neutronstar_lw_extrinsic_curvature_tensor(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3536,18 +3225,16 @@ spacetime_neutronstar_lw_extrinsic_curvature_tensor(lua_State *L) double pos_y = luaL_checknumber(L, 7); double pos_z = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew( &(struct gkyl_gr_neutronstar_inp) { - .mass = mass, - .spin = spin, - .mass_quadrupole = mass_quadrupole, - .spin_octupole = spin_octupole, - .mass_hexadecapole = mass_hexadecapole, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp + ){.mass = mass, + .spin = spin, + .mass_quadrupole = mass_quadrupole, + .spin_octupole = spin_octupole, + .mass_hexadecapole = mass_hexadecapole, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -3558,12 +3245,14 @@ spacetime_neutronstar_lw_extrinsic_curvature_tensor(lua_State *L) double dy = luaL_checknumber(L, 14); double dz = luaL_checknumber(L, 15); - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } - spacetime->extrinsic_curvature_tensor_func(spacetime, t, x, y, z, dx, dy, dz, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, t, x, y, z, dx, dy, dz, &extrinsic_curvature + ); lua_createtable(L, 3, 0); @@ -3590,8 +3279,7 @@ spacetime_neutronstar_lw_extrinsic_curvature_tensor(lua_State *L) return 1; } -static int -spacetime_neutronstar_lw_lapse_function_der(lua_State *L) +static int spacetime_neutronstar_lw_lapse_function_der(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3602,18 +3290,16 @@ spacetime_neutronstar_lw_lapse_function_der(lua_State *L) double pos_y = luaL_checknumber(L, 7); double pos_z = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew( &(struct gkyl_gr_neutronstar_inp) { - .mass = mass, - .spin = spin, - .mass_quadrupole = mass_quadrupole, - .spin_octupole = spin_octupole, - .mass_hexadecapole = mass_hexadecapole, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp + ){.mass = mass, + .spin = spin, + .mass_quadrupole = mass_quadrupole, + .spin_octupole = spin_octupole, + .mass_hexadecapole = mass_hexadecapole, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -3641,8 +3327,7 @@ spacetime_neutronstar_lw_lapse_function_der(lua_State *L) return 1; } -static int -spacetime_neutronstar_lw_shift_vector_der(lua_State *L) +static int spacetime_neutronstar_lw_shift_vector_der(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3653,18 +3338,16 @@ spacetime_neutronstar_lw_shift_vector_der(lua_State *L) double pos_y = luaL_checknumber(L, 7); double pos_z = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew( &(struct gkyl_gr_neutronstar_inp) { - .mass = mass, - .spin = spin, - .mass_quadrupole = mass_quadrupole, - .spin_octupole = spin_octupole, - .mass_hexadecapole = mass_hexadecapole, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp + ){.mass = mass, + .spin = spin, + .mass_quadrupole = mass_quadrupole, + .spin_octupole = spin_octupole, + .mass_hexadecapole = mass_hexadecapole, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -3675,7 +3358,7 @@ spacetime_neutronstar_lw_shift_vector_der(lua_State *L) double dy = luaL_checknumber(L, 14); double dz = luaL_checknumber(L, 15); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } @@ -3707,8 +3390,7 @@ spacetime_neutronstar_lw_shift_vector_der(lua_State *L) return 1; } -static int -spacetime_neutronstar_lw_spatial_metric_tensor_der(lua_State *L) +static int spacetime_neutronstar_lw_spatial_metric_tensor_der(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3719,18 +3401,16 @@ spacetime_neutronstar_lw_spatial_metric_tensor_der(lua_State *L) double pos_y = luaL_checknumber(L, 7); double pos_z = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew( &(struct gkyl_gr_neutronstar_inp) { - .mass = mass, - .spin = spin, - .mass_quadrupole = mass_quadrupole, - .spin_octupole = spin_octupole, - .mass_hexadecapole = mass_hexadecapole, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp + ){.mass = mass, + .spin = spin, + .mass_quadrupole = mass_quadrupole, + .spin_octupole = spin_octupole, + .mass_hexadecapole = mass_hexadecapole, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -3741,9 +3421,9 @@ spacetime_neutronstar_lw_spatial_metric_tensor_der(lua_State *L) double dy = luaL_checknumber(L, 14); double dz = luaL_checknumber(L, 15); - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -3787,8 +3467,7 @@ spacetime_neutronstar_lw_spatial_metric_tensor_der(lua_State *L) return 1; } -static int -spacetime_neutronstar_lw_excision_region(lua_State *L) +static int spacetime_neutronstar_lw_excision_region(lua_State *L) { double mass = luaL_checknumber(L, 1); double spin = luaL_checknumber(L, 2); @@ -3799,18 +3478,16 @@ spacetime_neutronstar_lw_excision_region(lua_State *L) double pos_y = luaL_checknumber(L, 7); double pos_z = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew( &(struct gkyl_gr_neutronstar_inp) { - .mass = mass, - .spin = spin, - .mass_quadrupole = mass_quadrupole, - .spin_octupole = spin_octupole, - .mass_hexadecapole = mass_hexadecapole, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - .use_gpu = false - } - ); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp + ){.mass = mass, + .spin = spin, + .mass_quadrupole = mass_quadrupole, + .spin_octupole = spin_octupole, + .mass_hexadecapole = mass_hexadecapole, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -3829,25 +3506,24 @@ spacetime_neutronstar_lw_excision_region(lua_State *L) // Spacetime constructor. static struct luaL_Reg spacetime_neutronstar_ctor[] = { - { "new", spacetime_neutronstar_lw_new }, - { "spatialMetricTensor", spacetime_neutronstar_lw_spatial_metric_tensor }, - { "spatialMetricDeterminant", spacetime_neutronstar_lw_spatial_metric_det }, - { "lapseFunction", spacetime_neutronstar_lw_lapse_function }, - { "shiftVector", spacetime_neutronstar_lw_shift_vector }, - { "extrinsicCurvatureTensor", spacetime_neutronstar_lw_extrinsic_curvature_tensor }, - { "lapseFunctionDer", spacetime_neutronstar_lw_lapse_function_der }, - { "shiftVectorDer", spacetime_neutronstar_lw_shift_vector_der }, - { "spatialMetricTensorDer", spacetime_neutronstar_lw_spatial_metric_tensor_der }, - { "excisionRegion", spacetime_neutronstar_lw_excision_region }, - { 0, 0 } + {"new", spacetime_neutronstar_lw_new}, + {"spatialMetricTensor", spacetime_neutronstar_lw_spatial_metric_tensor}, + {"spatialMetricDeterminant", spacetime_neutronstar_lw_spatial_metric_det}, + {"lapseFunction", spacetime_neutronstar_lw_lapse_function}, + {"shiftVector", spacetime_neutronstar_lw_shift_vector}, + {"extrinsicCurvatureTensor", spacetime_neutronstar_lw_extrinsic_curvature_tensor}, + {"lapseFunctionDer", spacetime_neutronstar_lw_lapse_function_der}, + {"shiftVectorDer", spacetime_neutronstar_lw_shift_vector_der}, + {"spatialMetricTensorDer", spacetime_neutronstar_lw_spatial_metric_tensor_der}, + {"excisionRegion", spacetime_neutronstar_lw_excision_region}, + {0, 0} }; /* ********************************************* */ /* Brill-Lindquist (Binary Black Hole) Spacetime */ /* ********************************************* */ -static int -spacetime_brill_lindquist_lw_new(lua_State *L) +static int spacetime_brill_lindquist_lw_new(lua_State *L) { struct gr_spacetime_lw *brill_lindquist_lw = gkyl_malloc(sizeof(*brill_lindquist_lw)); @@ -3861,21 +3537,20 @@ spacetime_brill_lindquist_lw_new(lua_State *L) double pos_z2 = luaL_checknumber(L, 8); brill_lindquist_lw->magic = MOMENT_SPACETIME_DEFAULT; - brill_lindquist_lw->spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, - .mass2 = mass2, - .pos_x1 = pos_x1, - .pos_y1 = pos_y1, - .pos_z1 = pos_z1, - .pos_x2 = pos_x2, - .pos_y2 = pos_y2, - .pos_z2 = pos_z2, - .use_gpu = false - } - ); + brill_lindquist_lw->spacetime = gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, + .mass2 = mass2, + .pos_x1 = pos_x1, + .pos_y1 = pos_y1, + .pos_z1 = pos_z1, + .pos_x2 = pos_x2, + .pos_y2 = pos_y2, + .pos_z2 = pos_z2, + .use_gpu = false}); // Create Lua userdata. - struct gr_spacetime_lw **l_brill_lindquist_lw = lua_newuserdata(L, sizeof(struct gr_spacetime_lw*)); + struct gr_spacetime_lw **l_brill_lindquist_lw = + lua_newuserdata(L, sizeof(struct gr_spacetime_lw *)); *l_brill_lindquist_lw = brill_lindquist_lw; // Set metatable. @@ -3885,8 +3560,7 @@ spacetime_brill_lindquist_lw_new(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_spatial_metric_tensor(lua_State *L) +static int spacetime_brill_lindquist_lw_spatial_metric_tensor(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -3897,8 +3571,9 @@ spacetime_brill_lindquist_lw_spatial_metric_tensor(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -3906,16 +3581,14 @@ spacetime_brill_lindquist_lw_spatial_metric_tensor(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); double y = luaL_checknumber(L, 11); double z = luaL_checknumber(L, 12); - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -3947,8 +3620,7 @@ spacetime_brill_lindquist_lw_spatial_metric_tensor(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_inv_spatial_metric_tensor(lua_State *L) +static int spacetime_brill_lindquist_lw_inv_spatial_metric_tensor(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -3959,8 +3631,9 @@ spacetime_brill_lindquist_lw_inv_spatial_metric_tensor(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -3968,16 +3641,14 @@ spacetime_brill_lindquist_lw_inv_spatial_metric_tensor(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); double y = luaL_checknumber(L, 11); double z = luaL_checknumber(L, 12); - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -4009,8 +3680,7 @@ spacetime_brill_lindquist_lw_inv_spatial_metric_tensor(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_spatial_metric_det(lua_State *L) +static int spacetime_brill_lindquist_lw_spatial_metric_det(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4021,8 +3691,9 @@ spacetime_brill_lindquist_lw_spatial_metric_det(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4030,9 +3701,7 @@ spacetime_brill_lindquist_lw_spatial_metric_det(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4049,8 +3718,7 @@ spacetime_brill_lindquist_lw_spatial_metric_det(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_lapse_function(lua_State *L) +static int spacetime_brill_lindquist_lw_lapse_function(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4061,8 +3729,9 @@ spacetime_brill_lindquist_lw_lapse_function(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4070,9 +3739,7 @@ spacetime_brill_lindquist_lw_lapse_function(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4089,8 +3756,7 @@ spacetime_brill_lindquist_lw_lapse_function(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_shift_vector(lua_State *L) +static int spacetime_brill_lindquist_lw_shift_vector(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4101,8 +3767,9 @@ spacetime_brill_lindquist_lw_shift_vector(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4110,9 +3777,7 @@ spacetime_brill_lindquist_lw_shift_vector(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4136,8 +3801,7 @@ spacetime_brill_lindquist_lw_shift_vector(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_extrinsic_curvature_tensor(lua_State *L) +static int spacetime_brill_lindquist_lw_extrinsic_curvature_tensor(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4148,8 +3812,9 @@ spacetime_brill_lindquist_lw_extrinsic_curvature_tensor(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4157,9 +3822,7 @@ spacetime_brill_lindquist_lw_extrinsic_curvature_tensor(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4170,12 +3833,14 @@ spacetime_brill_lindquist_lw_extrinsic_curvature_tensor(lua_State *L) double dy = luaL_checknumber(L, 14); double dz = luaL_checknumber(L, 15); - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } - spacetime->extrinsic_curvature_tensor_func(spacetime, t, x, y, z, dx, dy, dz, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, t, x, y, z, dx, dy, dz, &extrinsic_curvature + ); lua_createtable(L, 3, 0); @@ -4202,8 +3867,7 @@ spacetime_brill_lindquist_lw_extrinsic_curvature_tensor(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_lapse_function_der(lua_State *L) +static int spacetime_brill_lindquist_lw_lapse_function_der(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4214,8 +3878,9 @@ spacetime_brill_lindquist_lw_lapse_function_der(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4223,9 +3888,7 @@ spacetime_brill_lindquist_lw_lapse_function_der(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4253,8 +3916,7 @@ spacetime_brill_lindquist_lw_lapse_function_der(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_shift_vector_der(lua_State *L) +static int spacetime_brill_lindquist_lw_shift_vector_der(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4265,8 +3927,9 @@ spacetime_brill_lindquist_lw_shift_vector_der(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4274,9 +3937,7 @@ spacetime_brill_lindquist_lw_shift_vector_der(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4287,7 +3948,7 @@ spacetime_brill_lindquist_lw_shift_vector_der(lua_State *L) double dy = luaL_checknumber(L, 14); double dz = luaL_checknumber(L, 15); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } @@ -4319,8 +3980,7 @@ spacetime_brill_lindquist_lw_shift_vector_der(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_spatial_metric_tensor_der(lua_State *L) +static int spacetime_brill_lindquist_lw_spatial_metric_tensor_der(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4331,8 +3991,9 @@ spacetime_brill_lindquist_lw_spatial_metric_tensor_der(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4340,9 +4001,7 @@ spacetime_brill_lindquist_lw_spatial_metric_tensor_der(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4353,9 +4012,9 @@ spacetime_brill_lindquist_lw_spatial_metric_tensor_der(lua_State *L) double dy = luaL_checknumber(L, 14); double dz = luaL_checknumber(L, 15); - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -4399,8 +4058,7 @@ spacetime_brill_lindquist_lw_spatial_metric_tensor_der(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_excision_region(lua_State *L) +static int spacetime_brill_lindquist_lw_excision_region(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4411,8 +4069,9 @@ spacetime_brill_lindquist_lw_excision_region(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4420,9 +4079,7 @@ spacetime_brill_lindquist_lw_excision_region(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4439,8 +4096,7 @@ spacetime_brill_lindquist_lw_excision_region(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_conformal_factor(lua_State *L) +static int spacetime_brill_lindquist_lw_conformal_factor(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4451,8 +4107,9 @@ spacetime_brill_lindquist_lw_conformal_factor(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4460,9 +4117,7 @@ spacetime_brill_lindquist_lw_conformal_factor(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4479,8 +4134,7 @@ spacetime_brill_lindquist_lw_conformal_factor(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_bssn_conformal_factor(lua_State *L) +static int spacetime_brill_lindquist_lw_bssn_conformal_factor(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4491,8 +4145,9 @@ spacetime_brill_lindquist_lw_bssn_conformal_factor(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4500,9 +4155,7 @@ spacetime_brill_lindquist_lw_bssn_conformal_factor(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4519,8 +4172,7 @@ spacetime_brill_lindquist_lw_bssn_conformal_factor(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_conformal_factor_der(lua_State *L) +static int spacetime_brill_lindquist_lw_conformal_factor_der(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4531,8 +4183,9 @@ spacetime_brill_lindquist_lw_conformal_factor_der(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4540,9 +4193,7 @@ spacetime_brill_lindquist_lw_conformal_factor_der(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4570,8 +4221,7 @@ spacetime_brill_lindquist_lw_conformal_factor_der(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_bssn_conformal_factor_der(lua_State *L) +static int spacetime_brill_lindquist_lw_bssn_conformal_factor_der(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4582,8 +4232,9 @@ spacetime_brill_lindquist_lw_bssn_conformal_factor_der(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4591,9 +4242,7 @@ spacetime_brill_lindquist_lw_bssn_conformal_factor_der(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4605,7 +4254,9 @@ spacetime_brill_lindquist_lw_bssn_conformal_factor_der(lua_State *L) double dz = luaL_checknumber(L, 15); double *bssn_conformal_factor_der = gkyl_malloc(sizeof(double[3])); - spacetime->bssn_conformal_factor_der_func(spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der); + spacetime->bssn_conformal_factor_der_func( + spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der + ); lua_createtable(L, 3, 0); @@ -4621,8 +4272,7 @@ spacetime_brill_lindquist_lw_bssn_conformal_factor_der(lua_State *L) return 1; } -static int -spacetime_brill_lindquist_lw_bssn_conformal_factor_der2(lua_State *L) +static int spacetime_brill_lindquist_lw_bssn_conformal_factor_der2(lua_State *L) { double mass1 = luaL_checknumber(L, 1); double mass2 = luaL_checknumber(L, 2); @@ -4633,8 +4283,9 @@ spacetime_brill_lindquist_lw_bssn_conformal_factor_der2(lua_State *L) double pos_y2 = luaL_checknumber(L, 7); double pos_z2 = luaL_checknumber(L, 8); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_inew( &(struct gkyl_gr_brill_lindquist_inp) { - .mass1 = mass1, + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.mass1 = mass1, .mass2 = mass2, .pos_x1 = pos_x1, .pos_y1 = pos_y1, @@ -4642,9 +4293,7 @@ spacetime_brill_lindquist_lw_bssn_conformal_factor_der2(lua_State *L) .pos_x2 = pos_x2, .pos_y2 = pos_y2, .pos_z2 = pos_z2, - .use_gpu = false - } - ); + .use_gpu = false}); double t = luaL_checknumber(L, 9); double x = luaL_checknumber(L, 10); @@ -4655,12 +4304,14 @@ spacetime_brill_lindquist_lw_bssn_conformal_factor_der2(lua_State *L) double dy = luaL_checknumber(L, 14); double dz = luaL_checknumber(L, 15); - double **bssn_conformal_factor_der2 = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_factor_der2 = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_factor_der2[i] = gkyl_malloc(sizeof(double[3])); } - spacetime->bssn_conformal_factor_der2_func(spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der2); + spacetime->bssn_conformal_factor_der2_func( + spacetime, t, x, y, z, dx, dy, dz, &bssn_conformal_factor_der2 + ); lua_createtable(L, 3, 0); @@ -4689,28 +4340,27 @@ spacetime_brill_lindquist_lw_bssn_conformal_factor_der2(lua_State *L) // Spacetime constructor. static struct luaL_Reg spacetime_brill_lindquist_ctor[] = { - { "new", spacetime_brill_lindquist_lw_new }, - { "spatialMetricTensor", spacetime_brill_lindquist_lw_spatial_metric_tensor }, - { "invSpatialMetricTensor", spacetime_brill_lindquist_lw_inv_spatial_metric_tensor }, - { "spatialMetricDeterminant", spacetime_brill_lindquist_lw_spatial_metric_det }, - { "lapseFunction", spacetime_brill_lindquist_lw_lapse_function }, - { "shiftVector", spacetime_brill_lindquist_lw_shift_vector }, - { "extrinsicCurvatureTensor", spacetime_brill_lindquist_lw_extrinsic_curvature_tensor }, - { "lapseFunctionDer", spacetime_brill_lindquist_lw_lapse_function_der }, - { "shiftVectorDer", spacetime_brill_lindquist_lw_shift_vector_der }, - { "spatialMetricTensorDer", spacetime_brill_lindquist_lw_spatial_metric_tensor_der }, - { "excisionRegion", spacetime_brill_lindquist_lw_excision_region }, - { "conformalFactor", spacetime_brill_lindquist_lw_conformal_factor }, - { "bssnConformalFactor", spacetime_brill_lindquist_lw_bssn_conformal_factor }, - { "conformalFactorDer", spacetime_brill_lindquist_lw_conformal_factor_der }, - { "bssnConformalFactorDer", spacetime_brill_lindquist_lw_bssn_conformal_factor_der }, - { "bssnConformalFactorDer2", spacetime_brill_lindquist_lw_bssn_conformal_factor_der2 }, - { 0, 0 } + {"new", spacetime_brill_lindquist_lw_new}, + {"spatialMetricTensor", spacetime_brill_lindquist_lw_spatial_metric_tensor}, + {"invSpatialMetricTensor", spacetime_brill_lindquist_lw_inv_spatial_metric_tensor}, + {"spatialMetricDeterminant", spacetime_brill_lindquist_lw_spatial_metric_det}, + {"lapseFunction", spacetime_brill_lindquist_lw_lapse_function}, + {"shiftVector", spacetime_brill_lindquist_lw_shift_vector}, + {"extrinsicCurvatureTensor", spacetime_brill_lindquist_lw_extrinsic_curvature_tensor}, + {"lapseFunctionDer", spacetime_brill_lindquist_lw_lapse_function_der}, + {"shiftVectorDer", spacetime_brill_lindquist_lw_shift_vector_der}, + {"spatialMetricTensorDer", spacetime_brill_lindquist_lw_spatial_metric_tensor_der}, + {"excisionRegion", spacetime_brill_lindquist_lw_excision_region}, + {"conformalFactor", spacetime_brill_lindquist_lw_conformal_factor}, + {"bssnConformalFactor", spacetime_brill_lindquist_lw_bssn_conformal_factor}, + {"conformalFactorDer", spacetime_brill_lindquist_lw_conformal_factor_der}, + {"bssnConformalFactorDer", spacetime_brill_lindquist_lw_bssn_conformal_factor_der}, + {"bssnConformalFactorDer2", spacetime_brill_lindquist_lw_bssn_conformal_factor_der2}, + {0, 0} }; // Register and load all GR spacetime objects. -static void -spacetime_openlibs(lua_State *L) +static void spacetime_openlibs(lua_State *L) { luaL_newmetatable(L, MOMENT_SPACETIME_METATABLE_NM); @@ -4734,31 +4384,32 @@ spacetime_openlibs(lua_State *L) // Lua userdata object for constructing species input. struct moment_species_lw { int magic; // This must be first element in the struct. - + struct gkyl_moment_species mom_species; // Input struct to construct species. bool evolve; // Is this species evolved? struct lua_func_ctx init_ctx; // Lua registry reference to initialization function. - + bool has_applied_acceleration_func; // Is there an applied acceleration initialization function? - struct lua_func_ctx applied_acceleration_func_ref; // Lua registry reference to applied acceleration initialization function. + struct lua_func_ctx + applied_acceleration_func_ref; // Lua registry reference to applied acceleration initialization function. bool evolve_applied_acceleration; // Is the applied acceleration evolved? bool has_nT_source; // Is there a temperature source function? struct lua_func_ctx nT_source_func_ctx; // Lua registry reference to temperature source function. }; -static int -moment_species_lw_new(lua_State *L) +static int moment_species_lw_new(lua_State *L) { - int vdim = 0; - struct gkyl_moment_species mom_species = { }; + int vdim = 0; + struct gkyl_moment_species mom_species = {}; mom_species.charge = glua_tbl_get_number(L, "charge", 0.0); mom_species.mass = glua_tbl_get_number(L, "mass", 1.0); bool has_eqn = false; - with_lua_tbl_key(L, "equation") { + with_lua_tbl_key(L, "equation") + { mom_species.equation = wv_eqn_get(L); has_eqn = true; } @@ -4769,37 +4420,37 @@ moment_species_lw_new(lua_State *L) // simulation is being set up. lua_getfield(L, -1, "equation"); int eq_ref = luaL_ref(L, LUA_REGISTRYINDEX); - + lua_getglobal(L, "__moment_ref_table"); int eqtbl_len = glua_objlen(L); - lua_pushinteger(L, eqtbl_len+1); + lua_pushinteger(L, eqtbl_len + 1); lua_rawgeti(L, LUA_REGISTRYINDEX, eq_ref); lua_rawset(L, -3); lua_pop(L, 1); - } - else { + } else { return luaL_error(L, "Species \"equation\" not specfied or incorrect type!"); } mom_species.limiter = glua_tbl_get_integer(L, "limiter", GKYL_MONOTONIZED_CENTERED); const char *split_str = glua_tbl_get_string(L, "splitType", "qwave"); - mom_species.split_type = gkyl_search_str_int_pair_by_str(wave_split_type, split_str, GKYL_WAVE_QWAVE); + mom_species.split_type = + gkyl_search_str_int_pair_by_str(wave_split_type, split_str, GKYL_WAVE_QWAVE); bool evolve = glua_tbl_get_bool(L, "evolve", true); - mom_species.is_static = !evolve; + mom_species.is_static = !evolve; mom_species.force_low_order_flux = glua_tbl_get_bool(L, "forceLowOrderFlux", false); int init_ref = LUA_NOREF; if (glua_tbl_get_func(L, "init")) { init_ref = luaL_ref(L, LUA_REGISTRYINDEX); - } - else { + } else { return luaL_error(L, "Species must have an \"init\" function for initial conditions!"); } - with_lua_tbl_tbl(L, "bcx") { + with_lua_tbl_tbl(L, "bcx") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -4807,7 +4458,8 @@ moment_species_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcy") { + with_lua_tbl_tbl(L, "bcy") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -4815,7 +4467,8 @@ moment_species_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcz") { + with_lua_tbl_tbl(L, "bcz") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -4845,9 +4498,12 @@ moment_species_lw_new(lua_State *L) mom_species.has_reactivity = glua_tbl_get_bool(L, "hasReactivity", false); if (mom_species.has_reactivity) { mom_species.reactivity_gas_gamma = glua_tbl_get_number(L, "reactivityGasGamma", 1.4); - mom_species.reactivity_specific_heat_capacity = glua_tbl_get_number(L, "reactivitySpecificHeatCapacity", 2.5); - mom_species.reactivity_energy_of_formation = glua_tbl_get_number(L, "reactivityEnergyOfFormation", 1.0); - mom_species.reactivity_ignition_temperature = glua_tbl_get_number(L, "reactivityIgnitionTemperature", 0.25); + mom_species.reactivity_specific_heat_capacity = + glua_tbl_get_number(L, "reactivitySpecificHeatCapacity", 2.5); + mom_species.reactivity_energy_of_formation = + glua_tbl_get_number(L, "reactivityEnergyOfFormation", 1.0); + mom_species.reactivity_ignition_temperature = + glua_tbl_get_number(L, "reactivityIgnitionTemperature", 0.25); mom_species.reactivity_reaction_rate = glua_tbl_get_number(L, "reactivityReactionRate", 250.0); } @@ -4866,16 +4522,23 @@ moment_species_lw_new(lua_State *L) mom_species.has_vacuum_einstein = glua_tbl_get_bool(L, "hasVacuumEinstein", false); if (mom_species.has_vacuum_einstein) { - mom_species.vacuum_einstein_excision_threshold = glua_tbl_get_number(L, "vacuumEinsteinExcisionThreshold", 0.3); - mom_species.vacuum_einstein_spacetime_slicing = glua_tbl_get_integer(L, "vacuumEinsteinSpacetimeSlicing", GKYL_GEODESIC_SLICING); - mom_species.vacuum_einstein_spacetime_evolution = glua_tbl_get_integer(L, "vacuumEinsteinSpacetimeEvolution", GKYL_EINSTEIN_EVOLUTION); + mom_species.vacuum_einstein_excision_threshold = + glua_tbl_get_number(L, "vacuumEinsteinExcisionThreshold", 0.3); + mom_species.vacuum_einstein_spacetime_slicing = + glua_tbl_get_integer(L, "vacuumEinsteinSpacetimeSlicing", GKYL_GEODESIC_SLICING); + mom_species.vacuum_einstein_spacetime_evolution = + glua_tbl_get_integer(L, "vacuumEinsteinSpacetimeEvolution", GKYL_EINSTEIN_EVOLUTION); } - mom_species.has_vacuum_einstein_conformal = glua_tbl_get_bool(L, "hasVacuumEinsteinConformal", false); + mom_species.has_vacuum_einstein_conformal = + glua_tbl_get_bool(L, "hasVacuumEinsteinConformal", false); if (mom_species.has_vacuum_einstein_conformal) { - mom_species.vacuum_einstein_conformal_excision_threshold = glua_tbl_get_number(L, "vacuumEinsteinConformalExcisionThreshold", 0.3); - mom_species.vacuum_einstein_conformal_spacetime_slicing = glua_tbl_get_integer(L, "vacuumEinsteinConformalSpacetimeSlicing", GKYL_GEODESIC_SLICING); - mom_species.vacuum_einstein_conformal_spacetime_evolution = glua_tbl_get_integer(L, "vacuumEinsteinConformalSpacetimeEvolution", GKYL_EINSTEIN_EVOLUTION); + mom_species.vacuum_einstein_conformal_excision_threshold = + glua_tbl_get_number(L, "vacuumEinsteinConformalExcisionThreshold", 0.3); + mom_species.vacuum_einstein_conformal_spacetime_slicing = + glua_tbl_get_integer(L, "vacuumEinsteinConformalSpacetimeSlicing", GKYL_GEODESIC_SLICING); + mom_species.vacuum_einstein_conformal_spacetime_evolution = + glua_tbl_get_integer(L, "vacuumEinsteinConformalSpacetimeEvolution", GKYL_EINSTEIN_EVOLUTION); } mom_species.has_gr_ultra_rel = glua_tbl_get_bool(L, "hasGRUltraRel", false); @@ -4894,8 +4557,10 @@ moment_species_lw_new(lua_State *L) mom_species.gr_twofluid_mass_ion = glua_tbl_get_number(L, "GRTwoFluidMassIon", 1.0); mom_species.gr_twofluid_charge_elc = glua_tbl_get_number(L, "GRTwoFluidChargeElc", -1.0); mom_species.gr_twofluid_charge_ion = glua_tbl_get_number(L, "GRTwoFluidChargeIon", 1.0); - mom_species.gr_twofluid_gas_gamma_elc = glua_tbl_get_number(L, "GRTwoFluidGasGammaElc", 5.0 / 3.0); - mom_species.gr_twofluid_gas_gamma_ion = glua_tbl_get_number(L, "GRTwoFluidGasGammaIon", 5.0 / 3.0); + mom_species.gr_twofluid_gas_gamma_elc = + glua_tbl_get_number(L, "GRTwoFluidGasGammaElc", 5.0 / 3.0); + mom_species.gr_twofluid_gas_gamma_ion = + glua_tbl_get_number(L, "GRTwoFluidGasGammaIon", 5.0 / 3.0); mom_species.gr_twofluid_e_fact = glua_tbl_get_number(L, "GRTwoFluidEFact", 0.0); } @@ -4903,7 +4568,7 @@ moment_species_lw_new(lua_State *L) if (mom_species.has_gr_mhd) { mom_species.gr_mhd_gas_gamma = glua_tbl_get_number(L, "GRMHDGasGamma", 5.0 / 3.0); } - + mom_species.type_brag = glua_tbl_get_integer(L, "braginskiiType", 0); struct moment_species_lw *moms_lw = lua_newuserdata(L, sizeof(*moms_lw)); @@ -4911,42 +4576,36 @@ moment_species_lw_new(lua_State *L) moms_lw->evolve = evolve; moms_lw->mom_species = mom_species; - moms_lw->init_ctx = (struct lua_func_ctx) { - .func_ref = init_ref, + moms_lw->init_ctx = (struct lua_func_ctx + ){.func_ref = init_ref, .ndim = 0, // This will be set later. .nret = mom_species.equation->num_equations, - .L = L, - }; + .L = L}; moms_lw->has_applied_acceleration_func = has_applied_acceleration_func; - moms_lw->applied_acceleration_func_ref = (struct lua_func_ctx) { - .func_ref = applied_acceleration_func_ref, + moms_lw->applied_acceleration_func_ref = (struct lua_func_ctx + ){.func_ref = applied_acceleration_func_ref, .ndim = 0, // This will be set later. .nret = 3, - .L = L, - }; + .L = L}; moms_lw->evolve_applied_acceleration = evolve_applied_acceleration; moms_lw->has_nT_source = has_nT_source; - moms_lw->nT_source_func_ctx = (struct lua_func_ctx) { - .func_ref = nT_source_ref, + moms_lw->nT_source_func_ctx = (struct lua_func_ctx + ){.func_ref = nT_source_ref, .ndim = 0, // This will be set later. .nret = GKYL_MOM_APP_NUM_NT_SOURCE, - .L = L, - }; - + .L = L}; + // Set metatable. luaL_getmetatable(L, MOMENT_SPECIES_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Species constructor. -static struct luaL_Reg mom_species_ctor[] = { - { "new", moment_species_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg mom_species_ctor[] = {{"new", moment_species_lw_new}, {0, 0}}; /* ************* */ /* Field methods */ @@ -4959,27 +4618,29 @@ static struct luaL_Reg mom_species_ctor[] = { struct moment_field_lw { int magic; // This must be first element in the struct. - bool evolve; // Is this field evolved? + bool evolve; // Is this field evolved? struct gkyl_moment_field mom_field; // Input struct to construct field. - + struct lua_func_ctx init_ctx; // Lua registry reference to initialization function. bool has_external_field_func; // Is there an external field initialization function? - struct lua_func_ctx external_field_func_ref; // Lua registry reference to external field initialization function. + struct lua_func_ctx + external_field_func_ref; // Lua registry reference to external field initialization function. bool evolve_external_field; // Is the external field evolved? - double external_field_ramp_time; // Linear ramp for turning on external field without re-projecting. + double external_field_ramp_time; // Linear ramp for turning on external field without re-projecting. bool has_applied_current_func; // Is there an applied current initialization function? - struct lua_func_ctx applied_current_func_ref; // Lua registry reference to applied current initialization function. + struct lua_func_ctx + applied_current_func_ref; // Lua registry reference to applied current initialization function. bool evolve_applied_current; // Is the applied current evolved? - double applied_current_ramp_time; // Linear ramp for turning on applied current without re-projecting. + double + applied_current_ramp_time; // Linear ramp for turning on applied current without re-projecting. }; -static int -moment_field_lw_new(lua_State *L) +static int moment_field_lw_new(lua_State *L) { - int vdim = 0; - struct gkyl_moment_field mom_field = { }; + int vdim = 0; + struct gkyl_moment_field mom_field = {}; mom_field.epsilon0 = glua_tbl_get_number(L, "epsilon0", 1.0); mom_field.mu0 = glua_tbl_get_number(L, "mu0", 1.0); @@ -4987,20 +4648,20 @@ moment_field_lw_new(lua_State *L) mom_field.mag_error_speed_fact = glua_tbl_get_number(L, "mgnErrorSpeedFactor", 0.0); mom_field.limiter = glua_tbl_get_integer(L, "limiter", GKYL_MONOTONIZED_CENTERED); - + bool evolve = glua_tbl_get_bool(L, "evolve", true); - mom_field.is_static = !evolve; + mom_field.is_static = !evolve; mom_field.use_explicit_em_coupling = glua_tbl_get_bool(L, "useExplicitEmCoupling", false); int init_ref = LUA_NOREF; if (glua_tbl_get_func(L, "init")) { init_ref = luaL_ref(L, LUA_REGISTRYINDEX); - } - else { + } else { return luaL_error(L, "Field must have an \"init\" function for initial conditions!"); } - - with_lua_tbl_tbl(L, "bcx") { + + with_lua_tbl_tbl(L, "bcx") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -5008,7 +4669,8 @@ moment_field_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcy") { + with_lua_tbl_tbl(L, "bcy") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -5016,7 +4678,8 @@ moment_field_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcz") { + with_lua_tbl_tbl(L, "bcz") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -5027,7 +4690,7 @@ moment_field_lw_new(lua_State *L) bool has_external_field_func = false; int external_field_func_ref = LUA_NOREF; bool evolve_external_field = false; - double external_field_ramp_time = 0.0; + double external_field_ramp_time = 0.0; if (glua_tbl_get_func(L, "externalFieldInit")) { external_field_func_ref = luaL_ref(L, LUA_REGISTRYINDEX); @@ -5040,7 +4703,7 @@ moment_field_lw_new(lua_State *L) bool has_applied_current_func = false; int applied_current_func_ref = LUA_NOREF; bool evolve_applied_current = false; - double applied_current_ramp_time = 0.0; + double applied_current_ramp_time = 0.0; if (glua_tbl_get_func(L, "appliedCurrent")) { applied_current_func_ref = luaL_ref(L, LUA_REGISTRYINDEX); @@ -5056,45 +4719,39 @@ moment_field_lw_new(lua_State *L) momf_lw->evolve = evolve; momf_lw->mom_field = mom_field; - momf_lw->init_ctx = (struct lua_func_ctx) { - .func_ref = init_ref, + momf_lw->init_ctx = (struct lua_func_ctx + ){.func_ref = init_ref, .ndim = 0, // This will be set later. .nret = 6, - .L = L, - }; + .L = L}; momf_lw->has_external_field_func = has_external_field_func; - momf_lw->external_field_func_ref = (struct lua_func_ctx) { - .func_ref = external_field_func_ref, + momf_lw->external_field_func_ref = (struct lua_func_ctx + ){.func_ref = external_field_func_ref, .ndim = 0, // This will be set later. .nret = 6, - .L = L, - }; + .L = L}; momf_lw->evolve_external_field = evolve_external_field; momf_lw->external_field_ramp_time = external_field_ramp_time; momf_lw->has_applied_current_func = has_applied_current_func; - momf_lw->applied_current_func_ref = (struct lua_func_ctx) { - .func_ref = applied_current_func_ref, + momf_lw->applied_current_func_ref = (struct lua_func_ctx + ){.func_ref = applied_current_func_ref, .ndim = 0, // This will be set later. .nret = 3, - .L = L, - }; + .L = L}; momf_lw->evolve_applied_current = evolve_applied_current; momf_lw->applied_current_ramp_time = applied_current_ramp_time; - + // Set metatable. luaL_getmetatable(L, MOMENT_FIELD_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Species constructor. -static struct luaL_Reg mom_field_ctor[] = { - { "new", moment_field_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg mom_field_ctor[] = {{"new", moment_field_lw_new}, {0, 0}}; /* *********** */ /* App methods */ @@ -5106,17 +4763,20 @@ static struct luaL_Reg mom_field_ctor[] = { // Lua userdata object for holding Moment app and simulation parameters. struct moment_app_lw { gkyl_moment_app *app; // Moment app object. - + struct lua_func_ctx mapc2p_ctx; // Function context for mapc2p. - struct lua_func_ctx species_init_ctx[GKYL_MAX_SPECIES]; // Function context for species initial conditions. - struct lua_func_ctx applied_acceleration_func_ctx[GKYL_MAX_SPECIES]; // Function context for applied acceleration. - struct lua_func_ctx species_nT_source_func_ctx[GKYL_MAX_SPECIES]; // Function context for temperature sources. + struct lua_func_ctx + species_init_ctx[GKYL_MAX_SPECIES]; // Function context for species initial conditions. + struct lua_func_ctx + applied_acceleration_func_ctx[GKYL_MAX_SPECIES]; // Function context for applied acceleration. + struct lua_func_ctx + species_nT_source_func_ctx[GKYL_MAX_SPECIES]; // Function context for temperature sources. struct lua_func_ctx field_init_ctx; // Function context for field initial conditions. struct lua_func_ctx external_field_func_ctx; // Function context for external field. struct lua_func_ctx applied_current_func_ctx; // Function context for applied current. - + double t_start, t_end; // Start and end times of simulation. int num_frames; // Number of data frames to write. int field_energy_calcs; // Number of times to calculate field energy. @@ -5126,15 +4786,14 @@ struct moment_app_lw { }; // Find index of species in table given its name. -static int -app_find_species(const gkyl_moment_app *app, const char *nm) +static int app_find_species(const gkyl_moment_app *app, const char *nm) { for (int i = 0; i < app->num_species; i++) { if (strcmp(app->species[i].name, nm) == 0) { return i; } } - + return -1; } @@ -5144,8 +4803,8 @@ app_find_species(const gkyl_moment_app *app, const char *nm) static int get_species_inp(lua_State *L, int cdim, struct moment_species_lw *species[GKYL_MAX_SPECIES]) { - enum { TKEY = -2, TVAL = -1}; - + enum { TKEY = -2, TVAL = -1 }; + int curr = 0; lua_pushnil(L); // Initial key is nil. while (lua_next(L, TKEY) != 0) { @@ -5153,12 +4812,11 @@ get_species_inp(lua_State *L, int cdim, struct moment_species_lw *species[GKYL_M if (lua_type(L, TVAL) == LUA_TUSERDATA) { struct moment_species_lw *vms = lua_touserdata(L, TVAL); if (vms->magic == MOMENT_SPECIES_DEFAULT) { - vms->init_ctx.ndim = cdim; vms->applied_acceleration_func_ref.ndim = cdim; vms->nT_source_func_ctx.ndim = cdim; - - if (lua_type(L,TKEY) == LUA_TSTRING) { + + if (lua_type(L, TKEY) == LUA_TSTRING) { const char *key = lua_tolstring(L, TKEY, 0); strcpy(vms->mom_species.name, key); } @@ -5171,8 +4829,7 @@ get_species_inp(lua_State *L, int cdim, struct moment_species_lw *species[GKYL_M } // comparison method to sort species array by species name -static int -species_compare_func(const void *a, const void *b) +static int species_compare_func(const void *a, const void *b) { const struct moment_species_lw *const *spa = a; const struct moment_species_lw *const *spb = b; @@ -5180,20 +4837,20 @@ species_compare_func(const void *a, const void *b) } // Create top-level App object. -static int -mom_app_new(lua_State *L) +static int mom_app_new(lua_State *L) { struct moment_app_lw *app_lw = gkyl_malloc(sizeof(*app_lw)); // The output prefix to use is stored in the global // GKYL_OUT_PREFIX. If this is not found then "g0-moment" is used. const char *sim_name = "g0-moment"; - with_lua_global(L, "GKYL_OUT_PREFIX") { + with_lua_global(L, "GKYL_OUT_PREFIX") + { if (lua_isstring(L, -1)) { sim_name = lua_tostring(L, -1); } } - + // Initialize app using table inputs (table is on top of stack). app_lw->t_start = glua_tbl_get_number(L, "tStart", 0.0); @@ -5204,12 +4861,13 @@ mom_app_new(lua_State *L) app_lw->dt_failure_tol = glua_tbl_get_number(L, "dtFailureTol", 1.0e-4); app_lw->num_failures_max = glua_tbl_get_integer(L, "numFailuresMax", 20); - struct gkyl_moment mom = { }; // Input table for app. + struct gkyl_moment mom = {}; // Input table for app. strcpy(mom.name, sim_name); - + int cdim = 0; - with_lua_tbl_tbl(L, "cells") { + with_lua_tbl_tbl(L, "cells") + { mom.ndim = cdim = glua_objlen(L); for (int d = 0; d < cdim; d++) { @@ -5221,22 +4879,25 @@ mom_app_new(lua_State *L) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } - - with_lua_tbl_tbl(L, "decompCuts") { + + with_lua_tbl_tbl(L, "decompCuts") + { int ncuts = glua_objlen(L); for (int d = 0; d < ncuts; d++) { cuts[d] = glua_tbl_iget_integer(L, d + 1, 0); } - } + } - with_lua_tbl_tbl(L, "lower") { + with_lua_tbl_tbl(L, "lower") + { for (int d = 0; d < cdim; d++) { mom.lower[d] = glua_tbl_iget_number(L, d + 1, 0.0); } } - with_lua_tbl_tbl(L, "upper") { + with_lua_tbl_tbl(L, "upper") + { for (int d = 0; d < cdim; d++) { mom.upper[d] = glua_tbl_iget_number(L, d + 1, 0.0); } @@ -5248,7 +4909,8 @@ mom_app_new(lua_State *L) mom.num_periodic_dir = 0; if (glua_tbl_has_key(L, "periodicDirs")) { - with_lua_tbl_tbl(L, "periodicDirs") { + with_lua_tbl_tbl(L, "periodicDirs") + { mom.num_periodic_dir = glua_objlen(L); for (int d = 0; d < mom.num_periodic_dir; d++) { @@ -5272,12 +4934,8 @@ mom_app_new(lua_State *L) } if (has_mapc2p) { - app_lw->mapc2p_ctx = (struct lua_func_ctx) { - .func_ref = mapc2p_ref, - .ndim = cdim, - .nret = cdim, - .L = L, - }; + app_lw->mapc2p_ctx = + (struct lua_func_ctx){.func_ref = mapc2p_ref, .ndim = cdim, .nret = cdim, .L = L}; mom.mapc2p = gkyl_lw_eval_cb; mom.c2p_ctx = &app_lw->mapc2p_ctx; } @@ -5291,10 +4949,10 @@ mom_app_new(lua_State *L) // proceeding as there is no way to ensure that all cores loop over // Lua tables in the same order qsort(species, mom.num_species, sizeof(struct moment_species_lw *), species_compare_func); - + for (int s = 0; s < mom.num_species; s++) { mom.species[s] = species[s]->mom_species; - + app_lw->species_init_ctx[s] = species[s]->init_ctx; mom.species[s].init = gkyl_lw_eval_cb; mom.species[s].ctx = &app_lw->species_init_ctx[s]; @@ -5314,7 +4972,8 @@ mom_app_new(lua_State *L) } mom.has_collision = glua_tbl_get_bool(L, "hasCollision", false); - with_lua_tbl_tbl(L, "nuBase") { + with_lua_tbl_tbl(L, "nuBase") + { for (int s = 0; s < mom.num_species; s++) { if (glua_tbl_iget_tbl(L, s + 1)) { for (int s2 = 0; s2 < mom.num_species; s2++) { @@ -5327,13 +4986,14 @@ mom_app_new(lua_State *L) } // Set field input. - with_lua_tbl_key(L, "field") { + with_lua_tbl_key(L, "field") + { if (lua_type(L, -1) == LUA_TUSERDATA) { struct moment_field_lw *momf = lua_touserdata(L, -1); - + if (momf->magic == MOMENT_FIELD_DEFAULT) { momf->init_ctx.ndim = cdim; - + mom.field = momf->mom_field; app_lw->field_init_ctx = momf->init_ctx; @@ -5370,22 +5030,20 @@ mom_app_new(lua_State *L) bool has_mpi = false; for (int d = 0; d < cdim; d++) { - mom.parallelism.cuts[d] = cuts[d]; + mom.parallelism.cuts[d] = cuts[d]; } #ifdef GKYL_HAVE_MPI - with_lua_global(L, "GKYL_MPI_COMM") { + with_lua_global(L, "GKYL_MPI_COMM") + { if (lua_islightuserdata(L, -1)) { has_mpi = true; - struct { MPI_Comm comm;} *lw_mpi_comm_world - = lua_touserdata(L, -1); + struct { + MPI_Comm comm; + } *lw_mpi_comm_world = lua_touserdata(L, -1); MPI_Comm mpi_comm = lw_mpi_comm_world->comm; - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = mpi_comm, - .sync_corners = true - } - ); - + comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = mpi_comm, .sync_corners = true}); } } #endif @@ -5393,10 +5051,7 @@ mom_app_new(lua_State *L) if (!has_mpi) { // If there is no proper MPI_Comm specifed, then assume we are a // serial sim. - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .sync_corners = true - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.sync_corners = true}); } mom.parallelism.comm = comm; @@ -5406,32 +5061,35 @@ mom_app_new(lua_State *L) int comm_sz; gkyl_comm_get_size(comm, &comm_sz); - int tot_cuts = 1; for (int d=0; dapp = gkyl_moment_app_new(&mom); // Create the Moment app. gkyl_comm_release(comm); - + // Create Lua userdata. - struct moment_app_lw **l_app_lw = lua_newuserdata(L, sizeof(struct moment_app_lw*)); + struct moment_app_lw **l_app_lw = lua_newuserdata(L, sizeof(struct moment_app_lw *)); *l_app_lw = app_lw; // Point it to the Lua app pointer. // Set metatable. luaL_getmetatable(L, MOMENT_APP_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Return number of species () -> int. -static int -mom_app_num_species(lua_State *L) +static int mom_app_num_species(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; @@ -5442,8 +5100,7 @@ mom_app_num_species(lua_State *L) } // Return number of species (int) -> string. -static int -mom_app_species_name(lua_State *L) +static int mom_app_species_name(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; @@ -5455,21 +5112,19 @@ mom_app_species_name(lua_State *L) } // Compute maximum time-step () -> double. -static int -mom_app_max_dt(lua_State *L) +static int mom_app_max_dt(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; double maxdt = gkyl_moment_app_max_dt(app_lw->app); - lua_pushnumber(L, maxdt); + lua_pushnumber(L, maxdt); return 1; } // Apply initial conditions. (time) -> bool. -static int -mom_app_apply_ic(lua_State *L) +static int mom_app_apply_ic(lua_State *L) { bool status = true; @@ -5479,13 +5134,12 @@ mom_app_apply_ic(lua_State *L) double t0 = luaL_optnumber(L, 2, app_lw->t_start); gkyl_moment_app_apply_ic(app_lw->app, t0); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Apply initial conditions to field. (time) -> bool. -static int -mom_app_apply_ic_field(lua_State *L) +static int mom_app_apply_ic_field(lua_State *L) { bool status = true; @@ -5495,13 +5149,12 @@ mom_app_apply_ic_field(lua_State *L) double t0 = luaL_optnumber(L, 2, app_lw->t_start); gkyl_moment_app_apply_ic_field(app_lw->app, t0); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Apply initial conditions to species. (name, time) -> bool. -static int -mom_app_apply_ic_species(lua_State *L) +static int mom_app_apply_ic_species(lua_State *L) { bool status = true; @@ -5513,11 +5166,11 @@ mom_app_apply_ic_species(lua_State *L) if (sidx < 0) { return luaL_error(L, "Incorrect species name '%s' in apply_ic_species!", sp_name); } - + double t0 = luaL_optnumber(L, 3, app_lw->t_start); gkyl_moment_app_apply_ic_species(app_lw->app, sidx, t0); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } @@ -5530,17 +5183,16 @@ mom_app_apply_ic_species(lua_State *L) // } static const struct gkyl_str_int_pair rio_status[] = { - { "success", GKYL_ARRAY_RIO_SUCCESS }, - { "bad-version", GKYL_ARRAY_RIO_BAD_VERSION }, - { "fopen-failed", GKYL_ARRAY_RIO_FOPEN_FAILED }, - { "fread-failed", GKYL_ARRAY_RIO_FREAD_FAILED }, - { "data-mismatch", GKYL_ARRAY_RIO_DATA_MISMATCH }, - { 0, 0 } + {"success", GKYL_ARRAY_RIO_SUCCESS}, + {"bad-version", GKYL_ARRAY_RIO_BAD_VERSION}, + {"fopen-failed", GKYL_ARRAY_RIO_FOPEN_FAILED}, + {"fread-failed", GKYL_ARRAY_RIO_FREAD_FAILED}, + {"data-mismatch", GKYL_ARRAY_RIO_DATA_MISMATCH}, + {0, 0} }; // Pushes table with status on stack. Table is left on stack. -static void -push_restart_status_table(lua_State *L, struct gkyl_app_restart_status status) +static void push_restart_status_table(lua_State *L, struct gkyl_app_restart_status status) { lua_newtable(L); @@ -5558,12 +5210,11 @@ push_restart_status_table(lua_State *L, struct gkyl_app_restart_status status) lua_pushstring(L, "stime"); lua_pushnumber(L, status.stime); - lua_rawset(L, -3); + lua_rawset(L, -3); } // Read field from file. (file-name) -> status table. See above. -static int -mom_app_from_file_field(lua_State *L) +static int mom_app_from_file_field(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; @@ -5572,13 +5223,12 @@ mom_app_from_file_field(lua_State *L) struct gkyl_app_restart_status status = gkyl_moment_app_from_file_field(app_lw->app, fname); push_restart_status_table(L, status); - + return 1; } // Read field from file. (file-name, species-name) -> status table. See above. -static int -mom_app_from_file_species(lua_State *L) +static int mom_app_from_file_species(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; @@ -5590,17 +5240,17 @@ mom_app_from_file_species(lua_State *L) if (sidx < 0) { return luaL_error(L, "Incorrect species name '%s' in from_file_species!", sp_name); } - - struct gkyl_app_restart_status status = gkyl_moment_app_from_file_species(app_lw->app, sidx, fname); + + struct gkyl_app_restart_status status = + gkyl_moment_app_from_file_species(app_lw->app, sidx, fname); push_restart_status_table(L, status); - + return 1; } // Read field from file. (frame) -> status table. See above. -static int -mom_app_from_frame_field(lua_State *L) +static int mom_app_from_frame_field(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; @@ -5609,13 +5259,12 @@ mom_app_from_frame_field(lua_State *L) struct gkyl_app_restart_status status = gkyl_moment_app_from_frame_field(app_lw->app, frame); push_restart_status_table(L, status); - + return 1; } // Read field from file. (frame, species-name) -> status table. See above. -static int -mom_app_from_frame_species(lua_State *L) +static int mom_app_from_frame_species(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; @@ -5627,17 +5276,17 @@ mom_app_from_frame_species(lua_State *L) if (sidx < 0) { return luaL_error(L, "Incorrect species name '%s' in from_frame_species!", sp_name); } - - struct gkyl_app_restart_status status = gkyl_moment_app_from_frame_species(app_lw->app, sidx, frame); + + struct gkyl_app_restart_status status = + gkyl_moment_app_from_frame_species(app_lw->app, sidx, frame); push_restart_status_table(L, status); - + return 1; } // Compute integrated moments. (tm) -> bool. -static int -mom_app_calc_integrated_mom(lua_State *L) +static int mom_app_calc_integrated_mom(lua_State *L) { bool status = true; @@ -5647,13 +5296,12 @@ mom_app_calc_integrated_mom(lua_State *L) double tm = luaL_checknumber(L, 2); gkyl_moment_app_calc_integrated_mom(app_lw->app, tm); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // get number of field-energy diagnostics stored () -> int. -static int -mom_app_field_energy_ndiag(lua_State *L) +static int mom_app_field_energy_ndiag(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; @@ -5663,8 +5311,7 @@ mom_app_field_energy_ndiag(lua_State *L) } // Return the field energy as a table () -> table. -static int -mom_app_get_field_energy(lua_State *L) +static int mom_app_get_field_energy(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; @@ -5679,15 +5326,14 @@ mom_app_get_field_energy(lua_State *L) lua_pushinteger(L, i + 1); lua_pushnumber(L, vals[i]); lua_rawset(L, -3); - } + } return 1; } // Compute integrated field energy (L2 norm of each field // component). (tm) -> bool. -static int -mom_app_calc_field_energy(lua_State *L) +static int mom_app_calc_field_energy(lua_State *L) { bool status = true; @@ -5697,13 +5343,12 @@ mom_app_calc_field_energy(lua_State *L) double tm = luaL_checknumber(L, 2); gkyl_moment_app_calc_field_energy(app_lw->app, tm); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write solution (field and species) to file (time, frame) -> bool. -static int -mom_app_write(lua_State *L) +static int mom_app_write(lua_State *L) { bool status = true; @@ -5714,13 +5359,12 @@ mom_app_write(lua_State *L) int frame = luaL_checkinteger(L, 3); gkyl_moment_app_write(app_lw->app, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write field to file (time, frame) -> bool. -static int -mom_app_write_field(lua_State *L) +static int mom_app_write_field(lua_State *L) { bool status = true; @@ -5731,13 +5375,12 @@ mom_app_write_field(lua_State *L) int frame = luaL_checkinteger(L, 3); gkyl_moment_app_write_field(app_lw->app, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write species solution to file (name, time, frame) -> bool. -static int -mom_app_write_species(lua_State *L) +static int mom_app_write_species(lua_State *L) { bool status = true; @@ -5754,13 +5397,12 @@ mom_app_write_species(lua_State *L) int frame = luaL_checkinteger(L, 4); gkyl_moment_app_write_species(app_lw->app, sidx, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write integrated moments to file () -> bool. -static int -mom_app_write_integrated_mom(lua_State *L) +static int mom_app_write_integrated_mom(lua_State *L) { bool status = true; @@ -5769,13 +5411,12 @@ mom_app_write_integrated_mom(lua_State *L) gkyl_moment_app_write_integrated_mom(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write integrated field energy to file () -> bool. -static int -mom_app_write_field_energy(lua_State *L) +static int mom_app_write_field_energy(lua_State *L) { bool status = true; @@ -5784,13 +5425,12 @@ mom_app_write_field_energy(lua_State *L) gkyl_moment_app_write_field_energy(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write simulation statistics to JSON. () -> bool. -static int -mom_app_stat_write(lua_State *L) +static int mom_app_stat_write(lua_State *L) { bool status = true; @@ -5800,12 +5440,12 @@ mom_app_stat_write(lua_State *L) gkyl_moment_app_stat_write(app_lw->app); lua_pushboolean(L, status); - return 1; + return 1; } // Write data from simulation to file. static void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -5820,8 +5460,9 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } // Calculate and append field energy to dynvector. -static void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, double force_calc) +static void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, double force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); @@ -5829,8 +5470,9 @@ calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_cu } // Calculate and append integrated moments to dynvector. -static void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +static void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); @@ -5846,8 +5488,7 @@ calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_ // Update the solution by a suggested time-step. (dt) -> update status // table. See above. For details see the C API doc for this function. -static int -mom_app_update(lua_State *L) +static int mom_app_update(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; @@ -5859,49 +5500,52 @@ mom_app_update(lua_State *L) lua_newtable(L); lua_pushstring(L, "success"); lua_pushboolean(L, status.success); - lua_rawset(L, -3); + lua_rawset(L, -3); lua_pushstring(L, "dt_actual"); lua_pushnumber(L, status.dt_actual); - lua_rawset(L, -3); + lua_rawset(L, -3); lua_pushstring(L, "dt_suggested"); lua_pushnumber(L, status.dt_suggested); lua_rawset(L, -3); - + return 1; } // Step message context. struct step_message_trigs { int log_count; // Number of times logging called. - int tenth, p1c; + int tenth, p1c; struct gkyl_tm_trigger log_trig; // 10% trigger. struct gkyl_tm_trigger log_trig_1p; // 1% trigger. }; // Write log message to console. -static void -write_step_message(const struct gkyl_moment_app *app, struct step_message_trigs *trigs, int step, double t_curr, double dt_next) +static void write_step_message( + const struct gkyl_moment_app *app, struct step_message_trigs *trigs, int step, double t_curr, + double dt_next +) { if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig, t_curr)) { if (trigs->log_count > 0) { - gkyl_moment_app_cout(app, stdout, " Step %6d at time %#11.8g. Time-step %.6e. Completed %g%s\n", step, t_curr, dt_next, trigs->tenth * 10.0, "%"); - } - else { + gkyl_moment_app_cout( + app, stdout, " Step %6d at time %#11.8g. Time-step %.6e. Completed %g%s\n", step, t_curr, + dt_next, trigs->tenth * 10.0, "%" + ); + } else { trigs->log_count += 1; } - + trigs->tenth += 1; } if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig_1p, t_curr)) { gkyl_moment_app_cout(app, stdout, "%d", trigs->p1c); - trigs->p1c = (trigs->p1c+1) % 10; + trigs->p1c = (trigs->p1c + 1) % 10; } } -static void -show_help(const struct gkyl_moment_app *app) +static void show_help(const struct gkyl_moment_app *app) { gkyl_moment_app_cout(app, stdout, "Moment script takes the following arguments:\n"); gkyl_moment_app_cout(app, stdout, " -h Print this help message and exit\n"); @@ -5912,20 +5556,19 @@ show_help(const struct gkyl_moment_app *app) gkyl_moment_app_cout(app, stdout, "\n"); } -static struct gkyl_tool_args * -tool_args_from_argv(int optind, int argc, char *const*argv) +static struct gkyl_tool_args *tool_args_from_argv(int optind, int argc, char *const *argv) { struct gkyl_tool_args *targs = gkyl_malloc(sizeof *targs); - - targs->argc = argc-optind; + + targs->argc = argc - optind; targs->argv = 0; if (targs->argc > 0) { - targs->argv = gkyl_malloc(targs->argc*sizeof(char *)); - for (int i = optind, j = 0; i < argc; ++i, ++j) { - targs->argv[j] = gkyl_malloc(strlen(argv[i])+1); - strcpy(targs->argv[j], argv[i]); - } + targs->argv = gkyl_malloc(targs->argc * sizeof(char *)); + for (int i = optind, j = 0; i < argc; ++i, ++j) { + targs->argv[j] = gkyl_malloc(strlen(argv[i]) + 1); + strcpy(targs->argv[j], argv[i]); + } } return targs; @@ -5938,63 +5581,58 @@ struct script_cli { int num_steps; // number of steps bool use_verbose; // Should we use verbose output? bool is_restart; // Is this a restarted simulation? - int restart_frame; // Which frame to restart simulation from. - + int restart_frame; // Which frame to restart simulation from. + struct gkyl_tool_args *rest; }; -static struct script_cli -mom_parse_script_cli(struct gkyl_tool_args *acv) +static struct script_cli mom_parse_script_cli(struct gkyl_tool_args *acv) { struct script_cli cli = { - .help =- false, + .help = -false, .step_mode = false, .num_steps = INT_MAX, .use_verbose = false, .is_restart = false, - .restart_frame = 0, + .restart_frame = 0 }; - - coption_long longopts[] = { - {0} - }; - const char* shortopts = "+hVs:r:"; + + coption_long longopts[] = {{0}}; + const char *shortopts = "+hVs:r:"; coption opt = coption_init(); int c; while ((c = coption_get(&opt, acv->argc, acv->argv, shortopts, longopts)) != -1) { switch (c) { - case 'h': - cli.help = true; - break; - - case 'V': - cli.use_verbose = true; - break; + case 'h': + cli.help = true; + break; - case 's': - cli.num_steps = atoi(opt.arg); - break; - - case 'r': - cli.is_restart = true; - cli.restart_frame = atoi(opt.arg); - break; - - case '?': - break; + case 'V': + cli.use_verbose = true; + break; + + case 's': + cli.num_steps = atoi(opt.arg); + break; + + case 'r': + cli.is_restart = true; + cli.restart_frame = atoi(opt.arg); + break; + + case '?': + break; } } cli.rest = tool_args_from_argv(opt.ind, acv->argc, acv->argv); - + return cli; } - // Run simulation. (num_steps) -> bool. num_steps is optional. -static int -mom_app_run(lua_State *L) +static int mom_app_run(lua_State *L) { bool ret_status = true; @@ -6032,7 +5670,10 @@ mom_app_run(lua_State *L) struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -6041,8 +5682,7 @@ mom_app_run(lua_State *L) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } @@ -6050,16 +5690,22 @@ mom_app_run(lua_State *L) int field_energy_calcs = app_lw->field_energy_calcs; int integrated_mom_calcs = app_lw->integrated_mom_calcs; // Triggers for IO and logging. - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; struct step_message_trigs m_trig = { .log_count = 0, - .tenth = t_curr > 0.0 ? (int) floor(t_curr / t_end * 10.0) : 0.0, - .p1c = t_curr > 0.0 ? (int) floor(t_curr / t_end * 100.0) % 10 : 0.0, - .log_trig = { .dt = t_end / 10.0, .tcurr = t_curr }, - .log_trig_1p = { .dt = t_end / 100.0, .tcurr = t_curr }, + .tenth = t_curr > 0.0 ? (int)floor(t_curr / t_end * 10.0) : 0.0, + .p1c = t_curr > 0.0 ? (int)floor(t_curr / t_end * 100.0) % 10 : 0.0, + .log_trig = {.dt = t_end / 10.0, .tcurr = t_curr}, + .log_trig_1p = {.dt = t_end / 100.0, .tcurr = t_curr} }; struct timespec tm_ic0 = gkyl_wall_clock(); @@ -6067,8 +5713,10 @@ mom_app_run(lua_State *L) calc_field_energy(&fe_trig, app, t_curr, false); calc_integrated_mom(&im_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); - - gkyl_moment_app_cout(app, stdout, "Initialization completed in %g sec\n\n", gkyl_time_diff_now_sec(tm_ic0)); + + gkyl_moment_app_cout( + app, stdout, "Initialization completed in %g sec\n\n", gkyl_time_diff_now_sec(tm_ic0) + ); // Compute initial guess of maximum stable time-step. double dt = t_end - t_curr; @@ -6088,7 +5736,7 @@ mom_app_run(lua_State *L) if (use_verbose) { gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); } - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -6103,8 +5751,7 @@ mom_app_run(lua_State *L) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -6112,7 +5759,9 @@ mom_app_run(lua_State *L) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -6120,8 +5769,7 @@ mom_app_run(lua_State *L) break; } - } - else { + } else { num_failures = 0; } @@ -6155,16 +5803,15 @@ mom_app_run(lua_State *L) } // Return ghost cell as table of 2 elements. -static int -mom_app_nghost(lua_State *L) +static int mom_app_nghost(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; struct gkyl_moment_app *app = app_lw->app; - int nghost[3] = { 0 }; + int nghost[3] = {0}; gkyl_moment_app_nghost(app, nghost); - + lua_createtable(L, 3, 0); for (int i = 0; i < 3; i++) { @@ -6172,69 +5819,64 @@ mom_app_nghost(lua_State *L) lua_pushinteger(L, nghost[i]); lua_rawset(L, -3); } - + return 1; } // Clean up memory allocated for simulation. -static int -mom_app_gc(lua_State *L) +static int mom_app_gc(lua_State *L) { struct moment_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, MOMENT_APP_METATABLE_NM); struct moment_app_lw *app_lw = *l_app_lw; gkyl_moment_app_release(app_lw->app); gkyl_free(*l_app_lw); - + return 0; } // App constructor. -static struct luaL_Reg mom_app_ctor[] = { - { "new", mom_app_new }, - { 0, 0 } -}; +static struct luaL_Reg mom_app_ctor[] = {{"new", mom_app_new}, {0, 0}}; // App methods static struct luaL_Reg mom_app_funcs[] = { - { "num_species", mom_app_num_species }, - { "species_name", mom_app_species_name }, + {"num_species", mom_app_num_species}, + {"species_name", mom_app_species_name}, - { "max_dt", mom_app_max_dt }, + {"max_dt", mom_app_max_dt}, - { "apply_ic", mom_app_apply_ic }, - { "apply_ic_field", mom_app_apply_ic_field }, - { "apply_ic_species", mom_app_apply_ic_species }, - - { "from_file_field", mom_app_from_file_field }, - { "from_file_species", mom_app_from_file_species }, + {"apply_ic", mom_app_apply_ic}, + {"apply_ic_field", mom_app_apply_ic_field}, + {"apply_ic_species", mom_app_apply_ic_species}, - { "from_frame_field", mom_app_from_frame_field }, - { "from_frame_species", mom_app_from_frame_species }, + {"from_file_field", mom_app_from_file_field}, + {"from_file_species", mom_app_from_file_species}, - { "write", mom_app_write }, - { "write_field", mom_app_write_field }, - { "write_species", mom_app_write_species }, - { "write_field_energy", mom_app_write_field_energy }, - { "write_integrated_mom", mom_app_write_integrated_mom }, - { "stat_write", mom_app_stat_write }, + {"from_frame_field", mom_app_from_frame_field}, + {"from_frame_species", mom_app_from_frame_species}, - { "calc_field_energy", mom_app_calc_field_energy }, - { "calc_integrated_mom", mom_app_calc_integrated_mom }, + {"write", mom_app_write}, + {"write_field", mom_app_write_field}, + {"write_species", mom_app_write_species}, + {"write_field_energy", mom_app_write_field_energy}, + {"write_integrated_mom", mom_app_write_integrated_mom}, + {"stat_write", mom_app_stat_write}, - { "update", mom_app_update }, - { "run", mom_app_run }, + {"calc_field_energy", mom_app_calc_field_energy}, + {"calc_integrated_mom", mom_app_calc_integrated_mom}, + + {"update", mom_app_update}, + {"run", mom_app_run}, // Some low-level functions, typically not used by ordinary users. - { "nghost", mom_app_nghost }, - { "field_energy_ndiag", mom_app_field_energy_ndiag }, - { "get_field_energy", mom_app_get_field_energy }, - - { 0, 0 } + {"nghost", mom_app_nghost}, + {"field_energy_ndiag", mom_app_field_energy_ndiag}, + {"get_field_energy", mom_app_get_field_energy}, + + {0, 0} }; -static void -app_openlibs(lua_State *L) +static void app_openlibs(lua_State *L) { // Register top-level App. do { @@ -6247,37 +5889,32 @@ app_openlibs(lua_State *L) lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_register(L, NULL, mom_app_funcs); - + luaL_register(L, "G0.Moments.App", mom_app_ctor); - - } - while (0); + + } while (0); // Register Species input struct. do { luaL_newmetatable(L, MOMENT_SPECIES_METATABLE_NM); luaL_register(L, "G0.Moments.Species", mom_species_ctor); - } - while (0); + } while (0); // Register Field input struct. do { luaL_newmetatable(L, MOMENT_FIELD_METATABLE_NM); luaL_register(L, "G0.Moments.Field", mom_field_ctor); - } - while (0); + } while (0); // Add globals and other parameters. do { // Table to store references so the objects do not get garbage-collected. lua_newtable(L); lua_setglobal(L, "__moment_ref_table"); - } - while (0); + } while (0); } -void -gkyl_moment_lw_openlibs(lua_State *L) +void gkyl_moment_lw_openlibs(lua_State *L) { // Register types for moment reconstruction and wave limiter schemes. gkyl_register_moment_scheme_types(L); @@ -6292,7 +5929,7 @@ gkyl_moment_lw_openlibs(lua_State *L) gkyl_register_spacetime_slicing_types(L); gkyl_register_spacetime_evolution_types(L); gkyl_register_embed_geo_types(L); - + eqn_openlibs(L); spacetime_openlibs(L); app_openlibs(L); diff --git a/moments/apps/moment_multib.c b/moments/apps/moment_multib.c index b099578b95..7d3bdfe10e 100644 --- a/moments/apps/moment_multib.c +++ b/moments/apps/moment_multib.c @@ -7,33 +7,34 @@ #include // compute total number of ranges specified by cuts -static inline int -calc_cuts(int ndim, const int *cuts) +static inline int calc_cuts(int ndim, const int *cuts) { int tc = 1; - for (int d=0; dcuts); max_cuts = ncuts > max_cuts ? ncuts : max_cuts; @@ -44,8 +45,7 @@ calc_tot_and_max_cuts(const struct gkyl_block_geom *block_geom, int tot_max[2]) } // construct the mpack meta-data for multi-block data files -static struct gkyl_msgpack_data * -moment_multib_meta(struct moment_multib_output_meta meta) +static struct gkyl_msgpack_data *moment_multib_meta(struct moment_multib_output_meta meta) { struct gkyl_msgpack_data *mt = gkyl_malloc(sizeof *mt); @@ -55,7 +55,7 @@ moment_multib_meta(struct moment_multib_output_meta meta) // add some data to mpack mpack_build_map(&writer); - + mpack_write_cstr(&writer, "time"); mpack_write_double(&writer, meta.stime); @@ -78,30 +78,29 @@ moment_multib_meta(struct moment_multib_output_meta meta) mt = 0; } - return mt; + return mt; } // write out multi-block data files -static int -moment_multib_data_write(const char *fname, struct moment_multib_output_meta meta) +static int moment_multib_data_write(const char *fname, struct moment_multib_output_meta meta) { enum gkyl_array_rio_status status = GKYL_ARRAY_RIO_FOPEN_FAILED; FILE *fp = 0; int err; - with_file (fp, fname, "w") { + with_file(fp, fname, "w") + { struct gkyl_msgpack_data *amet = moment_multib_meta(meta); if (amet) { - status = gkyl_header_meta_write_fp( &(struct gkyl_array_header_info) { - .file_type = gkyl_file_type_int[GKYL_MULTI_BLOCK_DATA_FILE], + status = gkyl_header_meta_write_fp( + &(struct gkyl_array_header_info + ){.file_type = gkyl_file_type_int[GKYL_MULTI_BLOCK_DATA_FILE], .meta_size = amet->meta_sz, - .meta = amet->meta - }, + .meta = amet->meta}, fp ); MPACK_FREE(amet->meta); gkyl_free(amet); - } - else { + } else { status = GKYL_ARRAY_RIO_META_FAILED; } } @@ -109,18 +108,17 @@ moment_multib_data_write(const char *fname, struct moment_multib_output_meta met } // construct single-block App for given block ID -static struct gkyl_moment_app * -singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, - const struct gkyl_moment_multib_app *mbapp) +static struct gkyl_moment_app *singleb_app_new( + const struct gkyl_moment_multib *mbinp, int bid, const struct gkyl_moment_multib_app *mbapp +) { int ndim = gkyl_block_geom_ndim(mbapp->block_geom); int num_blocks = gkyl_block_geom_num_blocks(mbapp->block_geom); - const struct gkyl_block_geom_info *bgi = - gkyl_block_geom_get_block(mbapp->block_geom, bid); + const struct gkyl_block_geom_info *bgi = gkyl_block_geom_get_block(mbapp->block_geom, bid); // construct top-level single-block input struct - struct gkyl_moment app_inp = { }; + struct gkyl_moment app_inp = {}; strcpy(app_inp.name, mbinp->name); if (num_blocks > 1) { @@ -130,7 +128,7 @@ singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, } app_inp.ndim = ndim; - for (int i=0; ilower[i]; app_inp.upper[i] = bgi->upper[i]; app_inp.cells[i] = bgi->cells[i]; @@ -144,20 +142,21 @@ singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, app_inp.use_hybrid_flux_kep = mbinp->use_hybrid_flux_kep; app_inp.num_skip_dirs = mbinp->num_skip_dirs; - for (int d=0; d<3; ++d) + for (int d = 0; d < 3; ++d) { app_inp.skip_dirs[d] = mbinp->skip_dirs[d]; + } int num_species = app_inp.num_species = mbinp->num_species; // construct each species input block - for (int i=0; ispecies[i]; - - struct gkyl_moment_species species_inp = { }; + + struct gkyl_moment_species species_inp = {}; strcpy(species_inp.name, sp->name); species_inp.charge = sp->charge; species_inp.mass = sp->mass; - + species_inp.equation = sp->equation; species_inp.limiter = sp->limiter; species_inp.split_type = sp->split_type; @@ -168,11 +167,12 @@ singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, // choose proper block-specific species input const struct gkyl_moment_multib_species_pb *sp_pb = &sp->blocks[0]; if (!sp->duplicate_across_blocks) { - for (int i=0; iblocks[i].block_id) { sp_pb = &sp->blocks[i]; break; } + } } species_inp.ctx = sp_pb->ctx; @@ -187,7 +187,7 @@ singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, species_inp.nT_source_set_only_once = sp_pb->nT_source_set_only_once; // by default, skip BCs altogether - for (int e=0; e<2; ++e) { + for (int e = 0; e < 2; ++e) { species_inp.bcx[e] = GKYL_SPECIES_SKIP; species_inp.bcy[e] = GKYL_SPECIES_SKIP; species_inp.bcz[e] = GKYL_SPECIES_SKIP; @@ -196,16 +196,16 @@ singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, // set species physical BCs: we need to search through the list of // physical BCs and set the appropriate input to single-block // species inp - for (int i=0; inum_physical_bcs; ++i) { + for (int i = 0; i < sp->num_physical_bcs; ++i) { if (bid == sp->bcs[i].bidx) { - int e = sp->bcs[i].edge; - if (sp->bcs[i].dir == 0) + if (sp->bcs[i].dir == 0) { species_inp.bcx[e] = sp->bcs[i].bc_type; - else if (sp->bcs[i].dir == 1) + } else if (sp->bcs[i].dir == 1) { species_inp.bcy[e] = sp->bcs[i].bc_type; - else + } else { species_inp.bcz[e] = sp->bcs[i].bc_type; + } } } @@ -213,10 +213,9 @@ singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, memcpy(&app_inp.species[i], &species_inp, sizeof(struct gkyl_moment_species)); } - // construct field input if (mbinp->field.blocks) { // assumption is that blocks = 0 when there is no field - struct gkyl_moment_field field_inp = { }; + struct gkyl_moment_field field_inp = {}; const struct gkyl_moment_multib_field *fld = &mbinp->field; field_inp.epsilon0 = fld->epsilon0; @@ -230,11 +229,12 @@ singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, // choose proper block-specific field input const struct gkyl_moment_multib_field_pb *fld_pb = &fld->blocks[0]; if (!fld->duplicate_across_blocks) { - for (int i=0; iblocks[i].block_id) { fld_pb = &fld->blocks[i]; break; } + } } field_inp.ctx = fld_pb->ctx; @@ -253,7 +253,7 @@ singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, field_inp.use_explicit_em_coupling = fld_pb->use_explicit_em_coupling; // by default, skip BCs altogether - for (int e=0; e<2; ++e) { + for (int e = 0; e < 2; ++e) { field_inp.bcx[e] = GKYL_FIELD_SKIP; field_inp.bcy[e] = GKYL_FIELD_SKIP; field_inp.bcz[e] = GKYL_FIELD_SKIP; @@ -262,18 +262,18 @@ singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, // set field physical BCs: we need to search through the list of // physical BCs and set the appropriate input to single-block // field inp - for (int i=0; inum_physical_bcs; ++i) { + for (int i = 0; i < fld->num_physical_bcs; ++i) { if (bid == fld->bcs[i].bidx) { - int e = fld->bcs[i].edge; - if (fld->bcs[i].dir == 0) + if (fld->bcs[i].dir == 0) { field_inp.bcx[e] = fld->bcs[i].bc_type; - else if (fld->bcs[i].dir == 1) + } else if (fld->bcs[i].dir == 1) { field_inp.bcy[e] = fld->bcs[i].bc_type; - else + } else { field_inp.bcz[e] = fld->bcs[i].bc_type; + } } - } + } // copy field input into app input memcpy(&app_inp.field, &field_inp, sizeof(struct gkyl_moment_field)); @@ -282,8 +282,10 @@ singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, struct gkyl_comm *comm = mbapp->block_comms[bid]; struct gkyl_app_parallelism_inp parallel_inp = {}; -// parallel_inp.use_gpu = mbinp->use_gpu; // MF 2024/09/18: moments don't have use_gpu. - for (int d=0; dcuts[d]; + // parallel_inp.use_gpu = mbinp->use_gpu; // MF 2024/09/18: moments don't have use_gpu. + for (int d = 0; d < ndim; ++d) { + parallel_inp.cuts[d] = bgi->cuts[d]; + } parallel_inp.comm = comm; // copy parallelism input into app input. memcpy(&app_inp.parallelism, ¶llel_inp, sizeof(struct gkyl_app_parallelism_inp)); @@ -291,9 +293,7 @@ singleb_app_new(const struct gkyl_moment_multib *mbinp, int bid, return gkyl_moment_app_new(&app_inp); } - -struct gkyl_moment_multib_app * -gkyl_moment_multib_app_new(const struct gkyl_moment_multib *mbinp) +struct gkyl_moment_multib_app *gkyl_moment_multib_app_new(const struct gkyl_moment_multib *mbinp) { int my_rank; gkyl_comm_get_rank(mbinp->comm, &my_rank); @@ -302,22 +302,23 @@ gkyl_moment_multib_app_new(const struct gkyl_moment_multib *mbinp) int tot_max[2]; calc_tot_and_max_cuts(mbinp->block_geom, tot_max); - if ((num_ranks > tot_max[0]) || (num_ranks < tot_max[1])) + if ((num_ranks > tot_max[0]) || (num_ranks < tot_max[1])) { return 0; + } struct gkyl_moment_multib_app *mbapp = gkyl_malloc(sizeof(*mbapp)); strcpy(mbapp->name, mbinp->name); - mbapp->comm = gkyl_comm_acquire(mbinp->comm); - + mbapp->comm = gkyl_comm_acquire(mbinp->comm); + mbapp->block_geom = gkyl_block_geom_acquire(mbinp->block_geom); mbapp->block_topo = gkyl_block_geom_topo(mbinp->block_geom); - + int ndim = gkyl_block_geom_ndim(mbapp->block_geom); int num_blocks = gkyl_block_geom_num_blocks(mbapp->block_geom); // construct round-robin decomposition int *branks = gkyl_malloc(sizeof(int[num_blocks])); - for (int i=0; iblock_geom, i); branks[i] = calc_cuts(ndim, bgi->cuts); } @@ -329,134 +330,133 @@ gkyl_moment_multib_app_new(const struct gkyl_moment_multib *mbinp) int lidx = 0; int *rank_list = gkyl_malloc(sizeof(int[num_ranks])); // this is larger than needed - mbapp->decomp = gkyl_malloc(num_blocks*sizeof(struct gkyl_rect_decomp*)); - + mbapp->decomp = gkyl_malloc(num_blocks * sizeof(struct gkyl_rect_decomp *)); + // construct list of block communicators: there are as many // communicators as blocks. Not all communicators are valid on each // rank. The total number of valid communicators is // num_local_blocks. - mbapp->block_comms = gkyl_malloc(num_blocks*sizeof(struct gkyl_comm *)); - for (int i=0; iblock_comms = gkyl_malloc(num_blocks * sizeof(struct gkyl_comm *)); + for (int i = 0; i < num_blocks; ++i) { gkyl_rrobin_decomp_getranks(mbapp->round_robin, i, rank_list); bool is_my_rank_in_decomp = has_int(branks[i], my_rank, rank_list); if (is_my_rank_in_decomp) { mbapp->local_blocks[lidx++] = i; - num_local_blocks += 1; + num_local_blocks += 1; } const struct gkyl_block_geom_info *bgi = gkyl_block_geom_get_block(mbapp->block_geom, i); struct gkyl_range block_global_range; gkyl_create_global_range(ndim, bgi->cells, &block_global_range); - mbapp->decomp[i] = gkyl_rect_decomp_new_from_cuts( - ndim, bgi->cuts, &block_global_range); + mbapp->decomp[i] = gkyl_rect_decomp_new_from_cuts(ndim, bgi->cuts, &block_global_range); bool status; - mbapp->block_comms[i] = gkyl_comm_create_comm_from_ranks(mbinp->comm, - branks[i], rank_list, mbapp->decomp[i], &status); + mbapp->block_comms[i] = gkyl_comm_create_comm_from_ranks( + mbinp->comm, branks[i], rank_list, mbapp->decomp[i], &status + ); } gkyl_free(rank_list); - mbapp->num_local_blocks = num_local_blocks; + mbapp->num_local_blocks = num_local_blocks; printf("Rank %d handles %d Apps\n", my_rank, num_local_blocks); - for (int i=0; ilocal_blocks[i]); + } mbapp->num_species = 0; mbapp->singleb_apps = 0; - + if (num_local_blocks > 0) { mbapp->num_species = mbinp->num_species; - mbapp->singleb_apps = gkyl_malloc(num_local_blocks*sizeof(struct gkyl_moment_app*)); + mbapp->singleb_apps = gkyl_malloc(num_local_blocks * sizeof(struct gkyl_moment_app *)); } - if (!mbinp->field.blocks) + if (!mbinp->field.blocks) { mbapp->has_field = false; + } - for (int i=0; inum_species; ++i) + for (int i = 0; i < mbinp->num_species; ++i) { strcpy(mbapp->species_name[i], mbinp->species[i].name); + } // create single-block App for all local blocks this rank handles - for (int i=0; isingleb_apps[i] = singleb_app_new(mbinp, mbapp->local_blocks[i], mbapp); + } // construct send/recv lists for each block this rank handles mbapp->send_conn = gkyl_malloc(sizeof(struct gkyl_multib_comm_conn *[num_local_blocks])); mbapp->recv_conn = gkyl_malloc(sizeof(struct gkyl_multib_comm_conn *[num_local_blocks])); - mbapp->stat = (struct gkyl_moment_stat) { - }; + mbapp->stat = (struct gkyl_moment_stat){}; gkyl_free(branks); - + return mbapp; } -double -gkyl_moment_multib_app_max_dt(gkyl_moment_multib_app *app) +double gkyl_moment_multib_app_max_dt(gkyl_moment_multib_app *app) { // TODO return 0; } - -void -gkyl_moment_multib_app_apply_ic(gkyl_moment_multib_app* app, double t0) +void gkyl_moment_multib_app_apply_ic(gkyl_moment_multib_app *app, double t0) { app->tcurr = t0; gkyl_moment_multib_app_apply_ic_field(app, t0); - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { gkyl_moment_multib_app_apply_ic_species(app, i, t0); + } } -void -gkyl_moment_multib_app_apply_ic_field(gkyl_moment_multib_app* app, double t0) +void gkyl_moment_multib_app_apply_ic_field(gkyl_moment_multib_app *app, double t0) { app->tcurr = t0; - for (int i=0; inum_local_blocks; ++i) + for (int i = 0; i < app->num_local_blocks; ++i) { gkyl_moment_app_apply_ic_field(app->singleb_apps[i], t0); + } gkyl_comm_barrier(app->comm); } -void -gkyl_moment_multib_app_apply_ic_species(gkyl_moment_multib_app* app, int sidx, double t0) +void gkyl_moment_multib_app_apply_ic_species(gkyl_moment_multib_app *app, int sidx, double t0) { app->tcurr = t0; - for (int i=0; inum_local_blocks; ++i) + for (int i = 0; i < app->num_local_blocks; ++i) { gkyl_moment_app_apply_ic_species(app->singleb_apps[i], sidx, t0); + } gkyl_comm_barrier(app->comm); } struct gkyl_app_restart_status -gkyl_moment_multib_app_from_frame_field(gkyl_moment_multib_app *app, - int frame) +gkyl_moment_multib_app_from_frame_field(gkyl_moment_multib_app *app, int frame) { // TODO - return (struct gkyl_app_restart_status) { }; + return (struct gkyl_app_restart_status){}; } struct gkyl_app_restart_status -gkyl_moment_multib_app_from_frame_species(gkyl_moment_multib_app *app, - int sidx, int frame) +gkyl_moment_multib_app_from_frame_species(gkyl_moment_multib_app *app, int sidx, int frame) { // TODO - return (struct gkyl_app_restart_status) { }; + return (struct gkyl_app_restart_status){}; } // private function to handle variable argument list for printing static void -v_moment_app_cout(const gkyl_moment_multib_app* app, FILE *fp, const char *fmt, va_list argp) +v_moment_app_cout(const gkyl_moment_multib_app *app, FILE *fp, const char *fmt, va_list argp) { int rank; gkyl_comm_get_rank(app->comm, &rank); - if ((rank == 0) && fp) + if ((rank == 0) && fp) { vfprintf(fp, fmt, argp); + } } -void -gkyl_moment_multib_app_cout(const gkyl_moment_multib_app* app, FILE *fp, const char *fmt, ...) +void gkyl_moment_multib_app_cout(const gkyl_moment_multib_app *app, FILE *fp, const char *fmt, ...) { va_list argp; va_start(argp, fmt); @@ -464,8 +464,7 @@ gkyl_moment_multib_app_cout(const gkyl_moment_multib_app* app, FILE *fp, const c va_end(argp); } -void -gkyl_moment_multib_app_write_topo(const gkyl_moment_multib_app* app) +void gkyl_moment_multib_app_write_topo(const gkyl_moment_multib_app *app) { int rank; gkyl_comm_get_rank(app->comm, &rank); @@ -476,19 +475,19 @@ gkyl_moment_multib_app_write_topo(const gkyl_moment_multib_app* app) } } -void -gkyl_moment_multib_app_write(const gkyl_moment_multib_app* app, double tm, int frame) +void gkyl_moment_multib_app_write(const gkyl_moment_multib_app *app, double tm, int frame) { gkyl_moment_multib_app_write_field(app, tm, frame); - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { gkyl_moment_multib_app_write_species(app, i, tm, frame); + } } -void -gkyl_moment_multib_app_write_field(const gkyl_moment_multib_app *app, double tm, int frame) +void gkyl_moment_multib_app_write_field(const gkyl_moment_multib_app *app, double tm, int frame) { - for (int i=0; inum_local_blocks; ++i) + for (int i = 0; i < app->num_local_blocks; ++i) { gkyl_moment_app_write_field(app->singleb_apps[i], tm, frame); + } if (app->has_field) { int rank; @@ -496,108 +495,98 @@ gkyl_moment_multib_app_write_field(const gkyl_moment_multib_app *app, double tm, if (0 == rank) { cstr file_name = cstr_from_fmt("%s-%s_%d.gkyl", app->name, "field", frame); cstr topo_file_name = cstr_from_fmt("%s_btopo.gkyl", app->name); - - moment_multib_data_write(file_name.str, (struct moment_multib_output_meta) { - .frame = frame, - .stime = tm, - .topo_file_name = topo_file_name.str, - .app_name = app->name - } + + moment_multib_data_write( + file_name.str, + (struct moment_multib_output_meta + ){.frame = frame, .stime = tm, .topo_file_name = topo_file_name.str, .app_name = app->name} ); - + cstr_drop(&topo_file_name); cstr_drop(&file_name); } } - + gkyl_comm_barrier(app->comm); } -void -gkyl_moment_multib_app_write_species(const gkyl_moment_multib_app* app, int sidx, double tm, int frame) +void gkyl_moment_multib_app_write_species( + const gkyl_moment_multib_app *app, int sidx, double tm, int frame +) { - for (int i=0; inum_local_blocks; ++i) + for (int i = 0; i < app->num_local_blocks; ++i) { gkyl_moment_app_write_species(app->singleb_apps[i], sidx, tm, frame); + } int rank; gkyl_comm_get_rank(app->comm, &rank); if (0 == rank) { cstr file_name = cstr_from_fmt("%s-%s_%d.gkyl", app->name, app->species_name[sidx], frame); cstr topo_file_name = cstr_from_fmt("%s_btopo.gkyl", app->name); - - moment_multib_data_write(file_name.str, (struct moment_multib_output_meta) { - .frame = frame, - .stime = tm, - .topo_file_name = topo_file_name.str, - .app_name = app->name - } + + moment_multib_data_write( + file_name.str, + (struct moment_multib_output_meta + ){.frame = frame, .stime = tm, .topo_file_name = topo_file_name.str, .app_name = app->name} ); - + cstr_drop(&topo_file_name); cstr_drop(&file_name); - } - + } + gkyl_comm_barrier(app->comm); } -void -gkyl_moment_multib_app_write_field_energy(gkyl_moment_multib_app *app) +void gkyl_moment_multib_app_write_field_energy(gkyl_moment_multib_app *app) { // TODO } -void -gkyl_moment_multib_app_write_integrated_mom(gkyl_moment_multib_app *app) +void gkyl_moment_multib_app_write_integrated_mom(gkyl_moment_multib_app *app) { // TODO } -void -gkyl_moment_multib_app_stat_write(const gkyl_moment_multib_app *app) +void gkyl_moment_multib_app_stat_write(const gkyl_moment_multib_app *app) { // TODO } -struct gkyl_update_status -gkyl_moment_multib_update(gkyl_moment_multib_app *app, double dt) +struct gkyl_update_status gkyl_moment_multib_update(gkyl_moment_multib_app *app, double dt) { // TODO - return (struct gkyl_update_status) { }; + return (struct gkyl_update_status){}; } -void -gkyl_moment_multib_app_calc_field_energy(gkyl_moment_multib_app *app, double tm) +void gkyl_moment_multib_app_calc_field_energy(gkyl_moment_multib_app *app, double tm) { - // TODO + // TODO } -void -gkyl_moment_multib_app_get_field_energy(gkyl_moment_multib_app *app, double *vals) +void gkyl_moment_multib_app_get_field_energy(gkyl_moment_multib_app *app, double *vals) { // TODO } -void -gkyl_moment_multib_app_calc_integrated_mom(gkyl_moment_multib_app *app, double tm) +void gkyl_moment_multib_app_calc_integrated_mom(gkyl_moment_multib_app *app, double tm) { // TODO } -struct gkyl_moment_stat -gkyl_moment_multib_app_stat(gkyl_moment_multib_app *app) +struct gkyl_moment_stat gkyl_moment_multib_app_stat(gkyl_moment_multib_app *app) { return app->stat; } -void -gkyl_moment_multib_app_release(gkyl_moment_multib_app* mbapp) +void gkyl_moment_multib_app_release(gkyl_moment_multib_app *mbapp) { if (mbapp->singleb_apps) { - for (int i=0; inum_local_blocks; ++i) + for (int i = 0; i < mbapp->num_local_blocks; ++i) { gkyl_moment_app_release(mbapp->singleb_apps[i]); + } gkyl_free(mbapp->singleb_apps); - for (int i=0; inum_local_blocks; ++i) { + for (int i = 0; i < mbapp->num_local_blocks; ++i) { //gkyl_multib_comm_conn_release(mbapp->send_conn[i]); //gkyl_multib_comm_conn_release(mbapp->recv_conn[i]); } @@ -606,23 +595,24 @@ gkyl_moment_multib_app_release(gkyl_moment_multib_app* mbapp) gkyl_free(mbapp->recv_conn); } - int num_blocks = gkyl_block_geom_num_blocks(mbapp->block_geom); - for (int i=0; idecomp[i]); + } gkyl_free(mbapp->decomp); - for (int i=0; iblock_comms[i]); + } gkyl_free(mbapp->block_comms); gkyl_comm_release(mbapp->comm); gkyl_rrobin_decomp_release(mbapp->round_robin); - + gkyl_block_geom_release(mbapp->block_geom); gkyl_block_topo_release(mbapp->block_topo); - gkyl_free(mbapp->local_blocks); - + gkyl_free(mbapp->local_blocks); + gkyl_free(mbapp); } diff --git a/moments/creg/rt_10m_burch.c b/moments/creg/rt_10m_burch.c index a433d79424..849fab819b 100644 --- a/moments/creg/rt_10m_burch.c +++ b/moments/creg/rt_10m_burch.c @@ -25,8 +25,7 @@ #include #include -struct burch_ctx -{ +struct burch_ctx { // Mathematical constants (dimensionless). double pi; @@ -82,11 +81,10 @@ struct burch_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct burch_ctx -create_ctx(void) +struct burch_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -101,13 +99,16 @@ create_ctx(void) double vAe = 0.2; // Electron Alfven velocity. double n0 = 1.0; // Reference number density. double beta2 = 2.748; // Magnetosheath plasma beta. - double Ti1_over_Ti2 = 7.73 / 1.374; // Magnetospheric ion temperature / magnetosheath ion temperature. - double Te1_over_Te2 = 1.288 / 1.374; // Magnetospheric electron temperature / magnetosheath ion temperature. + double Ti1_over_Ti2 = + 7.73 / 1.374; // Magnetospheric ion temperature / magnetosheath ion temperature. + double Te1_over_Te2 = + 1.288 / 1.374; // Magnetospheric electron temperature / magnetosheath ion temperature. // Derived physical quantities (using normalized code units). double light_speed = 1.0 / sqrt(mu0 * epsilon0); // Speed of light. double B0 = vAe * sqrt(n0 * mass_elc); // Reference magnetic field strength. - double omega_pi = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_ion)); // Ion plasma frequency. + double omega_pi = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_ion)); // Ion plasma frequency. double di = light_speed / omega_pi; // Ion skin depth. double omega0 = 1.0 * di; // Reference frequency. double psi0 = 0.1 * B0 * di; // Reference magnetic scalar potential. @@ -122,8 +123,9 @@ create_ctx(void) double Te1 = Ti2 * Te1_over_Te2; // Magnetospheric electron temperature. double Ti1 = Ti2 * Ti1_over_Ti2; // Magnetospheric ion temperature. - double Te2 = (0.5 * (b1 * b1 - b2 * b2) + 0.5 * (guide1 * guide1 - guide2 * guide2) - + n1 * (Ti1 + Te1) - n2 * Ti2) / n2; // Magnetosheath electron temperature (so that the system is in force balance). + double Te2 = (0.5 * (b1 * b1 - b2 * b2) + 0.5 * (guide1 * guide1 - guide2 * guide2) + + n1 * (Ti1 + Te1) - n2 * Ti2) / + n2; // Magnetosheath electron temperature (so that the system is in force balance). // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -144,8 +146,9 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. - + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. + struct burch_ctx ctx = { .pi = pi, .epsilon0 = epsilon0, @@ -190,14 +193,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct burch_ctx *app = ctx; @@ -224,37 +226,54 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Lx = app->Lx; double Ly = app->Ly; - double b1x = 0.5 * (b2 + b1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). + double b1x = 0.5 * (b2 + b1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). double b1y = 0.0; // Magnetospheric magnetic field (y-direction). - double b1z = 0.5 * (guide2 - guide1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). - - double Ti_tot = 0.5 * (Ti2 - Ti1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Ti2 + Ti1); // Total ion temperature. - double Te_tot = 0.5 * (Te2 - Te1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Te2 + Te1); // Total electron temperature. - double n = (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / (Ti_tot + Te_tot); // Total number density. - - double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). - double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). + double b1z = 0.5 * (guide2 - guide1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). + + double Ti_tot = 0.5 * (Ti2 - Ti1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Ti2 + Ti1); // Total ion temperature. + double Te_tot = 0.5 * (Te2 - Te1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Te2 + Te1); // Total electron temperature. + double n = + (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / + (Ti_tot + Te_tot); // Total number density. + + double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * + sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). + double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * + (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). double Bz = b1z; // Total magnetic field (z-direction). double Te_frac = Te_tot / (Te_tot + Ti_tot); // Fraction of total temperature from electrons. double Ti_frac = Ti_tot / (Te_tot + Ti_tot); // Fraction of total temperature from ions; - double Jx = 0.5 * (guide2 - guide1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))); // Total current density (x-direction). + double Jx = 0.5 * (guide2 - guide1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0)) + ); // Total current density (x-direction). double Jy = 0.0; // Total current density (y-direction). - double Jz = -0.5 * (b2 + b1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - - psi0 * sin(2.0 * pi * x / Lx) * ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) - + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly)); // Total current density (z-direction). - + double Jz = -0.5 * (b2 + b1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - + psi0 * sin(2.0 * pi * x / Lx) * + ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) + + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly) + ); // Total current density (z-direction). + double Jxe = Jx * Te_frac; // Electron current density (x-direction). double Jye = Jy * Te_frac; // Electron current density (y-direction). double Jze = Jz * Te_frac; // Electron current density (z-direction). @@ -274,14 +293,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre_xx; fout[5] = pre_xy; fout[6] = pre_xz; - fout[7] = pre_yy; fout[8] = pre_yz; fout[9] = pre_zz; + fout[4] = pre_xx; + fout[5] = pre_xy; + fout[6] = pre_xz; + fout[7] = pre_yy; + fout[8] = pre_yz; + fout[9] = pre_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct burch_ctx *app = ctx; @@ -308,37 +332,54 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Lx = app->Lx; double Ly = app->Ly; - double b1x = 0.5 * (b2 + b1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). + double b1x = 0.5 * (b2 + b1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). double b1y = 0.0; // Magnetospheric magnetic field (y-direction). - double b1z = 0.5 * (guide2 - guide1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). - - double Ti_tot = 0.5 * (Ti2 - Ti1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Ti2 + Ti1); // Total ion temperature. - double Te_tot = 0.5 * (Te2 - Te1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Te2 + Te1); // Total electron temperature. - double n = (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / (Ti_tot + Te_tot); // Total number density. - - double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). - double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). + double b1z = 0.5 * (guide2 - guide1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). + + double Ti_tot = 0.5 * (Ti2 - Ti1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Ti2 + Ti1); // Total ion temperature. + double Te_tot = 0.5 * (Te2 - Te1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Te2 + Te1); // Total electron temperature. + double n = + (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / + (Ti_tot + Te_tot); // Total number density. + + double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * + sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). + double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * + (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). double Bz = b1z; // Total magnetic field (z-direction). double Te_frac = Te_tot / (Te_tot + Ti_tot); // Fraction of total temperature from electrons. double Ti_frac = Ti_tot / (Te_tot + Ti_tot); // Fraction of total temperature from ions; - double Jx = 0.5 * (guide2 - guide1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))); // Total current density (x-direction). + double Jx = 0.5 * (guide2 - guide1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0)) + ); // Total current density (x-direction). double Jy = 0.0; // Total current density (y-direction). - double Jz = -0.5 * (b2 + b1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - - psi0 * sin(2.0 * pi * x / Lx) * ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) - + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly)); // Total current density (z-direction). - + double Jz = -0.5 * (b2 + b1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - + psi0 * sin(2.0 * pi * x / Lx) * + ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) + + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly) + ); // Total current density (z-direction). + double Jxi = Jx * Ti_frac; // Ion current density (x-direction). double Jyi = Jy * Ti_frac; // Ion current density (y-direction). double Jzi = Jz * Ti_frac; // Ion current density (z-direction). @@ -358,14 +399,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density, fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion pressure tensor. - fout[4] = pri_xx; fout[5] = pri_xy; fout[6] = pri_xz; - fout[7] = pri_yy; fout[8] = pri_yz; fout[9] = pri_zz; + fout[4] = pri_xx; + fout[5] = pri_xy; + fout[6] = pri_xz; + fout[7] = pri_yy; + fout[8] = pri_yz; + fout[9] = pri_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct burch_ctx *app = ctx; @@ -389,36 +435,50 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Lx = app->Lx; double Ly = app->Ly; - double b1x = 0.5 * (b2 + b1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). + double b1x = 0.5 * (b2 + b1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). double b1y = 0.0; // Magnetospheric magnetic field (y-direction). - double b1z = 0.5 * (guide2 - guide1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). - - double Ti_tot = 0.5 * (Ti2 - Ti1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Ti2 + Ti1); // Total ion temperature. - double Te_tot = 0.5 * (Te2 - Te1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Te2 + Te1); // Total electron temperature. - double n = (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / (Ti_tot + Te_tot); // Total number density. + double b1z = 0.5 * (guide2 - guide1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). + + double Ti_tot = 0.5 * (Ti2 - Ti1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Ti2 + Ti1); // Total ion temperature. + double Te_tot = 0.5 * (Te2 - Te1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Te2 + Te1); // Total electron temperature. + double n = + (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / + (Ti_tot + Te_tot); // Total number density. double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). - double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). + double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * + sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). + double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * + (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). double Bz = b1z; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -432,24 +492,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -469,7 +530,7 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -479,8 +540,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -494,43 +554,49 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); } } - + // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_elc, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_ion, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_elc, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_ion, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -541,7 +607,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -549,8 +615,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -564,22 +629,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -603,24 +658,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx / ctx.di, ctx.Ly / ctx.di }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx / ctx.di, ctx.Ly / ctx.di}, + .cells = {NX, NY}, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -634,10 +686,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -646,26 +702,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -681,7 +742,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -696,8 +757,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -705,7 +765,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -713,8 +775,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -748,7 +809,7 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_10m_burch_grad_closure.c b/moments/creg/rt_10m_burch_grad_closure.c index 1b0611e745..cb586346c3 100644 --- a/moments/creg/rt_10m_burch_grad_closure.c +++ b/moments/creg/rt_10m_burch_grad_closure.c @@ -25,8 +25,7 @@ #include #include -struct burch_grad_closure_ctx -{ +struct burch_grad_closure_ctx { // Mathematical constants (dimensionless). double pi; @@ -82,11 +81,10 @@ struct burch_grad_closure_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct burch_grad_closure_ctx -create_ctx(void) +struct burch_grad_closure_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -101,13 +99,16 @@ create_ctx(void) double vAe = 0.2; // Electron Alfven velocity. double n0 = 1.0; // Reference number density. double beta2 = 2.748; // Magnetosheath plasma beta. - double Ti1_over_Ti2 = 7.73 / 1.374; // Magnetospheric ion temperature / magnetosheath ion temperature. - double Te1_over_Te2 = 1.288 / 1.374; // Magnetospheric electron temperature / magnetosheath ion temperature. + double Ti1_over_Ti2 = + 7.73 / 1.374; // Magnetospheric ion temperature / magnetosheath ion temperature. + double Te1_over_Te2 = + 1.288 / 1.374; // Magnetospheric electron temperature / magnetosheath ion temperature. // Derived physical quantities (using normalized code units). double light_speed = 1.0 / sqrt(mu0 * epsilon0); // Speed of light. double B0 = vAe * sqrt(n0 * mass_elc); // Reference magnetic field strength. - double omega_pi = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_ion)); // Ion plasma frequency. + double omega_pi = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_ion)); // Ion plasma frequency. double di = light_speed / omega_pi; // Ion skin depth. double omega0 = 1.0 * di; // Reference frequency. double psi0 = 0.1 * B0 * di; // Reference magnetic scalar potential. @@ -122,8 +123,9 @@ create_ctx(void) double Te1 = Ti2 * Te1_over_Te2; // Magnetospheric electron temperature. double Ti1 = Ti2 * Ti1_over_Ti2; // Magnetospheric ion temperature. - double Te2 = (0.5 * (b1 * b1 - b2 * b2) + 0.5 * (guide1 * guide1 - guide2 * guide2) - + n1 * (Ti1 + Te1) - n2 * Ti2) / n2; // Magnetosheath electron temperature (so that the system is in force balance). + double Te2 = (0.5 * (b1 * b1 - b2 * b2) + 0.5 * (guide1 * guide1 - guide2 * guide2) + + n1 * (Ti1 + Te1) - n2 * Ti2) / + n2; // Magnetosheath electron temperature (so that the system is in force balance). // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -144,8 +146,9 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. - + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. + struct burch_grad_closure_ctx ctx = { .pi = pi, .epsilon0 = epsilon0, @@ -190,14 +193,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct burch_grad_closure_ctx *app = ctx; @@ -224,37 +226,54 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Lx = app->Lx; double Ly = app->Ly; - double b1x = 0.5 * (b2 + b1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). + double b1x = 0.5 * (b2 + b1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). double b1y = 0.0; // Magnetospheric magnetic field (y-direction). - double b1z = 0.5 * (guide2 - guide1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). - - double Ti_tot = 0.5 * (Ti2 - Ti1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Ti2 + Ti1); // Total ion temperature. - double Te_tot = 0.5 * (Te2 - Te1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Te2 + Te1); // Total electron temperature. - double n = (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / (Ti_tot + Te_tot); // Total number density. - - double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). - double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). + double b1z = 0.5 * (guide2 - guide1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). + + double Ti_tot = 0.5 * (Ti2 - Ti1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Ti2 + Ti1); // Total ion temperature. + double Te_tot = 0.5 * (Te2 - Te1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Te2 + Te1); // Total electron temperature. + double n = + (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / + (Ti_tot + Te_tot); // Total number density. + + double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * + sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). + double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * + (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). double Bz = b1z; // Total magnetic field (z-direction). double Te_frac = Te_tot / (Te_tot + Ti_tot); // Fraction of total temperature from electrons. double Ti_frac = Ti_tot / (Te_tot + Ti_tot); // Fraction of total temperature from ions; - double Jx = 0.5 * (guide2 - guide1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))); // Total current density (x-direction). + double Jx = 0.5 * (guide2 - guide1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0)) + ); // Total current density (x-direction). double Jy = 0.0; // Total current density (y-direction). - double Jz = -0.5 * (b2 + b1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - - psi0 * sin(2.0 * pi * x / Lx) * ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) - + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly)); // Total current density (z-direction). - + double Jz = -0.5 * (b2 + b1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - + psi0 * sin(2.0 * pi * x / Lx) * + ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) + + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly) + ); // Total current density (z-direction). + double Jxe = Jx * Te_frac; // Electron current density (x-direction). double Jye = Jy * Te_frac; // Electron current density (y-direction). double Jze = Jz * Te_frac; // Electron current density (z-direction). @@ -274,14 +293,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre_xx; fout[5] = pre_xy; fout[6] = pre_xz; - fout[7] = pre_yy; fout[8] = pre_yz; fout[9] = pre_zz; + fout[4] = pre_xx; + fout[5] = pre_xy; + fout[6] = pre_xz; + fout[7] = pre_yy; + fout[8] = pre_yz; + fout[9] = pre_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct burch_grad_closure_ctx *app = ctx; @@ -308,37 +332,54 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Lx = app->Lx; double Ly = app->Ly; - double b1x = 0.5 * (b2 + b1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). + double b1x = 0.5 * (b2 + b1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). double b1y = 0.0; // Magnetospheric magnetic field (y-direction). - double b1z = 0.5 * (guide2 - guide1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). - - double Ti_tot = 0.5 * (Ti2 - Ti1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Ti2 + Ti1); // Total ion temperature. - double Te_tot = 0.5 * (Te2 - Te1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Te2 + Te1); // Total electron temperature. - double n = (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / (Ti_tot + Te_tot); // Total number density. - - double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). - double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). + double b1z = 0.5 * (guide2 - guide1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). + + double Ti_tot = 0.5 * (Ti2 - Ti1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Ti2 + Ti1); // Total ion temperature. + double Te_tot = 0.5 * (Te2 - Te1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Te2 + Te1); // Total electron temperature. + double n = + (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / + (Ti_tot + Te_tot); // Total number density. + + double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * + sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). + double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * + (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). double Bz = b1z; // Total magnetic field (z-direction). double Te_frac = Te_tot / (Te_tot + Ti_tot); // Fraction of total temperature from electrons. double Ti_frac = Ti_tot / (Te_tot + Ti_tot); // Fraction of total temperature from ions; - double Jx = 0.5 * (guide2 - guide1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))); // Total current density (x-direction). + double Jx = 0.5 * (guide2 - guide1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0)) + ); // Total current density (x-direction). double Jy = 0.0; // Total current density (y-direction). - double Jz = -0.5 * (b2 + b1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - - psi0 * sin(2.0 * pi * x / Lx) * ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) - + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly)); // Total current density (z-direction). - + double Jz = -0.5 * (b2 + b1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - + psi0 * sin(2.0 * pi * x / Lx) * + ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) + + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly) + ); // Total current density (z-direction). + double Jxi = Jx * Ti_frac; // Ion current density (x-direction). double Jyi = Jy * Ti_frac; // Ion current density (y-direction). double Jzi = Jz * Ti_frac; // Ion current density (z-direction). @@ -358,14 +399,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density, fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion pressure tensor. - fout[4] = pri_xx; fout[5] = pri_xy; fout[6] = pri_xz; - fout[7] = pri_yy; fout[8] = pri_yz; fout[9] = pri_zz; + fout[4] = pri_xx; + fout[5] = pri_xy; + fout[6] = pri_xz; + fout[7] = pri_yy; + fout[8] = pri_yz; + fout[9] = pri_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct burch_grad_closure_ctx *app = ctx; @@ -389,36 +435,50 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Lx = app->Lx; double Ly = app->Ly; - double b1x = 0.5 * (b2 + b1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). + double b1x = 0.5 * (b2 + b1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). double b1y = 0.0; // Magnetospheric magnetic field (y-direction). - double b1z = 0.5 * (guide2 - guide1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). - - double Ti_tot = 0.5 * (Ti2 - Ti1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Ti2 + Ti1); // Total ion temperature. - double Te_tot = 0.5 * (Te2 - Te1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Te2 + Te1); // Total electron temperature. - double n = (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / (Ti_tot + Te_tot); // Total number density. + double b1z = 0.5 * (guide2 - guide1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). + + double Ti_tot = 0.5 * (Ti2 - Ti1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Ti2 + Ti1); // Total ion temperature. + double Te_tot = 0.5 * (Te2 - Te1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Te2 + Te1); // Total electron temperature. + double n = + (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / + (Ti_tot + Te_tot); // Total number density. double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). - double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). + double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * + sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). + double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * + (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). double Bz = b1z; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -432,24 +492,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -469,7 +530,7 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -479,8 +540,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -494,43 +554,49 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); } } - + // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_elc, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_ion, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_elc, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_ion, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -540,7 +606,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -548,8 +614,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -563,25 +628,15 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .sync_corners = true, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .sync_corners = true}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); #endif int my_rank; @@ -605,24 +660,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx / ctx.di, ctx.Ly / ctx.di }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx / ctx.di, ctx.Ly / ctx.di}, + .cells = {NX, NY}, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -636,10 +688,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -648,26 +704,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -683,7 +744,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -698,8 +759,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -707,7 +767,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -715,8 +777,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -750,13 +811,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_checkerboard.c b/moments/creg/rt_10m_checkerboard.c index 01bf1285c5..f3d46616ef 100644 --- a/moments/creg/rt_10m_checkerboard.c +++ b/moments/creg/rt_10m_checkerboard.c @@ -23,8 +23,7 @@ #include -struct lhdi_ctx -{ +struct lhdi_ctx { // Mathematical constants (dimensionless). double pi; @@ -56,8 +55,7 @@ struct lhdi_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lhdi_ctx -create_ctx(void) +struct lhdi_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -109,14 +107,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct lhdi_ctx *app = ctx; @@ -129,45 +126,54 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double T0 = app->T0; double T1 = app->T1; - double rhoe = n0*mass_elc; // Electron mass density. + double rhoe = n0 * mass_elc; // Electron mass density. double mome_x = 0.0; // Electron momentum density (x-direction). double mome_y = 0.0; // Electron momentum density (y-direction). double mome_z = 0.0; // Electron momentum density (z-direction). - double pre = n0*T1; // Electron pressure (scalar). + double pre = n0 * T1; // Electron pressure (scalar). if (((x < 1.0) || (x < 3.0 && x > 2.0)) && ((y > 3.0) || (y < 2.0 && y > 1.0))) { - pre = n0*T0; // Electron pressure (scalar). + pre = n0 * T0; // Electron pressure (scalar). } if (((x > 3.0) || (x < 2.0 && x > 1.0)) && ((y < 1.0) || (y < 3.0 && y > 2.0))) { - pre = n0*T0; // Electron pressure (scalar). + pre = n0 * T0; // Electron pressure (scalar). } // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre; fout[5] = 0.0; fout[6] = 0.0; - fout[7] = pre; fout[8] = 0.0; fout[9] = pre; + fout[4] = pre; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = pre; + fout[8] = 0.0; + fout[9] = pre; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct lhdi_ctx *app = ctx; // Set electric field. - fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = 0.0; fout[4] = 0.0; fout[5] = 0.0; + fout[3] = 0.0; + fout[4] = 0.0; + fout[5] = 0.0; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -181,24 +187,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -216,29 +223,32 @@ main(int argc, char **argv) struct lhdi_ctx ctx = create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); + int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_elc, true, false, 1, NULL, app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = + gkyl_wv_ten_moment_new(ctx.k0_elc, true, false, 1, NULL, app_args.use_gpu); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; int nrank = 1; // Number of processes in simulation. @@ -249,7 +259,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -257,8 +267,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -272,25 +281,15 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .sync_corners = true, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .sync_corners = true}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); #endif int my_rank; @@ -314,41 +313,42 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); gkyl_moment_app *app = gkyl_moment_app_new(&app_inp); - + // Initial and final simulation times. double t_curr = 0.0, t_end = ctx.t_end; // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -357,26 +357,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; // calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; // calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -392,7 +397,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -407,8 +412,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -416,7 +420,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); // calc_field_energy(&fe_trig, app, t_curr, true); // calc_integrated_mom(&im_trig, app, t_curr, true); @@ -424,8 +430,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -452,7 +457,7 @@ main(int argc, char **argv) gkyl_wv_eqn_release(elc_ten_moment); gkyl_comm_release(comm); gkyl_moment_app_release(app); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_10m_expanding.c b/moments/creg/rt_10m_expanding.c index 78eb12c9b5..52ed73a013 100644 --- a/moments/creg/rt_10m_expanding.c +++ b/moments/creg/rt_10m_expanding.c @@ -19,8 +19,7 @@ #include #include -struct expanding_ctx -{ +struct expanding_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double U0; // (Initial) comoving plasma velocity. @@ -46,11 +45,10 @@ struct expanding_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct expanding_ctx -create_ctx(void) +struct expanding_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -77,7 +75,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. struct expanding_ctx ctx = { .gas_gamma = gas_gamma, @@ -98,14 +97,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval10mInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct expanding_ctx *app = ctx; @@ -124,18 +122,23 @@ eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double pr_yy = p; // Fluid pressure tensor (yy-component). double pr_yz = 0.0; // Fluid pressure tensor (yz-component). double pr_zz = p; // Fluid pressure tensor (zz-component). - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -149,24 +152,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -185,7 +189,7 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 1); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 1); if (ctx.use_nn_closure) { const char *fmt_10m = "%s-%s.dat"; int sz_10m = gkyl_calc_strlen(fmt_10m, ctx.nn_closure_file, "10m"); @@ -195,8 +199,7 @@ main(int argc, char **argv) if (file_10m != NULL) { ann[0] = gkyl_kann_net_load(fileNm_10m, app_args.use_gpu); fclose(file_10m); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for 10m species not found! Disabling NN-based closure.\n"); @@ -204,12 +207,14 @@ main(int argc, char **argv) } // Fluid equations. - struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); + struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "10m", .equation = ten_moment, - + .init = eval10mInit, .ctx = &ctx, @@ -218,7 +223,7 @@ main(int argc, char **argv) .volume_U0 = ctx.U0, .volume_R0 = ctx.R0, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -229,7 +234,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -237,8 +242,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -252,22 +256,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -291,20 +285,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -318,10 +308,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -330,26 +324,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -365,7 +364,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -380,8 +379,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -389,7 +387,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -397,8 +397,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -431,13 +430,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_expanding_axi_sodshock.c b/moments/creg/rt_10m_expanding_axi_sodshock.c index e8c0907f5b..af14eb3e35 100644 --- a/moments/creg/rt_10m_expanding_axi_sodshock.c +++ b/moments/creg/rt_10m_expanding_axi_sodshock.c @@ -19,8 +19,7 @@ #include #include -struct expanding_axi_sodshock_ctx -{ +struct expanding_axi_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -57,11 +56,10 @@ struct expanding_axi_sodshock_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct expanding_axi_sodshock_ctx -create_ctx(void) +struct expanding_axi_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -99,7 +97,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. struct expanding_axi_sodshock_ctx ctx = { .pi = pi, @@ -127,14 +126,13 @@ create_ctx(void) .rloc = rloc, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -eval10mInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void eval10mInit(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { double r = zc[0]; struct expanding_axi_sodshock_ctx *app = ctx; @@ -159,8 +157,7 @@ eval10mInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout rho = rhol; // Fluid mass density (left/inner). u = ul; // Fluid velocity (left/inner). p = pl; // Fluid pressure (left/inner). - } - else { + } else { rho = rhor; // Fluid mass density (right/outer). u = ur; // Fluid velocity (right/outer). p = pr; // Fluid pressure (right/outer). @@ -176,18 +173,24 @@ eval10mInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout double pr_yy = p; // Fluid pressure tensor (yy-component). double pr_yz = 0.0; // Fluid pressure tensor (yz-component). double pr_zz = p; // Fluid pressure tensor (zz-component). - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double r = zc[0], theta = zc[1]; @@ -196,8 +199,7 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* xp[1] = r * sin(theta); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -211,24 +213,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -248,7 +251,7 @@ main(int argc, char **argv) int NR = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nr); int NTHETA = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ntheta); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 1); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 1); if (ctx.use_nn_closure) { const char *fmt_10m = "%s-%s.dat"; int sz_10m = gkyl_calc_strlen(fmt_10m, ctx.nn_closure_file, "10m"); @@ -258,8 +261,7 @@ main(int argc, char **argv) if (file_10m != NULL) { ann[0] = gkyl_kann_net_load(fileNm_10m, app_args.use_gpu); fclose(file_10m); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for 10m species not found! Disabling NN-based closure.\n"); @@ -267,12 +269,14 @@ main(int argc, char **argv) } // Fluid equations. - struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); + struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "10m", .equation = ten_moment, - + .init = eval10mInit, .ctx = &ctx, @@ -281,7 +285,7 @@ main(int argc, char **argv) .volume_U0 = ctx.U0, .volume_R0 = ctx.R0, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -292,7 +296,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NR, NTHETA }; + int cells[] = {NR, NTHETA}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -300,8 +304,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -315,22 +318,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -354,25 +347,22 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.25, 0.0 }, - .upper = { 0.25 + ctx.Lr, ctx.Ltheta }, - .cells = { NR, NTHETA }, + .lower = {0.25, 0.0}, + .upper = {0.25 + ctx.Lr, ctx.Ltheta}, + .cells = {NR, NTHETA}, .mapc2p = mapc2p, .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .periodic_dirs = {1}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -386,10 +376,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -398,26 +392,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -433,7 +432,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -448,8 +447,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -457,7 +455,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -465,8 +465,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -499,13 +498,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_expanding_sodshock.c b/moments/creg/rt_10m_expanding_sodshock.c index 1b77c329db..74a376e66d 100644 --- a/moments/creg/rt_10m_expanding_sodshock.c +++ b/moments/creg/rt_10m_expanding_sodshock.c @@ -19,8 +19,7 @@ #include #include -struct expanding_sodshock_ctx -{ +struct expanding_sodshock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double U0; // (Initial) comoving plasma velocity. @@ -50,11 +49,10 @@ struct expanding_sodshock_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct expanding_sodshock_ctx -create_ctx(void) +struct expanding_sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -85,7 +83,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. struct expanding_sodshock_ctx ctx = { .gas_gamma = gas_gamma, @@ -109,14 +108,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval10mInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct expanding_sodshock_ctx *app = ctx; @@ -137,8 +135,7 @@ eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -154,18 +151,23 @@ eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double pr_yy = p; // Fluid pressure tensor (yy-component). double pr_yz = 0.0; // Fluid pressure tensor (yz-component). double pr_zz = p; // Fluid pressure tensor (zz-component). - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -179,24 +181,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -215,7 +218,7 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 1); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 1); if (ctx.use_nn_closure) { const char *fmt_10m = "%s-%s.dat"; int sz_10m = gkyl_calc_strlen(fmt_10m, ctx.nn_closure_file, "10m"); @@ -225,8 +228,7 @@ main(int argc, char **argv) if (file_10m != NULL) { ann[0] = gkyl_kann_net_load(fileNm_10m, app_args.use_gpu); fclose(file_10m); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for 10m species not found! Disabling NN-based closure.\n"); @@ -234,12 +236,14 @@ main(int argc, char **argv) } // Fluid equations. - struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); + struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "10m", .equation = ten_moment, - + .init = eval10mInit, .ctx = &ctx, @@ -248,7 +252,7 @@ main(int argc, char **argv) .volume_U0 = ctx.U0, .volume_R0 = ctx.R0, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -259,7 +263,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -267,8 +271,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -282,22 +285,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -321,20 +314,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.25 }, - .upper = { 0.25 + ctx.Lx }, - .cells = { NX }, + .lower = {0.25}, + .upper = {0.25 + ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -348,10 +337,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -360,26 +353,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -395,7 +393,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -410,8 +408,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -419,7 +416,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -427,8 +426,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -461,13 +459,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_gem.c b/moments/creg/rt_10m_gem.c index 58e2a5394f..409005dcd4 100644 --- a/moments/creg/rt_10m_gem.c +++ b/moments/creg/rt_10m_gem.c @@ -25,11 +25,10 @@ #include #include -struct gem_ctx -{ +struct gem_ctx { // Mathematical constants (dimensionless). double pi; - + // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -44,7 +43,7 @@ struct gem_ctx double B0; // Reference magnetic field strength. double Ti_over_Te; // Ion temperature / electron temperature. double beta; // Total plasma beta. - + // Derived physical quantities (using normalized code units). double lambda; // Current sheet width. double psi0; // Reference magnetic scalar potential. @@ -62,7 +61,7 @@ struct gem_ctx double Ly; // Domain size (y-direction). double k0; // Closure parameter. double cfl_frac; // CFL coefficient. - + double t_end; // Final simulation time. int num_frames; // Number of output frames. int field_energy_calcs; // Number of times to calculate field energy. @@ -73,11 +72,10 @@ struct gem_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct gem_ctx -create_ctx(void) +struct gem_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -96,7 +94,7 @@ create_ctx(void) double B0 = 0.1; // Reference magnetic field strength. double Ti_over_Te = 5.0; // Ion temperature / electron temperature. double beta = 1.0; // Total plasma beta. - + // Derived physical quantities (using normalized code units). double lambda = 0.5 * di; // Current sheet width. double psi0 = 0.1 * B0 * di; // Reference magnetic scalar potential. @@ -125,7 +123,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. struct gem_ctx ctx = { .pi = pi, @@ -161,14 +160,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_ctx *app = ctx; @@ -184,7 +182,8 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Te_frac = app->Te_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -192,7 +191,8 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double rhoe = n * mass_elc; // Electron mass density. double mome_x = 0.0; // Electron momentum density (x-direction). double mome_y = 0.0; // Electron momentum density (y-direction). - double mome_z = (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). + double mome_z = + (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). double pre = n * T_tot * Te_frac; // Electron pressure (scalar). double pre_xx = pre; // Electron pressure tensor (xx-component). @@ -205,14 +205,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre_xx; fout[5] = pre_xy; fout[6] = pre_xz; - fout[7] = pre_yy; fout[8] = pre_yz; fout[9] = pre_zz; + fout[4] = pre_xx; + fout[5] = pre_xy; + fout[6] = pre_xz; + fout[7] = pre_yy; + fout[8] = pre_yz; + fout[9] = pre_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_ctx *app = ctx; @@ -228,7 +233,8 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Ti_frac = app->Ti_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -249,14 +255,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion pressure tensor. - fout[4] = pri_xx; fout[5] = pri_xy; fout[6] = pri_xz; - fout[7] = pri_yy; fout[8] = pri_yz; fout[9] = pri_zz; + fout[4] = pri_xx; + fout[5] = pri_xy; + fout[6] = pri_xz; + fout[7] = pri_yy; + fout[8] = pri_yz; + fout[9] = pri_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_ctx *app = ctx; @@ -277,20 +288,24 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * sin(pi * y / Ly); // Total magnetic field (x-direction). - double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * cos(pi * y / Ly); // Total magnetic field (y-direction). + double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * + sin(pi * y / Ly); // Total magnetic field (x-direction). + double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * + cos(pi * y / Ly); // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -304,24 +319,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -339,9 +355,9 @@ main(int argc, char **argv) struct gem_ctx ctx = create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); + int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -351,8 +367,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -366,49 +381,55 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); } } - + // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); - + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); + struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, .ctx = &ctx, - - .bcy = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + + .bcy = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -419,7 +440,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -427,8 +448,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -442,22 +462,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -481,24 +491,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly}, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly}, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -512,10 +519,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -524,26 +535,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -559,7 +575,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -574,8 +590,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -583,7 +598,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -591,8 +608,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -626,13 +642,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_gem_grad_closure.c b/moments/creg/rt_10m_gem_grad_closure.c index 16b9fe2616..b97570e976 100644 --- a/moments/creg/rt_10m_gem_grad_closure.c +++ b/moments/creg/rt_10m_gem_grad_closure.c @@ -25,11 +25,10 @@ #include #include -struct gem_grad_closure_ctx -{ +struct gem_grad_closure_ctx { // Mathematical constants (dimensionless). double pi; - + // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -44,7 +43,7 @@ struct gem_grad_closure_ctx double B0; // Reference magnetic field strength. double Ti_over_Te; // Ion temperature / electron temperature. double beta; // Total plasma beta. - + // Derived physical quantities (using normalized code units). double lambda; // Current sheet width. double psi0; // Reference magnetic scalar potential. @@ -73,11 +72,10 @@ struct gem_grad_closure_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct gem_grad_closure_ctx -create_ctx(void) +struct gem_grad_closure_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -96,7 +94,7 @@ create_ctx(void) double B0 = 0.1; // Reference magnetic field strength. double Ti_over_Te = 5.0; // Ion temperature / electron temperature. double beta = 1.0; // Total plasma beta. - + // Derived physical quantities (using normalized code units). double lambda = 0.5 * di; // Current sheet width. double psi0 = 0.1 * B0 * di; // Reference magnetic scalar potential. @@ -125,7 +123,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. struct gem_grad_closure_ctx ctx = { .pi = pi, @@ -161,14 +160,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_grad_closure_ctx *app = ctx; @@ -184,7 +182,8 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Te_frac = app->Te_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -192,7 +191,8 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double rhoe = n * mass_elc; // Electron mass density. double mome_x = 0.0; // Electron momentum density (x-direction). double mome_y = 0.0; // Electron momentum density (y-direction). - double mome_z = (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). + double mome_z = + (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). double pre = n * T_tot * Te_frac; // Electron pressure (scalar). double pre_xx = pre; // Electron pressure tensor (xx-component). @@ -205,14 +205,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre_xx; fout[5] = pre_xy; fout[6] = pre_xz; - fout[7] = pre_yy; fout[8] = pre_yz; fout[9] = pre_zz; + fout[4] = pre_xx; + fout[5] = pre_xy; + fout[6] = pre_xz; + fout[7] = pre_yy; + fout[8] = pre_yz; + fout[9] = pre_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_grad_closure_ctx *app = ctx; @@ -228,7 +233,8 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Ti_frac = app->Ti_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -249,14 +255,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion pressure tensor. - fout[4] = pri_xx; fout[5] = pri_xy; fout[6] = pri_xz; - fout[7] = pri_yy; fout[8] = pri_yz; fout[9] = pri_zz; + fout[4] = pri_xx; + fout[5] = pri_xy; + fout[6] = pri_xz; + fout[7] = pri_yy; + fout[8] = pri_yz; + fout[9] = pri_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_grad_closure_ctx *app = ctx; @@ -277,20 +288,24 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * sin(pi * y / Ly); // Total magnetic field (x-direction). - double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * cos(pi * y / Ly); // Total magnetic field (y-direction). + double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * + sin(pi * y / Ly); // Total magnetic field (x-direction). + double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * + cos(pi * y / Ly); // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -304,24 +319,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -339,9 +355,9 @@ main(int argc, char **argv) struct gem_grad_closure_ctx ctx = create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); + int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -351,8 +367,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -366,49 +381,55 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); } } - + // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); - + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); + struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, .ctx = &ctx, - - .bcy = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + + .bcy = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -419,7 +440,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -427,8 +448,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -442,25 +462,15 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .sync_corners = true, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .sync_corners = true}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); #endif int my_rank; @@ -484,24 +494,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly}, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly}, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -515,10 +522,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -527,26 +538,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -562,7 +578,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -577,8 +593,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -586,7 +601,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -594,8 +611,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -629,13 +645,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_lhdi.c b/moments/creg/rt_10m_lhdi.c index c4fd308873..bc2ccc8cdf 100644 --- a/moments/creg/rt_10m_lhdi.c +++ b/moments/creg/rt_10m_lhdi.c @@ -25,8 +25,7 @@ #include #include -struct lhdi_ctx -{ +struct lhdi_ctx { // Mathematical constants (dimensionless). double pi; @@ -64,7 +63,7 @@ struct lhdi_ctx double larmor_elc; // Electron Larmor radius. double l; // Current sheet width. - + double nb; // Background number density. double Te_frac; // Fraction of total temperature from electrons. double Ti_frac; // Fraction of total temperature from ions. @@ -90,11 +89,10 @@ struct lhdi_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct lhdi_ctx -create_ctx(void) +struct lhdi_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -123,7 +121,8 @@ create_ctx(void) double vti = sqrt(2.0 * Ti / mass_ion); // Ion thermal velocity. double vAe = vte / sqrt(beta); // Electron Alfven velocity. - double B0 = vAe; // Reference magnetic field strength (derived from normalization of mass_elc and n0). + double B0 = + vAe; // Reference magnetic field strength (derived from normalization of mass_elc and n0). double vAi = vAe / sqrt(mass_ion); // Ion Alfven velocity. double omega_ci = charge_ion * B0 / mass_ion; // Ion cyclotron frequency. @@ -133,7 +132,7 @@ create_ctx(void) double larmor_elc = vte / omega_ce; // Electron Larmor radius. double l = larmor_ion; // Current sheet width. - + double nb = n0 * nb_over_n0; // Background number density. double Te_frac = Te / (Te + Ti); // Fraction of total temperature from electrons. double Ti_frac = 1.0 - Te_frac; // Fraction of total temperature from ions. @@ -159,7 +158,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. struct lhdi_ctx ctx = { .pi = pi, @@ -207,14 +207,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct lhdi_ctx *app = ctx; @@ -228,11 +227,11 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double noise_amp = app->noise_amp; double mode = app->mode; - + double Te = app->Te; double B0 = app->B0; - + double l = app->l; double Te_frac = app->Te_frac; @@ -245,15 +244,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double sech_sq = (1.0 / cosh(y / l)) * (1.0 / cosh(y / l)); // Hyperbolic secant squared. double n = n0 * sech_sq; // Total number density. - double Jx_noise = -noise_amp * (iy * pi / Ly) * sin(iy * pi * y / Ly) * sin(ix * 2.0 * pi* x / Lx) / mode; // Current density noise (x-direction). - double Jy_noise = -noise_amp * (ix * 2.0 * pi / Lx) * cos(iy * pi * y / Ly) * cos(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (y-direction). + double Jx_noise = -noise_amp * (iy * pi / Ly) * sin(iy * pi * y / Ly) * + sin(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (x-direction). + double Jy_noise = -noise_amp * (ix * 2.0 * pi / Lx) * cos(iy * pi * y / Ly) * + cos(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (y-direction). double Jx = (B0 / l) * (-sech_sq) + Jx_noise; // Total current density, with noise (x-direction). double Jy = Jy_noise; // Total current density, with noise (y-direction). double rhoe = n * mass_elc; // Electron mass density. - double mome_x = (mass_elc / charge_elc) * Jx * Te_frac; // Electron momentum density (x-direction). - double mome_y = (mass_elc / charge_elc) * Jy * Te_frac; // Electron momentum density (y-direction). + double mome_x = + (mass_elc / charge_elc) * Jx * Te_frac; // Electron momentum density (x-direction). + double mome_y = + (mass_elc / charge_elc) * Jy * Te_frac; // Electron momentum density (y-direction). double mome_z = 0.0; // Electron momentum density (z-direction). double pre = n * Te; // Electron pressure (scalar). @@ -267,14 +270,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre_xx; fout[5] = pre_xy; fout[6] = pre_xz; - fout[7] = pre_yy; fout[8] = pre_yz; fout[9] = pre_zz; + fout[4] = pre_xx; + fout[5] = pre_xy; + fout[6] = pre_xz; + fout[7] = pre_yy; + fout[8] = pre_yz; + fout[9] = pre_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct lhdi_ctx *app = ctx; @@ -288,11 +296,11 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double noise_amp = app->noise_amp; double mode = app->mode; - + double Ti = app->Ti; double B0 = app->B0; - + double l = app->l; double Ti_frac = app->Ti_frac; @@ -305,8 +313,10 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double sech_sq = (1.0 / cosh(y / l)) * (1.0 / cosh(y / l)); // Hyperbolic secant squared. double n = n0 * sech_sq; // Total number density. - double Jx_noise = -noise_amp * (iy * pi / Ly) * sin(iy * pi * y / Ly) * sin(ix * 2.0 * pi* x / Lx) / mode; // Current density noise (x-direction). - double Jy_noise = -noise_amp * (ix * 2.0 * pi / Lx) * cos(iy * pi * y / Ly) * cos(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (y-direction). + double Jx_noise = -noise_amp * (iy * pi / Ly) * sin(iy * pi * y / Ly) * + sin(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (x-direction). + double Jy_noise = -noise_amp * (ix * 2.0 * pi / Lx) * cos(iy * pi * y / Ly) * + cos(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (y-direction). double Jx = (B0 / l) * (-sech_sq) + Jx_noise; // Total current density, with noise (x-direction). double Jy = Jy_noise; // Total current density, with noise (y-direction). @@ -327,14 +337,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion pressure tensor. - fout[4] = pri_xx; fout[5] = pri_xy; fout[6] = pri_xz; - fout[7] = pri_yy; fout[8] = pri_yz; fout[9] = pri_zz; + fout[4] = pri_xx; + fout[5] = pri_xy; + fout[6] = pri_xz; + fout[7] = pri_yy; + fout[8] = pri_yz; + fout[9] = pri_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct lhdi_ctx *app = ctx; @@ -350,12 +365,12 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double ix = app->ix; double iy = app->iy; - + double Lx = app->Lx; double Ly = app->Ly; double Bz_noise = noise_amp * cos(iy * pi * y / Ly) * sin(ix * 2.0 * pi * x / Lx) / mode; - + double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). @@ -365,15 +380,19 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = -B0 * tanh(y / l) + Bz_noise; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -387,24 +406,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -422,9 +442,9 @@ main(int argc, char **argv) struct lhdi_ctx ctx = create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); + int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -434,8 +454,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -449,49 +468,55 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); } } - + // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_elc, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_ion, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_elc, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_ion, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, .ctx = &ctx, - - .bcy = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + + .bcy = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -502,7 +527,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -510,8 +535,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -525,22 +549,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -564,24 +578,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly}, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly}, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -595,10 +606,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -607,26 +622,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -642,7 +662,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -657,8 +677,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -666,7 +685,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -674,8 +695,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -709,7 +729,7 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_10m_lhdi_grad_closure.c b/moments/creg/rt_10m_lhdi_grad_closure.c index 8a920b934f..4804ef6a3a 100644 --- a/moments/creg/rt_10m_lhdi_grad_closure.c +++ b/moments/creg/rt_10m_lhdi_grad_closure.c @@ -25,8 +25,7 @@ #include #include -struct lhdi_grad_closure_ctx -{ +struct lhdi_grad_closure_ctx { // Mathematical constants (dimensionless). double pi; @@ -64,7 +63,7 @@ struct lhdi_grad_closure_ctx double larmor_elc; // Electron Larmor radius. double l; // Current sheet width. - + double nb; // Background number density. double Te_frac; // Fraction of total temperature from electrons. double Ti_frac; // Fraction of total temperature from ions. @@ -90,11 +89,10 @@ struct lhdi_grad_closure_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct lhdi_grad_closure_ctx -create_ctx(void) +struct lhdi_grad_closure_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -123,7 +121,8 @@ create_ctx(void) double vti = sqrt(2.0 * Ti / mass_ion); // Ion thermal velocity. double vAe = vte / sqrt(beta); // Electron Alfven velocity. - double B0 = vAe; // Reference magnetic field strength (derived from normalization of mass_elc and n0). + double B0 = + vAe; // Reference magnetic field strength (derived from normalization of mass_elc and n0). double vAi = vAe / sqrt(mass_ion); // Ion Alfven velocity. double omega_ci = charge_ion * B0 / mass_ion; // Ion cyclotron frequency. @@ -133,7 +132,7 @@ create_ctx(void) double larmor_elc = vte / omega_ce; // Electron Larmor radius. double l = larmor_ion; // Current sheet width. - + double nb = n0 * nb_over_n0; // Background number density. double Te_frac = Te / (Te + Ti); // Fraction of total temperature from electrons. double Ti_frac = 1.0 - Te_frac; // Fraction of total temperature from ions. @@ -159,7 +158,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. struct lhdi_grad_closure_ctx ctx = { .pi = pi, @@ -207,14 +207,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct lhdi_grad_closure_ctx *app = ctx; @@ -228,11 +227,11 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double noise_amp = app->noise_amp; double mode = app->mode; - + double Te = app->Te; double B0 = app->B0; - + double l = app->l; double Te_frac = app->Te_frac; @@ -245,15 +244,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double sech_sq = (1.0 / cosh(y / l)) * (1.0 / cosh(y / l)); // Hyperbolic secant squared. double n = n0 * sech_sq; // Total number density. - double Jx_noise = -noise_amp * (iy * pi / Ly) * sin(iy * pi * y / Ly) * sin(ix * 2.0 * pi* x / Lx) / mode; // Current density noise (x-direction). - double Jy_noise = -noise_amp * (ix * 2.0 * pi / Lx) * cos(iy * pi * y / Ly) * cos(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (y-direction). + double Jx_noise = -noise_amp * (iy * pi / Ly) * sin(iy * pi * y / Ly) * + sin(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (x-direction). + double Jy_noise = -noise_amp * (ix * 2.0 * pi / Lx) * cos(iy * pi * y / Ly) * + cos(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (y-direction). double Jx = (B0 / l) * (-sech_sq) + Jx_noise; // Total current density, with noise (x-direction). double Jy = Jy_noise; // Total current density, with noise (y-direction). double rhoe = n * mass_elc; // Electron mass density. - double mome_x = (mass_elc / charge_elc) * Jx * Te_frac; // Electron momentum density (x-direction). - double mome_y = (mass_elc / charge_elc) * Jy * Te_frac; // Electron momentum density (y-direction). + double mome_x = + (mass_elc / charge_elc) * Jx * Te_frac; // Electron momentum density (x-direction). + double mome_y = + (mass_elc / charge_elc) * Jy * Te_frac; // Electron momentum density (y-direction). double mome_z = 0.0; // Electron momentum density (z-direction). double pre = n * Te; // Electron pressure (scalar). @@ -267,14 +270,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre_xx; fout[5] = pre_xy; fout[6] = pre_xz; - fout[7] = pre_yy; fout[8] = pre_yz; fout[9] = pre_zz; + fout[4] = pre_xx; + fout[5] = pre_xy; + fout[6] = pre_xz; + fout[7] = pre_yy; + fout[8] = pre_yz; + fout[9] = pre_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct lhdi_grad_closure_ctx *app = ctx; @@ -288,11 +296,11 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double noise_amp = app->noise_amp; double mode = app->mode; - + double Ti = app->Ti; double B0 = app->B0; - + double l = app->l; double Ti_frac = app->Ti_frac; @@ -305,8 +313,10 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double sech_sq = (1.0 / cosh(y / l)) * (1.0 / cosh(y / l)); // Hyperbolic secant squared. double n = n0 * sech_sq; // Total number density. - double Jx_noise = -noise_amp * (iy * pi / Ly) * sin(iy * pi * y / Ly) * sin(ix * 2.0 * pi* x / Lx) / mode; // Current density noise (x-direction). - double Jy_noise = -noise_amp * (ix * 2.0 * pi / Lx) * cos(iy * pi * y / Ly) * cos(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (y-direction). + double Jx_noise = -noise_amp * (iy * pi / Ly) * sin(iy * pi * y / Ly) * + sin(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (x-direction). + double Jy_noise = -noise_amp * (ix * 2.0 * pi / Lx) * cos(iy * pi * y / Ly) * + cos(ix * 2.0 * pi * x / Lx) / mode; // Current density noise (y-direction). double Jx = (B0 / l) * (-sech_sq) + Jx_noise; // Total current density, with noise (x-direction). double Jy = Jy_noise; // Total current density, with noise (y-direction). @@ -327,14 +337,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion pressure tensor. - fout[4] = pri_xx; fout[5] = pri_xy; fout[6] = pri_xz; - fout[7] = pri_yy; fout[8] = pri_yz; fout[9] = pri_zz; + fout[4] = pri_xx; + fout[5] = pri_xy; + fout[6] = pri_xz; + fout[7] = pri_yy; + fout[8] = pri_yz; + fout[9] = pri_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct lhdi_grad_closure_ctx *app = ctx; @@ -350,12 +365,12 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double ix = app->ix; double iy = app->iy; - + double Lx = app->Lx; double Ly = app->Ly; double Bz_noise = noise_amp * cos(iy * pi * y / Ly) * sin(ix * 2.0 * pi * x / Lx) / mode; - + double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). @@ -365,15 +380,19 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = -B0 * tanh(y / l) + Bz_noise; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -387,24 +406,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -422,9 +442,9 @@ main(int argc, char **argv) struct lhdi_grad_closure_ctx ctx = create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); + int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -434,8 +454,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -449,49 +468,55 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); } } - + // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_elc, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_ion, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_elc, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_ion, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, .ctx = &ctx, - - .bcy = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + + .bcy = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -502,7 +527,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -510,8 +535,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -525,25 +549,15 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .sync_corners = true, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .sync_corners = true}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); #endif int my_rank; @@ -567,24 +581,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly}, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly}, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -598,10 +609,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -610,26 +625,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -645,7 +665,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -660,8 +680,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -669,7 +688,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -677,8 +698,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -712,7 +732,7 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_10m_neut_sodshock.c b/moments/creg/rt_10m_neut_sodshock.c index 9e04516515..83b4fe8c25 100644 --- a/moments/creg/rt_10m_neut_sodshock.c +++ b/moments/creg/rt_10m_neut_sodshock.c @@ -26,8 +26,7 @@ #include #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double rhol; // Left fluid mass density. double ul; // Left fluid velocity. @@ -53,11 +52,10 @@ struct sodshock_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double rhol = 1.0; // Left fluid mass density. @@ -71,7 +69,8 @@ create_ctx(void) // Simulation parameters. int Nx = 128; // Cell count (x-direction; matches the PKPM training resolution). double Lx = 1.0; // Domain size (x-direction). - double k0 = 10.0; // Integrating-factor relaxation rate (k0 = nu/vth), matching the PKPM collision frequency nu = 10. + double k0 = + 10.0; // Integrating-factor relaxation rate (k0 = nu/vth), matching the PKPM collision frequency nu = 10. double cfl_frac = 0.9; // CFL coefficient. double t_end = 0.1; // Final simulation time. @@ -84,7 +83,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = true; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "rt_pkpm_neut_sodshock_p1_moms_nn_1"; // File path of neural network to use (trained by rt_pkpm_neut_sodshock_p1). + const char *nn_closure_file = + "rt_pkpm_neut_sodshock_p1_moms_nn_1"; // File path of neural network to use (trained by rt_pkpm_neut_sodshock_p1). struct sodshock_ctx ctx = { .rhol = rhol, @@ -105,14 +105,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval10mInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct sodshock_ctx *app = ctx; @@ -133,8 +132,7 @@ eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -154,14 +152,19 @@ eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -175,24 +178,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -211,7 +215,7 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 1); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 1); if (ctx.use_nn_closure) { const char *fmt_10m = "%s-%s.dat"; int sz_10m = gkyl_calc_strlen(fmt_10m, ctx.nn_closure_file, "neut"); @@ -221,8 +225,7 @@ main(int argc, char **argv) if (file_10m != NULL) { ann[0] = gkyl_kann_net_load(fileNm_10m, app_args.use_gpu); fclose(file_10m); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for 10m species not found! Disabling NN-based closure.\n"); @@ -230,16 +233,18 @@ main(int argc, char **argv) } // Fluid equations. - struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); + struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "neut", .equation = ten_moment, - + .init = eval10mInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -250,7 +255,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -258,8 +263,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -273,22 +277,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -312,20 +306,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -339,10 +329,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -351,26 +345,29 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames, .tcurr = t_curr, .curr = frame_curr}; write_data(&io_trig, app, t_curr, false); @@ -386,7 +383,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -401,8 +398,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -410,7 +406,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -418,8 +416,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -452,13 +449,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_ot.c b/moments/creg/rt_10m_ot.c index f2226d323e..faab931456 100644 --- a/moments/creg/rt_10m_ot.c +++ b/moments/creg/rt_10m_ot.c @@ -19,8 +19,7 @@ #include #include -struct ot_ctx -{ +struct ot_ctx { // Mathematical constants (dimensionless). double pi; @@ -67,11 +66,10 @@ struct ot_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct ot_ctx -create_ctx(void) +struct ot_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -119,7 +117,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. struct ot_ctx ctx = { .pi = pi, @@ -154,14 +153,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -180,7 +178,9 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Lx = app->Lx; double Ly = app->Ly; - double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / mu0; + double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / + mu0; double vx_drift = -delta_u0 * sin(2.0 * pi * y / Ly); // Electron drift velocity (x-direction). double vy_drift = delta_u0 * sin(2.0 * pi * x / Lx); // Electron drift velocity (y-direction). @@ -202,14 +202,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre_xx; fout[5] = pre_xy; fout[6] = pre_xz; - fout[7] = pre_yy; fout[8] = pre_yz; fout[9] = pre_zz; + fout[4] = pre_xx; + fout[5] = pre_xy; + fout[6] = pre_xz; + fout[7] = pre_yy; + fout[8] = pre_yz; + fout[9] = pre_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -245,14 +250,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion pressure tensor. - fout[4] = pri_xx; fout[5] = pri_xy; fout[6] = pri_xz; - fout[7] = pri_yy; fout[8] = pri_yz; fout[9] = pri_zz; + fout[4] = pri_xx; + fout[5] = pri_xy; + fout[6] = pri_xz; + fout[7] = pri_yy; + fout[8] = pri_yz; + fout[9] = pri_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -269,7 +279,9 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Lx = app->Lx; double Ly = app->Ly; - double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / mu0; + double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / + mu0; double Bx = -delta_B0 * sin(2.0 * pi * y / Ly); // Total magnetic field (x-direction). double By = delta_B0 * sin(4.0 * pi * x / Lx); // Total magnetic field (y-direction). @@ -282,17 +294,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = -((vy_drift * Bz) - (vz_drift * By)); // Total electric field (x-direction). double Ey = -((vz_drift * Bx) - (vx_drift * Bz)); // Total electric field (y-direction). double Ez = -((vx_drift * By) - (vy_drift * Bx)); // Total electric field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -306,24 +321,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -332,18 +348,18 @@ main(int argc, char **argv) MPI_Init(&argc, &argv); } #endif - + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } struct ot_ctx ctx = create_ctx(); // Context for initialization functions. - + int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -353,8 +369,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -368,43 +383,49 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); } } - + // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; - + struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. #ifdef GKYL_HAVE_MPI @@ -414,7 +435,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -422,8 +443,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -437,22 +457,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -476,24 +486,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -507,10 +514,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -519,26 +530,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -554,7 +570,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -569,8 +585,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -578,7 +593,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -586,8 +603,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -621,13 +637,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } \ No newline at end of file diff --git a/moments/creg/rt_10m_ot_grad_closure.c b/moments/creg/rt_10m_ot_grad_closure.c index 89c9674498..22efa423ed 100644 --- a/moments/creg/rt_10m_ot_grad_closure.c +++ b/moments/creg/rt_10m_ot_grad_closure.c @@ -19,8 +19,7 @@ #include #include -struct ot_grad_closure_ctx -{ +struct ot_grad_closure_ctx { // Mathematical constants (dimensionless). double pi; @@ -67,11 +66,10 @@ struct ot_grad_closure_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct ot_grad_closure_ctx -create_ctx(void) +struct ot_grad_closure_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -119,7 +117,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. struct ot_grad_closure_ctx ctx = { .pi = pi, @@ -154,14 +153,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_grad_closure_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -180,7 +178,9 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Lx = app->Lx; double Ly = app->Ly; - double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / mu0; + double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / + mu0; double vx_drift = -delta_u0 * sin(2.0 * pi * y / Ly); // Electron drift velocity (x-direction). double vy_drift = delta_u0 * sin(2.0 * pi * x / Lx); // Electron drift velocity (y-direction). @@ -202,14 +202,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre_xx; fout[5] = pre_xy; fout[6] = pre_xz; - fout[7] = pre_yy; fout[8] = pre_yz; fout[9] = pre_zz; + fout[4] = pre_xx; + fout[5] = pre_xy; + fout[6] = pre_xz; + fout[7] = pre_yy; + fout[8] = pre_yz; + fout[9] = pre_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_grad_closure_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -245,14 +250,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion pressure tensor. - fout[4] = pri_xx; fout[5] = pri_xy; fout[6] = pri_xz; - fout[7] = pri_yy; fout[8] = pri_yz; fout[9] = pri_zz; + fout[4] = pri_xx; + fout[5] = pri_xy; + fout[6] = pri_xz; + fout[7] = pri_yy; + fout[8] = pri_yz; + fout[9] = pri_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_grad_closure_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -269,7 +279,9 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Lx = app->Lx; double Ly = app->Ly; - double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / mu0; + double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / + mu0; double Bx = -delta_B0 * sin(2.0 * pi * y / Ly); // Total magnetic field (x-direction). double By = delta_B0 * sin(4.0 * pi * x / Lx); // Total magnetic field (y-direction). @@ -282,17 +294,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = -((vy_drift * Bz) - (vz_drift * By)); // Total electric field (x-direction). double Ey = -((vz_drift * Bx) - (vx_drift * Bz)); // Total electric field (y-direction). double Ez = -((vx_drift * By) - (vy_drift * Bx)); // Total electric field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -306,24 +321,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -332,18 +348,18 @@ main(int argc, char **argv) MPI_Init(&argc, &argv); } #endif - + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } struct ot_grad_closure_ctx ctx = create_ctx(); // Context for initialization functions. - + int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -353,8 +369,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -368,43 +383,49 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); } } - + // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; - + struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. #ifdef GKYL_HAVE_MPI @@ -414,7 +435,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -422,8 +443,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -437,25 +457,15 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .sync_corners = true, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .sync_corners = true}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); #endif int my_rank; @@ -479,24 +489,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -510,10 +517,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -522,26 +533,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -557,7 +573,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -572,8 +588,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -581,7 +596,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -589,8 +606,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -624,13 +640,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } \ No newline at end of file diff --git a/moments/creg/rt_10m_ot_nn_closure.c b/moments/creg/rt_10m_ot_nn_closure.c index 0b8e6aa091..1aa81dca93 100644 --- a/moments/creg/rt_10m_ot_nn_closure.c +++ b/moments/creg/rt_10m_ot_nn_closure.c @@ -19,8 +19,7 @@ #include #include -struct ot_nn_closure_ctx -{ +struct ot_nn_closure_ctx { // Mathematical constants (dimensionless). double pi; @@ -67,11 +66,10 @@ struct ot_nn_closure_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct ot_nn_closure_ctx -create_ctx(void) +struct ot_nn_closure_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -119,7 +117,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = true; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_ot_p1_moms_nn_1"; // File path of neural network to use. struct ot_nn_closure_ctx ctx = { .pi = pi, @@ -154,14 +153,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_nn_closure_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -180,7 +178,9 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Lx = app->Lx; double Ly = app->Ly; - double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / mu0; + double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / + mu0; double vx_drift = -delta_u0 * sin(2.0 * pi * y / Ly); // Electron drift velocity (x-direction). double vy_drift = delta_u0 * sin(2.0 * pi * x / Lx); // Electron drift velocity (y-direction). @@ -202,14 +202,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre_xx; fout[5] = pre_xy; fout[6] = pre_xz; - fout[7] = pre_yy; fout[8] = pre_yz; fout[9] = pre_zz; + fout[4] = pre_xx; + fout[5] = pre_xy; + fout[6] = pre_xz; + fout[7] = pre_yy; + fout[8] = pre_yz; + fout[9] = pre_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_nn_closure_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -245,14 +250,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion pressure tensor. - fout[4] = pri_xx; fout[5] = pri_xy; fout[6] = pri_xz; - fout[7] = pri_yy; fout[8] = pri_yz; fout[9] = pri_zz; + fout[4] = pri_xx; + fout[5] = pri_xy; + fout[6] = pri_xz; + fout[7] = pri_yy; + fout[8] = pri_yz; + fout[9] = pri_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_nn_closure_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -269,7 +279,9 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Lx = app->Lx; double Ly = app->Ly; - double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / mu0; + double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / + mu0; double Bx = -delta_B0 * sin(2.0 * pi * y / Ly); // Total magnetic field (x-direction). double By = delta_B0 * sin(4.0 * pi * x / Lx); // Total magnetic field (y-direction). @@ -282,17 +294,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = -((vy_drift * Bz) - (vz_drift * By)); // Total electric field (x-direction). double Ey = -((vz_drift * Bx) - (vx_drift * Bz)); // Total electric field (y-direction). double Ez = -((vx_drift * By) - (vy_drift * Bx)); // Total electric field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -306,24 +321,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -332,18 +348,18 @@ main(int argc, char **argv) MPI_Init(&argc, &argv); } #endif - + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } struct ot_nn_closure_ctx ctx = create_ctx(); // Context for initialization functions. - + int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -353,8 +369,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -368,43 +383,49 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); } } - + // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; - + struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. #ifdef GKYL_HAVE_MPI @@ -414,7 +435,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -422,8 +443,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -437,25 +457,15 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .sync_corners = true, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .sync_corners = true}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu, - .sync_corners = true, - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.use_gpu = app_args.use_gpu, .sync_corners = true}); #endif int my_rank; @@ -479,24 +489,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -510,10 +517,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -522,26 +533,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -557,7 +573,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -572,8 +588,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -581,7 +596,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -589,8 +606,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -624,13 +640,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } \ No newline at end of file diff --git a/moments/creg/rt_10m_par_firehose.c b/moments/creg/rt_10m_par_firehose.c index 354173c708..62f7be1ea6 100644 --- a/moments/creg/rt_10m_par_firehose.c +++ b/moments/creg/rt_10m_par_firehose.c @@ -25,8 +25,7 @@ #include #include -struct par_firehose_ctx -{ +struct par_firehose_ctx { // Mathematical constants (dimensionless). double pi; @@ -51,7 +50,7 @@ struct par_firehose_ctx double vte; // Electron thermal velocity. double Te; // Electron temperature. - + double Ti_par; // Parallel ion temperature. double Ti_perp; // Perpendicular ion temperature. @@ -83,11 +82,10 @@ struct par_firehose_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct par_firehose_ctx -create_ctx(void) +struct par_firehose_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -113,14 +111,16 @@ create_ctx(void) double vte = vAe * sqrt(beta); // Electron thermal velocity. double Te = vte * vte * mass_elc / 2.0; // Electron temperature. - + double Ti_par = vAe * vAe * (beta_par * mass_elc / 2.0); // Parallel ion temperature. double Ti_perp = vAe * vAe * (beta_perp * mass_elc / 2.0); // Perpendicular ion temperature. double omega_ci = charge_ion * B0 / mass_ion; // Ion cyclotron frequency. - double omega_pe = sqrt(n0 * charge_elc * charge_elc / (epsilon0 * mass_elc)); // Electron plasma frequency. + double omega_pe = + sqrt(n0 * charge_elc * charge_elc / (epsilon0 * mass_elc)); // Electron plasma frequency. double de = light_speed / omega_pe; // Electron skin depth. - double omega_pi = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_ion)); // Ion plasma frequency. + double omega_pi = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_ion)); // Ion plasma frequency. double di = light_speed / omega_pi; // Ion skin depth. double lambdaD = vte / omega_pe; // Electron Debye length. @@ -145,8 +145,9 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. - + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. + struct par_firehose_ctx ctx = { .pi = pi, .epsilon0 = epsilon0, @@ -189,14 +190,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct par_firehose_ctx *app = ctx; @@ -222,14 +222,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre_xx; fout[5] = pre_xy; fout[6] = pre_xz; - fout[7] = pre_yy; fout[8] = pre_yz; fout[9] = pre_zz; + fout[4] = pre_xx; + fout[5] = pre_xy; + fout[6] = pre_xz; + fout[7] = pre_yy; + fout[8] = pre_yz; + fout[9] = pre_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct par_firehose_ctx *app = ctx; @@ -256,14 +261,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion pressure tensor. - fout[4] = pri_xx; fout[5] = pri_xy; fout[6] = pri_xz; - fout[7] = pri_yy; fout[8] = pri_yz; fout[9] = pri_zz; + fout[4] = pri_xx; + fout[5] = pri_xy; + fout[6] = pri_xz; + fout[7] = pri_yy; + fout[8] = pri_yz; + fout[9] = pri_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct par_firehose_ctx *app = ctx; @@ -291,22 +301,31 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo pcg64_random_t rng = gkyl_pcg64_init(0); // Random number generator. - for (int i = mode_init; i < mode_final; i++) - { - By -= alpha * gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); // Total magnetic field (y-direction). - Bz -= alpha * gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); // Total magnetic field (z-direction). + for (int i = mode_init; i < mode_final; i++) { + By -= alpha * gkyl_pcg64_rand_double(&rng) * + sin( + i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng) + ); // Total magnetic field (y-direction). + Bz -= alpha * gkyl_pcg64_rand_double(&rng) * + sin( + i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng) + ); // Total magnetic field (z-direction). } // Set electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -320,24 +339,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -355,8 +375,8 @@ main(int argc, char **argv) struct par_firehose_ctx ctx = create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -366,8 +386,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -381,8 +400,7 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); @@ -390,34 +408,41 @@ main(int argc, char **argv) } // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_elc, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_ion, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_elc, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_ion, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; - + struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -428,7 +453,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -436,8 +461,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -451,22 +475,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -490,24 +504,20 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, - .field = field, + .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -521,10 +531,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -533,26 +547,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -568,7 +587,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -583,8 +602,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -592,7 +610,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -600,8 +620,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -635,13 +654,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_par_firehose_grad_closure.c b/moments/creg/rt_10m_par_firehose_grad_closure.c index 95adb6b9b4..b8dda44d90 100644 --- a/moments/creg/rt_10m_par_firehose_grad_closure.c +++ b/moments/creg/rt_10m_par_firehose_grad_closure.c @@ -25,8 +25,7 @@ #include #include -struct par_firehose_grad_closure_ctx -{ +struct par_firehose_grad_closure_ctx { // Mathematical constants (dimensionless). double pi; @@ -51,7 +50,7 @@ struct par_firehose_grad_closure_ctx double vte; // Electron thermal velocity. double Te; // Electron temperature. - + double Ti_par; // Parallel ion temperature. double Ti_perp; // Perpendicular ion temperature. @@ -83,11 +82,10 @@ struct par_firehose_grad_closure_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct par_firehose_grad_closure_ctx -create_ctx(void) +struct par_firehose_grad_closure_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -113,14 +111,16 @@ create_ctx(void) double vte = vAe * sqrt(beta); // Electron thermal velocity. double Te = vte * vte * mass_elc / 2.0; // Electron temperature. - + double Ti_par = vAe * vAe * (beta_par * mass_elc / 2.0); // Parallel ion temperature. double Ti_perp = vAe * vAe * (beta_perp * mass_elc / 2.0); // Perpendicular ion temperature. double omega_ci = charge_ion * B0 / mass_ion; // Ion cyclotron frequency. - double omega_pe = sqrt(n0 * charge_elc * charge_elc / (epsilon0 * mass_elc)); // Electron plasma frequency. + double omega_pe = + sqrt(n0 * charge_elc * charge_elc / (epsilon0 * mass_elc)); // Electron plasma frequency. double de = light_speed / omega_pe; // Electron skin depth. - double omega_pi = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_ion)); // Ion plasma frequency. + double omega_pi = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_ion)); // Ion plasma frequency. double di = light_speed / omega_pi; // Ion skin depth. double lambdaD = vte / omega_pe; // Electron Debye length. @@ -145,8 +145,9 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. - + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. + struct par_firehose_grad_closure_ctx ctx = { .pi = pi, .epsilon0 = epsilon0, @@ -189,14 +190,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct par_firehose_grad_closure_ctx *app = ctx; @@ -222,14 +222,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron pressure tensor. - fout[4] = pre_xx; fout[5] = pre_xy; fout[6] = pre_xz; - fout[7] = pre_yy; fout[8] = pre_yz; fout[9] = pre_zz; + fout[4] = pre_xx; + fout[5] = pre_xy; + fout[6] = pre_xz; + fout[7] = pre_yy; + fout[8] = pre_yz; + fout[9] = pre_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct par_firehose_grad_closure_ctx *app = ctx; @@ -256,14 +261,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion pressure tensor. - fout[4] = pri_xx; fout[5] = pri_xy; fout[6] = pri_xz; - fout[7] = pri_yy; fout[8] = pri_yz; fout[9] = pri_zz; + fout[4] = pri_xx; + fout[5] = pri_xy; + fout[6] = pri_xz; + fout[7] = pri_yy; + fout[8] = pri_yz; + fout[9] = pri_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct par_firehose_grad_closure_ctx *app = ctx; @@ -291,22 +301,31 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo pcg64_random_t rng = gkyl_pcg64_init(0); // Random number generator. - for (int i = mode_init; i < mode_final; i++) - { - By -= alpha * gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); // Total magnetic field (y-direction). - Bz -= alpha * gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); // Total magnetic field (z-direction). + for (int i = mode_init; i < mode_final; i++) { + By -= alpha * gkyl_pcg64_rand_double(&rng) * + sin( + i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng) + ); // Total magnetic field (y-direction). + Bz -= alpha * gkyl_pcg64_rand_double(&rng) * + sin( + i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng) + ); // Total magnetic field (z-direction). } // Set electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -320,24 +339,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -355,8 +375,8 @@ main(int argc, char **argv) struct par_firehose_grad_closure_ctx ctx = create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -366,8 +386,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -381,8 +400,7 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); @@ -390,34 +408,41 @@ main(int argc, char **argv) } // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_elc, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0_ion, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_elc, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0_ion, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -428,7 +453,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -436,8 +461,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -451,22 +475,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -490,24 +504,20 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, - .field = field, + .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -521,10 +531,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -533,26 +547,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -568,7 +587,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -583,8 +602,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -592,7 +610,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -600,8 +620,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -635,13 +654,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_riem.c b/moments/creg/rt_10m_riem.c index 4dbeb105fd..8a94304df4 100644 --- a/moments/creg/rt_10m_riem.c +++ b/moments/creg/rt_10m_riem.c @@ -25,8 +25,7 @@ #include #include -struct riem_ctx -{ +struct riem_ctx { // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -67,11 +66,10 @@ struct riem_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct riem_ctx -create_ctx(void) +struct riem_ctx create_ctx(void) { // Physical constants (using normalized code units). double epsilon0 = 1.0; // Permittivity of free space. @@ -113,8 +111,9 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. - + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. + struct riem_ctx ctx = { .epsilon0 = epsilon0, .mu0 = mu0, @@ -145,14 +144,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_ctx *app = ctx; @@ -169,8 +167,7 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_elc; // Electron mass density (left). p = pl; // Electron pressure (left). - } - else { + } else { rho = rhor_elc; // Electron mass density (right). p = pr; // Electron pressure (right). } @@ -189,14 +186,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho; // Set electron momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set electron pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_ctx *app = ctx; @@ -213,8 +215,7 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_ion; // Ion mass density (left). p = pl; // Ion pressure (left). - } - else { + } else { rho = rhor_ion; // Ion mass density (right). p = pr; // Ion pressure (right). } @@ -233,14 +234,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rho; // Set ion momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set ion pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_ctx *app = ctx; @@ -251,28 +257,29 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - + double Bx = app->Bx; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; if (x < 0.5) { Bz = Bzl; // Total magnetic field (z-direction, left). - } - else { + } else { Bz = Bzr; // Total magnetic field (z-direction, right). } // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -286,24 +293,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -322,7 +330,7 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -332,8 +340,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -347,8 +354,7 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); @@ -356,33 +362,40 @@ main(int argc, char **argv) } // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -393,7 +406,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -401,8 +414,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -416,22 +428,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -455,28 +457,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .has_collision = ctx.has_collision, - .nu_base = { - { 0.0, ctx.nu_base_ei }, - { ctx.nu_base_ei, 0.0 } - }, + .nu_base = {{0.0, ctx.nu_base_ei}, {ctx.nu_base_ei, 0.0}}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -490,10 +485,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -502,26 +501,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -537,7 +541,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -552,8 +556,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -561,7 +564,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -569,8 +574,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -604,13 +608,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_riem_grad_closure.c b/moments/creg/rt_10m_riem_grad_closure.c index 3d249d4446..5d7f4a14eb 100644 --- a/moments/creg/rt_10m_riem_grad_closure.c +++ b/moments/creg/rt_10m_riem_grad_closure.c @@ -23,8 +23,7 @@ #include -struct riem_grad_closure_ctx -{ +struct riem_grad_closure_ctx { // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -65,11 +64,10 @@ struct riem_grad_closure_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct riem_grad_closure_ctx -create_ctx(void) +struct riem_grad_closure_ctx create_ctx(void) { // Physical constants (using normalized code units). double epsilon0 = 1.0; // Permittivity of free space. @@ -111,8 +109,9 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. - + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. + struct riem_grad_closure_ctx ctx = { .epsilon0 = epsilon0, .mu0 = mu0, @@ -143,14 +142,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_grad_closure_ctx *app = ctx; @@ -167,8 +165,7 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_elc; // Electron mass density (left). p = pl; // Electron pressure (left). - } - else { + } else { rho = rhor_elc; // Electron mass density (right). p = pr; // Electron pressure (right). } @@ -187,14 +184,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho; // Set electron momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set electron pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_grad_closure_ctx *app = ctx; @@ -211,8 +213,7 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_ion; // Ion mass density (left). p = pl; // Ion pressure (left). - } - else { + } else { rho = rhor_ion; // Ion mass density (right). p = pr; // Ion pressure (right). } @@ -231,14 +232,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rho; // Set ion momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set ion pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_grad_closure_ctx *app = ctx; @@ -249,28 +255,29 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - + double Bx = app->Bx; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; if (x < 0.5) { Bz = Bzl; // Total magnetic field (z-direction, left). - } - else { + } else { Bz = Bzr; // Total magnetic field (z-direction, right). } // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -284,24 +291,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -320,7 +328,7 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -330,8 +338,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -345,8 +352,7 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); @@ -354,33 +360,40 @@ main(int argc, char **argv) } // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, true, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -391,7 +404,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -399,8 +412,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -414,22 +426,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -453,28 +455,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .has_collision = ctx.has_collision, - .nu_base = { - { 0.0, ctx.nu_base_ei }, - { ctx.nu_base_ei, 0.0 } - }, + .nu_base = {{0.0, ctx.nu_base_ei}, {ctx.nu_base_ei, 0.0}}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -488,10 +483,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -500,26 +499,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -535,7 +539,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -550,8 +554,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -559,7 +562,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -567,8 +572,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -600,15 +604,15 @@ main(int argc, char **argv) gkyl_wv_eqn_release(elc_ten_moment); gkyl_wv_eqn_release(ion_ten_moment); gkyl_comm_release(comm); - gkyl_moment_app_release(app); + gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_riem_nn_closure_p1.c b/moments/creg/rt_10m_riem_nn_closure_p1.c index 30700b3f86..b5a16b87b2 100644 --- a/moments/creg/rt_10m_riem_nn_closure_p1.c +++ b/moments/creg/rt_10m_riem_nn_closure_p1.c @@ -25,8 +25,7 @@ #include #include -struct riem_nn_closure_ctx -{ +struct riem_nn_closure_ctx { // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -67,11 +66,10 @@ struct riem_nn_closure_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct riem_nn_closure_ctx -create_ctx(void) +struct riem_nn_closure_ctx create_ctx(void) { // Physical constants (using normalized code units). double epsilon0 = 1.0; // Permittivity of free space. @@ -113,8 +111,9 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = true; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "rt_pkpm_neut_sodshock_p1_moms_nn_1"; // File path of neural network to use (trained by the pkpm neut_sodshock_p1 run). - + const char *nn_closure_file = + "rt_pkpm_neut_sodshock_p1_moms_nn_1"; // File path of neural network to use (trained by the pkpm neut_sodshock_p1 run). + struct riem_nn_closure_ctx ctx = { .epsilon0 = epsilon0, .mu0 = mu0, @@ -145,14 +144,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_nn_closure_ctx *app = ctx; @@ -169,8 +167,7 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_elc; // Electron mass density (left). p = pl; // Electron pressure (left). - } - else { + } else { rho = rhor_elc; // Electron mass density (right). p = pr; // Electron pressure (right). } @@ -189,14 +186,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho; // Set electron momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set electron pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_nn_closure_ctx *app = ctx; @@ -213,8 +215,7 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_ion; // Ion mass density (left). p = pl; // Ion pressure (left). - } - else { + } else { rho = rhor_ion; // Ion mass density (right). p = pr; // Ion pressure (right). } @@ -233,14 +234,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rho; // Set ion momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set ion pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_nn_closure_ctx *app = ctx; @@ -251,28 +257,29 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - + double Bx = app->Bx; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; if (x < 0.5) { Bz = Bzl; // Total magnetic field (z-direction, left). - } - else { + } else { Bz = Bzr; // Total magnetic field (z-direction, right). } // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -286,24 +293,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -322,7 +330,7 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -332,8 +340,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -347,8 +354,7 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); @@ -356,33 +362,40 @@ main(int argc, char **argv) } // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -393,7 +406,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -401,8 +414,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -416,22 +428,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -455,28 +457,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .has_collision = ctx.has_collision, - .nu_base = { - { 0.0, ctx.nu_base_ei }, - { ctx.nu_base_ei, 0.0 } - }, + .nu_base = {{0.0, ctx.nu_base_ei}, {ctx.nu_base_ei, 0.0}}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -490,10 +485,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -502,26 +501,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -537,7 +541,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -552,8 +556,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -561,7 +564,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -569,8 +574,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -604,13 +608,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_riem_nn_closure_p2.c b/moments/creg/rt_10m_riem_nn_closure_p2.c index bad17cc59e..3f8a1a878e 100644 --- a/moments/creg/rt_10m_riem_nn_closure_p2.c +++ b/moments/creg/rt_10m_riem_nn_closure_p2.c @@ -25,8 +25,7 @@ #include #include -struct riem_nn_closure_ctx -{ +struct riem_nn_closure_ctx { // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -67,11 +66,10 @@ struct riem_nn_closure_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct riem_nn_closure_ctx -create_ctx(void) +struct riem_nn_closure_ctx create_ctx(void) { // Physical constants (using normalized code units). double epsilon0 = 1.0; // Permittivity of free space. @@ -113,8 +111,9 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = true; // Use neural network-based closure? int poly_order = 2; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_periodic_es_shock_p2_moms_nn_1"; // File path of neural network to use. - + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_periodic_es_shock_p2_moms_nn_1"; // File path of neural network to use. + struct riem_nn_closure_ctx ctx = { .epsilon0 = epsilon0, .mu0 = mu0, @@ -145,14 +144,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_nn_closure_ctx *app = ctx; @@ -169,8 +167,7 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_elc; // Electron mass density (left). p = pl; // Electron pressure (left). - } - else { + } else { rho = rhor_elc; // Electron mass density (right). p = pr; // Electron pressure (right). } @@ -189,14 +186,19 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho; // Set electron momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set electron pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_nn_closure_ctx *app = ctx; @@ -213,8 +215,7 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_ion; // Ion mass density (left). p = pl; // Ion pressure (left). - } - else { + } else { rho = rhor_ion; // Ion mass density (right). p = pr; // Ion pressure (right). } @@ -233,14 +234,19 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rho; // Set ion momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set ion pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_nn_closure_ctx *app = ctx; @@ -251,28 +257,29 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - + double Bx = app->Bx; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; if (x < 0.5) { Bz = Bzl; // Total magnetic field (z-direction, left). - } - else { + } else { Bz = Bzr; // Total magnetic field (z-direction, right). } // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -286,24 +293,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -322,7 +330,7 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 2); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 2); if (ctx.use_nn_closure) { const char *fmt_elc = "%s-%s.dat"; int sz_elc = gkyl_calc_strlen(fmt_elc, ctx.nn_closure_file, "elc"); @@ -332,8 +340,7 @@ main(int argc, char **argv) if (file_elc != NULL) { ann[0] = gkyl_kann_net_load(fileNm_elc, app_args.use_gpu); fclose(file_elc); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for elc species not found! Disabling NN-based closure.\n"); @@ -347,8 +354,7 @@ main(int argc, char **argv) if (file_ion != NULL) { ann[1] = gkyl_kann_net_load(fileNm_ion, app_args.use_gpu); fclose(file_ion); - } - else { + } else { ann[1] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for ion species not found! Disabling NN-based closure.\n"); @@ -356,33 +362,40 @@ main(int argc, char **argv) } // Electron/ion equations. - struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); - struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu); + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[1], app_args.use_gpu + ); struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_ten_moment, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_ten_moment, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -393,7 +406,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -401,8 +414,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -416,22 +428,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -455,28 +457,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .has_collision = ctx.has_collision, - .nu_base = { - { 0.0, ctx.nu_base_ei }, - { ctx.nu_base_ei, 0.0 } - }, + .nu_base = {{0.0, ctx.nu_base_ei}, {ctx.nu_base_ei, 0.0}}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -490,10 +485,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -502,26 +501,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -537,7 +541,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -552,8 +556,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -561,7 +564,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -569,8 +574,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -604,13 +608,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_sodshock.c b/moments/creg/rt_10m_sodshock.c index 2ab86c6c96..51e90ef3c8 100644 --- a/moments/creg/rt_10m_sodshock.c +++ b/moments/creg/rt_10m_sodshock.c @@ -25,8 +25,7 @@ #include #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double rhol; // Left fluid mass density. double ul; // Left fluid velocity. @@ -52,11 +51,10 @@ struct sodshock_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double rhol = 3.0; // Left fluid mass density. @@ -83,7 +81,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. struct sodshock_ctx ctx = { .rhol = rhol, @@ -104,14 +103,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval10mInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct sodshock_ctx *app = ctx; @@ -132,8 +130,7 @@ eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -153,14 +150,19 @@ eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -174,24 +176,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -210,7 +213,7 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 1); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 1); if (ctx.use_nn_closure) { const char *fmt_10m = "%s-%s.dat"; int sz_10m = gkyl_calc_strlen(fmt_10m, ctx.nn_closure_file, "10m"); @@ -220,8 +223,7 @@ main(int argc, char **argv) if (file_10m != NULL) { ann[0] = gkyl_kann_net_load(fileNm_10m, app_args.use_gpu); fclose(file_10m); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for 10m species not found! Disabling NN-based closure.\n"); @@ -229,16 +231,18 @@ main(int argc, char **argv) } // Fluid equations. - struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); + struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "10m", .equation = ten_moment, - + .init = eval10mInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -249,7 +253,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -257,8 +261,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -272,22 +275,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -311,20 +304,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.25 }, - .upper = { 0.25 + ctx.Lx }, - .cells = { NX }, + .lower = {0.25}, + .upper = {0.25 + ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -338,10 +327,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -350,26 +343,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -385,7 +383,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -400,8 +398,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -409,7 +406,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -417,8 +416,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -451,13 +449,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_10m_sodshock_lax.c b/moments/creg/rt_10m_sodshock_lax.c index 9ff4eab508..dae07ea1ae 100644 --- a/moments/creg/rt_10m_sodshock_lax.c +++ b/moments/creg/rt_10m_sodshock_lax.c @@ -25,8 +25,7 @@ #include #include -struct sodshock_lax_ctx -{ +struct sodshock_lax_ctx { // Physical constants (using normalized code units). double rhol; // Left fluid mass density. double ul; // Left fluid velocity. @@ -52,11 +51,10 @@ struct sodshock_lax_ctx // Neural network parameters. bool use_nn_closure; // Use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - const char* nn_closure_file; // File path of neural network to use. + const char *nn_closure_file; // File path of neural network to use. }; -struct sodshock_lax_ctx -create_ctx(void) +struct sodshock_lax_ctx create_ctx(void) { // Physical constants (using normalized code units). double rhol = 3.0; // Left fluid mass density. @@ -83,7 +81,8 @@ create_ctx(void) // Neural network parameters. bool use_nn_closure = false; // Use neural network-based closure? int poly_order = 1; // Polynomial order of learned DG coefficients. - const char* nn_closure_file = "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. + const char *nn_closure_file = + "moments/data/neural_nets/pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to use. struct sodshock_lax_ctx ctx = { .rhol = rhol, @@ -104,14 +103,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .use_nn_closure = use_nn_closure, .poly_order = poly_order, - .nn_closure_file = nn_closure_file, + .nn_closure_file = nn_closure_file }; return ctx; } -void -eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void eval10mInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct sodshock_lax_ctx *app = ctx; @@ -132,8 +130,7 @@ eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -153,14 +150,19 @@ eval10mInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid pressure tensor. - fout[4] = pr_xx; fout[5] = pr_xy; fout[6] = pr_xz; - fout[7] = pr_yy; fout[8] = pr_yz; fout[9] = pr_zz; + fout[4] = pr_xx; + fout[5] = pr_xy; + fout[6] = pr_xz; + fout[7] = pr_yy; + fout[8] = pr_yz; + fout[9] = pr_zz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -174,24 +176,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -210,7 +213,7 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * 1); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * 1); if (ctx.use_nn_closure) { const char *fmt_10m = "%s-%s.dat"; int sz_10m = gkyl_calc_strlen(fmt_10m, ctx.nn_closure_file, "10m"); @@ -220,8 +223,7 @@ main(int argc, char **argv) if (file_10m != NULL) { ann[0] = gkyl_kann_net_load(fileNm_10m, app_args.use_gpu); fclose(file_10m); - } - else { + } else { ann[0] = 0; ctx.use_nn_closure = false; fprintf(stderr, "Neural network for 10m species not found! Disabling NN-based closure.\n"); @@ -229,17 +231,19 @@ main(int argc, char **argv) } // Fluid equations. - struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new(ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu); + struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new( + ctx.k0, false, ctx.use_nn_closure, ctx.poly_order, ann[0], app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "10m", .equation = ten_moment, - + .init = eval10mInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -250,7 +254,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -258,8 +262,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -273,22 +276,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -312,20 +305,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.25 }, - .upper = { 0.25 + ctx.Lx }, - .cells = { NX }, + .lower = {0.25}, + .upper = {0.25 + ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -339,10 +328,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -351,26 +344,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -386,7 +384,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -401,8 +399,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -410,7 +407,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -418,8 +417,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -452,13 +450,13 @@ main(int argc, char **argv) gkyl_comm_release(comm); gkyl_moment_app_release(app); gkyl_free(ann); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_burch.c b/moments/creg/rt_5m_burch.c index 9893742d85..762f0abbe6 100644 --- a/moments/creg/rt_5m_burch.c +++ b/moments/creg/rt_5m_burch.c @@ -23,8 +23,7 @@ #include -struct burch_ctx -{ +struct burch_ctx { // Mathematical constants (dimensionless). double pi; @@ -77,8 +76,7 @@ struct burch_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct burch_ctx -create_ctx(void) +struct burch_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -94,13 +92,16 @@ create_ctx(void) double vAe = 0.2; // Electron Alfven velocity. double n0 = 1.0; // Reference number density. double beta2 = 2.748; // Magnetosheath plasma beta. - double Ti1_over_Ti2 = 7.73 / 1.374; // Magnetospheric ion temperature / magnetosheath ion temperature. - double Te1_over_Te2 = 1.288 / 1.374; // Magnetospheric electron temperature / magnetosheath ion temperature. + double Ti1_over_Ti2 = + 7.73 / 1.374; // Magnetospheric ion temperature / magnetosheath ion temperature. + double Te1_over_Te2 = + 1.288 / 1.374; // Magnetospheric electron temperature / magnetosheath ion temperature. // Derived physical quantities (using normalized code units). double light_speed = 1.0 / sqrt(mu0 * epsilon0); // Speed of light. double B0 = vAe * sqrt(n0 * mass_elc); // Reference magnetic field strength. - double omega_pi = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_ion)); // Ion plasma frequency. + double omega_pi = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_ion)); // Ion plasma frequency. double di = light_speed / omega_pi; // Ion skin depth. double omega0 = 1.0 * di; // Reference frequency. double psi0 = 0.1 * B0 * di; // Reference magnetic scalar potential. @@ -115,8 +116,9 @@ create_ctx(void) double Te1 = Ti2 * Te1_over_Te2; // Magnetospheric electron temperature. double Ti1 = Ti2 * Ti1_over_Ti2; // Magnetospheric ion temperature. - double Te2 = (0.5 * (b1 * b1 - b2 * b2) + 0.5 * (guide1 * guide1 - guide2 * guide2) - + n1 * (Ti1 + Te1) - n2 * Ti2) / n2; // Magnetosheath electron temperature (so that the system is in force balance). + double Te2 = (0.5 * (b1 * b1 - b2 * b2) + 0.5 * (guide1 * guide1 - guide2 * guide2) + + n1 * (Ti1 + Te1) - n2 * Ti2) / + n2; // Magnetosheath electron temperature (so that the system is in force balance). // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -131,7 +133,7 @@ create_ctx(void) int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct burch_ctx ctx = { .pi = pi, .gas_gamma = gas_gamma, @@ -172,14 +174,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct burch_ctx *app = ctx; @@ -207,37 +208,54 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Lx = app->Lx; double Ly = app->Ly; - double b1x = 0.5 * (b2 + b1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). + double b1x = 0.5 * (b2 + b1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). double b1y = 0.0; // Magnetospheric magnetic field (y-direction). - double b1z = 0.5 * (guide2 - guide1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). - - double Ti_tot = 0.5 * (Ti2 - Ti1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Ti2 + Ti1); // Total ion temperature. - double Te_tot = 0.5 * (Te2 - Te1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Te2 + Te1); // Total electron temperature. - double n = (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / (Ti_tot + Te_tot); // Total number density. - - double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). - double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). + double b1z = 0.5 * (guide2 - guide1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). + + double Ti_tot = 0.5 * (Ti2 - Ti1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Ti2 + Ti1); // Total ion temperature. + double Te_tot = 0.5 * (Te2 - Te1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Te2 + Te1); // Total electron temperature. + double n = + (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / + (Ti_tot + Te_tot); // Total number density. + + double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * + sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). + double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * + (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). double Bz = b1z; // Total magnetic field (z-direction). double Te_frac = Te_tot / (Te_tot + Ti_tot); // Fraction of total temperature from electrons. double Ti_frac = Ti_tot / (Te_tot + Ti_tot); // Fraction of total temperature from ions; - double Jx = 0.5 * (guide2 - guide1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))); // Total current density (x-direction). + double Jx = 0.5 * (guide2 - guide1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0)) + ); // Total current density (x-direction). double Jy = 0.0; // Total current density (y-direction). - double Jz = -0.5 * (b2 + b1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - - psi0 * sin(2.0 * pi * x / Lx) * ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) - + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly)); // Total current density (z-direction). - + double Jz = -0.5 * (b2 + b1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - + psi0 * sin(2.0 * pi * x / Lx) * + ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) + + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly) + ); // Total current density (z-direction). + double Jxe = Jx * Te_frac; // Electron current density (x-direction). double Jye = Jy * Te_frac; // Electron current density (y-direction). double Jze = Jz * Te_frac; // Electron current density (z-direction). @@ -246,18 +264,21 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double mome_x = (mass_elc / charge_elc) * Jxe; // Electron momentum density (x-direction). double mome_y = (mass_elc / charge_elc) * Jye; // Electron momentum density (y-direction). double mome_z = (mass_elc / charge_elc) * Jze; // Electron momentum density (z-direction). - double Ee_tot = n * Te_tot / (gas_gamma - 1.0) + 0.5 * ((mome_x * mome_x) + (mome_y * mome_y) + (mome_z * mome_z)) / rhoe; // Electron total energy density. + double Ee_tot = n * Te_tot / (gas_gamma - 1.0) + + 0.5 * ((mome_x * mome_x) + (mome_y * mome_y) + (mome_z * mome_z)) / + rhoe; // Electron total energy density. // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct burch_ctx *app = ctx; @@ -285,37 +306,54 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Lx = app->Lx; double Ly = app->Ly; - double b1x = 0.5 * (b2 + b1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). + double b1x = 0.5 * (b2 + b1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). double b1y = 0.0; // Magnetospheric magnetic field (y-direction). - double b1z = 0.5 * (guide2 - guide1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). - - double Ti_tot = 0.5 * (Ti2 - Ti1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Ti2 + Ti1); // Total ion temperature. - double Te_tot = 0.5 * (Te2 - Te1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Te2 + Te1); // Total electron temperature. - double n = (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / (Ti_tot + Te_tot); // Total number density. - - double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). - double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). + double b1z = 0.5 * (guide2 - guide1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). + + double Ti_tot = 0.5 * (Ti2 - Ti1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Ti2 + Ti1); // Total ion temperature. + double Te_tot = 0.5 * (Te2 - Te1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Te2 + Te1); // Total electron temperature. + double n = + (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / + (Ti_tot + Te_tot); // Total number density. + + double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * + sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). + double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * + (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). double Bz = b1z; // Total magnetic field (z-direction). double Te_frac = Te_tot / (Te_tot + Ti_tot); // Fraction of total temperature from electrons. double Ti_frac = Ti_tot / (Te_tot + Ti_tot); // Fraction of total temperature from ions; - double Jx = 0.5 * (guide2 - guide1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))); // Total current density (x-direction). + double Jx = 0.5 * (guide2 - guide1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0)) + ); // Total current density (x-direction). double Jy = 0.0; // Total current density (y-direction). - double Jz = -0.5 * (b2 + b1) / omega0 * ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - - (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) - + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - - (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - - psi0 * sin(2.0 * pi * x / Lx) * ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) - + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly)); // Total current density (z-direction). - + double Jz = -0.5 * (b2 + b1) / omega0 * + ((1.0 / cosh((y - Ly * 0.25) / omega0)) * (1.0 / cosh((y - Ly * 0.25) / omega0)) - + (1.0 / cosh((y - Ly * 0.75) / omega0)) * (1.0 / cosh((y - Ly * 0.75) / omega0)) + + (1.0 / cosh((y - Ly * 1.25) / omega0)) * (1.0 / cosh((y - Ly * 1.25) / omega0)) - + (1.0 / cosh((y + Ly * 0.25) / omega0)) * (1.0 / cosh((y + Ly * 0.25) / omega0))) - + psi0 * sin(2.0 * pi * x / Lx) * + ((2.0 * pi / Lx) * (2.0 * pi / Lx) * (1.0 - cos(4.0 * pi * y / Ly)) + + (4.0 * pi / Ly) * (4.0 * pi / Ly) * cos(4.0 * pi * y / Ly) + ); // Total current density (z-direction). + double Jxi = Jx * Ti_frac; // Ion current density (x-direction). double Jyi = Jy * Ti_frac; // Ion current density (y-direction). double Jzi = Jz * Ti_frac; // Ion current density (z-direction). @@ -324,18 +362,21 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double momi_x = (mass_ion / charge_ion) * Jxi; // Ion momentum density (x-direction). double momi_y = (mass_ion / charge_ion) * Jyi; // Ion momentum density (y-direction). double momi_z = (mass_ion / charge_ion) * Jzi; // Ion momentum density (z-direction). - double Ei_tot = n * Ti_tot / (gas_gamma - 1.0) + 0.5 * ((momi_x * momi_x) + (momi_y * momi_y) + (momi_z * momi_z)) / rhoi; // Ion total energy density. + double Ei_tot = n * Ti_tot / (gas_gamma - 1.0) + + 0.5 * ((momi_x * momi_x) + (momi_y * momi_y) + (momi_z * momi_z)) / + rhoi; // Ion total energy density. // Set ion mass density, fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion total energy density. fout[4] = Ei_tot; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct burch_ctx *app = ctx; @@ -359,36 +400,50 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Lx = app->Lx; double Ly = app->Ly; - double b1x = 0.5 * (b2 + b1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). + double b1x = 0.5 * (b2 + b1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (b2 - b1); // Magnetospheric magnetic field (x-direction). double b1y = 0.0; // Magnetospheric magnetic field (y-direction). - double b1z = 0.5 * (guide2 - guide1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). - - double Ti_tot = 0.5 * (Ti2 - Ti1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Ti2 + Ti1); // Total ion temperature. - double Te_tot = 0.5 * (Te2 - Te1) * (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) - + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + 0.5 * (Te2 + Te1); // Total electron temperature. - double n = (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / (Ti_tot + Te_tot); // Total number density. + double b1z = 0.5 * (guide2 - guide1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (guide2 + guide1); // Magnetospheric magnetic field (z-direction). + + double Ti_tot = 0.5 * (Ti2 - Ti1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Ti2 + Ti1); // Total ion temperature. + double Te_tot = 0.5 * (Te2 - Te1) * + (tanh((y - Ly * 0.25) / omega0) - tanh((y - Ly * 0.75) / omega0) + + tanh((y - Ly * 1.25) / omega0) - tanh((y + Ly * 0.25) / omega0) + 1.0) + + 0.5 * (Te2 + Te1); // Total electron temperature. + double n = + (0.5 * (b1 * b1 - b1x * b1x) + 0.5 * (guide1 * guide1 - b1z * b1z) + n1 * (Ti1 + Te1)) / + (Ti_tot + Te_tot); // Total number density. double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). - double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). + double Bx = b1x - psi0 * 4.0 * pi / Ly * sin(2.0 * pi * x / Lx) * + sin(4.0 * pi * y / Ly); // Total magnetic field (x-direction). + double By = b1y + psi0 * 2.0 * pi / Lx * cos(2.0 * pi * x / Lx) * + (1.0 - cos(4.0 * pi * y / Ly)); // Total magnetic field (y-direction). double Bz = b1z; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -402,24 +457,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -445,29 +501,32 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_euler, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -477,7 +536,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -485,8 +544,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -500,22 +558,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -539,24 +587,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx / ctx.di, ctx.Ly / ctx.di }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx / ctx.di, ctx.Ly / ctx.di}, + .cells = {NX, NY}, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -570,10 +615,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -582,26 +631,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -617,7 +671,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -632,8 +686,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -641,7 +694,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -649,8 +704,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -678,13 +732,13 @@ main(int argc, char **argv) gkyl_wv_eqn_release(ion_euler); gkyl_comm_release(comm); gkyl_moment_app_release(app); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_elc_heat_flux.c b/moments/creg/rt_5m_elc_heat_flux.c index c3830447d9..8a289490f8 100644 --- a/moments/creg/rt_5m_elc_heat_flux.c +++ b/moments/creg/rt_5m_elc_heat_flux.c @@ -17,8 +17,7 @@ #include -struct elc_heat_flux_ctx -{ +struct elc_heat_flux_ctx { // Mathematical constants (dimensionless). double pi; @@ -60,8 +59,7 @@ struct elc_heat_flux_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct elc_heat_flux_ctx -create_ctx(void) +struct elc_heat_flux_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -87,11 +85,14 @@ create_ctx(void) double rho_ion = n0 * mass_ion; // Ion mass density. double E_ion = n0 * T_low / (gas_gamma - 1.0); // Ion total energy density. - double E_elc_lower = n0 * T_high / (gas_gamma - 1.0); // Electron lower boundary total energy density. - double E_elc_upper = n0 * T_low / (gas_gamma - 1.0); // Electron upper boundary total energy density. - - double tau = 6.0 * sqrt(2.0 * pi * mass_elc * T_low * pi * T_low * pi * T_low) * epsilon0 * epsilon0 / - (charge_ion * charge_ion * charge_ion * charge_ion * n0); // Collision time. + double E_elc_lower = + n0 * T_high / (gas_gamma - 1.0); // Electron lower boundary total energy density. + double E_elc_upper = + n0 * T_low / (gas_gamma - 1.0); // Electron upper boundary total energy density. + + double tau = 6.0 * sqrt(2.0 * pi * mass_elc * T_low * pi * T_low * pi * T_low) * epsilon0 * + epsilon0 / + (charge_ion * charge_ion * charge_ion * charge_ion * n0); // Collision time. double lambda = vte * tau; // Collision wavelength. // Simulation parameters. @@ -131,14 +132,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct elc_heat_flux_ctx *app = ctx; @@ -159,13 +159,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho_elc; // Set electron momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set electron total energy density. fout[4] = E_elc; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct elc_heat_flux_ctx *app = ctx; @@ -175,24 +176,30 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rho_ion; // Set ion momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set ion total energy density. fout[4] = E_ion; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = 0.0, fout[4] = 0.0; fout[5] = 0.0; + fout[3] = 0.0, fout[4] = 0.0; + fout[5] = 0.0; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalElcLowerBC(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +void evalElcLowerBC( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { struct elc_heat_flux_ctx *app = ctx; @@ -202,13 +209,17 @@ evalElcLowerBC(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* sk // Set electron lower boundary mass density. ghost[0] = rho_elc; // Set electron lower boundary momentum density. - ghost[1] = 0.0; ghost[2] = 0.0; ghost[3] = 0.0; + ghost[1] = 0.0; + ghost[2] = 0.0; + ghost[3] = 0.0; // Set electron lower boundary total energy density. ghost[4] = E_elc_lower; } -void -evalElcUpperBC(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +void evalElcUpperBC( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { struct elc_heat_flux_ctx *app = ctx; @@ -218,13 +229,14 @@ evalElcUpperBC(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* sk // Set electron upper boundary mass density. ghost[0] = rho_elc; // Set electron upper boundary momentum density. - ghost[1] = 0.0; ghost[2] = 0.0; ghost[3] = 0.0; + ghost[1] = 0.0; + ghost[2] = 0.0; + ghost[3] = 0.0; // Set electron upper boundary total energy density. ghost[4] = E_elc_upper; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -236,8 +248,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -262,37 +273,40 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, - + .init = evalElcInit, .ctx = &ctx, .type_brag = GKYL_BRAG_UNMAG_FULL, - .bcx = { GKYL_SPECIES_FUNC, GKYL_SPECIES_FUNC }, - .bcx_func = { evalElcLowerBC, evalElcUpperBC}, + .bcx = {GKYL_SPECIES_FUNC, GKYL_SPECIES_FUNC}, + .bcx_func = {evalElcLowerBC, evalElcUpperBC} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_euler, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - }; + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} + }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .is_static = false, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -303,7 +317,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); struct gkyl_range global_r; gkyl_create_global_range(dim, cells, &global_r); @@ -314,8 +328,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -331,25 +344,15 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = decomp, - .use_gpu = app_args.use_gpu - } - ); + comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.decomp = decomp, .use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = decomp, - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.decomp = decomp, .use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -373,27 +376,23 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .cfl_frac = ctx.cfl_frac, .has_braginskii = true, .coll_fac = ctx.coll_fac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -406,7 +405,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_app_apply_ic(app, t_curr); @@ -424,7 +423,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -437,8 +436,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -446,11 +444,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -475,14 +474,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(ion_euler); gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_em_advect.c b/moments/creg/rt_5m_em_advect.c index 92cb253f3a..0c522623f3 100644 --- a/moments/creg/rt_5m_em_advect.c +++ b/moments/creg/rt_5m_em_advect.c @@ -1,7 +1,7 @@ // Advection in specified electromagnetic fields for the 5-moment equations. // Input parameters match the initial conditions found in entry JE32 of Ammar's Simulation Journal (https://ammar-hakim.org/sj/je/je32/je32-vlasov-test-ptcl.html) -// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. -// Solution is given by the non-resonant case, omega = 0.5*Omega_c where Omega_c = q B/m is the cyclotron frequency. +// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. +// Solution is given by the non-resonant case, omega = 0.5*Omega_c where Omega_c = q B/m is the cyclotron frequency. #include #include @@ -25,8 +25,7 @@ #include -struct em_advect_ctx -{ +struct em_advect_ctx { // Mathematical constants (dimensionless). double pi; @@ -56,8 +55,7 @@ struct em_advect_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct em_advect_ctx -create_ctx(void) +struct em_advect_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -77,13 +75,14 @@ create_ctx(void) // Simulation parameters. int Nx = 2; // Cell count (configuration space: x-direction). double Lx = 4.0 * pi; // Domain size (configuration space: x-direction). - double cfl_frac = 0.001; // CFL coefficient. Set to be small to compare with analytic result. + double cfl_frac = 0.001; // CFL coefficient. Set to be small to compare with analytic result. double t_end = 100.0; // Final simulation time. int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -95,7 +94,7 @@ create_ctx(void) .mass_elc = mass_elc, .charge_elc = charge_elc, .vt = vt, - .n0 = n0, + .n0 = n0, .B0 = B0, .omega = omega, .Nx = Nx, @@ -107,14 +106,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_ctx *app = ctx; @@ -122,25 +120,25 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double n0 = app->n0; double mass_elc = app->mass_elc; double vt = app->vt; - double T = vt*vt*mass_elc; + double T = vt * vt * mass_elc; - double rho_elc = n0*mass_elc; // Total electron mass density. + double rho_elc = n0 * mass_elc; // Total electron mass density. double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). - double E_elc = n0 * T / (gas_gamma - 1.0); // Total electron energy density. - + double E_elc = n0 * T / (gas_gamma - 1.0); // Total electron energy density. // Set electron mass density. fout[0] = rho_elc; // Set electron momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set electron total energy density. fout[4] = E_elc; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -149,17 +147,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct em_advect_ctx *app = ctx; @@ -175,13 +178,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -193,8 +199,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -218,18 +223,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -237,39 +241,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -294,50 +284,48 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - .is_static = true, + .is_static = true, .init = evalFieldInit, .ctx = &ctx, .ext_em = evalExternalFieldInit, - .ext_em_ctx = &ctx, - .ext_em_evolve = true, + .ext_em_ctx = &ctx, + .ext_em_evolve = true }; // Moment app. struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -350,7 +338,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_app_apply_ic(app, t_curr); @@ -368,7 +356,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -381,8 +369,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -390,11 +377,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -417,14 +405,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(elc_euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_em_advect_resonant.c b/moments/creg/rt_5m_em_advect_resonant.c index fdc6faca8e..1a684d682f 100644 --- a/moments/creg/rt_5m_em_advect_resonant.c +++ b/moments/creg/rt_5m_em_advect_resonant.c @@ -1,7 +1,7 @@ // Advection in specified electromagnetic fields for the 5-moment equations. // Input parameters match the initial conditions found in entry JE32 of Ammar's Simulation Journal (https://ammar-hakim.org/sj/je/je32/je32-vlasov-test-ptcl.html) -// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. -// Solution is given by the resonant case, omega = Omega_c where Omega_c = q B/m is the cyclotron frequency. +// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. +// Solution is given by the resonant case, omega = Omega_c where Omega_c = q B/m is the cyclotron frequency. #include #include @@ -25,8 +25,7 @@ #include -struct em_advect_resonant_ctx -{ +struct em_advect_resonant_ctx { // Mathematical constants (dimensionless). double pi; @@ -56,8 +55,7 @@ struct em_advect_resonant_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct em_advect_resonant_ctx -create_ctx(void) +struct em_advect_resonant_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -77,13 +75,14 @@ create_ctx(void) // Simulation parameters. int Nx = 2; // Cell count (configuration space: x-direction). double Lx = 4.0 * pi; // Domain size (configuration space: x-direction). - double cfl_frac = 0.001; // CFL coefficient. Set to be small to compare with analytic result. + double cfl_frac = 0.001; // CFL coefficient. Set to be small to compare with analytic result. double t_end = 100.0; // Final simulation time. int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -95,7 +94,7 @@ create_ctx(void) .mass_elc = mass_elc, .charge_elc = charge_elc, .vt = vt, - .n0 = n0, + .n0 = n0, .B0 = B0, .omega = omega, .Nx = Nx, @@ -107,14 +106,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_resonant_ctx *app = ctx; @@ -122,25 +120,25 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double n0 = app->n0; double mass_elc = app->mass_elc; double vt = app->vt; - double T = vt*vt*mass_elc; + double T = vt * vt * mass_elc; - double rho_elc = n0*mass_elc; // Total electron mass density. + double rho_elc = n0 * mass_elc; // Total electron mass density. double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). - double E_elc = n0 * T / (gas_gamma - 1.0); // Total electron energy density. - + double E_elc = n0 * T / (gas_gamma - 1.0); // Total electron energy density. // Set electron mass density. fout[0] = rho_elc; // Set electron momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set electron total energy density. fout[4] = E_elc; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -149,17 +147,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct em_advect_resonant_ctx *app = ctx; @@ -175,13 +178,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -193,8 +199,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -218,18 +223,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -237,39 +241,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -294,50 +284,48 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - .is_static = true, + .is_static = true, .init = evalFieldInit, .ctx = &ctx, .ext_em = evalExternalFieldInit, - .ext_em_ctx = &ctx, - .ext_em_evolve = true, + .ext_em_ctx = &ctx, + .ext_em_evolve = true }; // Moment app. struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -350,7 +338,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_app_apply_ic(app, t_curr); @@ -368,7 +356,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -381,8 +369,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -390,11 +377,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -417,14 +405,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(elc_euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_expanding.c b/moments/creg/rt_5m_expanding.c index 0387942f66..de9338db9a 100644 --- a/moments/creg/rt_5m_expanding.c +++ b/moments/creg/rt_5m_expanding.c @@ -17,8 +17,7 @@ #include -struct expanding_ctx -{ +struct expanding_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double U0; // (Initial) comoving plasma velocity. @@ -41,8 +40,7 @@ struct expanding_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct expanding_ctx -create_ctx(void) +struct expanding_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -80,14 +78,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct expanding_ctx *app = ctx; @@ -106,13 +103,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = E_tot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -126,24 +124,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -168,7 +167,7 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, @@ -177,7 +176,7 @@ main(int argc, char **argv) .volume_U0 = ctx.U0, .volume_R0 = ctx.R0, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -187,7 +186,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -195,8 +194,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -210,22 +208,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -249,20 +237,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -276,10 +260,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -288,26 +276,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -323,7 +316,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -338,8 +331,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -347,7 +339,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -355,8 +349,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -382,14 +375,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_expanding_axi_sodshock.c b/moments/creg/rt_5m_expanding_axi_sodshock.c index 17f0111147..ca940bcf68 100644 --- a/moments/creg/rt_5m_expanding_axi_sodshock.c +++ b/moments/creg/rt_5m_expanding_axi_sodshock.c @@ -17,8 +17,7 @@ #include -struct expanding_axi_sodshock_ctx -{ +struct expanding_axi_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -52,8 +51,7 @@ struct expanding_axi_sodshock_ctx double rloc; // Fluid boundary (radial coordinate). }; -struct expanding_axi_sodshock_ctx -create_ctx(void) +struct expanding_axi_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -109,14 +107,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .rloc = rloc, + .rloc = rloc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { double r = zc[0]; struct expanding_axi_sodshock_ctx *app = ctx; @@ -141,13 +138,12 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left/inner). u = ul; // Fluid velocity (left/inner). p = pl; // Fluid pressure (left/inner). - } - else { + } else { rho = rhor; // Fluid mass density (right/outer). u = ur; // Fluid velocity (right/outer). p = pr; // Fluid pressure (right/outer). } - + double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). @@ -156,13 +152,15 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = E_tot; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double r = zc[0], theta = zc[1]; @@ -171,8 +169,7 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* xp[1] = r * sin(theta); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -186,24 +183,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -229,7 +227,7 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, @@ -238,7 +236,7 @@ main(int argc, char **argv) .volume_U0 = ctx.U0, .volume_R0 = ctx.R0, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -248,7 +246,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NR, NTHETA }; + int cells[] = {NR, NTHETA}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -256,8 +254,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -271,22 +268,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -310,25 +297,22 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.25, 0.0 }, - .upper = { 0.25 + ctx.Lr, ctx.Ltheta }, - .cells = { NR, NTHETA }, + .lower = {0.25, 0.0}, + .upper = {0.25 + ctx.Lr, ctx.Ltheta}, + .cells = {NR, NTHETA}, .mapc2p = mapc2p, .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .periodic_dirs = {1}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -342,10 +326,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -354,26 +342,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -389,7 +382,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -404,8 +397,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -413,7 +405,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -421,8 +415,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -448,14 +441,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_expanding_sodshock.c b/moments/creg/rt_5m_expanding_sodshock.c index 730cc0aa0d..02c05db9d3 100644 --- a/moments/creg/rt_5m_expanding_sodshock.c +++ b/moments/creg/rt_5m_expanding_sodshock.c @@ -17,8 +17,7 @@ #include -struct expanding_sodshock_ctx -{ +struct expanding_sodshock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double U0; // (Initial) comoving plasma velocity. @@ -45,8 +44,7 @@ struct expanding_sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct expanding_sodshock_ctx -create_ctx(void) +struct expanding_sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -91,14 +89,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct expanding_sodshock_ctx *app = ctx; @@ -121,8 +118,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -136,13 +132,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = E_tot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -156,24 +153,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -198,7 +196,7 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, @@ -207,7 +205,7 @@ main(int argc, char **argv) .volume_U0 = ctx.U0, .volume_R0 = ctx.R0, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -217,7 +215,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -225,8 +223,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -240,22 +237,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -279,20 +266,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.25 }, - .upper = { 0.25 + ctx.Lx }, - .cells = { NX }, + .lower = {0.25}, + .upper = {0.25 + ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -306,10 +289,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -318,26 +305,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -353,7 +345,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -368,8 +360,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -377,7 +368,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -385,8 +378,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -412,14 +404,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_friction.c b/moments/creg/rt_5m_friction.c index fa8120d5fd..a4d9c747d7 100644 --- a/moments/creg/rt_5m_friction.c +++ b/moments/creg/rt_5m_friction.c @@ -17,8 +17,7 @@ #include -struct friction_ctx -{ +struct friction_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double epsilon0; // Permittivity of free space. @@ -59,8 +58,7 @@ struct friction_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct friction_ctx -create_ctx(void) +struct friction_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -79,7 +77,8 @@ create_ctx(void) double friction_Z = 1.0; // Ionization number for frictional sources. double friction_T_elc = 1.0; // Electron temperature for frictional sources. - double friction_Lambda_ee = exp(1.0); // Electron-electron collisional term for frictional sources. + double friction_Lambda_ee = + exp(1.0); // Electron-electron collisional term for frictional sources. // Derived physical quantities (using normalized code units). double rho_elc = n_elc * mass_elc; // Electron mass density. @@ -88,8 +87,10 @@ create_ctx(void) double mom_elc = (n_elc * mass_elc) * u_elc; // Electron momentum (x-direction). double mom_ion = (n_ion * mass_ion) * u_ion; // Ion momenutm (x-direction). - double E_elc = ((n_elc * mass_elc) / (gas_gamma - 1.0)) + (0.5 * (n_elc * mass_elc) * (u_elc * u_elc)); // Electron total energy density. - double E_ion = ((n_ion * mass_ion) / (gas_gamma - 1.0)) + (0.5 * (n_ion * mass_ion) * (u_ion * u_ion)); // Ion total energy density. + double E_elc = ((n_elc * mass_elc) / (gas_gamma - 1.0)) + + (0.5 * (n_elc * mass_elc) * (u_elc * u_elc)); // Electron total energy density. + double E_ion = ((n_ion * mass_ion) / (gas_gamma - 1.0)) + + (0.5 * (n_ion * mass_ion) * (u_ion * u_ion)); // Ion total energy density. // Simulation parameters. int Nx = 128; // Cell count (x-direction). @@ -128,14 +129,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct friction_ctx *app = ctx; @@ -147,13 +147,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho_elc; // Set electron momentum density. - fout[1] = mom_elc; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = mom_elc; + fout[2] = 0.0; + fout[3] = 0.0; // Set electron total energy density. fout[4] = E_elc; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct friction_ctx *app = ctx; @@ -165,24 +166,27 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rho_ion; // Set ion momentum density. - fout[1] = mom_ion; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = mom_ion; + fout[2] = 0.0; + fout[3] = 0.0; // Set ion total energy density. fout[4] = E_ion; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = 0.0, fout[4] = 0.0; fout[5] = 0.0; + fout[3] = 0.0, fout[4] = 0.0; + fout[5] = 0.0; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -194,8 +198,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -220,9 +223,10 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, - + .init = evalElcInit, .ctx = &ctx, @@ -230,32 +234,34 @@ main(int argc, char **argv) .use_explicit_friction = true, .friction_Z = ctx.friction_Z, .friction_T_elc = ctx.friction_T_elc, - .friction_Lambda_ee = ctx.friction_Lambda_ee, + .friction_Lambda_ee = ctx.friction_Lambda_ee }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_euler, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx, .has_friction = true, .use_explicit_friction = true, .friction_Z = ctx.friction_Z, .friction_T_elc = ctx.friction_T_elc, - .friction_Lambda_ee = ctx.friction_Lambda_ee, + .friction_Lambda_ee = ctx.friction_Lambda_ee }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .is_static = true, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -265,7 +271,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -273,8 +279,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -288,22 +293,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -327,24 +322,20 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -357,7 +348,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_app_apply_ic(app, t_curr); @@ -375,7 +366,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -388,8 +379,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -397,11 +387,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -425,14 +416,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(elc_euler); gkyl_wv_eqn_release(ion_euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_gem.c b/moments/creg/rt_5m_gem.c index ad51c506ff..6ff3d3f27b 100644 --- a/moments/creg/rt_5m_gem.c +++ b/moments/creg/rt_5m_gem.c @@ -23,11 +23,10 @@ #include -struct gem_ctx -{ +struct gem_ctx { // Mathematical constants (dimensionless). double pi; - + // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double epsilon0; // Permittivity of free space. @@ -43,7 +42,7 @@ struct gem_ctx double B0; // Reference magnetic field strength. double Ti_over_Te; // Ion temperature / electron temperature. double beta; // Total plasma beta. - + // Derived physical quantities (using normalized code units). double lambda; // Current sheet width. double psi0; // Reference magnetic scalar potential. @@ -69,8 +68,7 @@ struct gem_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct gem_ctx -create_ctx(void) +struct gem_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -90,7 +88,7 @@ create_ctx(void) double B0 = 0.1; // Reference magnetic field strength. double Ti_over_Te = 5.0; // Ion temperature / electron temperature. double beta = 1.0; // Total plasma beta. - + // Derived physical quantities (using normalized code units). double lambda = 0.5 * di; // Current sheet width. double psi0 = 0.1 * B0 * di; // Reference magnetic scalar potential. @@ -146,14 +144,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_ctx *app = ctx; @@ -170,7 +167,8 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Te_frac = app->Te_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -178,19 +176,22 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double rhoe = n * mass_elc; // Electron mass density. double mome_x = 0.0; // Electron momentum density (x-direction). double mome_y = 0.0; // Electron momentum density (y-direction). - double mome_z = (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). - double Ee_tot = n * T_tot * Te_frac / (gas_gamma - 1.0) + 0.5 * mome_z * mome_z / rhoe; // Electron total energy density. + double mome_z = + (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). + double Ee_tot = n * T_tot * Te_frac / (gas_gamma - 1.0) + + 0.5 * mome_z * mome_z / rhoe; // Electron total energy density. // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_ctx *app = ctx; @@ -207,7 +208,8 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Ti_frac = app->Ti_frac; double T_tot = app->T_tot; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -216,18 +218,20 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double momi_x = 0.0; // Ion momentum density (x-direction). double momi_y = 0.0; // Ion momentum density (y-direction). double momi_z = (mass_ion / charge_ion) * Jz * Ti_frac; // Ion momentum density (z-direction). - double Ei_tot = n * T_tot * Ti_frac / (gas_gamma - 1.0) + 0.5 * momi_z * momi_z / rhoi; // Ion total energy density. + double Ei_tot = n * T_tot * Ti_frac / (gas_gamma - 1.0) + + 0.5 * momi_z * momi_z / rhoi; // Ion total energy density. // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion total energy density. fout[4] = Ei_tot; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_ctx *app = ctx; @@ -248,20 +252,24 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * sin(pi * y / Ly); // Total magnetic field (x-direction). - double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * cos(pi * y / Ly); // Total magnetic field (y-direction). + double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * + sin(pi * y / Ly); // Total magnetic field (x-direction). + double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * + cos(pi * y / Ly); // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -275,24 +283,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -318,35 +327,38 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, - + .init = evalElcInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_euler, - + .init = evalIonInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, .ctx = &ctx, - - .bcy = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + + .bcy = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -356,7 +368,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -364,8 +376,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -379,22 +390,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -418,24 +419,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -449,10 +447,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -461,26 +463,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -496,7 +503,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -511,8 +518,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -520,7 +526,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -528,8 +536,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -556,14 +563,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(elc_euler); gkyl_wv_eqn_release(ion_euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_hartmann.c b/moments/creg/rt_5m_hartmann.c index e457af977a..3dcaf3b882 100644 --- a/moments/creg/rt_5m_hartmann.c +++ b/moments/creg/rt_5m_hartmann.c @@ -17,8 +17,7 @@ #include -struct hartmann_ctx -{ +struct hartmann_ctx { // Mathematical constants (dimensionless). double pi; @@ -69,8 +68,7 @@ struct hartmann_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct hartmann_ctx -create_ctx(void) +struct hartmann_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -94,9 +92,10 @@ create_ctx(void) double light_speed = 1.0 / sqrt(epsilon0 * mu0); // Speed of light. double vAe = light_speed; // Electron Alfven velocity. double B0 = vAe * sqrt(mu0 * n0 * mass_elc); // Reference magnetic field strength. - double omega_pi = sqrt(charge_ion * charge_ion * n0 / (epsilon0 * mass_ion)); // Ion plasma frequency. + double omega_pi = + sqrt(charge_ion * charge_ion * n0 / (epsilon0 * mass_ion)); // Ion plasma frequency. double di = light_speed / omega_pi; // Ion skin depth. - + double T_elc = beta * (B0 * B0) / (2.0 * n0 * mu0); // Electron temperature. double T_ion = beta * (B0 * B0) / (2.0 * n0 * mu0); // Ion temperature. @@ -106,9 +105,11 @@ create_ctx(void) double E_elc = n0 * T_elc / (gas_gamma - 1.0); // Electron total energy density. double E_ion = n0 * T_ion / (gas_gamma - 1.0); // Ion total energy density. - double tau = coll_fac * 6.0 * sqrt(2.0 * pi * mass_elc * T_elc * pi * T_elc * pi * T_elc) * epsilon0 * epsilon0 / - (charge_ion * charge_ion * charge_ion * charge_ion * n0); // Collision time. - double lambda = 1.0 / mu0 * (mass_elc / (charge_ion * charge_ion * n0 * tau)); // Collision wavelength. + double tau = coll_fac * 6.0 * sqrt(2.0 * pi * mass_elc * T_elc * pi * T_elc * pi * T_elc) * + epsilon0 * epsilon0 / + (charge_ion * charge_ion * charge_ion * charge_ion * n0); // Collision time. + double lambda = + 1.0 / mu0 * (mass_elc / (charge_ion * charge_ion * n0 * tau)); // Collision wavelength. // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -156,14 +157,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hartmann_ctx *app = ctx; @@ -179,13 +179,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hartmann_ctx *app = ctx; @@ -201,13 +202,14 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion total energy density. fout[4] = Ei_tot; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hartmann_ctx *app = ctx; @@ -222,15 +224,17 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalAppAccel(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalAppAccel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hartmann_ctx *app = ctx; @@ -241,11 +245,12 @@ evalAppAccel(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double accel_z = 0.0; // Applied acceleration (z-direction). // Set applied acceleration. - fout[0] = accel_x; fout[1] = accel_y; fout[2] = accel_z; + fout[0] = accel_x; + fout[1] = accel_y; + fout[2] = accel_z; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -259,24 +264,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -301,9 +307,10 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, - + .init = evalElcInit, .ctx = &ctx, @@ -312,14 +319,15 @@ main(int argc, char **argv) .type_brag = GKYL_BRAG_MAG_FULL, - .bcx = { GKYL_SPECIES_NO_SLIP, GKYL_SPECIES_NO_SLIP }, + .bcx = {GKYL_SPECIES_NO_SLIP, GKYL_SPECIES_NO_SLIP} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_euler, - + .init = evalIonInit, .ctx = &ctx, @@ -328,18 +336,19 @@ main(int argc, char **argv) .type_brag = GKYL_BRAG_MAG_FULL, - .bcx = { GKYL_SPECIES_NO_SLIP, GKYL_SPECIES_NO_SLIP }, + .bcx = {GKYL_SPECIES_NO_SLIP, GKYL_SPECIES_NO_SLIP} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .is_static = true, .init = evalFieldInit, .ctx = &ctx, - .bcx = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + .bcx = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -349,7 +358,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -357,8 +366,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -372,22 +380,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -411,27 +409,23 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .cfl_frac = ctx.cfl_frac, .has_braginskii = true, .coll_fac = ctx.coll_fac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -445,10 +439,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -457,26 +455,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -492,7 +495,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -507,8 +510,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -516,7 +518,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -524,8 +528,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -552,14 +555,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(elc_euler); gkyl_wv_eqn_release(ion_euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } \ No newline at end of file diff --git a/moments/creg/rt_5m_ion_heat_flux.c b/moments/creg/rt_5m_ion_heat_flux.c index 50b3f6ed56..658188c0ef 100644 --- a/moments/creg/rt_5m_ion_heat_flux.c +++ b/moments/creg/rt_5m_ion_heat_flux.c @@ -17,8 +17,7 @@ #include -struct ion_heat_flux_ctx -{ +struct ion_heat_flux_ctx { // Mathematical constants (dimensionless). double pi; @@ -60,8 +59,7 @@ struct ion_heat_flux_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct ion_heat_flux_ctx -create_ctx(void) +struct ion_heat_flux_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -90,8 +88,9 @@ create_ctx(void) double E_ion_lower = n0 * T_high / (gas_gamma - 1.0); // Ion lower boundary total energy density. double E_ion_upper = n0 * T_low / (gas_gamma - 1.0); // Ion upper boundary total energy density. - double tau = 6.0 * sqrt(2.0 * pi * mass_ion * T_low * pi * T_low * pi * T_low) * epsilon0 * epsilon0 / - (charge_ion * charge_ion * charge_ion * charge_ion * n0); // Collision time. + double tau = 6.0 * sqrt(2.0 * pi * mass_ion * T_low * pi * T_low * pi * T_low) * epsilon0 * + epsilon0 / + (charge_ion * charge_ion * charge_ion * charge_ion * n0); // Collision time. double lambda = vti * tau; // Collision wavelength. // Simulation parameters. @@ -131,14 +130,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ion_heat_flux_ctx *app = ctx; @@ -148,13 +146,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho_elc; // Set electron momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set electron total energy density. fout[4] = E_elc; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct ion_heat_flux_ctx *app = ctx; @@ -175,24 +174,30 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rho_ion; // Set ion momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set ion total energy density. fout[4] = E_ion; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = 0.0, fout[4] = 0.0; fout[5] = 0.0; + fout[3] = 0.0, fout[4] = 0.0; + fout[5] = 0.0; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalIonLowerBC(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +void evalIonLowerBC( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { struct ion_heat_flux_ctx *app = ctx; @@ -202,13 +207,17 @@ evalIonLowerBC(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* sk // Set ion lower boundary mass density. ghost[0] = rho_ion; // Set ion lower boundary momentum density. - ghost[1] = 0.0; ghost[2] = 0.0; ghost[3] = 0.0; + ghost[1] = 0.0; + ghost[2] = 0.0; + ghost[3] = 0.0; // Set ion lower boundary total energy density. ghost[4] = E_ion_lower; } -void -evalIonUpperBC(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +void evalIonUpperBC( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { struct ion_heat_flux_ctx *app = ctx; @@ -218,13 +227,14 @@ evalIonUpperBC(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* sk // Set ion upper boundary mass density. ghost[0] = rho_ion; // Set ion upper boundary momentum density. - ghost[1] = 0.0; ghost[2] = 0.0; ghost[3] = 0.0; + ghost[1] = 0.0; + ghost[2] = 0.0; + ghost[3] = 0.0; // Set ion upper boundary total energy density. ghost[4] = E_ion_upper; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -236,8 +246,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -262,37 +271,40 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, - + .init = evalElcInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_euler, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx, .type_brag = GKYL_BRAG_UNMAG_FULL, - .bcx = { GKYL_SPECIES_FUNC, GKYL_SPECIES_FUNC }, - .bcx_func = { evalIonLowerBC, evalIonUpperBC}, - }; + .bcx = {GKYL_SPECIES_FUNC, GKYL_SPECIES_FUNC}, + .bcx_func = {evalIonLowerBC, evalIonUpperBC} + }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .is_static = true, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -303,7 +315,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); struct gkyl_range global_r; gkyl_create_global_range(dim, cells, &global_r); @@ -314,8 +326,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -331,25 +342,15 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = decomp, - .use_gpu = app_args.use_gpu - } - ); + comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.decomp = decomp, .use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = decomp, - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.decomp = decomp, .use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -373,27 +374,23 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .cfl_frac = ctx.cfl_frac, .has_braginskii = true, .coll_fac = ctx.coll_fac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -406,7 +403,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_app_apply_ic(app, t_curr); @@ -424,7 +421,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -437,8 +434,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -446,11 +442,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -475,14 +472,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(ion_euler); gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_mom_beach.c b/moments/creg/rt_5m_mom_beach.c index 290e74fa23..fe88dc9534 100644 --- a/moments/creg/rt_5m_mom_beach.c +++ b/moments/creg/rt_5m_mom_beach.c @@ -23,8 +23,7 @@ #include -struct mom_beach_ctx -{ +struct mom_beach_ctx { // Mathematical constants (dimensionless). double pi; @@ -36,7 +35,7 @@ struct mom_beach_ctx double charge_elc; // Electron charge. double J0; // Reference current density (Amps / m^3). - + // Derived physical quantities (using non-normalized physical units). double light_speed; // Speed of light. @@ -59,8 +58,7 @@ struct mom_beach_ctx double omega_drive; // Drive current angular frequency. }; -struct mom_beach_ctx -create_ctx(void) +struct mom_beach_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -73,7 +71,7 @@ create_ctx(void) double charge_elc = -1.602176487e-19; // Electron charge. double J0 = 1.0e-12; // Reference current density (Amps / m^3). - + // Derived physical quantities (using non-normalized physical units). double light_speed = 1.0 / sqrt(mu0 * epsilon0); // Speed of light. @@ -91,7 +89,9 @@ create_ctx(void) int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double deltaT = Lx100 / light_speed; // Arbitrary constant, with units of time. - double factor = deltaT * deltaT * charge_elc * charge_elc / (mass_elc * epsilon0); // Numerical factor for calculation of electron number density. + double factor = + deltaT * deltaT * charge_elc * charge_elc / + (mass_elc * epsilon0); // Numerical factor for calculation of electron number density. double omega_drive = pi / 10.0 / deltaT; // Drive current angular frequency. struct mom_beach_ctx ctx = { @@ -116,14 +116,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .deltaT = deltaT, .factor = factor, - .omega_drive = omega_drive, + .omega_drive = omega_drive }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct mom_beach_ctx *app = ctx; @@ -132,9 +131,10 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double mass_elc = app->mass_elc; double charge_elc = app->charge_elc; - double factor = app ->factor; + double factor = app->factor; - double omegaPdt = 25.0 * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x); // Plasma frequency profile. + double omegaPdt = + 25.0 * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x); // Plasma frequency profile. double ne = omegaPdt * omegaPdt / factor; // Electron number density. double rhoe = mass_elc * ne; // Electron mass density. @@ -146,13 +146,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -163,15 +164,17 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAppCurrent(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct mom_beach_ctx *app = ctx; @@ -186,17 +189,17 @@ evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (x > x_last_edge) { app_y = -J0 * sin(omega_drive * t); // Applied current (y-direction, right). - } - else { + } else { app_y = 0.0; // Applied current (y-direction, left). } - + // Set applied current. - fout[0] = app_x; fout[1] = app_y; fout[2] = app_z; + fout[0] = app_x; + fout[1] = app_y; + fout[2] = app_z; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -210,24 +213,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -251,26 +255,28 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, - + .init = evalElcInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .init = evalFieldInit, .ctx = &ctx, .app_current = evalAppCurrent, .app_current_ctx = &ctx, - .app_current_evolve = true, + .app_current_evolve = true, - .bcx = { GKYL_FIELD_COPY, GKYL_FIELD_COPY }, + .bcx = {GKYL_FIELD_COPY, GKYL_FIELD_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -280,7 +286,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -288,8 +294,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -303,22 +308,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -342,22 +337,18 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -371,10 +362,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -383,26 +378,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -418,7 +418,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -433,8 +433,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -442,7 +441,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -450,8 +451,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -485,6 +485,6 @@ main(int argc, char **argv) MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_riem.c b/moments/creg/rt_5m_riem.c index 0b196a6f40..64b028bdfe 100644 --- a/moments/creg/rt_5m_riem.c +++ b/moments/creg/rt_5m_riem.c @@ -23,8 +23,7 @@ #include -struct riem_ctx -{ +struct riem_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double epsilon0; // Permittivity of free space. @@ -63,8 +62,7 @@ struct riem_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct riem_ctx -create_ctx(void) +struct riem_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -102,7 +100,7 @@ create_ctx(void) int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct riem_ctx ctx = { .gas_gamma = gas_gamma, .epsilon0 = epsilon0, @@ -130,14 +128,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_ctx *app = ctx; @@ -156,8 +153,7 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_elc; // Electron mass density (left). p = pl; // Electron pressure (left). - } - else { + } else { rho = rhor_elc; // Electron mass density (right). p = pr; // Electron pressure (right). } @@ -171,13 +167,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_ctx *app = ctx; @@ -186,7 +183,7 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double rhol_ion = app->rhol_ion; double rhor_ion = app->rhor_ion; - + double pl = app->pl; double pr = app->pr; @@ -196,8 +193,7 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < 0.5) { rho = rhol_ion; // Ion mass density (left). p = pl; // Ion pressure (left). - } - else { + } else { rho = rhor_ion; // Ion mass density (right). p = pr; // Ion pressure (right). } @@ -211,13 +207,14 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; // Set ion total energy density. fout[4] = Ei_tot; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct riem_ctx *app = ctx; @@ -235,21 +232,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo if (x < 0.5) { Bz = Bzl; // Total magnetic field (z-direction, left). - } - else { + } else { Bz = Bzr; // Total magnetic field (z-direction, right). } // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -263,24 +261,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -305,34 +304,37 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, - + .init = evalElcInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_euler, - + .init = evalIonInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .init = evalFieldInit, .ctx = &ctx, - .bcx = { GKYL_FIELD_COPY, GKYL_FIELD_COPY }, + .bcx = {GKYL_FIELD_COPY, GKYL_FIELD_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -342,7 +344,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -350,8 +352,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -365,22 +366,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -404,28 +395,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .has_collision = ctx.has_collision, - .nu_base = { - { 0.0, ctx.nu_base_ei }, - { ctx.nu_base_ei, 0.0 } - }, + .nu_base = {{0.0, ctx.nu_base_ei}, {ctx.nu_base_ei, 0.0}}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -439,10 +423,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -451,26 +439,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -486,7 +479,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -501,8 +494,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -510,7 +502,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -518,8 +512,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -546,14 +539,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(elc_euler); gkyl_wv_eqn_release(ion_euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_5m_rt.c b/moments/creg/rt_5m_rt.c index 9db7650bb3..fb2caac69c 100644 --- a/moments/creg/rt_5m_rt.c +++ b/moments/creg/rt_5m_rt.c @@ -21,8 +21,7 @@ #include -struct rt_ctx -{ +struct rt_ctx { // Mathematical constants (dimensionless). double pi; @@ -66,8 +65,7 @@ struct rt_ctx double xloc; // Fluid boundary (x-coordinate). }; -struct rt_ctx -create_ctx(void) +struct rt_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -110,7 +108,7 @@ create_ctx(void) int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double xloc = 0.5 * Lx; // Fluid boundary (x-coordinate). - + struct rt_ctx ctx = { .pi = pi, .gas_gamma = gas_gamma, @@ -143,14 +141,13 @@ create_ctx(void) .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .xloc = xloc, + .xloc = xloc }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct rt_ctx *app = ctx; @@ -175,8 +172,7 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < xloc) { n = nl; // Electron number density (left). - } - else { + } else { n = nr; // Electron number density (right). } @@ -188,22 +184,27 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double ky = 2.0 * pi / Ly; // Wave number (y-direction). for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { - momxe += rhoe * pert_max * vAi * gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)) - * sin(j * ky * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); // Electron momentum density (x-direction). + momxe += rhoe * pert_max * vAi * gkyl_pcg64_rand_double(&rng) * + sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)) * + sin( + j * ky * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng) + ); // Electron momentum density (x-direction). } } - double Ee_tot = n * Te / (gas_gamma - 1.0) + 0.5 * momxe * momxe / rhoe; // Electron total energy density. + double Ee_tot = + n * Te / (gas_gamma - 1.0) + 0.5 * momxe * momxe / rhoe; // Electron total energy density. // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = momxe; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = momxe; + fout[2] = 0.0; + fout[3] = 0.0; // Set electron total energy density. fout[4] = Ee_tot; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct rt_ctx *app = ctx; @@ -228,8 +229,7 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout if (x < xloc) { n = nl; // Ion number density (left). - } - else { + } else { n = nr; // Ion number density (right). } @@ -241,22 +241,27 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double ky = 2.0 * pi / Ly; // Wave number (y-direction). for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { - momxi += rhoi * pert_max * vAi * gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)) - * sin(j * ky * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); // Ion momentum density (x-direction). + momxi += rhoi * pert_max * vAi * gkyl_pcg64_rand_double(&rng) * + sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)) * + sin( + j * ky * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng) + ); // Ion momentum density (x-direction). } } - double Ei_tot = n * Ti / (gas_gamma - 1.0) + 0.5 * momxi * momxi / rhoi; // Ion total energy density. + double Ei_tot = + n * Ti / (gas_gamma - 1.0) + 0.5 * momxi * momxi / rhoi; // Ion total energy density. // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momxi; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = momxi; + fout[2] = 0.0; + fout[3] = 0.0; // Set ion total energy density. fout[4] = Ei_tot; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct rt_ctx *app = ctx; @@ -275,33 +280,40 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; if (x < xloc) { - Bz = sqrt(B0 * B0 + 2 * mu0 * (mass_ion * grav * nl * x)); // Total magnetic field (z- direction, left). - } - else { - Bz = sqrt(B0 * B0 + 2 * mu0 * ((nl - nr) * T + mass_ion * grav * nl * xloc + mass_ion * grav * nr * (x - xloc))); // Total magnetic field (z-direction, left). + Bz = sqrt( + B0 * B0 + 2 * mu0 * (mass_ion * grav * nl * x) + ); // Total magnetic field (z- direction, left). + } else { + Bz = sqrt( + B0 * B0 + + 2 * mu0 * ((nl - nr) * T + mass_ion * grav * nl * xloc + mass_ion * grav * nr * (x - xloc)) + ); // Total magnetic field (z-direction, left). } // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = 0.0, fout[4] = 0.0; fout[5] = Bz; + fout[3] = 0.0, fout[4] = 0.0; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalAppAccel(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalAppAccel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rt_ctx *app = ctx; double grav = app->grav; // Gravitational acceleration. // Set applied acceleration. - fout[0] = grav; fout[1] = 0.0; fout[2] = 0.0; + fout[0] = grav; + fout[1] = 0.0; + fout[2] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -313,8 +325,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -340,41 +351,44 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, - + .init = evalElcInit, .ctx = &ctx, .app_accel = evalAppAccel, .app_accel_ctx = &ctx, - .bcx = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcx = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_euler, - + .init = evalIonInit, .ctx = &ctx, - + .app_accel = evalAppAccel, .app_accel_ctx = &ctx, - .bcx = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcx = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, .ctx = &ctx, - - .bcx = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + + .bcx = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -384,7 +398,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -392,8 +406,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -407,22 +420,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -446,24 +449,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .periodic_dirs = {1}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -476,7 +476,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_app_apply_ic(app, t_curr); @@ -494,7 +494,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -507,8 +507,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -516,11 +515,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -545,13 +545,13 @@ main(int argc, char **argv) gkyl_wv_eqn_release(ion_euler); gkyl_comm_release(comm); gkyl_moment_app_release(app); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_advect_wv.c b/moments/creg/rt_advect_wv.c index f5edae063a..a8b8925fce 100644 --- a/moments/creg/rt_advect_wv.c +++ b/moments/creg/rt_advect_wv.c @@ -23,8 +23,7 @@ #include -struct advect_wv_ctx -{ +struct advect_wv_ctx { // Simulation parameters. int Nx; // Cell count (x-direction). double Lx; // Domain size (x-direction). @@ -39,8 +38,7 @@ struct advect_wv_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct advect_wv_ctx -create_ctx(void) +struct advect_wv_ctx create_ctx(void) { // Simulation parameters. int Nx = 200; // Cell count (x-direction). @@ -65,29 +63,26 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; double f = 0.0; if (-0.8 <= x && x <= -0.6) { - f = exp(-log(2.0) * (x + 0.7) * (x + 0.7) / 0.0009); // Advected quantity (between -0.8 and -0.6). - } - else if (-0.4 <= x && x <= -0.2) { + f = + exp(-log(2.0) * (x + 0.7) * (x + 0.7) / 0.0009); // Advected quantity (between -0.8 and -0.6). + } else if (-0.4 <= x && x <= -0.2) { f = 1.0; // Advected quantity (between -0.4 and -0.2). - } - else if (0 <= x && x <= 0.2) { + } else if (0 <= x && x <= 0.2) { f = 1.0 - fabs(10.0 * (x - 0.1)); // Advected quantity (between 0 and 0.2). - } - else if (0.4 <= x && x <= 0.6) { + } else if (0.4 <= x && x <= 0.6) { f = sqrt(1.0 - 100.0 * (x - 0.5) * (x - 0.5)); // Advected quantity (between 0.4 and 0.6). } @@ -95,8 +90,7 @@ evalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, v fout[0] = f; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -110,24 +104,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -152,9 +147,9 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "q", .equation = advect, - + .init = evalInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -165,7 +160,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -173,8 +168,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -188,22 +182,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -227,22 +211,18 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -256,10 +236,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -268,26 +252,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -303,7 +292,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -318,8 +307,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -327,7 +315,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -335,8 +325,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -362,14 +351,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_advect_wv_mp.c b/moments/creg/rt_advect_wv_mp.c index e758528c3f..b1d53de40c 100644 --- a/moments/creg/rt_advect_wv_mp.c +++ b/moments/creg/rt_advect_wv_mp.c @@ -23,8 +23,7 @@ #include -struct advect_wv_mp_ctx -{ +struct advect_wv_mp_ctx { // Simulation parameters. int Nx; // Cell count (x-direction). double Lx; // Domain size (x-direction). @@ -39,8 +38,7 @@ struct advect_wv_mp_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct advect_wv_mp_ctx -create_ctx(void) +struct advect_wv_mp_ctx create_ctx(void) { // Simulation parameters. int Nx = 200; // Cell count (x-direction). @@ -65,29 +63,26 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; double f = 0.0; if (-0.8 <= x && x <= -0.6) { - f = exp(-log(2.0) * (x + 0.7) * (x + 0.7) / 0.0009); // Advected quantity (between -0.8 and -0.6). - } - else if (-0.4 <= x && x <= -0.2) { + f = + exp(-log(2.0) * (x + 0.7) * (x + 0.7) / 0.0009); // Advected quantity (between -0.8 and -0.6). + } else if (-0.4 <= x && x <= -0.2) { f = 1.0; // Advected quantity (between -0.4 and -0.2). - } - else if (0 <= x && x <= 0.2) { + } else if (0 <= x && x <= 0.2) { f = 1.0 - fabs(10.0 * (x - 0.1)); // Advected quantity (between 0 and 0.2). - } - else if (0.4 <= x && x <= 0.6) { + } else if (0.4 <= x && x <= 0.6) { f = sqrt(1.0 - 100.0 * (x - 0.5) * (x - 0.5)); // Advected quantity (between 0.4 and 0.6). } @@ -95,8 +90,7 @@ evalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, v fout[0] = f; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -110,24 +104,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -152,9 +147,9 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "q", .equation = advect, - + .init = evalInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -165,7 +160,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -173,8 +168,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -188,22 +182,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -227,25 +211,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, - + .scheme_type = GKYL_MOMENT_MP, .mp_recon = app_args.mp_recon, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -259,10 +239,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -271,26 +255,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -306,7 +295,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -321,8 +310,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -330,7 +318,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -338,8 +328,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -365,14 +354,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_arg_parse.h b/moments/creg/rt_arg_parse.h index ac622fc504..ac9855fda7 100644 --- a/moments/creg/rt_arg_parse.h +++ b/moments/creg/rt_arg_parse.h @@ -17,7 +17,7 @@ struct gkyl_app_args { bool use_gpu; // should this be run on GPU? - bool use_mpi; // should this be run on MPI? + bool use_mpi; // should this be run on MPI? bool step_mode; // run for fixed number of steps? (for valgrind/cuda-memcheck) bool trace_mem; // should we trace memory allocation/deallocations? int num_steps; // number of steps @@ -26,7 +26,8 @@ struct gkyl_app_args { int vcells[3]; // velocity space cells int cuts[3]; // domain decomposition "cuts" char file_name[1024]; // name of input file - char app_name[128]; // basename of argv[0] — use with snprintf/strcpy to set char[] name fields (cannot assign directly in compound literals) + char app_name + [128]; // basename of argv[0] — use with snprintf/strcpy to set char[] name fields (cannot assign directly in compound literals) enum gkyl_basis_type basis_type; // type of basis functions to use enum gkyl_mp_recon mp_recon; // the XX in MP-XX bool skip_limiters; // should we skip limiters? @@ -35,45 +36,36 @@ struct gkyl_app_args { char opt_args[128]; // optional arguments }; -static int -get_basis_type(const char *nm) +static int get_basis_type(const char *nm) { if (strcmp(nm, "ms") == 0) { return GKYL_BASIS_MODAL_SERENDIPITY; - } - else if (strcmp(nm, "mt") == 0) { + } else if (strcmp(nm, "mt") == 0) { return GKYL_BASIS_MODAL_TENSOR; } return -1; } -static int -get_mp_recon_type(const char *nm) +static int get_mp_recon_type(const char *nm) { if (strcmp(nm, "u1") == 0) { return GKYL_MP_U1; - } - else if (strcmp(nm, "u3") == 0) { + } else if (strcmp(nm, "u3") == 0) { return GKYL_MP_U3; - } - else if (strcmp(nm, "u5") == 0) { + } else if (strcmp(nm, "u5") == 0) { return GKYL_MP_U5; - } - else if (strcmp(nm, "c2") == 0) { + } else if (strcmp(nm, "c2") == 0) { return GKYL_MP_C2; - } - else if (strcmp(nm, "c4") == 0) { + } else if (strcmp(nm, "c4") == 0) { return GKYL_MP_C4; - } - else if (strcmp(nm, "c6") == 0) { + } else if (strcmp(nm, "c6") == 0) { return GKYL_MP_C6; - } - + } + return -1; } -static struct gkyl_app_args -parse_app_args(int argc, char **argv) +static struct gkyl_app_args parse_app_args(int argc, char **argv) { bool use_gpu = false; bool use_mpi = false; @@ -85,134 +77,130 @@ parse_app_args(int argc, char **argv) int num_steps = INT_MAX; int num_threads = 1; // by default use only 1 thread - struct gkyl_app_args args = { - .xcells = { 0 }, - .vcells = { 0 }, - .cuts = { 1, 1, 1 }, - }; + struct gkyl_app_args args = {.xcells = {0}, .vcells = {0}, .cuts = {1, 1, 1}}; strcpy(args.file_name, APP_ARGS_DEFAULT_FILE_NAME); // default args.basis_type = GKYL_BASIS_MODAL_SERENDIPITY; int c; while ((c = getopt(argc, argv, "+hjgmMt:s:i:b:x:y:z:u:v:w:r:c:d:e:o:")) != -1) { - switch (c) - { - case 'h': - printf("Usage: -g -m -s nsteps -t nthreads -i inp -b [ms|mt] -x NX -y NY -z NZ -u VX -v VY -w VZ\n"); - printf(" All flags and parameters are optional.\n"); - printf(" -g Run on GPUs if GPUs are present and code built for GPUs\n"); - printf(" -M Run with MPI if code built with MPI\n"); - printf(" -sN Only run N steps of simulation\n"); - printf(" -tN Use N threads (when available)\n"); - printf(" -b Basis function to use (ms: Modal serendipity; mt: Modal tensor-product)\n"); - printf(" (Ignored for finite-volume solvers)\n"); - printf(" -j Recovery scheme. One of u1, u3, u5, c2, c4, c6\n"); - printf(" (Only used for MP-XX solvers)\n"); - printf(" -l Turn off limiters\n"); - printf(" -rN Restart the simulation from frame N\n"); - printf(" -m Turn on memory allocation/deallocation tracing\n"); - printf(" -o Optional arguments (as string, requires parsing)\n"); - printf("\n"); - printf(" Grid resolution in configuration space:\n"); - printf(" -xNX -yNY -zNZ\n"); - printf(" Grid resolution in velocity space:\n"); - printf(" -uVX -vVY -wVZ\n"); - printf(" Domain decomposition in each direction:\n"); - printf(" -cPX -dPY -ePZ\n"); - exit(-1); - break; - - case 'g': - use_gpu = true; - break; - - case 'M': - use_mpi = true; - break; - - case 'm': - trace_mem = true; - break; - - case 'l': - skip_limiters = true; - break; - - case 'r': - is_restart = true; - restart_frame = atoi(optarg); - break; - - case 's': - step_mode = true; - num_steps = atoi(optarg); - break; - - case 't': - num_threads = atoi(optarg); - break; - - case 'c': - args.cuts[0] = atoi(optarg); - break; - - case 'd': - args.cuts[1] = atoi(optarg); - break; - - case 'e': - args.cuts[2] = atoi(optarg); - break; - - case 'x': - args.xcells[0] = atoi(optarg); - break; - - case 'y': - args.xcells[1] = atoi(optarg); - break; - - case 'z': - args.xcells[2] = atoi(optarg); - break; - - case 'u': - args.vcells[0] = atoi(optarg); - break; - - case 'v': - args.vcells[1] = atoi(optarg); - break; - - case 'w': - args.vcells[2] = atoi(optarg); - break; - - case 'i': - strcpy(args.file_name, optarg); - break; - - case 'b': - args.basis_type = get_basis_type(optarg); - assert(args.basis_type != -1); - break; - - case 'j': - args.mp_recon = get_mp_recon_type(optarg); - assert(args.mp_recon != -1); - break; - - case 'o': - assert(strlen(optarg) < sizeof(args.opt_args)); - strcpy(args.opt_args, optarg); - break; - - case '?': - break; + switch (c) { + case 'h': + printf("Usage: -g -m -s nsteps -t nthreads -i inp -b [ms|mt] -x NX -y NY -z NZ -u " + "VX -v VY -w VZ\n"); + printf(" All flags and parameters are optional.\n"); + printf(" -g Run on GPUs if GPUs are present and code built for GPUs\n"); + printf(" -M Run with MPI if code built with MPI\n"); + printf(" -sN Only run N steps of simulation\n"); + printf(" -tN Use N threads (when available)\n"); + printf(" -b Basis function to use (ms: Modal serendipity; mt: Modal tensor-product)\n"); + printf(" (Ignored for finite-volume solvers)\n"); + printf(" -j Recovery scheme. One of u1, u3, u5, c2, c4, c6\n"); + printf(" (Only used for MP-XX solvers)\n"); + printf(" -l Turn off limiters\n"); + printf(" -rN Restart the simulation from frame N\n"); + printf(" -m Turn on memory allocation/deallocation tracing\n"); + printf(" -o Optional arguments (as string, requires parsing)\n"); + printf("\n"); + printf(" Grid resolution in configuration space:\n"); + printf(" -xNX -yNY -zNZ\n"); + printf(" Grid resolution in velocity space:\n"); + printf(" -uVX -vVY -wVZ\n"); + printf(" Domain decomposition in each direction:\n"); + printf(" -cPX -dPY -ePZ\n"); + exit(-1); + break; + + case 'g': + use_gpu = true; + break; + + case 'M': + use_mpi = true; + break; + + case 'm': + trace_mem = true; + break; + + case 'l': + skip_limiters = true; + break; + + case 'r': + is_restart = true; + restart_frame = atoi(optarg); + break; + + case 's': + step_mode = true; + num_steps = atoi(optarg); + break; + + case 't': + num_threads = atoi(optarg); + break; + + case 'c': + args.cuts[0] = atoi(optarg); + break; + + case 'd': + args.cuts[1] = atoi(optarg); + break; + + case 'e': + args.cuts[2] = atoi(optarg); + break; + + case 'x': + args.xcells[0] = atoi(optarg); + break; + + case 'y': + args.xcells[1] = atoi(optarg); + break; + + case 'z': + args.xcells[2] = atoi(optarg); + break; + + case 'u': + args.vcells[0] = atoi(optarg); + break; + + case 'v': + args.vcells[1] = atoi(optarg); + break; + + case 'w': + args.vcells[2] = atoi(optarg); + break; + + case 'i': + strcpy(args.file_name, optarg); + break; + + case 'b': + args.basis_type = get_basis_type(optarg); + assert(args.basis_type != -1); + break; + + case 'j': + args.mp_recon = get_mp_recon_type(optarg); + assert(args.mp_recon != -1); + break; + + case 'o': + assert(strlen(optarg) < sizeof(args.opt_args)); + strcpy(args.opt_args, optarg); + break; + + case '?': + break; } } - + args.use_gpu = use_gpu; args.use_mpi = use_mpi; args.trace_mem = trace_mem; diff --git a/moments/creg/rt_burgers_shock.c b/moments/creg/rt_burgers_shock.c index 4cd2cb8cfb..b59df57686 100644 --- a/moments/creg/rt_burgers_shock.c +++ b/moments/creg/rt_burgers_shock.c @@ -23,8 +23,7 @@ #include -struct burgers_shock_ctx -{ +struct burgers_shock_ctx { // Simulation parameters. int Nx; // Cell count (x-direction). double Lx; // Domain size (x-direction). @@ -38,8 +37,7 @@ struct burgers_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct burgers_shock_ctx -create_ctx(void) +struct burgers_shock_ctx create_ctx(void) { // Simulation parameters. int Nx = 128; // Cell count (x-direction). @@ -62,14 +60,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; @@ -77,8 +74,7 @@ evalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, v if (x > 2.0 && x < 4.0) { f = 3.0; // Advected quantity (between 2 and 4). - } - else { + } else { f = -1.0; // Advected quantity (elsewhere). } @@ -86,8 +82,7 @@ evalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, v fout[0] = f; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -101,24 +96,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -143,12 +139,12 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "burgers", .equation = burgers, - + .init = evalInit, .split_type = GKYL_WAVE_QWAVE, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -159,7 +155,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -167,8 +163,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -182,22 +177,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -221,20 +206,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -248,10 +229,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -260,26 +245,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -295,7 +285,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -310,8 +300,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -319,7 +308,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -327,8 +318,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -354,14 +344,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(burgers); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_burgers_shock_mp.c b/moments/creg/rt_burgers_shock_mp.c index e4f98a02b5..62fe05f784 100644 --- a/moments/creg/rt_burgers_shock_mp.c +++ b/moments/creg/rt_burgers_shock_mp.c @@ -23,8 +23,7 @@ #include -struct burgers_shock_mp_ctx -{ +struct burgers_shock_mp_ctx { // Mathematical constants (dimensionless). double pi; @@ -41,8 +40,7 @@ struct burgers_shock_mp_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct burgers_shock_mp_ctx -create_ctx(void) +struct burgers_shock_mp_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -69,14 +67,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct burgers_shock_mp_ctx *app = ctx; @@ -89,8 +86,7 @@ evalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, v fout[0] = f; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -104,24 +100,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -146,11 +143,11 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "burgers", .equation = burgers, - + .init = evalInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -161,7 +158,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -169,8 +166,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -184,22 +180,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -223,9 +209,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, @@ -233,13 +219,9 @@ main(int argc, char **argv) .mp_recon = app_args.mp_recon, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -253,10 +235,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -265,26 +251,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -300,7 +291,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -315,8 +306,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -324,7 +314,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -332,8 +324,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -359,14 +350,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(burgers); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_coldfluid_beach.c b/moments/creg/rt_coldfluid_beach.c index 6124370757..79399b94bc 100644 --- a/moments/creg/rt_coldfluid_beach.c +++ b/moments/creg/rt_coldfluid_beach.c @@ -23,8 +23,7 @@ #include -struct coldfluid_beach_ctx -{ +struct coldfluid_beach_ctx { // Mathematical constants (dimensionless). double pi; @@ -36,7 +35,7 @@ struct coldfluid_beach_ctx double charge_elc; // Electron charge. double J0; // Reference current density (Amps / m^3). - + // Derived physical quantities (using non-normalized physical units). double light_speed; // Speed of light. @@ -57,8 +56,7 @@ struct coldfluid_beach_ctx double omega_drive; // Drive current angular frequency. }; -struct coldfluid_beach_ctx -create_ctx(void) +struct coldfluid_beach_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -71,7 +69,7 @@ create_ctx(void) double charge_elc = -1.602176487e-19; // Electron charge. double J0 = 1.0e-12; // Reference current density (Amps / m^3). - + // Derived physical quantities (using non-normalized physical units). double light_speed = 1.0 / sqrt(mu0 * epsilon0); // Speed of light. @@ -88,7 +86,9 @@ create_ctx(void) int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double deltaT = Lx100 / light_speed; // Arbitrary constant, with units of time. - double factor = deltaT * deltaT * charge_elc * charge_elc / (mass_elc * epsilon0); // Numerical factor for calculation of electron number density. + double factor = + deltaT * deltaT * charge_elc * charge_elc / + (mass_elc * epsilon0); // Numerical factor for calculation of electron number density. double omega_drive = pi / 10.0 / deltaT; // Drive current angular frequency. struct coldfluid_beach_ctx ctx = { @@ -111,14 +111,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .deltaT = deltaT, .factor = factor, - .omega_drive = omega_drive, + .omega_drive = omega_drive }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct coldfluid_beach_ctx *app = ctx; @@ -132,30 +131,34 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Lx100 = app->Lx100; - double factor = app ->factor; + double factor = app->factor; - double omegaPdt = 25.0 * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x); // Plasma frequency profile. + double omegaPdt = + 25.0 * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x); // Plasma frequency profile. double ne = omegaPdt * omegaPdt / factor; // Electron number density. // Set electron mass density. fout[0] = mass_elc * ne; // Set electron momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = 0.0, fout[4] = 0.0; fout[5] = 0.0; + fout[3] = 0.0, fout[4] = 0.0; + fout[5] = 0.0; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAppCurrent(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct coldfluid_beach_ctx *app = ctx; @@ -179,8 +182,7 @@ evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f } } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -192,8 +194,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -203,7 +204,7 @@ main(int argc, char **argv) } #endif - if (app_args.trace_mem) { + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } @@ -217,24 +218,26 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_cold, .split_type = GKYL_WAVE_FWAVE, - + .init = evalElcInit, - .ctx = &ctx, + .ctx = &ctx }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .use_explicit_em_coupling = true, - + .init = evalFieldInit, .ctx = &ctx, .app_current = evalAppCurrent, .app_current_ctx = &ctx, - .app_current_evolve = true, + .app_current_evolve = true }; int nrank = 1; // Number of processes in simulation. @@ -245,7 +248,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -253,8 +256,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -268,22 +270,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -307,22 +299,18 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -335,7 +323,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_app_apply_ic(app, t_curr); @@ -353,7 +341,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -366,8 +354,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -375,11 +362,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -410,6 +398,6 @@ main(int argc, char **argv) MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_coldfluid_clouda.c b/moments/creg/rt_coldfluid_clouda.c index c6fdf587e1..d1b4419ac9 100644 --- a/moments/creg/rt_coldfluid_clouda.c +++ b/moments/creg/rt_coldfluid_clouda.c @@ -23,8 +23,7 @@ #include -struct coldfluid_clouda_ctx -{ +struct coldfluid_clouda_ctx { // Physical constants (using normalized code units). double rhol; // Left cold fluid mass density. double ul; // Left cold fluid velocity. @@ -43,8 +42,7 @@ struct coldfluid_clouda_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct coldfluid_clouda_ctx -create_ctx(void) +struct coldfluid_clouda_ctx create_ctx(void) { // Physical constants (using normalized code units). double rhol = 2.0; // Left cold fluid mass density. @@ -74,14 +72,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalColdInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalColdInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct coldfluid_clouda_ctx *app = ctx; @@ -98,8 +95,7 @@ evalColdInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (-2.0 < x && x < -1.0) { rho = rhol; // Cold fluid mass density (left). u = ul; // Cold fluid velocity (left). - } - else if (1.0 < x && x < 5.0) { + } else if (1.0 < x && x < 5.0) { rho = rhor; // Cold fluid mass density (right). u = ur; // Cold fluid velocity (right). } @@ -107,11 +103,12 @@ evalColdInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou // Set cold fluid mass density. fout[0] = rho; // Set cold fluid momentum density. - fout[1] = rho*u; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = rho * u; + fout[2] = 0.0; + fout[3] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -123,8 +120,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -149,14 +145,14 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "cold", .equation = coldf, - + .init = evalColdInit, .split_type = GKYL_WAVE_FWAVE, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; - + int nrank = 1; // Number of processes in simulation. #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { @@ -165,7 +161,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -173,8 +169,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -188,22 +183,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -227,20 +212,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -5.0 }, - .upper = { -5.0 + ctx.Lx }, - .cells = { NX }, + .lower = {-5.0}, + .upper = {-5.0 + ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -253,7 +234,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_app_apply_ic(app, t_curr); @@ -271,7 +252,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -284,8 +265,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -293,11 +273,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -320,14 +301,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(coldf); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_coldfluid_em_coupling.c b/moments/creg/rt_coldfluid_em_coupling.c index db798c1247..be04b9da22 100644 --- a/moments/creg/rt_coldfluid_em_coupling.c +++ b/moments/creg/rt_coldfluid_em_coupling.c @@ -17,8 +17,7 @@ #include -struct coldfluid_em_coupling_ctx -{ +struct coldfluid_em_coupling_ctx { // Mathematical constants (dimensionless). double pi; @@ -35,7 +34,7 @@ struct coldfluid_em_coupling_ctx double laser_profile_duration; // Duration of the laser pulse (in s). double laser_profile_t_peak; // Time at which the laser reaches peak intensity (in s). double laser_wavelength; // Wavelength of the laser (in m). - + // Derived physical quantities (using non-normalized physical units). double light_speed; // Speed of light. @@ -51,8 +50,7 @@ struct coldfluid_em_coupling_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct coldfluid_em_coupling_ctx -create_ctx(void) +struct coldfluid_em_coupling_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -70,7 +68,7 @@ create_ctx(void) double laser_profile_duration = 15.0e-15; // Duration of the laser pulse (in s). double laser_profile_t_peak = 30.0e-15; // Time at which the laser reaches peak intensity (in s). double laser_wavelength = 0.8e-6; // Wavelength of the laser (in m). - + // Derived physical quantities (using non-normalized physical units). double light_speed = 1.0 / sqrt(mu0 * epsilon0); // Speed of light. @@ -105,14 +103,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct coldfluid_em_coupling_ctx *app = ctx; @@ -121,22 +118,25 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho; // Set electron moment density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = 0.0, fout[4] = 0.0; fout[5] = 0.0; + fout[3] = 0.0, fout[4] = 0.0; + fout[5] = 0.0; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAppCurrent(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct coldfluid_em_coupling_ctx *app = ctx; @@ -158,10 +158,12 @@ evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double current = 0.0; if (x > 0.0 && x <= x_last_edge) { - current = amplitude * sin((2.0 * pi * light_speed * t) / laser_wavelength) * exp(-((t - laser_profile_t_peak) * - (t - laser_profile_t_peak)) / ((laser_profile_duration * laser_profile_duration))); - } - else { + current = amplitude * sin((2.0 * pi * light_speed * t) / laser_wavelength) * + exp( + -((t - laser_profile_t_peak) * (t - laser_profile_t_peak)) / + ((laser_profile_duration * laser_profile_duration)) + ); + } else { current = 0.0; } @@ -169,8 +171,7 @@ evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[1] = current; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -182,8 +183,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -193,7 +193,7 @@ main(int argc, char **argv) } #endif - if (app_args.trace_mem) { + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } @@ -207,28 +207,30 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_cold, .split_type = GKYL_WAVE_FWAVE, - + .init = evalElcInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .use_explicit_em_coupling = true, - + .init = evalFieldInit, .ctx = &ctx, .app_current = evalAppCurrent, .app_current_ctx = &ctx, - .app_current_evolve = true, + .app_current_evolve = true, - .bcx = { GKYL_FIELD_COPY, GKYL_FIELD_COPY }, + .bcx = {GKYL_FIELD_COPY, GKYL_FIELD_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -239,7 +241,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -247,8 +249,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -262,22 +263,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -301,22 +292,18 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -329,7 +316,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_app_apply_ic(app, t_curr); @@ -347,7 +334,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -360,8 +347,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -369,11 +355,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -404,6 +391,6 @@ main(int argc, char **argv) MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_axi_sodshock.c b/moments/creg/rt_euler_axi_sodshock.c index b559483ee0..b775a7971b 100644 --- a/moments/creg/rt_euler_axi_sodshock.c +++ b/moments/creg/rt_euler_axi_sodshock.c @@ -23,8 +23,7 @@ #include -struct axi_sodshock_ctx -{ +struct axi_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -56,8 +55,7 @@ struct axi_sodshock_ctx double rloc; // Fluid boundary (radial coordinate). }; -struct axi_sodshock_ctx -create_ctx(void) +struct axi_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -109,14 +107,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .rloc = rloc, + .rloc = rloc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { double r = zc[0]; struct axi_sodshock_ctx *app = ctx; @@ -141,8 +138,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left/inner). u = ul; // Fluid velocity (left/inner). p = pl; // Fluid pressure (left/inner). - } - else { + } else { rho = rhor; // Fluid mass density (right/outer). u = ur; // Fluid velocity (right/outer). p = pr; // Fluid pressure (right/outer). @@ -152,17 +148,19 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * u * u); // Fluid total energy density. - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double r = zc[0], theta = zc[1]; @@ -171,8 +169,7 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* xp[1] = r * sin(theta); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -186,24 +183,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -229,11 +227,11 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -244,7 +242,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NR, NTHETA }; + int cells[] = {NR, NTHETA}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -252,8 +250,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -267,22 +264,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -306,26 +293,23 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.25, 0.0 }, - .upper = { 0.25 + ctx.Lr, 0.0 + ctx.Ltheta }, - .cells = { NR, NTHETA }, + .lower = {0.25, 0.0}, + .upper = {0.25 + ctx.Lr, 0.0 + ctx.Ltheta}, + .cells = {NR, NTHETA}, .mapc2p = mapc2p, .c2p_ctx = &ctx, .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .periodic_dirs = {1}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -339,10 +323,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -351,26 +339,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -386,7 +379,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -401,8 +394,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -410,7 +402,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -418,8 +412,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -445,14 +438,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_axi_vac_riem.c b/moments/creg/rt_euler_axi_vac_riem.c index 8aa3355fa9..73e13da257 100644 --- a/moments/creg/rt_euler_axi_vac_riem.c +++ b/moments/creg/rt_euler_axi_vac_riem.c @@ -23,8 +23,7 @@ #include -struct axi_vac_riem_ctx -{ +struct axi_vac_riem_ctx { // Mathematical constants (dimensionless). double pi; @@ -56,8 +55,7 @@ struct axi_vac_riem_ctx double rloc; // Fluid boundary (radial coordinate). }; -struct axi_vac_riem_ctx -create_ctx(void) +struct axi_vac_riem_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -109,14 +107,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .rloc = rloc, + .rloc = rloc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { double r = zc[0]; struct axi_vac_riem_ctx *app = ctx; @@ -141,28 +138,29 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left/inner). u = ul; // Fluid velocity (left/inner). p = pl; // Fluid pressure (left/inner). - } - else { + } else { rho = rhor; // Fluid mass density (right/outer). u = ur; // Fluid velocity (right/outer). p = pr; // Fluid pressure (right/outer). } - + double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * u * u); // Fluid total energy density. - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double r = zc[0], theta = zc[1]; @@ -171,8 +169,7 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* xp[1] = r * sin(theta); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -186,24 +183,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -213,7 +211,7 @@ main(int argc, char **argv) } #endif - if (app_args.trace_mem) { + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } @@ -229,11 +227,11 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -243,7 +241,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NR, NTHETA }; + int cells[] = {NR, NTHETA}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -251,8 +249,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -266,22 +263,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -305,26 +292,23 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.25, 0.0 }, - .upper = { 0.25 + ctx.Lr, 0.0 + ctx.Ltheta }, - .cells = { NR, NTHETA }, + .lower = {0.25, 0.0}, + .upper = {0.25 + ctx.Lr, 0.0 + ctx.Ltheta}, + .cells = {NR, NTHETA}, .mapc2p = mapc2p, .c2p_ctx = &ctx, .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .periodic_dirs = {1}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -338,10 +322,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -350,26 +338,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -385,7 +378,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -400,8 +393,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -409,7 +401,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -417,8 +411,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -444,14 +437,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_bump_in_channel.c b/moments/creg/rt_euler_bump_in_channel.c index c0e40e8701..40bd32b6da 100644 --- a/moments/creg/rt_euler_bump_in_channel.c +++ b/moments/creg/rt_euler_bump_in_channel.c @@ -24,8 +24,7 @@ #include -struct bump_in_channel_ctx -{ +struct bump_in_channel_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -64,8 +63,7 @@ struct bump_in_channel_ctx double Ly; // Domain size (y-direction). }; -struct bump_in_channel_ctx -create_ctx(void) +struct bump_in_channel_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -128,14 +126,13 @@ create_ctx(void) .R = R, .half_xlen = half_xlen, .Lx = Lx, - .Ly = Ly, + .Ly = Ly }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void *ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { double x = zc[0]; struct bump_in_channel_ctx *app = ctx; @@ -160,8 +157,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -171,27 +167,29 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * u * u); // Fluid total energy density. - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double x = zc[0], y = zc[1]; struct bump_in_channel_ctx *app = ctx; - + double bump_xlen = app->bump_xlen; double height = app->height; double R = app->R; - + double zeta_min = sqrt((R * R) - ((0.5 * bump_xlen) * (0.5 * bump_xlen))); - + // Set physical coordinates (x, y) from computational coordinates (x, y). xp[0] = x; xp[1] = y; @@ -205,8 +203,7 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* } } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -220,24 +217,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -247,7 +245,7 @@ main(int argc, char **argv) } #endif - if (app_args.trace_mem) { + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } @@ -263,12 +261,12 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -278,7 +276,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -286,8 +284,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -301,22 +298,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -340,23 +327,20 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, 0.0 }, - .upper = { 0.5 * ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, 0.0}, + .upper = {0.5 * ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .mapc2p = mapc2p, .c2p_ctx = &ctx, - + .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -370,10 +354,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -382,26 +370,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -417,7 +410,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -432,8 +425,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -441,7 +433,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -449,8 +443,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -476,14 +469,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } \ No newline at end of file diff --git a/moments/creg/rt_euler_c2p_sodshock.c b/moments/creg/rt_euler_c2p_sodshock.c index d234fe1c5a..ca465730fc 100644 --- a/moments/creg/rt_euler_c2p_sodshock.c +++ b/moments/creg/rt_euler_c2p_sodshock.c @@ -23,8 +23,7 @@ #include -struct c2p_sodshock_ctx -{ +struct c2p_sodshock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -49,8 +48,7 @@ struct c2p_sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct c2p_sodshock_ctx -create_ctx(void) +struct c2p_sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -91,14 +89,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { double x = zc[0]; struct c2p_sodshock_ctx *app = ctx; @@ -121,8 +118,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -132,25 +128,26 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * u * u); // Fluid total energy density. - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double x = zc[0]; xp[0] = (0.5 * x) + 0.5; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -164,24 +161,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -206,11 +204,11 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -220,7 +218,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -228,8 +226,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -243,22 +240,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -282,22 +269,18 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, - .mapc2p = mapc2p, + .mapc2p = mapc2p, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -311,10 +294,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -323,26 +310,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -358,7 +350,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -373,8 +365,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -382,7 +373,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -390,8 +383,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -417,14 +409,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_cart_axi_sodshock.c b/moments/creg/rt_euler_cart_axi_sodshock.c index 884baf572b..65334bf4fa 100644 --- a/moments/creg/rt_euler_cart_axi_sodshock.c +++ b/moments/creg/rt_euler_cart_axi_sodshock.c @@ -23,8 +23,7 @@ #include -struct cart_axi_sodshock_ctx -{ +struct cart_axi_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -56,8 +55,7 @@ struct cart_axi_sodshock_ctx double rloc; // Fluid boundary (radial coordinate). }; -struct cart_axi_sodshock_ctx -create_ctx(void) +struct cart_axi_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -109,14 +107,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .rloc = rloc, + .rloc = rloc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct cart_axi_sodshock_ctx *app = ctx; @@ -143,28 +140,28 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left/inner). u = ul; // Fluid velocity (left/inner). p = pl; // Fluid pressure (left/inner). - } - else { + } else { rho = rhor; // Fluid mass density (right/outer). u = ur; // Fluid velocity (right/outer). p = pr; // Fluid pressure (right/outer). } - + double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * u * u); // Fluid total energy density. - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -178,24 +175,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -221,11 +219,11 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -235,7 +233,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -243,8 +241,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -258,22 +255,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -297,20 +284,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -324,10 +308,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -336,26 +324,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -371,7 +364,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -386,8 +379,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -395,7 +387,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -403,8 +397,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -430,14 +423,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_embedded_surface.c b/moments/creg/rt_euler_embedded_surface.c index ec6ae9df29..9d59c3ac58 100644 --- a/moments/creg/rt_euler_embedded_surface.c +++ b/moments/creg/rt_euler_embedded_surface.c @@ -18,8 +18,7 @@ #include -struct embedded_ctx -{ +struct embedded_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic idex. @@ -29,7 +28,7 @@ struct embedded_ctx double u1; double p0; double p1; - + // Simulation parameters. int Nx; // Cell count (x-direction). int Ny; // Cell count (y-direction). @@ -45,19 +44,18 @@ struct embedded_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct embedded_ctx -create_ctx(void) +struct embedded_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. - double rho0 = 2.66666666*1.4; // Reference fluid mass density. + double rho0 = 2.66666666 * 1.4; // Reference fluid mass density. double rho1 = 1.4; // Reference fluid mass density. double u0 = 1.25; double u1 = 0.0; - double p0 = 4.5*1.0; + double p0 = 4.5 * 1.0; double p1 = 1.0; - + // Simulation parameters. int Nx = 300; // Cell count (x-direction). int Ny = 300; // Cell count (y-direction). @@ -90,14 +88,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalPhiInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT phi, void* ctx) +void evalPhiInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT phi, void *ctx) { double x = xn[0], y = xn[1]; struct embedded_ctx *app = ctx; @@ -107,14 +104,14 @@ evalPhiInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT phi, double r = 0.15; - if (((x-xc)*(x-xc) + (y-yc)*(y-yc)) < r*r) + if (((x - xc) * (x - xc) + (y - yc) * (y - yc)) < r * r) { phi[0] = -1.0; - else + } else { phi[0] = 1.0; + } } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct embedded_ctx *app = ctx; @@ -122,7 +119,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double gas_gamma = app->gas_gamma; double rho0 = app->rho0; - + double Lx = app->Lx; double Ly = app->Ly; @@ -141,27 +138,28 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo p = app->p1; } - if (((x-xc)*(x-xc) + (y-yc)*(y-yc)) < r*r) { + if (((x - xc) * (x - xc) + (y - yc) * (y - yc)) < r * r) { rho = 0.01; u = 0.0; p = 0.01; } - double mom_x = rho*u; // Fluid momentum density (x-direction). + double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = p/(gas_gamma - 1.0) + 0.5*rho*u*u; // Fluid total energy density. + double Etot = p / (gas_gamma - 1.0) + 0.5 * rho * u * u; // Fluid total energy density. // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -175,24 +173,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -212,27 +211,25 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); - struct gkyl_wv_embed_geo *embed_geo = gkyl_wv_embed_geo_new(GKYL_EMBED_REFLECT, - evalPhiInit, NULL, &ctx); + struct gkyl_wv_embed_geo *embed_geo = + gkyl_wv_embed_geo_new(GKYL_EMBED_REFLECT, evalPhiInit, NULL, &ctx); // Fluid equations. - struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew( - &(struct gkyl_wv_euler_inp) { - .gas_gamma = ctx.gas_gamma, - .rp_type = WV_EULER_RP_HLLC, - .embed_geo = embed_geo, - .use_gpu = app_args.use_gpu, - }); + struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew(&(struct gkyl_wv_euler_inp + ){.gas_gamma = ctx.gas_gamma, + .rp_type = WV_EULER_RP_HLLC, + .embed_geo = embed_geo, + .use_gpu = app_args.use_gpu}); struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -242,7 +239,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -250,8 +247,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -265,22 +261,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -304,20 +290,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5*ctx.Lx, -0.5*ctx.Ly }, - .upper = { 0.5*ctx.Lx, 0.5*ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -331,10 +314,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -343,26 +330,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -378,7 +370,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -393,8 +385,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -402,7 +393,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -410,8 +403,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -438,14 +430,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(euler); gkyl_wv_embed_geo_release(embed_geo); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_embedded_surface_mapc2p.c b/moments/creg/rt_euler_embedded_surface_mapc2p.c index 9b848bde64..24cf83a772 100644 --- a/moments/creg/rt_euler_embedded_surface_mapc2p.c +++ b/moments/creg/rt_euler_embedded_surface_mapc2p.c @@ -18,8 +18,7 @@ #include -struct embedded_ctx -{ +struct embedded_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic idex. @@ -29,7 +28,7 @@ struct embedded_ctx double u1; double p0; double p1; - + // Simulation parameters. int Nx; // Cell count (x-direction). int Ny; // Cell count (y-direction). @@ -45,19 +44,18 @@ struct embedded_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct embedded_ctx -create_ctx(void) +struct embedded_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. - double rho0 = 3.85714285*1.4; // Reference fluid mass density. + double rho0 = 3.85714285 * 1.4; // Reference fluid mass density. double rho1 = 1.4; // Reference fluid mass density. double u0 = 2.22222222; double u1 = 0.0; - double p0 = 10.3333333*1.0; + double p0 = 10.3333333 * 1.0; double p1 = 1.0; - + // Simulation parameters. int Nx = 300; // Cell count (x-direction). int Ny = 300; // Cell count (y-direction). @@ -90,102 +88,95 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double x = zc[0], y = zc[1]; double r1 = 0.15; - double r2 = r1/0.8; + double r2 = r1 / 0.8; double cx1 = 0.4, cy1 = 0.25; double cx2 = 0.5, cy2 = 0.75; if ((x <= cx1 + r2) && (x >= cx1 - r2) && (y <= cy1 + r2) && (y >= cy1 - r2)) { - double xc = (x - cx1)/r2, yc = (y - cy1)/r2; + double xc = (x - cx1) / r2, yc = (y - cy1) / r2; double d = fmax(fabs(xc), fabs(yc)); d = fmax(d, 1.0e-10); - double D = r2*d/sqrt(2.0); + double D = r2 * d / sqrt(2.0); double R = r1; - if (d > r1/r2) { - R = r1*pow((1.0 - r1/r2)/(1.0 - d), r2/r1 + 0.5); + if (d > r1 / r2) { + R = r1 * pow((1.0 - r1 / r2) / (1.0 - d), r2 / r1 + 0.5); // Scale D outside circle to correctly extend to grid edge. - D = D*((1.0 - sqrt(2.0))/(r1/r2 - 1.0)*d + (1.0 - sqrt(2)*r1/r2)/(1.0 - r1/r2)); + D = + D * ((1.0 - sqrt(2.0)) / (r1 / r2 - 1.0) * d + (1.0 - sqrt(2) * r1 / r2) / (1.0 - r1 / r2)); } if ((xc > 0.0) && (fabs(yc) <= fabs(xc))) { - xp[1] = yc*D/d; - xp[0] = D - sqrt(R*R - D*D) + sqrt(R*R - xp[1]*xp[1]) + cx1; + xp[1] = yc * D / d; + xp[0] = D - sqrt(R * R - D * D) + sqrt(R * R - xp[1] * xp[1]) + cx1; xp[1] = xp[1] + cy1; - } - else if ((xc < 0.0) && (fabs(yc) <= fabs(xc))) { - xp[1] = yc*D/d; - xp[0] = -(D - sqrt(R*R - D*D) + sqrt(R*R - xp[1]*xp[1])) + cx1; + } else if ((xc < 0.0) && (fabs(yc) <= fabs(xc))) { + xp[1] = yc * D / d; + xp[0] = -(D - sqrt(R * R - D * D) + sqrt(R * R - xp[1] * xp[1])) + cx1; xp[1] = xp[1] + cy1; - } - else if ((yc > 0.0) && (fabs(xc) <= fabs(yc))) { - xp[0] = xc*D/d; - xp[1] = D - sqrt(R*R - D*D) + sqrt(R*R - xp[0]*xp[0]) + cy1; + } else if ((yc > 0.0) && (fabs(xc) <= fabs(yc))) { + xp[0] = xc * D / d; + xp[1] = D - sqrt(R * R - D * D) + sqrt(R * R - xp[0] * xp[0]) + cy1; xp[0] = xp[0] + cx1; - } - else { - xp[0] = xc*D/d; - xp[1] = -(D - sqrt(R*R - D*D) + sqrt(R*R - xp[0]*xp[0])) + cy1; + } else { + xp[0] = xc * D / d; + xp[1] = -(D - sqrt(R * R - D * D) + sqrt(R * R - xp[0] * xp[0])) + cy1; xp[0] = xp[0] + cx1; } - } - else if ((x <= cx2 + r2) && (x >= cx2 - r2) && (y <= cy2 + r2) && (y >= cy2 - r2)) { - double xc = (x - cx2)/r2, yc = (y - cy2)/r2; + } else if ((x <= cx2 + r2) && (x >= cx2 - r2) && (y <= cy2 + r2) && (y >= cy2 - r2)) { + double xc = (x - cx2) / r2, yc = (y - cy2) / r2; double d = fmax(fabs(xc), fabs(yc)); d = fmax(d, 1.0e-10); - double D = r2*d/sqrt(2.0); + double D = r2 * d / sqrt(2.0); double R = r1; - if (d > r1/r2) { - R = r1*pow((1.0 - r1/r2)/(1.0 - d), r2/r1 + 0.5); + if (d > r1 / r2) { + R = r1 * pow((1.0 - r1 / r2) / (1.0 - d), r2 / r1 + 0.5); // Scale D outside circle to correctly extend to grid edge. - D = D*((1.0 - sqrt(2.0))/(r1/r2 - 1.0)*d + (1.0 - sqrt(2)*r1/r2)/(1.0 - r1/r2)); + D = + D * ((1.0 - sqrt(2.0)) / (r1 / r2 - 1.0) * d + (1.0 - sqrt(2) * r1 / r2) / (1.0 - r1 / r2)); } if ((xc > 0.0) && (fabs(yc) <= fabs(xc))) { - xp[1] = yc*D/d; - xp[0] = D - sqrt(R*R - D*D) + sqrt(R*R - xp[1]*xp[1]) + cx2; + xp[1] = yc * D / d; + xp[0] = D - sqrt(R * R - D * D) + sqrt(R * R - xp[1] * xp[1]) + cx2; xp[1] = xp[1] + cy2; - } - else if ((xc < 0.0) && (fabs(yc) <= fabs(xc))) { - xp[1] = yc*D/d; - xp[0] = -(D - sqrt(R*R - D*D) + sqrt(R*R - xp[1]*xp[1])) + cx2; + } else if ((xc < 0.0) && (fabs(yc) <= fabs(xc))) { + xp[1] = yc * D / d; + xp[0] = -(D - sqrt(R * R - D * D) + sqrt(R * R - xp[1] * xp[1])) + cx2; xp[1] = xp[1] + cy2; - } - else if ((yc > 0.0) && (fabs(xc) <= fabs(yc))) { - xp[0] = xc*D/d; - xp[1] = D - sqrt(R*R - D*D) + sqrt(R*R - xp[0]*xp[0]) + cy2; + } else if ((yc > 0.0) && (fabs(xc) <= fabs(yc))) { + xp[0] = xc * D / d; + xp[1] = D - sqrt(R * R - D * D) + sqrt(R * R - xp[0] * xp[0]) + cy2; xp[0] = xp[0] + cx2; - } - else { - xp[0] = xc*D/d; - xp[1] = -(D - sqrt(R*R - D*D) + sqrt(R*R - xp[0]*xp[0])) + cy2; + } else { + xp[0] = xc * D / d; + xp[1] = -(D - sqrt(R * R - D * D) + sqrt(R * R - xp[0] * xp[0])) + cy2; xp[0] = xp[0] + cx2; } - } - else { + } else { xp[0] = x; xp[1] = y; } } -void -evalPhiInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT phi, void* ctx) +void evalPhiInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT phi, void *ctx) { double x = xn[0], y = xn[1]; - double xp[2] = { 0.0 }; + double xp[2] = {0.0}; mapc2p(0.0, xn, xp, ctx); struct embedded_ctx *app = ctx; @@ -198,17 +189,18 @@ evalPhiInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT phi, double r = 0.15; - if ((((xp[0]-xc1)*(xp[0]-xc1) + (xp[1]-yc1)*(xp[1]-yc1)) < r*r) || (((xp[0]-xc2)*(xp[0]-xc2) + (xp[1]-yc2)*(xp[1]-yc2)) < r*r)) + if ((((xp[0] - xc1) * (xp[0] - xc1) + (xp[1] - yc1) * (xp[1] - yc1)) < r * r) || + (((xp[0] - xc2) * (xp[0] - xc2) + (xp[1] - yc2) * (xp[1] - yc2)) < r * r)) { phi[0] = -1.0; - else + } else { phi[0] = 1.0; + } } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; - double xp[2] = { 0.0 }; + double xp[2] = {0.0}; mapc2p(0.0, xn, xp, ctx); struct embedded_ctx *app = ctx; @@ -216,7 +208,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double gas_gamma = app->gas_gamma; double rho0 = app->rho0; - + double Lx = app->Lx; double Ly = app->Ly; @@ -238,27 +230,29 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo p = app->p1; } - if ((((xp[0]-xc1)*(xp[0]-xc1) + (xp[1]-yc1)*(xp[1]-yc1)) < r*r) || (((xp[0]-xc2)*(xp[0]-xc2) + (xp[1]-yc2)*(xp[1]-yc2)) < r*r)) { + if ((((xp[0] - xc1) * (xp[0] - xc1) + (xp[1] - yc1) * (xp[1] - yc1)) < r * r) || + (((xp[0] - xc2) * (xp[0] - xc2) + (xp[1] - yc2) * (xp[1] - yc2)) < r * r)) { rho = 0.01; u = 0.0; p = 0.01; } - double mom_x = rho*u; // Fluid momentum density (x-direction). + double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = p/(gas_gamma - 1.0); // Fluid total energy density. + double Etot = p / (gas_gamma - 1.0); // Fluid total energy density. // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -272,24 +266,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -309,27 +304,25 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); - struct gkyl_wv_embed_geo *embed_geo = gkyl_wv_embed_geo_new(GKYL_EMBED_REFLECT, - evalPhiInit, NULL, &ctx); + struct gkyl_wv_embed_geo *embed_geo = + gkyl_wv_embed_geo_new(GKYL_EMBED_REFLECT, evalPhiInit, NULL, &ctx); // Fluid equations. - struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew( - &(struct gkyl_wv_euler_inp) { - .gas_gamma = ctx.gas_gamma, - .rp_type = WV_EULER_RP_HLLC, - .embed_geo = embed_geo, - .use_gpu = app_args.use_gpu, - }); + struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew(&(struct gkyl_wv_euler_inp + ){.gas_gamma = ctx.gas_gamma, + .rp_type = WV_EULER_RP_HLLC, + .embed_geo = embed_geo, + .use_gpu = app_args.use_gpu}); struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -339,7 +332,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -347,8 +340,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -362,22 +354,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -401,9 +383,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .mapc2p = mapc2p, @@ -412,13 +394,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -432,10 +411,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -444,26 +427,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -479,7 +467,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -494,8 +482,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -503,7 +490,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -511,8 +500,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -539,14 +527,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(euler); gkyl_wv_embed_geo_release(embed_geo); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_kh_2d.c b/moments/creg/rt_euler_kh_2d.c index 1c4db4ebfd..2f6400a3eb 100644 --- a/moments/creg/rt_euler_kh_2d.c +++ b/moments/creg/rt_euler_kh_2d.c @@ -23,8 +23,7 @@ #include -struct kh_2d_ctx -{ +struct kh_2d_ctx { // Mathematical constants (dimensionless). double pi; @@ -54,8 +53,7 @@ struct kh_2d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct kh_2d_ctx -create_ctx(void) +struct kh_2d_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -103,14 +101,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct kh_2d_ctx *app = ctx; @@ -118,7 +115,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double pi = app->pi; double gas_gamma = app->gas_gamma; - + double rhol = app->rhol; double ul = app->ul; double pl = app->pl; @@ -138,8 +135,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left/inner). vx = ul; // Fluid x-velocity (left/inner). p = pl; // Fluid pressure (left/inner). - } - else { + } else { rho = rhor; // Fluid mass density (right/outer). vx = ur; // Fluid x-velocity (right/outer). p = pr; // Fluid pressure (right/outer). @@ -152,21 +148,24 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - vx += alpha * gkyl_pcg64_rand_double(&rng) * sin(i * k * x + j * k * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); - vy += alpha * gkyl_pcg64_rand_double(&rng) * sin(i * k * x + j * k * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); + vx += alpha * gkyl_pcg64_rand_double(&rng) * + sin(i * k * x + j * k * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); + vy += alpha * gkyl_pcg64_rand_double(&rng) * + sin(i * k * x + j * k * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); } } // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = rho * vx; fout[2] = rho * vy; fout[3] = 0.0; + fout[1] = rho * vx; + fout[2] = rho * vy; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * (vx * vx + vy * vy); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -178,8 +177,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -205,9 +203,9 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -217,7 +215,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -225,8 +223,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -240,22 +237,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -279,23 +266,20 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -308,7 +292,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_app_apply_ic(app, t_curr); @@ -326,7 +310,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -339,8 +323,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -348,11 +331,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -375,14 +359,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_mixture_fedkiw_shock.c b/moments/creg/rt_euler_mixture_fedkiw_shock.c index 799d188f5b..3ee3f90313 100644 --- a/moments/creg/rt_euler_mixture_fedkiw_shock.c +++ b/moments/creg/rt_euler_mixture_fedkiw_shock.c @@ -17,8 +17,7 @@ #include -struct fedkiw_shock_ctx -{ +struct fedkiw_shock_ctx { // Physical constants (using normalized code units). double gas_gamma1; // First species adiabatic index. double gas_gamma2; // Second species adiabatic index. @@ -51,8 +50,7 @@ struct fedkiw_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct fedkiw_shock_ctx -create_ctx(void) +struct fedkiw_shock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma1 = 1.4; // First species adiabatic index. @@ -108,14 +106,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerMixtureInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct fedkiw_shock_ctx *app = ctx; @@ -154,16 +153,14 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST vx_total = ul; // Total mixture velocity (left). p_total = pl; // Total mixture pressure (left). - } - else if (x < 0.5) { + } else if (x < 0.5) { rho1 = rhoc; // First species fluid mass density (central). rho2 = rhor; // Second species fluid mass density (right). alpha1 = alpha1_c; // First species volume fraction (central). vx_total = uc; // Total mixture velocity (central). p_total = pc; // Total mixture pressure (central). - } - else { + } else { rho1 = rhoc; // First species fluid mass density (central). rho2 = rhor; // Second species fluid mass density (right). alpha1 = alpha1_r; // First species volume fraction (right). @@ -177,28 +174,33 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST double momy_total = rho_total * vy_total; // Total mixture momentum density (y-direction). double momz_total = rho_total * vz_total; // Total mixture momentum density (z-direction). - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. + double E1 = (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. + double E2 = (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. double E_total = (alpha1 * E1) + ((1.0 - alpha1) * E2); // Total mixture energy. double vol_frac1 = rho_total * alpha1; // Mixture weighted volume fraction (first species). double mass_frac1 = alpha1 * rho1; // Mixture volume-weighted mass density (first species). - double mass_frac2 = (1.0 - alpha1) * rho2; // Mixture volume-weighted mass density (second species). + double mass_frac2 = + (1.0 - alpha1) * rho2; // Mixture volume-weighted mass density (second species). // Set fluid mixture total mass density. fout[0] = rho_total; // Set fluid mixture total momentum density. - fout[1] = momx_total; fout[2] = momy_total; fout[3] = momz_total; + fout[1] = momx_total; + fout[2] = momy_total; + fout[3] = momz_total; // Set fluid mixture total energy density. fout[4] = E_total; // Set fluid mixture weighted volume fraction (first species). fout[5] = vol_frac1; // Set fluid mixture volume-weighted mass densities (first and second species). - fout[6] = mass_frac1; fout[7] = mass_frac2; + fout[6] = mass_frac1; + fout[7] = mass_frac2; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -212,24 +214,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -257,11 +260,11 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler_mixture", .equation = euler_mixture, - + .init = evalEulerMixtureInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -272,7 +275,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -280,8 +283,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -295,22 +297,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -334,20 +326,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -361,10 +349,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -373,26 +365,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -408,7 +405,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -423,8 +420,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -432,7 +428,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -440,8 +438,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -470,13 +467,13 @@ main(int argc, char **argv) gkyl_moment_app_release(app); gkyl_free(gas_gamma_s); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_mixture_shock_bubble.c b/moments/creg/rt_euler_mixture_shock_bubble.c index 501baed4e8..a89e87e65a 100644 --- a/moments/creg/rt_euler_mixture_shock_bubble.c +++ b/moments/creg/rt_euler_mixture_shock_bubble.c @@ -17,8 +17,7 @@ #include -struct shock_bubble_ctx -{ +struct shock_bubble_ctx { // Physical constants (using normalized code units). double gas_gamma1; // First species adiabatic index. double gas_gamma2; // Second species adiabatic index. @@ -60,8 +59,7 @@ struct shock_bubble_ctx double bub_rad; // Bubble radius. }; -struct shock_bubble_ctx -create_ctx(void) +struct shock_bubble_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma1 = 1.4; // First species adiabatic index. @@ -132,14 +130,15 @@ create_ctx(void) .x_loc = x_loc, .bub_loc_x = bub_loc_x, .bub_loc_y = bub_loc_y, - .bub_rad = bub_rad, + .bub_rad = bub_rad }; return ctx; } -void -evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerMixtureInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct shock_bubble_ctx *app = ctx; @@ -186,8 +185,7 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST vx_total = u_post; // Total mixture velocity (post-shock). p_total = p_post; // Total mixture pressure (post-shock). - } - else { + } else { rho1 = rho_pre; // First species fluid mass density (pre-shock). rho2 = rho_bub; // Second species fluid mass density (bubble). alpha1 = alpha1_pre; // First species volume fraction (pre-shock). @@ -211,28 +209,33 @@ evalEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_REST double momy_total = rho_total * vy_total; // Total mixture momentum density (y-direction). double momz_total = rho_total * vz_total; // Total mixture momentum density (z-direction). - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. + double E1 = (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. + double E2 = (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. double E_total = (alpha1 * E1) + ((1.0 - alpha1) * E2); // Total mixture energy. double vol_frac1 = rho_total * alpha1; // Mixture weighted volume fraction (first species). double mass_frac1 = alpha1 * rho1; // Mixture volume-weighted mass density (first species). - double mass_frac2 = (1.0 - alpha1) * rho2; // Mixture volume-weighted mass density (second species). + double mass_frac2 = + (1.0 - alpha1) * rho2; // Mixture volume-weighted mass density (second species). // Set fluid mixture total mass density. fout[0] = rho_total; // Set fluid mixture total momentum density. - fout[1] = momx_total; fout[2] = momy_total; fout[3] = momz_total; + fout[1] = momx_total; + fout[2] = momy_total; + fout[3] = momz_total; // Set fluid mixture total energy density. fout[4] = E_total; // Set fluid mixture weighted volume fraction (first species). fout[5] = vol_frac1; // Set fluid mixture volume-weighted mass densities (first and second species). - fout[6] = mass_frac1; fout[7] = mass_frac2; + fout[6] = mass_frac1; + fout[7] = mass_frac2; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -246,24 +249,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -292,12 +296,12 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler_mixture", .equation = euler_mixture, - + .init = evalEulerMixtureInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; int nrank = 1; // Number of processes in simulation. @@ -308,7 +312,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -316,8 +320,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -331,22 +334,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -370,20 +363,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -397,10 +387,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -409,26 +403,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -444,7 +443,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -459,8 +458,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -468,7 +466,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -476,8 +476,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -506,13 +505,13 @@ main(int argc, char **argv) gkyl_moment_app_release(app); gkyl_free(gas_gamma_s); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_multiblock.c b/moments/creg/rt_euler_multiblock.c index a3be613f6d..f478370cce 100644 --- a/moments/creg/rt_euler_multiblock.c +++ b/moments/creg/rt_euler_multiblock.c @@ -40,22 +40,23 @@ struct skin_ghost_ranges { struct gkyl_range upper_ghost[2]; }; -void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +void skin_ghost_ranges_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { int ndim = parent->ndim; - - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } -struct gkyl_block_topo* -create_block_topo() +struct gkyl_block_topo *create_block_topo() { struct gkyl_block_topo *btopo = gkyl_block_topo_new(2, 3); @@ -69,60 +70,65 @@ create_block_topo() | | | +------+-----+ - */ + */ // block 0 - btopo->conn[0] = (struct gkyl_block_connections) { - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } // physical boundary - } - }; + btopo->conn[0] = (struct gkyl_block_connections + ){.connections[0] = + { + // x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = { + // y-direction connections + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }}; // block 1 - btopo->conn[1] = (struct gkyl_block_connections) { - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE } - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE } - } - }; + btopo->conn[1] = (struct gkyl_block_connections + ){.connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = {// y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }}; // block 2 - btopo->conn[2] = (struct gkyl_block_connections) { - .connections[0] = { // x-direction connections - { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } // physical boundary - } - }; + btopo->conn[2] = (struct gkyl_block_connections + ){.connections[0] = + { + // x-direction connections + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = { + // y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }}; return btopo; } -void -initFluidSod(double t, const double *xn, double* restrict fout, void *ctx) +void initFluidSod(double t, const double *xn, double *restrict fout, void *ctx) { double xsloc = 1.25, ysloc = 1.5; double x = xn[0], y = xn[1]; double rho = 0.125, pr = 0.1; - if (y>ysloc || x>xsloc) { + if (y > ysloc || x > xsloc) { rho = 1.0; pr = 1.0; } - + fout[0] = rho; - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; - fout[4] = pr/(gas_gamma-1); + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; + fout[4] = pr / (gas_gamma - 1); } // Block data and methods on individual blocks @@ -150,142 +156,148 @@ struct block_data { gkyl_wv_apply_bc *lower_bc[2], *upper_bc[2]; }; -void -block_bc_updaters_init(struct block_data *bdata, const struct gkyl_block_connections *conn) +void block_bc_updaters_init(struct block_data *bdata, const struct gkyl_block_connections *conn) { - int nghost[] = { 2, 2, 2 }; + int nghost[] = {2, 2, 2}; // create updaters for physical boundaries (at present, all assumed // to be solid walls) - for (int d=0; d<2; ++d) { - + for (int d = 0; d < 2; ++d) { bdata->lower_bc[d] = bdata->upper_bc[d] = 0; // create BC updater in dir 'd' on lower edge - if (conn->connections[d][0].edge == GKYL_PHYSICAL) - bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, - d, GKYL_LOWER_EDGE, nghost, bdata->euler->wall_bc_func, 0); + if (conn->connections[d][0].edge == GKYL_PHYSICAL) { + bdata->lower_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + bdata->euler->wall_bc_func, 0 + ); + } // create BC updater in dir 'd' on upper edge - if (conn->connections[d][1].edge == GKYL_PHYSICAL) - bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, - d, GKYL_UPPER_EDGE, nghost, bdata->euler->wall_bc_func, 0); + if (conn->connections[d][1].edge == GKYL_PHYSICAL) { + bdata->upper_bc[d] = gkyl_wv_apply_bc_new( + &bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + bdata->euler->wall_bc_func, 0 + ); + } } // create skin/ghost region skin_ghost_ranges_init(&bdata->skin_ghost, &bdata->ext_range, nghost); // allocate buffer for inter-block BCs long buff_sz = 0; - for (int d=0; d<2; ++d) { + for (int d = 0; d < 2; ++d) { long vol = bdata->skin_ghost.lower_skin[d].volume; buff_sz = buff_sz > vol ? buff_sz : vol; } bdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); } -void -block_bc_updaters_release(struct block_data *bdata) +void block_bc_updaters_release(struct block_data *bdata) { - for (int d=0; d<2; ++d) { - if (bdata->lower_bc[d]) + for (int d = 0; d < 2; ++d) { + if (bdata->lower_bc[d]) { gkyl_wv_apply_bc_release(bdata->lower_bc[d]); - if (bdata->upper_bc[d]) + } + if (bdata->upper_bc[d]) { gkyl_wv_apply_bc_release(bdata->upper_bc[d]); + } } gkyl_array_release(bdata->bc_buffer); } -void -block_bc_updaters_apply(const struct block_data *bdata, double tm, struct gkyl_array *fld) +void block_bc_updaters_apply(const struct block_data *bdata, double tm, struct gkyl_array *fld) { - for (int d=0; d<2; ++d) { - if (bdata->lower_bc[d]) + for (int d = 0; d < 2; ++d) { + if (bdata->lower_bc[d]) { gkyl_wv_apply_bc_advance(bdata->lower_bc[d], tm, &bdata->range, fld); - if (bdata->upper_bc[d]) + } + if (bdata->upper_bc[d]) { gkyl_wv_apply_bc_advance(bdata->upper_bc[d], tm, &bdata->range, fld); + } } } -void -sync_blocks(const struct gkyl_block_topo *btopo, const struct block_data bdata[], - struct gkyl_array *fld[]) +void sync_blocks( + const struct gkyl_block_topo *btopo, const struct block_data bdata[], struct gkyl_array *fld[] +) { - for (int i=0; inum_blocks; ++i) { - - for (int d=0; dndim; ++d) { + for (int i = 0; i < btopo->num_blocks; ++i) { + for (int d = 0; d < btopo->ndim; ++d) { const struct gkyl_target_edge *te = btopo->conn[i].connections[d]; // lower-edge if (te[0].edge != GKYL_PHYSICAL) { - struct gkyl_array *bc_buffer = bdata[i].bc_buffer; - + // copy skin-cell data to buffer - gkyl_array_copy_to_buffer( - bc_buffer->data, fld[i], &(bdata[i].skin_ghost.lower_skin[d])); + gkyl_array_copy_to_buffer(bc_buffer->data, fld[i], &(bdata[i].skin_ghost.lower_skin[d])); int tbid = te[0].bid, tdir = te[0].dir; - - // copy buffer to ghost-cells of target block + + // copy buffer to ghost-cells of target block switch (te[0].edge) { - case GKYL_LOWER_POSITIVE: - case GKYL_LOWER_NEGATIVE: - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - break; - - case GKYL_UPPER_POSITIVE: - case GKYL_UPPER_NEGATIVE: - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - break; - - default: - ; + case GKYL_LOWER_POSITIVE: + case GKYL_LOWER_NEGATIVE: + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + break; + + case GKYL_UPPER_POSITIVE: + case GKYL_UPPER_NEGATIVE: + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + break; + + default:; } } // upper-edge if (te[1].edge != GKYL_PHYSICAL) { - struct gkyl_array *bc_buffer = bdata[i].bc_buffer; - + // copy skin-cell data to buffer - gkyl_array_copy_to_buffer( - bc_buffer->data, fld[i], &(bdata[i].skin_ghost.upper_skin[d])); + gkyl_array_copy_to_buffer(bc_buffer->data, fld[i], &(bdata[i].skin_ghost.upper_skin[d])); int tbid = te[1].bid, tdir = te[1].dir; - - // copy buffer to ghost-cells of target block + + // copy buffer to ghost-cells of target block switch (te[1].edge) { - case GKYL_LOWER_POSITIVE: - case GKYL_LOWER_NEGATIVE: - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - break; - - case GKYL_UPPER_POSITIVE: - case GKYL_UPPER_NEGATIVE: - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - break; - - default: - ; + case GKYL_LOWER_POSITIVE: + case GKYL_LOWER_NEGATIVE: + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir]) + ); + break; + + case GKYL_UPPER_POSITIVE: + case GKYL_UPPER_NEGATIVE: + gkyl_array_copy_from_buffer( + fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir]) + ); + break; + + default:; } - } + } } } } -void -block_data_write(const char *fileNm, const struct block_data *bdata) -{ +void block_data_write(const char *fileNm, const struct block_data *bdata) +{ gkyl_grid_sub_array_write(&bdata->grid, &bdata->range, 0, bdata->f[0], fileNm); } -double -block_data_max_dt(const struct block_data *bdata) +double block_data_max_dt(const struct block_data *bdata) { double dt = DBL_MAX; - for (int d=0; d<2; ++d) + for (int d = 0; d < 2; ++d) { dt = fmin(dt, gkyl_wave_prop_max_dt(bdata->slvr[d], &bdata->range, bdata->f[0])); + } return dt; } @@ -298,8 +310,7 @@ struct update_block_ctx { struct gkyl_wave_prop_status stat; // status of wave propagation (on output) }; -void -update_block_job_func(void *ctx) +void update_block_job_func(void *ctx) { struct update_block_ctx *ubctx = ctx; int d = ubctx->dir; @@ -307,60 +318,52 @@ update_block_job_func(void *ctx) const struct block_data *bdata = ubctx->bdata; // run wave-prop updater - ubctx->stat = gkyl_wave_prop_advance(bdata->slvr[d], tcurr, dt, - &bdata->range, NULL, bdata->f[d], bdata->f[d+1]); + ubctx->stat = gkyl_wave_prop_advance( + bdata->slvr[d], tcurr, dt, &bdata->range, NULL, bdata->f[d], bdata->f[d + 1] + ); // apply block-local boundary conditions - block_bc_updaters_apply(bdata, tcurr, bdata->f[d+1]); + block_bc_updaters_apply(bdata, tcurr, bdata->f[d + 1]); } -struct gkyl_update_status -update_all_blocks(const struct gkyl_job_pool *job_pool, - const struct gkyl_block_topo *btopo, const struct block_data bdata[], double tcurr, double dt) +struct gkyl_update_status update_all_blocks( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct block_data bdata[], double tcurr, double dt +) { int num_blocks = btopo->num_blocks; double dt_suggested = DBL_MAX; - - for (int d=0; d<2; ++d) { - + for (int d = 0; d < 2; ++d) { // initialize block ctx data struct update_block_ctx block_ctx[num_blocks]; - for (int i=0; ifv_proj, 0.0, &bdata->ext_range, bdata->f[0]); @@ -380,143 +382,123 @@ struct copy_job_ctx { const struct gkyl_array *inp; struct gkyl_array *out; }; -void -copy_job_func(void *ctx) +void copy_job_func(void *ctx) { struct copy_job_ctx *jctx = ctx; //printf("Inside copy_job_func with index %d\n", jctx->bidx); gkyl_array_copy(jctx->out, jctx->inp); } - // function that takes a time-step -struct gkyl_update_status -update(const struct gkyl_job_pool *job_pool, - const struct gkyl_block_topo *btopo, const struct block_data bdata[], - double tcurr, double dt0, struct sim_stats *stats) +struct gkyl_update_status update( + const struct gkyl_job_pool *job_pool, const struct gkyl_block_topo *btopo, + const struct block_data bdata[], double tcurr, double dt0, struct sim_stats *stats +) { int num_blocks = btopo->num_blocks; double dt_suggested = DBL_MAX; - + // time-stepper states - enum { - UPDATE_DONE = 0, - PRE_UPDATE, - POST_UPDATE, - FLUID_UPDATE, - UPDATE_REDO, - } state = PRE_UPDATE; + enum { UPDATE_DONE = 0, PRE_UPDATE, POST_UPDATE, FLUID_UPDATE, UPDATE_REDO } state = PRE_UPDATE; struct copy_job_ctx copy_ctx[num_blocks]; double dt = dt0; while (state != UPDATE_DONE) { switch (state) { - case PRE_UPDATE: - state = FLUID_UPDATE; // next state - - // copy old solution in case we need to redo this step - - // create context objects ... - for (int i=0; infail += 1; - dt = s.dt_suggested; - state = UPDATE_REDO; - break; - } - dt_suggested = fmin(dt_suggested, s.dt_suggested); + // copy old solution in case we need to redo this step - break; + // create context objects ... + for (int i = 0; i < num_blocks; ++i) { + copy_ctx[i] = (struct copy_job_ctx){.bidx = i, .inp = bdata[i].f[0], .out = bdata[i].fdup}; + } - case POST_UPDATE: - state = UPDATE_DONE; - - // copy solution in prep for next time-step - - for (int i=0; infail += 1; + dt = s.dt_suggested; + state = UPDATE_REDO; break; + } + dt_suggested = fmin(dt_suggested, s.dt_suggested); + + break; + + case POST_UPDATE: + state = UPDATE_DONE; + + // copy solution in prep for next time-step + + for (int i = 0; i < num_blocks; ++i) { + copy_ctx[i] = (struct copy_job_ctx){.bidx = i, .inp = bdata[i].f[2], .out = bdata[i].f[0]}; + } + + for (int i = 0; i < num_blocks; ++i) { + gkyl_job_pool_add_work(job_pool, copy_job_func, ©_ctx[i]); + } + gkyl_job_pool_wait(job_pool); + + break; + + case UPDATE_REDO: + state = PRE_UPDATE; // start all-over again + + // restore solution and retake step + + for (int i = 0; i < num_blocks; ++i) { + copy_ctx[i] = (struct copy_job_ctx){.bidx = i, .inp = bdata[i].fdup, .out = bdata[i].f[0]}; + } + + for (int i = 0; i < num_blocks; ++i) { + gkyl_job_pool_add_work(job_pool, copy_job_func, ©_ctx[i]); + } + gkyl_job_pool_wait(job_pool); + + break; + + case UPDATE_DONE: // unreachable code! (suppresses warning) + break; } } - return (struct gkyl_update_status) { - .success = 1, - .dt_actual = dt, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_update_status){.success = 1, .dt_actual = dt, .dt_suggested = dt_suggested}; } -void -write_sol(const char *fbase, int num_blocks, const struct block_data bdata[]) -{ - for (int i=0; iconn[i]); + } // allocate fields - for (int i=0; i -struct noh_1d_ctx -{ +struct noh_1d_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -49,8 +48,7 @@ struct noh_1d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct noh_1d_ctx -create_ctx(void) +struct noh_1d_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -91,14 +89,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct noh_1d_ctx *app = ctx; @@ -121,8 +118,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -136,13 +132,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -156,24 +153,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -198,11 +196,11 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -212,7 +210,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -220,8 +218,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -235,22 +232,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -274,20 +261,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -301,10 +284,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -313,26 +300,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -348,7 +340,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -363,8 +355,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -372,7 +363,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -380,8 +373,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -407,14 +399,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_p_perturbation.c b/moments/creg/rt_euler_p_perturbation.c index 71975611fb..7bf02ec6dd 100644 --- a/moments/creg/rt_euler_p_perturbation.c +++ b/moments/creg/rt_euler_p_perturbation.c @@ -17,8 +17,7 @@ #include -struct p_perturbation_ctx -{ +struct p_perturbation_ctx { // Mathematical constants (dimensionless). double pi; @@ -40,8 +39,7 @@ struct p_perturbation_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct p_perturbation_ctx -create_ctx(void) +struct p_perturbation_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -75,14 +73,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct p_perturbation_ctx *app = ctx; @@ -101,13 +98,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -121,24 +119,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -163,9 +162,9 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -175,7 +174,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -183,8 +182,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -198,22 +196,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -237,23 +225,19 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -267,10 +251,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -279,26 +267,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -314,7 +307,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -329,8 +322,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -338,7 +330,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -346,8 +340,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -373,14 +366,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_reflect_2d.c b/moments/creg/rt_euler_reflect_2d.c index 01bf90ae70..ea663113fb 100644 --- a/moments/creg/rt_euler_reflect_2d.c +++ b/moments/creg/rt_euler_reflect_2d.c @@ -17,8 +17,7 @@ #include -struct reflect_2d_ctx -{ +struct reflect_2d_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic idex. @@ -40,8 +39,7 @@ struct reflect_2d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct reflect_2d_ctx -create_ctx(void) +struct reflect_2d_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -77,14 +75,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct reflect_2d_ctx *app = ctx; @@ -93,7 +90,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double rho0 = app->rho0; double beta = app->beta; - + double Lx = app->Lx; double Ly = app->Ly; @@ -111,13 +108,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -131,24 +129,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -174,12 +173,12 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcx = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT}, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; int nrank = 1; // Number of processes in simulation. @@ -189,7 +188,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -197,8 +196,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -212,22 +210,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -251,20 +239,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -278,10 +263,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -290,26 +279,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -325,7 +319,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -340,8 +334,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -349,7 +342,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -357,8 +352,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -384,14 +378,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_rgfm_fedkiw_shock.c b/moments/creg/rt_euler_rgfm_fedkiw_shock.c index 8ba0e6bbc0..799e8709fb 100644 --- a/moments/creg/rt_euler_rgfm_fedkiw_shock.c +++ b/moments/creg/rt_euler_rgfm_fedkiw_shock.c @@ -17,8 +17,7 @@ #include -struct fedkiw_shock_ctx -{ +struct fedkiw_shock_ctx { // Physical constants (using normalized code units). double gas_gamma1; // First species adiabatic index. double gas_gamma2; // Second species adiabatic index. @@ -52,8 +51,7 @@ struct fedkiw_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct fedkiw_shock_ctx -create_ctx(void) +struct fedkiw_shock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma1 = 1.4; // First species adiabatic index. @@ -111,14 +109,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerRGFMInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerRGFMInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct fedkiw_shock_ctx *app = ctx; @@ -157,16 +156,14 @@ evalEulerRGFMInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC vx_total = ul; // Total fluid velocity (left). p_total = pl; // Total fluid pressure (left). - } - else if (x < 0.5) { + } else if (x < 0.5) { rho1 = rhoc; // First species fluid mass density (central). rho2 = rhor; // Second species fluid mass density (right). phi1 = phi1_c; // First species level set value (central). vx_total = uc; // Total fluid velocity (central). p_total = pc; // Total fluid pressure (central). - } - else { + } else { rho1 = rhoc; // First species fluid mass density (central). rho2 = rhor; // Second species fluid mass density (right). phi1 = phi1_r; // First species level set value (right). @@ -180,8 +177,10 @@ evalEulerRGFMInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double momy_total = rho_total * vy_total; // Total fluid momentum density (y-direction). double momz_total = rho_total * vz_total; // Total fluid momentum density (z-direction). - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. + double E1 = (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. + double E2 = (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. double E_total = (phi1 * E1) + ((1.0 - phi1) * E2); // Total fluid energy. double level_set1 = rho_total * phi1; // Conserved level set value (first species). @@ -191,19 +190,21 @@ evalEulerRGFMInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC // Set total fluid mass density. fout[0] = rho_total; // Set total fluid momentum density. - fout[1] = momx_total; fout[2] = momy_total; fout[3] = momz_total; + fout[1] = momx_total; + fout[2] = momy_total; + fout[3] = momz_total; // Set total flud energy density. fout[4] = E_total; // Set conserved level set value (first species). fout[5] = level_set1; // Set conserved mass densities (first and second species). - fout[6] = mass_frac1; fout[7] = mass_frac2; + fout[6] = mass_frac1; + fout[7] = mass_frac2; // Set reinitialization parameter (for level set). fout[8] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -217,24 +218,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -257,16 +259,17 @@ main(int argc, char **argv) double *gas_gamma_s = gkyl_malloc(sizeof(double[2])); gas_gamma_s[0] = ctx.gas_gamma1; gas_gamma_s[1] = ctx.gas_gamma2; - struct gkyl_wv_eqn *euler_rgfm = gkyl_wv_euler_rgfm_new(2, gas_gamma_s, ctx.reinit_freq, app_args.use_gpu); + struct gkyl_wv_eqn *euler_rgfm = + gkyl_wv_euler_rgfm_new(2, gas_gamma_s, ctx.reinit_freq, app_args.use_gpu); struct gkyl_moment_species fluid = { .name = "euler_rgfm", .equation = euler_rgfm, - + .init = evalEulerRGFMInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -277,7 +280,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -285,8 +288,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -300,22 +302,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -339,20 +331,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -366,10 +354,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -378,26 +370,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -413,7 +410,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -428,8 +425,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -437,7 +433,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -445,8 +443,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -475,13 +472,13 @@ main(int argc, char **argv) gkyl_moment_app_release(app); gkyl_free(gas_gamma_s); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_rgfm_shock_bubble.c b/moments/creg/rt_euler_rgfm_shock_bubble.c index 275789d90c..75e724ba8f 100644 --- a/moments/creg/rt_euler_rgfm_shock_bubble.c +++ b/moments/creg/rt_euler_rgfm_shock_bubble.c @@ -17,8 +17,7 @@ #include -struct shock_bubble_ctx -{ +struct shock_bubble_ctx { // Physical constants (using normalized code units). double gas_gamma1; // First species adiabatic index. double gas_gamma2; // Second species adiabatic index. @@ -61,8 +60,7 @@ struct shock_bubble_ctx double bub_rad; // Bubble radius. }; -struct shock_bubble_ctx -create_ctx(void) +struct shock_bubble_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma1 = 1.4; // First species adiabatic index. @@ -135,14 +133,15 @@ create_ctx(void) .x_loc = x_loc, .bub_loc_x = bub_loc_x, .bub_loc_y = bub_loc_y, - .bub_rad = bub_rad, + .bub_rad = bub_rad }; return ctx; } -void -evalEulerRGFMInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerRGFMInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct shock_bubble_ctx *app = ctx; @@ -189,8 +188,7 @@ evalEulerRGFMInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC vx_total = u_post; // Total fluid velocity (post-shock). p_total = p_post; // Total fluid pressure (post-shock). - } - else { + } else { rho1 = rho_pre; // First species fluid mass density (pre-shock). rho2 = rho_bub; // Second species fluid mass density (bubble). phi1 = phi1_pre; // First species level set value (pre-shock). @@ -214,8 +212,10 @@ evalEulerRGFMInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double momy_total = rho_total * vy_total; // Total fluid momentum density (y-direction). double momz_total = rho_total * vz_total; // Total fluid momentum density (z-direction). - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. + double E1 = (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * (vx_total * vx_total)); // First species total energy. + double E2 = (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * (vx_total * vx_total)); // Second species total energy. double E_total = (phi1 * E1) + ((1.0 - phi1) * E2); // Total fluid energy. double level_set1 = rho_total * phi1; // Conserved level set value (first species). @@ -225,19 +225,21 @@ evalEulerRGFMInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC // Set total fluid mass density. fout[0] = rho_total; // Set total fluid momentum density. - fout[1] = momx_total; fout[2] = momy_total; fout[3] = momz_total; + fout[1] = momx_total; + fout[2] = momy_total; + fout[3] = momz_total; // Set total fluid energy density. fout[4] = E_total; // Set conserved level set value (first species). fout[5] = level_set1; // Set conserved mass densities (first and second species). - fout[6] = mass_frac1; fout[7] = mass_frac2; + fout[6] = mass_frac1; + fout[7] = mass_frac2; // Set reinitialization parameter (for level set). fout[8] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -251,24 +253,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -292,17 +295,18 @@ main(int argc, char **argv) double *gas_gamma_s = gkyl_malloc(sizeof(double[2])); gas_gamma_s[0] = ctx.gas_gamma1; gas_gamma_s[1] = ctx.gas_gamma2; - struct gkyl_wv_eqn *euler_rgfm = gkyl_wv_euler_rgfm_new(2, gas_gamma_s, ctx.reinit_freq, app_args.use_gpu); + struct gkyl_wv_eqn *euler_rgfm = + gkyl_wv_euler_rgfm_new(2, gas_gamma_s, ctx.reinit_freq, app_args.use_gpu); struct gkyl_moment_species fluid = { .name = "euler_rgfm", .equation = euler_rgfm, - + .init = evalEulerRGFMInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; int nrank = 1; // Number of processes in simulation. @@ -313,7 +317,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -321,8 +325,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -336,22 +339,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -375,20 +368,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -402,10 +392,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -414,26 +408,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -449,7 +448,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -464,8 +463,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -473,7 +471,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -481,8 +481,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -511,13 +510,13 @@ main(int argc, char **argv) gkyl_moment_app_release(app); gkyl_free(gas_gamma_s); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_riem_2d_hll.c b/moments/creg/rt_euler_riem_2d_hll.c index 43775cab54..18ad7f4c99 100644 --- a/moments/creg/rt_euler_riem_2d_hll.c +++ b/moments/creg/rt_euler_riem_2d_hll.c @@ -23,8 +23,7 @@ #include -struct euler_riem_2d_hll_ctx -{ +struct euler_riem_2d_hll_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -37,7 +36,7 @@ struct euler_riem_2d_hll_ctx double u_ur; // Upper right fluid x-velocity. double v_ur; // Upper right fluid y-velocity. double p_ur; // Upper left fluid pressure. - + double rho_ll; // Lower left fluid mass density. double u_ll; // Lower left fluid x-velocity. double v_ll; // Lower left fluid y-velocity. @@ -65,8 +64,7 @@ struct euler_riem_2d_hll_ctx double loc; // Fluid boundaries (both x and y coordinates). }; -struct euler_riem_2d_hll_ctx -create_ctx(void) +struct euler_riem_2d_hll_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -80,7 +78,7 @@ create_ctx(void) double u_ur = 0.0; // Upper-right fluid x-velocity. double v_ur = 0.0; // Upper-right fluid y-velocity. double p_ur = 1.5; // Upper-right fluid pressure. - + double rho_ll = 0.138; // Lower-left fluid mass density. double u_ll = 1.206; // Lower-left fluid x-velocity. double v_ll = 1.206; // Lower-left fluid y-velocity. @@ -136,14 +134,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .loc = loc, + .loc = loc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct euler_riem_2d_hll_ctx *app = ctx; @@ -183,44 +180,43 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo u = u_ul; // Fluid x-velocity (upper-left). v = v_ul; // Fluid y-velocity (upper-left). p = p_ul; // Fluid pressure (upper-left). - } - else { + } else { rho = rho_ur; // Fluid mass density (upper-right). u = u_ur; // Fluid x-velocity (upper-right). v = v_ur; // Fluid y-velocity (upper-right). p = p_ur; // Fluid pressure (upper-right). } - } - else { + } else { if (x < loc) { rho = rho_ll; // Fluid mass density (lower-left). u = u_ll; // Fluid x-velocity (lower-left). v = v_ll; // Fluid y-velocity (lower-left). p = p_ll; // Fluid pressure (lower-left). - } - else { + } else { rho = rho_lr; // Fluid mass density (lower-right). u = u_lr; // Fluid x-velocity (lower-right). v = v_lr; // Fluid y-velocity (lower-right). p = p_lr; // Fluid pressure (lower-right). } } - + double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = rho * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. - + double Etot = + (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -234,24 +230,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -272,20 +269,15 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew( - &(struct gkyl_wv_euler_inp) { - .gas_gamma = ctx.gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, - } - ); + struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew(&(struct gkyl_wv_euler_inp + ){.gas_gamma = ctx.gas_gamma, .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu}); struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -295,7 +287,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -303,8 +295,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -318,22 +309,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -352,14 +333,14 @@ main(int argc, char **argv) } goto mpifinalize; } - + // Moment app. struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -367,13 +348,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -387,10 +365,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -399,26 +381,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -434,7 +421,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -449,8 +436,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -458,7 +444,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -466,8 +454,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -493,8 +480,8 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_euler_riem_2d_hllc.c b/moments/creg/rt_euler_riem_2d_hllc.c index d3cad3cbd4..6180413686 100644 --- a/moments/creg/rt_euler_riem_2d_hllc.c +++ b/moments/creg/rt_euler_riem_2d_hllc.c @@ -23,8 +23,7 @@ #include -struct euler_riem_2d_hllc_ctx -{ +struct euler_riem_2d_hllc_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -37,7 +36,7 @@ struct euler_riem_2d_hllc_ctx double u_ur; // Upper right fluid x-velocity. double v_ur; // Upper right fluid y-velocity. double p_ur; // Upper left fluid pressure. - + double rho_ll; // Lower left fluid mass density. double u_ll; // Lower left fluid x-velocity. double v_ll; // Lower left fluid y-velocity. @@ -65,8 +64,7 @@ struct euler_riem_2d_hllc_ctx double loc; // Fluid boundaries (both x and y coordinates). }; -struct euler_riem_2d_hllc_ctx -create_ctx(void) +struct euler_riem_2d_hllc_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -80,7 +78,7 @@ create_ctx(void) double u_ur = 0.0; // Upper-right fluid x-velocity. double v_ur = 0.0; // Upper-right fluid y-velocity. double p_ur = 1.5; // Upper-right fluid pressure. - + double rho_ll = 0.138; // Lower-left fluid mass density. double u_ll = 1.206; // Lower-left fluid x-velocity. double v_ll = 1.206; // Lower-left fluid y-velocity. @@ -136,14 +134,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .loc = loc, + .loc = loc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct euler_riem_2d_hllc_ctx *app = ctx; @@ -183,44 +180,43 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo u = u_ul; // Fluid x-velocity (upper-left). v = v_ul; // Fluid y-velocity (upper-left). p = p_ul; // Fluid pressure (upper-left). - } - else { + } else { rho = rho_ur; // Fluid mass density (upper-right). u = u_ur; // Fluid x-velocity (upper-right). v = v_ur; // Fluid y-velocity (upper-right). p = p_ur; // Fluid pressure (upper-right). } - } - else { + } else { if (x < loc) { rho = rho_ll; // Fluid mass density (lower-left). u = u_ll; // Fluid x-velocity (lower-left). v = v_ll; // Fluid y-velocity (lower-left). p = p_ll; // Fluid pressure (lower-left). - } - else { + } else { rho = rho_lr; // Fluid mass density (lower-right). u = u_lr; // Fluid x-velocity (lower-right). v = v_lr; // Fluid y-velocity (lower-right). p = p_lr; // Fluid pressure (lower-right). } } - + double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = rho * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. - + double Etot = + (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -234,24 +230,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -272,20 +269,15 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew( - &(struct gkyl_wv_euler_inp) { - .gas_gamma = ctx.gas_gamma, - .rp_type = WV_EULER_RP_HLLC, - .use_gpu = app_args.use_gpu, - } - ); + struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew(&(struct gkyl_wv_euler_inp + ){.gas_gamma = ctx.gas_gamma, .rp_type = WV_EULER_RP_HLLC, .use_gpu = app_args.use_gpu}); struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -295,7 +287,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -303,8 +295,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -318,22 +309,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -352,14 +333,14 @@ main(int argc, char **argv) } goto mpifinalize; } - + // Moment app. struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -367,13 +348,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -387,10 +365,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -399,26 +381,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -436,7 +423,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); gkyl_moment_app_calc_integrated_mom(app, t_curr); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -451,8 +438,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -460,7 +446,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -468,8 +456,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -495,8 +482,8 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_euler_riem_2d_lax.c b/moments/creg/rt_euler_riem_2d_lax.c index 88a2b99c2f..944e839649 100644 --- a/moments/creg/rt_euler_riem_2d_lax.c +++ b/moments/creg/rt_euler_riem_2d_lax.c @@ -23,8 +23,7 @@ #include -struct euler_riem_2d_lax_ctx -{ +struct euler_riem_2d_lax_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -37,7 +36,7 @@ struct euler_riem_2d_lax_ctx double u_ur; // Upper right fluid x-velocity. double v_ur; // Upper right fluid y-velocity. double p_ur; // Upper left fluid pressure. - + double rho_ll; // Lower left fluid mass density. double u_ll; // Lower left fluid x-velocity. double v_ll; // Lower left fluid y-velocity. @@ -65,8 +64,7 @@ struct euler_riem_2d_lax_ctx double loc; // Fluid boundaries (both x and y coordinates). }; -struct euler_riem_2d_lax_ctx -create_ctx(void) +struct euler_riem_2d_lax_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -80,7 +78,7 @@ create_ctx(void) double u_ur = 0.0; // Upper-right fluid x-velocity. double v_ur = 0.0; // Upper-right fluid y-velocity. double p_ur = 1.5; // Upper-right fluid pressure. - + double rho_ll = 0.138; // Lower-left fluid mass density. double u_ll = 1.206; // Lower-left fluid x-velocity. double v_ll = 1.206; // Lower-left fluid y-velocity. @@ -136,14 +134,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .loc = loc, + .loc = loc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct euler_riem_2d_lax_ctx *app = ctx; @@ -183,44 +180,43 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo u = u_ul; // Fluid x-velocity (upper-left). v = v_ul; // Fluid y-velocity (upper-left). p = p_ul; // Fluid pressure (upper-left). - } - else { + } else { rho = rho_ur; // Fluid mass density (upper-right). u = u_ur; // Fluid x-velocity (upper-right). v = v_ur; // Fluid y-velocity (upper-right). p = p_ur; // Fluid pressure (upper-right). } - } - else { + } else { if (x < loc) { rho = rho_ll; // Fluid mass density (lower-left). u = u_ll; // Fluid x-velocity (lower-left). v = v_ll; // Fluid y-velocity (lower-left). p = p_ll; // Fluid pressure (lower-left). - } - else { + } else { rho = rho_lr; // Fluid mass density (lower-right). u = u_lr; // Fluid x-velocity (lower-right). v = v_lr; // Fluid y-velocity (lower-right). p = p_lr; // Fluid pressure (lower-right). } } - + double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = rho * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. - + double Etot = + (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -234,24 +230,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -272,20 +269,15 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew( - &(struct gkyl_wv_euler_inp) { - .gas_gamma = ctx.gas_gamma, - .rp_type = WV_EULER_RP_LAX, - .use_gpu = app_args.use_gpu, - } - ); + struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew(&(struct gkyl_wv_euler_inp + ){.gas_gamma = ctx.gas_gamma, .rp_type = WV_EULER_RP_LAX, .use_gpu = app_args.use_gpu}); struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -295,7 +287,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -303,8 +295,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -318,22 +309,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -352,14 +333,14 @@ main(int argc, char **argv) } goto mpifinalize; } - + // Moment app. struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -367,13 +348,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -387,10 +365,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -399,26 +381,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -434,7 +421,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -449,8 +436,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -458,7 +444,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -466,8 +454,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -493,8 +480,8 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_euler_riem_2d_roe.c b/moments/creg/rt_euler_riem_2d_roe.c index 805902fc2b..3b35dea727 100644 --- a/moments/creg/rt_euler_riem_2d_roe.c +++ b/moments/creg/rt_euler_riem_2d_roe.c @@ -23,8 +23,7 @@ #include -struct euler_riem_2d_roe_ctx -{ +struct euler_riem_2d_roe_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -37,7 +36,7 @@ struct euler_riem_2d_roe_ctx double u_ur; // Upper right fluid x-velocity. double v_ur; // Upper right fluid y-velocity. double p_ur; // Upper left fluid pressure. - + double rho_ll; // Lower left fluid mass density. double u_ll; // Lower left fluid x-velocity. double v_ll; // Lower left fluid y-velocity. @@ -65,8 +64,7 @@ struct euler_riem_2d_roe_ctx double loc; // Fluid boundaries (both x and y coordinates). }; -struct euler_riem_2d_roe_ctx -create_ctx(void) +struct euler_riem_2d_roe_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -80,7 +78,7 @@ create_ctx(void) double u_ur = 0.0; // Upper-right fluid x-velocity. double v_ur = 0.0; // Upper-right fluid y-velocity. double p_ur = 1.5; // Upper-right fluid pressure. - + double rho_ll = 0.138; // Lower-left fluid mass density. double u_ll = 1.206; // Lower-left fluid x-velocity. double v_ll = 1.206; // Lower-left fluid y-velocity. @@ -136,14 +134,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .loc = loc, + .loc = loc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct euler_riem_2d_roe_ctx *app = ctx; @@ -183,22 +180,19 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo u = u_ul; // Fluid x-velocity (upper-left). v = v_ul; // Fluid y-velocity (upper-left). p = p_ul; // Fluid pressure (upper-left). - } - else { + } else { rho = rho_ur; // Fluid mass density (upper-right). u = u_ur; // Fluid x-velocity (upper-right). v = v_ur; // Fluid y-velocity (upper-right). p = p_ur; // Fluid pressure (upper-right). } - } - else { + } else { if (x < loc) { rho = rho_ll; // Fluid mass density (lower-left). u = u_ll; // Fluid x-velocity (lower-left). v = v_ll; // Fluid y-velocity (lower-left). p = p_ll; // Fluid pressure (lower-left). - } - else { + } else { rho = rho_lr; // Fluid mass density (lower-right). u = u_lr; // Fluid x-velocity (lower-right). v = v_lr; // Fluid y-velocity (lower-right). @@ -209,18 +203,20 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = rho * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. - + double Etot = + (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -234,24 +230,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -272,20 +269,15 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew( - &(struct gkyl_wv_euler_inp) { - .gas_gamma = ctx.gas_gamma, - .rp_type = WV_EULER_RP_ROE, - .use_gpu = app_args.use_gpu, - } - ); + struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew(&(struct gkyl_wv_euler_inp + ){.gas_gamma = ctx.gas_gamma, .rp_type = WV_EULER_RP_ROE, .use_gpu = app_args.use_gpu}); struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -295,7 +287,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -303,8 +295,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -318,22 +309,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -352,14 +333,14 @@ main(int argc, char **argv) } goto mpifinalize; } - + // Moment app. struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -367,13 +348,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -387,10 +365,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -399,26 +381,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -434,7 +421,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -449,8 +436,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -458,7 +444,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -466,8 +454,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -493,8 +480,8 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_euler_riem_3d.c b/moments/creg/rt_euler_riem_3d.c index f227e8472a..8573ca951f 100644 --- a/moments/creg/rt_euler_riem_3d.c +++ b/moments/creg/rt_euler_riem_3d.c @@ -24,8 +24,7 @@ #include -struct euler_riem_3d_ctx -{ +struct euler_riem_3d_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -54,8 +53,7 @@ struct euler_riem_3d_ctx double rloc; // Fluid boundary (radial coordinate). }; -struct euler_riem_3d_ctx -create_ctx(void) +struct euler_riem_3d_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -103,14 +101,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .rloc = rloc, + .rloc = rloc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; struct euler_riem_3d_ctx *app = ctx; @@ -133,12 +130,11 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo if (r < rloc) { rho = rhol; // Fluid mass density (left/inner). p = pl; // Fluid pressure (left/inner). - } - else { + } else { rho = rhor; // Fluid mass density (right/outer). p = pr; // Fluid pressure (right/outer). } - + double mom_x = 0.0; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). @@ -147,13 +143,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -167,24 +164,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -211,13 +209,13 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcz = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcz = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; int nrank = 1; // Number of processes in simulation. @@ -227,7 +225,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY, NZ }; + int cells[] = {NX, NY, NZ}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -235,8 +233,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -250,22 +247,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -289,20 +276,19 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 3, - .lower = { 0.0, 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly, ctx.Lz }, - .cells = { NX, NY, NZ }, + .lower = {0.0, 0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly, ctx.Lz}, + .cells = {NX, NY, NZ}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1], app_args.cuts[2] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, + .cuts = {app_args.cuts[0], app_args.cuts[1], app_args.cuts[2]}, + .comm = comm} }; // Create app object. @@ -316,10 +302,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -328,26 +318,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -363,7 +358,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -378,8 +373,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -387,7 +381,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -395,8 +391,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -422,8 +417,8 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_euler_rt.c b/moments/creg/rt_euler_rt.c index 99e64917c4..5d87d8b09b 100644 --- a/moments/creg/rt_euler_rt.c +++ b/moments/creg/rt_euler_rt.c @@ -17,8 +17,7 @@ #include -struct rt_ctx -{ +struct rt_ctx { // Mathematical constants (dimensionless). double pi; @@ -47,8 +46,7 @@ struct rt_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct rt_ctx -create_ctx(void) +struct rt_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -62,7 +60,7 @@ create_ctx(void) double p_ref = 0.01; // Reference fluid pressure. double pert_max = 0.01; // Maximum amplitude of initial perturbation. - + // Simulation parameters. int Nx = 50; // Cell count (x-direction). int Ny = 200; // Cell count (y-direction). @@ -95,14 +93,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct rt_ctx *app = ctx; @@ -127,12 +124,11 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo if (y > yloc) { rho = rho_top; // Fluid mass density (top). p = rho_top * grav * (1.0 - y); // Fluid pressure (top). - } - else { + } else { rho = rho_bot; // Fluid mass density (bottom). p = (rho_top * grav * (1.0 - yloc)) + (rho_bot * grav * (yloc - y)); // Fluid pressure (bottom). } - + double mom_x = 0.0; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). @@ -141,13 +137,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -evalAppAccel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAppAccel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct rt_ctx *app = ctx; @@ -158,11 +155,12 @@ evalAppAccel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double accel_z = 0.0; // Applied acceleration (z-direction). // Set applied acceleration. - fout[0] = accel_x; fout[1] = accel_y; fout[2] = accel_z; + fout[0] = accel_x; + fout[1] = accel_y; + fout[2] = accel_z; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -176,24 +174,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -219,15 +218,15 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, .app_accel = evalAppAccel, .app_accel_ctx = &ctx, - .bcx = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcx = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT}, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; int nrank = 1; // Number of processes in simulation. @@ -237,7 +236,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -245,8 +244,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -260,22 +258,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -294,27 +282,24 @@ main(int argc, char **argv) } goto mpifinalize; } - + // Moment app. struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -328,10 +313,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -340,26 +329,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -375,7 +369,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -390,8 +384,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -399,7 +392,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -407,8 +402,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -429,13 +423,13 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Field updates took %g secs\n", stat.field_tm); gkyl_moment_app_cout(app, stdout, "Source updates took %g secs\n", stat.sources_tm); gkyl_moment_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); - + freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_euler_sodshock.c b/moments/creg/rt_euler_sodshock.c index 481234d7a5..06a7bf52f7 100644 --- a/moments/creg/rt_euler_sodshock.c +++ b/moments/creg/rt_euler_sodshock.c @@ -23,8 +23,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -49,8 +48,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -91,14 +89,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct sodshock_ctx *app = ctx; @@ -121,8 +118,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -136,13 +132,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -156,24 +153,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -198,11 +196,11 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -212,7 +210,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -220,8 +218,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -235,22 +232,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -274,20 +261,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.25 }, - .upper = { 0.25 + ctx.Lx }, - .cells = { NX }, + .lower = {0.25}, + .upper = {0.25 + ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -301,10 +284,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -313,26 +300,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -348,7 +340,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -363,8 +355,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -372,7 +363,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -380,8 +373,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -407,14 +399,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_sodshock_lax.c b/moments/creg/rt_euler_sodshock_lax.c index 2826128091..1db176f085 100644 --- a/moments/creg/rt_euler_sodshock_lax.c +++ b/moments/creg/rt_euler_sodshock_lax.c @@ -23,8 +23,7 @@ #include -struct sodshock_lax_ctx -{ +struct sodshock_lax_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -49,8 +48,7 @@ struct sodshock_lax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_lax_ctx -create_ctx(void) +struct sodshock_lax_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -91,14 +89,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct sodshock_lax_ctx *app = ctx; @@ -121,8 +118,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -136,13 +132,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -156,24 +153,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -198,12 +196,12 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -213,7 +211,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -221,8 +219,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -236,22 +233,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -275,20 +262,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.25 }, - .upper = { 0.25 + ctx.Lx }, - .cells = { NX }, + .lower = {0.25}, + .upper = {0.25 + ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -302,10 +285,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -314,26 +301,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -349,7 +341,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -364,8 +356,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -373,7 +364,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -381,8 +374,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -408,14 +400,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_sodshock_mp.c b/moments/creg/rt_euler_sodshock_mp.c index cba89eb0fd..fe57737d53 100644 --- a/moments/creg/rt_euler_sodshock_mp.c +++ b/moments/creg/rt_euler_sodshock_mp.c @@ -23,8 +23,7 @@ #include -struct sodshock_mp_ctx -{ +struct sodshock_mp_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -49,8 +48,7 @@ struct sodshock_mp_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_mp_ctx -create_ctx(void) +struct sodshock_mp_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -91,14 +89,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct sodshock_mp_ctx *app = ctx; @@ -121,8 +118,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -136,13 +132,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -156,24 +153,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -193,22 +191,17 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew( - &(struct gkyl_wv_euler_inp) { - .gas_gamma = ctx.gas_gamma, - .rp_type = WV_EULER_RP_LAX, - .use_gpu = app_args.use_gpu, - } - ); + struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew(&(struct gkyl_wv_euler_inp + ){.gas_gamma = ctx.gas_gamma, .rp_type = WV_EULER_RP_LAX, .use_gpu = app_args.use_gpu}); struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -218,7 +211,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -226,8 +219,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -241,22 +233,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -280,9 +262,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.25 }, - .upper = { 0.25 + ctx.Lx }, - .cells = { NX }, + .lower = {0.25}, + .upper = {0.25 + ctx.Lx}, + .cells = {NX}, .scheme_type = GKYL_MOMENT_MP, .mp_recon = app_args.mp_recon, @@ -290,13 +272,9 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -310,10 +288,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -322,26 +304,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -357,7 +344,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -372,8 +359,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -381,7 +367,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -389,8 +377,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -416,14 +403,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_superwedge.c b/moments/creg/rt_euler_superwedge.c index 9762e74b67..32c9e6a64a 100644 --- a/moments/creg/rt_euler_superwedge.c +++ b/moments/creg/rt_euler_superwedge.c @@ -17,8 +17,7 @@ #include -struct superwedge_ctx -{ +struct superwedge_ctx { // Mathematical constants (dimensionless). double pi; @@ -50,8 +49,7 @@ struct superwedge_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct superwedge_ctx -create_ctx(void) +struct superwedge_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -103,14 +101,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { double x = zc[0]; struct superwedge_ctx *app = ctx; @@ -128,13 +125,12 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo double rho = 0.0; double u = 0.0; double p = 0.0; - + if (x < -0.05) { rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -148,13 +144,15 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double x = zc[0], y = zc[1]; struct superwedge_ctx *app = ctx; @@ -174,8 +172,7 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* } } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -189,24 +186,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -216,7 +214,7 @@ main(int argc, char **argv) } #endif - if (app_args.trace_mem) { + if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } @@ -232,12 +230,12 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; int nrank = 1; // Number of processes in simulation. @@ -247,7 +245,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -255,8 +253,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -270,22 +267,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -309,23 +296,20 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.1, 0.0 }, - .upper = { -0.1 + ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.1, 0.0}, + .upper = {-0.1 + ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .mapc2p = mapc2p, .c2p_ctx = &ctx, - + .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -339,10 +323,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -351,26 +339,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -386,7 +379,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -401,8 +394,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -410,7 +402,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -418,8 +412,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -445,14 +438,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_vac.c b/moments/creg/rt_euler_vac.c index b2baab0972..2912a586e6 100644 --- a/moments/creg/rt_euler_vac.c +++ b/moments/creg/rt_euler_vac.c @@ -23,8 +23,7 @@ #include -struct euler_vac_ctx -{ +struct euler_vac_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -49,8 +48,7 @@ struct euler_vac_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct euler_vac_ctx -create_ctx(void) +struct euler_vac_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -91,14 +89,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct euler_vac_ctx *app = ctx; @@ -121,8 +118,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -136,13 +132,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -156,24 +153,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -198,11 +196,11 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -212,7 +210,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -220,8 +218,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -235,22 +232,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -274,20 +261,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -301,10 +284,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -313,26 +300,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -348,7 +340,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -363,8 +355,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -372,7 +363,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -380,8 +373,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -407,14 +399,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_vac_riem_1d.c b/moments/creg/rt_euler_vac_riem_1d.c index 1d664e21f7..d2cf2ce33f 100644 --- a/moments/creg/rt_euler_vac_riem_1d.c +++ b/moments/creg/rt_euler_vac_riem_1d.c @@ -23,8 +23,7 @@ #include -struct euler_vac_riem_ctx -{ +struct euler_vac_riem_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -49,8 +48,7 @@ struct euler_vac_riem_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct euler_vac_riem_ctx -create_ctx(void) +struct euler_vac_riem_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -91,14 +89,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct euler_vac_riem_ctx *app = ctx; @@ -121,8 +118,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -136,13 +132,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -156,24 +153,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -198,11 +196,11 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -212,7 +210,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -220,8 +218,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -235,22 +232,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -274,20 +261,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.25 }, - .upper = { 0.25 + ctx.Lx }, - .cells = { NX }, + .lower = {0.25}, + .upper = {0.25 + ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -301,10 +284,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -313,26 +300,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -348,7 +340,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -363,8 +355,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -372,7 +363,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -380,8 +373,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -407,14 +399,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_euler_wave_2d_kep.c b/moments/creg/rt_euler_wave_2d_kep.c index 8b022ce68a..844bec1e7a 100644 --- a/moments/creg/rt_euler_wave_2d_kep.c +++ b/moments/creg/rt_euler_wave_2d_kep.c @@ -24,10 +24,9 @@ #include -struct euler_wave_2d_kep_ctx -{ +struct euler_wave_2d_kep_ctx { // Mathematical constants (dimensionless). - double pi; + double pi; // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -51,8 +50,7 @@ struct euler_wave_2d_kep_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct euler_wave_2d_kep_ctx -create_ctx(void) +struct euler_wave_2d_kep_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -94,14 +92,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct euler_wave_2d_kep_ctx *app = ctx; @@ -118,18 +115,20 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = rho * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. + double Etot = + (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -143,24 +142,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -186,9 +186,9 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -198,7 +198,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -206,8 +206,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -221,22 +220,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -260,25 +249,22 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_KEP, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -292,10 +278,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -304,26 +294,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -339,7 +334,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -354,8 +349,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -363,7 +357,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -371,8 +367,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -398,8 +393,8 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_euler_wave_2d_mp.c b/moments/creg/rt_euler_wave_2d_mp.c index 843dcf0d18..6e132614fb 100644 --- a/moments/creg/rt_euler_wave_2d_mp.c +++ b/moments/creg/rt_euler_wave_2d_mp.c @@ -24,10 +24,9 @@ #include -struct euler_wave_2d_mp_ctx -{ +struct euler_wave_2d_mp_ctx { // Mathematical constants (dimensionless). - double pi; + double pi; // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -51,8 +50,7 @@ struct euler_wave_2d_mp_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct euler_wave_2d_mp_ctx -create_ctx(void) +struct euler_wave_2d_mp_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -94,14 +92,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct euler_wave_2d_mp_ctx *app = ctx; @@ -118,18 +115,20 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = rho * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. + double Etot = + (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -143,24 +142,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -186,9 +186,9 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -198,7 +198,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -206,8 +206,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -221,22 +220,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -260,9 +249,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_MP, .mp_recon = app_args.mp_recon, @@ -270,16 +259,13 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -293,10 +279,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -305,26 +295,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -340,7 +335,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -355,8 +350,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -364,7 +358,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -372,8 +368,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -399,8 +394,8 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_euler_wave_2d_wv.c b/moments/creg/rt_euler_wave_2d_wv.c index 0e6d4685ba..251436530a 100644 --- a/moments/creg/rt_euler_wave_2d_wv.c +++ b/moments/creg/rt_euler_wave_2d_wv.c @@ -24,10 +24,9 @@ #include -struct euler_wave_2d_ctx -{ +struct euler_wave_2d_ctx { // Mathematical constants (dimensionless). - double pi; + double pi; // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -51,8 +50,7 @@ struct euler_wave_2d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct euler_wave_2d_ctx -create_ctx(void) +struct euler_wave_2d_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -94,14 +92,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct euler_wave_2d_ctx *app = ctx; @@ -118,18 +115,20 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = rho * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. + double Etot = + (p / (gas_gamma - 1.0)) + (0.5 * rho * (u * u + v * v)); // Fluid total energy density. // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -143,24 +142,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -186,9 +186,9 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -198,7 +198,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -206,8 +206,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -221,22 +220,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -260,23 +249,20 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -290,10 +276,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -302,26 +292,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -337,7 +332,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -352,8 +347,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -361,7 +355,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -369,8 +365,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -396,8 +391,8 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_euler_wedge_sodshock.c b/moments/creg/rt_euler_wedge_sodshock.c index 11be2f42b5..bd118e9811 100644 --- a/moments/creg/rt_euler_wedge_sodshock.c +++ b/moments/creg/rt_euler_wedge_sodshock.c @@ -23,8 +23,7 @@ #include -struct wedge_sodshock_ctx -{ +struct wedge_sodshock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic idex. @@ -55,8 +54,7 @@ struct wedge_sodshock_ctx double rloc; // Fluid boundary (radial coordinate). }; -struct wedge_sodshock_ctx -create_ctx(void) +struct wedge_sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -107,14 +105,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .rloc = rloc, + .rloc = rloc }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { double r = zc[0]; struct wedge_sodshock_ctx *app = ctx; @@ -139,28 +136,29 @@ evalEulerInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left/inner). u = ul; // Fluid velocity (left/inner). p = pl; // Fluid pressure (left/inner). - } - else { + } else { rho = rhor; // Fluid mass density (right/outer). u = ur; // Fluid velocity (right/outer). p = pr; // Fluid pressure (right/outer). } - + double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * u * u); // Fluid total energy density. - + // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double r = zc[0], theta = zc[1]; @@ -169,8 +167,7 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* xp[1] = r * sin(theta); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -184,24 +181,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -227,12 +225,12 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_WEDGE, GKYL_SPECIES_WEDGE }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_WEDGE, GKYL_SPECIES_WEDGE} }; int nrank = 1; // Number of processes in simulation. @@ -242,7 +240,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NR, NTHETA }; + int cells[] = {NR, NTHETA}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -250,8 +248,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -265,22 +262,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -304,9 +291,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.25, -0.5 * ctx.Ltheta }, - .upper = { 0.25 + ctx.Lr, 0.5 * ctx.Ltheta }, - .cells = { NR, NTHETA }, + .lower = {0.25, -0.5 * ctx.Ltheta}, + .upper = {0.25 + ctx.Lr, 0.5 * ctx.Ltheta}, + .cells = {NR, NTHETA}, .mapc2p = mapc2p, .c2p_ctx = &ctx, @@ -314,13 +301,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -334,10 +318,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -346,26 +334,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -381,7 +374,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -396,8 +389,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -405,7 +397,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -413,8 +407,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -440,14 +433,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_bhl_spinning.c b/moments/creg/rt_gr_bhl_spinning.c index 4998998ae1..32c37e41cc 100644 --- a/moments/creg/rt_gr_bhl_spinning.c +++ b/moments/creg/rt_gr_bhl_spinning.c @@ -26,8 +26,7 @@ #include -struct bhl_spinning_ctx -{ +struct bhl_spinning_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -70,8 +69,7 @@ struct bhl_spinning_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_spinning_ctx -create_ctx(void) +struct bhl_spinning_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -93,7 +91,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -141,14 +140,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct bhl_spinning_ctx *app = ctx; @@ -178,36 +176,35 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -218,17 +215,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -242,68 +251,112 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = y; fout[70] = 0.0; + fout[68] = x; + fout[69] = y; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -332,8 +385,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -347,24 +399,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -385,12 +438,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler", .equation = gr_euler, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -398,8 +453,8 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -410,7 +465,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -418,8 +473,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -433,22 +487,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -472,9 +516,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -482,13 +526,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -502,10 +543,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -514,26 +559,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -549,7 +599,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -564,8 +614,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -573,7 +622,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -581,8 +632,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -609,14 +659,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_bhl_spinning_neutronstar.c b/moments/creg/rt_gr_bhl_spinning_neutronstar.c index bd50bdf9d6..212cbd6fe0 100644 --- a/moments/creg/rt_gr_bhl_spinning_neutronstar.c +++ b/moments/creg/rt_gr_bhl_spinning_neutronstar.c @@ -26,8 +26,7 @@ #include -struct bhl_spinning_ctx -{ +struct bhl_spinning_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -82,8 +81,7 @@ struct bhl_spinning_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_spinning_ctx -create_ctx(void) +struct bhl_spinning_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -109,15 +107,27 @@ create_ctx(void) double spin_dimensionless = ang_mom / (mass * mass); // Dimensionless spin of the neutron star. double alpha = 5.0; // Neutron star alpha parameter (mass quadrupole moment coefficient). - double beta = pow(-0.36 + (1.48 * pow(sqrt(alpha), 0.65)), 3.0); // Neutron star beta parameter (spin octupole moment coefficient). - double gamma = pow(-4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), 4.0); // Neutron star gamma parameter (mass hexadecapole moment coefficient). - - double mass_quadrupole = -alpha * (spin_dimensionless * spin_dimensionless) * (mass * mass * mass); // Neutron star mass quadrupole. - double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass); // Neutron star spin octupole. - double mass_hexadecapole = gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass * mass); // Neutron star mass hexadecapole. + double beta = pow( + -0.36 + (1.48 * pow(sqrt(alpha), 0.65)), + 3.0 + ); // Neutron star beta parameter (spin octupole moment coefficient). + double gamma = pow( + -4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), + 4.0 + ); // Neutron star gamma parameter (mass hexadecapole moment coefficient). + + double mass_quadrupole = -alpha * (spin_dimensionless * spin_dimensionless) * + (mass * mass * mass); // Neutron star mass quadrupole. + double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass); // Neutron star spin octupole. + double mass_hexadecapole = + gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass * mass); // Neutron star mass hexadecapole. // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -173,14 +183,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct bhl_spinning_ctx *app = ctx; @@ -210,36 +219,35 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -250,17 +258,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -274,68 +294,112 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = y; fout[70] = 0.0; + fout[68] = x; + fout[69] = y; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -364,8 +428,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -379,24 +442,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -417,12 +481,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler", .equation = gr_euler, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -430,8 +496,8 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -442,7 +508,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -450,8 +516,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -465,22 +530,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -504,9 +559,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -514,13 +569,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -534,10 +586,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -546,26 +602,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -581,7 +642,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -596,8 +657,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -605,7 +665,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -613,8 +675,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -641,14 +702,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_bhl_spinning_tetrad.c b/moments/creg/rt_gr_bhl_spinning_tetrad.c index 10cf6f576c..2b1b463fef 100644 --- a/moments/creg/rt_gr_bhl_spinning_tetrad.c +++ b/moments/creg/rt_gr_bhl_spinning_tetrad.c @@ -26,8 +26,7 @@ #include -struct bhl_spinning_ctx -{ +struct bhl_spinning_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -70,8 +69,7 @@ struct bhl_spinning_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_spinning_ctx -create_ctx(void) +struct bhl_spinning_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -93,7 +91,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -141,14 +140,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct bhl_spinning_ctx *app = ctx; @@ -178,36 +176,35 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -218,17 +215,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -242,68 +251,112 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = y; fout[70] = 0.0; + fout[68] = x; + fout[69] = y; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -332,8 +385,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -347,24 +399,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -385,12 +438,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler_tetrad", .equation = gr_euler_tetrad, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -398,8 +453,8 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -410,7 +465,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -418,8 +473,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -433,22 +487,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -472,9 +516,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -482,13 +526,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -502,10 +543,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -514,26 +559,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -549,7 +599,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -564,8 +614,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -573,7 +622,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -581,8 +632,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -609,14 +659,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_bhl_static.c b/moments/creg/rt_gr_bhl_static.c index ce1084bb4d..ebb93e6580 100644 --- a/moments/creg/rt_gr_bhl_static.c +++ b/moments/creg/rt_gr_bhl_static.c @@ -26,8 +26,7 @@ #include -struct bhl_static_ctx -{ +struct bhl_static_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -70,8 +69,7 @@ struct bhl_static_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_static_ctx -create_ctx(void) +struct bhl_static_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -93,7 +91,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -141,14 +140,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct bhl_static_ctx *app = ctx; @@ -178,36 +176,35 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -218,17 +215,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -242,68 +251,112 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = y; fout[70] = 0.0; + fout[68] = x; + fout[69] = y; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -332,8 +385,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -347,24 +399,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -385,12 +438,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler", .equation = gr_euler, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -398,8 +453,8 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -410,7 +465,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -418,8 +473,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -433,22 +487,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -472,9 +516,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -482,13 +526,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -502,10 +543,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -514,26 +559,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -549,7 +599,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -564,8 +614,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -573,7 +622,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -581,8 +632,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -609,14 +659,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_bhl_static_neutronstar.c b/moments/creg/rt_gr_bhl_static_neutronstar.c index 5d678f8b96..2c11fa5f14 100644 --- a/moments/creg/rt_gr_bhl_static_neutronstar.c +++ b/moments/creg/rt_gr_bhl_static_neutronstar.c @@ -26,8 +26,7 @@ #include -struct bhl_static_ctx -{ +struct bhl_static_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -82,8 +81,7 @@ struct bhl_static_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_static_ctx -create_ctx(void) +struct bhl_static_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -109,15 +107,27 @@ create_ctx(void) double spin_dimensionless = ang_mom / (mass * mass); // Dimensionless spin of the neutron star. double alpha = 5.0; // Neutron star alpha parameter (mass quadrupole moment coefficient). - double beta = pow(-0.36 + (1.48 * pow(sqrt(alpha), 0.65)), 3.0); // Neutron star beta parameter (spin octupole moment coefficient). - double gamma = pow(-4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), 4.0); // Neutron star gamma parameter (mass hexadecapole moment coefficient). - - double mass_quadrupole = -alpha * (spin_dimensionless * spin_dimensionless) * (mass * mass * mass); // Neutron star mass quadrupole. - double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass); // Neutron star spin octupole. - double mass_hexadecapole = gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass * mass); // Neutron star mass hexadecapole. + double beta = pow( + -0.36 + (1.48 * pow(sqrt(alpha), 0.65)), + 3.0 + ); // Neutron star beta parameter (spin octupole moment coefficient). + double gamma = pow( + -4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), + 4.0 + ); // Neutron star gamma parameter (mass hexadecapole moment coefficient). + + double mass_quadrupole = -alpha * (spin_dimensionless * spin_dimensionless) * + (mass * mass * mass); // Neutron star mass quadrupole. + double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass); // Neutron star spin octupole. + double mass_hexadecapole = + gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass * mass); // Neutron star mass hexadecapole. // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -173,14 +183,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct bhl_static_ctx *app = ctx; @@ -210,36 +219,35 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -250,17 +258,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -274,68 +294,112 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = y; fout[70] = 0.0; + fout[68] = x; + fout[69] = y; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -364,8 +428,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -379,24 +442,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -417,12 +481,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler", .equation = gr_euler, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -430,8 +496,8 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -442,7 +508,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -450,8 +516,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -465,22 +530,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -504,9 +559,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -514,13 +569,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -534,10 +586,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -546,26 +602,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -581,7 +642,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -596,8 +657,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -605,7 +665,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -613,8 +675,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -641,14 +702,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_bhl_static_tetrad.c b/moments/creg/rt_gr_bhl_static_tetrad.c index edbdc6b4f6..0292f43042 100644 --- a/moments/creg/rt_gr_bhl_static_tetrad.c +++ b/moments/creg/rt_gr_bhl_static_tetrad.c @@ -26,8 +26,7 @@ #include -struct bhl_static_ctx -{ +struct bhl_static_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -70,8 +69,7 @@ struct bhl_static_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_static_ctx -create_ctx(void) +struct bhl_static_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -93,7 +91,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -141,14 +140,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct bhl_static_ctx *app = ctx; @@ -178,36 +176,35 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -218,17 +215,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -242,68 +251,112 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = y; fout[70] = 0.0; + fout[68] = x; + fout[69] = y; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -332,8 +385,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -347,24 +399,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -385,12 +438,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler_tetrad", .equation = gr_euler_tetrad, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -398,8 +453,8 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -410,7 +465,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -418,8 +473,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -433,22 +487,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -472,9 +516,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -482,13 +526,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -502,10 +543,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -514,26 +559,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -549,7 +599,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -564,8 +614,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -573,7 +622,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -581,8 +632,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -609,14 +659,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_blackhole_spinning.c b/moments/creg/rt_gr_blackhole_spinning.c index 25dec209af..66e0fa78b8 100644 --- a/moments/creg/rt_gr_blackhole_spinning.c +++ b/moments/creg/rt_gr_blackhole_spinning.c @@ -22,8 +22,7 @@ #include -struct blackhole_spinning_ctx -{ +struct blackhole_spinning_ctx { // Mathematical constants (dimensionless). double pi; @@ -74,8 +73,7 @@ struct blackhole_spinning_ctx double r_outer; // Ring outer radius. }; -struct blackhole_spinning_ctx -create_ctx(void) +struct blackhole_spinning_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -104,7 +102,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -158,14 +157,13 @@ create_ctx(void) .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, .r_inner = r_inner, - .r_outer = r_outer, + .r_outer = r_outer }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct blackhole_spinning_ctx *app = ctx; @@ -203,42 +201,40 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left ring). u = ul; // Fluid velocity (left ring). p = pl; // Fluid pressure (left ring). - } - else { + } else { rho = rhor; // Fluid mass density (right ring). u = ur; // Fluid velocity (right ring). p = pr; // Fluid pressure (right ring). } - } - else { + } else { rho = rhob; // Fluid mass density (background). u = ub; // Fluid velocity (background). p = pb; // Fluid pressure (background). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -249,17 +245,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -273,68 +281,112 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = y; fout[70] = 0.0; + fout[68] = x; + fout[69] = y; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -363,8 +415,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -378,24 +429,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -416,12 +468,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler", .equation = gr_euler, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -429,8 +483,8 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -441,7 +495,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -449,8 +503,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -464,22 +517,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -503,9 +546,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -513,13 +556,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -533,10 +573,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -545,26 +589,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -580,7 +629,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -595,8 +644,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -604,7 +652,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -612,8 +662,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -640,14 +689,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_blackhole_static.c b/moments/creg/rt_gr_blackhole_static.c index 156c1e9a51..54fe67fcd2 100644 --- a/moments/creg/rt_gr_blackhole_static.c +++ b/moments/creg/rt_gr_blackhole_static.c @@ -22,8 +22,7 @@ #include -struct blackhole_static_ctx -{ +struct blackhole_static_ctx { // Mathematical constants (dimensionless). double pi; @@ -74,8 +73,7 @@ struct blackhole_static_ctx double r_outer; // Ring outer radius. }; -struct blackhole_static_ctx -create_ctx(void) +struct blackhole_static_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -104,7 +102,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -158,14 +157,13 @@ create_ctx(void) .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, .r_inner = r_inner, - .r_outer = r_outer, + .r_outer = r_outer }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct blackhole_static_ctx *app = ctx; @@ -203,42 +201,40 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left ring). u = ul; // Fluid velocity (left ring). p = pl; // Fluid pressure (left ring). - } - else { + } else { rho = rhor; // Fluid mass density (right ring). u = ur; // Fluid velocity (right ring). p = pr; // Fluid pressure (right ring). } - } - else { + } else { rho = rhob; // Fluid mass density (background). u = ub; // Fluid velocity (background). p = pb; // Fluid pressure (background). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -249,17 +245,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -273,68 +281,112 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = y; fout[70] = 0.0; + fout[68] = x; + fout[69] = y; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -363,8 +415,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -378,24 +429,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -416,12 +468,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler", .equation = gr_euler, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -429,8 +483,8 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -441,7 +495,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -449,8 +503,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -464,22 +517,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -503,9 +546,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -513,13 +556,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -533,10 +573,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -545,26 +589,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -580,7 +629,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -595,8 +644,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -604,7 +652,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -612,8 +662,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -640,14 +689,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_bz_monopole_fast.c b/moments/creg/rt_gr_bz_monopole_fast.c index 22d2f9431a..2fdefe45cc 100644 --- a/moments/creg/rt_gr_bz_monopole_fast.c +++ b/moments/creg/rt_gr_bz_monopole_fast.c @@ -26,8 +26,7 @@ #include -struct bz_monopole_fast_ctx -{ +struct bz_monopole_fast_ctx { // Mathematical constants (dimensionless). double pi; @@ -67,8 +66,7 @@ struct bz_monopole_fast_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bz_monopole_fast_ctx -create_ctx(void) +struct bz_monopole_fast_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -89,7 +87,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -132,14 +131,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct bz_monopole_fast_ctx *app = ctx; @@ -155,16 +155,15 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double theta = 0.0; if (fabs(y) < pow(10.0, -6.0)) { theta = 0.5 * pi; - } - else { + } else { theta = atan(x / y); } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -173,9 +172,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - + double B_r = B0 * sin(theta) / sqrt(spatial_det); double Dx = 0.0; // Total electric field (x-direction). @@ -185,29 +184,41 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double Bx = sin(theta) * sin(phi) * B_r; // Total magnetic field (x-direction). double By = sin(theta) * cos(phi) * B_r; // Total magnetic field (y-direction). double Bz = cos(theta) * B_r; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -215,7 +226,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = y; fout[25] = 0.0; + fout[23] = x; + fout[24] = y; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -232,8 +245,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -247,24 +259,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -285,18 +298,21 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Field. - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell, - + .init = evalGRMaxwellInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -307,7 +323,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -315,8 +331,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -330,22 +345,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -369,20 +374,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -396,10 +398,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -408,26 +414,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -443,7 +454,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -458,8 +469,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -467,7 +477,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -475,8 +487,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -503,14 +514,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_bz_monopole_fast_tetrad.c b/moments/creg/rt_gr_bz_monopole_fast_tetrad.c index c0c90a272d..f138cb4f66 100644 --- a/moments/creg/rt_gr_bz_monopole_fast_tetrad.c +++ b/moments/creg/rt_gr_bz_monopole_fast_tetrad.c @@ -26,8 +26,7 @@ #include -struct bz_monopole_fast_ctx -{ +struct bz_monopole_fast_ctx { // Mathematical constants (dimensionless). double pi; @@ -67,8 +66,7 @@ struct bz_monopole_fast_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bz_monopole_fast_ctx -create_ctx(void) +struct bz_monopole_fast_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -89,7 +87,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -132,14 +131,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct bz_monopole_fast_ctx *app = ctx; @@ -155,16 +155,15 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double theta = 0.0; if (fabs(y) < pow(10.0, -6.0)) { theta = 0.5 * pi; - } - else { + } else { theta = atan(x / y); } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -173,9 +172,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - + double B_r = B0 * sin(theta) / sqrt(spatial_det); double Dx = 0.0; // Total electric field (x-direction). @@ -185,29 +184,41 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double Bx = sin(theta) * sin(phi) * B_r; // Total magnetic field (x-direction). double By = sin(theta) * cos(phi) * B_r; // Total magnetic field (y-direction). double Bz = cos(theta) * B_r; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -215,7 +226,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = y; fout[25] = 0.0; + fout[23] = x; + fout[24] = y; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -232,8 +245,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -247,24 +259,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -285,18 +298,21 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Field. - struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell_tetrad, - + .init = evalGRMaxwellInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -307,7 +323,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -315,8 +331,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -330,22 +345,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -369,20 +374,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -396,10 +398,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -408,26 +414,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -443,7 +454,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -458,8 +469,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -467,7 +477,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -475,8 +487,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -503,14 +514,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_bz_monopole_slow.c b/moments/creg/rt_gr_bz_monopole_slow.c index 74f38150de..0d9944c1df 100644 --- a/moments/creg/rt_gr_bz_monopole_slow.c +++ b/moments/creg/rt_gr_bz_monopole_slow.c @@ -26,8 +26,7 @@ #include -struct bz_monopole_slow_ctx -{ +struct bz_monopole_slow_ctx { // Mathematical constants (dimensionless). double pi; @@ -67,8 +66,7 @@ struct bz_monopole_slow_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bz_monopole_slow_ctx -create_ctx(void) +struct bz_monopole_slow_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -89,7 +87,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -132,14 +131,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct bz_monopole_slow_ctx *app = ctx; @@ -155,16 +155,15 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double theta = 0.0; if (fabs(y) < pow(10.0, -6.0)) { theta = 0.5 * pi; - } - else { + } else { theta = atan(x / y); } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -173,9 +172,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - + double B_r = B0 * sin(theta) / sqrt(spatial_det); double Dx = 0.0; // Total electric field (x-direction). @@ -185,29 +184,41 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double Bx = sin(theta) * sin(phi) * B_r; // Total magnetic field (x-direction). double By = sin(theta) * cos(phi) * B_r; // Total magnetic field (y-direction). double Bz = cos(theta) * B_r; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -215,7 +226,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = y; fout[25] = 0.0; + fout[23] = x; + fout[24] = y; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -232,8 +245,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -247,24 +259,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -285,18 +298,21 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Field. - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell, - + .init = evalGRMaxwellInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -307,7 +323,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -315,8 +331,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -330,22 +345,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -369,20 +374,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -396,10 +398,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -408,26 +414,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -443,7 +454,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -458,8 +469,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -467,7 +477,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -475,8 +487,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -503,14 +514,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_bz_monopole_slow_tetrad.c b/moments/creg/rt_gr_bz_monopole_slow_tetrad.c index 92aeea6139..19b815be48 100644 --- a/moments/creg/rt_gr_bz_monopole_slow_tetrad.c +++ b/moments/creg/rt_gr_bz_monopole_slow_tetrad.c @@ -26,8 +26,7 @@ #include -struct bz_monopole_slow_ctx -{ +struct bz_monopole_slow_ctx { // Mathematical constants (dimensionless). double pi; @@ -67,8 +66,7 @@ struct bz_monopole_slow_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bz_monopole_slow_ctx -create_ctx(void) +struct bz_monopole_slow_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -89,7 +87,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -132,14 +131,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct bz_monopole_slow_ctx *app = ctx; @@ -155,16 +155,15 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double theta = 0.0; if (fabs(y) < pow(10.0, -6.0)) { theta = 0.5 * pi; - } - else { + } else { theta = atan(x / y); } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -173,9 +172,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - + double B_r = B0 * sin(theta) / sqrt(spatial_det); double Dx = 0.0; // Total electric field (x-direction). @@ -185,29 +184,41 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double Bx = sin(theta) * sin(phi) * B_r; // Total magnetic field (x-direction). double By = sin(theta) * cos(phi) * B_r; // Total magnetic field (y-direction). double Bz = cos(theta) * B_r; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -215,7 +226,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = y; fout[25] = 0.0; + fout[23] = x; + fout[24] = y; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -232,8 +245,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -247,24 +259,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -285,18 +298,21 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Field. - struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell_tetrad, - + .init = evalGRMaxwellInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -307,7 +323,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -315,8 +331,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -330,22 +345,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -369,20 +374,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -396,10 +398,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -408,26 +414,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -443,7 +454,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -458,8 +469,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -467,7 +477,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -475,8 +487,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -503,14 +514,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_current_sheet.c b/moments/creg/rt_gr_current_sheet.c index 4a93bd0988..d2da256a4f 100644 --- a/moments/creg/rt_gr_current_sheet.c +++ b/moments/creg/rt_gr_current_sheet.c @@ -24,8 +24,7 @@ #include -struct current_sheet_ctx -{ +struct current_sheet_ctx { // Physical constants (using normalized code units). double light_speed; // Speed of light. double e_fact; // Factor of speed of light for electric field correction. @@ -62,8 +61,7 @@ struct current_sheet_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct current_sheet_ctx -create_ctx(void) +struct current_sheet_ctx create_ctx(void) { // Physical constants (using normalized code units). double light_speed = 1.0; // Speed of light. @@ -123,14 +121,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct current_sheet_ctx *app = ctx; @@ -150,8 +149,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC if (x < 0.0) { By = By_l; // Left total magnetic field (y-direction). - } - else { + } else { By = By_r; // Right total magnetic field (y-direction). } @@ -159,7 +157,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -167,31 +165,43 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -199,7 +209,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = 0.0; fout[25] = 0.0; + fout[23] = x; + fout[24] = 0.0; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -216,8 +228,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -231,24 +242,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -268,17 +280,20 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Field. - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell, - + .init = evalGRMaxwellInit, .force_low_order_flux = false, // Use Roe fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -289,7 +304,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -297,8 +312,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -312,22 +326,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -351,20 +355,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -378,10 +378,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -390,26 +394,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -425,7 +434,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -440,8 +449,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -449,7 +457,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -457,8 +467,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -485,14 +494,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_current_sheet_tetrad.c b/moments/creg/rt_gr_current_sheet_tetrad.c index b6ada59c02..bbb9d2690f 100644 --- a/moments/creg/rt_gr_current_sheet_tetrad.c +++ b/moments/creg/rt_gr_current_sheet_tetrad.c @@ -24,8 +24,7 @@ #include -struct current_sheet_ctx -{ +struct current_sheet_ctx { // Physical constants (using normalized code units). double light_speed; // Speed of light. double e_fact; // Factor of speed of light for electric field correction. @@ -62,8 +61,7 @@ struct current_sheet_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct current_sheet_ctx -create_ctx(void) +struct current_sheet_ctx create_ctx(void) { // Physical constants (using normalized code units). double light_speed = 1.0; // Speed of light. @@ -123,14 +121,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct current_sheet_ctx *app = ctx; @@ -150,8 +149,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC if (x < 0.0) { By = By_l; // Left total magnetic field (y-direction). - } - else { + } else { By = By_r; // Right total magnetic field (y-direction). } @@ -159,7 +157,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -167,31 +165,43 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -199,7 +209,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = 0.0; fout[25] = 0.0; + fout[23] = x; + fout[24] = 0.0; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -216,8 +228,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -231,24 +242,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -268,17 +280,20 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Field. - struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell_tetrad, - + .init = evalGRMaxwellInit, .force_low_order_flux = false, // Use Roe fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -289,7 +304,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -297,8 +312,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -312,22 +326,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -351,20 +355,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -378,10 +378,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -390,26 +394,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -425,7 +434,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -440,8 +449,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -449,7 +457,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -457,8 +467,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -485,14 +494,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_einstein_plane_shock.c b/moments/creg/rt_gr_einstein_plane_shock.c index 99fb725519..362d888951 100644 --- a/moments/creg/rt_gr_einstein_plane_shock.c +++ b/moments/creg/rt_gr_einstein_plane_shock.c @@ -23,8 +23,7 @@ #include -struct gr_einstein_plane_shock_ctx -{ +struct gr_einstein_plane_shock_ctx { // Mathematical constants (dimensionless). double pi; @@ -54,8 +53,7 @@ struct gr_einstein_plane_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct gr_einstein_plane_shock_ctx -create_ctx(void) +struct gr_einstein_plane_shock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -102,14 +100,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMediumInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMediumInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct gr_einstein_plane_shock_ctx *app = ctx; @@ -126,25 +125,30 @@ evalGRMediumInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.0) { Etot = Etot_l; // Fluid total energy density (left). - } - else { + } else { Etot = Etot_r; // Fluid total energy density (right). } double a_dt = 0.0; // Time derivative of metric term a. double a_dx = 0.0; // Space derivative of metric term a. double b_dt = 0.0; // Time derivative of metric term b. - double b_dx = -sqrt((kappa * exp_2a * Etot) / 3.0) * tan((0.5 * x * sqrt(3.0 * kappa * exp_2a * Etot))); // Space derivative of metric term b. + double b_dx = + -sqrt((kappa * exp_2a * Etot) / 3.0) * + tan((0.5 * x * sqrt(3.0 * kappa * exp_2a * Etot))); // Space derivative of metric term b. double c_dt = 0.0; // Time derivative of metric term c. double c_dx = 0.0; // Space derivative of metric term c. - double b_dx_plus = -sqrt((kappa * exp_2a * Etot) / 3.0) * tan((0.5 * (x + (0.5 * pow(10.0, -8.0))) * sqrt(3.0 * kappa * exp_2a * Etot))); - double b_dx_minus = -sqrt((kappa * exp_2a * Etot) / 3.0) * tan((0.5 * (x - (0.5 * pow(10.0, -8.0))) * sqrt(3.0 * kappa * exp_2a * Etot))); + double b_dx_plus = -sqrt((kappa * exp_2a * Etot) / 3.0) * + tan((0.5 * (x + (0.5 * pow(10.0, -8.0))) * sqrt(3.0 * kappa * exp_2a * Etot))); + double b_dx_minus = + -sqrt((kappa * exp_2a * Etot) / 3.0) * + tan((0.5 * (x - (0.5 * pow(10.0, -8.0))) * sqrt(3.0 * kappa * exp_2a * Etot))); double a_dt_dx = 0.0; // Mixed space-time derivative of metric term a. double a_dx_dx = 0.0; // Second space derivative of metric term a. double b_dt_dx = 0.0; // Mixed space-time derivative of metric term b. - double b_dx_dx = (b_dx_plus - b_dx_minus) / pow(10.0, -8.0); // Second space derivative of metric term b. + double b_dx_dx = + (b_dx_plus - b_dx_minus) / pow(10.0, -8.0); // Second space derivative of metric term b. double c_dt_dx = 0.0; // Mixed space-time derivative of metric term c. double c_dx_dx = 0.0; // Second space derivative of metric term c. @@ -153,21 +157,26 @@ evalGRMediumInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT // Set exponential appearing in dt and dx metric terms. fout[0] = exp_2a; // Set first time and space derivatives of metric terms. - fout[1] = a_dt; fout[2] = a_dx; - fout[3] = b_dt; fout[4] = b_dx; - fout[5] = c_dt; fout[6] = c_dx; + fout[1] = a_dt; + fout[2] = a_dx; + fout[3] = b_dt; + fout[4] = b_dx; + fout[5] = c_dt; + fout[6] = c_dx; // Set second time and space derivatives of metric terms. - fout[7] = a_dt_dx; fout[8] = a_dx_dx; - fout[9] = b_dt_dx; fout[10] = b_dx_dx; - fout[11] = c_dt_dx; fout[12] = c_dx_dx; + fout[7] = a_dt_dx; + fout[8] = a_dx_dx; + fout[9] = b_dt_dx; + fout[10] = b_dx_dx; + fout[11] = c_dt_dx; + fout[12] = c_dx_dx; // Set fluid total energy density. fout[13] = Etot; // Set fluid momentum density. fout[14] = mom_x; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -181,24 +190,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -223,7 +233,7 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "gr_medium", .equation = gr_medium, - + .init = evalGRMediumInit, .ctx = &ctx, @@ -231,7 +241,7 @@ main(int argc, char **argv) .medium_gas_gamma = ctx.gas_gamma, .medium_kappa = ctx.kappa, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -242,7 +252,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -250,8 +260,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -265,22 +274,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -304,20 +303,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -331,10 +326,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -343,26 +342,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -378,7 +382,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -393,8 +397,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -402,7 +405,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -410,8 +415,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -437,14 +441,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(gr_medium); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_kh_2d.c b/moments/creg/rt_gr_kh_2d.c index 7a12ccf8d3..b5e09a98ef 100644 --- a/moments/creg/rt_gr_kh_2d.c +++ b/moments/creg/rt_gr_kh_2d.c @@ -24,8 +24,7 @@ #include -struct kh_2d_ctx -{ +struct kh_2d_ctx { // Mathematical constants (dimensionless). double pi; @@ -36,7 +35,7 @@ struct kh_2d_ctx double u_u; // Upper fluid x-velocity. double v_u; // Upper fluid y-velocity. double p_u; // Upper fluid pressure. - + double rho_l; // Lower fluid mass density. double u_l; // Lower fluid x-velocity. double v_l; // Lower fluid y-velocity. @@ -65,8 +64,7 @@ struct kh_2d_ctx double y_loc; // Fluid boundary (y-direction). }; -struct kh_2d_ctx -create_ctx(void) +struct kh_2d_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -131,14 +129,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .y_loc = y_loc, + .y_loc = y_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct kh_2d_ctx *app = ctx; @@ -171,8 +168,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT u = u_u * tanh(100.0 * y); // Fluid x-velocity (upper). v = v_u * sin(2.0 * pi * x) * exp(-100.0 * y * y); // Fluid y-velocity (upper). p = p_u; // Fluid pressure (upper). - } - else { + } else { rho = rho_l; // Fluid mass density (lower). u = u_l * tanh(100.0 * y); // Fluid x-velocity (lower). v = v_l * sin(2.0 * pi * x) * exp(-100.0 * y * y); // Fluid y-velocity (lower). @@ -183,25 +179,25 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -212,17 +208,28 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = v; vel[2] = 0.0; + vel[0] = u; + vel[1] = v; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -236,68 +243,112 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = sqrt(spatial_det) * rho * h * (W * W) * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = y; fout[70] = 0.0; + fout[68] = x; + fout[69] = y; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -326,8 +377,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -341,24 +391,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -379,12 +430,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler", .equation = gr_euler, - + .init = evalGREulerInit, .force_low_order_flux = false, // Use HLL fluxes. .limiter = GKYL_MIN_MOD, @@ -393,7 +446,7 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -404,7 +457,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -412,8 +465,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -427,22 +479,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -461,14 +503,14 @@ main(int argc, char **argv) } goto mpifinalize; } - + // Moment app. struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, -0.5 * ctx.Ly }, - .upper = { ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, -0.5 * ctx.Ly}, + .upper = {ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -476,15 +518,12 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -498,10 +537,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -510,26 +553,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -545,7 +593,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -560,8 +608,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -569,7 +616,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -577,8 +626,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -605,8 +653,8 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_gr_mhd_bhl_spinning.c b/moments/creg/rt_gr_mhd_bhl_spinning.c index c73adc3400..7a64b9e27e 100644 --- a/moments/creg/rt_gr_mhd_bhl_spinning.c +++ b/moments/creg/rt_gr_mhd_bhl_spinning.c @@ -19,8 +19,7 @@ #include -struct bhl_spinning_mhd_ctx -{ +struct bhl_spinning_mhd_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -68,8 +67,7 @@ struct bhl_spinning_mhd_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_spinning_mhd_ctx -create_ctx(void) +struct bhl_spinning_mhd_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -96,7 +94,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -116,7 +115,7 @@ create_ctx(void) int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double x_loc = 1.0; // Shock location (x-direction). - + struct bhl_spinning_mhd_ctx ctx = { .gas_gamma = gas_gamma, .rhol = rhol, @@ -147,14 +146,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMHDInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct bhl_spinning_mhd_ctx *app = ctx; @@ -186,36 +184,35 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -226,17 +223,29 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -250,7 +259,9 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo } double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = 0.0; mag[1] = B0; mag[2] = 0.0; + mag[0] = 0.0; + mag[1] = B0; + mag[2] = 0.0; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -303,12 +314,16 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double h_star = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))) + (b_sq / rho); double p_star = p + (0.5 * b_sq); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. - double mom_x = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); // Fluid momentum density (x-direction). + double mom_x = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]) + ); // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); // Fluid total energy density. + double Etot = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W) + ); // Fluid total energy density. double Bx_rel = 0.0; // Fluid relativistic magnetic field (x-direction). double By_rel = sqrt(spatial_det) * B0; // Fluid relativistic magnetic field (y-direction). @@ -317,63 +332,108 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set fluid relativistic magnetic field. - fout[5] = Bx_rel; fout[6] = By_rel; fout[7] = Bz_rel; + fout[5] = Bx_rel; + fout[6] = By_rel; + fout[7] = Bz_rel; // Set correction potential. fout[8] = 0.0; // Set lapse gauge variable. fout[9] = lapse; // Set shift gauge variables. - fout[10] = shift[0]; fout[11] = shift[1]; fout[12] = shift[2]; + fout[10] = shift[0]; + fout[11] = shift[1]; + fout[12] = shift[2]; // Set spatial metric tensor. - fout[13] = spatial_metric[0][0]; fout[14] = spatial_metric[0][1]; fout[15] = spatial_metric[0][2]; - fout[16] = spatial_metric[1][0]; fout[17] = spatial_metric[1][1]; fout[18] = spatial_metric[1][2]; - fout[19] = spatial_metric[2][0]; fout[20] = spatial_metric[2][1]; fout[21] = spatial_metric[2][2]; + fout[13] = spatial_metric[0][0]; + fout[14] = spatial_metric[0][1]; + fout[15] = spatial_metric[0][2]; + fout[16] = spatial_metric[1][0]; + fout[17] = spatial_metric[1][1]; + fout[18] = spatial_metric[1][2]; + fout[19] = spatial_metric[2][0]; + fout[20] = spatial_metric[2][1]; + fout[21] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[22] = extrinsic_curvature[0][0]; fout[23] = extrinsic_curvature[0][1]; fout[24] = extrinsic_curvature[0][2]; - fout[25] = extrinsic_curvature[1][0]; fout[26] = extrinsic_curvature[1][1]; fout[27] = extrinsic_curvature[1][2]; - fout[28] = extrinsic_curvature[2][0]; fout[29] = extrinsic_curvature[2][1]; fout[30] = extrinsic_curvature[2][2]; + fout[22] = extrinsic_curvature[0][0]; + fout[23] = extrinsic_curvature[0][1]; + fout[24] = extrinsic_curvature[0][2]; + fout[25] = extrinsic_curvature[1][0]; + fout[26] = extrinsic_curvature[1][1]; + fout[27] = extrinsic_curvature[1][2]; + fout[28] = extrinsic_curvature[2][0]; + fout[29] = extrinsic_curvature[2][1]; + fout[30] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[31] = -1.0; - } - else { + } else { fout[31] = 1.0; } // Set lapse function derivatives. - fout[32] = lapse_der[0]; fout[33] = lapse_der[1]; fout[34] = lapse_der[2]; + fout[32] = lapse_der[0]; + fout[33] = lapse_der[1]; + fout[34] = lapse_der[2]; // Set shift vector derivatives. - fout[35] = shift_der[0][0]; fout[36] = shift_der[0][1]; fout[37] = shift_der[0][2]; - fout[38] = shift_der[1][0]; fout[39] = shift_der[1][1]; fout[40] = shift_der[1][2]; - fout[41] = shift_der[2][0]; fout[42] = shift_der[2][1]; fout[43] = shift_der[2][2]; + fout[35] = shift_der[0][0]; + fout[36] = shift_der[0][1]; + fout[37] = shift_der[0][2]; + fout[38] = shift_der[1][0]; + fout[39] = shift_der[1][1]; + fout[40] = shift_der[1][2]; + fout[41] = shift_der[2][0]; + fout[42] = shift_der[2][1]; + fout[43] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[44] = spatial_metric_der[0][0][0]; fout[45] = spatial_metric_der[0][0][1]; fout[46] = spatial_metric_der[0][0][2]; - fout[47] = spatial_metric_der[0][1][0]; fout[48] = spatial_metric_der[0][1][1]; fout[49] = spatial_metric_der[0][1][2]; - fout[50] = spatial_metric_der[0][2][0]; fout[51] = spatial_metric_der[0][2][1]; fout[52] = spatial_metric_der[0][2][2]; - - fout[53] = spatial_metric_der[1][0][0]; fout[54] = spatial_metric_der[1][0][1]; fout[55] = spatial_metric_der[1][0][2]; - fout[56] = spatial_metric_der[1][1][0]; fout[57] = spatial_metric_der[1][1][1]; fout[58] = spatial_metric_der[1][1][2]; - fout[59] = spatial_metric_der[1][2][0]; fout[60] = spatial_metric_der[1][2][1]; fout[61] = spatial_metric_der[1][2][2]; - - fout[62] = spatial_metric_der[2][0][0]; fout[63] = spatial_metric_der[2][0][1]; fout[64] = spatial_metric_der[2][0][2]; - fout[65] = spatial_metric_der[2][1][0]; fout[66] = spatial_metric_der[2][1][1]; fout[67] = spatial_metric_der[2][1][2]; - fout[68] = spatial_metric_der[2][2][0]; fout[69] = spatial_metric_der[2][2][1]; fout[70] = spatial_metric_der[2][2][2]; + fout[44] = spatial_metric_der[0][0][0]; + fout[45] = spatial_metric_der[0][0][1]; + fout[46] = spatial_metric_der[0][0][2]; + fout[47] = spatial_metric_der[0][1][0]; + fout[48] = spatial_metric_der[0][1][1]; + fout[49] = spatial_metric_der[0][1][2]; + fout[50] = spatial_metric_der[0][2][0]; + fout[51] = spatial_metric_der[0][2][1]; + fout[52] = spatial_metric_der[0][2][2]; + + fout[53] = spatial_metric_der[1][0][0]; + fout[54] = spatial_metric_der[1][0][1]; + fout[55] = spatial_metric_der[1][0][2]; + fout[56] = spatial_metric_der[1][1][0]; + fout[57] = spatial_metric_der[1][1][1]; + fout[58] = spatial_metric_der[1][1][2]; + fout[59] = spatial_metric_der[1][2][0]; + fout[60] = spatial_metric_der[1][2][1]; + fout[61] = spatial_metric_der[1][2][2]; + + fout[62] = spatial_metric_der[2][0][0]; + fout[63] = spatial_metric_der[2][0][1]; + fout[64] = spatial_metric_der[2][0][2]; + fout[65] = spatial_metric_der[2][1][0]; + fout[66] = spatial_metric_der[2][1][1]; + fout[67] = spatial_metric_der[2][1][2]; + fout[68] = spatial_metric_der[2][2][0]; + fout[69] = spatial_metric_der[2][2][1]; + fout[70] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[71] = 0.0; // Set spatial coordinates. - fout[72] = x; fout[73] = y; fout[74] = 0.0; + fout[72] = x; + fout[73] = y; + fout[74] = 0.0; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -408,8 +468,7 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -423,24 +482,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -461,12 +521,15 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new(ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new( + ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_mhd", .equation = gr_mhd, - + .init = evalGRMHDInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -474,8 +537,8 @@ main(int argc, char **argv) .has_gr_mhd = true, .gr_mhd_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -486,7 +549,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -494,8 +557,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -509,22 +571,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -548,9 +600,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -558,13 +610,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -578,10 +627,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -590,26 +643,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -625,7 +683,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -640,8 +698,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -649,7 +706,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -657,8 +716,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -685,14 +743,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_mhd); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_mhd_bhl_spinning_mhd.c b/moments/creg/rt_gr_mhd_bhl_spinning_mhd.c index 91c0b7515a..b546649a47 100644 --- a/moments/creg/rt_gr_mhd_bhl_spinning_mhd.c +++ b/moments/creg/rt_gr_mhd_bhl_spinning_mhd.c @@ -19,8 +19,7 @@ #include -struct bhl_spinning_mhd_ctx -{ +struct bhl_spinning_mhd_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -68,8 +67,7 @@ struct bhl_spinning_mhd_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_spinning_mhd_ctx -create_ctx(void) +struct bhl_spinning_mhd_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -96,7 +94,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -116,7 +115,7 @@ create_ctx(void) int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double x_loc = 1.0; // Shock location (x-direction). - + struct bhl_spinning_mhd_ctx ctx = { .gas_gamma = gas_gamma, .rhol = rhol, @@ -147,14 +146,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMHDTetradInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct bhl_spinning_mhd_ctx *app = ctx; @@ -186,36 +186,35 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -226,17 +225,29 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -250,7 +261,9 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR } double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = 0.0; mag[1] = B0; mag[2] = 0.0; + mag[0] = 0.0; + mag[1] = B0; + mag[2] = 0.0; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -303,12 +316,16 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR double h_star = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))) + (b_sq / rho); double p_star = p + (0.5 * b_sq); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. - double mom_x = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); // Fluid momentum density (x-direction). + double mom_x = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]) + ); // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); // Fluid total energy density. + double Etot = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W) + ); // Fluid total energy density. double Bx_rel = 0.0; // Fluid relativistic magnetic field (x-direction). double By_rel = sqrt(spatial_det) * B0; // Fluid relativistic magnetic field (y-direction). @@ -317,63 +334,108 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set fluid relativistic magnetic field. - fout[5] = Bx_rel; fout[6] = By_rel; fout[7] = Bz_rel; + fout[5] = Bx_rel; + fout[6] = By_rel; + fout[7] = Bz_rel; // Set correction potential. fout[8] = 0.0; // Set lapse gauge variable. fout[9] = lapse; // Set shift gauge variables. - fout[10] = shift[0]; fout[11] = shift[1]; fout[12] = shift[2]; + fout[10] = shift[0]; + fout[11] = shift[1]; + fout[12] = shift[2]; // Set spatial metric tensor. - fout[13] = spatial_metric[0][0]; fout[14] = spatial_metric[0][1]; fout[15] = spatial_metric[0][2]; - fout[16] = spatial_metric[1][0]; fout[17] = spatial_metric[1][1]; fout[18] = spatial_metric[1][2]; - fout[19] = spatial_metric[2][0]; fout[20] = spatial_metric[2][1]; fout[21] = spatial_metric[2][2]; + fout[13] = spatial_metric[0][0]; + fout[14] = spatial_metric[0][1]; + fout[15] = spatial_metric[0][2]; + fout[16] = spatial_metric[1][0]; + fout[17] = spatial_metric[1][1]; + fout[18] = spatial_metric[1][2]; + fout[19] = spatial_metric[2][0]; + fout[20] = spatial_metric[2][1]; + fout[21] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[22] = extrinsic_curvature[0][0]; fout[23] = extrinsic_curvature[0][1]; fout[24] = extrinsic_curvature[0][2]; - fout[25] = extrinsic_curvature[1][0]; fout[26] = extrinsic_curvature[1][1]; fout[27] = extrinsic_curvature[1][2]; - fout[28] = extrinsic_curvature[2][0]; fout[29] = extrinsic_curvature[2][1]; fout[30] = extrinsic_curvature[2][2]; + fout[22] = extrinsic_curvature[0][0]; + fout[23] = extrinsic_curvature[0][1]; + fout[24] = extrinsic_curvature[0][2]; + fout[25] = extrinsic_curvature[1][0]; + fout[26] = extrinsic_curvature[1][1]; + fout[27] = extrinsic_curvature[1][2]; + fout[28] = extrinsic_curvature[2][0]; + fout[29] = extrinsic_curvature[2][1]; + fout[30] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[31] = -1.0; - } - else { + } else { fout[31] = 1.0; } // Set lapse function derivatives. - fout[32] = lapse_der[0]; fout[33] = lapse_der[1]; fout[34] = lapse_der[2]; + fout[32] = lapse_der[0]; + fout[33] = lapse_der[1]; + fout[34] = lapse_der[2]; // Set shift vector derivatives. - fout[35] = shift_der[0][0]; fout[36] = shift_der[0][1]; fout[37] = shift_der[0][2]; - fout[38] = shift_der[1][0]; fout[39] = shift_der[1][1]; fout[40] = shift_der[1][2]; - fout[41] = shift_der[2][0]; fout[42] = shift_der[2][1]; fout[43] = shift_der[2][2]; + fout[35] = shift_der[0][0]; + fout[36] = shift_der[0][1]; + fout[37] = shift_der[0][2]; + fout[38] = shift_der[1][0]; + fout[39] = shift_der[1][1]; + fout[40] = shift_der[1][2]; + fout[41] = shift_der[2][0]; + fout[42] = shift_der[2][1]; + fout[43] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[44] = spatial_metric_der[0][0][0]; fout[45] = spatial_metric_der[0][0][1]; fout[46] = spatial_metric_der[0][0][2]; - fout[47] = spatial_metric_der[0][1][0]; fout[48] = spatial_metric_der[0][1][1]; fout[49] = spatial_metric_der[0][1][2]; - fout[50] = spatial_metric_der[0][2][0]; fout[51] = spatial_metric_der[0][2][1]; fout[52] = spatial_metric_der[0][2][2]; - - fout[53] = spatial_metric_der[1][0][0]; fout[54] = spatial_metric_der[1][0][1]; fout[55] = spatial_metric_der[1][0][2]; - fout[56] = spatial_metric_der[1][1][0]; fout[57] = spatial_metric_der[1][1][1]; fout[58] = spatial_metric_der[1][1][2]; - fout[59] = spatial_metric_der[1][2][0]; fout[60] = spatial_metric_der[1][2][1]; fout[61] = spatial_metric_der[1][2][2]; - - fout[62] = spatial_metric_der[2][0][0]; fout[63] = spatial_metric_der[2][0][1]; fout[64] = spatial_metric_der[2][0][2]; - fout[65] = spatial_metric_der[2][1][0]; fout[66] = spatial_metric_der[2][1][1]; fout[67] = spatial_metric_der[2][1][2]; - fout[68] = spatial_metric_der[2][2][0]; fout[69] = spatial_metric_der[2][2][1]; fout[70] = spatial_metric_der[2][2][2]; + fout[44] = spatial_metric_der[0][0][0]; + fout[45] = spatial_metric_der[0][0][1]; + fout[46] = spatial_metric_der[0][0][2]; + fout[47] = spatial_metric_der[0][1][0]; + fout[48] = spatial_metric_der[0][1][1]; + fout[49] = spatial_metric_der[0][1][2]; + fout[50] = spatial_metric_der[0][2][0]; + fout[51] = spatial_metric_der[0][2][1]; + fout[52] = spatial_metric_der[0][2][2]; + + fout[53] = spatial_metric_der[1][0][0]; + fout[54] = spatial_metric_der[1][0][1]; + fout[55] = spatial_metric_der[1][0][2]; + fout[56] = spatial_metric_der[1][1][0]; + fout[57] = spatial_metric_der[1][1][1]; + fout[58] = spatial_metric_der[1][1][2]; + fout[59] = spatial_metric_der[1][2][0]; + fout[60] = spatial_metric_der[1][2][1]; + fout[61] = spatial_metric_der[1][2][2]; + + fout[62] = spatial_metric_der[2][0][0]; + fout[63] = spatial_metric_der[2][0][1]; + fout[64] = spatial_metric_der[2][0][2]; + fout[65] = spatial_metric_der[2][1][0]; + fout[66] = spatial_metric_der[2][1][1]; + fout[67] = spatial_metric_der[2][1][2]; + fout[68] = spatial_metric_der[2][2][0]; + fout[69] = spatial_metric_der[2][2][1]; + fout[70] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[71] = 0.0; // Set spatial coordinates. - fout[72] = x; fout[73] = y; fout[74] = 0.0; + fout[72] = x; + fout[73] = y; + fout[74] = 0.0; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -408,8 +470,7 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -423,24 +484,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -461,12 +523,15 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new(ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new( + ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_mhd_tetrad", .equation = gr_mhd_tetrad, - + .init = evalGRMHDTetradInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -474,8 +539,8 @@ main(int argc, char **argv) .has_gr_mhd = true, .gr_mhd_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -486,7 +551,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -494,8 +559,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -509,22 +573,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -548,9 +602,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -558,13 +612,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -578,10 +629,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -590,26 +645,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -625,7 +685,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -640,8 +700,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -649,7 +708,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -657,8 +718,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -685,14 +745,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_mhd_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_mhd_bhl_spinning_tetrad.c b/moments/creg/rt_gr_mhd_bhl_spinning_tetrad.c index 91c0b7515a..b546649a47 100644 --- a/moments/creg/rt_gr_mhd_bhl_spinning_tetrad.c +++ b/moments/creg/rt_gr_mhd_bhl_spinning_tetrad.c @@ -19,8 +19,7 @@ #include -struct bhl_spinning_mhd_ctx -{ +struct bhl_spinning_mhd_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -68,8 +67,7 @@ struct bhl_spinning_mhd_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_spinning_mhd_ctx -create_ctx(void) +struct bhl_spinning_mhd_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -96,7 +94,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -116,7 +115,7 @@ create_ctx(void) int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double x_loc = 1.0; // Shock location (x-direction). - + struct bhl_spinning_mhd_ctx ctx = { .gas_gamma = gas_gamma, .rhol = rhol, @@ -147,14 +146,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMHDTetradInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct bhl_spinning_mhd_ctx *app = ctx; @@ -186,36 +186,35 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -226,17 +225,29 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -250,7 +261,9 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR } double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = 0.0; mag[1] = B0; mag[2] = 0.0; + mag[0] = 0.0; + mag[1] = B0; + mag[2] = 0.0; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -303,12 +316,16 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR double h_star = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))) + (b_sq / rho); double p_star = p + (0.5 * b_sq); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. - double mom_x = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); // Fluid momentum density (x-direction). + double mom_x = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]) + ); // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); // Fluid total energy density. + double Etot = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W) + ); // Fluid total energy density. double Bx_rel = 0.0; // Fluid relativistic magnetic field (x-direction). double By_rel = sqrt(spatial_det) * B0; // Fluid relativistic magnetic field (y-direction). @@ -317,63 +334,108 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set fluid relativistic magnetic field. - fout[5] = Bx_rel; fout[6] = By_rel; fout[7] = Bz_rel; + fout[5] = Bx_rel; + fout[6] = By_rel; + fout[7] = Bz_rel; // Set correction potential. fout[8] = 0.0; // Set lapse gauge variable. fout[9] = lapse; // Set shift gauge variables. - fout[10] = shift[0]; fout[11] = shift[1]; fout[12] = shift[2]; + fout[10] = shift[0]; + fout[11] = shift[1]; + fout[12] = shift[2]; // Set spatial metric tensor. - fout[13] = spatial_metric[0][0]; fout[14] = spatial_metric[0][1]; fout[15] = spatial_metric[0][2]; - fout[16] = spatial_metric[1][0]; fout[17] = spatial_metric[1][1]; fout[18] = spatial_metric[1][2]; - fout[19] = spatial_metric[2][0]; fout[20] = spatial_metric[2][1]; fout[21] = spatial_metric[2][2]; + fout[13] = spatial_metric[0][0]; + fout[14] = spatial_metric[0][1]; + fout[15] = spatial_metric[0][2]; + fout[16] = spatial_metric[1][0]; + fout[17] = spatial_metric[1][1]; + fout[18] = spatial_metric[1][2]; + fout[19] = spatial_metric[2][0]; + fout[20] = spatial_metric[2][1]; + fout[21] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[22] = extrinsic_curvature[0][0]; fout[23] = extrinsic_curvature[0][1]; fout[24] = extrinsic_curvature[0][2]; - fout[25] = extrinsic_curvature[1][0]; fout[26] = extrinsic_curvature[1][1]; fout[27] = extrinsic_curvature[1][2]; - fout[28] = extrinsic_curvature[2][0]; fout[29] = extrinsic_curvature[2][1]; fout[30] = extrinsic_curvature[2][2]; + fout[22] = extrinsic_curvature[0][0]; + fout[23] = extrinsic_curvature[0][1]; + fout[24] = extrinsic_curvature[0][2]; + fout[25] = extrinsic_curvature[1][0]; + fout[26] = extrinsic_curvature[1][1]; + fout[27] = extrinsic_curvature[1][2]; + fout[28] = extrinsic_curvature[2][0]; + fout[29] = extrinsic_curvature[2][1]; + fout[30] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[31] = -1.0; - } - else { + } else { fout[31] = 1.0; } // Set lapse function derivatives. - fout[32] = lapse_der[0]; fout[33] = lapse_der[1]; fout[34] = lapse_der[2]; + fout[32] = lapse_der[0]; + fout[33] = lapse_der[1]; + fout[34] = lapse_der[2]; // Set shift vector derivatives. - fout[35] = shift_der[0][0]; fout[36] = shift_der[0][1]; fout[37] = shift_der[0][2]; - fout[38] = shift_der[1][0]; fout[39] = shift_der[1][1]; fout[40] = shift_der[1][2]; - fout[41] = shift_der[2][0]; fout[42] = shift_der[2][1]; fout[43] = shift_der[2][2]; + fout[35] = shift_der[0][0]; + fout[36] = shift_der[0][1]; + fout[37] = shift_der[0][2]; + fout[38] = shift_der[1][0]; + fout[39] = shift_der[1][1]; + fout[40] = shift_der[1][2]; + fout[41] = shift_der[2][0]; + fout[42] = shift_der[2][1]; + fout[43] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[44] = spatial_metric_der[0][0][0]; fout[45] = spatial_metric_der[0][0][1]; fout[46] = spatial_metric_der[0][0][2]; - fout[47] = spatial_metric_der[0][1][0]; fout[48] = spatial_metric_der[0][1][1]; fout[49] = spatial_metric_der[0][1][2]; - fout[50] = spatial_metric_der[0][2][0]; fout[51] = spatial_metric_der[0][2][1]; fout[52] = spatial_metric_der[0][2][2]; - - fout[53] = spatial_metric_der[1][0][0]; fout[54] = spatial_metric_der[1][0][1]; fout[55] = spatial_metric_der[1][0][2]; - fout[56] = spatial_metric_der[1][1][0]; fout[57] = spatial_metric_der[1][1][1]; fout[58] = spatial_metric_der[1][1][2]; - fout[59] = spatial_metric_der[1][2][0]; fout[60] = spatial_metric_der[1][2][1]; fout[61] = spatial_metric_der[1][2][2]; - - fout[62] = spatial_metric_der[2][0][0]; fout[63] = spatial_metric_der[2][0][1]; fout[64] = spatial_metric_der[2][0][2]; - fout[65] = spatial_metric_der[2][1][0]; fout[66] = spatial_metric_der[2][1][1]; fout[67] = spatial_metric_der[2][1][2]; - fout[68] = spatial_metric_der[2][2][0]; fout[69] = spatial_metric_der[2][2][1]; fout[70] = spatial_metric_der[2][2][2]; + fout[44] = spatial_metric_der[0][0][0]; + fout[45] = spatial_metric_der[0][0][1]; + fout[46] = spatial_metric_der[0][0][2]; + fout[47] = spatial_metric_der[0][1][0]; + fout[48] = spatial_metric_der[0][1][1]; + fout[49] = spatial_metric_der[0][1][2]; + fout[50] = spatial_metric_der[0][2][0]; + fout[51] = spatial_metric_der[0][2][1]; + fout[52] = spatial_metric_der[0][2][2]; + + fout[53] = spatial_metric_der[1][0][0]; + fout[54] = spatial_metric_der[1][0][1]; + fout[55] = spatial_metric_der[1][0][2]; + fout[56] = spatial_metric_der[1][1][0]; + fout[57] = spatial_metric_der[1][1][1]; + fout[58] = spatial_metric_der[1][1][2]; + fout[59] = spatial_metric_der[1][2][0]; + fout[60] = spatial_metric_der[1][2][1]; + fout[61] = spatial_metric_der[1][2][2]; + + fout[62] = spatial_metric_der[2][0][0]; + fout[63] = spatial_metric_der[2][0][1]; + fout[64] = spatial_metric_der[2][0][2]; + fout[65] = spatial_metric_der[2][1][0]; + fout[66] = spatial_metric_der[2][1][1]; + fout[67] = spatial_metric_der[2][1][2]; + fout[68] = spatial_metric_der[2][2][0]; + fout[69] = spatial_metric_der[2][2][1]; + fout[70] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[71] = 0.0; // Set spatial coordinates. - fout[72] = x; fout[73] = y; fout[74] = 0.0; + fout[72] = x; + fout[73] = y; + fout[74] = 0.0; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -408,8 +470,7 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -423,24 +484,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -461,12 +523,15 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new(ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new( + ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_mhd_tetrad", .equation = gr_mhd_tetrad, - + .init = evalGRMHDTetradInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -474,8 +539,8 @@ main(int argc, char **argv) .has_gr_mhd = true, .gr_mhd_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -486,7 +551,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -494,8 +559,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -509,22 +573,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -548,9 +602,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -558,13 +612,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -578,10 +629,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -590,26 +645,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -625,7 +685,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -640,8 +700,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -649,7 +708,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -657,8 +718,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -685,14 +745,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_mhd_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_mhd_bhl_static.c b/moments/creg/rt_gr_mhd_bhl_static.c index 2f92b1a76d..25b43b7774 100644 --- a/moments/creg/rt_gr_mhd_bhl_static.c +++ b/moments/creg/rt_gr_mhd_bhl_static.c @@ -19,8 +19,7 @@ #include -struct bhl_static_mhd_ctx -{ +struct bhl_static_mhd_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -68,8 +67,7 @@ struct bhl_static_mhd_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_static_mhd_ctx -create_ctx(void) +struct bhl_static_mhd_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -96,7 +94,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -116,7 +115,7 @@ create_ctx(void) int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double x_loc = 1.0; // Shock location (x-direction). - + struct bhl_static_mhd_ctx ctx = { .gas_gamma = gas_gamma, .rhol = rhol, @@ -147,14 +146,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMHDInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct bhl_static_mhd_ctx *app = ctx; @@ -186,36 +184,35 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -226,17 +223,29 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -250,7 +259,9 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo } double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = 0.0; mag[1] = B0; mag[2] = 0.0; + mag[0] = 0.0; + mag[1] = B0; + mag[2] = 0.0; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -303,12 +314,16 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double h_star = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))) + (b_sq / rho); double p_star = p + (0.5 * b_sq); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. - double mom_x = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); // Fluid momentum density (x-direction). + double mom_x = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]) + ); // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); // Fluid total energy density. + double Etot = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W) + ); // Fluid total energy density. double Bx_rel = 0.0; // Fluid relativistic magnetic field (x-direction). double By_rel = sqrt(spatial_det) * B0; // Fluid relativistic magnetic field (y-direction). @@ -317,63 +332,108 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set fluid relativistic magnetic field. - fout[5] = Bx_rel; fout[6] = By_rel; fout[7] = Bz_rel; + fout[5] = Bx_rel; + fout[6] = By_rel; + fout[7] = Bz_rel; // Set correction potential. fout[8] = 0.0; // Set lapse gauge variable. fout[9] = lapse; // Set shift gauge variables. - fout[10] = shift[0]; fout[11] = shift[1]; fout[12] = shift[2]; + fout[10] = shift[0]; + fout[11] = shift[1]; + fout[12] = shift[2]; // Set spatial metric tensor. - fout[13] = spatial_metric[0][0]; fout[14] = spatial_metric[0][1]; fout[15] = spatial_metric[0][2]; - fout[16] = spatial_metric[1][0]; fout[17] = spatial_metric[1][1]; fout[18] = spatial_metric[1][2]; - fout[19] = spatial_metric[2][0]; fout[20] = spatial_metric[2][1]; fout[21] = spatial_metric[2][2]; + fout[13] = spatial_metric[0][0]; + fout[14] = spatial_metric[0][1]; + fout[15] = spatial_metric[0][2]; + fout[16] = spatial_metric[1][0]; + fout[17] = spatial_metric[1][1]; + fout[18] = spatial_metric[1][2]; + fout[19] = spatial_metric[2][0]; + fout[20] = spatial_metric[2][1]; + fout[21] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[22] = extrinsic_curvature[0][0]; fout[23] = extrinsic_curvature[0][1]; fout[24] = extrinsic_curvature[0][2]; - fout[25] = extrinsic_curvature[1][0]; fout[26] = extrinsic_curvature[1][1]; fout[27] = extrinsic_curvature[1][2]; - fout[28] = extrinsic_curvature[2][0]; fout[29] = extrinsic_curvature[2][1]; fout[30] = extrinsic_curvature[2][2]; + fout[22] = extrinsic_curvature[0][0]; + fout[23] = extrinsic_curvature[0][1]; + fout[24] = extrinsic_curvature[0][2]; + fout[25] = extrinsic_curvature[1][0]; + fout[26] = extrinsic_curvature[1][1]; + fout[27] = extrinsic_curvature[1][2]; + fout[28] = extrinsic_curvature[2][0]; + fout[29] = extrinsic_curvature[2][1]; + fout[30] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[31] = -1.0; - } - else { + } else { fout[31] = 1.0; } // Set lapse function derivatives. - fout[32] = lapse_der[0]; fout[33] = lapse_der[1]; fout[34] = lapse_der[2]; + fout[32] = lapse_der[0]; + fout[33] = lapse_der[1]; + fout[34] = lapse_der[2]; // Set shift vector derivatives. - fout[35] = shift_der[0][0]; fout[36] = shift_der[0][1]; fout[37] = shift_der[0][2]; - fout[38] = shift_der[1][0]; fout[39] = shift_der[1][1]; fout[40] = shift_der[1][2]; - fout[41] = shift_der[2][0]; fout[42] = shift_der[2][1]; fout[43] = shift_der[2][2]; + fout[35] = shift_der[0][0]; + fout[36] = shift_der[0][1]; + fout[37] = shift_der[0][2]; + fout[38] = shift_der[1][0]; + fout[39] = shift_der[1][1]; + fout[40] = shift_der[1][2]; + fout[41] = shift_der[2][0]; + fout[42] = shift_der[2][1]; + fout[43] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[44] = spatial_metric_der[0][0][0]; fout[45] = spatial_metric_der[0][0][1]; fout[46] = spatial_metric_der[0][0][2]; - fout[47] = spatial_metric_der[0][1][0]; fout[48] = spatial_metric_der[0][1][1]; fout[49] = spatial_metric_der[0][1][2]; - fout[50] = spatial_metric_der[0][2][0]; fout[51] = spatial_metric_der[0][2][1]; fout[52] = spatial_metric_der[0][2][2]; - - fout[53] = spatial_metric_der[1][0][0]; fout[54] = spatial_metric_der[1][0][1]; fout[55] = spatial_metric_der[1][0][2]; - fout[56] = spatial_metric_der[1][1][0]; fout[57] = spatial_metric_der[1][1][1]; fout[58] = spatial_metric_der[1][1][2]; - fout[59] = spatial_metric_der[1][2][0]; fout[60] = spatial_metric_der[1][2][1]; fout[61] = spatial_metric_der[1][2][2]; - - fout[62] = spatial_metric_der[2][0][0]; fout[63] = spatial_metric_der[2][0][1]; fout[64] = spatial_metric_der[2][0][2]; - fout[65] = spatial_metric_der[2][1][0]; fout[66] = spatial_metric_der[2][1][1]; fout[67] = spatial_metric_der[2][1][2]; - fout[68] = spatial_metric_der[2][2][0]; fout[69] = spatial_metric_der[2][2][1]; fout[70] = spatial_metric_der[2][2][2]; + fout[44] = spatial_metric_der[0][0][0]; + fout[45] = spatial_metric_der[0][0][1]; + fout[46] = spatial_metric_der[0][0][2]; + fout[47] = spatial_metric_der[0][1][0]; + fout[48] = spatial_metric_der[0][1][1]; + fout[49] = spatial_metric_der[0][1][2]; + fout[50] = spatial_metric_der[0][2][0]; + fout[51] = spatial_metric_der[0][2][1]; + fout[52] = spatial_metric_der[0][2][2]; + + fout[53] = spatial_metric_der[1][0][0]; + fout[54] = spatial_metric_der[1][0][1]; + fout[55] = spatial_metric_der[1][0][2]; + fout[56] = spatial_metric_der[1][1][0]; + fout[57] = spatial_metric_der[1][1][1]; + fout[58] = spatial_metric_der[1][1][2]; + fout[59] = spatial_metric_der[1][2][0]; + fout[60] = spatial_metric_der[1][2][1]; + fout[61] = spatial_metric_der[1][2][2]; + + fout[62] = spatial_metric_der[2][0][0]; + fout[63] = spatial_metric_der[2][0][1]; + fout[64] = spatial_metric_der[2][0][2]; + fout[65] = spatial_metric_der[2][1][0]; + fout[66] = spatial_metric_der[2][1][1]; + fout[67] = spatial_metric_der[2][1][2]; + fout[68] = spatial_metric_der[2][2][0]; + fout[69] = spatial_metric_der[2][2][1]; + fout[70] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[71] = 0.0; // Set spatial coordinates. - fout[72] = x; fout[73] = y; fout[74] = 0.0; + fout[72] = x; + fout[73] = y; + fout[74] = 0.0; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -408,8 +468,7 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -423,24 +482,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -461,12 +521,15 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new(ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new( + ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_mhd", .equation = gr_mhd, - + .init = evalGRMHDInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -474,8 +537,8 @@ main(int argc, char **argv) .has_gr_mhd = true, .gr_mhd_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -486,7 +549,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -494,8 +557,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -509,22 +571,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -548,9 +600,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -558,13 +610,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -578,10 +627,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -590,26 +643,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -625,7 +683,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -640,8 +698,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -649,7 +706,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -657,8 +716,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -685,14 +743,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_mhd); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_mhd_bhl_static_tetrad.c b/moments/creg/rt_gr_mhd_bhl_static_tetrad.c index 6fbde8fa91..7748210acc 100644 --- a/moments/creg/rt_gr_mhd_bhl_static_tetrad.c +++ b/moments/creg/rt_gr_mhd_bhl_static_tetrad.c @@ -19,8 +19,7 @@ #include -struct bhl_static_mhd_ctx -{ +struct bhl_static_mhd_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -68,8 +67,7 @@ struct bhl_static_mhd_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_static_mhd_ctx -create_ctx(void) +struct bhl_static_mhd_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -96,7 +94,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -116,7 +115,7 @@ create_ctx(void) int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double x_loc = 1.0; // Shock location (x-direction). - + struct bhl_static_mhd_ctx ctx = { .gas_gamma = gas_gamma, .rhol = rhol, @@ -147,14 +146,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMHDTetradInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct bhl_static_mhd_ctx *app = ctx; @@ -186,36 +186,35 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -226,17 +225,29 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -250,7 +261,9 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR } double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = 0.0; mag[1] = B0; mag[2] = 0.0; + mag[0] = 0.0; + mag[1] = B0; + mag[2] = 0.0; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -303,12 +316,16 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR double h_star = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))) + (b_sq / rho); double p_star = p + (0.5 * b_sq); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. - double mom_x = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); // Fluid momentum density (x-direction). + double mom_x = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]) + ); // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); // Fluid total energy density. + double Etot = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W) + ); // Fluid total energy density. double Bx_rel = 0.0; // Fluid relativistic magnetic field (x-direction). double By_rel = sqrt(spatial_det) * B0; // Fluid relativistic magnetic field (y-direction). @@ -317,63 +334,108 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set fluid relativistic magnetic field. - fout[5] = Bx_rel; fout[6] = By_rel; fout[7] = Bz_rel; + fout[5] = Bx_rel; + fout[6] = By_rel; + fout[7] = Bz_rel; // Set correction potential. fout[8] = 0.0; // Set lapse gauge variable. fout[9] = lapse; // Set shift gauge variables. - fout[10] = shift[0]; fout[11] = shift[1]; fout[12] = shift[2]; + fout[10] = shift[0]; + fout[11] = shift[1]; + fout[12] = shift[2]; // Set spatial metric tensor. - fout[13] = spatial_metric[0][0]; fout[14] = spatial_metric[0][1]; fout[15] = spatial_metric[0][2]; - fout[16] = spatial_metric[1][0]; fout[17] = spatial_metric[1][1]; fout[18] = spatial_metric[1][2]; - fout[19] = spatial_metric[2][0]; fout[20] = spatial_metric[2][1]; fout[21] = spatial_metric[2][2]; + fout[13] = spatial_metric[0][0]; + fout[14] = spatial_metric[0][1]; + fout[15] = spatial_metric[0][2]; + fout[16] = spatial_metric[1][0]; + fout[17] = spatial_metric[1][1]; + fout[18] = spatial_metric[1][2]; + fout[19] = spatial_metric[2][0]; + fout[20] = spatial_metric[2][1]; + fout[21] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[22] = extrinsic_curvature[0][0]; fout[23] = extrinsic_curvature[0][1]; fout[24] = extrinsic_curvature[0][2]; - fout[25] = extrinsic_curvature[1][0]; fout[26] = extrinsic_curvature[1][1]; fout[27] = extrinsic_curvature[1][2]; - fout[28] = extrinsic_curvature[2][0]; fout[29] = extrinsic_curvature[2][1]; fout[30] = extrinsic_curvature[2][2]; + fout[22] = extrinsic_curvature[0][0]; + fout[23] = extrinsic_curvature[0][1]; + fout[24] = extrinsic_curvature[0][2]; + fout[25] = extrinsic_curvature[1][0]; + fout[26] = extrinsic_curvature[1][1]; + fout[27] = extrinsic_curvature[1][2]; + fout[28] = extrinsic_curvature[2][0]; + fout[29] = extrinsic_curvature[2][1]; + fout[30] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[31] = -1.0; - } - else { + } else { fout[31] = 1.0; } // Set lapse function derivatives. - fout[32] = lapse_der[0]; fout[33] = lapse_der[1]; fout[34] = lapse_der[2]; + fout[32] = lapse_der[0]; + fout[33] = lapse_der[1]; + fout[34] = lapse_der[2]; // Set shift vector derivatives. - fout[35] = shift_der[0][0]; fout[36] = shift_der[0][1]; fout[37] = shift_der[0][2]; - fout[38] = shift_der[1][0]; fout[39] = shift_der[1][1]; fout[40] = shift_der[1][2]; - fout[41] = shift_der[2][0]; fout[42] = shift_der[2][1]; fout[43] = shift_der[2][2]; + fout[35] = shift_der[0][0]; + fout[36] = shift_der[0][1]; + fout[37] = shift_der[0][2]; + fout[38] = shift_der[1][0]; + fout[39] = shift_der[1][1]; + fout[40] = shift_der[1][2]; + fout[41] = shift_der[2][0]; + fout[42] = shift_der[2][1]; + fout[43] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[44] = spatial_metric_der[0][0][0]; fout[45] = spatial_metric_der[0][0][1]; fout[46] = spatial_metric_der[0][0][2]; - fout[47] = spatial_metric_der[0][1][0]; fout[48] = spatial_metric_der[0][1][1]; fout[49] = spatial_metric_der[0][1][2]; - fout[50] = spatial_metric_der[0][2][0]; fout[51] = spatial_metric_der[0][2][1]; fout[52] = spatial_metric_der[0][2][2]; - - fout[53] = spatial_metric_der[1][0][0]; fout[54] = spatial_metric_der[1][0][1]; fout[55] = spatial_metric_der[1][0][2]; - fout[56] = spatial_metric_der[1][1][0]; fout[57] = spatial_metric_der[1][1][1]; fout[58] = spatial_metric_der[1][1][2]; - fout[59] = spatial_metric_der[1][2][0]; fout[60] = spatial_metric_der[1][2][1]; fout[61] = spatial_metric_der[1][2][2]; - - fout[62] = spatial_metric_der[2][0][0]; fout[63] = spatial_metric_der[2][0][1]; fout[64] = spatial_metric_der[2][0][2]; - fout[65] = spatial_metric_der[2][1][0]; fout[66] = spatial_metric_der[2][1][1]; fout[67] = spatial_metric_der[2][1][2]; - fout[68] = spatial_metric_der[2][2][0]; fout[69] = spatial_metric_der[2][2][1]; fout[70] = spatial_metric_der[2][2][2]; + fout[44] = spatial_metric_der[0][0][0]; + fout[45] = spatial_metric_der[0][0][1]; + fout[46] = spatial_metric_der[0][0][2]; + fout[47] = spatial_metric_der[0][1][0]; + fout[48] = spatial_metric_der[0][1][1]; + fout[49] = spatial_metric_der[0][1][2]; + fout[50] = spatial_metric_der[0][2][0]; + fout[51] = spatial_metric_der[0][2][1]; + fout[52] = spatial_metric_der[0][2][2]; + + fout[53] = spatial_metric_der[1][0][0]; + fout[54] = spatial_metric_der[1][0][1]; + fout[55] = spatial_metric_der[1][0][2]; + fout[56] = spatial_metric_der[1][1][0]; + fout[57] = spatial_metric_der[1][1][1]; + fout[58] = spatial_metric_der[1][1][2]; + fout[59] = spatial_metric_der[1][2][0]; + fout[60] = spatial_metric_der[1][2][1]; + fout[61] = spatial_metric_der[1][2][2]; + + fout[62] = spatial_metric_der[2][0][0]; + fout[63] = spatial_metric_der[2][0][1]; + fout[64] = spatial_metric_der[2][0][2]; + fout[65] = spatial_metric_der[2][1][0]; + fout[66] = spatial_metric_der[2][1][1]; + fout[67] = spatial_metric_der[2][1][2]; + fout[68] = spatial_metric_der[2][2][0]; + fout[69] = spatial_metric_der[2][2][1]; + fout[70] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[71] = 0.0; // Set spatial coordinates. - fout[72] = x; fout[73] = y; fout[74] = 0.0; + fout[72] = x; + fout[73] = y; + fout[74] = 0.0; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -408,8 +470,7 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -423,24 +484,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -461,12 +523,15 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new(ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new( + ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_mhd_tetrad", .equation = gr_mhd_tetrad, - + .init = evalGRMHDTetradInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -474,8 +539,8 @@ main(int argc, char **argv) .has_gr_mhd = true, .gr_mhd_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -486,7 +551,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -494,8 +559,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -509,22 +573,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -548,9 +602,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -558,13 +612,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -578,10 +629,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -590,26 +645,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -625,7 +685,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -640,8 +700,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -649,7 +708,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -657,8 +718,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -685,14 +745,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_mhd_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_mhd_blackhole_collapse.c b/moments/creg/rt_gr_mhd_blackhole_collapse.c index 49c76664d3..ddc489fce5 100644 --- a/moments/creg/rt_gr_mhd_blackhole_collapse.c +++ b/moments/creg/rt_gr_mhd_blackhole_collapse.c @@ -19,8 +19,7 @@ #include -struct mhd_blackhole_collapse_ctx -{ +struct mhd_blackhole_collapse_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -68,8 +67,7 @@ struct mhd_blackhole_collapse_ctx double r_star; // Star radius. }; -struct mhd_blackhole_collapse_ctx -create_ctx(void) +struct mhd_blackhole_collapse_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -96,7 +94,8 @@ create_ctx(void) double pos_z = 0.0; // Predicted position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -105,7 +104,8 @@ create_ctx(void) double Ly = 5.0; // Domain size (y-direction). double cfl_frac = 0.9; // CFL coefficient. - enum gkyl_spacetime_gauge spacetime_gauge = GKYL_BLACKHOLE_COLLAPSE_GAUGE; // Spacetime gauge choice. + enum gkyl_spacetime_gauge spacetime_gauge = + GKYL_BLACKHOLE_COLLAPSE_GAUGE; // Spacetime gauge choice. int reinit_freq = 100; // Spacetime reinitialization frequency. double t_end = 2.0; // Final simulation time. @@ -147,14 +147,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .r_star = r_star, + .r_star = r_star }; return ctx; } -void -evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMHDInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct mhd_blackhole_collapse_ctx *app = ctx; @@ -191,37 +190,36 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo u = -omega_s * (y - (0.5 * Ly)); // Fluid velocity (star). v = omega_s * (x - (0.5 * Lx)); p = ps; // Fluid pressure (star). - } - else { + } else { rho = rhob; // Fluid mass density (background). u = -omega_b * (y - (0.5 * Ly)); // Fluid velocity (background). v = omega_b * (x - (0.5 * Lx)); p = pb; // Fluid pressure (background). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -232,17 +230,29 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = v; vel[2] = 0.0; + vel[0] = u; + vel[1] = v; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -256,7 +266,9 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo } double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = 0.0; mag[1] = B0; mag[2] = 0.0; + mag[0] = 0.0; + mag[1] = B0; + mag[2] = 0.0; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -309,12 +321,18 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double h_star = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))) + (b_sq / rho); double p_star = p + (0.5 * b_sq); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. - double mom_x = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); // Fluid momentum density (x-direction). - double mom_y = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); // Fluid momentum density (y-direction). + double mom_x = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]) + ); // Fluid momentum density (x-direction). + double mom_y = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1]) + ); // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); // Fluid total energy density. + double Etot = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W) + ); // Fluid total energy density. double Bx_rel = 0.0; // Fluid relativistic magnetic field (x-direction). double By_rel = sqrt(spatial_det) * B0; // Fluid relativistic magnetic field (y-direction). @@ -323,63 +341,108 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set fluid relativistic magnetic field. - fout[5] = Bx_rel; fout[6] = By_rel; fout[7] = Bz_rel; + fout[5] = Bx_rel; + fout[6] = By_rel; + fout[7] = Bz_rel; // Set correction potential. fout[8] = 0.0; // Set lapse gauge variable. fout[9] = lapse; // Set shift gauge variables. - fout[10] = shift[0]; fout[11] = shift[1]; fout[12] = shift[2]; + fout[10] = shift[0]; + fout[11] = shift[1]; + fout[12] = shift[2]; // Set spatial metric tensor. - fout[13] = spatial_metric[0][0]; fout[14] = spatial_metric[0][1]; fout[15] = spatial_metric[0][2]; - fout[16] = spatial_metric[1][0]; fout[17] = spatial_metric[1][1]; fout[18] = spatial_metric[1][2]; - fout[19] = spatial_metric[2][0]; fout[20] = spatial_metric[2][1]; fout[21] = spatial_metric[2][2]; + fout[13] = spatial_metric[0][0]; + fout[14] = spatial_metric[0][1]; + fout[15] = spatial_metric[0][2]; + fout[16] = spatial_metric[1][0]; + fout[17] = spatial_metric[1][1]; + fout[18] = spatial_metric[1][2]; + fout[19] = spatial_metric[2][0]; + fout[20] = spatial_metric[2][1]; + fout[21] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[22] = extrinsic_curvature[0][0]; fout[23] = extrinsic_curvature[0][1]; fout[24] = extrinsic_curvature[0][2]; - fout[25] = extrinsic_curvature[1][0]; fout[26] = extrinsic_curvature[1][1]; fout[27] = extrinsic_curvature[1][2]; - fout[28] = extrinsic_curvature[2][0]; fout[29] = extrinsic_curvature[2][1]; fout[30] = extrinsic_curvature[2][2]; + fout[22] = extrinsic_curvature[0][0]; + fout[23] = extrinsic_curvature[0][1]; + fout[24] = extrinsic_curvature[0][2]; + fout[25] = extrinsic_curvature[1][0]; + fout[26] = extrinsic_curvature[1][1]; + fout[27] = extrinsic_curvature[1][2]; + fout[28] = extrinsic_curvature[2][0]; + fout[29] = extrinsic_curvature[2][1]; + fout[30] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[31] = -1.0; - } - else { + } else { fout[31] = 1.0; } // Set lapse function derivatives. - fout[32] = lapse_der[0]; fout[33] = lapse_der[1]; fout[34] = lapse_der[2]; + fout[32] = lapse_der[0]; + fout[33] = lapse_der[1]; + fout[34] = lapse_der[2]; // Set shift vector derivatives. - fout[35] = shift_der[0][0]; fout[36] = shift_der[0][1]; fout[37] = shift_der[0][2]; - fout[38] = shift_der[1][0]; fout[39] = shift_der[1][1]; fout[40] = shift_der[1][2]; - fout[41] = shift_der[2][0]; fout[42] = shift_der[2][1]; fout[43] = shift_der[2][2]; + fout[35] = shift_der[0][0]; + fout[36] = shift_der[0][1]; + fout[37] = shift_der[0][2]; + fout[38] = shift_der[1][0]; + fout[39] = shift_der[1][1]; + fout[40] = shift_der[1][2]; + fout[41] = shift_der[2][0]; + fout[42] = shift_der[2][1]; + fout[43] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[44] = spatial_metric_der[0][0][0]; fout[45] = spatial_metric_der[0][0][1]; fout[46] = spatial_metric_der[0][0][2]; - fout[47] = spatial_metric_der[0][1][0]; fout[48] = spatial_metric_der[0][1][1]; fout[49] = spatial_metric_der[0][1][2]; - fout[50] = spatial_metric_der[0][2][0]; fout[51] = spatial_metric_der[0][2][1]; fout[52] = spatial_metric_der[0][2][2]; - - fout[53] = spatial_metric_der[1][0][0]; fout[54] = spatial_metric_der[1][0][1]; fout[55] = spatial_metric_der[1][0][2]; - fout[56] = spatial_metric_der[1][1][0]; fout[57] = spatial_metric_der[1][1][1]; fout[58] = spatial_metric_der[1][1][2]; - fout[59] = spatial_metric_der[1][2][0]; fout[60] = spatial_metric_der[1][2][1]; fout[61] = spatial_metric_der[1][2][2]; - - fout[62] = spatial_metric_der[2][0][0]; fout[63] = spatial_metric_der[2][0][1]; fout[64] = spatial_metric_der[2][0][2]; - fout[65] = spatial_metric_der[2][1][0]; fout[66] = spatial_metric_der[2][1][1]; fout[67] = spatial_metric_der[2][1][2]; - fout[68] = spatial_metric_der[2][2][0]; fout[69] = spatial_metric_der[2][2][1]; fout[70] = spatial_metric_der[2][2][2]; + fout[44] = spatial_metric_der[0][0][0]; + fout[45] = spatial_metric_der[0][0][1]; + fout[46] = spatial_metric_der[0][0][2]; + fout[47] = spatial_metric_der[0][1][0]; + fout[48] = spatial_metric_der[0][1][1]; + fout[49] = spatial_metric_der[0][1][2]; + fout[50] = spatial_metric_der[0][2][0]; + fout[51] = spatial_metric_der[0][2][1]; + fout[52] = spatial_metric_der[0][2][2]; + + fout[53] = spatial_metric_der[1][0][0]; + fout[54] = spatial_metric_der[1][0][1]; + fout[55] = spatial_metric_der[1][0][2]; + fout[56] = spatial_metric_der[1][1][0]; + fout[57] = spatial_metric_der[1][1][1]; + fout[58] = spatial_metric_der[1][1][2]; + fout[59] = spatial_metric_der[1][2][0]; + fout[60] = spatial_metric_der[1][2][1]; + fout[61] = spatial_metric_der[1][2][2]; + + fout[62] = spatial_metric_der[2][0][0]; + fout[63] = spatial_metric_der[2][0][1]; + fout[64] = spatial_metric_der[2][0][2]; + fout[65] = spatial_metric_der[2][1][0]; + fout[66] = spatial_metric_der[2][1][1]; + fout[67] = spatial_metric_der[2][1][2]; + fout[68] = spatial_metric_der[2][2][0]; + fout[69] = spatial_metric_der[2][2][1]; + fout[70] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[71] = 0.0; // Set spatial coordinates. - fout[72] = x; fout[73] = y; fout[74] = 0.0; + fout[72] = x; + fout[73] = y; + fout[74] = 0.0; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -408,8 +471,7 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -423,24 +485,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -461,12 +524,15 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new(ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new( + ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_mhd", .equation = gr_mhd, - + .init = evalGRMHDInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -474,8 +540,8 @@ main(int argc, char **argv) .has_gr_mhd = true, .gr_mhd_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -486,7 +552,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -494,8 +560,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -509,22 +574,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -548,9 +603,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -558,13 +613,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -578,10 +630,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -590,26 +646,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -625,7 +686,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -640,8 +701,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -649,7 +709,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -657,8 +719,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -685,14 +746,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_mhd); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_mhd_brio_wu.c b/moments/creg/rt_gr_mhd_brio_wu.c index e45f8e4935..76d00b4dea 100644 --- a/moments/creg/rt_gr_mhd_brio_wu.c +++ b/moments/creg/rt_gr_mhd_brio_wu.c @@ -18,8 +18,7 @@ #include -struct mhd_brio_wu_ctx -{ +struct mhd_brio_wu_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -59,8 +58,7 @@ struct mhd_brio_wu_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct mhd_brio_wu_ctx -create_ctx(void) +struct mhd_brio_wu_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 2.0; // Adiabatic index. @@ -125,14 +123,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMHDInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct mhd_brio_wu_ctx *app = ctx; @@ -169,8 +166,7 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo Bx = Bxl; // Fluid magnetic field (x-direction, left). By = Byl; // Fluid magnetic field (y-direction, left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -183,25 +179,25 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -212,17 +208,28 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -236,7 +243,9 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo } double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = Bx; mag[1] = By; mag[2] = 0.0; + mag[0] = Bx; + mag[1] = By; + mag[2] = 0.0; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -291,10 +300,16 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double p_star = p + (0.5 * b_sq); double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. - double mom_x = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); // Fluid momentum density (x-direction). - double mom_y = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); // Fluid momentum density (y-direction). + double mom_x = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]) + ); // Fluid momentum density (x-direction). + double mom_y = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1]) + ); // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); // Fluid total energy density. + double Etot = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W) + ); // Fluid total energy density. double Bx_rel = sqrt(spatial_det) * Bx; // Fluid relativistic magnetic field (x-direction). double By_rel = sqrt(spatial_det) * By; // Fluid relativistic magnetic field (y-direction). @@ -303,63 +318,108 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set fluid relativistic magnetic field. - fout[5] = Bx_rel; fout[6] = By_rel; fout[7] = Bz_rel; + fout[5] = Bx_rel; + fout[6] = By_rel; + fout[7] = Bz_rel; // Set correction potential. fout[8] = 0.0; // Set lapse gauge variable. fout[9] = lapse; // Set shift gauge variables. - fout[10] = shift[0]; fout[11] = shift[1]; fout[12] = shift[2]; + fout[10] = shift[0]; + fout[11] = shift[1]; + fout[12] = shift[2]; // Set spatial metric tensor. - fout[13] = spatial_metric[0][0]; fout[14] = spatial_metric[0][1]; fout[15] = spatial_metric[0][2]; - fout[16] = spatial_metric[1][0]; fout[17] = spatial_metric[1][1]; fout[18] = spatial_metric[1][2]; - fout[19] = spatial_metric[2][0]; fout[20] = spatial_metric[2][1]; fout[21] = spatial_metric[2][2]; + fout[13] = spatial_metric[0][0]; + fout[14] = spatial_metric[0][1]; + fout[15] = spatial_metric[0][2]; + fout[16] = spatial_metric[1][0]; + fout[17] = spatial_metric[1][1]; + fout[18] = spatial_metric[1][2]; + fout[19] = spatial_metric[2][0]; + fout[20] = spatial_metric[2][1]; + fout[21] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[22] = extrinsic_curvature[0][0]; fout[23] = extrinsic_curvature[0][1]; fout[24] = extrinsic_curvature[0][2]; - fout[25] = extrinsic_curvature[1][0]; fout[26] = extrinsic_curvature[1][1]; fout[27] = extrinsic_curvature[1][2]; - fout[28] = extrinsic_curvature[2][0]; fout[29] = extrinsic_curvature[2][1]; fout[30] = extrinsic_curvature[2][2]; + fout[22] = extrinsic_curvature[0][0]; + fout[23] = extrinsic_curvature[0][1]; + fout[24] = extrinsic_curvature[0][2]; + fout[25] = extrinsic_curvature[1][0]; + fout[26] = extrinsic_curvature[1][1]; + fout[27] = extrinsic_curvature[1][2]; + fout[28] = extrinsic_curvature[2][0]; + fout[29] = extrinsic_curvature[2][1]; + fout[30] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[31] = -1.0; - } - else { + } else { fout[31] = 1.0; } // Set lapse function derivatives. - fout[32] = lapse_der[0]; fout[33] = lapse_der[1]; fout[34] = lapse_der[2]; + fout[32] = lapse_der[0]; + fout[33] = lapse_der[1]; + fout[34] = lapse_der[2]; // Set shift vector derivatives. - fout[35] = shift_der[0][0]; fout[36] = shift_der[0][1]; fout[37] = shift_der[0][2]; - fout[38] = shift_der[1][0]; fout[39] = shift_der[1][1]; fout[40] = shift_der[1][2]; - fout[41] = shift_der[2][0]; fout[42] = shift_der[2][1]; fout[43] = shift_der[2][2]; + fout[35] = shift_der[0][0]; + fout[36] = shift_der[0][1]; + fout[37] = shift_der[0][2]; + fout[38] = shift_der[1][0]; + fout[39] = shift_der[1][1]; + fout[40] = shift_der[1][2]; + fout[41] = shift_der[2][0]; + fout[42] = shift_der[2][1]; + fout[43] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[44] = spatial_metric_der[0][0][0]; fout[45] = spatial_metric_der[0][0][1]; fout[46] = spatial_metric_der[0][0][2]; - fout[47] = spatial_metric_der[0][1][0]; fout[48] = spatial_metric_der[0][1][1]; fout[49] = spatial_metric_der[0][1][2]; - fout[50] = spatial_metric_der[0][2][0]; fout[51] = spatial_metric_der[0][2][1]; fout[52] = spatial_metric_der[0][2][2]; - - fout[53] = spatial_metric_der[1][0][0]; fout[54] = spatial_metric_der[1][0][1]; fout[55] = spatial_metric_der[1][0][2]; - fout[56] = spatial_metric_der[1][1][0]; fout[57] = spatial_metric_der[1][1][1]; fout[58] = spatial_metric_der[1][1][2]; - fout[59] = spatial_metric_der[1][2][0]; fout[60] = spatial_metric_der[1][2][1]; fout[61] = spatial_metric_der[1][2][2]; - - fout[62] = spatial_metric_der[2][0][0]; fout[63] = spatial_metric_der[2][0][1]; fout[64] = spatial_metric_der[2][0][2]; - fout[65] = spatial_metric_der[2][1][0]; fout[66] = spatial_metric_der[2][1][1]; fout[67] = spatial_metric_der[2][1][2]; - fout[68] = spatial_metric_der[2][2][0]; fout[69] = spatial_metric_der[2][2][1]; fout[70] = spatial_metric_der[2][2][2]; + fout[44] = spatial_metric_der[0][0][0]; + fout[45] = spatial_metric_der[0][0][1]; + fout[46] = spatial_metric_der[0][0][2]; + fout[47] = spatial_metric_der[0][1][0]; + fout[48] = spatial_metric_der[0][1][1]; + fout[49] = spatial_metric_der[0][1][2]; + fout[50] = spatial_metric_der[0][2][0]; + fout[51] = spatial_metric_der[0][2][1]; + fout[52] = spatial_metric_der[0][2][2]; + + fout[53] = spatial_metric_der[1][0][0]; + fout[54] = spatial_metric_der[1][0][1]; + fout[55] = spatial_metric_der[1][0][2]; + fout[56] = spatial_metric_der[1][1][0]; + fout[57] = spatial_metric_der[1][1][1]; + fout[58] = spatial_metric_der[1][1][2]; + fout[59] = spatial_metric_der[1][2][0]; + fout[60] = spatial_metric_der[1][2][1]; + fout[61] = spatial_metric_der[1][2][2]; + + fout[62] = spatial_metric_der[2][0][0]; + fout[63] = spatial_metric_der[2][0][1]; + fout[64] = spatial_metric_der[2][0][2]; + fout[65] = spatial_metric_der[2][1][0]; + fout[66] = spatial_metric_der[2][1][1]; + fout[67] = spatial_metric_der[2][1][2]; + fout[68] = spatial_metric_der[2][2][0]; + fout[69] = spatial_metric_der[2][2][1]; + fout[70] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[71] = 0.0; // Set spatial coordinates. - fout[72] = x; fout[73] = 0.0; fout[74] = 0.0; + fout[72] = x; + fout[73] = 0.0; + fout[74] = 0.0; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -394,8 +454,7 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -409,24 +468,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -446,21 +506,24 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new(ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new( + ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_mhd", .equation = gr_mhd, - + .init = evalGRMHDInit, .force_low_order_flux = false, // Use HLL fluxes. .limiter = GKYL_MIN_MOD, .ctx = &ctx, - + .has_gr_mhd = true, .gr_mhd_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -471,7 +534,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -479,8 +542,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -494,22 +556,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -533,20 +585,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -560,10 +608,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -572,26 +624,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -607,7 +664,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -622,8 +679,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -631,7 +687,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -639,8 +697,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -667,14 +724,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_mhd); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_mhd_brio_wu_tetrad.c b/moments/creg/rt_gr_mhd_brio_wu_tetrad.c index ad7f70b783..173273cb3d 100644 --- a/moments/creg/rt_gr_mhd_brio_wu_tetrad.c +++ b/moments/creg/rt_gr_mhd_brio_wu_tetrad.c @@ -18,8 +18,7 @@ #include -struct mhd_brio_wu_ctx -{ +struct mhd_brio_wu_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -59,8 +58,7 @@ struct mhd_brio_wu_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct mhd_brio_wu_ctx -create_ctx(void) +struct mhd_brio_wu_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 2.0; // Adiabatic index. @@ -125,14 +123,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMHDTetradInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct mhd_brio_wu_ctx *app = ctx; @@ -169,8 +168,7 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR Bx = Bxl; // Fluid magnetic field (x-direction, left). By = Byl; // Fluid magnetic field (y-direction, left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -183,25 +181,25 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -212,17 +210,28 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -236,7 +245,9 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR } double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = Bx; mag[1] = By; mag[2] = 0.0; + mag[0] = Bx; + mag[1] = By; + mag[2] = 0.0; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -291,10 +302,16 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR double p_star = p + (0.5 * b_sq); double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. - double mom_x = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); // Fluid momentum density (x-direction). - double mom_y = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); // Fluid momentum density (y-direction). + double mom_x = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]) + ); // Fluid momentum density (x-direction). + double mom_y = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1]) + ); // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); // Fluid total energy density. + double Etot = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W) + ); // Fluid total energy density. double Bx_rel = sqrt(spatial_det) * Bx; // Fluid relativistic magnetic field (x-direction). double By_rel = sqrt(spatial_det) * By; // Fluid relativistic magnetic field (y-direction). @@ -303,63 +320,108 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set fluid relativistic magnetic field. - fout[5] = Bx_rel; fout[6] = By_rel; fout[7] = Bz_rel; + fout[5] = Bx_rel; + fout[6] = By_rel; + fout[7] = Bz_rel; // Set correction potential. fout[8] = 0.0; // Set lapse gauge variable. fout[9] = lapse; // Set shift gauge variables. - fout[10] = shift[0]; fout[11] = shift[1]; fout[12] = shift[2]; + fout[10] = shift[0]; + fout[11] = shift[1]; + fout[12] = shift[2]; // Set spatial metric tensor. - fout[13] = spatial_metric[0][0]; fout[14] = spatial_metric[0][1]; fout[15] = spatial_metric[0][2]; - fout[16] = spatial_metric[1][0]; fout[17] = spatial_metric[1][1]; fout[18] = spatial_metric[1][2]; - fout[19] = spatial_metric[2][0]; fout[20] = spatial_metric[2][1]; fout[21] = spatial_metric[2][2]; + fout[13] = spatial_metric[0][0]; + fout[14] = spatial_metric[0][1]; + fout[15] = spatial_metric[0][2]; + fout[16] = spatial_metric[1][0]; + fout[17] = spatial_metric[1][1]; + fout[18] = spatial_metric[1][2]; + fout[19] = spatial_metric[2][0]; + fout[20] = spatial_metric[2][1]; + fout[21] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[22] = extrinsic_curvature[0][0]; fout[23] = extrinsic_curvature[0][1]; fout[24] = extrinsic_curvature[0][2]; - fout[25] = extrinsic_curvature[1][0]; fout[26] = extrinsic_curvature[1][1]; fout[27] = extrinsic_curvature[1][2]; - fout[28] = extrinsic_curvature[2][0]; fout[29] = extrinsic_curvature[2][1]; fout[30] = extrinsic_curvature[2][2]; + fout[22] = extrinsic_curvature[0][0]; + fout[23] = extrinsic_curvature[0][1]; + fout[24] = extrinsic_curvature[0][2]; + fout[25] = extrinsic_curvature[1][0]; + fout[26] = extrinsic_curvature[1][1]; + fout[27] = extrinsic_curvature[1][2]; + fout[28] = extrinsic_curvature[2][0]; + fout[29] = extrinsic_curvature[2][1]; + fout[30] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[31] = -1.0; - } - else { + } else { fout[31] = 1.0; } // Set lapse function derivatives. - fout[32] = lapse_der[0]; fout[33] = lapse_der[1]; fout[34] = lapse_der[2]; + fout[32] = lapse_der[0]; + fout[33] = lapse_der[1]; + fout[34] = lapse_der[2]; // Set shift vector derivatives. - fout[35] = shift_der[0][0]; fout[36] = shift_der[0][1]; fout[37] = shift_der[0][2]; - fout[38] = shift_der[1][0]; fout[39] = shift_der[1][1]; fout[40] = shift_der[1][2]; - fout[41] = shift_der[2][0]; fout[42] = shift_der[2][1]; fout[43] = shift_der[2][2]; + fout[35] = shift_der[0][0]; + fout[36] = shift_der[0][1]; + fout[37] = shift_der[0][2]; + fout[38] = shift_der[1][0]; + fout[39] = shift_der[1][1]; + fout[40] = shift_der[1][2]; + fout[41] = shift_der[2][0]; + fout[42] = shift_der[2][1]; + fout[43] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[44] = spatial_metric_der[0][0][0]; fout[45] = spatial_metric_der[0][0][1]; fout[46] = spatial_metric_der[0][0][2]; - fout[47] = spatial_metric_der[0][1][0]; fout[48] = spatial_metric_der[0][1][1]; fout[49] = spatial_metric_der[0][1][2]; - fout[50] = spatial_metric_der[0][2][0]; fout[51] = spatial_metric_der[0][2][1]; fout[52] = spatial_metric_der[0][2][2]; - - fout[53] = spatial_metric_der[1][0][0]; fout[54] = spatial_metric_der[1][0][1]; fout[55] = spatial_metric_der[1][0][2]; - fout[56] = spatial_metric_der[1][1][0]; fout[57] = spatial_metric_der[1][1][1]; fout[58] = spatial_metric_der[1][1][2]; - fout[59] = spatial_metric_der[1][2][0]; fout[60] = spatial_metric_der[1][2][1]; fout[61] = spatial_metric_der[1][2][2]; - - fout[62] = spatial_metric_der[2][0][0]; fout[63] = spatial_metric_der[2][0][1]; fout[64] = spatial_metric_der[2][0][2]; - fout[65] = spatial_metric_der[2][1][0]; fout[66] = spatial_metric_der[2][1][1]; fout[67] = spatial_metric_der[2][1][2]; - fout[68] = spatial_metric_der[2][2][0]; fout[69] = spatial_metric_der[2][2][1]; fout[70] = spatial_metric_der[2][2][2]; + fout[44] = spatial_metric_der[0][0][0]; + fout[45] = spatial_metric_der[0][0][1]; + fout[46] = spatial_metric_der[0][0][2]; + fout[47] = spatial_metric_der[0][1][0]; + fout[48] = spatial_metric_der[0][1][1]; + fout[49] = spatial_metric_der[0][1][2]; + fout[50] = spatial_metric_der[0][2][0]; + fout[51] = spatial_metric_der[0][2][1]; + fout[52] = spatial_metric_der[0][2][2]; + + fout[53] = spatial_metric_der[1][0][0]; + fout[54] = spatial_metric_der[1][0][1]; + fout[55] = spatial_metric_der[1][0][2]; + fout[56] = spatial_metric_der[1][1][0]; + fout[57] = spatial_metric_der[1][1][1]; + fout[58] = spatial_metric_der[1][1][2]; + fout[59] = spatial_metric_der[1][2][0]; + fout[60] = spatial_metric_der[1][2][1]; + fout[61] = spatial_metric_der[1][2][2]; + + fout[62] = spatial_metric_der[2][0][0]; + fout[63] = spatial_metric_der[2][0][1]; + fout[64] = spatial_metric_der[2][0][2]; + fout[65] = spatial_metric_der[2][1][0]; + fout[66] = spatial_metric_der[2][1][1]; + fout[67] = spatial_metric_der[2][1][2]; + fout[68] = spatial_metric_der[2][2][0]; + fout[69] = spatial_metric_der[2][2][1]; + fout[70] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[71] = 0.0; // Set spatial coordinates. - fout[72] = x; fout[73] = 0.0; fout[74] = 0.0; + fout[72] = x; + fout[73] = 0.0; + fout[74] = 0.0; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -394,8 +456,7 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -409,24 +470,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -446,21 +508,24 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new(ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new( + ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_mhd_tetrad", .equation = gr_mhd_tetrad, - + .init = evalGRMHDTetradInit, .force_low_order_flux = false, // Use HLL fluxes. .limiter = GKYL_MIN_MOD, .ctx = &ctx, - + .has_gr_mhd = true, .gr_mhd_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -471,7 +536,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -479,8 +544,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -494,22 +558,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -533,20 +587,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -560,10 +610,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -572,26 +626,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -607,7 +666,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -622,8 +681,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -631,7 +689,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -639,8 +699,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -667,14 +726,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_mhd_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_mhd_strong_blast.c b/moments/creg/rt_gr_mhd_strong_blast.c index e793dd9c08..7a2a5a0e7c 100644 --- a/moments/creg/rt_gr_mhd_strong_blast.c +++ b/moments/creg/rt_gr_mhd_strong_blast.c @@ -18,8 +18,7 @@ #include -struct mhd_strong_blast_ctx -{ +struct mhd_strong_blast_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -61,8 +60,7 @@ struct mhd_strong_blast_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct mhd_strong_blast_ctx -create_ctx(void) +struct mhd_strong_blast_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -93,7 +91,7 @@ create_ctx(void) int Nx = 4096; // Cell count (x-direction). double Lx = 1.0; // Domain size (x-direction). double cfl_frac = 0.85; // CFL coefficient. - + enum gkyl_spacetime_gauge spacetime_gauge = GKYL_STATIC_GAUGE; // Spacetime gauge choice. int reinit_freq = 10; // Spacetime reinitialization frequency. @@ -103,7 +101,7 @@ create_ctx(void) int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct mhd_strong_blast_ctx ctx = { .gas_gamma = gas_gamma, .rhol = rhol, @@ -131,14 +129,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMHDInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct mhd_strong_blast_ctx *app = ctx; @@ -179,8 +176,7 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo Bx = Bxl; // Fluid magnetic field (x-direction, left). By = Byl; // Fluid magnetic field (y-direction, left). Bz = Bzl; // Fluid magnetic field (z-direction, left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -194,25 +190,25 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -223,17 +219,28 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -247,7 +254,9 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo } double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = Bx; mag[1] = By; mag[2] = Bz; + mag[0] = Bx; + mag[1] = By; + mag[2] = Bz; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -302,10 +311,18 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double p_star = p + (0.5 * b_sq); double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. - double mom_x = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); // Fluid momentum density (x-direction). - double mom_y = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); // Fluid momentum density (y-direction). - double mom_z = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); // Fluid total energy density. + double mom_x = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]) + ); // Fluid momentum density (x-direction). + double mom_y = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1]) + ); // Fluid momentum density (y-direction). + double mom_z = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2]) + ); // Fluid momentum density (z-direction). + double Etot = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W) + ); // Fluid total energy density. double Bx_rel = sqrt(spatial_det) * Bx; // Fluid relativistic magnetic field (x-direction). double By_rel = sqrt(spatial_det) * By; // Fluid relativistic magnetic field (y-direction). @@ -314,63 +331,108 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set fluid relativistic magnetic field. - fout[5] = Bx_rel; fout[6] = By_rel; fout[7] = Bz_rel; + fout[5] = Bx_rel; + fout[6] = By_rel; + fout[7] = Bz_rel; // Set correction potential. fout[8] = 0.0; // Set lapse gauge variable. fout[9] = lapse; // Set shift gauge variables. - fout[10] = shift[0]; fout[11] = shift[1]; fout[12] = shift[2]; + fout[10] = shift[0]; + fout[11] = shift[1]; + fout[12] = shift[2]; // Set spatial metric tensor. - fout[13] = spatial_metric[0][0]; fout[14] = spatial_metric[0][1]; fout[15] = spatial_metric[0][2]; - fout[16] = spatial_metric[1][0]; fout[17] = spatial_metric[1][1]; fout[18] = spatial_metric[1][2]; - fout[19] = spatial_metric[2][0]; fout[20] = spatial_metric[2][1]; fout[21] = spatial_metric[2][2]; + fout[13] = spatial_metric[0][0]; + fout[14] = spatial_metric[0][1]; + fout[15] = spatial_metric[0][2]; + fout[16] = spatial_metric[1][0]; + fout[17] = spatial_metric[1][1]; + fout[18] = spatial_metric[1][2]; + fout[19] = spatial_metric[2][0]; + fout[20] = spatial_metric[2][1]; + fout[21] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[22] = extrinsic_curvature[0][0]; fout[23] = extrinsic_curvature[0][1]; fout[24] = extrinsic_curvature[0][2]; - fout[25] = extrinsic_curvature[1][0]; fout[26] = extrinsic_curvature[1][1]; fout[27] = extrinsic_curvature[1][2]; - fout[28] = extrinsic_curvature[2][0]; fout[29] = extrinsic_curvature[2][1]; fout[30] = extrinsic_curvature[2][2]; + fout[22] = extrinsic_curvature[0][0]; + fout[23] = extrinsic_curvature[0][1]; + fout[24] = extrinsic_curvature[0][2]; + fout[25] = extrinsic_curvature[1][0]; + fout[26] = extrinsic_curvature[1][1]; + fout[27] = extrinsic_curvature[1][2]; + fout[28] = extrinsic_curvature[2][0]; + fout[29] = extrinsic_curvature[2][1]; + fout[30] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[31] = -1.0; - } - else { + } else { fout[31] = 1.0; } // Set lapse function derivatives. - fout[32] = lapse_der[0]; fout[33] = lapse_der[1]; fout[34] = lapse_der[2]; + fout[32] = lapse_der[0]; + fout[33] = lapse_der[1]; + fout[34] = lapse_der[2]; // Set shift vector derivatives. - fout[35] = shift_der[0][0]; fout[36] = shift_der[0][1]; fout[37] = shift_der[0][2]; - fout[38] = shift_der[1][0]; fout[39] = shift_der[1][1]; fout[40] = shift_der[1][2]; - fout[41] = shift_der[2][0]; fout[42] = shift_der[2][1]; fout[43] = shift_der[2][2]; + fout[35] = shift_der[0][0]; + fout[36] = shift_der[0][1]; + fout[37] = shift_der[0][2]; + fout[38] = shift_der[1][0]; + fout[39] = shift_der[1][1]; + fout[40] = shift_der[1][2]; + fout[41] = shift_der[2][0]; + fout[42] = shift_der[2][1]; + fout[43] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[44] = spatial_metric_der[0][0][0]; fout[45] = spatial_metric_der[0][0][1]; fout[46] = spatial_metric_der[0][0][2]; - fout[47] = spatial_metric_der[0][1][0]; fout[48] = spatial_metric_der[0][1][1]; fout[49] = spatial_metric_der[0][1][2]; - fout[50] = spatial_metric_der[0][2][0]; fout[51] = spatial_metric_der[0][2][1]; fout[52] = spatial_metric_der[0][2][2]; - - fout[53] = spatial_metric_der[1][0][0]; fout[54] = spatial_metric_der[1][0][1]; fout[55] = spatial_metric_der[1][0][2]; - fout[56] = spatial_metric_der[1][1][0]; fout[57] = spatial_metric_der[1][1][1]; fout[58] = spatial_metric_der[1][1][2]; - fout[59] = spatial_metric_der[1][2][0]; fout[60] = spatial_metric_der[1][2][1]; fout[61] = spatial_metric_der[1][2][2]; - - fout[62] = spatial_metric_der[2][0][0]; fout[63] = spatial_metric_der[2][0][1]; fout[64] = spatial_metric_der[2][0][2]; - fout[65] = spatial_metric_der[2][1][0]; fout[66] = spatial_metric_der[2][1][1]; fout[67] = spatial_metric_der[2][1][2]; - fout[68] = spatial_metric_der[2][2][0]; fout[69] = spatial_metric_der[2][2][1]; fout[70] = spatial_metric_der[2][2][2]; + fout[44] = spatial_metric_der[0][0][0]; + fout[45] = spatial_metric_der[0][0][1]; + fout[46] = spatial_metric_der[0][0][2]; + fout[47] = spatial_metric_der[0][1][0]; + fout[48] = spatial_metric_der[0][1][1]; + fout[49] = spatial_metric_der[0][1][2]; + fout[50] = spatial_metric_der[0][2][0]; + fout[51] = spatial_metric_der[0][2][1]; + fout[52] = spatial_metric_der[0][2][2]; + + fout[53] = spatial_metric_der[1][0][0]; + fout[54] = spatial_metric_der[1][0][1]; + fout[55] = spatial_metric_der[1][0][2]; + fout[56] = spatial_metric_der[1][1][0]; + fout[57] = spatial_metric_der[1][1][1]; + fout[58] = spatial_metric_der[1][1][2]; + fout[59] = spatial_metric_der[1][2][0]; + fout[60] = spatial_metric_der[1][2][1]; + fout[61] = spatial_metric_der[1][2][2]; + + fout[62] = spatial_metric_der[2][0][0]; + fout[63] = spatial_metric_der[2][0][1]; + fout[64] = spatial_metric_der[2][0][2]; + fout[65] = spatial_metric_der[2][1][0]; + fout[66] = spatial_metric_der[2][1][1]; + fout[67] = spatial_metric_der[2][1][2]; + fout[68] = spatial_metric_der[2][2][0]; + fout[69] = spatial_metric_der[2][2][1]; + fout[70] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[71] = 0.0; // Set spatial coordinates. - fout[72] = x; fout[73] = 0.0; fout[74] = 0.0; + fout[72] = x; + fout[73] = 0.0; + fout[74] = 0.0; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -405,8 +467,7 @@ evalGRMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -420,24 +481,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -457,12 +519,15 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new(ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new( + ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_mhd", .equation = gr_mhd, - + .init = evalGRMHDInit, .force_low_order_flux = false, // Use HLL fluxes. .limiter = GKYL_MIN_MOD, @@ -471,9 +536,9 @@ main(int argc, char **argv) .has_gr_mhd = true, .gr_mhd_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; - + int nrank = 1; // Number of processes in simulation. #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { @@ -482,7 +547,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -490,8 +555,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -505,22 +569,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -544,20 +598,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -571,10 +621,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -583,26 +637,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -618,7 +677,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -633,8 +692,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -642,7 +700,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -650,8 +710,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -678,14 +737,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_mhd); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_mhd_strong_blast_tetrad.c b/moments/creg/rt_gr_mhd_strong_blast_tetrad.c index ec59105ab7..f1d052f612 100644 --- a/moments/creg/rt_gr_mhd_strong_blast_tetrad.c +++ b/moments/creg/rt_gr_mhd_strong_blast_tetrad.c @@ -18,8 +18,7 @@ #include -struct mhd_strong_blast_ctx -{ +struct mhd_strong_blast_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -61,8 +60,7 @@ struct mhd_strong_blast_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct mhd_strong_blast_ctx -create_ctx(void) +struct mhd_strong_blast_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -93,7 +91,7 @@ create_ctx(void) int Nx = 4096; // Cell count (x-direction). double Lx = 1.0; // Domain size (x-direction). double cfl_frac = 0.85; // CFL coefficient. - + enum gkyl_spacetime_gauge spacetime_gauge = GKYL_STATIC_GAUGE; // Spacetime gauge choice. int reinit_freq = 10; // Spacetime reinitialization frequency. @@ -103,7 +101,7 @@ create_ctx(void) int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct mhd_strong_blast_ctx ctx = { .gas_gamma = gas_gamma, .rhol = rhol, @@ -131,14 +129,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMHDTetradInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct mhd_strong_blast_ctx *app = ctx; @@ -179,8 +178,7 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR Bx = Bxl; // Fluid magnetic field (x-direction, left). By = Byl; // Fluid magnetic field (y-direction, left). Bz = Bzl; // Fluid magnetic field (z-direction, left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -194,25 +192,25 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -223,17 +221,28 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -247,7 +256,9 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR } double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = Bx; mag[1] = By; mag[2] = Bz; + mag[0] = Bx; + mag[1] = By; + mag[2] = Bz; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -302,10 +313,18 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR double p_star = p + (0.5 * b_sq); double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. - double mom_x = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); // Fluid momentum density (x-direction). - double mom_y = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); // Fluid momentum density (y-direction). - double mom_z = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); // Fluid total energy density. + double mom_x = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]) + ); // Fluid momentum density (x-direction). + double mom_y = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1]) + ); // Fluid momentum density (y-direction). + double mom_z = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2]) + ); // Fluid momentum density (z-direction). + double Etot = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W) + ); // Fluid total energy density. double Bx_rel = sqrt(spatial_det) * Bx; // Fluid relativistic magnetic field (x-direction). double By_rel = sqrt(spatial_det) * By; // Fluid relativistic magnetic field (y-direction). @@ -314,63 +333,108 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set fluid relativistic magnetic field. - fout[5] = Bx_rel; fout[6] = By_rel; fout[7] = Bz_rel; + fout[5] = Bx_rel; + fout[6] = By_rel; + fout[7] = Bz_rel; // Set correction potential. fout[8] = 0.0; // Set lapse gauge variable. fout[9] = lapse; // Set shift gauge variables. - fout[10] = shift[0]; fout[11] = shift[1]; fout[12] = shift[2]; + fout[10] = shift[0]; + fout[11] = shift[1]; + fout[12] = shift[2]; // Set spatial metric tensor. - fout[13] = spatial_metric[0][0]; fout[14] = spatial_metric[0][1]; fout[15] = spatial_metric[0][2]; - fout[16] = spatial_metric[1][0]; fout[17] = spatial_metric[1][1]; fout[18] = spatial_metric[1][2]; - fout[19] = spatial_metric[2][0]; fout[20] = spatial_metric[2][1]; fout[21] = spatial_metric[2][2]; + fout[13] = spatial_metric[0][0]; + fout[14] = spatial_metric[0][1]; + fout[15] = spatial_metric[0][2]; + fout[16] = spatial_metric[1][0]; + fout[17] = spatial_metric[1][1]; + fout[18] = spatial_metric[1][2]; + fout[19] = spatial_metric[2][0]; + fout[20] = spatial_metric[2][1]; + fout[21] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[22] = extrinsic_curvature[0][0]; fout[23] = extrinsic_curvature[0][1]; fout[24] = extrinsic_curvature[0][2]; - fout[25] = extrinsic_curvature[1][0]; fout[26] = extrinsic_curvature[1][1]; fout[27] = extrinsic_curvature[1][2]; - fout[28] = extrinsic_curvature[2][0]; fout[29] = extrinsic_curvature[2][1]; fout[30] = extrinsic_curvature[2][2]; + fout[22] = extrinsic_curvature[0][0]; + fout[23] = extrinsic_curvature[0][1]; + fout[24] = extrinsic_curvature[0][2]; + fout[25] = extrinsic_curvature[1][0]; + fout[26] = extrinsic_curvature[1][1]; + fout[27] = extrinsic_curvature[1][2]; + fout[28] = extrinsic_curvature[2][0]; + fout[29] = extrinsic_curvature[2][1]; + fout[30] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[31] = -1.0; - } - else { + } else { fout[31] = 1.0; } // Set lapse function derivatives. - fout[32] = lapse_der[0]; fout[33] = lapse_der[1]; fout[34] = lapse_der[2]; + fout[32] = lapse_der[0]; + fout[33] = lapse_der[1]; + fout[34] = lapse_der[2]; // Set shift vector derivatives. - fout[35] = shift_der[0][0]; fout[36] = shift_der[0][1]; fout[37] = shift_der[0][2]; - fout[38] = shift_der[1][0]; fout[39] = shift_der[1][1]; fout[40] = shift_der[1][2]; - fout[41] = shift_der[2][0]; fout[42] = shift_der[2][1]; fout[43] = shift_der[2][2]; + fout[35] = shift_der[0][0]; + fout[36] = shift_der[0][1]; + fout[37] = shift_der[0][2]; + fout[38] = shift_der[1][0]; + fout[39] = shift_der[1][1]; + fout[40] = shift_der[1][2]; + fout[41] = shift_der[2][0]; + fout[42] = shift_der[2][1]; + fout[43] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[44] = spatial_metric_der[0][0][0]; fout[45] = spatial_metric_der[0][0][1]; fout[46] = spatial_metric_der[0][0][2]; - fout[47] = spatial_metric_der[0][1][0]; fout[48] = spatial_metric_der[0][1][1]; fout[49] = spatial_metric_der[0][1][2]; - fout[50] = spatial_metric_der[0][2][0]; fout[51] = spatial_metric_der[0][2][1]; fout[52] = spatial_metric_der[0][2][2]; - - fout[53] = spatial_metric_der[1][0][0]; fout[54] = spatial_metric_der[1][0][1]; fout[55] = spatial_metric_der[1][0][2]; - fout[56] = spatial_metric_der[1][1][0]; fout[57] = spatial_metric_der[1][1][1]; fout[58] = spatial_metric_der[1][1][2]; - fout[59] = spatial_metric_der[1][2][0]; fout[60] = spatial_metric_der[1][2][1]; fout[61] = spatial_metric_der[1][2][2]; - - fout[62] = spatial_metric_der[2][0][0]; fout[63] = spatial_metric_der[2][0][1]; fout[64] = spatial_metric_der[2][0][2]; - fout[65] = spatial_metric_der[2][1][0]; fout[66] = spatial_metric_der[2][1][1]; fout[67] = spatial_metric_der[2][1][2]; - fout[68] = spatial_metric_der[2][2][0]; fout[69] = spatial_metric_der[2][2][1]; fout[70] = spatial_metric_der[2][2][2]; + fout[44] = spatial_metric_der[0][0][0]; + fout[45] = spatial_metric_der[0][0][1]; + fout[46] = spatial_metric_der[0][0][2]; + fout[47] = spatial_metric_der[0][1][0]; + fout[48] = spatial_metric_der[0][1][1]; + fout[49] = spatial_metric_der[0][1][2]; + fout[50] = spatial_metric_der[0][2][0]; + fout[51] = spatial_metric_der[0][2][1]; + fout[52] = spatial_metric_der[0][2][2]; + + fout[53] = spatial_metric_der[1][0][0]; + fout[54] = spatial_metric_der[1][0][1]; + fout[55] = spatial_metric_der[1][0][2]; + fout[56] = spatial_metric_der[1][1][0]; + fout[57] = spatial_metric_der[1][1][1]; + fout[58] = spatial_metric_der[1][1][2]; + fout[59] = spatial_metric_der[1][2][0]; + fout[60] = spatial_metric_der[1][2][1]; + fout[61] = spatial_metric_der[1][2][2]; + + fout[62] = spatial_metric_der[2][0][0]; + fout[63] = spatial_metric_der[2][0][1]; + fout[64] = spatial_metric_der[2][0][2]; + fout[65] = spatial_metric_der[2][1][0]; + fout[66] = spatial_metric_der[2][1][1]; + fout[67] = spatial_metric_der[2][1][2]; + fout[68] = spatial_metric_der[2][2][0]; + fout[69] = spatial_metric_der[2][2][1]; + fout[70] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[71] = 0.0; // Set spatial coordinates. - fout[72] = x; fout[73] = 0.0; fout[74] = 0.0; + fout[72] = x; + fout[73] = 0.0; + fout[74] = 0.0; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -405,8 +469,7 @@ evalGRMHDTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTR gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -420,24 +483,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -457,12 +521,15 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new(ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new( + ctx.gas_gamma, ctx.light_speed, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_mhd_tetrad", .equation = gr_mhd_tetrad, - + .init = evalGRMHDTetradInit, .force_low_order_flux = false, // Use HLL fluxes. .limiter = GKYL_MIN_MOD, @@ -471,9 +538,9 @@ main(int argc, char **argv) .has_gr_mhd = true, .gr_mhd_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; - + int nrank = 1; // Number of processes in simulation. #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { @@ -482,7 +549,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -490,8 +557,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -505,22 +571,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -544,20 +600,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -571,10 +623,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -583,26 +639,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -618,7 +679,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -633,8 +694,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -642,7 +702,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -650,8 +712,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -678,14 +739,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_mhd_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_mild_shock.c b/moments/creg/rt_gr_mild_shock.c index 869fc6fe98..94792834ff 100644 --- a/moments/creg/rt_gr_mild_shock.c +++ b/moments/creg/rt_gr_mild_shock.c @@ -24,8 +24,7 @@ #include -struct mild_shock_ctx -{ +struct mild_shock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -56,8 +55,7 @@ struct mild_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct mild_shock_ctx -create_ctx(void) +struct mild_shock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -107,14 +105,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct mild_shock_ctx *app = ctx; @@ -139,8 +136,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -150,25 +146,25 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -179,17 +175,28 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -208,63 +215,107 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = 0.0; fout[70] = 0.0; + fout[68] = x; + fout[69] = 0.0; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -293,8 +344,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -308,24 +358,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -345,12 +396,14 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler", .equation = gr_euler, - + .init = evalGREulerInit, .force_low_order_flux = false, // Use HLL fluxes. .limiter = GKYL_MIN_MOD, @@ -359,7 +412,7 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -370,7 +423,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -378,8 +431,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -393,22 +445,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -432,20 +474,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -459,10 +497,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -471,26 +513,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -506,7 +553,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -521,8 +568,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -530,7 +576,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -538,8 +586,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -566,14 +613,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_mild_shock_tetrad.c b/moments/creg/rt_gr_mild_shock_tetrad.c index 460bd4aa89..94527a7990 100644 --- a/moments/creg/rt_gr_mild_shock_tetrad.c +++ b/moments/creg/rt_gr_mild_shock_tetrad.c @@ -24,8 +24,7 @@ #include -struct mild_shock_ctx -{ +struct mild_shock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -56,8 +55,7 @@ struct mild_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct mild_shock_ctx -create_ctx(void) +struct mild_shock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -107,14 +105,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct mild_shock_ctx *app = ctx; @@ -139,8 +136,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -150,25 +146,25 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -179,17 +175,28 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -208,63 +215,107 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = 0.0; fout[70] = 0.0; + fout[68] = x; + fout[69] = 0.0; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -293,8 +344,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -308,24 +358,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -345,12 +396,14 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler_tetrad", .equation = gr_euler_tetrad, - + .init = evalGREulerInit, .force_low_order_flux = false, // Use HLL fluxes. .limiter = GKYL_MIN_MOD, @@ -359,7 +412,7 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -370,7 +423,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -378,8 +431,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -393,22 +445,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -432,20 +474,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -459,10 +497,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -471,26 +513,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -506,7 +553,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -521,8 +568,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -530,7 +576,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -538,8 +586,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -566,14 +613,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_multifluid_bhl_spinning.c b/moments/creg/rt_gr_multifluid_bhl_spinning.c index bfa366e447..22943b34cc 100644 --- a/moments/creg/rt_gr_multifluid_bhl_spinning.c +++ b/moments/creg/rt_gr_multifluid_bhl_spinning.c @@ -19,8 +19,7 @@ #include -struct bhl_spinning_multifluid_ctx -{ +struct bhl_spinning_multifluid_ctx { // Mathematical constants (dimensionless). double pi; @@ -81,8 +80,7 @@ struct bhl_spinning_multifluid_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_spinning_multifluid_ctx -create_ctx(void) +struct bhl_spinning_multifluid_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -122,7 +120,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -182,14 +181,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRTwoFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct bhl_spinning_multifluid_ctx *app = ctx; @@ -227,37 +227,36 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI rhoi = rhol_ion; // Ion mass density (left). u = ul; // Electron/ion velocity (left). p = pl; // Electron/ion pressure (left). - } - else { + } else { rhoe = rhor_elc; // Electron mass density (right). rhoi = rhor_ion; // Ion mass density (right). u = ur; // Electron/ion velocity (right). p = pr; // Electron/ion pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -268,17 +267,29 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -293,18 +304,22 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double he = 1.0 + ((p / rhoe) * (gas_gamma_elc / (gas_gamma_elc - 1.0))); double hi = 1.0 + ((p / rhoi) * (gas_gamma_ion / (gas_gamma_ion - 1.0))); - + double rhoe_rel = sqrt(spatial_det) * rhoe * W; // Electron relativistic mass density. - double mome_x = sqrt(spatial_det) * rhoe * he * (W * W) * u; // Electron momentum density (x-direction). + double mome_x = + sqrt(spatial_det) * rhoe * he * (W * W) * u; // Electron momentum density (x-direction). double mome_y = 0.0; // Electron momentum density (y-direction). double mome_z = 0.0; // Electron momentum density (z-direction). - double Ee_tot = sqrt(spatial_det) * ((rhoe * he * (W * W)) - p - (rhoe * W)); // Electron total energy density. + double Ee_tot = + sqrt(spatial_det) * ((rhoe * he * (W * W)) - p - (rhoe * W)); // Electron total energy density. double rhoi_rel = sqrt(spatial_det) * rhoi * W; // Ion relativistic mass density. - double momi_x = sqrt(spatial_det) * rhoi * hi * (W * W) * u; // Ion momentum density (x-direction). + double momi_x = + sqrt(spatial_det) * rhoi * hi * (W * W) * u; // Ion momentum density (x-direction). double momi_y = 0.0; // Ion momentum density (y-direction). double momi_z = 0.0; // Ion momentum density (z-direction). - double Ei_tot = sqrt(spatial_det) * ((rhoi * hi * (W * W)) - p - (rhoi * W)); // Ion total energy density. + double Ei_tot = + sqrt(spatial_det) * ((rhoi * hi * (W * W)) - p - (rhoi * W)); // Ion total energy density. double Dx = 0.0; // Total electric field (x-direction). double Dy = 0.0; // Total electric field (y-direction). @@ -317,72 +332,122 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI // Set electron relativistic mass density. fout[0] = rhoe_rel; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; // Set ion relativistic mass density. fout[5] = rhoi_rel; // Set ion momentum density. - fout[6] = momi_x; fout[7] = momi_y; fout[8] = momi_z; + fout[6] = momi_x; + fout[7] = momi_y; + fout[8] = momi_z; // Set ion total energy density. fout[9] = Ei_tot; // Set electric field. - fout[10] = Dx; fout[11] = Dy; fout[12] = Dz; + fout[10] = Dx; + fout[11] = Dy; + fout[12] = Dz; // Set magnetic field. - fout[13] = Bx; fout[14] = By; fout[15] = Bz; + fout[13] = Bx; + fout[14] = By; + fout[15] = Bz; // Set correction potentials. - fout[16] = 0.0; fout[17] = 0.0; + fout[16] = 0.0; + fout[17] = 0.0; // Set lapse gauge variable. fout[18] = lapse; // Set shift gauge variables. - fout[19] = shift[0]; fout[20] = shift[1]; fout[21] = shift[2]; + fout[19] = shift[0]; + fout[20] = shift[1]; + fout[21] = shift[2]; // Set spatial metric tensor. - fout[22] = spatial_metric[0][0]; fout[23] = spatial_metric[0][1]; fout[24] = spatial_metric[0][2]; - fout[25] = spatial_metric[1][0]; fout[26] = spatial_metric[1][1]; fout[27] = spatial_metric[1][2]; - fout[28] = spatial_metric[2][0]; fout[29] = spatial_metric[2][1]; fout[30] = spatial_metric[2][2]; + fout[22] = spatial_metric[0][0]; + fout[23] = spatial_metric[0][1]; + fout[24] = spatial_metric[0][2]; + fout[25] = spatial_metric[1][0]; + fout[26] = spatial_metric[1][1]; + fout[27] = spatial_metric[1][2]; + fout[28] = spatial_metric[2][0]; + fout[29] = spatial_metric[2][1]; + fout[30] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[31] = extrinsic_curvature[0][0]; fout[32] = extrinsic_curvature[0][1]; fout[33] = extrinsic_curvature[0][2]; - fout[34] = extrinsic_curvature[1][0]; fout[35] = extrinsic_curvature[1][1]; fout[36] = extrinsic_curvature[1][2]; - fout[37] = extrinsic_curvature[2][0]; fout[38] = extrinsic_curvature[2][1]; fout[39] = extrinsic_curvature[2][2]; + fout[31] = extrinsic_curvature[0][0]; + fout[32] = extrinsic_curvature[0][1]; + fout[33] = extrinsic_curvature[0][2]; + fout[34] = extrinsic_curvature[1][0]; + fout[35] = extrinsic_curvature[1][1]; + fout[36] = extrinsic_curvature[1][2]; + fout[37] = extrinsic_curvature[2][0]; + fout[38] = extrinsic_curvature[2][1]; + fout[39] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[40] = -1.0; - } - else { + } else { fout[40] = 1.0; } // Set lapse function derivatives. - fout[41] = lapse_der[0]; fout[42] = lapse_der[1]; fout[43] = lapse_der[2]; + fout[41] = lapse_der[0]; + fout[42] = lapse_der[1]; + fout[43] = lapse_der[2]; // Set shift vector derivatives. - fout[44] = shift_der[0][0]; fout[45] = shift_der[0][1]; fout[46] = shift_der[0][2]; - fout[47] = shift_der[1][0]; fout[48] = shift_der[1][1]; fout[49] = shift_der[1][2]; - fout[50] = shift_der[2][0]; fout[51] = shift_der[2][1]; fout[52] = shift_der[2][2]; + fout[44] = shift_der[0][0]; + fout[45] = shift_der[0][1]; + fout[46] = shift_der[0][2]; + fout[47] = shift_der[1][0]; + fout[48] = shift_der[1][1]; + fout[49] = shift_der[1][2]; + fout[50] = shift_der[2][0]; + fout[51] = shift_der[2][1]; + fout[52] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[53] = spatial_metric_der[0][0][0]; fout[54] = spatial_metric_der[0][0][1]; fout[55] = spatial_metric_der[0][0][2]; - fout[56] = spatial_metric_der[0][1][0]; fout[57] = spatial_metric_der[0][1][1]; fout[58] = spatial_metric_der[0][1][2]; - fout[59] = spatial_metric_der[0][2][0]; fout[60] = spatial_metric_der[0][2][1]; fout[61] = spatial_metric_der[0][2][2]; - - fout[62] = spatial_metric_der[1][0][0]; fout[63] = spatial_metric_der[1][0][1]; fout[64] = spatial_metric_der[1][0][2]; - fout[65] = spatial_metric_der[1][1][0]; fout[66] = spatial_metric_der[1][1][1]; fout[67] = spatial_metric_der[1][1][2]; - fout[68] = spatial_metric_der[1][2][0]; fout[69] = spatial_metric_der[1][2][1]; fout[70] = spatial_metric_der[1][2][2]; - - fout[71] = spatial_metric_der[2][0][0]; fout[72] = spatial_metric_der[2][0][1]; fout[73] = spatial_metric_der[2][0][2]; - fout[74] = spatial_metric_der[2][1][0]; fout[75] = spatial_metric_der[2][1][1]; fout[76] = spatial_metric_der[2][1][2]; - fout[77] = spatial_metric_der[2][2][0]; fout[78] = spatial_metric_der[2][2][1]; fout[79] = spatial_metric_der[2][2][2]; + fout[53] = spatial_metric_der[0][0][0]; + fout[54] = spatial_metric_der[0][0][1]; + fout[55] = spatial_metric_der[0][0][2]; + fout[56] = spatial_metric_der[0][1][0]; + fout[57] = spatial_metric_der[0][1][1]; + fout[58] = spatial_metric_der[0][1][2]; + fout[59] = spatial_metric_der[0][2][0]; + fout[60] = spatial_metric_der[0][2][1]; + fout[61] = spatial_metric_der[0][2][2]; + + fout[62] = spatial_metric_der[1][0][0]; + fout[63] = spatial_metric_der[1][0][1]; + fout[64] = spatial_metric_der[1][0][2]; + fout[65] = spatial_metric_der[1][1][0]; + fout[66] = spatial_metric_der[1][1][1]; + fout[67] = spatial_metric_der[1][1][2]; + fout[68] = spatial_metric_der[1][2][0]; + fout[69] = spatial_metric_der[1][2][1]; + fout[70] = spatial_metric_der[1][2][2]; + + fout[71] = spatial_metric_der[2][0][0]; + fout[72] = spatial_metric_der[2][0][1]; + fout[73] = spatial_metric_der[2][0][2]; + fout[74] = spatial_metric_der[2][1][0]; + fout[75] = spatial_metric_der[2][1][1]; + fout[76] = spatial_metric_der[2][1][2]; + fout[77] = spatial_metric_der[2][2][0]; + fout[78] = spatial_metric_der[2][2][1]; + fout[79] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[80] = 0.0; // Set spatial coordinates. - fout[81] = x; fout[82] = y; fout[83] = 0.0; + fout[81] = x; + fout[82] = y; + fout[83] = 0.0; if (in_excision_region) { for (int i = 0; i < 80; i++) { @@ -410,8 +475,7 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -425,24 +489,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -463,13 +528,16 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new(ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, ctx.gas_gamma_ion, - ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new( + ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, + ctx.gas_gamma_ion, ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, + ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species twofluid = { .name = "gr_twofluid", .equation = gr_twofluid, - + .init = evalGRTwoFluidInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -483,8 +551,8 @@ main(int argc, char **argv) .gr_twofluid_gas_gamma_ion = ctx.gas_gamma_ion, .gr_twofluid_e_fact = ctx.e_fact, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -495,7 +563,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -503,8 +571,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -518,22 +585,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -557,9 +614,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -567,13 +624,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { twofluid }, + .species = {twofluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -587,10 +641,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -599,26 +657,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -634,7 +697,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -649,8 +712,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -658,7 +720,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -666,8 +730,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -694,14 +757,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_twofluid); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_multifluid_bhl_spinning_tetrad.c b/moments/creg/rt_gr_multifluid_bhl_spinning_tetrad.c index 68a2811529..7650befaf8 100644 --- a/moments/creg/rt_gr_multifluid_bhl_spinning_tetrad.c +++ b/moments/creg/rt_gr_multifluid_bhl_spinning_tetrad.c @@ -19,8 +19,7 @@ #include -struct bhl_spinning_multifluid_ctx -{ +struct bhl_spinning_multifluid_ctx { // Mathematical constants (dimensionless). double pi; @@ -81,8 +80,7 @@ struct bhl_spinning_multifluid_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_spinning_multifluid_ctx -create_ctx(void) +struct bhl_spinning_multifluid_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -122,7 +120,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -182,14 +181,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRTwoFluidTetradInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct bhl_spinning_multifluid_ctx *app = ctx; @@ -227,37 +227,36 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ rhoi = rhol_ion; // Ion mass density (left). u = ul; // Electron/ion velocity (left). p = pl; // Electron/ion pressure (left). - } - else { + } else { rhoe = rhor_elc; // Electron mass density (right). rhoi = rhor_ion; // Ion mass density (right). u = ur; // Electron/ion velocity (right). p = pr; // Electron/ion pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -268,17 +267,29 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -293,18 +304,22 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double he = 1.0 + ((p / rhoe) * (gas_gamma_elc / (gas_gamma_elc - 1.0))); double hi = 1.0 + ((p / rhoi) * (gas_gamma_ion / (gas_gamma_ion - 1.0))); - + double rhoe_rel = sqrt(spatial_det) * rhoe * W; // Electron relativistic mass density. - double mome_x = sqrt(spatial_det) * rhoe * he * (W * W) * u; // Electron momentum density (x-direction). + double mome_x = + sqrt(spatial_det) * rhoe * he * (W * W) * u; // Electron momentum density (x-direction). double mome_y = 0.0; // Electron momentum density (y-direction). double mome_z = 0.0; // Electron momentum density (z-direction). - double Ee_tot = sqrt(spatial_det) * ((rhoe * he * (W * W)) - p - (rhoe * W)); // Electron total energy density. + double Ee_tot = + sqrt(spatial_det) * ((rhoe * he * (W * W)) - p - (rhoe * W)); // Electron total energy density. double rhoi_rel = sqrt(spatial_det) * rhoi * W; // Ion relativistic mass density. - double momi_x = sqrt(spatial_det) * rhoi * hi * (W * W) * u; // Ion momentum density (x-direction). + double momi_x = + sqrt(spatial_det) * rhoi * hi * (W * W) * u; // Ion momentum density (x-direction). double momi_y = 0.0; // Ion momentum density (y-direction). double momi_z = 0.0; // Ion momentum density (z-direction). - double Ei_tot = sqrt(spatial_det) * ((rhoi * hi * (W * W)) - p - (rhoi * W)); // Ion total energy density. + double Ei_tot = + sqrt(spatial_det) * ((rhoi * hi * (W * W)) - p - (rhoi * W)); // Ion total energy density. double Dx = 0.0; // Total electric field (x-direction). double Dy = 0.0; // Total electric field (y-direction). @@ -317,72 +332,122 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ // Set electron relativistic mass density. fout[0] = rhoe_rel; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; // Set ion relativistic mass density. fout[5] = rhoi_rel; // Set ion momentum density. - fout[6] = momi_x; fout[7] = momi_y; fout[8] = momi_z; + fout[6] = momi_x; + fout[7] = momi_y; + fout[8] = momi_z; // Set ion total energy density. fout[9] = Ei_tot; // Set electric field. - fout[10] = Dx; fout[11] = Dy; fout[12] = Dz; + fout[10] = Dx; + fout[11] = Dy; + fout[12] = Dz; // Set magnetic field. - fout[13] = Bx; fout[14] = By; fout[15] = Bz; + fout[13] = Bx; + fout[14] = By; + fout[15] = Bz; // Set correction potentials. - fout[16] = 0.0; fout[17] = 0.0; + fout[16] = 0.0; + fout[17] = 0.0; // Set lapse gauge variable. fout[18] = lapse; // Set shift gauge variables. - fout[19] = shift[0]; fout[20] = shift[1]; fout[21] = shift[2]; + fout[19] = shift[0]; + fout[20] = shift[1]; + fout[21] = shift[2]; // Set spatial metric tensor. - fout[22] = spatial_metric[0][0]; fout[23] = spatial_metric[0][1]; fout[24] = spatial_metric[0][2]; - fout[25] = spatial_metric[1][0]; fout[26] = spatial_metric[1][1]; fout[27] = spatial_metric[1][2]; - fout[28] = spatial_metric[2][0]; fout[29] = spatial_metric[2][1]; fout[30] = spatial_metric[2][2]; + fout[22] = spatial_metric[0][0]; + fout[23] = spatial_metric[0][1]; + fout[24] = spatial_metric[0][2]; + fout[25] = spatial_metric[1][0]; + fout[26] = spatial_metric[1][1]; + fout[27] = spatial_metric[1][2]; + fout[28] = spatial_metric[2][0]; + fout[29] = spatial_metric[2][1]; + fout[30] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[31] = extrinsic_curvature[0][0]; fout[32] = extrinsic_curvature[0][1]; fout[33] = extrinsic_curvature[0][2]; - fout[34] = extrinsic_curvature[1][0]; fout[35] = extrinsic_curvature[1][1]; fout[36] = extrinsic_curvature[1][2]; - fout[37] = extrinsic_curvature[2][0]; fout[38] = extrinsic_curvature[2][1]; fout[39] = extrinsic_curvature[2][2]; + fout[31] = extrinsic_curvature[0][0]; + fout[32] = extrinsic_curvature[0][1]; + fout[33] = extrinsic_curvature[0][2]; + fout[34] = extrinsic_curvature[1][0]; + fout[35] = extrinsic_curvature[1][1]; + fout[36] = extrinsic_curvature[1][2]; + fout[37] = extrinsic_curvature[2][0]; + fout[38] = extrinsic_curvature[2][1]; + fout[39] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[40] = -1.0; - } - else { + } else { fout[40] = 1.0; } // Set lapse function derivatives. - fout[41] = lapse_der[0]; fout[42] = lapse_der[1]; fout[43] = lapse_der[2]; + fout[41] = lapse_der[0]; + fout[42] = lapse_der[1]; + fout[43] = lapse_der[2]; // Set shift vector derivatives. - fout[44] = shift_der[0][0]; fout[45] = shift_der[0][1]; fout[46] = shift_der[0][2]; - fout[47] = shift_der[1][0]; fout[48] = shift_der[1][1]; fout[49] = shift_der[1][2]; - fout[50] = shift_der[2][0]; fout[51] = shift_der[2][1]; fout[52] = shift_der[2][2]; + fout[44] = shift_der[0][0]; + fout[45] = shift_der[0][1]; + fout[46] = shift_der[0][2]; + fout[47] = shift_der[1][0]; + fout[48] = shift_der[1][1]; + fout[49] = shift_der[1][2]; + fout[50] = shift_der[2][0]; + fout[51] = shift_der[2][1]; + fout[52] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[53] = spatial_metric_der[0][0][0]; fout[54] = spatial_metric_der[0][0][1]; fout[55] = spatial_metric_der[0][0][2]; - fout[56] = spatial_metric_der[0][1][0]; fout[57] = spatial_metric_der[0][1][1]; fout[58] = spatial_metric_der[0][1][2]; - fout[59] = spatial_metric_der[0][2][0]; fout[60] = spatial_metric_der[0][2][1]; fout[61] = spatial_metric_der[0][2][2]; - - fout[62] = spatial_metric_der[1][0][0]; fout[63] = spatial_metric_der[1][0][1]; fout[64] = spatial_metric_der[1][0][2]; - fout[65] = spatial_metric_der[1][1][0]; fout[66] = spatial_metric_der[1][1][1]; fout[67] = spatial_metric_der[1][1][2]; - fout[68] = spatial_metric_der[1][2][0]; fout[69] = spatial_metric_der[1][2][1]; fout[70] = spatial_metric_der[1][2][2]; - - fout[71] = spatial_metric_der[2][0][0]; fout[72] = spatial_metric_der[2][0][1]; fout[73] = spatial_metric_der[2][0][2]; - fout[74] = spatial_metric_der[2][1][0]; fout[75] = spatial_metric_der[2][1][1]; fout[76] = spatial_metric_der[2][1][2]; - fout[77] = spatial_metric_der[2][2][0]; fout[78] = spatial_metric_der[2][2][1]; fout[79] = spatial_metric_der[2][2][2]; + fout[53] = spatial_metric_der[0][0][0]; + fout[54] = spatial_metric_der[0][0][1]; + fout[55] = spatial_metric_der[0][0][2]; + fout[56] = spatial_metric_der[0][1][0]; + fout[57] = spatial_metric_der[0][1][1]; + fout[58] = spatial_metric_der[0][1][2]; + fout[59] = spatial_metric_der[0][2][0]; + fout[60] = spatial_metric_der[0][2][1]; + fout[61] = spatial_metric_der[0][2][2]; + + fout[62] = spatial_metric_der[1][0][0]; + fout[63] = spatial_metric_der[1][0][1]; + fout[64] = spatial_metric_der[1][0][2]; + fout[65] = spatial_metric_der[1][1][0]; + fout[66] = spatial_metric_der[1][1][1]; + fout[67] = spatial_metric_der[1][1][2]; + fout[68] = spatial_metric_der[1][2][0]; + fout[69] = spatial_metric_der[1][2][1]; + fout[70] = spatial_metric_der[1][2][2]; + + fout[71] = spatial_metric_der[2][0][0]; + fout[72] = spatial_metric_der[2][0][1]; + fout[73] = spatial_metric_der[2][0][2]; + fout[74] = spatial_metric_der[2][1][0]; + fout[75] = spatial_metric_der[2][1][1]; + fout[76] = spatial_metric_der[2][1][2]; + fout[77] = spatial_metric_der[2][2][0]; + fout[78] = spatial_metric_der[2][2][1]; + fout[79] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[80] = 0.0; // Set spatial coordinates. - fout[81] = x; fout[82] = y; fout[83] = 0.0; + fout[81] = x; + fout[82] = y; + fout[83] = 0.0; if (in_excision_region) { for (int i = 0; i < 80; i++) { @@ -410,8 +475,7 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -425,24 +489,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -463,13 +528,16 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new(ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, ctx.gas_gamma_ion, - ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new( + ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, + ctx.gas_gamma_ion, ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, + ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species twofluid_tetrad = { .name = "gr_twofluid_tetrad", .equation = gr_twofluid_tetrad, - + .init = evalGRTwoFluidTetradInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -483,8 +551,8 @@ main(int argc, char **argv) .gr_twofluid_gas_gamma_ion = ctx.gas_gamma_ion, .gr_twofluid_e_fact = ctx.e_fact, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -495,7 +563,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -503,8 +571,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -518,22 +585,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -557,9 +614,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -567,13 +624,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { twofluid_tetrad }, + .species = {twofluid_tetrad}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -587,10 +641,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -599,26 +657,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -634,7 +697,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -649,8 +712,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -658,7 +720,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -666,8 +730,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -694,14 +757,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_twofluid_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_multifluid_bhl_static.c b/moments/creg/rt_gr_multifluid_bhl_static.c index bfd7e84e1a..b27b66d13e 100644 --- a/moments/creg/rt_gr_multifluid_bhl_static.c +++ b/moments/creg/rt_gr_multifluid_bhl_static.c @@ -19,8 +19,7 @@ #include -struct bhl_static_multifluid_ctx -{ +struct bhl_static_multifluid_ctx { // Mathematical constants (dimensionless). double pi; @@ -81,8 +80,7 @@ struct bhl_static_multifluid_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_static_multifluid_ctx -create_ctx(void) +struct bhl_static_multifluid_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -122,7 +120,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -182,14 +181,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRTwoFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct bhl_static_multifluid_ctx *app = ctx; @@ -227,37 +227,36 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI rhoi = rhol_ion; // Ion mass density (left). u = ul; // Electron/ion velocity (left). p = pl; // Electron/ion pressure (left). - } - else { + } else { rhoe = rhor_elc; // Electron mass density (right). rhoi = rhor_ion; // Ion mass density (right). u = ur; // Electron/ion velocity (right). p = pr; // Electron/ion pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -268,17 +267,29 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -293,18 +304,22 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double he = 1.0 + ((p / rhoe) * (gas_gamma_elc / (gas_gamma_elc - 1.0))); double hi = 1.0 + ((p / rhoi) * (gas_gamma_ion / (gas_gamma_ion - 1.0))); - + double rhoe_rel = sqrt(spatial_det) * rhoe * W; // Electron relativistic mass density. - double mome_x = sqrt(spatial_det) * rhoe * he * (W * W) * u; // Electron momentum density (x-direction). + double mome_x = + sqrt(spatial_det) * rhoe * he * (W * W) * u; // Electron momentum density (x-direction). double mome_y = 0.0; // Electron momentum density (y-direction). double mome_z = 0.0; // Electron momentum density (z-direction). - double Ee_tot = sqrt(spatial_det) * ((rhoe * he * (W * W)) - p - (rhoe * W)); // Electron total energy density. + double Ee_tot = + sqrt(spatial_det) * ((rhoe * he * (W * W)) - p - (rhoe * W)); // Electron total energy density. double rhoi_rel = sqrt(spatial_det) * rhoi * W; // Ion relativistic mass density. - double momi_x = sqrt(spatial_det) * rhoi * hi * (W * W) * u; // Ion momentum density (x-direction). + double momi_x = + sqrt(spatial_det) * rhoi * hi * (W * W) * u; // Ion momentum density (x-direction). double momi_y = 0.0; // Ion momentum density (y-direction). double momi_z = 0.0; // Ion momentum density (z-direction). - double Ei_tot = sqrt(spatial_det) * ((rhoi * hi * (W * W)) - p - (rhoi * W)); // Ion total energy density. + double Ei_tot = + sqrt(spatial_det) * ((rhoi * hi * (W * W)) - p - (rhoi * W)); // Ion total energy density. double Dx = 0.0; // Total electric field (x-direction). double Dy = 0.0; // Total electric field (y-direction). @@ -317,72 +332,122 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI // Set electron relativistic mass density. fout[0] = rhoe_rel; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; // Set ion relativistic mass density. fout[5] = rhoi_rel; // Set ion momentum density. - fout[6] = momi_x; fout[7] = momi_y; fout[8] = momi_z; + fout[6] = momi_x; + fout[7] = momi_y; + fout[8] = momi_z; // Set ion total energy density. fout[9] = Ei_tot; // Set electric field. - fout[10] = Dx; fout[11] = Dy; fout[12] = Dz; + fout[10] = Dx; + fout[11] = Dy; + fout[12] = Dz; // Set magnetic field. - fout[13] = Bx; fout[14] = By; fout[15] = Bz; + fout[13] = Bx; + fout[14] = By; + fout[15] = Bz; // Set correction potentials. - fout[16] = 0.0; fout[17] = 0.0; + fout[16] = 0.0; + fout[17] = 0.0; // Set lapse gauge variable. fout[18] = lapse; // Set shift gauge variables. - fout[19] = shift[0]; fout[20] = shift[1]; fout[21] = shift[2]; + fout[19] = shift[0]; + fout[20] = shift[1]; + fout[21] = shift[2]; // Set spatial metric tensor. - fout[22] = spatial_metric[0][0]; fout[23] = spatial_metric[0][1]; fout[24] = spatial_metric[0][2]; - fout[25] = spatial_metric[1][0]; fout[26] = spatial_metric[1][1]; fout[27] = spatial_metric[1][2]; - fout[28] = spatial_metric[2][0]; fout[29] = spatial_metric[2][1]; fout[30] = spatial_metric[2][2]; + fout[22] = spatial_metric[0][0]; + fout[23] = spatial_metric[0][1]; + fout[24] = spatial_metric[0][2]; + fout[25] = spatial_metric[1][0]; + fout[26] = spatial_metric[1][1]; + fout[27] = spatial_metric[1][2]; + fout[28] = spatial_metric[2][0]; + fout[29] = spatial_metric[2][1]; + fout[30] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[31] = extrinsic_curvature[0][0]; fout[32] = extrinsic_curvature[0][1]; fout[33] = extrinsic_curvature[0][2]; - fout[34] = extrinsic_curvature[1][0]; fout[35] = extrinsic_curvature[1][1]; fout[36] = extrinsic_curvature[1][2]; - fout[37] = extrinsic_curvature[2][0]; fout[38] = extrinsic_curvature[2][1]; fout[39] = extrinsic_curvature[2][2]; + fout[31] = extrinsic_curvature[0][0]; + fout[32] = extrinsic_curvature[0][1]; + fout[33] = extrinsic_curvature[0][2]; + fout[34] = extrinsic_curvature[1][0]; + fout[35] = extrinsic_curvature[1][1]; + fout[36] = extrinsic_curvature[1][2]; + fout[37] = extrinsic_curvature[2][0]; + fout[38] = extrinsic_curvature[2][1]; + fout[39] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[40] = -1.0; - } - else { + } else { fout[40] = 1.0; } // Set lapse function derivatives. - fout[41] = lapse_der[0]; fout[42] = lapse_der[1]; fout[43] = lapse_der[2]; + fout[41] = lapse_der[0]; + fout[42] = lapse_der[1]; + fout[43] = lapse_der[2]; // Set shift vector derivatives. - fout[44] = shift_der[0][0]; fout[45] = shift_der[0][1]; fout[46] = shift_der[0][2]; - fout[47] = shift_der[1][0]; fout[48] = shift_der[1][1]; fout[49] = shift_der[1][2]; - fout[50] = shift_der[2][0]; fout[51] = shift_der[2][1]; fout[52] = shift_der[2][2]; + fout[44] = shift_der[0][0]; + fout[45] = shift_der[0][1]; + fout[46] = shift_der[0][2]; + fout[47] = shift_der[1][0]; + fout[48] = shift_der[1][1]; + fout[49] = shift_der[1][2]; + fout[50] = shift_der[2][0]; + fout[51] = shift_der[2][1]; + fout[52] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[53] = spatial_metric_der[0][0][0]; fout[54] = spatial_metric_der[0][0][1]; fout[55] = spatial_metric_der[0][0][2]; - fout[56] = spatial_metric_der[0][1][0]; fout[57] = spatial_metric_der[0][1][1]; fout[58] = spatial_metric_der[0][1][2]; - fout[59] = spatial_metric_der[0][2][0]; fout[60] = spatial_metric_der[0][2][1]; fout[61] = spatial_metric_der[0][2][2]; - - fout[62] = spatial_metric_der[1][0][0]; fout[63] = spatial_metric_der[1][0][1]; fout[64] = spatial_metric_der[1][0][2]; - fout[65] = spatial_metric_der[1][1][0]; fout[66] = spatial_metric_der[1][1][1]; fout[67] = spatial_metric_der[1][1][2]; - fout[68] = spatial_metric_der[1][2][0]; fout[69] = spatial_metric_der[1][2][1]; fout[70] = spatial_metric_der[1][2][2]; - - fout[71] = spatial_metric_der[2][0][0]; fout[72] = spatial_metric_der[2][0][1]; fout[73] = spatial_metric_der[2][0][2]; - fout[74] = spatial_metric_der[2][1][0]; fout[75] = spatial_metric_der[2][1][1]; fout[76] = spatial_metric_der[2][1][2]; - fout[77] = spatial_metric_der[2][2][0]; fout[78] = spatial_metric_der[2][2][1]; fout[79] = spatial_metric_der[2][2][2]; + fout[53] = spatial_metric_der[0][0][0]; + fout[54] = spatial_metric_der[0][0][1]; + fout[55] = spatial_metric_der[0][0][2]; + fout[56] = spatial_metric_der[0][1][0]; + fout[57] = spatial_metric_der[0][1][1]; + fout[58] = spatial_metric_der[0][1][2]; + fout[59] = spatial_metric_der[0][2][0]; + fout[60] = spatial_metric_der[0][2][1]; + fout[61] = spatial_metric_der[0][2][2]; + + fout[62] = spatial_metric_der[1][0][0]; + fout[63] = spatial_metric_der[1][0][1]; + fout[64] = spatial_metric_der[1][0][2]; + fout[65] = spatial_metric_der[1][1][0]; + fout[66] = spatial_metric_der[1][1][1]; + fout[67] = spatial_metric_der[1][1][2]; + fout[68] = spatial_metric_der[1][2][0]; + fout[69] = spatial_metric_der[1][2][1]; + fout[70] = spatial_metric_der[1][2][2]; + + fout[71] = spatial_metric_der[2][0][0]; + fout[72] = spatial_metric_der[2][0][1]; + fout[73] = spatial_metric_der[2][0][2]; + fout[74] = spatial_metric_der[2][1][0]; + fout[75] = spatial_metric_der[2][1][1]; + fout[76] = spatial_metric_der[2][1][2]; + fout[77] = spatial_metric_der[2][2][0]; + fout[78] = spatial_metric_der[2][2][1]; + fout[79] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[80] = 0.0; // Set spatial coordinates. - fout[81] = x; fout[82] = y; fout[83] = 0.0; + fout[81] = x; + fout[82] = y; + fout[83] = 0.0; if (in_excision_region) { for (int i = 0; i < 80; i++) { @@ -410,8 +475,7 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -425,24 +489,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -463,13 +528,16 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new(ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, ctx.gas_gamma_ion, - ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new( + ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, + ctx.gas_gamma_ion, ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, + ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species twofluid = { .name = "gr_twofluid", .equation = gr_twofluid, - + .init = evalGRTwoFluidInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -483,8 +551,8 @@ main(int argc, char **argv) .gr_twofluid_gas_gamma_ion = ctx.gas_gamma_ion, .gr_twofluid_e_fact = ctx.e_fact, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -495,7 +563,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -503,8 +571,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -518,22 +585,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -557,9 +614,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -567,13 +624,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { twofluid }, + .species = {twofluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -587,10 +641,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -599,26 +657,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -634,7 +697,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -649,8 +712,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -658,7 +720,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -666,8 +730,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -694,14 +757,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_twofluid); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_multifluid_bhl_static_tetrad.c b/moments/creg/rt_gr_multifluid_bhl_static_tetrad.c index 883fd746af..0bd4b16d7b 100644 --- a/moments/creg/rt_gr_multifluid_bhl_static_tetrad.c +++ b/moments/creg/rt_gr_multifluid_bhl_static_tetrad.c @@ -19,8 +19,7 @@ #include -struct bhl_static_multifluid_ctx -{ +struct bhl_static_multifluid_ctx { // Mathematical constants (dimensionless). double pi; @@ -81,8 +80,7 @@ struct bhl_static_multifluid_ctx double x_loc; // Shock location (x-direction). }; -struct bhl_static_multifluid_ctx -create_ctx(void) +struct bhl_static_multifluid_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -122,7 +120,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -182,14 +181,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRTwoFluidTetradInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct bhl_static_multifluid_ctx *app = ctx; @@ -227,37 +227,36 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ rhoi = rhol_ion; // Ion mass density (left). u = ul; // Electron/ion velocity (left). p = pl; // Electron/ion pressure (left). - } - else { + } else { rhoe = rhor_elc; // Electron mass density (right). rhoi = rhor_ion; // Ion mass density (right). u = ur; // Electron/ion velocity (right). p = pr; // Electron/ion pressure (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -268,17 +267,29 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -293,18 +304,22 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double he = 1.0 + ((p / rhoe) * (gas_gamma_elc / (gas_gamma_elc - 1.0))); double hi = 1.0 + ((p / rhoi) * (gas_gamma_ion / (gas_gamma_ion - 1.0))); - + double rhoe_rel = sqrt(spatial_det) * rhoe * W; // Electron relativistic mass density. - double mome_x = sqrt(spatial_det) * rhoe * he * (W * W) * u; // Electron momentum density (x-direction). + double mome_x = + sqrt(spatial_det) * rhoe * he * (W * W) * u; // Electron momentum density (x-direction). double mome_y = 0.0; // Electron momentum density (y-direction). double mome_z = 0.0; // Electron momentum density (z-direction). - double Ee_tot = sqrt(spatial_det) * ((rhoe * he * (W * W)) - p - (rhoe * W)); // Electron total energy density. + double Ee_tot = + sqrt(spatial_det) * ((rhoe * he * (W * W)) - p - (rhoe * W)); // Electron total energy density. double rhoi_rel = sqrt(spatial_det) * rhoi * W; // Ion relativistic mass density. - double momi_x = sqrt(spatial_det) * rhoi * hi * (W * W) * u; // Ion momentum density (x-direction). + double momi_x = + sqrt(spatial_det) * rhoi * hi * (W * W) * u; // Ion momentum density (x-direction). double momi_y = 0.0; // Ion momentum density (y-direction). double momi_z = 0.0; // Ion momentum density (z-direction). - double Ei_tot = sqrt(spatial_det) * ((rhoi * hi * (W * W)) - p - (rhoi * W)); // Ion total energy density. + double Ei_tot = + sqrt(spatial_det) * ((rhoi * hi * (W * W)) - p - (rhoi * W)); // Ion total energy density. double Dx = 0.0; // Total electric field (x-direction). double Dy = 0.0; // Total electric field (y-direction). @@ -317,72 +332,122 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ // Set electron relativistic mass density. fout[0] = rhoe_rel; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; // Set ion relativistic mass density. fout[5] = rhoi_rel; // Set ion momentum density. - fout[6] = momi_x; fout[7] = momi_y; fout[8] = momi_z; + fout[6] = momi_x; + fout[7] = momi_y; + fout[8] = momi_z; // Set ion total energy density. fout[9] = Ei_tot; // Set electric field. - fout[10] = Dx; fout[11] = Dy; fout[12] = Dz; + fout[10] = Dx; + fout[11] = Dy; + fout[12] = Dz; // Set magnetic field. - fout[13] = Bx; fout[14] = By; fout[15] = Bz; + fout[13] = Bx; + fout[14] = By; + fout[15] = Bz; // Set correction potentials. - fout[16] = 0.0; fout[17] = 0.0; + fout[16] = 0.0; + fout[17] = 0.0; // Set lapse gauge variable. fout[18] = lapse; // Set shift gauge variables. - fout[19] = shift[0]; fout[20] = shift[1]; fout[21] = shift[2]; + fout[19] = shift[0]; + fout[20] = shift[1]; + fout[21] = shift[2]; // Set spatial metric tensor. - fout[22] = spatial_metric[0][0]; fout[23] = spatial_metric[0][1]; fout[24] = spatial_metric[0][2]; - fout[25] = spatial_metric[1][0]; fout[26] = spatial_metric[1][1]; fout[27] = spatial_metric[1][2]; - fout[28] = spatial_metric[2][0]; fout[29] = spatial_metric[2][1]; fout[30] = spatial_metric[2][2]; + fout[22] = spatial_metric[0][0]; + fout[23] = spatial_metric[0][1]; + fout[24] = spatial_metric[0][2]; + fout[25] = spatial_metric[1][0]; + fout[26] = spatial_metric[1][1]; + fout[27] = spatial_metric[1][2]; + fout[28] = spatial_metric[2][0]; + fout[29] = spatial_metric[2][1]; + fout[30] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[31] = extrinsic_curvature[0][0]; fout[32] = extrinsic_curvature[0][1]; fout[33] = extrinsic_curvature[0][2]; - fout[34] = extrinsic_curvature[1][0]; fout[35] = extrinsic_curvature[1][1]; fout[36] = extrinsic_curvature[1][2]; - fout[37] = extrinsic_curvature[2][0]; fout[38] = extrinsic_curvature[2][1]; fout[39] = extrinsic_curvature[2][2]; + fout[31] = extrinsic_curvature[0][0]; + fout[32] = extrinsic_curvature[0][1]; + fout[33] = extrinsic_curvature[0][2]; + fout[34] = extrinsic_curvature[1][0]; + fout[35] = extrinsic_curvature[1][1]; + fout[36] = extrinsic_curvature[1][2]; + fout[37] = extrinsic_curvature[2][0]; + fout[38] = extrinsic_curvature[2][1]; + fout[39] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[40] = -1.0; - } - else { + } else { fout[40] = 1.0; } // Set lapse function derivatives. - fout[41] = lapse_der[0]; fout[42] = lapse_der[1]; fout[43] = lapse_der[2]; + fout[41] = lapse_der[0]; + fout[42] = lapse_der[1]; + fout[43] = lapse_der[2]; // Set shift vector derivatives. - fout[44] = shift_der[0][0]; fout[45] = shift_der[0][1]; fout[46] = shift_der[0][2]; - fout[47] = shift_der[1][0]; fout[48] = shift_der[1][1]; fout[49] = shift_der[1][2]; - fout[50] = shift_der[2][0]; fout[51] = shift_der[2][1]; fout[52] = shift_der[2][2]; + fout[44] = shift_der[0][0]; + fout[45] = shift_der[0][1]; + fout[46] = shift_der[0][2]; + fout[47] = shift_der[1][0]; + fout[48] = shift_der[1][1]; + fout[49] = shift_der[1][2]; + fout[50] = shift_der[2][0]; + fout[51] = shift_der[2][1]; + fout[52] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[53] = spatial_metric_der[0][0][0]; fout[54] = spatial_metric_der[0][0][1]; fout[55] = spatial_metric_der[0][0][2]; - fout[56] = spatial_metric_der[0][1][0]; fout[57] = spatial_metric_der[0][1][1]; fout[58] = spatial_metric_der[0][1][2]; - fout[59] = spatial_metric_der[0][2][0]; fout[60] = spatial_metric_der[0][2][1]; fout[61] = spatial_metric_der[0][2][2]; - - fout[62] = spatial_metric_der[1][0][0]; fout[63] = spatial_metric_der[1][0][1]; fout[64] = spatial_metric_der[1][0][2]; - fout[65] = spatial_metric_der[1][1][0]; fout[66] = spatial_metric_der[1][1][1]; fout[67] = spatial_metric_der[1][1][2]; - fout[68] = spatial_metric_der[1][2][0]; fout[69] = spatial_metric_der[1][2][1]; fout[70] = spatial_metric_der[1][2][2]; - - fout[71] = spatial_metric_der[2][0][0]; fout[72] = spatial_metric_der[2][0][1]; fout[73] = spatial_metric_der[2][0][2]; - fout[74] = spatial_metric_der[2][1][0]; fout[75] = spatial_metric_der[2][1][1]; fout[76] = spatial_metric_der[2][1][2]; - fout[77] = spatial_metric_der[2][2][0]; fout[78] = spatial_metric_der[2][2][1]; fout[79] = spatial_metric_der[2][2][2]; + fout[53] = spatial_metric_der[0][0][0]; + fout[54] = spatial_metric_der[0][0][1]; + fout[55] = spatial_metric_der[0][0][2]; + fout[56] = spatial_metric_der[0][1][0]; + fout[57] = spatial_metric_der[0][1][1]; + fout[58] = spatial_metric_der[0][1][2]; + fout[59] = spatial_metric_der[0][2][0]; + fout[60] = spatial_metric_der[0][2][1]; + fout[61] = spatial_metric_der[0][2][2]; + + fout[62] = spatial_metric_der[1][0][0]; + fout[63] = spatial_metric_der[1][0][1]; + fout[64] = spatial_metric_der[1][0][2]; + fout[65] = spatial_metric_der[1][1][0]; + fout[66] = spatial_metric_der[1][1][1]; + fout[67] = spatial_metric_der[1][1][2]; + fout[68] = spatial_metric_der[1][2][0]; + fout[69] = spatial_metric_der[1][2][1]; + fout[70] = spatial_metric_der[1][2][2]; + + fout[71] = spatial_metric_der[2][0][0]; + fout[72] = spatial_metric_der[2][0][1]; + fout[73] = spatial_metric_der[2][0][2]; + fout[74] = spatial_metric_der[2][1][0]; + fout[75] = spatial_metric_der[2][1][1]; + fout[76] = spatial_metric_der[2][1][2]; + fout[77] = spatial_metric_der[2][2][0]; + fout[78] = spatial_metric_der[2][2][1]; + fout[79] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[80] = 0.0; // Set spatial coordinates. - fout[81] = x; fout[82] = y; fout[83] = 0.0; + fout[81] = x; + fout[82] = y; + fout[83] = 0.0; if (in_excision_region) { for (int i = 0; i < 80; i++) { @@ -410,8 +475,7 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -425,24 +489,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -463,13 +528,16 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new(ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, ctx.gas_gamma_ion, - ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new( + ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, + ctx.gas_gamma_ion, ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, + ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species twofluid_tetrad = { .name = "gr_twofluid_tetrad", .equation = gr_twofluid_tetrad, - + .init = evalGRTwoFluidTetradInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -483,8 +551,8 @@ main(int argc, char **argv) .gr_twofluid_gas_gamma_ion = ctx.gas_gamma_ion, .gr_twofluid_e_fact = ctx.e_fact, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -495,7 +563,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -503,8 +571,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -518,22 +585,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -557,9 +614,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -567,13 +624,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { twofluid_tetrad }, + .species = {twofluid_tetrad}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -587,10 +641,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -599,26 +657,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -634,7 +697,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -649,8 +712,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -658,7 +720,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -666,8 +730,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -694,14 +757,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_twofluid_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_multifluid_brio_wu.c b/moments/creg/rt_gr_multifluid_brio_wu.c index 663084b8f1..5900e2ae69 100644 --- a/moments/creg/rt_gr_multifluid_brio_wu.c +++ b/moments/creg/rt_gr_multifluid_brio_wu.c @@ -18,8 +18,7 @@ #include -struct multifluid_brio_wu_ctx -{ +struct multifluid_brio_wu_ctx { // Physical constants (using normalized code units). double gas_gamma_elc; // Adiabatic index (electrons). double gas_gamma_ion; // Adiabatic index (ions). @@ -69,8 +68,7 @@ struct multifluid_brio_wu_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct multifluid_brio_wu_ctx -create_ctx(void) +struct multifluid_brio_wu_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma_elc = 2.0; // Adiabatic index (electrons). @@ -154,14 +152,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRTwoFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct multifluid_brio_wu_ctx *app = ctx; @@ -201,8 +200,7 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI rhoe = rhol_elc; // Electron mass density (left). rhoi = rhol_ion; // Ion mass density (left). p = pl; // Electron/ion pressure (left). - } - else { + } else { rhoe = rhor_elc; // Electron mass density (right). rhoi = rhor_ion; // Ion mass density (right). p = pr; // Electron/ion pressure (right). @@ -210,8 +208,7 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI if (x < 0.5 * Lx) { By = Byl; // Total magnetic field (y-direction, left). - } - else { + } else { By = Byr; // Total magnetic field (y-direction, right). } @@ -219,25 +216,25 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -248,13 +245,22 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double We = 1.0; double Wi = 1.0; @@ -266,83 +272,135 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI double mome_x = 0.0; // Electron momentum density (x-direction). double mome_y = 0.0; // Electron momentum density (y-direction). double mome_z = 0.0; // Electron momentum density (z-direction). - double Ee_tot = sqrt(spatial_det) * ((rhoe * he * (We * We)) - p - (rhoe * We)); // Electron total energy density. + double Ee_tot = sqrt(spatial_det) * + ((rhoe * he * (We * We)) - p - (rhoe * We)); // Electron total energy density. double rhoi_rel = sqrt(spatial_det) * rhoi * Wi; // Ion relativistic mass density. double momi_x = 0.0; // Ion momentum density (x-direction). double momi_y = 0.0; // Ion momentum density (y-direction). double momi_z = 0.0; // Ion momentum density (z-direction). - double Ei_tot = sqrt(spatial_det) * ((rhoi * hi * (Wi * Wi)) - p - (rhoi * Wi)); // Ion total energy density. + double Ei_tot = + sqrt(spatial_det) * ((rhoi * hi * (Wi * Wi)) - p - (rhoi * Wi)); // Ion total energy density. // Set electron relativistic mass density. fout[0] = rhoe_rel; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; // Set ion relativistic mass density. fout[5] = rhoi_rel; // Set ion momentum density. - fout[6] = momi_x; fout[7] = momi_y; fout[8] = momi_z; + fout[6] = momi_x; + fout[7] = momi_y; + fout[8] = momi_z; // Set ion total energy density. fout[9] = Ei_tot; // Set electric field. - fout[10] = Dx; fout[11] = Dy; fout[12] = Dz; + fout[10] = Dx; + fout[11] = Dy; + fout[12] = Dz; // Set magnetic field. - fout[13] = Bx; fout[14] = By; fout[15] = Bz; + fout[13] = Bx; + fout[14] = By; + fout[15] = Bz; // Set correction potentials. - fout[16] = 0.0; fout[17] = 0.0; + fout[16] = 0.0; + fout[17] = 0.0; // Set lapse gauge variable. fout[18] = lapse; // Set shift gauge variables. - fout[19] = shift[0]; fout[20] = shift[1]; fout[21] = shift[2]; + fout[19] = shift[0]; + fout[20] = shift[1]; + fout[21] = shift[2]; // Set spatial metric tensor. - fout[22] = spatial_metric[0][0]; fout[23] = spatial_metric[0][1]; fout[24] = spatial_metric[0][2]; - fout[25] = spatial_metric[1][0]; fout[26] = spatial_metric[1][1]; fout[27] = spatial_metric[1][2]; - fout[28] = spatial_metric[2][0]; fout[29] = spatial_metric[2][1]; fout[30] = spatial_metric[2][2]; + fout[22] = spatial_metric[0][0]; + fout[23] = spatial_metric[0][1]; + fout[24] = spatial_metric[0][2]; + fout[25] = spatial_metric[1][0]; + fout[26] = spatial_metric[1][1]; + fout[27] = spatial_metric[1][2]; + fout[28] = spatial_metric[2][0]; + fout[29] = spatial_metric[2][1]; + fout[30] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[31] = extrinsic_curvature[0][0]; fout[32] = extrinsic_curvature[0][1]; fout[33] = extrinsic_curvature[0][2]; - fout[34] = extrinsic_curvature[1][0]; fout[35] = extrinsic_curvature[1][1]; fout[36] = extrinsic_curvature[1][2]; - fout[37] = extrinsic_curvature[2][0]; fout[38] = extrinsic_curvature[2][1]; fout[39] = extrinsic_curvature[2][2]; + fout[31] = extrinsic_curvature[0][0]; + fout[32] = extrinsic_curvature[0][1]; + fout[33] = extrinsic_curvature[0][2]; + fout[34] = extrinsic_curvature[1][0]; + fout[35] = extrinsic_curvature[1][1]; + fout[36] = extrinsic_curvature[1][2]; + fout[37] = extrinsic_curvature[2][0]; + fout[38] = extrinsic_curvature[2][1]; + fout[39] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[40] = -1.0; - } - else { + } else { fout[40] = 1.0; } // Set lapse function derivatives. - fout[41] = lapse_der[0]; fout[42] = lapse_der[1]; fout[43] = lapse_der[2]; + fout[41] = lapse_der[0]; + fout[42] = lapse_der[1]; + fout[43] = lapse_der[2]; // Set shift vector derivatives. - fout[44] = shift_der[0][0]; fout[45] = shift_der[0][1]; fout[46] = shift_der[0][2]; - fout[47] = shift_der[1][0]; fout[48] = shift_der[1][1]; fout[49] = shift_der[1][2]; - fout[50] = shift_der[2][0]; fout[51] = shift_der[2][1]; fout[52] = shift_der[2][2]; + fout[44] = shift_der[0][0]; + fout[45] = shift_der[0][1]; + fout[46] = shift_der[0][2]; + fout[47] = shift_der[1][0]; + fout[48] = shift_der[1][1]; + fout[49] = shift_der[1][2]; + fout[50] = shift_der[2][0]; + fout[51] = shift_der[2][1]; + fout[52] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[53] = spatial_metric_der[0][0][0]; fout[54] = spatial_metric_der[0][0][1]; fout[55] = spatial_metric_der[0][0][2]; - fout[56] = spatial_metric_der[0][1][0]; fout[57] = spatial_metric_der[0][1][1]; fout[58] = spatial_metric_der[0][1][2]; - fout[59] = spatial_metric_der[0][2][0]; fout[60] = spatial_metric_der[0][2][1]; fout[61] = spatial_metric_der[0][2][2]; - - fout[62] = spatial_metric_der[1][0][0]; fout[63] = spatial_metric_der[1][0][1]; fout[64] = spatial_metric_der[1][0][2]; - fout[65] = spatial_metric_der[1][1][0]; fout[66] = spatial_metric_der[1][1][1]; fout[67] = spatial_metric_der[1][1][2]; - fout[68] = spatial_metric_der[1][2][0]; fout[69] = spatial_metric_der[1][2][1]; fout[70] = spatial_metric_der[1][2][2]; - - fout[71] = spatial_metric_der[2][0][0]; fout[72] = spatial_metric_der[2][0][1]; fout[73] = spatial_metric_der[2][0][2]; - fout[74] = spatial_metric_der[2][1][0]; fout[75] = spatial_metric_der[2][1][1]; fout[76] = spatial_metric_der[2][1][2]; - fout[77] = spatial_metric_der[2][2][0]; fout[78] = spatial_metric_der[2][2][1]; fout[79] = spatial_metric_der[2][2][2]; + fout[53] = spatial_metric_der[0][0][0]; + fout[54] = spatial_metric_der[0][0][1]; + fout[55] = spatial_metric_der[0][0][2]; + fout[56] = spatial_metric_der[0][1][0]; + fout[57] = spatial_metric_der[0][1][1]; + fout[58] = spatial_metric_der[0][1][2]; + fout[59] = spatial_metric_der[0][2][0]; + fout[60] = spatial_metric_der[0][2][1]; + fout[61] = spatial_metric_der[0][2][2]; + + fout[62] = spatial_metric_der[1][0][0]; + fout[63] = spatial_metric_der[1][0][1]; + fout[64] = spatial_metric_der[1][0][2]; + fout[65] = spatial_metric_der[1][1][0]; + fout[66] = spatial_metric_der[1][1][1]; + fout[67] = spatial_metric_der[1][1][2]; + fout[68] = spatial_metric_der[1][2][0]; + fout[69] = spatial_metric_der[1][2][1]; + fout[70] = spatial_metric_der[1][2][2]; + + fout[71] = spatial_metric_der[2][0][0]; + fout[72] = spatial_metric_der[2][0][1]; + fout[73] = spatial_metric_der[2][0][2]; + fout[74] = spatial_metric_der[2][1][0]; + fout[75] = spatial_metric_der[2][1][1]; + fout[76] = spatial_metric_der[2][1][2]; + fout[77] = spatial_metric_der[2][2][0]; + fout[78] = spatial_metric_der[2][2][1]; + fout[79] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[80] = 0.0; // Set spatial coordinates. - fout[81] = x; fout[82] = 0.0; fout[83] = 0.0; + fout[81] = x; + fout[82] = 0.0; + fout[83] = 0.0; if (in_excision_region) { for (int i = 0; i < 84; i++) { @@ -370,8 +428,7 @@ evalGRTwoFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -385,24 +442,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -422,13 +480,16 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new(ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, ctx.gas_gamma_ion, - ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new( + ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, + ctx.gas_gamma_ion, ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, + ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species twofluid = { .name = "gr_twofluid", .equation = gr_twofluid, - + .init = evalGRTwoFluidInit, .force_low_order_flux = false, // Use HLL fluxes. .limiter = GKYL_MIN_MOD, @@ -443,7 +504,7 @@ main(int argc, char **argv) .gr_twofluid_gas_gamma_ion = ctx.gas_gamma_ion, .gr_twofluid_e_fact = ctx.e_fact, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -454,7 +515,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -462,8 +523,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -477,22 +537,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -516,20 +566,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { twofluid }, + .species = {twofluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -543,10 +589,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -555,26 +605,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -590,7 +645,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -605,8 +660,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -614,7 +668,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -622,8 +678,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -650,14 +705,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_twofluid); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_multifluid_brio_wu_tetrad.c b/moments/creg/rt_gr_multifluid_brio_wu_tetrad.c index 513c54cf41..831393c2a5 100644 --- a/moments/creg/rt_gr_multifluid_brio_wu_tetrad.c +++ b/moments/creg/rt_gr_multifluid_brio_wu_tetrad.c @@ -18,8 +18,7 @@ #include -struct multifluid_brio_wu_ctx -{ +struct multifluid_brio_wu_ctx { // Physical constants (using normalized code units). double gas_gamma_elc; // Adiabatic index (electrons). double gas_gamma_ion; // Adiabatic index (ions). @@ -69,8 +68,7 @@ struct multifluid_brio_wu_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct multifluid_brio_wu_ctx -create_ctx(void) +struct multifluid_brio_wu_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma_elc = 2.0; // Adiabatic index (electrons). @@ -154,14 +152,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRTwoFluidTetradInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct multifluid_brio_wu_ctx *app = ctx; @@ -201,8 +200,7 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ rhoe = rhol_elc; // Electron mass density (left). rhoi = rhol_ion; // Ion mass density (left). p = pl; // Electron/ion pressure (left). - } - else { + } else { rhoe = rhor_elc; // Electron mass density (right). rhoi = rhor_ion; // Ion mass density (right). p = pr; // Electron/ion pressure (right). @@ -210,8 +208,7 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (x < 0.5 * Lx) { By = Byl; // Total magnetic field (y-direction, left). - } - else { + } else { By = Byr; // Total magnetic field (y-direction, right). } @@ -219,25 +216,25 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -248,13 +245,22 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double We = 1.0; double Wi = 1.0; @@ -266,83 +272,135 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ double mome_x = 0.0; // Electron momentum density (x-direction). double mome_y = 0.0; // Electron momentum density (y-direction). double mome_z = 0.0; // Electron momentum density (z-direction). - double Ee_tot = sqrt(spatial_det) * ((rhoe * he * (We * We)) - p - (rhoe * We)); // Electron total energy density. + double Ee_tot = sqrt(spatial_det) * + ((rhoe * he * (We * We)) - p - (rhoe * We)); // Electron total energy density. double rhoi_rel = sqrt(spatial_det) * rhoi * Wi; // Ion relativistic mass density. double momi_x = 0.0; // Ion momentum density (x-direction). double momi_y = 0.0; // Ion momentum density (y-direction). double momi_z = 0.0; // Ion momentum density (z-direction). - double Ei_tot = sqrt(spatial_det) * ((rhoi * hi * (Wi * Wi)) - p - (rhoi * Wi)); // Ion total energy density. + double Ei_tot = + sqrt(spatial_det) * ((rhoi * hi * (Wi * Wi)) - p - (rhoi * Wi)); // Ion total energy density. // Set electron relativistic mass density. fout[0] = rhoe_rel; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; // Set ion relativistic mass density. fout[5] = rhoi_rel; // Set ion momentum density. - fout[6] = momi_x; fout[7] = momi_y; fout[8] = momi_z; + fout[6] = momi_x; + fout[7] = momi_y; + fout[8] = momi_z; // Set ion total energy density. fout[9] = Ei_tot; // Set electric field. - fout[10] = Dx; fout[11] = Dy; fout[12] = Dz; + fout[10] = Dx; + fout[11] = Dy; + fout[12] = Dz; // Set magnetic field. - fout[13] = Bx; fout[14] = By; fout[15] = Bz; + fout[13] = Bx; + fout[14] = By; + fout[15] = Bz; // Set correction potentials. - fout[16] = 0.0; fout[17] = 0.0; + fout[16] = 0.0; + fout[17] = 0.0; // Set lapse gauge variable. fout[18] = lapse; // Set shift gauge variables. - fout[19] = shift[0]; fout[20] = shift[1]; fout[21] = shift[2]; + fout[19] = shift[0]; + fout[20] = shift[1]; + fout[21] = shift[2]; // Set spatial metric tensor. - fout[22] = spatial_metric[0][0]; fout[23] = spatial_metric[0][1]; fout[24] = spatial_metric[0][2]; - fout[25] = spatial_metric[1][0]; fout[26] = spatial_metric[1][1]; fout[27] = spatial_metric[1][2]; - fout[28] = spatial_metric[2][0]; fout[29] = spatial_metric[2][1]; fout[30] = spatial_metric[2][2]; + fout[22] = spatial_metric[0][0]; + fout[23] = spatial_metric[0][1]; + fout[24] = spatial_metric[0][2]; + fout[25] = spatial_metric[1][0]; + fout[26] = spatial_metric[1][1]; + fout[27] = spatial_metric[1][2]; + fout[28] = spatial_metric[2][0]; + fout[29] = spatial_metric[2][1]; + fout[30] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[31] = extrinsic_curvature[0][0]; fout[32] = extrinsic_curvature[0][1]; fout[33] = extrinsic_curvature[0][2]; - fout[34] = extrinsic_curvature[1][0]; fout[35] = extrinsic_curvature[1][1]; fout[36] = extrinsic_curvature[1][2]; - fout[37] = extrinsic_curvature[2][0]; fout[38] = extrinsic_curvature[2][1]; fout[39] = extrinsic_curvature[2][2]; + fout[31] = extrinsic_curvature[0][0]; + fout[32] = extrinsic_curvature[0][1]; + fout[33] = extrinsic_curvature[0][2]; + fout[34] = extrinsic_curvature[1][0]; + fout[35] = extrinsic_curvature[1][1]; + fout[36] = extrinsic_curvature[1][2]; + fout[37] = extrinsic_curvature[2][0]; + fout[38] = extrinsic_curvature[2][1]; + fout[39] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[40] = -1.0; - } - else { + } else { fout[40] = 1.0; } // Set lapse function derivatives. - fout[41] = lapse_der[0]; fout[42] = lapse_der[1]; fout[43] = lapse_der[2]; + fout[41] = lapse_der[0]; + fout[42] = lapse_der[1]; + fout[43] = lapse_der[2]; // Set shift vector derivatives. - fout[44] = shift_der[0][0]; fout[45] = shift_der[0][1]; fout[46] = shift_der[0][2]; - fout[47] = shift_der[1][0]; fout[48] = shift_der[1][1]; fout[49] = shift_der[1][2]; - fout[50] = shift_der[2][0]; fout[51] = shift_der[2][1]; fout[52] = shift_der[2][2]; + fout[44] = shift_der[0][0]; + fout[45] = shift_der[0][1]; + fout[46] = shift_der[0][2]; + fout[47] = shift_der[1][0]; + fout[48] = shift_der[1][1]; + fout[49] = shift_der[1][2]; + fout[50] = shift_der[2][0]; + fout[51] = shift_der[2][1]; + fout[52] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[53] = spatial_metric_der[0][0][0]; fout[54] = spatial_metric_der[0][0][1]; fout[55] = spatial_metric_der[0][0][2]; - fout[56] = spatial_metric_der[0][1][0]; fout[57] = spatial_metric_der[0][1][1]; fout[58] = spatial_metric_der[0][1][2]; - fout[59] = spatial_metric_der[0][2][0]; fout[60] = spatial_metric_der[0][2][1]; fout[61] = spatial_metric_der[0][2][2]; - - fout[62] = spatial_metric_der[1][0][0]; fout[63] = spatial_metric_der[1][0][1]; fout[64] = spatial_metric_der[1][0][2]; - fout[65] = spatial_metric_der[1][1][0]; fout[66] = spatial_metric_der[1][1][1]; fout[67] = spatial_metric_der[1][1][2]; - fout[68] = spatial_metric_der[1][2][0]; fout[69] = spatial_metric_der[1][2][1]; fout[70] = spatial_metric_der[1][2][2]; - - fout[71] = spatial_metric_der[2][0][0]; fout[72] = spatial_metric_der[2][0][1]; fout[73] = spatial_metric_der[2][0][2]; - fout[74] = spatial_metric_der[2][1][0]; fout[75] = spatial_metric_der[2][1][1]; fout[76] = spatial_metric_der[2][1][2]; - fout[77] = spatial_metric_der[2][2][0]; fout[78] = spatial_metric_der[2][2][1]; fout[79] = spatial_metric_der[2][2][2]; + fout[53] = spatial_metric_der[0][0][0]; + fout[54] = spatial_metric_der[0][0][1]; + fout[55] = spatial_metric_der[0][0][2]; + fout[56] = spatial_metric_der[0][1][0]; + fout[57] = spatial_metric_der[0][1][1]; + fout[58] = spatial_metric_der[0][1][2]; + fout[59] = spatial_metric_der[0][2][0]; + fout[60] = spatial_metric_der[0][2][1]; + fout[61] = spatial_metric_der[0][2][2]; + + fout[62] = spatial_metric_der[1][0][0]; + fout[63] = spatial_metric_der[1][0][1]; + fout[64] = spatial_metric_der[1][0][2]; + fout[65] = spatial_metric_der[1][1][0]; + fout[66] = spatial_metric_der[1][1][1]; + fout[67] = spatial_metric_der[1][1][2]; + fout[68] = spatial_metric_der[1][2][0]; + fout[69] = spatial_metric_der[1][2][1]; + fout[70] = spatial_metric_der[1][2][2]; + + fout[71] = spatial_metric_der[2][0][0]; + fout[72] = spatial_metric_der[2][0][1]; + fout[73] = spatial_metric_der[2][0][2]; + fout[74] = spatial_metric_der[2][1][0]; + fout[75] = spatial_metric_der[2][1][1]; + fout[76] = spatial_metric_der[2][1][2]; + fout[77] = spatial_metric_der[2][2][0]; + fout[78] = spatial_metric_der[2][2][1]; + fout[79] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[80] = 0.0; // Set spatial coordinates. - fout[81] = x; fout[82] = 0.0; fout[83] = 0.0; + fout[81] = x; + fout[82] = 0.0; + fout[83] = 0.0; if (in_excision_region) { for (int i = 0; i < 84; i++) { @@ -370,8 +428,7 @@ evalGRTwoFluidTetradInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -385,24 +442,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -422,13 +480,16 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new(ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, ctx.gas_gamma_ion, - ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new( + ctx.mass_elc, ctx.mass_ion, ctx.charge_elc, ctx.charge_ion, ctx.gas_gamma_elc, + ctx.gas_gamma_ion, ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, + ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species twofluid_tetrad = { .name = "gr_twofluid_tetrad", .equation = gr_twofluid_tetrad, - + .init = evalGRTwoFluidTetradInit, .force_low_order_flux = false, // Use HLL fluxes. .limiter = GKYL_MIN_MOD, @@ -443,7 +504,7 @@ main(int argc, char **argv) .gr_twofluid_gas_gamma_ion = ctx.gas_gamma_ion, .gr_twofluid_e_fact = ctx.e_fact, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -454,7 +515,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -462,8 +523,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -477,22 +537,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -516,20 +566,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { twofluid_tetrad }, + .species = {twofluid_tetrad}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -543,10 +589,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -555,26 +605,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -590,7 +645,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -605,8 +660,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -614,7 +668,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -622,8 +678,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -650,14 +705,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_twofluid_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_perturbed_density.c b/moments/creg/rt_gr_perturbed_density.c index a216e1d735..dab171033d 100644 --- a/moments/creg/rt_gr_perturbed_density.c +++ b/moments/creg/rt_gr_perturbed_density.c @@ -24,8 +24,7 @@ #include -struct perturbed_density_ctx -{ +struct perturbed_density_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -56,8 +55,7 @@ struct perturbed_density_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct perturbed_density_ctx -create_ctx(void) +struct perturbed_density_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -107,14 +105,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct perturbed_density_ctx *app = ctx; @@ -139,8 +136,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor + 0.3 * sin(50.0 * x); // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -150,25 +146,25 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -179,17 +175,28 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -208,63 +215,107 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = 0.0; fout[70] = 0.0; + fout[68] = x; + fout[69] = 0.0; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -293,8 +344,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -308,24 +358,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -345,12 +396,14 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler", .equation = gr_euler, - + .init = evalGREulerInit, .force_low_order_flux = false, // Use HLL fluxes. .limiter = GKYL_MIN_MOD, @@ -359,7 +412,7 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -370,7 +423,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -378,8 +431,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -393,22 +445,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -432,20 +474,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -459,10 +497,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -471,26 +513,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -506,7 +553,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -521,8 +568,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -530,7 +576,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -538,8 +586,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -566,14 +613,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_quadrants_2d.c b/moments/creg/rt_gr_quadrants_2d.c index f0517859be..b3fac10b67 100644 --- a/moments/creg/rt_gr_quadrants_2d.c +++ b/moments/creg/rt_gr_quadrants_2d.c @@ -24,8 +24,7 @@ #include -struct quadrants_2d_ctx -{ +struct quadrants_2d_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -38,7 +37,7 @@ struct quadrants_2d_ctx double u_ur; // Upper right fluid x-velocity. double v_ur; // Upper right fluid y-velocity. double p_ur; // Upper left fluid pressure. - + double rho_ll; // Lower left fluid mass density. double u_ll; // Lower left fluid x-velocity. double v_ll; // Lower left fluid y-velocity. @@ -72,8 +71,7 @@ struct quadrants_2d_ctx double loc; // Fluid boundaries (both x and y coordinates). }; -struct quadrants_2d_ctx -create_ctx(void) +struct quadrants_2d_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -87,7 +85,7 @@ create_ctx(void) double u_ur = 0.0; // Upper-right fluid x-velocity. double v_ur = 0.0; // Upper-right fluid y-velocity. double p_ur = 0.01; // Upper-right fluid pressure. - + double rho_ll = 0.5; // Lower-left fluid mass density. double u_ll = 0.0; // Lower-left fluid x-velocity. double v_ll = 0.0; // Lower-left fluid y-velocity. @@ -152,14 +150,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .loc = loc, + .loc = loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct quadrants_2d_ctx *app = ctx; @@ -201,22 +198,19 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT u = u_ul; // Fluid x-velocity (upper-left). v = v_ul; // Fluid y-velocity (upper-left). p = p_ul; // Fluid pressure (upper-left). - } - else { + } else { rho = rho_ur; // Fluid mass density (upper-right). u = u_ur; // Fluid x-velocity (upper-right). v = v_ur; // Fluid y-velocity (upper-right). p = p_ur; // Fluid pressure (upper-right). } - } - else { + } else { if (x < loc) { rho = rho_ll; // Fluid mass density (lower-left). u = u_ll; // Fluid x-velocity (lower-left). v = v_ll; // Fluid y-velocity (lower-left). p = p_ll; // Fluid pressure (lower-left). - } - else { + } else { rho = rho_lr; // Fluid mass density (lower-right). u = u_lr; // Fluid x-velocity (lower-right). v = v_lr; // Fluid y-velocity (lower-right). @@ -228,25 +222,25 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -257,17 +251,28 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = v; vel[2] = 0.0; + vel[0] = u; + vel[1] = v; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -281,68 +286,112 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double rho_rel = sqrt(spatial_det) * rho * W; // Fluid relativistic mass density. double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = sqrt(spatial_det) * rho * h * (W * W) * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = y; fout[70] = 0.0; + fout[68] = x; + fout[69] = y; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -371,8 +420,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -386,24 +434,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -424,12 +473,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler", .equation = gr_euler, - + .init = evalGREulerInit, .force_low_order_flux = false, // Use HLL fluxes. .limiter = GKYL_MIN_MOD, @@ -438,8 +489,8 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -450,7 +501,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -458,8 +509,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -473,22 +523,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -507,25 +547,22 @@ main(int argc, char **argv) } goto mpifinalize; } - + // Moment app. struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -539,10 +576,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -551,26 +592,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -586,7 +632,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -601,8 +647,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -610,7 +655,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -618,8 +665,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -646,8 +692,8 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/moments/creg/rt_gr_strong_blast.c b/moments/creg/rt_gr_strong_blast.c index 3382f32719..0404afff4d 100644 --- a/moments/creg/rt_gr_strong_blast.c +++ b/moments/creg/rt_gr_strong_blast.c @@ -24,8 +24,7 @@ #include -struct strong_blast_ctx -{ +struct strong_blast_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -56,8 +55,7 @@ struct strong_blast_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct strong_blast_ctx -create_ctx(void) +struct strong_blast_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 5.0 / 3.0; // Adiabatic index. @@ -107,14 +105,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct strong_blast_ctx *app = ctx; @@ -139,8 +136,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -150,25 +146,25 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -181,15 +177,26 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -208,63 +215,107 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_x = sqrt(spatial_det) * rho * h * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. + double Etot = + sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); // Fluid total energy density. // Set fluid relativistic mass density. fout[0] = rho_rel; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set lapse gauge variable. fout[5] = lapse; // Set shift gauge variables. - fout[6] = shift[0]; fout[7] = shift[1]; fout[8] = shift[2]; + fout[6] = shift[0]; + fout[7] = shift[1]; + fout[8] = shift[2]; // Set spatial metric tensor. - fout[9] = spatial_metric[0][0]; fout[10] = spatial_metric[0][1]; fout[11] = spatial_metric[0][2]; - fout[12] = spatial_metric[1][0]; fout[13] = spatial_metric[1][1]; fout[14] = spatial_metric[1][2]; - fout[15] = spatial_metric[2][0]; fout[16] = spatial_metric[2][1]; fout[17] = spatial_metric[2][2]; + fout[9] = spatial_metric[0][0]; + fout[10] = spatial_metric[0][1]; + fout[11] = spatial_metric[0][2]; + fout[12] = spatial_metric[1][0]; + fout[13] = spatial_metric[1][1]; + fout[14] = spatial_metric[1][2]; + fout[15] = spatial_metric[2][0]; + fout[16] = spatial_metric[2][1]; + fout[17] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[18] = extrinsic_curvature[0][0]; fout[19] = extrinsic_curvature[0][1]; fout[20] = extrinsic_curvature[0][2]; - fout[21] = extrinsic_curvature[1][0]; fout[22] = extrinsic_curvature[1][1]; fout[23] = extrinsic_curvature[1][2]; - fout[24] = extrinsic_curvature[2][0]; fout[25] = extrinsic_curvature[2][1]; fout[26] = extrinsic_curvature[2][2]; + fout[18] = extrinsic_curvature[0][0]; + fout[19] = extrinsic_curvature[0][1]; + fout[20] = extrinsic_curvature[0][2]; + fout[21] = extrinsic_curvature[1][0]; + fout[22] = extrinsic_curvature[1][1]; + fout[23] = extrinsic_curvature[1][2]; + fout[24] = extrinsic_curvature[2][0]; + fout[25] = extrinsic_curvature[2][1]; + fout[26] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[27] = -1.0; - } - else { + } else { fout[27] = 1.0; } // Set lapse function derivatives. - fout[28] = lapse_der[0]; fout[29] = lapse_der[1]; fout[30] = lapse_der[2]; + fout[28] = lapse_der[0]; + fout[29] = lapse_der[1]; + fout[30] = lapse_der[2]; // Set shift vector derivatives. - fout[31] = shift_der[0][0]; fout[32] = shift_der[0][1]; fout[33] = shift_der[0][2]; - fout[34] = shift_der[1][0]; fout[35] = shift_der[1][1]; fout[36] = shift_der[1][2]; - fout[37] = shift_der[2][0]; fout[38] = shift_der[2][1]; fout[39] = shift_der[2][2]; + fout[31] = shift_der[0][0]; + fout[32] = shift_der[0][1]; + fout[33] = shift_der[0][2]; + fout[34] = shift_der[1][0]; + fout[35] = shift_der[1][1]; + fout[36] = shift_der[1][2]; + fout[37] = shift_der[2][0]; + fout[38] = shift_der[2][1]; + fout[39] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[40] = spatial_metric_der[0][0][0]; fout[41] = spatial_metric_der[0][0][1]; fout[42] = spatial_metric_der[0][0][2]; - fout[43] = spatial_metric_der[0][1][0]; fout[44] = spatial_metric_der[0][1][1]; fout[45] = spatial_metric_der[0][1][2]; - fout[46] = spatial_metric_der[0][2][0]; fout[47] = spatial_metric_der[0][2][1]; fout[48] = spatial_metric_der[0][2][2]; - - fout[49] = spatial_metric_der[1][0][0]; fout[50] = spatial_metric_der[1][0][1]; fout[51] = spatial_metric_der[1][0][2]; - fout[52] = spatial_metric_der[1][1][0]; fout[53] = spatial_metric_der[1][1][1]; fout[54] = spatial_metric_der[1][1][2]; - fout[55] = spatial_metric_der[1][2][0]; fout[56] = spatial_metric_der[1][2][1]; fout[57] = spatial_metric_der[1][2][2]; - - fout[58] = spatial_metric_der[2][0][0]; fout[59] = spatial_metric_der[2][0][1]; fout[60] = spatial_metric_der[2][0][2]; - fout[61] = spatial_metric_der[2][1][0]; fout[62] = spatial_metric_der[2][1][1]; fout[63] = spatial_metric_der[2][1][2]; - fout[64] = spatial_metric_der[2][2][0]; fout[65] = spatial_metric_der[2][2][1]; fout[66] = spatial_metric_der[2][2][2]; + fout[40] = spatial_metric_der[0][0][0]; + fout[41] = spatial_metric_der[0][0][1]; + fout[42] = spatial_metric_der[0][0][2]; + fout[43] = spatial_metric_der[0][1][0]; + fout[44] = spatial_metric_der[0][1][1]; + fout[45] = spatial_metric_der[0][1][2]; + fout[46] = spatial_metric_der[0][2][0]; + fout[47] = spatial_metric_der[0][2][1]; + fout[48] = spatial_metric_der[0][2][2]; + + fout[49] = spatial_metric_der[1][0][0]; + fout[50] = spatial_metric_der[1][0][1]; + fout[51] = spatial_metric_der[1][0][2]; + fout[52] = spatial_metric_der[1][1][0]; + fout[53] = spatial_metric_der[1][1][1]; + fout[54] = spatial_metric_der[1][1][2]; + fout[55] = spatial_metric_der[1][2][0]; + fout[56] = spatial_metric_der[1][2][1]; + fout[57] = spatial_metric_der[1][2][2]; + + fout[58] = spatial_metric_der[2][0][0]; + fout[59] = spatial_metric_der[2][0][1]; + fout[60] = spatial_metric_der[2][0][2]; + fout[61] = spatial_metric_der[2][1][0]; + fout[62] = spatial_metric_der[2][1][1]; + fout[63] = spatial_metric_der[2][1][2]; + fout[64] = spatial_metric_der[2][2][0]; + fout[65] = spatial_metric_der[2][2][1]; + fout[66] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[67] = 0.0; // Set spatial coordinates. - fout[68] = x; fout[69] = 0.0; fout[70] = 0.0; + fout[68] = x; + fout[69] = 0.0; + fout[70] = 0.0; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -293,8 +344,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -308,24 +358,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -345,12 +396,14 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_euler", .equation = gr_euler, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -358,7 +411,7 @@ main(int argc, char **argv) .has_gr_euler = true, .gr_euler_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -369,7 +422,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -377,8 +430,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -392,22 +444,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -431,20 +473,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -458,10 +496,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -470,26 +512,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -505,7 +552,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -520,8 +567,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -529,7 +575,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -537,8 +585,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -565,14 +612,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_ultra_rel_bhl_spinning.c b/moments/creg/rt_gr_ultra_rel_bhl_spinning.c index 971f4365b9..8da2f02730 100644 --- a/moments/creg/rt_gr_ultra_rel_bhl_spinning.c +++ b/moments/creg/rt_gr_ultra_rel_bhl_spinning.c @@ -27,8 +27,7 @@ #include -struct ultra_rel_bhl_spinning_ctx -{ +struct ultra_rel_bhl_spinning_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -69,8 +68,7 @@ struct ultra_rel_bhl_spinning_ctx double x_loc; // Shock location (x-direction). }; -struct ultra_rel_bhl_spinning_ctx -create_ctx(void) +struct ultra_rel_bhl_spinning_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 2.0; // Adiabatic index. @@ -90,7 +88,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -136,14 +135,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct ultra_rel_bhl_spinning_ctx *app = ctx; @@ -166,35 +164,34 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < x_loc) { rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -205,17 +202,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -229,65 +238,109 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double p = (gas_gamma - 1.0) * rho; - + double Etot = sqrt(spatial_det) * (((rho + p) * (W * W)) - p); // Fluid total energy density. - double mom_x = sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). + double mom_x = + sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). // Set fluid total energy density. fout[0] = Etot; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set lapse gauge variable. fout[4] = lapse; // Set shift gauge variables. - fout[5] = shift[0]; fout[6] = shift[1]; fout[7] = shift[2]; + fout[5] = shift[0]; + fout[6] = shift[1]; + fout[7] = shift[2]; // Set spatial metric tensor. - fout[8] = spatial_metric[0][0]; fout[9] = spatial_metric[0][1]; fout[10] = spatial_metric[0][2]; - fout[11] = spatial_metric[1][0]; fout[12] = spatial_metric[1][1]; fout[13] = spatial_metric[1][2]; - fout[14] = spatial_metric[2][0]; fout[15] = spatial_metric[2][1]; fout[16] = spatial_metric[2][2]; + fout[8] = spatial_metric[0][0]; + fout[9] = spatial_metric[0][1]; + fout[10] = spatial_metric[0][2]; + fout[11] = spatial_metric[1][0]; + fout[12] = spatial_metric[1][1]; + fout[13] = spatial_metric[1][2]; + fout[14] = spatial_metric[2][0]; + fout[15] = spatial_metric[2][1]; + fout[16] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[17] = extrinsic_curvature[0][0]; fout[18] = extrinsic_curvature[0][1]; fout[19] = extrinsic_curvature[0][2]; - fout[20] = extrinsic_curvature[1][0]; fout[21] = extrinsic_curvature[1][1]; fout[22] = extrinsic_curvature[1][2]; - fout[23] = extrinsic_curvature[2][0]; fout[24] = extrinsic_curvature[2][1]; fout[25] = extrinsic_curvature[2][2]; + fout[17] = extrinsic_curvature[0][0]; + fout[18] = extrinsic_curvature[0][1]; + fout[19] = extrinsic_curvature[0][2]; + fout[20] = extrinsic_curvature[1][0]; + fout[21] = extrinsic_curvature[1][1]; + fout[22] = extrinsic_curvature[1][2]; + fout[23] = extrinsic_curvature[2][0]; + fout[24] = extrinsic_curvature[2][1]; + fout[25] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[26] = -1.0; - } - else { + } else { fout[26] = 1.0; } // Set lapse function derivatives. - fout[27] = lapse_der[0]; fout[28] = lapse_der[1]; fout[29] = lapse_der[2]; + fout[27] = lapse_der[0]; + fout[28] = lapse_der[1]; + fout[29] = lapse_der[2]; // Set shift vector derivatives. - fout[30] = shift_der[0][0]; fout[31] = shift_der[0][1]; fout[32] = shift_der[0][2]; - fout[33] = shift_der[1][0]; fout[34] = shift_der[1][1]; fout[35] = shift_der[1][2]; - fout[36] = shift_der[2][0]; fout[37] = shift_der[2][1]; fout[38] = shift_der[2][2]; + fout[30] = shift_der[0][0]; + fout[31] = shift_der[0][1]; + fout[32] = shift_der[0][2]; + fout[33] = shift_der[1][0]; + fout[34] = shift_der[1][1]; + fout[35] = shift_der[1][2]; + fout[36] = shift_der[2][0]; + fout[37] = shift_der[2][1]; + fout[38] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[39] = spatial_metric_der[0][0][0]; fout[40] = spatial_metric_der[0][0][1]; fout[41] = spatial_metric_der[0][0][2]; - fout[42] = spatial_metric_der[0][1][0]; fout[43] = spatial_metric_der[0][1][1]; fout[44] = spatial_metric_der[0][1][2]; - fout[45] = spatial_metric_der[0][2][0]; fout[46] = spatial_metric_der[0][2][1]; fout[47] = spatial_metric_der[0][2][2]; - - fout[48] = spatial_metric_der[1][0][0]; fout[49] = spatial_metric_der[1][0][1]; fout[50] = spatial_metric_der[1][0][2]; - fout[51] = spatial_metric_der[1][1][0]; fout[52] = spatial_metric_der[1][1][1]; fout[53] = spatial_metric_der[1][1][2]; - fout[54] = spatial_metric_der[1][2][0]; fout[55] = spatial_metric_der[1][2][1]; fout[56] = spatial_metric_der[1][2][2]; - - fout[57] = spatial_metric_der[2][0][0]; fout[58] = spatial_metric_der[2][0][1]; fout[59] = spatial_metric_der[2][0][2]; - fout[60] = spatial_metric_der[2][1][0]; fout[61] = spatial_metric_der[2][1][1]; fout[62] = spatial_metric_der[2][1][2]; - fout[63] = spatial_metric_der[2][2][0]; fout[64] = spatial_metric_der[2][2][1]; fout[65] = spatial_metric_der[2][2][2]; + fout[39] = spatial_metric_der[0][0][0]; + fout[40] = spatial_metric_der[0][0][1]; + fout[41] = spatial_metric_der[0][0][2]; + fout[42] = spatial_metric_der[0][1][0]; + fout[43] = spatial_metric_der[0][1][1]; + fout[44] = spatial_metric_der[0][1][2]; + fout[45] = spatial_metric_der[0][2][0]; + fout[46] = spatial_metric_der[0][2][1]; + fout[47] = spatial_metric_der[0][2][2]; + + fout[48] = spatial_metric_der[1][0][0]; + fout[49] = spatial_metric_der[1][0][1]; + fout[50] = spatial_metric_der[1][0][2]; + fout[51] = spatial_metric_der[1][1][0]; + fout[52] = spatial_metric_der[1][1][1]; + fout[53] = spatial_metric_der[1][1][2]; + fout[54] = spatial_metric_der[1][2][0]; + fout[55] = spatial_metric_der[1][2][1]; + fout[56] = spatial_metric_der[1][2][2]; + + fout[57] = spatial_metric_der[2][0][0]; + fout[58] = spatial_metric_der[2][0][1]; + fout[59] = spatial_metric_der[2][0][2]; + fout[60] = spatial_metric_der[2][1][0]; + fout[61] = spatial_metric_der[2][1][1]; + fout[62] = spatial_metric_der[2][1][2]; + fout[63] = spatial_metric_der[2][2][0]; + fout[64] = spatial_metric_der[2][2][1]; + fout[65] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[66] = 0.0; // Set spatial coordinates. - fout[67] = x; fout[68] = y; fout[69] = 0.0; + fout[67] = x; + fout[68] = y; + fout[69] = 0.0; if (in_excision_region) { for (int i = 0; i < 66; i++) { @@ -316,8 +369,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -331,24 +383,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -369,12 +422,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_ultra_rel_euler", .equation = gr_ultra_rel_euler, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -382,8 +437,8 @@ main(int argc, char **argv) .has_gr_ultra_rel = true, .gr_ultra_rel_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -394,7 +449,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -402,8 +457,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -417,22 +471,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -456,9 +500,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -466,13 +510,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -486,10 +527,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -498,26 +543,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -533,7 +583,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -548,8 +598,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -557,7 +606,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -565,8 +616,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -593,14 +643,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_ultra_rel_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_ultra_rel_bhl_spinning_tetrad.c b/moments/creg/rt_gr_ultra_rel_bhl_spinning_tetrad.c index 75aca8bde0..11d6033559 100644 --- a/moments/creg/rt_gr_ultra_rel_bhl_spinning_tetrad.c +++ b/moments/creg/rt_gr_ultra_rel_bhl_spinning_tetrad.c @@ -27,8 +27,7 @@ #include -struct ultra_rel_bhl_spinning_ctx -{ +struct ultra_rel_bhl_spinning_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -69,8 +68,7 @@ struct ultra_rel_bhl_spinning_ctx double x_loc; // Shock location (x-direction). }; -struct ultra_rel_bhl_spinning_ctx -create_ctx(void) +struct ultra_rel_bhl_spinning_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 2.0; // Adiabatic index. @@ -90,7 +88,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -136,14 +135,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct ultra_rel_bhl_spinning_ctx *app = ctx; @@ -166,35 +164,34 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < x_loc) { rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -205,17 +202,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -229,65 +238,109 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double p = (gas_gamma - 1.0) * rho; - + double Etot = sqrt(spatial_det) * (((rho + p) * (W * W)) - p); // Fluid total energy density. - double mom_x = sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). + double mom_x = + sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). // Set fluid total energy density. fout[0] = Etot; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set lapse gauge variable. fout[4] = lapse; // Set shift gauge variables. - fout[5] = shift[0]; fout[6] = shift[1]; fout[7] = shift[2]; + fout[5] = shift[0]; + fout[6] = shift[1]; + fout[7] = shift[2]; // Set spatial metric tensor. - fout[8] = spatial_metric[0][0]; fout[9] = spatial_metric[0][1]; fout[10] = spatial_metric[0][2]; - fout[11] = spatial_metric[1][0]; fout[12] = spatial_metric[1][1]; fout[13] = spatial_metric[1][2]; - fout[14] = spatial_metric[2][0]; fout[15] = spatial_metric[2][1]; fout[16] = spatial_metric[2][2]; + fout[8] = spatial_metric[0][0]; + fout[9] = spatial_metric[0][1]; + fout[10] = spatial_metric[0][2]; + fout[11] = spatial_metric[1][0]; + fout[12] = spatial_metric[1][1]; + fout[13] = spatial_metric[1][2]; + fout[14] = spatial_metric[2][0]; + fout[15] = spatial_metric[2][1]; + fout[16] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[17] = extrinsic_curvature[0][0]; fout[18] = extrinsic_curvature[0][1]; fout[19] = extrinsic_curvature[0][2]; - fout[20] = extrinsic_curvature[1][0]; fout[21] = extrinsic_curvature[1][1]; fout[22] = extrinsic_curvature[1][2]; - fout[23] = extrinsic_curvature[2][0]; fout[24] = extrinsic_curvature[2][1]; fout[25] = extrinsic_curvature[2][2]; + fout[17] = extrinsic_curvature[0][0]; + fout[18] = extrinsic_curvature[0][1]; + fout[19] = extrinsic_curvature[0][2]; + fout[20] = extrinsic_curvature[1][0]; + fout[21] = extrinsic_curvature[1][1]; + fout[22] = extrinsic_curvature[1][2]; + fout[23] = extrinsic_curvature[2][0]; + fout[24] = extrinsic_curvature[2][1]; + fout[25] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[26] = -1.0; - } - else { + } else { fout[26] = 1.0; } // Set lapse function derivatives. - fout[27] = lapse_der[0]; fout[28] = lapse_der[1]; fout[29] = lapse_der[2]; + fout[27] = lapse_der[0]; + fout[28] = lapse_der[1]; + fout[29] = lapse_der[2]; // Set shift vector derivatives. - fout[30] = shift_der[0][0]; fout[31] = shift_der[0][1]; fout[32] = shift_der[0][2]; - fout[33] = shift_der[1][0]; fout[34] = shift_der[1][1]; fout[35] = shift_der[1][2]; - fout[36] = shift_der[2][0]; fout[37] = shift_der[2][1]; fout[38] = shift_der[2][2]; + fout[30] = shift_der[0][0]; + fout[31] = shift_der[0][1]; + fout[32] = shift_der[0][2]; + fout[33] = shift_der[1][0]; + fout[34] = shift_der[1][1]; + fout[35] = shift_der[1][2]; + fout[36] = shift_der[2][0]; + fout[37] = shift_der[2][1]; + fout[38] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[39] = spatial_metric_der[0][0][0]; fout[40] = spatial_metric_der[0][0][1]; fout[41] = spatial_metric_der[0][0][2]; - fout[42] = spatial_metric_der[0][1][0]; fout[43] = spatial_metric_der[0][1][1]; fout[44] = spatial_metric_der[0][1][2]; - fout[45] = spatial_metric_der[0][2][0]; fout[46] = spatial_metric_der[0][2][1]; fout[47] = spatial_metric_der[0][2][2]; - - fout[48] = spatial_metric_der[1][0][0]; fout[49] = spatial_metric_der[1][0][1]; fout[50] = spatial_metric_der[1][0][2]; - fout[51] = spatial_metric_der[1][1][0]; fout[52] = spatial_metric_der[1][1][1]; fout[53] = spatial_metric_der[1][1][2]; - fout[54] = spatial_metric_der[1][2][0]; fout[55] = spatial_metric_der[1][2][1]; fout[56] = spatial_metric_der[1][2][2]; - - fout[57] = spatial_metric_der[2][0][0]; fout[58] = spatial_metric_der[2][0][1]; fout[59] = spatial_metric_der[2][0][2]; - fout[60] = spatial_metric_der[2][1][0]; fout[61] = spatial_metric_der[2][1][1]; fout[62] = spatial_metric_der[2][1][2]; - fout[63] = spatial_metric_der[2][2][0]; fout[64] = spatial_metric_der[2][2][1]; fout[65] = spatial_metric_der[2][2][2]; + fout[39] = spatial_metric_der[0][0][0]; + fout[40] = spatial_metric_der[0][0][1]; + fout[41] = spatial_metric_der[0][0][2]; + fout[42] = spatial_metric_der[0][1][0]; + fout[43] = spatial_metric_der[0][1][1]; + fout[44] = spatial_metric_der[0][1][2]; + fout[45] = spatial_metric_der[0][2][0]; + fout[46] = spatial_metric_der[0][2][1]; + fout[47] = spatial_metric_der[0][2][2]; + + fout[48] = spatial_metric_der[1][0][0]; + fout[49] = spatial_metric_der[1][0][1]; + fout[50] = spatial_metric_der[1][0][2]; + fout[51] = spatial_metric_der[1][1][0]; + fout[52] = spatial_metric_der[1][1][1]; + fout[53] = spatial_metric_der[1][1][2]; + fout[54] = spatial_metric_der[1][2][0]; + fout[55] = spatial_metric_der[1][2][1]; + fout[56] = spatial_metric_der[1][2][2]; + + fout[57] = spatial_metric_der[2][0][0]; + fout[58] = spatial_metric_der[2][0][1]; + fout[59] = spatial_metric_der[2][0][2]; + fout[60] = spatial_metric_der[2][1][0]; + fout[61] = spatial_metric_der[2][1][1]; + fout[62] = spatial_metric_der[2][1][2]; + fout[63] = spatial_metric_der[2][2][0]; + fout[64] = spatial_metric_der[2][2][1]; + fout[65] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[66] = 0.0; // Set spatial coordinates. - fout[67] = x; fout[68] = y; fout[69] = 0.0; + fout[67] = x; + fout[68] = y; + fout[69] = 0.0; if (in_excision_region) { for (int i = 0; i < 66; i++) { @@ -316,8 +369,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -331,24 +383,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -369,12 +422,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_ultra_rel_euler_tetrad", .equation = gr_ultra_rel_euler_tetrad, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -382,8 +437,8 @@ main(int argc, char **argv) .has_gr_ultra_rel = true, .gr_ultra_rel_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -394,7 +449,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -402,8 +457,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -417,22 +471,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -456,9 +500,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -466,13 +510,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -486,10 +527,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -498,26 +543,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -533,7 +583,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -548,8 +598,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -557,7 +606,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -565,8 +616,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -593,14 +643,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_ultra_rel_euler_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_ultra_rel_bhl_static.c b/moments/creg/rt_gr_ultra_rel_bhl_static.c index b734700d6f..15015e8c33 100644 --- a/moments/creg/rt_gr_ultra_rel_bhl_static.c +++ b/moments/creg/rt_gr_ultra_rel_bhl_static.c @@ -27,8 +27,7 @@ #include -struct ultra_rel_bhl_static_ctx -{ +struct ultra_rel_bhl_static_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -69,8 +68,7 @@ struct ultra_rel_bhl_static_ctx double x_loc; // Shock location (x-direction). }; -struct ultra_rel_bhl_static_ctx -create_ctx(void) +struct ultra_rel_bhl_static_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 2.0; // Adiabatic index. @@ -90,7 +88,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -136,14 +135,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct ultra_rel_bhl_static_ctx *app = ctx; @@ -166,35 +164,34 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < x_loc) { rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -205,17 +202,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -229,65 +238,109 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double p = (gas_gamma - 1.0) * rho; - + double Etot = sqrt(spatial_det) * (((rho + p) * (W * W)) - p); // Fluid total energy density. - double mom_x = sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). + double mom_x = + sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). // Set fluid total energy density. fout[0] = Etot; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set lapse gauge variable. fout[4] = lapse; // Set shift gauge variables. - fout[5] = shift[0]; fout[6] = shift[1]; fout[7] = shift[2]; + fout[5] = shift[0]; + fout[6] = shift[1]; + fout[7] = shift[2]; // Set spatial metric tensor. - fout[8] = spatial_metric[0][0]; fout[9] = spatial_metric[0][1]; fout[10] = spatial_metric[0][2]; - fout[11] = spatial_metric[1][0]; fout[12] = spatial_metric[1][1]; fout[13] = spatial_metric[1][2]; - fout[14] = spatial_metric[2][0]; fout[15] = spatial_metric[2][1]; fout[16] = spatial_metric[2][2]; + fout[8] = spatial_metric[0][0]; + fout[9] = spatial_metric[0][1]; + fout[10] = spatial_metric[0][2]; + fout[11] = spatial_metric[1][0]; + fout[12] = spatial_metric[1][1]; + fout[13] = spatial_metric[1][2]; + fout[14] = spatial_metric[2][0]; + fout[15] = spatial_metric[2][1]; + fout[16] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[17] = extrinsic_curvature[0][0]; fout[18] = extrinsic_curvature[0][1]; fout[19] = extrinsic_curvature[0][2]; - fout[20] = extrinsic_curvature[1][0]; fout[21] = extrinsic_curvature[1][1]; fout[22] = extrinsic_curvature[1][2]; - fout[23] = extrinsic_curvature[2][0]; fout[24] = extrinsic_curvature[2][1]; fout[25] = extrinsic_curvature[2][2]; + fout[17] = extrinsic_curvature[0][0]; + fout[18] = extrinsic_curvature[0][1]; + fout[19] = extrinsic_curvature[0][2]; + fout[20] = extrinsic_curvature[1][0]; + fout[21] = extrinsic_curvature[1][1]; + fout[22] = extrinsic_curvature[1][2]; + fout[23] = extrinsic_curvature[2][0]; + fout[24] = extrinsic_curvature[2][1]; + fout[25] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[26] = -1.0; - } - else { + } else { fout[26] = 1.0; } // Set lapse function derivatives. - fout[27] = lapse_der[0]; fout[28] = lapse_der[1]; fout[29] = lapse_der[2]; + fout[27] = lapse_der[0]; + fout[28] = lapse_der[1]; + fout[29] = lapse_der[2]; // Set shift vector derivatives. - fout[30] = shift_der[0][0]; fout[31] = shift_der[0][1]; fout[32] = shift_der[0][2]; - fout[33] = shift_der[1][0]; fout[34] = shift_der[1][1]; fout[35] = shift_der[1][2]; - fout[36] = shift_der[2][0]; fout[37] = shift_der[2][1]; fout[38] = shift_der[2][2]; + fout[30] = shift_der[0][0]; + fout[31] = shift_der[0][1]; + fout[32] = shift_der[0][2]; + fout[33] = shift_der[1][0]; + fout[34] = shift_der[1][1]; + fout[35] = shift_der[1][2]; + fout[36] = shift_der[2][0]; + fout[37] = shift_der[2][1]; + fout[38] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[39] = spatial_metric_der[0][0][0]; fout[40] = spatial_metric_der[0][0][1]; fout[41] = spatial_metric_der[0][0][2]; - fout[42] = spatial_metric_der[0][1][0]; fout[43] = spatial_metric_der[0][1][1]; fout[44] = spatial_metric_der[0][1][2]; - fout[45] = spatial_metric_der[0][2][0]; fout[46] = spatial_metric_der[0][2][1]; fout[47] = spatial_metric_der[0][2][2]; - - fout[48] = spatial_metric_der[1][0][0]; fout[49] = spatial_metric_der[1][0][1]; fout[50] = spatial_metric_der[1][0][2]; - fout[51] = spatial_metric_der[1][1][0]; fout[52] = spatial_metric_der[1][1][1]; fout[53] = spatial_metric_der[1][1][2]; - fout[54] = spatial_metric_der[1][2][0]; fout[55] = spatial_metric_der[1][2][1]; fout[56] = spatial_metric_der[1][2][2]; - - fout[57] = spatial_metric_der[2][0][0]; fout[58] = spatial_metric_der[2][0][1]; fout[59] = spatial_metric_der[2][0][2]; - fout[60] = spatial_metric_der[2][1][0]; fout[61] = spatial_metric_der[2][1][1]; fout[62] = spatial_metric_der[2][1][2]; - fout[63] = spatial_metric_der[2][2][0]; fout[64] = spatial_metric_der[2][2][1]; fout[65] = spatial_metric_der[2][2][2]; + fout[39] = spatial_metric_der[0][0][0]; + fout[40] = spatial_metric_der[0][0][1]; + fout[41] = spatial_metric_der[0][0][2]; + fout[42] = spatial_metric_der[0][1][0]; + fout[43] = spatial_metric_der[0][1][1]; + fout[44] = spatial_metric_der[0][1][2]; + fout[45] = spatial_metric_der[0][2][0]; + fout[46] = spatial_metric_der[0][2][1]; + fout[47] = spatial_metric_der[0][2][2]; + + fout[48] = spatial_metric_der[1][0][0]; + fout[49] = spatial_metric_der[1][0][1]; + fout[50] = spatial_metric_der[1][0][2]; + fout[51] = spatial_metric_der[1][1][0]; + fout[52] = spatial_metric_der[1][1][1]; + fout[53] = spatial_metric_der[1][1][2]; + fout[54] = spatial_metric_der[1][2][0]; + fout[55] = spatial_metric_der[1][2][1]; + fout[56] = spatial_metric_der[1][2][2]; + + fout[57] = spatial_metric_der[2][0][0]; + fout[58] = spatial_metric_der[2][0][1]; + fout[59] = spatial_metric_der[2][0][2]; + fout[60] = spatial_metric_der[2][1][0]; + fout[61] = spatial_metric_der[2][1][1]; + fout[62] = spatial_metric_der[2][1][2]; + fout[63] = spatial_metric_der[2][2][0]; + fout[64] = spatial_metric_der[2][2][1]; + fout[65] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[66] = 0.0; // Set spatial coordinates. - fout[67] = x; fout[68] = y; fout[69] = 0.0; + fout[67] = x; + fout[68] = y; + fout[69] = 0.0; if (in_excision_region) { for (int i = 0; i < 66; i++) { @@ -316,8 +369,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -331,24 +383,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -369,12 +422,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_ultra_rel_euler", .equation = gr_ultra_rel_euler, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -382,8 +437,8 @@ main(int argc, char **argv) .has_gr_ultra_rel = true, .gr_ultra_rel_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -394,7 +449,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -402,8 +457,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -417,22 +471,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -456,9 +500,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -466,13 +510,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -486,10 +527,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -498,26 +543,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -533,7 +583,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -548,8 +598,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -557,7 +606,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -565,8 +616,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -593,14 +643,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_ultra_rel_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_ultra_rel_bhl_static_tetrad.c b/moments/creg/rt_gr_ultra_rel_bhl_static_tetrad.c index e3ce1fb74c..0b0357ed8e 100644 --- a/moments/creg/rt_gr_ultra_rel_bhl_static_tetrad.c +++ b/moments/creg/rt_gr_ultra_rel_bhl_static_tetrad.c @@ -27,8 +27,7 @@ #include -struct ultra_rel_bhl_static_ctx -{ +struct ultra_rel_bhl_static_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -69,8 +68,7 @@ struct ultra_rel_bhl_static_ctx double x_loc; // Shock location (x-direction). }; -struct ultra_rel_bhl_static_ctx -create_ctx(void) +struct ultra_rel_bhl_static_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 2.0; // Adiabatic index. @@ -90,7 +88,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -136,14 +135,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .x_loc = x_loc, + .x_loc = x_loc }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct ultra_rel_bhl_static_ctx *app = ctx; @@ -166,35 +164,34 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < x_loc) { rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -205,17 +202,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + vel[0] = u; + vel[1] = 0.0; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -229,65 +238,109 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double p = (gas_gamma - 1.0) * rho; - + double Etot = sqrt(spatial_det) * (((rho + p) * (W * W)) - p); // Fluid total energy density. - double mom_x = sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). + double mom_x = + sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). // Set fluid total energy density. fout[0] = Etot; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set lapse gauge variable. fout[4] = lapse; // Set shift gauge variables. - fout[5] = shift[0]; fout[6] = shift[1]; fout[7] = shift[2]; + fout[5] = shift[0]; + fout[6] = shift[1]; + fout[7] = shift[2]; // Set spatial metric tensor. - fout[8] = spatial_metric[0][0]; fout[9] = spatial_metric[0][1]; fout[10] = spatial_metric[0][2]; - fout[11] = spatial_metric[1][0]; fout[12] = spatial_metric[1][1]; fout[13] = spatial_metric[1][2]; - fout[14] = spatial_metric[2][0]; fout[15] = spatial_metric[2][1]; fout[16] = spatial_metric[2][2]; + fout[8] = spatial_metric[0][0]; + fout[9] = spatial_metric[0][1]; + fout[10] = spatial_metric[0][2]; + fout[11] = spatial_metric[1][0]; + fout[12] = spatial_metric[1][1]; + fout[13] = spatial_metric[1][2]; + fout[14] = spatial_metric[2][0]; + fout[15] = spatial_metric[2][1]; + fout[16] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[17] = extrinsic_curvature[0][0]; fout[18] = extrinsic_curvature[0][1]; fout[19] = extrinsic_curvature[0][2]; - fout[20] = extrinsic_curvature[1][0]; fout[21] = extrinsic_curvature[1][1]; fout[22] = extrinsic_curvature[1][2]; - fout[23] = extrinsic_curvature[2][0]; fout[24] = extrinsic_curvature[2][1]; fout[25] = extrinsic_curvature[2][2]; + fout[17] = extrinsic_curvature[0][0]; + fout[18] = extrinsic_curvature[0][1]; + fout[19] = extrinsic_curvature[0][2]; + fout[20] = extrinsic_curvature[1][0]; + fout[21] = extrinsic_curvature[1][1]; + fout[22] = extrinsic_curvature[1][2]; + fout[23] = extrinsic_curvature[2][0]; + fout[24] = extrinsic_curvature[2][1]; + fout[25] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[26] = -1.0; - } - else { + } else { fout[26] = 1.0; } // Set lapse function derivatives. - fout[27] = lapse_der[0]; fout[28] = lapse_der[1]; fout[29] = lapse_der[2]; + fout[27] = lapse_der[0]; + fout[28] = lapse_der[1]; + fout[29] = lapse_der[2]; // Set shift vector derivatives. - fout[30] = shift_der[0][0]; fout[31] = shift_der[0][1]; fout[32] = shift_der[0][2]; - fout[33] = shift_der[1][0]; fout[34] = shift_der[1][1]; fout[35] = shift_der[1][2]; - fout[36] = shift_der[2][0]; fout[37] = shift_der[2][1]; fout[38] = shift_der[2][2]; + fout[30] = shift_der[0][0]; + fout[31] = shift_der[0][1]; + fout[32] = shift_der[0][2]; + fout[33] = shift_der[1][0]; + fout[34] = shift_der[1][1]; + fout[35] = shift_der[1][2]; + fout[36] = shift_der[2][0]; + fout[37] = shift_der[2][1]; + fout[38] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[39] = spatial_metric_der[0][0][0]; fout[40] = spatial_metric_der[0][0][1]; fout[41] = spatial_metric_der[0][0][2]; - fout[42] = spatial_metric_der[0][1][0]; fout[43] = spatial_metric_der[0][1][1]; fout[44] = spatial_metric_der[0][1][2]; - fout[45] = spatial_metric_der[0][2][0]; fout[46] = spatial_metric_der[0][2][1]; fout[47] = spatial_metric_der[0][2][2]; - - fout[48] = spatial_metric_der[1][0][0]; fout[49] = spatial_metric_der[1][0][1]; fout[50] = spatial_metric_der[1][0][2]; - fout[51] = spatial_metric_der[1][1][0]; fout[52] = spatial_metric_der[1][1][1]; fout[53] = spatial_metric_der[1][1][2]; - fout[54] = spatial_metric_der[1][2][0]; fout[55] = spatial_metric_der[1][2][1]; fout[56] = spatial_metric_der[1][2][2]; - - fout[57] = spatial_metric_der[2][0][0]; fout[58] = spatial_metric_der[2][0][1]; fout[59] = spatial_metric_der[2][0][2]; - fout[60] = spatial_metric_der[2][1][0]; fout[61] = spatial_metric_der[2][1][1]; fout[62] = spatial_metric_der[2][1][2]; - fout[63] = spatial_metric_der[2][2][0]; fout[64] = spatial_metric_der[2][2][1]; fout[65] = spatial_metric_der[2][2][2]; + fout[39] = spatial_metric_der[0][0][0]; + fout[40] = spatial_metric_der[0][0][1]; + fout[41] = spatial_metric_der[0][0][2]; + fout[42] = spatial_metric_der[0][1][0]; + fout[43] = spatial_metric_der[0][1][1]; + fout[44] = spatial_metric_der[0][1][2]; + fout[45] = spatial_metric_der[0][2][0]; + fout[46] = spatial_metric_der[0][2][1]; + fout[47] = spatial_metric_der[0][2][2]; + + fout[48] = spatial_metric_der[1][0][0]; + fout[49] = spatial_metric_der[1][0][1]; + fout[50] = spatial_metric_der[1][0][2]; + fout[51] = spatial_metric_der[1][1][0]; + fout[52] = spatial_metric_der[1][1][1]; + fout[53] = spatial_metric_der[1][1][2]; + fout[54] = spatial_metric_der[1][2][0]; + fout[55] = spatial_metric_der[1][2][1]; + fout[56] = spatial_metric_der[1][2][2]; + + fout[57] = spatial_metric_der[2][0][0]; + fout[58] = spatial_metric_der[2][0][1]; + fout[59] = spatial_metric_der[2][0][2]; + fout[60] = spatial_metric_der[2][1][0]; + fout[61] = spatial_metric_der[2][1][1]; + fout[62] = spatial_metric_der[2][1][2]; + fout[63] = spatial_metric_der[2][2][0]; + fout[64] = spatial_metric_der[2][2][1]; + fout[65] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[66] = 0.0; // Set spatial coordinates. - fout[67] = x; fout[68] = y; fout[69] = 0.0; + fout[67] = x; + fout[68] = y; + fout[69] = 0.0; if (in_excision_region) { for (int i = 0; i < 66; i++) { @@ -316,8 +369,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -331,24 +383,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -369,12 +422,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_ultra_rel_euler_tetrad", .equation = gr_ultra_rel_euler_tetrad, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -382,8 +437,8 @@ main(int argc, char **argv) .has_gr_ultra_rel = true, .gr_ultra_rel_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -394,7 +449,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -402,8 +457,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -417,22 +471,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -456,9 +500,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -466,13 +510,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -486,10 +527,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -498,26 +543,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -533,7 +583,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -548,8 +598,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -557,7 +606,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -565,8 +616,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -593,14 +643,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_ultra_rel_euler_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_ultra_rel_blackhole_collapse.c b/moments/creg/rt_gr_ultra_rel_blackhole_collapse.c index f24d72a675..f38ebdabe6 100644 --- a/moments/creg/rt_gr_ultra_rel_blackhole_collapse.c +++ b/moments/creg/rt_gr_ultra_rel_blackhole_collapse.c @@ -19,8 +19,7 @@ #include -struct ultra_rel_blackhole_collapse_ctx -{ +struct ultra_rel_blackhole_collapse_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -61,8 +60,7 @@ struct ultra_rel_blackhole_collapse_ctx double r_star; // Star radius. }; -struct ultra_rel_blackhole_collapse_ctx -create_ctx(void) +struct ultra_rel_blackhole_collapse_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 2.0; // Adiabatic index. @@ -82,7 +80,8 @@ create_ctx(void) double pos_z = 0.0; // Predicted position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -91,7 +90,8 @@ create_ctx(void) double Ly = 5.0; // Domain size (y-direction). double cfl_frac = 0.95; // CFL coefficient. - enum gkyl_spacetime_gauge spacetime_gauge = GKYL_BLACKHOLE_COLLAPSE_GAUGE; // Spacetime gauge choice. + enum gkyl_spacetime_gauge spacetime_gauge = + GKYL_BLACKHOLE_COLLAPSE_GAUGE; // Spacetime gauge choice. int reinit_freq = 100; // Spacetime reinitialization frequency. double t_end = 2.0; // Final simulation time. @@ -128,14 +128,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .r_star = r_star, + .r_star = r_star }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct ultra_rel_blackhole_collapse_ctx *app = ctx; @@ -166,36 +165,35 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhos; // Fluid mass density (star). u = -omega_s * (y - (0.5 * Ly)); // Fluid velocity (star). v = omega_s * (x - (0.5 * Lx)); - } - else { + } else { rho = rhob; // Fluid mass density (background). u = -omega_b * (y - (0.5 * Ly)); // Fluid velocity (background). v = omega_b * (x - (0.5 * Lx)); } - + double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -206,17 +204,29 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = v; vel[2] = 0.0; + vel[0] = u; + vel[1] = v; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -230,65 +240,110 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT } double p = (gas_gamma - 1.0) * rho; - + double Etot = sqrt(spatial_det) * (((rho + p) * (W * W)) - p); // Fluid total energy density. - double mom_x = sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). - double mom_y = sqrt(spatial_det) * (rho + p) * (W * W) * v; // Fluid momentum density (y-direction). + double mom_x = + sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). + double mom_y = + sqrt(spatial_det) * (rho + p) * (W * W) * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). // Set fluid total energy density. fout[0] = Etot; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set lapse gauge variable. fout[4] = lapse; // Set shift gauge variables. - fout[5] = shift[0]; fout[6] = shift[1]; fout[7] = shift[2]; + fout[5] = shift[0]; + fout[6] = shift[1]; + fout[7] = shift[2]; // Set spatial metric tensor. - fout[8] = spatial_metric[0][0]; fout[9] = spatial_metric[0][1]; fout[10] = spatial_metric[0][2]; - fout[11] = spatial_metric[1][0]; fout[12] = spatial_metric[1][1]; fout[13] = spatial_metric[1][2]; - fout[14] = spatial_metric[2][0]; fout[15] = spatial_metric[2][1]; fout[16] = spatial_metric[2][2]; + fout[8] = spatial_metric[0][0]; + fout[9] = spatial_metric[0][1]; + fout[10] = spatial_metric[0][2]; + fout[11] = spatial_metric[1][0]; + fout[12] = spatial_metric[1][1]; + fout[13] = spatial_metric[1][2]; + fout[14] = spatial_metric[2][0]; + fout[15] = spatial_metric[2][1]; + fout[16] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[17] = extrinsic_curvature[0][0]; fout[18] = extrinsic_curvature[0][1]; fout[19] = extrinsic_curvature[0][2]; - fout[20] = extrinsic_curvature[1][0]; fout[21] = extrinsic_curvature[1][1]; fout[22] = extrinsic_curvature[1][2]; - fout[23] = extrinsic_curvature[2][0]; fout[24] = extrinsic_curvature[2][1]; fout[25] = extrinsic_curvature[2][2]; + fout[17] = extrinsic_curvature[0][0]; + fout[18] = extrinsic_curvature[0][1]; + fout[19] = extrinsic_curvature[0][2]; + fout[20] = extrinsic_curvature[1][0]; + fout[21] = extrinsic_curvature[1][1]; + fout[22] = extrinsic_curvature[1][2]; + fout[23] = extrinsic_curvature[2][0]; + fout[24] = extrinsic_curvature[2][1]; + fout[25] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[26] = -1.0; - } - else { + } else { fout[26] = 1.0; } // Set lapse function derivatives. - fout[27] = lapse_der[0]; fout[28] = lapse_der[1]; fout[29] = lapse_der[2]; + fout[27] = lapse_der[0]; + fout[28] = lapse_der[1]; + fout[29] = lapse_der[2]; // Set shift vector derivatives. - fout[30] = shift_der[0][0]; fout[31] = shift_der[0][1]; fout[32] = shift_der[0][2]; - fout[33] = shift_der[1][0]; fout[34] = shift_der[1][1]; fout[35] = shift_der[1][2]; - fout[36] = shift_der[2][0]; fout[37] = shift_der[2][1]; fout[38] = shift_der[2][2]; + fout[30] = shift_der[0][0]; + fout[31] = shift_der[0][1]; + fout[32] = shift_der[0][2]; + fout[33] = shift_der[1][0]; + fout[34] = shift_der[1][1]; + fout[35] = shift_der[1][2]; + fout[36] = shift_der[2][0]; + fout[37] = shift_der[2][1]; + fout[38] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[39] = spatial_metric_der[0][0][0]; fout[40] = spatial_metric_der[0][0][1]; fout[41] = spatial_metric_der[0][0][2]; - fout[42] = spatial_metric_der[0][1][0]; fout[43] = spatial_metric_der[0][1][1]; fout[44] = spatial_metric_der[0][1][2]; - fout[45] = spatial_metric_der[0][2][0]; fout[46] = spatial_metric_der[0][2][1]; fout[47] = spatial_metric_der[0][2][2]; - - fout[48] = spatial_metric_der[1][0][0]; fout[49] = spatial_metric_der[1][0][1]; fout[50] = spatial_metric_der[1][0][2]; - fout[51] = spatial_metric_der[1][1][0]; fout[52] = spatial_metric_der[1][1][1]; fout[53] = spatial_metric_der[1][1][2]; - fout[54] = spatial_metric_der[1][2][0]; fout[55] = spatial_metric_der[1][2][1]; fout[56] = spatial_metric_der[1][2][2]; - - fout[57] = spatial_metric_der[2][0][0]; fout[58] = spatial_metric_der[2][0][1]; fout[59] = spatial_metric_der[2][0][2]; - fout[60] = spatial_metric_der[2][1][0]; fout[61] = spatial_metric_der[2][1][1]; fout[62] = spatial_metric_der[2][1][2]; - fout[63] = spatial_metric_der[2][2][0]; fout[64] = spatial_metric_der[2][2][1]; fout[65] = spatial_metric_der[2][2][2]; + fout[39] = spatial_metric_der[0][0][0]; + fout[40] = spatial_metric_der[0][0][1]; + fout[41] = spatial_metric_der[0][0][2]; + fout[42] = spatial_metric_der[0][1][0]; + fout[43] = spatial_metric_der[0][1][1]; + fout[44] = spatial_metric_der[0][1][2]; + fout[45] = spatial_metric_der[0][2][0]; + fout[46] = spatial_metric_der[0][2][1]; + fout[47] = spatial_metric_der[0][2][2]; + + fout[48] = spatial_metric_der[1][0][0]; + fout[49] = spatial_metric_der[1][0][1]; + fout[50] = spatial_metric_der[1][0][2]; + fout[51] = spatial_metric_der[1][1][0]; + fout[52] = spatial_metric_der[1][1][1]; + fout[53] = spatial_metric_der[1][1][2]; + fout[54] = spatial_metric_der[1][2][0]; + fout[55] = spatial_metric_der[1][2][1]; + fout[56] = spatial_metric_der[1][2][2]; + + fout[57] = spatial_metric_der[2][0][0]; + fout[58] = spatial_metric_der[2][0][1]; + fout[59] = spatial_metric_der[2][0][2]; + fout[60] = spatial_metric_der[2][1][0]; + fout[61] = spatial_metric_der[2][1][1]; + fout[62] = spatial_metric_der[2][1][2]; + fout[63] = spatial_metric_der[2][2][0]; + fout[64] = spatial_metric_der[2][2][1]; + fout[65] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[66] = 0.0; // Set spatial coordinates. - fout[67] = x; fout[68] = y; fout[69] = 0.0; + fout[67] = x; + fout[68] = y; + fout[69] = 0.0; if (in_excision_region) { for (int i = 0; i < 66; i++) { @@ -317,8 +372,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -332,24 +386,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -364,18 +419,21 @@ main(int argc, char **argv) gkyl_mem_debug_set(true); } - struct ultra_rel_blackhole_collapse_ctx ctx = create_ctx(); // Context for initialization functions. + struct ultra_rel_blackhole_collapse_ctx ctx = + create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_ultra_rel_euler", .equation = gr_ultra_rel_euler, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -383,8 +441,8 @@ main(int argc, char **argv) .has_gr_ultra_rel = true, .gr_ultra_rel_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -395,7 +453,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -403,8 +461,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -418,22 +475,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -457,9 +504,9 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -467,13 +514,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -487,10 +531,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -499,26 +547,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -534,7 +587,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -549,8 +602,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -558,7 +610,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -566,8 +620,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -594,14 +647,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_ultra_rel_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_ultra_rel_shock.c b/moments/creg/rt_gr_ultra_rel_shock.c index 3efc268bce..d84b80e9ce 100644 --- a/moments/creg/rt_gr_ultra_rel_shock.c +++ b/moments/creg/rt_gr_ultra_rel_shock.c @@ -24,8 +24,7 @@ #include -struct ultra_rel_shock_ctx -{ +struct ultra_rel_shock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -56,8 +55,7 @@ struct ultra_rel_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct ultra_rel_shock_ctx -create_ctx(void) +struct ultra_rel_shock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 4.0 / 3.0; // Adiabatic index. @@ -107,14 +105,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct ultra_rel_shock_ctx *app = ctx; @@ -139,8 +136,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid normal velocity (left). v = vl; // Fluid tangential velocity (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid normal velocity (right). v = vr; // Fluid tangential velocity (right). @@ -150,25 +146,25 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -179,17 +175,28 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = v; vel[2] = 0.0; + vel[0] = u; + vel[1] = v; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -205,63 +212,108 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double p = (gas_gamma - 1.0) * rho; double Etot = sqrt(spatial_det) * (((rho + p) * (W * W)) - p); // Fluid total energy density. - double mom_x = sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). - double mom_y = sqrt(spatial_det) * (rho + p) * (W * W) * v; // Fluid momentum density (y-direction). + double mom_x = + sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). + double mom_y = + sqrt(spatial_det) * (rho + p) * (W * W) * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). // Set fluid total energy density. fout[0] = Etot; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set lapse gauge variable. fout[4] = lapse; // Set shift gauge variables. - fout[5] = shift[0]; fout[6] = shift[1]; fout[7] = shift[2]; + fout[5] = shift[0]; + fout[6] = shift[1]; + fout[7] = shift[2]; // Set spatial metric tensor. - fout[8] = spatial_metric[0][0]; fout[9] = spatial_metric[0][1]; fout[10] = spatial_metric[0][2]; - fout[11] = spatial_metric[1][0]; fout[12] = spatial_metric[1][1]; fout[13] = spatial_metric[1][2]; - fout[14] = spatial_metric[2][0]; fout[15] = spatial_metric[2][1]; fout[16] = spatial_metric[2][2]; + fout[8] = spatial_metric[0][0]; + fout[9] = spatial_metric[0][1]; + fout[10] = spatial_metric[0][2]; + fout[11] = spatial_metric[1][0]; + fout[12] = spatial_metric[1][1]; + fout[13] = spatial_metric[1][2]; + fout[14] = spatial_metric[2][0]; + fout[15] = spatial_metric[2][1]; + fout[16] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[17] = extrinsic_curvature[0][0]; fout[18] = extrinsic_curvature[0][1]; fout[19] = extrinsic_curvature[0][2]; - fout[20] = extrinsic_curvature[1][0]; fout[21] = extrinsic_curvature[1][1]; fout[22] = extrinsic_curvature[1][2]; - fout[23] = extrinsic_curvature[2][0]; fout[24] = extrinsic_curvature[2][1]; fout[25] = extrinsic_curvature[2][2]; + fout[17] = extrinsic_curvature[0][0]; + fout[18] = extrinsic_curvature[0][1]; + fout[19] = extrinsic_curvature[0][2]; + fout[20] = extrinsic_curvature[1][0]; + fout[21] = extrinsic_curvature[1][1]; + fout[22] = extrinsic_curvature[1][2]; + fout[23] = extrinsic_curvature[2][0]; + fout[24] = extrinsic_curvature[2][1]; + fout[25] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[26] = -1.0; - } - else { + } else { fout[26] = 1.0; } // Set lapse function derivatives. - fout[27] = lapse_der[0]; fout[28] = lapse_der[1]; fout[29] = lapse_der[2]; + fout[27] = lapse_der[0]; + fout[28] = lapse_der[1]; + fout[29] = lapse_der[2]; // Set shift vector derivatives. - fout[30] = shift_der[0][0]; fout[31] = shift_der[0][1]; fout[32] = shift_der[0][2]; - fout[33] = shift_der[1][0]; fout[34] = shift_der[1][1]; fout[35] = shift_der[1][2]; - fout[36] = shift_der[2][0]; fout[37] = shift_der[2][1]; fout[38] = shift_der[2][2]; + fout[30] = shift_der[0][0]; + fout[31] = shift_der[0][1]; + fout[32] = shift_der[0][2]; + fout[33] = shift_der[1][0]; + fout[34] = shift_der[1][1]; + fout[35] = shift_der[1][2]; + fout[36] = shift_der[2][0]; + fout[37] = shift_der[2][1]; + fout[38] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[39] = spatial_metric_der[0][0][0]; fout[40] = spatial_metric_der[0][0][1]; fout[41] = spatial_metric_der[0][0][2]; - fout[42] = spatial_metric_der[0][1][0]; fout[43] = spatial_metric_der[0][1][1]; fout[44] = spatial_metric_der[0][1][2]; - fout[45] = spatial_metric_der[0][2][0]; fout[46] = spatial_metric_der[0][2][1]; fout[47] = spatial_metric_der[0][2][2]; - - fout[48] = spatial_metric_der[1][0][0]; fout[49] = spatial_metric_der[1][0][1]; fout[50] = spatial_metric_der[1][0][2]; - fout[51] = spatial_metric_der[1][1][0]; fout[52] = spatial_metric_der[1][1][1]; fout[53] = spatial_metric_der[1][1][2]; - fout[54] = spatial_metric_der[1][2][0]; fout[55] = spatial_metric_der[1][2][1]; fout[56] = spatial_metric_der[1][2][2]; - - fout[57] = spatial_metric_der[2][0][0]; fout[58] = spatial_metric_der[2][0][1]; fout[59] = spatial_metric_der[2][0][2]; - fout[60] = spatial_metric_der[2][1][0]; fout[61] = spatial_metric_der[2][1][1]; fout[62] = spatial_metric_der[2][1][2]; - fout[63] = spatial_metric_der[2][2][0]; fout[64] = spatial_metric_der[2][2][1]; fout[65] = spatial_metric_der[2][2][2]; + fout[39] = spatial_metric_der[0][0][0]; + fout[40] = spatial_metric_der[0][0][1]; + fout[41] = spatial_metric_der[0][0][2]; + fout[42] = spatial_metric_der[0][1][0]; + fout[43] = spatial_metric_der[0][1][1]; + fout[44] = spatial_metric_der[0][1][2]; + fout[45] = spatial_metric_der[0][2][0]; + fout[46] = spatial_metric_der[0][2][1]; + fout[47] = spatial_metric_der[0][2][2]; + + fout[48] = spatial_metric_der[1][0][0]; + fout[49] = spatial_metric_der[1][0][1]; + fout[50] = spatial_metric_der[1][0][2]; + fout[51] = spatial_metric_der[1][1][0]; + fout[52] = spatial_metric_der[1][1][1]; + fout[53] = spatial_metric_der[1][1][2]; + fout[54] = spatial_metric_der[1][2][0]; + fout[55] = spatial_metric_der[1][2][1]; + fout[56] = spatial_metric_der[1][2][2]; + + fout[57] = spatial_metric_der[2][0][0]; + fout[58] = spatial_metric_der[2][0][1]; + fout[59] = spatial_metric_der[2][0][2]; + fout[60] = spatial_metric_der[2][1][0]; + fout[61] = spatial_metric_der[2][1][1]; + fout[62] = spatial_metric_der[2][1][2]; + fout[63] = spatial_metric_der[2][2][0]; + fout[64] = spatial_metric_der[2][2][1]; + fout[65] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[66] = 0.0; // Set spatial coordinates. - fout[67] = x; fout[68] = 0.0; fout[69] = 0.0; + fout[67] = x; + fout[68] = 0.0; + fout[69] = 0.0; if (in_excision_region) { for (int i = 0; i < 66; i++) { @@ -290,8 +342,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -305,24 +356,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -342,12 +394,14 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_ultra_rel_euler", .equation = gr_ultra_rel_euler, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -355,7 +409,7 @@ main(int argc, char **argv) .has_gr_ultra_rel = true, .gr_ultra_rel_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -366,7 +420,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -374,8 +428,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -389,22 +442,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -428,20 +471,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -455,10 +494,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -467,26 +510,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -502,7 +550,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -517,8 +565,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -526,7 +573,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -534,8 +583,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -562,14 +610,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_ultra_rel_euler); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_ultra_rel_shock_tetrad.c b/moments/creg/rt_gr_ultra_rel_shock_tetrad.c index 7438f7d88c..4e142ee3cf 100644 --- a/moments/creg/rt_gr_ultra_rel_shock_tetrad.c +++ b/moments/creg/rt_gr_ultra_rel_shock_tetrad.c @@ -24,8 +24,7 @@ #include -struct ultra_rel_shock_ctx -{ +struct ultra_rel_shock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -56,8 +55,7 @@ struct ultra_rel_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct ultra_rel_shock_ctx -create_ctx(void) +struct ultra_rel_shock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 4.0 / 3.0; // Adiabatic index. @@ -107,14 +105,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct ultra_rel_shock_ctx *app = ctx; @@ -139,8 +136,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT rho = rhol; // Fluid mass density (left). u = ul; // Fluid normal velocity (left). v = vl; // Fluid tangential velocity (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid normal velocity (right). v = vr; // Fluid tangential velocity (right). @@ -150,25 +146,25 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -179,17 +175,28 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); double v_sq = 0.0; - vel[0] = u; vel[1] = v; vel[2] = 0.0; + vel[0] = u; + vel[1] = v; + vel[2] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -205,63 +212,108 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double p = (gas_gamma - 1.0) * rho; double Etot = sqrt(spatial_det) * (((rho + p) * (W * W)) - p); // Fluid total energy density. - double mom_x = sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). - double mom_y = sqrt(spatial_det) * (rho + p) * (W * W) * v; // Fluid momentum density (y-direction). + double mom_x = + sqrt(spatial_det) * (rho + p) * (W * W) * u; // Fluid momentum density (x-direction). + double mom_y = + sqrt(spatial_det) * (rho + p) * (W * W) * v; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). // Set fluid total energy density. fout[0] = Etot; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set lapse gauge variable. fout[4] = lapse; // Set shift gauge variables. - fout[5] = shift[0]; fout[6] = shift[1]; fout[7] = shift[2]; + fout[5] = shift[0]; + fout[6] = shift[1]; + fout[7] = shift[2]; // Set spatial metric tensor. - fout[8] = spatial_metric[0][0]; fout[9] = spatial_metric[0][1]; fout[10] = spatial_metric[0][2]; - fout[11] = spatial_metric[1][0]; fout[12] = spatial_metric[1][1]; fout[13] = spatial_metric[1][2]; - fout[14] = spatial_metric[2][0]; fout[15] = spatial_metric[2][1]; fout[16] = spatial_metric[2][2]; + fout[8] = spatial_metric[0][0]; + fout[9] = spatial_metric[0][1]; + fout[10] = spatial_metric[0][2]; + fout[11] = spatial_metric[1][0]; + fout[12] = spatial_metric[1][1]; + fout[13] = spatial_metric[1][2]; + fout[14] = spatial_metric[2][0]; + fout[15] = spatial_metric[2][1]; + fout[16] = spatial_metric[2][2]; // Set extrinsic curvature tensor. - fout[17] = extrinsic_curvature[0][0]; fout[18] = extrinsic_curvature[0][1]; fout[19] = extrinsic_curvature[0][2]; - fout[20] = extrinsic_curvature[1][0]; fout[21] = extrinsic_curvature[1][1]; fout[22] = extrinsic_curvature[1][2]; - fout[23] = extrinsic_curvature[2][0]; fout[24] = extrinsic_curvature[2][1]; fout[25] = extrinsic_curvature[2][2]; + fout[17] = extrinsic_curvature[0][0]; + fout[18] = extrinsic_curvature[0][1]; + fout[19] = extrinsic_curvature[0][2]; + fout[20] = extrinsic_curvature[1][0]; + fout[21] = extrinsic_curvature[1][1]; + fout[22] = extrinsic_curvature[1][2]; + fout[23] = extrinsic_curvature[2][0]; + fout[24] = extrinsic_curvature[2][1]; + fout[25] = extrinsic_curvature[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[26] = -1.0; - } - else { + } else { fout[26] = 1.0; } // Set lapse function derivatives. - fout[27] = lapse_der[0]; fout[28] = lapse_der[1]; fout[29] = lapse_der[2]; + fout[27] = lapse_der[0]; + fout[28] = lapse_der[1]; + fout[29] = lapse_der[2]; // Set shift vector derivatives. - fout[30] = shift_der[0][0]; fout[31] = shift_der[0][1]; fout[32] = shift_der[0][2]; - fout[33] = shift_der[1][0]; fout[34] = shift_der[1][1]; fout[35] = shift_der[1][2]; - fout[36] = shift_der[2][0]; fout[37] = shift_der[2][1]; fout[38] = shift_der[2][2]; + fout[30] = shift_der[0][0]; + fout[31] = shift_der[0][1]; + fout[32] = shift_der[0][2]; + fout[33] = shift_der[1][0]; + fout[34] = shift_der[1][1]; + fout[35] = shift_der[1][2]; + fout[36] = shift_der[2][0]; + fout[37] = shift_der[2][1]; + fout[38] = shift_der[2][2]; // Set spatial metric tensor derivatives. - fout[39] = spatial_metric_der[0][0][0]; fout[40] = spatial_metric_der[0][0][1]; fout[41] = spatial_metric_der[0][0][2]; - fout[42] = spatial_metric_der[0][1][0]; fout[43] = spatial_metric_der[0][1][1]; fout[44] = spatial_metric_der[0][1][2]; - fout[45] = spatial_metric_der[0][2][0]; fout[46] = spatial_metric_der[0][2][1]; fout[47] = spatial_metric_der[0][2][2]; - - fout[48] = spatial_metric_der[1][0][0]; fout[49] = spatial_metric_der[1][0][1]; fout[50] = spatial_metric_der[1][0][2]; - fout[51] = spatial_metric_der[1][1][0]; fout[52] = spatial_metric_der[1][1][1]; fout[53] = spatial_metric_der[1][1][2]; - fout[54] = spatial_metric_der[1][2][0]; fout[55] = spatial_metric_der[1][2][1]; fout[56] = spatial_metric_der[1][2][2]; - - fout[57] = spatial_metric_der[2][0][0]; fout[58] = spatial_metric_der[2][0][1]; fout[59] = spatial_metric_der[2][0][2]; - fout[60] = spatial_metric_der[2][1][0]; fout[61] = spatial_metric_der[2][1][1]; fout[62] = spatial_metric_der[2][1][2]; - fout[63] = spatial_metric_der[2][2][0]; fout[64] = spatial_metric_der[2][2][1]; fout[65] = spatial_metric_der[2][2][2]; + fout[39] = spatial_metric_der[0][0][0]; + fout[40] = spatial_metric_der[0][0][1]; + fout[41] = spatial_metric_der[0][0][2]; + fout[42] = spatial_metric_der[0][1][0]; + fout[43] = spatial_metric_der[0][1][1]; + fout[44] = spatial_metric_der[0][1][2]; + fout[45] = spatial_metric_der[0][2][0]; + fout[46] = spatial_metric_der[0][2][1]; + fout[47] = spatial_metric_der[0][2][2]; + + fout[48] = spatial_metric_der[1][0][0]; + fout[49] = spatial_metric_der[1][0][1]; + fout[50] = spatial_metric_der[1][0][2]; + fout[51] = spatial_metric_der[1][1][0]; + fout[52] = spatial_metric_der[1][1][1]; + fout[53] = spatial_metric_der[1][1][2]; + fout[54] = spatial_metric_der[1][2][0]; + fout[55] = spatial_metric_der[1][2][1]; + fout[56] = spatial_metric_der[1][2][2]; + + fout[57] = spatial_metric_der[2][0][0]; + fout[58] = spatial_metric_der[2][0][1]; + fout[59] = spatial_metric_der[2][0][2]; + fout[60] = spatial_metric_der[2][1][0]; + fout[61] = spatial_metric_der[2][1][1]; + fout[62] = spatial_metric_der[2][1][2]; + fout[63] = spatial_metric_der[2][2][0]; + fout[64] = spatial_metric_der[2][2][1]; + fout[65] = spatial_metric_der[2][2][2]; // Set evolution parameter. fout[66] = 0.0; // Set spatial coordinates. - fout[67] = x; fout[68] = 0.0; fout[69] = 0.0; + fout[67] = x; + fout[68] = 0.0; + fout[69] = 0.0; if (in_excision_region) { for (int i = 0; i < 66; i++) { @@ -290,8 +342,7 @@ evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -305,24 +356,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -342,12 +394,14 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new(ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new( + ctx.gas_gamma, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "gr_ultra_rel_euler_tetrad", .equation = gr_ultra_rel_euler_tetrad, - + .init = evalGREulerInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -355,7 +409,7 @@ main(int argc, char **argv) .has_gr_ultra_rel = true, .gr_ultra_rel_gas_gamma = ctx.gas_gamma, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -366,7 +420,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -374,8 +428,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -389,22 +442,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -428,20 +471,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -455,10 +494,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -467,26 +510,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -502,7 +550,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -517,8 +565,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -526,7 +573,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -534,8 +583,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -562,14 +610,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_ultra_rel_euler_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_wald_magnetosphere_spinning.c b/moments/creg/rt_gr_wald_magnetosphere_spinning.c index 6c3c3dd025..b538ab26cf 100644 --- a/moments/creg/rt_gr_wald_magnetosphere_spinning.c +++ b/moments/creg/rt_gr_wald_magnetosphere_spinning.c @@ -26,8 +26,7 @@ #include -struct wald_magnetosphere_spinning_ctx -{ +struct wald_magnetosphere_spinning_ctx { // Physical constants (using normalized code units). double light_speed; // Speed of light. double e_fact; // Factor of speed of light for electric field correction. @@ -64,8 +63,7 @@ struct wald_magnetosphere_spinning_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct wald_magnetosphere_spinning_ctx -create_ctx(void) +struct wald_magnetosphere_spinning_ctx create_ctx(void) { // Physical constants (using normalized code units). double light_speed = 1.0; // Speed of light. @@ -83,7 +81,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -125,14 +124,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct wald_magnetosphere_spinning_ctx *app = ctx; @@ -140,52 +140,64 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC struct gkyl_gr_spacetime *spacetime = app->spacetime; double B0 = app->B0; - + double lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - + spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - + double Dx = 0.0; // Total electric field (x-direction). double Dy = 0.0; // Total electric field (y-direction). double Dz = 0.0; // Total electric field (z-direction). - + double Bx = 0.125 * x * B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -193,7 +205,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = y; fout[25] = 0.0; + fout[23] = x; + fout[24] = y; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -210,8 +224,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -225,24 +238,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -257,24 +271,28 @@ main(int argc, char **argv) gkyl_mem_debug_set(true); } - struct wald_magnetosphere_spinning_ctx ctx = create_ctx(); // Context for initialization functions. + struct wald_magnetosphere_spinning_ctx ctx = + create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Field. - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell, - + .init = evalGRMaxwellInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -285,7 +303,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -293,8 +311,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -308,22 +325,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -347,20 +354,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -374,10 +378,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -386,26 +394,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -421,7 +434,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -436,8 +449,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -445,7 +457,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -453,8 +467,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -481,14 +494,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_wald_magnetosphere_spinning_neutronstar.c b/moments/creg/rt_gr_wald_magnetosphere_spinning_neutronstar.c index 3a9582dbcf..cd23282d35 100644 --- a/moments/creg/rt_gr_wald_magnetosphere_spinning_neutronstar.c +++ b/moments/creg/rt_gr_wald_magnetosphere_spinning_neutronstar.c @@ -26,8 +26,7 @@ #include -struct wald_magnetosphere_spinning_ctx -{ +struct wald_magnetosphere_spinning_ctx { // Physical constants (using normalized code units). double light_speed; // Speed of light. double e_fact; // Factor of speed of light for electric field correction. @@ -76,8 +75,7 @@ struct wald_magnetosphere_spinning_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct wald_magnetosphere_spinning_ctx -create_ctx(void) +struct wald_magnetosphere_spinning_ctx create_ctx(void) { // Physical constants (using normalized code units). double light_speed = 1.0; // Speed of light. @@ -99,15 +97,27 @@ create_ctx(void) double spin_dimensionless = ang_mom / (mass * mass); // Dimensionless spin of the neutron star. double alpha = 5.0; // Neutron star alpha parameter (mass quadrupole moment coefficient). - double beta = pow(-0.36 + (1.48 * pow(sqrt(alpha), 0.65)), 3.0); // Neutron star beta parameter (spin octupole moment coefficient). - double gamma = pow(-4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), 4.0); // Neutron star gamma parameter (mass hexadecapole moment coefficient). - - double mass_quadrupole = -alpha * (spin_dimensionless * spin_dimensionless) * (mass * mass * mass); // Neutron star mass quadrupole. - double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass); // Neutron star spin octupole. - double mass_hexadecapole = gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass * mass); // Neutron star mass hexadecapole. + double beta = pow( + -0.36 + (1.48 * pow(sqrt(alpha), 0.65)), + 3.0 + ); // Neutron star beta parameter (spin octupole moment coefficient). + double gamma = pow( + -4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), + 4.0 + ); // Neutron star gamma parameter (mass hexadecapole moment coefficient). + + double mass_quadrupole = -alpha * (spin_dimensionless * spin_dimensionless) * + (mass * mass * mass); // Neutron star mass quadrupole. + double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass); // Neutron star spin octupole. + double mass_hexadecapole = + gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass * mass); // Neutron star mass hexadecapole. // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -157,14 +167,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct wald_magnetosphere_spinning_ctx *app = ctx; @@ -172,52 +183,64 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC struct gkyl_gr_spacetime *spacetime = app->spacetime; double B0 = app->B0; - + double lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - + spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - + double Dx = 0.0; // Total electric field (x-direction). double Dy = 0.0; // Total electric field (y-direction). double Dz = 0.0; // Total electric field (z-direction). - + double Bx = 0.125 * x * B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -225,7 +248,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = y; fout[25] = 0.0; + fout[23] = x; + fout[24] = y; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -242,8 +267,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -257,24 +281,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -289,24 +314,28 @@ main(int argc, char **argv) gkyl_mem_debug_set(true); } - struct wald_magnetosphere_spinning_ctx ctx = create_ctx(); // Context for initialization functions. + struct wald_magnetosphere_spinning_ctx ctx = + create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Field. - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell, - + .init = evalGRMaxwellInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -317,7 +346,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -325,8 +354,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -340,22 +368,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -379,20 +397,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -406,10 +421,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -418,26 +437,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -453,7 +477,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -468,8 +492,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -477,7 +500,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -485,8 +510,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -513,14 +537,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_wald_magnetosphere_spinning_tetrad.c b/moments/creg/rt_gr_wald_magnetosphere_spinning_tetrad.c index c09705bbcb..96bc932309 100644 --- a/moments/creg/rt_gr_wald_magnetosphere_spinning_tetrad.c +++ b/moments/creg/rt_gr_wald_magnetosphere_spinning_tetrad.c @@ -26,8 +26,7 @@ #include -struct wald_magnetosphere_spinning_ctx -{ +struct wald_magnetosphere_spinning_ctx { // Physical constants (using normalized code units). double light_speed; // Speed of light. double e_fact; // Factor of speed of light for electric field correction. @@ -64,8 +63,7 @@ struct wald_magnetosphere_spinning_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct wald_magnetosphere_spinning_ctx -create_ctx(void) +struct wald_magnetosphere_spinning_ctx create_ctx(void) { // Physical constants (using normalized code units). double light_speed = 1.0; // Speed of light. @@ -83,7 +81,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -125,14 +124,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct wald_magnetosphere_spinning_ctx *app = ctx; @@ -140,52 +140,64 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC struct gkyl_gr_spacetime *spacetime = app->spacetime; double B0 = app->B0; - + double lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - + spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - + double Dx = 0.0; // Total electric field (x-direction). double Dy = 0.0; // Total electric field (y-direction). double Dz = 0.0; // Total electric field (z-direction). - + double Bx = 0.125 * x * B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -193,7 +205,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = y; fout[25] = 0.0; + fout[23] = x; + fout[24] = y; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -210,8 +224,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -225,24 +238,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -257,24 +271,28 @@ main(int argc, char **argv) gkyl_mem_debug_set(true); } - struct wald_magnetosphere_spinning_ctx ctx = create_ctx(); // Context for initialization functions. + struct wald_magnetosphere_spinning_ctx ctx = + create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Field. - struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell_tetrad, - + .init = evalGRMaxwellInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -285,7 +303,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -293,8 +311,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -308,22 +325,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -347,20 +354,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -374,10 +378,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -386,26 +394,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -421,7 +434,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -436,8 +449,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -445,7 +457,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -453,8 +467,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -481,14 +494,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_wald_magnetosphere_static.c b/moments/creg/rt_gr_wald_magnetosphere_static.c index 762543d8c8..d7285dc215 100644 --- a/moments/creg/rt_gr_wald_magnetosphere_static.c +++ b/moments/creg/rt_gr_wald_magnetosphere_static.c @@ -26,8 +26,7 @@ #include -struct wald_magnetosphere_static_ctx -{ +struct wald_magnetosphere_static_ctx { // Physical constants (using normalized code units). double light_speed; // Speed of light. double e_fact; // Factor of speed of light for electric field correction. @@ -64,8 +63,7 @@ struct wald_magnetosphere_static_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct wald_magnetosphere_static_ctx -create_ctx(void) +struct wald_magnetosphere_static_ctx create_ctx(void) { // Physical constants (using normalized code units). double light_speed = 1.0; // Speed of light. @@ -83,7 +81,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -125,14 +124,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct wald_magnetosphere_static_ctx *app = ctx; @@ -140,52 +140,64 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC struct gkyl_gr_spacetime *spacetime = app->spacetime; double B0 = app->B0; - + double lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - + spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - + double Dx = 0.0; // Total electric field (x-direction). double Dy = 0.0; // Total electric field (y-direction). double Dz = 0.0; // Total electric field (z-direction). - + double Bx = 0.125 * x * B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -193,7 +205,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = y; fout[25] = 0.0; + fout[23] = x; + fout[24] = y; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -210,8 +224,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -225,24 +238,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -263,18 +277,21 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Field. - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell, - + .init = evalGRMaxwellInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -285,7 +302,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -293,8 +310,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -308,22 +324,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -347,20 +353,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -374,10 +377,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -386,26 +393,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -421,7 +433,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -436,8 +448,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -445,7 +456,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -453,8 +466,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -481,14 +493,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_wald_magnetosphere_static_neutronstar.c b/moments/creg/rt_gr_wald_magnetosphere_static_neutronstar.c index e71b60cedf..beed053cd0 100644 --- a/moments/creg/rt_gr_wald_magnetosphere_static_neutronstar.c +++ b/moments/creg/rt_gr_wald_magnetosphere_static_neutronstar.c @@ -26,8 +26,7 @@ #include -struct wald_magnetosphere_static_ctx -{ +struct wald_magnetosphere_static_ctx { // Physical constants (using normalized code units). double light_speed; // Speed of light. double e_fact; // Factor of speed of light for electric field correction. @@ -76,8 +75,7 @@ struct wald_magnetosphere_static_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct wald_magnetosphere_static_ctx -create_ctx(void) +struct wald_magnetosphere_static_ctx create_ctx(void) { // Physical constants (using normalized code units). double light_speed = 1.0; // Speed of light. @@ -99,15 +97,27 @@ create_ctx(void) double spin_dimensionless = ang_mom / (mass * mass); // Dimensionless spin of the neutron star. double alpha = 5.0; // Neutron star alpha parameter (mass quadrupole moment coefficient). - double beta = pow(-0.36 + (1.48 * pow(sqrt(alpha), 0.65)), 3.0); // Neutron star beta parameter (spin octupole moment coefficient). - double gamma = pow(-4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), 4.0); // Neutron star gamma parameter (mass hexadecapole moment coefficient). - - double mass_quadrupole = -alpha * (spin_dimensionless * spin_dimensionless) * (mass * mass * mass); // Neutron star mass quadrupole. - double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass); // Neutron star spin octupole. - double mass_hexadecapole = gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass * mass); // Neutron star mass hexadecapole. + double beta = pow( + -0.36 + (1.48 * pow(sqrt(alpha), 0.65)), + 3.0 + ); // Neutron star beta parameter (spin octupole moment coefficient). + double gamma = pow( + -4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), + 4.0 + ); // Neutron star gamma parameter (mass hexadecapole moment coefficient). + + double mass_quadrupole = -alpha * (spin_dimensionless * spin_dimensionless) * + (mass * mass * mass); // Neutron star mass quadrupole. + double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass); // Neutron star spin octupole. + double mass_hexadecapole = + gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass * mass); // Neutron star mass hexadecapole. // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, pos_x, pos_y, pos_z + ); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -157,14 +167,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct wald_magnetosphere_static_ctx *app = ctx; @@ -172,52 +183,64 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC struct gkyl_gr_spacetime *spacetime = app->spacetime; double B0 = app->B0; - + double lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - + spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - + double Dx = 0.0; // Total electric field (x-direction). double Dy = 0.0; // Total electric field (y-direction). double Dz = 0.0; // Total electric field (z-direction). - + double Bx = 0.125 * x * B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -225,7 +248,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = y; fout[25] = 0.0; + fout[23] = x; + fout[24] = y; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -242,8 +267,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -257,24 +281,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -295,18 +320,21 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Field. - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell, - + .init = evalGRMaxwellInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -317,7 +345,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -325,8 +353,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -340,22 +367,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -379,20 +396,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -406,10 +420,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -418,26 +436,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -453,7 +476,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -468,8 +491,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -477,7 +499,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -485,8 +509,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -513,14 +536,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_gr_wald_magnetosphere_static_tetrad.c b/moments/creg/rt_gr_wald_magnetosphere_static_tetrad.c index d61517787d..5c81252fea 100644 --- a/moments/creg/rt_gr_wald_magnetosphere_static_tetrad.c +++ b/moments/creg/rt_gr_wald_magnetosphere_static_tetrad.c @@ -26,8 +26,7 @@ #include -struct wald_magnetosphere_static_ctx -{ +struct wald_magnetosphere_static_ctx { // Physical constants (using normalized code units). double light_speed; // Speed of light. double e_fact; // Factor of speed of light for electric field correction. @@ -64,8 +63,7 @@ struct wald_magnetosphere_static_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct wald_magnetosphere_static_ctx -create_ctx(void) +struct wald_magnetosphere_static_ctx create_ctx(void) { // Physical constants (using normalized code units). double light_speed = 1.0; // Speed of light. @@ -83,7 +81,8 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -125,14 +124,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalGRMaxwellInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct wald_magnetosphere_static_ctx *app = ctx; @@ -140,22 +140,22 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC struct gkyl_gr_spacetime *spacetime = app->spacetime; double B0 = app->B0; - + double lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - + spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - + double Dx = 0.0; // Total electric field (x-direction). double Dy = 0.0; // Total electric field (y-direction). double Dz = 0.0; // Total electric field (z-direction). @@ -163,29 +163,41 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double Bx = 0.125 * x * B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Dx; fout[1] = Dy; fout[2] = Dz; + fout[0] = Dx; + fout[1] = Dy; + fout[2] = Dz; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; // Set lapse gauge variable. fout[8] = lapse; // Set shift gauge variables. - fout[9] = shift[0]; fout[10] = shift[1]; fout[11] = shift[2]; + fout[9] = shift[0]; + fout[10] = shift[1]; + fout[11] = shift[2]; // Set spatial metric tensor. - fout[12] = spatial_metric[0][0]; fout[13] = spatial_metric[0][1]; fout[14] = spatial_metric[0][2]; - fout[15] = spatial_metric[1][0]; fout[16] = spatial_metric[1][1]; fout[17] = spatial_metric[1][2]; - fout[18] = spatial_metric[2][0]; fout[19] = spatial_metric[2][1]; fout[20] = spatial_metric[2][2]; + fout[12] = spatial_metric[0][0]; + fout[13] = spatial_metric[0][1]; + fout[14] = spatial_metric[0][2]; + fout[15] = spatial_metric[1][0]; + fout[16] = spatial_metric[1][1]; + fout[17] = spatial_metric[1][2]; + fout[18] = spatial_metric[2][0]; + fout[19] = spatial_metric[2][1]; + fout[20] = spatial_metric[2][2]; // Set excision boundary conditions. if (in_excision_region) { fout[21] = -1.0; - } - else { + } else { fout[21] = 1.0; } @@ -193,7 +205,9 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[22] = 0.0; // Set spatial coordinates. - fout[23] = x; fout[24] = y; fout[25] = 0.0; + fout[23] = x; + fout[24] = y; + fout[25] = 0.0; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -210,8 +224,7 @@ evalGRMaxwellInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC gkyl_free(shift); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -225,24 +238,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -263,18 +277,21 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Field. - struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new(ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, app_args.use_gpu); + struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new( + ctx.light_speed, ctx.e_fact, ctx.b_fact, ctx.spacetime_gauge, ctx.reinit_freq, ctx.spacetime, + app_args.use_gpu + ); struct gkyl_moment_species field = { .name = "field", .equation = gr_maxwell_tetrad, - + .init = evalGRMaxwellInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -285,7 +302,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -293,8 +310,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -308,22 +324,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -347,20 +353,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { field }, + .species = {field}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -374,10 +377,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -386,26 +393,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -421,7 +433,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -436,8 +448,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -445,7 +456,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -453,8 +466,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -481,14 +493,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(gr_maxwell_tetrad); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_iso_euler_friction.c b/moments/creg/rt_iso_euler_friction.c index 5bda9161b7..37e3aecfc4 100644 --- a/moments/creg/rt_iso_euler_friction.c +++ b/moments/creg/rt_iso_euler_friction.c @@ -17,8 +17,7 @@ #include -struct friction_ctx -{ +struct friction_ctx { // Physical constants (using normalized code units). double vt; // Thermal velocity. double epsilon0; // Permittivity of free space. @@ -56,8 +55,7 @@ struct friction_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct friction_ctx -create_ctx(void) +struct friction_ctx create_ctx(void) { // Physical constants (using normalized code units). double vt = 1.0; // Thermal velocity. @@ -76,7 +74,8 @@ create_ctx(void) double friction_Z = 1.0; // Ionization number for frictional sources. double friction_T_elc = 1.0; // Electron temperature for frictional sources. - double friction_Lambda_ee = exp(1.0); // Electron-electron collisional term for frictional sources. + double friction_Lambda_ee = + exp(1.0); // Electron-electron collisional term for frictional sources. // Derived physical quantities (using normalized code units). double rho_elc = n_elc * mass_elc; // Electron mass density. @@ -120,14 +119,13 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct friction_ctx *app = ctx; @@ -138,11 +136,12 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rho_elc; // Set electron momentum density. - fout[1] = mom_elc; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = mom_elc; + fout[2] = 0.0; + fout[3] = 0.0; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct friction_ctx *app = ctx; @@ -153,22 +152,25 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rho_ion; // Set ion momentum density. - fout[1] = mom_ion; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = mom_ion; + fout[2] = 0.0; + fout[3] = 0.0; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = 0.0, fout[4] = 0.0; fout[5] = 0.0; + fout[3] = 0.0, fout[4] = 0.0; + fout[5] = 0.0; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -180,8 +182,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -206,9 +207,10 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_iso_euler, - + .init = evalElcInit, .ctx = &ctx, @@ -216,32 +218,34 @@ main(int argc, char **argv) .use_explicit_friction = true, .friction_Z = ctx.friction_Z, .friction_T_elc = ctx.friction_T_elc, - .friction_Lambda_ee = ctx.friction_Lambda_ee, + .friction_Lambda_ee = ctx.friction_Lambda_ee }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_iso_euler, - + .init = evalIonInit, - .ctx = &ctx, + .ctx = &ctx, .has_friction = true, .use_explicit_friction = true, .friction_Z = ctx.friction_Z, .friction_T_elc = ctx.friction_T_elc, - .friction_Lambda_ee = ctx.friction_Lambda_ee, + .friction_Lambda_ee = ctx.friction_Lambda_ee }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .is_static = true, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -252,7 +256,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); struct gkyl_range global_r; gkyl_create_global_range(dim, cells, &global_r); @@ -263,8 +267,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -280,25 +283,15 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .decomp = decomp - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = decomp, - .use_gpu = app_args.use_gpu - } - ); + comm = + gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD, .decomp = decomp}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.decomp = decomp, .use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = decomp, - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.decomp = decomp, .use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -322,24 +315,20 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -352,7 +341,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_app_apply_ic(app, t_curr); @@ -370,7 +359,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -383,8 +372,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -392,11 +380,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -421,14 +410,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(ion_iso_euler); gkyl_rect_decomp_release(decomp); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_iso_euler_hartmann.c b/moments/creg/rt_iso_euler_hartmann.c index be775939e1..3c27d7d39a 100644 --- a/moments/creg/rt_iso_euler_hartmann.c +++ b/moments/creg/rt_iso_euler_hartmann.c @@ -17,8 +17,7 @@ #include -struct hartmann_ctx -{ +struct hartmann_ctx { // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -40,7 +39,7 @@ struct hartmann_ctx double T_elc; // Electron temperature. double T_ion; // Ion temperature. - double n_elc; // Electron number density. + double n_elc; // Electron number density. double n_ion; // Ion number density. double rho_elc; // Electron mass density. @@ -59,8 +58,7 @@ struct hartmann_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct hartmann_ctx -create_ctx(void) +struct hartmann_ctx create_ctx(void) { // Physical constants (using normalized code units). double epsilon0 = 8.854187817620389850536563031710750260608e-12; // Permittivity of free space. @@ -83,7 +81,7 @@ create_ctx(void) double T_elc = mass_elc * vte * vte / 2.0; // Electron temperature. double T_ion = mass_ion * vti * vti / 2.0; // Ion temperature. - double n_elc = beta * B0 * B0 / (2.0 * mu0 * T_elc); // Electron number density. + double n_elc = beta * B0 * B0 / (2.0 * mu0 * T_elc); // Electron number density. double n_ion = beta * B0 * B0 / (2.0 * mu0 * T_elc); // Ion number density. double rho_elc = n_elc * mass_elc; // Electron mass density. @@ -129,14 +127,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hartmann_ctx *app = ctx; @@ -150,11 +147,12 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hartmann_ctx *app = ctx; @@ -168,11 +166,12 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hartmann_ctx *app = ctx; @@ -185,15 +184,17 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalAppAccel(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalAppAccel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hartmann_ctx *app = ctx; @@ -204,11 +205,12 @@ evalAppAccel(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double accel_z = 0.0; // Applied acceleration (z-direction). // Set applied acceleration. - fout[0] = accel_x; fout[1] = accel_y; fout[2] = accel_z; + fout[0] = accel_x; + fout[1] = accel_y; + fout[2] = accel_z; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -222,24 +224,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -264,9 +267,10 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_iso_euler, - + .init = evalElcInit, .ctx = &ctx, @@ -275,14 +279,15 @@ main(int argc, char **argv) .type_brag = GKYL_BRAG_MAG_FULL, - .bcx = { GKYL_SPECIES_NO_SLIP, GKYL_SPECIES_NO_SLIP }, + .bcx = {GKYL_SPECIES_NO_SLIP, GKYL_SPECIES_NO_SLIP} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_iso_euler, - + .init = evalIonInit, .ctx = &ctx, @@ -291,18 +296,19 @@ main(int argc, char **argv) .type_brag = GKYL_BRAG_MAG_FULL, - .bcx = { GKYL_SPECIES_NO_SLIP, GKYL_SPECIES_NO_SLIP }, + .bcx = {GKYL_SPECIES_NO_SLIP, GKYL_SPECIES_NO_SLIP} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .is_static = true, .init = evalFieldInit, .ctx = &ctx, - .bcx = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + .bcx = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -312,7 +318,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -320,8 +326,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -335,22 +340,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -374,27 +369,23 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .cfl_frac = ctx.cfl_frac, .has_braginskii = true, .coll_fac = ctx.coll_fac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -408,10 +399,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -420,26 +415,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -455,7 +455,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -470,8 +470,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -479,7 +478,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -487,8 +488,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -515,14 +515,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(elc_iso_euler); gkyl_wv_eqn_release(ion_iso_euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } \ No newline at end of file diff --git a/moments/creg/rt_iso_euler_mixture_fedkiw_shock.c b/moments/creg/rt_iso_euler_mixture_fedkiw_shock.c index ce9f106113..aff7acf298 100644 --- a/moments/creg/rt_iso_euler_mixture_fedkiw_shock.c +++ b/moments/creg/rt_iso_euler_mixture_fedkiw_shock.c @@ -17,8 +17,7 @@ #include -struct fedkiw_shock_ctx -{ +struct fedkiw_shock_ctx { // Physical constants (using normalized code units). double vt2; // First species thermal velocity. double vt1; // Second species thermal velocity. @@ -48,8 +47,7 @@ struct fedkiw_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct fedkiw_shock_ctx -create_ctx(void) +struct fedkiw_shock_ctx create_ctx(void) { // Physical constants (using normalized code units). double vt1 = 396.867658; // First species thermal velocity. @@ -99,14 +97,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalIsoEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIsoEulerMixtureInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct fedkiw_shock_ctx *app = ctx; @@ -140,15 +139,13 @@ evalIsoEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_R alpha1 = alpha1_l; // First species volume fraction (left). vx_total = ul; // Total mixture velocity (left). - } - else if (x < 0.5) { + } else if (x < 0.5) { rho1 = rhoc; // First species fluid mass density (central). rho2 = rhor; // Second species fluid mass density (right). alpha1 = alpha1_c; // First species volume fraction (central). vx_total = uc; // Total mixture velocity (central). - } - else { + } else { rho1 = rhoc; // First species fluid mass density (central). rho2 = rhor; // Second species fluid mass density (right). alpha1 = alpha1_r; // First species volume fraction (right). @@ -163,20 +160,23 @@ evalIsoEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_R double vol_frac1 = rho_total * alpha1; // Mixture weighted volume fraction (first species). double mass_frac1 = alpha1 * rho1; // Mixture volume-weighted mass density (first species). - double mass_frac2 = (1.0 - alpha1) * rho2; // Mixture volume-weighted mass density (second species). + double mass_frac2 = + (1.0 - alpha1) * rho2; // Mixture volume-weighted mass density (second species). // Set fluid mixture total mass density. fout[0] = rho_total; // Set fluid mixture total momentum density. - fout[1] = momx_total; fout[2] = momy_total; fout[3] = momz_total; + fout[1] = momx_total; + fout[2] = momy_total; + fout[3] = momz_total; // Set fluid mixture weighted volume fraction (first species). fout[4] = vol_frac1; // Set fluid mixture volume-weighted mass densities (first and second species). - fout[5] = mass_frac1; fout[6] = mass_frac2; + fout[5] = mass_frac1; + fout[6] = mass_frac2; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -190,24 +190,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -235,11 +236,11 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "iso_euler_mixture", .equation = iso_euler_mixture, - + .init = evalIsoEulerMixtureInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -250,7 +251,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -258,8 +259,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -273,22 +273,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -312,20 +302,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -339,10 +325,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -351,26 +341,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -386,7 +381,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -401,8 +396,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -410,7 +404,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -418,8 +414,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -448,13 +443,13 @@ main(int argc, char **argv) gkyl_moment_app_release(app); gkyl_free(vt_s); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_iso_euler_mixture_shock_bubble.c b/moments/creg/rt_iso_euler_mixture_shock_bubble.c index c78c2b440f..60ca7425b4 100644 --- a/moments/creg/rt_iso_euler_mixture_shock_bubble.c +++ b/moments/creg/rt_iso_euler_mixture_shock_bubble.c @@ -17,8 +17,7 @@ #include -struct shock_bubble_ctx -{ +struct shock_bubble_ctx { // Physical constants (using normalized code units). double vt1; // First species thermal velocity. double vt2; // Second species thermal velocity. @@ -55,8 +54,7 @@ struct shock_bubble_ctx double bub_rad; // Bubble radius. }; -struct shock_bubble_ctx -create_ctx(void) +struct shock_bubble_ctx create_ctx(void) { // Physical constants (using normalized code units). double vt1 = 1.067947; // First species thermal velocity. @@ -119,14 +117,15 @@ create_ctx(void) .x_loc = x_loc, .bub_loc_x = bub_loc_x, .bub_loc_y = bub_loc_y, - .bub_rad = bub_rad, + .bub_rad = bub_rad }; return ctx; } -void -evalIsoEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIsoEulerMixtureInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct shock_bubble_ctx *app = ctx; @@ -167,8 +166,7 @@ evalIsoEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_R alpha1 = alpha1_post; // First species volume fraction (post-shock). vx_total = u_post; // Total mixture velocity (post-shock). - } - else { + } else { rho1 = rho_pre; // First species fluid mass density (pre-shock). rho2 = rho_bub; // Second species fluid mass density (bubble). alpha1 = alpha1_pre; // First species volume fraction (pre-shock). @@ -192,20 +190,23 @@ evalIsoEulerMixtureInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_R double vol_frac1 = rho_total * alpha1; // Mixture weighted volume fraction (first species). double mass_frac1 = alpha1 * rho1; // Mixture volume-weighted mass density (first species). - double mass_frac2 = (1.0 - alpha1) * rho2; // Mixture volume-weighted mass density (second species). + double mass_frac2 = + (1.0 - alpha1) * rho2; // Mixture volume-weighted mass density (second species). // Set fluid mixture total mass density. fout[0] = rho_total; // Set fluid mixture total momentum density. - fout[1] = momx_total; fout[2] = momy_total; fout[3] = momz_total; + fout[1] = momx_total; + fout[2] = momy_total; + fout[3] = momz_total; // Set fluid mixture weighted volume fraction (first species). fout[4] = vol_frac1; // Set fluid mixture volume-weighted mass densities (first and second species). - fout[5] = mass_frac1; fout[6] = mass_frac2; + fout[5] = mass_frac1; + fout[6] = mass_frac2; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -219,24 +220,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -265,12 +267,12 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "iso_euler_mixture", .equation = iso_euler_mixture, - + .init = evalIsoEulerMixtureInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; int nrank = 1; // Number of processes in simulation. @@ -281,7 +283,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -289,8 +291,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -304,22 +305,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -343,20 +334,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -370,10 +358,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -382,26 +374,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -417,7 +414,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -432,8 +429,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -441,7 +437,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -449,8 +447,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -479,13 +476,13 @@ main(int argc, char **argv) gkyl_moment_app_release(app); gkyl_free(vt_s); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_iso_euler_sodshock.c b/moments/creg/rt_iso_euler_sodshock.c index bd11c97a9e..dbf7aeb92e 100644 --- a/moments/creg/rt_iso_euler_sodshock.c +++ b/moments/creg/rt_iso_euler_sodshock.c @@ -23,8 +23,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double cs; // Fluid sound speed. @@ -47,8 +46,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double cs = 1.0; // Fluid sound speed. @@ -85,14 +83,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct sodshock_ctx *app = ctx; @@ -109,8 +106,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo if (x < 0.5) { rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). } @@ -122,11 +118,12 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_y; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_y; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -140,24 +137,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -185,7 +183,7 @@ main(int argc, char **argv) .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -196,7 +194,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -204,8 +202,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -219,22 +216,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -258,20 +245,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -285,10 +268,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -297,26 +284,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -332,7 +324,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -347,8 +339,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -356,7 +347,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -364,14 +357,13 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } step += 1; } - + calc_field_energy(&fe_trig, app, t_curr, false); calc_integrated_mom(&im_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); @@ -391,14 +383,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(iso_euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_iso_euler_sodshock_lax.c b/moments/creg/rt_iso_euler_sodshock_lax.c index 3577082ab6..b6b8909427 100644 --- a/moments/creg/rt_iso_euler_sodshock_lax.c +++ b/moments/creg/rt_iso_euler_sodshock_lax.c @@ -23,8 +23,7 @@ #include -struct sodshock_lax_ctx -{ +struct sodshock_lax_ctx { // Physical constants (using normalized code units). double cs; // Fluid sound speed. @@ -47,8 +46,7 @@ struct sodshock_lax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_lax_ctx -create_ctx(void) +struct sodshock_lax_ctx create_ctx(void) { // Physical constants (using normalized code units). double cs = 1.0; // Fluid sound speed. @@ -85,14 +83,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct sodshock_lax_ctx *app = ctx; @@ -109,8 +106,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo if (x < 0.5) { rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). } @@ -122,11 +118,12 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_y; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_y; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -140,24 +137,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -186,7 +184,7 @@ main(int argc, char **argv) .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -197,7 +195,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -205,8 +203,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -220,22 +217,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -259,20 +246,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -286,10 +269,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -298,26 +285,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -333,7 +325,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -348,8 +340,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -357,7 +348,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -365,14 +358,13 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } step += 1; } - + calc_field_energy(&fe_trig, app, t_curr, false); calc_integrated_mom(&im_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); @@ -392,14 +384,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(iso_euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_iso_gem.c b/moments/creg/rt_iso_gem.c index bf3b79f19b..5cbd7e454f 100644 --- a/moments/creg/rt_iso_gem.c +++ b/moments/creg/rt_iso_gem.c @@ -23,11 +23,10 @@ #include -struct gem_ctx -{ +struct gem_ctx { // Mathematical constants (dimensionless). double pi; - + // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -41,7 +40,7 @@ struct gem_ctx double nb_over_n0; // Background number density / reference number density. double B0; // Reference magnetic field strength. double beta; // Plasma beta. - + // Derived physical quantities (using normalized code units). double psi0; // Reference magnetic scalar potential. @@ -67,8 +66,7 @@ struct gem_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct gem_ctx -create_ctx(void) +struct gem_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -86,7 +84,7 @@ create_ctx(void) double nb_over_n0 = 0.2; // Background number density / reference number density. double B0 = 0.1; // Reference magnetic field strength. double beta = 1.0; // Plasma beta. - + // Derived physical quantities (using normalized code units). double psi0 = 0.1 * B0; // Reference magnetic scalar potential. @@ -141,14 +139,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_ctx *app = ctx; @@ -162,7 +159,8 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Te_frac = app->Te_frac; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -170,16 +168,18 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double rhoe = n * mass_elc; // Electron mass density. double mome_x = 0.0; // Electron momentum density (x-direction). double mome_y = 0.0; // Electron momentum density (y-direction). - double mome_z = (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). + double mome_z = + (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_ctx *app = ctx; @@ -193,7 +193,8 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double Ti_frac = app->Ti_frac; - double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + double sech_sq = + (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. double n = n0 * (sech_sq + nb_over_n0); // Total number density. double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). @@ -206,11 +207,12 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set ion mass density. fout[0] = rhoi; // Set ion momentum density. - fout[1] = momi_x; fout[2] = momi_y; fout[3] = momi_z; + fout[1] = momi_x; + fout[2] = momi_y; + fout[3] = momi_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct gem_ctx *app = ctx; @@ -231,20 +233,24 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ey = 0.0; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * sin(pi * y / Ly); // Total magnetic field (x-direction). - double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * cos(pi * y / Ly); // Total magnetic field (y-direction). + double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * + sin(pi * y / Ly); // Total magnetic field (x-direction). + double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * + cos(pi * y / Ly); // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -258,24 +264,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -301,33 +308,36 @@ main(int argc, char **argv) struct gkyl_moment_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_iso_euler, .init = evalElcInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; struct gkyl_moment_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, .equation = ion_iso_euler, .init = evalIonInit, .ctx = &ctx, - .bcy = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcy = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .mag_error_speed_fact = 1.0, - + .init = evalFieldInit, .ctx = &ctx, - - .bcy = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + + .bcy = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -338,7 +348,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -346,8 +356,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -361,22 +370,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -400,24 +399,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -431,10 +427,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -443,26 +443,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -478,7 +483,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -493,8 +498,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -502,7 +506,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -510,8 +516,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -538,14 +543,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(elc_iso_euler); gkyl_wv_eqn_release(ion_iso_euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } -#endif - +#endif + return 0; } diff --git a/moments/creg/rt_maxwell_annular_wg.c b/moments/creg/rt_maxwell_annular_wg.c index 312ca00947..59caaba898 100644 --- a/moments/creg/rt_maxwell_annular_wg.c +++ b/moments/creg/rt_maxwell_annular_wg.c @@ -17,8 +17,7 @@ #include -struct annular_wg_ctx -{ +struct annular_wg_ctx { // Mathematical constants (dimensionless). double pi; @@ -49,8 +48,7 @@ struct annular_wg_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct annular_wg_ctx -create_ctx(void) +struct annular_wg_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -100,14 +98,13 @@ create_ctx(void) .field_energy_writes = field_energy_writes, .integrated_mom_writes = integrated_mom_writes, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { double r = zc[0], theta = zc[1]; struct annular_wg_ctx *app = ctx; @@ -117,26 +114,30 @@ evalFieldInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo double a_coeff = app->a_coeff; double b_coeff = app->b_coeff; - double Ez_radial = (a_coeff * jn(bessel_order, r * w_mode)) + (b_coeff * yn(bessel_order, r * w_mode)); + double Ez_radial = + (a_coeff * jn(bessel_order, r * w_mode)) + (b_coeff * yn(bessel_order, r * w_mode)); double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). double Ez = Ez_radial * cos(2.0 * theta); // Total electric field (z-direction). - + double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double r = zc[0], theta = zc[1]; @@ -145,8 +146,7 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* xp[1] = r * sin(theta); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -158,8 +158,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -write_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr) +void write_field_energy(struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr)) { gkyl_moment_app_calc_field_energy(app, t_curr); @@ -167,8 +166,7 @@ write_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_c } } -void -write_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr) +void write_integrated_mom(struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr)) { gkyl_moment_app_calc_integrated_mom(app, t_curr); @@ -176,8 +174,7 @@ write_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -199,13 +196,14 @@ main(int argc, char **argv) // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .limiter = GKYL_NO_LIMITER, .init = evalFieldInit, .ctx = &ctx, - .bcx = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + .bcx = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -216,7 +214,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NR, NTHETA }; + int cells[] = {NR, NTHETA}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -224,8 +222,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -239,22 +236,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -278,24 +265,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 2.0, 0.0 }, - .upper = { 2.0 + ctx.Lr, ctx.Ltheta }, - .cells = { NR, NTHETA }, + .lower = {2.0, 0.0}, + .upper = {2.0 + ctx.Lr, ctx.Ltheta}, + .cells = {NR, NTHETA}, .mapc2p = mapc2p, .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .periodic_dirs = {1}, .cfl_frac = ctx.cfl_frac, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -309,10 +293,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -321,26 +309,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for field energy. int field_energy_writes = ctx.field_energy_writes; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_writes, .tcurr = t_curr, .curr = frame_curr + }; write_field_energy(&fe_trig, app, t_curr); // Create trigger for integrated moments. int integrated_mom_writes = ctx.integrated_mom_writes; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_writes, .tcurr = t_curr, .curr = frame_curr + }; write_integrated_mom(&im_trig, app, t_curr); @@ -356,7 +349,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -371,8 +364,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -380,11 +372,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -409,14 +402,14 @@ main(int argc, char **argv) freeresources: // Free resources after simulation completion. gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } \ No newline at end of file diff --git a/moments/creg/rt_maxwell_annulus.c b/moments/creg/rt_maxwell_annulus.c index 4969f5c095..62ad4619dc 100644 --- a/moments/creg/rt_maxwell_annulus.c +++ b/moments/creg/rt_maxwell_annulus.c @@ -17,8 +17,7 @@ #include -struct annulus_ctx -{ +struct annulus_ctx { // Mathematical constants (dimensionless). double pi; @@ -46,8 +45,7 @@ struct annulus_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct annulus_ctx -create_ctx(void) +struct annulus_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -91,14 +89,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT fout, void *ctx) { double r = zc[0], theta = zc[1]; struct annulus_ctx *app = ctx; @@ -112,21 +109,24 @@ evalFieldInit(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT fo double Ex = E_over_r * cos(theta); // Total electric field (x-direction). double Ey = E_over_r * sin(theta); // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). - + double Bx = -B_over_r * sin(theta); // Total magnetic field (x-direction). double By = B_over_r * cos(theta); // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } static inline void -mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* ctx) +mapc2p(double t, const double *GKYL_RESTRICT zc, double *GKYL_RESTRICT xp, void *ctx) { double r = zc[0], theta = zc[1]; @@ -135,8 +135,7 @@ mapc2p(double t, const double* GKYL_RESTRICT zc, double* GKYL_RESTRICT xp, void* xp[1] = r * sin(theta); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -150,24 +149,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -189,13 +189,14 @@ main(int argc, char **argv) // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .limiter = GKYL_NO_LIMITER, .init = evalFieldInit, .ctx = &ctx, - .bcx = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + .bcx = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -206,7 +207,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NR, NTHETA }; + int cells[] = {NR, NTHETA}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -214,8 +215,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -229,22 +229,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -268,24 +258,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.25, 0.0 }, - .upper = { 0.25 + ctx.Lr, ctx.Ltheta }, - .cells = { NR, NTHETA }, + .lower = {0.25, 0.0}, + .upper = {0.25 + ctx.Lr, ctx.Ltheta}, + .cells = {NR, NTHETA}, .mapc2p = mapc2p, .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .periodic_dirs = {1}, .cfl_frac = ctx.cfl_frac, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -299,10 +286,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -311,26 +302,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -346,7 +342,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -361,8 +357,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -370,7 +365,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -378,8 +375,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -390,7 +386,7 @@ main(int argc, char **argv) calc_integrated_mom(&im_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); gkyl_moment_app_stat_write(app); - + struct gkyl_moment_stat stat = gkyl_moment_app_stat(app); gkyl_moment_app_cout(app, stdout, "\n"); @@ -404,14 +400,14 @@ main(int argc, char **argv) freeresources: // Free resources after simulation completion. gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } \ No newline at end of file diff --git a/moments/creg/rt_maxwell_axi_wg.c b/moments/creg/rt_maxwell_axi_wg.c index 6ceb578367..8edfc6565e 100644 --- a/moments/creg/rt_maxwell_axi_wg.c +++ b/moments/creg/rt_maxwell_axi_wg.c @@ -8,27 +8,25 @@ #include // map (r,theta) -> (x,y) -void -mapc2p(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double r = xc[0], th = xc[1], z = xc[2]; - xp[0] = r*cos(th); - xp[1] = r*sin(th); + xp[0] = r * cos(th); + xp[1] = r * sin(th); xp[2] = z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double r = xn[0], phi = xn[1], z = xn[2]; - int m = 0, n = 1; - double kn = 2*M_PI*n/10.0; + int m = 0, n = 1; + double kn = 2 * M_PI * n / 10.0; double w = 1.212168982106865; // frequency of mode double a = 1.0, b = -0.351948050727361; - double Ez_r = a*jn(m,r*sqrt(w*w-kn*kn)) + b*yn(m,r*sqrt(w*w-kn*kn)); - double Ez = Ez_r*cos(m*phi)*cos(kn*z); + double Ez_r = a * jn(m, r * sqrt(w * w - kn * kn)) + b * yn(m, r * sqrt(w * w - kn * kn)); + double Ez = Ez_r * cos(m * phi) * cos(kn * z); fout[0] = 0.0; fout[1] = 0.0; @@ -37,17 +35,16 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo fout[4] = 0.0; fout[5] = 0.0; fout[6] = 0.0; - fout[7] = 0.0; + fout[7] = 0.0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); int NX = APP_ARGS_CHOOSE(app_args.xcells[0], 32); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], 3); - int NZ = APP_ARGS_CHOOSE(app_args.xcells[1], 32*3); + int NZ = APP_ARGS_CHOOSE(app_args.xcells[1], 32 * 3); if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); @@ -59,26 +56,26 @@ main(int argc, char **argv) .ndim = 3, // grid in computational space - .lower = { 2.0, -0.05, 0.0 }, - .upper = { 5.0, 0.05, 10.0 }, - .cells = { NX, NY, NZ }, + .lower = {2.0, -0.05, 0.0}, + .upper = {5.0, 0.05, 10.0}, + .cells = {NX, NY, NZ}, .mapc2p = mapc2p, // mapping of computational to physical space .num_periodic_dir = 1, - .periodic_dirs = { 2 }, + .periodic_dirs = {2}, .cfl_frac = 0.9, - .field = { - .epsilon0 = 1.0, .mu0 = 1.0, + .field = + {.epsilon0 = 1.0, + .mu0 = 1.0, - .limiter = GKYL_NO_LIMITER, - .init = evalFieldInit, + .limiter = GKYL_NO_LIMITER, + .init = evalFieldInit, - .bcx = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, - .bcy = { GKYL_FIELD_WEDGE, GKYL_FIELD_WEDGE }, - } + .bcx = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL}, + .bcy = {GKYL_FIELD_WEDGE, GKYL_FIELD_WEDGE}} }; // create app object @@ -87,10 +84,10 @@ main(int argc, char **argv) gkyl_moment_app *app = gkyl_moment_app_new(&app_inp); double w = 1.212168982106865; // frequency of mode - double tperiod = 2*M_PI/w; + double tperiod = 2 * M_PI / w; // start, end and initial time-step - double tcurr = 0.0, tend = 2*tperiod; + double tcurr = 0.0, tend = 2 * tperiod; // initialize simulation gkyl_moment_app_apply_ic(app, tcurr); @@ -104,7 +101,7 @@ main(int argc, char **argv) printf("Taking time-step %ld at t = %g ...", step, tcurr); struct gkyl_update_status status = gkyl_moment_update(app, dt); printf(" dt = %g\n", status.dt_actual); - + if (!status.success) { printf("** Update method failed! Aborting simulation ....\n"); break; @@ -129,6 +126,6 @@ main(int argc, char **argv) printf("Species updates took %g secs\n", stat.species_tm); printf("Field updates took %g secs\n", stat.field_tm); printf("Total updates took %g secs\n", stat.total_tm); - + return 0; } diff --git a/moments/creg/rt_maxwell_expanding.c b/moments/creg/rt_maxwell_expanding.c index 0330102360..33646d1180 100644 --- a/moments/creg/rt_maxwell_expanding.c +++ b/moments/creg/rt_maxwell_expanding.c @@ -17,8 +17,7 @@ #include -struct maxwell_expanding_ctx -{ +struct maxwell_expanding_ctx { // Mathematical constants (dimensionless). double pi; @@ -50,8 +49,7 @@ struct maxwell_expanding_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct maxwell_expanding_ctx -create_ctx(void) +struct maxwell_expanding_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -102,25 +100,25 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set fluid mass density. fout[0] = 1.0; // Set fluid momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = 1.0; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct maxwell_expanding_ctx *app = ctx; @@ -130,7 +128,7 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double E0 = app->E0; double k_wave_x = app->k_wave_x; double k_xn = app->k_xn; - + double Lx = app->Lx; double phi = ((2.0 * pi) / Lx) * (k_wave_x * x); @@ -144,15 +142,17 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = E0 * cos(phi) * k_xn; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -166,24 +166,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -208,22 +209,23 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, .has_volume_sources = true, .volume_gas_gamma = ctx.gas_gamma, .volume_U0 = ctx.U0, - .volume_R0 = ctx.R0, + .volume_R0 = ctx.R0 }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -234,7 +236,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -242,8 +244,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -257,22 +258,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -296,24 +287,20 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -327,10 +314,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -339,26 +330,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -374,7 +370,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -389,8 +385,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -398,7 +393,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -406,8 +403,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -433,14 +429,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_maxwell_expanding_2d.c b/moments/creg/rt_maxwell_expanding_2d.c index 0466a05bb4..4f5cb48a22 100644 --- a/moments/creg/rt_maxwell_expanding_2d.c +++ b/moments/creg/rt_maxwell_expanding_2d.c @@ -17,8 +17,7 @@ #include -struct maxwell_expanding_2d_ctx -{ +struct maxwell_expanding_2d_ctx { // Mathematical constants (dimensionless). double pi; @@ -54,8 +53,7 @@ struct maxwell_expanding_2d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct maxwell_expanding_2d_ctx -create_ctx(void) +struct maxwell_expanding_2d_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -73,7 +71,8 @@ create_ctx(void) double k_wave_y = 2.0; // Wave number (y-direction). // Derived physical quantities (using normalized code units). - double k_norm = sqrt((k_wave_x * k_wave_x) + (k_wave_y * k_wave_y)); // Wave number normalization factor. + double k_norm = + sqrt((k_wave_x * k_wave_x) + (k_wave_y * k_wave_y)); // Wave number normalization factor. double k_xn = k_wave_x / k_norm; // Normalized wave number (x-direction). double k_yn = k_wave_y / k_norm; // Normalized wave number (y-direction). @@ -114,25 +113,25 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set fluid mass density. fout[0] = 1.0; // Set fluid momentum density. - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = 1.0; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct maxwell_expanding_2d_ctx *app = ctx; @@ -144,7 +143,7 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double k_wave_y = app->k_wave_y; double k_xn = app->k_xn; double k_yn = app->k_yn; - + double Lx = app->Lx; double Ly = app->Ly; @@ -156,18 +155,21 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = E0 * cos(phi) * ((2.0 * pi) / Ly) * k_yn; // Total magnetic field (x-direction). double By = -E0 * cos(phi) * ((2.0 * pi) / Lx) * k_xn; // Total magnetic field (y-direction). - double Bz = E0 * cos(phi) * ((2.0 * pi) / Ly) * (-k_xn - k_yn); // Total magnetic field (z-direction). + double Bz = + E0 * cos(phi) * ((2.0 * pi) / Ly) * (-k_xn - k_yn); // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -181,24 +183,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -224,23 +227,24 @@ main(int argc, char **argv) struct gkyl_moment_species fluid = { .name = "euler", .equation = euler, - + .init = evalEulerInit, .ctx = &ctx, .has_volume_sources = true, .volume_gas_gamma = ctx.gas_gamma, .volume_U0 = ctx.U0, - .volume_R0 = ctx.R0, + .volume_R0 = ctx.R0 }; // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .limiter = GKYL_NO_LIMITER, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -251,7 +255,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -259,8 +263,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -274,22 +277,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -313,24 +306,21 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -344,10 +334,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -356,26 +350,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -391,7 +390,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -406,8 +405,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -415,7 +413,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -423,8 +423,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -450,14 +449,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_maxwell_plane_wave_1d.c b/moments/creg/rt_maxwell_plane_wave_1d.c index c0f2b2770b..b29125f580 100644 --- a/moments/creg/rt_maxwell_plane_wave_1d.c +++ b/moments/creg/rt_maxwell_plane_wave_1d.c @@ -17,8 +17,7 @@ #include -struct plane_wave_1d_ctx -{ +struct plane_wave_1d_ctx { // Mathematical constants (dimensionless). double pi; @@ -46,8 +45,7 @@ struct plane_wave_1d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct plane_wave_1d_ctx -create_ctx(void) +struct plane_wave_1d_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -91,14 +89,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct plane_wave_1d_ctx *app = ctx; @@ -108,7 +105,7 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double E0 = app->E0; double k_wave_x = app->k_wave_x; double k_xn = app->k_xn; - + double Lx = app->Lx; double phi = ((2.0 * pi) / Lx) * (k_wave_x * x); @@ -122,15 +119,17 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = E0 * cos(phi) * k_xn; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -144,24 +143,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -182,10 +182,11 @@ main(int argc, char **argv) // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -196,7 +197,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -204,8 +205,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -219,22 +219,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -257,21 +247,17 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -285,10 +271,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -297,26 +287,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -332,7 +327,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -347,8 +342,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -356,7 +350,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -364,8 +360,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -390,14 +385,14 @@ main(int argc, char **argv) freeresources: // Free resources after simulation completion. gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_maxwell_plane_wave_1d_mp.c b/moments/creg/rt_maxwell_plane_wave_1d_mp.c index 17a420a94e..800fc2af5d 100644 --- a/moments/creg/rt_maxwell_plane_wave_1d_mp.c +++ b/moments/creg/rt_maxwell_plane_wave_1d_mp.c @@ -17,8 +17,7 @@ #include -struct plane_wave_1d_mp_ctx -{ +struct plane_wave_1d_mp_ctx { // Mathematical constants (dimensionless). double pi; @@ -46,8 +45,7 @@ struct plane_wave_1d_mp_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct plane_wave_1d_mp_ctx -create_ctx(void) +struct plane_wave_1d_mp_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -91,14 +89,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct plane_wave_1d_mp_ctx *app = ctx; @@ -108,7 +105,7 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double E0 = app->E0; double k_wave_x = app->k_wave_x; double k_xn = app->k_xn; - + double Lx = app->Lx; double phi = ((2.0 * pi) / Lx) * (k_wave_x * x); @@ -122,15 +119,17 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = E0 * cos(phi) * k_xn; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -144,24 +143,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -182,10 +182,11 @@ main(int argc, char **argv) // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -196,7 +197,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -204,8 +205,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -219,22 +219,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -257,24 +247,20 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .scheme_type = GKYL_MOMENT_MP, .mp_recon = app_args.mp_recon, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .cfl_frac = ctx.cfl_frac, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -288,10 +274,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -300,26 +290,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -335,7 +330,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -350,8 +345,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -359,7 +353,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -367,8 +363,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -393,14 +388,14 @@ main(int argc, char **argv) freeresources: // Free resources after simulation completion. gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_maxwell_plane_wave_2d.c b/moments/creg/rt_maxwell_plane_wave_2d.c index 2cbf154145..26a7e95b6d 100644 --- a/moments/creg/rt_maxwell_plane_wave_2d.c +++ b/moments/creg/rt_maxwell_plane_wave_2d.c @@ -17,8 +17,7 @@ #include -struct plane_wave_2d_ctx -{ +struct plane_wave_2d_ctx { // Mathematical constants (dimensionless). double pi; @@ -50,8 +49,7 @@ struct plane_wave_2d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct plane_wave_2d_ctx -create_ctx(void) +struct plane_wave_2d_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -65,7 +63,8 @@ create_ctx(void) double k_wave_y = 2.0; // Wave number (y-direction). // Derived physical quantities (using normalized code units). - double k_norm = sqrt((k_wave_x * k_wave_x) + (k_wave_y * k_wave_y)); // Wave number normalization factor. + double k_norm = + sqrt((k_wave_x * k_wave_x) + (k_wave_y * k_wave_y)); // Wave number normalization factor. double k_xn = k_wave_x / k_norm; // Normalized wave number (x-direction). double k_yn = k_wave_y / k_norm; // Normalized wave number (y-direction). @@ -103,14 +102,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct plane_wave_2d_ctx *app = ctx; @@ -122,7 +120,7 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double k_wave_y = app->k_wave_y; double k_xn = app->k_xn; double k_yn = app->k_yn; - + double Lx = app->Lx; double Ly = app->Ly; @@ -134,18 +132,21 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = E0 * cos(phi) * ((2.0 * pi) / Ly) * k_yn; // Total magnetic field (x-direction). double By = -E0 * cos(phi) * ((2.0 * pi) / Lx) * k_xn; // Total magnetic field (y-direction). - double Bz = E0 * cos(phi) * ((2.0 * pi) / Ly) * (-k_xn - k_yn); // Total magnetic field (z-direction). + double Bz = + E0 * cos(phi) * ((2.0 * pi) / Ly) * (-k_xn - k_yn); // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -159,24 +160,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -198,11 +200,12 @@ main(int argc, char **argv) // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .limiter = GKYL_NO_LIMITER, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -213,7 +216,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -221,8 +224,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -236,22 +238,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -275,21 +267,18 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .cfl_frac = ctx.cfl_frac, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -303,10 +292,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -315,26 +308,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -350,7 +348,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -365,8 +363,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -374,7 +371,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -382,8 +381,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -408,14 +406,14 @@ main(int argc, char **argv) freeresources: // Free resources after simulation completion. gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_maxwell_plane_wave_2d_mp.c b/moments/creg/rt_maxwell_plane_wave_2d_mp.c index b4de3bdd66..8da5adfca4 100644 --- a/moments/creg/rt_maxwell_plane_wave_2d_mp.c +++ b/moments/creg/rt_maxwell_plane_wave_2d_mp.c @@ -17,8 +17,7 @@ #include -struct plane_wave_2d_mp_ctx -{ +struct plane_wave_2d_mp_ctx { // Mathematical constants (dimensionless). double pi; @@ -50,8 +49,7 @@ struct plane_wave_2d_mp_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct plane_wave_2d_mp_ctx -create_ctx(void) +struct plane_wave_2d_mp_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -65,7 +63,8 @@ create_ctx(void) double k_wave_y = 2.0; // Wave number (y-direction). // Derived physical quantities (using normalized code units). - double k_norm = sqrt((k_wave_x * k_wave_x) + (k_wave_y * k_wave_y)); // Wave number normalization factor. + double k_norm = + sqrt((k_wave_x * k_wave_x) + (k_wave_y * k_wave_y)); // Wave number normalization factor. double k_xn = k_wave_x / k_norm; // Normalized wave number (x-direction). double k_yn = k_wave_y / k_norm; // Normalized wave number (y-direction). @@ -103,14 +102,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct plane_wave_2d_mp_ctx *app = ctx; @@ -122,7 +120,7 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double k_wave_y = app->k_wave_y; double k_xn = app->k_xn; double k_yn = app->k_yn; - + double Lx = app->Lx; double Ly = app->Ly; @@ -134,18 +132,21 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = E0 * cos(phi) * ((2.0 * pi) / Ly) * k_yn; // Total magnetic field (x-direction). double By = -E0 * cos(phi) * ((2.0 * pi) / Lx) * k_xn; // Total magnetic field (y-direction). - double Bz = E0 * cos(phi) * ((2.0 * pi) / Ly) * (-k_xn - k_yn); // Total magnetic field (z-direction). + double Bz = + E0 * cos(phi) * ((2.0 * pi) / Ly) * (-k_xn - k_yn); // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -159,24 +160,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -198,11 +200,12 @@ main(int argc, char **argv) // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .limiter = GKYL_NO_LIMITER, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -213,7 +216,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -221,8 +224,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -236,22 +238,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -275,25 +267,22 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_MP, .mp_recon = app_args.mp_recon, .skip_mp_limiter = app_args.skip_limiters, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .cfl_frac = ctx.cfl_frac, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -307,10 +296,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -319,26 +312,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -354,7 +352,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -369,8 +367,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -378,7 +375,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -386,8 +385,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -412,14 +410,14 @@ main(int argc, char **argv) freeresources: // Free resources after simulation completion. gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_maxwell_reflect_2d.c b/moments/creg/rt_maxwell_reflect_2d.c index 17ebe2abbb..c81dd50205 100644 --- a/moments/creg/rt_maxwell_reflect_2d.c +++ b/moments/creg/rt_maxwell_reflect_2d.c @@ -17,8 +17,7 @@ #include -struct reflect_2d_ctx -{ +struct reflect_2d_ctx { // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -38,8 +37,7 @@ struct reflect_2d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct reflect_2d_ctx -create_ctx(void) +struct reflect_2d_ctx create_ctx(void) { // Physical constants (using normalized code units). double epsilon0 = 1.0; // Permittivity of free space. @@ -72,14 +70,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct reflect_2d_ctx *app = ctx; @@ -89,21 +86,23 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). double Ez = exp(-25.0 * r_sq); // Total electric field (z-direction). - + double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -117,24 +116,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -156,14 +156,15 @@ main(int argc, char **argv) // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .limiter = GKYL_NO_LIMITER, .init = evalFieldInit, .ctx = &ctx, - .bcx = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, - .bcy = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + .bcx = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL}, + .bcy = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -174,7 +175,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -182,8 +183,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -197,22 +197,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -236,19 +226,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .cfl_frac = ctx.cfl_frac, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -262,10 +249,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -274,26 +265,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -309,7 +305,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -324,8 +320,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -333,7 +328,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -341,8 +338,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -367,14 +363,14 @@ main(int argc, char **argv) freeresources: // Free resources after simulation completion. gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } \ No newline at end of file diff --git a/moments/creg/rt_maxwell_wg_2d.c b/moments/creg/rt_maxwell_wg_2d.c index 7f767634a1..d42ad034e9 100644 --- a/moments/creg/rt_maxwell_wg_2d.c +++ b/moments/creg/rt_maxwell_wg_2d.c @@ -17,8 +17,7 @@ #include -struct wg_2d_ctx -{ +struct wg_2d_ctx { // Mathematical constants (dimensionless). double pi; @@ -45,8 +44,7 @@ struct wg_2d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct wg_2d_ctx -create_ctx(void) +struct wg_2d_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -89,14 +87,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct wg_2d_ctx *app = ctx; @@ -112,15 +109,17 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = cos(pi * x) * cos(pi * y); // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -134,24 +133,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -173,14 +173,15 @@ main(int argc, char **argv) // Field. struct gkyl_moment_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .limiter = GKYL_NO_LIMITER, .init = evalFieldInit, .ctx = &ctx, - .bcx = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, - .bcy = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + .bcx = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL}, + .bcy = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processes in simulation. @@ -191,7 +192,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -199,8 +200,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -214,22 +214,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -253,21 +243,18 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .cfl_frac = ctx.cfl_frac, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -281,10 +268,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -293,26 +284,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -328,7 +324,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -343,8 +339,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -352,7 +347,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -360,8 +357,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -386,14 +382,14 @@ main(int argc, char **argv) freeresources: // Free resources after simulation completion. gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_mhd_brio_wu.c b/moments/creg/rt_mhd_brio_wu.c index c248d83597..a9213d1a64 100644 --- a/moments/creg/rt_mhd_brio_wu.c +++ b/moments/creg/rt_mhd_brio_wu.c @@ -17,8 +17,7 @@ #include -struct brio_wu_ctx -{ +struct brio_wu_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -47,8 +46,7 @@ struct brio_wu_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct brio_wu_ctx -create_ctx(void) +struct brio_wu_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 2.0; // Adiabatic index. @@ -97,14 +95,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMHDInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct brio_wu_ctx *app = ctx; @@ -138,8 +135,7 @@ evalMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout Bx = Bx_l; // Magnetic field (x-direction, left). By = By_l; // Magnetic field (y-direction, left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -151,22 +147,26 @@ evalMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = 0.0; // Fluid momentum density (y-direction). double mom_z = 0.0; // Fluid momentum density (z-direction). - double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * u * u) + (0.5 * ((Bx * Bx) + (By * By) + (Bz * Bz))); // Fluid total energy density. + double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * u * u) + + (0.5 * ((Bx * Bx) + (By * By) + (Bz * Bz))); // Fluid total energy density. // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set magnetic field. - fout[5] = Bx; fout[6] = By; fout[7] = Bz; + fout[5] = Bx; + fout[6] = By; + fout[7] = Bz; // Set correction potential. fout[8] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -180,24 +180,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -217,20 +218,17 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *mhd = gkyl_wv_mhd_new( &(struct gkyl_wv_mhd_inp) { - .gas_gamma = ctx.gas_gamma, - .divergence_constraint = GKYL_MHD_DIVB_NONE, - } - ); + struct gkyl_wv_eqn *mhd = gkyl_wv_mhd_new(&(struct gkyl_wv_mhd_inp + ){.gas_gamma = ctx.gas_gamma, .divergence_constraint = GKYL_MHD_DIVB_NONE}); struct gkyl_moment_species fluid = { .name = "mhd", .equation = mhd, - + .init = evalMHDInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -240,7 +238,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -248,8 +246,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -263,22 +260,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -302,20 +289,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -329,10 +312,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -341,26 +328,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -376,7 +368,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -391,8 +383,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -400,7 +391,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -408,8 +401,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -435,14 +427,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(mhd); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_mhd_ot.c b/moments/creg/rt_mhd_ot.c index aa9dd5e643..aac854226f 100644 --- a/moments/creg/rt_mhd_ot.c +++ b/moments/creg/rt_mhd_ot.c @@ -17,8 +17,7 @@ #include -struct ot_ctx -{ +struct ot_ctx { // Mathematical constants (dimensionless). double pi; @@ -44,8 +43,7 @@ struct ot_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct ot_ctx -create_ctx(void) +struct ot_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -87,14 +85,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMHDInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct ot_ctx *app = ctx; @@ -109,7 +106,7 @@ evalMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double u = sin(2.0 * pi * y); // Fluid velocity (x-direction). double v = -sin(2.0 * pi * x); // Fluid velocity (y-direction). double w = 0.0; // Fluid velocity (z-direction). - + double Bx = B0 * sin(2.0 * pi * y); // Magnetic field (x-direction). double By = B0 * sin(4.0 * pi * x); // Magnetic field (y-direction). double Bz = 0.0; // Magnetic field (z-direction). @@ -117,20 +114,24 @@ evalMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = rho * v; // Fluid momentum density (y-direction). double mom_z = rho * w; // Fluid momentum density (z-direction). - double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * ((u * u) + (v * v) + (w * w))) + (0.5 * ((Bx * Bx) + (By * By) + (Bz * Bz))); // Fluid total energy density. + double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * ((u * u) + (v * v) + (w * w))) + + (0.5 * ((Bx * Bx) + (By * By) + (Bz * Bz))); // Fluid total energy density. // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set magnetic field. - fout[5] = Bx; fout[6] = By; fout[7] = Bz; + fout[5] = Bx; + fout[6] = By; + fout[7] = Bz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -144,24 +145,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -182,18 +184,15 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Fluid equations. - struct gkyl_wv_eqn *mhd = gkyl_wv_mhd_new( &(struct gkyl_wv_mhd_inp) { - .gas_gamma = ctx.gas_gamma, - .divergence_constraint = GKYL_MHD_DIVB_EIGHT_WAVES, - } - ); + struct gkyl_wv_eqn *mhd = gkyl_wv_mhd_new(&(struct gkyl_wv_mhd_inp + ){.gas_gamma = ctx.gas_gamma, .divergence_constraint = GKYL_MHD_DIVB_EIGHT_WAVES}); struct gkyl_moment_species fluid = { .name = "mhd", .equation = mhd, - + .init = evalMHDInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processes in simulation. @@ -203,7 +202,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -211,8 +210,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -226,22 +224,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -265,22 +253,19 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -294,10 +279,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -306,26 +295,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -341,7 +335,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -356,8 +350,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -365,7 +358,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -373,8 +368,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -400,14 +394,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(mhd); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_mhd_rj2.c b/moments/creg/rt_mhd_rj2.c index 751d96f8de..b26a29dadb 100644 --- a/moments/creg/rt_mhd_rj2.c +++ b/moments/creg/rt_mhd_rj2.c @@ -17,8 +17,7 @@ #include -struct rj2_ctx -{ +struct rj2_ctx { // Mathematical constants (dimensionless). double pi; @@ -58,8 +57,7 @@ struct rj2_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct rj2_ctx -create_ctx(void) +struct rj2_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -126,14 +124,13 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMHDInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct rj2_ctx *app = ctx; @@ -180,8 +177,7 @@ evalMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout Bx = Bx_l; // Magnetic field (x-direction, left). By = By_l; // Magnetic field (y-direction, left). Bz = Bz_l; // Magnetic field (z-direction, left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (x-direction, right). v = vr; // Fluid velocity (y-direction, right). @@ -196,22 +192,26 @@ evalMHDInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double mom_x = rho * u; // Fluid momentum density (x-direction). double mom_y = rho * v; // Fluid momentum density (y-direction). double mom_z = rho * w; // Fluid momentum density (z-direction). - double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * ((u * u) + (v * v) + (w * w))) + (0.5 * ((Bx * Bx) + (By * By) + (Bz * Bz))); // Fluid total energy density. + double Etot = (p / (gas_gamma - 1.0)) + (0.5 * rho * ((u * u) + (v * v) + (w * w))) + + (0.5 * ((Bx * Bx) + (By * By) + (Bz * Bz))); // Fluid total energy density. // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set magnetic field. - fout[5] = Bx; fout[6] = By; fout[7] = Bz; + fout[5] = Bx; + fout[6] = By; + fout[7] = Bz; // Set correction potential. fout[8] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -225,24 +225,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -262,20 +263,17 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *mhd = gkyl_wv_mhd_new( &(struct gkyl_wv_mhd_inp) { - .gas_gamma = ctx.gas_gamma, - .divergence_constraint = GKYL_MHD_DIVB_NONE, - } - ); + struct gkyl_wv_eqn *mhd = gkyl_wv_mhd_new(&(struct gkyl_wv_mhd_inp + ){.gas_gamma = ctx.gas_gamma, .divergence_constraint = GKYL_MHD_DIVB_NONE}); struct gkyl_moment_species fluid = { .name = "mhd", .equation = mhd, - + .init = evalMHDInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -285,7 +283,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -293,8 +291,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -308,22 +305,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -347,20 +334,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -374,10 +357,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -386,26 +373,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -421,7 +413,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -436,8 +428,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -445,7 +436,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -453,8 +446,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -480,14 +472,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(mhd); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_multib_euler_2d.c b/moments/creg/rt_multib_euler_2d.c index 2f5322c9d0..5397deac4b 100644 --- a/moments/creg/rt_multib_euler_2d.c +++ b/moments/creg/rt_multib_euler_2d.c @@ -13,8 +13,7 @@ // Gas constant static const double gas_gamma = 1.4; -struct gkyl_block_geom* -create_block_geom(void) +struct gkyl_block_geom *create_block_geom(void) { struct gkyl_block_geom *bgeom = gkyl_block_geom_new(2, 3); @@ -32,68 +31,80 @@ create_block_geom(void) 0 +------+-----+ 0 -----1-----2 -> X - */ + */ // block 0 - gkyl_block_geom_set_block(bgeom, 0, &(struct gkyl_block_geom_info) { - .lower = { 0, 1 }, - .upper = { 1, 2 }, - .cells = { 128, 128 }, - .cuts = { 1, 1 }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } // physical boundary - } - } + gkyl_block_geom_set_block( + bgeom, 0, + &(struct gkyl_block_geom_info + ){.lower = {0, 1}, + .upper = {1, 2}, + .cells = {128, 128}, + .cuts = {1, 1}, + + .connections[0] = + { + // x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + { + // y-direction connections + {.bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); - + // block 1 - gkyl_block_geom_set_block(bgeom, 1, &(struct gkyl_block_geom_info) { - .lower = { 0, 0 }, - .upper = { 1, 1 }, - .cells = { 128, 128 }, - .cuts = { 1, 1 }, - - .connections[0] = { // x-direction connections - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE } - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE } - } - } + gkyl_block_geom_set_block( + bgeom, 1, + &(struct gkyl_block_geom_info + ){.lower = {0, 0}, + .upper = {1, 1}, + .cells = {128, 128}, + .cuts = {1, 1}, + + .connections[0] = + {// x-direction connections + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE} + }, + .connections[1] = + {// y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE} + }} ); // block 2 - gkyl_block_geom_set_block(bgeom, 2, &(struct gkyl_block_geom_info) { - .lower = { 1, 0 }, - .upper = { 2, 1 }, - .cells = { 128, 128 }, - .cuts = { 1, 1 }, - - .connections[0] = { // x-direction connections - { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, - { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } // physical boundary - }, - .connections[1] = { // y-direction connections - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, // physical boundary - { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } // physical boundary - } - } + gkyl_block_geom_set_block( + bgeom, 2, + &(struct gkyl_block_geom_info + ){.lower = {1, 0}, + .upper = {2, 1}, + .cells = {128, 128}, + .cuts = {1, 1}, + + .connections[0] = + { + // x-direction connections + {.bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE}, + {.bid = 0, .dir = 0, .edge = GKYL_PHYSICAL} // physical boundary + }, + .connections[1] = + { + // y-direction connections + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL}, // physical boundary + {.bid = 0, .dir = 1, .edge = GKYL_PHYSICAL} // physical boundary + }} ); return bgeom; } static void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_multib_app* app, - double t_curr, bool force_write) +write_data(struct gkyl_tm_trigger *iot, gkyl_moment_multib_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -104,25 +115,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_multib_app* app, } } -void -initFluidSod(double t, const double *xn, double* restrict fout, void *ctx) +void initFluidSod(double t, const double *xn, double *restrict fout, void *ctx) { double xsloc = 1.25, ysloc = 1.5; double x = xn[0], y = xn[1]; double rho = 0.125, pr = 0.1; - if (y>ysloc || x>xsloc) { + if (y > ysloc || x > xsloc) { rho = 1.0; pr = 1.0; } - + fout[0] = rho; - fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; - fout[4] = pr/(gas_gamma-1); + fout[1] = 0.0; + fout[2] = 0.0; + fout[3] = 0.0; + fout[4] = pr / (gas_gamma - 1); } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -130,48 +141,42 @@ main(int argc, char **argv) if (app_args.use_mpi) { #ifdef GKYL_HAVE_MPI MPI_Init(&argc, &argv); - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - .sync_corners = true - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp + ){.mpi_comm = MPI_COMM_WORLD, .sync_corners = true}); #endif } - if (comm == 0) - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { } ); + if (comm == 0) { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){}); + } if (app_args.trace_mem) { gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } - + // construct block geometry struct gkyl_block_geom *bgeom = create_block_geom(); int nblocks = gkyl_block_geom_num_blocks(bgeom); - struct gkyl_wv_eqn *euler_eqn = gkyl_wv_euler_inew( &(struct gkyl_wv_euler_inp) { - .gas_gamma = gas_gamma - } - ); + struct gkyl_wv_eqn *euler_eqn = + gkyl_wv_euler_inew(&(struct gkyl_wv_euler_inp){.gas_gamma = gas_gamma}); // all data is common across blocks struct gkyl_moment_multib_species_pb euler_blocks[1]; - euler_blocks[0] = (struct gkyl_moment_multib_species_pb) { - .init = initFluidSod, - }; + euler_blocks[0] = (struct gkyl_moment_multib_species_pb){.init = initFluidSod}; struct gkyl_block_physical_bcs euler_phys_bcs[] = { // block 0 BCs - { .bidx = 0, .dir = 0, .edge = GKYL_LOWER_EDGE, .bc_type = GKYL_SPECIES_REFLECT }, - { .bidx = 0, .dir = 0, .edge = GKYL_UPPER_EDGE, .bc_type = GKYL_SPECIES_REFLECT }, - { .bidx = 0, .dir = 1, .edge = GKYL_UPPER_EDGE, .bc_type = GKYL_SPECIES_COPY }, + {.bidx = 0, .dir = 0, .edge = GKYL_LOWER_EDGE, .bc_type = GKYL_SPECIES_REFLECT}, + {.bidx = 0, .dir = 0, .edge = GKYL_UPPER_EDGE, .bc_type = GKYL_SPECIES_REFLECT}, + {.bidx = 0, .dir = 1, .edge = GKYL_UPPER_EDGE, .bc_type = GKYL_SPECIES_COPY}, // block 1 BCs - { .bidx = 1, .dir = 0, .edge = GKYL_LOWER_EDGE, .bc_type = GKYL_SPECIES_REFLECT }, - { .bidx = 1, .dir = 1, .edge = GKYL_LOWER_EDGE, .bc_type = GKYL_SPECIES_REFLECT }, + {.bidx = 1, .dir = 0, .edge = GKYL_LOWER_EDGE, .bc_type = GKYL_SPECIES_REFLECT}, + {.bidx = 1, .dir = 1, .edge = GKYL_LOWER_EDGE, .bc_type = GKYL_SPECIES_REFLECT}, // block 2 BCs - { .bidx = 2, .dir = 0, .edge = GKYL_UPPER_EDGE, .bc_type = GKYL_SPECIES_COPY }, - { .bidx = 2, .dir = 1, .edge = GKYL_LOWER_EDGE, .bc_type = GKYL_SPECIES_REFLECT }, - { .bidx = 2, .dir = 1, .edge = GKYL_UPPER_EDGE, .bc_type = GKYL_SPECIES_REFLECT }, + {.bidx = 2, .dir = 0, .edge = GKYL_UPPER_EDGE, .bc_type = GKYL_SPECIES_COPY}, + {.bidx = 2, .dir = 1, .edge = GKYL_LOWER_EDGE, .bc_type = GKYL_SPECIES_REFLECT}, + {.bidx = 2, .dir = 1, .edge = GKYL_UPPER_EDGE, .bc_type = GKYL_SPECIES_REFLECT} }; struct gkyl_moment_multib_species euler = { @@ -184,7 +189,7 @@ main(int argc, char **argv) .blocks = euler_blocks, .num_physical_bcs = 8, - .bcs = euler_phys_bcs, + .bcs = euler_phys_bcs }; struct gkyl_moment_multib app_inp = { @@ -193,7 +198,7 @@ main(int argc, char **argv) .cfl_frac = 0.9, .num_species = 1, - .species = { euler }, + .species = {euler}, .comm = comm }; @@ -205,7 +210,7 @@ main(int argc, char **argv) fprintf(stderr, "Unable to construct multiblock App! (Probably too few or too many ranks)\n"); goto finish; } - + gkyl_moment_multib_app_write_topo(app); // Initial and final simulation times. @@ -213,7 +218,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = 4; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_moment_multib_app_apply_ic(app, t_curr); @@ -224,12 +229,13 @@ main(int argc, char **argv) gkyl_wv_eqn_release(euler_eqn); gkyl_moment_multib_app_release(app); - finish: +finish: #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); + } #endif - + return 0; } diff --git a/moments/creg/rt_reactive_euler_detonation.c b/moments/creg/rt_reactive_euler_detonation.c index c7901adcc1..c6db986e7a 100644 --- a/moments/creg/rt_reactive_euler_detonation.c +++ b/moments/creg/rt_reactive_euler_detonation.c @@ -17,8 +17,7 @@ #include -struct reactive_detonation_ctx -{ +struct reactive_detonation_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. double specific_heat_capacity; // Specific heat capacity. @@ -47,8 +46,7 @@ struct reactive_detonation_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct reactive_detonation_ctx -create_ctx(void) +struct reactive_detonation_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -97,14 +95,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalReactiveEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalReactiveEulerInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct reactive_detonation_ctx *app = ctx; @@ -128,8 +127,7 @@ evalReactiveEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -144,15 +142,16 @@ evalReactiveEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; // Set fluid reaction progress. fout[5] = reac; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -166,24 +165,21 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr) +void calc_field_energy(struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr)) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr) +void calc_integrated_mom(struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr)) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -203,13 +199,15 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Fluid equations. - struct gkyl_wv_eqn *reactive_euler = gkyl_wv_reactive_euler_new(ctx.gas_gamma, ctx.specific_heat_capacity, ctx.energy_of_formation, - ctx.ignition_temperature, ctx.reaction_rate, app_args.use_gpu); + struct gkyl_wv_eqn *reactive_euler = gkyl_wv_reactive_euler_new( + ctx.gas_gamma, ctx.specific_heat_capacity, ctx.energy_of_formation, ctx.ignition_temperature, + ctx.reaction_rate, app_args.use_gpu + ); struct gkyl_moment_species fluid = { .name = "reactive_euler", .equation = reactive_euler, - + .init = evalReactiveEulerInit, .ctx = &ctx, @@ -220,7 +218,7 @@ main(int argc, char **argv) .reactivity_ignition_temperature = ctx.ignition_temperature, .reactivity_reaction_rate = ctx.reaction_rate, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -231,7 +229,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -239,8 +237,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -254,22 +251,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -293,20 +280,16 @@ main(int argc, char **argv) struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { fluid }, + .species = {fluid}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -320,10 +303,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -332,26 +319,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -367,7 +359,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -382,8 +374,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -391,11 +382,12 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -421,14 +413,14 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_wv_eqn_release(reactive_euler); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_sr_euler_KH_2d.c b/moments/creg/rt_sr_euler_KH_2d.c index c560371dcf..20428a420d 100644 --- a/moments/creg/rt_sr_euler_KH_2d.c +++ b/moments/creg/rt_sr_euler_KH_2d.c @@ -11,51 +11,48 @@ struct sr_euler_ctx { double gas_gamma; // gas constant }; -void -evalSREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalSREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sr_euler_ctx *app = ctx; double gas_gamma = app->gas_gamma; - + double x = xn[0], y = xn[1]; //ICs from KH test from sec 4.3.2 Stone Athena++ 2020 - + double rho, rhou = 1.5, rhol = 0.5, p = 20.; double pi = 3.141592653589793238462643383279502884; - - double u = 0.25*tanh(100*y); - double v = sin(2*pi*x)*exp(-100*y*y)/400; - + + double u = 0.25 * tanh(100 * y); + double v = sin(2 * pi * x) * exp(-100 * y * y) / 400; + rho = rhol; if (y > 0.) { rho = rhou; } - - double gamma = 1 / sqrt(1 - u*u - v*v); - double rhoh = gas_gamma * p / (gas_gamma - 1) + rho; - - fout[0] = gamma*rho; - fout[1] = gamma*gamma*rhoh - p; - fout[2] = gamma*gamma*rhoh*u; - fout[3] = gamma*gamma*rhoh*v; + + double gamma = 1 / sqrt(1 - u * u - v * v); + double rhoh = gas_gamma * p / (gas_gamma - 1) + rho; + + fout[0] = gamma * rho; + fout[1] = gamma * gamma * rhoh - p; + fout[2] = gamma * gamma * rhoh * u; + fout[3] = gamma * gamma * rhoh * v; fout[4] = 0.; } -struct sr_euler_ctx -sr_euler_ctx(void) +struct sr_euler_ctx sr_euler_ctx(void) { - return (struct sr_euler_ctx) { .gas_gamma = 4./3. }; + return (struct sr_euler_ctx){.gas_gamma = 4. / 3.}; } -void -write_data(struct gkyl_tm_trigger *iot, const gkyl_moment_app *app, double tcurr) +void write_data(struct gkyl_tm_trigger *iot, const gkyl_moment_app *app, double tcurr) { - if (gkyl_tm_trigger_check_and_bump(iot, tcurr)) - gkyl_moment_app_write(app, tcurr, iot->curr-1); + if (gkyl_tm_trigger_check_and_bump(iot, tcurr)) { + gkyl_moment_app_write(app, tcurr, iot->curr - 1); + } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -77,23 +74,23 @@ main(int argc, char **argv) .equation = sr_euler, .ctx = &ctx, - .init = evalSREulerInit, + .init = evalSREulerInit }; // VM app struct gkyl_moment app_inp = { .ndim = 2, - .lower = { 0.0, -0.25 }, - .upper = { 1.0, 0.25 }, - .cells = { NX, NY }, + .lower = {0.0, -0.25}, + .upper = {1.0, 0.25}, + .cells = {NX, NY}, .cfl_frac = 0.9, .num_species = 1, - .species = { fluid }, + .species = {fluid}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0} }; // create app object @@ -104,10 +101,10 @@ main(int argc, char **argv) // start, end and initial time-step double tcurr = 0.0, tend = 5.; int nframe = 1; - + // create trigger for IO - struct gkyl_tm_trigger io_trig = { .dt = tend/nframe }; - + struct gkyl_tm_trigger io_trig = {.dt = tend / nframe}; + // initialize simulation gkyl_moment_app_apply_ic(app, tcurr); write_data(&io_trig, app, tcurr); @@ -121,7 +118,7 @@ main(int argc, char **argv) printf("Taking time-step %ld at t = %g ...", step, tcurr); struct gkyl_update_status status = gkyl_moment_update(app, dt); printf(" dt = %g\n", status.dt_actual); - + if (!status.success) { printf("** Update method failed! Aborting simulation ....\n"); break; @@ -130,7 +127,7 @@ main(int argc, char **argv) dt = status.dt_suggested; write_data(&io_trig, app, tcurr); - + step += 1; } @@ -149,6 +146,6 @@ main(int argc, char **argv) printf("Species updates took %g secs\n", stat.species_tm); printf("Field updates took %g secs\n", stat.field_tm); printf("Total updates took %g secs\n", stat.total_tm); - + return 0; } diff --git a/moments/creg/rt_sr_euler_riem_2d.c b/moments/creg/rt_sr_euler_riem_2d.c index b07d55e608..d062e636e6 100644 --- a/moments/creg/rt_sr_euler_riem_2d.c +++ b/moments/creg/rt_sr_euler_riem_2d.c @@ -13,21 +13,20 @@ struct sr_euler_ctx { double gas_gamma; // gas constant }; -void -evalSREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalSREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sr_euler_ctx *app = ctx; double gas_gamma = app->gas_gamma; - + double x = xn[0], y = xn[1]; // ICs from 2D Riemann test from 34.1.11 // http://flash.uchicago.edu/site/flashcode/user_support/flash_ug_devel/node184.html double rho, u, v, p; - + double sloc = 0.; - + double rho1 = 5.477875e-3, p1 = 2.762987e-3; - + double upLeft[] = {0., 1., 0.1, 0.99, 0.0}; double upRight[] = {0., p1, rho1, 0., 0.0}; double loLeft[] = {0., 1., 0.5, 0., 0.}; @@ -41,62 +40,56 @@ evalSREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double loLeft[] = {0., pl, rhol, 0., 0.}; double loRight[] = {0., pr, rhor, 0., 0.}; */ - - if (y>sloc) { - if (x sloc) { + if (x < sloc) { p = upLeft[1]; rho = upLeft[2]; u = upLeft[3]; v = upLeft[4]; - } - else { + } else { p = upRight[1]; rho = upRight[2]; u = upRight[3]; v = upRight[4]; } - } - else { - if (xcurr-1); + if (gkyl_tm_trigger_check_and_bump(iot, tcurr)) { + gkyl_moment_app_write(app, tcurr, iot->curr - 1); + } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -120,23 +113,23 @@ main(int argc, char **argv) .ctx = &ctx, .init = evalSREulerInit, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .limiter = GKYL_MIN_MOD, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .limiter = GKYL_MIN_MOD }; // VM app struct gkyl_moment app_inp = { .ndim = 2, - .lower = { -1., -1. }, - .upper = { 1.0, 1. }, - .cells = { NX, NY }, + .lower = {-1., -1.}, + .upper = {1.0, 1.}, + .cells = {NX, NY}, .cfl_frac = 0.9, .num_species = 1, - .species = { fluid }, + .species = {fluid} }; // create app object @@ -147,10 +140,10 @@ main(int argc, char **argv) // start, end and initial time-step double tcurr = 0.0, tend = 0.8; int nframe = 10; - + // create trigger for IO - struct gkyl_tm_trigger io_trig = { .dt = tend/nframe }; - + struct gkyl_tm_trigger io_trig = {.dt = tend / nframe}; + // initialize simulation gkyl_moment_app_apply_ic(app, tcurr); write_data(&io_trig, app, tcurr); @@ -164,7 +157,7 @@ main(int argc, char **argv) printf("Taking time-step %ld at t = %g ...", step, tcurr); struct gkyl_update_status status = gkyl_moment_update(app, dt); printf(" dt = %g\n", status.dt_actual); - + if (!status.success) { printf("** Update method failed! Aborting simulation ....\n"); break; @@ -173,7 +166,7 @@ main(int argc, char **argv) dt = status.dt_suggested; write_data(&io_trig, app, tcurr); - + step += 1; } @@ -192,6 +185,6 @@ main(int argc, char **argv) printf("Species updates took %g secs\n", stat.species_tm); printf("Field updates took %g secs\n", stat.field_tm); printf("Total updates took %g secs\n", stat.total_tm); - + return 0; } diff --git a/moments/creg/rt_sr_euler_sodshock.c b/moments/creg/rt_sr_euler_sodshock.c index a0ea99a7ee..85ca5bbf7a 100644 --- a/moments/creg/rt_sr_euler_sodshock.c +++ b/moments/creg/rt_sr_euler_sodshock.c @@ -11,43 +11,40 @@ struct sr_euler_ctx { double gas_gamma; // gas constant }; -void -evalSREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalSREulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sr_euler_ctx *app = ctx; double gas_gamma = app->gas_gamma; double x = xn[0]; //ICs from test 4, shock tube, in Eulderink 1995 - - double rhol = 10.0, ul = 0.0, pl = 40./3.; - double rhor = 1.0, ur = 0.0, pr = 2./(3.e7); + + double rhol = 10.0, ul = 0.0, pl = 40. / 3.; + double rhor = 1.0, ur = 0.0, pr = 2. / (3.e7); double rho = rhor, u = ur, p = pr; - if (x<45.) { + if (x < 45.) { rho = rhol; u = ul; p = pl; } - double gamma = 1 / sqrt(1 - u*u); - double rhoh = gas_gamma * p / (gas_gamma - 1) + rho; - - fout[0] = gamma*rho; - fout[1] = gamma*gamma*rhoh - p; - fout[2] = gamma*gamma*rhoh*u; + double gamma = 1 / sqrt(1 - u * u); + double rhoh = gas_gamma * p / (gas_gamma - 1) + rho; + + fout[0] = gamma * rho; + fout[1] = gamma * gamma * rhoh - p; + fout[2] = gamma * gamma * rhoh * u; fout[3] = 0.; fout[4] = 0.; } -struct sr_euler_ctx -sr_euler_ctx(void) +struct sr_euler_ctx sr_euler_ctx(void) { - return (struct sr_euler_ctx) { .gas_gamma = 5./3. }; + return (struct sr_euler_ctx){.gas_gamma = 5. / 3.}; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -70,21 +67,21 @@ main(int argc, char **argv) .ctx = &ctx, .init = evalSREulerInit, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; // VM app struct gkyl_moment app_inp = { .ndim = 1, - .lower = { 0.0 }, - .upper = { 100.0 }, - .cells = { NX }, + .lower = {0.0}, + .upper = {100.0}, + .cells = {NX}, .cfl_frac = 0.9, .num_species = 1, - .species = { fluid }, + .species = {fluid} }; // create app object @@ -107,7 +104,7 @@ main(int argc, char **argv) printf("Taking time-step %ld at t = %g ...", step, tcurr); struct gkyl_update_status status = gkyl_moment_update(app, dt); printf(" dt = %g\n", status.dt_actual); - + if (!status.success) { printf("** Update method failed! Aborting simulation ....\n"); break; @@ -133,6 +130,6 @@ main(int argc, char **argv) printf("Species updates took %g secs\n", stat.species_tm); printf("Field updates took %g secs\n", stat.field_tm); printf("Total updates took %g secs\n", stat.total_tm); - + return 0; } diff --git a/moments/creg/rt_vacuum_einstein_brill_lindquist.c b/moments/creg/rt_vacuum_einstein_brill_lindquist.c index 419f21440a..7d52822966 100644 --- a/moments/creg/rt_vacuum_einstein_brill_lindquist.c +++ b/moments/creg/rt_vacuum_einstein_brill_lindquist.c @@ -19,8 +19,7 @@ #include -struct einstein_brill_lindquist_ctx -{ +struct einstein_brill_lindquist_ctx { // Spacetime parameters (using geometric units). double mass1; // Mass of the first black hole. double mass2; // Mass of the second black hole. @@ -56,8 +55,7 @@ struct einstein_brill_lindquist_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct einstein_brill_lindquist_ctx -create_ctx(void) +struct einstein_brill_lindquist_ctx create_ctx(void) { // Spacetime parameters (using geometric units). double mass1 = 0.5; // Mass of the first black hole. @@ -72,12 +70,16 @@ create_ctx(void) double pos_z2 = 0.0; // Position of the second black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_new(false, mass1, mass2, pos_x1, pos_y1, pos_z1, pos_x2, pos_y2, pos_z2); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_new( + false, mass1, mass2, pos_x1, pos_y1, pos_z1, pos_x2, pos_y2, pos_z2 + ); // Evolution parameters. double excision_threshold = 0.3; // Excision threshold (lapse). - enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. - enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. + enum gkyl_spacetime_slicing spacetime_slicing = + GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. + enum gkyl_spacetime_evolution spacetime_evolution = + GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -116,14 +118,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVacuumEinsteinInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct einstein_brill_lindquist_ctx *app = ctx; @@ -134,30 +137,30 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -168,14 +171,24 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -196,14 +209,15 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1[k][i][j] += inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; + spatial_metric_der_raised1[k][i][j] += + inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; } } } } - + double spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -211,7 +225,8 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3[i][j][k] += inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; + spatial_metric_der_raised3[i][j][k] += + inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; } } } @@ -223,49 +238,91 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE for (int s = 0; s < 3; s++) { aux_vect[i] += spatial_metric_der_raised3[i][s][s]; - aux_vect[i] -= spatial_metric_der_raised1[s][s][i]; + aux_vect[i] -= spatial_metric_der_raised1[s][s][i]; } } // Set spatial metric tensor. - fout[0] = spatial_metric[0][0]; fout[1] = spatial_metric[0][1]; fout[2] = spatial_metric[0][2]; - fout[3] = spatial_metric[1][0]; fout[4] = spatial_metric[1][1]; fout[5] = spatial_metric[1][2]; - fout[6] = spatial_metric[2][0]; fout[7] = spatial_metric[2][1]; fout[8] = spatial_metric[2][2]; + fout[0] = spatial_metric[0][0]; + fout[1] = spatial_metric[0][1]; + fout[2] = spatial_metric[0][2]; + fout[3] = spatial_metric[1][0]; + fout[4] = spatial_metric[1][1]; + fout[5] = spatial_metric[1][2]; + fout[6] = spatial_metric[2][0]; + fout[7] = spatial_metric[2][1]; + fout[8] = spatial_metric[2][2]; // Set lapse gauge variable. fout[9] = lapse; // Set extrinsic curvature tensor. - fout[10] = extrinsic_curvature[0][0]; fout[11] = extrinsic_curvature[0][1]; fout[12] = extrinsic_curvature[0][2]; - fout[13] = extrinsic_curvature[1][0]; fout[14] = extrinsic_curvature[1][1]; fout[15] = extrinsic_curvature[1][2]; - fout[16] = extrinsic_curvature[2][0]; fout[17] = extrinsic_curvature[2][1]; fout[18] = extrinsic_curvature[2][2]; + fout[10] = extrinsic_curvature[0][0]; + fout[11] = extrinsic_curvature[0][1]; + fout[12] = extrinsic_curvature[0][2]; + fout[13] = extrinsic_curvature[1][0]; + fout[14] = extrinsic_curvature[1][1]; + fout[15] = extrinsic_curvature[1][2]; + fout[16] = extrinsic_curvature[2][0]; + fout[17] = extrinsic_curvature[2][1]; + fout[18] = extrinsic_curvature[2][2]; // Set spatial metric tensor derivatives. - fout[19] = spatial_metric_der[0][0][0]; fout[20] = spatial_metric_der[0][0][1]; fout[21] = spatial_metric_der[0][0][2]; - fout[22] = spatial_metric_der[0][1][0]; fout[23] = spatial_metric_der[0][1][1]; fout[24] = spatial_metric_der[0][1][2]; - fout[25] = spatial_metric_der[0][2][0]; fout[26] = spatial_metric_der[0][2][1]; fout[27] = spatial_metric_der[0][2][2]; - - fout[28] = spatial_metric_der[1][0][0]; fout[29] = spatial_metric_der[1][0][1]; fout[30] = spatial_metric_der[1][0][2]; - fout[31] = spatial_metric_der[1][1][0]; fout[32] = spatial_metric_der[1][1][1]; fout[33] = spatial_metric_der[1][1][2]; - fout[34] = spatial_metric_der[1][2][0]; fout[35] = spatial_metric_der[1][2][1]; fout[36] = spatial_metric_der[1][2][2]; - - fout[37] = spatial_metric_der[2][0][0]; fout[38] = spatial_metric_der[2][0][1]; fout[39] = spatial_metric_der[2][0][2]; - fout[40] = spatial_metric_der[2][1][0]; fout[41] = spatial_metric_der[2][1][1]; fout[42] = spatial_metric_der[2][1][2]; - fout[43] = spatial_metric_der[2][2][0]; fout[44] = spatial_metric_der[2][2][1]; fout[45] = spatial_metric_der[2][2][2]; + fout[19] = spatial_metric_der[0][0][0]; + fout[20] = spatial_metric_der[0][0][1]; + fout[21] = spatial_metric_der[0][0][2]; + fout[22] = spatial_metric_der[0][1][0]; + fout[23] = spatial_metric_der[0][1][1]; + fout[24] = spatial_metric_der[0][1][2]; + fout[25] = spatial_metric_der[0][2][0]; + fout[26] = spatial_metric_der[0][2][1]; + fout[27] = spatial_metric_der[0][2][2]; + + fout[28] = spatial_metric_der[1][0][0]; + fout[29] = spatial_metric_der[1][0][1]; + fout[30] = spatial_metric_der[1][0][2]; + fout[31] = spatial_metric_der[1][1][0]; + fout[32] = spatial_metric_der[1][1][1]; + fout[33] = spatial_metric_der[1][1][2]; + fout[34] = spatial_metric_der[1][2][0]; + fout[35] = spatial_metric_der[1][2][1]; + fout[36] = spatial_metric_der[1][2][2]; + + fout[37] = spatial_metric_der[2][0][0]; + fout[38] = spatial_metric_der[2][0][1]; + fout[39] = spatial_metric_der[2][0][2]; + fout[40] = spatial_metric_der[2][1][0]; + fout[41] = spatial_metric_der[2][1][1]; + fout[42] = spatial_metric_der[2][1][2]; + fout[43] = spatial_metric_der[2][2][0]; + fout[44] = spatial_metric_der[2][2][1]; + fout[45] = spatial_metric_der[2][2][2]; // Set lapse function derivatives. - fout[46] = lapse_der[0]; fout[47] = lapse_der[1]; fout[48] = lapse_der[2]; + fout[46] = lapse_der[0]; + fout[47] = lapse_der[1]; + fout[48] = lapse_der[2]; // Set auxiliary vector. - fout[49] = aux_vect[0]; fout[50] = aux_vect[1]; fout[51] = aux_vect[2]; + fout[49] = aux_vect[0]; + fout[50] = aux_vect[1]; + fout[51] = aux_vect[2]; // Set shift gauge variables. - fout[52] = shift[0]; fout[53] = shift[1]; fout[54] = shift[2]; + fout[52] = shift[0]; + fout[53] = shift[1]; + fout[54] = shift[2]; // Set shift vector derivatives. - fout[55] = shift_der[0][0]; fout[56] = shift_der[0][1]; fout[57] = shift_der[0][2]; - fout[58] = shift_der[1][0]; fout[59] = shift_der[1][1]; fout[60] = shift_der[1][2]; - fout[61] = shift_der[2][0]; fout[62] = shift_der[2][1]; fout[63] = shift_der[2][2]; + fout[55] = shift_der[0][0]; + fout[56] = shift_der[0][1]; + fout[57] = shift_der[0][2]; + fout[58] = shift_der[1][0]; + fout[59] = shift_der[1][1]; + fout[60] = shift_der[1][2]; + fout[61] = shift_der[2][0]; + fout[62] = shift_der[2][1]; + fout[63] = shift_der[2][2]; if (in_excision_region) { for (int i = 0; i < 64; i++) { @@ -294,8 +351,7 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -309,24 +365,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -347,12 +404,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Einstein equations. - struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new(ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu); + struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new( + ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu + ); struct gkyl_moment_species einstein = { .name = "vacuum_einstein", .equation = vacuum_einstein, - + .init = evalVacuumEinsteinInit, .force_low_order_flux = false, // Use HLL fluxes. .ctx = &ctx, @@ -362,8 +421,8 @@ main(int argc, char **argv) .vacuum_einstein_spacetime_slicing = ctx.spacetime_slicing, .vacuum_einstein_spacetime_evolution = ctx.spacetime_evolution, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -374,7 +433,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -382,8 +441,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -397,22 +455,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -437,9 +485,9 @@ main(int argc, char **argv) .name = "vacuum_einstein_brill_lindquist", .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -447,13 +495,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { einstein }, + .species = {einstein}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -465,10 +510,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -477,26 +526,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -512,7 +566,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -527,8 +581,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -536,7 +589,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -544,8 +599,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -572,14 +626,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(vacuum_einstein); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_vacuum_einstein_conformal_brill_lindquist.c b/moments/creg/rt_vacuum_einstein_conformal_brill_lindquist.c index 98117b589f..291da6215f 100644 --- a/moments/creg/rt_vacuum_einstein_conformal_brill_lindquist.c +++ b/moments/creg/rt_vacuum_einstein_conformal_brill_lindquist.c @@ -19,8 +19,7 @@ #include -struct einstein_conformal_brill_lindquist_ctx -{ +struct einstein_conformal_brill_lindquist_ctx { // Spacetime parameters (using geometric units). double mass1; // Mass of the first black hole. double mass2; // Mass of the second black hole. @@ -56,8 +55,7 @@ struct einstein_conformal_brill_lindquist_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct einstein_conformal_brill_lindquist_ctx -create_ctx(void) +struct einstein_conformal_brill_lindquist_ctx create_ctx(void) { // Spacetime parameters (using geometric units). double mass1 = 0.5; // Mass of the first black hole. @@ -70,14 +68,18 @@ create_ctx(void) double pos_x2 = 7.5; // Position of the second black hole (x-direction). double pos_y2 = 5.0; // Position of the second black hole (y-direction). double pos_z2 = 0.0; // Position of the second black hole (z-direction). - + // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_new(false, mass1, mass2, pos_x1, pos_y1, pos_z1, pos_x2, pos_y2, pos_z2); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_new( + false, mass1, mass2, pos_x1, pos_y1, pos_z1, pos_x2, pos_y2, pos_z2 + ); // Evolution parameters. double excision_threshold = 0.3; // Excision threshold (lapse). - enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. - enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. + enum gkyl_spacetime_slicing spacetime_slicing = + GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. + enum gkyl_spacetime_evolution spacetime_evolution = + GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -116,14 +118,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVacuumEinsteinConformalInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct einstein_conformal_brill_lindquist_ctx *app = ctx; @@ -134,30 +137,30 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double double *conformal_shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *conformal_lapse_der = gkyl_malloc(sizeof(double[3])); - double **conformal_shift_der = gkyl_malloc(sizeof(double*[3])); + double **conformal_shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { conformal_spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -167,7 +170,7 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double double conformal_fact, bssn_conformal_fact; double *conformal_fact_der = gkyl_malloc(sizeof(double[3])); double *bssn_conformal_fact_der = gkyl_malloc(sizeof(double[3])); - double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_fact_der2[i] = gkyl_malloc(sizeof(double[3])); } @@ -176,21 +179,44 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &conformal_lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &conformal_shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &conformal_spatial_metric); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_conformal_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_extrinsic_curvature); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x, y, 0.0, &inv_conformal_spatial_metric + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_extrinsic_curvature + ); spacetime->conformal_factor_func(spacetime, 0.0, x, y, 0.0, &conformal_fact); spacetime->bssn_conformal_factor_func(spacetime, 0.0, x, y, 0.0, &bssn_conformal_fact); - spacetime->conformal_factor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_fact_der); - spacetime->bssn_conformal_factor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &bssn_conformal_fact_der); - spacetime->bssn_conformal_factor_der2_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &bssn_conformal_fact_der2); + spacetime->conformal_factor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_fact_der + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &bssn_conformal_fact_der + ); + spacetime->bssn_conformal_factor_der2_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &bssn_conformal_fact_der2 + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_spatial_metric_der + ); for (int i = 0; i < 3; i++) { conformal_fact_der[i] /= conformal_fact; @@ -202,14 +228,16 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double bssn_conformal_fact_der[i] = 0.0; for (int j = 0; j < 3; j++) { - bssn_conformal_fact_der2[i][j] = 0.0; + bssn_conformal_fact_der2[i][j] = 0.0; } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_spatial_metric[i][j] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - inv_conformal_spatial_metric[i][j] *= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric[i][j] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + inv_conformal_spatial_metric[i][j] *= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); } } @@ -217,8 +245,10 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der[i][j][k] = 0.5 * conformal_spatial_metric_der[i][j][k]; - conformal_spatial_metric_der[i][j][k] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_spatial_metric_der[i][j][k] -= 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; + conformal_spatial_metric_der[i][j][k] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric_der[i][j][k] -= + 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; } conformal_shift_der[i][j] = 0.5 * conformal_shift_der[i][j]; @@ -234,14 +264,15 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1[k][i][j] += inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; + conformal_spatial_metric_der_raised1[k][i][j] += + inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; } } } } - + double conformal_spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -249,7 +280,8 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double conformal_spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3[i][j][k] += inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; + conformal_spatial_metric_der_raised3[i][j][k] += + inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; } } } @@ -261,62 +293,112 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int s = 0; s < 3; s++) { conformal_aux_vect[i] += conformal_spatial_metric_der_raised3[i][s][s]; - conformal_aux_vect[i] -= conformal_spatial_metric_der_raised1[s][s][i]; + conformal_aux_vect[i] -= conformal_spatial_metric_der_raised1[s][s][i]; } conformal_aux_vect[i] -= 4.0 * conformal_fact_der[i]; } // Set conformal spatial metric tensor. - fout[0] = conformal_spatial_metric[0][0]; fout[1] = conformal_spatial_metric[0][1]; fout[2] = conformal_spatial_metric[0][2]; - fout[3] = conformal_spatial_metric[1][0]; fout[4] = conformal_spatial_metric[1][1]; fout[5] = conformal_spatial_metric[1][2]; - fout[6] = conformal_spatial_metric[2][0]; fout[7] = conformal_spatial_metric[2][1]; fout[8] = conformal_spatial_metric[2][2]; + fout[0] = conformal_spatial_metric[0][0]; + fout[1] = conformal_spatial_metric[0][1]; + fout[2] = conformal_spatial_metric[0][2]; + fout[3] = conformal_spatial_metric[1][0]; + fout[4] = conformal_spatial_metric[1][1]; + fout[5] = conformal_spatial_metric[1][2]; + fout[6] = conformal_spatial_metric[2][0]; + fout[7] = conformal_spatial_metric[2][1]; + fout[8] = conformal_spatial_metric[2][2]; // Set conformal lapse gauge variable. fout[9] = conformal_lapse; // Set conformal extrinsic curvature tensor. - fout[10] = conformal_extrinsic_curvature[0][0]; fout[11] = conformal_extrinsic_curvature[0][1]; fout[12] = conformal_extrinsic_curvature[0][2]; - fout[13] = conformal_extrinsic_curvature[1][0]; fout[14] = conformal_extrinsic_curvature[1][1]; fout[15] = conformal_extrinsic_curvature[1][2]; - fout[16] = conformal_extrinsic_curvature[2][0]; fout[17] = conformal_extrinsic_curvature[2][1]; fout[18] = conformal_extrinsic_curvature[2][2]; + fout[10] = conformal_extrinsic_curvature[0][0]; + fout[11] = conformal_extrinsic_curvature[0][1]; + fout[12] = conformal_extrinsic_curvature[0][2]; + fout[13] = conformal_extrinsic_curvature[1][0]; + fout[14] = conformal_extrinsic_curvature[1][1]; + fout[15] = conformal_extrinsic_curvature[1][2]; + fout[16] = conformal_extrinsic_curvature[2][0]; + fout[17] = conformal_extrinsic_curvature[2][1]; + fout[18] = conformal_extrinsic_curvature[2][2]; // Set conformal spatial metric tensor derivatives. - fout[19] = conformal_spatial_metric_der[0][0][0]; fout[20] = conformal_spatial_metric_der[0][0][1]; fout[21] = conformal_spatial_metric_der[0][0][2]; - fout[22] = conformal_spatial_metric_der[0][1][0]; fout[23] = conformal_spatial_metric_der[0][1][1]; fout[24] = conformal_spatial_metric_der[0][1][2]; - fout[25] = conformal_spatial_metric_der[0][2][0]; fout[26] = conformal_spatial_metric_der[0][2][1]; fout[27] = conformal_spatial_metric_der[0][2][2]; - - fout[28] = conformal_spatial_metric_der[1][0][0]; fout[29] = conformal_spatial_metric_der[1][0][1]; fout[30] = conformal_spatial_metric_der[1][0][2]; - fout[31] = conformal_spatial_metric_der[1][1][0]; fout[32] = conformal_spatial_metric_der[1][1][1]; fout[33] = conformal_spatial_metric_der[1][1][2]; - fout[34] = conformal_spatial_metric_der[1][2][0]; fout[35] = conformal_spatial_metric_der[1][2][1]; fout[36] = conformal_spatial_metric_der[1][2][2]; - - fout[37] = conformal_spatial_metric_der[2][0][0]; fout[38] = conformal_spatial_metric_der[2][0][1]; fout[39] = conformal_spatial_metric_der[2][0][2]; - fout[40] = conformal_spatial_metric_der[2][1][0]; fout[41] = conformal_spatial_metric_der[2][1][1]; fout[42] = conformal_spatial_metric_der[2][1][2]; - fout[43] = conformal_spatial_metric_der[2][2][0]; fout[44] = conformal_spatial_metric_der[2][2][1]; fout[45] = conformal_spatial_metric_der[2][2][2]; + fout[19] = conformal_spatial_metric_der[0][0][0]; + fout[20] = conformal_spatial_metric_der[0][0][1]; + fout[21] = conformal_spatial_metric_der[0][0][2]; + fout[22] = conformal_spatial_metric_der[0][1][0]; + fout[23] = conformal_spatial_metric_der[0][1][1]; + fout[24] = conformal_spatial_metric_der[0][1][2]; + fout[25] = conformal_spatial_metric_der[0][2][0]; + fout[26] = conformal_spatial_metric_der[0][2][1]; + fout[27] = conformal_spatial_metric_der[0][2][2]; + + fout[28] = conformal_spatial_metric_der[1][0][0]; + fout[29] = conformal_spatial_metric_der[1][0][1]; + fout[30] = conformal_spatial_metric_der[1][0][2]; + fout[31] = conformal_spatial_metric_der[1][1][0]; + fout[32] = conformal_spatial_metric_der[1][1][1]; + fout[33] = conformal_spatial_metric_der[1][1][2]; + fout[34] = conformal_spatial_metric_der[1][2][0]; + fout[35] = conformal_spatial_metric_der[1][2][1]; + fout[36] = conformal_spatial_metric_der[1][2][2]; + + fout[37] = conformal_spatial_metric_der[2][0][0]; + fout[38] = conformal_spatial_metric_der[2][0][1]; + fout[39] = conformal_spatial_metric_der[2][0][2]; + fout[40] = conformal_spatial_metric_der[2][1][0]; + fout[41] = conformal_spatial_metric_der[2][1][1]; + fout[42] = conformal_spatial_metric_der[2][1][2]; + fout[43] = conformal_spatial_metric_der[2][2][0]; + fout[44] = conformal_spatial_metric_der[2][2][1]; + fout[45] = conformal_spatial_metric_der[2][2][2]; // Set conformal lapse function derivatives. - fout[46] = conformal_lapse_der[0]; fout[47] = conformal_lapse_der[1]; fout[48] = conformal_lapse_der[2]; + fout[46] = conformal_lapse_der[0]; + fout[47] = conformal_lapse_der[1]; + fout[48] = conformal_lapse_der[2]; // Set conformal auxiliary vector. - fout[49] = conformal_aux_vect[0]; fout[50] = conformal_aux_vect[1]; fout[51] = conformal_aux_vect[2]; + fout[49] = conformal_aux_vect[0]; + fout[50] = conformal_aux_vect[1]; + fout[51] = conformal_aux_vect[2]; // Set conformal shift gauge variables. - fout[52] = conformal_shift[0]; fout[53] = conformal_shift[1]; fout[54] = conformal_shift[2]; + fout[52] = conformal_shift[0]; + fout[53] = conformal_shift[1]; + fout[54] = conformal_shift[2]; // Set conformal shift vector derivatives. - fout[55] = conformal_shift_der[0][0]; fout[56] = conformal_shift_der[0][1]; fout[57] = conformal_shift_der[0][2]; - fout[58] = conformal_shift_der[1][0]; fout[59] = conformal_shift_der[1][1]; fout[60] = conformal_shift_der[1][2]; - fout[61] = conformal_shift_der[2][0]; fout[62] = conformal_shift_der[2][1]; fout[63] = conformal_shift_der[2][2]; + fout[55] = conformal_shift_der[0][0]; + fout[56] = conformal_shift_der[0][1]; + fout[57] = conformal_shift_der[0][2]; + fout[58] = conformal_shift_der[1][0]; + fout[59] = conformal_shift_der[1][1]; + fout[60] = conformal_shift_der[1][2]; + fout[61] = conformal_shift_der[2][0]; + fout[62] = conformal_shift_der[2][1]; + fout[63] = conformal_shift_der[2][2]; // Set BSSN conformal factor. fout[64] = bssn_conformal_fact; // Set BSSN conformal factor first derivatives. - fout[65] = bssn_conformal_fact_der[0]; fout[66] = bssn_conformal_fact_der[1]; fout[67] = bssn_conformal_fact_der[2]; + fout[65] = bssn_conformal_fact_der[0]; + fout[66] = bssn_conformal_fact_der[1]; + fout[67] = bssn_conformal_fact_der[2]; // Set BSSN conformal factor second derivatives. - fout[68] = bssn_conformal_fact_der2[0][0]; fout[69] = bssn_conformal_fact_der2[0][1]; fout[70] = bssn_conformal_fact_der2[0][2]; - fout[71] = bssn_conformal_fact_der2[1][0]; fout[72] = bssn_conformal_fact_der2[1][1]; fout[73] = bssn_conformal_fact_der2[1][2]; - fout[74] = bssn_conformal_fact_der2[2][0]; fout[75] = bssn_conformal_fact_der2[2][1]; fout[76] = bssn_conformal_fact_der2[2][2]; + fout[68] = bssn_conformal_fact_der2[0][0]; + fout[69] = bssn_conformal_fact_der2[0][1]; + fout[70] = bssn_conformal_fact_der2[0][2]; + fout[71] = bssn_conformal_fact_der2[1][0]; + fout[72] = bssn_conformal_fact_der2[1][1]; + fout[73] = bssn_conformal_fact_der2[1][2]; + fout[74] = bssn_conformal_fact_der2[2][0]; + fout[75] = bssn_conformal_fact_der2[2][1]; + fout[76] = bssn_conformal_fact_der2[2][2]; if (in_excision_region) { for (int i = 0; i < 77; i++) { @@ -349,8 +431,7 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double gkyl_free(bssn_conformal_fact_der2); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -364,24 +445,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -396,18 +478,21 @@ main(int argc, char **argv) gkyl_mem_debug_set(true); } - struct einstein_conformal_brill_lindquist_ctx ctx = create_ctx(); // Context for initialization functions. + struct einstein_conformal_brill_lindquist_ctx ctx = + create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Conformal Einstein equations. - struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new(ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu); + struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new( + ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu + ); struct gkyl_moment_species einstein_conformal = { .name = "vacuum_einstein_conformal", .equation = vacuum_einstein_conformal, - + .init = evalVacuumEinsteinConformalInit, .force_low_order_flux = false, // Use HLL fluxes. .ctx = &ctx, @@ -417,8 +502,8 @@ main(int argc, char **argv) .vacuum_einstein_conformal_spacetime_slicing = ctx.spacetime_slicing, .vacuum_einstein_conformal_spacetime_evolution = ctx.spacetime_evolution, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -429,7 +514,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -437,8 +522,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -452,22 +536,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -492,9 +566,9 @@ main(int argc, char **argv) .name = "vacuum_einstein_conformal_brill_lindquist", .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -502,13 +576,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { einstein_conformal }, + .species = {einstein_conformal}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -520,10 +591,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -532,26 +607,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -567,7 +647,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -582,8 +662,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -591,7 +670,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -599,8 +680,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -627,14 +707,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(vacuum_einstein_conformal); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_vacuum_einstein_conformal_gowdywave.c b/moments/creg/rt_vacuum_einstein_conformal_gowdywave.c index 6ba9dc3438..487d5bea2c 100644 --- a/moments/creg/rt_vacuum_einstein_conformal_gowdywave.c +++ b/moments/creg/rt_vacuum_einstein_conformal_gowdywave.c @@ -18,8 +18,7 @@ #include -struct einstein_conformal_gowdywave_ctx -{ +struct einstein_conformal_gowdywave_ctx { // Mathematical constants (dimensionless). double pi; @@ -47,8 +46,7 @@ struct einstein_conformal_gowdywave_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct einstein_conformal_gowdywave_ctx -create_ctx(void) +struct einstein_conformal_gowdywave_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -58,11 +56,13 @@ create_ctx(void) // Pointer to spacetime metric. struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - + // Evolution parameters. double excision_threshold = 0.3; // Excision threshold (lapse). - enum gkyl_spacetime_slicing spacetime_slicing = GKYL_HARMONIC_SLICING; // Spacetime slicing condition. - enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. + enum gkyl_spacetime_slicing spacetime_slicing = + GKYL_HARMONIC_SLICING; // Spacetime slicing condition. + enum gkyl_spacetime_evolution spacetime_evolution = + GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. // Simulation parameters. int Nx = 50; // Cell count (x-direction). @@ -91,14 +91,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVacuumEinsteinConformalInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct einstein_conformal_gowdywave_ctx *app = ctx; @@ -111,30 +112,30 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double double *conformal_shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *conformal_lapse_der = gkyl_malloc(sizeof(double[3])); - double **conformal_shift_der = gkyl_malloc(sizeof(double*[3])); + double **conformal_shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { conformal_spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -144,7 +145,7 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double double conformal_fact, bssn_conformal_fact; double *conformal_fact_der = gkyl_malloc(sizeof(double[3])); double *bssn_conformal_fact_der = gkyl_malloc(sizeof(double[3])); - double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_fact_der2[i] = gkyl_malloc(sizeof(double[3])); } @@ -153,28 +154,53 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &conformal_lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &conformal_shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &conformal_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &conformal_extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &conformal_extrinsic_curvature + ); spacetime->conformal_factor_func(spacetime, 0.0, x, 0.0, 0.0, &conformal_fact); spacetime->bssn_conformal_factor_func(spacetime, 0.0, x, 0.0, 0.0, &bssn_conformal_fact); - spacetime->conformal_factor_der_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &conformal_fact_der); - spacetime->bssn_conformal_factor_der_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &bssn_conformal_fact_der); - spacetime->bssn_conformal_factor_der2_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &bssn_conformal_fact_der2); + spacetime->conformal_factor_der_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &conformal_fact_der + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &bssn_conformal_fact_der + ); + spacetime->bssn_conformal_factor_der2_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &bssn_conformal_fact_der2 + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_spatial_metric_der + ); - double lambda = (-2.0 * pi * tau0 * jn(0, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0) * (cos(2.0 * pi * x) * cos(2.0 * pi * x))) - + (2.0 * (pi * pi) * (tau0 * tau0) * ((jn(0, 2.0 * pi * tau0) * jn(0, 2.0 * pi * tau0)) + (jn(1, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0)))) - - (0.5 * (((2.0 * pi) * (2.0 * pi)) * ((jn(0, 2.0 * pi) * jn(0, 2.0 * pi)) + (jn(1, 2.0 * pi) * jn(1, 2.0 * pi))))) - + (pi * jn(0, 2.0 * pi) * jn(1, 2.0 * pi)); - double lambda_dt = 2.0 * (pi * pi) * tau0 * ((jn(1, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0)) * (1.0 + cos(4.0 * pi * x)) - + (2.0 * (jn(0, 2.0 * pi * tau0) * jn(0, 2.0 * pi * tau0)) * (sin(2.0 * pi * x) * sin(2.0 * pi * x)))); - double lambda_dx = 4.0 * (pi * pi * tau0) * jn(0, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0) * sin(4.0 * pi * x); + double lambda = (-2.0 * pi * tau0 * jn(0, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0) * + (cos(2.0 * pi * x) * cos(2.0 * pi * x))) + + (2.0 * (pi * pi) * (tau0 * tau0) * + ((jn(0, 2.0 * pi * tau0) * jn(0, 2.0 * pi * tau0)) + + (jn(1, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0)))) - + (0.5 * (((2.0 * pi) * (2.0 * pi)) * ((jn(0, 2.0 * pi) * jn(0, 2.0 * pi)) + + (jn(1, 2.0 * pi) * jn(1, 2.0 * pi))))) + + (pi * jn(0, 2.0 * pi) * jn(1, 2.0 * pi)); + double lambda_dt = + 2.0 * (pi * pi) * tau0 * + ((jn(1, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0)) * (1.0 + cos(4.0 * pi * x)) + + (2.0 * (jn(0, 2.0 * pi * tau0) * jn(0, 2.0 * pi * tau0)) * + (sin(2.0 * pi * x) * sin(2.0 * pi * x)))); + double lambda_dx = + 4.0 * (pi * pi * tau0) * jn(0, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0) * sin(4.0 * pi * x); conformal_spatial_det = exp(0.5 * lambda) * pow(tau0, 1.5); conformal_fact = pow(conformal_spatial_det, 1.0 / 12.0); @@ -184,31 +210,44 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double double P_dt = -2.0 * pi * jn(1, 2.0 * pi * tau0) * cos(2.0 * pi * x); double P_dx = -2.0 * pi * jn(0, 2.0 * pi * tau0) * sin(2.0 * pi * x); - conformal_spatial_metric[0][0] = ((1.0 / sqrt(tau0)) * exp(0.5 * lambda)) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_spatial_metric[1][1] = (tau0 * exp(P)) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_spatial_metric[2][2] = (tau0 * exp(-P)) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric[0][0] = + ((1.0 / sqrt(tau0)) * exp(0.5 * lambda)) / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric[1][1] = + (tau0 * exp(P)) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric[2][2] = + (tau0 * exp(-P)) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); conformal_lapse = (1.0 / pow(tau0, 0.25)) * exp(0.25 * lambda); conformal_lapse_der[0] = (exp(0.25 * lambda) * lambda_dx) / (4.0 * pow(tau0, 0.25)); - conformal_extrinsic_curvature[0][0] = 0.25 * (1.0 / pow(tau0, 0.25)) * exp(0.25 * lambda) * ((1.0 / tau0) - lambda_dt); - conformal_extrinsic_curvature[1][1] = -0.5 * pow(tau0, 0.25) * exp(-0.25 * lambda) * exp(P) * (1.0 + (tau0 * P_dt)); - conformal_extrinsic_curvature[2][2] = -0.5 * pow(tau0, 0.25) * exp(-0.25 * lambda) * exp(-P) * (1.0 - (tau0 * P_dt)); + conformal_extrinsic_curvature[0][0] = + 0.25 * (1.0 / pow(tau0, 0.25)) * exp(0.25 * lambda) * ((1.0 / tau0) - lambda_dt); + conformal_extrinsic_curvature[1][1] = + -0.5 * pow(tau0, 0.25) * exp(-0.25 * lambda) * exp(P) * (1.0 + (tau0 * P_dt)); + conformal_extrinsic_curvature[2][2] = + -0.5 * pow(tau0, 0.25) * exp(-0.25 * lambda) * exp(-P) * (1.0 - (tau0 * P_dt)); conformal_spatial_metric_der[0][0][0] = (exp(0.25 * lambda) * lambda_dx) / (2.0 * sqrt(tau0)); conformal_spatial_metric_der[0][1][1] = exp(P) * tau0 * P_dx; conformal_spatial_metric_der[0][2][2] = -exp(-P) * tau0 * P_dx; - inv_conformal_spatial_metric[0][0] = (exp(-0.5 * lambda) * sqrt(tau0)) * (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - inv_conformal_spatial_metric[1][1] = (exp(-P) / tau0) * (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - inv_conformal_spatial_metric[2][2] = (exp(P) / tau0) * (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + inv_conformal_spatial_metric[0][0] = + (exp(-0.5 * lambda) * sqrt(tau0)) * + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + inv_conformal_spatial_metric[1][1] = + (exp(-P) / tau0) * (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + inv_conformal_spatial_metric[2][2] = + (exp(P) / tau0) * (conformal_fact * conformal_fact * conformal_fact * conformal_fact); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der[i][j][k] = 0.5 * conformal_spatial_metric_der[i][j][k]; - conformal_spatial_metric_der[i][j][k] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_spatial_metric_der[i][j][k] -= 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; + conformal_spatial_metric_der[i][j][k] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric_der[i][j][k] -= + 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; } conformal_shift_der[i][j] = 0.5 * conformal_shift_der[i][j]; @@ -224,14 +263,15 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1[k][i][j] += inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; + conformal_spatial_metric_der_raised1[k][i][j] += + inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; } } } } - + double conformal_spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -239,7 +279,8 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double conformal_spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3[i][j][k] += inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; + conformal_spatial_metric_der_raised3[i][j][k] += + inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; } } } @@ -251,62 +292,112 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int s = 0; s < 3; s++) { conformal_aux_vect[i] += conformal_spatial_metric_der_raised3[i][s][s]; - conformal_aux_vect[i] -= conformal_spatial_metric_der_raised1[s][s][i]; + conformal_aux_vect[i] -= conformal_spatial_metric_der_raised1[s][s][i]; } conformal_aux_vect[i] -= 4.0 * conformal_fact_der[i]; } // Set conformal spatial metric tensor. - fout[0] = conformal_spatial_metric[0][0]; fout[1] = conformal_spatial_metric[0][1]; fout[2] = conformal_spatial_metric[0][2]; - fout[3] = conformal_spatial_metric[1][0]; fout[4] = conformal_spatial_metric[1][1]; fout[5] = conformal_spatial_metric[1][2]; - fout[6] = conformal_spatial_metric[2][0]; fout[7] = conformal_spatial_metric[2][1]; fout[8] = conformal_spatial_metric[2][2]; + fout[0] = conformal_spatial_metric[0][0]; + fout[1] = conformal_spatial_metric[0][1]; + fout[2] = conformal_spatial_metric[0][2]; + fout[3] = conformal_spatial_metric[1][0]; + fout[4] = conformal_spatial_metric[1][1]; + fout[5] = conformal_spatial_metric[1][2]; + fout[6] = conformal_spatial_metric[2][0]; + fout[7] = conformal_spatial_metric[2][1]; + fout[8] = conformal_spatial_metric[2][2]; // Set conformal lapse gauge variable. fout[9] = conformal_lapse; // Set conformal extrinsic curvature tensor. - fout[10] = conformal_extrinsic_curvature[0][0]; fout[11] = conformal_extrinsic_curvature[0][1]; fout[12] = conformal_extrinsic_curvature[0][2]; - fout[13] = conformal_extrinsic_curvature[1][0]; fout[14] = conformal_extrinsic_curvature[1][1]; fout[15] = conformal_extrinsic_curvature[1][2]; - fout[16] = conformal_extrinsic_curvature[2][0]; fout[17] = conformal_extrinsic_curvature[2][1]; fout[18] = conformal_extrinsic_curvature[2][2]; + fout[10] = conformal_extrinsic_curvature[0][0]; + fout[11] = conformal_extrinsic_curvature[0][1]; + fout[12] = conformal_extrinsic_curvature[0][2]; + fout[13] = conformal_extrinsic_curvature[1][0]; + fout[14] = conformal_extrinsic_curvature[1][1]; + fout[15] = conformal_extrinsic_curvature[1][2]; + fout[16] = conformal_extrinsic_curvature[2][0]; + fout[17] = conformal_extrinsic_curvature[2][1]; + fout[18] = conformal_extrinsic_curvature[2][2]; // Set conformal spatial metric tensor derivatives. - fout[19] = conformal_spatial_metric_der[0][0][0]; fout[20] = conformal_spatial_metric_der[0][0][1]; fout[21] = conformal_spatial_metric_der[0][0][2]; - fout[22] = conformal_spatial_metric_der[0][1][0]; fout[23] = conformal_spatial_metric_der[0][1][1]; fout[24] = conformal_spatial_metric_der[0][1][2]; - fout[25] = conformal_spatial_metric_der[0][2][0]; fout[26] = conformal_spatial_metric_der[0][2][1]; fout[27] = conformal_spatial_metric_der[0][2][2]; - - fout[28] = conformal_spatial_metric_der[1][0][0]; fout[29] = conformal_spatial_metric_der[1][0][1]; fout[30] = conformal_spatial_metric_der[1][0][2]; - fout[31] = conformal_spatial_metric_der[1][1][0]; fout[32] = conformal_spatial_metric_der[1][1][1]; fout[33] = conformal_spatial_metric_der[1][1][2]; - fout[34] = conformal_spatial_metric_der[1][2][0]; fout[35] = conformal_spatial_metric_der[1][2][1]; fout[36] = conformal_spatial_metric_der[1][2][2]; - - fout[37] = conformal_spatial_metric_der[2][0][0]; fout[38] = conformal_spatial_metric_der[2][0][1]; fout[39] = conformal_spatial_metric_der[2][0][2]; - fout[40] = conformal_spatial_metric_der[2][1][0]; fout[41] = conformal_spatial_metric_der[2][1][1]; fout[42] = conformal_spatial_metric_der[2][1][2]; - fout[43] = conformal_spatial_metric_der[2][2][0]; fout[44] = conformal_spatial_metric_der[2][2][1]; fout[45] = conformal_spatial_metric_der[2][2][2]; + fout[19] = conformal_spatial_metric_der[0][0][0]; + fout[20] = conformal_spatial_metric_der[0][0][1]; + fout[21] = conformal_spatial_metric_der[0][0][2]; + fout[22] = conformal_spatial_metric_der[0][1][0]; + fout[23] = conformal_spatial_metric_der[0][1][1]; + fout[24] = conformal_spatial_metric_der[0][1][2]; + fout[25] = conformal_spatial_metric_der[0][2][0]; + fout[26] = conformal_spatial_metric_der[0][2][1]; + fout[27] = conformal_spatial_metric_der[0][2][2]; + + fout[28] = conformal_spatial_metric_der[1][0][0]; + fout[29] = conformal_spatial_metric_der[1][0][1]; + fout[30] = conformal_spatial_metric_der[1][0][2]; + fout[31] = conformal_spatial_metric_der[1][1][0]; + fout[32] = conformal_spatial_metric_der[1][1][1]; + fout[33] = conformal_spatial_metric_der[1][1][2]; + fout[34] = conformal_spatial_metric_der[1][2][0]; + fout[35] = conformal_spatial_metric_der[1][2][1]; + fout[36] = conformal_spatial_metric_der[1][2][2]; + + fout[37] = conformal_spatial_metric_der[2][0][0]; + fout[38] = conformal_spatial_metric_der[2][0][1]; + fout[39] = conformal_spatial_metric_der[2][0][2]; + fout[40] = conformal_spatial_metric_der[2][1][0]; + fout[41] = conformal_spatial_metric_der[2][1][1]; + fout[42] = conformal_spatial_metric_der[2][1][2]; + fout[43] = conformal_spatial_metric_der[2][2][0]; + fout[44] = conformal_spatial_metric_der[2][2][1]; + fout[45] = conformal_spatial_metric_der[2][2][2]; // Set conformal lapse function derivatives. - fout[46] = conformal_lapse_der[0]; fout[47] = conformal_lapse_der[1]; fout[48] = conformal_lapse_der[2]; + fout[46] = conformal_lapse_der[0]; + fout[47] = conformal_lapse_der[1]; + fout[48] = conformal_lapse_der[2]; // Set conformal auxiliary vector. - fout[49] = conformal_aux_vect[0]; fout[50] = conformal_aux_vect[1]; fout[51] = conformal_aux_vect[2]; + fout[49] = conformal_aux_vect[0]; + fout[50] = conformal_aux_vect[1]; + fout[51] = conformal_aux_vect[2]; // Set conformal shift gauge variables. - fout[52] = conformal_shift[0]; fout[53] = conformal_shift[1]; fout[54] = conformal_shift[2]; + fout[52] = conformal_shift[0]; + fout[53] = conformal_shift[1]; + fout[54] = conformal_shift[2]; // Set conformal shift vector derivatives. - fout[55] = conformal_shift_der[0][0]; fout[56] = conformal_shift_der[0][1]; fout[57] = conformal_shift_der[0][2]; - fout[58] = conformal_shift_der[1][0]; fout[59] = conformal_shift_der[1][1]; fout[60] = conformal_shift_der[1][2]; - fout[61] = conformal_shift_der[2][0]; fout[62] = conformal_shift_der[2][1]; fout[63] = conformal_shift_der[2][2]; + fout[55] = conformal_shift_der[0][0]; + fout[56] = conformal_shift_der[0][1]; + fout[57] = conformal_shift_der[0][2]; + fout[58] = conformal_shift_der[1][0]; + fout[59] = conformal_shift_der[1][1]; + fout[60] = conformal_shift_der[1][2]; + fout[61] = conformal_shift_der[2][0]; + fout[62] = conformal_shift_der[2][1]; + fout[63] = conformal_shift_der[2][2]; // Set BSSN conformal factor. fout[64] = bssn_conformal_fact; // Set BSSN conformal factor first derivatives. - fout[65] = bssn_conformal_fact_der[0]; fout[66] = bssn_conformal_fact_der[1]; fout[67] = bssn_conformal_fact_der[2]; + fout[65] = bssn_conformal_fact_der[0]; + fout[66] = bssn_conformal_fact_der[1]; + fout[67] = bssn_conformal_fact_der[2]; // Set BSSN conformal factor second derivatives. - fout[68] = bssn_conformal_fact_der2[0][0]; fout[69] = bssn_conformal_fact_der2[0][1]; fout[70] = bssn_conformal_fact_der2[0][2]; - fout[71] = bssn_conformal_fact_der2[1][0]; fout[72] = bssn_conformal_fact_der2[1][1]; fout[73] = bssn_conformal_fact_der2[1][2]; - fout[74] = bssn_conformal_fact_der2[2][0]; fout[75] = bssn_conformal_fact_der2[2][1]; fout[76] = bssn_conformal_fact_der2[2][2]; + fout[68] = bssn_conformal_fact_der2[0][0]; + fout[69] = bssn_conformal_fact_der2[0][1]; + fout[70] = bssn_conformal_fact_der2[0][2]; + fout[71] = bssn_conformal_fact_der2[1][0]; + fout[72] = bssn_conformal_fact_der2[1][1]; + fout[73] = bssn_conformal_fact_der2[1][2]; + fout[74] = bssn_conformal_fact_der2[2][0]; + fout[75] = bssn_conformal_fact_der2[2][1]; + fout[76] = bssn_conformal_fact_der2[2][2]; if (in_excision_region) { for (int i = 0; i < 77; i++) { @@ -339,8 +430,7 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double gkyl_free(bssn_conformal_fact_der2); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -354,24 +444,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -386,17 +477,20 @@ main(int argc, char **argv) gkyl_mem_debug_set(true); } - struct einstein_conformal_gowdywave_ctx ctx = create_ctx(); // Context for initialization functions. + struct einstein_conformal_gowdywave_ctx ctx = + create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Conformal Einstein equations. - struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new(ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu); + struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new( + ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu + ); struct gkyl_moment_species einstein_conformal = { .name = "vacuum_einstein_conformal", .equation = vacuum_einstein_conformal, - + .init = evalVacuumEinsteinConformalInit, .force_low_order_flux = true, // Use Lax fluxes. .ctx = &ctx, @@ -404,7 +498,7 @@ main(int argc, char **argv) .has_vacuum_einstein_conformal = true, .vacuum_einstein_conformal_excision_threshold = ctx.excision_threshold, .vacuum_einstein_conformal_spacetime_slicing = ctx.spacetime_slicing, - .vacuum_einstein_conformal_spacetime_evolution = ctx.spacetime_evolution, + .vacuum_einstein_conformal_spacetime_evolution = ctx.spacetime_evolution }; int nrank = 1; // Number of processes in simulation. @@ -415,7 +509,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -423,8 +517,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -438,22 +531,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -478,9 +561,9 @@ main(int argc, char **argv) .name = "vacuum_einstein_conformal_gowdywave", .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -488,16 +571,12 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { einstein_conformal }, + .species = {einstein_conformal}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -509,10 +588,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -521,26 +604,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -556,7 +644,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -571,8 +659,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -580,7 +667,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -588,8 +677,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -616,14 +704,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(vacuum_einstein_conformal); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_vacuum_einstein_conformal_kerr.c b/moments/creg/rt_vacuum_einstein_conformal_kerr.c index 924a7a553f..40a8c4fcb9 100644 --- a/moments/creg/rt_vacuum_einstein_conformal_kerr.c +++ b/moments/creg/rt_vacuum_einstein_conformal_kerr.c @@ -19,8 +19,7 @@ #include -struct einstein_conformal_kerr_ctx -{ +struct einstein_conformal_kerr_ctx { // Spacetime parameters (using geometric units). double mass; // Mass of the black hole. double spin; // Spin of the black hole. @@ -52,8 +51,7 @@ struct einstein_conformal_kerr_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct einstein_conformal_kerr_ctx -create_ctx(void) +struct einstein_conformal_kerr_ctx create_ctx(void) { // Spacetime parameters (using geometric units). double mass = 0.5; // Mass of the black hole. @@ -62,14 +60,17 @@ create_ctx(void) double pos_x = 5.0; // Position of the black hole (x-direction). double pos_y = 5.0; // Position of the black hole (y-direction). double pos_z = 0.0; // Position of the black hole (z-direction). - + // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Evolution parameters. double excision_threshold = 0.3; // Excision threshold (lapse). - enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. - enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. + enum gkyl_spacetime_slicing spacetime_slicing = + GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. + enum gkyl_spacetime_evolution spacetime_evolution = + GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -105,14 +106,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVacuumEinsteinConformalInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct einstein_conformal_kerr_ctx *app = ctx; @@ -123,30 +125,30 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double double *conformal_shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *conformal_lapse_der = gkyl_malloc(sizeof(double[3])); - double **conformal_shift_der = gkyl_malloc(sizeof(double*[3])); + double **conformal_shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { conformal_spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -156,7 +158,7 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double double conformal_fact, bssn_conformal_fact; double *conformal_fact_der = gkyl_malloc(sizeof(double[3])); double *bssn_conformal_fact_der = gkyl_malloc(sizeof(double[3])); - double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_fact_der2[i] = gkyl_malloc(sizeof(double[3])); } @@ -165,21 +167,44 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &conformal_lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &conformal_shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &conformal_spatial_metric); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_conformal_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_extrinsic_curvature); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x, y, 0.0, &inv_conformal_spatial_metric + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_extrinsic_curvature + ); spacetime->conformal_factor_func(spacetime, 0.0, x, y, 0.0, &conformal_fact); spacetime->bssn_conformal_factor_func(spacetime, 0.0, x, y, 0.0, &bssn_conformal_fact); - spacetime->conformal_factor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_fact_der); - spacetime->bssn_conformal_factor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &bssn_conformal_fact_der); - spacetime->bssn_conformal_factor_der2_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &bssn_conformal_fact_der2); + spacetime->conformal_factor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_fact_der + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &bssn_conformal_fact_der + ); + spacetime->bssn_conformal_factor_der2_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &bssn_conformal_fact_der2 + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_spatial_metric_der + ); for (int i = 0; i < 3; i++) { conformal_fact_der[i] /= conformal_fact; @@ -191,14 +216,16 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double bssn_conformal_fact_der[i] = 0.0; for (int j = 0; j < 3; j++) { - bssn_conformal_fact_der2[i][j] = 0.0; + bssn_conformal_fact_der2[i][j] = 0.0; } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_spatial_metric[i][j] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - inv_conformal_spatial_metric[i][j] *= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric[i][j] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + inv_conformal_spatial_metric[i][j] *= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); } } @@ -206,8 +233,10 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der[i][j][k] = 0.5 * conformal_spatial_metric_der[i][j][k]; - conformal_spatial_metric_der[i][j][k] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_spatial_metric_der[i][j][k] -= 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; + conformal_spatial_metric_der[i][j][k] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric_der[i][j][k] -= + 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; } conformal_shift_der[i][j] = 0.5 * conformal_shift_der[i][j]; @@ -223,14 +252,15 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1[k][i][j] += inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; + conformal_spatial_metric_der_raised1[k][i][j] += + inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; } } } } - + double conformal_spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -238,7 +268,8 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double conformal_spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3[i][j][k] += inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; + conformal_spatial_metric_der_raised3[i][j][k] += + inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; } } } @@ -250,62 +281,112 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int s = 0; s < 3; s++) { conformal_aux_vect[i] += conformal_spatial_metric_der_raised3[i][s][s]; - conformal_aux_vect[i] -= conformal_spatial_metric_der_raised1[s][s][i]; + conformal_aux_vect[i] -= conformal_spatial_metric_der_raised1[s][s][i]; } conformal_aux_vect[i] -= 4.0 * conformal_fact_der[i]; } // Set conformal spatial metric tensor. - fout[0] = conformal_spatial_metric[0][0]; fout[1] = conformal_spatial_metric[0][1]; fout[2] = conformal_spatial_metric[0][2]; - fout[3] = conformal_spatial_metric[1][0]; fout[4] = conformal_spatial_metric[1][1]; fout[5] = conformal_spatial_metric[1][2]; - fout[6] = conformal_spatial_metric[2][0]; fout[7] = conformal_spatial_metric[2][1]; fout[8] = conformal_spatial_metric[2][2]; + fout[0] = conformal_spatial_metric[0][0]; + fout[1] = conformal_spatial_metric[0][1]; + fout[2] = conformal_spatial_metric[0][2]; + fout[3] = conformal_spatial_metric[1][0]; + fout[4] = conformal_spatial_metric[1][1]; + fout[5] = conformal_spatial_metric[1][2]; + fout[6] = conformal_spatial_metric[2][0]; + fout[7] = conformal_spatial_metric[2][1]; + fout[8] = conformal_spatial_metric[2][2]; // Set conformal lapse gauge variable. fout[9] = conformal_lapse; // Set conformal extrinsic curvature tensor. - fout[10] = conformal_extrinsic_curvature[0][0]; fout[11] = conformal_extrinsic_curvature[0][1]; fout[12] = conformal_extrinsic_curvature[0][2]; - fout[13] = conformal_extrinsic_curvature[1][0]; fout[14] = conformal_extrinsic_curvature[1][1]; fout[15] = conformal_extrinsic_curvature[1][2]; - fout[16] = conformal_extrinsic_curvature[2][0]; fout[17] = conformal_extrinsic_curvature[2][1]; fout[18] = conformal_extrinsic_curvature[2][2]; + fout[10] = conformal_extrinsic_curvature[0][0]; + fout[11] = conformal_extrinsic_curvature[0][1]; + fout[12] = conformal_extrinsic_curvature[0][2]; + fout[13] = conformal_extrinsic_curvature[1][0]; + fout[14] = conformal_extrinsic_curvature[1][1]; + fout[15] = conformal_extrinsic_curvature[1][2]; + fout[16] = conformal_extrinsic_curvature[2][0]; + fout[17] = conformal_extrinsic_curvature[2][1]; + fout[18] = conformal_extrinsic_curvature[2][2]; // Set conformal spatial metric tensor derivatives. - fout[19] = conformal_spatial_metric_der[0][0][0]; fout[20] = conformal_spatial_metric_der[0][0][1]; fout[21] = conformal_spatial_metric_der[0][0][2]; - fout[22] = conformal_spatial_metric_der[0][1][0]; fout[23] = conformal_spatial_metric_der[0][1][1]; fout[24] = conformal_spatial_metric_der[0][1][2]; - fout[25] = conformal_spatial_metric_der[0][2][0]; fout[26] = conformal_spatial_metric_der[0][2][1]; fout[27] = conformal_spatial_metric_der[0][2][2]; - - fout[28] = conformal_spatial_metric_der[1][0][0]; fout[29] = conformal_spatial_metric_der[1][0][1]; fout[30] = conformal_spatial_metric_der[1][0][2]; - fout[31] = conformal_spatial_metric_der[1][1][0]; fout[32] = conformal_spatial_metric_der[1][1][1]; fout[33] = conformal_spatial_metric_der[1][1][2]; - fout[34] = conformal_spatial_metric_der[1][2][0]; fout[35] = conformal_spatial_metric_der[1][2][1]; fout[36] = conformal_spatial_metric_der[1][2][2]; - - fout[37] = conformal_spatial_metric_der[2][0][0]; fout[38] = conformal_spatial_metric_der[2][0][1]; fout[39] = conformal_spatial_metric_der[2][0][2]; - fout[40] = conformal_spatial_metric_der[2][1][0]; fout[41] = conformal_spatial_metric_der[2][1][1]; fout[42] = conformal_spatial_metric_der[2][1][2]; - fout[43] = conformal_spatial_metric_der[2][2][0]; fout[44] = conformal_spatial_metric_der[2][2][1]; fout[45] = conformal_spatial_metric_der[2][2][2]; + fout[19] = conformal_spatial_metric_der[0][0][0]; + fout[20] = conformal_spatial_metric_der[0][0][1]; + fout[21] = conformal_spatial_metric_der[0][0][2]; + fout[22] = conformal_spatial_metric_der[0][1][0]; + fout[23] = conformal_spatial_metric_der[0][1][1]; + fout[24] = conformal_spatial_metric_der[0][1][2]; + fout[25] = conformal_spatial_metric_der[0][2][0]; + fout[26] = conformal_spatial_metric_der[0][2][1]; + fout[27] = conformal_spatial_metric_der[0][2][2]; + + fout[28] = conformal_spatial_metric_der[1][0][0]; + fout[29] = conformal_spatial_metric_der[1][0][1]; + fout[30] = conformal_spatial_metric_der[1][0][2]; + fout[31] = conformal_spatial_metric_der[1][1][0]; + fout[32] = conformal_spatial_metric_der[1][1][1]; + fout[33] = conformal_spatial_metric_der[1][1][2]; + fout[34] = conformal_spatial_metric_der[1][2][0]; + fout[35] = conformal_spatial_metric_der[1][2][1]; + fout[36] = conformal_spatial_metric_der[1][2][2]; + + fout[37] = conformal_spatial_metric_der[2][0][0]; + fout[38] = conformal_spatial_metric_der[2][0][1]; + fout[39] = conformal_spatial_metric_der[2][0][2]; + fout[40] = conformal_spatial_metric_der[2][1][0]; + fout[41] = conformal_spatial_metric_der[2][1][1]; + fout[42] = conformal_spatial_metric_der[2][1][2]; + fout[43] = conformal_spatial_metric_der[2][2][0]; + fout[44] = conformal_spatial_metric_der[2][2][1]; + fout[45] = conformal_spatial_metric_der[2][2][2]; // Set conformal lapse function derivatives. - fout[46] = conformal_lapse_der[0]; fout[47] = conformal_lapse_der[1]; fout[48] = conformal_lapse_der[2]; + fout[46] = conformal_lapse_der[0]; + fout[47] = conformal_lapse_der[1]; + fout[48] = conformal_lapse_der[2]; // Set conformal auxiliary vector. - fout[49] = conformal_aux_vect[0]; fout[50] = conformal_aux_vect[1]; fout[51] = conformal_aux_vect[2]; + fout[49] = conformal_aux_vect[0]; + fout[50] = conformal_aux_vect[1]; + fout[51] = conformal_aux_vect[2]; // Set conformal shift gauge variables. - fout[52] = conformal_shift[0]; fout[53] = conformal_shift[1]; fout[54] = conformal_shift[2]; + fout[52] = conformal_shift[0]; + fout[53] = conformal_shift[1]; + fout[54] = conformal_shift[2]; // Set conformal shift vector derivatives. - fout[55] = conformal_shift_der[0][0]; fout[56] = conformal_shift_der[0][1]; fout[57] = conformal_shift_der[0][2]; - fout[58] = conformal_shift_der[1][0]; fout[59] = conformal_shift_der[1][1]; fout[60] = conformal_shift_der[1][2]; - fout[61] = conformal_shift_der[2][0]; fout[62] = conformal_shift_der[2][1]; fout[63] = conformal_shift_der[2][2]; + fout[55] = conformal_shift_der[0][0]; + fout[56] = conformal_shift_der[0][1]; + fout[57] = conformal_shift_der[0][2]; + fout[58] = conformal_shift_der[1][0]; + fout[59] = conformal_shift_der[1][1]; + fout[60] = conformal_shift_der[1][2]; + fout[61] = conformal_shift_der[2][0]; + fout[62] = conformal_shift_der[2][1]; + fout[63] = conformal_shift_der[2][2]; // Set BSSN conformal factor. fout[64] = bssn_conformal_fact; // Set BSSN conformal factor first derivatives. - fout[65] = bssn_conformal_fact_der[0]; fout[66] = bssn_conformal_fact_der[1]; fout[67] = bssn_conformal_fact_der[2]; + fout[65] = bssn_conformal_fact_der[0]; + fout[66] = bssn_conformal_fact_der[1]; + fout[67] = bssn_conformal_fact_der[2]; // Set BSSN conformal factor second derivatives. - fout[68] = bssn_conformal_fact_der2[0][0]; fout[69] = bssn_conformal_fact_der2[0][1]; fout[70] = bssn_conformal_fact_der2[0][2]; - fout[71] = bssn_conformal_fact_der2[1][0]; fout[72] = bssn_conformal_fact_der2[1][1]; fout[73] = bssn_conformal_fact_der2[1][2]; - fout[74] = bssn_conformal_fact_der2[2][0]; fout[75] = bssn_conformal_fact_der2[2][1]; fout[76] = bssn_conformal_fact_der2[2][2]; + fout[68] = bssn_conformal_fact_der2[0][0]; + fout[69] = bssn_conformal_fact_der2[0][1]; + fout[70] = bssn_conformal_fact_der2[0][2]; + fout[71] = bssn_conformal_fact_der2[1][0]; + fout[72] = bssn_conformal_fact_der2[1][1]; + fout[73] = bssn_conformal_fact_der2[1][2]; + fout[74] = bssn_conformal_fact_der2[2][0]; + fout[75] = bssn_conformal_fact_der2[2][1]; + fout[76] = bssn_conformal_fact_der2[2][2]; if (in_excision_region) { for (int i = 0; i < 77; i++) { @@ -338,8 +419,7 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double gkyl_free(bssn_conformal_fact_der2); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -353,24 +433,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -391,12 +472,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Conformal Einstein equations. - struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new(ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu); + struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new( + ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu + ); struct gkyl_moment_species einstein_conformal = { .name = "vacuum_einstein_conformal", .equation = vacuum_einstein_conformal, - + .init = evalVacuumEinsteinConformalInit, .force_low_order_flux = false, // Use HLL fluxes. .ctx = &ctx, @@ -406,8 +489,8 @@ main(int argc, char **argv) .vacuum_einstein_conformal_spacetime_slicing = ctx.spacetime_slicing, .vacuum_einstein_conformal_spacetime_evolution = ctx.spacetime_evolution, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -418,7 +501,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -426,8 +509,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -441,22 +523,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -481,9 +553,9 @@ main(int argc, char **argv) .name = "vacuum_einstein_conformal_kerr", .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -491,13 +563,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { einstein_conformal }, + .species = {einstein_conformal}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -509,10 +578,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -521,26 +594,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -556,7 +634,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -571,8 +649,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -580,7 +657,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -588,8 +667,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -616,14 +694,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(vacuum_einstein_conformal); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_vacuum_einstein_conformal_linearwave.c b/moments/creg/rt_vacuum_einstein_conformal_linearwave.c index 9978f51059..6cd42f823b 100644 --- a/moments/creg/rt_vacuum_einstein_conformal_linearwave.c +++ b/moments/creg/rt_vacuum_einstein_conformal_linearwave.c @@ -18,8 +18,7 @@ #include -struct einstein_conformal_linearwave_ctx -{ +struct einstein_conformal_linearwave_ctx { // Mathematical constants (dimensionless). double pi; @@ -47,8 +46,7 @@ struct einstein_conformal_linearwave_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct einstein_conformal_linearwave_ctx -create_ctx(void) +struct einstein_conformal_linearwave_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -61,8 +59,10 @@ create_ctx(void) // Evolution parameters. double excision_threshold = 0.3; // Excision threshold (lapse). - enum gkyl_spacetime_slicing spacetime_slicing = GKYL_HARMONIC_SLICING; // Spacetime slicing condition. - enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. + enum gkyl_spacetime_slicing spacetime_slicing = + GKYL_HARMONIC_SLICING; // Spacetime slicing condition. + enum gkyl_spacetime_evolution spacetime_evolution = + GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. // Simulation parameters. int Nx = 50; // Cell count (x-direction). @@ -91,14 +91,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVacuumEinsteinConformalInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct einstein_conformal_linearwave_ctx *app = ctx; @@ -111,30 +112,30 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double double *conformal_shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *conformal_lapse_der = gkyl_malloc(sizeof(double[3])); - double **conformal_shift_der = gkyl_malloc(sizeof(double*[3])); + double **conformal_shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { conformal_spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -144,7 +145,7 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double double conformal_fact, bssn_conformal_fact; double *conformal_fact_der = gkyl_malloc(sizeof(double[3])); double *bssn_conformal_fact_der = gkyl_malloc(sizeof(double[3])); - double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_fact_der2[i] = gkyl_malloc(sizeof(double[3])); } @@ -153,28 +154,47 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &conformal_lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &conformal_shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &conformal_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &conformal_extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &conformal_extrinsic_curvature + ); spacetime->conformal_factor_func(spacetime, 0.0, x, 0.0, 0.0, &conformal_fact); spacetime->bssn_conformal_factor_func(spacetime, 0.0, x, 0.0, 0.0, &bssn_conformal_fact); - spacetime->conformal_factor_der_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &conformal_fact_der); - spacetime->bssn_conformal_factor_der_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &bssn_conformal_fact_der); - spacetime->bssn_conformal_factor_der2_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &bssn_conformal_fact_der2); + spacetime->conformal_factor_der_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &conformal_fact_der + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &bssn_conformal_fact_der + ); + spacetime->bssn_conformal_factor_der2_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &bssn_conformal_fact_der2 + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_spatial_metric_der + ); double b = amp * sin(2.0 * pi * x); conformal_spatial_det = 1.0 - (b * b); conformal_fact = pow(conformal_spatial_det, 1.0 / 12.0); bssn_conformal_fact = 1.0 / (conformal_fact * conformal_fact); - conformal_spatial_metric[1][1] = (1.0 + b) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_spatial_metric[2][2] = (1.0 - b) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric[1][1] = + (1.0 + b) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric[2][2] = + (1.0 - b) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); conformal_extrinsic_curvature[1][1] = -amp * pi * cos(2.0 * pi * x); conformal_extrinsic_curvature[2][2] = amp * pi * cos(2.0 * pi * x); @@ -182,15 +202,21 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double conformal_spatial_metric_der[0][1][1] = 2.0 * amp * pi * cos(2.0 * pi * x); conformal_spatial_metric_der[0][2][2] = -2.0 * amp * pi * cos(2.0 * pi * x); - inv_conformal_spatial_metric[1][1] = (1.0 / (1.0 + b)) * (conformal_fact * conformal_fact * conformal_fact * conformal_fact);; - inv_conformal_spatial_metric[2][2] = (1.0 / (1.0 + b)) * (conformal_fact * conformal_fact * conformal_fact * conformal_fact);; + inv_conformal_spatial_metric[1][1] = + (1.0 / (1.0 + b)) * (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + ; + inv_conformal_spatial_metric[2][2] = + (1.0 / (1.0 + b)) * (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + ; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der[i][j][k] = 0.5 * conformal_spatial_metric_der[i][j][k]; - conformal_spatial_metric_der[i][j][k] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_spatial_metric_der[i][j][k] -= 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; + conformal_spatial_metric_der[i][j][k] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric_der[i][j][k] -= + 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; } conformal_shift_der[i][j] = 0.5 * conformal_shift_der[i][j]; @@ -206,14 +232,15 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1[k][i][j] += inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; + conformal_spatial_metric_der_raised1[k][i][j] += + inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; } } } } - + double conformal_spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -221,7 +248,8 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double conformal_spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3[i][j][k] += inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; + conformal_spatial_metric_der_raised3[i][j][k] += + inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; } } } @@ -233,62 +261,112 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int s = 0; s < 3; s++) { conformal_aux_vect[i] += conformal_spatial_metric_der_raised3[i][s][s]; - conformal_aux_vect[i] -= conformal_spatial_metric_der_raised1[s][s][i]; + conformal_aux_vect[i] -= conformal_spatial_metric_der_raised1[s][s][i]; } conformal_aux_vect[i] -= 4.0 * conformal_fact_der[i]; } // Set conformal spatial metric tensor. - fout[0] = conformal_spatial_metric[0][0]; fout[1] = conformal_spatial_metric[0][1]; fout[2] = conformal_spatial_metric[0][2]; - fout[3] = conformal_spatial_metric[1][0]; fout[4] = conformal_spatial_metric[1][1]; fout[5] = conformal_spatial_metric[1][2]; - fout[6] = conformal_spatial_metric[2][0]; fout[7] = conformal_spatial_metric[2][1]; fout[8] = conformal_spatial_metric[2][2]; + fout[0] = conformal_spatial_metric[0][0]; + fout[1] = conformal_spatial_metric[0][1]; + fout[2] = conformal_spatial_metric[0][2]; + fout[3] = conformal_spatial_metric[1][0]; + fout[4] = conformal_spatial_metric[1][1]; + fout[5] = conformal_spatial_metric[1][2]; + fout[6] = conformal_spatial_metric[2][0]; + fout[7] = conformal_spatial_metric[2][1]; + fout[8] = conformal_spatial_metric[2][2]; // Set conformal lapse gauge variable. fout[9] = conformal_lapse; // Set conformal extrinsic curvature tensor. - fout[10] = conformal_extrinsic_curvature[0][0]; fout[11] = conformal_extrinsic_curvature[0][1]; fout[12] = conformal_extrinsic_curvature[0][2]; - fout[13] = conformal_extrinsic_curvature[1][0]; fout[14] = conformal_extrinsic_curvature[1][1]; fout[15] = conformal_extrinsic_curvature[1][2]; - fout[16] = conformal_extrinsic_curvature[2][0]; fout[17] = conformal_extrinsic_curvature[2][1]; fout[18] = conformal_extrinsic_curvature[2][2]; + fout[10] = conformal_extrinsic_curvature[0][0]; + fout[11] = conformal_extrinsic_curvature[0][1]; + fout[12] = conformal_extrinsic_curvature[0][2]; + fout[13] = conformal_extrinsic_curvature[1][0]; + fout[14] = conformal_extrinsic_curvature[1][1]; + fout[15] = conformal_extrinsic_curvature[1][2]; + fout[16] = conformal_extrinsic_curvature[2][0]; + fout[17] = conformal_extrinsic_curvature[2][1]; + fout[18] = conformal_extrinsic_curvature[2][2]; // Set conformal spatial metric tensor derivatives. - fout[19] = conformal_spatial_metric_der[0][0][0]; fout[20] = conformal_spatial_metric_der[0][0][1]; fout[21] = conformal_spatial_metric_der[0][0][2]; - fout[22] = conformal_spatial_metric_der[0][1][0]; fout[23] = conformal_spatial_metric_der[0][1][1]; fout[24] = conformal_spatial_metric_der[0][1][2]; - fout[25] = conformal_spatial_metric_der[0][2][0]; fout[26] = conformal_spatial_metric_der[0][2][1]; fout[27] = conformal_spatial_metric_der[0][2][2]; - - fout[28] = conformal_spatial_metric_der[1][0][0]; fout[29] = conformal_spatial_metric_der[1][0][1]; fout[30] = conformal_spatial_metric_der[1][0][2]; - fout[31] = conformal_spatial_metric_der[1][1][0]; fout[32] = conformal_spatial_metric_der[1][1][1]; fout[33] = conformal_spatial_metric_der[1][1][2]; - fout[34] = conformal_spatial_metric_der[1][2][0]; fout[35] = conformal_spatial_metric_der[1][2][1]; fout[36] = conformal_spatial_metric_der[1][2][2]; - - fout[37] = conformal_spatial_metric_der[2][0][0]; fout[38] = conformal_spatial_metric_der[2][0][1]; fout[39] = conformal_spatial_metric_der[2][0][2]; - fout[40] = conformal_spatial_metric_der[2][1][0]; fout[41] = conformal_spatial_metric_der[2][1][1]; fout[42] = conformal_spatial_metric_der[2][1][2]; - fout[43] = conformal_spatial_metric_der[2][2][0]; fout[44] = conformal_spatial_metric_der[2][2][1]; fout[45] = conformal_spatial_metric_der[2][2][2]; + fout[19] = conformal_spatial_metric_der[0][0][0]; + fout[20] = conformal_spatial_metric_der[0][0][1]; + fout[21] = conformal_spatial_metric_der[0][0][2]; + fout[22] = conformal_spatial_metric_der[0][1][0]; + fout[23] = conformal_spatial_metric_der[0][1][1]; + fout[24] = conformal_spatial_metric_der[0][1][2]; + fout[25] = conformal_spatial_metric_der[0][2][0]; + fout[26] = conformal_spatial_metric_der[0][2][1]; + fout[27] = conformal_spatial_metric_der[0][2][2]; + + fout[28] = conformal_spatial_metric_der[1][0][0]; + fout[29] = conformal_spatial_metric_der[1][0][1]; + fout[30] = conformal_spatial_metric_der[1][0][2]; + fout[31] = conformal_spatial_metric_der[1][1][0]; + fout[32] = conformal_spatial_metric_der[1][1][1]; + fout[33] = conformal_spatial_metric_der[1][1][2]; + fout[34] = conformal_spatial_metric_der[1][2][0]; + fout[35] = conformal_spatial_metric_der[1][2][1]; + fout[36] = conformal_spatial_metric_der[1][2][2]; + + fout[37] = conformal_spatial_metric_der[2][0][0]; + fout[38] = conformal_spatial_metric_der[2][0][1]; + fout[39] = conformal_spatial_metric_der[2][0][2]; + fout[40] = conformal_spatial_metric_der[2][1][0]; + fout[41] = conformal_spatial_metric_der[2][1][1]; + fout[42] = conformal_spatial_metric_der[2][1][2]; + fout[43] = conformal_spatial_metric_der[2][2][0]; + fout[44] = conformal_spatial_metric_der[2][2][1]; + fout[45] = conformal_spatial_metric_der[2][2][2]; // Set conformal lapse function derivatives. - fout[46] = conformal_lapse_der[0]; fout[47] = conformal_lapse_der[1]; fout[48] = conformal_lapse_der[2]; + fout[46] = conformal_lapse_der[0]; + fout[47] = conformal_lapse_der[1]; + fout[48] = conformal_lapse_der[2]; // Set conformal auxiliary vector. - fout[49] = conformal_aux_vect[0]; fout[50] = conformal_aux_vect[1]; fout[51] = conformal_aux_vect[2]; + fout[49] = conformal_aux_vect[0]; + fout[50] = conformal_aux_vect[1]; + fout[51] = conformal_aux_vect[2]; // Set conformal shift gauge variables. - fout[52] = conformal_shift[0]; fout[53] = conformal_shift[1]; fout[54] = conformal_shift[2]; + fout[52] = conformal_shift[0]; + fout[53] = conformal_shift[1]; + fout[54] = conformal_shift[2]; // Set conformal shift vector derivatives. - fout[55] = conformal_shift_der[0][0]; fout[56] = conformal_shift_der[0][1]; fout[57] = conformal_shift_der[0][2]; - fout[58] = conformal_shift_der[1][0]; fout[59] = conformal_shift_der[1][1]; fout[60] = conformal_shift_der[1][2]; - fout[61] = conformal_shift_der[2][0]; fout[62] = conformal_shift_der[2][1]; fout[63] = conformal_shift_der[2][2]; + fout[55] = conformal_shift_der[0][0]; + fout[56] = conformal_shift_der[0][1]; + fout[57] = conformal_shift_der[0][2]; + fout[58] = conformal_shift_der[1][0]; + fout[59] = conformal_shift_der[1][1]; + fout[60] = conformal_shift_der[1][2]; + fout[61] = conformal_shift_der[2][0]; + fout[62] = conformal_shift_der[2][1]; + fout[63] = conformal_shift_der[2][2]; // Set BSSN conformal factor. fout[64] = bssn_conformal_fact; // Set BSSN conformal factor first derivatives. - fout[65] = bssn_conformal_fact_der[0]; fout[66] = bssn_conformal_fact_der[1]; fout[67] = bssn_conformal_fact_der[2]; + fout[65] = bssn_conformal_fact_der[0]; + fout[66] = bssn_conformal_fact_der[1]; + fout[67] = bssn_conformal_fact_der[2]; // Set BSSN conformal factor second derivatives. - fout[68] = bssn_conformal_fact_der2[0][0]; fout[69] = bssn_conformal_fact_der2[0][1]; fout[70] = bssn_conformal_fact_der2[0][2]; - fout[71] = bssn_conformal_fact_der2[1][0]; fout[72] = bssn_conformal_fact_der2[1][1]; fout[73] = bssn_conformal_fact_der2[1][2]; - fout[74] = bssn_conformal_fact_der2[2][0]; fout[75] = bssn_conformal_fact_der2[2][1]; fout[76] = bssn_conformal_fact_der2[2][2]; + fout[68] = bssn_conformal_fact_der2[0][0]; + fout[69] = bssn_conformal_fact_der2[0][1]; + fout[70] = bssn_conformal_fact_der2[0][2]; + fout[71] = bssn_conformal_fact_der2[1][0]; + fout[72] = bssn_conformal_fact_der2[1][1]; + fout[73] = bssn_conformal_fact_der2[1][2]; + fout[74] = bssn_conformal_fact_der2[2][0]; + fout[75] = bssn_conformal_fact_der2[2][1]; + fout[76] = bssn_conformal_fact_der2[2][2]; if (in_excision_region) { for (int i = 0; i < 77; i++) { @@ -321,8 +399,7 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double gkyl_free(bssn_conformal_fact_der2); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -336,24 +413,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -368,17 +446,20 @@ main(int argc, char **argv) gkyl_mem_debug_set(true); } - struct einstein_conformal_linearwave_ctx ctx = create_ctx(); // Context for initialization functions. + struct einstein_conformal_linearwave_ctx ctx = + create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Conformal Einstein equations. - struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new(ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu); + struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new( + ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu + ); struct gkyl_moment_species einstein_conformal = { .name = "vacuum_einstein_conformal", .equation = vacuum_einstein_conformal, - + .init = evalVacuumEinsteinConformalInit, .force_low_order_flux = false, // Use HLL fluxes. .ctx = &ctx, @@ -386,7 +467,7 @@ main(int argc, char **argv) .has_vacuum_einstein_conformal = true, .vacuum_einstein_conformal_excision_threshold = ctx.excision_threshold, .vacuum_einstein_conformal_spacetime_slicing = ctx.spacetime_slicing, - .vacuum_einstein_conformal_spacetime_evolution = ctx.spacetime_evolution, + .vacuum_einstein_conformal_spacetime_evolution = ctx.spacetime_evolution }; int nrank = 1; // Number of processes in simulation. @@ -397,7 +478,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -405,8 +486,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -420,22 +500,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -460,9 +530,9 @@ main(int argc, char **argv) .name = "vacuum_einstein_conformal_linearwave", .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -470,16 +540,12 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { einstein_conformal }, + .species = {einstein_conformal}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -491,10 +557,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -503,26 +573,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -538,7 +613,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -553,8 +628,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -562,7 +636,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -570,8 +646,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -598,14 +673,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(vacuum_einstein_conformal); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_vacuum_einstein_conformal_schwarzschild.c b/moments/creg/rt_vacuum_einstein_conformal_schwarzschild.c index d4e42ccee2..a065b57d85 100644 --- a/moments/creg/rt_vacuum_einstein_conformal_schwarzschild.c +++ b/moments/creg/rt_vacuum_einstein_conformal_schwarzschild.c @@ -19,8 +19,7 @@ #include -struct einstein_conformal_schwarzschild_ctx -{ +struct einstein_conformal_schwarzschild_ctx { // Spacetime parameters (using geometric units). double mass; // Mass of the black hole. double spin; // Spin of the black hole. @@ -52,8 +51,7 @@ struct einstein_conformal_schwarzschild_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct einstein_conformal_schwarzschild_ctx -create_ctx(void) +struct einstein_conformal_schwarzschild_ctx create_ctx(void) { // Spacetime parameters (using geometric units). double mass = 0.5; // Mass of the black hole. @@ -62,14 +60,17 @@ create_ctx(void) double pos_x = 5.0; // Position of the black hole (x-direction). double pos_y = 5.0; // Position of the black hole (y-direction). double pos_z = 0.0; // Position of the black hole (z-direction). - + // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Evolution parameters. double excision_threshold = 0.3; // Excision threshold (lapse). - enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. - enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. + enum gkyl_spacetime_slicing spacetime_slicing = + GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. + enum gkyl_spacetime_evolution spacetime_evolution = + GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -105,14 +106,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVacuumEinsteinConformalInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct einstein_conformal_schwarzschild_ctx *app = ctx; @@ -123,30 +125,30 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double double *conformal_shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *conformal_lapse_der = gkyl_malloc(sizeof(double[3])); - double **conformal_shift_der = gkyl_malloc(sizeof(double*[3])); + double **conformal_shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { conformal_spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -156,7 +158,7 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double double conformal_fact, bssn_conformal_fact; double *conformal_fact_der = gkyl_malloc(sizeof(double[3])); double *bssn_conformal_fact_der = gkyl_malloc(sizeof(double[3])); - double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_fact_der2[i] = gkyl_malloc(sizeof(double[3])); } @@ -165,21 +167,44 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &conformal_lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &conformal_shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &conformal_spatial_metric); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_conformal_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_extrinsic_curvature); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x, y, 0.0, &inv_conformal_spatial_metric + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_extrinsic_curvature + ); spacetime->conformal_factor_func(spacetime, 0.0, x, y, 0.0, &conformal_fact); spacetime->bssn_conformal_factor_func(spacetime, 0.0, x, y, 0.0, &bssn_conformal_fact); - spacetime->conformal_factor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_fact_der); - spacetime->bssn_conformal_factor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &bssn_conformal_fact_der); - spacetime->bssn_conformal_factor_der2_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &bssn_conformal_fact_der2); + spacetime->conformal_factor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_fact_der + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &bssn_conformal_fact_der + ); + spacetime->bssn_conformal_factor_der2_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &bssn_conformal_fact_der2 + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_spatial_metric_der + ); for (int i = 0; i < 3; i++) { conformal_fact_der[i] /= conformal_fact; @@ -191,14 +216,16 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double bssn_conformal_fact_der[i] = 0.0; for (int j = 0; j < 3; j++) { - bssn_conformal_fact_der2[i][j] = 0.0; + bssn_conformal_fact_der2[i][j] = 0.0; } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_spatial_metric[i][j] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - inv_conformal_spatial_metric[i][j] *= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric[i][j] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + inv_conformal_spatial_metric[i][j] *= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); } } @@ -206,8 +233,10 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der[i][j][k] = 0.5 * conformal_spatial_metric_der[i][j][k]; - conformal_spatial_metric_der[i][j][k] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_spatial_metric_der[i][j][k] -= 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; + conformal_spatial_metric_der[i][j][k] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric_der[i][j][k] -= + 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; } conformal_shift_der[i][j] = 0.5 * conformal_shift_der[i][j]; @@ -223,14 +252,15 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1[k][i][j] += inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; + conformal_spatial_metric_der_raised1[k][i][j] += + inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; } } } } - + double conformal_spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -238,7 +268,8 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double conformal_spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3[i][j][k] += inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; + conformal_spatial_metric_der_raised3[i][j][k] += + inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; } } } @@ -250,62 +281,112 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double for (int s = 0; s < 3; s++) { conformal_aux_vect[i] += conformal_spatial_metric_der_raised3[i][s][s]; - conformal_aux_vect[i] -= conformal_spatial_metric_der_raised1[s][s][i]; + conformal_aux_vect[i] -= conformal_spatial_metric_der_raised1[s][s][i]; } conformal_aux_vect[i] -= 4.0 * conformal_fact_der[i]; } // Set conformal spatial metric tensor. - fout[0] = conformal_spatial_metric[0][0]; fout[1] = conformal_spatial_metric[0][1]; fout[2] = conformal_spatial_metric[0][2]; - fout[3] = conformal_spatial_metric[1][0]; fout[4] = conformal_spatial_metric[1][1]; fout[5] = conformal_spatial_metric[1][2]; - fout[6] = conformal_spatial_metric[2][0]; fout[7] = conformal_spatial_metric[2][1]; fout[8] = conformal_spatial_metric[2][2]; + fout[0] = conformal_spatial_metric[0][0]; + fout[1] = conformal_spatial_metric[0][1]; + fout[2] = conformal_spatial_metric[0][2]; + fout[3] = conformal_spatial_metric[1][0]; + fout[4] = conformal_spatial_metric[1][1]; + fout[5] = conformal_spatial_metric[1][2]; + fout[6] = conformal_spatial_metric[2][0]; + fout[7] = conformal_spatial_metric[2][1]; + fout[8] = conformal_spatial_metric[2][2]; // Set conformal lapse gauge variable. fout[9] = conformal_lapse; // Set conformal extrinsic curvature tensor. - fout[10] = conformal_extrinsic_curvature[0][0]; fout[11] = conformal_extrinsic_curvature[0][1]; fout[12] = conformal_extrinsic_curvature[0][2]; - fout[13] = conformal_extrinsic_curvature[1][0]; fout[14] = conformal_extrinsic_curvature[1][1]; fout[15] = conformal_extrinsic_curvature[1][2]; - fout[16] = conformal_extrinsic_curvature[2][0]; fout[17] = conformal_extrinsic_curvature[2][1]; fout[18] = conformal_extrinsic_curvature[2][2]; + fout[10] = conformal_extrinsic_curvature[0][0]; + fout[11] = conformal_extrinsic_curvature[0][1]; + fout[12] = conformal_extrinsic_curvature[0][2]; + fout[13] = conformal_extrinsic_curvature[1][0]; + fout[14] = conformal_extrinsic_curvature[1][1]; + fout[15] = conformal_extrinsic_curvature[1][2]; + fout[16] = conformal_extrinsic_curvature[2][0]; + fout[17] = conformal_extrinsic_curvature[2][1]; + fout[18] = conformal_extrinsic_curvature[2][2]; // Set conformal spatial metric tensor derivatives. - fout[19] = conformal_spatial_metric_der[0][0][0]; fout[20] = conformal_spatial_metric_der[0][0][1]; fout[21] = conformal_spatial_metric_der[0][0][2]; - fout[22] = conformal_spatial_metric_der[0][1][0]; fout[23] = conformal_spatial_metric_der[0][1][1]; fout[24] = conformal_spatial_metric_der[0][1][2]; - fout[25] = conformal_spatial_metric_der[0][2][0]; fout[26] = conformal_spatial_metric_der[0][2][1]; fout[27] = conformal_spatial_metric_der[0][2][2]; - - fout[28] = conformal_spatial_metric_der[1][0][0]; fout[29] = conformal_spatial_metric_der[1][0][1]; fout[30] = conformal_spatial_metric_der[1][0][2]; - fout[31] = conformal_spatial_metric_der[1][1][0]; fout[32] = conformal_spatial_metric_der[1][1][1]; fout[33] = conformal_spatial_metric_der[1][1][2]; - fout[34] = conformal_spatial_metric_der[1][2][0]; fout[35] = conformal_spatial_metric_der[1][2][1]; fout[36] = conformal_spatial_metric_der[1][2][2]; - - fout[37] = conformal_spatial_metric_der[2][0][0]; fout[38] = conformal_spatial_metric_der[2][0][1]; fout[39] = conformal_spatial_metric_der[2][0][2]; - fout[40] = conformal_spatial_metric_der[2][1][0]; fout[41] = conformal_spatial_metric_der[2][1][1]; fout[42] = conformal_spatial_metric_der[2][1][2]; - fout[43] = conformal_spatial_metric_der[2][2][0]; fout[44] = conformal_spatial_metric_der[2][2][1]; fout[45] = conformal_spatial_metric_der[2][2][2]; + fout[19] = conformal_spatial_metric_der[0][0][0]; + fout[20] = conformal_spatial_metric_der[0][0][1]; + fout[21] = conformal_spatial_metric_der[0][0][2]; + fout[22] = conformal_spatial_metric_der[0][1][0]; + fout[23] = conformal_spatial_metric_der[0][1][1]; + fout[24] = conformal_spatial_metric_der[0][1][2]; + fout[25] = conformal_spatial_metric_der[0][2][0]; + fout[26] = conformal_spatial_metric_der[0][2][1]; + fout[27] = conformal_spatial_metric_der[0][2][2]; + + fout[28] = conformal_spatial_metric_der[1][0][0]; + fout[29] = conformal_spatial_metric_der[1][0][1]; + fout[30] = conformal_spatial_metric_der[1][0][2]; + fout[31] = conformal_spatial_metric_der[1][1][0]; + fout[32] = conformal_spatial_metric_der[1][1][1]; + fout[33] = conformal_spatial_metric_der[1][1][2]; + fout[34] = conformal_spatial_metric_der[1][2][0]; + fout[35] = conformal_spatial_metric_der[1][2][1]; + fout[36] = conformal_spatial_metric_der[1][2][2]; + + fout[37] = conformal_spatial_metric_der[2][0][0]; + fout[38] = conformal_spatial_metric_der[2][0][1]; + fout[39] = conformal_spatial_metric_der[2][0][2]; + fout[40] = conformal_spatial_metric_der[2][1][0]; + fout[41] = conformal_spatial_metric_der[2][1][1]; + fout[42] = conformal_spatial_metric_der[2][1][2]; + fout[43] = conformal_spatial_metric_der[2][2][0]; + fout[44] = conformal_spatial_metric_der[2][2][1]; + fout[45] = conformal_spatial_metric_der[2][2][2]; // Set conformal lapse function derivatives. - fout[46] = conformal_lapse_der[0]; fout[47] = conformal_lapse_der[1]; fout[48] = conformal_lapse_der[2]; + fout[46] = conformal_lapse_der[0]; + fout[47] = conformal_lapse_der[1]; + fout[48] = conformal_lapse_der[2]; // Set conformal auxiliary vector. - fout[49] = conformal_aux_vect[0]; fout[50] = conformal_aux_vect[1]; fout[51] = conformal_aux_vect[2]; + fout[49] = conformal_aux_vect[0]; + fout[50] = conformal_aux_vect[1]; + fout[51] = conformal_aux_vect[2]; // Set conformal shift gauge variables. - fout[52] = conformal_shift[0]; fout[53] = conformal_shift[1]; fout[54] = conformal_shift[2]; + fout[52] = conformal_shift[0]; + fout[53] = conformal_shift[1]; + fout[54] = conformal_shift[2]; // Set conformal shift vector derivatives. - fout[55] = conformal_shift_der[0][0]; fout[56] = conformal_shift_der[0][1]; fout[57] = conformal_shift_der[0][2]; - fout[58] = conformal_shift_der[1][0]; fout[59] = conformal_shift_der[1][1]; fout[60] = conformal_shift_der[1][2]; - fout[61] = conformal_shift_der[2][0]; fout[62] = conformal_shift_der[2][1]; fout[63] = conformal_shift_der[2][2]; + fout[55] = conformal_shift_der[0][0]; + fout[56] = conformal_shift_der[0][1]; + fout[57] = conformal_shift_der[0][2]; + fout[58] = conformal_shift_der[1][0]; + fout[59] = conformal_shift_der[1][1]; + fout[60] = conformal_shift_der[1][2]; + fout[61] = conformal_shift_der[2][0]; + fout[62] = conformal_shift_der[2][1]; + fout[63] = conformal_shift_der[2][2]; // Set BSSN conformal factor. fout[64] = bssn_conformal_fact; // Set BSSN conformal factor first derivatives. - fout[65] = bssn_conformal_fact_der[0]; fout[66] = bssn_conformal_fact_der[1]; fout[67] = bssn_conformal_fact_der[2]; + fout[65] = bssn_conformal_fact_der[0]; + fout[66] = bssn_conformal_fact_der[1]; + fout[67] = bssn_conformal_fact_der[2]; // Set BSSN conformal factor second derivatives. - fout[68] = bssn_conformal_fact_der2[0][0]; fout[69] = bssn_conformal_fact_der2[0][1]; fout[70] = bssn_conformal_fact_der2[0][2]; - fout[71] = bssn_conformal_fact_der2[1][0]; fout[72] = bssn_conformal_fact_der2[1][1]; fout[73] = bssn_conformal_fact_der2[1][2]; - fout[74] = bssn_conformal_fact_der2[2][0]; fout[75] = bssn_conformal_fact_der2[2][1]; fout[76] = bssn_conformal_fact_der2[2][2]; + fout[68] = bssn_conformal_fact_der2[0][0]; + fout[69] = bssn_conformal_fact_der2[0][1]; + fout[70] = bssn_conformal_fact_der2[0][2]; + fout[71] = bssn_conformal_fact_der2[1][0]; + fout[72] = bssn_conformal_fact_der2[1][1]; + fout[73] = bssn_conformal_fact_der2[1][2]; + fout[74] = bssn_conformal_fact_der2[2][0]; + fout[75] = bssn_conformal_fact_der2[2][1]; + fout[76] = bssn_conformal_fact_der2[2][2]; if (in_excision_region) { for (int i = 0; i < 77; i++) { @@ -338,8 +419,7 @@ evalVacuumEinsteinConformalInit(double t, const double* GKYL_RESTRICT xn, double gkyl_free(bssn_conformal_fact_der2); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -353,24 +433,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -385,18 +466,21 @@ main(int argc, char **argv) gkyl_mem_debug_set(true); } - struct einstein_conformal_schwarzschild_ctx ctx = create_ctx(); // Context for initialization functions. + struct einstein_conformal_schwarzschild_ctx ctx = + create_ctx(); // Context for initialization functions. int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Conformal Einstein equations. - struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new(ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu); + struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new( + ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu + ); struct gkyl_moment_species einstein_conformal = { .name = "vacuum_einstein_conformal", .equation = vacuum_einstein_conformal, - + .init = evalVacuumEinsteinConformalInit, .force_low_order_flux = false, // Use HLL fluxes. .ctx = &ctx, @@ -406,8 +490,8 @@ main(int argc, char **argv) .vacuum_einstein_conformal_spacetime_slicing = ctx.spacetime_slicing, .vacuum_einstein_conformal_spacetime_evolution = ctx.spacetime_evolution, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -418,7 +502,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -426,8 +510,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -441,22 +524,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -481,9 +554,9 @@ main(int argc, char **argv) .name = "vacuum_einstein_conformal_schwarzschild", .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -491,13 +564,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { einstein_conformal }, + .species = {einstein_conformal}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -509,10 +579,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -521,26 +595,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -556,7 +635,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -571,8 +650,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -580,7 +658,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -588,8 +668,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -616,14 +695,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(vacuum_einstein_conformal); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_vacuum_einstein_gowdywave.c b/moments/creg/rt_vacuum_einstein_gowdywave.c index f844d0d568..ba6859228e 100644 --- a/moments/creg/rt_vacuum_einstein_gowdywave.c +++ b/moments/creg/rt_vacuum_einstein_gowdywave.c @@ -18,8 +18,7 @@ #include -struct einstein_gowdywave_ctx -{ +struct einstein_gowdywave_ctx { // Mathematical constants (dimensionless). double pi; @@ -47,8 +46,7 @@ struct einstein_gowdywave_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct einstein_gowdywave_ctx -create_ctx(void) +struct einstein_gowdywave_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -61,8 +59,10 @@ create_ctx(void) // Evolution parameters. double excision_threshold = 0.3; // Excision threshold (lapse). - enum gkyl_spacetime_slicing spacetime_slicing = GKYL_HARMONIC_SLICING; // Spacetime slicing condition. - enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. + enum gkyl_spacetime_slicing spacetime_slicing = + GKYL_HARMONIC_SLICING; // Spacetime slicing condition. + enum gkyl_spacetime_evolution spacetime_evolution = + GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. // Simulation parameters. int Nx = 50; // Cell count (x-direction). @@ -91,14 +91,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVacuumEinsteinInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct einstein_gowdywave_ctx *app = ctx; @@ -111,30 +112,30 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -145,21 +146,38 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); - double lambda = (-2.0 * pi * tau0 * jn(0, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0) * (cos(2.0 * pi * x) * cos(2.0 * pi * x))) - + (2.0 * (pi * pi) * (tau0 * tau0) * ((jn(0, 2.0 * pi * tau0) * jn(0, 2.0 * pi * tau0)) + (jn(1, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0)))) - - (0.5 * (((2.0 * pi) * (2.0 * pi)) * ((jn(0, 2.0 * pi) * jn(0, 2.0 * pi)) + (jn(1, 2.0 * pi) * jn(1, 2.0 * pi))))) - + (pi * jn(0, 2.0 * pi) * jn(1, 2.0 * pi)); - double lambda_dt = 2.0 * (pi * pi) * tau0 * ((jn(1, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0)) * (1.0 + cos(4.0 * pi * x)) - + (2.0 * (jn(0, 2.0 * pi * tau0) * jn(0, 2.0 * pi * tau0)) * (sin(2.0 * pi * x) * sin(2.0 * pi * x)))); - double lambda_dx = 4.0 * (pi * pi * tau0) * jn(0, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0) * sin(4.0 * pi * x); + double lambda = (-2.0 * pi * tau0 * jn(0, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0) * + (cos(2.0 * pi * x) * cos(2.0 * pi * x))) + + (2.0 * (pi * pi) * (tau0 * tau0) * + ((jn(0, 2.0 * pi * tau0) * jn(0, 2.0 * pi * tau0)) + + (jn(1, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0)))) - + (0.5 * (((2.0 * pi) * (2.0 * pi)) * ((jn(0, 2.0 * pi) * jn(0, 2.0 * pi)) + + (jn(1, 2.0 * pi) * jn(1, 2.0 * pi))))) + + (pi * jn(0, 2.0 * pi) * jn(1, 2.0 * pi)); + double lambda_dt = + 2.0 * (pi * pi) * tau0 * + ((jn(1, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0)) * (1.0 + cos(4.0 * pi * x)) + + (2.0 * (jn(0, 2.0 * pi * tau0) * jn(0, 2.0 * pi * tau0)) * + (sin(2.0 * pi * x) * sin(2.0 * pi * x)))); + double lambda_dx = + 4.0 * (pi * pi * tau0) * jn(0, 2.0 * pi * tau0) * jn(1, 2.0 * pi * tau0) * sin(4.0 * pi * x); double P = jn(0, 2.0 * pi * tau0) * cos(2.0 * pi * x); double P_dt = -2.0 * pi * jn(1, 2.0 * pi * tau0) * cos(2.0 * pi * x); @@ -172,9 +190,12 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE lapse = (1.0 / pow(tau0, 0.25)) * exp(0.25 * lambda); lapse_der[0] = (exp(0.25 * lambda) * lambda_dx) / (4.0 * pow(tau0, 0.25)); - extrinsic_curvature[0][0] = 0.25 * (1.0 / pow(tau0, 0.25)) * exp(0.25 * lambda) * ((1.0 / tau0) - lambda_dt); - extrinsic_curvature[1][1] = -0.5 * pow(tau0, 0.25) * exp(-0.25 * lambda) * exp(P) * (1.0 + (tau0 * P_dt)); - extrinsic_curvature[2][2] = -0.5 * pow(tau0, 0.25) * exp(-0.25 * lambda) * exp(-P) * (1.0 - (tau0 * P_dt)); + extrinsic_curvature[0][0] = + 0.25 * (1.0 / pow(tau0, 0.25)) * exp(0.25 * lambda) * ((1.0 / tau0) - lambda_dt); + extrinsic_curvature[1][1] = + -0.5 * pow(tau0, 0.25) * exp(-0.25 * lambda) * exp(P) * (1.0 + (tau0 * P_dt)); + extrinsic_curvature[2][2] = + -0.5 * pow(tau0, 0.25) * exp(-0.25 * lambda) * exp(-P) * (1.0 - (tau0 * P_dt)); spatial_metric_der[0][0][0] = (exp(0.25 * lambda) * lambda_dx) / (2.0 * sqrt(tau0)); spatial_metric_der[0][1][1] = exp(P) * tau0 * P_dx; @@ -204,14 +225,15 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1[k][i][j] += inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; + spatial_metric_der_raised1[k][i][j] += + inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; } } } } - + double spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -219,7 +241,8 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3[i][j][k] += inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; + spatial_metric_der_raised3[i][j][k] += + inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; } } } @@ -231,49 +254,91 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE for (int s = 0; s < 3; s++) { aux_vect[i] += spatial_metric_der_raised3[i][s][s]; - aux_vect[i] -= spatial_metric_der_raised1[s][s][i]; + aux_vect[i] -= spatial_metric_der_raised1[s][s][i]; } } // Set spatial metric tensor. - fout[0] = spatial_metric[0][0]; fout[1] = spatial_metric[0][1]; fout[2] = spatial_metric[0][2]; - fout[3] = spatial_metric[1][0]; fout[4] = spatial_metric[1][1]; fout[5] = spatial_metric[1][2]; - fout[6] = spatial_metric[2][0]; fout[7] = spatial_metric[2][1]; fout[8] = spatial_metric[2][2]; + fout[0] = spatial_metric[0][0]; + fout[1] = spatial_metric[0][1]; + fout[2] = spatial_metric[0][2]; + fout[3] = spatial_metric[1][0]; + fout[4] = spatial_metric[1][1]; + fout[5] = spatial_metric[1][2]; + fout[6] = spatial_metric[2][0]; + fout[7] = spatial_metric[2][1]; + fout[8] = spatial_metric[2][2]; // Set lapse gauge variable. fout[9] = lapse; // Set extrinsic curvature tensor. - fout[10] = extrinsic_curvature[0][0]; fout[11] = extrinsic_curvature[0][1]; fout[12] = extrinsic_curvature[0][2]; - fout[13] = extrinsic_curvature[1][0]; fout[14] = extrinsic_curvature[1][1]; fout[15] = extrinsic_curvature[1][2]; - fout[16] = extrinsic_curvature[2][0]; fout[17] = extrinsic_curvature[2][1]; fout[18] = extrinsic_curvature[2][2]; + fout[10] = extrinsic_curvature[0][0]; + fout[11] = extrinsic_curvature[0][1]; + fout[12] = extrinsic_curvature[0][2]; + fout[13] = extrinsic_curvature[1][0]; + fout[14] = extrinsic_curvature[1][1]; + fout[15] = extrinsic_curvature[1][2]; + fout[16] = extrinsic_curvature[2][0]; + fout[17] = extrinsic_curvature[2][1]; + fout[18] = extrinsic_curvature[2][2]; // Set spatial metric tensor derivatives. - fout[19] = spatial_metric_der[0][0][0]; fout[20] = spatial_metric_der[0][0][1]; fout[21] = spatial_metric_der[0][0][2]; - fout[22] = spatial_metric_der[0][1][0]; fout[23] = spatial_metric_der[0][1][1]; fout[24] = spatial_metric_der[0][1][2]; - fout[25] = spatial_metric_der[0][2][0]; fout[26] = spatial_metric_der[0][2][1]; fout[27] = spatial_metric_der[0][2][2]; - - fout[28] = spatial_metric_der[1][0][0]; fout[29] = spatial_metric_der[1][0][1]; fout[30] = spatial_metric_der[1][0][2]; - fout[31] = spatial_metric_der[1][1][0]; fout[32] = spatial_metric_der[1][1][1]; fout[33] = spatial_metric_der[1][1][2]; - fout[34] = spatial_metric_der[1][2][0]; fout[35] = spatial_metric_der[1][2][1]; fout[36] = spatial_metric_der[1][2][2]; - - fout[37] = spatial_metric_der[2][0][0]; fout[38] = spatial_metric_der[2][0][1]; fout[39] = spatial_metric_der[2][0][2]; - fout[40] = spatial_metric_der[2][1][0]; fout[41] = spatial_metric_der[2][1][1]; fout[42] = spatial_metric_der[2][1][2]; - fout[43] = spatial_metric_der[2][2][0]; fout[44] = spatial_metric_der[2][2][1]; fout[45] = spatial_metric_der[2][2][2]; + fout[19] = spatial_metric_der[0][0][0]; + fout[20] = spatial_metric_der[0][0][1]; + fout[21] = spatial_metric_der[0][0][2]; + fout[22] = spatial_metric_der[0][1][0]; + fout[23] = spatial_metric_der[0][1][1]; + fout[24] = spatial_metric_der[0][1][2]; + fout[25] = spatial_metric_der[0][2][0]; + fout[26] = spatial_metric_der[0][2][1]; + fout[27] = spatial_metric_der[0][2][2]; + + fout[28] = spatial_metric_der[1][0][0]; + fout[29] = spatial_metric_der[1][0][1]; + fout[30] = spatial_metric_der[1][0][2]; + fout[31] = spatial_metric_der[1][1][0]; + fout[32] = spatial_metric_der[1][1][1]; + fout[33] = spatial_metric_der[1][1][2]; + fout[34] = spatial_metric_der[1][2][0]; + fout[35] = spatial_metric_der[1][2][1]; + fout[36] = spatial_metric_der[1][2][2]; + + fout[37] = spatial_metric_der[2][0][0]; + fout[38] = spatial_metric_der[2][0][1]; + fout[39] = spatial_metric_der[2][0][2]; + fout[40] = spatial_metric_der[2][1][0]; + fout[41] = spatial_metric_der[2][1][1]; + fout[42] = spatial_metric_der[2][1][2]; + fout[43] = spatial_metric_der[2][2][0]; + fout[44] = spatial_metric_der[2][2][1]; + fout[45] = spatial_metric_der[2][2][2]; // Set lapse function derivatives. - fout[46] = lapse_der[0]; fout[47] = lapse_der[1]; fout[48] = lapse_der[2]; + fout[46] = lapse_der[0]; + fout[47] = lapse_der[1]; + fout[48] = lapse_der[2]; // Set auxiliary vector. - fout[49] = aux_vect[0]; fout[50] = aux_vect[1]; fout[51] = aux_vect[2]; + fout[49] = aux_vect[0]; + fout[50] = aux_vect[1]; + fout[51] = aux_vect[2]; // Set shift gauge variables. - fout[52] = shift[0]; fout[53] = shift[1]; fout[54] = shift[2]; + fout[52] = shift[0]; + fout[53] = shift[1]; + fout[54] = shift[2]; // Set shift vector derivatives. - fout[55] = shift_der[0][0]; fout[56] = shift_der[0][1]; fout[57] = shift_der[0][2]; - fout[58] = shift_der[1][0]; fout[59] = shift_der[1][1]; fout[60] = shift_der[1][2]; - fout[61] = shift_der[2][0]; fout[62] = shift_der[2][1]; fout[63] = shift_der[2][2]; + fout[55] = shift_der[0][0]; + fout[56] = shift_der[0][1]; + fout[57] = shift_der[0][2]; + fout[58] = shift_der[1][0]; + fout[59] = shift_der[1][1]; + fout[60] = shift_der[1][2]; + fout[61] = shift_der[2][0]; + fout[62] = shift_der[2][1]; + fout[63] = shift_der[2][2]; if (in_excision_region) { for (int i = 0; i < 64; i++) { @@ -302,8 +367,7 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -317,24 +381,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -354,12 +419,14 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Einstein equations. - struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new(ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu); + struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new( + ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu + ); struct gkyl_moment_species einstein = { .name = "vacuum_einstein", .equation = vacuum_einstein, - + .init = evalVacuumEinsteinInit, .force_low_order_flux = false, // Use HLL fluxes. .ctx = &ctx, @@ -367,7 +434,7 @@ main(int argc, char **argv) .has_vacuum_einstein = true, .vacuum_einstein_excision_threshold = ctx.excision_threshold, .vacuum_einstein_spacetime_slicing = ctx.spacetime_slicing, - .vacuum_einstein_spacetime_evolution = ctx.spacetime_evolution, + .vacuum_einstein_spacetime_evolution = ctx.spacetime_evolution }; int nrank = 1; // Number of processes in simulation. @@ -378,7 +445,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -386,8 +453,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -401,22 +467,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -441,9 +497,9 @@ main(int argc, char **argv) .name = "vacuum_einstein_gowdywave", .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -451,16 +507,12 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { einstein }, + .species = {einstein}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -472,10 +524,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -484,26 +540,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -519,7 +580,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -534,8 +595,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -543,7 +603,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -551,8 +613,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -579,14 +640,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(vacuum_einstein); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_vacuum_einstein_kerr.c b/moments/creg/rt_vacuum_einstein_kerr.c index 6ecbfc798a..065fde2046 100644 --- a/moments/creg/rt_vacuum_einstein_kerr.c +++ b/moments/creg/rt_vacuum_einstein_kerr.c @@ -19,8 +19,7 @@ #include -struct einstein_kerr_ctx -{ +struct einstein_kerr_ctx { // Spacetime parameters (using geometric units). double mass; // Mass of the black hole. double spin; // Spin of the black hole. @@ -52,8 +51,7 @@ struct einstein_kerr_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct einstein_kerr_ctx -create_ctx(void) +struct einstein_kerr_ctx create_ctx(void) { // Spacetime parameters (using geometric units). double mass = 0.5; // Mass of the black hole. @@ -64,12 +62,15 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Evolution parameters. double excision_threshold = 0.3; // Excision threshold (lapse). - enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. - enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. + enum gkyl_spacetime_slicing spacetime_slicing = + GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. + enum gkyl_spacetime_evolution spacetime_evolution = + GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -105,14 +106,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVacuumEinsteinInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct einstein_kerr_ctx *app = ctx; @@ -123,30 +125,30 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -157,14 +159,24 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -185,14 +197,15 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1[k][i][j] += inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; + spatial_metric_der_raised1[k][i][j] += + inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; } } } } - + double spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -200,7 +213,8 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3[i][j][k] += inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; + spatial_metric_der_raised3[i][j][k] += + inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; } } } @@ -212,49 +226,91 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE for (int s = 0; s < 3; s++) { aux_vect[i] += spatial_metric_der_raised3[i][s][s]; - aux_vect[i] -= spatial_metric_der_raised1[s][s][i]; + aux_vect[i] -= spatial_metric_der_raised1[s][s][i]; } } // Set spatial metric tensor. - fout[0] = spatial_metric[0][0]; fout[1] = spatial_metric[0][1]; fout[2] = spatial_metric[0][2]; - fout[3] = spatial_metric[1][0]; fout[4] = spatial_metric[1][1]; fout[5] = spatial_metric[1][2]; - fout[6] = spatial_metric[2][0]; fout[7] = spatial_metric[2][1]; fout[8] = spatial_metric[2][2]; + fout[0] = spatial_metric[0][0]; + fout[1] = spatial_metric[0][1]; + fout[2] = spatial_metric[0][2]; + fout[3] = spatial_metric[1][0]; + fout[4] = spatial_metric[1][1]; + fout[5] = spatial_metric[1][2]; + fout[6] = spatial_metric[2][0]; + fout[7] = spatial_metric[2][1]; + fout[8] = spatial_metric[2][2]; // Set lapse gauge variable. fout[9] = lapse; // Set extrinsic curvature tensor. - fout[10] = extrinsic_curvature[0][0]; fout[11] = extrinsic_curvature[0][1]; fout[12] = extrinsic_curvature[0][2]; - fout[13] = extrinsic_curvature[1][0]; fout[14] = extrinsic_curvature[1][1]; fout[15] = extrinsic_curvature[1][2]; - fout[16] = extrinsic_curvature[2][0]; fout[17] = extrinsic_curvature[2][1]; fout[18] = extrinsic_curvature[2][2]; + fout[10] = extrinsic_curvature[0][0]; + fout[11] = extrinsic_curvature[0][1]; + fout[12] = extrinsic_curvature[0][2]; + fout[13] = extrinsic_curvature[1][0]; + fout[14] = extrinsic_curvature[1][1]; + fout[15] = extrinsic_curvature[1][2]; + fout[16] = extrinsic_curvature[2][0]; + fout[17] = extrinsic_curvature[2][1]; + fout[18] = extrinsic_curvature[2][2]; // Set spatial metric tensor derivatives. - fout[19] = spatial_metric_der[0][0][0]; fout[20] = spatial_metric_der[0][0][1]; fout[21] = spatial_metric_der[0][0][2]; - fout[22] = spatial_metric_der[0][1][0]; fout[23] = spatial_metric_der[0][1][1]; fout[24] = spatial_metric_der[0][1][2]; - fout[25] = spatial_metric_der[0][2][0]; fout[26] = spatial_metric_der[0][2][1]; fout[27] = spatial_metric_der[0][2][2]; - - fout[28] = spatial_metric_der[1][0][0]; fout[29] = spatial_metric_der[1][0][1]; fout[30] = spatial_metric_der[1][0][2]; - fout[31] = spatial_metric_der[1][1][0]; fout[32] = spatial_metric_der[1][1][1]; fout[33] = spatial_metric_der[1][1][2]; - fout[34] = spatial_metric_der[1][2][0]; fout[35] = spatial_metric_der[1][2][1]; fout[36] = spatial_metric_der[1][2][2]; - - fout[37] = spatial_metric_der[2][0][0]; fout[38] = spatial_metric_der[2][0][1]; fout[39] = spatial_metric_der[2][0][2]; - fout[40] = spatial_metric_der[2][1][0]; fout[41] = spatial_metric_der[2][1][1]; fout[42] = spatial_metric_der[2][1][2]; - fout[43] = spatial_metric_der[2][2][0]; fout[44] = spatial_metric_der[2][2][1]; fout[45] = spatial_metric_der[2][2][2]; + fout[19] = spatial_metric_der[0][0][0]; + fout[20] = spatial_metric_der[0][0][1]; + fout[21] = spatial_metric_der[0][0][2]; + fout[22] = spatial_metric_der[0][1][0]; + fout[23] = spatial_metric_der[0][1][1]; + fout[24] = spatial_metric_der[0][1][2]; + fout[25] = spatial_metric_der[0][2][0]; + fout[26] = spatial_metric_der[0][2][1]; + fout[27] = spatial_metric_der[0][2][2]; + + fout[28] = spatial_metric_der[1][0][0]; + fout[29] = spatial_metric_der[1][0][1]; + fout[30] = spatial_metric_der[1][0][2]; + fout[31] = spatial_metric_der[1][1][0]; + fout[32] = spatial_metric_der[1][1][1]; + fout[33] = spatial_metric_der[1][1][2]; + fout[34] = spatial_metric_der[1][2][0]; + fout[35] = spatial_metric_der[1][2][1]; + fout[36] = spatial_metric_der[1][2][2]; + + fout[37] = spatial_metric_der[2][0][0]; + fout[38] = spatial_metric_der[2][0][1]; + fout[39] = spatial_metric_der[2][0][2]; + fout[40] = spatial_metric_der[2][1][0]; + fout[41] = spatial_metric_der[2][1][1]; + fout[42] = spatial_metric_der[2][1][2]; + fout[43] = spatial_metric_der[2][2][0]; + fout[44] = spatial_metric_der[2][2][1]; + fout[45] = spatial_metric_der[2][2][2]; // Set lapse function derivatives. - fout[46] = lapse_der[0]; fout[47] = lapse_der[1]; fout[48] = lapse_der[2]; + fout[46] = lapse_der[0]; + fout[47] = lapse_der[1]; + fout[48] = lapse_der[2]; // Set auxiliary vector. - fout[49] = aux_vect[0]; fout[50] = aux_vect[1]; fout[51] = aux_vect[2]; + fout[49] = aux_vect[0]; + fout[50] = aux_vect[1]; + fout[51] = aux_vect[2]; // Set shift gauge variables. - fout[52] = shift[0]; fout[53] = shift[1]; fout[54] = shift[2]; + fout[52] = shift[0]; + fout[53] = shift[1]; + fout[54] = shift[2]; // Set shift vector derivatives. - fout[55] = shift_der[0][0]; fout[56] = shift_der[0][1]; fout[57] = shift_der[0][2]; - fout[58] = shift_der[1][0]; fout[59] = shift_der[1][1]; fout[60] = shift_der[1][2]; - fout[61] = shift_der[2][0]; fout[62] = shift_der[2][1]; fout[63] = shift_der[2][2]; + fout[55] = shift_der[0][0]; + fout[56] = shift_der[0][1]; + fout[57] = shift_der[0][2]; + fout[58] = shift_der[1][0]; + fout[59] = shift_der[1][1]; + fout[60] = shift_der[1][2]; + fout[61] = shift_der[2][0]; + fout[62] = shift_der[2][1]; + fout[63] = shift_der[2][2]; if (in_excision_region) { for (int i = 0; i < 64; i++) { @@ -283,8 +339,7 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -298,24 +353,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -336,12 +392,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Einstein equations. - struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new(ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu); + struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new( + ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu + ); struct gkyl_moment_species einstein = { .name = "vacuum_einstein", .equation = vacuum_einstein, - + .init = evalVacuumEinsteinInit, .force_low_order_flux = false, // Use HLL fluxes. .ctx = &ctx, @@ -351,8 +409,8 @@ main(int argc, char **argv) .vacuum_einstein_spacetime_slicing = ctx.spacetime_slicing, .vacuum_einstein_spacetime_evolution = ctx.spacetime_evolution, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -363,7 +421,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -371,8 +429,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -386,22 +443,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -426,9 +473,9 @@ main(int argc, char **argv) .name = "vacuum_einstein_kerr", .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -436,13 +483,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { einstein }, + .species = {einstein}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -454,10 +498,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -466,26 +514,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -501,7 +554,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -516,8 +569,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -525,7 +577,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -533,8 +587,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -561,14 +614,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(vacuum_einstein); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_vacuum_einstein_linearwave.c b/moments/creg/rt_vacuum_einstein_linearwave.c index f974b014ae..a71451f546 100644 --- a/moments/creg/rt_vacuum_einstein_linearwave.c +++ b/moments/creg/rt_vacuum_einstein_linearwave.c @@ -18,8 +18,7 @@ #include -struct einstein_linearwave_ctx -{ +struct einstein_linearwave_ctx { // Mathematical constants (dimensionless). double pi; @@ -47,8 +46,7 @@ struct einstein_linearwave_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct einstein_linearwave_ctx -create_ctx(void) +struct einstein_linearwave_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -61,8 +59,10 @@ create_ctx(void) // Evolution parameters. double excision_threshold = 0.3; // Excision threshold (lapse). - enum gkyl_spacetime_slicing spacetime_slicing = GKYL_HARMONIC_SLICING; // Spacetime slicing condition. - enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. + enum gkyl_spacetime_slicing spacetime_slicing = + GKYL_HARMONIC_SLICING; // Spacetime slicing condition. + enum gkyl_spacetime_evolution spacetime_evolution = + GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. // Simulation parameters. int Nx = 50; // Cell count (x-direction). @@ -91,14 +91,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVacuumEinsteinInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0]; struct einstein_linearwave_ctx *app = ctx; @@ -111,30 +112,30 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -145,13 +146,22 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, 0.0, 0.0, 1.0, 1.0, 1.0, &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, 0.0, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double b = amp * sin(2.0 * pi * x); spatial_metric[1][1] = 1.0 + b; @@ -186,14 +196,15 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1[k][i][j] += inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; + spatial_metric_der_raised1[k][i][j] += + inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; } } } } - + double spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -201,7 +212,8 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3[i][j][k] += inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; + spatial_metric_der_raised3[i][j][k] += + inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; } } } @@ -213,49 +225,91 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE for (int s = 0; s < 3; s++) { aux_vect[i] += spatial_metric_der_raised3[i][s][s]; - aux_vect[i] -= spatial_metric_der_raised1[s][s][i]; + aux_vect[i] -= spatial_metric_der_raised1[s][s][i]; } } // Set spatial metric tensor. - fout[0] = spatial_metric[0][0]; fout[1] = spatial_metric[0][1]; fout[2] = spatial_metric[0][2]; - fout[3] = spatial_metric[1][0]; fout[4] = spatial_metric[1][1]; fout[5] = spatial_metric[1][2]; - fout[6] = spatial_metric[2][0]; fout[7] = spatial_metric[2][1]; fout[8] = spatial_metric[2][2]; + fout[0] = spatial_metric[0][0]; + fout[1] = spatial_metric[0][1]; + fout[2] = spatial_metric[0][2]; + fout[3] = spatial_metric[1][0]; + fout[4] = spatial_metric[1][1]; + fout[5] = spatial_metric[1][2]; + fout[6] = spatial_metric[2][0]; + fout[7] = spatial_metric[2][1]; + fout[8] = spatial_metric[2][2]; // Set lapse gauge variable. fout[9] = lapse; // Set extrinsic curvature tensor. - fout[10] = extrinsic_curvature[0][0]; fout[11] = extrinsic_curvature[0][1]; fout[12] = extrinsic_curvature[0][2]; - fout[13] = extrinsic_curvature[1][0]; fout[14] = extrinsic_curvature[1][1]; fout[15] = extrinsic_curvature[1][2]; - fout[16] = extrinsic_curvature[2][0]; fout[17] = extrinsic_curvature[2][1]; fout[18] = extrinsic_curvature[2][2]; + fout[10] = extrinsic_curvature[0][0]; + fout[11] = extrinsic_curvature[0][1]; + fout[12] = extrinsic_curvature[0][2]; + fout[13] = extrinsic_curvature[1][0]; + fout[14] = extrinsic_curvature[1][1]; + fout[15] = extrinsic_curvature[1][2]; + fout[16] = extrinsic_curvature[2][0]; + fout[17] = extrinsic_curvature[2][1]; + fout[18] = extrinsic_curvature[2][2]; // Set spatial metric tensor derivatives. - fout[19] = spatial_metric_der[0][0][0]; fout[20] = spatial_metric_der[0][0][1]; fout[21] = spatial_metric_der[0][0][2]; - fout[22] = spatial_metric_der[0][1][0]; fout[23] = spatial_metric_der[0][1][1]; fout[24] = spatial_metric_der[0][1][2]; - fout[25] = spatial_metric_der[0][2][0]; fout[26] = spatial_metric_der[0][2][1]; fout[27] = spatial_metric_der[0][2][2]; - - fout[28] = spatial_metric_der[1][0][0]; fout[29] = spatial_metric_der[1][0][1]; fout[30] = spatial_metric_der[1][0][2]; - fout[31] = spatial_metric_der[1][1][0]; fout[32] = spatial_metric_der[1][1][1]; fout[33] = spatial_metric_der[1][1][2]; - fout[34] = spatial_metric_der[1][2][0]; fout[35] = spatial_metric_der[1][2][1]; fout[36] = spatial_metric_der[1][2][2]; - - fout[37] = spatial_metric_der[2][0][0]; fout[38] = spatial_metric_der[2][0][1]; fout[39] = spatial_metric_der[2][0][2]; - fout[40] = spatial_metric_der[2][1][0]; fout[41] = spatial_metric_der[2][1][1]; fout[42] = spatial_metric_der[2][1][2]; - fout[43] = spatial_metric_der[2][2][0]; fout[44] = spatial_metric_der[2][2][1]; fout[45] = spatial_metric_der[2][2][2]; + fout[19] = spatial_metric_der[0][0][0]; + fout[20] = spatial_metric_der[0][0][1]; + fout[21] = spatial_metric_der[0][0][2]; + fout[22] = spatial_metric_der[0][1][0]; + fout[23] = spatial_metric_der[0][1][1]; + fout[24] = spatial_metric_der[0][1][2]; + fout[25] = spatial_metric_der[0][2][0]; + fout[26] = spatial_metric_der[0][2][1]; + fout[27] = spatial_metric_der[0][2][2]; + + fout[28] = spatial_metric_der[1][0][0]; + fout[29] = spatial_metric_der[1][0][1]; + fout[30] = spatial_metric_der[1][0][2]; + fout[31] = spatial_metric_der[1][1][0]; + fout[32] = spatial_metric_der[1][1][1]; + fout[33] = spatial_metric_der[1][1][2]; + fout[34] = spatial_metric_der[1][2][0]; + fout[35] = spatial_metric_der[1][2][1]; + fout[36] = spatial_metric_der[1][2][2]; + + fout[37] = spatial_metric_der[2][0][0]; + fout[38] = spatial_metric_der[2][0][1]; + fout[39] = spatial_metric_der[2][0][2]; + fout[40] = spatial_metric_der[2][1][0]; + fout[41] = spatial_metric_der[2][1][1]; + fout[42] = spatial_metric_der[2][1][2]; + fout[43] = spatial_metric_der[2][2][0]; + fout[44] = spatial_metric_der[2][2][1]; + fout[45] = spatial_metric_der[2][2][2]; // Set lapse function derivatives. - fout[46] = lapse_der[0]; fout[47] = lapse_der[1]; fout[48] = lapse_der[2]; + fout[46] = lapse_der[0]; + fout[47] = lapse_der[1]; + fout[48] = lapse_der[2]; // Set auxiliary vector. - fout[49] = aux_vect[0]; fout[50] = aux_vect[1]; fout[51] = aux_vect[2]; + fout[49] = aux_vect[0]; + fout[50] = aux_vect[1]; + fout[51] = aux_vect[2]; // Set shift gauge variables. - fout[52] = shift[0]; fout[53] = shift[1]; fout[54] = shift[2]; + fout[52] = shift[0]; + fout[53] = shift[1]; + fout[54] = shift[2]; // Set shift vector derivatives. - fout[55] = shift_der[0][0]; fout[56] = shift_der[0][1]; fout[57] = shift_der[0][2]; - fout[58] = shift_der[1][0]; fout[59] = shift_der[1][1]; fout[60] = shift_der[1][2]; - fout[61] = shift_der[2][0]; fout[62] = shift_der[2][1]; fout[63] = shift_der[2][2]; + fout[55] = shift_der[0][0]; + fout[56] = shift_der[0][1]; + fout[57] = shift_der[0][2]; + fout[58] = shift_der[1][0]; + fout[59] = shift_der[1][1]; + fout[60] = shift_der[1][2]; + fout[61] = shift_der[2][0]; + fout[62] = shift_der[2][1]; + fout[63] = shift_der[2][2]; if (in_excision_region) { for (int i = 0; i < 64; i++) { @@ -284,8 +338,7 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -299,24 +352,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -336,12 +390,14 @@ main(int argc, char **argv) int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); // Einstein equations. - struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new(ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu); + struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new( + ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu + ); struct gkyl_moment_species einstein = { .name = "vacuum_einstein", .equation = vacuum_einstein, - + .init = evalVacuumEinsteinInit, .force_low_order_flux = false, // Use HLL fluxes. .ctx = &ctx, @@ -349,7 +405,7 @@ main(int argc, char **argv) .has_vacuum_einstein = true, .vacuum_einstein_excision_threshold = ctx.excision_threshold, .vacuum_einstein_spacetime_slicing = ctx.spacetime_slicing, - .vacuum_einstein_spacetime_evolution = ctx.spacetime_evolution, + .vacuum_einstein_spacetime_evolution = ctx.spacetime_evolution }; int nrank = 1; // Number of processes in simulation. @@ -360,7 +416,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -368,8 +424,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -383,22 +438,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -423,9 +468,9 @@ main(int argc, char **argv) .name = "vacuum_einstein_linearwave", .ndim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -433,16 +478,12 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { einstein }, + .species = {einstein}, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -454,10 +495,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -466,26 +511,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -501,7 +551,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -516,8 +566,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -525,7 +574,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -533,8 +584,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -561,14 +611,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(vacuum_einstein); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/creg/rt_vacuum_einstein_schwarzschild.c b/moments/creg/rt_vacuum_einstein_schwarzschild.c index 3d83b9a2c9..1ef9086975 100644 --- a/moments/creg/rt_vacuum_einstein_schwarzschild.c +++ b/moments/creg/rt_vacuum_einstein_schwarzschild.c @@ -19,8 +19,7 @@ #include -struct einstein_schwarzschild_ctx -{ +struct einstein_schwarzschild_ctx { // Spacetime parameters (using geometric units). double mass; // Mass of the black hole. double spin; // Spin of the black hole. @@ -52,8 +51,7 @@ struct einstein_schwarzschild_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct einstein_schwarzschild_ctx -create_ctx(void) +struct einstein_schwarzschild_ctx create_ctx(void) { // Spacetime parameters (using geometric units). double mass = 0.5; // Mass of the black hole. @@ -64,12 +62,15 @@ create_ctx(void) double pos_z = 0.0; // Position of the black hole (z-direction). // Pointer to spacetime metric. - struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *spacetime = + gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); // Evolution parameters. double excision_threshold = 0.3; // Excision threshold (lapse). - enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. - enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. + enum gkyl_spacetime_slicing spacetime_slicing = + GKYL_1PLUSLOG_SLICING; // Spacetime slicing condition. + enum gkyl_spacetime_evolution spacetime_evolution = + GKYL_EINSTEIN_EVOLUTION; // Spacetime evolution system. // Simulation parameters. int Nx = 256; // Cell count (x-direction). @@ -105,14 +106,15 @@ create_ctx(void) .field_energy_calcs = field_energy_calcs, .integrated_mom_calcs = integrated_mom_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVacuumEinsteinInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1]; struct einstein_schwarzschild_ctx *app = ctx; @@ -123,30 +125,30 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -157,14 +159,24 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -185,14 +197,15 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1[k][i][j] += inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; + spatial_metric_der_raised1[k][i][j] += + inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; } } } } - + double spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -200,7 +213,8 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3[i][j][k] += inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; + spatial_metric_der_raised3[i][j][k] += + inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; } } } @@ -212,49 +226,91 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE for (int s = 0; s < 3; s++) { aux_vect[i] += spatial_metric_der_raised3[i][s][s]; - aux_vect[i] -= spatial_metric_der_raised1[s][s][i]; + aux_vect[i] -= spatial_metric_der_raised1[s][s][i]; } } // Set spatial metric tensor. - fout[0] = spatial_metric[0][0]; fout[1] = spatial_metric[0][1]; fout[2] = spatial_metric[0][2]; - fout[3] = spatial_metric[1][0]; fout[4] = spatial_metric[1][1]; fout[5] = spatial_metric[1][2]; - fout[6] = spatial_metric[2][0]; fout[7] = spatial_metric[2][1]; fout[8] = spatial_metric[2][2]; + fout[0] = spatial_metric[0][0]; + fout[1] = spatial_metric[0][1]; + fout[2] = spatial_metric[0][2]; + fout[3] = spatial_metric[1][0]; + fout[4] = spatial_metric[1][1]; + fout[5] = spatial_metric[1][2]; + fout[6] = spatial_metric[2][0]; + fout[7] = spatial_metric[2][1]; + fout[8] = spatial_metric[2][2]; // Set lapse gauge variable. fout[9] = lapse; // Set extrinsic curvature tensor. - fout[10] = extrinsic_curvature[0][0]; fout[11] = extrinsic_curvature[0][1]; fout[12] = extrinsic_curvature[0][2]; - fout[13] = extrinsic_curvature[1][0]; fout[14] = extrinsic_curvature[1][1]; fout[15] = extrinsic_curvature[1][2]; - fout[16] = extrinsic_curvature[2][0]; fout[17] = extrinsic_curvature[2][1]; fout[18] = extrinsic_curvature[2][2]; + fout[10] = extrinsic_curvature[0][0]; + fout[11] = extrinsic_curvature[0][1]; + fout[12] = extrinsic_curvature[0][2]; + fout[13] = extrinsic_curvature[1][0]; + fout[14] = extrinsic_curvature[1][1]; + fout[15] = extrinsic_curvature[1][2]; + fout[16] = extrinsic_curvature[2][0]; + fout[17] = extrinsic_curvature[2][1]; + fout[18] = extrinsic_curvature[2][2]; // Set spatial metric tensor derivatives. - fout[19] = spatial_metric_der[0][0][0]; fout[20] = spatial_metric_der[0][0][1]; fout[21] = spatial_metric_der[0][0][2]; - fout[22] = spatial_metric_der[0][1][0]; fout[23] = spatial_metric_der[0][1][1]; fout[24] = spatial_metric_der[0][1][2]; - fout[25] = spatial_metric_der[0][2][0]; fout[26] = spatial_metric_der[0][2][1]; fout[27] = spatial_metric_der[0][2][2]; - - fout[28] = spatial_metric_der[1][0][0]; fout[29] = spatial_metric_der[1][0][1]; fout[30] = spatial_metric_der[1][0][2]; - fout[31] = spatial_metric_der[1][1][0]; fout[32] = spatial_metric_der[1][1][1]; fout[33] = spatial_metric_der[1][1][2]; - fout[34] = spatial_metric_der[1][2][0]; fout[35] = spatial_metric_der[1][2][1]; fout[36] = spatial_metric_der[1][2][2]; - - fout[37] = spatial_metric_der[2][0][0]; fout[38] = spatial_metric_der[2][0][1]; fout[39] = spatial_metric_der[2][0][2]; - fout[40] = spatial_metric_der[2][1][0]; fout[41] = spatial_metric_der[2][1][1]; fout[42] = spatial_metric_der[2][1][2]; - fout[43] = spatial_metric_der[2][2][0]; fout[44] = spatial_metric_der[2][2][1]; fout[45] = spatial_metric_der[2][2][2]; + fout[19] = spatial_metric_der[0][0][0]; + fout[20] = spatial_metric_der[0][0][1]; + fout[21] = spatial_metric_der[0][0][2]; + fout[22] = spatial_metric_der[0][1][0]; + fout[23] = spatial_metric_der[0][1][1]; + fout[24] = spatial_metric_der[0][1][2]; + fout[25] = spatial_metric_der[0][2][0]; + fout[26] = spatial_metric_der[0][2][1]; + fout[27] = spatial_metric_der[0][2][2]; + + fout[28] = spatial_metric_der[1][0][0]; + fout[29] = spatial_metric_der[1][0][1]; + fout[30] = spatial_metric_der[1][0][2]; + fout[31] = spatial_metric_der[1][1][0]; + fout[32] = spatial_metric_der[1][1][1]; + fout[33] = spatial_metric_der[1][1][2]; + fout[34] = spatial_metric_der[1][2][0]; + fout[35] = spatial_metric_der[1][2][1]; + fout[36] = spatial_metric_der[1][2][2]; + + fout[37] = spatial_metric_der[2][0][0]; + fout[38] = spatial_metric_der[2][0][1]; + fout[39] = spatial_metric_der[2][0][2]; + fout[40] = spatial_metric_der[2][1][0]; + fout[41] = spatial_metric_der[2][1][1]; + fout[42] = spatial_metric_der[2][1][2]; + fout[43] = spatial_metric_der[2][2][0]; + fout[44] = spatial_metric_der[2][2][1]; + fout[45] = spatial_metric_der[2][2][2]; // Set lapse function derivatives. - fout[46] = lapse_der[0]; fout[47] = lapse_der[1]; fout[48] = lapse_der[2]; + fout[46] = lapse_der[0]; + fout[47] = lapse_der[1]; + fout[48] = lapse_der[2]; // Set auxiliary vector. - fout[49] = aux_vect[0]; fout[50] = aux_vect[1]; fout[51] = aux_vect[2]; + fout[49] = aux_vect[0]; + fout[50] = aux_vect[1]; + fout[51] = aux_vect[2]; // Set shift gauge variables. - fout[52] = shift[0]; fout[53] = shift[1]; fout[54] = shift[2]; + fout[52] = shift[0]; + fout[53] = shift[1]; + fout[54] = shift[2]; // Set shift vector derivatives. - fout[55] = shift_der[0][0]; fout[56] = shift_der[0][1]; fout[57] = shift_der[0][2]; - fout[58] = shift_der[1][0]; fout[59] = shift_der[1][1]; fout[60] = shift_der[1][2]; - fout[61] = shift_der[2][0]; fout[62] = shift_der[2][1]; fout[63] = shift_der[2][2]; + fout[55] = shift_der[0][0]; + fout[56] = shift_der[0][1]; + fout[57] = shift_der[0][2]; + fout[58] = shift_der[1][0]; + fout[59] = shift_der[1][1]; + fout[60] = shift_der[1][2]; + fout[61] = shift_der[2][0]; + fout[62] = shift_der[2][1]; + fout[63] = shift_der[2][2]; if (in_excision_region) { for (int i = 0; i < 64; i++) { @@ -283,8 +339,7 @@ evalVacuumEinsteinInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE gkyl_free(spatial_metric_der); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_moment_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -298,24 +353,25 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_moment_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_moment_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_moment_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_moment_app_calc_integrated_mom(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -336,12 +392,14 @@ main(int argc, char **argv) int NY = APP_ARGS_CHOOSE(app_args.xcells[1], ctx.Ny); // Einstein equations. - struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new(ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu); + struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new( + ctx.excision_threshold, ctx.spacetime_slicing, ctx.spacetime_evolution, app_args.use_gpu + ); struct gkyl_moment_species einstein = { .name = "vacuum_einstein", .equation = vacuum_einstein, - + .init = evalVacuumEinsteinInit, .force_low_order_flux = false, // Use HLL fluxes. .ctx = &ctx, @@ -351,8 +409,8 @@ main(int argc, char **argv) .vacuum_einstein_spacetime_slicing = ctx.spacetime_slicing, .vacuum_einstein_spacetime_evolution = ctx.spacetime_evolution, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, - .bcy = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY}, + .bcy = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -363,7 +421,7 @@ main(int argc, char **argv) #endif // Create global range. - int cells[] = { NX, NY }; + int cells[] = {NX, NY}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -371,8 +429,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -386,22 +443,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -426,9 +473,9 @@ main(int argc, char **argv) .name = "vacuum_einstein_schwarzschild", .ndim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .scheme_type = GKYL_MOMENT_WAVE_PROP, .mp_recon = app_args.mp_recon, @@ -436,13 +483,10 @@ main(int argc, char **argv) .cfl_frac = ctx.cfl_frac, .num_species = 1, - .species = { einstein }, + .species = {einstein}, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -454,10 +498,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_moment_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_moment_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_moment_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_moment_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -466,26 +514,31 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_moment_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_moment_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -501,7 +554,7 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_moment_update(app, dt); gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -516,8 +569,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -525,7 +577,9 @@ main(int argc, char **argv) gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_moment_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -533,8 +587,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -561,14 +614,14 @@ main(int argc, char **argv) gkyl_wv_eqn_release(vacuum_einstein); gkyl_gr_spacetime_release(ctx.spacetime); gkyl_comm_release(comm); - gkyl_moment_app_release(app); - + gkyl_moment_app_release(app); + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); } #endif - + return 0; } diff --git a/moments/unit/ctest_fem_helmholtz.c b/moments/unit/ctest_fem_helmholtz.c index 82d869a8d2..6225eb51b6 100644 --- a/moments/unit/ctest_fem_helmholtz.c +++ b/moments/unit/ctest_fem_helmholtz.c @@ -11,7 +11,9 @@ #include #include -void evalFunc2x_dirichletx_periodicy_sol(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_periodicy_sol( + double t, const double *xn, double *restrict fout, void *ctx +) { // These values have to match those in the test below. double gxx = 3.0; @@ -25,9 +27,9 @@ void evalFunc2x_dirichletx_periodicy_sol(double t, const double *xn, double* res // ( 4*gxx*M_PI - 90*gxx*x - kSq*(4*M_PI - 5*x)*(M_PI - 3*x)*(M_PI + x) // +10*gxy*m*(3*pow(M_PI,2) + 2*M_PI*x - 9*pow(x,2))*cos(m*y) // -5*(-2*gxx*(M_PI - 9*x) + (kSq - gyy*pow(m,2))*(M_PI - 3*x)*(M_PI - x)*(M_PI + x))*sin(m*y))/15.; - fout[0] = ((x-4.*M_PI/5.) + (x-M_PI)*sin(m*y))*(x+M_PI)*(x-M_PI/3.); + fout[0] = ((x - 4. * M_PI / 5.) + (x - M_PI) * sin(m * y)) * (x + M_PI) * (x - M_PI / 3.); } -void evalFunc2x_dirichletx_periodicy(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_periodicy(double t, const double *xn, double *restrict fout, void *ctx) { // These values have to match those in the test below. double gxx = 3.0; @@ -38,24 +40,26 @@ void evalFunc2x_dirichletx_periodicy(double t, const double *xn, double* restric double m = 5.; double kSq = 0.3; // Expected solution: ((x-4.*M_PI/5.) + (x-M_PI)*sin(m*y))*(x+M_PI)*(x-M_PI/3.); - fout[0] = - ( 4*gxx*M_PI - 90*gxx*x - kSq*(4*M_PI - 5*x)*(M_PI - 3*x)*(M_PI + x) - +10*gxy*m*(3*pow(M_PI,2) + 2*M_PI*x - 9*pow(x,2))*cos(m*y) - -5*(-2*gxx*(M_PI - 9*x) + (kSq - gyy*pow(m,2))*(M_PI - 3*x)*(M_PI - x)*(M_PI + x))*sin(m*y) )/15.; + fout[0] = + (4 * gxx * M_PI - 90 * gxx * x - kSq * (4 * M_PI - 5 * x) * (M_PI - 3 * x) * (M_PI + x) + + 10 * gxy * m * (3 * pow(M_PI, 2) + 2 * M_PI * x - 9 * pow(x, 2)) * cos(m * y) - + 5 * + (-2 * gxx * (M_PI - 9 * x) + + (kSq - gyy * pow(m, 2)) * (M_PI - 3 * x) * (M_PI - x) * (M_PI + x)) * + sin(m * y)) / + 15.; } // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { - struct gkyl_array* a = gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -static struct gkyl_array* -mkarr_cu(long nc, long size) +static struct gkyl_array *mkarr_cu(long nc, long size) { - struct gkyl_array* a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); return a; } @@ -68,33 +72,35 @@ struct skin_ghost_ranges { }; // Create ghost and skin sub-ranges given a parent range -static void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { int ndim = parent->ndim; - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } // Apply periodic BCs in one direction. -void -apply_periodic_bc(struct gkyl_array *buff, struct gkyl_array *fld, const int dir, const struct skin_ghost_ranges sgr) +void apply_periodic_bc( + struct gkyl_array *buff, struct gkyl_array *fld, const int dir, const struct skin_ghost_ranges sgr +) { - gkyl_array_copy_to_buffer(buff->data, fld, &(sgr.lower_skin[dir])); + gkyl_array_copy_to_buffer(buff->data, fld, &(sgr.lower_skin[dir])); gkyl_array_copy_from_buffer(fld, buff->data, &(sgr.upper_ghost[dir])); - gkyl_array_copy_to_buffer(buff->data, fld, &(sgr.upper_skin[dir])); + gkyl_array_copy_to_buffer(buff->data, fld, &(sgr.upper_skin[dir])); gkyl_array_copy_from_buffer(fld, buff->data, &(sgr.lower_ghost[dir])); } -void -test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) +void test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) { // Determinant of g tensor has to be >0. Diagonal entries have to be >0. double gxx = 3.0; @@ -103,8 +109,8 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g double kSq = 0.3; - double lower[] = {-M_PI,-M_PI}, upper[] = {M_PI,M_PI}; - int dim = sizeof(lower)/sizeof(lower[0]); + double lower[] = {-M_PI, -M_PI}, upper[] = {M_PI, M_PI}; + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; @@ -114,7 +120,7 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // Local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct skin_ghost_ranges skin_ghost; // Skin/ghost. @@ -122,12 +128,14 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g // Projection updater for DG field. gkyl_proj_on_basis *projob, *projob_sol; - if ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_PERIODIC && bcs.up_type[1]==GKYL_POISSON_PERIODIC)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc2x_dirichletx_periodicy, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc2x_dirichletx_periodicy_sol, NULL); + if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC)) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc2x_dirichletx_periodicy, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc2x_dirichletx_periodicy_sol, NULL + ); } // Create DG field we wish to make continuous. @@ -135,10 +143,10 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g // Create array holding continuous field we'll compute. struct gkyl_array *phi = mkarr(basis.num_basis, localRange_ext.volume); // Create DG field for permittivity tensor. - int epsnum = dim+ceil((pow(3.,dim-1)-dim)/2); - struct gkyl_array *eps = use_gpu? mkarr_cu(epsnum*basis.num_basis, localRange_ext.volume) - : mkarr(epsnum*basis.num_basis, localRange_ext.volume); - struct gkyl_array *kSqFld; // kSq field multiplying phi in Helmholtz equation. + int epsnum = dim + ceil((pow(3., dim - 1) - dim) / 2); + struct gkyl_array *eps = use_gpu ? mkarr_cu(epsnum * basis.num_basis, localRange_ext.volume) : + mkarr(epsnum * basis.num_basis, localRange_ext.volume); + struct gkyl_array *kSqFld; // kSq field multiplying phi in Helmholtz equation. // Device copies: struct gkyl_array *rho_cu, *phi_cu; if (use_gpu) { @@ -151,36 +159,40 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g // Project distribution function on basis. gkyl_proj_on_basis_advance(projob, 0.0, &localRange, rho); - if (use_gpu) gkyl_array_copy(rho_cu, rho); -// gkyl_grid_sub_array_write(&grid, &localRange, rho, "ctest_fem_poisson_vareps_2x_rho_1.gkyl"); + if (use_gpu) { + gkyl_array_copy(rho_cu, rho); + } + // gkyl_grid_sub_array_write(&grid, &localRange, rho, "ctest_fem_poisson_vareps_2x_rho_1.gkyl"); // Project the expected solution. if (projob_sol != NULL) { struct gkyl_array *phisol = mkarr(basis.num_basis, localRange_ext.volume); gkyl_proj_on_basis_advance(projob_sol, 0.0, &localRange, phisol); -// gkyl_grid_sub_array_write(&grid, &localRange, phisol, "ctest_fem_helmholtz_2x_phisol.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, phisol, "ctest_fem_helmholtz_2x_phisol.gkyl"); gkyl_array_release(phisol); gkyl_proj_on_basis_release(projob_sol); } // Project the permittivity onto the basis. - double dg0norm = pow(sqrt(2.),dim); - gkyl_array_shiftc(eps, gxx*dg0norm, 0*basis.num_basis); - gkyl_array_shiftc(eps, gxy*dg0norm, 1*basis.num_basis); - gkyl_array_shiftc(eps, gyy*dg0norm, 2*basis.num_basis); -// gkyl_grid_sub_array_write(&grid, &localRange, eps, "ctest_fem_poisson_vareps_2x_eps_1.gkyl"); + double dg0norm = pow(sqrt(2.), dim); + gkyl_array_shiftc(eps, gxx * dg0norm, 0 * basis.num_basis); + gkyl_array_shiftc(eps, gxy * dg0norm, 1 * basis.num_basis); + gkyl_array_shiftc(eps, gyy * dg0norm, 2 * basis.num_basis); + // gkyl_grid_sub_array_write(&grid, &localRange, eps, "ctest_fem_poisson_vareps_2x_eps_1.gkyl"); // Project the kSq onto the basis. - gkyl_array_shiftc(kSqFld, kSq*dg0norm, 0); + gkyl_array_shiftc(kSqFld, kSq * dg0norm, 0); // FEM poisson solver. - gkyl_fem_poisson *poisson = gkyl_fem_poisson_new(&localRange, &grid, basis, &bcs, NULL, eps, kSqFld, false, use_gpu); + gkyl_fem_poisson *poisson = + gkyl_fem_poisson_new(&localRange, &grid, basis, &bcs, NULL, eps, kSqFld, false, use_gpu); // Set the RHS source. - if (use_gpu) + if (use_gpu) { gkyl_fem_poisson_set_rhs(poisson, rho_cu, NULL); - else + } else { gkyl_fem_poisson_set_rhs(poisson, rho, NULL); + } // Solve the problem. if (use_gpu) { @@ -192,183 +204,317 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g } else { gkyl_fem_poisson_solve(poisson, phi); } -// gkyl_grid_sub_array_write(&grid, &localRange, phi, "ctest_fem_helmholtz_2x_phi_8x8_p2.gkyl"); + // gkyl_grid_sub_array_write(&grid, &localRange, phi, "ctest_fem_helmholtz_2x_phi_8x8_p2.gkyl"); if (poly_order == 1) { - if ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_PERIODIC && bcs.up_type[1]==GKYL_POISSON_PERIODIC)) { + if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC)) { // Solution with N=8x8: const double sol[256] = { - 2.2723820361020547e+01, 1.3119603802451259e+01, -4.0251978322074500e+00, -2.3239490519656978e+00, 3.9871828304012533e+00, 2.3020010804407463e+00, - -6.7924048898040432e+00, -3.9215967915735011e+00, 1.5832165717984553e+01, 9.1407051391335976e+00, 1.3631108948496774e+01, 7.8699244207680055e+00, - 1.7817467802904730e+01, 1.0286919832284779e+01, -1.2484894255345385e+01, -7.2081570591280668e+00, 3.1648437814200294e+00, 1.8272234091458350e+00, - 4.0251978322068140e+00, 2.3239490519662831e+00, 2.1901481312039152e+01, 1.2644826131156655e+01, 6.7924048898045832e+00, 3.9215967915730929e+00, - 1.0056498424454976e+01, 5.8061220724639435e+00, -1.3631108948497818e+01, -7.8699244207675161e+00, 8.0711963395349660e+00, 4.6599073793124566e+00, - 1.2484894255346525e+01, 7.2081570591273998e+00, 5.2068465407884489e+01, 3.8225349146296583e+00, 1.5595761024353239e+00, 5.5483197864949103e+00, - 1.4583976837804151e+01, 3.8160607922803313e+00, -2.3201255668806660e+01, -5.5520576227760605e+00, 2.8528195952778681e+01, -1.8106486654355789e+00, - 3.1251954328476330e+01, 2.3034754027119662e+00, 4.6292580733758555e+01, 6.1531942835486744e+00, -2.0995681993189507e+01, 2.2944514676679968e+00, - 7.2257277343075419e+00, 5.1732903420160214e-01, -1.5595761024350800e+00, -5.5483197864949876e+00, 4.4710216304388261e+01, 5.2380315655093990e-01, - 2.3201255668806635e+01, 5.5520576227761431e+00, 3.0765997189413419e+01, 6.1505126142670354e+00, -3.1251954328476486e+01, -2.3034754027119408e+00, - 1.3001612408433161e+01, -1.8133303347172267e+00, 2.0995681993189443e+01, -2.2944514676680265e+00, 5.2440522267967133e+01, -3.6077277863070969e+00, - 1.5873676018183975e+01, 2.7159296530697716e+00, 2.3672467455535674e+01, 1.4311817123943515e+00, -3.2482920208203183e+01, 1.9328610242767283e-01, - 1.9482965775977302e+01, -3.4116174120228222e+00, 3.0064110285739766e+01, -2.9892774805412126e+00, 5.4175870683224048e+01, -1.6017747091249026e+00, - -1.0034152298570771e+01, 4.0341906522502073e+00, 9.3021957248332363e+00, 6.8152031909205002e-01, -1.5873676018183936e+01, -2.7159296530698160e+00, - 3.8070250537264926e+01, -4.3573891796094975e+00, 3.2482920208203282e+01, -1.9328610242768393e-01, 4.2259752216823379e+01, 4.8540994480772282e-01, - -3.0064110285739815e+01, 2.9892774805412503e+00, 7.5668473095764091e+00, -1.3244327580901019e+00, 1.0034152298570683e+01, -4.0341906522501887e+00, - 3.5044168186816982e+01, -6.4360619253629894e+00, 2.0348561428026951e+01, -1.3235335710419840e-01, 2.3784564026096898e+01, -1.3664627272055949e+00, - -2.6849296921187321e+01, 3.0592878188438819e+00, 7.8025527662067518e+00, -3.3320721834142146e+00, 1.7622078418098109e+01, -4.1941329675076027e+00, - 4.1664134004662145e+01, -5.6218798302725270e+00, 1.9279146251104966e+00, 2.8721119062014928e+00, 9.7586378337295834e+00, -4.1799334465126453e-01, - -2.0348561428026986e+01, 1.3235335710419946e-01, 2.1018241994449660e+01, -5.4875925428086951e+00, 2.6849296921187356e+01, -3.0592878188439032e+00, - 3.7000253254339917e+01, -3.5219830866001067e+00, -1.7622078418098084e+01, 4.1941329675076053e+00, 3.1386720158845236e+00, -1.2321754397417586e+00, - -1.9279146251105217e+00, -2.8721119062014746e+00, 1.2429370149904974e+01, -6.6205978089171778e+00, 1.6959032197075697e+01, -1.8245922568116115e+00, - 1.6916080202993015e+01, -2.5990582569880232e+00, -1.4368628940149517e+01, 4.1464291996746363e+00, -2.1492113622285096e+00, -2.4135815150495454e+00, - 3.3612777227901676e+00, -4.0393441527880407e+00, 2.0326472486816517e+01, -6.6974247909327680e+00, 9.6150643976769050e+00, 1.5660660842906933e+00, - 7.6063471291079514e+00, -8.2463227303636466e-01, -1.6959032197075729e+01, 1.8245922568116157e+00, 3.1196370760198544e+00, -4.8461718249655137e+00, - 1.4368628940149517e+01, -4.1464291996746381e+00, 2.2184928641241402e+01, -5.0316485669040114e+00, -3.3612777227901547e+00, 4.0393441527880318e+00, - -2.9075520780356889e-01, -7.4780529102079274e-01, -9.6150643976768855e+00, -1.5660660842906868e+00, -6.2750640026612921e+00, -4.1784122841065878e+00, - 8.2564814069615000e+00, -3.1998277844972116e+00, 7.7716710026903790e+00, -2.6804688563867942e+00, -1.4659517038637268e-01, 4.0646658257220656e+00, - -6.4238012029651843e+00, -5.4354080175013225e-02, -8.0491645288227200e+00, -2.5484777527533398e+00, -3.9510689078868699e-01, -5.2661846407617965e+00, - 1.1529832812819787e+01, -4.6057402437215789e-01, 5.2745040551848454e+00, -5.2165795340110488e-01, -8.2564814069615178e+00, 3.1998277844972169e+00, - -8.7722309501668576e+00, -2.0196013811208897e+00, 1.4659517038636960e-01, -4.0646658257220656e+00, 5.4232412554886942e+00, -4.6457161573326706e+00, - 8.0491645288227147e+00, 2.5484777527533398e+00, -6.0545305668776983e-01, 5.6611440325410312e-01, -1.1529832812819762e+01, 4.6057402437215300e-01, - -1.0802498418910655e+01, 1.5644968051466410e+00, -2.4972452249550914e+00, -3.0088391812314819e+00, 6.1266477647347584e-01, -1.4527853154497430e+00, - 9.0877927686536299e+00, 1.2668105366841138e+00, -1.5819159823365418e+00, 2.8498178156902303e+00, -1.0354834560510966e+01, 1.2172985392956770e+00, - -9.8934733048884986e+00, -2.1769976528043039e-01, 5.5561547029505878e+00, -2.9883306404129977e+00, 4.0554245439156702e+00, -1.8217793059371093e-01, - 2.4972452249550905e+00, 3.0088391812314845e+00, -7.3597386514684677e+00, 2.8351041900026783e+00, -9.0877927686536317e+00, -1.2668105366841140e+00, - -5.1651578926584536e+00, -1.4674989411372898e+00, 1.0354834560510968e+01, -1.2172985392956739e+00, 3.1463994298935098e+00, 1.6000186398333658e+00, - -5.5561547029505860e+00, 2.9883306404129919e+00, 4.2219852160212206e+00, 7.1098928659164056e+00, -3.8543537793259874e+00, 2.2253121920459011e+00, - 7.3165238468922222e+00, 5.3232601543653217e+00, 5.6409864908770562e+00, -3.2568250690029115e+00, 9.9453970814568979e+00, 3.8054794847240023e+00, - -4.1232058212357376e+00, 2.3805339908146852e+00, 3.1330702685049392e+00, 7.7385782039895217e+00, 1.9010710197021807e-01, -1.0975838649736505e-01, - 1.0138282004134755e+01, 3.6941173226933226e+00, 3.8543537793259817e+00, -2.2253121920459074e+00, 7.0437433732637391e+00, 5.4807500342443989e+00, - -5.6409864908770571e+00, 3.2568250690029119e+00, 4.4148701386990661e+00, 6.9985307038857156e+00, 4.1232058212357412e+00, -2.3805339908146874e+00, - 1.1227196951651038e+01, 3.0654319846202047e+00, -1.9010710197021397e-01, 1.0975838649737209e-01, + 2.2723820361020547e+01, 1.3119603802451259e+01, -4.0251978322074500e+00, + -2.3239490519656978e+00, 3.9871828304012533e+00, 2.3020010804407463e+00, + -6.7924048898040432e+00, -3.9215967915735011e+00, 1.5832165717984553e+01, + 9.1407051391335976e+00, 1.3631108948496774e+01, 7.8699244207680055e+00, + 1.7817467802904730e+01, 1.0286919832284779e+01, -1.2484894255345385e+01, + -7.2081570591280668e+00, 3.1648437814200294e+00, 1.8272234091458350e+00, + 4.0251978322068140e+00, 2.3239490519662831e+00, 2.1901481312039152e+01, + 1.2644826131156655e+01, 6.7924048898045832e+00, 3.9215967915730929e+00, + 1.0056498424454976e+01, 5.8061220724639435e+00, -1.3631108948497818e+01, + -7.8699244207675161e+00, 8.0711963395349660e+00, 4.6599073793124566e+00, + 1.2484894255346525e+01, 7.2081570591273998e+00, 5.2068465407884489e+01, + 3.8225349146296583e+00, 1.5595761024353239e+00, 5.5483197864949103e+00, + 1.4583976837804151e+01, 3.8160607922803313e+00, -2.3201255668806660e+01, + -5.5520576227760605e+00, 2.8528195952778681e+01, -1.8106486654355789e+00, + 3.1251954328476330e+01, 2.3034754027119662e+00, 4.6292580733758555e+01, + 6.1531942835486744e+00, -2.0995681993189507e+01, 2.2944514676679968e+00, + 7.2257277343075419e+00, 5.1732903420160214e-01, -1.5595761024350800e+00, + -5.5483197864949876e+00, 4.4710216304388261e+01, 5.2380315655093990e-01, + 2.3201255668806635e+01, 5.5520576227761431e+00, 3.0765997189413419e+01, + 6.1505126142670354e+00, -3.1251954328476486e+01, -2.3034754027119408e+00, + 1.3001612408433161e+01, -1.8133303347172267e+00, 2.0995681993189443e+01, + -2.2944514676680265e+00, 5.2440522267967133e+01, -3.6077277863070969e+00, + 1.5873676018183975e+01, 2.7159296530697716e+00, 2.3672467455535674e+01, + 1.4311817123943515e+00, -3.2482920208203183e+01, 1.9328610242767283e-01, + 1.9482965775977302e+01, -3.4116174120228222e+00, 3.0064110285739766e+01, + -2.9892774805412126e+00, 5.4175870683224048e+01, -1.6017747091249026e+00, + -1.0034152298570771e+01, 4.0341906522502073e+00, 9.3021957248332363e+00, + 6.8152031909205002e-01, -1.5873676018183936e+01, -2.7159296530698160e+00, + 3.8070250537264926e+01, -4.3573891796094975e+00, 3.2482920208203282e+01, + -1.9328610242768393e-01, 4.2259752216823379e+01, 4.8540994480772282e-01, + -3.0064110285739815e+01, 2.9892774805412503e+00, 7.5668473095764091e+00, + -1.3244327580901019e+00, 1.0034152298570683e+01, -4.0341906522501887e+00, + 3.5044168186816982e+01, -6.4360619253629894e+00, 2.0348561428026951e+01, + -1.3235335710419840e-01, 2.3784564026096898e+01, -1.3664627272055949e+00, + -2.6849296921187321e+01, 3.0592878188438819e+00, 7.8025527662067518e+00, + -3.3320721834142146e+00, 1.7622078418098109e+01, -4.1941329675076027e+00, + 4.1664134004662145e+01, -5.6218798302725270e+00, 1.9279146251104966e+00, + 2.8721119062014928e+00, 9.7586378337295834e+00, -4.1799334465126453e-01, + -2.0348561428026986e+01, 1.3235335710419946e-01, 2.1018241994449660e+01, + -5.4875925428086951e+00, 2.6849296921187356e+01, -3.0592878188439032e+00, + 3.7000253254339917e+01, -3.5219830866001067e+00, -1.7622078418098084e+01, + 4.1941329675076053e+00, 3.1386720158845236e+00, -1.2321754397417586e+00, + -1.9279146251105217e+00, -2.8721119062014746e+00, 1.2429370149904974e+01, + -6.6205978089171778e+00, 1.6959032197075697e+01, -1.8245922568116115e+00, + 1.6916080202993015e+01, -2.5990582569880232e+00, -1.4368628940149517e+01, + 4.1464291996746363e+00, -2.1492113622285096e+00, -2.4135815150495454e+00, + 3.3612777227901676e+00, -4.0393441527880407e+00, 2.0326472486816517e+01, + -6.6974247909327680e+00, 9.6150643976769050e+00, 1.5660660842906933e+00, + 7.6063471291079514e+00, -8.2463227303636466e-01, -1.6959032197075729e+01, + 1.8245922568116157e+00, 3.1196370760198544e+00, -4.8461718249655137e+00, + 1.4368628940149517e+01, -4.1464291996746381e+00, 2.2184928641241402e+01, + -5.0316485669040114e+00, -3.3612777227901547e+00, 4.0393441527880318e+00, + -2.9075520780356889e-01, -7.4780529102079274e-01, -9.6150643976768855e+00, + -1.5660660842906868e+00, -6.2750640026612921e+00, -4.1784122841065878e+00, + 8.2564814069615000e+00, -3.1998277844972116e+00, 7.7716710026903790e+00, + -2.6804688563867942e+00, -1.4659517038637268e-01, 4.0646658257220656e+00, + -6.4238012029651843e+00, -5.4354080175013225e-02, -8.0491645288227200e+00, + -2.5484777527533398e+00, -3.9510689078868699e-01, -5.2661846407617965e+00, + 1.1529832812819787e+01, -4.6057402437215789e-01, 5.2745040551848454e+00, + -5.2165795340110488e-01, -8.2564814069615178e+00, 3.1998277844972169e+00, + -8.7722309501668576e+00, -2.0196013811208897e+00, 1.4659517038636960e-01, + -4.0646658257220656e+00, 5.4232412554886942e+00, -4.6457161573326706e+00, + 8.0491645288227147e+00, 2.5484777527533398e+00, -6.0545305668776983e-01, + 5.6611440325410312e-01, -1.1529832812819762e+01, 4.6057402437215300e-01, + -1.0802498418910655e+01, 1.5644968051466410e+00, -2.4972452249550914e+00, + -3.0088391812314819e+00, 6.1266477647347584e-01, -1.4527853154497430e+00, + 9.0877927686536299e+00, 1.2668105366841138e+00, -1.5819159823365418e+00, + 2.8498178156902303e+00, -1.0354834560510966e+01, 1.2172985392956770e+00, + -9.8934733048884986e+00, -2.1769976528043039e-01, 5.5561547029505878e+00, + -2.9883306404129977e+00, 4.0554245439156702e+00, -1.8217793059371093e-01, + 2.4972452249550905e+00, 3.0088391812314845e+00, -7.3597386514684677e+00, + 2.8351041900026783e+00, -9.0877927686536317e+00, -1.2668105366841140e+00, + -5.1651578926584536e+00, -1.4674989411372898e+00, 1.0354834560510968e+01, + -1.2172985392956739e+00, 3.1463994298935098e+00, 1.6000186398333658e+00, + -5.5561547029505860e+00, 2.9883306404129919e+00, 4.2219852160212206e+00, + 7.1098928659164056e+00, -3.8543537793259874e+00, 2.2253121920459011e+00, + 7.3165238468922222e+00, 5.3232601543653217e+00, 5.6409864908770562e+00, + -3.2568250690029115e+00, 9.9453970814568979e+00, 3.8054794847240023e+00, + -4.1232058212357376e+00, 2.3805339908146852e+00, 3.1330702685049392e+00, + 7.7385782039895217e+00, 1.9010710197021807e-01, -1.0975838649736505e-01, + 1.0138282004134755e+01, 3.6941173226933226e+00, 3.8543537793259817e+00, + -2.2253121920459074e+00, 7.0437433732637391e+00, 5.4807500342443989e+00, + -5.6409864908770571e+00, 3.2568250690029119e+00, 4.4148701386990661e+00, + 6.9985307038857156e+00, 4.1232058212357412e+00, -2.3805339908146874e+00, + 1.1227196951651038e+01, 3.0654319846202047e+00, -1.9010710197021397e-01, + 1.0975838649737209e-01 }; - for (int j=0; j #include -void evalFunc1x_periodicx(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc1x_periodicx(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = sin((2.*M_PI/(2.*M_PI))*x); + fout[0] = sin((2. * M_PI / (2. * M_PI)) * x); } -void evalFunc1x_dirichletx(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc1x_dirichletx(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double a = 2.0; - double c0 = a/12. - 1./2.; + double c0 = a / 12. - 1. / 2.; double c1 = 0.; - fout[0] = -(1.-a*pow(x,2)); + fout[0] = -(1. - a * pow(x, 2)); } -void evalFunc1x_neumannx_dirichletx(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc1x_neumannx_dirichletx(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double a = 5.0; double c0 = 0.; - double c1 = a/12. - 1./2.; - fout[0] = -(1.-a*pow(x,2)); + double c1 = a / 12. - 1. / 2.; + fout[0] = -(1. - a * pow(x, 2)); } -void evalFunc1x_dirichletx_neumannx(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc1x_dirichletx_neumannx(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double a = 5.0; double c0 = 0.; - double c1 = a/12. - 1./2.; - fout[0] = -(1.-a*pow(x-1.,2)); + double c1 = a / 12. - 1. / 2.; + fout[0] = -(1. - a * pow(x - 1., 2)); } -void evalFunc2x_periodicx_periodicy(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_periodicx_periodicy(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; - fout[0] = sin((2.*M_PI/(2.*M_PI))*x)*cos((2.*2.*M_PI/(2.*M_PI))*y); + fout[0] = sin((2. * M_PI / (2. * M_PI)) * x) * cos((2. * 2. * M_PI / (2. * M_PI)) * y); } -void evalFunc2x_dirichletx_dirichlety(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_dirichlety(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; - double Lx = 2.*M_PI, Ly = 2.*M_PI; - double kx = 2.*M_PI/Lx, ky = 2.*M_PI/Ly; - double sig = 0.3*sqrt(Lx*Lx+Ly*Ly); - fout[0] = exp(-(pow(kx*x,2)+pow(ky*y,2))/(2.*(sig*sig))); + double Lx = 2. * M_PI, Ly = 2. * M_PI; + double kx = 2. * M_PI / Lx, ky = 2. * M_PI / Ly; + double sig = 0.3 * sqrt(Lx * Lx + Ly * Ly); + fout[0] = exp(-(pow(kx * x, 2) + pow(ky * y, 2)) / (2. * (sig * sig))); } -void evalFunc2x_dirichletx_periodicy(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_periodicy(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; - fout[0] = (y/(2.*M_PI)+0.5)*sin(5.0*M_PI*(y/(2.*M_PI)+0.5))+exp(-(pow(x/(2.*M_PI)+0.5-0.5,2)+pow(y/(2.*M_PI)+0.5-0.5,2))/0.02); + fout[0] = + (y / (2. * M_PI) + 0.5) * sin(5.0 * M_PI * (y / (2. * M_PI) + 0.5)) + + exp(-(pow(x / (2. * M_PI) + 0.5 - 0.5, 2) + pow(y / (2. * M_PI) + 0.5 - 0.5, 2)) / 0.02); } -void evalFunc2x_periodicx_dirichlety(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_periodicx_dirichlety(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; - fout[0] = (x/(2.*M_PI)+0.5)*sin(5.0*M_PI*(x/(2.*M_PI)+0.5))+exp(-(pow(x/(2.*M_PI)+0.5-0.5,2)+pow(y/(2.*M_PI)+0.5-0.5,2))/0.02); + fout[0] = + (x / (2. * M_PI) + 0.5) * sin(5.0 * M_PI * (x / (2. * M_PI) + 0.5)) + + exp(-(pow(x / (2. * M_PI) + 0.5 - 0.5, 2) + pow(y / (2. * M_PI) + 0.5 - 0.5, 2)) / 0.02); } -void evalFunc2x_dirichletx_neumanny_dirichlety(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_neumanny_dirichlety( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1]; double a = 2.0, b = 5.0; - double c1 = 0., c0 = a/12. - 1./2.; - double d1 = b/12. - 1./2., d0 = 0.; - fout[0] = -( (1.-a*pow(x,2))*(-b*pow(y,4)/12.+pow(y,2)/2.+d0*y+d1) - +(1.-b*pow(y,2))*(-a*pow(x,4)/12.+pow(x,2)/2.+c0*x+c1) ); + double c1 = 0., c0 = a / 12. - 1. / 2.; + double d1 = b / 12. - 1. / 2., d0 = 0.; + fout[0] = + -((1. - a * pow(x, 2)) * (-b * pow(y, 4) / 12. + pow(y, 2) / 2. + d0 * y + d1) + + (1. - b * pow(y, 2)) * (-a * pow(x, 4) / 12. + pow(x, 2) / 2. + c0 * x + c1)); } -void evalFunc2x_dirichletx_dirichlety_neumanny(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_dirichlety_neumanny( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1]; double a = 2.0, b = 5.0; - double c1 = 0., c0 = a/12. - 1./2.; - double d1 = b/12. - 1./2., d0 = 0.; - fout[0] = -( (1.-a*pow(x,2))*(-b*pow(y-1.,4)/12.+pow(y-1.,2)/2.+d0*y+d1) - +(1.-b*pow(y-1.,2))*(-a*pow(x,4)/12.+pow(x,2)/2.+c0*x+c1) ); + double c1 = 0., c0 = a / 12. - 1. / 2.; + double d1 = b / 12. - 1. / 2., d0 = 0.; + fout[0] = + -((1. - a * pow(x, 2)) * (-b * pow(y - 1., 4) / 12. + pow(y - 1., 2) / 2. + d0 * y + d1) + + (1. - b * pow(y - 1., 2)) * (-a * pow(x, 4) / 12. + pow(x, 2) / 2. + c0 * x + c1)); } -void evalFunc2x_neumannx_dirichletx_dirichlety(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_neumannx_dirichletx_dirichlety( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1]; double a = 2.0, b = 5.0; - double c1 = 0., c0 = a/12. - 1./2.; - double d1 = b/12. - 1./2., d0 = 0.; - fout[0] = -( (1.-a*pow(y,2))*(-b*pow(x,4)/12.+pow(x,2)/2.+d0*x+d1) - +(1.-b*pow(x,2))*(-a*pow(y,4)/12.+pow(y,2)/2.+c0*y+c1) ); + double c1 = 0., c0 = a / 12. - 1. / 2.; + double d1 = b / 12. - 1. / 2., d0 = 0.; + fout[0] = + -((1. - a * pow(y, 2)) * (-b * pow(x, 4) / 12. + pow(x, 2) / 2. + d0 * x + d1) + + (1. - b * pow(x, 2)) * (-a * pow(y, 4) / 12. + pow(y, 2) / 2. + c0 * y + c1)); } -void evalFunc2x_dirichletx_neumannx_dirichlety(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_neumannx_dirichlety( + double t, const double *xn, double *restrict fout, void *ctx +) { double x = xn[0], y = xn[1]; double a = 2.0, b = 5.0; - double c1 = 0., c0 = a/12. - 1./2.; - double d1 = b/12. - 1./2., d0 = 0.; - fout[0] = -( (1.-a*pow(y,2))*(-b*pow(x-1.,4)/12.+pow(x-1.,2)/2.+d0*x+d1) - +(1.-b*pow(x-1.,2))*(-a*pow(y,4)/12.+pow(y,2)/2.+c0*y+c1) ); + double c1 = 0., c0 = a / 12. - 1. / 2.; + double d1 = b / 12. - 1. / 2., d0 = 0.; + fout[0] = + -((1. - a * pow(y, 2)) * (-b * pow(x - 1., 4) / 12. + pow(x - 1., 2) / 2. + d0 * x + d1) + + (1. - b * pow(x - 1., 2)) * (-a * pow(y, 4) / 12. + pow(y, 2) / 2. + c0 * y + c1)); } // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { - struct gkyl_array* a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } @@ -120,41 +135,43 @@ struct skin_ghost_ranges { }; // Create ghost and skin sub-ranges given a parent range -static void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { int ndim = parent->ndim; - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } // Apply periodic BCs in one direction. -void -apply_periodic_bc(struct gkyl_array *buff, struct gkyl_array *fld, const int dir, const struct skin_ghost_ranges sgr) +void apply_periodic_bc( + struct gkyl_array *buff, struct gkyl_array *fld, const int dir, const struct skin_ghost_ranges sgr +) { - gkyl_array_copy_to_buffer(buff->data, fld, &(sgr.lower_skin[dir])); + gkyl_array_copy_to_buffer(buff->data, fld, &(sgr.lower_skin[dir])); gkyl_array_copy_from_buffer(fld, buff->data, &(sgr.upper_ghost[dir])); - gkyl_array_copy_to_buffer(buff->data, fld, &(sgr.upper_skin[dir])); + gkyl_array_copy_to_buffer(buff->data, fld, &(sgr.upper_skin[dir])); gkyl_array_copy_from_buffer(fld, buff->data, &(sgr.lower_ghost[dir])); } -void -test_1x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) +void test_1x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) { double epsilon_0 = 1.0; double lower[] = {0.0}, upper[] = {1.0}; if (bcs.lo_type[0] == GKYL_POISSON_PERIODIC) { lower[0] = -M_PI; - upper[0] = M_PI; + upper[0] = M_PI; } - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; @@ -164,7 +181,7 @@ test_1x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct skin_ghost_ranges skin_ghost; // skin/ghost. @@ -173,17 +190,17 @@ test_1x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g // Projection updater for DG field. gkyl_proj_on_basis *projob; if (bcs.lo_type[0] == GKYL_POISSON_PERIODIC) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc1x_periodicx, NULL); - } else if (bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc1x_dirichletx, NULL); - } else if (bcs.lo_type[0]==GKYL_POISSON_NEUMANN && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc1x_neumannx_dirichletx, NULL); - } else if (bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_NEUMANN) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc1x_dirichletx_neumannx, NULL); + projob = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc1x_periodicx, NULL); + } else if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { + projob = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc1x_dirichletx, NULL); + } else if (bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc1x_neumannx_dirichletx, NULL + ); + } else if (bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_NEUMANN) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc1x_dirichletx_neumannx, NULL + ); } // Create DG field we wish to make continuous. @@ -195,28 +212,32 @@ test_1x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g if (use_gpu) { rho_ho = mkarr(false, basis.num_basis, localRange_ext.volume); phi_ho = mkarr(false, basis.num_basis, localRange_ext.volume); - } - else { + } else { rho_ho = gkyl_array_acquire(rho); phi_ho = gkyl_array_acquire(phi); } struct gkyl_array *epsilon = mkarr(use_gpu, basis.num_basis, localRange_ext.volume); gkyl_array_clear(epsilon, 0.); - gkyl_array_shiftc(epsilon, epsilon_0*pow(sqrt(2.),dim), 0); + gkyl_array_shiftc(epsilon, epsilon_0 * pow(sqrt(2.), dim), 0); // Project the right-side source on the basis. gkyl_proj_on_basis_advance(projob, 0.0, &localRange, rho_ho); gkyl_array_copy(rho, rho_ho); - struct gkyl_array *perbuff = mkarr(use_gpu, basis.num_basis, skin_ghost.lower_skin[dim-1].volume); - for (int d=0; d #include -void evalFunc2x_periodicx_periodicy_sol(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_periodicx_periodicy_sol(double t, const double *xn, double *restrict fout, void *ctx) { // These values have to match those in the test below. double gxx = 3.0; @@ -22,17 +22,17 @@ void evalFunc2x_periodicx_periodicy_sol(double t, const double *xn, double* rest double amn[] = {0., 10., 0., 10., 0., 0., 10., 0., 0.}; double bmn[] = {0., 10., 0., 10., 0., 0., 10., 0., 0.}; fout[0] = 0.; - for (int m=1; m<4; m++) { - for (int n=1; n<4; n++) { - double a = amn[(m-1)*3+(n-1)]; - double b = bmn[(m-1)*3+(n-1)]; - double t1 = a*cos(m*x)*cos(n*y); - double t2 = b*sin(m*x)*sin(n*y); - fout[0] += t1+t2; + for (int m = 1; m < 4; m++) { + for (int n = 1; n < 4; n++) { + double a = amn[(m - 1) * 3 + (n - 1)]; + double b = bmn[(m - 1) * 3 + (n - 1)]; + double t1 = a * cos(m * x) * cos(n * y); + double t2 = b * sin(m * x) * sin(n * y); + fout[0] += t1 + t2; } } } -void evalFunc2x_periodicx_periodicy(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_periodicx_periodicy(double t, const double *xn, double *restrict fout, void *ctx) { // These values have to match those in the test below. double gxx = 3.0; @@ -43,13 +43,15 @@ void evalFunc2x_periodicx_periodicy(double t, const double *xn, double* restrict double amn[] = {0., 10., 0., 10., 0., 0., 10., 0., 0.}; double bmn[] = {0., 10., 0., 10., 0., 0., 10., 0., 0.}; fout[0] = 0.; - for (int m=1; m<4; m++) { - for (int n=1; n<4; n++) { - double a = amn[(m-1)*3+(n-1)]; - double b = bmn[(m-1)*3+(n-1)]; - double t1 = (a*gxx*pow(m,2) - 2*b*gxy*m*n + a*gyy*pow(n,2))*cos(m*x)*cos(n*y); - double t2 = (b*gxx*pow(m,2) - 2*a*gxy*m*n + b*gyy*pow(n,2))*sin(m*x)*sin(n*y); - fout[0] += t1+t2; + for (int m = 1; m < 4; m++) { + for (int n = 1; n < 4; n++) { + double a = amn[(m - 1) * 3 + (n - 1)]; + double b = bmn[(m - 1) * 3 + (n - 1)]; + double t1 = + (a * gxx * pow(m, 2) - 2 * b * gxy * m * n + a * gyy * pow(n, 2)) * cos(m * x) * cos(n * y); + double t2 = + (b * gxx * pow(m, 2) - 2 * a * gxy * m * n + b * gyy * pow(n, 2)) * sin(m * x) * sin(n * y); + fout[0] += t1 + t2; } } } @@ -58,10 +60,12 @@ double poly_test_func_1x(double x, double a, double *c) { // Function that can be used to produce homogeneous Dirichlet or Neumann // boundary values depending on the choice of a and c. It assumes x \in [0,1]. - return pow(x,2)/2.-a*pow(x,4)/12.+c[0]*x+c[1]; + return pow(x, 2) / 2. - a * pow(x, 4) / 12. + c[0] * x + c[1]; } -void evalFunc2x_dirichletx_dirichlety_sol(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_dirichlety_sol( + double t, const double *xn, double *restrict fout, void *ctx +) { // These values have to match those in the test below. double gxx = 3.0; @@ -69,13 +73,13 @@ void evalFunc2x_dirichletx_dirichlety_sol(double t, const double *xn, double* re double gyy = 2.0; double x = xn[0], y = xn[1]; - double a = M_PI/3.; - double b = 4.*M_PI/5.; + double a = M_PI / 3.; + double b = 4. * M_PI / 5.; // RHSsource: // gxx*(2*(x-a)*(y-M_PI)*(y+M_PI)*(y-b)+2*(x+M_PI)*(y-M_PI)*(y+M_PI)*(y-b)+2*(x-M_PI)*(y-M_PI)*(y+M_PI)*(y-b))+2*gxy*((x+M_PI)*(x-a)*(y+M_PI)*(y-b)+(x-M_PI)*(x-a)*(y+M_PI)*(y-b)+(x-M_PI)*(x+M_PI)*(y+M_PI)*(y-b)+(x+M_PI)*(x-a)*(y-M_PI)*(y-b)+(x-M_PI)*(x-a)*(y-M_PI)*(y-b)+(x-M_PI)*(x+M_PI)*(y-M_PI)*(y-b)+(x+M_PI)*(x-a)*(y-M_PI)*(y+M_PI)+(x-M_PI)*(x-a)*(y-M_PI)*(y+M_PI)+(x-M_PI)*(x+M_PI)*(y-M_PI)*(y+M_PI))+gyy*(2*(x-M_PI)*(x+M_PI)*(x-a)*(y-b)+2*(x-M_PI)*(x+M_PI)*(x-a)*(y+M_PI)+2*(x-M_PI)*(x+M_PI)*(x-a)*(y-M_PI)) - fout[0] = ((x+M_PI)*(x-a)*(x-M_PI))*((y+M_PI)*(y-b)*(y-M_PI)); + fout[0] = ((x + M_PI) * (x - a) * (x - M_PI)) * ((y + M_PI) * (y - b) * (y - M_PI)); } -void evalFunc2x_dirichletx_dirichlety(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_dirichlety(double t, const double *xn, double *restrict fout, void *ctx) { // These values have to match those in the test below. double gxx = 3.0; @@ -83,13 +87,29 @@ void evalFunc2x_dirichletx_dirichlety(double t, const double *xn, double* restri double gyy = 2.0; double x = xn[0], y = xn[1]; - double a = M_PI/3.; - double b = 4.*M_PI/5.; + double a = M_PI / 3.; + double b = 4. * M_PI / 5.; // Expected solution: ((x+M_PI)*(x-a)*(x-M_PI))*((x+M_PI)*(x-b.)*(x-M_PI)); - fout[0] = -( gxx*(2*(x-a)*(y-M_PI)*(y+M_PI)*(y-b)+2*(x+M_PI)*(y-M_PI)*(y+M_PI)*(y-b)+2*(x-M_PI)*(y-M_PI)*(y+M_PI)*(y-b))+2*gxy*((x+M_PI)*(x-a)*(y+M_PI)*(y-b)+(x-M_PI)*(x-a)*(y+M_PI)*(y-b)+(x-M_PI)*(x+M_PI)*(y+M_PI)*(y-b)+(x+M_PI)*(x-a)*(y-M_PI)*(y-b)+(x-M_PI)*(x-a)*(y-M_PI)*(y-b)+(x-M_PI)*(x+M_PI)*(y-M_PI)*(y-b)+(x+M_PI)*(x-a)*(y-M_PI)*(y+M_PI)+(x-M_PI)*(x-a)*(y-M_PI)*(y+M_PI)+(x-M_PI)*(x+M_PI)*(y-M_PI)*(y+M_PI))+gyy*(2*(x-M_PI)*(x+M_PI)*(x-a)*(y-b)+2*(x-M_PI)*(x+M_PI)*(x-a)*(y+M_PI)+2*(x-M_PI)*(x+M_PI)*(x-a)*(y-M_PI)) ); + fout[0] = + -(gxx * (2 * (x - a) * (y - M_PI) * (y + M_PI) * (y - b) + + 2 * (x + M_PI) * (y - M_PI) * (y + M_PI) * (y - b) + + 2 * (x - M_PI) * (y - M_PI) * (y + M_PI) * (y - b)) + + 2 * gxy * + ((x + M_PI) * (x - a) * (y + M_PI) * (y - b) + (x - M_PI) * (x - a) * (y + M_PI) * (y - b) + + (x - M_PI) * (x + M_PI) * (y + M_PI) * (y - b) + + (x + M_PI) * (x - a) * (y - M_PI) * (y - b) + (x - M_PI) * (x - a) * (y - M_PI) * (y - b) + + (x - M_PI) * (x + M_PI) * (y - M_PI) * (y - b) + + (x + M_PI) * (x - a) * (y - M_PI) * (y + M_PI) + + (x - M_PI) * (x - a) * (y - M_PI) * (y + M_PI) + + (x - M_PI) * (x + M_PI) * (y - M_PI) * (y + M_PI)) + + gyy * (2 * (x - M_PI) * (x + M_PI) * (x - a) * (y - b) + + 2 * (x - M_PI) * (x + M_PI) * (x - a) * (y + M_PI) + + 2 * (x - M_PI) * (x + M_PI) * (x - a) * (y - M_PI))); } -void evalFunc2x_dirichletx_periodicy_sol(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_periodicy_sol( + double t, const double *xn, double *restrict fout, void *ctx +) { // These values have to match those in the test below. double gxx = 3.0; @@ -101,9 +121,9 @@ void evalFunc2x_dirichletx_periodicy_sol(double t, const double *xn, double* res // RHSsource: (2*(2*M_PI - 45*x + 5*(M_PI - 9*x)*sin(m*y))*gxx)/15. // +(m*((3*pow(M_PI,2) + 2*M_PI*x - 9*pow(x,2))*cos(m*y)*2.*gxy // +m*(M_PI - 3*x)*(M_PI - x)*(M_PI + x)*sin(m*y)*gyy))/3.; - fout[0] = ((x-4.*M_PI/5.) + (x-M_PI)*sin(m*y))*(x+M_PI)*(x-M_PI/3.); + fout[0] = ((x - 4. * M_PI / 5.) + (x - M_PI) * sin(m * y)) * (x + M_PI) * (x - M_PI / 3.); } -void evalFunc2x_dirichletx_periodicy(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_periodicy(double t, const double *xn, double *restrict fout, void *ctx) { // These values have to match those in the test below. double gxx = 3.0; @@ -113,12 +133,15 @@ void evalFunc2x_dirichletx_periodicy(double t, const double *xn, double* restric double x = xn[0], y = xn[1]; double m = 5.; // Expected solution: ((x-4.*M_PI/5.) + (x-M_PI)*sin(m*y))*(x+M_PI)*(x-M_PI/3.); - fout[0] = (2*(2*M_PI - 45*x + 5*(M_PI - 9*x)*sin(m*y))*gxx)/15. - +(m*((3*pow(M_PI,2) + 2*M_PI*x - 9*pow(x,2))*cos(m*y)*2.*gxy - +m*(M_PI - 3*x)*(M_PI - x)*(M_PI + x)*sin(m*y)*gyy))/3.; + fout[0] = (2 * (2 * M_PI - 45 * x + 5 * (M_PI - 9 * x) * sin(m * y)) * gxx) / 15. + + (m * ((3 * pow(M_PI, 2) + 2 * M_PI * x - 9 * pow(x, 2)) * cos(m * y) * 2. * gxy + + m * (M_PI - 3 * x) * (M_PI - x) * (M_PI + x) * sin(m * y) * gyy)) / + 3.; } -void evalFunc2x_periodicx_dirichlety_sol(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_periodicx_dirichlety_sol( + double t, const double *xn, double *restrict fout, void *ctx +) { // These values have to match those in the test below. double gxx = 3.0; @@ -130,9 +153,9 @@ void evalFunc2x_periodicx_dirichlety_sol(double t, const double *xn, double* res // RHSsource: (2*(2*M_PI - 45*y + 5*(M_PI - 9*y)*sin(m*x))*gxx)/15. // +(m*((3*pow(M_PI,2) + 2*M_PI*y - 9*pow(y,2))*cos(m*x)*2.*gxy // +m*(M_PI - 3*y)*(M_PI - y)*(M_PI + y)*sin(m*x)*gyy))/3.; - fout[0] = ((y-4.*M_PI/5.) + (y-M_PI)*sin(m*x))*(y+M_PI)*(y-M_PI/3.); + fout[0] = ((y - 4. * M_PI / 5.) + (y - M_PI) * sin(m * x)) * (y + M_PI) * (y - M_PI / 3.); } -void evalFunc2x_periodicx_dirichlety(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_periodicx_dirichlety(double t, const double *xn, double *restrict fout, void *ctx) { // These values have to match those in the test below. double gxx = 3.0; @@ -142,12 +165,15 @@ void evalFunc2x_periodicx_dirichlety(double t, const double *xn, double* restric double x = xn[0], y = xn[1]; double m = 5.; // Expected solution: ((y-4.*M_PI/5.) + (y-M_PI)*sin(m*x))*(y+M_PI)*(y-M_PI/3.); - fout[0] = (5*pow(m,2)*(M_PI - 3*y)*(M_PI - y)*(M_PI + y)*sin(m*x)*gxx - +5*m*(3*pow(M_PI,2) + 2*M_PI*y - 9*pow(y,2))*cos(m*x)*(gxy + gxy) - +2*(2*M_PI - 45*y + 5*(M_PI - 9*y)*sin(m*x))*gyy)/15.; + fout[0] = (5 * pow(m, 2) * (M_PI - 3 * y) * (M_PI - y) * (M_PI + y) * sin(m * x) * gxx + + 5 * m * (3 * pow(M_PI, 2) + 2 * M_PI * y - 9 * pow(y, 2)) * cos(m * x) * (gxy + gxy) + + 2 * (2 * M_PI - 45 * y + 5 * (M_PI - 9 * y) * sin(m * x)) * gyy) / + 15.; } -void evalFunc2x_dirichletx_neumanny_dirichlety_sol(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_neumanny_dirichlety_sol( + double t, const double *xn, double *restrict fout, void *ctx +) { // These values have to match those in the test below. double gxx = 3.0; @@ -156,16 +182,18 @@ void evalFunc2x_dirichletx_neumanny_dirichlety_sol(double t, const double *xn, d double x = xn[0], y = xn[1]; double a = 2.; - double c[] = {a/12.-0.5, 0.}; + double c[] = {a / 12. - 0.5, 0.}; double b = 5.; - double d[] = {0., b/12.-0.5}; + double d[] = {0., b / 12. - 0.5}; // RHSsource: (-3*((6 - 6*a*pow(x,2))*pow(y,2) + b*(-1 + a*pow(x,2))*pow(y,4) // +4*(9*x - 5*a*pow(x,3) + 6*c[0])*d[0] - 12*(-1 + a*pow(x,2))*d[1])*gxx // -4*y*(-3 + b*pow(y,2))*(-3*x + a*pow(x,3) - 3*c[0])*(gxy + gxy) // -3*(-1 + b*pow(y,2))*(-6*pow(x,2) + a*pow(x,4) - 12*x*c[0] - 12*c[1])*gyy)/36. - fout[0] = poly_test_func_1x(x, a, c)*poly_test_func_1x(y, b, d); + fout[0] = poly_test_func_1x(x, a, c) * poly_test_func_1x(y, b, d); } -void evalFunc2x_dirichletx_neumanny_dirichlety(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_dirichletx_neumanny_dirichlety( + double t, const double *xn, double *restrict fout, void *ctx +) { // These values have to match those in the test below. double gxx = 3.0; @@ -174,17 +202,24 @@ void evalFunc2x_dirichletx_neumanny_dirichlety(double t, const double *xn, doubl double x = xn[0], y = xn[1]; double a = 2.; - double c[] = {a/12.-0.5, 0.}; + double c[] = {a / 12. - 0.5, 0.}; double b = 5.; - double d[] = {0., b/12.-0.5}; + double d[] = {0., b / 12. - 0.5}; // Expected solution: (x^2/2 - (a*x^4)/12 + c*x + q)*(y^2/2 - (b*y^4)/12 + f*x + h) - fout[0] = (-3*((6 - 6*a*pow(x,2))*pow(y,2) + b*(-1 + a*pow(x,2))*pow(y,4) - +4*(9*x - 5*a*pow(x,3) + 6*c[0])*d[0] - 12*(-1 + a*pow(x,2))*d[1])*gxx - -4*y*(-3 + b*pow(y,2))*(-3*x + a*pow(x,3) - 3*c[0])*(gxy + gxy) - -3*(-1 + b*pow(y,2))*(-6*pow(x,2) + a*pow(x,4) - 12*x*c[0] - 12*c[1])*gyy)/36.; + fout[0] = + (-3 * + ((6 - 6 * a * pow(x, 2)) * pow(y, 2) + b * (-1 + a * pow(x, 2)) * pow(y, 4) + + 4 * (9 * x - 5 * a * pow(x, 3) + 6 * c[0]) * d[0] - 12 * (-1 + a * pow(x, 2)) * d[1]) * + gxx - + 4 * y * (-3 + b * pow(y, 2)) * (-3 * x + a * pow(x, 3) - 3 * c[0]) * (gxy + gxy) - + 3 * (-1 + b * pow(y, 2)) * (-6 * pow(x, 2) + a * pow(x, 4) - 12 * x * c[0] - 12 * c[1]) * gyy + ) / + 36.; } -void evalFunc2x_neumannx_dirichletx_dirichlety_sol(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_neumannx_dirichletx_dirichlety_sol( + double t, const double *xn, double *restrict fout, void *ctx +) { // These values have to match those in the test below. double gxx = 3.0; @@ -193,14 +228,16 @@ void evalFunc2x_neumannx_dirichletx_dirichlety_sol(double t, const double *xn, d double x = xn[0], y = xn[1]; double a = 5.; - double c[] = {0., a/12.-0.5}; + double c[] = {0., a / 12. - 0.5}; double b = 2.; - double d[] = {b/12.-0.5, 0.}; - // RHSsource: + double d[] = {b / 12. - 0.5, 0.}; + // RHSsource: // gxx*(1.-a*pow(x,2))*(-((b*pow(y,4))/12)+pow(y,2)/2+d[0]*y+d[1])+2*gxy*(-((a*pow(x,3))/3)+x+c[0])*(-((b*pow(y,3))/3)+y+d[0])+gyy*(-((a*pow(x,4))/12)+pow(x,2)/2+c[0]*x+c[1])*(1.-b*pow(y,2)); - fout[0] = poly_test_func_1x(x, a, c)*poly_test_func_1x(y, b, d); + fout[0] = poly_test_func_1x(x, a, c) * poly_test_func_1x(y, b, d); } -void evalFunc2x_neumannx_dirichletx_dirichlety(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc2x_neumannx_dirichletx_dirichlety( + double t, const double *xn, double *restrict fout, void *ctx +) { // These values have to match those in the test below. double gxx = 3.0; @@ -209,25 +246,26 @@ void evalFunc2x_neumannx_dirichletx_dirichlety(double t, const double *xn, doubl double x = xn[0], y = xn[1]; double a = 5.; - double c[] = {0., a/12.-0.5}; + double c[] = {0., a / 12. - 0.5}; double b = 2.; - double d[] = {b/12.-0.5, 0.}; + double d[] = {b / 12. - 0.5, 0.}; // Expected solution: (x^2/2 - (a*x^4)/12 + c*x + q)*(y^2/2 - (b*y^4)/12 + f*x + h) - fout[0] = -( gxx*(1.-a*pow(x,2))*(-((b*pow(y,4))/12)+pow(y,2)/2+d[0]*y+d[1])+2*gxy*(-((a*pow(x,3))/3)+x+c[0])*(-((b*pow(y,3))/3)+y+d[0])+gyy*(-((a*pow(x,4))/12)+pow(x,2)/2+c[0]*x+c[1])*(1.-b*pow(y,2)) ); + fout[0] = + -(gxx * (1. - a * pow(x, 2)) * (-((b * pow(y, 4)) / 12) + pow(y, 2) / 2 + d[0] * y + d[1]) + + 2 * gxy * (-((a * pow(x, 3)) / 3) + x + c[0]) * (-((b * pow(y, 3)) / 3) + y + d[0]) + + gyy * (-((a * pow(x, 4)) / 12) + pow(x, 2) / 2 + c[0] * x + c[1]) * (1. - b * pow(y, 2))); } // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { - struct gkyl_array* a = gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -static struct gkyl_array* -mkarr_cu(long nc, long size) +static struct gkyl_array *mkarr_cu(long nc, long size) { - struct gkyl_array* a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); return a; } @@ -240,23 +278,26 @@ struct skin_ghost_ranges { }; // Create ghost and skin sub-ranges given a parent range -static void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { int ndim = parent->ndim; - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } // Apply periodic BCs in one direction. -void -apply_periodic_bc(struct gkyl_array *buff, struct gkyl_array *fld, const int dir, const struct skin_ghost_ranges sgr) +void apply_periodic_bc( + struct gkyl_array *buff, struct gkyl_array *fld, const int dir, const struct skin_ghost_ranges sgr +) { gkyl_array_copy_to_buffer(buff->data, fld, &(sgr.lower_skin[dir])); gkyl_array_copy_from_buffer(fld, buff->data, &(sgr.upper_ghost[dir])); @@ -265,32 +306,32 @@ apply_periodic_bc(struct gkyl_array *buff, struct gkyl_array *fld, const int dir gkyl_array_copy_from_buffer(fld, buff->data, &(sgr.lower_ghost[dir])); } -void -test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) +void test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_gpu) { // Determinant of g tensor has to be >0. Diagonal entries have to be >0. double gxx = 3.0; double gxy = 2.44948; double gyy = 2.0; - double lower[] = {-M_PI,-M_PI}, upper[] = {M_PI,M_PI}; - if ( - ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_NEUMANN && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) || - ((bcs.lo_type[0]==GKYL_POISSON_NEUMANN && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) - ){ - lower[0] = 0.; lower[1] = 0.; - upper[0] = 1.; upper[1] = 1.; + double lower[] = {-M_PI, -M_PI}, upper[] = {M_PI, M_PI}; + if (((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + (bcs.lo_type[1] == GKYL_POISSON_NEUMANN && bcs.up_type[1] == GKYL_POISSON_DIRICHLET)) || + ((bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET))) { + lower[0] = 0.; + lower[1] = 0.; + upper[0] = 1.; + upper[1] = 1.; gxy = 0.; - } else if ( - ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) - ) + } else if (((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET) + )) { gxy = 2.; + } { } - int dim = sizeof(lower)/sizeof(lower[0]); + int dim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; @@ -300,7 +341,7 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, dim, poly_order); - int ghost[] = { 1, 1 }; + int ghost[] = {1, 1}; struct gkyl_range localRange, localRange_ext; // Local, local-ext ranges. gkyl_create_grid_ranges(&grid, ghost, &localRange_ext, &localRange); struct skin_ghost_ranges skin_ghost; // Skin/ghost. @@ -309,40 +350,58 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g // Projection updater for DG field. gkyl_proj_on_basis *projob, *projob_sol; if (bcs.lo_type[0] == GKYL_POISSON_PERIODIC && bcs.lo_type[1] == GKYL_POISSON_PERIODIC) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc2x_periodicx_periodicy, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc2x_periodicx_periodicy_sol, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc2x_dirichletx_dirichlety, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc2x_dirichletx_dirichlety_sol, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_PERIODIC && bcs.up_type[1]==GKYL_POISSON_PERIODIC)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc2x_dirichletx_periodicy, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc2x_dirichletx_periodicy_sol, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_PERIODIC && bcs.up_type[0]==GKYL_POISSON_PERIODIC) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc2x_periodicx_dirichlety, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc2x_periodicx_dirichlety_sol, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_DIRICHLET && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_NEUMANN && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc2x_dirichletx_neumanny_dirichlety, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc2x_dirichletx_neumanny_dirichlety_sol, NULL); - } else if ((bcs.lo_type[0]==GKYL_POISSON_NEUMANN && bcs.up_type[0]==GKYL_POISSON_DIRICHLET) && - (bcs.lo_type[1]==GKYL_POISSON_DIRICHLET && bcs.up_type[1]==GKYL_POISSON_DIRICHLET)) { - projob = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc2x_neumannx_dirichletx_dirichlety, NULL); - projob_sol = gkyl_proj_on_basis_new(&grid, &basis, - 2*(poly_order+1), 1, evalFunc2x_neumannx_dirichletx_dirichlety_sol, NULL); + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc2x_periodicx_periodicy, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc2x_periodicx_periodicy_sol, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET + )) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc2x_dirichletx_dirichlety, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc2x_dirichletx_dirichlety_sol, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && + (bcs.lo_type[1] == GKYL_POISSON_PERIODIC && bcs.up_type[1] == GKYL_POISSON_PERIODIC)) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc2x_dirichletx_periodicy, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc2x_dirichletx_periodicy_sol, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_PERIODIC && bcs.up_type[0] == GKYL_POISSON_PERIODIC) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET + )) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc2x_periodicx_dirichlety, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc2x_periodicx_dirichlety_sol, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_DIRICHLET && bcs.up_type[0] == GKYL_POISSON_DIRICHLET + ) && + (bcs.lo_type[1] == GKYL_POISSON_NEUMANN && bcs.up_type[1] == GKYL_POISSON_DIRICHLET)) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc2x_dirichletx_neumanny_dirichlety, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc2x_dirichletx_neumanny_dirichlety_sol, NULL + ); + } else if ((bcs.lo_type[0] == GKYL_POISSON_NEUMANN && bcs.up_type[0] == GKYL_POISSON_DIRICHLET) && + (bcs.lo_type[1] == GKYL_POISSON_DIRICHLET && bcs.up_type[1] == GKYL_POISSON_DIRICHLET + )) { + projob = gkyl_proj_on_basis_new( + &grid, &basis, poly_order + 1, 1, evalFunc2x_neumannx_dirichletx_dirichlety, NULL + ); + projob_sol = gkyl_proj_on_basis_new( + &grid, &basis, 2 * (poly_order + 1), 1, evalFunc2x_neumannx_dirichletx_dirichlety_sol, NULL + ); } // Create DG field we wish to make continuous. @@ -350,9 +409,9 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g // Create array holding continuous field we'll compute. struct gkyl_array *phi = mkarr(basis.num_basis, localRange_ext.volume); // Create DG field for permittivity tensor. - int epsnum = dim+ceil((pow(3.,dim-1)-dim)/2); - struct gkyl_array *eps = use_gpu? mkarr_cu(epsnum*basis.num_basis, localRange_ext.volume) - : mkarr(epsnum*basis.num_basis, localRange_ext.volume); + int epsnum = dim + ceil((pow(3., dim - 1) - dim) / 2); + struct gkyl_array *eps = use_gpu ? mkarr_cu(epsnum * basis.num_basis, localRange_ext.volume) : + mkarr(epsnum * basis.num_basis, localRange_ext.volume); // Device copies: struct gkyl_array *rho_cu, *phi_cu; if (use_gpu) { @@ -362,26 +421,30 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g // Project distribution function on basis. gkyl_proj_on_basis_advance(projob, 0.0, &localRange, rho); - if (use_gpu) gkyl_array_copy(rho_cu, rho); + if (use_gpu) { + gkyl_array_copy(rho_cu, rho); + } // Project the expected solution. struct gkyl_array *phisol = mkarr(basis.num_basis, localRange_ext.volume); gkyl_proj_on_basis_advance(projob_sol, 0.0, &localRange, phisol); // Project the permittivity onto the basis. - double dg0norm = pow(sqrt(2.),dim); - gkyl_array_shiftc(eps, gxx*dg0norm, 0*basis.num_basis); - gkyl_array_shiftc(eps, gxy*dg0norm, 1*basis.num_basis); - gkyl_array_shiftc(eps, gyy*dg0norm, 2*basis.num_basis); + double dg0norm = pow(sqrt(2.), dim); + gkyl_array_shiftc(eps, gxx * dg0norm, 0 * basis.num_basis); + gkyl_array_shiftc(eps, gxy * dg0norm, 1 * basis.num_basis); + gkyl_array_shiftc(eps, gyy * dg0norm, 2 * basis.num_basis); // FEM poisson solver. - gkyl_fem_poisson *poisson = gkyl_fem_poisson_new(&localRange, &grid, basis, &bcs, NULL, eps, NULL, false, use_gpu); + gkyl_fem_poisson *poisson = + gkyl_fem_poisson_new(&localRange, &grid, basis, &bcs, NULL, eps, NULL, false, use_gpu); // Set the RHS source. - if (use_gpu) + if (use_gpu) { gkyl_fem_poisson_set_rhs(poisson, rho_cu, NULL); - else + } else { gkyl_fem_poisson_set_rhs(poisson, rho, NULL); + } // Solve the problem. if (use_gpu) { @@ -396,15 +459,15 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g if (bcs.lo_type[0] == GKYL_POISSON_PERIODIC && bcs.lo_type[1] == GKYL_POISSON_PERIODIC) { struct gkyl_array *sol_cellavg = gkyl_array_new(GKYL_DOUBLE, 1, localRange_ext.volume); - double* sol_avg = (double*) gkyl_malloc(sizeof(double)); + double *sol_avg = (double *)gkyl_malloc(sizeof(double)); gkyl_array_clear(sol_cellavg, 0.0); // Factor accounting for normalization when subtracting a constant from a // DG field and the 1/N to properly compute the volume averaged RHS. - double mavgfac = -pow(sqrt(2.),dim)/localRange.volume; + double mavgfac = -pow(sqrt(2.), dim) / localRange.volume; // Subtract the volume averaged sol from the sol. gkyl_dg_calc_average_range(&basis, 0, sol_cellavg, 0, phi, localRange); gkyl_array_reduce_range(sol_avg, sol_cellavg, GKYL_SUM, &localRange); - gkyl_array_shiftc(phi, mavgfac*sol_avg[0], 0); + gkyl_array_shiftc(phi, mavgfac * sol_avg[0], 0); gkyl_free(sol_avg); gkyl_array_release(sol_cellavg); @@ -414,1039 +477,1765 @@ test_2x(int poly_order, const int *cells, struct gkyl_poisson_bc bcs, bool use_g if (bcs.lo_type[0] == GKYL_POISSON_PERIODIC && bcs.lo_type[1] == GKYL_POISSON_PERIODIC) { // Solution with N=8x8: const double sol[256] = { - -1.0487258355542172e+01, -3.4672194615719323e+00, 1.2487089948838117e+00, -7.3829839001277786e-01, -1.5453564258762444e+00, -3.3771781285781359e+00, - 3.9139004912760469e+00, 7.9028377785493853e-01, 5.2215272976960074e+00, 4.6956135527195275e-01, -7.0383518967097811e-03, 1.4306322986482731e+00, - 1.4932886788449311e+00, 3.3046036633858393e+00, -2.1454612183001176e+00, 2.0618014110525743e-01, -2.9431153863741066e-02, 2.4254609580711044e+00, - 1.2663185129853838e+00, -7.1375341867481512e-01, 5.9015118519390191e+00, 8.6215062070894122e-01, 2.1579130279631680e+00, -1.8882422542815416e-01, - 5.2951622117098962e+00, 5.7219714822887291e-01, -2.5079891559724854e+00, 2.1419510039319974e-02, -5.8494441049077164e+00, -7.8957615551664595e-01, - -3.9263523009390977e+00, -8.0763969353204146e-01, -6.7270067596276100e+00, 5.6382017326939247e+00, -3.3771781285781368e+00, -1.9324587859588025e+00, - -9.4839930397771006e+00, -1.2061958574561431e+00, 1.7854313575817238e+00, -2.0191560051551658e+00, -3.6051177810056378e+00, -5.5656272675016334e+00, - 1.6087388556022115e+00, -4.9776289294830867e-01, -3.0508358878078150e+00, -5.9281552051739945e+00, -1.2887240553575130e+00, 2.8845729054441199e-01, - -3.7896827497783017e+00, -4.5964432291930963e+00, 8.6215062070894188e-01, 4.8040697727120762e-01, 5.1278376137143153e+00, -1.3088316504130526e+00, - 4.2863821616574915e+00, 1.4176964527283813e+00, 1.4121807290411542e+01, 4.5238687640008095e+00, 9.0628865226698430e-01, 1.9498147016359040e+00, - 7.4069913138705905e+00, 8.4431827130431927e+00, -4.7830894638817023e+00, 3.1300226188237157e-01, 1.0319933757546561e+01, 4.2038539637561216e+00, - -3.0271020005688309e+00, 2.1345753327018371e+00, 3.6051177810055952e+00, 8.7631975132878779e+00, -8.4969881104589473e-01, 4.9776289294830606e-01, - 2.2148951700382993e+00, 8.9258133114739593e+00, 4.7053412370420863e-02, -4.0387661809108605e-01, -3.5530500339743374e+00, 5.6382017326939149e+00, - -3.3771781285781279e+00, -1.4942268119085045e+00, -1.4676089183609335e+01, -1.6888264558869253e+00, -3.0447115186703853e+00, -2.7360348851286194e+00, - -1.4121807290411509e+01, -9.8049560167887009e+00, 3.3647263189150864e+00, -1.9498147016359004e+00, 2.1412602560244745e+00, -1.1440840819343155e+01, - 6.0247601068687962e+00, 1.0053361705178678e+00, 1.4069739543380248e+01, -4.5964432291930901e+00, 8.6215062070893500e-01, 2.9462786205960989e+00, - -1.4932886788448974e+00, -1.1024221117403657e+01, 3.1297644834797150e-01, -2.0618014110525401e-01, 2.0475705720427344e+00, -9.6624478136581367e+00, - 1.7313395933145797e+00, 9.9240032459797578e-01, 1.1825413219478111e+01, -3.3771781285781262e+00, 3.9139004912760385e+00, 2.6364018200123627e+00, - 1.7756356225280861e+01, 6.6647897073581737e+00, -4.8966895032749230e-01, 3.1613310132590238e+00, 5.8494441049076764e+00, 1.3539248625272847e+01, - -6.3847899675871842e+00, 8.0763969353203824e-01, -1.2564260081448641e+01, 1.0704206317158961e+01, -4.2463671011837762e+00, -2.4444521332855680e+00, - -1.6181568645540896e+01, 8.6215062070893345e-01, 2.1579130279631737e+00, -3.2378613724391472e+00, -7.2396667158749599e+00, -7.7065482108590002e+00, - 3.0046964581966891e+00, -1.7092792045714316e+00, -7.2396667158749564e+00, 7.7065482108589975e+00, -3.0046964581966829e+00, -1.7092792045714302e+00, - -1.6181568645540882e+01, -8.6215062070893089e-01, -2.1579130279631746e+00, -3.2378613724391458e+00, -1.2564260081448637e+01, -1.0704206317158961e+01, - 4.2463671011837727e+00, -2.4444521332855706e+00, 5.8494441049076782e+00, -1.3539248625272851e+01, 6.3847899675871851e+00, 8.0763969353203946e-01, - 1.7756356225280864e+01, -6.6647897073581719e+00, 4.8966895032749130e-01, 3.1613310132590242e+00, 1.1825413219478115e+01, 3.3771781285781279e+00, - -3.9139004912760367e+00, 2.6364018200123640e+00, 2.0475705720427291e+00, 9.6624478136581367e+00, -1.7313395933145861e+00, 9.9240032459797478e-01, - -1.4932886788449089e+00, 1.1024221117403654e+01, -3.1297644834796867e-01, -2.0618014110525504e-01, 1.4069739543380248e+01, 4.5964432291930901e+00, - -8.6215062070892989e-01, 2.9462786205960971e+00, 2.1412602560244904e+00, 1.1440840819343155e+01, -6.0247601068687908e+00, 1.0053361705178696e+00, - -1.4121807290411496e+01, 9.8049560167887044e+00, -3.3647263189150931e+00, -1.9498147016358995e+00, -1.4676089183609333e+01, 1.6888264558869279e+00, - 3.0447115186703857e+00, -2.7360348851286211e+00, -3.5530500339743369e+00, -5.6382017326939131e+00, 3.3771781285781262e+00, -1.4942268119085040e+00, - 2.2148951700383011e+00, -8.9258133114739593e+00, -4.7053412370418296e-02, -4.0387661809108694e-01, 3.6051177810055952e+00, -8.7631975132878761e+00, - 8.4969881104589007e-01, 4.9776289294830811e-01, 1.0319933757546551e+01, -4.2038539637561172e+00, 3.0271020005688305e+00, 2.1345753327018371e+00, - 7.4069913138705923e+00, -8.4431827130431909e+00, 4.7830894638817041e+00, 3.1300226188237157e-01, 1.4121807290411557e+01, -4.5238687640008104e+00, - -9.0628865226697919e-01, 1.9498147016359024e+00, 5.1278376137143313e+00, 1.3088316504130499e+00, -4.2863821616574942e+00, 1.4176964527283822e+00, - -3.7896827497782946e+00, 4.5964432291930963e+00, -8.6215062070894288e-01, 4.8040697727120818e-01, -3.0508358878078097e+00, 5.9281552051739954e+00, - 1.2887240553575130e+00, 2.8845729054441255e-01, -3.6051177810056338e+00, 5.5656272675016352e+00, -1.6087388556022122e+00, -4.9776289294830967e-01, - -9.4839930397771006e+00, 1.2061958574561427e+00, -1.7854313575817249e+00, -2.0191560051551658e+00, -6.7270067596276117e+00, -5.6382017326939247e+00, - 3.3771781285781368e+00, -1.9324587859588018e+00, -5.8494441049077155e+00, 7.8957615551664562e-01, 3.9263523009390977e+00, -8.0763969353204135e-01, - 5.2951622117098980e+00, -5.7219714822887602e-01, 2.5079891559724858e+00, 2.1419510039318492e-02, 5.9015118519390226e+00, -8.6215062070894533e-01, - -2.1579130279631680e+00, -1.8882422542815386e-01, -2.9431153863737514e-02, -2.4254609580711071e+00, -1.2663185129853838e+00, -7.1375341867481512e-01, - 1.4932886788449364e+00, -3.3046036633858407e+00, 2.1454612183001189e+00, 2.0618014110525712e-01, 5.2215272976960128e+00, -4.6956135527195375e-01, - 7.0383518967087558e-03, 1.4306322986482738e+00, -1.5453564258762436e+00, 3.3771781285781368e+00, -3.9139004912760487e+00, 7.9028377785493842e-01, - -1.0487258355542172e+01, 3.4672194615719323e+00, -1.2487089948838108e+00, -7.3829839001277808e-01, + -1.0487258355542172e+01, -3.4672194615719323e+00, 1.2487089948838117e+00, + -7.3829839001277786e-01, -1.5453564258762444e+00, -3.3771781285781359e+00, + 3.9139004912760469e+00, 7.9028377785493853e-01, 5.2215272976960074e+00, + 4.6956135527195275e-01, -7.0383518967097811e-03, 1.4306322986482731e+00, + 1.4932886788449311e+00, 3.3046036633858393e+00, -2.1454612183001176e+00, + 2.0618014110525743e-01, -2.9431153863741066e-02, 2.4254609580711044e+00, + 1.2663185129853838e+00, -7.1375341867481512e-01, 5.9015118519390191e+00, + 8.6215062070894122e-01, 2.1579130279631680e+00, -1.8882422542815416e-01, + 5.2951622117098962e+00, 5.7219714822887291e-01, -2.5079891559724854e+00, + 2.1419510039319974e-02, -5.8494441049077164e+00, -7.8957615551664595e-01, + -3.9263523009390977e+00, -8.0763969353204146e-01, -6.7270067596276100e+00, + 5.6382017326939247e+00, -3.3771781285781368e+00, -1.9324587859588025e+00, + -9.4839930397771006e+00, -1.2061958574561431e+00, 1.7854313575817238e+00, + -2.0191560051551658e+00, -3.6051177810056378e+00, -5.5656272675016334e+00, + 1.6087388556022115e+00, -4.9776289294830867e-01, -3.0508358878078150e+00, + -5.9281552051739945e+00, -1.2887240553575130e+00, 2.8845729054441199e-01, + -3.7896827497783017e+00, -4.5964432291930963e+00, 8.6215062070894188e-01, + 4.8040697727120762e-01, 5.1278376137143153e+00, -1.3088316504130526e+00, + 4.2863821616574915e+00, 1.4176964527283813e+00, 1.4121807290411542e+01, + 4.5238687640008095e+00, 9.0628865226698430e-01, 1.9498147016359040e+00, + 7.4069913138705905e+00, 8.4431827130431927e+00, -4.7830894638817023e+00, + 3.1300226188237157e-01, 1.0319933757546561e+01, 4.2038539637561216e+00, + -3.0271020005688309e+00, 2.1345753327018371e+00, 3.6051177810055952e+00, + 8.7631975132878779e+00, -8.4969881104589473e-01, 4.9776289294830606e-01, + 2.2148951700382993e+00, 8.9258133114739593e+00, 4.7053412370420863e-02, + -4.0387661809108605e-01, -3.5530500339743374e+00, 5.6382017326939149e+00, + -3.3771781285781279e+00, -1.4942268119085045e+00, -1.4676089183609335e+01, + -1.6888264558869253e+00, -3.0447115186703853e+00, -2.7360348851286194e+00, + -1.4121807290411509e+01, -9.8049560167887009e+00, 3.3647263189150864e+00, + -1.9498147016359004e+00, 2.1412602560244745e+00, -1.1440840819343155e+01, + 6.0247601068687962e+00, 1.0053361705178678e+00, 1.4069739543380248e+01, + -4.5964432291930901e+00, 8.6215062070893500e-01, 2.9462786205960989e+00, + -1.4932886788448974e+00, -1.1024221117403657e+01, 3.1297644834797150e-01, + -2.0618014110525401e-01, 2.0475705720427344e+00, -9.6624478136581367e+00, + 1.7313395933145797e+00, 9.9240032459797578e-01, 1.1825413219478111e+01, + -3.3771781285781262e+00, 3.9139004912760385e+00, 2.6364018200123627e+00, + 1.7756356225280861e+01, 6.6647897073581737e+00, -4.8966895032749230e-01, + 3.1613310132590238e+00, 5.8494441049076764e+00, 1.3539248625272847e+01, + -6.3847899675871842e+00, 8.0763969353203824e-01, -1.2564260081448641e+01, + 1.0704206317158961e+01, -4.2463671011837762e+00, -2.4444521332855680e+00, + -1.6181568645540896e+01, 8.6215062070893345e-01, 2.1579130279631737e+00, + -3.2378613724391472e+00, -7.2396667158749599e+00, -7.7065482108590002e+00, + 3.0046964581966891e+00, -1.7092792045714316e+00, -7.2396667158749564e+00, + 7.7065482108589975e+00, -3.0046964581966829e+00, -1.7092792045714302e+00, + -1.6181568645540882e+01, -8.6215062070893089e-01, -2.1579130279631746e+00, + -3.2378613724391458e+00, -1.2564260081448637e+01, -1.0704206317158961e+01, + 4.2463671011837727e+00, -2.4444521332855706e+00, 5.8494441049076782e+00, + -1.3539248625272851e+01, 6.3847899675871851e+00, 8.0763969353203946e-01, + 1.7756356225280864e+01, -6.6647897073581719e+00, 4.8966895032749130e-01, + 3.1613310132590242e+00, 1.1825413219478115e+01, 3.3771781285781279e+00, + -3.9139004912760367e+00, 2.6364018200123640e+00, 2.0475705720427291e+00, + 9.6624478136581367e+00, -1.7313395933145861e+00, 9.9240032459797478e-01, + -1.4932886788449089e+00, 1.1024221117403654e+01, -3.1297644834796867e-01, + -2.0618014110525504e-01, 1.4069739543380248e+01, 4.5964432291930901e+00, + -8.6215062070892989e-01, 2.9462786205960971e+00, 2.1412602560244904e+00, + 1.1440840819343155e+01, -6.0247601068687908e+00, 1.0053361705178696e+00, + -1.4121807290411496e+01, 9.8049560167887044e+00, -3.3647263189150931e+00, + -1.9498147016358995e+00, -1.4676089183609333e+01, 1.6888264558869279e+00, + 3.0447115186703857e+00, -2.7360348851286211e+00, -3.5530500339743369e+00, + -5.6382017326939131e+00, 3.3771781285781262e+00, -1.4942268119085040e+00, + 2.2148951700383011e+00, -8.9258133114739593e+00, -4.7053412370418296e-02, + -4.0387661809108694e-01, 3.6051177810055952e+00, -8.7631975132878761e+00, + 8.4969881104589007e-01, 4.9776289294830811e-01, 1.0319933757546551e+01, + -4.2038539637561172e+00, 3.0271020005688305e+00, 2.1345753327018371e+00, + 7.4069913138705923e+00, -8.4431827130431909e+00, 4.7830894638817041e+00, + 3.1300226188237157e-01, 1.4121807290411557e+01, -4.5238687640008104e+00, + -9.0628865226697919e-01, 1.9498147016359024e+00, 5.1278376137143313e+00, + 1.3088316504130499e+00, -4.2863821616574942e+00, 1.4176964527283822e+00, + -3.7896827497782946e+00, 4.5964432291930963e+00, -8.6215062070894288e-01, + 4.8040697727120818e-01, -3.0508358878078097e+00, 5.9281552051739954e+00, + 1.2887240553575130e+00, 2.8845729054441255e-01, -3.6051177810056338e+00, + 5.5656272675016352e+00, -1.6087388556022122e+00, -4.9776289294830967e-01, + -9.4839930397771006e+00, 1.2061958574561427e+00, -1.7854313575817249e+00, + -2.0191560051551658e+00, -6.7270067596276117e+00, -5.6382017326939247e+00, + 3.3771781285781368e+00, -1.9324587859588018e+00, -5.8494441049077155e+00, + 7.8957615551664562e-01, 3.9263523009390977e+00, -8.0763969353204135e-01, + 5.2951622117098980e+00, -5.7219714822887602e-01, 2.5079891559724858e+00, + 2.1419510039318492e-02, 5.9015118519390226e+00, -8.6215062070894533e-01, + -2.1579130279631680e+00, -1.8882422542815386e-01, -2.9431153863737514e-02, + -2.4254609580711071e+00, -1.2663185129853838e+00, -7.1375341867481512e-01, + 1.4932886788449364e+00, -3.3046036633858407e+00, 2.1454612183001189e+00, + 2.0618014110525712e-01, 5.2215272976960128e+00, -4.6956135527195375e-01, + 7.0383518967087558e-03, 1.4306322986482738e+00, -1.5453564258762436e+00, + 3.3771781285781368e+00, -3.9139004912760487e+00, 7.9028377785493842e-01, + -1.0487258355542172e+01, 3.4672194615719323e+00, -1.2487089948838108e+00, + -7.3829839001277808e-01 }; - for (int j=0; j #include -void -test_gr_spacetime_minkowski_ho() +void test_gr_spacetime_minkowski_ho() { struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); @@ -16,16 +15,16 @@ test_gr_spacetime_minkowski_ho() double x = 0.1 * x_ind; double y = 0.1 * y_ind; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **spacetime_metric = gkyl_malloc(sizeof(double*[4])); - double **inv_spacetime_metric = gkyl_malloc(sizeof(double*[4])); + double **spacetime_metric = gkyl_malloc(sizeof(double *[4])); + double **inv_spacetime_metric = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_metric[i] = gkyl_malloc(sizeof(double[4])); @@ -41,12 +40,11 @@ test_gr_spacetime_minkowski_ho() for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i == j) { - TEST_CHECK( gkyl_compare(spatial_metric[i][j], 1.0, 1e-10) ); - TEST_CHECK( gkyl_compare(inv_spatial_metric[i][j], 1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spatial_metric[i][j], 0.0, 1e-10) ); - TEST_CHECK( gkyl_compare(inv_spatial_metric[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_metric[i][j], 1.0, 1e-10)); + TEST_CHECK(gkyl_compare(inv_spatial_metric[i][j], 1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spatial_metric[i][j], 0.0, 1e-10)); + TEST_CHECK(gkyl_compare(inv_spatial_metric[i][j], 0.0, 1e-10)); } } } @@ -55,17 +53,15 @@ test_gr_spacetime_minkowski_ho() for (int j = 0; j < 4; j++) { if (i == j) { if (i == 0) { - TEST_CHECK( gkyl_compare(spacetime_metric[i][j], -1.0, 1e-10) ); - TEST_CHECK( gkyl_compare(inv_spacetime_metric[i][j], -1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spacetime_metric[i][j], 1.0, 1e-10) ); - TEST_CHECK( gkyl_compare(inv_spacetime_metric[i][j], 1.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spacetime_metric[i][j], -1.0, 1e-10)); + TEST_CHECK(gkyl_compare(inv_spacetime_metric[i][j], -1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spacetime_metric[i][j], 1.0, 1e-10)); + TEST_CHECK(gkyl_compare(inv_spacetime_metric[i][j], 1.0, 1e-10)); } - } - else { - TEST_CHECK( gkyl_compare(spacetime_metric[i][j], 0.0, 1e-10) ); - TEST_CHECK( gkyl_compare(inv_spacetime_metric[i][j], 0.0, 1e-10) ); + } else { + TEST_CHECK(gkyl_compare(spacetime_metric[i][j], 0.0, 1e-10)); + TEST_CHECK(gkyl_compare(inv_spacetime_metric[i][j], 0.0, 1e-10)); } } } @@ -76,15 +72,15 @@ test_gr_spacetime_minkowski_ho() spacetime->spatial_metric_det_func(spacetime, 0.0, x, y, 0.0, &spatial_metric_det); spacetime->spacetime_metric_det_func(spacetime, 0.0, x, y, 0.0, &spacetime_metric_det); - TEST_CHECK( gkyl_compare(spatial_metric_det, 1.0, 1e-10) ); - TEST_CHECK( gkyl_compare(spacetime_metric_det, -1.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_metric_det, 1.0, 1e-10)); + TEST_CHECK(gkyl_compare(spacetime_metric_det, -1.0, 1e-10)); - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); - double ***spatial_christoffel = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); + double ***spatial_christoffel = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); - spatial_christoffel[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); + spatial_christoffel[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -92,12 +88,12 @@ test_gr_spacetime_minkowski_ho() } } - double ***spacetime_metric_der = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel = gkyl_malloc(sizeof(double**[4])); + double ***spacetime_metric_der = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel = gkyl_malloc(sizeof(double **[4])); for (int i = 0; i < 4; i++) { - spacetime_metric_der[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel[i] = gkyl_malloc(sizeof(double*[4])); + spacetime_metric_der[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel[i] = gkyl_malloc(sizeof(double *[4])); for (int j = 0; j < 4; j++) { spacetime_metric_der[i][j] = gkyl_malloc(sizeof(double[4])); @@ -105,17 +101,29 @@ test_gr_spacetime_minkowski_ho() } } - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_metric_der); - spacetime->spatial_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_christoffel); - - spacetime->spacetime_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_metric_der); - spacetime->spacetime_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_christoffel); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_metric_der + ); + spacetime->spatial_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_christoffel + ); + + spacetime->spacetime_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_metric_der + ); + spacetime->spacetime_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_christoffel + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { - TEST_CHECK( gkyl_compare(spatial_metric_der[i][j][k], 0.0, 1e-10) ); - TEST_CHECK( gkyl_compare(spatial_christoffel[i][j][k], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_metric_der[i][j][k], 0.0, 1e-10)); + TEST_CHECK(gkyl_compare(spatial_christoffel[i][j][k], 0.0, 1e-10)); } } } @@ -123,8 +131,8 @@ test_gr_spacetime_minkowski_ho() for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { - TEST_CHECK( gkyl_compare(spacetime_metric_der[i][j][k], 0.0, 1e-10) ); - TEST_CHECK( gkyl_compare(spacetime_christoffel[i][j][k], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spacetime_metric_der[i][j][k], 0.0, 1e-10)); + TEST_CHECK(gkyl_compare(spacetime_christoffel[i][j][k], 0.0, 1e-10)); } } } @@ -135,48 +143,57 @@ test_gr_spacetime_minkowski_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse_function); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift_vector); - TEST_CHECK( gkyl_compare(lapse_function, 1.0, 1e-10) ); + TEST_CHECK(gkyl_compare(lapse_function, 1.0, 1e-10)); for (int i = 0; i < 3; i++) { - TEST_CHECK( gkyl_compare(shift_vector[i], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(shift_vector[i], 0.0, 1e-10)); } double *lapse_function_der = gkyl_malloc(sizeof(double[3])); - double **shift_vector_der = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **shift_vector_der = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_vector_der[i] = gkyl_malloc(sizeof(double[3])); extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &lapse_function_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &shift_vector_der); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &extrinsic_curvature); + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &lapse_function_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &shift_vector_der + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &extrinsic_curvature + ); for (int i = 0; i < 3; i++) { - TEST_CHECK( gkyl_compare(lapse_function_der[i], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(lapse_function_der[i], 0.0, 1e-10)); } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - TEST_CHECK( gkyl_compare(shift_vector_der[i][j], 0.0, 1e-10) ); - TEST_CHECK( gkyl_compare(extrinsic_curvature[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(shift_vector_der[i][j], 0.0, 1e-10)); + TEST_CHECK(gkyl_compare(extrinsic_curvature[i][j], 0.0, 1e-10)); } } - double ****spatial_riemann_tensor = gkyl_malloc(sizeof(double***[3])); - double ****spatial_weyl_tensor = gkyl_malloc(sizeof(double***[3])); - double **spatial_ricci_tensor = gkyl_malloc(sizeof(double*[3])); + double ****spatial_riemann_tensor = gkyl_malloc(sizeof(double ***[3])); + double ****spatial_weyl_tensor = gkyl_malloc(sizeof(double ***[3])); + double **spatial_ricci_tensor = gkyl_malloc(sizeof(double *[3])); double spatial_ricci_scalar; for (int i = 0; i < 3; i++) { - spatial_riemann_tensor[i] = gkyl_malloc(sizeof(double**[3])); - spatial_weyl_tensor[i] = gkyl_malloc(sizeof(double**[3])); + spatial_riemann_tensor[i] = gkyl_malloc(sizeof(double **[3])); + spatial_weyl_tensor[i] = gkyl_malloc(sizeof(double **[3])); spatial_ricci_tensor[i] = gkyl_malloc(sizeof(double[3])); for (int j = 0; j < 3; j++) { - spatial_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[3])); - spatial_weyl_tensor[i][j] = gkyl_malloc(sizeof(double*[3])); + spatial_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[3])); + spatial_weyl_tensor[i][j] = gkyl_malloc(sizeof(double *[3])); for (int k = 0; k < 3; k++) { spatial_riemann_tensor[i][j][k] = gkyl_malloc(sizeof(double[3])); @@ -185,39 +202,51 @@ test_gr_spacetime_minkowski_ho() } } - spacetime->spatial_riemann_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_riemann_tensor); - spacetime->spatial_weyl_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_weyl_tensor); - spacetime->spatial_ricci_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_ricci_tensor); - spacetime->spatial_ricci_scalar_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_ricci_scalar); + spacetime->spatial_riemann_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_riemann_tensor + ); + spacetime->spatial_weyl_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_weyl_tensor + ); + spacetime->spatial_ricci_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_ricci_tensor + ); + spacetime->spatial_ricci_scalar_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_ricci_scalar + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - TEST_CHECK( gkyl_compare(spatial_ricci_tensor[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_ricci_tensor[i][j], 0.0, 1e-10)); for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - TEST_CHECK( gkyl_compare(spatial_riemann_tensor[i][j][k][l], 0.0, 1e-10) ); - TEST_CHECK( gkyl_compare(spatial_weyl_tensor[i][j][k][l], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_riemann_tensor[i][j][k][l], 0.0, 1e-10)); + TEST_CHECK(gkyl_compare(spatial_weyl_tensor[i][j][k][l], 0.0, 1e-10)); } } } } - TEST_CHECK( gkyl_compare(spatial_ricci_scalar, 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_ricci_scalar, 0.0, 1e-10)); - double ****spacetime_riemann_tensor = gkyl_malloc(sizeof(double***[4])); - double ****spacetime_weyl_tensor = gkyl_malloc(sizeof(double***[4])); - double **spacetime_ricci_tensor = gkyl_malloc(sizeof(double*[4])); + double ****spacetime_riemann_tensor = gkyl_malloc(sizeof(double ***[4])); + double ****spacetime_weyl_tensor = gkyl_malloc(sizeof(double ***[4])); + double **spacetime_ricci_tensor = gkyl_malloc(sizeof(double *[4])); double spacetime_ricci_scalar; for (int i = 0; i < 4; i++) { - spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double**[4])); - spacetime_weyl_tensor[i] = gkyl_malloc(sizeof(double**[4])); + spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double **[4])); + spacetime_weyl_tensor[i] = gkyl_malloc(sizeof(double **[4])); spacetime_ricci_tensor[i] = gkyl_malloc(sizeof(double[4])); for (int j = 0; j < 4; j++) { - spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[4])); - spacetime_weyl_tensor[i][j] = gkyl_malloc(sizeof(double*[4])); + spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[4])); + spacetime_weyl_tensor[i][j] = gkyl_malloc(sizeof(double *[4])); for (int k = 0; k < 4; k++) { spacetime_riemann_tensor[i][j][k] = gkyl_malloc(sizeof(double[4])); @@ -226,30 +255,42 @@ test_gr_spacetime_minkowski_ho() } } - spacetime->spacetime_riemann_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_riemann_tensor); - spacetime->spacetime_weyl_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_weyl_tensor); - spacetime->spacetime_ricci_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_ricci_tensor); - spacetime->spacetime_ricci_scalar_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_ricci_scalar); + spacetime->spacetime_riemann_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_riemann_tensor + ); + spacetime->spacetime_weyl_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_weyl_tensor + ); + spacetime->spacetime_ricci_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_ricci_tensor + ); + spacetime->spacetime_ricci_scalar_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_ricci_scalar + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - TEST_CHECK( gkyl_compare(spacetime_ricci_tensor[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spacetime_ricci_tensor[i][j], 0.0, 1e-10)); for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { - TEST_CHECK( gkyl_compare(spacetime_riemann_tensor[i][j][k][l], 0.0, 1e-10) ); - TEST_CHECK( gkyl_compare(spacetime_weyl_tensor[i][j][k][l], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spacetime_riemann_tensor[i][j][k][l], 0.0, 1e-10)); + TEST_CHECK(gkyl_compare(spacetime_weyl_tensor[i][j][k][l], 0.0, 1e-10)); } } } } - TEST_CHECK( gkyl_compare(spacetime_ricci_scalar, 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spacetime_ricci_scalar, 0.0, 1e-10)); bool in_excision_region; spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - TEST_CHECK( (in_excision_region == false) ); + TEST_CHECK((in_excision_region == false)); for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric[i]); @@ -294,7 +335,7 @@ test_gr_spacetime_minkowski_ho() for (int j = 0; j < 4; j++) { gkyl_free(spacetime_metric_der[i][j]); gkyl_free(spacetime_christoffel[i][j]); - + for (int k = 0; k < 4; k++) { gkyl_free(spacetime_riemann_tensor[i][j][k]); gkyl_free(spacetime_weyl_tensor[i][j][k]); @@ -320,8 +361,7 @@ test_gr_spacetime_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_spacetime_schwarzschild_ho() +void test_gr_spacetime_schwarzschild_ho() { struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); @@ -331,9 +371,9 @@ test_gr_spacetime_schwarzschild_ho() double y = 0.1 * y_ind; if (sqrt((x * x) + (y * y)) > 0.2) { - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_prod = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_prod = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); @@ -345,9 +385,9 @@ test_gr_spacetime_schwarzschild_ho() } } - double **spacetime_metric = gkyl_malloc(sizeof(double*[4])); - double **inv_spacetime_metric = gkyl_malloc(sizeof(double*[4])); - double **spacetime_metric_prod = gkyl_malloc(sizeof(double*[4])); + double **spacetime_metric = gkyl_malloc(sizeof(double *[4])); + double **inv_spacetime_metric = gkyl_malloc(sizeof(double *[4])); + double **spacetime_metric_prod = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_metric[i] = gkyl_malloc(sizeof(double[4])); @@ -363,7 +403,9 @@ test_gr_spacetime_schwarzschild_ho() spacetime->spacetime_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spacetime_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); - spacetime->spacetime_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spacetime_metric); + spacetime->spacetime_inv_metric_tensor_func( + spacetime, 0.0, x, y, 0.0, &inv_spacetime_metric + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -372,10 +414,9 @@ test_gr_spacetime_schwarzschild_ho() } if (i == j) { - TEST_CHECK( gkyl_compare(spatial_metric_prod[i][j], 1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spatial_metric_prod[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_metric_prod[i][j], 1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spatial_metric_prod[i][j], 0.0, 1e-10)); } } } @@ -387,10 +428,9 @@ test_gr_spacetime_schwarzschild_ho() } if (i == j) { - TEST_CHECK( gkyl_compare(spacetime_metric_prod[i][j], 1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spacetime_metric_prod[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spacetime_metric_prod[i][j], 1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spacetime_metric_prod[i][j], 0.0, 1e-10)); } } } @@ -403,16 +443,18 @@ test_gr_spacetime_schwarzschild_ho() spacetime->spacetime_metric_det_func(spacetime, 0.0, x, y, 0.0, &spacetime_metric_det); spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse_function); - TEST_CHECK( gkyl_compare(sqrt(-spacetime_metric_det), lapse_function * sqrt(spatial_metric_det), 1e-10) ); + TEST_CHECK(gkyl_compare( + sqrt(-spacetime_metric_det), lapse_function * sqrt(spatial_metric_det), 1e-10 + )); - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); - double ***spatial_christoffel = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_cov_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); + double ***spatial_christoffel = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_cov_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); - spatial_christoffel[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_cov_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); + spatial_christoffel[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_cov_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -421,8 +463,14 @@ test_gr_spacetime_schwarzschild_ho() } } - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_metric_der); - spacetime->spatial_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_christoffel); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_metric_der + ); + spacetime->spatial_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_christoffel + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -430,23 +478,25 @@ test_gr_spacetime_schwarzschild_ho() spatial_metric_cov_der[i][j][k] = spatial_metric_der[i][j][k]; for (int l = 0; l < 3; l++) { - spatial_metric_cov_der[i][j][k] -= spatial_christoffel[l][i][j] * spatial_metric[l][k]; - spatial_metric_cov_der[i][j][k] -= spatial_christoffel[l][i][k] * spatial_metric[j][l]; + spatial_metric_cov_der[i][j][k] -= + spatial_christoffel[l][i][j] * spatial_metric[l][k]; + spatial_metric_cov_der[i][j][k] -= + spatial_christoffel[l][i][k] * spatial_metric[j][l]; } - TEST_CHECK( gkyl_compare(spatial_metric_cov_der[i][j][k], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_metric_cov_der[i][j][k], 0.0, 1e-10)); } } } - double ***spacetime_metric_der = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_metric_cov_der = gkyl_malloc(sizeof(double**[4])); + double ***spacetime_metric_der = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_metric_cov_der = gkyl_malloc(sizeof(double **[4])); for (int i = 0; i < 4; i++) { - spacetime_metric_der[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_metric_cov_der[i] = gkyl_malloc(sizeof(double*[4])); + spacetime_metric_der[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_metric_cov_der[i] = gkyl_malloc(sizeof(double *[4])); for (int j = 0; j < 4; j++) { spacetime_metric_der[i][j] = gkyl_malloc(sizeof(double[4])); @@ -455,8 +505,14 @@ test_gr_spacetime_schwarzschild_ho() } } - spacetime->spacetime_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_metric_der); - spacetime->spacetime_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_christoffel); + spacetime->spacetime_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_metric_der + ); + spacetime->spacetime_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_christoffel + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -464,19 +520,21 @@ test_gr_spacetime_schwarzschild_ho() spacetime_metric_cov_der[i][j][k] = spacetime_metric_der[i][j][k]; for (int l = 0; l < 4; l++) { - spacetime_metric_cov_der[i][j][k] -= spacetime_christoffel[l][i][j] * spacetime_metric[l][k]; - spacetime_metric_cov_der[i][j][k] -= spacetime_christoffel[l][i][k] * spacetime_metric[j][l]; + spacetime_metric_cov_der[i][j][k] -= + spacetime_christoffel[l][i][j] * spacetime_metric[l][k]; + spacetime_metric_cov_der[i][j][k] -= + spacetime_christoffel[l][i][k] * spacetime_metric[j][l]; } - TEST_CHECK( gkyl_compare(spacetime_metric_cov_der[i][j][k], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spacetime_metric_cov_der[i][j][k], 0.0, 1e-10)); } } } - double **shift_vector_der = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); - double **shift_vector_cov_der = gkyl_malloc(sizeof(double*[3])); - double **shift_covector_cov_der = gkyl_malloc(sizeof(double*[3])); + double **shift_vector_der = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); + double **shift_vector_cov_der = gkyl_malloc(sizeof(double *[3])); + double **shift_covector_cov_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_vector_der[i] = gkyl_malloc(sizeof(double[3])); @@ -484,13 +542,19 @@ test_gr_spacetime_schwarzschild_ho() shift_vector_cov_der[i] = gkyl_malloc(sizeof(double[3])); shift_covector_cov_der[i] = gkyl_malloc(sizeof(double[3])); - for (int j = 0; j < 3; j++){ + for (int j = 0; j < 3; j++) { shift_covector_cov_der[i][j] = 0.0; } } - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &shift_vector_der); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &extrinsic_curvature); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &shift_vector_der + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &extrinsic_curvature + ); double *shift_vector = gkyl_malloc(sizeof(double[3])); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift_vector); @@ -515,40 +579,49 @@ test_gr_spacetime_schwarzschild_ho() for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - TEST_CHECK( gkyl_compare(2.0 * lapse_function * extrinsic_curvature[i][j], -(shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]), 1e-6) ); + TEST_CHECK(gkyl_compare( + 2.0 * lapse_function * extrinsic_curvature[i][j], + -(shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]), 1e-6 + )); } } - double **spacetime_ricci_tensor = gkyl_malloc(sizeof(double*[4])); + double **spacetime_ricci_tensor = gkyl_malloc(sizeof(double *[4])); double spacetime_ricci_scalar; for (int i = 0; i < 4; i++) { spacetime_ricci_tensor[i] = gkyl_malloc(sizeof(double[4])); } - spacetime->spacetime_ricci_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_ricci_tensor); - spacetime->spacetime_ricci_scalar_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_ricci_scalar); + spacetime->spacetime_ricci_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_ricci_tensor + ); + spacetime->spacetime_ricci_scalar_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_ricci_scalar + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - TEST_CHECK( gkyl_compare(spacetime_ricci_tensor[i][j], 0.0, 1e-3) ); + TEST_CHECK(gkyl_compare(spacetime_ricci_tensor[i][j], 0.0, 1e-3)); } } - TEST_CHECK( gkyl_compare(spacetime_ricci_scalar, 0.0, 1e-2) ); + TEST_CHECK(gkyl_compare(spacetime_ricci_scalar, 0.0, 1e-2)); - double ****spacetime_riemann_tensor = gkyl_malloc(sizeof(double***[4])); - double ****covariant_spacetime_riemann_tensor = gkyl_malloc(sizeof(double***[4])); - double ****spacetime_weyl_tensor = gkyl_malloc(sizeof(double***[4])); + double ****spacetime_riemann_tensor = gkyl_malloc(sizeof(double ***[4])); + double ****covariant_spacetime_riemann_tensor = gkyl_malloc(sizeof(double ***[4])); + double ****spacetime_weyl_tensor = gkyl_malloc(sizeof(double ***[4])); for (int i = 0; i < 4; i++) { - spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double**[4])); - covariant_spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double**[4])); - spacetime_weyl_tensor[i] = gkyl_malloc(sizeof(double**[4])); + spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double **[4])); + covariant_spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double **[4])); + spacetime_weyl_tensor[i] = gkyl_malloc(sizeof(double **[4])); for (int j = 0; j < 4; j++) { - spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[4])); - covariant_spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[4])); - spacetime_weyl_tensor[i][j] = gkyl_malloc(sizeof(double*[4])); + spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[4])); + covariant_spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[4])); + spacetime_weyl_tensor[i][j] = gkyl_malloc(sizeof(double *[4])); for (int k = 0; k < 4; k++) { spacetime_riemann_tensor[i][j][k] = gkyl_malloc(sizeof(double[4])); @@ -562,15 +635,22 @@ test_gr_spacetime_schwarzschild_ho() } } - spacetime->spacetime_riemann_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_riemann_tensor); - spacetime->spacetime_weyl_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_weyl_tensor); + spacetime->spacetime_riemann_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_riemann_tensor + ); + spacetime->spacetime_weyl_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_weyl_tensor + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { for (int m = 0; m < 4; m++) { - covariant_spacetime_riemann_tensor[i][j][k][l] += spacetime_metric[i][m] * spacetime_riemann_tensor[m][j][k][l]; + covariant_spacetime_riemann_tensor[i][j][k][l] += + spacetime_metric[i][m] * spacetime_riemann_tensor[m][j][k][l]; } } } @@ -581,7 +661,10 @@ test_gr_spacetime_schwarzschild_ho() for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { - TEST_CHECK( gkyl_compare(covariant_spacetime_riemann_tensor[i][j][k][l], spacetime_weyl_tensor[i][j][k][l], 1e-2) ); + TEST_CHECK(gkyl_compare( + covariant_spacetime_riemann_tensor[i][j][k][l], spacetime_weyl_tensor[i][j][k][l], + 1e-2 + )); } } } @@ -590,7 +673,7 @@ test_gr_spacetime_schwarzschild_ho() bool in_excision_region; spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - TEST_CHECK( (in_excision_region == false) ); + TEST_CHECK((in_excision_region == false)); for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric[i]); @@ -600,7 +683,7 @@ test_gr_spacetime_schwarzschild_ho() gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_vector_cov_der[i]); gkyl_free(shift_covector_cov_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); gkyl_free(spatial_christoffel[i][j]); @@ -659,12 +742,11 @@ test_gr_spacetime_schwarzschild_ho() gkyl_free(spacetime_riemann_tensor); gkyl_free(covariant_spacetime_riemann_tensor); gkyl_free(spacetime_weyl_tensor); - } - else { + } else { bool in_excision_region; spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - TEST_CHECK( (in_excision_region == true) ); + TEST_CHECK((in_excision_region == true)); } } } @@ -672,8 +754,7 @@ test_gr_spacetime_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_spacetime_kerr_ho() +void test_gr_spacetime_kerr_ho() { struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); @@ -683,9 +764,9 @@ test_gr_spacetime_kerr_ho() double y = 0.1 * y_ind; if (sqrt((x * x) + (y * y)) > 0.1 * (1.0 + sqrt(0.19))) { - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_prod = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_prod = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); @@ -697,9 +778,9 @@ test_gr_spacetime_kerr_ho() } } - double **spacetime_metric = gkyl_malloc(sizeof(double*[4])); - double **inv_spacetime_metric = gkyl_malloc(sizeof(double*[4])); - double **spacetime_metric_prod = gkyl_malloc(sizeof(double*[4])); + double **spacetime_metric = gkyl_malloc(sizeof(double *[4])); + double **inv_spacetime_metric = gkyl_malloc(sizeof(double *[4])); + double **spacetime_metric_prod = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_metric[i] = gkyl_malloc(sizeof(double[4])); @@ -715,7 +796,9 @@ test_gr_spacetime_kerr_ho() spacetime->spacetime_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spacetime_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); - spacetime->spacetime_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spacetime_metric); + spacetime->spacetime_inv_metric_tensor_func( + spacetime, 0.0, x, y, 0.0, &inv_spacetime_metric + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -724,10 +807,9 @@ test_gr_spacetime_kerr_ho() } if (i == j) { - TEST_CHECK( gkyl_compare(spatial_metric_prod[i][j], 1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spatial_metric_prod[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_metric_prod[i][j], 1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spatial_metric_prod[i][j], 0.0, 1e-10)); } } } @@ -739,10 +821,9 @@ test_gr_spacetime_kerr_ho() } if (i == j) { - TEST_CHECK( gkyl_compare(spacetime_metric_prod[i][j], 1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spacetime_metric_prod[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spacetime_metric_prod[i][j], 1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spacetime_metric_prod[i][j], 0.0, 1e-10)); } } } @@ -755,16 +836,18 @@ test_gr_spacetime_kerr_ho() spacetime->spacetime_metric_det_func(spacetime, 0.0, x, y, 0.0, &spacetime_metric_det); spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse_function); - TEST_CHECK( gkyl_compare(sqrt(-spacetime_metric_det), lapse_function * sqrt(spatial_metric_det), 1e-10) ); + TEST_CHECK(gkyl_compare( + sqrt(-spacetime_metric_det), lapse_function * sqrt(spatial_metric_det), 1e-10 + )); - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); - double ***spatial_christoffel = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_cov_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); + double ***spatial_christoffel = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_cov_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); - spatial_christoffel[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_cov_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); + spatial_christoffel[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_cov_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -773,8 +856,14 @@ test_gr_spacetime_kerr_ho() } } - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_metric_der); - spacetime->spatial_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_christoffel); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_metric_der + ); + spacetime->spatial_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_christoffel + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -782,23 +871,25 @@ test_gr_spacetime_kerr_ho() spatial_metric_cov_der[i][j][k] = spatial_metric_der[i][j][k]; for (int l = 0; l < 3; l++) { - spatial_metric_cov_der[i][j][k] -= spatial_christoffel[l][i][j] * spatial_metric[l][k]; - spatial_metric_cov_der[i][j][k] -= spatial_christoffel[l][i][k] * spatial_metric[j][l]; + spatial_metric_cov_der[i][j][k] -= + spatial_christoffel[l][i][j] * spatial_metric[l][k]; + spatial_metric_cov_der[i][j][k] -= + spatial_christoffel[l][i][k] * spatial_metric[j][l]; } - TEST_CHECK( gkyl_compare(spatial_metric_cov_der[i][j][k], 0.0, 1e-9) ); + TEST_CHECK(gkyl_compare(spatial_metric_cov_der[i][j][k], 0.0, 1e-9)); } } } - double ***spacetime_metric_der = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_metric_cov_der = gkyl_malloc(sizeof(double**[4])); + double ***spacetime_metric_der = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_metric_cov_der = gkyl_malloc(sizeof(double **[4])); for (int i = 0; i < 4; i++) { - spacetime_metric_der[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_metric_cov_der[i] = gkyl_malloc(sizeof(double*[4])); + spacetime_metric_der[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_metric_cov_der[i] = gkyl_malloc(sizeof(double *[4])); for (int j = 0; j < 4; j++) { spacetime_metric_der[i][j] = gkyl_malloc(sizeof(double[4])); @@ -807,8 +898,14 @@ test_gr_spacetime_kerr_ho() } } - spacetime->spacetime_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_metric_der); - spacetime->spacetime_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_christoffel); + spacetime->spacetime_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_metric_der + ); + spacetime->spacetime_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_christoffel + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -816,19 +913,21 @@ test_gr_spacetime_kerr_ho() spacetime_metric_cov_der[i][j][k] = spacetime_metric_der[i][j][k]; for (int l = 0; l < 4; l++) { - spacetime_metric_cov_der[i][j][k] -= spacetime_christoffel[l][i][j] * spacetime_metric[l][k]; - spacetime_metric_cov_der[i][j][k] -= spacetime_christoffel[l][i][k] * spacetime_metric[j][l]; + spacetime_metric_cov_der[i][j][k] -= + spacetime_christoffel[l][i][j] * spacetime_metric[l][k]; + spacetime_metric_cov_der[i][j][k] -= + spacetime_christoffel[l][i][k] * spacetime_metric[j][l]; } - TEST_CHECK( gkyl_compare(spacetime_metric_cov_der[i][j][k], 0.0, 1e-9) ); + TEST_CHECK(gkyl_compare(spacetime_metric_cov_der[i][j][k], 0.0, 1e-9)); } } } - double **shift_vector_der = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); - double **shift_vector_cov_der = gkyl_malloc(sizeof(double*[3])); - double **shift_covector_cov_der = gkyl_malloc(sizeof(double*[3])); + double **shift_vector_der = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); + double **shift_vector_cov_der = gkyl_malloc(sizeof(double *[3])); + double **shift_covector_cov_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_vector_der[i] = gkyl_malloc(sizeof(double[3])); @@ -836,13 +935,19 @@ test_gr_spacetime_kerr_ho() shift_vector_cov_der[i] = gkyl_malloc(sizeof(double[3])); shift_covector_cov_der[i] = gkyl_malloc(sizeof(double[3])); - for (int j = 0; j < 3; j++){ + for (int j = 0; j < 3; j++) { shift_covector_cov_der[i][j] = 0.0; } } - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &shift_vector_der); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &extrinsic_curvature); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &shift_vector_der + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &extrinsic_curvature + ); double *shift_vector = gkyl_malloc(sizeof(double[3])); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift_vector); @@ -867,40 +972,49 @@ test_gr_spacetime_kerr_ho() for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - TEST_CHECK( gkyl_compare(2.0 * lapse_function * extrinsic_curvature[i][j], -(shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]), 1e-6) ); + TEST_CHECK(gkyl_compare( + 2.0 * lapse_function * extrinsic_curvature[i][j], + -(shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]), 1e-6 + )); } } - double **spacetime_ricci_tensor = gkyl_malloc(sizeof(double*[4])); + double **spacetime_ricci_tensor = gkyl_malloc(sizeof(double *[4])); double spacetime_ricci_scalar; for (int i = 0; i < 4; i++) { spacetime_ricci_tensor[i] = gkyl_malloc(sizeof(double[4])); } - spacetime->spacetime_ricci_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_ricci_tensor); - spacetime->spacetime_ricci_scalar_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_ricci_scalar); + spacetime->spacetime_ricci_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_ricci_tensor + ); + spacetime->spacetime_ricci_scalar_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_ricci_scalar + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - TEST_CHECK( gkyl_compare(spacetime_ricci_tensor[i][j], 0.0, 1e-3) ); + TEST_CHECK(gkyl_compare(spacetime_ricci_tensor[i][j], 0.0, 1e-3)); } } - TEST_CHECK( gkyl_compare(spacetime_ricci_scalar, 0.0, 1e-2) ); + TEST_CHECK(gkyl_compare(spacetime_ricci_scalar, 0.0, 1e-2)); - double ****spacetime_riemann_tensor = gkyl_malloc(sizeof(double***[4])); - double ****covariant_spacetime_riemann_tensor = gkyl_malloc(sizeof(double***[4])); - double ****spacetime_weyl_tensor = gkyl_malloc(sizeof(double***[4])); + double ****spacetime_riemann_tensor = gkyl_malloc(sizeof(double ***[4])); + double ****covariant_spacetime_riemann_tensor = gkyl_malloc(sizeof(double ***[4])); + double ****spacetime_weyl_tensor = gkyl_malloc(sizeof(double ***[4])); for (int i = 0; i < 4; i++) { - spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double**[4])); - covariant_spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double**[4])); - spacetime_weyl_tensor[i] = gkyl_malloc(sizeof(double**[4])); + spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double **[4])); + covariant_spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double **[4])); + spacetime_weyl_tensor[i] = gkyl_malloc(sizeof(double **[4])); for (int j = 0; j < 4; j++) { - spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[4])); - covariant_spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[4])); - spacetime_weyl_tensor[i][j] = gkyl_malloc(sizeof(double*[4])); + spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[4])); + covariant_spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[4])); + spacetime_weyl_tensor[i][j] = gkyl_malloc(sizeof(double *[4])); for (int k = 0; k < 4; k++) { spacetime_riemann_tensor[i][j][k] = gkyl_malloc(sizeof(double[4])); @@ -914,15 +1028,22 @@ test_gr_spacetime_kerr_ho() } } - spacetime->spacetime_riemann_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_riemann_tensor); - spacetime->spacetime_weyl_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_weyl_tensor); + spacetime->spacetime_riemann_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_riemann_tensor + ); + spacetime->spacetime_weyl_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_weyl_tensor + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { for (int m = 0; m < 4; m++) { - covariant_spacetime_riemann_tensor[i][j][k][l] += spacetime_metric[i][m] * spacetime_riemann_tensor[m][j][k][l]; + covariant_spacetime_riemann_tensor[i][j][k][l] += + spacetime_metric[i][m] * spacetime_riemann_tensor[m][j][k][l]; } } } @@ -933,7 +1054,10 @@ test_gr_spacetime_kerr_ho() for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { - TEST_CHECK( gkyl_compare(covariant_spacetime_riemann_tensor[i][j][k][l], spacetime_weyl_tensor[i][j][k][l], 1e-2) ); + TEST_CHECK(gkyl_compare( + covariant_spacetime_riemann_tensor[i][j][k][l], spacetime_weyl_tensor[i][j][k][l], + 1e-2 + )); } } } @@ -942,7 +1066,7 @@ test_gr_spacetime_kerr_ho() bool in_excision_region; spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - TEST_CHECK( (in_excision_region == false) ); + TEST_CHECK((in_excision_region == false)); for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric[i]); @@ -952,7 +1076,7 @@ test_gr_spacetime_kerr_ho() gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_vector_cov_der[i]); gkyl_free(shift_covector_cov_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); gkyl_free(spatial_christoffel[i][j]); @@ -1011,12 +1135,11 @@ test_gr_spacetime_kerr_ho() gkyl_free(spacetime_riemann_tensor); gkyl_free(covariant_spacetime_riemann_tensor); gkyl_free(spacetime_weyl_tensor); - } - else { + } else { bool in_excision_region; spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - TEST_CHECK( (in_excision_region == true) ); + TEST_CHECK((in_excision_region == true)); } } } @@ -1024,8 +1147,7 @@ test_gr_spacetime_kerr_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_spacetime_neutronstar_static_ho() +void test_gr_spacetime_neutronstar_static_ho() { double mass = 0.1; double spin = 0.0; @@ -1035,13 +1157,20 @@ test_gr_spacetime_neutronstar_static_ho() double alpha = 5.0; double beta = pow(-0.36 + (1.48 * pow(sqrt(alpha), 0.65)), 3.0); - double gamma = pow(-4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), 4.0); + double gamma = + pow(-4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), 4.0); - double mass_quadrupole = -alpha * (spin_dimensionless * spin_dimensionless) * (mass * mass * mass); - double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass); - double mass_hexadecapole = gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass * mass); + double mass_quadrupole = + -alpha * (spin_dimensionless * spin_dimensionless) * (mass * mass * mass); + double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass); + double mass_hexadecapole = + gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass * mass); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, 0.0, 0.0, 0.0); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, 0.0, 0.0, 0.0 + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1049,9 +1178,9 @@ test_gr_spacetime_neutronstar_static_ho() double y = 0.1 * y_ind; if (sqrt((x * x) + (y * y)) > 0.2) { - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_prod = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_prod = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); @@ -1063,9 +1192,9 @@ test_gr_spacetime_neutronstar_static_ho() } } - double **spacetime_metric = gkyl_malloc(sizeof(double*[4])); - double **inv_spacetime_metric = gkyl_malloc(sizeof(double*[4])); - double **spacetime_metric_prod = gkyl_malloc(sizeof(double*[4])); + double **spacetime_metric = gkyl_malloc(sizeof(double *[4])); + double **inv_spacetime_metric = gkyl_malloc(sizeof(double *[4])); + double **spacetime_metric_prod = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_metric[i] = gkyl_malloc(sizeof(double[4])); @@ -1081,7 +1210,9 @@ test_gr_spacetime_neutronstar_static_ho() spacetime->spacetime_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spacetime_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); - spacetime->spacetime_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spacetime_metric); + spacetime->spacetime_inv_metric_tensor_func( + spacetime, 0.0, x, y, 0.0, &inv_spacetime_metric + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1090,10 +1221,9 @@ test_gr_spacetime_neutronstar_static_ho() } if (i == j) { - TEST_CHECK( gkyl_compare(spatial_metric_prod[i][j], 1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spatial_metric_prod[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_metric_prod[i][j], 1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spatial_metric_prod[i][j], 0.0, 1e-10)); } } } @@ -1105,10 +1235,9 @@ test_gr_spacetime_neutronstar_static_ho() } if (i == j) { - TEST_CHECK( gkyl_compare(spacetime_metric_prod[i][j], 1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spacetime_metric_prod[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spacetime_metric_prod[i][j], 1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spacetime_metric_prod[i][j], 0.0, 1e-10)); } } } @@ -1121,16 +1250,18 @@ test_gr_spacetime_neutronstar_static_ho() spacetime->spacetime_metric_det_func(spacetime, 0.0, x, y, 0.0, &spacetime_metric_det); spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse_function); - TEST_CHECK( gkyl_compare(sqrt(-spacetime_metric_det), lapse_function * sqrt(spatial_metric_det), 1e-10) ); + TEST_CHECK(gkyl_compare( + sqrt(-spacetime_metric_det), lapse_function * sqrt(spatial_metric_det), 1e-10 + )); - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); - double ***spatial_christoffel = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_cov_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); + double ***spatial_christoffel = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_cov_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); - spatial_christoffel[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_cov_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); + spatial_christoffel[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_cov_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1139,8 +1270,14 @@ test_gr_spacetime_neutronstar_static_ho() } } - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_metric_der); - spacetime->spatial_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_christoffel); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_metric_der + ); + spacetime->spatial_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_christoffel + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1148,23 +1285,25 @@ test_gr_spacetime_neutronstar_static_ho() spatial_metric_cov_der[i][j][k] = spatial_metric_der[i][j][k]; for (int l = 0; l < 3; l++) { - spatial_metric_cov_der[i][j][k] -= spatial_christoffel[l][i][j] * spatial_metric[l][k]; - spatial_metric_cov_der[i][j][k] -= spatial_christoffel[l][i][k] * spatial_metric[j][l]; + spatial_metric_cov_der[i][j][k] -= + spatial_christoffel[l][i][j] * spatial_metric[l][k]; + spatial_metric_cov_der[i][j][k] -= + spatial_christoffel[l][i][k] * spatial_metric[j][l]; } - TEST_CHECK( gkyl_compare(spatial_metric_cov_der[i][j][k], 0.0, 1e-6) ); + TEST_CHECK(gkyl_compare(spatial_metric_cov_der[i][j][k], 0.0, 1e-6)); } } } - double ***spacetime_metric_der = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_metric_cov_der = gkyl_malloc(sizeof(double**[4])); + double ***spacetime_metric_der = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_metric_cov_der = gkyl_malloc(sizeof(double **[4])); for (int i = 0; i < 4; i++) { - spacetime_metric_der[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_metric_cov_der[i] = gkyl_malloc(sizeof(double*[4])); + spacetime_metric_der[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_metric_cov_der[i] = gkyl_malloc(sizeof(double *[4])); for (int j = 0; j < 4; j++) { spacetime_metric_der[i][j] = gkyl_malloc(sizeof(double[4])); @@ -1173,8 +1312,14 @@ test_gr_spacetime_neutronstar_static_ho() } } - spacetime->spacetime_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_metric_der); - spacetime->spacetime_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_christoffel); + spacetime->spacetime_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_metric_der + ); + spacetime->spacetime_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_christoffel + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -1182,19 +1327,21 @@ test_gr_spacetime_neutronstar_static_ho() spacetime_metric_cov_der[i][j][k] = spacetime_metric_der[i][j][k]; for (int l = 0; l < 4; l++) { - spacetime_metric_cov_der[i][j][k] -= spacetime_christoffel[l][i][j] * spacetime_metric[l][k]; - spacetime_metric_cov_der[i][j][k] -= spacetime_christoffel[l][i][k] * spacetime_metric[j][l]; + spacetime_metric_cov_der[i][j][k] -= + spacetime_christoffel[l][i][j] * spacetime_metric[l][k]; + spacetime_metric_cov_der[i][j][k] -= + spacetime_christoffel[l][i][k] * spacetime_metric[j][l]; } - TEST_CHECK( gkyl_compare(spacetime_metric_cov_der[i][j][k], 0.0, 1e-6) ); + TEST_CHECK(gkyl_compare(spacetime_metric_cov_der[i][j][k], 0.0, 1e-6)); } } } - double **shift_vector_der = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); - double **shift_vector_cov_der = gkyl_malloc(sizeof(double*[3])); - double **shift_covector_cov_der = gkyl_malloc(sizeof(double*[3])); + double **shift_vector_der = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); + double **shift_vector_cov_der = gkyl_malloc(sizeof(double *[3])); + double **shift_covector_cov_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_vector_der[i] = gkyl_malloc(sizeof(double[3])); @@ -1202,13 +1349,19 @@ test_gr_spacetime_neutronstar_static_ho() shift_vector_cov_der[i] = gkyl_malloc(sizeof(double[3])); shift_covector_cov_der[i] = gkyl_malloc(sizeof(double[3])); - for (int j = 0; j < 3; j++){ + for (int j = 0; j < 3; j++) { shift_covector_cov_der[i][j] = 0.0; } } - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &shift_vector_der); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &extrinsic_curvature); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &shift_vector_der + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &extrinsic_curvature + ); double *shift_vector = gkyl_malloc(sizeof(double[3])); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift_vector); @@ -1233,14 +1386,17 @@ test_gr_spacetime_neutronstar_static_ho() for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - TEST_CHECK( gkyl_compare(2.0 * lapse_function * extrinsic_curvature[i][j], -(shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]), 1e-6) ); + TEST_CHECK(gkyl_compare( + 2.0 * lapse_function * extrinsic_curvature[i][j], + -(shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]), 1e-6 + )); } } bool in_excision_region; spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - TEST_CHECK( (in_excision_region == false) ); + TEST_CHECK((in_excision_region == false)); for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric[i]); @@ -1250,7 +1406,7 @@ test_gr_spacetime_neutronstar_static_ho() gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_vector_cov_der[i]); gkyl_free(shift_covector_cov_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); gkyl_free(spatial_christoffel[i][j]); @@ -1292,12 +1448,11 @@ test_gr_spacetime_neutronstar_static_ho() gkyl_free(spacetime_metric_der); gkyl_free(spacetime_christoffel); gkyl_free(spacetime_metric_cov_der); - } - else { + } else { bool in_excision_region; spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - TEST_CHECK( (in_excision_region == true) ); + TEST_CHECK((in_excision_region == true)); } } } @@ -1305,8 +1460,7 @@ test_gr_spacetime_neutronstar_static_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_spacetime_neutronstar_spinning_ho() +void test_gr_spacetime_neutronstar_spinning_ho() { double mass = 0.1; double spin = -0.12; @@ -1316,13 +1470,20 @@ test_gr_spacetime_neutronstar_spinning_ho() double alpha = 5.0; double beta = pow(-0.36 + (1.48 * pow(sqrt(alpha), 0.65)), 3.0); - double gamma = pow(-4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), 4.0); + double gamma = + pow(-4.749 + (0.27613 * pow(sqrt(alpha), 1.5146)) + (5.5168 * pow(sqrt(alpha), 0.22229)), 4.0); - double mass_quadrupole = -alpha * (spin_dimensionless * spin_dimensionless) * (mass * mass * mass); - double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass); - double mass_hexadecapole = gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * (mass * mass * mass * mass * mass); + double mass_quadrupole = + -alpha * (spin_dimensionless * spin_dimensionless) * (mass * mass * mass); + double spin_octupole = -beta * (spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass); + double mass_hexadecapole = + gamma * (spin_dimensionless * spin_dimensionless * spin_dimensionless * spin_dimensionless) * + (mass * mass * mass * mass * mass); - struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new(false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, 0.0, 0.0, 0.0); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_neutronstar_new( + false, mass, spin, mass_quadrupole, spin_octupole, mass_hexadecapole, 0.0, 0.0, 0.0 + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1330,9 +1491,9 @@ test_gr_spacetime_neutronstar_spinning_ho() double y = 0.1 * y_ind; if (sqrt((x * x) + (y * y)) > 0.2) { - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_prod = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_prod = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); @@ -1344,9 +1505,9 @@ test_gr_spacetime_neutronstar_spinning_ho() } } - double **spacetime_metric = gkyl_malloc(sizeof(double*[4])); - double **inv_spacetime_metric = gkyl_malloc(sizeof(double*[4])); - double **spacetime_metric_prod = gkyl_malloc(sizeof(double*[4])); + double **spacetime_metric = gkyl_malloc(sizeof(double *[4])); + double **inv_spacetime_metric = gkyl_malloc(sizeof(double *[4])); + double **spacetime_metric_prod = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_metric[i] = gkyl_malloc(sizeof(double[4])); @@ -1362,7 +1523,9 @@ test_gr_spacetime_neutronstar_spinning_ho() spacetime->spacetime_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spacetime_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); - spacetime->spacetime_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spacetime_metric); + spacetime->spacetime_inv_metric_tensor_func( + spacetime, 0.0, x, y, 0.0, &inv_spacetime_metric + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1371,10 +1534,9 @@ test_gr_spacetime_neutronstar_spinning_ho() } if (i == j) { - TEST_CHECK( gkyl_compare(spatial_metric_prod[i][j], 1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spatial_metric_prod[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_metric_prod[i][j], 1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spatial_metric_prod[i][j], 0.0, 1e-10)); } } } @@ -1386,10 +1548,9 @@ test_gr_spacetime_neutronstar_spinning_ho() } if (i == j) { - TEST_CHECK( gkyl_compare(spacetime_metric_prod[i][j], 1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spacetime_metric_prod[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spacetime_metric_prod[i][j], 1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spacetime_metric_prod[i][j], 0.0, 1e-10)); } } } @@ -1402,16 +1563,18 @@ test_gr_spacetime_neutronstar_spinning_ho() spacetime->spacetime_metric_det_func(spacetime, 0.0, x, y, 0.0, &spacetime_metric_det); spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse_function); - TEST_CHECK( gkyl_compare(sqrt(-spacetime_metric_det), lapse_function * sqrt(spatial_metric_det), 1e-10) ); + TEST_CHECK(gkyl_compare( + sqrt(-spacetime_metric_det), lapse_function * sqrt(spatial_metric_det), 1e-10 + )); - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); - double ***spatial_christoffel = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_cov_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); + double ***spatial_christoffel = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_cov_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); - spatial_christoffel[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_cov_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); + spatial_christoffel[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_cov_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1420,8 +1583,14 @@ test_gr_spacetime_neutronstar_spinning_ho() } } - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_metric_der); - spacetime->spatial_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_christoffel); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_metric_der + ); + spacetime->spatial_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_christoffel + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1429,23 +1598,25 @@ test_gr_spacetime_neutronstar_spinning_ho() spatial_metric_cov_der[i][j][k] = spatial_metric_der[i][j][k]; for (int l = 0; l < 3; l++) { - spatial_metric_cov_der[i][j][k] -= spatial_christoffel[l][i][j] * spatial_metric[l][k]; - spatial_metric_cov_der[i][j][k] -= spatial_christoffel[l][i][k] * spatial_metric[j][l]; + spatial_metric_cov_der[i][j][k] -= + spatial_christoffel[l][i][j] * spatial_metric[l][k]; + spatial_metric_cov_der[i][j][k] -= + spatial_christoffel[l][i][k] * spatial_metric[j][l]; } - TEST_CHECK( gkyl_compare(spatial_metric_cov_der[i][j][k], 0.0, 1e-6) ); + TEST_CHECK(gkyl_compare(spatial_metric_cov_der[i][j][k], 0.0, 1e-6)); } } } - double ***spacetime_metric_der = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_metric_cov_der = gkyl_malloc(sizeof(double**[4])); + double ***spacetime_metric_der = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_metric_cov_der = gkyl_malloc(sizeof(double **[4])); for (int i = 0; i < 4; i++) { - spacetime_metric_der[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_metric_cov_der[i] = gkyl_malloc(sizeof(double*[4])); + spacetime_metric_der[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_metric_cov_der[i] = gkyl_malloc(sizeof(double *[4])); for (int j = 0; j < 4; j++) { spacetime_metric_der[i][j] = gkyl_malloc(sizeof(double[4])); @@ -1454,8 +1625,14 @@ test_gr_spacetime_neutronstar_spinning_ho() } } - spacetime->spacetime_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_metric_der); - spacetime->spacetime_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_christoffel); + spacetime->spacetime_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_metric_der + ); + spacetime->spacetime_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_christoffel + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -1463,19 +1640,21 @@ test_gr_spacetime_neutronstar_spinning_ho() spacetime_metric_cov_der[i][j][k] = spacetime_metric_der[i][j][k]; for (int l = 0; l < 4; l++) { - spacetime_metric_cov_der[i][j][k] -= spacetime_christoffel[l][i][j] * spacetime_metric[l][k]; - spacetime_metric_cov_der[i][j][k] -= spacetime_christoffel[l][i][k] * spacetime_metric[j][l]; + spacetime_metric_cov_der[i][j][k] -= + spacetime_christoffel[l][i][j] * spacetime_metric[l][k]; + spacetime_metric_cov_der[i][j][k] -= + spacetime_christoffel[l][i][k] * spacetime_metric[j][l]; } - TEST_CHECK( gkyl_compare(spacetime_metric_cov_der[i][j][k], 0.0, 1e-6) ); + TEST_CHECK(gkyl_compare(spacetime_metric_cov_der[i][j][k], 0.0, 1e-6)); } } } - double **shift_vector_der = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); - double **shift_vector_cov_der = gkyl_malloc(sizeof(double*[3])); - double **shift_covector_cov_der = gkyl_malloc(sizeof(double*[3])); + double **shift_vector_der = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); + double **shift_vector_cov_der = gkyl_malloc(sizeof(double *[3])); + double **shift_covector_cov_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_vector_der[i] = gkyl_malloc(sizeof(double[3])); @@ -1483,13 +1662,19 @@ test_gr_spacetime_neutronstar_spinning_ho() shift_vector_cov_der[i] = gkyl_malloc(sizeof(double[3])); shift_covector_cov_der[i] = gkyl_malloc(sizeof(double[3])); - for (int j = 0; j < 3; j++){ + for (int j = 0; j < 3; j++) { shift_covector_cov_der[i][j] = 0.0; } } - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &shift_vector_der); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &extrinsic_curvature); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &shift_vector_der + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &extrinsic_curvature + ); double *shift_vector = gkyl_malloc(sizeof(double[3])); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift_vector); @@ -1514,14 +1699,17 @@ test_gr_spacetime_neutronstar_spinning_ho() for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - TEST_CHECK( gkyl_compare(2.0 * lapse_function * extrinsic_curvature[i][j], -(shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]), 1e-6) ); + TEST_CHECK(gkyl_compare( + 2.0 * lapse_function * extrinsic_curvature[i][j], + -(shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]), 1e-6 + )); } } bool in_excision_region; spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - TEST_CHECK( (in_excision_region == false) ); + TEST_CHECK((in_excision_region == false)); for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric[i]); @@ -1531,7 +1719,7 @@ test_gr_spacetime_neutronstar_spinning_ho() gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_vector_cov_der[i]); gkyl_free(shift_covector_cov_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); gkyl_free(spatial_christoffel[i][j]); @@ -1573,12 +1761,11 @@ test_gr_spacetime_neutronstar_spinning_ho() gkyl_free(spacetime_metric_der); gkyl_free(spacetime_christoffel); gkyl_free(spacetime_metric_cov_der); - } - else { + } else { bool in_excision_region; spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - TEST_CHECK( (in_excision_region == true) ); + TEST_CHECK((in_excision_region == true)); } } } @@ -1586,12 +1773,11 @@ test_gr_spacetime_neutronstar_spinning_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_spacetime_brill_lindquist_ho() +void test_gr_spacetime_brill_lindquist_ho() { double mass1 = 0.5; double mass2 = 0.5; - + double pos_x1 = -3.0; double pos_y1 = 0.0; double pos_z1 = 0.0; @@ -1600,17 +1786,20 @@ test_gr_spacetime_brill_lindquist_ho() double pos_y2 = 0.0; double pos_z2 = 0.0; - struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_new(false, mass1, mass2, pos_x1, pos_y1, pos_z1, pos_x2, pos_y2, pos_z2); + struct gkyl_gr_spacetime *spacetime = gkyl_gr_brill_lindquist_new( + false, mass1, mass2, pos_x1, pos_y1, pos_z1, pos_x2, pos_y2, pos_z2 + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { double x = 1.0 * x_ind; double y = 1.0 * y_ind; - if (sqrt(((x - 3.0) * (x - 3.0)) + (y * y)) > 1.0 && sqrt(((x + 3.0) * (x + 3.0)) + (y * y)) > 1.0) { - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_prod = gkyl_malloc(sizeof(double*[3])); + if (sqrt(((x - 3.0) * (x - 3.0)) + (y * y)) > 1.0 && + sqrt(((x + 3.0) * (x + 3.0)) + (y * y)) > 1.0) { + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_prod = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); @@ -1622,9 +1811,9 @@ test_gr_spacetime_brill_lindquist_ho() } } - double **spacetime_metric = gkyl_malloc(sizeof(double*[4])); - double **inv_spacetime_metric = gkyl_malloc(sizeof(double*[4])); - double **spacetime_metric_prod = gkyl_malloc(sizeof(double*[4])); + double **spacetime_metric = gkyl_malloc(sizeof(double *[4])); + double **inv_spacetime_metric = gkyl_malloc(sizeof(double *[4])); + double **spacetime_metric_prod = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_metric[i] = gkyl_malloc(sizeof(double[4])); @@ -1640,7 +1829,9 @@ test_gr_spacetime_brill_lindquist_ho() spacetime->spacetime_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spacetime_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); - spacetime->spacetime_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spacetime_metric); + spacetime->spacetime_inv_metric_tensor_func( + spacetime, 0.0, x, y, 0.0, &inv_spacetime_metric + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1649,10 +1840,9 @@ test_gr_spacetime_brill_lindquist_ho() } if (i == j) { - TEST_CHECK( gkyl_compare(spatial_metric_prod[i][j], 1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spatial_metric_prod[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spatial_metric_prod[i][j], 1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spatial_metric_prod[i][j], 0.0, 1e-10)); } } } @@ -1664,10 +1854,9 @@ test_gr_spacetime_brill_lindquist_ho() } if (i == j) { - TEST_CHECK( gkyl_compare(spacetime_metric_prod[i][j], 1.0, 1e-10) ); - } - else { - TEST_CHECK( gkyl_compare(spacetime_metric_prod[i][j], 0.0, 1e-10) ); + TEST_CHECK(gkyl_compare(spacetime_metric_prod[i][j], 1.0, 1e-10)); + } else { + TEST_CHECK(gkyl_compare(spacetime_metric_prod[i][j], 0.0, 1e-10)); } } } @@ -1680,16 +1869,18 @@ test_gr_spacetime_brill_lindquist_ho() spacetime->spacetime_metric_det_func(spacetime, 0.0, x, y, 0.0, &spacetime_metric_det); spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse_function); - TEST_CHECK( gkyl_compare(sqrt(-spacetime_metric_det), lapse_function * sqrt(spatial_metric_det), 1e-10) ); + TEST_CHECK(gkyl_compare( + sqrt(-spacetime_metric_det), lapse_function * sqrt(spatial_metric_det), 1e-10 + )); - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); - double ***spatial_christoffel = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_cov_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); + double ***spatial_christoffel = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_cov_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); - spatial_christoffel[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_cov_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); + spatial_christoffel[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_cov_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1698,8 +1889,14 @@ test_gr_spacetime_brill_lindquist_ho() } } - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_metric_der); - spacetime->spatial_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spatial_christoffel); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_metric_der + ); + spacetime->spatial_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &spatial_christoffel + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1707,23 +1904,25 @@ test_gr_spacetime_brill_lindquist_ho() spatial_metric_cov_der[i][j][k] = spatial_metric_der[i][j][k]; for (int l = 0; l < 3; l++) { - spatial_metric_cov_der[i][j][k] -= spatial_christoffel[l][i][j] * spatial_metric[l][k]; - spatial_metric_cov_der[i][j][k] -= spatial_christoffel[l][i][k] * spatial_metric[j][l]; + spatial_metric_cov_der[i][j][k] -= + spatial_christoffel[l][i][j] * spatial_metric[l][k]; + spatial_metric_cov_der[i][j][k] -= + spatial_christoffel[l][i][k] * spatial_metric[j][l]; } - TEST_CHECK( gkyl_compare(spatial_metric_cov_der[i][j][k], 0.0, 1e-6) ); + TEST_CHECK(gkyl_compare(spatial_metric_cov_der[i][j][k], 0.0, 1e-6)); } } } - double ***spacetime_metric_der = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_metric_cov_der = gkyl_malloc(sizeof(double**[4])); + double ***spacetime_metric_der = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_metric_cov_der = gkyl_malloc(sizeof(double **[4])); for (int i = 0; i < 4; i++) { - spacetime_metric_der[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_metric_cov_der[i] = gkyl_malloc(sizeof(double*[4])); + spacetime_metric_der[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_metric_cov_der[i] = gkyl_malloc(sizeof(double *[4])); for (int j = 0; j < 4; j++) { spacetime_metric_der[i][j] = gkyl_malloc(sizeof(double[4])); @@ -1732,8 +1931,14 @@ test_gr_spacetime_brill_lindquist_ho() } } - spacetime->spacetime_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_metric_der); - spacetime->spacetime_christoffel_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &spacetime_christoffel); + spacetime->spacetime_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_metric_der + ); + spacetime->spacetime_christoffel_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + pow(10.0, -6.0), &spacetime_christoffel + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -1741,19 +1946,21 @@ test_gr_spacetime_brill_lindquist_ho() spacetime_metric_cov_der[i][j][k] = spacetime_metric_der[i][j][k]; for (int l = 0; l < 4; l++) { - spacetime_metric_cov_der[i][j][k] -= spacetime_christoffel[l][i][j] * spacetime_metric[l][k]; - spacetime_metric_cov_der[i][j][k] -= spacetime_christoffel[l][i][k] * spacetime_metric[j][l]; + spacetime_metric_cov_der[i][j][k] -= + spacetime_christoffel[l][i][j] * spacetime_metric[l][k]; + spacetime_metric_cov_der[i][j][k] -= + spacetime_christoffel[l][i][k] * spacetime_metric[j][l]; } - TEST_CHECK( gkyl_compare(spacetime_metric_cov_der[i][j][k], 0.0, 1e-6) ); + TEST_CHECK(gkyl_compare(spacetime_metric_cov_der[i][j][k], 0.0, 1e-6)); } } } - double **shift_vector_der = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); - double **shift_vector_cov_der = gkyl_malloc(sizeof(double*[3])); - double **shift_covector_cov_der = gkyl_malloc(sizeof(double*[3])); + double **shift_vector_der = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); + double **shift_vector_cov_der = gkyl_malloc(sizeof(double *[3])); + double **shift_covector_cov_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_vector_der[i] = gkyl_malloc(sizeof(double[3])); @@ -1761,13 +1968,19 @@ test_gr_spacetime_brill_lindquist_ho() shift_vector_cov_der[i] = gkyl_malloc(sizeof(double[3])); shift_covector_cov_der[i] = gkyl_malloc(sizeof(double[3])); - for (int j = 0; j < 3; j++){ + for (int j = 0; j < 3; j++) { shift_covector_cov_der[i][j] = 0.0; } } - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &shift_vector_der); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &extrinsic_curvature); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &shift_vector_der + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &extrinsic_curvature + ); double *shift_vector = gkyl_malloc(sizeof(double[3])); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift_vector); @@ -1792,14 +2005,17 @@ test_gr_spacetime_brill_lindquist_ho() for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - TEST_CHECK( gkyl_compare(2.0 * lapse_function * extrinsic_curvature[i][j], -(shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]), 1e-6) ); + TEST_CHECK(gkyl_compare( + 2.0 * lapse_function * extrinsic_curvature[i][j], + -(shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]), 1e-6 + )); } } bool in_excision_region; spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - TEST_CHECK( (in_excision_region == false) ); + TEST_CHECK((in_excision_region == false)); for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric[i]); @@ -1809,7 +2025,7 @@ test_gr_spacetime_brill_lindquist_ho() gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_vector_cov_der[i]); gkyl_free(shift_covector_cov_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); gkyl_free(spatial_christoffel[i][j]); @@ -1851,12 +2067,11 @@ test_gr_spacetime_brill_lindquist_ho() gkyl_free(spacetime_metric_der); gkyl_free(spacetime_christoffel); gkyl_free(spacetime_metric_cov_der); - } - else { + } else { bool in_excision_region; spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - TEST_CHECK( (in_excision_region == true) ); + TEST_CHECK((in_excision_region == true)); } } } @@ -1865,11 +2080,11 @@ test_gr_spacetime_brill_lindquist_ho() } TEST_LIST = { - { "gr_spacetime_minkowski_ho", test_gr_spacetime_minkowski_ho }, - { "gr_spacetime_schwarzschild_ho", test_gr_spacetime_schwarzschild_ho }, - { "gr_spacetime_kerr_ho", test_gr_spacetime_kerr_ho }, - { "gr_spacetime_neutronstar_static_ho", test_gr_spacetime_neutronstar_static_ho }, - { "gr_spacetime_neutronstar_spinning_ho", test_gr_spacetime_neutronstar_spinning_ho }, - { "gr_spacetime_brill_lindquist_ho", test_gr_spacetime_brill_lindquist_ho }, - { NULL, NULL }, + {"gr_spacetime_minkowski_ho", test_gr_spacetime_minkowski_ho}, + {"gr_spacetime_schwarzschild_ho", test_gr_spacetime_schwarzschild_ho}, + {"gr_spacetime_kerr_ho", test_gr_spacetime_kerr_ho}, + {"gr_spacetime_neutronstar_static_ho", test_gr_spacetime_neutronstar_static_ho}, + {"gr_spacetime_neutronstar_spinning_ho", test_gr_spacetime_neutronstar_spinning_ho}, + {"gr_spacetime_brill_lindquist_ho", test_gr_spacetime_brill_lindquist_ho}, + {NULL, NULL} }; \ No newline at end of file diff --git a/moments/unit/ctest_ten_moment_nn_closure.c b/moments/unit/ctest_ten_moment_nn_closure.c index 5ca5c993ac..a82039a5f2 100644 --- a/moments/unit/ctest_ten_moment_nn_closure.c +++ b/moments/unit/ctest_ten_moment_nn_closure.c @@ -35,50 +35,58 @@ static const double tol = 1.0e-5; // Fill a ten-moment cell with zero bulk velocity so the pressure tensor equals // the conserved P-components directly (p_ij = P_ij - rho u_i u_j = P_ij). -static void -set_fluid(double f[10], double rho, double p11, double p12, double p13, double p22, double p23, double p33) +static void set_fluid( + double f[10], double rho, double p11, double p12, double p13, double p22, double p23, double p33 +) { f[TM_RHO] = rho; - f[TM_MX] = 0.0; f[TM_MY] = 0.0; f[TM_MZ] = 0.0; - f[TM_P11] = p11; f[TM_P12] = p12; f[TM_P13] = p13; - f[TM_P22] = p22; f[TM_P23] = p23; f[TM_P33] = p33; + f[TM_MX] = 0.0; + f[TM_MY] = 0.0; + f[TM_MZ] = 0.0; + f[TM_P11] = p11; + f[TM_P12] = p12; + f[TM_P13] = p13; + f[TM_P22] = p22; + f[TM_P23] = p23; + f[TM_P33] = p33; } -static void -set_em(double e[8], double bx, double by, double bz) +static void set_em(double e[8], double bx, double by, double bz) { for (int i = 0; i < 8; i++) { e[i] = 0.0; } - e[EM_BX] = bx; e[EM_BY] = by; e[EM_BZ] = bz; + e[EM_BX] = bx; + e[EM_BY] = by; + e[EM_BZ] = bz; } -static struct gkyl_ten_moment_nn_closure* -mk_closure_1d(int poly_order, double dx) +static struct gkyl_ten_moment_nn_closure *mk_closure_1d(int poly_order, double dx) { static struct gkyl_rect_grid grid; // cells = 1/dx so that the grid spacing is exactly dx. int cells = (int)(1.0 / dx + 0.5); - gkyl_rect_grid_init(&grid, 1, (double[]) { 0.0 }, (double[]) { 1.0 }, (int[]) { cells }); - return gkyl_ten_moment_nn_closure_new( (struct gkyl_ten_moment_nn_closure_inp) { - .grid = &grid, .poly_order = poly_order, .k0 = 1.0, .ann = 0 - }); + gkyl_rect_grid_init(&grid, 1, (double[]){0.0}, (double[]){1.0}, (int[]){cells}); + return gkyl_ten_moment_nn_closure_new((struct gkyl_ten_moment_nn_closure_inp + ){.grid = &grid, .poly_order = poly_order, .k0 = 1.0, .ann = 0}); } // Input/output feature counts for each supported configuration. -static void -test_nn_closure_dims_ho(void) +static void test_nn_closure_dims_ho(void) { struct gkyl_rect_grid grid1, grid2; - gkyl_rect_grid_init(&grid1, 1, (double[]) { 0.0 }, (double[]) { 1.0 }, (int[]) { 10 }); - gkyl_rect_grid_init(&grid2, 2, (double[]) { 0.0, 0.0 }, (double[]) { 1.0, 1.0 }, (int[]) { 10, 10 }); + gkyl_rect_grid_init(&grid1, 1, (double[]){0.0}, (double[]){1.0}, (int[]){10}); + gkyl_rect_grid_init(&grid2, 2, (double[]){0.0, 0.0}, (double[]){1.0, 1.0}, (int[]){10, 10}); struct gkyl_ten_moment_nn_closure *nn_1d_p1 = gkyl_ten_moment_nn_closure_new( - (struct gkyl_ten_moment_nn_closure_inp) { .grid = &grid1, .poly_order = 1, .k0 = 1.0, .ann = 0 }); + (struct gkyl_ten_moment_nn_closure_inp){.grid = &grid1, .poly_order = 1, .k0 = 1.0, .ann = 0} + ); struct gkyl_ten_moment_nn_closure *nn_1d_p2 = gkyl_ten_moment_nn_closure_new( - (struct gkyl_ten_moment_nn_closure_inp) { .grid = &grid1, .poly_order = 2, .k0 = 1.0, .ann = 0 }); + (struct gkyl_ten_moment_nn_closure_inp){.grid = &grid1, .poly_order = 2, .k0 = 1.0, .ann = 0} + ); struct gkyl_ten_moment_nn_closure *nn_2d_p1 = gkyl_ten_moment_nn_closure_new( - (struct gkyl_ten_moment_nn_closure_inp) { .grid = &grid2, .poly_order = 1, .k0 = 1.0, .ann = 0 }); + (struct gkyl_ten_moment_nn_closure_inp){.grid = &grid2, .poly_order = 1, .k0 = 1.0, .ann = 0} + ); TEST_CHECK(gkyl_ten_moment_nn_closure_n_in(nn_1d_p1) == 6); TEST_CHECK(gkyl_ten_moment_nn_closure_n_out(nn_1d_p1) == 4); @@ -94,8 +102,7 @@ test_nn_closure_dims_ho(void) // Uniform stencil, B along x: b = (1,0,0), p_par = p_xx, p_perp = (p_yy+p_zz)/2, // all gradients zero. -static void -test_nn_closure_geom_1d_p1_uniform_bx_ho(void) +static void test_nn_closure_geom_1d_p1_uniform_bx_ho(void) { struct gkyl_ten_moment_nn_closure *nn = mk_closure_1d(1, 0.1); @@ -105,35 +112,34 @@ test_nn_closure_geom_1d_p1_uniform_bx_ho(void) set_em(eL, 1.0, 0.0, 0.0); set_em(eU, 1.0, 0.0, 0.0); - const double *fluid_d[2] = { fL, fU }; - const double *em_d[2] = { eL, eU }; + const double *fluid_d[2] = {fL, fU}; + const double *em_d[2] = {eL, eU}; float in[6]; struct gkyl_ten_moment_nn_closure_geom geom; gkyl_ten_moment_nn_closure_geom_calc(nn, fluid_d, em_d, in, &geom); - TEST_CHECK( fabs(in[0] - 2.0) < tol ); // rho_avg - TEST_CHECK( fabs(in[1] - 0.0) < tol ); // drho_dx - TEST_CHECK( fabs(in[2] - 3.0) < tol ); // p_par = p_xx - TEST_CHECK( fabs(in[3] - 0.0) < tol ); // p_par_dx - TEST_CHECK( fabs(in[4] - 0.75) < tol ); // p_perp = (p_yy + p_zz)/2 - TEST_CHECK( fabs(in[5] - 0.0) < tol ); // p_perp_dx - - TEST_CHECK( fabs(geom.local_mag[0] - 1.0) < tol ); - TEST_CHECK( fabs(geom.local_mag[1] - 0.0) < tol ); - TEST_CHECK( fabs(geom.local_mag[2] - 0.0) < tol ); - TEST_CHECK( fabs(geom.local_mag_dx[0]) < tol ); - TEST_CHECK( fabs(geom.local_mag_dx[1]) < tol ); - TEST_CHECK( fabs(geom.local_mag_dx[2]) < tol ); - TEST_CHECK( fabs(geom.rho_avg - 2.0) < tol ); - TEST_CHECK( fabs(geom.B_avg[0] - 1.0) < tol ); + TEST_CHECK(fabs(in[0] - 2.0) < tol); // rho_avg + TEST_CHECK(fabs(in[1] - 0.0) < tol); // drho_dx + TEST_CHECK(fabs(in[2] - 3.0) < tol); // p_par = p_xx + TEST_CHECK(fabs(in[3] - 0.0) < tol); // p_par_dx + TEST_CHECK(fabs(in[4] - 0.75) < tol); // p_perp = (p_yy + p_zz)/2 + TEST_CHECK(fabs(in[5] - 0.0) < tol); // p_perp_dx + + TEST_CHECK(fabs(geom.local_mag[0] - 1.0) < tol); + TEST_CHECK(fabs(geom.local_mag[1] - 0.0) < tol); + TEST_CHECK(fabs(geom.local_mag[2] - 0.0) < tol); + TEST_CHECK(fabs(geom.local_mag_dx[0]) < tol); + TEST_CHECK(fabs(geom.local_mag_dx[1]) < tol); + TEST_CHECK(fabs(geom.local_mag_dx[2]) < tol); + TEST_CHECK(fabs(geom.rho_avg - 2.0) < tol); + TEST_CHECK(fabs(geom.B_avg[0] - 1.0) < tol); gkyl_ten_moment_nn_closure_release(nn); } // Uniform stencil, B along z: b = (0,0,1), p_par = p_zz, p_perp = (p_xx+p_yy)/2. -static void -test_nn_closure_geom_1d_p1_uniform_bz_ho(void) +static void test_nn_closure_geom_1d_p1_uniform_bz_ho(void) { struct gkyl_ten_moment_nn_closure *nn = mk_closure_1d(1, 0.1); @@ -143,25 +149,24 @@ test_nn_closure_geom_1d_p1_uniform_bz_ho(void) set_em(eL, 0.0, 0.0, 1.0); set_em(eU, 0.0, 0.0, 1.0); - const double *fluid_d[2] = { fL, fU }; - const double *em_d[2] = { eL, eU }; + const double *fluid_d[2] = {fL, fU}; + const double *em_d[2] = {eL, eU}; float in[6]; struct gkyl_ten_moment_nn_closure_geom geom; gkyl_ten_moment_nn_closure_geom_calc(nn, fluid_d, em_d, in, &geom); - TEST_CHECK( fabs(in[2] - 0.5) < tol ); // p_par = p_zz - TEST_CHECK( fabs(in[4] - 2.0) < tol ); // p_perp = (p_xx + p_yy)/2 = (3+1)/2 - TEST_CHECK( fabs(geom.local_mag[2] - 1.0) < tol ); - TEST_CHECK( fabs(geom.local_mag[0]) < tol ); + TEST_CHECK(fabs(in[2] - 0.5) < tol); // p_par = p_zz + TEST_CHECK(fabs(in[4] - 2.0) < tol); // p_perp = (p_xx + p_yy)/2 = (3+1)/2 + TEST_CHECK(fabs(geom.local_mag[2] - 1.0) < tol); + TEST_CHECK(fabs(geom.local_mag[0]) < tol); gkyl_ten_moment_nn_closure_release(nn); } // Uniform stencil, B at 45 deg in the x-y plane: b = (1,1,0)/sqrt(2). // p_par = 0.5 p_xx + 0.5 p_yy + p_xy, p_perp = (tr(p) - p_par)/2. -static void -test_nn_closure_geom_1d_p1_diagonal_b_ho(void) +static void test_nn_closure_geom_1d_p1_diagonal_b_ho(void) { struct gkyl_ten_moment_nn_closure *nn = mk_closure_1d(1, 0.1); @@ -172,8 +177,8 @@ test_nn_closure_geom_1d_p1_diagonal_b_ho(void) set_em(eL, 1.0, 1.0, 0.0); set_em(eU, 1.0, 1.0, 0.0); - const double *fluid_d[2] = { fL, fU }; - const double *em_d[2] = { eL, eU }; + const double *fluid_d[2] = {fL, fU}; + const double *em_d[2] = {eL, eU}; float in[6]; struct gkyl_ten_moment_nn_closure_geom geom; @@ -183,19 +188,18 @@ test_nn_closure_geom_1d_p1_diagonal_b_ho(void) double p_perp_exp = 0.5 * ((pxx + pyy + pzz) - p_par_exp); double inv_sqrt2 = 1.0 / sqrt(2.0); - TEST_CHECK( fabs(in[2] - p_par_exp) < tol ); - TEST_CHECK( fabs(in[4] - p_perp_exp) < tol ); - TEST_CHECK( fabs(geom.local_mag[0] - inv_sqrt2) < tol ); - TEST_CHECK( fabs(geom.local_mag[1] - inv_sqrt2) < tol ); - TEST_CHECK( fabs(geom.local_mag[2] - 0.0) < tol ); + TEST_CHECK(fabs(in[2] - p_par_exp) < tol); + TEST_CHECK(fabs(in[4] - p_perp_exp) < tol); + TEST_CHECK(fabs(geom.local_mag[0] - inv_sqrt2) < tol); + TEST_CHECK(fabs(geom.local_mag[1] - inv_sqrt2) < tol); + TEST_CHECK(fabs(geom.local_mag[2] - 0.0) < tol); gkyl_ten_moment_nn_closure_release(nn); } // Density gradient only: B and pressure uniform along x, density linear across // the stencil. drho_dx = (rho_U - rho_L)/dx; field-aligned pressure gradients 0. -static void -test_nn_closure_geom_1d_p1_density_gradient_ho(void) +static void test_nn_closure_geom_1d_p1_density_gradient_ho(void) { double dx = 0.1; struct gkyl_ten_moment_nn_closure *nn = mk_closure_1d(1, dx); @@ -206,25 +210,24 @@ test_nn_closure_geom_1d_p1_density_gradient_ho(void) set_em(eL, 1.0, 0.0, 0.0); set_em(eU, 1.0, 0.0, 0.0); - const double *fluid_d[2] = { fL, fU }; - const double *em_d[2] = { eL, eU }; + const double *fluid_d[2] = {fL, fU}; + const double *em_d[2] = {eL, eU}; float in[6]; struct gkyl_ten_moment_nn_closure_geom geom; gkyl_ten_moment_nn_closure_geom_calc(nn, fluid_d, em_d, in, &geom); - TEST_CHECK( fabs(in[0] - 2.0) < tol ); // rho_avg = (1+3)/2 - TEST_CHECK( fabs(in[1] - (2.0 / dx)) < tol ); // drho_dx = (3-1)/dx = 20 - TEST_CHECK( fabs(in[3] - 0.0) < tol ); // p_par_dx - TEST_CHECK( fabs(in[5] - 0.0) < tol ); // p_perp_dx + TEST_CHECK(fabs(in[0] - 2.0) < tol); // rho_avg = (1+3)/2 + TEST_CHECK(fabs(in[1] - (2.0 / dx)) < tol); // drho_dx = (3-1)/dx = 20 + TEST_CHECK(fabs(in[3] - 0.0) < tol); // p_par_dx + TEST_CHECK(fabs(in[5] - 0.0) < tol); // p_perp_dx gkyl_ten_moment_nn_closure_release(nn); } // Pressure gradient with B uniform along x. With b = (1,0,0) and uniform b, // p_par_dx = d(p_xx)/dx and p_perp_dx = 0.5( d tr(p)/dx - p_par_dx ). -static void -test_nn_closure_geom_1d_p1_pressure_gradient_ho(void) +static void test_nn_closure_geom_1d_p1_pressure_gradient_ho(void) { double dx = 0.1; struct gkyl_ten_moment_nn_closure *nn = mk_closure_1d(1, dx); @@ -235,28 +238,27 @@ test_nn_closure_geom_1d_p1_pressure_gradient_ho(void) set_em(eL, 1.0, 0.0, 0.0); set_em(eU, 1.0, 0.0, 0.0); - const double *fluid_d[2] = { fL, fU }; - const double *em_d[2] = { eL, eU }; + const double *fluid_d[2] = {fL, fU}; + const double *em_d[2] = {eL, eU}; float in[6]; struct gkyl_ten_moment_nn_closure_geom geom; gkyl_ten_moment_nn_closure_geom_calc(nn, fluid_d, em_d, in, &geom); // p_xx avg = 3, p_yy avg = 1.5, p_zz = 0.5 -> p_par = 3, p_perp = 0.5(5-3) = 1. - TEST_CHECK( fabs(in[2] - 3.0) < tol ); - TEST_CHECK( fabs(in[4] - 1.0) < tol ); + TEST_CHECK(fabs(in[2] - 3.0) < tol); + TEST_CHECK(fabs(in[4] - 1.0) < tol); // d p_xx/dx = (4-2)/dx = 20 -> p_par_dx = 20. - TEST_CHECK( fabs(in[3] - (2.0 / dx)) < tol ); + TEST_CHECK(fabs(in[3] - (2.0 / dx)) < tol); // d tr/dx = (dPxx + dPyy)/dx = (2+1)/dx = 30 -> p_perp_dx = 0.5(30-20) = 5. - TEST_CHECK( fabs(in[5] - 5.0) < tol ); + TEST_CHECK(fabs(in[5] - 5.0) < tol); gkyl_ten_moment_nn_closure_release(nn); } // Vanishing magnetic field: the closure falls back to b = (1,0,0), so p_par // reduces to p_xx (avoids a divide-by-zero in the field direction). -static void -test_nn_closure_geom_1d_p1_zero_b_ho(void) +static void test_nn_closure_geom_1d_p1_zero_b_ho(void) { struct gkyl_ten_moment_nn_closure *nn = mk_closure_1d(1, 0.1); @@ -266,27 +268,29 @@ test_nn_closure_geom_1d_p1_zero_b_ho(void) set_em(eL, 0.0, 0.0, 0.0); set_em(eU, 0.0, 0.0, 0.0); - const double *fluid_d[2] = { fL, fU }; - const double *em_d[2] = { eL, eU }; + const double *fluid_d[2] = {fL, fU}; + const double *em_d[2] = {eL, eU}; float in[6]; struct gkyl_ten_moment_nn_closure_geom geom; gkyl_ten_moment_nn_closure_geom_calc(nn, fluid_d, em_d, in, &geom); - TEST_CHECK( fabs(geom.local_mag[0] - 1.0) < tol ); - TEST_CHECK( fabs(in[2] - 3.0) < tol ); // p_par = p_xx - TEST_CHECK( fabs(in[4] - 0.75) < tol ); + TEST_CHECK(fabs(geom.local_mag[0] - 1.0) < tol); + TEST_CHECK(fabs(in[2] - 3.0) < tol); // p_par = p_xx + TEST_CHECK(fabs(in[4] - 0.75) < tol); gkyl_ten_moment_nn_closure_release(nn); } // Helper: zero a geometry cache and set a uniform field direction b along axis // `ax` (0=x,1=y,2=z), with |B| = 1 (so the divQ B-prefactor is unity). -static void -set_geom_uniform_b(struct gkyl_ten_moment_nn_closure_geom *g, int ax) +static void set_geom_uniform_b(struct gkyl_ten_moment_nn_closure_geom *g, int ax) { for (int i = 0; i < 3; i++) { - g->local_mag[i] = 0.0; g->local_mag_dx[i] = 0.0; g->local_mag_dy[i] = 0.0; g->B_avg[i] = 0.0; + g->local_mag[i] = 0.0; + g->local_mag_dx[i] = 0.0; + g->local_mag_dy[i] = 0.0; + g->B_avg[i] = 0.0; } g->rho_avg = 1.0; for (int i = 0; i < 6; i++) { @@ -299,8 +303,7 @@ set_geom_uniform_b(struct gkyl_ten_moment_nn_closure_geom *g, int ax) // Coupling/sign test: with b = x and a prescribed heat flux (q_par, q_par_dx, // q_perp, q_perp_dx), the pressure-tensor source must be d(P_ij)/dt = -d(q)/dx, // with q_par -> Pxx and q_perp -> Pyy, Pzz (and no off-diagonal/mass/momentum). -static void -test_nn_closure_consume_1d_p1_sign_and_mapping_ho(void) +static void test_nn_closure_consume_1d_p1_sign_and_mapping_ho(void) { struct gkyl_ten_moment_nn_closure *nn = mk_closure_1d(1, 0.1); @@ -308,41 +311,40 @@ test_nn_closure_consume_1d_p1_sign_and_mapping_ho(void) set_geom_uniform_b(&geom, 0); // b = x, uniform // pred = [q_par, q_par_dx, q_perp, q_perp_dx] - float pred[4] = { 0.3f, 0.5f, 0.2f, 0.1f }; - double rhs[10] = { 0.0 }; + float pred[4] = {0.3f, 0.5f, 0.2f, 0.1f}; + double rhs[10] = {0.0}; gkyl_ten_moment_nn_closure_construct(nn, &geom, pred, rhs); - TEST_CHECK( fabs(rhs[TM_P11] - (-0.5)) < tol ); // -q_par_dx + TEST_CHECK(fabs(rhs[TM_P11] - (-0.5)) < tol); // -q_par_dx TEST_MSG("rhs[P11]=%g expected %g", rhs[TM_P11], -0.5); - TEST_CHECK( fabs(rhs[TM_P22] - (-0.1)) < tol ); // -q_perp_dx - TEST_CHECK( fabs(rhs[TM_P33] - (-0.1)) < tol ); // -q_perp_dx - TEST_CHECK( fabs(rhs[TM_P12]) < tol ); - TEST_CHECK( fabs(rhs[TM_P13]) < tol ); - TEST_CHECK( fabs(rhs[TM_P23]) < tol ); - TEST_CHECK( fabs(rhs[TM_RHO]) < tol ); - TEST_CHECK( fabs(rhs[TM_MX]) < tol ); - TEST_CHECK( fabs(rhs[TM_MY]) < tol ); - TEST_CHECK( fabs(rhs[TM_MZ]) < tol ); + TEST_CHECK(fabs(rhs[TM_P22] - (-0.1)) < tol); // -q_perp_dx + TEST_CHECK(fabs(rhs[TM_P33] - (-0.1)) < tol); // -q_perp_dx + TEST_CHECK(fabs(rhs[TM_P12]) < tol); + TEST_CHECK(fabs(rhs[TM_P13]) < tol); + TEST_CHECK(fabs(rhs[TM_P23]) < tol); + TEST_CHECK(fabs(rhs[TM_RHO]) < tol); + TEST_CHECK(fabs(rhs[TM_MX]) < tol); + TEST_CHECK(fabs(rhs[TM_MY]) < tol); + TEST_CHECK(fabs(rhs[TM_MZ]) < tol); gkyl_ten_moment_nn_closure_release(nn); } // Sign robustness: a negative parallel-flux gradient must flip the Pxx source. -static void -test_nn_closure_consume_1d_p1_sign_flip_ho(void) +static void test_nn_closure_consume_1d_p1_sign_flip_ho(void) { struct gkyl_ten_moment_nn_closure *nn = mk_closure_1d(1, 0.1); struct gkyl_ten_moment_nn_closure_geom geom; set_geom_uniform_b(&geom, 0); // b = x - float pred[4] = { 0.0f, -0.7f, 0.0f, 0.25f }; // q_par_dx<0, q_perp_dx>0 - double rhs[10] = { 0.0 }; + float pred[4] = {0.0f, -0.7f, 0.0f, 0.25f}; // q_par_dx<0, q_perp_dx>0 + double rhs[10] = {0.0}; gkyl_ten_moment_nn_closure_construct(nn, &geom, pred, rhs); - TEST_CHECK( fabs(rhs[TM_P11] - 0.7) < tol ); // -(-0.7) - TEST_CHECK( fabs(rhs[TM_P22] - (-0.25)) < tol ); - TEST_CHECK( fabs(rhs[TM_P33] - (-0.25)) < tol ); + TEST_CHECK(fabs(rhs[TM_P11] - 0.7) < tol); // -(-0.7) + TEST_CHECK(fabs(rhs[TM_P22] - (-0.25)) < tol); + TEST_CHECK(fabs(rhs[TM_P33] - (-0.25)) < tol); gkyl_ten_moment_nn_closure_release(nn); } @@ -351,20 +353,19 @@ test_nn_closure_consume_1d_p1_sign_flip_ho(void) // gradients) must produce no pressure source, even with q != 0. This is why the // network's constant offset in static regions does not inject a spurious source // provided it also predicts q' ~ 0 there. -static void -test_nn_closure_consume_1d_p1_uniform_q_zero_source_ho(void) +static void test_nn_closure_consume_1d_p1_uniform_q_zero_source_ho(void) { struct gkyl_ten_moment_nn_closure *nn = mk_closure_1d(1, 0.1); struct gkyl_ten_moment_nn_closure_geom geom; set_geom_uniform_b(&geom, 0); // b = x - float pred[4] = { 0.4f, 0.0f, 0.15f, 0.0f }; // nonzero q, zero gradients - double rhs[10] = { 0.0 }; + float pred[4] = {0.4f, 0.0f, 0.15f, 0.0f}; // nonzero q, zero gradients + double rhs[10] = {0.0}; gkyl_ten_moment_nn_closure_construct(nn, &geom, pred, rhs); for (int n = 0; n < 10; n++) { - TEST_CHECK( fabs(rhs[n]) < tol ); + TEST_CHECK(fabs(rhs[n]) < tol); TEST_MSG("rhs[%d] = %g (expected 0)", n, rhs[n]); } @@ -372,15 +373,17 @@ test_nn_closure_consume_1d_p1_uniform_q_zero_source_ho(void) } TEST_LIST = { - { "nn_closure_dims_ho", test_nn_closure_dims_ho }, - { "nn_closure_geom_1d_p1_uniform_bx_ho", test_nn_closure_geom_1d_p1_uniform_bx_ho }, - { "nn_closure_geom_1d_p1_uniform_bz_ho", test_nn_closure_geom_1d_p1_uniform_bz_ho }, - { "nn_closure_geom_1d_p1_diagonal_b_ho", test_nn_closure_geom_1d_p1_diagonal_b_ho }, - { "nn_closure_geom_1d_p1_density_gradient_ho", test_nn_closure_geom_1d_p1_density_gradient_ho }, - { "nn_closure_geom_1d_p1_pressure_gradient_ho", test_nn_closure_geom_1d_p1_pressure_gradient_ho }, - { "nn_closure_geom_1d_p1_zero_b_ho", test_nn_closure_geom_1d_p1_zero_b_ho }, - { "nn_closure_consume_1d_p1_sign_and_mapping_ho", test_nn_closure_consume_1d_p1_sign_and_mapping_ho }, - { "nn_closure_consume_1d_p1_sign_flip_ho", test_nn_closure_consume_1d_p1_sign_flip_ho }, - { "nn_closure_consume_1d_p1_uniform_q_zero_source_ho", test_nn_closure_consume_1d_p1_uniform_q_zero_source_ho }, - { NULL, NULL }, + {"nn_closure_dims_ho", test_nn_closure_dims_ho}, + {"nn_closure_geom_1d_p1_uniform_bx_ho", test_nn_closure_geom_1d_p1_uniform_bx_ho}, + {"nn_closure_geom_1d_p1_uniform_bz_ho", test_nn_closure_geom_1d_p1_uniform_bz_ho}, + {"nn_closure_geom_1d_p1_diagonal_b_ho", test_nn_closure_geom_1d_p1_diagonal_b_ho}, + {"nn_closure_geom_1d_p1_density_gradient_ho", test_nn_closure_geom_1d_p1_density_gradient_ho}, + {"nn_closure_geom_1d_p1_pressure_gradient_ho", test_nn_closure_geom_1d_p1_pressure_gradient_ho}, + {"nn_closure_geom_1d_p1_zero_b_ho", test_nn_closure_geom_1d_p1_zero_b_ho}, + {"nn_closure_consume_1d_p1_sign_and_mapping_ho", test_nn_closure_consume_1d_p1_sign_and_mapping_ho + }, + {"nn_closure_consume_1d_p1_sign_flip_ho", test_nn_closure_consume_1d_p1_sign_flip_ho}, + {"nn_closure_consume_1d_p1_uniform_q_zero_source_ho", + test_nn_closure_consume_1d_p1_uniform_q_zero_source_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wave_geom.c b/moments/unit/ctest_wave_geom.c index 43cfbbe30d..ff5b85d3e5 100644 --- a/moments/unit/ctest_wave_geom.c +++ b/moments/unit/ctest_wave_geom.c @@ -8,15 +8,15 @@ #include -static void -my_nomapc2p(double t, const double *xc, double *xp, void *ctx) +static void my_nomapc2p(double t, const double *xc, double *xp, void *ctx) { int *ndim = ctx; - for (int i=0; i<(*ndim); ++i) xp[i] = xc[i]; + for (int i = 0; i < (*ndim); ++i) { + xp[i] = xc[i]; + } } -void -test_wv_geom_1d_1_ho() +void test_wv_geom_1d_1_ho() { int ndim = 1; double lower[] = {0.0}, upper[] = {1.0}; @@ -25,7 +25,7 @@ test_wv_geom_1d_1_ho() gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); // create range - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range arr_range, arr_ext_range; gkyl_create_grid_ranges(&grid, nghost, &arr_ext_range, &arr_range); @@ -33,31 +33,31 @@ test_wv_geom_1d_1_ho() struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &arr_range); - + while (gkyl_range_iter_next(&iter)) { const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wg, iter.idx); - TEST_CHECK( gkyl_compare_double( cg->kappa, 1.0, 1e-15) ); - TEST_CHECK( cg->lenr[0] == 1.0 ); + TEST_CHECK(gkyl_compare_double(cg->kappa, 1.0, 1e-15)); + TEST_CHECK(cg->lenr[0] == 1.0); - TEST_CHECK( cg->norm[0][0] == 1.0 ); - TEST_CHECK( cg->tau1[0][1] == 1.0 ); - TEST_CHECK( cg->tau2[0][2] == 1.0 ); + TEST_CHECK(cg->norm[0][0] == 1.0); + TEST_CHECK(cg->tau1[0][1] == 1.0); + TEST_CHECK(cg->tau2[0][2] == 1.0); } gkyl_wave_geom_release(wg); } -static void -mapc2p(double t, const double *xc, double *xp, void *ctx) +static void mapc2p(double t, const double *xc, double *xp, void *ctx) { // quadratic mapping int *ndim = ctx; - for (int i=0; i<(*ndim); ++i) xp[i] = xc[i]*xc[i]; + for (int i = 0; i < (*ndim); ++i) { + xp[i] = xc[i] * xc[i]; + } } -void -test_wv_geom_1d_2_ho() +void test_wv_geom_1d_2_ho() { int ndim = 1; double lower[] = {0.0}, upper[] = {1.0}; @@ -66,7 +66,7 @@ test_wv_geom_1d_2_ho() gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); // create range - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range range, ext_range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); @@ -77,29 +77,28 @@ test_wv_geom_1d_2_ho() // cell 1 do { - const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wg, (int[]) { range.lower[0]+0 } ); - TEST_CHECK( gkyl_compare_double( cg->kappa, 0.5*0.5/0.5, 1e-15) ); - TEST_CHECK( cg->lenr[0] == 1.0 ); - TEST_CHECK( cg->norm[0][0] == 1.0 ); - TEST_CHECK( cg->tau1[0][1] == 1.0 ); - TEST_CHECK( cg->tau2[0][2] == 1.0 ); + const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wg, (int[]){range.lower[0] + 0}); + TEST_CHECK(gkyl_compare_double(cg->kappa, 0.5 * 0.5 / 0.5, 1e-15)); + TEST_CHECK(cg->lenr[0] == 1.0); + TEST_CHECK(cg->norm[0][0] == 1.0); + TEST_CHECK(cg->tau1[0][1] == 1.0); + TEST_CHECK(cg->tau2[0][2] == 1.0); } while (0); // cell 2 do { - const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wg, (int[]) { range.lower[0]+1 } ); - TEST_CHECK( gkyl_compare_double( cg->kappa, (1-0.5*0.5)/0.5, 1e-15) ); - TEST_CHECK( cg->lenr[0] == 1.0 ); - TEST_CHECK( cg->norm[0][0] == 1.0 ); - TEST_CHECK( cg->tau1[0][1] == 1.0 ); - TEST_CHECK( cg->tau2[0][2] == 1.0 ); - } while (0); + const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wg, (int[]){range.lower[0] + 1}); + TEST_CHECK(gkyl_compare_double(cg->kappa, (1 - 0.5 * 0.5) / 0.5, 1e-15)); + TEST_CHECK(cg->lenr[0] == 1.0); + TEST_CHECK(cg->norm[0][0] == 1.0); + TEST_CHECK(cg->tau1[0][1] == 1.0); + TEST_CHECK(cg->tau2[0][2] == 1.0); + } while (0); gkyl_wave_geom_release(wg); } -void -test_wv_geom_2d_1_ho() +void test_wv_geom_2d_1_ho() { int ndim = 2; double lower[] = {0.0, 0.0}, upper[] = {1.0, 1.0}; @@ -108,7 +107,7 @@ test_wv_geom_2d_1_ho() gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); // create range - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range range, ext_range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); @@ -116,59 +115,58 @@ test_wv_geom_2d_1_ho() struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wg, iter.idx); - TEST_CHECK( gkyl_compare_double( cg->kappa, 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[0], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[1], 1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->kappa, 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[0], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[1], 1.0, 1e-15)); // normal to left face is ex - TEST_CHECK( gkyl_compare_double( cg->norm[0][0], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[0][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[0][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->norm[0][0], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[0][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[0][2], 0.0, 1e-15)); // tangent1 to left face is ey - TEST_CHECK( gkyl_compare_double( cg->tau1[0][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[0][1], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[0][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][1], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][2], 0.0, 1e-15)); // tangent2 to left face is ez - TEST_CHECK( gkyl_compare_double( cg->tau2[0][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[0][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[0][2], 1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][2], 1.0, 1e-15)); // normal to bottom face is ey - TEST_CHECK( gkyl_compare_double( cg->norm[1][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[1][1], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[1][0], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->norm[1][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[1][1], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[1][0], 0.0, 1e-15)); // tangent1 to bottom face is ex - TEST_CHECK( gkyl_compare_double( cg->tau1[1][0], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[1][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[1][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][0], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][2], 0.0, 1e-15)); // tangent2 to bottom face is ez - TEST_CHECK( gkyl_compare_double( cg->tau2[1][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[1][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[1][2], -1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][2], -1.0, 1e-15)); } gkyl_wave_geom_release(wg); } -static void -mapc2p_2d(double t, const double *xc, double *xp, void *ctx) +static void mapc2p_2d(double t, const double *xc, double *xp, void *ctx) { double x = xc[0], y = xc[1]; - xp[0] = 0.375*((x+1.0)*y+x+1.0)-0.25*((x+1.0)*y-1.0*x-1.0)-0.125*((x-1.0)*y+x-1.0); - xp[1] = 0.25*((x+1.0)*y+x+1.0)-0.25*((x-1.0)*y+x-1.0); + xp[0] = 0.375 * ((x + 1.0) * y + x + 1.0) - 0.25 * ((x + 1.0) * y - 1.0 * x - 1.0) - + 0.125 * ((x - 1.0) * y + x - 1.0); + xp[1] = 0.25 * ((x + 1.0) * y + x + 1.0) - 0.25 * ((x - 1.0) * y + x - 1.0); } -void -test_wv_geom_2d_2_ho() +void test_wv_geom_2d_2_ho() { int ndim = 2; double lower[] = {-1.0, -1.0}, upper[] = {1.0, 1.0}; @@ -177,7 +175,7 @@ test_wv_geom_2d_2_ho() gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); // create range - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range range, ext_range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); @@ -185,58 +183,57 @@ test_wv_geom_2d_2_ho() struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wg, iter.idx); - TEST_CHECK( gkyl_compare_double( cg->kappa, 1.0/4.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[0], 1.118033988749895/2.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[1], 1.0/2.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->kappa, 1.0 / 4.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[0], 1.118033988749895 / 2.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[1], 1.0 / 2.0, 1e-15)); // normal to left face is ex - TEST_CHECK( gkyl_compare_double( cg->norm[0][0], 0.8944271909999159, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[0][1], -0.4472135954999579, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[0][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->norm[0][0], 0.8944271909999159, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[0][1], -0.4472135954999579, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[0][2], 0.0, 1e-15)); // tangent1 to left face - TEST_CHECK( gkyl_compare_double( cg->tau1[0][0], 0.4472135954999579, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[0][1], 0.8944271909999159, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[0][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][0], 0.4472135954999579, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][1], 0.8944271909999159, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][2], 0.0, 1e-15)); // tangent2 to left face is ez - TEST_CHECK( gkyl_compare_double( cg->tau2[0][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[0][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[0][2], 1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][2], 1.0, 1e-15)); // normal to bottom face is ey - TEST_CHECK( gkyl_compare_double( cg->norm[1][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[1][1], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[1][0], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->norm[1][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[1][1], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[1][0], 0.0, 1e-15)); // tangent1 to bottom face is ex - TEST_CHECK( gkyl_compare_double( cg->tau1[1][0], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[1][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[1][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][0], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][2], 0.0, 1e-15)); // tangent2 to bottom face is ez - TEST_CHECK( gkyl_compare_double( cg->tau2[1][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[1][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[1][2], -1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][2], -1.0, 1e-15)); } gkyl_wave_geom_release(wg); } // map (r,theta) -> (x,y) -void -mapc2p_polar(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p_polar(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double r = xc[0], th = xc[1]; - xp[0] = r*cos(th); xp[1] = r*sin(th); + xp[0] = r * cos(th); + xp[1] = r * sin(th); } -void -test_wv_geom_2d_3_ho() +void test_wv_geom_2d_3_ho() { int ndim = 2; double r_inn = 0.25, r_out = 1.25; @@ -246,12 +243,12 @@ test_wv_geom_2d_3_ho() struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); - double area = 0.5*(r_out*r_out-r_inn*r_inn); + double area = 0.5 * (r_out * r_out - r_inn * r_inn); double edge_inn = sqrt(2) * r_inn; double area_c = (r_out - r_inn) * phi_max; // create range - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range range, ext_range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); @@ -259,50 +256,49 @@ test_wv_geom_2d_3_ho() struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wg, iter.idx); - TEST_CHECK( gkyl_compare_double( cg->kappa, area / area_c, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[0], edge_inn / phi_max, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[1], 1, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->kappa, area / area_c, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[0], edge_inn / phi_max, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[1], 1, 1e-15)); // normal to left face has phi angle 45 deg - TEST_CHECK( gkyl_compare_double( cg->norm[0][0], 1/sqrt(2), 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[0][1], 1/sqrt(2), 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[0][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->norm[0][0], 1 / sqrt(2), 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[0][1], 1 / sqrt(2), 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[0][2], 0.0, 1e-15)); // tangent1 to left face has phi angle 135 deg - TEST_CHECK( gkyl_compare_double( cg->tau1[0][0], -1/sqrt(2), 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[0][1], 1/sqrt(2), 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[0][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][0], -1 / sqrt(2), 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][1], 1 / sqrt(2), 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][2], 0.0, 1e-15)); // tangent2 to left face is ez - TEST_CHECK( gkyl_compare_double( cg->tau2[0][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[0][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[0][2], 1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][2], 1.0, 1e-15)); // normal to bottom face is ey - TEST_CHECK( gkyl_compare_double( cg->norm[1][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[1][1], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[1][0], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->norm[1][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[1][1], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[1][0], 0.0, 1e-15)); // tangent1 to bottom face is ex - TEST_CHECK( gkyl_compare_double( cg->tau1[1][0], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[1][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[1][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][0], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][2], 0.0, 1e-15)); // tangent2 to bottom face is ez - TEST_CHECK( gkyl_compare_double( cg->tau2[1][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[1][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[1][2], -1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][2], -1.0, 1e-15)); } gkyl_wave_geom_release(wg); } -void -test_wv_geom_3d_1_ho() +void test_wv_geom_3d_1_ho() { int ndim = 3; double lower[] = {0.0, 0.0, 0.0}, upper[] = {1.0, 1.0, 1.0}; @@ -311,7 +307,7 @@ test_wv_geom_3d_1_ho() gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); // create range - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range range, ext_range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); @@ -319,74 +315,74 @@ test_wv_geom_3d_1_ho() struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wg, iter.idx); - TEST_CHECK( gkyl_compare_double( cg->kappa, 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[0], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[1], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[2], 1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->kappa, 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[0], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[1], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[2], 1.0, 1e-15)); // normal to lower-x face is ex - TEST_CHECK( gkyl_compare_double( cg->norm[0][0], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[0][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[0][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->norm[0][0], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[0][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[0][2], 0.0, 1e-15)); // tangent1 to lower-x face is ey - TEST_CHECK( gkyl_compare_double( cg->tau1[0][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[0][1], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[0][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][1], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][2], 0.0, 1e-15)); // tangent2 to lower-x face is ez - TEST_CHECK( gkyl_compare_double( cg->tau2[0][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[0][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[0][2], 1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][2], 1.0, 1e-15)); // normal to lower-y face is ey - TEST_CHECK( gkyl_compare_double( cg->norm[1][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[1][1], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[1][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->norm[1][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[1][1], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[1][2], 0.0, 1e-15)); // tangent1 to lower-y face is ez - TEST_CHECK( gkyl_compare_double( cg->tau1[1][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[1][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[1][2], 1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[1][2], 1.0, 1e-15)); // tangent2 to lower-y face is ex - TEST_CHECK( gkyl_compare_double( cg->tau2[1][0], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[1][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[1][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][0], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[1][2], 0.0, 1e-15)); // normal to lower-z face is ez - TEST_CHECK( gkyl_compare_double( cg->norm[2][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[2][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[2][2], 1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->norm[2][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[2][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[2][2], 1.0, 1e-15)); // tangent1 to lower-z face is ex - TEST_CHECK( gkyl_compare_double( cg->tau1[2][0], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[2][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[2][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau1[2][0], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[2][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[2][2], 0.0, 1e-15)); // tangent2 to lower-z face is ey - TEST_CHECK( gkyl_compare_double( cg->tau2[2][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[2][1], 1.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[2][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau2[2][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[2][1], 1.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[2][2], 0.0, 1e-15)); } gkyl_wave_geom_release(wg); } // map (r,theta) -> (x,y) -void -mapc2p_cylind(double t, const double *xc, double* GKYL_RESTRICT xp, void *ctx) +void mapc2p_cylind(double t, const double *xc, double *GKYL_RESTRICT xp, void *ctx) { double r = xc[0], th = xc[1], z = xc[2]; - xp[0] = r*cos(th); xp[1] = r*sin(th); xp[2] = z; + xp[0] = r * cos(th); + xp[1] = r * sin(th); + xp[2] = z; } -void -test_wv_geom_3d_2_ho() +void test_wv_geom_3d_2_ho() { int ndim = 3; double z_min = 0, z_max = 1; @@ -397,12 +393,12 @@ test_wv_geom_3d_2_ho() struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); - double area = 0.5*(r_out*r_out-r_inn*r_inn); + double area = 0.5 * (r_out * r_out - r_inn * r_inn); double edge_inn = sqrt(2) * r_inn; double area_c = (r_out - r_inn) * phi_max; // create range - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range range, ext_range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); @@ -410,29 +406,29 @@ test_wv_geom_3d_2_ho() struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &range); - + while (gkyl_range_iter_next(&iter)) { const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wg, iter.idx); - TEST_CHECK( gkyl_compare_double( cg->kappa, area / area_c, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[0], edge_inn / phi_max, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[1], 1, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->lenr[2], area / area_c, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->kappa, area / area_c, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[0], edge_inn / phi_max, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[1], 1, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->lenr[2], area / area_c, 1e-15)); // normal to left face has phi angle 45 deg - TEST_CHECK( gkyl_compare_double( cg->norm[0][0], 1/sqrt(2), 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[0][1], 1/sqrt(2), 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->norm[0][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->norm[0][0], 1 / sqrt(2), 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[0][1], 1 / sqrt(2), 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->norm[0][2], 0.0, 1e-15)); // tangent1 to left face has phi angle 135 deg - TEST_CHECK( gkyl_compare_double( cg->tau1[0][0], -1/sqrt(2), 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[0][1], 1/sqrt(2), 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau1[0][2], 0.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][0], -1 / sqrt(2), 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][1], 1 / sqrt(2), 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau1[0][2], 0.0, 1e-15)); // tangent2 to left face is ez - TEST_CHECK( gkyl_compare_double( cg->tau2[0][0], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[0][1], 0.0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( cg->tau2[0][2], 1.0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][0], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][1], 0.0, 1e-15)); + TEST_CHECK(gkyl_compare_double(cg->tau2[0][2], 1.0, 1e-15)); /* // normal to bottom face is ey */ /* TEST_CHECK( gkyl_compare_double( cg->norm[1][0], 0.0, 1e-15) ); */ @@ -457,8 +453,7 @@ test_wv_geom_3d_2_ho() int cu_wave_geom_test(const struct gkyl_wave_geom *wg); -void -test_wv_geom_3d_dev() +void test_wv_geom_3d_dev() { int ndim = 3; double z_min = 0, z_max = 1; @@ -469,12 +464,12 @@ test_wv_geom_3d_dev() struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); - double area = 0.5*(r_out*r_out-r_inn*r_inn); + double area = 0.5 * (r_out * r_out - r_inn * r_inn); double edge_inn = sqrt(2) * r_inn; double area_c = (r_out - r_inn) * phi_max; // create range - int nghost[GKYL_MAX_DIM] = { 0 }; + int nghost[GKYL_MAX_DIM] = {0}; struct gkyl_range range, ext_range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); @@ -487,15 +482,15 @@ test_wv_geom_3d_dev() #endif TEST_LIST = { - { "wv_geom_1d_1_ho", test_wv_geom_1d_1_ho }, - { "wv_geom_1d_2_ho", test_wv_geom_1d_2_ho }, - { "wv_geom_2d_1_ho", test_wv_geom_2d_1_ho }, - { "wv_geom_2d_2_ho", test_wv_geom_2d_2_ho }, - { "wv_geom_2d_3_ho", test_wv_geom_2d_3_ho }, - { "wv_geom_3d_1_ho", test_wv_geom_3d_1_ho }, - { "wv_geom_3d_2_ho", test_wv_geom_3d_2_ho }, + {"wv_geom_1d_1_ho", test_wv_geom_1d_1_ho}, + {"wv_geom_1d_2_ho", test_wv_geom_1d_2_ho}, + {"wv_geom_2d_1_ho", test_wv_geom_2d_1_ho}, + {"wv_geom_2d_2_ho", test_wv_geom_2d_2_ho}, + {"wv_geom_2d_3_ho", test_wv_geom_2d_3_ho}, + {"wv_geom_3d_1_ho", test_wv_geom_3d_1_ho}, + {"wv_geom_3d_2_ho", test_wv_geom_3d_2_ho}, #ifdef GKYL_HAVE_CUDA - { "wv_geom_3d_dev", test_wv_geom_3d_dev }, + {"wv_geom_3d_dev", test_wv_geom_3d_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wave_geom_cu.cu b/moments/unit/ctest_wave_geom_cu.cu index 592124e533..56430278d9 100644 --- a/moments/unit/ctest_wave_geom_cu.cu +++ b/moments/unit/ctest_wave_geom_cu.cu @@ -14,22 +14,29 @@ int cu_wave_geom_test(const struct gkyl_wave_geom *wg); // FIXME: duplicate of gkyl_compare_double in util.c GKYL_CU_D static int compare(double a, double b, double eps) { - double absa = fabs(a), absb = fabs(b), diff = fabs(a-b); - if (a == b) return 1; - if (a == 0 || b == 0 || (absa+absb < DBL_MIN)) return diff < eps; - if (absa < eps) return diff < eps; - if (absb < eps) return diff < eps; - return diff/fmin(absa+absb, DBL_MAX) < eps; + double absa = fabs(a), absb = fabs(b), diff = fabs(a - b); + if (a == b) { + return 1; + } + if (a == 0 || b == 0 || (absa + absb < DBL_MIN)) { + return diff < eps; + } + if (absa < eps) { + return diff < eps; + } + if (absb < eps) { + return diff < eps; + } + return diff / fmin(absa + absb, DBL_MAX) < eps; } -__global__ -void ker_cu_wave_geom_test(const struct gkyl_wave_geom *wg, int *nfail) +__global__ void ker_cu_wave_geom_test(const struct gkyl_wave_geom *wg, int *nfail) { *nfail = 0; double r_inn = 0.25, r_out = 1.25; double phi_max = M_PI / 2.; - double area = 0.5*(r_out*r_out-r_inn*r_inn); + double area = 0.5 * (r_out * r_out - r_inn * r_inn); double edge_inn = sqrtf(2) * r_inn; double area_c = (r_out - r_inn) * phi_max; @@ -43,13 +50,13 @@ void ker_cu_wave_geom_test(const struct gkyl_wave_geom *wg, int *nfail) GKYL_CU_CHECK(compare(cg->lenr[2], area / area_c, 1e-8), nfail); // normal to left face has phi angle 45 deg - GKYL_CU_CHECK(compare(cg->norm[0][0], 1/sqrtf(2.), 1e-8), nfail); - GKYL_CU_CHECK(compare(cg->norm[0][1], 1/sqrtf(2.), 1e-8), nfail); + GKYL_CU_CHECK(compare(cg->norm[0][0], 1 / sqrtf(2.), 1e-8), nfail); + GKYL_CU_CHECK(compare(cg->norm[0][1], 1 / sqrtf(2.), 1e-8), nfail); GKYL_CU_CHECK(compare(cg->norm[0][2], 0.0, 1e-8), nfail); // tangent1 to left face has phi angle 135 deg - GKYL_CU_CHECK(compare(cg->tau1[0][0], -1/sqrtf(2.), 1e-8), nfail); - GKYL_CU_CHECK(compare(cg->tau1[0][1], 1/sqrtf(2.), 1e-8), nfail); + GKYL_CU_CHECK(compare(cg->tau1[0][0], -1 / sqrtf(2.), 1e-8), nfail); + GKYL_CU_CHECK(compare(cg->tau1[0][1], 1 / sqrtf(2.), 1e-8), nfail); GKYL_CU_CHECK(compare(cg->tau1[0][2], 0.0, 1e-8), nfail); // tangent2 to left face is ez @@ -61,9 +68,9 @@ void ker_cu_wave_geom_test(const struct gkyl_wave_geom *wg, int *nfail) int cu_wave_geom_test(const struct gkyl_wave_geom *wg_dev) { - int *nfail_dev = (int *) gkyl_cu_malloc(sizeof(int)); + int *nfail_dev = (int *)gkyl_cu_malloc(sizeof(int)); - ker_cu_wave_geom_test<<<1, 1>>>(wg_dev, nfail_dev); + ker_cu_wave_geom_test<<<1, 1> > >(wg_dev, nfail_dev); checkCuda(cudaGetLastError()); int nfail; @@ -72,4 +79,3 @@ int cu_wave_geom_test(const struct gkyl_wave_geom *wg_dev) return nfail; } - diff --git a/moments/unit/ctest_wave_geom_helpers.c b/moments/unit/ctest_wave_geom_helpers.c index d917398e89..47821e7399 100644 --- a/moments/unit/ctest_wave_geom_helpers.c +++ b/moments/unit/ctest_wave_geom_helpers.c @@ -2,8 +2,7 @@ #include #include <../zero/wave_geom.c> -static void -test_geom_helpers_tri_ho() +static void test_geom_helpers_tri_ho() { struct gkyl_vec3 p1 = gkyl_vec3_new(1, 1, 2); struct gkyl_vec3 p2 = gkyl_vec3_new(-2, 4, 3); @@ -11,11 +10,10 @@ test_geom_helpers_tri_ho() double area = triangle_area(p1, p2, p3); - TEST_CHECK( gkyl_compare_double( area, 10.173494974687902, 1e-15) ); + TEST_CHECK(gkyl_compare_double(area, 10.173494974687902, 1e-15)); } -static void -test_geom_helpers_planar_quad_1_ho() +static void test_geom_helpers_planar_quad_1_ho() { struct gkyl_vec3 p1 = gkyl_vec3_new(0, 0, 0); struct gkyl_vec3 p2 = gkyl_vec3_new(1, 2, 3); @@ -24,25 +22,23 @@ test_geom_helpers_planar_quad_1_ho() struct gkyl_vec3 norm; - double area = planar_quad_area_norm( - p1, p2, p3, p4, &norm); + double area = planar_quad_area_norm(p1, p2, p3, p4, &norm); - TEST_CHECK( gkyl_compare_double( area, 3*sqrt(6), 1e-15) ); + TEST_CHECK(gkyl_compare_double(area, 3 * sqrt(6), 1e-15)); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_len(norm), 1, 1e-15) ); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_len(norm), 1, 1e-15)); struct gkyl_vec3 v12 = gkyl_vec3_sub(p2, p1); struct gkyl_vec3 v23 = gkyl_vec3_sub(p3, p2); struct gkyl_vec3 v34 = gkyl_vec3_sub(p4, p3); struct gkyl_vec3 v41 = gkyl_vec3_sub(p1, p2); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, v12), 0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, v23), 0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, v34), 0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, v41), 0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, v12), 0, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, v23), 0, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, v34), 0, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, v41), 0, 1e-15)); } -static void -test_geom_helpers_quad_1_ho() +static void test_geom_helpers_quad_1_ho() { struct gkyl_vec3 p1 = gkyl_vec3_new(0, 0, 0); struct gkyl_vec3 p2 = gkyl_vec3_new(1, 2, 3); @@ -53,33 +49,32 @@ test_geom_helpers_quad_1_ho() double area = quad_area_norm_tang(p1, p2, p3, p4, &norm, &tau1, &tau2); - TEST_CHECK( gkyl_compare_double( area, 3*sqrt(6), 1e-15) ); + TEST_CHECK(gkyl_compare_double(area, 3 * sqrt(6), 1e-15)); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_len(norm), 1, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_len(tau1), 1, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_len(tau2), 1, 1e-15) ); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_len(norm), 1, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_len(tau1), 1, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_len(tau2), 1, 1e-15)); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, tau1), 0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, tau2), 0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(tau1, tau2), 0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, tau1), 0, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, tau2), 0, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(tau1, tau2), 0, 1e-15)); struct gkyl_vec3 cross = gkyl_vec3_cross(tau1, tau2); - TEST_CHECK( gkyl_compare_double( cross.x[0], norm.x[0], 1e-15) ); - TEST_CHECK( gkyl_compare_double( cross.x[1], norm.x[1], 1e-15) ); - TEST_CHECK( gkyl_compare_double( cross.x[2], norm.x[2], 1e-15) ); + TEST_CHECK(gkyl_compare_double(cross.x[0], norm.x[0], 1e-15)); + TEST_CHECK(gkyl_compare_double(cross.x[1], norm.x[1], 1e-15)); + TEST_CHECK(gkyl_compare_double(cross.x[2], norm.x[2], 1e-15)); struct gkyl_vec3 v12 = gkyl_vec3_sub(p2, p1); struct gkyl_vec3 v23 = gkyl_vec3_sub(p3, p2); struct gkyl_vec3 v34 = gkyl_vec3_sub(p4, p3); struct gkyl_vec3 v41 = gkyl_vec3_sub(p1, p2); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, v12), 0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, v23), 0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, v34), 0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, v41), 0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, v12), 0, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, v23), 0, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, v34), 0, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, v41), 0, 1e-15)); } -static void -test_geom_helpers_quad_2_ho() +static void test_geom_helpers_quad_2_ho() { struct gkyl_vec3 p1 = gkyl_vec3_new(9., 3., 4.); struct gkyl_vec3 p2 = gkyl_vec3_new(9., 8., 7.); @@ -90,92 +85,73 @@ test_geom_helpers_quad_2_ho() double area = quad_area_norm_tang(p1, p2, p3, p4, &norm, &tau1, &tau2); - TEST_CHECK( gkyl_compare_double( area, 5.099019513592786, 1e-15) ); + TEST_CHECK(gkyl_compare_double(area, 5.099019513592786, 1e-15)); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_len(norm), 1, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_len(tau1), 1, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_len(tau2), 1, 1e-15) ); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_len(norm), 1, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_len(tau1), 1, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_len(tau2), 1, 1e-15)); - TEST_CHECK( gkyl_compare_double( norm.x[0], -0.196116, 1e-5) ); - TEST_CHECK( gkyl_compare_double( norm.x[1], 0.784465, 1e-5) ); - TEST_CHECK( gkyl_compare_double( norm.x[2], -0.588348, 1e-5) ); + TEST_CHECK(gkyl_compare_double(norm.x[0], -0.196116, 1e-5)); + TEST_CHECK(gkyl_compare_double(norm.x[1], 0.784465, 1e-5)); + TEST_CHECK(gkyl_compare_double(norm.x[2], -0.588348, 1e-5)); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, tau1), 0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(norm, tau2), 0, 1e-15) ); - TEST_CHECK( gkyl_compare_double( gkyl_vec3_dot(tau1, tau2), 0, 1e-15) ); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, tau1), 0, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(norm, tau2), 0, 1e-15)); + TEST_CHECK(gkyl_compare_double(gkyl_vec3_dot(tau1, tau2), 0, 1e-15)); struct gkyl_vec3 cross = gkyl_vec3_cross(tau1, tau2); - TEST_CHECK( gkyl_compare_double( cross.x[0], norm.x[0], 1e-15) ); - TEST_CHECK( gkyl_compare_double( cross.x[1], norm.x[1], 1e-15) ); - TEST_CHECK( gkyl_compare_double( cross.x[2], norm.x[2], 1e-15) ); + TEST_CHECK(gkyl_compare_double(cross.x[0], norm.x[0], 1e-15)); + TEST_CHECK(gkyl_compare_double(cross.x[1], norm.x[1], 1e-15)); + TEST_CHECK(gkyl_compare_double(cross.x[2], norm.x[2], 1e-15)); } -static void -test_geom_helpers_vol_tetra_1_ho() +static void test_geom_helpers_vol_tetra_1_ho() { struct gkyl_vec3 p1 = gkyl_vec3_new(0, 0, 0); struct gkyl_vec3 p2 = gkyl_vec3_new(1, 0, 0); struct gkyl_vec3 p3 = gkyl_vec3_new(1, 1, 0); struct gkyl_vec3 p4 = gkyl_vec3_new(1, 1, 1); double vol = vol_tetra(p1, p2, p3, p4); - TEST_CHECK( gkyl_compare_double( vol, 1./6., 1e-15) ); + TEST_CHECK(gkyl_compare_double(vol, 1. / 6., 1e-15)); } -static void -test_geom_helpers_vol_tetra_2_ho() +static void test_geom_helpers_vol_tetra_2_ho() { struct gkyl_vec3 p1 = gkyl_vec3_new(0.37, 0.07, 0.29); struct gkyl_vec3 p2 = gkyl_vec3_new(1.03, 0.08, 0.05); - struct gkyl_vec3 p3 = gkyl_vec3_new(1.1 , 1.2 , 0.32); + struct gkyl_vec3 p3 = gkyl_vec3_new(1.1, 1.2, 0.32); struct gkyl_vec3 p4 = gkyl_vec3_new(1.17, 1.18, 1.31); double vol = vol_tetra(p1, p2, p3, p4); - TEST_CHECK( gkyl_compare_double( vol, 0.12567, 1e-15) ); + TEST_CHECK(gkyl_compare_double(vol, 0.12567, 1e-15)); } -static void -test_geom_helpers_vol_hexa_1_ho() +static void test_geom_helpers_vol_hexa_1_ho() { - struct gkyl_vec3 verts[8] = { - {0, 0, 0}, - {1, 0, 0}, - {1, 1, 0}, - {0, 1, 0}, - {0, 0, 1}, - {1, 0, 1}, - {1, 1, 1}, - {0, 1, 1}, - }; - + struct gkyl_vec3 verts[8] = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}, + {0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}}; + double vol = vol_hexa(verts); - TEST_CHECK( gkyl_compare_double( vol, 1, 1e-15) ); + TEST_CHECK(gkyl_compare_double(vol, 1, 1e-15)); } -static void -test_geom_helpers_vol_hexa_2_ho() +static void test_geom_helpers_vol_hexa_2_ho() { - struct gkyl_vec3 verts[8] = { - {0.37, 0.07, 0.21}, - {1.16, 0.2 , 0.29}, - {1.33, 1.18, 0.23}, - {0.01, 1.21, 0.28}, - {0.38, 0.36, 1.02}, - {1.19, 0.11, 1.01}, - {1.04, 1.23, 1.14}, - {0.22, 1.2 , 1.18}, - }; - + struct gkyl_vec3 verts[8] = {{0.37, 0.07, 0.21}, {1.16, 0.2, 0.29}, {1.33, 1.18, 0.23}, + {0.01, 1.21, 0.28}, {0.38, 0.36, 1.02}, {1.19, 0.11, 1.01}, + {1.04, 1.23, 1.14}, {0.22, 1.2, 1.18}}; + double vol = vol_hexa(verts); - TEST_CHECK( gkyl_compare_double( vol, 0.746420666666667, 1e-15) ); + TEST_CHECK(gkyl_compare_double(vol, 0.746420666666667, 1e-15)); } TEST_LIST = { - { "geom_helpers_triangle_ho", test_geom_helpers_tri_ho }, - { "geom_helpers_parallelogram_as_planar_quad_ho", test_geom_helpers_planar_quad_1_ho }, - { "geom_helpers_parallelogram_as_quad_ho", test_geom_helpers_quad_1_ho }, - { "geom_helpers_quad_ho", test_geom_helpers_quad_2_ho }, - { "geom_helpers_vol_tetra_1_ho", test_geom_helpers_vol_tetra_1_ho }, - { "geom_helpers_vol_tetra_2_ho", test_geom_helpers_vol_tetra_2_ho }, - { "geom_helpers_vol_hexa_1_ho", test_geom_helpers_vol_hexa_1_ho }, - { "geom_helpers_vol_hexa_2_ho", test_geom_helpers_vol_hexa_2_ho }, - { NULL, NULL }, + {"geom_helpers_triangle_ho", test_geom_helpers_tri_ho}, + {"geom_helpers_parallelogram_as_planar_quad_ho", test_geom_helpers_planar_quad_1_ho}, + {"geom_helpers_parallelogram_as_quad_ho", test_geom_helpers_quad_1_ho}, + {"geom_helpers_quad_ho", test_geom_helpers_quad_2_ho}, + {"geom_helpers_vol_tetra_1_ho", test_geom_helpers_vol_tetra_1_ho}, + {"geom_helpers_vol_tetra_2_ho", test_geom_helpers_vol_tetra_2_ho}, + {"geom_helpers_vol_hexa_1_ho", test_geom_helpers_vol_hexa_1_ho}, + {"geom_helpers_vol_hexa_2_ho", test_geom_helpers_vol_hexa_2_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_apply_bc.c b/moments/unit/ctest_wv_apply_bc.c index 2b548152e6..e46ae905b2 100644 --- a/moments/unit/ctest_wv_apply_bc.c +++ b/moments/unit/ctest_wv_apply_bc.c @@ -12,28 +12,32 @@ #include #include -static void -nomapc2p(double t, const double *xc, double *xp, void *ctx) +static void nomapc2p(double t, const double *xc, double *xp, void *ctx) { int *ndim = ctx; - for (int i=0; i<(*ndim); ++i) xp[i] = xc[i]; + for (int i = 0; i < (*ndim); ++i) { + xp[i] = xc[i]; + } } -static void -rtheta_map(double t, const double *xc, double *xp, void *ctx) +static void rtheta_map(double t, const double *xc, double *xp, void *ctx) { - double r = xc[0], th = xc[1]; - xp[0] = r*cos(th); xp[1] = r*sin(th); + double r = xc[0], th = xc[1]; + xp[0] = r * cos(th); + xp[1] = r * sin(th); } -static void -bc_copy(const struct gkyl_wv_eqn* eqn, double t, int nc, const double *skin, double *restrict ghost, void *ctx) +static void bc_copy( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *restrict ghost, + void *ctx +) { - for (int c=0; cdata; - TEST_CHECK( 0.0 == data[0] ); - TEST_CHECK( 0.0 == data[1] ); + TEST_CHECK(0.0 == data[0]); + TEST_CHECK(0.0 == data[1]); + + TEST_CHECK(0.0 == data[18]); + TEST_CHECK(0.0 == data[19]); - TEST_CHECK( 0.0 == data[18] ); - TEST_CHECK( 0.0 == data[19] ); - // apply BC gkyl_wv_apply_bc_advance(lbc, 0.0, &range, distf); gkyl_wv_apply_bc_advance(rbc, 0.0, &range, distf); // check if BCs applied correctly - TEST_CHECK( 1.0 == data[0] ); - TEST_CHECK( 1.0 == data[1] ); + TEST_CHECK(1.0 == data[0]); + TEST_CHECK(1.0 == data[1]); - TEST_CHECK( 1.0 == data[18] ); - TEST_CHECK( 1.0 == data[19] ); + TEST_CHECK(1.0 == data[18]); + TEST_CHECK(1.0 == data[19]); gkyl_wv_apply_bc_release(lbc); gkyl_wv_apply_bc_release(rbc); @@ -83,8 +87,7 @@ test_apply_bc_1_ho() gkyl_array_release(distf); } -void -test_apply_bc_2_ho() +void test_apply_bc_2_ho() { int ndim = 2; double lower[] = {-1.0, -1.0}, upper[] = {1.0, 1.0}; @@ -92,23 +95,23 @@ test_apply_bc_2_ho() struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); - int nghost[] = { 2, 2 }; + int nghost[] = {2, 2}; struct gkyl_range ext_range, range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); struct gkyl_wave_geom *wg = gkyl_wave_geom_new(&grid, &ext_range, nomapc2p, &ndim, false); - struct gkyl_wv_eqn *eqn = gkyl_wv_burgers_new(false); + struct gkyl_wv_eqn *eqn = gkyl_wv_burgers_new(false); - gkyl_wv_apply_bc *lbc = gkyl_wv_apply_bc_new(&grid, eqn, wg, - 0, GKYL_LOWER_EDGE, nghost, bc_copy, NULL); - gkyl_wv_apply_bc *rbc = gkyl_wv_apply_bc_new(&grid, eqn, wg, - 0, GKYL_UPPER_EDGE, nghost, bc_copy, NULL); + gkyl_wv_apply_bc *lbc = + gkyl_wv_apply_bc_new(&grid, eqn, wg, 0, GKYL_LOWER_EDGE, nghost, bc_copy, NULL); + gkyl_wv_apply_bc *rbc = + gkyl_wv_apply_bc_new(&grid, eqn, wg, 0, GKYL_UPPER_EDGE, nghost, bc_copy, NULL); - gkyl_wv_apply_bc *bbc = gkyl_wv_apply_bc_new(&grid, eqn, wg, - 1, GKYL_LOWER_EDGE, nghost, bc_copy, NULL); - gkyl_wv_apply_bc *tbc = gkyl_wv_apply_bc_new(&grid, eqn, wg, - 1, GKYL_UPPER_EDGE, nghost, bc_copy, NULL); + gkyl_wv_apply_bc *bbc = + gkyl_wv_apply_bc_new(&grid, eqn, wg, 1, GKYL_LOWER_EDGE, nghost, bc_copy, NULL); + gkyl_wv_apply_bc *tbc = + gkyl_wv_apply_bc_new(&grid, eqn, wg, 1, GKYL_UPPER_EDGE, nghost, bc_copy, NULL); struct gkyl_array *distf = gkyl_array_new(GKYL_DOUBLE, 1, ext_range.volume); @@ -124,7 +127,7 @@ test_apply_bc_2_ho() double *f = gkyl_array_fetch(distf, gkyl_range_idx(&ext_range, iter.idx)); vol += f[0]; } - TEST_CHECK( vol == range.volume ); + TEST_CHECK(vol == range.volume); // apply various BCs @@ -144,7 +147,7 @@ test_apply_bc_2_ho() // volume should be volume of ext_range but as corners are not // touched by BC updater we need to subtract the volume of the 4 corners - TEST_CHECK( vol == ext_range.volume-4*4 ); + TEST_CHECK(vol == ext_range.volume - 4 * 4); gkyl_wv_apply_bc_release(lbc); gkyl_wv_apply_bc_release(rbc); @@ -155,8 +158,7 @@ test_apply_bc_2_ho() gkyl_array_release(distf); } -void -test_apply_bc_3_ho() +void test_apply_bc_3_ho() { int ndim = 2; double lower[] = {-1.0, -1.0}, upper[] = {1.0, 1.0}; @@ -164,7 +166,7 @@ test_apply_bc_3_ho() struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); - int nghost[] = { 2, 1 }; + int nghost[] = {2, 1}; struct gkyl_range ext_range, range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); @@ -172,15 +174,15 @@ test_apply_bc_3_ho() struct gkyl_wave_geom *wg = gkyl_wave_geom_new(&grid, &ext_range, nomapc2p, &ndim, false); struct gkyl_wv_eqn *eqn = gkyl_wv_burgers_new(false); - gkyl_wv_apply_bc *lbc = gkyl_wv_apply_bc_new(&grid, eqn, wg, - 0, GKYL_LOWER_EDGE, nghost, bc_copy, NULL); - gkyl_wv_apply_bc *rbc = gkyl_wv_apply_bc_new(&grid, eqn, wg, - 0, GKYL_UPPER_EDGE, nghost, bc_copy, NULL); + gkyl_wv_apply_bc *lbc = + gkyl_wv_apply_bc_new(&grid, eqn, wg, 0, GKYL_LOWER_EDGE, nghost, bc_copy, NULL); + gkyl_wv_apply_bc *rbc = + gkyl_wv_apply_bc_new(&grid, eqn, wg, 0, GKYL_UPPER_EDGE, nghost, bc_copy, NULL); - gkyl_wv_apply_bc *bbc = gkyl_wv_apply_bc_new(&grid, eqn, wg, - 1, GKYL_LOWER_EDGE, nghost, bc_copy, NULL); - gkyl_wv_apply_bc *tbc = gkyl_wv_apply_bc_new(&grid, eqn, wg, - 1, GKYL_UPPER_EDGE, nghost, bc_copy, NULL); + gkyl_wv_apply_bc *bbc = + gkyl_wv_apply_bc_new(&grid, eqn, wg, 1, GKYL_LOWER_EDGE, nghost, bc_copy, NULL); + gkyl_wv_apply_bc *tbc = + gkyl_wv_apply_bc_new(&grid, eqn, wg, 1, GKYL_UPPER_EDGE, nghost, bc_copy, NULL); struct gkyl_array *distf = gkyl_array_new(GKYL_DOUBLE, 1, ext_range.volume); @@ -197,11 +199,11 @@ test_apply_bc_3_ho() double *f = gkyl_array_fetch(distf, gkyl_range_idx(&ext_range, iter.idx)); vol += f[0]; } - TEST_CHECK( vol == range.volume ); + TEST_CHECK(vol == range.volume); /** apply BCs on restricted range: test 1 */ struct gkyl_range sub_range; - gkyl_sub_range_init(&sub_range, &ext_range, (int []) { 1, 2 }, (int []) { 10, 6 }); + gkyl_sub_range_init(&sub_range, &ext_range, (int[]){1, 2}, (int[]){10, 6}); gkyl_wv_apply_bc_advance(lbc, 0.0, &sub_range, distf); gkyl_wv_apply_bc_advance(rbc, 0.0, &sub_range, distf); @@ -219,14 +221,14 @@ test_apply_bc_3_ho() // volume should be volume of range + nghost*5 (as only small // portion of boundary is updated) - TEST_CHECK( vol == range.volume+2*5 ); + TEST_CHECK(vol == range.volume + 2 * 5); /** apply BCs on restricted range: test 2 */ gkyl_array_clear(distf, 0.0); gkyl_array_clear_range(distf, 1.0, &range); - - gkyl_sub_range_init(&sub_range, &ext_range, (int []) { 2, 1 }, (int []) { 8, 4 }); + + gkyl_sub_range_init(&sub_range, &ext_range, (int[]){2, 1}, (int[]){8, 4}); gkyl_wv_apply_bc_advance(lbc, 0.0, &sub_range, distf); gkyl_wv_apply_bc_advance(rbc, 0.0, &sub_range, distf); @@ -241,17 +243,17 @@ test_apply_bc_3_ho() double *f = gkyl_array_fetch(distf, gkyl_range_idx(&ext_range, iter.idx)); vol += f[0]; } - + // volume should be volume of range + nghost*7 (as only small // portion of boundary is updated) - TEST_CHECK( vol == range.volume+1*7 ); + TEST_CHECK(vol == range.volume + 1 * 7); /** apply BCs on restricted range: test 3 */ gkyl_array_clear(distf, 0.0); gkyl_array_clear_range(distf, 1.0, &range); - - gkyl_sub_range_init(&sub_range, &ext_range, (int []) { 2, 2 }, (int []) { 8, 4 }); + + gkyl_sub_range_init(&sub_range, &ext_range, (int[]){2, 2}, (int[]){8, 4}); gkyl_wv_apply_bc_advance(lbc, 0.0, &sub_range, distf); gkyl_wv_apply_bc_advance(rbc, 0.0, &sub_range, distf); @@ -268,7 +270,7 @@ test_apply_bc_3_ho() } // range does not touch boundaries - TEST_CHECK( vol == range.volume ); + TEST_CHECK(vol == range.volume); gkyl_wv_apply_bc_release(lbc); gkyl_wv_apply_bc_release(rbc); @@ -289,32 +291,33 @@ struct skin_ghost_ranges { }; // Create ghost and skin sub-ranges given a parent range -static void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { int ndim = parent->ndim; - - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } -void -test_apply_bc_buff_rtheta_ho() +void test_apply_bc_buff_rtheta_ho() { int ndim = 2; - double lower[] = {0.25, 0.0}, upper[] = {1.25, 2*M_PI/4}; + double lower[] = {0.25, 0.0}, upper[] = {1.25, 2 * M_PI / 4}; int cells[] = {16, 8}; struct gkyl_rect_grid grid; gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); - struct gkyl_wv_eqn *eqn = gkyl_wv_euler_new(1.4, false); + struct gkyl_wv_eqn *eqn = gkyl_wv_euler_new(1.4, false); - int nghost[] = { 2, 2 }; + int nghost[] = {2, 2}; struct gkyl_range ext_range, range; gkyl_create_grid_ranges(&grid, nghost, &ext_range, &range); @@ -324,23 +327,20 @@ test_apply_bc_buff_rtheta_ho() long buff_sz = 0; // compute buffer size needed - for (int d=0; d vol ? buff_sz : vol; } - struct gkyl_array *bc_buffer = gkyl_array_new(GKYL_DOUBLE, - eqn->num_equations, buff_sz); + struct gkyl_array *bc_buffer = gkyl_array_new(GKYL_DOUBLE, eqn->num_equations, buff_sz); - struct gkyl_wave_geom *wg = gkyl_wave_geom_new(&grid, &ext_range, - rtheta_map, &ndim, false); + struct gkyl_wave_geom *wg = gkyl_wave_geom_new(&grid, &ext_range, rtheta_map, &ndim, false); - gkyl_wv_apply_bc *bbc = gkyl_wv_apply_bc_new(&grid, eqn, wg, - 1, GKYL_LOWER_EDGE, nghost, bc_copy, NULL); - gkyl_wv_apply_bc *tbc = gkyl_wv_apply_bc_new(&grid, eqn, wg, - 1, GKYL_UPPER_EDGE, nghost, bc_copy, NULL); + gkyl_wv_apply_bc *bbc = + gkyl_wv_apply_bc_new(&grid, eqn, wg, 1, GKYL_LOWER_EDGE, nghost, bc_copy, NULL); + gkyl_wv_apply_bc *tbc = + gkyl_wv_apply_bc_new(&grid, eqn, wg, 1, GKYL_UPPER_EDGE, nghost, bc_copy, NULL); - struct gkyl_array *fluid = gkyl_array_new(GKYL_DOUBLE, - eqn->num_equations, ext_range.volume); + struct gkyl_array *fluid = gkyl_array_new(GKYL_DOUBLE, eqn->num_equations, ext_range.volume); // set interior of array struct gkyl_range_iter iter; @@ -355,11 +355,11 @@ test_apply_bc_buff_rtheta_ho() double r = xc[0], th = xc[1]; - q[0] = r*th*0.1; - q[1] = r*th*0.5; - q[2] = r*th*1.5; - q[3] = r*th*2.5; - q[4] = r*th*10.5; + q[0] = r * th * 0.1; + q[1] = r * th * 0.5; + q[2] = r * th * 1.5; + q[3] = r * th * 2.5; + q[4] = r * th * 10.5; } // apply various BCs, copying output to a buffer @@ -369,7 +369,7 @@ test_apply_bc_buff_rtheta_ho() gkyl_wv_apply_bc_to_buff(bbc, 0.0, &range, fluid, bc_buffer->data); // check if data copied properly into buffer - long count = 0; + long count = 0; gkyl_range_iter_init(&iter, &skin_ghost.lower_skin[1]); while (gkyl_range_iter_next(&iter)) { double xc[GKYL_MAX_DIM]; @@ -379,14 +379,14 @@ test_apply_bc_buff_rtheta_ho() const double *q = gkyl_array_cfetch(bc_buffer, count++); - TEST_CHECK( q[0] == r*th*0.1 ); + TEST_CHECK(q[0] == r * th * 0.1); // rotate counter-clockwise by pi/4 - TEST_CHECK( gkyl_compare(q[1], -r*th*1.5, 1e-14) ); - TEST_CHECK( gkyl_compare(q[2], r*th*0.5, 1e-14) ); - - TEST_CHECK( gkyl_compare(q[3], r*th*2.5, 1e-14) ); - TEST_CHECK( q[4] == r*th*10.5 ); + TEST_CHECK(gkyl_compare(q[1], -r * th * 1.5, 1e-14)); + TEST_CHECK(gkyl_compare(q[2], r * th * 0.5, 1e-14)); + + TEST_CHECK(gkyl_compare(q[3], r * th * 2.5, 1e-14)); + TEST_CHECK(q[4] == r * th * 10.5); } // right @@ -394,7 +394,7 @@ test_apply_bc_buff_rtheta_ho() gkyl_wv_apply_bc_to_buff(tbc, 0.0, &range, fluid, bc_buffer->data); // check if data copied properly into buffer - count = 0; + count = 0; gkyl_range_iter_init(&iter, &skin_ghost.upper_skin[1]); while (gkyl_range_iter_next(&iter)) { double xc[GKYL_MAX_DIM]; @@ -404,15 +404,15 @@ test_apply_bc_buff_rtheta_ho() const double *q = gkyl_array_cfetch(bc_buffer, count++); - TEST_CHECK( q[0] == r*th*0.1 ); + TEST_CHECK(q[0] == r * th * 0.1); // rotate clockwise by pi/4 - TEST_CHECK( gkyl_compare(q[1], r*th*1.5, 1e-14) ); - TEST_CHECK( gkyl_compare(q[2], -r*th*0.5, 1e-14) ); - - TEST_CHECK( gkyl_compare(q[3], r*th*2.5, 1e-14) ); - TEST_CHECK( q[4] == r*th*10.5 ); - } + TEST_CHECK(gkyl_compare(q[1], r * th * 1.5, 1e-14)); + TEST_CHECK(gkyl_compare(q[2], -r * th * 0.5, 1e-14)); + + TEST_CHECK(gkyl_compare(q[3], r * th * 2.5, 1e-14)); + TEST_CHECK(q[4] == r * th * 10.5); + } gkyl_wv_apply_bc_release(bbc); gkyl_wv_apply_bc_release(tbc); @@ -423,9 +423,9 @@ test_apply_bc_buff_rtheta_ho() } TEST_LIST = { - { "test_apply_bc_1_ho", test_apply_bc_1_ho }, - { "test_apply_bc_2_ho", test_apply_bc_2_ho }, - { "test_apply_bc_3_ho", test_apply_bc_3_ho }, - { "test_apply_bc_buff_rtheta_ho", test_apply_bc_buff_rtheta_ho }, - { NULL, NULL }, + {"test_apply_bc_1_ho", test_apply_bc_1_ho}, + {"test_apply_bc_2_ho", test_apply_bc_2_ho}, + {"test_apply_bc_3_ho", test_apply_bc_3_ho}, + {"test_apply_bc_buff_rtheta_ho", test_apply_bc_buff_rtheta_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_euler.c b/moments/unit/ctest_wv_euler.c index e4c2279f1b..2d0d2f452c 100644 --- a/moments/unit/ctest_wv_euler.c +++ b/moments/unit/ctest_wv_euler.c @@ -3,141 +3,127 @@ #include #include -void -calcq(double gas_gamma, const double pv[5], double q[5]) +void calcq(double gas_gamma, const double pv[5], double q[5]) { double rho = pv[0], u = pv[1], v = pv[2], w = pv[3], pr = pv[4]; q[0] = rho; - q[1] = rho*u; q[2] = rho*v; q[3] = rho*w; - q[4] = pr/(gas_gamma-1) + 0.5*rho*(u*u+v*v+w*w); + q[1] = rho * u; + q[2] = rho * v; + q[3] = rho * w; + q[4] = pr / (gas_gamma - 1) + 0.5 * rho * (u * u + v * v + w * w); } -void -test_euler_basic_ho() +void test_euler_basic_ho() { double gas_gamma = 1.4; struct gkyl_wv_eqn *euler = gkyl_wv_euler_new(gas_gamma, false); - TEST_CHECK( euler->num_equations == 5 ); - TEST_CHECK( euler->num_waves == 3 ); + TEST_CHECK(euler->num_equations == 5); + TEST_CHECK(euler->num_waves == 3); //double rho = 1.0, u = 0.1, v = 0.2, w = 0.3, pr = 1.5; double rho = 1.0, u = 0.1, v = 0.2, w = 0.3, pr = 0.0; - double q[5], pv[5] = { rho, u, v, w, pr }; + double q[5], pv[5] = {rho, u, v, w, pr}; calcq(gas_gamma, pv, q); double E = q[4]; double fluxes[3][5] = { - { rho*u, rho*u*u+pr, rho*u*v, rho*u*w, (E+pr)*u }, - { rho*v, rho*u*v, rho*v*v+pr, rho*v*w, (E+pr)*v }, - { rho*w, rho*u*w, rho*v*w, rho*w*w, (E+pr)*w }, + {rho * u, rho * u * u + pr, rho * u * v, rho * u * w, (E + pr) * u}, + {rho * v, rho * u * v, rho * v * v + pr, rho * v * w, (E + pr) * v}, + {rho * w, rho * u * w, rho * v * w, rho * w * w, (E + pr) * w} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; - TEST_CHECK ( pr == gkyl_euler_pressure(gas_gamma, q) ); + TEST_CHECK(pr == gkyl_euler_pressure(gas_gamma, q)); double q_local[5], flux_local[5], flux[5]; - for (int d=0; d<3; ++d) { + for (int d = 0; d < 3; ++d) { euler->rotate_to_local_func(euler, tau1[d], tau2[d], norm[d], q, q_local); gkyl_euler_flux(gas_gamma, q_local, flux_local); euler->rotate_to_global_func(euler, tau1[d], tau2[d], norm[d], flux_local, flux); - - for (int m=0; m<5; ++m) - TEST_CHECK( gkyl_compare(flux[m], fluxes[d][m], 1e-15) ); + + for (int m = 0; m < 5; ++m) { + TEST_CHECK(gkyl_compare(flux[m], fluxes[d][m], 1e-15)); + } } double q_l[5], q_g[5]; - for (int d=0; d<3; ++d) { + for (int d = 0; d < 3; ++d) { gkyl_wv_eqn_rotate_to_local(euler, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(euler, tau1[d], tau2[d], norm[d], q_l, q_g); - for (int m=0; m<5; ++m) TEST_CHECK( q[m] == q_g[m] ); + for (int m = 0; m < 5; ++m) { + TEST_CHECK(q[m] == q_g[m]); + } // check Riemann transform double w1[5], q1[5]; euler->cons_to_riem(euler, q_local, q_local, w1); euler->riem_to_cons(euler, q_local, w1, q1); - - for (int m=0; m<5; ++m) - TEST_CHECK( gkyl_compare_double(q_local[m], q1[m], 1e-14) ); + + for (int m = 0; m < 5; ++m) { + TEST_CHECK(gkyl_compare_double(q_local[m], q1[m], 1e-14)); + } } - gkyl_wv_eqn_release(euler); } -void -test_euler_waves(enum gkyl_wv_flux_type ftype) +void test_euler_waves(enum gkyl_wv_flux_type ftype) { double gas_gamma = 1.4; struct gkyl_wv_eqn *euler = gkyl_wv_euler_new(gas_gamma, false); - double vl[5] = { 1.0, 0.1, 0.2, 0.3, 1.5}; - double vr[5] = { 0.1, 1.0, 2.0, 3.0, 0.15}; + double vl[5] = {1.0, 0.1, 0.2, 0.3, 1.5}; + double vr[5] = {0.1, 1.0, 2.0, 3.0, 0.15}; double ql[5], qr[5]; double ql_local[5], qr_local[5]; - calcq(gas_gamma, vl, ql); calcq(gas_gamma, vr, qr); + calcq(gas_gamma, vl, ql); + calcq(gas_gamma, vr, qr); - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; - for (int d=0; d<3; ++d) { - double speeds[3], waves[3*5], waves_local[3*5]; + for (int d = 0; d < 3; ++d) { + double speeds[3], waves[3 * 5], waves_local[3 * 5]; // rotate to local tangent-normal frame gkyl_wv_eqn_rotate_to_local(euler, tau1[d], tau2[d], norm[d], ql, ql_local); gkyl_wv_eqn_rotate_to_local(euler, tau1[d], tau2[d], norm[d], qr, qr_local); double delta[5]; - for (int i=0; i<5; ++i) delta[i] = qr_local[i]-ql_local[i]; - + for (int i = 0; i < 5; ++i) { + delta[i] = qr_local[i] - ql_local[i]; + } + gkyl_wv_eqn_waves(euler, ftype, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); double apdq_local[5], amdq_local[5]; - gkyl_wv_eqn_qfluct(euler, ftype, ql_local, qr_local, 1.0, 1.0,waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + euler, ftype, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local + ); // rotate waves back to global frame - for (int mw=0; mw<3; ++mw) - gkyl_wv_eqn_rotate_to_global(euler, tau1[d], tau2[d], norm[d], &waves_local[mw*5], &waves[mw*5]); + for (int mw = 0; mw < 3; ++mw) { + gkyl_wv_eqn_rotate_to_global( + euler, tau1[d], tau2[d], norm[d], &waves_local[mw * 5], &waves[mw * 5] + ); + } double apdq[5], amdq[5]; // rotate fluctuations back to global frame gkyl_wv_eqn_rotate_to_global(euler, tau1[d], tau2[d], norm[d], apdq_local, apdq); gkyl_wv_eqn_rotate_to_global(euler, tau1[d], tau2[d], norm[d], amdq_local, amdq); - + // check if sum of left/right going fluctuations sum to jump in flux double fl_local[5], fr_local[5]; gkyl_euler_flux(gas_gamma, ql_local, fl_local); @@ -146,76 +132,74 @@ test_euler_waves(enum gkyl_wv_flux_type ftype) double fl[5], fr[5]; gkyl_wv_eqn_rotate_to_global(euler, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(euler, tau1[d], tau2[d], norm[d], fr_local, fr); - - for (int i=0; i<5; ++i) - TEST_CHECK( gkyl_compare(fr[i]-fl[i], amdq[i]+apdq[i], 1e-14) ); + + for (int i = 0; i < 5; ++i) { + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); + } } - + gkyl_wv_eqn_release(euler); } -void test_euler_waves_hof_ho(void) { test_euler_waves(GKYL_WV_HIGH_ORDER_FLUX); } -void test_euler_waves_lof_ho(void) { test_euler_waves(GKYL_WV_LOW_ORDER_FLUX); } +void test_euler_waves_hof_ho(void) +{ + test_euler_waves(GKYL_WV_HIGH_ORDER_FLUX); +} +void test_euler_waves_lof_ho(void) +{ + test_euler_waves(GKYL_WV_LOW_ORDER_FLUX); +} -void -test_euler_waves_2(enum gkyl_wv_flux_type ftype, enum gkyl_wv_euler_rp rp_type) +void test_euler_waves_2(enum gkyl_wv_flux_type ftype, enum gkyl_wv_euler_rp rp_type) { double gas_gamma = 1.4; - struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = rp_type, - .use_gpu = false, - }; + struct gkyl_wv_euler_inp inp = {.gas_gamma = gas_gamma, .rp_type = rp_type, .use_gpu = false}; struct gkyl_wv_eqn *euler = gkyl_wv_euler_inew(&inp); - double vl[5] = { 1.0, 0.1, 0.2, 0.3, 1.5}; - double vr[5] = { 0.01, 1.0, 2.0, 3.0, 15.0}; + double vl[5] = {1.0, 0.1, 0.2, 0.3, 1.5}; + double vr[5] = {0.01, 1.0, 2.0, 3.0, 15.0}; double ql[5], qr[5]; double ql_local[5], qr_local[5]; - calcq(gas_gamma, vl, ql); calcq(gas_gamma, vr, qr); + calcq(gas_gamma, vl, ql); + calcq(gas_gamma, vr, qr); - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; - for (int d=0; d<3; ++d) { - double speeds[3], waves[3*5], waves_local[3*5]; + for (int d = 0; d < 3; ++d) { + double speeds[3], waves[3 * 5], waves_local[3 * 5]; // rotate to local tangent-normal frame gkyl_wv_eqn_rotate_to_local(euler, tau1[d], tau2[d], norm[d], ql, ql_local); gkyl_wv_eqn_rotate_to_local(euler, tau1[d], tau2[d], norm[d], qr, qr_local); double delta[5]; - for (int i=0; i<5; ++i) delta[i] = qr_local[i]-ql_local[i]; - + for (int i = 0; i < 5; ++i) { + delta[i] = qr_local[i] - ql_local[i]; + } + gkyl_wv_eqn_waves(euler, ftype, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); double apdq_local[5], amdq_local[5]; - gkyl_wv_eqn_qfluct(euler, ftype, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + euler, ftype, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local + ); // rotate waves back to global frame - for (int mw=0; mw<3; ++mw) - gkyl_wv_eqn_rotate_to_global(euler, tau1[d], tau2[d], norm[d], &waves_local[mw*5], &waves[mw*5]); + for (int mw = 0; mw < 3; ++mw) { + gkyl_wv_eqn_rotate_to_global( + euler, tau1[d], tau2[d], norm[d], &waves_local[mw * 5], &waves[mw * 5] + ); + } double apdq[5], amdq[5]; // rotate fluctuations back to global frame gkyl_wv_eqn_rotate_to_global(euler, tau1[d], tau2[d], norm[d], apdq_local, apdq); gkyl_wv_eqn_rotate_to_global(euler, tau1[d], tau2[d], norm[d], amdq_local, amdq); - + // check if sum of left/right going fluctuations sum to jump in flux double fl_local[5], fr_local[5]; gkyl_euler_flux(gas_gamma, ql_local, fl_local); @@ -224,11 +208,12 @@ test_euler_waves_2(enum gkyl_wv_flux_type ftype, enum gkyl_wv_euler_rp rp_type) double fl[5], fr[5]; gkyl_wv_eqn_rotate_to_global(euler, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(euler, tau1[d], tau2[d], norm[d], fr_local, fr); - - for (int i=0; i<5; ++i) - TEST_CHECK( gkyl_compare(fr[i]-fl[i], amdq[i]+apdq[i], 1e-12) ); + + for (int i = 0; i < 5; ++i) { + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); + } } - + gkyl_wv_eqn_release(euler); } @@ -236,8 +221,7 @@ test_euler_waves_2(enum gkyl_wv_flux_type ftype, enum gkyl_wv_euler_rp rp_type) int cu_wv_euler_test(const struct gkyl_wv_eqn *eqn); -void -test_wv_euler_dev() +void test_wv_euler_dev() { double gas_gamma = 1.4; struct gkyl_wv_eqn *eqn = gkyl_wv_euler_new(gas_gamma, true); @@ -246,61 +230,68 @@ test_wv_euler_dev() // is for testing only struct wv_euler *euler = container_of(eqn, struct wv_euler, eqn); - TEST_CHECK( euler->gas_gamma == 1.4 ); - + TEST_CHECK(euler->gas_gamma == 1.4); + // call CUDA test int nfail = cu_wv_euler_test(eqn->on_dev); - TEST_CHECK( nfail == 0 ); + TEST_CHECK(nfail == 0); gkyl_wv_eqn_release(eqn); } #endif -void test_euler_waves_2_hof_roe_ho(void) { +void test_euler_waves_2_hof_roe_ho(void) +{ test_euler_waves_2(GKYL_WV_HIGH_ORDER_FLUX, WV_EULER_RP_ROE); } -void test_euler_waves_2_lof_roe_ho(void) { +void test_euler_waves_2_lof_roe_ho(void) +{ test_euler_waves_2(GKYL_WV_LOW_ORDER_FLUX, WV_EULER_RP_ROE); } -void test_euler_waves_2_hof_hllc_ho(void) { +void test_euler_waves_2_hof_hllc_ho(void) +{ test_euler_waves_2(GKYL_WV_HIGH_ORDER_FLUX, WV_EULER_RP_HLLC); } -void test_euler_waves_2_lof_hllc_ho(void) { +void test_euler_waves_2_lof_hllc_ho(void) +{ test_euler_waves_2(GKYL_WV_LOW_ORDER_FLUX, WV_EULER_RP_HLLC); } -void test_euler_waves_2_hof_lax_ho(void) { +void test_euler_waves_2_hof_lax_ho(void) +{ test_euler_waves_2(GKYL_WV_HIGH_ORDER_FLUX, WV_EULER_RP_LAX); } -void test_euler_waves_2_lof_lax_ho(void) { +void test_euler_waves_2_lof_lax_ho(void) +{ test_euler_waves_2(GKYL_WV_LOW_ORDER_FLUX, WV_EULER_RP_LAX); } -void test_euler_waves_2_hof_hll_ho(void) { +void test_euler_waves_2_hof_hll_ho(void) +{ test_euler_waves_2(GKYL_WV_HIGH_ORDER_FLUX, WV_EULER_RP_HLL); } -void test_euler_waves_2_lof_hll_ho(void) { +void test_euler_waves_2_lof_hll_ho(void) +{ test_euler_waves_2(GKYL_WV_LOW_ORDER_FLUX, WV_EULER_RP_HLL); } - TEST_LIST = { - { "euler_basic_ho", test_euler_basic_ho }, - { "euler_waves_hof_ho", test_euler_waves_hof_ho }, - { "euler_waves_lof_ho", test_euler_waves_lof_ho }, - { "euler_waves_2_hof_roe_ho", test_euler_waves_2_hof_roe_ho }, - { "euler_waves_2_lof_roe_ho", test_euler_waves_2_lof_roe_ho }, - { "euler_waves_2_hof_hllc_ho", test_euler_waves_2_hof_hllc_ho }, - { "euler_waves_2_lof_hllc_ho", test_euler_waves_2_lof_hllc_ho }, - { "euler_waves_2_hof_lax_ho", test_euler_waves_2_hof_lax_ho }, - { "euler_waves_2_lof_lax_ho", test_euler_waves_2_lof_lax_ho }, - { "euler_waves_2_hof_hll_ho", test_euler_waves_2_hof_hll_ho }, - { "euler_waves_2_lof_hll_ho", test_euler_waves_2_lof_hll_ho }, + {"euler_basic_ho", test_euler_basic_ho}, + {"euler_waves_hof_ho", test_euler_waves_hof_ho}, + {"euler_waves_lof_ho", test_euler_waves_lof_ho}, + {"euler_waves_2_hof_roe_ho", test_euler_waves_2_hof_roe_ho}, + {"euler_waves_2_lof_roe_ho", test_euler_waves_2_lof_roe_ho}, + {"euler_waves_2_hof_hllc_ho", test_euler_waves_2_hof_hllc_ho}, + {"euler_waves_2_lof_hllc_ho", test_euler_waves_2_lof_hllc_ho}, + {"euler_waves_2_hof_lax_ho", test_euler_waves_2_hof_lax_ho}, + {"euler_waves_2_lof_lax_ho", test_euler_waves_2_lof_lax_ho}, + {"euler_waves_2_hof_hll_ho", test_euler_waves_2_hof_hll_ho}, + {"euler_waves_2_lof_hll_ho", test_euler_waves_2_lof_hll_ho}, #ifdef GKYL_HAVE_CUDA - { "wv_euler_dev", test_wv_euler_dev }, -#endif - { NULL, NULL }, + {"wv_euler_dev", test_wv_euler_dev}, +#endif + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_euler_cu.cu b/moments/unit/ctest_wv_euler_cu.cu index ad430d9966..dda2f64f21 100644 --- a/moments/unit/ctest_wv_euler_cu.cu +++ b/moments/unit/ctest_wv_euler_cu.cu @@ -11,77 +11,69 @@ extern "C" { int cu_wv_euler_test(const struct gkyl_wv_eqn *eqn); } -__global__ -void ker_cu_wv_euler_test(const struct gkyl_wv_eqn *eqn, int *nfail) +__global__ void ker_cu_wv_euler_test(const struct gkyl_wv_eqn *eqn, int *nfail) { *nfail = 0; - GKYL_CU_CHECK( eqn->num_equations == 5, nfail ); - GKYL_CU_CHECK( eqn->num_waves == 3, nfail ); + GKYL_CU_CHECK(eqn->num_equations == 5, nfail); + GKYL_CU_CHECK(eqn->num_waves == 3, nfail); // DO NOT DO THIS IN PRODUCTION! ONLY FOR TESTING struct wv_euler *euler = container_of(eqn, struct wv_euler, eqn); - GKYL_CU_CHECK( euler->gas_gamma == 1.4, nfail ); + GKYL_CU_CHECK(euler->gas_gamma == 1.4, nfail); double gas_gamma = euler->gas_gamma; - + double rho = 1.0, u = 0.1, v = 0.2, w = 0.3, pr = 0.0; double q[5]; q[0] = rho; - q[1] = rho*u; q[2] = rho*v; q[3] = rho*w; - q[4] = pr/(gas_gamma-1) + 0.5*rho*(u*u+v*v+w*w); + q[1] = rho * u; + q[2] = rho * v; + q[3] = rho * w; + q[4] = pr / (gas_gamma - 1) + 0.5 * rho * (u * u + v * v + w * w); double E = q[4]; double fluxes[3][5] = { - { rho*u, rho*u*u+pr, rho*u*v, rho*u*w, (E+pr)*u }, - { rho*v, rho*u*v, rho*v*v+pr, rho*v*w, (E+pr)*v }, - { rho*w, rho*u*w, rho*v*w, rho*w*w, (E+pr)*w }, + {rho * u, rho * u * u + pr, rho * u * v, rho * u * w, (E + pr) * u}, + {rho * v, rho * u * v, rho * v * v + pr, rho * v * w, (E + pr) * v}, + {rho * w, rho * u * w, rho * v * w, rho * w * w, (E + pr) * w} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; - GKYL_CU_CHECK( pr == gkyl_euler_pressure(gas_gamma, q), nfail ); + GKYL_CU_CHECK(pr == gkyl_euler_pressure(gas_gamma, q), nfail); double q_local[5], flux_local[5], flux[5]; - for (int d=0; d<3; ++d) { + for (int d = 0; d < 3; ++d) { eqn->rotate_to_local_func(eqn, tau1[d], tau2[d], norm[d], q, q_local); gkyl_euler_flux(gas_gamma, q_local, flux_local); eqn->rotate_to_global_func(eqn, tau1[d], tau2[d], norm[d], flux_local, flux); - - for (int m=0; m<5; ++m) - GKYL_CU_CHECK( flux[m] == fluxes[d][m], nfail ); + + for (int m = 0; m < 5; ++m) { + GKYL_CU_CHECK(flux[m] == fluxes[d][m], nfail); + } } double q_l[5], q_g[5]; - for (int d=0; d<3; ++d) { + for (int d = 0; d < 3; ++d) { eqn->rotate_to_local_func(eqn, tau1[d], tau2[d], norm[d], q, q_l); eqn->rotate_to_global_func(eqn, tau1[d], tau2[d], norm[d], q_l, q_g); - for (int m=0; m<5; ++m) GKYL_CU_CHECK( q[m] == q_g[m], nfail ); + for (int m = 0; m < 5; ++m) { + GKYL_CU_CHECK(q[m] == q_g[m], nfail); + } } } int cu_wv_euler_test(const struct gkyl_wv_eqn *eqn) { - int *nfail_dev = (int *) gkyl_cu_malloc(sizeof(int)); - ker_cu_wv_euler_test<<<1,1>>>(eqn, nfail_dev); + int *nfail_dev = (int *)gkyl_cu_malloc(sizeof(int)); + ker_cu_wv_euler_test<<<1, 1> > >(eqn, nfail_dev); int nfail; gkyl_cu_memcpy(&nfail, nfail_dev, sizeof(int), GKYL_CU_MEMCPY_D2H); diff --git a/moments/unit/ctest_wv_euler_mixture.c b/moments/unit/ctest_wv_euler_mixture.c index 7809d86f80..4d03de5878 100644 --- a/moments/unit/ctest_wv_euler_mixture.c +++ b/moments/unit/ctest_wv_euler_mixture.c @@ -4,8 +4,7 @@ #include #include -void -test_euler_mixture_twocomponent_basic_ho() +void test_euler_mixture_twocomponent_basic_ho() { double gas_gamma1 = 1.4; double gas_gamma2 = 1.67; @@ -16,62 +15,60 @@ test_euler_mixture_twocomponent_basic_ho() struct gkyl_wv_eqn *euler_mixture = gkyl_wv_euler_mixture_new(2, gas_gamma_s, false); - TEST_CHECK( euler_mixture->num_equations == 8 ); - TEST_CHECK( euler_mixture->num_waves == 2 ); + TEST_CHECK(euler_mixture->num_equations == 8); + TEST_CHECK(euler_mixture->num_waves == 2); - double alpha1 = 0.75, rho1 = 1.0, rho2 = 2.0, vx_total = 0.1, vy_total = 0.2, vz_total = 0.3, p_total = 1.5; + double alpha1 = 0.75, rho1 = 1.0, rho2 = 2.0, vx_total = 0.1, vy_total = 0.2, vz_total = 0.3, + p_total = 1.5; double rho_total = (alpha1 * rho1) + ((1.0 - alpha1) * rho2); - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); + double E1 = + (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); + double E2 = + (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); double E_total = (alpha1 * E1) + ((1.0 - alpha1) * E2); - double q[8] = { rho_total, rho_total * vx_total, rho_total * vy_total, rho_total * vz_total, E_total, rho_total * alpha1, - alpha1 * rho1, (1.0 - alpha1) * rho2 }; + double q[8] = {rho_total, rho_total * vx_total, rho_total * vy_total, rho_total * vz_total, + E_total, rho_total * alpha1, alpha1 * rho1, (1.0 - alpha1) * rho2}; double prims[8]; gkyl_euler_mixture_prim_vars(2, gas_gamma_s, q, prims); - TEST_CHECK( gkyl_compare(prims[0], rho_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[1], vx_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[2], vy_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[3], vz_total, 1e-16) ); + TEST_CHECK(gkyl_compare(prims[0], rho_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[1], vx_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[2], vy_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[3], vz_total, 1e-16)); // For now, we check only that the reconstructed mixture pressure is of the correct order of magnitude. // This error tolerance can be reduced once we have introduced more physical mixture rules into the system. - TEST_CHECK( gkyl_compare(prims[4], p_total, 1e-1) ); + TEST_CHECK(gkyl_compare(prims[4], p_total, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], alpha1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[6], rho1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[7], rho2, 1e-16)); - TEST_CHECK( gkyl_compare(prims[5], alpha1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[6], rho1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[7], rho2, 1e-16) ); - p_total = prims[4]; // Use the reconstructed mixture pressure. double fluxes[3][8] = { - { rho_total * vx_total, (rho_total * (vx_total * vx_total)) + p_total, rho_total * (vx_total * vy_total), rho_total * (vx_total * vz_total), - (E_total * vx_total) + (vx_total * p_total), rho_total * vx_total * alpha1, alpha1 * (vx_total * rho1), (1.0 - alpha1) * (vx_total * rho2) }, - { rho_total * vy_total, rho_total * (vy_total * vx_total), (rho_total * (vy_total * vy_total)) + p_total, rho_total * (vy_total * vz_total), - (E_total * vy_total) + (vy_total * p_total), rho_total * vy_total * alpha1, alpha1 * (vy_total * rho1), (1.0 - alpha1) * (vy_total * rho2) }, - { rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), (rho_total * (vz_total * vz_total)) + p_total, - (E_total * vz_total) + (vz_total * p_total), rho_total * vz_total * alpha1, alpha1 * (vz_total * rho1), (1.0 - alpha1) * (vz_total * rho2) }, + {rho_total * vx_total, (rho_total * (vx_total * vx_total)) + p_total, + rho_total * (vx_total * vy_total), rho_total * (vx_total * vz_total), + (E_total * vx_total) + (vx_total * p_total), rho_total * vx_total * alpha1, + alpha1 * (vx_total * rho1), (1.0 - alpha1) * (vx_total * rho2)}, + {rho_total * vy_total, rho_total * (vy_total * vx_total), + (rho_total * (vy_total * vy_total)) + p_total, rho_total * (vy_total * vz_total), + (E_total * vy_total) + (vy_total * p_total), rho_total * vy_total * alpha1, + alpha1 * (vy_total * rho1), (1.0 - alpha1) * (vy_total * rho2)}, + {rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), + (rho_total * (vz_total * vz_total)) + p_total, (E_total * vz_total) + (vz_total * p_total), + rho_total * vz_total * alpha1, alpha1 * (vz_total * rho1), (1.0 - alpha1) * (vz_total * rho2)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[8], flux_local[8], flux[8]; for (int d = 0; d < 3; d++) { @@ -80,7 +77,7 @@ test_euler_mixture_twocomponent_basic_ho() euler_mixture->rotate_to_global_func(euler_mixture, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-15) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-15)); } } @@ -90,7 +87,7 @@ test_euler_mixture_twocomponent_basic_ho() gkyl_wv_eqn_rotate_to_global(euler_mixture, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-16)); } double w1[8], q1[8]; @@ -98,7 +95,7 @@ test_euler_mixture_twocomponent_basic_ho() euler_mixture->riem_to_cons(euler_mixture, q_local, w1, q1); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-16)); } } @@ -106,8 +103,7 @@ test_euler_mixture_twocomponent_basic_ho() gkyl_free(gas_gamma_s); } -void -test_euler_mixture_threecomponent_basic_ho() +void test_euler_mixture_threecomponent_basic_ho() { double gas_gamma1 = 1.4; double gas_gamma2 = 1.67; @@ -120,68 +116,78 @@ test_euler_mixture_threecomponent_basic_ho() struct gkyl_wv_eqn *euler_mixture = gkyl_wv_euler_mixture_new(3, gas_gamma_s, false); - TEST_CHECK( euler_mixture->num_equations == 10 ); - TEST_CHECK( euler_mixture->num_waves == 2 ); + TEST_CHECK(euler_mixture->num_equations == 10); + TEST_CHECK(euler_mixture->num_waves == 2); - double alpha1 = 0.5, alpha2 = 0.3, rho1 = 1.0, rho2 = 2.0, rho3 = 3.0, vx_total = 0.1, vy_total = 0.2, vz_total = 0.3, p_total = 1.5; + double alpha1 = 0.5, alpha2 = 0.3, rho1 = 1.0, rho2 = 2.0, rho3 = 3.0, vx_total = 0.1, + vy_total = 0.2, vz_total = 0.3, p_total = 1.5; double rho_total = (alpha1 * rho1) + (alpha2 * rho2) + ((1.0 - (alpha1 + alpha2)) * rho3); - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); - double E3 = (p_total / (gas_gamma3 - 1.0)) + (0.5 * rho3 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); + double E1 = + (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); + double E2 = + (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); + double E3 = + (p_total / (gas_gamma3 - 1.0)) + + (0.5 * rho3 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); double E_total = (alpha1 * E1) + (alpha2 * E2) + ((1.0 - (alpha1 + alpha2)) * rho3); - double q[10] = { rho_total, rho_total * vx_total, rho_total * vy_total, rho_total * vz_total, E_total, rho_total * alpha1, - rho_total * alpha2, alpha1 * rho1, alpha2 * rho2, (1.0 - (alpha1 + alpha2)) * rho3 }; + double q[10] = { + rho_total, + rho_total * vx_total, + rho_total * vy_total, + rho_total * vz_total, + E_total, + rho_total * alpha1, + rho_total * alpha2, + alpha1 * rho1, + alpha2 * rho2, + (1.0 - (alpha1 + alpha2)) * rho3 + }; double prims[10]; gkyl_euler_mixture_prim_vars(3, gas_gamma_s, q, prims); - TEST_CHECK( gkyl_compare(prims[0], rho_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[1], vx_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[2], vy_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[3], vz_total, 1e-16) ); + TEST_CHECK(gkyl_compare(prims[0], rho_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[1], vx_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[2], vy_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[3], vz_total, 1e-16)); // For now, we check only that the reconstructed mixture pressure is of the correct order of magnitude. // This error tolerance can be reduced once we have introduced more physical mixture rules into the system. - TEST_CHECK( gkyl_compare(prims[4], p_total, 1e-1) ); - - TEST_CHECK( gkyl_compare(prims[5], alpha1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[6], alpha2, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[7], rho1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[8], rho2, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[9], rho3, 1e-16) ); - + TEST_CHECK(gkyl_compare(prims[4], p_total, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], alpha1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[6], alpha2, 1e-16)); + TEST_CHECK(gkyl_compare(prims[7], rho1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[8], rho2, 1e-16)); + TEST_CHECK(gkyl_compare(prims[9], rho3, 1e-16)); + p_total = prims[4]; // Use the reconstructed mixture pressure. double fluxes[3][10] = { - { rho_total * vx_total, (rho_total * (vx_total * vx_total)) + p_total, rho_total * (vx_total * vy_total), rho_total * (vx_total * vz_total), - (E_total * vx_total) + (vx_total * p_total), rho_total * vx_total * alpha1, rho_total * vx_total * alpha2, alpha1 * (vx_total * rho1), - alpha2 * (vx_total * rho2), (1.0 - (alpha1 + alpha2)) * (vx_total * rho3) }, - { rho_total * vy_total, rho_total * (vy_total * vx_total), (rho_total * (vy_total * vy_total)) + p_total, rho_total * (vy_total * vz_total), - (E_total * vy_total) + (vy_total * p_total), rho_total * vy_total * alpha1, rho_total * vy_total * alpha2, alpha1 * (vy_total * rho1), - alpha2 * (vy_total * rho2), (1.0 - (alpha1 + alpha2)) * (vy_total * rho3) }, - { rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), (rho_total * (vz_total * vz_total)) + p_total, - (E_total * vz_total) + (vz_total * p_total), rho_total * vz_total * alpha1, rho_total * vz_total * alpha2, alpha1 * (vz_total * rho1), - alpha2 * (vz_total * rho2), (1.0 - (alpha1 + alpha2)) * (vz_total * rho3) }, + {rho_total * vx_total, (rho_total * (vx_total * vx_total)) + p_total, + rho_total * (vx_total * vy_total), rho_total * (vx_total * vz_total), + (E_total * vx_total) + (vx_total * p_total), rho_total * vx_total * alpha1, + rho_total * vx_total * alpha2, alpha1 * (vx_total * rho1), alpha2 * (vx_total * rho2), + (1.0 - (alpha1 + alpha2)) * (vx_total * rho3)}, + {rho_total * vy_total, rho_total * (vy_total * vx_total), + (rho_total * (vy_total * vy_total)) + p_total, rho_total * (vy_total * vz_total), + (E_total * vy_total) + (vy_total * p_total), rho_total * vy_total * alpha1, + rho_total * vy_total * alpha2, alpha1 * (vy_total * rho1), alpha2 * (vy_total * rho2), + (1.0 - (alpha1 + alpha2)) * (vy_total * rho3)}, + {rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), + (rho_total * (vz_total * vz_total)) + p_total, (E_total * vz_total) + (vz_total * p_total), + rho_total * vz_total * alpha1, rho_total * vz_total * alpha2, alpha1 * (vz_total * rho1), + alpha2 * (vz_total * rho2), (1.0 - (alpha1 + alpha2)) * (vz_total * rho3)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[10], flux_local[10], flux[10]; for (int d = 0; d < 3; d++) { @@ -190,7 +196,7 @@ test_euler_mixture_threecomponent_basic_ho() euler_mixture->rotate_to_global_func(euler_mixture, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 10; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-16) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-16)); } } @@ -200,7 +206,7 @@ test_euler_mixture_threecomponent_basic_ho() gkyl_wv_eqn_rotate_to_global(euler_mixture, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 10; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-16)); } double w1[10], q1[10]; @@ -208,7 +214,7 @@ test_euler_mixture_threecomponent_basic_ho() euler_mixture->riem_to_cons(euler_mixture, q_local, w1, q1); for (int i = 0; i < 10; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-16)); } } @@ -216,53 +222,58 @@ test_euler_mixture_threecomponent_basic_ho() gkyl_free(gas_gamma_s); } -void -test_euler_mixture_twocomponent_waves_ho() +void test_euler_mixture_twocomponent_waves_ho() { double gas_gamma1 = 1.4; double gas_gamma2 = 1.67; - + double *gas_gamma_s = gkyl_malloc(sizeof(double[2])); gas_gamma_s[0] = gas_gamma1; gas_gamma_s[1] = gas_gamma2; struct gkyl_wv_eqn *euler_mixture = gkyl_wv_euler_mixture_new(2, gas_gamma_s, false); - - double alpha1_l = 0.75, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; + + double alpha1_l = 0.75, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, + vz_total_l = 0.3, p_total_l = 1.5; double rho_total_l = (alpha1_l * rho1_l) + ((1.0 - alpha1_l) * rho2_l); - double E1_l = (p_total_l / (gas_gamma1 - 1.0)) + (0.5 * rho1_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E2_l = (p_total_l / (gas_gamma2 - 1.0)) + (0.5 * rho2_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E1_l = + (p_total_l / (gas_gamma1 - 1.0)) + + (0.5 * rho1_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E2_l = + (p_total_l / (gas_gamma2 - 1.0)) + + (0.5 * rho2_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); double E_total_l = (alpha1_l * E1_l) + ((1.0 - alpha1_l) * E2_l); - double alpha1_r = 0.25, rho1_r = 0.1, rho2_r = 0.2, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 0.15; + double alpha1_r = 0.25, rho1_r = 0.1, rho2_r = 0.2, vx_total_r = 1.0, vy_total_r = 2.0, + vz_total_r = 3.0, p_total_r = 0.15; double rho_total_r = (alpha1_r * rho1_r) + ((1.0 - alpha1_r) * rho2_r); - double E1_r = (p_total_r / (gas_gamma1 - 1.0)) + (0.5 * rho1_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E2_r = (p_total_r / (gas_gamma2 - 1.0)) + (0.5 * rho2_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E1_r = + (p_total_r / (gas_gamma1 - 1.0)) + + (0.5 * rho1_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E2_r = + (p_total_r / (gas_gamma2 - 1.0)) + + (0.5 * rho2_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); double E_total_r = (alpha1_r * E1_r) + ((1.0 - alpha1_r) * E2_r); - double ql[8] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, E_total_l, rho_total_l * alpha1_l, - alpha1_l * rho1_l, (1.0 - alpha1_l) * rho2_l }; - double qr[8] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, E_total_r, rho_total_r * alpha1_r, - alpha1_r * rho1_r, (1.0 - alpha1_r) * rho2_r }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[8] = { + rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, + E_total_l, rho_total_l * alpha1_l, alpha1_l * rho1_l, (1.0 - alpha1_l) * rho2_l }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[8] = { + rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, + E_total_r, rho_total_r * alpha1_r, alpha1_r * rho1_r, (1.0 - alpha1_r) * rho2_r }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 8], waves_local[2 * 8]; @@ -275,13 +286,21 @@ test_euler_mixture_twocomponent_waves_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[8], amdq_local[8]; - gkyl_wv_eqn_qfluct(euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 8], &waves[i * 8]); + gkyl_wv_eqn_rotate_to_global( + euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 8], &waves[i * 8] + ); } double apdq[8], amdq[8]; @@ -297,7 +316,7 @@ test_euler_mixture_twocomponent_waves_ho() gkyl_wv_eqn_rotate_to_global(euler_mixture, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); } } @@ -305,53 +324,58 @@ test_euler_mixture_twocomponent_waves_ho() gkyl_free(gas_gamma_s); } -void -test_euler_mixture_twocomponent_waves_2_ho() +void test_euler_mixture_twocomponent_waves_2_ho() { double gas_gamma1 = 1.2; double gas_gamma2 = 1.7; - + double *gas_gamma_s = gkyl_malloc(sizeof(double[2])); gas_gamma_s[0] = gas_gamma1; gas_gamma_s[1] = gas_gamma2; struct gkyl_wv_eqn *euler_mixture = gkyl_wv_euler_mixture_new(2, gas_gamma_s, false); - - double alpha1_l = 0.9, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; + + double alpha1_l = 0.9, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, + vz_total_l = 0.3, p_total_l = 1.5; double rho_total_l = (alpha1_l * rho1_l) + ((1.0 - alpha1_l) * rho2_l); - double E1_l = (p_total_l / (gas_gamma1 - 1.0)) + (0.5 * rho1_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E2_l = (p_total_l / (gas_gamma2 - 1.0)) + (0.5 * rho2_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E1_l = + (p_total_l / (gas_gamma1 - 1.0)) + + (0.5 * rho1_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E2_l = + (p_total_l / (gas_gamma2 - 1.0)) + + (0.5 * rho2_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); double E_total_l = (alpha1_l * E1_l) + ((1.0 - alpha1_l) * E2_l); - double alpha1_r = 0.1, rho1_r = 0.01, rho2_r = 0.02, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 15.0; + double alpha1_r = 0.1, rho1_r = 0.01, rho2_r = 0.02, vx_total_r = 1.0, vy_total_r = 2.0, + vz_total_r = 3.0, p_total_r = 15.0; double rho_total_r = (alpha1_r * rho1_r) + ((1.0 - alpha1_r) * rho2_r); - double E1_r = (p_total_r / (gas_gamma1 - 1.0)) + (0.5 * rho1_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E2_r = (p_total_r / (gas_gamma2 - 1.0)) + (0.5 * rho2_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E1_r = + (p_total_r / (gas_gamma1 - 1.0)) + + (0.5 * rho1_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E2_r = + (p_total_r / (gas_gamma2 - 1.0)) + + (0.5 * rho2_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); double E_total_r = (alpha1_r * E1_r) + ((1.0 - alpha1_r) * E2_r); - double ql[8] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, E_total_l, rho_total_l * alpha1_l, - alpha1_l * rho1_l, (1.0 - alpha1_l) * rho2_l }; - double qr[8] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, E_total_r, rho_total_r * alpha1_r, - alpha1_r * rho1_r, (1.0 - alpha1_r) * rho2_r }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[8] = { + rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, + E_total_l, rho_total_l * alpha1_l, alpha1_l * rho1_l, (1.0 - alpha1_l) * rho2_l }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[8] = { + rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, + E_total_r, rho_total_r * alpha1_r, alpha1_r * rho1_r, (1.0 - alpha1_r) * rho2_r }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 8], waves_local[2 * 8]; @@ -364,13 +388,21 @@ test_euler_mixture_twocomponent_waves_2_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[8], amdq_local[8]; - gkyl_wv_eqn_qfluct(euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 8], &waves[i * 8]); + gkyl_wv_eqn_rotate_to_global( + euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 8], &waves[i * 8] + ); } double apdq[8], amdq[8]; @@ -386,7 +418,7 @@ test_euler_mixture_twocomponent_waves_2_ho() gkyl_wv_eqn_rotate_to_global(euler_mixture, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } @@ -394,57 +426,86 @@ test_euler_mixture_twocomponent_waves_2_ho() gkyl_free(gas_gamma_s); } -void -test_euler_mixture_threecomponent_waves_ho() +void test_euler_mixture_threecomponent_waves_ho() { double gas_gamma1 = 1.4; double gas_gamma2 = 1.67; double gas_gamma3 = 1.9; - + double *gas_gamma_s = gkyl_malloc(sizeof(double[3])); gas_gamma_s[0] = gas_gamma1; gas_gamma_s[1] = gas_gamma2; gas_gamma_s[2] = gas_gamma3; struct gkyl_wv_eqn *euler_mixture = gkyl_wv_euler_mixture_new(3, gas_gamma_s, false); - - double alpha1_l = 0.5, alpha2_l = 0.3, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; - double rho_total_l = (alpha1_l * rho1_l) + (alpha2_l * rho2_l) + ((1.0 - (alpha1_l + alpha2_l)) * rho3_l); - double E1_l = (p_total_l / (gas_gamma1 - 1.0)) + (0.5 * rho1_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E2_l = (p_total_l / (gas_gamma2 - 1.0)) + (0.5 * rho2_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E3_l = (p_total_l / (gas_gamma3 - 1.0)) + (0.5 * rho3_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + + double alpha1_l = 0.5, alpha2_l = 0.3, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, + vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; + double rho_total_l = + (alpha1_l * rho1_l) + (alpha2_l * rho2_l) + ((1.0 - (alpha1_l + alpha2_l)) * rho3_l); + double E1_l = + (p_total_l / (gas_gamma1 - 1.0)) + + (0.5 * rho1_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E2_l = + (p_total_l / (gas_gamma2 - 1.0)) + + (0.5 * rho2_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E3_l = + (p_total_l / (gas_gamma3 - 1.0)) + + (0.5 * rho3_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); double E_total_l = (alpha1_l * E1_l) + (alpha2_l * E2_l) + ((1.0 - (alpha1_l + alpha2_l)) * E3_l); - double alpha1_r = 0.4, alpha2_r = 0.2, rho1_r = 0.1, rho2_r = 0.2, rho3_r = 0.3, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 0.15; - double rho_total_r = (alpha1_r * rho1_r) + (alpha2_r * rho2_r) + ((1.0 - (alpha1_r + alpha2_r)) * rho3_r); - double E1_r = (p_total_r / (gas_gamma1 - 1.0)) + (0.5 * rho1_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E2_r = (p_total_r / (gas_gamma2 - 1.0)) + (0.5 * rho2_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E3_r = (p_total_r / (gas_gamma3 - 1.0)) + (0.5 * rho3_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double alpha1_r = 0.4, alpha2_r = 0.2, rho1_r = 0.1, rho2_r = 0.2, rho3_r = 0.3, vx_total_r = 1.0, + vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 0.15; + double rho_total_r = + (alpha1_r * rho1_r) + (alpha2_r * rho2_r) + ((1.0 - (alpha1_r + alpha2_r)) * rho3_r); + double E1_r = + (p_total_r / (gas_gamma1 - 1.0)) + + (0.5 * rho1_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E2_r = + (p_total_r / (gas_gamma2 - 1.0)) + + (0.5 * rho2_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E3_r = + (p_total_r / (gas_gamma3 - 1.0)) + + (0.5 * rho3_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); double E_total_r = (alpha1_r * E1_r) + (alpha2_r * E2_r) + ((1.0 - (alpha1_r + alpha2_r)) * E3_r); - double ql[10] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, E_total_l, rho_total_l * alpha1_l, - rho_total_l * alpha2_l, alpha1_l * rho1_l, alpha2_l * rho2_l, (1.0 - (alpha1_l + alpha2_l)) * rho3_l }; - double qr[10] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, E_total_r, rho_total_r * alpha1_r, - rho_total_r * alpha2_r, alpha1_r * rho1_r, alpha2_r * rho2_r, (1.0 - (alpha1_r + alpha2_r)) * rho3_r }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[10] = { + rho_total_l, + rho_total_l * vx_total_l, + rho_total_l * vy_total_l, + rho_total_l * vz_total_l, + E_total_l, + rho_total_l * alpha1_l, + rho_total_l * alpha2_l, + alpha1_l * rho1_l, + alpha2_l * rho2_l, + (1.0 - (alpha1_l + alpha2_l)) * rho3_l }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[10] = { + rho_total_r, + rho_total_r * vx_total_r, + rho_total_r * vy_total_r, + rho_total_r * vz_total_r, + E_total_r, + rho_total_r * alpha1_r, + rho_total_r * alpha2_r, + alpha1_r * rho1_r, + alpha2_r * rho2_r, + (1.0 - (alpha1_r + alpha2_r)) * rho3_r }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 10], waves_local[2 * 10]; @@ -457,13 +518,21 @@ test_euler_mixture_threecomponent_waves_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[10], amdq_local[10]; - gkyl_wv_eqn_qfluct(euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 10], &waves[i * 10]); + gkyl_wv_eqn_rotate_to_global( + euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 10], &waves[i * 10] + ); } double apdq[10], amdq[10]; @@ -479,7 +548,7 @@ test_euler_mixture_threecomponent_waves_ho() gkyl_wv_eqn_rotate_to_global(euler_mixture, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 10; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } @@ -487,57 +556,86 @@ test_euler_mixture_threecomponent_waves_ho() gkyl_free(gas_gamma_s); } -void -test_euler_mixture_threecomponent_waves_2_ho() +void test_euler_mixture_threecomponent_waves_2_ho() { double gas_gamma1 = 1.1; double gas_gamma2 = 1.5; double gas_gamma3 = 1.9; - + double *gas_gamma_s = gkyl_malloc(sizeof(double[3])); gas_gamma_s[0] = gas_gamma1; gas_gamma_s[1] = gas_gamma2; gas_gamma_s[2] = gas_gamma3; struct gkyl_wv_eqn *euler_mixture = gkyl_wv_euler_mixture_new(3, gas_gamma_s, false); - - double alpha1_l = 0.8, alpha2_l = 0.1, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; - double rho_total_l = (alpha1_l * rho1_l) + (alpha2_l * rho2_l) + ((1.0 - (alpha1_l + alpha2_l)) * rho3_l); - double E1_l = (p_total_l / (gas_gamma1 - 1.0)) + (0.5 * rho1_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E2_l = (p_total_l / (gas_gamma2 - 1.0)) + (0.5 * rho2_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E3_l = (p_total_l / (gas_gamma3 - 1.0)) + (0.5 * rho3_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + + double alpha1_l = 0.8, alpha2_l = 0.1, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, + vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; + double rho_total_l = + (alpha1_l * rho1_l) + (alpha2_l * rho2_l) + ((1.0 - (alpha1_l + alpha2_l)) * rho3_l); + double E1_l = + (p_total_l / (gas_gamma1 - 1.0)) + + (0.5 * rho1_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E2_l = + (p_total_l / (gas_gamma2 - 1.0)) + + (0.5 * rho2_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E3_l = + (p_total_l / (gas_gamma3 - 1.0)) + + (0.5 * rho3_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); double E_total_l = (alpha1_l * E1_l) + (alpha2_l * E2_l) + ((1.0 - (alpha1_l + alpha2_l)) * E3_l); - double alpha1_r = 0.75, alpha2_r = 0.2, rho1_r = 0.01, rho2_r = 0.02, rho3_r = 0.03, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 15.0; - double rho_total_r = (alpha1_r * rho1_r) + (alpha2_r * rho2_r) + ((1.0 - (alpha1_r + alpha2_r)) * rho3_r); - double E1_r = (p_total_r / (gas_gamma1 - 1.0)) + (0.5 * rho1_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E2_r = (p_total_r / (gas_gamma2 - 1.0)) + (0.5 * rho2_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E3_r = (p_total_r / (gas_gamma3 - 1.0)) + (0.5 * rho3_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double alpha1_r = 0.75, alpha2_r = 0.2, rho1_r = 0.01, rho2_r = 0.02, rho3_r = 0.03, + vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 15.0; + double rho_total_r = + (alpha1_r * rho1_r) + (alpha2_r * rho2_r) + ((1.0 - (alpha1_r + alpha2_r)) * rho3_r); + double E1_r = + (p_total_r / (gas_gamma1 - 1.0)) + + (0.5 * rho1_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E2_r = + (p_total_r / (gas_gamma2 - 1.0)) + + (0.5 * rho2_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E3_r = + (p_total_r / (gas_gamma3 - 1.0)) + + (0.5 * rho3_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); double E_total_r = (alpha1_r * E1_r) + (alpha2_r * E2_r) + ((1.0 - (alpha1_r + alpha2_r)) * E3_r); - double ql[10] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, E_total_l, rho_total_l * alpha1_l, - rho_total_l * alpha2_l, alpha1_l * rho1_l, alpha2_l * rho2_l, (1.0 - (alpha1_l + alpha2_l)) * rho3_l }; - double qr[10] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, E_total_r, rho_total_r * alpha1_r, - rho_total_r * alpha2_r, alpha1_r * rho1_r, alpha2_r * rho2_r, (1.0 - (alpha1_r + alpha2_r)) * rho3_r }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[10] = { + rho_total_l, + rho_total_l * vx_total_l, + rho_total_l * vy_total_l, + rho_total_l * vz_total_l, + E_total_l, + rho_total_l * alpha1_l, + rho_total_l * alpha2_l, + alpha1_l * rho1_l, + alpha2_l * rho2_l, + (1.0 - (alpha1_l + alpha2_l)) * rho3_l }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[10] = { + rho_total_r, + rho_total_r * vx_total_r, + rho_total_r * vy_total_r, + rho_total_r * vz_total_r, + E_total_r, + rho_total_r * alpha1_r, + rho_total_r * alpha2_r, + alpha1_r * rho1_r, + alpha2_r * rho2_r, + (1.0 - (alpha1_r + alpha2_r)) * rho3_r }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 10], waves_local[2 * 10]; @@ -550,13 +648,21 @@ test_euler_mixture_threecomponent_waves_2_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[10], amdq_local[10]; - gkyl_wv_eqn_qfluct(euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 10], &waves[i * 10]); + gkyl_wv_eqn_rotate_to_global( + euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 10], &waves[i * 10] + ); } double apdq[10], amdq[10]; @@ -572,7 +678,7 @@ test_euler_mixture_threecomponent_waves_2_ho() gkyl_wv_eqn_rotate_to_global(euler_mixture, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 10; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } @@ -581,11 +687,11 @@ test_euler_mixture_threecomponent_waves_2_ho() } TEST_LIST = { - { "euler_mixture_twocomponent_basic_ho", test_euler_mixture_twocomponent_basic_ho }, - { "euler_mixture_threecomponent_basic_ho", test_euler_mixture_threecomponent_basic_ho }, - { "euler_mixture_twocomponent_waves_ho", test_euler_mixture_twocomponent_waves_ho }, - { "euler_mixture_twocomponent_waves_2_ho", test_euler_mixture_twocomponent_waves_2_ho }, - { "euler_mixture_threecomponent_waves_ho", test_euler_mixture_threecomponent_waves_ho }, - { "euler_mixture_threecomponent_waves_2_ho", test_euler_mixture_threecomponent_waves_2_ho }, - { NULL, NULL }, + {"euler_mixture_twocomponent_basic_ho", test_euler_mixture_twocomponent_basic_ho}, + {"euler_mixture_threecomponent_basic_ho", test_euler_mixture_threecomponent_basic_ho}, + {"euler_mixture_twocomponent_waves_ho", test_euler_mixture_twocomponent_waves_ho}, + {"euler_mixture_twocomponent_waves_2_ho", test_euler_mixture_twocomponent_waves_2_ho}, + {"euler_mixture_threecomponent_waves_ho", test_euler_mixture_threecomponent_waves_ho}, + {"euler_mixture_threecomponent_waves_2_ho", test_euler_mixture_threecomponent_waves_2_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_euler_rgfm.c b/moments/unit/ctest_wv_euler_rgfm.c index da94f323b3..dc2582ded2 100644 --- a/moments/unit/ctest_wv_euler_rgfm.c +++ b/moments/unit/ctest_wv_euler_rgfm.c @@ -4,8 +4,7 @@ #include #include -void -test_euler_rgfm_twospecies_basic_ho() +void test_euler_rgfm_twospecies_basic_ho() { double gas_gamma1 = 1.4; double gas_gamma2 = 1.67; @@ -16,62 +15,61 @@ test_euler_rgfm_twospecies_basic_ho() struct gkyl_wv_eqn *euler_rgfm = gkyl_wv_euler_rgfm_new(2, gas_gamma_s, 0, false); - TEST_CHECK( euler_rgfm->num_equations == 9 ); - TEST_CHECK( euler_rgfm->num_waves == 2 ); + TEST_CHECK(euler_rgfm->num_equations == 9); + TEST_CHECK(euler_rgfm->num_waves == 2); - double phi1 = 0.75, rho1 = 1.0, rho2 = 2.0, vx_total = 0.1, vy_total = 0.2, vz_total = 0.3, p_total = 1.5; + double phi1 = 0.75, rho1 = 1.0, rho2 = 2.0, vx_total = 0.1, vy_total = 0.2, vz_total = 0.3, + p_total = 1.5; double rho_total = (phi1 * rho1) + ((1.0 - phi1) * rho2); - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); + double E1 = + (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); + double E2 = + (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); double E_total = (phi1 * E1) + ((1.0 - phi1) * E2); - double q[9] = { rho_total, rho_total * vx_total, rho_total * vy_total, rho_total * vz_total, E_total, rho_total * phi1, - phi1 * rho1, (1.0 - phi1) * rho2, 0.0 }; + double q[9] = {rho_total, rho_total * vx_total, rho_total * vy_total, rho_total * vz_total, + E_total, rho_total * phi1, phi1 * rho1, (1.0 - phi1) * rho2, + 0.0}; double prims[9]; gkyl_euler_rgfm_prim_vars(2, gas_gamma_s, q, prims); - TEST_CHECK( gkyl_compare(prims[0], rho_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[1], vx_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[2], vy_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[3], vz_total, 1e-16) ); + TEST_CHECK(gkyl_compare(prims[0], rho_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[1], vx_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[2], vy_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[3], vz_total, 1e-16)); // For now, we check only that the reconstructed interface pressure is of the correct order of magnitude. // This error tolerance can be reduced once we have introduced more physical boundary conditions into the system. - TEST_CHECK( gkyl_compare(prims[4], p_total, 1e-1) ); + TEST_CHECK(gkyl_compare(prims[4], p_total, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], phi1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[6], rho1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[7], rho2, 1e-16)); - TEST_CHECK( gkyl_compare(prims[5], phi1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[6], rho1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[7], rho2, 1e-16) ); - p_total = prims[4]; // Use the reconstructed interface pressure. double fluxes[3][9] = { - { rho_total * vx_total, (rho_total * (vx_total * vx_total)) + p_total, rho_total * (vx_total * vy_total), rho_total * (vx_total * vz_total), - (E_total * vx_total) + (vx_total * p_total), rho_total * vx_total * phi1, phi1 * (vx_total * rho1), (1.0 - phi1) * (vx_total * rho2), 0.0 }, - { rho_total * vy_total, rho_total * (vy_total * vx_total), (rho_total * (vy_total * vy_total)) + p_total, rho_total * (vy_total * vz_total), - (E_total * vy_total) + (vy_total * p_total), rho_total * vy_total * phi1, phi1 * (vy_total * rho1), (1.0 - phi1) * (vy_total * rho2), 0.0 }, - { rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), (rho_total * (vz_total * vz_total)) + p_total, - (E_total * vz_total) + (vz_total * p_total), rho_total * vz_total * phi1, phi1 * (vz_total * rho1), (1.0 - phi1) * (vz_total * rho2), 0.0 }, + {rho_total * vx_total, (rho_total * (vx_total * vx_total)) + p_total, + rho_total * (vx_total * vy_total), rho_total * (vx_total * vz_total), + (E_total * vx_total) + (vx_total * p_total), rho_total * vx_total * phi1, + phi1 * (vx_total * rho1), (1.0 - phi1) * (vx_total * rho2), 0.0}, + {rho_total * vy_total, rho_total * (vy_total * vx_total), + (rho_total * (vy_total * vy_total)) + p_total, rho_total * (vy_total * vz_total), + (E_total * vy_total) + (vy_total * p_total), rho_total * vy_total * phi1, + phi1 * (vy_total * rho1), (1.0 - phi1) * (vy_total * rho2), 0.0}, + {rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), + (rho_total * (vz_total * vz_total)) + p_total, (E_total * vz_total) + (vz_total * p_total), + rho_total * vz_total * phi1, phi1 * (vz_total * rho1), (1.0 - phi1) * (vz_total * rho2), 0.0} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[9], flux_local[9], flux[9]; for (int d = 0; d < 3; d++) { @@ -80,7 +78,7 @@ test_euler_rgfm_twospecies_basic_ho() euler_rgfm->rotate_to_global_func(euler_rgfm, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-15) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-15)); } } @@ -90,7 +88,7 @@ test_euler_rgfm_twospecies_basic_ho() gkyl_wv_eqn_rotate_to_global(euler_rgfm, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-16)); } double w1[9], q1[9]; @@ -98,7 +96,7 @@ test_euler_rgfm_twospecies_basic_ho() euler_rgfm->riem_to_cons(euler_rgfm, q_local, w1, q1); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-16)); } } @@ -106,8 +104,7 @@ test_euler_rgfm_twospecies_basic_ho() gkyl_free(gas_gamma_s); } -void -test_euler_rgfm_threespecies_basic_ho() +void test_euler_rgfm_threespecies_basic_ho() { double gas_gamma1 = 1.4; double gas_gamma2 = 1.67; @@ -120,68 +117,79 @@ test_euler_rgfm_threespecies_basic_ho() struct gkyl_wv_eqn *euler_rgfm = gkyl_wv_euler_rgfm_new(3, gas_gamma_s, 0, false); - TEST_CHECK( euler_rgfm->num_equations == 11 ); - TEST_CHECK( euler_rgfm->num_waves == 2 ); + TEST_CHECK(euler_rgfm->num_equations == 11); + TEST_CHECK(euler_rgfm->num_waves == 2); - double phi1 = 0.5, phi2 = 0.3, rho1 = 1.0, rho2 = 2.0, rho3 = 3.0, vx_total = 0.1, vy_total = 0.2, vz_total = 0.3, p_total = 1.5; + double phi1 = 0.5, phi2 = 0.3, rho1 = 1.0, rho2 = 2.0, rho3 = 3.0, vx_total = 0.1, vy_total = 0.2, + vz_total = 0.3, p_total = 1.5; double rho_total = (phi1 * rho1) + (phi2 * rho2) + ((1.0 - (phi1 + phi2)) * rho3); - double E1 = (p_total / (gas_gamma1 - 1.0)) + (0.5 * rho1 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); - double E2 = (p_total / (gas_gamma2 - 1.0)) + (0.5 * rho2 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); - double E3 = (p_total / (gas_gamma3 - 1.0)) + (0.5 * rho3 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); + double E1 = + (p_total / (gas_gamma1 - 1.0)) + + (0.5 * rho1 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); + double E2 = + (p_total / (gas_gamma2 - 1.0)) + + (0.5 * rho2 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); + double E3 = + (p_total / (gas_gamma3 - 1.0)) + + (0.5 * rho3 * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total))); double E_total = (phi1 * E1) + (phi2 * E2) + ((1.0 - (phi1 + phi2)) * rho3); - double q[11] = { rho_total, rho_total * vx_total, rho_total * vy_total, rho_total * vz_total, E_total, rho_total * phi1, - rho_total * phi2, phi1 * rho1, phi2 * rho2, (1.0 - (phi1 + phi2)) * rho3, 0.0 }; + double q[11] = { + rho_total, + rho_total * vx_total, + rho_total * vy_total, + rho_total * vz_total, + E_total, + rho_total * phi1, + rho_total * phi2, + phi1 * rho1, + phi2 * rho2, + (1.0 - (phi1 + phi2)) * rho3, + 0.0 + }; double prims[11]; gkyl_euler_rgfm_prim_vars(3, gas_gamma_s, q, prims); - TEST_CHECK( gkyl_compare(prims[0], rho_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[1], vx_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[2], vy_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[3], vz_total, 1e-16) ); + TEST_CHECK(gkyl_compare(prims[0], rho_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[1], vx_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[2], vy_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[3], vz_total, 1e-16)); // For now, we check only that the reconstructed rgfm pressure is of the correct order of magnitude. // This error tolerance can be reduced once we have introduced more physical rgfm rules into the system. - TEST_CHECK( gkyl_compare(prims[4], p_total, 1e-1) ); - - TEST_CHECK( gkyl_compare(prims[5], phi1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[6], phi2, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[7], rho1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[8], rho2, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[9], rho3, 1e-16) ); - + TEST_CHECK(gkyl_compare(prims[4], p_total, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], phi1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[6], phi2, 1e-16)); + TEST_CHECK(gkyl_compare(prims[7], rho1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[8], rho2, 1e-16)); + TEST_CHECK(gkyl_compare(prims[9], rho3, 1e-16)); + p_total = prims[4]; // Use the reconstructed rgfm pressure. double fluxes[3][11] = { - { rho_total * vx_total, (rho_total * (vx_total * vx_total)) + p_total, rho_total * (vx_total * vy_total), rho_total * (vx_total * vz_total), - (E_total * vx_total) + (vx_total * p_total), rho_total * vx_total * phi1, rho_total * vx_total * phi2, phi1 * (vx_total * rho1), - phi2 * (vx_total * rho2), (1.0 - (phi1 + phi2)) * (vx_total * rho3), 0.0 }, - { rho_total * vy_total, rho_total * (vy_total * vx_total), (rho_total * (vy_total * vy_total)) + p_total, rho_total * (vy_total * vz_total), - (E_total * vy_total) + (vy_total * p_total), rho_total * vy_total * phi1, rho_total * vy_total * phi2, phi1 * (vy_total * rho1), - phi2 * (vy_total * rho2), (1.0 - (phi1 + phi2)) * (vy_total * rho3), 0.0 }, - { rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), (rho_total * (vz_total * vz_total)) + p_total, - (E_total * vz_total) + (vz_total * p_total), rho_total * vz_total * phi1, rho_total * vz_total * phi2, phi1 * (vz_total * rho1), - phi2 * (vz_total * rho2), (1.0 - (phi1 + phi2)) * (vz_total * rho3), 0.0 }, + {rho_total * vx_total, (rho_total * (vx_total * vx_total)) + p_total, + rho_total * (vx_total * vy_total), rho_total * (vx_total * vz_total), + (E_total * vx_total) + (vx_total * p_total), rho_total * vx_total * phi1, + rho_total * vx_total * phi2, phi1 * (vx_total * rho1), phi2 * (vx_total * rho2), + (1.0 - (phi1 + phi2)) * (vx_total * rho3), 0.0}, + {rho_total * vy_total, rho_total * (vy_total * vx_total), + (rho_total * (vy_total * vy_total)) + p_total, rho_total * (vy_total * vz_total), + (E_total * vy_total) + (vy_total * p_total), rho_total * vy_total * phi1, + rho_total * vy_total * phi2, phi1 * (vy_total * rho1), phi2 * (vy_total * rho2), + (1.0 - (phi1 + phi2)) * (vy_total * rho3), 0.0}, + {rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), + (rho_total * (vz_total * vz_total)) + p_total, (E_total * vz_total) + (vz_total * p_total), + rho_total * vz_total * phi1, rho_total * vz_total * phi2, phi1 * (vz_total * rho1), + phi2 * (vz_total * rho2), (1.0 - (phi1 + phi2)) * (vz_total * rho3), 0.0} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[11], flux_local[11], flux[11]; for (int d = 0; d < 3; d++) { @@ -190,7 +198,7 @@ test_euler_rgfm_threespecies_basic_ho() euler_rgfm->rotate_to_global_func(euler_rgfm, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 11; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-16) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-16)); } } @@ -200,7 +208,7 @@ test_euler_rgfm_threespecies_basic_ho() gkyl_wv_eqn_rotate_to_global(euler_rgfm, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 11; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-16)); } double w1[11], q1[11]; @@ -208,7 +216,7 @@ test_euler_rgfm_threespecies_basic_ho() euler_rgfm->riem_to_cons(euler_rgfm, q_local, w1, q1); for (int i = 0; i < 11; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-16)); } } @@ -216,53 +224,60 @@ test_euler_rgfm_threespecies_basic_ho() gkyl_free(gas_gamma_s); } -void -test_euler_rgfm_twospecies_waves_ho() +void test_euler_rgfm_twospecies_waves_ho() { double gas_gamma1 = 1.4; double gas_gamma2 = 1.67; - + double *gas_gamma_s = gkyl_malloc(sizeof(double[2])); gas_gamma_s[0] = gas_gamma1; gas_gamma_s[1] = gas_gamma2; struct gkyl_wv_eqn *euler_rgfm = gkyl_wv_euler_rgfm_new(2, gas_gamma_s, 0, false); - - double phi1_l = 0.75, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; + + double phi1_l = 0.75, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, + vz_total_l = 0.3, p_total_l = 1.5; double rho_total_l = (phi1_l * rho1_l) + ((1.0 - phi1_l) * rho2_l); - double E1_l = (p_total_l / (gas_gamma1 - 1.0)) + (0.5 * rho1_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E2_l = (p_total_l / (gas_gamma2 - 1.0)) + (0.5 * rho2_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E1_l = + (p_total_l / (gas_gamma1 - 1.0)) + + (0.5 * rho1_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E2_l = + (p_total_l / (gas_gamma2 - 1.0)) + + (0.5 * rho2_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); double E_total_l = (phi1_l * E1_l) + ((1.0 - phi1_l) * E2_l); - double phi1_r = 0.25, rho1_r = 0.1, rho2_r = 0.2, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 0.15; + double phi1_r = 0.25, rho1_r = 0.1, rho2_r = 0.2, vx_total_r = 1.0, vy_total_r = 2.0, + vz_total_r = 3.0, p_total_r = 0.15; double rho_total_r = (phi1_r * rho1_r) + ((1.0 - phi1_r) * rho2_r); - double E1_r = (p_total_r / (gas_gamma1 - 1.0)) + (0.5 * rho1_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E2_r = (p_total_r / (gas_gamma2 - 1.0)) + (0.5 * rho2_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E1_r = + (p_total_r / (gas_gamma1 - 1.0)) + + (0.5 * rho1_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E2_r = + (p_total_r / (gas_gamma2 - 1.0)) + + (0.5 * rho2_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); double E_total_r = (phi1_r * E1_r) + ((1.0 - phi1_r) * E2_r); - double ql[9] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, E_total_l, rho_total_l * phi1_l, - phi1_l * rho1_l, (1.0 - phi1_l) * rho2_l, 0.0 }; - double qr[9] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, E_total_r, rho_total_r * phi1_r, - phi1_r * rho1_r, (1.0 - phi1_r) * rho2_r, 0.0 }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[9] = { + rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, + E_total_l, rho_total_l * phi1_l, phi1_l * rho1_l, (1.0 - phi1_l) * rho2_l, + 0.0 }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[9] = { + rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, + E_total_r, rho_total_r * phi1_r, phi1_r * rho1_r, (1.0 - phi1_r) * rho2_r, + 0.0 }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 9], waves_local[2 * 9]; @@ -275,13 +290,20 @@ test_euler_rgfm_twospecies_waves_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); double apdq_local[9], amdq_local[9]; - gkyl_wv_eqn_qfluct(euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(euler_rgfm, tau1[d], tau2[d], norm[d], &waves_local[i * 8], &waves[i * 8]); + gkyl_wv_eqn_rotate_to_global( + euler_rgfm, tau1[d], tau2[d], norm[d], &waves_local[i * 8], &waves[i * 8] + ); } double apdq[9], amdq[9]; @@ -297,7 +319,7 @@ test_euler_rgfm_twospecies_waves_ho() gkyl_wv_eqn_rotate_to_global(euler_rgfm, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); } } @@ -305,53 +327,60 @@ test_euler_rgfm_twospecies_waves_ho() gkyl_free(gas_gamma_s); } -void -test_euler_rgfm_twospecies_waves_2_ho() +void test_euler_rgfm_twospecies_waves_2_ho() { double gas_gamma1 = 1.2; double gas_gamma2 = 1.7; - + double *gas_gamma_s = gkyl_malloc(sizeof(double[2])); gas_gamma_s[0] = gas_gamma1; gas_gamma_s[1] = gas_gamma2; struct gkyl_wv_eqn *euler_rgfm = gkyl_wv_euler_rgfm_new(2, gas_gamma_s, 0, false); - - double phi1_l = 0.9, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; + + double phi1_l = 0.9, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, + vz_total_l = 0.3, p_total_l = 1.5; double rho_total_l = (phi1_l * rho1_l) + ((1.0 - phi1_l) * rho2_l); - double E1_l = (p_total_l / (gas_gamma1 - 1.0)) + (0.5 * rho1_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E2_l = (p_total_l / (gas_gamma2 - 1.0)) + (0.5 * rho2_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E1_l = + (p_total_l / (gas_gamma1 - 1.0)) + + (0.5 * rho1_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E2_l = + (p_total_l / (gas_gamma2 - 1.0)) + + (0.5 * rho2_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); double E_total_l = (phi1_l * E1_l) + ((1.0 - phi1_l) * E2_l); - double phi1_r = 0.1, rho1_r = 0.01, rho2_r = 0.02, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 15.0; + double phi1_r = 0.1, rho1_r = 0.01, rho2_r = 0.02, vx_total_r = 1.0, vy_total_r = 2.0, + vz_total_r = 3.0, p_total_r = 15.0; double rho_total_r = (phi1_r * rho1_r) + ((1.0 - phi1_r) * rho2_r); - double E1_r = (p_total_r / (gas_gamma1 - 1.0)) + (0.5 * rho1_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E2_r = (p_total_r / (gas_gamma2 - 1.0)) + (0.5 * rho2_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E1_r = + (p_total_r / (gas_gamma1 - 1.0)) + + (0.5 * rho1_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E2_r = + (p_total_r / (gas_gamma2 - 1.0)) + + (0.5 * rho2_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); double E_total_r = (phi1_r * E1_r) + ((1.0 - phi1_r) * E2_r); - double ql[9] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, E_total_l, rho_total_l * phi1_l, - phi1_l * rho1_l, (1.0 - phi1_l) * rho2_l, 0.0 }; - double qr[9] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, E_total_r, rho_total_r * phi1_r, - phi1_r * rho1_r, (1.0 - phi1_r) * rho2_r, 0.0 }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[9] = { + rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, + E_total_l, rho_total_l * phi1_l, phi1_l * rho1_l, (1.0 - phi1_l) * rho2_l, + 0.0 }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[9] = { + rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, + E_total_r, rho_total_r * phi1_r, phi1_r * rho1_r, (1.0 - phi1_r) * rho2_r, + 0.0 }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 9], waves_local[2 * 9]; @@ -364,13 +393,20 @@ test_euler_rgfm_twospecies_waves_2_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); double apdq_local[9], amdq_local[9]; - gkyl_wv_eqn_qfluct(euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(euler_rgfm, tau1[d], tau2[d], norm[d], &waves_local[i * 8], &waves[i * 8]); + gkyl_wv_eqn_rotate_to_global( + euler_rgfm, tau1[d], tau2[d], norm[d], &waves_local[i * 8], &waves[i * 8] + ); } double apdq[9], amdq[9]; @@ -386,7 +422,7 @@ test_euler_rgfm_twospecies_waves_2_ho() gkyl_wv_eqn_rotate_to_global(euler_rgfm, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } @@ -394,57 +430,86 @@ test_euler_rgfm_twospecies_waves_2_ho() gkyl_free(gas_gamma_s); } -void -test_euler_rgfm_threespecies_waves_ho() +void test_euler_rgfm_threespecies_waves_ho() { double gas_gamma1 = 1.4; double gas_gamma2 = 1.67; double gas_gamma3 = 1.9; - + double *gas_gamma_s = gkyl_malloc(sizeof(double[3])); gas_gamma_s[0] = gas_gamma1; gas_gamma_s[1] = gas_gamma2; gas_gamma_s[2] = gas_gamma3; struct gkyl_wv_eqn *euler_rgfm = gkyl_wv_euler_rgfm_new(3, gas_gamma_s, 0, false); - - double phi1_l = 0.5, phi2_l = 0.3, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; + + double phi1_l = 0.5, phi2_l = 0.3, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, + vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; double rho_total_l = (phi1_l * rho1_l) + (phi2_l * rho2_l) + ((1.0 - (phi1_l + phi2_l)) * rho3_l); - double E1_l = (p_total_l / (gas_gamma1 - 1.0)) + (0.5 * rho1_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E2_l = (p_total_l / (gas_gamma2 - 1.0)) + (0.5 * rho2_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E3_l = (p_total_l / (gas_gamma3 - 1.0)) + (0.5 * rho3_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E1_l = + (p_total_l / (gas_gamma1 - 1.0)) + + (0.5 * rho1_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E2_l = + (p_total_l / (gas_gamma2 - 1.0)) + + (0.5 * rho2_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E3_l = + (p_total_l / (gas_gamma3 - 1.0)) + + (0.5 * rho3_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); double E_total_l = (phi1_l * E1_l) + (phi2_l * E2_l) + ((1.0 - (phi1_l + phi2_l)) * E3_l); - double phi1_r = 0.4, phi2_r = 0.2, rho1_r = 0.1, rho2_r = 0.2, rho3_r = 0.3, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 0.15; + double phi1_r = 0.4, phi2_r = 0.2, rho1_r = 0.1, rho2_r = 0.2, rho3_r = 0.3, vx_total_r = 1.0, + vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 0.15; double rho_total_r = (phi1_r * rho1_r) + (phi2_r * rho2_r) + ((1.0 - (phi1_r + phi2_r)) * rho3_r); - double E1_r = (p_total_r / (gas_gamma1 - 1.0)) + (0.5 * rho1_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E2_r = (p_total_r / (gas_gamma2 - 1.0)) + (0.5 * rho2_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E3_r = (p_total_r / (gas_gamma3 - 1.0)) + (0.5 * rho3_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E1_r = + (p_total_r / (gas_gamma1 - 1.0)) + + (0.5 * rho1_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E2_r = + (p_total_r / (gas_gamma2 - 1.0)) + + (0.5 * rho2_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E3_r = + (p_total_r / (gas_gamma3 - 1.0)) + + (0.5 * rho3_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); double E_total_r = (phi1_r * E1_r) + (phi2_r * E2_r) + ((1.0 - (phi1_r + phi2_r)) * E3_r); - double ql[11] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, E_total_l, rho_total_l * phi1_l, - rho_total_l * phi2_l, phi1_l * rho1_l, phi2_l * rho2_l, (1.0 - (phi1_l + phi2_l)) * rho3_l, 0.0 }; - double qr[11] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, E_total_r, rho_total_r * phi1_r, - rho_total_r * phi2_r, phi1_r * rho1_r, phi2_r * rho2_r, (1.0 - (phi1_r + phi2_r)) * rho3_r, 0.0 }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[11] = { + rho_total_l, + rho_total_l * vx_total_l, + rho_total_l * vy_total_l, + rho_total_l * vz_total_l, + E_total_l, + rho_total_l * phi1_l, + rho_total_l * phi2_l, + phi1_l * rho1_l, + phi2_l * rho2_l, + (1.0 - (phi1_l + phi2_l)) * rho3_l, + 0.0 }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[11] = { + rho_total_r, + rho_total_r * vx_total_r, + rho_total_r * vy_total_r, + rho_total_r * vz_total_r, + E_total_r, + rho_total_r * phi1_r, + rho_total_r * phi2_r, + phi1_r * rho1_r, + phi2_r * rho2_r, + (1.0 - (phi1_r + phi2_r)) * rho3_r, + 0.0 }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 11], waves_local[2 * 11]; @@ -457,13 +522,20 @@ test_euler_rgfm_threespecies_waves_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); double apdq_local[11], amdq_local[11]; - gkyl_wv_eqn_qfluct(euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(euler_rgfm, tau1[d], tau2[d], norm[d], &waves_local[i * 10], &waves[i * 10]); + gkyl_wv_eqn_rotate_to_global( + euler_rgfm, tau1[d], tau2[d], norm[d], &waves_local[i * 10], &waves[i * 10] + ); } double apdq[11], amdq[11]; @@ -479,7 +551,7 @@ test_euler_rgfm_threespecies_waves_ho() gkyl_wv_eqn_rotate_to_global(euler_rgfm, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 11; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } @@ -487,57 +559,86 @@ test_euler_rgfm_threespecies_waves_ho() gkyl_free(gas_gamma_s); } -void -test_euler_rgfm_threespecies_waves_2_ho() +void test_euler_rgfm_threespecies_waves_2_ho() { double gas_gamma1 = 1.1; double gas_gamma2 = 1.5; double gas_gamma3 = 1.9; - + double *gas_gamma_s = gkyl_malloc(sizeof(double[3])); gas_gamma_s[0] = gas_gamma1; gas_gamma_s[1] = gas_gamma2; gas_gamma_s[2] = gas_gamma3; struct gkyl_wv_eqn *euler_rgfm = gkyl_wv_euler_rgfm_new(3, gas_gamma_s, 0, false); - - double phi1_l = 0.8, phi2_l = 0.1, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; + + double phi1_l = 0.8, phi2_l = 0.1, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, + vy_total_l = 0.2, vz_total_l = 0.3, p_total_l = 1.5; double rho_total_l = (phi1_l * rho1_l) + (phi2_l * rho2_l) + ((1.0 - (phi1_l + phi2_l)) * rho3_l); - double E1_l = (p_total_l / (gas_gamma1 - 1.0)) + (0.5 * rho1_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E2_l = (p_total_l / (gas_gamma2 - 1.0)) + (0.5 * rho2_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); - double E3_l = (p_total_l / (gas_gamma3 - 1.0)) + (0.5 * rho3_l * ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E1_l = + (p_total_l / (gas_gamma1 - 1.0)) + + (0.5 * rho1_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E2_l = + (p_total_l / (gas_gamma2 - 1.0)) + + (0.5 * rho2_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); + double E3_l = + (p_total_l / (gas_gamma3 - 1.0)) + + (0.5 * rho3_l * + ((vx_total_l * vx_total_l) + (vy_total_l * vy_total_l) + (vz_total_l * vz_total_l))); double E_total_l = (phi1_l * E1_l) + (phi2_l * E2_l) + ((1.0 - (phi1_l + phi2_l)) * E3_l); - double phi1_r = 0.75, phi2_r = 0.2, rho1_r = 0.01, rho2_r = 0.02, rho3_r = 0.03, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 15.0; + double phi1_r = 0.75, phi2_r = 0.2, rho1_r = 0.01, rho2_r = 0.02, rho3_r = 0.03, vx_total_r = 1.0, + vy_total_r = 2.0, vz_total_r = 3.0, p_total_r = 15.0; double rho_total_r = (phi1_r * rho1_r) + (phi2_r * rho2_r) + ((1.0 - (phi1_r + phi2_r)) * rho3_r); - double E1_r = (p_total_r / (gas_gamma1 - 1.0)) + (0.5 * rho1_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E2_r = (p_total_r / (gas_gamma2 - 1.0)) + (0.5 * rho2_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); - double E3_r = (p_total_r / (gas_gamma3 - 1.0)) + (0.5 * rho3_r * ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E1_r = + (p_total_r / (gas_gamma1 - 1.0)) + + (0.5 * rho1_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E2_r = + (p_total_r / (gas_gamma2 - 1.0)) + + (0.5 * rho2_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); + double E3_r = + (p_total_r / (gas_gamma3 - 1.0)) + + (0.5 * rho3_r * + ((vx_total_r * vx_total_r) + (vy_total_r * vy_total_r) + (vz_total_r * vz_total_r))); double E_total_r = (phi1_r * E1_r) + (phi2_r * E2_r) + ((1.0 - (phi1_r + phi2_r)) * E3_r); - double ql[11] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, E_total_l, rho_total_l * phi1_l, - rho_total_l * phi2_l, phi1_l * rho1_l, phi2_l * rho2_l, (1.0 - (phi1_l + phi2_l)) * rho3_l, 0.0 }; - double qr[11] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, E_total_r, rho_total_r * phi1_r, - rho_total_r * phi2_r, phi1_r * rho1_r, phi2_r * rho2_r, (1.0 - (phi1_r + phi2_r)) * rho3_r, 0.0 }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[11] = { + rho_total_l, + rho_total_l * vx_total_l, + rho_total_l * vy_total_l, + rho_total_l * vz_total_l, + E_total_l, + rho_total_l * phi1_l, + rho_total_l * phi2_l, + phi1_l * rho1_l, + phi2_l * rho2_l, + (1.0 - (phi1_l + phi2_l)) * rho3_l, + 0.0 }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[11] = { + rho_total_r, + rho_total_r * vx_total_r, + rho_total_r * vy_total_r, + rho_total_r * vz_total_r, + E_total_r, + rho_total_r * phi1_r, + rho_total_r * phi2_r, + phi1_r * rho1_r, + phi2_r * rho2_r, + (1.0 - (phi1_r + phi2_r)) * rho3_r, + 0.0 }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 11], waves_local[2 * 11]; @@ -550,13 +651,20 @@ test_euler_rgfm_threespecies_waves_2_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); double apdq_local[11], amdq_local[11]; - gkyl_wv_eqn_qfluct(euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + euler_rgfm, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(euler_rgfm, tau1[d], tau2[d], norm[d], &waves_local[i * 10], &waves[i * 10]); + gkyl_wv_eqn_rotate_to_global( + euler_rgfm, tau1[d], tau2[d], norm[d], &waves_local[i * 10], &waves[i * 10] + ); } double apdq[11], amdq[11]; @@ -572,7 +680,7 @@ test_euler_rgfm_threespecies_waves_2_ho() gkyl_wv_eqn_rotate_to_global(euler_rgfm, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 11; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } @@ -581,11 +689,11 @@ test_euler_rgfm_threespecies_waves_2_ho() } TEST_LIST = { - { "euler_rgfm_twospecies_basic_ho", test_euler_rgfm_twospecies_basic_ho }, - { "euler_rgfm_threespecies_basic_ho", test_euler_rgfm_threespecies_basic_ho }, - { "euler_rgfm_twospecies_waves_ho", test_euler_rgfm_twospecies_waves_ho }, - { "euler_rgfm_twospecies_waves_2_ho", test_euler_rgfm_twospecies_waves_2_ho }, - { "euler_rgfm_threespecies_waves_ho", test_euler_rgfm_threespecies_waves_ho }, - { "euler_rgfm_threespecies_waves_2_ho", test_euler_rgfm_threespecies_waves_2_ho }, - { NULL, NULL }, + {"euler_rgfm_twospecies_basic_ho", test_euler_rgfm_twospecies_basic_ho}, + {"euler_rgfm_threespecies_basic_ho", test_euler_rgfm_threespecies_basic_ho}, + {"euler_rgfm_twospecies_waves_ho", test_euler_rgfm_twospecies_waves_ho}, + {"euler_rgfm_twospecies_waves_2_ho", test_euler_rgfm_twospecies_waves_2_ho}, + {"euler_rgfm_threespecies_waves_ho", test_euler_rgfm_threespecies_waves_ho}, + {"euler_rgfm_threespecies_waves_2_ho", test_euler_rgfm_threespecies_waves_2_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_gr_euler.c b/moments/unit/ctest_wv_gr_euler.c index 2d0b18131b..62e3de563f 100644 --- a/moments/unit/ctest_wv_gr_euler.c +++ b/moments/unit/ctest_wv_gr_euler.c @@ -6,15 +6,15 @@ #include #include -void -test_gr_euler_basic_minkowski_ho() +void test_gr_euler_basic_minkowski_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler = + gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_euler->num_equations == 71 ); - TEST_CHECK( gr_euler->num_waves == 2 ); + TEST_CHECK(gr_euler->num_equations == 71); + TEST_CHECK(gr_euler->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -27,25 +27,25 @@ test_gr_euler_basic_minkowski_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -56,16 +56,28 @@ test_gr_euler_basic_minkowski_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -85,82 +97,124 @@ test_gr_euler_basic_minkowski_ho() q[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); q[5] = lapse; - q[6] = shift[0]; q[7] = shift[1]; q[8] = shift[2]; - - q[9] = spatial_metric[0][0]; q[10] = spatial_metric[0][1]; q[11] = spatial_metric[0][2]; - q[12] = spatial_metric[1][0]; q[13] = spatial_metric[1][1]; q[14] = spatial_metric[1][2]; - q[15] = spatial_metric[2][0]; q[16] = spatial_metric[2][1]; q[17] = spatial_metric[2][2]; - - q[18] = extrinsic_curvature[0][0]; q[19] = extrinsic_curvature[0][1]; q[20] = extrinsic_curvature[0][2]; - q[21] = extrinsic_curvature[1][0]; q[22] = extrinsic_curvature[1][1]; q[23] = extrinsic_curvature[1][2]; - q[24] = extrinsic_curvature[2][0]; q[25] = extrinsic_curvature[2][1]; q[26] = extrinsic_curvature[2][2]; + q[6] = shift[0]; + q[7] = shift[1]; + q[8] = shift[2]; + + q[9] = spatial_metric[0][0]; + q[10] = spatial_metric[0][1]; + q[11] = spatial_metric[0][2]; + q[12] = spatial_metric[1][0]; + q[13] = spatial_metric[1][1]; + q[14] = spatial_metric[1][2]; + q[15] = spatial_metric[2][0]; + q[16] = spatial_metric[2][1]; + q[17] = spatial_metric[2][2]; + + q[18] = extrinsic_curvature[0][0]; + q[19] = extrinsic_curvature[0][1]; + q[20] = extrinsic_curvature[0][2]; + q[21] = extrinsic_curvature[1][0]; + q[22] = extrinsic_curvature[1][1]; + q[23] = extrinsic_curvature[1][2]; + q[24] = extrinsic_curvature[2][0]; + q[25] = extrinsic_curvature[2][1]; + q[26] = extrinsic_curvature[2][2]; q[27] = 1.0; - q[28] = lapse_der[0]; q[29] = lapse_der[1]; q[30] = lapse_der[2]; - q[31] = shift_der[0][0]; q[32] = shift_der[0][1]; q[33] = shift_der[0][2]; - q[34] = shift_der[1][0]; q[35] = shift_der[1][1]; q[36] = shift_der[1][2]; - q[37] = shift_der[2][0]; q[38] = shift_der[2][1]; q[39] = shift_der[2][2]; - - q[40] = spatial_metric_der[0][0][0]; q[41] = spatial_metric_der[0][0][1]; q[42] = spatial_metric_der[0][0][2]; - q[43] = spatial_metric_der[0][1][0]; q[44] = spatial_metric_der[0][1][1]; q[45] = spatial_metric_der[0][1][2]; - q[46] = spatial_metric_der[0][2][0]; q[47] = spatial_metric_der[0][2][1]; q[48] = spatial_metric_der[0][2][2]; - - q[49] = spatial_metric_der[1][0][0]; q[50] = spatial_metric_der[1][0][1]; q[51] = spatial_metric_der[1][0][2]; - q[52] = spatial_metric_der[1][1][0]; q[53] = spatial_metric_der[1][1][1]; q[54] = spatial_metric_der[1][1][2]; - q[55] = spatial_metric_der[1][2][0]; q[56] = spatial_metric_der[1][2][1]; q[57] = spatial_metric_der[1][2][2]; - - q[58] = spatial_metric_der[2][0][0]; q[59] = spatial_metric_der[2][0][1]; q[60] = spatial_metric_der[2][0][2]; - q[61] = spatial_metric_der[2][1][0]; q[62] = spatial_metric_der[2][1][1]; q[63] = spatial_metric_der[2][1][2]; - q[64] = spatial_metric_der[2][2][0]; q[65] = spatial_metric_der[2][2][1]; q[66] = spatial_metric_der[2][2][2]; + q[28] = lapse_der[0]; + q[29] = lapse_der[1]; + q[30] = lapse_der[2]; + q[31] = shift_der[0][0]; + q[32] = shift_der[0][1]; + q[33] = shift_der[0][2]; + q[34] = shift_der[1][0]; + q[35] = shift_der[1][1]; + q[36] = shift_der[1][2]; + q[37] = shift_der[2][0]; + q[38] = shift_der[2][1]; + q[39] = shift_der[2][2]; + + q[40] = spatial_metric_der[0][0][0]; + q[41] = spatial_metric_der[0][0][1]; + q[42] = spatial_metric_der[0][0][2]; + q[43] = spatial_metric_der[0][1][0]; + q[44] = spatial_metric_der[0][1][1]; + q[45] = spatial_metric_der[0][1][2]; + q[46] = spatial_metric_der[0][2][0]; + q[47] = spatial_metric_der[0][2][1]; + q[48] = spatial_metric_der[0][2][2]; + + q[49] = spatial_metric_der[1][0][0]; + q[50] = spatial_metric_der[1][0][1]; + q[51] = spatial_metric_der[1][0][2]; + q[52] = spatial_metric_der[1][1][0]; + q[53] = spatial_metric_der[1][1][1]; + q[54] = spatial_metric_der[1][1][2]; + q[55] = spatial_metric_der[1][2][0]; + q[56] = spatial_metric_der[1][2][1]; + q[57] = spatial_metric_der[1][2][2]; + + q[58] = spatial_metric_der[2][0][0]; + q[59] = spatial_metric_der[2][0][1]; + q[60] = spatial_metric_der[2][0][2]; + q[61] = spatial_metric_der[2][1][0]; + q[62] = spatial_metric_der[2][1][1]; + q[63] = spatial_metric_der[2][1][2]; + q[64] = spatial_metric_der[2][2][0]; + q[65] = spatial_metric_der[2][2][1]; + q[66] = spatial_metric_der[2][2][2]; q[67] = 0.0; - q[68] = x; q[69] = y; q[70] = 0.0; + q[68] = x; + q[69] = y; + q[70] = 0.0; double prims[71]; gkyl_gr_euler_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-13) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-13)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-13)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-13)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-13)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-13)); double fluxes[3][5] = { - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])) }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0]))}, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1]))}, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2]))} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[71], flux_local[71], flux[71]; for (int d = 0; d < 3; d++) { @@ -169,7 +223,7 @@ test_gr_euler_basic_minkowski_ho() gr_euler->rotate_to_global_func(gr_euler, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 5; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-8) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-8)); } } @@ -179,7 +233,7 @@ test_gr_euler_basic_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_euler, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[71], q1[71]; @@ -187,7 +241,7 @@ test_gr_euler_basic_minkowski_ho() gr_euler->riem_to_cons(gr_euler, q_local, w1, q1); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } @@ -195,7 +249,7 @@ test_gr_euler_basic_minkowski_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -215,15 +269,15 @@ test_gr_euler_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_euler_basic_schwarzschild_ho() +void test_gr_euler_basic_schwarzschild_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler = + gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_euler->num_equations == 71 ); - TEST_CHECK( gr_euler->num_waves == 2 ); + TEST_CHECK(gr_euler->num_equations == 71); + TEST_CHECK(gr_euler->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -236,25 +290,25 @@ test_gr_euler_basic_schwarzschild_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -265,16 +319,28 @@ test_gr_euler_basic_schwarzschild_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -295,82 +361,126 @@ test_gr_euler_basic_schwarzschild_ho() q[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); q[5] = lapse; - q[6] = shift[0]; q[7] = shift[1]; q[8] = shift[2]; - - q[9] = spatial_metric[0][0]; q[10] = spatial_metric[0][1]; q[11] = spatial_metric[0][2]; - q[12] = spatial_metric[1][0]; q[13] = spatial_metric[1][1]; q[14] = spatial_metric[1][2]; - q[15] = spatial_metric[2][0]; q[16] = spatial_metric[2][1]; q[17] = spatial_metric[2][2]; - - q[18] = extrinsic_curvature[0][0]; q[19] = extrinsic_curvature[0][1]; q[20] = extrinsic_curvature[0][2]; - q[21] = extrinsic_curvature[1][0]; q[22] = extrinsic_curvature[1][1]; q[23] = extrinsic_curvature[1][2]; - q[24] = extrinsic_curvature[2][0]; q[25] = extrinsic_curvature[2][1]; q[26] = extrinsic_curvature[2][2]; + q[6] = shift[0]; + q[7] = shift[1]; + q[8] = shift[2]; + + q[9] = spatial_metric[0][0]; + q[10] = spatial_metric[0][1]; + q[11] = spatial_metric[0][2]; + q[12] = spatial_metric[1][0]; + q[13] = spatial_metric[1][1]; + q[14] = spatial_metric[1][2]; + q[15] = spatial_metric[2][0]; + q[16] = spatial_metric[2][1]; + q[17] = spatial_metric[2][2]; + + q[18] = extrinsic_curvature[0][0]; + q[19] = extrinsic_curvature[0][1]; + q[20] = extrinsic_curvature[0][2]; + q[21] = extrinsic_curvature[1][0]; + q[22] = extrinsic_curvature[1][1]; + q[23] = extrinsic_curvature[1][2]; + q[24] = extrinsic_curvature[2][0]; + q[25] = extrinsic_curvature[2][1]; + q[26] = extrinsic_curvature[2][2]; q[27] = 1.0; - q[28] = lapse_der[0]; q[29] = lapse_der[1]; q[30] = lapse_der[2]; - q[31] = shift_der[0][0]; q[32] = shift_der[0][1]; q[33] = shift_der[0][2]; - q[34] = shift_der[1][0]; q[35] = shift_der[1][1]; q[36] = shift_der[1][2]; - q[37] = shift_der[2][0]; q[38] = shift_der[2][1]; q[39] = shift_der[2][2]; - - q[40] = spatial_metric_der[0][0][0]; q[41] = spatial_metric_der[0][0][1]; q[42] = spatial_metric_der[0][0][2]; - q[43] = spatial_metric_der[0][1][0]; q[44] = spatial_metric_der[0][1][1]; q[45] = spatial_metric_der[0][1][2]; - q[46] = spatial_metric_der[0][2][0]; q[47] = spatial_metric_der[0][2][1]; q[48] = spatial_metric_der[0][2][2]; - - q[49] = spatial_metric_der[1][0][0]; q[50] = spatial_metric_der[1][0][1]; q[51] = spatial_metric_der[1][0][2]; - q[52] = spatial_metric_der[1][1][0]; q[53] = spatial_metric_der[1][1][1]; q[54] = spatial_metric_der[1][1][2]; - q[55] = spatial_metric_der[1][2][0]; q[56] = spatial_metric_der[1][2][1]; q[57] = spatial_metric_der[1][2][2]; - - q[58] = spatial_metric_der[2][0][0]; q[59] = spatial_metric_der[2][0][1]; q[60] = spatial_metric_der[2][0][2]; - q[61] = spatial_metric_der[2][1][0]; q[62] = spatial_metric_der[2][1][1]; q[63] = spatial_metric_der[2][1][2]; - q[64] = spatial_metric_der[2][2][0]; q[65] = spatial_metric_der[2][2][1]; q[66] = spatial_metric_der[2][2][2]; + q[28] = lapse_der[0]; + q[29] = lapse_der[1]; + q[30] = lapse_der[2]; + q[31] = shift_der[0][0]; + q[32] = shift_der[0][1]; + q[33] = shift_der[0][2]; + q[34] = shift_der[1][0]; + q[35] = shift_der[1][1]; + q[36] = shift_der[1][2]; + q[37] = shift_der[2][0]; + q[38] = shift_der[2][1]; + q[39] = shift_der[2][2]; + + q[40] = spatial_metric_der[0][0][0]; + q[41] = spatial_metric_der[0][0][1]; + q[42] = spatial_metric_der[0][0][2]; + q[43] = spatial_metric_der[0][1][0]; + q[44] = spatial_metric_der[0][1][1]; + q[45] = spatial_metric_der[0][1][2]; + q[46] = spatial_metric_der[0][2][0]; + q[47] = spatial_metric_der[0][2][1]; + q[48] = spatial_metric_der[0][2][2]; + + q[49] = spatial_metric_der[1][0][0]; + q[50] = spatial_metric_der[1][0][1]; + q[51] = spatial_metric_der[1][0][2]; + q[52] = spatial_metric_der[1][1][0]; + q[53] = spatial_metric_der[1][1][1]; + q[54] = spatial_metric_der[1][1][2]; + q[55] = spatial_metric_der[1][2][0]; + q[56] = spatial_metric_der[1][2][1]; + q[57] = spatial_metric_der[1][2][2]; + + q[58] = spatial_metric_der[2][0][0]; + q[59] = spatial_metric_der[2][0][1]; + q[60] = spatial_metric_der[2][0][2]; + q[61] = spatial_metric_der[2][1][0]; + q[62] = spatial_metric_der[2][1][1]; + q[63] = spatial_metric_der[2][1][2]; + q[64] = spatial_metric_der[2][2][0]; + q[65] = spatial_metric_der[2][2][1]; + q[66] = spatial_metric_der[2][2][2]; q[67] = 0.0; - q[68] = x; q[69] = y; q[70] = 0.0; + q[68] = x; + q[69] = y; + q[70] = 0.0; double prims[71]; gkyl_gr_euler_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); double fluxes[3][5] = { - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])) }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])) + }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])) + }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2]))} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[71], flux_local[71], flux[71]; for (int d = 0; d < 3; d++) { @@ -379,7 +489,7 @@ test_gr_euler_basic_schwarzschild_ho() gr_euler->rotate_to_global_func(gr_euler, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 5; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } @@ -389,7 +499,7 @@ test_gr_euler_basic_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_euler, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[71], q1[71]; @@ -397,7 +507,7 @@ test_gr_euler_basic_schwarzschild_ho() gr_euler->riem_to_cons(gr_euler, q_local, w1, q1); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -406,7 +516,7 @@ test_gr_euler_basic_schwarzschild_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -426,15 +536,15 @@ test_gr_euler_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_euler_basic_kerr_ho() +void test_gr_euler_basic_kerr_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler = + gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_euler->num_equations == 71 ); - TEST_CHECK( gr_euler->num_waves == 2 ); + TEST_CHECK(gr_euler->num_equations == 71); + TEST_CHECK(gr_euler->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -447,25 +557,25 @@ test_gr_euler_basic_kerr_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -476,16 +586,28 @@ test_gr_euler_basic_kerr_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -506,82 +628,126 @@ test_gr_euler_basic_kerr_ho() q[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); q[5] = lapse; - q[6] = shift[0]; q[7] = shift[1]; q[8] = shift[2]; - - q[9] = spatial_metric[0][0]; q[10] = spatial_metric[0][1]; q[11] = spatial_metric[0][2]; - q[12] = spatial_metric[1][0]; q[13] = spatial_metric[1][1]; q[14] = spatial_metric[1][2]; - q[15] = spatial_metric[2][0]; q[16] = spatial_metric[2][1]; q[17] = spatial_metric[2][2]; - - q[18] = extrinsic_curvature[0][0]; q[19] = extrinsic_curvature[0][1]; q[20] = extrinsic_curvature[0][2]; - q[21] = extrinsic_curvature[1][0]; q[22] = extrinsic_curvature[1][1]; q[23] = extrinsic_curvature[1][2]; - q[24] = extrinsic_curvature[2][0]; q[25] = extrinsic_curvature[2][1]; q[26] = extrinsic_curvature[2][2]; + q[6] = shift[0]; + q[7] = shift[1]; + q[8] = shift[2]; + + q[9] = spatial_metric[0][0]; + q[10] = spatial_metric[0][1]; + q[11] = spatial_metric[0][2]; + q[12] = spatial_metric[1][0]; + q[13] = spatial_metric[1][1]; + q[14] = spatial_metric[1][2]; + q[15] = spatial_metric[2][0]; + q[16] = spatial_metric[2][1]; + q[17] = spatial_metric[2][2]; + + q[18] = extrinsic_curvature[0][0]; + q[19] = extrinsic_curvature[0][1]; + q[20] = extrinsic_curvature[0][2]; + q[21] = extrinsic_curvature[1][0]; + q[22] = extrinsic_curvature[1][1]; + q[23] = extrinsic_curvature[1][2]; + q[24] = extrinsic_curvature[2][0]; + q[25] = extrinsic_curvature[2][1]; + q[26] = extrinsic_curvature[2][2]; q[27] = 1.0; - q[28] = lapse_der[0]; q[29] = lapse_der[1]; q[30] = lapse_der[2]; - q[31] = shift_der[0][0]; q[32] = shift_der[0][1]; q[33] = shift_der[0][2]; - q[34] = shift_der[1][0]; q[35] = shift_der[1][1]; q[36] = shift_der[1][2]; - q[37] = shift_der[2][0]; q[38] = shift_der[2][1]; q[39] = shift_der[2][2]; - - q[40] = spatial_metric_der[0][0][0]; q[41] = spatial_metric_der[0][0][1]; q[42] = spatial_metric_der[0][0][2]; - q[43] = spatial_metric_der[0][1][0]; q[44] = spatial_metric_der[0][1][1]; q[45] = spatial_metric_der[0][1][2]; - q[46] = spatial_metric_der[0][2][0]; q[47] = spatial_metric_der[0][2][1]; q[48] = spatial_metric_der[0][2][2]; - - q[49] = spatial_metric_der[1][0][0]; q[50] = spatial_metric_der[1][0][1]; q[51] = spatial_metric_der[1][0][2]; - q[52] = spatial_metric_der[1][1][0]; q[53] = spatial_metric_der[1][1][1]; q[54] = spatial_metric_der[1][1][2]; - q[55] = spatial_metric_der[1][2][0]; q[56] = spatial_metric_der[1][2][1]; q[57] = spatial_metric_der[1][2][2]; - - q[58] = spatial_metric_der[2][0][0]; q[59] = spatial_metric_der[2][0][1]; q[60] = spatial_metric_der[2][0][2]; - q[61] = spatial_metric_der[2][1][0]; q[62] = spatial_metric_der[2][1][1]; q[63] = spatial_metric_der[2][1][2]; - q[64] = spatial_metric_der[2][2][0]; q[65] = spatial_metric_der[2][2][1]; q[66] = spatial_metric_der[2][2][2]; + q[28] = lapse_der[0]; + q[29] = lapse_der[1]; + q[30] = lapse_der[2]; + q[31] = shift_der[0][0]; + q[32] = shift_der[0][1]; + q[33] = shift_der[0][2]; + q[34] = shift_der[1][0]; + q[35] = shift_der[1][1]; + q[36] = shift_der[1][2]; + q[37] = shift_der[2][0]; + q[38] = shift_der[2][1]; + q[39] = shift_der[2][2]; + + q[40] = spatial_metric_der[0][0][0]; + q[41] = spatial_metric_der[0][0][1]; + q[42] = spatial_metric_der[0][0][2]; + q[43] = spatial_metric_der[0][1][0]; + q[44] = spatial_metric_der[0][1][1]; + q[45] = spatial_metric_der[0][1][2]; + q[46] = spatial_metric_der[0][2][0]; + q[47] = spatial_metric_der[0][2][1]; + q[48] = spatial_metric_der[0][2][2]; + + q[49] = spatial_metric_der[1][0][0]; + q[50] = spatial_metric_der[1][0][1]; + q[51] = spatial_metric_der[1][0][2]; + q[52] = spatial_metric_der[1][1][0]; + q[53] = spatial_metric_der[1][1][1]; + q[54] = spatial_metric_der[1][1][2]; + q[55] = spatial_metric_der[1][2][0]; + q[56] = spatial_metric_der[1][2][1]; + q[57] = spatial_metric_der[1][2][2]; + + q[58] = spatial_metric_der[2][0][0]; + q[59] = spatial_metric_der[2][0][1]; + q[60] = spatial_metric_der[2][0][2]; + q[61] = spatial_metric_der[2][1][0]; + q[62] = spatial_metric_der[2][1][1]; + q[63] = spatial_metric_der[2][1][2]; + q[64] = spatial_metric_der[2][2][0]; + q[65] = spatial_metric_der[2][2][1]; + q[66] = spatial_metric_der[2][2][2]; q[67] = 0.0; - q[68] = x; q[69] = y; q[70] = 0.0; + q[68] = x; + q[69] = y; + q[70] = 0.0; double prims[71]; gkyl_gr_euler_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); double fluxes[3][5] = { - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])) }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])) + }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])) + }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2]))} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[71], flux_local[71], flux[71]; for (int d = 0; d < 3; d++) { @@ -590,17 +756,17 @@ test_gr_euler_basic_kerr_ho() gr_euler->rotate_to_global_func(gr_euler, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 5; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } - + double q_l[71], q_g[71]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(gr_euler, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(gr_euler, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[71], q1[71]; @@ -608,7 +774,7 @@ test_gr_euler_basic_kerr_ho() gr_euler->riem_to_cons(gr_euler, q_local, w1, q1); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -617,7 +783,7 @@ test_gr_euler_basic_kerr_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -637,12 +803,12 @@ test_gr_euler_basic_kerr_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_euler_waves_minkowski_ho() +void test_gr_euler_waves_minkowski_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler = + gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -657,10 +823,10 @@ test_gr_euler_waves_minkowski_ho() double *shift_l = gkyl_malloc(sizeof(double[3])); double *shift_r = gkyl_malloc(sizeof(double[3])); - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -670,18 +836,18 @@ test_gr_euler_waves_minkowski_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -698,20 +864,46 @@ test_gr_euler_waves_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -734,37 +926,79 @@ test_gr_euler_waves_minkowski_ho() ql[4] = sqrt(spatial_det_l) * ((rho_l * h_l * (W_l * W_l)) - p_l - (rho_l * W_l)); ql[5] = lapse_l; - ql[6] = shift_l[0]; ql[7] = shift_l[1]; ql[8] = shift_l[2]; - - ql[9] = spatial_metric_l[0][0]; ql[10] = spatial_metric_l[0][1]; ql[11] = spatial_metric_l[0][2]; - ql[12] = spatial_metric_l[1][0]; ql[13] = spatial_metric_l[1][1]; ql[14] = spatial_metric_l[1][2]; - ql[15] = spatial_metric_l[2][0]; ql[16] = spatial_metric_l[2][1]; ql[17] = spatial_metric_l[2][2]; - - ql[18] = extrinsic_curvature_l[0][0]; ql[19] = extrinsic_curvature_l[0][1]; ql[20] = extrinsic_curvature_l[0][2]; - ql[21] = extrinsic_curvature_l[1][0]; ql[22] = extrinsic_curvature_l[1][1]; ql[23] = extrinsic_curvature_l[1][2]; - ql[24] = extrinsic_curvature_l[2][0]; ql[25] = extrinsic_curvature_l[2][1]; ql[26] = extrinsic_curvature_l[2][2]; + ql[6] = shift_l[0]; + ql[7] = shift_l[1]; + ql[8] = shift_l[2]; + + ql[9] = spatial_metric_l[0][0]; + ql[10] = spatial_metric_l[0][1]; + ql[11] = spatial_metric_l[0][2]; + ql[12] = spatial_metric_l[1][0]; + ql[13] = spatial_metric_l[1][1]; + ql[14] = spatial_metric_l[1][2]; + ql[15] = spatial_metric_l[2][0]; + ql[16] = spatial_metric_l[2][1]; + ql[17] = spatial_metric_l[2][2]; + + ql[18] = extrinsic_curvature_l[0][0]; + ql[19] = extrinsic_curvature_l[0][1]; + ql[20] = extrinsic_curvature_l[0][2]; + ql[21] = extrinsic_curvature_l[1][0]; + ql[22] = extrinsic_curvature_l[1][1]; + ql[23] = extrinsic_curvature_l[1][2]; + ql[24] = extrinsic_curvature_l[2][0]; + ql[25] = extrinsic_curvature_l[2][1]; + ql[26] = extrinsic_curvature_l[2][2]; ql[27] = 1.0; - ql[28] = lapse_der_l[0]; ql[29] = lapse_der_l[1]; ql[30] = lapse_der_l[2]; - ql[31] = shift_der_l[0][0]; ql[32] = shift_der_l[0][1]; ql[33] = shift_der_l[0][2]; - ql[34] = shift_der_l[1][0]; ql[35] = shift_der_l[1][1]; ql[36] = shift_der_l[1][2]; - ql[37] = shift_der_l[2][0]; ql[38] = shift_der_l[2][1]; ql[39] = shift_der_l[2][2]; - - ql[40] = spatial_metric_der_l[0][0][0]; ql[41] = spatial_metric_der_l[0][0][1]; ql[42] = spatial_metric_der_l[0][0][2]; - ql[43] = spatial_metric_der_l[0][1][0]; ql[44] = spatial_metric_der_l[0][1][1]; ql[45] = spatial_metric_der_l[0][1][2]; - ql[46] = spatial_metric_der_l[0][2][0]; ql[47] = spatial_metric_der_l[0][2][1]; ql[48] = spatial_metric_der_l[0][2][2]; - - ql[49] = spatial_metric_der_l[1][0][0]; ql[50] = spatial_metric_der_l[1][0][1]; ql[51] = spatial_metric_der_l[1][0][2]; - ql[52] = spatial_metric_der_l[1][1][0]; ql[53] = spatial_metric_der_l[1][1][1]; ql[54] = spatial_metric_der_l[1][1][2]; - ql[55] = spatial_metric_der_l[1][2][0]; ql[56] = spatial_metric_der_l[1][2][1]; ql[57] = spatial_metric_der_l[1][2][2]; - - ql[58] = spatial_metric_der_l[2][0][0]; ql[59] = spatial_metric_der_l[2][0][1]; ql[60] = spatial_metric_der_l[2][0][2]; - ql[61] = spatial_metric_der_l[2][1][0]; ql[62] = spatial_metric_der_l[2][1][1]; ql[63] = spatial_metric_der_l[2][1][2]; - ql[64] = spatial_metric_der_l[2][2][0]; ql[65] = spatial_metric_der_l[2][2][1]; ql[66] = spatial_metric_der_l[2][2][2]; + ql[28] = lapse_der_l[0]; + ql[29] = lapse_der_l[1]; + ql[30] = lapse_der_l[2]; + ql[31] = shift_der_l[0][0]; + ql[32] = shift_der_l[0][1]; + ql[33] = shift_der_l[0][2]; + ql[34] = shift_der_l[1][0]; + ql[35] = shift_der_l[1][1]; + ql[36] = shift_der_l[1][2]; + ql[37] = shift_der_l[2][0]; + ql[38] = shift_der_l[2][1]; + ql[39] = shift_der_l[2][2]; + + ql[40] = spatial_metric_der_l[0][0][0]; + ql[41] = spatial_metric_der_l[0][0][1]; + ql[42] = spatial_metric_der_l[0][0][2]; + ql[43] = spatial_metric_der_l[0][1][0]; + ql[44] = spatial_metric_der_l[0][1][1]; + ql[45] = spatial_metric_der_l[0][1][2]; + ql[46] = spatial_metric_der_l[0][2][0]; + ql[47] = spatial_metric_der_l[0][2][1]; + ql[48] = spatial_metric_der_l[0][2][2]; + + ql[49] = spatial_metric_der_l[1][0][0]; + ql[50] = spatial_metric_der_l[1][0][1]; + ql[51] = spatial_metric_der_l[1][0][2]; + ql[52] = spatial_metric_der_l[1][1][0]; + ql[53] = spatial_metric_der_l[1][1][1]; + ql[54] = spatial_metric_der_l[1][1][2]; + ql[55] = spatial_metric_der_l[1][2][0]; + ql[56] = spatial_metric_der_l[1][2][1]; + ql[57] = spatial_metric_der_l[1][2][2]; + + ql[58] = spatial_metric_der_l[2][0][0]; + ql[59] = spatial_metric_der_l[2][0][1]; + ql[60] = spatial_metric_der_l[2][0][2]; + ql[61] = spatial_metric_der_l[2][1][0]; + ql[62] = spatial_metric_der_l[2][1][1]; + ql[63] = spatial_metric_der_l[2][1][2]; + ql[64] = spatial_metric_der_l[2][2][0]; + ql[65] = spatial_metric_der_l[2][2][1]; + ql[66] = spatial_metric_der_l[2][2][2]; ql[67] = 0.0; - ql[68] = x - 0.5; ql[69] = y; ql[70] = 0.0; + ql[68] = x - 0.5; + ql[69] = y; + ql[70] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_r * h_r * (W_r * W_r) * u_r; @@ -773,55 +1007,85 @@ test_gr_euler_waves_minkowski_ho() qr[4] = sqrt(spatial_det_r) * ((rho_r * h_r * (W_r * W_r)) - p_r * (rho_r * W_r)); qr[5] = lapse_r; - qr[6] = shift_r[0]; qr[7] = shift_r[1]; qr[8] = shift_r[2]; - - qr[9] = spatial_metric_r[0][0]; qr[10] = spatial_metric_r[0][1]; qr[11] = spatial_metric_r[0][2]; - qr[12] = spatial_metric_r[1][0]; qr[13] = spatial_metric_r[1][1]; qr[14] = spatial_metric_r[1][2]; - qr[15] = spatial_metric_r[2][0]; qr[16] = spatial_metric_r[2][1]; qr[17] = spatial_metric_r[2][2]; - - qr[18] = extrinsic_curvature_r[0][0]; qr[19] = extrinsic_curvature_r[0][1]; qr[20] = extrinsic_curvature_r[0][2]; - qr[21] = extrinsic_curvature_r[1][0]; qr[22] = extrinsic_curvature_r[1][1]; qr[23] = extrinsic_curvature_r[1][2]; - qr[24] = extrinsic_curvature_r[2][0]; qr[25] = extrinsic_curvature_r[2][1]; qr[26] = extrinsic_curvature_r[2][2]; + qr[6] = shift_r[0]; + qr[7] = shift_r[1]; + qr[8] = shift_r[2]; + + qr[9] = spatial_metric_r[0][0]; + qr[10] = spatial_metric_r[0][1]; + qr[11] = spatial_metric_r[0][2]; + qr[12] = spatial_metric_r[1][0]; + qr[13] = spatial_metric_r[1][1]; + qr[14] = spatial_metric_r[1][2]; + qr[15] = spatial_metric_r[2][0]; + qr[16] = spatial_metric_r[2][1]; + qr[17] = spatial_metric_r[2][2]; + + qr[18] = extrinsic_curvature_r[0][0]; + qr[19] = extrinsic_curvature_r[0][1]; + qr[20] = extrinsic_curvature_r[0][2]; + qr[21] = extrinsic_curvature_r[1][0]; + qr[22] = extrinsic_curvature_r[1][1]; + qr[23] = extrinsic_curvature_r[1][2]; + qr[24] = extrinsic_curvature_r[2][0]; + qr[25] = extrinsic_curvature_r[2][1]; + qr[26] = extrinsic_curvature_r[2][2]; qr[27] = 1.0; - qr[28] = lapse_der_r[0]; qr[29] = lapse_der_r[1]; qr[30] = lapse_der_r[2]; - qr[31] = shift_der_r[0][0]; qr[32] = shift_der_r[0][1]; qr[33] = shift_der_r[0][2]; - qr[34] = shift_der_r[1][0]; qr[35] = shift_der_r[1][1]; qr[36] = shift_der_r[1][2]; - qr[37] = shift_der_r[2][0]; qr[38] = shift_der_r[2][1]; qr[39] = shift_der_r[2][2]; - - qr[40] = spatial_metric_der_r[0][0][0]; qr[41] = spatial_metric_der_r[0][0][1]; qr[42] = spatial_metric_der_r[0][0][2]; - qr[43] = spatial_metric_der_r[0][1][0]; qr[44] = spatial_metric_der_r[0][1][1]; qr[45] = spatial_metric_der_r[0][1][2]; - qr[46] = spatial_metric_der_r[0][2][0]; qr[47] = spatial_metric_der_r[0][2][1]; qr[48] = spatial_metric_der_r[0][2][2]; - - qr[49] = spatial_metric_der_r[1][0][0]; qr[50] = spatial_metric_der_r[1][0][1]; qr[51] = spatial_metric_der_r[1][0][2]; - qr[52] = spatial_metric_der_r[1][1][0]; qr[53] = spatial_metric_der_r[1][1][1]; qr[54] = spatial_metric_der_r[1][1][2]; - qr[55] = spatial_metric_der_r[1][2][0]; qr[56] = spatial_metric_der_r[1][2][1]; qr[57] = spatial_metric_der_r[1][2][2]; - - qr[58] = spatial_metric_der_r[2][0][0]; qr[59] = spatial_metric_der_r[2][0][1]; qr[60] = spatial_metric_der_r[2][0][2]; - qr[61] = spatial_metric_der_r[2][1][0]; qr[62] = spatial_metric_der_r[2][1][1]; qr[63] = spatial_metric_der_r[2][1][2]; - qr[64] = spatial_metric_der_r[2][2][0]; qr[65] = spatial_metric_der_r[2][2][1]; qr[66] = spatial_metric_der_r[2][2][2]; + qr[28] = lapse_der_r[0]; + qr[29] = lapse_der_r[1]; + qr[30] = lapse_der_r[2]; + qr[31] = shift_der_r[0][0]; + qr[32] = shift_der_r[0][1]; + qr[33] = shift_der_r[0][2]; + qr[34] = shift_der_r[1][0]; + qr[35] = shift_der_r[1][1]; + qr[36] = shift_der_r[1][2]; + qr[37] = shift_der_r[2][0]; + qr[38] = shift_der_r[2][1]; + qr[39] = shift_der_r[2][2]; + + qr[40] = spatial_metric_der_r[0][0][0]; + qr[41] = spatial_metric_der_r[0][0][1]; + qr[42] = spatial_metric_der_r[0][0][2]; + qr[43] = spatial_metric_der_r[0][1][0]; + qr[44] = spatial_metric_der_r[0][1][1]; + qr[45] = spatial_metric_der_r[0][1][2]; + qr[46] = spatial_metric_der_r[0][2][0]; + qr[47] = spatial_metric_der_r[0][2][1]; + qr[48] = spatial_metric_der_r[0][2][2]; + + qr[49] = spatial_metric_der_r[1][0][0]; + qr[50] = spatial_metric_der_r[1][0][1]; + qr[51] = spatial_metric_der_r[1][0][2]; + qr[52] = spatial_metric_der_r[1][1][0]; + qr[53] = spatial_metric_der_r[1][1][1]; + qr[54] = spatial_metric_der_r[1][1][2]; + qr[55] = spatial_metric_der_r[1][2][0]; + qr[56] = spatial_metric_der_r[1][2][1]; + qr[57] = spatial_metric_der_r[1][2][2]; + + qr[58] = spatial_metric_der_r[2][0][0]; + qr[59] = spatial_metric_der_r[2][0][1]; + qr[60] = spatial_metric_der_r[2][0][2]; + qr[61] = spatial_metric_der_r[2][1][0]; + qr[62] = spatial_metric_der_r[2][1][1]; + qr[63] = spatial_metric_der_r[2][1][2]; + qr[64] = spatial_metric_der_r[2][2][0]; + qr[65] = spatial_metric_der_r[2][2][1]; + qr[66] = spatial_metric_der_r[2][2][2]; qr[67] = 0.0; - qr[68] = x + 0.5; qr[69] = y; qr[70] = 0.0; + qr[68] = x + 0.5; + qr[69] = y; + qr[70] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 71], waves_local[3 * 71]; @@ -835,13 +1099,20 @@ test_gr_euler_waves_minkowski_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); double apdq_local[71], amdq_local[71]; - gkyl_wv_eqn_qfluct(gr_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71]); + gkyl_wv_eqn_rotate_to_global( + gr_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71] + ); } double apdq[71], amdq[71]; @@ -857,7 +1128,7 @@ test_gr_euler_waves_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_euler, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } @@ -868,7 +1139,7 @@ test_gr_euler_waves_minkowski_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -897,12 +1168,12 @@ test_gr_euler_waves_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_euler_waves_schwarzschild_ho() +void test_gr_euler_waves_schwarzschild_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler = + gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -918,10 +1189,10 @@ test_gr_euler_waves_schwarzschild_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -931,18 +1202,18 @@ test_gr_euler_waves_schwarzschild_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -961,20 +1232,46 @@ test_gr_euler_waves_schwarzschild_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -998,37 +1295,79 @@ test_gr_euler_waves_schwarzschild_ho() ql[4] = sqrt(spatial_det_l) * ((rho_l * h_l * (W_l * W_l)) - p_l - (rho_l * W_l)); ql[5] = lapse_l; - ql[6] = shift_l[0]; ql[7] = shift_l[1]; ql[8] = shift_l[2]; - - ql[9] = spatial_metric_l[0][0]; ql[10] = spatial_metric_l[0][1]; ql[11] = spatial_metric_l[0][2]; - ql[12] = spatial_metric_l[1][0]; ql[13] = spatial_metric_l[1][1]; ql[14] = spatial_metric_l[1][2]; - ql[15] = spatial_metric_l[2][0]; ql[16] = spatial_metric_l[2][1]; ql[17] = spatial_metric_l[2][2]; - - ql[18] = extrinsic_curvature_l[0][0]; ql[19] = extrinsic_curvature_l[0][1]; ql[20] = extrinsic_curvature_l[0][2]; - ql[21] = extrinsic_curvature_l[1][0]; ql[22] = extrinsic_curvature_l[1][1]; ql[23] = extrinsic_curvature_l[1][2]; - ql[24] = extrinsic_curvature_l[2][0]; ql[25] = extrinsic_curvature_l[2][1]; ql[26] = extrinsic_curvature_l[2][2]; + ql[6] = shift_l[0]; + ql[7] = shift_l[1]; + ql[8] = shift_l[2]; + + ql[9] = spatial_metric_l[0][0]; + ql[10] = spatial_metric_l[0][1]; + ql[11] = spatial_metric_l[0][2]; + ql[12] = spatial_metric_l[1][0]; + ql[13] = spatial_metric_l[1][1]; + ql[14] = spatial_metric_l[1][2]; + ql[15] = spatial_metric_l[2][0]; + ql[16] = spatial_metric_l[2][1]; + ql[17] = spatial_metric_l[2][2]; + + ql[18] = extrinsic_curvature_l[0][0]; + ql[19] = extrinsic_curvature_l[0][1]; + ql[20] = extrinsic_curvature_l[0][2]; + ql[21] = extrinsic_curvature_l[1][0]; + ql[22] = extrinsic_curvature_l[1][1]; + ql[23] = extrinsic_curvature_l[1][2]; + ql[24] = extrinsic_curvature_l[2][0]; + ql[25] = extrinsic_curvature_l[2][1]; + ql[26] = extrinsic_curvature_l[2][2]; ql[27] = 1.0; - ql[28] = lapse_der_l[0]; ql[29] = lapse_der_l[1]; ql[30] = lapse_der_l[2]; - ql[31] = shift_der_l[0][0]; ql[32] = shift_der_l[0][1]; ql[33] = shift_der_l[0][2]; - ql[34] = shift_der_l[1][0]; ql[35] = shift_der_l[1][1]; ql[36] = shift_der_l[1][2]; - ql[37] = shift_der_l[2][0]; ql[38] = shift_der_l[2][1]; ql[39] = shift_der_l[2][2]; - - ql[40] = spatial_metric_der_l[0][0][0]; ql[41] = spatial_metric_der_l[0][0][1]; ql[42] = spatial_metric_der_l[0][0][2]; - ql[43] = spatial_metric_der_l[0][1][0]; ql[44] = spatial_metric_der_l[0][1][1]; ql[45] = spatial_metric_der_l[0][1][2]; - ql[46] = spatial_metric_der_l[0][2][0]; ql[47] = spatial_metric_der_l[0][2][1]; ql[48] = spatial_metric_der_l[0][2][2]; - - ql[49] = spatial_metric_der_l[1][0][0]; ql[50] = spatial_metric_der_l[1][0][1]; ql[51] = spatial_metric_der_l[1][0][2]; - ql[52] = spatial_metric_der_l[1][1][0]; ql[53] = spatial_metric_der_l[1][1][1]; ql[54] = spatial_metric_der_l[1][1][2]; - ql[55] = spatial_metric_der_l[1][2][0]; ql[56] = spatial_metric_der_l[1][2][1]; ql[57] = spatial_metric_der_l[1][2][2]; - - ql[58] = spatial_metric_der_l[2][0][0]; ql[59] = spatial_metric_der_l[2][0][1]; ql[60] = spatial_metric_der_l[2][0][2]; - ql[61] = spatial_metric_der_l[2][1][0]; ql[62] = spatial_metric_der_l[2][1][1]; ql[63] = spatial_metric_der_l[2][1][2]; - ql[64] = spatial_metric_der_l[2][2][0]; ql[65] = spatial_metric_der_l[2][2][1]; ql[66] = spatial_metric_der_l[2][2][2]; + ql[28] = lapse_der_l[0]; + ql[29] = lapse_der_l[1]; + ql[30] = lapse_der_l[2]; + ql[31] = shift_der_l[0][0]; + ql[32] = shift_der_l[0][1]; + ql[33] = shift_der_l[0][2]; + ql[34] = shift_der_l[1][0]; + ql[35] = shift_der_l[1][1]; + ql[36] = shift_der_l[1][2]; + ql[37] = shift_der_l[2][0]; + ql[38] = shift_der_l[2][1]; + ql[39] = shift_der_l[2][2]; + + ql[40] = spatial_metric_der_l[0][0][0]; + ql[41] = spatial_metric_der_l[0][0][1]; + ql[42] = spatial_metric_der_l[0][0][2]; + ql[43] = spatial_metric_der_l[0][1][0]; + ql[44] = spatial_metric_der_l[0][1][1]; + ql[45] = spatial_metric_der_l[0][1][2]; + ql[46] = spatial_metric_der_l[0][2][0]; + ql[47] = spatial_metric_der_l[0][2][1]; + ql[48] = spatial_metric_der_l[0][2][2]; + + ql[49] = spatial_metric_der_l[1][0][0]; + ql[50] = spatial_metric_der_l[1][0][1]; + ql[51] = spatial_metric_der_l[1][0][2]; + ql[52] = spatial_metric_der_l[1][1][0]; + ql[53] = spatial_metric_der_l[1][1][1]; + ql[54] = spatial_metric_der_l[1][1][2]; + ql[55] = spatial_metric_der_l[1][2][0]; + ql[56] = spatial_metric_der_l[1][2][1]; + ql[57] = spatial_metric_der_l[1][2][2]; + + ql[58] = spatial_metric_der_l[2][0][0]; + ql[59] = spatial_metric_der_l[2][0][1]; + ql[60] = spatial_metric_der_l[2][0][2]; + ql[61] = spatial_metric_der_l[2][1][0]; + ql[62] = spatial_metric_der_l[2][1][1]; + ql[63] = spatial_metric_der_l[2][1][2]; + ql[64] = spatial_metric_der_l[2][2][0]; + ql[65] = spatial_metric_der_l[2][2][1]; + ql[66] = spatial_metric_der_l[2][2][2]; ql[67] = 0.0; - ql[68] = x - 0.5; ql[69] = y; ql[70] = 0.0; + ql[68] = x - 0.5; + ql[69] = y; + ql[70] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_r * h_r * (W_r * W_r) * u_r; @@ -1037,55 +1376,85 @@ test_gr_euler_waves_schwarzschild_ho() qr[4] = sqrt(spatial_det_r) * ((rho_r * h_r * (W_r * W_r)) - p_r * (rho_r * W_r)); qr[5] = lapse_r; - qr[6] = shift_r[0]; qr[7] = shift_r[1]; qr[8] = shift_r[2]; - - qr[9] = spatial_metric_r[0][0]; qr[10] = spatial_metric_r[0][1]; qr[11] = spatial_metric_r[0][2]; - qr[12] = spatial_metric_r[1][0]; qr[13] = spatial_metric_r[1][1]; qr[14] = spatial_metric_r[1][2]; - qr[15] = spatial_metric_r[2][0]; qr[16] = spatial_metric_r[2][1]; qr[17] = spatial_metric_r[2][2]; - - qr[18] = extrinsic_curvature_r[0][0]; qr[19] = extrinsic_curvature_r[0][1]; qr[20] = extrinsic_curvature_r[0][2]; - qr[21] = extrinsic_curvature_r[1][0]; qr[22] = extrinsic_curvature_r[1][1]; qr[23] = extrinsic_curvature_r[1][2]; - qr[24] = extrinsic_curvature_r[2][0]; qr[25] = extrinsic_curvature_r[2][1]; qr[26] = extrinsic_curvature_r[2][2]; + qr[6] = shift_r[0]; + qr[7] = shift_r[1]; + qr[8] = shift_r[2]; + + qr[9] = spatial_metric_r[0][0]; + qr[10] = spatial_metric_r[0][1]; + qr[11] = spatial_metric_r[0][2]; + qr[12] = spatial_metric_r[1][0]; + qr[13] = spatial_metric_r[1][1]; + qr[14] = spatial_metric_r[1][2]; + qr[15] = spatial_metric_r[2][0]; + qr[16] = spatial_metric_r[2][1]; + qr[17] = spatial_metric_r[2][2]; + + qr[18] = extrinsic_curvature_r[0][0]; + qr[19] = extrinsic_curvature_r[0][1]; + qr[20] = extrinsic_curvature_r[0][2]; + qr[21] = extrinsic_curvature_r[1][0]; + qr[22] = extrinsic_curvature_r[1][1]; + qr[23] = extrinsic_curvature_r[1][2]; + qr[24] = extrinsic_curvature_r[2][0]; + qr[25] = extrinsic_curvature_r[2][1]; + qr[26] = extrinsic_curvature_r[2][2]; qr[27] = 1.0; - qr[28] = lapse_der_r[0]; qr[29] = lapse_der_r[1]; qr[30] = lapse_der_r[2]; - qr[31] = shift_der_r[0][0]; qr[32] = shift_der_r[0][1]; qr[33] = shift_der_r[0][2]; - qr[34] = shift_der_r[1][0]; qr[35] = shift_der_r[1][1]; qr[36] = shift_der_r[1][2]; - qr[37] = shift_der_r[2][0]; qr[38] = shift_der_r[2][1]; qr[39] = shift_der_r[2][2]; - - qr[40] = spatial_metric_der_r[0][0][0]; qr[41] = spatial_metric_der_r[0][0][1]; qr[42] = spatial_metric_der_r[0][0][2]; - qr[43] = spatial_metric_der_r[0][1][0]; qr[44] = spatial_metric_der_r[0][1][1]; qr[45] = spatial_metric_der_r[0][1][2]; - qr[46] = spatial_metric_der_r[0][2][0]; qr[47] = spatial_metric_der_r[0][2][1]; qr[48] = spatial_metric_der_r[0][2][2]; - - qr[49] = spatial_metric_der_r[1][0][0]; qr[50] = spatial_metric_der_r[1][0][1]; qr[51] = spatial_metric_der_r[1][0][2]; - qr[52] = spatial_metric_der_r[1][1][0]; qr[53] = spatial_metric_der_r[1][1][1]; qr[54] = spatial_metric_der_r[1][1][2]; - qr[55] = spatial_metric_der_r[1][2][0]; qr[56] = spatial_metric_der_r[1][2][1]; qr[57] = spatial_metric_der_r[1][2][2]; - - qr[58] = spatial_metric_der_r[2][0][0]; qr[59] = spatial_metric_der_r[2][0][1]; qr[60] = spatial_metric_der_r[2][0][2]; - qr[61] = spatial_metric_der_r[2][1][0]; qr[62] = spatial_metric_der_r[2][1][1]; qr[63] = spatial_metric_der_r[2][1][2]; - qr[64] = spatial_metric_der_r[2][2][0]; qr[65] = spatial_metric_der_r[2][2][1]; qr[66] = spatial_metric_der_r[2][2][2]; + qr[28] = lapse_der_r[0]; + qr[29] = lapse_der_r[1]; + qr[30] = lapse_der_r[2]; + qr[31] = shift_der_r[0][0]; + qr[32] = shift_der_r[0][1]; + qr[33] = shift_der_r[0][2]; + qr[34] = shift_der_r[1][0]; + qr[35] = shift_der_r[1][1]; + qr[36] = shift_der_r[1][2]; + qr[37] = shift_der_r[2][0]; + qr[38] = shift_der_r[2][1]; + qr[39] = shift_der_r[2][2]; + + qr[40] = spatial_metric_der_r[0][0][0]; + qr[41] = spatial_metric_der_r[0][0][1]; + qr[42] = spatial_metric_der_r[0][0][2]; + qr[43] = spatial_metric_der_r[0][1][0]; + qr[44] = spatial_metric_der_r[0][1][1]; + qr[45] = spatial_metric_der_r[0][1][2]; + qr[46] = spatial_metric_der_r[0][2][0]; + qr[47] = spatial_metric_der_r[0][2][1]; + qr[48] = spatial_metric_der_r[0][2][2]; + + qr[49] = spatial_metric_der_r[1][0][0]; + qr[50] = spatial_metric_der_r[1][0][1]; + qr[51] = spatial_metric_der_r[1][0][2]; + qr[52] = spatial_metric_der_r[1][1][0]; + qr[53] = spatial_metric_der_r[1][1][1]; + qr[54] = spatial_metric_der_r[1][1][2]; + qr[55] = spatial_metric_der_r[1][2][0]; + qr[56] = spatial_metric_der_r[1][2][1]; + qr[57] = spatial_metric_der_r[1][2][2]; + + qr[58] = spatial_metric_der_r[2][0][0]; + qr[59] = spatial_metric_der_r[2][0][1]; + qr[60] = spatial_metric_der_r[2][0][2]; + qr[61] = spatial_metric_der_r[2][1][0]; + qr[62] = spatial_metric_der_r[2][1][1]; + qr[63] = spatial_metric_der_r[2][1][2]; + qr[64] = spatial_metric_der_r[2][2][0]; + qr[65] = spatial_metric_der_r[2][2][1]; + qr[66] = spatial_metric_der_r[2][2][2]; qr[67] = 0.0; - qr[68] = x + 0.5; qr[69] = y; qr[70] = 0.0; + qr[68] = x + 0.5; + qr[69] = y; + qr[70] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 71], waves_local[3 * 71]; @@ -1099,13 +1468,21 @@ test_gr_euler_waves_schwarzschild_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[71], amdq_local[71]; - gkyl_wv_eqn_qfluct(gr_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71]); + gkyl_wv_eqn_rotate_to_global( + gr_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71] + ); } double apdq[71], amdq[71]; @@ -1121,7 +1498,7 @@ test_gr_euler_waves_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_euler, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1133,7 +1510,7 @@ test_gr_euler_waves_schwarzschild_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1162,12 +1539,12 @@ test_gr_euler_waves_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_euler_waves_kerr_ho() +void test_gr_euler_waves_kerr_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_euler = gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler = + gkyl_wv_gr_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1183,10 +1560,10 @@ test_gr_euler_waves_kerr_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1196,18 +1573,18 @@ test_gr_euler_waves_kerr_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1226,20 +1603,46 @@ test_gr_euler_waves_kerr_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1263,37 +1666,79 @@ test_gr_euler_waves_kerr_ho() ql[4] = sqrt(spatial_det_l) * ((rho_l * h_l * (W_l * W_l)) - p_l - (rho_l * W_l)); ql[5] = lapse_l; - ql[6] = shift_l[0]; ql[7] = shift_l[1]; ql[8] = shift_l[2]; - - ql[9] = spatial_metric_l[0][0]; ql[10] = spatial_metric_l[0][1]; ql[11] = spatial_metric_l[0][2]; - ql[12] = spatial_metric_l[1][0]; ql[13] = spatial_metric_l[1][1]; ql[14] = spatial_metric_l[1][2]; - ql[15] = spatial_metric_l[2][0]; ql[16] = spatial_metric_l[2][1]; ql[17] = spatial_metric_l[2][2]; - - ql[18] = extrinsic_curvature_l[0][0]; ql[19] = extrinsic_curvature_l[0][1]; ql[20] = extrinsic_curvature_l[0][2]; - ql[21] = extrinsic_curvature_l[1][0]; ql[22] = extrinsic_curvature_l[1][1]; ql[23] = extrinsic_curvature_l[1][2]; - ql[24] = extrinsic_curvature_l[2][0]; ql[25] = extrinsic_curvature_l[2][1]; ql[26] = extrinsic_curvature_l[2][2]; + ql[6] = shift_l[0]; + ql[7] = shift_l[1]; + ql[8] = shift_l[2]; + + ql[9] = spatial_metric_l[0][0]; + ql[10] = spatial_metric_l[0][1]; + ql[11] = spatial_metric_l[0][2]; + ql[12] = spatial_metric_l[1][0]; + ql[13] = spatial_metric_l[1][1]; + ql[14] = spatial_metric_l[1][2]; + ql[15] = spatial_metric_l[2][0]; + ql[16] = spatial_metric_l[2][1]; + ql[17] = spatial_metric_l[2][2]; + + ql[18] = extrinsic_curvature_l[0][0]; + ql[19] = extrinsic_curvature_l[0][1]; + ql[20] = extrinsic_curvature_l[0][2]; + ql[21] = extrinsic_curvature_l[1][0]; + ql[22] = extrinsic_curvature_l[1][1]; + ql[23] = extrinsic_curvature_l[1][2]; + ql[24] = extrinsic_curvature_l[2][0]; + ql[25] = extrinsic_curvature_l[2][1]; + ql[26] = extrinsic_curvature_l[2][2]; ql[27] = 1.0; - ql[28] = lapse_der_l[0]; ql[29] = lapse_der_l[1]; ql[30] = lapse_der_l[2]; - ql[31] = shift_der_l[0][0]; ql[32] = shift_der_l[0][1]; ql[33] = shift_der_l[0][2]; - ql[34] = shift_der_l[1][0]; ql[35] = shift_der_l[1][1]; ql[36] = shift_der_l[1][2]; - ql[37] = shift_der_l[2][0]; ql[38] = shift_der_l[2][1]; ql[39] = shift_der_l[2][2]; - - ql[40] = spatial_metric_der_l[0][0][0]; ql[41] = spatial_metric_der_l[0][0][1]; ql[42] = spatial_metric_der_l[0][0][2]; - ql[43] = spatial_metric_der_l[0][1][0]; ql[44] = spatial_metric_der_l[0][1][1]; ql[45] = spatial_metric_der_l[0][1][2]; - ql[46] = spatial_metric_der_l[0][2][0]; ql[47] = spatial_metric_der_l[0][2][1]; ql[48] = spatial_metric_der_l[0][2][2]; - - ql[49] = spatial_metric_der_l[1][0][0]; ql[50] = spatial_metric_der_l[1][0][1]; ql[51] = spatial_metric_der_l[1][0][2]; - ql[52] = spatial_metric_der_l[1][1][0]; ql[53] = spatial_metric_der_l[1][1][1]; ql[54] = spatial_metric_der_l[1][1][2]; - ql[55] = spatial_metric_der_l[1][2][0]; ql[56] = spatial_metric_der_l[1][2][1]; ql[57] = spatial_metric_der_l[1][2][2]; - - ql[58] = spatial_metric_der_l[2][0][0]; ql[59] = spatial_metric_der_l[2][0][1]; ql[60] = spatial_metric_der_l[2][0][2]; - ql[61] = spatial_metric_der_l[2][1][0]; ql[62] = spatial_metric_der_l[2][1][1]; ql[63] = spatial_metric_der_l[2][1][2]; - ql[64] = spatial_metric_der_l[2][2][0]; ql[65] = spatial_metric_der_l[2][2][1]; ql[66] = spatial_metric_der_l[2][2][2]; + ql[28] = lapse_der_l[0]; + ql[29] = lapse_der_l[1]; + ql[30] = lapse_der_l[2]; + ql[31] = shift_der_l[0][0]; + ql[32] = shift_der_l[0][1]; + ql[33] = shift_der_l[0][2]; + ql[34] = shift_der_l[1][0]; + ql[35] = shift_der_l[1][1]; + ql[36] = shift_der_l[1][2]; + ql[37] = shift_der_l[2][0]; + ql[38] = shift_der_l[2][1]; + ql[39] = shift_der_l[2][2]; + + ql[40] = spatial_metric_der_l[0][0][0]; + ql[41] = spatial_metric_der_l[0][0][1]; + ql[42] = spatial_metric_der_l[0][0][2]; + ql[43] = spatial_metric_der_l[0][1][0]; + ql[44] = spatial_metric_der_l[0][1][1]; + ql[45] = spatial_metric_der_l[0][1][2]; + ql[46] = spatial_metric_der_l[0][2][0]; + ql[47] = spatial_metric_der_l[0][2][1]; + ql[48] = spatial_metric_der_l[0][2][2]; + + ql[49] = spatial_metric_der_l[1][0][0]; + ql[50] = spatial_metric_der_l[1][0][1]; + ql[51] = spatial_metric_der_l[1][0][2]; + ql[52] = spatial_metric_der_l[1][1][0]; + ql[53] = spatial_metric_der_l[1][1][1]; + ql[54] = spatial_metric_der_l[1][1][2]; + ql[55] = spatial_metric_der_l[1][2][0]; + ql[56] = spatial_metric_der_l[1][2][1]; + ql[57] = spatial_metric_der_l[1][2][2]; + + ql[58] = spatial_metric_der_l[2][0][0]; + ql[59] = spatial_metric_der_l[2][0][1]; + ql[60] = spatial_metric_der_l[2][0][2]; + ql[61] = spatial_metric_der_l[2][1][0]; + ql[62] = spatial_metric_der_l[2][1][1]; + ql[63] = spatial_metric_der_l[2][1][2]; + ql[64] = spatial_metric_der_l[2][2][0]; + ql[65] = spatial_metric_der_l[2][2][1]; + ql[66] = spatial_metric_der_l[2][2][2]; ql[67] = 0.0; - ql[68] = x - 0.5; ql[69] = y; ql[70] = 0.0; + ql[68] = x - 0.5; + ql[69] = y; + ql[70] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_r * h_r * (W_r * W_r) * u_r; @@ -1302,55 +1747,85 @@ test_gr_euler_waves_kerr_ho() qr[4] = sqrt(spatial_det_r) * ((rho_r * h_r * (W_r * W_r)) - p_r * (rho_r * W_r)); qr[5] = lapse_r; - qr[6] = shift_r[0]; qr[7] = shift_r[1]; qr[8] = shift_r[2]; - - qr[9] = spatial_metric_r[0][0]; qr[10] = spatial_metric_r[0][1]; qr[11] = spatial_metric_r[0][2]; - qr[12] = spatial_metric_r[1][0]; qr[13] = spatial_metric_r[1][1]; qr[14] = spatial_metric_r[1][2]; - qr[15] = spatial_metric_r[2][0]; qr[16] = spatial_metric_r[2][1]; qr[17] = spatial_metric_r[2][2]; - - qr[18] = extrinsic_curvature_r[0][0]; qr[19] = extrinsic_curvature_r[0][1]; qr[20] = extrinsic_curvature_r[0][2]; - qr[21] = extrinsic_curvature_r[1][0]; qr[22] = extrinsic_curvature_r[1][1]; qr[23] = extrinsic_curvature_r[1][2]; - qr[24] = extrinsic_curvature_r[2][0]; qr[25] = extrinsic_curvature_r[2][1]; qr[26] = extrinsic_curvature_r[2][2]; + qr[6] = shift_r[0]; + qr[7] = shift_r[1]; + qr[8] = shift_r[2]; + + qr[9] = spatial_metric_r[0][0]; + qr[10] = spatial_metric_r[0][1]; + qr[11] = spatial_metric_r[0][2]; + qr[12] = spatial_metric_r[1][0]; + qr[13] = spatial_metric_r[1][1]; + qr[14] = spatial_metric_r[1][2]; + qr[15] = spatial_metric_r[2][0]; + qr[16] = spatial_metric_r[2][1]; + qr[17] = spatial_metric_r[2][2]; + + qr[18] = extrinsic_curvature_r[0][0]; + qr[19] = extrinsic_curvature_r[0][1]; + qr[20] = extrinsic_curvature_r[0][2]; + qr[21] = extrinsic_curvature_r[1][0]; + qr[22] = extrinsic_curvature_r[1][1]; + qr[23] = extrinsic_curvature_r[1][2]; + qr[24] = extrinsic_curvature_r[2][0]; + qr[25] = extrinsic_curvature_r[2][1]; + qr[26] = extrinsic_curvature_r[2][2]; qr[27] = 1.0; - qr[28] = lapse_der_r[0]; qr[29] = lapse_der_r[1]; qr[30] = lapse_der_r[2]; - qr[31] = shift_der_r[0][0]; qr[32] = shift_der_r[0][1]; qr[33] = shift_der_r[0][2]; - qr[34] = shift_der_r[1][0]; qr[35] = shift_der_r[1][1]; qr[36] = shift_der_r[1][2]; - qr[37] = shift_der_r[2][0]; qr[38] = shift_der_r[2][1]; qr[39] = shift_der_r[2][2]; - - qr[40] = spatial_metric_der_r[0][0][0]; qr[41] = spatial_metric_der_r[0][0][1]; qr[42] = spatial_metric_der_r[0][0][2]; - qr[43] = spatial_metric_der_r[0][1][0]; qr[44] = spatial_metric_der_r[0][1][1]; qr[45] = spatial_metric_der_r[0][1][2]; - qr[46] = spatial_metric_der_r[0][2][0]; qr[47] = spatial_metric_der_r[0][2][1]; qr[48] = spatial_metric_der_r[0][2][2]; - - qr[49] = spatial_metric_der_r[1][0][0]; qr[50] = spatial_metric_der_r[1][0][1]; qr[51] = spatial_metric_der_r[1][0][2]; - qr[52] = spatial_metric_der_r[1][1][0]; qr[53] = spatial_metric_der_r[1][1][1]; qr[54] = spatial_metric_der_r[1][1][2]; - qr[55] = spatial_metric_der_r[1][2][0]; qr[56] = spatial_metric_der_r[1][2][1]; qr[57] = spatial_metric_der_r[1][2][2]; - - qr[58] = spatial_metric_der_r[2][0][0]; qr[59] = spatial_metric_der_r[2][0][1]; qr[60] = spatial_metric_der_r[2][0][2]; - qr[61] = spatial_metric_der_r[2][1][0]; qr[62] = spatial_metric_der_r[2][1][1]; qr[63] = spatial_metric_der_r[2][1][2]; - qr[64] = spatial_metric_der_r[2][2][0]; qr[65] = spatial_metric_der_r[2][2][1]; qr[66] = spatial_metric_der_r[2][2][2]; + qr[28] = lapse_der_r[0]; + qr[29] = lapse_der_r[1]; + qr[30] = lapse_der_r[2]; + qr[31] = shift_der_r[0][0]; + qr[32] = shift_der_r[0][1]; + qr[33] = shift_der_r[0][2]; + qr[34] = shift_der_r[1][0]; + qr[35] = shift_der_r[1][1]; + qr[36] = shift_der_r[1][2]; + qr[37] = shift_der_r[2][0]; + qr[38] = shift_der_r[2][1]; + qr[39] = shift_der_r[2][2]; + + qr[40] = spatial_metric_der_r[0][0][0]; + qr[41] = spatial_metric_der_r[0][0][1]; + qr[42] = spatial_metric_der_r[0][0][2]; + qr[43] = spatial_metric_der_r[0][1][0]; + qr[44] = spatial_metric_der_r[0][1][1]; + qr[45] = spatial_metric_der_r[0][1][2]; + qr[46] = spatial_metric_der_r[0][2][0]; + qr[47] = spatial_metric_der_r[0][2][1]; + qr[48] = spatial_metric_der_r[0][2][2]; + + qr[49] = spatial_metric_der_r[1][0][0]; + qr[50] = spatial_metric_der_r[1][0][1]; + qr[51] = spatial_metric_der_r[1][0][2]; + qr[52] = spatial_metric_der_r[1][1][0]; + qr[53] = spatial_metric_der_r[1][1][1]; + qr[54] = spatial_metric_der_r[1][1][2]; + qr[55] = spatial_metric_der_r[1][2][0]; + qr[56] = spatial_metric_der_r[1][2][1]; + qr[57] = spatial_metric_der_r[1][2][2]; + + qr[58] = spatial_metric_der_r[2][0][0]; + qr[59] = spatial_metric_der_r[2][0][1]; + qr[60] = spatial_metric_der_r[2][0][2]; + qr[61] = spatial_metric_der_r[2][1][0]; + qr[62] = spatial_metric_der_r[2][1][1]; + qr[63] = spatial_metric_der_r[2][1][2]; + qr[64] = spatial_metric_der_r[2][2][0]; + qr[65] = spatial_metric_der_r[2][2][1]; + qr[66] = spatial_metric_der_r[2][2][2]; qr[67] = 0.0; - qr[68] = x + 0.5; qr[69] = y; qr[70] = 0.0; + qr[68] = x + 0.5; + qr[69] = y; + qr[70] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 71], waves_local[3 * 71]; @@ -1364,13 +1839,21 @@ test_gr_euler_waves_kerr_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[71], amdq_local[71]; - gkyl_wv_eqn_qfluct(gr_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71]); + gkyl_wv_eqn_rotate_to_global( + gr_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71] + ); } double apdq[71], amdq[71]; @@ -1386,7 +1869,7 @@ test_gr_euler_waves_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_euler, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1398,7 +1881,7 @@ test_gr_euler_waves_kerr_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1428,11 +1911,11 @@ test_gr_euler_waves_kerr_ho() } TEST_LIST = { - { "gr_euler_basic_minkowski_ho", test_gr_euler_basic_minkowski_ho }, - { "gr_euler_basic_schwarzschild_ho", test_gr_euler_basic_schwarzschild_ho }, - { "gr_euler_basic_kerr_ho", test_gr_euler_basic_kerr_ho }, - { "gr_euler_waves_minkowski_ho", test_gr_euler_waves_minkowski_ho }, - { "gr_euler_waves_schwarzschild_ho", test_gr_euler_waves_schwarzschild_ho }, - { "gr_euler_waves_kerr_ho", test_gr_euler_waves_kerr_ho }, - { NULL, NULL }, + {"gr_euler_basic_minkowski_ho", test_gr_euler_basic_minkowski_ho}, + {"gr_euler_basic_schwarzschild_ho", test_gr_euler_basic_schwarzschild_ho}, + {"gr_euler_basic_kerr_ho", test_gr_euler_basic_kerr_ho}, + {"gr_euler_waves_minkowski_ho", test_gr_euler_waves_minkowski_ho}, + {"gr_euler_waves_schwarzschild_ho", test_gr_euler_waves_schwarzschild_ho}, + {"gr_euler_waves_kerr_ho", test_gr_euler_waves_kerr_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_gr_euler_tetrad.c b/moments/unit/ctest_wv_gr_euler_tetrad.c index 041b75a984..e3e9415eb1 100644 --- a/moments/unit/ctest_wv_gr_euler_tetrad.c +++ b/moments/unit/ctest_wv_gr_euler_tetrad.c @@ -6,15 +6,15 @@ #include #include -void -test_gr_euler_tetrad_basic_minkowski_ho() +void test_gr_euler_tetrad_basic_minkowski_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler_tetrad = + gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_euler_tetrad->num_equations == 71 ); - TEST_CHECK( gr_euler_tetrad->num_waves == 2 ); + TEST_CHECK(gr_euler_tetrad->num_equations == 71); + TEST_CHECK(gr_euler_tetrad->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -27,25 +27,25 @@ test_gr_euler_tetrad_basic_minkowski_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region = false; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -56,16 +56,28 @@ test_gr_euler_tetrad_basic_minkowski_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -85,92 +97,138 @@ test_gr_euler_tetrad_basic_minkowski_ho() q[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); q[5] = lapse; - q[6] = shift[0]; q[7] = shift[1]; q[8] = shift[2]; - - q[9] = spatial_metric[0][0]; q[10] = spatial_metric[0][1]; q[11] = spatial_metric[0][2]; - q[12] = spatial_metric[1][0]; q[13] = spatial_metric[1][1]; q[14] = spatial_metric[1][2]; - q[15] = spatial_metric[2][0]; q[16] = spatial_metric[2][1]; q[17] = spatial_metric[2][2]; - - q[18] = extrinsic_curvature[0][0]; q[19] = extrinsic_curvature[0][1]; q[20] = extrinsic_curvature[0][2]; - q[21] = extrinsic_curvature[1][0]; q[22] = extrinsic_curvature[1][1]; q[23] = extrinsic_curvature[1][2]; - q[24] = extrinsic_curvature[2][0]; q[25] = extrinsic_curvature[2][1]; q[26] = extrinsic_curvature[2][2]; + q[6] = shift[0]; + q[7] = shift[1]; + q[8] = shift[2]; + + q[9] = spatial_metric[0][0]; + q[10] = spatial_metric[0][1]; + q[11] = spatial_metric[0][2]; + q[12] = spatial_metric[1][0]; + q[13] = spatial_metric[1][1]; + q[14] = spatial_metric[1][2]; + q[15] = spatial_metric[2][0]; + q[16] = spatial_metric[2][1]; + q[17] = spatial_metric[2][2]; + + q[18] = extrinsic_curvature[0][0]; + q[19] = extrinsic_curvature[0][1]; + q[20] = extrinsic_curvature[0][2]; + q[21] = extrinsic_curvature[1][0]; + q[22] = extrinsic_curvature[1][1]; + q[23] = extrinsic_curvature[1][2]; + q[24] = extrinsic_curvature[2][0]; + q[25] = extrinsic_curvature[2][1]; + q[26] = extrinsic_curvature[2][2]; q[27] = 1.0; - q[28] = lapse_der[0]; q[29] = lapse_der[1]; q[30] = lapse_der[2]; - q[31] = shift_der[0][0]; q[32] = shift_der[0][1]; q[33] = shift_der[0][2]; - q[34] = shift_der[1][0]; q[35] = shift_der[1][1]; q[36] = shift_der[1][2]; - q[37] = shift_der[2][0]; q[38] = shift_der[2][1]; q[39] = shift_der[2][2]; - - q[40] = spatial_metric_der[0][0][0]; q[41] = spatial_metric_der[0][0][1]; q[42] = spatial_metric_der[0][0][2]; - q[43] = spatial_metric_der[0][1][0]; q[44] = spatial_metric_der[0][1][1]; q[45] = spatial_metric_der[0][1][2]; - q[46] = spatial_metric_der[0][2][0]; q[47] = spatial_metric_der[0][2][1]; q[48] = spatial_metric_der[0][2][2]; - - q[49] = spatial_metric_der[1][0][0]; q[50] = spatial_metric_der[1][0][1]; q[51] = spatial_metric_der[1][0][2]; - q[52] = spatial_metric_der[1][1][0]; q[53] = spatial_metric_der[1][1][1]; q[54] = spatial_metric_der[1][1][2]; - q[55] = spatial_metric_der[1][2][0]; q[56] = spatial_metric_der[1][2][1]; q[57] = spatial_metric_der[1][2][2]; - - q[58] = spatial_metric_der[2][0][0]; q[59] = spatial_metric_der[2][0][1]; q[60] = spatial_metric_der[2][0][2]; - q[61] = spatial_metric_der[2][1][0]; q[62] = spatial_metric_der[2][1][1]; q[63] = spatial_metric_der[2][1][2]; - q[64] = spatial_metric_der[2][2][0]; q[65] = spatial_metric_der[2][2][1]; q[66] = spatial_metric_der[2][2][2]; + q[28] = lapse_der[0]; + q[29] = lapse_der[1]; + q[30] = lapse_der[2]; + q[31] = shift_der[0][0]; + q[32] = shift_der[0][1]; + q[33] = shift_der[0][2]; + q[34] = shift_der[1][0]; + q[35] = shift_der[1][1]; + q[36] = shift_der[1][2]; + q[37] = shift_der[2][0]; + q[38] = shift_der[2][1]; + q[39] = shift_der[2][2]; + + q[40] = spatial_metric_der[0][0][0]; + q[41] = spatial_metric_der[0][0][1]; + q[42] = spatial_metric_der[0][0][2]; + q[43] = spatial_metric_der[0][1][0]; + q[44] = spatial_metric_der[0][1][1]; + q[45] = spatial_metric_der[0][1][2]; + q[46] = spatial_metric_der[0][2][0]; + q[47] = spatial_metric_der[0][2][1]; + q[48] = spatial_metric_der[0][2][2]; + + q[49] = spatial_metric_der[1][0][0]; + q[50] = spatial_metric_der[1][0][1]; + q[51] = spatial_metric_der[1][0][2]; + q[52] = spatial_metric_der[1][1][0]; + q[53] = spatial_metric_der[1][1][1]; + q[54] = spatial_metric_der[1][1][2]; + q[55] = spatial_metric_der[1][2][0]; + q[56] = spatial_metric_der[1][2][1]; + q[57] = spatial_metric_der[1][2][2]; + + q[58] = spatial_metric_der[2][0][0]; + q[59] = spatial_metric_der[2][0][1]; + q[60] = spatial_metric_der[2][0][2]; + q[61] = spatial_metric_der[2][1][0]; + q[62] = spatial_metric_der[2][1][1]; + q[63] = spatial_metric_der[2][1][2]; + q[64] = spatial_metric_der[2][2][0]; + q[65] = spatial_metric_der[2][2][1]; + q[66] = spatial_metric_der[2][2][2]; q[67] = 0.0; - q[68] = x; q[69] = y; q[70] = 0.0; + q[68] = x; + q[69] = y; + q[70] = 0.0; double prims[71] = {0}; gkyl_gr_euler_tetrad_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-13) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-13)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-13)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-13)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-13)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-13)); double fluxes[3][5] = { - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])) }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0]))}, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1]))}, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2]))} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[71] = {0}, flux_local_sr[71] = {0}, flux_local_gr[71] = {0}, flux[71] = {0}; for (int d = 0; d < 3; d++) { - gr_euler_tetrad->rotate_to_local_func(gr_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local); + gr_euler_tetrad->rotate_to_local_func( + gr_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_gr_euler_tetrad_flux(gas_gamma, q_local, flux_local_sr); gkyl_gr_euler_tetrad_flux_correction(gas_gamma, q_local, flux_local_sr, flux_local_gr); - gr_euler_tetrad->rotate_to_global_func(gr_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gr_euler_tetrad->rotate_to_global_func( + gr_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 5; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-8) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-8)); } } @@ -180,7 +238,7 @@ test_gr_euler_tetrad_basic_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_euler_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[71] = {0}, q1[71] = {0}; @@ -188,7 +246,7 @@ test_gr_euler_tetrad_basic_minkowski_ho() gr_euler_tetrad->riem_to_cons(gr_euler_tetrad, q_local, w1, q1); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } @@ -196,7 +254,7 @@ test_gr_euler_tetrad_basic_minkowski_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -216,15 +274,15 @@ test_gr_euler_tetrad_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_euler_tetrad_basic_schwarzschild_ho() +void test_gr_euler_tetrad_basic_schwarzschild_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler_tetrad = + gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_euler_tetrad->num_equations == 71 ); - TEST_CHECK( gr_euler_tetrad->num_waves == 2 ); + TEST_CHECK(gr_euler_tetrad->num_equations == 71); + TEST_CHECK(gr_euler_tetrad->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -237,25 +295,25 @@ test_gr_euler_tetrad_basic_schwarzschild_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region = false; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -266,16 +324,28 @@ test_gr_euler_tetrad_basic_schwarzschild_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -296,92 +366,140 @@ test_gr_euler_tetrad_basic_schwarzschild_ho() q[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); q[5] = lapse; - q[6] = shift[0]; q[7] = shift[1]; q[8] = shift[2]; - - q[9] = spatial_metric[0][0]; q[10] = spatial_metric[0][1]; q[11] = spatial_metric[0][2]; - q[12] = spatial_metric[1][0]; q[13] = spatial_metric[1][1]; q[14] = spatial_metric[1][2]; - q[15] = spatial_metric[2][0]; q[16] = spatial_metric[2][1]; q[17] = spatial_metric[2][2]; - - q[18] = extrinsic_curvature[0][0]; q[19] = extrinsic_curvature[0][1]; q[20] = extrinsic_curvature[0][2]; - q[21] = extrinsic_curvature[1][0]; q[22] = extrinsic_curvature[1][1]; q[23] = extrinsic_curvature[1][2]; - q[24] = extrinsic_curvature[2][0]; q[25] = extrinsic_curvature[2][1]; q[26] = extrinsic_curvature[2][2]; + q[6] = shift[0]; + q[7] = shift[1]; + q[8] = shift[2]; + + q[9] = spatial_metric[0][0]; + q[10] = spatial_metric[0][1]; + q[11] = spatial_metric[0][2]; + q[12] = spatial_metric[1][0]; + q[13] = spatial_metric[1][1]; + q[14] = spatial_metric[1][2]; + q[15] = spatial_metric[2][0]; + q[16] = spatial_metric[2][1]; + q[17] = spatial_metric[2][2]; + + q[18] = extrinsic_curvature[0][0]; + q[19] = extrinsic_curvature[0][1]; + q[20] = extrinsic_curvature[0][2]; + q[21] = extrinsic_curvature[1][0]; + q[22] = extrinsic_curvature[1][1]; + q[23] = extrinsic_curvature[1][2]; + q[24] = extrinsic_curvature[2][0]; + q[25] = extrinsic_curvature[2][1]; + q[26] = extrinsic_curvature[2][2]; q[27] = 1.0; - q[28] = lapse_der[0]; q[29] = lapse_der[1]; q[30] = lapse_der[2]; - q[31] = shift_der[0][0]; q[32] = shift_der[0][1]; q[33] = shift_der[0][2]; - q[34] = shift_der[1][0]; q[35] = shift_der[1][1]; q[36] = shift_der[1][2]; - q[37] = shift_der[2][0]; q[38] = shift_der[2][1]; q[39] = shift_der[2][2]; - - q[40] = spatial_metric_der[0][0][0]; q[41] = spatial_metric_der[0][0][1]; q[42] = spatial_metric_der[0][0][2]; - q[43] = spatial_metric_der[0][1][0]; q[44] = spatial_metric_der[0][1][1]; q[45] = spatial_metric_der[0][1][2]; - q[46] = spatial_metric_der[0][2][0]; q[47] = spatial_metric_der[0][2][1]; q[48] = spatial_metric_der[0][2][2]; - - q[49] = spatial_metric_der[1][0][0]; q[50] = spatial_metric_der[1][0][1]; q[51] = spatial_metric_der[1][0][2]; - q[52] = spatial_metric_der[1][1][0]; q[53] = spatial_metric_der[1][1][1]; q[54] = spatial_metric_der[1][1][2]; - q[55] = spatial_metric_der[1][2][0]; q[56] = spatial_metric_der[1][2][1]; q[57] = spatial_metric_der[1][2][2]; - - q[58] = spatial_metric_der[2][0][0]; q[59] = spatial_metric_der[2][0][1]; q[60] = spatial_metric_der[2][0][2]; - q[61] = spatial_metric_der[2][1][0]; q[62] = spatial_metric_der[2][1][1]; q[63] = spatial_metric_der[2][1][2]; - q[64] = spatial_metric_der[2][2][0]; q[65] = spatial_metric_der[2][2][1]; q[66] = spatial_metric_der[2][2][2]; + q[28] = lapse_der[0]; + q[29] = lapse_der[1]; + q[30] = lapse_der[2]; + q[31] = shift_der[0][0]; + q[32] = shift_der[0][1]; + q[33] = shift_der[0][2]; + q[34] = shift_der[1][0]; + q[35] = shift_der[1][1]; + q[36] = shift_der[1][2]; + q[37] = shift_der[2][0]; + q[38] = shift_der[2][1]; + q[39] = shift_der[2][2]; + + q[40] = spatial_metric_der[0][0][0]; + q[41] = spatial_metric_der[0][0][1]; + q[42] = spatial_metric_der[0][0][2]; + q[43] = spatial_metric_der[0][1][0]; + q[44] = spatial_metric_der[0][1][1]; + q[45] = spatial_metric_der[0][1][2]; + q[46] = spatial_metric_der[0][2][0]; + q[47] = spatial_metric_der[0][2][1]; + q[48] = spatial_metric_der[0][2][2]; + + q[49] = spatial_metric_der[1][0][0]; + q[50] = spatial_metric_der[1][0][1]; + q[51] = spatial_metric_der[1][0][2]; + q[52] = spatial_metric_der[1][1][0]; + q[53] = spatial_metric_der[1][1][1]; + q[54] = spatial_metric_der[1][1][2]; + q[55] = spatial_metric_der[1][2][0]; + q[56] = spatial_metric_der[1][2][1]; + q[57] = spatial_metric_der[1][2][2]; + + q[58] = spatial_metric_der[2][0][0]; + q[59] = spatial_metric_der[2][0][1]; + q[60] = spatial_metric_der[2][0][2]; + q[61] = spatial_metric_der[2][1][0]; + q[62] = spatial_metric_der[2][1][1]; + q[63] = spatial_metric_der[2][1][2]; + q[64] = spatial_metric_der[2][2][0]; + q[65] = spatial_metric_der[2][2][1]; + q[66] = spatial_metric_der[2][2][2]; q[67] = 0.0; - q[68] = x; q[69] = y; q[70] = 0.0; + q[68] = x; + q[69] = y; + q[70] = 0.0; double prims[71] = {0}; gkyl_gr_euler_tetrad_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); double fluxes[3][5] = { - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])) }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])) + }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])) + }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2]))} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[71] = {0}, flux_local_sr[71] = {0}, flux_local_gr[71] = {0}, flux[71] = {0}; for (int d = 0; d < 3; d++) { - gr_euler_tetrad->rotate_to_local_func(gr_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local); + gr_euler_tetrad->rotate_to_local_func( + gr_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_gr_euler_tetrad_flux(gas_gamma, q_local, flux_local_sr); gkyl_gr_euler_tetrad_flux_correction(gas_gamma, q_local, flux_local_sr, flux_local_gr); - gr_euler_tetrad->rotate_to_global_func(gr_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gr_euler_tetrad->rotate_to_global_func( + gr_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 5; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } @@ -391,7 +509,7 @@ test_gr_euler_tetrad_basic_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_euler_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[71] = {0}, q1[71] = {0}; @@ -399,7 +517,7 @@ test_gr_euler_tetrad_basic_schwarzschild_ho() gr_euler_tetrad->riem_to_cons(gr_euler_tetrad, q_local, w1, q1); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -408,7 +526,7 @@ test_gr_euler_tetrad_basic_schwarzschild_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -428,15 +546,15 @@ test_gr_euler_tetrad_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_euler_tetrad_basic_kerr_ho() +void test_gr_euler_tetrad_basic_kerr_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler_tetrad = + gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_euler_tetrad->num_equations == 71 ); - TEST_CHECK( gr_euler_tetrad->num_waves == 2 ); + TEST_CHECK(gr_euler_tetrad->num_equations == 71); + TEST_CHECK(gr_euler_tetrad->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -449,25 +567,25 @@ test_gr_euler_tetrad_basic_kerr_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region = false; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -478,16 +596,28 @@ test_gr_euler_tetrad_basic_kerr_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -508,92 +638,140 @@ test_gr_euler_tetrad_basic_kerr_ho() q[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); q[5] = lapse; - q[6] = shift[0]; q[7] = shift[1]; q[8] = shift[2]; - - q[9] = spatial_metric[0][0]; q[10] = spatial_metric[0][1]; q[11] = spatial_metric[0][2]; - q[12] = spatial_metric[1][0]; q[13] = spatial_metric[1][1]; q[14] = spatial_metric[1][2]; - q[15] = spatial_metric[2][0]; q[16] = spatial_metric[2][1]; q[17] = spatial_metric[2][2]; - - q[18] = extrinsic_curvature[0][0]; q[19] = extrinsic_curvature[0][1]; q[20] = extrinsic_curvature[0][2]; - q[21] = extrinsic_curvature[1][0]; q[22] = extrinsic_curvature[1][1]; q[23] = extrinsic_curvature[1][2]; - q[24] = extrinsic_curvature[2][0]; q[25] = extrinsic_curvature[2][1]; q[26] = extrinsic_curvature[2][2]; + q[6] = shift[0]; + q[7] = shift[1]; + q[8] = shift[2]; + + q[9] = spatial_metric[0][0]; + q[10] = spatial_metric[0][1]; + q[11] = spatial_metric[0][2]; + q[12] = spatial_metric[1][0]; + q[13] = spatial_metric[1][1]; + q[14] = spatial_metric[1][2]; + q[15] = spatial_metric[2][0]; + q[16] = spatial_metric[2][1]; + q[17] = spatial_metric[2][2]; + + q[18] = extrinsic_curvature[0][0]; + q[19] = extrinsic_curvature[0][1]; + q[20] = extrinsic_curvature[0][2]; + q[21] = extrinsic_curvature[1][0]; + q[22] = extrinsic_curvature[1][1]; + q[23] = extrinsic_curvature[1][2]; + q[24] = extrinsic_curvature[2][0]; + q[25] = extrinsic_curvature[2][1]; + q[26] = extrinsic_curvature[2][2]; q[27] = 1.0; - q[28] = lapse_der[0]; q[29] = lapse_der[1]; q[30] = lapse_der[2]; - q[31] = shift_der[0][0]; q[32] = shift_der[0][1]; q[33] = shift_der[0][2]; - q[34] = shift_der[1][0]; q[35] = shift_der[1][1]; q[36] = shift_der[1][2]; - q[37] = shift_der[2][0]; q[38] = shift_der[2][1]; q[39] = shift_der[2][2]; - - q[40] = spatial_metric_der[0][0][0]; q[41] = spatial_metric_der[0][0][1]; q[42] = spatial_metric_der[0][0][2]; - q[43] = spatial_metric_der[0][1][0]; q[44] = spatial_metric_der[0][1][1]; q[45] = spatial_metric_der[0][1][2]; - q[46] = spatial_metric_der[0][2][0]; q[47] = spatial_metric_der[0][2][1]; q[48] = spatial_metric_der[0][2][2]; - - q[49] = spatial_metric_der[1][0][0]; q[50] = spatial_metric_der[1][0][1]; q[51] = spatial_metric_der[1][0][2]; - q[52] = spatial_metric_der[1][1][0]; q[53] = spatial_metric_der[1][1][1]; q[54] = spatial_metric_der[1][1][2]; - q[55] = spatial_metric_der[1][2][0]; q[56] = spatial_metric_der[1][2][1]; q[57] = spatial_metric_der[1][2][2]; - - q[58] = spatial_metric_der[2][0][0]; q[59] = spatial_metric_der[2][0][1]; q[60] = spatial_metric_der[2][0][2]; - q[61] = spatial_metric_der[2][1][0]; q[62] = spatial_metric_der[2][1][1]; q[63] = spatial_metric_der[2][1][2]; - q[64] = spatial_metric_der[2][2][0]; q[65] = spatial_metric_der[2][2][1]; q[66] = spatial_metric_der[2][2][2]; + q[28] = lapse_der[0]; + q[29] = lapse_der[1]; + q[30] = lapse_der[2]; + q[31] = shift_der[0][0]; + q[32] = shift_der[0][1]; + q[33] = shift_der[0][2]; + q[34] = shift_der[1][0]; + q[35] = shift_der[1][1]; + q[36] = shift_der[1][2]; + q[37] = shift_der[2][0]; + q[38] = shift_der[2][1]; + q[39] = shift_der[2][2]; + + q[40] = spatial_metric_der[0][0][0]; + q[41] = spatial_metric_der[0][0][1]; + q[42] = spatial_metric_der[0][0][2]; + q[43] = spatial_metric_der[0][1][0]; + q[44] = spatial_metric_der[0][1][1]; + q[45] = spatial_metric_der[0][1][2]; + q[46] = spatial_metric_der[0][2][0]; + q[47] = spatial_metric_der[0][2][1]; + q[48] = spatial_metric_der[0][2][2]; + + q[49] = spatial_metric_der[1][0][0]; + q[50] = spatial_metric_der[1][0][1]; + q[51] = spatial_metric_der[1][0][2]; + q[52] = spatial_metric_der[1][1][0]; + q[53] = spatial_metric_der[1][1][1]; + q[54] = spatial_metric_der[1][1][2]; + q[55] = spatial_metric_der[1][2][0]; + q[56] = spatial_metric_der[1][2][1]; + q[57] = spatial_metric_der[1][2][2]; + + q[58] = spatial_metric_der[2][0][0]; + q[59] = spatial_metric_der[2][0][1]; + q[60] = spatial_metric_der[2][0][2]; + q[61] = spatial_metric_der[2][1][0]; + q[62] = spatial_metric_der[2][1][1]; + q[63] = spatial_metric_der[2][1][2]; + q[64] = spatial_metric_der[2][2][0]; + q[65] = spatial_metric_der[2][2][1]; + q[66] = spatial_metric_der[2][2][2]; q[67] = 0.0; - q[68] = x; q[69] = y; q[70] = 0.0; + q[68] = x; + q[69] = y; + q[70] = 0.0; double prims[71] = {0}; gkyl_gr_euler_tetrad_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); double fluxes[3][5] = { - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])) }, - { (lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])) }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])) + }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])) + }, + {(lapse * sqrt(spatial_det)) * (rho * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho * h * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2]))} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[71] = {0}, flux_local_sr[71] = {0}, flux_local_gr[71] = {0}, flux[71] = {0}; for (int d = 0; d < 3; d++) { - gr_euler_tetrad->rotate_to_local_func(gr_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local); + gr_euler_tetrad->rotate_to_local_func( + gr_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_gr_euler_tetrad_flux(gas_gamma, q_local, flux_local_sr); gkyl_gr_euler_tetrad_flux_correction(gas_gamma, q_local, flux_local_sr, flux_local_gr); - gr_euler_tetrad->rotate_to_global_func(gr_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gr_euler_tetrad->rotate_to_global_func( + gr_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 5; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } @@ -603,7 +781,7 @@ test_gr_euler_tetrad_basic_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_euler_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[71] = {0}, q1[71] = {0}; @@ -611,7 +789,7 @@ test_gr_euler_tetrad_basic_kerr_ho() gr_euler_tetrad->riem_to_cons(gr_euler_tetrad, q_local, w1, q1); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -620,7 +798,7 @@ test_gr_euler_tetrad_basic_kerr_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -640,12 +818,12 @@ test_gr_euler_tetrad_basic_kerr_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_euler_tetrad_waves_minkowski_ho() +void test_gr_euler_tetrad_waves_minkowski_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler_tetrad = + gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -660,10 +838,10 @@ test_gr_euler_tetrad_waves_minkowski_ho() double *shift_l = gkyl_malloc(sizeof(double[3])); double *shift_r = gkyl_malloc(sizeof(double[3])); - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -673,18 +851,18 @@ test_gr_euler_tetrad_waves_minkowski_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -701,20 +879,46 @@ test_gr_euler_tetrad_waves_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -737,37 +941,79 @@ test_gr_euler_tetrad_waves_minkowski_ho() ql[4] = sqrt(spatial_det_l) * ((rho_l * h_l * (W_l * W_l)) - p_l - (rho_l * W_l)); ql[5] = lapse_l; - ql[6] = shift_l[0]; ql[7] = shift_l[1]; ql[8] = shift_l[2]; - - ql[9] = spatial_metric_l[0][0]; ql[10] = spatial_metric_l[0][1]; ql[11] = spatial_metric_l[0][2]; - ql[12] = spatial_metric_l[1][0]; ql[13] = spatial_metric_l[1][1]; ql[14] = spatial_metric_l[1][2]; - ql[15] = spatial_metric_l[2][0]; ql[16] = spatial_metric_l[2][1]; ql[17] = spatial_metric_l[2][2]; - - ql[18] = extrinsic_curvature_l[0][0]; ql[19] = extrinsic_curvature_l[0][1]; ql[20] = extrinsic_curvature_l[0][2]; - ql[21] = extrinsic_curvature_l[1][0]; ql[22] = extrinsic_curvature_l[1][1]; ql[23] = extrinsic_curvature_l[1][2]; - ql[24] = extrinsic_curvature_l[2][0]; ql[25] = extrinsic_curvature_l[2][1]; ql[26] = extrinsic_curvature_l[2][2]; + ql[6] = shift_l[0]; + ql[7] = shift_l[1]; + ql[8] = shift_l[2]; + + ql[9] = spatial_metric_l[0][0]; + ql[10] = spatial_metric_l[0][1]; + ql[11] = spatial_metric_l[0][2]; + ql[12] = spatial_metric_l[1][0]; + ql[13] = spatial_metric_l[1][1]; + ql[14] = spatial_metric_l[1][2]; + ql[15] = spatial_metric_l[2][0]; + ql[16] = spatial_metric_l[2][1]; + ql[17] = spatial_metric_l[2][2]; + + ql[18] = extrinsic_curvature_l[0][0]; + ql[19] = extrinsic_curvature_l[0][1]; + ql[20] = extrinsic_curvature_l[0][2]; + ql[21] = extrinsic_curvature_l[1][0]; + ql[22] = extrinsic_curvature_l[1][1]; + ql[23] = extrinsic_curvature_l[1][2]; + ql[24] = extrinsic_curvature_l[2][0]; + ql[25] = extrinsic_curvature_l[2][1]; + ql[26] = extrinsic_curvature_l[2][2]; ql[27] = 1.0; - ql[28] = lapse_der_l[0]; ql[29] = lapse_der_l[1]; ql[30] = lapse_der_l[2]; - ql[31] = shift_der_l[0][0]; ql[32] = shift_der_l[0][1]; ql[33] = shift_der_l[0][2]; - ql[34] = shift_der_l[1][0]; ql[35] = shift_der_l[1][1]; ql[36] = shift_der_l[1][2]; - ql[37] = shift_der_l[2][0]; ql[38] = shift_der_l[2][1]; ql[39] = shift_der_l[2][2]; - - ql[40] = spatial_metric_der_l[0][0][0]; ql[41] = spatial_metric_der_l[0][0][1]; ql[42] = spatial_metric_der_l[0][0][2]; - ql[43] = spatial_metric_der_l[0][1][0]; ql[44] = spatial_metric_der_l[0][1][1]; ql[45] = spatial_metric_der_l[0][1][2]; - ql[46] = spatial_metric_der_l[0][2][0]; ql[47] = spatial_metric_der_l[0][2][1]; ql[48] = spatial_metric_der_l[0][2][2]; - - ql[49] = spatial_metric_der_l[1][0][0]; ql[50] = spatial_metric_der_l[1][0][1]; ql[51] = spatial_metric_der_l[1][0][2]; - ql[52] = spatial_metric_der_l[1][1][0]; ql[53] = spatial_metric_der_l[1][1][1]; ql[54] = spatial_metric_der_l[1][1][2]; - ql[55] = spatial_metric_der_l[1][2][0]; ql[56] = spatial_metric_der_l[1][2][1]; ql[57] = spatial_metric_der_l[1][2][2]; - - ql[58] = spatial_metric_der_l[2][0][0]; ql[59] = spatial_metric_der_l[2][0][1]; ql[60] = spatial_metric_der_l[2][0][2]; - ql[61] = spatial_metric_der_l[2][1][0]; ql[62] = spatial_metric_der_l[2][1][1]; ql[63] = spatial_metric_der_l[2][1][2]; - ql[64] = spatial_metric_der_l[2][2][0]; ql[65] = spatial_metric_der_l[2][2][1]; ql[66] = spatial_metric_der_l[2][2][2]; + ql[28] = lapse_der_l[0]; + ql[29] = lapse_der_l[1]; + ql[30] = lapse_der_l[2]; + ql[31] = shift_der_l[0][0]; + ql[32] = shift_der_l[0][1]; + ql[33] = shift_der_l[0][2]; + ql[34] = shift_der_l[1][0]; + ql[35] = shift_der_l[1][1]; + ql[36] = shift_der_l[1][2]; + ql[37] = shift_der_l[2][0]; + ql[38] = shift_der_l[2][1]; + ql[39] = shift_der_l[2][2]; + + ql[40] = spatial_metric_der_l[0][0][0]; + ql[41] = spatial_metric_der_l[0][0][1]; + ql[42] = spatial_metric_der_l[0][0][2]; + ql[43] = spatial_metric_der_l[0][1][0]; + ql[44] = spatial_metric_der_l[0][1][1]; + ql[45] = spatial_metric_der_l[0][1][2]; + ql[46] = spatial_metric_der_l[0][2][0]; + ql[47] = spatial_metric_der_l[0][2][1]; + ql[48] = spatial_metric_der_l[0][2][2]; + + ql[49] = spatial_metric_der_l[1][0][0]; + ql[50] = spatial_metric_der_l[1][0][1]; + ql[51] = spatial_metric_der_l[1][0][2]; + ql[52] = spatial_metric_der_l[1][1][0]; + ql[53] = spatial_metric_der_l[1][1][1]; + ql[54] = spatial_metric_der_l[1][1][2]; + ql[55] = spatial_metric_der_l[1][2][0]; + ql[56] = spatial_metric_der_l[1][2][1]; + ql[57] = spatial_metric_der_l[1][2][2]; + + ql[58] = spatial_metric_der_l[2][0][0]; + ql[59] = spatial_metric_der_l[2][0][1]; + ql[60] = spatial_metric_der_l[2][0][2]; + ql[61] = spatial_metric_der_l[2][1][0]; + ql[62] = spatial_metric_der_l[2][1][1]; + ql[63] = spatial_metric_der_l[2][1][2]; + ql[64] = spatial_metric_der_l[2][2][0]; + ql[65] = spatial_metric_der_l[2][2][1]; + ql[66] = spatial_metric_der_l[2][2][2]; ql[67] = 0.0; - ql[68] = x - 0.5; ql[69] = y; ql[70] = 0.0; + ql[68] = x - 0.5; + ql[69] = y; + ql[70] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_r * h_r * (W_r * W_r) * u_r; @@ -776,55 +1022,85 @@ test_gr_euler_tetrad_waves_minkowski_ho() qr[4] = sqrt(spatial_det_r) * ((rho_r * h_r * (W_r * W_r)) - p_r * (rho_r * W_r)); qr[5] = lapse_r; - qr[6] = shift_r[0]; qr[7] = shift_r[1]; qr[8] = shift_r[2]; - - qr[9] = spatial_metric_r[0][0]; qr[10] = spatial_metric_r[0][1]; qr[11] = spatial_metric_r[0][2]; - qr[12] = spatial_metric_r[1][0]; qr[13] = spatial_metric_r[1][1]; qr[14] = spatial_metric_r[1][2]; - qr[15] = spatial_metric_r[2][0]; qr[16] = spatial_metric_r[2][1]; qr[17] = spatial_metric_r[2][2]; - - qr[18] = extrinsic_curvature_r[0][0]; qr[19] = extrinsic_curvature_r[0][1]; qr[20] = extrinsic_curvature_r[0][2]; - qr[21] = extrinsic_curvature_r[1][0]; qr[22] = extrinsic_curvature_r[1][1]; qr[23] = extrinsic_curvature_r[1][2]; - qr[24] = extrinsic_curvature_r[2][0]; qr[25] = extrinsic_curvature_r[2][1]; qr[26] = extrinsic_curvature_r[2][2]; + qr[6] = shift_r[0]; + qr[7] = shift_r[1]; + qr[8] = shift_r[2]; + + qr[9] = spatial_metric_r[0][0]; + qr[10] = spatial_metric_r[0][1]; + qr[11] = spatial_metric_r[0][2]; + qr[12] = spatial_metric_r[1][0]; + qr[13] = spatial_metric_r[1][1]; + qr[14] = spatial_metric_r[1][2]; + qr[15] = spatial_metric_r[2][0]; + qr[16] = spatial_metric_r[2][1]; + qr[17] = spatial_metric_r[2][2]; + + qr[18] = extrinsic_curvature_r[0][0]; + qr[19] = extrinsic_curvature_r[0][1]; + qr[20] = extrinsic_curvature_r[0][2]; + qr[21] = extrinsic_curvature_r[1][0]; + qr[22] = extrinsic_curvature_r[1][1]; + qr[23] = extrinsic_curvature_r[1][2]; + qr[24] = extrinsic_curvature_r[2][0]; + qr[25] = extrinsic_curvature_r[2][1]; + qr[26] = extrinsic_curvature_r[2][2]; qr[27] = 1.0; - qr[28] = lapse_der_r[0]; qr[29] = lapse_der_r[1]; qr[30] = lapse_der_r[2]; - qr[31] = shift_der_r[0][0]; qr[32] = shift_der_r[0][1]; qr[33] = shift_der_r[0][2]; - qr[34] = shift_der_r[1][0]; qr[35] = shift_der_r[1][1]; qr[36] = shift_der_r[1][2]; - qr[37] = shift_der_r[2][0]; qr[38] = shift_der_r[2][1]; qr[39] = shift_der_r[2][2]; - - qr[40] = spatial_metric_der_r[0][0][0]; qr[41] = spatial_metric_der_r[0][0][1]; qr[42] = spatial_metric_der_r[0][0][2]; - qr[43] = spatial_metric_der_r[0][1][0]; qr[44] = spatial_metric_der_r[0][1][1]; qr[45] = spatial_metric_der_r[0][1][2]; - qr[46] = spatial_metric_der_r[0][2][0]; qr[47] = spatial_metric_der_r[0][2][1]; qr[48] = spatial_metric_der_r[0][2][2]; - - qr[49] = spatial_metric_der_r[1][0][0]; qr[50] = spatial_metric_der_r[1][0][1]; qr[51] = spatial_metric_der_r[1][0][2]; - qr[52] = spatial_metric_der_r[1][1][0]; qr[53] = spatial_metric_der_r[1][1][1]; qr[54] = spatial_metric_der_r[1][1][2]; - qr[55] = spatial_metric_der_r[1][2][0]; qr[56] = spatial_metric_der_r[1][2][1]; qr[57] = spatial_metric_der_r[1][2][2]; - - qr[58] = spatial_metric_der_r[2][0][0]; qr[59] = spatial_metric_der_r[2][0][1]; qr[60] = spatial_metric_der_r[2][0][2]; - qr[61] = spatial_metric_der_r[2][1][0]; qr[62] = spatial_metric_der_r[2][1][1]; qr[63] = spatial_metric_der_r[2][1][2]; - qr[64] = spatial_metric_der_r[2][2][0]; qr[65] = spatial_metric_der_r[2][2][1]; qr[66] = spatial_metric_der_r[2][2][2]; + qr[28] = lapse_der_r[0]; + qr[29] = lapse_der_r[1]; + qr[30] = lapse_der_r[2]; + qr[31] = shift_der_r[0][0]; + qr[32] = shift_der_r[0][1]; + qr[33] = shift_der_r[0][2]; + qr[34] = shift_der_r[1][0]; + qr[35] = shift_der_r[1][1]; + qr[36] = shift_der_r[1][2]; + qr[37] = shift_der_r[2][0]; + qr[38] = shift_der_r[2][1]; + qr[39] = shift_der_r[2][2]; + + qr[40] = spatial_metric_der_r[0][0][0]; + qr[41] = spatial_metric_der_r[0][0][1]; + qr[42] = spatial_metric_der_r[0][0][2]; + qr[43] = spatial_metric_der_r[0][1][0]; + qr[44] = spatial_metric_der_r[0][1][1]; + qr[45] = spatial_metric_der_r[0][1][2]; + qr[46] = spatial_metric_der_r[0][2][0]; + qr[47] = spatial_metric_der_r[0][2][1]; + qr[48] = spatial_metric_der_r[0][2][2]; + + qr[49] = spatial_metric_der_r[1][0][0]; + qr[50] = spatial_metric_der_r[1][0][1]; + qr[51] = spatial_metric_der_r[1][0][2]; + qr[52] = spatial_metric_der_r[1][1][0]; + qr[53] = spatial_metric_der_r[1][1][1]; + qr[54] = spatial_metric_der_r[1][1][2]; + qr[55] = spatial_metric_der_r[1][2][0]; + qr[56] = spatial_metric_der_r[1][2][1]; + qr[57] = spatial_metric_der_r[1][2][2]; + + qr[58] = spatial_metric_der_r[2][0][0]; + qr[59] = spatial_metric_der_r[2][0][1]; + qr[60] = spatial_metric_der_r[2][0][2]; + qr[61] = spatial_metric_der_r[2][1][0]; + qr[62] = spatial_metric_der_r[2][1][1]; + qr[63] = spatial_metric_der_r[2][1][2]; + qr[64] = spatial_metric_der_r[2][2][0]; + qr[65] = spatial_metric_der_r[2][2][1]; + qr[66] = spatial_metric_der_r[2][2][2]; qr[67] = 0.0; - qr[68] = x + 0.5; qr[69] = y; qr[70] = 0.0; + qr[68] = x + 0.5; + qr[69] = y; + qr[70] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3] = {0}, waves[3 * 71] = {0}, waves_local[3 * 71] = {0}; @@ -838,13 +1114,21 @@ test_gr_euler_tetrad_waves_minkowski_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[71] = {0}, amdq_local[71] = {0}; - gkyl_wv_eqn_qfluct(gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71]); + gkyl_wv_eqn_rotate_to_global( + gr_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71] + ); } double apdq[71] = {0}, amdq[71] = {0}; @@ -864,7 +1148,7 @@ test_gr_euler_tetrad_waves_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_euler_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } @@ -875,7 +1159,7 @@ test_gr_euler_tetrad_waves_minkowski_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -904,12 +1188,12 @@ test_gr_euler_tetrad_waves_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_euler_tetrad_waves_schwarzschild_ho() +void test_gr_euler_tetrad_waves_schwarzschild_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler_tetrad = + gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -925,10 +1209,10 @@ test_gr_euler_tetrad_waves_schwarzschild_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l = false, in_excision_region_r = false; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -938,18 +1222,18 @@ test_gr_euler_tetrad_waves_schwarzschild_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -968,20 +1252,46 @@ test_gr_euler_tetrad_waves_schwarzschild_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1005,37 +1315,79 @@ test_gr_euler_tetrad_waves_schwarzschild_ho() ql[4] = sqrt(spatial_det_l) * ((rho_l * h_l * (W_l * W_l)) - p_l - (rho_l * W_l)); ql[5] = lapse_l; - ql[6] = shift_l[0]; ql[7] = shift_l[1]; ql[8] = shift_l[2]; - - ql[9] = spatial_metric_l[0][0]; ql[10] = spatial_metric_l[0][1]; ql[11] = spatial_metric_l[0][2]; - ql[12] = spatial_metric_l[1][0]; ql[13] = spatial_metric_l[1][1]; ql[14] = spatial_metric_l[1][2]; - ql[15] = spatial_metric_l[2][0]; ql[16] = spatial_metric_l[2][1]; ql[17] = spatial_metric_l[2][2]; - - ql[18] = extrinsic_curvature_l[0][0]; ql[19] = extrinsic_curvature_l[0][1]; ql[20] = extrinsic_curvature_l[0][2]; - ql[21] = extrinsic_curvature_l[1][0]; ql[22] = extrinsic_curvature_l[1][1]; ql[23] = extrinsic_curvature_l[1][2]; - ql[24] = extrinsic_curvature_l[2][0]; ql[25] = extrinsic_curvature_l[2][1]; ql[26] = extrinsic_curvature_l[2][2]; + ql[6] = shift_l[0]; + ql[7] = shift_l[1]; + ql[8] = shift_l[2]; + + ql[9] = spatial_metric_l[0][0]; + ql[10] = spatial_metric_l[0][1]; + ql[11] = spatial_metric_l[0][2]; + ql[12] = spatial_metric_l[1][0]; + ql[13] = spatial_metric_l[1][1]; + ql[14] = spatial_metric_l[1][2]; + ql[15] = spatial_metric_l[2][0]; + ql[16] = spatial_metric_l[2][1]; + ql[17] = spatial_metric_l[2][2]; + + ql[18] = extrinsic_curvature_l[0][0]; + ql[19] = extrinsic_curvature_l[0][1]; + ql[20] = extrinsic_curvature_l[0][2]; + ql[21] = extrinsic_curvature_l[1][0]; + ql[22] = extrinsic_curvature_l[1][1]; + ql[23] = extrinsic_curvature_l[1][2]; + ql[24] = extrinsic_curvature_l[2][0]; + ql[25] = extrinsic_curvature_l[2][1]; + ql[26] = extrinsic_curvature_l[2][2]; ql[27] = 1.0; - ql[28] = lapse_der_l[0]; ql[29] = lapse_der_l[1]; ql[30] = lapse_der_l[2]; - ql[31] = shift_der_l[0][0]; ql[32] = shift_der_l[0][1]; ql[33] = shift_der_l[0][2]; - ql[34] = shift_der_l[1][0]; ql[35] = shift_der_l[1][1]; ql[36] = shift_der_l[1][2]; - ql[37] = shift_der_l[2][0]; ql[38] = shift_der_l[2][1]; ql[39] = shift_der_l[2][2]; - - ql[40] = spatial_metric_der_l[0][0][0]; ql[41] = spatial_metric_der_l[0][0][1]; ql[42] = spatial_metric_der_l[0][0][2]; - ql[43] = spatial_metric_der_l[0][1][0]; ql[44] = spatial_metric_der_l[0][1][1]; ql[45] = spatial_metric_der_l[0][1][2]; - ql[46] = spatial_metric_der_l[0][2][0]; ql[47] = spatial_metric_der_l[0][2][1]; ql[48] = spatial_metric_der_l[0][2][2]; - - ql[49] = spatial_metric_der_l[1][0][0]; ql[50] = spatial_metric_der_l[1][0][1]; ql[51] = spatial_metric_der_l[1][0][2]; - ql[52] = spatial_metric_der_l[1][1][0]; ql[53] = spatial_metric_der_l[1][1][1]; ql[54] = spatial_metric_der_l[1][1][2]; - ql[55] = spatial_metric_der_l[1][2][0]; ql[56] = spatial_metric_der_l[1][2][1]; ql[57] = spatial_metric_der_l[1][2][2]; - - ql[58] = spatial_metric_der_l[2][0][0]; ql[59] = spatial_metric_der_l[2][0][1]; ql[60] = spatial_metric_der_l[2][0][2]; - ql[61] = spatial_metric_der_l[2][1][0]; ql[62] = spatial_metric_der_l[2][1][1]; ql[63] = spatial_metric_der_l[2][1][2]; - ql[64] = spatial_metric_der_l[2][2][0]; ql[65] = spatial_metric_der_l[2][2][1]; ql[66] = spatial_metric_der_l[2][2][2]; + ql[28] = lapse_der_l[0]; + ql[29] = lapse_der_l[1]; + ql[30] = lapse_der_l[2]; + ql[31] = shift_der_l[0][0]; + ql[32] = shift_der_l[0][1]; + ql[33] = shift_der_l[0][2]; + ql[34] = shift_der_l[1][0]; + ql[35] = shift_der_l[1][1]; + ql[36] = shift_der_l[1][2]; + ql[37] = shift_der_l[2][0]; + ql[38] = shift_der_l[2][1]; + ql[39] = shift_der_l[2][2]; + + ql[40] = spatial_metric_der_l[0][0][0]; + ql[41] = spatial_metric_der_l[0][0][1]; + ql[42] = spatial_metric_der_l[0][0][2]; + ql[43] = spatial_metric_der_l[0][1][0]; + ql[44] = spatial_metric_der_l[0][1][1]; + ql[45] = spatial_metric_der_l[0][1][2]; + ql[46] = spatial_metric_der_l[0][2][0]; + ql[47] = spatial_metric_der_l[0][2][1]; + ql[48] = spatial_metric_der_l[0][2][2]; + + ql[49] = spatial_metric_der_l[1][0][0]; + ql[50] = spatial_metric_der_l[1][0][1]; + ql[51] = spatial_metric_der_l[1][0][2]; + ql[52] = spatial_metric_der_l[1][1][0]; + ql[53] = spatial_metric_der_l[1][1][1]; + ql[54] = spatial_metric_der_l[1][1][2]; + ql[55] = spatial_metric_der_l[1][2][0]; + ql[56] = spatial_metric_der_l[1][2][1]; + ql[57] = spatial_metric_der_l[1][2][2]; + + ql[58] = spatial_metric_der_l[2][0][0]; + ql[59] = spatial_metric_der_l[2][0][1]; + ql[60] = spatial_metric_der_l[2][0][2]; + ql[61] = spatial_metric_der_l[2][1][0]; + ql[62] = spatial_metric_der_l[2][1][1]; + ql[63] = spatial_metric_der_l[2][1][2]; + ql[64] = spatial_metric_der_l[2][2][0]; + ql[65] = spatial_metric_der_l[2][2][1]; + ql[66] = spatial_metric_der_l[2][2][2]; ql[67] = 0.0; - ql[68] = x - 0.5; ql[69] = y; ql[70] = 0.0; + ql[68] = x - 0.5; + ql[69] = y; + ql[70] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_r * h_r * (W_r * W_r) * u_r; @@ -1044,55 +1396,85 @@ test_gr_euler_tetrad_waves_schwarzschild_ho() qr[4] = sqrt(spatial_det_r) * ((rho_r * h_r * (W_r * W_r)) - p_r * (rho_r * W_r)); qr[5] = lapse_r; - qr[6] = shift_r[0]; qr[7] = shift_r[1]; qr[8] = shift_r[2]; - - qr[9] = spatial_metric_r[0][0]; qr[10] = spatial_metric_r[0][1]; qr[11] = spatial_metric_r[0][2]; - qr[12] = spatial_metric_r[1][0]; qr[13] = spatial_metric_r[1][1]; qr[14] = spatial_metric_r[1][2]; - qr[15] = spatial_metric_r[2][0]; qr[16] = spatial_metric_r[2][1]; qr[17] = spatial_metric_r[2][2]; - - qr[18] = extrinsic_curvature_r[0][0]; qr[19] = extrinsic_curvature_r[0][1]; qr[20] = extrinsic_curvature_r[0][2]; - qr[21] = extrinsic_curvature_r[1][0]; qr[22] = extrinsic_curvature_r[1][1]; qr[23] = extrinsic_curvature_r[1][2]; - qr[24] = extrinsic_curvature_r[2][0]; qr[25] = extrinsic_curvature_r[2][1]; qr[26] = extrinsic_curvature_r[2][2]; + qr[6] = shift_r[0]; + qr[7] = shift_r[1]; + qr[8] = shift_r[2]; + + qr[9] = spatial_metric_r[0][0]; + qr[10] = spatial_metric_r[0][1]; + qr[11] = spatial_metric_r[0][2]; + qr[12] = spatial_metric_r[1][0]; + qr[13] = spatial_metric_r[1][1]; + qr[14] = spatial_metric_r[1][2]; + qr[15] = spatial_metric_r[2][0]; + qr[16] = spatial_metric_r[2][1]; + qr[17] = spatial_metric_r[2][2]; + + qr[18] = extrinsic_curvature_r[0][0]; + qr[19] = extrinsic_curvature_r[0][1]; + qr[20] = extrinsic_curvature_r[0][2]; + qr[21] = extrinsic_curvature_r[1][0]; + qr[22] = extrinsic_curvature_r[1][1]; + qr[23] = extrinsic_curvature_r[1][2]; + qr[24] = extrinsic_curvature_r[2][0]; + qr[25] = extrinsic_curvature_r[2][1]; + qr[26] = extrinsic_curvature_r[2][2]; qr[27] = 1.0; - qr[28] = lapse_der_r[0]; qr[29] = lapse_der_r[1]; qr[30] = lapse_der_r[2]; - qr[31] = shift_der_r[0][0]; qr[32] = shift_der_r[0][1]; qr[33] = shift_der_r[0][2]; - qr[34] = shift_der_r[1][0]; qr[35] = shift_der_r[1][1]; qr[36] = shift_der_r[1][2]; - qr[37] = shift_der_r[2][0]; qr[38] = shift_der_r[2][1]; qr[39] = shift_der_r[2][2]; - - qr[40] = spatial_metric_der_r[0][0][0]; qr[41] = spatial_metric_der_r[0][0][1]; qr[42] = spatial_metric_der_r[0][0][2]; - qr[43] = spatial_metric_der_r[0][1][0]; qr[44] = spatial_metric_der_r[0][1][1]; qr[45] = spatial_metric_der_r[0][1][2]; - qr[46] = spatial_metric_der_r[0][2][0]; qr[47] = spatial_metric_der_r[0][2][1]; qr[48] = spatial_metric_der_r[0][2][2]; - - qr[49] = spatial_metric_der_r[1][0][0]; qr[50] = spatial_metric_der_r[1][0][1]; qr[51] = spatial_metric_der_r[1][0][2]; - qr[52] = spatial_metric_der_r[1][1][0]; qr[53] = spatial_metric_der_r[1][1][1]; qr[54] = spatial_metric_der_r[1][1][2]; - qr[55] = spatial_metric_der_r[1][2][0]; qr[56] = spatial_metric_der_r[1][2][1]; qr[57] = spatial_metric_der_r[1][2][2]; - - qr[58] = spatial_metric_der_r[2][0][0]; qr[59] = spatial_metric_der_r[2][0][1]; qr[60] = spatial_metric_der_r[2][0][2]; - qr[61] = spatial_metric_der_r[2][1][0]; qr[62] = spatial_metric_der_r[2][1][1]; qr[63] = spatial_metric_der_r[2][1][2]; - qr[64] = spatial_metric_der_r[2][2][0]; qr[65] = spatial_metric_der_r[2][2][1]; qr[66] = spatial_metric_der_r[2][2][2]; + qr[28] = lapse_der_r[0]; + qr[29] = lapse_der_r[1]; + qr[30] = lapse_der_r[2]; + qr[31] = shift_der_r[0][0]; + qr[32] = shift_der_r[0][1]; + qr[33] = shift_der_r[0][2]; + qr[34] = shift_der_r[1][0]; + qr[35] = shift_der_r[1][1]; + qr[36] = shift_der_r[1][2]; + qr[37] = shift_der_r[2][0]; + qr[38] = shift_der_r[2][1]; + qr[39] = shift_der_r[2][2]; + + qr[40] = spatial_metric_der_r[0][0][0]; + qr[41] = spatial_metric_der_r[0][0][1]; + qr[42] = spatial_metric_der_r[0][0][2]; + qr[43] = spatial_metric_der_r[0][1][0]; + qr[44] = spatial_metric_der_r[0][1][1]; + qr[45] = spatial_metric_der_r[0][1][2]; + qr[46] = spatial_metric_der_r[0][2][0]; + qr[47] = spatial_metric_der_r[0][2][1]; + qr[48] = spatial_metric_der_r[0][2][2]; + + qr[49] = spatial_metric_der_r[1][0][0]; + qr[50] = spatial_metric_der_r[1][0][1]; + qr[51] = spatial_metric_der_r[1][0][2]; + qr[52] = spatial_metric_der_r[1][1][0]; + qr[53] = spatial_metric_der_r[1][1][1]; + qr[54] = spatial_metric_der_r[1][1][2]; + qr[55] = spatial_metric_der_r[1][2][0]; + qr[56] = spatial_metric_der_r[1][2][1]; + qr[57] = spatial_metric_der_r[1][2][2]; + + qr[58] = spatial_metric_der_r[2][0][0]; + qr[59] = spatial_metric_der_r[2][0][1]; + qr[60] = spatial_metric_der_r[2][0][2]; + qr[61] = spatial_metric_der_r[2][1][0]; + qr[62] = spatial_metric_der_r[2][1][1]; + qr[63] = spatial_metric_der_r[2][1][2]; + qr[64] = spatial_metric_der_r[2][2][0]; + qr[65] = spatial_metric_der_r[2][2][1]; + qr[66] = spatial_metric_der_r[2][2][2]; qr[67] = 0.0; - qr[68] = x + 0.5; qr[69] = y; qr[70] = 0.0; + qr[68] = x + 0.5; + qr[69] = y; + qr[70] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3] = {0}, waves[3 * 71] = {0}, waves_local[3 * 71] = {0}; @@ -1106,13 +1488,21 @@ test_gr_euler_tetrad_waves_schwarzschild_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[71] = {0}, amdq_local[71] = {0}; - gkyl_wv_eqn_qfluct(gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71]); + gkyl_wv_eqn_rotate_to_global( + gr_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71] + ); } double apdq[71] = {0}, amdq[71] = {0}; @@ -1132,7 +1522,7 @@ test_gr_euler_tetrad_waves_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_euler_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1144,7 +1534,7 @@ test_gr_euler_tetrad_waves_schwarzschild_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1173,12 +1563,12 @@ test_gr_euler_tetrad_waves_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_euler_tetrad_waves_kerr_ho() +void test_gr_euler_tetrad_waves_kerr_ho() { double gas_gamma = 5.0 / 3.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_euler_tetrad = gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_euler_tetrad = + gkyl_wv_gr_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1194,10 +1584,10 @@ test_gr_euler_tetrad_waves_kerr_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l = false, in_excision_region_r = false; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1207,18 +1597,18 @@ test_gr_euler_tetrad_waves_kerr_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1237,20 +1627,46 @@ test_gr_euler_tetrad_waves_kerr_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1274,37 +1690,79 @@ test_gr_euler_tetrad_waves_kerr_ho() ql[4] = sqrt(spatial_det_l) * ((rho_l * h_l * (W_l * W_l)) - p_l - (rho_l * W_l)); ql[5] = lapse_l; - ql[6] = shift_l[0]; ql[7] = shift_l[1]; ql[8] = shift_l[2]; - - ql[9] = spatial_metric_l[0][0]; ql[10] = spatial_metric_l[0][1]; ql[11] = spatial_metric_l[0][2]; - ql[12] = spatial_metric_l[1][0]; ql[13] = spatial_metric_l[1][1]; ql[14] = spatial_metric_l[1][2]; - ql[15] = spatial_metric_l[2][0]; ql[16] = spatial_metric_l[2][1]; ql[17] = spatial_metric_l[2][2]; - - ql[18] = extrinsic_curvature_l[0][0]; ql[19] = extrinsic_curvature_l[0][1]; ql[20] = extrinsic_curvature_l[0][2]; - ql[21] = extrinsic_curvature_l[1][0]; ql[22] = extrinsic_curvature_l[1][1]; ql[23] = extrinsic_curvature_l[1][2]; - ql[24] = extrinsic_curvature_l[2][0]; ql[25] = extrinsic_curvature_l[2][1]; ql[26] = extrinsic_curvature_l[2][2]; + ql[6] = shift_l[0]; + ql[7] = shift_l[1]; + ql[8] = shift_l[2]; + + ql[9] = spatial_metric_l[0][0]; + ql[10] = spatial_metric_l[0][1]; + ql[11] = spatial_metric_l[0][2]; + ql[12] = spatial_metric_l[1][0]; + ql[13] = spatial_metric_l[1][1]; + ql[14] = spatial_metric_l[1][2]; + ql[15] = spatial_metric_l[2][0]; + ql[16] = spatial_metric_l[2][1]; + ql[17] = spatial_metric_l[2][2]; + + ql[18] = extrinsic_curvature_l[0][0]; + ql[19] = extrinsic_curvature_l[0][1]; + ql[20] = extrinsic_curvature_l[0][2]; + ql[21] = extrinsic_curvature_l[1][0]; + ql[22] = extrinsic_curvature_l[1][1]; + ql[23] = extrinsic_curvature_l[1][2]; + ql[24] = extrinsic_curvature_l[2][0]; + ql[25] = extrinsic_curvature_l[2][1]; + ql[26] = extrinsic_curvature_l[2][2]; ql[27] = 1.0; - ql[28] = lapse_der_l[0]; ql[29] = lapse_der_l[1]; ql[30] = lapse_der_l[2]; - ql[31] = shift_der_l[0][0]; ql[32] = shift_der_l[0][1]; ql[33] = shift_der_l[0][2]; - ql[34] = shift_der_l[1][0]; ql[35] = shift_der_l[1][1]; ql[36] = shift_der_l[1][2]; - ql[37] = shift_der_l[2][0]; ql[38] = shift_der_l[2][1]; ql[39] = shift_der_l[2][2]; - - ql[40] = spatial_metric_der_l[0][0][0]; ql[41] = spatial_metric_der_l[0][0][1]; ql[42] = spatial_metric_der_l[0][0][2]; - ql[43] = spatial_metric_der_l[0][1][0]; ql[44] = spatial_metric_der_l[0][1][1]; ql[45] = spatial_metric_der_l[0][1][2]; - ql[46] = spatial_metric_der_l[0][2][0]; ql[47] = spatial_metric_der_l[0][2][1]; ql[48] = spatial_metric_der_l[0][2][2]; - - ql[49] = spatial_metric_der_l[1][0][0]; ql[50] = spatial_metric_der_l[1][0][1]; ql[51] = spatial_metric_der_l[1][0][2]; - ql[52] = spatial_metric_der_l[1][1][0]; ql[53] = spatial_metric_der_l[1][1][1]; ql[54] = spatial_metric_der_l[1][1][2]; - ql[55] = spatial_metric_der_l[1][2][0]; ql[56] = spatial_metric_der_l[1][2][1]; ql[57] = spatial_metric_der_l[1][2][2]; - - ql[58] = spatial_metric_der_l[2][0][0]; ql[59] = spatial_metric_der_l[2][0][1]; ql[60] = spatial_metric_der_l[2][0][2]; - ql[61] = spatial_metric_der_l[2][1][0]; ql[62] = spatial_metric_der_l[2][1][1]; ql[63] = spatial_metric_der_l[2][1][2]; - ql[64] = spatial_metric_der_l[2][2][0]; ql[65] = spatial_metric_der_l[2][2][1]; ql[66] = spatial_metric_der_l[2][2][2]; + ql[28] = lapse_der_l[0]; + ql[29] = lapse_der_l[1]; + ql[30] = lapse_der_l[2]; + ql[31] = shift_der_l[0][0]; + ql[32] = shift_der_l[0][1]; + ql[33] = shift_der_l[0][2]; + ql[34] = shift_der_l[1][0]; + ql[35] = shift_der_l[1][1]; + ql[36] = shift_der_l[1][2]; + ql[37] = shift_der_l[2][0]; + ql[38] = shift_der_l[2][1]; + ql[39] = shift_der_l[2][2]; + + ql[40] = spatial_metric_der_l[0][0][0]; + ql[41] = spatial_metric_der_l[0][0][1]; + ql[42] = spatial_metric_der_l[0][0][2]; + ql[43] = spatial_metric_der_l[0][1][0]; + ql[44] = spatial_metric_der_l[0][1][1]; + ql[45] = spatial_metric_der_l[0][1][2]; + ql[46] = spatial_metric_der_l[0][2][0]; + ql[47] = spatial_metric_der_l[0][2][1]; + ql[48] = spatial_metric_der_l[0][2][2]; + + ql[49] = spatial_metric_der_l[1][0][0]; + ql[50] = spatial_metric_der_l[1][0][1]; + ql[51] = spatial_metric_der_l[1][0][2]; + ql[52] = spatial_metric_der_l[1][1][0]; + ql[53] = spatial_metric_der_l[1][1][1]; + ql[54] = spatial_metric_der_l[1][1][2]; + ql[55] = spatial_metric_der_l[1][2][0]; + ql[56] = spatial_metric_der_l[1][2][1]; + ql[57] = spatial_metric_der_l[1][2][2]; + + ql[58] = spatial_metric_der_l[2][0][0]; + ql[59] = spatial_metric_der_l[2][0][1]; + ql[60] = spatial_metric_der_l[2][0][2]; + ql[61] = spatial_metric_der_l[2][1][0]; + ql[62] = spatial_metric_der_l[2][1][1]; + ql[63] = spatial_metric_der_l[2][1][2]; + ql[64] = spatial_metric_der_l[2][2][0]; + ql[65] = spatial_metric_der_l[2][2][1]; + ql[66] = spatial_metric_der_l[2][2][2]; ql[67] = 0.0; - ql[68] = x - 0.5; ql[69] = y; ql[70] = 0.0; + ql[68] = x - 0.5; + ql[69] = y; + ql[70] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_r * h_r * (W_r * W_r) * u_r; @@ -1313,55 +1771,85 @@ test_gr_euler_tetrad_waves_kerr_ho() qr[4] = sqrt(spatial_det_r) * ((rho_r * h_r * (W_r * W_r)) - p_r * (rho_r * W_r)); qr[5] = lapse_r; - qr[6] = shift_r[0]; qr[7] = shift_r[1]; qr[8] = shift_r[2]; - - qr[9] = spatial_metric_r[0][0]; qr[10] = spatial_metric_r[0][1]; qr[11] = spatial_metric_r[0][2]; - qr[12] = spatial_metric_r[1][0]; qr[13] = spatial_metric_r[1][1]; qr[14] = spatial_metric_r[1][2]; - qr[15] = spatial_metric_r[2][0]; qr[16] = spatial_metric_r[2][1]; qr[17] = spatial_metric_r[2][2]; - - qr[18] = extrinsic_curvature_r[0][0]; qr[19] = extrinsic_curvature_r[0][1]; qr[20] = extrinsic_curvature_r[0][2]; - qr[21] = extrinsic_curvature_r[1][0]; qr[22] = extrinsic_curvature_r[1][1]; qr[23] = extrinsic_curvature_r[1][2]; - qr[24] = extrinsic_curvature_r[2][0]; qr[25] = extrinsic_curvature_r[2][1]; qr[26] = extrinsic_curvature_r[2][2]; + qr[6] = shift_r[0]; + qr[7] = shift_r[1]; + qr[8] = shift_r[2]; + + qr[9] = spatial_metric_r[0][0]; + qr[10] = spatial_metric_r[0][1]; + qr[11] = spatial_metric_r[0][2]; + qr[12] = spatial_metric_r[1][0]; + qr[13] = spatial_metric_r[1][1]; + qr[14] = spatial_metric_r[1][2]; + qr[15] = spatial_metric_r[2][0]; + qr[16] = spatial_metric_r[2][1]; + qr[17] = spatial_metric_r[2][2]; + + qr[18] = extrinsic_curvature_r[0][0]; + qr[19] = extrinsic_curvature_r[0][1]; + qr[20] = extrinsic_curvature_r[0][2]; + qr[21] = extrinsic_curvature_r[1][0]; + qr[22] = extrinsic_curvature_r[1][1]; + qr[23] = extrinsic_curvature_r[1][2]; + qr[24] = extrinsic_curvature_r[2][0]; + qr[25] = extrinsic_curvature_r[2][1]; + qr[26] = extrinsic_curvature_r[2][2]; qr[27] = 1.0; - qr[28] = lapse_der_r[0]; qr[29] = lapse_der_r[1]; qr[30] = lapse_der_r[2]; - qr[31] = shift_der_r[0][0]; qr[32] = shift_der_r[0][1]; qr[33] = shift_der_r[0][2]; - qr[34] = shift_der_r[1][0]; qr[35] = shift_der_r[1][1]; qr[36] = shift_der_r[1][2]; - qr[37] = shift_der_r[2][0]; qr[38] = shift_der_r[2][1]; qr[39] = shift_der_r[2][2]; - - qr[40] = spatial_metric_der_r[0][0][0]; qr[41] = spatial_metric_der_r[0][0][1]; qr[42] = spatial_metric_der_r[0][0][2]; - qr[43] = spatial_metric_der_r[0][1][0]; qr[44] = spatial_metric_der_r[0][1][1]; qr[45] = spatial_metric_der_r[0][1][2]; - qr[46] = spatial_metric_der_r[0][2][0]; qr[47] = spatial_metric_der_r[0][2][1]; qr[48] = spatial_metric_der_r[0][2][2]; - - qr[49] = spatial_metric_der_r[1][0][0]; qr[50] = spatial_metric_der_r[1][0][1]; qr[51] = spatial_metric_der_r[1][0][2]; - qr[52] = spatial_metric_der_r[1][1][0]; qr[53] = spatial_metric_der_r[1][1][1]; qr[54] = spatial_metric_der_r[1][1][2]; - qr[55] = spatial_metric_der_r[1][2][0]; qr[56] = spatial_metric_der_r[1][2][1]; qr[57] = spatial_metric_der_r[1][2][2]; - - qr[58] = spatial_metric_der_r[2][0][0]; qr[59] = spatial_metric_der_r[2][0][1]; qr[60] = spatial_metric_der_r[2][0][2]; - qr[61] = spatial_metric_der_r[2][1][0]; qr[62] = spatial_metric_der_r[2][1][1]; qr[63] = spatial_metric_der_r[2][1][2]; - qr[64] = spatial_metric_der_r[2][2][0]; qr[65] = spatial_metric_der_r[2][2][1]; qr[66] = spatial_metric_der_r[2][2][2]; + qr[28] = lapse_der_r[0]; + qr[29] = lapse_der_r[1]; + qr[30] = lapse_der_r[2]; + qr[31] = shift_der_r[0][0]; + qr[32] = shift_der_r[0][1]; + qr[33] = shift_der_r[0][2]; + qr[34] = shift_der_r[1][0]; + qr[35] = shift_der_r[1][1]; + qr[36] = shift_der_r[1][2]; + qr[37] = shift_der_r[2][0]; + qr[38] = shift_der_r[2][1]; + qr[39] = shift_der_r[2][2]; + + qr[40] = spatial_metric_der_r[0][0][0]; + qr[41] = spatial_metric_der_r[0][0][1]; + qr[42] = spatial_metric_der_r[0][0][2]; + qr[43] = spatial_metric_der_r[0][1][0]; + qr[44] = spatial_metric_der_r[0][1][1]; + qr[45] = spatial_metric_der_r[0][1][2]; + qr[46] = spatial_metric_der_r[0][2][0]; + qr[47] = spatial_metric_der_r[0][2][1]; + qr[48] = spatial_metric_der_r[0][2][2]; + + qr[49] = spatial_metric_der_r[1][0][0]; + qr[50] = spatial_metric_der_r[1][0][1]; + qr[51] = spatial_metric_der_r[1][0][2]; + qr[52] = spatial_metric_der_r[1][1][0]; + qr[53] = spatial_metric_der_r[1][1][1]; + qr[54] = spatial_metric_der_r[1][1][2]; + qr[55] = spatial_metric_der_r[1][2][0]; + qr[56] = spatial_metric_der_r[1][2][1]; + qr[57] = spatial_metric_der_r[1][2][2]; + + qr[58] = spatial_metric_der_r[2][0][0]; + qr[59] = spatial_metric_der_r[2][0][1]; + qr[60] = spatial_metric_der_r[2][0][2]; + qr[61] = spatial_metric_der_r[2][1][0]; + qr[62] = spatial_metric_der_r[2][1][1]; + qr[63] = spatial_metric_der_r[2][1][2]; + qr[64] = spatial_metric_der_r[2][2][0]; + qr[65] = spatial_metric_der_r[2][2][1]; + qr[66] = spatial_metric_der_r[2][2][2]; qr[67] = 0.0; - qr[68] = x + 0.5; qr[69] = y; qr[70] = 0.0; + qr[68] = x + 0.5; + qr[69] = y; + qr[70] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3] = {0}, waves[3 * 71] = {0}, waves_local[3 * 71] = {0}; @@ -1375,13 +1863,21 @@ test_gr_euler_tetrad_waves_kerr_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[71] = {0}, amdq_local[71] = {0}; - gkyl_wv_eqn_qfluct(gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71]); + gkyl_wv_eqn_rotate_to_global( + gr_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 71], &waves[i * 71] + ); } double apdq[71] = {0}, amdq[71] = {0}; @@ -1401,7 +1897,7 @@ test_gr_euler_tetrad_waves_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_euler_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); for (int i = 0; i < 71; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1413,7 +1909,7 @@ test_gr_euler_tetrad_waves_kerr_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1443,11 +1939,11 @@ test_gr_euler_tetrad_waves_kerr_ho() } TEST_LIST = { - { "gr_euler_tetrad_basic_minkowski_ho", test_gr_euler_tetrad_basic_minkowski_ho }, - { "gr_euler_tetrad_basic_schwarzschild_ho", test_gr_euler_tetrad_basic_schwarzschild_ho }, - { "gr_euler_tetrad_basic_kerr_ho", test_gr_euler_tetrad_basic_kerr_ho }, - { "gr_euler_tetrad_waves_minkowski_ho", test_gr_euler_tetrad_waves_minkowski_ho }, - { "gr_euler_tetrad_waves_schwarzschild_ho", test_gr_euler_tetrad_waves_schwarzschild_ho }, - { "gr_euler_tetrad_waves_kerr_ho", test_gr_euler_tetrad_waves_kerr_ho }, - { NULL, NULL }, + {"gr_euler_tetrad_basic_minkowski_ho", test_gr_euler_tetrad_basic_minkowski_ho}, + {"gr_euler_tetrad_basic_schwarzschild_ho", test_gr_euler_tetrad_basic_schwarzschild_ho}, + {"gr_euler_tetrad_basic_kerr_ho", test_gr_euler_tetrad_basic_kerr_ho}, + {"gr_euler_tetrad_waves_minkowski_ho", test_gr_euler_tetrad_waves_minkowski_ho}, + {"gr_euler_tetrad_waves_schwarzschild_ho", test_gr_euler_tetrad_waves_schwarzschild_ho}, + {"gr_euler_tetrad_waves_kerr_ho", test_gr_euler_tetrad_waves_kerr_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_gr_maxwell.c b/moments/unit/ctest_wv_gr_maxwell.c index 4d66492a21..4bf44e5c80 100644 --- a/moments/unit/ctest_wv_gr_maxwell.c +++ b/moments/unit/ctest_wv_gr_maxwell.c @@ -6,17 +6,17 @@ #include #include -void -test_gr_maxwell_basic_minkowski_ho() +void test_gr_maxwell_basic_minkowski_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell = + gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_maxwell->num_equations == 26 ); - TEST_CHECK( gr_maxwell->num_waves == 6 ); + TEST_CHECK(gr_maxwell->num_equations == 26); + TEST_CHECK(gr_maxwell->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -30,7 +30,7 @@ test_gr_maxwell_basic_minkowski_ho() double lapse; double *shift = gkyl_malloc(sizeof(double[3])); - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -41,21 +41,36 @@ test_gr_maxwell_basic_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); double q[26]; - q[0] = Dx; q[1] = Dy; q[2] = Dz; - q[3] = Bx; q[4] = By; q[5] = Bz; - q[6] = phi; q[7] = psi; + q[0] = Dx; + q[1] = Dy; + q[2] = Dz; + q[3] = Bx; + q[4] = By; + q[5] = Bz; + q[6] = phi; + q[7] = psi; q[8] = lapse; - q[9] = shift[0]; q[10] = shift[1]; q[11] = shift[2]; - - q[12] = spatial_metric[0][0]; q[13] = spatial_metric[0][1]; q[14] = spatial_metric[0][2]; - q[15] = spatial_metric[1][0]; q[16] = spatial_metric[1][1]; q[17] = spatial_metric[1][2]; - q[18] = spatial_metric[2][0]; q[19] = spatial_metric[2][1]; q[20] = spatial_metric[2][2]; + q[9] = shift[0]; + q[10] = shift[1]; + q[11] = shift[2]; + + q[12] = spatial_metric[0][0]; + q[13] = spatial_metric[0][1]; + q[14] = spatial_metric[0][2]; + q[15] = spatial_metric[1][0]; + q[16] = spatial_metric[1][1]; + q[17] = spatial_metric[1][2]; + q[18] = spatial_metric[2][0]; + q[19] = spatial_metric[2][1]; + q[20] = spatial_metric[2][2]; q[21] = 1.0; q[22] = 0.0; - q[23] = x; q[24] = y; q[25] = 0.0; + q[23] = x; + q[24] = y; + q[25] = 0.0; double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -66,31 +81,22 @@ test_gr_maxwell_basic_minkowski_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][8] = { - { e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {-(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[26], flux_local[26], flux[26]; for (int d = 0; d < 3; d++) { @@ -99,7 +105,7 @@ test_gr_maxwell_basic_minkowski_ho() gr_maxwell->rotate_to_global_func(gr_maxwell, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-13) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-13)); } } @@ -109,7 +115,7 @@ test_gr_maxwell_basic_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_maxwell, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[26], q1[26]; @@ -117,7 +123,7 @@ test_gr_maxwell_basic_minkowski_ho() gr_maxwell->riem_to_cons(gr_maxwell, q_local, w1, q1); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } @@ -133,17 +139,17 @@ test_gr_maxwell_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_maxwell_basic_schwarzschild_ho() +void test_gr_maxwell_basic_schwarzschild_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell = + gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_maxwell->num_equations == 26 ); - TEST_CHECK( gr_maxwell->num_waves == 6 ); + TEST_CHECK(gr_maxwell->num_equations == 26); + TEST_CHECK(gr_maxwell->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -158,7 +164,7 @@ test_gr_maxwell_basic_schwarzschild_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -171,21 +177,36 @@ test_gr_maxwell_basic_schwarzschild_ho() if (!in_excision_region) { double q[26]; - q[0] = Dx; q[1] = Dy; q[2] = Dz; - q[3] = Bx; q[4] = By; q[5] = Bz; - q[6] = phi; q[7] = psi; + q[0] = Dx; + q[1] = Dy; + q[2] = Dz; + q[3] = Bx; + q[4] = By; + q[5] = Bz; + q[6] = phi; + q[7] = psi; q[8] = lapse; - q[9] = shift[0]; q[10] = shift[1]; q[11] = shift[2]; - - q[12] = spatial_metric[0][0]; q[13] = spatial_metric[0][1]; q[14] = spatial_metric[0][2]; - q[15] = spatial_metric[1][0]; q[16] = spatial_metric[1][1]; q[17] = spatial_metric[1][2]; - q[18] = spatial_metric[2][0]; q[19] = spatial_metric[2][1]; q[20] = spatial_metric[2][2]; + q[9] = shift[0]; + q[10] = shift[1]; + q[11] = shift[2]; + + q[12] = spatial_metric[0][0]; + q[13] = spatial_metric[0][1]; + q[14] = spatial_metric[0][2]; + q[15] = spatial_metric[1][0]; + q[16] = spatial_metric[1][1]; + q[17] = spatial_metric[1][2]; + q[18] = spatial_metric[2][0]; + q[19] = spatial_metric[2][1]; + q[20] = spatial_metric[2][2]; q[21] = 1.0; q[22] = 0.0; - q[23] = x; q[24] = y; q[25] = 0.0; + q[23] = x; + q[24] = y; + q[25] = 0.0; double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -196,31 +217,22 @@ test_gr_maxwell_basic_schwarzschild_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][8] = { - { e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {-(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[26], flux_local[26], flux[26]; for (int d = 0; d < 3; d++) { @@ -229,7 +241,7 @@ test_gr_maxwell_basic_schwarzschild_ho() gr_maxwell->rotate_to_global_func(gr_maxwell, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-13) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-13)); } } @@ -239,7 +251,7 @@ test_gr_maxwell_basic_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_maxwell, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[26], q1[26]; @@ -247,7 +259,7 @@ test_gr_maxwell_basic_schwarzschild_ho() gr_maxwell->riem_to_cons(gr_maxwell, q_local, w1, q1); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -264,17 +276,17 @@ test_gr_maxwell_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_maxwell_basic_kerr_ho() +void test_gr_maxwell_basic_kerr_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell = + gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_maxwell->num_equations == 26 ); - TEST_CHECK( gr_maxwell->num_waves == 6 ); + TEST_CHECK(gr_maxwell->num_equations == 26); + TEST_CHECK(gr_maxwell->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -289,7 +301,7 @@ test_gr_maxwell_basic_kerr_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -302,21 +314,36 @@ test_gr_maxwell_basic_kerr_ho() if (!in_excision_region) { double q[26]; - q[0] = Dx; q[1] = Dy; q[2] = Dz; - q[3] = Bx; q[4] = By; q[5] = Bz; - q[6] = phi; q[7] = psi; + q[0] = Dx; + q[1] = Dy; + q[2] = Dz; + q[3] = Bx; + q[4] = By; + q[5] = Bz; + q[6] = phi; + q[7] = psi; q[8] = lapse; - q[9] = shift[0]; q[10] = shift[1]; q[11] = shift[2]; - - q[12] = spatial_metric[0][0]; q[13] = spatial_metric[0][1]; q[14] = spatial_metric[0][2]; - q[15] = spatial_metric[1][0]; q[16] = spatial_metric[1][1]; q[17] = spatial_metric[1][2]; - q[18] = spatial_metric[2][0]; q[19] = spatial_metric[2][1]; q[20] = spatial_metric[2][2]; + q[9] = shift[0]; + q[10] = shift[1]; + q[11] = shift[2]; + + q[12] = spatial_metric[0][0]; + q[13] = spatial_metric[0][1]; + q[14] = spatial_metric[0][2]; + q[15] = spatial_metric[1][0]; + q[16] = spatial_metric[1][1]; + q[17] = spatial_metric[1][2]; + q[18] = spatial_metric[2][0]; + q[19] = spatial_metric[2][1]; + q[20] = spatial_metric[2][2]; q[21] = 1.0; q[22] = 0.0; - q[23] = x; q[24] = y; q[25] = 0.0; + q[23] = x; + q[24] = y; + q[25] = 0.0; double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -327,31 +354,22 @@ test_gr_maxwell_basic_kerr_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][8] = { - { e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {-(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[26], flux_local[26], flux[26]; for (int d = 0; d < 3; d++) { @@ -360,7 +378,7 @@ test_gr_maxwell_basic_kerr_ho() gr_maxwell->rotate_to_global_func(gr_maxwell, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-13) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-13)); } } @@ -370,7 +388,7 @@ test_gr_maxwell_basic_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_maxwell, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[26], q1[26]; @@ -378,7 +396,7 @@ test_gr_maxwell_basic_kerr_ho() gr_maxwell->riem_to_cons(gr_maxwell, q_local, w1, q1); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -395,14 +413,14 @@ test_gr_maxwell_basic_kerr_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_maxwell_waves_minkowski_ho() +void test_gr_maxwell_waves_minkowski_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell = + gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -421,8 +439,8 @@ test_gr_maxwell_waves_minkowski_ho() double *shift_l = gkyl_malloc(sizeof(double[3])); double *shift_r = gkyl_malloc(sizeof(double[3])); - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -435,57 +453,75 @@ test_gr_maxwell_waves_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - + double ql[26], qr[26]; - ql[0] = Dx_l; ql[1] = Dy_l; ql[2] = Dz_l; - ql[3] = Bx_l; ql[4] = By_l; ql[5] = Bz_l; - ql[6] = phi_l; ql[7] = psi_l; + ql[0] = Dx_l; + ql[1] = Dy_l; + ql[2] = Dz_l; + ql[3] = Bx_l; + ql[4] = By_l; + ql[5] = Bz_l; + ql[6] = phi_l; + ql[7] = psi_l; ql[8] = lapse_l; - ql[9] = shift_l[0]; ql[10] = shift_l[1]; ql[11] = shift_l[2]; - - ql[12] = spatial_metric_l[0][0]; ql[13] = spatial_metric_l[0][1]; ql[14] = spatial_metric_l[0][2]; - ql[15] = spatial_metric_l[1][0]; ql[16] = spatial_metric_l[1][1]; ql[17] = spatial_metric_l[1][2]; - ql[18] = spatial_metric_l[2][0]; ql[19] = spatial_metric_l[2][1]; ql[20] = spatial_metric_l[2][2]; + ql[9] = shift_l[0]; + ql[10] = shift_l[1]; + ql[11] = shift_l[2]; + + ql[12] = spatial_metric_l[0][0]; + ql[13] = spatial_metric_l[0][1]; + ql[14] = spatial_metric_l[0][2]; + ql[15] = spatial_metric_l[1][0]; + ql[16] = spatial_metric_l[1][1]; + ql[17] = spatial_metric_l[1][2]; + ql[18] = spatial_metric_l[2][0]; + ql[19] = spatial_metric_l[2][1]; + ql[20] = spatial_metric_l[2][2]; ql[21] = 1.0; ql[22] = 0.0; - ql[23] = x - 0.5; ql[24] = y; ql[25] = 0.0; - - qr[0] = Dx_r; qr[1] = Dy_r; qr[2] = Dz_r; - qr[3] = Bx_r; qr[4] = By_r; qr[5] = Bz_r; - qr[6] = phi_r; qr[7] = psi_r; + ql[23] = x - 0.5; + ql[24] = y; + ql[25] = 0.0; + + qr[0] = Dx_r; + qr[1] = Dy_r; + qr[2] = Dz_r; + qr[3] = Bx_r; + qr[4] = By_r; + qr[5] = Bz_r; + qr[6] = phi_r; + qr[7] = psi_r; qr[8] = lapse_r; - qr[9] = shift_r[0]; qr[10] = shift_r[1]; qr[11] = shift_r[2]; - - qr[12] = spatial_metric_r[0][0]; qr[13] = spatial_metric_r[0][1]; qr[14] = spatial_metric_r[0][2]; - qr[15] = spatial_metric_r[1][0]; qr[16] = spatial_metric_r[1][1]; qr[17] = spatial_metric_r[1][2]; - qr[18] = spatial_metric_r[2][0]; qr[19] = spatial_metric_r[2][1]; qr[20] = spatial_metric_r[2][2]; + qr[9] = shift_r[0]; + qr[10] = shift_r[1]; + qr[11] = shift_r[2]; + + qr[12] = spatial_metric_r[0][0]; + qr[13] = spatial_metric_r[0][1]; + qr[14] = spatial_metric_r[0][2]; + qr[15] = spatial_metric_r[1][0]; + qr[16] = spatial_metric_r[1][1]; + qr[17] = spatial_metric_r[1][2]; + qr[18] = spatial_metric_r[2][0]; + qr[19] = spatial_metric_r[2][1]; + qr[20] = spatial_metric_r[2][2]; qr[21] = 1.0; qr[22] = 0.0; - qr[23] = x + 0.5; qr[24] = y; qr[25] = 0.0; + qr[23] = x + 0.5; + qr[24] = y; + qr[25] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[6], waves[6 * 26], waves_local[6 * 26]; @@ -499,13 +535,21 @@ test_gr_maxwell_waves_minkowski_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[26], amdq_local[26]; - gkyl_wv_eqn_qfluct(gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_maxwell, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26]); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26] + ); } double apdq[26], amdq[26]; @@ -521,10 +565,10 @@ test_gr_maxwell_waves_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_maxwell, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 26; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } - + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric_l[i]); gkyl_free(spatial_metric_r[i]); @@ -535,19 +579,19 @@ test_gr_maxwell_waves_minkowski_ho() gkyl_free(shift_r); } } - + gkyl_wv_eqn_release(gr_maxwell); gkyl_gr_spacetime_release(spacetime); } -void -test_gr_maxwell_waves_schwarzschild_ho() +void test_gr_maxwell_waves_schwarzschild_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell = + gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -567,8 +611,8 @@ test_gr_maxwell_waves_schwarzschild_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -586,55 +630,73 @@ test_gr_maxwell_waves_schwarzschild_ho() if (!in_excision_region_l && !in_excision_region_r) { double ql[26], qr[26]; - ql[0] = Dx_l; ql[1] = Dy_l; ql[2] = Dz_l; - ql[3] = Bx_l; ql[4] = By_l; ql[5] = Bz_l; - ql[6] = phi_l; ql[7] = psi_l; + ql[0] = Dx_l; + ql[1] = Dy_l; + ql[2] = Dz_l; + ql[3] = Bx_l; + ql[4] = By_l; + ql[5] = Bz_l; + ql[6] = phi_l; + ql[7] = psi_l; ql[8] = lapse_l; - ql[9] = shift_l[0]; ql[10] = shift_l[1]; ql[11] = shift_l[2]; - - ql[12] = spatial_metric_l[0][0]; ql[13] = spatial_metric_l[0][1]; ql[14] = spatial_metric_l[0][2]; - ql[15] = spatial_metric_l[1][0]; ql[16] = spatial_metric_l[1][1]; ql[17] = spatial_metric_l[1][2]; - ql[18] = spatial_metric_l[2][0]; ql[19] = spatial_metric_l[2][1]; ql[20] = spatial_metric_l[2][2]; + ql[9] = shift_l[0]; + ql[10] = shift_l[1]; + ql[11] = shift_l[2]; + + ql[12] = spatial_metric_l[0][0]; + ql[13] = spatial_metric_l[0][1]; + ql[14] = spatial_metric_l[0][2]; + ql[15] = spatial_metric_l[1][0]; + ql[16] = spatial_metric_l[1][1]; + ql[17] = spatial_metric_l[1][2]; + ql[18] = spatial_metric_l[2][0]; + ql[19] = spatial_metric_l[2][1]; + ql[20] = spatial_metric_l[2][2]; ql[21] = 1.0; ql[22] = 0.0; - ql[23] = x - 0.5; ql[24] = y; ql[25] = 0.0; - - qr[0] = Dx_r; qr[1] = Dy_r; qr[2] = Dz_r; - qr[3] = Bx_r; qr[4] = By_r; qr[5] = Bz_r; - qr[6] = phi_r; qr[7] = psi_r; + ql[23] = x - 0.5; + ql[24] = y; + ql[25] = 0.0; + + qr[0] = Dx_r; + qr[1] = Dy_r; + qr[2] = Dz_r; + qr[3] = Bx_r; + qr[4] = By_r; + qr[5] = Bz_r; + qr[6] = phi_r; + qr[7] = psi_r; qr[8] = lapse_r; - qr[9] = shift_r[0]; qr[10] = shift_r[1]; qr[11] = shift_r[2]; - - qr[12] = spatial_metric_r[0][0]; qr[13] = spatial_metric_r[0][1]; qr[14] = spatial_metric_r[0][2]; - qr[15] = spatial_metric_r[1][0]; qr[16] = spatial_metric_r[1][1]; qr[17] = spatial_metric_r[1][2]; - qr[18] = spatial_metric_r[2][0]; qr[19] = spatial_metric_r[2][1]; qr[20] = spatial_metric_r[2][2]; + qr[9] = shift_r[0]; + qr[10] = shift_r[1]; + qr[11] = shift_r[2]; + + qr[12] = spatial_metric_r[0][0]; + qr[13] = spatial_metric_r[0][1]; + qr[14] = spatial_metric_r[0][2]; + qr[15] = spatial_metric_r[1][0]; + qr[16] = spatial_metric_r[1][1]; + qr[17] = spatial_metric_r[1][2]; + qr[18] = spatial_metric_r[2][0]; + qr[19] = spatial_metric_r[2][1]; + qr[20] = spatial_metric_r[2][2]; qr[21] = 1.0; qr[22] = 0.0; - qr[23] = x + 0.5; qr[24] = y; qr[25] = 0.0; + qr[23] = x + 0.5; + qr[24] = y; + qr[25] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[6], waves[6 * 26], waves_local[6 * 26]; @@ -648,13 +710,21 @@ test_gr_maxwell_waves_schwarzschild_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[26], amdq_local[26]; - gkyl_wv_eqn_qfluct(gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_maxwell, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26]); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26] + ); } double apdq[26], amdq[26]; @@ -670,11 +740,11 @@ test_gr_maxwell_waves_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_maxwell, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 26; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } } - + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric_l[i]); gkyl_free(spatial_metric_r[i]); @@ -685,19 +755,19 @@ test_gr_maxwell_waves_schwarzschild_ho() gkyl_free(shift_r); } } - + gkyl_wv_eqn_release(gr_maxwell); gkyl_gr_spacetime_release(spacetime); } -void -test_gr_maxwell_waves_kerr_ho() +void test_gr_maxwell_waves_kerr_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_maxwell = gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell = + gkyl_wv_gr_maxwell_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -717,8 +787,8 @@ test_gr_maxwell_waves_kerr_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -736,55 +806,73 @@ test_gr_maxwell_waves_kerr_ho() if (!in_excision_region_l && !in_excision_region_r) { double ql[26], qr[26]; - ql[0] = Dx_l; ql[1] = Dy_l; ql[2] = Dz_l; - ql[3] = Bx_l; ql[4] = By_l; ql[5] = Bz_l; - ql[6] = phi_l; ql[7] = psi_l; + ql[0] = Dx_l; + ql[1] = Dy_l; + ql[2] = Dz_l; + ql[3] = Bx_l; + ql[4] = By_l; + ql[5] = Bz_l; + ql[6] = phi_l; + ql[7] = psi_l; ql[8] = lapse_l; - ql[9] = shift_l[0]; ql[10] = shift_l[1]; ql[11] = shift_l[2]; - - ql[12] = spatial_metric_l[0][0]; ql[13] = spatial_metric_l[0][1]; ql[14] = spatial_metric_l[0][2]; - ql[15] = spatial_metric_l[1][0]; ql[16] = spatial_metric_l[1][1]; ql[17] = spatial_metric_l[1][2]; - ql[18] = spatial_metric_l[2][0]; ql[19] = spatial_metric_l[2][1]; ql[20] = spatial_metric_l[2][2]; + ql[9] = shift_l[0]; + ql[10] = shift_l[1]; + ql[11] = shift_l[2]; + + ql[12] = spatial_metric_l[0][0]; + ql[13] = spatial_metric_l[0][1]; + ql[14] = spatial_metric_l[0][2]; + ql[15] = spatial_metric_l[1][0]; + ql[16] = spatial_metric_l[1][1]; + ql[17] = spatial_metric_l[1][2]; + ql[18] = spatial_metric_l[2][0]; + ql[19] = spatial_metric_l[2][1]; + ql[20] = spatial_metric_l[2][2]; ql[21] = 1.0; ql[22] = 0.0; - ql[23] = x - 0.5; ql[24] = y; ql[25] = 0.0; - - qr[0] = Dx_r; qr[1] = Dy_r; qr[2] = Dz_r; - qr[3] = Bx_r; qr[4] = By_r; qr[5] = Bz_r; - qr[6] = phi_r; qr[7] = psi_r; + ql[23] = x - 0.5; + ql[24] = y; + ql[25] = 0.0; + + qr[0] = Dx_r; + qr[1] = Dy_r; + qr[2] = Dz_r; + qr[3] = Bx_r; + qr[4] = By_r; + qr[5] = Bz_r; + qr[6] = phi_r; + qr[7] = psi_r; qr[8] = lapse_r; - qr[9] = shift_r[0]; qr[10] = shift_r[1]; qr[11] = shift_r[2]; - - qr[12] = spatial_metric_r[0][0]; qr[13] = spatial_metric_r[0][1]; qr[14] = spatial_metric_r[0][2]; - qr[15] = spatial_metric_r[1][0]; qr[16] = spatial_metric_r[1][1]; qr[17] = spatial_metric_r[1][2]; - qr[18] = spatial_metric_r[2][0]; qr[19] = spatial_metric_r[2][1]; qr[20] = spatial_metric_r[2][2]; + qr[9] = shift_r[0]; + qr[10] = shift_r[1]; + qr[11] = shift_r[2]; + + qr[12] = spatial_metric_r[0][0]; + qr[13] = spatial_metric_r[0][1]; + qr[14] = spatial_metric_r[0][2]; + qr[15] = spatial_metric_r[1][0]; + qr[16] = spatial_metric_r[1][1]; + qr[17] = spatial_metric_r[1][2]; + qr[18] = spatial_metric_r[2][0]; + qr[19] = spatial_metric_r[2][1]; + qr[20] = spatial_metric_r[2][2]; qr[21] = 1.0; qr[22] = 0.0; - qr[23] = x + 0.5; qr[24] = y; qr[25] = 0.0; + qr[23] = x + 0.5; + qr[24] = y; + qr[25] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[6], waves[6 * 26], waves_local[6 * 26]; @@ -798,13 +886,21 @@ test_gr_maxwell_waves_kerr_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[26], amdq_local[26]; - gkyl_wv_eqn_qfluct(gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_maxwell, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_maxwell, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26]); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26] + ); } double apdq[26], amdq[26]; @@ -820,11 +916,11 @@ test_gr_maxwell_waves_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_maxwell, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 26; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } } - + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric_l[i]); gkyl_free(spatial_metric_r[i]); @@ -835,17 +931,17 @@ test_gr_maxwell_waves_kerr_ho() gkyl_free(shift_r); } } - + gkyl_wv_eqn_release(gr_maxwell); gkyl_gr_spacetime_release(spacetime); } TEST_LIST = { - { "gr_maxwell_basic_minkowski_ho", test_gr_maxwell_basic_minkowski_ho }, - { "gr_maxwell_basic_schwarzschild_ho", test_gr_maxwell_basic_schwarzschild_ho }, - { "gr_maxwell_basic_kerr_ho", test_gr_maxwell_basic_kerr_ho }, - { "gr_maxwell_waves_minkowski_ho", test_gr_maxwell_waves_minkowski_ho }, - { "gr_maxwell_waves_schwarzschild_ho", test_gr_maxwell_waves_schwarzschild_ho }, - { "gr_maxwell_waves_kerr_ho", test_gr_maxwell_waves_kerr_ho }, - { NULL, NULL }, + {"gr_maxwell_basic_minkowski_ho", test_gr_maxwell_basic_minkowski_ho}, + {"gr_maxwell_basic_schwarzschild_ho", test_gr_maxwell_basic_schwarzschild_ho}, + {"gr_maxwell_basic_kerr_ho", test_gr_maxwell_basic_kerr_ho}, + {"gr_maxwell_waves_minkowski_ho", test_gr_maxwell_waves_minkowski_ho}, + {"gr_maxwell_waves_schwarzschild_ho", test_gr_maxwell_waves_schwarzschild_ho}, + {"gr_maxwell_waves_kerr_ho", test_gr_maxwell_waves_kerr_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_gr_maxwell_tetrad.c b/moments/unit/ctest_wv_gr_maxwell_tetrad.c index 6e5d6fec75..50a39a109f 100644 --- a/moments/unit/ctest_wv_gr_maxwell_tetrad.c +++ b/moments/unit/ctest_wv_gr_maxwell_tetrad.c @@ -6,17 +6,18 @@ #include #include -void -test_gr_maxwell_tetrad_basic_minkowski_ho() +void test_gr_maxwell_tetrad_basic_minkowski_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new( + light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_maxwell_tetrad->num_equations == 26 ); - TEST_CHECK( gr_maxwell_tetrad->num_waves == 6 ); + TEST_CHECK(gr_maxwell_tetrad->num_equations == 26); + TEST_CHECK(gr_maxwell_tetrad->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -30,7 +31,7 @@ test_gr_maxwell_tetrad_basic_minkowski_ho() double lapse; double *shift = gkyl_malloc(sizeof(double[3])); - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -41,21 +42,36 @@ test_gr_maxwell_tetrad_basic_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); double q[26]; - q[0] = Dx; q[1] = Dy; q[2] = Dz; - q[3] = Bx; q[4] = By; q[5] = Bz; - q[6] = phi; q[7] = psi; + q[0] = Dx; + q[1] = Dy; + q[2] = Dz; + q[3] = Bx; + q[4] = By; + q[5] = Bz; + q[6] = phi; + q[7] = psi; q[8] = lapse; - q[9] = shift[0]; q[10] = shift[1]; q[11] = shift[2]; - - q[12] = spatial_metric[0][0]; q[13] = spatial_metric[0][1]; q[14] = spatial_metric[0][2]; - q[15] = spatial_metric[1][0]; q[16] = spatial_metric[1][1]; q[17] = spatial_metric[1][2]; - q[18] = spatial_metric[2][0]; q[19] = spatial_metric[2][1]; q[20] = spatial_metric[2][2]; + q[9] = shift[0]; + q[10] = shift[1]; + q[11] = shift[2]; + + q[12] = spatial_metric[0][0]; + q[13] = spatial_metric[0][1]; + q[14] = spatial_metric[0][2]; + q[15] = spatial_metric[1][0]; + q[16] = spatial_metric[1][1]; + q[17] = spatial_metric[1][2]; + q[18] = spatial_metric[2][0]; + q[19] = spatial_metric[2][1]; + q[20] = spatial_metric[2][2]; q[21] = 1.0; q[22] = 0.0; - q[23] = x; q[24] = y; q[25] = 0.0; + q[23] = x; + q[24] = y; + q[25] = 0.0; double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -66,41 +82,38 @@ test_gr_maxwell_tetrad_basic_minkowski_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][8] = { - { e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {-(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[26], flux_local_sr[26], flux_local_gr[26], flux[26]; for (int d = 0; d < 3; d++) { - gr_maxwell_tetrad->rotate_to_local_func(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], q, q_local); + gr_maxwell_tetrad->rotate_to_local_func( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_gr_maxwell_tetrad_flux(light_speed, e_fact, b_fact, q_local, flux_local_sr); - gkyl_gr_maxwell_tetrad_flux_correction(light_speed, e_fact, b_fact, q_local, flux_local_sr, flux_local_gr); - gr_maxwell_tetrad->rotate_to_global_func(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gkyl_gr_maxwell_tetrad_flux_correction( + light_speed, e_fact, b_fact, q_local, flux_local_sr, flux_local_gr + ); + gr_maxwell_tetrad->rotate_to_global_func( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-13) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-13)); } } @@ -110,7 +123,7 @@ test_gr_maxwell_tetrad_basic_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[26], q1[26]; @@ -118,7 +131,7 @@ test_gr_maxwell_tetrad_basic_minkowski_ho() gr_maxwell_tetrad->riem_to_cons(gr_maxwell_tetrad, q_local, w1, q1); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } @@ -134,17 +147,18 @@ test_gr_maxwell_tetrad_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_maxwell_tetrad_basic_schwarzschild_ho() +void test_gr_maxwell_tetrad_basic_schwarzschild_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new( + light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_maxwell_tetrad->num_equations == 26 ); - TEST_CHECK( gr_maxwell_tetrad->num_waves == 6 ); + TEST_CHECK(gr_maxwell_tetrad->num_equations == 26); + TEST_CHECK(gr_maxwell_tetrad->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -159,7 +173,7 @@ test_gr_maxwell_tetrad_basic_schwarzschild_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -172,21 +186,36 @@ test_gr_maxwell_tetrad_basic_schwarzschild_ho() if (!in_excision_region) { double q[26]; - q[0] = Dx; q[1] = Dy; q[2] = Dz; - q[3] = Bx; q[4] = By; q[5] = Bz; - q[6] = phi; q[7] = psi; + q[0] = Dx; + q[1] = Dy; + q[2] = Dz; + q[3] = Bx; + q[4] = By; + q[5] = Bz; + q[6] = phi; + q[7] = psi; q[8] = lapse; - q[9] = shift[0]; q[10] = shift[1]; q[11] = shift[2]; - - q[12] = spatial_metric[0][0]; q[13] = spatial_metric[0][1]; q[14] = spatial_metric[0][2]; - q[15] = spatial_metric[1][0]; q[16] = spatial_metric[1][1]; q[17] = spatial_metric[1][2]; - q[18] = spatial_metric[2][0]; q[19] = spatial_metric[2][1]; q[20] = spatial_metric[2][2]; + q[9] = shift[0]; + q[10] = shift[1]; + q[11] = shift[2]; + + q[12] = spatial_metric[0][0]; + q[13] = spatial_metric[0][1]; + q[14] = spatial_metric[0][2]; + q[15] = spatial_metric[1][0]; + q[16] = spatial_metric[1][1]; + q[17] = spatial_metric[1][2]; + q[18] = spatial_metric[2][0]; + q[19] = spatial_metric[2][1]; + q[20] = spatial_metric[2][2]; q[21] = 1.0; q[22] = 0.0; - q[23] = x; q[24] = y; q[25] = 0.0; + q[23] = x; + q[24] = y; + q[25] = 0.0; double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -197,41 +226,38 @@ test_gr_maxwell_tetrad_basic_schwarzschild_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][8] = { - { e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {-(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[26], flux_local_sr[26], flux_local_gr[26], flux[26]; for (int d = 0; d < 3; d++) { - gr_maxwell_tetrad->rotate_to_local_func(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], q, q_local); + gr_maxwell_tetrad->rotate_to_local_func( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_gr_maxwell_tetrad_flux(light_speed, e_fact, b_fact, q_local, flux_local_sr); - gkyl_gr_maxwell_tetrad_flux_correction(light_speed, e_fact, b_fact, q_local, flux_local_sr, flux_local_gr); - gr_maxwell_tetrad->rotate_to_global_func(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gkyl_gr_maxwell_tetrad_flux_correction( + light_speed, e_fact, b_fact, q_local, flux_local_sr, flux_local_gr + ); + gr_maxwell_tetrad->rotate_to_global_func( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-13) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-13)); } } @@ -241,7 +267,7 @@ test_gr_maxwell_tetrad_basic_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[26], q1[26]; @@ -249,7 +275,7 @@ test_gr_maxwell_tetrad_basic_schwarzschild_ho() gr_maxwell_tetrad->riem_to_cons(gr_maxwell_tetrad, q_local, w1, q1); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -266,17 +292,18 @@ test_gr_maxwell_tetrad_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_maxwell_tetrad_basic_kerr_ho() +void test_gr_maxwell_tetrad_basic_kerr_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new( + light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_maxwell_tetrad->num_equations == 26 ); - TEST_CHECK( gr_maxwell_tetrad->num_waves == 6 ); + TEST_CHECK(gr_maxwell_tetrad->num_equations == 26); + TEST_CHECK(gr_maxwell_tetrad->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -291,7 +318,7 @@ test_gr_maxwell_tetrad_basic_kerr_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -304,21 +331,36 @@ test_gr_maxwell_tetrad_basic_kerr_ho() if (!in_excision_region) { double q[26]; - q[0] = Dx; q[1] = Dy; q[2] = Dz; - q[3] = Bx; q[4] = By; q[5] = Bz; - q[6] = phi; q[7] = psi; + q[0] = Dx; + q[1] = Dy; + q[2] = Dz; + q[3] = Bx; + q[4] = By; + q[5] = Bz; + q[6] = phi; + q[7] = psi; q[8] = lapse; - q[9] = shift[0]; q[10] = shift[1]; q[11] = shift[2]; - - q[12] = spatial_metric[0][0]; q[13] = spatial_metric[0][1]; q[14] = spatial_metric[0][2]; - q[15] = spatial_metric[1][0]; q[16] = spatial_metric[1][1]; q[17] = spatial_metric[1][2]; - q[18] = spatial_metric[2][0]; q[19] = spatial_metric[2][1]; q[20] = spatial_metric[2][2]; + q[9] = shift[0]; + q[10] = shift[1]; + q[11] = shift[2]; + + q[12] = spatial_metric[0][0]; + q[13] = spatial_metric[0][1]; + q[14] = spatial_metric[0][2]; + q[15] = spatial_metric[1][0]; + q[16] = spatial_metric[1][1]; + q[17] = spatial_metric[1][2]; + q[18] = spatial_metric[2][0]; + q[19] = spatial_metric[2][1]; + q[20] = spatial_metric[2][2]; q[21] = 1.0; q[22] = 0.0; - q[23] = x; q[24] = y; q[25] = 0.0; + q[23] = x; + q[24] = y; + q[25] = 0.0; double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -329,41 +371,38 @@ test_gr_maxwell_tetrad_basic_kerr_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][8] = { - { e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {-(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[26], flux_local_sr[26], flux_local_gr[26], flux[26]; for (int d = 0; d < 3; d++) { - gr_maxwell_tetrad->rotate_to_local_func(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], q, q_local); + gr_maxwell_tetrad->rotate_to_local_func( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_gr_maxwell_tetrad_flux(light_speed, e_fact, b_fact, q_local, flux_local_sr); - gkyl_gr_maxwell_tetrad_flux_correction(light_speed, e_fact, b_fact, q_local, flux_local_sr, flux_local_gr); - gr_maxwell_tetrad->rotate_to_global_func(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gkyl_gr_maxwell_tetrad_flux_correction( + light_speed, e_fact, b_fact, q_local, flux_local_sr, flux_local_gr + ); + gr_maxwell_tetrad->rotate_to_global_func( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-13) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-13)); } } @@ -373,7 +412,7 @@ test_gr_maxwell_tetrad_basic_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[26], q1[26]; @@ -381,7 +420,7 @@ test_gr_maxwell_tetrad_basic_kerr_ho() gr_maxwell_tetrad->riem_to_cons(gr_maxwell_tetrad, q_local, w1, q1); for (int i = 0; i < 8; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -398,14 +437,15 @@ test_gr_maxwell_tetrad_basic_kerr_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_maxwell_tetrad_waves_minkowski_ho() +void test_gr_maxwell_tetrad_waves_minkowski_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new( + light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -424,8 +464,8 @@ test_gr_maxwell_tetrad_waves_minkowski_ho() double *shift_l = gkyl_malloc(sizeof(double[3])); double *shift_r = gkyl_malloc(sizeof(double[3])); - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -438,57 +478,75 @@ test_gr_maxwell_tetrad_waves_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - + double ql[26], qr[26]; - ql[0] = Dx_l; ql[1] = Dy_l; ql[2] = Dz_l; - ql[3] = Bx_l; ql[4] = By_l; ql[5] = Bz_l; - ql[6] = phi_l; ql[7] = psi_l; + ql[0] = Dx_l; + ql[1] = Dy_l; + ql[2] = Dz_l; + ql[3] = Bx_l; + ql[4] = By_l; + ql[5] = Bz_l; + ql[6] = phi_l; + ql[7] = psi_l; ql[8] = lapse_l; - ql[9] = shift_l[0]; ql[10] = shift_l[1]; ql[11] = shift_l[2]; - - ql[12] = spatial_metric_l[0][0]; ql[13] = spatial_metric_l[0][1]; ql[14] = spatial_metric_l[0][2]; - ql[15] = spatial_metric_l[1][0]; ql[16] = spatial_metric_l[1][1]; ql[17] = spatial_metric_l[1][2]; - ql[18] = spatial_metric_l[2][0]; ql[19] = spatial_metric_l[2][1]; ql[20] = spatial_metric_l[2][2]; + ql[9] = shift_l[0]; + ql[10] = shift_l[1]; + ql[11] = shift_l[2]; + + ql[12] = spatial_metric_l[0][0]; + ql[13] = spatial_metric_l[0][1]; + ql[14] = spatial_metric_l[0][2]; + ql[15] = spatial_metric_l[1][0]; + ql[16] = spatial_metric_l[1][1]; + ql[17] = spatial_metric_l[1][2]; + ql[18] = spatial_metric_l[2][0]; + ql[19] = spatial_metric_l[2][1]; + ql[20] = spatial_metric_l[2][2]; ql[21] = 1.0; ql[22] = 0.0; - ql[23] = x - 0.5; ql[24] = y; ql[25] = 0.0; - - qr[0] = Dx_r; qr[1] = Dy_r; qr[2] = Dz_r; - qr[3] = Bx_r; qr[4] = By_r; qr[5] = Bz_r; - qr[6] = phi_r; qr[7] = psi_r; + ql[23] = x - 0.5; + ql[24] = y; + ql[25] = 0.0; + + qr[0] = Dx_r; + qr[1] = Dy_r; + qr[2] = Dz_r; + qr[3] = Bx_r; + qr[4] = By_r; + qr[5] = Bz_r; + qr[6] = phi_r; + qr[7] = psi_r; qr[8] = lapse_r; - qr[9] = shift_r[0]; qr[10] = shift_r[1]; qr[11] = shift_r[2]; - - qr[12] = spatial_metric_r[0][0]; qr[13] = spatial_metric_r[0][1]; qr[14] = spatial_metric_r[0][2]; - qr[15] = spatial_metric_r[1][0]; qr[16] = spatial_metric_r[1][1]; qr[17] = spatial_metric_r[1][2]; - qr[18] = spatial_metric_r[2][0]; qr[19] = spatial_metric_r[2][1]; qr[20] = spatial_metric_r[2][2]; + qr[9] = shift_r[0]; + qr[10] = shift_r[1]; + qr[11] = shift_r[2]; + + qr[12] = spatial_metric_r[0][0]; + qr[13] = spatial_metric_r[0][1]; + qr[14] = spatial_metric_r[0][2]; + qr[15] = spatial_metric_r[1][0]; + qr[16] = spatial_metric_r[1][1]; + qr[17] = spatial_metric_r[1][2]; + qr[18] = spatial_metric_r[2][0]; + qr[19] = spatial_metric_r[2][1]; + qr[20] = spatial_metric_r[2][2]; qr[21] = 1.0; qr[22] = 0.0; - qr[23] = x + 0.5; qr[24] = y; qr[25] = 0.0; + qr[23] = x + 0.5; + qr[24] = y; + qr[25] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[6], waves[6 * 26], waves_local[6 * 26]; @@ -502,13 +560,21 @@ test_gr_maxwell_tetrad_waves_minkowski_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[26], amdq_local[26]; - gkyl_wv_eqn_qfluct(gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26]); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26] + ); } double apdq[26], amdq[26]; @@ -520,18 +586,22 @@ test_gr_maxwell_tetrad_waves_minkowski_ho() gkyl_gr_maxwell_tetrad_flux(light_speed, e_fact, b_fact, qr_local, fr_local_sr); double fl_local_gr[26], fr_local_gr[26]; - gkyl_gr_maxwell_tetrad_flux_correction(light_speed, e_fact, b_fact, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_maxwell_tetrad_flux_correction(light_speed, e_fact, b_fact, qr_local, fr_local_sr, fr_local_gr); + gkyl_gr_maxwell_tetrad_flux_correction( + light_speed, e_fact, b_fact, ql_local, fl_local_sr, fl_local_gr + ); + gkyl_gr_maxwell_tetrad_flux_correction( + light_speed, e_fact, b_fact, qr_local, fr_local_sr, fr_local_gr + ); double fl[26], fr[26]; gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); for (int i = 0; i < 26; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } - + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric_l[i]); gkyl_free(spatial_metric_r[i]); @@ -542,19 +612,20 @@ test_gr_maxwell_tetrad_waves_minkowski_ho() gkyl_free(shift_r); } } - + gkyl_wv_eqn_release(gr_maxwell_tetrad); gkyl_gr_spacetime_release(spacetime); } -void -test_gr_maxwell_tetrad_waves_schwarzschild_ho() +void test_gr_maxwell_tetrad_waves_schwarzschild_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new( + light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -574,8 +645,8 @@ test_gr_maxwell_tetrad_waves_schwarzschild_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -593,55 +664,73 @@ test_gr_maxwell_tetrad_waves_schwarzschild_ho() if (!in_excision_region_l && !in_excision_region_r) { double ql[26], qr[26]; - ql[0] = Dx_l; ql[1] = Dy_l; ql[2] = Dz_l; - ql[3] = Bx_l; ql[4] = By_l; ql[5] = Bz_l; - ql[6] = phi_l; ql[7] = psi_l; + ql[0] = Dx_l; + ql[1] = Dy_l; + ql[2] = Dz_l; + ql[3] = Bx_l; + ql[4] = By_l; + ql[5] = Bz_l; + ql[6] = phi_l; + ql[7] = psi_l; ql[8] = lapse_l; - ql[9] = shift_l[0]; ql[10] = shift_l[1]; ql[11] = shift_l[2]; - - ql[12] = spatial_metric_l[0][0]; ql[13] = spatial_metric_l[0][1]; ql[14] = spatial_metric_l[0][2]; - ql[15] = spatial_metric_l[1][0]; ql[16] = spatial_metric_l[1][1]; ql[17] = spatial_metric_l[1][2]; - ql[18] = spatial_metric_l[2][0]; ql[19] = spatial_metric_l[2][1]; ql[20] = spatial_metric_l[2][2]; + ql[9] = shift_l[0]; + ql[10] = shift_l[1]; + ql[11] = shift_l[2]; + + ql[12] = spatial_metric_l[0][0]; + ql[13] = spatial_metric_l[0][1]; + ql[14] = spatial_metric_l[0][2]; + ql[15] = spatial_metric_l[1][0]; + ql[16] = spatial_metric_l[1][1]; + ql[17] = spatial_metric_l[1][2]; + ql[18] = spatial_metric_l[2][0]; + ql[19] = spatial_metric_l[2][1]; + ql[20] = spatial_metric_l[2][2]; ql[21] = 1.0; ql[22] = 0.0; - ql[23] = x - 0.5; ql[24] = y; ql[25] = 0.0; - - qr[0] = Dx_r; qr[1] = Dy_r; qr[2] = Dz_r; - qr[3] = Bx_r; qr[4] = By_r; qr[5] = Bz_r; - qr[6] = phi_r; qr[7] = psi_r; + ql[23] = x - 0.5; + ql[24] = y; + ql[25] = 0.0; + + qr[0] = Dx_r; + qr[1] = Dy_r; + qr[2] = Dz_r; + qr[3] = Bx_r; + qr[4] = By_r; + qr[5] = Bz_r; + qr[6] = phi_r; + qr[7] = psi_r; qr[8] = lapse_r; - qr[9] = shift_r[0]; qr[10] = shift_r[1]; qr[11] = shift_r[2]; - - qr[12] = spatial_metric_r[0][0]; qr[13] = spatial_metric_r[0][1]; qr[14] = spatial_metric_r[0][2]; - qr[15] = spatial_metric_r[1][0]; qr[16] = spatial_metric_r[1][1]; qr[17] = spatial_metric_r[1][2]; - qr[18] = spatial_metric_r[2][0]; qr[19] = spatial_metric_r[2][1]; qr[20] = spatial_metric_r[2][2]; + qr[9] = shift_r[0]; + qr[10] = shift_r[1]; + qr[11] = shift_r[2]; + + qr[12] = spatial_metric_r[0][0]; + qr[13] = spatial_metric_r[0][1]; + qr[14] = spatial_metric_r[0][2]; + qr[15] = spatial_metric_r[1][0]; + qr[16] = spatial_metric_r[1][1]; + qr[17] = spatial_metric_r[1][2]; + qr[18] = spatial_metric_r[2][0]; + qr[19] = spatial_metric_r[2][1]; + qr[20] = spatial_metric_r[2][2]; qr[21] = 1.0; qr[22] = 0.0; - qr[23] = x + 0.5; qr[24] = y; qr[25] = 0.0; + qr[23] = x + 0.5; + qr[24] = y; + qr[25] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[6], waves[6 * 26], waves_local[6 * 26]; @@ -655,37 +744,57 @@ test_gr_maxwell_tetrad_waves_schwarzschild_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[26], amdq_local[26]; - gkyl_wv_eqn_qfluct(gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26]); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26] + ); } double apdq[26], amdq[26]; - gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); double fl_local_sr[26], fr_local_sr[26]; gkyl_gr_maxwell_tetrad_flux(light_speed, e_fact, b_fact, ql_local, fl_local_sr); gkyl_gr_maxwell_tetrad_flux(light_speed, e_fact, b_fact, qr_local, fr_local_sr); double fl_local_gr[26], fr_local_gr[26]; - gkyl_gr_maxwell_tetrad_flux_correction(light_speed, e_fact, b_fact, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_maxwell_tetrad_flux_correction(light_speed, e_fact, b_fact, qr_local, fr_local_sr, fr_local_gr); + gkyl_gr_maxwell_tetrad_flux_correction( + light_speed, e_fact, b_fact, ql_local, fl_local_sr, fl_local_gr + ); + gkyl_gr_maxwell_tetrad_flux_correction( + light_speed, e_fact, b_fact, qr_local, fr_local_sr, fr_local_gr + ); double fl[26], fr[26]; - gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); - gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl + ); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr + ); for (int i = 0; i < 26; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } - + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric_l[i]); gkyl_free(spatial_metric_r[i]); @@ -696,19 +805,20 @@ test_gr_maxwell_tetrad_waves_schwarzschild_ho() gkyl_free(shift_r); } } - + gkyl_wv_eqn_release(gr_maxwell_tetrad); gkyl_gr_spacetime_release(spacetime); } -void -test_gr_maxwell_tetrad_waves_kerr_ho() +void test_gr_maxwell_tetrad_waves_kerr_ho() { double light_speed = 1.0; double e_fact = 0.0; double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new(light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_maxwell_tetrad = gkyl_wv_gr_maxwell_tetrad_new( + light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -728,8 +838,8 @@ test_gr_maxwell_tetrad_waves_kerr_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -747,55 +857,73 @@ test_gr_maxwell_tetrad_waves_kerr_ho() if (!in_excision_region_l && !in_excision_region_r) { double ql[26], qr[26]; - ql[0] = Dx_l; ql[1] = Dy_l; ql[2] = Dz_l; - ql[3] = Bx_l; ql[4] = By_l; ql[5] = Bz_l; - ql[6] = phi_l; ql[7] = psi_l; + ql[0] = Dx_l; + ql[1] = Dy_l; + ql[2] = Dz_l; + ql[3] = Bx_l; + ql[4] = By_l; + ql[5] = Bz_l; + ql[6] = phi_l; + ql[7] = psi_l; ql[8] = lapse_l; - ql[9] = shift_l[0]; ql[10] = shift_l[1]; ql[11] = shift_l[2]; - - ql[12] = spatial_metric_l[0][0]; ql[13] = spatial_metric_l[0][1]; ql[14] = spatial_metric_l[0][2]; - ql[15] = spatial_metric_l[1][0]; ql[16] = spatial_metric_l[1][1]; ql[17] = spatial_metric_l[1][2]; - ql[18] = spatial_metric_l[2][0]; ql[19] = spatial_metric_l[2][1]; ql[20] = spatial_metric_l[2][2]; + ql[9] = shift_l[0]; + ql[10] = shift_l[1]; + ql[11] = shift_l[2]; + + ql[12] = spatial_metric_l[0][0]; + ql[13] = spatial_metric_l[0][1]; + ql[14] = spatial_metric_l[0][2]; + ql[15] = spatial_metric_l[1][0]; + ql[16] = spatial_metric_l[1][1]; + ql[17] = spatial_metric_l[1][2]; + ql[18] = spatial_metric_l[2][0]; + ql[19] = spatial_metric_l[2][1]; + ql[20] = spatial_metric_l[2][2]; ql[21] = 1.0; ql[22] = 0.0; - ql[23] = x - 0.5; ql[24] = y; ql[25] = 0.0; - - qr[0] = Dx_r; qr[1] = Dy_r; qr[2] = Dz_r; - qr[3] = Bx_r; qr[4] = By_r; qr[5] = Bz_r; - qr[6] = phi_r; qr[7] = psi_r; + ql[23] = x - 0.5; + ql[24] = y; + ql[25] = 0.0; + + qr[0] = Dx_r; + qr[1] = Dy_r; + qr[2] = Dz_r; + qr[3] = Bx_r; + qr[4] = By_r; + qr[5] = Bz_r; + qr[6] = phi_r; + qr[7] = psi_r; qr[8] = lapse_r; - qr[9] = shift_r[0]; qr[10] = shift_r[1]; qr[11] = shift_r[2]; - - qr[12] = spatial_metric_r[0][0]; qr[13] = spatial_metric_r[0][1]; qr[14] = spatial_metric_r[0][2]; - qr[15] = spatial_metric_r[1][0]; qr[16] = spatial_metric_r[1][1]; qr[17] = spatial_metric_r[1][2]; - qr[18] = spatial_metric_r[2][0]; qr[19] = spatial_metric_r[2][1]; qr[20] = spatial_metric_r[2][2]; + qr[9] = shift_r[0]; + qr[10] = shift_r[1]; + qr[11] = shift_r[2]; + + qr[12] = spatial_metric_r[0][0]; + qr[13] = spatial_metric_r[0][1]; + qr[14] = spatial_metric_r[0][2]; + qr[15] = spatial_metric_r[1][0]; + qr[16] = spatial_metric_r[1][1]; + qr[17] = spatial_metric_r[1][2]; + qr[18] = spatial_metric_r[2][0]; + qr[19] = spatial_metric_r[2][1]; + qr[20] = spatial_metric_r[2][2]; qr[21] = 1.0; qr[22] = 0.0; - qr[23] = x + 0.5; qr[24] = y; qr[25] = 0.0; + qr[23] = x + 0.5; + qr[24] = y; + qr[25] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[6], waves[6 * 26], waves_local[6 * 26]; @@ -809,37 +937,57 @@ test_gr_maxwell_tetrad_waves_kerr_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[26], amdq_local[26]; - gkyl_wv_eqn_qfluct(gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_maxwell_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26]); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 26], &waves[i * 26] + ); } double apdq[26], amdq[26]; - gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); double fl_local_sr[26], fr_local_sr[26]; gkyl_gr_maxwell_tetrad_flux(light_speed, e_fact, b_fact, ql_local, fl_local_sr); gkyl_gr_maxwell_tetrad_flux(light_speed, e_fact, b_fact, qr_local, fr_local_sr); double fl_local_gr[26], fr_local_gr[26]; - gkyl_gr_maxwell_tetrad_flux_correction(light_speed, e_fact, b_fact, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_maxwell_tetrad_flux_correction(light_speed, e_fact, b_fact, qr_local, fr_local_sr, fr_local_gr); + gkyl_gr_maxwell_tetrad_flux_correction( + light_speed, e_fact, b_fact, ql_local, fl_local_sr, fl_local_gr + ); + gkyl_gr_maxwell_tetrad_flux_correction( + light_speed, e_fact, b_fact, qr_local, fr_local_sr, fr_local_gr + ); double fl[26], fr[26]; - gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); - gkyl_wv_eqn_rotate_to_global(gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl + ); + gkyl_wv_eqn_rotate_to_global( + gr_maxwell_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr + ); for (int i = 0; i < 26; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } } - + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric_l[i]); gkyl_free(spatial_metric_r[i]); @@ -850,17 +998,17 @@ test_gr_maxwell_tetrad_waves_kerr_ho() gkyl_free(shift_r); } } - + gkyl_wv_eqn_release(gr_maxwell_tetrad); gkyl_gr_spacetime_release(spacetime); } TEST_LIST = { - { "gr_maxwell_tetrad_basic_minkowski_ho", test_gr_maxwell_tetrad_basic_minkowski_ho }, - { "gr_maxwell_tetrad_basic_schwarzschild_ho", test_gr_maxwell_tetrad_basic_schwarzschild_ho }, - { "gr_maxwell_tetrad_basic_kerr_ho", test_gr_maxwell_tetrad_basic_kerr_ho }, - { "gr_maxwell_tetrad_waves_minkowski_ho", test_gr_maxwell_tetrad_waves_minkowski_ho }, - { "gr_maxwell_tetrad_waves_schwarzschild_ho", test_gr_maxwell_tetrad_waves_schwarzschild_ho }, - { "gr_maxwell_tetrad_waves_kerr_ho", test_gr_maxwell_tetrad_waves_kerr_ho }, - { NULL, NULL }, + {"gr_maxwell_tetrad_basic_minkowski_ho", test_gr_maxwell_tetrad_basic_minkowski_ho}, + {"gr_maxwell_tetrad_basic_schwarzschild_ho", test_gr_maxwell_tetrad_basic_schwarzschild_ho}, + {"gr_maxwell_tetrad_basic_kerr_ho", test_gr_maxwell_tetrad_basic_kerr_ho}, + {"gr_maxwell_tetrad_waves_minkowski_ho", test_gr_maxwell_tetrad_waves_minkowski_ho}, + {"gr_maxwell_tetrad_waves_schwarzschild_ho", test_gr_maxwell_tetrad_waves_schwarzschild_ho}, + {"gr_maxwell_tetrad_waves_kerr_ho", test_gr_maxwell_tetrad_waves_kerr_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_gr_medium.c b/moments/unit/ctest_wv_gr_medium.c index 66fc1c2c04..6f20d204e7 100644 --- a/moments/unit/ctest_wv_gr_medium.c +++ b/moments/unit/ctest_wv_gr_medium.c @@ -4,15 +4,14 @@ #include #include -void -test_gr_medium_basic_ho() +void test_gr_medium_basic_ho() { double gas_gamma = 5.0 / 3.0; double kappa = 8.0 * M_PI; struct gkyl_wv_eqn *gr_medium = gkyl_wv_gr_medium_new(gas_gamma, kappa, false); - TEST_CHECK( gr_medium->num_equations == 15 ); - TEST_CHECK( gr_medium->num_waves == 2 ); + TEST_CHECK(gr_medium->num_equations == 15); + TEST_CHECK(gr_medium->num_waves == 2); double exp_2a = 0.1; double a_dt = 0.2, a_dx = 0.3; @@ -27,63 +26,66 @@ test_gr_medium_basic_ho() double p = (gas_gamma - 1.0) * rho; double W = 1.0 / sqrt(1.0 - (vel * vel)); - double q[15] = { exp_2a, a_dt, a_dx, b_dt, b_dx, c_dt, c_dx, a_dt_dx, a_dx_dx, b_dt_dx, b_dx_dx, c_dt_dx, c_dx_dx, - ((rho + p) * (W * W)) - p, (rho + p) * vel * (W * W) }; + double q[15] = { + exp_2a, + a_dt, + a_dx, + b_dt, + b_dx, + c_dt, + c_dx, + a_dt_dx, + a_dx_dx, + b_dt_dx, + b_dx_dx, + c_dt_dx, + c_dx_dx, + ((rho + p) * (W * W)) - p, + (rho + p) * vel * (W * W) + }; double prims[15]; gkyl_gr_medium_prim_vars(gas_gamma, q, prims); - TEST_CHECK( gkyl_compare(prims[0], exp_2a, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[1], a_dt, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[2], a_dx, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[3], b_dt, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[4], b_dx, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[5], c_dt, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[6], c_dx, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[7], a_dt_dx, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[8], a_dx_dx, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[9], b_dt_dx, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[10], b_dx_dx, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[11], c_dt_dx, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[12], c_dx_dx, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[13], rho, 1e-14) ); - TEST_CHECK( gkyl_compare(prims[14], vel, 1e-14) ); + TEST_CHECK(gkyl_compare(prims[0], exp_2a, 1e-14)); + TEST_CHECK(gkyl_compare(prims[1], a_dt, 1e-14)); + TEST_CHECK(gkyl_compare(prims[2], a_dx, 1e-14)); + TEST_CHECK(gkyl_compare(prims[3], b_dt, 1e-14)); + TEST_CHECK(gkyl_compare(prims[4], b_dx, 1e-14)); + TEST_CHECK(gkyl_compare(prims[5], c_dt, 1e-14)); + TEST_CHECK(gkyl_compare(prims[6], c_dx, 1e-14)); + TEST_CHECK(gkyl_compare(prims[7], a_dt_dx, 1e-14)); + TEST_CHECK(gkyl_compare(prims[8], a_dx_dx, 1e-14)); + TEST_CHECK(gkyl_compare(prims[9], b_dt_dx, 1e-14)); + TEST_CHECK(gkyl_compare(prims[10], b_dx_dx, 1e-14)); + TEST_CHECK(gkyl_compare(prims[11], c_dt_dx, 1e-14)); + TEST_CHECK(gkyl_compare(prims[12], c_dx_dx, 1e-14)); + TEST_CHECK(gkyl_compare(prims[13], rho, 1e-14)); + TEST_CHECK(gkyl_compare(prims[14], vel, 1e-14)); double Etot = ((rho + p) * (W * W)) - p; double mom = (rho + p) * vel * (W * W); double fluxes[3][15] = { - { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -a_dx_dx + (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))), -a_dt_dx, - -b_dx_dx - (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))), -b_dt_dx, - -c_dx_dx, -c_dt_dx, mom, (mom * vel) + p }, - { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + -b_dx_dx - (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))), -b_dt_dx, -c_dx_dx, -c_dt_dx, + mom, (mom * vel) + p}, + {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -a_dx_dx + (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))), -a_dt_dx, - -b_dx_dx - (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))), -b_dt_dx, - -c_dx_dx, -c_dt_dx, mom, (mom * vel) + p }, - { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + -b_dx_dx - (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))), -b_dt_dx, -c_dx_dx, -c_dt_dx, + mom, (mom * vel) + p}, + {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -a_dx_dx + (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))), -a_dt_dx, - -b_dx_dx - (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))), -b_dt_dx, - -c_dx_dx, -c_dt_dx, mom, (mom * vel) + p }, + -b_dx_dx - (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))), -b_dt_dx, -c_dx_dx, -c_dt_dx, + mom, (mom * vel) + p} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[15], flux_local[15], flux[15]; for (int d = 0; d < 3; d++) { @@ -92,7 +94,7 @@ test_gr_medium_basic_ho() gr_medium->rotate_to_global_func(gr_medium, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 15; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-14) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-14)); } } @@ -102,7 +104,7 @@ test_gr_medium_basic_ho() gkyl_wv_eqn_rotate_to_global(gr_medium, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 15; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-14) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-14)); } double w1[15], q1[15]; @@ -110,15 +112,14 @@ test_gr_medium_basic_ho() gr_medium->riem_to_cons(gr_medium, q_local, w1, q1); for (int i = 0; i < 15; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-14) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-14)); } } gkyl_wv_eqn_release(gr_medium); } -void -test_gr_medium_waves_ho() +void test_gr_medium_waves_ho() { double gas_gamma = 5.0 / 3.0; double kappa = 8.0 * M_PI; @@ -137,8 +138,23 @@ test_gr_medium_waves_ho() double p_l = (gas_gamma - 1.0) * rho_l; double W_l = 1.0 / sqrt(1.0 - (vel_l * vel_l)); - double ql[15] = { exp_2a_l, a_dt_l, a_dx_l, b_dt_l, b_dx_l, c_dt_l, c_dx_l, a_dt_dx_l, a_dx_dx_l, b_dt_dx_l, b_dx_dx_l, c_dt_dx_l, c_dx_dx_l, - ((rho_l + p_l) * (W_l * W_l)) - p_l, (rho_l + p_l) * vel_l * (W_l * W_l) }; + double ql[15] = { + exp_2a_l, + a_dt_l, + a_dx_l, + b_dt_l, + b_dx_l, + c_dt_l, + c_dx_l, + a_dt_dx_l, + a_dx_dx_l, + b_dt_dx_l, + b_dx_dx_l, + c_dt_dx_l, + c_dx_dx_l, + ((rho_l + p_l) * (W_l * W_l)) - p_l, + (rho_l + p_l) * vel_l * (W_l * W_l) + }; double exp_2a_r = 0.07; double a_dt_r = 0.06, a_dx_r = 0.05; @@ -153,26 +169,29 @@ test_gr_medium_waves_ho() double p_r = (gas_gamma - 1.0) * rho_r; double W_r = 1.0 / sqrt(1.0 - (vel_r * vel_r)); - double qr[15] = { exp_2a_r, a_dt_r, a_dx_r, b_dt_r, b_dx_r, c_dt_r, c_dx_r, a_dt_dx_r, a_dx_dx_r, b_dt_dx_r, b_dx_dx_r, c_dt_dx_r, c_dx_dx_r, - ((rho_r + p_r) * (W_r * W_r)) - p_r, (rho_r + p_r) * vel_r * (W_r * W_r) }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double qr[15] = { + exp_2a_r, + a_dt_r, + a_dx_r, + b_dt_r, + b_dx_r, + c_dt_r, + c_dx_r, + a_dt_dx_r, + a_dx_dx_r, + b_dt_dx_r, + b_dx_dx_r, + c_dt_dx_r, + c_dx_dx_r, + ((rho_r + p_r) * (W_r * W_r)) - p_r, + (rho_r + p_r) * vel_r * (W_r * W_r) }; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 15], waves_local[2 * 15]; @@ -186,13 +205,20 @@ test_gr_medium_waves_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_medium, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_medium, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); double apdq_local[15], amdq_local[15]; - gkyl_wv_eqn_qfluct(gr_medium, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_medium, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_medium, tau1[d], tau2[d], norm[d], &waves_local[i * 15], &waves[i * 15]); + gkyl_wv_eqn_rotate_to_global( + gr_medium, tau1[d], tau2[d], norm[d], &waves_local[i * 15], &waves[i * 15] + ); } double apdq[15], amdq[15]; @@ -208,15 +234,14 @@ test_gr_medium_waves_ho() gkyl_wv_eqn_rotate_to_global(gr_medium, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 15; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); } } gkyl_wv_eqn_release(gr_medium); } -void -test_gr_medium_waves_2_ho() +void test_gr_medium_waves_2_ho() { double gas_gamma = 5.0 / 3.0; double kappa = 8.0 * M_PI; @@ -235,8 +260,23 @@ test_gr_medium_waves_2_ho() double p_l = (gas_gamma - 1.0) * rho_l; double W_l = 1.0 / sqrt(1.0 - (vel_l * vel_l)); - double ql[15] = { exp_2a_l, a_dt_l, a_dx_l, b_dt_l, b_dx_l, c_dt_l, c_dx_l, a_dt_dx_l, a_dx_dx_l, b_dt_dx_l, b_dx_dx_l, c_dt_dx_l, c_dx_dx_l, - ((rho_l + p_l) * (W_l * W_l)) - p_l, (rho_l + p_l) * vel_l * (W_l * W_l) }; + double ql[15] = { + exp_2a_l, + a_dt_l, + a_dx_l, + b_dt_l, + b_dx_l, + c_dt_l, + c_dx_l, + a_dt_dx_l, + a_dx_dx_l, + b_dt_dx_l, + b_dx_dx_l, + c_dt_dx_l, + c_dx_dx_l, + ((rho_l + p_l) * (W_l * W_l)) - p_l, + (rho_l + p_l) * vel_l * (W_l * W_l) + }; double exp_2a_r = 0.07; double a_dt_r = 0.06, a_dx_r = 0.05; @@ -251,26 +291,29 @@ test_gr_medium_waves_2_ho() double p_r = (gas_gamma - 1.0) * rho_r; double W_r = 1.0 / sqrt(1.0 - (vel_r * vel_r)); - double qr[15] = { exp_2a_r, a_dt_r, a_dx_r, b_dt_r, b_dx_r, c_dt_r, c_dx_r, a_dt_dx_r, a_dx_dx_r, b_dt_dx_r, b_dx_dx_r, c_dt_dx_r, c_dx_dx_r, - ((rho_r + p_r) * (W_r * W_r)) - p_r, (rho_r + p_r) * vel_r * (W_r * W_r) }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double qr[15] = { + exp_2a_r, + a_dt_r, + a_dx_r, + b_dt_r, + b_dx_r, + c_dt_r, + c_dx_r, + a_dt_dx_r, + a_dx_dx_r, + b_dt_dx_r, + b_dx_dx_r, + c_dt_dx_r, + c_dx_dx_r, + ((rho_r + p_r) * (W_r * W_r)) - p_r, + (rho_r + p_r) * vel_r * (W_r * W_r) }; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 15], waves_local[2 * 15]; @@ -284,13 +327,20 @@ test_gr_medium_waves_2_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_medium, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_medium, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); double apdq_local[15], amdq_local[15]; - gkyl_wv_eqn_qfluct(gr_medium, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_medium, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_medium, tau1[d], tau2[d], norm[d], &waves_local[i * 15], &waves[i * 15]); + gkyl_wv_eqn_rotate_to_global( + gr_medium, tau1[d], tau2[d], norm[d], &waves_local[i * 15], &waves[i * 15] + ); } double apdq[15], amdq[15]; @@ -306,7 +356,7 @@ test_gr_medium_waves_2_ho() gkyl_wv_eqn_rotate_to_global(gr_medium, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 15; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); } } @@ -314,8 +364,8 @@ test_gr_medium_waves_2_ho() } TEST_LIST = { - { "gr_medium_basic_ho", test_gr_medium_basic_ho }, - { "gr_medium_waves_ho", test_gr_medium_waves_ho }, - { "gr_medium_waves_2_ho", test_gr_medium_waves_2_ho }, - { NULL, NULL }, + {"gr_medium_basic_ho", test_gr_medium_basic_ho}, + {"gr_medium_waves_ho", test_gr_medium_waves_ho}, + {"gr_medium_waves_2_ho", test_gr_medium_waves_2_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_gr_mhd.c b/moments/unit/ctest_wv_gr_mhd.c index 7f1415ffe4..9a24f97411 100644 --- a/moments/unit/ctest_wv_gr_mhd.c +++ b/moments/unit/ctest_wv_gr_mhd.c @@ -6,17 +6,17 @@ #include #include -void -test_gr_mhd_basic_minkowski_ho() +void test_gr_mhd_basic_minkowski_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd = + gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_mhd->num_equations == 75 ); - TEST_CHECK( gr_mhd->num_waves == 2 ); + TEST_CHECK(gr_mhd->num_equations == 75); + TEST_CHECK(gr_mhd->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -30,25 +30,25 @@ test_gr_mhd_basic_minkowski_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -59,16 +59,28 @@ test_gr_mhd_basic_minkowski_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -80,7 +92,9 @@ test_gr_mhd_basic_minkowski_ho() double W = 1.0 / sqrt(1.0 - v_sq); double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -99,7 +113,7 @@ test_gr_mhd_basic_minkowski_ho() cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); @@ -139,7 +153,8 @@ test_gr_mhd_basic_minkowski_ho() q[1] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); q[2] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); q[3] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); - q[4] = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); + q[4] = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); q[5] = sqrt(spatial_det) * mag_x; q[6] = sqrt(spatial_det) * mag_y; @@ -147,51 +162,93 @@ test_gr_mhd_basic_minkowski_ho() q[8] = sqrt(spatial_det) * psi; q[9] = lapse; - q[10] = shift[0]; q[11] = shift[1]; q[12] = shift[2]; - - q[13] = spatial_metric[0][0]; q[14] = spatial_metric[0][1]; q[15] = spatial_metric[0][2]; - q[16] = spatial_metric[1][0]; q[17] = spatial_metric[1][1]; q[18] = spatial_metric[1][2]; - q[19] = spatial_metric[2][0]; q[20] = spatial_metric[2][1]; q[21] = spatial_metric[2][2]; - - q[22] = extrinsic_curvature[0][0]; q[23] = extrinsic_curvature[0][1]; q[24] = extrinsic_curvature[0][2]; - q[25] = extrinsic_curvature[1][0]; q[26] = extrinsic_curvature[1][1]; q[27] = extrinsic_curvature[1][2]; - q[28] = extrinsic_curvature[2][0]; q[29] = extrinsic_curvature[2][1]; q[30] = extrinsic_curvature[2][2]; + q[10] = shift[0]; + q[11] = shift[1]; + q[12] = shift[2]; + + q[13] = spatial_metric[0][0]; + q[14] = spatial_metric[0][1]; + q[15] = spatial_metric[0][2]; + q[16] = spatial_metric[1][0]; + q[17] = spatial_metric[1][1]; + q[18] = spatial_metric[1][2]; + q[19] = spatial_metric[2][0]; + q[20] = spatial_metric[2][1]; + q[21] = spatial_metric[2][2]; + + q[22] = extrinsic_curvature[0][0]; + q[23] = extrinsic_curvature[0][1]; + q[24] = extrinsic_curvature[0][2]; + q[25] = extrinsic_curvature[1][0]; + q[26] = extrinsic_curvature[1][1]; + q[27] = extrinsic_curvature[1][2]; + q[28] = extrinsic_curvature[2][0]; + q[29] = extrinsic_curvature[2][1]; + q[30] = extrinsic_curvature[2][2]; q[31] = 1.0; - q[32] = lapse_der[0]; q[33] = lapse_der[1]; q[34] = lapse_der[2]; - q[35] = shift_der[0][0]; q[36] = shift_der[0][1]; q[37] = shift_der[0][2]; - q[38] = shift_der[1][0]; q[39] = shift_der[1][1]; q[40] = shift_der[1][2]; - q[41] = shift_der[2][0]; q[42] = shift_der[2][1]; q[43] = shift_der[2][2]; - - q[44] = spatial_metric_der[0][0][0]; q[45] = spatial_metric_der[0][0][1]; q[46] = spatial_metric_der[0][0][2]; - q[47] = spatial_metric_der[0][1][0]; q[48] = spatial_metric_der[0][1][1]; q[49] = spatial_metric_der[0][1][2]; - q[50] = spatial_metric_der[0][2][0]; q[51] = spatial_metric_der[0][2][1]; q[52] = spatial_metric_der[0][2][2]; - - q[53] = spatial_metric_der[1][0][0]; q[54] = spatial_metric_der[1][0][1]; q[55] = spatial_metric_der[1][0][2]; - q[56] = spatial_metric_der[1][1][0]; q[57] = spatial_metric_der[1][1][1]; q[58] = spatial_metric_der[1][1][2]; - q[59] = spatial_metric_der[1][2][0]; q[60] = spatial_metric_der[1][2][1]; q[61] = spatial_metric_der[1][2][2]; - - q[62] = spatial_metric_der[2][0][0]; q[63] = spatial_metric_der[2][0][1]; q[64] = spatial_metric_der[2][0][2]; - q[65] = spatial_metric_der[2][1][0]; q[66] = spatial_metric_der[2][1][1]; q[67] = spatial_metric_der[2][1][2]; - q[68] = spatial_metric_der[2][2][0]; q[69] = spatial_metric_der[2][2][1]; q[70] = spatial_metric_der[2][2][2]; + q[32] = lapse_der[0]; + q[33] = lapse_der[1]; + q[34] = lapse_der[2]; + q[35] = shift_der[0][0]; + q[36] = shift_der[0][1]; + q[37] = shift_der[0][2]; + q[38] = shift_der[1][0]; + q[39] = shift_der[1][1]; + q[40] = shift_der[1][2]; + q[41] = shift_der[2][0]; + q[42] = shift_der[2][1]; + q[43] = shift_der[2][2]; + + q[44] = spatial_metric_der[0][0][0]; + q[45] = spatial_metric_der[0][0][1]; + q[46] = spatial_metric_der[0][0][2]; + q[47] = spatial_metric_der[0][1][0]; + q[48] = spatial_metric_der[0][1][1]; + q[49] = spatial_metric_der[0][1][2]; + q[50] = spatial_metric_der[0][2][0]; + q[51] = spatial_metric_der[0][2][1]; + q[52] = spatial_metric_der[0][2][2]; + + q[53] = spatial_metric_der[1][0][0]; + q[54] = spatial_metric_der[1][0][1]; + q[55] = spatial_metric_der[1][0][2]; + q[56] = spatial_metric_der[1][1][0]; + q[57] = spatial_metric_der[1][1][1]; + q[58] = spatial_metric_der[1][1][2]; + q[59] = spatial_metric_der[1][2][0]; + q[60] = spatial_metric_der[1][2][1]; + q[61] = spatial_metric_der[1][2][2]; + + q[62] = spatial_metric_der[2][0][0]; + q[63] = spatial_metric_der[2][0][1]; + q[64] = spatial_metric_der[2][0][2]; + q[65] = spatial_metric_der[2][1][0]; + q[66] = spatial_metric_der[2][1][1]; + q[67] = spatial_metric_der[2][1][2]; + q[68] = spatial_metric_der[2][2][0]; + q[69] = spatial_metric_der[2][2][1]; + q[70] = spatial_metric_der[2][2][2]; q[71] = 0.0; - q[72] = x; q[73] = y; q[74] = 0.0; + q[72] = x; + q[73] = y; + q[74] = 0.0; double prims[75]; gkyl_gr_mhd_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-8) ); - - TEST_CHECK( gkyl_compare(prims[5], mag_x, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[6], mag_y, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[7], mag_z, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[8], psi, 1e-8) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-8)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-8)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-8)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-8)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-8)); + + TEST_CHECK(gkyl_compare(prims[5], mag_x, 1e-8)); + TEST_CHECK(gkyl_compare(prims[6], mag_y, 1e-8)); + TEST_CHECK(gkyl_compare(prims[7], mag_z, 1e-8)); + TEST_CHECK(gkyl_compare(prims[8], psi, 1e-8)); double D = rho * W; double Sx = (rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]); @@ -200,52 +257,61 @@ test_gr_mhd_basic_minkowski_ho() double Etot = (rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W); double fluxes[3][9] = { - { (lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + (p_star * vel[0]) - ((lapse * b0 * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[0]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + (p_star * vel[1]) - ((lapse * b0 * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[1]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + (p_star * vel[2]) - ((lapse * b0 * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[2]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z) }, + {(lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + (p_star * vel[0]) - + ((lapse * b0 * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[0]) - + ((vel[0] - (shift[0] / lapse)) * mag[0]) + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + (p_star * vel[1]) - + ((lapse * b0 * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[1]) - + ((vel[1] - (shift[1] / lapse)) * mag[1]) + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + (p_star * vel[2]) - + ((lapse * b0 * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[2]) - + ((vel[2] - (shift[2] / lapse)) * mag[2]) + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[75], flux_local[75], flux[75]; for (int d = 0; d < 3; d++) { @@ -254,17 +320,17 @@ test_gr_mhd_basic_minkowski_ho() gr_mhd->rotate_to_global_func(gr_mhd, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-8) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-8)); } } - + double q_l[75], q_g[75]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(gr_mhd, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(gr_mhd, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[75], q1[75]; @@ -272,7 +338,7 @@ test_gr_mhd_basic_minkowski_ho() gr_mhd->riem_to_cons(gr_mhd, q_local, w1, q1); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } @@ -280,7 +346,7 @@ test_gr_mhd_basic_minkowski_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -306,17 +372,17 @@ test_gr_mhd_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_mhd_basic_schwarzschild_ho() +void test_gr_mhd_basic_schwarzschild_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd = + gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_mhd->num_equations == 75 ); - TEST_CHECK( gr_mhd->num_waves == 2 ); + TEST_CHECK(gr_mhd->num_equations == 75); + TEST_CHECK(gr_mhd->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -330,25 +396,25 @@ test_gr_mhd_basic_schwarzschild_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -359,16 +425,28 @@ test_gr_mhd_basic_schwarzschild_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -380,7 +458,9 @@ test_gr_mhd_basic_schwarzschild_ho() double W = 1.0 / sqrt(1.0 - v_sq); double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -399,7 +479,7 @@ test_gr_mhd_basic_schwarzschild_ho() cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); @@ -437,10 +517,14 @@ test_gr_mhd_basic_schwarzschild_ho() if (!in_excision_region) { double q[75]; q[0] = sqrt(spatial_det) * rho * W; - q[1] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); - q[2] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); - q[3] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); - q[4] = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); + q[1] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); + q[2] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); + q[3] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); + q[4] = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); q[5] = sqrt(spatial_det) * mag_x; q[6] = sqrt(spatial_det) * mag_y; @@ -448,51 +532,93 @@ test_gr_mhd_basic_schwarzschild_ho() q[8] = sqrt(spatial_det) * psi; q[9] = lapse; - q[10] = shift[0]; q[11] = shift[1]; q[12] = shift[2]; - - q[13] = spatial_metric[0][0]; q[14] = spatial_metric[0][1]; q[15] = spatial_metric[0][2]; - q[16] = spatial_metric[1][0]; q[17] = spatial_metric[1][1]; q[18] = spatial_metric[1][2]; - q[19] = spatial_metric[2][0]; q[20] = spatial_metric[2][1]; q[21] = spatial_metric[2][2]; - - q[22] = extrinsic_curvature[0][0]; q[23] = extrinsic_curvature[0][1]; q[24] = extrinsic_curvature[0][2]; - q[25] = extrinsic_curvature[1][0]; q[26] = extrinsic_curvature[1][1]; q[27] = extrinsic_curvature[1][2]; - q[28] = extrinsic_curvature[2][0]; q[29] = extrinsic_curvature[2][1]; q[30] = extrinsic_curvature[2][2]; + q[10] = shift[0]; + q[11] = shift[1]; + q[12] = shift[2]; + + q[13] = spatial_metric[0][0]; + q[14] = spatial_metric[0][1]; + q[15] = spatial_metric[0][2]; + q[16] = spatial_metric[1][0]; + q[17] = spatial_metric[1][1]; + q[18] = spatial_metric[1][2]; + q[19] = spatial_metric[2][0]; + q[20] = spatial_metric[2][1]; + q[21] = spatial_metric[2][2]; + + q[22] = extrinsic_curvature[0][0]; + q[23] = extrinsic_curvature[0][1]; + q[24] = extrinsic_curvature[0][2]; + q[25] = extrinsic_curvature[1][0]; + q[26] = extrinsic_curvature[1][1]; + q[27] = extrinsic_curvature[1][2]; + q[28] = extrinsic_curvature[2][0]; + q[29] = extrinsic_curvature[2][1]; + q[30] = extrinsic_curvature[2][2]; q[31] = 1.0; - q[32] = lapse_der[0]; q[33] = lapse_der[1]; q[34] = lapse_der[2]; - q[35] = shift_der[0][0]; q[36] = shift_der[0][1]; q[37] = shift_der[0][2]; - q[38] = shift_der[1][0]; q[39] = shift_der[1][1]; q[40] = shift_der[1][2]; - q[41] = shift_der[2][0]; q[42] = shift_der[2][1]; q[43] = shift_der[2][2]; - - q[44] = spatial_metric_der[0][0][0]; q[45] = spatial_metric_der[0][0][1]; q[46] = spatial_metric_der[0][0][2]; - q[47] = spatial_metric_der[0][1][0]; q[48] = spatial_metric_der[0][1][1]; q[49] = spatial_metric_der[0][1][2]; - q[50] = spatial_metric_der[0][2][0]; q[51] = spatial_metric_der[0][2][1]; q[52] = spatial_metric_der[0][2][2]; - - q[53] = spatial_metric_der[1][0][0]; q[54] = spatial_metric_der[1][0][1]; q[55] = spatial_metric_der[1][0][2]; - q[56] = spatial_metric_der[1][1][0]; q[57] = spatial_metric_der[1][1][1]; q[58] = spatial_metric_der[1][1][2]; - q[59] = spatial_metric_der[1][2][0]; q[60] = spatial_metric_der[1][2][1]; q[61] = spatial_metric_der[1][2][2]; - - q[62] = spatial_metric_der[2][0][0]; q[63] = spatial_metric_der[2][0][1]; q[64] = spatial_metric_der[2][0][2]; - q[65] = spatial_metric_der[2][1][0]; q[66] = spatial_metric_der[2][1][1]; q[67] = spatial_metric_der[2][1][2]; - q[68] = spatial_metric_der[2][2][0]; q[69] = spatial_metric_der[2][2][1]; q[70] = spatial_metric_der[2][2][2]; + q[32] = lapse_der[0]; + q[33] = lapse_der[1]; + q[34] = lapse_der[2]; + q[35] = shift_der[0][0]; + q[36] = shift_der[0][1]; + q[37] = shift_der[0][2]; + q[38] = shift_der[1][0]; + q[39] = shift_der[1][1]; + q[40] = shift_der[1][2]; + q[41] = shift_der[2][0]; + q[42] = shift_der[2][1]; + q[43] = shift_der[2][2]; + + q[44] = spatial_metric_der[0][0][0]; + q[45] = spatial_metric_der[0][0][1]; + q[46] = spatial_metric_der[0][0][2]; + q[47] = spatial_metric_der[0][1][0]; + q[48] = spatial_metric_der[0][1][1]; + q[49] = spatial_metric_der[0][1][2]; + q[50] = spatial_metric_der[0][2][0]; + q[51] = spatial_metric_der[0][2][1]; + q[52] = spatial_metric_der[0][2][2]; + + q[53] = spatial_metric_der[1][0][0]; + q[54] = spatial_metric_der[1][0][1]; + q[55] = spatial_metric_der[1][0][2]; + q[56] = spatial_metric_der[1][1][0]; + q[57] = spatial_metric_der[1][1][1]; + q[58] = spatial_metric_der[1][1][2]; + q[59] = spatial_metric_der[1][2][0]; + q[60] = spatial_metric_der[1][2][1]; + q[61] = spatial_metric_der[1][2][2]; + + q[62] = spatial_metric_der[2][0][0]; + q[63] = spatial_metric_der[2][0][1]; + q[64] = spatial_metric_der[2][0][2]; + q[65] = spatial_metric_der[2][1][0]; + q[66] = spatial_metric_der[2][1][1]; + q[67] = spatial_metric_der[2][1][2]; + q[68] = spatial_metric_der[2][2][0]; + q[69] = spatial_metric_der[2][2][1]; + q[70] = spatial_metric_der[2][2][2]; q[71] = 0.0; - q[72] = x; q[73] = y; q[74] = 0.0; + q[72] = x; + q[73] = y; + q[74] = 0.0; double prims[75]; gkyl_gr_mhd_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); - - TEST_CHECK( gkyl_compare(prims[5], mag_x, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[6], mag_y, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[7], mag_z, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[8], psi, 1e-8) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], mag_x, 1e-8)); + TEST_CHECK(gkyl_compare(prims[6], mag_y, 1e-8)); + TEST_CHECK(gkyl_compare(prims[7], mag_z, 1e-8)); + TEST_CHECK(gkyl_compare(prims[8], psi, 1e-8)); double D = rho * W; double Sx = (rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]); @@ -501,52 +627,64 @@ test_gr_mhd_basic_schwarzschild_ho() double Etot = (rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W); double fluxes[3][9] = { - { (lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + (p_star * vel[0]) - ((lapse * b0 * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[0]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + (p_star * vel[1]) - ((lapse * b0 * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[1]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + (p_star * vel[2]) - ((lapse * b0 * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[2]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z) }, + {(lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + + (p_star * vel[0]) - ((lapse * b0 * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[0]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + + (p_star * vel[1]) - ((lapse * b0 * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[1]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + + (p_star * vel[2]) - ((lapse * b0 * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[2]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[75], flux_local[75], flux[75]; for (int d = 0; d < 3; d++) { @@ -555,17 +693,17 @@ test_gr_mhd_basic_schwarzschild_ho() gr_mhd->rotate_to_global_func(gr_mhd, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } - + double q_l[75], q_g[75]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(gr_mhd, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(gr_mhd, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[75], q1[75]; @@ -573,7 +711,7 @@ test_gr_mhd_basic_schwarzschild_ho() gr_mhd->riem_to_cons(gr_mhd, q_local, w1, q1); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -582,7 +720,7 @@ test_gr_mhd_basic_schwarzschild_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -608,17 +746,17 @@ test_gr_mhd_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_mhd_basic_kerr_ho() +void test_gr_mhd_basic_kerr_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd = + gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_mhd->num_equations == 75 ); - TEST_CHECK( gr_mhd->num_waves == 2 ); + TEST_CHECK(gr_mhd->num_equations == 75); + TEST_CHECK(gr_mhd->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -632,25 +770,25 @@ test_gr_mhd_basic_kerr_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -661,16 +799,28 @@ test_gr_mhd_basic_kerr_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -682,7 +832,9 @@ test_gr_mhd_basic_kerr_ho() double W = 1.0 / sqrt(1.0 - v_sq); double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -701,7 +853,7 @@ test_gr_mhd_basic_kerr_ho() cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); @@ -739,10 +891,14 @@ test_gr_mhd_basic_kerr_ho() if (!in_excision_region) { double q[75]; q[0] = sqrt(spatial_det) * rho * W; - q[1] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); - q[2] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); - q[3] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); - q[4] = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); + q[1] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); + q[2] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); + q[3] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); + q[4] = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); q[5] = sqrt(spatial_det) * mag_x; q[6] = sqrt(spatial_det) * mag_y; @@ -750,51 +906,93 @@ test_gr_mhd_basic_kerr_ho() q[8] = sqrt(spatial_det) * psi; q[9] = lapse; - q[10] = shift[0]; q[11] = shift[1]; q[12] = shift[2]; - - q[13] = spatial_metric[0][0]; q[14] = spatial_metric[0][1]; q[15] = spatial_metric[0][2]; - q[16] = spatial_metric[1][0]; q[17] = spatial_metric[1][1]; q[18] = spatial_metric[1][2]; - q[19] = spatial_metric[2][0]; q[20] = spatial_metric[2][1]; q[21] = spatial_metric[2][2]; - - q[22] = extrinsic_curvature[0][0]; q[23] = extrinsic_curvature[0][1]; q[24] = extrinsic_curvature[0][2]; - q[25] = extrinsic_curvature[1][0]; q[26] = extrinsic_curvature[1][1]; q[27] = extrinsic_curvature[1][2]; - q[28] = extrinsic_curvature[2][0]; q[29] = extrinsic_curvature[2][1]; q[30] = extrinsic_curvature[2][2]; + q[10] = shift[0]; + q[11] = shift[1]; + q[12] = shift[2]; + + q[13] = spatial_metric[0][0]; + q[14] = spatial_metric[0][1]; + q[15] = spatial_metric[0][2]; + q[16] = spatial_metric[1][0]; + q[17] = spatial_metric[1][1]; + q[18] = spatial_metric[1][2]; + q[19] = spatial_metric[2][0]; + q[20] = spatial_metric[2][1]; + q[21] = spatial_metric[2][2]; + + q[22] = extrinsic_curvature[0][0]; + q[23] = extrinsic_curvature[0][1]; + q[24] = extrinsic_curvature[0][2]; + q[25] = extrinsic_curvature[1][0]; + q[26] = extrinsic_curvature[1][1]; + q[27] = extrinsic_curvature[1][2]; + q[28] = extrinsic_curvature[2][0]; + q[29] = extrinsic_curvature[2][1]; + q[30] = extrinsic_curvature[2][2]; q[31] = 1.0; - q[32] = lapse_der[0]; q[33] = lapse_der[1]; q[34] = lapse_der[2]; - q[35] = shift_der[0][0]; q[36] = shift_der[0][1]; q[37] = shift_der[0][2]; - q[38] = shift_der[1][0]; q[39] = shift_der[1][1]; q[40] = shift_der[1][2]; - q[41] = shift_der[2][0]; q[42] = shift_der[2][1]; q[43] = shift_der[2][2]; - - q[44] = spatial_metric_der[0][0][0]; q[45] = spatial_metric_der[0][0][1]; q[46] = spatial_metric_der[0][0][2]; - q[47] = spatial_metric_der[0][1][0]; q[48] = spatial_metric_der[0][1][1]; q[49] = spatial_metric_der[0][1][2]; - q[50] = spatial_metric_der[0][2][0]; q[51] = spatial_metric_der[0][2][1]; q[52] = spatial_metric_der[0][2][2]; - - q[53] = spatial_metric_der[1][0][0]; q[54] = spatial_metric_der[1][0][1]; q[55] = spatial_metric_der[1][0][2]; - q[56] = spatial_metric_der[1][1][0]; q[57] = spatial_metric_der[1][1][1]; q[58] = spatial_metric_der[1][1][2]; - q[59] = spatial_metric_der[1][2][0]; q[60] = spatial_metric_der[1][2][1]; q[61] = spatial_metric_der[1][2][2]; - - q[62] = spatial_metric_der[2][0][0]; q[63] = spatial_metric_der[2][0][1]; q[64] = spatial_metric_der[2][0][2]; - q[65] = spatial_metric_der[2][1][0]; q[66] = spatial_metric_der[2][1][1]; q[67] = spatial_metric_der[2][1][2]; - q[68] = spatial_metric_der[2][2][0]; q[69] = spatial_metric_der[2][2][1]; q[70] = spatial_metric_der[2][2][2]; + q[32] = lapse_der[0]; + q[33] = lapse_der[1]; + q[34] = lapse_der[2]; + q[35] = shift_der[0][0]; + q[36] = shift_der[0][1]; + q[37] = shift_der[0][2]; + q[38] = shift_der[1][0]; + q[39] = shift_der[1][1]; + q[40] = shift_der[1][2]; + q[41] = shift_der[2][0]; + q[42] = shift_der[2][1]; + q[43] = shift_der[2][2]; + + q[44] = spatial_metric_der[0][0][0]; + q[45] = spatial_metric_der[0][0][1]; + q[46] = spatial_metric_der[0][0][2]; + q[47] = spatial_metric_der[0][1][0]; + q[48] = spatial_metric_der[0][1][1]; + q[49] = spatial_metric_der[0][1][2]; + q[50] = spatial_metric_der[0][2][0]; + q[51] = spatial_metric_der[0][2][1]; + q[52] = spatial_metric_der[0][2][2]; + + q[53] = spatial_metric_der[1][0][0]; + q[54] = spatial_metric_der[1][0][1]; + q[55] = spatial_metric_der[1][0][2]; + q[56] = spatial_metric_der[1][1][0]; + q[57] = spatial_metric_der[1][1][1]; + q[58] = spatial_metric_der[1][1][2]; + q[59] = spatial_metric_der[1][2][0]; + q[60] = spatial_metric_der[1][2][1]; + q[61] = spatial_metric_der[1][2][2]; + + q[62] = spatial_metric_der[2][0][0]; + q[63] = spatial_metric_der[2][0][1]; + q[64] = spatial_metric_der[2][0][2]; + q[65] = spatial_metric_der[2][1][0]; + q[66] = spatial_metric_der[2][1][1]; + q[67] = spatial_metric_der[2][1][2]; + q[68] = spatial_metric_der[2][2][0]; + q[69] = spatial_metric_der[2][2][1]; + q[70] = spatial_metric_der[2][2][2]; q[71] = 0.0; - q[72] = x; q[73] = y; q[74] = 0.0; + q[72] = x; + q[73] = y; + q[74] = 0.0; double prims[75]; gkyl_gr_mhd_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); - - TEST_CHECK( gkyl_compare(prims[5], mag_x, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[6], mag_y, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[7], mag_z, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[8], psi, 1e-8) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], mag_x, 1e-8)); + TEST_CHECK(gkyl_compare(prims[6], mag_y, 1e-8)); + TEST_CHECK(gkyl_compare(prims[7], mag_z, 1e-8)); + TEST_CHECK(gkyl_compare(prims[8], psi, 1e-8)); double D = rho * W; double Sx = (rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]); @@ -803,52 +1001,64 @@ test_gr_mhd_basic_kerr_ho() double Etot = (rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W); double fluxes[3][9] = { - { (lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + (p_star * vel[0]) - ((lapse * b0 * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[0]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + (p_star * vel[1]) - ((lapse * b0 * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[1]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + (p_star * vel[2]) - ((lapse * b0 * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[2]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z) }, + {(lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + + (p_star * vel[0]) - ((lapse * b0 * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[0]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + + (p_star * vel[1]) - ((lapse * b0 * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[1]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + + (p_star * vel[2]) - ((lapse * b0 * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[2]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[75], flux_local[75], flux[75]; for (int d = 0; d < 3; d++) { @@ -857,17 +1067,17 @@ test_gr_mhd_basic_kerr_ho() gr_mhd->rotate_to_global_func(gr_mhd, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } - + double q_l[75], q_g[75]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(gr_mhd, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(gr_mhd, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[75], q1[75]; @@ -875,7 +1085,7 @@ test_gr_mhd_basic_kerr_ho() gr_mhd->riem_to_cons(gr_mhd, q_local, w1, q1); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -884,7 +1094,7 @@ test_gr_mhd_basic_kerr_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -910,14 +1120,14 @@ test_gr_mhd_basic_kerr_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_mhd_waves_minkowski_ho() +void test_gr_mhd_waves_minkowski_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd = + gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -934,10 +1144,10 @@ test_gr_mhd_waves_minkowski_ho() double *shift_l = gkyl_malloc(sizeof(double[3])); double *shift_r = gkyl_malloc(sizeof(double[3])); - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -947,18 +1157,18 @@ test_gr_mhd_waves_minkowski_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -975,20 +1185,46 @@ test_gr_mhd_waves_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1003,8 +1239,12 @@ test_gr_mhd_waves_minkowski_ho() double *mag_l = gkyl_malloc(sizeof(double[3])); double *mag_r = gkyl_malloc(sizeof(double[3])); - mag_l[0] = mag_x_l; mag_l[1] = mag_y_l; mag_l[2] = mag_z_l; - mag_r[0] = mag_x_r; mag_r[1] = mag_y_r; mag_r[2] = mag_z_r; + mag_l[0] = mag_x_l; + mag_l[1] = mag_y_l; + mag_l[2] = mag_z_l; + mag_r[0] = mag_x_r; + mag_r[1] = mag_y_r; + mag_r[2] = mag_z_r; double *cov_mag_l = gkyl_malloc(sizeof(double[3])); double *cov_mag_r = gkyl_malloc(sizeof(double[3])); @@ -1029,7 +1269,7 @@ test_gr_mhd_waves_minkowski_ho() cov_vel_r[i] += spatial_metric_r[i][j] * vel_r[j]; } } - + double b0_l = 0.0, b0_r = 0.0; for (int i = 0; i < 3; i++) { b0_l += W_l * mag_l[i] * (cov_vel_l[i] / lapse_l); @@ -1079,10 +1319,14 @@ test_gr_mhd_waves_minkowski_ho() double ql[75], qr[75]; ql[0] = sqrt(spatial_det_l) * rho_l * W_l; - ql[1] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); - ql[2] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); - ql[3] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); - ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); + ql[1] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); + ql[2] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); + ql[3] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); + ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - + ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); ql[5] = sqrt(spatial_det_l) * mag_x_l; ql[6] = sqrt(spatial_det_l) * mag_y_l; @@ -1090,43 +1334,89 @@ test_gr_mhd_waves_minkowski_ho() ql[8] = sqrt(spatial_det_l) * psi_l; ql[9] = lapse_l; - ql[10] = shift_l[0]; ql[11] = shift_l[1]; ql[12] = shift_l[2]; - - ql[13] = spatial_metric_l[0][0]; ql[14] = spatial_metric_l[0][1]; ql[15] = spatial_metric_l[0][2]; - ql[16] = spatial_metric_l[1][0]; ql[17] = spatial_metric_l[1][1]; ql[18] = spatial_metric_l[1][2]; - ql[19] = spatial_metric_l[2][0]; ql[20] = spatial_metric_l[2][1]; ql[21] = spatial_metric_l[2][2]; - - ql[22] = extrinsic_curvature_l[0][0]; ql[23] = extrinsic_curvature_l[0][1]; ql[24] = extrinsic_curvature_l[0][2]; - ql[25] = extrinsic_curvature_l[1][0]; ql[26] = extrinsic_curvature_l[1][1]; ql[27] = extrinsic_curvature_l[1][2]; - ql[28] = extrinsic_curvature_l[2][0]; ql[29] = extrinsic_curvature_l[2][1]; ql[30] = extrinsic_curvature_l[2][2]; + ql[10] = shift_l[0]; + ql[11] = shift_l[1]; + ql[12] = shift_l[2]; + + ql[13] = spatial_metric_l[0][0]; + ql[14] = spatial_metric_l[0][1]; + ql[15] = spatial_metric_l[0][2]; + ql[16] = spatial_metric_l[1][0]; + ql[17] = spatial_metric_l[1][1]; + ql[18] = spatial_metric_l[1][2]; + ql[19] = spatial_metric_l[2][0]; + ql[20] = spatial_metric_l[2][1]; + ql[21] = spatial_metric_l[2][2]; + + ql[22] = extrinsic_curvature_l[0][0]; + ql[23] = extrinsic_curvature_l[0][1]; + ql[24] = extrinsic_curvature_l[0][2]; + ql[25] = extrinsic_curvature_l[1][0]; + ql[26] = extrinsic_curvature_l[1][1]; + ql[27] = extrinsic_curvature_l[1][2]; + ql[28] = extrinsic_curvature_l[2][0]; + ql[29] = extrinsic_curvature_l[2][1]; + ql[30] = extrinsic_curvature_l[2][2]; ql[31] = 1.0; - ql[32] = lapse_der_l[0]; ql[33] = lapse_der_l[1]; ql[34] = lapse_der_l[2]; - ql[35] = shift_der_l[0][0]; ql[36] = shift_der_l[0][1]; ql[37] = shift_der_l[0][2]; - ql[38] = shift_der_l[1][0]; ql[39] = shift_der_l[1][1]; ql[40] = shift_der_l[1][2]; - ql[41] = shift_der_l[2][0]; ql[42] = shift_der_l[2][1]; ql[43] = shift_der_l[2][2]; - - ql[44] = spatial_metric_der_l[0][0][0]; ql[45] = spatial_metric_der_l[0][0][1]; ql[46] = spatial_metric_der_l[0][0][2]; - ql[47] = spatial_metric_der_l[0][1][0]; ql[48] = spatial_metric_der_l[0][1][1]; ql[49] = spatial_metric_der_l[0][1][2]; - ql[50] = spatial_metric_der_l[0][2][0]; ql[51] = spatial_metric_der_l[0][2][1]; ql[52] = spatial_metric_der_l[0][2][2]; - - ql[53] = spatial_metric_der_l[1][0][0]; ql[54] = spatial_metric_der_l[1][0][1]; ql[55] = spatial_metric_der_l[1][0][2]; - ql[56] = spatial_metric_der_l[1][1][0]; ql[57] = spatial_metric_der_l[1][1][1]; ql[58] = spatial_metric_der_l[1][1][2]; - ql[59] = spatial_metric_der_l[1][2][0]; ql[60] = spatial_metric_der_l[1][2][1]; ql[61] = spatial_metric_der_l[1][2][2]; - - ql[62] = spatial_metric_der_l[2][0][0]; ql[63] = spatial_metric_der_l[2][0][1]; ql[64] = spatial_metric_der_l[2][0][2]; - ql[65] = spatial_metric_der_l[2][1][0]; ql[66] = spatial_metric_der_l[2][1][1]; ql[67] = spatial_metric_der_l[2][1][2]; - ql[68] = spatial_metric_der_l[2][2][0]; ql[69] = spatial_metric_der_l[2][2][1]; ql[70] = spatial_metric_der_l[2][2][2]; + ql[32] = lapse_der_l[0]; + ql[33] = lapse_der_l[1]; + ql[34] = lapse_der_l[2]; + ql[35] = shift_der_l[0][0]; + ql[36] = shift_der_l[0][1]; + ql[37] = shift_der_l[0][2]; + ql[38] = shift_der_l[1][0]; + ql[39] = shift_der_l[1][1]; + ql[40] = shift_der_l[1][2]; + ql[41] = shift_der_l[2][0]; + ql[42] = shift_der_l[2][1]; + ql[43] = shift_der_l[2][2]; + + ql[44] = spatial_metric_der_l[0][0][0]; + ql[45] = spatial_metric_der_l[0][0][1]; + ql[46] = spatial_metric_der_l[0][0][2]; + ql[47] = spatial_metric_der_l[0][1][0]; + ql[48] = spatial_metric_der_l[0][1][1]; + ql[49] = spatial_metric_der_l[0][1][2]; + ql[50] = spatial_metric_der_l[0][2][0]; + ql[51] = spatial_metric_der_l[0][2][1]; + ql[52] = spatial_metric_der_l[0][2][2]; + + ql[53] = spatial_metric_der_l[1][0][0]; + ql[54] = spatial_metric_der_l[1][0][1]; + ql[55] = spatial_metric_der_l[1][0][2]; + ql[56] = spatial_metric_der_l[1][1][0]; + ql[57] = spatial_metric_der_l[1][1][1]; + ql[58] = spatial_metric_der_l[1][1][2]; + ql[59] = spatial_metric_der_l[1][2][0]; + ql[60] = spatial_metric_der_l[1][2][1]; + ql[61] = spatial_metric_der_l[1][2][2]; + + ql[62] = spatial_metric_der_l[2][0][0]; + ql[63] = spatial_metric_der_l[2][0][1]; + ql[64] = spatial_metric_der_l[2][0][2]; + ql[65] = spatial_metric_der_l[2][1][0]; + ql[66] = spatial_metric_der_l[2][1][1]; + ql[67] = spatial_metric_der_l[2][1][2]; + ql[68] = spatial_metric_der_l[2][2][0]; + ql[69] = spatial_metric_der_l[2][2][1]; + ql[70] = spatial_metric_der_l[2][2][2]; ql[71] = 0.0; - ql[72] = x - 0.5; ql[73] = y; ql[74] = 0.0; + ql[72] = x - 0.5; + ql[73] = y; + ql[74] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; - qr[1] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); - qr[2] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); - qr[3] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); - qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); + qr[1] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); + qr[2] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); + qr[3] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); + qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - + ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); qr[5] = sqrt(spatial_det_r) * mag_x_r; qr[6] = sqrt(spatial_det_r) * mag_y_r; @@ -1134,55 +1424,85 @@ test_gr_mhd_waves_minkowski_ho() qr[8] = sqrt(spatial_det_r) * psi_r; qr[9] = lapse_r; - qr[10] = shift_r[0]; qr[11] = shift_r[1]; qr[12] = shift_r[2]; - - qr[13] = spatial_metric_r[0][0]; qr[14] = spatial_metric_r[0][1]; qr[15] = spatial_metric_r[0][2]; - qr[16] = spatial_metric_r[1][0]; qr[17] = spatial_metric_r[1][1]; qr[18] = spatial_metric_r[1][2]; - qr[19] = spatial_metric_r[2][0]; qr[20] = spatial_metric_r[2][1]; qr[21] = spatial_metric_r[2][2]; - - qr[22] = extrinsic_curvature_r[0][0]; qr[23] = extrinsic_curvature_r[0][1]; qr[24] = extrinsic_curvature_r[0][2]; - qr[25] = extrinsic_curvature_r[1][0]; qr[26] = extrinsic_curvature_r[1][1]; qr[27] = extrinsic_curvature_r[1][2]; - qr[28] = extrinsic_curvature_r[2][0]; qr[29] = extrinsic_curvature_r[2][1]; qr[30] = extrinsic_curvature_r[2][2]; + qr[10] = shift_r[0]; + qr[11] = shift_r[1]; + qr[12] = shift_r[2]; + + qr[13] = spatial_metric_r[0][0]; + qr[14] = spatial_metric_r[0][1]; + qr[15] = spatial_metric_r[0][2]; + qr[16] = spatial_metric_r[1][0]; + qr[17] = spatial_metric_r[1][1]; + qr[18] = spatial_metric_r[1][2]; + qr[19] = spatial_metric_r[2][0]; + qr[20] = spatial_metric_r[2][1]; + qr[21] = spatial_metric_r[2][2]; + + qr[22] = extrinsic_curvature_r[0][0]; + qr[23] = extrinsic_curvature_r[0][1]; + qr[24] = extrinsic_curvature_r[0][2]; + qr[25] = extrinsic_curvature_r[1][0]; + qr[26] = extrinsic_curvature_r[1][1]; + qr[27] = extrinsic_curvature_r[1][2]; + qr[28] = extrinsic_curvature_r[2][0]; + qr[29] = extrinsic_curvature_r[2][1]; + qr[30] = extrinsic_curvature_r[2][2]; qr[31] = 1.0; - qr[32] = lapse_der_r[0]; qr[33] = lapse_der_r[1]; qr[34] = lapse_der_r[2]; - qr[35] = shift_der_r[0][0]; qr[36] = shift_der_r[0][1]; qr[37] = shift_der_r[0][2]; - qr[38] = shift_der_r[1][0]; qr[39] = shift_der_r[1][1]; qr[40] = shift_der_r[1][2]; - qr[41] = shift_der_r[2][0]; qr[42] = shift_der_r[2][1]; qr[43] = shift_der_r[2][2]; - - qr[44] = spatial_metric_der_r[0][0][0]; qr[45] = spatial_metric_der_r[0][0][1]; qr[46] = spatial_metric_der_r[0][0][2]; - qr[47] = spatial_metric_der_r[0][1][0]; qr[48] = spatial_metric_der_r[0][1][1]; qr[49] = spatial_metric_der_r[0][1][2]; - qr[50] = spatial_metric_der_r[0][2][0]; qr[51] = spatial_metric_der_r[0][2][1]; qr[52] = spatial_metric_der_r[0][2][2]; - - qr[53] = spatial_metric_der_r[1][0][0]; qr[54] = spatial_metric_der_r[1][0][1]; qr[55] = spatial_metric_der_r[1][0][2]; - qr[56] = spatial_metric_der_r[1][1][0]; qr[57] = spatial_metric_der_r[1][1][1]; qr[58] = spatial_metric_der_r[1][1][2]; - qr[59] = spatial_metric_der_r[1][2][0]; qr[60] = spatial_metric_der_r[1][2][1]; qr[61] = spatial_metric_der_r[1][2][2]; - - qr[62] = spatial_metric_der_r[2][0][0]; qr[63] = spatial_metric_der_r[2][0][1]; qr[64] = spatial_metric_der_r[2][0][2]; - qr[65] = spatial_metric_der_r[2][1][0]; qr[66] = spatial_metric_der_r[2][1][1]; qr[67] = spatial_metric_der_r[2][1][2]; - qr[68] = spatial_metric_der_r[2][2][0]; qr[69] = spatial_metric_der_r[2][2][1]; qr[70] = spatial_metric_der_r[2][2][2]; + qr[32] = lapse_der_r[0]; + qr[33] = lapse_der_r[1]; + qr[34] = lapse_der_r[2]; + qr[35] = shift_der_r[0][0]; + qr[36] = shift_der_r[0][1]; + qr[37] = shift_der_r[0][2]; + qr[38] = shift_der_r[1][0]; + qr[39] = shift_der_r[1][1]; + qr[40] = shift_der_r[1][2]; + qr[41] = shift_der_r[2][0]; + qr[42] = shift_der_r[2][1]; + qr[43] = shift_der_r[2][2]; + + qr[44] = spatial_metric_der_r[0][0][0]; + qr[45] = spatial_metric_der_r[0][0][1]; + qr[46] = spatial_metric_der_r[0][0][2]; + qr[47] = spatial_metric_der_r[0][1][0]; + qr[48] = spatial_metric_der_r[0][1][1]; + qr[49] = spatial_metric_der_r[0][1][2]; + qr[50] = spatial_metric_der_r[0][2][0]; + qr[51] = spatial_metric_der_r[0][2][1]; + qr[52] = spatial_metric_der_r[0][2][2]; + + qr[53] = spatial_metric_der_r[1][0][0]; + qr[54] = spatial_metric_der_r[1][0][1]; + qr[55] = spatial_metric_der_r[1][0][2]; + qr[56] = spatial_metric_der_r[1][1][0]; + qr[57] = spatial_metric_der_r[1][1][1]; + qr[58] = spatial_metric_der_r[1][1][2]; + qr[59] = spatial_metric_der_r[1][2][0]; + qr[60] = spatial_metric_der_r[1][2][1]; + qr[61] = spatial_metric_der_r[1][2][2]; + + qr[62] = spatial_metric_der_r[2][0][0]; + qr[63] = spatial_metric_der_r[2][0][1]; + qr[64] = spatial_metric_der_r[2][0][2]; + qr[65] = spatial_metric_der_r[2][1][0]; + qr[66] = spatial_metric_der_r[2][1][1]; + qr[67] = spatial_metric_der_r[2][1][2]; + qr[68] = spatial_metric_der_r[2][2][0]; + qr[69] = spatial_metric_der_r[2][2][1]; + qr[70] = spatial_metric_der_r[2][2][2]; qr[71] = 0.0; - qr[72] = x + 0.5; qr[73] = y; qr[74] = 0.0; + qr[72] = x + 0.5; + qr[73] = y; + qr[74] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 75], waves_local[2 * 75]; @@ -1196,13 +1516,20 @@ test_gr_mhd_waves_minkowski_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); double apdq_local[75], amdq_local[75]; - gkyl_wv_eqn_qfluct(gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_mhd, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75]); + gkyl_wv_eqn_rotate_to_global( + gr_mhd, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75] + ); } double apdq[75], amdq[75]; @@ -1218,7 +1545,7 @@ test_gr_mhd_waves_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_mhd, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); } } @@ -1229,7 +1556,7 @@ test_gr_mhd_waves_minkowski_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1270,14 +1597,14 @@ test_gr_mhd_waves_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_mhd_waves_schwarzschild_ho() +void test_gr_mhd_waves_schwarzschild_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd = + gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1295,10 +1622,10 @@ test_gr_mhd_waves_schwarzschild_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1308,18 +1635,18 @@ test_gr_mhd_waves_schwarzschild_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1338,20 +1665,46 @@ test_gr_mhd_waves_schwarzschild_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1366,8 +1719,12 @@ test_gr_mhd_waves_schwarzschild_ho() double *mag_l = gkyl_malloc(sizeof(double[3])); double *mag_r = gkyl_malloc(sizeof(double[3])); - mag_l[0] = mag_x_l; mag_l[1] = mag_y_l; mag_l[2] = mag_z_l; - mag_r[0] = mag_x_r; mag_r[1] = mag_y_r; mag_r[2] = mag_z_r; + mag_l[0] = mag_x_l; + mag_l[1] = mag_y_l; + mag_l[2] = mag_z_l; + mag_r[0] = mag_x_r; + mag_r[1] = mag_y_r; + mag_r[2] = mag_z_r; double *cov_mag_l = gkyl_malloc(sizeof(double[3])); double *cov_mag_r = gkyl_malloc(sizeof(double[3])); @@ -1392,7 +1749,7 @@ test_gr_mhd_waves_schwarzschild_ho() cov_vel_r[i] += spatial_metric_r[i][j] * vel_r[j]; } } - + double b0_l = 0.0, b0_r = 0.0; for (int i = 0; i < 3; i++) { b0_l += W_l * mag_l[i] * (cov_vel_l[i] / lapse_l); @@ -1443,10 +1800,14 @@ test_gr_mhd_waves_schwarzschild_ho() if (!in_excision_region_l && !in_excision_region_r) { double ql[75], qr[75]; ql[0] = sqrt(spatial_det_l) * rho_l * W_l; - ql[1] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); - ql[2] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); - ql[3] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); - ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); + ql[1] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); + ql[2] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); + ql[3] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); + ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - + ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); ql[5] = sqrt(spatial_det_l) * mag_x_l; ql[6] = sqrt(spatial_det_l) * mag_y_l; @@ -1454,43 +1815,89 @@ test_gr_mhd_waves_schwarzschild_ho() ql[8] = sqrt(spatial_det_l) * psi_l; ql[9] = lapse_l; - ql[10] = shift_l[0]; ql[11] = shift_l[1]; ql[12] = shift_l[2]; - - ql[13] = spatial_metric_l[0][0]; ql[14] = spatial_metric_l[0][1]; ql[15] = spatial_metric_l[0][2]; - ql[16] = spatial_metric_l[1][0]; ql[17] = spatial_metric_l[1][1]; ql[18] = spatial_metric_l[1][2]; - ql[19] = spatial_metric_l[2][0]; ql[20] = spatial_metric_l[2][1]; ql[21] = spatial_metric_l[2][2]; - - ql[22] = extrinsic_curvature_l[0][0]; ql[23] = extrinsic_curvature_l[0][1]; ql[24] = extrinsic_curvature_l[0][2]; - ql[25] = extrinsic_curvature_l[1][0]; ql[26] = extrinsic_curvature_l[1][1]; ql[27] = extrinsic_curvature_l[1][2]; - ql[28] = extrinsic_curvature_l[2][0]; ql[29] = extrinsic_curvature_l[2][1]; ql[30] = extrinsic_curvature_l[2][2]; + ql[10] = shift_l[0]; + ql[11] = shift_l[1]; + ql[12] = shift_l[2]; + + ql[13] = spatial_metric_l[0][0]; + ql[14] = spatial_metric_l[0][1]; + ql[15] = spatial_metric_l[0][2]; + ql[16] = spatial_metric_l[1][0]; + ql[17] = spatial_metric_l[1][1]; + ql[18] = spatial_metric_l[1][2]; + ql[19] = spatial_metric_l[2][0]; + ql[20] = spatial_metric_l[2][1]; + ql[21] = spatial_metric_l[2][2]; + + ql[22] = extrinsic_curvature_l[0][0]; + ql[23] = extrinsic_curvature_l[0][1]; + ql[24] = extrinsic_curvature_l[0][2]; + ql[25] = extrinsic_curvature_l[1][0]; + ql[26] = extrinsic_curvature_l[1][1]; + ql[27] = extrinsic_curvature_l[1][2]; + ql[28] = extrinsic_curvature_l[2][0]; + ql[29] = extrinsic_curvature_l[2][1]; + ql[30] = extrinsic_curvature_l[2][2]; ql[31] = 1.0; - ql[32] = lapse_der_l[0]; ql[33] = lapse_der_l[1]; ql[34] = lapse_der_l[2]; - ql[35] = shift_der_l[0][0]; ql[36] = shift_der_l[0][1]; ql[37] = shift_der_l[0][2]; - ql[38] = shift_der_l[1][0]; ql[39] = shift_der_l[1][1]; ql[40] = shift_der_l[1][2]; - ql[41] = shift_der_l[2][0]; ql[42] = shift_der_l[2][1]; ql[43] = shift_der_l[2][2]; - - ql[44] = spatial_metric_der_l[0][0][0]; ql[45] = spatial_metric_der_l[0][0][1]; ql[46] = spatial_metric_der_l[0][0][2]; - ql[47] = spatial_metric_der_l[0][1][0]; ql[48] = spatial_metric_der_l[0][1][1]; ql[49] = spatial_metric_der_l[0][1][2]; - ql[50] = spatial_metric_der_l[0][2][0]; ql[51] = spatial_metric_der_l[0][2][1]; ql[52] = spatial_metric_der_l[0][2][2]; - - ql[53] = spatial_metric_der_l[1][0][0]; ql[54] = spatial_metric_der_l[1][0][1]; ql[55] = spatial_metric_der_l[1][0][2]; - ql[56] = spatial_metric_der_l[1][1][0]; ql[57] = spatial_metric_der_l[1][1][1]; ql[58] = spatial_metric_der_l[1][1][2]; - ql[59] = spatial_metric_der_l[1][2][0]; ql[60] = spatial_metric_der_l[1][2][1]; ql[61] = spatial_metric_der_l[1][2][2]; - - ql[62] = spatial_metric_der_l[2][0][0]; ql[63] = spatial_metric_der_l[2][0][1]; ql[64] = spatial_metric_der_l[2][0][2]; - ql[65] = spatial_metric_der_l[2][1][0]; ql[66] = spatial_metric_der_l[2][1][1]; ql[67] = spatial_metric_der_l[2][1][2]; - ql[68] = spatial_metric_der_l[2][2][0]; ql[69] = spatial_metric_der_l[2][2][1]; ql[70] = spatial_metric_der_l[2][2][2]; + ql[32] = lapse_der_l[0]; + ql[33] = lapse_der_l[1]; + ql[34] = lapse_der_l[2]; + ql[35] = shift_der_l[0][0]; + ql[36] = shift_der_l[0][1]; + ql[37] = shift_der_l[0][2]; + ql[38] = shift_der_l[1][0]; + ql[39] = shift_der_l[1][1]; + ql[40] = shift_der_l[1][2]; + ql[41] = shift_der_l[2][0]; + ql[42] = shift_der_l[2][1]; + ql[43] = shift_der_l[2][2]; + + ql[44] = spatial_metric_der_l[0][0][0]; + ql[45] = spatial_metric_der_l[0][0][1]; + ql[46] = spatial_metric_der_l[0][0][2]; + ql[47] = spatial_metric_der_l[0][1][0]; + ql[48] = spatial_metric_der_l[0][1][1]; + ql[49] = spatial_metric_der_l[0][1][2]; + ql[50] = spatial_metric_der_l[0][2][0]; + ql[51] = spatial_metric_der_l[0][2][1]; + ql[52] = spatial_metric_der_l[0][2][2]; + + ql[53] = spatial_metric_der_l[1][0][0]; + ql[54] = spatial_metric_der_l[1][0][1]; + ql[55] = spatial_metric_der_l[1][0][2]; + ql[56] = spatial_metric_der_l[1][1][0]; + ql[57] = spatial_metric_der_l[1][1][1]; + ql[58] = spatial_metric_der_l[1][1][2]; + ql[59] = spatial_metric_der_l[1][2][0]; + ql[60] = spatial_metric_der_l[1][2][1]; + ql[61] = spatial_metric_der_l[1][2][2]; + + ql[62] = spatial_metric_der_l[2][0][0]; + ql[63] = spatial_metric_der_l[2][0][1]; + ql[64] = spatial_metric_der_l[2][0][2]; + ql[65] = spatial_metric_der_l[2][1][0]; + ql[66] = spatial_metric_der_l[2][1][1]; + ql[67] = spatial_metric_der_l[2][1][2]; + ql[68] = spatial_metric_der_l[2][2][0]; + ql[69] = spatial_metric_der_l[2][2][1]; + ql[70] = spatial_metric_der_l[2][2][2]; ql[71] = 0.0; - ql[72] = x - 0.5; ql[73] = y; ql[74] = 0.0; + ql[72] = x - 0.5; + ql[73] = y; + ql[74] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; - qr[1] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); - qr[2] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); - qr[3] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); - qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); + qr[1] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); + qr[2] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); + qr[3] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); + qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - + ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); qr[5] = sqrt(spatial_det_r) * mag_x_r; qr[6] = sqrt(spatial_det_r) * mag_y_r; @@ -1498,55 +1905,85 @@ test_gr_mhd_waves_schwarzschild_ho() qr[8] = sqrt(spatial_det_r) * psi_r; qr[9] = lapse_r; - qr[10] = shift_r[0]; qr[11] = shift_r[1]; qr[12] = shift_r[2]; - - qr[13] = spatial_metric_r[0][0]; qr[14] = spatial_metric_r[0][1]; qr[15] = spatial_metric_r[0][2]; - qr[16] = spatial_metric_r[1][0]; qr[17] = spatial_metric_r[1][1]; qr[18] = spatial_metric_r[1][2]; - qr[19] = spatial_metric_r[2][0]; qr[20] = spatial_metric_r[2][1]; qr[21] = spatial_metric_r[2][2]; - - qr[22] = extrinsic_curvature_r[0][0]; qr[23] = extrinsic_curvature_r[0][1]; qr[24] = extrinsic_curvature_r[0][2]; - qr[25] = extrinsic_curvature_r[1][0]; qr[26] = extrinsic_curvature_r[1][1]; qr[27] = extrinsic_curvature_r[1][2]; - qr[28] = extrinsic_curvature_r[2][0]; qr[29] = extrinsic_curvature_r[2][1]; qr[30] = extrinsic_curvature_r[2][2]; + qr[10] = shift_r[0]; + qr[11] = shift_r[1]; + qr[12] = shift_r[2]; + + qr[13] = spatial_metric_r[0][0]; + qr[14] = spatial_metric_r[0][1]; + qr[15] = spatial_metric_r[0][2]; + qr[16] = spatial_metric_r[1][0]; + qr[17] = spatial_metric_r[1][1]; + qr[18] = spatial_metric_r[1][2]; + qr[19] = spatial_metric_r[2][0]; + qr[20] = spatial_metric_r[2][1]; + qr[21] = spatial_metric_r[2][2]; + + qr[22] = extrinsic_curvature_r[0][0]; + qr[23] = extrinsic_curvature_r[0][1]; + qr[24] = extrinsic_curvature_r[0][2]; + qr[25] = extrinsic_curvature_r[1][0]; + qr[26] = extrinsic_curvature_r[1][1]; + qr[27] = extrinsic_curvature_r[1][2]; + qr[28] = extrinsic_curvature_r[2][0]; + qr[29] = extrinsic_curvature_r[2][1]; + qr[30] = extrinsic_curvature_r[2][2]; qr[31] = 1.0; - qr[32] = lapse_der_r[0]; qr[33] = lapse_der_r[1]; qr[34] = lapse_der_r[2]; - qr[35] = shift_der_r[0][0]; qr[36] = shift_der_r[0][1]; qr[37] = shift_der_r[0][2]; - qr[38] = shift_der_r[1][0]; qr[39] = shift_der_r[1][1]; qr[40] = shift_der_r[1][2]; - qr[41] = shift_der_r[2][0]; qr[42] = shift_der_r[2][1]; qr[43] = shift_der_r[2][2]; - - qr[44] = spatial_metric_der_r[0][0][0]; qr[45] = spatial_metric_der_r[0][0][1]; qr[46] = spatial_metric_der_r[0][0][2]; - qr[47] = spatial_metric_der_r[0][1][0]; qr[48] = spatial_metric_der_r[0][1][1]; qr[49] = spatial_metric_der_r[0][1][2]; - qr[50] = spatial_metric_der_r[0][2][0]; qr[51] = spatial_metric_der_r[0][2][1]; qr[52] = spatial_metric_der_r[0][2][2]; - - qr[53] = spatial_metric_der_r[1][0][0]; qr[54] = spatial_metric_der_r[1][0][1]; qr[55] = spatial_metric_der_r[1][0][2]; - qr[56] = spatial_metric_der_r[1][1][0]; qr[57] = spatial_metric_der_r[1][1][1]; qr[58] = spatial_metric_der_r[1][1][2]; - qr[59] = spatial_metric_der_r[1][2][0]; qr[60] = spatial_metric_der_r[1][2][1]; qr[61] = spatial_metric_der_r[1][2][2]; - - qr[62] = spatial_metric_der_r[2][0][0]; qr[63] = spatial_metric_der_r[2][0][1]; qr[64] = spatial_metric_der_r[2][0][2]; - qr[65] = spatial_metric_der_r[2][1][0]; qr[66] = spatial_metric_der_r[2][1][1]; qr[67] = spatial_metric_der_r[2][1][2]; - qr[68] = spatial_metric_der_r[2][2][0]; qr[69] = spatial_metric_der_r[2][2][1]; qr[70] = spatial_metric_der_r[2][2][2]; + qr[32] = lapse_der_r[0]; + qr[33] = lapse_der_r[1]; + qr[34] = lapse_der_r[2]; + qr[35] = shift_der_r[0][0]; + qr[36] = shift_der_r[0][1]; + qr[37] = shift_der_r[0][2]; + qr[38] = shift_der_r[1][0]; + qr[39] = shift_der_r[1][1]; + qr[40] = shift_der_r[1][2]; + qr[41] = shift_der_r[2][0]; + qr[42] = shift_der_r[2][1]; + qr[43] = shift_der_r[2][2]; + + qr[44] = spatial_metric_der_r[0][0][0]; + qr[45] = spatial_metric_der_r[0][0][1]; + qr[46] = spatial_metric_der_r[0][0][2]; + qr[47] = spatial_metric_der_r[0][1][0]; + qr[48] = spatial_metric_der_r[0][1][1]; + qr[49] = spatial_metric_der_r[0][1][2]; + qr[50] = spatial_metric_der_r[0][2][0]; + qr[51] = spatial_metric_der_r[0][2][1]; + qr[52] = spatial_metric_der_r[0][2][2]; + + qr[53] = spatial_metric_der_r[1][0][0]; + qr[54] = spatial_metric_der_r[1][0][1]; + qr[55] = spatial_metric_der_r[1][0][2]; + qr[56] = spatial_metric_der_r[1][1][0]; + qr[57] = spatial_metric_der_r[1][1][1]; + qr[58] = spatial_metric_der_r[1][1][2]; + qr[59] = spatial_metric_der_r[1][2][0]; + qr[60] = spatial_metric_der_r[1][2][1]; + qr[61] = spatial_metric_der_r[1][2][2]; + + qr[62] = spatial_metric_der_r[2][0][0]; + qr[63] = spatial_metric_der_r[2][0][1]; + qr[64] = spatial_metric_der_r[2][0][2]; + qr[65] = spatial_metric_der_r[2][1][0]; + qr[66] = spatial_metric_der_r[2][1][1]; + qr[67] = spatial_metric_der_r[2][1][2]; + qr[68] = spatial_metric_der_r[2][2][0]; + qr[69] = spatial_metric_der_r[2][2][1]; + qr[70] = spatial_metric_der_r[2][2][2]; qr[71] = 0.0; - qr[72] = x + 0.5; qr[73] = y; qr[74] = 0.0; + qr[72] = x + 0.5; + qr[73] = y; + qr[74] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 75], waves_local[2 * 75]; @@ -1560,13 +1997,21 @@ test_gr_mhd_waves_schwarzschild_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[75], amdq_local[75]; - gkyl_wv_eqn_qfluct(gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_mhd, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75]); + gkyl_wv_eqn_rotate_to_global( + gr_mhd, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75] + ); } double apdq[75], amdq[75]; @@ -1582,7 +2027,7 @@ test_gr_mhd_waves_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_mhd, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1594,7 +2039,7 @@ test_gr_mhd_waves_schwarzschild_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1635,14 +2080,14 @@ test_gr_mhd_waves_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_mhd_waves_kerr_ho() +void test_gr_mhd_waves_kerr_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_mhd = gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd = + gkyl_wv_gr_mhd_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1660,10 +2105,10 @@ test_gr_mhd_waves_kerr_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1673,18 +2118,18 @@ test_gr_mhd_waves_kerr_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1703,20 +2148,46 @@ test_gr_mhd_waves_kerr_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1731,8 +2202,12 @@ test_gr_mhd_waves_kerr_ho() double *mag_l = gkyl_malloc(sizeof(double[3])); double *mag_r = gkyl_malloc(sizeof(double[3])); - mag_l[0] = mag_x_l; mag_l[1] = mag_y_l; mag_l[2] = mag_z_l; - mag_r[0] = mag_x_r; mag_r[1] = mag_y_r; mag_r[2] = mag_z_r; + mag_l[0] = mag_x_l; + mag_l[1] = mag_y_l; + mag_l[2] = mag_z_l; + mag_r[0] = mag_x_r; + mag_r[1] = mag_y_r; + mag_r[2] = mag_z_r; double *cov_mag_l = gkyl_malloc(sizeof(double[3])); double *cov_mag_r = gkyl_malloc(sizeof(double[3])); @@ -1757,7 +2232,7 @@ test_gr_mhd_waves_kerr_ho() cov_vel_r[i] += spatial_metric_r[i][j] * vel_r[j]; } } - + double b0_l = 0.0, b0_r = 0.0; for (int i = 0; i < 3; i++) { b0_l += W_l * mag_l[i] * (cov_vel_l[i] / lapse_l); @@ -1808,10 +2283,14 @@ test_gr_mhd_waves_kerr_ho() if (!in_excision_region_l && !in_excision_region_r) { double ql[75], qr[75]; ql[0] = sqrt(spatial_det_l) * rho_l * W_l; - ql[1] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); - ql[2] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); - ql[3] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); - ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); + ql[1] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); + ql[2] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); + ql[3] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); + ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - + ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); ql[5] = sqrt(spatial_det_l) * mag_x_l; ql[6] = sqrt(spatial_det_l) * mag_y_l; @@ -1819,43 +2298,89 @@ test_gr_mhd_waves_kerr_ho() ql[8] = sqrt(spatial_det_l) * psi_l; ql[9] = lapse_l; - ql[10] = shift_l[0]; ql[11] = shift_l[1]; ql[12] = shift_l[2]; - - ql[13] = spatial_metric_l[0][0]; ql[14] = spatial_metric_l[0][1]; ql[15] = spatial_metric_l[0][2]; - ql[16] = spatial_metric_l[1][0]; ql[17] = spatial_metric_l[1][1]; ql[18] = spatial_metric_l[1][2]; - ql[19] = spatial_metric_l[2][0]; ql[20] = spatial_metric_l[2][1]; ql[21] = spatial_metric_l[2][2]; - - ql[22] = extrinsic_curvature_l[0][0]; ql[23] = extrinsic_curvature_l[0][1]; ql[24] = extrinsic_curvature_l[0][2]; - ql[25] = extrinsic_curvature_l[1][0]; ql[26] = extrinsic_curvature_l[1][1]; ql[27] = extrinsic_curvature_l[1][2]; - ql[28] = extrinsic_curvature_l[2][0]; ql[29] = extrinsic_curvature_l[2][1]; ql[30] = extrinsic_curvature_l[2][2]; + ql[10] = shift_l[0]; + ql[11] = shift_l[1]; + ql[12] = shift_l[2]; + + ql[13] = spatial_metric_l[0][0]; + ql[14] = spatial_metric_l[0][1]; + ql[15] = spatial_metric_l[0][2]; + ql[16] = spatial_metric_l[1][0]; + ql[17] = spatial_metric_l[1][1]; + ql[18] = spatial_metric_l[1][2]; + ql[19] = spatial_metric_l[2][0]; + ql[20] = spatial_metric_l[2][1]; + ql[21] = spatial_metric_l[2][2]; + + ql[22] = extrinsic_curvature_l[0][0]; + ql[23] = extrinsic_curvature_l[0][1]; + ql[24] = extrinsic_curvature_l[0][2]; + ql[25] = extrinsic_curvature_l[1][0]; + ql[26] = extrinsic_curvature_l[1][1]; + ql[27] = extrinsic_curvature_l[1][2]; + ql[28] = extrinsic_curvature_l[2][0]; + ql[29] = extrinsic_curvature_l[2][1]; + ql[30] = extrinsic_curvature_l[2][2]; ql[31] = 1.0; - ql[32] = lapse_der_l[0]; ql[33] = lapse_der_l[1]; ql[34] = lapse_der_l[2]; - ql[35] = shift_der_l[0][0]; ql[36] = shift_der_l[0][1]; ql[37] = shift_der_l[0][2]; - ql[38] = shift_der_l[1][0]; ql[39] = shift_der_l[1][1]; ql[40] = shift_der_l[1][2]; - ql[41] = shift_der_l[2][0]; ql[42] = shift_der_l[2][1]; ql[43] = shift_der_l[2][2]; - - ql[44] = spatial_metric_der_l[0][0][0]; ql[45] = spatial_metric_der_l[0][0][1]; ql[46] = spatial_metric_der_l[0][0][2]; - ql[47] = spatial_metric_der_l[0][1][0]; ql[48] = spatial_metric_der_l[0][1][1]; ql[49] = spatial_metric_der_l[0][1][2]; - ql[50] = spatial_metric_der_l[0][2][0]; ql[51] = spatial_metric_der_l[0][2][1]; ql[52] = spatial_metric_der_l[0][2][2]; - - ql[53] = spatial_metric_der_l[1][0][0]; ql[54] = spatial_metric_der_l[1][0][1]; ql[55] = spatial_metric_der_l[1][0][2]; - ql[56] = spatial_metric_der_l[1][1][0]; ql[57] = spatial_metric_der_l[1][1][1]; ql[58] = spatial_metric_der_l[1][1][2]; - ql[59] = spatial_metric_der_l[1][2][0]; ql[60] = spatial_metric_der_l[1][2][1]; ql[61] = spatial_metric_der_l[1][2][2]; - - ql[62] = spatial_metric_der_l[2][0][0]; ql[63] = spatial_metric_der_l[2][0][1]; ql[64] = spatial_metric_der_l[2][0][2]; - ql[65] = spatial_metric_der_l[2][1][0]; ql[66] = spatial_metric_der_l[2][1][1]; ql[67] = spatial_metric_der_l[2][1][2]; - ql[68] = spatial_metric_der_l[2][2][0]; ql[69] = spatial_metric_der_l[2][2][1]; ql[70] = spatial_metric_der_l[2][2][2]; + ql[32] = lapse_der_l[0]; + ql[33] = lapse_der_l[1]; + ql[34] = lapse_der_l[2]; + ql[35] = shift_der_l[0][0]; + ql[36] = shift_der_l[0][1]; + ql[37] = shift_der_l[0][2]; + ql[38] = shift_der_l[1][0]; + ql[39] = shift_der_l[1][1]; + ql[40] = shift_der_l[1][2]; + ql[41] = shift_der_l[2][0]; + ql[42] = shift_der_l[2][1]; + ql[43] = shift_der_l[2][2]; + + ql[44] = spatial_metric_der_l[0][0][0]; + ql[45] = spatial_metric_der_l[0][0][1]; + ql[46] = spatial_metric_der_l[0][0][2]; + ql[47] = spatial_metric_der_l[0][1][0]; + ql[48] = spatial_metric_der_l[0][1][1]; + ql[49] = spatial_metric_der_l[0][1][2]; + ql[50] = spatial_metric_der_l[0][2][0]; + ql[51] = spatial_metric_der_l[0][2][1]; + ql[52] = spatial_metric_der_l[0][2][2]; + + ql[53] = spatial_metric_der_l[1][0][0]; + ql[54] = spatial_metric_der_l[1][0][1]; + ql[55] = spatial_metric_der_l[1][0][2]; + ql[56] = spatial_metric_der_l[1][1][0]; + ql[57] = spatial_metric_der_l[1][1][1]; + ql[58] = spatial_metric_der_l[1][1][2]; + ql[59] = spatial_metric_der_l[1][2][0]; + ql[60] = spatial_metric_der_l[1][2][1]; + ql[61] = spatial_metric_der_l[1][2][2]; + + ql[62] = spatial_metric_der_l[2][0][0]; + ql[63] = spatial_metric_der_l[2][0][1]; + ql[64] = spatial_metric_der_l[2][0][2]; + ql[65] = spatial_metric_der_l[2][1][0]; + ql[66] = spatial_metric_der_l[2][1][1]; + ql[67] = spatial_metric_der_l[2][1][2]; + ql[68] = spatial_metric_der_l[2][2][0]; + ql[69] = spatial_metric_der_l[2][2][1]; + ql[70] = spatial_metric_der_l[2][2][2]; ql[71] = 0.0; - ql[72] = x - 0.5; ql[73] = y; ql[74] = 0.0; + ql[72] = x - 0.5; + ql[73] = y; + ql[74] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; - qr[1] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); - qr[2] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); - qr[3] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); - qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); + qr[1] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); + qr[2] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); + qr[3] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); + qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - + ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); qr[5] = sqrt(spatial_det_r) * mag_x_r; qr[6] = sqrt(spatial_det_r) * mag_y_r; @@ -1863,55 +2388,85 @@ test_gr_mhd_waves_kerr_ho() qr[8] = sqrt(spatial_det_r) * psi_r; qr[9] = lapse_r; - qr[10] = shift_r[0]; qr[11] = shift_r[1]; qr[12] = shift_r[2]; - - qr[13] = spatial_metric_r[0][0]; qr[14] = spatial_metric_r[0][1]; qr[15] = spatial_metric_r[0][2]; - qr[16] = spatial_metric_r[1][0]; qr[17] = spatial_metric_r[1][1]; qr[18] = spatial_metric_r[1][2]; - qr[19] = spatial_metric_r[2][0]; qr[20] = spatial_metric_r[2][1]; qr[21] = spatial_metric_r[2][2]; - - qr[22] = extrinsic_curvature_r[0][0]; qr[23] = extrinsic_curvature_r[0][1]; qr[24] = extrinsic_curvature_r[0][2]; - qr[25] = extrinsic_curvature_r[1][0]; qr[26] = extrinsic_curvature_r[1][1]; qr[27] = extrinsic_curvature_r[1][2]; - qr[28] = extrinsic_curvature_r[2][0]; qr[29] = extrinsic_curvature_r[2][1]; qr[30] = extrinsic_curvature_r[2][2]; + qr[10] = shift_r[0]; + qr[11] = shift_r[1]; + qr[12] = shift_r[2]; + + qr[13] = spatial_metric_r[0][0]; + qr[14] = spatial_metric_r[0][1]; + qr[15] = spatial_metric_r[0][2]; + qr[16] = spatial_metric_r[1][0]; + qr[17] = spatial_metric_r[1][1]; + qr[18] = spatial_metric_r[1][2]; + qr[19] = spatial_metric_r[2][0]; + qr[20] = spatial_metric_r[2][1]; + qr[21] = spatial_metric_r[2][2]; + + qr[22] = extrinsic_curvature_r[0][0]; + qr[23] = extrinsic_curvature_r[0][1]; + qr[24] = extrinsic_curvature_r[0][2]; + qr[25] = extrinsic_curvature_r[1][0]; + qr[26] = extrinsic_curvature_r[1][1]; + qr[27] = extrinsic_curvature_r[1][2]; + qr[28] = extrinsic_curvature_r[2][0]; + qr[29] = extrinsic_curvature_r[2][1]; + qr[30] = extrinsic_curvature_r[2][2]; qr[31] = 1.0; - qr[32] = lapse_der_r[0]; qr[33] = lapse_der_r[1]; qr[34] = lapse_der_r[2]; - qr[35] = shift_der_r[0][0]; qr[36] = shift_der_r[0][1]; qr[37] = shift_der_r[0][2]; - qr[38] = shift_der_r[1][0]; qr[39] = shift_der_r[1][1]; qr[40] = shift_der_r[1][2]; - qr[41] = shift_der_r[2][0]; qr[42] = shift_der_r[2][1]; qr[43] = shift_der_r[2][2]; - - qr[44] = spatial_metric_der_r[0][0][0]; qr[45] = spatial_metric_der_r[0][0][1]; qr[46] = spatial_metric_der_r[0][0][2]; - qr[47] = spatial_metric_der_r[0][1][0]; qr[48] = spatial_metric_der_r[0][1][1]; qr[49] = spatial_metric_der_r[0][1][2]; - qr[50] = spatial_metric_der_r[0][2][0]; qr[51] = spatial_metric_der_r[0][2][1]; qr[52] = spatial_metric_der_r[0][2][2]; - - qr[53] = spatial_metric_der_r[1][0][0]; qr[54] = spatial_metric_der_r[1][0][1]; qr[55] = spatial_metric_der_r[1][0][2]; - qr[56] = spatial_metric_der_r[1][1][0]; qr[57] = spatial_metric_der_r[1][1][1]; qr[58] = spatial_metric_der_r[1][1][2]; - qr[59] = spatial_metric_der_r[1][2][0]; qr[60] = spatial_metric_der_r[1][2][1]; qr[61] = spatial_metric_der_r[1][2][2]; - - qr[62] = spatial_metric_der_r[2][0][0]; qr[63] = spatial_metric_der_r[2][0][1]; qr[64] = spatial_metric_der_r[2][0][2]; - qr[65] = spatial_metric_der_r[2][1][0]; qr[66] = spatial_metric_der_r[2][1][1]; qr[67] = spatial_metric_der_r[2][1][2]; - qr[68] = spatial_metric_der_r[2][2][0]; qr[69] = spatial_metric_der_r[2][2][1]; qr[70] = spatial_metric_der_r[2][2][2]; + qr[32] = lapse_der_r[0]; + qr[33] = lapse_der_r[1]; + qr[34] = lapse_der_r[2]; + qr[35] = shift_der_r[0][0]; + qr[36] = shift_der_r[0][1]; + qr[37] = shift_der_r[0][2]; + qr[38] = shift_der_r[1][0]; + qr[39] = shift_der_r[1][1]; + qr[40] = shift_der_r[1][2]; + qr[41] = shift_der_r[2][0]; + qr[42] = shift_der_r[2][1]; + qr[43] = shift_der_r[2][2]; + + qr[44] = spatial_metric_der_r[0][0][0]; + qr[45] = spatial_metric_der_r[0][0][1]; + qr[46] = spatial_metric_der_r[0][0][2]; + qr[47] = spatial_metric_der_r[0][1][0]; + qr[48] = spatial_metric_der_r[0][1][1]; + qr[49] = spatial_metric_der_r[0][1][2]; + qr[50] = spatial_metric_der_r[0][2][0]; + qr[51] = spatial_metric_der_r[0][2][1]; + qr[52] = spatial_metric_der_r[0][2][2]; + + qr[53] = spatial_metric_der_r[1][0][0]; + qr[54] = spatial_metric_der_r[1][0][1]; + qr[55] = spatial_metric_der_r[1][0][2]; + qr[56] = spatial_metric_der_r[1][1][0]; + qr[57] = spatial_metric_der_r[1][1][1]; + qr[58] = spatial_metric_der_r[1][1][2]; + qr[59] = spatial_metric_der_r[1][2][0]; + qr[60] = spatial_metric_der_r[1][2][1]; + qr[61] = spatial_metric_der_r[1][2][2]; + + qr[62] = spatial_metric_der_r[2][0][0]; + qr[63] = spatial_metric_der_r[2][0][1]; + qr[64] = spatial_metric_der_r[2][0][2]; + qr[65] = spatial_metric_der_r[2][1][0]; + qr[66] = spatial_metric_der_r[2][1][1]; + qr[67] = spatial_metric_der_r[2][1][2]; + qr[68] = spatial_metric_der_r[2][2][0]; + qr[69] = spatial_metric_der_r[2][2][1]; + qr[70] = spatial_metric_der_r[2][2][2]; qr[71] = 0.0; - qr[72] = x + 0.5; qr[73] = y; qr[74] = 0.0; + qr[72] = x + 0.5; + qr[73] = y; + qr[74] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 75], waves_local[2 * 75]; @@ -1925,13 +2480,21 @@ test_gr_mhd_waves_kerr_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[75], amdq_local[75]; - gkyl_wv_eqn_qfluct(gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_mhd, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_mhd, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75]); + gkyl_wv_eqn_rotate_to_global( + gr_mhd, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75] + ); } double apdq[75], amdq[75]; @@ -1947,7 +2510,7 @@ test_gr_mhd_waves_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_mhd, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1959,7 +2522,7 @@ test_gr_mhd_waves_kerr_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -2001,11 +2564,11 @@ test_gr_mhd_waves_kerr_ho() } TEST_LIST = { - { "gr_mhd_basic_minkowski_ho", test_gr_mhd_basic_minkowski_ho}, - { "gr_mhd_basic_schwarzschild_ho", test_gr_mhd_basic_schwarzschild_ho }, - { "gr_mhd_basic_kerr_ho", test_gr_mhd_basic_kerr_ho }, - { "gr_mhd_waves_minkowski_ho", test_gr_mhd_waves_minkowski_ho }, - { "gr_mhd_waves_schwarzschild_ho", test_gr_mhd_waves_schwarzschild_ho }, - { "gr_mhd_waves_kerr_ho", test_gr_mhd_waves_kerr_ho }, - { NULL, NULL }, + {"gr_mhd_basic_minkowski_ho", test_gr_mhd_basic_minkowski_ho}, + {"gr_mhd_basic_schwarzschild_ho", test_gr_mhd_basic_schwarzschild_ho}, + {"gr_mhd_basic_kerr_ho", test_gr_mhd_basic_kerr_ho}, + {"gr_mhd_waves_minkowski_ho", test_gr_mhd_waves_minkowski_ho}, + {"gr_mhd_waves_schwarzschild_ho", test_gr_mhd_waves_schwarzschild_ho}, + {"gr_mhd_waves_kerr_ho", test_gr_mhd_waves_kerr_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_gr_mhd_tetrad.c b/moments/unit/ctest_wv_gr_mhd_tetrad.c index 4fb8c425ba..3648ce274a 100644 --- a/moments/unit/ctest_wv_gr_mhd_tetrad.c +++ b/moments/unit/ctest_wv_gr_mhd_tetrad.c @@ -6,17 +6,18 @@ #include #include -void -test_gr_mhd_tetrad_basic_minkowski_ho() +void test_gr_mhd_tetrad_basic_minkowski_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new( + gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_mhd_tetrad->num_equations == 75 ); - TEST_CHECK( gr_mhd_tetrad->num_waves == 2 ); + TEST_CHECK(gr_mhd_tetrad->num_equations == 75); + TEST_CHECK(gr_mhd_tetrad->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -30,25 +31,25 @@ test_gr_mhd_tetrad_basic_minkowski_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -59,16 +60,28 @@ test_gr_mhd_tetrad_basic_minkowski_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -80,7 +93,9 @@ test_gr_mhd_tetrad_basic_minkowski_ho() double W = 1.0 / sqrt(1.0 - v_sq); double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -99,7 +114,7 @@ test_gr_mhd_tetrad_basic_minkowski_ho() cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); @@ -139,7 +154,8 @@ test_gr_mhd_tetrad_basic_minkowski_ho() q[1] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); q[2] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); q[3] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); - q[4] = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); + q[4] = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); q[5] = sqrt(spatial_det) * mag_x; q[6] = sqrt(spatial_det) * mag_y; @@ -147,51 +163,93 @@ test_gr_mhd_tetrad_basic_minkowski_ho() q[8] = sqrt(spatial_det) * psi; q[9] = lapse; - q[10] = shift[0]; q[11] = shift[1]; q[12] = shift[2]; - - q[13] = spatial_metric[0][0]; q[14] = spatial_metric[0][1]; q[15] = spatial_metric[0][2]; - q[16] = spatial_metric[1][0]; q[17] = spatial_metric[1][1]; q[18] = spatial_metric[1][2]; - q[19] = spatial_metric[2][0]; q[20] = spatial_metric[2][1]; q[21] = spatial_metric[2][2]; - - q[22] = extrinsic_curvature[0][0]; q[23] = extrinsic_curvature[0][1]; q[24] = extrinsic_curvature[0][2]; - q[25] = extrinsic_curvature[1][0]; q[26] = extrinsic_curvature[1][1]; q[27] = extrinsic_curvature[1][2]; - q[28] = extrinsic_curvature[2][0]; q[29] = extrinsic_curvature[2][1]; q[30] = extrinsic_curvature[2][2]; + q[10] = shift[0]; + q[11] = shift[1]; + q[12] = shift[2]; + + q[13] = spatial_metric[0][0]; + q[14] = spatial_metric[0][1]; + q[15] = spatial_metric[0][2]; + q[16] = spatial_metric[1][0]; + q[17] = spatial_metric[1][1]; + q[18] = spatial_metric[1][2]; + q[19] = spatial_metric[2][0]; + q[20] = spatial_metric[2][1]; + q[21] = spatial_metric[2][2]; + + q[22] = extrinsic_curvature[0][0]; + q[23] = extrinsic_curvature[0][1]; + q[24] = extrinsic_curvature[0][2]; + q[25] = extrinsic_curvature[1][0]; + q[26] = extrinsic_curvature[1][1]; + q[27] = extrinsic_curvature[1][2]; + q[28] = extrinsic_curvature[2][0]; + q[29] = extrinsic_curvature[2][1]; + q[30] = extrinsic_curvature[2][2]; q[31] = 1.0; - q[32] = lapse_der[0]; q[33] = lapse_der[1]; q[34] = lapse_der[2]; - q[35] = shift_der[0][0]; q[36] = shift_der[0][1]; q[37] = shift_der[0][2]; - q[38] = shift_der[1][0]; q[39] = shift_der[1][1]; q[40] = shift_der[1][2]; - q[41] = shift_der[2][0]; q[42] = shift_der[2][1]; q[43] = shift_der[2][2]; - - q[44] = spatial_metric_der[0][0][0]; q[45] = spatial_metric_der[0][0][1]; q[46] = spatial_metric_der[0][0][2]; - q[47] = spatial_metric_der[0][1][0]; q[48] = spatial_metric_der[0][1][1]; q[49] = spatial_metric_der[0][1][2]; - q[50] = spatial_metric_der[0][2][0]; q[51] = spatial_metric_der[0][2][1]; q[52] = spatial_metric_der[0][2][2]; - - q[53] = spatial_metric_der[1][0][0]; q[54] = spatial_metric_der[1][0][1]; q[55] = spatial_metric_der[1][0][2]; - q[56] = spatial_metric_der[1][1][0]; q[57] = spatial_metric_der[1][1][1]; q[58] = spatial_metric_der[1][1][2]; - q[59] = spatial_metric_der[1][2][0]; q[60] = spatial_metric_der[1][2][1]; q[61] = spatial_metric_der[1][2][2]; - - q[62] = spatial_metric_der[2][0][0]; q[63] = spatial_metric_der[2][0][1]; q[64] = spatial_metric_der[2][0][2]; - q[65] = spatial_metric_der[2][1][0]; q[66] = spatial_metric_der[2][1][1]; q[67] = spatial_metric_der[2][1][2]; - q[68] = spatial_metric_der[2][2][0]; q[69] = spatial_metric_der[2][2][1]; q[70] = spatial_metric_der[2][2][2]; + q[32] = lapse_der[0]; + q[33] = lapse_der[1]; + q[34] = lapse_der[2]; + q[35] = shift_der[0][0]; + q[36] = shift_der[0][1]; + q[37] = shift_der[0][2]; + q[38] = shift_der[1][0]; + q[39] = shift_der[1][1]; + q[40] = shift_der[1][2]; + q[41] = shift_der[2][0]; + q[42] = shift_der[2][1]; + q[43] = shift_der[2][2]; + + q[44] = spatial_metric_der[0][0][0]; + q[45] = spatial_metric_der[0][0][1]; + q[46] = spatial_metric_der[0][0][2]; + q[47] = spatial_metric_der[0][1][0]; + q[48] = spatial_metric_der[0][1][1]; + q[49] = spatial_metric_der[0][1][2]; + q[50] = spatial_metric_der[0][2][0]; + q[51] = spatial_metric_der[0][2][1]; + q[52] = spatial_metric_der[0][2][2]; + + q[53] = spatial_metric_der[1][0][0]; + q[54] = spatial_metric_der[1][0][1]; + q[55] = spatial_metric_der[1][0][2]; + q[56] = spatial_metric_der[1][1][0]; + q[57] = spatial_metric_der[1][1][1]; + q[58] = spatial_metric_der[1][1][2]; + q[59] = spatial_metric_der[1][2][0]; + q[60] = spatial_metric_der[1][2][1]; + q[61] = spatial_metric_der[1][2][2]; + + q[62] = spatial_metric_der[2][0][0]; + q[63] = spatial_metric_der[2][0][1]; + q[64] = spatial_metric_der[2][0][2]; + q[65] = spatial_metric_der[2][1][0]; + q[66] = spatial_metric_der[2][1][1]; + q[67] = spatial_metric_der[2][1][2]; + q[68] = spatial_metric_der[2][2][0]; + q[69] = spatial_metric_der[2][2][1]; + q[70] = spatial_metric_der[2][2][2]; q[71] = 0.0; - q[72] = x; q[73] = y; q[74] = 0.0; + q[72] = x; + q[73] = y; + q[74] = 0.0; double prims[75]; gkyl_gr_mhd_tetrad_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-8) ); - - TEST_CHECK( gkyl_compare(prims[5], mag_x, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[6], mag_y, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[7], mag_z, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[8], psi, 1e-8) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-8)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-8)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-8)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-8)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-8)); + + TEST_CHECK(gkyl_compare(prims[5], mag_x, 1e-8)); + TEST_CHECK(gkyl_compare(prims[6], mag_y, 1e-8)); + TEST_CHECK(gkyl_compare(prims[7], mag_z, 1e-8)); + TEST_CHECK(gkyl_compare(prims[8], psi, 1e-8)); double D = rho * W; double Sx = (rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]); @@ -200,72 +258,85 @@ test_gr_mhd_tetrad_basic_minkowski_ho() double Etot = (rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W); double fluxes[3][9] = { - { (lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + (p_star * vel[0]) - ((lapse * b0 * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[0]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + (p_star * vel[1]) - ((lapse * b0 * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[1]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + (p_star * vel[2]) - ((lapse * b0 * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[2]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z) }, + {(lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + (p_star * vel[0]) - + ((lapse * b0 * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[0]) - + ((vel[0] - (shift[0] / lapse)) * mag[0]) + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + (p_star * vel[1]) - + ((lapse * b0 * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[1]) - + ((vel[1] - (shift[1] / lapse)) * mag[1]) + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + (p_star * vel[2]) - + ((lapse * b0 * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[2]) - + ((vel[2] - (shift[2] / lapse)) * mag[2]) + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[75], flux_local_sr[75], flux_local_gr[75], flux[75]; for (int d = 0; d < 3; d++) { gr_mhd_tetrad->rotate_to_local_func(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], q, q_local); gkyl_gr_mhd_tetrad_flux(gas_gamma, light_speed, b_fact, q_local, flux_local_sr); - gkyl_gr_mhd_tetrad_flux_correction(gas_gamma, light_speed, b_fact, q_local, flux_local_sr, flux_local_gr); - gr_mhd_tetrad->rotate_to_global_func(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gkyl_gr_mhd_tetrad_flux_correction( + gas_gamma, light_speed, b_fact, q_local, flux_local_sr, flux_local_gr + ); + gr_mhd_tetrad->rotate_to_global_func( + gr_mhd_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-8) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-8)); } } - + double q_l[75], q_g[75]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[75], q1[75]; @@ -273,7 +344,7 @@ test_gr_mhd_tetrad_basic_minkowski_ho() gr_mhd_tetrad->riem_to_cons(gr_mhd_tetrad, q_local, w1, q1); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } @@ -281,7 +352,7 @@ test_gr_mhd_tetrad_basic_minkowski_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -307,17 +378,18 @@ test_gr_mhd_tetrad_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_mhd_tetrad_basic_schwarzschild_ho() +void test_gr_mhd_tetrad_basic_schwarzschild_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new( + gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_mhd_tetrad->num_equations == 75 ); - TEST_CHECK( gr_mhd_tetrad->num_waves == 2 ); + TEST_CHECK(gr_mhd_tetrad->num_equations == 75); + TEST_CHECK(gr_mhd_tetrad->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -331,25 +403,25 @@ test_gr_mhd_tetrad_basic_schwarzschild_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -360,16 +432,28 @@ test_gr_mhd_tetrad_basic_schwarzschild_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -381,7 +465,9 @@ test_gr_mhd_tetrad_basic_schwarzschild_ho() double W = 1.0 / sqrt(1.0 - v_sq); double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -400,7 +486,7 @@ test_gr_mhd_tetrad_basic_schwarzschild_ho() cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); @@ -438,10 +524,14 @@ test_gr_mhd_tetrad_basic_schwarzschild_ho() if (!in_excision_region) { double q[75]; q[0] = sqrt(spatial_det) * rho * W; - q[1] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); - q[2] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); - q[3] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); - q[4] = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); + q[1] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); + q[2] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); + q[3] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); + q[4] = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); q[5] = sqrt(spatial_det) * mag_x; q[6] = sqrt(spatial_det) * mag_y; @@ -449,51 +539,93 @@ test_gr_mhd_tetrad_basic_schwarzschild_ho() q[8] = sqrt(spatial_det) * psi; q[9] = lapse; - q[10] = shift[0]; q[11] = shift[1]; q[12] = shift[2]; - - q[13] = spatial_metric[0][0]; q[14] = spatial_metric[0][1]; q[15] = spatial_metric[0][2]; - q[16] = spatial_metric[1][0]; q[17] = spatial_metric[1][1]; q[18] = spatial_metric[1][2]; - q[19] = spatial_metric[2][0]; q[20] = spatial_metric[2][1]; q[21] = spatial_metric[2][2]; - - q[22] = extrinsic_curvature[0][0]; q[23] = extrinsic_curvature[0][1]; q[24] = extrinsic_curvature[0][2]; - q[25] = extrinsic_curvature[1][0]; q[26] = extrinsic_curvature[1][1]; q[27] = extrinsic_curvature[1][2]; - q[28] = extrinsic_curvature[2][0]; q[29] = extrinsic_curvature[2][1]; q[30] = extrinsic_curvature[2][2]; + q[10] = shift[0]; + q[11] = shift[1]; + q[12] = shift[2]; + + q[13] = spatial_metric[0][0]; + q[14] = spatial_metric[0][1]; + q[15] = spatial_metric[0][2]; + q[16] = spatial_metric[1][0]; + q[17] = spatial_metric[1][1]; + q[18] = spatial_metric[1][2]; + q[19] = spatial_metric[2][0]; + q[20] = spatial_metric[2][1]; + q[21] = spatial_metric[2][2]; + + q[22] = extrinsic_curvature[0][0]; + q[23] = extrinsic_curvature[0][1]; + q[24] = extrinsic_curvature[0][2]; + q[25] = extrinsic_curvature[1][0]; + q[26] = extrinsic_curvature[1][1]; + q[27] = extrinsic_curvature[1][2]; + q[28] = extrinsic_curvature[2][0]; + q[29] = extrinsic_curvature[2][1]; + q[30] = extrinsic_curvature[2][2]; q[31] = 1.0; - q[32] = lapse_der[0]; q[33] = lapse_der[1]; q[34] = lapse_der[2]; - q[35] = shift_der[0][0]; q[36] = shift_der[0][1]; q[37] = shift_der[0][2]; - q[38] = shift_der[1][0]; q[39] = shift_der[1][1]; q[40] = shift_der[1][2]; - q[41] = shift_der[2][0]; q[42] = shift_der[2][1]; q[43] = shift_der[2][2]; - - q[44] = spatial_metric_der[0][0][0]; q[45] = spatial_metric_der[0][0][1]; q[46] = spatial_metric_der[0][0][2]; - q[47] = spatial_metric_der[0][1][0]; q[48] = spatial_metric_der[0][1][1]; q[49] = spatial_metric_der[0][1][2]; - q[50] = spatial_metric_der[0][2][0]; q[51] = spatial_metric_der[0][2][1]; q[52] = spatial_metric_der[0][2][2]; - - q[53] = spatial_metric_der[1][0][0]; q[54] = spatial_metric_der[1][0][1]; q[55] = spatial_metric_der[1][0][2]; - q[56] = spatial_metric_der[1][1][0]; q[57] = spatial_metric_der[1][1][1]; q[58] = spatial_metric_der[1][1][2]; - q[59] = spatial_metric_der[1][2][0]; q[60] = spatial_metric_der[1][2][1]; q[61] = spatial_metric_der[1][2][2]; - - q[62] = spatial_metric_der[2][0][0]; q[63] = spatial_metric_der[2][0][1]; q[64] = spatial_metric_der[2][0][2]; - q[65] = spatial_metric_der[2][1][0]; q[66] = spatial_metric_der[2][1][1]; q[67] = spatial_metric_der[2][1][2]; - q[68] = spatial_metric_der[2][2][0]; q[69] = spatial_metric_der[2][2][1]; q[70] = spatial_metric_der[2][2][2]; + q[32] = lapse_der[0]; + q[33] = lapse_der[1]; + q[34] = lapse_der[2]; + q[35] = shift_der[0][0]; + q[36] = shift_der[0][1]; + q[37] = shift_der[0][2]; + q[38] = shift_der[1][0]; + q[39] = shift_der[1][1]; + q[40] = shift_der[1][2]; + q[41] = shift_der[2][0]; + q[42] = shift_der[2][1]; + q[43] = shift_der[2][2]; + + q[44] = spatial_metric_der[0][0][0]; + q[45] = spatial_metric_der[0][0][1]; + q[46] = spatial_metric_der[0][0][2]; + q[47] = spatial_metric_der[0][1][0]; + q[48] = spatial_metric_der[0][1][1]; + q[49] = spatial_metric_der[0][1][2]; + q[50] = spatial_metric_der[0][2][0]; + q[51] = spatial_metric_der[0][2][1]; + q[52] = spatial_metric_der[0][2][2]; + + q[53] = spatial_metric_der[1][0][0]; + q[54] = spatial_metric_der[1][0][1]; + q[55] = spatial_metric_der[1][0][2]; + q[56] = spatial_metric_der[1][1][0]; + q[57] = spatial_metric_der[1][1][1]; + q[58] = spatial_metric_der[1][1][2]; + q[59] = spatial_metric_der[1][2][0]; + q[60] = spatial_metric_der[1][2][1]; + q[61] = spatial_metric_der[1][2][2]; + + q[62] = spatial_metric_der[2][0][0]; + q[63] = spatial_metric_der[2][0][1]; + q[64] = spatial_metric_der[2][0][2]; + q[65] = spatial_metric_der[2][1][0]; + q[66] = spatial_metric_der[2][1][1]; + q[67] = spatial_metric_der[2][1][2]; + q[68] = spatial_metric_der[2][2][0]; + q[69] = spatial_metric_der[2][2][1]; + q[70] = spatial_metric_der[2][2][2]; q[71] = 0.0; - q[72] = x; q[73] = y; q[74] = 0.0; + q[72] = x; + q[73] = y; + q[74] = 0.0; double prims[75]; gkyl_gr_mhd_tetrad_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); - - TEST_CHECK( gkyl_compare(prims[5], mag_x, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[6], mag_y, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[7], mag_z, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[8], psi, 1e-8) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], mag_x, 1e-8)); + TEST_CHECK(gkyl_compare(prims[6], mag_y, 1e-8)); + TEST_CHECK(gkyl_compare(prims[7], mag_z, 1e-8)); + TEST_CHECK(gkyl_compare(prims[8], psi, 1e-8)); double D = rho * W; double Sx = (rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]); @@ -502,72 +634,88 @@ test_gr_mhd_tetrad_basic_schwarzschild_ho() double Etot = (rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W); double fluxes[3][9] = { - { (lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + (p_star * vel[0]) - ((lapse * b0 * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[0]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + (p_star * vel[1]) - ((lapse * b0 * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[1]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + (p_star * vel[2]) - ((lapse * b0 * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[2]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z) }, + {(lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + + (p_star * vel[0]) - ((lapse * b0 * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[0]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + + (p_star * vel[1]) - ((lapse * b0 * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[1]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + + (p_star * vel[2]) - ((lapse * b0 * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[2]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[75], flux_local_sr[75], flux_local_gr[75], flux[75]; for (int d = 0; d < 3; d++) { gr_mhd_tetrad->rotate_to_local_func(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], q, q_local); gkyl_gr_mhd_tetrad_flux(gas_gamma, light_speed, b_fact, q_local, flux_local_sr); - gkyl_gr_mhd_tetrad_flux_correction(gas_gamma, light_speed, b_fact, q_local, flux_local_sr, flux_local_gr); - gr_mhd_tetrad->rotate_to_global_func(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gkyl_gr_mhd_tetrad_flux_correction( + gas_gamma, light_speed, b_fact, q_local, flux_local_sr, flux_local_gr + ); + gr_mhd_tetrad->rotate_to_global_func( + gr_mhd_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } - + double q_l[75], q_g[75]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[75], q1[75]; @@ -575,7 +723,7 @@ test_gr_mhd_tetrad_basic_schwarzschild_ho() gr_mhd_tetrad->riem_to_cons(gr_mhd_tetrad, q_local, w1, q1); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -584,7 +732,7 @@ test_gr_mhd_tetrad_basic_schwarzschild_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -610,17 +758,18 @@ test_gr_mhd_tetrad_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_mhd_tetrad_basic_kerr_ho() +void test_gr_mhd_tetrad_basic_kerr_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new( + gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_mhd_tetrad->num_equations == 75 ); - TEST_CHECK( gr_mhd_tetrad->num_waves == 2 ); + TEST_CHECK(gr_mhd_tetrad->num_equations == 75); + TEST_CHECK(gr_mhd_tetrad->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -634,25 +783,25 @@ test_gr_mhd_tetrad_basic_kerr_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -663,16 +812,28 @@ test_gr_mhd_tetrad_basic_kerr_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -684,7 +845,9 @@ test_gr_mhd_tetrad_basic_kerr_ho() double W = 1.0 / sqrt(1.0 - v_sq); double *mag = gkyl_malloc(sizeof(double[3])); - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double *cov_mag = gkyl_malloc(sizeof(double[3])); for (int i = 0; i < 3; i++) { @@ -703,7 +866,7 @@ test_gr_mhd_tetrad_basic_kerr_ho() cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); @@ -741,10 +904,14 @@ test_gr_mhd_tetrad_basic_kerr_ho() if (!in_excision_region) { double q[75]; q[0] = sqrt(spatial_det) * rho * W; - q[1] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); - q[2] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); - q[3] = sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); - q[4] = sqrt(spatial_det) * ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); + q[1] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0])); + q[2] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[1]) - (lapse * b0 * cov_b[1])); + q[3] = + sqrt(spatial_det) * ((rho * h_star * (W * W) * cov_vel[2]) - (lapse * b0 * cov_b[2])); + q[4] = sqrt(spatial_det) * + ((rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W)); q[5] = sqrt(spatial_det) * mag_x; q[6] = sqrt(spatial_det) * mag_y; @@ -752,51 +919,93 @@ test_gr_mhd_tetrad_basic_kerr_ho() q[8] = sqrt(spatial_det) * psi; q[9] = lapse; - q[10] = shift[0]; q[11] = shift[1]; q[12] = shift[2]; - - q[13] = spatial_metric[0][0]; q[14] = spatial_metric[0][1]; q[15] = spatial_metric[0][2]; - q[16] = spatial_metric[1][0]; q[17] = spatial_metric[1][1]; q[18] = spatial_metric[1][2]; - q[19] = spatial_metric[2][0]; q[20] = spatial_metric[2][1]; q[21] = spatial_metric[2][2]; - - q[22] = extrinsic_curvature[0][0]; q[23] = extrinsic_curvature[0][1]; q[24] = extrinsic_curvature[0][2]; - q[25] = extrinsic_curvature[1][0]; q[26] = extrinsic_curvature[1][1]; q[27] = extrinsic_curvature[1][2]; - q[28] = extrinsic_curvature[2][0]; q[29] = extrinsic_curvature[2][1]; q[30] = extrinsic_curvature[2][2]; + q[10] = shift[0]; + q[11] = shift[1]; + q[12] = shift[2]; + + q[13] = spatial_metric[0][0]; + q[14] = spatial_metric[0][1]; + q[15] = spatial_metric[0][2]; + q[16] = spatial_metric[1][0]; + q[17] = spatial_metric[1][1]; + q[18] = spatial_metric[1][2]; + q[19] = spatial_metric[2][0]; + q[20] = spatial_metric[2][1]; + q[21] = spatial_metric[2][2]; + + q[22] = extrinsic_curvature[0][0]; + q[23] = extrinsic_curvature[0][1]; + q[24] = extrinsic_curvature[0][2]; + q[25] = extrinsic_curvature[1][0]; + q[26] = extrinsic_curvature[1][1]; + q[27] = extrinsic_curvature[1][2]; + q[28] = extrinsic_curvature[2][0]; + q[29] = extrinsic_curvature[2][1]; + q[30] = extrinsic_curvature[2][2]; q[31] = 1.0; - q[32] = lapse_der[0]; q[33] = lapse_der[1]; q[34] = lapse_der[2]; - q[35] = shift_der[0][0]; q[36] = shift_der[0][1]; q[37] = shift_der[0][2]; - q[38] = shift_der[1][0]; q[39] = shift_der[1][1]; q[40] = shift_der[1][2]; - q[41] = shift_der[2][0]; q[42] = shift_der[2][1]; q[43] = shift_der[2][2]; - - q[44] = spatial_metric_der[0][0][0]; q[45] = spatial_metric_der[0][0][1]; q[46] = spatial_metric_der[0][0][2]; - q[47] = spatial_metric_der[0][1][0]; q[48] = spatial_metric_der[0][1][1]; q[49] = spatial_metric_der[0][1][2]; - q[50] = spatial_metric_der[0][2][0]; q[51] = spatial_metric_der[0][2][1]; q[52] = spatial_metric_der[0][2][2]; - - q[53] = spatial_metric_der[1][0][0]; q[54] = spatial_metric_der[1][0][1]; q[55] = spatial_metric_der[1][0][2]; - q[56] = spatial_metric_der[1][1][0]; q[57] = spatial_metric_der[1][1][1]; q[58] = spatial_metric_der[1][1][2]; - q[59] = spatial_metric_der[1][2][0]; q[60] = spatial_metric_der[1][2][1]; q[61] = spatial_metric_der[1][2][2]; - - q[62] = spatial_metric_der[2][0][0]; q[63] = spatial_metric_der[2][0][1]; q[64] = spatial_metric_der[2][0][2]; - q[65] = spatial_metric_der[2][1][0]; q[66] = spatial_metric_der[2][1][1]; q[67] = spatial_metric_der[2][1][2]; - q[68] = spatial_metric_der[2][2][0]; q[69] = spatial_metric_der[2][2][1]; q[70] = spatial_metric_der[2][2][2]; + q[32] = lapse_der[0]; + q[33] = lapse_der[1]; + q[34] = lapse_der[2]; + q[35] = shift_der[0][0]; + q[36] = shift_der[0][1]; + q[37] = shift_der[0][2]; + q[38] = shift_der[1][0]; + q[39] = shift_der[1][1]; + q[40] = shift_der[1][2]; + q[41] = shift_der[2][0]; + q[42] = shift_der[2][1]; + q[43] = shift_der[2][2]; + + q[44] = spatial_metric_der[0][0][0]; + q[45] = spatial_metric_der[0][0][1]; + q[46] = spatial_metric_der[0][0][2]; + q[47] = spatial_metric_der[0][1][0]; + q[48] = spatial_metric_der[0][1][1]; + q[49] = spatial_metric_der[0][1][2]; + q[50] = spatial_metric_der[0][2][0]; + q[51] = spatial_metric_der[0][2][1]; + q[52] = spatial_metric_der[0][2][2]; + + q[53] = spatial_metric_der[1][0][0]; + q[54] = spatial_metric_der[1][0][1]; + q[55] = spatial_metric_der[1][0][2]; + q[56] = spatial_metric_der[1][1][0]; + q[57] = spatial_metric_der[1][1][1]; + q[58] = spatial_metric_der[1][1][2]; + q[59] = spatial_metric_der[1][2][0]; + q[60] = spatial_metric_der[1][2][1]; + q[61] = spatial_metric_der[1][2][2]; + + q[62] = spatial_metric_der[2][0][0]; + q[63] = spatial_metric_der[2][0][1]; + q[64] = spatial_metric_der[2][0][2]; + q[65] = spatial_metric_der[2][1][0]; + q[66] = spatial_metric_der[2][1][1]; + q[67] = spatial_metric_der[2][1][2]; + q[68] = spatial_metric_der[2][2][0]; + q[69] = spatial_metric_der[2][2][1]; + q[70] = spatial_metric_der[2][2][2]; q[71] = 0.0; - q[72] = x; q[73] = y; q[74] = 0.0; + q[72] = x; + q[73] = y; + q[74] = 0.0; double prims[75]; gkyl_gr_mhd_tetrad_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); - - TEST_CHECK( gkyl_compare(prims[5], mag_x, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[6], mag_y, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[7], mag_z, 1e-8) ); - TEST_CHECK( gkyl_compare(prims[8], psi, 1e-8) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], mag_x, 1e-8)); + TEST_CHECK(gkyl_compare(prims[6], mag_y, 1e-8)); + TEST_CHECK(gkyl_compare(prims[7], mag_z, 1e-8)); + TEST_CHECK(gkyl_compare(prims[8], psi, 1e-8)); double D = rho * W; double Sx = (rho * h_star * (W * W) * cov_vel[0]) - (lapse * b0 * cov_b[0]); @@ -805,72 +1014,88 @@ test_gr_mhd_tetrad_basic_kerr_ho() double Etot = (rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W); double fluxes[3][9] = { - { (lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + (p_star * vel[0]) - ((lapse * b0 * mag[0]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[0]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + (p_star * vel[1]) - ((lapse * b0 * mag[1]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[1]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y) }, - { (lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + (p_star * vel[2]) - ((lapse * b0 * mag[2]) / W)), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), - (lapse * sqrt(spatial_det)) * (((vel[2] - (shift[2] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[2]) + (b_fact * psi)), - (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z) }, + {(lapse * sqrt(spatial_det)) * (D * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[0] - (shift[0] / lapse))) + p_star - ((cov_b[0] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[0] - (shift[0] / lapse))) - ((cov_b[1] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[0] - (shift[0] / lapse))) - ((cov_b[2] * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[0] - (shift[0] / lapse))) + + (p_star * vel[0]) - ((lapse * b0 * mag[0]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[0]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * + (((vel[0] - (shift[0] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[0])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[1] - (shift[1] / lapse))) - ((cov_b[0] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[1] - (shift[1] / lapse))) + p_star - ((cov_b[1] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[1] - (shift[1] / lapse))) - ((cov_b[2] * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[1] - (shift[1] / lapse))) + + (p_star * vel[1]) - ((lapse * b0 * mag[1]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[1]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * + (((vel[1] - (shift[1] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[1])), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_y)}, + {(lapse * sqrt(spatial_det)) * (D * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + ((Sx * (vel[2] - (shift[2] / lapse))) - ((cov_b[0] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sy * (vel[2] - (shift[2] / lapse))) - ((cov_b[1] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + ((Sz * (vel[2] - (shift[2] / lapse))) + p_star - ((cov_b[2] * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * ((Etot * (vel[2] - (shift[2] / lapse))) + + (p_star * vel[2]) - ((lapse * b0 * mag[2]) / W)), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[0]) - ((vel[0] - (shift[0] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[1]) - ((vel[1] - (shift[1] / lapse)) * mag[2])), + (lapse * sqrt(spatial_det)) * + (((vel[2] - (shift[2] / lapse)) * mag[2]) - ((vel[2] - (shift[2] / lapse)) * mag[2]) + + (b_fact * psi)), + (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_z)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[75], flux_local_sr[75], flux_local_gr[75], flux[75]; for (int d = 0; d < 3; d++) { gr_mhd_tetrad->rotate_to_local_func(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], q, q_local); gkyl_gr_mhd_tetrad_flux(gas_gamma, light_speed, b_fact, q_local, flux_local_sr); - gkyl_gr_mhd_tetrad_flux_correction(gas_gamma, light_speed, b_fact, q_local, flux_local_sr, flux_local_gr); - gr_mhd_tetrad->rotate_to_global_func(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gkyl_gr_mhd_tetrad_flux_correction( + gas_gamma, light_speed, b_fact, q_local, flux_local_sr, flux_local_gr + ); + gr_mhd_tetrad->rotate_to_global_func( + gr_mhd_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } - + double q_l[75], q_g[75]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[75], q1[75]; @@ -878,7 +1103,7 @@ test_gr_mhd_tetrad_basic_kerr_ho() gr_mhd_tetrad->riem_to_cons(gr_mhd_tetrad, q_local, w1, q1); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -887,7 +1112,7 @@ test_gr_mhd_tetrad_basic_kerr_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -913,20 +1138,21 @@ test_gr_mhd_tetrad_basic_kerr_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_mhd_tetrad_waves_minkowski_ho() +void test_gr_mhd_tetrad_waves_minkowski_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new( + gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { double x = 0.1 * x_ind; double y = 0.1 * y_ind; - + double rho_l = 1.0, u_l = 0.1, v_l = 0.2, w_l = 0.3, p_l = 1.5; double mag_x_l = 0.3, mag_y_l = 0.2, mag_z_l = 0.1, psi_l = 0.05; double rho_r = 0.1, u_r = 0.2, v_r = 0.3, w_r = 0.4, p_r = 0.15; @@ -937,10 +1163,10 @@ test_gr_mhd_tetrad_waves_minkowski_ho() double *shift_l = gkyl_malloc(sizeof(double[3])); double *shift_r = gkyl_malloc(sizeof(double[3])); - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -950,18 +1176,18 @@ test_gr_mhd_tetrad_waves_minkowski_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -978,20 +1204,46 @@ test_gr_mhd_tetrad_waves_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1006,8 +1258,12 @@ test_gr_mhd_tetrad_waves_minkowski_ho() double *mag_l = gkyl_malloc(sizeof(double[3])); double *mag_r = gkyl_malloc(sizeof(double[3])); - mag_l[0] = mag_x_l; mag_l[1] = mag_y_l; mag_l[2] = mag_z_l; - mag_r[0] = mag_x_r; mag_r[1] = mag_y_r; mag_r[2] = mag_z_r; + mag_l[0] = mag_x_l; + mag_l[1] = mag_y_l; + mag_l[2] = mag_z_l; + mag_r[0] = mag_x_r; + mag_r[1] = mag_y_r; + mag_r[2] = mag_z_r; double *cov_mag_l = gkyl_malloc(sizeof(double[3])); double *cov_mag_r = gkyl_malloc(sizeof(double[3])); @@ -1032,7 +1288,7 @@ test_gr_mhd_tetrad_waves_minkowski_ho() cov_vel_r[i] += spatial_metric_r[i][j] * vel_r[j]; } } - + double b0_l = 0.0, b0_r = 0.0; for (int i = 0; i < 3; i++) { b0_l += W_l * mag_l[i] * (cov_vel_l[i] / lapse_l); @@ -1082,10 +1338,14 @@ test_gr_mhd_tetrad_waves_minkowski_ho() double ql[75], qr[75]; ql[0] = sqrt(spatial_det_l) * rho_l * W_l; - ql[1] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); - ql[2] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); - ql[3] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); - ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); + ql[1] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); + ql[2] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); + ql[3] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); + ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - + ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); ql[5] = sqrt(spatial_det_l) * mag_x_l; ql[6] = sqrt(spatial_det_l) * mag_y_l; @@ -1093,43 +1353,89 @@ test_gr_mhd_tetrad_waves_minkowski_ho() ql[8] = sqrt(spatial_det_l) * psi_l; ql[9] = lapse_l; - ql[10] = shift_l[0]; ql[11] = shift_l[1]; ql[12] = shift_l[2]; - - ql[13] = spatial_metric_l[0][0]; ql[14] = spatial_metric_l[0][1]; ql[15] = spatial_metric_l[0][2]; - ql[16] = spatial_metric_l[1][0]; ql[17] = spatial_metric_l[1][1]; ql[18] = spatial_metric_l[1][2]; - ql[19] = spatial_metric_l[2][0]; ql[20] = spatial_metric_l[2][1]; ql[21] = spatial_metric_l[2][2]; - - ql[22] = extrinsic_curvature_l[0][0]; ql[23] = extrinsic_curvature_l[0][1]; ql[24] = extrinsic_curvature_l[0][2]; - ql[25] = extrinsic_curvature_l[1][0]; ql[26] = extrinsic_curvature_l[1][1]; ql[27] = extrinsic_curvature_l[1][2]; - ql[28] = extrinsic_curvature_l[2][0]; ql[29] = extrinsic_curvature_l[2][1]; ql[30] = extrinsic_curvature_l[2][2]; + ql[10] = shift_l[0]; + ql[11] = shift_l[1]; + ql[12] = shift_l[2]; + + ql[13] = spatial_metric_l[0][0]; + ql[14] = spatial_metric_l[0][1]; + ql[15] = spatial_metric_l[0][2]; + ql[16] = spatial_metric_l[1][0]; + ql[17] = spatial_metric_l[1][1]; + ql[18] = spatial_metric_l[1][2]; + ql[19] = spatial_metric_l[2][0]; + ql[20] = spatial_metric_l[2][1]; + ql[21] = spatial_metric_l[2][2]; + + ql[22] = extrinsic_curvature_l[0][0]; + ql[23] = extrinsic_curvature_l[0][1]; + ql[24] = extrinsic_curvature_l[0][2]; + ql[25] = extrinsic_curvature_l[1][0]; + ql[26] = extrinsic_curvature_l[1][1]; + ql[27] = extrinsic_curvature_l[1][2]; + ql[28] = extrinsic_curvature_l[2][0]; + ql[29] = extrinsic_curvature_l[2][1]; + ql[30] = extrinsic_curvature_l[2][2]; ql[31] = 1.0; - ql[32] = lapse_der_l[0]; ql[33] = lapse_der_l[1]; ql[34] = lapse_der_l[2]; - ql[35] = shift_der_l[0][0]; ql[36] = shift_der_l[0][1]; ql[37] = shift_der_l[0][2]; - ql[38] = shift_der_l[1][0]; ql[39] = shift_der_l[1][1]; ql[40] = shift_der_l[1][2]; - ql[41] = shift_der_l[2][0]; ql[42] = shift_der_l[2][1]; ql[43] = shift_der_l[2][2]; - - ql[44] = spatial_metric_der_l[0][0][0]; ql[45] = spatial_metric_der_l[0][0][1]; ql[46] = spatial_metric_der_l[0][0][2]; - ql[47] = spatial_metric_der_l[0][1][0]; ql[48] = spatial_metric_der_l[0][1][1]; ql[49] = spatial_metric_der_l[0][1][2]; - ql[50] = spatial_metric_der_l[0][2][0]; ql[51] = spatial_metric_der_l[0][2][1]; ql[52] = spatial_metric_der_l[0][2][2]; - - ql[53] = spatial_metric_der_l[1][0][0]; ql[54] = spatial_metric_der_l[1][0][1]; ql[55] = spatial_metric_der_l[1][0][2]; - ql[56] = spatial_metric_der_l[1][1][0]; ql[57] = spatial_metric_der_l[1][1][1]; ql[58] = spatial_metric_der_l[1][1][2]; - ql[59] = spatial_metric_der_l[1][2][0]; ql[60] = spatial_metric_der_l[1][2][1]; ql[61] = spatial_metric_der_l[1][2][2]; - - ql[62] = spatial_metric_der_l[2][0][0]; ql[63] = spatial_metric_der_l[2][0][1]; ql[64] = spatial_metric_der_l[2][0][2]; - ql[65] = spatial_metric_der_l[2][1][0]; ql[66] = spatial_metric_der_l[2][1][1]; ql[67] = spatial_metric_der_l[2][1][2]; - ql[68] = spatial_metric_der_l[2][2][0]; ql[69] = spatial_metric_der_l[2][2][1]; ql[70] = spatial_metric_der_l[2][2][2]; + ql[32] = lapse_der_l[0]; + ql[33] = lapse_der_l[1]; + ql[34] = lapse_der_l[2]; + ql[35] = shift_der_l[0][0]; + ql[36] = shift_der_l[0][1]; + ql[37] = shift_der_l[0][2]; + ql[38] = shift_der_l[1][0]; + ql[39] = shift_der_l[1][1]; + ql[40] = shift_der_l[1][2]; + ql[41] = shift_der_l[2][0]; + ql[42] = shift_der_l[2][1]; + ql[43] = shift_der_l[2][2]; + + ql[44] = spatial_metric_der_l[0][0][0]; + ql[45] = spatial_metric_der_l[0][0][1]; + ql[46] = spatial_metric_der_l[0][0][2]; + ql[47] = spatial_metric_der_l[0][1][0]; + ql[48] = spatial_metric_der_l[0][1][1]; + ql[49] = spatial_metric_der_l[0][1][2]; + ql[50] = spatial_metric_der_l[0][2][0]; + ql[51] = spatial_metric_der_l[0][2][1]; + ql[52] = spatial_metric_der_l[0][2][2]; + + ql[53] = spatial_metric_der_l[1][0][0]; + ql[54] = spatial_metric_der_l[1][0][1]; + ql[55] = spatial_metric_der_l[1][0][2]; + ql[56] = spatial_metric_der_l[1][1][0]; + ql[57] = spatial_metric_der_l[1][1][1]; + ql[58] = spatial_metric_der_l[1][1][2]; + ql[59] = spatial_metric_der_l[1][2][0]; + ql[60] = spatial_metric_der_l[1][2][1]; + ql[61] = spatial_metric_der_l[1][2][2]; + + ql[62] = spatial_metric_der_l[2][0][0]; + ql[63] = spatial_metric_der_l[2][0][1]; + ql[64] = spatial_metric_der_l[2][0][2]; + ql[65] = spatial_metric_der_l[2][1][0]; + ql[66] = spatial_metric_der_l[2][1][1]; + ql[67] = spatial_metric_der_l[2][1][2]; + ql[68] = spatial_metric_der_l[2][2][0]; + ql[69] = spatial_metric_der_l[2][2][1]; + ql[70] = spatial_metric_der_l[2][2][2]; ql[71] = 0.0; - ql[72] = x - 0.5; ql[73] = y; ql[74] = 0.0; + ql[72] = x - 0.5; + ql[73] = y; + ql[74] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; - qr[1] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); - qr[2] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); - qr[3] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); - qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); + qr[1] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); + qr[2] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); + qr[3] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); + qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - + ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); qr[5] = sqrt(spatial_det_r) * mag_x_r; qr[6] = sqrt(spatial_det_r) * mag_y_r; @@ -1137,55 +1443,85 @@ test_gr_mhd_tetrad_waves_minkowski_ho() qr[8] = sqrt(spatial_det_r) * psi_r; qr[9] = lapse_r; - qr[10] = shift_r[0]; qr[11] = shift_r[1]; qr[12] = shift_r[2]; - - qr[13] = spatial_metric_r[0][0]; qr[14] = spatial_metric_r[0][1]; qr[15] = spatial_metric_r[0][2]; - qr[16] = spatial_metric_r[1][0]; qr[17] = spatial_metric_r[1][1]; qr[18] = spatial_metric_r[1][2]; - qr[19] = spatial_metric_r[2][0]; qr[20] = spatial_metric_r[2][1]; qr[21] = spatial_metric_r[2][2]; - - qr[22] = extrinsic_curvature_r[0][0]; qr[23] = extrinsic_curvature_r[0][1]; qr[24] = extrinsic_curvature_r[0][2]; - qr[25] = extrinsic_curvature_r[1][0]; qr[26] = extrinsic_curvature_r[1][1]; qr[27] = extrinsic_curvature_r[1][2]; - qr[28] = extrinsic_curvature_r[2][0]; qr[29] = extrinsic_curvature_r[2][1]; qr[30] = extrinsic_curvature_r[2][2]; + qr[10] = shift_r[0]; + qr[11] = shift_r[1]; + qr[12] = shift_r[2]; + + qr[13] = spatial_metric_r[0][0]; + qr[14] = spatial_metric_r[0][1]; + qr[15] = spatial_metric_r[0][2]; + qr[16] = spatial_metric_r[1][0]; + qr[17] = spatial_metric_r[1][1]; + qr[18] = spatial_metric_r[1][2]; + qr[19] = spatial_metric_r[2][0]; + qr[20] = spatial_metric_r[2][1]; + qr[21] = spatial_metric_r[2][2]; + + qr[22] = extrinsic_curvature_r[0][0]; + qr[23] = extrinsic_curvature_r[0][1]; + qr[24] = extrinsic_curvature_r[0][2]; + qr[25] = extrinsic_curvature_r[1][0]; + qr[26] = extrinsic_curvature_r[1][1]; + qr[27] = extrinsic_curvature_r[1][2]; + qr[28] = extrinsic_curvature_r[2][0]; + qr[29] = extrinsic_curvature_r[2][1]; + qr[30] = extrinsic_curvature_r[2][2]; qr[31] = 1.0; - qr[32] = lapse_der_r[0]; qr[33] = lapse_der_r[1]; qr[34] = lapse_der_r[2]; - qr[35] = shift_der_r[0][0]; qr[36] = shift_der_r[0][1]; qr[37] = shift_der_r[0][2]; - qr[38] = shift_der_r[1][0]; qr[39] = shift_der_r[1][1]; qr[40] = shift_der_r[1][2]; - qr[41] = shift_der_r[2][0]; qr[42] = shift_der_r[2][1]; qr[43] = shift_der_r[2][2]; - - qr[44] = spatial_metric_der_r[0][0][0]; qr[45] = spatial_metric_der_r[0][0][1]; qr[46] = spatial_metric_der_r[0][0][2]; - qr[47] = spatial_metric_der_r[0][1][0]; qr[48] = spatial_metric_der_r[0][1][1]; qr[49] = spatial_metric_der_r[0][1][2]; - qr[50] = spatial_metric_der_r[0][2][0]; qr[51] = spatial_metric_der_r[0][2][1]; qr[52] = spatial_metric_der_r[0][2][2]; - - qr[53] = spatial_metric_der_r[1][0][0]; qr[54] = spatial_metric_der_r[1][0][1]; qr[55] = spatial_metric_der_r[1][0][2]; - qr[56] = spatial_metric_der_r[1][1][0]; qr[57] = spatial_metric_der_r[1][1][1]; qr[58] = spatial_metric_der_r[1][1][2]; - qr[59] = spatial_metric_der_r[1][2][0]; qr[60] = spatial_metric_der_r[1][2][1]; qr[61] = spatial_metric_der_r[1][2][2]; - - qr[62] = spatial_metric_der_r[2][0][0]; qr[63] = spatial_metric_der_r[2][0][1]; qr[64] = spatial_metric_der_r[2][0][2]; - qr[65] = spatial_metric_der_r[2][1][0]; qr[66] = spatial_metric_der_r[2][1][1]; qr[67] = spatial_metric_der_r[2][1][2]; - qr[68] = spatial_metric_der_r[2][2][0]; qr[69] = spatial_metric_der_r[2][2][1]; qr[70] = spatial_metric_der_r[2][2][2]; + qr[32] = lapse_der_r[0]; + qr[33] = lapse_der_r[1]; + qr[34] = lapse_der_r[2]; + qr[35] = shift_der_r[0][0]; + qr[36] = shift_der_r[0][1]; + qr[37] = shift_der_r[0][2]; + qr[38] = shift_der_r[1][0]; + qr[39] = shift_der_r[1][1]; + qr[40] = shift_der_r[1][2]; + qr[41] = shift_der_r[2][0]; + qr[42] = shift_der_r[2][1]; + qr[43] = shift_der_r[2][2]; + + qr[44] = spatial_metric_der_r[0][0][0]; + qr[45] = spatial_metric_der_r[0][0][1]; + qr[46] = spatial_metric_der_r[0][0][2]; + qr[47] = spatial_metric_der_r[0][1][0]; + qr[48] = spatial_metric_der_r[0][1][1]; + qr[49] = spatial_metric_der_r[0][1][2]; + qr[50] = spatial_metric_der_r[0][2][0]; + qr[51] = spatial_metric_der_r[0][2][1]; + qr[52] = spatial_metric_der_r[0][2][2]; + + qr[53] = spatial_metric_der_r[1][0][0]; + qr[54] = spatial_metric_der_r[1][0][1]; + qr[55] = spatial_metric_der_r[1][0][2]; + qr[56] = spatial_metric_der_r[1][1][0]; + qr[57] = spatial_metric_der_r[1][1][1]; + qr[58] = spatial_metric_der_r[1][1][2]; + qr[59] = spatial_metric_der_r[1][2][0]; + qr[60] = spatial_metric_der_r[1][2][1]; + qr[61] = spatial_metric_der_r[1][2][2]; + + qr[62] = spatial_metric_der_r[2][0][0]; + qr[63] = spatial_metric_der_r[2][0][1]; + qr[64] = spatial_metric_der_r[2][0][2]; + qr[65] = spatial_metric_der_r[2][1][0]; + qr[66] = spatial_metric_der_r[2][1][1]; + qr[67] = spatial_metric_der_r[2][1][2]; + qr[68] = spatial_metric_der_r[2][2][0]; + qr[69] = spatial_metric_der_r[2][2][1]; + qr[70] = spatial_metric_der_r[2][2][2]; qr[71] = 0.0; - qr[72] = x + 0.5; qr[73] = y; qr[74] = 0.0; + qr[72] = x + 0.5; + qr[73] = y; + qr[74] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 75], waves_local[2 * 75]; @@ -1199,13 +1535,21 @@ test_gr_mhd_tetrad_waves_minkowski_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[75], amdq_local[75]; - gkyl_wv_eqn_qfluct(gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75]); + gkyl_wv_eqn_rotate_to_global( + gr_mhd_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75] + ); } double apdq[75], amdq[75]; @@ -1217,15 +1561,19 @@ test_gr_mhd_tetrad_waves_minkowski_ho() gkyl_gr_mhd_tetrad_flux(gas_gamma, light_speed, b_fact, qr_local, fr_local_sr); double fl_local_gr[75], fr_local_gr[75]; - gkyl_gr_mhd_tetrad_flux_correction(gas_gamma, light_speed, b_fact, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_mhd_tetrad_flux_correction(gas_gamma, light_speed, b_fact, qr_local, fr_local_sr, fr_local_gr); + gkyl_gr_mhd_tetrad_flux_correction( + gas_gamma, light_speed, b_fact, ql_local, fl_local_sr, fl_local_gr + ); + gkyl_gr_mhd_tetrad_flux_correction( + gas_gamma, light_speed, b_fact, qr_local, fr_local_sr, fr_local_gr + ); double fl[75], fr[75]; gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); } } @@ -1236,7 +1584,7 @@ test_gr_mhd_tetrad_waves_minkowski_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1277,14 +1625,15 @@ test_gr_mhd_tetrad_waves_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_mhd_tetrad_waves_schwarzschild_ho() +void test_gr_mhd_tetrad_waves_schwarzschild_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new( + gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1302,10 +1651,10 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1315,18 +1664,18 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1345,20 +1694,46 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1373,8 +1748,12 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() double *mag_l = gkyl_malloc(sizeof(double[3])); double *mag_r = gkyl_malloc(sizeof(double[3])); - mag_l[0] = mag_x_l; mag_l[1] = mag_y_l; mag_l[2] = mag_z_l; - mag_r[0] = mag_x_r; mag_r[1] = mag_y_r; mag_r[2] = mag_z_r; + mag_l[0] = mag_x_l; + mag_l[1] = mag_y_l; + mag_l[2] = mag_z_l; + mag_r[0] = mag_x_r; + mag_r[1] = mag_y_r; + mag_r[2] = mag_z_r; double *cov_mag_l = gkyl_malloc(sizeof(double[3])); double *cov_mag_r = gkyl_malloc(sizeof(double[3])); @@ -1399,7 +1778,7 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() cov_vel_r[i] += spatial_metric_r[i][j] * vel_r[j]; } } - + double b0_l = 0.0, b0_r = 0.0; for (int i = 0; i < 3; i++) { b0_l += W_l * mag_l[i] * (cov_vel_l[i] / lapse_l); @@ -1450,10 +1829,14 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() if (!in_excision_region_l && !in_excision_region_r) { double ql[75], qr[75]; ql[0] = sqrt(spatial_det_l) * rho_l * W_l; - ql[1] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); - ql[2] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); - ql[3] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); - ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); + ql[1] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); + ql[2] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); + ql[3] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); + ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - + ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); ql[5] = sqrt(spatial_det_l) * mag_x_l; ql[6] = sqrt(spatial_det_l) * mag_y_l; @@ -1461,43 +1844,89 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() ql[8] = sqrt(spatial_det_l) * psi_l; ql[9] = lapse_l; - ql[10] = shift_l[0]; ql[11] = shift_l[1]; ql[12] = shift_l[2]; - - ql[13] = spatial_metric_l[0][0]; ql[14] = spatial_metric_l[0][1]; ql[15] = spatial_metric_l[0][2]; - ql[16] = spatial_metric_l[1][0]; ql[17] = spatial_metric_l[1][1]; ql[18] = spatial_metric_l[1][2]; - ql[19] = spatial_metric_l[2][0]; ql[20] = spatial_metric_l[2][1]; ql[21] = spatial_metric_l[2][2]; - - ql[22] = extrinsic_curvature_l[0][0]; ql[23] = extrinsic_curvature_l[0][1]; ql[24] = extrinsic_curvature_l[0][2]; - ql[25] = extrinsic_curvature_l[1][0]; ql[26] = extrinsic_curvature_l[1][1]; ql[27] = extrinsic_curvature_l[1][2]; - ql[28] = extrinsic_curvature_l[2][0]; ql[29] = extrinsic_curvature_l[2][1]; ql[30] = extrinsic_curvature_l[2][2]; + ql[10] = shift_l[0]; + ql[11] = shift_l[1]; + ql[12] = shift_l[2]; + + ql[13] = spatial_metric_l[0][0]; + ql[14] = spatial_metric_l[0][1]; + ql[15] = spatial_metric_l[0][2]; + ql[16] = spatial_metric_l[1][0]; + ql[17] = spatial_metric_l[1][1]; + ql[18] = spatial_metric_l[1][2]; + ql[19] = spatial_metric_l[2][0]; + ql[20] = spatial_metric_l[2][1]; + ql[21] = spatial_metric_l[2][2]; + + ql[22] = extrinsic_curvature_l[0][0]; + ql[23] = extrinsic_curvature_l[0][1]; + ql[24] = extrinsic_curvature_l[0][2]; + ql[25] = extrinsic_curvature_l[1][0]; + ql[26] = extrinsic_curvature_l[1][1]; + ql[27] = extrinsic_curvature_l[1][2]; + ql[28] = extrinsic_curvature_l[2][0]; + ql[29] = extrinsic_curvature_l[2][1]; + ql[30] = extrinsic_curvature_l[2][2]; ql[31] = 1.0; - ql[32] = lapse_der_l[0]; ql[33] = lapse_der_l[1]; ql[34] = lapse_der_l[2]; - ql[35] = shift_der_l[0][0]; ql[36] = shift_der_l[0][1]; ql[37] = shift_der_l[0][2]; - ql[38] = shift_der_l[1][0]; ql[39] = shift_der_l[1][1]; ql[40] = shift_der_l[1][2]; - ql[41] = shift_der_l[2][0]; ql[42] = shift_der_l[2][1]; ql[43] = shift_der_l[2][2]; - - ql[44] = spatial_metric_der_l[0][0][0]; ql[45] = spatial_metric_der_l[0][0][1]; ql[46] = spatial_metric_der_l[0][0][2]; - ql[47] = spatial_metric_der_l[0][1][0]; ql[48] = spatial_metric_der_l[0][1][1]; ql[49] = spatial_metric_der_l[0][1][2]; - ql[50] = spatial_metric_der_l[0][2][0]; ql[51] = spatial_metric_der_l[0][2][1]; ql[52] = spatial_metric_der_l[0][2][2]; - - ql[53] = spatial_metric_der_l[1][0][0]; ql[54] = spatial_metric_der_l[1][0][1]; ql[55] = spatial_metric_der_l[1][0][2]; - ql[56] = spatial_metric_der_l[1][1][0]; ql[57] = spatial_metric_der_l[1][1][1]; ql[58] = spatial_metric_der_l[1][1][2]; - ql[59] = spatial_metric_der_l[1][2][0]; ql[60] = spatial_metric_der_l[1][2][1]; ql[61] = spatial_metric_der_l[1][2][2]; - - ql[62] = spatial_metric_der_l[2][0][0]; ql[63] = spatial_metric_der_l[2][0][1]; ql[64] = spatial_metric_der_l[2][0][2]; - ql[65] = spatial_metric_der_l[2][1][0]; ql[66] = spatial_metric_der_l[2][1][1]; ql[67] = spatial_metric_der_l[2][1][2]; - ql[68] = spatial_metric_der_l[2][2][0]; ql[69] = spatial_metric_der_l[2][2][1]; ql[70] = spatial_metric_der_l[2][2][2]; + ql[32] = lapse_der_l[0]; + ql[33] = lapse_der_l[1]; + ql[34] = lapse_der_l[2]; + ql[35] = shift_der_l[0][0]; + ql[36] = shift_der_l[0][1]; + ql[37] = shift_der_l[0][2]; + ql[38] = shift_der_l[1][0]; + ql[39] = shift_der_l[1][1]; + ql[40] = shift_der_l[1][2]; + ql[41] = shift_der_l[2][0]; + ql[42] = shift_der_l[2][1]; + ql[43] = shift_der_l[2][2]; + + ql[44] = spatial_metric_der_l[0][0][0]; + ql[45] = spatial_metric_der_l[0][0][1]; + ql[46] = spatial_metric_der_l[0][0][2]; + ql[47] = spatial_metric_der_l[0][1][0]; + ql[48] = spatial_metric_der_l[0][1][1]; + ql[49] = spatial_metric_der_l[0][1][2]; + ql[50] = spatial_metric_der_l[0][2][0]; + ql[51] = spatial_metric_der_l[0][2][1]; + ql[52] = spatial_metric_der_l[0][2][2]; + + ql[53] = spatial_metric_der_l[1][0][0]; + ql[54] = spatial_metric_der_l[1][0][1]; + ql[55] = spatial_metric_der_l[1][0][2]; + ql[56] = spatial_metric_der_l[1][1][0]; + ql[57] = spatial_metric_der_l[1][1][1]; + ql[58] = spatial_metric_der_l[1][1][2]; + ql[59] = spatial_metric_der_l[1][2][0]; + ql[60] = spatial_metric_der_l[1][2][1]; + ql[61] = spatial_metric_der_l[1][2][2]; + + ql[62] = spatial_metric_der_l[2][0][0]; + ql[63] = spatial_metric_der_l[2][0][1]; + ql[64] = spatial_metric_der_l[2][0][2]; + ql[65] = spatial_metric_der_l[2][1][0]; + ql[66] = spatial_metric_der_l[2][1][1]; + ql[67] = spatial_metric_der_l[2][1][2]; + ql[68] = spatial_metric_der_l[2][2][0]; + ql[69] = spatial_metric_der_l[2][2][1]; + ql[70] = spatial_metric_der_l[2][2][2]; ql[71] = 0.0; - ql[72] = x - 0.5; ql[73] = y; ql[74] = 0.0; + ql[72] = x - 0.5; + ql[73] = y; + ql[74] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; - qr[1] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); - qr[2] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); - qr[3] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); - qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); + qr[1] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); + qr[2] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); + qr[3] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); + qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - + ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); qr[5] = sqrt(spatial_det_r) * mag_x_r; qr[6] = sqrt(spatial_det_r) * mag_y_r; @@ -1505,55 +1934,85 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() qr[8] = sqrt(spatial_det_r) * psi_r; qr[9] = lapse_r; - qr[10] = shift_r[0]; qr[11] = shift_r[1]; qr[12] = shift_r[2]; - - qr[13] = spatial_metric_r[0][0]; qr[14] = spatial_metric_r[0][1]; qr[15] = spatial_metric_r[0][2]; - qr[16] = spatial_metric_r[1][0]; qr[17] = spatial_metric_r[1][1]; qr[18] = spatial_metric_r[1][2]; - qr[19] = spatial_metric_r[2][0]; qr[20] = spatial_metric_r[2][1]; qr[21] = spatial_metric_r[2][2]; - - qr[22] = extrinsic_curvature_r[0][0]; qr[23] = extrinsic_curvature_r[0][1]; qr[24] = extrinsic_curvature_r[0][2]; - qr[25] = extrinsic_curvature_r[1][0]; qr[26] = extrinsic_curvature_r[1][1]; qr[27] = extrinsic_curvature_r[1][2]; - qr[28] = extrinsic_curvature_r[2][0]; qr[29] = extrinsic_curvature_r[2][1]; qr[30] = extrinsic_curvature_r[2][2]; + qr[10] = shift_r[0]; + qr[11] = shift_r[1]; + qr[12] = shift_r[2]; + + qr[13] = spatial_metric_r[0][0]; + qr[14] = spatial_metric_r[0][1]; + qr[15] = spatial_metric_r[0][2]; + qr[16] = spatial_metric_r[1][0]; + qr[17] = spatial_metric_r[1][1]; + qr[18] = spatial_metric_r[1][2]; + qr[19] = spatial_metric_r[2][0]; + qr[20] = spatial_metric_r[2][1]; + qr[21] = spatial_metric_r[2][2]; + + qr[22] = extrinsic_curvature_r[0][0]; + qr[23] = extrinsic_curvature_r[0][1]; + qr[24] = extrinsic_curvature_r[0][2]; + qr[25] = extrinsic_curvature_r[1][0]; + qr[26] = extrinsic_curvature_r[1][1]; + qr[27] = extrinsic_curvature_r[1][2]; + qr[28] = extrinsic_curvature_r[2][0]; + qr[29] = extrinsic_curvature_r[2][1]; + qr[30] = extrinsic_curvature_r[2][2]; qr[31] = 1.0; - qr[32] = lapse_der_r[0]; qr[33] = lapse_der_r[1]; qr[34] = lapse_der_r[2]; - qr[35] = shift_der_r[0][0]; qr[36] = shift_der_r[0][1]; qr[37] = shift_der_r[0][2]; - qr[38] = shift_der_r[1][0]; qr[39] = shift_der_r[1][1]; qr[40] = shift_der_r[1][2]; - qr[41] = shift_der_r[2][0]; qr[42] = shift_der_r[2][1]; qr[43] = shift_der_r[2][2]; - - qr[44] = spatial_metric_der_r[0][0][0]; qr[45] = spatial_metric_der_r[0][0][1]; qr[46] = spatial_metric_der_r[0][0][2]; - qr[47] = spatial_metric_der_r[0][1][0]; qr[48] = spatial_metric_der_r[0][1][1]; qr[49] = spatial_metric_der_r[0][1][2]; - qr[50] = spatial_metric_der_r[0][2][0]; qr[51] = spatial_metric_der_r[0][2][1]; qr[52] = spatial_metric_der_r[0][2][2]; - - qr[53] = spatial_metric_der_r[1][0][0]; qr[54] = spatial_metric_der_r[1][0][1]; qr[55] = spatial_metric_der_r[1][0][2]; - qr[56] = spatial_metric_der_r[1][1][0]; qr[57] = spatial_metric_der_r[1][1][1]; qr[58] = spatial_metric_der_r[1][1][2]; - qr[59] = spatial_metric_der_r[1][2][0]; qr[60] = spatial_metric_der_r[1][2][1]; qr[61] = spatial_metric_der_r[1][2][2]; - - qr[62] = spatial_metric_der_r[2][0][0]; qr[63] = spatial_metric_der_r[2][0][1]; qr[64] = spatial_metric_der_r[2][0][2]; - qr[65] = spatial_metric_der_r[2][1][0]; qr[66] = spatial_metric_der_r[2][1][1]; qr[67] = spatial_metric_der_r[2][1][2]; - qr[68] = spatial_metric_der_r[2][2][0]; qr[69] = spatial_metric_der_r[2][2][1]; qr[70] = spatial_metric_der_r[2][2][2]; + qr[32] = lapse_der_r[0]; + qr[33] = lapse_der_r[1]; + qr[34] = lapse_der_r[2]; + qr[35] = shift_der_r[0][0]; + qr[36] = shift_der_r[0][1]; + qr[37] = shift_der_r[0][2]; + qr[38] = shift_der_r[1][0]; + qr[39] = shift_der_r[1][1]; + qr[40] = shift_der_r[1][2]; + qr[41] = shift_der_r[2][0]; + qr[42] = shift_der_r[2][1]; + qr[43] = shift_der_r[2][2]; + + qr[44] = spatial_metric_der_r[0][0][0]; + qr[45] = spatial_metric_der_r[0][0][1]; + qr[46] = spatial_metric_der_r[0][0][2]; + qr[47] = spatial_metric_der_r[0][1][0]; + qr[48] = spatial_metric_der_r[0][1][1]; + qr[49] = spatial_metric_der_r[0][1][2]; + qr[50] = spatial_metric_der_r[0][2][0]; + qr[51] = spatial_metric_der_r[0][2][1]; + qr[52] = spatial_metric_der_r[0][2][2]; + + qr[53] = spatial_metric_der_r[1][0][0]; + qr[54] = spatial_metric_der_r[1][0][1]; + qr[55] = spatial_metric_der_r[1][0][2]; + qr[56] = spatial_metric_der_r[1][1][0]; + qr[57] = spatial_metric_der_r[1][1][1]; + qr[58] = spatial_metric_der_r[1][1][2]; + qr[59] = spatial_metric_der_r[1][2][0]; + qr[60] = spatial_metric_der_r[1][2][1]; + qr[61] = spatial_metric_der_r[1][2][2]; + + qr[62] = spatial_metric_der_r[2][0][0]; + qr[63] = spatial_metric_der_r[2][0][1]; + qr[64] = spatial_metric_der_r[2][0][2]; + qr[65] = spatial_metric_der_r[2][1][0]; + qr[66] = spatial_metric_der_r[2][1][1]; + qr[67] = spatial_metric_der_r[2][1][2]; + qr[68] = spatial_metric_der_r[2][2][0]; + qr[69] = spatial_metric_der_r[2][2][1]; + qr[70] = spatial_metric_der_r[2][2][2]; qr[71] = 0.0; - qr[72] = x + 0.5; qr[73] = y; qr[74] = 0.0; + qr[72] = x + 0.5; + qr[73] = y; + qr[74] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 75], waves_local[2 * 75]; @@ -1567,13 +2026,21 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[75], amdq_local[75]; - gkyl_wv_eqn_qfluct(gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75]); + gkyl_wv_eqn_rotate_to_global( + gr_mhd_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75] + ); } double apdq[75], amdq[75]; @@ -1585,15 +2052,19 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() gkyl_gr_mhd_tetrad_flux(gas_gamma, light_speed, b_fact, qr_local, fr_local_sr); double fl_local_gr[75], fr_local_gr[75]; - gkyl_gr_mhd_tetrad_flux_correction(gas_gamma, light_speed, b_fact, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_mhd_tetrad_flux_correction(gas_gamma, light_speed, b_fact, qr_local, fr_local_sr, fr_local_gr); + gkyl_gr_mhd_tetrad_flux_correction( + gas_gamma, light_speed, b_fact, ql_local, fl_local_sr, fl_local_gr + ); + gkyl_gr_mhd_tetrad_flux_correction( + gas_gamma, light_speed, b_fact, qr_local, fr_local_sr, fr_local_gr + ); double fl[75], fr[75]; gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1605,7 +2076,7 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1646,14 +2117,15 @@ test_gr_mhd_tetrad_waves_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_mhd_tetrad_waves_kerr_ho() +void test_gr_mhd_tetrad_waves_kerr_ho() { double gas_gamma = 5.0 / 3.0; double light_speed = 1.0; double b_fact = 0.8; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new(gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_mhd_tetrad = gkyl_wv_gr_mhd_tetrad_new( + gas_gamma, light_speed, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1671,10 +2143,10 @@ test_gr_mhd_tetrad_waves_kerr_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1684,18 +2156,18 @@ test_gr_mhd_tetrad_waves_kerr_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1714,20 +2186,46 @@ test_gr_mhd_tetrad_waves_kerr_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1742,8 +2240,12 @@ test_gr_mhd_tetrad_waves_kerr_ho() double *mag_l = gkyl_malloc(sizeof(double[3])); double *mag_r = gkyl_malloc(sizeof(double[3])); - mag_l[0] = mag_x_l; mag_l[1] = mag_y_l; mag_l[2] = mag_z_l; - mag_r[0] = mag_x_r; mag_r[1] = mag_y_r; mag_r[2] = mag_z_r; + mag_l[0] = mag_x_l; + mag_l[1] = mag_y_l; + mag_l[2] = mag_z_l; + mag_r[0] = mag_x_r; + mag_r[1] = mag_y_r; + mag_r[2] = mag_z_r; double *cov_mag_l = gkyl_malloc(sizeof(double[3])); double *cov_mag_r = gkyl_malloc(sizeof(double[3])); @@ -1768,7 +2270,7 @@ test_gr_mhd_tetrad_waves_kerr_ho() cov_vel_r[i] += spatial_metric_r[i][j] * vel_r[j]; } } - + double b0_l = 0.0, b0_r = 0.0; for (int i = 0; i < 3; i++) { b0_l += W_l * mag_l[i] * (cov_vel_l[i] / lapse_l); @@ -1819,10 +2321,14 @@ test_gr_mhd_tetrad_waves_kerr_ho() if (!in_excision_region_l && !in_excision_region_r) { double ql[75], qr[75]; ql[0] = sqrt(spatial_det_l) * rho_l * W_l; - ql[1] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); - ql[2] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); - ql[3] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); - ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); + ql[1] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[0]) - (lapse_l * b0_l * cov_b_l[0])); + ql[2] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[1]) - (lapse_l * b0_l * cov_b_l[1])); + ql[3] = sqrt(spatial_det_l) * + ((rho_l * h_star_l * (W_l * W_l) * cov_vel_l[2]) - (lapse_l * b0_l * cov_b_l[2])); + ql[4] = sqrt(spatial_det_l) * ((rho_l * h_star_l * (W_l * W_l)) - p_star_l - + ((lapse_l * lapse_l) * (b0_l * b0_l)) - (rho_l * W_l)); ql[5] = sqrt(spatial_det_l) * mag_x_l; ql[6] = sqrt(spatial_det_l) * mag_y_l; @@ -1830,43 +2336,89 @@ test_gr_mhd_tetrad_waves_kerr_ho() ql[8] = sqrt(spatial_det_l) * psi_l; ql[9] = lapse_l; - ql[10] = shift_l[0]; ql[11] = shift_l[1]; ql[12] = shift_l[2]; - - ql[13] = spatial_metric_l[0][0]; ql[14] = spatial_metric_l[0][1]; ql[15] = spatial_metric_l[0][2]; - ql[16] = spatial_metric_l[1][0]; ql[17] = spatial_metric_l[1][1]; ql[18] = spatial_metric_l[1][2]; - ql[19] = spatial_metric_l[2][0]; ql[20] = spatial_metric_l[2][1]; ql[21] = spatial_metric_l[2][2]; - - ql[22] = extrinsic_curvature_l[0][0]; ql[23] = extrinsic_curvature_l[0][1]; ql[24] = extrinsic_curvature_l[0][2]; - ql[25] = extrinsic_curvature_l[1][0]; ql[26] = extrinsic_curvature_l[1][1]; ql[27] = extrinsic_curvature_l[1][2]; - ql[28] = extrinsic_curvature_l[2][0]; ql[29] = extrinsic_curvature_l[2][1]; ql[30] = extrinsic_curvature_l[2][2]; + ql[10] = shift_l[0]; + ql[11] = shift_l[1]; + ql[12] = shift_l[2]; + + ql[13] = spatial_metric_l[0][0]; + ql[14] = spatial_metric_l[0][1]; + ql[15] = spatial_metric_l[0][2]; + ql[16] = spatial_metric_l[1][0]; + ql[17] = spatial_metric_l[1][1]; + ql[18] = spatial_metric_l[1][2]; + ql[19] = spatial_metric_l[2][0]; + ql[20] = spatial_metric_l[2][1]; + ql[21] = spatial_metric_l[2][2]; + + ql[22] = extrinsic_curvature_l[0][0]; + ql[23] = extrinsic_curvature_l[0][1]; + ql[24] = extrinsic_curvature_l[0][2]; + ql[25] = extrinsic_curvature_l[1][0]; + ql[26] = extrinsic_curvature_l[1][1]; + ql[27] = extrinsic_curvature_l[1][2]; + ql[28] = extrinsic_curvature_l[2][0]; + ql[29] = extrinsic_curvature_l[2][1]; + ql[30] = extrinsic_curvature_l[2][2]; ql[31] = 1.0; - ql[32] = lapse_der_l[0]; ql[33] = lapse_der_l[1]; ql[34] = lapse_der_l[2]; - ql[35] = shift_der_l[0][0]; ql[36] = shift_der_l[0][1]; ql[37] = shift_der_l[0][2]; - ql[38] = shift_der_l[1][0]; ql[39] = shift_der_l[1][1]; ql[40] = shift_der_l[1][2]; - ql[41] = shift_der_l[2][0]; ql[42] = shift_der_l[2][1]; ql[43] = shift_der_l[2][2]; - - ql[44] = spatial_metric_der_l[0][0][0]; ql[45] = spatial_metric_der_l[0][0][1]; ql[46] = spatial_metric_der_l[0][0][2]; - ql[47] = spatial_metric_der_l[0][1][0]; ql[48] = spatial_metric_der_l[0][1][1]; ql[49] = spatial_metric_der_l[0][1][2]; - ql[50] = spatial_metric_der_l[0][2][0]; ql[51] = spatial_metric_der_l[0][2][1]; ql[52] = spatial_metric_der_l[0][2][2]; - - ql[53] = spatial_metric_der_l[1][0][0]; ql[54] = spatial_metric_der_l[1][0][1]; ql[55] = spatial_metric_der_l[1][0][2]; - ql[56] = spatial_metric_der_l[1][1][0]; ql[57] = spatial_metric_der_l[1][1][1]; ql[58] = spatial_metric_der_l[1][1][2]; - ql[59] = spatial_metric_der_l[1][2][0]; ql[60] = spatial_metric_der_l[1][2][1]; ql[61] = spatial_metric_der_l[1][2][2]; - - ql[62] = spatial_metric_der_l[2][0][0]; ql[63] = spatial_metric_der_l[2][0][1]; ql[64] = spatial_metric_der_l[2][0][2]; - ql[65] = spatial_metric_der_l[2][1][0]; ql[66] = spatial_metric_der_l[2][1][1]; ql[67] = spatial_metric_der_l[2][1][2]; - ql[68] = spatial_metric_der_l[2][2][0]; ql[69] = spatial_metric_der_l[2][2][1]; ql[70] = spatial_metric_der_l[2][2][2]; + ql[32] = lapse_der_l[0]; + ql[33] = lapse_der_l[1]; + ql[34] = lapse_der_l[2]; + ql[35] = shift_der_l[0][0]; + ql[36] = shift_der_l[0][1]; + ql[37] = shift_der_l[0][2]; + ql[38] = shift_der_l[1][0]; + ql[39] = shift_der_l[1][1]; + ql[40] = shift_der_l[1][2]; + ql[41] = shift_der_l[2][0]; + ql[42] = shift_der_l[2][1]; + ql[43] = shift_der_l[2][2]; + + ql[44] = spatial_metric_der_l[0][0][0]; + ql[45] = spatial_metric_der_l[0][0][1]; + ql[46] = spatial_metric_der_l[0][0][2]; + ql[47] = spatial_metric_der_l[0][1][0]; + ql[48] = spatial_metric_der_l[0][1][1]; + ql[49] = spatial_metric_der_l[0][1][2]; + ql[50] = spatial_metric_der_l[0][2][0]; + ql[51] = spatial_metric_der_l[0][2][1]; + ql[52] = spatial_metric_der_l[0][2][2]; + + ql[53] = spatial_metric_der_l[1][0][0]; + ql[54] = spatial_metric_der_l[1][0][1]; + ql[55] = spatial_metric_der_l[1][0][2]; + ql[56] = spatial_metric_der_l[1][1][0]; + ql[57] = spatial_metric_der_l[1][1][1]; + ql[58] = spatial_metric_der_l[1][1][2]; + ql[59] = spatial_metric_der_l[1][2][0]; + ql[60] = spatial_metric_der_l[1][2][1]; + ql[61] = spatial_metric_der_l[1][2][2]; + + ql[62] = spatial_metric_der_l[2][0][0]; + ql[63] = spatial_metric_der_l[2][0][1]; + ql[64] = spatial_metric_der_l[2][0][2]; + ql[65] = spatial_metric_der_l[2][1][0]; + ql[66] = spatial_metric_der_l[2][1][1]; + ql[67] = spatial_metric_der_l[2][1][2]; + ql[68] = spatial_metric_der_l[2][2][0]; + ql[69] = spatial_metric_der_l[2][2][1]; + ql[70] = spatial_metric_der_l[2][2][2]; ql[71] = 0.0; - ql[72] = x - 0.5; ql[73] = y; ql[74] = 0.0; + ql[72] = x - 0.5; + ql[73] = y; + ql[74] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_r * W_r; - qr[1] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); - qr[2] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); - qr[3] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); - qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); + qr[1] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[0]) - (lapse_r * b0_r * cov_b_r[0])); + qr[2] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[1]) - (lapse_r * b0_r * cov_b_r[1])); + qr[3] = sqrt(spatial_det_r) * + ((rho_r * h_star_r * (W_r * W_r) * cov_vel_r[2]) - (lapse_r * b0_r * cov_b_r[2])); + qr[4] = sqrt(spatial_det_r) * ((rho_r * h_star_r * (W_r * W_r)) - p_star_r - + ((lapse_r * lapse_r) * (b0_r * b0_r)) - (rho_r * W_r)); qr[5] = sqrt(spatial_det_r) * mag_x_r; qr[6] = sqrt(spatial_det_r) * mag_y_r; @@ -1874,55 +2426,85 @@ test_gr_mhd_tetrad_waves_kerr_ho() qr[8] = sqrt(spatial_det_r) * psi_r; qr[9] = lapse_r; - qr[10] = shift_r[0]; qr[11] = shift_r[1]; qr[12] = shift_r[2]; - - qr[13] = spatial_metric_r[0][0]; qr[14] = spatial_metric_r[0][1]; qr[15] = spatial_metric_r[0][2]; - qr[16] = spatial_metric_r[1][0]; qr[17] = spatial_metric_r[1][1]; qr[18] = spatial_metric_r[1][2]; - qr[19] = spatial_metric_r[2][0]; qr[20] = spatial_metric_r[2][1]; qr[21] = spatial_metric_r[2][2]; - - qr[22] = extrinsic_curvature_r[0][0]; qr[23] = extrinsic_curvature_r[0][1]; qr[24] = extrinsic_curvature_r[0][2]; - qr[25] = extrinsic_curvature_r[1][0]; qr[26] = extrinsic_curvature_r[1][1]; qr[27] = extrinsic_curvature_r[1][2]; - qr[28] = extrinsic_curvature_r[2][0]; qr[29] = extrinsic_curvature_r[2][1]; qr[30] = extrinsic_curvature_r[2][2]; + qr[10] = shift_r[0]; + qr[11] = shift_r[1]; + qr[12] = shift_r[2]; + + qr[13] = spatial_metric_r[0][0]; + qr[14] = spatial_metric_r[0][1]; + qr[15] = spatial_metric_r[0][2]; + qr[16] = spatial_metric_r[1][0]; + qr[17] = spatial_metric_r[1][1]; + qr[18] = spatial_metric_r[1][2]; + qr[19] = spatial_metric_r[2][0]; + qr[20] = spatial_metric_r[2][1]; + qr[21] = spatial_metric_r[2][2]; + + qr[22] = extrinsic_curvature_r[0][0]; + qr[23] = extrinsic_curvature_r[0][1]; + qr[24] = extrinsic_curvature_r[0][2]; + qr[25] = extrinsic_curvature_r[1][0]; + qr[26] = extrinsic_curvature_r[1][1]; + qr[27] = extrinsic_curvature_r[1][2]; + qr[28] = extrinsic_curvature_r[2][0]; + qr[29] = extrinsic_curvature_r[2][1]; + qr[30] = extrinsic_curvature_r[2][2]; qr[31] = 1.0; - qr[32] = lapse_der_r[0]; qr[33] = lapse_der_r[1]; qr[34] = lapse_der_r[2]; - qr[35] = shift_der_r[0][0]; qr[36] = shift_der_r[0][1]; qr[37] = shift_der_r[0][2]; - qr[38] = shift_der_r[1][0]; qr[39] = shift_der_r[1][1]; qr[40] = shift_der_r[1][2]; - qr[41] = shift_der_r[2][0]; qr[42] = shift_der_r[2][1]; qr[43] = shift_der_r[2][2]; - - qr[44] = spatial_metric_der_r[0][0][0]; qr[45] = spatial_metric_der_r[0][0][1]; qr[46] = spatial_metric_der_r[0][0][2]; - qr[47] = spatial_metric_der_r[0][1][0]; qr[48] = spatial_metric_der_r[0][1][1]; qr[49] = spatial_metric_der_r[0][1][2]; - qr[50] = spatial_metric_der_r[0][2][0]; qr[51] = spatial_metric_der_r[0][2][1]; qr[52] = spatial_metric_der_r[0][2][2]; - - qr[53] = spatial_metric_der_r[1][0][0]; qr[54] = spatial_metric_der_r[1][0][1]; qr[55] = spatial_metric_der_r[1][0][2]; - qr[56] = spatial_metric_der_r[1][1][0]; qr[57] = spatial_metric_der_r[1][1][1]; qr[58] = spatial_metric_der_r[1][1][2]; - qr[59] = spatial_metric_der_r[1][2][0]; qr[60] = spatial_metric_der_r[1][2][1]; qr[61] = spatial_metric_der_r[1][2][2]; - - qr[62] = spatial_metric_der_r[2][0][0]; qr[63] = spatial_metric_der_r[2][0][1]; qr[64] = spatial_metric_der_r[2][0][2]; - qr[65] = spatial_metric_der_r[2][1][0]; qr[66] = spatial_metric_der_r[2][1][1]; qr[67] = spatial_metric_der_r[2][1][2]; - qr[68] = spatial_metric_der_r[2][2][0]; qr[69] = spatial_metric_der_r[2][2][1]; qr[70] = spatial_metric_der_r[2][2][2]; + qr[32] = lapse_der_r[0]; + qr[33] = lapse_der_r[1]; + qr[34] = lapse_der_r[2]; + qr[35] = shift_der_r[0][0]; + qr[36] = shift_der_r[0][1]; + qr[37] = shift_der_r[0][2]; + qr[38] = shift_der_r[1][0]; + qr[39] = shift_der_r[1][1]; + qr[40] = shift_der_r[1][2]; + qr[41] = shift_der_r[2][0]; + qr[42] = shift_der_r[2][1]; + qr[43] = shift_der_r[2][2]; + + qr[44] = spatial_metric_der_r[0][0][0]; + qr[45] = spatial_metric_der_r[0][0][1]; + qr[46] = spatial_metric_der_r[0][0][2]; + qr[47] = spatial_metric_der_r[0][1][0]; + qr[48] = spatial_metric_der_r[0][1][1]; + qr[49] = spatial_metric_der_r[0][1][2]; + qr[50] = spatial_metric_der_r[0][2][0]; + qr[51] = spatial_metric_der_r[0][2][1]; + qr[52] = spatial_metric_der_r[0][2][2]; + + qr[53] = spatial_metric_der_r[1][0][0]; + qr[54] = spatial_metric_der_r[1][0][1]; + qr[55] = spatial_metric_der_r[1][0][2]; + qr[56] = spatial_metric_der_r[1][1][0]; + qr[57] = spatial_metric_der_r[1][1][1]; + qr[58] = spatial_metric_der_r[1][1][2]; + qr[59] = spatial_metric_der_r[1][2][0]; + qr[60] = spatial_metric_der_r[1][2][1]; + qr[61] = spatial_metric_der_r[1][2][2]; + + qr[62] = spatial_metric_der_r[2][0][0]; + qr[63] = spatial_metric_der_r[2][0][1]; + qr[64] = spatial_metric_der_r[2][0][2]; + qr[65] = spatial_metric_der_r[2][1][0]; + qr[66] = spatial_metric_der_r[2][1][1]; + qr[67] = spatial_metric_der_r[2][1][2]; + qr[68] = spatial_metric_der_r[2][2][0]; + qr[69] = spatial_metric_der_r[2][2][1]; + qr[70] = spatial_metric_der_r[2][2][2]; qr[71] = 0.0; - qr[72] = x + 0.5; qr[73] = y; qr[74] = 0.0; + qr[72] = x + 0.5; + qr[73] = y; + qr[74] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 75], waves_local[2 * 75]; @@ -1936,13 +2518,21 @@ test_gr_mhd_tetrad_waves_kerr_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[75], amdq_local[75]; - gkyl_wv_eqn_qfluct(gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_mhd_tetrad, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75]); + gkyl_wv_eqn_rotate_to_global( + gr_mhd_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 75], &waves[i * 75] + ); } double apdq[75], amdq[75]; @@ -1954,15 +2544,19 @@ test_gr_mhd_tetrad_waves_kerr_ho() gkyl_gr_mhd_tetrad_flux(gas_gamma, light_speed, b_fact, qr_local, fr_local_sr); double fl_local_gr[75], fr_local_gr[75]; - gkyl_gr_mhd_tetrad_flux_correction(gas_gamma, light_speed, b_fact, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_mhd_tetrad_flux_correction(gas_gamma, light_speed, b_fact, qr_local, fr_local_sr, fr_local_gr); + gkyl_gr_mhd_tetrad_flux_correction( + gas_gamma, light_speed, b_fact, ql_local, fl_local_sr, fl_local_gr + ); + gkyl_gr_mhd_tetrad_flux_correction( + gas_gamma, light_speed, b_fact, qr_local, fr_local_sr, fr_local_gr + ); double fl[75], fr[75]; gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); gkyl_wv_eqn_rotate_to_global(gr_mhd_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); for (int i = 0; i < 75; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1974,7 +2568,7 @@ test_gr_mhd_tetrad_waves_kerr_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -2016,11 +2610,11 @@ test_gr_mhd_tetrad_waves_kerr_ho() } TEST_LIST = { - { "gr_mhd_tetrad_basic_minkowski_ho", test_gr_mhd_tetrad_basic_minkowski_ho}, - { "gr_mhd_tetrad_basic_schwarzschild_ho", test_gr_mhd_tetrad_basic_schwarzschild_ho }, - { "gr_mhd_tetrad_basic_kerr_ho", test_gr_mhd_tetrad_basic_kerr_ho }, - { "gr_mhd_tetrad_waves_minkowski_ho", test_gr_mhd_tetrad_waves_minkowski_ho }, - { "gr_mhd_tetrad_waves_schwarzschild_ho", test_gr_mhd_tetrad_waves_schwarzschild_ho }, - { "gr_mhd_tetrad_waves_kerr_ho", test_gr_mhd_tetrad_waves_kerr_ho }, - { NULL, NULL }, + {"gr_mhd_tetrad_basic_minkowski_ho", test_gr_mhd_tetrad_basic_minkowski_ho}, + {"gr_mhd_tetrad_basic_schwarzschild_ho", test_gr_mhd_tetrad_basic_schwarzschild_ho}, + {"gr_mhd_tetrad_basic_kerr_ho", test_gr_mhd_tetrad_basic_kerr_ho}, + {"gr_mhd_tetrad_waves_minkowski_ho", test_gr_mhd_tetrad_waves_minkowski_ho}, + {"gr_mhd_tetrad_waves_schwarzschild_ho", test_gr_mhd_tetrad_waves_schwarzschild_ho}, + {"gr_mhd_tetrad_waves_kerr_ho", test_gr_mhd_tetrad_waves_kerr_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_gr_twofluid.c b/moments/unit/ctest_wv_gr_twofluid.c index 98f4577bb7..dbc32502a3 100644 --- a/moments/unit/ctest_wv_gr_twofluid.c +++ b/moments/unit/ctest_wv_gr_twofluid.c @@ -6,8 +6,7 @@ #include #include -void -test_gr_twofluid_basic_minkowski_ho() +void test_gr_twofluid_basic_minkowski_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -21,11 +20,13 @@ test_gr_twofluid_basic_minkowski_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_twofluid->num_equations == 84 ); - TEST_CHECK( gr_twofluid->num_waves == 6 ); + TEST_CHECK(gr_twofluid->num_equations == 84); + TEST_CHECK(gr_twofluid->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -39,25 +40,25 @@ test_gr_twofluid_basic_minkowski_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -68,16 +69,28 @@ test_gr_twofluid_basic_minkowski_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -107,57 +120,104 @@ test_gr_twofluid_basic_minkowski_ho() q[8] = sqrt(spatial_det) * rho_ion * hi * (W * W) * w; q[9] = sqrt(spatial_det) * ((rho_ion * hi * (W * W)) - p - (rho_ion * W)); - q[10] = Dx; q[11] = Dy; q[12] = Dz; - q[13] = Bx; q[14] = By; q[15] = Bz; - q[16] = phi; q[17] = psi; + q[10] = Dx; + q[11] = Dy; + q[12] = Dz; + q[13] = Bx; + q[14] = By; + q[15] = Bz; + q[16] = phi; + q[17] = psi; q[18] = lapse; - q[19] = shift[0]; q[20] = shift[1]; q[21] = shift[2]; - - q[22] = spatial_metric[0][0]; q[23] = spatial_metric[0][1]; q[24] = spatial_metric[0][2]; - q[25] = spatial_metric[1][0]; q[26] = spatial_metric[1][1]; q[27] = spatial_metric[1][2]; - q[28] = spatial_metric[2][0]; q[29] = spatial_metric[2][1]; q[30] = spatial_metric[2][2]; - - q[31] = extrinsic_curvature[0][0]; q[32] = extrinsic_curvature[0][1]; q[33] = extrinsic_curvature[0][2]; - q[34] = extrinsic_curvature[1][0]; q[35] = extrinsic_curvature[1][1]; q[36] = extrinsic_curvature[1][2]; - q[37] = extrinsic_curvature[2][0]; q[38] = extrinsic_curvature[2][1]; q[39] = extrinsic_curvature[2][2]; + q[19] = shift[0]; + q[20] = shift[1]; + q[21] = shift[2]; + + q[22] = spatial_metric[0][0]; + q[23] = spatial_metric[0][1]; + q[24] = spatial_metric[0][2]; + q[25] = spatial_metric[1][0]; + q[26] = spatial_metric[1][1]; + q[27] = spatial_metric[1][2]; + q[28] = spatial_metric[2][0]; + q[29] = spatial_metric[2][1]; + q[30] = spatial_metric[2][2]; + + q[31] = extrinsic_curvature[0][0]; + q[32] = extrinsic_curvature[0][1]; + q[33] = extrinsic_curvature[0][2]; + q[34] = extrinsic_curvature[1][0]; + q[35] = extrinsic_curvature[1][1]; + q[36] = extrinsic_curvature[1][2]; + q[37] = extrinsic_curvature[2][0]; + q[38] = extrinsic_curvature[2][1]; + q[39] = extrinsic_curvature[2][2]; q[40] = 1.0; - q[41] = lapse_der[0]; q[42] = lapse_der[1]; q[43] = lapse_der[2]; - q[44] = shift_der[0][0]; q[45] = shift_der[0][1]; q[46] = shift_der[0][2]; - q[47] = shift_der[1][0]; q[48] = shift_der[1][1]; q[49] = shift_der[1][2]; - q[50] = shift_der[2][0]; q[51] = shift_der[2][1]; q[52] = shift_der[2][2]; - - q[53] = spatial_metric_der[0][0][0]; q[54] = spatial_metric_der[0][0][1]; q[55] = spatial_metric_der[0][0][2]; - q[56] = spatial_metric_der[0][1][0]; q[57] = spatial_metric_der[0][1][1]; q[58] = spatial_metric_der[0][1][2]; - q[59] = spatial_metric_der[0][2][0]; q[60] = spatial_metric_der[0][2][1]; q[61] = spatial_metric_der[0][2][2]; - - q[62] = spatial_metric_der[1][0][0]; q[63] = spatial_metric_der[1][0][1]; q[64] = spatial_metric_der[1][0][2]; - q[65] = spatial_metric_der[1][1][0]; q[66] = spatial_metric_der[1][1][1]; q[67] = spatial_metric_der[1][1][2]; - q[68] = spatial_metric_der[1][2][0]; q[69] = spatial_metric_der[1][2][1]; q[70] = spatial_metric_der[1][2][2]; - - q[71] = spatial_metric_der[2][0][0]; q[72] = spatial_metric_der[2][0][1]; q[73] = spatial_metric_der[2][0][2]; - q[74] = spatial_metric_der[2][1][0]; q[75] = spatial_metric_der[2][1][1]; q[76] = spatial_metric_der[2][1][2]; - q[77] = spatial_metric_der[2][2][0]; q[78] = spatial_metric_der[2][2][1]; q[79] = spatial_metric_der[2][2][2]; + q[41] = lapse_der[0]; + q[42] = lapse_der[1]; + q[43] = lapse_der[2]; + q[44] = shift_der[0][0]; + q[45] = shift_der[0][1]; + q[46] = shift_der[0][2]; + q[47] = shift_der[1][0]; + q[48] = shift_der[1][1]; + q[49] = shift_der[1][2]; + q[50] = shift_der[2][0]; + q[51] = shift_der[2][1]; + q[52] = shift_der[2][2]; + + q[53] = spatial_metric_der[0][0][0]; + q[54] = spatial_metric_der[0][0][1]; + q[55] = spatial_metric_der[0][0][2]; + q[56] = spatial_metric_der[0][1][0]; + q[57] = spatial_metric_der[0][1][1]; + q[58] = spatial_metric_der[0][1][2]; + q[59] = spatial_metric_der[0][2][0]; + q[60] = spatial_metric_der[0][2][1]; + q[61] = spatial_metric_der[0][2][2]; + + q[62] = spatial_metric_der[1][0][0]; + q[63] = spatial_metric_der[1][0][1]; + q[64] = spatial_metric_der[1][0][2]; + q[65] = spatial_metric_der[1][1][0]; + q[66] = spatial_metric_der[1][1][1]; + q[67] = spatial_metric_der[1][1][2]; + q[68] = spatial_metric_der[1][2][0]; + q[69] = spatial_metric_der[1][2][1]; + q[70] = spatial_metric_der[1][2][2]; + + q[71] = spatial_metric_der[2][0][0]; + q[72] = spatial_metric_der[2][0][1]; + q[73] = spatial_metric_der[2][0][2]; + q[74] = spatial_metric_der[2][1][0]; + q[75] = spatial_metric_der[2][1][1]; + q[76] = spatial_metric_der[2][1][2]; + q[77] = spatial_metric_der[2][2][0]; + q[78] = spatial_metric_der[2][2][1]; + q[79] = spatial_metric_der[2][2][2]; q[80] = 0.0; - q[81] = x; q[82] = y; q[83] = 0.0; + q[81] = x; + q[82] = y; + q[83] = 0.0; double prims[84]; gkyl_gr_twofluid_prim_vars(gas_gamma_elc, gas_gamma_ion, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho_elc, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-12) ); - - TEST_CHECK( gkyl_compare(prims[5], rho_ion, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[6], u, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[7], v, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[8], w, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[9], p, 1e-12) ); + + TEST_CHECK(gkyl_compare(prims[0], rho_elc, 1e-12)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-12)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-12)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-12)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-12)); + + TEST_CHECK(gkyl_compare(prims[5], rho_ion, 1e-12)); + TEST_CHECK(gkyl_compare(prims[6], u, 1e-12)); + TEST_CHECK(gkyl_compare(prims[7], v, 1e-12)); + TEST_CHECK(gkyl_compare(prims[8], w, 1e-12)); + TEST_CHECK(gkyl_compare(prims[9], p, 1e-12)); double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -168,70 +228,93 @@ test_gr_twofluid_basic_minkowski_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][18] = { - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[84], flux_local[84], flux[84]; for (int d = 0; d < 3; d++) { gr_twofluid->rotate_to_local_func(gr_twofluid, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_gr_twofluid_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local); + gkyl_gr_twofluid_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local + ); gr_twofluid->rotate_to_global_func(gr_twofluid, tau1[d], tau2[d], norm[d], flux_local, flux); for (int i = 0; i < 18; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-8) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-8)); } } @@ -241,7 +324,7 @@ test_gr_twofluid_basic_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[84], q1[84]; @@ -249,7 +332,7 @@ test_gr_twofluid_basic_minkowski_ho() gr_twofluid->riem_to_cons(gr_twofluid, q_local, w1, q1); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } @@ -257,7 +340,7 @@ test_gr_twofluid_basic_minkowski_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -277,8 +360,7 @@ test_gr_twofluid_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_twofluid_basic_schwarzschild_ho() +void test_gr_twofluid_basic_schwarzschild_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -292,11 +374,13 @@ test_gr_twofluid_basic_schwarzschild_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_twofluid->num_equations == 84 ); - TEST_CHECK( gr_twofluid->num_waves == 6 ); + TEST_CHECK(gr_twofluid->num_equations == 84); + TEST_CHECK(gr_twofluid->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -310,25 +394,25 @@ test_gr_twofluid_basic_schwarzschild_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -339,16 +423,28 @@ test_gr_twofluid_basic_schwarzschild_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -379,57 +475,104 @@ test_gr_twofluid_basic_schwarzschild_ho() q[8] = sqrt(spatial_det) * rho_ion * hi * (W * W) * w; q[9] = sqrt(spatial_det) * ((rho_ion * hi * (W * W)) - p - (rho_ion * W)); - q[10] = Dx; q[11] = Dy; q[12] = Dz; - q[13] = Bx; q[14] = By; q[15] = Bz; - q[16] = phi; q[17] = psi; + q[10] = Dx; + q[11] = Dy; + q[12] = Dz; + q[13] = Bx; + q[14] = By; + q[15] = Bz; + q[16] = phi; + q[17] = psi; q[18] = lapse; - q[19] = shift[0]; q[20] = shift[1]; q[21] = shift[2]; - - q[22] = spatial_metric[0][0]; q[23] = spatial_metric[0][1]; q[24] = spatial_metric[0][2]; - q[25] = spatial_metric[1][0]; q[26] = spatial_metric[1][1]; q[27] = spatial_metric[1][2]; - q[28] = spatial_metric[2][0]; q[29] = spatial_metric[2][1]; q[30] = spatial_metric[2][2]; - - q[31] = extrinsic_curvature[0][0]; q[32] = extrinsic_curvature[0][1]; q[33] = extrinsic_curvature[0][2]; - q[34] = extrinsic_curvature[1][0]; q[35] = extrinsic_curvature[1][1]; q[36] = extrinsic_curvature[1][2]; - q[37] = extrinsic_curvature[2][0]; q[38] = extrinsic_curvature[2][1]; q[39] = extrinsic_curvature[2][2]; + q[19] = shift[0]; + q[20] = shift[1]; + q[21] = shift[2]; + + q[22] = spatial_metric[0][0]; + q[23] = spatial_metric[0][1]; + q[24] = spatial_metric[0][2]; + q[25] = spatial_metric[1][0]; + q[26] = spatial_metric[1][1]; + q[27] = spatial_metric[1][2]; + q[28] = spatial_metric[2][0]; + q[29] = spatial_metric[2][1]; + q[30] = spatial_metric[2][2]; + + q[31] = extrinsic_curvature[0][0]; + q[32] = extrinsic_curvature[0][1]; + q[33] = extrinsic_curvature[0][2]; + q[34] = extrinsic_curvature[1][0]; + q[35] = extrinsic_curvature[1][1]; + q[36] = extrinsic_curvature[1][2]; + q[37] = extrinsic_curvature[2][0]; + q[38] = extrinsic_curvature[2][1]; + q[39] = extrinsic_curvature[2][2]; q[40] = 1.0; - q[41] = lapse_der[0]; q[42] = lapse_der[1]; q[43] = lapse_der[2]; - q[44] = shift_der[0][0]; q[45] = shift_der[0][1]; q[46] = shift_der[0][2]; - q[47] = shift_der[1][0]; q[48] = shift_der[1][1]; q[49] = shift_der[1][2]; - q[50] = shift_der[2][0]; q[51] = shift_der[2][1]; q[52] = shift_der[2][2]; - - q[53] = spatial_metric_der[0][0][0]; q[54] = spatial_metric_der[0][0][1]; q[55] = spatial_metric_der[0][0][2]; - q[56] = spatial_metric_der[0][1][0]; q[57] = spatial_metric_der[0][1][1]; q[58] = spatial_metric_der[0][1][2]; - q[59] = spatial_metric_der[0][2][0]; q[60] = spatial_metric_der[0][2][1]; q[61] = spatial_metric_der[0][2][2]; - - q[62] = spatial_metric_der[1][0][0]; q[63] = spatial_metric_der[1][0][1]; q[64] = spatial_metric_der[1][0][2]; - q[65] = spatial_metric_der[1][1][0]; q[66] = spatial_metric_der[1][1][1]; q[67] = spatial_metric_der[1][1][2]; - q[68] = spatial_metric_der[1][2][0]; q[69] = spatial_metric_der[1][2][1]; q[70] = spatial_metric_der[1][2][2]; - - q[71] = spatial_metric_der[2][0][0]; q[72] = spatial_metric_der[2][0][1]; q[73] = spatial_metric_der[2][0][2]; - q[74] = spatial_metric_der[2][1][0]; q[75] = spatial_metric_der[2][1][1]; q[76] = spatial_metric_der[2][1][2]; - q[77] = spatial_metric_der[2][2][0]; q[78] = spatial_metric_der[2][2][1]; q[79] = spatial_metric_der[2][2][2]; + q[41] = lapse_der[0]; + q[42] = lapse_der[1]; + q[43] = lapse_der[2]; + q[44] = shift_der[0][0]; + q[45] = shift_der[0][1]; + q[46] = shift_der[0][2]; + q[47] = shift_der[1][0]; + q[48] = shift_der[1][1]; + q[49] = shift_der[1][2]; + q[50] = shift_der[2][0]; + q[51] = shift_der[2][1]; + q[52] = shift_der[2][2]; + + q[53] = spatial_metric_der[0][0][0]; + q[54] = spatial_metric_der[0][0][1]; + q[55] = spatial_metric_der[0][0][2]; + q[56] = spatial_metric_der[0][1][0]; + q[57] = spatial_metric_der[0][1][1]; + q[58] = spatial_metric_der[0][1][2]; + q[59] = spatial_metric_der[0][2][0]; + q[60] = spatial_metric_der[0][2][1]; + q[61] = spatial_metric_der[0][2][2]; + + q[62] = spatial_metric_der[1][0][0]; + q[63] = spatial_metric_der[1][0][1]; + q[64] = spatial_metric_der[1][0][2]; + q[65] = spatial_metric_der[1][1][0]; + q[66] = spatial_metric_der[1][1][1]; + q[67] = spatial_metric_der[1][1][2]; + q[68] = spatial_metric_der[1][2][0]; + q[69] = spatial_metric_der[1][2][1]; + q[70] = spatial_metric_der[1][2][2]; + + q[71] = spatial_metric_der[2][0][0]; + q[72] = spatial_metric_der[2][0][1]; + q[73] = spatial_metric_der[2][0][2]; + q[74] = spatial_metric_der[2][1][0]; + q[75] = spatial_metric_der[2][1][1]; + q[76] = spatial_metric_der[2][1][2]; + q[77] = spatial_metric_der[2][2][0]; + q[78] = spatial_metric_der[2][2][1]; + q[79] = spatial_metric_der[2][2][2]; q[80] = 0.0; - q[81] = x; q[82] = y; q[83] = 0.0; + q[81] = x; + q[82] = y; + q[83] = 0.0; double prims[84]; gkyl_gr_twofluid_prim_vars(gas_gamma_elc, gas_gamma_ion, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho_elc, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); - - TEST_CHECK( gkyl_compare(prims[5], rho_ion, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[6], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[7], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[8], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[9], p, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho_elc, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], rho_ion, 1e-1)); + TEST_CHECK(gkyl_compare(prims[6], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[7], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[8], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[9], p, 1e-1)); double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -440,70 +583,95 @@ test_gr_twofluid_basic_schwarzschild_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][18] = { - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[84], flux_local[84], flux[84]; for (int d = 0; d < 3; d++) { gr_twofluid->rotate_to_local_func(gr_twofluid, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_gr_twofluid_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local); - gr_twofluid->rotate_to_global_func(gr_twofluid, tau1[d], tau2[d], norm[d], flux_local, flux); + gkyl_gr_twofluid_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local + ); + gr_twofluid->rotate_to_global_func( + gr_twofluid, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 18; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } @@ -513,7 +681,7 @@ test_gr_twofluid_basic_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[84], q1[84]; @@ -521,7 +689,7 @@ test_gr_twofluid_basic_schwarzschild_ho() gr_twofluid->riem_to_cons(gr_twofluid, q_local, w1, q1); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -530,7 +698,7 @@ test_gr_twofluid_basic_schwarzschild_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -550,8 +718,7 @@ test_gr_twofluid_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_twofluid_basic_kerr_ho() +void test_gr_twofluid_basic_kerr_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -565,11 +732,13 @@ test_gr_twofluid_basic_kerr_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_twofluid->num_equations == 84 ); - TEST_CHECK( gr_twofluid->num_waves == 6 ); + TEST_CHECK(gr_twofluid->num_equations == 84); + TEST_CHECK(gr_twofluid->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -583,25 +752,25 @@ test_gr_twofluid_basic_kerr_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -612,16 +781,28 @@ test_gr_twofluid_basic_kerr_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -652,57 +833,104 @@ test_gr_twofluid_basic_kerr_ho() q[8] = sqrt(spatial_det) * rho_ion * hi * (W * W) * w; q[9] = sqrt(spatial_det) * ((rho_ion * hi * (W * W)) - p - (rho_ion * W)); - q[10] = Dx; q[11] = Dy; q[12] = Dz; - q[13] = Bx; q[14] = By; q[15] = Bz; - q[16] = phi; q[17] = psi; + q[10] = Dx; + q[11] = Dy; + q[12] = Dz; + q[13] = Bx; + q[14] = By; + q[15] = Bz; + q[16] = phi; + q[17] = psi; q[18] = lapse; - q[19] = shift[0]; q[20] = shift[1]; q[21] = shift[2]; - - q[22] = spatial_metric[0][0]; q[23] = spatial_metric[0][1]; q[24] = spatial_metric[0][2]; - q[25] = spatial_metric[1][0]; q[26] = spatial_metric[1][1]; q[27] = spatial_metric[1][2]; - q[28] = spatial_metric[2][0]; q[29] = spatial_metric[2][1]; q[30] = spatial_metric[2][2]; - - q[31] = extrinsic_curvature[0][0]; q[32] = extrinsic_curvature[0][1]; q[33] = extrinsic_curvature[0][2]; - q[34] = extrinsic_curvature[1][0]; q[35] = extrinsic_curvature[1][1]; q[36] = extrinsic_curvature[1][2]; - q[37] = extrinsic_curvature[2][0]; q[38] = extrinsic_curvature[2][1]; q[39] = extrinsic_curvature[2][2]; + q[19] = shift[0]; + q[20] = shift[1]; + q[21] = shift[2]; + + q[22] = spatial_metric[0][0]; + q[23] = spatial_metric[0][1]; + q[24] = spatial_metric[0][2]; + q[25] = spatial_metric[1][0]; + q[26] = spatial_metric[1][1]; + q[27] = spatial_metric[1][2]; + q[28] = spatial_metric[2][0]; + q[29] = spatial_metric[2][1]; + q[30] = spatial_metric[2][2]; + + q[31] = extrinsic_curvature[0][0]; + q[32] = extrinsic_curvature[0][1]; + q[33] = extrinsic_curvature[0][2]; + q[34] = extrinsic_curvature[1][0]; + q[35] = extrinsic_curvature[1][1]; + q[36] = extrinsic_curvature[1][2]; + q[37] = extrinsic_curvature[2][0]; + q[38] = extrinsic_curvature[2][1]; + q[39] = extrinsic_curvature[2][2]; q[40] = 1.0; - q[41] = lapse_der[0]; q[42] = lapse_der[1]; q[43] = lapse_der[2]; - q[44] = shift_der[0][0]; q[45] = shift_der[0][1]; q[46] = shift_der[0][2]; - q[47] = shift_der[1][0]; q[48] = shift_der[1][1]; q[49] = shift_der[1][2]; - q[50] = shift_der[2][0]; q[51] = shift_der[2][1]; q[52] = shift_der[2][2]; - - q[53] = spatial_metric_der[0][0][0]; q[54] = spatial_metric_der[0][0][1]; q[55] = spatial_metric_der[0][0][2]; - q[56] = spatial_metric_der[0][1][0]; q[57] = spatial_metric_der[0][1][1]; q[58] = spatial_metric_der[0][1][2]; - q[59] = spatial_metric_der[0][2][0]; q[60] = spatial_metric_der[0][2][1]; q[61] = spatial_metric_der[0][2][2]; - - q[62] = spatial_metric_der[1][0][0]; q[63] = spatial_metric_der[1][0][1]; q[64] = spatial_metric_der[1][0][2]; - q[65] = spatial_metric_der[1][1][0]; q[66] = spatial_metric_der[1][1][1]; q[67] = spatial_metric_der[1][1][2]; - q[68] = spatial_metric_der[1][2][0]; q[69] = spatial_metric_der[1][2][1]; q[70] = spatial_metric_der[1][2][2]; - - q[71] = spatial_metric_der[2][0][0]; q[72] = spatial_metric_der[2][0][1]; q[73] = spatial_metric_der[2][0][2]; - q[74] = spatial_metric_der[2][1][0]; q[75] = spatial_metric_der[2][1][1]; q[76] = spatial_metric_der[2][1][2]; - q[77] = spatial_metric_der[2][2][0]; q[78] = spatial_metric_der[2][2][1]; q[79] = spatial_metric_der[2][2][2]; + q[41] = lapse_der[0]; + q[42] = lapse_der[1]; + q[43] = lapse_der[2]; + q[44] = shift_der[0][0]; + q[45] = shift_der[0][1]; + q[46] = shift_der[0][2]; + q[47] = shift_der[1][0]; + q[48] = shift_der[1][1]; + q[49] = shift_der[1][2]; + q[50] = shift_der[2][0]; + q[51] = shift_der[2][1]; + q[52] = shift_der[2][2]; + + q[53] = spatial_metric_der[0][0][0]; + q[54] = spatial_metric_der[0][0][1]; + q[55] = spatial_metric_der[0][0][2]; + q[56] = spatial_metric_der[0][1][0]; + q[57] = spatial_metric_der[0][1][1]; + q[58] = spatial_metric_der[0][1][2]; + q[59] = spatial_metric_der[0][2][0]; + q[60] = spatial_metric_der[0][2][1]; + q[61] = spatial_metric_der[0][2][2]; + + q[62] = spatial_metric_der[1][0][0]; + q[63] = spatial_metric_der[1][0][1]; + q[64] = spatial_metric_der[1][0][2]; + q[65] = spatial_metric_der[1][1][0]; + q[66] = spatial_metric_der[1][1][1]; + q[67] = spatial_metric_der[1][1][2]; + q[68] = spatial_metric_der[1][2][0]; + q[69] = spatial_metric_der[1][2][1]; + q[70] = spatial_metric_der[1][2][2]; + + q[71] = spatial_metric_der[2][0][0]; + q[72] = spatial_metric_der[2][0][1]; + q[73] = spatial_metric_der[2][0][2]; + q[74] = spatial_metric_der[2][1][0]; + q[75] = spatial_metric_der[2][1][1]; + q[76] = spatial_metric_der[2][1][2]; + q[77] = spatial_metric_der[2][2][0]; + q[78] = spatial_metric_der[2][2][1]; + q[79] = spatial_metric_der[2][2][2]; q[80] = 0.0; - q[81] = x; q[82] = y; q[83] = 0.0; + q[81] = x; + q[82] = y; + q[83] = 0.0; double prims[84]; gkyl_gr_twofluid_prim_vars(gas_gamma_elc, gas_gamma_ion, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho_elc, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); - - TEST_CHECK( gkyl_compare(prims[5], rho_ion, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[6], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[7], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[8], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[9], p, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho_elc, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], rho_ion, 1e-1)); + TEST_CHECK(gkyl_compare(prims[6], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[7], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[8], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[9], p, 1e-1)); double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -713,70 +941,95 @@ test_gr_twofluid_basic_kerr_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][18] = { - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[84], flux_local[84], flux[84]; for (int d = 0; d < 3; d++) { gr_twofluid->rotate_to_local_func(gr_twofluid, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_gr_twofluid_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local); - gr_twofluid->rotate_to_global_func(gr_twofluid, tau1[d], tau2[d], norm[d], flux_local, flux); + gkyl_gr_twofluid_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local + ); + gr_twofluid->rotate_to_global_func( + gr_twofluid, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 18; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } @@ -786,15 +1039,15 @@ test_gr_twofluid_basic_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } - + double w1[84], q1[84]; gr_twofluid->cons_to_riem(gr_twofluid, q_local, q_local, w1); gr_twofluid->riem_to_cons(gr_twofluid, q_local, w1, q1); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -803,7 +1056,7 @@ test_gr_twofluid_basic_kerr_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -823,8 +1076,7 @@ test_gr_twofluid_basic_kerr_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_twofluid_waves_minkowski_ho() +void test_gr_twofluid_waves_minkowski_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -838,8 +1090,10 @@ test_gr_twofluid_waves_minkowski_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -865,10 +1119,10 @@ test_gr_twofluid_waves_minkowski_ho() double *shift_l = gkyl_malloc(sizeof(double[3])); double *shift_r = gkyl_malloc(sizeof(double[3])); - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -878,18 +1132,18 @@ test_gr_twofluid_waves_minkowski_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -906,20 +1160,46 @@ test_gr_twofluid_waves_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -949,42 +1229,89 @@ test_gr_twofluid_waves_minkowski_ho() ql[8] = sqrt(spatial_det_l) * rho_ion_l * hi_l * (W_l * W_l) * w_l; ql[9] = sqrt(spatial_det_l) * ((rho_ion_l * hi_l * (W_l * W_l)) - p_l - (rho_ion_l * W_l)); - ql[10] = Dx_l; ql[11] = Dy_l; ql[12] = Dz_l; - ql[13] = Bx_l; ql[14] = By_l; ql[15] = Bz_l; - ql[16] = phi_l; ql[17] = psi_l; + ql[10] = Dx_l; + ql[11] = Dy_l; + ql[12] = Dz_l; + ql[13] = Bx_l; + ql[14] = By_l; + ql[15] = Bz_l; + ql[16] = phi_l; + ql[17] = psi_l; ql[18] = lapse_l; - ql[19] = shift_l[0]; ql[20] = shift_l[1]; ql[21] = shift_l[2]; - - ql[22] = spatial_metric_l[0][0]; ql[23] = spatial_metric_l[0][1]; ql[24] = spatial_metric_l[0][2]; - ql[25] = spatial_metric_l[1][0]; ql[26] = spatial_metric_l[1][1]; ql[27] = spatial_metric_l[1][2]; - ql[28] = spatial_metric_l[2][0]; ql[29] = spatial_metric_l[2][1]; ql[30] = spatial_metric_l[2][2]; - - ql[31] = extrinsic_curvature_l[0][0]; ql[32] = extrinsic_curvature_l[0][1]; ql[33] = extrinsic_curvature_l[0][2]; - ql[34] = extrinsic_curvature_l[1][0]; ql[35] = extrinsic_curvature_l[1][1]; ql[36] = extrinsic_curvature_l[1][2]; - ql[37] = extrinsic_curvature_l[2][0]; ql[38] = extrinsic_curvature_l[2][1]; ql[39] = extrinsic_curvature_l[2][2]; + ql[19] = shift_l[0]; + ql[20] = shift_l[1]; + ql[21] = shift_l[2]; + + ql[22] = spatial_metric_l[0][0]; + ql[23] = spatial_metric_l[0][1]; + ql[24] = spatial_metric_l[0][2]; + ql[25] = spatial_metric_l[1][0]; + ql[26] = spatial_metric_l[1][1]; + ql[27] = spatial_metric_l[1][2]; + ql[28] = spatial_metric_l[2][0]; + ql[29] = spatial_metric_l[2][1]; + ql[30] = spatial_metric_l[2][2]; + + ql[31] = extrinsic_curvature_l[0][0]; + ql[32] = extrinsic_curvature_l[0][1]; + ql[33] = extrinsic_curvature_l[0][2]; + ql[34] = extrinsic_curvature_l[1][0]; + ql[35] = extrinsic_curvature_l[1][1]; + ql[36] = extrinsic_curvature_l[1][2]; + ql[37] = extrinsic_curvature_l[2][0]; + ql[38] = extrinsic_curvature_l[2][1]; + ql[39] = extrinsic_curvature_l[2][2]; ql[40] = 1.0; - ql[41] = lapse_der_l[0]; ql[42] = lapse_der_l[1]; ql[43] = lapse_der_l[2]; - ql[44] = shift_der_l[0][0]; ql[45] = shift_der_l[0][1]; ql[46] = shift_der_l[0][2]; - ql[47] = shift_der_l[1][0]; ql[48] = shift_der_l[1][1]; ql[49] = shift_der_l[1][2]; - ql[50] = shift_der_l[2][0]; ql[51] = shift_der_l[2][1]; ql[52] = shift_der_l[2][2]; - - ql[53] = spatial_metric_der_l[0][0][0]; ql[54] = spatial_metric_der_l[0][0][1]; ql[55] = spatial_metric_der_l[0][0][2]; - ql[56] = spatial_metric_der_l[0][1][0]; ql[57] = spatial_metric_der_l[0][1][1]; ql[58] = spatial_metric_der_l[0][1][2]; - ql[59] = spatial_metric_der_l[0][2][0]; ql[60] = spatial_metric_der_l[0][2][1]; ql[61] = spatial_metric_der_l[0][2][2]; - - ql[62] = spatial_metric_der_l[1][0][0]; ql[63] = spatial_metric_der_l[1][0][1]; ql[64] = spatial_metric_der_l[1][0][2]; - ql[65] = spatial_metric_der_l[1][1][0]; ql[66] = spatial_metric_der_l[1][1][1]; ql[67] = spatial_metric_der_l[1][1][2]; - ql[68] = spatial_metric_der_l[1][2][0]; ql[69] = spatial_metric_der_l[1][2][1]; ql[70] = spatial_metric_der_l[1][2][2]; - - ql[71] = spatial_metric_der_l[2][0][0]; ql[72] = spatial_metric_der_l[2][0][1]; ql[73] = spatial_metric_der_l[2][0][2]; - ql[74] = spatial_metric_der_l[2][1][0]; ql[75] = spatial_metric_der_l[2][1][1]; ql[76] = spatial_metric_der_l[2][1][2]; - ql[77] = spatial_metric_der_l[2][2][0]; ql[78] = spatial_metric_der_l[2][2][1]; ql[79] = spatial_metric_der_l[2][2][2]; + ql[41] = lapse_der_l[0]; + ql[42] = lapse_der_l[1]; + ql[43] = lapse_der_l[2]; + ql[44] = shift_der_l[0][0]; + ql[45] = shift_der_l[0][1]; + ql[46] = shift_der_l[0][2]; + ql[47] = shift_der_l[1][0]; + ql[48] = shift_der_l[1][1]; + ql[49] = shift_der_l[1][2]; + ql[50] = shift_der_l[2][0]; + ql[51] = shift_der_l[2][1]; + ql[52] = shift_der_l[2][2]; + + ql[53] = spatial_metric_der_l[0][0][0]; + ql[54] = spatial_metric_der_l[0][0][1]; + ql[55] = spatial_metric_der_l[0][0][2]; + ql[56] = spatial_metric_der_l[0][1][0]; + ql[57] = spatial_metric_der_l[0][1][1]; + ql[58] = spatial_metric_der_l[0][1][2]; + ql[59] = spatial_metric_der_l[0][2][0]; + ql[60] = spatial_metric_der_l[0][2][1]; + ql[61] = spatial_metric_der_l[0][2][2]; + + ql[62] = spatial_metric_der_l[1][0][0]; + ql[63] = spatial_metric_der_l[1][0][1]; + ql[64] = spatial_metric_der_l[1][0][2]; + ql[65] = spatial_metric_der_l[1][1][0]; + ql[66] = spatial_metric_der_l[1][1][1]; + ql[67] = spatial_metric_der_l[1][1][2]; + ql[68] = spatial_metric_der_l[1][2][0]; + ql[69] = spatial_metric_der_l[1][2][1]; + ql[70] = spatial_metric_der_l[1][2][2]; + + ql[71] = spatial_metric_der_l[2][0][0]; + ql[72] = spatial_metric_der_l[2][0][1]; + ql[73] = spatial_metric_der_l[2][0][2]; + ql[74] = spatial_metric_der_l[2][1][0]; + ql[75] = spatial_metric_der_l[2][1][1]; + ql[76] = spatial_metric_der_l[2][1][2]; + ql[77] = spatial_metric_der_l[2][2][0]; + ql[78] = spatial_metric_der_l[2][2][1]; + ql[79] = spatial_metric_der_l[2][2][2]; ql[80] = 0.0; - ql[81] = x - 0.5; ql[82] = y; ql[83] = 0.0; + ql[81] = x - 0.5; + ql[82] = y; + ql[83] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_elc_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_elc_r * he_r * (W_r * W_r) * u_r; @@ -998,60 +1325,95 @@ test_gr_twofluid_waves_minkowski_ho() qr[8] = sqrt(spatial_det_r) * rho_ion_r * hi_r * (W_r * W_r) * w_r; qr[9] = sqrt(spatial_det_r) * ((rho_ion_r * hi_r * (W_r * W_r)) - p_r - (rho_ion_r * W_r)); - qr[10] = Dx_r; qr[11] = Dy_r; qr[12] = Dz_r; - qr[13] = Bx_r; qr[14] = By_r; qr[15] = Bz_r; - qr[16] = phi_r; qr[17] = psi_r; + qr[10] = Dx_r; + qr[11] = Dy_r; + qr[12] = Dz_r; + qr[13] = Bx_r; + qr[14] = By_r; + qr[15] = Bz_r; + qr[16] = phi_r; + qr[17] = psi_r; qr[18] = lapse_r; - qr[19] = shift_r[0]; qr[20] = shift_r[1]; qr[21] = shift_r[2]; - - qr[22] = spatial_metric_r[0][0]; qr[23] = spatial_metric_r[0][1]; qr[24] = spatial_metric_r[0][2]; - qr[25] = spatial_metric_r[1][0]; qr[26] = spatial_metric_r[1][1]; qr[27] = spatial_metric_r[1][2]; - qr[28] = spatial_metric_r[2][0]; qr[29] = spatial_metric_r[2][1]; qr[30] = spatial_metric_r[2][2]; - - qr[31] = extrinsic_curvature_r[0][0]; qr[32] = extrinsic_curvature_r[0][1]; qr[33] = extrinsic_curvature_r[0][2]; - qr[34] = extrinsic_curvature_r[1][0]; qr[35] = extrinsic_curvature_r[1][1]; qr[36] = extrinsic_curvature_r[1][2]; - qr[37] = extrinsic_curvature_r[2][0]; qr[38] = extrinsic_curvature_r[2][1]; qr[39] = extrinsic_curvature_r[2][2]; + qr[19] = shift_r[0]; + qr[20] = shift_r[1]; + qr[21] = shift_r[2]; + + qr[22] = spatial_metric_r[0][0]; + qr[23] = spatial_metric_r[0][1]; + qr[24] = spatial_metric_r[0][2]; + qr[25] = spatial_metric_r[1][0]; + qr[26] = spatial_metric_r[1][1]; + qr[27] = spatial_metric_r[1][2]; + qr[28] = spatial_metric_r[2][0]; + qr[29] = spatial_metric_r[2][1]; + qr[30] = spatial_metric_r[2][2]; + + qr[31] = extrinsic_curvature_r[0][0]; + qr[32] = extrinsic_curvature_r[0][1]; + qr[33] = extrinsic_curvature_r[0][2]; + qr[34] = extrinsic_curvature_r[1][0]; + qr[35] = extrinsic_curvature_r[1][1]; + qr[36] = extrinsic_curvature_r[1][2]; + qr[37] = extrinsic_curvature_r[2][0]; + qr[38] = extrinsic_curvature_r[2][1]; + qr[39] = extrinsic_curvature_r[2][2]; qr[40] = 1.0; - qr[41] = lapse_der_r[0]; qr[42] = lapse_der_r[1]; qr[43] = lapse_der_r[2]; - qr[44] = shift_der_r[0][0]; qr[45] = shift_der_r[0][1]; qr[46] = shift_der_r[0][2]; - qr[47] = shift_der_r[1][0]; qr[48] = shift_der_r[1][1]; qr[49] = shift_der_r[1][2]; - qr[50] = shift_der_r[2][0]; qr[51] = shift_der_r[2][1]; qr[52] = shift_der_r[2][2]; - - qr[53] = spatial_metric_der_r[0][0][0]; qr[54] = spatial_metric_der_r[0][0][1]; qr[55] = spatial_metric_der_r[0][0][2]; - qr[56] = spatial_metric_der_r[0][1][0]; qr[57] = spatial_metric_der_r[0][1][1]; qr[58] = spatial_metric_der_r[0][1][2]; - qr[59] = spatial_metric_der_r[0][2][0]; qr[60] = spatial_metric_der_r[0][2][1]; qr[61] = spatial_metric_der_r[0][2][2]; - - qr[62] = spatial_metric_der_r[1][0][0]; qr[63] = spatial_metric_der_r[1][0][1]; qr[64] = spatial_metric_der_r[1][0][2]; - qr[65] = spatial_metric_der_r[1][1][0]; qr[66] = spatial_metric_der_r[1][1][1]; qr[67] = spatial_metric_der_r[1][1][2]; - qr[68] = spatial_metric_der_r[1][2][0]; qr[69] = spatial_metric_der_r[1][2][1]; qr[70] = spatial_metric_der_r[1][2][2]; - - qr[71] = spatial_metric_der_r[2][0][0]; qr[72] = spatial_metric_der_r[2][0][1]; qr[73] = spatial_metric_der_r[2][0][2]; - qr[74] = spatial_metric_der_r[2][1][0]; qr[75] = spatial_metric_der_r[2][1][1]; qr[76] = spatial_metric_der_r[2][1][2]; - qr[77] = spatial_metric_der_r[2][2][0]; qr[78] = spatial_metric_der_r[2][2][1]; qr[79] = spatial_metric_der_r[2][2][2]; + qr[41] = lapse_der_r[0]; + qr[42] = lapse_der_r[1]; + qr[43] = lapse_der_r[2]; + qr[44] = shift_der_r[0][0]; + qr[45] = shift_der_r[0][1]; + qr[46] = shift_der_r[0][2]; + qr[47] = shift_der_r[1][0]; + qr[48] = shift_der_r[1][1]; + qr[49] = shift_der_r[1][2]; + qr[50] = shift_der_r[2][0]; + qr[51] = shift_der_r[2][1]; + qr[52] = shift_der_r[2][2]; + + qr[53] = spatial_metric_der_r[0][0][0]; + qr[54] = spatial_metric_der_r[0][0][1]; + qr[55] = spatial_metric_der_r[0][0][2]; + qr[56] = spatial_metric_der_r[0][1][0]; + qr[57] = spatial_metric_der_r[0][1][1]; + qr[58] = spatial_metric_der_r[0][1][2]; + qr[59] = spatial_metric_der_r[0][2][0]; + qr[60] = spatial_metric_der_r[0][2][1]; + qr[61] = spatial_metric_der_r[0][2][2]; + + qr[62] = spatial_metric_der_r[1][0][0]; + qr[63] = spatial_metric_der_r[1][0][1]; + qr[64] = spatial_metric_der_r[1][0][2]; + qr[65] = spatial_metric_der_r[1][1][0]; + qr[66] = spatial_metric_der_r[1][1][1]; + qr[67] = spatial_metric_der_r[1][1][2]; + qr[68] = spatial_metric_der_r[1][2][0]; + qr[69] = spatial_metric_der_r[1][2][1]; + qr[70] = spatial_metric_der_r[1][2][2]; + + qr[71] = spatial_metric_der_r[2][0][0]; + qr[72] = spatial_metric_der_r[2][0][1]; + qr[73] = spatial_metric_der_r[2][0][2]; + qr[74] = spatial_metric_der_r[2][1][0]; + qr[75] = spatial_metric_der_r[2][1][1]; + qr[76] = spatial_metric_der_r[2][1][2]; + qr[77] = spatial_metric_der_r[2][2][0]; + qr[78] = spatial_metric_der_r[2][2][1]; + qr[79] = spatial_metric_der_r[2][2][2]; qr[80] = 0.0; - qr[81] = x + 0.5; qr[82] = y; qr[83] = 0.0; + qr[81] = x + 0.5; + qr[82] = y; + qr[83] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 84], waves_local[3 * 84]; @@ -1065,13 +1427,21 @@ test_gr_twofluid_waves_minkowski_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[84], amdq_local[84]; - gkyl_wv_eqn_qfluct(gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84]); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84] + ); } double apdq[84], amdq[84]; @@ -1079,15 +1449,19 @@ test_gr_twofluid_waves_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], amdq_local, amdq); double fl_local[84], fr_local[84]; - gkyl_gr_twofluid_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local); - gkyl_gr_twofluid_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local); + gkyl_gr_twofluid_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local + ); + gkyl_gr_twofluid_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local + ); double fl[84], fr[84]; gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } @@ -1098,7 +1472,7 @@ test_gr_twofluid_waves_minkowski_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1127,8 +1501,7 @@ test_gr_twofluid_waves_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_twofluid_waves_schwarzschild_ho() +void test_gr_twofluid_waves_schwarzschild_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -1142,8 +1515,10 @@ test_gr_twofluid_waves_schwarzschild_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1170,10 +1545,10 @@ test_gr_twofluid_waves_schwarzschild_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1183,18 +1558,18 @@ test_gr_twofluid_waves_schwarzschild_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1213,20 +1588,46 @@ test_gr_twofluid_waves_schwarzschild_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1257,42 +1658,89 @@ test_gr_twofluid_waves_schwarzschild_ho() ql[8] = sqrt(spatial_det_l) * rho_ion_l * hi_l * (W_l * W_l) * w_l; ql[9] = sqrt(spatial_det_l) * ((rho_ion_l * hi_l * (W_l * W_l)) - p_l - (rho_ion_l * W_l)); - ql[10] = Dx_l; ql[11] = Dy_l; ql[12] = Dz_l; - ql[13] = Bx_l; ql[14] = By_l; ql[15] = Bz_l; - ql[16] = phi_l; ql[17] = psi_l; + ql[10] = Dx_l; + ql[11] = Dy_l; + ql[12] = Dz_l; + ql[13] = Bx_l; + ql[14] = By_l; + ql[15] = Bz_l; + ql[16] = phi_l; + ql[17] = psi_l; ql[18] = lapse_l; - ql[19] = shift_l[0]; ql[20] = shift_l[1]; ql[21] = shift_l[2]; - - ql[22] = spatial_metric_l[0][0]; ql[23] = spatial_metric_l[0][1]; ql[24] = spatial_metric_l[0][2]; - ql[25] = spatial_metric_l[1][0]; ql[26] = spatial_metric_l[1][1]; ql[27] = spatial_metric_l[1][2]; - ql[28] = spatial_metric_l[2][0]; ql[29] = spatial_metric_l[2][1]; ql[30] = spatial_metric_l[2][2]; - - ql[31] = extrinsic_curvature_l[0][0]; ql[32] = extrinsic_curvature_l[0][1]; ql[33] = extrinsic_curvature_l[0][2]; - ql[34] = extrinsic_curvature_l[1][0]; ql[35] = extrinsic_curvature_l[1][1]; ql[36] = extrinsic_curvature_l[1][2]; - ql[37] = extrinsic_curvature_l[2][0]; ql[38] = extrinsic_curvature_l[2][1]; ql[39] = extrinsic_curvature_l[2][2]; + ql[19] = shift_l[0]; + ql[20] = shift_l[1]; + ql[21] = shift_l[2]; + + ql[22] = spatial_metric_l[0][0]; + ql[23] = spatial_metric_l[0][1]; + ql[24] = spatial_metric_l[0][2]; + ql[25] = spatial_metric_l[1][0]; + ql[26] = spatial_metric_l[1][1]; + ql[27] = spatial_metric_l[1][2]; + ql[28] = spatial_metric_l[2][0]; + ql[29] = spatial_metric_l[2][1]; + ql[30] = spatial_metric_l[2][2]; + + ql[31] = extrinsic_curvature_l[0][0]; + ql[32] = extrinsic_curvature_l[0][1]; + ql[33] = extrinsic_curvature_l[0][2]; + ql[34] = extrinsic_curvature_l[1][0]; + ql[35] = extrinsic_curvature_l[1][1]; + ql[36] = extrinsic_curvature_l[1][2]; + ql[37] = extrinsic_curvature_l[2][0]; + ql[38] = extrinsic_curvature_l[2][1]; + ql[39] = extrinsic_curvature_l[2][2]; ql[40] = 1.0; - ql[41] = lapse_der_l[0]; ql[42] = lapse_der_l[1]; ql[43] = lapse_der_l[2]; - ql[44] = shift_der_l[0][0]; ql[45] = shift_der_l[0][1]; ql[46] = shift_der_l[0][2]; - ql[47] = shift_der_l[1][0]; ql[48] = shift_der_l[1][1]; ql[49] = shift_der_l[1][2]; - ql[50] = shift_der_l[2][0]; ql[51] = shift_der_l[2][1]; ql[52] = shift_der_l[2][2]; - - ql[53] = spatial_metric_der_l[0][0][0]; ql[54] = spatial_metric_der_l[0][0][1]; ql[55] = spatial_metric_der_l[0][0][2]; - ql[56] = spatial_metric_der_l[0][1][0]; ql[57] = spatial_metric_der_l[0][1][1]; ql[58] = spatial_metric_der_l[0][1][2]; - ql[59] = spatial_metric_der_l[0][2][0]; ql[60] = spatial_metric_der_l[0][2][1]; ql[61] = spatial_metric_der_l[0][2][2]; - - ql[62] = spatial_metric_der_l[1][0][0]; ql[63] = spatial_metric_der_l[1][0][1]; ql[64] = spatial_metric_der_l[1][0][2]; - ql[65] = spatial_metric_der_l[1][1][0]; ql[66] = spatial_metric_der_l[1][1][1]; ql[67] = spatial_metric_der_l[1][1][2]; - ql[68] = spatial_metric_der_l[1][2][0]; ql[69] = spatial_metric_der_l[1][2][1]; ql[70] = spatial_metric_der_l[1][2][2]; - - ql[71] = spatial_metric_der_l[2][0][0]; ql[72] = spatial_metric_der_l[2][0][1]; ql[73] = spatial_metric_der_l[2][0][2]; - ql[74] = spatial_metric_der_l[2][1][0]; ql[75] = spatial_metric_der_l[2][1][1]; ql[76] = spatial_metric_der_l[2][1][2]; - ql[77] = spatial_metric_der_l[2][2][0]; ql[78] = spatial_metric_der_l[2][2][1]; ql[79] = spatial_metric_der_l[2][2][2]; + ql[41] = lapse_der_l[0]; + ql[42] = lapse_der_l[1]; + ql[43] = lapse_der_l[2]; + ql[44] = shift_der_l[0][0]; + ql[45] = shift_der_l[0][1]; + ql[46] = shift_der_l[0][2]; + ql[47] = shift_der_l[1][0]; + ql[48] = shift_der_l[1][1]; + ql[49] = shift_der_l[1][2]; + ql[50] = shift_der_l[2][0]; + ql[51] = shift_der_l[2][1]; + ql[52] = shift_der_l[2][2]; + + ql[53] = spatial_metric_der_l[0][0][0]; + ql[54] = spatial_metric_der_l[0][0][1]; + ql[55] = spatial_metric_der_l[0][0][2]; + ql[56] = spatial_metric_der_l[0][1][0]; + ql[57] = spatial_metric_der_l[0][1][1]; + ql[58] = spatial_metric_der_l[0][1][2]; + ql[59] = spatial_metric_der_l[0][2][0]; + ql[60] = spatial_metric_der_l[0][2][1]; + ql[61] = spatial_metric_der_l[0][2][2]; + + ql[62] = spatial_metric_der_l[1][0][0]; + ql[63] = spatial_metric_der_l[1][0][1]; + ql[64] = spatial_metric_der_l[1][0][2]; + ql[65] = spatial_metric_der_l[1][1][0]; + ql[66] = spatial_metric_der_l[1][1][1]; + ql[67] = spatial_metric_der_l[1][1][2]; + ql[68] = spatial_metric_der_l[1][2][0]; + ql[69] = spatial_metric_der_l[1][2][1]; + ql[70] = spatial_metric_der_l[1][2][2]; + + ql[71] = spatial_metric_der_l[2][0][0]; + ql[72] = spatial_metric_der_l[2][0][1]; + ql[73] = spatial_metric_der_l[2][0][2]; + ql[74] = spatial_metric_der_l[2][1][0]; + ql[75] = spatial_metric_der_l[2][1][1]; + ql[76] = spatial_metric_der_l[2][1][2]; + ql[77] = spatial_metric_der_l[2][2][0]; + ql[78] = spatial_metric_der_l[2][2][1]; + ql[79] = spatial_metric_der_l[2][2][2]; ql[80] = 0.0; - ql[81] = x - 0.5; ql[82] = y; ql[83] = 0.0; + ql[81] = x - 0.5; + ql[82] = y; + ql[83] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_elc_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_elc_r * he_r * (W_r * W_r) * u_r; @@ -1306,60 +1754,95 @@ test_gr_twofluid_waves_schwarzschild_ho() qr[8] = sqrt(spatial_det_r) * rho_ion_r * hi_r * (W_r * W_r) * w_r; qr[9] = sqrt(spatial_det_r) * ((rho_ion_r * hi_r * (W_r * W_r)) - p_r - (rho_ion_r * W_r)); - qr[10] = Dx_r; qr[11] = Dy_r; qr[12] = Dz_r; - qr[13] = Bx_r; qr[14] = By_r; qr[15] = Bz_r; - qr[16] = phi_r; qr[17] = psi_r; + qr[10] = Dx_r; + qr[11] = Dy_r; + qr[12] = Dz_r; + qr[13] = Bx_r; + qr[14] = By_r; + qr[15] = Bz_r; + qr[16] = phi_r; + qr[17] = psi_r; qr[18] = lapse_r; - qr[19] = shift_r[0]; qr[20] = shift_r[1]; qr[21] = shift_r[2]; - - qr[22] = spatial_metric_r[0][0]; qr[23] = spatial_metric_r[0][1]; qr[24] = spatial_metric_r[0][2]; - qr[25] = spatial_metric_r[1][0]; qr[26] = spatial_metric_r[1][1]; qr[27] = spatial_metric_r[1][2]; - qr[28] = spatial_metric_r[2][0]; qr[29] = spatial_metric_r[2][1]; qr[30] = spatial_metric_r[2][2]; - - qr[31] = extrinsic_curvature_r[0][0]; qr[32] = extrinsic_curvature_r[0][1]; qr[33] = extrinsic_curvature_r[0][2]; - qr[34] = extrinsic_curvature_r[1][0]; qr[35] = extrinsic_curvature_r[1][1]; qr[36] = extrinsic_curvature_r[1][2]; - qr[37] = extrinsic_curvature_r[2][0]; qr[38] = extrinsic_curvature_r[2][1]; qr[39] = extrinsic_curvature_r[2][2]; + qr[19] = shift_r[0]; + qr[20] = shift_r[1]; + qr[21] = shift_r[2]; + + qr[22] = spatial_metric_r[0][0]; + qr[23] = spatial_metric_r[0][1]; + qr[24] = spatial_metric_r[0][2]; + qr[25] = spatial_metric_r[1][0]; + qr[26] = spatial_metric_r[1][1]; + qr[27] = spatial_metric_r[1][2]; + qr[28] = spatial_metric_r[2][0]; + qr[29] = spatial_metric_r[2][1]; + qr[30] = spatial_metric_r[2][2]; + + qr[31] = extrinsic_curvature_r[0][0]; + qr[32] = extrinsic_curvature_r[0][1]; + qr[33] = extrinsic_curvature_r[0][2]; + qr[34] = extrinsic_curvature_r[1][0]; + qr[35] = extrinsic_curvature_r[1][1]; + qr[36] = extrinsic_curvature_r[1][2]; + qr[37] = extrinsic_curvature_r[2][0]; + qr[38] = extrinsic_curvature_r[2][1]; + qr[39] = extrinsic_curvature_r[2][2]; qr[40] = 1.0; - qr[41] = lapse_der_r[0]; qr[42] = lapse_der_r[1]; qr[43] = lapse_der_r[2]; - qr[44] = shift_der_r[0][0]; qr[45] = shift_der_r[0][1]; qr[46] = shift_der_r[0][2]; - qr[47] = shift_der_r[1][0]; qr[48] = shift_der_r[1][1]; qr[49] = shift_der_r[1][2]; - qr[50] = shift_der_r[2][0]; qr[51] = shift_der_r[2][1]; qr[52] = shift_der_r[2][2]; - - qr[53] = spatial_metric_der_r[0][0][0]; qr[54] = spatial_metric_der_r[0][0][1]; qr[55] = spatial_metric_der_r[0][0][2]; - qr[56] = spatial_metric_der_r[0][1][0]; qr[57] = spatial_metric_der_r[0][1][1]; qr[58] = spatial_metric_der_r[0][1][2]; - qr[59] = spatial_metric_der_r[0][2][0]; qr[60] = spatial_metric_der_r[0][2][1]; qr[61] = spatial_metric_der_r[0][2][2]; - - qr[62] = spatial_metric_der_r[1][0][0]; qr[63] = spatial_metric_der_r[1][0][1]; qr[64] = spatial_metric_der_r[1][0][2]; - qr[65] = spatial_metric_der_r[1][1][0]; qr[66] = spatial_metric_der_r[1][1][1]; qr[67] = spatial_metric_der_r[1][1][2]; - qr[68] = spatial_metric_der_r[1][2][0]; qr[69] = spatial_metric_der_r[1][2][1]; qr[70] = spatial_metric_der_r[1][2][2]; - - qr[71] = spatial_metric_der_r[2][0][0]; qr[72] = spatial_metric_der_r[2][0][1]; qr[73] = spatial_metric_der_r[2][0][2]; - qr[74] = spatial_metric_der_r[2][1][0]; qr[75] = spatial_metric_der_r[2][1][1]; qr[76] = spatial_metric_der_r[2][1][2]; - qr[77] = spatial_metric_der_r[2][2][0]; qr[78] = spatial_metric_der_r[2][2][1]; qr[79] = spatial_metric_der_r[2][2][2]; + qr[41] = lapse_der_r[0]; + qr[42] = lapse_der_r[1]; + qr[43] = lapse_der_r[2]; + qr[44] = shift_der_r[0][0]; + qr[45] = shift_der_r[0][1]; + qr[46] = shift_der_r[0][2]; + qr[47] = shift_der_r[1][0]; + qr[48] = shift_der_r[1][1]; + qr[49] = shift_der_r[1][2]; + qr[50] = shift_der_r[2][0]; + qr[51] = shift_der_r[2][1]; + qr[52] = shift_der_r[2][2]; + + qr[53] = spatial_metric_der_r[0][0][0]; + qr[54] = spatial_metric_der_r[0][0][1]; + qr[55] = spatial_metric_der_r[0][0][2]; + qr[56] = spatial_metric_der_r[0][1][0]; + qr[57] = spatial_metric_der_r[0][1][1]; + qr[58] = spatial_metric_der_r[0][1][2]; + qr[59] = spatial_metric_der_r[0][2][0]; + qr[60] = spatial_metric_der_r[0][2][1]; + qr[61] = spatial_metric_der_r[0][2][2]; + + qr[62] = spatial_metric_der_r[1][0][0]; + qr[63] = spatial_metric_der_r[1][0][1]; + qr[64] = spatial_metric_der_r[1][0][2]; + qr[65] = spatial_metric_der_r[1][1][0]; + qr[66] = spatial_metric_der_r[1][1][1]; + qr[67] = spatial_metric_der_r[1][1][2]; + qr[68] = spatial_metric_der_r[1][2][0]; + qr[69] = spatial_metric_der_r[1][2][1]; + qr[70] = spatial_metric_der_r[1][2][2]; + + qr[71] = spatial_metric_der_r[2][0][0]; + qr[72] = spatial_metric_der_r[2][0][1]; + qr[73] = spatial_metric_der_r[2][0][2]; + qr[74] = spatial_metric_der_r[2][1][0]; + qr[75] = spatial_metric_der_r[2][1][1]; + qr[76] = spatial_metric_der_r[2][1][2]; + qr[77] = spatial_metric_der_r[2][2][0]; + qr[78] = spatial_metric_der_r[2][2][1]; + qr[79] = spatial_metric_der_r[2][2][2]; qr[80] = 0.0; - qr[81] = x + 0.5; qr[82] = y; qr[83] = 0.0; + qr[81] = x + 0.5; + qr[82] = y; + qr[83] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 84], waves_local[3 * 84]; @@ -1373,13 +1856,21 @@ test_gr_twofluid_waves_schwarzschild_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[84], amdq_local[84]; - gkyl_wv_eqn_qfluct(gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84]); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84] + ); } double apdq[84], amdq[84]; @@ -1387,15 +1878,19 @@ test_gr_twofluid_waves_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], amdq_local, amdq); double fl_local[84], fr_local[84]; - gkyl_gr_twofluid_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local); - gkyl_gr_twofluid_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local); + gkyl_gr_twofluid_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local + ); + gkyl_gr_twofluid_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local + ); double fl[84], fr[84]; gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1407,7 +1902,7 @@ test_gr_twofluid_waves_schwarzschild_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1436,8 +1931,7 @@ test_gr_twofluid_waves_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_twofluid_waves_kerr_ho() +void test_gr_twofluid_waves_kerr_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -1451,8 +1945,10 @@ test_gr_twofluid_waves_kerr_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid = gkyl_wv_gr_twofluid_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1479,10 +1975,10 @@ test_gr_twofluid_waves_kerr_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1492,18 +1988,18 @@ test_gr_twofluid_waves_kerr_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1522,20 +2018,46 @@ test_gr_twofluid_waves_kerr_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1566,42 +2088,89 @@ test_gr_twofluid_waves_kerr_ho() ql[8] = sqrt(spatial_det_l) * rho_ion_l * hi_l * (W_l * W_l) * w_l; ql[9] = sqrt(spatial_det_l) * ((rho_ion_l * hi_l * (W_l * W_l)) - p_l - (rho_ion_l * W_l)); - ql[10] = Dx_l; ql[11] = Dy_l; ql[12] = Dz_l; - ql[13] = Bx_l; ql[14] = By_l; ql[15] = Bz_l; - ql[16] = phi_l; ql[17] = psi_l; + ql[10] = Dx_l; + ql[11] = Dy_l; + ql[12] = Dz_l; + ql[13] = Bx_l; + ql[14] = By_l; + ql[15] = Bz_l; + ql[16] = phi_l; + ql[17] = psi_l; ql[18] = lapse_l; - ql[19] = shift_l[0]; ql[20] = shift_l[1]; ql[21] = shift_l[2]; - - ql[22] = spatial_metric_l[0][0]; ql[23] = spatial_metric_l[0][1]; ql[24] = spatial_metric_l[0][2]; - ql[25] = spatial_metric_l[1][0]; ql[26] = spatial_metric_l[1][1]; ql[27] = spatial_metric_l[1][2]; - ql[28] = spatial_metric_l[2][0]; ql[29] = spatial_metric_l[2][1]; ql[30] = spatial_metric_l[2][2]; - - ql[31] = extrinsic_curvature_l[0][0]; ql[32] = extrinsic_curvature_l[0][1]; ql[33] = extrinsic_curvature_l[0][2]; - ql[34] = extrinsic_curvature_l[1][0]; ql[35] = extrinsic_curvature_l[1][1]; ql[36] = extrinsic_curvature_l[1][2]; - ql[37] = extrinsic_curvature_l[2][0]; ql[38] = extrinsic_curvature_l[2][1]; ql[39] = extrinsic_curvature_l[2][2]; + ql[19] = shift_l[0]; + ql[20] = shift_l[1]; + ql[21] = shift_l[2]; + + ql[22] = spatial_metric_l[0][0]; + ql[23] = spatial_metric_l[0][1]; + ql[24] = spatial_metric_l[0][2]; + ql[25] = spatial_metric_l[1][0]; + ql[26] = spatial_metric_l[1][1]; + ql[27] = spatial_metric_l[1][2]; + ql[28] = spatial_metric_l[2][0]; + ql[29] = spatial_metric_l[2][1]; + ql[30] = spatial_metric_l[2][2]; + + ql[31] = extrinsic_curvature_l[0][0]; + ql[32] = extrinsic_curvature_l[0][1]; + ql[33] = extrinsic_curvature_l[0][2]; + ql[34] = extrinsic_curvature_l[1][0]; + ql[35] = extrinsic_curvature_l[1][1]; + ql[36] = extrinsic_curvature_l[1][2]; + ql[37] = extrinsic_curvature_l[2][0]; + ql[38] = extrinsic_curvature_l[2][1]; + ql[39] = extrinsic_curvature_l[2][2]; ql[40] = 1.0; - ql[41] = lapse_der_l[0]; ql[42] = lapse_der_l[1]; ql[43] = lapse_der_l[2]; - ql[44] = shift_der_l[0][0]; ql[45] = shift_der_l[0][1]; ql[46] = shift_der_l[0][2]; - ql[47] = shift_der_l[1][0]; ql[48] = shift_der_l[1][1]; ql[49] = shift_der_l[1][2]; - ql[50] = shift_der_l[2][0]; ql[51] = shift_der_l[2][1]; ql[52] = shift_der_l[2][2]; - - ql[53] = spatial_metric_der_l[0][0][0]; ql[54] = spatial_metric_der_l[0][0][1]; ql[55] = spatial_metric_der_l[0][0][2]; - ql[56] = spatial_metric_der_l[0][1][0]; ql[57] = spatial_metric_der_l[0][1][1]; ql[58] = spatial_metric_der_l[0][1][2]; - ql[59] = spatial_metric_der_l[0][2][0]; ql[60] = spatial_metric_der_l[0][2][1]; ql[61] = spatial_metric_der_l[0][2][2]; - - ql[62] = spatial_metric_der_l[1][0][0]; ql[63] = spatial_metric_der_l[1][0][1]; ql[64] = spatial_metric_der_l[1][0][2]; - ql[65] = spatial_metric_der_l[1][1][0]; ql[66] = spatial_metric_der_l[1][1][1]; ql[67] = spatial_metric_der_l[1][1][2]; - ql[68] = spatial_metric_der_l[1][2][0]; ql[69] = spatial_metric_der_l[1][2][1]; ql[70] = spatial_metric_der_l[1][2][2]; - - ql[71] = spatial_metric_der_l[2][0][0]; ql[72] = spatial_metric_der_l[2][0][1]; ql[73] = spatial_metric_der_l[2][0][2]; - ql[74] = spatial_metric_der_l[2][1][0]; ql[75] = spatial_metric_der_l[2][1][1]; ql[76] = spatial_metric_der_l[2][1][2]; - ql[77] = spatial_metric_der_l[2][2][0]; ql[78] = spatial_metric_der_l[2][2][1]; ql[79] = spatial_metric_der_l[2][2][2]; + ql[41] = lapse_der_l[0]; + ql[42] = lapse_der_l[1]; + ql[43] = lapse_der_l[2]; + ql[44] = shift_der_l[0][0]; + ql[45] = shift_der_l[0][1]; + ql[46] = shift_der_l[0][2]; + ql[47] = shift_der_l[1][0]; + ql[48] = shift_der_l[1][1]; + ql[49] = shift_der_l[1][2]; + ql[50] = shift_der_l[2][0]; + ql[51] = shift_der_l[2][1]; + ql[52] = shift_der_l[2][2]; + + ql[53] = spatial_metric_der_l[0][0][0]; + ql[54] = spatial_metric_der_l[0][0][1]; + ql[55] = spatial_metric_der_l[0][0][2]; + ql[56] = spatial_metric_der_l[0][1][0]; + ql[57] = spatial_metric_der_l[0][1][1]; + ql[58] = spatial_metric_der_l[0][1][2]; + ql[59] = spatial_metric_der_l[0][2][0]; + ql[60] = spatial_metric_der_l[0][2][1]; + ql[61] = spatial_metric_der_l[0][2][2]; + + ql[62] = spatial_metric_der_l[1][0][0]; + ql[63] = spatial_metric_der_l[1][0][1]; + ql[64] = spatial_metric_der_l[1][0][2]; + ql[65] = spatial_metric_der_l[1][1][0]; + ql[66] = spatial_metric_der_l[1][1][1]; + ql[67] = spatial_metric_der_l[1][1][2]; + ql[68] = spatial_metric_der_l[1][2][0]; + ql[69] = spatial_metric_der_l[1][2][1]; + ql[70] = spatial_metric_der_l[1][2][2]; + + ql[71] = spatial_metric_der_l[2][0][0]; + ql[72] = spatial_metric_der_l[2][0][1]; + ql[73] = spatial_metric_der_l[2][0][2]; + ql[74] = spatial_metric_der_l[2][1][0]; + ql[75] = spatial_metric_der_l[2][1][1]; + ql[76] = spatial_metric_der_l[2][1][2]; + ql[77] = spatial_metric_der_l[2][2][0]; + ql[78] = spatial_metric_der_l[2][2][1]; + ql[79] = spatial_metric_der_l[2][2][2]; ql[80] = 0.0; - ql[81] = x - 0.5; ql[82] = y; ql[83] = 0.0; + ql[81] = x - 0.5; + ql[82] = y; + ql[83] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_elc_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_elc_r * he_r * (W_r * W_r) * u_r; @@ -1615,60 +2184,95 @@ test_gr_twofluid_waves_kerr_ho() qr[8] = sqrt(spatial_det_r) * rho_ion_r * hi_r * (W_r * W_r) * w_r; qr[9] = sqrt(spatial_det_r) * ((rho_ion_r * hi_r * (W_r * W_r)) - p_r - (rho_ion_r * W_r)); - qr[10] = Dx_r; qr[11] = Dy_r; qr[12] = Dz_r; - qr[13] = Bx_r; qr[14] = By_r; qr[15] = Bz_r; - qr[16] = phi_r; qr[17] = psi_r; + qr[10] = Dx_r; + qr[11] = Dy_r; + qr[12] = Dz_r; + qr[13] = Bx_r; + qr[14] = By_r; + qr[15] = Bz_r; + qr[16] = phi_r; + qr[17] = psi_r; qr[18] = lapse_r; - qr[19] = shift_r[0]; qr[20] = shift_r[1]; qr[21] = shift_r[2]; - - qr[22] = spatial_metric_r[0][0]; qr[23] = spatial_metric_r[0][1]; qr[24] = spatial_metric_r[0][2]; - qr[25] = spatial_metric_r[1][0]; qr[26] = spatial_metric_r[1][1]; qr[27] = spatial_metric_r[1][2]; - qr[28] = spatial_metric_r[2][0]; qr[29] = spatial_metric_r[2][1]; qr[30] = spatial_metric_r[2][2]; - - qr[31] = extrinsic_curvature_r[0][0]; qr[32] = extrinsic_curvature_r[0][1]; qr[33] = extrinsic_curvature_r[0][2]; - qr[34] = extrinsic_curvature_r[1][0]; qr[35] = extrinsic_curvature_r[1][1]; qr[36] = extrinsic_curvature_r[1][2]; - qr[37] = extrinsic_curvature_r[2][0]; qr[38] = extrinsic_curvature_r[2][1]; qr[39] = extrinsic_curvature_r[2][2]; + qr[19] = shift_r[0]; + qr[20] = shift_r[1]; + qr[21] = shift_r[2]; + + qr[22] = spatial_metric_r[0][0]; + qr[23] = spatial_metric_r[0][1]; + qr[24] = spatial_metric_r[0][2]; + qr[25] = spatial_metric_r[1][0]; + qr[26] = spatial_metric_r[1][1]; + qr[27] = spatial_metric_r[1][2]; + qr[28] = spatial_metric_r[2][0]; + qr[29] = spatial_metric_r[2][1]; + qr[30] = spatial_metric_r[2][2]; + + qr[31] = extrinsic_curvature_r[0][0]; + qr[32] = extrinsic_curvature_r[0][1]; + qr[33] = extrinsic_curvature_r[0][2]; + qr[34] = extrinsic_curvature_r[1][0]; + qr[35] = extrinsic_curvature_r[1][1]; + qr[36] = extrinsic_curvature_r[1][2]; + qr[37] = extrinsic_curvature_r[2][0]; + qr[38] = extrinsic_curvature_r[2][1]; + qr[39] = extrinsic_curvature_r[2][2]; qr[40] = 1.0; - qr[41] = lapse_der_r[0]; qr[42] = lapse_der_r[1]; qr[43] = lapse_der_r[2]; - qr[44] = shift_der_r[0][0]; qr[45] = shift_der_r[0][1]; qr[46] = shift_der_r[0][2]; - qr[47] = shift_der_r[1][0]; qr[48] = shift_der_r[1][1]; qr[49] = shift_der_r[1][2]; - qr[50] = shift_der_r[2][0]; qr[51] = shift_der_r[2][1]; qr[52] = shift_der_r[2][2]; - - qr[53] = spatial_metric_der_r[0][0][0]; qr[54] = spatial_metric_der_r[0][0][1]; qr[55] = spatial_metric_der_r[0][0][2]; - qr[56] = spatial_metric_der_r[0][1][0]; qr[57] = spatial_metric_der_r[0][1][1]; qr[58] = spatial_metric_der_r[0][1][2]; - qr[59] = spatial_metric_der_r[0][2][0]; qr[60] = spatial_metric_der_r[0][2][1]; qr[61] = spatial_metric_der_r[0][2][2]; - - qr[62] = spatial_metric_der_r[1][0][0]; qr[63] = spatial_metric_der_r[1][0][1]; qr[64] = spatial_metric_der_r[1][0][2]; - qr[65] = spatial_metric_der_r[1][1][0]; qr[66] = spatial_metric_der_r[1][1][1]; qr[67] = spatial_metric_der_r[1][1][2]; - qr[68] = spatial_metric_der_r[1][2][0]; qr[69] = spatial_metric_der_r[1][2][1]; qr[70] = spatial_metric_der_r[1][2][2]; - - qr[71] = spatial_metric_der_r[2][0][0]; qr[72] = spatial_metric_der_r[2][0][1]; qr[73] = spatial_metric_der_r[2][0][2]; - qr[74] = spatial_metric_der_r[2][1][0]; qr[75] = spatial_metric_der_r[2][1][1]; qr[76] = spatial_metric_der_r[2][1][2]; - qr[77] = spatial_metric_der_r[2][2][0]; qr[78] = spatial_metric_der_r[2][2][1]; qr[79] = spatial_metric_der_r[2][2][2]; + qr[41] = lapse_der_r[0]; + qr[42] = lapse_der_r[1]; + qr[43] = lapse_der_r[2]; + qr[44] = shift_der_r[0][0]; + qr[45] = shift_der_r[0][1]; + qr[46] = shift_der_r[0][2]; + qr[47] = shift_der_r[1][0]; + qr[48] = shift_der_r[1][1]; + qr[49] = shift_der_r[1][2]; + qr[50] = shift_der_r[2][0]; + qr[51] = shift_der_r[2][1]; + qr[52] = shift_der_r[2][2]; + + qr[53] = spatial_metric_der_r[0][0][0]; + qr[54] = spatial_metric_der_r[0][0][1]; + qr[55] = spatial_metric_der_r[0][0][2]; + qr[56] = spatial_metric_der_r[0][1][0]; + qr[57] = spatial_metric_der_r[0][1][1]; + qr[58] = spatial_metric_der_r[0][1][2]; + qr[59] = spatial_metric_der_r[0][2][0]; + qr[60] = spatial_metric_der_r[0][2][1]; + qr[61] = spatial_metric_der_r[0][2][2]; + + qr[62] = spatial_metric_der_r[1][0][0]; + qr[63] = spatial_metric_der_r[1][0][1]; + qr[64] = spatial_metric_der_r[1][0][2]; + qr[65] = spatial_metric_der_r[1][1][0]; + qr[66] = spatial_metric_der_r[1][1][1]; + qr[67] = spatial_metric_der_r[1][1][2]; + qr[68] = spatial_metric_der_r[1][2][0]; + qr[69] = spatial_metric_der_r[1][2][1]; + qr[70] = spatial_metric_der_r[1][2][2]; + + qr[71] = spatial_metric_der_r[2][0][0]; + qr[72] = spatial_metric_der_r[2][0][1]; + qr[73] = spatial_metric_der_r[2][0][2]; + qr[74] = spatial_metric_der_r[2][1][0]; + qr[75] = spatial_metric_der_r[2][1][1]; + qr[76] = spatial_metric_der_r[2][1][2]; + qr[77] = spatial_metric_der_r[2][2][0]; + qr[78] = spatial_metric_der_r[2][2][1]; + qr[79] = spatial_metric_der_r[2][2][2]; qr[80] = 0.0; - qr[81] = x + 0.5; qr[82] = y; qr[83] = 0.0; + qr[81] = x + 0.5; + qr[82] = y; + qr[83] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 84], waves_local[3 * 84]; @@ -1682,13 +2286,21 @@ test_gr_twofluid_waves_kerr_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[84], amdq_local[84]; - gkyl_wv_eqn_qfluct(gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_twofluid, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84]); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84] + ); } double apdq[84], amdq[84]; @@ -1696,15 +2308,19 @@ test_gr_twofluid_waves_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], amdq_local, amdq); double fl_local[84], fr_local[84]; - gkyl_gr_twofluid_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local); - gkyl_gr_twofluid_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local); + gkyl_gr_twofluid_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local + ); + gkyl_gr_twofluid_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local + ); double fl[84], fr[84]; gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(gr_twofluid, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1716,7 +2332,7 @@ test_gr_twofluid_waves_kerr_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1746,11 +2362,11 @@ test_gr_twofluid_waves_kerr_ho() } TEST_LIST = { - { "gr_twofluid_basic_minkowski_ho", test_gr_twofluid_basic_minkowski_ho }, - { "gr_twofluid_basic_schwarzschild_ho", test_gr_twofluid_basic_schwarzschild_ho }, - { "gr_twofluid_basic_kerr_ho", test_gr_twofluid_basic_kerr_ho }, - { "gr_twofluid_waves_minkowski_ho", test_gr_twofluid_waves_minkowski_ho }, - { "gr_twofluid_waves_schwarzschild_ho", test_gr_twofluid_waves_schwarzschild_ho }, - { "gr_twofluid_waves_kerr_ho", test_gr_twofluid_waves_kerr_ho }, - { NULL, NULL }, + {"gr_twofluid_basic_minkowski_ho", test_gr_twofluid_basic_minkowski_ho}, + {"gr_twofluid_basic_schwarzschild_ho", test_gr_twofluid_basic_schwarzschild_ho}, + {"gr_twofluid_basic_kerr_ho", test_gr_twofluid_basic_kerr_ho}, + {"gr_twofluid_waves_minkowski_ho", test_gr_twofluid_waves_minkowski_ho}, + {"gr_twofluid_waves_schwarzschild_ho", test_gr_twofluid_waves_schwarzschild_ho}, + {"gr_twofluid_waves_kerr_ho", test_gr_twofluid_waves_kerr_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_gr_twofluid_tetrad.c b/moments/unit/ctest_wv_gr_twofluid_tetrad.c index a40e4ef4bd..bee50c13ee 100644 --- a/moments/unit/ctest_wv_gr_twofluid_tetrad.c +++ b/moments/unit/ctest_wv_gr_twofluid_tetrad.c @@ -6,8 +6,7 @@ #include #include -void -test_gr_twofluid_tetrad_basic_minkowski_ho() +void test_gr_twofluid_tetrad_basic_minkowski_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -21,11 +20,13 @@ test_gr_twofluid_tetrad_basic_minkowski_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_twofluid_tetrad->num_equations == 84 ); - TEST_CHECK( gr_twofluid_tetrad->num_waves == 6 ); + TEST_CHECK(gr_twofluid_tetrad->num_equations == 84); + TEST_CHECK(gr_twofluid_tetrad->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -39,25 +40,25 @@ test_gr_twofluid_tetrad_basic_minkowski_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -68,16 +69,28 @@ test_gr_twofluid_tetrad_basic_minkowski_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -107,57 +120,104 @@ test_gr_twofluid_tetrad_basic_minkowski_ho() q[8] = sqrt(spatial_det) * rho_ion * hi * (W * W) * w; q[9] = sqrt(spatial_det) * ((rho_ion * hi * (W * W)) - p - (rho_ion * W)); - q[10] = Dx; q[11] = Dy; q[12] = Dz; - q[13] = Bx; q[14] = By; q[15] = Bz; - q[16] = phi; q[17] = psi; + q[10] = Dx; + q[11] = Dy; + q[12] = Dz; + q[13] = Bx; + q[14] = By; + q[15] = Bz; + q[16] = phi; + q[17] = psi; q[18] = lapse; - q[19] = shift[0]; q[20] = shift[1]; q[21] = shift[2]; - - q[22] = spatial_metric[0][0]; q[23] = spatial_metric[0][1]; q[24] = spatial_metric[0][2]; - q[25] = spatial_metric[1][0]; q[26] = spatial_metric[1][1]; q[27] = spatial_metric[1][2]; - q[28] = spatial_metric[2][0]; q[29] = spatial_metric[2][1]; q[30] = spatial_metric[2][2]; - - q[31] = extrinsic_curvature[0][0]; q[32] = extrinsic_curvature[0][1]; q[33] = extrinsic_curvature[0][2]; - q[34] = extrinsic_curvature[1][0]; q[35] = extrinsic_curvature[1][1]; q[36] = extrinsic_curvature[1][2]; - q[37] = extrinsic_curvature[2][0]; q[38] = extrinsic_curvature[2][1]; q[39] = extrinsic_curvature[2][2]; + q[19] = shift[0]; + q[20] = shift[1]; + q[21] = shift[2]; + + q[22] = spatial_metric[0][0]; + q[23] = spatial_metric[0][1]; + q[24] = spatial_metric[0][2]; + q[25] = spatial_metric[1][0]; + q[26] = spatial_metric[1][1]; + q[27] = spatial_metric[1][2]; + q[28] = spatial_metric[2][0]; + q[29] = spatial_metric[2][1]; + q[30] = spatial_metric[2][2]; + + q[31] = extrinsic_curvature[0][0]; + q[32] = extrinsic_curvature[0][1]; + q[33] = extrinsic_curvature[0][2]; + q[34] = extrinsic_curvature[1][0]; + q[35] = extrinsic_curvature[1][1]; + q[36] = extrinsic_curvature[1][2]; + q[37] = extrinsic_curvature[2][0]; + q[38] = extrinsic_curvature[2][1]; + q[39] = extrinsic_curvature[2][2]; q[40] = 1.0; - q[41] = lapse_der[0]; q[42] = lapse_der[1]; q[43] = lapse_der[2]; - q[44] = shift_der[0][0]; q[45] = shift_der[0][1]; q[46] = shift_der[0][2]; - q[47] = shift_der[1][0]; q[48] = shift_der[1][1]; q[49] = shift_der[1][2]; - q[50] = shift_der[2][0]; q[51] = shift_der[2][1]; q[52] = shift_der[2][2]; - - q[53] = spatial_metric_der[0][0][0]; q[54] = spatial_metric_der[0][0][1]; q[55] = spatial_metric_der[0][0][2]; - q[56] = spatial_metric_der[0][1][0]; q[57] = spatial_metric_der[0][1][1]; q[58] = spatial_metric_der[0][1][2]; - q[59] = spatial_metric_der[0][2][0]; q[60] = spatial_metric_der[0][2][1]; q[61] = spatial_metric_der[0][2][2]; - - q[62] = spatial_metric_der[1][0][0]; q[63] = spatial_metric_der[1][0][1]; q[64] = spatial_metric_der[1][0][2]; - q[65] = spatial_metric_der[1][1][0]; q[66] = spatial_metric_der[1][1][1]; q[67] = spatial_metric_der[1][1][2]; - q[68] = spatial_metric_der[1][2][0]; q[69] = spatial_metric_der[1][2][1]; q[70] = spatial_metric_der[1][2][2]; - - q[71] = spatial_metric_der[2][0][0]; q[72] = spatial_metric_der[2][0][1]; q[73] = spatial_metric_der[2][0][2]; - q[74] = spatial_metric_der[2][1][0]; q[75] = spatial_metric_der[2][1][1]; q[76] = spatial_metric_der[2][1][2]; - q[77] = spatial_metric_der[2][2][0]; q[78] = spatial_metric_der[2][2][1]; q[79] = spatial_metric_der[2][2][2]; + q[41] = lapse_der[0]; + q[42] = lapse_der[1]; + q[43] = lapse_der[2]; + q[44] = shift_der[0][0]; + q[45] = shift_der[0][1]; + q[46] = shift_der[0][2]; + q[47] = shift_der[1][0]; + q[48] = shift_der[1][1]; + q[49] = shift_der[1][2]; + q[50] = shift_der[2][0]; + q[51] = shift_der[2][1]; + q[52] = shift_der[2][2]; + + q[53] = spatial_metric_der[0][0][0]; + q[54] = spatial_metric_der[0][0][1]; + q[55] = spatial_metric_der[0][0][2]; + q[56] = spatial_metric_der[0][1][0]; + q[57] = spatial_metric_der[0][1][1]; + q[58] = spatial_metric_der[0][1][2]; + q[59] = spatial_metric_der[0][2][0]; + q[60] = spatial_metric_der[0][2][1]; + q[61] = spatial_metric_der[0][2][2]; + + q[62] = spatial_metric_der[1][0][0]; + q[63] = spatial_metric_der[1][0][1]; + q[64] = spatial_metric_der[1][0][2]; + q[65] = spatial_metric_der[1][1][0]; + q[66] = spatial_metric_der[1][1][1]; + q[67] = spatial_metric_der[1][1][2]; + q[68] = spatial_metric_der[1][2][0]; + q[69] = spatial_metric_der[1][2][1]; + q[70] = spatial_metric_der[1][2][2]; + + q[71] = spatial_metric_der[2][0][0]; + q[72] = spatial_metric_der[2][0][1]; + q[73] = spatial_metric_der[2][0][2]; + q[74] = spatial_metric_der[2][1][0]; + q[75] = spatial_metric_der[2][1][1]; + q[76] = spatial_metric_der[2][1][2]; + q[77] = spatial_metric_der[2][2][0]; + q[78] = spatial_metric_der[2][2][1]; + q[79] = spatial_metric_der[2][2][2]; q[80] = 0.0; - q[81] = x; q[82] = y; q[83] = 0.0; + q[81] = x; + q[82] = y; + q[83] = 0.0; double prims[84]; gkyl_gr_twofluid_tetrad_prim_vars(gas_gamma_elc, gas_gamma_ion, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho_elc, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-12) ); - - TEST_CHECK( gkyl_compare(prims[5], rho_ion, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[6], u, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[7], v, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[8], w, 1e-12) ); - TEST_CHECK( gkyl_compare(prims[9], p, 1e-12) ); + + TEST_CHECK(gkyl_compare(prims[0], rho_elc, 1e-12)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-12)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-12)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-12)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-12)); + + TEST_CHECK(gkyl_compare(prims[5], rho_ion, 1e-12)); + TEST_CHECK(gkyl_compare(prims[6], u, 1e-12)); + TEST_CHECK(gkyl_compare(prims[7], v, 1e-12)); + TEST_CHECK(gkyl_compare(prims[8], w, 1e-12)); + TEST_CHECK(gkyl_compare(prims[9], p, 1e-12)); double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -168,71 +228,101 @@ test_gr_twofluid_tetrad_basic_minkowski_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][18] = { - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[84], flux_local_sr[84], flux_local_gr[84], flux[84]; for (int d = 0; d < 3; d++) { - gr_twofluid_tetrad->rotate_to_local_func(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr); - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr, flux_local_gr); - gr_twofluid_tetrad->rotate_to_global_func(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gr_twofluid_tetrad->rotate_to_local_func( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); + gkyl_gr_twofluid_tetrad_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr + ); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr, + flux_local_gr + ); + gr_twofluid_tetrad->rotate_to_global_func( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 18; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-8) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-8)); } } @@ -242,7 +332,7 @@ test_gr_twofluid_tetrad_basic_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[84], q1[84]; @@ -250,7 +340,7 @@ test_gr_twofluid_tetrad_basic_minkowski_ho() gr_twofluid_tetrad->riem_to_cons(gr_twofluid_tetrad, q_local, w1, q1); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } @@ -258,7 +348,7 @@ test_gr_twofluid_tetrad_basic_minkowski_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -278,8 +368,7 @@ test_gr_twofluid_tetrad_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_twofluid_tetrad_basic_schwarzschild_ho() +void test_gr_twofluid_tetrad_basic_schwarzschild_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -293,11 +382,13 @@ test_gr_twofluid_tetrad_basic_schwarzschild_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_twofluid_tetrad->num_equations == 84 ); - TEST_CHECK( gr_twofluid_tetrad->num_waves == 6 ); + TEST_CHECK(gr_twofluid_tetrad->num_equations == 84); + TEST_CHECK(gr_twofluid_tetrad->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -311,25 +402,25 @@ test_gr_twofluid_tetrad_basic_schwarzschild_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -340,16 +431,28 @@ test_gr_twofluid_tetrad_basic_schwarzschild_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -380,57 +483,104 @@ test_gr_twofluid_tetrad_basic_schwarzschild_ho() q[8] = sqrt(spatial_det) * rho_ion * hi * (W * W) * w; q[9] = sqrt(spatial_det) * ((rho_ion * hi * (W * W)) - p - (rho_ion * W)); - q[10] = Dx; q[11] = Dy; q[12] = Dz; - q[13] = Bx; q[14] = By; q[15] = Bz; - q[16] = phi; q[17] = psi; + q[10] = Dx; + q[11] = Dy; + q[12] = Dz; + q[13] = Bx; + q[14] = By; + q[15] = Bz; + q[16] = phi; + q[17] = psi; q[18] = lapse; - q[19] = shift[0]; q[20] = shift[1]; q[21] = shift[2]; - - q[22] = spatial_metric[0][0]; q[23] = spatial_metric[0][1]; q[24] = spatial_metric[0][2]; - q[25] = spatial_metric[1][0]; q[26] = spatial_metric[1][1]; q[27] = spatial_metric[1][2]; - q[28] = spatial_metric[2][0]; q[29] = spatial_metric[2][1]; q[30] = spatial_metric[2][2]; - - q[31] = extrinsic_curvature[0][0]; q[32] = extrinsic_curvature[0][1]; q[33] = extrinsic_curvature[0][2]; - q[34] = extrinsic_curvature[1][0]; q[35] = extrinsic_curvature[1][1]; q[36] = extrinsic_curvature[1][2]; - q[37] = extrinsic_curvature[2][0]; q[38] = extrinsic_curvature[2][1]; q[39] = extrinsic_curvature[2][2]; + q[19] = shift[0]; + q[20] = shift[1]; + q[21] = shift[2]; + + q[22] = spatial_metric[0][0]; + q[23] = spatial_metric[0][1]; + q[24] = spatial_metric[0][2]; + q[25] = spatial_metric[1][0]; + q[26] = spatial_metric[1][1]; + q[27] = spatial_metric[1][2]; + q[28] = spatial_metric[2][0]; + q[29] = spatial_metric[2][1]; + q[30] = spatial_metric[2][2]; + + q[31] = extrinsic_curvature[0][0]; + q[32] = extrinsic_curvature[0][1]; + q[33] = extrinsic_curvature[0][2]; + q[34] = extrinsic_curvature[1][0]; + q[35] = extrinsic_curvature[1][1]; + q[36] = extrinsic_curvature[1][2]; + q[37] = extrinsic_curvature[2][0]; + q[38] = extrinsic_curvature[2][1]; + q[39] = extrinsic_curvature[2][2]; q[40] = 1.0; - q[41] = lapse_der[0]; q[42] = lapse_der[1]; q[43] = lapse_der[2]; - q[44] = shift_der[0][0]; q[45] = shift_der[0][1]; q[46] = shift_der[0][2]; - q[47] = shift_der[1][0]; q[48] = shift_der[1][1]; q[49] = shift_der[1][2]; - q[50] = shift_der[2][0]; q[51] = shift_der[2][1]; q[52] = shift_der[2][2]; - - q[53] = spatial_metric_der[0][0][0]; q[54] = spatial_metric_der[0][0][1]; q[55] = spatial_metric_der[0][0][2]; - q[56] = spatial_metric_der[0][1][0]; q[57] = spatial_metric_der[0][1][1]; q[58] = spatial_metric_der[0][1][2]; - q[59] = spatial_metric_der[0][2][0]; q[60] = spatial_metric_der[0][2][1]; q[61] = spatial_metric_der[0][2][2]; - - q[62] = spatial_metric_der[1][0][0]; q[63] = spatial_metric_der[1][0][1]; q[64] = spatial_metric_der[1][0][2]; - q[65] = spatial_metric_der[1][1][0]; q[66] = spatial_metric_der[1][1][1]; q[67] = spatial_metric_der[1][1][2]; - q[68] = spatial_metric_der[1][2][0]; q[69] = spatial_metric_der[1][2][1]; q[70] = spatial_metric_der[1][2][2]; - - q[71] = spatial_metric_der[2][0][0]; q[72] = spatial_metric_der[2][0][1]; q[73] = spatial_metric_der[2][0][2]; - q[74] = spatial_metric_der[2][1][0]; q[75] = spatial_metric_der[2][1][1]; q[76] = spatial_metric_der[2][1][2]; - q[77] = spatial_metric_der[2][2][0]; q[78] = spatial_metric_der[2][2][1]; q[79] = spatial_metric_der[2][2][2]; + q[41] = lapse_der[0]; + q[42] = lapse_der[1]; + q[43] = lapse_der[2]; + q[44] = shift_der[0][0]; + q[45] = shift_der[0][1]; + q[46] = shift_der[0][2]; + q[47] = shift_der[1][0]; + q[48] = shift_der[1][1]; + q[49] = shift_der[1][2]; + q[50] = shift_der[2][0]; + q[51] = shift_der[2][1]; + q[52] = shift_der[2][2]; + + q[53] = spatial_metric_der[0][0][0]; + q[54] = spatial_metric_der[0][0][1]; + q[55] = spatial_metric_der[0][0][2]; + q[56] = spatial_metric_der[0][1][0]; + q[57] = spatial_metric_der[0][1][1]; + q[58] = spatial_metric_der[0][1][2]; + q[59] = spatial_metric_der[0][2][0]; + q[60] = spatial_metric_der[0][2][1]; + q[61] = spatial_metric_der[0][2][2]; + + q[62] = spatial_metric_der[1][0][0]; + q[63] = spatial_metric_der[1][0][1]; + q[64] = spatial_metric_der[1][0][2]; + q[65] = spatial_metric_der[1][1][0]; + q[66] = spatial_metric_der[1][1][1]; + q[67] = spatial_metric_der[1][1][2]; + q[68] = spatial_metric_der[1][2][0]; + q[69] = spatial_metric_der[1][2][1]; + q[70] = spatial_metric_der[1][2][2]; + + q[71] = spatial_metric_der[2][0][0]; + q[72] = spatial_metric_der[2][0][1]; + q[73] = spatial_metric_der[2][0][2]; + q[74] = spatial_metric_der[2][1][0]; + q[75] = spatial_metric_der[2][1][1]; + q[76] = spatial_metric_der[2][1][2]; + q[77] = spatial_metric_der[2][2][0]; + q[78] = spatial_metric_der[2][2][1]; + q[79] = spatial_metric_der[2][2][2]; q[80] = 0.0; - q[81] = x; q[82] = y; q[83] = 0.0; + q[81] = x; + q[82] = y; + q[83] = 0.0; double prims[84]; gkyl_gr_twofluid_tetrad_prim_vars(gas_gamma_elc, gas_gamma_ion, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho_elc, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); - - TEST_CHECK( gkyl_compare(prims[5], rho_ion, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[6], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[7], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[8], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[9], p, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho_elc, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], rho_ion, 1e-1)); + TEST_CHECK(gkyl_compare(prims[6], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[7], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[8], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[9], p, 1e-1)); double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -441,71 +591,101 @@ test_gr_twofluid_tetrad_basic_schwarzschild_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][18] = { - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; - double q_local[84], flux_local_sr[84], flux_local_gr[84], flux[84]; - for (int d = 0; d < 3; d++) { - gr_twofluid_tetrad->rotate_to_local_func(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr); - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr, flux_local_gr); - gr_twofluid_tetrad->rotate_to_global_func(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + double q_local[84], flux_local_sr[84], flux_local_gr[84], flux[84]; + for (int d = 0; d < 3; d++) { + gr_twofluid_tetrad->rotate_to_local_func( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); + gkyl_gr_twofluid_tetrad_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr + ); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr, + flux_local_gr + ); + gr_twofluid_tetrad->rotate_to_global_func( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 18; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } @@ -515,7 +695,7 @@ test_gr_twofluid_tetrad_basic_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[84], q1[84]; @@ -523,7 +703,7 @@ test_gr_twofluid_tetrad_basic_schwarzschild_ho() gr_twofluid_tetrad->riem_to_cons(gr_twofluid_tetrad, q_local, w1, q1); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -532,7 +712,7 @@ test_gr_twofluid_tetrad_basic_schwarzschild_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -552,8 +732,7 @@ test_gr_twofluid_tetrad_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_twofluid_tetrad_basic_kerr_ho() +void test_gr_twofluid_tetrad_basic_kerr_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -567,11 +746,13 @@ test_gr_twofluid_tetrad_basic_kerr_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); - TEST_CHECK( gr_twofluid_tetrad->num_equations == 84 ); - TEST_CHECK( gr_twofluid_tetrad->num_waves == 6 ); + TEST_CHECK(gr_twofluid_tetrad->num_equations == 84); + TEST_CHECK(gr_twofluid_tetrad->num_waves == 6); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -585,25 +766,25 @@ test_gr_twofluid_tetrad_basic_kerr_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -614,16 +795,28 @@ test_gr_twofluid_tetrad_basic_kerr_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -654,57 +847,104 @@ test_gr_twofluid_tetrad_basic_kerr_ho() q[8] = sqrt(spatial_det) * rho_ion * hi * (W * W) * w; q[9] = sqrt(spatial_det) * ((rho_ion * hi * (W * W)) - p - (rho_ion * W)); - q[10] = Dx; q[11] = Dy; q[12] = Dz; - q[13] = Bx; q[14] = By; q[15] = Bz; - q[16] = phi; q[17] = psi; + q[10] = Dx; + q[11] = Dy; + q[12] = Dz; + q[13] = Bx; + q[14] = By; + q[15] = Bz; + q[16] = phi; + q[17] = psi; q[18] = lapse; - q[19] = shift[0]; q[20] = shift[1]; q[21] = shift[2]; - - q[22] = spatial_metric[0][0]; q[23] = spatial_metric[0][1]; q[24] = spatial_metric[0][2]; - q[25] = spatial_metric[1][0]; q[26] = spatial_metric[1][1]; q[27] = spatial_metric[1][2]; - q[28] = spatial_metric[2][0]; q[29] = spatial_metric[2][1]; q[30] = spatial_metric[2][2]; - - q[31] = extrinsic_curvature[0][0]; q[32] = extrinsic_curvature[0][1]; q[33] = extrinsic_curvature[0][2]; - q[34] = extrinsic_curvature[1][0]; q[35] = extrinsic_curvature[1][1]; q[36] = extrinsic_curvature[1][2]; - q[37] = extrinsic_curvature[2][0]; q[38] = extrinsic_curvature[2][1]; q[39] = extrinsic_curvature[2][2]; + q[19] = shift[0]; + q[20] = shift[1]; + q[21] = shift[2]; + + q[22] = spatial_metric[0][0]; + q[23] = spatial_metric[0][1]; + q[24] = spatial_metric[0][2]; + q[25] = spatial_metric[1][0]; + q[26] = spatial_metric[1][1]; + q[27] = spatial_metric[1][2]; + q[28] = spatial_metric[2][0]; + q[29] = spatial_metric[2][1]; + q[30] = spatial_metric[2][2]; + + q[31] = extrinsic_curvature[0][0]; + q[32] = extrinsic_curvature[0][1]; + q[33] = extrinsic_curvature[0][2]; + q[34] = extrinsic_curvature[1][0]; + q[35] = extrinsic_curvature[1][1]; + q[36] = extrinsic_curvature[1][2]; + q[37] = extrinsic_curvature[2][0]; + q[38] = extrinsic_curvature[2][1]; + q[39] = extrinsic_curvature[2][2]; q[40] = 1.0; - q[41] = lapse_der[0]; q[42] = lapse_der[1]; q[43] = lapse_der[2]; - q[44] = shift_der[0][0]; q[45] = shift_der[0][1]; q[46] = shift_der[0][2]; - q[47] = shift_der[1][0]; q[48] = shift_der[1][1]; q[49] = shift_der[1][2]; - q[50] = shift_der[2][0]; q[51] = shift_der[2][1]; q[52] = shift_der[2][2]; - - q[53] = spatial_metric_der[0][0][0]; q[54] = spatial_metric_der[0][0][1]; q[55] = spatial_metric_der[0][0][2]; - q[56] = spatial_metric_der[0][1][0]; q[57] = spatial_metric_der[0][1][1]; q[58] = spatial_metric_der[0][1][2]; - q[59] = spatial_metric_der[0][2][0]; q[60] = spatial_metric_der[0][2][1]; q[61] = spatial_metric_der[0][2][2]; - - q[62] = spatial_metric_der[1][0][0]; q[63] = spatial_metric_der[1][0][1]; q[64] = spatial_metric_der[1][0][2]; - q[65] = spatial_metric_der[1][1][0]; q[66] = spatial_metric_der[1][1][1]; q[67] = spatial_metric_der[1][1][2]; - q[68] = spatial_metric_der[1][2][0]; q[69] = spatial_metric_der[1][2][1]; q[70] = spatial_metric_der[1][2][2]; - - q[71] = spatial_metric_der[2][0][0]; q[72] = spatial_metric_der[2][0][1]; q[73] = spatial_metric_der[2][0][2]; - q[74] = spatial_metric_der[2][1][0]; q[75] = spatial_metric_der[2][1][1]; q[76] = spatial_metric_der[2][1][2]; - q[77] = spatial_metric_der[2][2][0]; q[78] = spatial_metric_der[2][2][1]; q[79] = spatial_metric_der[2][2][2]; + q[41] = lapse_der[0]; + q[42] = lapse_der[1]; + q[43] = lapse_der[2]; + q[44] = shift_der[0][0]; + q[45] = shift_der[0][1]; + q[46] = shift_der[0][2]; + q[47] = shift_der[1][0]; + q[48] = shift_der[1][1]; + q[49] = shift_der[1][2]; + q[50] = shift_der[2][0]; + q[51] = shift_der[2][1]; + q[52] = shift_der[2][2]; + + q[53] = spatial_metric_der[0][0][0]; + q[54] = spatial_metric_der[0][0][1]; + q[55] = spatial_metric_der[0][0][2]; + q[56] = spatial_metric_der[0][1][0]; + q[57] = spatial_metric_der[0][1][1]; + q[58] = spatial_metric_der[0][1][2]; + q[59] = spatial_metric_der[0][2][0]; + q[60] = spatial_metric_der[0][2][1]; + q[61] = spatial_metric_der[0][2][2]; + + q[62] = spatial_metric_der[1][0][0]; + q[63] = spatial_metric_der[1][0][1]; + q[64] = spatial_metric_der[1][0][2]; + q[65] = spatial_metric_der[1][1][0]; + q[66] = spatial_metric_der[1][1][1]; + q[67] = spatial_metric_der[1][1][2]; + q[68] = spatial_metric_der[1][2][0]; + q[69] = spatial_metric_der[1][2][1]; + q[70] = spatial_metric_der[1][2][2]; + + q[71] = spatial_metric_der[2][0][0]; + q[72] = spatial_metric_der[2][0][1]; + q[73] = spatial_metric_der[2][0][2]; + q[74] = spatial_metric_der[2][1][0]; + q[75] = spatial_metric_der[2][1][1]; + q[76] = spatial_metric_der[2][1][2]; + q[77] = spatial_metric_der[2][2][0]; + q[78] = spatial_metric_der[2][2][1]; + q[79] = spatial_metric_der[2][2][2]; q[80] = 0.0; - q[81] = x; q[82] = y; q[83] = 0.0; + q[81] = x; + q[82] = y; + q[83] = 0.0; double prims[84]; gkyl_gr_twofluid_tetrad_prim_vars(gas_gamma_elc, gas_gamma_ion, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho_elc, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-1) ); - - TEST_CHECK( gkyl_compare(prims[5], rho_ion, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[6], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[7], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[8], w, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[9], p, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho_elc, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-1)); + + TEST_CHECK(gkyl_compare(prims[5], rho_ion, 1e-1)); + TEST_CHECK(gkyl_compare(prims[6], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[7], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[8], w, 1e-1)); + TEST_CHECK(gkyl_compare(prims[9], p, 1e-1)); double Ex = (lapse * Dx) + ((shift[1] * Bz) - (shift[2] * By)); double Ey = (lapse * Dy) - ((shift[0] * Bz) - (shift[2] * Bx)); @@ -715,71 +955,101 @@ test_gr_twofluid_tetrad_basic_kerr_ho() double Hz = (lapse * Bz) - ((shift[0] * Dy) - (shift[1] * Dx)); double fluxes[3][18] = { - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, -(light_speed * light_speed) * Hy, b_fact * psi, - -Ez, Ey, e_fact * Dx, b_fact * (light_speed * light_speed) * Bx }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hx, Ez, b_fact * psi, - -Ex, e_fact * Dy, b_fact * (light_speed * light_speed) * By }, - { (lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), - (lapse * sqrt(spatial_det)) * (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, - e_fact * Dz, b_fact * (light_speed * light_speed) * Bz }, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[0] - (shift[0] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[0] - (shift[0] / lapse)) + + (p * vel[0])), + e_fact * (light_speed * light_speed) * phi, (light_speed * light_speed) * Hz, + -(light_speed * light_speed) * Hy, b_fact * psi, -Ez, Ey, e_fact * Dx, + b_fact * (light_speed * light_speed) * Bx}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[1] - (shift[1] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[1] - (shift[1] / lapse)) + + (p * vel[1])), + -(light_speed * light_speed) * Hz, e_fact * (light_speed * light_speed) * phi, + (light_speed * light_speed) * Hx, Ez, b_fact * psi, -Ex, e_fact * Dy, + b_fact * (light_speed * light_speed) * By}, + {(lapse * sqrt(spatial_det)) * (rho_elc * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_elc * he * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_elc * he * (W * W)) - p - (rho_elc * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (lapse * sqrt(spatial_det)) * (rho_ion * W * (vel[2] - (shift[2] / lapse))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + (rho_ion * hi * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + (((rho_ion * hi * (W * W)) - p - (rho_ion * W)) * (vel[2] - (shift[2] / lapse)) + + (p * vel[2])), + (light_speed * light_speed) * Hy, -(light_speed * light_speed) * Hx, + e_fact * (light_speed * light_speed) * phi, -Ey, Ex, b_fact * psi, e_fact * Dz, + b_fact * (light_speed * light_speed) * Bz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; - double q_local[84], flux_local_sr[84], flux_local_gr[84], flux[84]; - for (int d = 0; d < 3; d++) { - gr_twofluid_tetrad->rotate_to_local_func(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr); - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr, flux_local_gr); - gr_twofluid_tetrad->rotate_to_global_func(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + double q_local[84], flux_local_sr[84], flux_local_gr[84], flux[84]; + for (int d = 0; d < 3; d++) { + gr_twofluid_tetrad->rotate_to_local_func( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); + gkyl_gr_twofluid_tetrad_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr + ); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, q_local, flux_local_sr, + flux_local_gr + ); + gr_twofluid_tetrad->rotate_to_global_func( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 18; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } @@ -789,15 +1059,15 @@ test_gr_twofluid_tetrad_basic_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } - + double w1[84], q1[84]; gr_twofluid_tetrad->cons_to_riem(gr_twofluid_tetrad, q_local, q_local, w1); gr_twofluid_tetrad->riem_to_cons(gr_twofluid_tetrad, q_local, w1, q1); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -806,7 +1076,7 @@ test_gr_twofluid_tetrad_basic_kerr_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -826,8 +1096,7 @@ test_gr_twofluid_tetrad_basic_kerr_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_twofluid_tetrad_waves_minkowski_ho() +void test_gr_twofluid_tetrad_waves_minkowski_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -841,8 +1110,10 @@ test_gr_twofluid_tetrad_waves_minkowski_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -868,10 +1139,10 @@ test_gr_twofluid_tetrad_waves_minkowski_ho() double *shift_l = gkyl_malloc(sizeof(double[3])); double *shift_r = gkyl_malloc(sizeof(double[3])); - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -881,18 +1152,18 @@ test_gr_twofluid_tetrad_waves_minkowski_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -909,20 +1180,46 @@ test_gr_twofluid_tetrad_waves_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -952,42 +1249,89 @@ test_gr_twofluid_tetrad_waves_minkowski_ho() ql[8] = sqrt(spatial_det_l) * rho_ion_l * hi_l * (W_l * W_l) * w_l; ql[9] = sqrt(spatial_det_l) * ((rho_ion_l * hi_l * (W_l * W_l)) - p_l - (rho_ion_l * W_l)); - ql[10] = Dx_l; ql[11] = Dy_l; ql[12] = Dz_l; - ql[13] = Bx_l; ql[14] = By_l; ql[15] = Bz_l; - ql[16] = phi_l; ql[17] = psi_l; + ql[10] = Dx_l; + ql[11] = Dy_l; + ql[12] = Dz_l; + ql[13] = Bx_l; + ql[14] = By_l; + ql[15] = Bz_l; + ql[16] = phi_l; + ql[17] = psi_l; ql[18] = lapse_l; - ql[19] = shift_l[0]; ql[20] = shift_l[1]; ql[21] = shift_l[2]; - - ql[22] = spatial_metric_l[0][0]; ql[23] = spatial_metric_l[0][1]; ql[24] = spatial_metric_l[0][2]; - ql[25] = spatial_metric_l[1][0]; ql[26] = spatial_metric_l[1][1]; ql[27] = spatial_metric_l[1][2]; - ql[28] = spatial_metric_l[2][0]; ql[29] = spatial_metric_l[2][1]; ql[30] = spatial_metric_l[2][2]; - - ql[31] = extrinsic_curvature_l[0][0]; ql[32] = extrinsic_curvature_l[0][1]; ql[33] = extrinsic_curvature_l[0][2]; - ql[34] = extrinsic_curvature_l[1][0]; ql[35] = extrinsic_curvature_l[1][1]; ql[36] = extrinsic_curvature_l[1][2]; - ql[37] = extrinsic_curvature_l[2][0]; ql[38] = extrinsic_curvature_l[2][1]; ql[39] = extrinsic_curvature_l[2][2]; + ql[19] = shift_l[0]; + ql[20] = shift_l[1]; + ql[21] = shift_l[2]; + + ql[22] = spatial_metric_l[0][0]; + ql[23] = spatial_metric_l[0][1]; + ql[24] = spatial_metric_l[0][2]; + ql[25] = spatial_metric_l[1][0]; + ql[26] = spatial_metric_l[1][1]; + ql[27] = spatial_metric_l[1][2]; + ql[28] = spatial_metric_l[2][0]; + ql[29] = spatial_metric_l[2][1]; + ql[30] = spatial_metric_l[2][2]; + + ql[31] = extrinsic_curvature_l[0][0]; + ql[32] = extrinsic_curvature_l[0][1]; + ql[33] = extrinsic_curvature_l[0][2]; + ql[34] = extrinsic_curvature_l[1][0]; + ql[35] = extrinsic_curvature_l[1][1]; + ql[36] = extrinsic_curvature_l[1][2]; + ql[37] = extrinsic_curvature_l[2][0]; + ql[38] = extrinsic_curvature_l[2][1]; + ql[39] = extrinsic_curvature_l[2][2]; ql[40] = 1.0; - ql[41] = lapse_der_l[0]; ql[42] = lapse_der_l[1]; ql[43] = lapse_der_l[2]; - ql[44] = shift_der_l[0][0]; ql[45] = shift_der_l[0][1]; ql[46] = shift_der_l[0][2]; - ql[47] = shift_der_l[1][0]; ql[48] = shift_der_l[1][1]; ql[49] = shift_der_l[1][2]; - ql[50] = shift_der_l[2][0]; ql[51] = shift_der_l[2][1]; ql[52] = shift_der_l[2][2]; - - ql[53] = spatial_metric_der_l[0][0][0]; ql[54] = spatial_metric_der_l[0][0][1]; ql[55] = spatial_metric_der_l[0][0][2]; - ql[56] = spatial_metric_der_l[0][1][0]; ql[57] = spatial_metric_der_l[0][1][1]; ql[58] = spatial_metric_der_l[0][1][2]; - ql[59] = spatial_metric_der_l[0][2][0]; ql[60] = spatial_metric_der_l[0][2][1]; ql[61] = spatial_metric_der_l[0][2][2]; - - ql[62] = spatial_metric_der_l[1][0][0]; ql[63] = spatial_metric_der_l[1][0][1]; ql[64] = spatial_metric_der_l[1][0][2]; - ql[65] = spatial_metric_der_l[1][1][0]; ql[66] = spatial_metric_der_l[1][1][1]; ql[67] = spatial_metric_der_l[1][1][2]; - ql[68] = spatial_metric_der_l[1][2][0]; ql[69] = spatial_metric_der_l[1][2][1]; ql[70] = spatial_metric_der_l[1][2][2]; - - ql[71] = spatial_metric_der_l[2][0][0]; ql[72] = spatial_metric_der_l[2][0][1]; ql[73] = spatial_metric_der_l[2][0][2]; - ql[74] = spatial_metric_der_l[2][1][0]; ql[75] = spatial_metric_der_l[2][1][1]; ql[76] = spatial_metric_der_l[2][1][2]; - ql[77] = spatial_metric_der_l[2][2][0]; ql[78] = spatial_metric_der_l[2][2][1]; ql[79] = spatial_metric_der_l[2][2][2]; + ql[41] = lapse_der_l[0]; + ql[42] = lapse_der_l[1]; + ql[43] = lapse_der_l[2]; + ql[44] = shift_der_l[0][0]; + ql[45] = shift_der_l[0][1]; + ql[46] = shift_der_l[0][2]; + ql[47] = shift_der_l[1][0]; + ql[48] = shift_der_l[1][1]; + ql[49] = shift_der_l[1][2]; + ql[50] = shift_der_l[2][0]; + ql[51] = shift_der_l[2][1]; + ql[52] = shift_der_l[2][2]; + + ql[53] = spatial_metric_der_l[0][0][0]; + ql[54] = spatial_metric_der_l[0][0][1]; + ql[55] = spatial_metric_der_l[0][0][2]; + ql[56] = spatial_metric_der_l[0][1][0]; + ql[57] = spatial_metric_der_l[0][1][1]; + ql[58] = spatial_metric_der_l[0][1][2]; + ql[59] = spatial_metric_der_l[0][2][0]; + ql[60] = spatial_metric_der_l[0][2][1]; + ql[61] = spatial_metric_der_l[0][2][2]; + + ql[62] = spatial_metric_der_l[1][0][0]; + ql[63] = spatial_metric_der_l[1][0][1]; + ql[64] = spatial_metric_der_l[1][0][2]; + ql[65] = spatial_metric_der_l[1][1][0]; + ql[66] = spatial_metric_der_l[1][1][1]; + ql[67] = spatial_metric_der_l[1][1][2]; + ql[68] = spatial_metric_der_l[1][2][0]; + ql[69] = spatial_metric_der_l[1][2][1]; + ql[70] = spatial_metric_der_l[1][2][2]; + + ql[71] = spatial_metric_der_l[2][0][0]; + ql[72] = spatial_metric_der_l[2][0][1]; + ql[73] = spatial_metric_der_l[2][0][2]; + ql[74] = spatial_metric_der_l[2][1][0]; + ql[75] = spatial_metric_der_l[2][1][1]; + ql[76] = spatial_metric_der_l[2][1][2]; + ql[77] = spatial_metric_der_l[2][2][0]; + ql[78] = spatial_metric_der_l[2][2][1]; + ql[79] = spatial_metric_der_l[2][2][2]; ql[80] = 0.0; - ql[81] = x - 0.5; ql[82] = y; ql[83] = 0.0; + ql[81] = x - 0.5; + ql[82] = y; + ql[83] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_elc_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_elc_r * he_r * (W_r * W_r) * u_r; @@ -1001,60 +1345,95 @@ test_gr_twofluid_tetrad_waves_minkowski_ho() qr[8] = sqrt(spatial_det_r) * rho_ion_r * hi_r * (W_r * W_r) * w_r; qr[9] = sqrt(spatial_det_r) * ((rho_ion_r * hi_r * (W_r * W_r)) - p_r - (rho_ion_r * W_r)); - qr[10] = Dx_r; qr[11] = Dy_r; qr[12] = Dz_r; - qr[13] = Bx_r; qr[14] = By_r; qr[15] = Bz_r; - qr[16] = phi_r; qr[17] = psi_r; + qr[10] = Dx_r; + qr[11] = Dy_r; + qr[12] = Dz_r; + qr[13] = Bx_r; + qr[14] = By_r; + qr[15] = Bz_r; + qr[16] = phi_r; + qr[17] = psi_r; qr[18] = lapse_r; - qr[19] = shift_r[0]; qr[20] = shift_r[1]; qr[21] = shift_r[2]; - - qr[22] = spatial_metric_r[0][0]; qr[23] = spatial_metric_r[0][1]; qr[24] = spatial_metric_r[0][2]; - qr[25] = spatial_metric_r[1][0]; qr[26] = spatial_metric_r[1][1]; qr[27] = spatial_metric_r[1][2]; - qr[28] = spatial_metric_r[2][0]; qr[29] = spatial_metric_r[2][1]; qr[30] = spatial_metric_r[2][2]; - - qr[31] = extrinsic_curvature_r[0][0]; qr[32] = extrinsic_curvature_r[0][1]; qr[33] = extrinsic_curvature_r[0][2]; - qr[34] = extrinsic_curvature_r[1][0]; qr[35] = extrinsic_curvature_r[1][1]; qr[36] = extrinsic_curvature_r[1][2]; - qr[37] = extrinsic_curvature_r[2][0]; qr[38] = extrinsic_curvature_r[2][1]; qr[39] = extrinsic_curvature_r[2][2]; + qr[19] = shift_r[0]; + qr[20] = shift_r[1]; + qr[21] = shift_r[2]; + + qr[22] = spatial_metric_r[0][0]; + qr[23] = spatial_metric_r[0][1]; + qr[24] = spatial_metric_r[0][2]; + qr[25] = spatial_metric_r[1][0]; + qr[26] = spatial_metric_r[1][1]; + qr[27] = spatial_metric_r[1][2]; + qr[28] = spatial_metric_r[2][0]; + qr[29] = spatial_metric_r[2][1]; + qr[30] = spatial_metric_r[2][2]; + + qr[31] = extrinsic_curvature_r[0][0]; + qr[32] = extrinsic_curvature_r[0][1]; + qr[33] = extrinsic_curvature_r[0][2]; + qr[34] = extrinsic_curvature_r[1][0]; + qr[35] = extrinsic_curvature_r[1][1]; + qr[36] = extrinsic_curvature_r[1][2]; + qr[37] = extrinsic_curvature_r[2][0]; + qr[38] = extrinsic_curvature_r[2][1]; + qr[39] = extrinsic_curvature_r[2][2]; qr[40] = 1.0; - qr[41] = lapse_der_r[0]; qr[42] = lapse_der_r[1]; qr[43] = lapse_der_r[2]; - qr[44] = shift_der_r[0][0]; qr[45] = shift_der_r[0][1]; qr[46] = shift_der_r[0][2]; - qr[47] = shift_der_r[1][0]; qr[48] = shift_der_r[1][1]; qr[49] = shift_der_r[1][2]; - qr[50] = shift_der_r[2][0]; qr[51] = shift_der_r[2][1]; qr[52] = shift_der_r[2][2]; - - qr[53] = spatial_metric_der_r[0][0][0]; qr[54] = spatial_metric_der_r[0][0][1]; qr[55] = spatial_metric_der_r[0][0][2]; - qr[56] = spatial_metric_der_r[0][1][0]; qr[57] = spatial_metric_der_r[0][1][1]; qr[58] = spatial_metric_der_r[0][1][2]; - qr[59] = spatial_metric_der_r[0][2][0]; qr[60] = spatial_metric_der_r[0][2][1]; qr[61] = spatial_metric_der_r[0][2][2]; - - qr[62] = spatial_metric_der_r[1][0][0]; qr[63] = spatial_metric_der_r[1][0][1]; qr[64] = spatial_metric_der_r[1][0][2]; - qr[65] = spatial_metric_der_r[1][1][0]; qr[66] = spatial_metric_der_r[1][1][1]; qr[67] = spatial_metric_der_r[1][1][2]; - qr[68] = spatial_metric_der_r[1][2][0]; qr[69] = spatial_metric_der_r[1][2][1]; qr[70] = spatial_metric_der_r[1][2][2]; - - qr[71] = spatial_metric_der_r[2][0][0]; qr[72] = spatial_metric_der_r[2][0][1]; qr[73] = spatial_metric_der_r[2][0][2]; - qr[74] = spatial_metric_der_r[2][1][0]; qr[75] = spatial_metric_der_r[2][1][1]; qr[76] = spatial_metric_der_r[2][1][2]; - qr[77] = spatial_metric_der_r[2][2][0]; qr[78] = spatial_metric_der_r[2][2][1]; qr[79] = spatial_metric_der_r[2][2][2]; + qr[41] = lapse_der_r[0]; + qr[42] = lapse_der_r[1]; + qr[43] = lapse_der_r[2]; + qr[44] = shift_der_r[0][0]; + qr[45] = shift_der_r[0][1]; + qr[46] = shift_der_r[0][2]; + qr[47] = shift_der_r[1][0]; + qr[48] = shift_der_r[1][1]; + qr[49] = shift_der_r[1][2]; + qr[50] = shift_der_r[2][0]; + qr[51] = shift_der_r[2][1]; + qr[52] = shift_der_r[2][2]; + + qr[53] = spatial_metric_der_r[0][0][0]; + qr[54] = spatial_metric_der_r[0][0][1]; + qr[55] = spatial_metric_der_r[0][0][2]; + qr[56] = spatial_metric_der_r[0][1][0]; + qr[57] = spatial_metric_der_r[0][1][1]; + qr[58] = spatial_metric_der_r[0][1][2]; + qr[59] = spatial_metric_der_r[0][2][0]; + qr[60] = spatial_metric_der_r[0][2][1]; + qr[61] = spatial_metric_der_r[0][2][2]; + + qr[62] = spatial_metric_der_r[1][0][0]; + qr[63] = spatial_metric_der_r[1][0][1]; + qr[64] = spatial_metric_der_r[1][0][2]; + qr[65] = spatial_metric_der_r[1][1][0]; + qr[66] = spatial_metric_der_r[1][1][1]; + qr[67] = spatial_metric_der_r[1][1][2]; + qr[68] = spatial_metric_der_r[1][2][0]; + qr[69] = spatial_metric_der_r[1][2][1]; + qr[70] = spatial_metric_der_r[1][2][2]; + + qr[71] = spatial_metric_der_r[2][0][0]; + qr[72] = spatial_metric_der_r[2][0][1]; + qr[73] = spatial_metric_der_r[2][0][2]; + qr[74] = spatial_metric_der_r[2][1][0]; + qr[75] = spatial_metric_der_r[2][1][1]; + qr[76] = spatial_metric_der_r[2][1][2]; + qr[77] = spatial_metric_der_r[2][2][0]; + qr[78] = spatial_metric_der_r[2][2][1]; + qr[79] = spatial_metric_der_r[2][2][2]; qr[80] = 0.0; - qr[81] = x + 0.5; qr[82] = y; qr[83] = 0.0; + qr[81] = x + 0.5; + qr[82] = y; + qr[83] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 84], waves_local[3 * 84]; @@ -1068,33 +1447,55 @@ test_gr_twofluid_tetrad_waves_minkowski_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[84], amdq_local[84]; - gkyl_wv_eqn_qfluct(gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84]); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84] + ); } double apdq[84], amdq[84]; - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); double fl_local_sr[84], fr_local_sr[84]; - gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr); - gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr); + gkyl_gr_twofluid_tetrad_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr + ); + gkyl_gr_twofluid_tetrad_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr + ); double fl_local_gr[84], fr_local_gr[84]; - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr, fr_local_gr); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr, + fl_local_gr + ); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr, + fr_local_gr + ); double fl[84], fr[84]; gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } @@ -1105,7 +1506,7 @@ test_gr_twofluid_tetrad_waves_minkowski_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1134,8 +1535,7 @@ test_gr_twofluid_tetrad_waves_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_twofluid_tetrad_waves_schwarzschild_ho() +void test_gr_twofluid_tetrad_waves_schwarzschild_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -1149,8 +1549,10 @@ test_gr_twofluid_tetrad_waves_schwarzschild_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1177,10 +1579,10 @@ test_gr_twofluid_tetrad_waves_schwarzschild_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1190,18 +1592,18 @@ test_gr_twofluid_tetrad_waves_schwarzschild_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1220,20 +1622,46 @@ test_gr_twofluid_tetrad_waves_schwarzschild_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1264,42 +1692,89 @@ test_gr_twofluid_tetrad_waves_schwarzschild_ho() ql[8] = sqrt(spatial_det_l) * rho_ion_l * hi_l * (W_l * W_l) * w_l; ql[9] = sqrt(spatial_det_l) * ((rho_ion_l * hi_l * (W_l * W_l)) - p_l - (rho_ion_l * W_l)); - ql[10] = Dx_l; ql[11] = Dy_l; ql[12] = Dz_l; - ql[13] = Bx_l; ql[14] = By_l; ql[15] = Bz_l; - ql[16] = phi_l; ql[17] = psi_l; + ql[10] = Dx_l; + ql[11] = Dy_l; + ql[12] = Dz_l; + ql[13] = Bx_l; + ql[14] = By_l; + ql[15] = Bz_l; + ql[16] = phi_l; + ql[17] = psi_l; ql[18] = lapse_l; - ql[19] = shift_l[0]; ql[20] = shift_l[1]; ql[21] = shift_l[2]; - - ql[22] = spatial_metric_l[0][0]; ql[23] = spatial_metric_l[0][1]; ql[24] = spatial_metric_l[0][2]; - ql[25] = spatial_metric_l[1][0]; ql[26] = spatial_metric_l[1][1]; ql[27] = spatial_metric_l[1][2]; - ql[28] = spatial_metric_l[2][0]; ql[29] = spatial_metric_l[2][1]; ql[30] = spatial_metric_l[2][2]; - - ql[31] = extrinsic_curvature_l[0][0]; ql[32] = extrinsic_curvature_l[0][1]; ql[33] = extrinsic_curvature_l[0][2]; - ql[34] = extrinsic_curvature_l[1][0]; ql[35] = extrinsic_curvature_l[1][1]; ql[36] = extrinsic_curvature_l[1][2]; - ql[37] = extrinsic_curvature_l[2][0]; ql[38] = extrinsic_curvature_l[2][1]; ql[39] = extrinsic_curvature_l[2][2]; + ql[19] = shift_l[0]; + ql[20] = shift_l[1]; + ql[21] = shift_l[2]; + + ql[22] = spatial_metric_l[0][0]; + ql[23] = spatial_metric_l[0][1]; + ql[24] = spatial_metric_l[0][2]; + ql[25] = spatial_metric_l[1][0]; + ql[26] = spatial_metric_l[1][1]; + ql[27] = spatial_metric_l[1][2]; + ql[28] = spatial_metric_l[2][0]; + ql[29] = spatial_metric_l[2][1]; + ql[30] = spatial_metric_l[2][2]; + + ql[31] = extrinsic_curvature_l[0][0]; + ql[32] = extrinsic_curvature_l[0][1]; + ql[33] = extrinsic_curvature_l[0][2]; + ql[34] = extrinsic_curvature_l[1][0]; + ql[35] = extrinsic_curvature_l[1][1]; + ql[36] = extrinsic_curvature_l[1][2]; + ql[37] = extrinsic_curvature_l[2][0]; + ql[38] = extrinsic_curvature_l[2][1]; + ql[39] = extrinsic_curvature_l[2][2]; ql[40] = 1.0; - ql[41] = lapse_der_l[0]; ql[42] = lapse_der_l[1]; ql[43] = lapse_der_l[2]; - ql[44] = shift_der_l[0][0]; ql[45] = shift_der_l[0][1]; ql[46] = shift_der_l[0][2]; - ql[47] = shift_der_l[1][0]; ql[48] = shift_der_l[1][1]; ql[49] = shift_der_l[1][2]; - ql[50] = shift_der_l[2][0]; ql[51] = shift_der_l[2][1]; ql[52] = shift_der_l[2][2]; - - ql[53] = spatial_metric_der_l[0][0][0]; ql[54] = spatial_metric_der_l[0][0][1]; ql[55] = spatial_metric_der_l[0][0][2]; - ql[56] = spatial_metric_der_l[0][1][0]; ql[57] = spatial_metric_der_l[0][1][1]; ql[58] = spatial_metric_der_l[0][1][2]; - ql[59] = spatial_metric_der_l[0][2][0]; ql[60] = spatial_metric_der_l[0][2][1]; ql[61] = spatial_metric_der_l[0][2][2]; - - ql[62] = spatial_metric_der_l[1][0][0]; ql[63] = spatial_metric_der_l[1][0][1]; ql[64] = spatial_metric_der_l[1][0][2]; - ql[65] = spatial_metric_der_l[1][1][0]; ql[66] = spatial_metric_der_l[1][1][1]; ql[67] = spatial_metric_der_l[1][1][2]; - ql[68] = spatial_metric_der_l[1][2][0]; ql[69] = spatial_metric_der_l[1][2][1]; ql[70] = spatial_metric_der_l[1][2][2]; - - ql[71] = spatial_metric_der_l[2][0][0]; ql[72] = spatial_metric_der_l[2][0][1]; ql[73] = spatial_metric_der_l[2][0][2]; - ql[74] = spatial_metric_der_l[2][1][0]; ql[75] = spatial_metric_der_l[2][1][1]; ql[76] = spatial_metric_der_l[2][1][2]; - ql[77] = spatial_metric_der_l[2][2][0]; ql[78] = spatial_metric_der_l[2][2][1]; ql[79] = spatial_metric_der_l[2][2][2]; + ql[41] = lapse_der_l[0]; + ql[42] = lapse_der_l[1]; + ql[43] = lapse_der_l[2]; + ql[44] = shift_der_l[0][0]; + ql[45] = shift_der_l[0][1]; + ql[46] = shift_der_l[0][2]; + ql[47] = shift_der_l[1][0]; + ql[48] = shift_der_l[1][1]; + ql[49] = shift_der_l[1][2]; + ql[50] = shift_der_l[2][0]; + ql[51] = shift_der_l[2][1]; + ql[52] = shift_der_l[2][2]; + + ql[53] = spatial_metric_der_l[0][0][0]; + ql[54] = spatial_metric_der_l[0][0][1]; + ql[55] = spatial_metric_der_l[0][0][2]; + ql[56] = spatial_metric_der_l[0][1][0]; + ql[57] = spatial_metric_der_l[0][1][1]; + ql[58] = spatial_metric_der_l[0][1][2]; + ql[59] = spatial_metric_der_l[0][2][0]; + ql[60] = spatial_metric_der_l[0][2][1]; + ql[61] = spatial_metric_der_l[0][2][2]; + + ql[62] = spatial_metric_der_l[1][0][0]; + ql[63] = spatial_metric_der_l[1][0][1]; + ql[64] = spatial_metric_der_l[1][0][2]; + ql[65] = spatial_metric_der_l[1][1][0]; + ql[66] = spatial_metric_der_l[1][1][1]; + ql[67] = spatial_metric_der_l[1][1][2]; + ql[68] = spatial_metric_der_l[1][2][0]; + ql[69] = spatial_metric_der_l[1][2][1]; + ql[70] = spatial_metric_der_l[1][2][2]; + + ql[71] = spatial_metric_der_l[2][0][0]; + ql[72] = spatial_metric_der_l[2][0][1]; + ql[73] = spatial_metric_der_l[2][0][2]; + ql[74] = spatial_metric_der_l[2][1][0]; + ql[75] = spatial_metric_der_l[2][1][1]; + ql[76] = spatial_metric_der_l[2][1][2]; + ql[77] = spatial_metric_der_l[2][2][0]; + ql[78] = spatial_metric_der_l[2][2][1]; + ql[79] = spatial_metric_der_l[2][2][2]; ql[80] = 0.0; - ql[81] = x - 0.5; ql[82] = y; ql[83] = 0.0; + ql[81] = x - 0.5; + ql[82] = y; + ql[83] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_elc_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_elc_r * he_r * (W_r * W_r) * u_r; @@ -1313,60 +1788,95 @@ test_gr_twofluid_tetrad_waves_schwarzschild_ho() qr[8] = sqrt(spatial_det_r) * rho_ion_r * hi_r * (W_r * W_r) * w_r; qr[9] = sqrt(spatial_det_r) * ((rho_ion_r * hi_r * (W_r * W_r)) - p_r - (rho_ion_r * W_r)); - qr[10] = Dx_r; qr[11] = Dy_r; qr[12] = Dz_r; - qr[13] = Bx_r; qr[14] = By_r; qr[15] = Bz_r; - qr[16] = phi_r; qr[17] = psi_r; + qr[10] = Dx_r; + qr[11] = Dy_r; + qr[12] = Dz_r; + qr[13] = Bx_r; + qr[14] = By_r; + qr[15] = Bz_r; + qr[16] = phi_r; + qr[17] = psi_r; qr[18] = lapse_r; - qr[19] = shift_r[0]; qr[20] = shift_r[1]; qr[21] = shift_r[2]; - - qr[22] = spatial_metric_r[0][0]; qr[23] = spatial_metric_r[0][1]; qr[24] = spatial_metric_r[0][2]; - qr[25] = spatial_metric_r[1][0]; qr[26] = spatial_metric_r[1][1]; qr[27] = spatial_metric_r[1][2]; - qr[28] = spatial_metric_r[2][0]; qr[29] = spatial_metric_r[2][1]; qr[30] = spatial_metric_r[2][2]; - - qr[31] = extrinsic_curvature_r[0][0]; qr[32] = extrinsic_curvature_r[0][1]; qr[33] = extrinsic_curvature_r[0][2]; - qr[34] = extrinsic_curvature_r[1][0]; qr[35] = extrinsic_curvature_r[1][1]; qr[36] = extrinsic_curvature_r[1][2]; - qr[37] = extrinsic_curvature_r[2][0]; qr[38] = extrinsic_curvature_r[2][1]; qr[39] = extrinsic_curvature_r[2][2]; + qr[19] = shift_r[0]; + qr[20] = shift_r[1]; + qr[21] = shift_r[2]; + + qr[22] = spatial_metric_r[0][0]; + qr[23] = spatial_metric_r[0][1]; + qr[24] = spatial_metric_r[0][2]; + qr[25] = spatial_metric_r[1][0]; + qr[26] = spatial_metric_r[1][1]; + qr[27] = spatial_metric_r[1][2]; + qr[28] = spatial_metric_r[2][0]; + qr[29] = spatial_metric_r[2][1]; + qr[30] = spatial_metric_r[2][2]; + + qr[31] = extrinsic_curvature_r[0][0]; + qr[32] = extrinsic_curvature_r[0][1]; + qr[33] = extrinsic_curvature_r[0][2]; + qr[34] = extrinsic_curvature_r[1][0]; + qr[35] = extrinsic_curvature_r[1][1]; + qr[36] = extrinsic_curvature_r[1][2]; + qr[37] = extrinsic_curvature_r[2][0]; + qr[38] = extrinsic_curvature_r[2][1]; + qr[39] = extrinsic_curvature_r[2][2]; qr[40] = 1.0; - qr[41] = lapse_der_r[0]; qr[42] = lapse_der_r[1]; qr[43] = lapse_der_r[2]; - qr[44] = shift_der_r[0][0]; qr[45] = shift_der_r[0][1]; qr[46] = shift_der_r[0][2]; - qr[47] = shift_der_r[1][0]; qr[48] = shift_der_r[1][1]; qr[49] = shift_der_r[1][2]; - qr[50] = shift_der_r[2][0]; qr[51] = shift_der_r[2][1]; qr[52] = shift_der_r[2][2]; - - qr[53] = spatial_metric_der_r[0][0][0]; qr[54] = spatial_metric_der_r[0][0][1]; qr[55] = spatial_metric_der_r[0][0][2]; - qr[56] = spatial_metric_der_r[0][1][0]; qr[57] = spatial_metric_der_r[0][1][1]; qr[58] = spatial_metric_der_r[0][1][2]; - qr[59] = spatial_metric_der_r[0][2][0]; qr[60] = spatial_metric_der_r[0][2][1]; qr[61] = spatial_metric_der_r[0][2][2]; - - qr[62] = spatial_metric_der_r[1][0][0]; qr[63] = spatial_metric_der_r[1][0][1]; qr[64] = spatial_metric_der_r[1][0][2]; - qr[65] = spatial_metric_der_r[1][1][0]; qr[66] = spatial_metric_der_r[1][1][1]; qr[67] = spatial_metric_der_r[1][1][2]; - qr[68] = spatial_metric_der_r[1][2][0]; qr[69] = spatial_metric_der_r[1][2][1]; qr[70] = spatial_metric_der_r[1][2][2]; - - qr[71] = spatial_metric_der_r[2][0][0]; qr[72] = spatial_metric_der_r[2][0][1]; qr[73] = spatial_metric_der_r[2][0][2]; - qr[74] = spatial_metric_der_r[2][1][0]; qr[75] = spatial_metric_der_r[2][1][1]; qr[76] = spatial_metric_der_r[2][1][2]; - qr[77] = spatial_metric_der_r[2][2][0]; qr[78] = spatial_metric_der_r[2][2][1]; qr[79] = spatial_metric_der_r[2][2][2]; + qr[41] = lapse_der_r[0]; + qr[42] = lapse_der_r[1]; + qr[43] = lapse_der_r[2]; + qr[44] = shift_der_r[0][0]; + qr[45] = shift_der_r[0][1]; + qr[46] = shift_der_r[0][2]; + qr[47] = shift_der_r[1][0]; + qr[48] = shift_der_r[1][1]; + qr[49] = shift_der_r[1][2]; + qr[50] = shift_der_r[2][0]; + qr[51] = shift_der_r[2][1]; + qr[52] = shift_der_r[2][2]; + + qr[53] = spatial_metric_der_r[0][0][0]; + qr[54] = spatial_metric_der_r[0][0][1]; + qr[55] = spatial_metric_der_r[0][0][2]; + qr[56] = spatial_metric_der_r[0][1][0]; + qr[57] = spatial_metric_der_r[0][1][1]; + qr[58] = spatial_metric_der_r[0][1][2]; + qr[59] = spatial_metric_der_r[0][2][0]; + qr[60] = spatial_metric_der_r[0][2][1]; + qr[61] = spatial_metric_der_r[0][2][2]; + + qr[62] = spatial_metric_der_r[1][0][0]; + qr[63] = spatial_metric_der_r[1][0][1]; + qr[64] = spatial_metric_der_r[1][0][2]; + qr[65] = spatial_metric_der_r[1][1][0]; + qr[66] = spatial_metric_der_r[1][1][1]; + qr[67] = spatial_metric_der_r[1][1][2]; + qr[68] = spatial_metric_der_r[1][2][0]; + qr[69] = spatial_metric_der_r[1][2][1]; + qr[70] = spatial_metric_der_r[1][2][2]; + + qr[71] = spatial_metric_der_r[2][0][0]; + qr[72] = spatial_metric_der_r[2][0][1]; + qr[73] = spatial_metric_der_r[2][0][2]; + qr[74] = spatial_metric_der_r[2][1][0]; + qr[75] = spatial_metric_der_r[2][1][1]; + qr[76] = spatial_metric_der_r[2][1][2]; + qr[77] = spatial_metric_der_r[2][2][0]; + qr[78] = spatial_metric_der_r[2][2][1]; + qr[79] = spatial_metric_der_r[2][2][2]; qr[80] = 0.0; - qr[81] = x + 0.5; qr[82] = y; qr[83] = 0.0; + qr[81] = x + 0.5; + qr[82] = y; + qr[83] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 84], waves_local[3 * 84]; @@ -1380,33 +1890,59 @@ test_gr_twofluid_tetrad_waves_schwarzschild_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[84], amdq_local[84]; - gkyl_wv_eqn_qfluct(gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84]); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84] + ); } double apdq[84], amdq[84]; - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); double fl_local_sr[84], fr_local_sr[84]; - gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr); - gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr); + gkyl_gr_twofluid_tetrad_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr + ); + gkyl_gr_twofluid_tetrad_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr + ); double fl_local_gr[84], fr_local_gr[84]; - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr, fr_local_gr); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr, + fl_local_gr + ); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr, + fr_local_gr + ); double fl[84], fr[84]; - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl + ); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr + ); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1418,7 +1954,7 @@ test_gr_twofluid_tetrad_waves_schwarzschild_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1447,8 +1983,7 @@ test_gr_twofluid_tetrad_waves_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_twofluid_tetrad_waves_kerr_ho() +void test_gr_twofluid_tetrad_waves_kerr_ho() { double gas_gamma_elc = 5.0 / 3.0; double gas_gamma_ion = 5.0 / 3.0; @@ -1462,8 +1997,10 @@ test_gr_twofluid_tetrad_waves_kerr_ho() double b_fact = 0.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new(mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, - light_speed, e_fact, b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_twofluid_tetrad = gkyl_wv_gr_twofluid_tetrad_new( + mass_elc, mass_ion, charge_elc, charge_ion, gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, + b_fact, GKYL_STATIC_GAUGE, 0, spacetime, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1490,10 +2027,10 @@ test_gr_twofluid_tetrad_waves_kerr_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1503,18 +2040,18 @@ test_gr_twofluid_tetrad_waves_kerr_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1533,20 +2070,46 @@ test_gr_twofluid_tetrad_waves_kerr_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1577,42 +2140,89 @@ test_gr_twofluid_tetrad_waves_kerr_ho() ql[8] = sqrt(spatial_det_l) * rho_ion_l * hi_l * (W_l * W_l) * w_l; ql[9] = sqrt(spatial_det_l) * ((rho_ion_l * hi_l * (W_l * W_l)) - p_l - (rho_ion_l * W_l)); - ql[10] = Dx_l; ql[11] = Dy_l; ql[12] = Dz_l; - ql[13] = Bx_l; ql[14] = By_l; ql[15] = Bz_l; - ql[16] = phi_l; ql[17] = psi_l; + ql[10] = Dx_l; + ql[11] = Dy_l; + ql[12] = Dz_l; + ql[13] = Bx_l; + ql[14] = By_l; + ql[15] = Bz_l; + ql[16] = phi_l; + ql[17] = psi_l; ql[18] = lapse_l; - ql[19] = shift_l[0]; ql[20] = shift_l[1]; ql[21] = shift_l[2]; - - ql[22] = spatial_metric_l[0][0]; ql[23] = spatial_metric_l[0][1]; ql[24] = spatial_metric_l[0][2]; - ql[25] = spatial_metric_l[1][0]; ql[26] = spatial_metric_l[1][1]; ql[27] = spatial_metric_l[1][2]; - ql[28] = spatial_metric_l[2][0]; ql[29] = spatial_metric_l[2][1]; ql[30] = spatial_metric_l[2][2]; - - ql[31] = extrinsic_curvature_l[0][0]; ql[32] = extrinsic_curvature_l[0][1]; ql[33] = extrinsic_curvature_l[0][2]; - ql[34] = extrinsic_curvature_l[1][0]; ql[35] = extrinsic_curvature_l[1][1]; ql[36] = extrinsic_curvature_l[1][2]; - ql[37] = extrinsic_curvature_l[2][0]; ql[38] = extrinsic_curvature_l[2][1]; ql[39] = extrinsic_curvature_l[2][2]; + ql[19] = shift_l[0]; + ql[20] = shift_l[1]; + ql[21] = shift_l[2]; + + ql[22] = spatial_metric_l[0][0]; + ql[23] = spatial_metric_l[0][1]; + ql[24] = spatial_metric_l[0][2]; + ql[25] = spatial_metric_l[1][0]; + ql[26] = spatial_metric_l[1][1]; + ql[27] = spatial_metric_l[1][2]; + ql[28] = spatial_metric_l[2][0]; + ql[29] = spatial_metric_l[2][1]; + ql[30] = spatial_metric_l[2][2]; + + ql[31] = extrinsic_curvature_l[0][0]; + ql[32] = extrinsic_curvature_l[0][1]; + ql[33] = extrinsic_curvature_l[0][2]; + ql[34] = extrinsic_curvature_l[1][0]; + ql[35] = extrinsic_curvature_l[1][1]; + ql[36] = extrinsic_curvature_l[1][2]; + ql[37] = extrinsic_curvature_l[2][0]; + ql[38] = extrinsic_curvature_l[2][1]; + ql[39] = extrinsic_curvature_l[2][2]; ql[40] = 1.0; - ql[41] = lapse_der_l[0]; ql[42] = lapse_der_l[1]; ql[43] = lapse_der_l[2]; - ql[44] = shift_der_l[0][0]; ql[45] = shift_der_l[0][1]; ql[46] = shift_der_l[0][2]; - ql[47] = shift_der_l[1][0]; ql[48] = shift_der_l[1][1]; ql[49] = shift_der_l[1][2]; - ql[50] = shift_der_l[2][0]; ql[51] = shift_der_l[2][1]; ql[52] = shift_der_l[2][2]; - - ql[53] = spatial_metric_der_l[0][0][0]; ql[54] = spatial_metric_der_l[0][0][1]; ql[55] = spatial_metric_der_l[0][0][2]; - ql[56] = spatial_metric_der_l[0][1][0]; ql[57] = spatial_metric_der_l[0][1][1]; ql[58] = spatial_metric_der_l[0][1][2]; - ql[59] = spatial_metric_der_l[0][2][0]; ql[60] = spatial_metric_der_l[0][2][1]; ql[61] = spatial_metric_der_l[0][2][2]; - - ql[62] = spatial_metric_der_l[1][0][0]; ql[63] = spatial_metric_der_l[1][0][1]; ql[64] = spatial_metric_der_l[1][0][2]; - ql[65] = spatial_metric_der_l[1][1][0]; ql[66] = spatial_metric_der_l[1][1][1]; ql[67] = spatial_metric_der_l[1][1][2]; - ql[68] = spatial_metric_der_l[1][2][0]; ql[69] = spatial_metric_der_l[1][2][1]; ql[70] = spatial_metric_der_l[1][2][2]; - - ql[71] = spatial_metric_der_l[2][0][0]; ql[72] = spatial_metric_der_l[2][0][1]; ql[73] = spatial_metric_der_l[2][0][2]; - ql[74] = spatial_metric_der_l[2][1][0]; ql[75] = spatial_metric_der_l[2][1][1]; ql[76] = spatial_metric_der_l[2][1][2]; - ql[77] = spatial_metric_der_l[2][2][0]; ql[78] = spatial_metric_der_l[2][2][1]; ql[79] = spatial_metric_der_l[2][2][2]; + ql[41] = lapse_der_l[0]; + ql[42] = lapse_der_l[1]; + ql[43] = lapse_der_l[2]; + ql[44] = shift_der_l[0][0]; + ql[45] = shift_der_l[0][1]; + ql[46] = shift_der_l[0][2]; + ql[47] = shift_der_l[1][0]; + ql[48] = shift_der_l[1][1]; + ql[49] = shift_der_l[1][2]; + ql[50] = shift_der_l[2][0]; + ql[51] = shift_der_l[2][1]; + ql[52] = shift_der_l[2][2]; + + ql[53] = spatial_metric_der_l[0][0][0]; + ql[54] = spatial_metric_der_l[0][0][1]; + ql[55] = spatial_metric_der_l[0][0][2]; + ql[56] = spatial_metric_der_l[0][1][0]; + ql[57] = spatial_metric_der_l[0][1][1]; + ql[58] = spatial_metric_der_l[0][1][2]; + ql[59] = spatial_metric_der_l[0][2][0]; + ql[60] = spatial_metric_der_l[0][2][1]; + ql[61] = spatial_metric_der_l[0][2][2]; + + ql[62] = spatial_metric_der_l[1][0][0]; + ql[63] = spatial_metric_der_l[1][0][1]; + ql[64] = spatial_metric_der_l[1][0][2]; + ql[65] = spatial_metric_der_l[1][1][0]; + ql[66] = spatial_metric_der_l[1][1][1]; + ql[67] = spatial_metric_der_l[1][1][2]; + ql[68] = spatial_metric_der_l[1][2][0]; + ql[69] = spatial_metric_der_l[1][2][1]; + ql[70] = spatial_metric_der_l[1][2][2]; + + ql[71] = spatial_metric_der_l[2][0][0]; + ql[72] = spatial_metric_der_l[2][0][1]; + ql[73] = spatial_metric_der_l[2][0][2]; + ql[74] = spatial_metric_der_l[2][1][0]; + ql[75] = spatial_metric_der_l[2][1][1]; + ql[76] = spatial_metric_der_l[2][1][2]; + ql[77] = spatial_metric_der_l[2][2][0]; + ql[78] = spatial_metric_der_l[2][2][1]; + ql[79] = spatial_metric_der_l[2][2][2]; ql[80] = 0.0; - ql[81] = x - 0.5; ql[82] = y; ql[83] = 0.0; + ql[81] = x - 0.5; + ql[82] = y; + ql[83] = 0.0; qr[0] = sqrt(spatial_det_r) * rho_elc_r * W_r; qr[1] = sqrt(spatial_det_r) * rho_elc_r * he_r * (W_r * W_r) * u_r; @@ -1626,60 +2236,95 @@ test_gr_twofluid_tetrad_waves_kerr_ho() qr[8] = sqrt(spatial_det_r) * rho_ion_r * hi_r * (W_r * W_r) * w_r; qr[9] = sqrt(spatial_det_r) * ((rho_ion_r * hi_r * (W_r * W_r)) - p_r - (rho_ion_r * W_r)); - qr[10] = Dx_r; qr[11] = Dy_r; qr[12] = Dz_r; - qr[13] = Bx_r; qr[14] = By_r; qr[15] = Bz_r; - qr[16] = phi_r; qr[17] = psi_r; + qr[10] = Dx_r; + qr[11] = Dy_r; + qr[12] = Dz_r; + qr[13] = Bx_r; + qr[14] = By_r; + qr[15] = Bz_r; + qr[16] = phi_r; + qr[17] = psi_r; qr[18] = lapse_r; - qr[19] = shift_r[0]; qr[20] = shift_r[1]; qr[21] = shift_r[2]; - - qr[22] = spatial_metric_r[0][0]; qr[23] = spatial_metric_r[0][1]; qr[24] = spatial_metric_r[0][2]; - qr[25] = spatial_metric_r[1][0]; qr[26] = spatial_metric_r[1][1]; qr[27] = spatial_metric_r[1][2]; - qr[28] = spatial_metric_r[2][0]; qr[29] = spatial_metric_r[2][1]; qr[30] = spatial_metric_r[2][2]; - - qr[31] = extrinsic_curvature_r[0][0]; qr[32] = extrinsic_curvature_r[0][1]; qr[33] = extrinsic_curvature_r[0][2]; - qr[34] = extrinsic_curvature_r[1][0]; qr[35] = extrinsic_curvature_r[1][1]; qr[36] = extrinsic_curvature_r[1][2]; - qr[37] = extrinsic_curvature_r[2][0]; qr[38] = extrinsic_curvature_r[2][1]; qr[39] = extrinsic_curvature_r[2][2]; + qr[19] = shift_r[0]; + qr[20] = shift_r[1]; + qr[21] = shift_r[2]; + + qr[22] = spatial_metric_r[0][0]; + qr[23] = spatial_metric_r[0][1]; + qr[24] = spatial_metric_r[0][2]; + qr[25] = spatial_metric_r[1][0]; + qr[26] = spatial_metric_r[1][1]; + qr[27] = spatial_metric_r[1][2]; + qr[28] = spatial_metric_r[2][0]; + qr[29] = spatial_metric_r[2][1]; + qr[30] = spatial_metric_r[2][2]; + + qr[31] = extrinsic_curvature_r[0][0]; + qr[32] = extrinsic_curvature_r[0][1]; + qr[33] = extrinsic_curvature_r[0][2]; + qr[34] = extrinsic_curvature_r[1][0]; + qr[35] = extrinsic_curvature_r[1][1]; + qr[36] = extrinsic_curvature_r[1][2]; + qr[37] = extrinsic_curvature_r[2][0]; + qr[38] = extrinsic_curvature_r[2][1]; + qr[39] = extrinsic_curvature_r[2][2]; qr[40] = 1.0; - qr[41] = lapse_der_r[0]; qr[42] = lapse_der_r[1]; qr[43] = lapse_der_r[2]; - qr[44] = shift_der_r[0][0]; qr[45] = shift_der_r[0][1]; qr[46] = shift_der_r[0][2]; - qr[47] = shift_der_r[1][0]; qr[48] = shift_der_r[1][1]; qr[49] = shift_der_r[1][2]; - qr[50] = shift_der_r[2][0]; qr[51] = shift_der_r[2][1]; qr[52] = shift_der_r[2][2]; - - qr[53] = spatial_metric_der_r[0][0][0]; qr[54] = spatial_metric_der_r[0][0][1]; qr[55] = spatial_metric_der_r[0][0][2]; - qr[56] = spatial_metric_der_r[0][1][0]; qr[57] = spatial_metric_der_r[0][1][1]; qr[58] = spatial_metric_der_r[0][1][2]; - qr[59] = spatial_metric_der_r[0][2][0]; qr[60] = spatial_metric_der_r[0][2][1]; qr[61] = spatial_metric_der_r[0][2][2]; - - qr[62] = spatial_metric_der_r[1][0][0]; qr[63] = spatial_metric_der_r[1][0][1]; qr[64] = spatial_metric_der_r[1][0][2]; - qr[65] = spatial_metric_der_r[1][1][0]; qr[66] = spatial_metric_der_r[1][1][1]; qr[67] = spatial_metric_der_r[1][1][2]; - qr[68] = spatial_metric_der_r[1][2][0]; qr[69] = spatial_metric_der_r[1][2][1]; qr[70] = spatial_metric_der_r[1][2][2]; - - qr[71] = spatial_metric_der_r[2][0][0]; qr[72] = spatial_metric_der_r[2][0][1]; qr[73] = spatial_metric_der_r[2][0][2]; - qr[74] = spatial_metric_der_r[2][1][0]; qr[75] = spatial_metric_der_r[2][1][1]; qr[76] = spatial_metric_der_r[2][1][2]; - qr[77] = spatial_metric_der_r[2][2][0]; qr[78] = spatial_metric_der_r[2][2][1]; qr[79] = spatial_metric_der_r[2][2][2]; + qr[41] = lapse_der_r[0]; + qr[42] = lapse_der_r[1]; + qr[43] = lapse_der_r[2]; + qr[44] = shift_der_r[0][0]; + qr[45] = shift_der_r[0][1]; + qr[46] = shift_der_r[0][2]; + qr[47] = shift_der_r[1][0]; + qr[48] = shift_der_r[1][1]; + qr[49] = shift_der_r[1][2]; + qr[50] = shift_der_r[2][0]; + qr[51] = shift_der_r[2][1]; + qr[52] = shift_der_r[2][2]; + + qr[53] = spatial_metric_der_r[0][0][0]; + qr[54] = spatial_metric_der_r[0][0][1]; + qr[55] = spatial_metric_der_r[0][0][2]; + qr[56] = spatial_metric_der_r[0][1][0]; + qr[57] = spatial_metric_der_r[0][1][1]; + qr[58] = spatial_metric_der_r[0][1][2]; + qr[59] = spatial_metric_der_r[0][2][0]; + qr[60] = spatial_metric_der_r[0][2][1]; + qr[61] = spatial_metric_der_r[0][2][2]; + + qr[62] = spatial_metric_der_r[1][0][0]; + qr[63] = spatial_metric_der_r[1][0][1]; + qr[64] = spatial_metric_der_r[1][0][2]; + qr[65] = spatial_metric_der_r[1][1][0]; + qr[66] = spatial_metric_der_r[1][1][1]; + qr[67] = spatial_metric_der_r[1][1][2]; + qr[68] = spatial_metric_der_r[1][2][0]; + qr[69] = spatial_metric_der_r[1][2][1]; + qr[70] = spatial_metric_der_r[1][2][2]; + + qr[71] = spatial_metric_der_r[2][0][0]; + qr[72] = spatial_metric_der_r[2][0][1]; + qr[73] = spatial_metric_der_r[2][0][2]; + qr[74] = spatial_metric_der_r[2][1][0]; + qr[75] = spatial_metric_der_r[2][1][1]; + qr[76] = spatial_metric_der_r[2][1][2]; + qr[77] = spatial_metric_der_r[2][2][0]; + qr[78] = spatial_metric_der_r[2][2][1]; + qr[79] = spatial_metric_der_r[2][2][2]; qr[80] = 0.0; - qr[81] = x + 0.5; qr[82] = y; qr[83] = 0.0; + qr[81] = x + 0.5; + qr[82] = y; + qr[83] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 84], waves_local[3 * 84]; @@ -1693,33 +2338,59 @@ test_gr_twofluid_tetrad_waves_kerr_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[84], amdq_local[84]; - gkyl_wv_eqn_qfluct(gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_twofluid_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84]); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 84], &waves[i * 84] + ); } double apdq[84], amdq[84]; - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); double fl_local_sr[84], fr_local_sr[84]; - gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr); - gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr); + gkyl_gr_twofluid_tetrad_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr + ); + gkyl_gr_twofluid_tetrad_flux( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr + ); double fl_local_gr[84], fr_local_gr[84]; - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr, fr_local_gr); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql_local, fl_local_sr, + fl_local_gr + ); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr_local, fr_local_sr, + fr_local_gr + ); double fl[84], fr[84]; - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); - gkyl_wv_eqn_rotate_to_global(gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl + ); + gkyl_wv_eqn_rotate_to_global( + gr_twofluid_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr + ); for (int i = 0; i < 84; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1731,7 +2402,7 @@ test_gr_twofluid_tetrad_waves_kerr_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1761,11 +2432,11 @@ test_gr_twofluid_tetrad_waves_kerr_ho() } TEST_LIST = { - { "gr_twofluid_tetrad_basic_minkowski_ho", test_gr_twofluid_tetrad_basic_minkowski_ho }, - { "gr_twofluid_tetrad_basic_schwarzschild_ho", test_gr_twofluid_tetrad_basic_schwarzschild_ho }, - { "gr_twofluid_tetrad_basic_kerr_ho", test_gr_twofluid_tetrad_basic_kerr_ho }, - { "gr_twofluid_tetrad_waves_minkowski_ho", test_gr_twofluid_tetrad_waves_minkowski_ho }, - { "gr_twofluid_tetrad_waves_schwarzschild_ho", test_gr_twofluid_tetrad_waves_schwarzschild_ho }, - { "gr_twofluid_tetrad_waves_kerr_ho", test_gr_twofluid_tetrad_waves_kerr_ho }, - { NULL, NULL }, + {"gr_twofluid_tetrad_basic_minkowski_ho", test_gr_twofluid_tetrad_basic_minkowski_ho}, + {"gr_twofluid_tetrad_basic_schwarzschild_ho", test_gr_twofluid_tetrad_basic_schwarzschild_ho}, + {"gr_twofluid_tetrad_basic_kerr_ho", test_gr_twofluid_tetrad_basic_kerr_ho}, + {"gr_twofluid_tetrad_waves_minkowski_ho", test_gr_twofluid_tetrad_waves_minkowski_ho}, + {"gr_twofluid_tetrad_waves_schwarzschild_ho", test_gr_twofluid_tetrad_waves_schwarzschild_ho}, + {"gr_twofluid_tetrad_waves_kerr_ho", test_gr_twofluid_tetrad_waves_kerr_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_gr_ultra_rel_euler.c b/moments/unit/ctest_wv_gr_ultra_rel_euler.c index 1dfaf115db..23abc5dbb4 100644 --- a/moments/unit/ctest_wv_gr_ultra_rel_euler.c +++ b/moments/unit/ctest_wv_gr_ultra_rel_euler.c @@ -6,15 +6,15 @@ #include #include -void -test_gr_ultra_rel_euler_basic_minkowski_ho() +void test_gr_ultra_rel_euler_basic_minkowski_ho() { double gas_gamma = 2.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler = + gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_ultra_rel_euler->num_equations == 70 ); - TEST_CHECK( gr_ultra_rel_euler->num_waves == 2 ); + TEST_CHECK(gr_ultra_rel_euler->num_equations == 70); + TEST_CHECK(gr_ultra_rel_euler->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -27,25 +27,25 @@ test_gr_ultra_rel_euler_basic_minkowski_ho() double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -55,16 +55,28 @@ test_gr_ultra_rel_euler_basic_minkowski_ho() spacetime->spatial_metric_det_func(spacetime, 0.0, x, y, 0.0, &spatial_det); spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -82,87 +94,133 @@ test_gr_ultra_rel_euler_basic_minkowski_ho() q[3] = sqrt(spatial_det) * (rho + p) * (W * W) * w; q[4] = lapse; - q[5] = shift[0]; q[6] = shift[1]; q[7] = shift[2]; - - q[8] = spatial_metric[0][0]; q[9] = spatial_metric[0][1]; q[10] = spatial_metric[0][2]; - q[11] = spatial_metric[1][0]; q[12] = spatial_metric[1][1]; q[13] = spatial_metric[1][2]; - q[14] = spatial_metric[2][0]; q[15] = spatial_metric[2][1]; q[16] = spatial_metric[2][2]; - - q[17] = extrinsic_curvature[0][0]; q[18] = extrinsic_curvature[0][1]; q[19] = extrinsic_curvature[0][2]; - q[20] = extrinsic_curvature[1][0]; q[21] = extrinsic_curvature[1][1]; q[22] = extrinsic_curvature[1][2]; - q[23] = extrinsic_curvature[2][0]; q[24] = extrinsic_curvature[2][1]; q[25] = extrinsic_curvature[2][2]; + q[5] = shift[0]; + q[6] = shift[1]; + q[7] = shift[2]; + + q[8] = spatial_metric[0][0]; + q[9] = spatial_metric[0][1]; + q[10] = spatial_metric[0][2]; + q[11] = spatial_metric[1][0]; + q[12] = spatial_metric[1][1]; + q[13] = spatial_metric[1][2]; + q[14] = spatial_metric[2][0]; + q[15] = spatial_metric[2][1]; + q[16] = spatial_metric[2][2]; + + q[17] = extrinsic_curvature[0][0]; + q[18] = extrinsic_curvature[0][1]; + q[19] = extrinsic_curvature[0][2]; + q[20] = extrinsic_curvature[1][0]; + q[21] = extrinsic_curvature[1][1]; + q[22] = extrinsic_curvature[1][2]; + q[23] = extrinsic_curvature[2][0]; + q[24] = extrinsic_curvature[2][1]; + q[25] = extrinsic_curvature[2][2]; q[26] = 1.0; - q[27] = lapse_der[0]; q[28] = lapse_der[1]; q[29] = lapse_der[2]; - q[30] = shift_der[0][0]; q[31] = shift_der[0][1]; q[32] = shift_der[0][2]; - q[33] = shift_der[1][0]; q[34] = shift_der[1][1]; q[35] = shift_der[1][2]; - q[36] = shift_der[2][0]; q[37] = shift_der[2][1]; q[38] = shift_der[2][2]; - - q[39] = spatial_metric_der[0][0][0]; q[40] = spatial_metric_der[0][0][1]; q[41] = spatial_metric_der[0][0][2]; - q[42] = spatial_metric_der[0][1][0]; q[43] = spatial_metric_der[0][1][1]; q[44] = spatial_metric_der[0][1][2]; - q[45] = spatial_metric_der[0][2][0]; q[46] = spatial_metric_der[0][2][1]; q[47] = spatial_metric_der[0][2][2]; - - q[48] = spatial_metric_der[1][0][0]; q[49] = spatial_metric_der[1][0][1]; q[50] = spatial_metric_der[1][0][2]; - q[51] = spatial_metric_der[1][1][0]; q[52] = spatial_metric_der[1][1][1]; q[53] = spatial_metric_der[1][1][2]; - q[54] = spatial_metric_der[1][2][0]; q[55] = spatial_metric_der[1][2][1]; q[56] = spatial_metric_der[1][2][2]; - - q[57] = spatial_metric_der[2][0][0]; q[58] = spatial_metric_der[2][0][1]; q[59] = spatial_metric_der[2][0][2]; - q[60] = spatial_metric_der[2][1][0]; q[61] = spatial_metric_der[2][1][1]; q[62] = spatial_metric_der[2][1][2]; - q[63] = spatial_metric_der[2][2][0]; q[64] = spatial_metric_der[2][2][1]; q[65] = spatial_metric_der[2][2][2]; + q[27] = lapse_der[0]; + q[28] = lapse_der[1]; + q[29] = lapse_der[2]; + q[30] = shift_der[0][0]; + q[31] = shift_der[0][1]; + q[32] = shift_der[0][2]; + q[33] = shift_der[1][0]; + q[34] = shift_der[1][1]; + q[35] = shift_der[1][2]; + q[36] = shift_der[2][0]; + q[37] = shift_der[2][1]; + q[38] = shift_der[2][2]; + + q[39] = spatial_metric_der[0][0][0]; + q[40] = spatial_metric_der[0][0][1]; + q[41] = spatial_metric_der[0][0][2]; + q[42] = spatial_metric_der[0][1][0]; + q[43] = spatial_metric_der[0][1][1]; + q[44] = spatial_metric_der[0][1][2]; + q[45] = spatial_metric_der[0][2][0]; + q[46] = spatial_metric_der[0][2][1]; + q[47] = spatial_metric_der[0][2][2]; + + q[48] = spatial_metric_der[1][0][0]; + q[49] = spatial_metric_der[1][0][1]; + q[50] = spatial_metric_der[1][0][2]; + q[51] = spatial_metric_der[1][1][0]; + q[52] = spatial_metric_der[1][1][1]; + q[53] = spatial_metric_der[1][1][2]; + q[54] = spatial_metric_der[1][2][0]; + q[55] = spatial_metric_der[1][2][1]; + q[56] = spatial_metric_der[1][2][2]; + + q[57] = spatial_metric_der[2][0][0]; + q[58] = spatial_metric_der[2][0][1]; + q[59] = spatial_metric_der[2][0][2]; + q[60] = spatial_metric_der[2][1][0]; + q[61] = spatial_metric_der[2][1][1]; + q[62] = spatial_metric_der[2][1][2]; + q[63] = spatial_metric_der[2][2][0]; + q[64] = spatial_metric_der[2][2][1]; + q[65] = spatial_metric_der[2][2][2]; q[66] = 0.0; - q[67] = x; q[68] = y; q[69] = 0.0; + q[67] = x; + q[68] = y; + q[69] = 0.0; double prims[70]; gkyl_gr_ultra_rel_euler_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-13) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-13)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-13)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-13)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-13)); double fluxes[3][4] = { - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p) }, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[70], flux_local[70], flux[70]; for (int d = 0; d < 3; d++) { - gr_ultra_rel_euler->rotate_to_local_func(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], q, q_local); + gr_ultra_rel_euler->rotate_to_local_func( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_gr_ultra_rel_euler_flux(gas_gamma, q_local, flux_local); - gr_ultra_rel_euler->rotate_to_global_func(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], flux_local, flux); + gr_ultra_rel_euler->rotate_to_global_func( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 4; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-13) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-13)); } } @@ -172,7 +230,7 @@ test_gr_ultra_rel_euler_basic_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[70], q1[70]; @@ -180,7 +238,7 @@ test_gr_ultra_rel_euler_basic_minkowski_ho() gr_ultra_rel_euler->riem_to_cons(gr_ultra_rel_euler, q_local, w1, q1); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } @@ -188,7 +246,7 @@ test_gr_ultra_rel_euler_basic_minkowski_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -208,15 +266,15 @@ test_gr_ultra_rel_euler_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_ultra_rel_euler_basic_schwarzschild_ho() +void test_gr_ultra_rel_euler_basic_schwarzschild_ho() { double gas_gamma = 2.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler = + gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_ultra_rel_euler->num_equations == 70 ); - TEST_CHECK( gr_ultra_rel_euler->num_waves == 2 ); + TEST_CHECK(gr_ultra_rel_euler->num_equations == 70); + TEST_CHECK(gr_ultra_rel_euler->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -230,25 +288,25 @@ test_gr_ultra_rel_euler_basic_schwarzschild_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -259,16 +317,28 @@ test_gr_ultra_rel_euler_basic_schwarzschild_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -287,94 +357,144 @@ test_gr_ultra_rel_euler_basic_schwarzschild_ho() q[3] = sqrt(spatial_det) * (rho + p) * (W * W) * w; q[4] = lapse; - q[5] = shift[0]; q[6] = shift[1]; q[7] = shift[2]; - - q[8] = spatial_metric[0][0]; q[9] = spatial_metric[0][1]; q[10] = spatial_metric[0][2]; - q[11] = spatial_metric[1][0]; q[12] = spatial_metric[1][1]; q[13] = spatial_metric[1][2]; - q[14] = spatial_metric[2][0]; q[15] = spatial_metric[2][1]; q[16] = spatial_metric[2][2]; - - q[17] = extrinsic_curvature[0][0]; q[18] = extrinsic_curvature[0][1]; q[19] = extrinsic_curvature[0][2]; - q[20] = extrinsic_curvature[1][0]; q[21] = extrinsic_curvature[1][1]; q[22] = extrinsic_curvature[1][2]; - q[23] = extrinsic_curvature[2][0]; q[24] = extrinsic_curvature[2][1]; q[25] = extrinsic_curvature[2][2]; + q[5] = shift[0]; + q[6] = shift[1]; + q[7] = shift[2]; + + q[8] = spatial_metric[0][0]; + q[9] = spatial_metric[0][1]; + q[10] = spatial_metric[0][2]; + q[11] = spatial_metric[1][0]; + q[12] = spatial_metric[1][1]; + q[13] = spatial_metric[1][2]; + q[14] = spatial_metric[2][0]; + q[15] = spatial_metric[2][1]; + q[16] = spatial_metric[2][2]; + + q[17] = extrinsic_curvature[0][0]; + q[18] = extrinsic_curvature[0][1]; + q[19] = extrinsic_curvature[0][2]; + q[20] = extrinsic_curvature[1][0]; + q[21] = extrinsic_curvature[1][1]; + q[22] = extrinsic_curvature[1][2]; + q[23] = extrinsic_curvature[2][0]; + q[24] = extrinsic_curvature[2][1]; + q[25] = extrinsic_curvature[2][2]; q[26] = 1.0; - q[27] = lapse_der[0]; q[28] = lapse_der[1]; q[29] = lapse_der[2]; - q[30] = shift_der[0][0]; q[31] = shift_der[0][1]; q[32] = shift_der[0][2]; - q[33] = shift_der[1][0]; q[34] = shift_der[1][1]; q[35] = shift_der[1][2]; - q[36] = shift_der[2][0]; q[37] = shift_der[2][1]; q[38] = shift_der[2][2]; - - q[39] = spatial_metric_der[0][0][0]; q[40] = spatial_metric_der[0][0][1]; q[41] = spatial_metric_der[0][0][2]; - q[42] = spatial_metric_der[0][1][0]; q[43] = spatial_metric_der[0][1][1]; q[44] = spatial_metric_der[0][1][2]; - q[45] = spatial_metric_der[0][2][0]; q[46] = spatial_metric_der[0][2][1]; q[47] = spatial_metric_der[0][2][2]; - - q[48] = spatial_metric_der[1][0][0]; q[49] = spatial_metric_der[1][0][1]; q[50] = spatial_metric_der[1][0][2]; - q[51] = spatial_metric_der[1][1][0]; q[52] = spatial_metric_der[1][1][1]; q[53] = spatial_metric_der[1][1][2]; - q[54] = spatial_metric_der[1][2][0]; q[55] = spatial_metric_der[1][2][1]; q[56] = spatial_metric_der[1][2][2]; - - q[57] = spatial_metric_der[2][0][0]; q[58] = spatial_metric_der[2][0][1]; q[59] = spatial_metric_der[2][0][2]; - q[60] = spatial_metric_der[2][1][0]; q[61] = spatial_metric_der[2][1][1]; q[62] = spatial_metric_der[2][1][2]; - q[63] = spatial_metric_der[2][2][0]; q[64] = spatial_metric_der[2][2][1]; q[65] = spatial_metric_der[2][2][2]; + q[27] = lapse_der[0]; + q[28] = lapse_der[1]; + q[29] = lapse_der[2]; + q[30] = shift_der[0][0]; + q[31] = shift_der[0][1]; + q[32] = shift_der[0][2]; + q[33] = shift_der[1][0]; + q[34] = shift_der[1][1]; + q[35] = shift_der[1][2]; + q[36] = shift_der[2][0]; + q[37] = shift_der[2][1]; + q[38] = shift_der[2][2]; + + q[39] = spatial_metric_der[0][0][0]; + q[40] = spatial_metric_der[0][0][1]; + q[41] = spatial_metric_der[0][0][2]; + q[42] = spatial_metric_der[0][1][0]; + q[43] = spatial_metric_der[0][1][1]; + q[44] = spatial_metric_der[0][1][2]; + q[45] = spatial_metric_der[0][2][0]; + q[46] = spatial_metric_der[0][2][1]; + q[47] = spatial_metric_der[0][2][2]; + + q[48] = spatial_metric_der[1][0][0]; + q[49] = spatial_metric_der[1][0][1]; + q[50] = spatial_metric_der[1][0][2]; + q[51] = spatial_metric_der[1][1][0]; + q[52] = spatial_metric_der[1][1][1]; + q[53] = spatial_metric_der[1][1][2]; + q[54] = spatial_metric_der[1][2][0]; + q[55] = spatial_metric_der[1][2][1]; + q[56] = spatial_metric_der[1][2][2]; + + q[57] = spatial_metric_der[2][0][0]; + q[58] = spatial_metric_der[2][0][1]; + q[59] = spatial_metric_der[2][0][2]; + q[60] = spatial_metric_der[2][1][0]; + q[61] = spatial_metric_der[2][1][1]; + q[62] = spatial_metric_der[2][1][2]; + q[63] = spatial_metric_der[2][2][0]; + q[64] = spatial_metric_der[2][2][1]; + q[65] = spatial_metric_der[2][2][2]; q[66] = 0.0; - q[67] = x; q[68] = y; q[69] = 0.0; + q[67] = x; + q[68] = y; + q[69] = 0.0; double prims[70]; gkyl_gr_ultra_rel_euler_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); // Calculate the fluxes using the reconstructed primitive variables, for now. -JG rho = prims[0]; - vel[0] = prims[1]; vel[1] = prims[2]; vel[2] = prims[3]; + vel[0] = prims[1]; + vel[1] = prims[2]; + vel[2] = prims[3]; p = (gas_gamma - 1.0) * rho; lapse = prims[4]; - shift[0] = prims[5]; shift[1] = prims[6]; shift[2] = prims[7]; + shift[0] = prims[5]; + shift[1] = prims[6]; + shift[2] = prims[7]; double fluxes[3][4] = { - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p) }, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[70], flux_local[70], flux[70]; for (int d = 0; d < 3; d++) { - gr_ultra_rel_euler->rotate_to_local_func(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], q, q_local); + gr_ultra_rel_euler->rotate_to_local_func( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_gr_ultra_rel_euler_flux(gas_gamma, q_local, flux_local); - gr_ultra_rel_euler->rotate_to_global_func(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], flux_local, flux); + gr_ultra_rel_euler->rotate_to_global_func( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 4; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } @@ -384,7 +504,7 @@ test_gr_ultra_rel_euler_basic_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[70], q1[70]; @@ -392,7 +512,7 @@ test_gr_ultra_rel_euler_basic_schwarzschild_ho() gr_ultra_rel_euler->riem_to_cons(gr_ultra_rel_euler, q_local, w1, q1); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -401,7 +521,7 @@ test_gr_ultra_rel_euler_basic_schwarzschild_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -421,17 +541,17 @@ test_gr_ultra_rel_euler_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_ultra_rel_euler_basic_kerr_ho() +void test_gr_ultra_rel_euler_basic_kerr_ho() { double gas_gamma = 2.0; // Currently this test only passes for very low (a = 0.2) values of the black hole spin. // Need to track down why the flux errors appear at higher spin values. -JG struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.2, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler = + gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_ultra_rel_euler->num_equations == 70 ); - TEST_CHECK( gr_ultra_rel_euler->num_waves == 2 ); + TEST_CHECK(gr_ultra_rel_euler->num_equations == 70); + TEST_CHECK(gr_ultra_rel_euler->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -445,25 +565,25 @@ test_gr_ultra_rel_euler_basic_kerr_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -474,16 +594,28 @@ test_gr_ultra_rel_euler_basic_kerr_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -502,94 +634,144 @@ test_gr_ultra_rel_euler_basic_kerr_ho() q[3] = sqrt(spatial_det) * (rho + p) * (W * W) * w; q[4] = lapse; - q[5] = shift[0]; q[6] = shift[1]; q[7] = shift[2]; - - q[8] = spatial_metric[0][0]; q[9] = spatial_metric[0][1]; q[10] = spatial_metric[0][2]; - q[11] = spatial_metric[1][0]; q[12] = spatial_metric[1][1]; q[13] = spatial_metric[1][2]; - q[14] = spatial_metric[2][0]; q[15] = spatial_metric[2][1]; q[16] = spatial_metric[2][2]; - - q[17] = extrinsic_curvature[0][0]; q[18] = extrinsic_curvature[0][1]; q[19] = extrinsic_curvature[0][2]; - q[20] = extrinsic_curvature[1][0]; q[21] = extrinsic_curvature[1][1]; q[22] = extrinsic_curvature[1][2]; - q[23] = extrinsic_curvature[2][0]; q[24] = extrinsic_curvature[2][1]; q[25] = extrinsic_curvature[2][2]; + q[5] = shift[0]; + q[6] = shift[1]; + q[7] = shift[2]; + + q[8] = spatial_metric[0][0]; + q[9] = spatial_metric[0][1]; + q[10] = spatial_metric[0][2]; + q[11] = spatial_metric[1][0]; + q[12] = spatial_metric[1][1]; + q[13] = spatial_metric[1][2]; + q[14] = spatial_metric[2][0]; + q[15] = spatial_metric[2][1]; + q[16] = spatial_metric[2][2]; + + q[17] = extrinsic_curvature[0][0]; + q[18] = extrinsic_curvature[0][1]; + q[19] = extrinsic_curvature[0][2]; + q[20] = extrinsic_curvature[1][0]; + q[21] = extrinsic_curvature[1][1]; + q[22] = extrinsic_curvature[1][2]; + q[23] = extrinsic_curvature[2][0]; + q[24] = extrinsic_curvature[2][1]; + q[25] = extrinsic_curvature[2][2]; q[26] = 1.0; - q[27] = lapse_der[0]; q[28] = lapse_der[1]; q[29] = lapse_der[2]; - q[30] = shift_der[0][0]; q[31] = shift_der[0][1]; q[32] = shift_der[0][2]; - q[33] = shift_der[1][0]; q[34] = shift_der[1][1]; q[35] = shift_der[1][2]; - q[36] = shift_der[2][0]; q[37] = shift_der[2][1]; q[38] = shift_der[2][2]; - - q[39] = spatial_metric_der[0][0][0]; q[40] = spatial_metric_der[0][0][1]; q[41] = spatial_metric_der[0][0][2]; - q[42] = spatial_metric_der[0][1][0]; q[43] = spatial_metric_der[0][1][1]; q[44] = spatial_metric_der[0][1][2]; - q[45] = spatial_metric_der[0][2][0]; q[46] = spatial_metric_der[0][2][1]; q[47] = spatial_metric_der[0][2][2]; - - q[48] = spatial_metric_der[1][0][0]; q[49] = spatial_metric_der[1][0][1]; q[50] = spatial_metric_der[1][0][2]; - q[51] = spatial_metric_der[1][1][0]; q[52] = spatial_metric_der[1][1][1]; q[53] = spatial_metric_der[1][1][2]; - q[54] = spatial_metric_der[1][2][0]; q[55] = spatial_metric_der[1][2][1]; q[56] = spatial_metric_der[1][2][2]; - - q[57] = spatial_metric_der[2][0][0]; q[58] = spatial_metric_der[2][0][1]; q[59] = spatial_metric_der[2][0][2]; - q[60] = spatial_metric_der[2][1][0]; q[61] = spatial_metric_der[2][1][1]; q[62] = spatial_metric_der[2][1][2]; - q[63] = spatial_metric_der[2][2][0]; q[64] = spatial_metric_der[2][2][1]; q[65] = spatial_metric_der[2][2][2]; + q[27] = lapse_der[0]; + q[28] = lapse_der[1]; + q[29] = lapse_der[2]; + q[30] = shift_der[0][0]; + q[31] = shift_der[0][1]; + q[32] = shift_der[0][2]; + q[33] = shift_der[1][0]; + q[34] = shift_der[1][1]; + q[35] = shift_der[1][2]; + q[36] = shift_der[2][0]; + q[37] = shift_der[2][1]; + q[38] = shift_der[2][2]; + + q[39] = spatial_metric_der[0][0][0]; + q[40] = spatial_metric_der[0][0][1]; + q[41] = spatial_metric_der[0][0][2]; + q[42] = spatial_metric_der[0][1][0]; + q[43] = spatial_metric_der[0][1][1]; + q[44] = spatial_metric_der[0][1][2]; + q[45] = spatial_metric_der[0][2][0]; + q[46] = spatial_metric_der[0][2][1]; + q[47] = spatial_metric_der[0][2][2]; + + q[48] = spatial_metric_der[1][0][0]; + q[49] = spatial_metric_der[1][0][1]; + q[50] = spatial_metric_der[1][0][2]; + q[51] = spatial_metric_der[1][1][0]; + q[52] = spatial_metric_der[1][1][1]; + q[53] = spatial_metric_der[1][1][2]; + q[54] = spatial_metric_der[1][2][0]; + q[55] = spatial_metric_der[1][2][1]; + q[56] = spatial_metric_der[1][2][2]; + + q[57] = spatial_metric_der[2][0][0]; + q[58] = spatial_metric_der[2][0][1]; + q[59] = spatial_metric_der[2][0][2]; + q[60] = spatial_metric_der[2][1][0]; + q[61] = spatial_metric_der[2][1][1]; + q[62] = spatial_metric_der[2][1][2]; + q[63] = spatial_metric_der[2][2][0]; + q[64] = spatial_metric_der[2][2][1]; + q[65] = spatial_metric_der[2][2][2]; q[66] = 0.0; - q[67] = x; q[68] = y; q[69] = 0.0; + q[67] = x; + q[68] = y; + q[69] = 0.0; double prims[70]; gkyl_gr_ultra_rel_euler_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); // Calculate the fluxes using the reconstructed primitive variables, for now. -JG rho = prims[0]; - vel[0] = prims[1]; vel[1] = prims[2]; vel[2] = prims[3]; + vel[0] = prims[1]; + vel[1] = prims[2]; + vel[2] = prims[3]; p = (gas_gamma - 1.0) * rho; lapse = prims[4]; - shift[0] = prims[5]; shift[1] = prims[6]; shift[2] = prims[7]; + shift[0] = prims[5]; + shift[1] = prims[6]; + shift[2] = prims[7]; double fluxes[3][4] = { - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p) }, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[70], flux_local[70], flux[70]; for (int d = 0; d < 3; d++) { - gr_ultra_rel_euler->rotate_to_local_func(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], q, q_local); + gr_ultra_rel_euler->rotate_to_local_func( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_gr_ultra_rel_euler_flux(gas_gamma, q_local, flux_local); - gr_ultra_rel_euler->rotate_to_global_func(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], flux_local, flux); + gr_ultra_rel_euler->rotate_to_global_func( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 4; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } @@ -599,7 +781,7 @@ test_gr_ultra_rel_euler_basic_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[70], q1[70]; @@ -607,16 +789,16 @@ test_gr_ultra_rel_euler_basic_kerr_ho() gr_ultra_rel_euler->riem_to_cons(gr_ultra_rel_euler, q_local, w1, q1); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } - + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -636,12 +818,12 @@ test_gr_ultra_rel_euler_basic_kerr_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_ultra_rel_euler_waves_minkowski_ho() +void test_gr_ultra_rel_euler_waves_minkowski_ho() { double gas_gamma = 2.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler = + gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -658,10 +840,10 @@ test_gr_ultra_rel_euler_waves_minkowski_ho() double *shift_l = gkyl_malloc(sizeof(double[3])); double *shift_r = gkyl_malloc(sizeof(double[3])); - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -671,18 +853,18 @@ test_gr_ultra_rel_euler_waves_minkowski_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -699,20 +881,46 @@ test_gr_ultra_rel_euler_waves_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -732,37 +940,79 @@ test_gr_ultra_rel_euler_waves_minkowski_ho() ql[3] = sqrt(spatial_det_l) * (rho_l + p_l) * (W_l * W_l) * w_l; ql[4] = lapse_l; - ql[5] = shift_l[0]; ql[6] = shift_l[1]; ql[7] = shift_l[2]; - - ql[8] = spatial_metric_l[0][0]; ql[9] = spatial_metric_l[0][1]; ql[10] = spatial_metric_l[0][2]; - ql[11] = spatial_metric_l[1][0]; ql[12] = spatial_metric_l[1][1]; ql[13] = spatial_metric_l[1][2]; - ql[14] = spatial_metric_l[2][0]; ql[15] = spatial_metric_l[2][1]; ql[16] = spatial_metric_l[2][2]; - - ql[17] = extrinsic_curvature_l[0][0]; ql[18] = extrinsic_curvature_l[0][1]; ql[19] = extrinsic_curvature_l[0][2]; - ql[20] = extrinsic_curvature_l[1][0]; ql[21] = extrinsic_curvature_l[1][1]; ql[22] = extrinsic_curvature_l[1][2]; - ql[23] = extrinsic_curvature_l[2][0]; ql[24] = extrinsic_curvature_l[2][1]; ql[25] = extrinsic_curvature_l[2][2]; + ql[5] = shift_l[0]; + ql[6] = shift_l[1]; + ql[7] = shift_l[2]; + + ql[8] = spatial_metric_l[0][0]; + ql[9] = spatial_metric_l[0][1]; + ql[10] = spatial_metric_l[0][2]; + ql[11] = spatial_metric_l[1][0]; + ql[12] = spatial_metric_l[1][1]; + ql[13] = spatial_metric_l[1][2]; + ql[14] = spatial_metric_l[2][0]; + ql[15] = spatial_metric_l[2][1]; + ql[16] = spatial_metric_l[2][2]; + + ql[17] = extrinsic_curvature_l[0][0]; + ql[18] = extrinsic_curvature_l[0][1]; + ql[19] = extrinsic_curvature_l[0][2]; + ql[20] = extrinsic_curvature_l[1][0]; + ql[21] = extrinsic_curvature_l[1][1]; + ql[22] = extrinsic_curvature_l[1][2]; + ql[23] = extrinsic_curvature_l[2][0]; + ql[24] = extrinsic_curvature_l[2][1]; + ql[25] = extrinsic_curvature_l[2][2]; ql[26] = 1.0; - ql[27] = lapse_der_l[0]; ql[28] = lapse_der_l[1]; ql[29] = lapse_der_l[2]; - ql[30] = shift_der_l[0][0]; ql[31] = shift_der_l[0][1]; ql[32] = shift_der_l[0][2]; - ql[33] = shift_der_l[1][0]; ql[34] = shift_der_l[1][1]; ql[35] = shift_der_l[1][2]; - ql[36] = shift_der_l[2][0]; ql[37] = shift_der_l[2][1]; ql[38] = shift_der_l[2][2]; - - ql[39] = spatial_metric_der_l[0][0][0]; ql[40] = spatial_metric_der_l[0][0][1]; ql[41] = spatial_metric_der_l[0][0][2]; - ql[42] = spatial_metric_der_l[0][1][0]; ql[43] = spatial_metric_der_l[0][1][1]; ql[44] = spatial_metric_der_l[0][1][2]; - ql[45] = spatial_metric_der_l[0][2][0]; ql[46] = spatial_metric_der_l[0][2][1]; ql[47] = spatial_metric_der_l[0][2][2]; - - ql[48] = spatial_metric_der_l[1][0][0]; ql[49] = spatial_metric_der_l[1][0][1]; ql[50] = spatial_metric_der_l[1][0][2]; - ql[51] = spatial_metric_der_l[1][1][0]; ql[52] = spatial_metric_der_l[1][1][1]; ql[53] = spatial_metric_der_l[1][1][2]; - ql[54] = spatial_metric_der_l[1][2][0]; ql[55] = spatial_metric_der_l[1][2][1]; ql[56] = spatial_metric_der_l[1][2][2]; - - ql[57] = spatial_metric_der_l[2][0][0]; ql[58] = spatial_metric_der_l[2][0][1]; ql[59] = spatial_metric_der_l[2][0][2]; - ql[60] = spatial_metric_der_l[2][1][0]; ql[61] = spatial_metric_der_l[2][1][1]; ql[62] = spatial_metric_der_l[2][1][2]; - ql[63] = spatial_metric_der_l[2][2][0]; ql[64] = spatial_metric_der_l[2][2][1]; ql[65] = spatial_metric_der_l[2][2][2]; + ql[27] = lapse_der_l[0]; + ql[28] = lapse_der_l[1]; + ql[29] = lapse_der_l[2]; + ql[30] = shift_der_l[0][0]; + ql[31] = shift_der_l[0][1]; + ql[32] = shift_der_l[0][2]; + ql[33] = shift_der_l[1][0]; + ql[34] = shift_der_l[1][1]; + ql[35] = shift_der_l[1][2]; + ql[36] = shift_der_l[2][0]; + ql[37] = shift_der_l[2][1]; + ql[38] = shift_der_l[2][2]; + + ql[39] = spatial_metric_der_l[0][0][0]; + ql[40] = spatial_metric_der_l[0][0][1]; + ql[41] = spatial_metric_der_l[0][0][2]; + ql[42] = spatial_metric_der_l[0][1][0]; + ql[43] = spatial_metric_der_l[0][1][1]; + ql[44] = spatial_metric_der_l[0][1][2]; + ql[45] = spatial_metric_der_l[0][2][0]; + ql[46] = spatial_metric_der_l[0][2][1]; + ql[47] = spatial_metric_der_l[0][2][2]; + + ql[48] = spatial_metric_der_l[1][0][0]; + ql[49] = spatial_metric_der_l[1][0][1]; + ql[50] = spatial_metric_der_l[1][0][2]; + ql[51] = spatial_metric_der_l[1][1][0]; + ql[52] = spatial_metric_der_l[1][1][1]; + ql[53] = spatial_metric_der_l[1][1][2]; + ql[54] = spatial_metric_der_l[1][2][0]; + ql[55] = spatial_metric_der_l[1][2][1]; + ql[56] = spatial_metric_der_l[1][2][2]; + + ql[57] = spatial_metric_der_l[2][0][0]; + ql[58] = spatial_metric_der_l[2][0][1]; + ql[59] = spatial_metric_der_l[2][0][2]; + ql[60] = spatial_metric_der_l[2][1][0]; + ql[61] = spatial_metric_der_l[2][1][1]; + ql[62] = spatial_metric_der_l[2][1][2]; + ql[63] = spatial_metric_der_l[2][2][0]; + ql[64] = spatial_metric_der_l[2][2][1]; + ql[65] = spatial_metric_der_l[2][2][2]; ql[66] = 0.0; - ql[67] = x - 0.5; ql[68] = y; ql[69] = 0.0; + ql[67] = x - 0.5; + ql[68] = y; + ql[69] = 0.0; qr[0] = sqrt(spatial_det_r) * (((rho_r + p_r) * (W_r * W_r)) - p_r); qr[1] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * u_r; @@ -770,55 +1020,85 @@ test_gr_ultra_rel_euler_waves_minkowski_ho() qr[3] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * w_r; qr[4] = lapse_r; - qr[5] = shift_r[0]; qr[6] = shift_r[1]; qr[7] = shift_r[2]; - - qr[8] = spatial_metric_r[0][0]; qr[9] = spatial_metric_r[0][1]; qr[10] = spatial_metric_r[0][2]; - qr[11] = spatial_metric_r[1][0]; qr[12] = spatial_metric_r[1][1]; qr[13] = spatial_metric_r[1][2]; - qr[14] = spatial_metric_r[2][0]; qr[15] = spatial_metric_r[2][1]; qr[16] = spatial_metric_r[2][2]; - - qr[17] = extrinsic_curvature_r[0][0]; qr[18] = extrinsic_curvature_r[0][1]; qr[19] = extrinsic_curvature_r[0][2]; - qr[20] = extrinsic_curvature_r[1][0]; qr[21] = extrinsic_curvature_r[1][1]; qr[22] = extrinsic_curvature_r[1][2]; - qr[23] = extrinsic_curvature_r[2][0]; qr[24] = extrinsic_curvature_r[2][1]; qr[25] = extrinsic_curvature_r[2][2]; + qr[5] = shift_r[0]; + qr[6] = shift_r[1]; + qr[7] = shift_r[2]; + + qr[8] = spatial_metric_r[0][0]; + qr[9] = spatial_metric_r[0][1]; + qr[10] = spatial_metric_r[0][2]; + qr[11] = spatial_metric_r[1][0]; + qr[12] = spatial_metric_r[1][1]; + qr[13] = spatial_metric_r[1][2]; + qr[14] = spatial_metric_r[2][0]; + qr[15] = spatial_metric_r[2][1]; + qr[16] = spatial_metric_r[2][2]; + + qr[17] = extrinsic_curvature_r[0][0]; + qr[18] = extrinsic_curvature_r[0][1]; + qr[19] = extrinsic_curvature_r[0][2]; + qr[20] = extrinsic_curvature_r[1][0]; + qr[21] = extrinsic_curvature_r[1][1]; + qr[22] = extrinsic_curvature_r[1][2]; + qr[23] = extrinsic_curvature_r[2][0]; + qr[24] = extrinsic_curvature_r[2][1]; + qr[25] = extrinsic_curvature_r[2][2]; qr[26] = 1.0; - qr[27] = lapse_der_r[0]; qr[28] = lapse_der_r[1]; qr[29] = lapse_der_r[2]; - qr[30] = shift_der_r[0][0]; qr[31] = shift_der_r[0][1]; qr[32] = shift_der_r[0][2]; - qr[33] = shift_der_r[1][0]; qr[34] = shift_der_r[1][1]; qr[35] = shift_der_r[1][2]; - qr[36] = shift_der_r[2][0]; qr[37] = shift_der_r[2][1]; qr[38] = shift_der_r[2][2]; - - qr[39] = spatial_metric_der_r[0][0][0]; qr[40] = spatial_metric_der_r[0][0][1]; qr[41] = spatial_metric_der_r[0][0][2]; - qr[42] = spatial_metric_der_r[0][1][0]; qr[43] = spatial_metric_der_r[0][1][1]; qr[44] = spatial_metric_der_r[0][1][2]; - qr[45] = spatial_metric_der_r[0][2][0]; qr[46] = spatial_metric_der_r[0][2][1]; qr[47] = spatial_metric_der_r[0][2][2]; - - qr[48] = spatial_metric_der_r[1][0][0]; qr[49] = spatial_metric_der_r[1][0][1]; qr[50] = spatial_metric_der_r[1][0][2]; - qr[51] = spatial_metric_der_r[1][1][0]; qr[52] = spatial_metric_der_r[1][1][1]; qr[53] = spatial_metric_der_r[1][1][2]; - qr[54] = spatial_metric_der_r[1][2][0]; qr[55] = spatial_metric_der_r[1][2][1]; qr[56] = spatial_metric_der_r[1][2][2]; - - qr[57] = spatial_metric_der_r[2][0][0]; qr[58] = spatial_metric_der_r[2][0][1]; qr[59] = spatial_metric_der_r[2][0][2]; - qr[60] = spatial_metric_der_r[2][1][0]; qr[61] = spatial_metric_der_r[2][1][1]; qr[62] = spatial_metric_der_r[2][1][2]; - qr[63] = spatial_metric_der_r[2][2][0]; qr[64] = spatial_metric_der_r[2][2][1]; qr[65] = spatial_metric_der_r[2][2][2]; + qr[27] = lapse_der_r[0]; + qr[28] = lapse_der_r[1]; + qr[29] = lapse_der_r[2]; + qr[30] = shift_der_r[0][0]; + qr[31] = shift_der_r[0][1]; + qr[32] = shift_der_r[0][2]; + qr[33] = shift_der_r[1][0]; + qr[34] = shift_der_r[1][1]; + qr[35] = shift_der_r[1][2]; + qr[36] = shift_der_r[2][0]; + qr[37] = shift_der_r[2][1]; + qr[38] = shift_der_r[2][2]; + + qr[39] = spatial_metric_der_r[0][0][0]; + qr[40] = spatial_metric_der_r[0][0][1]; + qr[41] = spatial_metric_der_r[0][0][2]; + qr[42] = spatial_metric_der_r[0][1][0]; + qr[43] = spatial_metric_der_r[0][1][1]; + qr[44] = spatial_metric_der_r[0][1][2]; + qr[45] = spatial_metric_der_r[0][2][0]; + qr[46] = spatial_metric_der_r[0][2][1]; + qr[47] = spatial_metric_der_r[0][2][2]; + + qr[48] = spatial_metric_der_r[1][0][0]; + qr[49] = spatial_metric_der_r[1][0][1]; + qr[50] = spatial_metric_der_r[1][0][2]; + qr[51] = spatial_metric_der_r[1][1][0]; + qr[52] = spatial_metric_der_r[1][1][1]; + qr[53] = spatial_metric_der_r[1][1][2]; + qr[54] = spatial_metric_der_r[1][2][0]; + qr[55] = spatial_metric_der_r[1][2][1]; + qr[56] = spatial_metric_der_r[1][2][2]; + + qr[57] = spatial_metric_der_r[2][0][0]; + qr[58] = spatial_metric_der_r[2][0][1]; + qr[59] = spatial_metric_der_r[2][0][2]; + qr[60] = spatial_metric_der_r[2][1][0]; + qr[61] = spatial_metric_der_r[2][1][1]; + qr[62] = spatial_metric_der_r[2][1][2]; + qr[63] = spatial_metric_der_r[2][2][0]; + qr[64] = spatial_metric_der_r[2][2][1]; + qr[65] = spatial_metric_der_r[2][2][2]; qr[66] = 0.0; - qr[67] = x + 0.5; qr[68] = y; qr[69] = 0.0; + qr[67] = x + 0.5; + qr[68] = y; + qr[69] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 70], waves_local[3 * 70]; @@ -832,18 +1112,30 @@ test_gr_ultra_rel_euler_waves_minkowski_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[70], amdq_local[70]; - gkyl_wv_eqn_qfluct(gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 70], &waves[i * 70]); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 70], &waves[i * 70] + ); } double apdq[70], amdq[70]; - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); double fl_local[70], fr_local[70]; gkyl_gr_ultra_rel_euler_flux(gas_gamma, ql_local, fl_local); @@ -854,7 +1146,7 @@ test_gr_ultra_rel_euler_waves_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } @@ -865,7 +1157,7 @@ test_gr_ultra_rel_euler_waves_minkowski_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -894,12 +1186,12 @@ test_gr_ultra_rel_euler_waves_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_ultra_rel_euler_waves_schwarzschild_ho() +void test_gr_ultra_rel_euler_waves_schwarzschild_ho() { double gas_gamma = 2.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler = + gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -917,10 +1209,10 @@ test_gr_ultra_rel_euler_waves_schwarzschild_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -930,18 +1222,18 @@ test_gr_ultra_rel_euler_waves_schwarzschild_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -960,20 +1252,46 @@ test_gr_ultra_rel_euler_waves_schwarzschild_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -985,7 +1303,7 @@ test_gr_ultra_rel_euler_waves_schwarzschild_ho() double W_l = 1.0 / sqrt(1.0 - v_sq_l); double W_r = 1.0 / sqrt(1.0 - v_sq_r); - + if (!in_excision_region_l && !in_excision_region_r) { double ql[70], qr[70]; ql[0] = sqrt(spatial_det_l) * (((rho_l + p_l) * (W_l * W_l)) - p_l); @@ -994,37 +1312,79 @@ test_gr_ultra_rel_euler_waves_schwarzschild_ho() ql[3] = sqrt(spatial_det_l) * (rho_l + p_l) * (W_l * W_l) * w_l; ql[4] = lapse_l; - ql[5] = shift_l[0]; ql[6] = shift_l[1]; ql[7] = shift_l[2]; - - ql[8] = spatial_metric_l[0][0]; ql[9] = spatial_metric_l[0][1]; ql[10] = spatial_metric_l[0][2]; - ql[11] = spatial_metric_l[1][0]; ql[12] = spatial_metric_l[1][1]; ql[13] = spatial_metric_l[1][2]; - ql[14] = spatial_metric_l[2][0]; ql[15] = spatial_metric_l[2][1]; ql[16] = spatial_metric_l[2][2]; - - ql[17] = extrinsic_curvature_l[0][0]; ql[18] = extrinsic_curvature_l[0][1]; ql[19] = extrinsic_curvature_l[0][2]; - ql[20] = extrinsic_curvature_l[1][0]; ql[21] = extrinsic_curvature_l[1][1]; ql[22] = extrinsic_curvature_l[1][2]; - ql[23] = extrinsic_curvature_l[2][0]; ql[24] = extrinsic_curvature_l[2][1]; ql[25] = extrinsic_curvature_l[2][2]; + ql[5] = shift_l[0]; + ql[6] = shift_l[1]; + ql[7] = shift_l[2]; + + ql[8] = spatial_metric_l[0][0]; + ql[9] = spatial_metric_l[0][1]; + ql[10] = spatial_metric_l[0][2]; + ql[11] = spatial_metric_l[1][0]; + ql[12] = spatial_metric_l[1][1]; + ql[13] = spatial_metric_l[1][2]; + ql[14] = spatial_metric_l[2][0]; + ql[15] = spatial_metric_l[2][1]; + ql[16] = spatial_metric_l[2][2]; + + ql[17] = extrinsic_curvature_l[0][0]; + ql[18] = extrinsic_curvature_l[0][1]; + ql[19] = extrinsic_curvature_l[0][2]; + ql[20] = extrinsic_curvature_l[1][0]; + ql[21] = extrinsic_curvature_l[1][1]; + ql[22] = extrinsic_curvature_l[1][2]; + ql[23] = extrinsic_curvature_l[2][0]; + ql[24] = extrinsic_curvature_l[2][1]; + ql[25] = extrinsic_curvature_l[2][2]; ql[26] = 1.0; - ql[27] = lapse_der_l[0]; ql[28] = lapse_der_l[1]; ql[29] = lapse_der_l[2]; - ql[30] = shift_der_l[0][0]; ql[31] = shift_der_l[0][1]; ql[32] = shift_der_l[0][2]; - ql[33] = shift_der_l[1][0]; ql[34] = shift_der_l[1][1]; ql[35] = shift_der_l[1][2]; - ql[36] = shift_der_l[2][0]; ql[37] = shift_der_l[2][1]; ql[38] = shift_der_l[2][2]; - - ql[39] = spatial_metric_der_l[0][0][0]; ql[40] = spatial_metric_der_l[0][0][1]; ql[41] = spatial_metric_der_l[0][0][2]; - ql[42] = spatial_metric_der_l[0][1][0]; ql[43] = spatial_metric_der_l[0][1][1]; ql[44] = spatial_metric_der_l[0][1][2]; - ql[45] = spatial_metric_der_l[0][2][0]; ql[46] = spatial_metric_der_l[0][2][1]; ql[47] = spatial_metric_der_l[0][2][2]; - - ql[48] = spatial_metric_der_l[1][0][0]; ql[49] = spatial_metric_der_l[1][0][1]; ql[50] = spatial_metric_der_l[1][0][2]; - ql[51] = spatial_metric_der_l[1][1][0]; ql[52] = spatial_metric_der_l[1][1][1]; ql[53] = spatial_metric_der_l[1][1][2]; - ql[54] = spatial_metric_der_l[1][2][0]; ql[55] = spatial_metric_der_l[1][2][1]; ql[56] = spatial_metric_der_l[1][2][2]; - - ql[57] = spatial_metric_der_l[2][0][0]; ql[58] = spatial_metric_der_l[2][0][1]; ql[59] = spatial_metric_der_l[2][0][2]; - ql[60] = spatial_metric_der_l[2][1][0]; ql[61] = spatial_metric_der_l[2][1][1]; ql[62] = spatial_metric_der_l[2][1][2]; - ql[63] = spatial_metric_der_l[2][2][0]; ql[64] = spatial_metric_der_l[2][2][1]; ql[65] = spatial_metric_der_l[2][2][2]; + ql[27] = lapse_der_l[0]; + ql[28] = lapse_der_l[1]; + ql[29] = lapse_der_l[2]; + ql[30] = shift_der_l[0][0]; + ql[31] = shift_der_l[0][1]; + ql[32] = shift_der_l[0][2]; + ql[33] = shift_der_l[1][0]; + ql[34] = shift_der_l[1][1]; + ql[35] = shift_der_l[1][2]; + ql[36] = shift_der_l[2][0]; + ql[37] = shift_der_l[2][1]; + ql[38] = shift_der_l[2][2]; + + ql[39] = spatial_metric_der_l[0][0][0]; + ql[40] = spatial_metric_der_l[0][0][1]; + ql[41] = spatial_metric_der_l[0][0][2]; + ql[42] = spatial_metric_der_l[0][1][0]; + ql[43] = spatial_metric_der_l[0][1][1]; + ql[44] = spatial_metric_der_l[0][1][2]; + ql[45] = spatial_metric_der_l[0][2][0]; + ql[46] = spatial_metric_der_l[0][2][1]; + ql[47] = spatial_metric_der_l[0][2][2]; + + ql[48] = spatial_metric_der_l[1][0][0]; + ql[49] = spatial_metric_der_l[1][0][1]; + ql[50] = spatial_metric_der_l[1][0][2]; + ql[51] = spatial_metric_der_l[1][1][0]; + ql[52] = spatial_metric_der_l[1][1][1]; + ql[53] = spatial_metric_der_l[1][1][2]; + ql[54] = spatial_metric_der_l[1][2][0]; + ql[55] = spatial_metric_der_l[1][2][1]; + ql[56] = spatial_metric_der_l[1][2][2]; + + ql[57] = spatial_metric_der_l[2][0][0]; + ql[58] = spatial_metric_der_l[2][0][1]; + ql[59] = spatial_metric_der_l[2][0][2]; + ql[60] = spatial_metric_der_l[2][1][0]; + ql[61] = spatial_metric_der_l[2][1][1]; + ql[62] = spatial_metric_der_l[2][1][2]; + ql[63] = spatial_metric_der_l[2][2][0]; + ql[64] = spatial_metric_der_l[2][2][1]; + ql[65] = spatial_metric_der_l[2][2][2]; ql[66] = 0.0; - ql[67] = x - 0.5; ql[68] = y; ql[69] = 0.0; + ql[67] = x - 0.5; + ql[68] = y; + ql[69] = 0.0; qr[0] = sqrt(spatial_det_r) * (((rho_r + p_r) * (W_r * W_r)) - p_r); qr[1] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * u_r; @@ -1032,55 +1392,85 @@ test_gr_ultra_rel_euler_waves_schwarzschild_ho() qr[3] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * w_r; qr[4] = lapse_r; - qr[5] = shift_r[0]; qr[6] = shift_r[1]; qr[7] = shift_r[2]; - - qr[8] = spatial_metric_r[0][0]; qr[9] = spatial_metric_r[0][1]; qr[10] = spatial_metric_r[0][2]; - qr[11] = spatial_metric_r[1][0]; qr[12] = spatial_metric_r[1][1]; qr[13] = spatial_metric_r[1][2]; - qr[14] = spatial_metric_r[2][0]; qr[15] = spatial_metric_r[2][1]; qr[16] = spatial_metric_r[2][2]; - - qr[17] = extrinsic_curvature_r[0][0]; qr[18] = extrinsic_curvature_r[0][1]; qr[19] = extrinsic_curvature_r[0][2]; - qr[20] = extrinsic_curvature_r[1][0]; qr[21] = extrinsic_curvature_r[1][1]; qr[22] = extrinsic_curvature_r[1][2]; - qr[23] = extrinsic_curvature_r[2][0]; qr[24] = extrinsic_curvature_r[2][1]; qr[25] = extrinsic_curvature_r[2][2]; + qr[5] = shift_r[0]; + qr[6] = shift_r[1]; + qr[7] = shift_r[2]; + + qr[8] = spatial_metric_r[0][0]; + qr[9] = spatial_metric_r[0][1]; + qr[10] = spatial_metric_r[0][2]; + qr[11] = spatial_metric_r[1][0]; + qr[12] = spatial_metric_r[1][1]; + qr[13] = spatial_metric_r[1][2]; + qr[14] = spatial_metric_r[2][0]; + qr[15] = spatial_metric_r[2][1]; + qr[16] = spatial_metric_r[2][2]; + + qr[17] = extrinsic_curvature_r[0][0]; + qr[18] = extrinsic_curvature_r[0][1]; + qr[19] = extrinsic_curvature_r[0][2]; + qr[20] = extrinsic_curvature_r[1][0]; + qr[21] = extrinsic_curvature_r[1][1]; + qr[22] = extrinsic_curvature_r[1][2]; + qr[23] = extrinsic_curvature_r[2][0]; + qr[24] = extrinsic_curvature_r[2][1]; + qr[25] = extrinsic_curvature_r[2][2]; qr[26] = 1.0; - qr[27] = lapse_der_r[0]; qr[28] = lapse_der_r[1]; qr[29] = lapse_der_r[2]; - qr[30] = shift_der_r[0][0]; qr[31] = shift_der_r[0][1]; qr[32] = shift_der_r[0][2]; - qr[33] = shift_der_r[1][0]; qr[34] = shift_der_r[1][1]; qr[35] = shift_der_r[1][2]; - qr[36] = shift_der_r[2][0]; qr[37] = shift_der_r[2][1]; qr[38] = shift_der_r[2][2]; - - qr[39] = spatial_metric_der_r[0][0][0]; qr[40] = spatial_metric_der_r[0][0][1]; qr[41] = spatial_metric_der_r[0][0][2]; - qr[42] = spatial_metric_der_r[0][1][0]; qr[43] = spatial_metric_der_r[0][1][1]; qr[44] = spatial_metric_der_r[0][1][2]; - qr[45] = spatial_metric_der_r[0][2][0]; qr[46] = spatial_metric_der_r[0][2][1]; qr[47] = spatial_metric_der_r[0][2][2]; - - qr[48] = spatial_metric_der_r[1][0][0]; qr[49] = spatial_metric_der_r[1][0][1]; qr[50] = spatial_metric_der_r[1][0][2]; - qr[51] = spatial_metric_der_r[1][1][0]; qr[52] = spatial_metric_der_r[1][1][1]; qr[53] = spatial_metric_der_r[1][1][2]; - qr[54] = spatial_metric_der_r[1][2][0]; qr[55] = spatial_metric_der_r[1][2][1]; qr[56] = spatial_metric_der_r[1][2][2]; - - qr[57] = spatial_metric_der_r[2][0][0]; qr[58] = spatial_metric_der_r[2][0][1]; qr[59] = spatial_metric_der_r[2][0][2]; - qr[60] = spatial_metric_der_r[2][1][0]; qr[61] = spatial_metric_der_r[2][1][1]; qr[62] = spatial_metric_der_r[2][1][2]; - qr[63] = spatial_metric_der_r[2][2][0]; qr[64] = spatial_metric_der_r[2][2][1]; qr[65] = spatial_metric_der_r[2][2][2]; + qr[27] = lapse_der_r[0]; + qr[28] = lapse_der_r[1]; + qr[29] = lapse_der_r[2]; + qr[30] = shift_der_r[0][0]; + qr[31] = shift_der_r[0][1]; + qr[32] = shift_der_r[0][2]; + qr[33] = shift_der_r[1][0]; + qr[34] = shift_der_r[1][1]; + qr[35] = shift_der_r[1][2]; + qr[36] = shift_der_r[2][0]; + qr[37] = shift_der_r[2][1]; + qr[38] = shift_der_r[2][2]; + + qr[39] = spatial_metric_der_r[0][0][0]; + qr[40] = spatial_metric_der_r[0][0][1]; + qr[41] = spatial_metric_der_r[0][0][2]; + qr[42] = spatial_metric_der_r[0][1][0]; + qr[43] = spatial_metric_der_r[0][1][1]; + qr[44] = spatial_metric_der_r[0][1][2]; + qr[45] = spatial_metric_der_r[0][2][0]; + qr[46] = spatial_metric_der_r[0][2][1]; + qr[47] = spatial_metric_der_r[0][2][2]; + + qr[48] = spatial_metric_der_r[1][0][0]; + qr[49] = spatial_metric_der_r[1][0][1]; + qr[50] = spatial_metric_der_r[1][0][2]; + qr[51] = spatial_metric_der_r[1][1][0]; + qr[52] = spatial_metric_der_r[1][1][1]; + qr[53] = spatial_metric_der_r[1][1][2]; + qr[54] = spatial_metric_der_r[1][2][0]; + qr[55] = spatial_metric_der_r[1][2][1]; + qr[56] = spatial_metric_der_r[1][2][2]; + + qr[57] = spatial_metric_der_r[2][0][0]; + qr[58] = spatial_metric_der_r[2][0][1]; + qr[59] = spatial_metric_der_r[2][0][2]; + qr[60] = spatial_metric_der_r[2][1][0]; + qr[61] = spatial_metric_der_r[2][1][1]; + qr[62] = spatial_metric_der_r[2][1][2]; + qr[63] = spatial_metric_der_r[2][2][0]; + qr[64] = spatial_metric_der_r[2][2][1]; + qr[65] = spatial_metric_der_r[2][2][2]; qr[66] = 0.0; - qr[67] = x + 0.5; qr[68] = y; qr[69] = 0.0; + qr[67] = x + 0.5; + qr[68] = y; + qr[69] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 70], waves_local[3 * 70]; @@ -1094,18 +1484,30 @@ test_gr_ultra_rel_euler_waves_schwarzschild_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[70], amdq_local[70]; - gkyl_wv_eqn_qfluct(gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 70], &waves[i * 70]); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 70], &waves[i * 70] + ); } double apdq[70], amdq[70]; - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); double fl_local[70], fr_local[70]; gkyl_gr_ultra_rel_euler_flux(gas_gamma, ql_local, fl_local); @@ -1116,7 +1518,7 @@ test_gr_ultra_rel_euler_waves_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1128,7 +1530,7 @@ test_gr_ultra_rel_euler_waves_schwarzschild_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1157,12 +1559,12 @@ test_gr_ultra_rel_euler_waves_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_ultra_rel_euler_waves_kerr_ho() +void test_gr_ultra_rel_euler_waves_kerr_ho() { double gas_gamma = 2.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_ultra_rel_euler = gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler = + gkyl_wv_gr_ultra_rel_euler_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1180,10 +1582,10 @@ test_gr_ultra_rel_euler_waves_kerr_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1193,18 +1595,18 @@ test_gr_ultra_rel_euler_waves_kerr_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1223,20 +1625,46 @@ test_gr_ultra_rel_euler_waves_kerr_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1248,7 +1676,7 @@ test_gr_ultra_rel_euler_waves_kerr_ho() double W_l = 1.0 / sqrt(1.0 - v_sq_l); double W_r = 1.0 / sqrt(1.0 - v_sq_r); - + if (!in_excision_region_l && !in_excision_region_r) { double ql[70], qr[70]; ql[0] = sqrt(spatial_det_l) * (((rho_l + p_l) * (W_l * W_l)) - p_l); @@ -1257,37 +1685,79 @@ test_gr_ultra_rel_euler_waves_kerr_ho() ql[3] = sqrt(spatial_det_l) * (rho_l + p_l) * (W_l * W_l) * w_l; ql[4] = lapse_l; - ql[5] = shift_l[0]; ql[6] = shift_l[1]; ql[7] = shift_l[2]; - - ql[8] = spatial_metric_l[0][0]; ql[9] = spatial_metric_l[0][1]; ql[10] = spatial_metric_l[0][2]; - ql[11] = spatial_metric_l[1][0]; ql[12] = spatial_metric_l[1][1]; ql[13] = spatial_metric_l[1][2]; - ql[14] = spatial_metric_l[2][0]; ql[15] = spatial_metric_l[2][1]; ql[16] = spatial_metric_l[2][2]; - - ql[17] = extrinsic_curvature_l[0][0]; ql[18] = extrinsic_curvature_l[0][1]; ql[19] = extrinsic_curvature_l[0][2]; - ql[20] = extrinsic_curvature_l[1][0]; ql[21] = extrinsic_curvature_l[1][1]; ql[22] = extrinsic_curvature_l[1][2]; - ql[23] = extrinsic_curvature_l[2][0]; ql[24] = extrinsic_curvature_l[2][1]; ql[25] = extrinsic_curvature_l[2][2]; + ql[5] = shift_l[0]; + ql[6] = shift_l[1]; + ql[7] = shift_l[2]; + + ql[8] = spatial_metric_l[0][0]; + ql[9] = spatial_metric_l[0][1]; + ql[10] = spatial_metric_l[0][2]; + ql[11] = spatial_metric_l[1][0]; + ql[12] = spatial_metric_l[1][1]; + ql[13] = spatial_metric_l[1][2]; + ql[14] = spatial_metric_l[2][0]; + ql[15] = spatial_metric_l[2][1]; + ql[16] = spatial_metric_l[2][2]; + + ql[17] = extrinsic_curvature_l[0][0]; + ql[18] = extrinsic_curvature_l[0][1]; + ql[19] = extrinsic_curvature_l[0][2]; + ql[20] = extrinsic_curvature_l[1][0]; + ql[21] = extrinsic_curvature_l[1][1]; + ql[22] = extrinsic_curvature_l[1][2]; + ql[23] = extrinsic_curvature_l[2][0]; + ql[24] = extrinsic_curvature_l[2][1]; + ql[25] = extrinsic_curvature_l[2][2]; ql[26] = 1.0; - ql[27] = lapse_der_l[0]; ql[28] = lapse_der_l[1]; ql[29] = lapse_der_l[2]; - ql[30] = shift_der_l[0][0]; ql[31] = shift_der_l[0][1]; ql[32] = shift_der_l[0][2]; - ql[33] = shift_der_l[1][0]; ql[34] = shift_der_l[1][1]; ql[35] = shift_der_l[1][2]; - ql[36] = shift_der_l[2][0]; ql[37] = shift_der_l[2][1]; ql[38] = shift_der_l[2][2]; - - ql[39] = spatial_metric_der_l[0][0][0]; ql[40] = spatial_metric_der_l[0][0][1]; ql[41] = spatial_metric_der_l[0][0][2]; - ql[42] = spatial_metric_der_l[0][1][0]; ql[43] = spatial_metric_der_l[0][1][1]; ql[44] = spatial_metric_der_l[0][1][2]; - ql[45] = spatial_metric_der_l[0][2][0]; ql[46] = spatial_metric_der_l[0][2][1]; ql[47] = spatial_metric_der_l[0][2][2]; - - ql[48] = spatial_metric_der_l[1][0][0]; ql[49] = spatial_metric_der_l[1][0][1]; ql[50] = spatial_metric_der_l[1][0][2]; - ql[51] = spatial_metric_der_l[1][1][0]; ql[52] = spatial_metric_der_l[1][1][1]; ql[53] = spatial_metric_der_l[1][1][2]; - ql[54] = spatial_metric_der_l[1][2][0]; ql[55] = spatial_metric_der_l[1][2][1]; ql[56] = spatial_metric_der_l[1][2][2]; - - ql[57] = spatial_metric_der_l[2][0][0]; ql[58] = spatial_metric_der_l[2][0][1]; ql[59] = spatial_metric_der_l[2][0][2]; - ql[60] = spatial_metric_der_l[2][1][0]; ql[61] = spatial_metric_der_l[2][1][1]; ql[62] = spatial_metric_der_l[2][1][2]; - ql[63] = spatial_metric_der_l[2][2][0]; ql[64] = spatial_metric_der_l[2][2][1]; ql[65] = spatial_metric_der_l[2][2][2]; + ql[27] = lapse_der_l[0]; + ql[28] = lapse_der_l[1]; + ql[29] = lapse_der_l[2]; + ql[30] = shift_der_l[0][0]; + ql[31] = shift_der_l[0][1]; + ql[32] = shift_der_l[0][2]; + ql[33] = shift_der_l[1][0]; + ql[34] = shift_der_l[1][1]; + ql[35] = shift_der_l[1][2]; + ql[36] = shift_der_l[2][0]; + ql[37] = shift_der_l[2][1]; + ql[38] = shift_der_l[2][2]; + + ql[39] = spatial_metric_der_l[0][0][0]; + ql[40] = spatial_metric_der_l[0][0][1]; + ql[41] = spatial_metric_der_l[0][0][2]; + ql[42] = spatial_metric_der_l[0][1][0]; + ql[43] = spatial_metric_der_l[0][1][1]; + ql[44] = spatial_metric_der_l[0][1][2]; + ql[45] = spatial_metric_der_l[0][2][0]; + ql[46] = spatial_metric_der_l[0][2][1]; + ql[47] = spatial_metric_der_l[0][2][2]; + + ql[48] = spatial_metric_der_l[1][0][0]; + ql[49] = spatial_metric_der_l[1][0][1]; + ql[50] = spatial_metric_der_l[1][0][2]; + ql[51] = spatial_metric_der_l[1][1][0]; + ql[52] = spatial_metric_der_l[1][1][1]; + ql[53] = spatial_metric_der_l[1][1][2]; + ql[54] = spatial_metric_der_l[1][2][0]; + ql[55] = spatial_metric_der_l[1][2][1]; + ql[56] = spatial_metric_der_l[1][2][2]; + + ql[57] = spatial_metric_der_l[2][0][0]; + ql[58] = spatial_metric_der_l[2][0][1]; + ql[59] = spatial_metric_der_l[2][0][2]; + ql[60] = spatial_metric_der_l[2][1][0]; + ql[61] = spatial_metric_der_l[2][1][1]; + ql[62] = spatial_metric_der_l[2][1][2]; + ql[63] = spatial_metric_der_l[2][2][0]; + ql[64] = spatial_metric_der_l[2][2][1]; + ql[65] = spatial_metric_der_l[2][2][2]; ql[66] = 0.0; - ql[67] = x - 0.5; ql[68] = y; ql[69] = 0.0; + ql[67] = x - 0.5; + ql[68] = y; + ql[69] = 0.0; qr[0] = sqrt(spatial_det_r) * (((rho_r + p_r) * (W_r * W_r)) - p_r); qr[1] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * u_r; @@ -1295,55 +1765,85 @@ test_gr_ultra_rel_euler_waves_kerr_ho() qr[3] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * w_r; qr[4] = lapse_r; - qr[5] = shift_r[0]; qr[6] = shift_r[1]; qr[7] = shift_r[2]; - - qr[8] = spatial_metric_r[0][0]; qr[9] = spatial_metric_r[0][1]; qr[10] = spatial_metric_r[0][2]; - qr[11] = spatial_metric_r[1][0]; qr[12] = spatial_metric_r[1][1]; qr[13] = spatial_metric_r[1][2]; - qr[14] = spatial_metric_r[2][0]; qr[15] = spatial_metric_r[2][1]; qr[16] = spatial_metric_r[2][2]; - - qr[17] = extrinsic_curvature_r[0][0]; qr[18] = extrinsic_curvature_r[0][1]; qr[19] = extrinsic_curvature_r[0][2]; - qr[20] = extrinsic_curvature_r[1][0]; qr[21] = extrinsic_curvature_r[1][1]; qr[22] = extrinsic_curvature_r[1][2]; - qr[23] = extrinsic_curvature_r[2][0]; qr[24] = extrinsic_curvature_r[2][1]; qr[25] = extrinsic_curvature_r[2][2]; + qr[5] = shift_r[0]; + qr[6] = shift_r[1]; + qr[7] = shift_r[2]; + + qr[8] = spatial_metric_r[0][0]; + qr[9] = spatial_metric_r[0][1]; + qr[10] = spatial_metric_r[0][2]; + qr[11] = spatial_metric_r[1][0]; + qr[12] = spatial_metric_r[1][1]; + qr[13] = spatial_metric_r[1][2]; + qr[14] = spatial_metric_r[2][0]; + qr[15] = spatial_metric_r[2][1]; + qr[16] = spatial_metric_r[2][2]; + + qr[17] = extrinsic_curvature_r[0][0]; + qr[18] = extrinsic_curvature_r[0][1]; + qr[19] = extrinsic_curvature_r[0][2]; + qr[20] = extrinsic_curvature_r[1][0]; + qr[21] = extrinsic_curvature_r[1][1]; + qr[22] = extrinsic_curvature_r[1][2]; + qr[23] = extrinsic_curvature_r[2][0]; + qr[24] = extrinsic_curvature_r[2][1]; + qr[25] = extrinsic_curvature_r[2][2]; qr[26] = 1.0; - qr[27] = lapse_der_r[0]; qr[28] = lapse_der_r[1]; qr[29] = lapse_der_r[2]; - qr[30] = shift_der_r[0][0]; qr[31] = shift_der_r[0][1]; qr[32] = shift_der_r[0][2]; - qr[33] = shift_der_r[1][0]; qr[34] = shift_der_r[1][1]; qr[35] = shift_der_r[1][2]; - qr[36] = shift_der_r[2][0]; qr[37] = shift_der_r[2][1]; qr[38] = shift_der_r[2][2]; - - qr[39] = spatial_metric_der_r[0][0][0]; qr[40] = spatial_metric_der_r[0][0][1]; qr[41] = spatial_metric_der_r[0][0][2]; - qr[42] = spatial_metric_der_r[0][1][0]; qr[43] = spatial_metric_der_r[0][1][1]; qr[44] = spatial_metric_der_r[0][1][2]; - qr[45] = spatial_metric_der_r[0][2][0]; qr[46] = spatial_metric_der_r[0][2][1]; qr[47] = spatial_metric_der_r[0][2][2]; - - qr[48] = spatial_metric_der_r[1][0][0]; qr[49] = spatial_metric_der_r[1][0][1]; qr[50] = spatial_metric_der_r[1][0][2]; - qr[51] = spatial_metric_der_r[1][1][0]; qr[52] = spatial_metric_der_r[1][1][1]; qr[53] = spatial_metric_der_r[1][1][2]; - qr[54] = spatial_metric_der_r[1][2][0]; qr[55] = spatial_metric_der_r[1][2][1]; qr[56] = spatial_metric_der_r[1][2][2]; - - qr[57] = spatial_metric_der_r[2][0][0]; qr[58] = spatial_metric_der_r[2][0][1]; qr[59] = spatial_metric_der_r[2][0][2]; - qr[60] = spatial_metric_der_r[2][1][0]; qr[61] = spatial_metric_der_r[2][1][1]; qr[62] = spatial_metric_der_r[2][1][2]; - qr[63] = spatial_metric_der_r[2][2][0]; qr[64] = spatial_metric_der_r[2][2][1]; qr[65] = spatial_metric_der_r[2][2][2]; + qr[27] = lapse_der_r[0]; + qr[28] = lapse_der_r[1]; + qr[29] = lapse_der_r[2]; + qr[30] = shift_der_r[0][0]; + qr[31] = shift_der_r[0][1]; + qr[32] = shift_der_r[0][2]; + qr[33] = shift_der_r[1][0]; + qr[34] = shift_der_r[1][1]; + qr[35] = shift_der_r[1][2]; + qr[36] = shift_der_r[2][0]; + qr[37] = shift_der_r[2][1]; + qr[38] = shift_der_r[2][2]; + + qr[39] = spatial_metric_der_r[0][0][0]; + qr[40] = spatial_metric_der_r[0][0][1]; + qr[41] = spatial_metric_der_r[0][0][2]; + qr[42] = spatial_metric_der_r[0][1][0]; + qr[43] = spatial_metric_der_r[0][1][1]; + qr[44] = spatial_metric_der_r[0][1][2]; + qr[45] = spatial_metric_der_r[0][2][0]; + qr[46] = spatial_metric_der_r[0][2][1]; + qr[47] = spatial_metric_der_r[0][2][2]; + + qr[48] = spatial_metric_der_r[1][0][0]; + qr[49] = spatial_metric_der_r[1][0][1]; + qr[50] = spatial_metric_der_r[1][0][2]; + qr[51] = spatial_metric_der_r[1][1][0]; + qr[52] = spatial_metric_der_r[1][1][1]; + qr[53] = spatial_metric_der_r[1][1][2]; + qr[54] = spatial_metric_der_r[1][2][0]; + qr[55] = spatial_metric_der_r[1][2][1]; + qr[56] = spatial_metric_der_r[1][2][2]; + + qr[57] = spatial_metric_der_r[2][0][0]; + qr[58] = spatial_metric_der_r[2][0][1]; + qr[59] = spatial_metric_der_r[2][0][2]; + qr[60] = spatial_metric_der_r[2][1][0]; + qr[61] = spatial_metric_der_r[2][1][1]; + qr[62] = spatial_metric_der_r[2][1][2]; + qr[63] = spatial_metric_der_r[2][2][0]; + qr[64] = spatial_metric_der_r[2][2][1]; + qr[65] = spatial_metric_der_r[2][2][2]; qr[66] = 0.0; - qr[67] = x + 0.5; qr[68] = y; qr[69] = 0.0; + qr[67] = x + 0.5; + qr[68] = y; + qr[69] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 70], waves_local[3 * 70]; @@ -1357,18 +1857,30 @@ test_gr_ultra_rel_euler_waves_kerr_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[70], amdq_local[70]; - gkyl_wv_eqn_qfluct(gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_ultra_rel_euler, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 70], &waves[i * 70]); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 70], &waves[i * 70] + ); } double apdq[70], amdq[70]; - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); double fl_local[70], fr_local[70]; gkyl_gr_ultra_rel_euler_flux(gas_gamma, ql_local, fl_local); @@ -1379,7 +1891,7 @@ test_gr_ultra_rel_euler_waves_kerr_ho() gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-11) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-11)); } } } @@ -1391,7 +1903,7 @@ test_gr_ultra_rel_euler_waves_kerr_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1421,11 +1933,11 @@ test_gr_ultra_rel_euler_waves_kerr_ho() } TEST_LIST = { - { "gr_ultra_rel_euler_basic_minkowski_ho", test_gr_ultra_rel_euler_basic_minkowski_ho }, - { "gr_ultra_rel_euler_basic_schwarzschild_ho", test_gr_ultra_rel_euler_basic_schwarzschild_ho }, - { "gr_ultra_rel_euler_basic_kerr_ho", test_gr_ultra_rel_euler_basic_kerr_ho }, - { "gr_ultra_rel_euler_waves_minkowski_ho", test_gr_ultra_rel_euler_waves_minkowski_ho }, - { "gr_ultra_rel_euler_waves_schwarzschild_ho", test_gr_ultra_rel_euler_waves_schwarzschild_ho }, - { "gr_ultra_rel_euler_waves_kerr_ho", test_gr_ultra_rel_euler_waves_kerr_ho }, - { NULL, NULL }, + {"gr_ultra_rel_euler_basic_minkowski_ho", test_gr_ultra_rel_euler_basic_minkowski_ho}, + {"gr_ultra_rel_euler_basic_schwarzschild_ho", test_gr_ultra_rel_euler_basic_schwarzschild_ho}, + {"gr_ultra_rel_euler_basic_kerr_ho", test_gr_ultra_rel_euler_basic_kerr_ho}, + {"gr_ultra_rel_euler_waves_minkowski_ho", test_gr_ultra_rel_euler_waves_minkowski_ho}, + {"gr_ultra_rel_euler_waves_schwarzschild_ho", test_gr_ultra_rel_euler_waves_schwarzschild_ho}, + {"gr_ultra_rel_euler_waves_kerr_ho", test_gr_ultra_rel_euler_waves_kerr_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_gr_ultra_rel_euler_tetrad.c b/moments/unit/ctest_wv_gr_ultra_rel_euler_tetrad.c index 21280551f0..291beb4350 100644 --- a/moments/unit/ctest_wv_gr_ultra_rel_euler_tetrad.c +++ b/moments/unit/ctest_wv_gr_ultra_rel_euler_tetrad.c @@ -6,15 +6,15 @@ #include #include -void -test_gr_ultra_rel_euler_tetrad_basic_minkowski_ho() +void test_gr_ultra_rel_euler_tetrad_basic_minkowski_ho() { double gas_gamma = 2.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = + gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_ultra_rel_euler_tetrad->num_equations == 70 ); - TEST_CHECK( gr_ultra_rel_euler_tetrad->num_waves == 2 ); + TEST_CHECK(gr_ultra_rel_euler_tetrad->num_equations == 70); + TEST_CHECK(gr_ultra_rel_euler_tetrad->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -27,25 +27,25 @@ test_gr_ultra_rel_euler_tetrad_basic_minkowski_ho() double spatial_det, lapse; double *shift = gkyl_malloc(sizeof(double[3])); - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -55,16 +55,28 @@ test_gr_ultra_rel_euler_tetrad_basic_minkowski_ho() spacetime->spatial_metric_det_func(spacetime, 0.0, x, y, 0.0, &spatial_det); spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -82,88 +94,136 @@ test_gr_ultra_rel_euler_tetrad_basic_minkowski_ho() q[3] = sqrt(spatial_det) * (rho + p) * (W * W) * w; q[4] = lapse; - q[5] = shift[0]; q[6] = shift[1]; q[7] = shift[2]; - - q[8] = spatial_metric[0][0]; q[9] = spatial_metric[0][1]; q[10] = spatial_metric[0][2]; - q[11] = spatial_metric[1][0]; q[12] = spatial_metric[1][1]; q[13] = spatial_metric[1][2]; - q[14] = spatial_metric[2][0]; q[15] = spatial_metric[2][1]; q[16] = spatial_metric[2][2]; - - q[17] = extrinsic_curvature[0][0]; q[18] = extrinsic_curvature[0][1]; q[19] = extrinsic_curvature[0][2]; - q[20] = extrinsic_curvature[1][0]; q[21] = extrinsic_curvature[1][1]; q[22] = extrinsic_curvature[1][2]; - q[23] = extrinsic_curvature[2][0]; q[24] = extrinsic_curvature[2][1]; q[25] = extrinsic_curvature[2][2]; + q[5] = shift[0]; + q[6] = shift[1]; + q[7] = shift[2]; + + q[8] = spatial_metric[0][0]; + q[9] = spatial_metric[0][1]; + q[10] = spatial_metric[0][2]; + q[11] = spatial_metric[1][0]; + q[12] = spatial_metric[1][1]; + q[13] = spatial_metric[1][2]; + q[14] = spatial_metric[2][0]; + q[15] = spatial_metric[2][1]; + q[16] = spatial_metric[2][2]; + + q[17] = extrinsic_curvature[0][0]; + q[18] = extrinsic_curvature[0][1]; + q[19] = extrinsic_curvature[0][2]; + q[20] = extrinsic_curvature[1][0]; + q[21] = extrinsic_curvature[1][1]; + q[22] = extrinsic_curvature[1][2]; + q[23] = extrinsic_curvature[2][0]; + q[24] = extrinsic_curvature[2][1]; + q[25] = extrinsic_curvature[2][2]; q[26] = 1.0; - q[27] = lapse_der[0]; q[28] = lapse_der[1]; q[29] = lapse_der[2]; - q[30] = shift_der[0][0]; q[31] = shift_der[0][1]; q[32] = shift_der[0][2]; - q[33] = shift_der[1][0]; q[34] = shift_der[1][1]; q[35] = shift_der[1][2]; - q[36] = shift_der[2][0]; q[37] = shift_der[2][1]; q[38] = shift_der[2][2]; - - q[39] = spatial_metric_der[0][0][0]; q[40] = spatial_metric_der[0][0][1]; q[41] = spatial_metric_der[0][0][2]; - q[42] = spatial_metric_der[0][1][0]; q[43] = spatial_metric_der[0][1][1]; q[44] = spatial_metric_der[0][1][2]; - q[45] = spatial_metric_der[0][2][0]; q[46] = spatial_metric_der[0][2][1]; q[47] = spatial_metric_der[0][2][2]; - - q[48] = spatial_metric_der[1][0][0]; q[49] = spatial_metric_der[1][0][1]; q[50] = spatial_metric_der[1][0][2]; - q[51] = spatial_metric_der[1][1][0]; q[52] = spatial_metric_der[1][1][1]; q[53] = spatial_metric_der[1][1][2]; - q[54] = spatial_metric_der[1][2][0]; q[55] = spatial_metric_der[1][2][1]; q[56] = spatial_metric_der[1][2][2]; - - q[57] = spatial_metric_der[2][0][0]; q[58] = spatial_metric_der[2][0][1]; q[59] = spatial_metric_der[2][0][2]; - q[60] = spatial_metric_der[2][1][0]; q[61] = spatial_metric_der[2][1][1]; q[62] = spatial_metric_der[2][1][2]; - q[63] = spatial_metric_der[2][2][0]; q[64] = spatial_metric_der[2][2][1]; q[65] = spatial_metric_der[2][2][2]; + q[27] = lapse_der[0]; + q[28] = lapse_der[1]; + q[29] = lapse_der[2]; + q[30] = shift_der[0][0]; + q[31] = shift_der[0][1]; + q[32] = shift_der[0][2]; + q[33] = shift_der[1][0]; + q[34] = shift_der[1][1]; + q[35] = shift_der[1][2]; + q[36] = shift_der[2][0]; + q[37] = shift_der[2][1]; + q[38] = shift_der[2][2]; + + q[39] = spatial_metric_der[0][0][0]; + q[40] = spatial_metric_der[0][0][1]; + q[41] = spatial_metric_der[0][0][2]; + q[42] = spatial_metric_der[0][1][0]; + q[43] = spatial_metric_der[0][1][1]; + q[44] = spatial_metric_der[0][1][2]; + q[45] = spatial_metric_der[0][2][0]; + q[46] = spatial_metric_der[0][2][1]; + q[47] = spatial_metric_der[0][2][2]; + + q[48] = spatial_metric_der[1][0][0]; + q[49] = spatial_metric_der[1][0][1]; + q[50] = spatial_metric_der[1][0][2]; + q[51] = spatial_metric_der[1][1][0]; + q[52] = spatial_metric_der[1][1][1]; + q[53] = spatial_metric_der[1][1][2]; + q[54] = spatial_metric_der[1][2][0]; + q[55] = spatial_metric_der[1][2][1]; + q[56] = spatial_metric_der[1][2][2]; + + q[57] = spatial_metric_der[2][0][0]; + q[58] = spatial_metric_der[2][0][1]; + q[59] = spatial_metric_der[2][0][2]; + q[60] = spatial_metric_der[2][1][0]; + q[61] = spatial_metric_der[2][1][1]; + q[62] = spatial_metric_der[2][1][2]; + q[63] = spatial_metric_der[2][2][0]; + q[64] = spatial_metric_der[2][2][1]; + q[65] = spatial_metric_der[2][2][2]; q[66] = 0.0; - q[67] = x; q[68] = y; q[69] = 0.0; + q[67] = x; + q[68] = y; + q[69] = 0.0; double prims[70]; gkyl_gr_ultra_rel_euler_tetrad_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-13) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-13) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-13)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-13)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-13)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-13)); double fluxes[3][4] = { - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p) }, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[70], flux_local_sr[70], flux_local_gr[70], flux[70]; for (int d = 0; d < 3; d++) { - gr_ultra_rel_euler_tetrad->rotate_to_local_func(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local); + gr_ultra_rel_euler_tetrad->rotate_to_local_func( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, q_local, flux_local_sr); - gkyl_gr_ultra_rel_euler_tetrad_flux_correction(gas_gamma, q_local, flux_local_sr, flux_local_gr); - gr_ultra_rel_euler_tetrad->rotate_to_global_func(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gkyl_gr_ultra_rel_euler_tetrad_flux_correction( + gas_gamma, q_local, flux_local_sr, flux_local_gr + ); + gr_ultra_rel_euler_tetrad->rotate_to_global_func( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 4; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-13) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-13)); } } @@ -173,7 +233,7 @@ test_gr_ultra_rel_euler_tetrad_basic_minkowski_ho() gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[70], q1[70]; @@ -181,7 +241,7 @@ test_gr_ultra_rel_euler_tetrad_basic_minkowski_ho() gr_ultra_rel_euler_tetrad->riem_to_cons(gr_ultra_rel_euler_tetrad, q_local, w1, q1); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } @@ -189,7 +249,7 @@ test_gr_ultra_rel_euler_tetrad_basic_minkowski_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -209,15 +269,15 @@ test_gr_ultra_rel_euler_tetrad_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho() +void test_gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho() { double gas_gamma = 2.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = + gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); - TEST_CHECK( gr_ultra_rel_euler_tetrad->num_equations == 70 ); - TEST_CHECK( gr_ultra_rel_euler_tetrad->num_waves == 2 ); + TEST_CHECK(gr_ultra_rel_euler_tetrad->num_equations == 70); + TEST_CHECK(gr_ultra_rel_euler_tetrad->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -231,25 +291,25 @@ test_gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -260,16 +320,28 @@ test_gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -288,105 +360,159 @@ test_gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho() q[3] = sqrt(spatial_det) * (rho + p) * (W * W) * w; q[4] = lapse; - q[5] = shift[0]; q[6] = shift[1]; q[7] = shift[2]; - - q[8] = spatial_metric[0][0]; q[9] = spatial_metric[0][1]; q[10] = spatial_metric[0][2]; - q[11] = spatial_metric[1][0]; q[12] = spatial_metric[1][1]; q[13] = spatial_metric[1][2]; - q[14] = spatial_metric[2][0]; q[15] = spatial_metric[2][1]; q[16] = spatial_metric[2][2]; - - q[17] = extrinsic_curvature[0][0]; q[18] = extrinsic_curvature[0][1]; q[19] = extrinsic_curvature[0][2]; - q[20] = extrinsic_curvature[1][0]; q[21] = extrinsic_curvature[1][1]; q[22] = extrinsic_curvature[1][2]; - q[23] = extrinsic_curvature[2][0]; q[24] = extrinsic_curvature[2][1]; q[25] = extrinsic_curvature[2][2]; + q[5] = shift[0]; + q[6] = shift[1]; + q[7] = shift[2]; + + q[8] = spatial_metric[0][0]; + q[9] = spatial_metric[0][1]; + q[10] = spatial_metric[0][2]; + q[11] = spatial_metric[1][0]; + q[12] = spatial_metric[1][1]; + q[13] = spatial_metric[1][2]; + q[14] = spatial_metric[2][0]; + q[15] = spatial_metric[2][1]; + q[16] = spatial_metric[2][2]; + + q[17] = extrinsic_curvature[0][0]; + q[18] = extrinsic_curvature[0][1]; + q[19] = extrinsic_curvature[0][2]; + q[20] = extrinsic_curvature[1][0]; + q[21] = extrinsic_curvature[1][1]; + q[22] = extrinsic_curvature[1][2]; + q[23] = extrinsic_curvature[2][0]; + q[24] = extrinsic_curvature[2][1]; + q[25] = extrinsic_curvature[2][2]; q[26] = 1.0; - q[27] = lapse_der[0]; q[28] = lapse_der[1]; q[29] = lapse_der[2]; - q[30] = shift_der[0][0]; q[31] = shift_der[0][1]; q[32] = shift_der[0][2]; - q[33] = shift_der[1][0]; q[34] = shift_der[1][1]; q[35] = shift_der[1][2]; - q[36] = shift_der[2][0]; q[37] = shift_der[2][1]; q[38] = shift_der[2][2]; - - q[39] = spatial_metric_der[0][0][0]; q[40] = spatial_metric_der[0][0][1]; q[41] = spatial_metric_der[0][0][2]; - q[42] = spatial_metric_der[0][1][0]; q[43] = spatial_metric_der[0][1][1]; q[44] = spatial_metric_der[0][1][2]; - q[45] = spatial_metric_der[0][2][0]; q[46] = spatial_metric_der[0][2][1]; q[47] = spatial_metric_der[0][2][2]; - - q[48] = spatial_metric_der[1][0][0]; q[49] = spatial_metric_der[1][0][1]; q[50] = spatial_metric_der[1][0][2]; - q[51] = spatial_metric_der[1][1][0]; q[52] = spatial_metric_der[1][1][1]; q[53] = spatial_metric_der[1][1][2]; - q[54] = spatial_metric_der[1][2][0]; q[55] = spatial_metric_der[1][2][1]; q[56] = spatial_metric_der[1][2][2]; - - q[57] = spatial_metric_der[2][0][0]; q[58] = spatial_metric_der[2][0][1]; q[59] = spatial_metric_der[2][0][2]; - q[60] = spatial_metric_der[2][1][0]; q[61] = spatial_metric_der[2][1][1]; q[62] = spatial_metric_der[2][1][2]; - q[63] = spatial_metric_der[2][2][0]; q[64] = spatial_metric_der[2][2][1]; q[65] = spatial_metric_der[2][2][2]; + q[27] = lapse_der[0]; + q[28] = lapse_der[1]; + q[29] = lapse_der[2]; + q[30] = shift_der[0][0]; + q[31] = shift_der[0][1]; + q[32] = shift_der[0][2]; + q[33] = shift_der[1][0]; + q[34] = shift_der[1][1]; + q[35] = shift_der[1][2]; + q[36] = shift_der[2][0]; + q[37] = shift_der[2][1]; + q[38] = shift_der[2][2]; + + q[39] = spatial_metric_der[0][0][0]; + q[40] = spatial_metric_der[0][0][1]; + q[41] = spatial_metric_der[0][0][2]; + q[42] = spatial_metric_der[0][1][0]; + q[43] = spatial_metric_der[0][1][1]; + q[44] = spatial_metric_der[0][1][2]; + q[45] = spatial_metric_der[0][2][0]; + q[46] = spatial_metric_der[0][2][1]; + q[47] = spatial_metric_der[0][2][2]; + + q[48] = spatial_metric_der[1][0][0]; + q[49] = spatial_metric_der[1][0][1]; + q[50] = spatial_metric_der[1][0][2]; + q[51] = spatial_metric_der[1][1][0]; + q[52] = spatial_metric_der[1][1][1]; + q[53] = spatial_metric_der[1][1][2]; + q[54] = spatial_metric_der[1][2][0]; + q[55] = spatial_metric_der[1][2][1]; + q[56] = spatial_metric_der[1][2][2]; + + q[57] = spatial_metric_der[2][0][0]; + q[58] = spatial_metric_der[2][0][1]; + q[59] = spatial_metric_der[2][0][2]; + q[60] = spatial_metric_der[2][1][0]; + q[61] = spatial_metric_der[2][1][1]; + q[62] = spatial_metric_der[2][1][2]; + q[63] = spatial_metric_der[2][2][0]; + q[64] = spatial_metric_der[2][2][1]; + q[65] = spatial_metric_der[2][2][2]; q[66] = 0.0; - q[67] = x; q[68] = y; q[69] = 0.0; + q[67] = x; + q[68] = y; + q[69] = 0.0; double prims[70]; gkyl_gr_ultra_rel_euler_tetrad_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); // Calculate the fluxes using the reconstructed primitive variables, for now. -JG rho = prims[0]; - vel[0] = prims[1]; vel[1] = prims[2]; vel[2] = prims[3]; + vel[0] = prims[1]; + vel[1] = prims[2]; + vel[2] = prims[3]; p = (gas_gamma - 1.0) * rho; lapse = prims[4]; - shift[0] = prims[5]; shift[1] = prims[6]; shift[2] = prims[7]; + shift[0] = prims[5]; + shift[1] = prims[6]; + shift[2] = prims[7]; double fluxes[3][4] = { - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p) }, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[70], flux_local_sr[70], flux_local_gr[70], flux[70]; for (int d = 0; d < 3; d++) { - gr_ultra_rel_euler_tetrad->rotate_to_local_func(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, q_local, flux_local_sr); - gkyl_gr_ultra_rel_euler_tetrad_flux_correction(gas_gamma, q_local, flux_local_sr, flux_local_gr); - gr_ultra_rel_euler_tetrad->rotate_to_global_func(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gr_ultra_rel_euler_tetrad->rotate_to_local_func( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); + gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, q_local, flux_local_sr); + gkyl_gr_ultra_rel_euler_tetrad_flux_correction( + gas_gamma, q_local, flux_local_sr, flux_local_gr + ); + gr_ultra_rel_euler_tetrad->rotate_to_global_func( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 4; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } double q_l[70], q_g[70]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_l); - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g + ); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[70], q1[70]; @@ -394,7 +520,7 @@ test_gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho() gr_ultra_rel_euler_tetrad->riem_to_cons(gr_ultra_rel_euler_tetrad, q_local, w1, q1); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -403,7 +529,7 @@ test_gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -423,18 +549,18 @@ test_gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_ultra_rel_euler_tetrad_basic_kerr_ho() +void test_gr_ultra_rel_euler_tetrad_basic_kerr_ho() { double gas_gamma = 2.0; // Currently this test only passes for very low (a = 0.2) values of the black hole spin. // Need to track down why the flux errors appear at higher spin values. -JG struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.2, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = + gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + + TEST_CHECK(gr_ultra_rel_euler_tetrad->num_equations == 70); + TEST_CHECK(gr_ultra_rel_euler_tetrad->num_waves == 2); - TEST_CHECK( gr_ultra_rel_euler_tetrad->num_equations == 70 ); - TEST_CHECK( gr_ultra_rel_euler_tetrad->num_waves == 2 ); - for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { double x = 0.1 * x_ind; @@ -447,25 +573,25 @@ test_gr_ultra_rel_euler_tetrad_basic_kerr_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -476,16 +602,28 @@ test_gr_ultra_rel_euler_tetrad_basic_kerr_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); double *vel = gkyl_malloc(sizeof(double[3])); - vel[0] = u; vel[1] = v; vel[2] = w; + vel[0] = u; + vel[1] = v; + vel[2] = w; double v_sq = 0.0; for (int i = 0; i < 3; i++) { @@ -504,105 +642,159 @@ test_gr_ultra_rel_euler_tetrad_basic_kerr_ho() q[3] = sqrt(spatial_det) * (rho + p) * (W * W) * w; q[4] = lapse; - q[5] = shift[0]; q[6] = shift[1]; q[7] = shift[2]; - - q[8] = spatial_metric[0][0]; q[9] = spatial_metric[0][1]; q[10] = spatial_metric[0][2]; - q[11] = spatial_metric[1][0]; q[12] = spatial_metric[1][1]; q[13] = spatial_metric[1][2]; - q[14] = spatial_metric[2][0]; q[15] = spatial_metric[2][1]; q[16] = spatial_metric[2][2]; - - q[17] = extrinsic_curvature[0][0]; q[18] = extrinsic_curvature[0][1]; q[19] = extrinsic_curvature[0][2]; - q[20] = extrinsic_curvature[1][0]; q[21] = extrinsic_curvature[1][1]; q[22] = extrinsic_curvature[1][2]; - q[23] = extrinsic_curvature[2][0]; q[24] = extrinsic_curvature[2][1]; q[25] = extrinsic_curvature[2][2]; + q[5] = shift[0]; + q[6] = shift[1]; + q[7] = shift[2]; + + q[8] = spatial_metric[0][0]; + q[9] = spatial_metric[0][1]; + q[10] = spatial_metric[0][2]; + q[11] = spatial_metric[1][0]; + q[12] = spatial_metric[1][1]; + q[13] = spatial_metric[1][2]; + q[14] = spatial_metric[2][0]; + q[15] = spatial_metric[2][1]; + q[16] = spatial_metric[2][2]; + + q[17] = extrinsic_curvature[0][0]; + q[18] = extrinsic_curvature[0][1]; + q[19] = extrinsic_curvature[0][2]; + q[20] = extrinsic_curvature[1][0]; + q[21] = extrinsic_curvature[1][1]; + q[22] = extrinsic_curvature[1][2]; + q[23] = extrinsic_curvature[2][0]; + q[24] = extrinsic_curvature[2][1]; + q[25] = extrinsic_curvature[2][2]; q[26] = 1.0; - q[27] = lapse_der[0]; q[28] = lapse_der[1]; q[29] = lapse_der[2]; - q[30] = shift_der[0][0]; q[31] = shift_der[0][1]; q[32] = shift_der[0][2]; - q[33] = shift_der[1][0]; q[34] = shift_der[1][1]; q[35] = shift_der[1][2]; - q[36] = shift_der[2][0]; q[37] = shift_der[2][1]; q[38] = shift_der[2][2]; - - q[39] = spatial_metric_der[0][0][0]; q[40] = spatial_metric_der[0][0][1]; q[41] = spatial_metric_der[0][0][2]; - q[42] = spatial_metric_der[0][1][0]; q[43] = spatial_metric_der[0][1][1]; q[44] = spatial_metric_der[0][1][2]; - q[45] = spatial_metric_der[0][2][0]; q[46] = spatial_metric_der[0][2][1]; q[47] = spatial_metric_der[0][2][2]; - - q[48] = spatial_metric_der[1][0][0]; q[49] = spatial_metric_der[1][0][1]; q[50] = spatial_metric_der[1][0][2]; - q[51] = spatial_metric_der[1][1][0]; q[52] = spatial_metric_der[1][1][1]; q[53] = spatial_metric_der[1][1][2]; - q[54] = spatial_metric_der[1][2][0]; q[55] = spatial_metric_der[1][2][1]; q[56] = spatial_metric_der[1][2][2]; - - q[57] = spatial_metric_der[2][0][0]; q[58] = spatial_metric_der[2][0][1]; q[59] = spatial_metric_der[2][0][2]; - q[60] = spatial_metric_der[2][1][0]; q[61] = spatial_metric_der[2][1][1]; q[62] = spatial_metric_der[2][1][2]; - q[63] = spatial_metric_der[2][2][0]; q[64] = spatial_metric_der[2][2][1]; q[65] = spatial_metric_der[2][2][2]; + q[27] = lapse_der[0]; + q[28] = lapse_der[1]; + q[29] = lapse_der[2]; + q[30] = shift_der[0][0]; + q[31] = shift_der[0][1]; + q[32] = shift_der[0][2]; + q[33] = shift_der[1][0]; + q[34] = shift_der[1][1]; + q[35] = shift_der[1][2]; + q[36] = shift_der[2][0]; + q[37] = shift_der[2][1]; + q[38] = shift_der[2][2]; + + q[39] = spatial_metric_der[0][0][0]; + q[40] = spatial_metric_der[0][0][1]; + q[41] = spatial_metric_der[0][0][2]; + q[42] = spatial_metric_der[0][1][0]; + q[43] = spatial_metric_der[0][1][1]; + q[44] = spatial_metric_der[0][1][2]; + q[45] = spatial_metric_der[0][2][0]; + q[46] = spatial_metric_der[0][2][1]; + q[47] = spatial_metric_der[0][2][2]; + + q[48] = spatial_metric_der[1][0][0]; + q[49] = spatial_metric_der[1][0][1]; + q[50] = spatial_metric_der[1][0][2]; + q[51] = spatial_metric_der[1][1][0]; + q[52] = spatial_metric_der[1][1][1]; + q[53] = spatial_metric_der[1][1][2]; + q[54] = spatial_metric_der[1][2][0]; + q[55] = spatial_metric_der[1][2][1]; + q[56] = spatial_metric_der[1][2][2]; + + q[57] = spatial_metric_der[2][0][0]; + q[58] = spatial_metric_der[2][0][1]; + q[59] = spatial_metric_der[2][0][2]; + q[60] = spatial_metric_der[2][1][0]; + q[61] = spatial_metric_der[2][1][1]; + q[62] = spatial_metric_der[2][1][2]; + q[63] = spatial_metric_der[2][2][0]; + q[64] = spatial_metric_der[2][2][1]; + q[65] = spatial_metric_der[2][2][2]; q[66] = 0.0; - q[67] = x; q[68] = y; q[69] = 0.0; + q[67] = x; + q[68] = y; + q[69] = 0.0; double prims[70]; gkyl_gr_ultra_rel_euler_tetrad_prim_vars(gas_gamma, q, prims); - - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-1) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-1) ); + + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-1)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-1)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-1)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-1)); // Calculate the fluxes using the reconstructed primitive variables, for now. -JG rho = prims[0]; - vel[0] = prims[1]; vel[1] = prims[2]; vel[2] = prims[3]; + vel[0] = prims[1]; + vel[1] = prims[2]; + vel[2] = prims[3]; p = (gas_gamma - 1.0) * rho; lapse = prims[4]; - shift[0] = prims[5]; shift[1] = prims[6]; shift[2] = prims[7]; + shift[0] = prims[5]; + shift[1] = prims[6]; + shift[2] = prims[7]; double fluxes[3][4] = { - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse)))) }, - { (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), - (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p) }, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[0] - (shift[0] / lapse)) + (p * vel[0])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[0] - (shift[0] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[0] - (shift[0] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[0] - (shift[0] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[1] - (shift[1] / lapse)) + (p * vel[1])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[1] - (shift[1] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[1] - (shift[1] / lapse))) + p), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[1] - (shift[1] / lapse))))}, + {(lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vel[2] - (shift[2] / lapse)) + (p * vel[2])), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[0] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[1] * (vel[2] - (shift[2] / lapse)))), + (lapse * sqrt(spatial_det)) * + ((rho + p) * (W * W) * (vel[2] * (vel[2] - (shift[2] / lapse))) + p)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[70], flux_local_sr[70], flux_local_gr[70], flux[70]; for (int d = 0; d < 3; d++) { - gr_ultra_rel_euler_tetrad->rotate_to_local_func(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, q_local, flux_local_sr); - gkyl_gr_ultra_rel_euler_tetrad_flux_correction(gas_gamma, q_local, flux_local_sr, flux_local_gr); - gr_ultra_rel_euler_tetrad->rotate_to_global_func(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux); + gr_ultra_rel_euler_tetrad->rotate_to_local_func( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_local + ); + gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, q_local, flux_local_sr); + gkyl_gr_ultra_rel_euler_tetrad_flux_correction( + gas_gamma, q_local, flux_local_sr, flux_local_gr + ); + gr_ultra_rel_euler_tetrad->rotate_to_global_func( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], flux_local_gr, flux + ); for (int i = 0; i < 4; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-1) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-1)); } } double q_l[70], q_g[70]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q, q_l); - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], q_l, q_g + ); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-13)); } double w1[70], q1[70]; @@ -610,7 +802,7 @@ test_gr_ultra_rel_euler_tetrad_basic_kerr_ho() gr_ultra_rel_euler_tetrad->riem_to_cons(gr_ultra_rel_euler_tetrad, q_local, w1, q1); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-13) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-13)); } } } @@ -619,7 +811,7 @@ test_gr_ultra_rel_euler_tetrad_basic_kerr_ho() gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -639,12 +831,12 @@ test_gr_ultra_rel_euler_tetrad_basic_kerr_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_ultra_rel_euler_tetrad_waves_minkowski_ho() +void test_gr_ultra_rel_euler_tetrad_waves_minkowski_ho() { double gas_gamma = 2.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = + gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -661,10 +853,10 @@ test_gr_ultra_rel_euler_tetrad_waves_minkowski_ho() double *shift_l = gkyl_malloc(sizeof(double[3])); double *shift_r = gkyl_malloc(sizeof(double[3])); - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -674,18 +866,18 @@ test_gr_ultra_rel_euler_tetrad_waves_minkowski_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -702,20 +894,46 @@ test_gr_ultra_rel_euler_tetrad_waves_minkowski_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -735,37 +953,79 @@ test_gr_ultra_rel_euler_tetrad_waves_minkowski_ho() ql[3] = sqrt(spatial_det_l) * (rho_l + p_l) * (W_l * W_l) * w_l; ql[4] = lapse_l; - ql[5] = shift_l[0]; ql[6] = shift_l[1]; ql[7] = shift_l[2]; - - ql[8] = spatial_metric_l[0][0]; ql[9] = spatial_metric_l[0][1]; ql[10] = spatial_metric_l[0][2]; - ql[11] = spatial_metric_l[1][0]; ql[12] = spatial_metric_l[1][1]; ql[13] = spatial_metric_l[1][2]; - ql[14] = spatial_metric_l[2][0]; ql[15] = spatial_metric_l[2][1]; ql[16] = spatial_metric_l[2][2]; - - ql[17] = extrinsic_curvature_l[0][0]; ql[18] = extrinsic_curvature_l[0][1]; ql[19] = extrinsic_curvature_l[0][2]; - ql[20] = extrinsic_curvature_l[1][0]; ql[21] = extrinsic_curvature_l[1][1]; ql[22] = extrinsic_curvature_l[1][2]; - ql[23] = extrinsic_curvature_l[2][0]; ql[24] = extrinsic_curvature_l[2][1]; ql[25] = extrinsic_curvature_l[2][2]; + ql[5] = shift_l[0]; + ql[6] = shift_l[1]; + ql[7] = shift_l[2]; + + ql[8] = spatial_metric_l[0][0]; + ql[9] = spatial_metric_l[0][1]; + ql[10] = spatial_metric_l[0][2]; + ql[11] = spatial_metric_l[1][0]; + ql[12] = spatial_metric_l[1][1]; + ql[13] = spatial_metric_l[1][2]; + ql[14] = spatial_metric_l[2][0]; + ql[15] = spatial_metric_l[2][1]; + ql[16] = spatial_metric_l[2][2]; + + ql[17] = extrinsic_curvature_l[0][0]; + ql[18] = extrinsic_curvature_l[0][1]; + ql[19] = extrinsic_curvature_l[0][2]; + ql[20] = extrinsic_curvature_l[1][0]; + ql[21] = extrinsic_curvature_l[1][1]; + ql[22] = extrinsic_curvature_l[1][2]; + ql[23] = extrinsic_curvature_l[2][0]; + ql[24] = extrinsic_curvature_l[2][1]; + ql[25] = extrinsic_curvature_l[2][2]; ql[26] = 1.0; - ql[27] = lapse_der_l[0]; ql[28] = lapse_der_l[1]; ql[29] = lapse_der_l[2]; - ql[30] = shift_der_l[0][0]; ql[31] = shift_der_l[0][1]; ql[32] = shift_der_l[0][2]; - ql[33] = shift_der_l[1][0]; ql[34] = shift_der_l[1][1]; ql[35] = shift_der_l[1][2]; - ql[36] = shift_der_l[2][0]; ql[37] = shift_der_l[2][1]; ql[38] = shift_der_l[2][2]; - - ql[39] = spatial_metric_der_l[0][0][0]; ql[40] = spatial_metric_der_l[0][0][1]; ql[41] = spatial_metric_der_l[0][0][2]; - ql[42] = spatial_metric_der_l[0][1][0]; ql[43] = spatial_metric_der_l[0][1][1]; ql[44] = spatial_metric_der_l[0][1][2]; - ql[45] = spatial_metric_der_l[0][2][0]; ql[46] = spatial_metric_der_l[0][2][1]; ql[47] = spatial_metric_der_l[0][2][2]; - - ql[48] = spatial_metric_der_l[1][0][0]; ql[49] = spatial_metric_der_l[1][0][1]; ql[50] = spatial_metric_der_l[1][0][2]; - ql[51] = spatial_metric_der_l[1][1][0]; ql[52] = spatial_metric_der_l[1][1][1]; ql[53] = spatial_metric_der_l[1][1][2]; - ql[54] = spatial_metric_der_l[1][2][0]; ql[55] = spatial_metric_der_l[1][2][1]; ql[56] = spatial_metric_der_l[1][2][2]; - - ql[57] = spatial_metric_der_l[2][0][0]; ql[58] = spatial_metric_der_l[2][0][1]; ql[59] = spatial_metric_der_l[2][0][2]; - ql[60] = spatial_metric_der_l[2][1][0]; ql[61] = spatial_metric_der_l[2][1][1]; ql[62] = spatial_metric_der_l[2][1][2]; - ql[63] = spatial_metric_der_l[2][2][0]; ql[64] = spatial_metric_der_l[2][2][1]; ql[65] = spatial_metric_der_l[2][2][2]; + ql[27] = lapse_der_l[0]; + ql[28] = lapse_der_l[1]; + ql[29] = lapse_der_l[2]; + ql[30] = shift_der_l[0][0]; + ql[31] = shift_der_l[0][1]; + ql[32] = shift_der_l[0][2]; + ql[33] = shift_der_l[1][0]; + ql[34] = shift_der_l[1][1]; + ql[35] = shift_der_l[1][2]; + ql[36] = shift_der_l[2][0]; + ql[37] = shift_der_l[2][1]; + ql[38] = shift_der_l[2][2]; + + ql[39] = spatial_metric_der_l[0][0][0]; + ql[40] = spatial_metric_der_l[0][0][1]; + ql[41] = spatial_metric_der_l[0][0][2]; + ql[42] = spatial_metric_der_l[0][1][0]; + ql[43] = spatial_metric_der_l[0][1][1]; + ql[44] = spatial_metric_der_l[0][1][2]; + ql[45] = spatial_metric_der_l[0][2][0]; + ql[46] = spatial_metric_der_l[0][2][1]; + ql[47] = spatial_metric_der_l[0][2][2]; + + ql[48] = spatial_metric_der_l[1][0][0]; + ql[49] = spatial_metric_der_l[1][0][1]; + ql[50] = spatial_metric_der_l[1][0][2]; + ql[51] = spatial_metric_der_l[1][1][0]; + ql[52] = spatial_metric_der_l[1][1][1]; + ql[53] = spatial_metric_der_l[1][1][2]; + ql[54] = spatial_metric_der_l[1][2][0]; + ql[55] = spatial_metric_der_l[1][2][1]; + ql[56] = spatial_metric_der_l[1][2][2]; + + ql[57] = spatial_metric_der_l[2][0][0]; + ql[58] = spatial_metric_der_l[2][0][1]; + ql[59] = spatial_metric_der_l[2][0][2]; + ql[60] = spatial_metric_der_l[2][1][0]; + ql[61] = spatial_metric_der_l[2][1][1]; + ql[62] = spatial_metric_der_l[2][1][2]; + ql[63] = spatial_metric_der_l[2][2][0]; + ql[64] = spatial_metric_der_l[2][2][1]; + ql[65] = spatial_metric_der_l[2][2][2]; ql[66] = 0.0; - ql[67] = x - 0.5; ql[68] = y; ql[69] = 0.0; + ql[67] = x - 0.5; + ql[68] = y; + ql[69] = 0.0; qr[0] = sqrt(spatial_det_r) * (((rho_r + p_r) * (W_r * W_r)) - p_r); qr[1] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * u_r; @@ -773,95 +1033,150 @@ test_gr_ultra_rel_euler_tetrad_waves_minkowski_ho() qr[3] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * w_r; qr[4] = lapse_r; - qr[5] = shift_r[0]; qr[6] = shift_r[1]; qr[7] = shift_r[2]; - - qr[8] = spatial_metric_r[0][0]; qr[9] = spatial_metric_r[0][1]; qr[10] = spatial_metric_r[0][2]; - qr[11] = spatial_metric_r[1][0]; qr[12] = spatial_metric_r[1][1]; qr[13] = spatial_metric_r[1][2]; - qr[14] = spatial_metric_r[2][0]; qr[15] = spatial_metric_r[2][1]; qr[16] = spatial_metric_r[2][2]; - - qr[17] = extrinsic_curvature_r[0][0]; qr[18] = extrinsic_curvature_r[0][1]; qr[19] = extrinsic_curvature_r[0][2]; - qr[20] = extrinsic_curvature_r[1][0]; qr[21] = extrinsic_curvature_r[1][1]; qr[22] = extrinsic_curvature_r[1][2]; - qr[23] = extrinsic_curvature_r[2][0]; qr[24] = extrinsic_curvature_r[2][1]; qr[25] = extrinsic_curvature_r[2][2]; + qr[5] = shift_r[0]; + qr[6] = shift_r[1]; + qr[7] = shift_r[2]; + + qr[8] = spatial_metric_r[0][0]; + qr[9] = spatial_metric_r[0][1]; + qr[10] = spatial_metric_r[0][2]; + qr[11] = spatial_metric_r[1][0]; + qr[12] = spatial_metric_r[1][1]; + qr[13] = spatial_metric_r[1][2]; + qr[14] = spatial_metric_r[2][0]; + qr[15] = spatial_metric_r[2][1]; + qr[16] = spatial_metric_r[2][2]; + + qr[17] = extrinsic_curvature_r[0][0]; + qr[18] = extrinsic_curvature_r[0][1]; + qr[19] = extrinsic_curvature_r[0][2]; + qr[20] = extrinsic_curvature_r[1][0]; + qr[21] = extrinsic_curvature_r[1][1]; + qr[22] = extrinsic_curvature_r[1][2]; + qr[23] = extrinsic_curvature_r[2][0]; + qr[24] = extrinsic_curvature_r[2][1]; + qr[25] = extrinsic_curvature_r[2][2]; qr[26] = 1.0; - qr[27] = lapse_der_r[0]; qr[28] = lapse_der_r[1]; qr[29] = lapse_der_r[2]; - qr[30] = shift_der_r[0][0]; qr[31] = shift_der_r[0][1]; qr[32] = shift_der_r[0][2]; - qr[33] = shift_der_r[1][0]; qr[34] = shift_der_r[1][1]; qr[35] = shift_der_r[1][2]; - qr[36] = shift_der_r[2][0]; qr[37] = shift_der_r[2][1]; qr[38] = shift_der_r[2][2]; - - qr[39] = spatial_metric_der_r[0][0][0]; qr[40] = spatial_metric_der_r[0][0][1]; qr[41] = spatial_metric_der_r[0][0][2]; - qr[42] = spatial_metric_der_r[0][1][0]; qr[43] = spatial_metric_der_r[0][1][1]; qr[44] = spatial_metric_der_r[0][1][2]; - qr[45] = spatial_metric_der_r[0][2][0]; qr[46] = spatial_metric_der_r[0][2][1]; qr[47] = spatial_metric_der_r[0][2][2]; - - qr[48] = spatial_metric_der_r[1][0][0]; qr[49] = spatial_metric_der_r[1][0][1]; qr[50] = spatial_metric_der_r[1][0][2]; - qr[51] = spatial_metric_der_r[1][1][0]; qr[52] = spatial_metric_der_r[1][1][1]; qr[53] = spatial_metric_der_r[1][1][2]; - qr[54] = spatial_metric_der_r[1][2][0]; qr[55] = spatial_metric_der_r[1][2][1]; qr[56] = spatial_metric_der_r[1][2][2]; - - qr[57] = spatial_metric_der_r[2][0][0]; qr[58] = spatial_metric_der_r[2][0][1]; qr[59] = spatial_metric_der_r[2][0][2]; - qr[60] = spatial_metric_der_r[2][1][0]; qr[61] = spatial_metric_der_r[2][1][1]; qr[62] = spatial_metric_der_r[2][1][2]; - qr[63] = spatial_metric_der_r[2][2][0]; qr[64] = spatial_metric_der_r[2][2][1]; qr[65] = spatial_metric_der_r[2][2][2]; + qr[27] = lapse_der_r[0]; + qr[28] = lapse_der_r[1]; + qr[29] = lapse_der_r[2]; + qr[30] = shift_der_r[0][0]; + qr[31] = shift_der_r[0][1]; + qr[32] = shift_der_r[0][2]; + qr[33] = shift_der_r[1][0]; + qr[34] = shift_der_r[1][1]; + qr[35] = shift_der_r[1][2]; + qr[36] = shift_der_r[2][0]; + qr[37] = shift_der_r[2][1]; + qr[38] = shift_der_r[2][2]; + + qr[39] = spatial_metric_der_r[0][0][0]; + qr[40] = spatial_metric_der_r[0][0][1]; + qr[41] = spatial_metric_der_r[0][0][2]; + qr[42] = spatial_metric_der_r[0][1][0]; + qr[43] = spatial_metric_der_r[0][1][1]; + qr[44] = spatial_metric_der_r[0][1][2]; + qr[45] = spatial_metric_der_r[0][2][0]; + qr[46] = spatial_metric_der_r[0][2][1]; + qr[47] = spatial_metric_der_r[0][2][2]; + + qr[48] = spatial_metric_der_r[1][0][0]; + qr[49] = spatial_metric_der_r[1][0][1]; + qr[50] = spatial_metric_der_r[1][0][2]; + qr[51] = spatial_metric_der_r[1][1][0]; + qr[52] = spatial_metric_der_r[1][1][1]; + qr[53] = spatial_metric_der_r[1][1][2]; + qr[54] = spatial_metric_der_r[1][2][0]; + qr[55] = spatial_metric_der_r[1][2][1]; + qr[56] = spatial_metric_der_r[1][2][2]; + + qr[57] = spatial_metric_der_r[2][0][0]; + qr[58] = spatial_metric_der_r[2][0][1]; + qr[59] = spatial_metric_der_r[2][0][2]; + qr[60] = spatial_metric_der_r[2][1][0]; + qr[61] = spatial_metric_der_r[2][1][1]; + qr[62] = spatial_metric_der_r[2][1][2]; + qr[63] = spatial_metric_der_r[2][2][0]; + qr[64] = spatial_metric_der_r[2][2][1]; + qr[65] = spatial_metric_der_r[2][2][2]; qr[66] = 0.0; - qr[67] = x + 0.5; qr[68] = y; qr[69] = 0.0; + qr[67] = x + 0.5; + qr[68] = y; + qr[69] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 70], waves_local[3 * 70]; double ql_local[70], qr_local[70]; - gkyl_wv_eqn_rotate_to_local(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], ql, ql_local); - gkyl_wv_eqn_rotate_to_local(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], qr, qr_local); + gkyl_wv_eqn_rotate_to_local( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], ql, ql_local + ); + gkyl_wv_eqn_rotate_to_local( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], qr, qr_local + ); double delta[70]; for (int i = 0; i < 70; i++) { delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[70], amdq_local[70]; - gkyl_wv_eqn_qfluct(gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 70], &waves[i * 70]); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 70], + &waves[i * 70] + ); } double apdq[70], amdq[70]; - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); double fl_local_sr[70], fr_local_sr[70]; gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, ql_local, fl_local_sr); gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, qr_local, fr_local_sr); double fl_local_gr[70], fr_local_gr[70]; - gkyl_gr_ultra_rel_euler_tetrad_flux_correction(gas_gamma, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_ultra_rel_euler_tetrad_flux_correction(gas_gamma, qr_local, fr_local_sr, fr_local_gr); + gkyl_gr_ultra_rel_euler_tetrad_flux_correction( + gas_gamma, ql_local, fl_local_sr, fl_local_gr + ); + gkyl_gr_ultra_rel_euler_tetrad_flux_correction( + gas_gamma, qr_local, fr_local_sr, fr_local_gr + ); double fl[70], fr[70]; - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl + ); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr + ); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } @@ -872,7 +1187,7 @@ test_gr_ultra_rel_euler_tetrad_waves_minkowski_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -901,12 +1216,12 @@ test_gr_ultra_rel_euler_tetrad_waves_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho() +void test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho() { double gas_gamma = 2.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = + gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -924,10 +1239,10 @@ test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -937,18 +1252,18 @@ test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -967,20 +1282,46 @@ test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -992,7 +1333,7 @@ test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho() double W_l = 1.0 / sqrt(1.0 - v_sq_l); double W_r = 1.0 / sqrt(1.0 - v_sq_r); - + if (!in_excision_region_l && !in_excision_region_r) { double ql[70], qr[70]; ql[0] = sqrt(spatial_det_l) * (((rho_l + p_l) * (W_l * W_l)) - p_l); @@ -1001,37 +1342,79 @@ test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho() ql[3] = sqrt(spatial_det_l) * (rho_l + p_l) * (W_l * W_l) * w_l; ql[4] = lapse_l; - ql[5] = shift_l[0]; ql[6] = shift_l[1]; ql[7] = shift_l[2]; - - ql[8] = spatial_metric_l[0][0]; ql[9] = spatial_metric_l[0][1]; ql[10] = spatial_metric_l[0][2]; - ql[11] = spatial_metric_l[1][0]; ql[12] = spatial_metric_l[1][1]; ql[13] = spatial_metric_l[1][2]; - ql[14] = spatial_metric_l[2][0]; ql[15] = spatial_metric_l[2][1]; ql[16] = spatial_metric_l[2][2]; - - ql[17] = extrinsic_curvature_l[0][0]; ql[18] = extrinsic_curvature_l[0][1]; ql[19] = extrinsic_curvature_l[0][2]; - ql[20] = extrinsic_curvature_l[1][0]; ql[21] = extrinsic_curvature_l[1][1]; ql[22] = extrinsic_curvature_l[1][2]; - ql[23] = extrinsic_curvature_l[2][0]; ql[24] = extrinsic_curvature_l[2][1]; ql[25] = extrinsic_curvature_l[2][2]; + ql[5] = shift_l[0]; + ql[6] = shift_l[1]; + ql[7] = shift_l[2]; + + ql[8] = spatial_metric_l[0][0]; + ql[9] = spatial_metric_l[0][1]; + ql[10] = spatial_metric_l[0][2]; + ql[11] = spatial_metric_l[1][0]; + ql[12] = spatial_metric_l[1][1]; + ql[13] = spatial_metric_l[1][2]; + ql[14] = spatial_metric_l[2][0]; + ql[15] = spatial_metric_l[2][1]; + ql[16] = spatial_metric_l[2][2]; + + ql[17] = extrinsic_curvature_l[0][0]; + ql[18] = extrinsic_curvature_l[0][1]; + ql[19] = extrinsic_curvature_l[0][2]; + ql[20] = extrinsic_curvature_l[1][0]; + ql[21] = extrinsic_curvature_l[1][1]; + ql[22] = extrinsic_curvature_l[1][2]; + ql[23] = extrinsic_curvature_l[2][0]; + ql[24] = extrinsic_curvature_l[2][1]; + ql[25] = extrinsic_curvature_l[2][2]; ql[26] = 1.0; - ql[27] = lapse_der_l[0]; ql[28] = lapse_der_l[1]; ql[29] = lapse_der_l[2]; - ql[30] = shift_der_l[0][0]; ql[31] = shift_der_l[0][1]; ql[32] = shift_der_l[0][2]; - ql[33] = shift_der_l[1][0]; ql[34] = shift_der_l[1][1]; ql[35] = shift_der_l[1][2]; - ql[36] = shift_der_l[2][0]; ql[37] = shift_der_l[2][1]; ql[38] = shift_der_l[2][2]; - - ql[39] = spatial_metric_der_l[0][0][0]; ql[40] = spatial_metric_der_l[0][0][1]; ql[41] = spatial_metric_der_l[0][0][2]; - ql[42] = spatial_metric_der_l[0][1][0]; ql[43] = spatial_metric_der_l[0][1][1]; ql[44] = spatial_metric_der_l[0][1][2]; - ql[45] = spatial_metric_der_l[0][2][0]; ql[46] = spatial_metric_der_l[0][2][1]; ql[47] = spatial_metric_der_l[0][2][2]; - - ql[48] = spatial_metric_der_l[1][0][0]; ql[49] = spatial_metric_der_l[1][0][1]; ql[50] = spatial_metric_der_l[1][0][2]; - ql[51] = spatial_metric_der_l[1][1][0]; ql[52] = spatial_metric_der_l[1][1][1]; ql[53] = spatial_metric_der_l[1][1][2]; - ql[54] = spatial_metric_der_l[1][2][0]; ql[55] = spatial_metric_der_l[1][2][1]; ql[56] = spatial_metric_der_l[1][2][2]; - - ql[57] = spatial_metric_der_l[2][0][0]; ql[58] = spatial_metric_der_l[2][0][1]; ql[59] = spatial_metric_der_l[2][0][2]; - ql[60] = spatial_metric_der_l[2][1][0]; ql[61] = spatial_metric_der_l[2][1][1]; ql[62] = spatial_metric_der_l[2][1][2]; - ql[63] = spatial_metric_der_l[2][2][0]; ql[64] = spatial_metric_der_l[2][2][1]; ql[65] = spatial_metric_der_l[2][2][2]; + ql[27] = lapse_der_l[0]; + ql[28] = lapse_der_l[1]; + ql[29] = lapse_der_l[2]; + ql[30] = shift_der_l[0][0]; + ql[31] = shift_der_l[0][1]; + ql[32] = shift_der_l[0][2]; + ql[33] = shift_der_l[1][0]; + ql[34] = shift_der_l[1][1]; + ql[35] = shift_der_l[1][2]; + ql[36] = shift_der_l[2][0]; + ql[37] = shift_der_l[2][1]; + ql[38] = shift_der_l[2][2]; + + ql[39] = spatial_metric_der_l[0][0][0]; + ql[40] = spatial_metric_der_l[0][0][1]; + ql[41] = spatial_metric_der_l[0][0][2]; + ql[42] = spatial_metric_der_l[0][1][0]; + ql[43] = spatial_metric_der_l[0][1][1]; + ql[44] = spatial_metric_der_l[0][1][2]; + ql[45] = spatial_metric_der_l[0][2][0]; + ql[46] = spatial_metric_der_l[0][2][1]; + ql[47] = spatial_metric_der_l[0][2][2]; + + ql[48] = spatial_metric_der_l[1][0][0]; + ql[49] = spatial_metric_der_l[1][0][1]; + ql[50] = spatial_metric_der_l[1][0][2]; + ql[51] = spatial_metric_der_l[1][1][0]; + ql[52] = spatial_metric_der_l[1][1][1]; + ql[53] = spatial_metric_der_l[1][1][2]; + ql[54] = spatial_metric_der_l[1][2][0]; + ql[55] = spatial_metric_der_l[1][2][1]; + ql[56] = spatial_metric_der_l[1][2][2]; + + ql[57] = spatial_metric_der_l[2][0][0]; + ql[58] = spatial_metric_der_l[2][0][1]; + ql[59] = spatial_metric_der_l[2][0][2]; + ql[60] = spatial_metric_der_l[2][1][0]; + ql[61] = spatial_metric_der_l[2][1][1]; + ql[62] = spatial_metric_der_l[2][1][2]; + ql[63] = spatial_metric_der_l[2][2][0]; + ql[64] = spatial_metric_der_l[2][2][1]; + ql[65] = spatial_metric_der_l[2][2][2]; ql[66] = 0.0; - ql[67] = x - 0.5; ql[68] = y; ql[69] = 0.0; + ql[67] = x - 0.5; + ql[68] = y; + ql[69] = 0.0; qr[0] = sqrt(spatial_det_r) * (((rho_r + p_r) * (W_r * W_r)) - p_r); qr[1] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * u_r; @@ -1039,95 +1422,150 @@ test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho() qr[3] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * w_r; qr[4] = lapse_r; - qr[5] = shift_r[0]; qr[6] = shift_r[1]; qr[7] = shift_r[2]; - - qr[8] = spatial_metric_r[0][0]; qr[9] = spatial_metric_r[0][1]; qr[10] = spatial_metric_r[0][2]; - qr[11] = spatial_metric_r[1][0]; qr[12] = spatial_metric_r[1][1]; qr[13] = spatial_metric_r[1][2]; - qr[14] = spatial_metric_r[2][0]; qr[15] = spatial_metric_r[2][1]; qr[16] = spatial_metric_r[2][2]; - - qr[17] = extrinsic_curvature_r[0][0]; qr[18] = extrinsic_curvature_r[0][1]; qr[19] = extrinsic_curvature_r[0][2]; - qr[20] = extrinsic_curvature_r[1][0]; qr[21] = extrinsic_curvature_r[1][1]; qr[22] = extrinsic_curvature_r[1][2]; - qr[23] = extrinsic_curvature_r[2][0]; qr[24] = extrinsic_curvature_r[2][1]; qr[25] = extrinsic_curvature_r[2][2]; + qr[5] = shift_r[0]; + qr[6] = shift_r[1]; + qr[7] = shift_r[2]; + + qr[8] = spatial_metric_r[0][0]; + qr[9] = spatial_metric_r[0][1]; + qr[10] = spatial_metric_r[0][2]; + qr[11] = spatial_metric_r[1][0]; + qr[12] = spatial_metric_r[1][1]; + qr[13] = spatial_metric_r[1][2]; + qr[14] = spatial_metric_r[2][0]; + qr[15] = spatial_metric_r[2][1]; + qr[16] = spatial_metric_r[2][2]; + + qr[17] = extrinsic_curvature_r[0][0]; + qr[18] = extrinsic_curvature_r[0][1]; + qr[19] = extrinsic_curvature_r[0][2]; + qr[20] = extrinsic_curvature_r[1][0]; + qr[21] = extrinsic_curvature_r[1][1]; + qr[22] = extrinsic_curvature_r[1][2]; + qr[23] = extrinsic_curvature_r[2][0]; + qr[24] = extrinsic_curvature_r[2][1]; + qr[25] = extrinsic_curvature_r[2][2]; qr[26] = 1.0; - qr[27] = lapse_der_r[0]; qr[28] = lapse_der_r[1]; qr[29] = lapse_der_r[2]; - qr[30] = shift_der_r[0][0]; qr[31] = shift_der_r[0][1]; qr[32] = shift_der_r[0][2]; - qr[33] = shift_der_r[1][0]; qr[34] = shift_der_r[1][1]; qr[35] = shift_der_r[1][2]; - qr[36] = shift_der_r[2][0]; qr[37] = shift_der_r[2][1]; qr[38] = shift_der_r[2][2]; - - qr[39] = spatial_metric_der_r[0][0][0]; qr[40] = spatial_metric_der_r[0][0][1]; qr[41] = spatial_metric_der_r[0][0][2]; - qr[42] = spatial_metric_der_r[0][1][0]; qr[43] = spatial_metric_der_r[0][1][1]; qr[44] = spatial_metric_der_r[0][1][2]; - qr[45] = spatial_metric_der_r[0][2][0]; qr[46] = spatial_metric_der_r[0][2][1]; qr[47] = spatial_metric_der_r[0][2][2]; - - qr[48] = spatial_metric_der_r[1][0][0]; qr[49] = spatial_metric_der_r[1][0][1]; qr[50] = spatial_metric_der_r[1][0][2]; - qr[51] = spatial_metric_der_r[1][1][0]; qr[52] = spatial_metric_der_r[1][1][1]; qr[53] = spatial_metric_der_r[1][1][2]; - qr[54] = spatial_metric_der_r[1][2][0]; qr[55] = spatial_metric_der_r[1][2][1]; qr[56] = spatial_metric_der_r[1][2][2]; - - qr[57] = spatial_metric_der_r[2][0][0]; qr[58] = spatial_metric_der_r[2][0][1]; qr[59] = spatial_metric_der_r[2][0][2]; - qr[60] = spatial_metric_der_r[2][1][0]; qr[61] = spatial_metric_der_r[2][1][1]; qr[62] = spatial_metric_der_r[2][1][2]; - qr[63] = spatial_metric_der_r[2][2][0]; qr[64] = spatial_metric_der_r[2][2][1]; qr[65] = spatial_metric_der_r[2][2][2]; + qr[27] = lapse_der_r[0]; + qr[28] = lapse_der_r[1]; + qr[29] = lapse_der_r[2]; + qr[30] = shift_der_r[0][0]; + qr[31] = shift_der_r[0][1]; + qr[32] = shift_der_r[0][2]; + qr[33] = shift_der_r[1][0]; + qr[34] = shift_der_r[1][1]; + qr[35] = shift_der_r[1][2]; + qr[36] = shift_der_r[2][0]; + qr[37] = shift_der_r[2][1]; + qr[38] = shift_der_r[2][2]; + + qr[39] = spatial_metric_der_r[0][0][0]; + qr[40] = spatial_metric_der_r[0][0][1]; + qr[41] = spatial_metric_der_r[0][0][2]; + qr[42] = spatial_metric_der_r[0][1][0]; + qr[43] = spatial_metric_der_r[0][1][1]; + qr[44] = spatial_metric_der_r[0][1][2]; + qr[45] = spatial_metric_der_r[0][2][0]; + qr[46] = spatial_metric_der_r[0][2][1]; + qr[47] = spatial_metric_der_r[0][2][2]; + + qr[48] = spatial_metric_der_r[1][0][0]; + qr[49] = spatial_metric_der_r[1][0][1]; + qr[50] = spatial_metric_der_r[1][0][2]; + qr[51] = spatial_metric_der_r[1][1][0]; + qr[52] = spatial_metric_der_r[1][1][1]; + qr[53] = spatial_metric_der_r[1][1][2]; + qr[54] = spatial_metric_der_r[1][2][0]; + qr[55] = spatial_metric_der_r[1][2][1]; + qr[56] = spatial_metric_der_r[1][2][2]; + + qr[57] = spatial_metric_der_r[2][0][0]; + qr[58] = spatial_metric_der_r[2][0][1]; + qr[59] = spatial_metric_der_r[2][0][2]; + qr[60] = spatial_metric_der_r[2][1][0]; + qr[61] = spatial_metric_der_r[2][1][1]; + qr[62] = spatial_metric_der_r[2][1][2]; + qr[63] = spatial_metric_der_r[2][2][0]; + qr[64] = spatial_metric_der_r[2][2][1]; + qr[65] = spatial_metric_der_r[2][2][2]; qr[66] = 0.0; - qr[67] = x + 0.5; qr[68] = y; qr[69] = 0.0; + qr[67] = x + 0.5; + qr[68] = y; + qr[69] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 70], waves_local[3 * 70]; double ql_local[70], qr_local[70]; - gkyl_wv_eqn_rotate_to_local(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], ql, ql_local); - gkyl_wv_eqn_rotate_to_local(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], qr, qr_local); + gkyl_wv_eqn_rotate_to_local( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], ql, ql_local + ); + gkyl_wv_eqn_rotate_to_local( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], qr, qr_local + ); double delta[70]; for (int i = 0; i < 70; i++) { delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[70], amdq_local[70]; - gkyl_wv_eqn_qfluct(gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 70], &waves[i * 70]); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 70], + &waves[i * 70] + ); } double apdq[70], amdq[70]; - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq); - - double fl_local_sr[70], fr_local_sr[70]; - gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, ql_local, fl_local_sr); - gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, qr_local, fr_local_sr); - - double fl_local_gr[70], fr_local_gr[70]; - gkyl_gr_ultra_rel_euler_tetrad_flux_correction(gas_gamma, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_ultra_rel_euler_tetrad_flux_correction(gas_gamma, qr_local, fr_local_sr, fr_local_gr); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); + + double fl_local_sr[70], fr_local_sr[70]; + gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, ql_local, fl_local_sr); + gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, qr_local, fr_local_sr); + + double fl_local_gr[70], fr_local_gr[70]; + gkyl_gr_ultra_rel_euler_tetrad_flux_correction( + gas_gamma, ql_local, fl_local_sr, fl_local_gr + ); + gkyl_gr_ultra_rel_euler_tetrad_flux_correction( + gas_gamma, qr_local, fr_local_sr, fr_local_gr + ); double fl[70], fr[70]; - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl + ); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr + ); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } @@ -1139,7 +1577,7 @@ test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1168,12 +1606,12 @@ test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_gr_ultra_rel_euler_tetrad_waves_kerr_ho() +void test_gr_ultra_rel_euler_tetrad_waves_kerr_ho() { double gas_gamma = 2.0; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); + struct gkyl_wv_eqn *gr_ultra_rel_euler_tetrad = + gkyl_wv_gr_ultra_rel_euler_tetrad_new(gas_gamma, GKYL_STATIC_GAUGE, 0, spacetime, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1191,10 +1629,10 @@ test_gr_ultra_rel_euler_tetrad_waves_kerr_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1204,18 +1642,18 @@ test_gr_ultra_rel_euler_tetrad_waves_kerr_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1234,20 +1672,46 @@ test_gr_ultra_rel_euler_tetrad_waves_kerr_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der_r); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der_r + ); double *vel_l = gkyl_malloc(sizeof(double[3])); double *vel_r = gkyl_malloc(sizeof(double[3])); - vel_l[0] = u_l; vel_l[1] = v_l; vel_l[2] = w_l; - vel_r[0] = u_r; vel_r[1] = v_r; vel_r[2] = w_r; + vel_l[0] = u_l; + vel_l[1] = v_l; + vel_l[2] = w_l; + vel_r[0] = u_r; + vel_r[1] = v_r; + vel_r[2] = w_r; double v_sq_l = 0.0, v_sq_r = 0.0; for (int i = 0; i < 3; i++) { @@ -1259,7 +1723,7 @@ test_gr_ultra_rel_euler_tetrad_waves_kerr_ho() double W_l = 1.0 / sqrt(1.0 - v_sq_l); double W_r = 1.0 / sqrt(1.0 - v_sq_r); - + if (!in_excision_region_l && !in_excision_region_r) { double ql[70], qr[70]; ql[0] = sqrt(spatial_det_l) * (((rho_l + p_l) * (W_l * W_l)) - p_l); @@ -1268,37 +1732,79 @@ test_gr_ultra_rel_euler_tetrad_waves_kerr_ho() ql[3] = sqrt(spatial_det_l) * (rho_l + p_l) * (W_l * W_l) * w_l; ql[4] = lapse_l; - ql[5] = shift_l[0]; ql[6] = shift_l[1]; ql[7] = shift_l[2]; - - ql[8] = spatial_metric_l[0][0]; ql[9] = spatial_metric_l[0][1]; ql[10] = spatial_metric_l[0][2]; - ql[11] = spatial_metric_l[1][0]; ql[12] = spatial_metric_l[1][1]; ql[13] = spatial_metric_l[1][2]; - ql[14] = spatial_metric_l[2][0]; ql[15] = spatial_metric_l[2][1]; ql[16] = spatial_metric_l[2][2]; - - ql[17] = extrinsic_curvature_l[0][0]; ql[18] = extrinsic_curvature_l[0][1]; ql[19] = extrinsic_curvature_l[0][2]; - ql[20] = extrinsic_curvature_l[1][0]; ql[21] = extrinsic_curvature_l[1][1]; ql[22] = extrinsic_curvature_l[1][2]; - ql[23] = extrinsic_curvature_l[2][0]; ql[24] = extrinsic_curvature_l[2][1]; ql[25] = extrinsic_curvature_l[2][2]; + ql[5] = shift_l[0]; + ql[6] = shift_l[1]; + ql[7] = shift_l[2]; + + ql[8] = spatial_metric_l[0][0]; + ql[9] = spatial_metric_l[0][1]; + ql[10] = spatial_metric_l[0][2]; + ql[11] = spatial_metric_l[1][0]; + ql[12] = spatial_metric_l[1][1]; + ql[13] = spatial_metric_l[1][2]; + ql[14] = spatial_metric_l[2][0]; + ql[15] = spatial_metric_l[2][1]; + ql[16] = spatial_metric_l[2][2]; + + ql[17] = extrinsic_curvature_l[0][0]; + ql[18] = extrinsic_curvature_l[0][1]; + ql[19] = extrinsic_curvature_l[0][2]; + ql[20] = extrinsic_curvature_l[1][0]; + ql[21] = extrinsic_curvature_l[1][1]; + ql[22] = extrinsic_curvature_l[1][2]; + ql[23] = extrinsic_curvature_l[2][0]; + ql[24] = extrinsic_curvature_l[2][1]; + ql[25] = extrinsic_curvature_l[2][2]; ql[26] = 1.0; - ql[27] = lapse_der_l[0]; ql[28] = lapse_der_l[1]; ql[29] = lapse_der_l[2]; - ql[30] = shift_der_l[0][0]; ql[31] = shift_der_l[0][1]; ql[32] = shift_der_l[0][2]; - ql[33] = shift_der_l[1][0]; ql[34] = shift_der_l[1][1]; ql[35] = shift_der_l[1][2]; - ql[36] = shift_der_l[2][0]; ql[37] = shift_der_l[2][1]; ql[38] = shift_der_l[2][2]; - - ql[39] = spatial_metric_der_l[0][0][0]; ql[40] = spatial_metric_der_l[0][0][1]; ql[41] = spatial_metric_der_l[0][0][2]; - ql[42] = spatial_metric_der_l[0][1][0]; ql[43] = spatial_metric_der_l[0][1][1]; ql[44] = spatial_metric_der_l[0][1][2]; - ql[45] = spatial_metric_der_l[0][2][0]; ql[46] = spatial_metric_der_l[0][2][1]; ql[47] = spatial_metric_der_l[0][2][2]; - - ql[48] = spatial_metric_der_l[1][0][0]; ql[49] = spatial_metric_der_l[1][0][1]; ql[50] = spatial_metric_der_l[1][0][2]; - ql[51] = spatial_metric_der_l[1][1][0]; ql[52] = spatial_metric_der_l[1][1][1]; ql[53] = spatial_metric_der_l[1][1][2]; - ql[54] = spatial_metric_der_l[1][2][0]; ql[55] = spatial_metric_der_l[1][2][1]; ql[56] = spatial_metric_der_l[1][2][2]; - - ql[57] = spatial_metric_der_l[2][0][0]; ql[58] = spatial_metric_der_l[2][0][1]; ql[59] = spatial_metric_der_l[2][0][2]; - ql[60] = spatial_metric_der_l[2][1][0]; ql[61] = spatial_metric_der_l[2][1][1]; ql[62] = spatial_metric_der_l[2][1][2]; - ql[63] = spatial_metric_der_l[2][2][0]; ql[64] = spatial_metric_der_l[2][2][1]; ql[65] = spatial_metric_der_l[2][2][2]; + ql[27] = lapse_der_l[0]; + ql[28] = lapse_der_l[1]; + ql[29] = lapse_der_l[2]; + ql[30] = shift_der_l[0][0]; + ql[31] = shift_der_l[0][1]; + ql[32] = shift_der_l[0][2]; + ql[33] = shift_der_l[1][0]; + ql[34] = shift_der_l[1][1]; + ql[35] = shift_der_l[1][2]; + ql[36] = shift_der_l[2][0]; + ql[37] = shift_der_l[2][1]; + ql[38] = shift_der_l[2][2]; + + ql[39] = spatial_metric_der_l[0][0][0]; + ql[40] = spatial_metric_der_l[0][0][1]; + ql[41] = spatial_metric_der_l[0][0][2]; + ql[42] = spatial_metric_der_l[0][1][0]; + ql[43] = spatial_metric_der_l[0][1][1]; + ql[44] = spatial_metric_der_l[0][1][2]; + ql[45] = spatial_metric_der_l[0][2][0]; + ql[46] = spatial_metric_der_l[0][2][1]; + ql[47] = spatial_metric_der_l[0][2][2]; + + ql[48] = spatial_metric_der_l[1][0][0]; + ql[49] = spatial_metric_der_l[1][0][1]; + ql[50] = spatial_metric_der_l[1][0][2]; + ql[51] = spatial_metric_der_l[1][1][0]; + ql[52] = spatial_metric_der_l[1][1][1]; + ql[53] = spatial_metric_der_l[1][1][2]; + ql[54] = spatial_metric_der_l[1][2][0]; + ql[55] = spatial_metric_der_l[1][2][1]; + ql[56] = spatial_metric_der_l[1][2][2]; + + ql[57] = spatial_metric_der_l[2][0][0]; + ql[58] = spatial_metric_der_l[2][0][1]; + ql[59] = spatial_metric_der_l[2][0][2]; + ql[60] = spatial_metric_der_l[2][1][0]; + ql[61] = spatial_metric_der_l[2][1][1]; + ql[62] = spatial_metric_der_l[2][1][2]; + ql[63] = spatial_metric_der_l[2][2][0]; + ql[64] = spatial_metric_der_l[2][2][1]; + ql[65] = spatial_metric_der_l[2][2][2]; ql[66] = 0.0; - ql[67] = x - 0.5; ql[68] = y; ql[69] = 0.0; + ql[67] = x - 0.5; + ql[68] = y; + ql[69] = 0.0; qr[0] = sqrt(spatial_det_r) * (((rho_r + p_r) * (W_r * W_r)) - p_r); qr[1] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * u_r; @@ -1306,95 +1812,150 @@ test_gr_ultra_rel_euler_tetrad_waves_kerr_ho() qr[3] = sqrt(spatial_det_r) * (rho_r + p_r) * (W_r * W_r) * w_r; qr[4] = lapse_r; - qr[5] = shift_r[0]; qr[6] = shift_r[1]; qr[7] = shift_r[2]; - - qr[8] = spatial_metric_r[0][0]; qr[9] = spatial_metric_r[0][1]; qr[10] = spatial_metric_r[0][2]; - qr[11] = spatial_metric_r[1][0]; qr[12] = spatial_metric_r[1][1]; qr[13] = spatial_metric_r[1][2]; - qr[14] = spatial_metric_r[2][0]; qr[15] = spatial_metric_r[2][1]; qr[16] = spatial_metric_r[2][2]; - - qr[17] = extrinsic_curvature_r[0][0]; qr[18] = extrinsic_curvature_r[0][1]; qr[19] = extrinsic_curvature_r[0][2]; - qr[20] = extrinsic_curvature_r[1][0]; qr[21] = extrinsic_curvature_r[1][1]; qr[22] = extrinsic_curvature_r[1][2]; - qr[23] = extrinsic_curvature_r[2][0]; qr[24] = extrinsic_curvature_r[2][1]; qr[25] = extrinsic_curvature_r[2][2]; + qr[5] = shift_r[0]; + qr[6] = shift_r[1]; + qr[7] = shift_r[2]; + + qr[8] = spatial_metric_r[0][0]; + qr[9] = spatial_metric_r[0][1]; + qr[10] = spatial_metric_r[0][2]; + qr[11] = spatial_metric_r[1][0]; + qr[12] = spatial_metric_r[1][1]; + qr[13] = spatial_metric_r[1][2]; + qr[14] = spatial_metric_r[2][0]; + qr[15] = spatial_metric_r[2][1]; + qr[16] = spatial_metric_r[2][2]; + + qr[17] = extrinsic_curvature_r[0][0]; + qr[18] = extrinsic_curvature_r[0][1]; + qr[19] = extrinsic_curvature_r[0][2]; + qr[20] = extrinsic_curvature_r[1][0]; + qr[21] = extrinsic_curvature_r[1][1]; + qr[22] = extrinsic_curvature_r[1][2]; + qr[23] = extrinsic_curvature_r[2][0]; + qr[24] = extrinsic_curvature_r[2][1]; + qr[25] = extrinsic_curvature_r[2][2]; qr[26] = 1.0; - qr[27] = lapse_der_r[0]; qr[28] = lapse_der_r[1]; qr[29] = lapse_der_r[2]; - qr[30] = shift_der_r[0][0]; qr[31] = shift_der_r[0][1]; qr[32] = shift_der_r[0][2]; - qr[33] = shift_der_r[1][0]; qr[34] = shift_der_r[1][1]; qr[35] = shift_der_r[1][2]; - qr[36] = shift_der_r[2][0]; qr[37] = shift_der_r[2][1]; qr[38] = shift_der_r[2][2]; - - qr[39] = spatial_metric_der_r[0][0][0]; qr[40] = spatial_metric_der_r[0][0][1]; qr[41] = spatial_metric_der_r[0][0][2]; - qr[42] = spatial_metric_der_r[0][1][0]; qr[43] = spatial_metric_der_r[0][1][1]; qr[44] = spatial_metric_der_r[0][1][2]; - qr[45] = spatial_metric_der_r[0][2][0]; qr[46] = spatial_metric_der_r[0][2][1]; qr[47] = spatial_metric_der_r[0][2][2]; - - qr[48] = spatial_metric_der_r[1][0][0]; qr[49] = spatial_metric_der_r[1][0][1]; qr[50] = spatial_metric_der_r[1][0][2]; - qr[51] = spatial_metric_der_r[1][1][0]; qr[52] = spatial_metric_der_r[1][1][1]; qr[53] = spatial_metric_der_r[1][1][2]; - qr[54] = spatial_metric_der_r[1][2][0]; qr[55] = spatial_metric_der_r[1][2][1]; qr[56] = spatial_metric_der_r[1][2][2]; - - qr[57] = spatial_metric_der_r[2][0][0]; qr[58] = spatial_metric_der_r[2][0][1]; qr[59] = spatial_metric_der_r[2][0][2]; - qr[60] = spatial_metric_der_r[2][1][0]; qr[61] = spatial_metric_der_r[2][1][1]; qr[62] = spatial_metric_der_r[2][1][2]; - qr[63] = spatial_metric_der_r[2][2][0]; qr[64] = spatial_metric_der_r[2][2][1]; qr[65] = spatial_metric_der_r[2][2][2]; + qr[27] = lapse_der_r[0]; + qr[28] = lapse_der_r[1]; + qr[29] = lapse_der_r[2]; + qr[30] = shift_der_r[0][0]; + qr[31] = shift_der_r[0][1]; + qr[32] = shift_der_r[0][2]; + qr[33] = shift_der_r[1][0]; + qr[34] = shift_der_r[1][1]; + qr[35] = shift_der_r[1][2]; + qr[36] = shift_der_r[2][0]; + qr[37] = shift_der_r[2][1]; + qr[38] = shift_der_r[2][2]; + + qr[39] = spatial_metric_der_r[0][0][0]; + qr[40] = spatial_metric_der_r[0][0][1]; + qr[41] = spatial_metric_der_r[0][0][2]; + qr[42] = spatial_metric_der_r[0][1][0]; + qr[43] = spatial_metric_der_r[0][1][1]; + qr[44] = spatial_metric_der_r[0][1][2]; + qr[45] = spatial_metric_der_r[0][2][0]; + qr[46] = spatial_metric_der_r[0][2][1]; + qr[47] = spatial_metric_der_r[0][2][2]; + + qr[48] = spatial_metric_der_r[1][0][0]; + qr[49] = spatial_metric_der_r[1][0][1]; + qr[50] = spatial_metric_der_r[1][0][2]; + qr[51] = spatial_metric_der_r[1][1][0]; + qr[52] = spatial_metric_der_r[1][1][1]; + qr[53] = spatial_metric_der_r[1][1][2]; + qr[54] = spatial_metric_der_r[1][2][0]; + qr[55] = spatial_metric_der_r[1][2][1]; + qr[56] = spatial_metric_der_r[1][2][2]; + + qr[57] = spatial_metric_der_r[2][0][0]; + qr[58] = spatial_metric_der_r[2][0][1]; + qr[59] = spatial_metric_der_r[2][0][2]; + qr[60] = spatial_metric_der_r[2][1][0]; + qr[61] = spatial_metric_der_r[2][1][1]; + qr[62] = spatial_metric_der_r[2][1][2]; + qr[63] = spatial_metric_der_r[2][2][0]; + qr[64] = spatial_metric_der_r[2][2][1]; + qr[65] = spatial_metric_der_r[2][2][2]; qr[66] = 0.0; - qr[67] = x + 0.5; qr[68] = y; qr[69] = 0.0; + qr[67] = x + 0.5; + qr[68] = y; + qr[69] = 0.0; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[3], waves[3 * 70], waves_local[3 * 70]; double ql_local[70], qr_local[70]; - gkyl_wv_eqn_rotate_to_local(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], ql, ql_local); - gkyl_wv_eqn_rotate_to_local(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], qr, qr_local); + gkyl_wv_eqn_rotate_to_local( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], ql, ql_local + ); + gkyl_wv_eqn_rotate_to_local( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], qr, qr_local + ); double delta[70]; for (int i = 0; i < 70; i++) { delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[70], amdq_local[70]; - gkyl_wv_eqn_qfluct(gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + gr_ultra_rel_euler_tetrad, GKYL_WV_LOW_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds, amdq_local, apdq_local + ); for (int i = 0; i < 3; i++) { - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 70], &waves[i * 70]); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], &waves_local[i * 70], + &waves[i * 70] + ); } double apdq[70], amdq[70]; - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq); - - double fl_local_sr[70], fr_local_sr[70]; - gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, ql_local, fl_local_sr); - gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, qr_local, fr_local_sr); - - double fl_local_gr[70], fr_local_gr[70]; - gkyl_gr_ultra_rel_euler_tetrad_flux_correction(gas_gamma, ql_local, fl_local_sr, fl_local_gr); - gkyl_gr_ultra_rel_euler_tetrad_flux_correction(gas_gamma, qr_local, fr_local_sr, fr_local_gr); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); + + double fl_local_sr[70], fr_local_sr[70]; + gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, ql_local, fl_local_sr); + gkyl_gr_ultra_rel_euler_tetrad_flux(gas_gamma, qr_local, fr_local_sr); + + double fl_local_gr[70], fr_local_gr[70]; + gkyl_gr_ultra_rel_euler_tetrad_flux_correction( + gas_gamma, ql_local, fl_local_sr, fl_local_gr + ); + gkyl_gr_ultra_rel_euler_tetrad_flux_correction( + gas_gamma, qr_local, fr_local_sr, fr_local_gr + ); double fl[70], fr[70]; - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl); - gkyl_wv_eqn_rotate_to_global(gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fl_local_gr, fl + ); + gkyl_wv_eqn_rotate_to_global( + gr_ultra_rel_euler_tetrad, tau1[d], tau2[d], norm[d], fr_local_gr, fr + ); for (int i = 0; i < 70; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-11) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-11)); } } } @@ -1406,7 +1967,7 @@ test_gr_ultra_rel_euler_tetrad_waves_kerr_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1436,11 +1997,15 @@ test_gr_ultra_rel_euler_tetrad_waves_kerr_ho() } TEST_LIST = { - { "gr_ultra_rel_euler_tetrad_basic_minkowski_ho", test_gr_ultra_rel_euler_tetrad_basic_minkowski_ho }, - { "gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho", test_gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho }, - { "gr_ultra_rel_euler_tetrad_basic_kerr_ho", test_gr_ultra_rel_euler_tetrad_basic_kerr_ho }, - { "gr_ultra_rel_euler_tetrad_waves_minkowski_ho", test_gr_ultra_rel_euler_tetrad_waves_minkowski_ho }, - { "gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho", test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho }, - { "gr_ultra_rel_euler_tetrad_waves_kerr_ho", test_gr_ultra_rel_euler_tetrad_waves_kerr_ho }, - { NULL, NULL }, + {"gr_ultra_rel_euler_tetrad_basic_minkowski_ho", test_gr_ultra_rel_euler_tetrad_basic_minkowski_ho + }, + {"gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho", + test_gr_ultra_rel_euler_tetrad_basic_schwarzschild_ho}, + {"gr_ultra_rel_euler_tetrad_basic_kerr_ho", test_gr_ultra_rel_euler_tetrad_basic_kerr_ho}, + {"gr_ultra_rel_euler_tetrad_waves_minkowski_ho", test_gr_ultra_rel_euler_tetrad_waves_minkowski_ho + }, + {"gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho", + test_gr_ultra_rel_euler_tetrad_waves_schwarzschild_ho}, + {"gr_ultra_rel_euler_tetrad_waves_kerr_ho", test_gr_ultra_rel_euler_tetrad_waves_kerr_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_iso_euler.c b/moments/unit/ctest_wv_iso_euler.c index e20ab47a7b..1bc40e11e5 100644 --- a/moments/unit/ctest_wv_iso_euler.c +++ b/moments/unit/ctest_wv_iso_euler.c @@ -2,232 +2,218 @@ #include #include -void -calcq(const double pv[4], double q[4]) +void calcq(const double pv[4], double q[4]) { double rho = pv[0], u = pv[1], v = pv[2], w = pv[3]; q[0] = rho; - q[1] = rho*u; q[2] = rho*v; q[3] = rho*w; + q[1] = rho * u; + q[2] = rho * v; + q[3] = rho * w; } -void -test_iso_euler_basic_ho() +void test_iso_euler_basic_ho() { double vt = 1.0; struct gkyl_wv_eqn *iso_euler = gkyl_wv_iso_euler_new(vt, false); - TEST_CHECK( iso_euler->num_equations == 4 ); - TEST_CHECK( iso_euler->num_waves == 3 ); + TEST_CHECK(iso_euler->num_equations == 4); + TEST_CHECK(iso_euler->num_waves == 3); double rho = 1.0, u = 0.1, v = 0.2, w = 0.3; - double q[4], q_local[4], pv[4] = { rho, u, v, w }; + double q[4], q_local[4], pv[4] = {rho, u, v, w}; calcq(pv, q); double fluxes[3][4] = { - { rho*u, rho*(u*u+vt*vt), rho*u*v, rho*u*w }, - { rho*v, rho*u*v, rho*(v*v+vt*vt), rho*v*w }, - { rho*w, rho*u*w, rho*v*w, rho*(w*w+vt*vt) }, - }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 } + {rho * u, rho * (u * u + vt * vt), rho * u * v, rho * u * w}, + {rho * v, rho * u * v, rho * (v * v + vt * vt), rho * v * w}, + {rho * w, rho * u * w, rho * v * w, rho * (w * w + vt * vt)} }; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; - double flux[4], flux_local[4]; - for (int d=1; d<2; ++d) { + double flux[4], flux_local[4]; + for (int d = 1; d < 2; ++d) { iso_euler->rotate_to_local_func(iso_euler, tau1[d], tau2[d], norm[d], q, q_local); gkyl_iso_euler_flux(vt, q_local, flux_local); iso_euler->rotate_to_global_func(iso_euler, tau1[d], tau2[d], norm[d], flux_local, flux); - - for (int m=0; m<4; ++m) - TEST_CHECK( gkyl_compare(flux[m], fluxes[d][m], 1e-15) ); + + for (int m = 0; m < 4; ++m) { + TEST_CHECK(gkyl_compare(flux[m], fluxes[d][m], 1e-15)); + } // check Riemann transform double w1[4], q1[4]; iso_euler->cons_to_riem(iso_euler, q_local, q_local, w1); iso_euler->riem_to_cons(iso_euler, q_local, w1, q1); - - for (int m=0; m<4; ++m) - TEST_CHECK( gkyl_compare_double(q_local[m], q1[m], 1e-14) ); - } + + for (int m = 0; m < 4; ++m) { + TEST_CHECK(gkyl_compare_double(q_local[m], q1[m], 1e-14)); + } + } iso_euler->rotate_to_local_func(iso_euler, tau1[0], tau2[0], norm[0], q, q_local); gkyl_iso_euler_flux(vt, q_local, flux_local); iso_euler->rotate_to_global_func(iso_euler, tau1[0], tau2[0], norm[0], flux_local, flux); - TEST_CHECK( flux[0] == rho*u ); - TEST_CHECK( flux[1] == rho*(u*u + vt*vt) ); - TEST_CHECK( flux[2] == rho*u*v ); - TEST_CHECK( flux[3] == rho*u*w ); + TEST_CHECK(flux[0] == rho * u); + TEST_CHECK(flux[1] == rho * (u * u + vt * vt)); + TEST_CHECK(flux[2] == rho * u * v); + TEST_CHECK(flux[3] == rho * u * w); iso_euler->rotate_to_local_func(iso_euler, tau1[1], tau2[1], norm[1], q, q_local); gkyl_iso_euler_flux(vt, q_local, flux_local); iso_euler->rotate_to_global_func(iso_euler, tau1[1], tau2[1], norm[1], flux_local, flux); - - TEST_CHECK( flux[0] == rho*v ); - TEST_CHECK( flux[1] == rho*v*u ); - TEST_CHECK( flux[2] == rho*(v*v + vt*vt) ); - TEST_CHECK( flux[3] == rho*v*w ); + + TEST_CHECK(flux[0] == rho * v); + TEST_CHECK(flux[1] == rho * v * u); + TEST_CHECK(flux[2] == rho * (v * v + vt * vt)); + TEST_CHECK(flux[3] == rho * v * w); iso_euler->rotate_to_local_func(iso_euler, tau1[2], tau2[2], norm[2], q, q_local); gkyl_iso_euler_flux(vt, q_local, flux_local); iso_euler->rotate_to_global_func(iso_euler, tau1[2], tau2[2], norm[2], flux_local, flux); - TEST_CHECK( flux[0] == rho*w ); - TEST_CHECK( flux[1] == rho*w*u ); - TEST_CHECK( flux[2] == rho*w*v ); - TEST_CHECK( flux[3] == rho*(w*w + vt*vt) ); - + TEST_CHECK(flux[0] == rho * w); + TEST_CHECK(flux[1] == rho * w * u); + TEST_CHECK(flux[2] == rho * w * v); + TEST_CHECK(flux[3] == rho * (w * w + vt * vt)); + gkyl_wv_eqn_release(iso_euler); } -void -test_iso_euler_waves_ho() +void test_iso_euler_waves_ho() { double vt = 1.0; struct gkyl_wv_eqn *iso_euler = gkyl_wv_iso_euler_new(vt, false); - double vl[4] = { 1.0, 0.1, 0.2, 0.3}; - double vr[4] = { 0.1, 1.0, 2.0, 3.0}; + double vl[4] = {1.0, 0.1, 0.2, 0.3}; + double vr[4] = {0.1, 1.0, 2.0, 3.0}; double ql[4], qr[4]; double ql_local[4], qr_local[4]; - calcq(vl, ql); calcq(vr, qr); + calcq(vl, ql); + calcq(vr, qr); - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; - for (int d=0; d<3; ++d) { - double speeds[3], waves[3*4], waves_local[3*4]; + for (int d = 0; d < 3; ++d) { + double speeds[3], waves[3 * 4], waves_local[3 * 4]; // rotate to local tangent-normal frame gkyl_wv_eqn_rotate_to_local(iso_euler, tau1[d], tau2[d], norm[d], ql, ql_local); gkyl_wv_eqn_rotate_to_local(iso_euler, tau1[d], tau2[d], norm[d], qr, qr_local); double delta[4]; - for (int i=0; i<4; ++i) delta[i] = qr_local[i]-ql_local[i]; - - gkyl_wv_eqn_waves(iso_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + for (int i = 0; i < 4; ++i) { + delta[i] = qr_local[i] - ql_local[i]; + } + + gkyl_wv_eqn_waves( + iso_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); // rotate waves back to global frame - for (int mw=0; mw<3; ++mw) - gkyl_wv_eqn_rotate_to_global(iso_euler, tau1[d], tau2[d], norm[d], &waves_local[mw*4], &waves[mw*4]); - + for (int mw = 0; mw < 3; ++mw) { + gkyl_wv_eqn_rotate_to_global( + iso_euler, tau1[d], tau2[d], norm[d], &waves_local[mw * 4], &waves[mw * 4] + ); + } + double apdq[4], amdq[4]; - gkyl_wv_eqn_qfluct(iso_euler, GKYL_WV_HIGH_ORDER_FLUX, ql, qr, 1.0, 1.0, waves, speeds, amdq, apdq); - + gkyl_wv_eqn_qfluct( + iso_euler, GKYL_WV_HIGH_ORDER_FLUX, ql, qr, 1.0, 1.0, waves, speeds, amdq, apdq + ); + // check if sum of left/right going fluctuations sum to jump in flux double fl_local[4], fr_local[4]; gkyl_iso_euler_flux(vt, ql_local, fl_local); gkyl_iso_euler_flux(vt, qr_local, fr_local); - + double fl[4], fr[4]; gkyl_wv_eqn_rotate_to_global(iso_euler, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(iso_euler, tau1[d], tau2[d], norm[d], fr_local, fr); - - for (int i=0; i<4; ++i) - TEST_CHECK( gkyl_compare(fr[i]-fl[i], amdq[i]+apdq[i], 1e-14) ); + + for (int i = 0; i < 4; ++i) { + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); + } } - + gkyl_wv_eqn_release(iso_euler); } -void -test_iso_euler_waves_2_ho() +void test_iso_euler_waves_2_ho() { double vt = 10.0; struct gkyl_wv_eqn *iso_euler = gkyl_wv_iso_euler_new(vt, false); - double vl[4] = { 1.0, 0.1, 0.2, 0.3}; - double vr[4] = { 0.01, 1.0, 2.0, 3.0}; + double vl[4] = {1.0, 0.1, 0.2, 0.3}; + double vr[4] = {0.01, 1.0, 2.0, 3.0}; double ql[4], qr[4]; double ql_local[4], qr_local[4]; - calcq(vl, ql); calcq(vr, qr); + calcq(vl, ql); + calcq(vr, qr); - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; - for (int d=0; d<3; ++d) { - double speeds[3], waves[3*4], waves_local[3*4]; + for (int d = 0; d < 3; ++d) { + double speeds[3], waves[3 * 4], waves_local[3 * 4]; // rotate to local tangent-normal frame gkyl_wv_eqn_rotate_to_local(iso_euler, tau1[d], tau2[d], norm[d], ql, ql_local); gkyl_wv_eqn_rotate_to_local(iso_euler, tau1[d], tau2[d], norm[d], qr, qr_local); double delta[4]; - for (int i=0; i<4; ++i) delta[i] = qr_local[i]-ql_local[i]; - - gkyl_wv_eqn_waves(iso_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + for (int i = 0; i < 4; ++i) { + delta[i] = qr_local[i] - ql_local[i]; + } + + gkyl_wv_eqn_waves( + iso_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); // rotate waves back to global frame - for (int mw=0; mw<3; ++mw) - gkyl_wv_eqn_rotate_to_global(iso_euler, tau1[d], tau2[d], norm[d], &waves_local[mw*4], &waves[mw*4]); + for (int mw = 0; mw < 3; ++mw) { + gkyl_wv_eqn_rotate_to_global( + iso_euler, tau1[d], tau2[d], norm[d], &waves_local[mw * 4], &waves[mw * 4] + ); + } double apdq[4], amdq[4]; - gkyl_wv_eqn_qfluct(iso_euler, GKYL_WV_HIGH_ORDER_FLUX, ql, qr, 1.0, 1.0, waves, speeds, amdq, apdq); - + gkyl_wv_eqn_qfluct( + iso_euler, GKYL_WV_HIGH_ORDER_FLUX, ql, qr, 1.0, 1.0, waves, speeds, amdq, apdq + ); + // check if sum of left/right going fluctuations sum to jump in flux double fl_local[4], fr_local[4]; gkyl_iso_euler_flux(vt, ql_local, fl_local); gkyl_iso_euler_flux(vt, qr_local, fr_local); - + double fl[4], fr[4]; gkyl_wv_eqn_rotate_to_global(iso_euler, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(iso_euler, tau1[d], tau2[d], norm[d], fr_local, fr); - - for (int i=0; i<4; ++i) - TEST_CHECK( gkyl_compare(fr[i]-fl[i], amdq[i]+apdq[i], 1e-14) ); + + for (int i = 0; i < 4; ++i) { + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); + } } - + gkyl_wv_eqn_release(iso_euler); } TEST_LIST = { - { "iso_euler_basic_ho", test_iso_euler_basic_ho }, - { "iso_euler_waves_ho", test_iso_euler_waves_ho }, - { "iso_euler_waves_2_ho", test_iso_euler_waves_2_ho }, - { NULL, NULL }, + {"iso_euler_basic_ho", test_iso_euler_basic_ho}, + {"iso_euler_waves_ho", test_iso_euler_waves_ho}, + {"iso_euler_waves_2_ho", test_iso_euler_waves_2_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_iso_euler_mixture.c b/moments/unit/ctest_wv_iso_euler_mixture.c index 7cf68a3df2..84a51bf02f 100644 --- a/moments/unit/ctest_wv_iso_euler_mixture.c +++ b/moments/unit/ctest_wv_iso_euler_mixture.c @@ -4,8 +4,7 @@ #include #include -void -test_iso_euler_mixture_twocomponent_basic_ho() +void test_iso_euler_mixture_twocomponent_basic_ho() { double vt1 = 1.0; double vt2 = 10.0; @@ -16,63 +15,61 @@ test_iso_euler_mixture_twocomponent_basic_ho() struct gkyl_wv_eqn *iso_euler_mixture = gkyl_wv_iso_euler_mixture_new(2, vt_s, false); - TEST_CHECK( iso_euler_mixture->num_equations == 7 ); - TEST_CHECK( iso_euler_mixture->num_waves == 2 ); + TEST_CHECK(iso_euler_mixture->num_equations == 7); + TEST_CHECK(iso_euler_mixture->num_waves == 2); double alpha1 = 0.75, rho1 = 1.0, rho2 = 2.0, vx_total = 0.1, vy_total = 0.2, vz_total = 0.3; double rho_total = (alpha1 * rho1) + ((1.0 - alpha1) * rho2); double vt_total = (alpha1 * vt1) + ((1.0 - alpha1) * vt2); - double q[7] = { rho_total, rho_total * vx_total, rho_total * vy_total, rho_total * vz_total, rho_total * alpha1, alpha1 * rho1, - (1.0 - alpha1) * rho2 }; + double q[7] = { + rho_total, rho_total * vx_total, rho_total * vy_total, rho_total * vz_total, + rho_total * alpha1, alpha1 * rho1, (1.0 - alpha1) * rho2 + }; double prims[7]; gkyl_iso_euler_mixture_prim_vars(2, vt_s, q, prims); - TEST_CHECK( gkyl_compare(prims[0], rho_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[1], vx_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[2], vy_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[3], vz_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[4], alpha1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[5], rho1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[6], rho2, 1e-16) ); + TEST_CHECK(gkyl_compare(prims[0], rho_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[1], vx_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[2], vy_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[3], vz_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[4], alpha1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[5], rho1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[6], rho2, 1e-16)); double fluxes[3][7] = { - { rho_total * vx_total, (rho_total * (vx_total * vx_total)) + (rho_total * (vt_total * vt_total)), rho_total * (vx_total * vy_total), - rho_total * (vx_total * vz_total), rho_total * vx_total * alpha1, alpha1 * (vx_total * rho1), (1.0 - alpha1) * (vx_total * rho2) }, - { rho_total * vy_total, rho_total * (vy_total * vx_total), (rho_total * (vy_total * vy_total)) + (rho_total * (vt_total * vt_total)), - rho_total * (vy_total * vz_total), rho_total * vy_total * alpha1, alpha1 * (vy_total * rho1), (1.0 - alpha1) * (vy_total * rho2) }, - { rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), - (rho_total * (vz_total * vz_total)) + (rho_total * (vt_total * vt_total)), rho_total * vz_total * alpha1, alpha1 * (vz_total * rho1), - (1.0 - alpha1) * (vz_total * rho2) }, + {rho_total * vx_total, + (rho_total * (vx_total * vx_total)) + (rho_total * (vt_total * vt_total)), + rho_total * (vx_total * vy_total), rho_total * (vx_total * vz_total), + rho_total * vx_total * alpha1, alpha1 * (vx_total * rho1), (1.0 - alpha1) * (vx_total * rho2)}, + {rho_total * vy_total, rho_total * (vy_total * vx_total), + (rho_total * (vy_total * vy_total)) + (rho_total * (vt_total * vt_total)), + rho_total * (vy_total * vz_total), rho_total * vy_total * alpha1, alpha1 * (vy_total * rho1), + (1.0 - alpha1) * (vy_total * rho2)}, + {rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), + (rho_total * (vz_total * vz_total)) + (rho_total * (vt_total * vt_total)), + rho_total * vz_total * alpha1, alpha1 * (vz_total * rho1), (1.0 - alpha1) * (vz_total * rho2)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[7], flux_local[7], flux[7]; for (int d = 0; d < 3; d++) { - iso_euler_mixture->rotate_to_local_func(iso_euler_mixture, tau1[d], tau2[d], norm[d], q, q_local); + iso_euler_mixture->rotate_to_local_func( + iso_euler_mixture, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_iso_euler_mixture_flux(2, vt_s, q_local, flux_local); - iso_euler_mixture->rotate_to_global_func(iso_euler_mixture, tau1[d], tau2[d], norm[d], flux_local, flux); + iso_euler_mixture->rotate_to_global_func( + iso_euler_mixture, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 7; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-15) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-15)); } } @@ -82,7 +79,7 @@ test_iso_euler_mixture_twocomponent_basic_ho() gkyl_wv_eqn_rotate_to_global(iso_euler_mixture, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 7; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-16)); } double w1[7], q1[7]; @@ -90,7 +87,7 @@ test_iso_euler_mixture_twocomponent_basic_ho() iso_euler_mixture->riem_to_cons(iso_euler_mixture, q_local, w1, q1); for (int i = 0; i < 7; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-16)); } } @@ -98,8 +95,7 @@ test_iso_euler_mixture_twocomponent_basic_ho() gkyl_free(vt_s); } -void -test_iso_euler_mixture_threecomponent_basic_ho() +void test_iso_euler_mixture_threecomponent_basic_ho() { double vt1 = 1.0; double vt2 = 10.0; @@ -112,67 +108,74 @@ test_iso_euler_mixture_threecomponent_basic_ho() struct gkyl_wv_eqn *iso_euler_mixture = gkyl_wv_iso_euler_mixture_new(3, vt_s, false); - TEST_CHECK( iso_euler_mixture->num_equations == 9 ); - TEST_CHECK( iso_euler_mixture->num_waves == 2 ); + TEST_CHECK(iso_euler_mixture->num_equations == 9); + TEST_CHECK(iso_euler_mixture->num_waves == 2); - double alpha1 = 0.5, alpha2 = 0.3, rho1 = 1.0, rho2 = 2.0, rho3 = 3.0, vx_total = 0.1, vy_total = 0.2, vz_total = 0.3; + double alpha1 = 0.5, alpha2 = 0.3, rho1 = 1.0, rho2 = 2.0, rho3 = 3.0, vx_total = 0.1, + vy_total = 0.2, vz_total = 0.3; double rho_total = (alpha1 * rho1) + (alpha2 * rho2) + (1.0 - (alpha1 + alpha2)) * rho3; double vt_total = (alpha1 * vt1) + (alpha2 * vt2) + (1.0 - (alpha1 + alpha2)) * vt3; - double q[9] = { rho_total, rho_total * vx_total, rho_total * vy_total, rho_total * vz_total, rho_total * alpha1, rho_total * alpha2, - alpha1 * rho1, alpha2 * rho2, (1.0 - (alpha1 + alpha2)) * rho3 }; + double q[9] = { + rho_total, + rho_total * vx_total, + rho_total * vy_total, + rho_total * vz_total, + rho_total * alpha1, + rho_total * alpha2, + alpha1 * rho1, + alpha2 * rho2, + (1.0 - (alpha1 + alpha2)) * rho3 + }; double prims[9]; gkyl_iso_euler_mixture_prim_vars(3, vt_s, q, prims); - TEST_CHECK( gkyl_compare(prims[0], rho_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[1], vx_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[2], vy_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[3], vz_total, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[4], alpha1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[5], alpha2, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[6], rho1, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[7], rho2, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[8], rho3, 1e-16) ); + TEST_CHECK(gkyl_compare(prims[0], rho_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[1], vx_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[2], vy_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[3], vz_total, 1e-16)); + TEST_CHECK(gkyl_compare(prims[4], alpha1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[5], alpha2, 1e-16)); + TEST_CHECK(gkyl_compare(prims[6], rho1, 1e-16)); + TEST_CHECK(gkyl_compare(prims[7], rho2, 1e-16)); + TEST_CHECK(gkyl_compare(prims[8], rho3, 1e-16)); double fluxes[3][9] = { - { rho_total * vx_total, (rho_total * (vx_total * vx_total)) + (rho_total * (vt_total * vt_total)), rho_total * (vx_total * vy_total), - rho_total * (vx_total * vz_total), rho_total * vx_total * alpha1, rho_total * vx_total * alpha2, alpha1 * (vx_total * rho1), - alpha2 * (vx_total * rho2), (1.0 - (alpha1 + alpha2)) * (vx_total * rho3) }, - { rho_total * vy_total, rho_total * (vy_total * vx_total), (rho_total * (vy_total * vy_total)) + (rho_total * (vt_total * vt_total)), - rho_total * (vy_total * vz_total), rho_total * vy_total * alpha1, rho_total * vy_total * alpha2, alpha1 * (vy_total * rho1), - alpha2 * (vy_total * rho2), (1.0 - (alpha1 + alpha2)) * (vy_total * rho3) }, - { rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), - (rho_total * (vz_total * vz_total)) + (rho_total * (vt_total * vt_total)), rho_total * vz_total * alpha1, rho_total * vz_total * alpha2, - alpha1 * (vz_total * rho1), alpha2 * (vz_total * rho2), (1.0 - (alpha1 + alpha2)) * (vz_total * rho3) }, + {rho_total * vx_total, + (rho_total * (vx_total * vx_total)) + (rho_total * (vt_total * vt_total)), + rho_total * (vx_total * vy_total), rho_total * (vx_total * vz_total), + rho_total * vx_total * alpha1, rho_total * vx_total * alpha2, alpha1 * (vx_total * rho1), + alpha2 * (vx_total * rho2), (1.0 - (alpha1 + alpha2)) * (vx_total * rho3)}, + {rho_total * vy_total, rho_total * (vy_total * vx_total), + (rho_total * (vy_total * vy_total)) + (rho_total * (vt_total * vt_total)), + rho_total * (vy_total * vz_total), rho_total * vy_total * alpha1, + rho_total * vy_total * alpha2, alpha1 * (vy_total * rho1), alpha2 * (vy_total * rho2), + (1.0 - (alpha1 + alpha2)) * (vy_total * rho3)}, + {rho_total * vz_total, rho_total * (vz_total * vx_total), rho_total * (vz_total * vy_total), + (rho_total * (vz_total * vz_total)) + (rho_total * (vt_total * vt_total)), + rho_total * vz_total * alpha1, rho_total * vz_total * alpha2, alpha1 * (vz_total * rho1), + alpha2 * (vz_total * rho2), (1.0 - (alpha1 + alpha2)) * (vz_total * rho3)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[9], flux_local[9], flux[9]; for (int d = 0; d < 3; d++) { - iso_euler_mixture->rotate_to_local_func(iso_euler_mixture, tau1[d], tau2[d], norm[d], q, q_local); + iso_euler_mixture->rotate_to_local_func( + iso_euler_mixture, tau1[d], tau2[d], norm[d], q, q_local + ); gkyl_iso_euler_mixture_flux(3, vt_s, q_local, flux_local); - iso_euler_mixture->rotate_to_global_func(iso_euler_mixture, tau1[d], tau2[d], norm[d], flux_local, flux); + iso_euler_mixture->rotate_to_global_func( + iso_euler_mixture, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-15) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-15)); } } @@ -182,7 +185,7 @@ test_iso_euler_mixture_threecomponent_basic_ho() gkyl_wv_eqn_rotate_to_global(iso_euler_mixture, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-16)); } double w1[9], q1[9]; @@ -190,7 +193,7 @@ test_iso_euler_mixture_threecomponent_basic_ho() iso_euler_mixture->riem_to_cons(iso_euler_mixture, q_local, w1, q1); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-16)); } } @@ -198,49 +201,52 @@ test_iso_euler_mixture_threecomponent_basic_ho() gkyl_free(vt_s); } -void -test_iso_euler_mixture_twocomponent_waves_ho() +void test_iso_euler_mixture_twocomponent_waves_ho() { double vt1 = 1.0; double vt2 = 10.0; - + double *vt_s = gkyl_malloc(sizeof(double[2])); vt_s[0] = vt1; vt_s[1] = vt2; struct gkyl_wv_eqn *iso_euler_mixture = gkyl_wv_iso_euler_mixture_new(2, vt_s, false); - - double alpha1_l = 0.75, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3; + + double alpha1_l = 0.75, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, + vz_total_l = 0.3; double rho_total_l = (alpha1_l * rho1_l) + ((1.0 - alpha1_l) * rho2_l); double vt_total_l = (alpha1_l * vt1) + ((1.0 - alpha1_l) * vt2); - double alpha1_r = 0.25, rho1_r = 0.1, rho2_r = 0.2, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0; + double alpha1_r = 0.25, rho1_r = 0.1, rho2_r = 0.2, vx_total_r = 1.0, vy_total_r = 2.0, + vz_total_r = 3.0; double rho_total_r = (alpha1_r * rho1_r) + ((1.0 - alpha1_r) * rho2_r); double vt_total_r = (alpha1_r * vt1) + ((1.0 - alpha1_r) * vt2); - double ql[7] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, rho_total_l * alpha1_l, - alpha1_l * rho1_l, (1.0 - alpha1_l) * rho2_l }; - double qr[7] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, rho_total_r * alpha1_r, - alpha1_r * rho1_r, (1.0 - alpha1_r) * rho2_r }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[7] = { + rho_total_l, + rho_total_l * vx_total_l, + rho_total_l * vy_total_l, + rho_total_l * vz_total_l, + rho_total_l * alpha1_l, + alpha1_l * rho1_l, + (1.0 - alpha1_l) * rho2_l }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[7] = { + rho_total_r, + rho_total_r * vx_total_r, + rho_total_r * vy_total_r, + rho_total_r * vz_total_r, + rho_total_r * alpha1_r, + alpha1_r * rho1_r, + (1.0 - alpha1_r) * rho2_r }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 7], waves_local[2 * 7]; @@ -253,13 +259,21 @@ test_iso_euler_mixture_twocomponent_waves_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[7], amdq_local[7]; - gkyl_wv_eqn_qfluct(iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(iso_euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 7], &waves[i * 7]); + gkyl_wv_eqn_rotate_to_global( + iso_euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 7], &waves[i * 7] + ); } double apdq[7], amdq[7]; @@ -275,7 +289,7 @@ test_iso_euler_mixture_twocomponent_waves_ho() gkyl_wv_eqn_rotate_to_global(iso_euler_mixture, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 7; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-13)); } } @@ -283,49 +297,52 @@ test_iso_euler_mixture_twocomponent_waves_ho() gkyl_free(vt_s); } -void -test_iso_euler_mixture_twocomponent_waves_2_ho() +void test_iso_euler_mixture_twocomponent_waves_2_ho() { double vt1 = 0.5; double vt2 = 50.0; - + double *vt_s = gkyl_malloc(sizeof(double[2])); vt_s[0] = vt1; vt_s[1] = vt2; struct gkyl_wv_eqn *iso_euler_mixture = gkyl_wv_iso_euler_mixture_new(2, vt_s, false); - - double alpha1_l = 0.9, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3; + + double alpha1_l = 0.9, rho1_l = 1.0, rho2_l = 2.0, vx_total_l = 0.1, vy_total_l = 0.2, + vz_total_l = 0.3; double rho_total_l = (alpha1_l * rho1_l) + ((1.0 - alpha1_l) * rho2_l); double vt_total_l = (alpha1_l * vt1) + ((1.0 - alpha1_l) * vt2); - double alpha1_r = 0.1, rho1_r = 0.01, rho2_r = 0.02, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0; + double alpha1_r = 0.1, rho1_r = 0.01, rho2_r = 0.02, vx_total_r = 1.0, vy_total_r = 2.0, + vz_total_r = 3.0; double rho_total_r = (alpha1_r * rho1_r) + ((1.0 - alpha1_r) * rho2_r); double vt_total_r = (alpha1_r * vt1) + ((1.0 - alpha1_r) * vt2); - double ql[7] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, rho_total_l * alpha1_l, - alpha1_l * rho1_l, (1.0 - alpha1_l) * rho2_l }; - double qr[7] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, rho_total_r * alpha1_r, - alpha1_r * rho1_r, (1.0 - alpha1_r) * rho2_r }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[7] = { + rho_total_l, + rho_total_l * vx_total_l, + rho_total_l * vy_total_l, + rho_total_l * vz_total_l, + rho_total_l * alpha1_l, + alpha1_l * rho1_l, + (1.0 - alpha1_l) * rho2_l }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[7] = { + rho_total_r, + rho_total_r * vx_total_r, + rho_total_r * vy_total_r, + rho_total_r * vz_total_r, + rho_total_r * alpha1_r, + alpha1_r * rho1_r, + (1.0 - alpha1_r) * rho2_r }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 7], waves_local[2 * 7]; @@ -338,13 +355,21 @@ test_iso_euler_mixture_twocomponent_waves_2_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[7], amdq_local[7]; - gkyl_wv_eqn_qfluct(iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(iso_euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 7], &waves[i * 7]); + gkyl_wv_eqn_rotate_to_global( + iso_euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 7], &waves[i * 7] + ); } double apdq[7], amdq[7]; @@ -360,7 +385,7 @@ test_iso_euler_mixture_twocomponent_waves_2_ho() gkyl_wv_eqn_rotate_to_global(iso_euler_mixture, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 7; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } @@ -368,51 +393,60 @@ test_iso_euler_mixture_twocomponent_waves_2_ho() gkyl_free(vt_s); } -void -test_iso_euler_mixture_threecomponent_waves_ho() +void test_iso_euler_mixture_threecomponent_waves_ho() { double vt1 = 1.0; double vt2 = 10.0; double vt3 = 100.0; - + double *vt_s = gkyl_malloc(sizeof(double[3])); vt_s[0] = vt1; vt_s[1] = vt2; vt_s[2] = vt3; struct gkyl_wv_eqn *iso_euler_mixture = gkyl_wv_iso_euler_mixture_new(3, vt_s, false); - - double alpha1_l = 0.5, alpha2_l = 0.3, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3; - double rho_total_l = (alpha1_l * rho1_l) + (alpha2_l * rho2_l) + ((1.0 - (alpha1_l + alpha2_l)) * rho3_l); + + double alpha1_l = 0.5, alpha2_l = 0.3, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, + vy_total_l = 0.2, vz_total_l = 0.3; + double rho_total_l = + (alpha1_l * rho1_l) + (alpha2_l * rho2_l) + ((1.0 - (alpha1_l + alpha2_l)) * rho3_l); double vt_total_l = (alpha1_l * vt1) + (alpha2_l * vt2) + ((1.0 - (alpha1_l + alpha2_l)) * vt3); - double alpha1_r = 0.4, alpha2_r = 0.2, rho1_r = 0.1, rho2_r = 0.2, rho3_r = 0.3, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0; - double rho_total_r = (alpha1_r * rho1_r) + (alpha2_r * rho2_r) + ((1.0 - (alpha1_r + alpha2_r)) * rho3_r); + double alpha1_r = 0.4, alpha2_r = 0.2, rho1_r = 0.1, rho2_r = 0.2, rho3_r = 0.3, vx_total_r = 1.0, + vy_total_r = 2.0, vz_total_r = 3.0; + double rho_total_r = + (alpha1_r * rho1_r) + (alpha2_r * rho2_r) + ((1.0 - (alpha1_r + alpha2_r)) * rho3_r); double vt_total_r = (alpha1_r * vt1) + (alpha2_r * vt2) + ((1.0 - (alpha1_r + alpha2_r)) * vt3); - double ql[9] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, rho_total_l * alpha1_l, - rho_total_l * alpha2_l, alpha1_l * rho1_l, alpha2_l * rho2_l, (1.0 - (alpha1_l + alpha2_l)) * rho3_l }; - double qr[9] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, rho_total_r * alpha1_r, - rho_total_r * alpha2_r, alpha1_r * rho1_r, alpha2_r * rho2_r, (1.0 - (alpha1_r + alpha2_r)) * rho3_r }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[9] = { + rho_total_l, + rho_total_l * vx_total_l, + rho_total_l * vy_total_l, + rho_total_l * vz_total_l, + rho_total_l * alpha1_l, + rho_total_l * alpha2_l, + alpha1_l * rho1_l, + alpha2_l * rho2_l, + (1.0 - (alpha1_l + alpha2_l)) * rho3_l }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[9] = { + rho_total_r, + rho_total_r * vx_total_r, + rho_total_r * vy_total_r, + rho_total_r * vz_total_r, + rho_total_r * alpha1_r, + rho_total_r * alpha2_r, + alpha1_r * rho1_r, + alpha2_r * rho2_r, + (1.0 - (alpha1_r + alpha2_r)) * rho3_r }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 9], waves_local[2 * 9]; @@ -425,13 +459,21 @@ test_iso_euler_mixture_threecomponent_waves_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[9], amdq_local[9]; - gkyl_wv_eqn_qfluct(iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(iso_euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 9], &waves[i * 9]); + gkyl_wv_eqn_rotate_to_global( + iso_euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 9], &waves[i * 9] + ); } double apdq[9], amdq[9]; @@ -447,7 +489,7 @@ test_iso_euler_mixture_threecomponent_waves_ho() gkyl_wv_eqn_rotate_to_global(iso_euler_mixture, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } @@ -455,51 +497,60 @@ test_iso_euler_mixture_threecomponent_waves_ho() gkyl_free(vt_s); } -void -test_iso_euler_mixture_threecomponent_waves_2_ho() +void test_iso_euler_mixture_threecomponent_waves_2_ho() { double vt1 = 0.5; double vt2 = 50.0; double vt3 = 800.0; - + double *vt_s = gkyl_malloc(sizeof(double[3])); vt_s[0] = vt1; vt_s[1] = vt2; vt_s[2] = vt3; struct gkyl_wv_eqn *iso_euler_mixture = gkyl_wv_iso_euler_mixture_new(3, vt_s, false); - - double alpha1_l = 0.8, alpha2_l = 0.1, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, vy_total_l = 0.2, vz_total_l = 0.3; - double rho_total_l = (alpha1_l * rho1_l) + (alpha2_l * rho2_l) + ((1.0 - (alpha1_l + alpha2_l)) * rho3_l); + + double alpha1_l = 0.8, alpha2_l = 0.1, rho1_l = 1.0, rho2_l = 2.0, rho3_l = 3.0, vx_total_l = 0.1, + vy_total_l = 0.2, vz_total_l = 0.3; + double rho_total_l = + (alpha1_l * rho1_l) + (alpha2_l * rho2_l) + ((1.0 - (alpha1_l + alpha2_l)) * rho3_l); double vt_total_l = (alpha1_l * vt1) + (alpha2_l * vt2) + ((1.0 - (alpha1_l + alpha2_l)) * vt3); - double alpha1_r = 0.75, alpha2_r = 0.2, rho1_r = 0.01, rho2_r = 0.02, rho3_r = 0.03, vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0; - double rho_total_r = (alpha1_r * rho1_r) + (alpha2_r * rho2_r) + ((1.0 - (alpha1_r + alpha2_r)) * rho3_r); + double alpha1_r = 0.75, alpha2_r = 0.2, rho1_r = 0.01, rho2_r = 0.02, rho3_r = 0.03, + vx_total_r = 1.0, vy_total_r = 2.0, vz_total_r = 3.0; + double rho_total_r = + (alpha1_r * rho1_r) + (alpha2_r * rho2_r) + ((1.0 - (alpha1_r + alpha2_r)) * rho3_r); double vt_total_r = (alpha1_r * vt1) + (alpha2_r * vt2) + ((1.0 - (alpha1_r + alpha2_r)) * vt3); - double ql[9] = { rho_total_l, rho_total_l * vx_total_l, rho_total_l * vy_total_l, rho_total_l * vz_total_l, rho_total_l * alpha1_l, - rho_total_l * alpha2_l, alpha1_l * rho1_l, alpha2_l * rho2_l, (1.0 - (alpha1_l + alpha2_l)) * rho3_l }; - double qr[9] = { rho_total_r, rho_total_r * vx_total_r, rho_total_r * vy_total_r, rho_total_r * vz_total_r, rho_total_r * alpha1_r, - rho_total_r * alpha2_r, alpha1_r * rho1_r, alpha2_r * rho2_r, (1.0 - (alpha1_r + alpha2_r)) * rho3_r }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[9] = { + rho_total_l, + rho_total_l * vx_total_l, + rho_total_l * vy_total_l, + rho_total_l * vz_total_l, + rho_total_l * alpha1_l, + rho_total_l * alpha2_l, + alpha1_l * rho1_l, + alpha2_l * rho2_l, + (1.0 - (alpha1_l + alpha2_l)) * rho3_l }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[9] = { + rho_total_r, + rho_total_r * vx_total_r, + rho_total_r * vy_total_r, + rho_total_r * vz_total_r, + rho_total_r * alpha1_r, + rho_total_r * alpha2_r, + alpha1_r * rho1_r, + alpha2_r * rho2_r, + (1.0 - (alpha1_r + alpha2_r)) * rho3_r }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 9], waves_local[2 * 9]; @@ -512,13 +563,21 @@ test_iso_euler_mixture_threecomponent_waves_2_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[9], amdq_local[9]; - gkyl_wv_eqn_qfluct(iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + iso_euler_mixture, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(iso_euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 9], &waves[i * 9]); + gkyl_wv_eqn_rotate_to_global( + iso_euler_mixture, tau1[d], tau2[d], norm[d], &waves_local[i * 9], &waves[i * 9] + ); } double apdq[9], amdq[9]; @@ -534,7 +593,7 @@ test_iso_euler_mixture_threecomponent_waves_2_ho() gkyl_wv_eqn_rotate_to_global(iso_euler_mixture, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 9; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } @@ -543,11 +602,11 @@ test_iso_euler_mixture_threecomponent_waves_2_ho() } TEST_LIST = { - { "iso_euler_mixture_twocomponent_basic_ho", test_iso_euler_mixture_twocomponent_basic_ho }, - { "iso_euler_mixture_threecomponent_basic_ho", test_iso_euler_mixture_threecomponent_basic_ho }, - { "iso_euler_mixture_twocomponent_waves_ho", test_iso_euler_mixture_twocomponent_waves_ho }, - { "iso_euler_mixture_twocomponent_waves_2_ho", test_iso_euler_mixture_twocomponent_waves_2_ho }, - { "iso_euler_mixture_threecomponent_waves_ho", test_iso_euler_mixture_threecomponent_waves_ho }, - { "iso_euler_mixture_threecomponent_waves_2_ho", test_iso_euler_mixture_threecomponent_waves_2_ho }, - { NULL, NULL }, + {"iso_euler_mixture_twocomponent_basic_ho", test_iso_euler_mixture_twocomponent_basic_ho}, + {"iso_euler_mixture_threecomponent_basic_ho", test_iso_euler_mixture_threecomponent_basic_ho}, + {"iso_euler_mixture_twocomponent_waves_ho", test_iso_euler_mixture_twocomponent_waves_ho}, + {"iso_euler_mixture_twocomponent_waves_2_ho", test_iso_euler_mixture_twocomponent_waves_2_ho}, + {"iso_euler_mixture_threecomponent_waves_ho", test_iso_euler_mixture_threecomponent_waves_ho}, + {"iso_euler_mixture_threecomponent_waves_2_ho", test_iso_euler_mixture_threecomponent_waves_2_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_maxwell.c b/moments/unit/ctest_wv_maxwell.c index ce74536133..f0370771e0 100644 --- a/moments/unit/ctest_wv_maxwell.c +++ b/moments/unit/ctest_wv_maxwell.c @@ -10,176 +10,139 @@ #define BY 4 #define BZ 5 -void -test_maxwell_basic_ho() +void test_maxwell_basic_ho() { // speed of light in SI units so tests are non-trivial double c = 299792458.0; - double c2 = c*c; + double c2 = c * c; double e_fact = 2.0; double b_fact = 2.5; struct gkyl_wv_eqn *maxwell = gkyl_wv_maxwell_new(c, e_fact, b_fact, false); - TEST_CHECK( maxwell->num_equations == 8 ); - TEST_CHECK( maxwell->num_waves == 6 ); + TEST_CHECK(maxwell->num_equations == 8); + TEST_CHECK(maxwell->num_waves == 6); double Ex = 1.0, Ey = 0.1, Ez = 0.2; double Bx = 10.0, By = 10.1, Bz = 10.2; double phi = 0.01, psi = 0.02; - double q[8] = { Ex, Ey, Ez, Bx, By, Bz, phi, psi }; + double q[8] = {Ex, Ey, Ez, Bx, By, Bz, phi, psi}; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double fluxes[3][8] = { - { - e_fact*c2*q[6], - c2*q[BZ], - -c2*q[BY], - - b_fact*q[7], - -q[EZ], - q[EY], - - e_fact*q[EX], - b_fact*c2*q[BX] - }, - { - -c2*q[BZ], - e_fact*c2*q[6], - c2*q[BX], - - q[EZ], - b_fact*q[7], - -q[EX], - - e_fact*q[EY], - b_fact*c2*q[BY] - }, - { - c2*q[BY], - -c2*q[BX], - e_fact*c2*q[6], - - -q[EY], - q[EX], - b_fact*q[7], - - e_fact*q[EZ], - b_fact*c2*q[BZ] - }, + {e_fact * c2 * q[6], c2 * q[BZ], -c2 * q[BY], - }; + b_fact * q[7], -q[EZ], q[EY], + + e_fact * q[EX], b_fact * c2 * q[BX]}, + {-c2 * q[BZ], e_fact * c2 * q[6], c2 * q[BX], + + q[EZ], b_fact * q[7], -q[EX], + + e_fact * q[EY], b_fact * c2 * q[BY]}, + {c2 * q[BY], -c2 * q[BX], e_fact * c2 * q[6], + -q[EY], q[EX], b_fact * q[7], + + e_fact * q[EZ], b_fact * c2 * q[BZ]} + + }; double q_local[8], flux_local[8], flux[8]; - for (int d=0; d<3; ++d) { + for (int d = 0; d < 3; ++d) { maxwell->rotate_to_local_func(maxwell, tau1[d], tau2[d], norm[d], q, q_local); gkyl_maxwell_flux(c, e_fact, b_fact, q_local, flux_local); maxwell->rotate_to_global_func(maxwell, tau1[d], tau2[d], norm[d], flux_local, flux); - for (int m=0; m<8; ++m) - TEST_CHECK( gkyl_compare(flux[m], fluxes[d][m], 1e-15) ); + for (int m = 0; m < 8; ++m) { + TEST_CHECK(gkyl_compare(flux[m], fluxes[d][m], 1e-15)); + } // check Riemann transform double w1[8], q1[8]; maxwell->cons_to_riem(maxwell, q_local, q_local, w1); maxwell->riem_to_cons(maxwell, q_local, w1, q1); - - for (int m=0; m<8; ++m) - TEST_CHECK( gkyl_compare_double(q_local[m], q1[m], 1e-14) ); + + for (int m = 0; m < 8; ++m) { + TEST_CHECK(gkyl_compare_double(q_local[m], q1[m], 1e-14)); + } } gkyl_wv_eqn_release(maxwell); } -void -test_maxwell_waves_ho() +void test_maxwell_waves_ho() { // speed of light in SI units so tests are non-trivial double c = 299792458.0; - double c2 = c*c; + double c2 = c * c; double e_fact = 1.0; double b_fact = 1.0; struct gkyl_wv_eqn *maxwell = gkyl_wv_maxwell_new(c, e_fact, b_fact, false); - double ql[8] = { 0.0, 1.0, 0.0, 1.0, -0.75, 0.0, 0.0, 0.0}; - double qr[8] = { 0.0, -1.0, 0.0, 1.0, 0.75, 0.0, 0.0, 0.0}; + double ql[8] = {0.0, 1.0, 0.0, 1.0, -0.75, 0.0, 0.0, 0.0}; + double qr[8] = {0.0, -1.0, 0.0, 1.0, 0.75, 0.0, 0.0, 0.0}; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; - for (int d=0; d<3; ++d) { - double speeds[6], waves[6*8], waves_local[6*8]; + for (int d = 0; d < 3; ++d) { + double speeds[6], waves[6 * 8], waves_local[6 * 8]; double ql_local[8], qr_local[8]; - + // rotate to local tangent-normal frame gkyl_wv_eqn_rotate_to_local(maxwell, tau1[d], tau2[d], norm[d], ql, ql_local); gkyl_wv_eqn_rotate_to_local(maxwell, tau1[d], tau2[d], norm[d], qr, qr_local); double delta[8]; - for (int i=0; i<8; ++i) delta[i] = qr_local[i]-ql_local[i]; - - gkyl_wv_eqn_waves(maxwell, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + for (int i = 0; i < 8; ++i) { + delta[i] = qr_local[i] - ql_local[i]; + } + + gkyl_wv_eqn_waves( + maxwell, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); double apdq_local[8], amdq_local[8]; - gkyl_wv_eqn_qfluct(maxwell, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, - amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + maxwell, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); // rotate waves back to global frame - for (int mw=0; mw<6; ++mw) - gkyl_wv_eqn_rotate_to_global(maxwell, tau1[d], tau2[d], norm[d], &waves_local[mw*8], &waves[mw*8]); + for (int mw = 0; mw < 6; ++mw) { + gkyl_wv_eqn_rotate_to_global( + maxwell, tau1[d], tau2[d], norm[d], &waves_local[mw * 8], &waves[mw * 8] + ); + } double apdq[8], amdq[8]; gkyl_wv_eqn_rotate_to_global(maxwell, tau1[d], tau2[d], norm[d], apdq_local, apdq); gkyl_wv_eqn_rotate_to_global(maxwell, tau1[d], tau2[d], norm[d], amdq_local, amdq); - + // check if sum of left/right going fluctuations sum to jump in flux double fl_local[8], fr_local[8]; gkyl_maxwell_flux(c, e_fact, b_fact, ql_local, fl_local); gkyl_maxwell_flux(c, e_fact, b_fact, qr_local, fr_local); - + double fl[8], fr[8]; gkyl_wv_eqn_rotate_to_global(maxwell, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(maxwell, tau1[d], tau2[d], norm[d], fr_local, fr); - - for (int i=0; i<8; ++i) { + + for (int i = 0; i < 8; ++i) { //printf("%d: %g %g (%g)\n", i, fr[i]-fl[i], amdq[i]+apdq[i], (fr[i]-fl[i])-(amdq[i]+apdq[i])); - TEST_CHECK( gkyl_compare(fr[i]-fl[i], amdq[i]+apdq[i], 1e-14) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); } } - + gkyl_wv_eqn_release(maxwell); } @@ -187,19 +150,18 @@ test_maxwell_waves_ho() int cu_wv_maxwell_test(const struct gkyl_wv_eqn *eqn); -void -test_wv_maxwell_dev() +void test_wv_maxwell_dev() { double c = 299792458.0; - double c2 = c*c; + double c2 = c * c; double e_fact = 2.0; double b_fact = 2.5; struct gkyl_wv_eqn *eqn = gkyl_wv_maxwell_new(c, e_fact, b_fact, true); - + // call CUDA test int nfail = cu_wv_maxwell_test(eqn->on_dev); - TEST_CHECK( nfail == 0 ); + TEST_CHECK(nfail == 0); gkyl_wv_eqn_release(eqn); } @@ -207,10 +169,10 @@ test_wv_maxwell_dev() #endif TEST_LIST = { - { "maxwell_basic_ho", test_maxwell_basic_ho }, - { "maxwell_waves_ho", test_maxwell_waves_ho }, + {"maxwell_basic_ho", test_maxwell_basic_ho}, + {"maxwell_waves_ho", test_maxwell_waves_ho}, #ifdef GKYL_HAVE_CUDA - { "wv_maxwell_dev", test_wv_maxwell_dev }, -#endif - { NULL, NULL }, + {"wv_maxwell_dev", test_wv_maxwell_dev}, +#endif + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_maxwell_cu.cu b/moments/unit/ctest_wv_maxwell_cu.cu index d00c20636a..7c7b6cc2d2 100644 --- a/moments/unit/ctest_wv_maxwell_cu.cu +++ b/moments/unit/ctest_wv_maxwell_cu.cu @@ -11,118 +11,86 @@ extern "C" { int cu_wv_maxwell_test(const struct gkyl_wv_eqn *eqn); } -__global__ -void ker_cu_wv_maxwell_test(const struct gkyl_wv_eqn *eqn, int *nfail) +__global__ void ker_cu_wv_maxwell_test(const struct gkyl_wv_eqn *eqn, int *nfail) { *nfail = 0; - GKYL_CU_CHECK( eqn->num_equations == 8, nfail ); - GKYL_CU_CHECK( eqn->num_waves == 6, nfail ); + GKYL_CU_CHECK(eqn->num_equations == 8, nfail); + GKYL_CU_CHECK(eqn->num_waves == 6, nfail); // DO NOT DO THIS IN PRODUCTION! ONLY FOR TESTING struct wv_maxwell *maxwell = container_of(eqn, struct wv_maxwell, eqn); double c = maxwell->c; - double c2 = c*c; + double c2 = c * c; double e_fact = maxwell->e_fact; double b_fact = maxwell->b_fact; double Ex = 1.0, Ey = 0.1, Ez = 0.2; double Bx = 10.0, By = 10.1, Bz = 10.2; double phi = 0.01, psi = 0.02; - double q[8] = { Ex, Ey, Ez, Bx, By, Bz, phi, psi }; + double q[8] = {Ex, Ey, Ez, Bx, By, Bz, phi, psi}; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double fluxes[3][8] = { - { - e_fact*c2*q[6], - c2*q[5], - -c2*q[4], - - b_fact*q[7], - -q[2], - q[1], - - e_fact*q[0], - b_fact*c2*q[3] - }, - { - -c2*q[5], - e_fact*c2*q[6], - c2*q[3], - - q[2], - b_fact*q[7], - -q[0], - - e_fact*q[1], - b_fact*c2*q[4] - }, - { - c2*q[4], - -c2*q[3], - e_fact*c2*q[6], - - -q[1], - q[0], - b_fact*q[7], - - e_fact*q[2], - b_fact*c2*q[5] - }, + {e_fact * c2 * q[6], c2 * q[5], -c2 * q[4], + + b_fact * q[7], -q[2], q[1], + + e_fact * q[0], b_fact * c2 * q[3]}, + {-c2 * q[5], e_fact * c2 * q[6], c2 * q[3], + + q[2], b_fact * q[7], -q[0], + + e_fact * q[1], b_fact * c2 * q[4]}, + {c2 * q[4], -c2 * q[3], e_fact * c2 * q[6], + + -q[1], q[0], b_fact * q[7], + + e_fact * q[2], b_fact * c2 * q[5]} }; double q_local[8], flux_local[8], flux[8]; - for (int d=0; d<3; ++d) { + for (int d = 0; d < 3; ++d) { eqn->rotate_to_local_func(eqn, tau1[d], tau2[d], norm[d], q, q_local); gkyl_maxwell_flux(c, e_fact, b_fact, q_local, flux_local); eqn->rotate_to_global_func(eqn, tau1[d], tau2[d], norm[d], flux_local, flux); - for (int m=0; m<8; ++m) { - GKYL_CU_CHECK( fabs(flux[m] - fluxes[d][m]) / flux[m] < 1e-14, nfail ); + for (int m = 0; m < 8; ++m) { + GKYL_CU_CHECK(fabs(flux[m] - fluxes[d][m]) / flux[m] < 1e-14, nfail); } // check Riemann transform double w1[8], q1[8]; eqn->cons_to_riem(eqn, q_local, q_local, w1); eqn->riem_to_cons(eqn, q_local, w1, q1); - - for (int m=0; m<8; ++m) { - GKYL_CU_CHECK( q_local[m] == q1[m], nfail ); + + for (int m = 0; m < 8; ++m) { + GKYL_CU_CHECK(q_local[m] == q1[m], nfail); } } double q_l[8], q_g[8]; - for (int d=0; d<3; ++d) { + for (int d = 0; d < 3; ++d) { eqn->rotate_to_local_func(eqn, tau1[d], tau2[d], norm[d], q, q_l); eqn->rotate_to_global_func(eqn, tau1[d], tau2[d], norm[d], q_l, q_g); - for (int m=0; m<8; ++m) GKYL_CU_CHECK( q[m] == q_g[m], nfail ); + for (int m = 0; m < 8; ++m) { + GKYL_CU_CHECK(q[m] == q_g[m], nfail); + } } } int cu_wv_maxwell_test(const struct gkyl_wv_eqn *eqn) { - int *nfail_dev = (int *) gkyl_cu_malloc(sizeof(int)); - ker_cu_wv_maxwell_test<<<1,1>>>(eqn, nfail_dev); + int *nfail_dev = (int *)gkyl_cu_malloc(sizeof(int)); + ker_cu_wv_maxwell_test<<<1, 1> > >(eqn, nfail_dev); int nfail; gkyl_cu_memcpy(&nfail, nfail_dev, sizeof(int), GKYL_CU_MEMCPY_D2H); diff --git a/moments/unit/ctest_wv_mhd.c b/moments/unit/ctest_wv_mhd.c index eee7fbaf27..5591820fe0 100644 --- a/moments/unit/ctest_wv_mhd.c +++ b/moments/unit/ctest_wv_mhd.c @@ -4,7 +4,8 @@ #include #include -void calcq(double gas_gamma, const double *pv, double *q) { +void calcq(double gas_gamma, const double *pv, double *q) +{ double rho = pv[0], u = pv[1], v = pv[2], w = pv[3], pr = pv[4]; q[0] = rho; q[1] = rho * u; @@ -13,18 +14,18 @@ void calcq(double gas_gamma, const double *pv, double *q) { q[5] = pv[5]; q[6] = pv[6]; q[7] = pv[7]; // B field - double pb = 0.5 * (pv[5] * pv[5] + pv[6] * pv[6] + - pv[7] * pv[7]); // magnetic pressure + double pb = 0.5 * (pv[5] * pv[5] + pv[6] * pv[6] + pv[7] * pv[7]); // magnetic pressure q[4] = pr / (gas_gamma - 1) + 0.5 * rho * (u * u + v * v + w * w) + pb; } /**************************************/ /* CHECK FLUX FUNCTION IMPLEMENTATION */ /**************************************/ -void test_mhd_basic_ho() { +void test_mhd_basic_ho() +{ double gas_gamma = 1.4; - struct gkyl_wv_eqn *mhd = gkyl_wv_mhd_new(&(struct gkyl_wv_mhd_inp){ - .gas_gamma = gas_gamma, .divergence_constraint = GKYL_MHD_DIVB_NONE}); + struct gkyl_wv_eqn *mhd = gkyl_wv_mhd_new(&(struct gkyl_wv_mhd_inp + ){.gas_gamma = gas_gamma, .divergence_constraint = GKYL_MHD_DIVB_NONE}); TEST_CHECK(mhd->num_equations == 8); TEST_CHECK(mhd->num_waves == 7); @@ -38,15 +39,12 @@ void test_mhd_basic_ho() { double E = q[4]; double fluxes[3][8] = { - {rho * u, rho * u * u - bx * bx + pr + pb, rho * u * v - bx * by, - rho * u * w - bx * bz, (E + pr + pb) * u - bx * u_dot_b, 0.0, - u * by - v * bx, u * bz - w * bx}, - {rho * v, rho * v * u - bx * by, rho * v * v - by * by + pr + pb, - rho * v * w - by * bz, (E + pr + pb) * v - by * u_dot_b, - v * bx - u * by, 0.0, v * bz - w * by}, - {rho * w, rho * w * u - bx * bz, rho * w * v - by * bz, - rho * w * w - bz * bz + pr + pb, (E + pr + pb) * w - bz * u_dot_b, - w * bx - u * bz, w * by - v * bz, 0.0}, + {rho * u, rho * u * u - bx * bx + pr + pb, rho * u * v - bx * by, rho * u * w - bx * bz, + (E + pr + pb) * u - bx * u_dot_b, 0.0, u * by - v * bx, u * bz - w * bx}, + {rho * v, rho * v * u - bx * by, rho * v * v - by * by + pr + pb, rho * v * w - by * bz, + (E + pr + pb) * v - by * u_dot_b, v * bx - u * by, 0.0, v * bz - w * by}, + {rho * w, rho * w * u - bx * bz, rho * w * v - by * bz, rho * w * w - bz * bz + pr + pb, + (E + pr + pb) * w - bz * u_dot_b, w * bx - u * bz, w * by - v * bz, 0.0} }; double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; @@ -63,16 +61,18 @@ void test_mhd_basic_ho() { gkyl_mhd_flux(gas_gamma, q_local, flux_local); mhd->rotate_to_global_func(mhd, tau1[d], tau2[d], norm[d], flux_local, flux); - for (int m = 0; m < 8; ++m) + for (int m = 0; m < 8; ++m) { TEST_CHECK(gkyl_compare(flux[m], fluxes[d][m], 1e-14)); + } // check Riemann transform double w1[8], q1[8]; mhd->cons_to_riem(mhd, q_local, q_local, w1); mhd->riem_to_cons(mhd, q_local, w1, q1); - for (int m = 0; m < 8; ++m) + for (int m = 0; m < 8; ++m) { TEST_CHECK(gkyl_compare_double(q_local[m], q1[m], 1e-14)); + } } double q_l[8], q_g[8]; @@ -80,8 +80,9 @@ void test_mhd_basic_ho() { gkyl_wv_eqn_rotate_to_local(mhd, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(mhd, tau1[d], tau2[d], norm[d], q_l, q_g); - for (int m = 0; m < 8; ++m) + for (int m = 0; m < 8; ++m) { TEST_CHECK(gkyl_compare(q[m], q_g[m], 1e-14)); + } } gkyl_wv_eqn_release(mhd); @@ -90,16 +91,15 @@ void test_mhd_basic_ho() { /*********************************************************************/ /* CHECK IF SUM OF LEFT/RIGHT GOING FLUCTUATIONS SUM TO JUMP IN FLUX */ /*********************************************************************/ -void do_test_mhd_qfluct(enum gkyl_wv_mhd_rp rp_type, - enum gkyl_wv_flux_type ftype, enum gkyl_wv_mhd_div_constraint divb, - const double vl[], const double vr[], const int d, const double eps) { +void do_test_mhd_qfluct( + enum gkyl_wv_mhd_rp rp_type, enum gkyl_wv_flux_type ftype, enum gkyl_wv_mhd_div_constraint divb, + const double vl[], const double vr[], const int d, const double eps +) +{ double gas_gamma = 5.0 / 3.0; double ch = 1.2345; - struct gkyl_wv_eqn *eqn = - gkyl_wv_mhd_new(&(struct gkyl_wv_mhd_inp){.rp_type = rp_type, - .gas_gamma = gas_gamma, - .divergence_constraint = divb, - .glm_ch = ch}); + struct gkyl_wv_eqn *eqn = gkyl_wv_mhd_new(&(struct gkyl_wv_mhd_inp + ){.rp_type = rp_type, .gas_gamma = gas_gamma, .divergence_constraint = divb, .glm_ch = ch}); int meq = eqn->num_equations; int mwv = eqn->num_waves; @@ -128,13 +128,15 @@ void do_test_mhd_qfluct(enum gkyl_wv_mhd_rp rp_type, gkyl_wv_eqn_rotate_to_local(eqn, tau1[d], tau2[d], norm[d], qr, qr_local); // compute waves in local frame - for (int i = 0; i < meq; ++i) + for (int i = 0; i < meq; ++i) { delta[i] = qr_local[i] - ql_local[i]; + } gkyl_wv_eqn_waves(eqn, ftype, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); // compute left/right-going fluctuations in local frame - gkyl_wv_eqn_qfluct(eqn, ftype, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, - amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + eqn, ftype, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local + ); // compute fluxes in local frame if (divb == GKYL_MHD_DIVB_GLM) { @@ -146,31 +148,33 @@ void do_test_mhd_qfluct(enum gkyl_wv_mhd_rp rp_type, } // rotate local-frame waves back to global frame - for (int mw = 0; mw < mwv; ++mw) - gkyl_wv_eqn_rotate_to_global(eqn, tau1[d], tau2[d], norm[d], - &waves_local[mw * meq], &waves[mw * meq]); + for (int mw = 0; mw < mwv; ++mw) { + gkyl_wv_eqn_rotate_to_global( + eqn, tau1[d], tau2[d], norm[d], &waves_local[mw * meq], &waves[mw * meq] + ); + } // rotate local-frame fluctuations back to global frame - gkyl_wv_eqn_rotate_to_global( - eqn, tau1[d], tau2[d], norm[d], amdq_local, amdq); - gkyl_wv_eqn_rotate_to_global( - eqn, tau1[d], tau2[d], norm[d], apdq_local, apdq); + gkyl_wv_eqn_rotate_to_global(eqn, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global(eqn, tau1[d], tau2[d], norm[d], apdq_local, apdq); // rotate local-frame fluxes back to global frame gkyl_wv_eqn_rotate_to_global(eqn, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(eqn, tau1[d], tau2[d], norm[d], fr_local, fr); // check if sum of left/right-going fluctuations sum to jump in flux - for (int i = 0; i < meq; ++i) + for (int i = 0; i < meq; ++i) { TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], eps)); - for (int i = 0; i < meq; ++i) - TEST_CHECK(gkyl_compare( - fr_local[i] - fl_local[i], amdq_local[i] + apdq_local[i], eps)); + } + for (int i = 0; i < meq; ++i) { + TEST_CHECK(gkyl_compare(fr_local[i] - fl_local[i], amdq_local[i] + apdq_local[i], eps)); + } gkyl_wv_eqn_release(eqn); } -void test_mhd_qfluct_lax_ho() { +void test_mhd_qfluct_lax_ho() +{ // jumps in bx, by, and bz; checking all three directions double vl[8] = {1.0, 0.1, 0.2, 0.3, 1.5, 0.4, 0.43, 0.3}; double vr[8] = {1.1, 0.13, 0.25, 0.34, 15.0, 0.42, 0.4, -0.3}; @@ -178,11 +182,13 @@ void test_mhd_qfluct_lax_ho() { int ftype = GKYL_WV_LOW_ORDER_FLUX; int divb = GKYL_MHD_DIVB_NONE; double eps = 1e-13; - for (int d = 0; d < 3; ++d) + for (int d = 0; d < 3; ++d) { do_test_mhd_qfluct(rp_type, ftype, divb, vl, vr, d, eps); + } } -void test_mhd_qfluct_roe_ho() { +void test_mhd_qfluct_roe_ho() +{ // no jump in bx double vl[8] = {1.0, 0.1, 0.2, 0.3, 1.5, 0.4, 0.4, 0.3}; double vr[8] = {1.1, 0.13, 0.25, 0.34, 1.54, 0.4, 0.44, 0.34}; @@ -194,7 +200,8 @@ void test_mhd_qfluct_roe_ho() { do_test_mhd_qfluct(WV_MHD_RP_ROE, ftype, divb, vl, vr, d, eps); } -void test_mhd_qfluct_hlld_ho() { +void test_mhd_qfluct_hlld_ho() +{ // no jump in bx double vl[8] = {1.0, 0.1, 0.2, 0.3, 1.5, 0.4, 0.4, 0.3}; double vr[8] = {1.1, 0.13, 0.25, 0.34, 1.54, 0.4, 0.44, 0.34}; @@ -206,7 +213,8 @@ void test_mhd_qfluct_hlld_ho() { do_test_mhd_qfluct(rp_type, ftype, divb, vl, vr, d, eps); } -void test_glm_mhd_qfluct_lax_ho() { +void test_glm_mhd_qfluct_lax_ho() +{ // jumps in bx, by, and bz; checking all three directions double vl[9] = {1.0, 0.1, 0.2, 0.3, 1.5, 0.4, 0.5, 0.2, 0.0}; double vr[9] = {1.1, 0.13, 0.25, 0.34, 15.0, 0.42, 0.4, -0.3, 0.1}; @@ -214,11 +222,13 @@ void test_glm_mhd_qfluct_lax_ho() { int ftype = GKYL_WV_LOW_ORDER_FLUX; int divb = GKYL_MHD_DIVB_GLM; double eps = 1e-13; - for (int d = 0; d < 3; ++d) + for (int d = 0; d < 3; ++d) { do_test_mhd_qfluct(rp_type, ftype, divb, vl, vr, d, eps); + } } -void test_glm_mhd_qfluct_roe_ho() { +void test_glm_mhd_qfluct_roe_ho() +{ // no jump in bx double vl[9] = {1.0, 0.1, 0.2, 0.3, 1.5, 0.4, 0.5, 0.2, 0.0}; double vr[9] = {1.1, 0.13, 0.25, 0.34, 15.0, 0.4, 0.4, -0.3, 0.1}; @@ -230,7 +240,8 @@ void test_glm_mhd_qfluct_roe_ho() { do_test_mhd_qfluct(rp_type, ftype, divb, vl, vr, d, eps); } -void test_glm_mhd_qfluct_hlld_ho() { +void test_glm_mhd_qfluct_hlld_ho() +{ // no jump in bx double vl[9] = {1.0, 0.1, 0.2, 0.3, 1.5, 0.4, 0.5, 0.2, 0.0}; double vr[9] = {1.1, 0.13, 0.25, 0.34, 15.0, 0.4, 0.4, -0.3, 0.1}; @@ -243,12 +254,12 @@ void test_glm_mhd_qfluct_hlld_ho() { } TEST_LIST = { - {"mhd_basic_ho", test_mhd_basic_ho}, - {"mhd_qfluct_lax_ho", test_mhd_qfluct_lax_ho}, - {"mhd_qfluct_roe_ho", test_mhd_qfluct_roe_ho}, - {"mhd_qfluct_hlld_ho", test_mhd_qfluct_hlld_ho}, - {"glm_mhd_qfluct_lax_ho", test_glm_mhd_qfluct_lax_ho}, - {"glm_mhd_qfluct_roe_ho", test_glm_mhd_qfluct_roe_ho}, - {"glm_mhd_qfluct_hlld_ho", test_glm_mhd_qfluct_hlld_ho}, - {NULL, NULL}, + {"mhd_basic_ho", test_mhd_basic_ho}, + {"mhd_qfluct_lax_ho", test_mhd_qfluct_lax_ho}, + {"mhd_qfluct_roe_ho", test_mhd_qfluct_roe_ho}, + {"mhd_qfluct_hlld_ho", test_mhd_qfluct_hlld_ho}, + {"glm_mhd_qfluct_lax_ho", test_glm_mhd_qfluct_lax_ho}, + {"glm_mhd_qfluct_roe_ho", test_glm_mhd_qfluct_roe_ho}, + {"glm_mhd_qfluct_hlld_ho", test_glm_mhd_qfluct_hlld_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_reactive_euler.c b/moments/unit/ctest_wv_reactive_euler.c index 99e25a1a63..1aba959dc0 100644 --- a/moments/unit/ctest_wv_reactive_euler.c +++ b/moments/unit/ctest_wv_reactive_euler.c @@ -4,68 +4,67 @@ #include #include -void -test_reactive_euler_basic_ho() +void test_reactive_euler_basic_ho() { double gas_gamma = 1.4; double specific_heat_capacity = 2.5; double energy_of_formation = 1.0; double ignition_temperature = 0.25; double reaction_rate = 250.0; - struct gkyl_wv_eqn *reactive_euler = gkyl_wv_reactive_euler_new(gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, - reaction_rate, false); + struct gkyl_wv_eqn *reactive_euler = gkyl_wv_reactive_euler_new( + gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, reaction_rate, + false + ); - TEST_CHECK( reactive_euler->num_equations == 6 ); - TEST_CHECK( reactive_euler->num_waves == 2 ); + TEST_CHECK(reactive_euler->num_equations == 6); + TEST_CHECK(reactive_euler->num_waves == 2); double rho = 1.0, u = 0.1, v = 0.2, w = 0.3, p = 1.5, reac = 0.5; - double q[6] = { rho, rho * u, rho * v, rho * w, p / (gas_gamma - 1.0) + (0.5 * rho * ((u * u) + (v * v) + (w * w))) + - (energy_of_formation * (reac - 1.0)), rho * reac }; + double q[6] = { + rho, + rho * u, + rho * v, + rho * w, + p / (gas_gamma - 1.0) + (0.5 * rho * ((u * u) + (v * v) + (w * w))) + + (energy_of_formation * (reac - 1.0)), + rho * reac + }; double prims[6]; gkyl_reactive_euler_prim_vars(gas_gamma, energy_of_formation, q, prims); - TEST_CHECK( gkyl_compare(prims[0], rho, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[1], u, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[2], v, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[3], w, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[4], p, 1e-16) ); - TEST_CHECK( gkyl_compare(prims[5], reac, 1e-16) ); + TEST_CHECK(gkyl_compare(prims[0], rho, 1e-16)); + TEST_CHECK(gkyl_compare(prims[1], u, 1e-16)); + TEST_CHECK(gkyl_compare(prims[2], v, 1e-16)); + TEST_CHECK(gkyl_compare(prims[3], w, 1e-16)); + TEST_CHECK(gkyl_compare(prims[4], p, 1e-16)); + TEST_CHECK(gkyl_compare(prims[5], reac, 1e-16)); - double E = p / (gas_gamma - 1.0) + (0.5 * rho * ((u * u) + (v * v) + (w * w))) + (energy_of_formation * (reac - 1.0)); + double E = p / (gas_gamma - 1.0) + (0.5 * rho * ((u * u) + (v * v) + (w * w))) + + (energy_of_formation * (reac - 1.0)); double fluxes[3][6] = { - { rho * u, (rho * (u * u)) + p, rho * (u * v), rho * (u * w), (E + p) * u, rho * (u * reac) }, - { rho * v, rho * (v * u), (rho * (v * v)) + p, rho * (v * w), (E + p) * v, rho * (v * reac) }, - { rho * w, rho * (w * u), rho * (w * v), (rho * (w * w)) + p, (E + p) * w, rho * (w * reac) }, + {rho * u, (rho * (u * u)) + p, rho * (u * v), rho * (u * w), (E + p) * u, rho * (u * reac)}, + {rho * v, rho * (v * u), (rho * (v * v)) + p, rho * (v * w), (E + p) * v, rho * (v * reac)}, + {rho * w, rho * (w * u), rho * (w * v), (rho * (w * w)) + p, (E + p) * w, rho * (w * reac)} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[6], flux_local[6], flux[6]; for (int d = 0; d < 3; d++) { reactive_euler->rotate_to_local_func(reactive_euler, tau1[d], tau2[d], norm[d], q, q_local); gkyl_reactive_euler_flux(gas_gamma, energy_of_formation, q_local, flux_local); - reactive_euler->rotate_to_global_func(reactive_euler, tau1[d], tau2[d], norm[d], flux_local, flux); + reactive_euler->rotate_to_global_func( + reactive_euler, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 6; i++) { - TEST_CHECK( gkyl_compare(flux[i], fluxes[d][i], 1e-16) ); + TEST_CHECK(gkyl_compare(flux[i], fluxes[d][i], 1e-16)); } } @@ -75,7 +74,7 @@ test_reactive_euler_basic_ho() gkyl_wv_eqn_rotate_to_global(reactive_euler, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 6; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-16)); } double w1[6], q1[6]; @@ -83,50 +82,53 @@ test_reactive_euler_basic_ho() reactive_euler->riem_to_cons(reactive_euler, q_local, w1, q1); for (int i = 0; i < 6; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-16)); } } gkyl_wv_eqn_release(reactive_euler); } -void -test_reactive_euler_waves_ho() +void test_reactive_euler_waves_ho() { double gas_gamma = 1.4; double specific_heat_capacity = 2.5; double energy_of_formation = 1.0; double ignition_temperature = 0.25; double reaction_rate = 250.0; - struct gkyl_wv_eqn *reactive_euler = gkyl_wv_reactive_euler_new(gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, - reaction_rate, false); - + struct gkyl_wv_eqn *reactive_euler = gkyl_wv_reactive_euler_new( + gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, reaction_rate, + false + ); + double rhol = 1.0, ul = 0.1, vl = 0.2, wl = 0.3, pl = 1.5, reacl = 0.75; double rhor = 0.1, ur = 1.0, vr = 2.0, wr = 3.0, pr = 0.15, reacr = 0.25; - double ql[6] = { rhol, rhol * ul, rhol * vl, rhol * wl, pl / (gas_gamma - 1.0) + (0.5 * rhol * ((ul * ul) + (vl * vl) + (wl * wl))) + - (energy_of_formation * (reacl - 1.0)), rhol * reacl }; - double qr[6] = { rhor, rhor * ur, rhor * vr, rhor * wr, pr / (gas_gamma - 1.0) + (0.5 * rhor * ((ur * ur) + (vr * vr) + (wr * wr))) + - (energy_of_formation * (reacr - 1.0)), rhor * reacr }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[6] = { + rhol, + rhol * ul, + rhol * vl, + rhol * wl, + pl / (gas_gamma - 1.0) + (0.5 * rhol * ((ul * ul) + (vl * vl) + (wl * wl))) + + (energy_of_formation * (reacl - 1.0)), + rhol * reacl }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[6] = { + rhor, + rhor * ur, + rhor * vr, + rhor * wr, + pr / (gas_gamma - 1.0) + (0.5 * rhor * ((ur * ur) + (vr * vr) + (wr * wr))) + + (energy_of_formation * (reacr - 1.0)), + rhor * reacr }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 6], waves_local[2 * 6]; @@ -139,13 +141,21 @@ test_reactive_euler_waves_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(reactive_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + reactive_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[6], amdq_local[6]; - gkyl_wv_eqn_qfluct(reactive_euler, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + reactive_euler, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(reactive_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 6], &waves[i * 6]); + gkyl_wv_eqn_rotate_to_global( + reactive_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 6], &waves[i * 6] + ); } double apdq[6], amdq[6]; @@ -161,50 +171,53 @@ test_reactive_euler_waves_ho() gkyl_wv_eqn_rotate_to_global(reactive_euler, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 6; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-15) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-15)); } } gkyl_wv_eqn_release(reactive_euler); } -void -test_reactive_euler_waves_2_ho() +void test_reactive_euler_waves_2_ho() { double gas_gamma = 1.4; double specific_heat_capacity = 25.0; double energy_of_formation = 10.0; double ignition_temperature = 0.025; double reaction_rate = 2500.0; - struct gkyl_wv_eqn *reactive_euler = gkyl_wv_reactive_euler_new(gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, - reaction_rate, false); - + struct gkyl_wv_eqn *reactive_euler = gkyl_wv_reactive_euler_new( + gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, reaction_rate, + false + ); + double rhol = 1.0, ul = 0.1, vl = 0.2, wl = 0.3, pl = 1.5, reacl = 0.9; double rhor = 0.01, ur = 1.0, vr = 2.0, wr = 3.0, pr = 15.0, reacr = 0.1; - double ql[6] = { rhol, rhol * ul, rhol * vl, rhol * wl, pl / (gas_gamma - 1.0) + (0.5 * rhol * ((ul * ul) + (vl * vl) + (wl * wl))) + - (energy_of_formation * (reacl - 1.0)), rhol * reacl }; - double qr[6] = { rhor, rhor * ur, rhor * vr, rhor * wr, pr / (gas_gamma - 1.0) + (0.5 * rhor * ((ur * ur) + (vr * vr) + (wr * wr))) + - (energy_of_formation * (reacr - 1.0)), rhor * reacr }; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + double ql[6] = { + rhol, + rhol * ul, + rhol * vl, + rhol * wl, + pl / (gas_gamma - 1.0) + (0.5 * rhol * ((ul * ul) + (vl * vl) + (wl * wl))) + + (energy_of_formation * (reacl - 1.0)), + rhol * reacl }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, + double qr[6] = { + rhor, + rhor * ur, + rhor * vr, + rhor * wr, + pr / (gas_gamma - 1.0) + (0.5 * rhor * ((ur * ur) + (vr * vr) + (wr * wr))) + + (energy_of_formation * (reacr - 1.0)), + rhor * reacr }; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 6], waves_local[2 * 6]; @@ -217,13 +230,21 @@ test_reactive_euler_waves_2_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(reactive_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + reactive_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds + ); double apdq_local[6], amdq_local[6]; - gkyl_wv_eqn_qfluct(reactive_euler, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + reactive_euler, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, + amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(reactive_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 6], &waves[i * 6]); + gkyl_wv_eqn_rotate_to_global( + reactive_euler, tau1[d], tau2[d], norm[d], &waves_local[i * 6], &waves[i * 6] + ); } double apdq[6], amdq[6]; @@ -239,7 +260,7 @@ test_reactive_euler_waves_2_ho() gkyl_wv_eqn_rotate_to_global(reactive_euler, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 6; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); } } @@ -247,8 +268,8 @@ test_reactive_euler_waves_2_ho() } TEST_LIST = { - { "reactive_euler_basic_ho", test_reactive_euler_basic_ho }, - { "reactive_euler_waves_ho", test_reactive_euler_waves_ho }, - { "reactive_euler_waves_2_ho", test_reactive_euler_waves_2_ho }, - { NULL, NULL }, + {"reactive_euler_basic_ho", test_reactive_euler_basic_ho}, + {"reactive_euler_waves_ho", test_reactive_euler_waves_ho}, + {"reactive_euler_waves_2_ho", test_reactive_euler_waves_2_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_sr_euler.c b/moments/unit/ctest_wv_sr_euler.c index 9515979843..9fc6ef8d94 100644 --- a/moments/unit/ctest_wv_sr_euler.c +++ b/moments/unit/ctest_wv_sr_euler.c @@ -4,147 +4,134 @@ #include #include -void -calcq(double gas_gamma, const double pv[5], double q[5]) +void calcq(double gas_gamma, const double pv[5], double q[5]) { double rho = pv[0], u = pv[1], v = pv[2], w = pv[3], pr = pv[4]; - double gamma = 1 / sqrt(1 - u*u - v*v - w*w); - double rhoh = gas_gamma * pr / (gas_gamma - 1) + rho; - q[0] = gamma*rho; - q[1] = gamma*gamma*rhoh - pr; - q[2] = gamma*gamma*rhoh*u; - q[3] = gamma*gamma*rhoh*v; - q[4] = gamma*gamma*rhoh*w; - + double gamma = 1 / sqrt(1 - u * u - v * v - w * w); + double rhoh = gas_gamma * pr / (gas_gamma - 1) + rho; + q[0] = gamma * rho; + q[1] = gamma * gamma * rhoh - pr; + q[2] = gamma * gamma * rhoh * u; + q[3] = gamma * gamma * rhoh * v; + q[4] = gamma * gamma * rhoh * w; } -void -test_sr_euler_prim1_ho() +void test_sr_euler_prim1_ho() { double gas_gamma = 1.333; struct gkyl_wv_eqn *sr_euler = gkyl_wv_sr_euler_new(gas_gamma); - TEST_CHECK( sr_euler->num_equations == 5 ); - TEST_CHECK( sr_euler->num_waves == 3 ); + TEST_CHECK(sr_euler->num_equations == 5); + TEST_CHECK(sr_euler->num_waves == 3); double rho = 1.0, u = 0.9999, v = 0.0, w = 0.01, pr = 1.5; - double q[5], pv2[5], pv[5] = { rho, u, v, w, pr }; + double q[5], pv2[5], pv[5] = {rho, u, v, w, pr}; calcq(gas_gamma, pv, q); - + gkyl_sr_euler_prim_vars(gas_gamma, q, pv2); - - TEST_CHECK ( gkyl_compare(rho, pv2[0], 1e-10) ); - TEST_CHECK ( gkyl_compare(pr, pv2[1], 1e-10) ); - TEST_CHECK ( gkyl_compare(u, pv2[2], 1e-15) ); - TEST_CHECK ( gkyl_compare(v, pv2[3], 1e-15) ); - TEST_CHECK ( gkyl_compare(w, pv2[4], 1e-15) ); - double gamma = 1 / sqrt(1 - u*u - v*v - w*w); - double rhoh = gas_gamma * pr / (gas_gamma - 1) + rho; + TEST_CHECK(gkyl_compare(rho, pv2[0], 1e-10)); + TEST_CHECK(gkyl_compare(pr, pv2[1], 1e-10)); + TEST_CHECK(gkyl_compare(u, pv2[2], 1e-15)); + TEST_CHECK(gkyl_compare(v, pv2[3], 1e-15)); + TEST_CHECK(gkyl_compare(w, pv2[4], 1e-15)); + + double gamma = 1 / sqrt(1 - u * u - v * v - w * w); + double rhoh = gas_gamma * pr / (gas_gamma - 1) + rho; double fluxes[3][5] = { - { gamma*rho*u, gamma*gamma*rhoh*u, gamma*gamma*rhoh*u*u + pr, gamma*gamma*rhoh*u*v, gamma*gamma*rhoh*u*w }, - { gamma*rho*v, gamma*gamma*rhoh*v, gamma*gamma*rhoh*v*u, gamma*gamma*rhoh*v*v + pr, gamma*gamma*rhoh*v*w }, - { gamma*rho*w, gamma*gamma*rhoh*w, gamma*gamma*rhoh*w*u, gamma*gamma*rhoh*w*v, gamma*gamma*rhoh*w*w + pr }, + {gamma * rho * u, gamma * gamma * rhoh * u, gamma * gamma * rhoh * u * u + pr, + gamma * gamma * rhoh * u * v, gamma * gamma * rhoh * u * w}, + {gamma * rho * v, gamma * gamma * rhoh * v, gamma * gamma * rhoh * v * u, + gamma * gamma * rhoh * v * v + pr, gamma * gamma * rhoh * v * w}, + {gamma * rho * w, gamma * gamma * rhoh * w, gamma * gamma * rhoh * w * u, + gamma * gamma * rhoh * w * v, gamma * gamma * rhoh * w * w + pr} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[5], flux_local[5], flux[5]; - for (int d=1; d<2; ++d) { + for (int d = 1; d < 2; ++d) { sr_euler->rotate_to_local_func(sr_euler, tau1[d], tau2[d], norm[d], q, q_local); gkyl_sr_euler_flux(gas_gamma, q_local, flux_local); sr_euler->rotate_to_global_func(sr_euler, tau1[d], tau2[d], norm[d], flux_local, flux); - - for (int m=0; m<5; ++m) - TEST_CHECK( gkyl_compare(flux[m], fluxes[d][m], 1e-10) ); + + for (int m = 0; m < 5; ++m) { + TEST_CHECK(gkyl_compare(flux[m], fluxes[d][m], 1e-10)); + } } double q_l[5], q_g[5]; - for (int d=1; d<3; ++d) { + for (int d = 1; d < 3; ++d) { gkyl_wv_eqn_rotate_to_local(sr_euler, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(sr_euler, tau1[d], tau2[d], norm[d], q_l, q_g); - for (int m=0; m<5; ++m) - TEST_CHECK( gkyl_compare(q[m], q_g[m], 1e-12) ); + for (int m = 0; m < 5; ++m) { + TEST_CHECK(gkyl_compare(q[m], q_g[m], 1e-12)); + } // check Riemann transform double w1[5], q1[5]; sr_euler->cons_to_riem(sr_euler, q_local, q_local, w1); sr_euler->riem_to_cons(sr_euler, q_local, w1, q1); - - for (int m=0; m<5; ++m) - TEST_CHECK( gkyl_compare_double(q_local[m], q1[m], 1e-14) ); + + for (int m = 0; m < 5; ++m) { + TEST_CHECK(gkyl_compare_double(q_local[m], q1[m], 1e-14)); + } } - + gkyl_wv_eqn_release(sr_euler); - } -void -test_sr_euler_waves_ho() +void test_sr_euler_waves_ho() { double gas_gamma = 1.333; struct gkyl_wv_eqn *sr_euler = gkyl_wv_sr_euler_new(gas_gamma); - double vl[5] = { 1.0, 0.09, 0.02, 0.03, 1.5}; - double vr[5] = { 0.1, .9, 0.2, 0.3, 0.15}; + double vl[5] = {1.0, 0.09, 0.02, 0.03, 1.5}; + double vr[5] = {0.1, .9, 0.2, 0.3, 0.15}; double ql[5], qr[5]; double ql_local[5], qr_local[5]; - calcq(gas_gamma, vl, ql); calcq(gas_gamma, vr, qr); + calcq(gas_gamma, vl, ql); + calcq(gas_gamma, vr, qr); - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; - for (int d=0; d<3; ++d) { - double speeds[3], waves[3*5], waves_local[3*5]; + for (int d = 0; d < 3; ++d) { + double speeds[3], waves[3 * 5], waves_local[3 * 5]; // rotate to local tangent-normal frame gkyl_wv_eqn_rotate_to_local(sr_euler, tau1[d], tau2[d], norm[d], ql, ql_local); gkyl_wv_eqn_rotate_to_local(sr_euler, tau1[d], tau2[d], norm[d], qr, qr_local); double delta[5]; - for (int i=0; i<5; ++i) delta[i] = qr_local[i]-ql_local[i]; - - gkyl_wv_eqn_waves(sr_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + for (int i = 0; i < 5; ++i) { + delta[i] = qr_local[i] - ql_local[i]; + } + + gkyl_wv_eqn_waves( + sr_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); // rotate waves back to global frame - for (int mw=0; mw<3; ++mw) - gkyl_wv_eqn_rotate_to_global(sr_euler, tau1[d], tau2[d], norm[d], &waves_local[mw*5], &waves[mw*5]); - + for (int mw = 0; mw < 3; ++mw) { + gkyl_wv_eqn_rotate_to_global( + sr_euler, tau1[d], tau2[d], norm[d], &waves_local[mw * 5], &waves[mw * 5] + ); + } + double apdq[5], amdq[5]; - gkyl_wv_eqn_qfluct(sr_euler, GKYL_WV_HIGH_ORDER_FLUX, ql, qr, 1.0, 1.0, waves, speeds, amdq, apdq); + gkyl_wv_eqn_qfluct( + sr_euler, GKYL_WV_HIGH_ORDER_FLUX, ql, qr, 1.0, 1.0, waves, speeds, amdq, apdq + ); // check if sum of left/right going fluctuations sum to jump in flux double fl_local[5], fr_local[5]; @@ -154,63 +141,61 @@ test_sr_euler_waves_ho() double fl[5], fr[5]; gkyl_wv_eqn_rotate_to_global(sr_euler, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(sr_euler, tau1[d], tau2[d], norm[d], fr_local, fr); - - for (int i=0; i<5; ++i) - TEST_CHECK( gkyl_compare(fr[i]-fl[i], amdq[i]+apdq[i], 1e-12) ); + + for (int i = 0; i < 5; ++i) { + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); + } } - + gkyl_wv_eqn_release(sr_euler); } -void -test_sr_euler_waves2_ho() +void test_sr_euler_waves2_ho() { double gas_gamma = 1.3333; struct gkyl_wv_eqn *sr_euler = gkyl_wv_sr_euler_new(gas_gamma); - double vl[5] = { 1.0, 0.0999, 0.02, 0.03, 1500.}; - double vr[5] = { 0.1, 0.999, 0.01, 0.0, 0.015}; - + double vl[5] = {1.0, 0.0999, 0.02, 0.03, 1500.}; + double vr[5] = {0.1, 0.999, 0.01, 0.0, 0.015}; + double ql[5], qr[5]; double ql_local[5], qr_local[5]; - calcq(gas_gamma, vl, ql); calcq(gas_gamma, vr, qr); + calcq(gas_gamma, vl, ql); + calcq(gas_gamma, vr, qr); - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; - for (int d=0; d<3; ++d) { - double speeds[3], waves[3*5], waves_local[3*5]; + for (int d = 0; d < 3; ++d) { + double speeds[3], waves[3 * 5], waves_local[3 * 5]; // rotate to local tangent-normal frame gkyl_wv_eqn_rotate_to_local(sr_euler, tau1[d], tau2[d], norm[d], ql, ql_local); gkyl_wv_eqn_rotate_to_local(sr_euler, tau1[d], tau2[d], norm[d], qr, qr_local); double delta[5]; - for (int i=0; i<5; ++i) delta[i] = qr_local[i]-ql_local[i]; - - gkyl_wv_eqn_waves(sr_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + for (int i = 0; i < 5; ++i) { + delta[i] = qr_local[i] - ql_local[i]; + } + + gkyl_wv_eqn_waves( + sr_euler, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); // rotate waves back to global frame - for (int mw=0; mw<3; ++mw) - gkyl_wv_eqn_rotate_to_global(sr_euler, tau1[d], tau2[d], norm[d], &waves_local[mw*5], &waves[mw*5]); + for (int mw = 0; mw < 3; ++mw) { + gkyl_wv_eqn_rotate_to_global( + sr_euler, tau1[d], tau2[d], norm[d], &waves_local[mw * 5], &waves[mw * 5] + ); + } double apdq[5], amdq[5]; - gkyl_wv_eqn_qfluct(sr_euler, GKYL_WV_HIGH_ORDER_FLUX, ql, qr, 1.0, 1.0, waves, speeds, amdq, apdq); - + gkyl_wv_eqn_qfluct( + sr_euler, GKYL_WV_HIGH_ORDER_FLUX, ql, qr, 1.0, 1.0, waves, speeds, amdq, apdq + ); + // check if sum of left/right going fluctuations sum to jump in flux double fl_local[5], fr_local[5]; gkyl_sr_euler_flux(gas_gamma, ql_local, fl_local); @@ -219,18 +204,18 @@ test_sr_euler_waves2_ho() double fl[5], fr[5]; gkyl_wv_eqn_rotate_to_global(sr_euler, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(sr_euler, tau1[d], tau2[d], norm[d], fr_local, fr); - - for (int i=0; i<5; ++i) - TEST_CHECK( gkyl_compare(fr[i]-fl[i], amdq[i]+apdq[i], 1e-10) ); + + for (int i = 0; i < 5; ++i) { + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-10)); + } } gkyl_wv_eqn_release(sr_euler); } - TEST_LIST = { - { "sr_euler_prim1_ho", test_sr_euler_prim1_ho }, - { "test_sr_euler_waves_ho", test_sr_euler_waves_ho}, - { "test_sr_euler_waves2_ho", test_sr_euler_waves2_ho}, - { NULL, NULL }, + {"sr_euler_prim1_ho", test_sr_euler_prim1_ho}, + {"test_sr_euler_waves_ho", test_sr_euler_waves_ho}, + {"test_sr_euler_waves2_ho", test_sr_euler_waves2_ho}, + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_ten_moment.c b/moments/unit/ctest_wv_ten_moment.c index b9149d7524..634e0cc137 100644 --- a/moments/unit/ctest_wv_ten_moment.c +++ b/moments/unit/ctest_wv_ten_moment.c @@ -2,17 +2,9 @@ #include #include -static const int dir_u_shuffle[][3] = { - {1, 2, 3}, - {2, 3, 1}, - {3, 1, 2} -}; +static const int dir_u_shuffle[][3] = {{1, 2, 3}, {2, 3, 1}, {3, 1, 2}}; -static const int dir_p_shuffle[][6] = { - {4, 5, 6, 7, 8, 9}, - {7, 8, 5, 9, 6, 4}, - {9, 6, 8, 4, 5, 7} -}; +static const int dir_p_shuffle[][6] = {{4, 5, 6, 7, 8, 9}, {7, 8, 5, 9, 6, 4}, {9, 6, 8, 4, 5, 7}}; // Make indexing cleaner with the dir_shuffle #define RHOU d[0] @@ -26,153 +18,149 @@ static const int dir_p_shuffle[][6] = { #define PYZ dp[4] #define PZZ dp[5] -void -calcq(const double pv[10], double q[10]) +void calcq(const double pv[10], double q[10]) { double rho = pv[0], u = pv[1], v = pv[2], w = pv[3]; double pxx = pv[4], pxy = pv[5], pxz = pv[6], pyy = pv[7], pyz = pv[8], pzz = pv[9]; q[0] = rho; - q[1] = rho*u; q[2] = rho*v; q[3] = rho*w; - q[4] = pxx + rho*u*u; q[5] = pxy + rho*u*v; q[6] = pxz + rho*u*w; - q[7] = pyy + rho*v*v; q[8] = pyz + rho*v*w; q[9] = pzz + rho*w*w; + q[1] = rho * u; + q[2] = rho * v; + q[3] = rho * w; + q[4] = pxx + rho * u * u; + q[5] = pxy + rho * u * v; + q[6] = pxz + rho * u * w; + q[7] = pyy + rho * v * v; + q[8] = pyz + rho * v * w; + q[9] = pzz + rho * w * w; } -void -test_ten_moment_basic_ho() +void test_ten_moment_basic_ho() { struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new(0.0, false, false, 1, 0, false); - TEST_CHECK( ten_moment->num_equations == 10 ); - TEST_CHECK( ten_moment->num_waves == 5 ); + TEST_CHECK(ten_moment->num_equations == 10); + TEST_CHECK(ten_moment->num_waves == 5); double rho = 1.0, u = 0.1, v = 0.2, w = 0.3; double pxx = 0.5, pxy = 0.1, pxz = 0.2, pyy = 1.0, pyz = 0.3, pzz = 1.5; - double q[10], pv[10] = { rho, u, v, w, pxx, pxy, pxz, pyy, pyz, pzz }; + double q[10], pv[10] = {rho, u, v, w, pxx, pxy, pxz, pyy, pyz, pzz}; calcq(pv, q); // new array for re-computed primitive variables double var[10]; gkyl_ten_moment_primitive(q, var); // check implementation of primitive variable calculation - TEST_CHECK ( var[0] == pv[0] ); - TEST_CHECK ( var[1] == pv[1] ); - TEST_CHECK ( var[2] == pv[2] ); - TEST_CHECK ( var[3] == pv[3] ); - TEST_CHECK ( var[4] == pv[4] ); - TEST_CHECK ( var[5] == pv[5] ); - TEST_CHECK ( var[6] == pv[6] ); - TEST_CHECK ( var[7] == pv[7] ); - TEST_CHECK ( var[8] == pv[8] ); - TEST_CHECK ( var[9] == pv[9] ); + TEST_CHECK(var[0] == pv[0]); + TEST_CHECK(var[1] == pv[1]); + TEST_CHECK(var[2] == pv[2]); + TEST_CHECK(var[3] == pv[3]); + TEST_CHECK(var[4] == pv[4]); + TEST_CHECK(var[5] == pv[5]); + TEST_CHECK(var[6] == pv[6]); + TEST_CHECK(var[7] == pv[7]); + TEST_CHECK(var[8] == pv[8]); + TEST_CHECK(var[9] == pv[9]); double fluxes[3][10] = { - { rho*u, rho*u*u + pxx, rho*u*v + pxy, rho*u*w + pxz, - rho*u*u*u + 3*u*pxx, rho*u*u*v + 2*u*pxy + v*pxx, rho*u*u*w + 2*u*pxz + w*pxx, - rho*u*v*v + 2*v*pxy + u*pyy, rho*u*v*w + u*pyz + v*pxz + w*pxy, rho*u*w*w + 2*w*pxz + u*pzz }, - { rho*v, rho*u*v + pxy, rho*v*v + pyy, rho*v*w + pyz, - rho*v*u*u + 2*u*pxy + v*pxx, rho*u*v*v + 2*v*pxy + u*pyy, rho*u*v*w + u*pyz + v*pxz + w*pxy, - rho*v*v*v + 3*v*pyy, rho*v*v*w + 2*v*pyz + w*pyy, rho*v*w*w + 2*w*pyz + v*pzz}, - { rho*w, rho*u*w + pxz, rho*v*w + pyz, rho*w*w + pzz, - rho*u*u*w + 2*u*pxz + w*pxx, rho*u*v*w + u*pyz + v*pxz + w*pxy, rho*u*w*w + 2*w*pxz + u*pzz, - rho*v*v*w + 2*v*pyz + w*pyy, rho*v*w*w + 2*w*pyz + v*pzz, rho*w*w*w + 3*w*pzz }, + {rho * u, rho * u * u + pxx, rho * u * v + pxy, rho * u * w + pxz, + rho * u * u * u + 3 * u * pxx, rho * u * u * v + 2 * u * pxy + v * pxx, + rho * u * u * w + 2 * u * pxz + w * pxx, rho * u * v * v + 2 * v * pxy + u * pyy, + rho * u * v * w + u * pyz + v * pxz + w * pxy, rho * u * w * w + 2 * w * pxz + u * pzz}, + {rho * v, rho * u * v + pxy, rho * v * v + pyy, rho * v * w + pyz, + rho * v * u * u + 2 * u * pxy + v * pxx, rho * u * v * v + 2 * v * pxy + u * pyy, + rho * u * v * w + u * pyz + v * pxz + w * pxy, rho * v * v * v + 3 * v * pyy, + rho * v * v * w + 2 * v * pyz + w * pyy, rho * v * w * w + 2 * w * pyz + v * pzz}, + {rho * w, rho * u * w + pxz, rho * v * w + pyz, rho * w * w + pzz, + rho * u * u * w + 2 * u * pxz + w * pxx, rho * u * v * w + u * pyz + v * pxz + w * pxy, + rho * u * w * w + 2 * w * pxz + u * pzz, rho * v * v * w + 2 * v * pyz + w * pyy, + rho * v * w * w + 2 * w * pyz + v * pzz, rho * w * w * w + 3 * w * pzz} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[10], flux_local[10], flux[10]; - for (int d=0; d<3; ++d) { + for (int d = 0; d < 3; ++d) { ten_moment->rotate_to_local_func(ten_moment, tau1[d], tau2[d], norm[d], q, q_local); gkyl_ten_moment_flux(q_local, flux_local); ten_moment->rotate_to_global_func(ten_moment, tau1[d], tau2[d], norm[d], flux_local, flux); - - for (int m=0; m<10; ++m) - TEST_CHECK( gkyl_compare(flux[m], fluxes[d][m], 1e-15) ); + + for (int m = 0; m < 10; ++m) { + TEST_CHECK(gkyl_compare(flux[m], fluxes[d][m], 1e-15)); + } } double q_l[10], q_g[10]; - for (int d=0; d<3; ++d) { + for (int d = 0; d < 3; ++d) { gkyl_wv_eqn_rotate_to_local(ten_moment, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(ten_moment, tau1[d], tau2[d], norm[d], q_l, q_g); - for (int m=0; m<10; ++m) TEST_CHECK( q[m] == q_g[m] ); + for (int m = 0; m < 10; ++m) { + TEST_CHECK(q[m] == q_g[m]); + } // check Riemann transform double w1[10], q1[10]; ten_moment->cons_to_riem(ten_moment, q_local, q_local, w1); ten_moment->riem_to_cons(ten_moment, q_local, w1, q1); - - for (int m=0; m<10; ++m) - TEST_CHECK( gkyl_compare_double(q_local[m], q1[m], 1e-14) ); + + for (int m = 0; m < 10; ++m) { + TEST_CHECK(gkyl_compare_double(q_local[m], q1[m], 1e-14)); + } } - + gkyl_wv_eqn_release(ten_moment); } -void -test_ten_moment_waves_ho() +void test_ten_moment_waves_ho() { struct gkyl_wv_eqn *ten_moment = gkyl_wv_ten_moment_new(0.0, false, false, 1, 0, false); - double vl[10] = { 1.0, 0.1, 0.2, 0.3, 0.5, 0.0, 0.0, 1.0, 0.0, 1.5}; - double vr[10] = { 0.1, 1.0, 2.0, 3.0, 0.1, 0.0, 0.0, 0.2, 0.0, 0.3}; + double vl[10] = {1.0, 0.1, 0.2, 0.3, 0.5, 0.0, 0.0, 1.0, 0.0, 1.5}; + double vr[10] = {0.1, 1.0, 2.0, 3.0, 0.1, 0.0, 0.0, 0.2, 0.0, 0.3}; double ql[10], qr[10]; double ql_local[10], qr_local[10]; - calcq(vl, ql); calcq(vr, qr); + calcq(vl, ql); + calcq(vr, qr); - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; - for (int d=0; d<3; ++d) { - double speeds[5], waves[5*10], waves_local[5*10]; + for (int d = 0; d < 3; ++d) { + double speeds[5], waves[5 * 10], waves_local[5 * 10]; // rotate to local tangent-normal frame gkyl_wv_eqn_rotate_to_local(ten_moment, tau1[d], tau2[d], norm[d], ql, ql_local); gkyl_wv_eqn_rotate_to_local(ten_moment, tau1[d], tau2[d], norm[d], qr, qr_local); double delta[10]; - for (int i=0; i<10; ++i) delta[i] = qr_local[i]-ql_local[i]; - - gkyl_wv_eqn_waves(ten_moment, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + for (int i = 0; i < 10; ++i) { + delta[i] = qr_local[i] - ql_local[i]; + } + + gkyl_wv_eqn_waves( + ten_moment, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); // rotate waves back to global frame - for (int mw=0; mw<5; ++mw) - gkyl_wv_eqn_rotate_to_global(ten_moment, tau1[d], tau2[d], norm[d], &waves_local[mw*10], &waves[mw*10]); + for (int mw = 0; mw < 5; ++mw) { + gkyl_wv_eqn_rotate_to_global( + ten_moment, tau1[d], tau2[d], norm[d], &waves_local[mw * 10], &waves[mw * 10] + ); + } double apdq[10], amdq[10]; - gkyl_wv_eqn_qfluct(ten_moment, GKYL_WV_HIGH_ORDER_FLUX, ql, qr, 1.0, 1.0, waves, speeds, amdq, apdq); - + gkyl_wv_eqn_qfluct( + ten_moment, GKYL_WV_HIGH_ORDER_FLUX, ql, qr, 1.0, 1.0, waves, speeds, amdq, apdq + ); + // check if sum of left/right going fluctuations sum to jump in flux double fl_local[10], fr_local[10]; gkyl_ten_moment_flux(ql_local, fl_local); @@ -181,11 +169,12 @@ test_ten_moment_waves_ho() double fl[10], fr[10]; gkyl_wv_eqn_rotate_to_global(ten_moment, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(ten_moment, tau1[d], tau2[d], norm[d], fr_local, fr); - - for (int i=0; i<10; ++i) - TEST_CHECK( gkyl_compare(fr[i]-fl[i], amdq[i]+apdq[i], 1e-14) ); + + for (int i = 0; i < 10; ++i) { + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-14)); + } } - + gkyl_wv_eqn_release(ten_moment); } @@ -193,8 +182,7 @@ test_ten_moment_waves_ho() int cu_wv_ten_moment_test(const struct gkyl_wv_eqn *eqn); -void -test_wv_ten_moment_dev() +void test_wv_ten_moment_dev() { double k0 = 1.0; struct gkyl_wv_eqn *eqn = gkyl_wv_ten_moment_new(k0, false, false, 0, 0, true); @@ -203,12 +191,12 @@ test_wv_ten_moment_dev() // is for testing only struct wv_ten_moment *ten_moment = container_of(eqn, struct wv_ten_moment, eqn); - TEST_CHECK( ten_moment->k0 == 1.0 ); - + TEST_CHECK(ten_moment->k0 == 1.0); + // call CUDA test int nfail = cu_wv_ten_moment_test(eqn->on_dev); - TEST_CHECK( nfail == 0 ); + TEST_CHECK(nfail == 0); gkyl_wv_eqn_release(eqn); } @@ -216,10 +204,10 @@ test_wv_ten_moment_dev() #endif TEST_LIST = { - { "ten_moment_basic_ho", test_ten_moment_basic_ho }, - { "ten_moment_waves_ho", test_ten_moment_waves_ho }, + {"ten_moment_basic_ho", test_ten_moment_basic_ho}, + {"ten_moment_waves_ho", test_ten_moment_waves_ho}, #ifdef GKYL_HAVE_CUDA - { "wv_ten_moment_dev", test_wv_ten_moment_dev }, -#endif - { NULL, NULL }, + {"wv_ten_moment_dev", test_wv_ten_moment_dev}, +#endif + {NULL, NULL} }; diff --git a/moments/unit/ctest_wv_ten_moment_cu.cu b/moments/unit/ctest_wv_ten_moment_cu.cu index 9c672235c6..eeb22ab7d6 100644 --- a/moments/unit/ctest_wv_ten_moment_cu.cu +++ b/moments/unit/ctest_wv_ten_moment_cu.cu @@ -11,83 +11,77 @@ extern "C" { int cu_wv_ten_moment_test(const struct gkyl_wv_eqn *eqn); } -__global__ -void ker_cu_wv_ten_moment_test(const struct gkyl_wv_eqn *eqn, int *nfail) +__global__ void ker_cu_wv_ten_moment_test(const struct gkyl_wv_eqn *eqn, int *nfail) { *nfail = 0; - GKYL_CU_CHECK( eqn->num_equations == 10, nfail ); - GKYL_CU_CHECK( eqn->num_waves == 5, nfail ); + GKYL_CU_CHECK(eqn->num_equations == 10, nfail); + GKYL_CU_CHECK(eqn->num_waves == 5, nfail); // DO NOT DO THIS IN PRODUCTION! ONLY FOR TESTING struct wv_ten_moment *ten_moment = container_of(eqn, struct wv_ten_moment, eqn); - GKYL_CU_CHECK( ten_moment->k0 == 1.0, nfail ); + GKYL_CU_CHECK(ten_moment->k0 == 1.0, nfail); - double vl[10] = { 1.0, 0.1, 0.2, 0.3, 0.5, 0.0, 0.0, 1.0, 0.0, 1.5}; - double vr[10] = { 0.1, 1.0, 2.0, 3.0, 0.1, 0.0, 0.0, 0.2, 0.0, 0.3}; + double vl[10] = {1.0, 0.1, 0.2, 0.3, 0.5, 0.0, 0.0, 1.0, 0.0, 1.5}; + double vr[10] = {0.1, 1.0, 2.0, 3.0, 0.1, 0.0, 0.0, 0.2, 0.0, 0.3}; double ql[10], qr[10]; double ql_local[10], qr_local[10]; ql[0] = vl[0]; - ql[1] = vl[0]*vl[1]; - ql[2] = vl[0]*vl[2]; - ql[3] = vl[0]*vl[3]; - ql[4] = vl[4] + vl[0]*vl[1]*vl[1]; - ql[5] = vl[5] + vl[0]*vl[1]*vl[2]; - ql[6] = vl[6] + vl[0]*vl[1]*vl[3]; - ql[7] = vl[7] + vl[0]*vl[2]*vl[2]; - ql[8] = vl[8] + vl[0]*vl[2]*vl[3]; - ql[9] = vl[9] + vl[0]*vl[3]*vl[3]; + ql[1] = vl[0] * vl[1]; + ql[2] = vl[0] * vl[2]; + ql[3] = vl[0] * vl[3]; + ql[4] = vl[4] + vl[0] * vl[1] * vl[1]; + ql[5] = vl[5] + vl[0] * vl[1] * vl[2]; + ql[6] = vl[6] + vl[0] * vl[1] * vl[3]; + ql[7] = vl[7] + vl[0] * vl[2] * vl[2]; + ql[8] = vl[8] + vl[0] * vl[2] * vl[3]; + ql[9] = vl[9] + vl[0] * vl[3] * vl[3]; qr[0] = vr[0]; - qr[1] = vr[0]*vr[1]; - qr[2] = vr[0]*vr[2]; - qr[3] = vr[0]*vr[3]; - qr[4] = vr[4] + vr[0]*vr[1]*vr[1]; - qr[5] = vr[5] + vr[0]*vr[1]*vr[2]; - qr[6] = vr[6] + vr[0]*vr[1]*vr[3]; - qr[7] = vr[7] + vr[0]*vr[2]*vr[2]; - qr[8] = vr[8] + vr[0]*vr[2]*vr[3]; - qr[9] = vr[9] + vr[0]*vr[3]*vr[3]; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, -1.0, 0.0 }, - { 0.0, 0.0, 1.0 } - }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 } - }; - - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 0.0 } - }; - - for (int d=0; d<3; ++d) { - double speeds[5], waves[5*10], waves_local[5*10]; + qr[1] = vr[0] * vr[1]; + qr[2] = vr[0] * vr[2]; + qr[3] = vr[0] * vr[3]; + qr[4] = vr[4] + vr[0] * vr[1] * vr[1]; + qr[5] = vr[5] + vr[0] * vr[1] * vr[2]; + qr[6] = vr[6] + vr[0] * vr[1] * vr[3]; + qr[7] = vr[7] + vr[0] * vr[2] * vr[2]; + qr[8] = vr[8] + vr[0] * vr[2] * vr[3]; + qr[9] = vr[9] + vr[0] * vr[3] * vr[3]; + + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}}; + + for (int d = 0; d < 3; ++d) { + double speeds[5], waves[5 * 10], waves_local[5 * 10]; // rotate to local tangent-normal frame eqn->rotate_to_local_func(eqn, tau1[d], tau2[d], norm[d], ql, ql_local); eqn->rotate_to_local_func(eqn, tau1[d], tau2[d], norm[d], qr, qr_local); double delta[10]; - for (int i=0; i<10; ++i) delta[i] = qr_local[i]-ql_local[i]; - - eqn->waves_func(eqn, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + for (int i = 0; i < 10; ++i) { + delta[i] = qr_local[i] - ql_local[i]; + } + + eqn->waves_func( + eqn, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds + ); // rotate waves back to global frame - for (int mw=0; mw<5; ++mw) - eqn->rotate_to_global_func(eqn, tau1[d], tau2[d], norm[d], &waves_local[mw*10], &waves[mw*10]); + for (int mw = 0; mw < 5; ++mw) { + eqn->rotate_to_global_func( + eqn, tau1[d], tau2[d], norm[d], &waves_local[mw * 10], &waves[mw * 10] + ); + } double apdq[10], amdq[10]; eqn->qfluct_func(eqn, GKYL_WV_HIGH_ORDER_FLUX, ql, qr, 1.0, 1.0, waves, speeds, amdq, apdq); - + // check if sum of left/right going fluctuations sum to jump in flux double fl_local[10], fr_local[10]; gkyl_ten_moment_flux(ql_local, fl_local); @@ -96,16 +90,17 @@ void ker_cu_wv_ten_moment_test(const struct gkyl_wv_eqn *eqn, int *nfail) double fl[10], fr[10]; eqn->rotate_to_global_func(eqn, tau1[d], tau2[d], norm[d], fl_local, fl); eqn->rotate_to_global_func(eqn, tau1[d], tau2[d], norm[d], fr_local, fr); - - for (int i=0; i<10; ++i) - GKYL_CU_CHECK( fabs((fr[i]-fl[i]) - (amdq[i]+apdq[i])) < 1e-14, nfail ); + + for (int i = 0; i < 10; ++i) { + GKYL_CU_CHECK(fabs((fr[i] - fl[i]) - (amdq[i] + apdq[i])) < 1e-14, nfail); + } } } int cu_wv_ten_moment_test(const struct gkyl_wv_eqn *eqn) { - int *nfail_dev = (int *) gkyl_cu_malloc(sizeof(int)); - ker_cu_wv_ten_moment_test<<<1,1>>>(eqn, nfail_dev); + int *nfail_dev = (int *)gkyl_cu_malloc(sizeof(int)); + ker_cu_wv_ten_moment_test<<<1, 1> > >(eqn, nfail_dev); int nfail; gkyl_cu_memcpy(&nfail, nfail_dev, sizeof(int), GKYL_CU_MEMCPY_D2H); diff --git a/moments/unit/ctest_wv_vacuum_einstein.c b/moments/unit/ctest_wv_vacuum_einstein.c index 360b481cf9..4ed1520e17 100644 --- a/moments/unit/ctest_wv_vacuum_einstein.c +++ b/moments/unit/ctest_wv_vacuum_einstein.c @@ -6,17 +6,17 @@ #include #include -void -test_vacuum_einstein_basic_minkowski_ho() +void test_vacuum_einstein_basic_minkowski_ho() { double excision_threshold = 0.3; enum gkyl_spacetime_slicing spacetime_slicing = GKYL_HARMONIC_SLICING; enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); + struct gkyl_wv_eqn *vacuum_einstein = + gkyl_wv_vacuum_einstein_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); - TEST_CHECK( vacuum_einstein->num_equations == 64 ); - TEST_CHECK( vacuum_einstein->num_waves == 2 ); + TEST_CHECK(vacuum_einstein->num_equations == 64); + TEST_CHECK(vacuum_einstein->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -27,27 +27,27 @@ test_vacuum_einstein_basic_minkowski_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -58,14 +58,24 @@ test_vacuum_einstein_basic_minkowski_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -93,14 +103,15 @@ test_vacuum_einstein_basic_minkowski_ho() for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1[k][i][j] += inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; + spatial_metric_der_raised1[k][i][j] += + inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; } } } } - + double spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -108,7 +119,8 @@ test_vacuum_einstein_basic_minkowski_ho() spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3[i][j][k] += inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; + spatial_metric_der_raised3[i][j][k] += + inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; } } } @@ -127,7 +139,7 @@ test_vacuum_einstein_basic_minkowski_ho() double aux_vect_raised[3]; for (int k = 0; k < 3; k++) { aux_vect_raised[k] = 0.0; - + for (int l = 0; l < 3; l++) { aux_vect_raised[k] += inv_spatial_metric[k][l] * aux_vect[l]; } @@ -151,7 +163,8 @@ test_vacuum_einstein_basic_minkowski_ho() for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - shift_der_switched[i][k] += inv_spatial_metric[i][l] * spatial_metric[m][k] * shift_der[l][m]; + shift_der_switched[i][k] += + inv_spatial_metric[i][l] * spatial_metric[m][k] * shift_der[l][m]; } } } @@ -160,42 +173,85 @@ test_vacuum_einstein_basic_minkowski_ho() double symmetrized_shift[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - symmetrized_shift[i][j] = (1.0 / lapse) * (shift_der_lowered[i][j] + shift_der_lowered[j][i]); + symmetrized_shift[i][j] = + (1.0 / lapse) * (shift_der_lowered[i][j] + shift_der_lowered[j][i]); } } double q[64]; - q[0] = spatial_metric[0][0]; q[1] = spatial_metric[0][1]; q[2] = spatial_metric[0][2]; - q[3] = spatial_metric[1][0]; q[4] = spatial_metric[1][1]; q[5] = spatial_metric[1][2]; - q[6] = spatial_metric[2][0]; q[7] = spatial_metric[2][1]; q[8] = spatial_metric[2][2]; + q[0] = spatial_metric[0][0]; + q[1] = spatial_metric[0][1]; + q[2] = spatial_metric[0][2]; + q[3] = spatial_metric[1][0]; + q[4] = spatial_metric[1][1]; + q[5] = spatial_metric[1][2]; + q[6] = spatial_metric[2][0]; + q[7] = spatial_metric[2][1]; + q[8] = spatial_metric[2][2]; q[9] = lapse; - q[10] = extrinsic_curvature[0][0]; q[11] = extrinsic_curvature[0][1]; q[12] = extrinsic_curvature[0][2]; - q[13] = extrinsic_curvature[1][0]; q[14] = extrinsic_curvature[1][1]; q[15] = extrinsic_curvature[1][2]; - q[16] = extrinsic_curvature[2][0]; q[17] = extrinsic_curvature[2][1]; q[18] = extrinsic_curvature[2][2]; - - q[19] = spatial_metric_der[0][0][0]; q[20] = spatial_metric_der[0][0][1]; q[21] = spatial_metric_der[0][0][2]; - q[22] = spatial_metric_der[0][1][0]; q[23] = spatial_metric_der[0][1][1]; q[24] = spatial_metric_der[0][1][2]; - q[25] = spatial_metric_der[0][2][0]; q[26] = spatial_metric_der[0][2][1]; q[27] = spatial_metric_der[0][2][2]; - - q[28] = spatial_metric_der[1][0][0]; q[29] = spatial_metric_der[1][0][1]; q[30] = spatial_metric_der[1][0][2]; - q[31] = spatial_metric_der[1][1][0]; q[32] = spatial_metric_der[1][1][1]; q[33] = spatial_metric_der[1][1][2]; - q[34] = spatial_metric_der[1][2][0]; q[35] = spatial_metric_der[1][2][1]; q[36] = spatial_metric_der[1][2][2]; - - q[37] = spatial_metric_der[2][0][0]; q[38] = spatial_metric_der[2][0][1]; q[39] = spatial_metric_der[2][0][2]; - q[40] = spatial_metric_der[2][1][0]; q[41] = spatial_metric_der[2][1][1]; q[42] = spatial_metric_der[2][1][2]; - q[43] = spatial_metric_der[2][2][0]; q[44] = spatial_metric_der[2][2][1]; q[45] = spatial_metric_der[2][2][2]; - - q[46] = lapse_der[0]; q[47] = lapse_der[1]; q[48] = lapse_der[2]; - - q[49] = aux_vect[0]; q[50] = aux_vect[1]; q[51] = aux_vect[2]; - - q[52] = shift[0]; q[53] = shift[1]; q[54] = shift[2]; - - q[55] = shift_der[0][0]; q[56] = shift_der[0][1]; q[57] = shift_der[0][2]; - q[58] = shift_der[1][0]; q[59] = shift_der[1][1]; q[60] = shift_der[1][2]; - q[61] = shift_der[2][0]; q[62] = shift_der[2][1]; q[63] = shift_der[2][2]; + q[10] = extrinsic_curvature[0][0]; + q[11] = extrinsic_curvature[0][1]; + q[12] = extrinsic_curvature[0][2]; + q[13] = extrinsic_curvature[1][0]; + q[14] = extrinsic_curvature[1][1]; + q[15] = extrinsic_curvature[1][2]; + q[16] = extrinsic_curvature[2][0]; + q[17] = extrinsic_curvature[2][1]; + q[18] = extrinsic_curvature[2][2]; + + q[19] = spatial_metric_der[0][0][0]; + q[20] = spatial_metric_der[0][0][1]; + q[21] = spatial_metric_der[0][0][2]; + q[22] = spatial_metric_der[0][1][0]; + q[23] = spatial_metric_der[0][1][1]; + q[24] = spatial_metric_der[0][1][2]; + q[25] = spatial_metric_der[0][2][0]; + q[26] = spatial_metric_der[0][2][1]; + q[27] = spatial_metric_der[0][2][2]; + + q[28] = spatial_metric_der[1][0][0]; + q[29] = spatial_metric_der[1][0][1]; + q[30] = spatial_metric_der[1][0][2]; + q[31] = spatial_metric_der[1][1][0]; + q[32] = spatial_metric_der[1][1][1]; + q[33] = spatial_metric_der[1][1][2]; + q[34] = spatial_metric_der[1][2][0]; + q[35] = spatial_metric_der[1][2][1]; + q[36] = spatial_metric_der[1][2][2]; + + q[37] = spatial_metric_der[2][0][0]; + q[38] = spatial_metric_der[2][0][1]; + q[39] = spatial_metric_der[2][0][2]; + q[40] = spatial_metric_der[2][1][0]; + q[41] = spatial_metric_der[2][1][1]; + q[42] = spatial_metric_der[2][1][2]; + q[43] = spatial_metric_der[2][2][0]; + q[44] = spatial_metric_der[2][2][1]; + q[45] = spatial_metric_der[2][2][2]; + + q[46] = lapse_der[0]; + q[47] = lapse_der[1]; + q[48] = lapse_der[2]; + + q[49] = aux_vect[0]; + q[50] = aux_vect[1]; + q[51] = aux_vect[2]; + + q[52] = shift[0]; + q[53] = shift[1]; + q[54] = shift[2]; + + q[55] = shift_der[0][0]; + q[56] = shift_der[0][1]; + q[57] = shift_der[0][2]; + q[58] = shift_der[1][0]; + q[59] = shift_der[1][1]; + q[60] = shift_der[1][2]; + q[61] = shift_der[2][0]; + q[62] = shift_der[2][1]; + q[63] = shift_der[2][2]; double evolution_func = 1.0; double slicing_func = extrinsic_curvature_trace; @@ -206,13 +262,15 @@ test_vacuum_einstein_basic_minkowski_ho() for (int j = 0; j < 3; j++) { extrinsic_curvature_flux[d][i][j] = -shift[d] * extrinsic_curvature[i][j]; extrinsic_curvature_flux[d][i][j] += lapse * spatial_metric_der_raised1[d][i][j]; - extrinsic_curvature_flux[d][i][j] -= lapse * (0.5 * evolution_func) * aux_vect_raised[d] * spatial_metric[i][j]; + extrinsic_curvature_flux[d][i][j] -= + lapse * (0.5 * evolution_func) * aux_vect_raised[d] * spatial_metric[i][j]; if (i == d) { extrinsic_curvature_flux[d][i][j] += 0.5 * lapse * lapse_der[j]; extrinsic_curvature_flux[d][i][j] += lapse * aux_vect[j]; for (int r = 0; r < 3; r++) { - extrinsic_curvature_flux[d][i][j] -= 0.5 * lapse * spatial_metric_der_raised3[j][r][r]; + extrinsic_curvature_flux[d][i][j] -= + 0.5 * lapse * spatial_metric_der_raised3[j][r][r]; } } @@ -220,13 +278,14 @@ test_vacuum_einstein_basic_minkowski_ho() extrinsic_curvature_flux[d][i][j] += 0.5 * lapse * lapse_der[i]; extrinsic_curvature_flux[d][i][j] += lapse * aux_vect[i]; for (int r = 0; r < 3; r++) { - extrinsic_curvature_flux[d][i][j] -= 0.5 * lapse * spatial_metric_der_raised3[i][r][r]; + extrinsic_curvature_flux[d][i][j] -= + 0.5 * lapse * spatial_metric_der_raised3[i][r][r]; } } } } } - + double spatial_metric_der_flux[3][3][3][3]; for (int d = 0; d < 3; d++) { for (int i = 0; i < 3; i++) { @@ -239,7 +298,8 @@ test_vacuum_einstein_basic_minkowski_ho() spatial_metric_der_flux[d][d][i][j] -= shift[r] * spatial_metric_der[r][i][j]; } - spatial_metric_der_flux[d][d][i][j] += lapse * (extrinsic_curvature[i][j] - symmetrized_shift[i][j]); + spatial_metric_der_flux[d][d][i][j] += + lapse * (extrinsic_curvature[i][j] - symmetrized_shift[i][j]); } } } @@ -250,7 +310,7 @@ test_vacuum_einstein_basic_minkowski_ho() lapse_der_flux[d][i] = 0.0; } } - + for (int d = 0; d < 3; d++) { for (int r = 0; r < 3; r++) { lapse_der_flux[d][d] -= shift[r] * lapse_der[r]; @@ -268,86 +328,164 @@ test_vacuum_einstein_basic_minkowski_ho() } double fluxes[3][42] = { - { extrinsic_curvature_flux[0][0][0], extrinsic_curvature_flux[0][0][1], extrinsic_curvature_flux[0][0][2], - extrinsic_curvature_flux[0][1][0], extrinsic_curvature_flux[0][1][1], extrinsic_curvature_flux[0][1][2], - extrinsic_curvature_flux[0][2][0], extrinsic_curvature_flux[0][2][1], extrinsic_curvature_flux[0][2][2], - spatial_metric_der_flux[0][0][0][0], spatial_metric_der_flux[0][0][0][1], spatial_metric_der_flux[0][0][0][2], - spatial_metric_der_flux[0][0][1][0], spatial_metric_der_flux[0][0][1][1], spatial_metric_der_flux[0][0][1][2], - spatial_metric_der_flux[0][0][2][0], spatial_metric_der_flux[0][0][2][1], spatial_metric_der_flux[0][0][2][2], - spatial_metric_der_flux[0][1][0][0], spatial_metric_der_flux[0][1][0][1], spatial_metric_der_flux[0][1][0][2], - spatial_metric_der_flux[0][1][1][0], spatial_metric_der_flux[0][1][1][1], spatial_metric_der_flux[0][1][1][2], - spatial_metric_der_flux[0][1][2][0], spatial_metric_der_flux[0][1][2][1], spatial_metric_der_flux[0][1][2][2], - spatial_metric_der_flux[0][2][0][0], spatial_metric_der_flux[0][2][0][1], spatial_metric_der_flux[0][2][0][2], - spatial_metric_der_flux[0][2][1][0], spatial_metric_der_flux[0][2][1][1], spatial_metric_der_flux[0][2][1][2], - spatial_metric_der_flux[0][2][2][0], spatial_metric_der_flux[0][2][2][1], spatial_metric_der_flux[0][2][2][2], - lapse_der_flux[0][0], lapse_der_flux[0][1], lapse_der_flux[0][2], - aux_vect_flux[0][0], aux_vect_flux[0][1], aux_vect_flux[0][2] }, - { extrinsic_curvature_flux[1][0][0], extrinsic_curvature_flux[1][0][1], extrinsic_curvature_flux[1][0][2], - extrinsic_curvature_flux[1][1][0], extrinsic_curvature_flux[1][1][1], extrinsic_curvature_flux[1][1][2], - extrinsic_curvature_flux[1][2][0], extrinsic_curvature_flux[1][2][1], extrinsic_curvature_flux[1][2][2], - spatial_metric_der_flux[1][0][0][0], spatial_metric_der_flux[1][0][0][1], spatial_metric_der_flux[1][0][0][2], - spatial_metric_der_flux[1][0][1][0], spatial_metric_der_flux[1][0][1][1], spatial_metric_der_flux[1][0][1][2], - spatial_metric_der_flux[1][0][2][0], spatial_metric_der_flux[1][0][2][1], spatial_metric_der_flux[1][0][2][2], - spatial_metric_der_flux[1][1][0][0], spatial_metric_der_flux[1][1][0][1], spatial_metric_der_flux[1][1][0][2], - spatial_metric_der_flux[1][1][1][0], spatial_metric_der_flux[1][1][1][1], spatial_metric_der_flux[1][1][1][2], - spatial_metric_der_flux[1][1][2][0], spatial_metric_der_flux[1][1][2][1], spatial_metric_der_flux[1][1][2][2], - spatial_metric_der_flux[1][2][0][0], spatial_metric_der_flux[1][2][0][1], spatial_metric_der_flux[1][2][0][2], - spatial_metric_der_flux[1][2][1][0], spatial_metric_der_flux[1][2][1][1], spatial_metric_der_flux[1][2][1][2], - spatial_metric_der_flux[1][2][2][0], spatial_metric_der_flux[1][2][2][1], spatial_metric_der_flux[1][2][2][2], - lapse_der_flux[1][0], lapse_der_flux[1][1], lapse_der_flux[1][2], - aux_vect_flux[1][0], aux_vect_flux[1][1], aux_vect_flux[1][2] }, - { extrinsic_curvature_flux[2][0][0], extrinsic_curvature_flux[2][0][1], extrinsic_curvature_flux[2][0][2], - extrinsic_curvature_flux[2][1][0], extrinsic_curvature_flux[2][1][1], extrinsic_curvature_flux[2][1][2], - extrinsic_curvature_flux[2][2][0], extrinsic_curvature_flux[2][2][1], extrinsic_curvature_flux[2][2][2], - spatial_metric_der_flux[2][0][0][0], spatial_metric_der_flux[2][0][0][1], spatial_metric_der_flux[2][0][0][2], - spatial_metric_der_flux[2][0][1][0], spatial_metric_der_flux[2][0][1][1], spatial_metric_der_flux[2][0][1][2], - spatial_metric_der_flux[2][0][2][0], spatial_metric_der_flux[2][0][2][1], spatial_metric_der_flux[2][0][2][2], - spatial_metric_der_flux[2][1][0][0], spatial_metric_der_flux[2][1][0][1], spatial_metric_der_flux[2][1][0][2], - spatial_metric_der_flux[2][1][1][0], spatial_metric_der_flux[2][1][1][1], spatial_metric_der_flux[2][1][1][2], - spatial_metric_der_flux[2][1][2][0], spatial_metric_der_flux[2][1][2][1], spatial_metric_der_flux[2][1][2][2], - spatial_metric_der_flux[2][2][0][0], spatial_metric_der_flux[2][2][0][1], spatial_metric_der_flux[2][2][0][2], - spatial_metric_der_flux[2][2][1][0], spatial_metric_der_flux[2][2][1][1], spatial_metric_der_flux[2][2][1][2], - spatial_metric_der_flux[2][2][2][0], spatial_metric_der_flux[2][2][2][1], spatial_metric_der_flux[2][2][2][2], - lapse_der_flux[2][0], lapse_der_flux[2][1], lapse_der_flux[2][2], - aux_vect_flux[2][0], aux_vect_flux[2][1], aux_vect_flux[2][2] }, + {extrinsic_curvature_flux[0][0][0], + extrinsic_curvature_flux[0][0][1], + extrinsic_curvature_flux[0][0][2], + extrinsic_curvature_flux[0][1][0], + extrinsic_curvature_flux[0][1][1], + extrinsic_curvature_flux[0][1][2], + extrinsic_curvature_flux[0][2][0], + extrinsic_curvature_flux[0][2][1], + extrinsic_curvature_flux[0][2][2], + spatial_metric_der_flux[0][0][0][0], + spatial_metric_der_flux[0][0][0][1], + spatial_metric_der_flux[0][0][0][2], + spatial_metric_der_flux[0][0][1][0], + spatial_metric_der_flux[0][0][1][1], + spatial_metric_der_flux[0][0][1][2], + spatial_metric_der_flux[0][0][2][0], + spatial_metric_der_flux[0][0][2][1], + spatial_metric_der_flux[0][0][2][2], + spatial_metric_der_flux[0][1][0][0], + spatial_metric_der_flux[0][1][0][1], + spatial_metric_der_flux[0][1][0][2], + spatial_metric_der_flux[0][1][1][0], + spatial_metric_der_flux[0][1][1][1], + spatial_metric_der_flux[0][1][1][2], + spatial_metric_der_flux[0][1][2][0], + spatial_metric_der_flux[0][1][2][1], + spatial_metric_der_flux[0][1][2][2], + spatial_metric_der_flux[0][2][0][0], + spatial_metric_der_flux[0][2][0][1], + spatial_metric_der_flux[0][2][0][2], + spatial_metric_der_flux[0][2][1][0], + spatial_metric_der_flux[0][2][1][1], + spatial_metric_der_flux[0][2][1][2], + spatial_metric_der_flux[0][2][2][0], + spatial_metric_der_flux[0][2][2][1], + spatial_metric_der_flux[0][2][2][2], + lapse_der_flux[0][0], + lapse_der_flux[0][1], + lapse_der_flux[0][2], + aux_vect_flux[0][0], + aux_vect_flux[0][1], + aux_vect_flux[0][2]}, + {extrinsic_curvature_flux[1][0][0], + extrinsic_curvature_flux[1][0][1], + extrinsic_curvature_flux[1][0][2], + extrinsic_curvature_flux[1][1][0], + extrinsic_curvature_flux[1][1][1], + extrinsic_curvature_flux[1][1][2], + extrinsic_curvature_flux[1][2][0], + extrinsic_curvature_flux[1][2][1], + extrinsic_curvature_flux[1][2][2], + spatial_metric_der_flux[1][0][0][0], + spatial_metric_der_flux[1][0][0][1], + spatial_metric_der_flux[1][0][0][2], + spatial_metric_der_flux[1][0][1][0], + spatial_metric_der_flux[1][0][1][1], + spatial_metric_der_flux[1][0][1][2], + spatial_metric_der_flux[1][0][2][0], + spatial_metric_der_flux[1][0][2][1], + spatial_metric_der_flux[1][0][2][2], + spatial_metric_der_flux[1][1][0][0], + spatial_metric_der_flux[1][1][0][1], + spatial_metric_der_flux[1][1][0][2], + spatial_metric_der_flux[1][1][1][0], + spatial_metric_der_flux[1][1][1][1], + spatial_metric_der_flux[1][1][1][2], + spatial_metric_der_flux[1][1][2][0], + spatial_metric_der_flux[1][1][2][1], + spatial_metric_der_flux[1][1][2][2], + spatial_metric_der_flux[1][2][0][0], + spatial_metric_der_flux[1][2][0][1], + spatial_metric_der_flux[1][2][0][2], + spatial_metric_der_flux[1][2][1][0], + spatial_metric_der_flux[1][2][1][1], + spatial_metric_der_flux[1][2][1][2], + spatial_metric_der_flux[1][2][2][0], + spatial_metric_der_flux[1][2][2][1], + spatial_metric_der_flux[1][2][2][2], + lapse_der_flux[1][0], + lapse_der_flux[1][1], + lapse_der_flux[1][2], + aux_vect_flux[1][0], + aux_vect_flux[1][1], + aux_vect_flux[1][2]}, + {extrinsic_curvature_flux[2][0][0], + extrinsic_curvature_flux[2][0][1], + extrinsic_curvature_flux[2][0][2], + extrinsic_curvature_flux[2][1][0], + extrinsic_curvature_flux[2][1][1], + extrinsic_curvature_flux[2][1][2], + extrinsic_curvature_flux[2][2][0], + extrinsic_curvature_flux[2][2][1], + extrinsic_curvature_flux[2][2][2], + spatial_metric_der_flux[2][0][0][0], + spatial_metric_der_flux[2][0][0][1], + spatial_metric_der_flux[2][0][0][2], + spatial_metric_der_flux[2][0][1][0], + spatial_metric_der_flux[2][0][1][1], + spatial_metric_der_flux[2][0][1][2], + spatial_metric_der_flux[2][0][2][0], + spatial_metric_der_flux[2][0][2][1], + spatial_metric_der_flux[2][0][2][2], + spatial_metric_der_flux[2][1][0][0], + spatial_metric_der_flux[2][1][0][1], + spatial_metric_der_flux[2][1][0][2], + spatial_metric_der_flux[2][1][1][0], + spatial_metric_der_flux[2][1][1][1], + spatial_metric_der_flux[2][1][1][2], + spatial_metric_der_flux[2][1][2][0], + spatial_metric_der_flux[2][1][2][1], + spatial_metric_der_flux[2][1][2][2], + spatial_metric_der_flux[2][2][0][0], + spatial_metric_der_flux[2][2][0][1], + spatial_metric_der_flux[2][2][0][2], + spatial_metric_der_flux[2][2][1][0], + spatial_metric_der_flux[2][2][1][1], + spatial_metric_der_flux[2][2][1][2], + spatial_metric_der_flux[2][2][2][0], + spatial_metric_der_flux[2][2][2][1], + spatial_metric_der_flux[2][2][2][2], + lapse_der_flux[2][0], + lapse_der_flux[2][1], + lapse_der_flux[2][2], + aux_vect_flux[2][0], + aux_vect_flux[2][1], + aux_vect_flux[2][2]} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[64], flux_local[64], flux[64]; for (int d = 0; d < 3; d++) { - vacuum_einstein->rotate_to_local_func(vacuum_einstein, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_vacuum_einstein_flux(excision_threshold, spacetime_slicing, spacetime_evolution, q_local, flux_local); - vacuum_einstein->rotate_to_global_func(vacuum_einstein, tau1[d], tau2[d], norm[d], flux_local, flux); + vacuum_einstein->rotate_to_local_func( + vacuum_einstein, tau1[d], tau2[d], norm[d], q, q_local + ); + gkyl_vacuum_einstein_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, q_local, flux_local + ); + vacuum_einstein->rotate_to_global_func( + vacuum_einstein, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 42; i++) { - TEST_CHECK( gkyl_compare(flux[i + 10], fluxes[d][i], 1e-8) ); + TEST_CHECK(gkyl_compare(flux[i + 10], fluxes[d][i], 1e-8)); } } - + double q_l[64], q_g[64]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(vacuum_einstein, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(vacuum_einstein, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 64; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-16)); } double w1[64], q1[64]; @@ -355,7 +493,7 @@ test_vacuum_einstein_basic_minkowski_ho() vacuum_einstein->riem_to_cons(vacuum_einstein, q_local, w1, q1); for (int i = 0; i < 64; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-16)); } } @@ -364,7 +502,7 @@ test_vacuum_einstein_basic_minkowski_ho() gkyl_free(inv_spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -384,17 +522,17 @@ test_vacuum_einstein_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_vacuum_einstein_basic_schwarzschild_ho() +void test_vacuum_einstein_basic_schwarzschild_ho() { double excision_threshold = 0.3; enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); + struct gkyl_wv_eqn *vacuum_einstein = + gkyl_wv_vacuum_einstein_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); - TEST_CHECK( vacuum_einstein->num_equations == 64 ); - TEST_CHECK( vacuum_einstein->num_waves == 2 ); + TEST_CHECK(vacuum_einstein->num_equations == 64); + TEST_CHECK(vacuum_einstein->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -405,27 +543,27 @@ test_vacuum_einstein_basic_schwarzschild_ho() double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -436,14 +574,24 @@ test_vacuum_einstein_basic_schwarzschild_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -471,14 +619,15 @@ test_vacuum_einstein_basic_schwarzschild_ho() for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1[k][i][j] += inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; + spatial_metric_der_raised1[k][i][j] += + inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; } } } } - + double spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -486,7 +635,8 @@ test_vacuum_einstein_basic_schwarzschild_ho() spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3[i][j][k] += inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; + spatial_metric_der_raised3[i][j][k] += + inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; } } } @@ -505,7 +655,7 @@ test_vacuum_einstein_basic_schwarzschild_ho() double aux_vect_raised[3]; for (int k = 0; k < 3; k++) { aux_vect_raised[k] = 0.0; - + for (int l = 0; l < 3; l++) { aux_vect_raised[k] += inv_spatial_metric[k][l] * aux_vect[l]; } @@ -529,7 +679,8 @@ test_vacuum_einstein_basic_schwarzschild_ho() for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - shift_der_switched[i][k] += inv_spatial_metric[i][l] * spatial_metric[m][k] * shift_der[l][m]; + shift_der_switched[i][k] += + inv_spatial_metric[i][l] * spatial_metric[m][k] * shift_der[l][m]; } } } @@ -538,43 +689,86 @@ test_vacuum_einstein_basic_schwarzschild_ho() double symmetrized_shift[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - symmetrized_shift[i][j] = (1.0 / lapse) * (shift_der_lowered[i][j] + shift_der_lowered[j][i]); + symmetrized_shift[i][j] = + (1.0 / lapse) * (shift_der_lowered[i][j] + shift_der_lowered[j][i]); } } if (!in_excision_region) { double q[64]; - q[0] = spatial_metric[0][0]; q[1] = spatial_metric[0][1]; q[2] = spatial_metric[0][2]; - q[3] = spatial_metric[1][0]; q[4] = spatial_metric[1][1]; q[5] = spatial_metric[1][2]; - q[6] = spatial_metric[2][0]; q[7] = spatial_metric[2][1]; q[8] = spatial_metric[2][2]; + q[0] = spatial_metric[0][0]; + q[1] = spatial_metric[0][1]; + q[2] = spatial_metric[0][2]; + q[3] = spatial_metric[1][0]; + q[4] = spatial_metric[1][1]; + q[5] = spatial_metric[1][2]; + q[6] = spatial_metric[2][0]; + q[7] = spatial_metric[2][1]; + q[8] = spatial_metric[2][2]; q[9] = lapse; - q[10] = extrinsic_curvature[0][0]; q[11] = extrinsic_curvature[0][1]; q[12] = extrinsic_curvature[0][2]; - q[13] = extrinsic_curvature[1][0]; q[14] = extrinsic_curvature[1][1]; q[15] = extrinsic_curvature[1][2]; - q[16] = extrinsic_curvature[2][0]; q[17] = extrinsic_curvature[2][1]; q[18] = extrinsic_curvature[2][2]; - - q[19] = spatial_metric_der[0][0][0]; q[20] = spatial_metric_der[0][0][1]; q[21] = spatial_metric_der[0][0][2]; - q[22] = spatial_metric_der[0][1][0]; q[23] = spatial_metric_der[0][1][1]; q[24] = spatial_metric_der[0][1][2]; - q[25] = spatial_metric_der[0][2][0]; q[26] = spatial_metric_der[0][2][1]; q[27] = spatial_metric_der[0][2][2]; - - q[28] = spatial_metric_der[1][0][0]; q[29] = spatial_metric_der[1][0][1]; q[30] = spatial_metric_der[1][0][2]; - q[31] = spatial_metric_der[1][1][0]; q[32] = spatial_metric_der[1][1][1]; q[33] = spatial_metric_der[1][1][2]; - q[34] = spatial_metric_der[1][2][0]; q[35] = spatial_metric_der[1][2][1]; q[36] = spatial_metric_der[1][2][2]; - - q[37] = spatial_metric_der[2][0][0]; q[38] = spatial_metric_der[2][0][1]; q[39] = spatial_metric_der[2][0][2]; - q[40] = spatial_metric_der[2][1][0]; q[41] = spatial_metric_der[2][1][1]; q[42] = spatial_metric_der[2][1][2]; - q[43] = spatial_metric_der[2][2][0]; q[44] = spatial_metric_der[2][2][1]; q[45] = spatial_metric_der[2][2][2]; - - q[46] = lapse_der[0]; q[47] = lapse_der[1]; q[48] = lapse_der[2]; - - q[49] = aux_vect[0]; q[50] = aux_vect[1]; q[51] = aux_vect[2]; - - q[52] = shift[0]; q[53] = shift[1]; q[54] = shift[2]; - - q[55] = shift_der[0][0]; q[56] = shift_der[0][1]; q[57] = shift_der[0][2]; - q[58] = shift_der[1][0]; q[59] = shift_der[1][1]; q[60] = shift_der[1][2]; - q[61] = shift_der[2][0]; q[62] = shift_der[2][1]; q[63] = shift_der[2][2]; + q[10] = extrinsic_curvature[0][0]; + q[11] = extrinsic_curvature[0][1]; + q[12] = extrinsic_curvature[0][2]; + q[13] = extrinsic_curvature[1][0]; + q[14] = extrinsic_curvature[1][1]; + q[15] = extrinsic_curvature[1][2]; + q[16] = extrinsic_curvature[2][0]; + q[17] = extrinsic_curvature[2][1]; + q[18] = extrinsic_curvature[2][2]; + + q[19] = spatial_metric_der[0][0][0]; + q[20] = spatial_metric_der[0][0][1]; + q[21] = spatial_metric_der[0][0][2]; + q[22] = spatial_metric_der[0][1][0]; + q[23] = spatial_metric_der[0][1][1]; + q[24] = spatial_metric_der[0][1][2]; + q[25] = spatial_metric_der[0][2][0]; + q[26] = spatial_metric_der[0][2][1]; + q[27] = spatial_metric_der[0][2][2]; + + q[28] = spatial_metric_der[1][0][0]; + q[29] = spatial_metric_der[1][0][1]; + q[30] = spatial_metric_der[1][0][2]; + q[31] = spatial_metric_der[1][1][0]; + q[32] = spatial_metric_der[1][1][1]; + q[33] = spatial_metric_der[1][1][2]; + q[34] = spatial_metric_der[1][2][0]; + q[35] = spatial_metric_der[1][2][1]; + q[36] = spatial_metric_der[1][2][2]; + + q[37] = spatial_metric_der[2][0][0]; + q[38] = spatial_metric_der[2][0][1]; + q[39] = spatial_metric_der[2][0][2]; + q[40] = spatial_metric_der[2][1][0]; + q[41] = spatial_metric_der[2][1][1]; + q[42] = spatial_metric_der[2][1][2]; + q[43] = spatial_metric_der[2][2][0]; + q[44] = spatial_metric_der[2][2][1]; + q[45] = spatial_metric_der[2][2][2]; + + q[46] = lapse_der[0]; + q[47] = lapse_der[1]; + q[48] = lapse_der[2]; + + q[49] = aux_vect[0]; + q[50] = aux_vect[1]; + q[51] = aux_vect[2]; + + q[52] = shift[0]; + q[53] = shift[1]; + q[54] = shift[2]; + + q[55] = shift_der[0][0]; + q[56] = shift_der[0][1]; + q[57] = shift_der[0][2]; + q[58] = shift_der[1][0]; + q[59] = shift_der[1][1]; + q[60] = shift_der[1][2]; + q[61] = shift_der[2][0]; + q[62] = shift_der[2][1]; + q[63] = shift_der[2][2]; double evolution_func = 1.0; double slicing_func = 2.0 * extrinsic_curvature_trace / lapse; @@ -585,13 +779,15 @@ test_vacuum_einstein_basic_schwarzschild_ho() for (int j = 0; j < 3; j++) { extrinsic_curvature_flux[d][i][j] = -shift[d] * extrinsic_curvature[i][j]; extrinsic_curvature_flux[d][i][j] += lapse * spatial_metric_der_raised1[d][i][j]; - extrinsic_curvature_flux[d][i][j] -= lapse * (0.5 * evolution_func) * aux_vect_raised[d] * spatial_metric[i][j]; + extrinsic_curvature_flux[d][i][j] -= + lapse * (0.5 * evolution_func) * aux_vect_raised[d] * spatial_metric[i][j]; if (i == d) { extrinsic_curvature_flux[d][i][j] += 0.5 * lapse * lapse_der[j]; extrinsic_curvature_flux[d][i][j] += lapse * aux_vect[j]; for (int r = 0; r < 3; r++) { - extrinsic_curvature_flux[d][i][j] -= 0.5 * lapse * spatial_metric_der_raised3[j][r][r]; + extrinsic_curvature_flux[d][i][j] -= + 0.5 * lapse * spatial_metric_der_raised3[j][r][r]; } } @@ -599,7 +795,8 @@ test_vacuum_einstein_basic_schwarzschild_ho() extrinsic_curvature_flux[d][i][j] += 0.5 * lapse * lapse_der[i]; extrinsic_curvature_flux[d][i][j] += lapse * aux_vect[i]; for (int r = 0; r < 3; r++) { - extrinsic_curvature_flux[d][i][j] -= 0.5 * lapse * spatial_metric_der_raised3[i][r][r]; + extrinsic_curvature_flux[d][i][j] -= + 0.5 * lapse * spatial_metric_der_raised3[i][r][r]; } } } @@ -618,7 +815,8 @@ test_vacuum_einstein_basic_schwarzschild_ho() spatial_metric_der_flux[d][d][i][j] -= shift[r] * spatial_metric_der[r][i][j]; } - spatial_metric_der_flux[d][d][i][j] += lapse * (extrinsic_curvature[i][j] - symmetrized_shift[i][j]); + spatial_metric_der_flux[d][d][i][j] += + lapse * (extrinsic_curvature[i][j] - symmetrized_shift[i][j]); } } } @@ -629,7 +827,7 @@ test_vacuum_einstein_basic_schwarzschild_ho() lapse_der_flux[d][i] = 0.0; } } - + for (int d = 0; d < 3; d++) { for (int r = 0; r < 3; r++) { lapse_der_flux[d][d] -= shift[r] * lapse_der[r]; @@ -647,86 +845,164 @@ test_vacuum_einstein_basic_schwarzschild_ho() } double fluxes[3][42] = { - { extrinsic_curvature_flux[0][0][0], extrinsic_curvature_flux[0][0][1], extrinsic_curvature_flux[0][0][2], - extrinsic_curvature_flux[0][1][0], extrinsic_curvature_flux[0][1][1], extrinsic_curvature_flux[0][1][2], - extrinsic_curvature_flux[0][2][0], extrinsic_curvature_flux[0][2][1], extrinsic_curvature_flux[0][2][2], - spatial_metric_der_flux[0][0][0][0], spatial_metric_der_flux[0][0][0][1], spatial_metric_der_flux[0][0][0][2], - spatial_metric_der_flux[0][0][1][0], spatial_metric_der_flux[0][0][1][1], spatial_metric_der_flux[0][0][1][2], - spatial_metric_der_flux[0][0][2][0], spatial_metric_der_flux[0][0][2][1], spatial_metric_der_flux[0][0][2][2], - spatial_metric_der_flux[0][1][0][0], spatial_metric_der_flux[0][1][0][1], spatial_metric_der_flux[0][1][0][2], - spatial_metric_der_flux[0][1][1][0], spatial_metric_der_flux[0][1][1][1], spatial_metric_der_flux[0][1][1][2], - spatial_metric_der_flux[0][1][2][0], spatial_metric_der_flux[0][1][2][1], spatial_metric_der_flux[0][1][2][2], - spatial_metric_der_flux[0][2][0][0], spatial_metric_der_flux[0][2][0][1], spatial_metric_der_flux[0][2][0][2], - spatial_metric_der_flux[0][2][1][0], spatial_metric_der_flux[0][2][1][1], spatial_metric_der_flux[0][2][1][2], - spatial_metric_der_flux[0][2][2][0], spatial_metric_der_flux[0][2][2][1], spatial_metric_der_flux[0][2][2][2], - lapse_der_flux[0][0], lapse_der_flux[0][1], lapse_der_flux[0][2], - aux_vect_flux[0][0], aux_vect_flux[0][1], aux_vect_flux[0][2] }, - { extrinsic_curvature_flux[1][0][0], extrinsic_curvature_flux[1][0][1], extrinsic_curvature_flux[1][0][2], - extrinsic_curvature_flux[1][1][0], extrinsic_curvature_flux[1][1][1], extrinsic_curvature_flux[1][1][2], - extrinsic_curvature_flux[1][2][0], extrinsic_curvature_flux[1][2][1], extrinsic_curvature_flux[1][2][2], - spatial_metric_der_flux[1][0][0][0], spatial_metric_der_flux[1][0][0][1], spatial_metric_der_flux[1][0][0][2], - spatial_metric_der_flux[1][0][1][0], spatial_metric_der_flux[1][0][1][1], spatial_metric_der_flux[1][0][1][2], - spatial_metric_der_flux[1][0][2][0], spatial_metric_der_flux[1][0][2][1], spatial_metric_der_flux[1][0][2][2], - spatial_metric_der_flux[1][1][0][0], spatial_metric_der_flux[1][1][0][1], spatial_metric_der_flux[1][1][0][2], - spatial_metric_der_flux[1][1][1][0], spatial_metric_der_flux[1][1][1][1], spatial_metric_der_flux[1][1][1][2], - spatial_metric_der_flux[1][1][2][0], spatial_metric_der_flux[1][1][2][1], spatial_metric_der_flux[1][1][2][2], - spatial_metric_der_flux[1][2][0][0], spatial_metric_der_flux[1][2][0][1], spatial_metric_der_flux[1][2][0][2], - spatial_metric_der_flux[1][2][1][0], spatial_metric_der_flux[1][2][1][1], spatial_metric_der_flux[1][2][1][2], - spatial_metric_der_flux[1][2][2][0], spatial_metric_der_flux[1][2][2][1], spatial_metric_der_flux[1][2][2][2], - lapse_der_flux[1][0], lapse_der_flux[1][1], lapse_der_flux[1][2], - aux_vect_flux[1][0], aux_vect_flux[1][1], aux_vect_flux[1][2] }, - { extrinsic_curvature_flux[2][0][0], extrinsic_curvature_flux[2][0][1], extrinsic_curvature_flux[2][0][2], - extrinsic_curvature_flux[2][1][0], extrinsic_curvature_flux[2][1][1], extrinsic_curvature_flux[2][1][2], - extrinsic_curvature_flux[2][2][0], extrinsic_curvature_flux[2][2][1], extrinsic_curvature_flux[2][2][2], - spatial_metric_der_flux[2][0][0][0], spatial_metric_der_flux[2][0][0][1], spatial_metric_der_flux[2][0][0][2], - spatial_metric_der_flux[2][0][1][0], spatial_metric_der_flux[2][0][1][1], spatial_metric_der_flux[2][0][1][2], - spatial_metric_der_flux[2][0][2][0], spatial_metric_der_flux[2][0][2][1], spatial_metric_der_flux[2][0][2][2], - spatial_metric_der_flux[2][1][0][0], spatial_metric_der_flux[2][1][0][1], spatial_metric_der_flux[2][1][0][2], - spatial_metric_der_flux[2][1][1][0], spatial_metric_der_flux[2][1][1][1], spatial_metric_der_flux[2][1][1][2], - spatial_metric_der_flux[2][1][2][0], spatial_metric_der_flux[2][1][2][1], spatial_metric_der_flux[2][1][2][2], - spatial_metric_der_flux[2][2][0][0], spatial_metric_der_flux[2][2][0][1], spatial_metric_der_flux[2][2][0][2], - spatial_metric_der_flux[2][2][1][0], spatial_metric_der_flux[2][2][1][1], spatial_metric_der_flux[2][2][1][2], - spatial_metric_der_flux[2][2][2][0], spatial_metric_der_flux[2][2][2][1], spatial_metric_der_flux[2][2][2][2], - lapse_der_flux[2][0], lapse_der_flux[2][1], lapse_der_flux[2][2], - aux_vect_flux[2][0], aux_vect_flux[2][1], aux_vect_flux[2][2] }, + {extrinsic_curvature_flux[0][0][0], + extrinsic_curvature_flux[0][0][1], + extrinsic_curvature_flux[0][0][2], + extrinsic_curvature_flux[0][1][0], + extrinsic_curvature_flux[0][1][1], + extrinsic_curvature_flux[0][1][2], + extrinsic_curvature_flux[0][2][0], + extrinsic_curvature_flux[0][2][1], + extrinsic_curvature_flux[0][2][2], + spatial_metric_der_flux[0][0][0][0], + spatial_metric_der_flux[0][0][0][1], + spatial_metric_der_flux[0][0][0][2], + spatial_metric_der_flux[0][0][1][0], + spatial_metric_der_flux[0][0][1][1], + spatial_metric_der_flux[0][0][1][2], + spatial_metric_der_flux[0][0][2][0], + spatial_metric_der_flux[0][0][2][1], + spatial_metric_der_flux[0][0][2][2], + spatial_metric_der_flux[0][1][0][0], + spatial_metric_der_flux[0][1][0][1], + spatial_metric_der_flux[0][1][0][2], + spatial_metric_der_flux[0][1][1][0], + spatial_metric_der_flux[0][1][1][1], + spatial_metric_der_flux[0][1][1][2], + spatial_metric_der_flux[0][1][2][0], + spatial_metric_der_flux[0][1][2][1], + spatial_metric_der_flux[0][1][2][2], + spatial_metric_der_flux[0][2][0][0], + spatial_metric_der_flux[0][2][0][1], + spatial_metric_der_flux[0][2][0][2], + spatial_metric_der_flux[0][2][1][0], + spatial_metric_der_flux[0][2][1][1], + spatial_metric_der_flux[0][2][1][2], + spatial_metric_der_flux[0][2][2][0], + spatial_metric_der_flux[0][2][2][1], + spatial_metric_der_flux[0][2][2][2], + lapse_der_flux[0][0], + lapse_der_flux[0][1], + lapse_der_flux[0][2], + aux_vect_flux[0][0], + aux_vect_flux[0][1], + aux_vect_flux[0][2]}, + {extrinsic_curvature_flux[1][0][0], + extrinsic_curvature_flux[1][0][1], + extrinsic_curvature_flux[1][0][2], + extrinsic_curvature_flux[1][1][0], + extrinsic_curvature_flux[1][1][1], + extrinsic_curvature_flux[1][1][2], + extrinsic_curvature_flux[1][2][0], + extrinsic_curvature_flux[1][2][1], + extrinsic_curvature_flux[1][2][2], + spatial_metric_der_flux[1][0][0][0], + spatial_metric_der_flux[1][0][0][1], + spatial_metric_der_flux[1][0][0][2], + spatial_metric_der_flux[1][0][1][0], + spatial_metric_der_flux[1][0][1][1], + spatial_metric_der_flux[1][0][1][2], + spatial_metric_der_flux[1][0][2][0], + spatial_metric_der_flux[1][0][2][1], + spatial_metric_der_flux[1][0][2][2], + spatial_metric_der_flux[1][1][0][0], + spatial_metric_der_flux[1][1][0][1], + spatial_metric_der_flux[1][1][0][2], + spatial_metric_der_flux[1][1][1][0], + spatial_metric_der_flux[1][1][1][1], + spatial_metric_der_flux[1][1][1][2], + spatial_metric_der_flux[1][1][2][0], + spatial_metric_der_flux[1][1][2][1], + spatial_metric_der_flux[1][1][2][2], + spatial_metric_der_flux[1][2][0][0], + spatial_metric_der_flux[1][2][0][1], + spatial_metric_der_flux[1][2][0][2], + spatial_metric_der_flux[1][2][1][0], + spatial_metric_der_flux[1][2][1][1], + spatial_metric_der_flux[1][2][1][2], + spatial_metric_der_flux[1][2][2][0], + spatial_metric_der_flux[1][2][2][1], + spatial_metric_der_flux[1][2][2][2], + lapse_der_flux[1][0], + lapse_der_flux[1][1], + lapse_der_flux[1][2], + aux_vect_flux[1][0], + aux_vect_flux[1][1], + aux_vect_flux[1][2]}, + {extrinsic_curvature_flux[2][0][0], + extrinsic_curvature_flux[2][0][1], + extrinsic_curvature_flux[2][0][2], + extrinsic_curvature_flux[2][1][0], + extrinsic_curvature_flux[2][1][1], + extrinsic_curvature_flux[2][1][2], + extrinsic_curvature_flux[2][2][0], + extrinsic_curvature_flux[2][2][1], + extrinsic_curvature_flux[2][2][2], + spatial_metric_der_flux[2][0][0][0], + spatial_metric_der_flux[2][0][0][1], + spatial_metric_der_flux[2][0][0][2], + spatial_metric_der_flux[2][0][1][0], + spatial_metric_der_flux[2][0][1][1], + spatial_metric_der_flux[2][0][1][2], + spatial_metric_der_flux[2][0][2][0], + spatial_metric_der_flux[2][0][2][1], + spatial_metric_der_flux[2][0][2][2], + spatial_metric_der_flux[2][1][0][0], + spatial_metric_der_flux[2][1][0][1], + spatial_metric_der_flux[2][1][0][2], + spatial_metric_der_flux[2][1][1][0], + spatial_metric_der_flux[2][1][1][1], + spatial_metric_der_flux[2][1][1][2], + spatial_metric_der_flux[2][1][2][0], + spatial_metric_der_flux[2][1][2][1], + spatial_metric_der_flux[2][1][2][2], + spatial_metric_der_flux[2][2][0][0], + spatial_metric_der_flux[2][2][0][1], + spatial_metric_der_flux[2][2][0][2], + spatial_metric_der_flux[2][2][1][0], + spatial_metric_der_flux[2][2][1][1], + spatial_metric_der_flux[2][2][1][2], + spatial_metric_der_flux[2][2][2][0], + spatial_metric_der_flux[2][2][2][1], + spatial_metric_der_flux[2][2][2][2], + lapse_der_flux[2][0], + lapse_der_flux[2][1], + lapse_der_flux[2][2], + aux_vect_flux[2][0], + aux_vect_flux[2][1], + aux_vect_flux[2][2]} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[64], flux_local[64], flux[64]; for (int d = 0; d < 3; d++) { - vacuum_einstein->rotate_to_local_func(vacuum_einstein, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_vacuum_einstein_flux(excision_threshold, spacetime_slicing, spacetime_evolution, q_local, flux_local); - vacuum_einstein->rotate_to_global_func(vacuum_einstein, tau1[d], tau2[d], norm[d], flux_local, flux); + vacuum_einstein->rotate_to_local_func( + vacuum_einstein, tau1[d], tau2[d], norm[d], q, q_local + ); + gkyl_vacuum_einstein_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, q_local, flux_local + ); + vacuum_einstein->rotate_to_global_func( + vacuum_einstein, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 42; i++) { - TEST_CHECK( gkyl_compare(flux[i + 10], fluxes[d][i], 1e-6) ); + TEST_CHECK(gkyl_compare(flux[i + 10], fluxes[d][i], 1e-6)); } } - + double q_l[64], q_g[64]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(vacuum_einstein, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(vacuum_einstein, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 64; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-16)); } double w1[64], q1[64]; @@ -734,7 +1010,7 @@ test_vacuum_einstein_basic_schwarzschild_ho() vacuum_einstein->riem_to_cons(vacuum_einstein, q_local, w1, q1); for (int i = 0; i < 64; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-16)); } } } @@ -744,7 +1020,7 @@ test_vacuum_einstein_basic_schwarzschild_ho() gkyl_free(inv_spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -764,14 +1040,14 @@ test_vacuum_einstein_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_vacuum_einstein_waves_schwarzschild_ho() +void test_vacuum_einstein_waves_schwarzschild_ho() { double excision_threshold = 0.3; enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); + struct gkyl_wv_eqn *vacuum_einstein = + gkyl_wv_vacuum_einstein_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -784,10 +1060,10 @@ test_vacuum_einstein_waves_schwarzschild_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -795,8 +1071,8 @@ test_vacuum_einstein_waves_schwarzschild_ho() inv_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature_l[i] = gkyl_malloc(sizeof(double[3])); extrinsic_curvature_r[i] = gkyl_malloc(sizeof(double[3])); @@ -804,18 +1080,18 @@ test_vacuum_einstein_waves_schwarzschild_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -834,17 +1110,33 @@ test_vacuum_einstein_waves_schwarzschild_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &inv_spatial_metric_l); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &inv_spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &lapse_der_r); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, &inv_spatial_metric_l + ); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, &inv_spatial_metric_r + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &lapse_der_r + ); spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &shift_der_l); spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &spatial_metric_der_r); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &spatial_metric_der_r + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -879,15 +1171,17 @@ test_vacuum_einstein_waves_schwarzschild_ho() for (int k = 0; k < 3; k++) { spatial_metric_der_raised1_l[k][i][j] = 0.0; spatial_metric_der_raised1_r[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1_l[k][i][j] += inv_spatial_metric_l[k][l] * spatial_metric_der_l[l][i][j]; - spatial_metric_der_raised1_r[k][i][j] += inv_spatial_metric_r[k][l] * spatial_metric_der_r[l][i][j]; + spatial_metric_der_raised1_l[k][i][j] += + inv_spatial_metric_l[k][l] * spatial_metric_der_l[l][i][j]; + spatial_metric_der_raised1_r[k][i][j] += + inv_spatial_metric_r[k][l] * spatial_metric_der_r[l][i][j]; } } } } - + double spatial_metric_der_raised3_l[3][3][3]; double spatial_metric_der_raised3_r[3][3][3]; for (int i = 0; i < 3; i++) { @@ -897,8 +1191,10 @@ test_vacuum_einstein_waves_schwarzschild_ho() spatial_metric_der_raised3_r[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3_l[i][j][k] += inv_spatial_metric_l[l][k] * spatial_metric_der_l[i][j][l]; - spatial_metric_der_raised3_r[i][j][k] += inv_spatial_metric_r[l][k] * spatial_metric_der_r[i][j][l]; + spatial_metric_der_raised3_l[i][j][k] += + inv_spatial_metric_l[l][k] * spatial_metric_der_l[i][j][l]; + spatial_metric_der_raised3_r[i][j][k] += + inv_spatial_metric_r[l][k] * spatial_metric_der_r[i][j][l]; } } } @@ -954,8 +1250,10 @@ test_vacuum_einstein_waves_schwarzschild_ho() for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - shift_der_switched_l[i][k] += inv_spatial_metric_l[i][l] * spatial_metric_l[m][k] * shift_der_l[l][m]; - shift_der_switched_r[i][k] += inv_spatial_metric_r[i][l] * spatial_metric_r[m][k] * shift_der_r[l][m]; + shift_der_switched_l[i][k] += + inv_spatial_metric_l[i][l] * spatial_metric_l[m][k] * shift_der_l[l][m]; + shift_der_switched_r[i][k] += + inv_spatial_metric_r[i][l] * spatial_metric_r[m][k] * shift_der_r[l][m]; } } } @@ -965,94 +1263,168 @@ test_vacuum_einstein_waves_schwarzschild_ho() double symmetrized_shift_r[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - symmetrized_shift_l[i][j] = (1.0 / lapse_l) * (shift_der_lowered_l[i][j] + shift_der_lowered_l[j][i]); - symmetrized_shift_r[i][j] = (1.0 / lapse_r) * (shift_der_lowered_r[i][j] + shift_der_lowered_r[j][i]); + symmetrized_shift_l[i][j] = + (1.0 / lapse_l) * (shift_der_lowered_l[i][j] + shift_der_lowered_l[j][i]); + symmetrized_shift_r[i][j] = + (1.0 / lapse_r) * (shift_der_lowered_r[i][j] + shift_der_lowered_r[j][i]); } } if (!in_excision_region_l && !in_excision_region_r) { double ql[64], qr[64]; - ql[0] = spatial_metric_l[0][0]; ql[1] = spatial_metric_l[0][1]; ql[2] = spatial_metric_l[0][2]; - ql[3] = spatial_metric_l[1][0]; ql[4] = spatial_metric_l[1][1]; ql[5] = spatial_metric_l[1][2]; - ql[6] = spatial_metric_l[2][0]; ql[7] = spatial_metric_l[2][1]; ql[8] = spatial_metric_l[2][2]; + ql[0] = spatial_metric_l[0][0]; + ql[1] = spatial_metric_l[0][1]; + ql[2] = spatial_metric_l[0][2]; + ql[3] = spatial_metric_l[1][0]; + ql[4] = spatial_metric_l[1][1]; + ql[5] = spatial_metric_l[1][2]; + ql[6] = spatial_metric_l[2][0]; + ql[7] = spatial_metric_l[2][1]; + ql[8] = spatial_metric_l[2][2]; ql[9] = lapse_l; - ql[10] = extrinsic_curvature_l[0][0]; ql[11] = extrinsic_curvature_l[0][1]; ql[12] = extrinsic_curvature_l[0][2]; - ql[13] = extrinsic_curvature_l[1][0]; ql[14] = extrinsic_curvature_l[1][1]; ql[15] = extrinsic_curvature_l[1][2]; - ql[16] = extrinsic_curvature_l[2][0]; ql[17] = extrinsic_curvature_l[2][1]; ql[18] = extrinsic_curvature_l[2][2]; - - ql[19] = spatial_metric_der_l[0][0][0]; ql[20] = spatial_metric_der_l[0][0][1]; ql[21] = spatial_metric_der_l[0][0][2]; - ql[22] = spatial_metric_der_l[0][1][0]; ql[23] = spatial_metric_der_l[0][1][1]; ql[24] = spatial_metric_der_l[0][1][2]; - ql[25] = spatial_metric_der_l[0][2][0]; ql[26] = spatial_metric_der_l[0][2][1]; ql[27] = spatial_metric_der_l[0][2][2]; - - ql[28] = spatial_metric_der_l[1][0][0]; ql[29] = spatial_metric_der_l[1][0][1]; ql[30] = spatial_metric_der_l[1][0][2]; - ql[31] = spatial_metric_der_l[1][1][0]; ql[32] = spatial_metric_der_l[1][1][1]; ql[33] = spatial_metric_der_l[1][1][2]; - ql[34] = spatial_metric_der_l[1][2][0]; ql[35] = spatial_metric_der_l[1][2][1]; ql[36] = spatial_metric_der_l[1][2][2]; - - ql[37] = spatial_metric_der_l[2][0][0]; ql[38] = spatial_metric_der_l[2][0][1]; ql[39] = spatial_metric_der_l[2][0][2]; - ql[40] = spatial_metric_der_l[2][1][0]; ql[41] = spatial_metric_der_l[2][1][1]; ql[42] = spatial_metric_der_l[2][1][2]; - ql[43] = spatial_metric_der_l[2][2][0]; ql[44] = spatial_metric_der_l[2][2][1]; ql[45] = spatial_metric_der_l[2][2][2]; - - ql[46] = lapse_der_l[0]; ql[47] = lapse_der_l[1]; ql[48] = lapse_der_l[2]; - - ql[49] = aux_vect_l[0]; ql[50] = aux_vect_l[1]; ql[51] = aux_vect_l[2]; - - ql[52] = shift_l[0]; ql[53] = shift_l[1]; ql[54] = shift_l[2]; - - ql[55] = shift_der_l[0][0]; ql[56] = shift_der_l[0][1]; ql[57] = shift_der_l[0][2]; - ql[58] = shift_der_l[1][0]; ql[59] = shift_der_l[1][1]; ql[60] = shift_der_l[1][2]; - ql[61] = shift_der_l[2][0]; ql[62] = shift_der_l[2][1]; ql[63] = shift_der_l[2][2]; - - qr[0] = spatial_metric_r[0][0]; qr[1] = spatial_metric_r[0][1]; qr[2] = spatial_metric_r[0][2]; - qr[3] = spatial_metric_r[1][0]; qr[4] = spatial_metric_r[1][1]; qr[5] = spatial_metric_r[1][2]; - qr[6] = spatial_metric_r[2][0]; qr[7] = spatial_metric_r[2][1]; qr[8] = spatial_metric_r[2][2]; + ql[10] = extrinsic_curvature_l[0][0]; + ql[11] = extrinsic_curvature_l[0][1]; + ql[12] = extrinsic_curvature_l[0][2]; + ql[13] = extrinsic_curvature_l[1][0]; + ql[14] = extrinsic_curvature_l[1][1]; + ql[15] = extrinsic_curvature_l[1][2]; + ql[16] = extrinsic_curvature_l[2][0]; + ql[17] = extrinsic_curvature_l[2][1]; + ql[18] = extrinsic_curvature_l[2][2]; + + ql[19] = spatial_metric_der_l[0][0][0]; + ql[20] = spatial_metric_der_l[0][0][1]; + ql[21] = spatial_metric_der_l[0][0][2]; + ql[22] = spatial_metric_der_l[0][1][0]; + ql[23] = spatial_metric_der_l[0][1][1]; + ql[24] = spatial_metric_der_l[0][1][2]; + ql[25] = spatial_metric_der_l[0][2][0]; + ql[26] = spatial_metric_der_l[0][2][1]; + ql[27] = spatial_metric_der_l[0][2][2]; + + ql[28] = spatial_metric_der_l[1][0][0]; + ql[29] = spatial_metric_der_l[1][0][1]; + ql[30] = spatial_metric_der_l[1][0][2]; + ql[31] = spatial_metric_der_l[1][1][0]; + ql[32] = spatial_metric_der_l[1][1][1]; + ql[33] = spatial_metric_der_l[1][1][2]; + ql[34] = spatial_metric_der_l[1][2][0]; + ql[35] = spatial_metric_der_l[1][2][1]; + ql[36] = spatial_metric_der_l[1][2][2]; + + ql[37] = spatial_metric_der_l[2][0][0]; + ql[38] = spatial_metric_der_l[2][0][1]; + ql[39] = spatial_metric_der_l[2][0][2]; + ql[40] = spatial_metric_der_l[2][1][0]; + ql[41] = spatial_metric_der_l[2][1][1]; + ql[42] = spatial_metric_der_l[2][1][2]; + ql[43] = spatial_metric_der_l[2][2][0]; + ql[44] = spatial_metric_der_l[2][2][1]; + ql[45] = spatial_metric_der_l[2][2][2]; + + ql[46] = lapse_der_l[0]; + ql[47] = lapse_der_l[1]; + ql[48] = lapse_der_l[2]; + + ql[49] = aux_vect_l[0]; + ql[50] = aux_vect_l[1]; + ql[51] = aux_vect_l[2]; + + ql[52] = shift_l[0]; + ql[53] = shift_l[1]; + ql[54] = shift_l[2]; + + ql[55] = shift_der_l[0][0]; + ql[56] = shift_der_l[0][1]; + ql[57] = shift_der_l[0][2]; + ql[58] = shift_der_l[1][0]; + ql[59] = shift_der_l[1][1]; + ql[60] = shift_der_l[1][2]; + ql[61] = shift_der_l[2][0]; + ql[62] = shift_der_l[2][1]; + ql[63] = shift_der_l[2][2]; + + qr[0] = spatial_metric_r[0][0]; + qr[1] = spatial_metric_r[0][1]; + qr[2] = spatial_metric_r[0][2]; + qr[3] = spatial_metric_r[1][0]; + qr[4] = spatial_metric_r[1][1]; + qr[5] = spatial_metric_r[1][2]; + qr[6] = spatial_metric_r[2][0]; + qr[7] = spatial_metric_r[2][1]; + qr[8] = spatial_metric_r[2][2]; qr[9] = lapse_r; - qr[10] = extrinsic_curvature_r[0][0]; qr[11] = extrinsic_curvature_r[0][1]; qr[12] = extrinsic_curvature_r[0][2]; - qr[13] = extrinsic_curvature_r[1][0]; qr[14] = extrinsic_curvature_r[1][1]; qr[15] = extrinsic_curvature_r[1][2]; - qr[16] = extrinsic_curvature_r[2][0]; qr[17] = extrinsic_curvature_r[2][1]; qr[18] = extrinsic_curvature_r[2][2]; - - qr[19] = spatial_metric_der_r[0][0][0]; qr[20] = spatial_metric_der_r[0][0][1]; qr[21] = spatial_metric_der_r[0][0][2]; - qr[22] = spatial_metric_der_r[0][1][0]; qr[23] = spatial_metric_der_r[0][1][1]; qr[24] = spatial_metric_der_r[0][1][2]; - qr[25] = spatial_metric_der_r[0][2][0]; qr[26] = spatial_metric_der_r[0][2][1]; qr[27] = spatial_metric_der_r[0][2][2]; - - qr[28] = spatial_metric_der_r[1][0][0]; qr[29] = spatial_metric_der_r[1][0][1]; qr[30] = spatial_metric_der_r[1][0][2]; - qr[31] = spatial_metric_der_r[1][1][0]; qr[32] = spatial_metric_der_r[1][1][1]; qr[33] = spatial_metric_der_r[1][1][2]; - qr[34] = spatial_metric_der_r[1][2][0]; qr[35] = spatial_metric_der_r[1][2][1]; qr[36] = spatial_metric_der_r[1][2][2]; - - qr[37] = spatial_metric_der_r[2][0][0]; qr[38] = spatial_metric_der_r[2][0][1]; qr[39] = spatial_metric_der_r[2][0][2]; - qr[40] = spatial_metric_der_r[2][1][0]; qr[41] = spatial_metric_der_r[2][1][1]; qr[42] = spatial_metric_der_r[2][1][2]; - qr[43] = spatial_metric_der_r[2][2][0]; qr[44] = spatial_metric_der_r[2][2][1]; qr[45] = spatial_metric_der_r[2][2][2]; - - qr[46] = lapse_der_r[0]; qr[47] = lapse_der_r[1]; qr[48] = lapse_der_r[2]; - - qr[49] = aux_vect_r[0]; qr[50] = aux_vect_r[1]; qr[51] = aux_vect_r[2]; - - qr[52] = shift_r[0]; qr[53] = shift_r[1]; qr[54] = shift_r[2]; - - qr[55] = shift_der_r[0][0]; qr[56] = shift_der_r[0][1]; qr[57] = shift_der_r[0][2]; - qr[58] = shift_der_r[1][0]; qr[59] = shift_der_r[1][1]; qr[60] = shift_der_r[1][2]; - qr[61] = shift_der_r[2][0]; qr[62] = shift_der_r[2][1]; qr[63] = shift_der_r[2][2]; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; - - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + qr[10] = extrinsic_curvature_r[0][0]; + qr[11] = extrinsic_curvature_r[0][1]; + qr[12] = extrinsic_curvature_r[0][2]; + qr[13] = extrinsic_curvature_r[1][0]; + qr[14] = extrinsic_curvature_r[1][1]; + qr[15] = extrinsic_curvature_r[1][2]; + qr[16] = extrinsic_curvature_r[2][0]; + qr[17] = extrinsic_curvature_r[2][1]; + qr[18] = extrinsic_curvature_r[2][2]; + + qr[19] = spatial_metric_der_r[0][0][0]; + qr[20] = spatial_metric_der_r[0][0][1]; + qr[21] = spatial_metric_der_r[0][0][2]; + qr[22] = spatial_metric_der_r[0][1][0]; + qr[23] = spatial_metric_der_r[0][1][1]; + qr[24] = spatial_metric_der_r[0][1][2]; + qr[25] = spatial_metric_der_r[0][2][0]; + qr[26] = spatial_metric_der_r[0][2][1]; + qr[27] = spatial_metric_der_r[0][2][2]; + + qr[28] = spatial_metric_der_r[1][0][0]; + qr[29] = spatial_metric_der_r[1][0][1]; + qr[30] = spatial_metric_der_r[1][0][2]; + qr[31] = spatial_metric_der_r[1][1][0]; + qr[32] = spatial_metric_der_r[1][1][1]; + qr[33] = spatial_metric_der_r[1][1][2]; + qr[34] = spatial_metric_der_r[1][2][0]; + qr[35] = spatial_metric_der_r[1][2][1]; + qr[36] = spatial_metric_der_r[1][2][2]; + + qr[37] = spatial_metric_der_r[2][0][0]; + qr[38] = spatial_metric_der_r[2][0][1]; + qr[39] = spatial_metric_der_r[2][0][2]; + qr[40] = spatial_metric_der_r[2][1][0]; + qr[41] = spatial_metric_der_r[2][1][1]; + qr[42] = spatial_metric_der_r[2][1][2]; + qr[43] = spatial_metric_der_r[2][2][0]; + qr[44] = spatial_metric_der_r[2][2][1]; + qr[45] = spatial_metric_der_r[2][2][2]; + + qr[46] = lapse_der_r[0]; + qr[47] = lapse_der_r[1]; + qr[48] = lapse_der_r[2]; + + qr[49] = aux_vect_r[0]; + qr[50] = aux_vect_r[1]; + qr[51] = aux_vect_r[2]; + + qr[52] = shift_r[0]; + qr[53] = shift_r[1]; + qr[54] = shift_r[2]; + + qr[55] = shift_der_r[0][0]; + qr[56] = shift_der_r[0][1]; + qr[57] = shift_der_r[0][2]; + qr[58] = shift_der_r[1][0]; + qr[59] = shift_der_r[1][1]; + qr[60] = shift_der_r[1][2]; + qr[61] = shift_der_r[2][0]; + qr[62] = shift_der_r[2][1]; + qr[63] = shift_der_r[2][2]; + + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 64], waves_local[2 * 64]; @@ -1066,13 +1438,21 @@ test_vacuum_einstein_waves_schwarzschild_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(vacuum_einstein, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + vacuum_einstein, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[64], amdq_local[64]; - gkyl_wv_eqn_qfluct(vacuum_einstein, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + vacuum_einstein, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(vacuum_einstein, tau1[d], tau2[d], norm[d], &waves_local[i * 64], &waves[i * 64]); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein, tau1[d], tau2[d], norm[d], &waves_local[i * 64], &waves[i * 64] + ); } double apdq[64], amdq[64]; @@ -1080,19 +1460,23 @@ test_vacuum_einstein_waves_schwarzschild_ho() gkyl_wv_eqn_rotate_to_global(vacuum_einstein, tau1[d], tau2[d], norm[d], amdq_local, amdq); double fl_local[64], fr_local[64]; - gkyl_vacuum_einstein_flux(excision_threshold, spacetime_slicing, spacetime_evolution, ql_local, fl_local); - gkyl_vacuum_einstein_flux(excision_threshold, spacetime_slicing, spacetime_evolution, qr_local, fr_local); + gkyl_vacuum_einstein_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, ql_local, fl_local + ); + gkyl_vacuum_einstein_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, qr_local, fr_local + ); double fl[64], fr[64]; gkyl_wv_eqn_rotate_to_global(vacuum_einstein, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(vacuum_einstein, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 64; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-11) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-11)); } } } - + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric_l[i]); gkyl_free(spatial_metric_r[i]); @@ -1102,7 +1486,7 @@ test_vacuum_einstein_waves_schwarzschild_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1128,14 +1512,14 @@ test_vacuum_einstein_waves_schwarzschild_ho() } } -void -test_vacuum_einstein_waves_kerr_ho() +void test_vacuum_einstein_waves_kerr_ho() { double excision_threshold = 0.3; enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *vacuum_einstein = gkyl_wv_vacuum_einstein_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); + struct gkyl_wv_eqn *vacuum_einstein = + gkyl_wv_vacuum_einstein_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1148,10 +1532,10 @@ test_vacuum_einstein_waves_kerr_ho() double *shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **inv_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1159,8 +1543,8 @@ test_vacuum_einstein_waves_kerr_ho() inv_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature_l[i] = gkyl_malloc(sizeof(double[3])); extrinsic_curvature_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1168,18 +1552,18 @@ test_vacuum_einstein_waves_kerr_ho() double *lapse_der_l = gkyl_malloc(sizeof(double[3])); double *lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der_l[i] = gkyl_malloc(sizeof(double[3])); shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1198,17 +1582,33 @@ test_vacuum_einstein_waves_kerr_ho() spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &spatial_metric_l); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &spatial_metric_r); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &inv_spatial_metric_l); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &inv_spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &lapse_der_r); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, &inv_spatial_metric_l + ); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, &inv_spatial_metric_r + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &extrinsic_curvature_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &lapse_der_r + ); spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &shift_der_l); spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &spatial_metric_der_r); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &spatial_metric_der_r + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1243,15 +1643,17 @@ test_vacuum_einstein_waves_kerr_ho() for (int k = 0; k < 3; k++) { spatial_metric_der_raised1_l[k][i][j] = 0.0; spatial_metric_der_raised1_r[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1_l[k][i][j] += inv_spatial_metric_l[k][l] * spatial_metric_der_l[l][i][j]; - spatial_metric_der_raised1_r[k][i][j] += inv_spatial_metric_r[k][l] * spatial_metric_der_r[l][i][j]; + spatial_metric_der_raised1_l[k][i][j] += + inv_spatial_metric_l[k][l] * spatial_metric_der_l[l][i][j]; + spatial_metric_der_raised1_r[k][i][j] += + inv_spatial_metric_r[k][l] * spatial_metric_der_r[l][i][j]; } } } } - + double spatial_metric_der_raised3_l[3][3][3]; double spatial_metric_der_raised3_r[3][3][3]; for (int i = 0; i < 3; i++) { @@ -1261,8 +1663,10 @@ test_vacuum_einstein_waves_kerr_ho() spatial_metric_der_raised3_r[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3_l[i][j][k] += inv_spatial_metric_l[l][k] * spatial_metric_der_l[i][j][l]; - spatial_metric_der_raised3_r[i][j][k] += inv_spatial_metric_r[l][k] * spatial_metric_der_r[i][j][l]; + spatial_metric_der_raised3_l[i][j][k] += + inv_spatial_metric_l[l][k] * spatial_metric_der_l[i][j][l]; + spatial_metric_der_raised3_r[i][j][k] += + inv_spatial_metric_r[l][k] * spatial_metric_der_r[i][j][l]; } } } @@ -1318,8 +1722,10 @@ test_vacuum_einstein_waves_kerr_ho() for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - shift_der_switched_l[i][k] += inv_spatial_metric_l[i][l] * spatial_metric_l[m][k] * shift_der_l[l][m]; - shift_der_switched_r[i][k] += inv_spatial_metric_r[i][l] * spatial_metric_r[m][k] * shift_der_r[l][m]; + shift_der_switched_l[i][k] += + inv_spatial_metric_l[i][l] * spatial_metric_l[m][k] * shift_der_l[l][m]; + shift_der_switched_r[i][k] += + inv_spatial_metric_r[i][l] * spatial_metric_r[m][k] * shift_der_r[l][m]; } } } @@ -1329,94 +1735,168 @@ test_vacuum_einstein_waves_kerr_ho() double symmetrized_shift_r[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - symmetrized_shift_l[i][j] = (1.0 / lapse_l) * (shift_der_lowered_l[i][j] + shift_der_lowered_l[j][i]); - symmetrized_shift_r[i][j] = (1.0 / lapse_r) * (shift_der_lowered_r[i][j] + shift_der_lowered_r[j][i]); + symmetrized_shift_l[i][j] = + (1.0 / lapse_l) * (shift_der_lowered_l[i][j] + shift_der_lowered_l[j][i]); + symmetrized_shift_r[i][j] = + (1.0 / lapse_r) * (shift_der_lowered_r[i][j] + shift_der_lowered_r[j][i]); } } if (!in_excision_region_l && !in_excision_region_r) { double ql[64], qr[64]; - ql[0] = spatial_metric_l[0][0]; ql[1] = spatial_metric_l[0][1]; ql[2] = spatial_metric_l[0][2]; - ql[3] = spatial_metric_l[1][0]; ql[4] = spatial_metric_l[1][1]; ql[5] = spatial_metric_l[1][2]; - ql[6] = spatial_metric_l[2][0]; ql[7] = spatial_metric_l[2][1]; ql[8] = spatial_metric_l[2][2]; + ql[0] = spatial_metric_l[0][0]; + ql[1] = spatial_metric_l[0][1]; + ql[2] = spatial_metric_l[0][2]; + ql[3] = spatial_metric_l[1][0]; + ql[4] = spatial_metric_l[1][1]; + ql[5] = spatial_metric_l[1][2]; + ql[6] = spatial_metric_l[2][0]; + ql[7] = spatial_metric_l[2][1]; + ql[8] = spatial_metric_l[2][2]; ql[9] = lapse_l; - ql[10] = extrinsic_curvature_l[0][0]; ql[11] = extrinsic_curvature_l[0][1]; ql[12] = extrinsic_curvature_l[0][2]; - ql[13] = extrinsic_curvature_l[1][0]; ql[14] = extrinsic_curvature_l[1][1]; ql[15] = extrinsic_curvature_l[1][2]; - ql[16] = extrinsic_curvature_l[2][0]; ql[17] = extrinsic_curvature_l[2][1]; ql[18] = extrinsic_curvature_l[2][2]; - - ql[19] = spatial_metric_der_l[0][0][0]; ql[20] = spatial_metric_der_l[0][0][1]; ql[21] = spatial_metric_der_l[0][0][2]; - ql[22] = spatial_metric_der_l[0][1][0]; ql[23] = spatial_metric_der_l[0][1][1]; ql[24] = spatial_metric_der_l[0][1][2]; - ql[25] = spatial_metric_der_l[0][2][0]; ql[26] = spatial_metric_der_l[0][2][1]; ql[27] = spatial_metric_der_l[0][2][2]; - - ql[28] = spatial_metric_der_l[1][0][0]; ql[29] = spatial_metric_der_l[1][0][1]; ql[30] = spatial_metric_der_l[1][0][2]; - ql[31] = spatial_metric_der_l[1][1][0]; ql[32] = spatial_metric_der_l[1][1][1]; ql[33] = spatial_metric_der_l[1][1][2]; - ql[34] = spatial_metric_der_l[1][2][0]; ql[35] = spatial_metric_der_l[1][2][1]; ql[36] = spatial_metric_der_l[1][2][2]; - - ql[37] = spatial_metric_der_l[2][0][0]; ql[38] = spatial_metric_der_l[2][0][1]; ql[39] = spatial_metric_der_l[2][0][2]; - ql[40] = spatial_metric_der_l[2][1][0]; ql[41] = spatial_metric_der_l[2][1][1]; ql[42] = spatial_metric_der_l[2][1][2]; - ql[43] = spatial_metric_der_l[2][2][0]; ql[44] = spatial_metric_der_l[2][2][1]; ql[45] = spatial_metric_der_l[2][2][2]; - - ql[46] = lapse_der_l[0]; ql[47] = lapse_der_l[1]; ql[48] = lapse_der_l[2]; - - ql[49] = aux_vect_l[0]; ql[50] = aux_vect_l[1]; ql[51] = aux_vect_l[2]; - - ql[52] = shift_l[0]; ql[53] = shift_l[1]; ql[54] = shift_l[2]; - - ql[55] = shift_der_l[0][0]; ql[56] = shift_der_l[0][1]; ql[57] = shift_der_l[0][2]; - ql[58] = shift_der_l[1][0]; ql[59] = shift_der_l[1][1]; ql[60] = shift_der_l[1][2]; - ql[61] = shift_der_l[2][0]; ql[62] = shift_der_l[2][1]; ql[63] = shift_der_l[2][2]; - - qr[0] = spatial_metric_r[0][0]; qr[1] = spatial_metric_r[0][1]; qr[2] = spatial_metric_r[0][2]; - qr[3] = spatial_metric_r[1][0]; qr[4] = spatial_metric_r[1][1]; qr[5] = spatial_metric_r[1][2]; - qr[6] = spatial_metric_r[2][0]; qr[7] = spatial_metric_r[2][1]; qr[8] = spatial_metric_r[2][2]; + ql[10] = extrinsic_curvature_l[0][0]; + ql[11] = extrinsic_curvature_l[0][1]; + ql[12] = extrinsic_curvature_l[0][2]; + ql[13] = extrinsic_curvature_l[1][0]; + ql[14] = extrinsic_curvature_l[1][1]; + ql[15] = extrinsic_curvature_l[1][2]; + ql[16] = extrinsic_curvature_l[2][0]; + ql[17] = extrinsic_curvature_l[2][1]; + ql[18] = extrinsic_curvature_l[2][2]; + + ql[19] = spatial_metric_der_l[0][0][0]; + ql[20] = spatial_metric_der_l[0][0][1]; + ql[21] = spatial_metric_der_l[0][0][2]; + ql[22] = spatial_metric_der_l[0][1][0]; + ql[23] = spatial_metric_der_l[0][1][1]; + ql[24] = spatial_metric_der_l[0][1][2]; + ql[25] = spatial_metric_der_l[0][2][0]; + ql[26] = spatial_metric_der_l[0][2][1]; + ql[27] = spatial_metric_der_l[0][2][2]; + + ql[28] = spatial_metric_der_l[1][0][0]; + ql[29] = spatial_metric_der_l[1][0][1]; + ql[30] = spatial_metric_der_l[1][0][2]; + ql[31] = spatial_metric_der_l[1][1][0]; + ql[32] = spatial_metric_der_l[1][1][1]; + ql[33] = spatial_metric_der_l[1][1][2]; + ql[34] = spatial_metric_der_l[1][2][0]; + ql[35] = spatial_metric_der_l[1][2][1]; + ql[36] = spatial_metric_der_l[1][2][2]; + + ql[37] = spatial_metric_der_l[2][0][0]; + ql[38] = spatial_metric_der_l[2][0][1]; + ql[39] = spatial_metric_der_l[2][0][2]; + ql[40] = spatial_metric_der_l[2][1][0]; + ql[41] = spatial_metric_der_l[2][1][1]; + ql[42] = spatial_metric_der_l[2][1][2]; + ql[43] = spatial_metric_der_l[2][2][0]; + ql[44] = spatial_metric_der_l[2][2][1]; + ql[45] = spatial_metric_der_l[2][2][2]; + + ql[46] = lapse_der_l[0]; + ql[47] = lapse_der_l[1]; + ql[48] = lapse_der_l[2]; + + ql[49] = aux_vect_l[0]; + ql[50] = aux_vect_l[1]; + ql[51] = aux_vect_l[2]; + + ql[52] = shift_l[0]; + ql[53] = shift_l[1]; + ql[54] = shift_l[2]; + + ql[55] = shift_der_l[0][0]; + ql[56] = shift_der_l[0][1]; + ql[57] = shift_der_l[0][2]; + ql[58] = shift_der_l[1][0]; + ql[59] = shift_der_l[1][1]; + ql[60] = shift_der_l[1][2]; + ql[61] = shift_der_l[2][0]; + ql[62] = shift_der_l[2][1]; + ql[63] = shift_der_l[2][2]; + + qr[0] = spatial_metric_r[0][0]; + qr[1] = spatial_metric_r[0][1]; + qr[2] = spatial_metric_r[0][2]; + qr[3] = spatial_metric_r[1][0]; + qr[4] = spatial_metric_r[1][1]; + qr[5] = spatial_metric_r[1][2]; + qr[6] = spatial_metric_r[2][0]; + qr[7] = spatial_metric_r[2][1]; + qr[8] = spatial_metric_r[2][2]; qr[9] = lapse_r; - qr[10] = extrinsic_curvature_r[0][0]; qr[11] = extrinsic_curvature_r[0][1]; qr[12] = extrinsic_curvature_r[0][2]; - qr[13] = extrinsic_curvature_r[1][0]; qr[14] = extrinsic_curvature_r[1][1]; qr[15] = extrinsic_curvature_r[1][2]; - qr[16] = extrinsic_curvature_r[2][0]; qr[17] = extrinsic_curvature_r[2][1]; qr[18] = extrinsic_curvature_r[2][2]; - - qr[19] = spatial_metric_der_r[0][0][0]; qr[20] = spatial_metric_der_r[0][0][1]; qr[21] = spatial_metric_der_r[0][0][2]; - qr[22] = spatial_metric_der_r[0][1][0]; qr[23] = spatial_metric_der_r[0][1][1]; qr[24] = spatial_metric_der_r[0][1][2]; - qr[25] = spatial_metric_der_r[0][2][0]; qr[26] = spatial_metric_der_r[0][2][1]; qr[27] = spatial_metric_der_r[0][2][2]; - - qr[28] = spatial_metric_der_r[1][0][0]; qr[29] = spatial_metric_der_r[1][0][1]; qr[30] = spatial_metric_der_r[1][0][2]; - qr[31] = spatial_metric_der_r[1][1][0]; qr[32] = spatial_metric_der_r[1][1][1]; qr[33] = spatial_metric_der_r[1][1][2]; - qr[34] = spatial_metric_der_r[1][2][0]; qr[35] = spatial_metric_der_r[1][2][1]; qr[36] = spatial_metric_der_r[1][2][2]; - - qr[37] = spatial_metric_der_r[2][0][0]; qr[38] = spatial_metric_der_r[2][0][1]; qr[39] = spatial_metric_der_r[2][0][2]; - qr[40] = spatial_metric_der_r[2][1][0]; qr[41] = spatial_metric_der_r[2][1][1]; qr[42] = spatial_metric_der_r[2][1][2]; - qr[43] = spatial_metric_der_r[2][2][0]; qr[44] = spatial_metric_der_r[2][2][1]; qr[45] = spatial_metric_der_r[2][2][2]; - - qr[46] = lapse_der_r[0]; qr[47] = lapse_der_r[1]; qr[48] = lapse_der_r[2]; - - qr[49] = aux_vect_r[0]; qr[50] = aux_vect_r[1]; qr[51] = aux_vect_r[2]; - - qr[52] = shift_r[0]; qr[53] = shift_r[1]; qr[54] = shift_r[2]; - - qr[55] = shift_der_r[0][0]; qr[56] = shift_der_r[0][1]; qr[57] = shift_der_r[0][2]; - qr[58] = shift_der_r[1][0]; qr[59] = shift_der_r[1][1]; qr[60] = shift_der_r[1][2]; - qr[61] = shift_der_r[2][0]; qr[62] = shift_der_r[2][1]; qr[63] = shift_der_r[2][2]; - - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; - - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; - - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + qr[10] = extrinsic_curvature_r[0][0]; + qr[11] = extrinsic_curvature_r[0][1]; + qr[12] = extrinsic_curvature_r[0][2]; + qr[13] = extrinsic_curvature_r[1][0]; + qr[14] = extrinsic_curvature_r[1][1]; + qr[15] = extrinsic_curvature_r[1][2]; + qr[16] = extrinsic_curvature_r[2][0]; + qr[17] = extrinsic_curvature_r[2][1]; + qr[18] = extrinsic_curvature_r[2][2]; + + qr[19] = spatial_metric_der_r[0][0][0]; + qr[20] = spatial_metric_der_r[0][0][1]; + qr[21] = spatial_metric_der_r[0][0][2]; + qr[22] = spatial_metric_der_r[0][1][0]; + qr[23] = spatial_metric_der_r[0][1][1]; + qr[24] = spatial_metric_der_r[0][1][2]; + qr[25] = spatial_metric_der_r[0][2][0]; + qr[26] = spatial_metric_der_r[0][2][1]; + qr[27] = spatial_metric_der_r[0][2][2]; + + qr[28] = spatial_metric_der_r[1][0][0]; + qr[29] = spatial_metric_der_r[1][0][1]; + qr[30] = spatial_metric_der_r[1][0][2]; + qr[31] = spatial_metric_der_r[1][1][0]; + qr[32] = spatial_metric_der_r[1][1][1]; + qr[33] = spatial_metric_der_r[1][1][2]; + qr[34] = spatial_metric_der_r[1][2][0]; + qr[35] = spatial_metric_der_r[1][2][1]; + qr[36] = spatial_metric_der_r[1][2][2]; + + qr[37] = spatial_metric_der_r[2][0][0]; + qr[38] = spatial_metric_der_r[2][0][1]; + qr[39] = spatial_metric_der_r[2][0][2]; + qr[40] = spatial_metric_der_r[2][1][0]; + qr[41] = spatial_metric_der_r[2][1][1]; + qr[42] = spatial_metric_der_r[2][1][2]; + qr[43] = spatial_metric_der_r[2][2][0]; + qr[44] = spatial_metric_der_r[2][2][1]; + qr[45] = spatial_metric_der_r[2][2][2]; + + qr[46] = lapse_der_r[0]; + qr[47] = lapse_der_r[1]; + qr[48] = lapse_der_r[2]; + + qr[49] = aux_vect_r[0]; + qr[50] = aux_vect_r[1]; + qr[51] = aux_vect_r[2]; + + qr[52] = shift_r[0]; + qr[53] = shift_r[1]; + qr[54] = shift_r[2]; + + qr[55] = shift_der_r[0][0]; + qr[56] = shift_der_r[0][1]; + qr[57] = shift_der_r[0][2]; + qr[58] = shift_der_r[1][0]; + qr[59] = shift_der_r[1][1]; + qr[60] = shift_der_r[1][2]; + qr[61] = shift_der_r[2][0]; + qr[62] = shift_der_r[2][1]; + qr[63] = shift_der_r[2][2]; + + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; + + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; + + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 64], waves_local[2 * 64]; @@ -1430,13 +1910,21 @@ test_vacuum_einstein_waves_kerr_ho() delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(vacuum_einstein, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + vacuum_einstein, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[64], amdq_local[64]; - gkyl_wv_eqn_qfluct(vacuum_einstein, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + vacuum_einstein, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, + speeds, amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(vacuum_einstein, tau1[d], tau2[d], norm[d], &waves_local[i * 64], &waves[i * 64]); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein, tau1[d], tau2[d], norm[d], &waves_local[i * 64], &waves[i * 64] + ); } double apdq[64], amdq[64]; @@ -1444,19 +1932,23 @@ test_vacuum_einstein_waves_kerr_ho() gkyl_wv_eqn_rotate_to_global(vacuum_einstein, tau1[d], tau2[d], norm[d], amdq_local, amdq); double fl_local[64], fr_local[64]; - gkyl_vacuum_einstein_flux(excision_threshold, spacetime_slicing, spacetime_evolution, ql_local, fl_local); - gkyl_vacuum_einstein_flux(excision_threshold, spacetime_slicing, spacetime_evolution, qr_local, fr_local); + gkyl_vacuum_einstein_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, ql_local, fl_local + ); + gkyl_vacuum_einstein_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, qr_local, fr_local + ); double fl[64], fr[64]; gkyl_wv_eqn_rotate_to_global(vacuum_einstein, tau1[d], tau2[d], norm[d], fl_local, fl); gkyl_wv_eqn_rotate_to_global(vacuum_einstein, tau1[d], tau2[d], norm[d], fr_local, fr); for (int i = 0; i < 64; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-12)); } } } - + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric_l[i]); gkyl_free(spatial_metric_r[i]); @@ -1466,7 +1958,7 @@ test_vacuum_einstein_waves_kerr_ho() gkyl_free(extrinsic_curvature_r[i]); gkyl_free(shift_der_l[i]); gkyl_free(shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der_l[i][j]); gkyl_free(spatial_metric_der_r[i][j]); @@ -1493,9 +1985,9 @@ test_vacuum_einstein_waves_kerr_ho() } TEST_LIST = { - { "vacuum_einstein_basic_minkowski_ho", test_vacuum_einstein_basic_minkowski_ho }, - { "vacuum_einstein_basic_schwarzschild_ho", test_vacuum_einstein_basic_schwarzschild_ho }, - { "vacuum_einstein_waves_schwarzschild_ho", test_vacuum_einstein_waves_schwarzschild_ho }, - { "vacuum_einstein_waves_kerr_ho", test_vacuum_einstein_waves_kerr_ho }, - { NULL, NULL }, + {"vacuum_einstein_basic_minkowski_ho", test_vacuum_einstein_basic_minkowski_ho}, + {"vacuum_einstein_basic_schwarzschild_ho", test_vacuum_einstein_basic_schwarzschild_ho}, + {"vacuum_einstein_waves_schwarzschild_ho", test_vacuum_einstein_waves_schwarzschild_ho}, + {"vacuum_einstein_waves_kerr_ho", test_vacuum_einstein_waves_kerr_ho}, + {NULL, NULL} }; \ No newline at end of file diff --git a/moments/unit/ctest_wv_vacuum_einstein_conformal.c b/moments/unit/ctest_wv_vacuum_einstein_conformal.c index 016ff954d7..0243fdac12 100644 --- a/moments/unit/ctest_wv_vacuum_einstein_conformal.c +++ b/moments/unit/ctest_wv_vacuum_einstein_conformal.c @@ -6,17 +6,18 @@ #include #include -void -test_vacuum_einstein_conformal_basic_minkowski_ho() +void test_vacuum_einstein_conformal_basic_minkowski_ho() { double excision_threshold = 0.3; enum gkyl_spacetime_slicing spacetime_slicing = GKYL_HARMONIC_SLICING; enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); - struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); + struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new( + excision_threshold, spacetime_slicing, spacetime_evolution, false + ); - TEST_CHECK( vacuum_einstein_conformal->num_equations == 77 ); - TEST_CHECK( vacuum_einstein_conformal->num_waves == 2 ); + TEST_CHECK(vacuum_einstein_conformal->num_equations == 77); + TEST_CHECK(vacuum_einstein_conformal->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -27,27 +28,27 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() double *conformal_shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); inv_conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *conformal_lapse_der = gkyl_malloc(sizeof(double[3])); - double **conformal_shift_der = gkyl_malloc(sizeof(double*[3])); + double **conformal_shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { conformal_spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -57,7 +58,7 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() double conformal_fact, bssn_conformal_fact; double *conformal_fact_der = gkyl_malloc(sizeof(double[3])); double *bssn_conformal_fact_der = gkyl_malloc(sizeof(double[3])); - double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_fact_der2[i] = gkyl_malloc(sizeof(double[3])); } @@ -66,21 +67,44 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &conformal_lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &conformal_shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &conformal_spatial_metric); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_conformal_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_extrinsic_curvature); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x, y, 0.0, &inv_conformal_spatial_metric + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_extrinsic_curvature + ); spacetime->conformal_factor_func(spacetime, 0.0, x, y, 0.0, &conformal_fact); spacetime->bssn_conformal_factor_func(spacetime, 0.0, x, y, 0.0, &bssn_conformal_fact); - spacetime->conformal_factor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_fact_der); - spacetime->bssn_conformal_factor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &bssn_conformal_fact_der); - spacetime->bssn_conformal_factor_der2_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &bssn_conformal_fact_der2); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_spatial_metric_der); + spacetime->conformal_factor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_fact_der + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &bssn_conformal_fact_der + ); + spacetime->bssn_conformal_factor_der2_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &bssn_conformal_fact_der2 + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_spatial_metric_der + ); for (int i = 0; i < 3; i++) { conformal_fact_der[i] /= conformal_fact; @@ -98,8 +122,10 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_spatial_metric[i][j] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - inv_conformal_spatial_metric[i][j] *= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric[i][j] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + inv_conformal_spatial_metric[i][j] *= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); } } @@ -107,8 +133,10 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der[i][j][k] = 0.5 * conformal_spatial_metric_der[i][j][k]; - conformal_spatial_metric_der[i][j][k] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_spatial_metric_der[i][j][k] -= 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; + conformal_spatial_metric_der[i][j][k] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric_der[i][j][k] -= + 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; } conformal_shift_der[i][j] = 0.5 * conformal_shift_der[i][j]; @@ -122,7 +150,8 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() double conformal_extrinsic_curvature_trace = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_extrinsic_curvature_trace += inv_conformal_spatial_metric[i][j] * conformal_extrinsic_curvature[i][j]; + conformal_extrinsic_curvature_trace += + inv_conformal_spatial_metric[i][j] * conformal_extrinsic_curvature[i][j]; } } @@ -131,14 +160,15 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1[k][i][j] += inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; + conformal_spatial_metric_der_raised1[k][i][j] += + inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; } } } } - + double conformal_spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -146,7 +176,8 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() conformal_spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3[i][j][k] += inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; + conformal_spatial_metric_der_raised3[i][j][k] += + inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; } } } @@ -167,9 +198,10 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() double conformal_aux_vect_raised[3]; for (int k = 0; k < 3; k++) { conformal_aux_vect_raised[k] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_aux_vect_raised[k] += inv_conformal_spatial_metric[k][l] * conformal_aux_vect[l]; + conformal_aux_vect_raised[k] += + inv_conformal_spatial_metric[k][l] * conformal_aux_vect[l]; } } @@ -179,7 +211,8 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() conformal_shift_der_lowered[i][j] = 0.0; for (int k = 0; k < 3; k++) { - conformal_shift_der_lowered[i][j] += conformal_spatial_metric[k][j] * conformal_shift_der[i][k]; + conformal_shift_der_lowered[i][j] += + conformal_spatial_metric[k][j] * conformal_shift_der[i][k]; } } } @@ -191,7 +224,9 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_shift_der_switched[i][k] += inv_conformal_spatial_metric[i][l] * conformal_spatial_metric[m][k] * conformal_shift_der[l][m]; + conformal_shift_der_switched[i][k] += inv_conformal_spatial_metric[i][l] * + conformal_spatial_metric[m][k] * + conformal_shift_der[l][m]; } } } @@ -200,75 +235,138 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() double symmetrized_conformal_shift[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - symmetrized_conformal_shift[i][j] = (1.0 / conformal_lapse) * (conformal_shift_der_lowered[i][j] + conformal_shift_der_lowered[j][i]); + symmetrized_conformal_shift[i][j] = + (1.0 / conformal_lapse) * + (conformal_shift_der_lowered[i][j] + conformal_shift_der_lowered[j][i]); } } double q[77]; - q[0] = conformal_spatial_metric[0][0]; q[1] = conformal_spatial_metric[0][1]; q[2] = conformal_spatial_metric[0][2]; - q[3] = conformal_spatial_metric[1][0]; q[4] = conformal_spatial_metric[1][1]; q[5] = conformal_spatial_metric[1][2]; - q[6] = conformal_spatial_metric[2][0]; q[7] = conformal_spatial_metric[2][1]; q[8] = conformal_spatial_metric[2][2]; + q[0] = conformal_spatial_metric[0][0]; + q[1] = conformal_spatial_metric[0][1]; + q[2] = conformal_spatial_metric[0][2]; + q[3] = conformal_spatial_metric[1][0]; + q[4] = conformal_spatial_metric[1][1]; + q[5] = conformal_spatial_metric[1][2]; + q[6] = conformal_spatial_metric[2][0]; + q[7] = conformal_spatial_metric[2][1]; + q[8] = conformal_spatial_metric[2][2]; q[9] = conformal_lapse; - q[10] = conformal_extrinsic_curvature[0][0]; q[11] = conformal_extrinsic_curvature[0][1]; q[12] = conformal_extrinsic_curvature[0][2]; - q[13] = conformal_extrinsic_curvature[1][0]; q[14] = conformal_extrinsic_curvature[1][1]; q[15] = conformal_extrinsic_curvature[1][2]; - q[16] = conformal_extrinsic_curvature[2][0]; q[17] = conformal_extrinsic_curvature[2][1]; q[18] = conformal_extrinsic_curvature[2][2]; - - q[19] = conformal_spatial_metric_der[0][0][0]; q[20] = conformal_spatial_metric_der[0][0][1]; q[21] = conformal_spatial_metric_der[0][0][2]; - q[22] = conformal_spatial_metric_der[0][1][0]; q[23] = conformal_spatial_metric_der[0][1][1]; q[24] = conformal_spatial_metric_der[0][1][2]; - q[25] = conformal_spatial_metric_der[0][2][0]; q[26] = conformal_spatial_metric_der[0][2][1]; q[27] = conformal_spatial_metric_der[0][2][2]; - - q[28] = conformal_spatial_metric_der[1][0][0]; q[29] = conformal_spatial_metric_der[1][0][1]; q[30] = conformal_spatial_metric_der[1][0][2]; - q[31] = conformal_spatial_metric_der[1][1][0]; q[32] = conformal_spatial_metric_der[1][1][1]; q[33] = conformal_spatial_metric_der[1][1][2]; - q[34] = conformal_spatial_metric_der[1][2][0]; q[35] = conformal_spatial_metric_der[1][2][1]; q[36] = conformal_spatial_metric_der[1][2][2]; - - q[37] = conformal_spatial_metric_der[2][0][0]; q[38] = conformal_spatial_metric_der[2][0][1]; q[39] = conformal_spatial_metric_der[2][0][2]; - q[40] = conformal_spatial_metric_der[2][1][0]; q[41] = conformal_spatial_metric_der[2][1][1]; q[42] = conformal_spatial_metric_der[2][1][2]; - q[43] = conformal_spatial_metric_der[2][2][0]; q[44] = conformal_spatial_metric_der[2][2][1]; q[45] = conformal_spatial_metric_der[2][2][2]; - - q[46] = conformal_lapse_der[0]; q[47] = conformal_lapse_der[1]; q[48] = conformal_lapse_der[2]; - - q[49] = conformal_aux_vect[0]; q[50] = conformal_aux_vect[1]; q[51] = conformal_aux_vect[2]; - - q[52] = conformal_shift[0]; q[53] = conformal_shift[1]; q[54] = conformal_shift[2]; - - q[55] = conformal_shift_der[0][0]; q[56] = conformal_shift_der[0][1]; q[57] = conformal_shift_der[0][2]; - q[58] = conformal_shift_der[1][0]; q[59] = conformal_shift_der[1][1]; q[60] = conformal_shift_der[1][2]; - q[61] = conformal_shift_der[2][0]; q[62] = conformal_shift_der[2][1]; q[63] = conformal_shift_der[2][2]; + q[10] = conformal_extrinsic_curvature[0][0]; + q[11] = conformal_extrinsic_curvature[0][1]; + q[12] = conformal_extrinsic_curvature[0][2]; + q[13] = conformal_extrinsic_curvature[1][0]; + q[14] = conformal_extrinsic_curvature[1][1]; + q[15] = conformal_extrinsic_curvature[1][2]; + q[16] = conformal_extrinsic_curvature[2][0]; + q[17] = conformal_extrinsic_curvature[2][1]; + q[18] = conformal_extrinsic_curvature[2][2]; + + q[19] = conformal_spatial_metric_der[0][0][0]; + q[20] = conformal_spatial_metric_der[0][0][1]; + q[21] = conformal_spatial_metric_der[0][0][2]; + q[22] = conformal_spatial_metric_der[0][1][0]; + q[23] = conformal_spatial_metric_der[0][1][1]; + q[24] = conformal_spatial_metric_der[0][1][2]; + q[25] = conformal_spatial_metric_der[0][2][0]; + q[26] = conformal_spatial_metric_der[0][2][1]; + q[27] = conformal_spatial_metric_der[0][2][2]; + + q[28] = conformal_spatial_metric_der[1][0][0]; + q[29] = conformal_spatial_metric_der[1][0][1]; + q[30] = conformal_spatial_metric_der[1][0][2]; + q[31] = conformal_spatial_metric_der[1][1][0]; + q[32] = conformal_spatial_metric_der[1][1][1]; + q[33] = conformal_spatial_metric_der[1][1][2]; + q[34] = conformal_spatial_metric_der[1][2][0]; + q[35] = conformal_spatial_metric_der[1][2][1]; + q[36] = conformal_spatial_metric_der[1][2][2]; + + q[37] = conformal_spatial_metric_der[2][0][0]; + q[38] = conformal_spatial_metric_der[2][0][1]; + q[39] = conformal_spatial_metric_der[2][0][2]; + q[40] = conformal_spatial_metric_der[2][1][0]; + q[41] = conformal_spatial_metric_der[2][1][1]; + q[42] = conformal_spatial_metric_der[2][1][2]; + q[43] = conformal_spatial_metric_der[2][2][0]; + q[44] = conformal_spatial_metric_der[2][2][1]; + q[45] = conformal_spatial_metric_der[2][2][2]; + + q[46] = conformal_lapse_der[0]; + q[47] = conformal_lapse_der[1]; + q[48] = conformal_lapse_der[2]; + + q[49] = conformal_aux_vect[0]; + q[50] = conformal_aux_vect[1]; + q[51] = conformal_aux_vect[2]; + + q[52] = conformal_shift[0]; + q[53] = conformal_shift[1]; + q[54] = conformal_shift[2]; + + q[55] = conformal_shift_der[0][0]; + q[56] = conformal_shift_der[0][1]; + q[57] = conformal_shift_der[0][2]; + q[58] = conformal_shift_der[1][0]; + q[59] = conformal_shift_der[1][1]; + q[60] = conformal_shift_der[1][2]; + q[61] = conformal_shift_der[2][0]; + q[62] = conformal_shift_der[2][1]; + q[63] = conformal_shift_der[2][2]; q[64] = bssn_conformal_fact; - q[65] = bssn_conformal_fact_der[0]; q[66] = bssn_conformal_fact_der[1]; q[67] = bssn_conformal_fact_der[2]; + q[65] = bssn_conformal_fact_der[0]; + q[66] = bssn_conformal_fact_der[1]; + q[67] = bssn_conformal_fact_der[2]; - q[68] = bssn_conformal_fact_der2[0][0]; q[69] = bssn_conformal_fact_der2[0][1]; q[70] = bssn_conformal_fact_der2[0][2]; - q[71] = bssn_conformal_fact_der2[1][0]; q[72] = bssn_conformal_fact_der2[1][1]; q[73] = bssn_conformal_fact_der2[1][2]; - q[74] = bssn_conformal_fact_der2[2][0]; q[75] = bssn_conformal_fact_der2[2][1]; q[76] = bssn_conformal_fact_der2[2][2]; + q[68] = bssn_conformal_fact_der2[0][0]; + q[69] = bssn_conformal_fact_der2[0][1]; + q[70] = bssn_conformal_fact_der2[0][2]; + q[71] = bssn_conformal_fact_der2[1][0]; + q[72] = bssn_conformal_fact_der2[1][1]; + q[73] = bssn_conformal_fact_der2[1][2]; + q[74] = bssn_conformal_fact_der2[2][0]; + q[75] = bssn_conformal_fact_der2[2][1]; + q[76] = bssn_conformal_fact_der2[2][2]; double evolution_func = 1.0; - double slicing_func = conformal_extrinsic_curvature_trace / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + double slicing_func = conformal_extrinsic_curvature_trace / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); double conformal_extrinsic_curvature_flux[3][3][3]; for (int d = 0; d < 3; d++) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_extrinsic_curvature_flux[d][i][j] = -conformal_shift[d] * conformal_extrinsic_curvature[i][j]; - conformal_extrinsic_curvature_flux[d][i][j] += conformal_lapse * conformal_spatial_metric_der_raised1[d][i][j]; - conformal_extrinsic_curvature_flux[d][i][j] -= conformal_lapse * (0.5 * evolution_func) * conformal_aux_vect_raised[d] * conformal_spatial_metric[i][j]; + conformal_extrinsic_curvature_flux[d][i][j] = + -conformal_shift[d] * conformal_extrinsic_curvature[i][j]; + conformal_extrinsic_curvature_flux[d][i][j] += + conformal_lapse * conformal_spatial_metric_der_raised1[d][i][j]; + conformal_extrinsic_curvature_flux[d][i][j] -= + conformal_lapse * (0.5 * evolution_func) * conformal_aux_vect_raised[d] * + conformal_spatial_metric[i][j]; if (i == d) { - conformal_extrinsic_curvature_flux[d][i][j] += 0.5 * conformal_lapse * conformal_lapse_der[j]; - conformal_extrinsic_curvature_flux[d][i][j] += conformal_lapse * conformal_aux_vect[j]; + conformal_extrinsic_curvature_flux[d][i][j] += + 0.5 * conformal_lapse * conformal_lapse_der[j]; + conformal_extrinsic_curvature_flux[d][i][j] += + conformal_lapse * conformal_aux_vect[j]; for (int r = 0; r < 3; r++) { - conformal_extrinsic_curvature_flux[d][i][j] -= 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[j][r][r]; + conformal_extrinsic_curvature_flux[d][i][j] -= + 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[j][r][r]; } } if (j == d) { - conformal_extrinsic_curvature_flux[d][i][j] += 0.5 * conformal_lapse * conformal_lapse_der[i]; - conformal_extrinsic_curvature_flux[d][i][j] += conformal_lapse * conformal_aux_vect[i]; + conformal_extrinsic_curvature_flux[d][i][j] += + 0.5 * conformal_lapse * conformal_lapse_der[i]; + conformal_extrinsic_curvature_flux[d][i][j] += + conformal_lapse * conformal_aux_vect[i]; for (int r = 0; r < 3; r++) { - conformal_extrinsic_curvature_flux[d][i][j] -= 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[i][r][r]; + conformal_extrinsic_curvature_flux[d][i][j] -= + 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[i][r][r]; } } } @@ -284,13 +382,18 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() } for (int r = 0; r < 3; r++) { - conformal_spatial_metric_der_flux[d][d][i][j] -= conformal_shift[r] * conformal_spatial_metric_der[r][i][j]; - conformal_spatial_metric_der_flux[d][d][i][j] -= 2.0 * conformal_shift[r] * conformal_fact_der[r] * conformal_spatial_metric[i][j]; + conformal_spatial_metric_der_flux[d][d][i][j] -= + conformal_shift[r] * conformal_spatial_metric_der[r][i][j]; + conformal_spatial_metric_der_flux[d][d][i][j] -= + 2.0 * conformal_shift[r] * conformal_fact_der[r] * conformal_spatial_metric[i][j]; } - conformal_spatial_metric_der_flux[d][d][i][j] += conformal_lapse * (conformal_extrinsic_curvature[i][j] / - (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); - conformal_spatial_metric_der_flux[d][d][i][j] -= conformal_lapse * symmetrized_conformal_shift[i][j]; + conformal_spatial_metric_der_flux[d][d][i][j] += + conformal_lapse * + (conformal_extrinsic_curvature[i][j] / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); + conformal_spatial_metric_der_flux[d][d][i][j] -= + conformal_lapse * symmetrized_conformal_shift[i][j]; } } } @@ -301,7 +404,7 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() conformal_lapse_der_flux[d][i] = 0.0; } } - + for (int d = 0; d < 3; d++) { for (int r = 0; r < 3; r++) { conformal_lapse_der_flux[d][d] -= conformal_shift[r] * conformal_lapse_der[r]; @@ -320,86 +423,164 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() } double fluxes[3][42] = { - { conformal_extrinsic_curvature_flux[0][0][0], conformal_extrinsic_curvature_flux[0][0][1], conformal_extrinsic_curvature_flux[0][0][2], - conformal_extrinsic_curvature_flux[0][1][0], conformal_extrinsic_curvature_flux[0][1][1], conformal_extrinsic_curvature_flux[0][1][2], - conformal_extrinsic_curvature_flux[0][2][0], conformal_extrinsic_curvature_flux[0][2][1], conformal_extrinsic_curvature_flux[0][2][2], - conformal_spatial_metric_der_flux[0][0][0][0], conformal_spatial_metric_der_flux[0][0][0][1], conformal_spatial_metric_der_flux[0][0][0][2], - conformal_spatial_metric_der_flux[0][0][1][0], conformal_spatial_metric_der_flux[0][0][1][1], conformal_spatial_metric_der_flux[0][0][1][2], - conformal_spatial_metric_der_flux[0][0][2][0], conformal_spatial_metric_der_flux[0][0][2][1], conformal_spatial_metric_der_flux[0][0][2][2], - conformal_spatial_metric_der_flux[0][1][0][0], conformal_spatial_metric_der_flux[0][1][0][1], conformal_spatial_metric_der_flux[0][1][0][2], - conformal_spatial_metric_der_flux[0][1][1][0], conformal_spatial_metric_der_flux[0][1][1][1], conformal_spatial_metric_der_flux[0][1][1][2], - conformal_spatial_metric_der_flux[0][1][2][0], conformal_spatial_metric_der_flux[0][1][2][1], conformal_spatial_metric_der_flux[0][1][2][2], - conformal_spatial_metric_der_flux[0][2][0][0], conformal_spatial_metric_der_flux[0][2][0][1], conformal_spatial_metric_der_flux[0][2][0][2], - conformal_spatial_metric_der_flux[0][2][1][0], conformal_spatial_metric_der_flux[0][2][1][1], conformal_spatial_metric_der_flux[0][2][1][2], - conformal_spatial_metric_der_flux[0][2][2][0], conformal_spatial_metric_der_flux[0][2][2][1], conformal_spatial_metric_der_flux[0][2][2][2], - conformal_lapse_der_flux[0][0], conformal_lapse_der_flux[0][1], conformal_lapse_der_flux[0][2], - conformal_aux_vect_flux[0][0], conformal_aux_vect_flux[0][1], conformal_aux_vect_flux[0][2] }, - { conformal_extrinsic_curvature_flux[1][0][0], conformal_extrinsic_curvature_flux[1][0][1], conformal_extrinsic_curvature_flux[1][0][2], - conformal_extrinsic_curvature_flux[1][1][0], conformal_extrinsic_curvature_flux[1][1][1], conformal_extrinsic_curvature_flux[1][1][2], - conformal_extrinsic_curvature_flux[1][2][0], conformal_extrinsic_curvature_flux[1][2][1], conformal_extrinsic_curvature_flux[1][2][2], - conformal_spatial_metric_der_flux[1][0][0][0], conformal_spatial_metric_der_flux[1][0][0][1], conformal_spatial_metric_der_flux[1][0][0][2], - conformal_spatial_metric_der_flux[1][0][1][0], conformal_spatial_metric_der_flux[1][0][1][1], conformal_spatial_metric_der_flux[1][0][1][2], - conformal_spatial_metric_der_flux[1][0][2][0], conformal_spatial_metric_der_flux[1][0][2][1], conformal_spatial_metric_der_flux[1][0][2][2], - conformal_spatial_metric_der_flux[1][1][0][0], conformal_spatial_metric_der_flux[1][1][0][1], conformal_spatial_metric_der_flux[1][1][0][2], - conformal_spatial_metric_der_flux[1][1][1][0], conformal_spatial_metric_der_flux[1][1][1][1], conformal_spatial_metric_der_flux[1][1][1][2], - conformal_spatial_metric_der_flux[1][1][2][0], conformal_spatial_metric_der_flux[1][1][2][1], conformal_spatial_metric_der_flux[1][1][2][2], - conformal_spatial_metric_der_flux[1][2][0][0], conformal_spatial_metric_der_flux[1][2][0][1], conformal_spatial_metric_der_flux[1][2][0][2], - conformal_spatial_metric_der_flux[1][2][1][0], conformal_spatial_metric_der_flux[1][2][1][1], conformal_spatial_metric_der_flux[1][2][1][2], - conformal_spatial_metric_der_flux[1][2][2][0], conformal_spatial_metric_der_flux[1][2][2][1], conformal_spatial_metric_der_flux[1][2][2][2], - conformal_lapse_der_flux[1][0], conformal_lapse_der_flux[1][1], conformal_lapse_der_flux[1][2], - conformal_aux_vect_flux[1][0], conformal_aux_vect_flux[1][1], conformal_aux_vect_flux[1][2] }, - { conformal_extrinsic_curvature_flux[2][0][0], conformal_extrinsic_curvature_flux[2][0][1], conformal_extrinsic_curvature_flux[2][0][2], - conformal_extrinsic_curvature_flux[2][1][0], conformal_extrinsic_curvature_flux[2][1][1], conformal_extrinsic_curvature_flux[2][1][2], - conformal_extrinsic_curvature_flux[2][2][0], conformal_extrinsic_curvature_flux[2][2][1], conformal_extrinsic_curvature_flux[2][2][2], - conformal_spatial_metric_der_flux[2][0][0][0], conformal_spatial_metric_der_flux[2][0][0][1], conformal_spatial_metric_der_flux[2][0][0][2], - conformal_spatial_metric_der_flux[2][0][1][0], conformal_spatial_metric_der_flux[2][0][1][1], conformal_spatial_metric_der_flux[2][0][1][2], - conformal_spatial_metric_der_flux[2][0][2][0], conformal_spatial_metric_der_flux[2][0][2][1], conformal_spatial_metric_der_flux[2][0][2][2], - conformal_spatial_metric_der_flux[2][1][0][0], conformal_spatial_metric_der_flux[2][1][0][1], conformal_spatial_metric_der_flux[2][1][0][2], - conformal_spatial_metric_der_flux[2][1][1][0], conformal_spatial_metric_der_flux[2][1][1][1], conformal_spatial_metric_der_flux[2][1][1][2], - conformal_spatial_metric_der_flux[2][1][2][0], conformal_spatial_metric_der_flux[2][1][2][1], conformal_spatial_metric_der_flux[2][1][2][2], - conformal_spatial_metric_der_flux[2][2][0][0], conformal_spatial_metric_der_flux[2][2][0][1], conformal_spatial_metric_der_flux[2][2][0][2], - conformal_spatial_metric_der_flux[2][2][1][0], conformal_spatial_metric_der_flux[2][2][1][1], conformal_spatial_metric_der_flux[2][2][1][2], - conformal_spatial_metric_der_flux[2][2][2][0], conformal_spatial_metric_der_flux[2][2][2][1], conformal_spatial_metric_der_flux[2][2][2][2], - conformal_lapse_der_flux[2][0], conformal_lapse_der_flux[2][1], conformal_lapse_der_flux[2][2], - conformal_aux_vect_flux[2][0], conformal_aux_vect_flux[2][1], conformal_aux_vect_flux[2][2] }, + {conformal_extrinsic_curvature_flux[0][0][0], + conformal_extrinsic_curvature_flux[0][0][1], + conformal_extrinsic_curvature_flux[0][0][2], + conformal_extrinsic_curvature_flux[0][1][0], + conformal_extrinsic_curvature_flux[0][1][1], + conformal_extrinsic_curvature_flux[0][1][2], + conformal_extrinsic_curvature_flux[0][2][0], + conformal_extrinsic_curvature_flux[0][2][1], + conformal_extrinsic_curvature_flux[0][2][2], + conformal_spatial_metric_der_flux[0][0][0][0], + conformal_spatial_metric_der_flux[0][0][0][1], + conformal_spatial_metric_der_flux[0][0][0][2], + conformal_spatial_metric_der_flux[0][0][1][0], + conformal_spatial_metric_der_flux[0][0][1][1], + conformal_spatial_metric_der_flux[0][0][1][2], + conformal_spatial_metric_der_flux[0][0][2][0], + conformal_spatial_metric_der_flux[0][0][2][1], + conformal_spatial_metric_der_flux[0][0][2][2], + conformal_spatial_metric_der_flux[0][1][0][0], + conformal_spatial_metric_der_flux[0][1][0][1], + conformal_spatial_metric_der_flux[0][1][0][2], + conformal_spatial_metric_der_flux[0][1][1][0], + conformal_spatial_metric_der_flux[0][1][1][1], + conformal_spatial_metric_der_flux[0][1][1][2], + conformal_spatial_metric_der_flux[0][1][2][0], + conformal_spatial_metric_der_flux[0][1][2][1], + conformal_spatial_metric_der_flux[0][1][2][2], + conformal_spatial_metric_der_flux[0][2][0][0], + conformal_spatial_metric_der_flux[0][2][0][1], + conformal_spatial_metric_der_flux[0][2][0][2], + conformal_spatial_metric_der_flux[0][2][1][0], + conformal_spatial_metric_der_flux[0][2][1][1], + conformal_spatial_metric_der_flux[0][2][1][2], + conformal_spatial_metric_der_flux[0][2][2][0], + conformal_spatial_metric_der_flux[0][2][2][1], + conformal_spatial_metric_der_flux[0][2][2][2], + conformal_lapse_der_flux[0][0], + conformal_lapse_der_flux[0][1], + conformal_lapse_der_flux[0][2], + conformal_aux_vect_flux[0][0], + conformal_aux_vect_flux[0][1], + conformal_aux_vect_flux[0][2]}, + {conformal_extrinsic_curvature_flux[1][0][0], + conformal_extrinsic_curvature_flux[1][0][1], + conformal_extrinsic_curvature_flux[1][0][2], + conformal_extrinsic_curvature_flux[1][1][0], + conformal_extrinsic_curvature_flux[1][1][1], + conformal_extrinsic_curvature_flux[1][1][2], + conformal_extrinsic_curvature_flux[1][2][0], + conformal_extrinsic_curvature_flux[1][2][1], + conformal_extrinsic_curvature_flux[1][2][2], + conformal_spatial_metric_der_flux[1][0][0][0], + conformal_spatial_metric_der_flux[1][0][0][1], + conformal_spatial_metric_der_flux[1][0][0][2], + conformal_spatial_metric_der_flux[1][0][1][0], + conformal_spatial_metric_der_flux[1][0][1][1], + conformal_spatial_metric_der_flux[1][0][1][2], + conformal_spatial_metric_der_flux[1][0][2][0], + conformal_spatial_metric_der_flux[1][0][2][1], + conformal_spatial_metric_der_flux[1][0][2][2], + conformal_spatial_metric_der_flux[1][1][0][0], + conformal_spatial_metric_der_flux[1][1][0][1], + conformal_spatial_metric_der_flux[1][1][0][2], + conformal_spatial_metric_der_flux[1][1][1][0], + conformal_spatial_metric_der_flux[1][1][1][1], + conformal_spatial_metric_der_flux[1][1][1][2], + conformal_spatial_metric_der_flux[1][1][2][0], + conformal_spatial_metric_der_flux[1][1][2][1], + conformal_spatial_metric_der_flux[1][1][2][2], + conformal_spatial_metric_der_flux[1][2][0][0], + conformal_spatial_metric_der_flux[1][2][0][1], + conformal_spatial_metric_der_flux[1][2][0][2], + conformal_spatial_metric_der_flux[1][2][1][0], + conformal_spatial_metric_der_flux[1][2][1][1], + conformal_spatial_metric_der_flux[1][2][1][2], + conformal_spatial_metric_der_flux[1][2][2][0], + conformal_spatial_metric_der_flux[1][2][2][1], + conformal_spatial_metric_der_flux[1][2][2][2], + conformal_lapse_der_flux[1][0], + conformal_lapse_der_flux[1][1], + conformal_lapse_der_flux[1][2], + conformal_aux_vect_flux[1][0], + conformal_aux_vect_flux[1][1], + conformal_aux_vect_flux[1][2]}, + {conformal_extrinsic_curvature_flux[2][0][0], + conformal_extrinsic_curvature_flux[2][0][1], + conformal_extrinsic_curvature_flux[2][0][2], + conformal_extrinsic_curvature_flux[2][1][0], + conformal_extrinsic_curvature_flux[2][1][1], + conformal_extrinsic_curvature_flux[2][1][2], + conformal_extrinsic_curvature_flux[2][2][0], + conformal_extrinsic_curvature_flux[2][2][1], + conformal_extrinsic_curvature_flux[2][2][2], + conformal_spatial_metric_der_flux[2][0][0][0], + conformal_spatial_metric_der_flux[2][0][0][1], + conformal_spatial_metric_der_flux[2][0][0][2], + conformal_spatial_metric_der_flux[2][0][1][0], + conformal_spatial_metric_der_flux[2][0][1][1], + conformal_spatial_metric_der_flux[2][0][1][2], + conformal_spatial_metric_der_flux[2][0][2][0], + conformal_spatial_metric_der_flux[2][0][2][1], + conformal_spatial_metric_der_flux[2][0][2][2], + conformal_spatial_metric_der_flux[2][1][0][0], + conformal_spatial_metric_der_flux[2][1][0][1], + conformal_spatial_metric_der_flux[2][1][0][2], + conformal_spatial_metric_der_flux[2][1][1][0], + conformal_spatial_metric_der_flux[2][1][1][1], + conformal_spatial_metric_der_flux[2][1][1][2], + conformal_spatial_metric_der_flux[2][1][2][0], + conformal_spatial_metric_der_flux[2][1][2][1], + conformal_spatial_metric_der_flux[2][1][2][2], + conformal_spatial_metric_der_flux[2][2][0][0], + conformal_spatial_metric_der_flux[2][2][0][1], + conformal_spatial_metric_der_flux[2][2][0][2], + conformal_spatial_metric_der_flux[2][2][1][0], + conformal_spatial_metric_der_flux[2][2][1][1], + conformal_spatial_metric_der_flux[2][2][1][2], + conformal_spatial_metric_der_flux[2][2][2][0], + conformal_spatial_metric_der_flux[2][2][2][1], + conformal_spatial_metric_der_flux[2][2][2][2], + conformal_lapse_der_flux[2][0], + conformal_lapse_der_flux[2][1], + conformal_lapse_der_flux[2][2], + conformal_aux_vect_flux[2][0], + conformal_aux_vect_flux[2][1], + conformal_aux_vect_flux[2][2]} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[77], flux_local[77], flux[77]; for (int d = 0; d < 3; d++) { - vacuum_einstein_conformal->rotate_to_local_func(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, q_local, flux_local); - vacuum_einstein_conformal->rotate_to_global_func(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], flux_local, flux); + vacuum_einstein_conformal->rotate_to_local_func( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], q, q_local + ); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, q_local, flux_local + ); + vacuum_einstein_conformal->rotate_to_global_func( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 42; i++) { - TEST_CHECK( gkyl_compare(flux[i + 10], fluxes[d][i], 1e-8) ); + TEST_CHECK(gkyl_compare(flux[i + 10], fluxes[d][i], 1e-8)); } } - + double q_l[77], q_g[77]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], q, q_l); gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], q_l, q_g); for (int i = 0; i < 77; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-16)); } double w1[77], q1[77]; @@ -407,7 +588,7 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() vacuum_einstein_conformal->riem_to_cons(vacuum_einstein_conformal, q_local, w1, q1); for (int i = 0; i < 77; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-16)); } } @@ -416,7 +597,7 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() gkyl_free(inv_conformal_spatial_metric[i]); gkyl_free(conformal_extrinsic_curvature[i]); gkyl_free(conformal_shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(conformal_spatial_metric_der[i][j]); } @@ -440,17 +621,18 @@ test_vacuum_einstein_conformal_basic_minkowski_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_vacuum_einstein_conformal_basic_schwarzschild_ho() +void test_vacuum_einstein_conformal_basic_schwarzschild_ho() { double excision_threshold = 0.3; enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); + struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new( + excision_threshold, spacetime_slicing, spacetime_evolution, false + ); - TEST_CHECK( vacuum_einstein_conformal->num_equations == 77 ); - TEST_CHECK( vacuum_einstein_conformal->num_waves == 2 ); + TEST_CHECK(vacuum_einstein_conformal->num_equations == 77); + TEST_CHECK(vacuum_einstein_conformal->num_waves == 2); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -461,27 +643,27 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() double *conformal_shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); inv_conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **conformal_extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *conformal_lapse_der = gkyl_malloc(sizeof(double[3])); - double **conformal_shift_der = gkyl_malloc(sizeof(double*[3])); + double **conformal_shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***conformal_spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + conformal_spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { conformal_spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -491,7 +673,7 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() double conformal_fact, bssn_conformal_fact; double *conformal_fact_der = gkyl_malloc(sizeof(double[3])); double *bssn_conformal_fact_der = gkyl_malloc(sizeof(double[3])); - double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_fact_der2 = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_fact_der2[i] = gkyl_malloc(sizeof(double[3])); } @@ -500,21 +682,44 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &conformal_lapse); spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &conformal_shift); spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); - + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &conformal_spatial_metric); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_conformal_spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_extrinsic_curvature); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x, y, 0.0, &inv_conformal_spatial_metric + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_extrinsic_curvature + ); spacetime->conformal_factor_func(spacetime, 0.0, x, y, 0.0, &conformal_fact); spacetime->bssn_conformal_factor_func(spacetime, 0.0, x, y, 0.0, &bssn_conformal_fact); - spacetime->conformal_factor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_fact_der); - spacetime->bssn_conformal_factor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &bssn_conformal_fact_der); - spacetime->bssn_conformal_factor_der2_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), &bssn_conformal_fact_der2); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &conformal_spatial_metric_der); + spacetime->conformal_factor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_fact_der + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &bssn_conformal_fact_der + ); + spacetime->bssn_conformal_factor_der2_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -6.0), pow(10.0, -6.0), pow(10.0, -6.0), + &bssn_conformal_fact_der2 + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, 0.0, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &conformal_spatial_metric_der + ); for (int i = 0; i < 3; i++) { conformal_fact_der[i] /= conformal_fact; @@ -532,8 +737,10 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_spatial_metric[i][j] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - inv_conformal_spatial_metric[i][j] *= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric[i][j] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + inv_conformal_spatial_metric[i][j] *= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); } } @@ -541,8 +748,10 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der[i][j][k] = 0.5 * conformal_spatial_metric_der[i][j][k]; - conformal_spatial_metric_der[i][j][k] /= (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_spatial_metric_der[i][j][k] -= 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; + conformal_spatial_metric_der[i][j][k] /= + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_spatial_metric_der[i][j][k] -= + 2.0 * conformal_fact_der[i] * conformal_spatial_metric[j][k]; } conformal_shift_der[i][j] = 0.5 * conformal_shift_der[i][j]; @@ -556,7 +765,8 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() double conformal_extrinsic_curvature_trace = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_extrinsic_curvature_trace += inv_conformal_spatial_metric[i][j] * conformal_extrinsic_curvature[i][j]; + conformal_extrinsic_curvature_trace += + inv_conformal_spatial_metric[i][j] * conformal_extrinsic_curvature[i][j]; } } @@ -565,14 +775,15 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1[k][i][j] += inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; + conformal_spatial_metric_der_raised1[k][i][j] += + inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; } } } } - + double conformal_spatial_metric_der_raised3[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -580,7 +791,8 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() conformal_spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3[i][j][k] += inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; + conformal_spatial_metric_der_raised3[i][j][k] += + inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; } } } @@ -601,9 +813,10 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() double conformal_aux_vect_raised[3]; for (int k = 0; k < 3; k++) { conformal_aux_vect_raised[k] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_aux_vect_raised[k] += inv_conformal_spatial_metric[k][l] * conformal_aux_vect[l]; + conformal_aux_vect_raised[k] += + inv_conformal_spatial_metric[k][l] * conformal_aux_vect[l]; } } @@ -613,7 +826,8 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() conformal_shift_der_lowered[i][j] = 0.0; for (int k = 0; k < 3; k++) { - conformal_shift_der_lowered[i][j] += conformal_spatial_metric[k][j] * conformal_shift_der[i][k]; + conformal_shift_der_lowered[i][j] += + conformal_spatial_metric[k][j] * conformal_shift_der[i][k]; } } } @@ -625,7 +839,9 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_shift_der_switched[i][k] += inv_conformal_spatial_metric[i][l] * conformal_spatial_metric[m][k] * conformal_shift_der[l][m]; + conformal_shift_der_switched[i][k] += inv_conformal_spatial_metric[i][l] * + conformal_spatial_metric[m][k] * + conformal_shift_der[l][m]; } } } @@ -634,76 +850,140 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() double symmetrized_conformal_shift[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - symmetrized_conformal_shift[i][j] = (1.0 / conformal_lapse) * (conformal_shift_der_lowered[i][j] + conformal_shift_der_lowered[j][i]); + symmetrized_conformal_shift[i][j] = + (1.0 / conformal_lapse) * + (conformal_shift_der_lowered[i][j] + conformal_shift_der_lowered[j][i]); } } if (!in_excision_region) { double q[77]; - q[0] = conformal_spatial_metric[0][0]; q[1] = conformal_spatial_metric[0][1]; q[2] = conformal_spatial_metric[0][2]; - q[3] = conformal_spatial_metric[1][0]; q[4] = conformal_spatial_metric[1][1]; q[5] = conformal_spatial_metric[1][2]; - q[6] = conformal_spatial_metric[2][0]; q[7] = conformal_spatial_metric[2][1]; q[8] = conformal_spatial_metric[2][2]; + q[0] = conformal_spatial_metric[0][0]; + q[1] = conformal_spatial_metric[0][1]; + q[2] = conformal_spatial_metric[0][2]; + q[3] = conformal_spatial_metric[1][0]; + q[4] = conformal_spatial_metric[1][1]; + q[5] = conformal_spatial_metric[1][2]; + q[6] = conformal_spatial_metric[2][0]; + q[7] = conformal_spatial_metric[2][1]; + q[8] = conformal_spatial_metric[2][2]; q[9] = conformal_lapse; - q[10] = conformal_extrinsic_curvature[0][0]; q[11] = conformal_extrinsic_curvature[0][1]; q[12] = conformal_extrinsic_curvature[0][2]; - q[13] = conformal_extrinsic_curvature[1][0]; q[14] = conformal_extrinsic_curvature[1][1]; q[15] = conformal_extrinsic_curvature[1][2]; - q[16] = conformal_extrinsic_curvature[2][0]; q[17] = conformal_extrinsic_curvature[2][1]; q[18] = conformal_extrinsic_curvature[2][2]; - - q[19] = conformal_spatial_metric_der[0][0][0]; q[20] = conformal_spatial_metric_der[0][0][1]; q[21] = conformal_spatial_metric_der[0][0][2]; - q[22] = conformal_spatial_metric_der[0][1][0]; q[23] = conformal_spatial_metric_der[0][1][1]; q[24] = conformal_spatial_metric_der[0][1][2]; - q[25] = conformal_spatial_metric_der[0][2][0]; q[26] = conformal_spatial_metric_der[0][2][1]; q[27] = conformal_spatial_metric_der[0][2][2]; - - q[28] = conformal_spatial_metric_der[1][0][0]; q[29] = conformal_spatial_metric_der[1][0][1]; q[30] = conformal_spatial_metric_der[1][0][2]; - q[31] = conformal_spatial_metric_der[1][1][0]; q[32] = conformal_spatial_metric_der[1][1][1]; q[33] = conformal_spatial_metric_der[1][1][2]; - q[34] = conformal_spatial_metric_der[1][2][0]; q[35] = conformal_spatial_metric_der[1][2][1]; q[36] = conformal_spatial_metric_der[1][2][2]; - - q[37] = conformal_spatial_metric_der[2][0][0]; q[38] = conformal_spatial_metric_der[2][0][1]; q[39] = conformal_spatial_metric_der[2][0][2]; - q[40] = conformal_spatial_metric_der[2][1][0]; q[41] = conformal_spatial_metric_der[2][1][1]; q[42] = conformal_spatial_metric_der[2][1][2]; - q[43] = conformal_spatial_metric_der[2][2][0]; q[44] = conformal_spatial_metric_der[2][2][1]; q[45] = conformal_spatial_metric_der[2][2][2]; - - q[46] = conformal_lapse_der[0]; q[47] = conformal_lapse_der[1]; q[48] = conformal_lapse_der[2]; - - q[49] = conformal_aux_vect[0]; q[50] = conformal_aux_vect[1]; q[51] = conformal_aux_vect[2]; - - q[52] = conformal_shift[0]; q[53] = conformal_shift[1]; q[54] = conformal_shift[2]; - - q[55] = conformal_shift_der[0][0]; q[56] = conformal_shift_der[0][1]; q[57] = conformal_shift_der[0][2]; - q[58] = conformal_shift_der[1][0]; q[59] = conformal_shift_der[1][1]; q[60] = conformal_shift_der[1][2]; - q[61] = conformal_shift_der[2][0]; q[62] = conformal_shift_der[2][1]; q[63] = conformal_shift_der[2][2]; + q[10] = conformal_extrinsic_curvature[0][0]; + q[11] = conformal_extrinsic_curvature[0][1]; + q[12] = conformal_extrinsic_curvature[0][2]; + q[13] = conformal_extrinsic_curvature[1][0]; + q[14] = conformal_extrinsic_curvature[1][1]; + q[15] = conformal_extrinsic_curvature[1][2]; + q[16] = conformal_extrinsic_curvature[2][0]; + q[17] = conformal_extrinsic_curvature[2][1]; + q[18] = conformal_extrinsic_curvature[2][2]; + + q[19] = conformal_spatial_metric_der[0][0][0]; + q[20] = conformal_spatial_metric_der[0][0][1]; + q[21] = conformal_spatial_metric_der[0][0][2]; + q[22] = conformal_spatial_metric_der[0][1][0]; + q[23] = conformal_spatial_metric_der[0][1][1]; + q[24] = conformal_spatial_metric_der[0][1][2]; + q[25] = conformal_spatial_metric_der[0][2][0]; + q[26] = conformal_spatial_metric_der[0][2][1]; + q[27] = conformal_spatial_metric_der[0][2][2]; + + q[28] = conformal_spatial_metric_der[1][0][0]; + q[29] = conformal_spatial_metric_der[1][0][1]; + q[30] = conformal_spatial_metric_der[1][0][2]; + q[31] = conformal_spatial_metric_der[1][1][0]; + q[32] = conformal_spatial_metric_der[1][1][1]; + q[33] = conformal_spatial_metric_der[1][1][2]; + q[34] = conformal_spatial_metric_der[1][2][0]; + q[35] = conformal_spatial_metric_der[1][2][1]; + q[36] = conformal_spatial_metric_der[1][2][2]; + + q[37] = conformal_spatial_metric_der[2][0][0]; + q[38] = conformal_spatial_metric_der[2][0][1]; + q[39] = conformal_spatial_metric_der[2][0][2]; + q[40] = conformal_spatial_metric_der[2][1][0]; + q[41] = conformal_spatial_metric_der[2][1][1]; + q[42] = conformal_spatial_metric_der[2][1][2]; + q[43] = conformal_spatial_metric_der[2][2][0]; + q[44] = conformal_spatial_metric_der[2][2][1]; + q[45] = conformal_spatial_metric_der[2][2][2]; + + q[46] = conformal_lapse_der[0]; + q[47] = conformal_lapse_der[1]; + q[48] = conformal_lapse_der[2]; + + q[49] = conformal_aux_vect[0]; + q[50] = conformal_aux_vect[1]; + q[51] = conformal_aux_vect[2]; + + q[52] = conformal_shift[0]; + q[53] = conformal_shift[1]; + q[54] = conformal_shift[2]; + + q[55] = conformal_shift_der[0][0]; + q[56] = conformal_shift_der[0][1]; + q[57] = conformal_shift_der[0][2]; + q[58] = conformal_shift_der[1][0]; + q[59] = conformal_shift_der[1][1]; + q[60] = conformal_shift_der[1][2]; + q[61] = conformal_shift_der[2][0]; + q[62] = conformal_shift_der[2][1]; + q[63] = conformal_shift_der[2][2]; q[64] = bssn_conformal_fact; - q[65] = bssn_conformal_fact_der[0]; q[66] = bssn_conformal_fact_der[1]; q[67] = bssn_conformal_fact_der[2]; + q[65] = bssn_conformal_fact_der[0]; + q[66] = bssn_conformal_fact_der[1]; + q[67] = bssn_conformal_fact_der[2]; - q[68] = bssn_conformal_fact_der2[0][0]; q[69] = bssn_conformal_fact_der2[0][1]; q[70] = bssn_conformal_fact_der2[0][2]; - q[71] = bssn_conformal_fact_der2[1][0]; q[72] = bssn_conformal_fact_der2[1][1]; q[73] = bssn_conformal_fact_der2[1][2]; - q[74] = bssn_conformal_fact_der2[2][0]; q[75] = bssn_conformal_fact_der2[2][1]; q[76] = bssn_conformal_fact_der2[2][2]; + q[68] = bssn_conformal_fact_der2[0][0]; + q[69] = bssn_conformal_fact_der2[0][1]; + q[70] = bssn_conformal_fact_der2[0][2]; + q[71] = bssn_conformal_fact_der2[1][0]; + q[72] = bssn_conformal_fact_der2[1][1]; + q[73] = bssn_conformal_fact_der2[1][2]; + q[74] = bssn_conformal_fact_der2[2][0]; + q[75] = bssn_conformal_fact_der2[2][1]; + q[76] = bssn_conformal_fact_der2[2][2]; double evolution_func = 1.0; - double slicing_func = 2.0 * conformal_extrinsic_curvature_trace / (conformal_lapse * conformal_fact * conformal_fact * conformal_fact * conformal_fact); + double slicing_func = + 2.0 * conformal_extrinsic_curvature_trace / + (conformal_lapse * conformal_fact * conformal_fact * conformal_fact * conformal_fact); double conformal_extrinsic_curvature_flux[3][3][3]; for (int d = 0; d < 3; d++) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_extrinsic_curvature_flux[d][i][j] = -conformal_shift[d] * conformal_extrinsic_curvature[i][j]; - conformal_extrinsic_curvature_flux[d][i][j] += conformal_lapse * conformal_spatial_metric_der_raised1[d][i][j]; - conformal_extrinsic_curvature_flux[d][i][j] -= conformal_lapse * (0.5 * evolution_func) * conformal_aux_vect_raised[d] * conformal_spatial_metric[i][j]; + conformal_extrinsic_curvature_flux[d][i][j] = + -conformal_shift[d] * conformal_extrinsic_curvature[i][j]; + conformal_extrinsic_curvature_flux[d][i][j] += + conformal_lapse * conformal_spatial_metric_der_raised1[d][i][j]; + conformal_extrinsic_curvature_flux[d][i][j] -= + conformal_lapse * (0.5 * evolution_func) * conformal_aux_vect_raised[d] * + conformal_spatial_metric[i][j]; if (i == d) { - conformal_extrinsic_curvature_flux[d][i][j] += 0.5 * conformal_lapse * conformal_lapse_der[j]; - conformal_extrinsic_curvature_flux[d][i][j] += conformal_lapse * conformal_aux_vect[j]; + conformal_extrinsic_curvature_flux[d][i][j] += + 0.5 * conformal_lapse * conformal_lapse_der[j]; + conformal_extrinsic_curvature_flux[d][i][j] += + conformal_lapse * conformal_aux_vect[j]; for (int r = 0; r < 3; r++) { - conformal_extrinsic_curvature_flux[d][i][j] -= 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[j][r][r]; + conformal_extrinsic_curvature_flux[d][i][j] -= + 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[j][r][r]; } } if (j == d) { - conformal_extrinsic_curvature_flux[d][i][j] += 0.5 * conformal_lapse * conformal_lapse_der[i]; - conformal_extrinsic_curvature_flux[d][i][j] += conformal_lapse * conformal_aux_vect[i]; + conformal_extrinsic_curvature_flux[d][i][j] += + 0.5 * conformal_lapse * conformal_lapse_der[i]; + conformal_extrinsic_curvature_flux[d][i][j] += + conformal_lapse * conformal_aux_vect[i]; for (int r = 0; r < 3; r++) { - conformal_extrinsic_curvature_flux[d][i][j] -= 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[i][r][r]; + conformal_extrinsic_curvature_flux[d][i][j] -= + 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[i][r][r]; } } } @@ -719,13 +999,18 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() } for (int r = 0; r < 3; r++) { - conformal_spatial_metric_der_flux[d][d][i][j] -= conformal_shift[r] * conformal_spatial_metric_der[r][i][j]; - conformal_spatial_metric_der_flux[d][d][i][j] -= 2.0 * conformal_shift[r] * conformal_fact_der[r] * conformal_spatial_metric[i][j]; + conformal_spatial_metric_der_flux[d][d][i][j] -= + conformal_shift[r] * conformal_spatial_metric_der[r][i][j]; + conformal_spatial_metric_der_flux[d][d][i][j] -= + 2.0 * conformal_shift[r] * conformal_fact_der[r] * conformal_spatial_metric[i][j]; } - conformal_spatial_metric_der_flux[d][d][i][j] += conformal_lapse * (conformal_extrinsic_curvature[i][j] / - (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); - conformal_spatial_metric_der_flux[d][d][i][j] -= conformal_lapse * symmetrized_conformal_shift[i][j]; + conformal_spatial_metric_der_flux[d][d][i][j] += + conformal_lapse * + (conformal_extrinsic_curvature[i][j] / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); + conformal_spatial_metric_der_flux[d][d][i][j] -= + conformal_lapse * symmetrized_conformal_shift[i][j]; } } } @@ -736,7 +1021,7 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() conformal_lapse_der_flux[d][i] = 0.0; } } - + for (int d = 0; d < 3; d++) { for (int r = 0; r < 3; r++) { conformal_lapse_der_flux[d][d] -= conformal_shift[r] * conformal_lapse_der[r]; @@ -755,86 +1040,166 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() } double fluxes[3][42] = { - { conformal_extrinsic_curvature_flux[0][0][0], conformal_extrinsic_curvature_flux[0][0][1], conformal_extrinsic_curvature_flux[0][0][2], - conformal_extrinsic_curvature_flux[0][1][0], conformal_extrinsic_curvature_flux[0][1][1], conformal_extrinsic_curvature_flux[0][1][2], - conformal_extrinsic_curvature_flux[0][2][0], conformal_extrinsic_curvature_flux[0][2][1], conformal_extrinsic_curvature_flux[0][2][2], - conformal_spatial_metric_der_flux[0][0][0][0], conformal_spatial_metric_der_flux[0][0][0][1], conformal_spatial_metric_der_flux[0][0][0][2], - conformal_spatial_metric_der_flux[0][0][1][0], conformal_spatial_metric_der_flux[0][0][1][1], conformal_spatial_metric_der_flux[0][0][1][2], - conformal_spatial_metric_der_flux[0][0][2][0], conformal_spatial_metric_der_flux[0][0][2][1], conformal_spatial_metric_der_flux[0][0][2][2], - conformal_spatial_metric_der_flux[0][1][0][0], conformal_spatial_metric_der_flux[0][1][0][1], conformal_spatial_metric_der_flux[0][1][0][2], - conformal_spatial_metric_der_flux[0][1][1][0], conformal_spatial_metric_der_flux[0][1][1][1], conformal_spatial_metric_der_flux[0][1][1][2], - conformal_spatial_metric_der_flux[0][1][2][0], conformal_spatial_metric_der_flux[0][1][2][1], conformal_spatial_metric_der_flux[0][1][2][2], - conformal_spatial_metric_der_flux[0][2][0][0], conformal_spatial_metric_der_flux[0][2][0][1], conformal_spatial_metric_der_flux[0][2][0][2], - conformal_spatial_metric_der_flux[0][2][1][0], conformal_spatial_metric_der_flux[0][2][1][1], conformal_spatial_metric_der_flux[0][2][1][2], - conformal_spatial_metric_der_flux[0][2][2][0], conformal_spatial_metric_der_flux[0][2][2][1], conformal_spatial_metric_der_flux[0][2][2][2], - conformal_lapse_der_flux[0][0], conformal_lapse_der_flux[0][1], conformal_lapse_der_flux[0][2], - conformal_aux_vect_flux[0][0], conformal_aux_vect_flux[0][1], conformal_aux_vect_flux[0][2] }, - { conformal_extrinsic_curvature_flux[1][0][0], conformal_extrinsic_curvature_flux[1][0][1], conformal_extrinsic_curvature_flux[1][0][2], - conformal_extrinsic_curvature_flux[1][1][0], conformal_extrinsic_curvature_flux[1][1][1], conformal_extrinsic_curvature_flux[1][1][2], - conformal_extrinsic_curvature_flux[1][2][0], conformal_extrinsic_curvature_flux[1][2][1], conformal_extrinsic_curvature_flux[1][2][2], - conformal_spatial_metric_der_flux[1][0][0][0], conformal_spatial_metric_der_flux[1][0][0][1], conformal_spatial_metric_der_flux[1][0][0][2], - conformal_spatial_metric_der_flux[1][0][1][0], conformal_spatial_metric_der_flux[1][0][1][1], conformal_spatial_metric_der_flux[1][0][1][2], - conformal_spatial_metric_der_flux[1][0][2][0], conformal_spatial_metric_der_flux[1][0][2][1], conformal_spatial_metric_der_flux[1][0][2][2], - conformal_spatial_metric_der_flux[1][1][0][0], conformal_spatial_metric_der_flux[1][1][0][1], conformal_spatial_metric_der_flux[1][1][0][2], - conformal_spatial_metric_der_flux[1][1][1][0], conformal_spatial_metric_der_flux[1][1][1][1], conformal_spatial_metric_der_flux[1][1][1][2], - conformal_spatial_metric_der_flux[1][1][2][0], conformal_spatial_metric_der_flux[1][1][2][1], conformal_spatial_metric_der_flux[1][1][2][2], - conformal_spatial_metric_der_flux[1][2][0][0], conformal_spatial_metric_der_flux[1][2][0][1], conformal_spatial_metric_der_flux[1][2][0][2], - conformal_spatial_metric_der_flux[1][2][1][0], conformal_spatial_metric_der_flux[1][2][1][1], conformal_spatial_metric_der_flux[1][2][1][2], - conformal_spatial_metric_der_flux[1][2][2][0], conformal_spatial_metric_der_flux[1][2][2][1], conformal_spatial_metric_der_flux[1][2][2][2], - conformal_lapse_der_flux[1][0], conformal_lapse_der_flux[1][1], conformal_lapse_der_flux[1][2], - conformal_aux_vect_flux[1][0], conformal_aux_vect_flux[1][1], conformal_aux_vect_flux[1][2] }, - { conformal_extrinsic_curvature_flux[2][0][0], conformal_extrinsic_curvature_flux[2][0][1], conformal_extrinsic_curvature_flux[2][0][2], - conformal_extrinsic_curvature_flux[2][1][0], conformal_extrinsic_curvature_flux[2][1][1], conformal_extrinsic_curvature_flux[2][1][2], - conformal_extrinsic_curvature_flux[2][2][0], conformal_extrinsic_curvature_flux[2][2][1], conformal_extrinsic_curvature_flux[2][2][2], - conformal_spatial_metric_der_flux[2][0][0][0], conformal_spatial_metric_der_flux[2][0][0][1], conformal_spatial_metric_der_flux[2][0][0][2], - conformal_spatial_metric_der_flux[2][0][1][0], conformal_spatial_metric_der_flux[2][0][1][1], conformal_spatial_metric_der_flux[2][0][1][2], - conformal_spatial_metric_der_flux[2][0][2][0], conformal_spatial_metric_der_flux[2][0][2][1], conformal_spatial_metric_der_flux[2][0][2][2], - conformal_spatial_metric_der_flux[2][1][0][0], conformal_spatial_metric_der_flux[2][1][0][1], conformal_spatial_metric_der_flux[2][1][0][2], - conformal_spatial_metric_der_flux[2][1][1][0], conformal_spatial_metric_der_flux[2][1][1][1], conformal_spatial_metric_der_flux[2][1][1][2], - conformal_spatial_metric_der_flux[2][1][2][0], conformal_spatial_metric_der_flux[2][1][2][1], conformal_spatial_metric_der_flux[2][1][2][2], - conformal_spatial_metric_der_flux[2][2][0][0], conformal_spatial_metric_der_flux[2][2][0][1], conformal_spatial_metric_der_flux[2][2][0][2], - conformal_spatial_metric_der_flux[2][2][1][0], conformal_spatial_metric_der_flux[2][2][1][1], conformal_spatial_metric_der_flux[2][2][1][2], - conformal_spatial_metric_der_flux[2][2][2][0], conformal_spatial_metric_der_flux[2][2][2][1], conformal_spatial_metric_der_flux[2][2][2][2], - conformal_lapse_der_flux[2][0], conformal_lapse_der_flux[2][1], conformal_lapse_der_flux[2][2], - conformal_aux_vect_flux[2][0], conformal_aux_vect_flux[2][1], conformal_aux_vect_flux[2][2] }, + {conformal_extrinsic_curvature_flux[0][0][0], + conformal_extrinsic_curvature_flux[0][0][1], + conformal_extrinsic_curvature_flux[0][0][2], + conformal_extrinsic_curvature_flux[0][1][0], + conformal_extrinsic_curvature_flux[0][1][1], + conformal_extrinsic_curvature_flux[0][1][2], + conformal_extrinsic_curvature_flux[0][2][0], + conformal_extrinsic_curvature_flux[0][2][1], + conformal_extrinsic_curvature_flux[0][2][2], + conformal_spatial_metric_der_flux[0][0][0][0], + conformal_spatial_metric_der_flux[0][0][0][1], + conformal_spatial_metric_der_flux[0][0][0][2], + conformal_spatial_metric_der_flux[0][0][1][0], + conformal_spatial_metric_der_flux[0][0][1][1], + conformal_spatial_metric_der_flux[0][0][1][2], + conformal_spatial_metric_der_flux[0][0][2][0], + conformal_spatial_metric_der_flux[0][0][2][1], + conformal_spatial_metric_der_flux[0][0][2][2], + conformal_spatial_metric_der_flux[0][1][0][0], + conformal_spatial_metric_der_flux[0][1][0][1], + conformal_spatial_metric_der_flux[0][1][0][2], + conformal_spatial_metric_der_flux[0][1][1][0], + conformal_spatial_metric_der_flux[0][1][1][1], + conformal_spatial_metric_der_flux[0][1][1][2], + conformal_spatial_metric_der_flux[0][1][2][0], + conformal_spatial_metric_der_flux[0][1][2][1], + conformal_spatial_metric_der_flux[0][1][2][2], + conformal_spatial_metric_der_flux[0][2][0][0], + conformal_spatial_metric_der_flux[0][2][0][1], + conformal_spatial_metric_der_flux[0][2][0][2], + conformal_spatial_metric_der_flux[0][2][1][0], + conformal_spatial_metric_der_flux[0][2][1][1], + conformal_spatial_metric_der_flux[0][2][1][2], + conformal_spatial_metric_der_flux[0][2][2][0], + conformal_spatial_metric_der_flux[0][2][2][1], + conformal_spatial_metric_der_flux[0][2][2][2], + conformal_lapse_der_flux[0][0], + conformal_lapse_der_flux[0][1], + conformal_lapse_der_flux[0][2], + conformal_aux_vect_flux[0][0], + conformal_aux_vect_flux[0][1], + conformal_aux_vect_flux[0][2]}, + {conformal_extrinsic_curvature_flux[1][0][0], + conformal_extrinsic_curvature_flux[1][0][1], + conformal_extrinsic_curvature_flux[1][0][2], + conformal_extrinsic_curvature_flux[1][1][0], + conformal_extrinsic_curvature_flux[1][1][1], + conformal_extrinsic_curvature_flux[1][1][2], + conformal_extrinsic_curvature_flux[1][2][0], + conformal_extrinsic_curvature_flux[1][2][1], + conformal_extrinsic_curvature_flux[1][2][2], + conformal_spatial_metric_der_flux[1][0][0][0], + conformal_spatial_metric_der_flux[1][0][0][1], + conformal_spatial_metric_der_flux[1][0][0][2], + conformal_spatial_metric_der_flux[1][0][1][0], + conformal_spatial_metric_der_flux[1][0][1][1], + conformal_spatial_metric_der_flux[1][0][1][2], + conformal_spatial_metric_der_flux[1][0][2][0], + conformal_spatial_metric_der_flux[1][0][2][1], + conformal_spatial_metric_der_flux[1][0][2][2], + conformal_spatial_metric_der_flux[1][1][0][0], + conformal_spatial_metric_der_flux[1][1][0][1], + conformal_spatial_metric_der_flux[1][1][0][2], + conformal_spatial_metric_der_flux[1][1][1][0], + conformal_spatial_metric_der_flux[1][1][1][1], + conformal_spatial_metric_der_flux[1][1][1][2], + conformal_spatial_metric_der_flux[1][1][2][0], + conformal_spatial_metric_der_flux[1][1][2][1], + conformal_spatial_metric_der_flux[1][1][2][2], + conformal_spatial_metric_der_flux[1][2][0][0], + conformal_spatial_metric_der_flux[1][2][0][1], + conformal_spatial_metric_der_flux[1][2][0][2], + conformal_spatial_metric_der_flux[1][2][1][0], + conformal_spatial_metric_der_flux[1][2][1][1], + conformal_spatial_metric_der_flux[1][2][1][2], + conformal_spatial_metric_der_flux[1][2][2][0], + conformal_spatial_metric_der_flux[1][2][2][1], + conformal_spatial_metric_der_flux[1][2][2][2], + conformal_lapse_der_flux[1][0], + conformal_lapse_der_flux[1][1], + conformal_lapse_der_flux[1][2], + conformal_aux_vect_flux[1][0], + conformal_aux_vect_flux[1][1], + conformal_aux_vect_flux[1][2]}, + {conformal_extrinsic_curvature_flux[2][0][0], + conformal_extrinsic_curvature_flux[2][0][1], + conformal_extrinsic_curvature_flux[2][0][2], + conformal_extrinsic_curvature_flux[2][1][0], + conformal_extrinsic_curvature_flux[2][1][1], + conformal_extrinsic_curvature_flux[2][1][2], + conformal_extrinsic_curvature_flux[2][2][0], + conformal_extrinsic_curvature_flux[2][2][1], + conformal_extrinsic_curvature_flux[2][2][2], + conformal_spatial_metric_der_flux[2][0][0][0], + conformal_spatial_metric_der_flux[2][0][0][1], + conformal_spatial_metric_der_flux[2][0][0][2], + conformal_spatial_metric_der_flux[2][0][1][0], + conformal_spatial_metric_der_flux[2][0][1][1], + conformal_spatial_metric_der_flux[2][0][1][2], + conformal_spatial_metric_der_flux[2][0][2][0], + conformal_spatial_metric_der_flux[2][0][2][1], + conformal_spatial_metric_der_flux[2][0][2][2], + conformal_spatial_metric_der_flux[2][1][0][0], + conformal_spatial_metric_der_flux[2][1][0][1], + conformal_spatial_metric_der_flux[2][1][0][2], + conformal_spatial_metric_der_flux[2][1][1][0], + conformal_spatial_metric_der_flux[2][1][1][1], + conformal_spatial_metric_der_flux[2][1][1][2], + conformal_spatial_metric_der_flux[2][1][2][0], + conformal_spatial_metric_der_flux[2][1][2][1], + conformal_spatial_metric_der_flux[2][1][2][2], + conformal_spatial_metric_der_flux[2][2][0][0], + conformal_spatial_metric_der_flux[2][2][0][1], + conformal_spatial_metric_der_flux[2][2][0][2], + conformal_spatial_metric_der_flux[2][2][1][0], + conformal_spatial_metric_der_flux[2][2][1][1], + conformal_spatial_metric_der_flux[2][2][1][2], + conformal_spatial_metric_der_flux[2][2][2][0], + conformal_spatial_metric_der_flux[2][2][2][1], + conformal_spatial_metric_der_flux[2][2][2][2], + conformal_lapse_der_flux[2][0], + conformal_lapse_der_flux[2][1], + conformal_lapse_der_flux[2][2], + conformal_aux_vect_flux[2][0], + conformal_aux_vect_flux[2][1], + conformal_aux_vect_flux[2][2]} }; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; double q_local[77], flux_local[77], flux[77]; for (int d = 0; d < 3; d++) { - vacuum_einstein_conformal->rotate_to_local_func(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], q, q_local); - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, q_local, flux_local); - vacuum_einstein_conformal->rotate_to_global_func(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], flux_local, flux); + vacuum_einstein_conformal->rotate_to_local_func( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], q, q_local + ); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, q_local, flux_local + ); + vacuum_einstein_conformal->rotate_to_global_func( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], flux_local, flux + ); for (int i = 0; i < 42; i++) { - TEST_CHECK( gkyl_compare(flux[i + 10], fluxes[d][i], 1e-6) ); + TEST_CHECK(gkyl_compare(flux[i + 10], fluxes[d][i], 1e-6)); } } - + double q_l[77], q_g[77]; for (int d = 0; d < 3; d++) { gkyl_wv_eqn_rotate_to_local(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], q, q_l); - gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], q_l, q_g); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], q_l, q_g + ); for (int i = 0; i < 77; i++) { - TEST_CHECK( gkyl_compare(q[i], q_g[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q[i], q_g[i], 1e-16)); } double w1[77], q1[77]; @@ -842,7 +1207,7 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() vacuum_einstein_conformal->riem_to_cons(vacuum_einstein_conformal, q_local, w1, q1); for (int i = 0; i < 77; i++) { - TEST_CHECK( gkyl_compare(q_local[i], q1[i], 1e-16) ); + TEST_CHECK(gkyl_compare(q_local[i], q1[i], 1e-16)); } } } @@ -852,7 +1217,7 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() gkyl_free(inv_conformal_spatial_metric[i]); gkyl_free(conformal_extrinsic_curvature[i]); gkyl_free(conformal_shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(conformal_spatial_metric_der[i][j]); } @@ -876,14 +1241,15 @@ test_vacuum_einstein_conformal_basic_schwarzschild_ho() gkyl_gr_spacetime_release(spacetime); } -void -test_vacuum_einstein_conformal_waves_schwarzschild_ho() +void test_vacuum_einstein_conformal_waves_schwarzschild_ho() { double excision_threshold = 0.3; enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.0, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); + struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new( + excision_threshold, spacetime_slicing, spacetime_evolution, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -896,10 +1262,10 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() double *conformal_shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **conformal_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **conformal_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **inv_conformal_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **inv_conformal_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **conformal_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **conformal_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **inv_conformal_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **inv_conformal_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); conformal_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -907,8 +1273,8 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() inv_conformal_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } - double **conformal_extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **conformal_extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **conformal_extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **conformal_extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_extrinsic_curvature_l[i] = gkyl_malloc(sizeof(double[3])); conformal_extrinsic_curvature_r[i] = gkyl_malloc(sizeof(double[3])); @@ -916,18 +1282,18 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() double *conformal_lapse_der_l = gkyl_malloc(sizeof(double[3])); double *conformal_lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **conformal_shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **conformal_shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **conformal_shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **conformal_shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_shift_der_l[i] = gkyl_malloc(sizeof(double[3])); conformal_shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***conformal_spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***conformal_spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***conformal_spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***conformal_spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - conformal_spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - conformal_spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + conformal_spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + conformal_spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { conformal_spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -941,8 +1307,8 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() double *conformal_fact_der_r = gkyl_malloc(sizeof(double[3])); double *bssn_conformal_fact_der_l = gkyl_malloc(sizeof(double[3])); double *bssn_conformal_fact_der_r = gkyl_malloc(sizeof(double[3])); - double **bssn_conformal_fact_der2_l = gkyl_malloc(sizeof(double*[3])); - double **bssn_conformal_fact_der2_r = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_fact_der2_l = gkyl_malloc(sizeof(double *[3])); + double **bssn_conformal_fact_der2_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_fact_der2_l[i] = gkyl_malloc(sizeof(double[3])); bssn_conformal_fact_der2_r[i] = gkyl_malloc(sizeof(double[3])); @@ -957,31 +1323,67 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() spacetime->excision_region_func(spacetime, 0.0, x - 0.1, y, 0.0, &in_excision_region_l); spacetime->excision_region_func(spacetime, 0.0, x + 0.1, y, 0.0, &in_excision_region_r); - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &conformal_spatial_metric_l); - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &conformal_spatial_metric_r); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &inv_conformal_spatial_metric_l); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &inv_conformal_spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_extrinsic_curvature_r); + spacetime->spatial_metric_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, &conformal_spatial_metric_l + ); + spacetime->spatial_metric_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, &conformal_spatial_metric_r + ); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, &inv_conformal_spatial_metric_l + ); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, &inv_conformal_spatial_metric_r + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_extrinsic_curvature_r + ); spacetime->conformal_factor_func(spacetime, 0.0, x - 0.1, y, 0.0, &conformal_fact_l); spacetime->conformal_factor_func(spacetime, 0.0, x + 0.1, y, 0.0, &conformal_fact_r); spacetime->bssn_conformal_factor_func(spacetime, 0.0, x - 0.1, y, 0.0, &bssn_conformal_fact_l); spacetime->bssn_conformal_factor_func(spacetime, 0.0, x + 0.1, y, 0.0, &bssn_conformal_fact_r); - spacetime->conformal_factor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_fact_der_l); - spacetime->conformal_factor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_fact_der_r); - spacetime->bssn_conformal_factor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der_l); - spacetime->bssn_conformal_factor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der_r); - spacetime->bssn_conformal_factor_der2_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der2_l); - spacetime->bssn_conformal_factor_der2_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der2_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_spatial_metric_der_r); + spacetime->conformal_factor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_fact_der_l + ); + spacetime->conformal_factor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_fact_der_r + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der_l + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der_r + ); + spacetime->bssn_conformal_factor_der2_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der2_l + ); + spacetime->bssn_conformal_factor_der2_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der2_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_spatial_metric_der_r + ); for (int i = 0; i < 3; i++) { conformal_fact_der_l[i] /= conformal_fact_l; @@ -1003,10 +1405,14 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_spatial_metric_l[i][j] /= (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); - conformal_spatial_metric_r[i][j] /= (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); - inv_conformal_spatial_metric_l[i][j] *= (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); - inv_conformal_spatial_metric_r[i][j] *= (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); + conformal_spatial_metric_l[i][j] /= + (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); + conformal_spatial_metric_r[i][j] /= + (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); + inv_conformal_spatial_metric_l[i][j] *= + (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); + inv_conformal_spatial_metric_r[i][j] *= + (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); } } @@ -1015,10 +1421,14 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_l[i][j][k] = 0.5 * conformal_spatial_metric_der_l[i][j][k]; conformal_spatial_metric_der_r[i][j][k] = 0.5 * conformal_spatial_metric_der_r[i][j][k]; - conformal_spatial_metric_der_l[i][j][k] /= (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); - conformal_spatial_metric_der_r[i][j][k] /= (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); - conformal_spatial_metric_der_l[i][j][k] -= 2.0 * conformal_fact_der_l[i] * conformal_spatial_metric_l[j][k]; - conformal_spatial_metric_der_r[i][j][k] -= 2.0 * conformal_fact_der_r[i] * conformal_spatial_metric_r[j][k]; + conformal_spatial_metric_der_l[i][j][k] /= + (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); + conformal_spatial_metric_der_r[i][j][k] /= + (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); + conformal_spatial_metric_der_l[i][j][k] -= + 2.0 * conformal_fact_der_l[i] * conformal_spatial_metric_l[j][k]; + conformal_spatial_metric_der_r[i][j][k] -= + 2.0 * conformal_fact_der_r[i] * conformal_spatial_metric_r[j][k]; } conformal_shift_der_l[i][j] = 0.5 * conformal_shift_der_l[i][j]; @@ -1035,8 +1445,10 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() double conformal_extrinsic_curvature_trace_r = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_extrinsic_curvature_trace_l += inv_conformal_spatial_metric_l[i][j] * conformal_extrinsic_curvature_l[i][j]; - conformal_extrinsic_curvature_trace_r += inv_conformal_spatial_metric_r[i][j] * conformal_extrinsic_curvature_r[i][j]; + conformal_extrinsic_curvature_trace_l += + inv_conformal_spatial_metric_l[i][j] * conformal_extrinsic_curvature_l[i][j]; + conformal_extrinsic_curvature_trace_r += + inv_conformal_spatial_metric_r[i][j] * conformal_extrinsic_curvature_r[i][j]; } } @@ -1047,15 +1459,17 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1_l[k][i][j] = 0.0; conformal_spatial_metric_der_raised1_r[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1_l[k][i][j] += inv_conformal_spatial_metric_l[k][l] * conformal_spatial_metric_der_l[l][i][j]; - conformal_spatial_metric_der_raised1_r[k][i][j] += inv_conformal_spatial_metric_r[k][l] * conformal_spatial_metric_der_r[l][i][j]; + conformal_spatial_metric_der_raised1_l[k][i][j] += + inv_conformal_spatial_metric_l[k][l] * conformal_spatial_metric_der_l[l][i][j]; + conformal_spatial_metric_der_raised1_r[k][i][j] += + inv_conformal_spatial_metric_r[k][l] * conformal_spatial_metric_der_r[l][i][j]; } } } } - + double conformal_spatial_metric_der_raised3_l[3][3][3]; double conformal_spatial_metric_der_raised3_r[3][3][3]; for (int i = 0; i < 3; i++) { @@ -1065,8 +1479,10 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() conformal_spatial_metric_der_raised3_r[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3_l[i][j][k] += inv_conformal_spatial_metric_l[l][k] * conformal_spatial_metric_der_l[i][j][l]; - conformal_spatial_metric_der_raised3_r[i][j][k] += inv_conformal_spatial_metric_r[l][k] * conformal_spatial_metric_der_r[i][j][l]; + conformal_spatial_metric_der_raised3_l[i][j][k] += + inv_conformal_spatial_metric_l[l][k] * conformal_spatial_metric_der_l[i][j][l]; + conformal_spatial_metric_der_raised3_r[i][j][k] += + inv_conformal_spatial_metric_r[l][k] * conformal_spatial_metric_der_r[i][j][l]; } } } @@ -1097,8 +1513,10 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() conformal_aux_vect_raised_r[k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_aux_vect_raised_l[k] += inv_conformal_spatial_metric_l[k][l] * conformal_aux_vect_l[l]; - conformal_aux_vect_raised_r[k] += inv_conformal_spatial_metric_r[k][l] * conformal_aux_vect_r[l]; + conformal_aux_vect_raised_l[k] += + inv_conformal_spatial_metric_l[k][l] * conformal_aux_vect_l[l]; + conformal_aux_vect_raised_r[k] += + inv_conformal_spatial_metric_r[k][l] * conformal_aux_vect_r[l]; } } @@ -1110,8 +1528,10 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() conformal_shift_der_lowered_r[i][j] = 0.0; for (int k = 0; k < 3; k++) { - conformal_shift_der_lowered_l[i][j] += conformal_spatial_metric_l[k][j] * conformal_shift_der_l[i][k]; - conformal_shift_der_lowered_r[i][j] += conformal_spatial_metric_r[k][j] * conformal_shift_der_r[i][k]; + conformal_shift_der_lowered_l[i][j] += + conformal_spatial_metric_l[k][j] * conformal_shift_der_l[i][k]; + conformal_shift_der_lowered_r[i][j] += + conformal_spatial_metric_r[k][j] * conformal_shift_der_r[i][k]; } } } @@ -1125,8 +1545,12 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_shift_der_switched_l[i][k] += inv_conformal_spatial_metric_l[i][l] * conformal_spatial_metric_l[m][k] * conformal_shift_der_l[l][m]; - conformal_shift_der_switched_r[i][k] += inv_conformal_spatial_metric_r[i][l] * conformal_spatial_metric_r[m][k] * conformal_shift_der_r[l][m]; + conformal_shift_der_switched_l[i][k] += inv_conformal_spatial_metric_l[i][l] * + conformal_spatial_metric_l[m][k] * + conformal_shift_der_l[l][m]; + conformal_shift_der_switched_r[i][k] += inv_conformal_spatial_metric_r[i][l] * + conformal_spatial_metric_r[m][k] * + conformal_shift_der_r[l][m]; } } } @@ -1136,150 +1560,267 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() double symmetrized_conformal_shift_r[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - symmetrized_conformal_shift_l[i][j] = (1.0 / conformal_lapse_l) * (conformal_shift_der_lowered_l[i][j] + conformal_shift_der_lowered_l[j][i]); - symmetrized_conformal_shift_r[i][j] = (1.0 / conformal_lapse_r) * (conformal_shift_der_lowered_r[i][j] + conformal_shift_der_lowered_r[j][i]); + symmetrized_conformal_shift_l[i][j] = + (1.0 / conformal_lapse_l) * + (conformal_shift_der_lowered_l[i][j] + conformal_shift_der_lowered_l[j][i]); + symmetrized_conformal_shift_r[i][j] = + (1.0 / conformal_lapse_r) * + (conformal_shift_der_lowered_r[i][j] + conformal_shift_der_lowered_r[j][i]); } } if (!in_excision_region_l && !in_excision_region_r) { double ql[77], qr[77]; - ql[0] = conformal_spatial_metric_l[0][0]; ql[1] = conformal_spatial_metric_l[0][1]; ql[2] = conformal_spatial_metric_l[0][2]; - ql[3] = conformal_spatial_metric_l[1][0]; ql[4] = conformal_spatial_metric_l[1][1]; ql[5] = conformal_spatial_metric_l[1][2]; - ql[6] = conformal_spatial_metric_l[2][0]; ql[7] = conformal_spatial_metric_l[2][1]; ql[8] = conformal_spatial_metric_l[2][2]; + ql[0] = conformal_spatial_metric_l[0][0]; + ql[1] = conformal_spatial_metric_l[0][1]; + ql[2] = conformal_spatial_metric_l[0][2]; + ql[3] = conformal_spatial_metric_l[1][0]; + ql[4] = conformal_spatial_metric_l[1][1]; + ql[5] = conformal_spatial_metric_l[1][2]; + ql[6] = conformal_spatial_metric_l[2][0]; + ql[7] = conformal_spatial_metric_l[2][1]; + ql[8] = conformal_spatial_metric_l[2][2]; ql[9] = conformal_lapse_l; - ql[10] = conformal_extrinsic_curvature_l[0][0]; ql[11] = conformal_extrinsic_curvature_l[0][1]; ql[12] = conformal_extrinsic_curvature_l[0][2]; - ql[13] = conformal_extrinsic_curvature_l[1][0]; ql[14] = conformal_extrinsic_curvature_l[1][1]; ql[15] = conformal_extrinsic_curvature_l[1][2]; - ql[16] = conformal_extrinsic_curvature_l[2][0]; ql[17] = conformal_extrinsic_curvature_l[2][1]; ql[18] = conformal_extrinsic_curvature_l[2][2]; - - ql[19] = conformal_spatial_metric_der_l[0][0][0]; ql[20] = conformal_spatial_metric_der_l[0][0][1]; ql[21] = conformal_spatial_metric_der_l[0][0][2]; - ql[22] = conformal_spatial_metric_der_l[0][1][0]; ql[23] = conformal_spatial_metric_der_l[0][1][1]; ql[24] = conformal_spatial_metric_der_l[0][1][2]; - ql[25] = conformal_spatial_metric_der_l[0][2][0]; ql[26] = conformal_spatial_metric_der_l[0][2][1]; ql[27] = conformal_spatial_metric_der_l[0][2][2]; - - ql[28] = conformal_spatial_metric_der_l[1][0][0]; ql[29] = conformal_spatial_metric_der_l[1][0][1]; ql[30] = conformal_spatial_metric_der_l[1][0][2]; - ql[31] = conformal_spatial_metric_der_l[1][1][0]; ql[32] = conformal_spatial_metric_der_l[1][1][1]; ql[33] = conformal_spatial_metric_der_l[1][1][2]; - ql[34] = conformal_spatial_metric_der_l[1][2][0]; ql[35] = conformal_spatial_metric_der_l[1][2][1]; ql[36] = conformal_spatial_metric_der_l[1][2][2]; - - ql[37] = conformal_spatial_metric_der_l[2][0][0]; ql[38] = conformal_spatial_metric_der_l[2][0][1]; ql[39] = conformal_spatial_metric_der_l[2][0][2]; - ql[40] = conformal_spatial_metric_der_l[2][1][0]; ql[41] = conformal_spatial_metric_der_l[2][1][1]; ql[42] = conformal_spatial_metric_der_l[2][1][2]; - ql[43] = conformal_spatial_metric_der_l[2][2][0]; ql[44] = conformal_spatial_metric_der_l[2][2][1]; ql[45] = conformal_spatial_metric_der_l[2][2][2]; - - ql[46] = conformal_lapse_der_l[0]; ql[47] = conformal_lapse_der_l[1]; ql[48] = conformal_lapse_der_l[2]; - - ql[49] = conformal_aux_vect_l[0]; ql[50] = conformal_aux_vect_l[1]; ql[51] = conformal_aux_vect_l[2]; - - ql[52] = conformal_shift_l[0]; ql[53] = conformal_shift_l[1]; ql[54] = conformal_shift_l[2]; - - ql[55] = conformal_shift_der_l[0][0]; ql[56] = conformal_shift_der_l[0][1]; ql[57] = conformal_shift_der_l[0][2]; - ql[58] = conformal_shift_der_l[1][0]; ql[59] = conformal_shift_der_l[1][1]; ql[60] = conformal_shift_der_l[1][2]; - ql[61] = conformal_shift_der_l[2][0]; ql[62] = conformal_shift_der_l[2][1]; ql[63] = conformal_shift_der_l[2][2]; + ql[10] = conformal_extrinsic_curvature_l[0][0]; + ql[11] = conformal_extrinsic_curvature_l[0][1]; + ql[12] = conformal_extrinsic_curvature_l[0][2]; + ql[13] = conformal_extrinsic_curvature_l[1][0]; + ql[14] = conformal_extrinsic_curvature_l[1][1]; + ql[15] = conformal_extrinsic_curvature_l[1][2]; + ql[16] = conformal_extrinsic_curvature_l[2][0]; + ql[17] = conformal_extrinsic_curvature_l[2][1]; + ql[18] = conformal_extrinsic_curvature_l[2][2]; + + ql[19] = conformal_spatial_metric_der_l[0][0][0]; + ql[20] = conformal_spatial_metric_der_l[0][0][1]; + ql[21] = conformal_spatial_metric_der_l[0][0][2]; + ql[22] = conformal_spatial_metric_der_l[0][1][0]; + ql[23] = conformal_spatial_metric_der_l[0][1][1]; + ql[24] = conformal_spatial_metric_der_l[0][1][2]; + ql[25] = conformal_spatial_metric_der_l[0][2][0]; + ql[26] = conformal_spatial_metric_der_l[0][2][1]; + ql[27] = conformal_spatial_metric_der_l[0][2][2]; + + ql[28] = conformal_spatial_metric_der_l[1][0][0]; + ql[29] = conformal_spatial_metric_der_l[1][0][1]; + ql[30] = conformal_spatial_metric_der_l[1][0][2]; + ql[31] = conformal_spatial_metric_der_l[1][1][0]; + ql[32] = conformal_spatial_metric_der_l[1][1][1]; + ql[33] = conformal_spatial_metric_der_l[1][1][2]; + ql[34] = conformal_spatial_metric_der_l[1][2][0]; + ql[35] = conformal_spatial_metric_der_l[1][2][1]; + ql[36] = conformal_spatial_metric_der_l[1][2][2]; + + ql[37] = conformal_spatial_metric_der_l[2][0][0]; + ql[38] = conformal_spatial_metric_der_l[2][0][1]; + ql[39] = conformal_spatial_metric_der_l[2][0][2]; + ql[40] = conformal_spatial_metric_der_l[2][1][0]; + ql[41] = conformal_spatial_metric_der_l[2][1][1]; + ql[42] = conformal_spatial_metric_der_l[2][1][2]; + ql[43] = conformal_spatial_metric_der_l[2][2][0]; + ql[44] = conformal_spatial_metric_der_l[2][2][1]; + ql[45] = conformal_spatial_metric_der_l[2][2][2]; + + ql[46] = conformal_lapse_der_l[0]; + ql[47] = conformal_lapse_der_l[1]; + ql[48] = conformal_lapse_der_l[2]; + + ql[49] = conformal_aux_vect_l[0]; + ql[50] = conformal_aux_vect_l[1]; + ql[51] = conformal_aux_vect_l[2]; + + ql[52] = conformal_shift_l[0]; + ql[53] = conformal_shift_l[1]; + ql[54] = conformal_shift_l[2]; + + ql[55] = conformal_shift_der_l[0][0]; + ql[56] = conformal_shift_der_l[0][1]; + ql[57] = conformal_shift_der_l[0][2]; + ql[58] = conformal_shift_der_l[1][0]; + ql[59] = conformal_shift_der_l[1][1]; + ql[60] = conformal_shift_der_l[1][2]; + ql[61] = conformal_shift_der_l[2][0]; + ql[62] = conformal_shift_der_l[2][1]; + ql[63] = conformal_shift_der_l[2][2]; ql[64] = bssn_conformal_fact_l; - ql[65] = bssn_conformal_fact_der_l[0]; ql[66] = bssn_conformal_fact_der_l[1]; ql[67] = bssn_conformal_fact_der_l[2]; - - ql[68] = bssn_conformal_fact_der2_l[0][0]; ql[69] = bssn_conformal_fact_der2_l[0][1]; ql[70] = bssn_conformal_fact_der2_l[0][2]; - ql[71] = bssn_conformal_fact_der2_l[1][0]; ql[72] = bssn_conformal_fact_der2_l[1][1]; ql[73] = bssn_conformal_fact_der2_l[1][2]; - ql[74] = bssn_conformal_fact_der2_l[2][0]; ql[75] = bssn_conformal_fact_der2_l[2][1]; ql[76] = bssn_conformal_fact_der2_l[2][2]; - - qr[0] = conformal_spatial_metric_r[0][0]; qr[1] = conformal_spatial_metric_r[0][1]; qr[2] = conformal_spatial_metric_r[0][2]; - qr[3] = conformal_spatial_metric_r[1][0]; qr[4] = conformal_spatial_metric_r[1][1]; qr[5] = conformal_spatial_metric_r[1][2]; - qr[6] = conformal_spatial_metric_r[2][0]; qr[7] = conformal_spatial_metric_r[2][1]; qr[8] = conformal_spatial_metric_r[2][2]; + ql[65] = bssn_conformal_fact_der_l[0]; + ql[66] = bssn_conformal_fact_der_l[1]; + ql[67] = bssn_conformal_fact_der_l[2]; + + ql[68] = bssn_conformal_fact_der2_l[0][0]; + ql[69] = bssn_conformal_fact_der2_l[0][1]; + ql[70] = bssn_conformal_fact_der2_l[0][2]; + ql[71] = bssn_conformal_fact_der2_l[1][0]; + ql[72] = bssn_conformal_fact_der2_l[1][1]; + ql[73] = bssn_conformal_fact_der2_l[1][2]; + ql[74] = bssn_conformal_fact_der2_l[2][0]; + ql[75] = bssn_conformal_fact_der2_l[2][1]; + ql[76] = bssn_conformal_fact_der2_l[2][2]; + + qr[0] = conformal_spatial_metric_r[0][0]; + qr[1] = conformal_spatial_metric_r[0][1]; + qr[2] = conformal_spatial_metric_r[0][2]; + qr[3] = conformal_spatial_metric_r[1][0]; + qr[4] = conformal_spatial_metric_r[1][1]; + qr[5] = conformal_spatial_metric_r[1][2]; + qr[6] = conformal_spatial_metric_r[2][0]; + qr[7] = conformal_spatial_metric_r[2][1]; + qr[8] = conformal_spatial_metric_r[2][2]; qr[9] = conformal_lapse_r; - qr[10] = conformal_extrinsic_curvature_r[0][0]; qr[11] = conformal_extrinsic_curvature_r[0][1]; qr[12] = conformal_extrinsic_curvature_r[0][2]; - qr[13] = conformal_extrinsic_curvature_r[1][0]; qr[14] = conformal_extrinsic_curvature_r[1][1]; qr[15] = conformal_extrinsic_curvature_r[1][2]; - qr[16] = conformal_extrinsic_curvature_r[2][0]; qr[17] = conformal_extrinsic_curvature_r[2][1]; qr[18] = conformal_extrinsic_curvature_r[2][2]; - - qr[19] = conformal_spatial_metric_der_r[0][0][0]; qr[20] = conformal_spatial_metric_der_r[0][0][1]; qr[21] = conformal_spatial_metric_der_r[0][0][2]; - qr[22] = conformal_spatial_metric_der_r[0][1][0]; qr[23] = conformal_spatial_metric_der_r[0][1][1]; qr[24] = conformal_spatial_metric_der_r[0][1][2]; - qr[25] = conformal_spatial_metric_der_r[0][2][0]; qr[26] = conformal_spatial_metric_der_r[0][2][1]; qr[27] = conformal_spatial_metric_der_r[0][2][2]; - - qr[28] = conformal_spatial_metric_der_r[1][0][0]; qr[29] = conformal_spatial_metric_der_r[1][0][1]; qr[30] = conformal_spatial_metric_der_r[1][0][2]; - qr[31] = conformal_spatial_metric_der_r[1][1][0]; qr[32] = conformal_spatial_metric_der_r[1][1][1]; qr[33] = conformal_spatial_metric_der_r[1][1][2]; - qr[34] = conformal_spatial_metric_der_r[1][2][0]; qr[35] = conformal_spatial_metric_der_r[1][2][1]; qr[36] = conformal_spatial_metric_der_r[1][2][2]; - - qr[37] = conformal_spatial_metric_der_r[2][0][0]; qr[38] = conformal_spatial_metric_der_r[2][0][1]; qr[39] = conformal_spatial_metric_der_r[2][0][2]; - qr[40] = conformal_spatial_metric_der_r[2][1][0]; qr[41] = conformal_spatial_metric_der_r[2][1][1]; qr[42] = conformal_spatial_metric_der_r[2][1][2]; - qr[43] = conformal_spatial_metric_der_r[2][2][0]; qr[44] = conformal_spatial_metric_der_r[2][2][1]; qr[45] = conformal_spatial_metric_der_r[2][2][2]; - - qr[46] = conformal_lapse_der_r[0]; qr[47] = conformal_lapse_der_r[1]; qr[48] = conformal_lapse_der_r[2]; - - qr[49] = conformal_aux_vect_r[0]; qr[50] = conformal_aux_vect_r[1]; qr[51] = conformal_aux_vect_r[2]; - - qr[52] = conformal_shift_r[0]; qr[53] = conformal_shift_r[1]; qr[54] = conformal_shift_r[2]; - - qr[55] = conformal_shift_der_r[0][0]; qr[56] = conformal_shift_der_r[0][1]; qr[57] = conformal_shift_der_r[0][2]; - qr[58] = conformal_shift_der_r[1][0]; qr[59] = conformal_shift_der_r[1][1]; qr[60] = conformal_shift_der_r[1][2]; - qr[61] = conformal_shift_der_r[2][0]; qr[62] = conformal_shift_der_r[2][1]; qr[63] = conformal_shift_der_r[2][2]; + qr[10] = conformal_extrinsic_curvature_r[0][0]; + qr[11] = conformal_extrinsic_curvature_r[0][1]; + qr[12] = conformal_extrinsic_curvature_r[0][2]; + qr[13] = conformal_extrinsic_curvature_r[1][0]; + qr[14] = conformal_extrinsic_curvature_r[1][1]; + qr[15] = conformal_extrinsic_curvature_r[1][2]; + qr[16] = conformal_extrinsic_curvature_r[2][0]; + qr[17] = conformal_extrinsic_curvature_r[2][1]; + qr[18] = conformal_extrinsic_curvature_r[2][2]; + + qr[19] = conformal_spatial_metric_der_r[0][0][0]; + qr[20] = conformal_spatial_metric_der_r[0][0][1]; + qr[21] = conformal_spatial_metric_der_r[0][0][2]; + qr[22] = conformal_spatial_metric_der_r[0][1][0]; + qr[23] = conformal_spatial_metric_der_r[0][1][1]; + qr[24] = conformal_spatial_metric_der_r[0][1][2]; + qr[25] = conformal_spatial_metric_der_r[0][2][0]; + qr[26] = conformal_spatial_metric_der_r[0][2][1]; + qr[27] = conformal_spatial_metric_der_r[0][2][2]; + + qr[28] = conformal_spatial_metric_der_r[1][0][0]; + qr[29] = conformal_spatial_metric_der_r[1][0][1]; + qr[30] = conformal_spatial_metric_der_r[1][0][2]; + qr[31] = conformal_spatial_metric_der_r[1][1][0]; + qr[32] = conformal_spatial_metric_der_r[1][1][1]; + qr[33] = conformal_spatial_metric_der_r[1][1][2]; + qr[34] = conformal_spatial_metric_der_r[1][2][0]; + qr[35] = conformal_spatial_metric_der_r[1][2][1]; + qr[36] = conformal_spatial_metric_der_r[1][2][2]; + + qr[37] = conformal_spatial_metric_der_r[2][0][0]; + qr[38] = conformal_spatial_metric_der_r[2][0][1]; + qr[39] = conformal_spatial_metric_der_r[2][0][2]; + qr[40] = conformal_spatial_metric_der_r[2][1][0]; + qr[41] = conformal_spatial_metric_der_r[2][1][1]; + qr[42] = conformal_spatial_metric_der_r[2][1][2]; + qr[43] = conformal_spatial_metric_der_r[2][2][0]; + qr[44] = conformal_spatial_metric_der_r[2][2][1]; + qr[45] = conformal_spatial_metric_der_r[2][2][2]; + + qr[46] = conformal_lapse_der_r[0]; + qr[47] = conformal_lapse_der_r[1]; + qr[48] = conformal_lapse_der_r[2]; + + qr[49] = conformal_aux_vect_r[0]; + qr[50] = conformal_aux_vect_r[1]; + qr[51] = conformal_aux_vect_r[2]; + + qr[52] = conformal_shift_r[0]; + qr[53] = conformal_shift_r[1]; + qr[54] = conformal_shift_r[2]; + + qr[55] = conformal_shift_der_r[0][0]; + qr[56] = conformal_shift_der_r[0][1]; + qr[57] = conformal_shift_der_r[0][2]; + qr[58] = conformal_shift_der_r[1][0]; + qr[59] = conformal_shift_der_r[1][1]; + qr[60] = conformal_shift_der_r[1][2]; + qr[61] = conformal_shift_der_r[2][0]; + qr[62] = conformal_shift_der_r[2][1]; + qr[63] = conformal_shift_der_r[2][2]; qr[64] = bssn_conformal_fact_r; - qr[65] = bssn_conformal_fact_der_r[0]; qr[66] = bssn_conformal_fact_der_r[1]; qr[67] = bssn_conformal_fact_der_r[2]; + qr[65] = bssn_conformal_fact_der_r[0]; + qr[66] = bssn_conformal_fact_der_r[1]; + qr[67] = bssn_conformal_fact_der_r[2]; - qr[68] = bssn_conformal_fact_der2_r[0][0]; qr[69] = bssn_conformal_fact_der2_r[0][1]; qr[70] = bssn_conformal_fact_der2_r[0][2]; - qr[71] = bssn_conformal_fact_der2_r[1][0]; qr[72] = bssn_conformal_fact_der2_r[1][1]; qr[73] = bssn_conformal_fact_der2_r[1][2]; - qr[74] = bssn_conformal_fact_der2_r[2][0]; qr[75] = bssn_conformal_fact_der2_r[2][1]; qr[76] = bssn_conformal_fact_der2_r[2][2]; + qr[68] = bssn_conformal_fact_der2_r[0][0]; + qr[69] = bssn_conformal_fact_der2_r[0][1]; + qr[70] = bssn_conformal_fact_der2_r[0][2]; + qr[71] = bssn_conformal_fact_der2_r[1][0]; + qr[72] = bssn_conformal_fact_der2_r[1][1]; + qr[73] = bssn_conformal_fact_der2_r[1][2]; + qr[74] = bssn_conformal_fact_der2_r[2][0]; + qr[75] = bssn_conformal_fact_der2_r[2][1]; + qr[76] = bssn_conformal_fact_der2_r[2][2]; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 77], waves_local[2 * 77]; double ql_local[77], qr_local[77]; - gkyl_wv_eqn_rotate_to_local(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], ql, ql_local); - gkyl_wv_eqn_rotate_to_local(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], qr, qr_local); + gkyl_wv_eqn_rotate_to_local( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], ql, ql_local + ); + gkyl_wv_eqn_rotate_to_local( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], qr, qr_local + ); double delta[77]; for (int i = 0; i < 77; i++) { delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(vacuum_einstein_conformal, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + vacuum_einstein_conformal, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[77], amdq_local[77]; - gkyl_wv_eqn_qfluct(vacuum_einstein_conformal, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + vacuum_einstein_conformal, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds, amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], &waves_local[i * 77], &waves[i * 77]); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], &waves_local[i * 77], + &waves[i * 77] + ); } double apdq[77], amdq[77]; - gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); double fl_local[77], fr_local[77]; - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, ql_local, fl_local); - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, qr_local, fr_local); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, ql_local, fl_local + ); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, qr_local, fr_local + ); double fl[77], fr[77]; - gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], fl_local, fl); - gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], fr_local, fr); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], fl_local, fl + ); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], fr_local, fr + ); for (int i = 0; i < 77; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-11) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-11)); } } } - + for (int i = 0; i < 3; i++) { gkyl_free(conformal_spatial_metric_l[i]); gkyl_free(conformal_spatial_metric_r[i]); @@ -1289,7 +1830,7 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() gkyl_free(conformal_extrinsic_curvature_r[i]); gkyl_free(conformal_shift_der_l[i]); gkyl_free(conformal_shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(conformal_spatial_metric_der_l[i][j]); gkyl_free(conformal_spatial_metric_der_r[i][j]); @@ -1315,14 +1856,15 @@ test_vacuum_einstein_conformal_waves_schwarzschild_ho() } } -void -test_vacuum_einstein_conformal_waves_kerr_ho() +void test_vacuum_einstein_conformal_waves_kerr_ho() { double excision_threshold = 0.3; enum gkyl_spacetime_slicing spacetime_slicing = GKYL_1PLUSLOG_SLICING; enum gkyl_spacetime_evolution spacetime_evolution = GKYL_EINSTEIN_EVOLUTION; struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, 0.1, 0.9, 0.0, 0.0, 0.0); - struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new(excision_threshold, spacetime_slicing, spacetime_evolution, false); + struct gkyl_wv_eqn *vacuum_einstein_conformal = gkyl_wv_vacuum_einstein_conformal_new( + excision_threshold, spacetime_slicing, spacetime_evolution, false + ); for (int x_ind = -10; x_ind < 11; x_ind++) { for (int y_ind = -10; y_ind < 11; y_ind++) { @@ -1335,10 +1877,10 @@ test_vacuum_einstein_conformal_waves_kerr_ho() double *conformal_shift_r = gkyl_malloc(sizeof(double[3])); bool in_excision_region_l, in_excision_region_r; - double **conformal_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **conformal_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); - double **inv_conformal_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); - double **inv_conformal_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **conformal_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **conformal_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); + double **inv_conformal_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); + double **inv_conformal_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); conformal_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1346,8 +1888,8 @@ test_vacuum_einstein_conformal_waves_kerr_ho() inv_conformal_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } - double **conformal_extrinsic_curvature_l = gkyl_malloc(sizeof(double*[3])); - double **conformal_extrinsic_curvature_r = gkyl_malloc(sizeof(double*[3])); + double **conformal_extrinsic_curvature_l = gkyl_malloc(sizeof(double *[3])); + double **conformal_extrinsic_curvature_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_extrinsic_curvature_l[i] = gkyl_malloc(sizeof(double[3])); conformal_extrinsic_curvature_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1355,18 +1897,18 @@ test_vacuum_einstein_conformal_waves_kerr_ho() double *conformal_lapse_der_l = gkyl_malloc(sizeof(double[3])); double *conformal_lapse_der_r = gkyl_malloc(sizeof(double[3])); - double **conformal_shift_der_l = gkyl_malloc(sizeof(double*[3])); - double **conformal_shift_der_r = gkyl_malloc(sizeof(double*[3])); + double **conformal_shift_der_l = gkyl_malloc(sizeof(double *[3])); + double **conformal_shift_der_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { conformal_shift_der_l[i] = gkyl_malloc(sizeof(double[3])); conformal_shift_der_r[i] = gkyl_malloc(sizeof(double[3])); } - double ***conformal_spatial_metric_der_l = gkyl_malloc(sizeof(double**[3])); - double ***conformal_spatial_metric_der_r = gkyl_malloc(sizeof(double**[3])); + double ***conformal_spatial_metric_der_l = gkyl_malloc(sizeof(double **[3])); + double ***conformal_spatial_metric_der_r = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - conformal_spatial_metric_der_l[i] = gkyl_malloc(sizeof(double*[3])); - conformal_spatial_metric_der_r[i] = gkyl_malloc(sizeof(double*[3])); + conformal_spatial_metric_der_l[i] = gkyl_malloc(sizeof(double *[3])); + conformal_spatial_metric_der_r[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { conformal_spatial_metric_der_l[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1380,8 +1922,8 @@ test_vacuum_einstein_conformal_waves_kerr_ho() double *conformal_fact_der_r = gkyl_malloc(sizeof(double[3])); double *bssn_conformal_fact_der_l = gkyl_malloc(sizeof(double[3])); double *bssn_conformal_fact_der_r = gkyl_malloc(sizeof(double[3])); - double **bssn_conformal_fact_der2_l = gkyl_malloc(sizeof(double*[3])); - double **bssn_conformal_fact_der2_r = gkyl_malloc(sizeof(double*[3])); + double **bssn_conformal_fact_der2_l = gkyl_malloc(sizeof(double *[3])); + double **bssn_conformal_fact_der2_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { bssn_conformal_fact_der2_l[i] = gkyl_malloc(sizeof(double[3])); bssn_conformal_fact_der2_r[i] = gkyl_malloc(sizeof(double[3])); @@ -1396,31 +1938,67 @@ test_vacuum_einstein_conformal_waves_kerr_ho() spacetime->excision_region_func(spacetime, 0.0, x - 0.1, y, 0.0, &in_excision_region_l); spacetime->excision_region_func(spacetime, 0.0, x + 0.1, y, 0.0, &in_excision_region_r); - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &conformal_spatial_metric_l); - spacetime->spatial_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &conformal_spatial_metric_r); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, &inv_conformal_spatial_metric_l); - spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, &inv_conformal_spatial_metric_r); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_extrinsic_curvature_l); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_extrinsic_curvature_r); + spacetime->spatial_metric_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, &conformal_spatial_metric_l + ); + spacetime->spatial_metric_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, &conformal_spatial_metric_r + ); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, &inv_conformal_spatial_metric_l + ); + spacetime->spatial_inv_metric_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, &inv_conformal_spatial_metric_r + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_extrinsic_curvature_l + ); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_extrinsic_curvature_r + ); spacetime->conformal_factor_func(spacetime, 0.0, x - 0.1, y, 0.0, &conformal_fact_l); spacetime->conformal_factor_func(spacetime, 0.0, x + 0.1, y, 0.0, &conformal_fact_r); spacetime->bssn_conformal_factor_func(spacetime, 0.0, x - 0.1, y, 0.0, &bssn_conformal_fact_l); spacetime->bssn_conformal_factor_func(spacetime, 0.0, x + 0.1, y, 0.0, &bssn_conformal_fact_r); - spacetime->conformal_factor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_fact_der_l); - spacetime->conformal_factor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_fact_der_r); - spacetime->bssn_conformal_factor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der_l); - spacetime->bssn_conformal_factor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der_r); - spacetime->bssn_conformal_factor_der2_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der2_l); - spacetime->bssn_conformal_factor_der2_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der2_r); - - spacetime->lapse_function_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_lapse_der_l); - spacetime->lapse_function_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_lapse_der_r); - spacetime->shift_vector_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_shift_der_l); - spacetime->shift_vector_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_shift_der_r); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_spatial_metric_der_l); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_spatial_metric_der_r); + spacetime->conformal_factor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_fact_der_l + ); + spacetime->conformal_factor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_fact_der_r + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der_l + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der_r + ); + spacetime->bssn_conformal_factor_der2_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der2_l + ); + spacetime->bssn_conformal_factor_der2_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &bssn_conformal_fact_der2_r + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_lapse_der_l + ); + spacetime->lapse_function_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_lapse_der_r + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_shift_der_l + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_shift_der_r + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x - 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_spatial_metric_der_l + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x + 0.1, y, 0.0, 0.1, 0.1, 0.1, &conformal_spatial_metric_der_r + ); for (int i = 0; i < 3; i++) { conformal_fact_der_l[i] /= conformal_fact_l; @@ -1442,10 +2020,14 @@ test_vacuum_einstein_conformal_waves_kerr_ho() for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_spatial_metric_l[i][j] /= (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); - conformal_spatial_metric_r[i][j] /= (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); - inv_conformal_spatial_metric_l[i][j] *= (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); - inv_conformal_spatial_metric_r[i][j] *= (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); + conformal_spatial_metric_l[i][j] /= + (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); + conformal_spatial_metric_r[i][j] /= + (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); + inv_conformal_spatial_metric_l[i][j] *= + (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); + inv_conformal_spatial_metric_r[i][j] *= + (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); } } @@ -1454,10 +2036,14 @@ test_vacuum_einstein_conformal_waves_kerr_ho() for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_l[i][j][k] = 0.5 * conformal_spatial_metric_der_l[i][j][k]; conformal_spatial_metric_der_r[i][j][k] = 0.5 * conformal_spatial_metric_der_r[i][j][k]; - conformal_spatial_metric_der_l[i][j][k] /= (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); - conformal_spatial_metric_der_r[i][j][k] /= (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); - conformal_spatial_metric_der_l[i][j][k] -= 2.0 * conformal_fact_der_l[i] * conformal_spatial_metric_l[j][k]; - conformal_spatial_metric_der_r[i][j][k] -= 2.0 * conformal_fact_der_r[i] * conformal_spatial_metric_r[j][k]; + conformal_spatial_metric_der_l[i][j][k] /= + (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); + conformal_spatial_metric_der_r[i][j][k] /= + (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); + conformal_spatial_metric_der_l[i][j][k] -= + 2.0 * conformal_fact_der_l[i] * conformal_spatial_metric_l[j][k]; + conformal_spatial_metric_der_r[i][j][k] -= + 2.0 * conformal_fact_der_r[i] * conformal_spatial_metric_r[j][k]; } conformal_shift_der_l[i][j] = 0.5 * conformal_shift_der_l[i][j]; @@ -1474,8 +2060,10 @@ test_vacuum_einstein_conformal_waves_kerr_ho() double conformal_extrinsic_curvature_trace_r = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_extrinsic_curvature_trace_l += inv_conformal_spatial_metric_l[i][j] * conformal_extrinsic_curvature_l[i][j]; - conformal_extrinsic_curvature_trace_r += inv_conformal_spatial_metric_r[i][j] * conformal_extrinsic_curvature_r[i][j]; + conformal_extrinsic_curvature_trace_l += + inv_conformal_spatial_metric_l[i][j] * conformal_extrinsic_curvature_l[i][j]; + conformal_extrinsic_curvature_trace_r += + inv_conformal_spatial_metric_r[i][j] * conformal_extrinsic_curvature_r[i][j]; } } @@ -1486,15 +2074,17 @@ test_vacuum_einstein_conformal_waves_kerr_ho() for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1_l[k][i][j] = 0.0; conformal_spatial_metric_der_raised1_r[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1_l[k][i][j] += inv_conformal_spatial_metric_l[k][l] * conformal_spatial_metric_der_l[l][i][j]; - conformal_spatial_metric_der_raised1_r[k][i][j] += inv_conformal_spatial_metric_r[k][l] * conformal_spatial_metric_der_r[l][i][j]; + conformal_spatial_metric_der_raised1_l[k][i][j] += + inv_conformal_spatial_metric_l[k][l] * conformal_spatial_metric_der_l[l][i][j]; + conformal_spatial_metric_der_raised1_r[k][i][j] += + inv_conformal_spatial_metric_r[k][l] * conformal_spatial_metric_der_r[l][i][j]; } } } } - + double conformal_spatial_metric_der_raised3_l[3][3][3]; double conformal_spatial_metric_der_raised3_r[3][3][3]; for (int i = 0; i < 3; i++) { @@ -1504,8 +2094,10 @@ test_vacuum_einstein_conformal_waves_kerr_ho() conformal_spatial_metric_der_raised3_r[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3_l[i][j][k] += inv_conformal_spatial_metric_l[l][k] * conformal_spatial_metric_der_l[i][j][l]; - conformal_spatial_metric_der_raised3_r[i][j][k] += inv_conformal_spatial_metric_r[l][k] * conformal_spatial_metric_der_r[i][j][l]; + conformal_spatial_metric_der_raised3_l[i][j][k] += + inv_conformal_spatial_metric_l[l][k] * conformal_spatial_metric_der_l[i][j][l]; + conformal_spatial_metric_der_raised3_r[i][j][k] += + inv_conformal_spatial_metric_r[l][k] * conformal_spatial_metric_der_r[i][j][l]; } } } @@ -1536,8 +2128,10 @@ test_vacuum_einstein_conformal_waves_kerr_ho() conformal_aux_vect_raised_r[k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_aux_vect_raised_l[k] += inv_conformal_spatial_metric_l[k][l] * conformal_aux_vect_l[l]; - conformal_aux_vect_raised_r[k] += inv_conformal_spatial_metric_r[k][l] * conformal_aux_vect_r[l]; + conformal_aux_vect_raised_l[k] += + inv_conformal_spatial_metric_l[k][l] * conformal_aux_vect_l[l]; + conformal_aux_vect_raised_r[k] += + inv_conformal_spatial_metric_r[k][l] * conformal_aux_vect_r[l]; } } @@ -1549,8 +2143,10 @@ test_vacuum_einstein_conformal_waves_kerr_ho() conformal_shift_der_lowered_r[i][j] = 0.0; for (int k = 0; k < 3; k++) { - conformal_shift_der_lowered_l[i][j] += conformal_spatial_metric_l[k][j] * conformal_shift_der_l[i][k]; - conformal_shift_der_lowered_r[i][j] += conformal_spatial_metric_r[k][j] * conformal_shift_der_r[i][k]; + conformal_shift_der_lowered_l[i][j] += + conformal_spatial_metric_l[k][j] * conformal_shift_der_l[i][k]; + conformal_shift_der_lowered_r[i][j] += + conformal_spatial_metric_r[k][j] * conformal_shift_der_r[i][k]; } } } @@ -1564,8 +2160,12 @@ test_vacuum_einstein_conformal_waves_kerr_ho() for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_shift_der_switched_l[i][k] += inv_conformal_spatial_metric_l[i][l] * conformal_spatial_metric_l[m][k] * conformal_shift_der_l[l][m]; - conformal_shift_der_switched_r[i][k] += inv_conformal_spatial_metric_r[i][l] * conformal_spatial_metric_r[m][k] * conformal_shift_der_r[l][m]; + conformal_shift_der_switched_l[i][k] += inv_conformal_spatial_metric_l[i][l] * + conformal_spatial_metric_l[m][k] * + conformal_shift_der_l[l][m]; + conformal_shift_der_switched_r[i][k] += inv_conformal_spatial_metric_r[i][l] * + conformal_spatial_metric_r[m][k] * + conformal_shift_der_r[l][m]; } } } @@ -1575,150 +2175,267 @@ test_vacuum_einstein_conformal_waves_kerr_ho() double symmetrized_conformal_shift_r[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - symmetrized_conformal_shift_l[i][j] = (1.0 / conformal_lapse_l) * (conformal_shift_der_lowered_l[i][j] + conformal_shift_der_lowered_l[j][i]); - symmetrized_conformal_shift_r[i][j] = (1.0 / conformal_lapse_r) * (conformal_shift_der_lowered_r[i][j] + conformal_shift_der_lowered_r[j][i]); + symmetrized_conformal_shift_l[i][j] = + (1.0 / conformal_lapse_l) * + (conformal_shift_der_lowered_l[i][j] + conformal_shift_der_lowered_l[j][i]); + symmetrized_conformal_shift_r[i][j] = + (1.0 / conformal_lapse_r) * + (conformal_shift_der_lowered_r[i][j] + conformal_shift_der_lowered_r[j][i]); } } if (!in_excision_region_l && !in_excision_region_r) { double ql[77], qr[77]; - ql[0] = conformal_spatial_metric_l[0][0]; ql[1] = conformal_spatial_metric_l[0][1]; ql[2] = conformal_spatial_metric_l[0][2]; - ql[3] = conformal_spatial_metric_l[1][0]; ql[4] = conformal_spatial_metric_l[1][1]; ql[5] = conformal_spatial_metric_l[1][2]; - ql[6] = conformal_spatial_metric_l[2][0]; ql[7] = conformal_spatial_metric_l[2][1]; ql[8] = conformal_spatial_metric_l[2][2]; + ql[0] = conformal_spatial_metric_l[0][0]; + ql[1] = conformal_spatial_metric_l[0][1]; + ql[2] = conformal_spatial_metric_l[0][2]; + ql[3] = conformal_spatial_metric_l[1][0]; + ql[4] = conformal_spatial_metric_l[1][1]; + ql[5] = conformal_spatial_metric_l[1][2]; + ql[6] = conformal_spatial_metric_l[2][0]; + ql[7] = conformal_spatial_metric_l[2][1]; + ql[8] = conformal_spatial_metric_l[2][2]; ql[9] = conformal_lapse_l; - ql[10] = conformal_extrinsic_curvature_l[0][0]; ql[11] = conformal_extrinsic_curvature_l[0][1]; ql[12] = conformal_extrinsic_curvature_l[0][2]; - ql[13] = conformal_extrinsic_curvature_l[1][0]; ql[14] = conformal_extrinsic_curvature_l[1][1]; ql[15] = conformal_extrinsic_curvature_l[1][2]; - ql[16] = conformal_extrinsic_curvature_l[2][0]; ql[17] = conformal_extrinsic_curvature_l[2][1]; ql[18] = conformal_extrinsic_curvature_l[2][2]; - - ql[19] = conformal_spatial_metric_der_l[0][0][0]; ql[20] = conformal_spatial_metric_der_l[0][0][1]; ql[21] = conformal_spatial_metric_der_l[0][0][2]; - ql[22] = conformal_spatial_metric_der_l[0][1][0]; ql[23] = conformal_spatial_metric_der_l[0][1][1]; ql[24] = conformal_spatial_metric_der_l[0][1][2]; - ql[25] = conformal_spatial_metric_der_l[0][2][0]; ql[26] = conformal_spatial_metric_der_l[0][2][1]; ql[27] = conformal_spatial_metric_der_l[0][2][2]; - - ql[28] = conformal_spatial_metric_der_l[1][0][0]; ql[29] = conformal_spatial_metric_der_l[1][0][1]; ql[30] = conformal_spatial_metric_der_l[1][0][2]; - ql[31] = conformal_spatial_metric_der_l[1][1][0]; ql[32] = conformal_spatial_metric_der_l[1][1][1]; ql[33] = conformal_spatial_metric_der_l[1][1][2]; - ql[34] = conformal_spatial_metric_der_l[1][2][0]; ql[35] = conformal_spatial_metric_der_l[1][2][1]; ql[36] = conformal_spatial_metric_der_l[1][2][2]; - - ql[37] = conformal_spatial_metric_der_l[2][0][0]; ql[38] = conformal_spatial_metric_der_l[2][0][1]; ql[39] = conformal_spatial_metric_der_l[2][0][2]; - ql[40] = conformal_spatial_metric_der_l[2][1][0]; ql[41] = conformal_spatial_metric_der_l[2][1][1]; ql[42] = conformal_spatial_metric_der_l[2][1][2]; - ql[43] = conformal_spatial_metric_der_l[2][2][0]; ql[44] = conformal_spatial_metric_der_l[2][2][1]; ql[45] = conformal_spatial_metric_der_l[2][2][2]; - - ql[46] = conformal_lapse_der_l[0]; ql[47] = conformal_lapse_der_l[1]; ql[48] = conformal_lapse_der_l[2]; - - ql[49] = conformal_aux_vect_l[0]; ql[50] = conformal_aux_vect_l[1]; ql[51] = conformal_aux_vect_l[2]; - - ql[52] = conformal_shift_l[0]; ql[53] = conformal_shift_l[1]; ql[54] = conformal_shift_l[2]; - - ql[55] = conformal_shift_der_l[0][0]; ql[56] = conformal_shift_der_l[0][1]; ql[57] = conformal_shift_der_l[0][2]; - ql[58] = conformal_shift_der_l[1][0]; ql[59] = conformal_shift_der_l[1][1]; ql[60] = conformal_shift_der_l[1][2]; - ql[61] = conformal_shift_der_l[2][0]; ql[62] = conformal_shift_der_l[2][1]; ql[63] = conformal_shift_der_l[2][2]; + ql[10] = conformal_extrinsic_curvature_l[0][0]; + ql[11] = conformal_extrinsic_curvature_l[0][1]; + ql[12] = conformal_extrinsic_curvature_l[0][2]; + ql[13] = conformal_extrinsic_curvature_l[1][0]; + ql[14] = conformal_extrinsic_curvature_l[1][1]; + ql[15] = conformal_extrinsic_curvature_l[1][2]; + ql[16] = conformal_extrinsic_curvature_l[2][0]; + ql[17] = conformal_extrinsic_curvature_l[2][1]; + ql[18] = conformal_extrinsic_curvature_l[2][2]; + + ql[19] = conformal_spatial_metric_der_l[0][0][0]; + ql[20] = conformal_spatial_metric_der_l[0][0][1]; + ql[21] = conformal_spatial_metric_der_l[0][0][2]; + ql[22] = conformal_spatial_metric_der_l[0][1][0]; + ql[23] = conformal_spatial_metric_der_l[0][1][1]; + ql[24] = conformal_spatial_metric_der_l[0][1][2]; + ql[25] = conformal_spatial_metric_der_l[0][2][0]; + ql[26] = conformal_spatial_metric_der_l[0][2][1]; + ql[27] = conformal_spatial_metric_der_l[0][2][2]; + + ql[28] = conformal_spatial_metric_der_l[1][0][0]; + ql[29] = conformal_spatial_metric_der_l[1][0][1]; + ql[30] = conformal_spatial_metric_der_l[1][0][2]; + ql[31] = conformal_spatial_metric_der_l[1][1][0]; + ql[32] = conformal_spatial_metric_der_l[1][1][1]; + ql[33] = conformal_spatial_metric_der_l[1][1][2]; + ql[34] = conformal_spatial_metric_der_l[1][2][0]; + ql[35] = conformal_spatial_metric_der_l[1][2][1]; + ql[36] = conformal_spatial_metric_der_l[1][2][2]; + + ql[37] = conformal_spatial_metric_der_l[2][0][0]; + ql[38] = conformal_spatial_metric_der_l[2][0][1]; + ql[39] = conformal_spatial_metric_der_l[2][0][2]; + ql[40] = conformal_spatial_metric_der_l[2][1][0]; + ql[41] = conformal_spatial_metric_der_l[2][1][1]; + ql[42] = conformal_spatial_metric_der_l[2][1][2]; + ql[43] = conformal_spatial_metric_der_l[2][2][0]; + ql[44] = conformal_spatial_metric_der_l[2][2][1]; + ql[45] = conformal_spatial_metric_der_l[2][2][2]; + + ql[46] = conformal_lapse_der_l[0]; + ql[47] = conformal_lapse_der_l[1]; + ql[48] = conformal_lapse_der_l[2]; + + ql[49] = conformal_aux_vect_l[0]; + ql[50] = conformal_aux_vect_l[1]; + ql[51] = conformal_aux_vect_l[2]; + + ql[52] = conformal_shift_l[0]; + ql[53] = conformal_shift_l[1]; + ql[54] = conformal_shift_l[2]; + + ql[55] = conformal_shift_der_l[0][0]; + ql[56] = conformal_shift_der_l[0][1]; + ql[57] = conformal_shift_der_l[0][2]; + ql[58] = conformal_shift_der_l[1][0]; + ql[59] = conformal_shift_der_l[1][1]; + ql[60] = conformal_shift_der_l[1][2]; + ql[61] = conformal_shift_der_l[2][0]; + ql[62] = conformal_shift_der_l[2][1]; + ql[63] = conformal_shift_der_l[2][2]; ql[64] = bssn_conformal_fact_l; - ql[65] = bssn_conformal_fact_der_l[0]; ql[66] = bssn_conformal_fact_der_l[1]; ql[67] = bssn_conformal_fact_der_l[2]; - - ql[68] = bssn_conformal_fact_der2_l[0][0]; ql[69] = bssn_conformal_fact_der2_l[0][1]; ql[70] = bssn_conformal_fact_der2_l[0][2]; - ql[71] = bssn_conformal_fact_der2_l[1][0]; ql[72] = bssn_conformal_fact_der2_l[1][1]; ql[73] = bssn_conformal_fact_der2_l[1][2]; - ql[74] = bssn_conformal_fact_der2_l[2][0]; ql[75] = bssn_conformal_fact_der2_l[2][1]; ql[76] = bssn_conformal_fact_der2_l[2][2]; - - qr[0] = conformal_spatial_metric_r[0][0]; qr[1] = conformal_spatial_metric_r[0][1]; qr[2] = conformal_spatial_metric_r[0][2]; - qr[3] = conformal_spatial_metric_r[1][0]; qr[4] = conformal_spatial_metric_r[1][1]; qr[5] = conformal_spatial_metric_r[1][2]; - qr[6] = conformal_spatial_metric_r[2][0]; qr[7] = conformal_spatial_metric_r[2][1]; qr[8] = conformal_spatial_metric_r[2][2]; + ql[65] = bssn_conformal_fact_der_l[0]; + ql[66] = bssn_conformal_fact_der_l[1]; + ql[67] = bssn_conformal_fact_der_l[2]; + + ql[68] = bssn_conformal_fact_der2_l[0][0]; + ql[69] = bssn_conformal_fact_der2_l[0][1]; + ql[70] = bssn_conformal_fact_der2_l[0][2]; + ql[71] = bssn_conformal_fact_der2_l[1][0]; + ql[72] = bssn_conformal_fact_der2_l[1][1]; + ql[73] = bssn_conformal_fact_der2_l[1][2]; + ql[74] = bssn_conformal_fact_der2_l[2][0]; + ql[75] = bssn_conformal_fact_der2_l[2][1]; + ql[76] = bssn_conformal_fact_der2_l[2][2]; + + qr[0] = conformal_spatial_metric_r[0][0]; + qr[1] = conformal_spatial_metric_r[0][1]; + qr[2] = conformal_spatial_metric_r[0][2]; + qr[3] = conformal_spatial_metric_r[1][0]; + qr[4] = conformal_spatial_metric_r[1][1]; + qr[5] = conformal_spatial_metric_r[1][2]; + qr[6] = conformal_spatial_metric_r[2][0]; + qr[7] = conformal_spatial_metric_r[2][1]; + qr[8] = conformal_spatial_metric_r[2][2]; qr[9] = conformal_lapse_r; - qr[10] = conformal_extrinsic_curvature_r[0][0]; qr[11] = conformal_extrinsic_curvature_r[0][1]; qr[12] = conformal_extrinsic_curvature_r[0][2]; - qr[13] = conformal_extrinsic_curvature_r[1][0]; qr[14] = conformal_extrinsic_curvature_r[1][1]; qr[15] = conformal_extrinsic_curvature_r[1][2]; - qr[16] = conformal_extrinsic_curvature_r[2][0]; qr[17] = conformal_extrinsic_curvature_r[2][1]; qr[18] = conformal_extrinsic_curvature_r[2][2]; - - qr[19] = conformal_spatial_metric_der_r[0][0][0]; qr[20] = conformal_spatial_metric_der_r[0][0][1]; qr[21] = conformal_spatial_metric_der_r[0][0][2]; - qr[22] = conformal_spatial_metric_der_r[0][1][0]; qr[23] = conformal_spatial_metric_der_r[0][1][1]; qr[24] = conformal_spatial_metric_der_r[0][1][2]; - qr[25] = conformal_spatial_metric_der_r[0][2][0]; qr[26] = conformal_spatial_metric_der_r[0][2][1]; qr[27] = conformal_spatial_metric_der_r[0][2][2]; - - qr[28] = conformal_spatial_metric_der_r[1][0][0]; qr[29] = conformal_spatial_metric_der_r[1][0][1]; qr[30] = conformal_spatial_metric_der_r[1][0][2]; - qr[31] = conformal_spatial_metric_der_r[1][1][0]; qr[32] = conformal_spatial_metric_der_r[1][1][1]; qr[33] = conformal_spatial_metric_der_r[1][1][2]; - qr[34] = conformal_spatial_metric_der_r[1][2][0]; qr[35] = conformal_spatial_metric_der_r[1][2][1]; qr[36] = conformal_spatial_metric_der_r[1][2][2]; - - qr[37] = conformal_spatial_metric_der_r[2][0][0]; qr[38] = conformal_spatial_metric_der_r[2][0][1]; qr[39] = conformal_spatial_metric_der_r[2][0][2]; - qr[40] = conformal_spatial_metric_der_r[2][1][0]; qr[41] = conformal_spatial_metric_der_r[2][1][1]; qr[42] = conformal_spatial_metric_der_r[2][1][2]; - qr[43] = conformal_spatial_metric_der_r[2][2][0]; qr[44] = conformal_spatial_metric_der_r[2][2][1]; qr[45] = conformal_spatial_metric_der_r[2][2][2]; - - qr[46] = conformal_lapse_der_r[0]; qr[47] = conformal_lapse_der_r[1]; qr[48] = conformal_lapse_der_r[2]; - - qr[49] = conformal_aux_vect_r[0]; qr[50] = conformal_aux_vect_r[1]; qr[51] = conformal_aux_vect_r[2]; - - qr[52] = conformal_shift_r[0]; qr[53] = conformal_shift_r[1]; qr[54] = conformal_shift_r[2]; - - qr[55] = conformal_shift_der_r[0][0]; qr[56] = conformal_shift_der_r[0][1]; qr[57] = conformal_shift_der_r[0][2]; - qr[58] = conformal_shift_der_r[1][0]; qr[59] = conformal_shift_der_r[1][1]; qr[60] = conformal_shift_der_r[1][2]; - qr[61] = conformal_shift_der_r[2][0]; qr[62] = conformal_shift_der_r[2][1]; qr[63] = conformal_shift_der_r[2][2]; + qr[10] = conformal_extrinsic_curvature_r[0][0]; + qr[11] = conformal_extrinsic_curvature_r[0][1]; + qr[12] = conformal_extrinsic_curvature_r[0][2]; + qr[13] = conformal_extrinsic_curvature_r[1][0]; + qr[14] = conformal_extrinsic_curvature_r[1][1]; + qr[15] = conformal_extrinsic_curvature_r[1][2]; + qr[16] = conformal_extrinsic_curvature_r[2][0]; + qr[17] = conformal_extrinsic_curvature_r[2][1]; + qr[18] = conformal_extrinsic_curvature_r[2][2]; + + qr[19] = conformal_spatial_metric_der_r[0][0][0]; + qr[20] = conformal_spatial_metric_der_r[0][0][1]; + qr[21] = conformal_spatial_metric_der_r[0][0][2]; + qr[22] = conformal_spatial_metric_der_r[0][1][0]; + qr[23] = conformal_spatial_metric_der_r[0][1][1]; + qr[24] = conformal_spatial_metric_der_r[0][1][2]; + qr[25] = conformal_spatial_metric_der_r[0][2][0]; + qr[26] = conformal_spatial_metric_der_r[0][2][1]; + qr[27] = conformal_spatial_metric_der_r[0][2][2]; + + qr[28] = conformal_spatial_metric_der_r[1][0][0]; + qr[29] = conformal_spatial_metric_der_r[1][0][1]; + qr[30] = conformal_spatial_metric_der_r[1][0][2]; + qr[31] = conformal_spatial_metric_der_r[1][1][0]; + qr[32] = conformal_spatial_metric_der_r[1][1][1]; + qr[33] = conformal_spatial_metric_der_r[1][1][2]; + qr[34] = conformal_spatial_metric_der_r[1][2][0]; + qr[35] = conformal_spatial_metric_der_r[1][2][1]; + qr[36] = conformal_spatial_metric_der_r[1][2][2]; + + qr[37] = conformal_spatial_metric_der_r[2][0][0]; + qr[38] = conformal_spatial_metric_der_r[2][0][1]; + qr[39] = conformal_spatial_metric_der_r[2][0][2]; + qr[40] = conformal_spatial_metric_der_r[2][1][0]; + qr[41] = conformal_spatial_metric_der_r[2][1][1]; + qr[42] = conformal_spatial_metric_der_r[2][1][2]; + qr[43] = conformal_spatial_metric_der_r[2][2][0]; + qr[44] = conformal_spatial_metric_der_r[2][2][1]; + qr[45] = conformal_spatial_metric_der_r[2][2][2]; + + qr[46] = conformal_lapse_der_r[0]; + qr[47] = conformal_lapse_der_r[1]; + qr[48] = conformal_lapse_der_r[2]; + + qr[49] = conformal_aux_vect_r[0]; + qr[50] = conformal_aux_vect_r[1]; + qr[51] = conformal_aux_vect_r[2]; + + qr[52] = conformal_shift_r[0]; + qr[53] = conformal_shift_r[1]; + qr[54] = conformal_shift_r[2]; + + qr[55] = conformal_shift_der_r[0][0]; + qr[56] = conformal_shift_der_r[0][1]; + qr[57] = conformal_shift_der_r[0][2]; + qr[58] = conformal_shift_der_r[1][0]; + qr[59] = conformal_shift_der_r[1][1]; + qr[60] = conformal_shift_der_r[1][2]; + qr[61] = conformal_shift_der_r[2][0]; + qr[62] = conformal_shift_der_r[2][1]; + qr[63] = conformal_shift_der_r[2][2]; qr[64] = bssn_conformal_fact_r; - qr[65] = bssn_conformal_fact_der_r[0]; qr[66] = bssn_conformal_fact_der_r[1]; qr[67] = bssn_conformal_fact_der_r[2]; + qr[65] = bssn_conformal_fact_der_r[0]; + qr[66] = bssn_conformal_fact_der_r[1]; + qr[67] = bssn_conformal_fact_der_r[2]; - qr[68] = bssn_conformal_fact_der2_r[0][0]; qr[69] = bssn_conformal_fact_der2_r[0][1]; qr[70] = bssn_conformal_fact_der2_r[0][2]; - qr[71] = bssn_conformal_fact_der2_r[1][0]; qr[72] = bssn_conformal_fact_der2_r[1][1]; qr[73] = bssn_conformal_fact_der2_r[1][2]; - qr[74] = bssn_conformal_fact_der2_r[2][0]; qr[75] = bssn_conformal_fact_der2_r[2][1]; qr[76] = bssn_conformal_fact_der2_r[2][2]; + qr[68] = bssn_conformal_fact_der2_r[0][0]; + qr[69] = bssn_conformal_fact_der2_r[0][1]; + qr[70] = bssn_conformal_fact_der2_r[0][2]; + qr[71] = bssn_conformal_fact_der2_r[1][0]; + qr[72] = bssn_conformal_fact_der2_r[1][1]; + qr[73] = bssn_conformal_fact_der2_r[1][2]; + qr[74] = bssn_conformal_fact_der2_r[2][0]; + qr[75] = bssn_conformal_fact_der2_r[2][1]; + qr[76] = bssn_conformal_fact_der2_r[2][2]; - double norm[3][3] = { - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - }; + double norm[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; - double tau1[3][3] = { - { 0.0, 1.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - { 1.0, 0.0, 0.0 }, - }; + double tau1[3][3] = {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}}; - double tau2[3][3] = { - { 0.0, 0.0, 1.0 }, - { 0.0, 0.0, -1.0 }, - { 0.0, 1.0, 0.0 }, - }; + double tau2[3][3] = {{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}}; for (int d = 0; d < 3; d++) { double speeds[2], waves[2 * 77], waves_local[2 * 77]; double ql_local[77], qr_local[77]; - gkyl_wv_eqn_rotate_to_local(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], ql, ql_local); - gkyl_wv_eqn_rotate_to_local(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], qr, qr_local); + gkyl_wv_eqn_rotate_to_local( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], ql, ql_local + ); + gkyl_wv_eqn_rotate_to_local( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], qr, qr_local + ); double delta[77]; for (int i = 0; i < 77; i++) { delta[i] = qr_local[i] - ql_local[i]; } - gkyl_wv_eqn_waves(vacuum_einstein_conformal, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, waves_local, speeds); + gkyl_wv_eqn_waves( + vacuum_einstein_conformal, GKYL_WV_HIGH_ORDER_FLUX, delta, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds + ); double apdq_local[77], amdq_local[77]; - gkyl_wv_eqn_qfluct(vacuum_einstein_conformal, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, waves_local, speeds, amdq_local, apdq_local); + gkyl_wv_eqn_qfluct( + vacuum_einstein_conformal, GKYL_WV_HIGH_ORDER_FLUX, ql_local, qr_local, 1.0, 1.0, + waves_local, speeds, amdq_local, apdq_local + ); for (int i = 0; i < 2; i++) { - gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], &waves_local[i * 77], &waves[i * 77]); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], &waves_local[i * 77], + &waves[i * 77] + ); } double apdq[77], amdq[77]; - gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], apdq_local, apdq); - gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], amdq_local, amdq); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], apdq_local, apdq + ); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], amdq_local, amdq + ); double fl_local[77], fr_local[77]; - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, ql_local, fl_local); - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, qr_local, fr_local); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, ql_local, fl_local + ); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, qr_local, fr_local + ); double fl[77], fr[77]; - gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], fl_local, fl); - gkyl_wv_eqn_rotate_to_global(vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], fr_local, fr); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], fl_local, fl + ); + gkyl_wv_eqn_rotate_to_global( + vacuum_einstein_conformal, tau1[d], tau2[d], norm[d], fr_local, fr + ); for (int i = 0; i < 77; i++) { - TEST_CHECK( gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-11) ); + TEST_CHECK(gkyl_compare(fr[i] - fl[i], amdq[i] + apdq[i], 1e-11)); } } } - + for (int i = 0; i < 3; i++) { gkyl_free(conformal_spatial_metric_l[i]); gkyl_free(conformal_spatial_metric_r[i]); @@ -1728,7 +2445,7 @@ test_vacuum_einstein_conformal_waves_kerr_ho() gkyl_free(conformal_extrinsic_curvature_r[i]); gkyl_free(conformal_shift_der_l[i]); gkyl_free(conformal_shift_der_r[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(conformal_spatial_metric_der_l[i][j]); gkyl_free(conformal_spatial_metric_der_r[i][j]); @@ -1755,9 +2472,12 @@ test_vacuum_einstein_conformal_waves_kerr_ho() } TEST_LIST = { - { "vacuum_einstein_conformal_basic_minkowski_ho", test_vacuum_einstein_conformal_basic_minkowski_ho }, - { "vacuum_einstein_conformal_basic_schwarzschild_ho", test_vacuum_einstein_conformal_basic_schwarzschild_ho }, - { "vacuum_einstein_conformal_waves_schwarzschild_ho", test_vacuum_einstein_conformal_waves_schwarzschild_ho }, - { "vacuum_einstein_conformal_waves_kerr_ho", test_vacuum_einstein_conformal_waves_kerr_ho }, - { NULL, NULL }, + {"vacuum_einstein_conformal_basic_minkowski_ho", test_vacuum_einstein_conformal_basic_minkowski_ho + }, + {"vacuum_einstein_conformal_basic_schwarzschild_ho", + test_vacuum_einstein_conformal_basic_schwarzschild_ho}, + {"vacuum_einstein_conformal_waves_schwarzschild_ho", + test_vacuum_einstein_conformal_waves_schwarzschild_ho}, + {"vacuum_einstein_conformal_waves_kerr_ho", test_vacuum_einstein_conformal_waves_kerr_ho}, + {NULL, NULL} }; \ No newline at end of file diff --git a/moments/zero/fem_poisson.c b/moments/zero/fem_poisson.c index 43682a56c3..830b9a1c51 100644 --- a/moments/zero/fem_poisson.c +++ b/moments/zero/fem_poisson.c @@ -2,13 +2,11 @@ #include #include -static void -fem_poisson_bias_src_disabled(gkyl_fem_poisson* up, struct gkyl_array *rhsin) +static void fem_poisson_bias_src_disabled(gkyl_fem_poisson *up, struct gkyl_array *rhsin) { } -static void -fem_poisson_bias_src_enabled(gkyl_fem_poisson* up, struct gkyl_array *rhsin) +static void fem_poisson_bias_src_enabled(gkyl_fem_poisson *up, struct gkyl_array *rhsin) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { @@ -26,37 +24,43 @@ fem_poisson_bias_src_enabled(gkyl_fem_poisson* up, struct gkyl_array *rhsin) long linidx = gkyl_range_idx(up->solve_range, up->solve_iter.idx); int keri = idx_to_inup_ker(up->ndim, up->num_cells, up->solve_iter.idx); - for (size_t d=0; dndim; d++) idx0[d] = up->solve_iter.idx[d]-1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = up->solve_iter.idx[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); - for (int i=0; inum_bias_plane; i++) { + for (int i = 0; i < up->num_bias_plane; i++) { // Index of the cell that abuts the plane from below. struct gkyl_poisson_bias_plane *bp = &up->bias_planes[i]; double dx = up->grid.dx[bp->dir]; - int bp_idx_m = (bp->loc-1e-3*dx - up->grid.lower[bp->dir])/dx+1; - - if (up->solve_iter.idx[bp->dir] == bp_idx_m || up->solve_iter.idx[bp->dir] == bp_idx_m+1) { - up->kernels->bias_src_ker[keri](-1+2*((bp_idx_m+1)-up->solve_iter.idx[bp->dir]), - bp->dir, bp->val, up->globalidx, brhs_p); + int bp_idx_m = (bp->loc - 1e-3 * dx - up->grid.lower[bp->dir]) / dx + 1; + + if (up->solve_iter.idx[bp->dir] == bp_idx_m || up->solve_iter.idx[bp->dir] == bp_idx_m + 1) { + up->kernels->bias_src_ker[keri]( + -1 + 2 * ((bp_idx_m + 1) - up->solve_iter.idx[bp->dir]), bp->dir, bp->val, up->globalidx, + brhs_p + ); } } } } -struct gkyl_fem_poisson* -gkyl_fem_poisson_new(const struct gkyl_range *solve_range, const struct gkyl_rect_grid *grid, const struct gkyl_basis basis, - struct gkyl_poisson_bc *bcs, struct gkyl_poisson_bias_plane_list *bias_planes, struct gkyl_array *epsilon, - struct gkyl_array *kSq, bool is_epsilon_const, bool use_gpu) +struct gkyl_fem_poisson *gkyl_fem_poisson_new( + const struct gkyl_range *solve_range, const struct gkyl_rect_grid *grid, + const struct gkyl_basis basis, struct gkyl_poisson_bc *bcs, + struct gkyl_poisson_bias_plane_list *bias_planes, struct gkyl_array *epsilon, + struct gkyl_array *kSq, bool is_epsilon_const, bool use_gpu +) { - struct gkyl_fem_poisson *up = gkyl_malloc(sizeof(struct gkyl_fem_poisson)); up->kernels = gkyl_malloc(sizeof(struct gkyl_fem_poisson_kernels)); #ifdef GKYL_HAVE_CUDA - if (use_gpu) + if (use_gpu) { up->kernels_cu = gkyl_cu_malloc(sizeof(struct gkyl_fem_poisson_kernels)); - else + } else { up->kernels_cu = up->kernels; + } #else up->kernels_cu = up->kernels; #endif @@ -64,7 +68,7 @@ gkyl_fem_poisson_new(const struct gkyl_range *solve_range, const struct gkyl_rec up->solve_range = solve_range; up->ndim = grid->ndim; up->grid = *grid; - up->num_basis = basis.num_basis; + up->num_basis = basis.num_basis; up->basis_type = basis.b_type; up->poly_order = basis.poly_order; up->basis = basis; @@ -72,19 +76,21 @@ gkyl_fem_poisson_new(const struct gkyl_range *solve_range, const struct gkyl_rec // Factor accounting for normalization when subtracting a constant from a // DG field and the 1/N to properly compute the volume averaged RHS. - up->mavgfac = -pow(sqrt(2.),up->ndim)/up->solve_range->volume; + up->mavgfac = -pow(sqrt(2.), up->ndim) / up->solve_range->volume; if (!is_epsilon_const) { up->isvareps = true; - up->epsilon = epsilon; + up->epsilon = epsilon; } else { up->isvareps = false; // Create a small gkyl_array to hold the constant epsilon value. - double *eps_avg = gkyl_malloc(sizeof(double)); + double *eps_avg = gkyl_malloc(sizeof(double)); #ifdef GKYL_HAVE_CUDA - up->epsilon = up->use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, 1) : gkyl_array_new(GKYL_DOUBLE, 1, 1); - struct gkyl_array *eps_cellavg = up->use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, epsilon->size) - : gkyl_array_new(GKYL_DOUBLE, 1, epsilon->size); + up->epsilon = up->use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, 1) : + gkyl_array_new(GKYL_DOUBLE, 1, 1); + struct gkyl_array *eps_cellavg = up->use_gpu ? + gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, epsilon->size) : + gkyl_array_new(GKYL_DOUBLE, 1, epsilon->size); gkyl_dg_calc_average_range(&up->basis, 0, eps_cellavg, 0, epsilon, *up->solve_range); if (up->use_gpu) { double *eps_avg_cu = gkyl_cu_malloc(sizeof(double)); @@ -101,14 +107,15 @@ gkyl_fem_poisson_new(const struct gkyl_range *solve_range, const struct gkyl_rec gkyl_dg_calc_average_range(&up->basis, 0, eps_cellavg, 0, epsilon, *up->solve_range); gkyl_array_reduce_range(eps_avg, eps_cellavg, GKYL_SUM, up->solve_range); #endif - gkyl_array_shiftc(up->epsilon, eps_avg[0]/up->solve_range->volume, 0); + gkyl_array_shiftc(up->epsilon, eps_avg[0] / up->solve_range->volume, 0); gkyl_array_release(eps_cellavg); gkyl_free(eps_avg); } // We assume epsilon and kSq live on the device, and we create a host-side // copies temporarily to compute the LHS matrix. This also works for CPU solves. - struct gkyl_array *epsilon_ho = gkyl_array_new(GKYL_DOUBLE, up->epsilon->ncomp, up->epsilon->size); + struct gkyl_array *epsilon_ho = + gkyl_array_new(GKYL_DOUBLE, up->epsilon->ncomp, up->epsilon->size); gkyl_array_copy(epsilon_ho, up->epsilon); struct gkyl_array *kSq_ho; if (kSq) { @@ -121,69 +128,91 @@ gkyl_fem_poisson_new(const struct gkyl_range *solve_range, const struct gkyl_rec gkyl_array_clear(kSq_ho, 0.); } - up->globalidx = gkyl_malloc(sizeof(long[up->num_basis])); // global index, one for each basis in a cell. + up->globalidx = + gkyl_malloc(sizeof(long[up->num_basis])); // global index, one for each basis in a cell. - for (int d=0; dndim; d++) up->num_cells[d] = up->solve_range->upper[d]-up->solve_range->lower[d]+1; + for (int d = 0; d < up->ndim; d++) { + up->num_cells[d] = up->solve_range->upper[d] - up->solve_range->lower[d] + 1; + } // Prepare for periodic domain case. - for (int d=0; dndim; d++) { + for (int d = 0; d < up->ndim; d++) { // Sanity check. if ((bcs->lo_type[d] == GKYL_POISSON_PERIODIC && bcs->up_type[d] != GKYL_POISSON_PERIODIC) || - (bcs->lo_type[d] != GKYL_POISSON_PERIODIC && bcs->up_type[d] == GKYL_POISSON_PERIODIC)) + (bcs->lo_type[d] != GKYL_POISSON_PERIODIC && bcs->up_type[d] == GKYL_POISSON_PERIODIC)) { assert(false); + } + } + for (int d = 0; d < up->ndim; d++) { + up->isdirperiodic[d] = bcs->lo_type[d] == GKYL_POISSON_PERIODIC; } - for (int d=0; dndim; d++) up->isdirperiodic[d] = bcs->lo_type[d] == GKYL_POISSON_PERIODIC; up->isdomperiodic = true; - for (int d=0; dndim; d++) up->isdomperiodic = up->isdomperiodic && up->isdirperiodic[d]; + for (int d = 0; d < up->ndim; d++) { + up->isdomperiodic = up->isdomperiodic && up->isdirperiodic[d]; + } if (up->isdomperiodic) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { up->rhs_cellavg = gkyl_array_cu_dev_new(GKYL_DOUBLE, 1, epsilon->size); - up->rhs_avg_cu = (double*) gkyl_cu_malloc(sizeof(double)); + up->rhs_avg_cu = (double *)gkyl_cu_malloc(sizeof(double)); } else { up->rhs_cellavg = gkyl_array_new(GKYL_DOUBLE, 1, epsilon->size); } #else up->rhs_cellavg = gkyl_array_new(GKYL_DOUBLE, 1, epsilon->size); #endif - up->rhs_avg = (double*) gkyl_malloc(sizeof(double)); + up->rhs_avg = (double *)gkyl_malloc(sizeof(double)); gkyl_array_clear(up->rhs_cellavg, 0.0); } // Pack BC values into a single array for easier use in kernels. - for (int d=0; dndim; d++) { - for (int k=0; k<6; k++) up->bcvals[d*2*3+k] = 0.0; // default. Not used in some cases (e.g. periodic). + for (int d = 0; d < up->ndim; d++) { + for (int k = 0; k < 6; k++) { + up->bcvals[d * 2 * 3 + k] = 0.0; // default. Not used in some cases (e.g. periodic). + } if (bcs->lo_type[d] != GKYL_POISSON_PERIODIC) { int vnum, voff; vnum = bcs->lo_type[d] == GKYL_POISSON_ROBIN ? 3 : 1; voff = bcs->lo_type[d] == GKYL_POISSON_ROBIN ? 0 : 2; - for (int k=0; kbcvals[d*2*3+voff+k] = bcs->lo_value[d].v[k]; + for (int k = 0; k < vnum; k++) { + up->bcvals[d * 2 * 3 + voff + k] = bcs->lo_value[d].v[k]; + } vnum = bcs->up_type[d] == GKYL_POISSON_ROBIN ? 3 : 1; voff = bcs->up_type[d] == GKYL_POISSON_ROBIN ? 0 : 2; - for (int k=0; kbcvals[d*2*3+voff+3+k] = bcs->up_value[d].v[k]; + for (int k = 0; k < vnum; k++) { + up->bcvals[d * 2 * 3 + voff + 3 + k] = bcs->up_value[d].v[k]; + } } } #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - up->bcvals_cu = (double *) gkyl_cu_malloc(sizeof(double[GKYL_MAX_CDIM*3*2])); - gkyl_cu_memcpy(up->bcvals_cu, up->bcvals, sizeof(double[GKYL_MAX_CDIM*3*2]), GKYL_CU_MEMCPY_H2D); + up->bcvals_cu = (double *)gkyl_cu_malloc(sizeof(double[GKYL_MAX_CDIM * 3 * 2])); + gkyl_cu_memcpy( + up->bcvals_cu, up->bcvals, sizeof(double[GKYL_MAX_CDIM * 3 * 2]), GKYL_CU_MEMCPY_H2D + ); } #endif - + // Check if one of the boundaries needs a spatially varying Dirichlet BC. up->isdirichletvar = false; - for (int d=0; dndim; d++) up->isdirichletvar = up->isdirichletvar || - (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING || bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING); + for (int d = 0; d < up->ndim; d++) { + up->isdirichletvar = up->isdirichletvar || (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING || + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING); + } // Compute the number of local and global nodes. up->numnodes_local = up->num_basis; - up->numnodes_global = gkyl_fem_poisson_global_num_nodes(up->ndim, up->poly_order, basis.b_type, up->num_cells, up->isdirperiodic); + up->numnodes_global = gkyl_fem_poisson_global_num_nodes( + up->ndim, up->poly_order, basis.b_type, up->num_cells, up->isdirperiodic + ); - for (int d=0; dndim; d++) up->dx[d] = up->grid.dx[d]; // Cell lengths. + for (int d = 0; d < up->ndim; d++) { + up->dx[d] = up->grid.dx[d]; // Cell lengths. + } #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - up->dx_cu = (double *) gkyl_cu_malloc(sizeof(double[GKYL_MAX_CDIM])); + up->dx_cu = (double *)gkyl_cu_malloc(sizeof(double[GKYL_MAX_CDIM])); gkyl_cu_memcpy(up->dx_cu, up->dx, sizeof(double[GKYL_MAX_CDIM]), GKYL_CU_MEMCPY_H2D); } #endif @@ -213,28 +242,31 @@ gkyl_fem_poisson_new(const struct gkyl_range *solve_range, const struct gkyl_rec up->num_bias_plane = bias_planes->num_bias_plane; size_t bp_sz = bias_planes->num_bias_plane * sizeof(struct gkyl_poisson_bias_plane); if (up->use_gpu) { - up->bias_planes = gkyl_cu_malloc(bias_planes->num_bias_plane * sizeof(struct gkyl_poisson_bias_plane)); + up->bias_planes = + gkyl_cu_malloc(bias_planes->num_bias_plane * sizeof(struct gkyl_poisson_bias_plane)); gkyl_cu_memcpy(up->bias_planes, bias_planes->bp, bp_sz, GKYL_CU_MEMCPY_H2D); - } - else { - up->bias_planes = gkyl_malloc(bias_planes->num_bias_plane * sizeof(struct gkyl_poisson_bias_plane)); + } else { + up->bias_planes = + gkyl_malloc(bias_planes->num_bias_plane * sizeof(struct gkyl_poisson_bias_plane)); memcpy(up->bias_planes, bias_planes->bp, bp_sz); } } } #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { fem_poisson_choose_kernels_cu(&basis, bcs, up->isvareps, up->isdirperiodic, up->kernels_cu); + } #endif // Create a linear Ax=B problem. Here A is the discrete (global) matrix // representation of the LHS of the Helmholtz equation. #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) + if (up->use_gpu) { up->prob_cu = gkyl_culinsolver_prob_new(1, up->numnodes_global, up->numnodes_global, 1); - else + } else { up->prob = gkyl_superlu_prob_new(1, up->numnodes_global, up->numnodes_global, 1); + } #else up->prob = gkyl_superlu_prob_new(1, up->numnodes_global, up->numnodes_global, 1); #endif @@ -243,18 +275,24 @@ gkyl_fem_poisson_new(const struct gkyl_range *solve_range, const struct gkyl_rec struct gkyl_mat_triples **tri = gkyl_malloc(sizeof(struct gkyl_mat_triples *)); tri[0] = gkyl_mat_triples_new(up->numnodes_global, up->numnodes_global); #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) gkyl_mat_triples_set_rowmaj_order(tri[0]); + if (up->use_gpu) { + gkyl_mat_triples_set_rowmaj_order(tri[0]); + } #endif gkyl_range_iter_init(&up->solve_iter, up->solve_range); int idx0[GKYL_MAX_CDIM]; while (gkyl_range_iter_next(&up->solve_iter)) { long linidx = gkyl_range_idx(up->solve_range, up->solve_iter.idx); - double *eps_p = up->isvareps? gkyl_array_fetch(epsilon_ho, linidx) : gkyl_array_fetch(epsilon_ho,0); - double *kSq_p = up->ishelmholtz? gkyl_array_fetch(kSq_ho, linidx) : gkyl_array_fetch(kSq_ho,0); + double *eps_p = up->isvareps ? gkyl_array_fetch(epsilon_ho, linidx) : + gkyl_array_fetch(epsilon_ho, 0); + double *kSq_p = up->ishelmholtz ? gkyl_array_fetch(kSq_ho, linidx) : + gkyl_array_fetch(kSq_ho, 0); int keri = idx_to_inup_ker(up->ndim, up->num_cells, up->solve_iter.idx); - for (size_t d=0; dndim; d++) idx0[d] = up->solve_iter.idx[d]-1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = up->solve_iter.idx[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); // Apply the -nabla . (epsilon*nabla)-kSq stencil. @@ -270,28 +308,31 @@ gkyl_fem_poisson_new(const struct gkyl_range *solve_range, const struct gkyl_rec long linidx = gkyl_range_idx(up->solve_range, up->solve_iter.idx); int keri = idx_to_inup_ker(up->ndim, up->num_cells, up->solve_iter.idx); - for (size_t d=0; dndim; d++) idx0[d] = up->solve_iter.idx[d]-1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = up->solve_iter.idx[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); - for (int i=0; inum_bias_plane; i++) { + for (int i = 0; i < bias_planes->num_bias_plane; i++) { // Index of the cell that abuts the plane from below. struct gkyl_poisson_bias_plane *bp = &bias_planes->bp[i]; double dx = up->grid.dx[bp->dir]; - int bp_idx_m = (bp->loc-1e-3*dx - up->grid.lower[bp->dir])/dx+1; - - if (up->solve_iter.idx[bp->dir] == bp_idx_m || up->solve_iter.idx[bp->dir] == bp_idx_m+1) { - up->kernels->bias_lhs_ker[keri](-1+2*((bp_idx_m+1)-up->solve_iter.idx[bp->dir]), - bp->dir, up->globalidx, tri[0]); + int bp_idx_m = (bp->loc - 1e-3 * dx - up->grid.lower[bp->dir]) / dx + 1; + + if (up->solve_iter.idx[bp->dir] == bp_idx_m || + up->solve_iter.idx[bp->dir] == bp_idx_m + 1) { + up->kernels->bias_lhs_ker[keri]( + -1 + 2 * ((bp_idx_m + 1) - up->solve_iter.idx[bp->dir]), bp->dir, up->globalidx, tri[0] + ); } } } up->bias_plane_src = fem_poisson_bias_src_enabled; - } - else { + } else { up->bias_plane_src = fem_poisson_bias_src_disabled; } - + #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { gkyl_culinsolver_amat_from_triples(up->prob_cu, tri); @@ -310,10 +351,10 @@ gkyl_fem_poisson_new(const struct gkyl_range *solve_range, const struct gkyl_rec return up; } -void -gkyl_fem_poisson_set_rhs(gkyl_fem_poisson* up, struct gkyl_array *rhsin, const struct gkyl_array *phibc) +void gkyl_fem_poisson_set_rhs( + gkyl_fem_poisson *up, struct gkyl_array *rhsin, const struct gkyl_array *phibc +) { - if (up->isdomperiodic && !(up->ishelmholtz)) { // Subtract the volume averaged RHS from the RHS. gkyl_array_clear(up->rhs_cellavg, 0.0); @@ -328,15 +369,15 @@ gkyl_fem_poisson_set_rhs(gkyl_fem_poisson* up, struct gkyl_array *rhsin, const s #else gkyl_array_reduce_range(up->rhs_avg, up->rhs_cellavg, GKYL_SUM, up->solve_range); #endif - gkyl_array_shiftc(rhsin, up->mavgfac*up->rhs_avg[0], 0); + gkyl_array_shiftc(rhsin, up->mavgfac * up->rhs_avg[0], 0); } - #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { assert(gkyl_array_is_cu_dev(rhsin)); - if (phibc) + if (phibc) { assert(gkyl_array_is_cu_dev(phibc)); + } gkyl_fem_poisson_set_rhs_cu(up, rhsin, phibc); return; @@ -351,12 +392,15 @@ gkyl_fem_poisson_set_rhs(gkyl_fem_poisson* up, struct gkyl_array *rhsin, const s while (gkyl_range_iter_next(&up->solve_iter)) { long linidx = gkyl_range_idx(up->solve_range, up->solve_iter.idx); - double *eps_p = up->isvareps? gkyl_array_fetch(up->epsilon, linidx) : gkyl_array_fetch(up->epsilon,0); + double *eps_p = up->isvareps ? gkyl_array_fetch(up->epsilon, linidx) : + gkyl_array_fetch(up->epsilon, 0); double *rhsin_p = gkyl_array_fetch(rhsin, linidx); - const double *phibc_p = up->isdirichletvar? gkyl_array_cfetch(phibc, linidx) : NULL; + const double *phibc_p = up->isdirichletvar ? gkyl_array_cfetch(phibc, linidx) : NULL; int keri = idx_to_inup_ker(up->ndim, up->num_cells, up->solve_iter.idx); - for (size_t d=0; dndim; d++) idx0[d] = up->solve_iter.idx[d]-1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = up->solve_iter.idx[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); // Apply the RHS source stencil. It's mostly the mass matrix times a @@ -369,11 +413,10 @@ gkyl_fem_poisson_set_rhs(gkyl_fem_poisson* up, struct gkyl_array *rhsin, const s up->bias_plane_src(up, rhsin); gkyl_superlu_brhs_from_array(up->prob, brhs_p); - } -void -gkyl_fem_poisson_solve(gkyl_fem_poisson* up, struct gkyl_array *phiout) { +void gkyl_fem_poisson_solve(gkyl_fem_poisson *up, struct gkyl_array *phiout) +{ #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { assert(gkyl_array_is_cu_dev(phiout)); @@ -394,13 +437,13 @@ gkyl_fem_poisson_solve(gkyl_fem_poisson* up, struct gkyl_array *phiout) { double *phiout_p = gkyl_array_fetch(phiout, linidx); int keri = idx_to_inup_ker(up->ndim, up->num_cells, up->solve_iter.idx); - for (size_t d=0; dndim; d++) idx0[d] = up->solve_iter.idx[d]-1; + for (size_t d = 0; d < up->ndim; d++) { + idx0[d] = up->solve_iter.idx[d] - 1; + } up->kernels->l2g[keri](up->num_cells, idx0, up->globalidx); up->kernels->solker(gkyl_superlu_get_rhs_ptr(up->prob, 0), up->globalidx, phiout_p); - } - } void gkyl_fem_poisson_release(gkyl_fem_poisson *up) @@ -410,29 +453,35 @@ void gkyl_fem_poisson_release(gkyl_fem_poisson *up) gkyl_free(up->rhs_avg); } - if (!up->isvareps) + if (!up->isvareps) { gkyl_array_release(up->epsilon); + } #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { gkyl_cu_free(up->kernels_cu); gkyl_cu_free(up->dx_cu); - if (up->isdomperiodic) gkyl_cu_free(up->rhs_avg_cu); + if (up->isdomperiodic) { + gkyl_cu_free(up->rhs_avg_cu); + } gkyl_cu_free(up->bcvals_cu); gkyl_culinsolver_prob_release(up->prob_cu); - if (up->num_bias_plane > 0) + if (up->num_bias_plane > 0) { gkyl_cu_free(up->bias_planes); + } } else { gkyl_superlu_prob_release(up->prob); - if (up->num_bias_plane > 0) + if (up->num_bias_plane > 0) { gkyl_free(up->bias_planes); + } } #else gkyl_superlu_prob_release(up->prob); - if (up->num_bias_plane > 0) + if (up->num_bias_plane > 0) { gkyl_free(up->bias_planes); + } #endif gkyl_free(up->globalidx); diff --git a/moments/zero/fem_poisson_cu.cu b/moments/zero/fem_poisson_cu.cu index 41f69050c7..8aa3de59ae 100644 --- a/moments/zero/fem_poisson_cu.cu +++ b/moments/zero/fem_poisson_cu.cu @@ -10,78 +10,77 @@ extern "C" { // CUDA kernel to set device pointers to l2g kernel function. // Doing function pointer stuff in here avoids troublesome // cudaMemcpyFromSymbol. -__global__ static void -fem_poisson_set_cu_l2gker_ptrs(struct gkyl_fem_poisson_kernels* kers, enum gkyl_basis_type b_type, - int dim, int poly_order, const int *bckey) +__global__ static void fem_poisson_set_cu_l2gker_ptrs( + struct gkyl_fem_poisson_kernels *kers, enum gkyl_basis_type b_type, int dim, int poly_order, + const int *bckey +) { - // Set l2g kernels. const local2global_kern_bcx_list_1x *local2global_1x_kernels; const local2global_kern_bcx_list_2x *local2global_2x_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - local2global_1x_kernels = ser_loc2glob_list_1x; - local2global_2x_kernels = ser_loc2glob_list_2x; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + local2global_1x_kernels = ser_loc2glob_list_1x; + local2global_2x_kernels = ser_loc2glob_list_2x; + break; + default: + assert(false); + break; } - for (int k=0; k<(int)(pow(2,dim)+0.5); k++) { + for (int k = 0; k < (int)(pow(2, dim) + 0.5); k++) { if (dim == 1) { kers->l2g[k] = CK1(local2global_1x_kernels, poly_order, k, bckey[0]); - } else if ( dim == 2) { + } else if (dim == 2) { kers->l2g[k] = CK2(local2global_2x_kernels, poly_order, k, bckey[0], bckey[1]); -// } else if (dim == 3) { -// kers->l2g[k] = CK3(ser_loc2glob_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); + // } else if (dim == 3) { + // kers->l2g[k] = CK3(ser_loc2glob_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); } } - } // CUDA kernel to set device pointers to RHS src and solution kernels. -__global__ static void -fem_poisson_set_cu_ker_ptrs(struct gkyl_fem_poisson_kernels* kers, enum gkyl_basis_type b_type, - int dim, int poly_order, const int *bckey, bool isvareps) +__global__ static void fem_poisson_set_cu_ker_ptrs( + struct gkyl_fem_poisson_kernels *kers, enum gkyl_basis_type b_type, int dim, int poly_order, + const int *bckey, bool isvareps +) { - // Set RHS stencil kernels. const srcstencil_kern_bcx_list_1x *srcstencil_1x_kernels; const srcstencil_kern_bcx_list_2x *srcstencil_2x_kernels; if (isvareps) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - srcstencil_1x_kernels = ser_srcstencil_vareps_list_1x; - srcstencil_2x_kernels = ser_srcstencil_vareps_list_2x; - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); + case GKYL_BASIS_MODAL_SERENDIPITY: + srcstencil_1x_kernels = ser_srcstencil_vareps_list_1x; + srcstencil_2x_kernels = ser_srcstencil_vareps_list_2x; + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); } } else { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - srcstencil_1x_kernels = ser_srcstencil_consteps_list_1x; - srcstencil_2x_kernels = ser_srcstencil_consteps_list_2x; - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); + case GKYL_BASIS_MODAL_SERENDIPITY: + srcstencil_1x_kernels = ser_srcstencil_consteps_list_1x; + srcstencil_2x_kernels = ser_srcstencil_consteps_list_2x; + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); } } - for (int k=0; k<(int)(pow(3,dim)+0.5); k++) { + for (int k = 0; k < (int)(pow(3, dim) + 0.5); k++) { if (dim == 1) { kers->srcker[k] = CK1(srcstencil_1x_kernels, poly_order, k, bckey[0]); } else if (dim == 2) { kers->srcker[k] = CK2(srcstencil_2x_kernels, poly_order, k, bckey[0], bckey[1]); -// } else if (dim == 3) { -// kers->srcker[k] = CK3(srcstencil_3x_kernels, poly_order, k, bckey[0], bckey[1], bckey[2]); + // } else if (dim == 3) { + // kers->srcker[k] = CK3(srcstencil_3x_kernels, poly_order, k, bckey[0], bckey[1], bckey[2]); } } @@ -89,124 +88,155 @@ fem_poisson_set_cu_ker_ptrs(struct gkyl_fem_poisson_kernels* kers, enum gkyl_bas const solstencil_kern_list *solstencil_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - solstencil_kernels = ser_solstencil_list; - break; - case GKYL_BASIS_MODAL_TENSOR: - break; - default: - assert(false); + case GKYL_BASIS_MODAL_SERENDIPITY: + solstencil_kernels = ser_solstencil_list; + break; + case GKYL_BASIS_MODAL_TENSOR: + break; + default: + assert(false); } kers->solker = solstencil_kernels[dim].kernels[poly_order]; - } // CUDA kernel to set device pointers to biasing kernel functions. // Doing function pointer stuff in here avoids troublesome // cudaMemcpyFromSymbol. -__global__ static void -fem_poisson_set_cu_biasker_ptrs(struct gkyl_fem_poisson_kernels* kers, enum gkyl_basis_type b_type, - int dim, int poly_order, const int *bckey) +__global__ static void fem_poisson_set_cu_biasker_ptrs( + struct gkyl_fem_poisson_kernels *kers, enum gkyl_basis_type b_type, int dim, int poly_order, + const int *bckey +) { - // Set l2g kernels. const bias_src_kern_bcx_list_1x *bias_plane_1x_kernels; const bias_src_kern_bcx_list_2x *bias_plane_2x_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - bias_plane_1x_kernels = ser_bias_src_list_1x; - bias_plane_2x_kernels = ser_bias_src_list_2x; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + bias_plane_1x_kernels = ser_bias_src_list_1x; + bias_plane_2x_kernels = ser_bias_src_list_2x; + break; + default: + assert(false); + break; } - for (int k=0; k<(int)(pow(2,dim)+0.5); k++) { + for (int k = 0; k < (int)(pow(2, dim) + 0.5); k++) { if (dim == 1) { kers->bias_src_ker[k] = CK1(bias_plane_1x_kernels, poly_order, k, bckey[0]); - } else if ( dim == 2) { + } else if (dim == 2) { kers->bias_src_ker[k] = CK2(bias_plane_2x_kernels, poly_order, k, bckey[0], bckey[1]); -// } else if (dim == 3) { -// kers->bias_src_ker[k] = CK3(bias_plane_3x_kernels, poly_order, k, bckey[0], bckey[1], bckey[2]); + // } else if (dim == 3) { + // kers->bias_src_ker[k] = CK3(bias_plane_3x_kernels, poly_order, k, bckey[0], bckey[1], bckey[2]); } } - } -void -fem_poisson_choose_kernels_cu(const struct gkyl_basis* basis, const struct gkyl_poisson_bc *bcs, - bool isvareps, const bool *isdirperiodic, struct gkyl_fem_poisson_kernels *kers) +void fem_poisson_choose_kernels_cu( + const struct gkyl_basis *basis, const struct gkyl_poisson_bc *bcs, bool isvareps, + const bool *isdirperiodic, struct gkyl_fem_poisson_kernels *kers +) { - int dim = basis->ndim; int poly_order = basis->poly_order; int bckey[GKYL_MAX_CDIM] = {-1}; - for (int d=0; dndim; d++) bckey[d] = isdirperiodic[d] ? 0 : 1; - int *bckey_d = (int *) gkyl_cu_malloc(sizeof(int[GKYL_MAX_CDIM])); + for (int d = 0; d < basis->ndim; d++) { + bckey[d] = isdirperiodic[d] ? 0 : 1; + } + int *bckey_d = (int *)gkyl_cu_malloc(sizeof(int[GKYL_MAX_CDIM])); gkyl_cu_memcpy(bckey_d, bckey, sizeof(int[GKYL_MAX_CDIM]), GKYL_CU_MEMCPY_H2D); - fem_poisson_set_cu_l2gker_ptrs<<<1,1>>>(kers, basis->b_type, dim, poly_order, bckey_d); - + fem_poisson_set_cu_l2gker_ptrs<<<1, 1> > >(kers, basis->b_type, dim, poly_order, bckey_d); + // Biasing kernels (set this before redefining bckey_d below). - fem_poisson_set_cu_biasker_ptrs<<<1,1>>>(kers, basis->b_type, dim, poly_order, bckey_d); - - for (int d=0; dndim; d++) { - if (bcs->lo_type[d]==GKYL_POISSON_PERIODIC && bcs->up_type[d]==GKYL_POISSON_PERIODIC ) { bckey[d] = 0; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 1; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_NEUMANN ) { bckey[d] = 2; } - else if (bcs->lo_type[d]==GKYL_POISSON_NEUMANN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 3; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_ROBIN ) { bckey[d] = 4; } - else if (bcs->lo_type[d]==GKYL_POISSON_ROBIN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 5; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 6; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 7; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 8; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_NEUMANN ) { bckey[d] = 9; } - else if (bcs->lo_type[d]==GKYL_POISSON_NEUMANN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 10; } + fem_poisson_set_cu_biasker_ptrs<<<1, 1> > >(kers, basis->b_type, dim, poly_order, bckey_d); + + for (int d = 0; d < basis->ndim; d++) { + if (bcs->lo_type[d] == GKYL_POISSON_PERIODIC && bcs->up_type[d] == GKYL_POISSON_PERIODIC) { + bckey[d] = 0; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 1; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_NEUMANN) { + bckey[d] = 2; + } else if (bcs->lo_type[d] == GKYL_POISSON_NEUMANN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 3; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && bcs->up_type[d] == GKYL_POISSON_ROBIN) { + bckey[d] = 4; + } else if (bcs->lo_type[d] == GKYL_POISSON_ROBIN && bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 5; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 6; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 7; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 8; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_NEUMANN) { + bckey[d] = 9; + } else if (bcs->lo_type[d] == GKYL_POISSON_NEUMANN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 10; + } // MF 2024/10/01: kernels for these two are not yet plugged into the big lists above. - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_ROBIN ) { bckey[d] = 11; } - else if (bcs->lo_type[d]==GKYL_POISSON_ROBIN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 12; } - else { assert(false); } + else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_ROBIN) { + bckey[d] = 11; + } else if (bcs->lo_type[d] == GKYL_POISSON_ROBIN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 12; + } else { + assert(false); + } }; gkyl_cu_memcpy(bckey_d, bckey, sizeof(int[GKYL_MAX_CDIM]), GKYL_CU_MEMCPY_H2D); - fem_poisson_set_cu_ker_ptrs<<<1,1>>>(kers, basis->b_type, dim, poly_order, bckey_d, isvareps); + fem_poisson_set_cu_ker_ptrs<<<1, 1> > >(kers, basis->b_type, dim, poly_order, bckey_d, isvareps); gkyl_cu_free(bckey_d); } -__global__ void -gkyl_fem_poisson_set_rhs_kernel(struct gkyl_array *epsilon, bool isvareps, const double *dx, double *rhs_global, - struct gkyl_array *rhs_local, struct gkyl_range range, const double *bcvals, const struct gkyl_array *phibc, - struct gkyl_fem_poisson_kernels *kers) +__global__ void gkyl_fem_poisson_set_rhs_kernel( + struct gkyl_array *epsilon, bool isvareps, const double *dx, double *rhs_global, + struct gkyl_array *rhs_local, struct gkyl_range range, const double *bcvals, + const struct gkyl_array *phibc, struct gkyl_fem_poisson_kernels *kers +) { - int idx[GKYL_MAX_CDIM]; int idx0[GKYL_MAX_CDIM]; int num_cells[GKYL_MAX_CDIM]; + int idx[GKYL_MAX_CDIM]; + int idx0[GKYL_MAX_CDIM]; + int num_cells[GKYL_MAX_CDIM]; long globalidx[32]; - for (int d=0; dl2g[keri](num_cells, idx0, globalidx); // Apply the RHS source stencil. It's mostly the mass matrix times a @@ -216,31 +246,36 @@ gkyl_fem_poisson_set_rhs_kernel(struct gkyl_array *epsilon, bool isvareps, const } } -__global__ void -gkyl_fem_poisson_get_sol_kernel(struct gkyl_array *x_local, const double *x_global, - struct gkyl_range range, struct gkyl_fem_poisson_kernels *kers) +__global__ void gkyl_fem_poisson_get_sol_kernel( + struct gkyl_array *x_local, const double *x_global, struct gkyl_range range, + struct gkyl_fem_poisson_kernels *kers +) { - int idx[GKYL_MAX_CDIM]; int idx0[GKYL_MAX_CDIM]; int num_cells[GKYL_MAX_CDIM]; + int idx[GKYL_MAX_CDIM]; + int idx0[GKYL_MAX_CDIM]; + int num_cells[GKYL_MAX_CDIM]; long globalidx[32]; - for (int d=0; dl2g[keri](num_cells, idx0, globalidx); // Apply the RHS source stencil. It's mostly the mass matrix times a @@ -249,73 +284,80 @@ gkyl_fem_poisson_get_sol_kernel(struct gkyl_array *x_local, const double *x_glob } } -__global__ void -gkyl_fem_poisson_bias_src_kernel(double *rhs_global, struct gkyl_rect_grid grid, - struct gkyl_range range, struct gkyl_fem_poisson_kernels *kers, - int num_bias_plane, struct gkyl_poisson_bias_plane *bias_planes) +__global__ void gkyl_fem_poisson_bias_src_kernel( + double *rhs_global, struct gkyl_rect_grid grid, struct gkyl_range range, + struct gkyl_fem_poisson_kernels *kers, int num_bias_plane, + struct gkyl_poisson_bias_plane *bias_planes +) { - int idx[GKYL_MAX_CDIM]; int idx0[GKYL_MAX_CDIM]; int num_cells[GKYL_MAX_CDIM]; + int idx[GKYL_MAX_CDIM]; + int idx0[GKYL_MAX_CDIM]; + int num_cells[GKYL_MAX_CDIM]; long globalidx[32]; - for (int d=0; dl2g[keri](num_cells, idx0, globalidx); // Modify the RHS source to enforce biasing of the solution. - for (int i=0; idir]; - int bp_idx_m = (bp->loc-1e-3*dx - grid.lower[bp->dir])/dx+1; + int bp_idx_m = (bp->loc - 1e-3 * dx - grid.lower[bp->dir]) / dx + 1; - if (idx[bp->dir] == bp_idx_m || idx[bp->dir] == bp_idx_m+1) { - kers->bias_src_ker[keri](-1+2*((bp_idx_m+1)-idx[bp->dir]), - bp->dir, bp->val, globalidx, rhs_global); + if (idx[bp->dir] == bp_idx_m || idx[bp->dir] == bp_idx_m + 1) { + kers->bias_src_ker[keri]( + -1 + 2 * ((bp_idx_m + 1) - idx[bp->dir]), bp->dir, bp->val, globalidx, rhs_global + ); } } } } -void -gkyl_fem_poisson_bias_src_enabled_cu(gkyl_fem_poisson *up, struct gkyl_array *rhsin) +void gkyl_fem_poisson_bias_src_enabled_cu(gkyl_fem_poisson *up, struct gkyl_array *rhsin) { double *rhs_cu = gkyl_culinsolver_get_rhs_ptr(up->prob_cu, 0); - gkyl_fem_poisson_bias_src_kernel<<nblocks, rhsin->nthreads>>>(rhs_cu, up->grid, - *up->solve_range, up->kernels_cu, up->num_bias_plane, up->bias_planes); -} + gkyl_fem_poisson_bias_src_kernel<<nblocks, rhsin->nthreads> > >( + rhs_cu, up->grid, *up->solve_range, up->kernels_cu, up->num_bias_plane, up->bias_planes + ); +} -void -gkyl_fem_poisson_set_rhs_cu(gkyl_fem_poisson *up, struct gkyl_array *rhsin, const struct gkyl_array *phibc) +void gkyl_fem_poisson_set_rhs_cu( + gkyl_fem_poisson *up, struct gkyl_array *rhsin, const struct gkyl_array *phibc +) { gkyl_culinsolver_clear_rhs(up->prob_cu, 0); double *rhs_cu = gkyl_culinsolver_get_rhs_ptr(up->prob_cu, 0); - const struct gkyl_array *phibc_cu = phibc? phibc->on_dev : NULL; - gkyl_fem_poisson_set_rhs_kernel<<nblocks, rhsin->nthreads>>>(up->epsilon->on_dev, - up->isvareps, up->dx_cu, rhs_cu, rhsin->on_dev, *up->solve_range, up->bcvals_cu, - phibc_cu, up->kernels_cu); + const struct gkyl_array *phibc_cu = phibc ? phibc->on_dev : NULL; + gkyl_fem_poisson_set_rhs_kernel<<nblocks, rhsin->nthreads> > >( + up->epsilon->on_dev, up->isvareps, up->dx_cu, rhs_cu, rhsin->on_dev, *up->solve_range, + up->bcvals_cu, phibc_cu, up->kernels_cu + ); // Set the corresponding entries to the biasing potential. up->bias_plane_src(up, rhsin); -} +} -void -gkyl_fem_poisson_solve_cu(gkyl_fem_poisson *up, struct gkyl_array *phiout) +void gkyl_fem_poisson_solve_cu(gkyl_fem_poisson *up, struct gkyl_array *phiout) { // Do linear solve with cusolver. gkyl_culinsolver_solve(up->prob_cu); double *x_cu = gkyl_culinsolver_get_sol_ptr(up->prob_cu, 0); - gkyl_fem_poisson_get_sol_kernel<<nblocks, phiout->nthreads>>>(phiout->on_dev, - x_cu, *up->solve_range, up->kernels_cu); + gkyl_fem_poisson_get_sol_kernel<<nblocks, phiout->nthreads> > >( + phiout->on_dev, x_cu, *up->solve_range, up->kernels_cu + ); } - diff --git a/moments/zero/gkyl_fem_poisson.h b/moments/zero/gkyl_fem_poisson.h index 99c4847f60..cf6f074454 100644 --- a/moments/zero/gkyl_fem_poisson.h +++ b/moments/zero/gkyl_fem_poisson.h @@ -36,10 +36,12 @@ typedef struct gkyl_fem_poisson gkyl_fem_poisson; * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -struct gkyl_fem_poisson* gkyl_fem_poisson_new( - const struct gkyl_range *solve_range, const struct gkyl_rect_grid *grid, const struct gkyl_basis basis, - struct gkyl_poisson_bc *bcs, struct gkyl_poisson_bias_plane_list* bias_plane_list, struct gkyl_array *epsilon_var, - struct gkyl_array *kSq, bool is_epsilon_const, bool use_gpu); +struct gkyl_fem_poisson *gkyl_fem_poisson_new( + const struct gkyl_range *solve_range, const struct gkyl_rect_grid *grid, + const struct gkyl_basis basis, struct gkyl_poisson_bc *bcs, + struct gkyl_poisson_bias_plane_list *bias_plane_list, struct gkyl_array *epsilon_var, + struct gkyl_array *kSq, bool is_epsilon_const, bool use_gpu +); /** * Assign the right-side vector with the discontinuous (DG) source field. @@ -49,14 +51,16 @@ struct gkyl_fem_poisson* gkyl_fem_poisson_new( * @param phibc Spatially varying BC as a DG (volume) field, defined in the whole domain but really only applicable to and used in the skin cell. */ -void gkyl_fem_poisson_set_rhs(gkyl_fem_poisson* up, struct gkyl_array *rhsin, const struct gkyl_array *phibc); +void gkyl_fem_poisson_set_rhs( + gkyl_fem_poisson *up, struct gkyl_array *rhsin, const struct gkyl_array *phibc +); /** * Solve the linear problem. * * @param up FEM project updater to run. */ -void gkyl_fem_poisson_solve(gkyl_fem_poisson* up, struct gkyl_array *phiout); +void gkyl_fem_poisson_solve(gkyl_fem_poisson *up, struct gkyl_array *phiout); /** * Delete updater. diff --git a/moments/zero/gkyl_fem_poisson_bctype.h b/moments/zero/gkyl_fem_poisson_bctype.h index 3a9f923e3a..e824201dc6 100644 --- a/moments/zero/gkyl_fem_poisson_bctype.h +++ b/moments/zero/gkyl_fem_poisson_bctype.h @@ -8,13 +8,15 @@ enum gkyl_poisson_bc_type { GKYL_POISSON_PERIODIC = 0, GKYL_POISSON_DIRICHLET, // Sets the value. GKYL_POISSON_NEUMANN, // Sets the slope normal to the boundary. - GKYL_POISSON_ROBIN, // A combination of dirichlet and neumann. - GKYL_POISSON_DIRICHLET_VARYING, // Sets the value, spatially varying. + GKYL_POISSON_ROBIN, // A combination of dirichlet and neumann. + GKYL_POISSON_DIRICHLET_VARYING // Sets the value, spatially varying. }; // Boundary condition values. Dirichlet and Neumann use only one value, // Robin uses 3, and periodic ignores the value. -struct gkyl_poisson_bc_value { double v[3]; }; +struct gkyl_poisson_bc_value { + double v[3]; +}; struct gkyl_poisson_bias_plane { int dir; // Direction perpendicular to the plane. @@ -30,8 +32,8 @@ struct gkyl_poisson_bias_plane_list { struct gkyl_poisson_bias_line { // Directions perpendicular to the line and coordinates in those directions // (in 3D space; for 2x sims value in 3rd direction is ignored). - int perp_dirs[GKYL_MAX_CDIM-1]; - double perp_coords[GKYL_MAX_CDIM-1]; + int perp_dirs[GKYL_MAX_CDIM - 1]; + double perp_coords[GKYL_MAX_CDIM - 1]; double val; // Biasing value. }; diff --git a/moments/zero/gkyl_fem_poisson_priv.h b/moments/zero/gkyl_fem_poisson_priv.h index cfa1704492..b474922bad 100644 --- a/moments/zero/gkyl_fem_poisson_priv.h +++ b/moments/zero/gkyl_fem_poisson_priv.h @@ -8,1887 +8,6223 @@ #endif #ifndef GKYL_IPOW -# define GKYL_IPOW(a,e) (int)(pow(a,e)+0.5) +#define GKYL_IPOW(a, e) (int)(pow(a, e) + 0.5) #endif // Function pointer type for local-to-global mapping. -typedef void (*local2global_t)(const int *numCells, const int *idx, - long *globalIdxs); +typedef void (*local2global_t)(const int *numCells, const int *idx, long *globalIdxs); // For use in kernel tables. -typedef struct { local2global_t kernels[2]; } local2global_kern_loc_list_1x; -typedef struct { local2global_kern_loc_list_1x list[3]; } local2global_kern_bcx_list_1x; +typedef struct { + local2global_t kernels[2]; +} local2global_kern_loc_list_1x; +typedef struct { + local2global_kern_loc_list_1x list[3]; +} local2global_kern_bcx_list_1x; -typedef struct { local2global_t kernels[4]; } local2global_kern_loc_list_2x; -typedef struct { local2global_kern_loc_list_2x list[3]; } local2global_kern_bcy_list_2x; -typedef struct { local2global_kern_bcy_list_2x list[2]; } local2global_kern_bcx_list_2x; +typedef struct { + local2global_t kernels[4]; +} local2global_kern_loc_list_2x; +typedef struct { + local2global_kern_loc_list_2x list[3]; +} local2global_kern_bcy_list_2x; +typedef struct { + local2global_kern_bcy_list_2x list[2]; +} local2global_kern_bcx_list_2x; // Serendipity local-to-global kernels. -GKYL_CU_D -static const local2global_kern_bcx_list_1x ser_loc2glob_list_1x[] = { +GKYL_CU_D static const local2global_kern_bcx_list_1x ser_loc2glob_list_1x[] = { // periodicx - { .list = {{NULL, NULL}, - {fem_poisson_local_to_global_1x_ser_p1_inx_periodicx, fem_poisson_local_to_global_1x_ser_p1_upx_periodicx}, - {fem_poisson_local_to_global_1x_ser_p2_inx_periodicx, fem_poisson_local_to_global_1x_ser_p2_upx_periodicx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_local_to_global_1x_ser_p1_inx_periodicx, + fem_poisson_local_to_global_1x_ser_p1_upx_periodicx}, + {fem_poisson_local_to_global_1x_ser_p2_inx_periodicx, + fem_poisson_local_to_global_1x_ser_p2_upx_periodicx}}}, // nonperiodicx - { .list = {{NULL, NULL}, - {fem_poisson_local_to_global_1x_ser_p1_inx_nonperiodicx, fem_poisson_local_to_global_1x_ser_p1_upx_nonperiodicx}, - {fem_poisson_local_to_global_1x_ser_p2_inx_nonperiodicx, fem_poisson_local_to_global_1x_ser_p2_upx_nonperiodicx}}, } + {.list = + {{NULL, NULL}, + {fem_poisson_local_to_global_1x_ser_p1_inx_nonperiodicx, + fem_poisson_local_to_global_1x_ser_p1_upx_nonperiodicx}, + {fem_poisson_local_to_global_1x_ser_p2_inx_nonperiodicx, + fem_poisson_local_to_global_1x_ser_p2_upx_nonperiodicx}}} }; -GKYL_CU_D -static const local2global_kern_bcx_list_2x ser_loc2glob_list_2x[] = { - // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_local_to_global_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_local_to_global_2x_ser_p1_upx_periodicx_upy_periodicy}, - {fem_poisson_local_to_global_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_local_to_global_2x_ser_p2_upx_periodicx_upy_periodicy}}, - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_local_to_global_2x_ser_p1_inx_periodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p1_upx_periodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p1_inx_periodicx_upy_nonperiodicy, fem_poisson_local_to_global_2x_ser_p1_upx_periodicx_upy_nonperiodicy}, - {fem_poisson_local_to_global_2x_ser_p2_inx_periodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p2_upx_periodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p2_inx_periodicx_upy_nonperiodicy, fem_poisson_local_to_global_2x_ser_p2_upx_periodicx_upy_nonperiodicy},} - }} - }, - // nonperiodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_local_to_global_2x_ser_p1_inx_nonperiodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p1_upx_nonperiodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p1_inx_nonperiodicx_upy_periodicy, fem_poisson_local_to_global_2x_ser_p1_upx_nonperiodicx_upy_periodicy}, - {fem_poisson_local_to_global_2x_ser_p2_inx_nonperiodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p2_upx_nonperiodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p2_inx_nonperiodicx_upy_periodicy, fem_poisson_local_to_global_2x_ser_p2_upx_nonperiodicx_upy_periodicy}}, - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_local_to_global_2x_ser_p1_inx_nonperiodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p1_upx_nonperiodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p1_inx_nonperiodicx_upy_nonperiodicy, fem_poisson_local_to_global_2x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, - {fem_poisson_local_to_global_2x_ser_p2_inx_nonperiodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p2_upx_nonperiodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p2_inx_nonperiodicx_upy_nonperiodicy, fem_poisson_local_to_global_2x_ser_p2_upx_nonperiodicx_upy_nonperiodicy},} - }} - } +GKYL_CU_D static const local2global_kern_bcx_list_2x + ser_loc2glob_list_2x[] = + { + // periodicx + {.list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_local_to_global_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_local_to_global_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_local_to_global_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_local_to_global_2x_ser_p1_upx_periodicx_upy_periodicy}, + {fem_poisson_local_to_global_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_local_to_global_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_local_to_global_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_local_to_global_2x_ser_p2_upx_periodicx_upy_periodicy}}}, + // nonperiodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_local_to_global_2x_ser_p1_inx_periodicx_iny_nonperiodicy, + fem_poisson_local_to_global_2x_ser_p1_upx_periodicx_iny_nonperiodicy, + fem_poisson_local_to_global_2x_ser_p1_inx_periodicx_upy_nonperiodicy, + fem_poisson_local_to_global_2x_ser_p1_upx_periodicx_upy_nonperiodicy}, + {fem_poisson_local_to_global_2x_ser_p2_inx_periodicx_iny_nonperiodicy, + fem_poisson_local_to_global_2x_ser_p2_upx_periodicx_iny_nonperiodicy, + fem_poisson_local_to_global_2x_ser_p2_inx_periodicx_upy_nonperiodicy, + fem_poisson_local_to_global_2x_ser_p2_upx_periodicx_upy_nonperiodicy}}} + }}, + // nonperiodicx + { + .list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, {fem_poisson_local_to_global_2x_ser_p1_inx_nonperiodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p1_upx_nonperiodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p1_inx_nonperiodicx_upy_periodicy, fem_poisson_local_to_global_2x_ser_p1_upx_nonperiodicx_upy_periodicy}, {fem_poisson_local_to_global_2x_ser_p2_inx_nonperiodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p2_upx_nonperiodicx_iny_periodicy, fem_poisson_local_to_global_2x_ser_p2_inx_nonperiodicx_upy_periodicy, fem_poisson_local_to_global_2x_ser_p2_upx_nonperiodicx_upy_periodicy}} + }, + // nonperiodicy + {.list = {{NULL, NULL, NULL, NULL}, {fem_poisson_local_to_global_2x_ser_p1_inx_nonperiodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p1_upx_nonperiodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p1_inx_nonperiodicx_upy_nonperiodicy, fem_poisson_local_to_global_2x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, {fem_poisson_local_to_global_2x_ser_p2_inx_nonperiodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p2_upx_nonperiodicx_iny_nonperiodicy, fem_poisson_local_to_global_2x_ser_p2_inx_nonperiodicx_upy_nonperiodicy, fem_poisson_local_to_global_2x_ser_p2_upx_nonperiodicx_upy_nonperiodicy}} + } + } + } }; // Function pointer type for lhs kernels. -typedef void (*lhsstencil_t)(const double *epsilon, const double *kSq, const double *dx, const double *bcVals, - const long *globalIdxs, gkyl_mat_triples *tri); +typedef void (*lhsstencil_t)( + const double *epsilon, const double *kSq, const double *dx, const double *bcVals, + const long *globalIdxs, gkyl_mat_triples *tri +); // For use in kernel tables. -typedef struct { lhsstencil_t kernels[3]; } lhsstencil_kern_loc_list_1x; -typedef struct { lhsstencil_kern_loc_list_1x list[3]; } lhsstencil_kern_bcx_list_1x; +typedef struct { + lhsstencil_t kernels[3]; +} lhsstencil_kern_loc_list_1x; +typedef struct { + lhsstencil_kern_loc_list_1x list[3]; +} lhsstencil_kern_bcx_list_1x; -typedef struct { lhsstencil_t kernels[9]; } lhsstencil_kern_loc_list_2x; -typedef struct { lhsstencil_kern_loc_list_2x list[3]; } lhsstencil_kern_bcy_list_2x; -typedef struct { lhsstencil_kern_bcy_list_2x list[9]; } lhsstencil_kern_bcx_list_2x; +typedef struct { + lhsstencil_t kernels[9]; +} lhsstencil_kern_loc_list_2x; +typedef struct { + lhsstencil_kern_loc_list_2x list[3]; +} lhsstencil_kern_bcy_list_2x; +typedef struct { + lhsstencil_kern_bcy_list_2x list[9]; +} lhsstencil_kern_bcx_list_2x; // Serendipity lhs kernels. static const lhsstencil_kern_bcx_list_1x ser_lhsstencil_consteps_list_1x[] = { // periodicx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_periodicx}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_periodicx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_periodicx}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_periodicx}}}, // dirichletx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_dirichletx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_dirichletx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_dirichletx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_dirichletx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_dirichletx}}}, // dirichletx-neumannx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_dirichletx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_neumannx}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_dirichletx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_neumannx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_dirichletx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_neumannx}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_dirichletx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_neumannx}}}, // neumannx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_neumannx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_neumannx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_neumannx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_neumannx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_dirichletx}}}, // dirichletx-robinx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_dirichletx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_robinx}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_dirichletx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_robinx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_dirichletx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_robinx}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_dirichletx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_robinx}}}, // robinx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_robinx, fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_robinx, fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_lox_robinx, + fem_poisson_lhs_stencil_consteps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_lhs_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_lox_robinx, + fem_poisson_lhs_stencil_consteps_1x_ser_p2_upx_dirichletx}}} }; static const lhsstencil_kern_bcx_list_2x ser_lhsstencil_consteps_list_2x[] = { // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_upy_periodicy}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_upy_neumanny}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_upy_periodicy}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_upy_neumanny}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}}}, // dirichletx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}}}, // dirichletx-neumannx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_upy_periodicy}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_upy_neumanny}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_upy_periodicy}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_upy_neumanny}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}}}, // neumannx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_upy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_upy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - } - }, -}; + {.list = {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_upy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_upy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}}}}; static const lhsstencil_kern_bcx_list_1x ser_lhsstencil_vareps_list_1x[] = { // periodicx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_periodicx}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_periodicx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_periodicx}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_periodicx}}}, // dirichletx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_dirichletx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_dirichletx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_dirichletx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_dirichletx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_dirichletx}}}, // dirichletx-neumannx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_dirichletx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_neumannx}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_dirichletx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_neumannx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_dirichletx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_neumannx}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_dirichletx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_neumannx}}}, // neumannx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_neumannx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_neumannx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_neumannx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_neumannx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_dirichletx}}}, // dirichletx-robinx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_dirichletx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_robinx}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_dirichletx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_robinx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_dirichletx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_robinx}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_dirichletx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_robinx}}}, // robinx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_robinx, fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_robinx, fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_lox_robinx, + fem_poisson_lhs_stencil_vareps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_lhs_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_lox_robinx, + fem_poisson_lhs_stencil_vareps_1x_ser_p2_upx_dirichletx}}} }; static const lhsstencil_kern_bcx_list_2x ser_lhsstencil_vareps_list_2x[] = { // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_upy_periodicy}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_upy_neumanny}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_upy_periodicy}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_upy_neumanny}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}}}, // dirichletx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}}}, // dirichletx-neumannx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_upy_periodicy}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_upy_neumanny}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_upy_periodicy}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_upy_neumanny}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}}}, // neumannx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_upy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_upy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - } - }, -}; + {.list = {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_upy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_upy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_lhs_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}}}}; // Function pointer type for rhs source kernels. -typedef void (*srcstencil_t)(const double *epsilon, const double *dx, const double *rho, - const double *bcVals, const double *phiBC, const long *globalIdxs, double *bsrc); +typedef void (*srcstencil_t)( + const double *epsilon, const double *dx, const double *rho, const double *bcVals, + const double *phiBC, const long *globalIdxs, double *bsrc +); // For use in kernel tables. -typedef struct { srcstencil_t kernels[3]; } srcstencil_kern_loc_list_1x; -typedef struct { srcstencil_kern_loc_list_1x list[3]; } srcstencil_kern_bcx_list_1x; +typedef struct { + srcstencil_t kernels[3]; +} srcstencil_kern_loc_list_1x; +typedef struct { + srcstencil_kern_loc_list_1x list[3]; +} srcstencil_kern_bcx_list_1x; -typedef struct { srcstencil_t kernels[9]; } srcstencil_kern_loc_list_2x; -typedef struct { srcstencil_kern_loc_list_2x list[3]; } srcstencil_kern_bcy_list_2x; -typedef struct { srcstencil_kern_bcy_list_2x list[13]; } srcstencil_kern_bcx_list_2x; +typedef struct { + srcstencil_t kernels[9]; +} srcstencil_kern_loc_list_2x; +typedef struct { + srcstencil_kern_loc_list_2x list[3]; +} srcstencil_kern_bcy_list_2x; +typedef struct { + srcstencil_kern_bcy_list_2x list[13]; +} srcstencil_kern_bcx_list_2x; // Serendipity src kernels. -GKYL_CU_D -static const srcstencil_kern_bcx_list_1x ser_srcstencil_consteps_list_1x[] = { +GKYL_CU_D static const srcstencil_kern_bcx_list_1x ser_srcstencil_consteps_list_1x[] = { // periodicx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_periodicx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_periodicx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_periodicx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_periodicx}}}, // dirichletx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletx}}}, // dirichletx-neumannx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_neumannx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_neumannx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_neumannx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_neumannx}}}, // neumannx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_neumannx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_neumannx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_neumannx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_neumannx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletx}}}, // dirichletx-robinx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_robinx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_robinx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_robinx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_robinx}}}, // robinx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_robinx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_robinx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_robinx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_robinx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletx}}}, // dirichletx-dirichletvarx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletvarx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletvarx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletvarx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletvarx}}}, // dirichletvarx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletvarx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletvarx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletvarx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletvarx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletx}}}, // dirichletvarx-dirichletvarx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletvarx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletvarx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletvarx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletvarx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletvarx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletvarx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletvarx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletvarx}}}, // dirichletvarx-neumannx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletvarx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_neumannx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletvarx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_neumannx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletvarx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_neumannx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletvarx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_neumannx}}}, // neumannx-dirichletvarx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_neumannx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletvarx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_neumannx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletvarx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_neumannx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletvarx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_neumannx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletvarx}}}, // dirichletvarx-robinx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletvarx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_robinx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletvarx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_robinx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_dirichletvarx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_robinx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_dirichletvarx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_robinx}}}, // robinx-dirichletvarx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p1_lox_robinx, fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletvarx}, - {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_consteps_1x_ser_p2_lox_robinx, fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletvarx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_consteps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p1_lox_robinx, + fem_poisson_src_stencil_consteps_1x_ser_p1_upx_dirichletvarx}, + {fem_poisson_src_stencil_consteps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_consteps_1x_ser_p2_lox_robinx, + fem_poisson_src_stencil_consteps_1x_ser_p2_upx_dirichletvarx}}} }; -GKYL_CU_D -static const srcstencil_kern_bcx_list_2x ser_srcstencil_consteps_list_2x[] = { +GKYL_CU_D static const srcstencil_kern_bcx_list_2x ser_srcstencil_consteps_list_2x[] = { // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_periodicy}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_robiny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_periodicy}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_robiny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_periodicx_upy_dirichletvary}}}}}, // dirichletx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_robiny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_robiny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}}}, // dirichletx-neumannx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_periodicy}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_robiny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_periodicy}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_robiny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}}}, // neumannx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_robiny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_robiny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}}}, // dirichletx-robinx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_periodicy}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_robiny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_periodicy}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_robiny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_robinx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_robinx_upy_dirichletvary}}}}}, // robinx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_robiny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_robiny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}}}, // dirichletx-dirichletvarx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}}}, // dirichletvarx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_robiny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_robiny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}}}, // dirichletvarx-dirichletvarx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}}}, // dirichletvarx-neumannx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_periodicy}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_robiny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_periodicy}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_robiny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}}}, // neumannx-dirichletvarx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},} - }, - } - }, -}; + {.list = {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_consteps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}}}}; -GKYL_CU_D -static const srcstencil_kern_bcx_list_1x ser_srcstencil_vareps_list_1x[] = { +GKYL_CU_D static const srcstencil_kern_bcx_list_1x ser_srcstencil_vareps_list_1x[] = { // periodicx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_periodicx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_periodicx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_periodicx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_periodicx}}}, // dirichletx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletx}}}, // dirichletx-neumannx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_neumannx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_neumannx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_neumannx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_neumannx}}}, // neumannx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_neumannx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_neumannx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_neumannx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_neumannx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletx}}}, // dirichletx-robinx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_robinx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_robinx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_robinx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_robinx}}}, // robinx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_robinx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_robinx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_robinx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_robinx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletx}}}, // dirichletx-dirichletvarx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletvarx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletvarx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletvarx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletvarx}}}, // dirichletvarx-dirichletx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletvarx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletvarx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletvarx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletvarx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletx}}}, // dirichletvarx-dirichletvarx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletvarx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletvarx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletvarx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletvarx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletvarx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletvarx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletvarx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletvarx}}}, // dirichletvarx-neumannx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletvarx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_neumannx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletvarx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_neumannx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletvarx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_neumannx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletvarx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_neumannx}}}, // neumannx-dirichletvarx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_neumannx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletvarx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_neumannx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletvarx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_neumannx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletvarx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_neumannx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletvarx}}}, // dirichletvarx-robinx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletvarx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_robinx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletvarx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_robinx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_dirichletvarx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_robinx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_dirichletvarx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_robinx}}}, // robinx-dirichletvarx - { .list = {{NULL, NULL}, - {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p1_lox_robinx, fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletvarx}, - {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, fem_poisson_src_stencil_vareps_1x_ser_p2_lox_robinx, fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletvarx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_src_stencil_vareps_1x_ser_p1_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p1_lox_robinx, + fem_poisson_src_stencil_vareps_1x_ser_p1_upx_dirichletvarx}, + {fem_poisson_src_stencil_vareps_1x_ser_p2_inx_periodicx, + fem_poisson_src_stencil_vareps_1x_ser_p2_lox_robinx, + fem_poisson_src_stencil_vareps_1x_ser_p2_upx_dirichletvarx}}} }; -GKYL_CU_D -static const srcstencil_kern_bcx_list_2x ser_srcstencil_vareps_list_2x[] = { +GKYL_CU_D static const srcstencil_kern_bcx_list_2x ser_srcstencil_vareps_list_2x[] = { // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_periodicy}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_robiny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_periodicy}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_robiny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_periodicx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_periodicx_upy_dirichletvary}}}}}, // dirichletx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_robiny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_robiny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}}}, // dirichletx-neumannx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_periodicy}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_robiny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_periodicy}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_robiny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}}}, // neumannx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_robiny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_robiny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}}}, // dirichletx-robinx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_periodicy}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_robiny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_periodicy}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_robiny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_robinx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_robinx_upy_dirichletvary}}}}}, // robinx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_robiny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_robiny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_robinx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}}}, // dirichletx-dirichletvarx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}}}, // dirichletvarx-dirichletx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_robiny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_periodicy}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_robiny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletx_upy_dirichletvary}}}}}, // dirichletvarx-dirichletvarx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}}}, // dirichletvarx-neumannx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_periodicy}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_robiny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary},} - }, - } - }, + {.list = + {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_periodicy}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_robiny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_neumannx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_dirichletvarx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_neumannx_upy_dirichletvary}}}}}, // neumannx-dirichletvarx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_periodicy},}, - }, - // dirichlety-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichlety-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-robiny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_robiny},}, - }, - // robiny-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_robiny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},} - }, - // dirichlety-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-dirichlety - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety},}, - }, - // dirichletvary-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},}, - }, - // dirichletvary-neumanny - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny},}, - }, - // neumanny-dirichletvary - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, - {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary},} - }, - } - }, -}; + {.list = {// periodicy + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_periodicy}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_periodicy}}}, + // dirichlety-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-robiny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_robiny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_robiny}}}, + // robiny-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_robiny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichlety-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-dirichlety + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichlety}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichlety, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichlety}}}, + // dirichletvary-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}, + // dirichletvary-neumanny + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_neumanny}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_neumanny}}}, + // neumanny-dirichletvary + {.list = {{NULL, NULL, NULL, NULL}, + {fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p1_upx_dirichletvarx_upy_dirichletvary}, + {fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_iny_periodicy, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_inx_periodicx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_lox_neumannx_upy_dirichletvary, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_loy_neumanny, + fem_poisson_src_stencil_vareps_2x_ser_p2_upx_dirichletvarx_upy_dirichletvary}}}}}}; // Function pointer type for sol kernels. -typedef void (*solstencil_t)(const double *sol_nodal_global, const long *globalIdxs, double *sol_modal_local); +typedef void (*solstencil_t)( + const double *sol_nodal_global, const long *globalIdxs, double *sol_modal_local +); -typedef struct { solstencil_t kernels[3]; } solstencil_kern_list; +typedef struct { + solstencil_t kernels[3]; +} solstencil_kern_list; -GKYL_CU_D -static const solstencil_kern_list ser_solstencil_list[] = { - { NULL, NULL, NULL }, +GKYL_CU_D static const solstencil_kern_list ser_solstencil_list[] = { + {NULL, NULL, NULL}, // 1x kernels - { NULL, fem_poisson_sol_stencil_1x_ser_p1, fem_poisson_sol_stencil_1x_ser_p2 }, // 0 + {NULL, fem_poisson_sol_stencil_1x_ser_p1, fem_poisson_sol_stencil_1x_ser_p2}, // 0 // 2x kernels - { NULL, fem_poisson_sol_stencil_2x_ser_p1, fem_poisson_sol_stencil_2x_ser_p2 }, // 1 + {NULL, fem_poisson_sol_stencil_2x_ser_p1, fem_poisson_sol_stencil_2x_ser_p2} // 1 }; // Function pointer type for kernels that enforce biasing in LHS matrix. typedef void (*bias_lhs_t)(int edge, int dir, const long *globalIdxs, gkyl_mat_triples *tri); // For use in kernel tables. -typedef struct { bias_lhs_t kernels[2]; } bias_lhs_kern_loc_list_1x; -typedef struct { bias_lhs_kern_loc_list_1x list[3]; } bias_lhs_kern_bcx_list_1x; +typedef struct { + bias_lhs_t kernels[2]; +} bias_lhs_kern_loc_list_1x; +typedef struct { + bias_lhs_kern_loc_list_1x list[3]; +} bias_lhs_kern_bcx_list_1x; -typedef struct { bias_lhs_t kernels[4]; } bias_lhs_kern_loc_list_2x; -typedef struct { bias_lhs_kern_loc_list_2x list[3]; } bias_lhs_kern_bcy_list_2x; -typedef struct { bias_lhs_kern_bcy_list_2x list[2]; } bias_lhs_kern_bcx_list_2x; +typedef struct { + bias_lhs_t kernels[4]; +} bias_lhs_kern_loc_list_2x; +typedef struct { + bias_lhs_kern_loc_list_2x list[3]; +} bias_lhs_kern_bcy_list_2x; +typedef struct { + bias_lhs_kern_bcy_list_2x list[2]; +} bias_lhs_kern_bcx_list_2x; // Serendipity bias_lhs kernels. static const bias_lhs_kern_bcx_list_1x ser_bias_lhs_list_1x[] = { // periodicx - { .list = {{NULL, NULL}, - {fem_poisson_bias_plane_lhs_1x_ser_p1_inx, fem_poisson_bias_plane_lhs_1x_ser_p1_upx_periodicx}, - {fem_poisson_bias_plane_lhs_1x_ser_p2_inx, fem_poisson_bias_plane_lhs_1x_ser_p2_upx_periodicx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_bias_plane_lhs_1x_ser_p1_inx, fem_poisson_bias_plane_lhs_1x_ser_p1_upx_periodicx}, + {fem_poisson_bias_plane_lhs_1x_ser_p2_inx, fem_poisson_bias_plane_lhs_1x_ser_p2_upx_periodicx} + }}, // nonperiodicx - { .list = {{NULL, NULL}, - {fem_poisson_bias_plane_lhs_1x_ser_p1_inx, fem_poisson_bias_plane_lhs_1x_ser_p1_upx_nonperiodicx}, - {fem_poisson_bias_plane_lhs_1x_ser_p2_inx, fem_poisson_bias_plane_lhs_1x_ser_p2_upx_nonperiodicx}}, } + {.list = + {{NULL, NULL}, + {fem_poisson_bias_plane_lhs_1x_ser_p1_inx, + fem_poisson_bias_plane_lhs_1x_ser_p1_upx_nonperiodicx}, + {fem_poisson_bias_plane_lhs_1x_ser_p2_inx, + fem_poisson_bias_plane_lhs_1x_ser_p2_upx_nonperiodicx}}} }; -static const bias_lhs_kern_bcx_list_2x ser_bias_lhs_list_2x[] = { - // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_bias_plane_lhs_2x_ser_p1_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_periodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_inx_upy_periodicy, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_periodicx_upy_periodicy}, - {fem_poisson_bias_plane_lhs_2x_ser_p2_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_periodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_inx_upy_periodicy, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_periodicx_upy_periodicy}}, - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_bias_plane_lhs_2x_ser_p1_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_periodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_inx_upy_nonperiodicy, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_periodicx_upy_nonperiodicy}, - {fem_poisson_bias_plane_lhs_2x_ser_p2_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_periodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_inx_upy_nonperiodicy, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_periodicx_upy_nonperiodicy},} - }} - }, - // nonperiodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_bias_plane_lhs_2x_ser_p1_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_nonperiodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_inx_upy_periodicy, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_nonperiodicx_upy_periodicy}, - {fem_poisson_bias_plane_lhs_2x_ser_p2_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_nonperiodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_inx_upy_periodicy, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_nonperiodicx_upy_periodicy}}, - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_bias_plane_lhs_2x_ser_p1_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_nonperiodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_inx_upy_nonperiodicy, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, - {fem_poisson_bias_plane_lhs_2x_ser_p2_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_nonperiodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_inx_upy_nonperiodicy, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_nonperiodicx_upy_nonperiodicy},} - }} - } +static const bias_lhs_kern_bcx_list_2x + ser_bias_lhs_list_2x[] = + { + // periodicx + {.list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_bias_plane_lhs_2x_ser_p1_inx_iny, + fem_poisson_bias_plane_lhs_2x_ser_p1_upx_periodicx_iny, + fem_poisson_bias_plane_lhs_2x_ser_p1_inx_upy_periodicy, + fem_poisson_bias_plane_lhs_2x_ser_p1_upx_periodicx_upy_periodicy}, + {fem_poisson_bias_plane_lhs_2x_ser_p2_inx_iny, + fem_poisson_bias_plane_lhs_2x_ser_p2_upx_periodicx_iny, + fem_poisson_bias_plane_lhs_2x_ser_p2_inx_upy_periodicy, + fem_poisson_bias_plane_lhs_2x_ser_p2_upx_periodicx_upy_periodicy}}}, + // nonperiodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_bias_plane_lhs_2x_ser_p1_inx_iny, + fem_poisson_bias_plane_lhs_2x_ser_p1_upx_periodicx_iny, + fem_poisson_bias_plane_lhs_2x_ser_p1_inx_upy_nonperiodicy, + fem_poisson_bias_plane_lhs_2x_ser_p1_upx_periodicx_upy_nonperiodicy}, + {fem_poisson_bias_plane_lhs_2x_ser_p2_inx_iny, + fem_poisson_bias_plane_lhs_2x_ser_p2_upx_periodicx_iny, + fem_poisson_bias_plane_lhs_2x_ser_p2_inx_upy_nonperiodicy, + fem_poisson_bias_plane_lhs_2x_ser_p2_upx_periodicx_upy_nonperiodicy}}} + }}, + // nonperiodicx + { + .list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, {fem_poisson_bias_plane_lhs_2x_ser_p1_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_nonperiodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_inx_upy_periodicy, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_nonperiodicx_upy_periodicy}, {fem_poisson_bias_plane_lhs_2x_ser_p2_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_nonperiodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_inx_upy_periodicy, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_nonperiodicx_upy_periodicy}} + }, + // nonperiodicy + {.list = {{NULL, NULL, NULL, NULL}, {fem_poisson_bias_plane_lhs_2x_ser_p1_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_nonperiodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p1_inx_upy_nonperiodicy, fem_poisson_bias_plane_lhs_2x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, {fem_poisson_bias_plane_lhs_2x_ser_p2_inx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_nonperiodicx_iny, fem_poisson_bias_plane_lhs_2x_ser_p2_inx_upy_nonperiodicy, fem_poisson_bias_plane_lhs_2x_ser_p2_upx_nonperiodicx_upy_nonperiodicy}} + } + } + } }; // Function pointer type for kernels that enforce biasing in RHS source. typedef void (*bias_src_t)(int edge, int dir, double val, const long *globalIdxs, double *bsrc); // For use in kernel tables. -typedef struct { bias_src_t kernels[2]; } bias_src_kern_loc_list_1x; -typedef struct { bias_src_kern_loc_list_1x list[3]; } bias_src_kern_bcx_list_1x; +typedef struct { + bias_src_t kernels[2]; +} bias_src_kern_loc_list_1x; +typedef struct { + bias_src_kern_loc_list_1x list[3]; +} bias_src_kern_bcx_list_1x; -typedef struct { bias_src_t kernels[4]; } bias_src_kern_loc_list_2x; -typedef struct { bias_src_kern_loc_list_2x list[3]; } bias_src_kern_bcy_list_2x; -typedef struct { bias_src_kern_bcy_list_2x list[2]; } bias_src_kern_bcx_list_2x; +typedef struct { + bias_src_t kernels[4]; +} bias_src_kern_loc_list_2x; +typedef struct { + bias_src_kern_loc_list_2x list[3]; +} bias_src_kern_bcy_list_2x; +typedef struct { + bias_src_kern_bcy_list_2x list[2]; +} bias_src_kern_bcx_list_2x; // Serendipity bias_src kernels. -GKYL_CU_D -static const bias_src_kern_bcx_list_1x ser_bias_src_list_1x[] = { +GKYL_CU_D static const bias_src_kern_bcx_list_1x ser_bias_src_list_1x[] = { // periodicx - { .list = {{NULL, NULL}, - {fem_poisson_bias_plane_src_1x_ser_p1_inx, fem_poisson_bias_plane_src_1x_ser_p1_upx_periodicx}, - {fem_poisson_bias_plane_src_1x_ser_p2_inx, fem_poisson_bias_plane_src_1x_ser_p2_upx_periodicx}}, }, + {.list = + {{NULL, NULL}, + {fem_poisson_bias_plane_src_1x_ser_p1_inx, fem_poisson_bias_plane_src_1x_ser_p1_upx_periodicx}, + {fem_poisson_bias_plane_src_1x_ser_p2_inx, fem_poisson_bias_plane_src_1x_ser_p2_upx_periodicx} + }}, // nonperiodicx - { .list = {{NULL, NULL}, - {fem_poisson_bias_plane_src_1x_ser_p1_inx, fem_poisson_bias_plane_src_1x_ser_p1_upx_nonperiodicx}, - {fem_poisson_bias_plane_src_1x_ser_p2_inx, fem_poisson_bias_plane_src_1x_ser_p2_upx_nonperiodicx}}, } + {.list = + {{NULL, NULL}, + {fem_poisson_bias_plane_src_1x_ser_p1_inx, + fem_poisson_bias_plane_src_1x_ser_p1_upx_nonperiodicx}, + {fem_poisson_bias_plane_src_1x_ser_p2_inx, + fem_poisson_bias_plane_src_1x_ser_p2_upx_nonperiodicx}}} }; -GKYL_CU_D -static const bias_src_kern_bcx_list_2x ser_bias_src_list_2x[] = { - // periodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_bias_plane_src_2x_ser_p1_inx_iny, fem_poisson_bias_plane_src_2x_ser_p1_upx_periodicx_iny, fem_poisson_bias_plane_src_2x_ser_p1_inx_upy_periodicy, fem_poisson_bias_plane_src_2x_ser_p1_upx_periodicx_upy_periodicy}, - {fem_poisson_bias_plane_src_2x_ser_p2_inx_iny, fem_poisson_bias_plane_src_2x_ser_p2_upx_periodicx_iny, fem_poisson_bias_plane_src_2x_ser_p2_inx_upy_periodicy, fem_poisson_bias_plane_src_2x_ser_p2_upx_periodicx_upy_periodicy}}, - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_bias_plane_src_2x_ser_p1_inx_iny, fem_poisson_bias_plane_src_2x_ser_p1_upx_periodicx_iny, fem_poisson_bias_plane_src_2x_ser_p1_inx_upy_nonperiodicy, fem_poisson_bias_plane_src_2x_ser_p1_upx_periodicx_upy_nonperiodicy}, - {fem_poisson_bias_plane_src_2x_ser_p2_inx_iny, fem_poisson_bias_plane_src_2x_ser_p2_upx_periodicx_iny, fem_poisson_bias_plane_src_2x_ser_p2_inx_upy_nonperiodicy, fem_poisson_bias_plane_src_2x_ser_p2_upx_periodicx_upy_nonperiodicy},} - }} - }, - // nonperiodicx - { .list = { - // periodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_bias_plane_src_2x_ser_p1_inx_iny, fem_poisson_bias_plane_src_2x_ser_p1_upx_nonperiodicx_iny, fem_poisson_bias_plane_src_2x_ser_p1_inx_upy_periodicy, fem_poisson_bias_plane_src_2x_ser_p1_upx_nonperiodicx_upy_periodicy}, - {fem_poisson_bias_plane_src_2x_ser_p2_inx_iny, fem_poisson_bias_plane_src_2x_ser_p2_upx_nonperiodicx_iny, fem_poisson_bias_plane_src_2x_ser_p2_inx_upy_periodicy, fem_poisson_bias_plane_src_2x_ser_p2_upx_nonperiodicx_upy_periodicy}}, - }, - // nonperiodicy - { .list = {{NULL, NULL, NULL, NULL}, - {fem_poisson_bias_plane_src_2x_ser_p1_inx_iny, fem_poisson_bias_plane_src_2x_ser_p1_upx_nonperiodicx_iny, fem_poisson_bias_plane_src_2x_ser_p1_inx_upy_nonperiodicy, fem_poisson_bias_plane_src_2x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, - {fem_poisson_bias_plane_src_2x_ser_p2_inx_iny, fem_poisson_bias_plane_src_2x_ser_p2_upx_nonperiodicx_iny, fem_poisson_bias_plane_src_2x_ser_p2_inx_upy_nonperiodicy, fem_poisson_bias_plane_src_2x_ser_p2_upx_nonperiodicx_upy_nonperiodicy},} - }} - } +GKYL_CU_D static const bias_src_kern_bcx_list_2x + ser_bias_src_list_2x[] = + { + // periodicx + {.list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_bias_plane_src_2x_ser_p1_inx_iny, + fem_poisson_bias_plane_src_2x_ser_p1_upx_periodicx_iny, + fem_poisson_bias_plane_src_2x_ser_p1_inx_upy_periodicy, + fem_poisson_bias_plane_src_2x_ser_p1_upx_periodicx_upy_periodicy}, + {fem_poisson_bias_plane_src_2x_ser_p2_inx_iny, + fem_poisson_bias_plane_src_2x_ser_p2_upx_periodicx_iny, + fem_poisson_bias_plane_src_2x_ser_p2_inx_upy_periodicy, + fem_poisson_bias_plane_src_2x_ser_p2_upx_periodicx_upy_periodicy}}}, + // nonperiodicy + {.list = + {{NULL, NULL, NULL, NULL}, + {fem_poisson_bias_plane_src_2x_ser_p1_inx_iny, + fem_poisson_bias_plane_src_2x_ser_p1_upx_periodicx_iny, + fem_poisson_bias_plane_src_2x_ser_p1_inx_upy_nonperiodicy, + fem_poisson_bias_plane_src_2x_ser_p1_upx_periodicx_upy_nonperiodicy}, + {fem_poisson_bias_plane_src_2x_ser_p2_inx_iny, + fem_poisson_bias_plane_src_2x_ser_p2_upx_periodicx_iny, + fem_poisson_bias_plane_src_2x_ser_p2_inx_upy_nonperiodicy, + fem_poisson_bias_plane_src_2x_ser_p2_upx_periodicx_upy_nonperiodicy}}} + }}, + // nonperiodicx + { + .list = + {// periodicy + {.list = + {{NULL, NULL, NULL, NULL}, {fem_poisson_bias_plane_src_2x_ser_p1_inx_iny, fem_poisson_bias_plane_src_2x_ser_p1_upx_nonperiodicx_iny, fem_poisson_bias_plane_src_2x_ser_p1_inx_upy_periodicy, fem_poisson_bias_plane_src_2x_ser_p1_upx_nonperiodicx_upy_periodicy}, {fem_poisson_bias_plane_src_2x_ser_p2_inx_iny, fem_poisson_bias_plane_src_2x_ser_p2_upx_nonperiodicx_iny, fem_poisson_bias_plane_src_2x_ser_p2_inx_upy_periodicy, fem_poisson_bias_plane_src_2x_ser_p2_upx_nonperiodicx_upy_periodicy}} + }, + // nonperiodicy + {.list = {{NULL, NULL, NULL, NULL}, {fem_poisson_bias_plane_src_2x_ser_p1_inx_iny, fem_poisson_bias_plane_src_2x_ser_p1_upx_nonperiodicx_iny, fem_poisson_bias_plane_src_2x_ser_p1_inx_upy_nonperiodicy, fem_poisson_bias_plane_src_2x_ser_p1_upx_nonperiodicx_upy_nonperiodicy}, {fem_poisson_bias_plane_src_2x_ser_p2_inx_iny, fem_poisson_bias_plane_src_2x_ser_p2_upx_nonperiodicx_iny, fem_poisson_bias_plane_src_2x_ser_p2_inx_upy_nonperiodicy, fem_poisson_bias_plane_src_2x_ser_p2_upx_nonperiodicx_upy_nonperiodicy}} + } + } + } }; // "Choose Kernel" based on cdim, vdim and polyorder -#define CK1(lst,poly_order,loc,bcx) lst[bcx].list[poly_order].kernels[loc] -#define CK2(lst,poly_order,loc,bcx,bcy) lst[bcx].list[bcy].list[poly_order].kernels[loc] -#define CK3(lst,poly_order,loc,bcx,bcy,bcz) lst[bcx].list[bcy].list[bcz].list[poly_order].kernels[loc] +#define CK1(lst, poly_order, loc, bcx) lst[bcx].list[poly_order].kernels[loc] +#define CK2(lst, poly_order, loc, bcx, bcy) lst[bcx].list[bcy].list[poly_order].kernels[loc] +#define CK3(lst, poly_order, loc, bcx, bcy, bcz) \ + lst[bcx].list[bcy].list[bcz].list[poly_order].kernels[loc] // Struct containing pointers to the various kernels. Needed to create a similar struct on the GPU. -struct gkyl_fem_poisson_kernels { +struct gkyl_fem_poisson_kernels { // Pointer to local-to-global kernels. 2^3, 2 (interior and upper) in each direction. local2global_t l2g[8]; @@ -1906,7 +6242,7 @@ struct gkyl_fem_poisson_kernels { }; // Type of function used to enforce biasing in the RHS src. -typedef void (*bias_src_func_t)(gkyl_fem_poisson* up, struct gkyl_array *rhsin); +typedef void (*bias_src_func_t)(gkyl_fem_poisson *up, struct gkyl_array *rhsin); // Updater type struct gkyl_fem_poisson { @@ -1934,7 +6270,8 @@ struct gkyl_fem_poisson { double *rhs_avg, mavgfac; double *rhs_avg_cu; - double bcvals[GKYL_MAX_CDIM*2*3]; // BC values, bc[0]*phi+bc[1]*d(phi)/dx=phi[3] at each boundary. + double + bcvals[GKYL_MAX_CDIM * 2 * 3]; // BC values, bc[0]*phi+bc[1]*d(phi)/dx=phi[3] at each boundary. double *bcvals_cu; // BC values, bc[0]*phi+bc[1]*d(phi)/dx=phi[3] at each boundary. const struct gkyl_range *solve_range; @@ -1943,7 +6280,7 @@ struct gkyl_fem_poisson { int numnodes_local; long numnodes_global; - struct gkyl_superlu_prob* prob; + struct gkyl_superlu_prob *prob; struct gkyl_array *brhs; #ifdef GKYL_HAVE_CUDA @@ -1959,18 +6296,20 @@ struct gkyl_fem_poisson { int num_bias_plane; // Number of biased planes. struct gkyl_poisson_bias_plane *bias_planes; // Biased planes. - bias_src_func_t bias_plane_src; // Function to enforce biasing in RHS source. + bias_src_func_t bias_plane_src; // Function to enforce biasing in RHS source. }; -void -fem_poisson_choose_kernels_cu(const struct gkyl_basis* basis, const struct gkyl_poisson_bc* bcs, - bool isvareps, const bool *isdirperiodic, struct gkyl_fem_poisson_kernels *kers); +void fem_poisson_choose_kernels_cu( + const struct gkyl_basis *basis, const struct gkyl_poisson_bc *bcs, bool isvareps, + const bool *isdirperiodic, struct gkyl_fem_poisson_kernels *kers +); -static long -gkyl_fem_poisson_global_num_nodes(const int dim, const int poly_order, - const int basis_type, const int *num_cells, bool *isdirperiodic) +static long gkyl_fem_poisson_global_num_nodes( + const int dim, const int poly_order, const int basis_type, const int *num_cells, + bool *isdirperiodic +) { - if (dim==1) { + if (dim == 1) { if (poly_order == 1) { if (isdirperiodic[0]) { return fem_poisson_num_nodes_global_1x_ser_p1_periodicx(num_cells); @@ -1984,7 +6323,7 @@ gkyl_fem_poisson_global_num_nodes(const int dim, const int poly_order, return fem_poisson_num_nodes_global_1x_ser_p2_nonperiodicx(num_cells); } } - } else if (dim==2) { + } else if (dim == 2) { if (poly_order == 1) { if (isdirperiodic[0] && isdirperiodic[1]) { return fem_poisson_num_nodes_global_2x_ser_p1_periodicx_periodicy(num_cells); @@ -2006,249 +6345,305 @@ gkyl_fem_poisson_global_num_nodes(const int dim, const int poly_order, return fem_poisson_num_nodes_global_2x_ser_p2_nonperiodicx_nonperiodicy(num_cells); } } - } else if (dim==3) { - assert(false); // Other dimensionalities not supported. + } else if (dim == 3) { + assert(false); // Other dimensionalities not supported. } - assert(false); // Other dimensionalities not supported. + assert(false); // Other dimensionalities not supported. return -1; } -GKYL_CU_D -static void -fem_poisson_choose_local2global_kernels(const struct gkyl_basis* basis, - const bool *isdirperiodic, local2global_t *l2gout) +GKYL_CU_D static void fem_poisson_choose_local2global_kernels( + const struct gkyl_basis *basis, const bool *isdirperiodic, local2global_t *l2gout +) { int dim = basis->ndim; int poly_order = basis->poly_order; int bckey[GKYL_MAX_CDIM] = {-1}; - for (int d=0; dndim; d++) bckey[d] = isdirperiodic[d] ? 0 : 1; + for (int d = 0; d < basis->ndim; d++) { + bckey[d] = isdirperiodic[d] ? 0 : 1; + } switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<(int)(pow(2,dim)+0.5); k++) { - if (dim == 1) { - l2gout[k] = CK1(ser_loc2glob_list_1x, poly_order, k, bckey[0]); - } else if (dim == 2) { - l2gout[k] = CK2(ser_loc2glob_list_2x, poly_order, k, bckey[0], bckey[1]); -// } else if (dim == 3) { -// l2gout[k] = CK3(ser_loc2glob_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); - } + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < (int)(pow(2, dim) + 0.5); k++) { + if (dim == 1) { + l2gout[k] = CK1(ser_loc2glob_list_1x, poly_order, k, bckey[0]); + } else if (dim == 2) { + l2gout[k] = CK2(ser_loc2glob_list_2x, poly_order, k, bckey[0], bckey[1]); + // } else if (dim == 3) { + // l2gout[k] = CK3(ser_loc2glob_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); } - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + } + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } } -GKYL_CU_D -static void -fem_poisson_choose_lhs_kernels(const struct gkyl_basis* basis, const struct gkyl_poisson_bc *bcs, - bool isvareps, lhsstencil_t *lhsout) +GKYL_CU_D static void fem_poisson_choose_lhs_kernels( + const struct gkyl_basis *basis, const struct gkyl_poisson_bc *bcs, bool isvareps, + lhsstencil_t *lhsout +) { int dim = basis->ndim; int poly_order = basis->poly_order; int bckey[GKYL_MAX_CDIM] = {-1}; - for (int d=0; dndim; d++) { - if (bcs->lo_type[d]==GKYL_POISSON_PERIODIC && bcs->up_type[d]==GKYL_POISSON_PERIODIC ) { bckey[d] = 0; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 1; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_NEUMANN ) { bckey[d] = 2; } - else if (bcs->lo_type[d]==GKYL_POISSON_NEUMANN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 3; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_ROBIN ) { bckey[d] = 4; } - else if (bcs->lo_type[d]==GKYL_POISSON_ROBIN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 5; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 1; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 1; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 1; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_NEUMANN ) { bckey[d] = 2; } - else if (bcs->lo_type[d]==GKYL_POISSON_NEUMANN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 3; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_ROBIN ) { bckey[d] = 4; } - else if (bcs->lo_type[d]==GKYL_POISSON_ROBIN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 5; } - else { assert(false); } + for (int d = 0; d < basis->ndim; d++) { + if (bcs->lo_type[d] == GKYL_POISSON_PERIODIC && bcs->up_type[d] == GKYL_POISSON_PERIODIC) { + bckey[d] = 0; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 1; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_NEUMANN) { + bckey[d] = 2; + } else if (bcs->lo_type[d] == GKYL_POISSON_NEUMANN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 3; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && bcs->up_type[d] == GKYL_POISSON_ROBIN) { + bckey[d] = 4; + } else if (bcs->lo_type[d] == GKYL_POISSON_ROBIN && bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 5; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 1; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 1; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 1; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_NEUMANN) { + bckey[d] = 2; + } else if (bcs->lo_type[d] == GKYL_POISSON_NEUMANN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 3; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_ROBIN) { + bckey[d] = 4; + } else if (bcs->lo_type[d] == GKYL_POISSON_ROBIN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 5; + } else { + assert(false); + } }; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<(int)(pow(3,dim)+0.5); k++) { - if (dim == 1) { - lhsout[k] = isvareps? CK1(ser_lhsstencil_vareps_list_1x, poly_order, k, bckey[0]) - : CK1(ser_lhsstencil_consteps_list_1x, poly_order, k, bckey[0]); - } else if (dim == 2) { - lhsout[k] = isvareps? CK2(ser_lhsstencil_vareps_list_2x, poly_order, k, bckey[0], bckey[1]) - : CK2(ser_lhsstencil_consteps_list_2x, poly_order, k, bckey[0], bckey[1]); -// } else if (dim == 3) { -// lhsout[k] = isvareps? CK3(ser_lhsstencil_vareps_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]) -// : CK3(ser_lhsstencil_consteps_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); - } + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < (int)(pow(3, dim) + 0.5); k++) { + if (dim == 1) { + lhsout[k] = isvareps ? CK1(ser_lhsstencil_vareps_list_1x, poly_order, k, bckey[0]) : + CK1(ser_lhsstencil_consteps_list_1x, poly_order, k, bckey[0]); + } else if (dim == 2) { + lhsout[k] = isvareps ? + CK2(ser_lhsstencil_vareps_list_2x, poly_order, k, bckey[0], bckey[1]) : + CK2(ser_lhsstencil_consteps_list_2x, poly_order, k, bckey[0], bckey[1]); + // } else if (dim == 3) { + // lhsout[k] = isvareps? CK3(ser_lhsstencil_vareps_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]) + // : CK3(ser_lhsstencil_consteps_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); } - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + } + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } } -GKYL_CU_D -static void -fem_poisson_choose_src_kernels(const struct gkyl_basis* basis, const struct gkyl_poisson_bc *bcs, - bool isvareps, srcstencil_t *srcout) +GKYL_CU_D static void fem_poisson_choose_src_kernels( + const struct gkyl_basis *basis, const struct gkyl_poisson_bc *bcs, bool isvareps, + srcstencil_t *srcout +) { int dim = basis->ndim; int poly_order = basis->poly_order; int bckey[GKYL_MAX_CDIM] = {-1}; - for (int d=0; dndim; d++) { - if (bcs->lo_type[d]==GKYL_POISSON_PERIODIC && bcs->up_type[d]==GKYL_POISSON_PERIODIC ) { bckey[d] = 0; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 1; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_NEUMANN ) { bckey[d] = 2; } - else if (bcs->lo_type[d]==GKYL_POISSON_NEUMANN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 3; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_ROBIN ) { bckey[d] = 4; } - else if (bcs->lo_type[d]==GKYL_POISSON_ROBIN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 5; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 6; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_DIRICHLET ) { bckey[d] = 7; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 8; } - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_NEUMANN ) { bckey[d] = 9; } - else if (bcs->lo_type[d]==GKYL_POISSON_NEUMANN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 10; } + for (int d = 0; d < basis->ndim; d++) { + if (bcs->lo_type[d] == GKYL_POISSON_PERIODIC && bcs->up_type[d] == GKYL_POISSON_PERIODIC) { + bckey[d] = 0; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 1; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_NEUMANN) { + bckey[d] = 2; + } else if (bcs->lo_type[d] == GKYL_POISSON_NEUMANN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 3; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && bcs->up_type[d] == GKYL_POISSON_ROBIN) { + bckey[d] = 4; + } else if (bcs->lo_type[d] == GKYL_POISSON_ROBIN && bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 5; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 6; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET) { + bckey[d] = 7; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 8; + } else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_NEUMANN) { + bckey[d] = 9; + } else if (bcs->lo_type[d] == GKYL_POISSON_NEUMANN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 10; + } // MF 2024/10/01: kernels for these two are not yet plugged into the big lists above. - else if (bcs->lo_type[d]==GKYL_POISSON_DIRICHLET_VARYING && bcs->up_type[d]==GKYL_POISSON_ROBIN ) { bckey[d] = 11; } - else if (bcs->lo_type[d]==GKYL_POISSON_ROBIN && bcs->up_type[d]==GKYL_POISSON_DIRICHLET_VARYING) { bckey[d] = 12; } - else { assert(false); } + else if (bcs->lo_type[d] == GKYL_POISSON_DIRICHLET_VARYING && + bcs->up_type[d] == GKYL_POISSON_ROBIN) { + bckey[d] = 11; + } else if (bcs->lo_type[d] == GKYL_POISSON_ROBIN && + bcs->up_type[d] == GKYL_POISSON_DIRICHLET_VARYING) { + bckey[d] = 12; + } else { + assert(false); + } }; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<(int)(pow(3,dim)+0.5); k++) { - if (dim == 1) { - srcout[k] = isvareps? CK1(ser_srcstencil_vareps_list_1x, poly_order, k, bckey[0]) - : CK1(ser_srcstencil_consteps_list_1x, poly_order, k, bckey[0]); - } else if (dim == 2) { - srcout[k] = isvareps? CK2(ser_srcstencil_vareps_list_2x, poly_order, k, bckey[0], bckey[1]) - : CK2(ser_srcstencil_consteps_list_2x, poly_order, k, bckey[0], bckey[1]); -// } else if (dim == 3) { -// srcout[k] = isvareps? CK3(ser_srcstencil_vareps_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]) -// : CK3(ser_srcstencil_consteps_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); - } + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < (int)(pow(3, dim) + 0.5); k++) { + if (dim == 1) { + srcout[k] = isvareps ? CK1(ser_srcstencil_vareps_list_1x, poly_order, k, bckey[0]) : + CK1(ser_srcstencil_consteps_list_1x, poly_order, k, bckey[0]); + } else if (dim == 2) { + srcout[k] = isvareps ? + CK2(ser_srcstencil_vareps_list_2x, poly_order, k, bckey[0], bckey[1]) : + CK2(ser_srcstencil_consteps_list_2x, poly_order, k, bckey[0], bckey[1]); + // } else if (dim == 3) { + // srcout[k] = isvareps? CK3(ser_srcstencil_vareps_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]) + // : CK3(ser_srcstencil_consteps_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); } - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + } + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } } -GKYL_CU_D -static solstencil_t -fem_poisson_choose_sol_kernels(const struct gkyl_basis* basis) +GKYL_CU_D static solstencil_t fem_poisson_choose_sol_kernels(const struct gkyl_basis *basis) { int dim = basis->ndim; int poly_order = basis->poly_order; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_solstencil_list[dim].kernels[poly_order]; - - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_solstencil_list[dim].kernels[poly_order]; + + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } return 0; } -GKYL_CU_D -static void -fem_poisson_choose_bias_lhs_kernels(const struct gkyl_basis* basis, - const bool *isdirperiodic, bias_lhs_t *blhs_out) +GKYL_CU_D static void fem_poisson_choose_bias_lhs_kernels( + const struct gkyl_basis *basis, const bool *isdirperiodic, bias_lhs_t *blhs_out +) { int dim = basis->ndim; int poly_order = basis->poly_order; int bckey[GKYL_MAX_CDIM] = {-1}; - for (int d=0; dndim; d++) bckey[d] = isdirperiodic[d] ? 0 : 1; + for (int d = 0; d < basis->ndim; d++) { + bckey[d] = isdirperiodic[d] ? 0 : 1; + } switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<(int)(pow(2,dim)+0.5); k++) { - if (dim == 1) { - blhs_out[k] = CK1(ser_bias_lhs_list_1x, poly_order, k, bckey[0]); - } else if (dim == 2) { - blhs_out[k] = CK2(ser_bias_lhs_list_2x, poly_order, k, bckey[0], bckey[1]); -// } else if (dim == 3) { -// blhs_out[k] = CK3(ser_bias_lhs_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); - } + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < (int)(pow(2, dim) + 0.5); k++) { + if (dim == 1) { + blhs_out[k] = CK1(ser_bias_lhs_list_1x, poly_order, k, bckey[0]); + } else if (dim == 2) { + blhs_out[k] = CK2(ser_bias_lhs_list_2x, poly_order, k, bckey[0], bckey[1]); + // } else if (dim == 3) { + // blhs_out[k] = CK3(ser_bias_lhs_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); } - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + } + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } } -GKYL_CU_D -static void -fem_poisson_choose_bias_src_kernels(const struct gkyl_basis* basis, - const bool *isdirperiodic, bias_src_t *bsrc_out) +GKYL_CU_D static void fem_poisson_choose_bias_src_kernels( + const struct gkyl_basis *basis, const bool *isdirperiodic, bias_src_t *bsrc_out +) { int dim = basis->ndim; int poly_order = basis->poly_order; int bckey[GKYL_MAX_CDIM] = {-1}; - for (int d=0; dndim; d++) bckey[d] = isdirperiodic[d] ? 0 : 1; + for (int d = 0; d < basis->ndim; d++) { + bckey[d] = isdirperiodic[d] ? 0 : 1; + } switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - for (int k=0; k<(int)(pow(2,dim)+0.5); k++) { - if (dim == 1) { - bsrc_out[k] = CK1(ser_bias_src_list_1x, poly_order, k, bckey[0]); - } else if (dim == 2) { - bsrc_out[k] = CK2(ser_bias_src_list_2x, poly_order, k, bckey[0], bckey[1]); -// } else if (dim == 3) { -// bsrc_out[k] = CK3(ser_bias_src_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); - } + case GKYL_BASIS_MODAL_SERENDIPITY: + for (int k = 0; k < (int)(pow(2, dim) + 0.5); k++) { + if (dim == 1) { + bsrc_out[k] = CK1(ser_bias_src_list_1x, poly_order, k, bckey[0]); + } else if (dim == 2) { + bsrc_out[k] = CK2(ser_bias_src_list_2x, poly_order, k, bckey[0], bckey[1]); + // } else if (dim == 3) { + // bsrc_out[k] = CK3(ser_bias_src_list_3x, poly_order, k, bckey[0], bckey[1], bckey[2]); } - break; -// case GKYL_BASIS_MODAL_TENSOR: -// break; - default: - assert(false); - break; + } + break; + // case GKYL_BASIS_MODAL_TENSOR: + // break; + default: + assert(false); + break; } } -GKYL_CU_DH -static inline int idx_to_inup_ker(const int dim, const int *num_cells, const int *idx) { +GKYL_CU_DH static inline int idx_to_inup_ker(const int dim, const int *num_cells, const int *idx) +{ // Return the index of the kernel (in the array of kernels) needed given the grid index. // This function is for kernels that differentiate between upper cells and // elsewhere. int iout = 0; - for (int d=0; d // Identifiers for different Braginskii types -enum gkyl_braginskii_type -{ +enum gkyl_braginskii_type { NONE = 0, GKYL_BRAG_MAG = 1 << 0, GKYL_BRAG_VISC = 1 << 1, @@ -33,7 +32,8 @@ struct gkyl_moment_braginskii_inp { int nfluids; // number of fluids struct gkyl_moment_braginskii_data param[GKYL_MAX_SPECIES]; // species data double epsilon0; // permittivity of free space - double coll_fac; // constant multiplicative factor for collision time to increase or decrease collisionality + double + coll_fac; // constant multiplicative factor for collision time to increase or decrease collisionality }; // Object type @@ -46,7 +46,7 @@ typedef struct gkyl_moment_braginskii gkyl_moment_braginskii; * * @param inp Input parameters to updater */ -gkyl_moment_braginskii* gkyl_moment_braginskii_new(struct gkyl_moment_braginskii_inp inp); +gkyl_moment_braginskii *gkyl_moment_braginskii_new(struct gkyl_moment_braginskii_inp inp); /** * Compute RHS contribution from Braginskii transport terms in the @@ -65,11 +65,12 @@ gkyl_moment_braginskii* gkyl_moment_braginskii_new(struct gkyl_moment_braginskii * @param rhs RHS output (NOTE: Returns RHS output of all nfluids) */ -void gkyl_moment_braginskii_advance(const gkyl_moment_braginskii *bes, - struct gkyl_range brag_vars_range, struct gkyl_range update_range, - struct gkyl_array *fluid[GKYL_MAX_SPECIES], const struct gkyl_array *em_tot, - struct gkyl_array *cflrate[GKYL_MAX_SPECIES], - struct gkyl_array *brag_vars[GKYL_MAX_SPECIES], struct gkyl_array *rhs[GKYL_MAX_SPECIES]); +void gkyl_moment_braginskii_advance( + const gkyl_moment_braginskii *bes, struct gkyl_range brag_vars_range, + struct gkyl_range update_range, struct gkyl_array *fluid[GKYL_MAX_SPECIES], + const struct gkyl_array *em_tot, struct gkyl_array *cflrate[GKYL_MAX_SPECIES], + struct gkyl_array *brag_vars[GKYL_MAX_SPECIES], struct gkyl_array *rhs[GKYL_MAX_SPECIES] +); /** * Delete updater. diff --git a/moments/zero/gkyl_moment_em_coupling.h b/moments/zero/gkyl_moment_em_coupling.h index ce6e955e13..5ffd361e55 100644 --- a/moments/zero/gkyl_moment_em_coupling.h +++ b/moments/zero/gkyl_moment_em_coupling.h @@ -26,18 +26,20 @@ struct gkyl_moment_em_coupling_inp { double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. - bool static_field; // Is the plasma field static? If true, only J is updated to new time step. - double t_ramp_E; // Ramp-up time for the linear ramp function for initializing external electric fields. + bool static_field; // Is the plasma field static? If true, only J is updated to new time step. + double + t_ramp_E; // Ramp-up time for the linear ramp function for initializing external electric fields. double t_ramp_curr; // Ramp-up time for the linear ramp function for initializing applied currents. bool has_collision; // Run with collisions switched on. bool use_rel; // Assume special relativistic fluid species. - + // Matrix of scaling factors for collision frequencies. Should be symmetric (i.e. nu_base_sr = nu_base_rs). // These are defined such that nu_sr = nu_base_sr / rho_s, and nu_rs = nu_base_rs / rho_r. double nu_base[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES]; - bool use_explicit_em_coupling; // Use the explicit source-solver for handling moment-EM coupling (not operational yet). + bool + use_explicit_em_coupling; // Use the explicit source-solver for handling moment-EM coupling (not operational yet). bool has_nT_sources; // Run with number density and temperature sources. @@ -50,7 +52,8 @@ struct gkyl_moment_em_coupling_inp { bool has_volume_sources; // Run with volume-based geometrical sources. double volume_gas_gamma; // Adiabatic index for volume-based geometrical sources. double volume_U0; // Initial comoving plasma velocity for volume-based geometrical sources. - double volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. + double + volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. bool has_reactive_sources; // Run with reactive sources. double reactivity_gas_gamma; // Adiabatic index for reactive sources. @@ -59,36 +62,55 @@ struct gkyl_moment_em_coupling_inp { double reactivity_ignition_temperature; // Ignition temperature for reactive sources. double reactivity_reaction_rate; // Reaction rate for reactive sources. - bool has_einstein_medium_sources; // Run with coupled fluid-Einstein sources in plane-symmetric spacetimes. - double medium_gas_gamma; // Adiabatic index for coupled fluid-Einstein sources in plane-symmetric spacetimes. - double medium_kappa; // Stress-energy prefactor for coupled fluid-Einstein sources in plane-symmetric spacetimes. + bool + has_einstein_medium_sources; // Run with coupled fluid-Einstein sources in plane-symmetric spacetimes. + double + medium_gas_gamma; // Adiabatic index for coupled fluid-Einstein sources in plane-symmetric spacetimes. + double + medium_kappa; // Stress-energy prefactor for coupled fluid-Einstein sources in plane-symmetric spacetimes. - bool has_gr_ultra_rel_sources; // Run with general relativistic source terms (Euler equations, ultra-relativistic equation of state). - double gr_ultra_rel_gas_gamma; // Adiabatic index for general relativistic Euler equations (ultra-relativistic equation of state). + bool + has_gr_ultra_rel_sources; // Run with general relativistic source terms (Euler equations, ultra-relativistic equation of state). + double + gr_ultra_rel_gas_gamma; // Adiabatic index for general relativistic Euler equations (ultra-relativistic equation of state). - bool has_gr_euler_sources; // Run with general relativistic source terms (Euler equations, general equation of state). - double gr_euler_gas_gamma; // Adiabatic index for general relativistic Euler equations (general equation of state). + bool + has_gr_euler_sources; // Run with general relativistic source terms (Euler equations, general equation of state). + double + gr_euler_gas_gamma; // Adiabatic index for general relativistic Euler equations (general equation of state). bool has_gr_twofluid_sources; // Run with general relativistic two-fluid source terms. double gr_twofluid_mass_elc; // Electron mass for general relativistic two-fluid equations. double gr_twofluid_mass_ion; // Ion mass for general relativistic two-fluid equations. double gr_twofluid_charge_elc; // Electron charge for general relativistic two-fluid equations. double gr_twofluid_charge_ion; // Ion charge for general relativistic two-fluid equations. - double gr_twofluid_gas_gamma_elc; // Adiabatic index for electrons in general relativistic two-fluid equations. - double gr_twofluid_gas_gamma_ion; // Adiabatic index for ions in general relativistic two-fluid equations. - double gr_twofluid_e_fact; // Electric field divergence error propagation speed for general relativistic two-fluid equations. - - bool has_vacuum_einstein_sources; // Run with vacuum Einstein sources using the Bona-Masso formalism. - double vacuum_einstein_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the Bona-Masso formalism. - enum gkyl_spacetime_slicing vacuum_einstein_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the Bona-Masso formalism. - enum gkyl_spacetime_evolution vacuum_einstein_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the Bona-Masso formalism. - - bool has_vacuum_einstein_conformal_sources; // Run with vacuum Einstein sources using the conformal Bona-Masso formalism. - double vacuum_einstein_conformal_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the conformal Bona-Masso formalism. - enum gkyl_spacetime_slicing vacuum_einstein_conformal_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the conformal Bona-Masso formalism. - enum gkyl_spacetime_evolution vacuum_einstein_conformal_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the conformal Bona-Masso formalism. - - bool has_gr_mhd_sources; // Run with general relativistic source terms (general relativistic magnetohydrodynamics equations). + double + gr_twofluid_gas_gamma_elc; // Adiabatic index for electrons in general relativistic two-fluid equations. + double + gr_twofluid_gas_gamma_ion; // Adiabatic index for ions in general relativistic two-fluid equations. + double + gr_twofluid_e_fact; // Electric field divergence error propagation speed for general relativistic two-fluid equations. + + bool + has_vacuum_einstein_sources; // Run with vacuum Einstein sources using the Bona-Masso formalism. + double + vacuum_einstein_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the Bona-Masso formalism. + enum gkyl_spacetime_slicing + vacuum_einstein_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the Bona-Masso formalism. + enum gkyl_spacetime_evolution + vacuum_einstein_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the Bona-Masso formalism. + + bool + has_vacuum_einstein_conformal_sources; // Run with vacuum Einstein sources using the conformal Bona-Masso formalism. + double + vacuum_einstein_conformal_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the conformal Bona-Masso formalism. + enum gkyl_spacetime_slicing + vacuum_einstein_conformal_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the conformal Bona-Masso formalism. + enum gkyl_spacetime_evolution + vacuum_einstein_conformal_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the conformal Bona-Masso formalism. + + bool + has_gr_mhd_sources; // Run with general relativistic source terms (general relativistic magnetohydrodynamics equations). double gr_mhd_gas_gamma; // Adiabatic index for general relativistic magnetohydrodynamics equations. }; @@ -101,8 +123,7 @@ typedef struct gkyl_moment_em_coupling gkyl_moment_em_coupling; * @param inp Input parameters for the moment-EM coupling object. * @return Moment-EM coupling object. */ -gkyl_moment_em_coupling* -gkyl_moment_em_coupling_new(struct gkyl_moment_em_coupling_inp inp); +gkyl_moment_em_coupling *gkyl_moment_em_coupling_new(struct gkyl_moment_em_coupling_inp inp); /** * Integrate the electromagnetic source terms in the multi-fluid equation system using an implicit forcing solver (specifically the time-centered @@ -123,10 +144,14 @@ gkyl_moment_em_coupling_new(struct gkyl_moment_em_coupling_inp inp); * @param ext_em External electromagnetic variables (for EM fields coming from external sources, e.g. coils, capacitors, etc.). * @param nT_sources Array of number density and temperature source terms. */ -void -gkyl_moment_em_coupling_implicit_advance(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, const struct gkyl_range* update_range, - struct gkyl_array* fluid[GKYL_MAX_SPECIES], const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], const struct gkyl_array *p_rhs[GKYL_MAX_SPECIES], - struct gkyl_array* em, const struct gkyl_array* app_current, const struct gkyl_array* ext_em, const struct gkyl_array* nT_sources[GKYL_MAX_SPECIES]); +void gkyl_moment_em_coupling_implicit_advance( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + const struct gkyl_range *update_range, struct gkyl_array *fluid[GKYL_MAX_SPECIES], + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], + const struct gkyl_array *p_rhs[GKYL_MAX_SPECIES], struct gkyl_array *em, + const struct gkyl_array *app_current, const struct gkyl_array *ext_em, + const struct gkyl_array *nT_sources[GKYL_MAX_SPECIES] +); /** * Integrate the electromagnetic source terms in the multi-fluid equation system using an explicit forcing solver (specifically either the strong @@ -150,16 +175,19 @@ gkyl_moment_em_coupling_implicit_advance(const gkyl_moment_em_coupling* mom_em, * @param proj_app_curr The finite-volume projection routine for the external current. * @param nstrang Indicator of which step in the Strang splitting we are currently considering. */ -void -gkyl_moment_em_coupling_explicit_advance(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, const struct gkyl_range* update_range, - struct gkyl_array* fluid[GKYL_MAX_SPECIES], const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], const struct gkyl_array* p_rhs[GKYL_MAX_SPECIES], - struct gkyl_array* em, const struct gkyl_array *app_current, const struct gkyl_array* app_current1, const struct gkyl_array* app_current2, - const struct gkyl_array* ext_em, const struct gkyl_array* nT_sources[GKYL_MAX_SPECIES], gkyl_fv_proj* proj_app_curr, int nstrang); +void gkyl_moment_em_coupling_explicit_advance( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + const struct gkyl_range *update_range, struct gkyl_array *fluid[GKYL_MAX_SPECIES], + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], + const struct gkyl_array *p_rhs[GKYL_MAX_SPECIES], struct gkyl_array *em, + const struct gkyl_array *app_current, const struct gkyl_array *app_current1, + const struct gkyl_array *app_current2, const struct gkyl_array *ext_em, + const struct gkyl_array *nT_sources[GKYL_MAX_SPECIES], gkyl_fv_proj *proj_app_curr, int nstrang +); /** * Delete moment-EM coupling object. * * @param mom_em Moment-EM coupling object to delete. */ -void -gkyl_moment_em_coupling_release(gkyl_moment_em_coupling* mom_em); \ No newline at end of file +void gkyl_moment_em_coupling_release(gkyl_moment_em_coupling *mom_em); \ No newline at end of file diff --git a/moments/zero/gkyl_moment_em_coupling_priv.h b/moments/zero/gkyl_moment_em_coupling_priv.h index ebc89ad77e..58b2043a1c 100644 --- a/moments/zero/gkyl_moment_em_coupling_priv.h +++ b/moments/zero/gkyl_moment_em_coupling_priv.h @@ -16,9 +16,10 @@ struct gkyl_moment_em_coupling { double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. - bool static_field; // Is the plasma field static? If true, only J is updated to new time step. + bool static_field; // Is the plasma field static? If true, only J is updated to new time step. bool ramp_app_E; // Use a linear ramp function for initializing external electric fields. - double t_ramp_E; // Ramp-up time for the linear ramp function for initializing external electric fields. + double + t_ramp_E; // Ramp-up time for the linear ramp function for initializing external electric fields. bool ramp_app_curr; // Use a linear ramp function for initializing applied currents. double t_ramp_curr; // Ramp-up time for the linear ramp function for initializing applied currents. @@ -29,7 +30,8 @@ struct gkyl_moment_em_coupling { // These are defined such that nu_sr = nu_base_sr / rho_s, and nu_rs = nu_base_rs / rho_r. double nu_base[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES]; - bool use_explicit_em_coupling; // Use the explicit source-solver for handling moment-EM coupling (not operational yet). + bool + use_explicit_em_coupling; // Use the explicit source-solver for handling moment-EM coupling (not operational yet). bool has_nT_sources; // Run with number density and temperature sources. @@ -42,7 +44,8 @@ struct gkyl_moment_em_coupling { bool has_volume_sources; // Run with volume-based geometrical sources. double volume_gas_gamma; // Adiabatic index for volume-based geometrical sources. double volume_U0; // Initial comoving plasma velocity for volume-based geometrical sources. - double volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. + double + volume_R0; // Initial radial distance from expansion/contraction center for volume-based geometrical sources. bool has_reactive_sources; // Run with reactive sources. double reactivity_gas_gamma; // Adiabatic index for reactive sources. @@ -51,35 +54,54 @@ struct gkyl_moment_em_coupling { double reactivity_ignition_temperature; // Ignition temperature for reactive sources. double reactivity_reaction_rate; // Reaction rate for reactive sources. - bool has_einstein_medium_sources; // Run with coupled fluid-Einstein sources in plane-symmetric spacetimes. - double medium_gas_gamma; // Adiabatic index for coupled fluid-Einstein sources in plane-symmetric spacetimes. - double medium_kappa; // Stress-energy prefactor for coupled fluid-Einstein sources in plane-symmetric spacetimes. + bool + has_einstein_medium_sources; // Run with coupled fluid-Einstein sources in plane-symmetric spacetimes. + double + medium_gas_gamma; // Adiabatic index for coupled fluid-Einstein sources in plane-symmetric spacetimes. + double + medium_kappa; // Stress-energy prefactor for coupled fluid-Einstein sources in plane-symmetric spacetimes. - bool has_gr_ultra_rel_sources; // Run with general relativistic source terms (Euler equations, ultra-relativistic equation of state). - double gr_ultra_rel_gas_gamma; // Adiabatic index for general relativistic Euler equations (ultra-relativistic equation of state). + bool + has_gr_ultra_rel_sources; // Run with general relativistic source terms (Euler equations, ultra-relativistic equation of state). + double + gr_ultra_rel_gas_gamma; // Adiabatic index for general relativistic Euler equations (ultra-relativistic equation of state). - bool has_gr_euler_sources; // Run with general relativistic source terms (Euler equations, general equation of state). - double gr_euler_gas_gamma; // Adiabatic index for general relativistic Euler equations (general equation of state). + bool + has_gr_euler_sources; // Run with general relativistic source terms (Euler equations, general equation of state). + double + gr_euler_gas_gamma; // Adiabatic index for general relativistic Euler equations (general equation of state). bool has_gr_twofluid_sources; // Run with general relativistic two-fluid source terms. double gr_twofluid_mass_elc; // Electron mass for general relativistic two-fluid equations. double gr_twofluid_mass_ion; // Ion mass for general relativistic two-fluid equations. double gr_twofluid_charge_elc; // Electron charge for general relativistic two-fluid equations. double gr_twofluid_charge_ion; // Ion charge for general relativistic two-fluid equations. - double gr_twofluid_gas_gamma_elc; // Adiabatic index for electrons in general relativistic two-fluid equations. - double gr_twofluid_gas_gamma_ion; // Adiabatic index for ions in general relativistic two-fluid equations. - double gr_twofluid_e_fact; // Electric field divergence error propagation speed for general relativistic two-fluid equations. - - bool has_vacuum_einstein_sources; // Run with vacuum Einstein sources using the Bona-Masso formalism. - double vacuum_einstein_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the Bona-Masso formalism. - enum gkyl_spacetime_slicing vacuum_einstein_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the Bona-Masso formalism. - enum gkyl_spacetime_evolution vacuum_einstein_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the Bona-Masso formalism. - - bool has_vacuum_einstein_conformal_sources; // Run with vacuum Einstein sources using the conformal Bona-Masso formalism. - double vacuum_einstein_conformal_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the conformal Bona-Masso formalism. - enum gkyl_spacetime_slicing vacuum_einstein_conformal_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the conformal Bona-Masso formalism. - enum gkyl_spacetime_evolution vacuum_einstein_conformal_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the conformal Bona-Masso formalism. - - bool has_gr_mhd_sources; // Run with general relativistic source terms (general relativistic magnetohydrodynamics equations). + double + gr_twofluid_gas_gamma_elc; // Adiabatic index for electrons in general relativistic two-fluid equations. + double + gr_twofluid_gas_gamma_ion; // Adiabatic index for ions in general relativistic two-fluid equations. + double + gr_twofluid_e_fact; // Electric field divergence error propagation speed for general relativistic two-fluid equations. + + bool + has_vacuum_einstein_sources; // Run with vacuum Einstein sources using the Bona-Masso formalism. + double + vacuum_einstein_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the Bona-Masso formalism. + enum gkyl_spacetime_slicing + vacuum_einstein_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the Bona-Masso formalism. + enum gkyl_spacetime_evolution + vacuum_einstein_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the Bona-Masso formalism. + + bool + has_vacuum_einstein_conformal_sources; // Run with vacuum Einstein sources using the conformal Bona-Masso formalism. + double + vacuum_einstein_conformal_excision_threshold; // Excision threshold (lapse) for vacuum Einstein equations using the conformal Bona-Masso formalism. + enum gkyl_spacetime_slicing + vacuum_einstein_conformal_spacetime_slicing; // Spacetime slicing condition for vacuum Einstein equations using the conformal Bona-Masso formalism. + enum gkyl_spacetime_evolution + vacuum_einstein_conformal_spacetime_evolution; // Spacetime evolution system for vacuum Einstein equations using the conformal Bona-Masso formalism. + + bool + has_gr_mhd_sources; // Run with general relativistic source terms (general relativistic magnetohydrodynamics equations). double gr_mhd_gas_gamma; // Adiabatic index for general relativistic magnetohydrodynamics equations. }; diff --git a/moments/zero/gkyl_moment_non_ideal_priv.h b/moments/zero/gkyl_moment_non_ideal_priv.h index 85d2e33e86..ff33acc1e9 100644 --- a/moments/zero/gkyl_moment_non_ideal_priv.h +++ b/moments/zero/gkyl_moment_non_ideal_priv.h @@ -2,7 +2,7 @@ #include #ifndef M_PI - #define M_PI 3.14159265358979323846 +#define M_PI 3.14159265358979323846 #endif // Private header, not for direct use in user code @@ -44,15 +44,13 @@ static const unsigned QZ = 8; // Calculate symmetrized gradient 1D // Based on Günter, Lackner, & Tichmann 2005 JCP -static inline double -calc_sym_grad_1D(double dx, double a_l, double a_u) +static inline double calc_sym_grad_1D(double dx, double a_l, double a_u) { - return (a_u - a_l)/dx; + return (a_u - a_l) / dx; } // Calculate symmetrized second-derivative in 1D. -static inline double -calc_sym_grad2_1D(double dx, double a_l, double a_c, double a_u) +static inline double calc_sym_grad2_1D(double dx, double a_l, double a_c, double a_u) { return (a_u + a_l - (2.0 * a_c)) / (dx * dx); } @@ -61,13 +59,13 @@ calc_sym_grad2_1D(double dx, double a_l, double a_c, double a_u) static inline double calc_sym_gradx_2D(double dx, double a_ll, double a_lu, double a_ul, double a_uu) { - return (a_ul + a_uu - a_ll - a_lu)/(2*dx); + return (a_ul + a_uu - a_ll - a_lu) / (2 * dx); } static inline double calc_sym_grady_2D(double dy, double a_ll, double a_lu, double a_ul, double a_uu) { - return (a_lu + a_uu - a_ll - a_ul)/(2*dy); + return (a_lu + a_uu - a_ll - a_ul) / (2 * dy); } // Calculate symmetrized cross-derivative in 2D. @@ -78,67 +76,73 @@ calc_sym_gradxy_2D(double dx, double dy, double a_ll, double a_lu, double a_ul, } // Calculate symmetrized gradients 3D -static inline double -calc_sym_gradx_3D(double dx, double a_lll, double a_llu, double a_lul, double a_luu, double a_ull, double a_ulu, double a_uul, double a_uuu) +static inline double calc_sym_gradx_3D( + double dx, double a_lll, double a_llu, double a_lul, double a_luu, double a_ull, double a_ulu, + double a_uul, double a_uuu +) { - return (a_ull + a_ulu + a_uul + a_uuu - a_lll - a_llu - a_lul - a_luu)/(4*dx); + return (a_ull + a_ulu + a_uul + a_uuu - a_lll - a_llu - a_lul - a_luu) / (4 * dx); } -static inline double -calc_sym_grady_3D(double dy, double a_lll, double a_llu, double a_lul, double a_luu, double a_ull, double a_ulu, double a_uul, double a_uuu) +static inline double calc_sym_grady_3D( + double dy, double a_lll, double a_llu, double a_lul, double a_luu, double a_ull, double a_ulu, + double a_uul, double a_uuu +) { - return (a_lul + a_luu + a_uul + a_uuu - a_lll - a_llu - a_ull - a_ulu)/(4*dy); + return (a_lul + a_luu + a_uul + a_uuu - a_lll - a_llu - a_ull - a_ulu) / (4 * dy); } -static inline double -calc_sym_gradz_3D(double dz, double a_lll, double a_llu, double a_lul, double a_luu, double a_ull, double a_ulu, double a_uul, double a_uuu) +static inline double calc_sym_gradz_3D( + double dz, double a_lll, double a_llu, double a_lul, double a_luu, double a_ull, double a_ulu, + double a_uul, double a_uuu +) { - return (a_llu + a_luu + a_ulu + a_uuu - a_lll - a_lul - a_ull - a_uul)/(4*dz); + return (a_llu + a_luu + a_ulu + a_uuu - a_lll - a_lul - a_ull - a_uul) / (4 * dz); } // In 1D, computes quantity at cell edge of two-cell interface -static inline double -calc_arithm_avg_1D(double a_l, double a_u) +static inline double calc_arithm_avg_1D(double a_l, double a_u) { - return 0.5*(a_l + a_u); + return 0.5 * (a_l + a_u); } -static inline double -calc_harmonic_avg_1D(double a_l, double a_u) +static inline double calc_harmonic_avg_1D(double a_l, double a_u) { - return 1.0/(0.5/a_l + 0.5/a_u); + return 1.0 / (0.5 / a_l + 0.5 / a_u); } // In 2D, computes quantity at cell corner of four-cell interface -static inline double -calc_arithm_avg_2D(double a_ll, double a_lu, double a_ul, double a_uu) +static inline double calc_arithm_avg_2D(double a_ll, double a_lu, double a_ul, double a_uu) { - return 0.25*(a_ll + a_lu + a_ul + a_uu); + return 0.25 * (a_ll + a_lu + a_ul + a_uu); } -static inline double -calc_harmonic_avg_2D(double a_ll, double a_lu, double a_ul, double a_uu) +static inline double calc_harmonic_avg_2D(double a_ll, double a_lu, double a_ul, double a_uu) { - return 1.0/(0.25/a_ll + 0.25/a_lu + 0.25/a_ul + 0.25/a_uu); + return 1.0 / (0.25 / a_ll + 0.25 / a_lu + 0.25 / a_ul + 0.25 / a_uu); } // In 3D, computes quantity at cell corner of eight-cell interface -static inline double -calc_arithm_avg_3D(double a_lll, double a_llu, double a_lul, double a_luu, double a_ull, double a_ulu, double a_uul, double a_uuu) +static inline double calc_arithm_avg_3D( + double a_lll, double a_llu, double a_lul, double a_luu, double a_ull, double a_ulu, double a_uul, + double a_uuu +) { - return 0.125*(a_lll + a_llu + a_lul + a_luu + a_ull + a_ulu + a_uul + a_uuu); + return 0.125 * (a_lll + a_llu + a_lul + a_luu + a_ull + a_ulu + a_uul + a_uuu); } -static inline double -calc_harmonic_avg_3D(double a_lll, double a_llu, double a_lul, double a_luu, double a_ull, double a_ulu, double a_uul, double a_uuu) +static inline double calc_harmonic_avg_3D( + double a_lll, double a_llu, double a_lul, double a_luu, double a_ull, double a_ulu, double a_uul, + double a_uuu +) { - return 1.0/(0.125/a_lll + 0.125/a_llu + 0.125/a_lul + 0.125/a_luu + 0.125/a_ull + 0.125/a_ulu + 0.125/a_uul + 0.125/a_uuu); + return 1.0 / (0.125 / a_lll + 0.125 / a_llu + 0.125 / a_lul + 0.125 / a_luu + 0.125 / a_ull + + 0.125 / a_ulu + 0.125 / a_uul + 0.125 / a_uuu); } // Calculate grad(u) // In 1D, computes tensor at cell edge of two-cell interface -static inline void -calc_grad_u_1D(double dx, double u_l[3], double u_u[3], double grad_u[3]) +static inline void calc_grad_u_1D(double dx, double u_l[3], double u_u[3], double grad_u[3]) { grad_u[0] = calc_sym_grad_1D(dx, u_l[0], u_u[0]); grad_u[1] = calc_sym_grad_1D(dx, u_l[1], u_u[1]); @@ -146,8 +150,10 @@ calc_grad_u_1D(double dx, double u_l[3], double u_u[3], double grad_u[3]) } // In 2D, computes tensor computes tensor in one corner of four-cell interface -static inline void -calc_grad_u_2D(double dx, double dy, double u_ll[3], double u_lu[3], double u_ul[3], double u_uu[3], double grad_u[6]) +static inline void calc_grad_u_2D( + double dx, double dy, double u_ll[3], double u_lu[3], double u_ul[3], double u_uu[3], + double grad_u[6] +) { grad_u[0] = calc_sym_gradx_2D(dx, u_ll[0], u_lu[0], u_ul[0], u_uu[0]); grad_u[1] = calc_sym_gradx_2D(dx, u_ll[1], u_lu[1], u_ul[1], u_uu[1]); @@ -159,92 +165,113 @@ calc_grad_u_2D(double dx, double dy, double u_ll[3], double u_lu[3], double u_ul } // In 3D, computes tensor in one corner of eight-cell interface -static inline void -calc_grad_u_3D(double dx, double dy, double dz, double u_lll[3], double u_llu[3], double u_lul[3], double u_luu[3], double u_ull[3], double u_ulu[3], double u_uul[3], double u_uuu[3], double grad_u[9]) +static inline void calc_grad_u_3D( + double dx, double dy, double dz, double u_lll[3], double u_llu[3], double u_lul[3], + double u_luu[3], double u_ull[3], double u_ulu[3], double u_uul[3], double u_uuu[3], + double grad_u[9] +) { - grad_u[0] = calc_sym_gradx_3D(dx, u_lll[0], u_llu[0], u_lul[0], u_luu[0], u_ull[0], u_ulu[0], u_uul[0], u_uuu[0]); - grad_u[1] = calc_sym_gradx_3D(dx, u_lll[1], u_llu[1], u_lul[1], u_luu[1], u_ull[1], u_ulu[1], u_uul[1], u_uuu[1]); - grad_u[2] = calc_sym_gradx_3D(dx, u_lll[2], u_llu[2], u_lul[2], u_luu[2], u_ull[2], u_ulu[2], u_uul[2], u_uuu[2]); - - grad_u[3] = calc_sym_grady_3D(dy, u_lll[0], u_llu[0], u_lul[0], u_luu[0], u_ull[0], u_ulu[0], u_uul[0], u_uuu[0]); - grad_u[4] = calc_sym_grady_3D(dy, u_lll[1], u_llu[1], u_lul[1], u_luu[1], u_ull[1], u_ulu[1], u_uul[1], u_uuu[1]); - grad_u[5] = calc_sym_grady_3D(dy, u_lll[2], u_llu[2], u_lul[2], u_luu[2], u_ull[2], u_ulu[2], u_uul[2], u_uuu[2]); - - grad_u[6] = calc_sym_gradz_3D(dz, u_lll[0], u_llu[0], u_lul[0], u_luu[0], u_ull[0], u_ulu[0], u_uul[0], u_uuu[0]); - grad_u[7] = calc_sym_gradz_3D(dz, u_lll[1], u_llu[1], u_lul[1], u_luu[1], u_ull[1], u_ulu[1], u_uul[1], u_uuu[1]); - grad_u[8] = calc_sym_gradz_3D(dz, u_lll[2], u_llu[2], u_lul[2], u_luu[2], u_ull[2], u_ulu[2], u_uul[2], u_uuu[2]); + grad_u[0] = calc_sym_gradx_3D( + dx, u_lll[0], u_llu[0], u_lul[0], u_luu[0], u_ull[0], u_ulu[0], u_uul[0], u_uuu[0] + ); + grad_u[1] = calc_sym_gradx_3D( + dx, u_lll[1], u_llu[1], u_lul[1], u_luu[1], u_ull[1], u_ulu[1], u_uul[1], u_uuu[1] + ); + grad_u[2] = calc_sym_gradx_3D( + dx, u_lll[2], u_llu[2], u_lul[2], u_luu[2], u_ull[2], u_ulu[2], u_uul[2], u_uuu[2] + ); + + grad_u[3] = calc_sym_grady_3D( + dy, u_lll[0], u_llu[0], u_lul[0], u_luu[0], u_ull[0], u_ulu[0], u_uul[0], u_uuu[0] + ); + grad_u[4] = calc_sym_grady_3D( + dy, u_lll[1], u_llu[1], u_lul[1], u_luu[1], u_ull[1], u_ulu[1], u_uul[1], u_uuu[1] + ); + grad_u[5] = calc_sym_grady_3D( + dy, u_lll[2], u_llu[2], u_lul[2], u_luu[2], u_ull[2], u_ulu[2], u_uul[2], u_uuu[2] + ); + + grad_u[6] = calc_sym_gradz_3D( + dz, u_lll[0], u_llu[0], u_lul[0], u_luu[0], u_ull[0], u_ulu[0], u_uul[0], u_uuu[0] + ); + grad_u[7] = calc_sym_gradz_3D( + dz, u_lll[1], u_llu[1], u_lul[1], u_luu[1], u_ull[1], u_ulu[1], u_uul[1], u_uuu[1] + ); + grad_u[8] = calc_sym_gradz_3D( + dz, u_lll[2], u_llu[2], u_lul[2], u_luu[2], u_ull[2], u_ulu[2], u_uul[2], u_uuu[2] + ); } // Calculate rate of strain tensor // In 1D, computes tensor at cell edge of two-cell interface -static inline void -calc_ros_1D(double dx, double u_l[3], double u_u[3], double w[6]) +static inline void calc_ros_1D(double dx, double u_l[3], double u_u[3], double w[6]) { double grad_u[3] = {0.0}; calc_grad_u_1D(dx, u_l, u_u, grad_u); - w[0] = 4.0/3.0*grad_u[0]; + w[0] = 4.0 / 3.0 * grad_u[0]; w[1] = grad_u[1]; w[2] = grad_u[2]; - w[3] = -2.0/3.0*grad_u[0]; + w[3] = -2.0 / 3.0 * grad_u[0]; w[4] = 0.0; - w[5] = -2.0/3.0*grad_u[0]; + w[5] = -2.0 / 3.0 * grad_u[0]; } // In 2D, computes tensor in one corner of four-cell interface -static inline void -calc_ros_2D(double dx, double dy, double u_ll[3], double u_lu[3], double u_ul[3], double u_uu[3], double w[6]) +static inline void calc_ros_2D( + double dx, double dy, double u_ll[3], double u_lu[3], double u_ul[3], double u_uu[3], double w[6] +) { double grad_u[6] = {0.0}; calc_grad_u_2D(dx, dy, u_ll, u_lu, u_ul, u_uu, grad_u); double divu = grad_u[0] + grad_u[4]; - w[0] = 2.0*grad_u[0] - 2.0/3.0*divu; + w[0] = 2.0 * grad_u[0] - 2.0 / 3.0 * divu; w[1] = grad_u[1] + grad_u[3]; w[2] = grad_u[2]; - w[3] = 2.0*grad_u[4] - 2.0/3.0*divu; + w[3] = 2.0 * grad_u[4] - 2.0 / 3.0 * divu; w[4] = grad_u[5]; - w[5] = -2.0/3.0*divu; + w[5] = -2.0 / 3.0 * divu; } // In 3D, computes tensor in one corner of eight-cell interface -static inline void -calc_ros_3D(double dx, double dy, double dz, double u_lll[3], double u_llu[3], double u_lul[3], double u_luu[3], double u_ull[3], double u_ulu[3], double u_uul[3], double u_uuu[3], double w[6]) +static inline void calc_ros_3D( + double dx, double dy, double dz, double u_lll[3], double u_llu[3], double u_lul[3], + double u_luu[3], double u_ull[3], double u_ulu[3], double u_uul[3], double u_uuu[3], double w[6] +) { double grad_u[9] = {0.0}; calc_grad_u_3D(dx, dy, dz, u_lll, u_llu, u_lul, u_luu, u_ull, u_ulu, u_uul, u_uuu, grad_u); double divu = grad_u[0] + grad_u[4] + grad_u[8]; - w[0] = 2.0*grad_u[0] - 2.0/3.0*divu; + w[0] = 2.0 * grad_u[0] - 2.0 / 3.0 * divu; w[1] = grad_u[1] + grad_u[3]; w[2] = grad_u[2] + grad_u[6]; - w[3] = 2.0*grad_u[4] - 2.0/3.0*divu; + w[3] = 2.0 * grad_u[4] - 2.0 / 3.0 * divu; w[4] = grad_u[5] + grad_u[7]; - w[5] = 2.0*grad_u[8] - 2.0/3.0*divu; + w[5] = 2.0 * grad_u[8] - 2.0 / 3.0 * divu; } // Magnetized closure helper functions // Calculate the magnitude of the local magnetic field -static inline double -calc_mag_b(const double em_tot[8]) +static inline double calc_mag_b(const double em_tot[8]) { - return sqrt(em_tot[BX]*em_tot[BX] + em_tot[BY]*em_tot[BY] + em_tot[BZ]*em_tot[BZ]); + return sqrt(em_tot[BX] * em_tot[BX] + em_tot[BY] * em_tot[BY] + em_tot[BZ] * em_tot[BZ]); } // Calculate the cyclotron frequency based on the species' parameters -static inline double -calc_omega_c(double charge, double mass, const double em_tot[8]) +static inline double calc_omega_c(double charge, double mass, const double em_tot[8]) { double omega_c = 0.0; double Bmag = calc_mag_b(em_tot); - if (Bmag > 0.0) - omega_c = charge*Bmag/mass; + if (Bmag > 0.0) { + omega_c = charge * Bmag / mass; + } return omega_c; } // Calculate magnetic field unit vector -static inline void -calc_bhat(const double em_tot[8], double b[3]) +static inline void calc_bhat(const double em_tot[8], double b[3]) { double Bx = em_tot[BX]; double By = em_tot[BY]; @@ -252,67 +279,71 @@ calc_bhat(const double em_tot[8], double b[3]) double Bmag = calc_mag_b(em_tot); // get magnetic field unit vector if (Bmag > 0.0) { - b[0] = Bx/Bmag; - b[1] = By/Bmag; - b[2] = Bz/Bmag; + b[0] = Bx / Bmag; + b[1] = By / Bmag; + b[2] = Bz / Bmag; } } // Calculate the collision time based on the species' parameters // Note: assumes the electron-ion collision frequency so sqrt(2) may be missing // coulomb_log considered constant, rho is mass density, temp is temperature -static inline double -calc_tau(double coulomb_log, double coll_fac, double epsilon0, double charge1, double charge2, double mass1, double mass2, double rho, double temp) +static inline double calc_tau( + double coulomb_log, double coll_fac, double epsilon0, double charge1, double charge2, + double mass1, double mass2, double rho, double temp +) { - return coll_fac*6.0*sqrt(2.0*M_PI*mass1*temp*M_PI*mass2*temp*M_PI*mass2*temp)*epsilon0*epsilon0/(coulomb_log*charge1*charge1*charge2*charge2*rho); + return coll_fac * 6.0 * + sqrt(2.0 * M_PI * mass1 * temp * M_PI * mass2 * temp * M_PI * mass2 * temp) * epsilon0 * + epsilon0 / (coulomb_log * charge1 * charge1 * charge2 * charge2 * rho); } // Calculate magnetized parallel viscous stress tensor -static void -calc_pi_par(double eta_par, double b_avg[3], double w[6], double pi_par[6]) -{ +static void calc_pi_par(double eta_par, double b_avg[3], double w[6], double pi_par[6]) +{ // parallel rate of strain = (bb - 1/3 I) : W - double par_ros = (b_avg[0]*b_avg[0] - 1.0/3.0)*w[0] + 2.0*b_avg[0]*b_avg[1]*w[1] + 2.0*b_avg[0]*b_avg[2]*w[2] - + (b_avg[1]*b_avg[1] - 1.0/3.0)*w[3] + 2.0*b_avg[1]*b_avg[2]*w[4] - + (b_avg[2]*b_avg[2] - 1.0/3.0)*w[5]; + double par_ros = (b_avg[0] * b_avg[0] - 1.0 / 3.0) * w[0] + 2.0 * b_avg[0] * b_avg[1] * w[1] + + 2.0 * b_avg[0] * b_avg[2] * w[2] + (b_avg[1] * b_avg[1] - 1.0 / 3.0) * w[3] + + 2.0 * b_avg[1] * b_avg[2] * w[4] + (b_avg[2] * b_avg[2] - 1.0 / 3.0) * w[5]; // pi_par = -eta_par * (bb - 1/3 I) (bb - 1/3 I) : W - pi_par[0] = -eta_par*(b_avg[0]*b_avg[0] - 1.0/3.0)*par_ros; - pi_par[1] = -eta_par*b_avg[0]*b_avg[1]*par_ros; - pi_par[2] = -eta_par*b_avg[0]*b_avg[2]*par_ros; - pi_par[3] = -eta_par*(b_avg[1]*b_avg[1] - 1.0/3.0)*par_ros; - pi_par[4] = -eta_par*b_avg[1]*b_avg[2]*par_ros; - pi_par[5] = -eta_par*(b_avg[2]*b_avg[2] - 1.0/3.0)*par_ros; + pi_par[0] = -eta_par * (b_avg[0] * b_avg[0] - 1.0 / 3.0) * par_ros; + pi_par[1] = -eta_par * b_avg[0] * b_avg[1] * par_ros; + pi_par[2] = -eta_par * b_avg[0] * b_avg[2] * par_ros; + pi_par[3] = -eta_par * (b_avg[1] * b_avg[1] - 1.0 / 3.0) * par_ros; + pi_par[4] = -eta_par * b_avg[1] * b_avg[2] * par_ros; + pi_par[5] = -eta_par * (b_avg[2] * b_avg[2] - 1.0 / 3.0) * par_ros; } // Calculate magnetized perpendicular viscous stress tensor -static void -calc_pi_perp(double eta_perp, double b_avg[3], double w[6], double pi_perp[6]) -{ +static void calc_pi_perp(double eta_perp, double b_avg[3], double w[6], double pi_perp[6]) +{ // (b . W . I)_x = b_x W_xx + b_y W_xy + b_z W_xz - double bWIx = w[0]*b_avg[0] + w[1]*b_avg[1] + w[2]*b_avg[2]; - // (b . W . I)_y = b_x W_xy + b_y W_yy + b_z W_yz - double bWIy = w[1]*b_avg[0] + w[3]*b_avg[1] + w[4]*b_avg[2]; + double bWIx = w[0] * b_avg[0] + w[1] * b_avg[1] + w[2] * b_avg[2]; + // (b . W . I)_y = b_x W_xy + b_y W_yy + b_z W_yz + double bWIy = w[1] * b_avg[0] + w[3] * b_avg[1] + w[4] * b_avg[2]; // (b . W . I)_z = b_x W_xz + b_y W_yz + b_z W_zz - double bWIz = w[0]*b_avg[2] + w[4]*b_avg[1] + w[5]*b_avg[2]; + double bWIz = w[0] * b_avg[2] + w[4] * b_avg[1] + w[5] * b_avg[2]; // b . W . b - double bWb = b_avg[0]*b_avg[0]*w[0] + 2.0*b_avg[0]*b_avg[1]*w[1] + 2.0*b_avg[0]*b_avg[2]*w[2] - + b_avg[1]*b_avg[1]*w[3] + 2.0*b_avg[1]*b_avg[2]*w[4] - + b_avg[2]*b_avg[2]*w[5]; + double bWb = b_avg[0] * b_avg[0] * w[0] + 2.0 * b_avg[0] * b_avg[1] * w[1] + + 2.0 * b_avg[0] * b_avg[2] * w[2] + b_avg[1] * b_avg[1] * w[3] + + 2.0 * b_avg[1] * b_avg[2] * w[4] + b_avg[2] * b_avg[2] * w[5]; // pi_perp = -eta_perp * ((I - bb) . W . (I + 3bb) + (I + 3bb) . W . (I - bb)) - pi_perp[0] = -eta_perp*(2.0*(w[0] + 2.0*b_avg[0]*bWIx - 3.0*b_avg[0]*b_avg[0]*bWb)); - pi_perp[1] = -eta_perp*(2.0*w[1] + 2.0*(b_avg[1]*bWIx + b_avg[0]*bWIy) - 6.0*b_avg[0]*b_avg[1]*bWb); - pi_perp[2] = -eta_perp*(2.0*w[2] + 2.0*(b_avg[2]*bWIx + b_avg[0]*bWIz) - 6.0*b_avg[0]*b_avg[2]*bWb); - pi_perp[3] = -eta_perp*(2.0*(w[3] + 2.0*b_avg[1]*bWIy - 3.0*b_avg[1]*b_avg[1]*bWb)); - pi_perp[4] = -eta_perp*(2.0*w[4] + 2.0*(b_avg[2]*bWIy + b_avg[1]*bWIz) - 6.0*b_avg[1]*b_avg[2]*bWb); - pi_perp[5] = -eta_perp*(2.0*(w[5] + 2.0*b_avg[2]*bWIz - 3.0*b_avg[2]*b_avg[2]*bWb)); + pi_perp[0] = -eta_perp * (2.0 * (w[0] + 2.0 * b_avg[0] * bWIx - 3.0 * b_avg[0] * b_avg[0] * bWb)); + pi_perp[1] = -eta_perp * (2.0 * w[1] + 2.0 * (b_avg[1] * bWIx + b_avg[0] * bWIy) - + 6.0 * b_avg[0] * b_avg[1] * bWb); + pi_perp[2] = -eta_perp * (2.0 * w[2] + 2.0 * (b_avg[2] * bWIx + b_avg[0] * bWIz) - + 6.0 * b_avg[0] * b_avg[2] * bWb); + pi_perp[3] = -eta_perp * (2.0 * (w[3] + 2.0 * b_avg[1] * bWIy - 3.0 * b_avg[1] * b_avg[1] * bWb)); + pi_perp[4] = -eta_perp * (2.0 * w[4] + 2.0 * (b_avg[2] * bWIy + b_avg[1] * bWIz) - + 6.0 * b_avg[1] * b_avg[2] * bWb); + pi_perp[5] = -eta_perp * (2.0 * (w[5] + 2.0 * b_avg[2] * bWIz - 3.0 * b_avg[2] * b_avg[2] * bWb)); } // Calculate magnetized gyroviscous viscous stress tensor -static void -calc_pi_cross(double eta_cross, double b_avg[3], double w[6], double pi_cross[6]) +static void calc_pi_cross(double eta_cross, double b_avg[3], double w[6], double pi_cross[6]) { pi_cross[0] = 0.0; pi_cross[1] = 0.0; diff --git a/moments/zero/gkyl_moment_prim_mhd.h b/moments/zero/gkyl_moment_prim_mhd.h index 8506697359..c0b50f5eed 100644 --- a/moments/zero/gkyl_moment_prim_mhd.h +++ b/moments/zero/gkyl_moment_prim_mhd.h @@ -6,12 +6,10 @@ * @param gas_gamma Gas adiabatic constant * @param q Conserved variables */ -static inline double -gkyl_mhd_pressure(double gas_gamma, const double q[8]) +static inline double gkyl_mhd_pressure(double gas_gamma, const double q[8]) { - return (gas_gamma-1) * - (q[4] - 0.5*(q[1]*q[1]+q[2]*q[2]+q[3]*q[3])/q[0] - - 0.5*(q[5]*q[5]+q[6]*q[6]+q[7]*q[7])); + return (gas_gamma - 1) * (q[4] - 0.5 * (q[1] * q[1] + q[2] * q[2] + q[3] * q[3]) / q[0] - + 0.5 * (q[5] * q[5] + q[6] * q[6] + q[7] * q[7])); } /** @@ -40,8 +38,7 @@ double gkyl_mhd_max_abs_speed(double gas_gamma, const double q[8]); * @param buf Array with four elements to hold computed u, v, w, cfast. * @return buf */ -void gkyl_mhd_eigen_speeds_roe(const double gamma, const double *ql, - const double *qr, double buf[]); +void gkyl_mhd_eigen_speeds_roe(const double gamma, const double *ql, const double *qr, double buf[]); /** * Compute maximum absolute speed using MHD flow and fast Alfven speed due to a diff --git a/moments/zero/gkyl_moment_prim_sr_euler.h b/moments/zero/gkyl_moment_prim_sr_euler.h index 887bac2c5c..58e095090b 100644 --- a/moments/zero/gkyl_moment_prim_sr_euler.h +++ b/moments/zero/gkyl_moment_prim_sr_euler.h @@ -16,16 +16,15 @@ * @param q Conserved variables * @param v Primitive variables (output) */ -static inline void -gkyl_sr_euler_prim_vars(double gas_gamma, const double q[5], double v[5]) +static inline void gkyl_sr_euler_prim_vars(double gas_gamma, const double q[5], double v[5]) { - double us=0., vs=0., ws=0., q2s = 0., cs2 = 0.; - double gammas=0., rhos=0., rhoEpss = 0., fs = 0., dfs = 0., fac0 = 1.; + double us = 0., vs = 0., ws = 0., q2s = 0., cs2 = 0.; + double gammas = 0., rhos = 0., rhoEpss = 0., fs = 0., dfs = 0., fac0 = 1.; double g1 = gas_gamma - 1; - double ps = 0., ps2 = 1.; + double ps = 0., ps2 = 1.; double tol = 1.e-6; size_t iter = 0; - + while (fabs(ps2 - ps) > tol) { iter += 1; ps = ps2; @@ -33,33 +32,33 @@ gkyl_sr_euler_prim_vars(double gas_gamma, const double q[5], double v[5]) us = q[2] / fac0; vs = q[3] / fac0; ws = q[4] / fac0; - q2s = us*us + vs*vs + ws*ws; + q2s = us * us + vs * vs + ws * ws; //gammas = 1. / sqrt(1. - q2s); gammas = pow(fabs(1. - q2s), -0.5); - + rhos = q[0] / gammas; - rhoEpss = (q[1] - gammas*q[0] + ps*(1 - gammas*gammas)) / (gammas*gammas); - fs = g1*rhoEpss - ps; // (gas_gamma - 1)*rhos*eps - ps = p(rhos,epss) - ps, eqn 55 - cs2 = gas_gamma*gammas*gammas*ps / fac0; - dfs = q2s*cs2 - 1; // eqn 60 for df / dp + rhoEpss = (q[1] - gammas * q[0] + ps * (1 - gammas * gammas)) / (gammas * gammas); + fs = g1 * rhoEpss - ps; // (gas_gamma - 1)*rhos*eps - ps = p(rhos,epss) - ps, eqn 55 + cs2 = gas_gamma * gammas * gammas * ps / fac0; + dfs = q2s * cs2 - 1; // eqn 60 for df / dp ps2 = ps - fs / dfs; //printf("---> Iteration %ld (%g) \n", iter, ps2); //printf(" %lg %lg %lg %lg %lg\n", q[0], q[1], q[2], q[3], q[4]); } //printf("Iterations %ld. Error %lg \n", iter, fabs(ps2-ps)); - + fac0 = q[1] + ps2; - us = q[2] / fac0; + us = q[2] / fac0; vs = q[3] / fac0; ws = q[4] / fac0; - q2s = us*us + vs*vs + ws*ws; + q2s = us * us + vs * vs + ws * ws; //gammas = 1 / sqrt(1 - q2s); gammas = pow(fabs(1. - q2s), -0.5); - + v[0] = q[0] / gammas; // rho v[1] = ps2; // p - v[2] = us; + v[2] = us; v[3] = vs; v[4] = ws; } diff --git a/moments/zero/gkyl_mp_scheme.h b/moments/zero/gkyl_mp_scheme.h index 4fa196e129..988a45577f 100644 --- a/moments/zero/gkyl_mp_scheme.h +++ b/moments/zero/gkyl_mp_scheme.h @@ -12,10 +12,10 @@ enum gkyl_mp_recon { GKYL_MP_U5 = 0, // upwind-biased 5th order (default) GKYL_MP_C2, // centered second-order - GKYL_MP_C4, // centered fourth-order + GKYL_MP_C4, // centered fourth-order GKYL_MP_C6, // centered sixth-order GKYL_MP_U1, // upwind-biased 1st order - GKYL_MP_U3, // upwind-biased 3rd order + GKYL_MP_U3 // upwind-biased 3rd order }; // Object type for updater @@ -31,7 +31,7 @@ struct gkyl_mp_scheme_inp { int num_up_dirs; // number of update directions int update_dirs[GKYL_MAX_DIM]; // directions to update - double cfl; // CFL number to use + double cfl; // CFL number to use const struct gkyl_wave_geom *geom; // geometry }; @@ -42,7 +42,7 @@ struct gkyl_mp_scheme_inp { * * @param winp Input for creating updater. See gkyl_mp_scheme_inp above. */ -gkyl_mp_scheme* gkyl_mp_scheme_new(const struct gkyl_mp_scheme_inp *winp); +gkyl_mp_scheme *gkyl_mp_scheme_new(const struct gkyl_mp_scheme_inp *winp); /** * Compute wave-propagation update. The update_rng MUST be a sub-range @@ -62,11 +62,12 @@ gkyl_mp_scheme* gkyl_mp_scheme_new(const struct gkyl_mp_scheme_inp *winp); * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS of PDE */ -void gkyl_mp_scheme_advance(gkyl_mp_scheme *mp, - const struct gkyl_range *update_range, const struct gkyl_array *qin, - struct gkyl_array *qrec_l, struct gkyl_array *qrec_r, - struct gkyl_array *amdq, struct gkyl_array *apdq, - struct gkyl_array *cflrate, struct gkyl_array *phi, struct gkyl_array *rhs); +void gkyl_mp_scheme_advance( + gkyl_mp_scheme *mp, const struct gkyl_range *update_range, const struct gkyl_array *qin, + struct gkyl_array *qrec_l, struct gkyl_array *qrec_r, struct gkyl_array *amdq, + struct gkyl_array *apdq, struct gkyl_array *cflrate, struct gkyl_array *phi, + struct gkyl_array *rhs +); /** * Compute an estimate of maximum stable time-step for given input @@ -76,12 +77,13 @@ void gkyl_mp_scheme_advance(gkyl_mp_scheme *mp, * @param qin Input to compute dt for * @return maximum stable time-step */ -double gkyl_mp_scheme_max_dt(const gkyl_mp_scheme *mp, const struct gkyl_range *update_range, - const struct gkyl_array *qin); +double gkyl_mp_scheme_max_dt( + const gkyl_mp_scheme *mp, const struct gkyl_range *update_range, const struct gkyl_array *qin +); /** * Delete updater. * * @param mp Updater to delete. */ -void gkyl_mp_scheme_release(gkyl_mp_scheme* mp); +void gkyl_mp_scheme_release(gkyl_mp_scheme *mp); diff --git a/moments/zero/gkyl_sources_explicit_priv.h b/moments/zero/gkyl_sources_explicit_priv.h index 71c059450d..740a0285a0 100644 --- a/moments/zero/gkyl_sources_explicit_priv.h +++ b/moments/zero/gkyl_sources_explicit_priv.h @@ -14,8 +14,9 @@ typedef struct gkyl_moment_em_coupling gkyl_moment_em_coupling; * @param fluid_new Array of new fluid variables for a single fluid species (after source update). * @param nT_sources Array of number density and temperature source terms for a single fluid species. */ -void -explicit_nT_source_update_euler(const double mass, const double dt, double* fluid_old, double* fluid_new, const double* nT_sources); +void explicit_nT_source_update_euler( + const double mass, const double dt, double *fluid_old, double *fluid_new, const double *nT_sources +); /** * Integrate the number density and temperature source terms in the multi-fluid equation system within a single cell, using an explicit forcing @@ -26,9 +27,10 @@ explicit_nT_source_update_euler(const double mass, const double dt, double* flui * @param fluid_s Array of fluid variables (array size = nfluids). * @param nT_sources_s Array of number density and temperature source terms. */ -void -explicit_nT_source_update(const gkyl_moment_em_coupling* mom_em, const double dt, double* fluid_s[GKYL_MAX_SPECIES], - const double* nT_sources_s[GKYL_MAX_SPECIES]); +void explicit_nT_source_update( + const gkyl_moment_em_coupling *mom_em, const double dt, double *fluid_s[GKYL_MAX_SPECIES], + const double *nT_sources_s[GKYL_MAX_SPECIES] +); /** * Integrate the frictional source terms in the multi-fluid equation system within a single cell, using an explicit forcing solver (specifically a @@ -45,9 +47,11 @@ explicit_nT_source_update(const gkyl_moment_em_coupling* mom_em, const double dt * @param f_elc_new Array of new electron fluid variables (after source update). * @param f_ion_new Array of new ion fluid variables (after source update). */ -void -explicit_frictional_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double Z, const double T_elc, const double Lambda_ee, - double t_curr, const double dt, double* f_elc_old, double* f_ion_old, double* f_elc_new, double* f_ion_new); +void explicit_frictional_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double Z, const double T_elc, const double Lambda_ee, + double t_curr, const double dt, double *f_elc_old, double *f_ion_old, double *f_elc_new, + double *f_ion_new +); /** * Integrate the frictional source terms in the multi-fluid equation system within a single cell, using an explicit forcing solver (specifically a @@ -58,8 +62,10 @@ explicit_frictional_source_update_euler(const gkyl_moment_em_coupling* mom_em, c * @param dt Current stable time-step. * @param fluid_s Array of fluid variables (array size = nfluids). */ -void -explicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]); +void explicit_frictional_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +); /** * Integrate the volume-based geometrical source terms (e.g. for expanding/contracting box formalism) in the multi-fluid equation system for a @@ -74,9 +80,10 @@ explicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double * @param fluid_old Array of old single-species 5-moment fluid variables (before source update). * @param fluid_new Array of new single-species 5-moment fluid variables (after source update). */ -void -explicit_volume_source_5m_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, const double U0, const double R0, - double t_curr, const double dt, double* fluid_old, double* fluid_new); +void explicit_volume_source_5m_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, const double U0, const double R0, + double t_curr, const double dt, double *fluid_old, double *fluid_new +); /** * Integrate the volume-based geometrical source terms (e.g. for expanding/contracting box formalism) in the multi-fluid equation system for a @@ -90,9 +97,10 @@ explicit_volume_source_5m_update_euler(const gkyl_moment_em_coupling* mom_em, co * @param fluid_old Array of old single-species 10-moment fluid variables (before source update). * @param fluid_new Array of new single-species 10-moment fluid variables (after source update). */ -void -explicit_volume_source_10m_update_euler(const gkyl_moment_em_coupling* mom_em, const double U0, const double R0, double t_curr, const double dt, - double* fluid_old, double* fluid_new); +void explicit_volume_source_10m_update_euler( + const gkyl_moment_em_coupling *mom_em, const double U0, const double R0, double t_curr, + const double dt, double *fluid_old, double *fluid_new +); /** * Integrate the volume-based geometrical source terms (e.g. for expanding/contracting box formalism) in the multi-fluid equation system for a @@ -107,9 +115,10 @@ explicit_volume_source_10m_update_euler(const gkyl_moment_em_coupling* mom_em, c * @param em_new Array of new electromagnetic variables (after source update). * @param ext_em External electromagnetic variables (for EM fields coming from external sources, e.g. coils, capacitors, etc.). */ -void -explicit_volume_source_maxwell_update_euler(const gkyl_moment_em_coupling* mom_em, const double U0, const double R0, double t_curr, - const double dt, double* em_old, double* em_new, const double* ext_em); +void explicit_volume_source_maxwell_update_euler( + const gkyl_moment_em_coupling *mom_em, const double U0, const double R0, double t_curr, + const double dt, double *em_old, double *em_new, const double *ext_em +); /** * Integrate the volume-based geometrical source terms (e.g. for expanding/contracting box formalism) in the multi-fluid equation system within @@ -122,9 +131,10 @@ explicit_volume_source_maxwell_update_euler(const gkyl_moment_em_coupling* mom_e * @param em Array of electromagnetic variables. * @param ext_em External electromagnetic variables (for EM fields coming from external sources, e.g. coils, capacitors, etc.). */ -void -explicit_volume_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES], - double* em, const double* ext_em); +void explicit_volume_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES], double *em, const double *ext_em +); /** * Integrate the reactive source terms in the multi-fluid equation system within a single cell, using an explicit forcing solver (specifically a @@ -141,10 +151,12 @@ explicit_volume_source_update(const gkyl_moment_em_coupling* mom_em, double t_cu * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_reactive_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, const double specific_heat_capacity, - const double energy_of_formation, const double ignition_temperature, const double reaction_rate, double t_curr, const double dt, - double* fluid_old, double* fluid_new); +void explicit_reactive_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, + const double specific_heat_capacity, const double energy_of_formation, + const double ignition_temperature, const double reaction_rate, double t_curr, const double dt, + double *fluid_old, double *fluid_new +); /** * Integrate the reactive source terms in the multi-fluid equation system within a single cell, using an explicit forcing solver (specifically a @@ -155,8 +167,10 @@ explicit_reactive_source_update_euler(const gkyl_moment_em_coupling* mom_em, con * @param dt Current stable time-step. * @param fluid_s Array of fluid variables (array size = nfluids). */ -void -explicit_reactive_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]); +void explicit_reactive_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +); /** * Integrate the coupled fluid-Einstein source terms in plane-symmetric spacetimes in the multi-fluid equation system within a single cell, using an @@ -170,9 +184,10 @@ explicit_reactive_source_update(const gkyl_moment_em_coupling* mom_em, double t_ * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_medium_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, const double kappa, double t_curr, - const double dt, double* fluid_old, double* fluid_new); +void explicit_medium_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, const double kappa, double t_curr, + const double dt, double *fluid_old, double *fluid_new +); /** * Integrate the coupled fluid-Einstein source terms in plane-symmetric spacetimes in the multi-fluid equation system within a single cell, using an @@ -183,8 +198,10 @@ explicit_medium_source_update_euler(const gkyl_moment_em_coupling* mom_em, const * @param dt Current stable time-step. * @param fluid_s Array of fluid variables (array size = nfluids). */ -void -explicit_medium_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]); +void explicit_medium_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +); /** * Integrate the general relativistic source terms (Euler equations, ultra-relativistic equation of state) in the multi-fluid equation system within a @@ -197,9 +214,10 @@ explicit_medium_source_update(const gkyl_moment_em_coupling* mom_em, double t_cu * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, double t_curr, const double dt, - double* fluid_old, double* fluid_new); +void explicit_gr_ultra_rel_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, double t_curr, const double dt, + double *fluid_old, double *fluid_new +); /** * Integrate the general relativistic source terms (Euler equations, ultra-relativistic equation of state) in the multi-fluid equation system within a @@ -210,8 +228,10 @@ explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, * @param dt Current stable time-step. * @param fluid_s Array of fluid variables (array size = nfluids). */ -void -explicit_gr_ultra_rel_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]); +void explicit_gr_ultra_rel_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +); /** * Integrate the general relativistic source terms (Euler equations, general equation of state) in the multi-fluid equation system within a @@ -224,9 +244,10 @@ explicit_gr_ultra_rel_source_update(const gkyl_moment_em_coupling* mom_em, doubl * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_gr_euler_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, double t_curr, const double dt, - double* fluid_old, double* fluid_new); +void explicit_gr_euler_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, double t_curr, const double dt, + double *fluid_old, double *fluid_new +); /** * Integrate the general relativistic source terms (Euler equations, general equation of state) in the multi-fluid equation system within a @@ -237,8 +258,10 @@ explicit_gr_euler_source_update_euler(const gkyl_moment_em_coupling* mom_em, con * @param dt Current stable time-step. * @param fluid_s Array of fluid variables (array size = nfluids). */ -void -explicit_gr_euler_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]); +void explicit_gr_euler_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +); /** * Integrate the electron coupling source terms in the general relativistic two-fluid equation system within a single cell, using an explicit @@ -253,9 +276,10 @@ explicit_gr_euler_source_update(const gkyl_moment_em_coupling* mom_em, double t_ * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_gr_twofluid_source_update_elc_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma_elc, const double mass_elc, - const double charge_elc, double t_curr, const double dt, double* fluid_old, double* fluid_new); +void explicit_gr_twofluid_source_update_elc_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma_elc, const double mass_elc, + const double charge_elc, double t_curr, const double dt, double *fluid_old, double *fluid_new +); /** * Integrate the ion coupling source terms in the general relativistic two-fluid equation system within a single cell, using an explicit @@ -270,9 +294,10 @@ explicit_gr_twofluid_source_update_elc_euler(const gkyl_moment_em_coupling* mom_ * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_gr_twofluid_source_update_ion_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma_ion, const double mass_ion, - const double charge_ion, double t_curr, const double dt, double* fluid_old, double* fluid_new); +void explicit_gr_twofluid_source_update_ion_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma_ion, const double mass_ion, + const double charge_ion, double t_curr, const double dt, double *fluid_old, double *fluid_new +); /** * Integrate the electromagnetic coupling source terms in the general relativistic two-fluid equation system within a single cell, using an @@ -291,10 +316,11 @@ explicit_gr_twofluid_source_update_ion_euler(const gkyl_moment_em_coupling* mom_ * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_gr_twofluid_source_update_em_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma_elc, const double gas_gamma_ion, - const double mass_elc, const double charge_elc, const double mass_ion, const double charge_ion, double e_fact, double t_curr, const double dt, - double* fluid_old, double* fluid_new); +void explicit_gr_twofluid_source_update_em_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma_elc, const double gas_gamma_ion, + const double mass_elc, const double charge_elc, const double mass_ion, const double charge_ion, + double e_fact, double t_curr, const double dt, double *fluid_old, double *fluid_new +); /** * Integrate the curved spacetime coupling source terms for the electrons in the general relativistic two-fluid equation system within a single @@ -307,9 +333,10 @@ explicit_gr_twofluid_source_update_em_euler(const gkyl_moment_em_coupling* mom_e * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_gr_twofluid_source_update_elc_spacetime_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma_elc, double t_curr, - const double dt, double* fluid_old, double* fluid_new); +void explicit_gr_twofluid_source_update_elc_spacetime_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma_elc, double t_curr, const double dt, + double *fluid_old, double *fluid_new +); /** * Integrate the curved spacetime coupling source terms for the ions in the general relativistic two-fluid equation system within a single @@ -322,9 +349,10 @@ explicit_gr_twofluid_source_update_elc_spacetime_euler(const gkyl_moment_em_coup * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_gr_twofluid_source_update_ion_spacetime_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma_ion, double t_curr, - const double dt, double* fluid_old, double* fluid_new); +void explicit_gr_twofluid_source_update_ion_spacetime_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma_ion, double t_curr, const double dt, + double *fluid_old, double *fluid_new +); /** * Integrate all electron, ion, and electromagnetic coupling source terms in the general relativistic two-fluid equation system within a @@ -335,8 +363,10 @@ explicit_gr_twofluid_source_update_ion_spacetime_euler(const gkyl_moment_em_coup * @param dt Current stable time-step. * @param fluid_s Array of fluid variables (array size = nfluids). */ -void -explicit_gr_twofluid_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]); +void explicit_gr_twofluid_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +); /** * Integrate the vacuum Einstein source terms (Bona-Masso formalism) in the dynamic spacetime equation system within a single cell, using an @@ -351,10 +381,12 @@ explicit_gr_twofluid_source_update(const gkyl_moment_em_coupling* mom_em, double * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double excision_threshold, - const enum gkyl_spacetime_slicing spacetime_slicing, const enum gkyl_spacetime_evolution spacetime_evolution, double t_curr, const double dt, - double* fluid_old, double* fluid_new); +void explicit_vacuum_einstein_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double excision_threshold, + const enum gkyl_spacetime_slicing spacetime_slicing, + const enum gkyl_spacetime_evolution spacetime_evolution, double t_curr, const double dt, + double *fluid_old, double *fluid_new +); /** * Integrate the vacuum Einstein source terms (Bona-Masso formalism) in the dynamic spacetime equation system within a single cell, using an @@ -365,8 +397,10 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ * @param dt Current stable time-step. * @param fluid_s Array of fluid variables (array size = nfluids). */ -void -explicit_vacuum_einstein_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]); +void explicit_vacuum_einstein_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +); /** * Integrate the vacuum Einstein source terms (conformal Bona-Masso formalism) in the dynamic spacetime equation system within a single cell, using an @@ -381,10 +415,12 @@ explicit_vacuum_einstein_source_update(const gkyl_moment_em_coupling* mom_em, do * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double excision_threshold, - const enum gkyl_spacetime_slicing spacetime_slicing, const enum gkyl_spacetime_evolution spacetime_evolution, double t_curr, const double dt, - double* fluid_old, double* fluid_new); +void explicit_vacuum_einstein_conformal_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double excision_threshold, + const enum gkyl_spacetime_slicing spacetime_slicing, + const enum gkyl_spacetime_evolution spacetime_evolution, double t_curr, const double dt, + double *fluid_old, double *fluid_new +); /** * Integrate the vacuum Einstein source terms (conformal Bona-Masso formalism) in the dynamic spacetime equation system within a single cell, using an @@ -395,8 +431,10 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup * @param dt Current stable time-step. * @param fluid_s Array of fluid variables (array size = nfluids). */ -void -explicit_vacuum_einstein_conformal_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]); +void explicit_vacuum_einstein_conformal_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +); /** * Integrate the general relativistic source terms (general relativistic magnetohydrodynamics equations) in the multi-fluid equation system within a @@ -409,9 +447,10 @@ single cell, using an explicit forcing solver (specifically a simple first-order * @param fluid_old Array of old fluid variables (before source update). * @param fluid_new Array of new fluid variables (after source update). */ -void -explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, double t_curr, const double dt, - double* fluid_old, double* fluid_new); +void explicit_gr_mhd_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, double t_curr, const double dt, + double *fluid_old, double *fluid_new +); /** * Integrate the general relativistic source terms (general relativistic magnetohydrodynamics) in the multi-fluid equation system within a @@ -422,8 +461,10 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const * @param dt Current stable time-step. * @param fluid_s Array of fluid variables (array size = nfluids). */ -void -explicit_gr_mhd_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]); +void explicit_gr_mhd_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +); /** * Integrate the electric field source terms in the multi-field equation system within a single cell, using an explicit forcing solver (specifically @@ -437,9 +478,10 @@ explicit_gr_mhd_source_update(const gkyl_moment_em_coupling* mom_em, double t_cu * @param fluid_s Array of fluid variables (array size = nfluids). * @param app_current Array of current terms to be applied to the fluid equations (for external current driving). */ -void -explicit_e_field_source_update_euler(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, double e_field_old[3], double* e_field_new, - double* fluid_s[GKYL_MAX_SPECIES], const double* app_current); +void explicit_e_field_source_update_euler( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, double e_field_old[3], + double *e_field_new, double *fluid_s[GKYL_MAX_SPECIES], const double *app_current +); /** * Integrate the electric field source terms in the multi-fluid equation system within a single cell, using an explicit forcing solver (specifically @@ -455,9 +497,11 @@ explicit_e_field_source_update_euler(const gkyl_moment_em_coupling* mom_em, doub * @param app_current2 Array of stage-2 current terms to be applied to the fluid equations (for stage-2 of external current driving). * @param ext_em External electromagnetic variables (for EM fields coming from external sources, e.g. coils, capacitors, etc.). */ -void -explicit_e_field_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, double* fluid_s[GKYL_MAX_SPECIES], - double* em, const double* app_current, const double* app_current1, const double* app_current2, const double* ext_em); +void explicit_e_field_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double *fluid_s[GKYL_MAX_SPECIES], double *em, const double *app_current, + const double *app_current1, const double *app_current2, const double *ext_em +); /** * Perform a Higuera-Cary particle push of the fluid momentum in the multi-fluid equation system within a single cell, assuming a cold relativistic @@ -470,9 +514,10 @@ explicit_e_field_source_update(const gkyl_moment_em_coupling* mom_em, double t_c * @param e_field Array of electric field variables. * @param b_field Array of magnetic field variables. */ -void -explicit_higuera_cary_push(double* vel, const double q, const double m, const double dt, const double c, const double e_field[3], - const double b_field[3]); +void explicit_higuera_cary_push( + double *vel, const double q, const double m, const double dt, const double c, + const double e_field[3], const double b_field[3] +); /** * Integrate the momentum source terms in the multi-fluid equation system within a single cell, using a Higuera-Cary particle push, assuming a cold @@ -486,9 +531,11 @@ explicit_higuera_cary_push(double* vel, const double q, const double m, const do * @param em Array of electromagnetic variables. * @param ext_em External electromagnetic variables (for EM fields coming from external sources, e.g. coils, capacitors, etc.). */ -void -explicit_higuera_cary_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, double* fluid_s[GKYL_MAX_SPECIES], - const double* app_accel_s[GKYL_MAX_SPECIES], double* em, const double* ext_em); +void explicit_higuera_cary_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double *fluid_s[GKYL_MAX_SPECIES], const double *app_accel_s[GKYL_MAX_SPECIES], double *em, + const double *ext_em +); /** * Integrate the electromagnetic source terms in the multi-fluid equation system within each cell, using an explicit forcing solver (specifically @@ -506,7 +553,9 @@ explicit_higuera_cary_update(const gkyl_moment_em_coupling* mom_em, double t_cur * @param ext_em External electromagnetic variables (for EM fields coming from external sources, e.g. coils, capacitors, etc.). * @param nstrang Indictator of which step in the Strang splitting we are currently considering. */ -void -explicit_source_coupling_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, double* fluid_s[GKYL_MAX_SPECIES], - const double* app_accel_s[GKYL_MAX_SPECIES], double* em, const double* app_current, const double* app_current1, const double* app_current2, - const double* ext_em, int nstrang); \ No newline at end of file +void explicit_source_coupling_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double *fluid_s[GKYL_MAX_SPECIES], const double *app_accel_s[GKYL_MAX_SPECIES], double *em, + const double *app_current, const double *app_current1, const double *app_current2, + const double *ext_em, int nstrang +); \ No newline at end of file diff --git a/moments/zero/gkyl_sources_implicit_priv.h b/moments/zero/gkyl_sources_implicit_priv.h index 591ab9cb2f..4c33866c21 100644 --- a/moments/zero/gkyl_sources_implicit_priv.h +++ b/moments/zero/gkyl_sources_implicit_priv.h @@ -15,8 +15,10 @@ typedef struct gkyl_moment_em_coupling gkyl_moment_em_coupling; * @param p_tensor_rhs Source terms appearing on the right-hand-side of the pressure tensor equations. * @param p_tensor_new New components of the pressure tensor (after rotation). */ -void pressure_tensor_rotate(double q_over_m, double dt, const double* em, const double* ext_em, double p_tensor_old[6], double p_tensor_rhs[6], - double p_tensor_new[6]); +void pressure_tensor_rotate( + double q_over_m, double dt, const double *em, const double *ext_em, double p_tensor_old[6], + double p_tensor_rhs[6], double p_tensor_new[6] +); /** * Integrate the electromagnetic source terms of a charged multi-fluid equation system within a single cell, using an implicit forcing solver @@ -32,10 +34,12 @@ void pressure_tensor_rotate(double q_over_m, double dt, const double* em, const * @param app_current Array of current terms to be applied to the fluid equations (for external current driving). * @param ext_em External electromagnetic variables (for EM fields coming from external sources, e.g. coils, capacitors, etc.). */ -void -implicit_em_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, - double fluid_rhs_s[GKYL_MAX_SPECIES][4], double* fluid_s[GKYL_MAX_SPECIES], - const double *app_accel_s[GKYL_MAX_SPECIES], double* em, const double* app_current, const double* ext_em); +void implicit_em_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double fluid_rhs_s[GKYL_MAX_SPECIES][4], double *fluid_s[GKYL_MAX_SPECIES], + const double *app_accel_s[GKYL_MAX_SPECIES], double *em, const double *app_current, + const double *ext_em +); /** * Integrate the momentum source terms of a neutral multi-fluid equation system within a single cell, using an implicit forcing solver (specifically @@ -50,10 +54,11 @@ implicit_em_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, * @param p_rhs_s Array of right-hand-side source terms; for neutral ten-moment fluids the pressure-tensor * components (indices 4-9) are applied as a direct forward-Euler increment (e.g. a heat-flux closure). */ -void -implicit_neut_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, - double fluid_rhs_s[GKYL_MAX_SPECIES][4], double* fluid_s[GKYL_MAX_SPECIES], - const double* app_accel_s[GKYL_MAX_SPECIES], const double* p_rhs_s[GKYL_MAX_SPECIES]); +void implicit_neut_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double fluid_rhs_s[GKYL_MAX_SPECIES][4], double *fluid_s[GKYL_MAX_SPECIES], + const double *app_accel_s[GKYL_MAX_SPECIES], const double *p_rhs_s[GKYL_MAX_SPECIES] +); /** * Integrate the collisional source terms of a multi-fluid equation system within a single cell, using an implicit forcing solver (specifically the @@ -63,8 +68,9 @@ implicit_neut_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr * @param dt Current stable time-step. * @param fluid_s Array of fluid variables (array size = nfluids). */ -void -implicit_collision_source_update(const gkyl_moment_em_coupling* mom_em, double dt, double* fluid_s[GKYL_MAX_SPECIES]); +void implicit_collision_source_update( + const gkyl_moment_em_coupling *mom_em, double dt, double *fluid_s[GKYL_MAX_SPECIES] +); /** * Integrate the frictional source terms in the multi-fluid equation system within a single cell, using an implicit forcing solver (specifically @@ -86,10 +92,12 @@ implicit_collision_source_update(const gkyl_moment_em_coupling* mom_em, double d * @param app_current Array of current terms to be applied to the fluid equations (for external current driving). * @param ext_em External electromagnetic variables (for EM fields coming from external sources, e.g. coils, capacitors, etc.). */ -void -implicit_frictional_source_update_half(const gkyl_moment_em_coupling* mom_em, const double Z, const double T_elc, const double Lambda_ee, - double t_curr, const double dt, double* f_elc_old, double* f_ion_old, double* f_elc_new, double* f_ion_new, - const double* app_accel_s[GKYL_MAX_SPECIES], double* em_old, double* em_new, const double* app_current, const double* ext_em); +void implicit_frictional_source_update_half( + const gkyl_moment_em_coupling *mom_em, const double Z, const double T_elc, const double Lambda_ee, + double t_curr, const double dt, double *f_elc_old, double *f_ion_old, double *f_elc_new, + double *f_ion_new, const double *app_accel_s[GKYL_MAX_SPECIES], double *em_old, double *em_new, + const double *app_current, const double *ext_em +); /** * Integrate the frictional source terms in the multi-fluid equation system within a single cell, using an implicit forcing solver (specifically @@ -104,9 +112,11 @@ implicit_frictional_source_update_half(const gkyl_moment_em_coupling* mom_em, co * @param app_current Array of current terms to be applied to the fluid equations (for external current driving). * @param ext_em External electromagnetic variables (for EM fields coming from external sources, e.g. coils, capacitors, etc.). */ -void -implicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, double* fluid_s[GKYL_MAX_SPECIES], - const double* app_accel_s[GKYL_MAX_SPECIES], double* em, const double* app_current, const double* ext_em); +void implicit_frictional_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double *fluid_s[GKYL_MAX_SPECIES], const double *app_accel_s[GKYL_MAX_SPECIES], double *em, + const double *app_current, const double *ext_em +); /** * Integrate the electromagnetic source terms in the multi-fluid equation system within each cell, using an implicit forcing solver (specifically @@ -123,7 +133,9 @@ implicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double * @param ext_em External electromagnetic variables (for EM fields coming from external sources, e.g. coils, capacitors, etc.). * @param nT_sources_s Array of number density and temperature source terms. */ -void -implicit_source_coupling_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, double* fluid_s[GKYL_MAX_SPECIES], - const double* app_accel_s[GKYL_MAX_SPECIES], const double* p_rhs_s[GKYL_MAX_SPECIES], double* em, const double* app_current, - const double* ext_em, const double* nT_sources_s[GKYL_MAX_SPECIES]); +void implicit_source_coupling_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double *fluid_s[GKYL_MAX_SPECIES], const double *app_accel_s[GKYL_MAX_SPECIES], + const double *p_rhs_s[GKYL_MAX_SPECIES], double *em, const double *app_current, + const double *ext_em, const double *nT_sources_s[GKYL_MAX_SPECIES] +); diff --git a/moments/zero/gkyl_ten_moment_grad_closure.h b/moments/zero/gkyl_ten_moment_grad_closure.h index 37722aeb22..1fb23b8eaa 100644 --- a/moments/zero/gkyl_ten_moment_grad_closure.h +++ b/moments/zero/gkyl_ten_moment_grad_closure.h @@ -33,7 +33,8 @@ typedef struct gkyl_ten_moment_grad_closure gkyl_ten_moment_grad_closure; * * @param inp Input parameters to updater */ -gkyl_ten_moment_grad_closure* gkyl_ten_moment_grad_closure_new(const struct gkyl_ten_moment_grad_closure_inp *inp); +gkyl_ten_moment_grad_closure * +gkyl_ten_moment_grad_closure_new(const struct gkyl_ten_moment_grad_closure_inp *inp); /** * Compute RHS contribution from symmetrized gradient-based closure @@ -51,11 +52,12 @@ gkyl_ten_moment_grad_closure* gkyl_ten_moment_grad_closure_new(const struct gkyl * @param heat_flux Array for storing intermediate computation of heat flux tensor (cell nodes) * @param rhs RHS output (NOTE: Returns RHS output of all nfluids) */ -struct gkyl_ten_moment_grad_closure_status gkyl_ten_moment_grad_closure_advance( +struct gkyl_ten_moment_grad_closure_status gkyl_ten_moment_grad_closure_advance( const gkyl_ten_moment_grad_closure *gces, const struct gkyl_range *heat_flux_range, const struct gkyl_range *update_range, const struct gkyl_array *fluid, const struct gkyl_array *em_tot, struct gkyl_array *cflrate, double dt, - struct gkyl_array *heat_flux, struct gkyl_array *rhs); + struct gkyl_array *heat_flux, struct gkyl_array *rhs +); /** * Delete updater. diff --git a/moments/zero/gkyl_ten_moment_grad_closure_priv.h b/moments/zero/gkyl_ten_moment_grad_closure_priv.h index 5c5fd4463d..44a07ce6e9 100644 --- a/moments/zero/gkyl_ten_moment_grad_closure_priv.h +++ b/moments/zero/gkyl_ten_moment_grad_closure_priv.h @@ -1,10 +1,13 @@ #include -typedef void (*heat_flux_calc_t)(const gkyl_ten_moment_grad_closure *gces, - const double *fluid_d[], double *cflrate, double dt, double *q); +typedef void (*heat_flux_calc_t)( + const gkyl_ten_moment_grad_closure *gces, const double *fluid_d[], double *cflrate, double dt, + double *q +); -typedef void (*heat_flux_update_t)(const gkyl_ten_moment_grad_closure *gces, - const double *q[], double *rhs); +typedef void (*heat_flux_update_t)( + const gkyl_ten_moment_grad_closure *gces, const double *q[], double *rhs +); struct gkyl_ten_moment_grad_closure { struct gkyl_rect_grid grid; // grid object @@ -13,7 +16,7 @@ struct gkyl_ten_moment_grad_closure { double cfl; // CFL number to use double *cfla; bool use_gpu; // Boolean to determine whether wave equation object is on host or device - + struct gkyl_comm *comm; long offsets_centers[8]; long offsets_vertices[8]; @@ -44,28 +47,17 @@ static const unsigned Q233 = 8; static const unsigned Q333 = 9; // 1D stencil locations (L: lower, U: upper) -enum loc_1d { - L_1D, U_1D -}; +enum loc_1d { L_1D, U_1D }; // 2D stencil locations (L: lower, U: upper) -enum loc_2d { - LL_2D, LU_2D, - UL_2D, UU_2D -}; +enum loc_2d { LL_2D, LU_2D, UL_2D, UU_2D }; // 3D stencil locations (L: lower, U: upper) -enum loc_3d { - LLL_3D, LLU_3D, - LUL_3D, LUU_3D, - ULL_3D, ULU_3D, - UUL_3D, UUU_3D -}; +enum loc_3d { LLL_3D, LLU_3D, LUL_3D, LUU_3D, ULL_3D, ULU_3D, UUL_3D, UUU_3D }; -static void -create_offsets_vertices(const struct gkyl_range *range, long offsets[]) +static void create_offsets_vertices(const struct gkyl_range *range, long offsets[]) { - int arr1[3] = { -1, -1, -1 }, arr2[3] = { 0, 0, 0 }; + int arr1[3] = {-1, -1, -1}, arr2[3] = {0, 0, 0}; // box spanning stencil struct gkyl_range box3; gkyl_range_init(&box3, range->ndim, arr1, arr2); @@ -75,14 +67,14 @@ create_offsets_vertices(const struct gkyl_range *range, long offsets[]) // construct list of offsets int count = 0; - while (gkyl_range_iter_next(&iter3)) + while (gkyl_range_iter_next(&iter3)) { offsets[count++] = gkyl_range_offset(range, iter3.idx); + } } -static void -create_offsets_centers(const struct gkyl_range *range, long offsets[]) +static void create_offsets_centers(const struct gkyl_range *range, long offsets[]) { - int arr1[3] = { 0, 0, 0 }, arr2[3] = { 1, 1, 1 }; + int arr1[3] = {0, 0, 0}, arr2[3] = {1, 1, 1}; // box spanning stencil struct gkyl_range box3; gkyl_range_init(&box3, range->ndim, arr1, arr2); @@ -92,38 +84,42 @@ create_offsets_centers(const struct gkyl_range *range, long offsets[]) // construct list of offsets int count = 0; - while (gkyl_range_iter_next(&iter3)) + while (gkyl_range_iter_next(&iter3)) { offsets[count++] = gkyl_range_offset(range, iter3.idx); + } } -GKYL_CU_D -static void -var_setup(const gkyl_ten_moment_grad_closure *gces, - int start, int end, - const double *fluid_d[], - double rho[], double p[], double Tij[][6]) +GKYL_CU_D static void var_setup( + const gkyl_ten_moment_grad_closure *gces, int start, int end, const double *fluid_d[], + double rho[], double p[], double Tij[][6] +) { for (int j = start; j <= end; ++j) { rho[j] = fluid_d[j][RHO]; - p[j] = (fluid_d[j][P11] - fluid_d[j][MX]*fluid_d[j][MX]/fluid_d[j][RHO] - + fluid_d[j][P22] - fluid_d[j][MY]*fluid_d[j][MY]/fluid_d[j][RHO] - + fluid_d[j][P33] - fluid_d[j][MZ]*fluid_d[j][MZ]/fluid_d[j][RHO])/3.0; - Tij[j][T11] = (fluid_d[j][P11] - fluid_d[j][MX]*fluid_d[j][MX]/fluid_d[j][RHO])/fluid_d[j][RHO]; - Tij[j][T12] = (fluid_d[j][P12] - fluid_d[j][MX]*fluid_d[j][MY]/fluid_d[j][RHO])/fluid_d[j][RHO]; - Tij[j][T13] = (fluid_d[j][P13] - fluid_d[j][MX]*fluid_d[j][MZ]/fluid_d[j][RHO])/fluid_d[j][RHO]; - Tij[j][T22] = (fluid_d[j][P22] - fluid_d[j][MY]*fluid_d[j][MY]/fluid_d[j][RHO])/fluid_d[j][RHO]; - Tij[j][T23] = (fluid_d[j][P23] - fluid_d[j][MY]*fluid_d[j][MZ]/fluid_d[j][RHO])/fluid_d[j][RHO]; - Tij[j][T33] = (fluid_d[j][P33] - fluid_d[j][MZ]*fluid_d[j][MZ]/fluid_d[j][RHO])/fluid_d[j][RHO]; + p[j] = (fluid_d[j][P11] - fluid_d[j][MX] * fluid_d[j][MX] / fluid_d[j][RHO] + fluid_d[j][P22] - + fluid_d[j][MY] * fluid_d[j][MY] / fluid_d[j][RHO] + fluid_d[j][P33] - + fluid_d[j][MZ] * fluid_d[j][MZ] / fluid_d[j][RHO]) / + 3.0; + Tij[j][T11] = + (fluid_d[j][P11] - fluid_d[j][MX] * fluid_d[j][MX] / fluid_d[j][RHO]) / fluid_d[j][RHO]; + Tij[j][T12] = + (fluid_d[j][P12] - fluid_d[j][MX] * fluid_d[j][MY] / fluid_d[j][RHO]) / fluid_d[j][RHO]; + Tij[j][T13] = + (fluid_d[j][P13] - fluid_d[j][MX] * fluid_d[j][MZ] / fluid_d[j][RHO]) / fluid_d[j][RHO]; + Tij[j][T22] = + (fluid_d[j][P22] - fluid_d[j][MY] * fluid_d[j][MY] / fluid_d[j][RHO]) / fluid_d[j][RHO]; + Tij[j][T23] = + (fluid_d[j][P23] - fluid_d[j][MY] * fluid_d[j][MZ] / fluid_d[j][RHO]) / fluid_d[j][RHO]; + Tij[j][T33] = + (fluid_d[j][P33] - fluid_d[j][MZ] * fluid_d[j][MZ] / fluid_d[j][RHO]) / fluid_d[j][RHO]; } } -GKYL_CU_D -static inline double -calc_sym_grad_limiter_2D(double alpha, double a, double b) +GKYL_CU_D static inline double calc_sym_grad_limiter_2D(double alpha, double a, double b) { - double avg = (a + b)/2; - double min = fmin(alpha*a, a/alpha); - double max = fmax(alpha*a, a/alpha); + double avg = (a + b) / 2; + double min = fmin(alpha * a, a / alpha); + double max = fmax(alpha * a, a / alpha); if (avg <= min) { return min; } else if (avg >= max) { @@ -133,13 +129,12 @@ calc_sym_grad_limiter_2D(double alpha, double a, double b) } } -GKYL_CU_D -static inline double +GKYL_CU_D static inline double calc_sym_grad_limiter_3D(double alpha, double a, double b, double c, double d) { - double avg = (a + b + c + d)/4; - double min = fmin(alpha*a, a/alpha); - double max = fmax(alpha*a, a/alpha); + double avg = (a + b + c + d) / 4; + double min = fmin(alpha * a, a / alpha); + double max = fmax(alpha * a, a / alpha); if (avg <= min) { return min; } else if (avg >= max) { @@ -149,10 +144,10 @@ calc_sym_grad_limiter_3D(double alpha, double a, double b, double c, double d) } } -GKYL_CU_D -static void -calc_unmag_heat_flux_1d(const gkyl_ten_moment_grad_closure *gces, - const double *fluid_d[], double *cflrate, double dt, double *q) +GKYL_CU_D static void calc_unmag_heat_flux_1d( + const gkyl_ten_moment_grad_closure *gces, const double *fluid_d[], double *cflrate, double dt, + double *q +) { const int ndim = gces->ndim; double rho_avg = 0.0; @@ -177,28 +172,26 @@ calc_unmag_heat_flux_1d(const gkyl_ten_moment_grad_closure *gces, dTdx[T23] = calc_sym_grad_1D(dx, Tij[L_1D][T23], Tij[U_1D][T23]); dTdx[T33] = calc_sym_grad_1D(dx, Tij[L_1D][T33], Tij[U_1D][T33]); - double alpha = 1.0/gces->k0; - double vth_avg = sqrt(p_avg/rho_avg); - + double alpha = 1.0 / gces->k0; + double vth_avg = sqrt(p_avg / rho_avg); + // Temperature is actually T/m due to the formulation of var_setup. // Thus, the mass density rho is used instead of number density n. - double chi = alpha*vth_avg*rho_avg; + double chi = alpha * vth_avg * rho_avg; - q[Q111] = chi*dTdx[T11]; - q[Q112] = chi*2.0*dTdx[T12]/3.0; - q[Q113] = chi*2.0*dTdx[T13]/3.0; - q[Q122] = chi*dTdx[T22]/3.0; - q[Q123] = chi*dTdx[T23]/3.0; - q[Q133] = chi*dTdx[T33]/3.0; + q[Q111] = chi * dTdx[T11]; + q[Q112] = chi * 2.0 * dTdx[T12] / 3.0; + q[Q113] = chi * 2.0 * dTdx[T13] / 3.0; + q[Q122] = chi * dTdx[T22] / 3.0; + q[Q123] = chi * dTdx[T23] / 3.0; + q[Q133] = chi * dTdx[T33] / 3.0; - double cfla = dt/(dx*dx); - cflrate[0] = alpha*vth_avg*cfla; + double cfla = dt / (dx * dx); + cflrate[0] = alpha * vth_avg * cfla; } -GKYL_CU_D -static void -grad_closure_update_1d(const gkyl_ten_moment_grad_closure *gces, - const double *q[], double *rhs) +GKYL_CU_D static void +grad_closure_update_1d(const gkyl_ten_moment_grad_closure *gces, const double *q[], double *rhs) { double div_qx[6] = {0.0}; @@ -223,10 +216,10 @@ grad_closure_update_1d(const gkyl_ten_moment_grad_closure *gces, rhs[P33] = div_qx[5]; } -GKYL_CU_D -static void -calc_unmag_heat_flux_2d(const gkyl_ten_moment_grad_closure *gces, - const double *fluid_d[], double *cflrate, double dt, double *q) +GKYL_CU_D static void calc_unmag_heat_flux_2d( + const gkyl_ten_moment_grad_closure *gces, const double *fluid_d[], double *cflrate, double dt, + double *q +) { const int ndim = gces->ndim; double rho_avg = 0.0; @@ -303,77 +296,63 @@ calc_unmag_heat_flux_2d(const gkyl_ten_moment_grad_closure *gces, dTdy[U_1D][T23] = calc_sym_grad_limiter_2D(limit, dTy[U_1D][T23], dTy[L_1D][T23]); dTdy[U_1D][T33] = calc_sym_grad_limiter_2D(limit, dTy[U_1D][T33], dTy[L_1D][T33]); - double alpha = 1.0/gces->k0; - double vth_avg = sqrt(p_avg/rho_avg); + double alpha = 1.0 / gces->k0; + double vth_avg = sqrt(p_avg / rho_avg); // Temperature is actually T/m due to the formulation of var_setup. // Thus, the mass density rho is used instead of number density n. - double chi = alpha*vth_avg*rho_avg; - - int compx[4] = { L_1D, U_1D, L_1D, U_1D }; - int compy[4] = { L_1D, L_1D, U_1D, U_1D }; - - q[LL_2D*10 + Q111] = chi*dTdx[compx[LL_2D]][T11]; - q[LL_2D*10 + Q112] = chi*(2.0*dTdx[compx[LL_2D]][T12] - + dTdy[compy[LL_2D]][T11])/3.0; - q[LL_2D*10 + Q113] = chi*2.0*dTdx[compx[LL_2D]][T13]/3.0; - q[LL_2D*10 + Q122] = chi*(dTdx[compx[LL_2D]][T22] - + 2.0*dTdy[compy[LL_2D]][T12])/3.0; - q[LL_2D*10 + Q123] = chi*(dTdx[compx[LL_2D]][T23] - + dTdy[compy[LL_2D]][T13])/3.0; - q[LL_2D*10 + Q133] = chi*dTdx[compx[LL_2D]][T33]/3.0; - q[LL_2D*10 + Q222] = chi*dTdy[compy[LL_2D]][T22]; - q[LL_2D*10 + Q223] = chi*2.0*dTdy[compy[LL_2D]][T23]/3.0; - q[LL_2D*10 + Q233] = chi*dTdy[compy[LL_2D]][T33]/3.0; - - q[LU_2D*10 + Q111] = chi*dTdx[compx[LU_2D]][T11]; - q[LU_2D*10 + Q112] = chi*(2.0*dTdx[compx[LU_2D]][T12] - + dTdy[compy[LU_2D]][T11])/3.0; - q[LU_2D*10 + Q113] = chi*2.0*dTdx[compx[LU_2D]][T13]/3.0; - q[LU_2D*10 + Q122] = chi*(dTdx[compx[LU_2D]][T22] - + 2.0*dTdy[compy[LU_2D]][T12])/3.0; - q[LU_2D*10 + Q123] = chi*(dTdx[compx[LU_2D]][T23] - + dTdy[compy[LU_2D]][T13])/3.0; - q[LU_2D*10 + Q133] = chi*dTdx[compx[LU_2D]][T33]/3.0; - q[LU_2D*10 + Q222] = chi*dTdy[compy[LU_2D]][T22]; - q[LU_2D*10 + Q223] = chi*2.0*dTdy[compy[LU_2D]][T23]/3.0; - q[LU_2D*10 + Q233] = chi*dTdy[compy[LU_2D]][T33]/3.0; - - q[UL_2D*10 + Q111] = chi*dTdx[compx[UL_2D]][T11]; - q[UL_2D*10 + Q112] = chi*(2.0*dTdx[compx[UL_2D]][T12] - + dTdy[compy[UL_2D]][T11])/3.0; - q[UL_2D*10 + Q113] = chi*2.0*dTdx[compx[UL_2D]][T13]/3.0; - q[UL_2D*10 + Q122] = chi*(dTdx[compx[UL_2D]][T22] - + 2.0*dTdy[compy[UL_2D]][T12])/3.0; - q[UL_2D*10 + Q123] = chi*(dTdx[compx[UL_2D]][T23] - + dTdy[compy[UL_2D]][T13])/3.0; - q[UL_2D*10 + Q133] = chi*dTdx[compx[UL_2D]][T33]/3.0; - q[UL_2D*10 + Q222] = chi*dTdy[compy[UL_2D]][T22]; - q[UL_2D*10 + Q223] = chi*2.0*dTdy[compy[UL_2D]][T23]/3.0; - q[UL_2D*10 + Q233] = chi*dTdy[compy[UL_2D]][T33]/3.0; - - q[UU_2D*10 + Q111] = chi*dTdx[compx[UU_2D]][T11]; - q[UU_2D*10 + Q112] = chi*(2.0*dTdx[compx[UU_2D]][T12] - + dTdy[compy[UU_2D]][T11])/3.0; - q[UU_2D*10 + Q113] = chi*2.0*dTdx[compx[UU_2D]][T13]/3.0; - q[UU_2D*10 + Q122] = chi*(dTdx[compx[UU_2D]][T22] - + 2.0*dTdy[compy[UU_2D]][T12])/3.0; - q[UU_2D*10 + Q123] = chi*(dTdx[compx[UU_2D]][T23] - + dTdy[compy[UU_2D]][T13])/3.0; - q[UU_2D*10 + Q133] = chi*dTdx[compx[UU_2D]][T33]/3.0; - q[UU_2D*10 + Q222] = chi*dTdy[compy[UU_2D]][T22]; - q[UU_2D*10 + Q223] = chi*2.0*dTdy[compy[UU_2D]][T23]/3.0; - q[UU_2D*10 + Q233] = chi*dTdy[compy[UU_2D]][T33]/3.0; + double chi = alpha * vth_avg * rho_avg; + + int compx[4] = {L_1D, U_1D, L_1D, U_1D}; + int compy[4] = {L_1D, L_1D, U_1D, U_1D}; + + q[LL_2D * 10 + Q111] = chi * dTdx[compx[LL_2D]][T11]; + q[LL_2D * 10 + Q112] = chi * (2.0 * dTdx[compx[LL_2D]][T12] + dTdy[compy[LL_2D]][T11]) / 3.0; + q[LL_2D * 10 + Q113] = chi * 2.0 * dTdx[compx[LL_2D]][T13] / 3.0; + q[LL_2D * 10 + Q122] = chi * (dTdx[compx[LL_2D]][T22] + 2.0 * dTdy[compy[LL_2D]][T12]) / 3.0; + q[LL_2D * 10 + Q123] = chi * (dTdx[compx[LL_2D]][T23] + dTdy[compy[LL_2D]][T13]) / 3.0; + q[LL_2D * 10 + Q133] = chi * dTdx[compx[LL_2D]][T33] / 3.0; + q[LL_2D * 10 + Q222] = chi * dTdy[compy[LL_2D]][T22]; + q[LL_2D * 10 + Q223] = chi * 2.0 * dTdy[compy[LL_2D]][T23] / 3.0; + q[LL_2D * 10 + Q233] = chi * dTdy[compy[LL_2D]][T33] / 3.0; + + q[LU_2D * 10 + Q111] = chi * dTdx[compx[LU_2D]][T11]; + q[LU_2D * 10 + Q112] = chi * (2.0 * dTdx[compx[LU_2D]][T12] + dTdy[compy[LU_2D]][T11]) / 3.0; + q[LU_2D * 10 + Q113] = chi * 2.0 * dTdx[compx[LU_2D]][T13] / 3.0; + q[LU_2D * 10 + Q122] = chi * (dTdx[compx[LU_2D]][T22] + 2.0 * dTdy[compy[LU_2D]][T12]) / 3.0; + q[LU_2D * 10 + Q123] = chi * (dTdx[compx[LU_2D]][T23] + dTdy[compy[LU_2D]][T13]) / 3.0; + q[LU_2D * 10 + Q133] = chi * dTdx[compx[LU_2D]][T33] / 3.0; + q[LU_2D * 10 + Q222] = chi * dTdy[compy[LU_2D]][T22]; + q[LU_2D * 10 + Q223] = chi * 2.0 * dTdy[compy[LU_2D]][T23] / 3.0; + q[LU_2D * 10 + Q233] = chi * dTdy[compy[LU_2D]][T33] / 3.0; + + q[UL_2D * 10 + Q111] = chi * dTdx[compx[UL_2D]][T11]; + q[UL_2D * 10 + Q112] = chi * (2.0 * dTdx[compx[UL_2D]][T12] + dTdy[compy[UL_2D]][T11]) / 3.0; + q[UL_2D * 10 + Q113] = chi * 2.0 * dTdx[compx[UL_2D]][T13] / 3.0; + q[UL_2D * 10 + Q122] = chi * (dTdx[compx[UL_2D]][T22] + 2.0 * dTdy[compy[UL_2D]][T12]) / 3.0; + q[UL_2D * 10 + Q123] = chi * (dTdx[compx[UL_2D]][T23] + dTdy[compy[UL_2D]][T13]) / 3.0; + q[UL_2D * 10 + Q133] = chi * dTdx[compx[UL_2D]][T33] / 3.0; + q[UL_2D * 10 + Q222] = chi * dTdy[compy[UL_2D]][T22]; + q[UL_2D * 10 + Q223] = chi * 2.0 * dTdy[compy[UL_2D]][T23] / 3.0; + q[UL_2D * 10 + Q233] = chi * dTdy[compy[UL_2D]][T33] / 3.0; + + q[UU_2D * 10 + Q111] = chi * dTdx[compx[UU_2D]][T11]; + q[UU_2D * 10 + Q112] = chi * (2.0 * dTdx[compx[UU_2D]][T12] + dTdy[compy[UU_2D]][T11]) / 3.0; + q[UU_2D * 10 + Q113] = chi * 2.0 * dTdx[compx[UU_2D]][T13] / 3.0; + q[UU_2D * 10 + Q122] = chi * (dTdx[compx[UU_2D]][T22] + 2.0 * dTdy[compy[UU_2D]][T12]) / 3.0; + q[UU_2D * 10 + Q123] = chi * (dTdx[compx[UU_2D]][T23] + dTdy[compy[UU_2D]][T13]) / 3.0; + q[UU_2D * 10 + Q133] = chi * dTdx[compx[UU_2D]][T33] / 3.0; + q[UU_2D * 10 + Q222] = chi * dTdy[compy[UU_2D]][T22]; + q[UU_2D * 10 + Q223] = chi * 2.0 * dTdy[compy[UU_2D]][T23] / 3.0; + q[UU_2D * 10 + Q233] = chi * dTdy[compy[UU_2D]][T33] / 3.0; double da = fmin(dx, dy); - double cfla = dt/(da*da); - cflrate[0] = alpha*vth_avg*cfla; + double cfla = dt / (da * da); + cflrate[0] = alpha * vth_avg * cfla; } -GKYL_CU_D -static void -grad_closure_update_2d(const gkyl_ten_moment_grad_closure *gces, - const double *q[], double *rhs) +GKYL_CU_D static void +grad_closure_update_2d(const gkyl_ten_moment_grad_closure *gces, const double *q[], double *rhs) { double div_qx[6] = {0.0}; double div_qy[6] = {0.0}; @@ -381,31 +360,55 @@ grad_closure_update_2d(const gkyl_ten_moment_grad_closure *gces, const double dx = gces->grid.dx[0]; const double dy = gces->grid.dx[1]; - div_qx[0] = calc_sym_gradx_2D(dx, q[LL_2D][UU_2D*10 + Q111], - q[LU_2D][UL_2D*10 + Q111], q[UL_2D][LU_2D*10 + Q111], q[UU_2D][LL_2D*10 + Q111]); - div_qx[1] = calc_sym_gradx_2D(dx, q[LL_2D][UU_2D*10 + Q112], - q[LU_2D][UL_2D*10 + Q112], q[UL_2D][LU_2D*10 + Q112], q[UU_2D][LL_2D*10 + Q112]); - div_qx[2] = calc_sym_gradx_2D(dx, q[LL_2D][UU_2D*10 + Q113], - q[LU_2D][UL_2D*10 + Q113], q[UL_2D][LU_2D*10 + Q113], q[UU_2D][LL_2D*10 + Q113]); - div_qx[3] = calc_sym_gradx_2D(dx, q[LL_2D][UU_2D*10 + Q122], - q[LU_2D][UL_2D*10 + Q122], q[UL_2D][LU_2D*10 + Q122], q[UU_2D][LL_2D*10 + Q122]); - div_qx[4] = calc_sym_gradx_2D(dx, q[LL_2D][UU_2D*10 + Q123], - q[LU_2D][UL_2D*10 + Q123], q[UL_2D][LU_2D*10 + Q123], q[UU_2D][LL_2D*10 + Q123]); - div_qx[5] = calc_sym_gradx_2D(dx, q[LL_2D][UU_2D*10 + Q133], - q[LU_2D][UL_2D*10 + Q133], q[UL_2D][LU_2D*10 + Q133], q[UU_2D][LL_2D*10 + Q133]); - - div_qy[0] = calc_sym_grady_2D(dy, q[LL_2D][UU_2D*10 + Q112], - q[LU_2D][UL_2D*10 + Q112], q[UL_2D][LU_2D*10 + Q112], q[UU_2D][LL_2D*10 + Q112]); - div_qy[1] = calc_sym_grady_2D(dy, q[LL_2D][UU_2D*10 + Q122], - q[LU_2D][UL_2D*10 + Q122], q[UL_2D][LU_2D*10 + Q122], q[UU_2D][LL_2D*10 + Q122]); - div_qy[2] = calc_sym_grady_2D(dy, q[LL_2D][UU_2D*10 + Q123], - q[LU_2D][UL_2D*10 + Q123], q[UL_2D][LU_2D*10 + Q123], q[UU_2D][LL_2D*10 + Q123]); - div_qy[3] = calc_sym_grady_2D(dy, q[LL_2D][UU_2D*10 + Q222], - q[LU_2D][UL_2D*10 + Q222], q[UL_2D][LU_2D*10 + Q222], q[UU_2D][LL_2D*10 + Q222]); - div_qy[4] = calc_sym_grady_2D(dy, q[LL_2D][UU_2D*10 + Q223], - q[LU_2D][UL_2D*10 + Q223], q[UL_2D][LU_2D*10 + Q223], q[UU_2D][LL_2D*10 + Q223]); - div_qy[5] = calc_sym_grady_2D(dy, q[LL_2D][UU_2D*10 + Q233], - q[LU_2D][UL_2D*10 + Q233], q[UL_2D][LU_2D*10 + Q233], q[UU_2D][LL_2D*10 + Q233]); + div_qx[0] = calc_sym_gradx_2D( + dx, q[LL_2D][UU_2D * 10 + Q111], q[LU_2D][UL_2D * 10 + Q111], q[UL_2D][LU_2D * 10 + Q111], + q[UU_2D][LL_2D * 10 + Q111] + ); + div_qx[1] = calc_sym_gradx_2D( + dx, q[LL_2D][UU_2D * 10 + Q112], q[LU_2D][UL_2D * 10 + Q112], q[UL_2D][LU_2D * 10 + Q112], + q[UU_2D][LL_2D * 10 + Q112] + ); + div_qx[2] = calc_sym_gradx_2D( + dx, q[LL_2D][UU_2D * 10 + Q113], q[LU_2D][UL_2D * 10 + Q113], q[UL_2D][LU_2D * 10 + Q113], + q[UU_2D][LL_2D * 10 + Q113] + ); + div_qx[3] = calc_sym_gradx_2D( + dx, q[LL_2D][UU_2D * 10 + Q122], q[LU_2D][UL_2D * 10 + Q122], q[UL_2D][LU_2D * 10 + Q122], + q[UU_2D][LL_2D * 10 + Q122] + ); + div_qx[4] = calc_sym_gradx_2D( + dx, q[LL_2D][UU_2D * 10 + Q123], q[LU_2D][UL_2D * 10 + Q123], q[UL_2D][LU_2D * 10 + Q123], + q[UU_2D][LL_2D * 10 + Q123] + ); + div_qx[5] = calc_sym_gradx_2D( + dx, q[LL_2D][UU_2D * 10 + Q133], q[LU_2D][UL_2D * 10 + Q133], q[UL_2D][LU_2D * 10 + Q133], + q[UU_2D][LL_2D * 10 + Q133] + ); + + div_qy[0] = calc_sym_grady_2D( + dy, q[LL_2D][UU_2D * 10 + Q112], q[LU_2D][UL_2D * 10 + Q112], q[UL_2D][LU_2D * 10 + Q112], + q[UU_2D][LL_2D * 10 + Q112] + ); + div_qy[1] = calc_sym_grady_2D( + dy, q[LL_2D][UU_2D * 10 + Q122], q[LU_2D][UL_2D * 10 + Q122], q[UL_2D][LU_2D * 10 + Q122], + q[UU_2D][LL_2D * 10 + Q122] + ); + div_qy[2] = calc_sym_grady_2D( + dy, q[LL_2D][UU_2D * 10 + Q123], q[LU_2D][UL_2D * 10 + Q123], q[UL_2D][LU_2D * 10 + Q123], + q[UU_2D][LL_2D * 10 + Q123] + ); + div_qy[3] = calc_sym_grady_2D( + dy, q[LL_2D][UU_2D * 10 + Q222], q[LU_2D][UL_2D * 10 + Q222], q[UL_2D][LU_2D * 10 + Q222], + q[UU_2D][LL_2D * 10 + Q222] + ); + div_qy[4] = calc_sym_grady_2D( + dy, q[LL_2D][UU_2D * 10 + Q223], q[LU_2D][UL_2D * 10 + Q223], q[UL_2D][LU_2D * 10 + Q223], + q[UU_2D][LL_2D * 10 + Q223] + ); + div_qy[5] = calc_sym_grady_2D( + dy, q[LL_2D][UU_2D * 10 + Q233], q[LU_2D][UL_2D * 10 + Q233], q[UL_2D][LU_2D * 10 + Q233], + q[UU_2D][LL_2D * 10 + Q233] + ); rhs[RHO] = 0.0; rhs[MX] = 0.0; @@ -419,10 +422,10 @@ grad_closure_update_2d(const gkyl_ten_moment_grad_closure *gces, rhs[P33] = div_qx[5] + div_qy[5]; } -GKYL_CU_D -static void -calc_unmag_heat_flux_3d(const gkyl_ten_moment_grad_closure *gces, - const double *fluid_d[], double *cflrate, double dt, double *q) +GKYL_CU_D static void calc_unmag_heat_flux_3d( + const gkyl_ten_moment_grad_closure *gces, const double *fluid_d[], double *cflrate, double dt, + double *q +) { const int ndim = gces->ndim; double rho_avg = 0.0; @@ -444,10 +447,13 @@ calc_unmag_heat_flux_3d(const gkyl_ten_moment_grad_closure *gces, double p[8] = {0.0}; var_setup(gces, LLL_3D, UUU_3D, fluid_d, rho, p, Tij); - rho_avg = calc_harmonic_avg_3D(rho[LLL_3D], rho[LLU_3D], rho[LUL_3D], rho[LUU_3D], - rho[ULL_3D], rho[ULU_3D], rho[UUL_3D], rho[UUU_3D]); - p_avg = calc_harmonic_avg_3D(p[LLL_3D], p[LLU_3D], p[LUL_3D], p[LUU_3D], - p[ULL_3D], p[ULU_3D], p[UUL_3D], p[UUU_3D]); + rho_avg = calc_harmonic_avg_3D( + rho[LLL_3D], rho[LLU_3D], rho[LUL_3D], rho[LUU_3D], rho[ULL_3D], rho[ULU_3D], rho[UUL_3D], + rho[UUU_3D] + ); + p_avg = calc_harmonic_avg_3D( + p[LLL_3D], p[LLU_3D], p[LUL_3D], p[LUU_3D], p[ULL_3D], p[ULU_3D], p[UUL_3D], p[UUU_3D] + ); dTx[LL_2D][T11] = calc_sym_grad_1D(dx, Tij[LLL_3D][T11], Tij[ULL_3D][T11]); dTx[LL_2D][T12] = calc_sym_grad_1D(dx, Tij[LLL_3D][T12], Tij[ULL_3D][T12]); @@ -462,72 +468,96 @@ calc_unmag_heat_flux_3d(const gkyl_ten_moment_grad_closure *gces, dTx[LU_2D][T22] = calc_sym_grad_1D(dx, Tij[LUL_3D][T22], Tij[UUL_3D][T22]); dTx[LU_2D][T23] = calc_sym_grad_1D(dx, Tij[LUL_3D][T23], Tij[UUL_3D][T23]); dTx[LU_2D][T33] = calc_sym_grad_1D(dx, Tij[LUL_3D][T33], Tij[UUL_3D][T33]); - + dTx[UL_2D][T11] = calc_sym_grad_1D(dx, Tij[LLU_3D][T11], Tij[ULU_3D][T11]); dTx[UL_2D][T12] = calc_sym_grad_1D(dx, Tij[LLU_3D][T12], Tij[ULU_3D][T12]); dTx[UL_2D][T13] = calc_sym_grad_1D(dx, Tij[LLU_3D][T13], Tij[ULU_3D][T13]); dTx[UL_2D][T22] = calc_sym_grad_1D(dx, Tij[LLU_3D][T22], Tij[ULU_3D][T22]); dTx[UL_2D][T23] = calc_sym_grad_1D(dx, Tij[LLU_3D][T23], Tij[ULU_3D][T23]); dTx[UL_2D][T33] = calc_sym_grad_1D(dx, Tij[LLU_3D][T33], Tij[ULU_3D][T33]); - + dTx[UU_2D][T11] = calc_sym_grad_1D(dx, Tij[LUU_3D][T11], Tij[UUU_3D][T11]); dTx[UU_2D][T12] = calc_sym_grad_1D(dx, Tij[LUU_3D][T12], Tij[UUU_3D][T12]); dTx[UU_2D][T13] = calc_sym_grad_1D(dx, Tij[LUU_3D][T13], Tij[UUU_3D][T13]); dTx[UU_2D][T22] = calc_sym_grad_1D(dx, Tij[LUU_3D][T22], Tij[UUU_3D][T22]); - dTx[UU_2D][T23] = calc_sym_grad_1D(dx, Tij[LUU_3D][T23], Tij[UUU_3D][T23]); + dTx[UU_2D][T23] = calc_sym_grad_1D(dx, Tij[LUU_3D][T23], Tij[UUU_3D][T23]); dTx[UU_2D][T33] = calc_sym_grad_1D(dx, Tij[LUU_3D][T33], Tij[UUU_3D][T33]); - dTdx[LL_2D][T11] = calc_sym_grad_limiter_3D(limit, dTx[LL_2D][T11], dTx[LU_2D][T11], - dTx[UL_2D][T11], dTx[UU_2D][T11]); - dTdx[LL_2D][T12] = calc_sym_grad_limiter_3D(limit, dTx[LL_2D][T12], dTx[LU_2D][T12], - dTx[UL_2D][T12], dTx[UU_2D][T12]); - dTdx[LL_2D][T13] = calc_sym_grad_limiter_3D(limit, dTx[LL_2D][T13], dTx[LU_2D][T13], - dTx[UL_2D][T13], dTx[UU_2D][T13]); - dTdx[LL_2D][T22] = calc_sym_grad_limiter_3D(limit, dTx[LL_2D][T22], dTx[LU_2D][T22], - dTx[UL_2D][T22], dTx[UU_2D][T22]); - dTdx[LL_2D][T23] = calc_sym_grad_limiter_3D(limit, dTx[LL_2D][T23], dTx[LU_2D][T23], - dTx[UL_2D][T23], dTx[UU_2D][T23]); - dTdx[LL_2D][T33] = calc_sym_grad_limiter_3D(limit, dTx[LL_2D][T33], dTx[LU_2D][T33], - dTx[UL_2D][T33], dTx[UU_2D][T33]); - - dTdx[LU_2D][T11] = calc_sym_grad_limiter_3D(limit, dTx[LU_2D][T11], dTx[LL_2D][T11], - dTx[UL_2D][T11], dTx[UU_2D][T11]); - dTdx[LU_2D][T12] = calc_sym_grad_limiter_3D(limit, dTx[LU_2D][T12], dTx[LL_2D][T12], - dTx[UL_2D][T12], dTx[UU_2D][T12]); - dTdx[LU_2D][T13] = calc_sym_grad_limiter_3D(limit, dTx[LU_2D][T13], dTx[LL_2D][T13], - dTx[UL_2D][T13], dTx[UU_2D][T13]); - dTdx[LU_2D][T22] = calc_sym_grad_limiter_3D(limit, dTx[LU_2D][T22], dTx[LL_2D][T22], - dTx[UL_2D][T22], dTx[UU_2D][T22]); - dTdx[LU_2D][T23] = calc_sym_grad_limiter_3D(limit, dTx[LU_2D][T23], dTx[LL_2D][T23], - dTx[UL_2D][T23], dTx[UU_2D][T23]); - dTdx[LU_2D][T33] = calc_sym_grad_limiter_3D(limit, dTx[LU_2D][T33], dTx[LL_2D][T33], - dTx[UL_2D][T33], dTx[UU_2D][T33]); - - dTdx[UL_2D][T11] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T11], dTx[LL_2D][T11], - dTx[LU_2D][T11], dTx[UU_2D][T11]); - dTdx[UL_2D][T12] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T12], dTx[LL_2D][T12], - dTx[LU_2D][T12], dTx[UU_2D][T12]); - dTdx[UL_2D][T13] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T13], dTx[LL_2D][T13], - dTx[LU_2D][T13], dTx[UU_2D][T13]); - dTdx[UL_2D][T22] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T22], dTx[LL_2D][T22], - dTx[LU_2D][T22], dTx[UU_2D][T22]); - dTdx[UL_2D][T23] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T23], dTx[LL_2D][T23], - dTx[LU_2D][T23], dTx[UU_2D][T23]); - dTdx[UL_2D][T33] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T33], dTx[LL_2D][T33], - dTx[LU_2D][T33], dTx[UU_2D][T33]); - - dTdx[UU_2D][T11] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T11], dTx[LL_2D][T11], - dTx[LU_2D][T11], dTx[UU_2D][T11]); - dTdx[UU_2D][T12] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T12], dTx[LL_2D][T12], - dTx[LU_2D][T12], dTx[UU_2D][T12]); - dTdx[UU_2D][T13] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T13], dTx[LL_2D][T13], - dTx[LU_2D][T13], dTx[UU_2D][T13]); - dTdx[UU_2D][T22] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T22], dTx[LL_2D][T22], - dTx[LU_2D][T22], dTx[UU_2D][T22]); - dTdx[UU_2D][T23] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T23], dTx[LL_2D][T23], - dTx[LU_2D][T23], dTx[UU_2D][T23]); - dTdx[UU_2D][T33] = calc_sym_grad_limiter_3D(limit, dTx[UL_2D][T33], dTx[LL_2D][T33], - dTx[LU_2D][T33], dTx[UU_2D][T33]); + dTdx[LL_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTx[LL_2D][T11], dTx[LU_2D][T11], dTx[UL_2D][T11], dTx[UU_2D][T11] + ); + dTdx[LL_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTx[LL_2D][T12], dTx[LU_2D][T12], dTx[UL_2D][T12], dTx[UU_2D][T12] + ); + dTdx[LL_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTx[LL_2D][T13], dTx[LU_2D][T13], dTx[UL_2D][T13], dTx[UU_2D][T13] + ); + dTdx[LL_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTx[LL_2D][T22], dTx[LU_2D][T22], dTx[UL_2D][T22], dTx[UU_2D][T22] + ); + dTdx[LL_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTx[LL_2D][T23], dTx[LU_2D][T23], dTx[UL_2D][T23], dTx[UU_2D][T23] + ); + dTdx[LL_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTx[LL_2D][T33], dTx[LU_2D][T33], dTx[UL_2D][T33], dTx[UU_2D][T33] + ); + + dTdx[LU_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTx[LU_2D][T11], dTx[LL_2D][T11], dTx[UL_2D][T11], dTx[UU_2D][T11] + ); + dTdx[LU_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTx[LU_2D][T12], dTx[LL_2D][T12], dTx[UL_2D][T12], dTx[UU_2D][T12] + ); + dTdx[LU_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTx[LU_2D][T13], dTx[LL_2D][T13], dTx[UL_2D][T13], dTx[UU_2D][T13] + ); + dTdx[LU_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTx[LU_2D][T22], dTx[LL_2D][T22], dTx[UL_2D][T22], dTx[UU_2D][T22] + ); + dTdx[LU_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTx[LU_2D][T23], dTx[LL_2D][T23], dTx[UL_2D][T23], dTx[UU_2D][T23] + ); + dTdx[LU_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTx[LU_2D][T33], dTx[LL_2D][T33], dTx[UL_2D][T33], dTx[UU_2D][T33] + ); + + dTdx[UL_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T11], dTx[LL_2D][T11], dTx[LU_2D][T11], dTx[UU_2D][T11] + ); + dTdx[UL_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T12], dTx[LL_2D][T12], dTx[LU_2D][T12], dTx[UU_2D][T12] + ); + dTdx[UL_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T13], dTx[LL_2D][T13], dTx[LU_2D][T13], dTx[UU_2D][T13] + ); + dTdx[UL_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T22], dTx[LL_2D][T22], dTx[LU_2D][T22], dTx[UU_2D][T22] + ); + dTdx[UL_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T23], dTx[LL_2D][T23], dTx[LU_2D][T23], dTx[UU_2D][T23] + ); + dTdx[UL_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T33], dTx[LL_2D][T33], dTx[LU_2D][T33], dTx[UU_2D][T33] + ); + + dTdx[UU_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T11], dTx[LL_2D][T11], dTx[LU_2D][T11], dTx[UU_2D][T11] + ); + dTdx[UU_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T12], dTx[LL_2D][T12], dTx[LU_2D][T12], dTx[UU_2D][T12] + ); + dTdx[UU_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T13], dTx[LL_2D][T13], dTx[LU_2D][T13], dTx[UU_2D][T13] + ); + dTdx[UU_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T22], dTx[LL_2D][T22], dTx[LU_2D][T22], dTx[UU_2D][T22] + ); + dTdx[UU_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T23], dTx[LL_2D][T23], dTx[LU_2D][T23], dTx[UU_2D][T23] + ); + dTdx[UU_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTx[UL_2D][T33], dTx[LL_2D][T33], dTx[LU_2D][T33], dTx[UU_2D][T33] + ); dTy[LL_2D][T11] = calc_sym_grad_1D(dy, Tij[LLL_3D][T11], Tij[LUL_3D][T11]); dTy[LL_2D][T12] = calc_sym_grad_1D(dy, Tij[LLL_3D][T12], Tij[LUL_3D][T12]); @@ -557,57 +587,81 @@ calc_unmag_heat_flux_3d(const gkyl_ten_moment_grad_closure *gces, dTy[UU_2D][T23] = calc_sym_grad_1D(dy, Tij[ULU_3D][T23], Tij[UUU_3D][T23]); dTy[UU_2D][T33] = calc_sym_grad_1D(dy, Tij[ULU_3D][T33], Tij[UUU_3D][T33]); - dTdy[LL_2D][T11] = calc_sym_grad_limiter_3D(limit, dTy[LL_2D][T11], dTy[LU_2D][T11], - dTy[UL_2D][T11], dTy[UU_2D][T11]); - dTdy[LL_2D][T12] = calc_sym_grad_limiter_3D(limit, dTy[LL_2D][T12], dTy[LU_2D][T12], - dTy[UL_2D][T12], dTy[UU_2D][T12]); - dTdy[LL_2D][T13] = calc_sym_grad_limiter_3D(limit, dTy[LL_2D][T13], dTy[LU_2D][T13], - dTy[UL_2D][T13], dTy[UU_2D][T13]); - dTdy[LL_2D][T22] = calc_sym_grad_limiter_3D(limit, dTy[LL_2D][T22], dTy[LU_2D][T22], - dTy[UL_2D][T22], dTy[UU_2D][T22]); - dTdy[LL_2D][T23] = calc_sym_grad_limiter_3D(limit, dTy[LL_2D][T23], dTy[LU_2D][T23], - dTy[UL_2D][T23], dTy[UU_2D][T23]); - dTdy[LL_2D][T33] = calc_sym_grad_limiter_3D(limit, dTy[LL_2D][T33], dTy[LU_2D][T33], - dTy[UL_2D][T33], dTy[UU_2D][T33]); - - dTdy[LU_2D][T11] = calc_sym_grad_limiter_3D(limit, dTy[LU_2D][T11], dTy[LL_2D][T11], - dTy[UL_2D][T11], dTy[UU_2D][T11]); - dTdy[LU_2D][T12] = calc_sym_grad_limiter_3D(limit, dTy[LU_2D][T12], dTy[LL_2D][T12], - dTy[UL_2D][T12], dTy[UU_2D][T12]); - dTdy[LU_2D][T13] = calc_sym_grad_limiter_3D(limit, dTy[LU_2D][T13], dTy[LL_2D][T13], - dTy[UL_2D][T13], dTy[UU_2D][T13]); - dTdy[LU_2D][T22] = calc_sym_grad_limiter_3D(limit, dTy[LU_2D][T22], dTy[LL_2D][T22], - dTy[UL_2D][T22], dTy[UU_2D][T22]); - dTdy[LU_2D][T23] = calc_sym_grad_limiter_3D(limit, dTy[LU_2D][T23], dTy[LL_2D][T23], - dTy[UL_2D][T23], dTy[UU_2D][T23]); - dTdy[LU_2D][T33] = calc_sym_grad_limiter_3D(limit, dTy[LU_2D][T33], dTy[LL_2D][T33], - dTy[UL_2D][T33], dTy[UU_2D][T33]); - - dTdy[UL_2D][T11] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T11], dTy[LL_2D][T11], - dTy[LU_2D][T11], dTy[UU_2D][T11]); - dTdy[UL_2D][T12] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T12], dTy[LL_2D][T12], - dTy[LU_2D][T12], dTy[UU_2D][T12]); - dTdy[UL_2D][T13] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T13], dTy[LL_2D][T13], - dTy[LU_2D][T13], dTy[UU_2D][T13]); - dTdy[UL_2D][T22] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T22], dTy[LL_2D][T22], - dTy[LU_2D][T22], dTy[UU_2D][T22]); - dTdy[UL_2D][T23] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T23], dTy[LL_2D][T23], - dTy[LU_2D][T23], dTy[UU_2D][T23]); - dTdy[UL_2D][T33] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T33], dTy[LL_2D][T33], - dTy[LU_2D][T33], dTy[UU_2D][T33]); - - dTdy[UU_2D][T11] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T11], dTy[LL_2D][T11], - dTy[LU_2D][T11], dTy[UU_2D][T11]); - dTdy[UU_2D][T12] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T12], dTy[LL_2D][T12], - dTy[LU_2D][T12], dTy[UU_2D][T12]); - dTdy[UU_2D][T13] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T13], dTy[LL_2D][T13], - dTy[LU_2D][T13], dTy[UU_2D][T13]); - dTdy[UU_2D][T22] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T22], dTy[LL_2D][T22], - dTy[LU_2D][T22], dTy[UU_2D][T22]); - dTdy[UU_2D][T23] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T23], dTy[LL_2D][T23], - dTy[LU_2D][T23], dTy[UU_2D][T23]); - dTdy[UU_2D][T33] = calc_sym_grad_limiter_3D(limit, dTy[UL_2D][T33], dTy[LL_2D][T33], - dTy[LU_2D][T33], dTy[UU_2D][T33]); + dTdy[LL_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTy[LL_2D][T11], dTy[LU_2D][T11], dTy[UL_2D][T11], dTy[UU_2D][T11] + ); + dTdy[LL_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTy[LL_2D][T12], dTy[LU_2D][T12], dTy[UL_2D][T12], dTy[UU_2D][T12] + ); + dTdy[LL_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTy[LL_2D][T13], dTy[LU_2D][T13], dTy[UL_2D][T13], dTy[UU_2D][T13] + ); + dTdy[LL_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTy[LL_2D][T22], dTy[LU_2D][T22], dTy[UL_2D][T22], dTy[UU_2D][T22] + ); + dTdy[LL_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTy[LL_2D][T23], dTy[LU_2D][T23], dTy[UL_2D][T23], dTy[UU_2D][T23] + ); + dTdy[LL_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTy[LL_2D][T33], dTy[LU_2D][T33], dTy[UL_2D][T33], dTy[UU_2D][T33] + ); + + dTdy[LU_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTy[LU_2D][T11], dTy[LL_2D][T11], dTy[UL_2D][T11], dTy[UU_2D][T11] + ); + dTdy[LU_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTy[LU_2D][T12], dTy[LL_2D][T12], dTy[UL_2D][T12], dTy[UU_2D][T12] + ); + dTdy[LU_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTy[LU_2D][T13], dTy[LL_2D][T13], dTy[UL_2D][T13], dTy[UU_2D][T13] + ); + dTdy[LU_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTy[LU_2D][T22], dTy[LL_2D][T22], dTy[UL_2D][T22], dTy[UU_2D][T22] + ); + dTdy[LU_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTy[LU_2D][T23], dTy[LL_2D][T23], dTy[UL_2D][T23], dTy[UU_2D][T23] + ); + dTdy[LU_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTy[LU_2D][T33], dTy[LL_2D][T33], dTy[UL_2D][T33], dTy[UU_2D][T33] + ); + + dTdy[UL_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T11], dTy[LL_2D][T11], dTy[LU_2D][T11], dTy[UU_2D][T11] + ); + dTdy[UL_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T12], dTy[LL_2D][T12], dTy[LU_2D][T12], dTy[UU_2D][T12] + ); + dTdy[UL_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T13], dTy[LL_2D][T13], dTy[LU_2D][T13], dTy[UU_2D][T13] + ); + dTdy[UL_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T22], dTy[LL_2D][T22], dTy[LU_2D][T22], dTy[UU_2D][T22] + ); + dTdy[UL_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T23], dTy[LL_2D][T23], dTy[LU_2D][T23], dTy[UU_2D][T23] + ); + dTdy[UL_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T33], dTy[LL_2D][T33], dTy[LU_2D][T33], dTy[UU_2D][T33] + ); + + dTdy[UU_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T11], dTy[LL_2D][T11], dTy[LU_2D][T11], dTy[UU_2D][T11] + ); + dTdy[UU_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T12], dTy[LL_2D][T12], dTy[LU_2D][T12], dTy[UU_2D][T12] + ); + dTdy[UU_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T13], dTy[LL_2D][T13], dTy[LU_2D][T13], dTy[UU_2D][T13] + ); + dTdy[UU_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T22], dTy[LL_2D][T22], dTy[LU_2D][T22], dTy[UU_2D][T22] + ); + dTdy[UU_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T23], dTy[LL_2D][T23], dTy[LU_2D][T23], dTy[UU_2D][T23] + ); + dTdy[UU_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTy[UL_2D][T33], dTy[LL_2D][T33], dTy[LU_2D][T33], dTy[UU_2D][T33] + ); dTz[LL_2D][T11] = calc_sym_grad_1D(dz, Tij[LLL_3D][T11], Tij[LLU_3D][T11]); dTz[LL_2D][T12] = calc_sym_grad_1D(dz, Tij[LLL_3D][T12], Tij[LLU_3D][T12]); @@ -637,222 +691,196 @@ calc_unmag_heat_flux_3d(const gkyl_ten_moment_grad_closure *gces, dTz[UU_2D][T23] = calc_sym_grad_1D(dz, Tij[UUL_3D][T23], Tij[UUU_3D][T23]); dTz[UU_2D][T33] = calc_sym_grad_1D(dz, Tij[UUL_3D][T33], Tij[UUU_3D][T33]); - dTdz[LL_2D][T11] = calc_sym_grad_limiter_3D(limit, dTz[LL_2D][T11], dTz[LU_2D][T11], - dTz[UL_2D][T11], dTz[UU_2D][T11]); - dTdz[LL_2D][T12] = calc_sym_grad_limiter_3D(limit, dTz[LL_2D][T12], dTz[LU_2D][T12], - dTz[UL_2D][T12], dTz[UU_2D][T12]); - dTdz[LL_2D][T13] = calc_sym_grad_limiter_3D(limit, dTz[LL_2D][T13], dTz[LU_2D][T13], - dTz[UL_2D][T13], dTz[UU_2D][T13]); - dTdz[LL_2D][T22] = calc_sym_grad_limiter_3D(limit, dTz[LL_2D][T22], dTz[LU_2D][T22], - dTz[UL_2D][T22], dTz[UU_2D][T22]); - dTdz[LL_2D][T23] = calc_sym_grad_limiter_3D(limit, dTz[LL_2D][T23], dTz[LU_2D][T23], - dTz[UL_2D][T23], dTz[UU_2D][T23]); - dTdz[LL_2D][T33] = calc_sym_grad_limiter_3D(limit, dTz[LL_2D][T33], dTz[LU_2D][T33], - dTz[UL_2D][T33], dTz[UU_2D][T33]); - - dTdz[LU_2D][T11] = calc_sym_grad_limiter_3D(limit, dTz[LU_2D][T11], dTz[LL_2D][T11], - dTz[UL_2D][T11], dTz[UU_2D][T11]); - dTdz[LU_2D][T12] = calc_sym_grad_limiter_3D(limit, dTz[LU_2D][T12], dTz[LL_2D][T12], - dTz[UL_2D][T12], dTz[UU_2D][T12]); - dTdz[LU_2D][T13] = calc_sym_grad_limiter_3D(limit, dTz[LU_2D][T13], dTz[LL_2D][T13], - dTz[UL_2D][T13], dTz[UU_2D][T13]); - dTdz[LU_2D][T22] = calc_sym_grad_limiter_3D(limit, dTz[LU_2D][T22], dTz[LL_2D][T22], - dTz[UL_2D][T22], dTz[UU_2D][T22]); - dTdz[LU_2D][T23] = calc_sym_grad_limiter_3D(limit, dTz[LU_2D][T23], dTz[LL_2D][T23], - dTz[UL_2D][T23], dTz[UU_2D][T23]); - dTdz[LU_2D][T33] = calc_sym_grad_limiter_3D(limit, dTz[LU_2D][T33], dTz[LL_2D][T33], - dTz[UL_2D][T33], dTz[UU_2D][T33]); - - dTdz[UL_2D][T11] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T11], dTz[LL_2D][T11], - dTz[LU_2D][T11], dTz[UU_2D][T11]); - dTdz[UL_2D][T12] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T12], dTz[LL_2D][T12], - dTz[LU_2D][T12], dTz[UU_2D][T12]); - dTdz[UL_2D][T13] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T13], dTz[LL_2D][T13], - dTz[LU_2D][T13], dTz[UU_2D][T13]); - dTdz[UL_2D][T22] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T22], dTz[LL_2D][T22], - dTz[LU_2D][T22], dTz[UU_2D][T22]); - dTdz[UL_2D][T23] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T23], dTz[LL_2D][T23], - dTz[LU_2D][T23], dTz[UU_2D][T23]); - dTdz[UL_2D][T33] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T33], dTz[LL_2D][T33], - dTz[LU_2D][T33], dTz[UU_2D][T33]); - - dTdz[UU_2D][T11] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T11], dTz[LL_2D][T11], - dTz[LU_2D][T11], dTz[UU_2D][T11]); - dTdz[UU_2D][T12] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T12], dTz[LL_2D][T12], - dTz[LU_2D][T12], dTz[UU_2D][T12]); - dTdz[UU_2D][T13] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T13], dTz[LL_2D][T13], - dTz[LU_2D][T13], dTz[UU_2D][T13]); - dTdz[UU_2D][T22] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T22], dTz[LL_2D][T22], - dTz[LU_2D][T22], dTz[UU_2D][T22]); - dTdz[UU_2D][T23] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T23], dTz[LL_2D][T23], - dTz[LU_2D][T23], dTz[UU_2D][T23]); - dTdz[UU_2D][T33] = calc_sym_grad_limiter_3D(limit, dTz[UL_2D][T33], dTz[LL_2D][T33], - dTz[LU_2D][T33], dTz[UU_2D][T33]); - - double alpha = 1.0/gces->k0; - double vth_avg = sqrt(p_avg/rho_avg); + dTdz[LL_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTz[LL_2D][T11], dTz[LU_2D][T11], dTz[UL_2D][T11], dTz[UU_2D][T11] + ); + dTdz[LL_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTz[LL_2D][T12], dTz[LU_2D][T12], dTz[UL_2D][T12], dTz[UU_2D][T12] + ); + dTdz[LL_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTz[LL_2D][T13], dTz[LU_2D][T13], dTz[UL_2D][T13], dTz[UU_2D][T13] + ); + dTdz[LL_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTz[LL_2D][T22], dTz[LU_2D][T22], dTz[UL_2D][T22], dTz[UU_2D][T22] + ); + dTdz[LL_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTz[LL_2D][T23], dTz[LU_2D][T23], dTz[UL_2D][T23], dTz[UU_2D][T23] + ); + dTdz[LL_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTz[LL_2D][T33], dTz[LU_2D][T33], dTz[UL_2D][T33], dTz[UU_2D][T33] + ); + + dTdz[LU_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTz[LU_2D][T11], dTz[LL_2D][T11], dTz[UL_2D][T11], dTz[UU_2D][T11] + ); + dTdz[LU_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTz[LU_2D][T12], dTz[LL_2D][T12], dTz[UL_2D][T12], dTz[UU_2D][T12] + ); + dTdz[LU_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTz[LU_2D][T13], dTz[LL_2D][T13], dTz[UL_2D][T13], dTz[UU_2D][T13] + ); + dTdz[LU_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTz[LU_2D][T22], dTz[LL_2D][T22], dTz[UL_2D][T22], dTz[UU_2D][T22] + ); + dTdz[LU_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTz[LU_2D][T23], dTz[LL_2D][T23], dTz[UL_2D][T23], dTz[UU_2D][T23] + ); + dTdz[LU_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTz[LU_2D][T33], dTz[LL_2D][T33], dTz[UL_2D][T33], dTz[UU_2D][T33] + ); + + dTdz[UL_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T11], dTz[LL_2D][T11], dTz[LU_2D][T11], dTz[UU_2D][T11] + ); + dTdz[UL_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T12], dTz[LL_2D][T12], dTz[LU_2D][T12], dTz[UU_2D][T12] + ); + dTdz[UL_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T13], dTz[LL_2D][T13], dTz[LU_2D][T13], dTz[UU_2D][T13] + ); + dTdz[UL_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T22], dTz[LL_2D][T22], dTz[LU_2D][T22], dTz[UU_2D][T22] + ); + dTdz[UL_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T23], dTz[LL_2D][T23], dTz[LU_2D][T23], dTz[UU_2D][T23] + ); + dTdz[UL_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T33], dTz[LL_2D][T33], dTz[LU_2D][T33], dTz[UU_2D][T33] + ); + + dTdz[UU_2D][T11] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T11], dTz[LL_2D][T11], dTz[LU_2D][T11], dTz[UU_2D][T11] + ); + dTdz[UU_2D][T12] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T12], dTz[LL_2D][T12], dTz[LU_2D][T12], dTz[UU_2D][T12] + ); + dTdz[UU_2D][T13] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T13], dTz[LL_2D][T13], dTz[LU_2D][T13], dTz[UU_2D][T13] + ); + dTdz[UU_2D][T22] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T22], dTz[LL_2D][T22], dTz[LU_2D][T22], dTz[UU_2D][T22] + ); + dTdz[UU_2D][T23] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T23], dTz[LL_2D][T23], dTz[LU_2D][T23], dTz[UU_2D][T23] + ); + dTdz[UU_2D][T33] = calc_sym_grad_limiter_3D( + limit, dTz[UL_2D][T33], dTz[LL_2D][T33], dTz[LU_2D][T33], dTz[UU_2D][T33] + ); + + double alpha = 1.0 / gces->k0; + double vth_avg = sqrt(p_avg / rho_avg); // Temperature is actually T/m due to the formulation of var_setup. // Thus, the mass density rho is used instead of number density n. - double chi = alpha*vth_avg*rho_avg; - - int compx[8] = { LL_2D, UL_2D, LU_2D, UU_2D, LL_2D, UL_2D, LU_2D, UU_2D }; - int compy[8] = { LL_2D, UL_2D, LL_2D, UL_2D, LU_2D, UU_2D, LU_2D, UU_2D }; - int compz[8] = { LL_2D, LL_2D, UL_2D, UL_2D, LU_2D, LU_2D, UU_2D, UU_2D }; - - q[LLL_3D*10 + Q111] = chi*dTdx[compx[LLL_3D]][T11]; - q[LLL_3D*10 + Q112] = chi*(2.0*dTdx[compx[LLL_3D]][T12] - + dTdy[compy[LLL_3D]][T11])/3.0; - q[LLL_3D*10 + Q113] = chi*(2.0*dTdx[compx[LLL_3D]][T13] - + dTdz[compz[LLL_3D]][T11])/3.0; - q[LLL_3D*10 + Q122] = chi*(dTdx[compx[LLL_3D]][T22] - + 2.0*dTdy[compy[LLL_3D]][T12])/3.0; - q[LLL_3D*10 + Q123] = chi*(dTdx[compx[LLL_3D]][T23] - + dTdy[compy[LLL_3D]][T13] + dTdz[compz[LLL_3D]][T12])/3.0; - q[LLL_3D*10 + Q133] = chi*(dTdx[compx[LLL_3D]][T33] - + 2.0*dTdz[compz[LLL_3D]][T13])/3.0; - q[LLL_3D*10 + Q222] = chi*dTdy[compy[LLL_3D]][T22]; - q[LLL_3D*10 + Q223] = chi*(2.0*dTdy[compy[LLL_3D]][T23] - + dTdz[compz[LLL_3D]][T22])/3.0; - q[LLL_3D*10 + Q233] = chi*(dTdy[compy[LLL_3D]][T33] - + 2.0*dTdz[compz[LLL_3D]][T23])/3.0; - q[LLL_3D*10 + Q333] = chi*dTdz[compz[LLL_3D]][T33]; - - q[LLU_3D*10 + Q111] = chi*dTdx[compx[LLU_3D]][T11]; - q[LLU_3D*10 + Q112] = chi*(2.0*dTdx[compx[LLU_3D]][T12] - + dTdy[compy[LLU_3D]][T11])/3.0; - q[LLU_3D*10 + Q113] = chi*(2.0*dTdx[compx[LLU_3D]][T13] - + dTdz[compz[LLU_3D]][T11])/3.0; - q[LLU_3D*10 + Q122] = chi*(dTdx[compx[LLU_3D]][T22] - + 2.0*dTdy[compy[LLU_3D]][T12])/3.0; - q[LLU_3D*10 + Q123] = chi*(dTdx[compx[LLU_3D]][T23] - + dTdy[compy[LLU_3D]][T13] + dTdz[compz[LLU_3D]][T12])/3.0; - q[LLU_3D*10 + Q133] = chi*(dTdx[compx[LLU_3D]][T33] - + 2.0*dTdz[compz[LLU_3D]][T13])/3.0; - q[LLU_3D*10 + Q222] = chi*dTdy[compy[LLU_3D]][T22]; - q[LLU_3D*10 + Q223] = chi*(2.0*dTdy[compy[LLU_3D]][T23] - + dTdz[compz[LLU_3D]][T22])/3.0; - q[LLU_3D*10 + Q233] = chi*(dTdy[compy[LLU_3D]][T33] - + 2.0*dTdz[compz[LLU_3D]][T23])/3.0; - q[LLU_3D*10 + Q333] = chi*dTdz[compz[LLU_3D]][T33]; - - q[LUL_3D*10 + Q111] = chi*dTdx[compx[LUL_3D]][T11]; - q[LUL_3D*10 + Q112] = chi*(2.0*dTdx[compx[LUL_3D]][T12] - + dTdy[compy[LUL_3D]][T11])/3.0; - q[LUL_3D*10 + Q113] = chi*(2.0*dTdx[compx[LUL_3D]][T13] - + dTdz[compz[LUL_3D]][T11])/3.0; - q[LUL_3D*10 + Q122] = chi*(dTdx[compx[LUL_3D]][T22] - + 2.0*dTdy[compy[LUL_3D]][T12])/3.0; - q[LUL_3D*10 + Q123] = chi*(dTdx[compx[LUL_3D]][T23] - + dTdy[compy[LUL_3D]][T13] + dTdz[compz[LUL_3D]][T12])/3.0; - q[LUL_3D*10 + Q133] = chi*(dTdx[compx[LUL_3D]][T33] - + 2.0*dTdz[compz[LUL_3D]][T13])/3.0; - q[LUL_3D*10 + Q222] = chi*dTdy[compy[LUL_3D]][T22]; - q[LUL_3D*10 + Q223] = chi*(2.0*dTdy[compy[LUL_3D]][T23] - + dTdz[compz[LUL_3D]][T22])/3.0; - q[LUL_3D*10 + Q233] = chi*(dTdy[compy[LUL_3D]][T33] - + 2.0*dTdz[compz[LUL_3D]][T23])/3.0; - q[LUL_3D*10 + Q333] = chi*dTdz[compz[LUL_3D]][T33]; - - q[LUU_3D*10 + Q111] = chi*dTdx[compx[LUU_3D]][T11]; - q[LUU_3D*10 + Q112] = chi*(2.0*dTdx[compx[LUU_3D]][T12] - + dTdy[compy[LUU_3D]][T11])/3.0; - q[LUU_3D*10 + Q113] = chi*(2.0*dTdx[compx[LUU_3D]][T13] - + dTdz[compz[LUU_3D]][T11])/3.0; - q[LUU_3D*10 + Q122] = chi*(dTdx[compx[LUU_3D]][T22] - + 2.0*dTdy[compy[LUU_3D]][T12])/3.0; - q[LUU_3D*10 + Q123] = chi*(dTdx[compx[LUU_3D]][T23] - + dTdy[compy[LUU_3D]][T13] + dTdz[compz[LUU_3D]][T12])/3.0; - q[LUU_3D*10 + Q133] = chi*(dTdx[compx[LUU_3D]][T33] - + 2.0*dTdz[compz[LUU_3D]][T13])/3.0; - q[LUU_3D*10 + Q222] = chi*dTdy[compy[LUU_3D]][T22]; - q[LUU_3D*10 + Q223] = chi*(2.0*dTdy[compy[LUU_3D]][T23] - + dTdz[compz[LUU_3D]][T22])/3.0; - q[LUU_3D*10 + Q233] = chi*(dTdy[compy[LUU_3D]][T33] - + 2.0*dTdz[compz[LUU_3D]][T23])/3.0; - q[LUU_3D*10 + Q333] = chi*dTdz[compz[LUU_3D]][T33]; - - q[ULL_3D*10 + Q111] = chi*dTdx[compx[ULL_3D]][T11]; - q[ULL_3D*10 + Q112] = chi*(2.0*dTdx[compx[ULL_3D]][T12] - + dTdy[compy[ULL_3D]][T11])/3.0; - q[ULL_3D*10 + Q113] = chi*(2.0*dTdx[compx[ULL_3D]][T13] - + dTdz[compz[ULL_3D]][T11])/3.0; - q[ULL_3D*10 + Q122] = chi*(dTdx[compx[ULL_3D]][T22] - + 2.0*dTdy[compy[ULL_3D]][T12])/3.0; - q[ULL_3D*10 + Q123] = chi*(dTdx[compx[ULL_3D]][T23] - + dTdy[compy[ULL_3D]][T13] + dTdz[compz[ULL_3D]][T12])/3.0; - q[ULL_3D*10 + Q133] = chi*(dTdx[compx[ULL_3D]][T33] - + 2.0*dTdz[compz[ULL_3D]][T13])/3.0; - q[ULL_3D*10 + Q222] = chi*dTdy[compy[ULL_3D]][T22]; - q[ULL_3D*10 + Q223] = chi*(2.0*dTdy[compy[ULL_3D]][T23] - + dTdz[compz[ULL_3D]][T22])/3.0; - q[ULL_3D*10 + Q233] = chi*(dTdy[compy[ULL_3D]][T33] - + 2.0*dTdz[compz[ULL_3D]][T23])/3.0; - q[ULL_3D*10 + Q333] = chi*dTdz[compz[ULL_3D]][T33]; - - q[ULU_3D*10 + Q111] = chi*dTdx[compx[ULU_3D]][T11]; - q[ULU_3D*10 + Q112] = chi*(2.0*dTdx[compx[ULU_3D]][T12] - + dTdy[compy[ULU_3D]][T11])/3.0; - q[ULU_3D*10 + Q113] = chi*(2.0*dTdx[compx[ULU_3D]][T13] - + dTdz[compz[ULU_3D]][T11])/3.0; - q[ULU_3D*10 + Q122] = chi*(dTdx[compx[ULU_3D]][T22] - + 2.0*dTdy[compy[ULU_3D]][T12])/3.0; - q[ULU_3D*10 + Q123] = chi*(dTdx[compx[ULU_3D]][T23] - + dTdy[compy[ULU_3D]][T13] + dTdz[compz[ULU_3D]][T12])/3.0; - q[ULU_3D*10 + Q133] = chi*(dTdx[compx[ULU_3D]][T33] - + 2.0*dTdz[compz[ULU_3D]][T13])/3.0; - q[ULU_3D*10 + Q222] = chi*dTdy[compy[ULU_3D]][T22]; - q[ULU_3D*10 + Q223] = chi*(2.0*dTdy[compy[ULU_3D]][T23] - + dTdz[compz[ULU_3D]][T22])/3.0; - q[ULU_3D*10 + Q233] = chi*(dTdy[compy[ULU_3D]][T33] - + 2.0*dTdz[compz[ULU_3D]][T23])/3.0; - q[ULU_3D*10 + Q333] = chi*dTdz[compz[ULU_3D]][T33]; - - q[UUL_3D*10 + Q111] = chi*dTdx[compx[UUL_3D]][T11]; - q[UUL_3D*10 + Q112] = chi*(2.0*dTdx[compx[UUL_3D]][T12] - + dTdy[compy[UUL_3D]][T11])/3.0; - q[UUL_3D*10 + Q113] = chi*(2.0*dTdx[compx[UUL_3D]][T13] - + dTdz[compz[UUL_3D]][T11])/3.0; - q[UUL_3D*10 + Q122] = chi*(dTdx[compx[UUL_3D]][T22] - + 2.0*dTdy[compy[UUL_3D]][T12])/3.0; - q[UUL_3D*10 + Q123] = chi*(dTdx[compx[UUL_3D]][T23] - + dTdy[compy[UUL_3D]][T13] + dTdz[compz[UUL_3D]][T12])/3.0; - q[UUL_3D*10 + Q133] = chi*(dTdx[compx[UUL_3D]][T33] - + 2.0*dTdz[compz[UUL_3D]][T13])/3.0; - q[UUL_3D*10 + Q222] = chi*dTdy[compy[UUL_3D]][T22]; - q[UUL_3D*10 + Q223] = chi*(2.0*dTdy[compy[UUL_3D]][T23] - + dTdz[compz[UUL_3D]][T22])/3.0; - q[UUL_3D*10 + Q233] = chi*(dTdy[compy[UUL_3D]][T33] - + 2.0*dTdz[compz[UUL_3D]][T23])/3.0; - q[UUL_3D*10 + Q333] = chi*dTdz[compz[UUL_3D]][T33]; - - q[UUU_3D*10 + Q111] = chi*dTdx[compx[UUU_3D]][T11]; - q[UUU_3D*10 + Q112] = chi*(2.0*dTdx[compx[UUU_3D]][T12] - + dTdy[compy[UUU_3D]][T11])/3.0; - q[UUU_3D*10 + Q113] = chi*(2.0*dTdx[compx[UUU_3D]][T13] - + dTdz[compz[UUU_3D]][T11])/3.0; - q[UUU_3D*10 + Q122] = chi*(dTdx[compx[UUU_3D]][T22] - + 2.0*dTdy[compy[UUU_3D]][T12])/3.0; - q[UUU_3D*10 + Q123] = chi*(dTdx[compx[UUU_3D]][T23] - + dTdy[compy[UUU_3D]][T13] + dTdz[compz[UUU_3D]][T12])/3.0; - q[UUU_3D*10 + Q133] = chi*(dTdx[compx[UUU_3D]][T33] - + 2.0*dTdz[compz[UUU_3D]][T13])/3.0; - q[UUU_3D*10 + Q222] = chi*dTdy[compy[UUU_3D]][T22]; - q[UUU_3D*10 + Q223] = chi*(2.0*dTdy[compy[UUU_3D]][T23] - + dTdz[compz[UUU_3D]][T22])/3.0; - q[UUU_3D*10 + Q233] = chi*(dTdy[compy[UUU_3D]][T33] - + 2.0*dTdz[compz[UUU_3D]][T23])/3.0; - q[UUU_3D*10 + Q333] = chi*dTdz[compz[UUU_3D]][T33]; + double chi = alpha * vth_avg * rho_avg; + + int compx[8] = {LL_2D, UL_2D, LU_2D, UU_2D, LL_2D, UL_2D, LU_2D, UU_2D}; + int compy[8] = {LL_2D, UL_2D, LL_2D, UL_2D, LU_2D, UU_2D, LU_2D, UU_2D}; + int compz[8] = {LL_2D, LL_2D, UL_2D, UL_2D, LU_2D, LU_2D, UU_2D, UU_2D}; + + q[LLL_3D * 10 + Q111] = chi * dTdx[compx[LLL_3D]][T11]; + q[LLL_3D * 10 + Q112] = chi * (2.0 * dTdx[compx[LLL_3D]][T12] + dTdy[compy[LLL_3D]][T11]) / 3.0; + q[LLL_3D * 10 + Q113] = chi * (2.0 * dTdx[compx[LLL_3D]][T13] + dTdz[compz[LLL_3D]][T11]) / 3.0; + q[LLL_3D * 10 + Q122] = chi * (dTdx[compx[LLL_3D]][T22] + 2.0 * dTdy[compy[LLL_3D]][T12]) / 3.0; + q[LLL_3D * 10 + Q123] = + chi * (dTdx[compx[LLL_3D]][T23] + dTdy[compy[LLL_3D]][T13] + dTdz[compz[LLL_3D]][T12]) / 3.0; + q[LLL_3D * 10 + Q133] = chi * (dTdx[compx[LLL_3D]][T33] + 2.0 * dTdz[compz[LLL_3D]][T13]) / 3.0; + q[LLL_3D * 10 + Q222] = chi * dTdy[compy[LLL_3D]][T22]; + q[LLL_3D * 10 + Q223] = chi * (2.0 * dTdy[compy[LLL_3D]][T23] + dTdz[compz[LLL_3D]][T22]) / 3.0; + q[LLL_3D * 10 + Q233] = chi * (dTdy[compy[LLL_3D]][T33] + 2.0 * dTdz[compz[LLL_3D]][T23]) / 3.0; + q[LLL_3D * 10 + Q333] = chi * dTdz[compz[LLL_3D]][T33]; + + q[LLU_3D * 10 + Q111] = chi * dTdx[compx[LLU_3D]][T11]; + q[LLU_3D * 10 + Q112] = chi * (2.0 * dTdx[compx[LLU_3D]][T12] + dTdy[compy[LLU_3D]][T11]) / 3.0; + q[LLU_3D * 10 + Q113] = chi * (2.0 * dTdx[compx[LLU_3D]][T13] + dTdz[compz[LLU_3D]][T11]) / 3.0; + q[LLU_3D * 10 + Q122] = chi * (dTdx[compx[LLU_3D]][T22] + 2.0 * dTdy[compy[LLU_3D]][T12]) / 3.0; + q[LLU_3D * 10 + Q123] = + chi * (dTdx[compx[LLU_3D]][T23] + dTdy[compy[LLU_3D]][T13] + dTdz[compz[LLU_3D]][T12]) / 3.0; + q[LLU_3D * 10 + Q133] = chi * (dTdx[compx[LLU_3D]][T33] + 2.0 * dTdz[compz[LLU_3D]][T13]) / 3.0; + q[LLU_3D * 10 + Q222] = chi * dTdy[compy[LLU_3D]][T22]; + q[LLU_3D * 10 + Q223] = chi * (2.0 * dTdy[compy[LLU_3D]][T23] + dTdz[compz[LLU_3D]][T22]) / 3.0; + q[LLU_3D * 10 + Q233] = chi * (dTdy[compy[LLU_3D]][T33] + 2.0 * dTdz[compz[LLU_3D]][T23]) / 3.0; + q[LLU_3D * 10 + Q333] = chi * dTdz[compz[LLU_3D]][T33]; + + q[LUL_3D * 10 + Q111] = chi * dTdx[compx[LUL_3D]][T11]; + q[LUL_3D * 10 + Q112] = chi * (2.0 * dTdx[compx[LUL_3D]][T12] + dTdy[compy[LUL_3D]][T11]) / 3.0; + q[LUL_3D * 10 + Q113] = chi * (2.0 * dTdx[compx[LUL_3D]][T13] + dTdz[compz[LUL_3D]][T11]) / 3.0; + q[LUL_3D * 10 + Q122] = chi * (dTdx[compx[LUL_3D]][T22] + 2.0 * dTdy[compy[LUL_3D]][T12]) / 3.0; + q[LUL_3D * 10 + Q123] = + chi * (dTdx[compx[LUL_3D]][T23] + dTdy[compy[LUL_3D]][T13] + dTdz[compz[LUL_3D]][T12]) / 3.0; + q[LUL_3D * 10 + Q133] = chi * (dTdx[compx[LUL_3D]][T33] + 2.0 * dTdz[compz[LUL_3D]][T13]) / 3.0; + q[LUL_3D * 10 + Q222] = chi * dTdy[compy[LUL_3D]][T22]; + q[LUL_3D * 10 + Q223] = chi * (2.0 * dTdy[compy[LUL_3D]][T23] + dTdz[compz[LUL_3D]][T22]) / 3.0; + q[LUL_3D * 10 + Q233] = chi * (dTdy[compy[LUL_3D]][T33] + 2.0 * dTdz[compz[LUL_3D]][T23]) / 3.0; + q[LUL_3D * 10 + Q333] = chi * dTdz[compz[LUL_3D]][T33]; + + q[LUU_3D * 10 + Q111] = chi * dTdx[compx[LUU_3D]][T11]; + q[LUU_3D * 10 + Q112] = chi * (2.0 * dTdx[compx[LUU_3D]][T12] + dTdy[compy[LUU_3D]][T11]) / 3.0; + q[LUU_3D * 10 + Q113] = chi * (2.0 * dTdx[compx[LUU_3D]][T13] + dTdz[compz[LUU_3D]][T11]) / 3.0; + q[LUU_3D * 10 + Q122] = chi * (dTdx[compx[LUU_3D]][T22] + 2.0 * dTdy[compy[LUU_3D]][T12]) / 3.0; + q[LUU_3D * 10 + Q123] = + chi * (dTdx[compx[LUU_3D]][T23] + dTdy[compy[LUU_3D]][T13] + dTdz[compz[LUU_3D]][T12]) / 3.0; + q[LUU_3D * 10 + Q133] = chi * (dTdx[compx[LUU_3D]][T33] + 2.0 * dTdz[compz[LUU_3D]][T13]) / 3.0; + q[LUU_3D * 10 + Q222] = chi * dTdy[compy[LUU_3D]][T22]; + q[LUU_3D * 10 + Q223] = chi * (2.0 * dTdy[compy[LUU_3D]][T23] + dTdz[compz[LUU_3D]][T22]) / 3.0; + q[LUU_3D * 10 + Q233] = chi * (dTdy[compy[LUU_3D]][T33] + 2.0 * dTdz[compz[LUU_3D]][T23]) / 3.0; + q[LUU_3D * 10 + Q333] = chi * dTdz[compz[LUU_3D]][T33]; + + q[ULL_3D * 10 + Q111] = chi * dTdx[compx[ULL_3D]][T11]; + q[ULL_3D * 10 + Q112] = chi * (2.0 * dTdx[compx[ULL_3D]][T12] + dTdy[compy[ULL_3D]][T11]) / 3.0; + q[ULL_3D * 10 + Q113] = chi * (2.0 * dTdx[compx[ULL_3D]][T13] + dTdz[compz[ULL_3D]][T11]) / 3.0; + q[ULL_3D * 10 + Q122] = chi * (dTdx[compx[ULL_3D]][T22] + 2.0 * dTdy[compy[ULL_3D]][T12]) / 3.0; + q[ULL_3D * 10 + Q123] = + chi * (dTdx[compx[ULL_3D]][T23] + dTdy[compy[ULL_3D]][T13] + dTdz[compz[ULL_3D]][T12]) / 3.0; + q[ULL_3D * 10 + Q133] = chi * (dTdx[compx[ULL_3D]][T33] + 2.0 * dTdz[compz[ULL_3D]][T13]) / 3.0; + q[ULL_3D * 10 + Q222] = chi * dTdy[compy[ULL_3D]][T22]; + q[ULL_3D * 10 + Q223] = chi * (2.0 * dTdy[compy[ULL_3D]][T23] + dTdz[compz[ULL_3D]][T22]) / 3.0; + q[ULL_3D * 10 + Q233] = chi * (dTdy[compy[ULL_3D]][T33] + 2.0 * dTdz[compz[ULL_3D]][T23]) / 3.0; + q[ULL_3D * 10 + Q333] = chi * dTdz[compz[ULL_3D]][T33]; + + q[ULU_3D * 10 + Q111] = chi * dTdx[compx[ULU_3D]][T11]; + q[ULU_3D * 10 + Q112] = chi * (2.0 * dTdx[compx[ULU_3D]][T12] + dTdy[compy[ULU_3D]][T11]) / 3.0; + q[ULU_3D * 10 + Q113] = chi * (2.0 * dTdx[compx[ULU_3D]][T13] + dTdz[compz[ULU_3D]][T11]) / 3.0; + q[ULU_3D * 10 + Q122] = chi * (dTdx[compx[ULU_3D]][T22] + 2.0 * dTdy[compy[ULU_3D]][T12]) / 3.0; + q[ULU_3D * 10 + Q123] = + chi * (dTdx[compx[ULU_3D]][T23] + dTdy[compy[ULU_3D]][T13] + dTdz[compz[ULU_3D]][T12]) / 3.0; + q[ULU_3D * 10 + Q133] = chi * (dTdx[compx[ULU_3D]][T33] + 2.0 * dTdz[compz[ULU_3D]][T13]) / 3.0; + q[ULU_3D * 10 + Q222] = chi * dTdy[compy[ULU_3D]][T22]; + q[ULU_3D * 10 + Q223] = chi * (2.0 * dTdy[compy[ULU_3D]][T23] + dTdz[compz[ULU_3D]][T22]) / 3.0; + q[ULU_3D * 10 + Q233] = chi * (dTdy[compy[ULU_3D]][T33] + 2.0 * dTdz[compz[ULU_3D]][T23]) / 3.0; + q[ULU_3D * 10 + Q333] = chi * dTdz[compz[ULU_3D]][T33]; + + q[UUL_3D * 10 + Q111] = chi * dTdx[compx[UUL_3D]][T11]; + q[UUL_3D * 10 + Q112] = chi * (2.0 * dTdx[compx[UUL_3D]][T12] + dTdy[compy[UUL_3D]][T11]) / 3.0; + q[UUL_3D * 10 + Q113] = chi * (2.0 * dTdx[compx[UUL_3D]][T13] + dTdz[compz[UUL_3D]][T11]) / 3.0; + q[UUL_3D * 10 + Q122] = chi * (dTdx[compx[UUL_3D]][T22] + 2.0 * dTdy[compy[UUL_3D]][T12]) / 3.0; + q[UUL_3D * 10 + Q123] = + chi * (dTdx[compx[UUL_3D]][T23] + dTdy[compy[UUL_3D]][T13] + dTdz[compz[UUL_3D]][T12]) / 3.0; + q[UUL_3D * 10 + Q133] = chi * (dTdx[compx[UUL_3D]][T33] + 2.0 * dTdz[compz[UUL_3D]][T13]) / 3.0; + q[UUL_3D * 10 + Q222] = chi * dTdy[compy[UUL_3D]][T22]; + q[UUL_3D * 10 + Q223] = chi * (2.0 * dTdy[compy[UUL_3D]][T23] + dTdz[compz[UUL_3D]][T22]) / 3.0; + q[UUL_3D * 10 + Q233] = chi * (dTdy[compy[UUL_3D]][T33] + 2.0 * dTdz[compz[UUL_3D]][T23]) / 3.0; + q[UUL_3D * 10 + Q333] = chi * dTdz[compz[UUL_3D]][T33]; + + q[UUU_3D * 10 + Q111] = chi * dTdx[compx[UUU_3D]][T11]; + q[UUU_3D * 10 + Q112] = chi * (2.0 * dTdx[compx[UUU_3D]][T12] + dTdy[compy[UUU_3D]][T11]) / 3.0; + q[UUU_3D * 10 + Q113] = chi * (2.0 * dTdx[compx[UUU_3D]][T13] + dTdz[compz[UUU_3D]][T11]) / 3.0; + q[UUU_3D * 10 + Q122] = chi * (dTdx[compx[UUU_3D]][T22] + 2.0 * dTdy[compy[UUU_3D]][T12]) / 3.0; + q[UUU_3D * 10 + Q123] = + chi * (dTdx[compx[UUU_3D]][T23] + dTdy[compy[UUU_3D]][T13] + dTdz[compz[UUU_3D]][T12]) / 3.0; + q[UUU_3D * 10 + Q133] = chi * (dTdx[compx[UUU_3D]][T33] + 2.0 * dTdz[compz[UUU_3D]][T13]) / 3.0; + q[UUU_3D * 10 + Q222] = chi * dTdy[compy[UUU_3D]][T22]; + q[UUU_3D * 10 + Q223] = chi * (2.0 * dTdy[compy[UUU_3D]][T23] + dTdz[compz[UUU_3D]][T22]) / 3.0; + q[UUU_3D * 10 + Q233] = chi * (dTdy[compy[UUU_3D]][T33] + 2.0 * dTdz[compz[UUU_3D]][T23]) / 3.0; + q[UUU_3D * 10 + Q333] = chi * dTdz[compz[UUU_3D]][T33]; double da = fmin(fmin(dx, dy), dz); - double cfla = dt/(da*da); - cflrate[0] = alpha*vth_avg*cfla; + double cfla = dt / (da * da); + cflrate[0] = alpha * vth_avg * cfla; } -GKYL_CU_D -static void -grad_closure_update_3d(const gkyl_ten_moment_grad_closure *gces, - const double *q[], double *rhs) +GKYL_CU_D static void +grad_closure_update_3d(const gkyl_ten_moment_grad_closure *gces, const double *q[], double *rhs) { double div_qx[6] = {0.0}; double div_qy[6] = {0.0}; @@ -862,98 +890,98 @@ grad_closure_update_3d(const gkyl_ten_moment_grad_closure *gces, const double dy = gces->grid.dx[1]; const double dz = gces->grid.dx[2]; - div_qx[0] = calc_sym_gradx_3D(dx, q[LLL_3D][UUU_3D*10 + Q111], - q[LLU_3D][UUL_3D*10 + Q111], q[LUL_3D][ULU_3D*10 + Q111], - q[LUU_3D][ULL_3D*10 + Q111], q[ULL_3D][LUU_3D*10 + Q111], - q[ULU_3D][LUL_3D*10 + Q111], q[UUL_3D][LLU_3D*10 + Q111], - q[UUU_3D][LLL_3D*10 + Q111]); - div_qx[1] = calc_sym_gradx_3D(dx, q[LLL_3D][UUU_3D*10 + Q112], - q[LLU_3D][UUL_3D*10 + Q112], q[LUL_3D][ULU_3D*10 + Q112], - q[LUU_3D][ULL_3D*10 + Q112], q[ULL_3D][LUU_3D*10 + Q112], - q[ULU_3D][LUL_3D*10 + Q112], q[UUL_3D][LLU_3D*10 + Q112], - q[UUU_3D][LLL_3D*10 + Q112]); - div_qx[2] = calc_sym_gradx_3D(dx, q[LLL_3D][UUU_3D*10 + Q113], - q[LLU_3D][UUL_3D*10 + Q113], q[LUL_3D][ULU_3D*10 + Q113], - q[LUU_3D][ULL_3D*10 + Q113], q[ULL_3D][LUU_3D*10 + Q113], - q[ULU_3D][LUL_3D*10 + Q113], q[UUL_3D][LLU_3D*10 + Q113], - q[UUU_3D][LLL_3D*10 + Q113]); - div_qx[3] = calc_sym_gradx_3D(dx, q[LLL_3D][UUU_3D*10 + Q122], - q[LLU_3D][UUL_3D*10 + Q122], q[LUL_3D][ULU_3D*10 + Q122], - q[LUU_3D][ULL_3D*10 + Q122], q[ULL_3D][LUU_3D*10 + Q122], - q[ULU_3D][LUL_3D*10 + Q122], q[UUL_3D][LLU_3D*10 + Q122], - q[UUU_3D][LLL_3D*10 + Q122]); - div_qx[4] = calc_sym_gradx_3D(dx, q[LLL_3D][UUU_3D*10 + Q123], - q[LLU_3D][UUL_3D*10 + Q123], q[LUL_3D][ULU_3D*10 + Q123], - q[LUU_3D][ULL_3D*10 + Q123], q[ULL_3D][LUU_3D*10 + Q123], - q[ULU_3D][LUL_3D*10 + Q123], q[UUL_3D][LLU_3D*10 + Q123], - q[UUU_3D][LLL_3D*10 + Q123]); - div_qx[5] = calc_sym_gradx_3D(dx, q[LLL_3D][UUU_3D*10 + Q133], - q[LLU_3D][UUL_3D*10 + Q133], q[LUL_3D][ULU_3D*10 + Q133], - q[LUU_3D][ULL_3D*10 + Q133], q[ULL_3D][LUU_3D*10 + Q133], - q[ULU_3D][LUL_3D*10 + Q133], q[UUL_3D][LLU_3D*10 + Q133], - q[UUU_3D][LLL_3D*10 + Q133]); - - div_qy[0] = calc_sym_grady_3D(dy, q[LLL_3D][UUU_3D*10 + Q112], - q[LLU_3D][UUL_3D*10 + Q112], q[LUL_3D][ULU_3D*10 + Q112], - q[LUU_3D][ULL_3D*10 + Q112], q[ULL_3D][LUU_3D*10 + Q112], - q[ULU_3D][LUL_3D*10 + Q112], q[UUL_3D][LLU_3D*10 + Q112], - q[UUU_3D][LLL_3D*10 + Q112]); - div_qy[1] = calc_sym_grady_3D(dy, q[LLL_3D][UUU_3D*10 + Q122], - q[LLU_3D][UUL_3D*10 + Q122], q[LUL_3D][ULU_3D*10 + Q122], - q[LUU_3D][ULL_3D*10 + Q122], q[ULL_3D][LUU_3D*10 + Q122], - q[ULU_3D][LUL_3D*10 + Q122], q[UUL_3D][LLU_3D*10 + Q122], - q[UUU_3D][LLL_3D*10 + Q122]); - div_qy[2] = calc_sym_grady_3D(dy, q[LLL_3D][UUU_3D*10 + Q123], - q[LLU_3D][UUL_3D*10 + Q123], q[LUL_3D][ULU_3D*10 + Q123], - q[LUU_3D][ULL_3D*10 + Q123], q[ULL_3D][LUU_3D*10 + Q123], - q[ULU_3D][LUL_3D*10 + Q123], q[UUL_3D][LLU_3D*10 + Q123], - q[UUU_3D][LLL_3D*10 + Q123]); - div_qy[3] = calc_sym_grady_3D(dy, q[LLL_3D][UUU_3D*10 + Q222], - q[LLU_3D][UUL_3D*10 + Q222], q[LUL_3D][ULU_3D*10 + Q222], - q[LUU_3D][ULL_3D*10 + Q222], q[ULL_3D][LUU_3D*10 + Q222], - q[ULU_3D][LUL_3D*10 + Q222], q[UUL_3D][LLU_3D*10 + Q222], - q[UUU_3D][LLL_3D*10 + Q222]); - div_qy[4] = calc_sym_grady_3D(dy, q[LLL_3D][UUU_3D*10 + Q223], - q[LLU_3D][UUL_3D*10 + Q223], q[LUL_3D][ULU_3D*10 + Q223], - q[LUU_3D][ULL_3D*10 + Q223], q[ULL_3D][LUU_3D*10 + Q223], - q[ULU_3D][LUL_3D*10 + Q223], q[UUL_3D][LLU_3D*10 + Q223], - q[UUU_3D][LLL_3D*10 + Q223]); - div_qy[5] = calc_sym_grady_3D(dy, q[LLL_3D][UUU_3D*10 + Q233], - q[LLU_3D][UUL_3D*10 + Q233], q[LUL_3D][ULU_3D*10 + Q233], - q[LUU_3D][ULL_3D*10 + Q233], q[ULL_3D][LUU_3D*10 + Q233], - q[ULU_3D][LUL_3D*10 + Q233], q[UUL_3D][LLU_3D*10 + Q233], - q[UUU_3D][LLL_3D*10 + Q233]); - - div_qz[0] = calc_sym_gradz_3D(dz, q[LLL_3D][UUU_3D*10 + Q113], - q[LLU_3D][UUL_3D*10 + Q113], q[LUL_3D][ULU_3D*10 + Q113], - q[LUU_3D][ULL_3D*10 + Q113], q[ULL_3D][LUU_3D*10 + Q113], - q[ULU_3D][LUL_3D*10 + Q113], q[UUL_3D][LLU_3D*10 + Q113], - q[UUU_3D][LLL_3D*10 + Q113]); - div_qz[1] = calc_sym_gradz_3D(dz, q[LLL_3D][UUU_3D*10 + Q123], - q[LLU_3D][UUL_3D*10 + Q123], q[LUL_3D][ULU_3D*10 + Q123], - q[LUU_3D][ULL_3D*10 + Q123], q[ULL_3D][LUU_3D*10 + Q123], - q[ULU_3D][LUL_3D*10 + Q123], q[UUL_3D][LLU_3D*10 + Q123], - q[UUU_3D][LLL_3D*10 + Q123]); - div_qz[2] = calc_sym_gradz_3D(dz, q[LLL_3D][UUU_3D*10 + Q133], - q[LLU_3D][UUL_3D*10 + Q133], q[LUL_3D][ULU_3D*10 + Q133], - q[LUU_3D][ULL_3D*10 + Q133], q[ULL_3D][LUU_3D*10 + Q133], - q[ULU_3D][LUL_3D*10 + Q133], q[UUL_3D][LLU_3D*10 + Q133], - q[UUU_3D][LLL_3D*10 + Q133]); - div_qz[3] = calc_sym_gradz_3D(dz, q[LLL_3D][UUU_3D*10 + Q223], - q[LLU_3D][UUL_3D*10 + Q223], q[LUL_3D][ULU_3D*10 + Q223], - q[LUU_3D][ULL_3D*10 + Q223], q[ULL_3D][LUU_3D*10 + Q223], - q[ULU_3D][LUL_3D*10 + Q223], q[UUL_3D][LLU_3D*10 + Q223], - q[UUU_3D][LLL_3D*10 + Q223]); - div_qz[4] = calc_sym_gradz_3D(dz, q[LLL_3D][UUU_3D*10 + Q233], - q[LLU_3D][UUL_3D*10 + Q233], q[LUL_3D][ULU_3D*10 + Q233], - q[LUU_3D][ULL_3D*10 + Q233], q[ULL_3D][LUU_3D*10 + Q233], - q[ULU_3D][LUL_3D*10 + Q233], q[UUL_3D][LLU_3D*10 + Q233], - q[UUU_3D][LLL_3D*10 + Q233]); - div_qz[5] = calc_sym_gradz_3D(dz, q[LLL_3D][UUU_3D*10 + Q333], - q[LLU_3D][UUL_3D*10 + Q333], q[LUL_3D][ULU_3D*10 + Q333], - q[LUU_3D][ULL_3D*10 + Q333], q[ULL_3D][LUU_3D*10 + Q333], - q[ULU_3D][LUL_3D*10 + Q333], q[UUL_3D][LLU_3D*10 + Q333], - q[UUU_3D][LLL_3D*10 + Q333]); + div_qx[0] = calc_sym_gradx_3D( + dx, q[LLL_3D][UUU_3D * 10 + Q111], q[LLU_3D][UUL_3D * 10 + Q111], q[LUL_3D][ULU_3D * 10 + Q111], + q[LUU_3D][ULL_3D * 10 + Q111], q[ULL_3D][LUU_3D * 10 + Q111], q[ULU_3D][LUL_3D * 10 + Q111], + q[UUL_3D][LLU_3D * 10 + Q111], q[UUU_3D][LLL_3D * 10 + Q111] + ); + div_qx[1] = calc_sym_gradx_3D( + dx, q[LLL_3D][UUU_3D * 10 + Q112], q[LLU_3D][UUL_3D * 10 + Q112], q[LUL_3D][ULU_3D * 10 + Q112], + q[LUU_3D][ULL_3D * 10 + Q112], q[ULL_3D][LUU_3D * 10 + Q112], q[ULU_3D][LUL_3D * 10 + Q112], + q[UUL_3D][LLU_3D * 10 + Q112], q[UUU_3D][LLL_3D * 10 + Q112] + ); + div_qx[2] = calc_sym_gradx_3D( + dx, q[LLL_3D][UUU_3D * 10 + Q113], q[LLU_3D][UUL_3D * 10 + Q113], q[LUL_3D][ULU_3D * 10 + Q113], + q[LUU_3D][ULL_3D * 10 + Q113], q[ULL_3D][LUU_3D * 10 + Q113], q[ULU_3D][LUL_3D * 10 + Q113], + q[UUL_3D][LLU_3D * 10 + Q113], q[UUU_3D][LLL_3D * 10 + Q113] + ); + div_qx[3] = calc_sym_gradx_3D( + dx, q[LLL_3D][UUU_3D * 10 + Q122], q[LLU_3D][UUL_3D * 10 + Q122], q[LUL_3D][ULU_3D * 10 + Q122], + q[LUU_3D][ULL_3D * 10 + Q122], q[ULL_3D][LUU_3D * 10 + Q122], q[ULU_3D][LUL_3D * 10 + Q122], + q[UUL_3D][LLU_3D * 10 + Q122], q[UUU_3D][LLL_3D * 10 + Q122] + ); + div_qx[4] = calc_sym_gradx_3D( + dx, q[LLL_3D][UUU_3D * 10 + Q123], q[LLU_3D][UUL_3D * 10 + Q123], q[LUL_3D][ULU_3D * 10 + Q123], + q[LUU_3D][ULL_3D * 10 + Q123], q[ULL_3D][LUU_3D * 10 + Q123], q[ULU_3D][LUL_3D * 10 + Q123], + q[UUL_3D][LLU_3D * 10 + Q123], q[UUU_3D][LLL_3D * 10 + Q123] + ); + div_qx[5] = calc_sym_gradx_3D( + dx, q[LLL_3D][UUU_3D * 10 + Q133], q[LLU_3D][UUL_3D * 10 + Q133], q[LUL_3D][ULU_3D * 10 + Q133], + q[LUU_3D][ULL_3D * 10 + Q133], q[ULL_3D][LUU_3D * 10 + Q133], q[ULU_3D][LUL_3D * 10 + Q133], + q[UUL_3D][LLU_3D * 10 + Q133], q[UUU_3D][LLL_3D * 10 + Q133] + ); + + div_qy[0] = calc_sym_grady_3D( + dy, q[LLL_3D][UUU_3D * 10 + Q112], q[LLU_3D][UUL_3D * 10 + Q112], q[LUL_3D][ULU_3D * 10 + Q112], + q[LUU_3D][ULL_3D * 10 + Q112], q[ULL_3D][LUU_3D * 10 + Q112], q[ULU_3D][LUL_3D * 10 + Q112], + q[UUL_3D][LLU_3D * 10 + Q112], q[UUU_3D][LLL_3D * 10 + Q112] + ); + div_qy[1] = calc_sym_grady_3D( + dy, q[LLL_3D][UUU_3D * 10 + Q122], q[LLU_3D][UUL_3D * 10 + Q122], q[LUL_3D][ULU_3D * 10 + Q122], + q[LUU_3D][ULL_3D * 10 + Q122], q[ULL_3D][LUU_3D * 10 + Q122], q[ULU_3D][LUL_3D * 10 + Q122], + q[UUL_3D][LLU_3D * 10 + Q122], q[UUU_3D][LLL_3D * 10 + Q122] + ); + div_qy[2] = calc_sym_grady_3D( + dy, q[LLL_3D][UUU_3D * 10 + Q123], q[LLU_3D][UUL_3D * 10 + Q123], q[LUL_3D][ULU_3D * 10 + Q123], + q[LUU_3D][ULL_3D * 10 + Q123], q[ULL_3D][LUU_3D * 10 + Q123], q[ULU_3D][LUL_3D * 10 + Q123], + q[UUL_3D][LLU_3D * 10 + Q123], q[UUU_3D][LLL_3D * 10 + Q123] + ); + div_qy[3] = calc_sym_grady_3D( + dy, q[LLL_3D][UUU_3D * 10 + Q222], q[LLU_3D][UUL_3D * 10 + Q222], q[LUL_3D][ULU_3D * 10 + Q222], + q[LUU_3D][ULL_3D * 10 + Q222], q[ULL_3D][LUU_3D * 10 + Q222], q[ULU_3D][LUL_3D * 10 + Q222], + q[UUL_3D][LLU_3D * 10 + Q222], q[UUU_3D][LLL_3D * 10 + Q222] + ); + div_qy[4] = calc_sym_grady_3D( + dy, q[LLL_3D][UUU_3D * 10 + Q223], q[LLU_3D][UUL_3D * 10 + Q223], q[LUL_3D][ULU_3D * 10 + Q223], + q[LUU_3D][ULL_3D * 10 + Q223], q[ULL_3D][LUU_3D * 10 + Q223], q[ULU_3D][LUL_3D * 10 + Q223], + q[UUL_3D][LLU_3D * 10 + Q223], q[UUU_3D][LLL_3D * 10 + Q223] + ); + div_qy[5] = calc_sym_grady_3D( + dy, q[LLL_3D][UUU_3D * 10 + Q233], q[LLU_3D][UUL_3D * 10 + Q233], q[LUL_3D][ULU_3D * 10 + Q233], + q[LUU_3D][ULL_3D * 10 + Q233], q[ULL_3D][LUU_3D * 10 + Q233], q[ULU_3D][LUL_3D * 10 + Q233], + q[UUL_3D][LLU_3D * 10 + Q233], q[UUU_3D][LLL_3D * 10 + Q233] + ); + + div_qz[0] = calc_sym_gradz_3D( + dz, q[LLL_3D][UUU_3D * 10 + Q113], q[LLU_3D][UUL_3D * 10 + Q113], q[LUL_3D][ULU_3D * 10 + Q113], + q[LUU_3D][ULL_3D * 10 + Q113], q[ULL_3D][LUU_3D * 10 + Q113], q[ULU_3D][LUL_3D * 10 + Q113], + q[UUL_3D][LLU_3D * 10 + Q113], q[UUU_3D][LLL_3D * 10 + Q113] + ); + div_qz[1] = calc_sym_gradz_3D( + dz, q[LLL_3D][UUU_3D * 10 + Q123], q[LLU_3D][UUL_3D * 10 + Q123], q[LUL_3D][ULU_3D * 10 + Q123], + q[LUU_3D][ULL_3D * 10 + Q123], q[ULL_3D][LUU_3D * 10 + Q123], q[ULU_3D][LUL_3D * 10 + Q123], + q[UUL_3D][LLU_3D * 10 + Q123], q[UUU_3D][LLL_3D * 10 + Q123] + ); + div_qz[2] = calc_sym_gradz_3D( + dz, q[LLL_3D][UUU_3D * 10 + Q133], q[LLU_3D][UUL_3D * 10 + Q133], q[LUL_3D][ULU_3D * 10 + Q133], + q[LUU_3D][ULL_3D * 10 + Q133], q[ULL_3D][LUU_3D * 10 + Q133], q[ULU_3D][LUL_3D * 10 + Q133], + q[UUL_3D][LLU_3D * 10 + Q133], q[UUU_3D][LLL_3D * 10 + Q133] + ); + div_qz[3] = calc_sym_gradz_3D( + dz, q[LLL_3D][UUU_3D * 10 + Q223], q[LLU_3D][UUL_3D * 10 + Q223], q[LUL_3D][ULU_3D * 10 + Q223], + q[LUU_3D][ULL_3D * 10 + Q223], q[ULL_3D][LUU_3D * 10 + Q223], q[ULU_3D][LUL_3D * 10 + Q223], + q[UUL_3D][LLU_3D * 10 + Q223], q[UUU_3D][LLL_3D * 10 + Q223] + ); + div_qz[4] = calc_sym_gradz_3D( + dz, q[LLL_3D][UUU_3D * 10 + Q233], q[LLU_3D][UUL_3D * 10 + Q233], q[LUL_3D][ULU_3D * 10 + Q233], + q[LUU_3D][ULL_3D * 10 + Q233], q[ULL_3D][LUU_3D * 10 + Q233], q[ULU_3D][LUL_3D * 10 + Q233], + q[UUL_3D][LLU_3D * 10 + Q233], q[UUU_3D][LLL_3D * 10 + Q233] + ); + div_qz[5] = calc_sym_gradz_3D( + dz, q[LLL_3D][UUU_3D * 10 + Q333], q[LLU_3D][UUL_3D * 10 + Q333], q[LUL_3D][ULU_3D * 10 + Q333], + q[LUU_3D][ULL_3D * 10 + Q333], q[ULL_3D][LUU_3D * 10 + Q333], q[ULU_3D][LUL_3D * 10 + Q333], + q[UUL_3D][LLU_3D * 10 + Q333], q[UUU_3D][LLL_3D * 10 + Q333] + ); rhs[RHO] = 0.0; rhs[MX] = 0.0; @@ -967,24 +995,20 @@ grad_closure_update_3d(const gkyl_ten_moment_grad_closure *gces, rhs[P33] = div_qx[5] + div_qy[5] + div_qz[5]; } -GKYL_CU_D -static const heat_flux_calc_t grad_closure_unmag_funcs[3] = { calc_unmag_heat_flux_1d, - calc_unmag_heat_flux_2d, calc_unmag_heat_flux_3d }; +GKYL_CU_D static const heat_flux_calc_t grad_closure_unmag_funcs[3] = { + calc_unmag_heat_flux_1d, calc_unmag_heat_flux_2d, calc_unmag_heat_flux_3d +}; -GKYL_CU_D -static const heat_flux_update_t grad_closure_update_funcs[3] = { grad_closure_update_1d, - grad_closure_update_2d, grad_closure_update_3d }; +GKYL_CU_D static const heat_flux_update_t grad_closure_update_funcs[3] = { + grad_closure_update_1d, grad_closure_update_2d, grad_closure_update_3d +}; -GKYL_CU_D -static void -grad_closure_calc_q_choose(gkyl_ten_moment_grad_closure *gces) +GKYL_CU_D static void grad_closure_calc_q_choose(gkyl_ten_moment_grad_closure *gces) { gces->calc_q = grad_closure_unmag_funcs[gces->ndim - 1]; } -GKYL_CU_D -static void -grad_closure_update_q_choose(gkyl_ten_moment_grad_closure *gces) +GKYL_CU_D static void grad_closure_update_q_choose(gkyl_ten_moment_grad_closure *gces) { gces->update_q = grad_closure_update_funcs[gces->ndim - 1]; } diff --git a/moments/zero/gkyl_ten_moment_nn_closure.h b/moments/zero/gkyl_ten_moment_nn_closure.h index 6c0881dc01..7f148bcdbd 100644 --- a/moments/zero/gkyl_ten_moment_nn_closure.h +++ b/moments/zero/gkyl_ten_moment_nn_closure.h @@ -11,12 +11,11 @@ #include #include -struct gkyl_ten_moment_nn_closure_inp -{ +struct gkyl_ten_moment_nn_closure_inp { const struct gkyl_rect_grid *grid; // Grid on which to solve equations. int poly_order; // Polynomial order of learned DG coefficients. double k0; // Damping coefficient. - struct gkyl_kann_net* ann; // Neural network architecture. + struct gkyl_kann_net *ann; // Neural network architecture. }; // Object type. @@ -26,12 +25,12 @@ typedef struct gkyl_ten_moment_nn_closure gkyl_ten_moment_nn_closure; // pass and consumed when constructing the heat-flux divergence after // inference. Computed once per cell so the gather and scatter phases share it. struct gkyl_ten_moment_nn_closure_geom { - double local_mag[3]; // Unit magnetic field direction b = B / |B|. + double local_mag[3]; // Unit magnetic field direction b = B / |B|. double local_mag_dx[3]; // d(b) / dx. double local_mag_dy[3]; // d(b) / dy (2D only; zero otherwise). - double B_avg[3]; // Cell-averaged magnetic field. - double rho_avg; // Cell-averaged mass density. - double p_avg[6]; // Cell-averaged pressure tensor (xx, xy, xz, yy, yz, zz). + double B_avg[3]; // Cell-averaged magnetic field. + double rho_avg; // Cell-averaged mass density. + double p_avg[6]; // Cell-averaged pressure tensor (xx, xy, xz, yy, yz, zz). }; /** @@ -40,8 +39,7 @@ struct gkyl_ten_moment_nn_closure_geom { * @param nnclosure Neural network closure updater object. * @return Input feature count (6 for 1D-p1, 9 for 1D-p2, 12 for 2D-p1). */ -int -gkyl_ten_moment_nn_closure_n_in(const gkyl_ten_moment_nn_closure *nnclosure); +int gkyl_ten_moment_nn_closure_n_in(const gkyl_ten_moment_nn_closure *nnclosure); /** * Number of neural-network output predictions for the given closure configuration. @@ -49,8 +47,7 @@ gkyl_ten_moment_nn_closure_n_in(const gkyl_ten_moment_nn_closure *nnclosure); * @param nnclosure Neural network closure updater object. * @return Output count (4 for 1D-p1, 6 for 1D-p2, 8 for 2D-p1). */ -int -gkyl_ten_moment_nn_closure_n_out(const gkyl_ten_moment_nn_closure *nnclosure); +int gkyl_ten_moment_nn_closure_n_out(const gkyl_ten_moment_nn_closure *nnclosure); /** * Compute the neural-network input feature vector (of length n_in) and cache @@ -64,9 +61,10 @@ gkyl_ten_moment_nn_closure_n_out(const gkyl_ten_moment_nn_closure *nnclosure); * @param input_data Output: input feature vector (caller-allocated, length n_in). * @param geom Output: cached aligned geometry for this cell. */ -void -gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure, const double *fluid_d[], const double *em_tot_d[], float *input_data, - struct gkyl_ten_moment_nn_closure_geom *geom); +void gkyl_ten_moment_nn_closure_geom_calc( + const gkyl_ten_moment_nn_closure *nnclosure, const double *fluid_d[], const double *em_tot_d[], + float *input_data, struct gkyl_ten_moment_nn_closure_geom *geom +); /** * Construct the magnetized heat-flux tensor from a (network) prediction and @@ -78,9 +76,10 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure * @param output_data_predicted Predicted outputs (q and its gradients), length n_out. * @param rhs Output: closure source for the conserved variables (length 10). */ -void -gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure, const struct gkyl_ten_moment_nn_closure_geom *geom, - const float *output_data_predicted, double *rhs); +void gkyl_ten_moment_nn_closure_construct( + const gkyl_ten_moment_nn_closure *nnclosure, const struct gkyl_ten_moment_nn_closure_geom *geom, + const float *output_data_predicted, double *rhs +); /** * Create a new updater to update the pressure tensor in the ten moment equation system using a machine-learned magnetized closure trained on PKPM simulations, @@ -90,8 +89,8 @@ gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure * @param inp Input parameters for updater. * @return Pointer to updater. */ -gkyl_ten_moment_nn_closure* -gkyl_ten_moment_nn_closure_new(struct gkyl_ten_moment_nn_closure_inp inp); +gkyl_ten_moment_nn_closure *gkyl_ten_moment_nn_closure_new(struct gkyl_ten_moment_nn_closure_inp inp +); /** * Compute the right-hand-side contribution to the ten moment equation system from a machine-learned magnetized closure trained on PKPM simulations. @@ -106,14 +105,15 @@ gkyl_ten_moment_nn_closure_new(struct gkyl_ten_moment_nn_closure_inp inp); * @param heat_flux Array for storing intermediate computation of heat flux tensor (at cell nodes). * @param rhs Right-hand-side output. */ -void -gkyl_ten_moment_nn_closure_advance(const gkyl_ten_moment_nn_closure *nnclosure, const struct gkyl_range *heat_flux_rng, const struct gkyl_range *update_rng, - const struct gkyl_array *fluid, const struct gkyl_array *em_tot, struct gkyl_array *heat_flux, struct gkyl_array *rhs); +void gkyl_ten_moment_nn_closure_advance( + const gkyl_ten_moment_nn_closure *nnclosure, const struct gkyl_range *heat_flux_rng, + const struct gkyl_range *update_rng, const struct gkyl_array *fluid, + const struct gkyl_array *em_tot, struct gkyl_array *heat_flux, struct gkyl_array *rhs +); /** * Delete updater. * * @param nnclosure Updater to delete. */ - void - gkyl_ten_moment_nn_closure_release(gkyl_ten_moment_nn_closure *nnclosure); \ No newline at end of file +void gkyl_ten_moment_nn_closure_release(gkyl_ten_moment_nn_closure *nnclosure); \ No newline at end of file diff --git a/moments/zero/gkyl_wave_geom.h b/moments/zero/gkyl_wave_geom.h index 9ca117b787..b929456e21 100644 --- a/moments/zero/gkyl_wave_geom.h +++ b/moments/zero/gkyl_wave_geom.h @@ -23,7 +23,7 @@ struct gkyl_wave_geom { struct gkyl_array *geom; // geometry in each cell uint32_t flags; - struct gkyl_ref_count ref_count; + struct gkyl_ref_count ref_count; struct gkyl_wave_geom *on_dev; // pointer to itself or device object }; @@ -35,17 +35,18 @@ struct gkyl_wave_geom { * @param mapc2p Mapping from computational to physical space * @param ctx Context for use in mapping */ -struct gkyl_wave_geom* -gkyl_wave_geom_new(const struct gkyl_rect_grid *grid, - struct gkyl_range *range, evalf_t mapc2p, void *ctx, bool use_gpu); +struct gkyl_wave_geom *gkyl_wave_geom_new( + const struct gkyl_rect_grid *grid, struct gkyl_range *range, evalf_t mapc2p, void *ctx, + bool use_gpu +); /** * Create a new wave geometry object that lives on NV-GPU: see new() method * above for documentation. */ -struct gkyl_wave_geom* -gkyl_wave_geom_cu_dev_new(const struct gkyl_rect_grid *grid, - struct gkyl_range *range, evalf_t mapc2p, void *ctx); +struct gkyl_wave_geom *gkyl_wave_geom_cu_dev_new( + const struct gkyl_rect_grid *grid, struct gkyl_range *range, evalf_t mapc2p, void *ctx +); /** * Acquire pointer to geometry object. The pointer must be released @@ -54,7 +55,7 @@ gkyl_wave_geom_cu_dev_new(const struct gkyl_rect_grid *grid, * @param wg Geometry to which a pointer is needed * @return Pointer to acquired geometry */ -struct gkyl_wave_geom* gkyl_wave_geom_acquire(const struct gkyl_wave_geom* wg); +struct gkyl_wave_geom *gkyl_wave_geom_acquire(const struct gkyl_wave_geom *wg); /** * Get pointer to geometry in a cell given by idx into the range over @@ -64,11 +65,12 @@ struct gkyl_wave_geom* gkyl_wave_geom_acquire(const struct gkyl_wave_geom* wg); * @param idx Index into grid * @return cell geometry in cell @a idx */ -GKYL_CU_DH -static inline const struct gkyl_wave_cell_geom* +GKYL_CU_DH static inline const struct gkyl_wave_cell_geom * gkyl_wave_geom_get(const struct gkyl_wave_geom *wg, const int *idx) { - return (const struct gkyl_wave_cell_geom*) gkyl_array_cfetch(wg->geom, gkyl_range_idx(&wg->range, idx)); + return (const struct gkyl_wave_cell_geom *)gkyl_array_cfetch( + wg->geom, gkyl_range_idx(&wg->range, idx) + ); } /** diff --git a/moments/zero/gkyl_wave_geom_priv.h b/moments/zero/gkyl_wave_geom_priv.h index a3e4691f74..97f178f33b 100644 --- a/moments/zero/gkyl_wave_geom_priv.h +++ b/moments/zero/gkyl_wave_geom_priv.h @@ -18,33 +18,42 @@ */ void gkyl_wave_geom_free(const struct gkyl_ref_count *ref); -static void -nomapc2p(double t, const double *xc, double *xp, void *ctx) +static void nomapc2p(double t, const double *xc, double *xp, void *ctx) { - for (int i=0; i<3; ++i) xp[i] = xc[i]; + for (int i = 0; i < 3; ++i) { + xp[i] = xc[i]; + } } // Computes 1D geometry -static void -calc_geom_1d_from_nodes(const double *dx, const double *xlp, const double *xrp, - evalf_t mapc2p, void *ctx, struct gkyl_wave_cell_geom *geo) +static void calc_geom_1d_from_nodes( + const double *dx, const double *xlp, const double *xrp, evalf_t mapc2p, void *ctx, + struct gkyl_wave_cell_geom *geo +) { - geo->kappa = fabs(xrp[0]-xlp[0])/dx[0]; + geo->kappa = fabs(xrp[0] - xlp[0]) / dx[0]; geo->lenr[0] = 1.0; - geo->norm[0][0] = 1.0; geo->norm[0][1] = 0.0; geo->norm[0][2] = 0.0; - geo->tau1[0][0] = 0.0; geo->tau1[0][1] = 1.0; geo->tau1[0][2] = 0.0; - geo->tau2[0][0] = 0.0; geo->tau2[0][1] = 0.0; geo->tau2[0][2] = 1.0; + geo->norm[0][0] = 1.0; + geo->norm[0][1] = 0.0; + geo->norm[0][2] = 0.0; + geo->tau1[0][0] = 0.0; + geo->tau1[0][1] = 1.0; + geo->tau1[0][2] = 0.0; + geo->tau2[0][0] = 0.0; + geo->tau2[0][1] = 0.0; + geo->tau2[0][2] = 1.0; } -static void -calc_geom_1d(const double *dx, const double *xc, evalf_t mapc2p, void *ctx, struct gkyl_wave_cell_geom *geo) +static void calc_geom_1d( + const double *dx, const double *xc, evalf_t mapc2p, void *ctx, struct gkyl_wave_cell_geom *geo +) { double xlc[GKYL_MAX_CDIM], xrc[GKYL_MAX_CDIM]; double xlp[GKYL_MAX_CDIM], xrp[GKYL_MAX_CDIM]; - xlc[0] = xc[0]-0.5*dx[0]; // left node - xrc[0] = xc[0]+0.5*dx[0]; // right node + xlc[0] = xc[0] - 0.5 * dx[0]; // left node + xrc[0] = xc[0] + 0.5 * dx[0]; // right node // compute coordinates of left/right nodes mapc2p(0.0, xlc, xlp, ctx); @@ -54,31 +63,32 @@ calc_geom_1d(const double *dx, const double *xc, evalf_t mapc2p, void *ctx, stru } // Computes 2D geometry -static void -calc_geom_2d_from_nodes(const double *dx, const struct gkyl_vec3 xll_p, - const struct gkyl_vec3 xlr_p, const struct gkyl_vec3 xul_p, - const struct gkyl_vec3 xur_p, evalf_t mapc2p, void *ctx, - struct gkyl_wave_cell_geom *geo) +static void calc_geom_2d_from_nodes( + const double *dx, const struct gkyl_vec3 xll_p, const struct gkyl_vec3 xlr_p, + const struct gkyl_vec3 xul_p, const struct gkyl_vec3 xur_p, evalf_t mapc2p, void *ctx, + struct gkyl_wave_cell_geom *geo +) { // ll: lower-left; lr: lower-right // ul: upper-left; ur: upper-right // volume factor - double area = 0.5*gkyl_vec3_len( gkyl_vec3_cross(gkyl_vec3_sub(xlr_p,xll_p), gkyl_vec3_sub(xul_p,xll_p)) ) - + 0.5*gkyl_vec3_len( gkyl_vec3_cross(gkyl_vec3_sub(xlr_p,xur_p), gkyl_vec3_sub(xul_p,xur_p)) ); + double area = + 0.5 * gkyl_vec3_len(gkyl_vec3_cross(gkyl_vec3_sub(xlr_p, xll_p), gkyl_vec3_sub(xul_p, xll_p))) + + 0.5 * gkyl_vec3_len(gkyl_vec3_cross(gkyl_vec3_sub(xlr_p, xur_p), gkyl_vec3_sub(xul_p, xur_p))); - geo->kappa = area/(dx[0]*dx[1]); + geo->kappa = area / (dx[0] * dx[1]); // face-area ratios for faces (a face is an edge in 2D) - geo->lenr[0] = gkyl_vec3_len(gkyl_vec3_sub(xul_p, xll_p))/dx[1]; - geo->lenr[1] = gkyl_vec3_len(gkyl_vec3_sub(xlr_p, xll_p))/dx[0]; + geo->lenr[0] = gkyl_vec3_len(gkyl_vec3_sub(xul_p, xll_p)) / dx[1]; + geo->lenr[1] = gkyl_vec3_len(gkyl_vec3_sub(xlr_p, xll_p)) / dx[0]; // normal-tangent to left face struct gkyl_vec3 tau1_l = gkyl_vec3_norm(gkyl_vec3_sub(xul_p, xll_p)); struct gkyl_vec3 tau2_l = gkyl_vec3_new(0.0, 0.0, 1.0); // ez struct gkyl_vec3 norm_l = gkyl_vec3_cross(tau1_l, tau2_l); - - for (int d=0; d<3; ++d) { + + for (int d = 0; d < 3; ++d) { geo->norm[0][d] = norm_l.x[d]; geo->tau1[0][d] = tau1_l.x[d]; geo->tau2[0][d] = tau2_l.x[d]; @@ -89,30 +99,31 @@ calc_geom_2d_from_nodes(const double *dx, const struct gkyl_vec3 xll_p, struct gkyl_vec3 tau2_b = gkyl_vec3_new(0.0, 0.0, -1.0); // -ez (ensures normal points into cell) struct gkyl_vec3 norm_b = gkyl_vec3_cross(tau1_b, tau2_b); - for (int d=0; d<3; ++d) { + for (int d = 0; d < 3; ++d) { geo->norm[1][d] = norm_b.x[d]; geo->tau1[1][d] = tau1_b.x[d]; geo->tau2[1][d] = tau2_b.x[d]; } } -static void -calc_geom_2d(const double *dx, const double *xc, evalf_t mapc2p, void *ctx, struct gkyl_wave_cell_geom *geo) +static void calc_geom_2d( + const double *dx, const double *xc, evalf_t mapc2p, void *ctx, struct gkyl_wave_cell_geom *geo +) { // ll: lower-left; lr: lower-right // ul: upper-left; ur: upper-right - + struct gkyl_vec3 xll_p = gkyl_vec3_zeros(); struct gkyl_vec3 xlr_p = gkyl_vec3_zeros(); struct gkyl_vec3 xul_p = gkyl_vec3_zeros(); struct gkyl_vec3 xur_p = gkyl_vec3_zeros(); - struct gkyl_vec3 xll_c = gkyl_vec3_new(xc[0] - 0.5*dx[0], xc[1] - 0.5*dx[1], 0.0); - struct gkyl_vec3 xlr_c = gkyl_vec3_new(xc[0] + 0.5*dx[0], xc[1] - 0.5*dx[1], 0.0); + struct gkyl_vec3 xll_c = gkyl_vec3_new(xc[0] - 0.5 * dx[0], xc[1] - 0.5 * dx[1], 0.0); + struct gkyl_vec3 xlr_c = gkyl_vec3_new(xc[0] + 0.5 * dx[0], xc[1] - 0.5 * dx[1], 0.0); + + struct gkyl_vec3 xul_c = gkyl_vec3_new(xc[0] - 0.5 * dx[0], xc[1] + 0.5 * dx[1], 0.0); + struct gkyl_vec3 xur_c = gkyl_vec3_new(xc[0] + 0.5 * dx[0], xc[1] + 0.5 * dx[1], 0.0); - struct gkyl_vec3 xul_c = gkyl_vec3_new(xc[0] - 0.5*dx[0], xc[1] + 0.5*dx[1], 0.0); - struct gkyl_vec3 xur_c = gkyl_vec3_new(xc[0] + 0.5*dx[0], xc[1] + 0.5*dx[1], 0.0); - mapc2p(0.0, xll_c.x, xll_p.x, ctx); mapc2p(0.0, xlr_c.x, xlr_p.x, ctx); mapc2p(0.0, xul_c.x, xul_p.x, ctx); @@ -125,17 +136,16 @@ calc_geom_2d(const double *dx, const double *xc, evalf_t mapc2p, void *ctx, stru } // Computes 3D geometry -static double -vol_tetra(const struct gkyl_vec3 p1, - const struct gkyl_vec3 p2, - const struct gkyl_vec3 p3, - const struct gkyl_vec3 p4) +static double vol_tetra( + const struct gkyl_vec3 p1, const struct gkyl_vec3 p2, const struct gkyl_vec3 p3, + const struct gkyl_vec3 p4 +) { struct gkyl_vec3 a = gkyl_vec3_sub(p1, p4); struct gkyl_vec3 b = gkyl_vec3_sub(p2, p4); struct gkyl_vec3 c = gkyl_vec3_sub(p3, p4); double vol = gkyl_vec3_dot(a, gkyl_vec3_cross(b, c)) / 6.; - return vol > 0? vol : -vol; + return vol > 0 ? vol : -vol; } /* The order of vertices is assumed to be (l: lower, u: upper): @@ -161,8 +171,7 @@ vol_tetra(const struct gkyl_vec3 p1, \| z \| 4----------5 */ -static double -vol_hexa(const struct gkyl_vec3 *verts) +static double vol_hexa(const struct gkyl_vec3 *verts) { // split the hexahedron into five tetrahedrons and add up their volumes // FIXME does this handle bad hexahedrons? @@ -177,21 +186,16 @@ vol_hexa(const struct gkyl_vec3 *verts) } static inline double -triangle_area(const struct gkyl_vec3 p1, - const struct gkyl_vec3 p2, - const struct gkyl_vec3 p3) +triangle_area(const struct gkyl_vec3 p1, const struct gkyl_vec3 p2, const struct gkyl_vec3 p3) { - return 0.5*gkyl_vec3_len( - gkyl_vec3_cross(gkyl_vec3_sub(p1, p2), gkyl_vec3_sub(p2, p3))); + return 0.5 * gkyl_vec3_len(gkyl_vec3_cross(gkyl_vec3_sub(p1, p2), gkyl_vec3_sub(p2, p3))); } // Points are in anti-clockwise order, i.e., p1-p3 and p2-p4 are diagonals. -static double -planar_quad_area_norm(const struct gkyl_vec3 p1, - const struct gkyl_vec3 p2, - const struct gkyl_vec3 p3, - const struct gkyl_vec3 p4, - struct gkyl_vec3 *norm) +static double planar_quad_area_norm( + const struct gkyl_vec3 p1, const struct gkyl_vec3 p2, const struct gkyl_vec3 p3, + const struct gkyl_vec3 p4, struct gkyl_vec3 *norm +) { struct gkyl_vec3 v13 = gkyl_vec3_sub(p3, p1); struct gkyl_vec3 v24 = gkyl_vec3_sub(p4, p2); @@ -201,8 +205,7 @@ planar_quad_area_norm(const struct gkyl_vec3 p1, if (norm) { struct gkyl_vec3 norm_ = gkyl_vec3_norm(gkyl_vec3_cross(v13, v24)); - for (int d=0; d<3; ++d) - { + for (int d = 0; d < 3; ++d) { norm->x[d] = norm_.x[d]; } } @@ -212,23 +215,16 @@ planar_quad_area_norm(const struct gkyl_vec3 p1, // ca * a + cb * b static inline struct gkyl_vec3 -gkyl_vec3_add_coeff( - const double ca, struct gkyl_vec3 a, const double cb, struct gkyl_vec3 b) +gkyl_vec3_add_coeff(const double ca, struct gkyl_vec3 a, const double cb, struct gkyl_vec3 b) { - return (struct gkyl_vec3) { .x = { - ca*a.x[0] + cb*b.x[0], - ca*a.x[1] + cb*b.x[1], - ca*a.x[2] + cb*b.x[2] } }; + return (struct gkyl_vec3 + ){.x = {ca * a.x[0] + cb * b.x[0], ca * a.x[1] + cb * b.x[1], ca * a.x[2] + cb * b.x[2]}}; } -static double -quad_area_norm_tang(const struct gkyl_vec3 p1, - const struct gkyl_vec3 p2, - const struct gkyl_vec3 p3, - const struct gkyl_vec3 p4, - struct gkyl_vec3 *norm, - struct gkyl_vec3 *tau1, - struct gkyl_vec3 *tau2) +static double quad_area_norm_tang( + const struct gkyl_vec3 p1, const struct gkyl_vec3 p2, const struct gkyl_vec3 p3, + const struct gkyl_vec3 p4, struct gkyl_vec3 *norm, struct gkyl_vec3 *tau1, struct gkyl_vec3 *tau2 +) { // find Varignon parallelogram and use its normal as the quad's normal struct gkyl_vec3 pp1 = gkyl_vec3_add_coeff(0.5, p1, 0.5, p2); @@ -243,8 +239,7 @@ quad_area_norm_tang(const struct gkyl_vec3 p1, double d = gkyl_vec3_dot(p12, *norm); struct gkyl_vec3 t1 = gkyl_vec3_norm(gkyl_vec3_add_coeff(1, p12, -d, *norm)); struct gkyl_vec3 t2 = gkyl_vec3_cross(*norm, t1); - for (int d=0; d<3; ++d) - { + for (int d = 0; d < 3; ++d) { tau1->x[d] = t1.x[d]; tau2->x[d] = t2.x[d]; } @@ -260,7 +255,7 @@ quad_area_norm_tang(const struct gkyl_vec3 p1, struct gkyl_vec3 proj3 = gkyl_vec3_add_coeff(1, p3, -d, *norm); d = gkyl_vec3_dot(*norm, p4); struct gkyl_vec3 proj4 = gkyl_vec3_add_coeff(1, p4, -d, *norm); - + area = planar_quad_area_norm(proj1, proj2, proj3, proj4, norm); #else // accumulate triangle areas @@ -273,9 +268,10 @@ quad_area_norm_tang(const struct gkyl_vec3 p1, return area; } -static void -calc_geom_3d_form_nodes(const double *dx, struct gkyl_vec3 verts[8], - evalf_t mapc2p, void *ctx, struct gkyl_wave_cell_geom *geo) +static void calc_geom_3d_form_nodes( + const double *dx, struct gkyl_vec3 verts[8], evalf_t mapc2p, void *ctx, + struct gkyl_wave_cell_geom *geo +) { // compute cell volume and kappa double vol = vol_hexa(verts); @@ -284,28 +280,26 @@ calc_geom_3d_form_nodes(const double *dx, struct gkyl_vec3 verts[8], // for each of the thee lower quad faces 'owned' by the present cell, compute // area, norm, tan1, tan2, and lenr - int pt_idx[3][4] = { // indices of verices of each face in verts; see vol_hexa - // lower-x face, lll, lul, luu, llu; v(p1->p2)=ey - {0, 3, 7, 4}, - // lower-y face, lll, llu, ulu, ull; v(p1->p2)=ez - {0, 4, 5, 1}, - // lower-z face, lll, ull, uul, lul; v(p1->p2)=ex - {0, 1, 2, 3} + int pt_idx[3][4] = {// indices of verices of each face in verts; see vol_hexa + // lower-x face, lll, lul, luu, llu; v(p1->p2)=ey + {0, 3, 7, 4}, + // lower-y face, lll, llu, ulu, ull; v(p1->p2)=ez + {0, 4, 5, 1}, + // lower-z face, lll, ull, uul, lul; v(p1->p2)=ex + {0, 1, 2, 3} }; - for (int face_idx = 0; face_idx < 3; ++face_idx) - { + for (int face_idx = 0; face_idx < 3; ++face_idx) { int ip1 = pt_idx[face_idx][0]; int ip2 = pt_idx[face_idx][1]; int ip3 = pt_idx[face_idx][2]; int ip4 = pt_idx[face_idx][3]; struct gkyl_vec3 norm, tau1, tau2; - double area= quad_area_norm_tang( - verts[ip1], verts[ip2], verts[ip3], verts[ip4], &norm, &tau1, &tau2); + double area = + quad_area_norm_tang(verts[ip1], verts[ip2], verts[ip3], verts[ip4], &norm, &tau1, &tau2); double cell_area_c = cell_vol_c / dx[face_idx]; geo->lenr[face_idx] = area / cell_area_c; - for (int d=0; d<3; ++d) - { + for (int d = 0; d < 3; ++d) { geo->norm[face_idx][d] = norm.x[d]; geo->tau1[face_idx][d] = tau1.x[d]; geo->tau2[face_idx][d] = tau2.x[d]; @@ -313,26 +307,26 @@ calc_geom_3d_form_nodes(const double *dx, struct gkyl_vec3 verts[8], } } -static void -calc_geom_3d(const double *dx, const double *xc, evalf_t mapc2p, void *ctx, - struct gkyl_wave_cell_geom *geo) +static void calc_geom_3d( + const double *dx, const double *xc, evalf_t mapc2p, void *ctx, struct gkyl_wave_cell_geom *geo +) { // get all vertices of the hexahedron; see vol_hexa for their order struct gkyl_vec3 verts_c[8] = { - gkyl_vec3_new(xc[0]-0.5*dx[0], xc[1]-0.5*dx[1], xc[2]-0.5*dx[2]), - gkyl_vec3_new(xc[0]+0.5*dx[0], xc[1]-0.5*dx[1], xc[2]-0.5*dx[2]), - gkyl_vec3_new(xc[0]+0.5*dx[0], xc[1]+0.5*dx[1], xc[2]-0.5*dx[2]), - gkyl_vec3_new(xc[0]-0.5*dx[0], xc[1]+0.5*dx[1], xc[2]-0.5*dx[2]), - gkyl_vec3_new(xc[0]-0.5*dx[0], xc[1]-0.5*dx[1], xc[2]+0.5*dx[2]), - gkyl_vec3_new(xc[0]+0.5*dx[0], xc[1]-0.5*dx[1], xc[2]+0.5*dx[2]), - gkyl_vec3_new(xc[0]+0.5*dx[0], xc[1]+0.5*dx[1], xc[2]+0.5*dx[2]), - gkyl_vec3_new(xc[0]-0.5*dx[0], xc[1]+0.5*dx[1], xc[2]+0.5*dx[2]) + gkyl_vec3_new(xc[0] - 0.5 * dx[0], xc[1] - 0.5 * dx[1], xc[2] - 0.5 * dx[2]), + gkyl_vec3_new(xc[0] + 0.5 * dx[0], xc[1] - 0.5 * dx[1], xc[2] - 0.5 * dx[2]), + gkyl_vec3_new(xc[0] + 0.5 * dx[0], xc[1] + 0.5 * dx[1], xc[2] - 0.5 * dx[2]), + gkyl_vec3_new(xc[0] - 0.5 * dx[0], xc[1] + 0.5 * dx[1], xc[2] - 0.5 * dx[2]), + gkyl_vec3_new(xc[0] - 0.5 * dx[0], xc[1] - 0.5 * dx[1], xc[2] + 0.5 * dx[2]), + gkyl_vec3_new(xc[0] + 0.5 * dx[0], xc[1] - 0.5 * dx[1], xc[2] + 0.5 * dx[2]), + gkyl_vec3_new(xc[0] + 0.5 * dx[0], xc[1] + 0.5 * dx[1], xc[2] + 0.5 * dx[2]), + gkyl_vec3_new(xc[0] - 0.5 * dx[0], xc[1] + 0.5 * dx[1], xc[2] + 0.5 * dx[2]) }; struct gkyl_vec3 verts[8]; // physical coordinate nodes - for (int i=0; i<8; ++i) + for (int i = 0; i < 8; ++i) { mapc2p(0.0, verts_c[i].x, verts[i].x, ctx); + } calc_geom_3d_form_nodes(dx, verts, mapc2p, ctx, geo); } - diff --git a/moments/zero/gkyl_wave_prop.h b/moments/zero/gkyl_wave_prop.h index 4cab8d4742..ac9c1c12b7 100644 --- a/moments/zero/gkyl_wave_prop.h +++ b/moments/zero/gkyl_wave_prop.h @@ -67,7 +67,7 @@ struct gkyl_wave_prop_stats { * * @param winp Input for creating updater. See gkyl_wave_prop_inp above. */ -gkyl_wave_prop* gkyl_wave_prop_new(const struct gkyl_wave_prop_inp *winp); +gkyl_wave_prop *gkyl_wave_prop_new(const struct gkyl_wave_prop_inp *winp); /** * Compute wave-propagation update. The update_rng MUST be a sub-range @@ -82,9 +82,10 @@ gkyl_wave_prop* gkyl_wave_prop_new(const struct gkyl_wave_prop_inp *winp); * @param qin Input to updater * @param qout Solution at tm+dt */ -struct gkyl_wave_prop_status gkyl_wave_prop_advance(gkyl_wave_prop *wv, - double tm, double dt, const struct gkyl_range *update_range, - struct gkyl_array *phi, const struct gkyl_array *qin, struct gkyl_array *qout); +struct gkyl_wave_prop_status gkyl_wave_prop_advance( + gkyl_wave_prop *wv, double tm, double dt, const struct gkyl_range *update_range, + struct gkyl_array *phi, const struct gkyl_array *qin, struct gkyl_array *qout +); /** * Compute an estimate of maximum stable time-step for given input @@ -94,8 +95,9 @@ struct gkyl_wave_prop_status gkyl_wave_prop_advance(gkyl_wave_prop *wv, * @param qin Input to compute dt for * @return maximum stable time-step */ -double gkyl_wave_prop_max_dt(const gkyl_wave_prop *wv, const struct gkyl_range *update_range, - const struct gkyl_array *qin); +double gkyl_wave_prop_max_dt( + const gkyl_wave_prop *wv, const struct gkyl_range *update_range, const struct gkyl_array *qin +); /** * Fetch statics @@ -104,10 +106,10 @@ double gkyl_wave_prop_max_dt(const gkyl_wave_prop *wv, const struct gkyl_range * * @return statics from all calls to this updater */ struct gkyl_wave_prop_stats gkyl_wave_prop_stats(const gkyl_wave_prop *wv); - + /** * Delete updater. * * @param wv Updater to delete. */ -void gkyl_wave_prop_release(gkyl_wave_prop* wv); +void gkyl_wave_prop_release(gkyl_wave_prop *wv); diff --git a/moments/zero/gkyl_wv_advect.h b/moments/zero/gkyl_wv_advect.h index 5d49d2c1bd..0477670e35 100644 --- a/moments/zero/gkyl_wv_advect.h +++ b/moments/zero/gkyl_wv_advect.h @@ -32,8 +32,7 @@ struct gkyl_wv_advect_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the linear advection equation object. */ -struct gkyl_wv_eqn* -gkyl_wv_advect_new(double a, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_advect_new(double a, bool use_gpu); /** * Create a new linear advection equation object, from an input context struct. @@ -41,5 +40,4 @@ gkyl_wv_advect_new(double a, bool use_gpu); * @param inp Input context struct. * @return Pointer to the linear advection equation object. */ -struct gkyl_wv_eqn* -gkyl_wv_advect_inew(const struct gkyl_wv_advect_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_advect_inew(const struct gkyl_wv_advect_inp *inp); diff --git a/moments/zero/gkyl_wv_advect_priv.h b/moments/zero/gkyl_wv_advect_priv.h index 36754144cd..6d2519c719 100644 --- a/moments/zero/gkyl_wv_advect_priv.h +++ b/moments/zero/gkyl_wv_advect_priv.h @@ -30,9 +30,7 @@ struct wv_advect { * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_advect_max_abs_speed(double a, const double* q); +GKYL_CU_D static inline double gkyl_advect_max_abs_speed(double a, const double *q); /** * Compute flux vector. Assumes rotation to local coordinate system. @@ -41,9 +39,7 @@ gkyl_advect_max_abs_speed(double a, const double* q); * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_advect_flux(double a, const double* q, double* flux); +GKYL_CU_D void gkyl_advect_flux(double a, const double *q, double *flux); /** * Compute eigenvalues of the flux Jacobian. Assumes rotation to local coordinate system. @@ -52,9 +48,7 @@ gkyl_advect_flux(double a, const double* q, double* flux); * @param q Conserved variable vector. * @param flux_deriv Flux Jacobian eigenvalues in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_advect_flux_deriv(double a, const double* q, double* flux_deriv); +GKYL_CU_D void gkyl_advect_flux_deriv(double a, const double *q, double *flux_deriv); /** * Compute Riemann variables given the conserved variables. @@ -64,9 +58,8 @@ gkyl_advect_flux_deriv(double a, const double* q, double* flux_deriv); * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -76,9 +69,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the linear advection equation. @@ -90,9 +82,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -advect_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void advect_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the linear advection equation. @@ -104,9 +97,10 @@ advect_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -advect_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void advect_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -118,10 +112,10 @@ advect_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* sk * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -133,10 +127,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -149,9 +143,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -164,9 +159,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -180,9 +176,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -196,10 +193,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -212,9 +210,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -227,9 +226,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double phil, + const double phir, const double *waves, const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -243,9 +243,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback), @@ -259,10 +260,11 @@ wave(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* d * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -273,9 +275,8 @@ qfluct(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the linear advection equation is satisfied. @@ -284,9 +285,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -295,9 +294,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -306,9 +303,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -advect_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +advect_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variable vector. @@ -317,14 +313,12 @@ advect_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* di * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -advect_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +advect_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free linear advection equation object. * * @param ref Reference counter for linear advection equation. */ -void -gkyl_advect_free(const struct gkyl_ref_count* ref); +void gkyl_advect_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_apply_bc.h b/moments/zero/gkyl_wv_apply_bc.h index 67e40b050a..9583922611 100644 --- a/moments/zero/gkyl_wv_apply_bc.h +++ b/moments/zero/gkyl_wv_apply_bc.h @@ -23,10 +23,11 @@ typedef struct gkyl_wv_apply_bc gkyl_wv_apply_bc; * @param ctx Context to pass to bcfunc. * @return New updater pointer. */ -gkyl_wv_apply_bc* gkyl_wv_apply_bc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_wv_eqn *eqn, const struct gkyl_wave_geom *geom, - int dir, enum gkyl_edge_loc edge, const int *nghost, - wv_bc_func_t bcfunc, void *ctx); +gkyl_wv_apply_bc *gkyl_wv_apply_bc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_wv_eqn *eqn, + const struct gkyl_wave_geom *geom, int dir, enum gkyl_edge_loc edge, const int *nghost, + wv_bc_func_t bcfunc, void *ctx +); /** * Apply boundary condition on specified field. If the update_rng does @@ -37,8 +38,9 @@ gkyl_wv_apply_bc* gkyl_wv_apply_bc_new(const struct gkyl_rect_grid *grid, * @param update_rng Range on which BC is applied. See note above. * @param out Output array */ -void gkyl_wv_apply_bc_advance(const gkyl_wv_apply_bc *bc, double tm, - const struct gkyl_range *update_rng, struct gkyl_array *out); +void gkyl_wv_apply_bc_advance( + const gkyl_wv_apply_bc *bc, double tm, const struct gkyl_range *update_rng, struct gkyl_array *out +); /** * Apply boundary condition on specified field, however, copying the @@ -51,12 +53,14 @@ void gkyl_wv_apply_bc_advance(const gkyl_wv_apply_bc *bc, double tm, * @param inp Input array * @param buffer Output buffer in which BCs are copied */ -void gkyl_wv_apply_bc_to_buff(const gkyl_wv_apply_bc *bc, double tm, - const struct gkyl_range *update_rng, const struct gkyl_array *inp, double *buffer); +void gkyl_wv_apply_bc_to_buff( + const gkyl_wv_apply_bc *bc, double tm, const struct gkyl_range *update_rng, + const struct gkyl_array *inp, double *buffer +); /** * Delete updater. * * @param bc Updater to delete. */ -void gkyl_wv_apply_bc_release(gkyl_wv_apply_bc* bc); +void gkyl_wv_apply_bc_release(gkyl_wv_apply_bc *bc); diff --git a/moments/zero/gkyl_wv_burgers.h b/moments/zero/gkyl_wv_burgers.h index 150d745e1d..4aa859e590 100644 --- a/moments/zero/gkyl_wv_burgers.h +++ b/moments/zero/gkyl_wv_burgers.h @@ -30,8 +30,7 @@ struct gkyl_wv_burgers_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the inviscid Burgers' equation object. */ -struct gkyl_wv_eqn* -gkyl_wv_burgers_new(bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_burgers_new(bool use_gpu); /** * Create a new inviscid Burgers' equation object, from an input context struct. @@ -39,5 +38,4 @@ gkyl_wv_burgers_new(bool use_gpu); * @param inp Input context struct. * @return Pointer to the inviscid Burgers' equation object. */ -struct gkyl_wv_eqn* -gkyl_wv_burgers_inew(const struct gkyl_wv_burgers_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_burgers_inew(const struct gkyl_wv_burgers_inp *inp); diff --git a/moments/zero/gkyl_wv_burgers_priv.h b/moments/zero/gkyl_wv_burgers_priv.h index fbf628c692..4ccc7a0ec6 100644 --- a/moments/zero/gkyl_wv_burgers_priv.h +++ b/moments/zero/gkyl_wv_burgers_priv.h @@ -29,9 +29,7 @@ struct wv_burgers { * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_burgers_max_abs_speed(const double* q); +GKYL_CU_D static inline double gkyl_burgers_max_abs_speed(const double *q); /** * Compute flux vector. Assumes rotation to local coordinate system. @@ -39,9 +37,7 @@ gkyl_burgers_max_abs_speed(const double* q); * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_burgers_flux(const double* q, double* flux); +GKYL_CU_D void gkyl_burgers_flux(const double *q, double *flux); /** * Compute eigenvalues of the flux Jacobian. Assumes rotation to local coordinate system. @@ -49,9 +45,7 @@ gkyl_burgers_flux(const double* q, double* flux); * @param q Conserved variable vector. * @param flux_deriv Flux Jacobian eigenvalues in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_burgers_flux_deriv(const double* q, double* flux_deriv); +GKYL_CU_D void gkyl_burgers_flux_deriv(const double *q, double *flux_deriv); /** * Compute Riemann variables given the conserved variables. @@ -61,9 +55,8 @@ gkyl_burgers_flux_deriv(const double* q, double* flux_deriv); * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -73,9 +66,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the inviscid Burgers' equation. @@ -87,9 +79,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -burgers_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void burgers_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the inviscid Burgers' equation. @@ -101,9 +94,10 @@ burgers_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -burgers_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void burgers_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -115,10 +109,10 @@ burgers_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* s * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -130,10 +124,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -146,9 +140,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -161,9 +156,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -177,9 +173,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -193,10 +190,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -209,9 +207,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -224,9 +223,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -240,9 +240,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback), @@ -256,10 +257,11 @@ wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -270,9 +272,8 @@ qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the inviscid Burgers' equation is satisfied. @@ -281,9 +282,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -292,9 +291,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -303,9 +300,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -burgers_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +burgers_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variable vector. @@ -314,14 +310,12 @@ burgers_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* d * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -burgers_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +burgers_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free inviscid Burgers' equation object. * * @param ref Reference counter for inviscid Burgers' equation. */ -void -gkyl_burgers_free(const struct gkyl_ref_count* ref); +void gkyl_burgers_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_canonical_pb_fluid.h b/moments/zero/gkyl_wv_canonical_pb_fluid.h index cb02c59b86..d94e84e5f8 100644 --- a/moments/zero/gkyl_wv_canonical_pb_fluid.h +++ b/moments/zero/gkyl_wv_canonical_pb_fluid.h @@ -8,7 +8,7 @@ * * @return Pointer to incompressible Euler equation object. */ -struct gkyl_wv_eqn* gkyl_wv_can_pb_incompress_euler_new(); +struct gkyl_wv_eqn *gkyl_wv_can_pb_incompress_euler_new(); /** * Create a new Hasegawa-Mima equation object for use @@ -16,7 +16,7 @@ struct gkyl_wv_eqn* gkyl_wv_can_pb_incompress_euler_new(); * * @return Pointer to Hasegawa-Mima equation object. */ -struct gkyl_wv_eqn* gkyl_wv_can_pb_hasegawa_mima_new(); +struct gkyl_wv_eqn *gkyl_wv_can_pb_hasegawa_mima_new(); /** * Create a new Hasegawa-Wakatani equation object for use @@ -28,7 +28,7 @@ struct gkyl_wv_eqn* gkyl_wv_can_pb_hasegawa_mima_new(); * to find the non-zonal contribution to adiabatic coupling RHS * @return Pointer to Hasegawa Wakatani equation object. */ -struct gkyl_wv_eqn* gkyl_wv_can_pb_hasegawa_wakatani_new(double alpha, bool is_modified); +struct gkyl_wv_eqn *gkyl_wv_can_pb_hasegawa_wakatani_new(double alpha, bool is_modified); /** * Get adiabatic coupling parameter @@ -36,7 +36,7 @@ struct gkyl_wv_eqn* gkyl_wv_can_pb_hasegawa_wakatani_new(double alpha, bool is_m * @param wv Hasegawa-Wakatani equation object * @return Adiabaticity parameter for adiabatic coupling of vorticity and density. */ -double gkyl_wv_can_pb_hasegawa_wakatani_alpha(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_can_pb_hasegawa_wakatani_alpha(const struct gkyl_wv_eqn *eqn); /** * Determine if Hasegawa-Wakatani system is modified or not. @@ -44,4 +44,4 @@ double gkyl_wv_can_pb_hasegawa_wakatani_alpha(const struct gkyl_wv_eqn* eqn); * @param wv Hasegawa-Wakatani equation object * @return Boolean is_modified for whether the Hasegawa-Wakatani system is modified. */ -bool gkyl_wv_can_pb_hasegawa_wakatani_is_modified(const struct gkyl_wv_eqn* eqn); +bool gkyl_wv_can_pb_hasegawa_wakatani_is_modified(const struct gkyl_wv_eqn *eqn); diff --git a/moments/zero/gkyl_wv_canonical_pb_fluid_priv.h b/moments/zero/gkyl_wv_canonical_pb_fluid_priv.h index 29989d4b4d..9e1ee03733 100644 --- a/moments/zero/gkyl_wv_canonical_pb_fluid_priv.h +++ b/moments/zero/gkyl_wv_canonical_pb_fluid_priv.h @@ -34,7 +34,8 @@ void gkyl_wv_can_pb_hasegawa_mima_free(const struct gkyl_ref_count *ref); struct wv_can_pb_hasegawa_wakatani { struct gkyl_wv_eqn eqn; // base object double alpha; // Adiabaticity parameter for adiabatic coupling of vorticity and density. - bool is_modified; // is_modified Boolean parameter for if we are doing the modified Hasegawa-Wakatani + bool + is_modified; // is_modified Boolean parameter for if we are doing the modified Hasegawa-Wakatani }; /** diff --git a/moments/zero/gkyl_wv_coldfluid.h b/moments/zero/gkyl_wv_coldfluid.h index 2354ee2e8b..f5ce01274e 100644 --- a/moments/zero/gkyl_wv_coldfluid.h +++ b/moments/zero/gkyl_wv_coldfluid.h @@ -7,4 +7,4 @@ * * @return Pointer to cold-fluid equation object. */ -struct gkyl_wv_eqn* gkyl_wv_coldfluid_new(void); +struct gkyl_wv_eqn *gkyl_wv_coldfluid_new(void); diff --git a/moments/zero/gkyl_wv_embed_geo.h b/moments/zero/gkyl_wv_embed_geo.h index 1a0de50849..196b96225b 100644 --- a/moments/zero/gkyl_wv_embed_geo.h +++ b/moments/zero/gkyl_wv_embed_geo.h @@ -8,12 +8,12 @@ #include // BC types in this updater. -enum gkyl_embed_type { - GKYL_EMBED_ABSORB = 0, +enum gkyl_embed_type { + GKYL_EMBED_ABSORB = 0, GKYL_EMBED_REFLECT, GKYL_EMBED_COPY_B, GKYL_EMBED_PEC, - GKYL_EMBED_FUNC, + GKYL_EMBED_FUNC }; // Object type @@ -34,11 +34,14 @@ struct gkyl_wv_embed_geo { * @param ctx Context to pass to bcfunc. * @return New updater pointer. */ -gkyl_wv_embed_geo* gkyl_wv_embed_geo_new(enum gkyl_embed_type type, void *mask_func, - wv_embed_func_t embed_func, void *ctx); +gkyl_wv_embed_geo *gkyl_wv_embed_geo_new( + enum gkyl_embed_type type, void *mask_func, wv_embed_func_t embed_func, void *ctx +); -void gkyl_wv_embed_geo_new_mask(struct gkyl_wv_embed_geo *geo, - struct gkyl_rect_grid *grid, struct gkyl_range *rng, struct gkyl_array *mask); +void gkyl_wv_embed_geo_new_mask( + struct gkyl_wv_embed_geo *geo, struct gkyl_rect_grid *grid, struct gkyl_range *rng, + struct gkyl_array *mask +); /** * Delete structure. diff --git a/moments/zero/gkyl_wv_eqn.h b/moments/zero/gkyl_wv_eqn.h index 89ec82ffd4..b95f33d31b 100644 --- a/moments/zero/gkyl_wv_eqn.h +++ b/moments/zero/gkyl_wv_eqn.h @@ -12,19 +12,22 @@ enum gkyl_wv_flux_type { GKYL_WV_HIGH_ORDER_FLUX, GKYL_WV_LOW_ORDER_FLUX }; struct gkyl_wv_eqn; // Function pointer to compute waves from RP solver -typedef double (*wv_waves_t)(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *delta, const double *ql, const double *qr, double phil, double phir, - double *waves, double *speeds); +typedef double (*wv_waves_t)( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, double phil, double phir, double *waves, double *speeds +); // Function pointer to compute q-fluctuations from waves -typedef void (*wv_qfluct_t)(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *ql, const double *qr, double phil, double phir, const double *waves, const double *speeds, - double *amdq, double *apdq); +typedef void (*wv_qfluct_t)( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + double phil, double phir, const double *waves, const double *speeds, double *amdq, double *apdq +); // Function pointer to compute jump in flux. Returns absolute maximum // wave-speed -typedef double (*wv_flux_jump_t)(const struct gkyl_wv_eqn *eqn, - const double *ql, const double *qr, double *flux_jump); +typedef double (*wv_flux_jump_t)( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump +); // Function pointer to check if invariant domain is preserved typedef bool (*wv_check_inv)(const struct gkyl_wv_eqn *eqn, const double *q); @@ -34,31 +37,36 @@ typedef double (*wv_max_speed_t)(const struct gkyl_wv_eqn *eqn, const double *q) // Function pointer to rotate conserved variables to local // tangent-normal frame: tau1 X tau2 = norm -typedef void (*wv_rotate_to_local)(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* qglobal, double* qlocal); +typedef void (*wv_rotate_to_local)( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *qglobal, double *qlocal +); // Function pointer to rotate conserved variables to local // tangent-normal frame: tau1 X tau2 = norm -typedef void (*wv_rotate_to_global)(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* qlocal, double* qglobal); +typedef void (*wv_rotate_to_global)( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *qlocal, double *qglobal +); // Function pointer to convert conserved variables to Riemann // variables, given an input state 'qstate' -typedef void (*wv_cons_to_riem)(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *qin, double *wout); +typedef void (*wv_cons_to_riem)( + const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout +); // Function pointer to convert Riemann variables back to conserved // variables, given an input state 'qstate' -typedef void (*wv_riem_to_cons)(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *win, double *qout); +typedef void (*wv_riem_to_cons)( + const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout +); // Function pointer to compute diagnostic variables from conserved // variables -typedef void (*wv_cons_to_diag)(const struct gkyl_wv_eqn *eqn, - const double *qin, double *diag); - +typedef void (*wv_cons_to_diag)(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); + // Function pointer to compute the forcing/source term vector. -typedef void (*wv_source_func_t)(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +typedef void (*wv_source_func_t)(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); struct gkyl_wv_eqn { enum gkyl_eqn_type type; // Equation type @@ -89,7 +97,7 @@ struct gkyl_wv_eqn { struct gkyl_wv_embed_geo *embed_geo; - uint32_t flags; + uint32_t flags; struct gkyl_ref_count ref_count; // reference count struct gkyl_wv_eqn *on_dev; // pointer to itself or device data }; @@ -116,12 +124,12 @@ struct gkyl_wv_eqn *gkyl_wv_eqn_acquire(const struct gkyl_wv_eqn *eqn); * eqn systems the conserved vara are the diagnostics one wishes to * compute. */ -GKYL_CU_DH -static inline void -gkyl_default_cons_to_diag(const struct gkyl_wv_eqn *eqn, - const double *qin, double *diag) +GKYL_CU_DH static inline void +gkyl_default_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { - for (int i=0; inum_equations; ++i) diag[i] = qin[i]; + for (int i = 0; i < eqn->num_equations; ++i) { + diag[i] = qin[i]; + } } /** @@ -132,8 +140,7 @@ gkyl_default_cons_to_diag(const struct gkyl_wv_eqn *eqn, * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void +GKYL_CU_DH static inline void gkyl_default_source_func(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < eqn->num_equations; i++) { @@ -155,11 +162,10 @@ gkyl_default_source_func(const struct gkyl_wv_eqn *eqn, const double *qin, doubl * @param speeds On output wave speeds[num_wave] * @return Maximum wave speed. */ -GKYL_CU_DH -static inline double -gkyl_wv_eqn_waves(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *delta, const double *ql, const double *qr, const double phil, const double phir, - double *waves, double *speeds) +GKYL_CU_DH static inline double gkyl_wv_eqn_waves( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *speeds +) { return eqn->waves_func(eqn, type, delta, ql, qr, phil, phir, waves, speeds); } @@ -178,11 +184,11 @@ gkyl_wv_eqn_waves(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, * @param amdq On output, the left-going fluctuations. * @param apdq On output, the right-going fluctuations. */ -GKYL_CU_DH -static inline void -gkyl_wv_eqn_qfluct(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *ql, const double *qr, const double phil, const double phir, const double *waves, const double *speeds, - double *amdq, double *apdq) +GKYL_CU_DH static inline void gkyl_wv_eqn_qfluct( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *speeds, double *amdq, + double *apdq +) { eqn->qfluct_func(eqn, type, ql, qr, phil, phir, waves, speeds, amdq, apdq); } @@ -191,11 +197,11 @@ gkyl_wv_eqn_qfluct(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, * See signature for gkyl_wv_eqn_qfluct. This function computes the * fluctuations using f-waves rather than q-waves. */ -GKYL_CU_DH -static inline void -gkyl_wv_eqn_ffluct(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *ql, const double *qr, const double phil, const double phir, const double *waves, const double *speeds, - double *amdq, double *apdq) +GKYL_CU_DH static inline void gkyl_wv_eqn_ffluct( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *speeds, double *amdq, + double *apdq +) { eqn->ffluct_func(eqn, type, ql, qr, phil, phir, waves, speeds, amdq, apdq); } @@ -209,10 +215,9 @@ gkyl_wv_eqn_ffluct(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, * @param flux_jump Jump in flux (F(qr)-F(ql)) * @return Maximum wave speed for states qr and ql. */ -GKYL_CU_DH -static inline double -gkyl_wv_eqn_flux_jump(const struct gkyl_wv_eqn *eqn, - const double *ql, const double *qr, double *flux_jump) +GKYL_CU_DH static inline double gkyl_wv_eqn_flux_jump( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump +) { return eqn->flux_jump(eqn, ql, qr, flux_jump); } @@ -224,9 +229,7 @@ gkyl_wv_eqn_flux_jump(const struct gkyl_wv_eqn *eqn, * @param q Conserved variables * @return boolean (true if invariant domain is satisfied, false if not) */ -GKYL_CU_DH -static inline bool -gkyl_wv_eqn_check_inv(const struct gkyl_wv_eqn *eqn, const double *q) +GKYL_CU_DH static inline bool gkyl_wv_eqn_check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { return eqn->check_inv_func(eqn, q); } @@ -241,8 +244,7 @@ gkyl_wv_eqn_check_inv(const struct gkyl_wv_eqn *eqn, const double *q) * @param q Conserved variables * @return maximum wave-speed in direction 'dir' */ -GKYL_CU_DH -static inline double +GKYL_CU_DH static inline double gkyl_wv_eqn_max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { return eqn->max_speed_func(eqn, q); @@ -258,11 +260,10 @@ gkyl_wv_eqn_max_speed(const struct gkyl_wv_eqn *eqn, const double *q) * @param qglobal State vector in global coordinates * @param qlocal State vector in local coordinates */ -GKYL_CU_DH -static inline void -gkyl_wv_eqn_rotate_to_local(const struct gkyl_wv_eqn* eqn, - const double *tau1, const double *tau2, const double *norm, - const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal) +GKYL_CU_DH static inline void gkyl_wv_eqn_rotate_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { eqn->rotate_to_local_func(eqn, tau1, tau2, norm, qglobal, qlocal); } @@ -277,11 +278,10 @@ gkyl_wv_eqn_rotate_to_local(const struct gkyl_wv_eqn* eqn, * @param qlocal State vector in local coordinates * @param qglobal State vector in local coordinates */ -GKYL_CU_DH -static inline void -gkyl_wv_eqn_rotate_to_global(const struct gkyl_wv_eqn* eqn, - const double *tau1, const double *tau2, const double *norm, - const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal) +GKYL_CU_DH static inline void gkyl_wv_eqn_rotate_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { eqn->rotate_to_global_func(eqn, tau1, tau2, norm, qlocal, qglobal); } @@ -293,9 +293,8 @@ gkyl_wv_eqn_rotate_to_global(const struct gkyl_wv_eqn* eqn, * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gkyl_wv_eqn_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +GKYL_CU_DH static inline void +gkyl_wv_eqn_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { eqn->source_func(eqn, qin, sout); } @@ -305,4 +304,4 @@ gkyl_wv_eqn_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sou * * @param eqn Equation object to delete. */ -void gkyl_wv_eqn_release(const struct gkyl_wv_eqn* eqn); +void gkyl_wv_eqn_release(const struct gkyl_wv_eqn *eqn); diff --git a/moments/zero/gkyl_wv_euler.h b/moments/zero/gkyl_wv_euler.h index 69fe6f371c..8087229798 100644 --- a/moments/zero/gkyl_wv_euler.h +++ b/moments/zero/gkyl_wv_euler.h @@ -33,7 +33,7 @@ struct gkyl_wv_eqn *gkyl_wv_euler_new(double gas_gamma, bool use_gpu); * @param inp Input parameters * @return Pointer to Euler equation object. */ -struct gkyl_wv_eqn* gkyl_wv_euler_inew(const struct gkyl_wv_euler_inp *inp); +struct gkyl_wv_eqn *gkyl_wv_euler_inew(const struct gkyl_wv_euler_inp *inp); /** * Create a new Euler equation object that lives on NV-GPU. @@ -41,7 +41,7 @@ struct gkyl_wv_eqn* gkyl_wv_euler_inew(const struct gkyl_wv_euler_inp *inp); * @param inp Input parameters * @return Pointer to Euler equation object. */ -struct gkyl_wv_eqn* gkyl_wv_euler_cu_dev_inew(const struct gkyl_wv_euler_inp *inp); +struct gkyl_wv_eqn *gkyl_wv_euler_cu_dev_inew(const struct gkyl_wv_euler_inp *inp); /** * Get gas adiabatic constant. @@ -49,4 +49,4 @@ struct gkyl_wv_eqn* gkyl_wv_euler_cu_dev_inew(const struct gkyl_wv_euler_inp *in * @param wv Euler equation object * @return Gas adiabatic constant */ -double gkyl_wv_euler_gas_gamma(const struct gkyl_wv_eqn* wv); +double gkyl_wv_euler_gas_gamma(const struct gkyl_wv_eqn *wv); diff --git a/moments/zero/gkyl_wv_euler_mixture.h b/moments/zero/gkyl_wv_euler_mixture.h index 6dd8b8effc..fc716a44f4 100644 --- a/moments/zero/gkyl_wv_euler_mixture.h +++ b/moments/zero/gkyl_wv_euler_mixture.h @@ -5,13 +5,13 @@ // Type of Riemann-solver to use: enum gkyl_wv_euler_mixture_rp { WV_EULER_MIXTURE_RP_LAX = 0, // Default (Lax fluxes). - WV_EULER_MIXTURE_RP_ROE, + WV_EULER_MIXTURE_RP_ROE }; // Input context, packaged as a struct. struct gkyl_wv_euler_mixture_inp { int num_species; // Number of distinct species in mixture. - double* gas_gamma_s; // Adiabatic indices for each species in mixture. + double *gas_gamma_s; // Adiabatic indices for each species in mixture. enum gkyl_wv_euler_mixture_rp rp_type; // Type of Riemann-solver to use. bool use_gpu; // Whether the wave equation object is on the host (false) or the device (true). @@ -25,8 +25,7 @@ struct gkyl_wv_euler_mixture_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the Euler mixture equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_euler_mixture_new(int num_species, double* gas_gamma_s, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_euler_mixture_new(int num_species, double *gas_gamma_s, bool use_gpu); /** * Create a new Euler mixture equations object, from an input context struct. @@ -34,8 +33,7 @@ gkyl_wv_euler_mixture_new(int num_species, double* gas_gamma_s, bool use_gpu); * @param inp Input context struct. * @return Pointer to the Euler mixture equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_euler_mixture_inew(const struct gkyl_wv_euler_mixture_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_euler_mixture_inew(const struct gkyl_wv_euler_mixture_inp *inp); /** * Get number of distinct species in mixture. @@ -43,8 +41,7 @@ gkyl_wv_euler_mixture_inew(const struct gkyl_wv_euler_mixture_inp* inp); * @param wv Euler mixture equations object. * @return Number of distinct species in mixture. */ -int -gkyl_wv_euler_mixture_num_species(const struct gkyl_wv_eqn* wv); +int gkyl_wv_euler_mixture_num_species(const struct gkyl_wv_eqn *wv); /** * Get adiabatic indices for each species in mixture. @@ -52,5 +49,4 @@ gkyl_wv_euler_mixture_num_species(const struct gkyl_wv_eqn* wv); * @param wv Euler mixture equations object. * @return Adiabatic indices for each species in mixture. */ -double* -gkyl_wv_euler_mixture_gas_gamma_s(const struct gkyl_wv_eqn* wv); \ No newline at end of file +double *gkyl_wv_euler_mixture_gas_gamma_s(const struct gkyl_wv_eqn *wv); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_euler_mixture_priv.h b/moments/zero/gkyl_wv_euler_mixture_priv.h index 2b133a7428..58b2496d6c 100644 --- a/moments/zero/gkyl_wv_euler_mixture_priv.h +++ b/moments/zero/gkyl_wv_euler_mixture_priv.h @@ -12,7 +12,7 @@ struct wv_euler_mixture { struct gkyl_wv_eqn eqn; // Base equation object. int num_species; // Number of distinct species in mixture. - double* gas_gamma_s; // Adiabatic indices for each species in mixture. + double *gas_gamma_s; // Adiabatic indices for each species in mixture. }; /** @@ -23,9 +23,8 @@ struct wv_euler_mixture { * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void -gkyl_euler_mixture_prim_vars(int num_species, double* gas_gamma_s, const double* q, double* v); +GKYL_CU_D void +gkyl_euler_mixture_prim_vars(int num_species, double *gas_gamma_s, const double *q, double *v); /** * Compute maximum absolute wave speed. @@ -35,9 +34,8 @@ gkyl_euler_mixture_prim_vars(int num_species, double* gas_gamma_s, const double* * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_euler_mixture_max_abs_speed(int num_species, double* gas_gamma_s, const double* q); +GKYL_CU_D static inline double +gkyl_euler_mixture_max_abs_speed(int num_species, double *gas_gamma_s, const double *q); /** * Compute flux vector. Assumes rotation to local coordinate system. @@ -47,9 +45,8 @@ gkyl_euler_mixture_max_abs_speed(int num_species, double* gas_gamma_s, const dou * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_euler_mixture_flux(int num_species, double* gas_gamma_s, const double* q, double* flux); +GKYL_CU_D void +gkyl_euler_mixture_flux(int num_species, double *gas_gamma_s, const double *q, double *flux); /** * Compute Riemann variables given the conserved variables. @@ -59,9 +56,8 @@ gkyl_euler_mixture_flux(int num_species, double* gas_gamma_s, const double* q, d * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -71,9 +67,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the Euler mixture equations. @@ -85,9 +80,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -euler_mixture_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void euler_mixture_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the Euler mixture equations. @@ -99,9 +95,10 @@ euler_mixture_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -euler_mixture_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void euler_mixture_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -113,10 +110,10 @@ euler_mixture_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const dou * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -128,10 +125,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -144,9 +141,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -159,9 +157,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -175,9 +174,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -191,10 +191,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -207,9 +208,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -222,9 +224,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -238,9 +241,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe_l( + const struct gkyl_wv_eqn *, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback). @@ -254,10 +258,11 @@ wave_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe_l( + const struct gkyl_wv_eqn *, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -268,9 +273,8 @@ qfluct_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const doubl * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the Euler mixture equations is satisfied. @@ -279,9 +283,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -290,9 +292,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -301,9 +301,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -euler_mixture_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +euler_mixture_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variable vector. @@ -312,13 +311,12 @@ euler_mixture_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, dou * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -euler_mixture_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +euler_mixture_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free Euler mixture equations object. * * @param ref Reference counter for Euler mixture equations. */ -void gkyl_euler_mixture_free(const struct gkyl_ref_count* ref); +void gkyl_euler_mixture_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_euler_priv.h b/moments/zero/gkyl_wv_euler_priv.h index 6726a1948d..3d2bcbb317 100644 --- a/moments/zero/gkyl_wv_euler_priv.h +++ b/moments/zero/gkyl_wv_euler_priv.h @@ -28,11 +28,9 @@ void gkyl_euler_free(const struct gkyl_ref_count *ref); * @param gas_gamma Gas adiabatic constant * @param q Conserved variables */ -GKYL_CU_DH -static inline double -gkyl_euler_pressure(double gas_gamma, const double q[5]) +GKYL_CU_DH static inline double gkyl_euler_pressure(double gas_gamma, const double q[5]) { - return (gas_gamma-1)*(q[4]-0.5*(q[1]*q[1]+q[2]*q[2]+q[3]*q[3])/q[0]); + return (gas_gamma - 1) * (q[4] - 0.5 * (q[1] * q[1] + q[2] * q[2] + q[3] * q[3]) / q[0]); } /** @@ -42,14 +40,12 @@ gkyl_euler_pressure(double gas_gamma, const double q[5]) * @param q Conserved variables * @param v Primitive variables (output) */ -GKYL_CU_DH -static inline void -gkyl_euler_prim_vars(double gas_gamma, const double q[5], double v[5]) +GKYL_CU_DH static inline void gkyl_euler_prim_vars(double gas_gamma, const double q[5], double v[5]) { v[0] = q[0]; - v[1] = q[1]/q[0]; - v[2] = q[2]/q[0]; - v[3] = q[3]/q[0]; + v[1] = q[1] / q[0]; + v[2] = q[2] / q[0]; + v[3] = q[3] / q[0]; v[4] = gkyl_euler_pressure(gas_gamma, q); } @@ -60,15 +56,13 @@ gkyl_euler_prim_vars(double gas_gamma, const double q[5], double v[5]) * @param q Conserved variables * @return Maximum absolute speed for given q */ -GKYL_CU_DH -static inline double -gkyl_euler_max_abs_speed(double gas_gamma, const double q[5]) +GKYL_CU_DH static inline double gkyl_euler_max_abs_speed(double gas_gamma, const double q[5]) { double v[5] = {0.0}; gkyl_euler_prim_vars(gas_gamma, q, v); - double u2 = sqrt(v[1]*v[1] + v[2]*v[2] + v[3]*v[3]); + double u2 = sqrt(v[1] * v[1] + v[2] * v[2] + v[3] * v[3]); double pr = v[4]; - return fabs(u2) + sqrt(gas_gamma*pr/q[0]); + return fabs(u2) + sqrt(gas_gamma * pr / q[0]); } /** @@ -78,42 +72,39 @@ gkyl_euler_max_abs_speed(double gas_gamma, const double q[5]) * @param Conserved variables * @param flux On output, the flux in direction 'dir' */ -GKYL_CU_DH -static void -gkyl_euler_flux(double gas_gamma, const double q[5], double flux[5]) +GKYL_CU_DH static void gkyl_euler_flux(double gas_gamma, const double q[5], double flux[5]) { - double pr = gkyl_euler_pressure(gas_gamma, q), u = q[1]/q[0]; + double pr = gkyl_euler_pressure(gas_gamma, q), u = q[1] / q[0]; flux[0] = q[1]; // rho*u - flux[1] = q[1]*u + pr; // rho*u*u + pr - flux[2] = q[2]*u; // rho*v*u - flux[3] = q[3]*u; // rho*w*u - flux[4] = (q[4]+pr)*u; // (E+p)*u + flux[1] = q[1] * u + pr; // rho*u*u + pr + flux[2] = q[2] * u; // rho*v*u + flux[3] = q[3] * u; // rho*w*u + flux[4] = (q[4] + pr) * u; // (E+p)*u } -GKYL_CU_DH -static inline void -cons_to_riem(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *qin, double *wout) +GKYL_CU_DH static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: this should use proper L matrix - for (int i=0; i<5; ++i) + for (int i = 0; i < 5; ++i) { wout[i] = qin[i]; + } } -GKYL_CU_DH -static inline void -riem_to_cons(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *win, double *qout) +GKYL_CU_DH static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: this should use proper L matrix - for (int i=0; i<5; ++i) + for (int i = 0; i < 5; ++i) { qout[i] = win[i]; + } } // Euler perfectly reflecting wall -GKYL_CU_DH -static void -euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double *skin, double * GKYL_RESTRICT ghost, void *ctx) +GKYL_CU_DH static void euler_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { // copy density and pressure ghost[0] = skin[0]; @@ -126,9 +117,10 @@ euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double *skin, } // Euler no-slip wall -GKYL_CU_DH -static void -euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double *skin, double * GKYL_RESTRICT ghost, void *ctx) +GKYL_CU_DH static void euler_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { // copy density and pressure ghost[0] = skin[0]; @@ -140,33 +132,31 @@ euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double *ski ghost[3] = -skin[3]; } -GKYL_CU_DH -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qglobal, double* GKYL_RESTRICT qlocal) +GKYL_CU_DH static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; - qlocal[1] = qglobal[1]*norm[0] + qglobal[2]*norm[1] + qglobal[3]*norm[2]; - qlocal[2] = qglobal[1]*tau1[0] + qglobal[2]*tau1[1] + qglobal[3]*tau1[2]; - qlocal[3] = qglobal[1]*tau2[0] + qglobal[2]*tau2[1] + qglobal[3]*tau2[2]; + qlocal[1] = qglobal[1] * norm[0] + qglobal[2] * norm[1] + qglobal[3] * norm[2]; + qlocal[2] = qglobal[1] * tau1[0] + qglobal[2] * tau1[1] + qglobal[3] * tau1[2]; + qlocal[3] = qglobal[1] * tau2[0] + qglobal[2] * tau2[1] + qglobal[3] * tau2[2]; qlocal[4] = qglobal[4]; } -GKYL_CU_DH -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qlocal, double* GKYL_RESTRICT qglobal) +GKYL_CU_DH static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; - qglobal[1] = qlocal[1]*norm[0] + qlocal[2]*tau1[0] + qlocal[3]*tau2[0]; - qglobal[2] = qlocal[1]*norm[1] + qlocal[2]*tau1[1] + qlocal[3]*tau2[1]; - qglobal[3] = qlocal[1]*norm[2] + qlocal[2]*tau1[2] + qlocal[3]*tau2[2]; + qglobal[1] = qlocal[1] * norm[0] + qlocal[2] * tau1[0] + qlocal[3] * tau2[0]; + qglobal[2] = qlocal[1] * norm[1] + qlocal[2] * tau1[1] + qlocal[3] * tau2[1]; + qglobal[3] = qlocal[1] * norm[2] + qlocal[2] * tau1[2] + qlocal[3] * tau2[2]; qglobal[4] = qlocal[4]; } -GKYL_CU_DH -static void -wave_embed_absorb(const double *q, double *qphi, double *delta, void *ctx) +GKYL_CU_DH static void wave_embed_absorb(const double *q, double *qphi, double *delta, void *ctx) { qphi[0] = 0.0; qphi[1] = 0.0; @@ -175,9 +165,7 @@ wave_embed_absorb(const double *q, double *qphi, double *delta, void *ctx) qphi[4] = 0.0; } -GKYL_CU_DH -static void -wave_embed_reflect(const double *q, double *qphi, double *delta, void *ctx) +GKYL_CU_DH static void wave_embed_reflect(const double *q, double *qphi, double *delta, void *ctx) { qphi[0] = q[0]; qphi[1] = -q[1]; @@ -186,11 +174,10 @@ wave_embed_reflect(const double *q, double *qphi, double *delta, void *ctx) qphi[4] = q[4]; } -GKYL_CU_DH -static double -wave_embedded(const struct gkyl_wv_eqn *eqn, - const double *delta, const double *ql, const double *qr, const double phil, - const double phir, double *waves, double *s) +GKYL_CU_DH static double wave_embedded( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + const double phil, const double phir, double *waves, double *s +) { const struct wv_euler *euler = container_of(eqn, struct wv_euler, eqn); double gas_gamma = euler->gas_gamma; @@ -203,59 +190,59 @@ wave_embedded(const struct gkyl_wv_eqn *eqn, double fl[5], fr[5] = {0.0}; if ((phil < 0.0) && (phir > 0.0)) { double rhor = qr[0]; - double ur = qr[1]/qr[0]; + double ur = qr[1] / qr[0]; double pr = gkyl_euler_pressure(gas_gamma, qr); - double sr = fabs(ur) + sqrt(gas_gamma*pr/rhor); + double sr = fabs(ur) + sqrt(gas_gamma * pr / rhor); amax = sr; - + eqn->embed_geo->embed_func(qr, qphi, deltaphi, eqn->embed_geo->ctx); gkyl_euler_flux(gas_gamma, qphi, fl); gkyl_euler_flux(gas_gamma, qr, fr); double *w0 = &waves[0], *w1 = &waves[5]; - for (int i=0; i<5; ++i) { - w1[i] = 0.5*((qr[i]-qphi[i]) + (fr[i]-fl[i])/amax); + for (int i = 0; i < 5; ++i) { + w1[i] = 0.5 * ((qr[i] - qphi[i]) + (fr[i] - fl[i]) / amax); } } - + if ((phir < 0.0) && (phil > 0.0)) { double rhol = ql[0]; - double ul = ql[1]/ql[0]; + double ul = ql[1] / ql[0]; double pl = gkyl_euler_pressure(gas_gamma, ql); - double sl = fabs(ul) + sqrt(gas_gamma*pl/rhol); + double sl = fabs(ul) + sqrt(gas_gamma * pl / rhol); amax = sl; - + eqn->embed_geo->embed_func(ql, qphi, deltaphi, eqn->embed_geo->ctx); gkyl_euler_flux(gas_gamma, ql, fl); gkyl_euler_flux(gas_gamma, qphi, fr); - + double *w0 = &waves[0], *w1 = &waves[5]; - for (int i=0; i<5; ++i) { - w0[i] = 0.5*((qphi[i]-ql[i]) - (fr[i]-fl[i])/amax); + for (int i = 0; i < 5; ++i) { + w0[i] = 0.5 * ((qphi[i] - ql[i]) - (fr[i] - fl[i]) / amax); } } s[0] = -amax; s[1] = amax; - + return s[1]; } // Waves and speeds using Lax fluxes -GKYL_CU_DH -static double -wave_lax(const struct gkyl_wv_eqn *eqn, - const double *delta, const double *ql, const double *qr, double *waves, double *s) +GKYL_CU_DH static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_euler *euler = container_of(eqn, struct wv_euler, eqn); double gas_gamma = euler->gas_gamma; double rhol = ql[0], rhor = qr[0]; - double ul = ql[1]/ql[0], ur = qr[1]/qr[0]; + double ul = ql[1] / ql[0], ur = qr[1] / qr[0]; double pl = gkyl_euler_pressure(gas_gamma, ql), pr = gkyl_euler_pressure(gas_gamma, qr); - double sl = fabs(ul) + sqrt(gas_gamma*pl/rhol), sr = fabs(ur) + sqrt(gas_gamma*pr/rhor); + double sl = fabs(ul) + sqrt(gas_gamma * pl / rhol), sr = fabs(ur) + sqrt(gas_gamma * pr / rhor); double amax = fmax(sl, sr); double fl[5], fr[5]; @@ -263,61 +250,57 @@ wave_lax(const struct gkyl_wv_eqn *eqn, gkyl_euler_flux(gas_gamma, qr, fr); double *w0 = &waves[0], *w1 = &waves[5]; - for (int i=0; i<5; ++i) { - w0[i] = 0.5*((qr[i]-ql[i]) - (fr[i]-fl[i])/amax); - w1[i] = 0.5*((qr[i]-ql[i]) + (fr[i]-fl[i])/amax); + for (int i = 0; i < 5; ++i) { + w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr[i] - fl[i]) / amax); + w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr[i] - fl[i]) / amax); } s[0] = -amax; s[1] = amax; - + return s[1]; } -GKYL_CU_DH -static void -qfluct_lax(const struct gkyl_wv_eqn *eqn, - const double *ql, const double *qr, const double *waves, const double *s, - double *amdq, double *apdq) +GKYL_CU_DH static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[5]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]); - for (int i=0; i<5; ++i) { - amdq[i] = s0m*w0[i] + s1m*w1[i]; - apdq[i] = s0p*w0[i] + s1p*w1[i]; + for (int i = 0; i < 5; ++i) { + amdq[i] = s0m * w0[i] + s1m * w1[i]; + apdq[i] = s0p * w0[i] + s1p * w1[i]; } } -GKYL_CU_DH -static double -wave_lax_l(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *delta, const double *ql, const double *qr, double phil, - double phir, double *waves, double *s) +GKYL_CU_DH static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, double phil, double phir, double *waves, double *s +) { - if ((phil < 0.0) || (phir < 0.0)) + if ((phil < 0.0) || (phir < 0.0)) { return wave_embedded(eqn, delta, ql, qr, phil, phir, waves, s); - else + } else { return wave_lax(eqn, delta, ql, qr, waves, s); + } } -GKYL_CU_DH -static void -qfluct_lax_l(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *ql, const double *qr, double phil, - double phir, const double *waves, const double *s, - double *amdq, double *apdq) +GKYL_CU_DH static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + double phil, double phir, const double *waves, const double *s, double *amdq, double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } // project column vector delta onto the right eigenvectors of the flux Jacobian // evaluated at avg = {u, v, w, enth} -GKYL_CU_DH -static double -proj_onto_euler_eigvect(const struct gkyl_wv_eqn *eqn, - const double *delta, const double *avg, double *waves, double *s) +GKYL_CU_DH static double proj_onto_euler_eigvect( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *avg, double *waves, double *s +) { const struct wv_euler *euler = container_of(eqn, struct wv_euler, eqn); double gas_gamma = euler->gas_gamma; @@ -327,53 +310,51 @@ proj_onto_euler_eigvect(const struct gkyl_wv_eqn *eqn, // See http://ammar-hakim.org/sj/euler-eigensystem.html for notation // and meaning of these terms - double q2 = u*u+v*v+w*w; - double aa2 = g1*(enth-0.5*q2); + double q2 = u * u + v * v + w * w; + double aa2 = g1 * (enth - 0.5 * q2); double a = sqrt(aa2); - double g1a2 = g1/aa2, euv = enth-q2; + double g1a2 = g1 / aa2, euv = enth - q2; // Compute projections of jump - double a4 = g1a2*(euv*delta[0] + u*delta[1] + v*delta[2] + w*delta[3] - delta[4]); - double a2 = delta[2] - v*delta[0]; - double a3 = delta[3] - w*delta[0]; - double a5 = 0.5*(delta[1] + (a-u)*delta[0] - a*a4)/a; + double a4 = g1a2 * (euv * delta[0] + u * delta[1] + v * delta[2] + w * delta[3] - delta[4]); + double a2 = delta[2] - v * delta[0]; + double a3 = delta[3] - w * delta[0]; + double a5 = 0.5 * (delta[1] + (a - u) * delta[0] - a * a4) / a; double a1 = delta[0] - a4 - a5; double *wv; // Wave 1: eigenvalue is u-c wv = &waves[0]; wv[0] = a1; - wv[1] = a1*(u-a); - wv[2] = a1*v; - wv[3] = a1*w; - wv[4] = a1*(enth-u*a); - s[0] = u-a; + wv[1] = a1 * (u - a); + wv[2] = a1 * v; + wv[3] = a1 * w; + wv[4] = a1 * (enth - u * a); + s[0] = u - a; // Wave 2: eigenvalue is u, u, u three waves are lumped into one wv = &waves[5]; wv[0] = a4; - wv[1] = a4*u; - wv[2] = a4*v + a2; - wv[3] = a4*w + a3; - wv[4] = a4*0.5*q2 + a2*v + a3*w; + wv[1] = a4 * u; + wv[2] = a4 * v + a2; + wv[3] = a4 * w + a3; + wv[4] = a4 * 0.5 * q2 + a2 * v + a3 * w; s[1] = u; // Wave 3: eigenvalue is u+c wv = &waves[10]; wv[0] = a5; - wv[1] = a5*(u+a); - wv[2] = a5*v; - wv[3] = a5*w; - wv[4] = a5*(enth+u*a); - s[2] = u+a; - - return fabs(u)+a; + wv[1] = a5 * (u + a); + wv[2] = a5 * v; + wv[3] = a5 * w; + wv[4] = a5 * (enth + u * a); + s[2] = u + a; + + return fabs(u) + a; } -GKYL_CU_DH -inline static void -roe_avg(const struct gkyl_wv_eqn *eqn, const double *ql, - const double *qr, double *avg) +GKYL_CU_DH inline static void +roe_avg(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *avg) { const struct wv_euler *euler = container_of(eqn, struct wv_euler, eqn); double gas_gamma = euler->gas_gamma; @@ -383,88 +364,89 @@ roe_avg(const struct gkyl_wv_eqn *eqn, const double *ql, // Roe averages: see Roe's original 1981 paper or LeVeque book double srrhol = sqrt(rhol), srrhor = sqrt(rhor); - double ravgl1 = 1/srrhol, ravgr1 = 1/srrhor; - double ravg2 = 1/(srrhol+srrhor); - double u = (ql[1]*ravgl1 + qr[1]*ravgr1)*ravg2; - double v = (ql[2]*ravgl1 + qr[2]*ravgr1)*ravg2; - double w = (ql[3]*ravgl1 + qr[3]*ravgr1)*ravg2; - double enth = ((ql[4]+pl)*ravgl1 + (qr[4]+pr)*ravgr1)*ravg2; + double ravgl1 = 1 / srrhol, ravgr1 = 1 / srrhor; + double ravg2 = 1 / (srrhol + srrhor); + double u = (ql[1] * ravgl1 + qr[1] * ravgr1) * ravg2; + double v = (ql[2] * ravgl1 + qr[2] * ravgr1) * ravg2; + double w = (ql[3] * ravgl1 + qr[3] * ravgr1) * ravg2; + double enth = ((ql[4] + pl) * ravgl1 + (qr[4] + pr) * ravgr1) * ravg2; - avg[0] = u; avg[1] = v; avg[2] = w; avg[3] = enth; + avg[0] = u; + avg[1] = v; + avg[2] = w; + avg[3] = enth; } // Waves and speeds using Roe averaging -GKYL_CU_DH -static double -wave_roe(const struct gkyl_wv_eqn *eqn, - const double *delta, const double *ql, const double *qr, double *waves, double *s) +GKYL_CU_DH static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { double avg[4]; roe_avg(eqn, ql, qr, avg); return proj_onto_euler_eigvect(eqn, delta, avg, waves, s); } -GKYL_CU_DH -static void -qfluct_roe(const struct gkyl_wv_eqn *eqn, - const double *ql, const double *qr, const double *waves, const double *s, - double *amdq, double *apdq) +GKYL_CU_DH static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[5], *w2 = &waves[10]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]); - for (int i=0; i<5; ++i) { - amdq[i] = s0m*w0[i] + s1m*w1[i] + s2m*w2[i]; - apdq[i] = s0p*w0[i] + s1p*w1[i] + s2p*w2[i]; + for (int i = 0; i < 5; ++i) { + amdq[i] = s0m * w0[i] + s1m * w1[i] + s2m * w2[i]; + apdq[i] = s0p * w0[i] + s1p * w1[i] + s2p * w2[i]; } } -GKYL_CU_DH -static double -wave_roe_l(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *delta, const double *ql, const double *qr, double phil, - double phir, double *waves, double *s) +GKYL_CU_DH static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, double phil, double phir, double *waves, double *s +) { // clear waves and wave speeds int mwaves = (type == GKYL_WV_HIGH_ORDER_FLUX) ? eqn->num_waves : 2; int meqn = eqn->num_equations; - for (int i=0; i 0.0) && (phir > 0.0)) + if (type == GKYL_WV_HIGH_ORDER_FLUX && (phil > 0.0) && (phir > 0.0)) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - else + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); + } } // HLL -GKYL_CU_DH -static void -states_hll_common(const struct gkyl_wv_eqn *eqn, const double *ql, - const double *qr, double state[8]) +GKYL_CU_DH static void +states_hll_common(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double state[8]) { const struct wv_euler *euler = container_of(eqn, struct wv_euler, eqn); double g = euler->gas_gamma; @@ -483,14 +465,14 @@ states_hll_common(const struct gkyl_wv_eqn *eqn, const double *ql, // first, estimate middle pressure; using PVRS Toro (10.61) but Toro Fig 9.4 // presents an adaptive method to switch between PVRS and TRRS (10.63) and // TSRS (10.65); for ideal gases, max(0, p_PVRS) might also be good - double cl = sqrt(g*pl/rl); - double cr = sqrt(g*pr/rr); + double cl = sqrt(g * pl / rl); + double cr = sqrt(g * pr / rr); double ra = 0.5 * (rl + rr); double ca = 0.5 * (cl + cr); double pm = 0.5 * (pl + pr) - 0.5 * (ur - ul) * ra * ca; // second, compue the q coefficients in Toro (10.60) - double coeffl = pm <= pl ? 1 : sqrt(1 + 0.5 * (1 + 1/g) * (pm/pl - 1)); - double coeffr = pm <= pr ? 1 : sqrt(1 + 0.5 * (1 + 1/g) * (pm/pr - 1)); + double coeffl = pm <= pl ? 1 : sqrt(1 + 0.5 * (1 + 1 / g) * (pm / pl - 1)); + double coeffr = pm <= pr ? 1 : sqrt(1 + 0.5 * (1 + 1 / g) * (pm / pr - 1)); // finally, compute Toro (10.59) double sl = ul - cl * coeffl; double sr = ur + cr * coeffr; @@ -506,10 +488,9 @@ states_hll_common(const struct gkyl_wv_eqn *eqn, const double *ql, } // HLL -GKYL_CU_DH -static void -states_hll(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, - double *speeds, double *qm) +GKYL_CU_DH static void states_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *speeds, double *qm +) { // STEP 1. compute min and max wave speeds double state[8]; @@ -534,21 +515,21 @@ states_hll(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, fr[4] = qr[4] * ur + pr * ur; // STEP 3. compute standard HLL intermediate states - qm[0] = (sr*qr[0]-sl*ql[0]+fl[0]-fr[0]) / (sr-sl); - qm[1] = (sr*qr[1]-sl*ql[1]+fl[1]-fr[1]) / (sr-sl); - qm[2] = (sr*qr[2]-sl*ql[2]+fl[2]-fr[2]) / (sr-sl); - qm[3] = (sr*qr[3]-sl*ql[3]+fl[3]-fr[3]) / (sr-sl); - qm[4] = (sr*qr[4]-sl*ql[4]+fl[4]-fr[4]) / (sr-sl); + qm[0] = (sr * qr[0] - sl * ql[0] + fl[0] - fr[0]) / (sr - sl); + qm[1] = (sr * qr[1] - sl * ql[1] + fl[1] - fr[1]) / (sr - sl); + qm[2] = (sr * qr[2] - sl * ql[2] + fl[2] - fr[2]) / (sr - sl); + qm[3] = (sr * qr[3] - sl * ql[3] + fl[3] - fr[3]) / (sr - sl); + qm[4] = (sr * qr[4] - sl * ql[4] + fl[4] - fr[4]) / (sr - sl); // STEP 4. collect all speeds speeds[0] = sl; speeds[1] = sr; } -GKYL_CU_DH -static double -wave_hll(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, - const double *qr, double *waves, double *speeds) +GKYL_CU_DH static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, const double *qr, + double *waves, double *speeds +) { double qm[5]; states_hll(eqn, ql, qr, speeds, qm); @@ -556,61 +537,64 @@ wave_hll(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, double *wv; wv = waves; - for (int i=0; i<5; ++i) wv[i] = qm[i] - ql[i]; + for (int i = 0; i < 5; ++i) { + wv[i] = qm[i] - ql[i]; + } wv += 5; - for (int i=0; i<5; ++i) wv[i] = qr[i] - qm[i]; + for (int i = 0; i < 5; ++i) { + wv[i] = qr[i] - qm[i]; + } return fmax(fabs(speeds[0]), fabs(speeds[1])); } -GKYL_CU_DH -static void -qfluct_hll(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, - const double *waves, const double *s, double *amdq, double *apdq) +GKYL_CU_DH static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[5]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]); - for (int i=0; i<5; ++i) { - amdq[i] = s0m*w0[i] + s1m*w1[i]; - apdq[i] = s0p*w0[i] + s1p*w1[i]; + for (int i = 0; i < 5; ++i) { + amdq[i] = s0m * w0[i] + s1m * w1[i]; + apdq[i] = s0p * w0[i] + s1p * w1[i]; } } -GKYL_CU_DH -static double -wave_hll_l(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *delta, const double *ql, const double *qr, double phil, - double phir, double *waves, double *s) +GKYL_CU_DH static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, double phil, double phir, double *waves, double *s +) { - if (type == GKYL_WV_HIGH_ORDER_FLUX) + if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hll(eqn, delta, ql, qr, waves, s); - else // FIXME perhaps not needed + } else { // FIXME perhaps not needed return wave_lax(eqn, delta, ql, qr, waves, s); + } return 0.0; // can't happen } -GKYL_CU_DH -static void -qfluct_hll_l(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *ql, const double *qr, double phil, - double phir, const double *waves, const double *s, - double *amdq, double *apdq) +GKYL_CU_DH static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + double phil, double phir, const double *waves, const double *s, double *amdq, double *apdq +) { - if (type == GKYL_WV_HIGH_ORDER_FLUX) + if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_hll(eqn, ql, qr, waves, s, amdq, apdq); - else + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); + } } // HLLC -GKYL_CU_DH -static void -states_hllc(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, - double *speeds, double *qml, double *qmr) +GKYL_CU_DH static void states_hllc( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *speeds, double *qml, + double *qmr +) { // STEP 1. compute min and max wave speeds double state[8]; @@ -620,20 +604,21 @@ states_hllc(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double sl = state[6], sr = state[7]; // STEP 2. compute middle wave speed, Toro (10.37) - double sm = (pr-pl+rl*ul*(sl-ul)-rr*ur*(sr-ur)) / (rl*(sl-ul)-rr*(sr-ur)); + double sm = + (pr - pl + rl * ul * (sl - ul) - rr * ur * (sr - ur)) / (rl * (sl - ul) - rr * (sr - ur)); // STEP 3. compute left and right intermediate states, Toro (10.39) - qml[0] = rl * (sl-ul) / (sl-sm); + qml[0] = rl * (sl - ul) / (sl - sm); qml[1] = qml[0] * sm; qml[2] = qml[0] * ql[2] / ql[0]; qml[3] = qml[0] * ql[3] / ql[0]; - qml[4] = qml[0] * (ql[4]/rl + (sm-ul) * (sm + pl / rl / (sl-ul))); + qml[4] = qml[0] * (ql[4] / rl + (sm - ul) * (sm + pl / rl / (sl - ul))); - qmr[0] = rr * (sr-ur) / (sr-sm); + qmr[0] = rr * (sr - ur) / (sr - sm); qmr[1] = qmr[0] * sm; qmr[2] = qmr[0] * qr[2] / qr[0]; qmr[3] = qmr[0] * qr[3] / qr[0]; - qmr[4] = qmr[0] * (qr[4]/rr + (sm-ur) * (sm + pr / rr / (sr-ur))); + qmr[4] = qmr[0] * (qr[4] / rr + (sm - ur) * (sm + pr / rr / (sr - ur))); // STEP 4. collect all speeds speeds[0] = sl; @@ -641,10 +626,10 @@ states_hllc(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, speeds[2] = sr; } -GKYL_CU_DH -static double -wave_hllc(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, - const double *qr, double *waves, double *speeds) +GKYL_CU_DH static double wave_hllc( + const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, const double *qr, + double *waves, double *speeds +) { double qml[5], qmr[5]; states_hllc(eqn, ql, qr, speeds, qml, qmr); @@ -652,72 +637,80 @@ wave_hllc(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, double *wv; wv = waves; - for (int i=0; i<5; ++i) wv[i] = qml[i] - ql[i]; + for (int i = 0; i < 5; ++i) { + wv[i] = qml[i] - ql[i]; + } wv += 5; - for (int i=0; i<5; ++i) wv[i] = qmr[i] - qml[i]; + for (int i = 0; i < 5; ++i) { + wv[i] = qmr[i] - qml[i]; + } wv += 5; - for (int i=0; i<5; ++i) wv[i] = qr[i] - qmr[i]; + for (int i = 0; i < 5; ++i) { + wv[i] = qr[i] - qmr[i]; + } return fmax(fabs(speeds[0]), fabs(speeds[2])); } -GKYL_CU_DH -static void -qfluct_hllc(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, - const double *waves, const double *s, double *amdq, double *apdq) +GKYL_CU_DH static void qfluct_hllc( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[5], *w2 = &waves[10]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]); - for (int i=0; i<5; ++i) { - amdq[i] = s0m*w0[i] + s1m*w1[i] + s2m*w2[i]; - apdq[i] = s0p*w0[i] + s1p*w1[i] + s2p*w2[i]; + for (int i = 0; i < 5; ++i) { + amdq[i] = s0m * w0[i] + s1m * w1[i] + s2m * w2[i]; + apdq[i] = s0p * w0[i] + s1p * w1[i] + s2p * w2[i]; } } -GKYL_CU_DH -static double -wave_hllc_l(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *delta, const double *ql, const double *qr, const double phil, const double phir, double *waves, double *s) +GKYL_CU_DH static double wave_hllc_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { // clear waves and wave speeds - for (int i=0; i<3; ++i) { // mwaves - double *w = &waves[5*i]; - for (int j=0; j<5; ++j) // meqn + for (int i = 0; i < 3; ++i) { // mwaves + double *w = &waves[5 * i]; + for (int j = 0; j < 5; ++j) { // meqn w[j] = 0.0; + } s[i] = 0.0; } - if ((phil < 0.0) || (phir < 0.0)) + if ((phil < 0.0) || (phir < 0.0)) { return wave_embedded(eqn, delta, ql, qr, phil, phir, waves, s); - else { - if (type == GKYL_WV_HIGH_ORDER_FLUX) + } else { + if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hllc(eqn, delta, ql, qr, waves, s); - else + } else { return wave_lax(eqn, delta, ql, qr, waves, s); + } } return 0.0; // can't happen } -GKYL_CU_DH -static void -qfluct_hllc_l(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *ql, const double *qr, const double phil, const double phir, const double *waves, const double *s, - double *amdq, double *apdq) +GKYL_CU_DH static void qfluct_hllc_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { - if (type == GKYL_WV_HIGH_ORDER_FLUX && (phil > 0.0) && (phir > 0.0)) + if (type == GKYL_WV_HIGH_ORDER_FLUX && (phil > 0.0) && (phir > 0.0)) { return qfluct_hllc(eqn, ql, qr, waves, s, amdq, apdq); - else + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); + } } -GKYL_CU_DH -static void -qfluct_hllc_direct(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *ql, const double *qr, const double *waves, const double *speeds, - double *amdq, double *apdq) +GKYL_CU_DH static void qfluct_hllc_direct( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double *waves, const double *speeds, double *amdq, double *apdq +) { double s[3], qml[5], qmr[5]; states_hllc(eqn, ql, qr, s, qml, qmr); @@ -725,17 +718,16 @@ qfluct_hllc_direct(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]); - for (int i=0; i<5; ++i) { + for (int i = 0; i < 5; ++i) { double w0 = qml[i] - ql[i]; double w1 = qmr[i] - qml[i]; double w2 = qr[i] - qmr[i]; - amdq[i] = s0m*w0 + s1m*w1 + s2m*w2; - apdq[i] = s0p*w0 + s1p*w1 + s2p*w2; + amdq[i] = s0m * w0 + s1m * w1 + s2m * w2; + apdq[i] = s0p * w0 + s1p * w1 + s2p * w2; } } -GKYL_CU_DH -static double +GKYL_CU_DH static double flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_euler *euler = container_of(eqn, struct wv_euler, eqn); @@ -744,53 +736,52 @@ flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, dou gkyl_euler_flux(euler->gas_gamma, ql, fl); gkyl_euler_flux(euler->gas_gamma, qr, fr); - for (int m=0; m<5; ++m) flux_jump[m] = fr[m]-fl[m]; + for (int m = 0; m < 5; ++m) { + flux_jump[m] = fr[m] - fl[m]; + } double amaxl = gkyl_euler_max_abs_speed(euler->gas_gamma, ql); - double amaxr = gkyl_euler_max_abs_speed(euler->gas_gamma, qr); + double amaxr = gkyl_euler_max_abs_speed(euler->gas_gamma, qr); return fmax(amaxl, amaxr); } -GKYL_CU_DH -static bool -check_inv(const struct gkyl_wv_eqn *eqn, const double *q) +GKYL_CU_DH static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_euler *euler = container_of(eqn, struct wv_euler, eqn); - - if (q[0] < 0.0) + + if (q[0] < 0.0) { return false; + } double pr = gkyl_euler_pressure(euler->gas_gamma, q); - if (pr < 0.0) + if (pr < 0.0) { return false; + } return true; } -GKYL_CU_DH -static double -max_speed(const struct gkyl_wv_eqn *eqn, const double *q) +GKYL_CU_DH static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_euler *euler = container_of(eqn, struct wv_euler, eqn); return gkyl_euler_max_abs_speed(euler->gas_gamma, q); } -GKYL_CU_DH -static inline void -euler_cons_to_diag(const struct gkyl_wv_eqn *eqn, - const double *qin, double *diag) +GKYL_CU_DH static inline void +euler_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { // density and moment as copied as-is - for (int i=0; i<4; ++i) diag[i] = qin[i]; - double ke = 0.5*(qin[1]*qin[1] + qin[2]*qin[2] + qin[3]*qin[3])/qin[0]; - diag[4] = ke; - diag[5] = qin[4]-ke; + for (int i = 0; i < 4; ++i) { + diag[i] = qin[i]; + } + double ke = 0.5 * (qin[1] * qin[1] + qin[2] * qin[2] + qin[3] * qin[3]) / qin[0]; + diag[4] = ke; + diag[5] = qin[4] - ke; } -GKYL_CU_DH -static inline void -euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +GKYL_CU_DH static inline void +euler_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < 5; i++) { sout[i] = 0.0; diff --git a/moments/zero/gkyl_wv_euler_rgfm.h b/moments/zero/gkyl_wv_euler_rgfm.h index 05de4dc54f..95ffb25421 100644 --- a/moments/zero/gkyl_wv_euler_rgfm.h +++ b/moments/zero/gkyl_wv_euler_rgfm.h @@ -4,13 +4,13 @@ // Type of Riemann-solver to use: enum gkyl_wv_euler_rgfm_rp { - WV_EULER_RGFM_RP_LAX = 0, // Default (Lax fluxes). + WV_EULER_RGFM_RP_LAX = 0 // Default (Lax fluxes). }; // Input context, packaged as a struct. struct gkyl_wv_euler_rgfm_inp { int num_species; // Number of distinct species in the domain. - double* gas_gamma_s; // Adiabatic indices for each species in the domain. + double *gas_gamma_s; // Adiabatic indices for each species in the domain. int reinit_freq; // Reinitialization frequency for the level set. enum gkyl_wv_euler_rgfm_rp rp_type; // Type of Riemann-solver to use. @@ -26,8 +26,8 @@ struct gkyl_wv_euler_rgfm_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the Euler Riemann ghost fluid equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_euler_rgfm_new(int num_species, double* gas_gamma_s, int reinit_freq, bool use_gpu); +struct gkyl_wv_eqn * +gkyl_wv_euler_rgfm_new(int num_species, double *gas_gamma_s, int reinit_freq, bool use_gpu); /** * Create a new Euler Riemann ghost fluid equations object, from an input context struct. @@ -35,8 +35,7 @@ gkyl_wv_euler_rgfm_new(int num_species, double* gas_gamma_s, int reinit_freq, bo * @param inp Input context struct. * @return Pointer to the Euler Riemann ghost fluid equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_euler_rgfm_inew(const struct gkyl_wv_euler_rgfm_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_euler_rgfm_inew(const struct gkyl_wv_euler_rgfm_inp *inp); /** * Get number of distinct species in the domain. @@ -44,8 +43,7 @@ gkyl_wv_euler_rgfm_inew(const struct gkyl_wv_euler_rgfm_inp* inp); * @param wv Euler Riemann ghost fluid equations object. * @return Number of distinct species in the domain. */ -int -gkyl_wv_euler_rgfm_num_species(const struct gkyl_wv_eqn* wv); +int gkyl_wv_euler_rgfm_num_species(const struct gkyl_wv_eqn *wv); /** * Get adiabatic indices for each species in the domain. @@ -53,8 +51,7 @@ gkyl_wv_euler_rgfm_num_species(const struct gkyl_wv_eqn* wv); * @param wv Euler Riemann ghost fluid equations object. * @return Adiabatic indices for each species in the domain. */ -double* -gkyl_wv_euler_rgfm_gas_gamma_s(const struct gkyl_wv_eqn* wv); +double *gkyl_wv_euler_rgfm_gas_gamma_s(const struct gkyl_wv_eqn *wv); /** * Get reinitialization frequency for the level set. @@ -62,5 +59,4 @@ gkyl_wv_euler_rgfm_gas_gamma_s(const struct gkyl_wv_eqn* wv); * @param wv Euler Riemann ghost fluid equations object. * @return Reinitialization frequency for the level set. */ -int -gkyl_wv_euler_rgfm_reinit_freq(const struct gkyl_wv_eqn* wv); \ No newline at end of file +int gkyl_wv_euler_rgfm_reinit_freq(const struct gkyl_wv_eqn *wv); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_euler_rgfm_priv.h b/moments/zero/gkyl_wv_euler_rgfm_priv.h index 61f0bdf393..25a0ec1cc6 100644 --- a/moments/zero/gkyl_wv_euler_rgfm_priv.h +++ b/moments/zero/gkyl_wv_euler_rgfm_priv.h @@ -12,7 +12,7 @@ struct wv_euler_rgfm { struct gkyl_wv_eqn eqn; // Base equation object. int num_species; // Number of distinct species in the domain. - double* gas_gamma_s; // Adiabatic indices for each species in the domain. + double *gas_gamma_s; // Adiabatic indices for each species in the domain. int reinit_freq; // Reinitialization frequency for the level set. }; @@ -24,9 +24,8 @@ struct wv_euler_rgfm { * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void -gkyl_euler_rgfm_prim_vars(int num_species, double* gas_gamma_s, const double* q, double* v); +GKYL_CU_D void +gkyl_euler_rgfm_prim_vars(int num_species, double *gas_gamma_s, const double *q, double *v); /** * Compute maximum absolute wave speed. @@ -36,9 +35,8 @@ gkyl_euler_rgfm_prim_vars(int num_species, double* gas_gamma_s, const double* q, * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_euler_rgfm_max_abs_speed(int num_species, double* gas_gamma_s, const double* q); +GKYL_CU_D static inline double +gkyl_euler_rgfm_max_abs_speed(int num_species, double *gas_gamma_s, const double *q); /** * Compute flux vector. Assumes rotation to local coordinate system. @@ -48,9 +46,8 @@ gkyl_euler_rgfm_max_abs_speed(int num_species, double* gas_gamma_s, const double * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_euler_rgfm_flux(int num_species, double* gas_gamma_s, const double* q, double* flux); +GKYL_CU_D void +gkyl_euler_rgfm_flux(int num_species, double *gas_gamma_s, const double *q, double *flux); /** * Compute Riemann variables given the conserved variables. @@ -60,9 +57,8 @@ gkyl_euler_rgfm_flux(int num_species, double* gas_gamma_s, const double* q, doub * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -72,9 +68,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the Euler Riemann ghost fluid equations. @@ -86,9 +81,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -euler_rgfm_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void euler_rgfm_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the Euler Riemann ghost fluid equations. @@ -100,9 +96,10 @@ euler_rgfm_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* s * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -euler_rgfm_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void euler_rgfm_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -114,10 +111,10 @@ euler_rgfm_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -129,10 +126,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -145,9 +142,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -160,9 +158,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -176,9 +175,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -192,10 +192,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -206,9 +207,8 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the Euler Riemann ghost fluid equations is satisfied. @@ -217,9 +217,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -228,9 +226,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -239,9 +235,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -euler_rgfm_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +euler_rgfm_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variable vector. @@ -250,13 +245,12 @@ euler_rgfm_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -euler_rgfm_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +euler_rgfm_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free Euler Riemann ghost fluid equations object. * * @param ref Reference counter for Euler Riemann ghost fluid equations. */ -void gkyl_euler_rgfm_free(const struct gkyl_ref_count* ref); +void gkyl_euler_rgfm_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_gr_euler.h b/moments/zero/gkyl_wv_gr_euler.h index 11c46beb19..0131b7841d 100644 --- a/moments/zero/gkyl_wv_gr_euler.h +++ b/moments/zero/gkyl_wv_gr_euler.h @@ -7,7 +7,7 @@ enum gkyl_wv_gr_euler_rp { WV_GR_EULER_RP_HLL = 0, // Default (HLL fluxes). WV_GR_EULER_RP_ROE, - WV_GR_EULER_RP_LAX, + WV_GR_EULER_RP_LAX }; // Input context, packaged as a struct. @@ -31,8 +31,10 @@ struct gkyl_wv_gr_euler_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the general relativistic Euler equations object with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_euler_new(double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_gr_euler_new( + double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, + struct gkyl_gr_spacetime *spacetime, bool use_gpu +); /** * Create a new general relativistic Euler equations object with ideal gas equation of state, from an input context struct. @@ -40,8 +42,7 @@ gkyl_wv_gr_euler_new(double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge * @param inp Input context struct. * @return Pointer to the general relativistic Euler equations object with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_euler_inew(const struct gkyl_wv_gr_euler_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_gr_euler_inew(const struct gkyl_wv_gr_euler_inp *inp); /** * Get adiabatic index. @@ -49,8 +50,7 @@ gkyl_wv_gr_euler_inew(const struct gkyl_wv_gr_euler_inp* inp); * @param eqn General relativistic Euler equations object with ideal gas equation of state. * @return Adiabatic index. */ -double -gkyl_wv_gr_euler_gas_gamma(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_euler_gas_gamma(const struct gkyl_wv_eqn *eqn); /** * Get spacetime gauge choice. @@ -58,8 +58,7 @@ gkyl_wv_gr_euler_gas_gamma(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Euler equations object with ideal gas equation of state. * @return Spacetime gauge choice. */ -enum gkyl_spacetime_gauge -gkyl_wv_gr_euler_spacetime_gauge(const struct gkyl_wv_eqn* eqn); +enum gkyl_spacetime_gauge gkyl_wv_gr_euler_spacetime_gauge(const struct gkyl_wv_eqn *eqn); /** * Get spacetime reinitialization frequency. @@ -67,8 +66,7 @@ gkyl_wv_gr_euler_spacetime_gauge(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Euler equations object with ideal gas equation of state. * @return Spacetime reinitialization frequency. */ -int -gkyl_wv_gr_euler_reinit_freq(const struct gkyl_wv_eqn* eqn); +int gkyl_wv_gr_euler_reinit_freq(const struct gkyl_wv_eqn *eqn); /** * Get base spacetime object. @@ -76,5 +74,4 @@ gkyl_wv_gr_euler_reinit_freq(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Euler equations object with ideal gas equation of state. * @return Pointer to the base spacetime object. */ -struct gkyl_gr_spacetime* -gkyl_wv_gr_euler_spacetime(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +struct gkyl_gr_spacetime *gkyl_wv_gr_euler_spacetime(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_gr_euler_priv.h b/moments/zero/gkyl_wv_gr_euler_priv.h index 922f3a73dc..e8c836f6ce 100644 --- a/moments/zero/gkyl_wv_gr_euler_priv.h +++ b/moments/zero/gkyl_wv_gr_euler_priv.h @@ -26,9 +26,7 @@ struct wv_gr_euler { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_euler_flux(double gas_gamma, const double q[71], double flux[71]); +GKYL_CU_D void gkyl_gr_euler_flux(double gas_gamma, const double q[71], double flux[71]); /** * Compute primitive variables given the conserved variables. @@ -37,9 +35,7 @@ gkyl_gr_euler_flux(double gas_gamma, const double q[71], double flux[71]); * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void -gkyl_gr_euler_prim_vars(double gas_gamma, const double q[71], double v[71]); +GKYL_CU_D void gkyl_gr_euler_prim_vars(double gas_gamma, const double q[71], double v[71]); /** * Compute inverse spatial metric tensor (in covariant component form) given the conserved variables. @@ -47,9 +43,7 @@ gkyl_gr_euler_prim_vars(double gas_gamma, const double q[71], double v[71]); * @param q Conserved variable vector. * @param inv_spatial_metric Inverse spatial metric tensor (output). */ -GKYL_CU_D -void -gkyl_gr_euler_inv_spatial_metric(const double q[71], double ***inv_spatial_metric); +GKYL_CU_D void gkyl_gr_euler_inv_spatial_metric(const double q[71], double ***inv_spatial_metric); /** * Compute perfect fluid stress-energy tensor (in contravariant component form) given the conserved variables. @@ -58,8 +52,7 @@ gkyl_gr_euler_inv_spatial_metric(const double q[71], double ***inv_spatial_metri * @param q Conserved variable vector. * @param stress_energy Stress-energy tensor (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_euler_stress_energy_tensor(double gas_gamma, const double q[71], double ***stress_energy); /** @@ -69,9 +62,7 @@ gkyl_gr_euler_stress_energy_tensor(double gas_gamma, const double q[71], double * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]); +GKYL_CU_D static inline double gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]); /** * Compute Riemann variables given the conserved variables. @@ -81,9 +72,8 @@ gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]); * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -93,9 +83,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the general relativistic Euler equations with ideal gas equation of state. @@ -107,9 +96,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_euler_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the general relativistic Euler equations with ideal gas equation of state. @@ -121,9 +111,10 @@ gr_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* ski * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_euler_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -135,10 +126,10 @@ gr_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -150,10 +141,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -166,9 +157,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -181,9 +173,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -197,9 +190,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -213,10 +207,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -229,9 +224,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -244,9 +240,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -260,9 +257,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback). @@ -276,10 +274,11 @@ wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param qpdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using HLL fluxes. @@ -292,9 +291,10 @@ qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using HLL fluxes. @@ -307,9 +307,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using HLL fluxes (with potential fallback). @@ -323,9 +324,10 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using HLL fluxes (with potential fallback), @@ -339,10 +341,11 @@ wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -353,9 +356,8 @@ qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the general relativistic Euler equations with ideal gas equation of state is satisfied. @@ -364,9 +366,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -375,9 +375,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -386,9 +384,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -gr_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +gr_euler_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variables. @@ -397,13 +394,12 @@ gr_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gr_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +gr_euler_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free general relativistic Euler equations object with ideal gas equation of state. * * @param ref Reference counter for general relativistic Euler equations with ideal gas equation of state. */ -void gkyl_gr_euler_free(const struct gkyl_ref_count* ref); +void gkyl_gr_euler_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_gr_euler_tetrad.h b/moments/zero/gkyl_wv_gr_euler_tetrad.h index 1eee74819c..6f18348e3c 100644 --- a/moments/zero/gkyl_wv_gr_euler_tetrad.h +++ b/moments/zero/gkyl_wv_gr_euler_tetrad.h @@ -7,7 +7,7 @@ enum gkyl_wv_gr_euler_tetrad_rp { WV_GR_EULER_TETRAD_RP_HLL = 0, // Default (HLL fluxes). WV_GR_EULER_TETRAD_RP_ROE, - WV_GR_EULER_TETRAD_RP_LAX, + WV_GR_EULER_TETRAD_RP_LAX }; // Input context, packaged as a struct. @@ -31,8 +31,10 @@ struct gkyl_wv_gr_euler_tetrad_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the general relativistic Euler equations object in the tetrad basis with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_euler_tetrad_new(double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_gr_euler_tetrad_new( + double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, + struct gkyl_gr_spacetime *spacetime, bool use_gpu +); /** * Create a new general relativistic Euler equations object in the tetrad basis with ideal gas equation of state, from an input context struct. @@ -40,8 +42,7 @@ gkyl_wv_gr_euler_tetrad_new(double gas_gamma, enum gkyl_spacetime_gauge spacetim * @param inp Input context struct. * @return Pointer to the general relativistic Euler equations object in the tetrad basis with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_euler_tetrad_inew(const struct gkyl_wv_gr_euler_tetrad_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_gr_euler_tetrad_inew(const struct gkyl_wv_gr_euler_tetrad_inp *inp); /** * Get adiabatic index. @@ -49,8 +50,7 @@ gkyl_wv_gr_euler_tetrad_inew(const struct gkyl_wv_gr_euler_tetrad_inp* inp); * @param eqn General relativistic Euler equations object in the tetrad basis with ideal gas equation of state. * @return Adiabatic index. */ -double -gkyl_wv_gr_euler_tetrad_gas_gamma(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_euler_tetrad_gas_gamma(const struct gkyl_wv_eqn *eqn); /** * Get spacetime gauge choice. @@ -58,8 +58,7 @@ gkyl_wv_gr_euler_tetrad_gas_gamma(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Euler equations object in the tetrad with ideal gas equation of state. * @return Spacetime gauge choice. */ -enum gkyl_spacetime_gauge -gkyl_wv_gr_euler_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn); +enum gkyl_spacetime_gauge gkyl_wv_gr_euler_tetrad_spacetime_gauge(const struct gkyl_wv_eqn *eqn); /** * Get spacetime reinitialization frequency. @@ -67,8 +66,7 @@ gkyl_wv_gr_euler_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Euler equations object in the tetrad basis with ideal gas equation of state. * @return Spacetime reinitialization frequency. */ -int -gkyl_wv_gr_euler_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn); +int gkyl_wv_gr_euler_tetrad_reinit_freq(const struct gkyl_wv_eqn *eqn); /** * Get base spacetime object. @@ -76,5 +74,4 @@ gkyl_wv_gr_euler_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Euler equations object in the tetrad basis with ideal gas equation of state. * @return Pointer to the base spacetime object. */ -struct gkyl_gr_spacetime* -gkyl_wv_gr_euler_tetrad_spacetime(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +struct gkyl_gr_spacetime *gkyl_wv_gr_euler_tetrad_spacetime(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_gr_euler_tetrad_priv.h b/moments/zero/gkyl_wv_gr_euler_tetrad_priv.h index ae06b12911..7f5934129b 100644 --- a/moments/zero/gkyl_wv_gr_euler_tetrad_priv.h +++ b/moments/zero/gkyl_wv_gr_euler_tetrad_priv.h @@ -26,9 +26,7 @@ struct wv_gr_euler_tetrad { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_euler_tetrad_flux(double gas_gamma, const double q[71], double flux[71]); +GKYL_CU_D void gkyl_gr_euler_tetrad_flux(double gas_gamma, const double q[71], double flux[71]); /** * Compute general relativistic correction to special relativistic flux. Assumes rotation to local coordinate system. @@ -38,9 +36,9 @@ gkyl_gr_euler_tetrad_flux(double gas_gamma, const double q[71], double flux[71]) * @param flux_sr Special relativistic flux vector in direction 'dir'. * @param flux_gr General relativistic flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_euler_tetrad_flux_correction(double gas_gamma, const double q[71], const double flux_sr[71], double flux_gr[71]); +GKYL_CU_D void gkyl_gr_euler_tetrad_flux_correction( + double gas_gamma, const double q[71], const double flux_sr[71], double flux_gr[71] +); /** * Compute primitive variables given the conserved variables. @@ -49,9 +47,7 @@ gkyl_gr_euler_tetrad_flux_correction(double gas_gamma, const double q[71], const * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void -gkyl_gr_euler_tetrad_prim_vars(double gas_gamma, const double q[71], double v[71]); +GKYL_CU_D void gkyl_gr_euler_tetrad_prim_vars(double gas_gamma, const double q[71], double v[71]); /** * Compute inverse spatial metric tensor (in covariant component form) given the conserved variables. @@ -59,8 +55,7 @@ gkyl_gr_euler_tetrad_prim_vars(double gas_gamma, const double q[71], double v[71 * @param q Conserved variable vector. * @param inv_spatial_metric Inverse spatial metric tensor (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_euler_tetrad_inv_spatial_metric(const double q[71], double ***inv_spatial_metric); /** @@ -70,9 +65,9 @@ gkyl_gr_euler_tetrad_inv_spatial_metric(const double q[71], double ***inv_spatia * @param q Conserved variable vector. * @param stress_energy Stress-energy tensor (output). */ -GKYL_CU_D -void -gkyl_gr_euler_tetrad_stress_energy_tensor(double gas_gamma, const double q[71], double ***stress_energy); +GKYL_CU_D void gkyl_gr_euler_tetrad_stress_energy_tensor( + double gas_gamma, const double q[71], double ***stress_energy +); /** * Compute maximum absolute wave speed. @@ -81,8 +76,7 @@ gkyl_gr_euler_tetrad_stress_energy_tensor(double gas_gamma, const double q[71], * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double +GKYL_CU_D static inline double gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]); /** @@ -93,9 +87,8 @@ gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]); * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -105,9 +98,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the general relativistic Euler equations in the tetrad basis with ideal gas equation of state. @@ -119,9 +111,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_euler_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_euler_tetrad_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the general relativistic Euler equations in the tetrad basis with ideal gas equation of state. @@ -133,9 +126,10 @@ gr_euler_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const doub * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_euler_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_euler_tetrad_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -147,10 +141,10 @@ gr_euler_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const d * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -162,10 +156,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -178,9 +172,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -193,9 +188,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -209,9 +205,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -225,10 +222,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -241,9 +239,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -256,9 +255,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -272,9 +272,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback). @@ -288,10 +289,11 @@ wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param qpdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using HLL fluxes. @@ -304,9 +306,10 @@ qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using HLL fluxes. @@ -319,9 +322,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using HLL fluxes (with potential fallback). @@ -335,9 +339,10 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using HLL fluxes (with potential fallback), @@ -351,10 +356,11 @@ wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -365,9 +371,8 @@ qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the general relativistic Euler equations in the tetrad basis with ideal gas equation of state is satisfied. @@ -376,9 +381,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -387,9 +390,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -398,9 +399,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -gr_euler_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +gr_euler_tetrad_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variables. @@ -409,13 +409,12 @@ gr_euler_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, d * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gr_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +gr_euler_tetrad_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free general relativistic Euler equations object in the tetrad basis with ideal gas equation of state. * * @param ref Reference counter for general relativistic Euler equations in the tetrad basis with ideal gas equation of state. */ -void gkyl_gr_euler_tetrad_free(const struct gkyl_ref_count* ref); +void gkyl_gr_euler_tetrad_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_gr_maxwell.h b/moments/zero/gkyl_wv_gr_maxwell.h index d96d91016e..60d75837fb 100644 --- a/moments/zero/gkyl_wv_gr_maxwell.h +++ b/moments/zero/gkyl_wv_gr_maxwell.h @@ -6,7 +6,7 @@ // Type of Riemann-solver to use: enum gkyl_wv_gr_maxwell_rp { WV_GR_MAXWELL_RP_ROE = 0, // Default (Roe fluxes). - WV_GR_MAXWELL_RP_LAX, + WV_GR_MAXWELL_RP_LAX }; // Input context, packaged as a struct. @@ -35,8 +35,10 @@ struct gkyl_wv_gr_maxwell_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the general relativistic Maxwell equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_maxwell_new(double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_gr_maxwell_new( + double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, + int reinit_freq, struct gkyl_gr_spacetime *spacetime, bool use_gpu +); /** * Create a new general relativistic Maxwell equations object, from an input context struct. @@ -44,8 +46,7 @@ gkyl_wv_gr_maxwell_new(double light_speed, double e_fact, double b_fact, enum gk * @param inp Input context struct. * @return Pointer to the general relativistic Maxwell equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_maxwell_inew(const struct gkyl_wv_gr_maxwell_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_gr_maxwell_inew(const struct gkyl_wv_gr_maxwell_inp *inp); /** * Get speed of light. @@ -53,8 +54,7 @@ gkyl_wv_gr_maxwell_inew(const struct gkyl_wv_gr_maxwell_inp* inp); * @param eqn General relativistic Maxwell equations object. * @return Speed of light. */ -double -gkyl_wv_gr_maxwell_light_speed(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_maxwell_light_speed(const struct gkyl_wv_eqn *eqn); /** * Get factor of speed of light for electric field correction. @@ -62,8 +62,7 @@ gkyl_wv_gr_maxwell_light_speed(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Maxwell equations object. * @return Factor of speed of light for electric field correction. */ -double -gkyl_wv_gr_maxwell_e_fact(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_maxwell_e_fact(const struct gkyl_wv_eqn *eqn); /** * Get factor of speed of light for magnetic field correction. @@ -71,8 +70,7 @@ gkyl_wv_gr_maxwell_e_fact(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Maxwell equations object. * @return Factor of speed of light for magnetic field correction. */ -double -gkyl_wv_gr_maxwell_b_fact(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_maxwell_b_fact(const struct gkyl_wv_eqn *eqn); /** * Get spacetime gauge choice. @@ -80,8 +78,7 @@ gkyl_wv_gr_maxwell_b_fact(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Maxwell equations object. * @return Spacetime gauge choice. */ -enum gkyl_spacetime_gauge -gkyl_wv_gr_maxwell_spacetime_gauge(const struct gkyl_wv_eqn* eqn); +enum gkyl_spacetime_gauge gkyl_wv_gr_maxwell_spacetime_gauge(const struct gkyl_wv_eqn *eqn); /** * Get spacetime reinitialization frequency. @@ -89,8 +86,7 @@ gkyl_wv_gr_maxwell_spacetime_gauge(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Maxwell equations object. * @return Spacetime reinitialization frequency. */ -int -gkyl_wv_gr_maxwell_reinit_freq(const struct gkyl_wv_eqn* eqn); +int gkyl_wv_gr_maxwell_reinit_freq(const struct gkyl_wv_eqn *eqn); /** * Get base spacetime object. @@ -98,5 +94,4 @@ gkyl_wv_gr_maxwell_reinit_freq(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Maxwell equations object. * @return Pointer to the base spacetime object. */ -struct gkyl_gr_spacetime* -gkyl_wv_gr_maxwell_spacetime(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +struct gkyl_gr_spacetime *gkyl_wv_gr_maxwell_spacetime(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_gr_maxwell_priv.h b/moments/zero/gkyl_wv_gr_maxwell_priv.h index 1792a45c44..e694bcb2c4 100644 --- a/moments/zero/gkyl_wv_gr_maxwell_priv.h +++ b/moments/zero/gkyl_wv_gr_maxwell_priv.h @@ -31,9 +31,9 @@ struct wv_gr_maxwell { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_maxwell_flux(double light_speed, double e_fact, double b_fact, const double q[26], double flux[26]); +GKYL_CU_D void gkyl_gr_maxwell_flux( + double light_speed, double e_fact, double b_fact, const double q[26], double flux[26] +); /** * Compute maximum absolute wave speed. @@ -42,8 +42,7 @@ gkyl_gr_maxwell_flux(double light_speed, double e_fact, double b_fact, const dou * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double +GKYL_CU_D static inline double gkyl_gr_maxwell_max_abs_speed(double light_speed, const double q[26]); /** @@ -54,9 +53,8 @@ gkyl_gr_maxwell_max_abs_speed(double light_speed, const double q[26]); * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -66,9 +64,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the general relativistic Maxwell equations. @@ -80,9 +77,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_maxwell_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_maxwell_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -94,10 +92,10 @@ gr_maxwell_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* s * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -109,10 +107,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -125,9 +123,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -140,9 +139,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -156,9 +156,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -172,10 +173,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -188,9 +190,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -203,9 +206,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -219,9 +223,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe_l( + const struct gkyl_wv_eqn *, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback). @@ -235,10 +240,11 @@ wave_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe_l( + const struct gkyl_wv_eqn *, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -249,9 +255,8 @@ qfluct_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const doubl * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the general relativistic Maxwell equations is satisfied. @@ -260,9 +265,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -271,9 +274,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -282,9 +283,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -gr_maxwell_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +gr_maxwell_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variables. @@ -293,13 +293,12 @@ gr_maxwell_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gr_maxwell_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +gr_maxwell_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free general relativistic Maxwell equations object. * * @param ref Reference counter for general relativistic Maxwell equations. */ -void gkyl_gr_maxwell_free(const struct gkyl_ref_count* ref); +void gkyl_gr_maxwell_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_gr_maxwell_tetrad.h b/moments/zero/gkyl_wv_gr_maxwell_tetrad.h index 9a44e69b9c..044ffe48e3 100644 --- a/moments/zero/gkyl_wv_gr_maxwell_tetrad.h +++ b/moments/zero/gkyl_wv_gr_maxwell_tetrad.h @@ -6,7 +6,7 @@ // Type of Riemann-solver to use: enum gkyl_wv_gr_maxwell_tetrad_rp { WV_GR_MAXWELL_TETRAD_RP_ROE = 0, // Default (Roe fluxes). - WV_GR_MAXWELL_TETRAD_RP_LAX, + WV_GR_MAXWELL_TETRAD_RP_LAX }; // Input context, packaged as a struct. @@ -35,8 +35,10 @@ struct gkyl_wv_gr_maxwell_tetrad_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the general relativistic Maxwell equations object in the tetrad basis. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_maxwell_tetrad_new(double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_gr_maxwell_tetrad_new( + double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, + int reinit_freq, struct gkyl_gr_spacetime *spacetime, bool use_gpu +); /** * Create a new general relativistic Maxwell equations object in the tetrad basis, from an input context struct. @@ -44,8 +46,7 @@ gkyl_wv_gr_maxwell_tetrad_new(double light_speed, double e_fact, double b_fact, * @param inp Input context struct. * @return Pointer to the general relativistic Maxwell equations object in the tetrad basis. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_maxwell_tetrad_inew(const struct gkyl_wv_gr_maxwell_tetrad_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_gr_maxwell_tetrad_inew(const struct gkyl_wv_gr_maxwell_tetrad_inp *inp); /** * Get speed of light. @@ -53,8 +54,7 @@ gkyl_wv_gr_maxwell_tetrad_inew(const struct gkyl_wv_gr_maxwell_tetrad_inp* inp); * @param eqn General relativistic Maxwell equations object in the tetrad basis. * @return Speed of light. */ -double -gkyl_wv_gr_maxwell_tetrad_light_speed(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_maxwell_tetrad_light_speed(const struct gkyl_wv_eqn *eqn); /** * Get factor of speed of light for electric field correction. @@ -62,8 +62,7 @@ gkyl_wv_gr_maxwell_tetrad_light_speed(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Maxwell equations object in the tetrad basis. * @return Factor of speed of light for electric field correction. */ -double -gkyl_wv_gr_maxwell_tetrad_e_fact(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_maxwell_tetrad_e_fact(const struct gkyl_wv_eqn *eqn); /** * Get factor of speed of light for magnetic field correction. @@ -71,8 +70,7 @@ gkyl_wv_gr_maxwell_tetrad_e_fact(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Maxwell equations object in the tetrad basis. * @return Factor of speed of light for magnetic field correction. */ -double -gkyl_wv_gr_maxwell_tetrad_b_fact(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_maxwell_tetrad_b_fact(const struct gkyl_wv_eqn *eqn); /** * Get spacetime gauge choice. @@ -80,8 +78,7 @@ gkyl_wv_gr_maxwell_tetrad_b_fact(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Maxwell equations object in the tetrad basis. * @return Spacetime gauge choice. */ -enum gkyl_spacetime_gauge -gkyl_wv_gr_maxwell_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn); +enum gkyl_spacetime_gauge gkyl_wv_gr_maxwell_tetrad_spacetime_gauge(const struct gkyl_wv_eqn *eqn); /** * Get spacetime reinitialization frequency. @@ -89,8 +86,7 @@ gkyl_wv_gr_maxwell_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Maxwell equations object in the tetrad basis. * @return Spacetime reinitialization frequency. */ -int -gkyl_wv_gr_maxwell_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn); +int gkyl_wv_gr_maxwell_tetrad_reinit_freq(const struct gkyl_wv_eqn *eqn); /** * Get base spacetime object. @@ -98,5 +94,4 @@ gkyl_wv_gr_maxwell_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Maxwell equations object in the tetrad basis. * @return Pointer to the base spacetime object. */ -struct gkyl_gr_spacetime* -gkyl_wv_gr_maxwell_tetrad_spacetime(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +struct gkyl_gr_spacetime *gkyl_wv_gr_maxwell_tetrad_spacetime(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_gr_maxwell_tetrad_priv.h b/moments/zero/gkyl_wv_gr_maxwell_tetrad_priv.h index 5899829110..8261257049 100644 --- a/moments/zero/gkyl_wv_gr_maxwell_tetrad_priv.h +++ b/moments/zero/gkyl_wv_gr_maxwell_tetrad_priv.h @@ -31,9 +31,9 @@ struct wv_gr_maxwell_tetrad { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_maxwell_tetrad_flux(double light_speed, double e_fact, double b_fact, const double q[26], double flux[26]); +GKYL_CU_D void gkyl_gr_maxwell_tetrad_flux( + double light_speed, double e_fact, double b_fact, const double q[26], double flux[26] +); /** * Compute general relativistic correction to special relativistic flux. Assumes rotation to local coordinate system. @@ -45,9 +45,10 @@ gkyl_gr_maxwell_tetrad_flux(double light_speed, double e_fact, double b_fact, co * @param flux_sr Special relativistic flux vector in direction 'dir'. * @param flux_gr General relativistic flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_maxwell_tetrad_flux_correction(double light_speed, double e_fact, double b_fact, const double q[26], const double flux_sr[26], double flux_gr[26]); +GKYL_CU_D void gkyl_gr_maxwell_tetrad_flux_correction( + double light_speed, double e_fact, double b_fact, const double q[26], const double flux_sr[26], + double flux_gr[26] +); /** * Compute maximum absolute wave speed. @@ -56,8 +57,7 @@ gkyl_gr_maxwell_tetrad_flux_correction(double light_speed, double e_fact, double * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double +GKYL_CU_D static inline double gkyl_gr_maxwell_tetrad_max_abs_speed(double light_speed, const double q[26]); /** @@ -68,9 +68,8 @@ gkyl_gr_maxwell_tetrad_max_abs_speed(double light_speed, const double q[26]); * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -80,9 +79,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the general relativistic Maxwell equations in the tetrad basis. @@ -94,9 +92,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_maxwell_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_maxwell_tetrad_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -108,10 +107,10 @@ gr_maxwell_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const do * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -123,10 +122,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -139,9 +138,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -154,9 +154,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -170,9 +171,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -186,10 +188,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -202,9 +205,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -217,9 +221,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -233,9 +238,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe_l( + const struct gkyl_wv_eqn *, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback). @@ -249,10 +255,11 @@ wave_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe_l( + const struct gkyl_wv_eqn *, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -263,9 +270,8 @@ qfluct_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const doubl * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the general relativistic Maxwell equations in the tetrad basis is satisfied. @@ -274,9 +280,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -285,9 +289,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -296,9 +298,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -gr_maxwell_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +gr_maxwell_tetrad_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variables. @@ -307,13 +308,12 @@ gr_maxwell_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gr_maxwell_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +gr_maxwell_tetrad_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free general relativistic Maxwell equations object in the tetrad basis. * * @param ref Reference counter for general relativistic Maxwell equations. */ -void gkyl_gr_maxwell_tetrad_free(const struct gkyl_ref_count* ref); +void gkyl_gr_maxwell_tetrad_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_gr_medium.h b/moments/zero/gkyl_wv_gr_medium.h index 580f0eba1a..de70c08245 100644 --- a/moments/zero/gkyl_wv_gr_medium.h +++ b/moments/zero/gkyl_wv_gr_medium.h @@ -5,7 +5,7 @@ // Type of Riemann-solver to use: enum gkyl_wv_gr_medium_rp { WV_GR_MEDIUM_RP_LAX = 0, // Default (Lax fluxes). - WV_GR_MEDIUM_RP_ROE, + WV_GR_MEDIUM_RP_ROE }; // Input context, packaged as a struct. @@ -25,8 +25,7 @@ struct gkyl_wv_gr_medium_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the coupled fluid-Einstein equations object in plane-symmetric spacetimes. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_medium_new(double gas_gamma, double kappa, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_gr_medium_new(double gas_gamma, double kappa, bool use_gpu); /** * Create a new coupled fluid-Einstein equations object in plane-symmetric spacetimes, from an input context struct. @@ -34,8 +33,7 @@ gkyl_wv_gr_medium_new(double gas_gamma, double kappa, bool use_gpu); * @param inp Input context struct. * @return Pointer to the coupled fluid-Einstein equations object in plane-symmetric spacetimes. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_medium_inew(const struct gkyl_wv_gr_medium_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_gr_medium_inew(const struct gkyl_wv_gr_medium_inp *inp); /** * Get adiabatic index. @@ -43,8 +41,7 @@ gkyl_wv_gr_medium_inew(const struct gkyl_wv_gr_medium_inp* inp); * @param eqn Coupled fluid-Einstein equations object in plane-symmetric spacetimes. * @return Adiabatic index. */ -double -gkyl_wv_gr_medium_gas_gamma(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_medium_gas_gamma(const struct gkyl_wv_eqn *eqn); /** * Get stress-energy prefactor in the Einstein field equations. @@ -52,5 +49,4 @@ gkyl_wv_gr_medium_gas_gamma(const struct gkyl_wv_eqn* eqn); * @param eqn Coupled fluid-Einstein equations object in plane-symmetric spacetimes. * @return Stress-energy prefactor in the Einstein field equations. */ -double -gkyl_wv_gr_medium_kappa(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +double gkyl_wv_gr_medium_kappa(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_gr_medium_priv.h b/moments/zero/gkyl_wv_gr_medium_priv.h index 65c1e8d858..d6fd5fd863 100644 --- a/moments/zero/gkyl_wv_gr_medium_priv.h +++ b/moments/zero/gkyl_wv_gr_medium_priv.h @@ -23,9 +23,7 @@ struct wv_gr_medium { * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void -gkyl_gr_medium_prim_vars(double gas_gamma, const double q[15], double v[15]); +GKYL_CU_D void gkyl_gr_medium_prim_vars(double gas_gamma, const double q[15], double v[15]); /** * Compute maximum absolute wave speed. @@ -34,9 +32,7 @@ gkyl_gr_medium_prim_vars(double gas_gamma, const double q[15], double v[15]); * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_gr_medium_max_abs_speed(double gas_gamma, const double q[15]); +GKYL_CU_D static inline double gkyl_gr_medium_max_abs_speed(double gas_gamma, const double q[15]); /** * Compute flux vector. Assumes rotation to local coordinate system. @@ -46,8 +42,7 @@ gkyl_gr_medium_max_abs_speed(double gas_gamma, const double q[15]); * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_medium_flux(double gas_gamma, double kappa, const double q[15], double flux[15]); /** @@ -58,9 +53,8 @@ gkyl_gr_medium_flux(double gas_gamma, double kappa, const double q[15], double f * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -70,9 +64,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the coupled fluid-Einstein equations in plane-symmetric spacetimes. @@ -84,9 +77,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_medium_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_medium_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -98,10 +92,10 @@ gr_medium_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* sk * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -113,10 +107,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -129,9 +123,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -144,9 +139,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -160,9 +156,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -176,10 +173,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -190,9 +188,8 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the coupled fluid-Einstein equations in plane-symmetric spacetimes is satisfied. @@ -201,9 +198,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -212,9 +207,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -223,9 +216,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -gr_medium_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +gr_medium_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variables. @@ -234,13 +226,12 @@ gr_medium_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gr_medium_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +gr_medium_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free coupled fluid-Einstein equations object in plane-symmetric spacetimes. * * @param ref Reference counter for coupled fluid-Einstein equations in plane-symmetric spacetimes. */ -void gkyl_gr_medium_free(const struct gkyl_ref_count* ref); +void gkyl_gr_medium_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_gr_mhd.h b/moments/zero/gkyl_wv_gr_mhd.h index 7987c49ece..bd070c6c8e 100644 --- a/moments/zero/gkyl_wv_gr_mhd.h +++ b/moments/zero/gkyl_wv_gr_mhd.h @@ -35,9 +35,10 @@ struct gkyl_wv_gr_mhd_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the general relativistic magnetohydrodynamics equations object with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_mhd_new(double gas_gamma, double light_speed, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, - struct gkyl_gr_spacetime* spacetime, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_gr_mhd_new( + double gas_gamma, double light_speed, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, + int reinit_freq, struct gkyl_gr_spacetime *spacetime, bool use_gpu +); /** * Create a new general relativistic magnetohydrodynamics equations object with ideal gas equation of state, from an input context struct. @@ -45,8 +46,7 @@ gkyl_wv_gr_mhd_new(double gas_gamma, double light_speed, double b_fact, enum gky * @param inp Input context struct. * @return Pointer to the general relativistic magnetohydrodynamics equations object with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_mhd_inew(const struct gkyl_wv_gr_mhd_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_gr_mhd_inew(const struct gkyl_wv_gr_mhd_inp *inp); /** * Get adiabatic index. @@ -54,8 +54,7 @@ gkyl_wv_gr_mhd_inew(const struct gkyl_wv_gr_mhd_inp* inp); * @param eqn General relativistic magnetohydrodynamics equations object with ideal gas equation of state. * @return Adiabatic index. */ -double -gkyl_wv_gr_mhd_gas_gamma(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_mhd_gas_gamma(const struct gkyl_wv_eqn *eqn); /** * Get speed of light. @@ -63,8 +62,7 @@ gkyl_wv_gr_mhd_gas_gamma(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic magnetohydrodynamics equations object with ideal gas equation of state. * @return Speed of light. */ -double -gkyl_wv_gr_mhd_light_speed(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_mhd_light_speed(const struct gkyl_wv_eqn *eqn); /** * Get factor of speed of light for magnetic field correction. @@ -72,8 +70,7 @@ gkyl_wv_gr_mhd_light_speed(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic magnetohydrodynamics equations object with ideal gas equation of state. * @return Factor of speed of light for magnetic field correction. */ -double -gkyl_wv_gr_mhd_b_fact(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_mhd_b_fact(const struct gkyl_wv_eqn *eqn); /** * Get spacetime gauge choice. @@ -81,8 +78,7 @@ gkyl_wv_gr_mhd_b_fact(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic magnetohydrodynamics equations object with ideal gas equation of state. * @return Spacetime gauge choice. */ -enum gkyl_spacetime_gauge -gkyl_wv_gr_mhd_spacetime_gauge(const struct gkyl_wv_eqn* eqn); +enum gkyl_spacetime_gauge gkyl_wv_gr_mhd_spacetime_gauge(const struct gkyl_wv_eqn *eqn); /** * Get spacetime reinitialization frequency. @@ -90,8 +86,7 @@ gkyl_wv_gr_mhd_spacetime_gauge(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic magnetohydrodynamics equations object with ideal gas equation of state. * @return Spacetime reinitialization frequency. */ -int -gkyl_wv_gr_mhd_reinit_freq(const struct gkyl_wv_eqn* eqn); +int gkyl_wv_gr_mhd_reinit_freq(const struct gkyl_wv_eqn *eqn); /** * Get base spacetime object. @@ -99,5 +94,4 @@ gkyl_wv_gr_mhd_reinit_freq(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic magnetohydrodynamics equations object with ideal gas equation of state. * @return Pointer to the base spacetime object. */ -struct gkyl_gr_spacetime* -gkyl_wv_gr_mhd_spacetime(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +struct gkyl_gr_spacetime *gkyl_wv_gr_mhd_spacetime(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_gr_mhd_priv.h b/moments/zero/gkyl_wv_gr_mhd_priv.h index 7102b7c936..f01217762f 100644 --- a/moments/zero/gkyl_wv_gr_mhd_priv.h +++ b/moments/zero/gkyl_wv_gr_mhd_priv.h @@ -31,9 +31,9 @@ struct wv_gr_mhd { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_mhd_flux(double gas_gamma, double light_speed, double b_fact, const double q[75], double flux[75]); +GKYL_CU_D void gkyl_gr_mhd_flux( + double gas_gamma, double light_speed, double b_fact, const double q[75], double flux[75] +); /** * Compute primitive variables given the conserved variables. @@ -42,9 +42,7 @@ gkyl_gr_mhd_flux(double gas_gamma, double light_speed, double b_fact, const doub * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void -gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]); +GKYL_CU_D void gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]); /** * Compute inverse spatial metric tensor (in covariant component form) given the conserved variables. @@ -52,9 +50,7 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]); * @param q Conserved variable vector. * @param inv_spatial_metric Inverse spatial metric tensor (output). */ -GKYL_CU_D -void -gkyl_gr_mhd_inv_spatial_metric(const double q[75], double ***inv_spatial_metric); +GKYL_CU_D void gkyl_gr_mhd_inv_spatial_metric(const double q[75], double ***inv_spatial_metric); /** * Compute ideal magnetohydrodynamic stress-energy tensor (in contravariant component form) given the conserved variables. @@ -63,8 +59,7 @@ gkyl_gr_mhd_inv_spatial_metric(const double q[75], double ***inv_spatial_metric) * @param q Conserved variable vector. * @param stress_energy Stress-energy tensor (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_mhd_stress_energy_tensor(double gas_gamma, const double q[75], double ***stress_energy); /** @@ -74,9 +69,7 @@ gkyl_gr_mhd_stress_energy_tensor(double gas_gamma, const double q[75], double ** * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]); +GKYL_CU_D static inline double gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]); /** * Compute Riemann variables given the conserved variables. @@ -86,9 +79,8 @@ gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]); * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -98,9 +90,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the general relativistic magnetohydrodynamics equations with ideal gas equation of state. @@ -112,9 +103,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_mhd_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_mhd_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the general relativistic magnetohydrodynamics equations with ideal gas equation of state. @@ -126,9 +118,10 @@ gr_mhd_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_mhd_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_mhd_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -140,10 +133,10 @@ gr_mhd_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* sk * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -155,10 +148,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -171,9 +164,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -186,9 +180,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -202,9 +197,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -218,10 +214,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using HLL fluxes. @@ -234,9 +231,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using HLL fluxes. @@ -249,9 +247,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using HLL fluxes (with potential fallback). @@ -265,9 +264,10 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using HLL fluxes (with potential fallback), @@ -281,10 +281,11 @@ wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -295,9 +296,8 @@ qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the general relativistic magnetohydrodynamics equations with ideal gas equation of state is satisfied. @@ -306,9 +306,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -317,9 +315,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -328,9 +324,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -gr_mhd_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +gr_mhd_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variables. @@ -339,13 +334,12 @@ gr_mhd_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* di * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gr_mhd_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +gr_mhd_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free general relativistic magnetohydrodynamics equations object with ideal gas equation of state. * * @param ref Reference counter for general relativistic magnetohydrodynamics equations with ideal gas equation of state. */ -void gkyl_gr_mhd_free(const struct gkyl_ref_count* ref); +void gkyl_gr_mhd_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_gr_mhd_tetrad.h b/moments/zero/gkyl_wv_gr_mhd_tetrad.h index c324351c7d..0891bbb081 100644 --- a/moments/zero/gkyl_wv_gr_mhd_tetrad.h +++ b/moments/zero/gkyl_wv_gr_mhd_tetrad.h @@ -35,9 +35,10 @@ struct gkyl_wv_gr_mhd_tetrad_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the general relativistic magnetohydrodynamics equations object in the tetrad basis with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_mhd_tetrad_new(double gas_gamma, double light_speed, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, - struct gkyl_gr_spacetime* spacetime, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_gr_mhd_tetrad_new( + double gas_gamma, double light_speed, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, + int reinit_freq, struct gkyl_gr_spacetime *spacetime, bool use_gpu +); /** * Create a new general relativistic magnetohydrodynamics equations object in the tetrad basis with ideal gas equation of state, from an input context struct. @@ -45,8 +46,7 @@ gkyl_wv_gr_mhd_tetrad_new(double gas_gamma, double light_speed, double b_fact, e * @param inp Input context struct. * @return Pointer to the general relativistic magnetohydrodynamics equations object in the tetad basis with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_mhd_tetrad_inew(const struct gkyl_wv_gr_mhd_tetrad_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_gr_mhd_tetrad_inew(const struct gkyl_wv_gr_mhd_tetrad_inp *inp); /** * Get adiabatic index. @@ -54,8 +54,7 @@ gkyl_wv_gr_mhd_tetrad_inew(const struct gkyl_wv_gr_mhd_tetrad_inp* inp); * @param eqn General relativistic magnetohydrodynamics equations object in the tetrad basis with ideal gas equation of state. * @return Adiabatic index. */ -double -gkyl_wv_gr_mhd_tetrad_gas_gamma(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_mhd_tetrad_gas_gamma(const struct gkyl_wv_eqn *eqn); /** * Get speed of light. @@ -63,8 +62,7 @@ gkyl_wv_gr_mhd_tetrad_gas_gamma(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic magnetohydrodynamics equations object in the tetrad basis with ideal gas equation of state. * @return Speed of light. */ -double -gkyl_wv_gr_mhd_tetrad_light_speed(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_mhd_tetrad_light_speed(const struct gkyl_wv_eqn *eqn); /** * Get factor of speed of light for magnetic field correction. @@ -72,8 +70,7 @@ gkyl_wv_gr_mhd_tetrad_light_speed(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic magnetohydrodynamics equations object in the tetrad basis with ideal gas equation of state. * @return Factor of speed of light for magnetic field correction. */ -double -gkyl_wv_gr_mhd_tetrad_b_fact(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_mhd_tetrad_b_fact(const struct gkyl_wv_eqn *eqn); /** * Get spacetime gauge choice. @@ -81,8 +78,7 @@ gkyl_wv_gr_mhd_tetrad_b_fact(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic magnetohydrodynamics equations object in the tetrad basis with ideal gas equation of state. * @return Spacetime gauge choice. */ -enum gkyl_spacetime_gauge -gkyl_wv_gr_mhd_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn); +enum gkyl_spacetime_gauge gkyl_wv_gr_mhd_tetrad_spacetime_gauge(const struct gkyl_wv_eqn *eqn); /** * Get spacetime reinitialization frequency. @@ -90,8 +86,7 @@ gkyl_wv_gr_mhd_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic magnetohydrodynamics equations object in the tetrad basis with ideal gas equation of state. * @return Spacetime reinitialization frequency. */ -int -gkyl_wv_gr_mhd_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn); +int gkyl_wv_gr_mhd_tetrad_reinit_freq(const struct gkyl_wv_eqn *eqn); /** * Get base spacetime object. @@ -99,5 +94,4 @@ gkyl_wv_gr_mhd_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic magnetohydrodynamics equations object in the tetrad basis with ideal gas equation of state. * @return Pointer to the base spacetime object. */ -struct gkyl_gr_spacetime* -gkyl_wv_gr_mhd_tetrad_spacetime(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +struct gkyl_gr_spacetime *gkyl_wv_gr_mhd_tetrad_spacetime(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_gr_mhd_tetrad_priv.h b/moments/zero/gkyl_wv_gr_mhd_tetrad_priv.h index f41e66b42e..3be9ef6860 100644 --- a/moments/zero/gkyl_wv_gr_mhd_tetrad_priv.h +++ b/moments/zero/gkyl_wv_gr_mhd_tetrad_priv.h @@ -31,9 +31,9 @@ struct wv_gr_mhd_tetrad { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_mhd_tetrad_flux(double gas_gamma, double light_speed, double b_fact, const double q[75], double flux[75]); +GKYL_CU_D void gkyl_gr_mhd_tetrad_flux( + double gas_gamma, double light_speed, double b_fact, const double q[75], double flux[75] +); /** * Compute general relativistic correction to special relativistic flux. Assumes rotation to local coordinate system. @@ -44,9 +44,10 @@ gkyl_gr_mhd_tetrad_flux(double gas_gamma, double light_speed, double b_fact, con * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_mhd_tetrad_flux_correction(double gas_gamma, double light_speed, double b_fact, const double q[75], const double flux_sr[75], double flux_gr[75]); +GKYL_CU_D void gkyl_gr_mhd_tetrad_flux_correction( + double gas_gamma, double light_speed, double b_fact, const double q[75], const double flux_sr[75], + double flux_gr[75] +); /** * Compute primitive variables given the conserved variables. @@ -55,9 +56,7 @@ gkyl_gr_mhd_tetrad_flux_correction(double gas_gamma, double light_speed, double * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void -gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]); +GKYL_CU_D void gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]); /** * Compute inverse spatial metric tensor (in covariant component form) given the conserved variables. @@ -65,8 +64,7 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) * @param q Conserved variable vector. * @param inv_spatial_metric Inverse spatial metric tensor (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_mhd_tetrad_inv_spatial_metric(const double q[75], double ***inv_spatial_metric); /** @@ -76,9 +74,9 @@ gkyl_gr_mhd_tetrad_inv_spatial_metric(const double q[75], double ***inv_spatial_ * @param q Conserved variable vector. * @param stress_energy Stress-energy tensor (output). */ -GKYL_CU_D -void -gkyl_gr_mhd_tetrad_stress_energy_tensor(double gas_gamma, const double q[75], double ***stress_energy); +GKYL_CU_D void gkyl_gr_mhd_tetrad_stress_energy_tensor( + double gas_gamma, const double q[75], double ***stress_energy +); /** * Compute maximum absolute wave speed. @@ -87,8 +85,7 @@ gkyl_gr_mhd_tetrad_stress_energy_tensor(double gas_gamma, const double q[75], do * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double +GKYL_CU_D static inline double gkyl_gr_mhd_tetrad_max_abs_speed(double gas_gamma, const double q[71]); /** @@ -99,9 +96,8 @@ gkyl_gr_mhd_tetrad_max_abs_speed(double gas_gamma, const double q[71]); * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -111,9 +107,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the general relativistic magnetohydrodynamics equations in the tetrad basis with ideal gas equation of state. @@ -125,9 +120,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_mhd_tetrad_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_mhd_tetrad_tetrad_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the general relativistic magnetohydrodynamics equations in the tetrad basis with ideal gas equation of state. @@ -139,9 +135,10 @@ gr_mhd_tetrad_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_mhd_tetrad_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_mhd_tetrad_tetrad_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -153,10 +150,10 @@ gr_mhd_tetrad_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, co * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -168,10 +165,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -184,9 +181,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -199,9 +197,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -215,9 +214,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -231,10 +231,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using HLL fluxes. @@ -247,9 +248,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using HLL fluxes. @@ -262,9 +264,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using HLL fluxes (with potential fallback). @@ -278,9 +281,10 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using HLL fluxes (with potential fallback), @@ -294,10 +298,11 @@ wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -308,9 +313,8 @@ qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the general relativistic magnetohydrodynamics equations in the tetrad basis with ideal gas equation of state is satisfied. @@ -319,9 +323,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -330,9 +332,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -341,9 +341,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -gr_mhd_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +gr_mhd_tetrad_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variables. @@ -352,13 +351,12 @@ gr_mhd_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, dou * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gr_mhd_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +gr_mhd_tetrad_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free general relativistic magnetohydrodynamics equations object in the tetrad basis with ideal gas equation of state. * * @param ref Reference counter for general relativistic magnetohydrodynamics equations in the tetrad basis with ideal gas equation of state. */ -void gkyl_gr_mhd_tetrad_free(const struct gkyl_ref_count* ref); +void gkyl_gr_mhd_tetrad_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_gr_twofluid.h b/moments/zero/gkyl_wv_gr_twofluid.h index ad4cbb9026..149fa524f7 100644 --- a/moments/zero/gkyl_wv_gr_twofluid.h +++ b/moments/zero/gkyl_wv_gr_twofluid.h @@ -47,9 +47,12 @@ struct gkyl_wv_gr_twofluid_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the general relativistic two-fluid equations object with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_twofluid_new(double mass_elc, double mass_ion, double charge_elc, double charge_ion, double gas_gamma_elc, double gas_gamma_ion, - double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_gr_twofluid_new( + double mass_elc, double mass_ion, double charge_elc, double charge_ion, double gas_gamma_elc, + double gas_gamma_ion, double light_speed, double e_fact, double b_fact, + enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime *spacetime, + bool use_gpu +); /** * Create a new general relativistic two-fluid equations object with ideal gas equation of state, from an input context struct. @@ -57,8 +60,7 @@ gkyl_wv_gr_twofluid_new(double mass_elc, double mass_ion, double charge_elc, dou * @param inp Input context struct. * @return Pointer to the general relativistic two-fluid equations object with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_twofluid_inew(const struct gkyl_wv_gr_twofluid_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_gr_twofluid_inew(const struct gkyl_wv_gr_twofluid_inp *inp); /** * Get electron mass. @@ -66,8 +68,7 @@ gkyl_wv_gr_twofluid_inew(const struct gkyl_wv_gr_twofluid_inp* inp); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Electron mass. */ -double -gkyl_wv_gr_twofluid_mass_elc(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_mass_elc(const struct gkyl_wv_eqn *eqn); /** * Get ion mass. @@ -75,8 +76,7 @@ gkyl_wv_gr_twofluid_mass_elc(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Ion mass. */ -double -gkyl_wv_gr_twofluid_mass_ion(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_mass_ion(const struct gkyl_wv_eqn *eqn); /** * Get electron charge. @@ -84,8 +84,7 @@ gkyl_wv_gr_twofluid_mass_ion(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Electron charge. */ -double -gkyl_wv_gr_twofluid_charge_elc(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_charge_elc(const struct gkyl_wv_eqn *eqn); /** * Get ion charge. @@ -93,8 +92,7 @@ gkyl_wv_gr_twofluid_charge_elc(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Ion charge. */ -double -gkyl_wv_gr_twofluid_charge_ion(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_charge_ion(const struct gkyl_wv_eqn *eqn); /** * Get adiabatic index (electrons). @@ -102,8 +100,7 @@ gkyl_wv_gr_twofluid_charge_ion(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Adiabatic index (electrons). */ -double -gkyl_wv_gr_twofluid_gas_gamma_elc(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_gas_gamma_elc(const struct gkyl_wv_eqn *eqn); /** * Get adiabatic index (ions). @@ -111,8 +108,7 @@ gkyl_wv_gr_twofluid_gas_gamma_elc(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Adiabatic index (ions). */ -double -gkyl_wv_gr_twofluid_gas_gamma_ion(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_gas_gamma_ion(const struct gkyl_wv_eqn *eqn); /** * Get speed of light. @@ -120,8 +116,7 @@ gkyl_wv_gr_twofluid_gas_gamma_ion(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Speed of light. */ -double -gkyl_wv_gr_twofluid_light_speed(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_light_speed(const struct gkyl_wv_eqn *eqn); /** * Get factor of speed of light for electric field correction. @@ -129,8 +124,7 @@ gkyl_wv_gr_twofluid_light_speed(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Factor of speed of light for electric field correction. */ -double -gkyl_wv_gr_twofluid_e_fact(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_e_fact(const struct gkyl_wv_eqn *eqn); /** * Get factor of speed of light for magnetic field correction. @@ -138,8 +132,7 @@ gkyl_wv_gr_twofluid_e_fact(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Factor of speed of light for magnetic field correction. */ -double -gkyl_wv_gr_twofluid_b_fact(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_b_fact(const struct gkyl_wv_eqn *eqn); /** * Get spacetime gauge choice. @@ -147,8 +140,7 @@ gkyl_wv_gr_twofluid_b_fact(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Spacetime gauge choice. */ -enum gkyl_spacetime_gauge -gkyl_wv_gr_twofluid_spacetime_gauge(const struct gkyl_wv_eqn* eqn); +enum gkyl_spacetime_gauge gkyl_wv_gr_twofluid_spacetime_gauge(const struct gkyl_wv_eqn *eqn); /** * Get spacetime reinitialization frequency. @@ -156,8 +148,7 @@ gkyl_wv_gr_twofluid_spacetime_gauge(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Spacetime reinitialization frequency. */ -int -gkyl_wv_gr_twofluid_reinit_freq(const struct gkyl_wv_eqn* eqn); +int gkyl_wv_gr_twofluid_reinit_freq(const struct gkyl_wv_eqn *eqn); /** * Get base spacetime object. @@ -165,5 +156,4 @@ gkyl_wv_gr_twofluid_reinit_freq(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object with ideal gas equation of state. * @return Pointer to the base spacetime object. */ -struct gkyl_gr_spacetime* -gkyl_wv_gr_twofluid_spacetime(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +struct gkyl_gr_spacetime *gkyl_wv_gr_twofluid_spacetime(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_gr_twofluid_priv.h b/moments/zero/gkyl_wv_gr_twofluid_priv.h index 1697e2de79..cd427ab2f6 100644 --- a/moments/zero/gkyl_wv_gr_twofluid_priv.h +++ b/moments/zero/gkyl_wv_gr_twofluid_priv.h @@ -39,9 +39,10 @@ struct wv_gr_twofluid { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_twofluid_flux(double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, const double q[84], double flux[84]); +GKYL_CU_D void gkyl_gr_twofluid_flux( + double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, + const double q[84], double flux[84] +); /** * Compute primitive variables given the conserved variables. @@ -51,9 +52,9 @@ gkyl_gr_twofluid_flux(double gas_gamma_elc, double gas_gamma_ion, double light_s * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void -gkyl_gr_twofluid_prim_vars(double gas_gamma_elc, double gas_gama_ion, const double q[84], double v[84]); +GKYL_CU_D void gkyl_gr_twofluid_prim_vars( + double gas_gamma_elc, double gas_gama_ion, const double q[84], double v[84] +); /** * Compute inverse spatial metric tensor (in covariant component form) given the conserved variables. @@ -61,8 +62,7 @@ gkyl_gr_twofluid_prim_vars(double gas_gamma_elc, double gas_gama_ion, const doub * @param q Conserved variable vector. * @param inv_spatial_metric Inverse spatial metric tensor (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_twofluid_inv_spatial_metric(const double q[84], double ***inv_spatial_metric); /** @@ -73,9 +73,9 @@ gkyl_gr_twofluid_inv_spatial_metric(const double q[84], double ***inv_spatial_me * @param q Conserved variable vector. * @param stress_energy Stress-energy tensor (output). */ -GKYL_CU_D -void -gkyl_gr_twofluid_stress_energy_tensor_elc(double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_elc); +GKYL_CU_D void gkyl_gr_twofluid_stress_energy_tensor_elc( + double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_elc +); /** * Compute perfect fluid stress-energy tensor (in contravariant component form) for the ions, given the conserved variables. @@ -85,9 +85,9 @@ gkyl_gr_twofluid_stress_energy_tensor_elc(double gas_gamma_elc, double gas_gamma * @param q Conserved variable vector. * @param stress_energy Stress-energy tensor (output). */ -GKYL_CU_D -void -gkyl_gr_twofluid_stress_energy_tensor_ion(double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_ion); +GKYL_CU_D void gkyl_gr_twofluid_stress_energy_tensor_ion( + double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_ion +); /** * Compute maximum absolute wave speed. @@ -98,9 +98,9 @@ gkyl_gr_twofluid_stress_energy_tensor_ion(double gas_gamma_elc, double gas_gamma * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, double light_speed, const double q[84]); +GKYL_CU_D static inline double gkyl_gr_twofluid_max_abs_speed( + double gas_gamma_elc, double gas_gamma_ion, double light_speed, const double q[84] +); /** * Compute Riemann variables given the conserved variables. @@ -110,9 +110,8 @@ gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, doubl * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -122,9 +121,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the general relativistic two-fluid equations with ideal gas equation of state. @@ -136,9 +134,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_twofluid_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_twofluid_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the general relativistic two-fluid equations with ideal gas equation of state. @@ -150,9 +149,10 @@ gr_twofluid_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_twofluid_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_twofluid_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -164,10 +164,10 @@ gr_twofluid_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const doubl * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -179,10 +179,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -195,9 +195,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -210,9 +211,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -226,9 +228,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -242,10 +245,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using HLL fluxes. @@ -258,9 +262,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using HLL fluxes. @@ -273,9 +278,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using HLL fluxes (with potential fallback). @@ -289,9 +295,10 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using HLL fluxes (with potential fallback), @@ -305,10 +312,11 @@ wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -319,9 +327,8 @@ qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the general relativistic two-fluid equations with ideal gas equation of state is satisfied. @@ -330,9 +337,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -341,9 +346,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -352,9 +355,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -gr_twofluid_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +gr_twofluid_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variables. @@ -363,13 +365,12 @@ gr_twofluid_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, doubl * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gr_twofluid_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +gr_twofluid_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free general relativistic two-fluid equations object with ideal gas equation of state. * * @param ref Reference counter for general relativistic two-fluid equations with ideal gas equation of state. */ -void gkyl_gr_twofluid_free(const struct gkyl_ref_count* ref); +void gkyl_gr_twofluid_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_gr_twofluid_tetrad.h b/moments/zero/gkyl_wv_gr_twofluid_tetrad.h index 2839cf5836..a5421c1d30 100644 --- a/moments/zero/gkyl_wv_gr_twofluid_tetrad.h +++ b/moments/zero/gkyl_wv_gr_twofluid_tetrad.h @@ -47,9 +47,12 @@ struct gkyl_wv_gr_twofluid_tetrad_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the general relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_twofluid_tetrad_new(double mass_elc, double mass_ion, double charge_elc, double charge_ion, double gas_gamma_elc, double gas_gamma_ion, - double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_gr_twofluid_tetrad_new( + double mass_elc, double mass_ion, double charge_elc, double charge_ion, double gas_gamma_elc, + double gas_gamma_ion, double light_speed, double e_fact, double b_fact, + enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime *spacetime, + bool use_gpu +); /** * Create a new general relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state, from an input context struct. @@ -57,8 +60,8 @@ gkyl_wv_gr_twofluid_tetrad_new(double mass_elc, double mass_ion, double charge_e * @param inp Input context struct. * @return Pointer to the general relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_twofluid_tetrad_inew(const struct gkyl_wv_gr_twofluid_tetrad_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_gr_twofluid_tetrad_inew(const struct gkyl_wv_gr_twofluid_tetrad_inp *inp +); /** * Get electron mass. @@ -66,8 +69,7 @@ gkyl_wv_gr_twofluid_tetrad_inew(const struct gkyl_wv_gr_twofluid_tetrad_inp* inp * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Electron mass. */ -double -gkyl_wv_gr_twofluid_tetrad_mass_elc(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_tetrad_mass_elc(const struct gkyl_wv_eqn *eqn); /** * Get ion mass. @@ -75,8 +77,7 @@ gkyl_wv_gr_twofluid_tetrad_mass_elc(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Ion mass. */ -double -gkyl_wv_gr_twofluid_tetrad_mass_ion(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_tetrad_mass_ion(const struct gkyl_wv_eqn *eqn); /** * Get electron charge. @@ -84,8 +85,7 @@ gkyl_wv_gr_twofluid_tetrad_mass_ion(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Electron charge. */ -double -gkyl_wv_gr_twofluid_tetrad_charge_elc(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_tetrad_charge_elc(const struct gkyl_wv_eqn *eqn); /** * Get ion charge. @@ -93,8 +93,7 @@ gkyl_wv_gr_twofluid_tetrad_charge_elc(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Ion charge. */ -double -gkyl_wv_gr_twofluid_tetrad_charge_ion(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_tetrad_charge_ion(const struct gkyl_wv_eqn *eqn); /** * Get adiabatic index (electrons). @@ -102,8 +101,7 @@ gkyl_wv_gr_twofluid_tetrad_charge_ion(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Adiabatic index (electrons). */ -double -gkyl_wv_gr_twofluid_tetrad_gas_gamma_elc(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_tetrad_gas_gamma_elc(const struct gkyl_wv_eqn *eqn); /** * Get adiabatic index (ions). @@ -111,8 +109,7 @@ gkyl_wv_gr_twofluid_tetrad_gas_gamma_elc(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Adiabatic index (ions). */ -double -gkyl_wv_gr_twofluid_tetrad_gas_gamma_ion(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_tetrad_gas_gamma_ion(const struct gkyl_wv_eqn *eqn); /** * Get speed of light. @@ -120,8 +117,7 @@ gkyl_wv_gr_twofluid_tetrad_gas_gamma_ion(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Speed of light. */ -double -gkyl_wv_gr_twofluid_tetrad_light_speed(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_tetrad_light_speed(const struct gkyl_wv_eqn *eqn); /** * Get factor of speed of light for electric field correction. @@ -129,8 +125,7 @@ gkyl_wv_gr_twofluid_tetrad_light_speed(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Factor of speed of light for electric field correction. */ -double -gkyl_wv_gr_twofluid_tetrad_e_fact(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_tetrad_e_fact(const struct gkyl_wv_eqn *eqn); /** * Get factor of speed of light for magnetic field correction. @@ -138,8 +133,7 @@ gkyl_wv_gr_twofluid_tetrad_e_fact(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Factor of speed of light for magnetic field correction. */ -double -gkyl_wv_gr_twofluid_tetrad_b_fact(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_twofluid_tetrad_b_fact(const struct gkyl_wv_eqn *eqn); /** * Get spacetime gauge choice. @@ -147,8 +141,7 @@ gkyl_wv_gr_twofluid_tetrad_b_fact(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Spacetime gauge choice. */ -enum gkyl_spacetime_gauge -gkyl_wv_gr_twofluid_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn); +enum gkyl_spacetime_gauge gkyl_wv_gr_twofluid_tetrad_spacetime_gauge(const struct gkyl_wv_eqn *eqn); /** * Get spacetime reinitialization frequency. @@ -156,8 +149,7 @@ gkyl_wv_gr_twofluid_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Spacetime reinitialization frequency. */ -int -gkyl_wv_gr_twofluid_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn); +int gkyl_wv_gr_twofluid_tetrad_reinit_freq(const struct gkyl_wv_eqn *eqn); /** * Get base spacetime object. @@ -165,5 +157,4 @@ gkyl_wv_gr_twofluid_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * @return Pointer to the base spacetime object. */ -struct gkyl_gr_spacetime* -gkyl_wv_gr_twofluid_tetrad_spacetime(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +struct gkyl_gr_spacetime *gkyl_wv_gr_twofluid_tetrad_spacetime(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_gr_twofluid_tetrad_priv.h b/moments/zero/gkyl_wv_gr_twofluid_tetrad_priv.h index 97a8d7f5c9..a7d8c37d79 100644 --- a/moments/zero/gkyl_wv_gr_twofluid_tetrad_priv.h +++ b/moments/zero/gkyl_wv_gr_twofluid_tetrad_priv.h @@ -39,9 +39,10 @@ struct wv_gr_twofluid_tetrad { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_twofluid_tetrad_flux(double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, const double q[84], double flux[84]); +GKYL_CU_D void gkyl_gr_twofluid_tetrad_flux( + double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, + const double q[84], double flux[84] +); /** * Compute general relativistic correction to special relativistic flux. Assumes rotation to local coordinate system. @@ -55,9 +56,10 @@ gkyl_gr_twofluid_tetrad_flux(double gas_gamma_elc, double gas_gamma_ion, double * @param flux_sr Special relativistic flux vector in direction 'dir'. * @param flux_gr General relativistic flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_twofluid_tetrad_flux_correction(double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, const double q[84], const double flux_sr[84], double flux_gr[84]); +GKYL_CU_D void gkyl_gr_twofluid_tetrad_flux_correction( + double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, + const double q[84], const double flux_sr[84], double flux_gr[84] +); /** * Compute primitive variables given the conserved variables. @@ -67,9 +69,9 @@ gkyl_gr_twofluid_tetrad_flux_correction(double gas_gamma_elc, double gas_gamma_i * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void -gkyl_gr_twofluid_tetrad_prim_vars(double gas_gamma_elc, double gas_gama_ion, const double q[84], double v[84]); +GKYL_CU_D void gkyl_gr_twofluid_tetrad_prim_vars( + double gas_gamma_elc, double gas_gama_ion, const double q[84], double v[84] +); /** * Compute inverse spatial metric tensor (in covariant component form) given the conserved variables. @@ -77,8 +79,7 @@ gkyl_gr_twofluid_tetrad_prim_vars(double gas_gamma_elc, double gas_gama_ion, con * @param q Conserved variable vector. * @param inv_spatial_metric Inverse spatial metric tensor (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_twofluid_tetrad_inv_spatial_metric(const double q[84], double ***inv_spatial_metric); /** @@ -89,9 +90,9 @@ gkyl_gr_twofluid_tetrad_inv_spatial_metric(const double q[84], double ***inv_spa * @param q Conserved variable vector. * @param stress_energy Stress-energy tensor (output). */ -GKYL_CU_D -void -gkyl_gr_twofluid_tetrad_stress_energy_tensor_elc(double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_elc); +GKYL_CU_D void gkyl_gr_twofluid_tetrad_stress_energy_tensor_elc( + double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_elc +); /** * Compute perfect fluid stress-energy tensor (in contravariant component form) for the ions, given the conserved variables. @@ -101,9 +102,9 @@ gkyl_gr_twofluid_tetrad_stress_energy_tensor_elc(double gas_gamma_elc, double ga * @param q Conserved variable vector. * @param stress_energy Stress-energy tensor (output). */ -GKYL_CU_D -void -gkyl_gr_twofluid_tetrad_tress_energy_tensor_ion(double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_ion); +GKYL_CU_D void gkyl_gr_twofluid_tetrad_tress_energy_tensor_ion( + double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_ion +); /** * Compute maximum absolute wave speed. @@ -114,9 +115,9 @@ gkyl_gr_twofluid_tetrad_tress_energy_tensor_ion(double gas_gamma_elc, double gas * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, double light_speed, const double q[84]); +GKYL_CU_D static inline double gkyl_gr_twofluid_tetrad_max_abs_speed( + double gas_gamma_elc, double gas_gamma_ion, double light_speed, const double q[84] +); /** * Compute Riemann variables given the conserved variables. @@ -126,9 +127,8 @@ gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -138,9 +138,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the general relativistic two-fluid equations in the tetrad basis with ideal gas equation of state. @@ -152,9 +151,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_twofluid_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_twofluid_tetrad_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the general relativistic two-fluid equations in the tetrad basis with ideal gas equation of state. @@ -166,9 +166,10 @@ gr_twofluid_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const d * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_twofluid_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_twofluid_tetrad_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -180,10 +181,10 @@ gr_twofluid_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, cons * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -195,10 +196,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -211,9 +212,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -226,9 +228,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -242,9 +245,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -258,10 +262,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using HLL fluxes. @@ -274,9 +279,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using HLL fluxes. @@ -289,9 +295,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using HLL fluxes (with potential fallback). @@ -305,9 +312,10 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using HLL fluxes (with potential fallback), @@ -321,10 +329,11 @@ wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -335,9 +344,8 @@ qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the general relativistic two-fluid equations in the tetrad basis with ideal gas equation of state is satisfied. @@ -346,9 +354,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -357,9 +363,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -368,9 +372,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -gr_twofluid_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +gr_twofluid_tetrad_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variables. @@ -379,14 +382,12 @@ gr_twofluid_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gr_twofluid_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +gr_twofluid_tetrad_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free general relativistic two-fluid equations object in the tetrad basis with ideal gas equation of state. * * @param ref Reference counter for general relativistic two-fluid equations in the tetrad basis with ideal gas equation of state. */ -void -gkyl_gr_twofluid_tetrad_free(const struct gkyl_ref_count* ref); +void gkyl_gr_twofluid_tetrad_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_gr_ultra_rel_euler.h b/moments/zero/gkyl_wv_gr_ultra_rel_euler.h index cec6c1a2bb..dd1d1b2b28 100644 --- a/moments/zero/gkyl_wv_gr_ultra_rel_euler.h +++ b/moments/zero/gkyl_wv_gr_ultra_rel_euler.h @@ -7,7 +7,7 @@ enum gkyl_wv_gr_ultra_rel_euler_rp { WV_GR_ULTRA_REL_EULER_RP_HLL = 0, // Default (HLL fluxes). WV_GR_ULTRA_REL_EULER_RP_ROE, - WV_GR_ULTRA_REL_EULER_RP_LAX, + WV_GR_ULTRA_REL_EULER_RP_LAX }; // Input context, packaged as a struct. @@ -31,8 +31,10 @@ struct gkyl_wv_gr_ultra_rel_euler_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the general relativistic Euler equations object with ultra-relativistic equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_ultra_rel_euler_new(double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_gr_ultra_rel_euler_new( + double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, + struct gkyl_gr_spacetime *spacetime, bool use_gpu +); /** * Create a new general relativistic Euler equations object with ultra-relativistic equation of state, from an input context struct. @@ -40,8 +42,8 @@ gkyl_wv_gr_ultra_rel_euler_new(double gas_gamma, enum gkyl_spacetime_gauge space * @param inp Input context struct. * @return Pointer to the general relativistic Euler equations object with ultra-relativistic equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_ultra_rel_euler_inew(const struct gkyl_wv_gr_ultra_rel_euler_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_gr_ultra_rel_euler_inew(const struct gkyl_wv_gr_ultra_rel_euler_inp *inp +); /** * Get adiabatic index. @@ -49,8 +51,7 @@ gkyl_wv_gr_ultra_rel_euler_inew(const struct gkyl_wv_gr_ultra_rel_euler_inp* inp * @param eqn General relativistic Euler equations object with ultra-relativistic equation of state. * @return Adiabatic index. */ -double -gkyl_wv_gr_ultra_rel_euler_gas_gamma(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_ultra_rel_euler_gas_gamma(const struct gkyl_wv_eqn *eqn); /** * Get spacetime gauge choice. @@ -58,8 +59,7 @@ gkyl_wv_gr_ultra_rel_euler_gas_gamma(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Euler equations object with ultra-relativistic equation of state. * @return Spacetime gauge choice. */ -enum gkyl_spacetime_gauge -gkyl_wv_gr_ultra_rel_euler_spacetime_gauge(const struct gkyl_wv_eqn* eqn); +enum gkyl_spacetime_gauge gkyl_wv_gr_ultra_rel_euler_spacetime_gauge(const struct gkyl_wv_eqn *eqn); /** * Get spacetime reinitialization frequency. @@ -67,8 +67,7 @@ gkyl_wv_gr_ultra_rel_euler_spacetime_gauge(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Euler equations object with ultra-relativistic equation of state. * @return Spacetime reinitialization frequency. */ -int -gkyl_wv_gr_ultra_rel_euler_reinit_freq(const struct gkyl_wv_eqn* eqn); +int gkyl_wv_gr_ultra_rel_euler_reinit_freq(const struct gkyl_wv_eqn *eqn); /** * Get base spacetime object. @@ -76,5 +75,4 @@ gkyl_wv_gr_ultra_rel_euler_reinit_freq(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Euler equations object with ultra-relativistic equation of state. * @return Pointer to the base spacetime object. */ -struct gkyl_gr_spacetime* -gkyl_wv_gr_ultra_rel_euler_spacetime(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +struct gkyl_gr_spacetime *gkyl_wv_gr_ultra_rel_euler_spacetime(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_gr_ultra_rel_euler_priv.h b/moments/zero/gkyl_wv_gr_ultra_rel_euler_priv.h index 96ebf51793..37fb1292b0 100644 --- a/moments/zero/gkyl_wv_gr_ultra_rel_euler_priv.h +++ b/moments/zero/gkyl_wv_gr_ultra_rel_euler_priv.h @@ -26,9 +26,7 @@ struct wv_gr_ultra_rel_euler { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_ultra_rel_euler_flux(double gas_gamma, const double q[70], double flux[70]); +GKYL_CU_D void gkyl_gr_ultra_rel_euler_flux(double gas_gamma, const double q[70], double flux[70]); /** * Compute primitive variables given the conserved variables. @@ -37,8 +35,7 @@ gkyl_gr_ultra_rel_euler_flux(double gas_gamma, const double q[70], double flux[7 * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v[70]); /** @@ -47,8 +44,7 @@ gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v * @param q Conserved variable vector. * @param inv_spatial_metric Inverse spatial metric tensor (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_ultra_rel_euler_inv_spatial_metric(const double q[70], double ***inv_spatial_metric); /** @@ -58,9 +54,9 @@ gkyl_gr_ultra_rel_euler_inv_spatial_metric(const double q[70], double ***inv_spa * @param q Conserved variable vector. * @param stress_energy Stress-energy tensor (output). */ -GKYL_CU_D -void -gkyl_gr_ultra_rel_euler_stress_energy_tensor(double gas_gamma, const double q[70], double ***stress_energy); +GKYL_CU_D void gkyl_gr_ultra_rel_euler_stress_energy_tensor( + double gas_gamma, const double q[70], double ***stress_energy +); /** * Compute maximum absolute wave speed. @@ -69,8 +65,7 @@ gkyl_gr_ultra_rel_euler_stress_energy_tensor(double gas_gamma, const double q[70 * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double +GKYL_CU_D static inline double gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]); /** @@ -81,9 +76,8 @@ gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]); * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -93,9 +87,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the general relativistic Euler equations with ultra-relativistic equation of state. @@ -107,9 +100,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_ultra_rel_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_ultra_rel_euler_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the general relativistic Euler equations with ultra-relativistic equation of state. @@ -121,9 +115,10 @@ gr_ultra_rel_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const d * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_ultra_rel_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_ultra_rel_euler_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -135,10 +130,10 @@ gr_ultra_rel_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, cons * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -150,10 +145,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -166,9 +161,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -181,9 +177,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -197,9 +194,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -213,10 +211,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -229,9 +228,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -244,9 +244,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -260,9 +261,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback). @@ -276,10 +278,11 @@ wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param qpdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using HLL fluxes. @@ -292,9 +295,10 @@ qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using HLL fluxes. @@ -307,9 +311,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using HLL fluxes (with potential fallback). @@ -323,9 +328,10 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using HLL fluxes (with potential fallback), @@ -339,10 +345,11 @@ wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -353,9 +360,8 @@ qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the general relativistic Euler equations with ultra-relativistic equation of state is satisfied. @@ -364,9 +370,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -375,9 +379,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -386,9 +388,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -gr_ultra_rel_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +gr_ultra_rel_euler_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variable. @@ -397,13 +398,12 @@ gr_ultra_rel_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gr_ultra_rel_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +gr_ultra_rel_euler_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free general relativistic Euler equations object with ultra-relativistic equation of state. * * @param ref Reference counter for general relativistic Euler equations with ultra-relativistic equation of state. */ -void gkyl_gr_ultra_rel_euler_free(const struct gkyl_ref_count* ref); +void gkyl_gr_ultra_rel_euler_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_gr_ultra_rel_euler_tetrad.h b/moments/zero/gkyl_wv_gr_ultra_rel_euler_tetrad.h index f9b99a21b6..c9b90f8e5f 100644 --- a/moments/zero/gkyl_wv_gr_ultra_rel_euler_tetrad.h +++ b/moments/zero/gkyl_wv_gr_ultra_rel_euler_tetrad.h @@ -7,7 +7,7 @@ enum gkyl_wv_gr_ultra_rel_euler_tetrad_rp { WV_GR_ULTRA_REL_EULER_TETRAD_RP_HLL = 0, // Default (HLL fluxes). WV_GR_ULTRA_REL_EULER_TETRAD_RP_ROE, - WV_GR_ULTRA_REL_EULER_TETRAD_RP_LAX, + WV_GR_ULTRA_REL_EULER_TETRAD_RP_LAX }; // Input context, packaged as a struct. @@ -31,8 +31,10 @@ struct gkyl_wv_gr_ultra_rel_euler_tetrad_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the general relativistic Euler equations object in the tetrad basis with ultra-relativistic equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_ultra_rel_euler_tetrad_new(double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_gr_ultra_rel_euler_tetrad_new( + double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, + struct gkyl_gr_spacetime *spacetime, bool use_gpu +); /** * Create a new general relativistic Euler equations object in the tetrad basis with ultra-relativistic equation of state, from an input context struct. @@ -40,8 +42,8 @@ gkyl_wv_gr_ultra_rel_euler_tetrad_new(double gas_gamma, enum gkyl_spacetime_gaug * @param inp Input context struct. * @return Pointer to the general relativistic Euler equations object in the tetrad basis with ultra-relativistic equation of state. */ -struct gkyl_wv_eqn* -gkyl_wv_gr_ultra_rel_euler_tetrad_inew(const struct gkyl_wv_gr_ultra_rel_euler_tetrad_inp* inp); +struct gkyl_wv_eqn * +gkyl_wv_gr_ultra_rel_euler_tetrad_inew(const struct gkyl_wv_gr_ultra_rel_euler_tetrad_inp *inp); /** * Get adiabatic index. @@ -49,8 +51,7 @@ gkyl_wv_gr_ultra_rel_euler_tetrad_inew(const struct gkyl_wv_gr_ultra_rel_euler_t * @param eqn General relativistic Euler equations object in the tetrad basis with ultra-relativistic equation of state. * @return Adiabatic index. */ -double -gkyl_wv_gr_ultra_rel_euler_tetrad_gas_gamma(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_gr_ultra_rel_euler_tetrad_gas_gamma(const struct gkyl_wv_eqn *eqn); /** * Get spacetime gauge choice. @@ -59,7 +60,7 @@ gkyl_wv_gr_ultra_rel_euler_tetrad_gas_gamma(const struct gkyl_wv_eqn* eqn); * @return Spacetime gauge choice. */ enum gkyl_spacetime_gauge -gkyl_wv_gr_ultra_rel_euler_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn); +gkyl_wv_gr_ultra_rel_euler_tetrad_spacetime_gauge(const struct gkyl_wv_eqn *eqn); /** * Get spacetime reinitialization frequency. @@ -67,8 +68,7 @@ gkyl_wv_gr_ultra_rel_euler_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn) * @param eqn General relativistic Euler equations object in the tetrad basis with ultra-relativistic equation of state. * @return Spacetime reinitialization frequency. */ -int -gkyl_wv_gr_ultra_rel_euler_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn); +int gkyl_wv_gr_ultra_rel_euler_tetrad_reinit_freq(const struct gkyl_wv_eqn *eqn); /** * Get base spacetime object. @@ -76,5 +76,5 @@ gkyl_wv_gr_ultra_rel_euler_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn); * @param eqn General relativistic Euler equations object in the tetrad basis with ultra-relativistic equation of state. * @return Pointer to the base spacetime object. */ -struct gkyl_gr_spacetime* -gkyl_wv_gr_ultra_rel_euler_tetrad_spacetime(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +struct gkyl_gr_spacetime *gkyl_wv_gr_ultra_rel_euler_tetrad_spacetime(const struct gkyl_wv_eqn *eqn +); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_gr_ultra_rel_euler_tetrad_priv.h b/moments/zero/gkyl_wv_gr_ultra_rel_euler_tetrad_priv.h index 0484ad279a..e23d6eb1a9 100644 --- a/moments/zero/gkyl_wv_gr_ultra_rel_euler_tetrad_priv.h +++ b/moments/zero/gkyl_wv_gr_ultra_rel_euler_tetrad_priv.h @@ -26,8 +26,7 @@ struct wv_gr_ultra_rel_euler_tetrad { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_ultra_rel_euler_tetrad_flux(double gas_gamma, const double q[27], double flux[27]); /** @@ -38,9 +37,9 @@ gkyl_gr_ultra_rel_euler_tetrad_flux(double gas_gamma, const double q[27], double * @param flux_sr Special relativistic flux vector in direction 'dir'. * @param flux_gr General relativistic flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_gr_ultra_rel_euler_tetrad_flux_correction(double gas_gamma, const double q[27], const double flux_sr[27], double flux_gr[27]); +GKYL_CU_D void gkyl_gr_ultra_rel_euler_tetrad_flux_correction( + double gas_gamma, const double q[27], const double flux_sr[27], double flux_gr[27] +); /** * Compute primitive variables given the conserved variables. @@ -49,8 +48,7 @@ gkyl_gr_ultra_rel_euler_tetrad_flux_correction(double gas_gamma, const double q[ * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[27], double v[27]); /** @@ -59,8 +57,7 @@ gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[27], d * @param q Conserved variable vector. * @param inv_spatial_metric Inverse spatial metric tensor (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_gr_ultra_rel_euler_tetrad_inv_spatial_metric(const double q[27], double ***inv_spatial_metric); /** @@ -70,9 +67,9 @@ gkyl_gr_ultra_rel_euler_tetrad_inv_spatial_metric(const double q[27], double *** * @param q Conserved variable vector. * @param stress_energy Stress-energy tensor (output). */ -GKYL_CU_D -void -gkyl_gr_ultra_rel_euler_tetrad_stress_energy_tensor(double gas_gamma, const double q[27], double ***stress_energy); +GKYL_CU_D void gkyl_gr_ultra_rel_euler_tetrad_stress_energy_tensor( + double gas_gamma, const double q[27], double ***stress_energy +); /** * Compute maximum absolute wave speed. @@ -81,8 +78,7 @@ gkyl_gr_ultra_rel_euler_tetrad_stress_energy_tensor(double gas_gamma, const doub * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double +GKYL_CU_D static inline double gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(double gas_gamma, const double q[27]); /** @@ -93,9 +89,8 @@ gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(double gas_gamma, const double q[27 * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -105,9 +100,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the general relativistic Euler equations in the tetrad basis with ultra-relativistic equation of state. @@ -119,9 +113,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_ultra_rel_euler_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_ultra_rel_euler_tetrad_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the general relativistic Euler equations in the tetrad basis with ultra-relativistic equation of state. @@ -133,9 +128,10 @@ gr_ultra_rel_euler_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -gr_ultra_rel_euler_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void gr_ultra_rel_euler_tetrad_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -147,10 +143,10 @@ gr_ultra_rel_euler_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int n * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -162,10 +158,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -178,9 +174,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -193,9 +190,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -209,9 +207,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -225,10 +224,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -241,9 +241,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -256,9 +257,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -272,9 +274,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback). @@ -288,10 +291,11 @@ wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param qpdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using HLL fluxes. @@ -304,9 +308,10 @@ qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using HLL fluxes. @@ -319,9 +324,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using HLL fluxes (with potential fallback). @@ -335,9 +341,10 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using HLL fluxes (with potential fallback), @@ -351,10 +358,11 @@ wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -365,9 +373,8 @@ qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the general relativistic Euler equations in the tetrad basis with ultra-relativistic equation of state is satisfied. @@ -376,9 +383,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -387,9 +392,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -398,9 +401,9 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -gr_ultra_rel_euler_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void gr_ultra_rel_euler_tetrad_cons_to_diag( + const struct gkyl_wv_eqn *eqn, const double *qin, double *diag +); /** * Compute forcing/source term vector from conserved variables. @@ -409,13 +412,12 @@ gr_ultra_rel_euler_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const doub * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -gr_ultra_rel_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +gr_ultra_rel_euler_tetrad_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free general relativistic Euler equations object in the tetrad basis with ultra-relativistic equation of state. * * @param ref Reference counter for general relativistic Euler equations in the tetrad basis with ultra-relativistic equation of state. */ -void gkyl_gr_ultra_rel_euler_tetrad_free(const struct gkyl_ref_count* ref); +void gkyl_gr_ultra_rel_euler_tetrad_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_iso_euler.h b/moments/zero/gkyl_wv_iso_euler.h index 62580c384a..517f9ea92f 100644 --- a/moments/zero/gkyl_wv_iso_euler.h +++ b/moments/zero/gkyl_wv_iso_euler.h @@ -23,7 +23,7 @@ // Type of Riemann-solver to use: enum gkyl_wv_iso_euler_rp { WV_ISO_EULER_RP_LAX = 0, // Default (Lax fluxes). - WV_ISO_EULER_RP_ROE, + WV_ISO_EULER_RP_ROE }; // Input context, packaged as a struct. @@ -41,8 +41,7 @@ struct gkyl_wv_iso_euler_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the isothermal Euler equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_iso_euler_new(double vt, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_iso_euler_new(double vt, bool use_gpu); /** * Create a new isothermal Euler equations object, from an input context struct. @@ -50,8 +49,7 @@ gkyl_wv_iso_euler_new(double vt, bool use_gpu); * @param inp Input context struct. * @return Pointer to the isothermal Euler equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_iso_euler_inew(const struct gkyl_wv_iso_euler_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_iso_euler_inew(const struct gkyl_wv_iso_euler_inp *inp); /** * Get thermal velocity. @@ -59,4 +57,4 @@ gkyl_wv_iso_euler_inew(const struct gkyl_wv_iso_euler_inp* inp); * @param wv Isothermal Euler equations object. * @return Thermal velocity. */ - double gkyl_wv_iso_euler_vt(const struct gkyl_wv_eqn* wv); \ No newline at end of file +double gkyl_wv_iso_euler_vt(const struct gkyl_wv_eqn *wv); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_iso_euler_mixture.h b/moments/zero/gkyl_wv_iso_euler_mixture.h index 10003f7270..23255d554c 100644 --- a/moments/zero/gkyl_wv_iso_euler_mixture.h +++ b/moments/zero/gkyl_wv_iso_euler_mixture.h @@ -5,13 +5,13 @@ // Type of Riemann-solver to use: enum gkyl_wv_iso_euler_mixture_rp { WV_ISO_EULER_MIXTURE_RP_LAX = 0, // Default (Lax fluxes). - WV_ISO_EULER_MIXTURE_RP_ROE, + WV_ISO_EULER_MIXTURE_RP_ROE }; // Input context, packaged as a struct. struct gkyl_wv_iso_euler_mixture_inp { int num_species; // Number of distinct species in mixture. - double* vt_s; // Thermal velocities for each species in mixture. + double *vt_s; // Thermal velocities for each species in mixture. enum gkyl_wv_iso_euler_mixture_rp rp_type; // Type of Riemann-solver to use. bool use_gpu; // Whether the wave equation object is on the host (false) or the device (true). @@ -25,8 +25,7 @@ struct gkyl_wv_iso_euler_mixture_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the isothermal Euler mixture equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_iso_euler_mixture_new(int num_species, double* vt_s, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_iso_euler_mixture_new(int num_species, double *vt_s, bool use_gpu); /** * Create a new isothermal Euler mixture equations object, from an input context struct. @@ -34,8 +33,7 @@ gkyl_wv_iso_euler_mixture_new(int num_species, double* vt_s, bool use_gpu); * @param inp Input context struct. * @return Pointer to the isothermal Euler mixture equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_iso_euler_mixture_inew(const struct gkyl_wv_iso_euler_mixture_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_iso_euler_mixture_inew(const struct gkyl_wv_iso_euler_mixture_inp *inp); /** * Get number of distinct species in mixture. @@ -43,8 +41,7 @@ gkyl_wv_iso_euler_mixture_inew(const struct gkyl_wv_iso_euler_mixture_inp* inp); * @param wv Isothermal Euler mixture equations object. * @return Number of distinct species in mixture. */ -int -gkyl_wv_iso_euler_mixture_num_species(const struct gkyl_wv_eqn* wv); +int gkyl_wv_iso_euler_mixture_num_species(const struct gkyl_wv_eqn *wv); /** * Get thermal velocities for each species in mixture. @@ -52,5 +49,4 @@ gkyl_wv_iso_euler_mixture_num_species(const struct gkyl_wv_eqn* wv); * @param wv Isothermal Euler mixture equations object. * @return Thermal velocities for each species in mixture. */ -double* -gkyl_wv_iso_euler_mixture_gas_gamma_s(const struct gkyl_wv_eqn* wv); \ No newline at end of file +double *gkyl_wv_iso_euler_mixture_gas_gamma_s(const struct gkyl_wv_eqn *wv); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_iso_euler_mixture_priv.h b/moments/zero/gkyl_wv_iso_euler_mixture_priv.h index eba88eb398..57dd2e4abc 100644 --- a/moments/zero/gkyl_wv_iso_euler_mixture_priv.h +++ b/moments/zero/gkyl_wv_iso_euler_mixture_priv.h @@ -12,7 +12,7 @@ struct wv_iso_euler_mixture { struct gkyl_wv_eqn eqn; // Base equation object. int num_species; // Number of distinct species in mixture. - double* vt_s; // Thermal velocities for each species in mixture. + double *vt_s; // Thermal velocities for each species in mixture. }; /** @@ -23,9 +23,8 @@ struct wv_iso_euler_mixture { * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void -gkyl_iso_euler_mixture_prim_vars(int num_species, double* vt_s, const double* q, double* v); +GKYL_CU_D void +gkyl_iso_euler_mixture_prim_vars(int num_species, double *vt_s, const double *q, double *v); /** * Compute maximum absolute wave speed. @@ -35,9 +34,8 @@ gkyl_iso_euler_mixture_prim_vars(int num_species, double* vt_s, const double* q, * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_iso_euler_mixture_max_abs_speed(int num_species, double* vt_s, const double* q); +GKYL_CU_D static inline double +gkyl_iso_euler_mixture_max_abs_speed(int num_species, double *vt_s, const double *q); /** * Compute flux vector. Assumes rotation to local coordinate system. @@ -47,9 +45,8 @@ gkyl_iso_euler_mixture_max_abs_speed(int num_species, double* vt_s, const double * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_iso_euler_mixture_flux(int num_species, double* vt_s, const double* q, double* flux); +GKYL_CU_D void +gkyl_iso_euler_mixture_flux(int num_species, double *vt_s, const double *q, double *flux); /** * Compute Riemann variables given the conserved variables. @@ -59,9 +56,8 @@ gkyl_iso_euler_mixture_flux(int num_species, double* vt_s, const double* q, doub * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -71,9 +67,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the isothermal Euler mixture equations. @@ -85,9 +80,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -iso_euler_mixture_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void iso_euler_mixture_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the isothermal Euler mixture equations. @@ -99,9 +95,10 @@ iso_euler_mixture_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const do * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -iso_euler_mixture_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void iso_euler_mixture_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -113,10 +110,10 @@ iso_euler_mixture_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -128,10 +125,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -144,9 +141,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -159,9 +157,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -175,9 +174,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -191,10 +191,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -207,9 +208,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -222,9 +224,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -238,9 +241,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe_l( + const struct gkyl_wv_eqn *, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback). @@ -254,10 +258,11 @@ wave_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe_l( + const struct gkyl_wv_eqn *, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -268,9 +273,8 @@ qfluct_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const doubl * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the isothermal Euler mixture equations is satisfied. @@ -279,9 +283,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -290,9 +292,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -301,9 +301,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -iso_euler_mixture_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +iso_euler_mixture_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variable vector. @@ -312,13 +311,12 @@ iso_euler_mixture_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -iso_euler_mixture_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +iso_euler_mixture_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free isothermal Euler mixture equations object. * * @param ref Reference counter for isothermal Euler mixture equations. */ -void gkyl_iso_euler_mixture_free(const struct gkyl_ref_count* ref); +void gkyl_iso_euler_mixture_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_iso_euler_priv.h b/moments/zero/gkyl_wv_iso_euler_priv.h index 3e7b583265..8539ea6368 100644 --- a/moments/zero/gkyl_wv_iso_euler_priv.h +++ b/moments/zero/gkyl_wv_iso_euler_priv.h @@ -39,9 +39,7 @@ struct wv_iso_euler { * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_iso_euler_max_abs_speed(double vt, const double* q); +GKYL_CU_D static inline double gkyl_iso_euler_max_abs_speed(double vt, const double *q); /** * Compute flux vector. Assumes rotation to local coordinate system. @@ -50,9 +48,7 @@ gkyl_iso_euler_max_abs_speed(double vt, const double* q); * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_iso_euler_flux(double vt, const double* q, double* flux); +GKYL_CU_D void gkyl_iso_euler_flux(double vt, const double *q, double *flux); /** * Compute Riemann variables given the conserved variables. @@ -62,9 +58,8 @@ gkyl_iso_euler_flux(double vt, const double* q, double* flux); * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -74,9 +69,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the isothermal Euler equations. @@ -88,9 +82,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -iso_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void iso_euler_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the isothermal Euler equations. @@ -102,9 +97,10 @@ iso_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* sk * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -iso_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void iso_euler_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -116,10 +112,10 @@ iso_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -131,10 +127,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -147,9 +143,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -162,9 +159,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -178,9 +176,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -194,10 +193,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -210,9 +210,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -225,9 +226,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -241,9 +243,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback), @@ -257,10 +260,11 @@ wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -271,9 +275,8 @@ qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the isothermal Euler equations is satisfied. @@ -282,9 +285,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -293,9 +294,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -304,9 +303,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -iso_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +iso_euler_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variable vector. @@ -315,14 +313,12 @@ iso_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -iso_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +iso_euler_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free isothermal Euler equations object. * * @param ref Reference counter for isothermal Euler equations. */ -void -gkyl_iso_euler_free(const struct gkyl_ref_count* ref); +void gkyl_iso_euler_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_maxwell.h b/moments/zero/gkyl_wv_maxwell.h index 876826fea6..abe886031b 100644 --- a/moments/zero/gkyl_wv_maxwell.h +++ b/moments/zero/gkyl_wv_maxwell.h @@ -60,14 +60,13 @@ struct gkyl_wv_maxwell_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the Maxwell equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_maxwell_new(double c, double e_fact, double b_fact, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_maxwell_new(double c, double e_fact, double b_fact, bool use_gpu); /** * Create a new Maxwell equation object that lives on NV-GPU. * see new() method above for documentation. */ - struct gkyl_wv_eqn* gkyl_wv_maxwell_cu_dev_new(double c, double e_fact, double b_fact); +struct gkyl_wv_eqn *gkyl_wv_maxwell_cu_dev_new(double c, double e_fact, double b_fact); /** * Create a new Maxwell equations object, from an input context struct. @@ -75,5 +74,4 @@ gkyl_wv_maxwell_new(double c, double e_fact, double b_fact, bool use_gpu); * @param inp Input context struct. * @return Pointer to the Maxwell equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_maxwell_inew(const struct gkyl_wv_maxwell_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_maxwell_inew(const struct gkyl_wv_maxwell_inp *inp); diff --git a/moments/zero/gkyl_wv_maxwell_priv.h b/moments/zero/gkyl_wv_maxwell_priv.h index b158f85a2a..604d20385d 100644 --- a/moments/zero/gkyl_wv_maxwell_priv.h +++ b/moments/zero/gkyl_wv_maxwell_priv.h @@ -57,8 +57,7 @@ struct wv_maxwell { * * @param ref Reference counter for Maxwell equations. */ -void -gkyl_wv_maxwell_free(const struct gkyl_ref_count* ref); +void gkyl_wv_maxwell_free(const struct gkyl_ref_count *ref); /** * Compute maximum absolute wave speed. @@ -69,9 +68,8 @@ gkyl_wv_maxwell_free(const struct gkyl_ref_count* ref); * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_DH -static inline double -gkyl_maxwell_max_abs_speed(double c, double e_fact, double b_fact, const double* q) +GKYL_CU_DH static inline double +gkyl_maxwell_max_abs_speed(double c, double e_fact, double b_fact, const double *q) { return fmax(fmax(fabs((c * e_fact)), fabs(c)), fabs((b_fact * c))); } @@ -85,9 +83,8 @@ gkyl_maxwell_max_abs_speed(double c, double e_fact, double b_fact, const double* * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_DH -static inline void -gkyl_maxwell_flux(double c, double e_fact, double b_fact, const double* q, double* flux) +GKYL_CU_DH static inline void +gkyl_maxwell_flux(double c, double e_fact, double b_fact, const double *q, double *flux) { flux[0] = (e_fact * ((c * c) * q[6])); flux[1] = ((c * c) * q[5]); @@ -108,9 +105,8 @@ gkyl_maxwell_flux(double c, double e_fact, double b_fact, const double* q, doubl * @param q Conserved variable vector. * @param flux_deriv Flux Jacobian eigenvalues in direction 'dir' (output). */ -GKYL_CU_DH -static inline void -gkyl_maxwell_flux_deriv(double c, double e_fact, double b_fact, const double* q, double* flux_deriv) +GKYL_CU_DH static inline void +gkyl_maxwell_flux_deriv(double c, double e_fact, double b_fact, const double *q, double *flux_deriv) { flux_deriv[0] = (-1.0 * (c * e_fact)); flux_deriv[1] = (-1.0 * c); @@ -130,9 +126,8 @@ gkyl_maxwell_flux_deriv(double c, double e_fact, double b_fact, const double* q, * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_DH -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +GKYL_CU_DH static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 8; i++) { @@ -148,9 +143,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_DH -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout) +GKYL_CU_DH static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 8; i++) { @@ -168,9 +162,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_DH -static void -maxwell_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +GKYL_CU_DH static void maxwell_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { // Zero tangent for electric field. ghost[0] = skin[0]; @@ -197,9 +192,10 @@ maxwell_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_DH -static void -maxwell_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +GKYL_CU_DH static void maxwell_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { // Zero tangent for the electric field. ghost[0] = skin[0]; @@ -226,21 +222,21 @@ maxwell_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* s * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_DH -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +GKYL_CU_DH static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { // Rotate electric field vector to local coordinates. qlocal[0] = (qglobal[0] * norm[0]) + (qglobal[1] * norm[1]) + (qglobal[2] * norm[2]); qlocal[1] = (qglobal[0] * tau1[0]) + (qglobal[1] * tau1[1]) + (qglobal[2] * tau1[2]); qlocal[2] = (qglobal[0] * tau2[0]) + (qglobal[1] * tau2[1]) + (qglobal[2] * tau2[2]); - + // Rotate magnetic field vector to local coordinates. qlocal[3] = (qglobal[3] * norm[0]) + (qglobal[4] * norm[1]) + (qglobal[5] * norm[2]); qlocal[4] = (qglobal[3] * tau1[0]) + (qglobal[4] * tau1[1]) + (qglobal[5] * tau1[2]); qlocal[5] = (qglobal[3] * tau2[0]) + (qglobal[4] * tau2[1]) + (qglobal[5] * tau2[2]); - + // Correction potentials are scalars (so remain unchanged). qlocal[6] = qglobal[6]; qlocal[7] = qglobal[7]; @@ -256,10 +252,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_DH -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +GKYL_CU_DH static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { // Rotate electric field vector to global coordinates. qglobal[0] = (qlocal[0] * norm[0]) + (qlocal[1] * tau1[0]) + (qlocal[2] * tau2[0]); @@ -287,9 +283,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_DH -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +GKYL_CU_DH static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_maxwell *maxwell = container_of(eqn, struct wv_maxwell, eqn); double c = maxwell->c; // Speed of light. @@ -329,7 +326,6 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c s[0] = -amax; s[1] = amax; - return s[1]; } @@ -344,9 +340,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_DH -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +GKYL_CU_DH static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[8]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -358,9 +355,7 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -GKYL_CU_DH -static void -wave_embed_copy_B(const double *q, double *qphi, double *delta, void *ctx) +GKYL_CU_DH static void wave_embed_copy_B(const double *q, double *qphi, double *delta, void *ctx) { qphi[0] = 0.0; qphi[1] = 0.0; @@ -372,9 +367,7 @@ wave_embed_copy_B(const double *q, double *qphi, double *delta, void *ctx) qphi[7] = q[7]; } -GKYL_CU_DH -static void -wave_embed_pec(const double *q, double *qphi, double *delta, void *ctx) +GKYL_CU_DH static void wave_embed_pec(const double *q, double *qphi, double *delta, void *ctx) { qphi[0] = q[0]; qphi[1] = -q[1]; @@ -386,11 +379,10 @@ wave_embed_pec(const double *q, double *qphi, double *delta, void *ctx) qphi[7] = q[7]; } -GKYL_CU_DH -static double -wave_embedded(const struct gkyl_wv_eqn *eqn, const double *delta, - const double *ql, const double *qr, const double phil, const double phir, - double *waves, double *s) +GKYL_CU_DH static double wave_embedded( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + const double phil, const double phir, double *waves, double *s +) { double qphi[8] = {0.0}; double deltaphi[8] = {0.0}; @@ -398,12 +390,16 @@ wave_embedded(const struct gkyl_wv_eqn *eqn, const double *delta, if ((phil < 0.0) && (phir > 0.0)) { eqn->embed_geo->embed_func(qr, qphi, deltaphi, eqn->embed_geo->ctx); - for (int d=0; d<8; ++d) deltaphi[d] = qr[d] - qphi[d]; + for (int d = 0; d < 8; ++d) { + deltaphi[d] = qr[d] - qphi[d]; + } } if ((phil > 0.0) && (phir < 0.0)) { eqn->embed_geo->embed_func(ql, qphi, deltaphi, eqn->embed_geo->ctx); - for (int d=0; d<8; ++d) deltaphi[d] = qphi[d] - ql[d]; + for (int d = 0; d < 8; ++d) { + deltaphi[d] = qphi[d] - ql[d]; + } } return wave_lax(eqn, deltaphi, ql, qr, waves, s); @@ -421,14 +417,16 @@ wave_embedded(const struct gkyl_wv_eqn *eqn, const double *delta, * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_DH -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, double phil, double phir, double* waves, double* s) +GKYL_CU_DH static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, double phil, double phir, double *waves, double *s +) { - if ((phil < 0.0) || (phir < 0.0)) + if ((phil < 0.0) || (phir < 0.0)) { return wave_embedded(eqn, delta, ql, qr, phil, phir, waves, s); - else + } else { return wave_lax(eqn, delta, ql, qr, waves, s); + } } /** @@ -443,10 +441,10 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_DH -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, double phil, double phir, const double* waves, const double* s, - double* amdq, double* apdq) +GKYL_CU_DH static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + double phil, double phir, const double *waves, const double *s, double *amdq, double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } @@ -462,9 +460,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_DH -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +GKYL_CU_DH static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_maxwell *maxwell = container_of(eqn, struct wv_maxwell, eqn); double c = maxwell->c; // Speed of light. @@ -480,29 +479,43 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double a7 = 0.5 * (delta[2] - (c * delta[4])); double a8 = 0.5 * (delta[2] + (c * delta[4])); - double *w0 = &waves[0 * 8], *w1 = &waves[1 * 8], *w2 = &waves[2 * 8], *w3 = &waves[3 * 8], *w4 = &waves[4 * 8], *w5 = &waves[5 * 8]; + double *w0 = &waves[0 * 8], *w1 = &waves[1 * 8], *w2 = &waves[2 * 8], *w3 = &waves[3 * 8], + *w4 = &waves[4 * 8], *w5 = &waves[5 * 8]; for (int i = 0; i < 8; i++) { - w0[i] = 0.0; w1[i] = 0.0; w2[i] = 0.0; w3[i] = 0.0; w4[i] = 0.0; w5[i] = 0.0; + w0[i] = 0.0; + w1[i] = 0.0; + w2[i] = 0.0; + w3[i] = 0.0; + w4[i] = 0.0; + w5[i] = 0.0; } - w0[3] = a1; w0[7] = -c * a1; + w0[3] = a1; + w0[7] = -c * a1; s[0] = -c * b_fact; - w1[3] = a2; w1[7] = c * a2; + w1[3] = a2; + w1[7] = c * a2; s[1] = c * b_fact; - w2[0] = a3; w2[6] = -(1.0 / c) * a3; + w2[0] = a3; + w2[6] = -(1.0 / c) * a3; s[2] = -c * e_fact; - w3[0] = a4; w3[6] = (1.0 / c) * a4; + w3[0] = a4; + w3[6] = (1.0 / c) * a4; s[3] = c * e_fact; - w4[1] = a5; w4[2] = a8; - w4[4] = (1.0 / c) * a8; w4[5] = -(1.0 / c) * a5; + w4[1] = a5; + w4[2] = a8; + w4[4] = (1.0 / c) * a8; + w4[5] = -(1.0 / c) * a5; s[4] = -c; - w5[1] = a6; w5[2] = a7; - w5[4] = -(1.0 / c) * a7; w5[5] = (1.0 / c) * a6; + w5[1] = a6; + w5[2] = a7; + w5[4] = -(1.0 / c) * a7; + w5[5] = (1.0 / c) * a6; s[5] = c; return c; @@ -519,17 +532,23 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_DH -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +GKYL_CU_DH static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { - const double *w0 = &waves[0 * 8], *w1 = &waves[1 * 8], *w2 = &waves[2 * 8], *w3 = &waves[3 * 8], *w4 = &waves[4 * 8], *w5 = &waves[5 * 8]; - double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]), s3m = fmin(0.0, s[3]), s4m = fmin(0.0, s[4]), s5m = fmin(0.0, s[5]); - double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]), s3p = fmax(0.0, s[3]), s4p = fmax(0.0, s[4]), s5p = fmax(0.0, s[5]); + const double *w0 = &waves[0 * 8], *w1 = &waves[1 * 8], *w2 = &waves[2 * 8], *w3 = &waves[3 * 8], + *w4 = &waves[4 * 8], *w5 = &waves[5 * 8]; + double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]), s3m = fmin(0.0, s[3]), + s4m = fmin(0.0, s[4]), s5m = fmin(0.0, s[5]); + double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]), s3p = fmax(0.0, s[3]), + s4p = fmax(0.0, s[4]), s5p = fmax(0.0, s[5]); for (int i = 0; i < 8; i++) { - amdq[i] = (s0m * w0[i]) + (s1m * w1[i]) + (s2m * w2[i]) + (s3m * w3[i]) + (s4m * w4[i]) + (s5m * w5[i]); - apdq[i] = (s0p * w0[i]) + (s1p * w1[i]) + (s2p * w2[i]) + (s3p * w3[i]) + (s4p * w4[i]) + (s5p * w5[i]); + amdq[i] = + (s0m * w0[i]) + (s1m * w1[i]) + (s2m * w2[i]) + (s3m * w3[i]) + (s4m * w4[i]) + (s5m * w5[i]); + apdq[i] = + (s0p * w0[i]) + (s1p * w1[i]) + (s2p * w2[i]) + (s3p * w3[i]) + (s4p * w4[i]) + (s5p * w5[i]); } } @@ -545,27 +564,30 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_DH -static double -wave(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, double phil, double phir, double* waves, double* s) +GKYL_CU_DH static double wave( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, double phil, double phir, double *waves, double *s +) { // clear waves and wave speeds int mwaves = (type == GKYL_WV_HIGH_ORDER_FLUX) ? eqn->num_waves : 2; int meqn = eqn->num_equations; - for (int i=0; ic; // Speed of light. @@ -651,9 +671,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_DH -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +GKYL_CU_DH static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { return true; // All states are assumed to be valid. } @@ -665,9 +683,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q) * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_DH -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +GKYL_CU_DH static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_maxwell *maxwell = container_of(eqn, struct wv_maxwell, eqn); double c = maxwell->c; // Speed of light. @@ -684,9 +700,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_DH -static inline void -maxwell_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +GKYL_CU_DH static inline void +maxwell_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 6; i++) { diag[i] = qin[i] * qin[i]; @@ -700,6 +715,5 @@ maxwell_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* d * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -maxwell_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +maxwell_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); diff --git a/moments/zero/gkyl_wv_mhd.h b/moments/zero/gkyl_wv_mhd.h index f0cc938158..7af393fd84 100644 --- a/moments/zero/gkyl_wv_mhd.h +++ b/moments/zero/gkyl_wv_mhd.h @@ -31,7 +31,7 @@ struct gkyl_wv_mhd_inp { * @param divb Divergence constraint method * @return Pointer to mhd equation object. */ -struct gkyl_wv_eqn* gkyl_wv_mhd_new(const struct gkyl_wv_mhd_inp *inp); +struct gkyl_wv_eqn *gkyl_wv_mhd_new(const struct gkyl_wv_mhd_inp *inp); /** * Get gas adiabatic constant. @@ -39,7 +39,7 @@ struct gkyl_wv_eqn* gkyl_wv_mhd_new(const struct gkyl_wv_mhd_inp *inp); * @param wv mhd equation object * @return Get gas adiabatic constant */ -double gkyl_wv_mhd_gas_gamma(const struct gkyl_wv_eqn* wv); +double gkyl_wv_mhd_gas_gamma(const struct gkyl_wv_eqn *wv); /** * Get ch parameter used by the GLM divergence constraint. @@ -47,7 +47,7 @@ double gkyl_wv_mhd_gas_gamma(const struct gkyl_wv_eqn* wv); * @param wv mhd equation object * @return divergence constraint type */ -double gkyl_wv_mhd_divergence_constraint(const struct gkyl_wv_eqn* wv); +double gkyl_wv_mhd_divergence_constraint(const struct gkyl_wv_eqn *wv); /** * Get ch parameter used by the GLM divergence constraint. @@ -55,7 +55,7 @@ double gkyl_wv_mhd_divergence_constraint(const struct gkyl_wv_eqn* wv); * @param wv mhd equation object * @return ch number */ -double gkyl_wv_mhd_glm_ch(const struct gkyl_wv_eqn* wv); +double gkyl_wv_mhd_glm_ch(const struct gkyl_wv_eqn *wv); /** * Get alpha parameter used by the GLM divergence constraint. @@ -63,7 +63,7 @@ double gkyl_wv_mhd_glm_ch(const struct gkyl_wv_eqn* wv); * @param wv mhd equation object * @return alpha number */ -double gkyl_wv_mhd_glm_alpha(const struct gkyl_wv_eqn* wv); +double gkyl_wv_mhd_glm_alpha(const struct gkyl_wv_eqn *wv); /** * Set ch parameter used by the GLM divergence constraint. @@ -71,5 +71,4 @@ double gkyl_wv_mhd_glm_alpha(const struct gkyl_wv_eqn* wv); * @param wv mhd equation object * @param ch number */ -void gkyl_wv_mhd_set_glm_ch(struct gkyl_wv_eqn* wv, double glm_ch); - +void gkyl_wv_mhd_set_glm_ch(struct gkyl_wv_eqn *wv, double glm_ch); diff --git a/moments/zero/gkyl_wv_reactive_euler.h b/moments/zero/gkyl_wv_reactive_euler.h index 97c4ac1ed2..55d52f60c1 100644 --- a/moments/zero/gkyl_wv_reactive_euler.h +++ b/moments/zero/gkyl_wv_reactive_euler.h @@ -5,7 +5,7 @@ // Type of Riemann-solver to use: enum gkyl_wv_reactive_euler_rp { WV_REACTIVE_EULER_RP_LAX = 0, // Default (Lax fluxes). - WV_REACTIVE_EULER_RP_ROE, + WV_REACTIVE_EULER_RP_ROE }; // Input context, packaged as a struct. @@ -31,9 +31,10 @@ struct gkyl_wv_reactive_euler_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the reactive Euler equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_reactive_euler_new(double gas_gamma, double specific_heat_capacity, double energy_of_formation, double ignition_temperature, - double reaction_rate, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_reactive_euler_new( + double gas_gamma, double specific_heat_capacity, double energy_of_formation, + double ignition_temperature, double reaction_rate, bool use_gpu +); /** * Create a new reactive Euler equations object, from an input context struct. @@ -41,8 +42,7 @@ gkyl_wv_reactive_euler_new(double gas_gamma, double specific_heat_capacity, doub * @param inp Input context struct. * @return Pointer to the reactive Euler equations object. */ -struct gkyl_wv_eqn* -gkyl_wv_reactive_euler_inew(const struct gkyl_wv_reactive_euler_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_reactive_euler_inew(const struct gkyl_wv_reactive_euler_inp *inp); /** * Get adiabatic index. @@ -50,8 +50,7 @@ gkyl_wv_reactive_euler_inew(const struct gkyl_wv_reactive_euler_inp* inp); * @param wv Reactive Euler equations object. * @return Adiabatic index. */ -double -gkyl_wv_reactive_euler_gas_gamma(const struct gkyl_wv_eqn* wv); +double gkyl_wv_reactive_euler_gas_gamma(const struct gkyl_wv_eqn *wv); /** * Get specific heat capacity. @@ -59,8 +58,7 @@ gkyl_wv_reactive_euler_gas_gamma(const struct gkyl_wv_eqn* wv); * @param wv Reactive Euler equations object. * @return Specific heat capacity. */ -double -gkyl_wv_reactive_euler_specific_heat_capacity(const struct gkyl_wv_eqn* wv); +double gkyl_wv_reactive_euler_specific_heat_capacity(const struct gkyl_wv_eqn *wv); /** * Get energy of formation. @@ -68,8 +66,7 @@ gkyl_wv_reactive_euler_specific_heat_capacity(const struct gkyl_wv_eqn* wv); * @param wv Reactive Euler equations object. * @return Energy of formation. */ -double -gkyl_wv_reactive_euler_energy_of_formation(const struct gkyl_wv_eqn* wv); +double gkyl_wv_reactive_euler_energy_of_formation(const struct gkyl_wv_eqn *wv); /** * Get ignition temperature. @@ -77,8 +74,7 @@ gkyl_wv_reactive_euler_energy_of_formation(const struct gkyl_wv_eqn* wv); * @param wv Reactive Euler equations object. * @return Ignition temperature. */ -double -gkyl_wv_reactive_euler_ignition_temperature(const struct gkyl_wv_eqn* wv); +double gkyl_wv_reactive_euler_ignition_temperature(const struct gkyl_wv_eqn *wv); /** * Get reaction rate. @@ -86,5 +82,4 @@ gkyl_wv_reactive_euler_ignition_temperature(const struct gkyl_wv_eqn* wv); * @param wv Reactive Euler equations object. * @return Reaction rate. */ -double -gkyl_wv_reactive_euler_reaction_rate(const struct gkyl_wv_eqn* wv); \ No newline at end of file +double gkyl_wv_reactive_euler_reaction_rate(const struct gkyl_wv_eqn *wv); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_reactive_euler_priv.h b/moments/zero/gkyl_wv_reactive_euler_priv.h index 8de7ae7854..2e42a6e854 100644 --- a/moments/zero/gkyl_wv_reactive_euler_priv.h +++ b/moments/zero/gkyl_wv_reactive_euler_priv.h @@ -26,9 +26,9 @@ struct wv_reactive_euler { * @param q Conserved variable vector. * @param v Primitive variable vector (output). */ -GKYL_CU_D -void -gkyl_reactive_euler_prim_vars(double gas_gamma, double energy_of_formation, const double q[6], double v[6]); +GKYL_CU_D void gkyl_reactive_euler_prim_vars( + double gas_gamma, double energy_of_formation, const double q[6], double v[6] +); /** * Compute maximum absolute wave speed. @@ -38,8 +38,7 @@ gkyl_reactive_euler_prim_vars(double gas_gamma, double energy_of_formation, cons * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double +GKYL_CU_D static inline double gkyl_reactive_euler_max_abs_speed(double gas_gamma, double energy_of_formation, const double q[6]); /** @@ -50,9 +49,9 @@ gkyl_reactive_euler_max_abs_speed(double gas_gamma, double energy_of_formation, * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_reactive_euler_flux(double gas_gamma, double energy_of_formation, const double q[6], double flux[6]); +GKYL_CU_D void gkyl_reactive_euler_flux( + double gas_gamma, double energy_of_formation, const double q[6], double flux[6] +); /** * Compute Riemann variables given the conserved variables. @@ -62,9 +61,8 @@ gkyl_reactive_euler_flux(double gas_gamma, double energy_of_formation, const dou * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -74,9 +72,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the reactive Euler equations. @@ -88,9 +85,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -reactive_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void reactive_euler_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Boundary condition function for applying no-slip boundary conditions for the reactive Euler equations. @@ -102,9 +100,10 @@ reactive_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const doubl * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -reactive_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void reactive_euler_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -116,10 +115,10 @@ reactive_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const do * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -131,10 +130,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -147,9 +146,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -162,9 +162,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -178,9 +179,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -194,10 +196,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using Roe fluxes. @@ -210,9 +213,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Roe fluxes. @@ -225,9 +229,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Roe fluxes (with potential fallback). @@ -241,9 +246,10 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s); +GKYL_CU_D static double wave_roe_l( + const struct gkyl_wv_eqn *, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Roe fluxes (with potential fallback). @@ -257,10 +263,11 @@ wave_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq); +GKYL_CU_D static void qfluct_roe_l( + const struct gkyl_wv_eqn *, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -271,9 +278,8 @@ qfluct_roe_l(const struct gkyl_wv_eqn*, enum gkyl_wv_flux_type type, const doubl * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the reactive Euler equations is satisfied. @@ -282,9 +288,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -293,9 +297,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -304,9 +306,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -reactive_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +reactive_euler_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variable vector. @@ -315,13 +316,12 @@ reactive_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, do * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -reactive_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +reactive_euler_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free reactive Euler equations object. * * @param ref Reference counter for reactive Euler equations. */ -void gkyl_reactive_euler_free(const struct gkyl_ref_count* ref); +void gkyl_reactive_euler_free(const struct gkyl_ref_count *ref); diff --git a/moments/zero/gkyl_wv_sr_euler.h b/moments/zero/gkyl_wv_sr_euler.h index 60969d0696..6b0867121f 100644 --- a/moments/zero/gkyl_wv_sr_euler.h +++ b/moments/zero/gkyl_wv_sr_euler.h @@ -8,7 +8,7 @@ * @param gas_gamma Gas adiabatic constant * @return Pointer to SR Euler equation object. */ -struct gkyl_wv_eqn* gkyl_wv_sr_euler_new(double gas_gamma); +struct gkyl_wv_eqn *gkyl_wv_sr_euler_new(double gas_gamma); /** * Get gas adiabatic constant. @@ -16,4 +16,4 @@ struct gkyl_wv_eqn* gkyl_wv_sr_euler_new(double gas_gamma); * @param wv SR Euler equation object * @return Get gas adiabatic constant */ -double gkyl_wv_sr_euler_gas_gamma(const struct gkyl_wv_eqn* wv); +double gkyl_wv_sr_euler_gas_gamma(const struct gkyl_wv_eqn *wv); diff --git a/moments/zero/gkyl_wv_ten_moment.h b/moments/zero/gkyl_wv_ten_moment.h index 7df6341bbf..6ccc51fad3 100644 --- a/moments/zero/gkyl_wv_ten_moment.h +++ b/moments/zero/gkyl_wv_ten_moment.h @@ -10,7 +10,7 @@ struct gkyl_wv_ten_moment_inp { bool use_grad_closure; // Should we use gradient-based closure? bool use_nn_closure; // Should we use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - struct gkyl_kann_net* ann; // Neural network architecture. + struct gkyl_kann_net *ann; // Neural network architecture. struct gkyl_wv_embed_geo *embed_geo; // embedded geometry bool use_gpu; // Boolean to determine whether wave equation object is on host or device. }; @@ -26,8 +26,10 @@ struct gkyl_wv_ten_moment_inp { * @param use_gpu Boolean to determine whether wave equation object is on host or device. * @return Pointer to 10-moment equation object. */ -struct gkyl_wv_eqn* -gkyl_wv_ten_moment_new(double k0, bool use_grad_closure, bool use_nn_closure, int poly_order, struct gkyl_kann_net* ann, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_ten_moment_new( + double k0, bool use_grad_closure, bool use_nn_closure, int poly_order, struct gkyl_kann_net *ann, + bool use_gpu +); /** * Create a new 10-moment equation object. @@ -35,8 +37,7 @@ gkyl_wv_ten_moment_new(double k0, bool use_grad_closure, bool use_nn_closure, in * @param inp Input parameters. * @return Pointer to 10-moment equation object. */ -struct gkyl_wv_eqn* -gkyl_wv_ten_moment_inew(const struct gkyl_wv_ten_moment_inp *inp); +struct gkyl_wv_eqn *gkyl_wv_ten_moment_inew(const struct gkyl_wv_ten_moment_inp *inp); /** * Create a new 10-moment equation object that lives on NV-GPU. @@ -49,8 +50,10 @@ gkyl_wv_ten_moment_inew(const struct gkyl_wv_ten_moment_inp *inp); * @param use_gpu Boolean to determine whether wave equation object is on host or device. * @return Pointer to 10-moment equation object on device. */ -struct gkyl_wv_eqn* -gkyl_wv_ten_moment_cu_dev_new(double k0, bool use_grad_closure, bool use_nn_closure, int poly_order, struct gkyl_kann_net* ann, bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_ten_moment_cu_dev_new( + double k0, bool use_grad_closure, bool use_nn_closure, int poly_order, struct gkyl_kann_net *ann, + bool use_gpu +); /** * Create a new 10-moment equation object that lives on NV-GPU. @@ -58,8 +61,7 @@ gkyl_wv_ten_moment_cu_dev_new(double k0, bool use_grad_closure, bool use_nn_clos * @param inp Input parameters. * @return Pointer to 10-moment equation object on device. */ - struct gkyl_wv_eqn* - gkyl_wv_ten_moment_cu_dev_inew(const struct gkyl_wv_ten_moment_inp *inp); +struct gkyl_wv_eqn *gkyl_wv_ten_moment_cu_dev_inew(const struct gkyl_wv_ten_moment_inp *inp); /** * Get closure parameter. @@ -67,8 +69,7 @@ gkyl_wv_ten_moment_cu_dev_new(double k0, bool use_grad_closure, bool use_nn_clos * @param wv 10-moment equation object. * @return Closure parameter. */ -double -gkyl_wv_ten_moment_k0(const struct gkyl_wv_eqn* wv); +double gkyl_wv_ten_moment_k0(const struct gkyl_wv_eqn *wv); /** * Should we use gradient-based closure? @@ -76,8 +77,7 @@ gkyl_wv_ten_moment_k0(const struct gkyl_wv_eqn* wv); * @param wv 10-moment equation object. * @return True if using gradient-based closure, false otherwise. */ -bool -gkyl_wv_ten_moment_use_grad_closure(const struct gkyl_wv_eqn* wv); +bool gkyl_wv_ten_moment_use_grad_closure(const struct gkyl_wv_eqn *wv); /** * Should we use neural netowork-based closure? @@ -85,8 +85,7 @@ gkyl_wv_ten_moment_use_grad_closure(const struct gkyl_wv_eqn* wv); * @param wv 10-moment equation object. * @return True if using neural network-based closure, false otherwise. */ -bool -gkyl_wv_ten_moment_use_nn_closure(const struct gkyl_wv_eqn* wv); +bool gkyl_wv_ten_moment_use_nn_closure(const struct gkyl_wv_eqn *wv); /** * Get polynomial order of learned DG coefficients. @@ -94,8 +93,7 @@ gkyl_wv_ten_moment_use_nn_closure(const struct gkyl_wv_eqn* wv); * @param wv 10-moment equation object. * @return Polynomial order of learned DG coefficients. */ - int - gkyl_wv_ten_moment_poly_order(const struct gkyl_wv_eqn* wv); +int gkyl_wv_ten_moment_poly_order(const struct gkyl_wv_eqn *wv); /** * Get neural network architecture. @@ -103,5 +101,4 @@ gkyl_wv_ten_moment_use_nn_closure(const struct gkyl_wv_eqn* wv); * @param wv 10-moment equation object * @return Neural network architecture. */ -struct gkyl_kann_net* -gkyl_wv_ten_moment_ann(const struct gkyl_wv_eqn* wv); +struct gkyl_kann_net *gkyl_wv_ten_moment_ann(const struct gkyl_wv_eqn *wv); diff --git a/moments/zero/gkyl_wv_ten_moment_priv.h b/moments/zero/gkyl_wv_ten_moment_priv.h index c295107bde..e811967f73 100644 --- a/moments/zero/gkyl_wv_ten_moment_priv.h +++ b/moments/zero/gkyl_wv_ten_moment_priv.h @@ -19,7 +19,7 @@ struct wv_ten_moment { bool use_grad_closure; // Should we use gradient-based closure? bool use_nn_closure; // Should we use neural network-based closure? int poly_order; // Polynomial order of learned DG coefficients. - struct gkyl_kann_net* ann; // Neural network architecture. + struct gkyl_kann_net *ann; // Neural network architecture. }; /** @@ -29,49 +29,44 @@ struct wv_ten_moment { */ void gkyl_ten_moment_free(const struct gkyl_ref_count *ref); -GKYL_CU_DH -static inline double -sq(double x) -{ - return x * x; +GKYL_CU_DH static inline double sq(double x) +{ + return x * x; } -GKYL_CU_DH -static inline void -cons_to_riem(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *qin, double *wout) +GKYL_CU_DH static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: this should use proper L matrix - for (int i=0; i<10; ++i) + for (int i = 0; i < 10; ++i) { wout[i] = qin[i]; + } } -GKYL_CU_DH -static inline void -riem_to_cons(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *win, double *qout) +GKYL_CU_DH static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: this should use proper L matrix - for (int i=0; i<10; ++i) + for (int i = 0; i < 10; ++i) { qout[i] = win[i]; + } } /* Multiply by phi prime */ -GKYL_CU_DH -static inline void -mulByPhiPrime(double p0, double u1, double u2, double u3, const double w[10], double out[10]) -{ - out[0] = w[0]; - out[1] = w[0]*u1+w[1]*p0; - out[2] = w[0]*u2+w[2]*p0; - out[3] = w[0]*u3+w[3]*p0; - out[4] = w[0]*sq(u1)+2*w[1]*p0*u1+w[4]; - out[5] = w[0]*u1*u2+w[1]*p0*u2+w[2]*p0*u1+w[5]; - out[6] = w[0]*u1*u3+w[1]*p0*u3+w[3]*p0*u1+w[6]; - out[7] = w[0]*sq(u2)+2*w[2]*p0*u2+w[7]; - out[8] = w[0]*u2*u3+w[2]*p0*u3+w[3]*p0*u2+w[8]; - out[9] = w[0]*sq(u3)+2*w[3]*p0*u3+w[9]; -} +GKYL_CU_DH static inline void +mulByPhiPrime(double p0, double u1, double u2, double u3, const double w[10], double out[10]) +{ + out[0] = w[0]; + out[1] = w[0] * u1 + w[1] * p0; + out[2] = w[0] * u2 + w[2] * p0; + out[3] = w[0] * u3 + w[3] * p0; + out[4] = w[0] * sq(u1) + 2 * w[1] * p0 * u1 + w[4]; + out[5] = w[0] * u1 * u2 + w[1] * p0 * u2 + w[2] * p0 * u1 + w[5]; + out[6] = w[0] * u1 * u3 + w[1] * p0 * u3 + w[3] * p0 * u1 + w[6]; + out[7] = w[0] * sq(u2) + 2 * w[2] * p0 * u2 + w[7]; + out[8] = w[0] * u2 * u3 + w[2] * p0 * u3 + w[3] * p0 * u2 + w[8]; + out[9] = w[0] * sq(u3) + 2 * w[3] * p0 * u3 + w[9]; +} /** * Computes the primitive variables given the conserved variables. @@ -79,20 +74,18 @@ mulByPhiPrime(double p0, double u1, double u2, double u3, const double w[10], do * @param q Conserved variables * @param out Primitive variables */ -GKYL_CU_DH -static inline void -gkyl_ten_moment_primitive(const double q[10], double out[10]) +GKYL_CU_DH static inline void gkyl_ten_moment_primitive(const double q[10], double out[10]) { - out[0] = q[0]; - out[1] = q[1]/q[0]; - out[2] = q[2]/q[0]; - out[3] = q[3]/q[0]; - out[4] = q[4]-(q[1]*q[1])/q[0]; - out[5] = q[5]-(q[1]*q[2])/q[0]; - out[6] = q[6]-(q[1]*q[3])/q[0]; - out[7] = q[7]-(q[2]*q[2])/q[0]; - out[8] = q[8]-(q[2]*q[3])/q[0]; - out[9] = q[9]-(q[3]*q[3])/q[0]; + out[0] = q[0]; + out[1] = q[1] / q[0]; + out[2] = q[2] / q[0]; + out[3] = q[3] / q[0]; + out[4] = q[4] - (q[1] * q[1]) / q[0]; + out[5] = q[5] - (q[1] * q[2]) / q[0]; + out[6] = q[6] - (q[1] * q[3]) / q[0]; + out[7] = q[7] - (q[2] * q[2]) / q[0]; + out[8] = q[8] - (q[2] * q[3]) / q[0]; + out[9] = q[9] - (q[3] * q[3]) / q[0]; } /** @@ -101,13 +94,11 @@ gkyl_ten_moment_primitive(const double q[10], double out[10]) * @param q Conserved variables * @param out [Pxx, Pyy, Pzz] */ -GKYL_CU_DH -static inline void -gkyl_ten_moment_diag_pressure(const double q[10], double out[3]) +GKYL_CU_DH static inline void gkyl_ten_moment_diag_pressure(const double q[10], double out[3]) { - out[0] = q[4]-(q[1]*q[1])/q[0]; // pxx - out[1] = q[7]-(q[2]*q[2])/q[0]; // pyy - out[2] = q[9]-(q[3]*q[3])/q[0]; // pzz + out[0] = q[4] - (q[1] * q[1]) / q[0]; // pxx + out[1] = q[7] - (q[2] * q[2]) / q[0]; // pyy + out[2] = q[9] - (q[3] * q[3]) / q[0]; // pzz } /** @@ -117,13 +108,11 @@ gkyl_ten_moment_diag_pressure(const double q[10], double out[3]) * @param q Conserved variables * @return Maximum absolute speed for given q */ -GKYL_CU_DH -static inline double -gkyl_ten_moment_max_abs_speed(const double q[10]) +GKYL_CU_DH static inline double gkyl_ten_moment_max_abs_speed(const double q[10]) { - double u = q[1]/q[0]; - double p11 = q[4] - q[0]*u*u; - return fabs(u) + sqrt(3.0*p11/q[0]); + double u = q[1] / q[0]; + double p11 = q[4] - q[0] * u * u; + return fabs(u) + sqrt(3.0 * p11 / q[0]); } /** @@ -133,9 +122,7 @@ gkyl_ten_moment_max_abs_speed(const double q[10]) * @param Conserved variables * @param flux On output, the flux in direction 'dir' */ -GKYL_CU_DH -static inline void -gkyl_ten_moment_flux(const double q[10], double flux[10]) +GKYL_CU_DH static inline void gkyl_ten_moment_flux(const double q[10], double flux[10]) { double v[10]; gkyl_ten_moment_primitive(q, v); @@ -144,18 +131,24 @@ gkyl_ten_moment_flux(const double q[10], double flux[10]) flux[1] = q[4]; // Pxx flux[2] = q[5]; // Pxy flux[3] = q[6]; // Pxz - flux[4] = v[0]*v[1]*v[1]*v[1] + 3*v[1]*v[4]; // rho u^3 + 3*u*Pxx - flux[5] = v[0]*v[1]*v[1]*v[2] + 2*v[1]*v[5] + v[2]*v[4]; // rho*u^2*v + 2*u*Pxy + v*Pxx - flux[6] = v[0]*v[1]*v[1]*v[3] + 2*v[1]*v[6] + v[3]*v[4]; // rho*u^2*w + 2*u*Pxz + w*Pxx - flux[7] = v[0]*v[1]*v[2]*v[2] + 2*v[2]*v[5] + v[1]*v[7]; // rho*u*v^2 + 2*v*Pxy + u*Pyy - flux[8] = v[0]*v[1]*v[2]*v[3] + v[1]*v[8] + v[2]*v[6] + v[3]*v[5]; // rho*u*v*w + u*Pyz + v*Pxz + w*Pxy - flux[9] = v[0]*v[1]*v[3]*v[3] + 2*v[3]*v[6] + v[1]*v[9]; // rho*u*w^2 + 2*w*Pxz + u*Pzz + flux[4] = v[0] * v[1] * v[1] * v[1] + 3 * v[1] * v[4]; // rho u^3 + 3*u*Pxx + flux[5] = + v[0] * v[1] * v[1] * v[2] + 2 * v[1] * v[5] + v[2] * v[4]; // rho*u^2*v + 2*u*Pxy + v*Pxx + flux[6] = + v[0] * v[1] * v[1] * v[3] + 2 * v[1] * v[6] + v[3] * v[4]; // rho*u^2*w + 2*u*Pxz + w*Pxx + flux[7] = + v[0] * v[1] * v[2] * v[2] + 2 * v[2] * v[5] + v[1] * v[7]; // rho*u*v^2 + 2*v*Pxy + u*Pyy + flux[8] = v[0] * v[1] * v[2] * v[3] + v[1] * v[8] + v[2] * v[6] + + v[3] * v[5]; // rho*u*v*w + u*Pyz + v*Pxz + w*Pxy + flux[9] = + v[0] * v[1] * v[3] * v[3] + 2 * v[3] * v[6] + v[1] * v[9]; // rho*u*w^2 + 2*w*Pxz + u*Pzz } // Ten moment perfectly reflecting wall -GKYL_CU_DH -static void -ten_moment_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double *skin, double * GKYL_RESTRICT ghost, void *ctx) +GKYL_CU_DH static void ten_moment_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { // copy density and Pxx, Pyy, and Pzz ghost[0] = skin[0]; @@ -174,45 +167,45 @@ ten_moment_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double *s ghost[5] = -skin[5]; } -GKYL_CU_DH -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qglobal, double* GKYL_RESTRICT qlocal) +GKYL_CU_DH static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { // Mass density is a scalar qlocal[0] = qglobal[0]; // Rotate momentum to local coordinates - qlocal[1] = qglobal[1]*norm[0] + qglobal[2]*norm[1] + qglobal[3]*norm[2]; - qlocal[2] = qglobal[1]*tau1[0] + qglobal[2]*tau1[1] + qglobal[3]*tau1[2]; - qlocal[3] = qglobal[1]*tau2[0] + qglobal[2]*tau2[1] + qglobal[3]*tau2[2]; + qlocal[1] = qglobal[1] * norm[0] + qglobal[2] * norm[1] + qglobal[3] * norm[2]; + qlocal[2] = qglobal[1] * tau1[0] + qglobal[2] * tau1[1] + qglobal[3] * tau1[2]; + qlocal[3] = qglobal[1] * tau2[0] + qglobal[2] * tau2[1] + qglobal[3] * tau2[2]; // temp arrays to store rotated column vectors double r1[3], r2[3], r3[3]; - r1[0] = qglobal[4]*norm[0] + qglobal[5]*norm[1] + qglobal[6]*norm[2]; - r1[1] = qglobal[4]*tau1[0] + qglobal[5]*tau1[1] + qglobal[6]*tau1[2]; - r1[2] = qglobal[4]*tau2[0] + qglobal[5]*tau2[1] + qglobal[6]*tau2[2]; + r1[0] = qglobal[4] * norm[0] + qglobal[5] * norm[1] + qglobal[6] * norm[2]; + r1[1] = qglobal[4] * tau1[0] + qglobal[5] * tau1[1] + qglobal[6] * tau1[2]; + r1[2] = qglobal[4] * tau2[0] + qglobal[5] * tau2[1] + qglobal[6] * tau2[2]; - r2[0] = qglobal[5]*norm[0] + qglobal[7]*norm[1] + qglobal[8]*norm[2]; - r2[1] = qglobal[5]*tau1[0] + qglobal[7]*tau1[1] + qglobal[8]*tau1[2]; - r2[2] = qglobal[5]*tau2[0] + qglobal[7]*tau2[1] + qglobal[8]*tau2[2]; + r2[0] = qglobal[5] * norm[0] + qglobal[7] * norm[1] + qglobal[8] * norm[2]; + r2[1] = qglobal[5] * tau1[0] + qglobal[7] * tau1[1] + qglobal[8] * tau1[2]; + r2[2] = qglobal[5] * tau2[0] + qglobal[7] * tau2[1] + qglobal[8] * tau2[2]; - r3[0] = qglobal[6]*norm[0] + qglobal[8]*norm[1] + qglobal[9]*norm[2]; - r3[1] = qglobal[6]*tau1[0] + qglobal[8]*tau1[1] + qglobal[9]*tau1[2]; - r3[2] = qglobal[6]*tau2[0] + qglobal[8]*tau2[1] + qglobal[9]*tau2[2]; + r3[0] = qglobal[6] * norm[0] + qglobal[8] * norm[1] + qglobal[9] * norm[2]; + r3[1] = qglobal[6] * tau1[0] + qglobal[8] * tau1[1] + qglobal[9] * tau1[2]; + r3[2] = qglobal[6] * tau2[0] + qglobal[8] * tau2[1] + qglobal[9] * tau2[2]; // temp arrays to store rotated row vectors double v1[3], v2[3], v3[3]; - v1[0] = r1[0]*norm[0] + r2[0]*norm[1] + r3[0]*norm[2]; - v1[1] = r1[0]*tau1[0] + r2[0]*tau1[1] + r3[0]*tau1[2]; - v1[2] = r1[0]*tau2[0] + r2[0]*tau2[1] + r3[0]*tau2[2]; + v1[0] = r1[0] * norm[0] + r2[0] * norm[1] + r3[0] * norm[2]; + v1[1] = r1[0] * tau1[0] + r2[0] * tau1[1] + r3[0] * tau1[2]; + v1[2] = r1[0] * tau2[0] + r2[0] * tau2[1] + r3[0] * tau2[2]; - v2[0] = r1[1]*norm[0] + r2[1]*norm[1] + r3[1]*norm[2]; - v2[1] = r1[1]*tau1[0] + r2[1]*tau1[1] + r3[1]*tau1[2]; - v2[2] = r1[1]*tau2[0] + r2[1]*tau2[1] + r3[1]*tau2[2]; + v2[0] = r1[1] * norm[0] + r2[1] * norm[1] + r3[1] * norm[2]; + v2[1] = r1[1] * tau1[0] + r2[1] * tau1[1] + r3[1] * tau1[2]; + v2[2] = r1[1] * tau2[0] + r2[1] * tau2[1] + r3[1] * tau2[2]; - v3[0] = r1[2]*norm[0] + r2[2]*norm[1] + r3[2]*norm[2]; - v3[1] = r1[2]*tau1[0] + r2[2]*tau1[1] + r3[2]*tau1[2]; - v3[2] = r1[2]*tau2[0] + r2[2]*tau2[1] + r3[2]*tau2[2]; + v3[0] = r1[2] * norm[0] + r2[2] * norm[1] + r3[2] * norm[2]; + v3[1] = r1[2] * tau1[0] + r2[2] * tau1[1] + r3[2] * tau1[2]; + v3[2] = r1[2] * tau2[0] + r2[2] * tau2[1] + r3[2] * tau2[2]; qlocal[4] = v1[0]; qlocal[5] = v1[1]; @@ -222,46 +215,45 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[9] = v3[2]; } -GKYL_CU_DH -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qlocal, double* GKYL_RESTRICT qglobal) +GKYL_CU_DH static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { - // Mass density is a scalar qglobal[0] = qlocal[0]; // Rotate momentum back to global coordinates - qglobal[1] = qlocal[1]*norm[0] + qlocal[2]*tau1[0] + qlocal[3]*tau2[0]; - qglobal[2] = qlocal[1]*norm[1] + qlocal[2]*tau1[1] + qlocal[3]*tau2[1]; - qglobal[3] = qlocal[1]*norm[2] + qlocal[2]*tau1[2] + qlocal[3]*tau2[2]; + qglobal[1] = qlocal[1] * norm[0] + qlocal[2] * tau1[0] + qlocal[3] * tau2[0]; + qglobal[2] = qlocal[1] * norm[1] + qlocal[2] * tau1[1] + qlocal[3] * tau2[1]; + qglobal[3] = qlocal[1] * norm[2] + qlocal[2] * tau1[2] + qlocal[3] * tau2[2]; // temp arrays to store rotated column vectors double r1[3], r2[3], r3[3]; - r1[0] = qlocal[4]*norm[0] + qlocal[5]*tau1[0] + qlocal[6]*tau2[0]; - r1[1] = qlocal[4]*norm[1] + qlocal[5]*tau1[1] + qlocal[6]*tau2[1]; - r1[2] = qlocal[4]*norm[2] + qlocal[5]*tau1[2] + qlocal[6]*tau2[2]; + r1[0] = qlocal[4] * norm[0] + qlocal[5] * tau1[0] + qlocal[6] * tau2[0]; + r1[1] = qlocal[4] * norm[1] + qlocal[5] * tau1[1] + qlocal[6] * tau2[1]; + r1[2] = qlocal[4] * norm[2] + qlocal[5] * tau1[2] + qlocal[6] * tau2[2]; - r2[0] = qlocal[5]*norm[0] + qlocal[7]*tau1[0] + qlocal[8]*tau2[0]; - r2[1] = qlocal[5]*norm[1] + qlocal[7]*tau1[1] + qlocal[8]*tau2[1]; - r2[2] = qlocal[5]*norm[2] + qlocal[7]*tau1[2] + qlocal[8]*tau2[2]; + r2[0] = qlocal[5] * norm[0] + qlocal[7] * tau1[0] + qlocal[8] * tau2[0]; + r2[1] = qlocal[5] * norm[1] + qlocal[7] * tau1[1] + qlocal[8] * tau2[1]; + r2[2] = qlocal[5] * norm[2] + qlocal[7] * tau1[2] + qlocal[8] * tau2[2]; - r3[0] = qlocal[6]*norm[0] + qlocal[8]*tau1[0] + qlocal[9]*tau2[0]; - r3[1] = qlocal[6]*norm[1] + qlocal[8]*tau1[1] + qlocal[9]*tau2[1]; - r3[2] = qlocal[6]*norm[2] + qlocal[8]*tau1[2] + qlocal[9]*tau2[2]; + r3[0] = qlocal[6] * norm[0] + qlocal[8] * tau1[0] + qlocal[9] * tau2[0]; + r3[1] = qlocal[6] * norm[1] + qlocal[8] * tau1[1] + qlocal[9] * tau2[1]; + r3[2] = qlocal[6] * norm[2] + qlocal[8] * tau1[2] + qlocal[9] * tau2[2]; // temp arrays to store rotated row vectors double v1[3], v2[3], v3[3]; - v1[0] = r1[0]*norm[0] + r2[0]*tau1[0] + r3[0]*tau2[0]; - v1[1] = r1[0]*norm[1] + r2[0]*tau1[1] + r3[0]*tau2[1]; - v1[2] = r1[0]*norm[2] + r2[0]*tau1[2] + r3[0]*tau2[2]; + v1[0] = r1[0] * norm[0] + r2[0] * tau1[0] + r3[0] * tau2[0]; + v1[1] = r1[0] * norm[1] + r2[0] * tau1[1] + r3[0] * tau2[1]; + v1[2] = r1[0] * norm[2] + r2[0] * tau1[2] + r3[0] * tau2[2]; - v2[0] = r1[1]*norm[0] + r2[1]*tau1[0] + r3[1]*tau2[0]; - v2[1] = r1[1]*norm[1] + r2[1]*tau1[1] + r3[1]*tau2[1]; - v2[2] = r1[1]*norm[2] + r2[1]*tau1[2] + r3[1]*tau2[2]; + v2[0] = r1[1] * norm[0] + r2[1] * tau1[0] + r3[1] * tau2[0]; + v2[1] = r1[1] * norm[1] + r2[1] * tau1[1] + r3[1] * tau2[1]; + v2[2] = r1[1] * norm[2] + r2[1] * tau1[2] + r3[1] * tau2[2]; - v3[0] = r1[2]*norm[0] + r2[2]*tau1[0] + r3[2]*tau2[0]; - v3[1] = r1[2]*norm[1] + r2[2]*tau1[1] + r3[2]*tau2[1]; - v3[2] = r1[2]*norm[2] + r2[2]*tau1[2] + r3[2]*tau2[2]; + v3[0] = r1[2] * norm[0] + r2[2] * tau1[0] + r3[2] * tau2[0]; + v3[1] = r1[2] * norm[1] + r2[2] * tau1[1] + r3[2] * tau2[1]; + v3[2] = r1[2] * norm[2] + r2[2] * tau1[2] + r3[2] * tau2[2]; // Rotate pressure tensor back to local coordinates qglobal[4] = v1[0]; @@ -273,11 +265,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t } // Waves and speeds using Roe averaging -GKYL_CU_DH -static double -wave_roe(const struct gkyl_wv_eqn *eqn, - const double *delta, const double *ql, const double *qr, - double *waves, double *s) +GKYL_CU_DH static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { double vl[10], vr[10]; gkyl_ten_moment_primitive(ql, vl); @@ -285,24 +276,32 @@ wave_roe(const struct gkyl_wv_eqn *eqn, // compute Roe averages double sqrl = sqrt(vl[0]), sqrr = sqrt(vr[0]); - double sqr1 = 1/(sqrl+sqrr); - - double p0 = sqrl*sqrr; - double p2s1 = sq(p0*sqr1); - - double u1 = (sqrl*vl[1] + sqrr*vr[1])*sqr1; - double u2 = (sqrl*vl[2] + sqrr*vr[2])*sqr1; - double u3 = (sqrl*vl[3] + sqrr*vr[3])*sqr1; - double p11 = (sqrr*vl[4]+sqrl*vr[4])*sqr1 + 1.0/3.0*p2s1*(vr[1]-vl[1])*(vr[1]-vl[1]); - double p12 = (sqrr*vl[5]+sqrl*vr[5])*sqr1 + 1.0/3.0*p2s1*(vr[1]-vl[1])*(vr[2]-vl[2]); - double p13 = (sqrr*vl[6]+sqrl*vr[6])*sqr1 + 1.0/3.0*p2s1*(vr[1]-vl[1])*(vr[3]-vl[3]); - double p22 = (sqrr*vl[7]+sqrl*vr[7])*sqr1 + 1.0/3.0*p2s1*(vr[2]-vl[2])*(vr[2]-vl[2]); - double p23 = (sqrr*vl[8]+sqrl*vr[8])*sqr1 + 1.0/3.0*p2s1*(vr[2]-vl[2])*(vr[3]-vl[3]); - double p33 = (sqrr*vl[9]+sqrl*vr[9])*sqr1 + 1.0/3.0*p2s1*(vr[3]-vl[3])*(vr[3]-vl[3]); + double sqr1 = 1 / (sqrl + sqrr); + + double p0 = sqrl * sqrr; + double p2s1 = sq(p0 * sqr1); + + double u1 = (sqrl * vl[1] + sqrr * vr[1]) * sqr1; + double u2 = (sqrl * vl[2] + sqrr * vr[2]) * sqr1; + double u3 = (sqrl * vl[3] + sqrr * vr[3]) * sqr1; + double p11 = + (sqrr * vl[4] + sqrl * vr[4]) * sqr1 + 1.0 / 3.0 * p2s1 * (vr[1] - vl[1]) * (vr[1] - vl[1]); + double p12 = + (sqrr * vl[5] + sqrl * vr[5]) * sqr1 + 1.0 / 3.0 * p2s1 * (vr[1] - vl[1]) * (vr[2] - vl[2]); + double p13 = + (sqrr * vl[6] + sqrl * vr[6]) * sqr1 + 1.0 / 3.0 * p2s1 * (vr[1] - vl[1]) * (vr[3] - vl[3]); + double p22 = + (sqrr * vl[7] + sqrl * vr[7]) * sqr1 + 1.0 / 3.0 * p2s1 * (vr[2] - vl[2]) * (vr[2] - vl[2]); + double p23 = + (sqrr * vl[8] + sqrl * vr[8]) * sqr1 + 1.0 / 3.0 * p2s1 * (vr[2] - vl[2]) * (vr[3] - vl[3]); + double p33 = + (sqrr * vl[9] + sqrl * vr[9]) * sqr1 + 1.0 / 3.0 * p2s1 * (vr[3] - vl[3]) * (vr[3] - vl[3]); // for multiplication by phi' we need to use unrotated values double v[4]; - v[1] = u1; v[2] = u2; v[3] = u3; + v[1] = u1; + v[2] = u2; + v[3] = u3; double phiDelta[10]; @@ -310,133 +309,147 @@ wave_roe(const struct gkyl_wv_eqn *eqn, // jumps are in conserved variables, while left eigenvectors used // below are computed from primitive variables phiDelta[0] = delta[0]; - phiDelta[1] = delta[1]/p0-(1.0*delta[0]*u1)/p0; - phiDelta[2] = delta[2]/p0-(1.0*delta[0]*u2)/p0; - phiDelta[3] = delta[3]/p0-(1.0*delta[0]*u3)/p0; - phiDelta[4] = delta[0]*sq(u1)-2.0*delta[1]*u1+delta[4]; - phiDelta[5] = delta[0]*u1*u2-1.0*delta[1]*u2-1.0*delta[2]*u1+delta[5]; - phiDelta[6] = delta[0]*u1*u3-1.0*delta[1]*u3-1.0*delta[3]*u1+delta[6]; - phiDelta[7] = delta[0]*sq(u2)-2.0*delta[2]*u2+delta[7]; - phiDelta[8] = delta[0]*u2*u3-1.0*delta[2]*u3-1.0*delta[3]*u2+delta[8]; - phiDelta[9] = delta[0]*sq(u3)-2.0*delta[3]*u3+delta[9]; + phiDelta[1] = delta[1] / p0 - (1.0 * delta[0] * u1) / p0; + phiDelta[2] = delta[2] / p0 - (1.0 * delta[0] * u2) / p0; + phiDelta[3] = delta[3] / p0 - (1.0 * delta[0] * u3) / p0; + phiDelta[4] = delta[0] * sq(u1) - 2.0 * delta[1] * u1 + delta[4]; + phiDelta[5] = delta[0] * u1 * u2 - 1.0 * delta[1] * u2 - 1.0 * delta[2] * u1 + delta[5]; + phiDelta[6] = delta[0] * u1 * u3 - 1.0 * delta[1] * u3 - 1.0 * delta[3] * u1 + delta[6]; + phiDelta[7] = delta[0] * sq(u2) - 2.0 * delta[2] * u2 + delta[7]; + phiDelta[8] = delta[0] * u2 * u3 - 1.0 * delta[2] * u3 - 1.0 * delta[3] * u2 + delta[8]; + phiDelta[9] = delta[0] * sq(u3) - 2.0 * delta[3] * u3 + delta[9]; // predefine some constants - double p11sq = sq(p11), p12sq = sq(p12), p13sq = sq(p13), p11th = sqrt(p11*p11*p11); + double p11sq = sq(p11), p12sq = sq(p12), p13sq = sq(p13), p11th = sqrt(p11 * p11 * p11); double sqp0 = sqrt(p0), sqp11 = sqrt(p11); - + double leftProj[10]; // project jumps on left eigenvectors [Gen from Maxima] - leftProj[0] = (0.5*phiDelta[1]*sqp0*sqp11*p12)/p11sq-(0.5*phiDelta[4]*p12)/p11sq-(0.5*phiDelta[2]*sqp0)/sqp11+(0.5*phiDelta[5])/p11; - leftProj[1] = (0.5*phiDelta[1]*sqp0*p13)/p11th-(0.5*phiDelta[4]*p13)/p11sq-(0.5*phiDelta[3]*sqp0)/sqp11+(0.5*phiDelta[6])/p11; - leftProj[2] = (-(0.5*phiDelta[1]*sqp0*sqp11*p12)/p11sq)-(0.5*phiDelta[4]*p12)/p11sq+(0.5*phiDelta[2]*sqp0)/sqp11+(0.5*phiDelta[5])/p11; - leftProj[3] = (-(0.5*phiDelta[1]*sqp0*p13)/p11th)-(0.5*phiDelta[4]*p13)/p11sq+(0.5*phiDelta[3]*sqp0)/sqp11+(0.5*phiDelta[6])/p11; - leftProj[4] = (0.16666666666666666667*phiDelta[4])/p11sq-(0.2886751345948129*phiDelta[1]*sqp0)/p11th; - leftProj[5] = (0.2886751345948129*phiDelta[1]*sqp0)/p11th+(0.16666666666666666667*phiDelta[4])/p11sq; - leftProj[6] = phiDelta[0]-(0.3333333333333333333*phiDelta[4]*p0)/p11; - leftProj[7] = (-(0.3333333333333333333*phiDelta[4]*p11*p22)/p11sq)+(1.333333333333333333*phiDelta[4]*p12sq)/p11sq-(2.0*phiDelta[5]*p12)/p11+phiDelta[7]; - leftProj[8] = (-(0.3333333333333333333*phiDelta[4]*p11*p23)/p11sq)+(1.333333333333333333*phiDelta[4]*p12*p13)/p11sq-(1.0*phiDelta[5]*p13)/p11-(1.0*phiDelta[6]*p12)/p11+phiDelta[8]; - leftProj[9] = (-(0.3333333333333333333*phiDelta[4]*p11*p33)/p11sq)+(1.333333333333333333*phiDelta[4]*p13sq)/p11sq-(2.0*phiDelta[6]*p13)/p11+phiDelta[9]; + leftProj[0] = (0.5 * phiDelta[1] * sqp0 * sqp11 * p12) / p11sq - + (0.5 * phiDelta[4] * p12) / p11sq - (0.5 * phiDelta[2] * sqp0) / sqp11 + + (0.5 * phiDelta[5]) / p11; + leftProj[1] = (0.5 * phiDelta[1] * sqp0 * p13) / p11th - (0.5 * phiDelta[4] * p13) / p11sq - + (0.5 * phiDelta[3] * sqp0) / sqp11 + (0.5 * phiDelta[6]) / p11; + leftProj[2] = (-(0.5 * phiDelta[1] * sqp0 * sqp11 * p12) / p11sq) - + (0.5 * phiDelta[4] * p12) / p11sq + (0.5 * phiDelta[2] * sqp0) / sqp11 + + (0.5 * phiDelta[5]) / p11; + leftProj[3] = (-(0.5 * phiDelta[1] * sqp0 * p13) / p11th) - (0.5 * phiDelta[4] * p13) / p11sq + + (0.5 * phiDelta[3] * sqp0) / sqp11 + (0.5 * phiDelta[6]) / p11; + leftProj[4] = (0.16666666666666666667 * phiDelta[4]) / p11sq - + (0.2886751345948129 * phiDelta[1] * sqp0) / p11th; + leftProj[5] = (0.2886751345948129 * phiDelta[1] * sqp0) / p11th + + (0.16666666666666666667 * phiDelta[4]) / p11sq; + leftProj[6] = phiDelta[0] - (0.3333333333333333333 * phiDelta[4] * p0) / p11; + leftProj[7] = (-(0.3333333333333333333 * phiDelta[4] * p11 * p22) / p11sq) + + (1.333333333333333333 * phiDelta[4] * p12sq) / p11sq - + (2.0 * phiDelta[5] * p12) / p11 + phiDelta[7]; + leftProj[8] = (-(0.3333333333333333333 * phiDelta[4] * p11 * p23) / p11sq) + + (1.333333333333333333 * phiDelta[4] * p12 * p13) / p11sq - + (1.0 * phiDelta[5] * p13) / p11 - (1.0 * phiDelta[6] * p12) / p11 + phiDelta[8]; + leftProj[9] = (-(0.3333333333333333333 * phiDelta[4] * p11 * p33) / p11sq) + + (1.333333333333333333 * phiDelta[4] * p13sq) / p11sq - + (2.0 * phiDelta[6] * p13) / p11 + phiDelta[9]; // compute waves and speeds double wv[10]; // Wave 1: (ev 1 and 2 are repeated) - s[0] = u1-sqrt(p11/p0); - wv[0] = 0.0; - wv[1] = 0.0; - wv[2] = -(1.0*leftProj[0]*sqp11)/sqp0; - wv[3] = -(1.0*leftProj[1]*sqp11)/sqp0; - wv[4] = 0.0; - wv[5] = leftProj[0]*p11; - wv[6] = leftProj[1]*p11; - wv[7] = 2.0*leftProj[0]*p12; - wv[8] = leftProj[0]*p13+leftProj[1]*p12; - wv[9] = 2.0*leftProj[1]*p13; + s[0] = u1 - sqrt(p11 / p0); + wv[0] = 0.0; + wv[1] = 0.0; + wv[2] = -(1.0 * leftProj[0] * sqp11) / sqp0; + wv[3] = -(1.0 * leftProj[1] * sqp11) / sqp0; + wv[4] = 0.0; + wv[5] = leftProj[0] * p11; + wv[6] = leftProj[1] * p11; + wv[7] = 2.0 * leftProj[0] * p12; + wv[8] = leftProj[0] * p13 + leftProj[1] * p12; + wv[9] = 2.0 * leftProj[1] * p13; mulByPhiPrime(p0, v[1], v[2], v[3], wv, &waves[0]); // Wave 2: (ev 3 and 4 are repeated) - s[1] = u1+sqrt(p11/p0); - wv[0] = 0.0; - wv[1] = 0.0; - wv[2] = (leftProj[2]*sqp11)/sqp0; - wv[3] = (leftProj[3]*sqp11)/sqp0; - wv[4] = 0.0; - wv[5] = leftProj[2]*p11; - wv[6] = leftProj[3]*p11; - wv[7] = 2.0*leftProj[2]*p12; - wv[8] = leftProj[2]*p13+leftProj[3]*p12; - wv[9] = 2.0*leftProj[3]*p13; + s[1] = u1 + sqrt(p11 / p0); + wv[0] = 0.0; + wv[1] = 0.0; + wv[2] = (leftProj[2] * sqp11) / sqp0; + wv[3] = (leftProj[3] * sqp11) / sqp0; + wv[4] = 0.0; + wv[5] = leftProj[2] * p11; + wv[6] = leftProj[3] * p11; + wv[7] = 2.0 * leftProj[2] * p12; + wv[8] = leftProj[2] * p13 + leftProj[3] * p12; + wv[9] = 2.0 * leftProj[3] * p13; mulByPhiPrime(p0, v[1], v[2], v[3], wv, &waves[10]); - + // Wave 3 (ev 5) - s[2] = u1-sqrt(3*p11/p0); - wv[0] = leftProj[4]*p0*p11; - wv[1] = -(1.732050807568877*leftProj[4]*p11th)/sqp0; - wv[2] = -(1.732050807568877*leftProj[4]*sqp11*p12)/sqp0; - wv[3] = -(1.732050807568877*leftProj[4]*sqp11*p13)/sqp0; - wv[4] = 3.0*leftProj[4]*p11sq; - wv[5] = 3.0*leftProj[4]*p11*p12; - wv[6] = 3.0*leftProj[4]*p11*p13; - wv[7] = leftProj[4]*p11*p22+2.0*leftProj[4]*p12sq; - wv[8] = leftProj[4]*p11*p23+2.0*leftProj[4]*p12*p13; - wv[9] = leftProj[4]*p11*p33+2.0*leftProj[4]*p13sq; + s[2] = u1 - sqrt(3 * p11 / p0); + wv[0] = leftProj[4] * p0 * p11; + wv[1] = -(1.732050807568877 * leftProj[4] * p11th) / sqp0; + wv[2] = -(1.732050807568877 * leftProj[4] * sqp11 * p12) / sqp0; + wv[3] = -(1.732050807568877 * leftProj[4] * sqp11 * p13) / sqp0; + wv[4] = 3.0 * leftProj[4] * p11sq; + wv[5] = 3.0 * leftProj[4] * p11 * p12; + wv[6] = 3.0 * leftProj[4] * p11 * p13; + wv[7] = leftProj[4] * p11 * p22 + 2.0 * leftProj[4] * p12sq; + wv[8] = leftProj[4] * p11 * p23 + 2.0 * leftProj[4] * p12 * p13; + wv[9] = leftProj[4] * p11 * p33 + 2.0 * leftProj[4] * p13sq; mulByPhiPrime(p0, v[1], v[2], v[3], wv, &waves[20]); // Wave 4 (ev 6) - s[3] = u1+sqrt(3*p11/p0); - wv[0] = leftProj[5]*p0*p11; - wv[1] = (1.732050807568877*leftProj[5]*p11th)/sqp0; - wv[2] = (1.732050807568877*leftProj[5]*sqp11*p12)/sqp0; - wv[3] = (1.732050807568877*leftProj[5]*sqp11*p13)/sqp0; - wv[4] = 3.0*leftProj[5]*p11sq; - wv[5] = 3.0*leftProj[5]*p11*p12; - wv[6] = 3.0*leftProj[5]*p11*p13; - wv[7] = leftProj[5]*p11*p22+2.0*leftProj[5]*p12sq; - wv[8] = leftProj[5]*p11*p23+2.0*leftProj[5]*p12*p13; - wv[9] = leftProj[5]*p11*p33+2.0*leftProj[5]*p13sq; + s[3] = u1 + sqrt(3 * p11 / p0); + wv[0] = leftProj[5] * p0 * p11; + wv[1] = (1.732050807568877 * leftProj[5] * p11th) / sqp0; + wv[2] = (1.732050807568877 * leftProj[5] * sqp11 * p12) / sqp0; + wv[3] = (1.732050807568877 * leftProj[5] * sqp11 * p13) / sqp0; + wv[4] = 3.0 * leftProj[5] * p11sq; + wv[5] = 3.0 * leftProj[5] * p11 * p12; + wv[6] = 3.0 * leftProj[5] * p11 * p13; + wv[7] = leftProj[5] * p11 * p22 + 2.0 * leftProj[5] * p12sq; + wv[8] = leftProj[5] * p11 * p23 + 2.0 * leftProj[5] * p12 * p13; + wv[9] = leftProj[5] * p11 * p33 + 2.0 * leftProj[5] * p13sq; mulByPhiPrime(p0, v[1], v[2], v[3], wv, &waves[30]); // Wave 5: (ev 7, 8, 9, 10 are repeated) s[4] = u1; - wv[0] = leftProj[6]; - wv[1] = 0.0; - wv[2] = 0.0; - wv[3] = 0.0; - wv[4] = 0.0; - wv[5] = 0.0; - wv[6] = 0.0; - wv[7] = leftProj[7]; - wv[8] = leftProj[8]; + wv[0] = leftProj[6]; + wv[1] = 0.0; + wv[2] = 0.0; + wv[3] = 0.0; + wv[4] = 0.0; + wv[5] = 0.0; + wv[6] = 0.0; + wv[7] = leftProj[7]; + wv[8] = leftProj[8]; wv[9] = leftProj[9]; mulByPhiPrime(p0, v[1], v[2], v[3], wv, &waves[40]); - - return fabs(u1)+sqrt(3*p11/p0); + + return fabs(u1) + sqrt(3 * p11 / p0); } -GKYL_CU_DH -static void -qfluct_roe(const struct gkyl_wv_eqn *eqn, - const double *ql, const double *qr, const double *waves, const double *s, - double *amdq, double *apdq) +GKYL_CU_DH static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { - const double *w0 = &waves[0], *w1 = &waves[10], *w2 = &waves[20], *w3 = &waves[30], *w4 = &waves[40]; - double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]), s3m = fmin(0.0, s[3]), s4m = fmin(0.0, s[4]); - double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]), s3p = fmax(0.0, s[3]), s4p = fmax(0.0, s[4]); - - for (int i=0; i<10; ++i) { - amdq[i] = s0m*w0[i] + s1m*w1[i] + s2m*w2[i] + s3m*w3[i] + s4m*w4[i]; - apdq[i] = s0p*w0[i] + s1p*w1[i] + s2p*w2[i] + s3p*w3[i] + s4p*w4[i]; + const double *w0 = &waves[0], *w1 = &waves[10], *w2 = &waves[20], *w3 = &waves[30], + *w4 = &waves[40]; + double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]), s3m = fmin(0.0, s[3]), + s4m = fmin(0.0, s[4]); + double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]), s3p = fmax(0.0, s[3]), + s4p = fmax(0.0, s[4]); + + for (int i = 0; i < 10; ++i) { + amdq[i] = s0m * w0[i] + s1m * w1[i] + s2m * w2[i] + s3m * w3[i] + s4m * w4[i]; + apdq[i] = s0p * w0[i] + s1p * w1[i] + s2p * w2[i] + s3p * w3[i] + s4p * w4[i]; } } -GKYL_CU_DH -static void -wave_embed_absorb(const double *q, double *qphi, double *delta, void *ctx) +GKYL_CU_DH static void wave_embed_absorb(const double *q, double *qphi, double *delta, void *ctx) { qphi[0] = 0.0; qphi[1] = 0.0; @@ -450,9 +463,7 @@ wave_embed_absorb(const double *q, double *qphi, double *delta, void *ctx) qphi[9] = 0.0; } -GKYL_CU_DH -static void -wave_embed_reflect(const double *q, double *qphi, double *delta, void *ctx) +GKYL_CU_DH static void wave_embed_reflect(const double *q, double *qphi, double *delta, void *ctx) { qphi[0] = q[0]; qphi[1] = -q[1]; @@ -466,11 +477,10 @@ wave_embed_reflect(const double *q, double *qphi, double *delta, void *ctx) qphi[9] = q[9]; } -GKYL_CU_DH -static double -wave_embedded(const struct gkyl_wv_eqn *eqn, - const double *delta, const double *ql, const double *qr, - const double phil, const double phir, double *waves, double *s) +GKYL_CU_DH static double wave_embedded( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + const double phil, const double phir, double *waves, double *s +) { double deltaphi[10] = {0.0}; double qphi[10] = {0.0}; @@ -481,45 +491,44 @@ wave_embedded(const struct gkyl_wv_eqn *eqn, if ((phil < 0.0) && (phir > 0.0)) { double sr = gkyl_ten_moment_max_abs_speed(qr); amax = sr; - + eqn->embed_geo->embed_func(qr, qphi, deltaphi, eqn->embed_geo->ctx); gkyl_ten_moment_flux(qphi, fl); gkyl_ten_moment_flux(qr, fr); double *w0 = &waves[0], *w1 = &waves[10]; - for (int i=0; i<10; ++i) { - w1[i] = 0.5*((qr[i]-qphi[i]) + (fr[i]-fl[i])/amax); + for (int i = 0; i < 10; ++i) { + w1[i] = 0.5 * ((qr[i] - qphi[i]) + (fr[i] - fl[i]) / amax); } } - + if ((phir < 0.0) && (phil > 0.0)) { double sl = gkyl_ten_moment_max_abs_speed(ql); amax = sl; - + eqn->embed_geo->embed_func(ql, qphi, deltaphi, eqn->embed_geo->ctx); gkyl_ten_moment_flux(ql, fl); gkyl_ten_moment_flux(qphi, fr); - + double *w0 = &waves[0], *w1 = &waves[10]; - for (int i=0; i<10; ++i) { - w0[i] = 0.5*((qphi[i]-ql[i]) - (fr[i]-fl[i])/amax); + for (int i = 0; i < 10; ++i) { + w0[i] = 0.5 * ((qphi[i] - ql[i]) - (fr[i] - fl[i]) / amax); } } s[0] = -amax; s[1] = amax; - + return s[1]; } // Waves and speeds using Lax fluxes -GKYL_CU_DH -static double -wave_lax(const struct gkyl_wv_eqn *eqn, - const double *delta, const double *ql, const double *qr, - double *waves, double *s) +GKYL_CU_DH static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { double sl = gkyl_ten_moment_max_abs_speed(ql); double sr = gkyl_ten_moment_max_abs_speed(qr); @@ -530,75 +539,74 @@ wave_lax(const struct gkyl_wv_eqn *eqn, gkyl_ten_moment_flux(qr, fr); double *w0 = &waves[0], *w1 = &waves[10]; - for (int i=0; i<10; ++i) { - w0[i] = 0.5*((qr[i]-ql[i]) - (fr[i]-fl[i])/amax); - w1[i] = 0.5*((qr[i]-ql[i]) + (fr[i]-fl[i])/amax); + for (int i = 0; i < 10; ++i) { + w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr[i] - fl[i]) / amax); + w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr[i] - fl[i]) / amax); } s[0] = -amax; s[1] = amax; - + return s[1]; } -GKYL_CU_DH -static void -qfluct_lax(const struct gkyl_wv_eqn *eqn, - const double *ql, const double *qr, const double *waves, const double *s, - double *amdq, double *apdq) +GKYL_CU_DH static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[10]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]); - for (int i=0; i<10; ++i) { - amdq[i] = s0m*w0[i] + s1m*w1[i]; - apdq[i] = s0p*w0[i] + s1p*w1[i]; + for (int i = 0; i < 10; ++i) { + amdq[i] = s0m * w0[i] + s1m * w1[i]; + apdq[i] = s0p * w0[i] + s1p * w1[i]; } } -GKYL_CU_DH -static double -wave(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *delta, const double *ql, const double *qr, - const double phil, const double phir, double *waves, double *s) +GKYL_CU_DH static double wave( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { // clear waves and wave speeds int mwaves = (type == GKYL_WV_HIGH_ORDER_FLUX) ? eqn->num_waves : 2; int meqn = eqn->num_equations; - for (int i=0; i 0.0) && (phir > 0.0)) + if (type == GKYL_WV_HIGH_ORDER_FLUX && (phil > 0.0) && (phir > 0.0)) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - else + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); + } } -GKYL_CU_DH -static bool -check_inv(const struct gkyl_wv_eqn *eqn, const double *q) +GKYL_CU_DH static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { if (q[0] < 0.0) { return false; @@ -609,13 +617,11 @@ check_inv(const struct gkyl_wv_eqn *eqn, const double *q) if (P[0] < 0.0 || P[1] < 0.0 || P[2] < 0.0) { return false; } - + return true; } -GKYL_CU_DH -static double -max_speed(const struct gkyl_wv_eqn *eqn, const double *q) +GKYL_CU_DH static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { return gkyl_ten_moment_max_abs_speed(q); } diff --git a/moments/zero/gkyl_wv_vacuum_einstein.h b/moments/zero/gkyl_wv_vacuum_einstein.h index 80b484bf09..6822dda51a 100644 --- a/moments/zero/gkyl_wv_vacuum_einstein.h +++ b/moments/zero/gkyl_wv_vacuum_einstein.h @@ -6,7 +6,7 @@ // Type of Riemann-solver to use: enum gkyl_wv_vacuum_einstein_rp { WV_VACUUM_EINSTEIN_RP_HLL = 0, // Default (HLL fluxes). - WV_VACUUM_EINSTEIN_RP_LAX, + WV_VACUUM_EINSTEIN_RP_LAX }; // Input context, packaged as a struct. @@ -28,9 +28,10 @@ struct gkyl_wv_vacuum_einstein_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the vacuum Einstein equations object using the Bona-Masso formalism. */ -struct gkyl_wv_eqn* -gkyl_wv_vacuum_einstein_new(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, enum gkyl_spacetime_evolution spacetime_evolution, - bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_vacuum_einstein_new( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, + enum gkyl_spacetime_evolution spacetime_evolution, bool use_gpu +); /** * Create a new vacuum Einstein equations object using the Bona-Masso formalism, from an input context struct. @@ -38,8 +39,7 @@ gkyl_wv_vacuum_einstein_new(double excision_threshold, enum gkyl_spacetime_slici * @param inp Input context struct. * @return Pointer to the vacuum Einstein equations object using the Bona-Masso formalism. */ -struct gkyl_wv_eqn* -gkyl_wv_vacuum_einstein_inew(const struct gkyl_wv_vacuum_einstein_inp* inp); +struct gkyl_wv_eqn *gkyl_wv_vacuum_einstein_inew(const struct gkyl_wv_vacuum_einstein_inp *inp); /** * Get excision threshold. @@ -47,8 +47,7 @@ gkyl_wv_vacuum_einstein_inew(const struct gkyl_wv_vacuum_einstein_inp* inp); * @param eqn Vacuum Einstein equations object using the Bona-Masso formalism. * @return Excision threshold (lapse). */ -double -gkyl_wv_vacuum_einstein_excision_threshold(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_vacuum_einstein_excision_threshold(const struct gkyl_wv_eqn *eqn); /** * Get spacetime slicing condition. @@ -56,8 +55,8 @@ gkyl_wv_vacuum_einstein_excision_threshold(const struct gkyl_wv_eqn* eqn); * @param eqn Vacuum Einstein equations object using the Bona-Masso formalism. * @return Spacetime slicing condition. */ -enum gkyl_spacetime_slicing -gkyl_wv_vacuum_einstein_spacetime_slicing(const struct gkyl_wv_eqn* eqn); +enum gkyl_spacetime_slicing gkyl_wv_vacuum_einstein_spacetime_slicing(const struct gkyl_wv_eqn *eqn +); /** * Get spacetime evolution system. @@ -66,4 +65,4 @@ gkyl_wv_vacuum_einstein_spacetime_slicing(const struct gkyl_wv_eqn* eqn); * @return Spacetime evolution system. */ enum gkyl_spacetime_evolution -gkyl_wv_vacuum_einstein_spacetime_evolution(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +gkyl_wv_vacuum_einstein_spacetime_evolution(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_vacuum_einstein_conformal.h b/moments/zero/gkyl_wv_vacuum_einstein_conformal.h index 1763ed6520..a8574f7382 100644 --- a/moments/zero/gkyl_wv_vacuum_einstein_conformal.h +++ b/moments/zero/gkyl_wv_vacuum_einstein_conformal.h @@ -6,7 +6,7 @@ // Type of Riemann-solver to use: enum gkyl_wv_vacuum_einstein_conformal_rp { WV_VACUUM_EINSTEIN_CONFORMAL_RP_HLL = 0, // Default (HLL fluxes). - WV_VACUUM_EINSTEIN_CONFORMAL_RP_LAX, + WV_VACUUM_EINSTEIN_CONFORMAL_RP_LAX }; // Input context, packaged as a struct. @@ -28,9 +28,10 @@ struct gkyl_wv_vacuum_einstein_conformal_inp { * @param use_gpu Whether the wave equation object is on the host (false) or the device (true). * @return Pointer to the vacuum Einstein equations object using the conformal Bona-Masso formalism. */ -struct gkyl_wv_eqn* -gkyl_wv_vacuum_einstein_conformal_new(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, enum gkyl_spacetime_evolution spacetime_evolution, - bool use_gpu); +struct gkyl_wv_eqn *gkyl_wv_vacuum_einstein_conformal_new( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, + enum gkyl_spacetime_evolution spacetime_evolution, bool use_gpu +); /** * Create a new vacuum Einstein equations object using the conformal Bona-Masso formalism, from an input context struct. @@ -38,8 +39,8 @@ gkyl_wv_vacuum_einstein_conformal_new(double excision_threshold, enum gkyl_space * @param inp Input context struct. * @return Pointer to the vacuum Einstein equations object using the conformal Bona-Masso formalism. */ -struct gkyl_wv_eqn* -gkyl_wv_vacuum_einstein_conformal_inew(const struct gkyl_wv_vacuum_einstein_conformal_inp* inp); +struct gkyl_wv_eqn * +gkyl_wv_vacuum_einstein_conformal_inew(const struct gkyl_wv_vacuum_einstein_conformal_inp *inp); /** * Get excision threshold. @@ -47,8 +48,7 @@ gkyl_wv_vacuum_einstein_conformal_inew(const struct gkyl_wv_vacuum_einstein_conf * @param eqn Vacuum Einstein equations object using the conformal Bona-Masso formalism. * @return Excision threshold (lapse). */ -double -gkyl_wv_vacuum_einstein_conformal_excision_threshold(const struct gkyl_wv_eqn* eqn); +double gkyl_wv_vacuum_einstein_conformal_excision_threshold(const struct gkyl_wv_eqn *eqn); /** * Get spacetime slicing condition. @@ -57,7 +57,7 @@ gkyl_wv_vacuum_einstein_conformal_excision_threshold(const struct gkyl_wv_eqn* e * @return Spacetime slicing condition. */ enum gkyl_spacetime_slicing -gkyl_wv_vacuum_einstein_conformal_spacetime_slicing(const struct gkyl_wv_eqn* eqn); +gkyl_wv_vacuum_einstein_conformal_spacetime_slicing(const struct gkyl_wv_eqn *eqn); /** * Get spacetime evolution system. @@ -66,4 +66,4 @@ gkyl_wv_vacuum_einstein_conformal_spacetime_slicing(const struct gkyl_wv_eqn* eq * @return Spacetime evolution system. */ enum gkyl_spacetime_evolution -gkyl_wv_vacuum_einstein_conformal_spacetime_evolution(const struct gkyl_wv_eqn* eqn); \ No newline at end of file +gkyl_wv_vacuum_einstein_conformal_spacetime_evolution(const struct gkyl_wv_eqn *eqn); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_vacuum_einstein_conformal_priv.h b/moments/zero/gkyl_wv_vacuum_einstein_conformal_priv.h index 93b8523324..ca701b8b00 100644 --- a/moments/zero/gkyl_wv_vacuum_einstein_conformal_priv.h +++ b/moments/zero/gkyl_wv_vacuum_einstein_conformal_priv.h @@ -27,10 +27,10 @@ struct wv_vacuum_einstein_conformal { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, enum gkyl_spacetime_evolution spacetime_evolution, - const double q[77], double flux[77]); +GKYL_CU_D void gkyl_vacuum_einstein_conformal_flux( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, + enum gkyl_spacetime_evolution spacetime_evolution, const double q[77], double flux[77] +); /** * Compute inverse conformal spatial metric tensor (in contravariant component form) given the conserved variables. @@ -38,9 +38,9 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti * @param q Conserved variable vector. * @param inv_spatial_metric Inverse spatial metric tensor (output). */ -GKYL_CU_D -void -gkyl_vacuum_einstein_conformal_inv_spatial_metric(const double q[77], double ***inv_conformal_spatial_metric); +GKYL_CU_D void gkyl_vacuum_einstein_conformal_inv_spatial_metric( + const double q[77], double ***inv_conformal_spatial_metric +); /** * Compute maximum absolute wave speed. @@ -50,9 +50,9 @@ gkyl_vacuum_einstein_conformal_inv_spatial_metric(const double q[77], double *** * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_vacuum_einstein_conformal_max_abs_speed(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, const double q[77]); +GKYL_CU_D static inline double gkyl_vacuum_einstein_conformal_max_abs_speed( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, const double q[77] +); /** * Compute Riemann variables given the conserved variables. @@ -62,9 +62,8 @@ gkyl_vacuum_einstein_conformal_max_abs_speed(double excision_threshold, enum gky * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -74,9 +73,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the vacuum Einstein equations using the conformal Bona-Masso formalism. @@ -88,9 +86,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -vacuum_einstein_conformal_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void vacuum_einstein_conformal_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -102,10 +101,10 @@ vacuum_einstein_conformal_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -117,10 +116,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -133,9 +132,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -148,9 +148,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -166,10 +167,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, - double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -185,10 +186,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, - const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using HLL fluxes. @@ -201,9 +203,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using HLL fluxes. @@ -216,9 +219,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using HLL fluxes (with potential fallback). @@ -234,10 +238,10 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, - double* waves, double* s); +GKYL_CU_D static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using HLL fluxes (with potential fallback), @@ -253,10 +257,11 @@ wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, - const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -267,9 +272,8 @@ qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the vacuum Einstein equations using the conformal Bona-Masso formalism is satisfied. @@ -278,9 +282,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -289,9 +291,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -300,9 +300,9 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -vacuum_einstein_conformal_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void vacuum_einstein_conformal_cons_to_diag( + const struct gkyl_wv_eqn *eqn, const double *qin, double *diag +); /** * Compute forcing/source term vector from conserved variables. @@ -311,14 +311,12 @@ vacuum_einstein_conformal_cons_to_diag(const struct gkyl_wv_eqn* eqn, const doub * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +vacuum_einstein_conformal_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free vacuum Einstein equations object using the conformal Bona-Masso formalism. * * @param ref Reference counter for vacuum Einstein equations object using the conformal Bona-Masso formalism. */ -void -gkyl_vacuum_einstein_conformal_free(const struct gkyl_ref_count* ref); \ No newline at end of file +void gkyl_vacuum_einstein_conformal_free(const struct gkyl_ref_count *ref); \ No newline at end of file diff --git a/moments/zero/gkyl_wv_vacuum_einstein_priv.h b/moments/zero/gkyl_wv_vacuum_einstein_priv.h index cee8641112..f7167aa2b2 100644 --- a/moments/zero/gkyl_wv_vacuum_einstein_priv.h +++ b/moments/zero/gkyl_wv_vacuum_einstein_priv.h @@ -27,10 +27,10 @@ struct wv_vacuum_einstein { * @param q Conserved variable vector. * @param flux Flux vector in direction 'dir' (output). */ -GKYL_CU_D -void -gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, enum gkyl_spacetime_evolution spacetime_evolution, - const double q[64], double flux[64]); +GKYL_CU_D void gkyl_vacuum_einstein_flux( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, + enum gkyl_spacetime_evolution spacetime_evolution, const double q[64], double flux[64] +); /** * Compute inverse spatial metric tensor (in contravariant component form) given the conserved variables. @@ -38,8 +38,7 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing * @param q Conserved variable vector. * @param inv_spatial_metric Inverse spatial metric tensor (output). */ -GKYL_CU_D -void +GKYL_CU_D void gkyl_vacuum_einstein_inv_spatial_metric(const double q[64], double ***inv_spatial_metric); /** @@ -50,9 +49,9 @@ gkyl_vacuum_einstein_inv_spatial_metric(const double q[64], double ***inv_spatia * @param q Conserved variable vector. * @return Maximum absolute wave speed for a given q. */ -GKYL_CU_D -static inline double -gkyl_vacuum_einstein_max_abs_speed(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, const double q[64]); +GKYL_CU_D static inline double gkyl_vacuum_einstein_max_abs_speed( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, const double q[64] +); /** * Compute Riemann variables given the conserved variables. @@ -62,9 +61,8 @@ gkyl_vacuum_einstein_max_abs_speed(double excision_threshold, enum gkyl_spacetim * @param qin Conserved variable vector (input). * @param wout Riemann variable vector (output). */ -GKYL_CU_D -static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout); +GKYL_CU_D static inline void +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout); /** * Compute conserved variables given the Riemann variables. @@ -74,9 +72,8 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param win Riemann variable vector (input). * @param qout Conserved variable vector (output). */ -GKYL_CU_D -static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double *qout); +GKYL_CU_D static inline void +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout); /** * Boundary condition function for applying wall boundary conditions for the vacuum Einstein equations using the Bona-Masso formalism. @@ -88,9 +85,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -GKYL_CU_D -static void -vacuum_einstein_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx); +GKYL_CU_D static void vacuum_einstein_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +); /** * Rotate state vector from global to local coordinate frame. @@ -102,10 +100,10 @@ vacuum_einstein_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const doub * @param qglobal State vector in global coordinate frame (input). * @param qlocal State vector in local coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal); +GKYL_CU_D static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); /** * Rotate state vector from local to global coordinate frame. @@ -117,10 +115,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta * @param qlocal State vector in local coordinate frame (input). * @param qglobal State vector in global coordinate frame (output). */ -GKYL_CU_D -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal); +GKYL_CU_D static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); /** * Compute waves and speeds using Lax fluxes. @@ -133,9 +131,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using Lax fluxes. @@ -148,9 +147,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using Lax fluxes (with potential fallback). @@ -166,10 +166,10 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, - double* waves, double* s); +GKYL_CU_D static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using Lax fluxes (with potential fallback), @@ -185,10 +185,11 @@ wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, - const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute waves and speeds using HLL fluxes. @@ -201,9 +202,10 @@ qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s); +GKYL_CU_D static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +); /** * Compute fluctuations using HLL fluxes. @@ -216,9 +218,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +); /** * Compute waves and speeds using HLL fluxes (with potential fallback). @@ -234,10 +237,10 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co * @param s Wave speeds (output). * @return Maximum wave speed. */ -GKYL_CU_D -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, - double* waves, double* s); +GKYL_CU_D static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +); /** * Compute fluctuations using HLL fluxes (with potential fallback), @@ -253,10 +256,11 @@ wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const dou * @param amdq Left-moving fluctuations (output). * @param apdq Right-moving fluctuations (output). */ -GKYL_CU_D -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, - const double* waves, const double* s, double* amdq, double* apdq); +GKYL_CU_D static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +); /** * Compute jump in flux given two conserved variable states. @@ -267,9 +271,8 @@ qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const d * @param flux_jump Jump in flux vector (output). * @return Maximum wave speeds for states ql and qr. */ -GKYL_CU_D -static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump); +GKYL_CU_D static double +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump); /** * Determine whether invariant domain of the vacuum Einstein equations using the Bona-Masso formalism is satisfied. @@ -278,9 +281,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou * @param q Conserved variable vector. * @return Whether the invariant domain is satisfied. */ -GKYL_CU_D -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q); /** * Compute maximum wave speed from a conserved variable vector. @@ -289,9 +290,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q); * @param q Conserved variable vector. * @return Maximum absolute wave speed. */ -GKYL_CU_D -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q); +GKYL_CU_D static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q); /** * Convert conserved variables to diagnostic variables. @@ -300,9 +299,8 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q); * @param qin Conserved variable vector (input). * @param diag Diagnostic variable vector (output). */ -GKYL_CU_D -static inline void -vacuum_einstein_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag); +GKYL_CU_D static inline void +vacuum_einstein_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag); /** * Compute forcing/source term vector from conserved variables. @@ -311,13 +309,12 @@ vacuum_einstein_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, d * @param qin Conserved variable vector (input). * @param sout Forcing/source term vector (output). */ -GKYL_CU_DH -static inline void -vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +GKYL_CU_DH static inline void +vacuum_einstein_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); /** * Free vacuum Einstein equations object using the Bona-Masso formalism. * * @param ref Reference counter for vacuum Einstein equations object using the Bona-Masso formalism. */ -void gkyl_vacuum_einstein_free(const struct gkyl_ref_count* ref); \ No newline at end of file +void gkyl_vacuum_einstein_free(const struct gkyl_ref_count *ref); \ No newline at end of file diff --git a/moments/zero/gr_blackhole.c b/moments/zero/gr_blackhole.c index 55ffc1d090..3caf9a3572 100644 --- a/moments/zero/gr_blackhole.c +++ b/moments/zero/gr_blackhole.c @@ -6,8 +6,9 @@ #include #include -double -blackhole_kerrschildscalar(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double blackhole_kerrschildscalar( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { const struct gr_blackhole *blackhole = container_of(spacetime, struct gr_blackhole, spacetime); @@ -18,17 +19,26 @@ blackhole_kerrschildscalar(const struct gkyl_gr_spacetime* spacetime, const doub double pos_y = blackhole->pos_y; double pos_z = blackhole->pos_z; - double norm_sq = ((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z)); + double norm_sq = + ((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z)); - double rad_dist = sqrt(0.5 * (norm_sq - ((mass * mass) * (spin * spin)) + sqrt(((norm_sq - ((mass * mass) * (spin * spin))) * - (norm_sq - ((mass * mass) * (spin * spin)))) + (4.0 * ((mass * mass) * (spin * spin) * ((z - pos_z) * (z - pos_z))))))); - - return - (mass * (rad_dist * rad_dist * rad_dist)) / ((rad_dist * rad_dist * rad_dist * rad_dist) + ((mass * mass) * (spin * spin) * - ((z - pos_z) * (z - pos_z)))); + double rad_dist = sqrt( + 0.5 * + (norm_sq - ((mass * mass) * (spin * spin)) + + sqrt( + ((norm_sq - ((mass * mass) * (spin * spin))) * (norm_sq - ((mass * mass) * (spin * spin)))) + + (4.0 * ((mass * mass) * (spin * spin) * ((z - pos_z) * (z - pos_z)))) + )) + ); + + return -(mass * (rad_dist * rad_dist * rad_dist)) / + ((rad_dist * rad_dist * rad_dist * rad_dist) + + ((mass * mass) * (spin * spin) * ((z - pos_z) * (z - pos_z)))); } -double* -blackhole_kerrschildvector(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double *blackhole_kerrschildvector( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { const struct gr_blackhole *blackhole = container_of(spacetime, struct gr_blackhole, spacetime); @@ -39,21 +49,31 @@ blackhole_kerrschildvector(const struct gkyl_gr_spacetime* spacetime, const doub double pos_y = blackhole->pos_y; double pos_z = blackhole->pos_z; - double norm_sq = ((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z)); + double norm_sq = + ((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z)); + + double rad_dist = sqrt( + 0.5 * + (norm_sq - ((mass * mass) * (spin * spin)) + + sqrt( + ((norm_sq - ((mass * mass) * (spin * spin))) * (norm_sq - ((mass * mass) * (spin * spin)))) + + (4.0 * ((mass * mass) * (spin * spin) * ((z - pos_z) * (z - pos_z)))) + )) + ); - double rad_dist = sqrt(0.5 * (norm_sq - ((mass * mass) * (spin * spin)) + sqrt(((norm_sq - ((mass * mass) * (spin * spin))) * - (norm_sq - ((mass * mass) * (spin * spin)))) + (4.0 * ((mass * mass) * (spin * spin) * ((z - pos_z) * (z - pos_z))))))); - double *kerrschild_vector = gkyl_malloc(sizeof(double[3])); - kerrschild_vector[0] = - ((rad_dist * (x - pos_x)) + (spin * mass * (y - pos_y))) / ((rad_dist * rad_dist) + ((mass * mass) * (spin * spin))); - kerrschild_vector[1] = - ((rad_dist * (y - pos_y)) - (spin * mass * (x - pos_x))) / ((rad_dist * rad_dist) + ((mass * mass) * (spin * spin))); - kerrschild_vector[2] = - (z - pos_z) / rad_dist; + kerrschild_vector[0] = -((rad_dist * (x - pos_x)) + (spin * mass * (y - pos_y))) / + ((rad_dist * rad_dist) + ((mass * mass) * (spin * spin))); + kerrschild_vector[1] = -((rad_dist * (y - pos_y)) - (spin * mass * (x - pos_x))) / + ((rad_dist * rad_dist) + ((mass * mass) * (spin * spin))); + kerrschild_vector[2] = -(z - pos_z) / rad_dist; return kerrschild_vector; } -double* -blackhole_kerrschildvector_spacetime(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double *blackhole_kerrschildvector_spacetime( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { const struct gr_blackhole *blackhole = container_of(spacetime, struct gr_blackhole, spacetime); @@ -64,23 +84,33 @@ blackhole_kerrschildvector_spacetime(const struct gkyl_gr_spacetime* spacetime, double pos_y = blackhole->pos_y; double pos_z = blackhole->pos_z; - double norm_sq = ((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z)); + double norm_sq = + ((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z)); + + double rad_dist = sqrt( + 0.5 * + (norm_sq - ((mass * mass) * (spin * spin)) + + sqrt( + ((norm_sq - ((mass * mass) * (spin * spin))) * (norm_sq - ((mass * mass) * (spin * spin)))) + + (4.0 * ((mass * mass) * (spin * spin) * ((z - pos_z) * (z - pos_z)))) + )) + ); - double rad_dist = sqrt(0.5 * (norm_sq - ((mass * mass) * (spin * spin)) + sqrt(((norm_sq - ((mass * mass) * (spin * spin))) * - (norm_sq - ((mass * mass) * (spin * spin)))) + (4.0 * ((mass * mass) * (spin * spin) * ((z - pos_z) * (z - pos_z))))))); - double *kerrschild_vector_spacetime = gkyl_malloc(sizeof(double[4])); kerrschild_vector_spacetime[0] = -1.0; - kerrschild_vector_spacetime[1] = - ((rad_dist * (x - pos_x)) + (spin * mass * (y - pos_y))) / ((rad_dist * rad_dist) + ((mass * mass) * (spin * spin))); - kerrschild_vector_spacetime[2] = - ((rad_dist * (y - pos_y)) - (spin * mass * (x - pos_x))) / ((rad_dist * rad_dist) + ((mass * mass) * (spin * spin))); - kerrschild_vector_spacetime[3] = - (z - pos_z) / rad_dist; + kerrschild_vector_spacetime[1] = -((rad_dist * (x - pos_x)) + (spin * mass * (y - pos_y))) / + ((rad_dist * rad_dist) + ((mass * mass) * (spin * spin))); + kerrschild_vector_spacetime[2] = -((rad_dist * (y - pos_y)) - (spin * mass * (x - pos_x))) / + ((rad_dist * rad_dist) + ((mass * mass) * (spin * spin))); + kerrschild_vector_spacetime[3] = -(z - pos_z) / rad_dist; return kerrschild_vector_spacetime; } -double* -blackhole_kerrschildscalar_der(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z, - const double dx, const double dy, const double dz) +double *blackhole_kerrschildscalar_der( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z, + const double dx, const double dy, const double dz +) { double kerrschild_scalar_x_forward = blackhole_kerrschildscalar(spacetime, x + (0.5 * dx), y, z); double kerrschild_scalar_y_forward = blackhole_kerrschildscalar(spacetime, x, y + (0.5 * dy), z); @@ -91,34 +121,44 @@ blackhole_kerrschildscalar_der(const struct gkyl_gr_spacetime* spacetime, const double kerrschild_scalar_z_backward = blackhole_kerrschildscalar(spacetime, x, y, z - (0.5 * dz)); double *kerrschild_scalar_der = gkyl_malloc(sizeof(double[3])); - kerrschild_scalar_der[0] = (1.0 / dx) * (kerrschild_scalar_x_forward - kerrschild_scalar_x_backward); - kerrschild_scalar_der[1] = (1.0 / dy) * (kerrschild_scalar_y_forward - kerrschild_scalar_y_backward); - kerrschild_scalar_der[2] = (1.0 / dz) * (kerrschild_scalar_z_forward - kerrschild_scalar_z_backward); + kerrschild_scalar_der[0] = + (1.0 / dx) * (kerrschild_scalar_x_forward - kerrschild_scalar_x_backward); + kerrschild_scalar_der[1] = + (1.0 / dy) * (kerrschild_scalar_y_forward - kerrschild_scalar_y_backward); + kerrschild_scalar_der[2] = + (1.0 / dz) * (kerrschild_scalar_z_forward - kerrschild_scalar_z_backward); return kerrschild_scalar_der; } -double** -blackhole_kerrschildvector_der(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z, - const double dx, const double dy, const double dz) +double **blackhole_kerrschildvector_der( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z, + const double dx, const double dy, const double dz +) { double *kerrschild_vector_x_forward = blackhole_kerrschildvector(spacetime, x + (0.5 * dx), y, z); double *kerrschild_vector_y_forward = blackhole_kerrschildvector(spacetime, x, y + (0.5 * dy), z); double *kerrschild_vector_z_forward = blackhole_kerrschildvector(spacetime, x, y, z + (0.5 * dz)); - double *kerrschild_vector_x_backward = blackhole_kerrschildvector(spacetime, x - (0.5 * dx), y, z); - double *kerrschild_vector_y_backward = blackhole_kerrschildvector(spacetime, x, y - (0.5 * dy), z); - double *kerrschild_vector_z_backward = blackhole_kerrschildvector(spacetime, x, y, z - (0.5 * dz)); + double *kerrschild_vector_x_backward = + blackhole_kerrschildvector(spacetime, x - (0.5 * dx), y, z); + double *kerrschild_vector_y_backward = + blackhole_kerrschildvector(spacetime, x, y - (0.5 * dy), z); + double *kerrschild_vector_z_backward = + blackhole_kerrschildvector(spacetime, x, y, z - (0.5 * dz)); - double **kerrschild_vector_der = gkyl_malloc(sizeof(double*[3])); + double **kerrschild_vector_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { kerrschild_vector_der[i] = gkyl_malloc(sizeof(double[3])); } for (int i = 0; i < 3; i++) { - kerrschild_vector_der[0][i] = (1.0 / dx) * (kerrschild_vector_x_forward[i] - kerrschild_vector_x_backward[i]); - kerrschild_vector_der[1][i] = (1.0 / dy) * (kerrschild_vector_y_forward[i] - kerrschild_vector_y_backward[i]); - kerrschild_vector_der[2][i] = (1.0 / dz) * (kerrschild_vector_z_forward[i] - kerrschild_vector_z_backward[i]); + kerrschild_vector_der[0][i] = + (1.0 / dx) * (kerrschild_vector_x_forward[i] - kerrschild_vector_x_backward[i]); + kerrschild_vector_der[1][i] = + (1.0 / dy) * (kerrschild_vector_y_forward[i] - kerrschild_vector_y_backward[i]); + kerrschild_vector_der[2][i] = + (1.0 / dz) * (kerrschild_vector_z_forward[i] - kerrschild_vector_z_backward[i]); } gkyl_free(kerrschild_vector_x_forward); @@ -132,16 +172,16 @@ blackhole_kerrschildvector_der(const struct gkyl_gr_spacetime* spacetime, const return kerrschild_vector_der; } -static void -blackhole_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_metric_tensor) +static void blackhole_spatial_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_metric_tensor +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i == j) { (*spatial_metric_tensor)[i][j] = 1.0; - } - else { + } else { (*spatial_metric_tensor)[i][j] = 0.0; } } @@ -152,27 +192,28 @@ blackhole_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*spatial_metric_tensor)[i][j] = (*spatial_metric_tensor)[i][j] - (2.0 * kerrschild_scalar * kerrschild_vector[i] * kerrschild_vector[j]); + (*spatial_metric_tensor)[i][j] = + (*spatial_metric_tensor)[i][j] - + (2.0 * kerrschild_scalar * kerrschild_vector[i] * kerrschild_vector[j]); } } gkyl_free(kerrschild_vector); } -static void -blackhole_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_metric_tensor) +static void blackhole_spacetime_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_metric_tensor +) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (i == j) { if (i == 0) { (*spacetime_metric_tensor)[i][j] = -1.0; - } - else { + } else { (*spacetime_metric_tensor)[i][j] = 1.0; } - } - else { + } else { (*spacetime_metric_tensor)[i][j] = 0.0; } } @@ -183,33 +224,40 @@ blackhole_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spacetime, con for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*spacetime_metric_tensor)[i][j] = (*spacetime_metric_tensor)[i][j] - (2.0 * kerrschild_scalar * kerrschild_vector_spacetime[i] * kerrschild_vector_spacetime[j]); + (*spacetime_metric_tensor)[i][j] = + (*spacetime_metric_tensor)[i][j] - + (2.0 * kerrschild_scalar * kerrschild_vector_spacetime[i] * kerrschild_vector_spacetime[j]); } } gkyl_free(kerrschild_vector_spacetime); } -static void -blackhole_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_inv_metric_tensor) +static void blackhole_spatial_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_inv_metric_tensor +) { - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } blackhole_spatial_metric_tensor(spacetime, t, x, y, z, &spatial_metric); - double spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + double spatial_metric_det = + (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; } - double **spatial_metric_sq = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_sq = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_sq[i] = gkyl_malloc(sizeof(double[3])); } @@ -233,7 +281,7 @@ blackhole_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, c sq_trace += spatial_metric_sq[i][i]; } - double **euclidean_metric = gkyl_malloc(sizeof(double*[3])); + double **euclidean_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { euclidean_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -242,8 +290,7 @@ blackhole_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, c for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -251,8 +298,10 @@ blackhole_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, c for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*spatial_inv_metric_tensor)[i][j] = (1.0 / spatial_metric_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*spatial_inv_metric_tensor)[i][j] = + (1.0 / spatial_metric_det) * + ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } @@ -266,11 +315,12 @@ blackhole_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, c gkyl_free(euclidean_metric); } -static void -blackhole_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_inv_metric_tensor) +static void blackhole_spacetime_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_inv_metric_tensor +) { - double** inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -278,7 +328,7 @@ blackhole_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, blackhole_spatial_inv_metric_tensor(spacetime, t, x, y, z, &inv_spatial_metric); double lapse_function; - double* shift_vector = gkyl_malloc(sizeof(double[3])); + double *shift_vector = gkyl_malloc(sizeof(double[3])); blackhole_lapse_function(spacetime, t, x, y, z, &lapse_function); blackhole_shift_vector(spacetime, t, x, y, z, &shift_vector); @@ -294,7 +344,9 @@ blackhole_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, (*spacetime_inv_metric_tensor)[i + 1][0] = shift_vector[i] / (lapse_function * lapse_function); for (int j = 0; j < 3; j++) { - (*spacetime_inv_metric_tensor)[i + 1][j + 1] = inv_spatial_metric[i][j] - (shift_vector[i] * shift_vector[j]) / (lapse_function * lapse_function); + (*spacetime_inv_metric_tensor)[i + 1][j + 1] = + inv_spatial_metric[i][j] - + (shift_vector[i] * shift_vector[j]) / (lapse_function * lapse_function); } } @@ -305,162 +357,198 @@ blackhole_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, gkyl_free(shift_vector); } -static void -blackhole_spatial_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spatial_metric_det) +static void blackhole_spatial_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spatial_metric_det +) { - double** spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } blackhole_spatial_metric_tensor(spacetime, t, x, y, z, &spatial_metric); - *spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + *spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric[i]); } gkyl_free(spatial_metric); } -static void -blackhole_spacetime_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spacetime_metric_det) +static void blackhole_spacetime_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spacetime_metric_det +) { double spatial_metric_det; double lapse_function; blackhole_spatial_metric_det(spacetime, t, x, y, z, &spatial_metric_det); blackhole_lapse_function(spacetime, t, x, y, z, &lapse_function); - *spacetime_metric_det = - (lapse_function * lapse_function) * spatial_metric_det; + *spacetime_metric_det = -(lapse_function * lapse_function) * spatial_metric_det; } -static void -blackhole_spatial_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_metric_tensor_der) +static void blackhole_spatial_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ****spatial_metric_tensor_der +) { gkyl_gr_spatial_metric_tensor_diff(spacetime, t, x, y, z, dx, dy, dz, spatial_metric_tensor_der); } -static void -blackhole_spacetime_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_metric_tensor_der) +static void blackhole_spacetime_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_metric_tensor_der +) { - gkyl_gr_spacetime_metric_tensor_diff(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_metric_tensor_der); + gkyl_gr_spacetime_metric_tensor_diff( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_metric_tensor_der + ); } -static void -blackhole_lapse_function(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* lapse_function) +static void blackhole_lapse_function( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *lapse_function +) { double kerrschild_scalar = blackhole_kerrschildscalar(spacetime, x, y, z); *lapse_function = 1.0 / sqrt(1.0 - (2.0 * kerrschild_scalar)); } -static void -blackhole_shift_vector(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double** shift_vector) +static void blackhole_shift_vector( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double **shift_vector +) { double kerrschild_scalar = blackhole_kerrschildscalar(spacetime, x, y, z); double *kerrschild_vector = blackhole_kerrschildvector(spacetime, x, y, z); for (int i = 0; i < 3; i++) { - (*shift_vector)[i] = ((2.0 * kerrschild_scalar) / (1.0 - (2.0 * kerrschild_scalar))) * kerrschild_vector[i]; + (*shift_vector)[i] = + ((2.0 * kerrschild_scalar) / (1.0 - (2.0 * kerrschild_scalar))) * kerrschild_vector[i]; } gkyl_free(kerrschild_vector); } -static void -blackhole_lapse_function_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** lapse_function_der) +static void blackhole_lapse_function_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **lapse_function_der +) { gkyl_gr_lapse_function_diff(spacetime, t, x, y, z, dx, dy, dz, lapse_function_der); } -static void -blackhole_shift_vector_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** shift_vector_der) +static void blackhole_shift_vector_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***shift_vector_der +) { gkyl_gr_shift_vector_diff(spacetime, t, x, y, z, dx, dy, dz, shift_vector_der); } -static void -blackhole_spatial_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_christoffel) +static void blackhole_spatial_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ****spatial_christoffel +) { gkyl_gr_spatial_christoffel_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_christoffel); } -static void -blackhole_spacetime_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_christoffel) +static void blackhole_spacetime_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_christoffel +) { gkyl_gr_spacetime_christoffel_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_christoffel); } -static void -blackhole_spatial_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_riemann_tensor) +static void blackhole_spatial_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double *****spatial_riemann_tensor +) { gkyl_gr_spatial_riemann_tensor_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_riemann_tensor); } -static void -blackhole_spacetime_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_riemann_tensor) +static void blackhole_spacetime_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_riemann_tensor +) { - gkyl_gr_spacetime_riemann_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_riemann_tensor); + gkyl_gr_spacetime_riemann_tensor_fd( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_riemann_tensor + ); } -static void -blackhole_spatial_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** spatial_ricci_tensor) +static void blackhole_spatial_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***spatial_ricci_tensor +) { gkyl_gr_spatial_ricci_tensor_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_tensor); } -static void -blackhole_spacetime_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double*** spacetime_ricci_tensor) +static void blackhole_spacetime_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ***spacetime_ricci_tensor +) { gkyl_gr_spacetime_ricci_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_tensor); } -static void -blackhole_spatial_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double* spatial_ricci_scalar) +static void blackhole_spatial_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *spatial_ricci_scalar +) { gkyl_gr_spatial_ricci_scalar_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_scalar); } -static void -blackhole_spacetime_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double* spacetime_ricci_scalar) +static void blackhole_spacetime_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *spacetime_ricci_scalar +) { gkyl_gr_spacetime_ricci_scalar_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_scalar); } -static void -blackhole_spatial_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_weyl_tensor) +static void blackhole_spatial_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *****spatial_weyl_tensor +) { gkyl_gr_spatial_weyl_tensor_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_weyl_tensor); } -static void -blackhole_spacetime_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_weyl_tensor) +static void blackhole_spacetime_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_weyl_tensor +) { gkyl_gr_spacetime_weyl_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_weyl_tensor); } -static void -blackhole_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** extrinsic_curvature_tensor) +static void blackhole_extrinsic_curvature_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***extrinsic_curvature_tensor +) { double lapse_function; blackhole_lapse_function(spacetime, t, x, y, z, &lapse_function); @@ -473,17 +561,21 @@ blackhole_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime, for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*extrinsic_curvature_tensor)[i][j] = lapse_function * (- (kerrschild_vector[i] * kerrschild_scalar_der[j]) - - (kerrschild_vector[j] * kerrschild_scalar_der[i]) - (kerrschild_scalar * kerrschild_vector_der[j][i]) - - (kerrschild_scalar * kerrschild_vector_der[i][j])); + (*extrinsic_curvature_tensor)[i][j] = + lapse_function * (-(kerrschild_vector[i] * kerrschild_scalar_der[j]) - + (kerrschild_vector[j] * kerrschild_scalar_der[i]) - + (kerrschild_scalar * kerrschild_vector_der[j][i]) - + (kerrschild_scalar * kerrschild_vector_der[i][j])); for (int k = 0; k < 3; k++) { - (*extrinsic_curvature_tensor)[i][j] += lapse_function * 2.0 * (kerrschild_scalar * kerrschild_scalar) * - ((kerrschild_vector[i] * kerrschild_vector[k] * kerrschild_vector_der[k][j]) - + (kerrschild_vector[j] * kerrschild_vector[k] * kerrschild_vector_der[k][i])); - - (*extrinsic_curvature_tensor)[i][j] += lapse_function * 2.0 * kerrschild_scalar * kerrschild_vector[i] * - kerrschild_vector[j] * kerrschild_vector[k] * kerrschild_scalar_der[k]; + (*extrinsic_curvature_tensor)[i][j] += + lapse_function * 2.0 * (kerrschild_scalar * kerrschild_scalar) * + ((kerrschild_vector[i] * kerrschild_vector[k] * kerrschild_vector_der[k][j]) + + (kerrschild_vector[j] * kerrschild_vector[k] * kerrschild_vector_der[k][i])); + + (*extrinsic_curvature_tensor)[i][j] += lapse_function * 2.0 * kerrschild_scalar * + kerrschild_vector[i] * kerrschild_vector[j] * + kerrschild_vector[k] * kerrschild_scalar_der[k]; } } } @@ -496,9 +588,10 @@ blackhole_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime, gkyl_free(kerrschild_vector_der); } -static void -blackhole_conformal_factor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* conformal_factor) +static void blackhole_conformal_factor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *conformal_factor +) { double spatial_metric_det; blackhole_spatial_metric_det(spacetime, t, x, y, z, &spatial_metric_det); @@ -506,9 +599,10 @@ blackhole_conformal_factor(const struct gkyl_gr_spacetime* spacetime, const doub *conformal_factor = pow(spatial_metric_det, 1.0 / 12.0); } -static void -blackhole_bssn_conformal_factor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* bssn_conformal_factor) +static void blackhole_bssn_conformal_factor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *bssn_conformal_factor +) { double spatial_metric_det; blackhole_spatial_metric_det(spacetime, t, x, y, z, &spatial_metric_det); @@ -516,37 +610,44 @@ blackhole_bssn_conformal_factor(const struct gkyl_gr_spacetime* spacetime, const *bssn_conformal_factor = 1.0 / pow(spatial_metric_det, 1.0 / 6.0); } -static void -blackhole_conformal_factor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** conformal_factor_der) +static void blackhole_conformal_factor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **conformal_factor_der +) { gkyl_gr_conformal_factor_diff(spacetime, t, x, y, z, dx, dy, dz, conformal_factor_der); } -static void -blackhole_bssn_conformal_factor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** bssn_conformal_factor_der) +static void blackhole_bssn_conformal_factor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double **bssn_conformal_factor_der +) { gkyl_gr_bssn_conformal_factor_diff(spacetime, t, x, y, z, dx, dy, dz, bssn_conformal_factor_der); } -static void -blackhole_conformal_factor_der2(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** conformal_factor_der2) +static void blackhole_conformal_factor_der2( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***conformal_factor_der2 +) { gkyl_gr_conformal_factor_diff2(spacetime, t, x, y, z, dx, dy, dz, conformal_factor_der2); } -static void -blackhole_bssn_conformal_factor_der2(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** bssn_conformal_factor_der2) +static void blackhole_bssn_conformal_factor_der2( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***bssn_conformal_factor_der2 +) { gkyl_gr_bssn_conformal_factor_diff2(spacetime, t, x, y, z, dx, dy, dz, bssn_conformal_factor_der2); } -static void -blackhole_excision_region(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - bool* in_excision_region) +static void blackhole_excision_region( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, bool *in_excision_region +) { const struct gr_blackhole *blackhole = container_of(spacetime, struct gr_blackhole, spacetime); @@ -557,20 +658,19 @@ blackhole_excision_region(const struct gkyl_gr_spacetime* spacetime, const doubl double pos_y = blackhole->pos_y; double pos_z = blackhole->pos_z; - double r = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); + double r = + sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); if (r <= (mass * (1.0 + sqrt(1.0 - (spin * spin))))) { *in_excision_region = true; - } - else { + } else { *in_excision_region = false; } } -void -gkyl_gr_blackhole_free(const struct gkyl_ref_count* ref) +void gkyl_gr_blackhole_free(const struct gkyl_ref_count *ref) { - struct gkyl_gr_spacetime* base = container_of(ref, struct gkyl_gr_spacetime, ref_count); + struct gkyl_gr_spacetime *base = container_of(ref, struct gkyl_gr_spacetime, ref_count); if (gkyl_gr_spacetime_is_cu_dev(base)) { // Free inner on_dev object. @@ -582,22 +682,16 @@ gkyl_gr_blackhole_free(const struct gkyl_ref_count* ref) gkyl_free(gr_blackhole); } -struct gkyl_gr_spacetime* -gkyl_gr_blackhole_new(bool use_gpu, double mass, double spin, double pos_x, double pos_y, double pos_z) +struct gkyl_gr_spacetime *gkyl_gr_blackhole_new( + bool use_gpu, double mass, double spin, double pos_x, double pos_y, double pos_z +) { - return gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp) { - .use_gpu = use_gpu, - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - } + return gkyl_gr_blackhole_inew(&(struct gkyl_gr_blackhole_inp + ){.use_gpu = use_gpu, .mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z} ); } -struct gkyl_gr_spacetime* -gkyl_gr_blackhole_inew(const struct gkyl_gr_blackhole_inp* inp) +struct gkyl_gr_spacetime *gkyl_gr_blackhole_inew(const struct gkyl_gr_blackhole_inp *inp) { struct gr_blackhole *gr_blackhole = gkyl_malloc(sizeof(struct gr_blackhole)); @@ -657,7 +751,8 @@ gkyl_gr_blackhole_inew(const struct gkyl_gr_blackhole_inp* inp) gr_blackhole->spacetime.flags = 0; GKYL_CLEAR_CU_ALLOC(gr_blackhole->spacetime.flags); gr_blackhole->spacetime.ref_count = gkyl_ref_count_init(gkyl_gr_blackhole_free); - gr_blackhole->spacetime.on_dev = &gr_blackhole->spacetime; // On the CPU, the spacetime object points to itself. + gr_blackhole->spacetime.on_dev = + &gr_blackhole->spacetime; // On the CPU, the spacetime object points to itself. return &gr_blackhole->spacetime; } diff --git a/moments/zero/gr_blackhole_isotropic.c b/moments/zero/gr_blackhole_isotropic.c index 26f364de4f..572458841d 100644 --- a/moments/zero/gr_blackhole_isotropic.c +++ b/moments/zero/gr_blackhole_isotropic.c @@ -6,11 +6,13 @@ #include #include -static void -blackhole_isotropic_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_metric_tensor) +static void blackhole_isotropic_spatial_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_metric_tensor +) { - const struct gr_blackhole_isotropic *blackhole_isotropic = container_of(spacetime, struct gr_blackhole_isotropic, spacetime); + const struct gr_blackhole_isotropic *blackhole_isotropic = + container_of(spacetime, struct gr_blackhole_isotropic, spacetime); double mass = blackhole_isotropic->mass; double spin = blackhole_isotropic->spin; @@ -21,15 +23,18 @@ blackhole_isotropic_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacet double Mspin = mass * spin; - double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); + double rho = + sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); double sin_theta = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double cos_theta = (z - pos_z) / rho; - double r_BL = rho * (1.0 + ((mass + Mspin) / (2.0 * rho))) * (1.0 + ((mass - Mspin) / (2.0 * rho))); + double r_BL = + rho * (1.0 + ((mass + Mspin) / (2.0 * rho))) * (1.0 + ((mass - Mspin) / (2.0 * rho))); double sigma = (r_BL * r_BL) + ((Mspin * Mspin) * (cos_theta * cos_theta)); double delta = (r_BL * r_BL) - (2.0 * mass * r_BL) + (Mspin * Mspin); - double A_BL = (((r_BL * r_BL) + (Mspin * Mspin)) * ((r_BL * r_BL) + (Mspin + Mspin))) - ((Mspin * Mspin) * delta * (sin_theta * sin_theta)); + double A_BL = (((r_BL * r_BL) + (Mspin * Mspin)) * ((r_BL * r_BL) + (Mspin + Mspin))) - + ((Mspin * Mspin) * delta * (sin_theta * sin_theta)); double A_func = sqrt(sigma) / rho; double B_func = sqrt(A_BL) / (rho * sqrt(sigma)); @@ -39,23 +44,28 @@ blackhole_isotropic_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacet } } - (*spatial_metric_tensor)[0][0] = ((A_func * A_func) + (((B_func * B_func) - (A_func * A_func)) * ((y - pos_y) * (y - pos_y)))) / + (*spatial_metric_tensor)[0][0] = + ((A_func * A_func) + (((B_func * B_func) - (A_func * A_func)) * ((y - pos_y) * (y - pos_y)))) / (((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); - (*spatial_metric_tensor)[1][1] = ((A_func * A_func) + (((B_func * B_func) - (A_func * A_func)) * ((y - pos_y) * (y - pos_y)))) / + (*spatial_metric_tensor)[1][1] = + ((A_func * A_func) + (((B_func * B_func) - (A_func * A_func)) * ((y - pos_y) * (y - pos_y)))) / (((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); (*spatial_metric_tensor)[2][2] = (A_func * A_func); - (*spatial_metric_tensor)[0][1] = -(((B_func * B_func) - (A_func * A_func)) * ((x - pos_x) * (y - pos_y))) / + (*spatial_metric_tensor)[0][1] = + -(((B_func * B_func) - (A_func * A_func)) * ((x - pos_x) * (y - pos_y))) / (((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); - (*spatial_metric_tensor)[1][0] = -(((B_func * B_func) - (A_func * A_func)) * ((x - pos_x) * (y - pos_y))) / + (*spatial_metric_tensor)[1][0] = + -(((B_func * B_func) - (A_func * A_func)) * ((x - pos_x) * (y - pos_y))) / (((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); } -static void -blackhole_isotropic_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_metric_tensor) +static void blackhole_isotropic_spacetime_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_metric_tensor +) { - double** spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -63,7 +73,7 @@ blackhole_isotropic_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spac blackhole_isotropic_spatial_metric_tensor(spacetime, t, x, y, z, &spatial_metric); double lapse_function; - double* shift_vector = gkyl_malloc(sizeof(double[3])); + double *shift_vector = gkyl_malloc(sizeof(double[3])); blackhole_isotropic_lapse_function(spacetime, t, x, y, z, &lapse_function); blackhole_isotropic_shift_vector(spacetime, t, x, y, z, &shift_vector); @@ -71,7 +81,6 @@ blackhole_isotropic_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spac for (int i = 0; i < 3; i++) { cov_shift_vector[0] = 0.0; - for (int j = 0; j < 3; j++) { cov_shift_vector[i] += spatial_metric[i][j] * shift_vector[j]; } @@ -96,26 +105,31 @@ blackhole_isotropic_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spac gkyl_free(shift_vector); } -static void -blackhole_isotropic_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_inv_metric_tensor) +static void blackhole_isotropic_spatial_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_inv_metric_tensor +) { - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } blackhole_isotropic_spatial_metric_tensor(spacetime, t, x, y, z, &spatial_metric); - double spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + double spatial_metric_det = + (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; } - double **spatial_metric_sq = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_sq = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_sq[i] = gkyl_malloc(sizeof(double[3])); } @@ -139,7 +153,7 @@ blackhole_isotropic_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* sp sq_trace += spatial_metric_sq[i][i]; } - double **euclidean_metric = gkyl_malloc(sizeof(double*[3])); + double **euclidean_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { euclidean_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -148,8 +162,7 @@ blackhole_isotropic_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* sp for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -157,8 +170,10 @@ blackhole_isotropic_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* sp for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*spatial_inv_metric_tensor)[i][j] = (1.0 / spatial_metric_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*spatial_inv_metric_tensor)[i][j] = + (1.0 / spatial_metric_det) * + ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } @@ -172,11 +187,12 @@ blackhole_isotropic_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* sp gkyl_free(euclidean_metric); } -static void -blackhole_isotropic_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_inv_metric_tensor) +static void blackhole_isotropic_spacetime_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_inv_metric_tensor +) { - double** inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -184,7 +200,7 @@ blackhole_isotropic_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* blackhole_isotropic_spatial_inv_metric_tensor(spacetime, t, x, y, z, &inv_spatial_metric); double lapse_function; - double* shift_vector = gkyl_malloc(sizeof(double[3])); + double *shift_vector = gkyl_malloc(sizeof(double[3])); blackhole_isotropic_lapse_function(spacetime, t, x, y, z, &lapse_function); blackhole_isotropic_shift_vector(spacetime, t, x, y, z, &shift_vector); @@ -200,7 +216,9 @@ blackhole_isotropic_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* (*spacetime_inv_metric_tensor)[i + 1][0] = shift_vector[i] / (lapse_function * lapse_function); for (int j = 0; j < 3; j++) { - (*spacetime_inv_metric_tensor)[i + 1][j + 1] = inv_spatial_metric[i][j] - (shift_vector[i] * shift_vector[j]) / (lapse_function * lapse_function); + (*spacetime_inv_metric_tensor)[i + 1][j + 1] = + inv_spatial_metric[i][j] - + (shift_vector[i] * shift_vector[j]) / (lapse_function * lapse_function); } } @@ -211,58 +229,71 @@ blackhole_isotropic_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* gkyl_free(shift_vector); } -static void -blackhole_isotropic_spatial_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spatial_metric_det) +static void blackhole_isotropic_spatial_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spatial_metric_det +) { - double** spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } blackhole_isotropic_spatial_metric_tensor(spacetime, t, x, y, z, &spatial_metric); - *spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + *spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric[i]); } gkyl_free(spatial_metric); } -static void -blackhole_isotropic_spacetime_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spacetime_metric_det) +static void blackhole_isotropic_spacetime_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spacetime_metric_det +) { double spatial_metric_det; double lapse_function; blackhole_isotropic_spatial_metric_det(spacetime, t, x, y, z, &spatial_metric_det); blackhole_isotropic_lapse_function(spacetime, t, x, y, z, &lapse_function); - *spacetime_metric_det = - (lapse_function * lapse_function) * spatial_metric_det; + *spacetime_metric_det = -(lapse_function * lapse_function) * spatial_metric_det; } -static void -blackhole_isotropic_spatial_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_metric_tensor_der) +static void blackhole_isotropic_spatial_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ****spatial_metric_tensor_der +) { gkyl_gr_spatial_metric_tensor_diff(spacetime, t, x, y, z, dx, dy, dz, spatial_metric_tensor_der); } -static void -blackhole_isotropic_spacetime_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_metric_tensor_der) +static void blackhole_isotropic_spacetime_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_metric_tensor_der +) { - gkyl_gr_spacetime_metric_tensor_diff(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_metric_tensor_der); + gkyl_gr_spacetime_metric_tensor_diff( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_metric_tensor_der + ); } -static void -blackhole_isotropic_lapse_function(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* lapse_function) +static void blackhole_isotropic_lapse_function( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *lapse_function +) { - const struct gr_blackhole_isotropic *blackhole_isotropic = container_of(spacetime, struct gr_blackhole_isotropic, spacetime); + const struct gr_blackhole_isotropic *blackhole_isotropic = + container_of(spacetime, struct gr_blackhole_isotropic, spacetime); double mass = blackhole_isotropic->mass; double spin = blackhole_isotropic->spin; @@ -273,24 +304,29 @@ blackhole_isotropic_lapse_function(const struct gkyl_gr_spacetime* spacetime, co double Mspin = mass * spin; - double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); + double rho = + sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); double sin_theta = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double cos_theta = (z - pos_z) / rho; - double r_BL = rho * (1.0 + ((mass + Mspin) / (2.0 * rho))) * (1.0 + ((mass - Mspin) / (2.0 * rho))); + double r_BL = + rho * (1.0 + ((mass + Mspin) / (2.0 * rho))) * (1.0 + ((mass - Mspin) / (2.0 * rho))); double sigma = (r_BL * r_BL) + ((Mspin * Mspin) * (cos_theta * cos_theta)); double delta = (r_BL * r_BL) - (2.0 * mass * r_BL) + (Mspin * Mspin); - double A_BL = (((r_BL * r_BL) + (Mspin * Mspin)) * ((r_BL * r_BL) + (Mspin + Mspin))) - ((Mspin * Mspin) * delta * (sin_theta * sin_theta)); + double A_BL = (((r_BL * r_BL) + (Mspin * Mspin)) * ((r_BL * r_BL) + (Mspin + Mspin))) - + ((Mspin * Mspin) * delta * (sin_theta * sin_theta)); *lapse_function = sqrt((sigma * delta) / A_BL); } -static void -blackhole_isotropic_shift_vector(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double** shift_vector) +static void blackhole_isotropic_shift_vector( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double **shift_vector +) { - const struct gr_blackhole_isotropic *blackhole_isotropic = container_of(spacetime, struct gr_blackhole_isotropic, spacetime); + const struct gr_blackhole_isotropic *blackhole_isotropic = + container_of(spacetime, struct gr_blackhole_isotropic, spacetime); double mass = blackhole_isotropic->mass; double spin = blackhole_isotropic->spin; @@ -301,14 +337,17 @@ blackhole_isotropic_shift_vector(const struct gkyl_gr_spacetime* spacetime, cons double Mspin = mass * spin; - double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); + double rho = + sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); double sin_theta = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double cos_theta = (z - pos_z) / rho; - double r_BL = rho * (1.0 + ((mass + Mspin) / (2.0 * rho))) * (1.0 + ((mass - Mspin) / (2.0 * rho))); + double r_BL = + rho * (1.0 + ((mass + Mspin) / (2.0 * rho))) * (1.0 + ((mass - Mspin) / (2.0 * rho))); double delta = (r_BL * r_BL) - (2.0 * mass * r_BL) + (Mspin * Mspin); - double A_BL = (((r_BL * r_BL) + (Mspin * Mspin)) * ((r_BL * r_BL) + (Mspin + Mspin))) - ((Mspin * Mspin) * delta * (sin_theta * sin_theta)); + double A_BL = (((r_BL * r_BL) + (Mspin * Mspin)) * ((r_BL * r_BL) + (Mspin + Mspin))) - + ((Mspin * Mspin) * delta * (sin_theta * sin_theta)); double omega = (2.0 * mass * Mspin * r_BL) / (A_BL); (*shift_vector)[0] = omega * (y - pos_y); @@ -316,103 +355,125 @@ blackhole_isotropic_shift_vector(const struct gkyl_gr_spacetime* spacetime, cons (*shift_vector)[2] = 0.0; } -static void -blackhole_isotropic_lapse_function_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** lapse_function_der) +static void blackhole_isotropic_lapse_function_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **lapse_function_der +) { gkyl_gr_lapse_function_diff(spacetime, t, x, y, z, dx, dy, dz, lapse_function_der); } -static void -blackhole_isotropic_shift_vector_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** shift_vector_der) +static void blackhole_isotropic_shift_vector_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***shift_vector_der +) { gkyl_gr_shift_vector_diff(spacetime, t, x, y, z, dx, dy, dz, shift_vector_der); } -static void -blackhole_isotropic_spatial_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_christoffel) +static void blackhole_isotropic_spatial_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ****spatial_christoffel +) { gkyl_gr_spatial_christoffel_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_christoffel); } -static void -blackhole_isotropic_spacetime_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_christoffel) +static void blackhole_isotropic_spacetime_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_christoffel +) { gkyl_gr_spacetime_christoffel_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_christoffel); } -static void -blackhole_isotropic_spatial_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_riemann_tensor) +static void blackhole_isotropic_spatial_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double *****spatial_riemann_tensor +) { gkyl_gr_spatial_riemann_tensor_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_riemann_tensor); } -static void -blackhole_isotropic_spacetime_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_riemann_tensor) +static void blackhole_isotropic_spacetime_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_riemann_tensor +) { - gkyl_gr_spacetime_riemann_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_riemann_tensor); + gkyl_gr_spacetime_riemann_tensor_fd( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_riemann_tensor + ); } -static void -blackhole_isotropic_spatial_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** spatial_ricci_tensor) +static void blackhole_isotropic_spatial_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***spatial_ricci_tensor +) { gkyl_gr_spatial_ricci_tensor_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_tensor); } -static void -blackhole_isotropic_spacetime_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double*** spacetime_ricci_tensor) +static void blackhole_isotropic_spacetime_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ***spacetime_ricci_tensor +) { gkyl_gr_spacetime_ricci_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_tensor); } -static void -blackhole_isotropic_spatial_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double* spatial_ricci_scalar) +static void blackhole_isotropic_spatial_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *spatial_ricci_scalar +) { gkyl_gr_spatial_ricci_scalar_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_scalar); } -static void -blackhole_isotropic_spacetime_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double* spacetime_ricci_scalar) +static void blackhole_isotropic_spacetime_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *spacetime_ricci_scalar +) { gkyl_gr_spacetime_ricci_scalar_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_scalar); } -static void -blackhole_isotropic_spatial_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_weyl_tensor) +static void blackhole_isotropic_spatial_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *****spatial_weyl_tensor +) { gkyl_gr_spatial_weyl_tensor_fd(spacetime, t, x, y, z, dx, dy, dx, spatial_weyl_tensor); } -static void -blackhole_isotropic_spacetime_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_weyl_tensor) +static void blackhole_isotropic_spacetime_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_weyl_tensor +) { gkyl_gr_spacetime_weyl_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_weyl_tensor); } -static void -blackhole_isotropic_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** extrinsic_curvature_tensor) +static void blackhole_isotropic_extrinsic_curvature_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***extrinsic_curvature_tensor +) { double lapse_function; double *shift_vector = gkyl_malloc(sizeof(double[3])); - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **shift_vector_der = gkyl_malloc(sizeof(double*[3])); - double **shift_vector_cov_der = gkyl_malloc(sizeof(double*[3])); - double **shift_covector_cov_der = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **shift_vector_der = gkyl_malloc(sizeof(double *[3])); + double **shift_vector_cov_der = gkyl_malloc(sizeof(double *[3])); + double **shift_covector_cov_der = gkyl_malloc(sizeof(double *[3])); - double ***spatial_christoffel = gkyl_malloc(sizeof(double**[3])); + double ***spatial_christoffel = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); @@ -420,7 +481,7 @@ blackhole_isotropic_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* s shift_vector_cov_der[i] = gkyl_malloc(sizeof(double[3])); shift_covector_cov_der[i] = gkyl_malloc(sizeof(double[3])); - spatial_christoffel[i] = gkyl_malloc(sizeof(double*[3])); + spatial_christoffel[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_christoffel[i][j] = gkyl_malloc(sizeof(double[3])); @@ -454,7 +515,9 @@ blackhole_isotropic_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* s for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*extrinsic_curvature_tensor)[i][j] = -(1.0 / (2.0 * lapse_function)) * (shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]); + (*extrinsic_curvature_tensor)[i][j] = + -(1.0 / (2.0 * lapse_function)) * + (shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]); } } @@ -477,11 +540,13 @@ blackhole_isotropic_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* s gkyl_free(spatial_christoffel); } -static void -blackhole_isotropic_excision_region(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - bool* in_excision_region) +static void blackhole_isotropic_excision_region( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, bool *in_excision_region +) { - const struct gr_blackhole_isotropic *blackhole_isotropic = container_of(spacetime, struct gr_blackhole_isotropic, spacetime); + const struct gr_blackhole_isotropic *blackhole_isotropic = + container_of(spacetime, struct gr_blackhole_isotropic, spacetime); double mass = blackhole_isotropic->mass; @@ -489,49 +554,46 @@ blackhole_isotropic_excision_region(const struct gkyl_gr_spacetime* spacetime, c double pos_y = blackhole_isotropic->pos_y; double pos_z = blackhole_isotropic->pos_z; - double eta = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); + double eta = + sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); if (eta <= mass * 2.0) { *in_excision_region = true; - } - else { + } else { *in_excision_region = false; } } -void -gkyl_gr_blackhole_isotropic_free(const struct gkyl_ref_count* ref) +void gkyl_gr_blackhole_isotropic_free(const struct gkyl_ref_count *ref) { - struct gkyl_gr_spacetime* base = container_of(ref, struct gkyl_gr_spacetime, ref_count); + struct gkyl_gr_spacetime *base = container_of(ref, struct gkyl_gr_spacetime, ref_count); if (gkyl_gr_spacetime_is_cu_dev(base)) { // Free inner on_dev object. - struct gr_blackhole_isotropic *gr_blackhole_isotropic = container_of(base->on_dev, struct gr_blackhole_isotropic, spacetime); + struct gr_blackhole_isotropic *gr_blackhole_isotropic = + container_of(base->on_dev, struct gr_blackhole_isotropic, spacetime); gkyl_cu_free(gr_blackhole_isotropic); } - struct gr_blackhole_isotropic *gr_blackhole_isotropic = container_of(base, struct gr_blackhole_isotropic, spacetime); + struct gr_blackhole_isotropic *gr_blackhole_isotropic = + container_of(base, struct gr_blackhole_isotropic, spacetime); gkyl_free(gr_blackhole_isotropic); } -struct gkyl_gr_spacetime* -gkyl_gr_blackhole_isotropic_new(bool use_gpu, double mass, double spin, double pos_x, double pos_y, double pos_z) +struct gkyl_gr_spacetime *gkyl_gr_blackhole_isotropic_new( + bool use_gpu, double mass, double spin, double pos_x, double pos_y, double pos_z +) { - return gkyl_gr_blackhole_isotropic_inew(&(struct gkyl_gr_blackhole_isotropic_inp) { - .use_gpu = use_gpu, - .mass = mass, - .spin = spin, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - } + return gkyl_gr_blackhole_isotropic_inew(&(struct gkyl_gr_blackhole_isotropic_inp + ){.use_gpu = use_gpu, .mass = mass, .spin = spin, .pos_x = pos_x, .pos_y = pos_y, .pos_z = pos_z} ); } -struct gkyl_gr_spacetime* -gkyl_gr_blackhole_isotropic_inew(const struct gkyl_gr_blackhole_isotropic_inp* inp) +struct gkyl_gr_spacetime * +gkyl_gr_blackhole_isotropic_inew(const struct gkyl_gr_blackhole_isotropic_inp *inp) { - struct gr_blackhole_isotropic *gr_blackhole_isotropic = gkyl_malloc(sizeof(struct gr_blackhole_isotropic)); + struct gr_blackhole_isotropic *gr_blackhole_isotropic = + gkyl_malloc(sizeof(struct gr_blackhole_isotropic)); gr_blackhole_isotropic->mass = inp->mass; gr_blackhole_isotropic->spin = inp->spin; @@ -540,47 +602,69 @@ gkyl_gr_blackhole_isotropic_inew(const struct gkyl_gr_blackhole_isotropic_inp* i gr_blackhole_isotropic->pos_y = inp->pos_y; gr_blackhole_isotropic->pos_z = inp->pos_z; - gr_blackhole_isotropic->spacetime.spatial_metric_tensor_func = blackhole_isotropic_spatial_metric_tensor; - gr_blackhole_isotropic->spacetime.spacetime_metric_tensor_func = blackhole_isotropic_spacetime_metric_tensor; + gr_blackhole_isotropic->spacetime.spatial_metric_tensor_func = + blackhole_isotropic_spatial_metric_tensor; + gr_blackhole_isotropic->spacetime.spacetime_metric_tensor_func = + blackhole_isotropic_spacetime_metric_tensor; - gr_blackhole_isotropic->spacetime.spatial_inv_metric_tensor_func = blackhole_isotropic_spatial_inv_metric_tensor; - gr_blackhole_isotropic->spacetime.spacetime_inv_metric_tensor_func = blackhole_isotropic_spacetime_inv_metric_tensor; + gr_blackhole_isotropic->spacetime.spatial_inv_metric_tensor_func = + blackhole_isotropic_spatial_inv_metric_tensor; + gr_blackhole_isotropic->spacetime.spacetime_inv_metric_tensor_func = + blackhole_isotropic_spacetime_inv_metric_tensor; - gr_blackhole_isotropic->spacetime.spatial_metric_det_func = blackhole_isotropic_spatial_metric_det; - gr_blackhole_isotropic->spacetime.spacetime_metric_det_func = blackhole_isotropic_spacetime_metric_det; + gr_blackhole_isotropic->spacetime.spatial_metric_det_func = + blackhole_isotropic_spatial_metric_det; + gr_blackhole_isotropic->spacetime.spacetime_metric_det_func = + blackhole_isotropic_spacetime_metric_det; - gr_blackhole_isotropic->spacetime.spatial_metric_tensor_der_func = blackhole_isotropic_spatial_metric_tensor_der; - gr_blackhole_isotropic->spacetime.spacetime_metric_tensor_der_func = blackhole_isotropic_spacetime_metric_tensor_der; + gr_blackhole_isotropic->spacetime.spatial_metric_tensor_der_func = + blackhole_isotropic_spatial_metric_tensor_der; + gr_blackhole_isotropic->spacetime.spacetime_metric_tensor_der_func = + blackhole_isotropic_spacetime_metric_tensor_der; gr_blackhole_isotropic->spacetime.lapse_function_func = blackhole_isotropic_lapse_function; gr_blackhole_isotropic->spacetime.shift_vector_func = blackhole_isotropic_shift_vector; - gr_blackhole_isotropic->spacetime.lapse_function_der_func = blackhole_isotropic_lapse_function_der; + gr_blackhole_isotropic->spacetime.lapse_function_der_func = + blackhole_isotropic_lapse_function_der; gr_blackhole_isotropic->spacetime.shift_vector_der_func = blackhole_isotropic_shift_vector_der; - gr_blackhole_isotropic->spacetime.spatial_christoffel_func = blackhole_isotropic_spatial_christoffel; - gr_blackhole_isotropic->spacetime.spacetime_christoffel_func = blackhole_isotropic_spacetime_christoffel; + gr_blackhole_isotropic->spacetime.spatial_christoffel_func = + blackhole_isotropic_spatial_christoffel; + gr_blackhole_isotropic->spacetime.spacetime_christoffel_func = + blackhole_isotropic_spacetime_christoffel; - gr_blackhole_isotropic->spacetime.spatial_riemann_tensor_func = blackhole_isotropic_spatial_riemann_tensor; - gr_blackhole_isotropic->spacetime.spacetime_riemann_tensor_func = blackhole_isotropic_spacetime_riemann_tensor; + gr_blackhole_isotropic->spacetime.spatial_riemann_tensor_func = + blackhole_isotropic_spatial_riemann_tensor; + gr_blackhole_isotropic->spacetime.spacetime_riemann_tensor_func = + blackhole_isotropic_spacetime_riemann_tensor; - gr_blackhole_isotropic->spacetime.spatial_ricci_tensor_func = blackhole_isotropic_spatial_ricci_tensor; - gr_blackhole_isotropic->spacetime.spacetime_ricci_tensor_func = blackhole_isotropic_spacetime_ricci_tensor; + gr_blackhole_isotropic->spacetime.spatial_ricci_tensor_func = + blackhole_isotropic_spatial_ricci_tensor; + gr_blackhole_isotropic->spacetime.spacetime_ricci_tensor_func = + blackhole_isotropic_spacetime_ricci_tensor; - gr_blackhole_isotropic->spacetime.spatial_ricci_scalar_func = blackhole_isotropic_spatial_ricci_scalar; - gr_blackhole_isotropic->spacetime.spacetime_ricci_scalar_func = blackhole_isotropic_spacetime_ricci_scalar; + gr_blackhole_isotropic->spacetime.spatial_ricci_scalar_func = + blackhole_isotropic_spatial_ricci_scalar; + gr_blackhole_isotropic->spacetime.spacetime_ricci_scalar_func = + blackhole_isotropic_spacetime_ricci_scalar; - gr_blackhole_isotropic->spacetime.spatial_weyl_tensor_func = blackhole_isotropic_spatial_weyl_tensor; - gr_blackhole_isotropic->spacetime.spacetime_weyl_tensor_func = blackhole_isotropic_spacetime_weyl_tensor; + gr_blackhole_isotropic->spacetime.spatial_weyl_tensor_func = + blackhole_isotropic_spatial_weyl_tensor; + gr_blackhole_isotropic->spacetime.spacetime_weyl_tensor_func = + blackhole_isotropic_spacetime_weyl_tensor; - gr_blackhole_isotropic->spacetime.extrinsic_curvature_tensor_func = blackhole_isotropic_extrinsic_curvature_tensor; + gr_blackhole_isotropic->spacetime.extrinsic_curvature_tensor_func = + blackhole_isotropic_extrinsic_curvature_tensor; gr_blackhole_isotropic->spacetime.excision_region_func = blackhole_isotropic_excision_region; gr_blackhole_isotropic->spacetime.flags = 0; GKYL_CLEAR_CU_ALLOC(gr_blackhole_isotropic->spacetime.flags); - gr_blackhole_isotropic->spacetime.ref_count = gkyl_ref_count_init(gkyl_gr_blackhole_isotropic_free); - gr_blackhole_isotropic->spacetime.on_dev = &gr_blackhole_isotropic->spacetime; // On the CPU, the spacetime object points to itself. + gr_blackhole_isotropic->spacetime.ref_count = + gkyl_ref_count_init(gkyl_gr_blackhole_isotropic_free); + gr_blackhole_isotropic->spacetime.on_dev = + &gr_blackhole_isotropic->spacetime; // On the CPU, the spacetime object points to itself. return &gr_blackhole_isotropic->spacetime; } \ No newline at end of file diff --git a/moments/zero/gr_brill_lindquist.c b/moments/zero/gr_brill_lindquist.c index 4c20277f2e..d2200a7199 100644 --- a/moments/zero/gr_brill_lindquist.c +++ b/moments/zero/gr_brill_lindquist.c @@ -6,10 +6,12 @@ #include #include -double -brill_lindquist_phi(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double brill_lindquist_phi( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_brill_lindquist *brill_lindquist = container_of(spacetime, struct gr_brill_lindquist, spacetime); + const struct gr_brill_lindquist *brill_lindquist = + container_of(spacetime, struct gr_brill_lindquist, spacetime); double mass1 = brill_lindquist->mass1; double mass2 = brill_lindquist->mass2; @@ -22,22 +24,39 @@ brill_lindquist_phi(const struct gkyl_gr_spacetime* spacetime, const double x, c double pos_y2 = brill_lindquist->pos_y2; double pos_z2 = brill_lindquist->pos_z2; - double radial_12 = sqrt(((pos_x1 - pos_x2) * (pos_x1 - pos_x2)) + ((pos_y1 - pos_y2) * (pos_y1 - pos_y2)) + ((pos_z1 - pos_z2) * (pos_z1 - pos_z2))); - double radial_1 = sqrt(((x - pos_x1) * (x - pos_x1)) + ((y - pos_y1) * (y - pos_y1)) + ((z - pos_z1) * (z - pos_z1))); - double radial_2 = sqrt(((x - pos_x2) * (x - pos_x2)) + ((y - pos_y2) * (y - pos_y2)) + ((z - pos_z2) * (z - pos_z2))); + double radial_12 = sqrt( + ((pos_x1 - pos_x2) * (pos_x1 - pos_x2)) + ((pos_y1 - pos_y2) * (pos_y1 - pos_y2)) + + ((pos_z1 - pos_z2) * (pos_z1 - pos_z2)) + ); + double radial_1 = sqrt( + ((x - pos_x1) * (x - pos_x1)) + ((y - pos_y1) * (y - pos_y1)) + ((z - pos_z1) * (z - pos_z1)) + ); + double radial_2 = sqrt( + ((x - pos_x2) * (x - pos_x2)) + ((y - pos_y2) * (y - pos_y2)) + ((z - pos_z2) * (z - pos_z2)) + ); + + double alpha1 = + -(0.25 * ((2.0 * radial_12) + mass2 - mass1)) + + ((0.25 * radial_12) * sqrt( + 4.0 + ((4.0 / radial_12) * (mass1 + mass2)) + + (((mass1 - mass2) / radial_12) * (mass1 - mass2) / radial_12) + )); + double alpha2 = + -(0.25 * ((2.0 * radial_12) + mass1 - mass2)) + + ((0.25 * radial_12) * sqrt( + 4.0 + ((4.0 / radial_12) * (mass1 + mass2)) + + (((mass1 - mass2) / radial_12) * (mass1 - mass2) / radial_12) + )); - double alpha1 = -(0.25 * ((2.0 * radial_12) + mass2 - mass1)) + - ((0.25 * radial_12) * sqrt(4.0 + ((4.0 / radial_12) * (mass1 + mass2)) + (((mass1 - mass2) / radial_12) * (mass1 - mass2) / radial_12))); - double alpha2 = -(0.25 * ((2.0 * radial_12) + mass1 - mass2)) + - ((0.25 * radial_12) * sqrt(4.0 + ((4.0 / radial_12) * (mass1 + mass2)) + (((mass1 - mass2) / radial_12) * (mass1 - mass2) / radial_12))); - return 8.0 * ((alpha1 / radial_1) + (alpha2 / radial_2)); } -double -brill_lindquist_psi(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double brill_lindquist_psi( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_brill_lindquist *brill_lindquist = container_of(spacetime, struct gr_brill_lindquist, spacetime); + const struct gr_brill_lindquist *brill_lindquist = + container_of(spacetime, struct gr_brill_lindquist, spacetime); double mass1 = brill_lindquist->mass1; double mass2 = brill_lindquist->mass2; @@ -50,42 +69,59 @@ brill_lindquist_psi(const struct gkyl_gr_spacetime* spacetime, const double x, c double pos_y2 = brill_lindquist->pos_y2; double pos_z2 = brill_lindquist->pos_z2; - double radial_12 = sqrt(((pos_x1 - pos_x2) * (pos_x1 - pos_x2)) + ((pos_y1 - pos_y2) * (pos_y1 - pos_y2)) + ((pos_z1 - pos_z2) * (pos_z1 - pos_z2))); - double radial_1 = sqrt(((x - pos_x1) * (x - pos_x1)) + ((y - pos_y1) * (y - pos_y1)) + ((z - pos_z1) * (z - pos_z1))); - double radial_2 = sqrt(((x - pos_x2) * (x - pos_x2)) + ((y - pos_y2) * (y - pos_y2)) + ((z - pos_z2) * (z - pos_z2))); + double radial_12 = sqrt( + ((pos_x1 - pos_x2) * (pos_x1 - pos_x2)) + ((pos_y1 - pos_y2) * (pos_y1 - pos_y2)) + + ((pos_z1 - pos_z2) * (pos_z1 - pos_z2)) + ); + double radial_1 = sqrt( + ((x - pos_x1) * (x - pos_x1)) + ((y - pos_y1) * (y - pos_y1)) + ((z - pos_z1) * (z - pos_z1)) + ); + double radial_2 = sqrt( + ((x - pos_x2) * (x - pos_x2)) + ((y - pos_y2) * (y - pos_y2)) + ((z - pos_z2) * (z - pos_z2)) + ); - double alpha1 = -(0.25 * ((2.0 * radial_12) + mass2 - mass1)) + - ((0.25 * radial_12) * sqrt(4.0 + ((4.0 / radial_12) * (mass1 + mass2)) + (((mass1 - mass2) / radial_12) * (mass1 - mass2) / radial_12))); - double alpha2 = -(0.25 * ((2.0 * radial_12) + mass1 - mass2)) + - ((0.25 * radial_12) * sqrt(4.0 + ((4.0 / radial_12) * (mass1 + mass2)) + (((mass1 - mass2) / radial_12) * (mass1 - mass2) / radial_12))); + double alpha1 = + -(0.25 * ((2.0 * radial_12) + mass2 - mass1)) + + ((0.25 * radial_12) * sqrt( + 4.0 + ((4.0 / radial_12) * (mass1 + mass2)) + + (((mass1 - mass2) / radial_12) * (mass1 - mass2) / radial_12) + )); + double alpha2 = + -(0.25 * ((2.0 * radial_12) + mass1 - mass2)) + + ((0.25 * radial_12) * sqrt( + 4.0 + ((4.0 / radial_12) * (mass1 + mass2)) + + (((mass1 - mass2) / radial_12) * (mass1 - mass2) / radial_12) + )); double beta1 = alpha1 * ((radial_12 + alpha1 - alpha2) / (radial_12 + alpha1 + alpha2)); double beta2 = alpha2 * ((radial_12 + alpha2 - alpha1) / (radial_12 + alpha1 + alpha2)); - + return 8.0 * ((beta1 / radial_1) + (beta2 / radial_2)); } -static void -brill_lindquist_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_metric_tensor) +static void brill_lindquist_spatial_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_metric_tensor +) { double phi = brill_lindquist_phi(spacetime, x, y, z); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i == j) { - (*spatial_metric_tensor)[i][j] = (1.0 + (0.125 * phi)) * (1.0 + (0.125 * phi)) * (1.0 + (0.125 * phi)) * (1.0 + (0.125 * phi)); - } - else { + (*spatial_metric_tensor)[i][j] = (1.0 + (0.125 * phi)) * (1.0 + (0.125 * phi)) * + (1.0 + (0.125 * phi)) * (1.0 + (0.125 * phi)); + } else { (*spatial_metric_tensor)[i][j] = 0.0; } } } } -static void -brill_lindquist_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_metric_tensor) +static void brill_lindquist_spacetime_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_metric_tensor +) { double phi = brill_lindquist_phi(spacetime, x, y, z); double psi = brill_lindquist_psi(spacetime, x, y, z); @@ -94,39 +130,44 @@ brill_lindquist_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spacetim for (int j = 0; j < 4; j++) { if (i == j) { if (i == 0) { - (*spacetime_metric_tensor)[i][j] = -((1.0 - (0.125 * psi)) / (1.0 + (0.5 * phi))) * ((1.0 - (0.125 * psi)) / (1.0 + (0.5 * phi))); + (*spacetime_metric_tensor)[i][j] = -((1.0 - (0.125 * psi)) / (1.0 + (0.5 * phi))) * + ((1.0 - (0.125 * psi)) / (1.0 + (0.5 * phi))); + } else { + (*spacetime_metric_tensor)[i][j] = (1.0 + (0.125 * phi)) * (1.0 + (0.125 * phi)) * + (1.0 + (0.125 * phi)) * (1.0 + (0.125 * phi)); } - else { - (*spacetime_metric_tensor)[i][j] = (1.0 + (0.125 * phi)) * (1.0 + (0.125 * phi)) * (1.0 + (0.125 * phi)) * (1.0 + (0.125 * phi)); - } - } - else { + } else { (*spacetime_metric_tensor)[i][j] = 0.0; } } } } -static void -brill_lindquist_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_inv_metric_tensor) +static void brill_lindquist_spatial_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_inv_metric_tensor +) { - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } brill_lindquist_spatial_metric_tensor(spacetime, t, x, y, z, &spatial_metric); - double spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + double spatial_metric_det = + (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; } - double **spatial_metric_sq = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_sq = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_sq[i] = gkyl_malloc(sizeof(double[3])); } @@ -150,7 +191,7 @@ brill_lindquist_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacet sq_trace += spatial_metric_sq[i][i]; } - double **euclidean_metric = gkyl_malloc(sizeof(double*[3])); + double **euclidean_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { euclidean_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -159,8 +200,7 @@ brill_lindquist_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacet for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -168,8 +208,10 @@ brill_lindquist_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacet for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*spatial_inv_metric_tensor)[i][j] = (1.0 / spatial_metric_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*spatial_inv_metric_tensor)[i][j] = + (1.0 / spatial_metric_det) * + ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } @@ -183,12 +225,13 @@ brill_lindquist_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacet gkyl_free(euclidean_metric); } -static void -brill_lindquist_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_inv_metric_tensor) +static void brill_lindquist_spacetime_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_inv_metric_tensor +) { - double** spatial_metric = gkyl_malloc(sizeof(double*[3])); - double** inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); @@ -198,7 +241,7 @@ brill_lindquist_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spac brill_lindquist_spatial_inv_metric_tensor(spacetime, t, x, y, z, &inv_spatial_metric); double lapse_function; - double* shift_vector = gkyl_malloc(sizeof(double[3])); + double *shift_vector = gkyl_malloc(sizeof(double[3])); brill_lindquist_lapse_function(spacetime, t, x, y, z, &lapse_function); brill_lindquist_shift_vector(spacetime, t, x, y, z, &shift_vector); @@ -214,7 +257,9 @@ brill_lindquist_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spac (*spacetime_inv_metric_tensor)[i + 1][0] = shift_vector[i] / (lapse_function * lapse_function); for (int j = 0; j < 3; j++) { - (*spacetime_inv_metric_tensor)[i + 1][j + 1] = inv_spatial_metric[i][j] - (shift_vector[i] * shift_vector[j]) / (lapse_function * lapse_function); + (*spacetime_inv_metric_tensor)[i + 1][j + 1] = + inv_spatial_metric[i][j] - + (shift_vector[i] * shift_vector[j]) / (lapse_function * lapse_function); } } @@ -227,56 +272,68 @@ brill_lindquist_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spac gkyl_free(shift_vector); } -static void -brill_lindquist_spatial_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spatial_metric_det) +static void brill_lindquist_spatial_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spatial_metric_det +) { - double** spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } brill_lindquist_spatial_metric_tensor(spacetime, t, x, y, z, &spatial_metric); - *spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + *spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric[i]); } gkyl_free(spatial_metric); } -static void -brill_lindquist_spacetime_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spacetime_metric_det) +static void brill_lindquist_spacetime_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spacetime_metric_det +) { double spatial_metric_det; double lapse_function; brill_lindquist_spatial_metric_det(spacetime, t, x, y, z, &spatial_metric_det); brill_lindquist_lapse_function(spacetime, t, x, y, z, &lapse_function); - *spacetime_metric_det = - (lapse_function * lapse_function) * spatial_metric_det; + *spacetime_metric_det = -(lapse_function * lapse_function) * spatial_metric_det; } -static void -brill_lindquist_spatial_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_metric_tensor_der) +static void brill_lindquist_spatial_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ****spatial_metric_tensor_der +) { gkyl_gr_spatial_metric_tensor_diff(spacetime, t, x, y, z, dx, dy, dz, spatial_metric_tensor_der); } -static void -brill_lindquist_spacetime_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_metric_tensor_der) +static void brill_lindquist_spacetime_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_metric_tensor_der +) { - gkyl_gr_spacetime_metric_tensor_diff(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_metric_tensor_der); + gkyl_gr_spacetime_metric_tensor_diff( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_metric_tensor_der + ); } -static void -brill_lindquist_lapse_function(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* lapse_function) +static void brill_lindquist_lapse_function( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *lapse_function +) { double phi = brill_lindquist_phi(spacetime, x, y, z); double psi = brill_lindquist_psi(spacetime, x, y, z); @@ -284,102 +341,125 @@ brill_lindquist_lapse_function(const struct gkyl_gr_spacetime* spacetime, const *lapse_function = (1.0 - (0.125 * psi)) / (1.0 + (0.5 * phi)); } -static void -brill_lindquist_shift_vector(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double** shift_vector) +static void brill_lindquist_shift_vector( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double **shift_vector +) { for (int i = 0; i < 3; i++) { (*shift_vector)[i] = 0.0; } } -static void -brill_lindquist_lapse_function_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** lapse_function_der) +static void brill_lindquist_lapse_function_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **lapse_function_der +) { gkyl_gr_lapse_function_diff(spacetime, t, x, y, z, dx, dy, dz, lapse_function_der); } -static void -brill_lindquist_shift_vector_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** shift_vector_der) +static void brill_lindquist_shift_vector_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***shift_vector_der +) { gkyl_gr_shift_vector_diff(spacetime, t, x, y, z, dx, dy, dz, shift_vector_der); } -static void -brill_lindquist_spatial_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_christoffel) +static void brill_lindquist_spatial_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ****spatial_christoffel +) { gkyl_gr_spatial_christoffel_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_christoffel); } -static void -brill_lindquist_spacetime_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_christoffel) +static void brill_lindquist_spacetime_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_christoffel +) { gkyl_gr_spacetime_christoffel_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_christoffel); } -static void -brill_lindquist_spatial_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_riemann_tensor) +static void brill_lindquist_spatial_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double *****spatial_riemann_tensor +) { gkyl_gr_spatial_riemann_tensor_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_riemann_tensor); } -static void -brill_lindquist_spacetime_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_riemann_tensor) +static void brill_lindquist_spacetime_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_riemann_tensor +) { - gkyl_gr_spacetime_riemann_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_riemann_tensor); + gkyl_gr_spacetime_riemann_tensor_fd( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_riemann_tensor + ); } -static void -brill_lindquist_spatial_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** spatial_ricci_tensor) +static void brill_lindquist_spatial_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***spatial_ricci_tensor +) { gkyl_gr_spatial_ricci_tensor_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_tensor); } -static void -brill_lindquist_spacetime_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double*** spacetime_ricci_tensor) +static void brill_lindquist_spacetime_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ***spacetime_ricci_tensor +) { gkyl_gr_spacetime_ricci_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_tensor); } -static void -brill_lindquist_spatial_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double* spatial_ricci_scalar) +static void brill_lindquist_spatial_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *spatial_ricci_scalar +) { gkyl_gr_spatial_ricci_scalar_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_scalar); } -static void -brill_lindquist_spacetime_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double* spacetime_ricci_scalar) +static void brill_lindquist_spacetime_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *spacetime_ricci_scalar +) { gkyl_gr_spacetime_ricci_scalar_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_scalar); } -static void -brill_lindquist_spatial_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_weyl_tensor) +static void brill_lindquist_spatial_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *****spatial_weyl_tensor +) { gkyl_gr_spatial_weyl_tensor_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_weyl_tensor); } -static void -brill_lindquist_spacetime_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_weyl_tensor) +static void brill_lindquist_spacetime_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_weyl_tensor +) { gkyl_gr_spacetime_weyl_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_weyl_tensor); } -static void -brill_lindquist_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** extrinsic_curvature_tensor) +static void brill_lindquist_extrinsic_curvature_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***extrinsic_curvature_tensor +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -388,9 +468,10 @@ brill_lindquist_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* space } } -static void -brill_lindquist_conformal_factor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* conformal_factor) +static void brill_lindquist_conformal_factor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *conformal_factor +) { double spatial_metric_det; brill_lindquist_spatial_metric_det(spacetime, t, x, y, z, &spatial_metric_det); @@ -398,9 +479,10 @@ brill_lindquist_conformal_factor(const struct gkyl_gr_spacetime* spacetime, cons *conformal_factor = pow(spatial_metric_det, 1.0 / 12.0); } -static void -brill_lindquist_bssn_conformal_factor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* bssn_conformal_factor) +static void brill_lindquist_bssn_conformal_factor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *bssn_conformal_factor +) { double spatial_metric_det; brill_lindquist_spatial_metric_det(spacetime, t, x, y, z, &spatial_metric_det); @@ -408,39 +490,47 @@ brill_lindquist_bssn_conformal_factor(const struct gkyl_gr_spacetime* spacetime, *bssn_conformal_factor = 1.0 / pow(spatial_metric_det, 1.0 / 6.0); } -static void -brill_lindquist_conformal_factor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** conformal_factor_der) +static void brill_lindquist_conformal_factor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **conformal_factor_der +) { gkyl_gr_conformal_factor_diff(spacetime, t, x, y, z, dx, dy, dz, conformal_factor_der); } -static void -brill_lindquist_bssn_conformal_factor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** bssn_conformal_factor_der) +static void brill_lindquist_bssn_conformal_factor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double **bssn_conformal_factor_der +) { gkyl_gr_bssn_conformal_factor_diff(spacetime, t, x, y, z, dx, dy, dz, bssn_conformal_factor_der); } -static void -brill_lindquist_conformal_factor_der2(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** conformal_factor_der2) +static void brill_lindquist_conformal_factor_der2( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***conformal_factor_der2 +) { gkyl_gr_conformal_factor_diff2(spacetime, t, x, y, z, dx, dy, dz, conformal_factor_der2); } -static void -brill_lindquist_bssn_conformal_factor_der2(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** bssn_conformal_factor_der2) +static void brill_lindquist_bssn_conformal_factor_der2( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***bssn_conformal_factor_der2 +) { gkyl_gr_bssn_conformal_factor_diff2(spacetime, t, x, y, z, dx, dy, dz, bssn_conformal_factor_der2); } -static void -brill_lindquist_excision_region(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - bool* in_excision_region) +static void brill_lindquist_excision_region( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, bool *in_excision_region +) { - const struct gr_brill_lindquist *brill_lindquist = container_of(spacetime, struct gr_brill_lindquist, spacetime); + const struct gr_brill_lindquist *brill_lindquist = + container_of(spacetime, struct gr_brill_lindquist, spacetime); double mass1 = brill_lindquist->mass1; double mass2 = brill_lindquist->mass2; @@ -453,51 +543,55 @@ brill_lindquist_excision_region(const struct gkyl_gr_spacetime* spacetime, const double pos_y2 = brill_lindquist->pos_y2; double pos_z2 = brill_lindquist->pos_z2; - double r1 = sqrt(((x - pos_x1) * (x - pos_x1)) + ((y - pos_y1) * (y - pos_y1)) + ((z - pos_z1) * (z - pos_z1))); - double r2 = sqrt(((x - pos_x2) * (x - pos_x2)) + ((y - pos_y2) * (y - pos_y2)) + ((z - pos_z2) * (z - pos_z2))); + double r1 = sqrt( + ((x - pos_x1) * (x - pos_x1)) + ((y - pos_y1) * (y - pos_y1)) + ((z - pos_z1) * (z - pos_z1)) + ); + double r2 = sqrt( + ((x - pos_x2) * (x - pos_x2)) + ((y - pos_y2) * (y - pos_y2)) + ((z - pos_z2) * (z - pos_z2)) + ); if (r1 <= 2.0 * mass1 || r2 <= 2.0 * mass2) { *in_excision_region = true; - } - else { + } else { *in_excision_region = false; } } -void -gkyl_gr_brill_lindquist_free(const struct gkyl_ref_count* ref) +void gkyl_gr_brill_lindquist_free(const struct gkyl_ref_count *ref) { - struct gkyl_gr_spacetime* base = container_of(ref, struct gkyl_gr_spacetime, ref_count); + struct gkyl_gr_spacetime *base = container_of(ref, struct gkyl_gr_spacetime, ref_count); if (gkyl_gr_spacetime_is_cu_dev(base)) { // Free inner on_dev object. - struct gr_brill_lindquist *gr_brill_lindquist = container_of(base->on_dev, struct gr_brill_lindquist, spacetime); + struct gr_brill_lindquist *gr_brill_lindquist = + container_of(base->on_dev, struct gr_brill_lindquist, spacetime); gkyl_cu_free(gr_brill_lindquist); } - struct gr_brill_lindquist *gr_brill_lindquist = container_of(base, struct gr_brill_lindquist, spacetime); + struct gr_brill_lindquist *gr_brill_lindquist = + container_of(base, struct gr_brill_lindquist, spacetime); gkyl_free(gr_brill_lindquist); } -struct gkyl_gr_spacetime* -gkyl_gr_brill_lindquist_new(bool use_gpu, double mass1, double mass2, double pos_x1, double pos_y1, double pos_z1, double pos_x2, double pos_y2, double pos_z2) +struct gkyl_gr_spacetime *gkyl_gr_brill_lindquist_new( + bool use_gpu, double mass1, double mass2, double pos_x1, double pos_y1, double pos_z1, + double pos_x2, double pos_y2, double pos_z2 +) { - return gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp) { - .use_gpu = use_gpu, - .mass1 = mass1, - .mass2 = mass2, - .pos_x1 = pos_x1, - .pos_y1 = pos_y1, - .pos_z1 = pos_z1, - .pos_x2 = pos_x2, - .pos_y2 = pos_y2, - .pos_z2 = pos_z2, - } - ); + return gkyl_gr_brill_lindquist_inew(&(struct gkyl_gr_brill_lindquist_inp + ){.use_gpu = use_gpu, + .mass1 = mass1, + .mass2 = mass2, + .pos_x1 = pos_x1, + .pos_y1 = pos_y1, + .pos_z1 = pos_z1, + .pos_x2 = pos_x2, + .pos_y2 = pos_y2, + .pos_z2 = pos_z2}); } -struct gkyl_gr_spacetime* -gkyl_gr_brill_lindquist_inew(const struct gkyl_gr_brill_lindquist_inp* inp) +struct gkyl_gr_spacetime *gkyl_gr_brill_lindquist_inew(const struct gkyl_gr_brill_lindquist_inp *inp +) { struct gr_brill_lindquist *gr_brill_lindquist = gkyl_malloc(sizeof(struct gr_brill_lindquist)); @@ -513,16 +607,21 @@ gkyl_gr_brill_lindquist_inew(const struct gkyl_gr_brill_lindquist_inp* inp) gr_brill_lindquist->pos_z2 = inp->pos_z2; gr_brill_lindquist->spacetime.spatial_metric_tensor_func = brill_lindquist_spatial_metric_tensor; - gr_brill_lindquist->spacetime.spacetime_metric_tensor_func = brill_lindquist_spacetime_metric_tensor; + gr_brill_lindquist->spacetime.spacetime_metric_tensor_func = + brill_lindquist_spacetime_metric_tensor; - gr_brill_lindquist->spacetime.spatial_inv_metric_tensor_func = brill_lindquist_spatial_inv_metric_tensor; - gr_brill_lindquist->spacetime.spacetime_inv_metric_tensor_func = brill_lindquist_spacetime_inv_metric_tensor; + gr_brill_lindquist->spacetime.spatial_inv_metric_tensor_func = + brill_lindquist_spatial_inv_metric_tensor; + gr_brill_lindquist->spacetime.spacetime_inv_metric_tensor_func = + brill_lindquist_spacetime_inv_metric_tensor; gr_brill_lindquist->spacetime.spatial_metric_det_func = brill_lindquist_spatial_metric_det; gr_brill_lindquist->spacetime.spacetime_metric_det_func = brill_lindquist_spacetime_metric_det; - gr_brill_lindquist->spacetime.spatial_metric_tensor_der_func = brill_lindquist_spatial_metric_tensor_der; - gr_brill_lindquist->spacetime.spacetime_metric_tensor_der_func = brill_lindquist_spacetime_metric_tensor_der; + gr_brill_lindquist->spacetime.spatial_metric_tensor_der_func = + brill_lindquist_spatial_metric_tensor_der; + gr_brill_lindquist->spacetime.spacetime_metric_tensor_der_func = + brill_lindquist_spacetime_metric_tensor_der; gr_brill_lindquist->spacetime.lapse_function_func = brill_lindquist_lapse_function; gr_brill_lindquist->spacetime.shift_vector_func = brill_lindquist_shift_vector; @@ -533,35 +632,43 @@ gkyl_gr_brill_lindquist_inew(const struct gkyl_gr_brill_lindquist_inp* inp) gr_brill_lindquist->spacetime.spatial_christoffel_func = brill_lindquist_spatial_christoffel; gr_brill_lindquist->spacetime.spacetime_christoffel_func = brill_lindquist_spacetime_christoffel; - gr_brill_lindquist->spacetime.spatial_riemann_tensor_func = brill_lindquist_spatial_riemann_tensor; - gr_brill_lindquist->spacetime.spacetime_riemann_tensor_func = brill_lindquist_spacetime_riemann_tensor; + gr_brill_lindquist->spacetime.spatial_riemann_tensor_func = + brill_lindquist_spatial_riemann_tensor; + gr_brill_lindquist->spacetime.spacetime_riemann_tensor_func = + brill_lindquist_spacetime_riemann_tensor; gr_brill_lindquist->spacetime.spatial_ricci_tensor_func = brill_lindquist_spatial_ricci_tensor; - gr_brill_lindquist->spacetime.spacetime_ricci_tensor_func = brill_lindquist_spacetime_ricci_tensor; + gr_brill_lindquist->spacetime.spacetime_ricci_tensor_func = + brill_lindquist_spacetime_ricci_tensor; gr_brill_lindquist->spacetime.spatial_ricci_scalar_func = brill_lindquist_spatial_ricci_scalar; - gr_brill_lindquist->spacetime.spacetime_ricci_scalar_func = brill_lindquist_spacetime_ricci_scalar; + gr_brill_lindquist->spacetime.spacetime_ricci_scalar_func = + brill_lindquist_spacetime_ricci_scalar; gr_brill_lindquist->spacetime.spatial_weyl_tensor_func = brill_lindquist_spatial_weyl_tensor; gr_brill_lindquist->spacetime.spacetime_weyl_tensor_func = brill_lindquist_spacetime_weyl_tensor; - gr_brill_lindquist->spacetime.extrinsic_curvature_tensor_func = brill_lindquist_extrinsic_curvature_tensor; + gr_brill_lindquist->spacetime.extrinsic_curvature_tensor_func = + brill_lindquist_extrinsic_curvature_tensor; gr_brill_lindquist->spacetime.conformal_factor_func = brill_lindquist_conformal_factor; gr_brill_lindquist->spacetime.bssn_conformal_factor_func = brill_lindquist_bssn_conformal_factor; gr_brill_lindquist->spacetime.conformal_factor_der_func = brill_lindquist_conformal_factor_der; - gr_brill_lindquist->spacetime.bssn_conformal_factor_der_func = brill_lindquist_bssn_conformal_factor_der; + gr_brill_lindquist->spacetime.bssn_conformal_factor_der_func = + brill_lindquist_bssn_conformal_factor_der; gr_brill_lindquist->spacetime.conformal_factor_der2_func = brill_lindquist_conformal_factor_der2; - gr_brill_lindquist->spacetime.bssn_conformal_factor_der2_func = brill_lindquist_bssn_conformal_factor_der2; + gr_brill_lindquist->spacetime.bssn_conformal_factor_der2_func = + brill_lindquist_bssn_conformal_factor_der2; gr_brill_lindquist->spacetime.excision_region_func = brill_lindquist_excision_region; gr_brill_lindquist->spacetime.flags = 0; GKYL_CLEAR_CU_ALLOC(gr_brill_lindquist->spacetime.flags); gr_brill_lindquist->spacetime.ref_count = gkyl_ref_count_init(gkyl_gr_brill_lindquist_free); - gr_brill_lindquist->spacetime.on_dev = &gr_brill_lindquist->spacetime; // On the CPU, the spacetime object points to itself. + gr_brill_lindquist->spacetime.on_dev = + &gr_brill_lindquist->spacetime; // On the CPU, the spacetime object points to itself. return &gr_brill_lindquist->spacetime; } \ No newline at end of file diff --git a/moments/zero/gr_minkowski.c b/moments/zero/gr_minkowski.c index 9fe52a81f6..deff4cb6fd 100644 --- a/moments/zero/gr_minkowski.c +++ b/moments/zero/gr_minkowski.c @@ -5,74 +5,79 @@ #include #include -static void -minkowski_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_metric_tensor) +static void minkowski_spatial_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_metric_tensor +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i == j) { (*spatial_metric_tensor)[i][j] = 1.0; - } - else { + } else { (*spatial_metric_tensor)[i][j] = 0.0; } } } } -static void -minkowski_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_metric_tensor) +static void minkowski_spacetime_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_metric_tensor +) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (i == j) { if (i == 0) { (*spacetime_metric_tensor)[i][j] = -1.0; - } - else { + } else { (*spacetime_metric_tensor)[i][j] = 1.0; } - } - else { + } else { (*spacetime_metric_tensor)[i][j] = 0.0; } } } } -static void -minkowski_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_inv_metric_tensor) +static void minkowski_spatial_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_inv_metric_tensor +) { minkowski_spatial_metric_tensor(spacetime, t, x, y, z, spatial_inv_metric_tensor); } -static void -minkowski_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_inv_metric_tensor) +static void minkowski_spacetime_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_inv_metric_tensor +) { minkowski_spacetime_metric_tensor(spacetime, t, x, y, z, spacetime_inv_metric_tensor); } -static void -minkowski_spatial_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spatial_metric_det) +static void minkowski_spatial_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spatial_metric_det +) { *spatial_metric_det = 1.0; } -static void -minkowski_spacetime_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spacetime_metric_det) +static void minkowski_spacetime_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spacetime_metric_det +) { *spacetime_metric_det = -1.0; } -static void -minkowski_spatial_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_metric_tensor_der) +static void minkowski_spatial_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ****spatial_metric_tensor_der +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -83,9 +88,11 @@ minkowski_spatial_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, c } } -static void -minkowski_spacetime_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_metric_tensor_der) +static void minkowski_spacetime_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_metric_tensor_der +) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -96,34 +103,38 @@ minkowski_spacetime_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, } } -static void -minkowski_lapse_function(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* lapse_function) +static void minkowski_lapse_function( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *lapse_function +) { *lapse_function = 1.0; } -static void -minkowski_shift_vector(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double** shift_vector) +static void minkowski_shift_vector( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double **shift_vector +) { for (int i = 0; i < 3; i++) { (*shift_vector)[i] = 0.0; } } -static void -minkowski_lapse_function_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** lapse_function_der) +static void minkowski_lapse_function_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **lapse_function_der +) { for (int i = 0; i < 3; i++) { (*lapse_function_der)[i] = 0.0; } } -static void -minkowski_shift_vector_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** shift_vector_der) +static void minkowski_shift_vector_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***shift_vector_der +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -132,9 +143,10 @@ minkowski_shift_vector_der(const struct gkyl_gr_spacetime* spacetime, const doub } } -static void -minkowski_spatial_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_christoffel) +static void minkowski_spatial_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ****spatial_christoffel +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -145,9 +157,11 @@ minkowski_spatial_christoffel(const struct gkyl_gr_spacetime* spacetime, const d } } -static void -minkowski_spacetime_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_christoffel) +static void minkowski_spacetime_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_christoffel +) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -158,9 +172,11 @@ minkowski_spacetime_christoffel(const struct gkyl_gr_spacetime* spacetime, const } } -static void -minkowski_spatial_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_riemann_tensor) +static void minkowski_spatial_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double *****spatial_riemann_tensor +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -173,9 +189,11 @@ minkowski_spatial_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, cons } } -static void -minkowski_spacetime_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_riemann_tensor) +static void minkowski_spacetime_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_riemann_tensor +) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -188,9 +206,10 @@ minkowski_spacetime_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, co } } -static void -minkowski_spatial_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** spatial_ricci_tensor) +static void minkowski_spatial_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***spatial_ricci_tensor +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -199,9 +218,11 @@ minkowski_spatial_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const } } -static void -minkowski_spacetime_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double*** spacetime_ricci_tensor) +static void minkowski_spacetime_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ***spacetime_ricci_tensor +) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -210,23 +231,27 @@ minkowski_spacetime_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, cons } } -static void -minkowski_spatial_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double* spatial_ricci_scalar) +static void minkowski_spatial_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *spatial_ricci_scalar +) { *spatial_ricci_scalar = 0.0; } -static void -minkowski_spacetime_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double* spacetime_ricci_scalar) +static void minkowski_spacetime_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *spacetime_ricci_scalar +) { *spacetime_ricci_scalar = 0.0; } -static void -minkowski_spatial_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_weyl_tensor) +static void minkowski_spatial_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *****spatial_weyl_tensor +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -239,9 +264,11 @@ minkowski_spatial_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const d } } -static void -minkowski_spacetime_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_weyl_tensor) +static void minkowski_spacetime_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_weyl_tensor +) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -254,9 +281,11 @@ minkowski_spacetime_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const } } -static void -minkowski_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** extrinsic_curvature_tensor) +static void minkowski_extrinsic_curvature_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***extrinsic_curvature_tensor +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -265,41 +294,47 @@ minkowski_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime, } } -static void -minkowski_conformal_factor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* conformal_factor) +static void minkowski_conformal_factor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *conformal_factor +) { *conformal_factor = 1.0; } -static void -minkowski_bssn_conformal_factor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* bssn_conformal_factor) +static void minkowski_bssn_conformal_factor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *bssn_conformal_factor +) { *bssn_conformal_factor = 1.0; } -static void -minkowski_conformal_factor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** conformal_factor_der) +static void minkowski_conformal_factor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **conformal_factor_der +) { for (int i = 0; i < 3; i++) { (*conformal_factor_der)[i] = 0.0; } } -static void -minkowski_bssn_conformal_factor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** bssn_conformal_factor_der) +static void minkowski_bssn_conformal_factor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double **bssn_conformal_factor_der +) { for (int i = 0; i < 3; i++) { (*bssn_conformal_factor_der)[i] = 0.0; } } -static void -minkowski_conformal_factor_der2(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** conformal_factor_der2) +static void minkowski_conformal_factor_der2( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***conformal_factor_der2 +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -308,9 +343,11 @@ minkowski_conformal_factor_der2(const struct gkyl_gr_spacetime* spacetime, const } } -static void -minkowski_bssn_conformal_factor_der2(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** bssn_conformal_factor_der2) +static void minkowski_bssn_conformal_factor_der2( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***bssn_conformal_factor_der2 +) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -319,17 +356,17 @@ minkowski_bssn_conformal_factor_der2(const struct gkyl_gr_spacetime* spacetime, } } -static void -minkowski_excision_region(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - bool* in_excision_region) +static void minkowski_excision_region( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, bool *in_excision_region +) { *in_excision_region = false; } -void -gkyl_gr_minkowski_free(const struct gkyl_ref_count* ref) +void gkyl_gr_minkowski_free(const struct gkyl_ref_count *ref) { - struct gkyl_gr_spacetime* base = container_of(ref, struct gkyl_gr_spacetime, ref_count); + struct gkyl_gr_spacetime *base = container_of(ref, struct gkyl_gr_spacetime, ref_count); if (gkyl_gr_spacetime_is_cu_dev(base)) { // Free inner on_dev object. @@ -341,17 +378,12 @@ gkyl_gr_minkowski_free(const struct gkyl_ref_count* ref) gkyl_free(gr_minkowski); } -struct gkyl_gr_spacetime* -gkyl_gr_minkowski_new(bool use_gpu) +struct gkyl_gr_spacetime *gkyl_gr_minkowski_new(bool use_gpu) { - return gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp) { - .use_gpu = use_gpu, - } - ); + return gkyl_gr_minkowski_inew(&(struct gkyl_gr_minkowski_inp){.use_gpu = use_gpu}); } -struct gkyl_gr_spacetime* -gkyl_gr_minkowski_inew(const struct gkyl_gr_minkowski_inp* inp) +struct gkyl_gr_spacetime *gkyl_gr_minkowski_inew(const struct gkyl_gr_minkowski_inp *inp) { struct gr_minkowski *gr_minkowski = gkyl_malloc(sizeof(struct gr_minkowski)); @@ -404,7 +436,8 @@ gkyl_gr_minkowski_inew(const struct gkyl_gr_minkowski_inp* inp) gr_minkowski->spacetime.flags = 0; GKYL_CLEAR_CU_ALLOC(gr_minkowski->spacetime.flags); gr_minkowski->spacetime.ref_count = gkyl_ref_count_init(gkyl_gr_minkowski_free); - gr_minkowski->spacetime.on_dev = &gr_minkowski->spacetime; // On the CPU, the spacetime object points to itself. + gr_minkowski->spacetime.on_dev = + &gr_minkowski->spacetime; // On the CPU, the spacetime object points to itself. return &gr_minkowski->spacetime; } \ No newline at end of file diff --git a/moments/zero/gr_neutronstar.c b/moments/zero/gr_neutronstar.c index d1b55069d5..aa5e04c1d4 100644 --- a/moments/zero/gr_neutronstar.c +++ b/moments/zero/gr_neutronstar.c @@ -6,10 +6,12 @@ #include #include -double -neutronstar_A_scalar(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double neutronstar_A_scalar( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double mass = neutronstar->mass; double spin = neutronstar->spin; @@ -26,16 +28,23 @@ neutronstar_A_scalar(const struct gkyl_gr_spacetime* spacetime, const double x, double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double z_cylindrical = z - pos_z; - return (8.0 * (rho * rho) * (z_cylindrical * z_cylindrical) * ((24.0 * (ang_mom * ang_mom) * mass) + (17.0 * (mass * mass) * mass_quadrupole) + (21.0 * mass_hexadecapole))) + - ((rho * rho * rho * rho) * ((-10.0 * (ang_mom * ang_mom) * mass) + (7.0 * (mass * mass * mass * mass * mass)) + (32.0 * mass_quadrupole * (mass * mass)) - (21.0 * mass_hexadecapole))) + - (8.0 * (z_cylindrical * z_cylindrical * z_cylindrical * z_cylindrical) * ((20.0 * (ang_mom * ang_mom) * mass) - (7.0 * (mass * mass * mass * mass * mass)) - - (22.0 * mass_quadrupole * (mass * mass)) - (7.0 * mass_hexadecapole))); + return (8.0 * (rho * rho) * (z_cylindrical * z_cylindrical) * + ((24.0 * (ang_mom * ang_mom) * mass) + (17.0 * (mass * mass) * mass_quadrupole) + + (21.0 * mass_hexadecapole))) + + ((rho * rho * rho * rho) * + ((-10.0 * (ang_mom * ang_mom) * mass) + (7.0 * (mass * mass * mass * mass * mass)) + + (32.0 * mass_quadrupole * (mass * mass)) - (21.0 * mass_hexadecapole))) + + (8.0 * (z_cylindrical * z_cylindrical * z_cylindrical * z_cylindrical) * + ((20.0 * (ang_mom * ang_mom) * mass) - (7.0 * (mass * mass * mass * mass * mass)) - + (22.0 * mass_quadrupole * (mass * mass)) - (7.0 * mass_hexadecapole))); } -double -neutronstar_B_scalar(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double neutronstar_B_scalar( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double mass = neutronstar->mass; double spin = neutronstar->spin; @@ -53,18 +62,28 @@ neutronstar_B_scalar(const struct gkyl_gr_spacetime* spacetime, const double x, double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double z_cylindrical = z - pos_z; - return ((rho * rho * rho * rho) * ((10.0 * (ang_mom * ang_mom) * (mass * mass)) + (10.0 * mass_quadrupole * (mass * mass * mass)) + (21.0 * mass_hexadecapole * mass) + - (7.0 * (mass_quadrupole * mass_quadrupole)))) + - (4.0 * (z_cylindrical * z_cylindrical * z_cylindrical * z_cylindrical) * ((-40.0 * (ang_mom * ang_mom) * (mass * mass)) - (14.0 * ang_mom * spin_octupole) + - (7.0 * (mass * mass * mass * mass * mass * mass)) + (30.0 * mass_quadrupole * (mass * mass * mass)) + (14.0 * mass_hexadecapole * mass) + (7.0 * (mass_quadrupole * mass_quadrupole)))) - - (4.0 * (rho * rho) * (z_cylindrical * z_cylindrical) * ((27.0 * (ang_mom * ang_mom) * (mass * mass)) - (21.0 * ang_mom * spin_octupole) + (7.0 * (mass * mass * mass * mass * mass * mass)) + - (48.0 * mass_quadrupole * (mass * mass * mass)) + (42.0 * mass_hexadecapole * mass) + (7.0 * (mass_quadrupole * mass_quadrupole)))); + return ((rho * rho * rho * rho) * + ((10.0 * (ang_mom * ang_mom) * (mass * mass)) + + (10.0 * mass_quadrupole * (mass * mass * mass)) + (21.0 * mass_hexadecapole * mass) + + (7.0 * (mass_quadrupole * mass_quadrupole)))) + + (4.0 * (z_cylindrical * z_cylindrical * z_cylindrical * z_cylindrical) * + ((-40.0 * (ang_mom * ang_mom) * (mass * mass)) - (14.0 * ang_mom * spin_octupole) + + (7.0 * (mass * mass * mass * mass * mass * mass)) + + (30.0 * mass_quadrupole * (mass * mass * mass)) + (14.0 * mass_hexadecapole * mass) + + (7.0 * (mass_quadrupole * mass_quadrupole)))) - + (4.0 * (rho * rho) * (z_cylindrical * z_cylindrical) * + ((27.0 * (ang_mom * ang_mom) * (mass * mass)) - (21.0 * ang_mom * spin_octupole) + + (7.0 * (mass * mass * mass * mass * mass * mass)) + + (48.0 * mass_quadrupole * (mass * mass * mass)) + (42.0 * mass_hexadecapole * mass) + + (7.0 * (mass_quadrupole * mass_quadrupole)))); } -double -neutronstar_H_scalar(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double neutronstar_H_scalar( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double mass = neutronstar->mass; double spin = neutronstar->spin; @@ -81,14 +100,18 @@ neutronstar_H_scalar(const struct gkyl_gr_spacetime* spacetime, const double x, double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double z_cylindrical = z - pos_z; - return (4.0 * (rho * rho) * (z_cylindrical * z_cylindrical) * ((ang_mom * (mass_quadrupole - (2.0 * (mass * mass * mass)))) - (3.0 * mass * spin_octupole))) + - ((rho * rho * rho * rho) * ((ang_mom * mass_quadrupole) + (3.0 * mass * spin_octupole))); + return (4.0 * (rho * rho) * (z_cylindrical * z_cylindrical) * + ((ang_mom * (mass_quadrupole - (2.0 * (mass * mass * mass)))) - + (3.0 * mass * spin_octupole))) + + ((rho * rho * rho * rho) * ((ang_mom * mass_quadrupole) + (3.0 * mass * spin_octupole))); } -double -neutronstar_G_scalar(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double neutronstar_G_scalar( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double mass = neutronstar->mass; double spin = neutronstar->spin; @@ -105,19 +128,31 @@ neutronstar_G_scalar(const struct gkyl_gr_spacetime* spacetime, const double x, double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double z_cylindrical = z - pos_z; - return (rho * rho) * ((ang_mom * ang_mom * ang_mom) * (- ((rho * rho * rho * rho) + (8.0 * (z_cylindrical * z_cylindrical * z_cylindrical * z_cylindrical)) - - (12.0 * (rho * rho) * (z_cylindrical * z_cylindrical)))) + - ((ang_mom * mass) * ((((mass * mass * mass) + (2.0 * mass_quadrupole)) * (rho * rho * rho * rho)) - (8.0 * ((3.0 * (mass * mass * mass)) + (2.0 * mass_quadrupole)) * - (z_cylindrical * z_cylindrical * z_cylindrical * z_cylindrical)) + - (4.0 * (((mass * mass * mass) + (10.0 * mass_quadrupole)) * ((rho * rho) * (z_cylindrical * z_cylindrical)))))) + - ((mass * mass) * spin_octupole) * ((3.0 * (rho * rho * rho * rho)) - (40.0 * (z_cylindrical * z_cylindrical * z_cylindrical * z_cylindrical)) + - (12.0 * (rho * rho) * (z_cylindrical * z_cylindrical)))); + return (rho * rho) * + ((ang_mom * ang_mom * ang_mom) * + (-( + (rho * rho * rho * rho) + + (8.0 * (z_cylindrical * z_cylindrical * z_cylindrical * z_cylindrical)) - + (12.0 * (rho * rho) * (z_cylindrical * z_cylindrical)) + )) + + ((ang_mom * mass) * + ((((mass * mass * mass) + (2.0 * mass_quadrupole)) * (rho * rho * rho * rho)) - + (8.0 * ((3.0 * (mass * mass * mass)) + (2.0 * mass_quadrupole)) * + (z_cylindrical * z_cylindrical * z_cylindrical * z_cylindrical)) + + (4.0 * (((mass * mass * mass) + (10.0 * mass_quadrupole)) * + ((rho * rho) * (z_cylindrical * z_cylindrical)))))) + + ((mass * mass) * spin_octupole) * + ((3.0 * (rho * rho * rho * rho)) - + (40.0 * (z_cylindrical * z_cylindrical * z_cylindrical * z_cylindrical)) + + (12.0 * (rho * rho) * (z_cylindrical * z_cylindrical)))); } -double -neutronstar_F_scalar(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double neutronstar_F_scalar( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double mass = neutronstar->mass; double spin = neutronstar->spin; @@ -133,13 +168,17 @@ neutronstar_F_scalar(const struct gkyl_gr_spacetime* spacetime, const double x, double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double z_cylindrical = z - pos_z; - return ((rho * rho * rho * rho) * (spin_octupole - (ang_mom * (mass * mass)))) - ((4.0 * (rho * rho) * (z_cylindrical * z_cylindrical)) * ((ang_mom * (mass * mass)) + spin_octupole)); + return ((rho * rho * rho * rho) * (spin_octupole - (ang_mom * (mass * mass)))) - + ((4.0 * (rho * rho) * (z_cylindrical * z_cylindrical)) * + ((ang_mom * (mass * mass)) + spin_octupole)); } -double -neutronstar_f_function(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double neutronstar_f_function( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double mass = neutronstar->mass; double spin = neutronstar->spin; @@ -158,18 +197,25 @@ neutronstar_f_function(const struct gkyl_gr_spacetime* spacetime, const double x double A_scalar = neutronstar_A_scalar(spacetime, x, y, z); double B_scalar = neutronstar_B_scalar(spacetime, x, y, z); - return 1.0 - ((2.0 * mass) / sqrt((rho * rho) + (z_cylindrical * z_cylindrical))) + ((2.0 * (mass * mass)) / ((rho * rho) + (z_cylindrical * z_cylindrical))) + - (((mass_quadrupole - (mass * mass * mass)) * (rho * rho)) - (2.0 * ((mass * mass * mass) + mass_quadrupole) * (z_cylindrical * z_cylindrical))) / - pow((rho * rho) + (z_cylindrical * z_cylindrical), 5.0 / 2.0) + - ((2.0 * (z_cylindrical * z_cylindrical) * (-(ang_mom * ang_mom) + (mass * mass * mass * mass) + (2.0 * mass_quadrupole * mass))) - (2.0 * mass * mass_quadrupole * (rho * rho))) / - pow((rho * rho) + (z_cylindrical * z_cylindrical), 3.0) + - (A_scalar / (28.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 9.0 / 2.0))) + (B_scalar / (14.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 5.0))); + return 1.0 - ((2.0 * mass) / sqrt((rho * rho) + (z_cylindrical * z_cylindrical))) + + ((2.0 * (mass * mass)) / ((rho * rho) + (z_cylindrical * z_cylindrical))) + + (((mass_quadrupole - (mass * mass * mass)) * (rho * rho)) - + (2.0 * ((mass * mass * mass) + mass_quadrupole) * (z_cylindrical * z_cylindrical))) / + pow((rho * rho) + (z_cylindrical * z_cylindrical), 5.0 / 2.0) + + ((2.0 * (z_cylindrical * z_cylindrical) * + (-(ang_mom * ang_mom) + (mass * mass * mass * mass) + (2.0 * mass_quadrupole * mass))) - + (2.0 * mass * mass_quadrupole * (rho * rho))) / + pow((rho * rho) + (z_cylindrical * z_cylindrical), 3.0) + + (A_scalar / (28.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 9.0 / 2.0))) + + (B_scalar / (14.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 5.0))); } -double -neutronstar_omega_function(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double neutronstar_omega_function( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double mass = neutronstar->mass; double spin = neutronstar->spin; @@ -187,16 +233,21 @@ neutronstar_omega_function(const struct gkyl_gr_spacetime* spacetime, const doub double G_scalar = neutronstar_G_scalar(spacetime, x, y, z); double F_scalar = neutronstar_F_scalar(spacetime, x, y, z); - return (-(2.0 * ang_mom * (rho * rho)) / pow((rho * rho) + (z_cylindrical * z_cylindrical), 3.0 / 2.0)) - ((2.0 * ang_mom * mass * (rho * rho)) / - pow((rho * rho) + (z_cylindrical * z_cylindrical), 2.0)) + - (F_scalar / pow((rho * rho) + (z_cylindrical * z_cylindrical), 7.0 / 2.0)) + (H_scalar / (2.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 4.0))) + - (G_scalar / (4.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 11.0 / 2.0))); + return (-(2.0 * ang_mom * (rho * rho)) / + pow((rho * rho) + (z_cylindrical * z_cylindrical), 3.0 / 2.0)) - + ((2.0 * ang_mom * mass * (rho * rho)) / + pow((rho * rho) + (z_cylindrical * z_cylindrical), 2.0)) + + (F_scalar / pow((rho * rho) + (z_cylindrical * z_cylindrical), 7.0 / 2.0)) + + (H_scalar / (2.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 4.0))) + + (G_scalar / (4.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 11.0 / 2.0))); } -double -neutronstar_gamma_function(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double neutronstar_gamma_function( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double mass = neutronstar->mass; double spin = neutronstar->spin; @@ -212,15 +263,21 @@ neutronstar_gamma_function(const struct gkyl_gr_spacetime* spacetime, const doub double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double z_cylindrical = z - pos_z; - return (((rho * rho) * (((ang_mom * ang_mom) * ((rho * rho) - (8.0 * (z_cylindrical * z_cylindrical)))) + (mass * ((mass * mass * mass) + - (3.0 * mass_quadrupole)) * ((rho * rho) - (4.0 * (z_cylindrical * z_cylindrical)))))) / (4.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 4.0))) - - (((mass * mass) * (rho * rho)) / (2.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 2.0))); + return (((rho * rho) * + (((ang_mom * ang_mom) * ((rho * rho) - (8.0 * (z_cylindrical * z_cylindrical)))) + + (mass * ((mass * mass * mass) + (3.0 * mass_quadrupole)) * + ((rho * rho) - (4.0 * (z_cylindrical * z_cylindrical)))))) / + (4.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 4.0))) - + (((mass * mass) * (rho * rho)) / + (2.0 * pow((rho * rho) + (z_cylindrical * z_cylindrical), 2.0))); } -double** -neutronstar_spatial_transformation_tensor(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double **neutronstar_spatial_transformation_tensor( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double pos_x = neutronstar->pos_x; double pos_y = neutronstar->pos_y; @@ -229,7 +286,7 @@ neutronstar_spatial_transformation_tensor(const struct gkyl_gr_spacetime* spacet double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double theta = atan2((y - pos_y), (x - pos_x)); - double **spatial_transformation_tensor = gkyl_malloc(sizeof(double*[3])); + double **spatial_transformation_tensor = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_transformation_tensor[i] = gkyl_malloc(sizeof(double[3])); } @@ -249,10 +306,12 @@ neutronstar_spatial_transformation_tensor(const struct gkyl_gr_spacetime* spacet return spatial_transformation_tensor; } -double** -neutronstar_spacetime_transformation_tensor(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double **neutronstar_spacetime_transformation_tensor( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double pos_x = neutronstar->pos_x; double pos_y = neutronstar->pos_y; @@ -261,7 +320,7 @@ neutronstar_spacetime_transformation_tensor(const struct gkyl_gr_spacetime* spac double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double theta = atan2((y - pos_y), (x - pos_x)); - double **spacetime_transformation_tensor = gkyl_malloc(sizeof(double*[4])); + double **spacetime_transformation_tensor = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_transformation_tensor[i] = gkyl_malloc(sizeof(double[4])); } @@ -270,7 +329,7 @@ neutronstar_spacetime_transformation_tensor(const struct gkyl_gr_spacetime* spac spacetime_transformation_tensor[0][1] = 0.0; spacetime_transformation_tensor[0][2] = 0.0; spacetime_transformation_tensor[0][3] = 0.0; - + spacetime_transformation_tensor[1][0] = 0.0; spacetime_transformation_tensor[1][1] = cos(theta); spacetime_transformation_tensor[1][2] = sin(theta); @@ -289,10 +348,12 @@ neutronstar_spacetime_transformation_tensor(const struct gkyl_gr_spacetime* spac return spacetime_transformation_tensor; } -double** -neutronstar_spatial_inv_transformation_tensor(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double **neutronstar_spatial_inv_transformation_tensor( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double pos_x = neutronstar->pos_x; double pos_y = neutronstar->pos_y; @@ -301,7 +362,7 @@ neutronstar_spatial_inv_transformation_tensor(const struct gkyl_gr_spacetime* sp double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double theta = atan2((y - pos_y), (x - pos_x)); - double **spatial_inv_transformation_tensor = gkyl_malloc(sizeof(double*[3])); + double **spatial_inv_transformation_tensor = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_inv_transformation_tensor[i] = gkyl_malloc(sizeof(double[3])); } @@ -321,10 +382,12 @@ neutronstar_spatial_inv_transformation_tensor(const struct gkyl_gr_spacetime* sp return spatial_inv_transformation_tensor; } -double** -neutronstar_spacetime_inv_transformation_tensor(const struct gkyl_gr_spacetime* spacetime, const double x, const double y, const double z) +double **neutronstar_spacetime_inv_transformation_tensor( + const struct gkyl_gr_spacetime *spacetime, const double x, const double y, const double z +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double pos_x = neutronstar->pos_x; double pos_y = neutronstar->pos_y; @@ -333,7 +396,7 @@ neutronstar_spacetime_inv_transformation_tensor(const struct gkyl_gr_spacetime* double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); double theta = atan2((y - pos_y), (x - pos_x)); - double **spacetime_inv_transformation_tensor = gkyl_malloc(sizeof(double*[4])); + double **spacetime_inv_transformation_tensor = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_inv_transformation_tensor[i] = gkyl_malloc(sizeof(double[4])); } @@ -342,7 +405,7 @@ neutronstar_spacetime_inv_transformation_tensor(const struct gkyl_gr_spacetime* spacetime_inv_transformation_tensor[0][1] = 0.0; spacetime_inv_transformation_tensor[0][2] = 0.0; spacetime_inv_transformation_tensor[0][3] = 0.0; - + spacetime_inv_transformation_tensor[1][0] = 0.0; spacetime_inv_transformation_tensor[1][1] = cos(theta); spacetime_inv_transformation_tensor[1][2] = -rho * sin(theta); @@ -361,11 +424,13 @@ neutronstar_spacetime_inv_transformation_tensor(const struct gkyl_gr_spacetime* return spacetime_inv_transformation_tensor; } -static void -neutronstar_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_metric_tensor) +static void neutronstar_spatial_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_metric_tensor +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double pos_x = neutronstar->pos_x; double pos_y = neutronstar->pos_y; @@ -373,7 +438,7 @@ neutronstar_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacetime, con double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); - double **spatial_metric_tensor_cylindrical = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_tensor_cylindrical = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_tensor_cylindrical[i] = gkyl_malloc(sizeof(double[3])); } @@ -390,16 +455,20 @@ neutronstar_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacetime, con double gamma_function = neutronstar_gamma_function(spacetime, x, y, z); spatial_metric_tensor_cylindrical[0][0] = exp(2.0 * gamma_function) / f_function; - spatial_metric_tensor_cylindrical[1][1] = ((rho * rho) / f_function) - (f_function * (omega_function * omega_function)); + spatial_metric_tensor_cylindrical[1][1] = + ((rho * rho) / f_function) - (f_function * (omega_function * omega_function)); spatial_metric_tensor_cylindrical[2][2] = exp(2.0 * gamma_function) / f_function; - double **spatial_transformation_tensor = neutronstar_spatial_transformation_tensor(spacetime, x, y, z); + double **spatial_transformation_tensor = + neutronstar_spatial_transformation_tensor(spacetime, x, y, z); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - (*spatial_metric_tensor)[i][j] += spatial_transformation_tensor[k][i] * spatial_transformation_tensor[l][j] * spatial_metric_tensor_cylindrical[k][l]; + (*spatial_metric_tensor)[i][j] += spatial_transformation_tensor[k][i] * + spatial_transformation_tensor[l][j] * + spatial_metric_tensor_cylindrical[k][l]; } } } @@ -413,11 +482,13 @@ neutronstar_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacetime, con gkyl_free(spatial_transformation_tensor); } -static void -neutronstar_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_metric_tensor) +static void neutronstar_spacetime_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_metric_tensor +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double pos_x = neutronstar->pos_x; double pos_y = neutronstar->pos_y; @@ -425,7 +496,7 @@ neutronstar_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spacetime, c double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); - double **spacetime_metric_tensor_cylindrical = gkyl_malloc(sizeof(double*[4])); + double **spacetime_metric_tensor_cylindrical = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_metric_tensor_cylindrical[i] = gkyl_malloc(sizeof(double[4])); } @@ -443,19 +514,23 @@ neutronstar_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spacetime, c spacetime_metric_tensor_cylindrical[0][0] = -f_function; spacetime_metric_tensor_cylindrical[1][1] = exp(2.0 * gamma_function) / f_function; - spacetime_metric_tensor_cylindrical[2][2] = ((rho * rho) / f_function) - (f_function * (omega_function * omega_function)); + spacetime_metric_tensor_cylindrical[2][2] = + ((rho * rho) / f_function) - (f_function * (omega_function * omega_function)); spacetime_metric_tensor_cylindrical[3][3] = exp(2.0 * gamma_function) / f_function; spacetime_metric_tensor_cylindrical[0][2] = f_function * omega_function; spacetime_metric_tensor_cylindrical[2][0] = f_function * omega_function; - double **spacetime_transformation_tensor = neutronstar_spacetime_transformation_tensor(spacetime, x, y, z); + double **spacetime_transformation_tensor = + neutronstar_spacetime_transformation_tensor(spacetime, x, y, z); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { - (*spacetime_metric_tensor)[i][j] += spacetime_transformation_tensor[k][i] * spacetime_transformation_tensor[l][j] * spacetime_metric_tensor_cylindrical[k][l]; + (*spacetime_metric_tensor)[i][j] += spacetime_transformation_tensor[k][i] * + spacetime_transformation_tensor[l][j] * + spacetime_metric_tensor_cylindrical[k][l]; } } } @@ -469,11 +544,13 @@ neutronstar_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spacetime, c gkyl_free(spacetime_transformation_tensor); } -static void -neutronstar_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_inv_metric_tensor) +static void neutronstar_spatial_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_inv_metric_tensor +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double pos_x = neutronstar->pos_x; double pos_y = neutronstar->pos_y; @@ -481,7 +558,7 @@ neutronstar_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); - double **spatial_inv_metric_tensor_cylindrical = gkyl_malloc(sizeof(double*[3])); + double **spatial_inv_metric_tensor_cylindrical = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_inv_metric_tensor_cylindrical[i] = gkyl_malloc(sizeof(double[3])); } @@ -496,18 +573,22 @@ neutronstar_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, double f_function = neutronstar_f_function(spacetime, x, y, z); double omega_function = neutronstar_omega_function(spacetime, x, y, z); double gamma_function = neutronstar_gamma_function(spacetime, x, y, z); - + spatial_inv_metric_tensor_cylindrical[0][0] = exp(-2.0 * gamma_function) * f_function; - spatial_inv_metric_tensor_cylindrical[1][1] = f_function / ((rho * rho) - ((f_function * f_function) * (omega_function * omega_function))); + spatial_inv_metric_tensor_cylindrical[1][1] = + f_function / ((rho * rho) - ((f_function * f_function) * (omega_function * omega_function))); spatial_inv_metric_tensor_cylindrical[2][2] = exp(-2.0 * gamma_function) * f_function; - double **spatial_inv_transformation_tensor = neutronstar_spatial_inv_transformation_tensor(spacetime, x, y, z); + double **spatial_inv_transformation_tensor = + neutronstar_spatial_inv_transformation_tensor(spacetime, x, y, z); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - (*spatial_inv_metric_tensor)[i][j] += spatial_inv_transformation_tensor[i][k] * spatial_inv_transformation_tensor[j][l] * spatial_inv_metric_tensor_cylindrical[k][l]; + (*spatial_inv_metric_tensor)[i][j] += spatial_inv_transformation_tensor[i][k] * + spatial_inv_transformation_tensor[j][l] * + spatial_inv_metric_tensor_cylindrical[k][l]; } } } @@ -521,11 +602,13 @@ neutronstar_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, gkyl_free(spatial_inv_transformation_tensor); } -static void -neutronstar_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_inv_metric_tensor) +static void neutronstar_spacetime_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_inv_metric_tensor +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double pos_x = neutronstar->pos_x; double pos_y = neutronstar->pos_y; @@ -533,7 +616,7 @@ neutronstar_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetim double rho = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y))); - double **spacetime_inv_metric_tensor_cylindrical = gkyl_malloc(sizeof(double*[4])); + double **spacetime_inv_metric_tensor_cylindrical = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_inv_metric_tensor_cylindrical[i] = gkyl_malloc(sizeof(double[4])); } @@ -549,7 +632,8 @@ neutronstar_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetim double omega_function = neutronstar_omega_function(spacetime, x, y, z); double gamma_function = neutronstar_gamma_function(spacetime, x, y, z); - spacetime_inv_metric_tensor_cylindrical[0][0] = -(1.0 / f_function) + ((f_function * (omega_function * omega_function)) / (rho * rho)); + spacetime_inv_metric_tensor_cylindrical[0][0] = + -(1.0 / f_function) + ((f_function * (omega_function * omega_function)) / (rho * rho)); spacetime_inv_metric_tensor_cylindrical[1][1] = exp(-2.0 * gamma_function) * f_function; spacetime_inv_metric_tensor_cylindrical[2][2] = f_function / (rho * rho); spacetime_inv_metric_tensor_cylindrical[3][3] = exp(-2.0 * gamma_function) * f_function; @@ -557,13 +641,16 @@ neutronstar_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetim spacetime_inv_metric_tensor_cylindrical[0][2] = (f_function * omega_function) / (rho * rho); spacetime_inv_metric_tensor_cylindrical[2][0] = (f_function * omega_function) / (rho * rho); - double **spacetime_inv_transformation_tensor = neutronstar_spacetime_inv_transformation_tensor(spacetime, x, y, z); + double **spacetime_inv_transformation_tensor = + neutronstar_spacetime_inv_transformation_tensor(spacetime, x, y, z); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { - (*spacetime_inv_metric_tensor)[i][j] += spacetime_inv_transformation_tensor[i][k] * spacetime_inv_transformation_tensor[j][l] * spacetime_inv_metric_tensor_cylindrical[k][l]; + (*spacetime_inv_metric_tensor)[i][j] += spacetime_inv_transformation_tensor[i][k] * + spacetime_inv_transformation_tensor[j][l] * + spacetime_inv_metric_tensor_cylindrical[k][l]; } } } @@ -577,58 +664,71 @@ neutronstar_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetim gkyl_free(spacetime_inv_transformation_tensor); } -static void -neutronstar_spatial_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spatial_metric_det) +static void neutronstar_spatial_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spatial_metric_det +) { - double** spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } neutronstar_spatial_metric_tensor(spacetime, t, x, y, z, &spatial_metric); - *spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + *spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + for (int i = 0; i < 3; i++) { gkyl_free(spatial_metric[i]); } gkyl_free(spatial_metric); } -static void -neutronstar_spacetime_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spacetime_metric_det) +static void neutronstar_spacetime_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spacetime_metric_det +) { double spatial_metric_det; double lapse_function; neutronstar_spatial_metric_det(spacetime, t, x, y, z, &spatial_metric_det); neutronstar_lapse_function(spacetime, t, x, y, z, &lapse_function); - *spacetime_metric_det = - (lapse_function * lapse_function) * spatial_metric_det; + *spacetime_metric_det = -(lapse_function * lapse_function) * spatial_metric_det; } -static void -neutronstar_spatial_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_metric_tensor_der) +static void neutronstar_spatial_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ****spatial_metric_tensor_der +) { gkyl_gr_spatial_metric_tensor_diff(spacetime, t, x, y, z, dx, dy, dz, spatial_metric_tensor_der); } -static void -neutronstar_spacetime_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_metric_tensor_der) +static void neutronstar_spacetime_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_metric_tensor_der +) { - gkyl_gr_spacetime_metric_tensor_diff(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_metric_tensor_der); + gkyl_gr_spacetime_metric_tensor_diff( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_metric_tensor_der + ); } -static void -neutronstar_lapse_function(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* lapse_function) +static void neutronstar_lapse_function( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *lapse_function +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double pos_x = neutronstar->pos_x; double pos_y = neutronstar->pos_y; @@ -638,14 +738,18 @@ neutronstar_lapse_function(const struct gkyl_gr_spacetime* spacetime, const doub double f_function = neutronstar_f_function(spacetime, x, y, z); double omega_function = neutronstar_omega_function(spacetime, x, y, z); - *lapse_function = (sqrt(f_function) * rho) / sqrt((rho * rho) - ((f_function * f_function) * (omega_function * omega_function))); + *lapse_function = + (sqrt(f_function) * rho) / + sqrt((rho * rho) - ((f_function * f_function) * (omega_function * omega_function))); } -static void -neutronstar_shift_vector(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double** shift_vector) +static void neutronstar_shift_vector( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double **shift_vector +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double pos_x = neutronstar->pos_x; double pos_y = neutronstar->pos_y; @@ -661,10 +765,13 @@ neutronstar_shift_vector(const struct gkyl_gr_spacetime* spacetime, const double double omega_function = neutronstar_omega_function(spacetime, x, y, z); shift_vector_cylindrical[0] = 0.0; - shift_vector_cylindrical[1] = - ((f_function * f_function) * omega_function) / (-(rho * rho) + ((f_function * f_function) * (omega_function * omega_function))); + shift_vector_cylindrical[1] = + -((f_function * f_function) * omega_function) / + (-(rho * rho) + ((f_function * f_function) * (omega_function * omega_function))); shift_vector_cylindrical[2] = 0.0; - double **spatial_inv_transformation_tensor = neutronstar_spatial_inv_transformation_tensor(spacetime, x, y, z); + double **spatial_inv_transformation_tensor = + neutronstar_spatial_inv_transformation_tensor(spacetime, x, y, z); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -679,103 +786,125 @@ neutronstar_shift_vector(const struct gkyl_gr_spacetime* spacetime, const double gkyl_free(spatial_inv_transformation_tensor); } -static void -neutronstar_lapse_function_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** lapse_function_der) +static void neutronstar_lapse_function_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **lapse_function_der +) { gkyl_gr_lapse_function_diff(spacetime, t, x, y, z, dx, dy, dz, lapse_function_der); } -static void -neutronstar_shift_vector_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** shift_vector_der) +static void neutronstar_shift_vector_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***shift_vector_der +) { gkyl_gr_shift_vector_diff(spacetime, t, x, y, z, dx, dy, dz, shift_vector_der); } -static void -neutronstar_spatial_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_christoffel) +static void neutronstar_spatial_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ****spatial_christoffel +) { gkyl_gr_spatial_christoffel_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_christoffel); } -static void -neutronstar_spacetime_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_christoffel) +static void neutronstar_spacetime_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_christoffel +) { gkyl_gr_spacetime_christoffel_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_christoffel); } -static void -neutronstar_spatial_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_riemann_tensor) +static void neutronstar_spatial_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double *****spatial_riemann_tensor +) { gkyl_gr_spatial_riemann_tensor_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_riemann_tensor); } -static void -neutronstar_spacetime_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_riemann_tensor) +static void neutronstar_spacetime_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_riemann_tensor +) { - gkyl_gr_spacetime_riemann_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_riemann_tensor); + gkyl_gr_spacetime_riemann_tensor_fd( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_riemann_tensor + ); } -static void -neutronstar_spatial_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** spatial_ricci_tensor) +static void neutronstar_spatial_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***spatial_ricci_tensor +) { gkyl_gr_spatial_ricci_tensor_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_tensor); } -static void -neutronstar_spacetime_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double*** spacetime_ricci_tensor) +static void neutronstar_spacetime_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ***spacetime_ricci_tensor +) { gkyl_gr_spacetime_ricci_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_tensor); } -static void -neutronstar_spatial_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double* spatial_ricci_scalar) +static void neutronstar_spatial_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *spatial_ricci_scalar +) { gkyl_gr_spatial_ricci_scalar_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_scalar); } -static void -neutronstar_spacetime_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double* spacetime_ricci_scalar) +static void neutronstar_spacetime_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *spacetime_ricci_scalar +) { gkyl_gr_spacetime_ricci_scalar_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_scalar); } -static void -neutronstar_spatial_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_weyl_tensor) +static void neutronstar_spatial_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *****spatial_weyl_tensor +) { gkyl_gr_spatial_weyl_tensor_fd(spacetime, t, x, y, z, dx, dy, dz, spatial_weyl_tensor); } -static void -neutronstar_spacetime_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_weyl_tensor) +static void neutronstar_spacetime_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_weyl_tensor +) { gkyl_gr_spacetime_weyl_tensor_fd(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_weyl_tensor); } -static void -neutronstar_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** extrinsic_curvature_tensor) +static void neutronstar_extrinsic_curvature_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***extrinsic_curvature_tensor +) { double lapse_function; double *shift_vector = gkyl_malloc(sizeof(double[3])); - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); - double **shift_vector_der = gkyl_malloc(sizeof(double*[3])); - double **shift_vector_cov_der = gkyl_malloc(sizeof(double*[3])); - double **shift_covector_cov_der = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); + double **shift_vector_der = gkyl_malloc(sizeof(double *[3])); + double **shift_vector_cov_der = gkyl_malloc(sizeof(double *[3])); + double **shift_covector_cov_der = gkyl_malloc(sizeof(double *[3])); - double ***spatial_christoffel = gkyl_malloc(sizeof(double**[3])); + double ***spatial_christoffel = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); @@ -783,7 +912,7 @@ neutronstar_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime shift_vector_cov_der[i] = gkyl_malloc(sizeof(double[3])); shift_covector_cov_der[i] = gkyl_malloc(sizeof(double[3])); - spatial_christoffel[i] = gkyl_malloc(sizeof(double*[3])); + spatial_christoffel[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_christoffel[i][j] = gkyl_malloc(sizeof(double[3])); @@ -817,7 +946,9 @@ neutronstar_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*extrinsic_curvature_tensor)[i][j] = -(1.0 / (2.0 * lapse_function)) * (shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]); + (*extrinsic_curvature_tensor)[i][j] = + -(1.0 / (2.0 * lapse_function)) * + (shift_covector_cov_der[j][i] + shift_covector_cov_der[i][j]); } } @@ -840,11 +971,13 @@ neutronstar_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime gkyl_free(spatial_christoffel); } -static void -neutronstar_excision_region(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - bool* in_excision_region) +static void neutronstar_excision_region( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, bool *in_excision_region +) { - const struct gr_neutronstar *neutronstar = container_of(spacetime, struct gr_neutronstar, spacetime); + const struct gr_neutronstar *neutronstar = + container_of(spacetime, struct gr_neutronstar, spacetime); double mass = neutronstar->mass; double spin = neutronstar->spin; @@ -853,25 +986,25 @@ neutronstar_excision_region(const struct gkyl_gr_spacetime* spacetime, const dou double pos_y = neutronstar->pos_y; double pos_z = neutronstar->pos_z; - double r = sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); + double r = + sqrt(((x - pos_x) * (x - pos_x)) + ((y - pos_y) * (y - pos_y)) + ((z - pos_z) * (z - pos_z))); //if (r <= (mass * (1.0 + sqrt(1.0 + (spin * spin))))) { if (r <= mass * 2.0) { *in_excision_region = true; - } - else { + } else { *in_excision_region = false; } } -void -gkyl_gr_neutronstar_free(const struct gkyl_ref_count* ref) +void gkyl_gr_neutronstar_free(const struct gkyl_ref_count *ref) { - struct gkyl_gr_spacetime* base = container_of(ref, struct gkyl_gr_spacetime, ref_count); + struct gkyl_gr_spacetime *base = container_of(ref, struct gkyl_gr_spacetime, ref_count); if (gkyl_gr_spacetime_is_cu_dev(base)) { // Free inner on_dev object. - struct gr_neutronstar *gr_neutronstar = container_of(base->on_dev, struct gr_neutronstar, spacetime); + struct gr_neutronstar *gr_neutronstar = + container_of(base->on_dev, struct gr_neutronstar, spacetime); gkyl_cu_free(gr_neutronstar); } @@ -879,25 +1012,24 @@ gkyl_gr_neutronstar_free(const struct gkyl_ref_count* ref) gkyl_free(gr_neutronstar); } -struct gkyl_gr_spacetime* -gkyl_gr_neutronstar_new(bool use_gpu, double mass, double spin, double mass_quadrupole, double spin_octupole, double mass_hexadecapole, double pos_x, double pos_y, double pos_z) +struct gkyl_gr_spacetime *gkyl_gr_neutronstar_new( + bool use_gpu, double mass, double spin, double mass_quadrupole, double spin_octupole, + double mass_hexadecapole, double pos_x, double pos_y, double pos_z +) { - return gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp) { - .use_gpu = use_gpu, - .mass = mass, - .spin = spin, - .mass_quadrupole = mass_quadrupole, - .spin_octupole = spin_octupole, - .mass_hexadecapole = mass_hexadecapole, - .pos_x = pos_x, - .pos_y = pos_y, - .pos_z = pos_z, - } - ); + return gkyl_gr_neutronstar_inew(&(struct gkyl_gr_neutronstar_inp + ){.use_gpu = use_gpu, + .mass = mass, + .spin = spin, + .mass_quadrupole = mass_quadrupole, + .spin_octupole = spin_octupole, + .mass_hexadecapole = mass_hexadecapole, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z}); } -struct gkyl_gr_spacetime* -gkyl_gr_neutronstar_inew(const struct gkyl_gr_neutronstar_inp* inp) +struct gkyl_gr_spacetime *gkyl_gr_neutronstar_inew(const struct gkyl_gr_neutronstar_inp *inp) { struct gr_neutronstar *gr_neutronstar = gkyl_malloc(sizeof(struct gr_neutronstar)); @@ -916,13 +1048,15 @@ gkyl_gr_neutronstar_inew(const struct gkyl_gr_neutronstar_inp* inp) gr_neutronstar->spacetime.spacetime_metric_tensor_func = neutronstar_spacetime_metric_tensor; gr_neutronstar->spacetime.spatial_inv_metric_tensor_func = neutronstar_spatial_inv_metric_tensor; - gr_neutronstar->spacetime.spacetime_inv_metric_tensor_func = neutronstar_spacetime_inv_metric_tensor; + gr_neutronstar->spacetime.spacetime_inv_metric_tensor_func = + neutronstar_spacetime_inv_metric_tensor; gr_neutronstar->spacetime.spatial_metric_det_func = neutronstar_spatial_metric_det; gr_neutronstar->spacetime.spacetime_metric_det_func = neutronstar_spacetime_metric_det; gr_neutronstar->spacetime.spatial_metric_tensor_der_func = neutronstar_spatial_metric_tensor_der; - gr_neutronstar->spacetime.spacetime_metric_tensor_der_func = neutronstar_spacetime_metric_tensor_der; + gr_neutronstar->spacetime.spacetime_metric_tensor_der_func = + neutronstar_spacetime_metric_tensor_der; gr_neutronstar->spacetime.lapse_function_func = neutronstar_lapse_function; gr_neutronstar->spacetime.shift_vector_func = neutronstar_shift_vector; @@ -945,14 +1079,16 @@ gkyl_gr_neutronstar_inew(const struct gkyl_gr_neutronstar_inp* inp) gr_neutronstar->spacetime.spatial_weyl_tensor_func = neutronstar_spatial_weyl_tensor; gr_neutronstar->spacetime.spacetime_weyl_tensor_func = neutronstar_spacetime_weyl_tensor; - gr_neutronstar->spacetime.extrinsic_curvature_tensor_func = neutronstar_extrinsic_curvature_tensor; + gr_neutronstar->spacetime.extrinsic_curvature_tensor_func = + neutronstar_extrinsic_curvature_tensor; gr_neutronstar->spacetime.excision_region_func = neutronstar_excision_region; gr_neutronstar->spacetime.flags = 0; GKYL_CLEAR_CU_ALLOC(gr_neutronstar->spacetime.flags); gr_neutronstar->spacetime.ref_count = gkyl_ref_count_init(gkyl_gr_neutronstar_free); - gr_neutronstar->spacetime.on_dev = &gr_neutronstar->spacetime; // On the CPU, the spacetime object points to itself. + gr_neutronstar->spacetime.on_dev = + &gr_neutronstar->spacetime; // On the CPU, the spacetime object points to itself. return &gr_neutronstar->spacetime; } \ No newline at end of file diff --git a/moments/zero/gr_spacetime.c b/moments/zero/gr_spacetime.c index dd2f7b8bb5..ea0bf1c1fe 100644 --- a/moments/zero/gr_spacetime.c +++ b/moments/zero/gr_spacetime.c @@ -3,232 +3,302 @@ // These ensure that inline functions are only defined once. -static inline void -gkyl_gr_spatial_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_metric_tensor) +static inline void gkyl_gr_spatial_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_metric_tensor +) { return spacetime->spatial_metric_tensor_func(spacetime, t, x, y, z, spatial_metric_tensor); } -static inline void -gkyl_gr_spacetime_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_metric_tensor) +static inline void gkyl_gr_spacetime_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_metric_tensor +) { return spacetime->spacetime_metric_tensor_func(spacetime, t, x, y, z, spacetime_metric_tensor); } -static inline void -gkyl_gr_spatial_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spatial_inv_metric_tensor) +static inline void gkyl_gr_spatial_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spatial_inv_metric_tensor +) { return spacetime->spatial_inv_metric_tensor_func(spacetime, t, x, y, z, spatial_inv_metric_tensor); } -static inline void -gkyl_gr_spacetime_inv_metric_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double*** spacetime_inv_metric_tensor) +static inline void gkyl_gr_spacetime_inv_metric_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double ***spacetime_inv_metric_tensor +) { - return spacetime->spacetime_inv_metric_tensor_func(spacetime, t, x, y, z, spacetime_inv_metric_tensor); + return spacetime->spacetime_inv_metric_tensor_func( + spacetime, t, x, y, z, spacetime_inv_metric_tensor + ); } -static inline void -gkyl_gr_spatial_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spatial_metric_det) +static inline void gkyl_gr_spatial_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spatial_metric_det +) { return spacetime->spatial_metric_det_func(spacetime, t, x, y, z, spatial_metric_det); } -static inline void -gkyl_gr_spacetime_metric_det(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* spacetime_metric_det) +static inline void gkyl_gr_spacetime_metric_det( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *spacetime_metric_det +) { return spacetime->spacetime_metric_det_func(spacetime, t, x, y, z, spacetime_metric_det); } -static inline void -gkyl_gr_spatial_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_metric_tensor_der) +static inline void gkyl_gr_spatial_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ****spatial_metric_tensor_der +) { - return spacetime->spatial_metric_tensor_der_func(spacetime, t, x, y, z, dx, dy, dz, spatial_metric_tensor_der); + return spacetime->spatial_metric_tensor_der_func( + spacetime, t, x, y, z, dx, dy, dz, spatial_metric_tensor_der + ); } -static inline void -gkyl_gr_spacetime_metric_tensor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_metric_tensor_der) +static inline void gkyl_gr_spacetime_metric_tensor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_metric_tensor_der +) { - return spacetime->spacetime_metric_tensor_der_func(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_metric_tensor_der); + return spacetime->spacetime_metric_tensor_der_func( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_metric_tensor_der + ); } -static inline void -gkyl_gr_lapse_function(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* lapse_function) +static inline void gkyl_gr_lapse_function( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *lapse_function +) { return spacetime->lapse_function_func(spacetime, t, x, y, z, lapse_function); } -static inline void -gkyl_gr_shift_vector(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double** shift_vector) +static inline void gkyl_gr_shift_vector( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double **shift_vector +) { return spacetime->shift_vector_func(spacetime, t, x, y, z, shift_vector); } -static inline void -gkyl_gr_lapse_function_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** lapse_function_der) +static inline void gkyl_gr_lapse_function_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **lapse_function_der +) { return spacetime->lapse_function_der_func(spacetime, t, x, y, z, dx, dy, dz, lapse_function_der); } -static inline void -gkyl_gr_shift_vector_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** shift_vector_der) +static inline void gkyl_gr_shift_vector_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***shift_vector_der +) { return spacetime->shift_vector_der_func(spacetime, t, x, y, z, dx, dy, dz, shift_vector_der); } -static inline void -gkyl_gr_spatial_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_christoffel) +static inline void gkyl_gr_spatial_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ****spatial_christoffel +) { return spacetime->spatial_christoffel_func(spacetime, t, x, y, z, dx, dy, dz, spatial_christoffel); } -static inline void -gkyl_gr_spacetime_christoffel(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_christoffel) +static inline void gkyl_gr_spacetime_christoffel( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_christoffel +) { - return spacetime->spacetime_christoffel_func(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_christoffel); + return spacetime->spacetime_christoffel_func( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_christoffel + ); } -static inline void -gkyl_gr_spatial_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_riemann_tensor) +static inline void gkyl_gr_spatial_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double *****spatial_riemann_tensor +) { - return spacetime->spatial_riemann_tensor_func(spacetime, t, x, y, z, dx, dy, dz, spatial_riemann_tensor); + return spacetime->spatial_riemann_tensor_func( + spacetime, t, x, y, z, dx, dy, dz, spatial_riemann_tensor + ); } -static inline void -gkyl_gr_spacetime_riemann_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_riemann_tensor) +static inline void gkyl_gr_spacetime_riemann_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_riemann_tensor +) { - return spacetime->spacetime_riemann_tensor_func(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_riemann_tensor); + return spacetime->spacetime_riemann_tensor_func( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_riemann_tensor + ); } -static inline void -gkyl_gr_spatial_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** spatial_ricci_tensor) +static inline void gkyl_gr_spatial_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***spatial_ricci_tensor +) { - return spacetime->spatial_ricci_tensor_func(spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_tensor); + return spacetime->spatial_ricci_tensor_func( + spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_tensor + ); } -static inline void -gkyl_gr_spacetime_ricci_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double*** spacetime_ricci_tensor) +static inline void gkyl_gr_spacetime_ricci_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ***spacetime_ricci_tensor +) { - return spacetime->spacetime_ricci_tensor_func(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_tensor); + return spacetime->spacetime_ricci_tensor_func( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_tensor + ); } -static inline void -gkyl_gr_spatial_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double* spatial_ricci_scalar) +static inline void gkyl_gr_spatial_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *spatial_ricci_scalar +) { - return spacetime->spatial_ricci_scalar_func(spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_scalar); + return spacetime->spatial_ricci_scalar_func( + spacetime, t, x, y, z, dx, dy, dz, spatial_ricci_scalar + ); } -static inline void -gkyl_gr_spacetime_ricci_scalar(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double* spacetime_ricci_scalar) +static inline void gkyl_gr_spacetime_ricci_scalar( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *spacetime_ricci_scalar +) { - return spacetime->spacetime_ricci_scalar_func(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_scalar); + return spacetime->spacetime_ricci_scalar_func( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_ricci_scalar + ); } -static inline void -gkyl_gr_spatial_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_weyl_tensor) +static inline void gkyl_gr_spatial_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *****spatial_weyl_tensor +) { return spacetime->spatial_weyl_tensor_func(spacetime, t, x, y, z, dx, dy, dz, spatial_weyl_tensor); } -static inline void -gkyl_gr_spacetime_weyl_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_weyl_tensor) +static inline void gkyl_gr_spacetime_weyl_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_weyl_tensor +) { - return spacetime->spacetime_weyl_tensor_func(spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_weyl_tensor); + return spacetime->spacetime_weyl_tensor_func( + spacetime, t, x, y, z, dt, dx, dy, dz, spacetime_weyl_tensor + ); } -static inline void -gkyl_gr_extrinsic_curvature_tensor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** extrinsic_curvature_tensor) +static inline void gkyl_gr_extrinsic_curvature_tensor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***extrinsic_curvature_tensor +) { - return spacetime->extrinsic_curvature_tensor_func(spacetime, t, x, y, z, dx, dy, dz, extrinsic_curvature_tensor); + return spacetime->extrinsic_curvature_tensor_func( + spacetime, t, x, y, z, dx, dy, dz, extrinsic_curvature_tensor + ); } -static inline void -gkyl_gr_conformal_factor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* conformal_factor) +static inline void gkyl_gr_conformal_factor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *conformal_factor +) { return spacetime->conformal_factor_func(spacetime, t, x, y, z, conformal_factor); } -static inline void -gkyl_gr_bssn_conformal_factor(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - double* bssn_conformal_factor) +static inline void gkyl_gr_bssn_conformal_factor( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, double *bssn_conformal_factor +) { return spacetime->bssn_conformal_factor_func(spacetime, t, x, y, z, bssn_conformal_factor); } -static inline void -gkyl_gr_conformal_factor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** conformal_factor_der) +static inline void gkyl_gr_conformal_factor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **conformal_factor_der +) { - return spacetime->conformal_factor_der_func(spacetime, t, x, y, z, dx, dy, dz, conformal_factor_der); + return spacetime->conformal_factor_der_func( + spacetime, t, x, y, z, dx, dy, dz, conformal_factor_der + ); } -static inline void -gkyl_gr_bssn_conformal_factor_der(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** bssn_conformal_factor_der) +static inline void gkyl_gr_bssn_conformal_factor_der( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double **bssn_conformal_factor_der +) { - return spacetime->bssn_conformal_factor_der_func(spacetime, t, x, y, z, dx, dy, dz, bssn_conformal_factor_der); + return spacetime->bssn_conformal_factor_der_func( + spacetime, t, x, y, z, dx, dy, dz, bssn_conformal_factor_der + ); } -static inline void -gkyl_gr_conformal_factor_der2(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** conformal_factor_der2) +static inline void gkyl_gr_conformal_factor_der2( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***conformal_factor_der2 +) { - return spacetime->conformal_factor_der2_func(spacetime, t, x, y, z, dx, dy, dz, conformal_factor_der2); + return spacetime->conformal_factor_der2_func( + spacetime, t, x, y, z, dx, dy, dz, conformal_factor_der2 + ); } -static inline void -gkyl_gr_bssn_conformal_factor_der2(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** bssn_conformal_factor_der2) +static inline void gkyl_gr_bssn_conformal_factor_der2( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***bssn_conformal_factor_der2 +) { - return spacetime->bssn_conformal_factor_der2_func(spacetime, t, x, y, z, dx, dy, dz, bssn_conformal_factor_der2); + return spacetime->bssn_conformal_factor_der2_func( + spacetime, t, x, y, z, dx, dy, dz, bssn_conformal_factor_der2 + ); } -static inline void -gkyl_gr_excision_region(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - bool* in_excision_region) +static inline void gkyl_gr_excision_region( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, bool *in_excision_region +) { return spacetime->excision_region_func(spacetime, t, x, y, z, in_excision_region); } -bool -gkyl_gr_spacetime_is_cu_dev(const struct gkyl_gr_spacetime* spacetime) +bool gkyl_gr_spacetime_is_cu_dev(const struct gkyl_gr_spacetime *spacetime) { return GKYL_IS_CU_ALLOC(spacetime->flags); } -struct gkyl_gr_spacetime* -gkyl_gr_spacetime_acquire(const struct gkyl_gr_spacetime* spacetime) +struct gkyl_gr_spacetime *gkyl_gr_spacetime_acquire(const struct gkyl_gr_spacetime *spacetime) { gkyl_ref_count_inc(&spacetime->ref_count); - return (struct gkyl_gr_spacetime*) spacetime; + return (struct gkyl_gr_spacetime *)spacetime; } -void -gkyl_gr_spacetime_release(const struct gkyl_gr_spacetime* spacetime) +void gkyl_gr_spacetime_release(const struct gkyl_gr_spacetime *spacetime) { gkyl_ref_count_dec(&spacetime->ref_count); } \ No newline at end of file diff --git a/moments/zero/gr_spacetime_diff.c b/moments/zero/gr_spacetime_diff.c index 65cbb5d7d3..55e3dce029 100644 --- a/moments/zero/gr_spacetime_diff.c +++ b/moments/zero/gr_spacetime_diff.c @@ -5,17 +5,19 @@ #include #include -void -gkyl_gr_spatial_metric_tensor_diff(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_metric_tensor_diff) +void gkyl_gr_spatial_metric_tensor_diff( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ****spatial_metric_tensor_diff +) { - double **spatial_metric_x_forward = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_y_forward = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_z_forward = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_x_forward = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_y_forward = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_z_forward = gkyl_malloc(sizeof(double *[3])); - double **spatial_metric_x_backward = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_y_backward = gkyl_malloc(sizeof(double*[3])); - double **spatial_metric_z_backward = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_x_backward = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_y_backward = gkyl_malloc(sizeof(double *[3])); + double **spatial_metric_z_backward = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_x_forward[i] = gkyl_malloc(sizeof(double[3])); @@ -27,19 +29,34 @@ gkyl_gr_spatial_metric_tensor_diff(const struct gkyl_gr_spacetime* spacetime, co spatial_metric_z_backward[i] = gkyl_malloc(sizeof(double[3])); } - spacetime->spatial_metric_tensor_func(spacetime, t, x + (0.5 * dx), y, z, &spatial_metric_x_forward); - spacetime->spatial_metric_tensor_func(spacetime, t, x, y + (0.5 * dy), z, &spatial_metric_y_forward); - spacetime->spatial_metric_tensor_func(spacetime, t, x, y, z + (0.5 * dz), &spatial_metric_z_forward); - - spacetime->spatial_metric_tensor_func(spacetime, t, x - (0.5 * dx), y, z, &spatial_metric_x_backward); - spacetime->spatial_metric_tensor_func(spacetime, t, x, y - (0.5 * dy), z, &spatial_metric_y_backward); - spacetime->spatial_metric_tensor_func(spacetime, t, x, y, z - (0.5 * dz), &spatial_metric_z_backward); + spacetime->spatial_metric_tensor_func( + spacetime, t, x + (0.5 * dx), y, z, &spatial_metric_x_forward + ); + spacetime->spatial_metric_tensor_func( + spacetime, t, x, y + (0.5 * dy), z, &spatial_metric_y_forward + ); + spacetime->spatial_metric_tensor_func( + spacetime, t, x, y, z + (0.5 * dz), &spatial_metric_z_forward + ); + + spacetime->spatial_metric_tensor_func( + spacetime, t, x - (0.5 * dx), y, z, &spatial_metric_x_backward + ); + spacetime->spatial_metric_tensor_func( + spacetime, t, x, y - (0.5 * dy), z, &spatial_metric_y_backward + ); + spacetime->spatial_metric_tensor_func( + spacetime, t, x, y, z - (0.5 * dz), &spatial_metric_z_backward + ); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*spatial_metric_tensor_diff)[0][i][j] = (1.0 / dx) * (spatial_metric_x_forward[i][j] - spatial_metric_x_backward[i][j]); - (*spatial_metric_tensor_diff)[1][i][j] = (1.0 / dy) * (spatial_metric_y_forward[i][j] - spatial_metric_y_backward[i][j]); - (*spatial_metric_tensor_diff)[2][i][j] = (1.0 / dz) * (spatial_metric_z_forward[i][j] - spatial_metric_z_backward[i][j]); + (*spatial_metric_tensor_diff)[0][i][j] = + (1.0 / dx) * (spatial_metric_x_forward[i][j] - spatial_metric_x_backward[i][j]); + (*spatial_metric_tensor_diff)[1][i][j] = + (1.0 / dy) * (spatial_metric_y_forward[i][j] - spatial_metric_y_backward[i][j]); + (*spatial_metric_tensor_diff)[2][i][j] = + (1.0 / dz) * (spatial_metric_z_forward[i][j] - spatial_metric_z_backward[i][j]); } } @@ -61,48 +78,70 @@ gkyl_gr_spatial_metric_tensor_diff(const struct gkyl_gr_spacetime* spacetime, co gkyl_free(spatial_metric_z_backward); } -void -gkyl_gr_spacetime_metric_tensor_diff(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_metric_tensor_diff) +void gkyl_gr_spacetime_metric_tensor_diff( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_metric_tensor_diff +) { - double **spacetime_metric_t_forward = gkyl_malloc(sizeof(double*[4])); - double **spacetime_metric_x_forward = gkyl_malloc(sizeof(double*[4])); - double **spacetime_metric_y_forward = gkyl_malloc(sizeof(double*[4])); - double **spacetime_metric_z_forward = gkyl_malloc(sizeof(double*[4])); + double **spacetime_metric_t_forward = gkyl_malloc(sizeof(double *[4])); + double **spacetime_metric_x_forward = gkyl_malloc(sizeof(double *[4])); + double **spacetime_metric_y_forward = gkyl_malloc(sizeof(double *[4])); + double **spacetime_metric_z_forward = gkyl_malloc(sizeof(double *[4])); - double **spacetime_metric_t_backward = gkyl_malloc(sizeof(double*[4])); - double **spacetime_metric_x_backward = gkyl_malloc(sizeof(double*[4])); - double **spacetime_metric_y_backward = gkyl_malloc(sizeof(double*[4])); - double **spacetime_metric_z_backward = gkyl_malloc(sizeof(double*[4])); + double **spacetime_metric_t_backward = gkyl_malloc(sizeof(double *[4])); + double **spacetime_metric_x_backward = gkyl_malloc(sizeof(double *[4])); + double **spacetime_metric_y_backward = gkyl_malloc(sizeof(double *[4])); + double **spacetime_metric_z_backward = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_metric_t_forward[i] = gkyl_malloc(sizeof(double[4])); spacetime_metric_x_forward[i] = gkyl_malloc(sizeof(double[4])); spacetime_metric_y_forward[i] = gkyl_malloc(sizeof(double[4])); spacetime_metric_z_forward[i] = gkyl_malloc(sizeof(double[4])); - + spacetime_metric_t_backward[i] = gkyl_malloc(sizeof(double[4])); spacetime_metric_x_backward[i] = gkyl_malloc(sizeof(double[4])); spacetime_metric_y_backward[i] = gkyl_malloc(sizeof(double[4])); spacetime_metric_z_backward[i] = gkyl_malloc(sizeof(double[4])); } - spacetime->spacetime_metric_tensor_func(spacetime, t + (0.5 * dt), x, y, z, &spacetime_metric_t_forward); - spacetime->spacetime_metric_tensor_func(spacetime, t, x + (0.5 * dx), y, z, &spacetime_metric_x_forward); - spacetime->spacetime_metric_tensor_func(spacetime, t, x, y + (0.5 * dy), z, &spacetime_metric_y_forward); - spacetime->spacetime_metric_tensor_func(spacetime, t, x, y, z + (0.5 * dz), &spacetime_metric_z_forward); - - spacetime->spacetime_metric_tensor_func(spacetime, t - (0.5 * dt), x, y, z, &spacetime_metric_t_backward); - spacetime->spacetime_metric_tensor_func(spacetime, t, x - (0.5 * dx), y, z, &spacetime_metric_x_backward); - spacetime->spacetime_metric_tensor_func(spacetime, t, x, y - (0.5 * dy), z, &spacetime_metric_y_backward); - spacetime->spacetime_metric_tensor_func(spacetime, t, x, y, z - (0.5 * dz), &spacetime_metric_z_backward); + spacetime->spacetime_metric_tensor_func( + spacetime, t + (0.5 * dt), x, y, z, &spacetime_metric_t_forward + ); + spacetime->spacetime_metric_tensor_func( + spacetime, t, x + (0.5 * dx), y, z, &spacetime_metric_x_forward + ); + spacetime->spacetime_metric_tensor_func( + spacetime, t, x, y + (0.5 * dy), z, &spacetime_metric_y_forward + ); + spacetime->spacetime_metric_tensor_func( + spacetime, t, x, y, z + (0.5 * dz), &spacetime_metric_z_forward + ); + + spacetime->spacetime_metric_tensor_func( + spacetime, t - (0.5 * dt), x, y, z, &spacetime_metric_t_backward + ); + spacetime->spacetime_metric_tensor_func( + spacetime, t, x - (0.5 * dx), y, z, &spacetime_metric_x_backward + ); + spacetime->spacetime_metric_tensor_func( + spacetime, t, x, y - (0.5 * dy), z, &spacetime_metric_y_backward + ); + spacetime->spacetime_metric_tensor_func( + spacetime, t, x, y, z - (0.5 * dz), &spacetime_metric_z_backward + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*spacetime_metric_tensor_diff)[0][i][j] = (1.0 / dt) * (spacetime_metric_t_forward[i][j] - spacetime_metric_t_backward[i][j]); - (*spacetime_metric_tensor_diff)[1][i][j] = (1.0 / dx) * (spacetime_metric_x_forward[i][j] - spacetime_metric_x_backward[i][j]); - (*spacetime_metric_tensor_diff)[2][i][j] = (1.0 / dy) * (spacetime_metric_y_forward[i][j] - spacetime_metric_y_backward[i][j]); - (*spacetime_metric_tensor_diff)[3][i][j] = (1.0 / dz) * (spacetime_metric_z_forward[i][j] - spacetime_metric_z_backward[i][j]); + (*spacetime_metric_tensor_diff)[0][i][j] = + (1.0 / dt) * (spacetime_metric_t_forward[i][j] - spacetime_metric_t_backward[i][j]); + (*spacetime_metric_tensor_diff)[1][i][j] = + (1.0 / dx) * (spacetime_metric_x_forward[i][j] - spacetime_metric_x_backward[i][j]); + (*spacetime_metric_tensor_diff)[2][i][j] = + (1.0 / dy) * (spacetime_metric_y_forward[i][j] - spacetime_metric_y_backward[i][j]); + (*spacetime_metric_tensor_diff)[3][i][j] = + (1.0 / dz) * (spacetime_metric_z_forward[i][j] - spacetime_metric_z_backward[i][j]); } } @@ -128,9 +167,10 @@ gkyl_gr_spacetime_metric_tensor_diff(const struct gkyl_gr_spacetime* spacetime, gkyl_free(spacetime_metric_z_backward); } -void -gkyl_gr_lapse_function_diff(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** lapse_function_diff) +void gkyl_gr_lapse_function_diff( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **lapse_function_diff +) { double lapse_function_x_forward; double lapse_function_y_forward; @@ -153,17 +193,18 @@ gkyl_gr_lapse_function_diff(const struct gkyl_gr_spacetime* spacetime, const dou (*lapse_function_diff)[2] = (1.0 / dz) * (lapse_function_z_forward - lapse_function_z_backward); } -void -gkyl_gr_shift_vector_diff(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** shift_vector_diff) +void gkyl_gr_shift_vector_diff( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***shift_vector_diff +) { - double* shift_vector_x_forward = gkyl_malloc(sizeof(double[3])); - double* shift_vector_y_forward = gkyl_malloc(sizeof(double[3])); - double* shift_vector_z_forward = gkyl_malloc(sizeof(double[3])); - - double* shift_vector_x_backward = gkyl_malloc(sizeof(double[3])); - double* shift_vector_y_backward = gkyl_malloc(sizeof(double[3])); - double* shift_vector_z_backward = gkyl_malloc(sizeof(double[3])); + double *shift_vector_x_forward = gkyl_malloc(sizeof(double[3])); + double *shift_vector_y_forward = gkyl_malloc(sizeof(double[3])); + double *shift_vector_z_forward = gkyl_malloc(sizeof(double[3])); + + double *shift_vector_x_backward = gkyl_malloc(sizeof(double[3])); + double *shift_vector_y_backward = gkyl_malloc(sizeof(double[3])); + double *shift_vector_z_backward = gkyl_malloc(sizeof(double[3])); spacetime->shift_vector_func(spacetime, t, x + (0.5 * dx), y, z, &shift_vector_x_forward); spacetime->shift_vector_func(spacetime, t, x, y + (0.5 * dy), z, &shift_vector_y_forward); @@ -172,11 +213,14 @@ gkyl_gr_shift_vector_diff(const struct gkyl_gr_spacetime* spacetime, const doubl spacetime->shift_vector_func(spacetime, t, x - (0.5 * dx), y, z, &shift_vector_x_backward); spacetime->shift_vector_func(spacetime, t, x, y - (0.5 * dy), z, &shift_vector_y_backward); spacetime->shift_vector_func(spacetime, t, x, y, z - (0.5 * dz), &shift_vector_z_backward); - + for (int i = 0; i < 3; i++) { - (*shift_vector_diff)[0][i] = (1.0 / dx) * (shift_vector_x_forward[i] - shift_vector_x_backward[i]); - (*shift_vector_diff)[1][i] = (1.0 / dy) * (shift_vector_y_forward[i] - shift_vector_y_backward[i]); - (*shift_vector_diff)[2][i] = (1.0 / dz) * (shift_vector_z_forward[i] - shift_vector_z_backward[i]); + (*shift_vector_diff)[0][i] = + (1.0 / dx) * (shift_vector_x_forward[i] - shift_vector_x_backward[i]); + (*shift_vector_diff)[1][i] = + (1.0 / dy) * (shift_vector_y_forward[i] - shift_vector_y_backward[i]); + (*shift_vector_diff)[2][i] = + (1.0 / dz) * (shift_vector_z_forward[i] - shift_vector_z_backward[i]); } gkyl_free(shift_vector_x_forward); @@ -188,18 +232,19 @@ gkyl_gr_shift_vector_diff(const struct gkyl_gr_spacetime* spacetime, const doubl gkyl_free(shift_vector_z_backward); } -void -gkyl_gr_spatial_christoffel_fd(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double**** spatial_christoffel) +void gkyl_gr_spatial_christoffel_fd( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ****spatial_christoffel +) { - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -210,7 +255,7 @@ gkyl_gr_spatial_christoffel_fd(const struct gkyl_gr_spacetime* spacetime, const spacetime->spatial_metric_tensor_der_func(spacetime, t, x, y, z, dx, dy, dz, &spatial_metric_der); for (int i = 0; i < 3; i++) { - for (int j = 0 ; j < 3; j++) { + for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { (*spatial_christoffel)[i][j][k] = 0.0; } @@ -221,8 +266,10 @@ gkyl_gr_spatial_christoffel_fd(const struct gkyl_gr_spacetime* spacetime, const for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - (*spatial_christoffel)[i][j][k] += (0.5 * inv_spatial_metric[i][l]) * (spatial_metric_der[k][l][j] + spatial_metric_der[j][l][k] - - spatial_metric_der[l][j][k]); + (*spatial_christoffel)[i][j][k] += + (0.5 * inv_spatial_metric[i][l]) * + (spatial_metric_der[k][l][j] + spatial_metric_der[j][l][k] - spatial_metric_der[l][j][k] + ); } } } @@ -240,18 +287,20 @@ gkyl_gr_spatial_christoffel_fd(const struct gkyl_gr_spacetime* spacetime, const gkyl_free(spatial_metric_der); } -void -gkyl_gr_spacetime_christoffel_fd(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double**** spacetime_christoffel) +void gkyl_gr_spacetime_christoffel_fd( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ****spacetime_christoffel +) { - double **inv_spacetime_metric = gkyl_malloc(sizeof(double*[4])); + double **inv_spacetime_metric = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { inv_spacetime_metric[i] = gkyl_malloc(sizeof(double[4])); } - double ***spacetime_metric_der = gkyl_malloc(sizeof(double**[4])); + double ***spacetime_metric_der = gkyl_malloc(sizeof(double **[4])); for (int i = 0; i < 4; i++) { - spacetime_metric_der[i] = gkyl_malloc(sizeof(double*[4])); + spacetime_metric_der[i] = gkyl_malloc(sizeof(double *[4])); for (int j = 0; j < 4; j++) { spacetime_metric_der[i][j] = gkyl_malloc(sizeof(double[4])); @@ -259,7 +308,9 @@ gkyl_gr_spacetime_christoffel_fd(const struct gkyl_gr_spacetime* spacetime, cons } spacetime->spacetime_inv_metric_tensor_func(spacetime, t, x, y, z, &inv_spacetime_metric); - spacetime->spacetime_metric_tensor_der_func(spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_metric_der); + spacetime->spacetime_metric_tensor_der_func( + spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_metric_der + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -273,8 +324,10 @@ gkyl_gr_spacetime_christoffel_fd(const struct gkyl_gr_spacetime* spacetime, cons for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { - (*spacetime_christoffel)[i][j][k] += (0.5 * inv_spacetime_metric[i][l]) * (spacetime_metric_der[k][l][j] + spacetime_metric_der[j][l][k] - - spacetime_metric_der[l][j][k]); + (*spacetime_christoffel)[i][j][k] += + (0.5 * inv_spacetime_metric[i][l]) * + (spacetime_metric_der[k][l][j] + spacetime_metric_der[j][l][k] - + spacetime_metric_der[l][j][k]); } } } @@ -292,28 +345,30 @@ gkyl_gr_spacetime_christoffel_fd(const struct gkyl_gr_spacetime* spacetime, cons gkyl_free(spacetime_metric_der); } -void -gkyl_gr_spatial_riemann_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_riemann_tensor) +void gkyl_gr_spatial_riemann_tensor_fd( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double *****spatial_riemann_tensor +) { - double ***spatial_christoffel = gkyl_malloc(sizeof(double**[3])); - double ***spatial_christoffel_x_forward = gkyl_malloc(sizeof(double**[3])); - double ***spatial_christoffel_y_forward = gkyl_malloc(sizeof(double**[3])); - double ***spatial_christoffel_z_forward = gkyl_malloc(sizeof(double**[3])); + double ***spatial_christoffel = gkyl_malloc(sizeof(double **[3])); + double ***spatial_christoffel_x_forward = gkyl_malloc(sizeof(double **[3])); + double ***spatial_christoffel_y_forward = gkyl_malloc(sizeof(double **[3])); + double ***spatial_christoffel_z_forward = gkyl_malloc(sizeof(double **[3])); - double ***spatial_christoffel_x_backward = gkyl_malloc(sizeof(double**[3])); - double ***spatial_christoffel_y_backward = gkyl_malloc(sizeof(double**[3])); - double ***spatial_christoffel_z_backward = gkyl_malloc(sizeof(double**[3])); + double ***spatial_christoffel_x_backward = gkyl_malloc(sizeof(double **[3])); + double ***spatial_christoffel_y_backward = gkyl_malloc(sizeof(double **[3])); + double ***spatial_christoffel_z_backward = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_christoffel[i] = gkyl_malloc(sizeof(double*[3])); - spatial_christoffel_x_forward[i] = gkyl_malloc(sizeof(double*[3])); - spatial_christoffel_y_forward[i] = gkyl_malloc(sizeof(double*[3])); - spatial_christoffel_z_forward[i] = gkyl_malloc(sizeof(double*[3])); + spatial_christoffel[i] = gkyl_malloc(sizeof(double *[3])); + spatial_christoffel_x_forward[i] = gkyl_malloc(sizeof(double *[3])); + spatial_christoffel_y_forward[i] = gkyl_malloc(sizeof(double *[3])); + spatial_christoffel_z_forward[i] = gkyl_malloc(sizeof(double *[3])); - spatial_christoffel_x_backward[i] = gkyl_malloc(sizeof(double*[3])); - spatial_christoffel_y_backward[i] = gkyl_malloc(sizeof(double*[3])); - spatial_christoffel_z_backward[i] = gkyl_malloc(sizeof(double*[3])); + spatial_christoffel_x_backward[i] = gkyl_malloc(sizeof(double *[3])); + spatial_christoffel_y_backward[i] = gkyl_malloc(sizeof(double *[3])); + spatial_christoffel_z_backward[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_christoffel[i][j] = gkyl_malloc(sizeof(double[3])); @@ -326,22 +381,34 @@ gkyl_gr_spatial_riemann_tensor_fd(const struct gkyl_gr_spacetime* spacetime, con spatial_christoffel_z_backward[i][j] = gkyl_malloc(sizeof(double[3])); } } - - spacetime->spatial_christoffel_func(spacetime, t, x, y, z, dx, dy, dz, &spatial_christoffel); - spacetime->spatial_christoffel_func(spacetime, t, x + (0.5 * dx), y, z, dx, dy, dz, &spatial_christoffel_x_forward); - spacetime->spatial_christoffel_func(spacetime, t, x, y + (0.5 * dy), z, dx, dy, dz, &spatial_christoffel_y_forward); - spacetime->spatial_christoffel_func(spacetime, t, x, y, z + (0.5 * dz), dx, dy, dz, &spatial_christoffel_z_forward); - - spacetime->spatial_christoffel_func(spacetime, t, x - (0.5 * dx), y, z, dx, dy, dz, &spatial_christoffel_x_backward); - spacetime->spatial_christoffel_func(spacetime, t, x, y - (0.5 * dy), z, dx, dy, dz, &spatial_christoffel_y_backward); - spacetime->spatial_christoffel_func(spacetime, t, x, y, z - (0.5 * dz), dx, dy, dz, &spatial_christoffel_z_backward); - double ****spatial_christoffel_der = gkyl_malloc(sizeof(double***[3])); + spacetime->spatial_christoffel_func(spacetime, t, x, y, z, dx, dy, dz, &spatial_christoffel); + spacetime->spatial_christoffel_func( + spacetime, t, x + (0.5 * dx), y, z, dx, dy, dz, &spatial_christoffel_x_forward + ); + spacetime->spatial_christoffel_func( + spacetime, t, x, y + (0.5 * dy), z, dx, dy, dz, &spatial_christoffel_y_forward + ); + spacetime->spatial_christoffel_func( + spacetime, t, x, y, z + (0.5 * dz), dx, dy, dz, &spatial_christoffel_z_forward + ); + + spacetime->spatial_christoffel_func( + spacetime, t, x - (0.5 * dx), y, z, dx, dy, dz, &spatial_christoffel_x_backward + ); + spacetime->spatial_christoffel_func( + spacetime, t, x, y - (0.5 * dy), z, dx, dy, dz, &spatial_christoffel_y_backward + ); + spacetime->spatial_christoffel_func( + spacetime, t, x, y, z - (0.5 * dz), dx, dy, dz, &spatial_christoffel_z_backward + ); + + double ****spatial_christoffel_der = gkyl_malloc(sizeof(double ***[3])); for (int i = 0; i < 3; i++) { - spatial_christoffel_der[i] = gkyl_malloc(sizeof(double**[3])); + spatial_christoffel_der[i] = gkyl_malloc(sizeof(double **[3])); for (int j = 0; j < 3; j++) { - spatial_christoffel_der[i][j] = gkyl_malloc(sizeof(double*[3])); + spatial_christoffel_der[i][j] = gkyl_malloc(sizeof(double *[3])); for (int k = 0; k < 3; k++) { spatial_christoffel_der[i][j][k] = gkyl_malloc(sizeof(double[3])); @@ -352,9 +419,15 @@ gkyl_gr_spatial_riemann_tensor_fd(const struct gkyl_gr_spacetime* spacetime, con for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { - spatial_christoffel_der[0][i][j][k] = (1.0 / dx) * (spatial_christoffel_x_forward[i][j][k] - spatial_christoffel_x_backward[i][j][k]); - spatial_christoffel_der[1][i][j][k] = (1.0 / dy) * (spatial_christoffel_y_forward[i][j][k] - spatial_christoffel_y_backward[i][j][k]); - spatial_christoffel_der[2][i][j][k] = (1.0 / dz) * (spatial_christoffel_z_forward[i][j][k] - spatial_christoffel_z_backward[i][j][k]); + spatial_christoffel_der[0][i][j][k] = + (1.0 / dx) * + (spatial_christoffel_x_forward[i][j][k] - spatial_christoffel_x_backward[i][j][k]); + spatial_christoffel_der[1][i][j][k] = + (1.0 / dy) * + (spatial_christoffel_y_forward[i][j][k] - spatial_christoffel_y_backward[i][j][k]); + spatial_christoffel_der[2][i][j][k] = + (1.0 / dz) * + (spatial_christoffel_z_forward[i][j][k] - spatial_christoffel_z_backward[i][j][k]); } } } @@ -363,11 +436,14 @@ gkyl_gr_spatial_riemann_tensor_fd(const struct gkyl_gr_spacetime* spacetime, con for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - (*spatial_riemann_tensor)[i][j][k][l] = spatial_christoffel_der[k][i][l][j] - spatial_christoffel_der[l][i][k][j]; + (*spatial_riemann_tensor)[i][j][k][l] = + spatial_christoffel_der[k][i][l][j] - spatial_christoffel_der[l][i][k][j]; for (int m = 0; m < 3; m++) { - (*spatial_riemann_tensor)[i][j][k][l] += (spatial_christoffel[i][k][m] * spatial_christoffel[m][l][j]); - (*spatial_riemann_tensor)[i][j][k][l] -= (spatial_christoffel[i][l][m] * spatial_christoffel[m][k][j]); + (*spatial_riemann_tensor)[i][j][k][l] += + (spatial_christoffel[i][k][m] * spatial_christoffel[m][l][j]); + (*spatial_riemann_tensor)[i][j][k][l] -= + (spatial_christoffel[i][l][m] * spatial_christoffel[m][k][j]); } } } @@ -410,32 +486,34 @@ gkyl_gr_spatial_riemann_tensor_fd(const struct gkyl_gr_spacetime* spacetime, con gkyl_free(spatial_christoffel_z_backward); } -void -gkyl_gr_spacetime_riemann_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_riemann_tensor) +void gkyl_gr_spacetime_riemann_tensor_fd( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_riemann_tensor +) { - double ***spacetime_christoffel = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel_t_forward = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel_x_forward = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel_y_forward = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel_z_forward = gkyl_malloc(sizeof(double**[4])); + double ***spacetime_christoffel = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel_t_forward = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel_x_forward = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel_y_forward = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel_z_forward = gkyl_malloc(sizeof(double **[4])); - double ***spacetime_christoffel_t_backward = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel_x_backward = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel_y_backward = gkyl_malloc(sizeof(double**[4])); - double ***spacetime_christoffel_z_backward = gkyl_malloc(sizeof(double**[4])); + double ***spacetime_christoffel_t_backward = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel_x_backward = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel_y_backward = gkyl_malloc(sizeof(double **[4])); + double ***spacetime_christoffel_z_backward = gkyl_malloc(sizeof(double **[4])); for (int i = 0; i < 4; i++) { - spacetime_christoffel[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel_t_forward[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel_x_forward[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel_y_forward[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel_z_forward[i] = gkyl_malloc(sizeof(double*[4])); + spacetime_christoffel[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel_t_forward[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel_x_forward[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel_y_forward[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel_z_forward[i] = gkyl_malloc(sizeof(double *[4])); - spacetime_christoffel_t_backward[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel_x_backward[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel_y_backward[i] = gkyl_malloc(sizeof(double*[4])); - spacetime_christoffel_z_backward[i] = gkyl_malloc(sizeof(double*[4])); + spacetime_christoffel_t_backward[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel_x_backward[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel_y_backward[i] = gkyl_malloc(sizeof(double *[4])); + spacetime_christoffel_z_backward[i] = gkyl_malloc(sizeof(double *[4])); for (int j = 0; j < 4; j++) { spacetime_christoffel[i][j] = gkyl_malloc(sizeof(double[4])); @@ -451,23 +529,41 @@ gkyl_gr_spacetime_riemann_tensor_fd(const struct gkyl_gr_spacetime* spacetime, c } } - spacetime->spacetime_christoffel_func(spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_christoffel); - spacetime->spacetime_christoffel_func(spacetime, t + (0.5 * dt), x, y, z, dt, dx, dy, dz, &spacetime_christoffel_t_forward); - spacetime->spacetime_christoffel_func(spacetime, t, x + (0.5 * dx), y, z, dt, dx, dy, dz, &spacetime_christoffel_x_forward); - spacetime->spacetime_christoffel_func(spacetime, t, x, y + (0.5 * dy), z, dt, dx, dy, dz, &spacetime_christoffel_y_forward); - spacetime->spacetime_christoffel_func(spacetime, t, x, y, z + (0.5 * dz), dt, dx, dy, dz, &spacetime_christoffel_z_forward); - - spacetime->spacetime_christoffel_func(spacetime, t - (0.5 * dt), x, y, z, dt, dx, dy, dz, &spacetime_christoffel_t_backward); - spacetime->spacetime_christoffel_func(spacetime, t, x - (0.5 * dx), y, z, dt, dx, dy, dz, &spacetime_christoffel_x_backward); - spacetime->spacetime_christoffel_func(spacetime, t, x, y - (0.5 * dy), z, dt, dx, dy, dz, &spacetime_christoffel_y_backward); - spacetime->spacetime_christoffel_func(spacetime, t, x, y, z - (0.5 * dz), dt, dx, dy, dz, &spacetime_christoffel_z_backward); - - double ****spacetime_christoffel_der = gkyl_malloc(sizeof(double***[4])); + spacetime->spacetime_christoffel_func( + spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_christoffel + ); + spacetime->spacetime_christoffel_func( + spacetime, t + (0.5 * dt), x, y, z, dt, dx, dy, dz, &spacetime_christoffel_t_forward + ); + spacetime->spacetime_christoffel_func( + spacetime, t, x + (0.5 * dx), y, z, dt, dx, dy, dz, &spacetime_christoffel_x_forward + ); + spacetime->spacetime_christoffel_func( + spacetime, t, x, y + (0.5 * dy), z, dt, dx, dy, dz, &spacetime_christoffel_y_forward + ); + spacetime->spacetime_christoffel_func( + spacetime, t, x, y, z + (0.5 * dz), dt, dx, dy, dz, &spacetime_christoffel_z_forward + ); + + spacetime->spacetime_christoffel_func( + spacetime, t - (0.5 * dt), x, y, z, dt, dx, dy, dz, &spacetime_christoffel_t_backward + ); + spacetime->spacetime_christoffel_func( + spacetime, t, x - (0.5 * dx), y, z, dt, dx, dy, dz, &spacetime_christoffel_x_backward + ); + spacetime->spacetime_christoffel_func( + spacetime, t, x, y - (0.5 * dy), z, dt, dx, dy, dz, &spacetime_christoffel_y_backward + ); + spacetime->spacetime_christoffel_func( + spacetime, t, x, y, z - (0.5 * dz), dt, dx, dy, dz, &spacetime_christoffel_z_backward + ); + + double ****spacetime_christoffel_der = gkyl_malloc(sizeof(double ***[4])); for (int i = 0; i < 4; i++) { - spacetime_christoffel_der[i] = gkyl_malloc(sizeof(double**[4])); + spacetime_christoffel_der[i] = gkyl_malloc(sizeof(double **[4])); for (int j = 0; j < 4; j++) { - spacetime_christoffel_der[i][j] = gkyl_malloc(sizeof(double*[4])); + spacetime_christoffel_der[i][j] = gkyl_malloc(sizeof(double *[4])); for (int k = 0; k < 4; k++) { spacetime_christoffel_der[i][j][k] = gkyl_malloc(sizeof(double[4])); @@ -478,10 +574,18 @@ gkyl_gr_spacetime_riemann_tensor_fd(const struct gkyl_gr_spacetime* spacetime, c for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { - spacetime_christoffel_der[0][i][j][k] = (1.0 / dt) * (spacetime_christoffel_t_forward[i][j][k] - spacetime_christoffel_t_backward[i][j][k]); - spacetime_christoffel_der[1][i][j][k] = (1.0 / dx) * (spacetime_christoffel_x_forward[i][j][k] - spacetime_christoffel_x_backward[i][j][k]); - spacetime_christoffel_der[2][i][j][k] = (1.0 / dy) * (spacetime_christoffel_y_forward[i][j][k] - spacetime_christoffel_y_backward[i][j][k]); - spacetime_christoffel_der[3][i][j][k] = (1.0 / dz) * (spacetime_christoffel_z_forward[i][j][k] - spacetime_christoffel_z_backward[i][j][k]); + spacetime_christoffel_der[0][i][j][k] = + (1.0 / dt) * + (spacetime_christoffel_t_forward[i][j][k] - spacetime_christoffel_t_backward[i][j][k]); + spacetime_christoffel_der[1][i][j][k] = + (1.0 / dx) * + (spacetime_christoffel_x_forward[i][j][k] - spacetime_christoffel_x_backward[i][j][k]); + spacetime_christoffel_der[2][i][j][k] = + (1.0 / dy) * + (spacetime_christoffel_y_forward[i][j][k] - spacetime_christoffel_y_backward[i][j][k]); + spacetime_christoffel_der[3][i][j][k] = + (1.0 / dz) * + (spacetime_christoffel_z_forward[i][j][k] - spacetime_christoffel_z_backward[i][j][k]); } } } @@ -490,11 +594,14 @@ gkyl_gr_spacetime_riemann_tensor_fd(const struct gkyl_gr_spacetime* spacetime, c for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { - (*spacetime_riemann_tensor)[i][j][k][l] = spacetime_christoffel_der[k][i][l][j] - spacetime_christoffel_der[l][i][k][j]; + (*spacetime_riemann_tensor)[i][j][k][l] = + spacetime_christoffel_der[k][i][l][j] - spacetime_christoffel_der[l][i][k][j]; for (int m = 0; m < 4; m++) { - (*spacetime_riemann_tensor)[i][j][k][l] += (spacetime_christoffel[i][k][m] * spacetime_christoffel[m][l][j]); - (*spacetime_riemann_tensor)[i][j][k][l] -= (spacetime_christoffel[i][l][m] * spacetime_christoffel[m][k][j]); + (*spacetime_riemann_tensor)[i][j][k][l] += + (spacetime_christoffel[i][k][m] * spacetime_christoffel[m][l][j]); + (*spacetime_riemann_tensor)[i][j][k][l] -= + (spacetime_christoffel[i][l][m] * spacetime_christoffel[m][k][j]); } } } @@ -543,16 +650,17 @@ gkyl_gr_spacetime_riemann_tensor_fd(const struct gkyl_gr_spacetime* spacetime, c gkyl_free(spacetime_christoffel_z_backward); } -void -gkyl_gr_spatial_ricci_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** spatial_ricci_tensor) +void gkyl_gr_spatial_ricci_tensor_fd( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double ***spatial_ricci_tensor +) { - double ****spatial_riemann_tensor = gkyl_malloc(sizeof(double***[3])); + double ****spatial_riemann_tensor = gkyl_malloc(sizeof(double ***[3])); for (int i = 0; i < 3; i++) { - spatial_riemann_tensor[i] = gkyl_malloc(sizeof(double**[3])); + spatial_riemann_tensor[i] = gkyl_malloc(sizeof(double **[3])); for (int j = 0; j < 3; j++) { - spatial_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[3])); + spatial_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[3])); for (int k = 0; k < 3; k++) { spatial_riemann_tensor[i][j][k] = gkyl_malloc(sizeof(double[3])); @@ -577,7 +685,7 @@ gkyl_gr_spatial_ricci_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const for (int k = 0; k < 3; k++) { gkyl_free(spatial_riemann_tensor[i][j][k]); } - + gkyl_free(spatial_riemann_tensor[i][j]); } @@ -587,16 +695,18 @@ gkyl_gr_spatial_ricci_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const gkyl_free(spatial_riemann_tensor); } -void -gkyl_gr_spacetime_ricci_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double*** spacetime_ricci_tensor) +void gkyl_gr_spacetime_ricci_tensor_fd( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double ***spacetime_ricci_tensor +) { - double ****spacetime_riemann_tensor = gkyl_malloc(sizeof(double***[4])); + double ****spacetime_riemann_tensor = gkyl_malloc(sizeof(double ***[4])); for (int i = 0; i < 4; i++) { - spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double**[4])); + spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double **[4])); for (int j = 0; j < 4; j++) { - spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[4])); + spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[4])); for (int k = 0; k < 4; k++) { spacetime_riemann_tensor[i][j][k] = gkyl_malloc(sizeof(double[4])); @@ -604,7 +714,9 @@ gkyl_gr_spacetime_ricci_tensor_fd(const struct gkyl_gr_spacetime* spacetime, con } } - spacetime->spacetime_riemann_tensor_func(spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_riemann_tensor); + spacetime->spacetime_riemann_tensor_func( + spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_riemann_tensor + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -621,7 +733,7 @@ gkyl_gr_spacetime_ricci_tensor_fd(const struct gkyl_gr_spacetime* spacetime, con for (int k = 0; k < 4; k++) { gkyl_free(spacetime_riemann_tensor[i][j][k]); } - + gkyl_free(spacetime_riemann_tensor[i][j]); } @@ -631,13 +743,14 @@ gkyl_gr_spacetime_ricci_tensor_fd(const struct gkyl_gr_spacetime* spacetime, con gkyl_free(spacetime_riemann_tensor); } -void -gkyl_gr_spatial_ricci_scalar_fd(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double* spatial_ricci_scalar) +void gkyl_gr_spatial_ricci_scalar_fd( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *spatial_ricci_scalar +) { - double **spatial_inv_metric_tensor = gkyl_malloc(sizeof(double*[3])); - double **spatial_ricci_tensor = gkyl_malloc(sizeof(double*[3])); - + double **spatial_inv_metric_tensor = gkyl_malloc(sizeof(double *[3])); + double **spatial_ricci_tensor = gkyl_malloc(sizeof(double *[3])); + for (int i = 0; i < 3; i++) { spatial_inv_metric_tensor[i] = gkyl_malloc(sizeof(double[3])); spatial_ricci_tensor[i] = gkyl_malloc(sizeof(double[3])); @@ -663,20 +776,24 @@ gkyl_gr_spatial_ricci_scalar_fd(const struct gkyl_gr_spacetime* spacetime, const gkyl_free(spatial_ricci_tensor); } -void -gkyl_gr_spacetime_ricci_scalar_fd(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double* spacetime_ricci_scalar) +void gkyl_gr_spacetime_ricci_scalar_fd( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *spacetime_ricci_scalar +) { - double **spacetime_inv_metric_tensor = gkyl_malloc(sizeof(double*[4])); - double **spacetime_ricci_tensor = gkyl_malloc(sizeof(double*[4])); - + double **spacetime_inv_metric_tensor = gkyl_malloc(sizeof(double *[4])); + double **spacetime_ricci_tensor = gkyl_malloc(sizeof(double *[4])); + for (int i = 0; i < 4; i++) { spacetime_inv_metric_tensor[i] = gkyl_malloc(sizeof(double[4])); spacetime_ricci_tensor[i] = gkyl_malloc(sizeof(double[4])); } spacetime->spacetime_inv_metric_tensor_func(spacetime, t, x, y, z, &spacetime_inv_metric_tensor); - spacetime->spacetime_ricci_tensor_func(spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_ricci_tensor); + spacetime->spacetime_ricci_tensor_func( + spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_ricci_tensor + ); *spacetime_ricci_scalar = 0.0; @@ -695,20 +812,21 @@ gkyl_gr_spacetime_ricci_scalar_fd(const struct gkyl_gr_spacetime* spacetime, con gkyl_free(spacetime_ricci_tensor); } -void -gkyl_gr_spatial_weyl_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double***** spatial_weyl_tensor) +void gkyl_gr_spatial_weyl_tensor_fd( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double *****spatial_weyl_tensor +) { - double ****spatial_riemann_tensor = gkyl_malloc(sizeof(double***[3])); - double ****covariant_spatial_riemann_tensor = gkyl_malloc(sizeof(double***[3])); + double ****spatial_riemann_tensor = gkyl_malloc(sizeof(double ***[3])); + double ****covariant_spatial_riemann_tensor = gkyl_malloc(sizeof(double ***[3])); for (int i = 0; i < 3; i++) { - spatial_riemann_tensor[i] = gkyl_malloc(sizeof(double**[3])); - covariant_spatial_riemann_tensor[i] = gkyl_malloc(sizeof(double**[3])); + spatial_riemann_tensor[i] = gkyl_malloc(sizeof(double **[3])); + covariant_spatial_riemann_tensor[i] = gkyl_malloc(sizeof(double **[3])); for (int j = 0; j < 3; j++) { - spatial_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[3])); - covariant_spatial_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[3])); + spatial_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[3])); + covariant_spatial_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[3])); for (int k = 0; k < 3; k++) { spatial_riemann_tensor[i][j][k] = gkyl_malloc(sizeof(double[3])); @@ -721,8 +839,8 @@ gkyl_gr_spatial_weyl_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const } } - double **spatial_metric_tensor = gkyl_malloc(sizeof(double*[3])); - double **spatial_ricci_tensor = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric_tensor = gkyl_malloc(sizeof(double *[3])); + double **spatial_ricci_tensor = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric_tensor[i] = gkyl_malloc(sizeof(double[3])); @@ -741,7 +859,8 @@ gkyl_gr_spatial_weyl_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - covariant_spatial_riemann_tensor[i][j][k][l] += spatial_metric_tensor[i][m] * spatial_riemann_tensor[m][j][k][l]; + covariant_spatial_riemann_tensor[i][j][k][l] += + spatial_metric_tensor[i][m] * spatial_riemann_tensor[m][j][k][l]; } } } @@ -752,10 +871,15 @@ gkyl_gr_spatial_weyl_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - (*spatial_weyl_tensor)[i][j][k][l] = covariant_spatial_riemann_tensor[i][j][k][l] + ((spatial_ricci_tensor[i][l] * spatial_metric_tensor[j][k]) - - (spatial_ricci_tensor[i][k] * spatial_metric_tensor[j][l]) + (spatial_ricci_tensor[j][k] * spatial_metric_tensor[i][l]) - - (spatial_ricci_tensor[j][l] * spatial_metric_tensor[i][k])) + ((0.5 * spatial_ricci_scalar) * ((spatial_metric_tensor[i][k] * spatial_metric_tensor[j][l]) - - (spatial_metric_tensor[i][l] * spatial_metric_tensor[j][k]))); + (*spatial_weyl_tensor)[i][j][k][l] = + covariant_spatial_riemann_tensor[i][j][k][l] + + ((spatial_ricci_tensor[i][l] * spatial_metric_tensor[j][k]) - + (spatial_ricci_tensor[i][k] * spatial_metric_tensor[j][l]) + + (spatial_ricci_tensor[j][k] * spatial_metric_tensor[i][l]) - + (spatial_ricci_tensor[j][l] * spatial_metric_tensor[i][k])) + + ((0.5 * spatial_ricci_scalar) * + ((spatial_metric_tensor[i][k] * spatial_metric_tensor[j][l]) - + (spatial_metric_tensor[i][l] * spatial_metric_tensor[j][k]))); } } } @@ -781,20 +905,22 @@ gkyl_gr_spatial_weyl_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const gkyl_free(spatial_ricci_tensor); } -void -gkyl_gr_spacetime_weyl_tensor_fd(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dt, const double dx, const double dy, const double dz, double***** spacetime_weyl_tensor) +void gkyl_gr_spacetime_weyl_tensor_fd( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dt, const double dx, const double dy, const double dz, + double *****spacetime_weyl_tensor +) { - double ****spacetime_riemann_tensor = gkyl_malloc(sizeof(double***[4])); - double ****covariant_spacetime_riemann_tensor = gkyl_malloc(sizeof(double***[4])); + double ****spacetime_riemann_tensor = gkyl_malloc(sizeof(double ***[4])); + double ****covariant_spacetime_riemann_tensor = gkyl_malloc(sizeof(double ***[4])); for (int i = 0; i < 4; i++) { - spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double**[4])); - covariant_spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double**[4])); + spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double **[4])); + covariant_spacetime_riemann_tensor[i] = gkyl_malloc(sizeof(double **[4])); for (int j = 0; j < 4; j++) { - spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[4])); - covariant_spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double*[4])); + spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[4])); + covariant_spacetime_riemann_tensor[i][j] = gkyl_malloc(sizeof(double *[4])); for (int k = 0; k < 4; k++) { spacetime_riemann_tensor[i][j][k] = gkyl_malloc(sizeof(double[4])); @@ -807,8 +933,8 @@ gkyl_gr_spacetime_weyl_tensor_fd(const struct gkyl_gr_spacetime* spacetime, cons } } - double **spacetime_metric_tensor = gkyl_malloc(sizeof(double*[4])); - double **spacetime_ricci_tensor = gkyl_malloc(sizeof(double*[4])); + double **spacetime_metric_tensor = gkyl_malloc(sizeof(double *[4])); + double **spacetime_ricci_tensor = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { spacetime_metric_tensor[i] = gkyl_malloc(sizeof(double[4])); @@ -817,17 +943,24 @@ gkyl_gr_spacetime_weyl_tensor_fd(const struct gkyl_gr_spacetime* spacetime, cons double spacetime_ricci_scalar; - spacetime->spacetime_riemann_tensor_func(spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_riemann_tensor); + spacetime->spacetime_riemann_tensor_func( + spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_riemann_tensor + ); spacetime->spacetime_metric_tensor_func(spacetime, t, x, y, z, &spacetime_metric_tensor); - spacetime->spacetime_ricci_tensor_func(spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_ricci_tensor); - spacetime->spacetime_ricci_scalar_func(spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_ricci_scalar); + spacetime->spacetime_ricci_tensor_func( + spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_ricci_tensor + ); + spacetime->spacetime_ricci_scalar_func( + spacetime, t, x, y, z, dt, dx, dy, dz, &spacetime_ricci_scalar + ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { for (int m = 0; m < 4; m++) { - covariant_spacetime_riemann_tensor[i][j][k][l] += spacetime_metric_tensor[i][m] * spacetime_riemann_tensor[m][j][k][l]; + covariant_spacetime_riemann_tensor[i][j][k][l] += + spacetime_metric_tensor[i][m] * spacetime_riemann_tensor[m][j][k][l]; } } } @@ -838,10 +971,15 @@ gkyl_gr_spacetime_weyl_tensor_fd(const struct gkyl_gr_spacetime* spacetime, cons for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { - (*spacetime_weyl_tensor)[i][j][k][l] = covariant_spacetime_riemann_tensor[i][j][k][l] + (0.5 * ((spacetime_ricci_tensor[i][l] * spacetime_metric_tensor[j][k]) - - (spacetime_ricci_tensor[i][k] * spacetime_metric_tensor[j][l]) + (spacetime_ricci_tensor[j][k] * spacetime_metric_tensor[i][l]) - - (spacetime_ricci_tensor[j][l] * spacetime_metric_tensor[i][k]))) + ((spacetime_ricci_scalar / 6.0) * ((spacetime_metric_tensor[i][k] * spacetime_metric_tensor[j][l]) - - (spacetime_metric_tensor[i][l] * spacetime_metric_tensor[j][k]))); + (*spacetime_weyl_tensor)[i][j][k][l] = + covariant_spacetime_riemann_tensor[i][j][k][l] + + (0.5 * ((spacetime_ricci_tensor[i][l] * spacetime_metric_tensor[j][k]) - + (spacetime_ricci_tensor[i][k] * spacetime_metric_tensor[j][l]) + + (spacetime_ricci_tensor[j][k] * spacetime_metric_tensor[i][l]) - + (spacetime_ricci_tensor[j][l] * spacetime_metric_tensor[i][k]))) + + ((spacetime_ricci_scalar / 6.0) * + ((spacetime_metric_tensor[i][k] * spacetime_metric_tensor[j][l]) - + (spacetime_metric_tensor[i][l] * spacetime_metric_tensor[j][k]))); } } } @@ -867,9 +1005,10 @@ gkyl_gr_spacetime_weyl_tensor_fd(const struct gkyl_gr_spacetime* spacetime, cons gkyl_free(spacetime_ricci_tensor); } -void -gkyl_gr_conformal_factor_diff(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** conformal_factor_diff) +void gkyl_gr_conformal_factor_diff( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, double **conformal_factor_diff +) { double conformal_factor_x_forward; double conformal_factor_y_forward; @@ -887,14 +1026,19 @@ gkyl_gr_conformal_factor_diff(const struct gkyl_gr_spacetime* spacetime, const d spacetime->conformal_factor_func(spacetime, t, x, y - (0.5 * dy), z, &conformal_factor_y_backward); spacetime->conformal_factor_func(spacetime, t, x, y, z - (0.5 * dz), &conformal_factor_z_backward); - (*conformal_factor_diff)[0] = (1.0 / dx) * (conformal_factor_x_forward - conformal_factor_x_backward); - (*conformal_factor_diff)[1] = (1.0 / dy) * (conformal_factor_y_forward - conformal_factor_y_backward); - (*conformal_factor_diff)[2] = (1.0 / dz) * (conformal_factor_z_forward - conformal_factor_z_backward); + (*conformal_factor_diff)[0] = + (1.0 / dx) * (conformal_factor_x_forward - conformal_factor_x_backward); + (*conformal_factor_diff)[1] = + (1.0 / dy) * (conformal_factor_y_forward - conformal_factor_y_backward); + (*conformal_factor_diff)[2] = + (1.0 / dz) * (conformal_factor_z_forward - conformal_factor_z_backward); } -void -gkyl_gr_bssn_conformal_factor_diff(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double** bssn_conformal_factor_diff) +void gkyl_gr_bssn_conformal_factor_diff( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double **bssn_conformal_factor_diff +) { double bssn_conformal_factor_x_forward; double bssn_conformal_factor_y_forward; @@ -904,43 +1048,75 @@ gkyl_gr_bssn_conformal_factor_diff(const struct gkyl_gr_spacetime* spacetime, co double bssn_conformal_factor_y_backward; double bssn_conformal_factor_z_backward; - spacetime->bssn_conformal_factor_func(spacetime, t, x + (0.5 * dx), y, z, &bssn_conformal_factor_x_forward); - spacetime->bssn_conformal_factor_func(spacetime, t, x, y + (0.5 * dy), z, &bssn_conformal_factor_y_forward); - spacetime->bssn_conformal_factor_func(spacetime, t, x, y, z + (0.5 * dz), &bssn_conformal_factor_z_forward); - - spacetime->bssn_conformal_factor_func(spacetime, t, x - (0.5 * dx), y, z, &bssn_conformal_factor_x_backward); - spacetime->bssn_conformal_factor_func(spacetime, t, x, y - (0.5 * dy), z, &bssn_conformal_factor_y_backward); - spacetime->bssn_conformal_factor_func(spacetime, t, x, y, z - (0.5 * dz), &bssn_conformal_factor_z_backward); - - (*bssn_conformal_factor_diff)[0] = (1.0 / dx) * (bssn_conformal_factor_x_forward - bssn_conformal_factor_x_backward); - (*bssn_conformal_factor_diff)[1] = (1.0 / dy) * (bssn_conformal_factor_y_forward - bssn_conformal_factor_y_backward); - (*bssn_conformal_factor_diff)[2] = (1.0 / dz) * (bssn_conformal_factor_z_forward - bssn_conformal_factor_z_backward); + spacetime->bssn_conformal_factor_func( + spacetime, t, x + (0.5 * dx), y, z, &bssn_conformal_factor_x_forward + ); + spacetime->bssn_conformal_factor_func( + spacetime, t, x, y + (0.5 * dy), z, &bssn_conformal_factor_y_forward + ); + spacetime->bssn_conformal_factor_func( + spacetime, t, x, y, z + (0.5 * dz), &bssn_conformal_factor_z_forward + ); + + spacetime->bssn_conformal_factor_func( + spacetime, t, x - (0.5 * dx), y, z, &bssn_conformal_factor_x_backward + ); + spacetime->bssn_conformal_factor_func( + spacetime, t, x, y - (0.5 * dy), z, &bssn_conformal_factor_y_backward + ); + spacetime->bssn_conformal_factor_func( + spacetime, t, x, y, z - (0.5 * dz), &bssn_conformal_factor_z_backward + ); + + (*bssn_conformal_factor_diff)[0] = + (1.0 / dx) * (bssn_conformal_factor_x_forward - bssn_conformal_factor_x_backward); + (*bssn_conformal_factor_diff)[1] = + (1.0 / dy) * (bssn_conformal_factor_y_forward - bssn_conformal_factor_y_backward); + (*bssn_conformal_factor_diff)[2] = + (1.0 / dz) * (bssn_conformal_factor_z_forward - bssn_conformal_factor_z_backward); } -void -gkyl_gr_conformal_factor_diff2(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** conformal_factor_diff2) +void gkyl_gr_conformal_factor_diff2( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***conformal_factor_diff2 +) { - double* conformal_factor_der_x_forward = gkyl_malloc(sizeof(double[3])); - double* conformal_factor_der_y_forward = gkyl_malloc(sizeof(double[3])); - double* conformal_factor_der_z_forward = gkyl_malloc(sizeof(double[3])); - - double* conformal_factor_der_x_backward = gkyl_malloc(sizeof(double[3])); - double* conformal_factor_der_y_backward = gkyl_malloc(sizeof(double[3])); - double* conformal_factor_der_z_backward = gkyl_malloc(sizeof(double[3])); - - spacetime->conformal_factor_der_func(spacetime, t, x + (0.5 * dx), y, z, dx, dy, dz, &conformal_factor_der_x_forward); - spacetime->conformal_factor_der_func(spacetime, t, x, y + (0.5 * dy), z, dx, dy, dz, &conformal_factor_der_y_forward); - spacetime->conformal_factor_der_func(spacetime, t, x, y, z + (0.5 * dz), dx, dy, dz, &conformal_factor_der_z_forward); - - spacetime->conformal_factor_der_func(spacetime, t, x - (0.5 * dx), y, z, dx, dy, dz, &conformal_factor_der_x_backward); - spacetime->conformal_factor_der_func(spacetime, t, x, y - (0.5 * dy), z, dx, dy, dz, &conformal_factor_der_y_backward); - spacetime->conformal_factor_der_func(spacetime, t, x, y, z - (0.5 * dz), dx, dy, dz, &conformal_factor_der_z_backward); + double *conformal_factor_der_x_forward = gkyl_malloc(sizeof(double[3])); + double *conformal_factor_der_y_forward = gkyl_malloc(sizeof(double[3])); + double *conformal_factor_der_z_forward = gkyl_malloc(sizeof(double[3])); + + double *conformal_factor_der_x_backward = gkyl_malloc(sizeof(double[3])); + double *conformal_factor_der_y_backward = gkyl_malloc(sizeof(double[3])); + double *conformal_factor_der_z_backward = gkyl_malloc(sizeof(double[3])); + + spacetime->conformal_factor_der_func( + spacetime, t, x + (0.5 * dx), y, z, dx, dy, dz, &conformal_factor_der_x_forward + ); + spacetime->conformal_factor_der_func( + spacetime, t, x, y + (0.5 * dy), z, dx, dy, dz, &conformal_factor_der_y_forward + ); + spacetime->conformal_factor_der_func( + spacetime, t, x, y, z + (0.5 * dz), dx, dy, dz, &conformal_factor_der_z_forward + ); + + spacetime->conformal_factor_der_func( + spacetime, t, x - (0.5 * dx), y, z, dx, dy, dz, &conformal_factor_der_x_backward + ); + spacetime->conformal_factor_der_func( + spacetime, t, x, y - (0.5 * dy), z, dx, dy, dz, &conformal_factor_der_y_backward + ); + spacetime->conformal_factor_der_func( + spacetime, t, x, y, z - (0.5 * dz), dx, dy, dz, &conformal_factor_der_z_backward + ); for (int i = 0; i < 3; i++) { - (*conformal_factor_diff2)[0][i] = (1.0 / dx) * (conformal_factor_der_x_forward[i] - conformal_factor_der_x_backward[i]); - (*conformal_factor_diff2)[1][i] = (1.0 / dy) * (conformal_factor_der_y_forward[i] - conformal_factor_der_y_backward[i]); - (*conformal_factor_diff2)[2][i] = (1.0 / dz) * (conformal_factor_der_z_forward[i] - conformal_factor_der_z_backward[i]); + (*conformal_factor_diff2)[0][i] = + (1.0 / dx) * (conformal_factor_der_x_forward[i] - conformal_factor_der_x_backward[i]); + (*conformal_factor_diff2)[1][i] = + (1.0 / dy) * (conformal_factor_der_y_forward[i] - conformal_factor_der_y_backward[i]); + (*conformal_factor_diff2)[2][i] = + (1.0 / dz) * (conformal_factor_der_z_forward[i] - conformal_factor_der_z_backward[i]); } gkyl_free(conformal_factor_der_x_forward); @@ -952,30 +1128,47 @@ gkyl_gr_conformal_factor_diff2(const struct gkyl_gr_spacetime* spacetime, const gkyl_free(conformal_factor_der_z_backward); } -void -gkyl_gr_bssn_conformal_factor_diff2(const struct gkyl_gr_spacetime* spacetime, const double t, const double x, const double y, const double z, - const double dx, const double dy, const double dz, double*** bssn_conformal_factor_diff2) +void gkyl_gr_bssn_conformal_factor_diff2( + const struct gkyl_gr_spacetime *spacetime, const double t, const double x, const double y, + const double z, const double dx, const double dy, const double dz, + double ***bssn_conformal_factor_diff2 +) { - double* bssn_conformal_factor_der_x_forward = gkyl_malloc(sizeof(double[3])); - double* bssn_conformal_factor_der_y_forward = gkyl_malloc(sizeof(double[3])); - double* bssn_conformal_factor_der_z_forward = gkyl_malloc(sizeof(double[3])); - - double* bssn_conformal_factor_der_x_backward = gkyl_malloc(sizeof(double[3])); - double* bssn_conformal_factor_der_y_backward = gkyl_malloc(sizeof(double[3])); - double* bssn_conformal_factor_der_z_backward = gkyl_malloc(sizeof(double[3])); - - spacetime->bssn_conformal_factor_der_func(spacetime, t, x + (0.5 * dx), y, z, dx, dy, dz, &bssn_conformal_factor_der_x_forward); - spacetime->bssn_conformal_factor_der_func(spacetime, t, x, y + (0.5 * dy), z, dx, dy, dz, &bssn_conformal_factor_der_y_forward); - spacetime->bssn_conformal_factor_der_func(spacetime, t, x, y, z + (0.5 * dz), dx, dy, dz, &bssn_conformal_factor_der_z_forward); - - spacetime->bssn_conformal_factor_der_func(spacetime, t, x - (0.5 * dx), y, z, dx, dy, dz, &bssn_conformal_factor_der_x_backward); - spacetime->bssn_conformal_factor_der_func(spacetime, t, x, y - (0.5 * dy), z, dx, dy, dz, &bssn_conformal_factor_der_y_backward); - spacetime->bssn_conformal_factor_der_func(spacetime, t, x, y, z - (0.5 * dz), dx, dy, dz, &bssn_conformal_factor_der_z_backward); + double *bssn_conformal_factor_der_x_forward = gkyl_malloc(sizeof(double[3])); + double *bssn_conformal_factor_der_y_forward = gkyl_malloc(sizeof(double[3])); + double *bssn_conformal_factor_der_z_forward = gkyl_malloc(sizeof(double[3])); + + double *bssn_conformal_factor_der_x_backward = gkyl_malloc(sizeof(double[3])); + double *bssn_conformal_factor_der_y_backward = gkyl_malloc(sizeof(double[3])); + double *bssn_conformal_factor_der_z_backward = gkyl_malloc(sizeof(double[3])); + + spacetime->bssn_conformal_factor_der_func( + spacetime, t, x + (0.5 * dx), y, z, dx, dy, dz, &bssn_conformal_factor_der_x_forward + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, t, x, y + (0.5 * dy), z, dx, dy, dz, &bssn_conformal_factor_der_y_forward + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, t, x, y, z + (0.5 * dz), dx, dy, dz, &bssn_conformal_factor_der_z_forward + ); + + spacetime->bssn_conformal_factor_der_func( + spacetime, t, x - (0.5 * dx), y, z, dx, dy, dz, &bssn_conformal_factor_der_x_backward + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, t, x, y - (0.5 * dy), z, dx, dy, dz, &bssn_conformal_factor_der_y_backward + ); + spacetime->bssn_conformal_factor_der_func( + spacetime, t, x, y, z - (0.5 * dz), dx, dy, dz, &bssn_conformal_factor_der_z_backward + ); for (int i = 0; i < 3; i++) { - (*bssn_conformal_factor_diff2)[0][i] = (1.0 / dx) * (bssn_conformal_factor_der_x_forward[i] - bssn_conformal_factor_der_x_backward[i]); - (*bssn_conformal_factor_diff2)[1][i] = (1.0 / dy) * (bssn_conformal_factor_der_y_forward[i] - bssn_conformal_factor_der_y_backward[i]); - (*bssn_conformal_factor_diff2)[2][i] = (1.0 / dz) * (bssn_conformal_factor_der_z_forward[i] - bssn_conformal_factor_der_z_backward[i]); + (*bssn_conformal_factor_diff2)[0][i] = (1.0 / dx) * (bssn_conformal_factor_der_x_forward[i] - + bssn_conformal_factor_der_x_backward[i]); + (*bssn_conformal_factor_diff2)[1][i] = (1.0 / dy) * (bssn_conformal_factor_der_y_forward[i] - + bssn_conformal_factor_der_y_backward[i]); + (*bssn_conformal_factor_diff2)[2][i] = (1.0 / dz) * (bssn_conformal_factor_der_z_forward[i] - + bssn_conformal_factor_der_z_backward[i]); } gkyl_free(bssn_conformal_factor_der_x_forward); diff --git a/moments/zero/kep_scheme.c b/moments/zero/kep_scheme.c index 538c2d081d..4b98679d6f 100644 --- a/moments/zero/kep_scheme.c +++ b/moments/zero/kep_scheme.c @@ -8,20 +8,16 @@ #include #include -#define RHO 0 +#define RHO 0 #define RHOU d[0] #define RHOV d[1] #define RHOW d[2] #define ER 4 #define PR 4 -#define SQ(x) ((x)*(x)) +#define SQ(x) ((x) * (x)) -static const int dir_shuffle[][3] = { - {1, 2, 3}, - {2, 3, 1}, - {3, 1, 2} -}; +static const int dir_shuffle[][3] = {{1, 2, 3}, {2, 3, 1}, {3, 1, 2}}; struct gkyl_kep_scheme { struct gkyl_rect_grid grid; // grid object @@ -30,25 +26,25 @@ struct gkyl_kep_scheme { int update_dirs[GKYL_MAX_DIM]; // directions to update bool use_hybrid_flux; // should we use shock detector for hybrid flux - + double cfl; // CFL number - + const struct gkyl_wv_eqn *equation; // equation object - struct gkyl_wave_geom *geom; // geometry object + struct gkyl_wave_geom *geom; // geometry object }; -gkyl_kep_scheme* -gkyl_kep_scheme_new(const struct gkyl_kep_scheme_inp *inp) +gkyl_kep_scheme *gkyl_kep_scheme_new(const struct gkyl_kep_scheme_inp *inp) { struct gkyl_kep_scheme *up; up = gkyl_malloc(sizeof(*up)); up->grid = *(inp->grid); up->ndim = up->grid.ndim; - + up->num_up_dirs = inp->num_up_dirs; - for (int i=0; inum_up_dirs; ++i) + for (int i = 0; i < inp->num_up_dirs; ++i) { up->update_dirs[i] = inp->update_dirs[i]; + } up->cfl = inp->cfl; up->use_hybrid_flux = inp->use_hybrid_flux; @@ -60,26 +56,24 @@ gkyl_kep_scheme_new(const struct gkyl_kep_scheme_inp *inp) } // compute kinetic energy (no density factor) -static inline -double euler_ke(const double v[5]) +static inline double euler_ke(const double v[5]) { - return 0.5*(v[1]*v[1] + v[2]*v[2] + v[3]*v[3]); + return 0.5 * (v[1] * v[1] + v[2] * v[2] + v[3] * v[3]); } -static inline double -euler_flux(int dir, double gas_gamma, const double q[5], double flux[5]) +static inline double euler_flux(int dir, double gas_gamma, const double q[5], double flux[5]) { const int *d = dir_shuffle[dir]; - double pr = gkyl_euler_pressure(gas_gamma, q), u = q[RHOU]/q[0]; + double pr = gkyl_euler_pressure(gas_gamma, q), u = q[RHOU] / q[0]; flux[0] = q[RHOU]; // rho*u - flux[RHOU] = q[RHOU]*u + pr; // rho*u*u + pr - flux[RHOV] = q[RHOV]*u; // rho*v*u - flux[RHOW] = q[RHOW]*u; // rho*w*u - flux[4] = (q[4]+pr)*u; // (E+p)*u + flux[RHOU] = q[RHOU] * u + pr; // rho*u*u + pr + flux[RHOV] = q[RHOV] * u; // rho*v*u + flux[RHOW] = q[RHOW] * u; // rho*w*u + flux[4] = (q[4] + pr) * u; // (E+p)*u - double u2 = sqrt( SQ(q[1]/q[0]) + SQ(q[2]/q[0]) + SQ(q[3]/q[0]) ); - return fabs(u2) + sqrt(gas_gamma*pr/q[0]); + double u2 = sqrt(SQ(q[1] / q[0]) + SQ(q[2] / q[0]) + SQ(q[3] / q[0])); + return fabs(u2) + sqrt(gas_gamma * pr / q[0]); } // Lax fluxes @@ -91,8 +85,9 @@ mlax_flux(int dir, double gas_gamma, const double qm[5], const double qp[5], dou double amaxp = euler_flux(dir, gas_gamma, qp, fp); double amaxm = euler_flux(dir, gas_gamma, qm, fm); - for (int i=0; i<5; ++i) - flux[i] = 0.5*(fp[i]+fm[i]) - 0.5*fmax(amaxm, amaxp)*(qp[i]-qm[i]); + for (int i = 0; i < 5; ++i) { + flux[i] = 0.5 * (fp[i] + fm[i]) - 0.5 * fmax(amaxm, amaxp) * (qp[i] - qm[i]); + } } // Numerical flux using modified KEP scheme @@ -100,31 +95,33 @@ static inline void mkep_flux(int dir, double gas_gamma, const double vm[5], const double vp[5], double flux[5]) { double vbar[5]; - - for (int i=0; i<5; ++i) vbar[i] = 0.5*(vm[i]+vp[i]); - double kebar = 0.5*(euler_ke(vm) + euler_ke(vp)); - + + for (int i = 0; i < 5; ++i) { + vbar[i] = 0.5 * (vm[i] + vp[i]); + } + double kebar = 0.5 * (euler_ke(vm) + euler_ke(vp)); + const int *d = dir_shuffle[dir]; - flux[0] = vbar[RHO]*vbar[RHOU]; // rho*u + flux[0] = vbar[RHO] * vbar[RHOU]; // rho*u // momentum flux must have this form to ensure KEP property - flux[RHOU] = flux[0]*vbar[RHOU] + vbar[PR]; // rho*u*u + pe - flux[RHOV] = flux[0]*vbar[RHOV]; // rho*u*v - flux[RHOW] = flux[0]*vbar[RHOW]; // rho*u*v + flux[RHOU] = flux[0] * vbar[RHOU] + vbar[PR]; // rho*u*u + pe + flux[RHOV] = flux[0] * vbar[RHOV]; // rho*u*v + flux[RHOW] = flux[0] * vbar[RHOW]; // rho*u*v // following ensure stability of linear perturbations around uniform flow - flux[ER] = gas_gamma/(gas_gamma-1)*vbar[PR]*vbar[RHOU] + flux[0]*kebar; // (E+p)*u + flux[ER] = gas_gamma / (gas_gamma - 1) * vbar[PR] * vbar[RHOU] + flux[0] * kebar; // (E+p)*u } -static inline long -get_offset(int dir, int loc, const struct gkyl_range *range) +static inline long get_offset(int dir, int loc, const struct gkyl_range *range) { - int idx[GKYL_MAX_CDIM] = { 0, 0, 0 }; + int idx[GKYL_MAX_CDIM] = {0, 0, 0}; idx[dir] = loc; return gkyl_range_offset(range, idx); } -static void -calc_alpha(const gkyl_kep_scheme *kep, const struct gkyl_range *update_rng, - const struct gkyl_array *qin, struct gkyl_array *alpha) +static void calc_alpha( + const gkyl_kep_scheme *kep, const struct gkyl_range *update_rng, const struct gkyl_array *qin, + struct gkyl_array *alpha +) { int ndim = update_rng->ndim; gkyl_array_clear_range(alpha, 0.0, update_rng); @@ -133,20 +130,20 @@ calc_alpha(const gkyl_kep_scheme *kep, const struct gkyl_range *update_rng, double nu = 0.1; double phi = 0.01; // base diffusion - enum { IRHO, IRHOU, IRHOV, IRHOW}; // indexing Euler conserved vars + enum { IRHO, IRHOU, IRHOV, IRHOW }; // indexing Euler conserved vars enum { IC, IL, IR }; // indexing into offsets long offsets[GKYL_MAX_CDIM][3]; - - for (int d=0; dgrid.dx[d]; L = fmin(L, dx[d]); } @@ -155,52 +152,49 @@ calc_alpha(const gkyl_kep_scheme *kep, const struct gkyl_range *update_rng, gkyl_range_iter_init(&iter, update_rng); while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(update_rng, iter.idx); - + double divu = 0.0, curlx = 0.0, curly = 0.0, curlz = 0.0; double u2 = 0.0; // u*u const double *qc = gkyl_array_cfetch(qin, loc); // compute div(u), curl(u) and u*u - for (int d=0; dndim; double gas_gamma = gkyl_wv_euler_gas_gamma(kep->equation); @@ -211,15 +205,16 @@ gkyl_kep_scheme_advance(const gkyl_kep_scheme *kep, const struct gkyl_range *upd gkyl_array_clear_range(rhs, 0.0, update_rng); - if (kep->use_hybrid_flux) + if (kep->use_hybrid_flux) { calc_alpha(kep, update_rng, qin, alpha); + } - for (int d=0; dnum_up_dirs; ++d) { + for (int d = 0; d < kep->num_up_dirs; ++d) { int dir = kep->update_dirs[d]; double dx = kep->grid.dx[dir]; int loidx = update_rng->lower[dir]; - int upidx = update_rng->upper[dir]+1; // one more edge than cells + int upidx = update_rng->upper[dir] + 1; // one more edge than cells struct gkyl_range perp_range; gkyl_range_shorten_from_above(&perp_range, update_rng, dir, 1); @@ -227,12 +222,12 @@ gkyl_kep_scheme_advance(const gkyl_kep_scheme *kep, const struct gkyl_range *upd gkyl_range_iter_init(&iter, &perp_range); while (gkyl_range_iter_next(&iter)) { - gkyl_copy_int_arr(ndim, iter.idx, idxm); gkyl_copy_int_arr(ndim, iter.idx, idxp); - - for (int i=loidx; i<=upidx; ++i) { // note upidx is inclusive - idxm[dir] = i-1; idxp[dir] = i; + + for (int i = loidx; i <= upidx; ++i) { // note upidx is inclusive + idxm[dir] = i - 1; + idxp[dir] = i; long linm = gkyl_range_idx(update_rng, idxm); long linp = gkyl_range_idx(update_rng, idxp); @@ -245,8 +240,9 @@ gkyl_kep_scheme_advance(const gkyl_kep_scheme *kep, const struct gkyl_range *upd mkep_flux(dir, gas_gamma, vm, vp, flux); - if (kep->use_hybrid_flux) + if (kep->use_hybrid_flux) { mlax_flux(dir, gas_gamma, qm, qp, lflux); + } // accumulate contribution of flux to left/right cell double *rhsm = gkyl_array_fetch(rhs, linm); @@ -257,15 +253,14 @@ gkyl_kep_scheme_advance(const gkyl_kep_scheme *kep, const struct gkyl_range *upd const double *alphap = gkyl_array_fetch(alpha, linp); double am = fmax(alpham[0], alphap[0]); - for (int m=0; m<5; ++m) { - rhsp[m] += ((1.0-am)*flux[m] + am*lflux[m])/dx; - rhsm[m] += -((1.0-am)*flux[m] + am*lflux[m])/dx; + for (int m = 0; m < 5; ++m) { + rhsp[m] += ((1.0 - am) * flux[m] + am * lflux[m]) / dx; + rhsm[m] += -((1.0 - am) * flux[m] + am * lflux[m]) / dx; } - } - else { - for (int m=0; m<5; ++m) { - rhsp[m] += flux[m]/dx; - rhsm[m] += -flux[m]/dx; + } else { + for (int m = 0; m < 5; ++m) { + rhsp[m] += flux[m] / dx; + rhsm[m] += -flux[m] / dx; } } @@ -275,41 +270,40 @@ gkyl_kep_scheme_advance(const gkyl_kep_scheme *kep, const struct gkyl_range *upd const int *d = dir_shuffle[dir]; double qp_dir[5]; qp_dir[0] = qp[0]; - qp_dir[RHOU] = qp[1]; qp_dir[RHOV] = qp[2]; qp_dir[RHOW] = qp[3]; + qp_dir[RHOU] = qp[1]; + qp_dir[RHOV] = qp[2]; + qp_dir[RHOW] = qp[3]; qp_dir[4] = qp[4]; - - cflrate_d[0] += gkyl_euler_max_abs_speed(gas_gamma, qp_dir)/dx; + + cflrate_d[0] += gkyl_euler_max_abs_speed(gas_gamma, qp_dir) / dx; } } } } -double -gkyl_kep_scheme_max_dt(const gkyl_kep_scheme *kep, const struct gkyl_range *update_range, - const struct gkyl_array *qin) +double gkyl_kep_scheme_max_dt( + const gkyl_kep_scheme *kep, const struct gkyl_range *update_range, const struct gkyl_array *qin +) { double max_dt = DBL_MAX; - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, update_range); while (gkyl_range_iter_next(&iter)) { - - for (int d=0; dnum_up_dirs; ++d) { + for (int d = 0; d < kep->num_up_dirs; ++d) { int dir = kep->update_dirs[d]; double dx = kep->grid.dx[dir]; const double *q = gkyl_array_cfetch(qin, gkyl_range_idx(update_range, iter.idx)); double maxs = gkyl_wv_eqn_max_speed(kep->equation, q); - max_dt = fmin(max_dt, kep->cfl*dx/maxs); + max_dt = fmin(max_dt, kep->cfl * dx / maxs); } - } - return max_dt; + return max_dt; } -void -gkyl_kep_scheme_release(gkyl_kep_scheme* up) +void gkyl_kep_scheme_release(gkyl_kep_scheme *up) { gkyl_wv_eqn_release(up->equation); gkyl_wave_geom_release(up->geom); diff --git a/moments/zero/level_set.c b/moments/zero/level_set.c index 915d63b0a7..34610dd75a 100644 --- a/moments/zero/level_set.c +++ b/moments/zero/level_set.c @@ -42,11 +42,12 @@ struct gkyl_wave_prop { long n_max_bad_cells; // Maximum number of cells fixed in a call. }; -void -euler_rgfm_reinit_level_set(gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, int upidx_c, - struct gkyl_array *qout, int dir) +void euler_rgfm_reinit_level_set( + gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, + int upidx_c, struct gkyl_array *qout, int dir +) { - const struct gkyl_wv_eqn* eqn = wv->equation; + const struct gkyl_wv_eqn *eqn = wv->equation; const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; int reinit_freq = euler_rgfm->reinit_freq; @@ -71,7 +72,7 @@ euler_rgfm_reinit_level_set(gkyl_wave_prop *wv, const struct gkyl_range *update_ double *qll = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); idxl[dir] = i - 3; double *qlll = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); - + double rho_total_l = ql[0]; double rho_total_ll = qll[0]; double rho_total_lll = qlll[0]; @@ -82,19 +83,20 @@ euler_rgfm_reinit_level_set(gkyl_wave_prop *wv, const struct gkyl_range *update_ double *qrr = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); idxl[dir] = i + 3; double *qrrr = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); - + double rho_total_r = qr[0]; double rho_total_rr = qrr[0]; double rho_total_rrr = qrrr[0]; - - if (ql[5 + j] / rho_total_l < 0.5 || qll[5 + j] / rho_total_ll < 0.5 || qlll[5 + j] / rho_total_lll < 0.5 || qr[5 + j] / rho_total_r < 0.5 || - qrr[5 + j] / rho_total_rr < 0.5 || qrrr[5 + j] / rho_total_rrr < 0.5) { + + if (ql[5 + j] / rho_total_l < 0.5 || qll[5 + j] / rho_total_ll < 0.5 || + qlll[5 + j] / rho_total_lll < 0.5 || qr[5 + j] / rho_total_r < 0.5 || + qrr[5 + j] / rho_total_rr < 0.5 || qrrr[5 + j] / rho_total_rrr < 0.5) { qnew[5 + j] = 0.99999 * rho_total; qnew[4 + num_species + j] = 0.99999 * rho_total; update_up = true; } } - + if (qnew[5 + j] / rho_total < 0.5) { idxl[dir] = i - 1; double *ql = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); @@ -102,7 +104,7 @@ euler_rgfm_reinit_level_set(gkyl_wave_prop *wv, const struct gkyl_range *update_ double *qll = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); idxl[dir] = i - 3; double *qlll = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); - + double rho_total_l = ql[0]; double rho_total_ll = qll[0]; double rho_total_lll = qlll[0]; @@ -113,13 +115,14 @@ euler_rgfm_reinit_level_set(gkyl_wave_prop *wv, const struct gkyl_range *update_ double *qrr = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); idxl[dir] = i + 3; double *qrrr = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); - + double rho_total_r = qr[0]; double rho_total_rr = qrr[0]; double rho_total_rrr = qrrr[0]; - if (qr[5 + j] / rho_total_r >= 0.5 || qrr[5 + j] / rho_total_rr >= 0.5 || qrrr[5 + j] / rho_total_rrr >= 0.5 || ql[5 + j] / rho_total_l >= 0.5 || - qll[5 + j] / rho_total_ll >= 0.5 || qlll[5 + j] / rho_total_lll >= 0.5) { + if (qr[5 + j] / rho_total_r >= 0.5 || qrr[5 + j] / rho_total_rr >= 0.5 || + qrrr[5 + j] / rho_total_rrr >= 0.5 || ql[5 + j] / rho_total_l >= 0.5 || + qll[5 + j] / rho_total_ll >= 0.5 || qlll[5 + j] / rho_total_lll >= 0.5) { qnew[5 + j] = 0.00001 * rho_total; qnew[4 + num_species + j] = 0.00001 * rho_total; update_down = true; @@ -135,27 +138,27 @@ euler_rgfm_reinit_level_set(gkyl_wave_prop *wv, const struct gkyl_range *update_ } qnew[4 + (2 * num_species)] = 0.0; - } - else { + } else { qnew[4 + (2 * num_species)] += 1.0; } } } -void -gr_maxwell_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, int upidx_c, - struct gkyl_array *qout, int dir) +void gr_maxwell_impose_gauge( + gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, + int upidx_c, struct gkyl_array *qout, int dir +) { - const struct gkyl_wv_eqn* eqn = wv->equation; + const struct gkyl_wv_eqn *eqn = wv->equation; const struct wv_gr_maxwell *gr_maxwell = container_of(eqn, struct wv_gr_maxwell, eqn); - + const enum gkyl_spacetime_gauge spacetime_gauge = gr_maxwell->spacetime_gauge; if (spacetime_gauge == GKYL_STATIC_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_maxwell->spacetime; + const struct gkyl_gr_spacetime *spacetime = gr_maxwell->spacetime; int reinit_freq = gr_maxwell->reinit_freq; - - for (int i = loidx_c; i<= upidx_c; i++) { + + for (int i = loidx_c; i <= upidx_c; i++) { idxl[dir] = i; double *qnew = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); @@ -170,7 +173,7 @@ gr_maxwell_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_rang double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -182,11 +185,19 @@ gr_maxwell_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_rang spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, z, &spatial_metric); qnew[8] = lapse; - qnew[9] = shift[0]; qnew[10] = shift[1]; qnew[11] = shift[2]; - - qnew[12] = spatial_metric[0][0]; qnew[13] = spatial_metric[0][1]; qnew[14] = spatial_metric[0][2]; - qnew[15] = spatial_metric[1][0]; qnew[16] = spatial_metric[1][1]; qnew[17] = spatial_metric[1][2]; - qnew[18] = spatial_metric[2][0]; qnew[19] = spatial_metric[2][1]; qnew[20] = spatial_metric[2][2]; + qnew[9] = shift[0]; + qnew[10] = shift[1]; + qnew[11] = shift[2]; + + qnew[12] = spatial_metric[0][0]; + qnew[13] = spatial_metric[0][1]; + qnew[14] = spatial_metric[0][2]; + qnew[15] = spatial_metric[1][0]; + qnew[16] = spatial_metric[1][1]; + qnew[17] = spatial_metric[1][2]; + qnew[18] = spatial_metric[2][0]; + qnew[19] = spatial_metric[2][1]; + qnew[20] = spatial_metric[2][2]; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -194,8 +205,7 @@ gr_maxwell_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_rang } qnew[21] = -1.0; - } - else { + } else { qnew[21] = 1.0; } @@ -204,30 +214,31 @@ gr_maxwell_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_rang } gkyl_free(spatial_metric); gkyl_free(shift); - + qnew[22] = 0.0; - } - else { + } else { qnew[22] += 1.0; } } } } -void -gr_maxwell_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, int upidx_c, - struct gkyl_array *qout, int dir) +void gr_maxwell_tetrad_impose_gauge( + gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, + int upidx_c, struct gkyl_array *qout, int dir +) { - const struct gkyl_wv_eqn* eqn = wv->equation; - const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); - + const struct gkyl_wv_eqn *eqn = wv->equation; + const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); + const enum gkyl_spacetime_gauge spacetime_gauge = gr_maxwell_tetrad->spacetime_gauge; if (spacetime_gauge == GKYL_STATIC_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_maxwell_tetrad->spacetime; + const struct gkyl_gr_spacetime *spacetime = gr_maxwell_tetrad->spacetime; int reinit_freq = gr_maxwell_tetrad->reinit_freq; - - for (int i = loidx_c; i<= upidx_c; i++) { + + for (int i = loidx_c; i <= upidx_c; i++) { idxl[dir] = i; double *qnew = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); @@ -242,7 +253,7 @@ gr_maxwell_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upda double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -254,11 +265,19 @@ gr_maxwell_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upda spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, z, &spatial_metric); qnew[8] = lapse; - qnew[9] = shift[0]; qnew[10] = shift[1]; qnew[11] = shift[2]; - - qnew[12] = spatial_metric[0][0]; qnew[13] = spatial_metric[0][1]; qnew[14] = spatial_metric[0][2]; - qnew[15] = spatial_metric[1][0]; qnew[16] = spatial_metric[1][1]; qnew[17] = spatial_metric[1][2]; - qnew[18] = spatial_metric[2][0]; qnew[19] = spatial_metric[2][1]; qnew[20] = spatial_metric[2][2]; + qnew[9] = shift[0]; + qnew[10] = shift[1]; + qnew[11] = shift[2]; + + qnew[12] = spatial_metric[0][0]; + qnew[13] = spatial_metric[0][1]; + qnew[14] = spatial_metric[0][2]; + qnew[15] = spatial_metric[1][0]; + qnew[16] = spatial_metric[1][1]; + qnew[17] = spatial_metric[1][2]; + qnew[18] = spatial_metric[2][0]; + qnew[19] = spatial_metric[2][1]; + qnew[20] = spatial_metric[2][2]; if (in_excision_region) { for (int i = 0; i < 22; i++) { @@ -266,8 +285,7 @@ gr_maxwell_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upda } qnew[21] = -1.0; - } - else { + } else { qnew[21] = 1.0; } @@ -276,30 +294,30 @@ gr_maxwell_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upda } gkyl_free(spatial_metric); gkyl_free(shift); - + qnew[22] = 0.0; - } - else { + } else { qnew[22] += 1.0; } } } } -void -gr_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, int upidx_c, - struct gkyl_array *qout, int dir) +void gr_euler_impose_gauge( + gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, + int upidx_c, struct gkyl_array *qout, int dir +) { - const struct gkyl_wv_eqn* eqn = wv->equation; + const struct gkyl_wv_eqn *eqn = wv->equation; const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); - + const enum gkyl_spacetime_gauge spacetime_gauge = gr_euler->spacetime_gauge; if (spacetime_gauge == GKYL_STATIC_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_euler->spacetime; + const struct gkyl_gr_spacetime *spacetime = gr_euler->spacetime; int reinit_freq = gr_euler->reinit_freq; - - for (int i = loidx_c; i<= upidx_c; i++) { + + for (int i = loidx_c; i <= upidx_c; i++) { idxl[dir] = i; double *qnew = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); @@ -314,25 +332,25 @@ gr_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -344,47 +362,96 @@ gr_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, spacetime->excision_region_func(spacetime, 0.0, x, y, z, &in_excision_region); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, z, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[5] = lapse; - qnew[6] = shift[0]; qnew[7] = shift[1]; qnew[8] = shift[2]; - - qnew[9] = spatial_metric[0][0]; qnew[10] = spatial_metric[0][1]; qnew[11] = spatial_metric[0][2]; - qnew[12] = spatial_metric[1][0]; qnew[13] = spatial_metric[1][1]; qnew[14] = spatial_metric[1][2]; - qnew[15] = spatial_metric[2][0]; qnew[16] = spatial_metric[2][1]; qnew[17] = spatial_metric[2][2]; - - qnew[18] = extrinsic_curvature[0][0]; qnew[19] = extrinsic_curvature[0][1]; qnew[20] = extrinsic_curvature[0][2]; - qnew[21] = extrinsic_curvature[1][0]; qnew[22] = extrinsic_curvature[1][1]; qnew[23] = extrinsic_curvature[1][2]; - qnew[24] = extrinsic_curvature[2][0]; qnew[25] = extrinsic_curvature[2][1]; qnew[26] = extrinsic_curvature[2][2]; + qnew[6] = shift[0]; + qnew[7] = shift[1]; + qnew[8] = shift[2]; + + qnew[9] = spatial_metric[0][0]; + qnew[10] = spatial_metric[0][1]; + qnew[11] = spatial_metric[0][2]; + qnew[12] = spatial_metric[1][0]; + qnew[13] = spatial_metric[1][1]; + qnew[14] = spatial_metric[1][2]; + qnew[15] = spatial_metric[2][0]; + qnew[16] = spatial_metric[2][1]; + qnew[17] = spatial_metric[2][2]; + + qnew[18] = extrinsic_curvature[0][0]; + qnew[19] = extrinsic_curvature[0][1]; + qnew[20] = extrinsic_curvature[0][2]; + qnew[21] = extrinsic_curvature[1][0]; + qnew[22] = extrinsic_curvature[1][1]; + qnew[23] = extrinsic_curvature[1][2]; + qnew[24] = extrinsic_curvature[2][0]; + qnew[25] = extrinsic_curvature[2][1]; + qnew[26] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[27] = -1.0; - } - else { + } else { qnew[27] = 1.0; } - qnew[28] = lapse_der[0]; qnew[29] = lapse_der[1]; qnew[30] = lapse_der[2]; - - qnew[31] = shift_der[0][0]; qnew[32] = shift_der[0][1]; qnew[33] = shift_der[0][2]; - qnew[34] = shift_der[1][0]; qnew[35] = shift_der[1][1]; qnew[36] = shift_der[1][2]; - qnew[37] = shift_der[2][0]; qnew[38] = shift_der[2][1]; qnew[39] = shift_der[2][2]; - - qnew[40] = spatial_metric_der[0][0][0]; qnew[41] = spatial_metric_der[0][0][1]; qnew[42] = spatial_metric_der[0][0][2]; - qnew[43] = spatial_metric_der[0][1][0]; qnew[44] = spatial_metric_der[0][1][1]; qnew[45] = spatial_metric_der[0][1][2]; - qnew[46] = spatial_metric_der[0][2][0]; qnew[47] = spatial_metric_der[0][2][1]; qnew[48] = spatial_metric_der[0][2][2]; - - qnew[49] = spatial_metric_der[1][0][0]; qnew[50] = spatial_metric_der[1][0][1]; qnew[51] = spatial_metric_der[1][0][2]; - qnew[52] = spatial_metric_der[1][1][0]; qnew[53] = spatial_metric_der[1][1][1]; qnew[54] = spatial_metric_der[1][1][2]; - qnew[55] = spatial_metric_der[1][2][0]; qnew[56] = spatial_metric_der[1][2][1]; qnew[57] = spatial_metric_der[1][2][2]; - - qnew[58] = spatial_metric_der[2][0][0]; qnew[59] = spatial_metric_der[2][0][1]; qnew[60] = spatial_metric_der[2][0][2]; - qnew[61] = spatial_metric_der[2][1][0]; qnew[62] = spatial_metric_der[2][1][1]; qnew[63] = spatial_metric_der[2][1][2]; - qnew[64] = spatial_metric_der[2][2][0]; qnew[65] = spatial_metric_der[2][2][1]; qnew[66] = spatial_metric_der[2][2][2]; + qnew[28] = lapse_der[0]; + qnew[29] = lapse_der[1]; + qnew[30] = lapse_der[2]; + + qnew[31] = shift_der[0][0]; + qnew[32] = shift_der[0][1]; + qnew[33] = shift_der[0][2]; + qnew[34] = shift_der[1][0]; + qnew[35] = shift_der[1][1]; + qnew[36] = shift_der[1][2]; + qnew[37] = shift_der[2][0]; + qnew[38] = shift_der[2][1]; + qnew[39] = shift_der[2][2]; + + qnew[40] = spatial_metric_der[0][0][0]; + qnew[41] = spatial_metric_der[0][0][1]; + qnew[42] = spatial_metric_der[0][0][2]; + qnew[43] = spatial_metric_der[0][1][0]; + qnew[44] = spatial_metric_der[0][1][1]; + qnew[45] = spatial_metric_der[0][1][2]; + qnew[46] = spatial_metric_der[0][2][0]; + qnew[47] = spatial_metric_der[0][2][1]; + qnew[48] = spatial_metric_der[0][2][2]; + + qnew[49] = spatial_metric_der[1][0][0]; + qnew[50] = spatial_metric_der[1][0][1]; + qnew[51] = spatial_metric_der[1][0][2]; + qnew[52] = spatial_metric_der[1][1][0]; + qnew[53] = spatial_metric_der[1][1][1]; + qnew[54] = spatial_metric_der[1][1][2]; + qnew[55] = spatial_metric_der[1][2][0]; + qnew[56] = spatial_metric_der[1][2][1]; + qnew[57] = spatial_metric_der[1][2][2]; + + qnew[58] = spatial_metric_der[2][0][0]; + qnew[59] = spatial_metric_der[2][0][1]; + qnew[60] = spatial_metric_der[2][0][2]; + qnew[61] = spatial_metric_der[2][1][0]; + qnew[62] = spatial_metric_der[2][1][1]; + qnew[63] = spatial_metric_der[2][1][2]; + qnew[64] = spatial_metric_der[2][2][0]; + qnew[65] = spatial_metric_der[2][2][1]; + qnew[66] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -397,7 +464,7 @@ gr_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -409,30 +476,31 @@ gr_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, gkyl_free(lapse_der); gkyl_free(shift_der); gkyl_free(spatial_metric_der); - + qnew[67] = 0.0; - } - else { + } else { qnew[67] += 1.0; } } } } -void -gr_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, int upidx_c, - struct gkyl_array *qout, int dir) +void gr_euler_tetrad_impose_gauge( + gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, + int upidx_c, struct gkyl_array *qout, int dir +) { - const struct gkyl_wv_eqn* eqn = wv->equation; - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); - + const struct gkyl_wv_eqn *eqn = wv->equation; + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const enum gkyl_spacetime_gauge spacetime_gauge = gr_euler_tetrad->spacetime_gauge; if (spacetime_gauge == GKYL_STATIC_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_euler_tetrad->spacetime; + const struct gkyl_gr_spacetime *spacetime = gr_euler_tetrad->spacetime; int reinit_freq = gr_euler_tetrad->reinit_freq; - - for (int i = loidx_c; i<= upidx_c; i++) { + + for (int i = loidx_c; i <= upidx_c; i++) { idxl[dir] = i; double *qnew = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); @@ -447,25 +515,25 @@ gr_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -477,47 +545,96 @@ gr_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update spacetime->excision_region_func(spacetime, 0.0, x, y, z, &in_excision_region); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, z, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[5] = lapse; - qnew[6] = shift[0]; qnew[7] = shift[1]; qnew[8] = shift[2]; - - qnew[9] = spatial_metric[0][0]; qnew[10] = spatial_metric[0][1]; qnew[11] = spatial_metric[0][2]; - qnew[12] = spatial_metric[1][0]; qnew[13] = spatial_metric[1][1]; qnew[14] = spatial_metric[1][2]; - qnew[15] = spatial_metric[2][0]; qnew[16] = spatial_metric[2][1]; qnew[17] = spatial_metric[2][2]; - - qnew[18] = extrinsic_curvature[0][0]; qnew[19] = extrinsic_curvature[0][1]; qnew[20] = extrinsic_curvature[0][2]; - qnew[21] = extrinsic_curvature[1][0]; qnew[22] = extrinsic_curvature[1][1]; qnew[23] = extrinsic_curvature[1][2]; - qnew[24] = extrinsic_curvature[2][0]; qnew[25] = extrinsic_curvature[2][1]; qnew[26] = extrinsic_curvature[2][2]; + qnew[6] = shift[0]; + qnew[7] = shift[1]; + qnew[8] = shift[2]; + + qnew[9] = spatial_metric[0][0]; + qnew[10] = spatial_metric[0][1]; + qnew[11] = spatial_metric[0][2]; + qnew[12] = spatial_metric[1][0]; + qnew[13] = spatial_metric[1][1]; + qnew[14] = spatial_metric[1][2]; + qnew[15] = spatial_metric[2][0]; + qnew[16] = spatial_metric[2][1]; + qnew[17] = spatial_metric[2][2]; + + qnew[18] = extrinsic_curvature[0][0]; + qnew[19] = extrinsic_curvature[0][1]; + qnew[20] = extrinsic_curvature[0][2]; + qnew[21] = extrinsic_curvature[1][0]; + qnew[22] = extrinsic_curvature[1][1]; + qnew[23] = extrinsic_curvature[1][2]; + qnew[24] = extrinsic_curvature[2][0]; + qnew[25] = extrinsic_curvature[2][1]; + qnew[26] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[27] = -1.0; - } - else { + } else { qnew[27] = 1.0; } - qnew[28] = lapse_der[0]; qnew[29] = lapse_der[1]; qnew[30] = lapse_der[2]; - - qnew[31] = shift_der[0][0]; qnew[32] = shift_der[0][1]; qnew[33] = shift_der[0][2]; - qnew[34] = shift_der[1][0]; qnew[35] = shift_der[1][1]; qnew[36] = shift_der[1][2]; - qnew[37] = shift_der[2][0]; qnew[38] = shift_der[2][1]; qnew[39] = shift_der[2][2]; - - qnew[40] = spatial_metric_der[0][0][0]; qnew[41] = spatial_metric_der[0][0][1]; qnew[42] = spatial_metric_der[0][0][2]; - qnew[43] = spatial_metric_der[0][1][0]; qnew[44] = spatial_metric_der[0][1][1]; qnew[45] = spatial_metric_der[0][1][2]; - qnew[46] = spatial_metric_der[0][2][0]; qnew[47] = spatial_metric_der[0][2][1]; qnew[48] = spatial_metric_der[0][2][2]; - - qnew[49] = spatial_metric_der[1][0][0]; qnew[50] = spatial_metric_der[1][0][1]; qnew[51] = spatial_metric_der[1][0][2]; - qnew[52] = spatial_metric_der[1][1][0]; qnew[53] = spatial_metric_der[1][1][1]; qnew[54] = spatial_metric_der[1][1][2]; - qnew[55] = spatial_metric_der[1][2][0]; qnew[56] = spatial_metric_der[1][2][1]; qnew[57] = spatial_metric_der[1][2][2]; - - qnew[58] = spatial_metric_der[2][0][0]; qnew[59] = spatial_metric_der[2][0][1]; qnew[60] = spatial_metric_der[2][0][2]; - qnew[61] = spatial_metric_der[2][1][0]; qnew[62] = spatial_metric_der[2][1][1]; qnew[63] = spatial_metric_der[2][1][2]; - qnew[64] = spatial_metric_der[2][2][0]; qnew[65] = spatial_metric_der[2][2][1]; qnew[66] = spatial_metric_der[2][2][2]; + qnew[28] = lapse_der[0]; + qnew[29] = lapse_der[1]; + qnew[30] = lapse_der[2]; + + qnew[31] = shift_der[0][0]; + qnew[32] = shift_der[0][1]; + qnew[33] = shift_der[0][2]; + qnew[34] = shift_der[1][0]; + qnew[35] = shift_der[1][1]; + qnew[36] = shift_der[1][2]; + qnew[37] = shift_der[2][0]; + qnew[38] = shift_der[2][1]; + qnew[39] = shift_der[2][2]; + + qnew[40] = spatial_metric_der[0][0][0]; + qnew[41] = spatial_metric_der[0][0][1]; + qnew[42] = spatial_metric_der[0][0][2]; + qnew[43] = spatial_metric_der[0][1][0]; + qnew[44] = spatial_metric_der[0][1][1]; + qnew[45] = spatial_metric_der[0][1][2]; + qnew[46] = spatial_metric_der[0][2][0]; + qnew[47] = spatial_metric_der[0][2][1]; + qnew[48] = spatial_metric_der[0][2][2]; + + qnew[49] = spatial_metric_der[1][0][0]; + qnew[50] = spatial_metric_der[1][0][1]; + qnew[51] = spatial_metric_der[1][0][2]; + qnew[52] = spatial_metric_der[1][1][0]; + qnew[53] = spatial_metric_der[1][1][1]; + qnew[54] = spatial_metric_der[1][1][2]; + qnew[55] = spatial_metric_der[1][2][0]; + qnew[56] = spatial_metric_der[1][2][1]; + qnew[57] = spatial_metric_der[1][2][2]; + + qnew[58] = spatial_metric_der[2][0][0]; + qnew[59] = spatial_metric_der[2][0][1]; + qnew[60] = spatial_metric_der[2][0][2]; + qnew[61] = spatial_metric_der[2][1][0]; + qnew[62] = spatial_metric_der[2][1][1]; + qnew[63] = spatial_metric_der[2][1][2]; + qnew[64] = spatial_metric_der[2][2][0]; + qnew[65] = spatial_metric_der[2][2][1]; + qnew[66] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 67; i++) { @@ -530,7 +647,7 @@ gr_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -542,30 +659,31 @@ gr_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update gkyl_free(lapse_der); gkyl_free(shift_der); gkyl_free(spatial_metric_der); - + qnew[67] = 0.0; - } - else { + } else { qnew[67] += 1.0; } } } } -void -gr_ultra_rel_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, int upidx_c, - struct gkyl_array *qout, int dir) +void gr_ultra_rel_euler_impose_gauge( + gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, + int upidx_c, struct gkyl_array *qout, int dir +) { - const struct gkyl_wv_eqn* eqn = wv->equation; - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct gkyl_wv_eqn *eqn = wv->equation; + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); const enum gkyl_spacetime_gauge spacetime_gauge = gr_ultra_rel_euler->spacetime_gauge; if (spacetime_gauge == GKYL_STATIC_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_ultra_rel_euler->spacetime; + const struct gkyl_gr_spacetime *spacetime = gr_ultra_rel_euler->spacetime; int reinit_freq = gr_ultra_rel_euler->reinit_freq; - - for (int i = loidx_c; i<= upidx_c; i++) { + + for (int i = loidx_c; i <= upidx_c; i++) { idxl[dir] = i; double *qnew = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); @@ -580,25 +698,25 @@ gr_ultra_rel_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -610,47 +728,96 @@ gr_ultra_rel_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd spacetime->excision_region_func(spacetime, 0.0, x, y, z, &in_excision_region); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, z, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[4] = lapse; - qnew[5] = shift[0]; qnew[6] = shift[1]; qnew[7] = shift[2]; - - qnew[8] = spatial_metric[0][0]; qnew[9] = spatial_metric[0][1]; qnew[10] = spatial_metric[0][2]; - qnew[11] = spatial_metric[1][0]; qnew[12] = spatial_metric[1][1]; qnew[13] = spatial_metric[1][2]; - qnew[14] = spatial_metric[2][0]; qnew[15] = spatial_metric[2][1]; qnew[16] = spatial_metric[2][2]; - - qnew[17] = extrinsic_curvature[0][0]; qnew[18] = extrinsic_curvature[0][1]; qnew[19] = extrinsic_curvature[0][2]; - qnew[20] = extrinsic_curvature[1][0]; qnew[21] = extrinsic_curvature[1][1]; qnew[22] = extrinsic_curvature[1][2]; - qnew[23] = extrinsic_curvature[2][0]; qnew[24] = extrinsic_curvature[2][1]; qnew[25] = extrinsic_curvature[2][2]; + qnew[5] = shift[0]; + qnew[6] = shift[1]; + qnew[7] = shift[2]; + + qnew[8] = spatial_metric[0][0]; + qnew[9] = spatial_metric[0][1]; + qnew[10] = spatial_metric[0][2]; + qnew[11] = spatial_metric[1][0]; + qnew[12] = spatial_metric[1][1]; + qnew[13] = spatial_metric[1][2]; + qnew[14] = spatial_metric[2][0]; + qnew[15] = spatial_metric[2][1]; + qnew[16] = spatial_metric[2][2]; + + qnew[17] = extrinsic_curvature[0][0]; + qnew[18] = extrinsic_curvature[0][1]; + qnew[19] = extrinsic_curvature[0][2]; + qnew[20] = extrinsic_curvature[1][0]; + qnew[21] = extrinsic_curvature[1][1]; + qnew[22] = extrinsic_curvature[1][2]; + qnew[23] = extrinsic_curvature[2][0]; + qnew[24] = extrinsic_curvature[2][1]; + qnew[25] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[26] = -1.0; - } - else { + } else { qnew[26] = 1.0; } - qnew[27] = lapse_der[0]; qnew[28] = lapse_der[1]; qnew[29] = lapse_der[2]; - - qnew[30] = shift_der[0][0]; qnew[31] = shift_der[0][1]; qnew[32] = shift_der[0][2]; - qnew[33] = shift_der[1][0]; qnew[34] = shift_der[1][1]; qnew[35] = shift_der[1][2]; - qnew[36] = shift_der[2][0]; qnew[37] = shift_der[2][1]; qnew[38] = shift_der[2][2]; - - qnew[39] = spatial_metric_der[0][0][0]; qnew[40] = spatial_metric_der[0][0][1]; qnew[41] = spatial_metric_der[0][0][2]; - qnew[42] = spatial_metric_der[0][1][0]; qnew[43] = spatial_metric_der[0][1][1]; qnew[44] = spatial_metric_der[0][1][2]; - qnew[45] = spatial_metric_der[0][2][0]; qnew[46] = spatial_metric_der[0][2][1]; qnew[47] = spatial_metric_der[0][2][2]; - - qnew[48] = spatial_metric_der[1][0][0]; qnew[49] = spatial_metric_der[1][0][1]; qnew[50] = spatial_metric_der[1][0][2]; - qnew[51] = spatial_metric_der[1][1][0]; qnew[52] = spatial_metric_der[1][1][1]; qnew[53] = spatial_metric_der[1][1][2]; - qnew[54] = spatial_metric_der[1][2][0]; qnew[55] = spatial_metric_der[1][2][1]; qnew[56] = spatial_metric_der[1][2][2]; - - qnew[57] = spatial_metric_der[2][0][0]; qnew[58] = spatial_metric_der[2][0][1]; qnew[59] = spatial_metric_der[2][0][2]; - qnew[60] = spatial_metric_der[2][1][0]; qnew[61] = spatial_metric_der[2][1][1]; qnew[62] = spatial_metric_der[2][1][2]; - qnew[63] = spatial_metric_der[2][2][0]; qnew[64] = spatial_metric_der[2][2][1]; qnew[65] = spatial_metric_der[2][2][2]; + qnew[27] = lapse_der[0]; + qnew[28] = lapse_der[1]; + qnew[29] = lapse_der[2]; + + qnew[30] = shift_der[0][0]; + qnew[31] = shift_der[0][1]; + qnew[32] = shift_der[0][2]; + qnew[33] = shift_der[1][0]; + qnew[34] = shift_der[1][1]; + qnew[35] = shift_der[1][2]; + qnew[36] = shift_der[2][0]; + qnew[37] = shift_der[2][1]; + qnew[38] = shift_der[2][2]; + + qnew[39] = spatial_metric_der[0][0][0]; + qnew[40] = spatial_metric_der[0][0][1]; + qnew[41] = spatial_metric_der[0][0][2]; + qnew[42] = spatial_metric_der[0][1][0]; + qnew[43] = spatial_metric_der[0][1][1]; + qnew[44] = spatial_metric_der[0][1][2]; + qnew[45] = spatial_metric_der[0][2][0]; + qnew[46] = spatial_metric_der[0][2][1]; + qnew[47] = spatial_metric_der[0][2][2]; + + qnew[48] = spatial_metric_der[1][0][0]; + qnew[49] = spatial_metric_der[1][0][1]; + qnew[50] = spatial_metric_der[1][0][2]; + qnew[51] = spatial_metric_der[1][1][0]; + qnew[52] = spatial_metric_der[1][1][1]; + qnew[53] = spatial_metric_der[1][1][2]; + qnew[54] = spatial_metric_der[1][2][0]; + qnew[55] = spatial_metric_der[1][2][1]; + qnew[56] = spatial_metric_der[1][2][2]; + + qnew[57] = spatial_metric_der[2][0][0]; + qnew[58] = spatial_metric_der[2][0][1]; + qnew[59] = spatial_metric_der[2][0][2]; + qnew[60] = spatial_metric_der[2][1][0]; + qnew[61] = spatial_metric_der[2][1][1]; + qnew[62] = spatial_metric_der[2][1][2]; + qnew[63] = spatial_metric_der[2][2][0]; + qnew[64] = spatial_metric_der[2][2][1]; + qnew[65] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 66; i++) { @@ -663,7 +830,7 @@ gr_ultra_rel_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -677,14 +844,12 @@ gr_ultra_rel_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd gkyl_free(spatial_metric_der); qnew[66] = 0.0; - } - else { + } else { qnew[66] += 1.0; } } - } - else if (spacetime_gauge == GKYL_BLACKHOLE_COLLAPSE_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_ultra_rel_euler->spacetime; + } else if (spacetime_gauge == GKYL_BLACKHOLE_COLLAPSE_GAUGE) { + const struct gkyl_gr_spacetime *spacetime = gr_ultra_rel_euler->spacetime; const struct gr_blackhole *blackhole = container_of(spacetime, struct gr_blackhole, spacetime); double mass = blackhole->mass; @@ -709,31 +874,32 @@ gr_ultra_rel_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd double y = qnew[68]; double z = qnew[69]; - struct gkyl_gr_spacetime *new_spacetime = gkyl_gr_blackhole_new(false, fmin(evol_param, mass), spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *new_spacetime = + gkyl_gr_blackhole_new(false, fmin(evol_param, mass), spin, pos_x, pos_y, pos_z); double lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -745,47 +911,96 @@ gr_ultra_rel_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd new_spacetime->excision_region_func(new_spacetime, 0.0, x, y, z, &in_excision_region); new_spacetime->spatial_metric_tensor_func(new_spacetime, 0.0, x, y, z, &spatial_metric); - new_spacetime->extrinsic_curvature_tensor_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - new_spacetime->lapse_function_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - new_spacetime->shift_vector_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - new_spacetime->spatial_metric_tensor_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + new_spacetime->extrinsic_curvature_tensor_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + new_spacetime->lapse_function_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + new_spacetime->shift_vector_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + new_spacetime->spatial_metric_tensor_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[4] = lapse; - qnew[5] = shift[0]; qnew[6] = shift[1]; qnew[7] = shift[2]; - - qnew[8] = spatial_metric[0][0]; qnew[9] = spatial_metric[0][1]; qnew[10] = spatial_metric[0][2]; - qnew[11] = spatial_metric[1][0]; qnew[12] = spatial_metric[1][1]; qnew[13] = spatial_metric[1][2]; - qnew[14] = spatial_metric[2][0]; qnew[15] = spatial_metric[2][1]; qnew[16] = spatial_metric[2][2]; - - qnew[17] = extrinsic_curvature[0][0]; qnew[18] = extrinsic_curvature[0][1]; qnew[19] = extrinsic_curvature[0][2]; - qnew[20] = extrinsic_curvature[1][0]; qnew[21] = extrinsic_curvature[1][1]; qnew[22] = extrinsic_curvature[1][2]; - qnew[23] = extrinsic_curvature[2][0]; qnew[24] = extrinsic_curvature[2][1]; qnew[25] = extrinsic_curvature[2][2]; + qnew[5] = shift[0]; + qnew[6] = shift[1]; + qnew[7] = shift[2]; + + qnew[8] = spatial_metric[0][0]; + qnew[9] = spatial_metric[0][1]; + qnew[10] = spatial_metric[0][2]; + qnew[11] = spatial_metric[1][0]; + qnew[12] = spatial_metric[1][1]; + qnew[13] = spatial_metric[1][2]; + qnew[14] = spatial_metric[2][0]; + qnew[15] = spatial_metric[2][1]; + qnew[16] = spatial_metric[2][2]; + + qnew[17] = extrinsic_curvature[0][0]; + qnew[18] = extrinsic_curvature[0][1]; + qnew[19] = extrinsic_curvature[0][2]; + qnew[20] = extrinsic_curvature[1][0]; + qnew[21] = extrinsic_curvature[1][1]; + qnew[22] = extrinsic_curvature[1][2]; + qnew[23] = extrinsic_curvature[2][0]; + qnew[24] = extrinsic_curvature[2][1]; + qnew[25] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[26] = -1.0; - } - else { + } else { qnew[26] = 1.0; } - qnew[27] = lapse_der[0]; qnew[28] = lapse_der[1]; qnew[29] = lapse_der[2]; - - qnew[30] = shift_der[0][0]; qnew[31] = shift_der[0][1]; qnew[32] = shift_der[0][2]; - qnew[33] = shift_der[1][0]; qnew[34] = shift_der[1][1]; qnew[35] = shift_der[1][2]; - qnew[36] = shift_der[2][0]; qnew[37] = shift_der[2][1]; qnew[38] = shift_der[2][2]; - - qnew[39] = spatial_metric_der[0][0][0]; qnew[40] = spatial_metric_der[0][0][1]; qnew[41] = spatial_metric_der[0][0][2]; - qnew[42] = spatial_metric_der[0][1][0]; qnew[43] = spatial_metric_der[0][1][1]; qnew[44] = spatial_metric_der[0][1][2]; - qnew[45] = spatial_metric_der[0][2][0]; qnew[46] = spatial_metric_der[0][2][1]; qnew[47] = spatial_metric_der[0][2][2]; - - qnew[48] = spatial_metric_der[1][0][0]; qnew[49] = spatial_metric_der[1][0][1]; qnew[50] = spatial_metric_der[1][0][2]; - qnew[51] = spatial_metric_der[1][1][0]; qnew[52] = spatial_metric_der[1][1][1]; qnew[53] = spatial_metric_der[1][1][2]; - qnew[54] = spatial_metric_der[1][2][0]; qnew[55] = spatial_metric_der[1][2][1]; qnew[56] = spatial_metric_der[1][2][2]; - - qnew[57] = spatial_metric_der[2][0][0]; qnew[58] = spatial_metric_der[2][0][1]; qnew[59] = spatial_metric_der[2][0][2]; - qnew[60] = spatial_metric_der[2][1][0]; qnew[61] = spatial_metric_der[2][1][1]; qnew[62] = spatial_metric_der[2][1][2]; - qnew[63] = spatial_metric_der[2][2][0]; qnew[64] = spatial_metric_der[2][2][1]; qnew[65] = spatial_metric_der[2][2][2]; + qnew[27] = lapse_der[0]; + qnew[28] = lapse_der[1]; + qnew[29] = lapse_der[2]; + + qnew[30] = shift_der[0][0]; + qnew[31] = shift_der[0][1]; + qnew[32] = shift_der[0][2]; + qnew[33] = shift_der[1][0]; + qnew[34] = shift_der[1][1]; + qnew[35] = shift_der[1][2]; + qnew[36] = shift_der[2][0]; + qnew[37] = shift_der[2][1]; + qnew[38] = shift_der[2][2]; + + qnew[39] = spatial_metric_der[0][0][0]; + qnew[40] = spatial_metric_der[0][0][1]; + qnew[41] = spatial_metric_der[0][0][2]; + qnew[42] = spatial_metric_der[0][1][0]; + qnew[43] = spatial_metric_der[0][1][1]; + qnew[44] = spatial_metric_der[0][1][2]; + qnew[45] = spatial_metric_der[0][2][0]; + qnew[46] = spatial_metric_der[0][2][1]; + qnew[47] = spatial_metric_der[0][2][2]; + + qnew[48] = spatial_metric_der[1][0][0]; + qnew[49] = spatial_metric_der[1][0][1]; + qnew[50] = spatial_metric_der[1][0][2]; + qnew[51] = spatial_metric_der[1][1][0]; + qnew[52] = spatial_metric_der[1][1][1]; + qnew[53] = spatial_metric_der[1][1][2]; + qnew[54] = spatial_metric_der[1][2][0]; + qnew[55] = spatial_metric_der[1][2][1]; + qnew[56] = spatial_metric_der[1][2][2]; + + qnew[57] = spatial_metric_der[2][0][0]; + qnew[58] = spatial_metric_der[2][0][1]; + qnew[59] = spatial_metric_der[2][0][2]; + qnew[60] = spatial_metric_der[2][1][0]; + qnew[61] = spatial_metric_der[2][1][1]; + qnew[62] = spatial_metric_der[2][1][2]; + qnew[63] = spatial_metric_der[2][2][0]; + qnew[64] = spatial_metric_der[2][2][1]; + qnew[65] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 66; i++) { @@ -798,7 +1013,7 @@ gr_ultra_rel_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -815,20 +1030,22 @@ gr_ultra_rel_euler_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd } } -void -gr_ultra_rel_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, int upidx_c, - struct gkyl_array *qout, int dir) +void gr_ultra_rel_euler_tetrad_impose_gauge( + gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, + int upidx_c, struct gkyl_array *qout, int dir +) { - const struct gkyl_wv_eqn* eqn = wv->equation; - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct gkyl_wv_eqn *eqn = wv->equation; + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); const enum gkyl_spacetime_gauge spacetime_gauge = gr_ultra_rel_euler_tetrad->spacetime_gauge; if (spacetime_gauge == GKYL_STATIC_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_ultra_rel_euler_tetrad->spacetime; + const struct gkyl_gr_spacetime *spacetime = gr_ultra_rel_euler_tetrad->spacetime; int reinit_freq = gr_ultra_rel_euler_tetrad->reinit_freq; - - for (int i = loidx_c; i<= upidx_c; i++) { + + for (int i = loidx_c; i <= upidx_c; i++) { idxl[dir] = i; double *qnew = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); @@ -843,25 +1060,25 @@ gr_ultra_rel_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_ran double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -873,47 +1090,96 @@ gr_ultra_rel_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_ran spacetime->excision_region_func(spacetime, 0.0, x, y, z, &in_excision_region); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, z, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[4] = lapse; - qnew[5] = shift[0]; qnew[6] = shift[1]; qnew[7] = shift[2]; - - qnew[8] = spatial_metric[0][0]; qnew[9] = spatial_metric[0][1]; qnew[10] = spatial_metric[0][2]; - qnew[11] = spatial_metric[1][0]; qnew[12] = spatial_metric[1][1]; qnew[13] = spatial_metric[1][2]; - qnew[14] = spatial_metric[2][0]; qnew[15] = spatial_metric[2][1]; qnew[16] = spatial_metric[2][2]; - - qnew[17] = extrinsic_curvature[0][0]; qnew[18] = extrinsic_curvature[0][1]; qnew[19] = extrinsic_curvature[0][2]; - qnew[20] = extrinsic_curvature[1][0]; qnew[21] = extrinsic_curvature[1][1]; qnew[22] = extrinsic_curvature[1][2]; - qnew[23] = extrinsic_curvature[2][0]; qnew[24] = extrinsic_curvature[2][1]; qnew[25] = extrinsic_curvature[2][2]; + qnew[5] = shift[0]; + qnew[6] = shift[1]; + qnew[7] = shift[2]; + + qnew[8] = spatial_metric[0][0]; + qnew[9] = spatial_metric[0][1]; + qnew[10] = spatial_metric[0][2]; + qnew[11] = spatial_metric[1][0]; + qnew[12] = spatial_metric[1][1]; + qnew[13] = spatial_metric[1][2]; + qnew[14] = spatial_metric[2][0]; + qnew[15] = spatial_metric[2][1]; + qnew[16] = spatial_metric[2][2]; + + qnew[17] = extrinsic_curvature[0][0]; + qnew[18] = extrinsic_curvature[0][1]; + qnew[19] = extrinsic_curvature[0][2]; + qnew[20] = extrinsic_curvature[1][0]; + qnew[21] = extrinsic_curvature[1][1]; + qnew[22] = extrinsic_curvature[1][2]; + qnew[23] = extrinsic_curvature[2][0]; + qnew[24] = extrinsic_curvature[2][1]; + qnew[25] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[26] = -1.0; - } - else { + } else { qnew[26] = 1.0; } - qnew[27] = lapse_der[0]; qnew[28] = lapse_der[1]; qnew[29] = lapse_der[2]; - - qnew[30] = shift_der[0][0]; qnew[31] = shift_der[0][1]; qnew[32] = shift_der[0][2]; - qnew[33] = shift_der[1][0]; qnew[34] = shift_der[1][1]; qnew[35] = shift_der[1][2]; - qnew[36] = shift_der[2][0]; qnew[37] = shift_der[2][1]; qnew[38] = shift_der[2][2]; - - qnew[39] = spatial_metric_der[0][0][0]; qnew[40] = spatial_metric_der[0][0][1]; qnew[41] = spatial_metric_der[0][0][2]; - qnew[42] = spatial_metric_der[0][1][0]; qnew[43] = spatial_metric_der[0][1][1]; qnew[44] = spatial_metric_der[0][1][2]; - qnew[45] = spatial_metric_der[0][2][0]; qnew[46] = spatial_metric_der[0][2][1]; qnew[47] = spatial_metric_der[0][2][2]; - - qnew[48] = spatial_metric_der[1][0][0]; qnew[49] = spatial_metric_der[1][0][1]; qnew[50] = spatial_metric_der[1][0][2]; - qnew[51] = spatial_metric_der[1][1][0]; qnew[52] = spatial_metric_der[1][1][1]; qnew[53] = spatial_metric_der[1][1][2]; - qnew[54] = spatial_metric_der[1][2][0]; qnew[55] = spatial_metric_der[1][2][1]; qnew[56] = spatial_metric_der[1][2][2]; - - qnew[57] = spatial_metric_der[2][0][0]; qnew[58] = spatial_metric_der[2][0][1]; qnew[59] = spatial_metric_der[2][0][2]; - qnew[60] = spatial_metric_der[2][1][0]; qnew[61] = spatial_metric_der[2][1][1]; qnew[62] = spatial_metric_der[2][1][2]; - qnew[63] = spatial_metric_der[2][2][0]; qnew[64] = spatial_metric_der[2][2][1]; qnew[65] = spatial_metric_der[2][2][2]; + qnew[27] = lapse_der[0]; + qnew[28] = lapse_der[1]; + qnew[29] = lapse_der[2]; + + qnew[30] = shift_der[0][0]; + qnew[31] = shift_der[0][1]; + qnew[32] = shift_der[0][2]; + qnew[33] = shift_der[1][0]; + qnew[34] = shift_der[1][1]; + qnew[35] = shift_der[1][2]; + qnew[36] = shift_der[2][0]; + qnew[37] = shift_der[2][1]; + qnew[38] = shift_der[2][2]; + + qnew[39] = spatial_metric_der[0][0][0]; + qnew[40] = spatial_metric_der[0][0][1]; + qnew[41] = spatial_metric_der[0][0][2]; + qnew[42] = spatial_metric_der[0][1][0]; + qnew[43] = spatial_metric_der[0][1][1]; + qnew[44] = spatial_metric_der[0][1][2]; + qnew[45] = spatial_metric_der[0][2][0]; + qnew[46] = spatial_metric_der[0][2][1]; + qnew[47] = spatial_metric_der[0][2][2]; + + qnew[48] = spatial_metric_der[1][0][0]; + qnew[49] = spatial_metric_der[1][0][1]; + qnew[50] = spatial_metric_der[1][0][2]; + qnew[51] = spatial_metric_der[1][1][0]; + qnew[52] = spatial_metric_der[1][1][1]; + qnew[53] = spatial_metric_der[1][1][2]; + qnew[54] = spatial_metric_der[1][2][0]; + qnew[55] = spatial_metric_der[1][2][1]; + qnew[56] = spatial_metric_der[1][2][2]; + + qnew[57] = spatial_metric_der[2][0][0]; + qnew[58] = spatial_metric_der[2][0][1]; + qnew[59] = spatial_metric_der[2][0][2]; + qnew[60] = spatial_metric_der[2][1][0]; + qnew[61] = spatial_metric_der[2][1][1]; + qnew[62] = spatial_metric_der[2][1][2]; + qnew[63] = spatial_metric_der[2][2][0]; + qnew[64] = spatial_metric_der[2][2][1]; + qnew[65] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 66; i++) { @@ -926,7 +1192,7 @@ gr_ultra_rel_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_ran gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -940,14 +1206,12 @@ gr_ultra_rel_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_ran gkyl_free(spatial_metric_der); qnew[66] = 0.0; - } - else { + } else { qnew[66] += 1.0; } } - } - else if (spacetime_gauge == GKYL_BLACKHOLE_COLLAPSE_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_ultra_rel_euler_tetrad->spacetime; + } else if (spacetime_gauge == GKYL_BLACKHOLE_COLLAPSE_GAUGE) { + const struct gkyl_gr_spacetime *spacetime = gr_ultra_rel_euler_tetrad->spacetime; const struct gr_blackhole *blackhole = container_of(spacetime, struct gr_blackhole, spacetime); double mass = blackhole->mass; @@ -972,31 +1236,32 @@ gr_ultra_rel_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_ran double y = qnew[68]; double z = qnew[69]; - struct gkyl_gr_spacetime *new_spacetime = gkyl_gr_blackhole_new(false, fmin(evol_param, mass), spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *new_spacetime = + gkyl_gr_blackhole_new(false, fmin(evol_param, mass), spin, pos_x, pos_y, pos_z); double lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1008,47 +1273,96 @@ gr_ultra_rel_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_ran new_spacetime->excision_region_func(new_spacetime, 0.0, x, y, z, &in_excision_region); new_spacetime->spatial_metric_tensor_func(new_spacetime, 0.0, x, y, z, &spatial_metric); - new_spacetime->extrinsic_curvature_tensor_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - new_spacetime->lapse_function_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - new_spacetime->shift_vector_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - new_spacetime->spatial_metric_tensor_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + new_spacetime->extrinsic_curvature_tensor_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + new_spacetime->lapse_function_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + new_spacetime->shift_vector_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + new_spacetime->spatial_metric_tensor_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[4] = lapse; - qnew[5] = shift[0]; qnew[6] = shift[1]; qnew[7] = shift[2]; - - qnew[8] = spatial_metric[0][0]; qnew[9] = spatial_metric[0][1]; qnew[10] = spatial_metric[0][2]; - qnew[11] = spatial_metric[1][0]; qnew[12] = spatial_metric[1][1]; qnew[13] = spatial_metric[1][2]; - qnew[14] = spatial_metric[2][0]; qnew[15] = spatial_metric[2][1]; qnew[16] = spatial_metric[2][2]; - - qnew[17] = extrinsic_curvature[0][0]; qnew[18] = extrinsic_curvature[0][1]; qnew[19] = extrinsic_curvature[0][2]; - qnew[20] = extrinsic_curvature[1][0]; qnew[21] = extrinsic_curvature[1][1]; qnew[22] = extrinsic_curvature[1][2]; - qnew[23] = extrinsic_curvature[2][0]; qnew[24] = extrinsic_curvature[2][1]; qnew[25] = extrinsic_curvature[2][2]; + qnew[5] = shift[0]; + qnew[6] = shift[1]; + qnew[7] = shift[2]; + + qnew[8] = spatial_metric[0][0]; + qnew[9] = spatial_metric[0][1]; + qnew[10] = spatial_metric[0][2]; + qnew[11] = spatial_metric[1][0]; + qnew[12] = spatial_metric[1][1]; + qnew[13] = spatial_metric[1][2]; + qnew[14] = spatial_metric[2][0]; + qnew[15] = spatial_metric[2][1]; + qnew[16] = spatial_metric[2][2]; + + qnew[17] = extrinsic_curvature[0][0]; + qnew[18] = extrinsic_curvature[0][1]; + qnew[19] = extrinsic_curvature[0][2]; + qnew[20] = extrinsic_curvature[1][0]; + qnew[21] = extrinsic_curvature[1][1]; + qnew[22] = extrinsic_curvature[1][2]; + qnew[23] = extrinsic_curvature[2][0]; + qnew[24] = extrinsic_curvature[2][1]; + qnew[25] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[26] = -1.0; - } - else { + } else { qnew[26] = 1.0; } - qnew[27] = lapse_der[0]; qnew[28] = lapse_der[1]; qnew[29] = lapse_der[2]; - - qnew[30] = shift_der[0][0]; qnew[31] = shift_der[0][1]; qnew[32] = shift_der[0][2]; - qnew[33] = shift_der[1][0]; qnew[34] = shift_der[1][1]; qnew[35] = shift_der[1][2]; - qnew[36] = shift_der[2][0]; qnew[37] = shift_der[2][1]; qnew[38] = shift_der[2][2]; - - qnew[39] = spatial_metric_der[0][0][0]; qnew[40] = spatial_metric_der[0][0][1]; qnew[41] = spatial_metric_der[0][0][2]; - qnew[42] = spatial_metric_der[0][1][0]; qnew[43] = spatial_metric_der[0][1][1]; qnew[44] = spatial_metric_der[0][1][2]; - qnew[45] = spatial_metric_der[0][2][0]; qnew[46] = spatial_metric_der[0][2][1]; qnew[47] = spatial_metric_der[0][2][2]; - - qnew[48] = spatial_metric_der[1][0][0]; qnew[49] = spatial_metric_der[1][0][1]; qnew[50] = spatial_metric_der[1][0][2]; - qnew[51] = spatial_metric_der[1][1][0]; qnew[52] = spatial_metric_der[1][1][1]; qnew[53] = spatial_metric_der[1][1][2]; - qnew[54] = spatial_metric_der[1][2][0]; qnew[55] = spatial_metric_der[1][2][1]; qnew[56] = spatial_metric_der[1][2][2]; - - qnew[57] = spatial_metric_der[2][0][0]; qnew[58] = spatial_metric_der[2][0][1]; qnew[59] = spatial_metric_der[2][0][2]; - qnew[60] = spatial_metric_der[2][1][0]; qnew[61] = spatial_metric_der[2][1][1]; qnew[62] = spatial_metric_der[2][1][2]; - qnew[63] = spatial_metric_der[2][2][0]; qnew[64] = spatial_metric_der[2][2][1]; qnew[65] = spatial_metric_der[2][2][2]; + qnew[27] = lapse_der[0]; + qnew[28] = lapse_der[1]; + qnew[29] = lapse_der[2]; + + qnew[30] = shift_der[0][0]; + qnew[31] = shift_der[0][1]; + qnew[32] = shift_der[0][2]; + qnew[33] = shift_der[1][0]; + qnew[34] = shift_der[1][1]; + qnew[35] = shift_der[1][2]; + qnew[36] = shift_der[2][0]; + qnew[37] = shift_der[2][1]; + qnew[38] = shift_der[2][2]; + + qnew[39] = spatial_metric_der[0][0][0]; + qnew[40] = spatial_metric_der[0][0][1]; + qnew[41] = spatial_metric_der[0][0][2]; + qnew[42] = spatial_metric_der[0][1][0]; + qnew[43] = spatial_metric_der[0][1][1]; + qnew[44] = spatial_metric_der[0][1][2]; + qnew[45] = spatial_metric_der[0][2][0]; + qnew[46] = spatial_metric_der[0][2][1]; + qnew[47] = spatial_metric_der[0][2][2]; + + qnew[48] = spatial_metric_der[1][0][0]; + qnew[49] = spatial_metric_der[1][0][1]; + qnew[50] = spatial_metric_der[1][0][2]; + qnew[51] = spatial_metric_der[1][1][0]; + qnew[52] = spatial_metric_der[1][1][1]; + qnew[53] = spatial_metric_der[1][1][2]; + qnew[54] = spatial_metric_der[1][2][0]; + qnew[55] = spatial_metric_der[1][2][1]; + qnew[56] = spatial_metric_der[1][2][2]; + + qnew[57] = spatial_metric_der[2][0][0]; + qnew[58] = spatial_metric_der[2][0][1]; + qnew[59] = spatial_metric_der[2][0][2]; + qnew[60] = spatial_metric_der[2][1][0]; + qnew[61] = spatial_metric_der[2][1][1]; + qnew[62] = spatial_metric_der[2][1][2]; + qnew[63] = spatial_metric_der[2][2][0]; + qnew[64] = spatial_metric_der[2][2][1]; + qnew[65] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 66; i++) { @@ -1061,7 +1375,7 @@ gr_ultra_rel_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_ran gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -1078,20 +1392,21 @@ gr_ultra_rel_euler_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_ran } } -void -gr_twofluid_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, int upidx_c, - struct gkyl_array *qout, int dir) +void gr_twofluid_impose_gauge( + gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, + int upidx_c, struct gkyl_array *qout, int dir +) { - const struct gkyl_wv_eqn* eqn = wv->equation; + const struct gkyl_wv_eqn *eqn = wv->equation; const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); - + const enum gkyl_spacetime_gauge spacetime_gauge = gr_twofluid->spacetime_gauge; if (spacetime_gauge == GKYL_STATIC_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_twofluid->spacetime; + const struct gkyl_gr_spacetime *spacetime = gr_twofluid->spacetime; int reinit_freq = gr_twofluid->reinit_freq; - - for (int i = loidx_c; i<= upidx_c; i++) { + + for (int i = loidx_c; i <= upidx_c; i++) { idxl[dir] = i; double *qnew = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); @@ -1106,25 +1421,25 @@ gr_twofluid_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_ran double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1136,47 +1451,96 @@ gr_twofluid_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_ran spacetime->excision_region_func(spacetime, 0.0, x, y, z, &in_excision_region); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, z, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[18] = lapse; - qnew[19] = shift[0]; qnew[20] = shift[1]; qnew[21] = shift[2]; - - qnew[22] = spatial_metric[0][0]; qnew[23] = spatial_metric[0][1]; qnew[24] = spatial_metric[0][2]; - qnew[25] = spatial_metric[1][0]; qnew[26] = spatial_metric[1][1]; qnew[27] = spatial_metric[1][2]; - qnew[28] = spatial_metric[2][0]; qnew[29] = spatial_metric[2][1]; qnew[30] = spatial_metric[2][2]; - - qnew[31] = extrinsic_curvature[0][0]; qnew[32] = extrinsic_curvature[0][1]; qnew[33] = extrinsic_curvature[0][2]; - qnew[34] = extrinsic_curvature[1][0]; qnew[35] = extrinsic_curvature[1][1]; qnew[36] = extrinsic_curvature[1][2]; - qnew[37] = extrinsic_curvature[2][0]; qnew[38] = extrinsic_curvature[2][1]; qnew[39] = extrinsic_curvature[2][2]; + qnew[19] = shift[0]; + qnew[20] = shift[1]; + qnew[21] = shift[2]; + + qnew[22] = spatial_metric[0][0]; + qnew[23] = spatial_metric[0][1]; + qnew[24] = spatial_metric[0][2]; + qnew[25] = spatial_metric[1][0]; + qnew[26] = spatial_metric[1][1]; + qnew[27] = spatial_metric[1][2]; + qnew[28] = spatial_metric[2][0]; + qnew[29] = spatial_metric[2][1]; + qnew[30] = spatial_metric[2][2]; + + qnew[31] = extrinsic_curvature[0][0]; + qnew[32] = extrinsic_curvature[0][1]; + qnew[33] = extrinsic_curvature[0][2]; + qnew[34] = extrinsic_curvature[1][0]; + qnew[35] = extrinsic_curvature[1][1]; + qnew[36] = extrinsic_curvature[1][2]; + qnew[37] = extrinsic_curvature[2][0]; + qnew[38] = extrinsic_curvature[2][1]; + qnew[39] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[40] = -1.0; - } - else { + } else { qnew[40] = 1.0; } - qnew[41] = lapse_der[0]; qnew[42] = lapse_der[1]; qnew[43] = lapse_der[2]; - - qnew[44] = shift_der[0][0]; qnew[45] = shift_der[0][1]; qnew[46] = shift_der[0][2]; - qnew[47] = shift_der[1][0]; qnew[48] = shift_der[1][1]; qnew[49] = shift_der[1][2]; - qnew[50] = shift_der[2][0]; qnew[51] = shift_der[2][1]; qnew[52] = shift_der[2][2]; - - qnew[53] = spatial_metric_der[0][0][0]; qnew[54] = spatial_metric_der[0][0][1]; qnew[55] = spatial_metric_der[0][0][2]; - qnew[56] = spatial_metric_der[0][1][0]; qnew[57] = spatial_metric_der[0][1][1]; qnew[58] = spatial_metric_der[0][1][2]; - qnew[59] = spatial_metric_der[0][2][0]; qnew[60] = spatial_metric_der[0][2][1]; qnew[61] = spatial_metric_der[0][2][2]; - - qnew[62] = spatial_metric_der[1][0][0]; qnew[63] = spatial_metric_der[1][0][1]; qnew[64] = spatial_metric_der[1][0][2]; - qnew[65] = spatial_metric_der[1][1][0]; qnew[66] = spatial_metric_der[1][1][1]; qnew[67] = spatial_metric_der[1][1][2]; - qnew[68] = spatial_metric_der[1][2][0]; qnew[69] = spatial_metric_der[1][2][1]; qnew[70] = spatial_metric_der[1][2][2]; - - qnew[71] = spatial_metric_der[2][0][0]; qnew[72] = spatial_metric_der[2][0][1]; qnew[73] = spatial_metric_der[2][0][2]; - qnew[74] = spatial_metric_der[2][1][0]; qnew[75] = spatial_metric_der[2][1][1]; qnew[76] = spatial_metric_der[2][1][2]; - qnew[77] = spatial_metric_der[2][2][0]; qnew[78] = spatial_metric_der[2][2][1]; qnew[79] = spatial_metric_der[2][2][2]; + qnew[41] = lapse_der[0]; + qnew[42] = lapse_der[1]; + qnew[43] = lapse_der[2]; + + qnew[44] = shift_der[0][0]; + qnew[45] = shift_der[0][1]; + qnew[46] = shift_der[0][2]; + qnew[47] = shift_der[1][0]; + qnew[48] = shift_der[1][1]; + qnew[49] = shift_der[1][2]; + qnew[50] = shift_der[2][0]; + qnew[51] = shift_der[2][1]; + qnew[52] = shift_der[2][2]; + + qnew[53] = spatial_metric_der[0][0][0]; + qnew[54] = spatial_metric_der[0][0][1]; + qnew[55] = spatial_metric_der[0][0][2]; + qnew[56] = spatial_metric_der[0][1][0]; + qnew[57] = spatial_metric_der[0][1][1]; + qnew[58] = spatial_metric_der[0][1][2]; + qnew[59] = spatial_metric_der[0][2][0]; + qnew[60] = spatial_metric_der[0][2][1]; + qnew[61] = spatial_metric_der[0][2][2]; + + qnew[62] = spatial_metric_der[1][0][0]; + qnew[63] = spatial_metric_der[1][0][1]; + qnew[64] = spatial_metric_der[1][0][2]; + qnew[65] = spatial_metric_der[1][1][0]; + qnew[66] = spatial_metric_der[1][1][1]; + qnew[67] = spatial_metric_der[1][1][2]; + qnew[68] = spatial_metric_der[1][2][0]; + qnew[69] = spatial_metric_der[1][2][1]; + qnew[70] = spatial_metric_der[1][2][2]; + + qnew[71] = spatial_metric_der[2][0][0]; + qnew[72] = spatial_metric_der[2][0][1]; + qnew[73] = spatial_metric_der[2][0][2]; + qnew[74] = spatial_metric_der[2][1][0]; + qnew[75] = spatial_metric_der[2][1][1]; + qnew[76] = spatial_metric_der[2][1][2]; + qnew[77] = spatial_metric_der[2][2][0]; + qnew[78] = spatial_metric_der[2][2][1]; + qnew[79] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 80; i++) { @@ -1189,7 +1553,7 @@ gr_twofluid_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_ran gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -1201,30 +1565,31 @@ gr_twofluid_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_ran gkyl_free(lapse_der); gkyl_free(shift_der); gkyl_free(spatial_metric_der); - + qnew[80] = 0.0; - } - else { + } else { qnew[80] += 1.0; } } } } -void -gr_twofluid_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, int upidx_c, - struct gkyl_array *qout, int dir) +void gr_twofluid_tetrad_impose_gauge( + gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, + int upidx_c, struct gkyl_array *qout, int dir +) { - const struct gkyl_wv_eqn* eqn = wv->equation; - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); - + const struct gkyl_wv_eqn *eqn = wv->equation; + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const enum gkyl_spacetime_gauge spacetime_gauge = gr_twofluid_tetrad->spacetime_gauge; if (spacetime_gauge == GKYL_STATIC_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_twofluid_tetrad->spacetime; + const struct gkyl_gr_spacetime *spacetime = gr_twofluid_tetrad->spacetime; int reinit_freq = gr_twofluid_tetrad->reinit_freq; - - for (int i = loidx_c; i<= upidx_c; i++) { + + for (int i = loidx_c; i <= upidx_c; i++) { idxl[dir] = i; double *qnew = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); @@ -1239,25 +1604,25 @@ gr_twofluid_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1269,47 +1634,96 @@ gr_twofluid_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd spacetime->excision_region_func(spacetime, 0.0, x, y, z, &in_excision_region); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, z, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[18] = lapse; - qnew[19] = shift[0]; qnew[20] = shift[1]; qnew[21] = shift[2]; - - qnew[22] = spatial_metric[0][0]; qnew[23] = spatial_metric[0][1]; qnew[24] = spatial_metric[0][2]; - qnew[25] = spatial_metric[1][0]; qnew[26] = spatial_metric[1][1]; qnew[27] = spatial_metric[1][2]; - qnew[28] = spatial_metric[2][0]; qnew[29] = spatial_metric[2][1]; qnew[30] = spatial_metric[2][2]; - - qnew[31] = extrinsic_curvature[0][0]; qnew[32] = extrinsic_curvature[0][1]; qnew[33] = extrinsic_curvature[0][2]; - qnew[34] = extrinsic_curvature[1][0]; qnew[35] = extrinsic_curvature[1][1]; qnew[36] = extrinsic_curvature[1][2]; - qnew[37] = extrinsic_curvature[2][0]; qnew[38] = extrinsic_curvature[2][1]; qnew[39] = extrinsic_curvature[2][2]; + qnew[19] = shift[0]; + qnew[20] = shift[1]; + qnew[21] = shift[2]; + + qnew[22] = spatial_metric[0][0]; + qnew[23] = spatial_metric[0][1]; + qnew[24] = spatial_metric[0][2]; + qnew[25] = spatial_metric[1][0]; + qnew[26] = spatial_metric[1][1]; + qnew[27] = spatial_metric[1][2]; + qnew[28] = spatial_metric[2][0]; + qnew[29] = spatial_metric[2][1]; + qnew[30] = spatial_metric[2][2]; + + qnew[31] = extrinsic_curvature[0][0]; + qnew[32] = extrinsic_curvature[0][1]; + qnew[33] = extrinsic_curvature[0][2]; + qnew[34] = extrinsic_curvature[1][0]; + qnew[35] = extrinsic_curvature[1][1]; + qnew[36] = extrinsic_curvature[1][2]; + qnew[37] = extrinsic_curvature[2][0]; + qnew[38] = extrinsic_curvature[2][1]; + qnew[39] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[40] = -1.0; - } - else { + } else { qnew[40] = 1.0; } - qnew[41] = lapse_der[0]; qnew[42] = lapse_der[1]; qnew[43] = lapse_der[2]; - - qnew[44] = shift_der[0][0]; qnew[45] = shift_der[0][1]; qnew[46] = shift_der[0][2]; - qnew[47] = shift_der[1][0]; qnew[48] = shift_der[1][1]; qnew[49] = shift_der[1][2]; - qnew[50] = shift_der[2][0]; qnew[51] = shift_der[2][1]; qnew[52] = shift_der[2][2]; - - qnew[53] = spatial_metric_der[0][0][0]; qnew[54] = spatial_metric_der[0][0][1]; qnew[55] = spatial_metric_der[0][0][2]; - qnew[56] = spatial_metric_der[0][1][0]; qnew[57] = spatial_metric_der[0][1][1]; qnew[58] = spatial_metric_der[0][1][2]; - qnew[59] = spatial_metric_der[0][2][0]; qnew[60] = spatial_metric_der[0][2][1]; qnew[61] = spatial_metric_der[0][2][2]; - - qnew[62] = spatial_metric_der[1][0][0]; qnew[63] = spatial_metric_der[1][0][1]; qnew[64] = spatial_metric_der[1][0][2]; - qnew[65] = spatial_metric_der[1][1][0]; qnew[66] = spatial_metric_der[1][1][1]; qnew[67] = spatial_metric_der[1][1][2]; - qnew[68] = spatial_metric_der[1][2][0]; qnew[69] = spatial_metric_der[1][2][1]; qnew[70] = spatial_metric_der[1][2][2]; - - qnew[71] = spatial_metric_der[2][0][0]; qnew[72] = spatial_metric_der[2][0][1]; qnew[73] = spatial_metric_der[2][0][2]; - qnew[74] = spatial_metric_der[2][1][0]; qnew[75] = spatial_metric_der[2][1][1]; qnew[76] = spatial_metric_der[2][1][2]; - qnew[77] = spatial_metric_der[2][2][0]; qnew[78] = spatial_metric_der[2][2][1]; qnew[79] = spatial_metric_der[2][2][2]; + qnew[41] = lapse_der[0]; + qnew[42] = lapse_der[1]; + qnew[43] = lapse_der[2]; + + qnew[44] = shift_der[0][0]; + qnew[45] = shift_der[0][1]; + qnew[46] = shift_der[0][2]; + qnew[47] = shift_der[1][0]; + qnew[48] = shift_der[1][1]; + qnew[49] = shift_der[1][2]; + qnew[50] = shift_der[2][0]; + qnew[51] = shift_der[2][1]; + qnew[52] = shift_der[2][2]; + + qnew[53] = spatial_metric_der[0][0][0]; + qnew[54] = spatial_metric_der[0][0][1]; + qnew[55] = spatial_metric_der[0][0][2]; + qnew[56] = spatial_metric_der[0][1][0]; + qnew[57] = spatial_metric_der[0][1][1]; + qnew[58] = spatial_metric_der[0][1][2]; + qnew[59] = spatial_metric_der[0][2][0]; + qnew[60] = spatial_metric_der[0][2][1]; + qnew[61] = spatial_metric_der[0][2][2]; + + qnew[62] = spatial_metric_der[1][0][0]; + qnew[63] = spatial_metric_der[1][0][1]; + qnew[64] = spatial_metric_der[1][0][2]; + qnew[65] = spatial_metric_der[1][1][0]; + qnew[66] = spatial_metric_der[1][1][1]; + qnew[67] = spatial_metric_der[1][1][2]; + qnew[68] = spatial_metric_der[1][2][0]; + qnew[69] = spatial_metric_der[1][2][1]; + qnew[70] = spatial_metric_der[1][2][2]; + + qnew[71] = spatial_metric_der[2][0][0]; + qnew[72] = spatial_metric_der[2][0][1]; + qnew[73] = spatial_metric_der[2][0][2]; + qnew[74] = spatial_metric_der[2][1][0]; + qnew[75] = spatial_metric_der[2][1][1]; + qnew[76] = spatial_metric_der[2][1][2]; + qnew[77] = spatial_metric_der[2][2][0]; + qnew[78] = spatial_metric_der[2][2][1]; + qnew[79] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 80; i++) { @@ -1322,7 +1736,7 @@ gr_twofluid_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -1334,30 +1748,30 @@ gr_twofluid_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *upd gkyl_free(lapse_der); gkyl_free(shift_der); gkyl_free(spatial_metric_der); - + qnew[80] = 0.0; - } - else { + } else { qnew[80] += 1.0; } } } } -void -gr_mhd_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, int upidx_c, - struct gkyl_array *qout, int dir) +void gr_mhd_impose_gauge( + gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, + int upidx_c, struct gkyl_array *qout, int dir +) { - const struct gkyl_wv_eqn* eqn = wv->equation; + const struct gkyl_wv_eqn *eqn = wv->equation; const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); - + const enum gkyl_spacetime_gauge spacetime_gauge = gr_mhd->spacetime_gauge; if (spacetime_gauge == GKYL_STATIC_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_mhd->spacetime; + const struct gkyl_gr_spacetime *spacetime = gr_mhd->spacetime; int reinit_freq = gr_mhd->reinit_freq; - - for (int i = loidx_c; i<= upidx_c; i++) { + + for (int i = loidx_c; i <= upidx_c; i++) { idxl[dir] = i; double *qnew = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); @@ -1372,25 +1786,25 @@ gr_mhd_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, i double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1402,47 +1816,96 @@ gr_mhd_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, i spacetime->excision_region_func(spacetime, 0.0, x, y, z, &in_excision_region); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, z, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[9] = lapse; - qnew[10] = shift[0]; qnew[11] = shift[1]; qnew[12] = shift[2]; - - qnew[13] = spatial_metric[0][0]; qnew[14] = spatial_metric[0][1]; qnew[15] = spatial_metric[0][2]; - qnew[16] = spatial_metric[1][0]; qnew[17] = spatial_metric[1][1]; qnew[18] = spatial_metric[1][2]; - qnew[19] = spatial_metric[2][0]; qnew[20] = spatial_metric[2][1]; qnew[21] = spatial_metric[2][2]; - - qnew[22] = extrinsic_curvature[0][0]; qnew[23] = extrinsic_curvature[0][1]; qnew[24] = extrinsic_curvature[0][2]; - qnew[25] = extrinsic_curvature[1][0]; qnew[26] = extrinsic_curvature[1][1]; qnew[27] = extrinsic_curvature[1][2]; - qnew[28] = extrinsic_curvature[2][0]; qnew[29] = extrinsic_curvature[2][1]; qnew[30] = extrinsic_curvature[2][2]; + qnew[10] = shift[0]; + qnew[11] = shift[1]; + qnew[12] = shift[2]; + + qnew[13] = spatial_metric[0][0]; + qnew[14] = spatial_metric[0][1]; + qnew[15] = spatial_metric[0][2]; + qnew[16] = spatial_metric[1][0]; + qnew[17] = spatial_metric[1][1]; + qnew[18] = spatial_metric[1][2]; + qnew[19] = spatial_metric[2][0]; + qnew[20] = spatial_metric[2][1]; + qnew[21] = spatial_metric[2][2]; + + qnew[22] = extrinsic_curvature[0][0]; + qnew[23] = extrinsic_curvature[0][1]; + qnew[24] = extrinsic_curvature[0][2]; + qnew[25] = extrinsic_curvature[1][0]; + qnew[26] = extrinsic_curvature[1][1]; + qnew[27] = extrinsic_curvature[1][2]; + qnew[28] = extrinsic_curvature[2][0]; + qnew[29] = extrinsic_curvature[2][1]; + qnew[30] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[31] = -1.0; - } - else { + } else { qnew[31] = 1.0; } - qnew[32] = lapse_der[0]; qnew[33] = lapse_der[1]; qnew[34] = lapse_der[2]; - - qnew[35] = shift_der[0][0]; qnew[36] = shift_der[0][1]; qnew[37] = shift_der[0][2]; - qnew[38] = shift_der[1][0]; qnew[39] = shift_der[1][1]; qnew[40] = shift_der[1][2]; - qnew[41] = shift_der[2][0]; qnew[42] = shift_der[2][1]; qnew[43] = shift_der[2][2]; - - qnew[44] = spatial_metric_der[0][0][0]; qnew[45] = spatial_metric_der[0][0][1]; qnew[46] = spatial_metric_der[0][0][2]; - qnew[47] = spatial_metric_der[0][1][0]; qnew[48] = spatial_metric_der[0][1][1]; qnew[49] = spatial_metric_der[0][1][2]; - qnew[50] = spatial_metric_der[0][2][0]; qnew[51] = spatial_metric_der[0][2][1]; qnew[52] = spatial_metric_der[0][2][2]; - - qnew[53] = spatial_metric_der[1][0][0]; qnew[54] = spatial_metric_der[1][0][1]; qnew[55] = spatial_metric_der[1][0][2]; - qnew[56] = spatial_metric_der[1][1][0]; qnew[57] = spatial_metric_der[1][1][1]; qnew[58] = spatial_metric_der[1][1][2]; - qnew[59] = spatial_metric_der[1][2][0]; qnew[60] = spatial_metric_der[1][2][1]; qnew[61] = spatial_metric_der[1][2][2]; - - qnew[62] = spatial_metric_der[2][0][0]; qnew[63] = spatial_metric_der[2][0][1]; qnew[64] = spatial_metric_der[2][0][2]; - qnew[65] = spatial_metric_der[2][1][0]; qnew[66] = spatial_metric_der[2][1][1]; qnew[67] = spatial_metric_der[2][1][2]; - qnew[68] = spatial_metric_der[2][2][0]; qnew[69] = spatial_metric_der[2][2][1]; qnew[70] = spatial_metric_der[2][2][2]; + qnew[32] = lapse_der[0]; + qnew[33] = lapse_der[1]; + qnew[34] = lapse_der[2]; + + qnew[35] = shift_der[0][0]; + qnew[36] = shift_der[0][1]; + qnew[37] = shift_der[0][2]; + qnew[38] = shift_der[1][0]; + qnew[39] = shift_der[1][1]; + qnew[40] = shift_der[1][2]; + qnew[41] = shift_der[2][0]; + qnew[42] = shift_der[2][1]; + qnew[43] = shift_der[2][2]; + + qnew[44] = spatial_metric_der[0][0][0]; + qnew[45] = spatial_metric_der[0][0][1]; + qnew[46] = spatial_metric_der[0][0][2]; + qnew[47] = spatial_metric_der[0][1][0]; + qnew[48] = spatial_metric_der[0][1][1]; + qnew[49] = spatial_metric_der[0][1][2]; + qnew[50] = spatial_metric_der[0][2][0]; + qnew[51] = spatial_metric_der[0][2][1]; + qnew[52] = spatial_metric_der[0][2][2]; + + qnew[53] = spatial_metric_der[1][0][0]; + qnew[54] = spatial_metric_der[1][0][1]; + qnew[55] = spatial_metric_der[1][0][2]; + qnew[56] = spatial_metric_der[1][1][0]; + qnew[57] = spatial_metric_der[1][1][1]; + qnew[58] = spatial_metric_der[1][1][2]; + qnew[59] = spatial_metric_der[1][2][0]; + qnew[60] = spatial_metric_der[1][2][1]; + qnew[61] = spatial_metric_der[1][2][2]; + + qnew[62] = spatial_metric_der[2][0][0]; + qnew[63] = spatial_metric_der[2][0][1]; + qnew[64] = spatial_metric_der[2][0][2]; + qnew[65] = spatial_metric_der[2][1][0]; + qnew[66] = spatial_metric_der[2][1][1]; + qnew[67] = spatial_metric_der[2][1][2]; + qnew[68] = spatial_metric_der[2][2][0]; + qnew[69] = spatial_metric_der[2][2][1]; + qnew[70] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -1455,7 +1918,7 @@ gr_mhd_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, i gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -1467,16 +1930,14 @@ gr_mhd_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, i gkyl_free(lapse_der); gkyl_free(shift_der); gkyl_free(spatial_metric_der); - + qnew[71] = 0.0; - } - else { + } else { qnew[71] += 1.0; } } - } - else if (spacetime_gauge == GKYL_BLACKHOLE_COLLAPSE_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_mhd->spacetime; + } else if (spacetime_gauge == GKYL_BLACKHOLE_COLLAPSE_GAUGE) { + const struct gkyl_gr_spacetime *spacetime = gr_mhd->spacetime; const struct gr_blackhole *blackhole = container_of(spacetime, struct gr_blackhole, spacetime); double mass = blackhole->mass; @@ -1501,31 +1962,32 @@ gr_mhd_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, i double y = qnew[73]; double z = qnew[74]; - struct gkyl_gr_spacetime *new_spacetime = gkyl_gr_blackhole_new(false, fmin(evol_param, mass), spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *new_spacetime = + gkyl_gr_blackhole_new(false, fmin(evol_param, mass), spin, pos_x, pos_y, pos_z); double lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1537,47 +1999,96 @@ gr_mhd_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, i new_spacetime->excision_region_func(new_spacetime, 0.0, x, y, z, &in_excision_region); new_spacetime->spatial_metric_tensor_func(new_spacetime, 0.0, x, y, z, &spatial_metric); - new_spacetime->extrinsic_curvature_tensor_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - new_spacetime->lapse_function_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - new_spacetime->shift_vector_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - new_spacetime->spatial_metric_tensor_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + new_spacetime->extrinsic_curvature_tensor_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + new_spacetime->lapse_function_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + new_spacetime->shift_vector_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + new_spacetime->spatial_metric_tensor_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[9] = lapse; - qnew[10] = shift[0]; qnew[11] = shift[1]; qnew[12] = shift[2]; - - qnew[13] = spatial_metric[0][0]; qnew[14] = spatial_metric[0][1]; qnew[15] = spatial_metric[0][2]; - qnew[16] = spatial_metric[1][0]; qnew[17] = spatial_metric[1][1]; qnew[18] = spatial_metric[1][2]; - qnew[19] = spatial_metric[2][0]; qnew[20] = spatial_metric[2][1]; qnew[21] = spatial_metric[2][2]; - - qnew[22] = extrinsic_curvature[0][0]; qnew[23] = extrinsic_curvature[0][1]; qnew[24] = extrinsic_curvature[0][2]; - qnew[25] = extrinsic_curvature[1][0]; qnew[26] = extrinsic_curvature[1][1]; qnew[27] = extrinsic_curvature[1][2]; - qnew[28] = extrinsic_curvature[2][0]; qnew[29] = extrinsic_curvature[2][1]; qnew[30] = extrinsic_curvature[2][2]; + qnew[10] = shift[0]; + qnew[11] = shift[1]; + qnew[12] = shift[2]; + + qnew[13] = spatial_metric[0][0]; + qnew[14] = spatial_metric[0][1]; + qnew[15] = spatial_metric[0][2]; + qnew[16] = spatial_metric[1][0]; + qnew[17] = spatial_metric[1][1]; + qnew[18] = spatial_metric[1][2]; + qnew[19] = spatial_metric[2][0]; + qnew[20] = spatial_metric[2][1]; + qnew[21] = spatial_metric[2][2]; + + qnew[22] = extrinsic_curvature[0][0]; + qnew[23] = extrinsic_curvature[0][1]; + qnew[24] = extrinsic_curvature[0][2]; + qnew[25] = extrinsic_curvature[1][0]; + qnew[26] = extrinsic_curvature[1][1]; + qnew[27] = extrinsic_curvature[1][2]; + qnew[28] = extrinsic_curvature[2][0]; + qnew[29] = extrinsic_curvature[2][1]; + qnew[30] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[31] = -1.0; - } - else { + } else { qnew[31] = 1.0; } - qnew[32] = lapse_der[0]; qnew[33] = lapse_der[1]; qnew[34] = lapse_der[2]; - - qnew[35] = shift_der[0][0]; qnew[36] = shift_der[0][1]; qnew[37] = shift_der[0][2]; - qnew[38] = shift_der[1][0]; qnew[39] = shift_der[1][1]; qnew[40] = shift_der[1][2]; - qnew[41] = shift_der[2][0]; qnew[42] = shift_der[2][1]; qnew[43] = shift_der[2][2]; - - qnew[44] = spatial_metric_der[0][0][0]; qnew[45] = spatial_metric_der[0][0][1]; qnew[46] = spatial_metric_der[0][0][2]; - qnew[47] = spatial_metric_der[0][1][0]; qnew[48] = spatial_metric_der[0][1][1]; qnew[49] = spatial_metric_der[0][1][2]; - qnew[50] = spatial_metric_der[0][2][0]; qnew[51] = spatial_metric_der[0][2][1]; qnew[52] = spatial_metric_der[0][2][2]; - - qnew[53] = spatial_metric_der[1][0][0]; qnew[54] = spatial_metric_der[1][0][1]; qnew[55] = spatial_metric_der[1][0][2]; - qnew[56] = spatial_metric_der[1][1][0]; qnew[57] = spatial_metric_der[1][1][1]; qnew[58] = spatial_metric_der[1][1][2]; - qnew[59] = spatial_metric_der[1][2][0]; qnew[60] = spatial_metric_der[1][2][1]; qnew[61] = spatial_metric_der[1][2][2]; - - qnew[62] = spatial_metric_der[2][0][0]; qnew[63] = spatial_metric_der[2][0][1]; qnew[64] = spatial_metric_der[2][0][2]; - qnew[65] = spatial_metric_der[2][1][0]; qnew[66] = spatial_metric_der[2][1][1]; qnew[67] = spatial_metric_der[2][1][2]; - qnew[68] = spatial_metric_der[2][2][0]; qnew[69] = spatial_metric_der[2][2][1]; qnew[70] = spatial_metric_der[2][2][2]; + qnew[32] = lapse_der[0]; + qnew[33] = lapse_der[1]; + qnew[34] = lapse_der[2]; + + qnew[35] = shift_der[0][0]; + qnew[36] = shift_der[0][1]; + qnew[37] = shift_der[0][2]; + qnew[38] = shift_der[1][0]; + qnew[39] = shift_der[1][1]; + qnew[40] = shift_der[1][2]; + qnew[41] = shift_der[2][0]; + qnew[42] = shift_der[2][1]; + qnew[43] = shift_der[2][2]; + + qnew[44] = spatial_metric_der[0][0][0]; + qnew[45] = spatial_metric_der[0][0][1]; + qnew[46] = spatial_metric_der[0][0][2]; + qnew[47] = spatial_metric_der[0][1][0]; + qnew[48] = spatial_metric_der[0][1][1]; + qnew[49] = spatial_metric_der[0][1][2]; + qnew[50] = spatial_metric_der[0][2][0]; + qnew[51] = spatial_metric_der[0][2][1]; + qnew[52] = spatial_metric_der[0][2][2]; + + qnew[53] = spatial_metric_der[1][0][0]; + qnew[54] = spatial_metric_der[1][0][1]; + qnew[55] = spatial_metric_der[1][0][2]; + qnew[56] = spatial_metric_der[1][1][0]; + qnew[57] = spatial_metric_der[1][1][1]; + qnew[58] = spatial_metric_der[1][1][2]; + qnew[59] = spatial_metric_der[1][2][0]; + qnew[60] = spatial_metric_der[1][2][1]; + qnew[61] = spatial_metric_der[1][2][2]; + + qnew[62] = spatial_metric_der[2][0][0]; + qnew[63] = spatial_metric_der[2][0][1]; + qnew[64] = spatial_metric_der[2][0][2]; + qnew[65] = spatial_metric_der[2][1][0]; + qnew[66] = spatial_metric_der[2][1][1]; + qnew[67] = spatial_metric_der[2][1][2]; + qnew[68] = spatial_metric_der[2][2][0]; + qnew[69] = spatial_metric_der[2][2][1]; + qnew[70] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -1590,7 +2101,7 @@ gr_mhd_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, i gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -1607,20 +2118,21 @@ gr_mhd_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, i } } -void -gr_mhd_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, int upidx_c, - struct gkyl_array *qout, int dir) +void gr_mhd_tetrad_impose_gauge( + gkyl_wave_prop *wv, const struct gkyl_range *update_range, int idxl[GKYL_MAX_DIM], int loidx_c, + int upidx_c, struct gkyl_array *qout, int dir +) { - const struct gkyl_wv_eqn* eqn = wv->equation; + const struct gkyl_wv_eqn *eqn = wv->equation; const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); - + const enum gkyl_spacetime_gauge spacetime_gauge = gr_mhd_tetrad->spacetime_gauge; if (spacetime_gauge == GKYL_STATIC_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_mhd_tetrad->spacetime; + const struct gkyl_gr_spacetime *spacetime = gr_mhd_tetrad->spacetime; int reinit_freq = gr_mhd_tetrad->reinit_freq; - - for (int i = loidx_c; i<= upidx_c; i++) { + + for (int i = loidx_c; i <= upidx_c; i++) { idxl[dir] = i; double *qnew = gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)); @@ -1635,25 +2147,25 @@ gr_mhd_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_r double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1665,47 +2177,96 @@ gr_mhd_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_r spacetime->excision_region_func(spacetime, 0.0, x, y, z, &in_excision_region); spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, z, &spatial_metric); - spacetime->extrinsic_curvature_tensor_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - spacetime->lapse_function_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - spacetime->shift_vector_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - spacetime->spatial_metric_tensor_der_func(spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + spacetime->extrinsic_curvature_tensor_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + spacetime->lapse_function_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + spacetime->shift_vector_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + spacetime->spatial_metric_tensor_der_func( + spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[9] = lapse; - qnew[10] = shift[0]; qnew[11] = shift[1]; qnew[12] = shift[2]; - - qnew[13] = spatial_metric[0][0]; qnew[14] = spatial_metric[0][1]; qnew[15] = spatial_metric[0][2]; - qnew[16] = spatial_metric[1][0]; qnew[17] = spatial_metric[1][1]; qnew[18] = spatial_metric[1][2]; - qnew[19] = spatial_metric[2][0]; qnew[20] = spatial_metric[2][1]; qnew[21] = spatial_metric[2][2]; - - qnew[22] = extrinsic_curvature[0][0]; qnew[23] = extrinsic_curvature[0][1]; qnew[24] = extrinsic_curvature[0][2]; - qnew[25] = extrinsic_curvature[1][0]; qnew[26] = extrinsic_curvature[1][1]; qnew[27] = extrinsic_curvature[1][2]; - qnew[28] = extrinsic_curvature[2][0]; qnew[29] = extrinsic_curvature[2][1]; qnew[30] = extrinsic_curvature[2][2]; + qnew[10] = shift[0]; + qnew[11] = shift[1]; + qnew[12] = shift[2]; + + qnew[13] = spatial_metric[0][0]; + qnew[14] = spatial_metric[0][1]; + qnew[15] = spatial_metric[0][2]; + qnew[16] = spatial_metric[1][0]; + qnew[17] = spatial_metric[1][1]; + qnew[18] = spatial_metric[1][2]; + qnew[19] = spatial_metric[2][0]; + qnew[20] = spatial_metric[2][1]; + qnew[21] = spatial_metric[2][2]; + + qnew[22] = extrinsic_curvature[0][0]; + qnew[23] = extrinsic_curvature[0][1]; + qnew[24] = extrinsic_curvature[0][2]; + qnew[25] = extrinsic_curvature[1][0]; + qnew[26] = extrinsic_curvature[1][1]; + qnew[27] = extrinsic_curvature[1][2]; + qnew[28] = extrinsic_curvature[2][0]; + qnew[29] = extrinsic_curvature[2][1]; + qnew[30] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[31] = -1.0; - } - else { + } else { qnew[31] = 1.0; } - qnew[32] = lapse_der[0]; qnew[33] = lapse_der[1]; qnew[34] = lapse_der[2]; - - qnew[35] = shift_der[0][0]; qnew[36] = shift_der[0][1]; qnew[37] = shift_der[0][2]; - qnew[38] = shift_der[1][0]; qnew[39] = shift_der[1][1]; qnew[40] = shift_der[1][2]; - qnew[41] = shift_der[2][0]; qnew[42] = shift_der[2][1]; qnew[43] = shift_der[2][2]; - - qnew[44] = spatial_metric_der[0][0][0]; qnew[45] = spatial_metric_der[0][0][1]; qnew[46] = spatial_metric_der[0][0][2]; - qnew[47] = spatial_metric_der[0][1][0]; qnew[48] = spatial_metric_der[0][1][1]; qnew[49] = spatial_metric_der[0][1][2]; - qnew[50] = spatial_metric_der[0][2][0]; qnew[51] = spatial_metric_der[0][2][1]; qnew[52] = spatial_metric_der[0][2][2]; - - qnew[53] = spatial_metric_der[1][0][0]; qnew[54] = spatial_metric_der[1][0][1]; qnew[55] = spatial_metric_der[1][0][2]; - qnew[56] = spatial_metric_der[1][1][0]; qnew[57] = spatial_metric_der[1][1][1]; qnew[58] = spatial_metric_der[1][1][2]; - qnew[59] = spatial_metric_der[1][2][0]; qnew[60] = spatial_metric_der[1][2][1]; qnew[61] = spatial_metric_der[1][2][2]; - - qnew[62] = spatial_metric_der[2][0][0]; qnew[63] = spatial_metric_der[2][0][1]; qnew[64] = spatial_metric_der[2][0][2]; - qnew[65] = spatial_metric_der[2][1][0]; qnew[66] = spatial_metric_der[2][1][1]; qnew[67] = spatial_metric_der[2][1][2]; - qnew[68] = spatial_metric_der[2][2][0]; qnew[69] = spatial_metric_der[2][2][1]; qnew[70] = spatial_metric_der[2][2][2]; + qnew[32] = lapse_der[0]; + qnew[33] = lapse_der[1]; + qnew[34] = lapse_der[2]; + + qnew[35] = shift_der[0][0]; + qnew[36] = shift_der[0][1]; + qnew[37] = shift_der[0][2]; + qnew[38] = shift_der[1][0]; + qnew[39] = shift_der[1][1]; + qnew[40] = shift_der[1][2]; + qnew[41] = shift_der[2][0]; + qnew[42] = shift_der[2][1]; + qnew[43] = shift_der[2][2]; + + qnew[44] = spatial_metric_der[0][0][0]; + qnew[45] = spatial_metric_der[0][0][1]; + qnew[46] = spatial_metric_der[0][0][2]; + qnew[47] = spatial_metric_der[0][1][0]; + qnew[48] = spatial_metric_der[0][1][1]; + qnew[49] = spatial_metric_der[0][1][2]; + qnew[50] = spatial_metric_der[0][2][0]; + qnew[51] = spatial_metric_der[0][2][1]; + qnew[52] = spatial_metric_der[0][2][2]; + + qnew[53] = spatial_metric_der[1][0][0]; + qnew[54] = spatial_metric_der[1][0][1]; + qnew[55] = spatial_metric_der[1][0][2]; + qnew[56] = spatial_metric_der[1][1][0]; + qnew[57] = spatial_metric_der[1][1][1]; + qnew[58] = spatial_metric_der[1][1][2]; + qnew[59] = spatial_metric_der[1][2][0]; + qnew[60] = spatial_metric_der[1][2][1]; + qnew[61] = spatial_metric_der[1][2][2]; + + qnew[62] = spatial_metric_der[2][0][0]; + qnew[63] = spatial_metric_der[2][0][1]; + qnew[64] = spatial_metric_der[2][0][2]; + qnew[65] = spatial_metric_der[2][1][0]; + qnew[66] = spatial_metric_der[2][1][1]; + qnew[67] = spatial_metric_der[2][1][2]; + qnew[68] = spatial_metric_der[2][2][0]; + qnew[69] = spatial_metric_der[2][2][1]; + qnew[70] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -1718,7 +2279,7 @@ gr_mhd_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_r gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } @@ -1730,16 +2291,14 @@ gr_mhd_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_r gkyl_free(lapse_der); gkyl_free(shift_der); gkyl_free(spatial_metric_der); - + qnew[71] = 0.0; - } - else { + } else { qnew[71] += 1.0; } } - } - else if (spacetime_gauge == GKYL_BLACKHOLE_COLLAPSE_GAUGE) { - const struct gkyl_gr_spacetime* spacetime = gr_mhd_tetrad->spacetime; + } else if (spacetime_gauge == GKYL_BLACKHOLE_COLLAPSE_GAUGE) { + const struct gkyl_gr_spacetime *spacetime = gr_mhd_tetrad->spacetime; const struct gr_blackhole *blackhole = container_of(spacetime, struct gr_blackhole, spacetime); double mass = blackhole->mass; @@ -1764,31 +2323,32 @@ gr_mhd_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_r double y = qnew[73]; double z = qnew[74]; - struct gkyl_gr_spacetime *new_spacetime = gkyl_gr_blackhole_new(false, fmin(evol_param, mass), spin, pos_x, pos_y, pos_z); + struct gkyl_gr_spacetime *new_spacetime = + gkyl_gr_blackhole_new(false, fmin(evol_param, mass), spin, pos_x, pos_y, pos_z); double lapse; double *shift = gkyl_malloc(sizeof(double[3])); bool in_excision_region; - double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } - double **extrinsic_curvature = gkyl_malloc(sizeof(double*[3])); + double **extrinsic_curvature = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { extrinsic_curvature[i] = gkyl_malloc(sizeof(double[3])); } double *lapse_der = gkyl_malloc(sizeof(double[3])); - double **shift_der = gkyl_malloc(sizeof(double*[3])); + double **shift_der = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { shift_der[i] = gkyl_malloc(sizeof(double[3])); } - double ***spatial_metric_der = gkyl_malloc(sizeof(double**[3])); + double ***spatial_metric_der = gkyl_malloc(sizeof(double **[3])); for (int i = 0; i < 3; i++) { - spatial_metric_der[i] = gkyl_malloc(sizeof(double*[3])); + spatial_metric_der[i] = gkyl_malloc(sizeof(double *[3])); for (int j = 0; j < 3; j++) { spatial_metric_der[i][j] = gkyl_malloc(sizeof(double[3])); @@ -1800,47 +2360,96 @@ gr_mhd_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_r new_spacetime->excision_region_func(new_spacetime, 0.0, x, y, z, &in_excision_region); new_spacetime->spatial_metric_tensor_func(new_spacetime, 0.0, x, y, z, &spatial_metric); - new_spacetime->extrinsic_curvature_tensor_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &extrinsic_curvature); - - new_spacetime->lapse_function_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der); - new_spacetime->shift_vector_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der); - new_spacetime->spatial_metric_tensor_der_func(new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &spatial_metric_der); + new_spacetime->extrinsic_curvature_tensor_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &extrinsic_curvature + ); + + new_spacetime->lapse_function_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &lapse_der + ); + new_spacetime->shift_vector_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), &shift_der + ); + new_spacetime->spatial_metric_tensor_der_func( + new_spacetime, 0.0, x, y, z, pow(10.0, -8.0), pow(10.0, -8.0), pow(10.0, -8.0), + &spatial_metric_der + ); qnew[9] = lapse; - qnew[10] = shift[0]; qnew[11] = shift[1]; qnew[12] = shift[2]; - - qnew[13] = spatial_metric[0][0]; qnew[14] = spatial_metric[0][1]; qnew[15] = spatial_metric[0][2]; - qnew[16] = spatial_metric[1][0]; qnew[17] = spatial_metric[1][1]; qnew[18] = spatial_metric[1][2]; - qnew[19] = spatial_metric[2][0]; qnew[20] = spatial_metric[2][1]; qnew[21] = spatial_metric[2][2]; - - qnew[22] = extrinsic_curvature[0][0]; qnew[23] = extrinsic_curvature[0][1]; qnew[24] = extrinsic_curvature[0][2]; - qnew[25] = extrinsic_curvature[1][0]; qnew[26] = extrinsic_curvature[1][1]; qnew[27] = extrinsic_curvature[1][2]; - qnew[28] = extrinsic_curvature[2][0]; qnew[29] = extrinsic_curvature[2][1]; qnew[30] = extrinsic_curvature[2][2]; + qnew[10] = shift[0]; + qnew[11] = shift[1]; + qnew[12] = shift[2]; + + qnew[13] = spatial_metric[0][0]; + qnew[14] = spatial_metric[0][1]; + qnew[15] = spatial_metric[0][2]; + qnew[16] = spatial_metric[1][0]; + qnew[17] = spatial_metric[1][1]; + qnew[18] = spatial_metric[1][2]; + qnew[19] = spatial_metric[2][0]; + qnew[20] = spatial_metric[2][1]; + qnew[21] = spatial_metric[2][2]; + + qnew[22] = extrinsic_curvature[0][0]; + qnew[23] = extrinsic_curvature[0][1]; + qnew[24] = extrinsic_curvature[0][2]; + qnew[25] = extrinsic_curvature[1][0]; + qnew[26] = extrinsic_curvature[1][1]; + qnew[27] = extrinsic_curvature[1][2]; + qnew[28] = extrinsic_curvature[2][0]; + qnew[29] = extrinsic_curvature[2][1]; + qnew[30] = extrinsic_curvature[2][2]; if (in_excision_region) { qnew[31] = -1.0; - } - else { + } else { qnew[31] = 1.0; } - qnew[32] = lapse_der[0]; qnew[33] = lapse_der[1]; qnew[34] = lapse_der[2]; - - qnew[35] = shift_der[0][0]; qnew[36] = shift_der[0][1]; qnew[37] = shift_der[0][2]; - qnew[38] = shift_der[1][0]; qnew[39] = shift_der[1][1]; qnew[40] = shift_der[1][2]; - qnew[41] = shift_der[2][0]; qnew[42] = shift_der[2][1]; qnew[43] = shift_der[2][2]; - - qnew[44] = spatial_metric_der[0][0][0]; qnew[45] = spatial_metric_der[0][0][1]; qnew[46] = spatial_metric_der[0][0][2]; - qnew[47] = spatial_metric_der[0][1][0]; qnew[48] = spatial_metric_der[0][1][1]; qnew[49] = spatial_metric_der[0][1][2]; - qnew[50] = spatial_metric_der[0][2][0]; qnew[51] = spatial_metric_der[0][2][1]; qnew[52] = spatial_metric_der[0][2][2]; - - qnew[53] = spatial_metric_der[1][0][0]; qnew[54] = spatial_metric_der[1][0][1]; qnew[55] = spatial_metric_der[1][0][2]; - qnew[56] = spatial_metric_der[1][1][0]; qnew[57] = spatial_metric_der[1][1][1]; qnew[58] = spatial_metric_der[1][1][2]; - qnew[59] = spatial_metric_der[1][2][0]; qnew[60] = spatial_metric_der[1][2][1]; qnew[61] = spatial_metric_der[1][2][2]; - - qnew[62] = spatial_metric_der[2][0][0]; qnew[63] = spatial_metric_der[2][0][1]; qnew[64] = spatial_metric_der[2][0][2]; - qnew[65] = spatial_metric_der[2][1][0]; qnew[66] = spatial_metric_der[2][1][1]; qnew[67] = spatial_metric_der[2][1][2]; - qnew[68] = spatial_metric_der[2][2][0]; qnew[69] = spatial_metric_der[2][2][1]; qnew[70] = spatial_metric_der[2][2][2]; + qnew[32] = lapse_der[0]; + qnew[33] = lapse_der[1]; + qnew[34] = lapse_der[2]; + + qnew[35] = shift_der[0][0]; + qnew[36] = shift_der[0][1]; + qnew[37] = shift_der[0][2]; + qnew[38] = shift_der[1][0]; + qnew[39] = shift_der[1][1]; + qnew[40] = shift_der[1][2]; + qnew[41] = shift_der[2][0]; + qnew[42] = shift_der[2][1]; + qnew[43] = shift_der[2][2]; + + qnew[44] = spatial_metric_der[0][0][0]; + qnew[45] = spatial_metric_der[0][0][1]; + qnew[46] = spatial_metric_der[0][0][2]; + qnew[47] = spatial_metric_der[0][1][0]; + qnew[48] = spatial_metric_der[0][1][1]; + qnew[49] = spatial_metric_der[0][1][2]; + qnew[50] = spatial_metric_der[0][2][0]; + qnew[51] = spatial_metric_der[0][2][1]; + qnew[52] = spatial_metric_der[0][2][2]; + + qnew[53] = spatial_metric_der[1][0][0]; + qnew[54] = spatial_metric_der[1][0][1]; + qnew[55] = spatial_metric_der[1][0][2]; + qnew[56] = spatial_metric_der[1][1][0]; + qnew[57] = spatial_metric_der[1][1][1]; + qnew[58] = spatial_metric_der[1][1][2]; + qnew[59] = spatial_metric_der[1][2][0]; + qnew[60] = spatial_metric_der[1][2][1]; + qnew[61] = spatial_metric_der[1][2][2]; + + qnew[62] = spatial_metric_der[2][0][0]; + qnew[63] = spatial_metric_der[2][0][1]; + qnew[64] = spatial_metric_der[2][0][2]; + qnew[65] = spatial_metric_der[2][1][0]; + qnew[66] = spatial_metric_der[2][1][1]; + qnew[67] = spatial_metric_der[2][1][2]; + qnew[68] = spatial_metric_der[2][2][0]; + qnew[69] = spatial_metric_der[2][2][1]; + qnew[70] = spatial_metric_der[2][2][2]; if (in_excision_region) { for (int i = 0; i < 71; i++) { @@ -1853,7 +2462,7 @@ gr_mhd_tetrad_impose_gauge(gkyl_wave_prop *wv, const struct gkyl_range *update_r gkyl_free(spatial_metric[i]); gkyl_free(extrinsic_curvature[i]); gkyl_free(shift_der[i]); - + for (int j = 0; j < 3; j++) { gkyl_free(spatial_metric_der[i][j]); } diff --git a/moments/zero/mhd_src.c b/moments/zero/mhd_src.c index daf9e61f4c..c0ac69b31a 100644 --- a/moments/zero/mhd_src.c +++ b/moments/zero/mhd_src.c @@ -2,7 +2,6 @@ #include #include - // Makes indexing cleaner #define DN (0) #define MX (1) @@ -14,8 +13,8 @@ #define BZ (7) #define PSI_GLM (8) -gkyl_mhd_src *gkyl_mhd_src_new(struct gkyl_mhd_src_inp inp, - const struct gkyl_range *local_ext) { +gkyl_mhd_src *gkyl_mhd_src_new(struct gkyl_mhd_src_inp inp, const struct gkyl_range *local_ext) +{ gkyl_mhd_src *up = gkyl_calloc(1, sizeof(gkyl_mhd_src)); up->grid = *(inp.grid); @@ -25,8 +24,8 @@ gkyl_mhd_src *gkyl_mhd_src_new(struct gkyl_mhd_src_inp inp, up->glm_alpha = inp.glm_alpha; up->dxyz_min = inp.dxyz_min; - if (up->divergence_constraint >= GKYL_MHD_DIVB_EIGHT_WAVES - && up->divergence_constraint <= GKYL_MHD_DIVB_GLM) { + if (up->divergence_constraint >= GKYL_MHD_DIVB_EIGHT_WAVES && + up->divergence_constraint <= GKYL_MHD_DIVB_GLM) { up->divB_array = gkyl_array_new(GKYL_DOUBLE, 1, local_ext->volume); } @@ -41,9 +40,9 @@ gkyl_mhd_src *gkyl_mhd_src_new(struct gkyl_mhd_src_inp inp, // SOURCE UPDATE HELPERS // /////////////////////////// -static void calc_divB(const gkyl_mhd_src *up, - const struct gkyl_range *update_range, - struct gkyl_array *q_array) { +static void +calc_divB(const gkyl_mhd_src *up, const struct gkyl_range *update_range, struct gkyl_array *q_array) +{ struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, update_range); @@ -53,9 +52,9 @@ static void calc_divB(const gkyl_mhd_src *up, double *divB = gkyl_array_fetch(up->divB_array, lidx); int idxl[3], idxr[3]; - + double my_divB = 0.0; - for(int d=0; dgrid.ndim; ++d) { + for (int d = 0; d < up->grid.ndim; ++d) { gkyl_copy_int_arr(up->grid.ndim, iter.idx, idxl); gkyl_copy_int_arr(up->grid.ndim, iter.idx, idxr); idxl[d]--; @@ -74,9 +73,10 @@ static void calc_divB(const gkyl_mhd_src *up, } } -static void calc_B_dot_gradPsi(const gkyl_mhd_src *up, - const struct gkyl_range *update_range, - struct gkyl_array *q_array) { +static void calc_B_dot_gradPsi( + const gkyl_mhd_src *up, const struct gkyl_range *update_range, struct gkyl_array *q_array +) +{ struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, update_range); @@ -86,9 +86,9 @@ static void calc_B_dot_gradPsi(const gkyl_mhd_src *up, double *B_dot_gradPsi = gkyl_array_fetch(up->B_dot_gradPsi_array, lidx); int idxl[3], idxr[3]; - + double my_B_dot_gradPsi = 0.0; - for(int d=0; dgrid.ndim; ++d) { + for (int d = 0; d < up->grid.ndim; ++d) { gkyl_copy_int_arr(up->grid.ndim, iter.idx, idxl); gkyl_copy_int_arr(up->grid.ndim, iter.idx, idxr); idxl[d]--; @@ -111,10 +111,11 @@ static void calc_B_dot_gradPsi(const gkyl_mhd_src *up, // VARIOUS SOURCE UPDATES // //////////////////////////// -static void gkyl_mhd_src_eight_wave(const gkyl_mhd_src *up, double dt, - const struct gkyl_range *update_range, - struct gkyl_array *q_array, - const struct gkyl_array *acc_array) { +static void gkyl_mhd_src_eight_wave( + const gkyl_mhd_src *up, double dt, const struct gkyl_range *update_range, + struct gkyl_array *q_array, const struct gkyl_array *acc_array +) +{ // Powell et al., JCP (1999), 10.1006/jcph.1999.6299 calc_divB(up, update_range, q_array); @@ -124,7 +125,7 @@ static void gkyl_mhd_src_eight_wave(const gkyl_mhd_src *up, double dt, while (gkyl_range_iter_next(&iter)) { long lidx = gkyl_range_idx(update_range, iter.idx); double *q = gkyl_array_fetch(q_array, lidx); - double *divB =gkyl_array_fetch(up->divB_array, lidx); + double *divB = gkyl_array_fetch(up->divB_array, lidx); double ux = q[MX] / q[DN], uy = q[MY] / q[DN], uz = q[MZ] / q[DN]; double Bx = q[BX], By = q[BY], Bz = q[BZ]; @@ -136,14 +137,15 @@ static void gkyl_mhd_src_eight_wave(const gkyl_mhd_src *up, double dt, q[BX] -= dt * divB[0] * ux; q[BY] -= dt * divB[0] * uy; q[BZ] -= dt * divB[0] * uz; - q[ER] -= dt * divB[0] * (ux*Bx + uy*By + uz*Bz); + q[ER] -= dt * divB[0] * (ux * Bx + uy * By + uz * Bz); } } -static void gkyl_mhd_src_glm(const gkyl_mhd_src *up, double dt, - const struct gkyl_range *update_range, - struct gkyl_array *q_array, - const struct gkyl_array *acc_array) { +static void gkyl_mhd_src_glm( + const gkyl_mhd_src *up, double dt, const struct gkyl_range *update_range, + struct gkyl_array *q_array, const struct gkyl_array *acc_array +) +{ // Dedner et al., JCP (2002), 10.1006/jcph.2001.6961 // Mignone & Tzeferacos, JCP (2010), 10.1016/j.jcp.2009.11.026 calc_divB(up, update_range, q_array); @@ -155,7 +157,7 @@ static void gkyl_mhd_src_glm(const gkyl_mhd_src *up, double dt, while (gkyl_range_iter_next(&iter)) { long lidx = gkyl_range_idx(update_range, iter.idx); double *q = gkyl_array_fetch(q_array, lidx); - double *divB =gkyl_array_fetch(up->divB_array, lidx); + double *divB = gkyl_array_fetch(up->divB_array, lidx); double *B_dot_gradPsi = gkyl_array_fetch(up->B_dot_gradPsi_array, lidx); double ch = up->glm_ch; @@ -163,7 +165,7 @@ static void gkyl_mhd_src_glm(const gkyl_mhd_src *up, double dt, // Dedner's equation (24e) or Mignone's equation (27) double rate = alpha * ch / up->dxyz_min; - q[PSI_GLM] *= exp(- rate * dt); + q[PSI_GLM] *= exp(-rate * dt); double Bx = q[BX], By = q[BY], Bz = q[BZ]; // Dedner's equations (24b) and (24d) @@ -178,27 +180,29 @@ static void gkyl_mhd_src_glm(const gkyl_mhd_src *up, double dt, // SOURCE UPDATES MAIN API // ///////////////////////////// -void gkyl_mhd_src_advance(const gkyl_mhd_src *up, double dt, - const struct gkyl_range *update_range, - struct gkyl_array *q_array, - const struct gkyl_array *acc_array) { +void gkyl_mhd_src_advance( + const gkyl_mhd_src *up, double dt, const struct gkyl_range *update_range, + struct gkyl_array *q_array, const struct gkyl_array *acc_array +) +{ switch (up->divergence_constraint) { - case GKYL_MHD_DIVB_NONE: - break; + case GKYL_MHD_DIVB_NONE: + break; - case GKYL_MHD_DIVB_EIGHT_WAVES: - gkyl_mhd_src_eight_wave(up, dt, update_range, q_array, acc_array); - break; + case GKYL_MHD_DIVB_EIGHT_WAVES: + gkyl_mhd_src_eight_wave(up, dt, update_range, q_array, acc_array); + break; - case GKYL_MHD_DIVB_GLM: - gkyl_mhd_src_glm(up, dt, update_range, q_array, acc_array); - break; + case GKYL_MHD_DIVB_GLM: + gkyl_mhd_src_glm(up, dt, update_range, q_array, acc_array); + break; } } -double gkyl_mhd_src_calc_divB(const gkyl_mhd_src *up, - const struct gkyl_range *update_range, - struct gkyl_array *q_array) { +double gkyl_mhd_src_calc_divB( + const gkyl_mhd_src *up, const struct gkyl_range *update_range, struct gkyl_array *q_array +) +{ calc_divB(up, update_range, q_array); struct gkyl_range_iter iter; @@ -215,12 +219,15 @@ double gkyl_mhd_src_calc_divB(const gkyl_mhd_src *up, return total / count; } -void gkyl_mhd_src_release(gkyl_mhd_src *up) { - if (up->divB_array) +void gkyl_mhd_src_release(gkyl_mhd_src *up) +{ + if (up->divB_array) { gkyl_array_release(up->divB_array); + } - if (up->B_dot_gradPsi_array) + if (up->B_dot_gradPsi_array) { gkyl_array_release(up->B_dot_gradPsi_array); + } gkyl_free(up); } @@ -229,9 +236,7 @@ void gkyl_mhd_src_release(gkyl_mhd_src *up) { // MEMBER GETTERS AND SETTERS // //////////////////////////////// -void -gkyl_mhd_src_set_glm_ch(struct gkyl_mhd_src* up, const double glm_ch) +void gkyl_mhd_src_set_glm_ch(struct gkyl_mhd_src *up, const double glm_ch) { up->glm_ch = glm_ch; } - diff --git a/moments/zero/moment_braginskii.c b/moments/zero/moment_braginskii.c index 77b8151545..5aeadd0c67 100644 --- a/moments/zero/moment_braginskii.c +++ b/moments/zero/moment_braginskii.c @@ -5,23 +5,13 @@ #include // 1D stencil locations (L: lower, U: upper) -enum loc_1d { - L_1D, U_1D -}; +enum loc_1d { L_1D, U_1D }; // 2D stencil locations (L: lower, U: upper) -enum loc_2d { - LL_2D, LU_2D, - UL_2D, UU_2D -}; +enum loc_2d { LL_2D, LU_2D, UL_2D, UU_2D }; // 3D stencil locations (L: lower, U: upper) -enum loc_3d { - LLL_3D, LLU_3D, - LUL_3D, LUU_3D, - ULL_3D, ULU_3D, - UUL_3D, UUU_3D -}; +enum loc_3d { LLL_3D, LLU_3D, LUL_3D, LUU_3D, ULL_3D, ULU_3D, UUL_3D, UUU_3D }; struct gkyl_moment_braginskii { struct gkyl_rect_grid grid; // grid object @@ -29,76 +19,82 @@ struct gkyl_moment_braginskii { int nfluids; // number of fluids in multi-fluid system struct gkyl_moment_braginskii_data param[GKYL_MAX_SPECIES]; // struct of fluid parameters double epsilon0; // permittivity of free space - double coll_fac; // constant multiplicative factor for collision time to increase or decrease collisionality + double + coll_fac; // constant multiplicative factor for collision time to increase or decrease collisionality }; -static void -create_offsets_vertices(const struct gkyl_range *range, long offsets[]) +static void create_offsets_vertices(const struct gkyl_range *range, long offsets[]) { // box spanning stencil struct gkyl_range box3; - gkyl_range_init(&box3, range->ndim, (int[]) { -1, -1, -1 }, (int[]) { 0, 0, 0 }); + gkyl_range_init(&box3, range->ndim, (int[]){-1, -1, -1}, (int[]){0, 0, 0}); struct gkyl_range_iter iter3; gkyl_range_iter_init(&iter3, &box3); // construct list of offsets int count = 0; - while (gkyl_range_iter_next(&iter3)) + while (gkyl_range_iter_next(&iter3)) { offsets[count++] = gkyl_range_offset(range, iter3.idx); + } } -static void -create_offsets_centers(const struct gkyl_range *range, long offsets[]) +static void create_offsets_centers(const struct gkyl_range *range, long offsets[]) { // box spanning stencil struct gkyl_range box3; - gkyl_range_init(&box3, range->ndim, (int[]) { 0, 0, 0 }, (int[]) { 1, 1, 1 }); + gkyl_range_init(&box3, range->ndim, (int[]){0, 0, 0}, (int[]){1, 1, 1}); struct gkyl_range_iter iter3; gkyl_range_iter_init(&iter3, &box3); // construct list of offsets int count = 0; - while (gkyl_range_iter_next(&iter3)) + while (gkyl_range_iter_next(&iter3)) { offsets[count++] = gkyl_range_offset(range, iter3.idx); + } } // Fetch input quantities and compute derived quantities for magnetized Braginskii -static void -mag_var_setup(const gkyl_moment_braginskii *bes, int start, int end, - const double *fluid_d[][GKYL_MAX_SPECIES], const double *em_tot_d[], - double u[][2][3], double b[][3], - double T[][2], double tau[][2], - double eta_par[][2], double eta_perp[][2], double eta_cross[][2], - double kappa_par[][2], double kappa_perp[][2], double kappa_cross[][2], - double current_par[][3], double current_cross[][3]) +static void mag_var_setup( + const gkyl_moment_braginskii *bes, int start, int end, const double *fluid_d[][GKYL_MAX_SPECIES], + const double *em_tot_d[], double u[][2][3], double b[][3], double T[][2], double tau[][2], + double eta_par[][2], double eta_perp[][2], double eta_cross[][2], double kappa_par[][2], + double kappa_perp[][2], double kappa_cross[][2], double current_par[][3], + double current_cross[][3] +) { int nfluids = bes->nfluids; - double m[2] = { bes->param[0].mass, bes->param[1].mass }; - double q[2] = { bes->param[0].charge, bes->param[1].charge }; + double m[2] = {bes->param[0].mass, bes->param[1].mass}; + double q[2] = {bes->param[0].charge, bes->param[1].charge}; // Grab indices of electron and ion fluid arrays int ELC = bes->param[0].charge < 0.0 ? 0 : 1; int ION = (ELC + 1) % 2; - double rho[2] = {}; // Mass density for each species - double p[2] = {}; // Pressure for each species + double rho[2] = {}; // Mass density for each species + double p[2] = {}; // Pressure for each species double omega_c[2] = {}; // Cyclotron frequency for each species for (int j = start; j <= end; ++j) { for (int n = 0; n < nfluids; ++n) { // Input density and flow in each cell rho[n] = fluid_d[j][n][RHO]; - for (int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) { u[j][n][k] = fluid_d[j][n][MX + k] / rho[n]; + } // Pressure information is different for each equation type - if (bes->param[n].type_eqn == GKYL_EQN_EULER) - p[n] = gkyl_euler_pressure(bes->param[n].p_fac, fluid_d[j][n]); // Euler needs to divide out gas_gamma factor to obtain pressure - else if (bes->param[n].type_eqn == GKYL_EQN_ISO_EULER) - p[n] = rho[n] * bes->param[n].p_fac * bes->param[n].p_fac; // isothermal Euler input is vth, pressure = rho*vth^2 + if (bes->param[n].type_eqn == GKYL_EQN_EULER) { + p[n] = gkyl_euler_pressure( + bes->param[n].p_fac, + fluid_d[j][n] + ); // Euler needs to divide out gas_gamma factor to obtain pressure + } else if (bes->param[n].type_eqn == GKYL_EQN_ISO_EULER) { + p[n] = rho[n] * bes->param[n].p_fac * + bes->param[n].p_fac; // isothermal Euler input is vth, pressure = rho*vth^2 + } T[j][n] = m[n] * p[n] / rho[n]; @@ -109,8 +105,13 @@ mag_var_setup(const gkyl_moment_braginskii *bes, int start, int end, calc_bhat(em_tot_d[j], b[j]); // Derived collision times - tau[j][ELC] = calc_tau(1.0, bes->coll_fac, bes->epsilon0, q[ELC], q[ION], m[ELC], m[ION], rho[ION], T[j][ELC]); - tau[j][ION] = calc_tau(1.0, sqrt(2.0)*bes->coll_fac, bes->epsilon0, q[ION], q[ION], m[ION], m[ION], rho[ION], T[j][ION]); + tau[j][ELC] = calc_tau( + 1.0, bes->coll_fac, bes->epsilon0, q[ELC], q[ION], m[ELC], m[ION], rho[ION], T[j][ELC] + ); + tau[j][ION] = calc_tau( + 1.0, sqrt(2.0) * bes->coll_fac, bes->epsilon0, q[ION], q[ION], m[ION], m[ION], rho[ION], + T[j][ION] + ); // Brag-type enum is used to turn coefficients on/off in a branchless fashion bool electron_viscosity = (bes->param[ELC].type_brag & GKYL_BRAG_VISC); @@ -118,36 +119,47 @@ mag_var_setup(const gkyl_moment_braginskii *bes, int start, int end, bool ion_viscosity = (bes->param[ION].type_brag & GKYL_BRAG_VISC); bool ion_heatFlux = (bes->param[ION].type_brag & GKYL_BRAG_HEATFLUX); - eta_par[j][ELC] = electron_viscosity * 1.5*0.73*p[ELC]*tau[j][ELC]; - eta_perp[j][ELC] = electron_viscosity * 0.51*p[ELC]/(tau[j][ELC]*omega_c[ELC]*omega_c[ELC]); - eta_cross[j][ELC] = electron_viscosity * 0.25*p[ELC]/omega_c[ELC]; - kappa_par[j][ELC] = electron_heatFlux * 3.16*p[ELC]*tau[j][ELC]/m[ELC]; - kappa_perp[j][ELC] = electron_heatFlux * 4.66*p[ELC]/(m[ELC]*tau[j][ELC]*omega_c[ELC]*omega_c[ELC]); - kappa_cross[j][ELC] = electron_heatFlux * 2.5*p[ELC]/(m[ELC]*omega_c[ELC]); - - eta_par[j][ION] = ion_viscosity * 1.5*0.96*p[ION]*tau[j][ION]; - eta_perp[j][ION] = ion_viscosity * 0.3*p[ION]/(tau[j][ION]*omega_c[ION]*omega_c[ION]); - eta_cross[j][ION] = ion_viscosity * 0.25*p[ION]/omega_c[ION]; - kappa_par[j][ION] = ion_heatFlux * 3.91*p[ION]*tau[j][ION]/m[ION]; - kappa_perp[j][ION] = ion_heatFlux * 2*p[ION]/(m[ION]*tau[j][ION]*omega_c[ION]*omega_c[ION]); - kappa_cross[j][ION] = ion_heatFlux * 2.5*p[ION]/(m[ION]*omega_c[ION]); - - double thermal_par = electron_heatFlux * -0.71*p[ELC]; // Parallel thermal force coefficient (same for each species) - double thermal_perp = electron_heatFlux * 1.5*p[ELC]/(omega_c[ELC]*tau[j][ELC]); // Perpendicular thermal force coefficient (same for each species) - double b_dot_j = b[j][0]*(u[j][ION][0] - u[j][ELC][0]) + b[j][1]*(u[j][ION][1] - u[j][ELC][1]) + b[j][2]*(u[j][ION][2] - u[j][ELC][2]); - current_par[j][0] = thermal_par*b[j][0]*b_dot_j; - current_par[j][1] = thermal_par*b[j][1]*b_dot_j; - current_par[j][2] = thermal_par*b[j][2]*b_dot_j; - current_cross[j][0] = thermal_perp*(b[j][1]*(u[j][ION][2] - u[j][ELC][2]) - b[j][2]*(u[j][ION][1] - u[j][ELC][1])); - current_cross[j][1] = thermal_perp*(b[j][2]*(u[j][ION][0] - u[j][ELC][0]) - b[j][0]*(u[j][ION][2] - u[j][ELC][2])); - current_cross[j][2] = thermal_perp*(b[j][0]*(u[j][ION][1] - u[j][ELC][1]) - b[j][1]*(u[j][ION][0] - u[j][ELC][0])); + eta_par[j][ELC] = electron_viscosity * 1.5 * 0.73 * p[ELC] * tau[j][ELC]; + eta_perp[j][ELC] = + electron_viscosity * 0.51 * p[ELC] / (tau[j][ELC] * omega_c[ELC] * omega_c[ELC]); + eta_cross[j][ELC] = electron_viscosity * 0.25 * p[ELC] / omega_c[ELC]; + kappa_par[j][ELC] = electron_heatFlux * 3.16 * p[ELC] * tau[j][ELC] / m[ELC]; + kappa_perp[j][ELC] = + electron_heatFlux * 4.66 * p[ELC] / (m[ELC] * tau[j][ELC] * omega_c[ELC] * omega_c[ELC]); + kappa_cross[j][ELC] = electron_heatFlux * 2.5 * p[ELC] / (m[ELC] * omega_c[ELC]); + + eta_par[j][ION] = ion_viscosity * 1.5 * 0.96 * p[ION] * tau[j][ION]; + eta_perp[j][ION] = ion_viscosity * 0.3 * p[ION] / (tau[j][ION] * omega_c[ION] * omega_c[ION]); + eta_cross[j][ION] = ion_viscosity * 0.25 * p[ION] / omega_c[ION]; + kappa_par[j][ION] = ion_heatFlux * 3.91 * p[ION] * tau[j][ION] / m[ION]; + kappa_perp[j][ION] = + ion_heatFlux * 2 * p[ION] / (m[ION] * tau[j][ION] * omega_c[ION] * omega_c[ION]); + kappa_cross[j][ION] = ion_heatFlux * 2.5 * p[ION] / (m[ION] * omega_c[ION]); + + double thermal_par = electron_heatFlux * -0.71 * + p[ELC]; // Parallel thermal force coefficient (same for each species) + double thermal_perp = electron_heatFlux * 1.5 * p[ELC] / + (omega_c[ELC] * tau[j][ELC] + ); // Perpendicular thermal force coefficient (same for each species) + double b_dot_j = b[j][0] * (u[j][ION][0] - u[j][ELC][0]) + + b[j][1] * (u[j][ION][1] - u[j][ELC][1]) + + b[j][2] * (u[j][ION][2] - u[j][ELC][2]); + current_par[j][0] = thermal_par * b[j][0] * b_dot_j; + current_par[j][1] = thermal_par * b[j][1] * b_dot_j; + current_par[j][2] = thermal_par * b[j][2] * b_dot_j; + current_cross[j][0] = thermal_perp * (b[j][1] * (u[j][ION][2] - u[j][ELC][2]) - + b[j][2] * (u[j][ION][1] - u[j][ELC][1])); + current_cross[j][1] = thermal_perp * (b[j][2] * (u[j][ION][0] - u[j][ELC][0]) - + b[j][0] * (u[j][ION][2] - u[j][ELC][2])); + current_cross[j][2] = thermal_perp * (b[j][0] * (u[j][ION][1] - u[j][ELC][1]) - + b[j][1] * (u[j][ION][0] - u[j][ELC][0])); } } -static void -mag_brag_calc_vars(const gkyl_moment_braginskii *bes, - const double *fluid_d[][GKYL_MAX_SPECIES], const double *em_tot_d[], - double *cflrate[GKYL_MAX_SPECIES], double *brag_d[GKYL_MAX_SPECIES]) +static void mag_brag_calc_vars( + const gkyl_moment_braginskii *bes, const double *fluid_d[][GKYL_MAX_SPECIES], + const double *em_tot_d[], double *cflrate[GKYL_MAX_SPECIES], double *brag_d[GKYL_MAX_SPECIES] +) { int nfluids = bes->nfluids; const int ndim = bes->ndim; @@ -155,8 +167,8 @@ mag_brag_calc_vars(const gkyl_moment_braginskii *bes, // Allocate some memory on stack regardless of dimensionality or equation type (Euler vs. isothermal Euler) // These allocations allow us to make final construction of Braginskii variables dimensionally independent // Note: Braginskii implementation currently assumes only two fluids (electrons and an ion species) - double m[2] = { bes->param[0].mass, bes->param[1].mass }; - double q[2] = { bes->param[0].charge, bes->param[1].charge }; + double m[2] = {bes->param[0].mass, bes->param[1].mass}; + double q[2] = {bes->param[0].charge, bes->param[1].charge}; // Grab indices of electron and ion fluid arrays int ELC = bes->param[0].charge < 0.0 ? 0 : 1; @@ -171,16 +183,19 @@ mag_brag_calc_vars(const gkyl_moment_braginskii *bes, double pi_cross[2][6] = {}; double kappa_par_avg[2] = {}, kappa_perp_avg[2] = {}, kappa_cross_avg[2] = {}; - double current_par_avg[3] = {}; // Parallel current multiplied by parallel thermal force coefficient at cell edges (using arithmetic average) - double current_cross_avg[3] = {}; // Cross current multiplied by perpendicular thermal force coefficient at cell edges (using arithmetic average) + double current_par_avg[3] = { + }; // Parallel current multiplied by parallel thermal force coefficient at cell edges (using arithmetic average) + double current_cross_avg[3] = { + }; // Cross current multiplied by perpendicular thermal force coefficient at cell edges (using arithmetic average) // Temperature gradient, parallel, perp, and cross at cell edges double gradxT[2] = {}; double gradyT[2] = {}; double gradzT[2] = {}; - double bbgradT[2][3] = {}; // Parallel temperature gradient (b_hat b_hat dot grad T) - double perp_gradT[2][3] = {}; // Perpendicular temperature gradient (grad T - b_hat b_hat dot grad T) + double bbgradT[2][3] = {}; // Parallel temperature gradient (b_hat b_hat dot grad T) + double perp_gradT[2][3] = { + }; // Perpendicular temperature gradient (grad T - b_hat b_hat dot grad T) double cross_gradT[2][3] = {}; // Cross temperature gradient (b x grad T) // Average velocity at cell edges @@ -190,31 +205,30 @@ mag_brag_calc_vars(const gkyl_moment_braginskii *bes, double dx = bes->grid.dx[0]; // Derived quantities - double u[2][2][3] = {}; // Flow for each species, ux, uy, & uz - double b[2][3] = {}; // Magnetic field unit vector, Bx/|B|, By/|B|, & Bz/|B| - double T[2][2] = {}; // Temperature for each species (m*p/rho) - double tau[2][2] = {}; // Collision times for each species - double eta_par[2][2] = {}; // Parallel viscosity for each species - double eta_perp[2][2] = {}; // Perpendicular viscosity for each species - double eta_cross[2][2] = {}; // Gyro-viscosity for each species - double kappa_par[2][2] = {}; // Parallel conductivity for each species - double kappa_perp[2][2] = {}; // Perpendicular conductivity for each species - double kappa_cross[2][2] = {}; // Gyro-conductivity for each species - double current_par[2][3] = {}; // b_hat b_hat dot (u_i - u_e) - double current_cross[2][3] = {}; // b x (u_i - u_e) + double u[2][2][3] = {}; // Flow for each species, ux, uy, & uz + double b[2][3] = {}; // Magnetic field unit vector, Bx/|B|, By/|B|, & Bz/|B| + double T[2][2] = {}; // Temperature for each species (m*p/rho) + double tau[2][2] = {}; // Collision times for each species + double eta_par[2][2] = {}; // Parallel viscosity for each species + double eta_perp[2][2] = {}; // Perpendicular viscosity for each species + double eta_cross[2][2] = {}; // Gyro-viscosity for each species + double kappa_par[2][2] = {}; // Parallel conductivity for each species + double kappa_perp[2][2] = {}; // Perpendicular conductivity for each species + double kappa_cross[2][2] = {}; // Gyro-conductivity for each species + double current_par[2][3] = {}; // b_hat b_hat dot (u_i - u_e) + double current_cross[2][3] = {}; // b x (u_i - u_e) // Compute derived quantities - mag_var_setup(bes, L_1D, U_1D, - fluid_d, em_tot_d, - u, b, T, tau, - eta_par, eta_perp, eta_cross, - kappa_par, kappa_perp, kappa_cross, - current_par, current_cross); + mag_var_setup( + bes, L_1D, U_1D, fluid_d, em_tot_d, u, b, T, tau, eta_par, eta_perp, eta_cross, kappa_par, + kappa_perp, kappa_cross, current_par, current_cross + ); // Magnetic field at cell edges (using arithmetic average) - for (int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) { b_avg[k] = calc_arithm_avg_1D(b[L_1D][k], b[U_1D][k]); - + } + for (int n = 0; n < nfluids; ++n) { // Parallel viscosity, perpendicular viscosity, and gyro-viscosity coefficients at cell edges (using harmonic average) eta_par_avg[n] = calc_harmonic_avg_1D(eta_par[L_1D][n], eta_par[U_1D][n]); @@ -233,8 +247,9 @@ mag_brag_calc_vars(const gkyl_moment_braginskii *bes, gradxT[n] = calc_sym_grad_1D(dx, T[L_1D][n], T[U_1D][n]); - for (int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) { bbgradT[n][k] = b_avg[k] * b_avg[0] * gradxT[n]; + } perp_gradT[n][0] = gradxT[n] - bbgradT[n][0]; @@ -242,54 +257,60 @@ mag_brag_calc_vars(const gkyl_moment_braginskii *bes, cross_gradT[n][2] = -b_avg[1] * gradxT[n]; // Average velocity at cell edges (using arithmetic average) - for (int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) { u_avg[n][k] = calc_arithm_avg_1D(u[L_1D][n][k], u[U_1D][n][k]); + } } } - - if (bes->param[ELC].type_eqn == GKYL_EQN_EULER) + + if (bes->param[ELC].type_eqn == GKYL_EQN_EULER) { for (int k = 0; k < 3; ++k) { // Parallel current multiplied by parallel thermal force coefficient at cell edges (using arithmetic average) current_par_avg[k] = calc_arithm_avg_1D(current_par[L_1D][k], current_par[U_1D][k]); // Cross current multiplied by perpendicular thermal force coefficient at cell edges (using arithmetic average) current_cross_avg[k] = calc_arithm_avg_1D(current_cross[L_1D][k], current_cross[U_1D][k]); } - } - else if (ndim == 2) { + } + } else if (ndim == 2) { double dx = bes->grid.dx[0]; double dy = bes->grid.dx[1]; // Derived quantities - double u[4][2][3] = {}; // Flow for each species, ux, uy, & uz - double b[4][3] = {}; // Magnetic field unit vector, Bx/|B|, By/|B|, & Bz/|B| - double T[4][2] = {}; // Temperature for each species (m*p/rho) - double tau[4][2] = {}; // Collision times for each species - double eta_par[4][2] = {}; // Parallel viscosity for each species - double eta_perp[4][2] = {}; // Perpendicular viscosity for each species - double eta_cross[4][2] = {}; // Gyro-viscosity for each species - double kappa_par[4][2] = {}; // Parallel conductivity for each species - double kappa_perp[4][2] = {}; // Perpendicular conductivity for each species - double kappa_cross[4][2] = {}; // Gyro-conductivity for each species - double current_par[4][3] = {}; // b_hat b_hat dot (u_i - u_e) + double u[4][2][3] = {}; // Flow for each species, ux, uy, & uz + double b[4][3] = {}; // Magnetic field unit vector, Bx/|B|, By/|B|, & Bz/|B| + double T[4][2] = {}; // Temperature for each species (m*p/rho) + double tau[4][2] = {}; // Collision times for each species + double eta_par[4][2] = {}; // Parallel viscosity for each species + double eta_perp[4][2] = {}; // Perpendicular viscosity for each species + double eta_cross[4][2] = {}; // Gyro-viscosity for each species + double kappa_par[4][2] = {}; // Parallel conductivity for each species + double kappa_perp[4][2] = {}; // Perpendicular conductivity for each species + double kappa_cross[4][2] = {}; // Gyro-conductivity for each species + double current_par[4][3] = {}; // b_hat b_hat dot (u_i - u_e) double current_cross[4][3] = {}; // b x (u_i - u_e) // Compute derived quantities - mag_var_setup(bes, LL_2D, UU_2D, - fluid_d, em_tot_d, - u, b, T, tau, - eta_par, eta_perp, eta_cross, - kappa_par, kappa_perp, kappa_cross, - current_par, current_cross); + mag_var_setup( + bes, LL_2D, UU_2D, fluid_d, em_tot_d, u, b, T, tau, eta_par, eta_perp, eta_cross, kappa_par, + kappa_perp, kappa_cross, current_par, current_cross + ); // Magnetic field at cell vertices (using arithmetic average) - for (int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) { b_avg[k] = calc_arithm_avg_2D(b[LL_2D][k], b[LU_2D][k], b[UL_2D][k], b[UU_2D][k]); + } for (int n = 0; n < nfluids; ++n) { // Parallel viscosity, perpendicular viscosity, and gyro-viscosity coefficients at cell edges (using harmonic average) - eta_par_avg[n] = calc_harmonic_avg_2D(eta_par[LL_2D][n], eta_par[LU_2D][n], eta_par[UL_2D][n], eta_par[UU_2D][n]); - eta_perp_avg[n] = calc_harmonic_avg_2D(eta_perp[LL_2D][n], eta_perp[LU_2D][n], eta_perp[UL_2D][n], eta_perp[UU_2D][n]); - eta_cross_avg[n] = calc_harmonic_avg_2D(eta_cross[LL_2D][n], eta_cross[LU_2D][n], eta_cross[UL_2D][n], eta_cross[UU_2D][n]); + eta_par_avg[n] = calc_harmonic_avg_2D( + eta_par[LL_2D][n], eta_par[LU_2D][n], eta_par[UL_2D][n], eta_par[UU_2D][n] + ); + eta_perp_avg[n] = calc_harmonic_avg_2D( + eta_perp[LL_2D][n], eta_perp[LU_2D][n], eta_perp[UL_2D][n], eta_perp[UU_2D][n] + ); + eta_cross_avg[n] = calc_harmonic_avg_2D( + eta_cross[LL_2D][n], eta_cross[LU_2D][n], eta_cross[UL_2D][n], eta_cross[UU_2D][n] + ); // Rate of strain tensor at cell vertices for electrons and ions calc_ros_2D(dx, dy, u[LL_2D][n], u[LU_2D][n], u[UL_2D][n], u[UU_2D][n], w[n]); @@ -297,36 +318,51 @@ mag_brag_calc_vars(const gkyl_moment_braginskii *bes, // Calculate heat flux and viscous heating if energy variable exists if (bes->param[n].type_eqn == GKYL_EQN_EULER) { // Parallel conductivity, perpendicular conductivity, and gyro-conductivity coefficients at cell edges (using harmonic average) - kappa_par_avg[n] = calc_harmonic_avg_2D(kappa_par[LL_2D][n], kappa_par[LU_2D][n], kappa_par[UL_2D][n], kappa_par[UU_2D][n]); - kappa_perp_avg[n] = calc_harmonic_avg_2D(kappa_perp[LL_2D][n], kappa_perp[LU_2D][n], kappa_perp[UL_2D][n], kappa_perp[UU_2D][n]); - kappa_cross_avg[n] = calc_harmonic_avg_2D(kappa_cross[LL_2D][n], kappa_cross[LU_2D][n], kappa_cross[UL_2D][n], kappa_cross[UU_2D][n]); + kappa_par_avg[n] = calc_harmonic_avg_2D( + kappa_par[LL_2D][n], kappa_par[LU_2D][n], kappa_par[UL_2D][n], kappa_par[UU_2D][n] + ); + kappa_perp_avg[n] = calc_harmonic_avg_2D( + kappa_perp[LL_2D][n], kappa_perp[LU_2D][n], kappa_perp[UL_2D][n], kappa_perp[UU_2D][n] + ); + kappa_cross_avg[n] = calc_harmonic_avg_2D( + kappa_cross[LL_2D][n], kappa_cross[LU_2D][n], kappa_cross[UL_2D][n], kappa_cross[UU_2D][n] + ); gradxT[n] = calc_sym_gradx_2D(dx, T[LL_2D][n], T[LU_2D][n], T[UL_2D][n], T[UU_2D][n]); gradyT[n] = calc_sym_grady_2D(dy, T[LL_2D][n], T[LU_2D][n], T[UL_2D][n], T[UU_2D][n]); - for (int k = 0; k < 3; ++k) - bbgradT[n][k] = b_avg[k] * (b_avg[0]*gradxT[n] + b_avg[1]*gradyT[n]); + for (int k = 0; k < 3; ++k) { + bbgradT[n][k] = b_avg[k] * (b_avg[0] * gradxT[n] + b_avg[1] * gradyT[n]); + } perp_gradT[n][0] = gradxT[n] - bbgradT[n][0]; perp_gradT[n][1] = gradyT[n] - bbgradT[n][1]; - cross_gradT[n][0] = -b_avg[2]*gradyT[n]; - cross_gradT[n][1] = b_avg[2]*gradxT[n]; - cross_gradT[n][2] = b_avg[0]*gradyT[n] - b_avg[1]*gradxT[n]; + cross_gradT[n][0] = -b_avg[2] * gradyT[n]; + cross_gradT[n][1] = b_avg[2] * gradxT[n]; + cross_gradT[n][2] = b_avg[0] * gradyT[n] - b_avg[1] * gradxT[n]; // Average velocity at cell edges (using arithmetic average) - for (int k = 0; k < 3; ++k) - u_avg[n][k] = calc_arithm_avg_2D(u[LL_2D][n][k], u[LU_2D][n][k], u[UL_2D][n][k], u[UU_2D][n][k]); + for (int k = 0; k < 3; ++k) { + u_avg[n][k] = + calc_arithm_avg_2D(u[LL_2D][n][k], u[LU_2D][n][k], u[UL_2D][n][k], u[UU_2D][n][k]); + } } } - - if (bes->param[ELC].type_eqn == GKYL_EQN_EULER) + + if (bes->param[ELC].type_eqn == GKYL_EQN_EULER) { for (int k = 0; k < 3; ++k) { // Parallel current multiplied by parallel thermal force coefficient at cell edges (using arithmetic average) - current_par_avg[k] = calc_arithm_avg_2D(current_par[LL_2D][k], current_par[LU_2D][k], current_par[UL_2D][k], current_par[UU_2D][k]); + current_par_avg[k] = calc_arithm_avg_2D( + current_par[LL_2D][k], current_par[LU_2D][k], current_par[UL_2D][k], current_par[UU_2D][k] + ); // Cross current multiplied by perpendicular thermal force coefficient at cell edges (using arithmetic average) - current_cross_avg[k] = calc_arithm_avg_2D(current_cross[LL_2D][k], current_cross[LU_2D][k], current_cross[UL_2D][k], current_cross[UU_2D][k]); + current_cross_avg[k] = calc_arithm_avg_2D( + current_cross[LL_2D][k], current_cross[LU_2D][k], current_cross[UL_2D][k], + current_cross[UU_2D][k] + ); } + } } for (int n = 0; n < nfluids; ++n) { @@ -336,62 +372,77 @@ mag_brag_calc_vars(const gkyl_moment_braginskii *bes, calc_pi_cross(eta_cross_avg[n], b_avg, w[n], pi_cross[n]); // Total viscous stress tensor - for (int k = 0; k < 6; ++k) + for (int k = 0; k < 6; ++k) { brag_d[n][PIXX + k] = pi_par[n][k] + pi_perp[n][k] + pi_cross[n][k]; + } // Pi dot u - double Piu[3] = { brag_d[n][PIXX]*u_avg[n][0] + brag_d[n][PIXY]*u_avg[n][1] + brag_d[n][PIXZ]*u_avg[n][2], - brag_d[n][PIXY]*u_avg[n][0] + brag_d[n][PIYY]*u_avg[n][1] + brag_d[n][PIYZ]*u_avg[n][2], - brag_d[n][PIXZ]*u_avg[n][0] + brag_d[n][PIYZ]*u_avg[n][1] + brag_d[n][PIZZ]*u_avg[n][2] }; + double Piu[3] = { + brag_d[n][PIXX] * u_avg[n][0] + brag_d[n][PIXY] * u_avg[n][1] + brag_d[n][PIXZ] * u_avg[n][2], + brag_d[n][PIXY] * u_avg[n][0] + brag_d[n][PIYY] * u_avg[n][1] + brag_d[n][PIYZ] * u_avg[n][2], + brag_d[n][PIXZ] * u_avg[n][0] + brag_d[n][PIYZ] * u_avg[n][1] + brag_d[n][PIZZ] * u_avg[n][2] + }; // Total heat flux + viscous heating - for (int k = 0; k < 3; ++k) - brag_d[n][QX + k] = -kappa_par_avg[n]*bbgradT[n][k] - kappa_perp_avg[n]*perp_gradT[n][k] + kappa_cross_avg[n]*cross_gradT[n][k] + Piu[k]; + for (int k = 0; k < 3; ++k) { + brag_d[n][QX + k] = -kappa_par_avg[n] * bbgradT[n][k] - kappa_perp_avg[n] * perp_gradT[n][k] + + kappa_cross_avg[n] * cross_gradT[n][k] + Piu[k]; + } } - for (int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) { brag_d[ELC][QX + k] += current_par_avg[k] + current_cross_avg[k]; + } } // Fetch input quantities and compute derived quantities for UNmagnetized Braginskii -static void -unmag_var_setup(const gkyl_moment_braginskii *bes, int start, int end, - const double *fluid_d[][GKYL_MAX_SPECIES], - double u[][2][3], - double T[][2], double tau[][2], - double eta[][2], double kappa[][2], - double current[][3]) +static void unmag_var_setup( + const gkyl_moment_braginskii *bes, int start, int end, const double *fluid_d[][GKYL_MAX_SPECIES], + double u[][2][3], double T[][2], double tau[][2], double eta[][2], double kappa[][2], + double current[][3] +) { int nfluids = bes->nfluids; - double m[2] = { bes->param[0].mass, bes->param[1].mass }; - double q[2] = { bes->param[0].charge, bes->param[1].charge }; + double m[2] = {bes->param[0].mass, bes->param[1].mass}; + double q[2] = {bes->param[0].charge, bes->param[1].charge}; // Grab indices of electron and ion fluid arrays int ELC = bes->param[0].charge < 0.0 ? 0 : 1; int ION = (ELC + 1) % 2; - double rho[2] = {}; // Mass density for each species - double p[2] = {}; // Pressure for each species + double rho[2] = {}; // Mass density for each species + double p[2] = {}; // Pressure for each species for (int j = start; j <= end; ++j) { for (int n = 0; n < nfluids; ++n) { // Input density and flow in each cell rho[n] = fluid_d[j][n][RHO]; - for (int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) { u[j][n][k] = fluid_d[j][n][MX + k] / rho[n]; + } // Pressure information is different for each equation type - if (bes->param[n].type_eqn == GKYL_EQN_EULER) - p[n] = gkyl_euler_pressure(bes->param[n].p_fac, fluid_d[j][n]); // Euler needs to divide out gas_gamma factor to obtain pressure - else if (bes->param[n].type_eqn == GKYL_EQN_ISO_EULER) - p[n] = rho[n] * bes->param[n].p_fac * bes->param[n].p_fac; // isothermal Euler input is vth, pressure = rho*vth^2 + if (bes->param[n].type_eqn == GKYL_EQN_EULER) { + p[n] = gkyl_euler_pressure( + bes->param[n].p_fac, + fluid_d[j][n] + ); // Euler needs to divide out gas_gamma factor to obtain pressure + } else if (bes->param[n].type_eqn == GKYL_EQN_ISO_EULER) { + p[n] = rho[n] * bes->param[n].p_fac * + bes->param[n].p_fac; // isothermal Euler input is vth, pressure = rho*vth^2 + } T[j][n] = m[n] * p[n] / rho[n]; } - tau[j][ELC] = calc_tau(1.0, bes->coll_fac, bes->epsilon0, q[ELC], q[ION], m[ELC], m[ION], rho[ION], T[j][ELC]); - tau[j][ION] = calc_tau(1.0, sqrt(2.0)*bes->coll_fac, bes->epsilon0, q[ION], q[ION], m[ION], m[ION], rho[ION], T[j][ION]); + tau[j][ELC] = calc_tau( + 1.0, bes->coll_fac, bes->epsilon0, q[ELC], q[ION], m[ELC], m[ION], rho[ION], T[j][ELC] + ); + tau[j][ION] = calc_tau( + 1.0, sqrt(2.0) * bes->coll_fac, bes->epsilon0, q[ION], q[ION], m[ION], m[ION], rho[ION], + T[j][ION] + ); // Brag-type enum is used to turn coefficients on/off in a branchless fashion bool electron_viscosity = (bes->param[ELC].type_brag & GKYL_BRAG_VISC); @@ -399,22 +450,24 @@ unmag_var_setup(const gkyl_moment_braginskii *bes, int start, int end, bool ion_viscosity = (bes->param[ION].type_brag & GKYL_BRAG_VISC); bool ion_heatFlux = (bes->param[ION].type_brag & GKYL_BRAG_HEATFLUX); - eta[j][ELC] = electron_viscosity * 0.73*p[ELC]*tau[j][ELC]; - eta[j][ION] = ion_viscosity * 0.96*p[ION]*tau[j][ION]; + eta[j][ELC] = electron_viscosity * 0.73 * p[ELC] * tau[j][ELC]; + eta[j][ION] = ion_viscosity * 0.96 * p[ION] * tau[j][ION]; - kappa[j][ELC] = electron_heatFlux * 3.16*p[ELC]*tau[j][ELC]/m[ELC]; - kappa[j][ION] = ion_heatFlux * 3.91*p[ION]*tau[j][ION]/m[ION]; + kappa[j][ELC] = electron_heatFlux * 3.16 * p[ELC] * tau[j][ELC] / m[ELC]; + kappa[j][ION] = ion_heatFlux * 3.91 * p[ION] * tau[j][ION] / m[ION]; - double thermal = electron_heatFlux * -0.71*p[ELC]; // thermal force coefficient (same for each species) - for (int k = 0; k < 3; ++k) - current[j][k] = thermal*(u[j][ION][k] - u[j][ELC][k]); + double thermal = + electron_heatFlux * -0.71 * p[ELC]; // thermal force coefficient (same for each species) + for (int k = 0; k < 3; ++k) { + current[j][k] = thermal * (u[j][ION][k] - u[j][ELC][k]); + } } } - -static void -unmag_brag_calc_vars(const gkyl_moment_braginskii *bes, - const double *fluid_d[][GKYL_MAX_SPECIES], - double *cflrate[GKYL_MAX_SPECIES], double *brag_d[GKYL_MAX_SPECIES]) + +static void unmag_brag_calc_vars( + const gkyl_moment_braginskii *bes, const double *fluid_d[][GKYL_MAX_SPECIES], + double *cflrate[GKYL_MAX_SPECIES], double *brag_d[GKYL_MAX_SPECIES] +) { const int nfluids = bes->nfluids; const int ndim = bes->ndim; @@ -422,8 +475,8 @@ unmag_brag_calc_vars(const gkyl_moment_braginskii *bes, // Allocate some memory on stack regardless of dimensionality or equation type (Euler vs. isothermal Euler) // These allocations allow us to make final construction of Braginskii variables dimensionally independent // Note: Braginskii implementation currently assumes only two fluids (electrons and an ion species) - double m[2] = { bes->param[0].mass, bes->param[1].mass }; - double q[2] = { bes->param[0].charge, bes->param[1].charge }; + double m[2] = {bes->param[0].mass, bes->param[1].mass}; + double q[2] = {bes->param[0].charge, bes->param[1].charge}; // Grab indices of electron and ion fluid arrays int ELC = bes->param[0].charge < 0.0 ? 0 : 1; @@ -445,20 +498,18 @@ unmag_brag_calc_vars(const gkyl_moment_braginskii *bes, double u_avg[2][3] = {}; if (ndim == 1) { - double dx = bes->grid.dx[0]; + double dx = bes->grid.dx[0]; // Derived quantities - double u[2][2][3] = {}; // Flow for each species, ux, uy, & uz - double T[2][2] = {}; // Temperature for each species (m*p/rho) - double tau[2][2] = {}; // Collision times for each species - double eta[2][2] = {}; // Viscosity for each species - double kappa[2][2] = {}; // Conductivity for each species - double current[2][3] = {}; // (u_i - u_e) + double u[2][2][3] = {}; // Flow for each species, ux, uy, & uz + double T[2][2] = {}; // Temperature for each species (m*p/rho) + double tau[2][2] = {}; // Collision times for each species + double eta[2][2] = {}; // Viscosity for each species + double kappa[2][2] = {}; // Conductivity for each species + double current[2][3] = {}; // (u_i - u_e) // Compute derived quantities - unmag_var_setup(bes, L_1D, U_1D, fluid_d, - u, T, tau, - eta, kappa, current); + unmag_var_setup(bes, L_1D, U_1D, fluid_d, u, T, tau, eta, kappa, current); for (int n = 0; n < nfluids; ++n) { // Viscosity coefficients at cell edges (using harmonic average) @@ -475,32 +526,32 @@ unmag_brag_calc_vars(const gkyl_moment_braginskii *bes, gradxT[n] = calc_sym_grad_1D(dx, T[L_1D][n], T[U_1D][n]); // Average velocity at cell edges (using arithmetic average) - for (int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) { u_avg[n][k] = calc_arithm_avg_1D(u[L_1D][n][k], u[U_1D][n][k]); + } } } // Current multiplied by thermal force coefficient at cell edges (using arithmetic average) - if (bes->param[ELC].type_eqn == GKYL_EQN_EULER) - for (int k = 0; k < 3; ++k) + if (bes->param[ELC].type_eqn == GKYL_EQN_EULER) { + for (int k = 0; k < 3; ++k) { current_avg[k] = calc_arithm_avg_1D(current[L_1D][k], current[U_1D][k]); - } - else if (ndim == 2) { + } + } + } else if (ndim == 2) { double dx = bes->grid.dx[0]; - double dy = bes->grid.dx[1]; + double dy = bes->grid.dx[1]; // Derived quantities - double u[4][2][3] = {}; // Flow for each species, ux, uy, & uz - double T[4][2] = {}; // Temperature for each species (m*p/rho) - double tau[4][2] = {}; // Collision times for each species - double eta[4][2] = {}; // Viscosity for each species - double kappa[4][2] = {}; // Conductivity for each species - double current[4][3] = {}; // (u_i - u_e) + double u[4][2][3] = {}; // Flow for each species, ux, uy, & uz + double T[4][2] = {}; // Temperature for each species (m*p/rho) + double tau[4][2] = {}; // Collision times for each species + double eta[4][2] = {}; // Viscosity for each species + double kappa[4][2] = {}; // Conductivity for each species + double current[4][3] = {}; // (u_i - u_e) // Compute derived quantities - unmag_var_setup(bes, LL_2D, UU_2D, fluid_d, - u, T, tau, - eta, kappa, current); + unmag_var_setup(bes, LL_2D, UU_2D, fluid_d, u, T, tau, eta, kappa, current); for (int n = 0; n < nfluids; ++n) { // Viscosity coefficients at cell edges (using harmonic average) @@ -512,47 +563,60 @@ unmag_brag_calc_vars(const gkyl_moment_braginskii *bes, // Calculate heat flux and viscous heating if energy variable exists if (bes->param[n].type_eqn == GKYL_EQN_EULER) { // Conductivity coefficients at cell edges (using harmonic average) - kappa_avg[n] = calc_harmonic_avg_2D(kappa[LL_2D][n], kappa[LU_2D][n], kappa[UL_2D][n], kappa[UU_2D][n]); + kappa_avg[n] = + calc_harmonic_avg_2D(kappa[LL_2D][n], kappa[LU_2D][n], kappa[UL_2D][n], kappa[UU_2D][n]); gradxT[n] = calc_sym_gradx_2D(dx, T[LL_2D][n], T[LU_2D][n], T[UL_2D][n], T[UU_2D][n]); gradyT[n] = calc_sym_grady_2D(dy, T[LL_2D][n], T[LU_2D][n], T[UL_2D][n], T[UU_2D][n]); // Average velocity at cell edges (using arithmetic average) - for (int k = 0; k < 3; ++k) - u_avg[n][k] = calc_arithm_avg_2D(u[LL_2D][n][k], u[LU_2D][n][k], u[UL_2D][n][k], u[UU_2D][n][k]); + for (int k = 0; k < 3; ++k) { + u_avg[n][k] = + calc_arithm_avg_2D(u[LL_2D][n][k], u[LU_2D][n][k], u[UL_2D][n][k], u[UU_2D][n][k]); + } } } - + // Current multiplied by thermal force coefficient at cell edges (using arithmetic average) - if (bes->param[ELC].type_eqn == GKYL_EQN_EULER) - for (int k = 0; k < 3; ++k) - current_avg[k] = calc_arithm_avg_2D(current[LL_2D][k], current[LU_2D][k], current[UL_2D][k], current[UU_2D][k]); + if (bes->param[ELC].type_eqn == GKYL_EQN_EULER) { + for (int k = 0; k < 3; ++k) { + current_avg[k] = calc_arithm_avg_2D( + current[LL_2D][k], current[LU_2D][k], current[UL_2D][k], current[UU_2D][k] + ); + } + } } for (int n = 0; n < nfluids; ++n) { // Total viscous stress tensor - for (int k = 0; k < 6; ++k) + for (int k = 0; k < 6; ++k) { brag_d[n][PIXX + k] = -eta_avg[n] * w[n][k]; + } - double gradT[3] = { gradxT[n], gradyT[n] , gradzT[n] }; + double gradT[3] = {gradxT[n], gradyT[n], gradzT[n]}; // Pi dot u - double Piu[3] = { brag_d[n][PIXX]*u_avg[n][0] + brag_d[n][PIXY]*u_avg[n][1] + brag_d[n][PIXZ]*u_avg[n][2], - brag_d[n][PIXY]*u_avg[n][0] + brag_d[n][PIYY]*u_avg[n][1] + brag_d[n][PIYZ]*u_avg[n][2], - brag_d[n][PIXZ]*u_avg[n][0] + brag_d[n][PIYZ]*u_avg[n][1] + brag_d[n][PIZZ]*u_avg[n][2] }; + double Piu[3] = { + brag_d[n][PIXX] * u_avg[n][0] + brag_d[n][PIXY] * u_avg[n][1] + brag_d[n][PIXZ] * u_avg[n][2], + brag_d[n][PIXY] * u_avg[n][0] + brag_d[n][PIYY] * u_avg[n][1] + brag_d[n][PIYZ] * u_avg[n][2], + brag_d[n][PIXZ] * u_avg[n][0] + brag_d[n][PIYZ] * u_avg[n][1] + brag_d[n][PIZZ] * u_avg[n][2] + }; // Total heat flux + viscous heating - for (int k = 0; k < 3; ++k) - brag_d[n][QX + k] = -kappa_avg[n]*gradT[k] + Piu[k]; + for (int k = 0; k < 3; ++k) { + brag_d[n][QX + k] = -kappa_avg[n] * gradT[k] + Piu[k]; + } } - for (int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) { brag_d[ELC][QX + k] += current_avg[k]; + } } -static void -brag_calc_update(const gkyl_moment_braginskii *bes, - const double *brag_d[][GKYL_MAX_SPECIES], double *rhs[GKYL_MAX_SPECIES]) +static void brag_calc_update( + const gkyl_moment_braginskii *bes, const double *brag_d[][GKYL_MAX_SPECIES], + double *rhs[GKYL_MAX_SPECIES] +) { int nfluids = bes->nfluids; const int ndim = bes->ndim; @@ -562,10 +626,12 @@ brag_calc_update(const gkyl_moment_braginskii *bes, const double dx = bes->grid.dx[0]; double pi[2][GKYL_MAX_SPECIES][6] = {}; double q[2][GKYL_MAX_SPECIES][3] = {}; - for (int n=0; n < nfluids; ++n) { - for (int j = L_1D; j <= U_1D; ++j) - for (int k = 0; k < 6; ++k) + for (int n = 0; n < nfluids; ++n) { + for (int j = L_1D; j <= U_1D; ++j) { + for (int k = 0; k < 6; ++k) { pi[j][n][k] = brag_d[j][n][PIXX + k]; + } + } div_pi[n][0] = calc_sym_grad_1D(dx, pi[L_1D][n][0], pi[U_1D][n][0]); div_pi[n][1] = calc_sym_grad_1D(dx, pi[L_1D][n][1], pi[U_1D][n][1]); @@ -578,33 +644,39 @@ brag_calc_update(const gkyl_moment_braginskii *bes, // If energy variable exists, increment heat flux and viscous heating if (bes->param[n].type_eqn == GKYL_EQN_EULER) { - for (int j = L_1D; j <= U_1D; ++j) - for (int k = 0; k < 3; ++k) + for (int j = L_1D; j <= U_1D; ++j) { + for (int k = 0; k < 3; ++k) { q[j][n][k] = brag_d[j][n][QX + k]; + } + } div_q[n] = calc_sym_grad_1D(dx, q[L_1D][n][0], q[U_1D][n][0]); rhs[n][ER] = -div_q[n]; } } - } - else if (ndim == 2) { + } else if (ndim == 2) { const double dx = bes->grid.dx[0]; const double dy = bes->grid.dx[1]; double pi[4][GKYL_MAX_SPECIES][6] = {}; double q[4][GKYL_MAX_SPECIES][3] = {}; - for (int n=0; n < nfluids; ++n) { - for (int j = LL_2D; j <= UU_2D; ++j) - for (int k = 0; k < 6; ++k) + for (int n = 0; n < nfluids; ++n) { + for (int j = LL_2D; j <= UU_2D; ++j) { + for (int k = 0; k < 6; ++k) { pi[j][n][k] = brag_d[j][n][PIXX + k]; + } + } + + div_pi[n][0] = + calc_sym_gradx_2D(dx, pi[LL_2D][n][0], pi[LU_2D][n][0], pi[UL_2D][n][0], pi[UU_2D][n][0]) + + calc_sym_grady_2D(dy, pi[LL_2D][n][1], pi[LU_2D][n][1], pi[UL_2D][n][1], pi[UU_2D][n][1]); - div_pi[n][0] = calc_sym_gradx_2D(dx, pi[LL_2D][n][0], pi[LU_2D][n][0], pi[UL_2D][n][0], pi[UU_2D][n][0]) - + calc_sym_grady_2D(dy, pi[LL_2D][n][1], pi[LU_2D][n][1], pi[UL_2D][n][1], pi[UU_2D][n][1]); - - div_pi[n][1] = calc_sym_gradx_2D(dx, pi[LL_2D][n][1], pi[LU_2D][n][1], pi[UL_2D][n][1], pi[UU_2D][n][1]) - + calc_sym_grady_2D(dy, pi[LL_2D][n][3], pi[LU_2D][n][3], pi[UL_2D][n][3], pi[UU_2D][n][3]); - - div_pi[n][2] = calc_sym_gradx_2D(dx, pi[LL_2D][n][2], pi[LU_2D][n][2], pi[UL_2D][n][2], pi[UU_2D][n][2]) - + calc_sym_grady_2D(dy, pi[LL_2D][n][4], pi[LU_2D][n][4], pi[UL_2D][n][4], pi[UU_2D][n][4]); + div_pi[n][1] = + calc_sym_gradx_2D(dx, pi[LL_2D][n][1], pi[LU_2D][n][1], pi[UL_2D][n][1], pi[UU_2D][n][1]) + + calc_sym_grady_2D(dy, pi[LL_2D][n][3], pi[LU_2D][n][3], pi[UL_2D][n][3], pi[UU_2D][n][3]); + + div_pi[n][2] = + calc_sym_gradx_2D(dx, pi[LL_2D][n][2], pi[LU_2D][n][2], pi[UL_2D][n][2], pi[UU_2D][n][2]) + + calc_sym_grady_2D(dy, pi[LL_2D][n][4], pi[LU_2D][n][4], pi[UL_2D][n][4], pi[UU_2D][n][4]); rhs[n][RHO] = 0.0; rhs[n][MX] = -div_pi[n][0]; @@ -613,112 +685,120 @@ brag_calc_update(const gkyl_moment_braginskii *bes, // If energy variable exists, increment heat flux and viscous heating if (bes->param[n].type_eqn == GKYL_EQN_EULER) { - for (int j = LL_2D; j <= UU_2D; ++j) - for (int k = 0; k < 3; ++k) + for (int j = LL_2D; j <= UU_2D; ++j) { + for (int k = 0; k < 3; ++k) { q[j][n][k] = brag_d[j][n][QX + k]; + } + } - div_q[n] = calc_sym_gradx_2D(dx, q[LL_2D][n][0], q[LU_2D][n][0], q[UL_2D][n][0], q[UU_2D][n][0]) - + calc_sym_grady_2D(dy, q[LL_2D][n][1], q[LU_2D][n][1], q[UL_2D][n][1], q[UU_2D][n][1]); + div_q[n] = + calc_sym_gradx_2D(dx, q[LL_2D][n][0], q[LU_2D][n][0], q[UL_2D][n][0], q[UU_2D][n][0]) + + calc_sym_grady_2D(dy, q[LL_2D][n][1], q[LU_2D][n][1], q[UL_2D][n][1], q[UU_2D][n][1]); rhs[n][ER] = -div_q[n]; } } } } -gkyl_moment_braginskii* -gkyl_moment_braginskii_new(struct gkyl_moment_braginskii_inp inp) +gkyl_moment_braginskii *gkyl_moment_braginskii_new(struct gkyl_moment_braginskii_inp inp) { gkyl_moment_braginskii *up = gkyl_malloc(sizeof(gkyl_moment_braginskii)); up->grid = *(inp.grid); up->ndim = up->grid.ndim; up->nfluids = inp.nfluids; - for (int n=0; nparam[n] = inp.param[n]; + for (int n = 0; n < inp.nfluids; ++n) { + up->param[n] = inp.param[n]; + } up->epsilon0 = inp.epsilon0; up->coll_fac = inp.coll_fac; return up; } -static bool -has_mag(const gkyl_moment_braginskii *bes) +static bool has_mag(const gkyl_moment_braginskii *bes) { bool mag = false; - for (int n = 0; n < bes->nfluids; ++n) - if (bes->param[n].type_brag & GKYL_BRAG_MAG) + for (int n = 0; n < bes->nfluids; ++n) { + if (bes->param[n].type_brag & GKYL_BRAG_MAG) { mag = true; + } + } return mag; } -void -gkyl_moment_braginskii_advance(const gkyl_moment_braginskii *bes, - struct gkyl_range brag_vars_range, struct gkyl_range update_range, - struct gkyl_array *fluid[GKYL_MAX_SPECIES], const struct gkyl_array *em_tot, - struct gkyl_array *cflrate[GKYL_MAX_SPECIES], struct gkyl_array *brag_vars[GKYL_MAX_SPECIES], struct gkyl_array *rhs[GKYL_MAX_SPECIES]) +void gkyl_moment_braginskii_advance( + const gkyl_moment_braginskii *bes, struct gkyl_range brag_vars_range, + struct gkyl_range update_range, struct gkyl_array *fluid[GKYL_MAX_SPECIES], + const struct gkyl_array *em_tot, struct gkyl_array *cflrate[GKYL_MAX_SPECIES], + struct gkyl_array *brag_vars[GKYL_MAX_SPECIES], struct gkyl_array *rhs[GKYL_MAX_SPECIES] +) { int nfluids = bes->nfluids; int ndim = update_range.ndim; - long sz[] = { 2, 4, 8 }; + long sz[] = {2, 4, 8}; bool mag = has_mag(bes); - long offsets_vertices[sz[ndim-1]]; + long offsets_vertices[sz[ndim - 1]]; create_offsets_vertices(&brag_vars_range, offsets_vertices); - long offsets_centers[sz[ndim-1]]; + long offsets_centers[sz[ndim - 1]]; create_offsets_centers(&update_range, offsets_centers); - - const double* fluid_d[sz[ndim-1]][GKYL_MAX_SPECIES]; - const double* em_tot_d[sz[ndim-1]]; + + const double *fluid_d[sz[ndim - 1]][GKYL_MAX_SPECIES]; + const double *em_tot_d[sz[ndim - 1]]; double *cflrate_d[GKYL_MAX_SPECIES]; double *brag_vars_d[GKYL_MAX_SPECIES]; - const double* brag_vars_up[sz[ndim-1]][GKYL_MAX_SPECIES]; + const double *brag_vars_up[sz[ndim - 1]][GKYL_MAX_SPECIES]; double *rhs_d[GKYL_MAX_SPECIES]; struct gkyl_range_iter iter_vertex; gkyl_range_iter_init(&iter_vertex, &brag_vars_range); while (gkyl_range_iter_next(&iter_vertex)) { - long linc_vertex = gkyl_range_idx(&brag_vars_range, iter_vertex.idx); long linc_center = gkyl_range_idx(&update_range, iter_vertex.idx); - - for (int i=0; i #include -gkyl_moment_em_coupling* -gkyl_moment_em_coupling_new(struct gkyl_moment_em_coupling_inp inp) +gkyl_moment_em_coupling *gkyl_moment_em_coupling_new(struct gkyl_moment_em_coupling_inp inp) { gkyl_moment_em_coupling *mom_em = gkyl_malloc(sizeof(gkyl_moment_em_coupling)); @@ -27,19 +26,17 @@ gkyl_moment_em_coupling_new(struct gkyl_moment_em_coupling_inp inp) } } - mom_em->static_field = inp.static_field; + mom_em->static_field = inp.static_field; mom_em->t_ramp_E = inp.t_ramp_E; if (mom_em->t_ramp_E != 0.0) { mom_em->ramp_app_E = true; - } - else { + } else { mom_em->ramp_app_E = false; } mom_em->t_ramp_curr = inp.t_ramp_curr; if (mom_em->t_ramp_curr != 0.0) { mom_em->ramp_app_curr = true; - } - else { + } else { mom_em->ramp_app_curr = false; } @@ -52,8 +49,7 @@ gkyl_moment_em_coupling_new(struct gkyl_moment_em_coupling_inp inp) mom_em->nu_base[i][j] = inp.nu_base[i][j]; } } - } - else { + } else { for (int i = 0; i < mom_em->nfluids; i++) { for (int j = 0; j < mom_em->nfluids; j++) { mom_em->nu_base[i][j] = 0.0; @@ -125,11 +121,14 @@ gkyl_moment_em_coupling_new(struct gkyl_moment_em_coupling_inp inp) mom_em->has_vacuum_einstein_conformal_sources = inp.has_vacuum_einstein_conformal_sources; if (mom_em->has_vacuum_einstein_conformal_sources) { - mom_em->vacuum_einstein_conformal_excision_threshold = inp.vacuum_einstein_conformal_excision_threshold; - mom_em->vacuum_einstein_conformal_spacetime_slicing = inp.vacuum_einstein_conformal_spacetime_slicing; - mom_em->vacuum_einstein_conformal_spacetime_evolution = inp.vacuum_einstein_conformal_spacetime_evolution; + mom_em->vacuum_einstein_conformal_excision_threshold = + inp.vacuum_einstein_conformal_excision_threshold; + mom_em->vacuum_einstein_conformal_spacetime_slicing = + inp.vacuum_einstein_conformal_spacetime_slicing; + mom_em->vacuum_einstein_conformal_spacetime_evolution = + inp.vacuum_einstein_conformal_spacetime_evolution; } - + mom_em->has_gr_mhd_sources = inp.has_gr_mhd_sources; if (mom_em->has_gr_mhd_sources) { mom_em->gr_mhd_gas_gamma = inp.gr_mhd_gas_gamma; @@ -138,10 +137,14 @@ gkyl_moment_em_coupling_new(struct gkyl_moment_em_coupling_inp inp) return mom_em; } -void -gkyl_moment_em_coupling_implicit_advance(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, const struct gkyl_range* update_range, - struct gkyl_array* fluid[GKYL_MAX_SPECIES], const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], const struct gkyl_array* p_rhs[GKYL_MAX_SPECIES], - struct gkyl_array* em, const struct gkyl_array* app_current, const struct gkyl_array* ext_em, const struct gkyl_array* nT_sources[GKYL_MAX_SPECIES]) +void gkyl_moment_em_coupling_implicit_advance( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + const struct gkyl_range *update_range, struct gkyl_array *fluid[GKYL_MAX_SPECIES], + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], + const struct gkyl_array *p_rhs[GKYL_MAX_SPECIES], struct gkyl_array *em, + const struct gkyl_array *app_current, const struct gkyl_array *ext_em, + const struct gkyl_array *nT_sources[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; double *fluid_s[GKYL_MAX_SPECIES]; @@ -166,15 +169,22 @@ gkyl_moment_em_coupling_implicit_advance(const gkyl_moment_em_coupling* mom_em, const double *app_current_arr = app_current ? gkyl_array_cfetch(app_current, cell_idx) : 0; const double *ext_em_arr = ext_em ? gkyl_array_cfetch(ext_em, cell_idx) : 0; - implicit_source_coupling_update(mom_em, t_curr, dt, fluid_s, app_accel_s, p_rhs_s, em_arr, app_current_arr, ext_em_arr, nT_sources_s); + implicit_source_coupling_update( + mom_em, t_curr, dt, fluid_s, app_accel_s, p_rhs_s, em_arr, app_current_arr, ext_em_arr, + nT_sources_s + ); } } -void -gkyl_moment_em_coupling_explicit_advance(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, const struct gkyl_range* update_range, - struct gkyl_array* fluid[GKYL_MAX_SPECIES], const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], const struct gkyl_array* p_rhs[GKYL_MAX_SPECIES], - struct gkyl_array* em, const struct gkyl_array* app_current, const struct gkyl_array* app_current1, const struct gkyl_array* app_current2, - const struct gkyl_array* ext_em, const struct gkyl_array* nT_sources[GKYL_MAX_SPECIES], gkyl_fv_proj *proj_app_curr, int nstrang) +void gkyl_moment_em_coupling_explicit_advance( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + const struct gkyl_range *update_range, struct gkyl_array *fluid[GKYL_MAX_SPECIES], + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], + const struct gkyl_array *p_rhs[GKYL_MAX_SPECIES], struct gkyl_array *em, + const struct gkyl_array *app_current, const struct gkyl_array *app_current1, + const struct gkyl_array *app_current2, const struct gkyl_array *ext_em, + const struct gkyl_array *nT_sources[GKYL_MAX_SPECIES], gkyl_fv_proj *proj_app_curr, int nstrang +) { int nfluids = mom_em->nfluids; double *fluid_s[GKYL_MAX_SPECIES]; @@ -202,14 +212,15 @@ gkyl_moment_em_coupling_explicit_advance(const gkyl_moment_em_coupling* mom_em, const double *ext_em_arr = ext_em ? gkyl_array_cfetch(ext_em, cell_idx) : 0; if (mom_em->use_rel) { - explicit_source_coupling_update(mom_em, t_curr, dt_local, fluid_s, app_accel_s, em_arr, app_current_arr, app_current1_arr, app_current2_arr, - ext_em_arr, nstrang); + explicit_source_coupling_update( + mom_em, t_curr, dt_local, fluid_s, app_accel_s, em_arr, app_current_arr, app_current1_arr, + app_current2_arr, ext_em_arr, nstrang + ); } } } -void -gkyl_moment_em_coupling_release(gkyl_moment_em_coupling* mom_em) +void gkyl_moment_em_coupling_release(gkyl_moment_em_coupling *mom_em) { gkyl_free(mom_em); } \ No newline at end of file diff --git a/moments/zero/moment_prim_mhd.c b/moments/zero/moment_prim_mhd.c index 98f0c1daf3..8e1d4a4a57 100644 --- a/moments/zero/moment_prim_mhd.c +++ b/moments/zero/moment_prim_mhd.c @@ -14,41 +14,37 @@ #define BZ (7) #define PSI_GLM (8) -#define sq(x) ((x)*(x)) +#define sq(x) ((x) * (x)) -double -gkyl_mhd_fast_speed(double gas_gamma, const double q[8]) +double gkyl_mhd_fast_speed(double gas_gamma, const double q[8]) { double u1 = q[MX] / q[DN]; double u2 = q[MY] / q[DN]; double u3 = q[MZ] / q[DN]; - double k = q[DN] * (u1*u1 + u2*u2 + u3*u3) / 2; // bulk kinetic energy + double k = q[DN] * (u1 * u1 + u2 * u2 + u3 * u3) / 2; // bulk kinetic energy double BX_sq = sq(q[BX]); double B_sq = BX_sq + sq(q[BY]) + sq(q[BZ]); double pb = B_sq / 2; // magnetic pressure - double p = (gas_gamma-1) * (q[ER] - k - pb); // plasma pressure + double p = (gas_gamma - 1) * (q[ER] - k - pb); // plasma pressure double a_sq = gas_gamma * p / q[DN]; // sound speed - double ca_sq = B_sq / q[DN]; // Alfven speed - double ca1_sq = BX_sq / q[DN]; // Alfven speed due to normal B field + double ca_sq = B_sq / q[DN]; // Alfven speed + double ca1_sq = BX_sq / q[DN]; // Alfven speed due to normal B field // fast speed - double cf = sqrt(a_sq+ca_sq + sqrt(sq(a_sq + ca_sq) - 4*a_sq*ca1_sq)) / 2; + double cf = sqrt(a_sq + ca_sq + sqrt(sq(a_sq + ca_sq) - 4 * a_sq * ca1_sq)) / 2; return cf; } -double -gkyl_mhd_max_abs_speed(double gas_gamma, const double q[8]) +double gkyl_mhd_max_abs_speed(double gas_gamma, const double q[8]) { double cf = gkyl_mhd_fast_speed(gas_gamma, q); - double u = sqrt( sq(q[1]) + sq(q[2]) + sq(q[3]) ) / q[0]; + double u = sqrt(sq(q[1]) + sq(q[2]) + sq(q[3])) / q[0]; return u + cf; } -void -gkyl_mhd_eigen_speeds_roe(const double gamma, const double *ql, const double *qr, - double buf[]) +void gkyl_mhd_eigen_speeds_roe(const double gamma, const double *ql, const double *qr, double buf[]) { ////////////////////////////////////////////////////////////////////////////// // STEP 1: COMPUTE PRIMITIVE VARIABLES // @@ -76,7 +72,7 @@ gkyl_mhd_eigen_speeds_roe(const double gamma, const double *ql, const double *qr double u = sl * ul + sr * ur; double v = sl * vl + sr * vr; double w = sl * wl + sr * wr; - double H = sl * Hl + sr * Hr; // total enthalpy + double H = sl * Hl + sr * Hr; // total enthalpy double Bx = sr * ql[BX] + sl * qr[BX]; double By = sr * ql[BY] + sl * qr[BY]; double Bz = sr * ql[BZ] + sl * qr[BZ]; @@ -84,16 +80,16 @@ gkyl_mhd_eigen_speeds_roe(const double gamma, const double *ql, const double *qr ////////////////////////////////////////////////////////////////////////////// // STEP 3: COMPUTE CHARACTERASTIC WAVE SPEEDS AND OTHER USEFUL QUANTITIES // ////////////////////////////////////////////////////////////////////////////// - double X = (sq(qr[BX] - ql[BX]) + sq(qr[BY] - ql[BY]) + sq(qr[BZ] - qr[BZ])) / - (2 * sq(srrhol + srrhor)); - double ca2 = Bx*Bx/rho; // for alfven speed due to normal B field - double b2 = (Bx*Bx+By*By+Bz*Bz) / rho; // for alfven speed due to full B field - double v2 = u*u+v*v+w*w; - double Hgas = H - b2; // enthalpy of the gas - double a2 = (2-gamma)*X + (gamma-1)*(Hgas-0.5*v2); // for sound speed + double X = + (sq(qr[BX] - ql[BX]) + sq(qr[BY] - ql[BY]) + sq(qr[BZ] - qr[BZ])) / (2 * sq(srrhol + srrhor)); + double ca2 = Bx * Bx / rho; // for alfven speed due to normal B field + double b2 = (Bx * Bx + By * By + Bz * Bz) / rho; // for alfven speed due to full B field + double v2 = u * u + v * v + w * w; + double Hgas = H - b2; // enthalpy of the gas + double a2 = (2 - gamma) * X + (gamma - 1) * (Hgas - 0.5 * v2); // for sound speed double astar2 = a2 + b2; - double cf2 = (astar2 + sqrt(sq(astar2)-4*a2*ca2)) / 2; // fast wave speed + double cf2 = (astar2 + sqrt(sq(astar2) - 4 * a2 * ca2)) / 2; // fast wave speed buf[0] = u; buf[1] = v; @@ -101,8 +97,7 @@ gkyl_mhd_eigen_speeds_roe(const double gamma, const double *ql, const double *qr buf[3] = sqrt(cf2); } -double -gkyl_mhd_max_abs_speed_roe(const double gamma, const double *ql, const double *qr) +double gkyl_mhd_max_abs_speed_roe(const double gamma, const double *ql, const double *qr) { double buf[4]; gkyl_mhd_eigen_speeds_roe(gamma, ql, qr, buf); @@ -113,42 +108,43 @@ gkyl_mhd_max_abs_speed_roe(const double gamma, const double *ql, const double *q return v_tot + cf; } -void -gkyl_mhd_cons_vars(double gas_gamma, const double pv[8], double q[8]) +void gkyl_mhd_cons_vars(double gas_gamma, const double pv[8], double q[8]) { double rho = pv[0], u = pv[1], v = pv[2], w = pv[3], pr = pv[4]; q[0] = rho; - q[1] = rho*u; q[2] = rho*v; q[3] = rho*w; - q[5] = pv[5]; q[6] = pv[6]; q[7] = pv[7]; // B field - double pb = 0.5*(pv[5]*pv[5]+pv[6]*pv[6]+pv[7]*pv[7]); // magnetic pressure - q[4] = pr/(gas_gamma-1) + 0.5*rho*(u*u+v*v+w*w) + pb; + q[1] = rho * u; + q[2] = rho * v; + q[3] = rho * w; + q[5] = pv[5]; + q[6] = pv[6]; + q[7] = pv[7]; // B field + double pb = 0.5 * (pv[5] * pv[5] + pv[6] * pv[6] + pv[7] * pv[7]); // magnetic pressure + q[4] = pr / (gas_gamma - 1) + 0.5 * rho * (u * u + v * v + w * w) + pb; } -void -gkyl_mhd_flux(double gas_gamma, const double q[8], double flux[8]) +void gkyl_mhd_flux(double gas_gamma, const double q[8], double flux[8]) { double u1 = q[MX] / q[DN]; double u2 = q[MY] / q[DN]; double u3 = q[MZ] / q[DN]; - double k = q[DN] * (u1*u1 + u2*u2 + u3*u3) / 2; // bulk kinetic energy + double k = q[DN] * (u1 * u1 + u2 * u2 + u3 * u3) / 2; // bulk kinetic energy double pb = (sq(q[BX]) + sq(q[BY]) + sq(q[BZ])) / 2; // magnetic pressure - double p = (gas_gamma-1) * (q[ER] - k - pb); // plasma pressure + double p = (gas_gamma - 1) * (q[ER] - k - pb); // plasma pressure flux[DN] = q[MX]; - flux[MX] = u1*q[MX] - q[BX]*q[BX] + p + pb; - flux[MY] = u1*q[MY] - q[BX]*q[BY]; - flux[MZ] = u1*q[MZ] - q[BX]*q[BZ]; - flux[ER] = u1*(q[ER]+p+pb) - q[BX]*(u1*q[BX]+u2*q[BY]+u3*q[BZ]); + flux[MX] = u1 * q[MX] - q[BX] * q[BX] + p + pb; + flux[MY] = u1 * q[MY] - q[BX] * q[BY]; + flux[MZ] = u1 * q[MZ] - q[BX] * q[BZ]; + flux[ER] = u1 * (q[ER] + p + pb) - q[BX] * (u1 * q[BX] + u2 * q[BY] + u3 * q[BZ]); flux[BX] = 0.0; - flux[BY] = u1*q[BY] - u2*q[BX]; - flux[BZ] = u1*q[BZ] - u3*q[BX]; + flux[BY] = u1 * q[BY] - u2 * q[BX]; + flux[BZ] = u1 * q[BZ] - u3 * q[BX]; } -void -gkyl_glm_mhd_flux(double gas_gamma, double ch, const double q[9], double flux[9]) +void gkyl_glm_mhd_flux(double gas_gamma, double ch, const double q[9], double flux[9]) { gkyl_mhd_flux(gas_gamma, q, flux); flux[BX] = q[PSI_GLM]; - flux[PSI_GLM] = ch*ch*q[BX]; + flux[PSI_GLM] = ch * ch * q[BX]; } diff --git a/moments/zero/moment_prim_sr_euler.c b/moments/zero/moment_prim_sr_euler.c index 7a090e0a16..77a04fafb5 100644 --- a/moments/zero/moment_prim_sr_euler.c +++ b/moments/zero/moment_prim_sr_euler.c @@ -5,33 +5,32 @@ #define TV 3 #define TW 4 -double -gkyl_sr_euler_max_abs_speed(double gas_gamma, const double q[5]) +double gkyl_sr_euler_max_abs_speed(double gas_gamma, const double q[5]) { double v[5]; gkyl_sr_euler_prim_vars(gas_gamma, q, v); double pr = v[1]; - double gamma = 1. / sqrt(1. - (v[2]*v[2] + v[3]*v[3] + v[4]*v[4])); + double gamma = 1. / sqrt(1. - (v[2] * v[2] + v[3] * v[3] + v[4] * v[4])); double fac0 = q[1] + pr; - double v4 = gamma*gamma*pr/fac0; - double fac1 = 1 - gas_gamma*v4; - double fac2 = gas_gamma*pr*fac1*(fac0 - q[2]*q[2] / fac0) + gas_gamma*gas_gamma*pr*pr; - - return (fac1*q[2] + sqrt(fac2)) / (fac1*fac0 + gas_gamma*pr); + double v4 = gamma * gamma * pr / fac0; + double fac1 = 1 - gas_gamma * v4; + double fac2 = + gas_gamma * pr * fac1 * (fac0 - q[2] * q[2] / fac0) + gas_gamma * gas_gamma * pr * pr; + + return (fac1 * q[2] + sqrt(fac2)) / (fac1 * fac0 + gas_gamma * pr); } -void -gkyl_sr_euler_flux(double gas_gamma, const double q[5], double flux[5]) +void gkyl_sr_euler_flux(double gas_gamma, const double q[5], double flux[5]) { double v[5]; gkyl_sr_euler_prim_vars(gas_gamma, q, v); double pr = v[1]; double fac0 = q[1] + pr; - flux[0] = q[0]*q[TU]/fac0; // gamma*rho*u + flux[0] = q[0] * q[TU] / fac0; // gamma*rho*u flux[1] = q[TU]; //gamma^2*rho*h*u - flux[TU] = q[TU]*q[TU]/fac0 + pr; // gamma^2*rho*h*u*u + pr - flux[TV] = q[TU]*q[TV]/fac0; // gamma^2*rho*h*u*v - flux[TW] = q[TU]*q[TW]/fac0; // gamma^2*rho*h*u*w + flux[TU] = q[TU] * q[TU] / fac0 + pr; // gamma^2*rho*h*u*u + pr + flux[TV] = q[TU] * q[TV] / fac0; // gamma^2*rho*h*u*v + flux[TW] = q[TU] * q[TW] / fac0; // gamma^2*rho*h*u*w } diff --git a/moments/zero/mp_scheme.c b/moments/zero/mp_scheme.c index 74e8aceb27..7efc333b60 100644 --- a/moments/zero/mp_scheme.c +++ b/moments/zero/mp_scheme.c @@ -10,10 +10,10 @@ #include // type signature for function to do recovery -typedef void (*recovery_fn_t)(int meqn, - const double *f3m, const double *f2m, const double *fm, - const double *fp, const double *f2p, const double *f3p, - double *outl, double *outr); +typedef void (*recovery_fn_t)( + int meqn, const double *f3m, const double *f2m, const double *fm, const double *fp, + const double *f2p, const double *f3p, double *outl, double *outr +); struct gkyl_mp_scheme { struct gkyl_rect_grid grid; // grid object @@ -21,10 +21,10 @@ struct gkyl_mp_scheme { int num_up_dirs; // number of update directions int update_dirs[GKYL_MAX_DIM]; // directions to update enum gkyl_mp_recon mp_recon; // base reconstruction to use - bool skip_mp_limiter; // should we skip MP limiter? + bool skip_mp_limiter; // should we skip MP limiter? + + double cfl; // CFL number - double cfl; // CFL number - const struct gkyl_wv_eqn *equation; // equation object struct gkyl_wave_geom *geom; // geometry object @@ -36,115 +36,113 @@ struct gkyl_mp_scheme { // the interface. Note that depending on the scheme, some of the input // values may be ignored. -static inline void -c2_recovery(int meqn, - const double *f3m, const double *f2m, const double *fm, - const double *fp, const double *f2p, const double *f3p, - double *outl, double *outr) +static inline void c2_recovery( + int meqn, const double *f3m, const double *f2m, const double *fm, const double *fp, + const double *f2p, const double *f3p, double *outl, double *outr +) { // c2 is symmetric 2nd order scheme, so outl and outr are same - for (int m=0; m0 && y>0) - return fmin(x,y); - if (x<0 && y<0) - return fmax(x,y); + if (x > 0 && y > 0) { + return fmin(x, y); + } + if (x < 0 && y < 0) { + return fmax(x, y); + } return 0.0; } -static inline double -minmod_4(double x, double y, double z, double w) +static inline double minmod_4(double x, double y, double z, double w) { - if (x>0 && y>0 && z>0 && w>0) - return fmin(fmin(x,y),fmin(z,w)); - if (x<0 && y<0 && z<0 && w<0) - return fmax(fmax(x,y),fmax(z,w)); + if (x > 0 && y > 0 && z > 0 && w > 0) { + return fmin(fmin(x, y), fmin(z, w)); + } + if (x < 0 && y < 0 && z < 0 && w < 0) { + return fmax(fmax(x, y), fmax(z, w)); + } return 0.0; } -static inline double -median(double x, double y, double z) +static inline double median(double x, double y, double z) { - return x + minmod_2(y-x,z-x); + return x + minmod_2(y - x, z - x); } -static inline double -min_3(double x, double y, double z) +static inline double min_3(double x, double y, double z) { - return fmin(x,fmin(y,z)); + return fmin(x, fmin(y, z)); } -static inline double -max_3(double x, double y, double z) +static inline double max_3(double x, double y, double z) { - return fmax(x,fmax(y,z)); + return fmax(x, fmax(y, z)); } // MP limiter: See Eqns 3.44 - 3.57 of Peterson and Hammett SIAM @@ -153,99 +151,100 @@ static inline double mp_limiter(double qe, double q2m, double q1m, double q0, double q1p, double q2p) { double alpha = 4.0; - // Suresh and Huynh recommend 1e-10, but that seems turns off the - // limiter when the jumps are very tiny, leading to small-scale noise - // in certain situations. Not sure what this should be. Greg Hammett - // recommends eps = 0.0 + // Suresh and Huynh recommend 1e-10, but that seems turns off the + // limiter when the jumps are very tiny, leading to small-scale noise + // in certain situations. Not sure what this should be. Greg Hammett + // recommends eps = 0.0 double eps = 0.0; // Eq 3.44 - double qmp = q0 + minmod_2(q1p-q0, alpha*(q0-q1m)); + double qmp = q0 + minmod_2(q1p - q0, alpha * (q0 - q1m)); //return median(qe, q0, qmp); // Eq 3.45 - if ((qe-q0)*(qe-qmp)grid = *(mpinp->grid); mp->ndim = mp->grid.ndim; - + mp->num_up_dirs = mpinp->num_up_dirs; - for (int i=0; inum_up_dirs; ++i) + for (int i = 0; i < mpinp->num_up_dirs; ++i) { mp->update_dirs[i] = mpinp->update_dirs[i]; + } mp->mp_recon = mpinp->mp_recon; mp->skip_mp_limiter = mpinp->skip_mp_limiter; - + mp->cfl = mpinp->cfl; - + mp->equation = gkyl_wv_eqn_acquire(mpinp->equation); mp->geom = gkyl_wave_geom_acquire(mpinp->geom); switch (mpinp->mp_recon) { - case GKYL_MP_C2: - mp->recovery_fn = c2_recovery; - break; - case GKYL_MP_C4: - mp->recovery_fn = c4_recovery; - break; - case GKYL_MP_C6: - mp->recovery_fn = c6_recovery; - break; - case GKYL_MP_U1: - mp->recovery_fn = u1_recovery; - break; - case GKYL_MP_U3: - mp->recovery_fn = u3_recovery; - break; - case GKYL_MP_U5: - mp->recovery_fn = u5_recovery; - break; + case GKYL_MP_C2: + mp->recovery_fn = c2_recovery; + break; + case GKYL_MP_C4: + mp->recovery_fn = c4_recovery; + break; + case GKYL_MP_C6: + mp->recovery_fn = c6_recovery; + break; + case GKYL_MP_U1: + mp->recovery_fn = u1_recovery; + break; + case GKYL_MP_U3: + mp->recovery_fn = u3_recovery; + break; + case GKYL_MP_U5: + mp->recovery_fn = u5_recovery; + break; } return mp; } -void -gkyl_mp_scheme_advance(gkyl_mp_scheme *mp, - const struct gkyl_range *update_range, const struct gkyl_array *qin, - struct gkyl_array *qrec_l, struct gkyl_array *qrec_r, - struct gkyl_array *amdq, struct gkyl_array *apdq, - struct gkyl_array *cflrate, struct gkyl_array *phi, struct gkyl_array *rhs) +void gkyl_mp_scheme_advance( + gkyl_mp_scheme *mp, const struct gkyl_range *update_range, const struct gkyl_array *qin, + struct gkyl_array *qrec_l, struct gkyl_array *qrec_r, struct gkyl_array *amdq, + struct gkyl_array *apdq, struct gkyl_array *cflrate, struct gkyl_array *phi, + struct gkyl_array *rhs +) { int ndim = update_range->ndim; int meqn = mp->equation->num_equations; @@ -253,34 +252,36 @@ gkyl_mp_scheme_advance(gkyl_mp_scheme *mp, double apdq_local[meqn], amdq_local[meqn]; double qlocal_r[meqn], qlocal_l[meqn]; - double delta[meqn], waves[meqn*mwaves], speeds[mwaves]; + double delta[meqn], waves[meqn * mwaves], speeds[mwaves]; // labels for three cells to left, three cells to right of edge: enum { I3M, I2M, IM, IP, I2P, I3P }; gkyl_array_clear_range(rhs, 0.0, update_range); - + // outer loop is over direction: the RHS is updated direction // by direction - for (int d=0; dnum_up_dirs; ++d) { + for (int d = 0; d < mp->num_up_dirs; ++d) { int dir = mp->update_dirs[d]; double dx = mp->grid.dx[dir]; // compute index offsets of cells on left/right of edge long offsets[6]; - offsets[IP] = get_offset(dir, 0, update_range); + offsets[IP] = get_offset(dir, 0, update_range); offsets[I2P] = get_offset(dir, 1, update_range); offsets[I3P] = get_offset(dir, 2, update_range); - offsets[IM] = get_offset(dir, -1, update_range); + offsets[IM] = get_offset(dir, -1, update_range); offsets[I2M] = get_offset(dir, -2, update_range); offsets[I3M] = get_offset(dir, -3, update_range); const double *qavg[6]; // pointers to cells attached to edge // create range that includes one extra layer on the upper size - int upper[GKYL_MAX_CDIM] = { 0 }; - for (int d=0; dndim; ++d) upper[d] = update_range->upper[d]; + int upper[GKYL_MAX_CDIM] = {0}; + for (int d = 0; d < update_range->ndim; ++d) { + upper[d] = update_range->upper[d]; + } upper[dir] += 1; struct gkyl_range update_range_ext; gkyl_range_init(&update_range_ext, update_range->ndim, update_range->lower, upper); @@ -292,59 +293,72 @@ gkyl_mp_scheme_advance(gkyl_mp_scheme *mp, gkyl_range_iter_init(&iter, &update_range_ext); while (gkyl_range_iter_next(&iter)) { // Note: edge is between cells IM and IP - + long loc = gkyl_range_idx(update_range, iter.idx); // attach pointers to cells for recovery - for (int i=0; i<6; ++i) - qavg[i] = gkyl_array_cfetch(qin, loc+offsets[i]); + for (int i = 0; i < 6; ++i) { + qavg[i] = gkyl_array_cfetch(qin, loc + offsets[i]); + } // qr_l is left of edge (right edge of left cell), qr_r right of // edge (left edge of right cell) - double *qr_l = gkyl_array_fetch(qrec_r, loc+offsets[IM]); - double *qr_r = gkyl_array_fetch(qrec_l, loc+offsets[IP]); + double *qr_l = gkyl_array_fetch(qrec_r, loc + offsets[IM]); + double *qr_r = gkyl_array_fetch(qrec_l, loc + offsets[IP]); - const double *phil = gkyl_array_cfetch(phi, loc+offsets[IM]); - const double *phir = gkyl_array_cfetch(phi, loc+offsets[IP]); + const double *phil = gkyl_array_cfetch(phi, loc + offsets[IM]); + const double *phir = gkyl_array_cfetch(phi, loc + offsets[IP]); // recover variables at cell edge - mp->recovery_fn(meqn, qavg[I3M], qavg[I2M], qavg[IM], - qavg[IP], qavg[I2P], qavg[I3P], - qr_l, qr_r); + mp->recovery_fn( + meqn, qavg[I3M], qavg[I2M], qavg[IM], qavg[IP], qavg[I2P], qavg[I3P], qr_l, qr_r + ); if (!mp->skip_mp_limiter) { // apply MP limiter to left and right edge recovered values - for (int m=0; mgeom, iter.idx); // rotate ql and qr to local frame - mp->equation->rotate_to_local_func(mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qr_l, qlocal_l); - mp->equation->rotate_to_local_func(mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qr_r, qlocal_r); + mp->equation->rotate_to_local_func( + mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qr_l, qlocal_l + ); + mp->equation->rotate_to_local_func( + mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qr_r, qlocal_r + ); + + for (int m = 0; m < meqn; ++m) { + delta[m] = qlocal_r[m] - qlocal_l[m]; + } - for (int m=0; mequation, GKYL_WV_HIGH_ORDER_FLUX, delta, - qlocal_l, qlocal_r, phil[0], phir[0], waves, speeds); - gkyl_wv_eqn_qfluct(mp->equation, GKYL_WV_HIGH_ORDER_FLUX, - qlocal_l, qlocal_r, phil[0], phir[0], waves, speeds, amdq_local, apdq_local); - - double *amdq_p = gkyl_array_fetch(amdq, loc+offsets[IM]); - double *apdq_p = gkyl_array_fetch(apdq, loc+offsets[IP]); + gkyl_wv_eqn_waves( + mp->equation, GKYL_WV_HIGH_ORDER_FLUX, delta, qlocal_l, qlocal_r, phil[0], phir[0], waves, + speeds + ); + gkyl_wv_eqn_qfluct( + mp->equation, GKYL_WV_HIGH_ORDER_FLUX, qlocal_l, qlocal_r, phil[0], phir[0], waves, speeds, + amdq_local, apdq_local + ); + + double *amdq_p = gkyl_array_fetch(amdq, loc + offsets[IM]); + double *apdq_p = gkyl_array_fetch(apdq, loc + offsets[IP]); // rotate fluctuations back to global frame - mp->equation->rotate_to_global_func(mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], amdq_local, amdq_p); - mp->equation->rotate_to_global_func(mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], apdq_local, apdq_p); + mp->equation->rotate_to_global_func( + mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], amdq_local, amdq_p + ); + mp->equation->rotate_to_global_func( + mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], apdq_local, apdq_p + ); } double deltaf_local[meqn], deltaf[meqn]; @@ -359,58 +373,62 @@ gkyl_mp_scheme_advance(gkyl_mp_scheme *mp, const double *qr_l = gkyl_array_cfetch(qrec_l, loc); const double *qr_r = gkyl_array_cfetch(qrec_r, loc); - + // rotate ql and qr to local frame - mp->equation->rotate_to_local_func(mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qr_l, qlocal_l); - mp->equation->rotate_to_local_func(mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qr_r, qlocal_r); + mp->equation->rotate_to_local_func( + mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qr_l, qlocal_l + ); + mp->equation->rotate_to_local_func( + mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qr_r, qlocal_r + ); double amax = gkyl_wv_eqn_flux_jump(mp->equation, qlocal_l, qlocal_r, deltaf_local); // rotate deltaf back to global frame - mp->equation->rotate_to_local_func(mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], deltaf_local, deltaf); + mp->equation->rotate_to_local_func( + mp->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], deltaf_local, deltaf + ); const double *amdq_p = gkyl_array_cfetch(amdq, loc); const double *apdq_p = gkyl_array_cfetch(apdq, loc); double *rhs_p = gkyl_array_fetch(rhs, loc); - for (int m=0; mnum_up_dirs; ++d) { + for (int d = 0; d < mp->num_up_dirs; ++d) { int dir = mp->update_dirs[d]; double dx = mp->grid.dx[dir]; const double *q = gkyl_array_cfetch(qin, gkyl_range_idx(update_range, iter.idx)); double maxs = gkyl_wv_eqn_max_speed(mp->equation, q); - max_dt = fmin(max_dt, mp->cfl*dx/maxs); + max_dt = fmin(max_dt, mp->cfl * dx / maxs); } - } - return max_dt; + return max_dt; } -void -gkyl_mp_scheme_release(gkyl_mp_scheme* mp) +void gkyl_mp_scheme_release(gkyl_mp_scheme *mp) { gkyl_wv_eqn_release(mp->equation); gkyl_wave_geom_release(mp->geom); - + gkyl_free(mp); } diff --git a/moments/zero/sources_explicit.c b/moments/zero/sources_explicit.c index e0b008cf68..2d33d9d807 100644 --- a/moments/zero/sources_explicit.c +++ b/moments/zero/sources_explicit.c @@ -5,8 +5,9 @@ #include #include -void -explicit_nT_source_update_euler(const double mass, const double dt, double* fluid_old, double* fluid_new, const double* nT_sources) +void explicit_nT_source_update_euler( + const double mass, const double dt, double *fluid_old, double *fluid_new, const double *nT_sources +) { double rho_old = fluid_old[0]; double n_old = rho_old / mass; @@ -28,9 +29,10 @@ explicit_nT_source_update_euler(const double mass, const double dt, double* flui fluid_new[4] = (n_new * TT_new) + (0.5 * rho_new * v_sq); } -void -explicit_nT_source_update(const gkyl_moment_em_coupling* mom_em, const double dt, double* fluid_s[GKYL_MAX_SPECIES], - const double* nT_sources_s[GKYL_MAX_SPECIES]) +void explicit_nT_source_update( + const gkyl_moment_em_coupling *mom_em, const double dt, double *fluid_s[GKYL_MAX_SPECIES], + const double *nT_sources_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; @@ -44,9 +46,11 @@ explicit_nT_source_update(const gkyl_moment_em_coupling* mom_em, const double dt } } -void -explicit_frictional_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double Z, const double T_elc, const double Lambda_ee, - double t_curr, const double dt, double* f_elc_old, double* f_ion_old, double* f_elc_new, double* f_ion_new) +void explicit_frictional_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double Z, const double T_elc, const double Lambda_ee, + double t_curr, const double dt, double *f_elc_old, double *f_ion_old, double *f_elc_new, + double *f_ion_new +) { int nfluids = mom_em->nfluids; double pi = M_PI; @@ -54,7 +58,7 @@ explicit_frictional_source_update_euler(const gkyl_moment_em_coupling* mom_em, c if (nfluids == 2) { double mass_elc = mom_em->param[0].mass; double epsilon0 = mom_em->epsilon0; - + double rho_elc = f_elc_old[0]; double rho_ion = f_ion_old[0]; @@ -63,9 +67,12 @@ explicit_frictional_source_update_euler(const gkyl_moment_em_coupling* mom_em, c double n_elc = rho_elc / mass_elc; - double tau_ei = (1.0 / Z) * ((3.0 * sqrt(mass_elc) * ((4.0 * pi * epsilon0) * (4.0 * pi * epsilon0)) * pow(T_elc, 3.0 / 2.0)) / - (4.0 * sqrt(2.0 * pi) * n_elc * exp(4.0) * log(Lambda_ee))); - double alpha_par = 1.0 - (pow(Z, 2.0 / 3.0) / ((1.46 * pow(Z, 2.0 / 3.0)) - (0.33 * pow (Z, 1.0 / 3.0)) + 0.888)); + double tau_ei = + (1.0 / Z) * ((3.0 * sqrt(mass_elc) * ((4.0 * pi * epsilon0) * (4.0 * pi * epsilon0)) * + pow(T_elc, 3.0 / 2.0)) / + (4.0 * sqrt(2.0 * pi) * n_elc * exp(4.0) * log(Lambda_ee))); + double alpha_par = + 1.0 - (pow(Z, 2.0 / 3.0) / ((1.46 * pow(Z, 2.0 / 3.0)) - (0.33 * pow(Z, 1.0 / 3.0)) + 0.888)); double mom_src_x = -(rho_elc / tau_ei) * (alpha_par * (u_elc - u_ion)); double mom_src_y = -(rho_elc / tau_ei) * (alpha_par * (v_elc - v_ion)); @@ -93,8 +100,10 @@ explicit_frictional_source_update_euler(const gkyl_moment_em_coupling* mom_em, c } } -void -explicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]) +void explicit_frictional_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; @@ -111,8 +120,7 @@ explicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double if (mom_em->param[0].type == GKYL_EQN_EULER) { elc_num_equations = 5; - } - else if (mom_em->param[0].type == GKYL_EQN_ISO_EULER) { + } else if (mom_em->param[0].type == GKYL_EQN_ISO_EULER) { elc_num_equations = 4; } @@ -124,8 +132,7 @@ explicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double if (mom_em->param[1].type == GKYL_EQN_EULER) { ion_num_equations = 5; - } - else if (mom_em->param[1].type == GKYL_EQN_ISO_EULER) { + } else if (mom_em->param[1].type == GKYL_EQN_ISO_EULER) { ion_num_equations = 4; } @@ -142,7 +149,9 @@ explicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double f_ion_old[i] = f_ion[i]; } - explicit_frictional_source_update_euler(mom_em, Z, T_elc, Lambda_ee, t_curr, dt, f_elc_old, f_ion_old, f_elc_new, f_ion_new); + explicit_frictional_source_update_euler( + mom_em, Z, T_elc, Lambda_ee, t_curr, dt, f_elc_old, f_ion_old, f_elc_new, f_ion_new + ); for (int i = 0; i < elc_num_equations; i++) { f_elc_stage1[i] = f_elc_new[i]; } @@ -150,7 +159,9 @@ explicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double f_ion_stage1[i] = f_ion_new[i]; } - explicit_frictional_source_update_euler(mom_em, Z, T_elc, Lambda_ee, t_curr + dt, dt, f_elc_stage1, f_ion_stage1, f_elc_new, f_ion_new); + explicit_frictional_source_update_euler( + mom_em, Z, T_elc, Lambda_ee, t_curr + dt, dt, f_elc_stage1, f_ion_stage1, f_elc_new, f_ion_new + ); for (int i = 0; i < elc_num_equations; i++) { f_elc_stage2[i] = (0.75 * f_elc_old[i]) + (0.25 * f_elc_new[i]); } @@ -158,7 +169,10 @@ explicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double f_ion_stage2[i] = (0.75 * f_ion_old[i]) + (0.25 * f_ion_new[i]); } - explicit_frictional_source_update_euler(mom_em, Z, T_elc, Lambda_ee, t_curr + (0.5 * dt), dt, f_elc_stage2, f_ion_stage2, f_elc_new, f_ion_new); + explicit_frictional_source_update_euler( + mom_em, Z, T_elc, Lambda_ee, t_curr + (0.5 * dt), dt, f_elc_stage2, f_ion_stage2, f_elc_new, + f_ion_new + ); for (int i = 0; i < elc_num_equations; i++) { f_elc[i] = ((1.0 / 3.0) * f_elc_old[i]) + ((2.0 / 3.0) * f_elc_new[i]); } @@ -168,9 +182,10 @@ explicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double } } -void -explicit_volume_source_5m_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, const double U0, const double R0, - double t_curr, const double dt, double* fluid_old, double* fluid_new) +void explicit_volume_source_5m_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, const double U0, const double R0, + double t_curr, const double dt, double *fluid_old, double *fluid_new +) { double rho = fluid_old[0]; double vx = fluid_old[1] / rho; @@ -195,15 +210,16 @@ explicit_volume_source_5m_update_euler(const gkyl_moment_em_coupling* mom_em, co fluid_new[4] = (p_new / (gas_gamma - 1.0)) + (0.5 * rho * (vx * vx) + (vy * vy) + (vz * vz)); } -void -explicit_volume_source_10m_update_euler(const gkyl_moment_em_coupling* mom_em, const double U0, const double R0, double t_curr, const double dt, - double* fluid_old, double* fluid_new) +void explicit_volume_source_10m_update_euler( + const gkyl_moment_em_coupling *mom_em, const double U0, const double R0, double t_curr, + const double dt, double *fluid_old, double *fluid_new +) { double rho = fluid_old[0]; double vx = fluid_old[1] / rho; double vy = fluid_old[2] / rho; double vz = fluid_old[3] / rho; - + double Pxx = fluid_old[4], Pxy = fluid_old[5], Pxz = fluid_old[6]; double Pyy = fluid_old[7], Pyz = fluid_old[8], Pzz = fluid_old[9]; @@ -226,9 +242,10 @@ explicit_volume_source_10m_update_euler(const gkyl_moment_em_coupling* mom_em, c fluid_new[9] -= dt * ((((2.0 * U0) / (a * R0)) * Pzz) + (((2.0 * U0) / (a * R0)) * Pzz)); } -void -explicit_volume_source_maxwell_update_euler(const gkyl_moment_em_coupling* mom_em, const double U0, const double R0, double t_curr, - const double dt, double* em_old, double* em_new, const double* ext_em) +void explicit_volume_source_maxwell_update_euler( + const gkyl_moment_em_coupling *mom_em, const double U0, const double R0, double t_curr, + const double dt, double *em_old, double *em_new, const double *ext_em +) { double a = 1.0 + ((U0 * t_curr) / R0); @@ -253,9 +270,10 @@ explicit_volume_source_maxwell_update_euler(const gkyl_moment_em_coupling* mom_e em_new[5] -= dt * (U0 / (a * R0)) * Bz; } -void -explicit_volume_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES], - double* em, const double* ext_em) +void explicit_volume_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES], double *em, const double *ext_em +) { int nfluids = mom_em->nfluids; @@ -278,17 +296,20 @@ explicit_volume_source_update(const gkyl_moment_em_coupling* mom_em, double t_cu f_stage1[j] = f_new[j]; } - explicit_volume_source_5m_update_euler(mom_em, gas_gamma, U0, R0, t_curr + dt, dt, f_stage1, f_new); + explicit_volume_source_5m_update_euler( + mom_em, gas_gamma, U0, R0, t_curr + dt, dt, f_stage1, f_new + ); for (int j = 0; j < 5; j++) { f_stage2[j] = (0.75 * f_old[j]) + (0.25 * f_new[j]); } - explicit_volume_source_5m_update_euler(mom_em, gas_gamma, U0, R0, t_curr + (0.5 * dt), dt, f_stage2, f_new); + explicit_volume_source_5m_update_euler( + mom_em, gas_gamma, U0, R0, t_curr + (0.5 * dt), dt, f_stage2, f_new + ); for (int j = 0; j < 5; j++) { f[j] = ((1.0 / 3.0) * f_old[j]) + ((2.0 / 3.0) * f_new[j]); } - } - else if (mom_em->param[i].type == GKYL_EQN_TEN_MOMENT) { + } else if (mom_em->param[i].type == GKYL_EQN_TEN_MOMENT) { double f_new[10], f_stage1[10], f_stage2[10], f_old[10]; for (int j = 0; j < 10; j++) { @@ -305,7 +326,9 @@ explicit_volume_source_update(const gkyl_moment_em_coupling* mom_em, double t_cu f_stage2[j] = (0.75 * f_old[j]) + (0.25 * f_new[j]); } - explicit_volume_source_10m_update_euler(mom_em, U0, R0, t_curr + (0.5 * dt), dt, f_stage2, f_new); + explicit_volume_source_10m_update_euler( + mom_em, U0, R0, t_curr + (0.5 * dt), dt, f_stage2, f_new + ); for (int j = 0; j < 10; j++) { f[j] = ((1.0 / 3.0) * f_old[j]) + ((2.0 / 3.0) * f_new[j]); } @@ -323,21 +346,27 @@ explicit_volume_source_update(const gkyl_moment_em_coupling* mom_em, double t_cu em_stage1[i] = em_new[i]; } - explicit_volume_source_maxwell_update_euler(mom_em, U0, R0, t_curr + dt, dt, em_stage1, em_new, ext_em); + explicit_volume_source_maxwell_update_euler( + mom_em, U0, R0, t_curr + dt, dt, em_stage1, em_new, ext_em + ); for (int i = 0; i < 8; i++) { em_stage2[i] = (0.75 * em_old[i]) + (0.25 * em_new[i]); } - explicit_volume_source_maxwell_update_euler(mom_em, U0, R0, t_curr + (0.5 * dt), dt, em_stage2, em_new, ext_em); + explicit_volume_source_maxwell_update_euler( + mom_em, U0, R0, t_curr + (0.5 * dt), dt, em_stage2, em_new, ext_em + ); for (int i = 0; i < 8; i++) { em[i] = ((1.0 / 3.0) * em_old[i]) + ((2.0 / 3.0) * em_new[i]); } } -void -explicit_reactive_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, const double specific_heat_capacity, - const double energy_of_formation, const double ignition_temperature, const double reaction_rate, double t_curr, const double dt, - double* fluid_old, double* fluid_new) +void explicit_reactive_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, + const double specific_heat_capacity, const double energy_of_formation, + const double ignition_temperature, const double reaction_rate, double t_curr, const double dt, + double *fluid_old, double *fluid_new +) { double rho = fluid_old[0]; double vx = fluid_old[1] / rho; @@ -345,8 +374,9 @@ explicit_reactive_source_update_euler(const gkyl_moment_em_coupling* mom_em, con double vz = fluid_old[3] / rho; double reaction_progress = fluid_old[5] / rho; - double specific_internal_energy = (fluid_old[4] / rho) - (0.5 * ((vx * vx) + (vy * vy) + (vz * vz))) - - (energy_of_formation * (reaction_progress - 1.0)); + double specific_internal_energy = (fluid_old[4] / rho) - + (0.5 * ((vx * vx) + (vy * vy) + (vz * vz))) - + (energy_of_formation * (reaction_progress - 1.0)); double temperature = specific_internal_energy / specific_heat_capacity; for (int i = 0; i < 6; i++) { @@ -358,8 +388,10 @@ explicit_reactive_source_update_euler(const gkyl_moment_em_coupling* mom_em, con } } -void -explicit_reactive_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]) +void explicit_reactive_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; @@ -378,36 +410,43 @@ explicit_reactive_source_update(const gkyl_moment_em_coupling* mom_em, double t_ f_old[j] = f[j]; } - explicit_reactive_source_update_euler(mom_em, gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, reaction_rate, - t_curr, dt, f_old, f_new); + explicit_reactive_source_update_euler( + mom_em, gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, + reaction_rate, t_curr, dt, f_old, f_new + ); for (int j = 0; j < 6; j++) { f_stage1[j] = f_new[j]; } - explicit_reactive_source_update_euler(mom_em, gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, reaction_rate, - t_curr + dt, dt, f_stage1, f_new); + explicit_reactive_source_update_euler( + mom_em, gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, + reaction_rate, t_curr + dt, dt, f_stage1, f_new + ); for (int j = 0; j < 6; j++) { f_stage2[j] = (0.75 * f_old[j]) + (0.25 * f_new[j]); } - explicit_reactive_source_update_euler(mom_em, gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, reaction_rate, - t_curr + (0.5 * dt), dt, f_stage2, f_new); + explicit_reactive_source_update_euler( + mom_em, gas_gamma, specific_heat_capacity, energy_of_formation, ignition_temperature, + reaction_rate, t_curr + (0.5 * dt), dt, f_stage2, f_new + ); for (int j = 0; j < 6; j++) { f[j] = ((1.0 / 3.0) * f_old[j]) + ((2.0 / 3.0) * f_new[j]); } } } -void -explicit_medium_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, const double kappa, double t_curr, - const double dt, double* fluid_old, double* fluid_new) +void explicit_medium_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, const double kappa, double t_curr, + const double dt, double *fluid_old, double *fluid_new +) { double exp_2a = fluid_old[0]; double a_dt = fluid_old[1], a_dx = fluid_old[2]; double b_dt = fluid_old[3], b_dx = fluid_old[4]; double c_dt = fluid_old[5], c_dx = fluid_old[6]; - + double a_dt_dx = fluid_old[7], a_dx_dx = fluid_old[8]; double b_dt_dx = fluid_old[9], b_dx_dx = fluid_old[10]; double c_dt_dx = fluid_old[11], c_dx_dx = fluid_old[12]; @@ -415,12 +454,17 @@ explicit_medium_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double Etot = fluid_old[13]; double mom = fluid_old[14]; - double rho = (1.0 / (gas_gamma - 1.0)) * ((-0.5 * (2.0 - gas_gamma) * Etot) + sqrt((0.25 * (2.0 - gas_gamma) * (2.0 - gas_gamma) * Etot * Etot) + - ((gas_gamma - 1.0) * ((Etot * Etot) - (mom * mom))))); + double rho = + (1.0 / (gas_gamma - 1.0)) * ((-0.5 * (2.0 - gas_gamma) * Etot) + + sqrt( + (0.25 * (2.0 - gas_gamma) * (2.0 - gas_gamma) * Etot * Etot) + + ((gas_gamma - 1.0) * ((Etot * Etot) - (mom * mom))) + )); double vel = 0.0; if (fabs(mom) > pow(10.0, -8.0)) { - vel = ((gas_gamma * rho) / (2.0 * mom)) * (sqrt(1.0 + ((4 * mom * mom) / ((gas_gamma * gas_gamma) * (rho * rho)))) - 1.0); + vel = ((gas_gamma * rho) / (2.0 * mom)) * + (sqrt(1.0 + ((4 * mom * mom) / ((gas_gamma * gas_gamma) * (rho * rho)))) - 1.0); } double p = (gas_gamma - 1.0) * rho; @@ -436,26 +480,34 @@ explicit_medium_source_update_euler(const gkyl_moment_em_coupling* mom_em, const fluid_new[0] += dt * (2.0 * a_dt * exp_2a); - fluid_new[1] += dt * (a_dx_dx + (b_dt * b_dt) - (b_dx * b_dx) - (c_dt * c_dt) + (c_dx * c_dx) - (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p)))); + fluid_new[1] += dt * (a_dx_dx + (b_dt * b_dt) - (b_dx * b_dx) - (c_dt * c_dt) + (c_dx * c_dx) - + (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p)))); fluid_new[2] += dt * (a_dt_dx); - fluid_new[3] += dt * (b_dx_dx - (2.0 * (b_dt * b_dt)) + (2.0 * (b_dx * b_dx)) + (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p)))); + fluid_new[3] += dt * (b_dx_dx - (2.0 * (b_dt * b_dt)) + (2.0 * (b_dx * b_dx)) + + (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p)))); fluid_new[4] += dt * (b_dt_dx); fluid_new[5] += dt * (c_dx_dx - (2.0 * ((b_dt * c_dt) - (b_dx * c_dx)))); fluid_new[6] += dt * (c_dt_dx); - fluid_new[7] += dt * ((2.0 * (b_dt * b_dt_dx)) - (2.0 * (b_dx * b_dx_dx)) - (2.0 * (c_dt * c_dt_dx)) + (2.0 * (c_dx * c_dx_dx))); + fluid_new[7] += dt * ((2.0 * (b_dt * b_dt_dx)) - (2.0 * (b_dx * b_dx_dx)) - + (2.0 * (c_dt * c_dt_dx)) + (2.0 * (c_dx * c_dx_dx))); fluid_new[8] += 0.0; fluid_new[9] += dt * (-(4.0 * (b_dt * b_dt_dx)) + (4.0 * (b_dx * b_dx_dx))); fluid_new[10] += 0.0; - fluid_new[11] += dt * (-2.0 * ((b_dt * c_dt_dx) - (b_dx * c_dx_dx) + (b_dt_dx * c_dt) - (b_dx_dx * c_dx))); + fluid_new[11] += + dt * (-2.0 * ((b_dt * c_dt_dx) - (b_dx * c_dx_dx) + (b_dt_dx * c_dt) - (b_dx_dx * c_dx))); fluid_new[12] += 0.0; - fluid_new[13] += dt * ((-Etot * (a_dt + (2.0 * b_dt))) - (2.0 * mom * (a_dx + b_dx)) - (((mom * vel) + p) * a_dt) - (2.0 * p * b_dt)); - fluid_new[14] += dt * ((-Etot * a_dx) - (2.0 * mom * (a_dt + b_dt)) - (((mom * vel) + p) * (a_dx + (2.0 * b_dx))) + (2.0 * p * b_dx)); + fluid_new[13] += dt * ((-Etot * (a_dt + (2.0 * b_dt))) - (2.0 * mom * (a_dx + b_dx)) - + (((mom * vel) + p) * a_dt) - (2.0 * p * b_dt)); + fluid_new[14] += dt * ((-Etot * a_dx) - (2.0 * mom * (a_dt + b_dt)) - + (((mom * vel) + p) * (a_dx + (2.0 * b_dx))) + (2.0 * p * b_dx)); } -void -explicit_medium_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]) +void explicit_medium_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; @@ -481,16 +533,19 @@ explicit_medium_source_update(const gkyl_moment_em_coupling* mom_em, double t_cu f_stage2[j] = (0.75 * f_old[j]) + (0.25 * f_new[j]); } - explicit_medium_source_update_euler(mom_em, gas_gamma, kappa, t_curr + (0.5 * dt), dt, f_stage2, f_new); + explicit_medium_source_update_euler( + mom_em, gas_gamma, kappa, t_curr + (0.5 * dt), dt, f_stage2, f_new + ); for (int j = 0; j < 15; j++) { f[j] = ((1.0 / 3.0) * f_old[j]) + ((2.0 / 3.0) * f_new[j]); } } } -void -explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, double t_curr, const double dt, - double* fluid_old, double* fluid_new) +void explicit_gr_ultra_rel_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, double t_curr, const double dt, + double *fluid_old, double *fluid_new +) { double lapse = fluid_old[4]; double shift_x = fluid_old[5]; @@ -498,15 +553,24 @@ explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, double shift_z = fluid_old[7]; double spatial_metric[3][3]; - spatial_metric[0][0] = fluid_old[8]; spatial_metric[0][1] = fluid_old[9]; spatial_metric[0][2] = fluid_old[10]; - spatial_metric[1][0] = fluid_old[11]; spatial_metric[1][1] = fluid_old[12]; spatial_metric[1][2] = fluid_old[13]; - spatial_metric[2][0] = fluid_old[14]; spatial_metric[2][1] = fluid_old[15]; spatial_metric[2][2] = fluid_old[16]; + spatial_metric[0][0] = fluid_old[8]; + spatial_metric[0][1] = fluid_old[9]; + spatial_metric[0][2] = fluid_old[10]; + spatial_metric[1][0] = fluid_old[11]; + spatial_metric[1][1] = fluid_old[12]; + spatial_metric[1][2] = fluid_old[13]; + spatial_metric[2][0] = fluid_old[14]; + spatial_metric[2][1] = fluid_old[15]; + spatial_metric[2][2] = fluid_old[16]; double inv_spatial_metric[3][3]; - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -537,8 +601,7 @@ explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -546,15 +609,22 @@ explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spatial_metric[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + inv_spatial_metric[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = fluid_old[17]; extrinsic_curvature[0][1] = fluid_old[18]; extrinsic_curvature[0][2] = fluid_old[19]; - extrinsic_curvature[1][0] = fluid_old[20]; extrinsic_curvature[1][1] = fluid_old[21]; extrinsic_curvature[1][2] = fluid_old[22]; - extrinsic_curvature[2][0] = fluid_old[23]; extrinsic_curvature[2][1] = fluid_old[24]; extrinsic_curvature[2][2] = fluid_old[25]; + extrinsic_curvature[0][0] = fluid_old[17]; + extrinsic_curvature[0][1] = fluid_old[18]; + extrinsic_curvature[0][2] = fluid_old[19]; + extrinsic_curvature[1][0] = fluid_old[20]; + extrinsic_curvature[1][1] = fluid_old[21]; + extrinsic_curvature[1][2] = fluid_old[22]; + extrinsic_curvature[2][0] = fluid_old[23]; + extrinsic_curvature[2][1] = fluid_old[24]; + extrinsic_curvature[2][2] = fluid_old[25]; bool in_excision_region = false; if (fluid_old[26] < pow(10.0, -8.0)) { @@ -569,7 +639,9 @@ explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, double mom[3]; double mom_sq = 0.0; - mom[0] = momx; mom[1] = momy; mom[2] = momz; + mom[0] = momx; + mom[1] = momy; + mom[2] = momz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -578,7 +650,9 @@ explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, } double beta = 0.25 * (2.0 - gas_gamma); - double p = -(2.0 * beta * Etot) + sqrt((4.0 * (beta * beta) * (Etot * Etot)) + ((gas_gamma - 1.0) * ((Etot * Etot) - mom_sq))); + double p = + -(2.0 * beta * Etot) + + sqrt((4.0 * (beta * beta) * (Etot * Etot)) + ((gas_gamma - 1.0) * ((Etot * Etot) - mom_sq))); if (p < pow(10.0, -8.0)) { p = pow(10.0, -8.0); } @@ -605,7 +679,9 @@ explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, } double cov_vel[3]; - cov_vel[0] = cov_vx; cov_vel[1] = cov_vy; cov_vel[2] = cov_vz; + cov_vel[0] = cov_vx; + cov_vel[1] = cov_vy; + cov_vel[2] = cov_vz; double vel[3]; for (int i = 0; i < 3; i++) { @@ -641,24 +717,28 @@ explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, spacetime_vel[3] = (W * vz) - (shift_z * (W / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } double stress_energy[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - stress_energy[i][j] = (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); + stress_energy[i][j] = + (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); } } @@ -668,22 +748,46 @@ explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, lapse_der[2] = fluid_old[29]; double shift_der[3][3]; - shift_der[0][0] = fluid_old[30]; shift_der[0][1] = fluid_old[31]; shift_der[0][2] = fluid_old[32]; - shift_der[1][0] = fluid_old[33]; shift_der[1][1] = fluid_old[34]; shift_der[1][2] = fluid_old[35]; - shift_der[2][0] = fluid_old[36]; shift_der[2][1] = fluid_old[37]; shift_der[2][2] = fluid_old[38]; + shift_der[0][0] = fluid_old[30]; + shift_der[0][1] = fluid_old[31]; + shift_der[0][2] = fluid_old[32]; + shift_der[1][0] = fluid_old[33]; + shift_der[1][1] = fluid_old[34]; + shift_der[1][2] = fluid_old[35]; + shift_der[2][0] = fluid_old[36]; + shift_der[2][1] = fluid_old[37]; + shift_der[2][2] = fluid_old[38]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = fluid_old[39]; spatial_metric_der[0][0][1] = fluid_old[40]; spatial_metric_der[0][0][2] = fluid_old[41]; - spatial_metric_der[0][1][0] = fluid_old[42]; spatial_metric_der[0][1][1] = fluid_old[43]; spatial_metric_der[0][1][2] = fluid_old[44]; - spatial_metric_der[0][2][0] = fluid_old[45]; spatial_metric_der[0][2][1] = fluid_old[46]; spatial_metric_der[0][2][2] = fluid_old[47]; - - spatial_metric_der[1][0][0] = fluid_old[48]; spatial_metric_der[1][0][1] = fluid_old[49]; spatial_metric_der[1][0][2] = fluid_old[50]; - spatial_metric_der[1][1][0] = fluid_old[51]; spatial_metric_der[1][1][1] = fluid_old[52]; spatial_metric_der[1][1][2] = fluid_old[53]; - spatial_metric_der[1][2][0] = fluid_old[54]; spatial_metric_der[1][2][1] = fluid_old[55]; spatial_metric_der[1][2][2] = fluid_old[56]; - - spatial_metric_der[2][0][0] = fluid_old[57]; spatial_metric_der[2][0][1] = fluid_old[58]; spatial_metric_der[2][0][2] = fluid_old[59]; - spatial_metric_der[2][1][0] = fluid_old[60]; spatial_metric_der[2][1][1] = fluid_old[61]; spatial_metric_der[2][1][2] = fluid_old[62]; - spatial_metric_der[2][2][0] = fluid_old[63]; spatial_metric_der[2][2][1] = fluid_old[64]; spatial_metric_der[2][2][2] = fluid_old[65]; + spatial_metric_der[0][0][0] = fluid_old[39]; + spatial_metric_der[0][0][1] = fluid_old[40]; + spatial_metric_der[0][0][2] = fluid_old[41]; + spatial_metric_der[0][1][0] = fluid_old[42]; + spatial_metric_der[0][1][1] = fluid_old[43]; + spatial_metric_der[0][1][2] = fluid_old[44]; + spatial_metric_der[0][2][0] = fluid_old[45]; + spatial_metric_der[0][2][1] = fluid_old[46]; + spatial_metric_der[0][2][2] = fluid_old[47]; + + spatial_metric_der[1][0][0] = fluid_old[48]; + spatial_metric_der[1][0][1] = fluid_old[49]; + spatial_metric_der[1][0][2] = fluid_old[50]; + spatial_metric_der[1][1][0] = fluid_old[51]; + spatial_metric_der[1][1][1] = fluid_old[52]; + spatial_metric_der[1][1][2] = fluid_old[53]; + spatial_metric_der[1][2][0] = fluid_old[54]; + spatial_metric_der[1][2][1] = fluid_old[55]; + spatial_metric_der[1][2][2] = fluid_old[56]; + + spatial_metric_der[2][0][0] = fluid_old[57]; + spatial_metric_der[2][0][1] = fluid_old[58]; + spatial_metric_der[2][0][2] = fluid_old[59]; + spatial_metric_der[2][1][0] = fluid_old[60]; + spatial_metric_der[2][1][1] = fluid_old[61]; + spatial_metric_der[2][1][2] = fluid_old[62]; + spatial_metric_der[2][2][0] = fluid_old[63]; + spatial_metric_der[2][2][1] = fluid_old[64]; + spatial_metric_der[2][2][2] = fluid_old[65]; mom[0] = (rho + p) * (W * W) * vx; mom[1] = (rho + p) * (W * W) * vy; @@ -696,7 +800,8 @@ explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, // Energy density source. for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - fluid_new[0] += dt * (stress_energy[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); + fluid_new[0] += + dt * (stress_energy[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); fluid_new[0] += dt * (2.0 * stress_energy[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); fluid_new[0] += dt * (stress_energy[i + 1][j + 1] * extrinsic_curvature[i][j]); } @@ -711,27 +816,31 @@ explicit_gr_ultra_rel_source_update_euler(const gkyl_moment_em_coupling* mom_em, for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - fluid_new[1 + j] += dt * (0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]); - fluid_new[1 + j] += dt * (0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]); + fluid_new[1 + j] += + dt * (0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]); + fluid_new[1 + j] += + dt * (0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]); } fluid_new[1 + j] += dt * ((mom[k] / lapse) * shift_der[j][k]); for (int i = 0; i < 3; i++) { - fluid_new[1 + j] += dt * (stress_energy[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); + fluid_new[1 + j] += + dt * (stress_energy[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); } } } - } - else { + } else { for (int i = 0; i < 70; i++) { fluid_new[i] = fluid_old[i]; } } } -void -explicit_gr_ultra_rel_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]) +void explicit_gr_ultra_rel_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; @@ -756,16 +865,19 @@ explicit_gr_ultra_rel_source_update(const gkyl_moment_em_coupling* mom_em, doubl f_stage2[j] = (0.75 * f_old[j]) + (0.25 * f_new[j]); } - explicit_gr_ultra_rel_source_update_euler(mom_em, gas_gamma, t_curr + (0.5 * dt), dt, f_stage2, f_new); + explicit_gr_ultra_rel_source_update_euler( + mom_em, gas_gamma, t_curr + (0.5 * dt), dt, f_stage2, f_new + ); for (int j = 0; j < 70; j++) { f[j] = ((1.0 / 3.0) * f_old[j]) + ((2.0 / 3.0) * f_new[j]); } } } -void -explicit_gr_euler_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, double t_curr, const double dt, - double* fluid_old, double* fluid_new) +void explicit_gr_euler_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, double t_curr, const double dt, + double *fluid_old, double *fluid_new +) { double lapse = fluid_old[5]; double shift_x = fluid_old[6]; @@ -773,15 +885,24 @@ explicit_gr_euler_source_update_euler(const gkyl_moment_em_coupling* mom_em, con double shift_z = fluid_old[8]; double spatial_metric[3][3]; - spatial_metric[0][0] = fluid_old[9]; spatial_metric[0][1] = fluid_old[10]; spatial_metric[0][2] = fluid_old[11]; - spatial_metric[1][0] = fluid_old[12]; spatial_metric[1][1] = fluid_old[13]; spatial_metric[1][2] = fluid_old[14]; - spatial_metric[2][0] = fluid_old[15]; spatial_metric[2][1] = fluid_old[16]; spatial_metric[2][2] = fluid_old[17]; + spatial_metric[0][0] = fluid_old[9]; + spatial_metric[0][1] = fluid_old[10]; + spatial_metric[0][2] = fluid_old[11]; + spatial_metric[1][0] = fluid_old[12]; + spatial_metric[1][1] = fluid_old[13]; + spatial_metric[1][2] = fluid_old[14]; + spatial_metric[2][0] = fluid_old[15]; + spatial_metric[2][1] = fluid_old[16]; + spatial_metric[2][2] = fluid_old[17]; double inv_spatial_metric[3][3]; - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -812,8 +933,7 @@ explicit_gr_euler_source_update_euler(const gkyl_moment_em_coupling* mom_em, con for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -821,15 +941,22 @@ explicit_gr_euler_source_update_euler(const gkyl_moment_em_coupling* mom_em, con for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spatial_metric[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + inv_spatial_metric[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = fluid_old[18]; extrinsic_curvature[0][1] = fluid_old[19]; extrinsic_curvature[0][2] = fluid_old[20]; - extrinsic_curvature[1][0] = fluid_old[21]; extrinsic_curvature[1][1] = fluid_old[22]; extrinsic_curvature[1][2] = fluid_old[23]; - extrinsic_curvature[2][0] = fluid_old[24]; extrinsic_curvature[2][1] = fluid_old[25]; extrinsic_curvature[2][2] = fluid_old[26]; + extrinsic_curvature[0][0] = fluid_old[18]; + extrinsic_curvature[0][1] = fluid_old[19]; + extrinsic_curvature[0][2] = fluid_old[20]; + extrinsic_curvature[1][0] = fluid_old[21]; + extrinsic_curvature[1][1] = fluid_old[22]; + extrinsic_curvature[1][2] = fluid_old[23]; + extrinsic_curvature[2][0] = fluid_old[24]; + extrinsic_curvature[2][1] = fluid_old[25]; + extrinsic_curvature[2][2] = fluid_old[26]; bool in_excision_region = false; if (fluid_old[27] < pow(10.0, -8.0)) { @@ -843,38 +970,47 @@ explicit_gr_euler_source_update_euler(const gkyl_moment_em_coupling* mom_em, con double momz = fluid_old[3] / sqrt(spatial_det); double Etot = fluid_old[4] / sqrt(spatial_det); - double C = D / sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); - double C0 = (D + Etot) / sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); - if (((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz)) < pow(10.0, -8.0)) { + double C = + D / sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); + double C0 = (D + Etot) / + sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); + if (((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz)) < + pow(10.0, -8.0)) { C = D / sqrt(pow(10.0, -8.0)); C0 = (D + Etot) / sqrt(pow(10.0, -8.0)); } double alpha0 = -1.0 / (gas_gamma * gas_gamma); double alpha1 = -2.0 * C * ((gas_gamma - 1.0) / (gas_gamma * gas_gamma)); - double alpha2 = ((gas_gamma - 2.0) / gas_gamma) * ((C0 * C0) - 1.0) + 1.0 - (C * C) * ((gas_gamma - 1.0) / gas_gamma) * ((gas_gamma - 1.0) / gas_gamma); + double alpha2 = ((gas_gamma - 2.0) / gas_gamma) * ((C0 * C0) - 1.0) + 1.0 - + (C * C) * ((gas_gamma - 1.0) / gas_gamma) * ((gas_gamma - 1.0) / gas_gamma); double alpha4 = (C0 * C0) - 1.0; - double eta = 2.0 * C *((gas_gamma - 1.0) / gas_gamma); + double eta = 2.0 * C * ((gas_gamma - 1.0) / gas_gamma); double guess = 1.0; int iter = 0; while (iter < 100) { - double poly = (alpha4 * (guess * guess * guess) * (guess - eta)) + (alpha2 * (guess * guess)) + (alpha1 * guess) + alpha0; - double poly_der = alpha1 + (2.0 * alpha2 * guess) + (4.0 * alpha4 * (guess * guess * guess)) - (3.0 * eta * alpha4 * (guess * guess)); + double poly = (alpha4 * (guess * guess * guess) * (guess - eta)) + + (alpha2 * (guess * guess)) + (alpha1 * guess) + alpha0; + double poly_der = alpha1 + (2.0 * alpha2 * guess) + (4.0 * alpha4 * (guess * guess * guess)) - + (3.0 * eta * alpha4 * (guess * guess)); double guess_new = guess - (poly / poly_der); if (fabs(guess - guess_new) < pow(10.0, -8.0)) { iter = 100; - } - else { + } else { iter += 1; guess = guess_new; } } - double W = 0.5 * C0 * guess * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma - 1.0) / gas_gamma) * ((1.0 - (C * guess)) / ((C0 * C0) * (guess * guess)))))); + double W = 0.5 * C0 * guess * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma - 1.0) / gas_gamma) * + ((1.0 - (C * guess)) / ((C0 * C0) * (guess * guess)))) + )); double h = 1.0 / (C * guess); double rho = D / W; @@ -897,24 +1033,28 @@ explicit_gr_euler_source_update_euler(const gkyl_moment_em_coupling* mom_em, con spacetime_vel[3] = (W * vz) - (shift_z * (W / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } double stress_energy[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - stress_energy[i][j] = (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); + stress_energy[i][j] = + (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); } } @@ -924,22 +1064,46 @@ explicit_gr_euler_source_update_euler(const gkyl_moment_em_coupling* mom_em, con lapse_der[2] = fluid_old[30]; double shift_der[3][3]; - shift_der[0][0] = fluid_old[31]; shift_der[0][1] = fluid_old[32]; shift_der[0][2] = fluid_old[33]; - shift_der[1][0] = fluid_old[34]; shift_der[1][1] = fluid_old[35]; shift_der[1][2] = fluid_old[36]; - shift_der[2][0] = fluid_old[37]; shift_der[2][1] = fluid_old[38]; shift_der[2][2] = fluid_old[39]; + shift_der[0][0] = fluid_old[31]; + shift_der[0][1] = fluid_old[32]; + shift_der[0][2] = fluid_old[33]; + shift_der[1][0] = fluid_old[34]; + shift_der[1][1] = fluid_old[35]; + shift_der[1][2] = fluid_old[36]; + shift_der[2][0] = fluid_old[37]; + shift_der[2][1] = fluid_old[38]; + shift_der[2][2] = fluid_old[39]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = fluid_old[40]; spatial_metric_der[0][0][1] = fluid_old[41]; spatial_metric_der[0][0][2] = fluid_old[42]; - spatial_metric_der[0][1][0] = fluid_old[43]; spatial_metric_der[0][1][1] = fluid_old[44]; spatial_metric_der[0][1][2] = fluid_old[45]; - spatial_metric_der[0][2][0] = fluid_old[46]; spatial_metric_der[0][2][1] = fluid_old[47]; spatial_metric_der[0][2][2] = fluid_old[48]; - - spatial_metric_der[1][0][0] = fluid_old[49]; spatial_metric_der[1][0][1] = fluid_old[50]; spatial_metric_der[1][0][2] = fluid_old[51]; - spatial_metric_der[1][1][0] = fluid_old[52]; spatial_metric_der[1][1][1] = fluid_old[53]; spatial_metric_der[1][1][2] = fluid_old[54]; - spatial_metric_der[1][2][0] = fluid_old[55]; spatial_metric_der[1][2][1] = fluid_old[56]; spatial_metric_der[1][2][2] = fluid_old[57]; - - spatial_metric_der[2][0][0] = fluid_old[58]; spatial_metric_der[2][0][1] = fluid_old[59]; spatial_metric_der[2][0][2] = fluid_old[60]; - spatial_metric_der[2][1][0] = fluid_old[61]; spatial_metric_der[2][1][1] = fluid_old[62]; spatial_metric_der[2][1][2] = fluid_old[63]; - spatial_metric_der[2][2][0] = fluid_old[64]; spatial_metric_der[2][2][1] = fluid_old[65]; spatial_metric_der[2][2][2] = fluid_old[66]; + spatial_metric_der[0][0][0] = fluid_old[40]; + spatial_metric_der[0][0][1] = fluid_old[41]; + spatial_metric_der[0][0][2] = fluid_old[42]; + spatial_metric_der[0][1][0] = fluid_old[43]; + spatial_metric_der[0][1][1] = fluid_old[44]; + spatial_metric_der[0][1][2] = fluid_old[45]; + spatial_metric_der[0][2][0] = fluid_old[46]; + spatial_metric_der[0][2][1] = fluid_old[47]; + spatial_metric_der[0][2][2] = fluid_old[48]; + + spatial_metric_der[1][0][0] = fluid_old[49]; + spatial_metric_der[1][0][1] = fluid_old[50]; + spatial_metric_der[1][0][2] = fluid_old[51]; + spatial_metric_der[1][1][0] = fluid_old[52]; + spatial_metric_der[1][1][1] = fluid_old[53]; + spatial_metric_der[1][1][2] = fluid_old[54]; + spatial_metric_der[1][2][0] = fluid_old[55]; + spatial_metric_der[1][2][1] = fluid_old[56]; + spatial_metric_der[1][2][2] = fluid_old[57]; + + spatial_metric_der[2][0][0] = fluid_old[58]; + spatial_metric_der[2][0][1] = fluid_old[59]; + spatial_metric_der[2][0][2] = fluid_old[60]; + spatial_metric_der[2][1][0] = fluid_old[61]; + spatial_metric_der[2][1][1] = fluid_old[62]; + spatial_metric_der[2][1][2] = fluid_old[63]; + spatial_metric_der[2][2][0] = fluid_old[64]; + spatial_metric_der[2][2][1] = fluid_old[65]; + spatial_metric_der[2][2][2] = fluid_old[66]; double mom[3]; mom[0] = (rho + p) * (W * W) * vx; @@ -953,7 +1117,8 @@ explicit_gr_euler_source_update_euler(const gkyl_moment_em_coupling* mom_em, con // Energy density source. for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - fluid_new[4] += dt * (stress_energy[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); + fluid_new[4] += + dt * (stress_energy[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); fluid_new[4] += dt * (2.0 * stress_energy[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); fluid_new[4] += dt * (stress_energy[i + 1][j + 1] * extrinsic_curvature[i][j]); } @@ -968,27 +1133,31 @@ explicit_gr_euler_source_update_euler(const gkyl_moment_em_coupling* mom_em, con for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - fluid_new[1 + j] += dt * (0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]); - fluid_new[1 + j] += dt * (0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]); + fluid_new[1 + j] += + dt * (0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]); + fluid_new[1 + j] += + dt * (0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]); } fluid_new[1 + j] += dt * ((mom[k] / lapse) * shift_der[j][k]); for (int i = 0; i < 3; i++) { - fluid_new[1 + j] += dt * (stress_energy[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); + fluid_new[1 + j] += + dt * (stress_energy[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); } } } - } - else { + } else { for (int i = 0; i < 71; i++) { fluid_new[i] = fluid_old[i]; } } } -void -explicit_gr_euler_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]) +void explicit_gr_euler_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; @@ -1013,16 +1182,19 @@ explicit_gr_euler_source_update(const gkyl_moment_em_coupling* mom_em, double t_ f_stage2[j] = (0.75 * f_old[j]) + (0.25 * f_new[j]); } - explicit_gr_euler_source_update_euler(mom_em, gas_gamma, t_curr + (0.5 * dt), dt, f_stage2, f_new); + explicit_gr_euler_source_update_euler( + mom_em, gas_gamma, t_curr + (0.5 * dt), dt, f_stage2, f_new + ); for (int j = 0; j < 71; j++) { f[j] = ((1.0 / 3.0) * f_old[j]) + ((2.0 / 3.0) * f_new[j]); } } } -void -explicit_gr_twofluid_source_update_elc_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma_elc, const double mass_elc, - const double charge_elc, double t_curr, const double dt, double* fluid_old, double* fluid_new) +void explicit_gr_twofluid_source_update_elc_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma_elc, const double mass_elc, + const double charge_elc, double t_curr, const double dt, double *fluid_old, double *fluid_new +) { for (int i = 0; i < 84; i++) { fluid_new[i] = fluid_old[i]; @@ -1037,9 +1209,15 @@ explicit_gr_twofluid_source_update_elc_euler(const gkyl_moment_em_coupling* mom_ double shift_z = fluid_old[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = fluid_old[22]; spatial_metric[0][1] = fluid_old[23]; spatial_metric[0][2] = fluid_old[24]; - spatial_metric[1][0] = fluid_old[25]; spatial_metric[1][1] = fluid_old[26]; spatial_metric[1][2] = fluid_old[27]; - spatial_metric[2][0] = fluid_old[28]; spatial_metric[2][1] = fluid_old[29]; spatial_metric[2][2] = fluid_old[30]; + spatial_metric[0][0] = fluid_old[22]; + spatial_metric[0][1] = fluid_old[23]; + spatial_metric[0][2] = fluid_old[24]; + spatial_metric[1][0] = fluid_old[25]; + spatial_metric[1][1] = fluid_old[26]; + spatial_metric[1][2] = fluid_old[27]; + spatial_metric[2][0] = fluid_old[28]; + spatial_metric[2][1] = fluid_old[29]; + spatial_metric[2][2] = fluid_old[30]; bool in_excision_region = false; if (fluid_old[40] < pow(10.0, -8.0)) { @@ -1047,9 +1225,12 @@ explicit_gr_twofluid_source_update_elc_euler(const gkyl_moment_em_coupling* mom_ } if (!in_excision_region) { - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double D_elc = fluid_old[0] / sqrt(spatial_det); double momx_elc = fluid_old[1] / sqrt(spatial_det); @@ -1057,46 +1238,60 @@ explicit_gr_twofluid_source_update_elc_euler(const gkyl_moment_em_coupling* mom_ double momz_elc = fluid_old[3] / sqrt(spatial_det); double Etot_elc = fluid_old[4] / sqrt(spatial_det); - double C_elc = D_elc / sqrt(((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc))); - double C0_elc = (D_elc + Etot_elc) / sqrt(((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + - (momz_elc * momz_elc))); - if (((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) < pow(10.0, -8.0)) { + double C_elc = D_elc / sqrt( + ((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) + ); + double C0_elc = + (D_elc + Etot_elc) / sqrt( + ((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) + ); + if (((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) < + pow(10.0, -8.0)) { C_elc = D_elc / sqrt(pow(10.0, -8.0)); C0_elc = (D_elc + Etot_elc) / sqrt(pow(10.0, -8.0)); } double alpha0_elc = -1.0 / (gas_gamma_elc * gas_gamma_elc); double alpha1_elc = -2.0 * C_elc * ((gas_gamma_elc - 1.0) / (gas_gamma_elc * gas_gamma_elc)); - double alpha2_elc = ((gas_gamma_elc - 2.0) / gas_gamma_elc) * ((C0_elc * C0_elc) - 1.0) + 1.0 - (C_elc * C_elc) * - ((gas_gamma_elc - 1.0) / gas_gamma_elc) * ((gas_gamma_elc - 1.0) / gas_gamma_elc); + double alpha2_elc = ((gas_gamma_elc - 2.0) / gas_gamma_elc) * ((C0_elc * C0_elc) - 1.0) + 1.0 - + (C_elc * C_elc) * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * + ((gas_gamma_elc - 1.0) / gas_gamma_elc); double alpha4_elc = (C0_elc * C0_elc) - 1.0; - double eta_elc = 2.0 * C_elc *((gas_gamma_elc - 1.0) / gas_gamma_elc); + double eta_elc = 2.0 * C_elc * ((gas_gamma_elc - 1.0) / gas_gamma_elc); double guess_elc = 1.0; int iter_elc = 0; while (iter_elc < 100) { - double poly_elc = (alpha4_elc * (guess_elc * guess_elc * guess_elc) * (guess_elc - eta_elc)) + (alpha2_elc * (guess_elc * guess_elc)) + - (alpha1_elc * guess_elc) + alpha0_elc; - double poly_der_elc = alpha1_elc + (2.0 * alpha2_elc * guess_elc) + (4.0 * alpha4_elc * (guess_elc * guess_elc * guess_elc)) - - (3.0 * eta_elc * alpha4_elc * (guess_elc * guess_elc)); + double poly_elc = (alpha4_elc * (guess_elc * guess_elc * guess_elc) * (guess_elc - eta_elc)) + + (alpha2_elc * (guess_elc * guess_elc)) + (alpha1_elc * guess_elc) + + alpha0_elc; + double poly_der_elc = alpha1_elc + (2.0 * alpha2_elc * guess_elc) + + (4.0 * alpha4_elc * (guess_elc * guess_elc * guess_elc)) - + (3.0 * eta_elc * alpha4_elc * (guess_elc * guess_elc)); double guess_new_elc = guess_elc - (poly_elc / poly_der_elc); if (fabs(guess_elc - guess_new_elc) < pow(10.0, -8.0)) { iter_elc = 100; - } - else { + } else { iter_elc += 1; guess_elc = guess_new_elc; } } - double W_elc = 0.5 * C0_elc * guess_elc * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * ((1.0 - (C_elc * guess_elc)) / - ((C0_elc * C0_elc) * (guess_elc * guess_elc)))))); + double W_elc = + 0.5 * C0_elc * guess_elc * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * + ((1.0 - (C_elc * guess_elc)) / ((C0_elc * C0_elc) * (guess_elc * guess_elc)))) + )); double h_elc = 1.0 / (C_elc * guess_elc); - double rho_elc = D_elc / W_elc; + double rho_elc = D_elc / W_elc; double vx_elc = momx_elc / (rho_elc * h_elc * (W_elc * W_elc)); double vy_elc = momy_elc / (rho_elc * h_elc * (W_elc * W_elc)); double vz_elc = momz_elc / (rho_elc * h_elc * (W_elc * W_elc)); @@ -1110,8 +1305,12 @@ explicit_gr_twofluid_source_update_elc_euler(const gkyl_moment_em_coupling* mom_ } double D[3], B[3]; - D[0] = Dx; D[1] = Dy; D[2] = Dz; - B[0] = Bx; B[1] = By; B[2] = Bz; + D[0] = Dx; + D[1] = Dy; + D[2] = Dz; + B[0] = Bx; + B[1] = By; + B[2] = Bz; double covD[3], covB[3]; for (int i = 0; i < 3; i++) { @@ -1124,22 +1323,32 @@ explicit_gr_twofluid_source_update_elc_euler(const gkyl_moment_em_coupling* mom_ } } - fluid_new[1] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * covD[0]; - fluid_new[1] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * ((vy_elc * covB[2]) - (vz_elc * covB[1])); - fluid_new[2] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * covD[1]; - fluid_new[2] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * ((vz_elc * covB[0]) - (vx_elc * covB[2])); - fluid_new[3] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * covD[2]; - fluid_new[3] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * ((vx_elc * covB[1]) - (vy_elc * covB[0])); - - fluid_new[4] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * vx_elc * covD[0]; - fluid_new[4] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * vy_elc * covD[1]; - fluid_new[4] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * vz_elc * covD[2]; + fluid_new[1] += + (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * covD[0]; + fluid_new[1] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * + ((vy_elc * covB[2]) - (vz_elc * covB[1])); + fluid_new[2] += + (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * covD[1]; + fluid_new[2] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * + ((vz_elc * covB[0]) - (vx_elc * covB[2])); + fluid_new[3] += + (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * covD[2]; + fluid_new[3] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * + ((vx_elc * covB[1]) - (vy_elc * covB[0])); + + fluid_new[4] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * + vx_elc * covD[0]; + fluid_new[4] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * + vy_elc * covD[1]; + fluid_new[4] += (lapse * sqrt(spatial_det)) * dt * (charge_elc / mass_elc) * rho_elc * W_elc * + vz_elc * covD[2]; } } -void -explicit_gr_twofluid_source_update_ion_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma_ion, const double mass_ion, - const double charge_ion, double t_curr, const double dt, double* fluid_old, double* fluid_new) +void explicit_gr_twofluid_source_update_ion_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma_ion, const double mass_ion, + const double charge_ion, double t_curr, const double dt, double *fluid_old, double *fluid_new +) { for (int i = 0; i < 84; i++) { fluid_new[i] = fluid_old[i]; @@ -1154,9 +1363,15 @@ explicit_gr_twofluid_source_update_ion_euler(const gkyl_moment_em_coupling* mom_ double shift_z = fluid_old[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = fluid_old[22]; spatial_metric[0][1] = fluid_old[23]; spatial_metric[0][2] = fluid_old[24]; - spatial_metric[1][0] = fluid_old[25]; spatial_metric[1][1] = fluid_old[26]; spatial_metric[1][2] = fluid_old[27]; - spatial_metric[2][0] = fluid_old[28]; spatial_metric[2][1] = fluid_old[29]; spatial_metric[2][2] = fluid_old[30]; + spatial_metric[0][0] = fluid_old[22]; + spatial_metric[0][1] = fluid_old[23]; + spatial_metric[0][2] = fluid_old[24]; + spatial_metric[1][0] = fluid_old[25]; + spatial_metric[1][1] = fluid_old[26]; + spatial_metric[1][2] = fluid_old[27]; + spatial_metric[2][0] = fluid_old[28]; + spatial_metric[2][1] = fluid_old[29]; + spatial_metric[2][2] = fluid_old[30]; bool in_excision_region = false; if (fluid_old[40] < pow(10.0, -8.0)) { @@ -1164,9 +1379,12 @@ explicit_gr_twofluid_source_update_ion_euler(const gkyl_moment_em_coupling* mom_ } if (!in_excision_region) { - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double D_ion = fluid_old[5] / sqrt(spatial_det); double momx_ion = fluid_old[6] / sqrt(spatial_det); @@ -1174,46 +1392,60 @@ explicit_gr_twofluid_source_update_ion_euler(const gkyl_moment_em_coupling* mom_ double momz_ion = fluid_old[8] / sqrt(spatial_det); double Etot_ion = fluid_old[9] / sqrt(spatial_det); - double C_ion = D_ion / sqrt(((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion))); - double C0_ion = (D_ion + Etot_ion) / sqrt(((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + - (momz_ion * momz_ion))); - if (((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) < pow(10.0, -8.0)) { + double C_ion = D_ion / sqrt( + ((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) + ); + double C0_ion = + (D_ion + Etot_ion) / sqrt( + ((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) + ); + if (((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) < + pow(10.0, -8.0)) { C_ion = D_ion / sqrt(pow(10.0, -8.0)); C0_ion = (D_ion + Etot_ion) / sqrt(pow(10.0, -8.0)); } double alpha0_ion = -1.0 / (gas_gamma_ion * gas_gamma_ion); double alpha1_ion = -2.0 * C_ion * ((gas_gamma_ion - 1.0) / (gas_gamma_ion * gas_gamma_ion)); - double alpha2_ion = ((gas_gamma_ion - 2.0) / gas_gamma_ion) * ((C0_ion * C0_ion) - 1.0) + 1.0 - (C_ion * C_ion) * - ((gas_gamma_ion - 1.0) / gas_gamma_ion) * ((gas_gamma_ion - 1.0) / gas_gamma_ion); + double alpha2_ion = ((gas_gamma_ion - 2.0) / gas_gamma_ion) * ((C0_ion * C0_ion) - 1.0) + 1.0 - + (C_ion * C_ion) * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * + ((gas_gamma_ion - 1.0) / gas_gamma_ion); double alpha4_ion = (C0_ion * C0_ion) - 1.0; - double eta_ion = 2.0 * C_ion *((gas_gamma_ion - 1.0) / gas_gamma_ion); + double eta_ion = 2.0 * C_ion * ((gas_gamma_ion - 1.0) / gas_gamma_ion); double guess_ion = 1.0; int iter_ion = 0; while (iter_ion < 100) { - double poly_ion = (alpha4_ion * (guess_ion * guess_ion * guess_ion) * (guess_ion - eta_ion)) + (alpha2_ion * (guess_ion * guess_ion)) + - (alpha1_ion * guess_ion) + alpha0_ion; - double poly_der_ion = alpha1_ion + (2.0 * alpha2_ion * guess_ion) + (4.0 * alpha4_ion * (guess_ion * guess_ion * guess_ion)) - - (3.0 * eta_ion * alpha4_ion * (guess_ion * guess_ion)); + double poly_ion = (alpha4_ion * (guess_ion * guess_ion * guess_ion) * (guess_ion - eta_ion)) + + (alpha2_ion * (guess_ion * guess_ion)) + (alpha1_ion * guess_ion) + + alpha0_ion; + double poly_der_ion = alpha1_ion + (2.0 * alpha2_ion * guess_ion) + + (4.0 * alpha4_ion * (guess_ion * guess_ion * guess_ion)) - + (3.0 * eta_ion * alpha4_ion * (guess_ion * guess_ion)); double guess_new_ion = guess_ion - (poly_ion / poly_der_ion); if (fabs(guess_ion - guess_new_ion) < pow(10.0, -8.0)) { iter_ion = 100; - } - else { + } else { iter_ion += 1; guess_ion = guess_new_ion; } } - double W_ion = 0.5 * C0_ion * guess_ion * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * ((1.0 - (C_ion * guess_ion)) / - ((C0_ion * C0_ion) * (guess_ion * guess_ion)))))); + double W_ion = + 0.5 * C0_ion * guess_ion * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * + ((1.0 - (C_ion * guess_ion)) / ((C0_ion * C0_ion) * (guess_ion * guess_ion)))) + )); double h_ion = 1.0 / (C_ion * guess_ion); - double rho_ion = D_ion / W_ion; + double rho_ion = D_ion / W_ion; double vx_ion = momx_ion / (rho_ion * h_ion * (W_ion * W_ion)); double vy_ion = momy_ion / (rho_ion * h_ion * (W_ion * W_ion)); double vz_ion = momz_ion / (rho_ion * h_ion * (W_ion * W_ion)); @@ -1225,10 +1457,14 @@ explicit_gr_twofluid_source_update_ion_euler(const gkyl_moment_em_coupling* mom_ if (p_ion < pow(10.0, -8.0)) { p_ion = pow(10.0, -8.0); } - + double D[3], B[3]; - D[0] = Dx; D[1] = Dy; D[2] = Dz; - B[0] = Bx; B[1] = By; B[2] = Bz; + D[0] = Dx; + D[1] = Dy; + D[2] = Dz; + B[0] = Bx; + B[1] = By; + B[2] = Bz; double covD[3], covB[3]; for (int i = 0; i < 3; i++) { @@ -1241,22 +1477,33 @@ explicit_gr_twofluid_source_update_ion_euler(const gkyl_moment_em_coupling* mom_ } } - fluid_new[6] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * covD[0]; - fluid_new[6] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * ((vy_ion * covB[2]) - (vz_ion * covB[1])); - fluid_new[7] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * covD[1]; - fluid_new[7] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * ((vz_ion * covB[0]) - (vx_ion * covB[2])); - fluid_new[8] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * covD[2]; - fluid_new[8] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * ((vx_ion * covB[1]) - (vy_ion * covB[0])); - - fluid_new[9] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * vx_ion * covD[0]; - fluid_new[9] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * vy_ion * covD[1]; - fluid_new[9] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * vz_ion * covD[2]; + fluid_new[6] += + (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * covD[0]; + fluid_new[6] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * + ((vy_ion * covB[2]) - (vz_ion * covB[1])); + fluid_new[7] += + (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * covD[1]; + fluid_new[7] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * + ((vz_ion * covB[0]) - (vx_ion * covB[2])); + fluid_new[8] += + (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * covD[2]; + fluid_new[8] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * + ((vx_ion * covB[1]) - (vy_ion * covB[0])); + + fluid_new[9] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * + vx_ion * covD[0]; + fluid_new[9] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * + vy_ion * covD[1]; + fluid_new[9] += (lapse * sqrt(spatial_det)) * dt * (charge_ion / mass_ion) * rho_ion * W_ion * + vz_ion * covD[2]; } } -void -explicit_gr_twofluid_source_update_em_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma_elc, const double gas_gamma_ion, const double mass_elc, - const double charge_elc, const double mass_ion, const double charge_ion, double e_fact, double t_curr, const double dt, double* fluid_old, double* fluid_new) +void explicit_gr_twofluid_source_update_em_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma_elc, const double gas_gamma_ion, + const double mass_elc, const double charge_elc, const double mass_ion, const double charge_ion, + double e_fact, double t_curr, const double dt, double *fluid_old, double *fluid_new +) { for (int i = 0; i < 84; i++) { fluid_new[i] = fluid_old[i]; @@ -1265,9 +1512,15 @@ explicit_gr_twofluid_source_update_em_euler(const gkyl_moment_em_coupling* mom_e double Dx = fluid_old[10], Dy = fluid_old[11], Dz = fluid_old[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = fluid_old[22]; spatial_metric[0][1] = fluid_old[23]; spatial_metric[0][2] = fluid_old[24]; - spatial_metric[1][0] = fluid_old[25]; spatial_metric[1][1] = fluid_old[26]; spatial_metric[1][2] = fluid_old[27]; - spatial_metric[2][0] = fluid_old[28]; spatial_metric[2][1] = fluid_old[29]; spatial_metric[2][2] = fluid_old[30]; + spatial_metric[0][0] = fluid_old[22]; + spatial_metric[0][1] = fluid_old[23]; + spatial_metric[0][2] = fluid_old[24]; + spatial_metric[1][0] = fluid_old[25]; + spatial_metric[1][1] = fluid_old[26]; + spatial_metric[1][2] = fluid_old[27]; + spatial_metric[2][0] = fluid_old[28]; + spatial_metric[2][1] = fluid_old[29]; + spatial_metric[2][2] = fluid_old[30]; bool in_excision_region = false; if (fluid_old[40] < pow(10.0, -8.0)) { @@ -1275,9 +1528,12 @@ explicit_gr_twofluid_source_update_em_euler(const gkyl_moment_em_coupling* mom_e } if (!in_excision_region) { - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double D_elc = fluid_old[0] / sqrt(spatial_det); double momx_elc = fluid_old[1] / sqrt(spatial_det); @@ -1285,46 +1541,60 @@ explicit_gr_twofluid_source_update_em_euler(const gkyl_moment_em_coupling* mom_e double momz_elc = fluid_old[3] / sqrt(spatial_det); double Etot_elc = fluid_old[4] / sqrt(spatial_det); - double C_elc = D_elc / sqrt(((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc))); - double C0_elc = (D_elc + Etot_elc) / sqrt(((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + - (momz_elc * momz_elc))); - if (((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) < pow(10.0, -8.0)) { + double C_elc = D_elc / sqrt( + ((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) + ); + double C0_elc = + (D_elc + Etot_elc) / sqrt( + ((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) + ); + if (((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) < + pow(10.0, -8.0)) { C_elc = D_elc / sqrt(pow(10.0, -8.0)); C0_elc = (D_elc + Etot_elc) / sqrt(pow(10.0, -8.0)); } double alpha0_elc = -1.0 / (gas_gamma_elc * gas_gamma_elc); double alpha1_elc = -2.0 * C_elc * ((gas_gamma_elc - 1.0) / (gas_gamma_elc * gas_gamma_elc)); - double alpha2_elc = ((gas_gamma_elc - 2.0) / gas_gamma_elc) * ((C0_elc * C0_elc) - 1.0) + 1.0 - (C_elc * C_elc) * - ((gas_gamma_elc - 1.0) / gas_gamma_elc) * ((gas_gamma_elc - 1.0) / gas_gamma_elc); + double alpha2_elc = ((gas_gamma_elc - 2.0) / gas_gamma_elc) * ((C0_elc * C0_elc) - 1.0) + 1.0 - + (C_elc * C_elc) * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * + ((gas_gamma_elc - 1.0) / gas_gamma_elc); double alpha4_elc = (C0_elc * C0_elc) - 1.0; - double eta_elc = 2.0 * C_elc *((gas_gamma_elc - 1.0) / gas_gamma_elc); + double eta_elc = 2.0 * C_elc * ((gas_gamma_elc - 1.0) / gas_gamma_elc); double guess_elc = 1.0; int iter_elc = 0; while (iter_elc < 100) { - double poly_elc = (alpha4_elc * (guess_elc * guess_elc * guess_elc) * (guess_elc - eta_elc)) + (alpha2_elc * (guess_elc * guess_elc)) + - (alpha1_elc * guess_elc) + alpha0_elc; - double poly_der_elc = alpha1_elc + (2.0 * alpha2_elc * guess_elc) + (4.0 * alpha4_elc * (guess_elc * guess_elc * guess_elc)) - - (3.0 * eta_elc * alpha4_elc * (guess_elc * guess_elc)); + double poly_elc = (alpha4_elc * (guess_elc * guess_elc * guess_elc) * (guess_elc - eta_elc)) + + (alpha2_elc * (guess_elc * guess_elc)) + (alpha1_elc * guess_elc) + + alpha0_elc; + double poly_der_elc = alpha1_elc + (2.0 * alpha2_elc * guess_elc) + + (4.0 * alpha4_elc * (guess_elc * guess_elc * guess_elc)) - + (3.0 * eta_elc * alpha4_elc * (guess_elc * guess_elc)); double guess_new_elc = guess_elc - (poly_elc / poly_der_elc); if (fabs(guess_elc - guess_new_elc) < pow(10.0, -8.0)) { iter_elc = 100; - } - else { + } else { iter_elc += 1; guess_elc = guess_new_elc; } } - double W_elc = 0.5 * C0_elc * guess_elc * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * ((1.0 - (C_elc * guess_elc)) / - ((C0_elc * C0_elc) * (guess_elc * guess_elc)))))); + double W_elc = + 0.5 * C0_elc * guess_elc * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * + ((1.0 - (C_elc * guess_elc)) / ((C0_elc * C0_elc) * (guess_elc * guess_elc)))) + )); double h_elc = 1.0 / (C_elc * guess_elc); - double rho_elc = D_elc / W_elc; + double rho_elc = D_elc / W_elc; double vx_elc = momx_elc / (rho_elc * h_elc * (W_elc * W_elc)); double vy_elc = momy_elc / (rho_elc * h_elc * (W_elc * W_elc)); double vz_elc = momz_elc / (rho_elc * h_elc * (W_elc * W_elc)); @@ -1343,46 +1613,60 @@ explicit_gr_twofluid_source_update_em_euler(const gkyl_moment_em_coupling* mom_e double momz_ion = fluid_old[8] / sqrt(spatial_det); double Etot_ion = fluid_old[9] / sqrt(spatial_det); - double C_ion = D_ion / sqrt(((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion))); - double C0_ion = (D_ion + Etot_ion) / sqrt(((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + - (momz_ion * momz_ion))); - if (((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) < pow(10.0, -8.0)) { + double C_ion = D_ion / sqrt( + ((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) + ); + double C0_ion = + (D_ion + Etot_ion) / sqrt( + ((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) + ); + if (((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) < + pow(10.0, -8.0)) { C_ion = D_ion / sqrt(pow(10.0, -8.0)); C0_ion = (D_ion + Etot_ion) / sqrt(pow(10.0, -8.0)); } double alpha0_ion = -1.0 / (gas_gamma_ion * gas_gamma_ion); double alpha1_ion = -2.0 * C_ion * ((gas_gamma_ion - 1.0) / (gas_gamma_ion * gas_gamma_ion)); - double alpha2_ion = ((gas_gamma_ion - 2.0) / gas_gamma_ion) * ((C0_ion * C0_ion) - 1.0) + 1.0 - (C_ion * C_ion) * - ((gas_gamma_ion - 1.0) / gas_gamma_ion) * ((gas_gamma_ion - 1.0) / gas_gamma_ion); + double alpha2_ion = ((gas_gamma_ion - 2.0) / gas_gamma_ion) * ((C0_ion * C0_ion) - 1.0) + 1.0 - + (C_ion * C_ion) * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * + ((gas_gamma_ion - 1.0) / gas_gamma_ion); double alpha4_ion = (C0_ion * C0_ion) - 1.0; - double eta_ion = 2.0 * C_ion *((gas_gamma_ion - 1.0) / gas_gamma_ion); + double eta_ion = 2.0 * C_ion * ((gas_gamma_ion - 1.0) / gas_gamma_ion); double guess_ion = 1.0; int iter_ion = 0; while (iter_ion < 100) { - double poly_ion = (alpha4_ion * (guess_ion * guess_ion * guess_ion) * (guess_ion - eta_ion)) + (alpha2_ion * (guess_ion * guess_ion)) + - (alpha1_ion * guess_ion) + alpha0_ion; - double poly_der_ion = alpha1_ion + (2.0 * alpha2_ion * guess_ion) + (4.0 * alpha4_ion * (guess_ion * guess_ion * guess_ion)) - - (3.0 * eta_ion * alpha4_ion * (guess_ion * guess_ion)); + double poly_ion = (alpha4_ion * (guess_ion * guess_ion * guess_ion) * (guess_ion - eta_ion)) + + (alpha2_ion * (guess_ion * guess_ion)) + (alpha1_ion * guess_ion) + + alpha0_ion; + double poly_der_ion = alpha1_ion + (2.0 * alpha2_ion * guess_ion) + + (4.0 * alpha4_ion * (guess_ion * guess_ion * guess_ion)) - + (3.0 * eta_ion * alpha4_ion * (guess_ion * guess_ion)); double guess_new_ion = guess_ion - (poly_ion / poly_der_ion); if (fabs(guess_ion - guess_new_ion) < pow(10.0, -8.0)) { iter_ion = 100; - } - else { + } else { iter_ion += 1; guess_ion = guess_new_ion; } } - double W_ion = 0.5 * C0_ion * guess_ion * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * ((1.0 - (C_ion * guess_ion)) / - ((C0_ion * C0_ion) * (guess_ion * guess_ion)))))); + double W_ion = + 0.5 * C0_ion * guess_ion * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * + ((1.0 - (C_ion * guess_ion)) / ((C0_ion * C0_ion) * (guess_ion * guess_ion)))) + )); double h_ion = 1.0 / (C_ion * guess_ion); - double rho_ion = D_ion / W_ion; + double rho_ion = D_ion / W_ion; double vx_ion = momx_ion / (rho_ion * h_ion * (W_ion * W_ion)); double vy_ion = momy_ion / (rho_ion * h_ion * (W_ion * W_ion)); double vz_ion = momz_ion / (rho_ion * h_ion * (W_ion * W_ion)); @@ -1407,9 +1691,10 @@ explicit_gr_twofluid_source_update_em_euler(const gkyl_moment_em_coupling* mom_e } } -void -explicit_gr_twofluid_source_update_elc_spacetime_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma_elc, double t_curr, const double dt, - double* fluid_old, double* fluid_new) +void explicit_gr_twofluid_source_update_elc_spacetime_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma_elc, double t_curr, const double dt, + double *fluid_old, double *fluid_new +) { double lapse = fluid_old[18]; double shift_x = fluid_old[19]; @@ -1417,15 +1702,24 @@ explicit_gr_twofluid_source_update_elc_spacetime_euler(const gkyl_moment_em_coup double shift_z = fluid_old[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = fluid_old[22]; spatial_metric[0][1] = fluid_old[23]; spatial_metric[0][2] = fluid_old[24]; - spatial_metric[1][0] = fluid_old[25]; spatial_metric[1][1] = fluid_old[26]; spatial_metric[1][2] = fluid_old[27]; - spatial_metric[2][0] = fluid_old[28]; spatial_metric[2][1] = fluid_old[29]; spatial_metric[2][2] = fluid_old[30]; + spatial_metric[0][0] = fluid_old[22]; + spatial_metric[0][1] = fluid_old[23]; + spatial_metric[0][2] = fluid_old[24]; + spatial_metric[1][0] = fluid_old[25]; + spatial_metric[1][1] = fluid_old[26]; + spatial_metric[1][2] = fluid_old[27]; + spatial_metric[2][0] = fluid_old[28]; + spatial_metric[2][1] = fluid_old[29]; + spatial_metric[2][2] = fluid_old[30]; double inv_spatial_metric[3][3]; - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -1456,8 +1750,7 @@ explicit_gr_twofluid_source_update_elc_spacetime_euler(const gkyl_moment_em_coup for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -1465,15 +1758,22 @@ explicit_gr_twofluid_source_update_elc_spacetime_euler(const gkyl_moment_em_coup for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spatial_metric[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + inv_spatial_metric[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = fluid_old[31]; extrinsic_curvature[0][1] = fluid_old[32]; extrinsic_curvature[0][2] = fluid_old[33]; - extrinsic_curvature[1][0] = fluid_old[34]; extrinsic_curvature[1][1] = fluid_old[35]; extrinsic_curvature[1][2] = fluid_old[36]; - extrinsic_curvature[2][0] = fluid_old[37]; extrinsic_curvature[2][1] = fluid_old[38]; extrinsic_curvature[2][2] = fluid_old[39]; + extrinsic_curvature[0][0] = fluid_old[31]; + extrinsic_curvature[0][1] = fluid_old[32]; + extrinsic_curvature[0][2] = fluid_old[33]; + extrinsic_curvature[1][0] = fluid_old[34]; + extrinsic_curvature[1][1] = fluid_old[35]; + extrinsic_curvature[1][2] = fluid_old[36]; + extrinsic_curvature[2][0] = fluid_old[37]; + extrinsic_curvature[2][1] = fluid_old[38]; + extrinsic_curvature[2][2] = fluid_old[39]; bool in_excision_region = false; if (fluid_old[40] < pow(10.0, -8.0)) { @@ -1487,42 +1787,57 @@ explicit_gr_twofluid_source_update_elc_spacetime_euler(const gkyl_moment_em_coup double momz_elc = fluid_old[3] / sqrt(spatial_det); double Etot_elc = fluid_old[4] / sqrt(spatial_det); - double C_elc = D_elc / sqrt(((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc))); - double C0_elc = (D_elc + Etot_elc) / sqrt(((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc))); - if (((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) < pow(10.0, -8.0)) { + double C_elc = D_elc / sqrt( + ((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) + ); + double C0_elc = + (D_elc + Etot_elc) / sqrt( + ((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) + ); + if (((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) < + pow(10.0, -8.0)) { C_elc = D_elc / sqrt(pow(10.0, -8.0)); C0_elc = (D_elc + Etot_elc) / sqrt(pow(10.0, -8.0)); } double alpha0_elc = -1.0 / (gas_gamma_elc * gas_gamma_elc); double alpha1_elc = -2.0 * C_elc * ((gas_gamma_elc - 1.0) / (gas_gamma_elc * gas_gamma_elc)); - double alpha2_elc = ((gas_gamma_elc - 2.0) / gas_gamma_elc) * ((C0_elc * C0_elc) - 1.0) + 1.0 - (C_elc * C_elc) * - ((gas_gamma_elc - 1.0) / gas_gamma_elc) * ((gas_gamma_elc - 1.0) / gas_gamma_elc); + double alpha2_elc = ((gas_gamma_elc - 2.0) / gas_gamma_elc) * ((C0_elc * C0_elc) - 1.0) + 1.0 - + (C_elc * C_elc) * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * + ((gas_gamma_elc - 1.0) / gas_gamma_elc); double alpha4_elc = (C0_elc * C0_elc) - 1.0; - double eta_elc = 2.0 * C_elc *((gas_gamma_elc - 1.0) / gas_gamma_elc); + double eta_elc = 2.0 * C_elc * ((gas_gamma_elc - 1.0) / gas_gamma_elc); double guess_elc = 1.0; int iter_elc = 0; while (iter_elc < 100) { - double poly_elc = (alpha4_elc * (guess_elc * guess_elc * guess_elc) * (guess_elc - eta_elc)) + (alpha2_elc * (guess_elc * guess_elc)) + - (alpha1_elc * guess_elc) + alpha0_elc; - double poly_der_elc = alpha1_elc + (2.0 * alpha2_elc * guess_elc) + (4.0 * alpha4_elc * (guess_elc * guess_elc * guess_elc)) - - (3.0 * eta_elc * alpha4_elc * (guess_elc * guess_elc)); + double poly_elc = (alpha4_elc * (guess_elc * guess_elc * guess_elc) * (guess_elc - eta_elc)) + + (alpha2_elc * (guess_elc * guess_elc)) + (alpha1_elc * guess_elc) + + alpha0_elc; + double poly_der_elc = alpha1_elc + (2.0 * alpha2_elc * guess_elc) + + (4.0 * alpha4_elc * (guess_elc * guess_elc * guess_elc)) - + (3.0 * eta_elc * alpha4_elc * (guess_elc * guess_elc)); double guess_new_elc = guess_elc - (poly_elc / poly_der_elc); if (fabs(guess_elc - guess_new_elc) < pow(10.0, -8.0)) { iter_elc = 100; - } - else { + } else { iter_elc += 1; guess_elc = guess_new_elc; } } - double W_elc = 0.5 * C0_elc * guess_elc * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * ((1.0 - (C_elc * guess_elc)) / - ((C0_elc * C0_elc) * (guess_elc * guess_elc)))))); + double W_elc = + 0.5 * C0_elc * guess_elc * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * + ((1.0 - (C_elc * guess_elc)) / ((C0_elc * C0_elc) * (guess_elc * guess_elc)))) + )); double h_elc = 1.0 / (C_elc * guess_elc); double rho_elc = D_elc / W_elc; @@ -1545,24 +1860,28 @@ explicit_gr_twofluid_source_update_elc_spacetime_euler(const gkyl_moment_em_coup spacetime_vel_elc[3] = (W_elc * vz_elc) - (shift_z * (W_elc / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } double stress_energy_elc[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - stress_energy_elc[i][j] = (rho_elc * h_elc * spacetime_vel_elc[i] * spacetime_vel_elc[j]) + (p_elc * inv_spacetime_metric[i][j]); + stress_energy_elc[i][j] = (rho_elc * h_elc * spacetime_vel_elc[i] * spacetime_vel_elc[j]) + + (p_elc * inv_spacetime_metric[i][j]); } } @@ -1572,22 +1891,46 @@ explicit_gr_twofluid_source_update_elc_spacetime_euler(const gkyl_moment_em_coup lapse_der[2] = fluid_old[43]; double shift_der[3][3]; - shift_der[0][0] = fluid_old[44]; shift_der[0][1] = fluid_old[45]; shift_der[0][2] = fluid_old[46]; - shift_der[1][0] = fluid_old[47]; shift_der[1][1] = fluid_old[48]; shift_der[1][2] = fluid_old[49]; - shift_der[2][0] = fluid_old[50]; shift_der[2][1] = fluid_old[51]; shift_der[2][2] = fluid_old[52]; + shift_der[0][0] = fluid_old[44]; + shift_der[0][1] = fluid_old[45]; + shift_der[0][2] = fluid_old[46]; + shift_der[1][0] = fluid_old[47]; + shift_der[1][1] = fluid_old[48]; + shift_der[1][2] = fluid_old[49]; + shift_der[2][0] = fluid_old[50]; + shift_der[2][1] = fluid_old[51]; + shift_der[2][2] = fluid_old[52]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = fluid_old[53]; spatial_metric_der[0][0][1] = fluid_old[54]; spatial_metric_der[0][0][2] = fluid_old[55]; - spatial_metric_der[0][1][0] = fluid_old[56]; spatial_metric_der[0][1][1] = fluid_old[57]; spatial_metric_der[0][1][2] = fluid_old[58]; - spatial_metric_der[0][2][0] = fluid_old[59]; spatial_metric_der[0][2][1] = fluid_old[60]; spatial_metric_der[0][2][2] = fluid_old[61]; - - spatial_metric_der[1][0][0] = fluid_old[62]; spatial_metric_der[1][0][1] = fluid_old[63]; spatial_metric_der[1][0][2] = fluid_old[64]; - spatial_metric_der[1][1][0] = fluid_old[65]; spatial_metric_der[1][1][1] = fluid_old[66]; spatial_metric_der[1][1][2] = fluid_old[67]; - spatial_metric_der[1][2][0] = fluid_old[68]; spatial_metric_der[1][2][1] = fluid_old[69]; spatial_metric_der[1][2][2] = fluid_old[70]; - - spatial_metric_der[2][0][0] = fluid_old[71]; spatial_metric_der[2][0][1] = fluid_old[72]; spatial_metric_der[2][0][2] = fluid_old[73]; - spatial_metric_der[2][1][0] = fluid_old[74]; spatial_metric_der[2][1][1] = fluid_old[75]; spatial_metric_der[2][1][2] = fluid_old[76]; - spatial_metric_der[2][2][0] = fluid_old[77]; spatial_metric_der[2][2][1] = fluid_old[78]; spatial_metric_der[2][2][2] = fluid_old[79]; + spatial_metric_der[0][0][0] = fluid_old[53]; + spatial_metric_der[0][0][1] = fluid_old[54]; + spatial_metric_der[0][0][2] = fluid_old[55]; + spatial_metric_der[0][1][0] = fluid_old[56]; + spatial_metric_der[0][1][1] = fluid_old[57]; + spatial_metric_der[0][1][2] = fluid_old[58]; + spatial_metric_der[0][2][0] = fluid_old[59]; + spatial_metric_der[0][2][1] = fluid_old[60]; + spatial_metric_der[0][2][2] = fluid_old[61]; + + spatial_metric_der[1][0][0] = fluid_old[62]; + spatial_metric_der[1][0][1] = fluid_old[63]; + spatial_metric_der[1][0][2] = fluid_old[64]; + spatial_metric_der[1][1][0] = fluid_old[65]; + spatial_metric_der[1][1][1] = fluid_old[66]; + spatial_metric_der[1][1][2] = fluid_old[67]; + spatial_metric_der[1][2][0] = fluid_old[68]; + spatial_metric_der[1][2][1] = fluid_old[69]; + spatial_metric_der[1][2][2] = fluid_old[70]; + + spatial_metric_der[2][0][0] = fluid_old[71]; + spatial_metric_der[2][0][1] = fluid_old[72]; + spatial_metric_der[2][0][2] = fluid_old[73]; + spatial_metric_der[2][1][0] = fluid_old[74]; + spatial_metric_der[2][1][1] = fluid_old[75]; + spatial_metric_der[2][1][2] = fluid_old[76]; + spatial_metric_der[2][2][0] = fluid_old[77]; + spatial_metric_der[2][2][1] = fluid_old[78]; + spatial_metric_der[2][2][2] = fluid_old[79]; double mom_elc[3]; mom_elc[0] = (rho_elc + p_elc) * (W_elc * W_elc) * vx_elc; @@ -1601,8 +1944,10 @@ explicit_gr_twofluid_source_update_elc_spacetime_euler(const gkyl_moment_em_coup // Energy density source. for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - fluid_new[4] += dt * (stress_energy_elc[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); - fluid_new[4] += dt * (2.0 * stress_energy_elc[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); + fluid_new[4] += + dt * (stress_energy_elc[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); + fluid_new[4] += + dt * (2.0 * stress_energy_elc[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); fluid_new[4] += dt * (stress_energy_elc[i + 1][j + 1] * extrinsic_curvature[i][j]); } @@ -1616,28 +1961,31 @@ explicit_gr_twofluid_source_update_elc_spacetime_euler(const gkyl_moment_em_coup for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - fluid_new[1 + j] += dt * (0.5 * stress_energy_elc[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]); - fluid_new[1 + j] += dt * (0.5 * stress_energy_elc[k + 1][l + 1] * spatial_metric_der[j][k][l]); + fluid_new[1 + j] += dt * (0.5 * stress_energy_elc[0][0] * shift[k] * shift[l] * + spatial_metric_der[j][k][l]); + fluid_new[1 + j] += + dt * (0.5 * stress_energy_elc[k + 1][l + 1] * spatial_metric_der[j][k][l]); } fluid_new[1 + j] += dt * ((mom_elc[k] / lapse) * shift_der[j][k]); for (int i = 0; i < 3; i++) { - fluid_new[1 + j] += dt * (stress_energy_elc[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); + fluid_new[1 + j] += + dt * (stress_energy_elc[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); } } } - } - else { + } else { for (int i = 0; i < 84; i++) { fluid_new[i] = fluid_old[i]; } } } -void -explicit_gr_twofluid_source_update_ion_spacetime_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma_ion, double t_curr, const double dt, - double* fluid_old, double* fluid_new) +void explicit_gr_twofluid_source_update_ion_spacetime_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma_ion, double t_curr, const double dt, + double *fluid_old, double *fluid_new +) { double lapse = fluid_old[18]; double shift_x = fluid_old[19]; @@ -1645,15 +1993,24 @@ explicit_gr_twofluid_source_update_ion_spacetime_euler(const gkyl_moment_em_coup double shift_z = fluid_old[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = fluid_old[22]; spatial_metric[0][1] = fluid_old[23]; spatial_metric[0][2] = fluid_old[24]; - spatial_metric[1][0] = fluid_old[25]; spatial_metric[1][1] = fluid_old[26]; spatial_metric[1][2] = fluid_old[27]; - spatial_metric[2][0] = fluid_old[28]; spatial_metric[2][1] = fluid_old[29]; spatial_metric[2][2] = fluid_old[30]; + spatial_metric[0][0] = fluid_old[22]; + spatial_metric[0][1] = fluid_old[23]; + spatial_metric[0][2] = fluid_old[24]; + spatial_metric[1][0] = fluid_old[25]; + spatial_metric[1][1] = fluid_old[26]; + spatial_metric[1][2] = fluid_old[27]; + spatial_metric[2][0] = fluid_old[28]; + spatial_metric[2][1] = fluid_old[29]; + spatial_metric[2][2] = fluid_old[30]; double inv_spatial_metric[3][3]; - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -1684,8 +2041,7 @@ explicit_gr_twofluid_source_update_ion_spacetime_euler(const gkyl_moment_em_coup for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -1693,15 +2049,22 @@ explicit_gr_twofluid_source_update_ion_spacetime_euler(const gkyl_moment_em_coup for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spatial_metric[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + inv_spatial_metric[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = fluid_old[31]; extrinsic_curvature[0][1] = fluid_old[32]; extrinsic_curvature[0][2] = fluid_old[33]; - extrinsic_curvature[1][0] = fluid_old[34]; extrinsic_curvature[1][1] = fluid_old[35]; extrinsic_curvature[1][2] = fluid_old[36]; - extrinsic_curvature[2][0] = fluid_old[37]; extrinsic_curvature[2][1] = fluid_old[38]; extrinsic_curvature[2][2] = fluid_old[39]; + extrinsic_curvature[0][0] = fluid_old[31]; + extrinsic_curvature[0][1] = fluid_old[32]; + extrinsic_curvature[0][2] = fluid_old[33]; + extrinsic_curvature[1][0] = fluid_old[34]; + extrinsic_curvature[1][1] = fluid_old[35]; + extrinsic_curvature[1][2] = fluid_old[36]; + extrinsic_curvature[2][0] = fluid_old[37]; + extrinsic_curvature[2][1] = fluid_old[38]; + extrinsic_curvature[2][2] = fluid_old[39]; bool in_excision_region = false; if (fluid_old[40] < pow(10.0, -8.0)) { @@ -1715,42 +2078,57 @@ explicit_gr_twofluid_source_update_ion_spacetime_euler(const gkyl_moment_em_coup double momz_ion = fluid_old[8] / sqrt(spatial_det); double Etot_ion = fluid_old[9] / sqrt(spatial_det); - double C_ion = D_ion / sqrt(((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion))); - double C0_ion = (D_ion + Etot_ion) / sqrt(((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion))); - if (((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) < pow(10.0, -8.0)) { + double C_ion = D_ion / sqrt( + ((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) + ); + double C0_ion = + (D_ion + Etot_ion) / sqrt( + ((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) + ); + if (((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) < + pow(10.0, -8.0)) { C_ion = D_ion / sqrt(pow(10.0, -8.0)); C0_ion = (D_ion + Etot_ion) / sqrt(pow(10.0, -8.0)); } double alpha0_ion = -1.0 / (gas_gamma_ion * gas_gamma_ion); double alpha1_ion = -2.0 * C_ion * ((gas_gamma_ion - 1.0) / (gas_gamma_ion * gas_gamma_ion)); - double alpha2_ion = ((gas_gamma_ion - 2.0) / gas_gamma_ion) * ((C0_ion * C0_ion) - 1.0) + 1.0 - (C_ion * C_ion) * - ((gas_gamma_ion - 1.0) / gas_gamma_ion) * ((gas_gamma_ion - 1.0) / gas_gamma_ion); + double alpha2_ion = ((gas_gamma_ion - 2.0) / gas_gamma_ion) * ((C0_ion * C0_ion) - 1.0) + 1.0 - + (C_ion * C_ion) * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * + ((gas_gamma_ion - 1.0) / gas_gamma_ion); double alpha4_ion = (C0_ion * C0_ion) - 1.0; - double eta_ion = 2.0 * C_ion *((gas_gamma_ion - 1.0) / gas_gamma_ion); + double eta_ion = 2.0 * C_ion * ((gas_gamma_ion - 1.0) / gas_gamma_ion); double guess_ion = 1.0; int iter_ion = 0; while (iter_ion < 100) { - double poly_ion = (alpha4_ion * (guess_ion * guess_ion * guess_ion) * (guess_ion - eta_ion)) + (alpha2_ion * (guess_ion * guess_ion)) + - (alpha1_ion * guess_ion) + alpha0_ion; - double poly_der_ion = alpha1_ion + (2.0 * alpha2_ion * guess_ion) + (4.0 * alpha4_ion * (guess_ion * guess_ion * guess_ion)) - - (3.0 * eta_ion * alpha4_ion * (guess_ion * guess_ion)); + double poly_ion = (alpha4_ion * (guess_ion * guess_ion * guess_ion) * (guess_ion - eta_ion)) + + (alpha2_ion * (guess_ion * guess_ion)) + (alpha1_ion * guess_ion) + + alpha0_ion; + double poly_der_ion = alpha1_ion + (2.0 * alpha2_ion * guess_ion) + + (4.0 * alpha4_ion * (guess_ion * guess_ion * guess_ion)) - + (3.0 * eta_ion * alpha4_ion * (guess_ion * guess_ion)); double guess_new_ion = guess_ion - (poly_ion / poly_der_ion); if (fabs(guess_ion - guess_new_ion) < pow(10.0, -8.0)) { iter_ion = 100; - } - else { + } else { iter_ion += 1; guess_ion = guess_new_ion; } } - double W_ion = 0.5 * C0_ion * guess_ion * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * ((1.0 - (C_ion * guess_ion)) / - ((C0_ion * C0_ion) * (guess_ion * guess_ion)))))); + double W_ion = + 0.5 * C0_ion * guess_ion * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * + ((1.0 - (C_ion * guess_ion)) / ((C0_ion * C0_ion) * (guess_ion * guess_ion)))) + )); double h_ion = 1.0 / (C_ion * guess_ion); double rho_ion = D_ion / W_ion; @@ -1773,24 +2151,28 @@ explicit_gr_twofluid_source_update_ion_spacetime_euler(const gkyl_moment_em_coup spacetime_vel_ion[3] = (W_ion * vz_ion) - (shift_z * (W_ion / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } double stress_energy_ion[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - stress_energy_ion[i][j] = (rho_ion * h_ion * spacetime_vel_ion[i] * spacetime_vel_ion[j]) + (p_ion * inv_spacetime_metric[i][j]); + stress_energy_ion[i][j] = (rho_ion * h_ion * spacetime_vel_ion[i] * spacetime_vel_ion[j]) + + (p_ion * inv_spacetime_metric[i][j]); } } @@ -1800,22 +2182,46 @@ explicit_gr_twofluid_source_update_ion_spacetime_euler(const gkyl_moment_em_coup lapse_der[2] = fluid_old[43]; double shift_der[3][3]; - shift_der[0][0] = fluid_old[44]; shift_der[0][1] = fluid_old[45]; shift_der[0][2] = fluid_old[46]; - shift_der[1][0] = fluid_old[47]; shift_der[1][1] = fluid_old[48]; shift_der[1][2] = fluid_old[49]; - shift_der[2][0] = fluid_old[50]; shift_der[2][1] = fluid_old[51]; shift_der[2][2] = fluid_old[52]; + shift_der[0][0] = fluid_old[44]; + shift_der[0][1] = fluid_old[45]; + shift_der[0][2] = fluid_old[46]; + shift_der[1][0] = fluid_old[47]; + shift_der[1][1] = fluid_old[48]; + shift_der[1][2] = fluid_old[49]; + shift_der[2][0] = fluid_old[50]; + shift_der[2][1] = fluid_old[51]; + shift_der[2][2] = fluid_old[52]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = fluid_old[53]; spatial_metric_der[0][0][1] = fluid_old[54]; spatial_metric_der[0][0][2] = fluid_old[55]; - spatial_metric_der[0][1][0] = fluid_old[56]; spatial_metric_der[0][1][1] = fluid_old[57]; spatial_metric_der[0][1][2] = fluid_old[58]; - spatial_metric_der[0][2][0] = fluid_old[59]; spatial_metric_der[0][2][1] = fluid_old[60]; spatial_metric_der[0][2][2] = fluid_old[61]; - - spatial_metric_der[1][0][0] = fluid_old[62]; spatial_metric_der[1][0][1] = fluid_old[63]; spatial_metric_der[1][0][2] = fluid_old[64]; - spatial_metric_der[1][1][0] = fluid_old[65]; spatial_metric_der[1][1][1] = fluid_old[66]; spatial_metric_der[1][1][2] = fluid_old[67]; - spatial_metric_der[1][2][0] = fluid_old[68]; spatial_metric_der[1][2][1] = fluid_old[69]; spatial_metric_der[1][2][2] = fluid_old[70]; - - spatial_metric_der[2][0][0] = fluid_old[71]; spatial_metric_der[2][0][1] = fluid_old[72]; spatial_metric_der[2][0][2] = fluid_old[73]; - spatial_metric_der[2][1][0] = fluid_old[74]; spatial_metric_der[2][1][1] = fluid_old[75]; spatial_metric_der[2][1][2] = fluid_old[76]; - spatial_metric_der[2][2][0] = fluid_old[77]; spatial_metric_der[2][2][1] = fluid_old[78]; spatial_metric_der[2][2][2] = fluid_old[79]; + spatial_metric_der[0][0][0] = fluid_old[53]; + spatial_metric_der[0][0][1] = fluid_old[54]; + spatial_metric_der[0][0][2] = fluid_old[55]; + spatial_metric_der[0][1][0] = fluid_old[56]; + spatial_metric_der[0][1][1] = fluid_old[57]; + spatial_metric_der[0][1][2] = fluid_old[58]; + spatial_metric_der[0][2][0] = fluid_old[59]; + spatial_metric_der[0][2][1] = fluid_old[60]; + spatial_metric_der[0][2][2] = fluid_old[61]; + + spatial_metric_der[1][0][0] = fluid_old[62]; + spatial_metric_der[1][0][1] = fluid_old[63]; + spatial_metric_der[1][0][2] = fluid_old[64]; + spatial_metric_der[1][1][0] = fluid_old[65]; + spatial_metric_der[1][1][1] = fluid_old[66]; + spatial_metric_der[1][1][2] = fluid_old[67]; + spatial_metric_der[1][2][0] = fluid_old[68]; + spatial_metric_der[1][2][1] = fluid_old[69]; + spatial_metric_der[1][2][2] = fluid_old[70]; + + spatial_metric_der[2][0][0] = fluid_old[71]; + spatial_metric_der[2][0][1] = fluid_old[72]; + spatial_metric_der[2][0][2] = fluid_old[73]; + spatial_metric_der[2][1][0] = fluid_old[74]; + spatial_metric_der[2][1][1] = fluid_old[75]; + spatial_metric_der[2][1][2] = fluid_old[76]; + spatial_metric_der[2][2][0] = fluid_old[77]; + spatial_metric_der[2][2][1] = fluid_old[78]; + spatial_metric_der[2][2][2] = fluid_old[79]; double mom_ion[3]; mom_ion[0] = (rho_ion + p_ion) * (W_ion * W_ion) * vx_ion; @@ -1829,8 +2235,10 @@ explicit_gr_twofluid_source_update_ion_spacetime_euler(const gkyl_moment_em_coup // Energy density source. for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - fluid_new[9] += dt * (stress_energy_ion[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); - fluid_new[9] += dt * (2.0 * stress_energy_ion[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); + fluid_new[9] += + dt * (stress_energy_ion[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); + fluid_new[9] += + dt * (2.0 * stress_energy_ion[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); fluid_new[9] += dt * (stress_energy_ion[i + 1][j + 1] * extrinsic_curvature[i][j]); } @@ -1844,27 +2252,31 @@ explicit_gr_twofluid_source_update_ion_spacetime_euler(const gkyl_moment_em_coup for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - fluid_new[6 + j] += dt * (0.5 * stress_energy_ion[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]); - fluid_new[6 + j] += dt * (0.5 * stress_energy_ion[k + 1][l + 1] * spatial_metric_der[j][k][l]); + fluid_new[6 + j] += dt * (0.5 * stress_energy_ion[0][0] * shift[k] * shift[l] * + spatial_metric_der[j][k][l]); + fluid_new[6 + j] += + dt * (0.5 * stress_energy_ion[k + 1][l + 1] * spatial_metric_der[j][k][l]); } fluid_new[6 + j] += dt * ((mom_ion[k] / lapse) * shift_der[j][k]); for (int i = 0; i < 3; i++) { - fluid_new[6 + j] += dt * (stress_energy_ion[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); + fluid_new[6 + j] += + dt * (stress_energy_ion[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); } } } - } - else { + } else { for (int i = 0; i < 84; i++) { fluid_new[i] = fluid_old[i]; } } } -void -explicit_gr_twofluid_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]) +void explicit_gr_twofluid_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; @@ -1879,18 +2291,30 @@ explicit_gr_twofluid_source_update(const gkyl_moment_em_coupling* mom_em, double for (int i = 0; i < nfluids; i++) { double *f = fluid_s[i]; - double f_new_elc[84], f_new_elc_spacetime[84], f_new_ion[84], f_new_ion_spacetime[84], f_new[84]; + double f_new_elc[84], f_new_elc_spacetime[84], f_new_ion[84], f_new_ion_spacetime[84], + f_new[84]; double f_stage1[84], f_stage2[84], f_old[84]; for (int j = 0; j < 84; j++) { f_old[j] = f[j]; } - explicit_gr_twofluid_source_update_elc_euler(mom_em, gas_gamma_elc, mass_elc, charge_elc, t_curr, dt, f_old, f_new_elc); - explicit_gr_twofluid_source_update_elc_spacetime_euler(mom_em, gas_gamma_elc, t_curr, dt, f_new_elc, f_new_elc_spacetime); - explicit_gr_twofluid_source_update_ion_euler(mom_em, gas_gamma_ion, mass_ion, charge_ion, t_curr, dt, f_old, f_new_ion); - explicit_gr_twofluid_source_update_ion_spacetime_euler(mom_em, gas_gamma_ion, t_curr, dt, f_new_ion, f_new_ion_spacetime); - explicit_gr_twofluid_source_update_em_euler(mom_em, gas_gamma_elc, gas_gamma_ion, mass_elc, charge_elc, mass_ion, charge_ion, e_fact, t_curr, dt, f_old, f_new); + explicit_gr_twofluid_source_update_elc_euler( + mom_em, gas_gamma_elc, mass_elc, charge_elc, t_curr, dt, f_old, f_new_elc + ); + explicit_gr_twofluid_source_update_elc_spacetime_euler( + mom_em, gas_gamma_elc, t_curr, dt, f_new_elc, f_new_elc_spacetime + ); + explicit_gr_twofluid_source_update_ion_euler( + mom_em, gas_gamma_ion, mass_ion, charge_ion, t_curr, dt, f_old, f_new_ion + ); + explicit_gr_twofluid_source_update_ion_spacetime_euler( + mom_em, gas_gamma_ion, t_curr, dt, f_new_ion, f_new_ion_spacetime + ); + explicit_gr_twofluid_source_update_em_euler( + mom_em, gas_gamma_elc, gas_gamma_ion, mass_elc, charge_elc, mass_ion, charge_ion, e_fact, + t_curr, dt, f_old, f_new + ); for (int j = 0; j < 5; j++) { f_stage1[j] = f_new_elc_spacetime[j]; } @@ -1901,12 +2325,22 @@ explicit_gr_twofluid_source_update(const gkyl_moment_em_coupling* mom_em, double f_stage1[j] = f_new[j]; } - explicit_gr_twofluid_source_update_elc_euler(mom_em, gas_gamma_elc, mass_elc, charge_elc, t_curr + dt, dt, f_stage1, f_new_elc); - explicit_gr_twofluid_source_update_elc_spacetime_euler(mom_em, gas_gamma_elc, t_curr + dt, dt, f_new_elc, f_new_elc_spacetime); - explicit_gr_twofluid_source_update_ion_euler(mom_em, gas_gamma_ion, mass_ion, charge_ion, t_curr + dt, dt, f_stage1, f_new_ion); - explicit_gr_twofluid_source_update_ion_spacetime_euler(mom_em, gas_gamma_ion, t_curr + dt, dt, f_new_ion, f_new_ion_spacetime); - explicit_gr_twofluid_source_update_em_euler(mom_em, gas_gamma_elc, gas_gamma_ion, mass_elc, charge_elc, mass_ion, charge_ion, e_fact, t_curr + dt, dt, - f_stage1, f_new); + explicit_gr_twofluid_source_update_elc_euler( + mom_em, gas_gamma_elc, mass_elc, charge_elc, t_curr + dt, dt, f_stage1, f_new_elc + ); + explicit_gr_twofluid_source_update_elc_spacetime_euler( + mom_em, gas_gamma_elc, t_curr + dt, dt, f_new_elc, f_new_elc_spacetime + ); + explicit_gr_twofluid_source_update_ion_euler( + mom_em, gas_gamma_ion, mass_ion, charge_ion, t_curr + dt, dt, f_stage1, f_new_ion + ); + explicit_gr_twofluid_source_update_ion_spacetime_euler( + mom_em, gas_gamma_ion, t_curr + dt, dt, f_new_ion, f_new_ion_spacetime + ); + explicit_gr_twofluid_source_update_em_euler( + mom_em, gas_gamma_elc, gas_gamma_ion, mass_elc, charge_elc, mass_ion, charge_ion, e_fact, + t_curr + dt, dt, f_stage1, f_new + ); for (int j = 0; j < 5; j++) { f_stage2[j] = (0.75 * f_old[j]) + (0.25 * f_new_elc_spacetime[j]); } @@ -1917,12 +2351,22 @@ explicit_gr_twofluid_source_update(const gkyl_moment_em_coupling* mom_em, double f_stage2[j] = (0.75 * f_old[j]) + (0.25 * f_new[j]); } - explicit_gr_twofluid_source_update_elc_euler(mom_em, gas_gamma_elc, mass_elc, charge_elc, t_curr + (0.5 * dt), dt, f_stage2, f_new_elc); - explicit_gr_twofluid_source_update_elc_spacetime_euler(mom_em, gas_gamma_elc, t_curr + (0.5 * dt), dt, f_new_elc, f_new_elc_spacetime); - explicit_gr_twofluid_source_update_ion_euler(mom_em, gas_gamma_ion, mass_ion, charge_ion, t_curr + (0.5 * dt), dt, f_stage2, f_new_ion); - explicit_gr_twofluid_source_update_ion_spacetime_euler(mom_em, gas_gamma_ion, t_curr + (0.5 * dt), dt, f_new_ion, f_new_ion_spacetime); - explicit_gr_twofluid_source_update_em_euler(mom_em, gas_gamma_elc, gas_gamma_ion, mass_elc, charge_elc, mass_ion, charge_ion, e_fact, - t_curr + (0.5 * dt), dt, f_stage2, f_new); + explicit_gr_twofluid_source_update_elc_euler( + mom_em, gas_gamma_elc, mass_elc, charge_elc, t_curr + (0.5 * dt), dt, f_stage2, f_new_elc + ); + explicit_gr_twofluid_source_update_elc_spacetime_euler( + mom_em, gas_gamma_elc, t_curr + (0.5 * dt), dt, f_new_elc, f_new_elc_spacetime + ); + explicit_gr_twofluid_source_update_ion_euler( + mom_em, gas_gamma_ion, mass_ion, charge_ion, t_curr + (0.5 * dt), dt, f_stage2, f_new_ion + ); + explicit_gr_twofluid_source_update_ion_spacetime_euler( + mom_em, gas_gamma_ion, t_curr + (0.5 * dt), dt, f_new_ion, f_new_ion_spacetime + ); + explicit_gr_twofluid_source_update_em_euler( + mom_em, gas_gamma_elc, gas_gamma_ion, mass_elc, charge_elc, mass_ion, charge_ion, e_fact, + t_curr + (0.5 * dt), dt, f_stage2, f_new + ); for (int j = 0; j < 5; j++) { f[j] = ((1.0 / 3.0) * f_old[j]) + ((2.0 / 3.0) * f_new_elc_spacetime[j]); } @@ -1935,35 +2379,67 @@ explicit_gr_twofluid_source_update(const gkyl_moment_em_coupling* mom_em, double } } -void -explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double excision_threshold, - const enum gkyl_spacetime_slicing spacetime_slicing, const enum gkyl_spacetime_evolution spacetime_evolution, double t_curr, const double dt, - double* fluid_old, double* fluid_new) +void explicit_vacuum_einstein_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double excision_threshold, + const enum gkyl_spacetime_slicing spacetime_slicing, + const enum gkyl_spacetime_evolution spacetime_evolution, double t_curr, const double dt, + double *fluid_old, double *fluid_new +) { double spatial_metric[3][3]; - spatial_metric[0][0] = fluid_old[0]; spatial_metric[0][1] = fluid_old[1]; spatial_metric[0][2] = fluid_old[2]; - spatial_metric[1][0] = fluid_old[3]; spatial_metric[1][1] = fluid_old[4]; spatial_metric[1][2] = fluid_old[5]; - spatial_metric[2][0] = fluid_old[6]; spatial_metric[2][1] = fluid_old[7]; spatial_metric[2][2] = fluid_old[8]; + spatial_metric[0][0] = fluid_old[0]; + spatial_metric[0][1] = fluid_old[1]; + spatial_metric[0][2] = fluid_old[2]; + spatial_metric[1][0] = fluid_old[3]; + spatial_metric[1][1] = fluid_old[4]; + spatial_metric[1][2] = fluid_old[5]; + spatial_metric[2][0] = fluid_old[6]; + spatial_metric[2][1] = fluid_old[7]; + spatial_metric[2][2] = fluid_old[8]; double lapse = fluid_old[9]; double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = fluid_old[10]; extrinsic_curvature[0][1] = fluid_old[11]; extrinsic_curvature[0][2] = fluid_old[12]; - extrinsic_curvature[1][0] = fluid_old[13]; extrinsic_curvature[1][1] = fluid_old[14]; extrinsic_curvature[1][2] = fluid_old[15]; - extrinsic_curvature[2][0] = fluid_old[16]; extrinsic_curvature[2][1] = fluid_old[17]; extrinsic_curvature[2][2] = fluid_old[18]; + extrinsic_curvature[0][0] = fluid_old[10]; + extrinsic_curvature[0][1] = fluid_old[11]; + extrinsic_curvature[0][2] = fluid_old[12]; + extrinsic_curvature[1][0] = fluid_old[13]; + extrinsic_curvature[1][1] = fluid_old[14]; + extrinsic_curvature[1][2] = fluid_old[15]; + extrinsic_curvature[2][0] = fluid_old[16]; + extrinsic_curvature[2][1] = fluid_old[17]; + extrinsic_curvature[2][2] = fluid_old[18]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = fluid_old[19]; spatial_metric_der[0][0][1] = fluid_old[20]; spatial_metric_der[0][0][2] = fluid_old[21]; - spatial_metric_der[0][1][0] = fluid_old[22]; spatial_metric_der[0][1][1] = fluid_old[23]; spatial_metric_der[0][1][2] = fluid_old[24]; - spatial_metric_der[0][2][0] = fluid_old[25]; spatial_metric_der[0][2][1] = fluid_old[26]; spatial_metric_der[0][2][2] = fluid_old[27]; - - spatial_metric_der[1][0][0] = fluid_old[28]; spatial_metric_der[1][0][1] = fluid_old[29]; spatial_metric_der[1][0][2] = fluid_old[30]; - spatial_metric_der[1][1][0] = fluid_old[31]; spatial_metric_der[1][1][1] = fluid_old[32]; spatial_metric_der[1][1][2] = fluid_old[33]; - spatial_metric_der[1][2][0] = fluid_old[34]; spatial_metric_der[1][2][1] = fluid_old[35]; spatial_metric_der[1][2][2] = fluid_old[36]; - - spatial_metric_der[2][0][0] = fluid_old[37]; spatial_metric_der[2][0][1] = fluid_old[38]; spatial_metric_der[2][0][2] = fluid_old[39]; - spatial_metric_der[2][1][0] = fluid_old[40]; spatial_metric_der[2][1][1] = fluid_old[41]; spatial_metric_der[2][1][2] = fluid_old[42]; - spatial_metric_der[2][2][0] = fluid_old[43]; spatial_metric_der[2][2][1] = fluid_old[44]; spatial_metric_der[2][2][2] = fluid_old[45]; + spatial_metric_der[0][0][0] = fluid_old[19]; + spatial_metric_der[0][0][1] = fluid_old[20]; + spatial_metric_der[0][0][2] = fluid_old[21]; + spatial_metric_der[0][1][0] = fluid_old[22]; + spatial_metric_der[0][1][1] = fluid_old[23]; + spatial_metric_der[0][1][2] = fluid_old[24]; + spatial_metric_der[0][2][0] = fluid_old[25]; + spatial_metric_der[0][2][1] = fluid_old[26]; + spatial_metric_der[0][2][2] = fluid_old[27]; + + spatial_metric_der[1][0][0] = fluid_old[28]; + spatial_metric_der[1][0][1] = fluid_old[29]; + spatial_metric_der[1][0][2] = fluid_old[30]; + spatial_metric_der[1][1][0] = fluid_old[31]; + spatial_metric_der[1][1][1] = fluid_old[32]; + spatial_metric_der[1][1][2] = fluid_old[33]; + spatial_metric_der[1][2][0] = fluid_old[34]; + spatial_metric_der[1][2][1] = fluid_old[35]; + spatial_metric_der[1][2][2] = fluid_old[36]; + + spatial_metric_der[2][0][0] = fluid_old[37]; + spatial_metric_der[2][0][1] = fluid_old[38]; + spatial_metric_der[2][0][2] = fluid_old[39]; + spatial_metric_der[2][1][0] = fluid_old[40]; + spatial_metric_der[2][1][1] = fluid_old[41]; + spatial_metric_der[2][1][2] = fluid_old[42]; + spatial_metric_der[2][2][0] = fluid_old[43]; + spatial_metric_der[2][2][1] = fluid_old[44]; + spatial_metric_der[2][2][2] = fluid_old[45]; double lapse_der[3]; lapse_der[0] = fluid_old[46]; @@ -1981,9 +2457,15 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ shift_vect[2] = fluid_old[54]; double shift_vect_der[3][3]; - shift_vect_der[0][0] = fluid_old[55]; shift_vect_der[0][1] = fluid_old[56]; shift_vect_der[0][2] = fluid_old[57]; - shift_vect_der[1][0] = fluid_old[58]; shift_vect_der[1][1] = fluid_old[59]; shift_vect_der[1][2] = fluid_old[60]; - shift_vect_der[2][0] = fluid_old[61]; shift_vect_der[2][1] = fluid_old[62]; shift_vect_der[2][2] = fluid_old[63]; + shift_vect_der[0][0] = fluid_old[55]; + shift_vect_der[0][1] = fluid_old[56]; + shift_vect_der[0][2] = fluid_old[57]; + shift_vect_der[1][0] = fluid_old[58]; + shift_vect_der[1][1] = fluid_old[59]; + shift_vect_der[1][2] = fluid_old[60]; + shift_vect_der[2][0] = fluid_old[61]; + shift_vect_der[2][1] = fluid_old[62]; + shift_vect_der[2][2] = fluid_old[63]; bool in_excision_region = false; if (lapse < excision_threshold) { @@ -1992,10 +2474,13 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ if (!in_excision_region) { double inv_spatial_metric[3][3]; - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -2026,8 +2511,7 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -2035,16 +2519,16 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spatial_metric[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + inv_spatial_metric[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } double evolution_func = 0.0; if (spacetime_evolution == GKYL_RICCI_EVOLUTION) { evolution_func = 0.0; - } - else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { + } else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { evolution_func = 1.0; } @@ -2073,7 +2557,8 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - extrinsic_curvature_raised[i][j] += inv_spatial_metric[i][l] * inv_spatial_metric[m][j] * extrinsic_curvature[l][m]; + extrinsic_curvature_raised[i][j] += + inv_spatial_metric[i][l] * inv_spatial_metric[m][j] * extrinsic_curvature[l][m]; } } } @@ -2097,7 +2582,8 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - shift_vect_der_switched[i][k] += inv_spatial_metric[i][l] * spatial_metric[m][k] * shift_vect_der[l][m]; + shift_vect_der_switched[i][k] += + inv_spatial_metric[i][l] * spatial_metric[m][k] * shift_vect_der[l][m]; } } } @@ -2111,18 +2597,17 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ double symmetrized_shift[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - symmetrized_shift[i][j] = (1.0 / lapse) * (shift_vect_der_lowered[i][j] + shift_vect_der_lowered[j][i]); + symmetrized_shift[i][j] = + (1.0 / lapse) * (shift_vect_der_lowered[i][j] + shift_vect_der_lowered[j][i]); } } double slicing_func = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { slicing_func = extrinsic_curvature_trace; - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { slicing_func = 2.0 * extrinsic_curvature_trace / lapse; } @@ -2131,9 +2616,10 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1[k][i][j] += inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; + spatial_metric_der_raised1[k][i][j] += + inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; } } } @@ -2146,7 +2632,8 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3[i][j][k] += inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; + spatial_metric_der_raised3[i][j][k] += + inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; } } } @@ -2160,7 +2647,8 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - spatial_metric_der_lowered1[i][j][k] += inv_spatial_metric[j][l] * inv_spatial_metric[m][k] * spatial_metric_der[i][l][m]; + spatial_metric_der_lowered1[i][j][k] += + inv_spatial_metric[j][l] * inv_spatial_metric[m][k] * spatial_metric_der[i][l][m]; } } } @@ -2175,7 +2663,8 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - spatial_metric_der_lowered3[i][j][k] += inv_spatial_metric[i][l] * inv_spatial_metric[m][j] * spatial_metric_der[l][m][k]; + spatial_metric_der_lowered3[i][j][k] += + inv_spatial_metric[i][l] * inv_spatial_metric[m][j] * spatial_metric_der[l][m][k]; } } } @@ -2185,7 +2674,7 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ double aux_vect_raised[3]; for (int k = 0; k < 3; k++) { aux_vect_raised[k] = 0.0; - + for (int l = 0; l < 3; l++) { aux_vect_raised[k] += inv_spatial_metric[k][l] * aux_vect[l]; } @@ -2209,7 +2698,8 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ double spatial_metric_source[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - spatial_metric_source[i][j] = -2.0 * lapse * (extrinsic_curvature[i][j] - symmetrized_shift[i][j]); + spatial_metric_source[i][j] = + -2.0 * lapse * (extrinsic_curvature[i][j] - symmetrized_shift[i][j]); for (int r = 0; r < 3; r++) { spatial_metric_source[i][j] += 2.0 * shift_vect[r] * spatial_metric_der[r][i][j]; @@ -2228,49 +2718,72 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ extrinsic_curvature_source[i][j] = 0.0; for (int r = 0; r < 3; r++) { - extrinsic_curvature_source[i][j] += 2.0 * extrinsic_curvature[i][r] * shift_vect_der[j][r]; - extrinsic_curvature_source[i][j] += 2.0 * extrinsic_curvature[j][r] * shift_vect_der[i][r]; - extrinsic_curvature_source[i][j] -= 2.0 * extrinsic_curvature[i][j] * shift_vect_der[r][r]; + extrinsic_curvature_source[i][j] += + 2.0 * extrinsic_curvature[i][r] * shift_vect_der[j][r]; + extrinsic_curvature_source[i][j] += + 2.0 * extrinsic_curvature[j][r] * shift_vect_der[i][r]; + extrinsic_curvature_source[i][j] -= + 2.0 * extrinsic_curvature[i][j] * shift_vect_der[r][r]; } for (int k = 0; k < 3; k++) { - extrinsic_curvature_source[i][j] -= 2.0 * lapse * extrinsic_curvature_mixed[i][k] * extrinsic_curvature[k][j]; - extrinsic_curvature_source[i][j] += lapse * extrinsic_curvature_trace * extrinsic_curvature[i][j]; + extrinsic_curvature_source[i][j] -= + 2.0 * lapse * extrinsic_curvature_mixed[i][k] * extrinsic_curvature[k][j]; + extrinsic_curvature_source[i][j] += + lapse * extrinsic_curvature_trace * extrinsic_curvature[i][j]; for (int r = 0; r < 3; r++) { - extrinsic_curvature_source[i][j] -= lapse * spatial_christoffel[k][r][i] * spatial_christoffel[r][k][j]; - - extrinsic_curvature_source[i][j] += 2.0 * lapse * spatial_metric_der_raised3[i][k][r] * spatial_metric_der_raised3[r][j][k]; - extrinsic_curvature_source[i][j] += 2.0 * lapse * spatial_metric_der_raised3[j][k][r] * spatial_metric_der_raised3[r][i][k]; - extrinsic_curvature_source[i][j] += lapse * spatial_christoffel[k][k][r] * spatial_christoffel[r][i][j]; - - extrinsic_curvature_source[i][j] -= lapse * (2.0 * spatial_metric_der_raised3[k][r][k] - lapse_der[r]) * (spatial_metric_der_raised3[i][j][r] + spatial_metric_der_raised3[j][i][r]); + extrinsic_curvature_source[i][j] -= + lapse * spatial_christoffel[k][r][i] * spatial_christoffel[r][k][j]; + + extrinsic_curvature_source[i][j] += 2.0 * lapse * spatial_metric_der_raised3[i][k][r] * + spatial_metric_der_raised3[r][j][k]; + extrinsic_curvature_source[i][j] += 2.0 * lapse * spatial_metric_der_raised3[j][k][r] * + spatial_metric_der_raised3[r][i][k]; + extrinsic_curvature_source[i][j] += + lapse * spatial_christoffel[k][k][r] * spatial_christoffel[r][i][j]; + + extrinsic_curvature_source[i][j] -= + lapse * (2.0 * spatial_metric_der_raised3[k][r][k] - lapse_der[r]) * + (spatial_metric_der_raised3[i][j][r] + spatial_metric_der_raised3[j][i][r]); } - extrinsic_curvature_source[i][j] += lapse * lapse_der[i] * (aux_vect[j] - (0.5 * spatial_metric_der_raised3[j][k][k])); - extrinsic_curvature_source[i][j] += lapse * lapse_der[j] * (aux_vect[i] - (0.5 * spatial_metric_der_raised3[i][k][k])); + extrinsic_curvature_source[i][j] += + lapse * lapse_der[i] * (aux_vect[j] - (0.5 * spatial_metric_der_raised3[j][k][k])); + extrinsic_curvature_source[i][j] += + lapse * lapse_der[j] * (aux_vect[i] - (0.5 * spatial_metric_der_raised3[i][k][k])); - extrinsic_curvature_source[i][j] -= lapse * evolution_func * aux_vect_raised[k] * spatial_metric_der[k][i][j]; + extrinsic_curvature_source[i][j] -= + lapse * evolution_func * aux_vect_raised[k] * spatial_metric_der[k][i][j]; } for (int k = 0; k < 3; k++) { for (int r = 0; r < 3; r++) { for (int s = 0; s < 3; s++) { - extrinsic_curvature_source[i][j] -= (0.25 * evolution_func * lapse * spatial_metric[i][j]) * spatial_metric_der_lowered1[k][r][s] * spatial_christoffel[k][r][s]; - extrinsic_curvature_source[i][j] += (0.25 * evolution_func * lapse * spatial_metric[i][j]) * spatial_metric_der_raised3[k][r][r] * spatial_metric_der_lowered3[k][s][s]; + extrinsic_curvature_source[i][j] -= + (0.25 * evolution_func * lapse * spatial_metric[i][j]) * + spatial_metric_der_lowered1[k][r][s] * spatial_christoffel[k][r][s]; + extrinsic_curvature_source[i][j] += + (0.25 * evolution_func * lapse * spatial_metric[i][j]) * + spatial_metric_der_raised3[k][r][r] * spatial_metric_der_lowered3[k][s][s]; } } - extrinsic_curvature_source[i][j] -= (0.5 * evolution_func * lapse * spatial_metric[i][j]) * aux_vect_raised[k] * lapse_der[k]; + extrinsic_curvature_source[i][j] -= + (0.5 * evolution_func * lapse * spatial_metric[i][j]) * aux_vect_raised[k] * + lapse_der[k]; } for (int r = 0; r < 3; r++) { for (int s = 0; s < 3; s++) { - extrinsic_curvature_source[i][j] += (0.25 * evolution_func * lapse * spatial_metric[i][j]) * extrinsic_curvature_raised[r][s] * extrinsic_curvature[r][s]; + extrinsic_curvature_source[i][j] += + (0.25 * evolution_func * lapse * spatial_metric[i][j]) * + extrinsic_curvature_raised[r][s] * extrinsic_curvature[r][s]; } } - extrinsic_curvature_source[i][j] -= (0.25 * evolution_func * lapse * spatial_metric[i][j]) * (extrinsic_curvature_trace * extrinsic_curvature_trace); + extrinsic_curvature_source[i][j] -= (0.25 * evolution_func * lapse * spatial_metric[i][j]) * + (extrinsic_curvature_trace * extrinsic_curvature_trace); } } @@ -2280,17 +2793,21 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ for (int r = 0; r < 3; r++) { aux_vect_source[i] += lapse * lapse_der[r] * extrinsic_curvature_mixed[i][r]; - + if (i == r) { aux_vect_source[i] -= lapse * lapse_der[r] * extrinsic_curvature_trace; } for (int s = 0; s < 3; s++) { - aux_vect_source[i] += lapse * extrinsic_curvature_mixed[s][r] * spatial_metric_der_raised3[i][r][s]; - aux_vect_source[i] -= 2.0 * lapse * extrinsic_curvature_mixed[s][r] * spatial_metric_der_raised3[r][i][s]; - - aux_vect_source[i] -= lapse * extrinsic_curvature_mixed[i][r] * spatial_metric_der_raised3[r][s][s]; - aux_vect_source[i] += 2.0 * lapse * extrinsic_curvature_mixed[i][r] * spatial_metric_der_raised3[s][r][s]; + aux_vect_source[i] += + lapse * extrinsic_curvature_mixed[s][r] * spatial_metric_der_raised3[i][r][s]; + aux_vect_source[i] -= + 2.0 * lapse * extrinsic_curvature_mixed[s][r] * spatial_metric_der_raised3[r][i][s]; + + aux_vect_source[i] -= + lapse * extrinsic_curvature_mixed[i][r] * spatial_metric_der_raised3[r][s][s]; + aux_vect_source[i] += + 2.0 * lapse * extrinsic_curvature_mixed[i][r] * spatial_metric_der_raised3[s][r][s]; } aux_vect_source[i] += 2.0 * shift_vect_der[i][r] * aux_vect[r]; @@ -2300,11 +2817,13 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ } for (int s = 0; s < 3; s++) { - aux_vect_source[i] += 2.0 * spatial_metric_der_raised3[r][i][s] * shift_vect_der_switched[r][s]; + aux_vect_source[i] += + 2.0 * spatial_metric_der_raised3[r][i][s] * shift_vect_der_switched[r][s]; if (i == s) { for (int j = 0; j < 3; j++) { - aux_vect_source[i] -= 2.0 * spatial_metric_der_raised1[j][j][r] * shift_vect_der_switched[r][s]; + aux_vect_source[i] -= + 2.0 * spatial_metric_der_raised1[j][j][r] * shift_vect_der_switched[r][s]; } } } @@ -2315,15 +2834,27 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ fluid_new[i] = fluid_old[i]; } - fluid_new[0] += dt * spatial_metric_source[0][0]; fluid_new[1] += dt * spatial_metric_source[0][1]; fluid_new[2] += dt * spatial_metric_source[0][2]; - fluid_new[3] += dt * spatial_metric_source[1][0]; fluid_new[4] += dt * spatial_metric_source[1][1]; fluid_new[5] += dt * spatial_metric_source[1][2]; - fluid_new[6] += dt * spatial_metric_source[2][0]; fluid_new[7] += dt * spatial_metric_source[2][1]; fluid_new[8] += dt * spatial_metric_source[2][2]; + fluid_new[0] += dt * spatial_metric_source[0][0]; + fluid_new[1] += dt * spatial_metric_source[0][1]; + fluid_new[2] += dt * spatial_metric_source[0][2]; + fluid_new[3] += dt * spatial_metric_source[1][0]; + fluid_new[4] += dt * spatial_metric_source[1][1]; + fluid_new[5] += dt * spatial_metric_source[1][2]; + fluid_new[6] += dt * spatial_metric_source[2][0]; + fluid_new[7] += dt * spatial_metric_source[2][1]; + fluid_new[8] += dt * spatial_metric_source[2][2]; fluid_new[9] += dt * lapse_source; - fluid_new[10] += dt * extrinsic_curvature_source[0][0]; fluid_new[11] += dt * extrinsic_curvature_source[0][1]; fluid_new[12] += dt * extrinsic_curvature_source[0][2]; - fluid_new[13] += dt * extrinsic_curvature_source[1][0]; fluid_new[14] += dt * extrinsic_curvature_source[1][1]; fluid_new[15] += dt * extrinsic_curvature_source[1][2]; - fluid_new[16] += dt * extrinsic_curvature_source[2][0]; fluid_new[17] += dt * extrinsic_curvature_source[2][1]; fluid_new[18] += dt * extrinsic_curvature_source[2][2]; + fluid_new[10] += dt * extrinsic_curvature_source[0][0]; + fluid_new[11] += dt * extrinsic_curvature_source[0][1]; + fluid_new[12] += dt * extrinsic_curvature_source[0][2]; + fluid_new[13] += dt * extrinsic_curvature_source[1][0]; + fluid_new[14] += dt * extrinsic_curvature_source[1][1]; + fluid_new[15] += dt * extrinsic_curvature_source[1][2]; + fluid_new[16] += dt * extrinsic_curvature_source[2][0]; + fluid_new[17] += dt * extrinsic_curvature_source[2][1]; + fluid_new[18] += dt * extrinsic_curvature_source[2][2]; fluid_new[49] += dt * aux_vect_source[0]; fluid_new[50] += dt * aux_vect_source[1]; @@ -2334,16 +2865,17 @@ explicit_vacuum_einstein_source_update_euler(const gkyl_moment_em_coupling* mom_ fluid_new[i] = 0.0; } } - } - else { + } else { for (int i = 0; i < 64; i++) { fluid_new[i] = fluid_old[i]; } } } -void -explicit_vacuum_einstein_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]) +void explicit_vacuum_einstein_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; @@ -2360,74 +2892,126 @@ explicit_vacuum_einstein_source_update(const gkyl_moment_em_coupling* mom_em, do f_old[j] = f[j]; } - explicit_vacuum_einstein_source_update_euler(mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr, dt, f_old, f_new); + explicit_vacuum_einstein_source_update_euler( + mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr, dt, f_old, f_new + ); for (int j = 0; j < 64; j++) { f_stage1[j] = f_new[j]; } - explicit_vacuum_einstein_source_update_euler(mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr + dt, dt, f_stage1, f_new); + explicit_vacuum_einstein_source_update_euler( + mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr + dt, dt, f_stage1, + f_new + ); for (int j = 0; j < 64; j++) { f_stage2[j] = (0.75 * f_old[j]) + (0.25 * f_new[j]); } - explicit_vacuum_einstein_source_update_euler(mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr + (0.5 * dt), dt, f_stage2, f_new); + explicit_vacuum_einstein_source_update_euler( + mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr + (0.5 * dt), dt, + f_stage2, f_new + ); for (int j = 0; j < 64; j++) { f[j] = ((1.0 / 3.0) * f_old[j]) + ((2.0 / 3.0) * f_new[j]); } } } -void -explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double excision_threshold, - const enum gkyl_spacetime_slicing spacetime_slicing, const enum gkyl_spacetime_evolution spacetime_evolution, double t_curr, const double dt, - double* fluid_old, double* fluid_new) +void explicit_vacuum_einstein_conformal_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double excision_threshold, + const enum gkyl_spacetime_slicing spacetime_slicing, + const enum gkyl_spacetime_evolution spacetime_evolution, double t_curr, const double dt, + double *fluid_old, double *fluid_new +) { double bssn_conformal_fact = fluid_old[64]; double conformal_fact = 1.0 / sqrt(bssn_conformal_fact); double bssn_conformal_fact_der[3]; - bssn_conformal_fact_der[0] = fluid_old[65]; bssn_conformal_fact_der[1] = fluid_old[66]; bssn_conformal_fact_der[2] = fluid_old[67]; + bssn_conformal_fact_der[0] = fluid_old[65]; + bssn_conformal_fact_der[1] = fluid_old[66]; + bssn_conformal_fact_der[2] = fluid_old[67]; double conformal_fact_der[3]; for (int i = 0; i < 3; i++) { - conformal_fact_der[i] = -(0.5 * bssn_conformal_fact_der[i]) / (pow(bssn_conformal_fact, 1.5) * conformal_fact); + conformal_fact_der[i] = + -(0.5 * bssn_conformal_fact_der[i]) / (pow(bssn_conformal_fact, 1.5) * conformal_fact); } double bssn_conformal_fact_der2[3][3]; - bssn_conformal_fact_der2[0][0] = fluid_old[68]; bssn_conformal_fact_der2[0][1] = fluid_old[69]; bssn_conformal_fact_der2[0][2] = fluid_old[70]; - bssn_conformal_fact_der2[1][0] = fluid_old[71]; bssn_conformal_fact_der2[1][1] = fluid_old[72]; bssn_conformal_fact_der2[1][2] = fluid_old[73]; - bssn_conformal_fact_der2[2][0] = fluid_old[74]; bssn_conformal_fact_der2[2][1] = fluid_old[75]; bssn_conformal_fact_der2[2][2] = fluid_old[76]; + bssn_conformal_fact_der2[0][0] = fluid_old[68]; + bssn_conformal_fact_der2[0][1] = fluid_old[69]; + bssn_conformal_fact_der2[0][2] = fluid_old[70]; + bssn_conformal_fact_der2[1][0] = fluid_old[71]; + bssn_conformal_fact_der2[1][1] = fluid_old[72]; + bssn_conformal_fact_der2[1][2] = fluid_old[73]; + bssn_conformal_fact_der2[2][0] = fluid_old[74]; + bssn_conformal_fact_der2[2][1] = fluid_old[75]; + bssn_conformal_fact_der2[2][2] = fluid_old[76]; double conformal_fact_der2[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_fact_der2[i][j] = -(0.5 * bssn_conformal_fact_der2[i][j]) / (pow(bssn_conformal_fact, 1.5) * conformal_fact); - conformal_fact_der2[i][j] += (0.75 * bssn_conformal_fact_der[i] * bssn_conformal_fact_der[j]) / (pow(bssn_conformal_fact, 2.5) * conformal_fact); + conformal_fact_der2[i][j] = + -(0.5 * bssn_conformal_fact_der2[i][j]) / (pow(bssn_conformal_fact, 1.5) * conformal_fact); + conformal_fact_der2[i][j] += + (0.75 * bssn_conformal_fact_der[i] * bssn_conformal_fact_der[j]) / + (pow(bssn_conformal_fact, 2.5) * conformal_fact); } } double conformal_spatial_metric[3][3]; - conformal_spatial_metric[0][0] = fluid_old[0]; conformal_spatial_metric[0][1] = fluid_old[1]; conformal_spatial_metric[0][2] = fluid_old[2]; - conformal_spatial_metric[1][0] = fluid_old[3]; conformal_spatial_metric[1][1] = fluid_old[4]; conformal_spatial_metric[1][2] = fluid_old[5]; - conformal_spatial_metric[2][0] = fluid_old[6]; conformal_spatial_metric[2][1] = fluid_old[7]; conformal_spatial_metric[2][2] = fluid_old[8]; + conformal_spatial_metric[0][0] = fluid_old[0]; + conformal_spatial_metric[0][1] = fluid_old[1]; + conformal_spatial_metric[0][2] = fluid_old[2]; + conformal_spatial_metric[1][0] = fluid_old[3]; + conformal_spatial_metric[1][1] = fluid_old[4]; + conformal_spatial_metric[1][2] = fluid_old[5]; + conformal_spatial_metric[2][0] = fluid_old[6]; + conformal_spatial_metric[2][1] = fluid_old[7]; + conformal_spatial_metric[2][2] = fluid_old[8]; double conformal_lapse = fluid_old[9]; double conformal_extrinsic_curvature[3][3]; - conformal_extrinsic_curvature[0][0] = fluid_old[10]; conformal_extrinsic_curvature[0][1] = fluid_old[11]; conformal_extrinsic_curvature[0][2] = fluid_old[12]; - conformal_extrinsic_curvature[1][0] = fluid_old[13]; conformal_extrinsic_curvature[1][1] = fluid_old[14]; conformal_extrinsic_curvature[1][2] = fluid_old[15]; - conformal_extrinsic_curvature[2][0] = fluid_old[16]; conformal_extrinsic_curvature[2][1] = fluid_old[17]; conformal_extrinsic_curvature[2][2] = fluid_old[18]; + conformal_extrinsic_curvature[0][0] = fluid_old[10]; + conformal_extrinsic_curvature[0][1] = fluid_old[11]; + conformal_extrinsic_curvature[0][2] = fluid_old[12]; + conformal_extrinsic_curvature[1][0] = fluid_old[13]; + conformal_extrinsic_curvature[1][1] = fluid_old[14]; + conformal_extrinsic_curvature[1][2] = fluid_old[15]; + conformal_extrinsic_curvature[2][0] = fluid_old[16]; + conformal_extrinsic_curvature[2][1] = fluid_old[17]; + conformal_extrinsic_curvature[2][2] = fluid_old[18]; double conformal_spatial_metric_der[3][3][3]; - conformal_spatial_metric_der[0][0][0] = fluid_old[19]; conformal_spatial_metric_der[0][0][1] = fluid_old[20]; conformal_spatial_metric_der[0][0][2] = fluid_old[21]; - conformal_spatial_metric_der[0][1][0] = fluid_old[22]; conformal_spatial_metric_der[0][1][1] = fluid_old[23]; conformal_spatial_metric_der[0][1][2] = fluid_old[24]; - conformal_spatial_metric_der[0][2][0] = fluid_old[25]; conformal_spatial_metric_der[0][2][1] = fluid_old[26]; conformal_spatial_metric_der[0][2][2] = fluid_old[27]; - - conformal_spatial_metric_der[1][0][0] = fluid_old[28]; conformal_spatial_metric_der[1][0][1] = fluid_old[29]; conformal_spatial_metric_der[1][0][2] = fluid_old[30]; - conformal_spatial_metric_der[1][1][0] = fluid_old[31]; conformal_spatial_metric_der[1][1][1] = fluid_old[32]; conformal_spatial_metric_der[1][1][2] = fluid_old[33]; - conformal_spatial_metric_der[1][2][0] = fluid_old[34]; conformal_spatial_metric_der[1][2][1] = fluid_old[35]; conformal_spatial_metric_der[1][2][2] = fluid_old[36]; - - conformal_spatial_metric_der[2][0][0] = fluid_old[37]; conformal_spatial_metric_der[2][0][1] = fluid_old[38]; conformal_spatial_metric_der[2][0][2] = fluid_old[39]; - conformal_spatial_metric_der[2][1][0] = fluid_old[40]; conformal_spatial_metric_der[2][1][1] = fluid_old[41]; conformal_spatial_metric_der[2][1][2] = fluid_old[42]; - conformal_spatial_metric_der[2][2][0] = fluid_old[43]; conformal_spatial_metric_der[2][2][1] = fluid_old[44]; conformal_spatial_metric_der[2][2][2] = fluid_old[45]; + conformal_spatial_metric_der[0][0][0] = fluid_old[19]; + conformal_spatial_metric_der[0][0][1] = fluid_old[20]; + conformal_spatial_metric_der[0][0][2] = fluid_old[21]; + conformal_spatial_metric_der[0][1][0] = fluid_old[22]; + conformal_spatial_metric_der[0][1][1] = fluid_old[23]; + conformal_spatial_metric_der[0][1][2] = fluid_old[24]; + conformal_spatial_metric_der[0][2][0] = fluid_old[25]; + conformal_spatial_metric_der[0][2][1] = fluid_old[26]; + conformal_spatial_metric_der[0][2][2] = fluid_old[27]; + + conformal_spatial_metric_der[1][0][0] = fluid_old[28]; + conformal_spatial_metric_der[1][0][1] = fluid_old[29]; + conformal_spatial_metric_der[1][0][2] = fluid_old[30]; + conformal_spatial_metric_der[1][1][0] = fluid_old[31]; + conformal_spatial_metric_der[1][1][1] = fluid_old[32]; + conformal_spatial_metric_der[1][1][2] = fluid_old[33]; + conformal_spatial_metric_der[1][2][0] = fluid_old[34]; + conformal_spatial_metric_der[1][2][1] = fluid_old[35]; + conformal_spatial_metric_der[1][2][2] = fluid_old[36]; + + conformal_spatial_metric_der[2][0][0] = fluid_old[37]; + conformal_spatial_metric_der[2][0][1] = fluid_old[38]; + conformal_spatial_metric_der[2][0][2] = fluid_old[39]; + conformal_spatial_metric_der[2][1][0] = fluid_old[40]; + conformal_spatial_metric_der[2][1][1] = fluid_old[41]; + conformal_spatial_metric_der[2][1][2] = fluid_old[42]; + conformal_spatial_metric_der[2][2][0] = fluid_old[43]; + conformal_spatial_metric_der[2][2][1] = fluid_old[44]; + conformal_spatial_metric_der[2][2][2] = fluid_old[45]; double conformal_lapse_der[3]; conformal_lapse_der[0] = fluid_old[46]; @@ -2445,9 +3029,15 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup conformal_shift_vect[2] = fluid_old[54]; double conformal_shift_vect_der[3][3]; - conformal_shift_vect_der[0][0] = fluid_old[55]; conformal_shift_vect_der[0][1] = fluid_old[56]; conformal_shift_vect_der[0][2] = fluid_old[57]; - conformal_shift_vect_der[1][0] = fluid_old[58]; conformal_shift_vect_der[1][1] = fluid_old[59]; conformal_shift_vect_der[1][2] = fluid_old[60]; - conformal_shift_vect_der[2][0] = fluid_old[61]; conformal_shift_vect_der[2][1] = fluid_old[62]; conformal_shift_vect_der[2][2] = fluid_old[63]; + conformal_shift_vect_der[0][0] = fluid_old[55]; + conformal_shift_vect_der[0][1] = fluid_old[56]; + conformal_shift_vect_der[0][2] = fluid_old[57]; + conformal_shift_vect_der[1][0] = fluid_old[58]; + conformal_shift_vect_der[1][1] = fluid_old[59]; + conformal_shift_vect_der[1][2] = fluid_old[60]; + conformal_shift_vect_der[2][0] = fluid_old[61]; + conformal_shift_vect_der[2][1] = fluid_old[62]; + conformal_shift_vect_der[2][2] = fluid_old[63]; bool in_excision_region = false; if (conformal_lapse < excision_threshold) { @@ -2457,10 +3047,16 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup if (!in_excision_region) { double inv_conformal_spatial_metric[3][3]; double conformal_spatial_det = - (conformal_spatial_metric[0][0] * ((conformal_spatial_metric[1][1] * conformal_spatial_metric[2][2]) - (conformal_spatial_metric[2][1] * conformal_spatial_metric[1][2]))) - - (conformal_spatial_metric[0][1] * ((conformal_spatial_metric[1][0] * conformal_spatial_metric[2][2]) - (conformal_spatial_metric[1][2] * conformal_spatial_metric[2][0]))) + - (conformal_spatial_metric[0][2] * ((conformal_spatial_metric[1][0] * conformal_spatial_metric[2][1]) - (conformal_spatial_metric[1][1] * conformal_spatial_metric[2][0]))); - + (conformal_spatial_metric[0][0] * + ((conformal_spatial_metric[1][1] * conformal_spatial_metric[2][2]) - + (conformal_spatial_metric[2][1] * conformal_spatial_metric[1][2]))) - + (conformal_spatial_metric[0][1] * + ((conformal_spatial_metric[1][0] * conformal_spatial_metric[2][2]) - + (conformal_spatial_metric[1][2] * conformal_spatial_metric[2][0]))) + + (conformal_spatial_metric[0][2] * + ((conformal_spatial_metric[1][0] * conformal_spatial_metric[2][1]) - + (conformal_spatial_metric[1][1] * conformal_spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += conformal_spatial_metric[i][i]; @@ -2476,7 +3072,8 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { - conformal_spatial_metric_sq[i][j] += conformal_spatial_metric[i][k] * conformal_spatial_metric[k][j]; + conformal_spatial_metric_sq[i][j] += + conformal_spatial_metric[i][k] * conformal_spatial_metric[k][j]; } } } @@ -2491,8 +3088,7 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -2500,23 +3096,25 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_conformal_spatial_metric[i][j] = (1.0 / conformal_spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * conformal_spatial_metric[i][j]) + conformal_spatial_metric_sq[i][j]); + inv_conformal_spatial_metric[i][j] = + (1.0 / conformal_spatial_det) * + ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * conformal_spatial_metric[i][j]) + conformal_spatial_metric_sq[i][j]); } } double evolution_func = 0.0; if (spacetime_evolution == GKYL_RICCI_EVOLUTION) { evolution_func = 0.0; - } - else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { + } else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { evolution_func = 1.0; } double conformal_extrinsic_curvature_trace = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_extrinsic_curvature_trace += inv_conformal_spatial_metric[i][j] * conformal_extrinsic_curvature[i][j]; + conformal_extrinsic_curvature_trace += + inv_conformal_spatial_metric[i][j] * conformal_extrinsic_curvature[i][j]; } } @@ -2526,7 +3124,8 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup conformal_extrinsic_curvature_mixed[i][j] = 0.0; for (int l = 0; l < 3; l++) { - conformal_extrinsic_curvature_mixed[i][j] += inv_conformal_spatial_metric[l][j] * conformal_extrinsic_curvature[i][l]; + conformal_extrinsic_curvature_mixed[i][j] += + inv_conformal_spatial_metric[l][j] * conformal_extrinsic_curvature[i][l]; } } } @@ -2538,7 +3137,9 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_extrinsic_curvature_raised[i][j] += inv_conformal_spatial_metric[i][l] * inv_conformal_spatial_metric[m][j] * conformal_extrinsic_curvature[l][m]; + conformal_extrinsic_curvature_raised[i][j] += inv_conformal_spatial_metric[i][l] * + inv_conformal_spatial_metric[m][j] * + conformal_extrinsic_curvature[l][m]; } } } @@ -2550,7 +3151,8 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup conformal_shift_vect_der_lowered[i][j] = 0.0; for (int k = 0; k < 3; k++) { - conformal_shift_vect_der_lowered[i][j] += conformal_spatial_metric[k][j] * conformal_shift_vect_der[i][k]; + conformal_shift_vect_der_lowered[i][j] += + conformal_spatial_metric[k][j] * conformal_shift_vect_der[i][k]; } } } @@ -2562,7 +3164,9 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_shift_vect_der_switched[i][k] += inv_conformal_spatial_metric[i][l] * conformal_spatial_metric[m][k] * conformal_shift_vect_der[l][m]; + conformal_shift_vect_der_switched[i][k] += inv_conformal_spatial_metric[i][l] * + conformal_spatial_metric[m][k] * + conformal_shift_vect_der[l][m]; } } } @@ -2576,19 +3180,22 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup double conformal_symmetrized_shift[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_symmetrized_shift[i][j] = (1.0 / conformal_lapse) * (conformal_shift_vect_der_lowered[i][j] + conformal_shift_vect_der_lowered[j][i]); + conformal_symmetrized_shift[i][j] = + (1.0 / conformal_lapse) * + (conformal_shift_vect_der_lowered[i][j] + conformal_shift_vect_der_lowered[j][i]); } } double slicing_func = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { - slicing_func = conformal_extrinsic_curvature_trace / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { - slicing_func = 2.0 * conformal_extrinsic_curvature_trace / (conformal_lapse * (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + slicing_func = conformal_extrinsic_curvature_trace / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + slicing_func = + 2.0 * conformal_extrinsic_curvature_trace / + (conformal_lapse * (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); } double conformal_spatial_metric_der_raised1[3][3][3]; @@ -2596,9 +3203,10 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1[k][i][j] += inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; + conformal_spatial_metric_der_raised1[k][i][j] += + inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; } } } @@ -2611,7 +3219,8 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup conformal_spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3[i][j][k] += inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; + conformal_spatial_metric_der_raised3[i][j][k] += + inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; } } } @@ -2625,7 +3234,9 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_spatial_metric_der_lowered1[i][j][k] += inv_conformal_spatial_metric[j][l] * inv_conformal_spatial_metric[m][k] * conformal_spatial_metric_der[i][l][m]; + conformal_spatial_metric_der_lowered1[i][j][k] += + inv_conformal_spatial_metric[j][l] * inv_conformal_spatial_metric[m][k] * + conformal_spatial_metric_der[i][l][m]; } } } @@ -2640,7 +3251,9 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_spatial_metric_der_lowered3[i][j][k] += inv_conformal_spatial_metric[i][l] * inv_conformal_spatial_metric[m][j] * conformal_spatial_metric_der[l][m][k]; + conformal_spatial_metric_der_lowered3[i][j][k] += + inv_conformal_spatial_metric[i][l] * inv_conformal_spatial_metric[m][j] * + conformal_spatial_metric_der[l][m][k]; } } } @@ -2650,7 +3263,7 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup double conformal_aux_vect_raised[3]; for (int k = 0; k < 3; k++) { conformal_aux_vect_raised[k] = 0.0; - + for (int l = 0; l < 3; l++) { conformal_aux_vect_raised[k] += inv_conformal_spatial_metric[k][l] * conformal_aux_vect[l]; } @@ -2663,9 +3276,12 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup conformal_spatial_christoffel[i][k][l] = 0.0; for (int m = 0; m < 3; m++) { - conformal_spatial_christoffel[i][k][l] += inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[l][m][k]; - conformal_spatial_christoffel[i][k][l] += inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[k][m][l]; - conformal_spatial_christoffel[i][k][l] -= inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[m][k][l]; + conformal_spatial_christoffel[i][k][l] += + inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[l][m][k]; + conformal_spatial_christoffel[i][k][l] += + inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[k][m][l]; + conformal_spatial_christoffel[i][k][l] -= + inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[m][k][l]; } } } @@ -2676,7 +3292,8 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup conformal_lapse_der_raised[k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_lapse_der_raised[k] += inv_conformal_spatial_metric[k][l] * conformal_lapse_der[l]; + conformal_lapse_der_raised[k] += + inv_conformal_spatial_metric[k][l] * conformal_lapse_der[l]; } } @@ -2695,7 +3312,8 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup Y_tensor[i][j] = 2.0 * conformal_fact_der2[i][j]; for (int k = 0; k < 3; k++) { - Y_tensor[i][j] += 2.0 * conformal_spatial_metric[i][j] * conformal_fact_der_raised[k] * conformal_fact_der[k]; + Y_tensor[i][j] += 2.0 * conformal_spatial_metric[i][j] * conformal_fact_der_raised[k] * + conformal_fact_der[k]; } for (int r = 0; r < 3; r++) { @@ -2719,12 +3337,18 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup double conformal_spatial_metric_source[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_spatial_metric_source[i][j] = -2.0 * conformal_lapse * (conformal_extrinsic_curvature[i][j] / (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); - conformal_spatial_metric_source[i][j] += 2.0 * conformal_lapse * conformal_symmetrized_shift[i][j]; + conformal_spatial_metric_source[i][j] = + -2.0 * conformal_lapse * + (conformal_extrinsic_curvature[i][j] / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); + conformal_spatial_metric_source[i][j] += + 2.0 * conformal_lapse * conformal_symmetrized_shift[i][j]; for (int r = 0; r < 3; r++) { - conformal_spatial_metric_source[i][j] += 2.0 * conformal_shift_vect[r] * conformal_spatial_metric_der[r][i][j]; - conformal_spatial_metric_source[i][j] += 4.0 * conformal_shift_vect[r] * conformal_fact_der[r] * conformal_spatial_metric[i][j]; + conformal_spatial_metric_source[i][j] += + 2.0 * conformal_shift_vect[r] * conformal_spatial_metric_der[r][i][j]; + conformal_spatial_metric_source[i][j] += + 4.0 * conformal_shift_vect[r] * conformal_fact_der[r] * conformal_spatial_metric[i][j]; } } } @@ -2740,64 +3364,103 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup conformal_extrinsic_curvature_source[i][j] = 0.0; for (int r = 0; r < 3; r++) { - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_extrinsic_curvature[i][r] * conformal_shift_vect_der[j][r]; - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_extrinsic_curvature[j][r] * conformal_shift_vect_der[i][r]; - conformal_extrinsic_curvature_source[i][j] -= 2.0 * conformal_extrinsic_curvature[i][j] * conformal_shift_vect_der[r][r]; + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_extrinsic_curvature[i][r] * conformal_shift_vect_der[j][r]; + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_extrinsic_curvature[j][r] * conformal_shift_vect_der[i][r]; + conformal_extrinsic_curvature_source[i][j] -= + 2.0 * conformal_extrinsic_curvature[i][j] * conformal_shift_vect_der[r][r]; } for (int k = 0; k < 3; k++) { - conformal_extrinsic_curvature_source[i][j] -= (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[i][k] * conformal_extrinsic_curvature[k][j]) / + conformal_extrinsic_curvature_source[i][j] -= + (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[i][k] * + conformal_extrinsic_curvature[k][j]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_extrinsic_curvature_source[i][j] += (conformal_lapse * conformal_extrinsic_curvature_trace * conformal_extrinsic_curvature[i][j]) / + conformal_extrinsic_curvature_source[i][j] += + (conformal_lapse * conformal_extrinsic_curvature_trace * + conformal_extrinsic_curvature[i][j]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); for (int r = 0; r < 3; r++) { - conformal_extrinsic_curvature_source[i][j] -= conformal_lapse * conformal_spatial_christoffel[k][r][i] * conformal_spatial_christoffel[r][k][j]; - - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_lapse * conformal_spatial_metric_der_raised3[i][k][r] * conformal_spatial_metric_der_raised3[r][j][k]; - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_lapse * conformal_spatial_metric_der_raised3[j][k][r] * conformal_spatial_metric_der_raised3[r][i][k]; - conformal_extrinsic_curvature_source[i][j] += conformal_lapse * conformal_spatial_christoffel[k][k][r] * conformal_spatial_christoffel[r][i][j]; - - conformal_extrinsic_curvature_source[i][j] -= conformal_lapse * (2.0 * conformal_spatial_metric_der_raised3[k][r][k] - conformal_lapse_der[r]) * - (conformal_spatial_metric_der_raised3[i][j][r] + conformal_spatial_metric_der_raised3[j][i][r]); + conformal_extrinsic_curvature_source[i][j] -= conformal_lapse * + conformal_spatial_christoffel[k][r][i] * + conformal_spatial_christoffel[r][k][j]; + + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_lapse * conformal_spatial_metric_der_raised3[i][k][r] * + conformal_spatial_metric_der_raised3[r][j][k]; + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_lapse * conformal_spatial_metric_der_raised3[j][k][r] * + conformal_spatial_metric_der_raised3[r][i][k]; + conformal_extrinsic_curvature_source[i][j] += conformal_lapse * + conformal_spatial_christoffel[k][k][r] * + conformal_spatial_christoffel[r][i][j]; + + conformal_extrinsic_curvature_source[i][j] -= + conformal_lapse * + (2.0 * conformal_spatial_metric_der_raised3[k][r][k] - conformal_lapse_der[r]) * + (conformal_spatial_metric_der_raised3[i][j][r] + + conformal_spatial_metric_der_raised3[j][i][r]); } - conformal_extrinsic_curvature_source[i][j] += conformal_lapse * conformal_lapse_der[i] * (conformal_aux_vect[j] - (0.5 * conformal_spatial_metric_der_raised3[j][k][k])); - conformal_extrinsic_curvature_source[i][j] += conformal_lapse * conformal_lapse_der[j] * (conformal_aux_vect[i] - (0.5 * conformal_spatial_metric_der_raised3[i][k][k])); + conformal_extrinsic_curvature_source[i][j] += + conformal_lapse * conformal_lapse_der[i] * + (conformal_aux_vect[j] - (0.5 * conformal_spatial_metric_der_raised3[j][k][k])); + conformal_extrinsic_curvature_source[i][j] += + conformal_lapse * conformal_lapse_der[j] * + (conformal_aux_vect[i] - (0.5 * conformal_spatial_metric_der_raised3[i][k][k])); - conformal_extrinsic_curvature_source[i][j] -= conformal_lapse * evolution_func * conformal_aux_vect_raised[k] * conformal_spatial_metric_der[k][i][j]; + conformal_extrinsic_curvature_source[i][j] -= conformal_lapse * evolution_func * + conformal_aux_vect_raised[k] * + conformal_spatial_metric_der[k][i][j]; } for (int k = 0; k < 3; k++) { for (int r = 0; r < 3; r++) { for (int s = 0; s < 3; s++) { - conformal_extrinsic_curvature_source[i][j] -= (0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * - conformal_spatial_metric_der_lowered1[k][r][s] * conformal_spatial_christoffel[k][r][s]; - conformal_extrinsic_curvature_source[i][j] += (0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * - conformal_spatial_metric_der_raised3[k][r][r] * conformal_spatial_metric_der_lowered3[k][s][s]; + conformal_extrinsic_curvature_source[i][j] -= + (0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * + conformal_spatial_metric_der_lowered1[k][r][s] * + conformal_spatial_christoffel[k][r][s]; + conformal_extrinsic_curvature_source[i][j] += + (0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * + conformal_spatial_metric_der_raised3[k][r][r] * + conformal_spatial_metric_der_lowered3[k][s][s]; } } - conformal_extrinsic_curvature_source[i][j] -= (0.5 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * conformal_aux_vect_raised[k] * conformal_lapse_der[k]; + conformal_extrinsic_curvature_source[i][j] -= + (0.5 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * + conformal_aux_vect_raised[k] * conformal_lapse_der[k]; } for (int r = 0; r < 3; r++) { for (int s = 0; s < 3; s++) { - conformal_extrinsic_curvature_source[i][j] += ((0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * - conformal_extrinsic_curvature_raised[r][s] * conformal_extrinsic_curvature[r][s]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_extrinsic_curvature_source[i][j] += + ((0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * + conformal_extrinsic_curvature_raised[r][s] * conformal_extrinsic_curvature[r][s]) / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); } } - conformal_extrinsic_curvature_source[i][j] -= ((0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * - (conformal_extrinsic_curvature_trace * conformal_extrinsic_curvature_trace)) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_extrinsic_curvature_source[i][j] -= + ((0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * + (conformal_extrinsic_curvature_trace * conformal_extrinsic_curvature_trace)) / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); conformal_extrinsic_curvature_source[i][j] -= Y_tensor[i][j]; - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_lapse_der[i] * conformal_fact_der[j]; - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_lapse_der[j] * conformal_fact_der[i]; - + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_lapse_der[i] * conformal_fact_der[j]; + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_lapse_der[j] * conformal_fact_der[i]; + for (int k = 0; k < 3; k++) { - conformal_extrinsic_curvature_source[i][j] += conformal_spatial_metric[i][j] * (evolution_func - 1.0) * Y_tensor_mixed[k][k]; - conformal_extrinsic_curvature_source[i][j] -= 2.0 * conformal_spatial_metric[i][j] * conformal_lapse_der_raised[k] * conformal_fact_der[k]; + conformal_extrinsic_curvature_source[i][j] += + conformal_spatial_metric[i][j] * (evolution_func - 1.0) * Y_tensor_mixed[k][k]; + conformal_extrinsic_curvature_source[i][j] -= 2.0 * conformal_spatial_metric[i][j] * + conformal_lapse_der_raised[k] * + conformal_fact_der[k]; } } } @@ -2807,52 +3470,72 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup conformal_aux_vect_source[i] = 0.0; for (int r = 0; r < 3; r++) { - conformal_aux_vect_source[i] += (conformal_lapse * conformal_lapse_der[r] * conformal_extrinsic_curvature_mixed[i][r]) / + conformal_aux_vect_source[i] += + (conformal_lapse * conformal_lapse_der[r] * conformal_extrinsic_curvature_mixed[i][r]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - + if (i == r) { - conformal_aux_vect_source[i] -= (conformal_lapse * conformal_lapse_der[r] * conformal_extrinsic_curvature_trace) / + conformal_aux_vect_source[i] -= + (conformal_lapse * conformal_lapse_der[r] * conformal_extrinsic_curvature_trace) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); } for (int s = 0; s < 3; s++) { - conformal_aux_vect_source[i] += (conformal_lapse * conformal_extrinsic_curvature_mixed[s][r] * conformal_spatial_metric_der_raised3[i][r][s]) / + conformal_aux_vect_source[i] += + (conformal_lapse * conformal_extrinsic_curvature_mixed[s][r] * + conformal_spatial_metric_der_raised3[i][r][s]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_aux_vect_source[i] -= (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[s][r] * conformal_spatial_metric_der_raised3[r][i][s]) / + conformal_aux_vect_source[i] -= + (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[s][r] * + conformal_spatial_metric_der_raised3[r][i][s]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_aux_vect_source[i] -= (conformal_lapse * conformal_extrinsic_curvature_mixed[i][r] * conformal_spatial_metric_der_raised3[r][s][s]) / + conformal_aux_vect_source[i] -= + (conformal_lapse * conformal_extrinsic_curvature_mixed[i][r] * + conformal_spatial_metric_der_raised3[r][s][s]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_aux_vect_source[i] += (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[i][r] * conformal_spatial_metric_der_raised3[s][r][s]) / + conformal_aux_vect_source[i] += + (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[i][r] * + conformal_spatial_metric_der_raised3[s][r][s]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_aux_vect_source[i] -= (6.0 * conformal_lapse * conformal_fact_der[r] * conformal_extrinsic_curvature_mixed[s][r]) / + conformal_aux_vect_source[i] -= + (6.0 * conformal_lapse * conformal_fact_der[r] * + conformal_extrinsic_curvature_mixed[s][r]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); if (s == r) { - conformal_aux_vect_source[i] += (2.0 * conformal_lapse * conformal_fact_der[r] * conformal_extrinsic_curvature_trace) / + conformal_aux_vect_source[i] += + (2.0 * conformal_lapse * conformal_fact_der[r] * conformal_extrinsic_curvature_trace + ) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); } } - conformal_aux_vect_source[i] += 2.0 * conformal_shift_vect_der[i][r] * conformal_aux_vect[r]; + conformal_aux_vect_source[i] += + 2.0 * conformal_shift_vect_der[i][r] * conformal_aux_vect[r]; if (i == r) { - conformal_aux_vect_source[i] -= 2.0 * conformal_shift_vect_der_trace * conformal_aux_vect[r]; + conformal_aux_vect_source[i] -= + 2.0 * conformal_shift_vect_der_trace * conformal_aux_vect[r]; } for (int s = 0; s < 3; s++) { - conformal_aux_vect_source[i] += 2.0 * conformal_spatial_metric_der_raised3[r][i][s] * conformal_shift_vect_der_switched[r][s]; + conformal_aux_vect_source[i] += 2.0 * conformal_spatial_metric_der_raised3[r][i][s] * + conformal_shift_vect_der_switched[r][s]; if (i == s) { for (int j = 0; j < 3; j++) { - conformal_aux_vect_source[i] -= 2.0 * conformal_spatial_metric_der_raised1[j][j][r] * conformal_shift_vect_der_switched[r][s]; + conformal_aux_vect_source[i] -= 2.0 * conformal_spatial_metric_der_raised1[j][j][r] * + conformal_shift_vect_der_switched[r][s]; } } } - conformal_aux_vect_source[i] += 4.0 * conformal_shift_vect_der[i][r] * conformal_fact_der[r]; - conformal_aux_vect_source[i] -= 4.0 * conformal_shift_vect_der_trace * conformal_fact_der[i]; + conformal_aux_vect_source[i] += + 4.0 * conformal_shift_vect_der[i][r] * conformal_fact_der[r]; + conformal_aux_vect_source[i] -= + 4.0 * conformal_shift_vect_der_trace * conformal_fact_der[i]; } } @@ -2860,18 +3543,27 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup fluid_new[i] = fluid_old[i]; } - fluid_new[0] += dt * conformal_spatial_metric_source[0][0]; fluid_new[1] += dt * conformal_spatial_metric_source[0][1]; fluid_new[2] += dt * conformal_spatial_metric_source[0][2]; - fluid_new[3] += dt * conformal_spatial_metric_source[1][0]; fluid_new[4] += dt * conformal_spatial_metric_source[1][1]; fluid_new[5] += dt * conformal_spatial_metric_source[1][2]; - fluid_new[6] += dt * conformal_spatial_metric_source[2][0]; fluid_new[7] += dt * conformal_spatial_metric_source[2][1]; fluid_new[8] += dt * conformal_spatial_metric_source[2][2]; + fluid_new[0] += dt * conformal_spatial_metric_source[0][0]; + fluid_new[1] += dt * conformal_spatial_metric_source[0][1]; + fluid_new[2] += dt * conformal_spatial_metric_source[0][2]; + fluid_new[3] += dt * conformal_spatial_metric_source[1][0]; + fluid_new[4] += dt * conformal_spatial_metric_source[1][1]; + fluid_new[5] += dt * conformal_spatial_metric_source[1][2]; + fluid_new[6] += dt * conformal_spatial_metric_source[2][0]; + fluid_new[7] += dt * conformal_spatial_metric_source[2][1]; + fluid_new[8] += dt * conformal_spatial_metric_source[2][2]; fluid_new[9] += dt * conformal_lapse_source; - fluid_new[10] += dt * conformal_extrinsic_curvature_source[0][0]; fluid_new[11] += dt * conformal_extrinsic_curvature_source[0][1]; fluid_new[12] += - dt * conformal_extrinsic_curvature_source[0][2]; - fluid_new[13] += dt * conformal_extrinsic_curvature_source[1][0]; fluid_new[14] += dt * conformal_extrinsic_curvature_source[1][1]; fluid_new[15] += - dt * conformal_extrinsic_curvature_source[1][2]; - fluid_new[16] += dt * conformal_extrinsic_curvature_source[2][0]; fluid_new[17] += dt * conformal_extrinsic_curvature_source[2][1]; fluid_new[18] += - dt * conformal_extrinsic_curvature_source[2][2]; + fluid_new[10] += dt * conformal_extrinsic_curvature_source[0][0]; + fluid_new[11] += dt * conformal_extrinsic_curvature_source[0][1]; + fluid_new[12] += dt * conformal_extrinsic_curvature_source[0][2]; + fluid_new[13] += dt * conformal_extrinsic_curvature_source[1][0]; + fluid_new[14] += dt * conformal_extrinsic_curvature_source[1][1]; + fluid_new[15] += dt * conformal_extrinsic_curvature_source[1][2]; + fluid_new[16] += dt * conformal_extrinsic_curvature_source[2][0]; + fluid_new[17] += dt * conformal_extrinsic_curvature_source[2][1]; + fluid_new[18] += dt * conformal_extrinsic_curvature_source[2][2]; fluid_new[49] += dt * conformal_aux_vect_source[0]; fluid_new[50] += dt * conformal_aux_vect_source[1]; @@ -2882,22 +3574,25 @@ explicit_vacuum_einstein_conformal_source_update_euler(const gkyl_moment_em_coup fluid_new[i] = 0.0; } } - } - else { + } else { for (int i = 0; i < 77; i++) { fluid_new[i] = fluid_old[i]; } } } -void -explicit_vacuum_einstein_conformal_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]) +void explicit_vacuum_einstein_conformal_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; double excision_threshold = mom_em->vacuum_einstein_conformal_excision_threshold; - enum gkyl_spacetime_slicing spacetime_slicing = mom_em->vacuum_einstein_conformal_spacetime_slicing; - enum gkyl_spacetime_evolution spacetime_evolution = mom_em->vacuum_einstein_conformal_spacetime_evolution; + enum gkyl_spacetime_slicing spacetime_slicing = + mom_em->vacuum_einstein_conformal_spacetime_slicing; + enum gkyl_spacetime_evolution spacetime_evolution = + mom_em->vacuum_einstein_conformal_spacetime_evolution; for (int i = 0; i < nfluids; i++) { double *f = fluid_s[i]; @@ -2908,26 +3603,35 @@ explicit_vacuum_einstein_conformal_source_update(const gkyl_moment_em_coupling* f_old[j] = f[j]; } - explicit_vacuum_einstein_conformal_source_update_euler(mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr, dt, f_old, f_new); + explicit_vacuum_einstein_conformal_source_update_euler( + mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr, dt, f_old, f_new + ); for (int j = 0; j < 77; j++) { f_stage1[j] = f_new[j]; } - explicit_vacuum_einstein_conformal_source_update_euler(mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr + dt, dt, f_stage1, f_new); + explicit_vacuum_einstein_conformal_source_update_euler( + mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr + dt, dt, f_stage1, + f_new + ); for (int j = 0; j < 77; j++) { f_stage2[j] = (0.75 * f_old[j]) + (0.25 * f_new[j]); } - explicit_vacuum_einstein_conformal_source_update_euler(mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr + (0.5 * dt), dt, f_stage2, f_new); + explicit_vacuum_einstein_conformal_source_update_euler( + mom_em, excision_threshold, spacetime_slicing, spacetime_evolution, t_curr + (0.5 * dt), dt, + f_stage2, f_new + ); for (int j = 0; j < 77; j++) { f[j] = ((1.0 / 3.0) * f_old[j]) + ((2.0 / 3.0) * f_new[j]); } } } -void -explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double gas_gamma, double t_curr, const double dt, - double* fluid_old, double* fluid_new) +void explicit_gr_mhd_source_update_euler( + const gkyl_moment_em_coupling *mom_em, const double gas_gamma, double t_curr, const double dt, + double *fluid_old, double *fluid_new +) { double lapse = fluid_old[9]; double shift_x = fluid_old[10]; @@ -2935,15 +3639,24 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double shift_z = fluid_old[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = fluid_old[13]; spatial_metric[0][1] = fluid_old[14]; spatial_metric[0][2] = fluid_old[15]; - spatial_metric[1][0] = fluid_old[16]; spatial_metric[1][1] = fluid_old[17]; spatial_metric[1][2] = fluid_old[18]; - spatial_metric[2][0] = fluid_old[19]; spatial_metric[2][1] = fluid_old[20]; spatial_metric[2][2] = fluid_old[21]; + spatial_metric[0][0] = fluid_old[13]; + spatial_metric[0][1] = fluid_old[14]; + spatial_metric[0][2] = fluid_old[15]; + spatial_metric[1][0] = fluid_old[16]; + spatial_metric[1][1] = fluid_old[17]; + spatial_metric[1][2] = fluid_old[18]; + spatial_metric[2][0] = fluid_old[19]; + spatial_metric[2][1] = fluid_old[20]; + spatial_metric[2][2] = fluid_old[21]; double inv_spatial_metric[3][3]; - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -2974,8 +3687,7 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -2983,15 +3695,22 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spatial_metric[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + inv_spatial_metric[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = fluid_old[22]; extrinsic_curvature[0][1] = fluid_old[23]; extrinsic_curvature[0][2] = fluid_old[24]; - extrinsic_curvature[1][0] = fluid_old[25]; extrinsic_curvature[1][1] = fluid_old[26]; extrinsic_curvature[1][2] = fluid_old[27]; - extrinsic_curvature[2][0] = fluid_old[28]; extrinsic_curvature[2][1] = fluid_old[29]; extrinsic_curvature[2][2] = fluid_old[30]; + extrinsic_curvature[0][0] = fluid_old[22]; + extrinsic_curvature[0][1] = fluid_old[23]; + extrinsic_curvature[0][2] = fluid_old[24]; + extrinsic_curvature[1][0] = fluid_old[25]; + extrinsic_curvature[1][1] = fluid_old[26]; + extrinsic_curvature[1][2] = fluid_old[27]; + extrinsic_curvature[2][0] = fluid_old[28]; + extrinsic_curvature[2][1] = fluid_old[29]; + extrinsic_curvature[2][2] = fluid_old[30]; bool in_excision_region = false; if (fluid_old[31] < pow(10.0, -8.0)) { @@ -3010,7 +3729,9 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double mag_z = fluid_old[7] / sqrt(spatial_det); double cov_mom[3]; - cov_mom[0] = momx; cov_mom[1] = momy; cov_mom[2] = momz; + cov_mom[0] = momx; + cov_mom[1] = momy; + cov_mom[2] = momz; double mom[3]; for (int i = 0; i < 3; i++) { @@ -3027,7 +3748,9 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const } double mag[3]; - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double cov_mag[3]; for (int i = 0; i < 3; i++) { @@ -3037,7 +3760,7 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const cov_mag[i] += spatial_metric[i][j] * mag[j]; } } - + double mag_sq = 0.0; for (int i = 0; i < 3; i++) { mag_sq += mag[i] * cov_mag[i]; @@ -3056,10 +3779,12 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double d = 0.5 * ((M_sq * mag_sq) - (tau_star * tau_star)); double phi = acos((1.0 / a) * sqrt((27.0 * d) / (4.0 * a))); - double epsilon1 = ((1.0 / 3.0) * a) - ((2.0 / 3.0) * a * cos(((2.0 / 3.0) * phi) + ((2.0 / 3.0) * M_PI))); + double epsilon1 = + ((1.0 / 3.0) * a) - ((2.0 / 3.0) * a * cos(((2.0 / 3.0) * phi) + ((2.0 / 3.0) * M_PI))); z = epsilon1 - mag_sq; - double v_sq = ((M_sq * (z * z)) + ((tau_star * tau_star) * (mag_sq + (2.0 * z)))) / ((z * z) * (mag_sq + z) * (mag_sq + z)); + double v_sq = ((M_sq * (z * z)) + ((tau_star * tau_star) * (mag_sq + (2.0 * z)))) / + ((z * z) * (mag_sq + z) * (mag_sq + z)); W = 1.0 / sqrt(1.0 - v_sq); rho = D / W; double h = z / (W * W * rho); @@ -3068,8 +3793,7 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const if (fabs(p_guess - p_new) < pow(10.0, -15.0)) { iter = 100; - } - else { + } else { iter += 1; p_guess = p_new; } @@ -3107,7 +3831,9 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double spacetime_vel[4]; spacetime_vel[0] = W / lapse; @@ -3139,14 +3865,15 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double p_star = p_new + (0.5 * b_sq); double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } @@ -3159,7 +3886,9 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const double stress_energy[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - stress_energy[i][j] = (rho * h_star * spacetime_vel[i] * spacetime_vel[j]) + (p_star * inv_spacetime_metric[i][j]) - (spacetime_b[i] * spacetime_b[j]); + stress_energy[i][j] = (rho * h_star * spacetime_vel[i] * spacetime_vel[j]) + + (p_star * inv_spacetime_metric[i][j]) - + (spacetime_b[i] * spacetime_b[j]); } } @@ -3173,22 +3902,46 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const lapse_der[2] = fluid_old[34]; double shift_der[3][3]; - shift_der[0][0] = fluid_old[35]; shift_der[0][1] = fluid_old[36]; shift_der[0][2] = fluid_old[37]; - shift_der[1][0] = fluid_old[38]; shift_der[1][1] = fluid_old[39]; shift_der[1][2] = fluid_old[40]; - shift_der[2][0] = fluid_old[41]; shift_der[2][1] = fluid_old[42]; shift_der[2][2] = fluid_old[43]; + shift_der[0][0] = fluid_old[35]; + shift_der[0][1] = fluid_old[36]; + shift_der[0][2] = fluid_old[37]; + shift_der[1][0] = fluid_old[38]; + shift_der[1][1] = fluid_old[39]; + shift_der[1][2] = fluid_old[40]; + shift_der[2][0] = fluid_old[41]; + shift_der[2][1] = fluid_old[42]; + shift_der[2][2] = fluid_old[43]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = fluid_old[44]; spatial_metric_der[0][0][1] = fluid_old[45]; spatial_metric_der[0][0][2] = fluid_old[46]; - spatial_metric_der[0][1][0] = fluid_old[47]; spatial_metric_der[0][1][1] = fluid_old[48]; spatial_metric_der[0][1][2] = fluid_old[49]; - spatial_metric_der[0][2][0] = fluid_old[50]; spatial_metric_der[0][2][1] = fluid_old[51]; spatial_metric_der[0][2][2] = fluid_old[52]; - - spatial_metric_der[1][0][0] = fluid_old[53]; spatial_metric_der[1][0][1] = fluid_old[54]; spatial_metric_der[1][0][2] = fluid_old[55]; - spatial_metric_der[1][1][0] = fluid_old[56]; spatial_metric_der[1][1][1] = fluid_old[57]; spatial_metric_der[1][1][2] = fluid_old[58]; - spatial_metric_der[1][2][0] = fluid_old[59]; spatial_metric_der[1][2][1] = fluid_old[60]; spatial_metric_der[1][2][2] = fluid_old[61]; - - spatial_metric_der[2][0][0] = fluid_old[62]; spatial_metric_der[2][0][1] = fluid_old[63]; spatial_metric_der[2][0][2] = fluid_old[64]; - spatial_metric_der[2][1][0] = fluid_old[65]; spatial_metric_der[2][1][1] = fluid_old[66]; spatial_metric_der[2][1][2] = fluid_old[67]; - spatial_metric_der[2][2][0] = fluid_old[68]; spatial_metric_der[2][2][1] = fluid_old[69]; spatial_metric_der[2][2][2] = fluid_old[70]; + spatial_metric_der[0][0][0] = fluid_old[44]; + spatial_metric_der[0][0][1] = fluid_old[45]; + spatial_metric_der[0][0][2] = fluid_old[46]; + spatial_metric_der[0][1][0] = fluid_old[47]; + spatial_metric_der[0][1][1] = fluid_old[48]; + spatial_metric_der[0][1][2] = fluid_old[49]; + spatial_metric_der[0][2][0] = fluid_old[50]; + spatial_metric_der[0][2][1] = fluid_old[51]; + spatial_metric_der[0][2][2] = fluid_old[52]; + + spatial_metric_der[1][0][0] = fluid_old[53]; + spatial_metric_der[1][0][1] = fluid_old[54]; + spatial_metric_der[1][0][2] = fluid_old[55]; + spatial_metric_der[1][1][0] = fluid_old[56]; + spatial_metric_der[1][1][1] = fluid_old[57]; + spatial_metric_der[1][1][2] = fluid_old[58]; + spatial_metric_der[1][2][0] = fluid_old[59]; + spatial_metric_der[1][2][1] = fluid_old[60]; + spatial_metric_der[1][2][2] = fluid_old[61]; + + spatial_metric_der[2][0][0] = fluid_old[62]; + spatial_metric_der[2][0][1] = fluid_old[63]; + spatial_metric_der[2][0][2] = fluid_old[64]; + spatial_metric_der[2][1][0] = fluid_old[65]; + spatial_metric_der[2][1][1] = fluid_old[66]; + spatial_metric_der[2][1][2] = fluid_old[67]; + spatial_metric_der[2][2][0] = fluid_old[68]; + spatial_metric_der[2][2][1] = fluid_old[69]; + spatial_metric_der[2][2][2] = fluid_old[70]; for (int i = 0; i < 75; i++) { fluid_new[i] = fluid_old[i]; @@ -3197,42 +3950,52 @@ explicit_gr_mhd_source_update_euler(const gkyl_moment_em_coupling* mom_em, const // Energy density source. for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - fluid_new[4] += dt * (lapse * sqrt(spatial_det)) * (stress_energy[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); - fluid_new[4] += dt * (lapse * sqrt(spatial_det)) * (2.0 * stress_energy[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); - fluid_new[4] += dt * (lapse * sqrt(spatial_det)) * (stress_energy[i + 1][j + 1] * extrinsic_curvature[i][j]); + fluid_new[4] += dt * (lapse * sqrt(spatial_det)) * + (stress_energy[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); + fluid_new[4] += dt * (lapse * sqrt(spatial_det)) * + (2.0 * stress_energy[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); + fluid_new[4] += dt * (lapse * sqrt(spatial_det)) * + (stress_energy[i + 1][j + 1] * extrinsic_curvature[i][j]); } - fluid_new[4] -= dt * (lapse * sqrt(spatial_det)) * (stress_energy[0][0] * shift[i] * lapse_der[i]); + fluid_new[4] -= + dt * (lapse * sqrt(spatial_det)) * (stress_energy[0][0] * shift[i] * lapse_der[i]); fluid_new[4] -= dt * (lapse * sqrt(spatial_det)) * (stress_energy[0][i + 1] * lapse_der[i]); } // Momentum density sources. for (int j = 0; j < 3; j++) { - fluid_new[1 + j] -= dt * (lapse * sqrt(spatial_det)) * (stress_energy[0][0] * lapse * lapse_der[j]); + fluid_new[1 + j] -= + dt * (lapse * sqrt(spatial_det)) * (stress_energy[0][0] * lapse * lapse_der[j]); for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - fluid_new[1 + j] += dt * (lapse * sqrt(spatial_det)) * (0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]); - fluid_new[1 + j] += dt * (lapse * sqrt(spatial_det)) * (0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]); + fluid_new[1 + j] += + dt * (lapse * sqrt(spatial_det)) * + (0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]); + fluid_new[1 + j] += dt * (lapse * sqrt(spatial_det)) * + (0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]); } fluid_new[1 + j] += dt * (lapse * sqrt(spatial_det)) * ((mom[k] / lapse) * shift_der[j][k]); for (int i = 0; i < 3; i++) { - fluid_new[1 + j] += dt * (lapse * sqrt(spatial_det)) * (stress_energy[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); + fluid_new[1 + j] += dt * (lapse * sqrt(spatial_det)) * + (stress_energy[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); } } } - } - else { + } else { for (int i = 0; i < 75; i++) { fluid_new[i] = fluid_old[i]; } } } -void -explicit_gr_mhd_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES]) +void explicit_gr_mhd_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; @@ -3264,9 +4027,10 @@ explicit_gr_mhd_source_update(const gkyl_moment_em_coupling* mom_em, double t_cu } } -void -explicit_e_field_source_update_euler(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, double e_field_old[3], double* e_field_new, - double* fluid_s[GKYL_MAX_SPECIES], const double* app_current) +void explicit_e_field_source_update_euler( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, double e_field_old[3], + double *e_field_new, double *fluid_s[GKYL_MAX_SPECIES], const double *app_current +) { int nfluids = mom_em->nfluids; @@ -3296,40 +4060,51 @@ explicit_e_field_source_update_euler(const gkyl_moment_em_coupling* mom_em, doub double vy = uy / gamma; double vz = uz / gamma; - e_field_new[0] += dt * (-(1.0 / epsilon0) * (q/m) * rho * vx); - e_field_new[1] += dt * (-(1.0 / epsilon0) * (q/m) * rho * vy); - e_field_new[2] += dt * (-(1.0 / epsilon0) * (q/m) * rho * vz); + e_field_new[0] += dt * (-(1.0 / epsilon0) * (q / m) * rho * vx); + e_field_new[1] += dt * (-(1.0 / epsilon0) * (q / m) * rho * vy); + e_field_new[2] += dt * (-(1.0 / epsilon0) * (q / m) * rho * vz); } } } -void -explicit_e_field_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, double* fluid_s[GKYL_MAX_SPECIES], double* em, - const double* app_current, const double* app_current1, const double* app_current2, const double* ext_em) +void explicit_e_field_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double *fluid_s[GKYL_MAX_SPECIES], double *em, const double *app_current, + const double *app_current1, const double *app_current2, const double *ext_em +) { double e_field_new[3], e_field_stage1[3], e_field_stage2[3]; double e_field_old[3]; - e_field_old[0] = em[0]; e_field_old[1] = em[1]; e_field_old[2] = em[2]; + e_field_old[0] = em[0]; + e_field_old[1] = em[1]; + e_field_old[2] = em[2]; - explicit_e_field_source_update_euler(mom_em, t_curr, dt, e_field_old, e_field_new, fluid_s, app_current); + explicit_e_field_source_update_euler( + mom_em, t_curr, dt, e_field_old, e_field_new, fluid_s, app_current + ); e_field_stage1[0] = e_field_new[0]; e_field_stage1[1] = e_field_new[1]; e_field_stage1[2] = e_field_new[2]; - explicit_e_field_source_update_euler(mom_em, t_curr + dt, dt, e_field_stage1, e_field_new, fluid_s, app_current1); + explicit_e_field_source_update_euler( + mom_em, t_curr + dt, dt, e_field_stage1, e_field_new, fluid_s, app_current1 + ); e_field_stage2[0] = (0.75 * e_field_old[0]) + (0.25 * e_field_new[0]); e_field_stage2[1] = (0.75 * e_field_old[1]) + (0.25 * e_field_new[1]); e_field_stage2[2] = (0.75 * e_field_old[2]) + (0.25 * e_field_new[2]); - explicit_e_field_source_update_euler(mom_em, t_curr + (0.5 * dt), dt, e_field_stage2, e_field_new, fluid_s, app_current2); + explicit_e_field_source_update_euler( + mom_em, t_curr + (0.5 * dt), dt, e_field_stage2, e_field_new, fluid_s, app_current2 + ); em[0] = ((1.0 / 3.0) * e_field_old[0]) + ((2.0 / 3.0) * e_field_new[0]); em[1] = ((1.0 / 3.0) * e_field_old[1]) + ((2.0 / 3.0) * e_field_new[1]); em[2] = ((1.0 / 3.0) * e_field_old[2]) + ((2.0 / 3.0) * e_field_new[2]); } -void -explicit_higuera_cary_push(double* vel, const double q, const double m, const double dt, const double c, const double e_field[3], - const double b_field[3]) +void explicit_higuera_cary_push( + double *vel, const double q, const double m, const double dt, const double c, + const double e_field[3], const double b_field[3] +) { const double q_over_m = (0.5 * dt) * (q / m); const double Ex = q_over_m * e_field[0]; @@ -3343,30 +4118,41 @@ explicit_higuera_cary_push(double* vel, const double q, const double m, const do const double vel_y_minus = vel[1] + Ey; const double vel_z_minus = vel[2] + Ez; - const double vel_star = (vel_x_minus * (Bx / c)) + (vel_y_minus * (By / c)) + (vel_z_minus * (Bz / c)); - const double gamma_minus = sqrt(1.0 + (((vel_x_minus * vel_x_minus) + (vel_y_minus * vel_y_minus) + (vel_z_minus * vel_z_minus)) / (c * c))); + const double vel_star = + (vel_x_minus * (Bx / c)) + (vel_y_minus * (By / c)) + (vel_z_minus * (Bz / c)); + const double gamma_minus = sqrt( + 1.0 + + (((vel_x_minus * vel_x_minus) + (vel_y_minus * vel_y_minus) + (vel_z_minus * vel_z_minus)) / + (c * c)) + ); const double dot_tau_tau = (Bx * Bx) + (By * By) + (Bz * Bz); const double sigma = (gamma_minus * gamma_minus) - dot_tau_tau; - const double gamma_new = sqrt(0.5 * (sigma + sqrt((sigma * sigma) + (4.0 * (dot_tau_tau + (vel_star * vel_star)))))); + const double gamma_new = + sqrt(0.5 * (sigma + sqrt((sigma * sigma) + (4.0 * (dot_tau_tau + (vel_star * vel_star)))))); const double tx = Bx / gamma_new; const double ty = By / gamma_new; const double tz = Bz / gamma_new; - const double s = 1.0 / (1.0 + ((tx * tx) + (ty * ty) + (tz * tz))); + const double s = 1.0 / (1.0 + ((tx * tx) + (ty * ty) + (tz * tz))); const double t_vel_minus = (vel_x_minus * tx) + (vel_y_minus * ty) + (vel_z_minus * tz); - const double vel_x_plus = s * (vel_x_minus + (t_vel_minus * tx) + ((vel_y_minus * tz) - (vel_z_minus * ty))); - const double vel_y_plus = s * (vel_y_minus + (t_vel_minus * ty) + ((vel_z_minus * tx) - (vel_x_minus * tz))); - const double vel_z_plus = s * (vel_z_minus + (t_vel_minus * tz) + ((vel_x_minus * ty) - (vel_y_minus * tx))); + const double vel_x_plus = + s * (vel_x_minus + (t_vel_minus * tx) + ((vel_y_minus * tz) - (vel_z_minus * ty))); + const double vel_y_plus = + s * (vel_y_minus + (t_vel_minus * ty) + ((vel_z_minus * tx) - (vel_x_minus * tz))); + const double vel_z_plus = + s * (vel_z_minus + (t_vel_minus * tz) + ((vel_x_minus * ty) - (vel_y_minus * tx))); vel[0] = vel_x_plus + Ex + ((vel_y_plus * tz) - (vel_z_plus * ty)); vel[1] = vel_y_plus + Ey + ((vel_z_plus * tx) - (vel_x_plus * tz)); vel[2] = vel_z_plus + Ez + ((vel_x_plus * ty) - (vel_y_plus * tx)); } -void -explicit_higuera_cary_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, double* fluid_s[GKYL_MAX_SPECIES], - const double* app_accel_s[GKYL_MAX_SPECIES], double* em, const double* ext_em) +void explicit_higuera_cary_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double *fluid_s[GKYL_MAX_SPECIES], const double *app_accel_s[GKYL_MAX_SPECIES], double *em, + const double *ext_em +) { int nfluids = mom_em->nfluids; @@ -3382,8 +4168,12 @@ explicit_higuera_cary_update(const gkyl_moment_em_coupling* mom_em, double t_cur double Bz = em[5] + ext_em[5]; double e_field[3], b_field[3]; - e_field[0] = Ex; e_field[1] = Ey; e_field[2] = Ez; - b_field[0] = Bx; b_field[1] = By; b_field[2] = Bz; + e_field[0] = Ex; + e_field[1] = Ey; + e_field[2] = Ez; + b_field[0] = Bx; + b_field[1] = By; + b_field[2] = Bz; for (int i = 0; i < nfluids; i++) { double *f = fluid_s[i]; @@ -3407,15 +4197,18 @@ explicit_higuera_cary_update(const gkyl_moment_em_coupling* mom_em, double t_cur } } -void -explicit_source_coupling_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, double* fluid_s[GKYL_MAX_SPECIES], - const double* app_accel_s[GKYL_MAX_SPECIES], double* em, const double* app_current, const double* app_current1, const double* app_current2, - const double* ext_em, int nstrang) +void explicit_source_coupling_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double *fluid_s[GKYL_MAX_SPECIES], const double *app_accel_s[GKYL_MAX_SPECIES], double *em, + const double *app_current, const double *app_current1, const double *app_current2, + const double *ext_em, int nstrang +) { if (nstrang == 0) { - explicit_e_field_source_update(mom_em, t_curr, dt, fluid_s, em, app_current, app_current1, app_current2, ext_em); - } - else if (nstrang == 1) { + explicit_e_field_source_update( + mom_em, t_curr, dt, fluid_s, em, app_current, app_current1, app_current2, ext_em + ); + } else if (nstrang == 1) { explicit_higuera_cary_update(mom_em, t_curr, dt, fluid_s, app_accel_s, em, ext_em); } } diff --git a/moments/zero/sources_implicit.c b/moments/zero/sources_implicit.c index 2435a6af40..b0042a61ae 100644 --- a/moments/zero/sources_implicit.c +++ b/moments/zero/sources_implicit.c @@ -6,9 +6,10 @@ #include #include -void -pressure_tensor_rotate(double q_over_m, double dt, const double* em, const double* ext_em, double p_tensor_old[6], double p_tensor_rhs[6], - double p_tensor_new[6]) +void pressure_tensor_rotate( + double q_over_m, double dt, const double *em, const double *ext_em, double p_tensor_old[6], + double p_tensor_rhs[6], double p_tensor_new[6] +) { double Bx = em[3] + ext_em[3]; double By = em[4] + ext_em[4]; @@ -35,69 +36,200 @@ pressure_tensor_rotate(double q_over_m, double dt, const double* em, const doubl double q_over_m_cu = q_over_m_sq * q_over_m; double q_over_m_qu = q_over_m_cu * q_over_m; - double denom = 1.0 + (5.0 * (Bx_sq + By_sq + Bz_sq) * dt1_sq * q_over_m_sq) + (4.0 * (Bx_sq + By_sq + Bz_sq) * (Bx_sq + By_sq + Bz_sq) * dt1_qu * q_over_m_qu); - - p_tensor_new[0] = 2.0 * (p_tensor_rhs[0] + 2.0 * dt1 * (Bz * p_tensor_rhs[1] - By * p_tensor_rhs[2]) * q_over_m + dt1_sq * (5.0 * Bx_sq * p_tensor_rhs[0] + - 2.0 * Bx * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + Bz_sq * (3.0 * p_tensor_rhs[0] + 2.0 * p_tensor_rhs[3]) - 4.0 * By * Bz * p_tensor_rhs[4] + - By_sq * (3.0 * p_tensor_rhs[0] + 2.0 * p_tensor_rhs[5])) * q_over_m_sq + 2.0 * dt1_cu * (4.0 * Bx_sq * (Bz * p_tensor_rhs[1] - By * p_tensor_rhs[2]) - - (By_sq + Bz_sq) * (-(Bz * p_tensor_rhs[1]) + By * p_tensor_rhs[2]) - 3.0 * Bx * (By_sq * p_tensor_rhs[4] - Bz_sq * p_tensor_rhs[4] + By * Bz * - (-p_tensor_rhs[3] + p_tensor_rhs[5]))) * q_over_m_cu + 2.0 * dt1_qu * (2.0 * Bx_qu * p_tensor_rhs[0] + 4.0 * Bx_cu * (By * p_tensor_rhs[1] + - Bz * p_tensor_rhs[2]) - 2.0 * Bx * (By_sq + Bz_sq) * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + (By_sq + Bz_sq) * (Bz_sq * (p_tensor_rhs[0] + - p_tensor_rhs[3]) - 2.0 * By * Bz * p_tensor_rhs[4] + By_sq * (p_tensor_rhs[0] + p_tensor_rhs[5])) + Bx_sq * (4.0 * By * Bz * p_tensor_rhs[4] + By_sq * (3.0 * - p_tensor_rhs[3] + p_tensor_rhs[5]) + Bz_sq * (p_tensor_rhs[3] + 3.0 * p_tensor_rhs[5]))) * q_over_m_qu) / denom - p_tensor_old[0]; - - p_tensor_new[1] = 2.0 * (p_tensor_rhs[1] + dt1 * (Bx * p_tensor_rhs[2] + Bz * (-p_tensor_rhs[0] + p_tensor_rhs[3]) - By * p_tensor_rhs[4]) * q_over_m + dt1_sq * - (4.0 * Bx_sq * p_tensor_rhs[1] + 4.0 * By_sq * p_tensor_rhs[1] + Bz_sq * p_tensor_rhs[1] + 3.0 * By * Bz * p_tensor_rhs[2] + Bx * (3.0 * Bz * p_tensor_rhs[4] + - By * (p_tensor_rhs[0] + p_tensor_rhs[3] - 2.0 * p_tensor_rhs[5]))) * q_over_m_sq + dt1_cu * (4.0 * Bx_cu * p_tensor_rhs[2] - 2.0 * Bx * (By_sq + Bz_sq) * - p_tensor_rhs[2] + Bz_cu * (-p_tensor_rhs[0] + p_tensor_rhs[3]) - 4.0 * By_cu * p_tensor_rhs[4] + 2.0 * By * Bz_sq * p_tensor_rhs[4] - By_sq * Bz * - (p_tensor_rhs[0] - 4.0 * p_tensor_rhs[3] + 3.0 * p_tensor_rhs[5]) + Bx_sq * (2.0 * By * p_tensor_rhs[4] + Bz * (-4.0 * p_tensor_rhs[0] + p_tensor_rhs[3] + - 3.0 * p_tensor_rhs[5]))) * q_over_m_cu + 2.0 * Bx * By * dt1_qu * (6.0 * Bx * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + 6.0 * By * Bz * p_tensor_rhs[4] - - Bz_sq * (p_tensor_rhs[0] + p_tensor_rhs[3] - 2.0 * p_tensor_rhs[5]) + Bx_sq * (2.0 * p_tensor_rhs[0] - p_tensor_rhs[3] - p_tensor_rhs[5]) - By_sq * - (p_tensor_rhs[0] - 2.0 * p_tensor_rhs[3] + p_tensor_rhs[5])) * q_over_m_qu) / denom - p_tensor_old[1]; - - p_tensor_new[2] = 2.0 * (p_tensor_rhs[2] + dt1 * (-(Bx * p_tensor_rhs[1]) + Bz * p_tensor_rhs[4] + By * (p_tensor_rhs[0] - p_tensor_rhs[5])) * q_over_m + dt1_sq * - (3.0 * By * Bz * p_tensor_rhs[1] + 4.0 * Bx_sq * p_tensor_rhs[2] + By_sq * p_tensor_rhs[2] + 4.0 * Bz_sq * p_tensor_rhs[2] + Bx * (3.0 * By * p_tensor_rhs[4] + - Bz * (p_tensor_rhs[0] - 2.0 * p_tensor_rhs[3] + p_tensor_rhs[5]))) * q_over_m_sq + dt1_cu * (-4.0 * Bx_cu * p_tensor_rhs[1] + 2.0 * Bx * (By_sq + Bz_sq) * - p_tensor_rhs[1] - 2.0 * By_sq * Bz * p_tensor_rhs[4] + 4.0 * Bz_cu * p_tensor_rhs[4] + By * Bz_sq * (p_tensor_rhs[0] + 3.0 * p_tensor_rhs[3] - 4.0 * - p_tensor_rhs[5]) + By_cu * (p_tensor_rhs[0] - p_tensor_rhs[5]) - Bx_sq * (2.0 * Bz * p_tensor_rhs[4] + By * (-4.0 * p_tensor_rhs[0] + 3.0 * p_tensor_rhs[3] + - p_tensor_rhs[5]))) * q_over_m_cu + 2.0 * Bx * Bz * dt1_qu * (6.0 * Bx * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + 6.0 * By * Bz * p_tensor_rhs[4] - - Bz_sq * (p_tensor_rhs[0] + p_tensor_rhs[3] - 2.0 * p_tensor_rhs[5]) + Bx_sq * (2.0 * p_tensor_rhs[0] - p_tensor_rhs[3] - p_tensor_rhs[5]) - By_sq * (p_tensor_rhs[0] - - 2.0 * p_tensor_rhs[3] + p_tensor_rhs[5])) * q_over_m_qu) / denom - p_tensor_old[2]; - - p_tensor_new[3] = 2.0 * (p_tensor_rhs[3] + (-2.0 * Bz * dt1 * p_tensor_rhs[1] + 2.0 * Bx * dt1 * p_tensor_rhs[4]) * q_over_m + dt1_sq * (2.0 * Bx * By * - p_tensor_rhs[1] + 5.0 * By_sq * p_tensor_rhs[3] + Bz_sq * (2.0 * p_tensor_rhs[0] + 3.0 * p_tensor_rhs[3]) + Bz * (-4.0 * Bx * p_tensor_rhs[2] + 2.0 * By * - p_tensor_rhs[4]) + Bx_sq * (3.0 * p_tensor_rhs[3] + 2.0 * p_tensor_rhs[5])) * q_over_m_sq + 2.0 * dt1_cu * (Bx_sq * (-(Bz * p_tensor_rhs[1]) + 3.0 * By * - p_tensor_rhs[2]) - Bz * (4.0 * By_sq * p_tensor_rhs[1] + Bz_sq * p_tensor_rhs[1] + 3.0 * By * Bz * p_tensor_rhs[2]) + Bx_cu * p_tensor_rhs[4] + Bx * - (4.0 * By_sq * p_tensor_rhs[4] + Bz_sq * p_tensor_rhs[4] + 3.0 * By * Bz * (-p_tensor_rhs[0] + p_tensor_rhs[5]))) * q_over_m_cu + 2.0 * dt1_qu * (-2.0 * - Bx_cu * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + 2.0 * Bx * (2.0 * By_sq - Bz_sq) * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + 2.0 * By_qu * - p_tensor_rhs[3] + Bz_qu * (p_tensor_rhs[0] + p_tensor_rhs[3]) + 4.0 * By_cu * Bz * p_tensor_rhs[4] - 2.0 * By * Bz_cu * p_tensor_rhs[4] + Bx_qu * (p_tensor_rhs[3] + - p_tensor_rhs[5]) + By_sq * Bz_sq * (p_tensor_rhs[0] + 3.0 * p_tensor_rhs[5]) + Bx_sq * (-2.0 * By * Bz * p_tensor_rhs[4] + By_sq * (3.0 * p_tensor_rhs[0] + - p_tensor_rhs[5]) + Bz_sq * (p_tensor_rhs[0] + 2.0 * p_tensor_rhs[3] + p_tensor_rhs[5]))) * q_over_m_qu) / denom - p_tensor_old[3]; - - p_tensor_new[4] = 2.0 * (p_tensor_rhs[4] + dt1 * (By * p_tensor_rhs[1] - Bz * p_tensor_rhs[2] + Bx * (-p_tensor_rhs[3] + p_tensor_rhs[5])) * q_over_m + dt1_sq * - (3.0 * Bx * Bz * p_tensor_rhs[1] + Bx_sq * p_tensor_rhs[4] + 4.0 * By_sq * p_tensor_rhs[4] + 4.0 * Bz_sq * p_tensor_rhs[4] + By * (3.0 * Bx * p_tensor_rhs[2] + - Bz * (-2.0 * p_tensor_rhs[0] + p_tensor_rhs[3] + p_tensor_rhs[5]))) * q_over_m_sq + dt1_cu * (4.0 * By_cu * p_tensor_rhs[1] - 2.0 * By * Bz_sq * p_tensor_rhs[1] + - 2.0 * By_sq * Bz * p_tensor_rhs[2] - 4.0 * Bz_cu * p_tensor_rhs[2] + Bx_sq * (-2.0 * By * p_tensor_rhs[1] + 2.0 * Bz * p_tensor_rhs[2]) + Bx_cu * (-p_tensor_rhs[3] + - p_tensor_rhs[5]) + Bx * (-(Bz_sq * (3.0 * p_tensor_rhs[0] + p_tensor_rhs[3] - 4.0 * p_tensor_rhs[5])) + By_sq * (3.0 * p_tensor_rhs[0] - 4.0 * p_tensor_rhs[3] + - p_tensor_rhs[5]))) * q_over_m_cu - 2.0 * By * Bz * dt1_qu * (-6.0 * Bx * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) - 6.0 * By * Bz * p_tensor_rhs[4] + Bz_sq * - (p_tensor_rhs[0] + p_tensor_rhs[3] - 2.0 * p_tensor_rhs[5]) + By_sq * (p_tensor_rhs[0] - 2.0 * p_tensor_rhs[3] + p_tensor_rhs[5]) + Bx_sq * (-2.0 * p_tensor_rhs[0] + - p_tensor_rhs[3] + p_tensor_rhs[5])) * q_over_m_qu) / denom - p_tensor_old[4]; - - p_tensor_new[5] = 2.0 * (p_tensor_rhs[5] + 2.0 * dt1 * (By * p_tensor_rhs[2] - Bx * p_tensor_rhs[4]) * q_over_m + dt1_sq * (2.0 * Bx * Bz * p_tensor_rhs[2] + By * - (-4.0 * Bx * p_tensor_rhs[1] + 2 * Bz * p_tensor_rhs[4]) + 5.0 * Bz_sq * p_tensor_rhs[5] + By_sq * (2.0 * p_tensor_rhs[0] + 3.0 * p_tensor_rhs[5]) + Bx_sq * - (2.0 * p_tensor_rhs[3] + 3.0 * p_tensor_rhs[5])) * q_over_m_sq - 2.0 * dt1_cu * (Bx_sq * (3.0 * Bz * p_tensor_rhs[1] - By * p_tensor_rhs[2]) - By * (3.0 * By * Bz * - p_tensor_rhs[1] + By_sq * p_tensor_rhs[2] + 4.0 * Bz_sq * p_tensor_rhs[2]) + Bx_cu * p_tensor_rhs[4] + Bx * (3.0 * By * Bz * (-p_tensor_rhs[0] + p_tensor_rhs[3]) + - By_sq * p_tensor_rhs[4] + 4.0 * Bz_sq * p_tensor_rhs[4])) * q_over_m_cu + 2.0 * dt1_qu * (-2.0 * Bx_cu * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) - 2.0 * Bx * - (By_sq - 2.0 * Bz_sq) * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + By_sq * Bz_sq * (p_tensor_rhs[0] + 3.0 * p_tensor_rhs[3]) - 2.0 * By_cu * Bz * - p_tensor_rhs[4] + 4.0 * By * Bz_cu * p_tensor_rhs[4] + 2.0 * Bz_qu * p_tensor_rhs[5] + By_qu * (p_tensor_rhs[0] + p_tensor_rhs[5]) + Bx_qu * (p_tensor_rhs[3] + - p_tensor_rhs[5]) + Bx_sq * (Bz_sq * (3.0 * p_tensor_rhs[0] + p_tensor_rhs[3]) - 2.0 * By * Bz * p_tensor_rhs[4] + By_sq * (p_tensor_rhs[0] + p_tensor_rhs[3] + 2.0 * - p_tensor_rhs[5]))) * q_over_m_qu) / denom - p_tensor_old[5]; + double denom = 1.0 + (5.0 * (Bx_sq + By_sq + Bz_sq) * dt1_sq * q_over_m_sq) + + (4.0 * (Bx_sq + By_sq + Bz_sq) * (Bx_sq + By_sq + Bz_sq) * dt1_qu * q_over_m_qu); + + p_tensor_new[0] = + 2.0 * + (p_tensor_rhs[0] + 2.0 * dt1 * (Bz * p_tensor_rhs[1] - By * p_tensor_rhs[2]) * q_over_m + + dt1_sq * + (5.0 * Bx_sq * p_tensor_rhs[0] + 2.0 * Bx * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + + Bz_sq * (3.0 * p_tensor_rhs[0] + 2.0 * p_tensor_rhs[3]) - + 4.0 * By * Bz * p_tensor_rhs[4] + + By_sq * (3.0 * p_tensor_rhs[0] + 2.0 * p_tensor_rhs[5])) * + q_over_m_sq + + 2.0 * dt1_cu * + (4.0 * Bx_sq * (Bz * p_tensor_rhs[1] - By * p_tensor_rhs[2]) - + (By_sq + Bz_sq) * (-(Bz * p_tensor_rhs[1]) + By * p_tensor_rhs[2]) - + 3.0 * Bx * + (By_sq * p_tensor_rhs[4] - Bz_sq * p_tensor_rhs[4] + + By * Bz * (-p_tensor_rhs[3] + p_tensor_rhs[5]))) * + q_over_m_cu + + 2.0 * dt1_qu * + (2.0 * Bx_qu * p_tensor_rhs[0] + + 4.0 * Bx_cu * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) - + 2.0 * Bx * (By_sq + Bz_sq) * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + + (By_sq + Bz_sq) * + (Bz_sq * (p_tensor_rhs[0] + p_tensor_rhs[3]) - 2.0 * By * Bz * p_tensor_rhs[4] + + By_sq * (p_tensor_rhs[0] + p_tensor_rhs[5])) + + Bx_sq * + (4.0 * By * Bz * p_tensor_rhs[4] + By_sq * (3.0 * p_tensor_rhs[3] + p_tensor_rhs[5]) + + Bz_sq * (p_tensor_rhs[3] + 3.0 * p_tensor_rhs[5]))) * + q_over_m_qu) / + denom - + p_tensor_old[0]; + + p_tensor_new[1] = + 2.0 * + (p_tensor_rhs[1] + + dt1 * + (Bx * p_tensor_rhs[2] + Bz * (-p_tensor_rhs[0] + p_tensor_rhs[3]) - By * p_tensor_rhs[4]) * + q_over_m + + dt1_sq * + (4.0 * Bx_sq * p_tensor_rhs[1] + 4.0 * By_sq * p_tensor_rhs[1] + Bz_sq * p_tensor_rhs[1] + + 3.0 * By * Bz * p_tensor_rhs[2] + + Bx * (3.0 * Bz * p_tensor_rhs[4] + + By * (p_tensor_rhs[0] + p_tensor_rhs[3] - 2.0 * p_tensor_rhs[5]))) * + q_over_m_sq + + dt1_cu * + (4.0 * Bx_cu * p_tensor_rhs[2] - 2.0 * Bx * (By_sq + Bz_sq) * p_tensor_rhs[2] + + Bz_cu * (-p_tensor_rhs[0] + p_tensor_rhs[3]) - 4.0 * By_cu * p_tensor_rhs[4] + + 2.0 * By * Bz_sq * p_tensor_rhs[4] - + By_sq * Bz * (p_tensor_rhs[0] - 4.0 * p_tensor_rhs[3] + 3.0 * p_tensor_rhs[5]) + + Bx_sq * (2.0 * By * p_tensor_rhs[4] + + Bz * (-4.0 * p_tensor_rhs[0] + p_tensor_rhs[3] + 3.0 * p_tensor_rhs[5]))) * + q_over_m_cu + + 2.0 * Bx * By * dt1_qu * + (6.0 * Bx * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + + 6.0 * By * Bz * p_tensor_rhs[4] - + Bz_sq * (p_tensor_rhs[0] + p_tensor_rhs[3] - 2.0 * p_tensor_rhs[5]) + + Bx_sq * (2.0 * p_tensor_rhs[0] - p_tensor_rhs[3] - p_tensor_rhs[5]) - + By_sq * (p_tensor_rhs[0] - 2.0 * p_tensor_rhs[3] + p_tensor_rhs[5])) * + q_over_m_qu) / + denom - + p_tensor_old[1]; + + p_tensor_new[2] = + 2.0 * + (p_tensor_rhs[2] + + dt1 * + (-(Bx * p_tensor_rhs[1]) + Bz * p_tensor_rhs[4] + By * (p_tensor_rhs[0] - p_tensor_rhs[5]) + ) * + q_over_m + + dt1_sq * + (3.0 * By * Bz * p_tensor_rhs[1] + 4.0 * Bx_sq * p_tensor_rhs[2] + + By_sq * p_tensor_rhs[2] + 4.0 * Bz_sq * p_tensor_rhs[2] + + Bx * (3.0 * By * p_tensor_rhs[4] + + Bz * (p_tensor_rhs[0] - 2.0 * p_tensor_rhs[3] + p_tensor_rhs[5]))) * + q_over_m_sq + + dt1_cu * + (-4.0 * Bx_cu * p_tensor_rhs[1] + 2.0 * Bx * (By_sq + Bz_sq) * p_tensor_rhs[1] - + 2.0 * By_sq * Bz * p_tensor_rhs[4] + 4.0 * Bz_cu * p_tensor_rhs[4] + + By * Bz_sq * (p_tensor_rhs[0] + 3.0 * p_tensor_rhs[3] - 4.0 * p_tensor_rhs[5]) + + By_cu * (p_tensor_rhs[0] - p_tensor_rhs[5]) - + Bx_sq * (2.0 * Bz * p_tensor_rhs[4] + + By * (-4.0 * p_tensor_rhs[0] + 3.0 * p_tensor_rhs[3] + p_tensor_rhs[5]))) * + q_over_m_cu + + 2.0 * Bx * Bz * dt1_qu * + (6.0 * Bx * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + + 6.0 * By * Bz * p_tensor_rhs[4] - + Bz_sq * (p_tensor_rhs[0] + p_tensor_rhs[3] - 2.0 * p_tensor_rhs[5]) + + Bx_sq * (2.0 * p_tensor_rhs[0] - p_tensor_rhs[3] - p_tensor_rhs[5]) - + By_sq * (p_tensor_rhs[0] - 2.0 * p_tensor_rhs[3] + p_tensor_rhs[5])) * + q_over_m_qu) / + denom - + p_tensor_old[2]; + + p_tensor_new[3] = + 2.0 * + (p_tensor_rhs[3] + + (-2.0 * Bz * dt1 * p_tensor_rhs[1] + 2.0 * Bx * dt1 * p_tensor_rhs[4]) * q_over_m + + dt1_sq * + (2.0 * Bx * By * p_tensor_rhs[1] + 5.0 * By_sq * p_tensor_rhs[3] + + Bz_sq * (2.0 * p_tensor_rhs[0] + 3.0 * p_tensor_rhs[3]) + + Bz * (-4.0 * Bx * p_tensor_rhs[2] + 2.0 * By * p_tensor_rhs[4]) + + Bx_sq * (3.0 * p_tensor_rhs[3] + 2.0 * p_tensor_rhs[5])) * + q_over_m_sq + + 2.0 * dt1_cu * + (Bx_sq * (-(Bz * p_tensor_rhs[1]) + 3.0 * By * p_tensor_rhs[2]) - + Bz * (4.0 * By_sq * p_tensor_rhs[1] + Bz_sq * p_tensor_rhs[1] + + 3.0 * By * Bz * p_tensor_rhs[2]) + + Bx_cu * p_tensor_rhs[4] + + Bx * (4.0 * By_sq * p_tensor_rhs[4] + Bz_sq * p_tensor_rhs[4] + + 3.0 * By * Bz * (-p_tensor_rhs[0] + p_tensor_rhs[5]))) * + q_over_m_cu + + 2.0 * dt1_qu * + (-2.0 * Bx_cu * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + + 2.0 * Bx * (2.0 * By_sq - Bz_sq) * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + + 2.0 * By_qu * p_tensor_rhs[3] + Bz_qu * (p_tensor_rhs[0] + p_tensor_rhs[3]) + + 4.0 * By_cu * Bz * p_tensor_rhs[4] - 2.0 * By * Bz_cu * p_tensor_rhs[4] + + Bx_qu * (p_tensor_rhs[3] + p_tensor_rhs[5]) + + By_sq * Bz_sq * (p_tensor_rhs[0] + 3.0 * p_tensor_rhs[5]) + + Bx_sq * + (-2.0 * By * Bz * p_tensor_rhs[4] + By_sq * (3.0 * p_tensor_rhs[0] + p_tensor_rhs[5]) + + Bz_sq * (p_tensor_rhs[0] + 2.0 * p_tensor_rhs[3] + p_tensor_rhs[5]))) * + q_over_m_qu) / + denom - + p_tensor_old[3]; + + p_tensor_new[4] = + 2.0 * + (p_tensor_rhs[4] + + dt1 * + (By * p_tensor_rhs[1] - Bz * p_tensor_rhs[2] + Bx * (-p_tensor_rhs[3] + p_tensor_rhs[5])) * + q_over_m + + dt1_sq * + (3.0 * Bx * Bz * p_tensor_rhs[1] + Bx_sq * p_tensor_rhs[4] + + 4.0 * By_sq * p_tensor_rhs[4] + 4.0 * Bz_sq * p_tensor_rhs[4] + + By * (3.0 * Bx * p_tensor_rhs[2] + + Bz * (-2.0 * p_tensor_rhs[0] + p_tensor_rhs[3] + p_tensor_rhs[5]))) * + q_over_m_sq + + dt1_cu * + (4.0 * By_cu * p_tensor_rhs[1] - 2.0 * By * Bz_sq * p_tensor_rhs[1] + + 2.0 * By_sq * Bz * p_tensor_rhs[2] - 4.0 * Bz_cu * p_tensor_rhs[2] + + Bx_sq * (-2.0 * By * p_tensor_rhs[1] + 2.0 * Bz * p_tensor_rhs[2]) + + Bx_cu * (-p_tensor_rhs[3] + p_tensor_rhs[5]) + + Bx * (-(Bz_sq * (3.0 * p_tensor_rhs[0] + p_tensor_rhs[3] - 4.0 * p_tensor_rhs[5])) + + By_sq * (3.0 * p_tensor_rhs[0] - 4.0 * p_tensor_rhs[3] + p_tensor_rhs[5]))) * + q_over_m_cu - + 2.0 * By * Bz * dt1_qu * + (-6.0 * Bx * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) - + 6.0 * By * Bz * p_tensor_rhs[4] + + Bz_sq * (p_tensor_rhs[0] + p_tensor_rhs[3] - 2.0 * p_tensor_rhs[5]) + + By_sq * (p_tensor_rhs[0] - 2.0 * p_tensor_rhs[3] + p_tensor_rhs[5]) + + Bx_sq * (-2.0 * p_tensor_rhs[0] + p_tensor_rhs[3] + p_tensor_rhs[5])) * + q_over_m_qu) / + denom - + p_tensor_old[4]; + + p_tensor_new[5] = + 2.0 * + (p_tensor_rhs[5] + 2.0 * dt1 * (By * p_tensor_rhs[2] - Bx * p_tensor_rhs[4]) * q_over_m + + dt1_sq * + (2.0 * Bx * Bz * p_tensor_rhs[2] + + By * (-4.0 * Bx * p_tensor_rhs[1] + 2 * Bz * p_tensor_rhs[4]) + + 5.0 * Bz_sq * p_tensor_rhs[5] + By_sq * (2.0 * p_tensor_rhs[0] + 3.0 * p_tensor_rhs[5]) + + Bx_sq * (2.0 * p_tensor_rhs[3] + 3.0 * p_tensor_rhs[5])) * + q_over_m_sq - + 2.0 * dt1_cu * + (Bx_sq * (3.0 * Bz * p_tensor_rhs[1] - By * p_tensor_rhs[2]) - + By * (3.0 * By * Bz * p_tensor_rhs[1] + By_sq * p_tensor_rhs[2] + + 4.0 * Bz_sq * p_tensor_rhs[2]) + + Bx_cu * p_tensor_rhs[4] + + Bx * (3.0 * By * Bz * (-p_tensor_rhs[0] + p_tensor_rhs[3]) + By_sq * p_tensor_rhs[4] + + 4.0 * Bz_sq * p_tensor_rhs[4])) * + q_over_m_cu + + 2.0 * dt1_qu * + (-2.0 * Bx_cu * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) - + 2.0 * Bx * (By_sq - 2.0 * Bz_sq) * (By * p_tensor_rhs[1] + Bz * p_tensor_rhs[2]) + + By_sq * Bz_sq * (p_tensor_rhs[0] + 3.0 * p_tensor_rhs[3]) - + 2.0 * By_cu * Bz * p_tensor_rhs[4] + 4.0 * By * Bz_cu * p_tensor_rhs[4] + + 2.0 * Bz_qu * p_tensor_rhs[5] + By_qu * (p_tensor_rhs[0] + p_tensor_rhs[5]) + + Bx_qu * (p_tensor_rhs[3] + p_tensor_rhs[5]) + + Bx_sq * + (Bz_sq * (3.0 * p_tensor_rhs[0] + p_tensor_rhs[3]) - 2.0 * By * Bz * p_tensor_rhs[4] + + By_sq * (p_tensor_rhs[0] + p_tensor_rhs[3] + 2.0 * p_tensor_rhs[5]))) * + q_over_m_qu) / + denom - + p_tensor_old[5]; } -void -implicit_em_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, - double fluid_rhs_s[GKYL_MAX_SPECIES][4], double* fluid_s[GKYL_MAX_SPECIES], - const double *app_accel_s[GKYL_MAX_SPECIES], double* em, const double* app_current, const double* ext_em) +void implicit_em_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double fluid_rhs_s[GKYL_MAX_SPECIES][4], double *fluid_s[GKYL_MAX_SPECIES], + const double *app_accel_s[GKYL_MAX_SPECIES], double *em, const double *app_current, + const double *ext_em +) { int nfluids = mom_em->nfluids; double epsilon0 = mom_em->epsilon0; @@ -106,7 +238,7 @@ implicit_em_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double By = em[4] + ext_em[4]; double Bz = em[5] + ext_em[5]; double B_mag = sqrt((Bx * Bx) + (By * By) + (Bz * Bz)); - + double bx = 0.0, by = 0.0, bz = 0.0; if (B_mag > 0.0) { bx = Bx / B_mag; @@ -148,9 +280,12 @@ implicit_em_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, scale_fact_E = fmin(1.0, t_curr / t_ramp_E); } - J[i][0] = J_old[i][0] + (0.5 * dt * q_over_m[i] * rho * ((q_over_m[i] * ext_em[0] * scale_fact_E) + app_accel[0])); - J[i][1] = J_old[i][1] + (0.5 * dt * q_over_m[i] * rho * ((q_over_m[i] * ext_em[1] * scale_fact_E) + app_accel[1])); - J[i][2] = J_old[i][2] + (0.5 * dt * q_over_m[i] * rho * ((q_over_m[i] * ext_em[2] * scale_fact_E) + app_accel[2])); + J[i][0] = J_old[i][0] + (0.5 * dt * q_over_m[i] * rho * + ((q_over_m[i] * ext_em[0] * scale_fact_E) + app_accel[0])); + J[i][1] = J_old[i][1] + (0.5 * dt * q_over_m[i] * rho * + ((q_over_m[i] * ext_em[1] * scale_fact_E) + app_accel[1])); + J[i][2] = J_old[i][2] + (0.5 * dt * q_over_m[i] * rho * + ((q_over_m[i] * ext_em[2] * scale_fact_E) + app_accel[2])); wc_dt[i] = q_over_m[i] * B_mag * dt; wp_dt_sq[i] = (rho * (q_over_m[i] * q_over_m[i]) * (dt * dt)) / epsilon0; @@ -160,12 +295,18 @@ implicit_em_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, gam_sq += (wp_dt_sq[i] * (wc_dt[i] * wc_dt[i])) / denom; delta += (wp_dt_sq[i] * wc_dt[i]) / denom; - Kx -= (dt / denom) * (J[i][0] + (((wc_dt[i] * wc_dt[i]) / 4.0) * bx * ((bx * J[i][0]) + (by * J[i][1]) + (bz * J[i][2]))) - - ((wc_dt[i] / 2.0) * ((by * J[i][2]) - (bz * J[i][1])))); - Ky -= (dt / denom) * (J[i][1] + (((wc_dt[i] * wc_dt[i]) / 4.0) * by * ((bx * J[i][0]) + (by * J[i][1]) + (bz * J[i][2]))) - - ((wc_dt[i] / 2.0) * ((bz * J[i][0]) - (bx * J[i][2])))); - Kz -= (dt / denom) * (J[i][2] + (((wc_dt[i] * wc_dt[i]) / 4.0) * bz * ((bx * J[i][0]) + (by * J[i][1]) + (bz * J[i][2]))) - - ((wc_dt[i] / 2.0) * ((bx * J[i][1]) - (by * J[i][0])))); + Kx -= (dt / denom) * (J[i][0] + + (((wc_dt[i] * wc_dt[i]) / 4.0) * bx * + ((bx * J[i][0]) + (by * J[i][1]) + (bz * J[i][2]))) - + ((wc_dt[i] / 2.0) * ((by * J[i][2]) - (bz * J[i][1])))); + Ky -= (dt / denom) * (J[i][1] + + (((wc_dt[i] * wc_dt[i]) / 4.0) * by * + ((bx * J[i][0]) + (by * J[i][1]) + (bz * J[i][2]))) - + ((wc_dt[i] / 2.0) * ((bz * J[i][0]) - (bx * J[i][2])))); + Kz -= (dt / denom) * (J[i][2] + + (((wc_dt[i] * wc_dt[i]) / 4.0) * bz * + ((bx * J[i][0]) + (by * J[i][1]) + (bz * J[i][2]))) - + ((wc_dt[i] / 2.0) * ((bx * J[i][1]) - (by * J[i][0])))); } double Delta_sq = (delta * delta) / (1.0 + (w0_sq / 4.0)); @@ -186,22 +327,30 @@ implicit_em_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double Fy_K = Fy + (0.5 * Ky); double Fz_K = Fz + (0.5 * Kz); - double Fx_bar = (1.0 / (1.0 + (w0_sq / 4.0) + (Delta_sq / 64.0))) * (Fx_K + ((((Delta_sq / 64.0) - (gam_sq / 16.0)) / - (1.0 + (w0_sq / 4.0) + (gam_sq / 16.0))) * bx * ((bx * Fx_K) + (by * Fy_K) + (bz * Fz_K))) + (((delta / 8.0) / - (1.0 + (w0_sq / 4.0))) * ((by * Fz_K) - (bz * Fy_K)))); - double Fy_bar = (1.0 / (1.0 + (w0_sq / 4.0) + (Delta_sq / 64.0))) * (Fy_K + ((((Delta_sq / 64.0) - (gam_sq / 16.0)) / - (1.0 + (w0_sq / 4.0) + (gam_sq / 16.0))) * by * ((bx * Fx_K) + (by * Fy_K) + (bz * Fz_K))) + (((delta / 8.0) / - (1.0 + (w0_sq / 4.0))) * ((bz * Fx_K) - (bx * Fz_K)))); - double Fz_bar = (1.0 / (1.0 + (w0_sq / 4.0) + (Delta_sq / 64.0))) * (Fz_K + ((((Delta_sq / 64.0) - (gam_sq / 16.0)) / - (1.0 + (w0_sq / 4.0) + (gam_sq / 16.0))) * bz * ((bx * Fx_K) + (by * Fy_K) + (bz * Fz_K))) + (((delta / 8.0) / - (1.0 + (w0_sq / 4.0))) * ((bx * Fy_K) - (by * Fx_K)))); + double Fx_bar = + (1.0 / (1.0 + (w0_sq / 4.0) + (Delta_sq / 64.0))) * + (Fx_K + + ((((Delta_sq / 64.0) - (gam_sq / 16.0)) / (1.0 + (w0_sq / 4.0) + (gam_sq / 16.0))) * bx * + ((bx * Fx_K) + (by * Fy_K) + (bz * Fz_K))) + + (((delta / 8.0) / (1.0 + (w0_sq / 4.0))) * ((by * Fz_K) - (bz * Fy_K)))); + double Fy_bar = + (1.0 / (1.0 + (w0_sq / 4.0) + (Delta_sq / 64.0))) * + (Fy_K + + ((((Delta_sq / 64.0) - (gam_sq / 16.0)) / (1.0 + (w0_sq / 4.0) + (gam_sq / 16.0))) * by * + ((bx * Fx_K) + (by * Fy_K) + (bz * Fz_K))) + + (((delta / 8.0) / (1.0 + (w0_sq / 4.0))) * ((bz * Fx_K) - (bx * Fz_K)))); + double Fz_bar = + (1.0 / (1.0 + (w0_sq / 4.0) + (Delta_sq / 64.0))) * + (Fz_K + + ((((Delta_sq / 64.0) - (gam_sq / 16.0)) / (1.0 + (w0_sq / 4.0) + (gam_sq / 16.0))) * bz * + ((bx * Fx_K) + (by * Fy_K) + (bz * Fz_K))) + + (((delta / 8.0) / (1.0 + (w0_sq / 4.0))) * ((bx * Fy_K) - (by * Fx_K)))); if (mom_em->static_field) { em[0] = Fx_old / epsilon0; em[1] = Fy_old / epsilon0; em[2] = Fz_old / epsilon0; - } - else { + } else { em[0] = ((2.0 * Fx_bar) - Fx_old) / epsilon0; em[1] = ((2.0 * Fy_bar) - Fy_old) / epsilon0; em[2] = ((2.0 * Fz_bar) - Fz_old) / epsilon0; @@ -214,23 +363,36 @@ implicit_em_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double Jy_star = J[i][1] + (Fy_bar * ((wp_dt_sq[i] / dt) / 2.0)); double Jz_star = J[i][2] + (Fz_bar * ((wp_dt_sq[i] / dt) / 2.0)); - double Jx_new = ((2.0 * (Jx_star + (((wc_dt[i] * wc_dt[i]) / 4.0) * bx * ((bx * Jx_star) + (by * Jy_star) + (bz * Jz_star))) - - ((wc_dt[i] / 2.0) * ((by * Jz_star) - (bz * Jy_star))))) / (1.0 + ((wc_dt[i] * wc_dt[i]) / 4.0))) - J_old[i][0]; - double Jy_new = ((2.0 * (Jy_star + (((wc_dt[i] * wc_dt[i]) / 4.0) * by * ((bx * Jx_star) + (by * Jy_star) + (bz * Jz_star))) - - ((wc_dt[i] / 2.0) * ((bz * Jx_star) - (bx * Jz_star))))) / (1.0 + ((wc_dt[i] * wc_dt[i]) / 4.0))) - J_old[i][1]; - double Jz_new = ((2.0 * (Jz_star + (((wc_dt[i] * wc_dt[i]) / 4.0) * bz * ((bx * Jx_star) + (by * Jy_star) + (bz * Jz_star))) - - ((wc_dt[i] / 2.0) * ((bx * Jy_star) - (by * Jx_star))))) / (1.0 + ((wc_dt[i] * wc_dt[i]) / 4.0))) - J_old[i][2]; - + double Jx_new = ((2.0 * (Jx_star + + (((wc_dt[i] * wc_dt[i]) / 4.0) * bx * + ((bx * Jx_star) + (by * Jy_star) + (bz * Jz_star))) - + ((wc_dt[i] / 2.0) * ((by * Jz_star) - (bz * Jy_star))))) / + (1.0 + ((wc_dt[i] * wc_dt[i]) / 4.0))) - + J_old[i][0]; + double Jy_new = ((2.0 * (Jy_star + + (((wc_dt[i] * wc_dt[i]) / 4.0) * by * + ((bx * Jx_star) + (by * Jy_star) + (bz * Jz_star))) - + ((wc_dt[i] / 2.0) * ((bz * Jx_star) - (bx * Jz_star))))) / + (1.0 + ((wc_dt[i] * wc_dt[i]) / 4.0))) - + J_old[i][1]; + double Jz_new = ((2.0 * (Jz_star + + (((wc_dt[i] * wc_dt[i]) / 4.0) * bz * + ((bx * Jx_star) + (by * Jy_star) + (bz * Jz_star))) - + ((wc_dt[i] / 2.0) * ((bx * Jy_star) - (by * Jx_star))))) / + (1.0 + ((wc_dt[i] * wc_dt[i]) / 4.0))) - + J_old[i][2]; + f[1] = Jx_new / q_over_m[i]; f[2] = Jy_new / q_over_m[i]; f[3] = Jz_new / q_over_m[i]; } } -void -implicit_neut_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, - double fluid_rhs_s[GKYL_MAX_SPECIES][4], double* fluid_s[GKYL_MAX_SPECIES], - const double* app_accel_s[GKYL_MAX_SPECIES], const double* p_rhs_s[GKYL_MAX_SPECIES]) +void implicit_neut_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double fluid_rhs_s[GKYL_MAX_SPECIES][4], double *fluid_s[GKYL_MAX_SPECIES], + const double *app_accel_s[GKYL_MAX_SPECIES], const double *p_rhs_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; @@ -294,12 +456,13 @@ implicit_neut_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr } } -void -implicit_collision_source_update(const gkyl_moment_em_coupling* mom_em, double dt, double* fluid_s[GKYL_MAX_SPECIES]) +void implicit_collision_source_update( + const gkyl_moment_em_coupling *mom_em, double dt, double *fluid_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; double nu_base[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES]; - for (int i = 0; i < nfluids; i++) { + for (int i = 0; i < nfluids; i++) { for (int j = 0; j < nfluids; j++) { nu_base[i][j] = (mom_em->nu_base)[i][j]; } @@ -323,7 +486,9 @@ implicit_collision_source_update(const gkyl_moment_em_coupling* mom_em, double d lhs[i][j] = 0.0; } - rhs[i][0] = 0.0; rhs[i][1] = 0.0; rhs[i][2] = 0.0; + rhs[i][0] = 0.0; + rhs[i][1] = 0.0; + rhs[i][2] = 0.0; } for (int i = 0; i < nfluids; i++) { @@ -337,13 +502,12 @@ implicit_collision_source_update(const gkyl_moment_em_coupling* mom_em, double d rhs[i][2] = mom_z / rho; lhs[i][i] = 1.0; - double* nu_i = nu + (nfluids * i); + double *nu_i = nu + (nfluids * i); for (int j = 0; j < nfluids; j++) { if (i == j) { lhs[i][i] += 0.5 * dt * nu_i[i]; - } - else { + } else { double dt_nu_ij = 0.5 * dt * nu_i[j]; lhs[i][i] += dt_nu_ij; lhs[i][j] -= dt_nu_ij; @@ -390,7 +554,8 @@ implicit_collision_source_update(const gkyl_moment_em_coupling* mom_em, double d double rho = f[0]; double mom_x = f[1], mom_y = f[2], mom_z = f[3]; double E = f[4]; - double internal_energy = E - (0.5 * ((mom_x * mom_x) + (mom_y * mom_y) + (mom_z * mom_z)) / rho); + double internal_energy = + E - (0.5 * ((mom_x * mom_x) + (mom_y * mom_y) + (mom_z * mom_z)) / rho); T[i] = (internal_energy / rho) * m; rhs_T[i][0] = T[i]; @@ -401,9 +566,10 @@ implicit_collision_source_update(const gkyl_moment_em_coupling* mom_em, double d for (int j = 0; j < nfluids; j++) { if (i != j) { double m_j = mom_em->param[j].mass; - - double du_sq = ((rhs[i][0] - rhs[j][0]) * (rhs[i][0] - rhs[j][0])) + ((rhs[i][1] - rhs[j][1]) * (rhs[i][1] - rhs[j][1])) + - ((rhs[i][2] - rhs[j][2]) * (rhs[i][2] - rhs[j][2])); + + double du_sq = ((rhs[i][0] - rhs[j][0]) * (rhs[i][0] - rhs[j][0])) + + ((rhs[i][1] - rhs[j][1]) * (rhs[i][1] - rhs[j][1])) + + ((rhs[i][2] - rhs[j][2]) * (rhs[i][2] - rhs[j][2])); double coeff_ij = (dt * nu_i[j] * m) / (m + m_j); rhs_T[i][0] += 0.5 * coeff_ij * m_j * du_sq; @@ -461,10 +627,12 @@ implicit_collision_source_update(const gkyl_moment_em_coupling* mom_em, double d gkyl_mat_release(rhs_T_mat); } -void -implicit_frictional_source_update_half(const gkyl_moment_em_coupling* mom_em, const double Z, const double T_elc, const double Lambda_ee, - double t_curr, const double dt, double* f_elc_old, double* f_ion_old, double* f_elc_new, double* f_ion_new, - const double* app_accel_s[GKYL_MAX_SPECIES], double* em_old, double* em_new, const double* app_current, const double* ext_em) +void implicit_frictional_source_update_half( + const gkyl_moment_em_coupling *mom_em, const double Z, const double T_elc, const double Lambda_ee, + double t_curr, const double dt, double *f_elc_old, double *f_ion_old, double *f_elc_new, + double *f_ion_new, const double *app_accel_s[GKYL_MAX_SPECIES], double *em_old, double *em_new, + const double *app_current, const double *ext_em +) { int nfluids = mom_em->nfluids; double pi = M_PI; @@ -500,9 +668,12 @@ implicit_frictional_source_update_half(const gkyl_moment_em_coupling* mom_em, co double s_elc = sigma_elc / rho_elc; double s_ion = sigma_ion / rho_ion; - double tau_ei = (1.0 / Z) * ((3.0 * sqrt(mass_elc) * ((4.0 * pi * epsilon0) * (4.0 * pi * epsilon0)) * pow(T_elc, 3.0 / 2.0)) / - (4.0 * sqrt(2.0 * pi) * n_elc * exp(4.0) * log(Lambda_ee))); - double alpha_par = 1.0 - (pow(Z, 2.0 / 3.0) / ((1.46 * pow(Z, 2.0 / 3.0)) - (0.33 * pow (Z, 1.0 / 3.0)) + 0.888)); + double tau_ei = + (1.0 / Z) * ((3.0 * sqrt(mass_elc) * ((4.0 * pi * epsilon0) * (4.0 * pi * epsilon0)) * + pow(T_elc, 3.0 / 2.0)) / + (4.0 * sqrt(2.0 * pi) * n_elc * exp(4.0) * log(Lambda_ee))); + double alpha_par = + 1.0 - (pow(Z, 2.0 / 3.0) / ((1.46 * pow(Z, 2.0 / 3.0)) - (0.33 * pow(Z, 1.0 / 3.0)) + 0.888)); double A_ee = 1.0 + ((0.5 * dt) * (1.0 / tau_ei) * alpha_par); double A_ei = -(0.5 * dt) * (1.0 / tau_ei) * alpha_par; @@ -515,7 +686,8 @@ implicit_frictional_source_update_half(const gkyl_moment_em_coupling* mom_em, co double D_e = (dt / (2.0 * epsilon0)) * sigma_elc; double D_i = (dt / (2.0 * epsilon0)) * sigma_ion; - double det = (A_ei * (-A_ie + (C_i * D_e))) + (C_e * ((-A_ii * D_e) + (A_ie * D_i))) + (A_ee * (A_ii - (C_i * D_i))); + double det = (A_ei * (-A_ie + (C_i * D_e))) + (C_e * ((-A_ii * D_e) + (A_ie * D_i))) + + (A_ee * (A_ii - (C_i * D_i))); double mat_11 = (A_ii - (C_i * D_i)) / det; double mat_12 = (A_ei - (C_e * D_i)) / det; double mat_13 = (-(A_ii * C_e) + (A_ei * C_i)) / det; @@ -527,35 +699,35 @@ implicit_frictional_source_update_half(const gkyl_moment_em_coupling* mom_em, co double mat_33 = (-(A_ei * A_ie) + (A_ee * A_ii)) / det; f_elc_new[1] = (mat_11 * (u_elc + (0.5 * dt * (1.0 / rho_elc) * app_accel_elc[0]))) + - (mat_12 * (u_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[0]))) + - (mat_13 * (Ex - ((dt / (2.0 * epsilon0)) * app_current[0]))); + (mat_12 * (u_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[0]))) + + (mat_13 * (Ex - ((dt / (2.0 * epsilon0)) * app_current[0]))); f_elc_new[2] = (mat_11 * (v_elc + (0.5 * dt * (1.0 / rho_elc) * app_accel_elc[1]))) + - (mat_12 * (v_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[1]))) + - (mat_13 * (Ey - ((dt / (2.0 * epsilon0)) * app_current[1]))); + (mat_12 * (v_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[1]))) + + (mat_13 * (Ey - ((dt / (2.0 * epsilon0)) * app_current[1]))); f_elc_new[3] = (mat_11 * (w_elc + (0.5 * dt * (1.0 / rho_elc) * app_accel_elc[2]))) + - (mat_12 * (w_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[2]))) + - (mat_13 * (Ez - ((dt / (2.0 * epsilon0)) * app_current[2]))); + (mat_12 * (w_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[2]))) + + (mat_13 * (Ez - ((dt / (2.0 * epsilon0)) * app_current[2]))); f_ion_new[1] = (mat_21 * (u_elc + (0.5 * dt * (1.0 / rho_elc) * app_accel_elc[0]))) + - (mat_22 * (u_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[0]))) + - (mat_23 * (Ex - ((dt / (2.0 * epsilon0)) * app_current[0]))); + (mat_22 * (u_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[0]))) + + (mat_23 * (Ex - ((dt / (2.0 * epsilon0)) * app_current[0]))); f_ion_new[2] = (mat_21 * (v_elc + (0.5 * dt * (1.0 / rho_elc) * app_accel_elc[1]))) + - (mat_22 * (v_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[1]))) + - (mat_23 * (Ey - ((dt / (2.0 * epsilon0)) * app_current[1]))); + (mat_22 * (v_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[1]))) + + (mat_23 * (Ey - ((dt / (2.0 * epsilon0)) * app_current[1]))); f_ion_new[3] = (mat_21 * (w_elc + (0.5 * dt * (1.0 / rho_elc) * app_accel_elc[2]))) + - (mat_22 * (w_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[2]))) + - (mat_23 * (Ez - ((dt / (2.0 * epsilon0)) * app_current[2]))); - + (mat_22 * (w_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[2]))) + + (mat_23 * (Ez - ((dt / (2.0 * epsilon0)) * app_current[2]))); + em_new[0] = (mat_31 * (u_elc + (0.5 * dt * (1.0 / rho_elc) * app_accel_elc[0]))) + - (mat_32 * (u_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[0]))) + - (mat_33 * (Ex - ((dt / (2.0 * epsilon0)) * app_current[0]))); + (mat_32 * (u_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[0]))) + + (mat_33 * (Ex - ((dt / (2.0 * epsilon0)) * app_current[0]))); em_new[1] = (mat_31 * (v_elc + (0.5 * dt * (1.0 / rho_elc) * app_accel_elc[1]))) + - (mat_32 * (v_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[1]))) + - (mat_33 * (Ey - ((dt / (2.0 * epsilon0)) * app_current[1]))); + (mat_32 * (v_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[1]))) + + (mat_33 * (Ey - ((dt / (2.0 * epsilon0)) * app_current[1]))); em_new[2] = (mat_31 * (w_elc + (0.5 * dt * (1.0 / rho_elc) * app_accel_elc[2]))) + - (mat_32 * (w_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[2]))) + - (mat_33 * (Ez - ((dt / (2.0 * epsilon0)) * app_current[2]))); - + (mat_32 * (w_ion + (0.5 * dt * (1.0 / rho_ion) * app_accel_ion[2]))) + + (mat_33 * (Ez - ((dt / (2.0 * epsilon0)) * app_current[2]))); + em_new[0] -= ext_em[0]; em_new[1] -= ext_em[1]; em_new[2] -= ext_em[2]; @@ -572,9 +744,11 @@ implicit_frictional_source_update_half(const gkyl_moment_em_coupling* mom_em, co } } -void -implicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double t_curr, const double dt, double* fluid_s[GKYL_MAX_SPECIES], - const double* app_accel_s[GKYL_MAX_SPECIES], double* em, const double* app_current, const double* ext_em) +void implicit_frictional_source_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, const double dt, + double *fluid_s[GKYL_MAX_SPECIES], const double *app_accel_s[GKYL_MAX_SPECIES], double *em, + const double *app_current, const double *ext_em +) { int nfluids = mom_em->nfluids; @@ -595,15 +769,19 @@ implicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double f_elc_old[i] = f_elc[i]; f_ion_old[i] = f_ion[i]; } - + for (int i = 0; i < 8; i++) { em_old[i] = em[i]; } - implicit_frictional_source_update_half(mom_em, Z, T_elc, Lambda_ee, t_curr, dt, f_elc_old, f_ion_old, f_elc_stage1, f_ion_stage1, - app_accel_s, em_old, em_stage1, app_current, ext_em); - implicit_frictional_source_update_half(mom_em, Z, T_elc, Lambda_ee, t_curr + (0.5 * dt), dt, f_elc_stage1, f_ion_stage1, f_elc_new, f_ion_new, - app_accel_s, em_stage1, em_new, app_current, ext_em); + implicit_frictional_source_update_half( + mom_em, Z, T_elc, Lambda_ee, t_curr, dt, f_elc_old, f_ion_old, f_elc_stage1, f_ion_stage1, + app_accel_s, em_old, em_stage1, app_current, ext_em + ); + implicit_frictional_source_update_half( + mom_em, Z, T_elc, Lambda_ee, t_curr + (0.5 * dt), dt, f_elc_stage1, f_ion_stage1, f_elc_new, + f_ion_new, app_accel_s, em_stage1, em_new, app_current, ext_em + ); for (int i = 0; i < 5; i++) { f_elc[i] = f_elc_new[i]; @@ -616,10 +794,12 @@ implicit_frictional_source_update(const gkyl_moment_em_coupling* mom_em, double } } -void -implicit_source_coupling_update(const gkyl_moment_em_coupling* mom_em, double t_curr, double dt, double* fluid_s[GKYL_MAX_SPECIES], - const double* app_accel_s[GKYL_MAX_SPECIES], const double* p_rhs_s[GKYL_MAX_SPECIES], double* em, const double* app_current, - const double* ext_em, const double* nT_sources_s[GKYL_MAX_SPECIES]) +void implicit_source_coupling_update( + const gkyl_moment_em_coupling *mom_em, double t_curr, double dt, + double *fluid_s[GKYL_MAX_SPECIES], const double *app_accel_s[GKYL_MAX_SPECIES], + const double *p_rhs_s[GKYL_MAX_SPECIES], double *em, const double *app_current, + const double *ext_em, const double *nT_sources_s[GKYL_MAX_SPECIES] +) { int nfluids = mom_em->nfluids; double ke_old[GKYL_MAX_SPECIES]; @@ -654,14 +834,14 @@ implicit_source_coupling_update(const gkyl_moment_em_coupling* mom_em, double t_ double energy_rhs = p_rhs[4]; // kinetic energy at known time (including potential transport terms) - ke_old[i] = 0.5 * (((fluid_rhs[i][1] * fluid_rhs[i][1]) - + (fluid_rhs[i][2] * fluid_rhs[i][2]) - + (fluid_rhs[i][3] * fluid_rhs[i][3])) / fluid_rhs[i][0]); + ke_old[i] = + 0.5 * (((fluid_rhs[i][1] * fluid_rhs[i][1]) + (fluid_rhs[i][2] * fluid_rhs[i][2]) + + (fluid_rhs[i][3] * fluid_rhs[i][3])) / + fluid_rhs[i][0]); // total energy at known time (including potential transport terms) energy_old[i] = energy + (0.5 * dt * energy_rhs); - } - else if (mom_em->param[i].type == GKYL_EQN_TEN_MOMENT) { + } else if (mom_em->param[i].type == GKYL_EQN_TEN_MOMENT) { double q_over_m = q / m; double p11 = f[4], p12 = f[5], p13 = f[6]; @@ -690,7 +870,9 @@ implicit_source_coupling_update(const gkyl_moment_em_coupling* mom_em, double t_ double exp_nu = exp(nu * dt); if (mom_em->is_charged_species) { - pressure_tensor_rotate(q_over_m, dt, em, ext_em, p_tensor_old, p_tensor_rhs, p_tensor_new[i]); + pressure_tensor_rotate( + q_over_m, dt, em, ext_em, p_tensor_old, p_tensor_rhs, p_tensor_new[i] + ); } p_tensor_new[i][0] = ((p_tensor_new[i][0] - p) / exp_nu) + p; @@ -703,9 +885,10 @@ implicit_source_coupling_update(const gkyl_moment_em_coupling* mom_em, double t_ } if (mom_em->is_charged_species) { - implicit_em_source_update(mom_em, t_curr, dt, fluid_rhs, fluid_s, app_accel_s, em, app_current, ext_em); - } - else { + implicit_em_source_update( + mom_em, t_curr, dt, fluid_rhs, fluid_s, app_accel_s, em, app_current, ext_em + ); + } else { implicit_neut_source_update(mom_em, t_curr, dt, fluid_rhs, fluid_s, app_accel_s, p_rhs_s); } @@ -716,12 +899,12 @@ implicit_source_coupling_update(const gkyl_moment_em_coupling* mom_em, double t_ double rho = f[0]; double mom_x = f[1], mom_y = f[2], mom_z = f[3]; double energy = f[4]; - + // Energy at new time is new kinetic energy plus potential contribution from // transport terms. We use a time-centered approach even though the update // from the transport terms is a simple forward Euler. - f[4] = (0.5 * ((mom_x * mom_x) + (mom_y * mom_y) + (mom_z * mom_z)) / rho) - + 2.0*energy_old[i] - energy - ke_old[i]; + f[4] = (0.5 * ((mom_x * mom_x) + (mom_y * mom_y) + (mom_z * mom_z)) / rho) + + 2.0 * energy_old[i] - energy - ke_old[i]; } // As I do not understand how the source terms for gradient-based closure interact with the source terms for the expanding-box // model, I'm disabling the former whenever the latter are present, pro tem. This should be updated! -JG 07/25/24 @@ -749,9 +932,10 @@ implicit_source_coupling_update(const gkyl_moment_em_coupling* mom_em, double t_ if (mom_em->has_frictional_sources) { if (mom_em->use_explicit_friction) { explicit_frictional_source_update(mom_em, t_curr, dt, fluid_s); - } - else { - implicit_frictional_source_update(mom_em, t_curr, dt, fluid_s, app_accel_s, em, app_current, ext_em); + } else { + implicit_frictional_source_update( + mom_em, t_curr, dt, fluid_s, app_accel_s, em, app_current, ext_em + ); } } if (mom_em->has_volume_sources) { diff --git a/moments/zero/ten_moment_grad_closure.c b/moments/zero/ten_moment_grad_closure.c index 95ad5f9836..6d82bb03f8 100644 --- a/moments/zero/ten_moment_grad_closure.c +++ b/moments/zero/ten_moment_grad_closure.c @@ -7,7 +7,7 @@ #include #include -gkyl_ten_moment_grad_closure* +gkyl_ten_moment_grad_closure * gkyl_ten_moment_grad_closure_new(const struct gkyl_ten_moment_grad_closure_inp *inp) { gkyl_ten_moment_grad_closure *up = gkyl_malloc(sizeof(gkyl_ten_moment_grad_closure)); @@ -18,14 +18,15 @@ gkyl_ten_moment_grad_closure_new(const struct gkyl_ten_moment_grad_closure_inp * up->cfl = inp->cfl; int ndim = inp->update_range->ndim; - + create_offsets_vertices(inp->update_range, up->offsets_vertices); create_offsets_centers(inp->heat_flux_range, up->offsets_centers); - - if (inp->comm) + + if (inp->comm) { up->comm = gkyl_comm_acquire(inp->comm); - else - up->comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { } ); + } else { + up->comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){}); + } grad_closure_calc_q_choose(up); grad_closure_update_q_choose(up); @@ -35,35 +36,34 @@ gkyl_ten_moment_grad_closure_new(const struct gkyl_ten_moment_grad_closure_inp * return up; } -struct gkyl_ten_moment_grad_closure_status -gkyl_ten_moment_grad_closure_advance(const gkyl_ten_moment_grad_closure *gces, - const struct gkyl_range *heat_flux_range, const struct gkyl_range *update_range, - const struct gkyl_array *fluid, const struct gkyl_array *em_tot, - struct gkyl_array *cflrate, double dt, struct gkyl_array *heat_flux, - struct gkyl_array *rhs) +struct gkyl_ten_moment_grad_closure_status gkyl_ten_moment_grad_closure_advance( + const gkyl_ten_moment_grad_closure *gces, const struct gkyl_range *heat_flux_range, + const struct gkyl_range *update_range, const struct gkyl_array *fluid, + const struct gkyl_array *em_tot, struct gkyl_array *cflrate, double dt, + struct gkyl_array *heat_flux, struct gkyl_array *rhs +) { int ndim = update_range->ndim; - long sz[] = { 2, 4, 8 }; + long sz[] = {2, 4, 8}; double *cfla = gces->cfla; - double cfl = gces->cfl, cflm = 1.1*cfl; + double cfl = gces->cfl, cflm = 1.1 * cfl; double is_cfl_violated = 0.0; // deliberately a double - - const double* fluid_d[sz[ndim-1]]; - const double* em_tot_d[sz[ndim-1]]; + + const double *fluid_d[sz[ndim - 1]]; + const double *em_tot_d[sz[ndim - 1]]; double *heat_flux_d; - const double* heat_flux_up[sz[ndim-1]]; + const double *heat_flux_up[sz[ndim - 1]]; double *rhs_d; struct gkyl_range_iter iter_vertex; gkyl_range_iter_init(&iter_vertex, heat_flux_range); while (gkyl_range_iter_next(&iter_vertex)) { - long linc_vertex = gkyl_range_idx(heat_flux_range, iter_vertex.idx); long linc_center = gkyl_range_idx(update_range, iter_vertex.idx); - for (int i=0; ioffsets_vertices[i]); + for (int i = 0; i < sz[ndim - 1]; ++i) { + em_tot_d[i] = gkyl_array_cfetch(em_tot, linc_center + gces->offsets_vertices[i]); fluid_d[i] = gkyl_array_cfetch(fluid, linc_center + gces->offsets_vertices[i]); } @@ -75,13 +75,12 @@ gkyl_ten_moment_grad_closure_advance(const gkyl_ten_moment_grad_closure *gces, struct gkyl_range_iter iter_center; gkyl_range_iter_init(&iter_center, update_range); while (gkyl_range_iter_next(&iter_center)) { - long linc_vertex = gkyl_range_idx(heat_flux_range, iter_center.idx); long linc_center = gkyl_range_idx(update_range, iter_center.idx); - for (int i=0; ioffsets_centers[i]); + for (int i = 0; i < sz[ndim - 1]; ++i) { + heat_flux_up[i] = gkyl_array_fetch(heat_flux, linc_vertex + gces->offsets_centers[i]); + } rhs_d = gkyl_array_fetch(rhs, linc_center); @@ -90,38 +89,33 @@ gkyl_ten_moment_grad_closure_advance(const gkyl_ten_moment_grad_closure *gces, gkyl_array_reduce(cfla, cflrate, GKYL_MAX); - if (cfla[0] > cflm) + if (cfla[0] > cflm) { is_cfl_violated = 1.0; + } // compute actual CFL, status & max-speed across all domains - double red_vars[2] = { cfla[0], is_cfl_violated }; - double red_vars_global[2] = { 0.0, 0.0 }; - gkyl_comm_allreduce(gces->comm, GKYL_DOUBLE, GKYL_MAX, 2, red_vars, - red_vars_global); + double red_vars[2] = {cfla[0], is_cfl_violated}; + double red_vars_global[2] = {0.0, 0.0}; + gkyl_comm_allreduce(gces->comm, GKYL_DOUBLE, GKYL_MAX, 2, red_vars, red_vars_global); cfla[0] = red_vars_global[0]; is_cfl_violated = red_vars_global[1]; - double dt_suggested = dt*cfl/fmax(cfla[0], DBL_MIN); + double dt_suggested = dt * cfl / fmax(cfla[0], DBL_MIN); if (is_cfl_violated > 0.0) { // indicate failure, and return smaller stable time-step - return (struct gkyl_ten_moment_grad_closure_status) { - .success = 0, - .dt_suggested = dt_suggested, - }; + return (struct gkyl_ten_moment_grad_closure_status){.success = 0, .dt_suggested = dt_suggested}; } // on success, suggest only bigger time-step; (Only way dt can // reduce is if the update fails. If the code comes here the update // succeeded and so we should not allow dt to reduce). - return (struct gkyl_ten_moment_grad_closure_status) { - .success = is_cfl_violated > 0.0 ? 0 : 1, - .dt_suggested = dt_suggested > dt ? dt_suggested : dt, + return (struct gkyl_ten_moment_grad_closure_status + ){.success = is_cfl_violated > 0.0 ? 0 : 1, .dt_suggested = dt_suggested > dt ? dt_suggested : dt }; } -void -gkyl_ten_moment_grad_closure_release(gkyl_ten_moment_grad_closure* up) +void gkyl_ten_moment_grad_closure_release(gkyl_ten_moment_grad_closure *up) { gkyl_comm_release(up->comm); gkyl_free(up->cfla); diff --git a/moments/zero/ten_moment_nn_closure.c b/moments/zero/ten_moment_nn_closure.c index fa3e44a0df..a34afad2f3 100644 --- a/moments/zero/ten_moment_nn_closure.c +++ b/moments/zero/ten_moment_nn_closure.c @@ -16,36 +16,27 @@ static const unsigned Q233 = 8; static const unsigned Q333 = 9; // 1D stencil locations (L: lower, U: upper). -enum loc_1d { - L_1D, U_1D -}; +enum loc_1d { L_1D, U_1D }; // 1D, second-order stencil locations (L2: lower, C2: center, U2: upper). -enum loc_1d_second_order { - L2_1D, C2_1D, U2_1D -}; +enum loc_1d_second_order { L2_1D, C2_1D, U2_1D }; // 2D stencil locations (L: lower, U: upper). -enum loc_2d { - LL_2D, LU_2D, - UL_2D, UU_2D -}; +enum loc_2d { LL_2D, LU_2D, UL_2D, UU_2D }; -struct gkyl_ten_moment_nn_closure -{ +struct gkyl_ten_moment_nn_closure { struct gkyl_rect_grid grid; // Grid on which to solve equations. int ndim; // Number of dimensions. int poly_order; // Polynomial order of learned DG coefficients. double k0; // Damping coefficient. - struct gkyl_kann_net* ann; // Neural network architecture. + struct gkyl_kann_net *ann; // Neural network architecture. }; -static void -create_offsets_vertices(const struct gkyl_range* range, long offsets[]) +static void create_offsets_vertices(const struct gkyl_range *range, long offsets[]) { // Box-spanning stencil. struct gkyl_range box3; - gkyl_range_init(&box3, range->ndim, (int[]) { -1, -1, -1 }, (int[]) { 0, 0, 0 }); + gkyl_range_init(&box3, range->ndim, (int[]){-1, -1, -1}, (int[]){0, 0, 0}); struct gkyl_range_iter iter3; gkyl_range_iter_init(&iter3, &box3); @@ -58,12 +49,11 @@ create_offsets_vertices(const struct gkyl_range* range, long offsets[]) } } -static void -create_offsets_centers(const struct gkyl_range *range, long offsets[]) +static void create_offsets_centers(const struct gkyl_range *range, long offsets[]) { // Box-spanning stencil. struct gkyl_range box3; - gkyl_range_init(&box3, range->ndim, (int[]) { 0, 0, 0 }, (int[]) { 1, 1, 1 }); + gkyl_range_init(&box3, range->ndim, (int[]){0, 0, 0}, (int[]){1, 1, 1}); struct gkyl_range_iter iter3; gkyl_range_iter_init(&iter3, &box3); @@ -76,8 +66,10 @@ create_offsets_centers(const struct gkyl_range *range, long offsets[]) } } -static void -var_setup(const gkyl_ten_moment_nn_closure *nnclosure, int start, int end, const double *fluid_d[], double rho[], double p[][6]) +static void var_setup( + const gkyl_ten_moment_nn_closure *nnclosure, int start, int end, const double *fluid_d[], + double rho[], double p[][6] +) { for (int j = start; j <= end; j++) { rho[j] = fluid_d[j][RHO]; @@ -90,8 +82,7 @@ var_setup(const gkyl_ten_moment_nn_closure *nnclosure, int start, int end, const } } -int -gkyl_ten_moment_nn_closure_n_in(const gkyl_ten_moment_nn_closure *nnclosure) +int gkyl_ten_moment_nn_closure_n_in(const gkyl_ten_moment_nn_closure *nnclosure) { const int ndim = nnclosure->ndim; const int poly_order = nnclosure->poly_order; @@ -101,8 +92,7 @@ gkyl_ten_moment_nn_closure_n_in(const gkyl_ten_moment_nn_closure *nnclosure) return 12; // ndim == 2, poly_order == 1. } -int -gkyl_ten_moment_nn_closure_n_out(const gkyl_ten_moment_nn_closure *nnclosure) +int gkyl_ten_moment_nn_closure_n_out(const gkyl_ten_moment_nn_closure *nnclosure) { const int ndim = nnclosure->ndim; const int poly_order = nnclosure->poly_order; @@ -118,9 +108,10 @@ gkyl_ten_moment_nn_closure_n_out(const gkyl_ten_moment_nn_closure *nnclosure) // cell-averaged density and pressure tensor) is computed exactly once per cell // here and reused in gkyl_ten_moment_nn_closure_construct, avoiding any duplicate work. // Exposed (non-static) for unit testing the geometry. -void -gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure, const double *fluid_d[], const double *em_tot_d[], float *input_data, - struct gkyl_ten_moment_nn_closure_geom *geom) +void gkyl_ten_moment_nn_closure_geom_calc( + const gkyl_ten_moment_nn_closure *nnclosure, const double *fluid_d[], const double *em_tot_d[], + float *input_data, struct gkyl_ten_moment_nn_closure_geom *geom +) { const int ndim = nnclosure->ndim; const int poly_order = nnclosure->poly_order; @@ -130,19 +121,19 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure double drho_dx_dx = 0.0; double drho_dx_dy = 0.0; - double p_avg[6] = { 0.0 }; - double dp_dx[6] = { 0.0 }; - double dp_dy[6] = { 0.0 }; - double dp_dz[6] = { 0.0 }; - double dp_dx_dx[6] = { 0.0 }; - double dp_dx_dy[6] = { 0.0 }; + double p_avg[6] = {0.0}; + double dp_dx[6] = {0.0}; + double dp_dy[6] = {0.0}; + double dp_dz[6] = {0.0}; + double dp_dx_dx[6] = {0.0}; + double dp_dx_dy[6] = {0.0}; - double B_avg[3] = { 0.0 }; - double dB_dx[3] = { 0.0 }; - double dB_dy[3] = { 0.0 }; - double dB_dz[3] = { 0.0 }; - double dB_dx_dx[3] = { 0.0 }; - double dB_dx_dy[3] = { 0.0 }; + double B_avg[3] = {0.0}; + double dB_dx[3] = {0.0}; + double dB_dy[3] = {0.0}; + double dB_dz[3] = {0.0}; + double dB_dx_dx[3] = {0.0}; + double dB_dx_dy[3] = {0.0}; // Initialize the geometry cache (entries not touched by a given branch stay // zero, e.g. local_mag_dy in 1D). @@ -158,10 +149,10 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure } if (ndim == 1) { - if (poly_order == 1 ) { + if (poly_order == 1) { const double dx = nnclosure->grid.dx[0]; - double rho[2] = { 0.0 }; - double p[2][6] = { 0.0 }; + double rho[2] = {0.0}; + double p[2][6] = {0.0}; var_setup(nnclosure, L_1D, U_1D, fluid_d, rho, p); rho_avg = calc_arithm_avg_1D(rho[L_1D], rho[U_1D]); @@ -186,15 +177,23 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure dB_dx[1] = calc_sym_grad_1D(dx, em_tot_d[L_1D][BY], em_tot_d[U_1D][BY]); dB_dx[2] = calc_sym_grad_1D(dx, em_tot_d[L_1D][BZ], em_tot_d[U_1D][BZ]); - if (fabs(B_avg[0]) < pow(10.0, -8.0) && fabs(B_avg[1]) < pow(10.0, -8.0) && fabs(B_avg[2]) < pow(10.0, -8.0)) { + if (fabs(B_avg[0]) < pow(10.0, -8.0) && fabs(B_avg[1]) < pow(10.0, -8.0) && + fabs(B_avg[2]) < pow(10.0, -8.0)) { B_avg[0] = 1.0; - dB_dx[0] = 0.0; dB_dx[1] = 0.0; dB_dx[2] = 0.0; - dB_dy[0] = 0.0; dB_dy[1] = 0.0; dB_dy[2] = 0.0; - dB_dz[0] = 0.0; dB_dz[1] = 0.0; dB_dz[2] = 0.0; + dB_dx[0] = 0.0; + dB_dx[1] = 0.0; + dB_dx[2] = 0.0; + dB_dy[0] = 0.0; + dB_dy[1] = 0.0; + dB_dy[2] = 0.0; + dB_dz[0] = 0.0; + dB_dz[1] = 0.0; + dB_dz[2] = 0.0; } double b_mag = sqrt((B_avg[0] * B_avg[0]) + (B_avg[1] * B_avg[1]) + (B_avg[2] * B_avg[2])); - double b_mag_dx = ((B_avg[0] * dB_dx[0]) + (B_avg[1] * dB_dx[1]) + (B_avg[2] * dB_dx[2])) / b_mag; + double b_mag_dx = + ((B_avg[0] * dB_dx[0]) + (B_avg[1] * dB_dx[1]) + (B_avg[2] * dB_dx[2])) / b_mag; double local_mag[3]; for (int i = 0; i < 3; i++) { @@ -209,13 +208,25 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure double p_tensor[3][3]; double p_tensor_dx[3][3]; - p_tensor[0][0] = p_avg[0]; p_tensor[0][1] = p_avg[1]; p_tensor[0][2] = p_avg[2]; - p_tensor[1][0] = p_avg[1]; p_tensor[1][1] = p_avg[3]; p_tensor[1][2] = p_avg[4]; - p_tensor[2][0] = p_avg[2]; p_tensor[2][1] = p_avg[4]; p_tensor[2][2] = p_avg[5]; - - p_tensor_dx[0][0] = dp_dx[0]; p_tensor_dx[0][1] = dp_dx[1]; p_tensor_dx[0][2] = dp_dx[2]; - p_tensor_dx[1][0] = dp_dx[1]; p_tensor_dx[1][1] = dp_dx[3]; p_tensor_dx[1][2] = dp_dx[4]; - p_tensor_dx[2][0] = dp_dx[2]; p_tensor_dx[2][1] = dp_dx[4]; p_tensor_dx[2][2] = dp_dx[5]; + p_tensor[0][0] = p_avg[0]; + p_tensor[0][1] = p_avg[1]; + p_tensor[0][2] = p_avg[2]; + p_tensor[1][0] = p_avg[1]; + p_tensor[1][1] = p_avg[3]; + p_tensor[1][2] = p_avg[4]; + p_tensor[2][0] = p_avg[2]; + p_tensor[2][1] = p_avg[4]; + p_tensor[2][2] = p_avg[5]; + + p_tensor_dx[0][0] = dp_dx[0]; + p_tensor_dx[0][1] = dp_dx[1]; + p_tensor_dx[0][2] = dp_dx[2]; + p_tensor_dx[1][0] = dp_dx[1]; + p_tensor_dx[1][1] = dp_dx[3]; + p_tensor_dx[1][2] = dp_dx[4]; + p_tensor_dx[2][0] = dp_dx[2]; + p_tensor_dx[2][1] = dp_dx[4]; + p_tensor_dx[2][2] = dp_dx[5]; double p_par = 0.0; for (int i = 0; i < 3; i++) { @@ -263,11 +274,10 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure geom->local_mag[i] = local_mag[i]; geom->local_mag_dx[i] = local_mag_dx[i]; } - } - else if (poly_order == 2) { + } else if (poly_order == 2) { const double dx = nnclosure->grid.dx[0]; - double rho[3] = { 0.0 }; - double p[3][6] = { 0.0 }; + double rho[3] = {0.0}; + double p[3][6] = {0.0}; var_setup(nnclosure, L2_1D, U2_1D, fluid_d, rho, p); rho_avg = calc_arithm_avg_1D(rho[L2_1D], rho[U2_1D]); @@ -299,21 +309,36 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure dp_dx_dx[3] = calc_sym_grad2_1D(dx, p[L2_1D][3], p[C2_1D][3], p[U2_1D][3]); dp_dx_dx[4] = calc_sym_grad2_1D(dx, p[L2_1D][4], p[C2_1D][4], p[U2_1D][4]); dp_dx_dx[5] = calc_sym_grad2_1D(dx, p[L2_1D][5], p[C2_1D][5], p[U2_1D][5]); - dB_dx_dx[0] = calc_sym_grad2_1D(dx, em_tot_d[L2_1D][BX], em_tot_d[C2_1D][BX], em_tot_d[U2_1D][BX]); - dB_dx_dx[1] = calc_sym_grad2_1D(dx, em_tot_d[L2_1D][BY], em_tot_d[C2_1D][BY], em_tot_d[U2_1D][BY]); - dB_dx_dx[2] = calc_sym_grad2_1D(dx, em_tot_d[L2_1D][BZ], em_tot_d[C2_1D][BZ], em_tot_d[U2_1D][BZ]); - - if (fabs(B_avg[0]) < pow(10.0, -8.0) && fabs(B_avg[1]) < pow(10.0, -8.0) && fabs(B_avg[2]) < pow(10.0, -8.0)) { + dB_dx_dx[0] = + calc_sym_grad2_1D(dx, em_tot_d[L2_1D][BX], em_tot_d[C2_1D][BX], em_tot_d[U2_1D][BX]); + dB_dx_dx[1] = + calc_sym_grad2_1D(dx, em_tot_d[L2_1D][BY], em_tot_d[C2_1D][BY], em_tot_d[U2_1D][BY]); + dB_dx_dx[2] = + calc_sym_grad2_1D(dx, em_tot_d[L2_1D][BZ], em_tot_d[C2_1D][BZ], em_tot_d[U2_1D][BZ]); + + if (fabs(B_avg[0]) < pow(10.0, -8.0) && fabs(B_avg[1]) < pow(10.0, -8.0) && + fabs(B_avg[2]) < pow(10.0, -8.0)) { B_avg[0] = 1.0; - dB_dx[0] = 0.0; dB_dx[1] = 0.0; dB_dx[2] = 0.0; - dB_dy[0] = 0.0; dB_dy[1] = 0.0; dB_dy[2] = 0.0; - dB_dz[0] = 0.0; dB_dz[1] = 0.0; dB_dz[2] = 0.0; - dB_dx_dx[0] = 0.0; dB_dx_dx[1] = 0.0; dB_dx_dx[2] = 0.0; + dB_dx[0] = 0.0; + dB_dx[1] = 0.0; + dB_dx[2] = 0.0; + dB_dy[0] = 0.0; + dB_dy[1] = 0.0; + dB_dy[2] = 0.0; + dB_dz[0] = 0.0; + dB_dz[1] = 0.0; + dB_dz[2] = 0.0; + dB_dx_dx[0] = 0.0; + dB_dx_dx[1] = 0.0; + dB_dx_dx[2] = 0.0; } double b_mag = sqrt((B_avg[0] * B_avg[0]) + (B_avg[1] * B_avg[1]) + (B_avg[2] * B_avg[2])); - double b_mag_dx = ((B_avg[0] * dB_dx[0]) + (B_avg[1] * dB_dx[1]) + (B_avg[2] * dB_dx[2])) / b_mag; - double b_mag_dx_dx = b_mag * ((dB_dx[0] * dB_dx[0]) + (B_avg[0] * dB_dx_dx[0]) + (dB_dx[1] * dB_dx[1]) + (B_avg[1] * dB_dx_dx[1]) + (dB_dx[2] * dB_dy[2]) + (B_avg[2] * dB_dx_dy[2])); + double b_mag_dx = + ((B_avg[0] * dB_dx[0]) + (B_avg[1] * dB_dx[1]) + (B_avg[2] * dB_dx[2])) / b_mag; + double b_mag_dx_dx = + b_mag * ((dB_dx[0] * dB_dx[0]) + (B_avg[0] * dB_dx_dx[0]) + (dB_dx[1] * dB_dx[1]) + + (B_avg[1] * dB_dx_dx[1]) + (dB_dx[2] * dB_dy[2]) + (B_avg[2] * dB_dx_dy[2])); b_mag_dx_dx -= b_mag_dx * b_mag_dx; b_mag_dx_dx /= b_mag * b_mag; @@ -327,7 +352,8 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure double local_mag_dx_dx[3]; for (int i = 0; i < 3; i++) { local_mag_dx[i] = ((b_mag * dB_dx[i]) - (B_avg[i] * b_mag_dx)) / (b_mag * b_mag); - local_mag_dx_dx[i] = (b_mag * b_mag) * ((b_mag_dx * dB_dx[i]) + (b_mag * dB_dx_dx[i]) - (dB_dx[i] * b_mag_dx) * (B_avg[i] * b_mag_dx_dx)); + local_mag_dx_dx[i] = (b_mag * b_mag) * ((b_mag_dx * dB_dx[i]) + (b_mag * dB_dx_dx[i]) - + (dB_dx[i] * b_mag_dx) * (B_avg[i] * b_mag_dx_dx)); local_mag_dx_dx[i] -= 2.0 * ((b_mag * dB_dx[i]) - (B_avg[i] * b_mag_dx)) * b_mag * b_mag_dx; local_mag_dx_dx[i] /= b_mag * b_mag * b_mag * b_mag; } @@ -336,17 +362,35 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure double p_tensor_dx[3][3]; double p_tensor_dx_dx[3][3]; - p_tensor[0][0] = p_avg[0]; p_tensor[0][1] = p_avg[1]; p_tensor[0][2] = p_avg[2]; - p_tensor[1][0] = p_avg[1]; p_tensor[1][1] = p_avg[3]; p_tensor[1][2] = p_avg[4]; - p_tensor[2][0] = p_avg[2]; p_tensor[2][1] = p_avg[4]; p_tensor[2][2] = p_avg[5]; - - p_tensor_dx[0][0] = dp_dx[0]; p_tensor_dx[0][1] = dp_dx[1]; p_tensor_dx[0][2] = dp_dx[2]; - p_tensor_dx[1][0] = dp_dx[1]; p_tensor_dx[1][1] = dp_dx[3]; p_tensor_dx[1][2] = dp_dx[4]; - p_tensor_dx[2][0] = dp_dx[2]; p_tensor_dx[2][1] = dp_dx[4]; p_tensor_dx[2][2] = dp_dx[5]; - - p_tensor_dx_dx[0][0] = dp_dx_dx[0]; p_tensor_dx_dx[0][1] = dp_dx_dx[1]; p_tensor_dx_dx[0][2] = dp_dx_dx[2]; - p_tensor_dx_dx[1][0] = dp_dx_dx[1]; p_tensor_dx_dx[1][1] = dp_dx_dx[3]; p_tensor_dx_dx[1][2] = dp_dx_dx[4]; - p_tensor_dx_dx[2][0] = dp_dx_dx[2]; p_tensor_dx_dx[2][1] = dp_dx_dx[4]; p_tensor_dx_dx[2][2] = dp_dx_dx[5]; + p_tensor[0][0] = p_avg[0]; + p_tensor[0][1] = p_avg[1]; + p_tensor[0][2] = p_avg[2]; + p_tensor[1][0] = p_avg[1]; + p_tensor[1][1] = p_avg[3]; + p_tensor[1][2] = p_avg[4]; + p_tensor[2][0] = p_avg[2]; + p_tensor[2][1] = p_avg[4]; + p_tensor[2][2] = p_avg[5]; + + p_tensor_dx[0][0] = dp_dx[0]; + p_tensor_dx[0][1] = dp_dx[1]; + p_tensor_dx[0][2] = dp_dx[2]; + p_tensor_dx[1][0] = dp_dx[1]; + p_tensor_dx[1][1] = dp_dx[3]; + p_tensor_dx[1][2] = dp_dx[4]; + p_tensor_dx[2][0] = dp_dx[2]; + p_tensor_dx[2][1] = dp_dx[4]; + p_tensor_dx[2][2] = dp_dx[5]; + + p_tensor_dx_dx[0][0] = dp_dx_dx[0]; + p_tensor_dx_dx[0][1] = dp_dx_dx[1]; + p_tensor_dx_dx[0][2] = dp_dx_dx[2]; + p_tensor_dx_dx[1][0] = dp_dx_dx[1]; + p_tensor_dx_dx[1][1] = dp_dx_dx[3]; + p_tensor_dx_dx[1][2] = dp_dx_dx[4]; + p_tensor_dx_dx[2][0] = dp_dx_dx[2]; + p_tensor_dx_dx[2][1] = dp_dx_dx[4]; + p_tensor_dx_dx[2][2] = dp_dx_dx[5]; double p_par = 0.0; for (int i = 0; i < 3; i++) { @@ -413,13 +457,12 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure geom->local_mag_dx[i] = local_mag_dx[i]; } } - } - else if (ndim == 2) { + } else if (ndim == 2) { if (poly_order == 1) { const double dx = nnclosure->grid.dx[0]; const double dy = nnclosure->grid.dx[1]; - double rho[4] = { 0.0 }; - double p[4][6] = { 0.0 }; + double rho[4] = {0.0}; + double p[4][6] = {0.0}; var_setup(nnclosure, LL_2D, UU_2D, fluid_d, rho, p); rho_avg = calc_arithm_avg_2D(rho[LL_2D], rho[LU_2D], rho[UL_2D], rho[UU_2D]); @@ -429,9 +472,15 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure p_avg[3] = calc_arithm_avg_2D(p[LL_2D][3], p[LU_2D][3], p[UL_2D][3], p[UU_2D][3]); p_avg[4] = calc_arithm_avg_2D(p[LL_2D][4], p[LU_2D][4], p[UL_2D][4], p[UU_2D][4]); p_avg[5] = calc_arithm_avg_2D(p[LL_2D][5], p[LU_2D][5], p[UL_2D][5], p[UU_2D][5]); - B_avg[0] = calc_arithm_avg_2D(em_tot_d[LL_2D][BX], em_tot_d[LU_2D][BX], em_tot_d[UL_2D][BX], em_tot_d[UU_2D][BX]); - B_avg[1] = calc_arithm_avg_2D(em_tot_d[LL_2D][BY], em_tot_d[LU_2D][BY], em_tot_d[UL_2D][BY], em_tot_d[UU_2D][BY]); - B_avg[2] = calc_arithm_avg_2D(em_tot_d[LL_2D][BZ], em_tot_d[LU_2D][BZ], em_tot_d[UL_2D][BZ], em_tot_d[UU_2D][BZ]); + B_avg[0] = calc_arithm_avg_2D( + em_tot_d[LL_2D][BX], em_tot_d[LU_2D][BX], em_tot_d[UL_2D][BX], em_tot_d[UU_2D][BX] + ); + B_avg[1] = calc_arithm_avg_2D( + em_tot_d[LL_2D][BY], em_tot_d[LU_2D][BY], em_tot_d[UL_2D][BY], em_tot_d[UU_2D][BY] + ); + B_avg[2] = calc_arithm_avg_2D( + em_tot_d[LL_2D][BZ], em_tot_d[LU_2D][BZ], em_tot_d[UL_2D][BZ], em_tot_d[UU_2D][BZ] + ); drho_dx = calc_sym_gradx_2D(dx, rho[LL_2D], rho[LU_2D], rho[UL_2D], rho[UU_2D]); dp_dx[0] = calc_sym_gradx_2D(dx, p[LL_2D][0], p[LU_2D][0], p[UL_2D][0], p[UU_2D][0]); @@ -440,9 +489,15 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure dp_dx[3] = calc_sym_gradx_2D(dx, p[LL_2D][3], p[LU_2D][3], p[UL_2D][3], p[UU_2D][3]); dp_dx[4] = calc_sym_gradx_2D(dx, p[LL_2D][4], p[LU_2D][4], p[UL_2D][4], p[UU_2D][4]); dp_dx[5] = calc_sym_gradx_2D(dx, p[LL_2D][5], p[LU_2D][5], p[UL_2D][5], p[UU_2D][5]); - dB_dx[0] = calc_sym_gradx_2D(dx, em_tot_d[LL_2D][BX], em_tot_d[LU_2D][BX], em_tot_d[UL_2D][BX], em_tot_d[UU_2D][BX]); - dB_dx[1] = calc_sym_gradx_2D(dx, em_tot_d[LL_2D][BY], em_tot_d[LU_2D][BY], em_tot_d[UL_2D][BY], em_tot_d[UU_2D][BY]); - dB_dx[2] = calc_sym_gradx_2D(dx, em_tot_d[LL_2D][BZ], em_tot_d[LU_2D][BZ], em_tot_d[UL_2D][BZ], em_tot_d[UU_2D][BZ]); + dB_dx[0] = calc_sym_gradx_2D( + dx, em_tot_d[LL_2D][BX], em_tot_d[LU_2D][BX], em_tot_d[UL_2D][BX], em_tot_d[UU_2D][BX] + ); + dB_dx[1] = calc_sym_gradx_2D( + dx, em_tot_d[LL_2D][BY], em_tot_d[LU_2D][BY], em_tot_d[UL_2D][BY], em_tot_d[UU_2D][BY] + ); + dB_dx[2] = calc_sym_gradx_2D( + dx, em_tot_d[LL_2D][BZ], em_tot_d[LU_2D][BZ], em_tot_d[UL_2D][BZ], em_tot_d[UU_2D][BZ] + ); drho_dy = calc_sym_grady_2D(dy, rho[LL_2D], rho[LU_2D], rho[UL_2D], rho[UU_2D]); dp_dy[0] = calc_sym_grady_2D(dy, p[LL_2D][0], p[LU_2D][0], p[UL_2D][0], p[UU_2D][0]); @@ -451,9 +506,15 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure dp_dy[3] = calc_sym_grady_2D(dy, p[LL_2D][3], p[LU_2D][3], p[UL_2D][3], p[UU_2D][3]); dp_dy[4] = calc_sym_grady_2D(dy, p[LL_2D][4], p[LU_2D][4], p[UL_2D][4], p[UU_2D][4]); dp_dy[5] = calc_sym_grady_2D(dy, p[LL_2D][5], p[LU_2D][5], p[UL_2D][5], p[UU_2D][5]); - dB_dy[0] = calc_sym_grady_2D(dy, em_tot_d[LL_2D][BX], em_tot_d[LU_2D][BX], em_tot_d[UL_2D][BX], em_tot_d[UU_2D][BX]); - dB_dy[1] = calc_sym_grady_2D(dy, em_tot_d[LL_2D][BY], em_tot_d[LU_2D][BY], em_tot_d[UL_2D][BY], em_tot_d[UU_2D][BY]); - dB_dy[2] = calc_sym_grady_2D(dy, em_tot_d[LL_2D][BZ], em_tot_d[LU_2D][BZ], em_tot_d[UL_2D][BZ], em_tot_d[UU_2D][BZ]); + dB_dy[0] = calc_sym_grady_2D( + dy, em_tot_d[LL_2D][BX], em_tot_d[LU_2D][BX], em_tot_d[UL_2D][BX], em_tot_d[UU_2D][BX] + ); + dB_dy[1] = calc_sym_grady_2D( + dy, em_tot_d[LL_2D][BY], em_tot_d[LU_2D][BY], em_tot_d[UL_2D][BY], em_tot_d[UU_2D][BY] + ); + dB_dy[2] = calc_sym_grady_2D( + dy, em_tot_d[LL_2D][BZ], em_tot_d[LU_2D][BZ], em_tot_d[UL_2D][BZ], em_tot_d[UU_2D][BZ] + ); drho_dx_dy = calc_sym_gradxy_2D(dx, dy, rho[LL_2D], rho[LU_2D], rho[UL_2D], rho[UU_2D]); dp_dx_dy[0] = calc_sym_gradxy_2D(dx, dy, p[LL_2D][0], p[LU_2D][0], p[UL_2D][0], p[UU_2D][0]); @@ -462,22 +523,41 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure dp_dx_dy[3] = calc_sym_gradxy_2D(dx, dy, p[LL_2D][3], p[LU_2D][3], p[UL_2D][3], p[UU_2D][3]); dp_dx_dy[4] = calc_sym_gradxy_2D(dx, dy, p[LL_2D][4], p[LU_2D][4], p[UL_2D][4], p[UU_2D][4]); dp_dx_dy[5] = calc_sym_gradxy_2D(dx, dy, p[LL_2D][5], p[LU_2D][5], p[UL_2D][5], p[UU_2D][5]); - dB_dx_dy[0] = calc_sym_gradxy_2D(dx, dy, em_tot_d[LL_2D][BX], em_tot_d[LU_2D][BX], em_tot_d[UL_2D][BX], em_tot_d[UU_2D][BX]); - dB_dx_dy[1] = calc_sym_gradxy_2D(dx, dy, em_tot_d[LL_2D][BY], em_tot_d[LU_2D][BY], em_tot_d[UL_2D][BY], em_tot_d[UU_2D][BY]); - dB_dx_dy[2] = calc_sym_gradxy_2D(dx, dy, em_tot_d[LL_2D][BZ], em_tot_d[LU_2D][BZ], em_tot_d[UL_2D][BZ], em_tot_d[UU_2D][BZ]); - - if (fabs(B_avg[0]) < pow(10.0, -8.0) && fabs(B_avg[1]) < pow(10.0, -8.0) && fabs(B_avg[2]) < pow(10.0, -8.0)) { + dB_dx_dy[0] = calc_sym_gradxy_2D( + dx, dy, em_tot_d[LL_2D][BX], em_tot_d[LU_2D][BX], em_tot_d[UL_2D][BX], em_tot_d[UU_2D][BX] + ); + dB_dx_dy[1] = calc_sym_gradxy_2D( + dx, dy, em_tot_d[LL_2D][BY], em_tot_d[LU_2D][BY], em_tot_d[UL_2D][BY], em_tot_d[UU_2D][BY] + ); + dB_dx_dy[2] = calc_sym_gradxy_2D( + dx, dy, em_tot_d[LL_2D][BZ], em_tot_d[LU_2D][BZ], em_tot_d[UL_2D][BZ], em_tot_d[UU_2D][BZ] + ); + + if (fabs(B_avg[0]) < pow(10.0, -8.0) && fabs(B_avg[1]) < pow(10.0, -8.0) && + fabs(B_avg[2]) < pow(10.0, -8.0)) { B_avg[0] = 1.0; - dB_dx[0] = 0.0; dB_dx[1] = 0.0; dB_dx[2] = 0.0; - dB_dy[0] = 0.0; dB_dy[1] = 0.0; dB_dy[2] = 0.0; - dB_dz[0] = 0.0; dB_dz[1] = 0.0; dB_dz[2] = 0.0; - dB_dx_dy[0] = 0.0; dB_dx_dy[1] = 0.0; dB_dx_dy[2] = 0.0; + dB_dx[0] = 0.0; + dB_dx[1] = 0.0; + dB_dx[2] = 0.0; + dB_dy[0] = 0.0; + dB_dy[1] = 0.0; + dB_dy[2] = 0.0; + dB_dz[0] = 0.0; + dB_dz[1] = 0.0; + dB_dz[2] = 0.0; + dB_dx_dy[0] = 0.0; + dB_dx_dy[1] = 0.0; + dB_dx_dy[2] = 0.0; } double b_mag = sqrt((B_avg[0] * B_avg[0]) + (B_avg[1] * B_avg[1]) + (B_avg[2] * B_avg[2])); - double b_mag_dx = ((B_avg[0] * dB_dx[0]) + (B_avg[1] * dB_dx[1]) + (B_avg[2] * dB_dx[2])) / b_mag; - double b_mag_dy = ((B_avg[0] * dB_dy[0]) + (B_avg[1] * dB_dy[1]) + (B_avg[2] * dB_dy[2])) / b_mag; - double b_mag_dx_dy = b_mag * ((dB_dx[0] * dB_dy[0]) + (B_avg[0] * dB_dx_dy[0]) + (dB_dx[1] * dB_dy[1]) + (B_avg[1] * dB_dx_dy[1]) + (dB_dx[2] * dB_dy[2]) + (B_avg[2] * dB_dx_dy[2])); + double b_mag_dx = + ((B_avg[0] * dB_dx[0]) + (B_avg[1] * dB_dx[1]) + (B_avg[2] * dB_dx[2])) / b_mag; + double b_mag_dy = + ((B_avg[0] * dB_dy[0]) + (B_avg[1] * dB_dy[1]) + (B_avg[2] * dB_dy[2])) / b_mag; + double b_mag_dx_dy = + b_mag * ((dB_dx[0] * dB_dy[0]) + (B_avg[0] * dB_dx_dy[0]) + (dB_dx[1] * dB_dy[1]) + + (B_avg[1] * dB_dx_dy[1]) + (dB_dx[2] * dB_dy[2]) + (B_avg[2] * dB_dx_dy[2])); b_mag_dx_dy -= b_mag_dx * b_mag_dy; b_mag_dx_dy /= b_mag * b_mag; @@ -492,7 +572,8 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure for (int i = 0; i < 3; i++) { local_mag_dx[i] = ((b_mag * dB_dx[i]) - (B_avg[i] * b_mag_dx)) / (b_mag * b_mag); local_mag_dy[i] = ((b_mag * dB_dy[i]) - (B_avg[i] * b_mag_dy)) / (b_mag * b_mag); - local_mag_dx_dy[i] = (b_mag * b_mag) * ((b_mag_dy * dB_dx[i]) + (b_mag * dB_dx_dy[i]) - (dB_dy[i] * b_mag_dx) * (B_avg[i] * b_mag_dx_dy)); + local_mag_dx_dy[i] = (b_mag * b_mag) * ((b_mag_dy * dB_dx[i]) + (b_mag * dB_dx_dy[i]) - + (dB_dy[i] * b_mag_dx) * (B_avg[i] * b_mag_dx_dy)); local_mag_dx_dy[i] -= 2.0 * ((b_mag * dB_dx[i]) - (B_avg[i] * b_mag_dx)) * b_mag * b_mag_dy; local_mag_dx_dy[i] /= b_mag * b_mag * b_mag * b_mag; } @@ -502,21 +583,45 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure double p_tensor_dy[3][3]; double p_tensor_dx_dy[3][3]; - p_tensor[0][0] = p_avg[0]; p_tensor[0][1] = p_avg[1]; p_tensor[0][2] = p_avg[2]; - p_tensor[1][0] = p_avg[1]; p_tensor[1][1] = p_avg[3]; p_tensor[1][2] = p_avg[4]; - p_tensor[2][0] = p_avg[2]; p_tensor[2][1] = p_avg[4]; p_tensor[2][2] = p_avg[5]; - - p_tensor_dx[0][0] = dp_dx[0]; p_tensor_dx[0][1] = dp_dx[1]; p_tensor_dx[0][2] = dp_dx[2]; - p_tensor_dx[1][0] = dp_dx[1]; p_tensor_dx[1][1] = dp_dx[3]; p_tensor_dx[1][2] = dp_dx[4]; - p_tensor_dx[2][0] = dp_dx[2]; p_tensor_dx[2][1] = dp_dx[4]; p_tensor_dx[2][2] = dp_dx[5]; - - p_tensor_dy[0][0] = dp_dy[0]; p_tensor_dy[0][1] = dp_dy[1]; p_tensor_dy[0][2] = dp_dy[2]; - p_tensor_dy[1][0] = dp_dy[1]; p_tensor_dy[1][1] = dp_dy[3]; p_tensor_dy[1][2] = dp_dy[4]; - p_tensor_dy[2][0] = dp_dy[2]; p_tensor_dy[2][1] = dp_dy[4]; p_tensor_dy[2][2] = dp_dy[5]; - - p_tensor_dx_dy[0][0] = dp_dx_dy[0]; p_tensor_dx_dy[0][1] = dp_dx_dy[1]; p_tensor_dx_dy[0][2] = dp_dx_dy[2]; - p_tensor_dx_dy[1][0] = dp_dx_dy[1]; p_tensor_dx_dy[1][1] = dp_dx_dy[3]; p_tensor_dx_dy[1][2] = dp_dx_dy[4]; - p_tensor_dx_dy[2][0] = dp_dx_dy[2]; p_tensor_dx_dy[2][1] = dp_dx_dy[4]; p_tensor_dx_dy[2][2] = dp_dx_dy[5]; + p_tensor[0][0] = p_avg[0]; + p_tensor[0][1] = p_avg[1]; + p_tensor[0][2] = p_avg[2]; + p_tensor[1][0] = p_avg[1]; + p_tensor[1][1] = p_avg[3]; + p_tensor[1][2] = p_avg[4]; + p_tensor[2][0] = p_avg[2]; + p_tensor[2][1] = p_avg[4]; + p_tensor[2][2] = p_avg[5]; + + p_tensor_dx[0][0] = dp_dx[0]; + p_tensor_dx[0][1] = dp_dx[1]; + p_tensor_dx[0][2] = dp_dx[2]; + p_tensor_dx[1][0] = dp_dx[1]; + p_tensor_dx[1][1] = dp_dx[3]; + p_tensor_dx[1][2] = dp_dx[4]; + p_tensor_dx[2][0] = dp_dx[2]; + p_tensor_dx[2][1] = dp_dx[4]; + p_tensor_dx[2][2] = dp_dx[5]; + + p_tensor_dy[0][0] = dp_dy[0]; + p_tensor_dy[0][1] = dp_dy[1]; + p_tensor_dy[0][2] = dp_dy[2]; + p_tensor_dy[1][0] = dp_dy[1]; + p_tensor_dy[1][1] = dp_dy[3]; + p_tensor_dy[1][2] = dp_dy[4]; + p_tensor_dy[2][0] = dp_dy[2]; + p_tensor_dy[2][1] = dp_dy[4]; + p_tensor_dy[2][2] = dp_dy[5]; + + p_tensor_dx_dy[0][0] = dp_dx_dy[0]; + p_tensor_dx_dy[0][1] = dp_dx_dy[1]; + p_tensor_dx_dy[0][2] = dp_dx_dy[2]; + p_tensor_dx_dy[1][0] = dp_dx_dy[1]; + p_tensor_dx_dy[1][1] = dp_dx_dy[3]; + p_tensor_dx_dy[1][2] = dp_dx_dy[4]; + p_tensor_dx_dy[2][0] = dp_dx_dy[2]; + p_tensor_dx_dy[2][1] = dp_dx_dy[4]; + p_tensor_dx_dy[2][2] = dp_dx_dy[5]; double p_par = 0.0; for (int i = 0; i < 3; i++) { @@ -603,8 +708,10 @@ gkyl_ten_moment_nn_closure_geom_calc(const gkyl_ten_moment_nn_closure *nnclosure // then write the closure contribution into rhs. This is the second half of the // former calc_nn_closure_update, reading the geometry from the cache rather // than recomputing it. Exposed (non-static) for unit testing the coupling. -void -gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure, const struct gkyl_ten_moment_nn_closure_geom *geom, const float *output_data_predicted, double *rhs) +void gkyl_ten_moment_nn_closure_construct( + const gkyl_ten_moment_nn_closure *nnclosure, const struct gkyl_ten_moment_nn_closure_geom *geom, + const float *output_data_predicted, double *rhs +) { const int ndim = nnclosure->ndim; const int poly_order = nnclosure->poly_order; @@ -617,10 +724,10 @@ gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure local_mag_dy[i] = geom->local_mag_dy[i]; } - double output_data[8] = { 0.0 }; - double divQx[6] = { 0.0 }; - double divQy[6] = { 0.0 }; - double divQz[6] = { 0.0 }; + double output_data[8] = {0.0}; + double divQx[6] = {0.0}; + double divQy[6] = {0.0}; + double divQz[6] = {0.0}; if (ndim == 1) { if (poly_order == 1) { @@ -641,23 +748,23 @@ gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure heat_flux_tensor[i][j][k] = q_par * local_mag[i] * local_mag[j] * local_mag[k]; if (i == j) { - heat_flux_tensor[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k]; - } - else { + heat_flux_tensor[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k]; + } else { heat_flux_tensor[i][j][k] -= q_perp * (local_mag[i] * local_mag[j]) * local_mag[k]; } if (i == k) { - heat_flux_tensor[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j]; - } - else { + heat_flux_tensor[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j]; + } else { heat_flux_tensor[i][j][k] -= q_perp * (local_mag[i] * local_mag[k]) * local_mag[j]; } if (j == k) { - heat_flux_tensor[i][j][k] += q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i]; - } - else { + heat_flux_tensor[i][j][k] += + q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i]; + } else { heat_flux_tensor[i][j][k] -= q_perp * (local_mag[j] * local_mag[k]) * local_mag[i]; } } @@ -675,35 +782,47 @@ gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure heat_flux_tensor_dx[i][j][k] += q_par * local_mag[i] * local_mag[j] * local_mag_dx[k]; if (i == j) { - heat_flux_tensor_dx[i][j][k] += (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag_dx[k]; - } - else { - heat_flux_tensor_dx[i][j][k] -= (local_mag[i] * local_mag[j]) * local_mag[k] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (local_mag[i] * local_mag[j]) * local_mag_dx[k]; + heat_flux_tensor_dx[i][j][k] += + (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag_dx[k]; + } else { + heat_flux_tensor_dx[i][j][k] -= + (local_mag[i] * local_mag[j]) * local_mag[k] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (local_mag[i] * local_mag[j]) * local_mag_dx[k]; } if (i == k) { - heat_flux_tensor_dx[i][j][k] += (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag_dx[j]; - } - else { - heat_flux_tensor_dx[i][j][k] -= (local_mag[i] * local_mag[k]) * local_mag[j] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (local_mag[i] * local_mag[k]) * local_mag_dx[j]; + heat_flux_tensor_dx[i][j][k] += + (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag_dx[j]; + } else { + heat_flux_tensor_dx[i][j][k] -= + (local_mag[i] * local_mag[k]) * local_mag[j] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (local_mag[i] * local_mag[k]) * local_mag_dx[j]; } if (j == k) { - heat_flux_tensor_dx[i][j][k] += (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag_dx[i]; - } - else { - heat_flux_tensor_dx[i][j][k] -= (local_mag[j] * local_mag[k]) * local_mag[i] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (local_mag[j] * local_mag[k]) * local_mag_dx[i]; + heat_flux_tensor_dx[i][j][k] += + (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag_dx[i]; + } else { + heat_flux_tensor_dx[i][j][k] -= + (local_mag[j] * local_mag[k]) * local_mag[i] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (local_mag[j] * local_mag[k]) * local_mag_dx[i]; } - heat_flux_tensor_dx[i][j][k] -= ((local_mag[i] * local_mag_dx[j]) + (local_mag[j] * local_mag_dx[i])) * local_mag[k]; - heat_flux_tensor_dx[i][j][k] -= ((local_mag[i] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[i])) * local_mag[j]; - heat_flux_tensor_dx[i][j][k] -= ((local_mag[j] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[j])) * local_mag[i]; + heat_flux_tensor_dx[i][j][k] -= + ((local_mag[i] * local_mag_dx[j]) + (local_mag[j] * local_mag_dx[i])) * local_mag[k]; + heat_flux_tensor_dx[i][j][k] -= + ((local_mag[i] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[i])) * local_mag[j]; + heat_flux_tensor_dx[i][j][k] -= + ((local_mag[j] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[j])) * local_mag[i]; } } } @@ -714,8 +833,7 @@ gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure divQx[3] = B_avg[0] * heat_flux_tensor_dx[0][1][1]; divQx[4] = B_avg[0] * heat_flux_tensor_dx[0][1][2]; divQx[5] = B_avg[0] * heat_flux_tensor_dx[0][2][2]; - } - else if (poly_order == 2) { + } else if (poly_order == 2) { for (int i = 0; i < 6; i++) { output_data[i] = output_data_predicted[i]; } @@ -733,23 +851,23 @@ gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure heat_flux_tensor[i][j][k] = q_par * local_mag[i] * local_mag[j] * local_mag[k]; if (i == j) { - heat_flux_tensor[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k]; - } - else { + heat_flux_tensor[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k]; + } else { heat_flux_tensor[i][j][k] -= q_perp * (local_mag[i] * local_mag[j]) * local_mag[k]; } if (i == k) { - heat_flux_tensor[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j]; - } - else { + heat_flux_tensor[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j]; + } else { heat_flux_tensor[i][j][k] -= q_perp * (local_mag[i] * local_mag[k]) * local_mag[j]; } if (j == k) { - heat_flux_tensor[i][j][k] += q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i]; - } - else { + heat_flux_tensor[i][j][k] += + q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i]; + } else { heat_flux_tensor[i][j][k] -= q_perp * (local_mag[j] * local_mag[k]) * local_mag[i]; } } @@ -767,35 +885,47 @@ gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure heat_flux_tensor_dx[i][j][k] += q_par * local_mag[i] * local_mag[j] * local_mag_dx[k]; if (i == j) { - heat_flux_tensor_dx[i][j][k] += (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag_dx[k]; - } - else { - heat_flux_tensor_dx[i][j][k] -= (local_mag[i] * local_mag[j]) * local_mag[k] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (local_mag[i] * local_mag[j]) * local_mag_dx[k]; + heat_flux_tensor_dx[i][j][k] += + (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag_dx[k]; + } else { + heat_flux_tensor_dx[i][j][k] -= + (local_mag[i] * local_mag[j]) * local_mag[k] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (local_mag[i] * local_mag[j]) * local_mag_dx[k]; } if (i == k) { - heat_flux_tensor_dx[i][j][k] += (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag_dx[j]; - } - else { - heat_flux_tensor_dx[i][j][k] -= (local_mag[i] * local_mag[k]) * local_mag[j] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (local_mag[i] * local_mag[k]) * local_mag_dx[j]; + heat_flux_tensor_dx[i][j][k] += + (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag_dx[j]; + } else { + heat_flux_tensor_dx[i][j][k] -= + (local_mag[i] * local_mag[k]) * local_mag[j] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (local_mag[i] * local_mag[k]) * local_mag_dx[j]; } if (j == k) { - heat_flux_tensor_dx[i][j][k] += (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag_dx[i]; - } - else { - heat_flux_tensor_dx[i][j][k] -= (local_mag[j] * local_mag[k]) * local_mag[i] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (local_mag[j] * local_mag[k]) * local_mag_dx[i]; + heat_flux_tensor_dx[i][j][k] += + (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag_dx[i]; + } else { + heat_flux_tensor_dx[i][j][k] -= + (local_mag[j] * local_mag[k]) * local_mag[i] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (local_mag[j] * local_mag[k]) * local_mag_dx[i]; } - heat_flux_tensor_dx[i][j][k] -= ((local_mag[i] * local_mag_dx[j]) + (local_mag[j] * local_mag_dx[i])) * local_mag[k]; - heat_flux_tensor_dx[i][j][k] -= ((local_mag[i] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[i])) * local_mag[j]; - heat_flux_tensor_dx[i][j][k] -= ((local_mag[j] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[j])) * local_mag[i]; + heat_flux_tensor_dx[i][j][k] -= + ((local_mag[i] * local_mag_dx[j]) + (local_mag[j] * local_mag_dx[i])) * local_mag[k]; + heat_flux_tensor_dx[i][j][k] -= + ((local_mag[i] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[i])) * local_mag[j]; + heat_flux_tensor_dx[i][j][k] -= + ((local_mag[j] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[j])) * local_mag[i]; } } } @@ -807,8 +937,7 @@ gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure divQx[4] = B_avg[0] * heat_flux_tensor_dx[0][1][2]; divQx[5] = B_avg[0] * heat_flux_tensor_dx[0][2][2]; } - } - else if (ndim == 2) { + } else if (ndim == 2) { if (poly_order == 1) { for (int i = 0; i < 8; i++) { output_data[i] = output_data_predicted[i]; @@ -829,23 +958,23 @@ gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure heat_flux_tensor[i][j][k] = q_par * local_mag[i] * local_mag[j] * local_mag[k]; if (i == j) { - heat_flux_tensor[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k]; - } - else { + heat_flux_tensor[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k]; + } else { heat_flux_tensor[i][j][k] -= q_perp * (local_mag[i] * local_mag[j]) * local_mag[k]; } if (i == k) { - heat_flux_tensor[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j]; - } - else { + heat_flux_tensor[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j]; + } else { heat_flux_tensor[i][j][k] -= q_perp * (local_mag[i] * local_mag[k]) * local_mag[j]; } if (j == k) { - heat_flux_tensor[i][j][k] += q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i]; - } - else { + heat_flux_tensor[i][j][k] += + q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i]; + } else { heat_flux_tensor[i][j][k] -= q_perp * (local_mag[j] * local_mag[k]) * local_mag[i]; } } @@ -869,57 +998,84 @@ gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure heat_flux_tensor_dy[i][j][k] += q_par * local_mag[i] * local_mag[j] * local_mag_dy[k]; if (i == j) { - heat_flux_tensor_dx[i][j][k] += (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag_dx[k]; - - heat_flux_tensor_dy[i][j][k] += (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k] * q_perp_dy; - heat_flux_tensor_dy[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag_dy[k]; - } - else { - heat_flux_tensor_dx[i][j][k] -= (local_mag[i] * local_mag[j]) * local_mag[k] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (local_mag[i] * local_mag[j]) * local_mag_dx[k]; - - heat_flux_tensor_dy[i][j][k] -= (local_mag[i] * local_mag[j]) * local_mag[k] * q_perp_dy; - heat_flux_tensor_dy[i][j][k] += q_perp * (local_mag[i] * local_mag[j]) * local_mag_dy[k]; + heat_flux_tensor_dx[i][j][k] += + (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag_dx[k]; + + heat_flux_tensor_dy[i][j][k] += + (1.0 - (local_mag[i] * local_mag[j])) * local_mag[k] * q_perp_dy; + heat_flux_tensor_dy[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[j])) * local_mag_dy[k]; + } else { + heat_flux_tensor_dx[i][j][k] -= + (local_mag[i] * local_mag[j]) * local_mag[k] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (local_mag[i] * local_mag[j]) * local_mag_dx[k]; + + heat_flux_tensor_dy[i][j][k] -= + (local_mag[i] * local_mag[j]) * local_mag[k] * q_perp_dy; + heat_flux_tensor_dy[i][j][k] += + q_perp * (local_mag[i] * local_mag[j]) * local_mag_dy[k]; } if (i == k) { - heat_flux_tensor_dx[i][j][k] += (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag_dx[j]; - - heat_flux_tensor_dy[i][j][k] += (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j] * q_perp_dy; - heat_flux_tensor_dy[i][j][k] += q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag_dy[j]; - } - else { - heat_flux_tensor_dx[i][j][k] -= (local_mag[i] * local_mag[k]) * local_mag[j] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (local_mag[i] * local_mag[k]) * local_mag_dx[j]; - - heat_flux_tensor_dy[i][j][k] -= (local_mag[i] * local_mag[k]) * local_mag[j] * q_perp_dy; - heat_flux_tensor_dy[i][j][k] += q_perp * (local_mag[i] * local_mag[k]) * local_mag_dy[j]; + heat_flux_tensor_dx[i][j][k] += + (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag_dx[j]; + + heat_flux_tensor_dy[i][j][k] += + (1.0 - (local_mag[i] * local_mag[k])) * local_mag[j] * q_perp_dy; + heat_flux_tensor_dy[i][j][k] += + q_perp * (1.0 - (local_mag[i] * local_mag[k])) * local_mag_dy[j]; + } else { + heat_flux_tensor_dx[i][j][k] -= + (local_mag[i] * local_mag[k]) * local_mag[j] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (local_mag[i] * local_mag[k]) * local_mag_dx[j]; + + heat_flux_tensor_dy[i][j][k] -= + (local_mag[i] * local_mag[k]) * local_mag[j] * q_perp_dy; + heat_flux_tensor_dy[i][j][k] += + q_perp * (local_mag[i] * local_mag[k]) * local_mag_dy[j]; } if (j == k) { - heat_flux_tensor_dx[i][j][k] += (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag_dx[i]; - - heat_flux_tensor_dy[i][j][k] += (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i] * q_perp_dy; - heat_flux_tensor_dy[i][j][k] += q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag_dy[i]; + heat_flux_tensor_dx[i][j][k] += + (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag_dx[i]; + + heat_flux_tensor_dy[i][j][k] += + (1.0 - (local_mag[j] * local_mag[k])) * local_mag[i] * q_perp_dy; + heat_flux_tensor_dy[i][j][k] += + q_perp * (1.0 - (local_mag[j] * local_mag[k])) * local_mag_dy[i]; + } else { + heat_flux_tensor_dx[i][j][k] -= + (local_mag[j] * local_mag[k]) * local_mag[i] * q_perp_dx; + heat_flux_tensor_dx[i][j][k] += + q_perp * (local_mag[j] * local_mag[k]) * local_mag_dx[i]; + + heat_flux_tensor_dy[i][j][k] -= + (local_mag[j] * local_mag[k]) * local_mag[i] * q_perp_dy; + heat_flux_tensor_dy[i][j][k] += + q_perp * (local_mag[j] * local_mag[k]) * local_mag_dy[i]; } - else { - heat_flux_tensor_dx[i][j][k] -= (local_mag[j] * local_mag[k]) * local_mag[i] * q_perp_dx; - heat_flux_tensor_dx[i][j][k] += q_perp * (local_mag[j] * local_mag[k]) * local_mag_dx[i]; - heat_flux_tensor_dy[i][j][k] -= (local_mag[j] * local_mag[k]) * local_mag[i] * q_perp_dy; - heat_flux_tensor_dy[i][j][k] += q_perp * (local_mag[j] * local_mag[k]) * local_mag_dy[i]; - } - - heat_flux_tensor_dx[i][j][k] -= ((local_mag[i] * local_mag_dx[j]) + (local_mag[j] * local_mag_dx[i])) * local_mag[k]; - heat_flux_tensor_dx[i][j][k] -= ((local_mag[i] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[i])) * local_mag[j]; - heat_flux_tensor_dx[i][j][k] -= ((local_mag[j] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[j])) * local_mag[i]; - - heat_flux_tensor_dy[i][j][k] -= ((local_mag[i] * local_mag_dy[j]) + (local_mag[j] * local_mag_dy[i])) * local_mag[k]; - heat_flux_tensor_dy[i][j][k] -= ((local_mag[i] * local_mag_dy[k]) + (local_mag[k] * local_mag_dy[i])) * local_mag[j]; - heat_flux_tensor_dy[i][j][k] -= ((local_mag[j] * local_mag_dy[k]) + (local_mag[k] * local_mag_dy[j])) * local_mag[i]; + heat_flux_tensor_dx[i][j][k] -= + ((local_mag[i] * local_mag_dx[j]) + (local_mag[j] * local_mag_dx[i])) * local_mag[k]; + heat_flux_tensor_dx[i][j][k] -= + ((local_mag[i] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[i])) * local_mag[j]; + heat_flux_tensor_dx[i][j][k] -= + ((local_mag[j] * local_mag_dx[k]) + (local_mag[k] * local_mag_dx[j])) * local_mag[i]; + + heat_flux_tensor_dy[i][j][k] -= + ((local_mag[i] * local_mag_dy[j]) + (local_mag[j] * local_mag_dy[i])) * local_mag[k]; + heat_flux_tensor_dy[i][j][k] -= + ((local_mag[i] * local_mag_dy[k]) + (local_mag[k] * local_mag_dy[i])) * local_mag[j]; + heat_flux_tensor_dy[i][j][k] -= + ((local_mag[j] * local_mag_dy[k]) + (local_mag[k] * local_mag_dy[j])) * local_mag[i]; } } } @@ -955,21 +1111,22 @@ gkyl_ten_moment_nn_closure_construct(const gkyl_ten_moment_nn_closure *nnclosure rhs[P33] = -(divQx[5] + divQy[5] + divQz[5]); } -void -gkyl_ten_moment_nn_closure_advance(const gkyl_ten_moment_nn_closure *nnclosure, const struct gkyl_range *heat_flux_rng, const struct gkyl_range *update_rng, - const struct gkyl_array *fluid, const struct gkyl_array *em_tot, struct gkyl_array *heat_flux, struct gkyl_array *rhs) +void gkyl_ten_moment_nn_closure_advance( + const gkyl_ten_moment_nn_closure *nnclosure, const struct gkyl_range *heat_flux_rng, + const struct gkyl_range *update_rng, const struct gkyl_array *fluid, + const struct gkyl_array *em_tot, struct gkyl_array *heat_flux, struct gkyl_array *rhs +) { int poly_order = nnclosure->poly_order; int ndim = update_rng->ndim; - long sz[] = { 2, 4, 8 }; - long sz_p2[] = { 3, 9, 27 }; + long sz[] = {2, 4, 8}; + long sz_p2[] = {3, 9, 27}; long offsets_centers[sz[ndim - 1]]; long offsets_centers_p2[sz_p2[ndim - 1]]; if (poly_order == 1) { create_offsets_centers(heat_flux_rng, offsets_centers); - } - else { + } else { create_offsets_centers(heat_flux_rng, offsets_centers_p2); } @@ -980,7 +1137,8 @@ gkyl_ten_moment_nn_closure_advance(const gkyl_ten_moment_nn_closure *nnclosure, // Batched inference buffers and a per-cell geometry cache. struct gkyl_kn_vec *nn_in = gkyl_kn_vec_new(ncells, n_in); struct gkyl_kn_vec *nn_out = gkyl_kn_vec_new(ncells, n_out); - struct gkyl_ten_moment_nn_closure_geom *geom = gkyl_malloc(ncells * sizeof(struct gkyl_ten_moment_nn_closure_geom)); + struct gkyl_ten_moment_nn_closure_geom *geom = + gkyl_malloc(ncells * sizeof(struct gkyl_ten_moment_nn_closure_geom)); const double *fluid_d[sz[ndim - 1]]; const double *fluid_d_p2[sz_p2[ndim - 1]]; @@ -1000,14 +1158,17 @@ gkyl_ten_moment_nn_closure_advance(const gkyl_ten_moment_nn_closure *nnclosure, em_tot_d[i] = gkyl_array_cfetch(em_tot, linc_vertex + offsets_centers[i]); fluid_d[i] = gkyl_array_cfetch(fluid, linc_vertex + offsets_centers[i]); } - gkyl_ten_moment_nn_closure_geom_calc(nnclosure, fluid_d, em_tot_d, nn_in->vals[count], &geom[count]); - } - else { + gkyl_ten_moment_nn_closure_geom_calc( + nnclosure, fluid_d, em_tot_d, nn_in->vals[count], &geom[count] + ); + } else { for (int i = 0; i < sz_p2[ndim - 1]; i++) { em_tot_d_p2[i] = gkyl_array_cfetch(em_tot, linc_vertex + offsets_centers_p2[i]); fluid_d_p2[i] = gkyl_array_cfetch(fluid, linc_vertex + offsets_centers_p2[i]); } - gkyl_ten_moment_nn_closure_geom_calc(nnclosure, fluid_d_p2, em_tot_d_p2, nn_in->vals[count], &geom[count]); + gkyl_ten_moment_nn_closure_geom_calc( + nnclosure, fluid_d_p2, em_tot_d_p2, nn_in->vals[count], &geom[count] + ); } count += 1; @@ -1025,8 +1186,7 @@ gkyl_ten_moment_nn_closure_advance(const gkyl_ten_moment_nn_closure *nnclosure, gkyl_kn_vec_copy(nn_out, nn_out_cu); gkyl_kn_vec_release(nn_in_cu); gkyl_kn_vec_release(nn_out_cu); - } - else { + } else { gkyl_kann_net_apply(nnclosure->ann, nn_in, nn_out); } @@ -1048,8 +1208,8 @@ gkyl_ten_moment_nn_closure_advance(const gkyl_ten_moment_nn_closure *nnclosure, gkyl_free(geom); } -gkyl_ten_moment_nn_closure* -gkyl_ten_moment_nn_closure_new(struct gkyl_ten_moment_nn_closure_inp inp) +gkyl_ten_moment_nn_closure *gkyl_ten_moment_nn_closure_new(struct gkyl_ten_moment_nn_closure_inp inp +) { gkyl_ten_moment_nn_closure *up = gkyl_malloc(sizeof(gkyl_ten_moment_nn_closure)); @@ -1062,8 +1222,7 @@ gkyl_ten_moment_nn_closure_new(struct gkyl_ten_moment_nn_closure_inp inp) return up; } -void -gkyl_ten_moment_nn_closure_release(gkyl_ten_moment_nn_closure *nnclosure) +void gkyl_ten_moment_nn_closure_release(gkyl_ten_moment_nn_closure *nnclosure) { free(nnclosure); } diff --git a/moments/zero/wave_geom.c b/moments/zero/wave_geom.c index 1976394a71..06d9028a48 100644 --- a/moments/zero/wave_geom.c +++ b/moments/zero/wave_geom.c @@ -9,32 +9,32 @@ #include #include -static bool -wave_geom_is_cu_dev(const struct gkyl_wave_geom* wg) +static bool wave_geom_is_cu_dev(const struct gkyl_wave_geom *wg) { return GKYL_IS_CU_ALLOC(wg->flags); } -void -gkyl_wave_geom_free(const struct gkyl_ref_count *ref) +void gkyl_wave_geom_free(const struct gkyl_ref_count *ref) { struct gkyl_wave_geom *wg = container_of(ref, struct gkyl_wave_geom, ref_count); gkyl_array_release(wg->geom); - if (wave_geom_is_cu_dev(wg)) - gkyl_cu_free(wg->on_dev); + if (wave_geom_is_cu_dev(wg)) { + gkyl_cu_free(wg->on_dev); + } gkyl_free(wg); } -struct gkyl_wave_geom* -gkyl_wave_geom_new(const struct gkyl_rect_grid *grid, struct gkyl_range *range, - evalf_t mapc2p, void *ctx, bool use_gpu) +struct gkyl_wave_geom *gkyl_wave_geom_new( + const struct gkyl_rect_grid *grid, struct gkyl_range *range, evalf_t mapc2p, void *ctx, + bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_wave_geom_cu_dev_new(grid, range, mapc2p, ctx); - } -#endif + } +#endif struct gkyl_wave_geom *wg = gkyl_malloc(sizeof(struct gkyl_wave_geom)); @@ -46,24 +46,23 @@ gkyl_wave_geom_new(const struct gkyl_rect_grid *grid, struct gkyl_range *range, struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, range); while (gkyl_range_iter_next(&iter)) { - gkyl_rect_grid_cell_center(grid, iter.idx, xc); struct gkyl_wave_cell_geom *geo = gkyl_array_fetch(wg->geom, gkyl_range_idx(range, iter.idx)); // compute geometry based on grid dimensions switch (grid->ndim) { - case 1: - calc_geom_1d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); - break; + case 1: + calc_geom_1d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); + break; - case 2: - calc_geom_2d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); - break; + case 2: + calc_geom_2d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); + break; - case 3: - calc_geom_3d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); - break; + case 3: + calc_geom_3d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); + break; }; } @@ -75,15 +74,13 @@ gkyl_wave_geom_new(const struct gkyl_rect_grid *grid, struct gkyl_range *range, return wg; } -struct gkyl_wave_geom* -gkyl_wave_geom_acquire(const struct gkyl_wave_geom* wg) +struct gkyl_wave_geom *gkyl_wave_geom_acquire(const struct gkyl_wave_geom *wg) { gkyl_ref_count_inc(&wg->ref_count); - return (struct gkyl_wave_geom*) wg; + return (struct gkyl_wave_geom *)wg; } -void -gkyl_wave_geom_release(const struct gkyl_wave_geom *wg) +void gkyl_wave_geom_release(const struct gkyl_wave_geom *wg) { gkyl_ref_count_dec(&wg->ref_count); } diff --git a/moments/zero/wave_geom_cu.cu b/moments/zero/wave_geom_cu.cu index 083858125f..1fb294411b 100644 --- a/moments/zero/wave_geom_cu.cu +++ b/moments/zero/wave_geom_cu.cu @@ -13,36 +13,39 @@ extern "C" { #include // CPU interface to create and track a GPU object -struct gkyl_wave_geom* -gkyl_wave_geom_cu_dev_new(const struct gkyl_rect_grid *grid, struct gkyl_range *range, - evalf_t mapc2p, void *ctx) +struct gkyl_wave_geom *gkyl_wave_geom_cu_dev_new( + const struct gkyl_rect_grid *grid, struct gkyl_range *range, evalf_t mapc2p, void *ctx +) { - struct gkyl_wave_geom *wg =(struct gkyl_wave_geom*) gkyl_malloc(sizeof(struct gkyl_wave_geom)); + struct gkyl_wave_geom *wg = (struct gkyl_wave_geom *)gkyl_malloc(sizeof(struct gkyl_wave_geom)); wg->range = *range; // Initialize the geometry object on the host side - struct gkyl_array *geom = gkyl_array_new(GKYL_USER, sizeof(struct gkyl_wave_cell_geom), range->volume); + struct gkyl_array *geom = + gkyl_array_new(GKYL_USER, sizeof(struct gkyl_wave_cell_geom), range->volume); double xc[GKYL_MAX_CDIM]; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, range); while (gkyl_range_iter_next(&iter)) { gkyl_rect_grid_cell_center(grid, iter.idx, xc); - struct gkyl_wave_cell_geom *geo =(struct gkyl_wave_cell_geom*) gkyl_array_fetch(geom, gkyl_range_idx(range, iter.idx)); + struct gkyl_wave_cell_geom *geo = + (struct gkyl_wave_cell_geom *)gkyl_array_fetch(geom, gkyl_range_idx(range, iter.idx)); switch (grid->ndim) { - case 1: - calc_geom_1d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); - break; - case 2: - calc_geom_2d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); - break; - case 3: - calc_geom_3d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); - break; + case 1: + calc_geom_1d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); + break; + case 2: + calc_geom_2d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); + break; + case 3: + calc_geom_3d(grid->dx, xc, mapc2p ? mapc2p : nomapc2p, ctx, geo); + break; }; } // Copy the host-side initialized geometry object to the device - struct gkyl_array *geom_dev = gkyl_array_cu_dev_new(GKYL_USER, sizeof(struct gkyl_wave_cell_geom), range->volume); + struct gkyl_array *geom_dev = + gkyl_array_cu_dev_new(GKYL_USER, sizeof(struct gkyl_wave_cell_geom), range->volume); gkyl_array_copy(geom_dev, geom); gkyl_array_release(geom); @@ -53,12 +56,13 @@ gkyl_wave_geom_cu_dev_new(const struct gkyl_rect_grid *grid, struct gkyl_range * wg->ref_count = gkyl_ref_count_init(gkyl_wave_geom_free); // Initialize the device geometry object - struct gkyl_wave_geom *wg_cu = (struct gkyl_wave_geom*) gkyl_cu_malloc(sizeof(struct gkyl_wave_geom)); + struct gkyl_wave_geom *wg_cu = + (struct gkyl_wave_geom *)gkyl_cu_malloc(sizeof(struct gkyl_wave_geom)); gkyl_cu_memcpy(wg_cu, wg, sizeof(struct gkyl_wave_geom), GKYL_CU_MEMCPY_H2D); wg->on_dev = wg_cu; wg->geom = geom_dev; // geometry object should store host pointer - + return wg; } diff --git a/moments/zero/wave_prop.c b/moments/zero/wave_prop.c index 69f6cc4f07..6c915304bb 100644 --- a/moments/zero/wave_prop.c +++ b/moments/zero/wave_prop.c @@ -29,7 +29,7 @@ struct gkyl_wave_prop { struct gkyl_wave_geom *geom; // geometry object struct gkyl_comm *comm; // communcator - + // data for 1D slice update struct gkyl_array *waves, *apdq, *amdq, *speeds, *flux2; // flags to indicate if fluctuations should be recomputed @@ -42,99 +42,97 @@ struct gkyl_wave_prop { long n_max_bad_cells; // maximum number of cells fixed in a call }; -static inline double -fmax3(double a, double b, double c) +static inline double fmax3(double a, double b, double c) { - return fmax(fmax(a,b),c); + return fmax(fmax(a, b), c); } -static inline double -fmin3(double a, double b, double c) +static inline double fmin3(double a, double b, double c) { - return fmin(fmin(a,b),c); + return fmin(fmin(a, b), c); } // limiter function -static inline double -limiter_function(double r, enum gkyl_wave_limiter limiter) +static inline double limiter_function(double r, enum gkyl_wave_limiter limiter) { double theta = 0.0; switch (limiter) { - case GKYL_NO_LIMITER: - theta = 1.0; - break; - - // ** Fully formally-verified implementation of the minmod flux limiter ** - // ** Proof of symmetry (equivalent action on forward and backward gradients): ../proofs/finite_volume/proof_limiter_minmod_symmetry.rkt ** - // ** Proof of second-order TVD (total variation diminishing): ../proofs/finite_volume/proof_limiter_minmod_tvd.rkt ** - case GKYL_MIN_MOD: - theta = fmax(0.0, fmin(1.0, r)); - break; - - // ** Partially formally-verified implementation of the superbee flux limiter ** - // ** Proof of symmetry (equivalent action on forward and backward gradients): NOT PROVEN ** - // ** Proof of second-order TVD (total variation diminishing): ../proofs/finite_volume/proof_limiter_superbee_tvd.rkt ** - case GKYL_SUPERBEE: - theta = fmax3(0.0, fmin((2.0 * r), 1.0), fmin(r, 2.0)); - break; - - // ** Partially formally-verified implementation of the van Leer flux limiter ** - // ** Proof of symmetry (equivalent action on forward and backward gradients): ../proofs/finite_volume/proof_limiter_van_leer_symmetry.rkt ** - // ** Proof of second-order TVD (total variation diminishing): NOT PROVEN ** - case GKYL_VAN_LEER: - theta = ((r + fabs(r)) / (1.0 + fabs(r))); - break; - - // ** Fully formally-verified implementation of the monotonized-centered flux limiter ** - // ** Proof of symmetry (equivalent action on forward and backward gradients): ../proofs/finite_volume/proof_limiter_monotonized_centered_symmetry.rkt ** - // ** Proof of second-order TVD (total variation diminishing): ../proofs/finite_volume/proof_limiter_monotonized_centered_tvd.rkt ** - case GKYL_MONOTONIZED_CENTERED: - theta = fmax(0.0, fmin3((2.0 * r), ((1.0 + r) / 2.0), 2.0)); - break; - - case GKYL_BEAM_WARMING: - theta = r; - break; - - case GKYL_ZERO: - theta = 0; - break; + case GKYL_NO_LIMITER: + theta = 1.0; + break; + + // ** Fully formally-verified implementation of the minmod flux limiter ** + // ** Proof of symmetry (equivalent action on forward and backward gradients): ../proofs/finite_volume/proof_limiter_minmod_symmetry.rkt ** + // ** Proof of second-order TVD (total variation diminishing): ../proofs/finite_volume/proof_limiter_minmod_tvd.rkt ** + case GKYL_MIN_MOD: + theta = fmax(0.0, fmin(1.0, r)); + break; + + // ** Partially formally-verified implementation of the superbee flux limiter ** + // ** Proof of symmetry (equivalent action on forward and backward gradients): NOT PROVEN ** + // ** Proof of second-order TVD (total variation diminishing): ../proofs/finite_volume/proof_limiter_superbee_tvd.rkt ** + case GKYL_SUPERBEE: + theta = fmax3(0.0, fmin((2.0 * r), 1.0), fmin(r, 2.0)); + break; + + // ** Partially formally-verified implementation of the van Leer flux limiter ** + // ** Proof of symmetry (equivalent action on forward and backward gradients): ../proofs/finite_volume/proof_limiter_van_leer_symmetry.rkt ** + // ** Proof of second-order TVD (total variation diminishing): NOT PROVEN ** + case GKYL_VAN_LEER: + theta = ((r + fabs(r)) / (1.0 + fabs(r))); + break; + + // ** Fully formally-verified implementation of the monotonized-centered flux limiter ** + // ** Proof of symmetry (equivalent action on forward and backward gradients): ../proofs/finite_volume/proof_limiter_monotonized_centered_symmetry.rkt ** + // ** Proof of second-order TVD (total variation diminishing): ../proofs/finite_volume/proof_limiter_monotonized_centered_tvd.rkt ** + case GKYL_MONOTONIZED_CENTERED: + theta = fmax(0.0, fmin3((2.0 * r), ((1.0 + r) / 2.0), 2.0)); + break; + + case GKYL_BEAM_WARMING: + theta = r; + break; + + case GKYL_ZERO: + theta = 0; + break; } return theta; } -gkyl_wave_prop* -gkyl_wave_prop_new(const struct gkyl_wave_prop_inp *winp) +gkyl_wave_prop *gkyl_wave_prop_new(const struct gkyl_wave_prop_inp *winp) { gkyl_wave_prop *up = gkyl_malloc(sizeof(*up)); up->grid = *(winp->grid); up->ndim = up->grid.ndim; - + up->num_up_dirs = winp->num_up_dirs; - for (int i=0; inum_up_dirs; ++i) + for (int i = 0; i < winp->num_up_dirs; ++i) { up->update_dirs[i] = winp->update_dirs[i]; + } up->limiter = winp->limiter == 0 ? GKYL_MONOTONIZED_CENTERED : winp->limiter; up->cfl = winp->cfl; up->equation = gkyl_wv_eqn_acquire(winp->equation); - if (winp->comm) + if (winp->comm) { up->comm = gkyl_comm_acquire(winp->comm); - else - up->comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { } ); + } else { + up->comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){}); + } up->force_low_order_flux = winp->force_low_order_flux; up->check_inv_domain = winp->check_inv_domain; up->split_type = winp->split_type; - int nghost[3] = { 2, 2, 2 }; + int nghost[3] = {2, 2, 2}; struct gkyl_range range, ext_range; gkyl_create_grid_ranges(&up->grid, nghost, &ext_range, &range); int max_1d = 0; - for (int d=0; d shape ? max_1d : shape; } @@ -142,7 +140,7 @@ gkyl_wave_prop_new(const struct gkyl_wave_prop_inp *winp) // allocate memory to store 1D slices of waves, speeds and // second-order correction flux int meqn = winp->equation->num_equations, mwaves = winp->equation->num_waves; - up->waves = gkyl_array_new(GKYL_DOUBLE, meqn*mwaves, max_1d); + up->waves = gkyl_array_new(GKYL_DOUBLE, meqn * mwaves, max_1d); up->apdq = gkyl_array_new(GKYL_DOUBLE, meqn, max_1d); up->amdq = gkyl_array_new(GKYL_DOUBLE, meqn, max_1d); up->speeds = gkyl_array_new(GKYL_DOUBLE, mwaves, max_1d); @@ -160,156 +158,167 @@ gkyl_wave_prop_new(const struct gkyl_wave_prop_inp *winp) // some helper functions -static inline void -copy_wv_vec(int n, double * GKYL_RESTRICT out, const double * GKYL_RESTRICT inp) +static inline void copy_wv_vec(int n, double *GKYL_RESTRICT out, const double *GKYL_RESTRICT inp) { - for (int i=0; iequation->num_equations; - for (int mw=0; mw 0) { const double *s = gkyl_array_cfetch(speed, gkyl_ridx(*slice_range, i)); - double r = s[mw] > 0 ? dotl/wnorm2 : dotr/wnorm2; + double r = s[mw] > 0 ? dotl / wnorm2 : dotr / wnorm2; double theta = limiter_function(r, wv->limiter); - wave_rescale(meqn, theta, &wi[mw*meqn]); + wave_rescale(meqn, theta, &wi[mw * meqn]); } } } } // advance method -struct gkyl_wave_prop_status -gkyl_wave_prop_advance(gkyl_wave_prop *wv, - double tm, double dt, const struct gkyl_range *update_range, - struct gkyl_array *phi, const struct gkyl_array *qin, struct gkyl_array *qout) +struct gkyl_wave_prop_status gkyl_wave_prop_advance( + gkyl_wave_prop *wv, double tm, double dt, const struct gkyl_range *update_range, + struct gkyl_array *phi, const struct gkyl_array *qin, struct gkyl_array *qout +) { wv->n_calls += 1; - + int ndim = update_range->ndim; int meqn = wv->equation->num_equations; // when forced to use Lax fluxes, we only have a single wave - int mwaves = wv->force_low_order_flux ? 2 : wv->equation->num_waves; + int mwaves = wv->force_low_order_flux ? 2 : wv->equation->num_waves; - double cfla = 0.0, cfl = wv->cfl, cflm = 1.1*cfl; + double cfla = 0.0, cfl = wv->cfl, cflm = 1.1 * cfl; double is_cfl_violated = 0.0; // delibrately a double - + double ql_local[meqn], qr_local[meqn]; double fjump_local[meqn]; - double waves_local[meqn*mwaves]; + double waves_local[meqn * mwaves]; double amdq_local[meqn], apdq_local[meqn]; double delta[meqn]; - + int idxl[GKYL_MAX_DIM], idxr[GKYL_MAX_DIM]; double max_speed = 0.0; // state of the update - enum update_state { - WV_FIRST_SWEEP, WV_POSITIVITY_SWEEP, WV_FIN_SWEEP - } state, next_state; + enum update_state { WV_FIRST_SWEEP, WV_POSITIVITY_SWEEP, WV_FIN_SWEEP } state, next_state; - for (int d=0; dnum_up_dirs; ++d) { + for (int d = 0; d < wv->num_up_dirs; ++d) { int dir = wv->update_dirs[d]; - double dtdx = dt/wv->grid.dx[dir]; + double dtdx = dt / wv->grid.dx[dir]; // upper/lower bounds in direction 'd'. These are edge indices - int loidx = update_range->lower[dir]-1; - int upidx = update_range->upper[dir]+2; + int loidx = update_range->lower[dir] - 1; + int upidx = update_range->upper[dir] + 2; // cell indices in 1D slice for interior cells int loidx_c = update_range->lower[dir]; int upidx_c = update_range->upper[dir]; struct gkyl_range slice_range; - gkyl_range_init(&slice_range, 1, (int[]) { loidx }, (int[]) { upidx } ); + gkyl_range_init(&slice_range, 1, (int[]){loidx}, (int[]){upidx}); struct gkyl_range perp_range; gkyl_range_shorten_from_above(&perp_range, update_range, dir, 1); @@ -319,32 +328,32 @@ gkyl_wave_prop_advance(gkyl_wave_prop *wv, // outer loop is over perpendicular directions, inner loop over 1D // slice along that direction while (gkyl_range_iter_next(&iter)) { - gkyl_copy_int_arr(ndim, iter.idx, idxl); gkyl_copy_int_arr(ndim, iter.idx, idxr); gkyl_array_clear(wv->redo_fluct, 1.0); - - enum gkyl_wv_flux_type ftype = wv->force_low_order_flux ? - GKYL_WV_LOW_ORDER_FLUX : GKYL_WV_HIGH_ORDER_FLUX; + + enum gkyl_wv_flux_type ftype = wv->force_low_order_flux ? GKYL_WV_LOW_ORDER_FLUX : + GKYL_WV_HIGH_ORDER_FLUX; state = WV_FIRST_SWEEP; // perform 1D sweeps, fixing positivity if required while (state != WV_FIN_SWEEP) { - - if (state == WV_POSITIVITY_SWEEP) + if (state == WV_POSITIVITY_SWEEP) { ftype = GKYL_WV_LOW_ORDER_FLUX; + } // copy previous time-step solution - for (int i=loidx_c; i<=upidx_c; ++i) { + for (int i = loidx_c; i <= upidx_c; ++i) { idxl[dir] = i; // cell index long lidx = gkyl_range_idx(update_range, idxl); copy_wv_vec(meqn, gkyl_array_fetch(qout, lidx), gkyl_array_cfetch(qin, lidx)); } - for (int i=loidx; i<=upidx; ++i) { - idxl[dir] = i-1; idxr[dir] = i; + for (int i = loidx; i <= upidx; ++i) { + idxl[dir] = i - 1; + idxr[dir] = i; long sidx = gkyl_ridx(slice_range, i); const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wv->geom, idxr); @@ -352,7 +361,6 @@ gkyl_wave_prop_advance(gkyl_wave_prop *wv, const double *redo_fluct = gkyl_array_cfetch(wv->redo_fluct, sidx); if (redo_fluct[0] > 0.0) { - // compute fluctuations and waves only if needed (this // prevents doing the full 1D sweep with low-order fluxes // on positivity violations) @@ -365,53 +373,69 @@ gkyl_wave_prop_advance(gkyl_wave_prop *wv, const double *phil = gkyl_array_cfetch(phi, lidx); const double *phir = gkyl_array_cfetch(phi, ridx); - gkyl_wv_eqn_rotate_to_local(wv->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qinl, ql_local); - gkyl_wv_eqn_rotate_to_local(wv->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qinr, qr_local); + gkyl_wv_eqn_rotate_to_local( + wv->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qinl, ql_local + ); + gkyl_wv_eqn_rotate_to_local( + wv->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], qinr, qr_local + ); - if (wv->split_type == GKYL_WAVE_QWAVE) + if (wv->split_type == GKYL_WAVE_QWAVE) { calc_jump(meqn, ql_local, qr_local, delta); - else + } else { gkyl_wv_eqn_flux_jump(wv->equation, ql_local, qr_local, delta); + } - double my_max_speed = gkyl_wv_eqn_waves(wv->equation, ftype, delta, - ql_local, qr_local, phil[0], phir[0], waves_local, s); + double my_max_speed = gkyl_wv_eqn_waves( + wv->equation, ftype, delta, ql_local, qr_local, phil[0], phir[0], waves_local, s + ); max_speed = max_speed > my_max_speed ? max_speed : my_max_speed; - + double lenr = cg->lenr[dir]; - for (int mw=0; mwsplit_type == GKYL_WAVE_QWAVE) - gkyl_wv_eqn_qfluct(wv->equation, ftype, ql_local, qr_local, - phil[0], phir[0], waves_local, s, amdq_local, apdq_local); - else - gkyl_wv_eqn_ffluct(wv->equation, ftype, ql_local, qr_local, - phil[0], phir[0], waves_local, s, amdq_local, apdq_local); - + if (wv->split_type == GKYL_WAVE_QWAVE) { + gkyl_wv_eqn_qfluct( + wv->equation, ftype, ql_local, qr_local, phil[0], phir[0], waves_local, s, + amdq_local, apdq_local + ); + } else { + gkyl_wv_eqn_ffluct( + wv->equation, ftype, ql_local, qr_local, phil[0], phir[0], waves_local, s, + amdq_local, apdq_local + ); + } double *waves = gkyl_array_fetch(wv->waves, sidx); - for (int mw=0; mwequation, - cg->tau1[dir], cg->tau2[dir], cg->norm[dir], &waves_local[mw*meqn], &waves[mw*meqn] + gkyl_wv_eqn_rotate_to_global( + wv->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], &waves_local[mw * meqn], + &waves[mw * meqn] ); + } // rotate fluctuations double *amdq = gkyl_array_fetch(wv->amdq, sidx); - gkyl_wv_eqn_rotate_to_global(wv->equation, - cg->tau1[dir], cg->tau2[dir], cg->norm[dir], amdq_local, amdq); - + gkyl_wv_eqn_rotate_to_global( + wv->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], amdq_local, amdq + ); + double *apdq = gkyl_array_fetch(wv->apdq, sidx); - gkyl_wv_eqn_rotate_to_global(wv->equation, - cg->tau1[dir], cg->tau2[dir], cg->norm[dir], apdq_local, apdq); + gkyl_wv_eqn_rotate_to_global( + wv->equation, cg->tau1[dir], cg->tau2[dir], cg->norm[dir], apdq_local, apdq + ); } - - cfla = calc_cfla(mwaves, cfla, dtdx/cg->kappa, s); + + cfla = calc_cfla(mwaves, cfla, dtdx / cg->kappa, s); } - if (cfla > cflm) // check time-step before any updates are performed + if (cfla > cflm) { // check time-step before any updates are performed is_cfl_violated = 1.0; + } if (is_cfl_violated > 0) { // we need to use this goto to jump out of this deep loop to @@ -423,38 +447,40 @@ gkyl_wave_prop_advance(gkyl_wave_prop *wv, } // compute first-order update in each cell - for (int i=loidx_c; i<=upidx_c; ++i) { // loop is over cells - + for (int i = loidx_c; i <= upidx_c; ++i) { // loop is over cells + idxl[dir] = i; // cell index and left-edge index long lidx = gkyl_range_idx(update_range, idxl); const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wv->geom, idxl); - calc_first_order_update(meqn, dtdx/cg->kappa, - gkyl_array_fetch(qout, lidx), - gkyl_array_cfetch(wv->amdq, gkyl_ridx(slice_range, i+1)), + calc_first_order_update( + meqn, dtdx / cg->kappa, gkyl_array_fetch(qout, lidx), + gkyl_array_cfetch(wv->amdq, gkyl_ridx(slice_range, i + 1)), gkyl_array_cfetch(wv->apdq, gkyl_ridx(slice_range, i)) ); } if (state == WV_FIRST_SWEEP) { // we only compute second-correction if we are in first sweep - + // apply limiters to waves for all edges in update range, // including edges that are on the range boundary - limit_waves(wv, mwaves, &slice_range, - update_range->lower[dir], update_range->upper[dir]+1, wv->waves, wv->speeds); + limit_waves( + wv, mwaves, &slice_range, update_range->lower[dir], update_range->upper[dir] + 1, + wv->waves, wv->speeds + ); // get the kappa in the first ghost cell on left (needed in // the second order flux calculation) - idxl[dir] = update_range->lower[dir]-1; + idxl[dir] = update_range->lower[dir] - 1; const struct gkyl_wave_cell_geom *cg = gkyl_wave_geom_get(wv->geom, idxl); double kappal = cg->kappa; gkyl_array_clear(wv->flux2, 0.0); // compute second-order correction fluxes at each interface: // note that there is one extra edge than cell - for (int i=loidx_c; i<=upidx_c+1; ++i) { + for (int i = loidx_c; i <= upidx_c + 1; ++i) { long sidx = gkyl_ridx(slice_range, i); const double *waves = gkyl_array_cfetch(wv->waves, sidx); @@ -466,48 +492,53 @@ gkyl_wave_prop_advance(gkyl_wave_prop *wv, double kappar = cg->kappa; if (wv->split_type == GKYL_WAVE_QWAVE) { - for (int mw=0; mwgeom, idxl); - calc_second_order_update(meqn, dtdx/cg->kappa, - gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)), + calc_second_order_update( + meqn, dtdx / cg->kappa, gkyl_array_fetch(qout, gkyl_range_idx(update_range, idxl)), gkyl_array_cfetch(wv->flux2, gkyl_ridx(slice_range, i)), - gkyl_array_cfetch(wv->flux2, gkyl_ridx(slice_range, i+1)) + gkyl_array_cfetch(wv->flux2, gkyl_ridx(slice_range, i + 1)) ); } } next_state = WV_FIN_SWEEP; // check invariant domains if needed - if ( (state == WV_FIRST_SWEEP) && wv->check_inv_domain) { - long n_bad_cells = 0; + if ((state == WV_FIRST_SWEEP) && wv->check_inv_domain) { + long n_bad_cells = 0; gkyl_array_clear(wv->redo_fluct, 0.0); // by default no edge needs recomputing - + // check if invariant domains are violated, flagging edges // of each bad cell - for (int i=loidx_c; i<=upidx_c; ++i) { + for (int i = loidx_c; i <= upidx_c; ++i) { idxl[dir] = i; const double *qt = gkyl_array_cfetch(qout, gkyl_range_idx(update_range, idxl)); if (!gkyl_wv_eqn_check_inv(wv->equation, qt)) { - double *redo_fluct_l = gkyl_array_fetch(wv->redo_fluct, gkyl_ridx(slice_range, i)); - double *redo_fluct_r = gkyl_array_fetch(wv->redo_fluct, gkyl_ridx(slice_range, i+1)); + double *redo_fluct_r = + gkyl_array_fetch(wv->redo_fluct, gkyl_ridx(slice_range, i + 1)); // mark left and right edges so fluctuations are redone redo_fluct_l[0] = 1.0; redo_fluct_r[0] = 1.0; @@ -523,7 +554,8 @@ gkyl_wave_prop_advance(gkyl_wave_prop *wv, } wv->n_bad_cells += n_bad_cells; - wv->n_max_bad_cells = wv->n_max_bad_cells > n_bad_cells ? wv->n_max_bad_cells : n_bad_cells; + wv->n_max_bad_cells = wv->n_max_bad_cells > n_bad_cells ? wv->n_max_bad_cells : + n_bad_cells; } if (wv->equation->type == GKYL_EQN_EULER_RGFM) { @@ -545,7 +577,9 @@ gkyl_wave_prop_advance(gkyl_wave_prop *wv, gr_ultra_rel_euler_impose_gauge(wv, update_range, idxl, loidx_c, upidx_c, qout, dir); } if (wv->equation->type == GKYL_EQN_GR_ULTRA_REL_EULER_TETRAD) { - gr_ultra_rel_euler_tetrad_impose_gauge(wv, update_range, idxl, loidx_c, upidx_c, qout, dir); + gr_ultra_rel_euler_tetrad_impose_gauge( + wv, update_range, idxl, loidx_c, upidx_c, qout, dir + ); } if (wv->equation->type == GKYL_EQN_GR_TWOFLUID) { gr_twofluid_impose_gauge(wv, update_range, idxl, loidx_c, upidx_c, qout, dir); @@ -561,81 +595,72 @@ gkyl_wave_prop_advance(gkyl_wave_prop *wv, } state = next_state; // change state for next sweep - + } // end loop over sweeps } // end loop over perpendicular directions } // end loop over directions - outsideloop: - ; +outsideloop:; // compute actual CFL, status & max-speed across all domains - double red_vars[3] = { cfla, is_cfl_violated, max_speed }; - double red_vars_global[3] = { 0.0, 0.0, 0.0 }; + double red_vars[3] = {cfla, is_cfl_violated, max_speed}; + double red_vars_global[3] = {0.0, 0.0, 0.0}; gkyl_comm_allreduce(wv->comm, GKYL_DOUBLE, GKYL_MAX, 3, &red_vars, &red_vars_global); cfla = red_vars_global[0]; is_cfl_violated = red_vars_global[1]; max_speed = red_vars_global[2]; - double dt_suggested = dt*cfl/fmax(cfla, DBL_MIN); + double dt_suggested = dt * cfl / fmax(cfla, DBL_MIN); - if (is_cfl_violated > 0.0) + if (is_cfl_violated > 0.0) { // indicate failure, and return smaller stable time-step - return (struct gkyl_wave_prop_status) { - .success = 0, - .dt_suggested = dt_suggested, - .max_speed = max_speed, - }; - + return (struct gkyl_wave_prop_status + ){.success = 0, .dt_suggested = dt_suggested, .max_speed = max_speed}; + } + // on success, suggest only bigger time-step; (Only way dt can // reduce is if the update fails. If the code comes here the update // succeeded and so we should not allow dt to reduce). - return (struct gkyl_wave_prop_status) { - .success = is_cfl_violated > 0.0 ? 0 : 1, + return (struct gkyl_wave_prop_status + ){.success = is_cfl_violated > 0.0 ? 0 : 1, .dt_suggested = dt_suggested > dt ? dt_suggested : dt, - .max_speed = max_speed, - }; + .max_speed = max_speed}; } -double -gkyl_wave_prop_max_dt(const gkyl_wave_prop *wv, const struct gkyl_range *update_range, - const struct gkyl_array *qin) +double gkyl_wave_prop_max_dt( + const gkyl_wave_prop *wv, const struct gkyl_range *update_range, const struct gkyl_array *qin +) { double max_dt = DBL_MAX; - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, update_range); while (gkyl_range_iter_next(&iter)) { - - for (int d=0; dnum_up_dirs; ++d) { + for (int d = 0; d < wv->num_up_dirs; ++d) { int dir = wv->update_dirs[d]; double dx = wv->grid.dx[dir]; const double *q = gkyl_array_cfetch(qin, gkyl_range_idx(update_range, iter.idx)); double maxs = gkyl_wv_eqn_max_speed(wv->equation, q); - max_dt = fmin(max_dt, wv->cfl*dx/maxs); + max_dt = fmin(max_dt, wv->cfl * dx / maxs); } - } return max_dt; } -struct gkyl_wave_prop_stats -gkyl_wave_prop_stats(const gkyl_wave_prop *wv) +struct gkyl_wave_prop_stats gkyl_wave_prop_stats(const gkyl_wave_prop *wv) { - return (struct gkyl_wave_prop_stats) { - .n_calls = wv->n_calls, + return (struct gkyl_wave_prop_stats + ){.n_calls = wv->n_calls, .n_bad_advance_calls = wv->n_bad_advance_calls, .n_bad_cells = wv->n_bad_cells, - .n_max_bad_cells = wv->n_max_bad_cells - }; + .n_max_bad_cells = wv->n_max_bad_cells}; } -void -gkyl_wave_prop_release(gkyl_wave_prop* up) +void gkyl_wave_prop_release(gkyl_wave_prop *up) { gkyl_wv_eqn_release(up->equation); gkyl_array_release(up->waves); @@ -645,8 +670,8 @@ gkyl_wave_prop_release(gkyl_wave_prop* up) gkyl_array_release(up->flux2); gkyl_array_release(up->redo_fluct); gkyl_comm_release(up->comm); - + gkyl_wave_geom_release(up->geom); - + gkyl_free(up); } diff --git a/moments/zero/wv_advect.c b/moments/zero/wv_advect.c index 06f26baf97..5c6cfe6517 100644 --- a/moments/zero/wv_advect.c +++ b/moments/zero/wv_advect.c @@ -15,66 +15,71 @@ #include #include -static inline double -gkyl_advect_max_abs_speed(double a, const double* q) +static inline double gkyl_advect_max_abs_speed(double a, const double *q) { return fabs(a); } -void -gkyl_advect_flux(double a, const double* q, double* flux) +void gkyl_advect_flux(double a, const double *q, double *flux) { flux[0] = (a * q[0]); } -void -gkyl_advect_flux_deriv(double a, const double* q, double* flux_deriv) +void gkyl_advect_flux_deriv(double a, const double *q, double *flux_deriv) { flux_deriv[0] = a; } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. wout[0] = qin[0]; } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. qout[0] = win[0]; } -static void -advect_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void advect_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { ghost[0] = skin[0]; } -static void -advect_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void advect_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { ghost[0] = skin[0]; } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_advect *advect = container_of(eqn, struct wv_advect, eqn); double a = advect->a; // Advection speed. @@ -101,8 +106,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[1]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -112,21 +119,27 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co apdq[0] = (s0p * w0[0]) + (s1p * w1[0]); } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + const double phil, const double phir, double *waves, double *s +) { const struct wv_advect *advect = container_of(eqn, struct wv_advect, eqn); double a = advect->a; // Additional simulation parameter. @@ -149,48 +162,51 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[0]; } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double phil, + const double phir, const double *waves, const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0]; if (s[0] < 0.0) { amdq[0] = s[0] * w0[0]; apdq[0] = 0.0; - } - else { + } else { amdq[0] = 0.0; apdq[0] = s[0] * w0[0]; } } -static double -wave(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, phil, phir, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, phil, phir, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_advect *advect = container_of(eqn, struct wv_advect, eqn); double a = advect->a; // Advection speed. @@ -204,21 +220,19 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou double amaxl = gkyl_advect_max_abs_speed(a, ql); double amaxr = gkyl_advect_max_abs_speed(a, qr); - + gkyl_free(fr); gkyl_free(fl); return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { return true; // All states are assumed to be valid. } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_advect *advect = container_of(eqn, struct wv_advect, eqn); double a = advect->a; // Advection speed. @@ -227,21 +241,19 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) } static inline void -advect_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +advect_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { diag[0] = qin[0]; } -static inline void -advect_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void advect_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { sout[0] = 0.0; } -void -gkyl_advect_free(const struct gkyl_ref_count* ref) +void gkyl_advect_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. @@ -253,19 +265,13 @@ gkyl_advect_free(const struct gkyl_ref_count* ref) gkyl_free(advect); } -struct gkyl_wv_eqn* -gkyl_wv_advect_new(double a, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_advect_new(double a, bool use_gpu) { - return gkyl_wv_advect_inew(&(struct gkyl_wv_advect_inp) { - .a = a, - .rp_type = WV_ADVECT_RP_ROE, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_advect_inew(&(struct gkyl_wv_advect_inp + ){.a = a, .rp_type = WV_ADVECT_RP_ROE, .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_advect_inew(const struct gkyl_wv_advect_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_advect_inew(const struct gkyl_wv_advect_inp *inp) { struct wv_advect *advect = gkyl_malloc(sizeof(struct wv_advect)); @@ -279,8 +285,7 @@ gkyl_wv_advect_inew(const struct gkyl_wv_advect_inp* inp) advect->eqn.num_waves = 1; advect->eqn.waves_func = wave; advect->eqn.qfluct_func = qfluct; - } - else if (inp->rp_type == WV_ADVECT_RP_LAX) { + } else if (inp->rp_type == WV_ADVECT_RP_LAX) { advect->eqn.num_waves = 2; advect->eqn.waves_func = wave_lax_l; advect->eqn.qfluct_func = qfluct_lax_l; @@ -291,7 +296,7 @@ gkyl_wv_advect_inew(const struct gkyl_wv_advect_inp* inp) advect->eqn.max_speed_func = max_speed; advect->eqn.rotate_to_local_func = rot_to_local; advect->eqn.rotate_to_global_func = rot_to_global; - + advect->eqn.wall_bc_func = advect_wall; advect->eqn.no_slip_bc_func = advect_no_slip; diff --git a/moments/zero/wv_apply_bc.c b/moments/zero/wv_apply_bc.c index 2739ebc779..97c3e6742d 100644 --- a/moments/zero/wv_apply_bc.c +++ b/moments/zero/wv_apply_bc.c @@ -12,9 +12,9 @@ struct gkyl_wv_apply_bc { enum gkyl_edge_loc edge; // edge to apply BC int nghost[GKYL_MAX_DIM]; // number of ghost cells - const struct gkyl_wv_eqn *eqn; // equation + const struct gkyl_wv_eqn *eqn; // equation const struct gkyl_wave_geom *geom; // geometry needed for BCs - + wv_bc_func_t bcfunc; // function pointer void *ctx; // context to pass to function @@ -22,11 +22,11 @@ struct gkyl_wv_apply_bc { struct gkyl_range skin, ghost; // skin and ghost ranges }; -gkyl_wv_apply_bc* -gkyl_wv_apply_bc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_wv_eqn *eqn, const struct gkyl_wave_geom *geom, - int dir, enum gkyl_edge_loc edge, const int *nghost, - wv_bc_func_t bcfunc, void *ctx) +gkyl_wv_apply_bc *gkyl_wv_apply_bc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_wv_eqn *eqn, + const struct gkyl_wave_geom *geom, int dir, enum gkyl_edge_loc edge, const int *nghost, + wv_bc_func_t bcfunc, void *ctx +) { gkyl_wv_apply_bc *up = gkyl_malloc(sizeof(gkyl_wv_apply_bc)); @@ -37,7 +37,7 @@ gkyl_wv_apply_bc_new(const struct gkyl_rect_grid *grid, up->eqn = gkyl_wv_eqn_acquire(eqn); up->geom = gkyl_wave_geom_acquire(geom); - + up->bcfunc = bcfunc; up->ctx = ctx; @@ -49,9 +49,9 @@ gkyl_wv_apply_bc_new(const struct gkyl_rect_grid *grid, return up; } -void -gkyl_wv_apply_bc_advance(const gkyl_wv_apply_bc *bc, double tm, - const struct gkyl_range *update_rng, struct gkyl_array *out) +void gkyl_wv_apply_bc_advance( + const gkyl_wv_apply_bc *bc, double tm, const struct gkyl_range *update_rng, struct gkyl_array *out +) { enum gkyl_edge_loc edge = bc->edge; int dir = bc->dir, ndim = bc->grid.ndim, ncomp = out->ncomp; @@ -60,10 +60,12 @@ gkyl_wv_apply_bc_advance(const gkyl_wv_apply_bc *bc, double tm, double skin_local[meqn], ghost_local[meqn]; // return immediately if update region does not touch boundary - if ( (edge == GKYL_LOWER_EDGE) && (update_rng->lower[dir] > bc->range.lower[dir]) ) + if ((edge == GKYL_LOWER_EDGE) && (update_rng->lower[dir] > bc->range.lower[dir])) { return; - if ( (edge == GKYL_UPPER_EDGE) && (update_rng->upper[dir] < bc->range.upper[dir]) ) + } + if ((edge == GKYL_UPPER_EDGE) && (update_rng->upper[dir] < bc->range.upper[dir])) { return; + } // compute intersection for region to update struct gkyl_range up_range; @@ -74,23 +76,22 @@ gkyl_wv_apply_bc_advance(const gkyl_wv_apply_bc *bc, double tm, int eidx[GKYL_MAX_DIM]; // index into geometry int gidx[GKYL_MAX_DIM]; // index into ghost cell - + // create iterator to walk over skin cells struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &up_range); - - while (gkyl_range_iter_next(&iter)) { + while (gkyl_range_iter_next(&iter)) { long sloc = gkyl_range_idx(update_rng, iter.idx); gkyl_copy_int_arr(ndim, iter.idx, gidx); - + // compute linear index into appropriate ghost-cell: // this strange indexing ensures that the ghost cell index is // essentially "reflection" of the skin cell index; might not be // correct for all BCs but I am not sure how else to handle // multiple ghost-cell situations - gidx[dir] = 2*edge_idx-gidx[dir]+fact; + gidx[dir] = 2 * edge_idx - gidx[dir] + fact; long gloc = gkyl_range_idx(update_rng, gidx); // compute index into geometry: we always use the edge on the @@ -100,30 +101,32 @@ gkyl_wv_apply_bc_advance(const gkyl_wv_apply_bc *bc, double tm, if (edge == GKYL_LOWER_EDGE) { gkyl_copy_int_arr(ndim, iter.idx, eidx); eidx[dir] = edge_idx; - } - else { + } else { gkyl_copy_int_arr(ndim, gidx, eidx); - eidx[dir] = edge_idx+1; + eidx[dir] = edge_idx + 1; } const struct gkyl_wave_cell_geom *wg = gkyl_wave_geom_get(bc->geom, eidx); // rotate skin data to local coordinates - gkyl_wv_eqn_rotate_to_local(bc->eqn, wg->tau1[dir], wg->tau2[dir], wg->norm[dir], - gkyl_array_fetch(out, sloc), skin_local); - + gkyl_wv_eqn_rotate_to_local( + bc->eqn, wg->tau1[dir], wg->tau2[dir], wg->norm[dir], gkyl_array_fetch(out, sloc), skin_local + ); + // apply boundary condition in local coordinates bc->bcfunc(bc->eqn, tm, ncomp, skin_local, ghost_local, bc->ctx); // rotate back to global - gkyl_wv_eqn_rotate_to_global(bc->eqn, wg->tau1[dir], wg->tau2[dir], wg->norm[dir], - ghost_local, gkyl_array_fetch(out, gloc)); + gkyl_wv_eqn_rotate_to_global( + bc->eqn, wg->tau1[dir], wg->tau2[dir], wg->norm[dir], ghost_local, gkyl_array_fetch(out, gloc) + ); } } -void -gkyl_wv_apply_bc_to_buff(const gkyl_wv_apply_bc *bc, double tm, - const struct gkyl_range *update_rng, const struct gkyl_array *inp, double *buffer) +void gkyl_wv_apply_bc_to_buff( + const gkyl_wv_apply_bc *bc, double tm, const struct gkyl_range *update_rng, + const struct gkyl_array *inp, double *buffer +) { enum gkyl_edge_loc edge = bc->edge; int dir = bc->dir, ndim = bc->grid.ndim, ncomp = inp->ncomp; @@ -132,10 +135,12 @@ gkyl_wv_apply_bc_to_buff(const gkyl_wv_apply_bc *bc, double tm, double skin_local[meqn], ghost_local[meqn]; // return immediately if update region does not touch boundary - if ( (edge == GKYL_LOWER_EDGE) && (update_rng->lower[dir] > bc->range.lower[dir]) ) + if ((edge == GKYL_LOWER_EDGE) && (update_rng->lower[dir] > bc->range.lower[dir])) { return; - if ( (edge == GKYL_UPPER_EDGE) && (update_rng->upper[dir] < bc->range.upper[dir]) ) + } + if ((edge == GKYL_UPPER_EDGE) && (update_rng->upper[dir] < bc->range.upper[dir])) { return; + } // compute intersection for region to update struct gkyl_range up_range; @@ -144,56 +149,56 @@ gkyl_wv_apply_bc_to_buff(const gkyl_wv_apply_bc *bc, double tm, int edge_idx = (edge == GKYL_LOWER_EDGE) ? bc->range.lower[dir] : bc->range.upper[dir]; int fact = (edge == GKYL_LOWER_EDGE) ? -1 : 1; - int ncells = bc->range.upper[dir]-bc->range.lower[dir]+1; // cells in 'dir' + int ncells = bc->range.upper[dir] - bc->range.lower[dir] + 1; // cells in 'dir' int sidx[GKYL_MAX_DIM]; // index into skin-cell geometry int gidx[GKYL_MAX_DIM]; // index into ghost-cell geometry - + // create iterator to walk over skin cells struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &up_range); long count = 0; while (gkyl_range_iter_next(&iter)) { - long sloc = gkyl_range_idx(update_rng, iter.idx); // compute index into geometry if (edge == GKYL_LOWER_EDGE) { gkyl_copy_int_arr(ndim, iter.idx, sidx); sidx[dir] = iter.idx[dir]; - + gkyl_copy_int_arr(ndim, iter.idx, gidx); - gidx[dir] = sidx[dir]+ncells; - } - else { + gidx[dir] = sidx[dir] + ncells; + } else { gkyl_copy_int_arr(ndim, iter.idx, sidx); - sidx[dir] = iter.idx[dir]+1; - + sidx[dir] = iter.idx[dir] + 1; + gkyl_copy_int_arr(ndim, iter.idx, gidx); - gidx[dir] = sidx[dir]-ncells; + gidx[dir] = sidx[dir] - ncells; } const struct gkyl_wave_cell_geom *wgs = gkyl_wave_geom_get(bc->geom, sidx); // rotate skin data to local coordinates of skin-cell edge - gkyl_wv_eqn_rotate_to_local(bc->eqn, wgs->tau1[dir], wgs->tau2[dir], wgs->norm[dir], - gkyl_array_cfetch(inp, sloc), skin_local); - + gkyl_wv_eqn_rotate_to_local( + bc->eqn, wgs->tau1[dir], wgs->tau2[dir], wgs->norm[dir], gkyl_array_cfetch(inp, sloc), + skin_local + ); + // apply boundary condition in local coordinates bc->bcfunc(bc->eqn, tm, ncomp, skin_local, ghost_local, bc->ctx); // rotate back to global coordinates as defined on ghost cell edge const struct gkyl_wave_cell_geom *wgg = gkyl_wave_geom_get(bc->geom, gidx); - gkyl_wv_eqn_rotate_to_global(bc->eqn, wgg->tau1[dir], wgg->tau2[dir], wgg->norm[dir], - ghost_local, buffer+meqn*count); + gkyl_wv_eqn_rotate_to_global( + bc->eqn, wgg->tau1[dir], wgg->tau2[dir], wgg->norm[dir], ghost_local, buffer + meqn * count + ); count += 1; - } + } } -void -gkyl_wv_apply_bc_release(gkyl_wv_apply_bc* bc) +void gkyl_wv_apply_bc_release(gkyl_wv_apply_bc *bc) { gkyl_wv_eqn_release(bc->eqn); gkyl_wave_geom_release(bc->geom); diff --git a/moments/zero/wv_burgers.c b/moments/zero/wv_burgers.c index bb114de5d5..4a58813847 100644 --- a/moments/zero/wv_burgers.c +++ b/moments/zero/wv_burgers.c @@ -15,66 +15,71 @@ #include #include -static inline double -gkyl_burgers_max_abs_speed(const double* q) +static inline double gkyl_burgers_max_abs_speed(const double *q) { return fabs(q[0]); } -void -gkyl_burgers_flux(const double* q, double* flux) +void gkyl_burgers_flux(const double *q, double *flux) { flux[0] = (0.5 * q[0] * q[0]); } -void -gkyl_burgers_flux_deriv(const double* q, double* flux_deriv) +void gkyl_burgers_flux_deriv(const double *q, double *flux_deriv) { flux_deriv[0] = q[0]; } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. wout[0] = qin[0]; } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. qout[0] = win[0]; } -static void -burgers_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void burgers_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { ghost[0] = skin[0]; } -static void -burgers_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void burgers_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { ghost[0] = skin[0]; } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { double sl = gkyl_burgers_max_abs_speed(ql); double sr = gkyl_burgers_max_abs_speed(qr); @@ -98,8 +103,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[1]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -109,24 +116,30 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co apdq[0] = (s0p * w0[0]) + (s1p * w1[0]); } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_burgers *burgers = container_of(eqn, struct wv_burgers, eqn); - + double *fl_deriv = gkyl_malloc(sizeof(double)); double *fr_deriv = gkyl_malloc(sizeof(double)); gkyl_burgers_flux_deriv(ql, fl_deriv); @@ -145,49 +158,52 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[0]; } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0]; if (s[0] < 0.0) { amdq[0] = s[0] * w0[0]; apdq[0] = 0.0; - } - else { + } else { amdq[0] = 0.0; apdq[0] = s[0] * w0[0]; } } -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) -{ +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) +{ double *fr = gkyl_malloc(sizeof(double)); double *fl = gkyl_malloc(sizeof(double)); gkyl_burgers_flux(ql, fl); @@ -197,41 +213,37 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou double amaxl = gkyl_burgers_max_abs_speed(ql); double amaxr = gkyl_burgers_max_abs_speed(qr); - + gkyl_free(fr); gkyl_free(fl); return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { return true; // All states are assumed to be valid. } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) -{ +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) +{ return gkyl_burgers_max_abs_speed(q); } static inline void -burgers_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +burgers_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { diag[0] = qin[0]; } -static inline void -burgers_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void burgers_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { sout[0] = 0.0; } -void -gkyl_burgers_free(const struct gkyl_ref_count* ref) +void gkyl_burgers_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. @@ -243,18 +255,13 @@ gkyl_burgers_free(const struct gkyl_ref_count* ref) gkyl_free(burgers); } -struct gkyl_wv_eqn* -gkyl_wv_burgers_new(bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_burgers_new(bool use_gpu) { - return gkyl_wv_burgers_inew(&(struct gkyl_wv_burgers_inp) { - .rp_type = WV_BURGERS_RP_ROE, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_burgers_inew(&(struct gkyl_wv_burgers_inp + ){.rp_type = WV_BURGERS_RP_ROE, .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_burgers_inew(const struct gkyl_wv_burgers_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_burgers_inew(const struct gkyl_wv_burgers_inp *inp) { struct wv_burgers *burgers = gkyl_malloc(sizeof(struct wv_burgers)); @@ -266,8 +273,7 @@ gkyl_wv_burgers_inew(const struct gkyl_wv_burgers_inp* inp) burgers->eqn.num_waves = 1; burgers->eqn.waves_func = wave_roe_l; burgers->eqn.qfluct_func = qfluct_roe_l; - } - else if (inp->rp_type == WV_BURGERS_RP_LAX) { + } else if (inp->rp_type == WV_BURGERS_RP_LAX) { burgers->eqn.num_waves = 2; burgers->eqn.waves_func = wave_lax_l; burgers->eqn.qfluct_func = qfluct_lax_l; @@ -278,7 +284,7 @@ gkyl_wv_burgers_inew(const struct gkyl_wv_burgers_inp* inp) burgers->eqn.max_speed_func = max_speed; burgers->eqn.rotate_to_local_func = rot_to_local; burgers->eqn.rotate_to_global_func = rot_to_global; - + burgers->eqn.wall_bc_func = burgers_wall; burgers->eqn.no_slip_bc_func = burgers_no_slip; diff --git a/moments/zero/wv_canonical_pb_fluid.c b/moments/zero/wv_canonical_pb_fluid.c index 6400c653a9..740531fa8c 100644 --- a/moments/zero/wv_canonical_pb_fluid.c +++ b/moments/zero/wv_canonical_pb_fluid.c @@ -6,45 +6,47 @@ #include #include -void -gkyl_wv_can_pb_incompress_euler_free(const struct gkyl_ref_count *ref) -{ +void gkyl_wv_can_pb_incompress_euler_free(const struct gkyl_ref_count *ref) +{ struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); - struct wv_can_pb_incompress_euler *can_pb_incompress_euler = container_of(base, struct wv_can_pb_incompress_euler, eqn); - gkyl_free(can_pb_incompress_euler); + struct wv_can_pb_incompress_euler *can_pb_incompress_euler = + container_of(base, struct wv_can_pb_incompress_euler, eqn); + gkyl_free(can_pb_incompress_euler); } -struct gkyl_wv_eqn* -gkyl_wv_can_pb_incompress_euler_new() -{ - struct wv_can_pb_incompress_euler *can_pb_incompress_euler = gkyl_malloc(sizeof(struct wv_can_pb_incompress_euler)); +struct gkyl_wv_eqn *gkyl_wv_can_pb_incompress_euler_new() +{ + struct wv_can_pb_incompress_euler *can_pb_incompress_euler = + gkyl_malloc(sizeof(struct wv_can_pb_incompress_euler)); can_pb_incompress_euler->eqn.type = GKYL_EQN_CAN_PB_INCOMPRESS_EULER; - can_pb_incompress_euler->eqn.num_equations = 1; + can_pb_incompress_euler->eqn.num_equations = 1; can_pb_incompress_euler->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(can_pb_incompress_euler->eqn.flags); - can_pb_incompress_euler->eqn.ref_count = gkyl_ref_count_init(gkyl_wv_can_pb_incompress_euler_free); - can_pb_incompress_euler->eqn.on_dev = &can_pb_incompress_euler->eqn; // CPU eqn obj points to itself + can_pb_incompress_euler->eqn.ref_count = + gkyl_ref_count_init(gkyl_wv_can_pb_incompress_euler_free); + can_pb_incompress_euler->eqn.on_dev = + &can_pb_incompress_euler->eqn; // CPU eqn obj points to itself return &can_pb_incompress_euler->eqn; } -void -gkyl_wv_can_pb_hasegawa_mima_free(const struct gkyl_ref_count *ref) -{ +void gkyl_wv_can_pb_hasegawa_mima_free(const struct gkyl_ref_count *ref) +{ struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); - struct wv_can_pb_hasegawa_mima *can_pb_hasegawa_mima = container_of(base, struct wv_can_pb_hasegawa_mima, eqn); - gkyl_free(can_pb_hasegawa_mima); + struct wv_can_pb_hasegawa_mima *can_pb_hasegawa_mima = + container_of(base, struct wv_can_pb_hasegawa_mima, eqn); + gkyl_free(can_pb_hasegawa_mima); } -struct gkyl_wv_eqn* -gkyl_wv_can_pb_hasegawa_mima_new() -{ - struct wv_can_pb_hasegawa_mima *can_pb_hasegawa_mima = gkyl_malloc(sizeof(struct wv_can_pb_hasegawa_mima)); +struct gkyl_wv_eqn *gkyl_wv_can_pb_hasegawa_mima_new() +{ + struct wv_can_pb_hasegawa_mima *can_pb_hasegawa_mima = + gkyl_malloc(sizeof(struct wv_can_pb_hasegawa_mima)); can_pb_hasegawa_mima->eqn.type = GKYL_EQN_CAN_PB_HASEGAWA_MIMA; - can_pb_hasegawa_mima->eqn.num_equations = 1; + can_pb_hasegawa_mima->eqn.num_equations = 1; can_pb_hasegawa_mima->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(can_pb_hasegawa_mima->eqn.flags); @@ -54,42 +56,44 @@ gkyl_wv_can_pb_hasegawa_mima_new() return &can_pb_hasegawa_mima->eqn; } -void -gkyl_wv_can_pb_hasegawa_wakatani_free(const struct gkyl_ref_count *ref) -{ +void gkyl_wv_can_pb_hasegawa_wakatani_free(const struct gkyl_ref_count *ref) +{ struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); - struct wv_can_pb_hasegawa_wakatani *can_pb_hasegawa_wakatani = container_of(base, struct wv_can_pb_hasegawa_wakatani, eqn); - gkyl_free(can_pb_hasegawa_wakatani); + struct wv_can_pb_hasegawa_wakatani *can_pb_hasegawa_wakatani = + container_of(base, struct wv_can_pb_hasegawa_wakatani, eqn); + gkyl_free(can_pb_hasegawa_wakatani); } -struct gkyl_wv_eqn* -gkyl_wv_can_pb_hasegawa_wakatani_new(double alpha, bool is_modified) -{ - struct wv_can_pb_hasegawa_wakatani *can_pb_hasegawa_wakatani = gkyl_malloc(sizeof(struct wv_can_pb_hasegawa_wakatani)); +struct gkyl_wv_eqn *gkyl_wv_can_pb_hasegawa_wakatani_new(double alpha, bool is_modified) +{ + struct wv_can_pb_hasegawa_wakatani *can_pb_hasegawa_wakatani = + gkyl_malloc(sizeof(struct wv_can_pb_hasegawa_wakatani)); can_pb_hasegawa_wakatani->eqn.type = GKYL_EQN_CAN_PB_HASEGAWA_WAKATANI; - can_pb_hasegawa_wakatani->eqn.num_equations = 2; - can_pb_hasegawa_wakatani->alpha = alpha; - can_pb_hasegawa_wakatani->is_modified = is_modified; + can_pb_hasegawa_wakatani->eqn.num_equations = 2; + can_pb_hasegawa_wakatani->alpha = alpha; + can_pb_hasegawa_wakatani->is_modified = is_modified; can_pb_hasegawa_wakatani->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(can_pb_hasegawa_wakatani->eqn.flags); - can_pb_hasegawa_wakatani->eqn.ref_count = gkyl_ref_count_init(gkyl_wv_can_pb_hasegawa_wakatani_free); - can_pb_hasegawa_wakatani->eqn.on_dev = &can_pb_hasegawa_wakatani->eqn; // CPU eqn obj points to itself + can_pb_hasegawa_wakatani->eqn.ref_count = + gkyl_ref_count_init(gkyl_wv_can_pb_hasegawa_wakatani_free); + can_pb_hasegawa_wakatani->eqn.on_dev = + &can_pb_hasegawa_wakatani->eqn; // CPU eqn obj points to itself return &can_pb_hasegawa_wakatani->eqn; } -double -gkyl_wv_can_pb_hasegawa_wakatani_alpha(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_can_pb_hasegawa_wakatani_alpha(const struct gkyl_wv_eqn *eqn) { - const struct wv_can_pb_hasegawa_wakatani *can_pb_hasegawa_wakatani = container_of(eqn, struct wv_can_pb_hasegawa_wakatani, eqn); + const struct wv_can_pb_hasegawa_wakatani *can_pb_hasegawa_wakatani = + container_of(eqn, struct wv_can_pb_hasegawa_wakatani, eqn); return can_pb_hasegawa_wakatani->alpha; } -bool -gkyl_wv_can_pb_hasegawa_wakatani_is_modified(const struct gkyl_wv_eqn* eqn) +bool gkyl_wv_can_pb_hasegawa_wakatani_is_modified(const struct gkyl_wv_eqn *eqn) { - const struct wv_can_pb_hasegawa_wakatani *can_pb_hasegawa_wakatani = container_of(eqn, struct wv_can_pb_hasegawa_wakatani, eqn); + const struct wv_can_pb_hasegawa_wakatani *can_pb_hasegawa_wakatani = + container_of(eqn, struct wv_can_pb_hasegawa_wakatani, eqn); return can_pb_hasegawa_wakatani->is_modified; } diff --git a/moments/zero/wv_coldfluid.c b/moments/zero/wv_coldfluid.c index 1b06dd7484..151e0ef045 100644 --- a/moments/zero/wv_coldfluid.c +++ b/moments/zero/wv_coldfluid.c @@ -7,34 +7,33 @@ #define RHOV 2 #define RHOW 3 -#define SQ(x) ((x)*(x)) +#define SQ(x) ((x) * (x)) struct wv_coldfluid { struct gkyl_wv_eqn eqn; // base object }; -static void -coldfluid_flux(const double q[4], double flux[4]) +static void coldfluid_flux(const double q[4], double flux[4]) { - double u = q[RHOU]/q[0]; + double u = q[RHOU] / q[0]; flux[0] = q[RHOU]; // rho*u - flux[RHOU] = q[RHOU]*u; // rho*u*u - flux[RHOV] = q[RHOV]*u; // rho*v*u - flux[RHOW] = q[RHOW]*u; // rho*w*u + flux[RHOU] = q[RHOU] * u; // rho*u*u + flux[RHOV] = q[RHOV] * u; // rho*v*u + flux[RHOW] = q[RHOW] * u; // rho*w*u } static inline void -coldfluid_cons_to_diag(const struct gkyl_wv_eqn *eqn, - const double *qin, double *diag) +coldfluid_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { // density and moment as copied as-is - for (int i=0; i<4; ++i) diag[i] = qin[i]; - double ke = 0.5*(qin[1]*qin[1] + qin[2]*qin[2] + qin[3]*qin[3])/qin[0]; + for (int i = 0; i < 4; ++i) { + diag[i] = qin[i]; + } + double ke = 0.5 * (qin[1] * qin[1] + qin[2] * qin[2] + qin[3] * qin[3]) / qin[0]; diag[4] = ke; } -static void -coldfluid_free(const struct gkyl_ref_count *ref) +static void coldfluid_free(const struct gkyl_ref_count *ref) { struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); struct wv_coldfluid *coldfluid = container_of(base, struct wv_coldfluid, eqn); @@ -42,88 +41,96 @@ coldfluid_free(const struct gkyl_ref_count *ref) } static inline void -cons_to_riem(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *qin, double *wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: this should use proper L matrix - for (int i=0; i<4; ++i) + for (int i = 0; i < 4; ++i) { wout[i] = qin[i]; + } } static inline void -riem_to_cons(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *win, double *qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: this should use proper L matrix - for (int i=0; i<4; ++i) + for (int i = 0; i < 4; ++i) { qout[i] = win[i]; + } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qglobal, double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; - qlocal[1] = qglobal[1]*norm[0] + qglobal[2]*norm[1] + qglobal[3]*norm[2]; - qlocal[2] = qglobal[1]*tau1[0] + qglobal[2]*tau1[1] + qglobal[3]*tau1[2]; - qlocal[3] = qglobal[1]*tau2[0] + qglobal[2]*tau2[1] + qglobal[3]*tau2[2]; + qlocal[1] = qglobal[1] * norm[0] + qglobal[2] * norm[1] + qglobal[3] * norm[2]; + qlocal[2] = qglobal[1] * tau1[0] + qglobal[2] * tau1[1] + qglobal[3] * tau1[2]; + qlocal[3] = qglobal[1] * tau2[0] + qglobal[2] * tau2[1] + qglobal[3] * tau2[2]; } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qlocal, double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; - qglobal[1] = qlocal[1]*norm[0] + qlocal[2]*tau1[0] + qlocal[3]*tau2[0]; - qglobal[2] = qlocal[1]*norm[1] + qlocal[2]*tau1[1] + qlocal[3]*tau2[1]; - qglobal[3] = qlocal[1]*norm[2] + qlocal[2]*tau1[2] + qlocal[3]*tau2[2]; + qglobal[1] = qlocal[1] * norm[0] + qlocal[2] * tau1[0] + qlocal[3] * tau2[0]; + qglobal[2] = qlocal[1] * norm[1] + qlocal[2] * tau1[1] + qlocal[3] * tau2[1]; + qglobal[3] = qlocal[1] * norm[2] + qlocal[2] * tau1[2] + qlocal[3] * tau2[2]; } // Waves and speeds using Roe averaging -static double -wave_roe(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *delta, const double *ql, const double *qr, - const double phil, const double phir, double *waves, double *s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { double f[4]; - double ur = qr[RHOU]/qr[0], ul = ql[RHOU]/ql[0]; + double ur = qr[RHOU] / qr[0], ul = ql[RHOU] / ql[0]; double *wv = 0; if ((ul < 0) && (0 < ur)) { // vacuum intermediate state will be formed coldfluid_flux(ql, f); wv = &waves[0]; - for(int m=0; m<4; ++m) wv[m] = -f[m]; + for (int m = 0; m < 4; ++m) { + wv[m] = -f[m]; + } s[0] = ul; coldfluid_flux(qr, f); wv = &waves[4]; - for(int m=0; m<4; ++m) wv[m] = f[m]; + for (int m = 0; m < 4; ++m) { + wv[m] = f[m]; + } s[1] = ur; - } - else { + } else { // no vacuum state double rl = ql[0]; double rr = qr[0]; // compute Roe averaged speed - double uav = (sqrt(rl)*ul + sqrt(rr)*ur)/(sqrt(rl)+sqrt(rr)); - - if(uav<0) { + double uav = (sqrt(rl) * ul + sqrt(rr) * ur) / (sqrt(rl) + sqrt(rr)); + + if (uav < 0) { wv = &waves[0]; - for(int m=0; m<4; ++m) + for (int m = 0; m < 4; ++m) { wv[m] = delta[m]; + } wv = &waves[4]; - for(int m=0; m<4; ++m) + for (int m = 0; m < 4; ++m) { wv[m] = 0.0; - } - else { + } + } else { wv = &waves[0]; - for(int m=0; m<4; ++m) + for (int m = 0; m < 4; ++m) { wv[m] = 0; + } wv = &waves[4]; - for(int m=0; m<4; ++m) + for (int m = 0; m < 4; ++m) { wv[m] = delta[m]; + } } s[0] = uav; s[1] = uav; @@ -132,49 +139,52 @@ wave_roe(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, return fmax(fabs(s[0]), fabs(s[1])); } -static void -qfluct_roe(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *ql, const double *qr, const double phil, const double phir, const double *waves, const double *s, - double *amdq, double *apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { int meqn = 4, mwaves = 2; - - for (int m=0; m 0.0) { + } else if (s[mw] > 0.0) { apdq[m] += wv[m]; - } - else { - amdq[m] += 0.5*wv[m]; - apdq[m] += 0.5*wv[m]; + } else { + amdq[m] += 0.5 * wv[m]; + apdq[m] += 0.5 * wv[m]; } } } @@ -187,37 +197,35 @@ flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, dou coldfluid_flux(ql, fl); coldfluid_flux(qr, fr); - for (int m=0; m<4; ++m) flux_jump[m] = fr[m]-fl[m]; + for (int m = 0; m < 4; ++m) { + flux_jump[m] = fr[m] - fl[m]; + } - double amaxl = ql[RHOU]/ql[0]; - double amaxr = qr[RHOU]/qr[0]; + double amaxl = ql[RHOU] / ql[0]; + double amaxr = qr[RHOU] / qr[0]; return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn *eqn, const double *q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { return q[0] > 0.0; } -static double -max_speed(const struct gkyl_wv_eqn *eqn, const double *q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_coldfluid *coldfluid = container_of(eqn, struct wv_coldfluid, eqn); - return fabs(q[RHOU]/q[0]); + return fabs(q[RHOU] / q[0]); } -static inline void -coldfluid_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void coldfluid_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < 4; i++) { sout[i] = 0.0; } } -struct gkyl_wv_eqn* -gkyl_wv_coldfluid_new(void) +struct gkyl_wv_eqn *gkyl_wv_coldfluid_new(void) { struct wv_coldfluid *coldfluid = gkyl_malloc(sizeof(struct wv_coldfluid)); @@ -225,7 +233,7 @@ gkyl_wv_coldfluid_new(void) coldfluid->eqn.num_equations = 4; coldfluid->eqn.num_waves = 2; coldfluid->eqn.num_diag = 5; // KE is final component - + coldfluid->eqn.waves_func = wave_roe; coldfluid->eqn.qfluct_func = qfluct_roe; coldfluid->eqn.ffluct_func = ffluct_roe; diff --git a/moments/zero/wv_embed_geo.c b/moments/zero/wv_embed_geo.c index 03ed06a933..4d44e8560f 100644 --- a/moments/zero/wv_embed_geo.c +++ b/moments/zero/wv_embed_geo.c @@ -3,9 +3,9 @@ #include #include -struct gkyl_wv_embed_geo* -gkyl_wv_embed_geo_new(enum gkyl_embed_type type, void *mask_func, - wv_embed_func_t embed_func, void *ctx) +struct gkyl_wv_embed_geo *gkyl_wv_embed_geo_new( + enum gkyl_embed_type type, void *mask_func, wv_embed_func_t embed_func, void *ctx +) { gkyl_wv_embed_geo *geo = gkyl_malloc(sizeof(gkyl_wv_embed_geo)); @@ -17,18 +17,17 @@ gkyl_wv_embed_geo_new(enum gkyl_embed_type type, void *mask_func, return geo; } -void -gkyl_wv_embed_geo_new_mask(struct gkyl_wv_embed_geo *geo, struct gkyl_rect_grid *grid, - struct gkyl_range *rng, struct gkyl_array *mask) +void gkyl_wv_embed_geo_new_mask( + struct gkyl_wv_embed_geo *geo, struct gkyl_rect_grid *grid, struct gkyl_range *rng, + struct gkyl_array *mask +) { - gkyl_fv_proj *proj = gkyl_fv_proj_new(grid, 1, 1, geo->mask_func, - geo->ctx); + gkyl_fv_proj *proj = gkyl_fv_proj_new(grid, 1, 1, geo->mask_func, geo->ctx); gkyl_fv_proj_advance(proj, 0.0, rng, mask); gkyl_fv_proj_release(proj); } -void -gkyl_wv_embed_geo_release(gkyl_wv_embed_geo* geo) +void gkyl_wv_embed_geo_release(gkyl_wv_embed_geo *geo) { gkyl_free(geo); } diff --git a/moments/zero/wv_eqn.c b/moments/zero/wv_eqn.c index bba1dccefe..ff631efdc1 100644 --- a/moments/zero/wv_eqn.c +++ b/moments/zero/wv_eqn.c @@ -3,44 +3,56 @@ // these ensure inline functions are defined only once -extern inline double gkyl_wv_eqn_waves(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, const double *qr, const double phil, const double phir, double *waves, double *speeds); - -extern inline void gkyl_wv_eqn_qfluct(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, const double phil, const double phir, const double *waves, const double *speeds, double *amdq, double *apdq); - -extern inline void gkyl_wv_eqn_ffluct(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, const double phil, const double phir, const double *waves, const double *speeds, double *amdq, double *apdq); - -extern inline double gkyl_wv_eqn_flux_jump(const struct gkyl_wv_eqn *eqn, - const double *ql, const double *qr, double *flux_jump); +extern inline double gkyl_wv_eqn_waves( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *speeds +); + +extern inline void gkyl_wv_eqn_qfluct( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *speeds, double *amdq, + double *apdq +); + +extern inline void gkyl_wv_eqn_ffluct( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *speeds, double *amdq, + double *apdq +); + +extern inline double gkyl_wv_eqn_flux_jump( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump +); extern inline bool gkyl_wv_eqn_check_inv(const struct gkyl_wv_eqn *eqn, const double *q); extern inline double gkyl_wv_eqn_max_speed(const struct gkyl_wv_eqn *eqn, const double *q); -extern inline void gkyl_wv_eqn_rotate_to_local(const struct gkyl_wv_eqn *eqn, - const double *tau1, const double *tau2, const double *norm, - const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal); +extern inline void gkyl_wv_eqn_rotate_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +); -extern inline void gkyl_wv_eqn_rotate_to_global(const struct gkyl_wv_eqn *eqn, - const double *tau1, const double *tau2, const double *norm, - const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal); +extern inline void gkyl_wv_eqn_rotate_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +); -extern inline void gkyl_wv_eqn_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout); +extern inline void +gkyl_wv_eqn_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout); -bool -gkyl_wv_eqn_is_cu_dev(const struct gkyl_wv_eqn *eqn) +bool gkyl_wv_eqn_is_cu_dev(const struct gkyl_wv_eqn *eqn) { return GKYL_IS_CU_ALLOC(eqn->flags); } -struct gkyl_wv_eqn* -gkyl_wv_eqn_acquire(const struct gkyl_wv_eqn* eqn) +struct gkyl_wv_eqn *gkyl_wv_eqn_acquire(const struct gkyl_wv_eqn *eqn) { gkyl_ref_count_inc(&eqn->ref_count); - return (struct gkyl_wv_eqn*) eqn; + return (struct gkyl_wv_eqn *)eqn; } -void -gkyl_wv_eqn_release(const struct gkyl_wv_eqn* eqn) +void gkyl_wv_eqn_release(const struct gkyl_wv_eqn *eqn) { gkyl_ref_count_dec(&eqn->ref_count); } diff --git a/moments/zero/wv_euler.c b/moments/zero/wv_euler.c index f406b78acc..8f94453536 100644 --- a/moments/zero/wv_euler.c +++ b/moments/zero/wv_euler.c @@ -6,61 +6,59 @@ #include #include -void -gkyl_euler_free(const struct gkyl_ref_count *ref) +void gkyl_euler_free(const struct gkyl_ref_count *ref) { struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); - + if (gkyl_wv_eqn_is_cu_dev(base)) { // free inner on_dev object struct wv_euler *euler = container_of(base->on_dev, struct wv_euler, eqn); gkyl_cu_free(euler); } - + struct wv_euler *euler = container_of(base, struct wv_euler, eqn); gkyl_free(euler); } -struct gkyl_wv_eqn* -gkyl_wv_euler_inew(const struct gkyl_wv_euler_inp *inp) +struct gkyl_wv_eqn *gkyl_wv_euler_inew(const struct gkyl_wv_euler_inp *inp) { #ifdef GKYL_HAVE_CUDA - if(inp->use_gpu) { + if (inp->use_gpu) { return gkyl_wv_euler_cu_dev_inew(inp); - } -#endif + } +#endif struct wv_euler *euler = gkyl_malloc(sizeof(struct wv_euler)); euler->eqn.type = GKYL_EQN_EULER; euler->eqn.num_equations = 5; euler->eqn.num_diag = 6; // KE and PE stored separate - + euler->gas_gamma = inp->gas_gamma; switch (inp->rp_type) { - case WV_EULER_RP_ROE: - euler->eqn.num_waves = 3; - euler->eqn.waves_func = wave_roe_l; - euler->eqn.qfluct_func = qfluct_roe_l; - break; - - case WV_EULER_RP_HLLC: - euler->eqn.num_waves = 3; - euler->eqn.waves_func = wave_hllc_l; - euler->eqn.qfluct_func = qfluct_hllc_l; - break; - - case WV_EULER_RP_LAX: - euler->eqn.num_waves = 2; - euler->eqn.waves_func = wave_lax_l; - euler->eqn.qfluct_func = qfluct_lax_l; - break; - - case WV_EULER_RP_HLL: - euler->eqn.num_waves = 2; - euler->eqn.waves_func = wave_hll_l; - euler->eqn.qfluct_func = qfluct_hll_l; - break; + case WV_EULER_RP_ROE: + euler->eqn.num_waves = 3; + euler->eqn.waves_func = wave_roe_l; + euler->eqn.qfluct_func = qfluct_roe_l; + break; + + case WV_EULER_RP_HLLC: + euler->eqn.num_waves = 3; + euler->eqn.waves_func = wave_hllc_l; + euler->eqn.qfluct_func = qfluct_hllc_l; + break; + + case WV_EULER_RP_LAX: + euler->eqn.num_waves = 2; + euler->eqn.waves_func = wave_lax_l; + euler->eqn.qfluct_func = qfluct_lax_l; + break; + + case WV_EULER_RP_HLL: + euler->eqn.num_waves = 2; + euler->eqn.waves_func = wave_hll_l; + euler->eqn.qfluct_func = qfluct_hll_l; + break; } euler->eqn.flux_jump = flux_jump; @@ -87,39 +85,33 @@ gkyl_wv_euler_inew(const struct gkyl_wv_euler_inp *inp) euler->eqn.embed_geo = inp->embed_geo; if (euler->eqn.embed_geo) { switch (euler->eqn.embed_geo->type) { - case GKYL_EMBED_ABSORB: - euler->eqn.embed_geo->embed_func = wave_embed_absorb; - break; + case GKYL_EMBED_ABSORB: + euler->eqn.embed_geo->embed_func = wave_embed_absorb; + break; - case GKYL_EMBED_REFLECT: - euler->eqn.embed_geo->embed_func = wave_embed_reflect; - break; + case GKYL_EMBED_REFLECT: + euler->eqn.embed_geo->embed_func = wave_embed_reflect; + break; - case GKYL_EMBED_FUNC: - break; // already set by gkyl_wv_embed_geo_new + case GKYL_EMBED_FUNC: + break; // already set by gkyl_wv_embed_geo_new - default: - assert(false); - break; + default: + assert(false); + break; } - } + } - return &euler->eqn; + return &euler->eqn; } -struct gkyl_wv_eqn* -gkyl_wv_euler_new(double gas_gamma, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_euler_new(double gas_gamma, bool use_gpu) { - return gkyl_wv_euler_inew( &(struct gkyl_wv_euler_inp) { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_ROE, - .use_gpu = use_gpu - } - ); + return gkyl_wv_euler_inew(&(struct gkyl_wv_euler_inp + ){.gas_gamma = gas_gamma, .rp_type = WV_EULER_RP_ROE, .use_gpu = use_gpu}); } -double -gkyl_wv_euler_gas_gamma(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_euler_gas_gamma(const struct gkyl_wv_eqn *eqn) { const struct wv_euler *euler = container_of(eqn, struct wv_euler, eqn); return euler->gas_gamma; diff --git a/moments/zero/wv_euler_cu.cu b/moments/zero/wv_euler_cu.cu index 93db1f8081..0a0b8b285d 100644 --- a/moments/zero/wv_euler_cu.cu +++ b/moments/zero/wv_euler_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include } @@ -11,33 +11,33 @@ extern "C" { // CUDA kernel to set device pointers to euler kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void +__global__ static void wv_euler_set_cu_dev_ptrs(enum gkyl_wv_euler_rp rp_type, struct wv_euler *euler) { switch (rp_type) { - case WV_EULER_RP_ROE: - euler->eqn.num_waves = 3; - euler->eqn.waves_func = wave_roe_l; - euler->eqn.qfluct_func = qfluct_roe_l; - break; - - case WV_EULER_RP_HLLC: - euler->eqn.num_waves = 3; - euler->eqn.waves_func = wave_hllc_l; - euler->eqn.qfluct_func = qfluct_hllc_l; - break; - - case WV_EULER_RP_LAX: - euler->eqn.num_waves = 2; - euler->eqn.waves_func = wave_lax_l; - euler->eqn.qfluct_func = qfluct_lax_l; - break; - - case WV_EULER_RP_HLL: - euler->eqn.num_waves = 2; - euler->eqn.waves_func = wave_hll_l; - euler->eqn.qfluct_func = qfluct_hll_l; - break; + case WV_EULER_RP_ROE: + euler->eqn.num_waves = 3; + euler->eqn.waves_func = wave_roe_l; + euler->eqn.qfluct_func = qfluct_roe_l; + break; + + case WV_EULER_RP_HLLC: + euler->eqn.num_waves = 3; + euler->eqn.waves_func = wave_hllc_l; + euler->eqn.qfluct_func = qfluct_hllc_l; + break; + + case WV_EULER_RP_LAX: + euler->eqn.num_waves = 2; + euler->eqn.waves_func = wave_lax_l; + euler->eqn.qfluct_func = qfluct_lax_l; + break; + + case WV_EULER_RP_HLL: + euler->eqn.num_waves = 2; + euler->eqn.waves_func = wave_hll_l; + euler->eqn.qfluct_func = qfluct_hll_l; + break; } euler->eqn.flux_jump = flux_jump; @@ -57,15 +57,14 @@ wv_euler_set_cu_dev_ptrs(enum gkyl_wv_euler_rp rp_type, struct wv_euler *euler) euler->eqn.source_func = euler_source; } -struct gkyl_wv_eqn* -gkyl_wv_euler_cu_dev_inew(const struct gkyl_wv_euler_inp *inp) +struct gkyl_wv_eqn *gkyl_wv_euler_cu_dev_inew(const struct gkyl_wv_euler_inp *inp) { - struct wv_euler *euler = (struct wv_euler*) gkyl_malloc(sizeof(struct wv_euler)); + struct wv_euler *euler = (struct wv_euler *)gkyl_malloc(sizeof(struct wv_euler)); euler->eqn.type = GKYL_EQN_EULER; euler->eqn.num_equations = 5; euler->eqn.num_diag = 6; // KE and PE stored separate - + euler->gas_gamma = inp->gas_gamma; euler->eqn.flags = 0; @@ -73,10 +72,10 @@ gkyl_wv_euler_cu_dev_inew(const struct gkyl_wv_euler_inp *inp) euler->eqn.ref_count = gkyl_ref_count_init(gkyl_euler_free); // copy the host struct to device struct - struct wv_euler *euler_cu = (struct wv_euler*) gkyl_cu_malloc(sizeof(struct wv_euler)); + struct wv_euler *euler_cu = (struct wv_euler *)gkyl_cu_malloc(sizeof(struct wv_euler)); gkyl_cu_memcpy(euler_cu, euler, sizeof(struct wv_euler), GKYL_CU_MEMCPY_H2D); - wv_euler_set_cu_dev_ptrs<<<1,1>>>(inp->rp_type, euler_cu); + wv_euler_set_cu_dev_ptrs<<<1, 1> > >(inp->rp_type, euler_cu); euler->eqn.on_dev = &euler_cu->eqn; // CPU eqn obj points to itself return &euler->eqn; diff --git a/moments/zero/wv_euler_mixture.c b/moments/zero/wv_euler_mixture.c index a21f469881..51a3838021 100644 --- a/moments/zero/wv_euler_mixture.c +++ b/moments/zero/wv_euler_mixture.c @@ -6,8 +6,7 @@ #include #include -void -gkyl_euler_mixture_prim_vars(int num_species, double* gas_gamma_s, const double* q, double* v) +void gkyl_euler_mixture_prim_vars(int num_species, double *gas_gamma_s, const double *q, double *v) { double rho_total = q[0]; double momx_total = q[1]; @@ -44,7 +43,9 @@ gkyl_euler_mixture_prim_vars(int num_species, double* gas_gamma_s, const double* double *p_s = gkyl_malloc(sizeof(double[num_species])); for (int i = 0; i < num_species; i++) { - p_s[i] = (gas_gamma_s[i] - 1.0) * (E_total - (0.5 * rho_total * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total)))); + p_s[i] = (gas_gamma_s[i] - 1.0) * + (E_total - (0.5 * rho_total * + ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total)))); } double p_total = 0.0; @@ -72,7 +73,7 @@ gkyl_euler_mixture_prim_vars(int num_species, double* gas_gamma_s, const double* } static inline double -gkyl_euler_mixture_max_abs_speed(int num_species, double* gas_gamma_s, const double* q) +gkyl_euler_mixture_max_abs_speed(int num_species, double *gas_gamma_s, const double *q) { double *v = gkyl_malloc(sizeof(double[4 + (2 * num_species)])); gkyl_euler_mixture_prim_vars(num_species, gas_gamma_s, q, v); @@ -102,8 +103,7 @@ gkyl_euler_mixture_max_abs_speed(int num_species, double* gas_gamma_s, const dou return max_abs_speed; } -void -gkyl_euler_mixture_flux(int num_species, double* gas_gamma_s, const double* q, double* flux) +void gkyl_euler_mixture_flux(int num_species, double *gas_gamma_s, const double *q, double *flux) { double *v = gkyl_malloc(sizeof(double[4 + (2 * num_species)])); gkyl_euler_mixture_prim_vars(num_species, gas_gamma_s, q, v); @@ -133,7 +133,7 @@ gkyl_euler_mixture_flux(int num_species, double* gas_gamma_s, const double* q, d flux[2] = rho_total * (vx_total * vy_total); flux[3] = rho_total * (vx_total * vz_total); flux[4] = (E_total * vx_total) + (vx_total * p_total); - + for (int i = 0; i < num_species - 1; i++) { flux[5 + i] = rho_total * (vx_total * vol_frac_s[i]); } @@ -147,7 +147,7 @@ gkyl_euler_mixture_flux(int num_species, double* gas_gamma_s, const double* q, d } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -159,7 +159,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -170,8 +170,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -euler_mixture_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void euler_mixture_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -183,8 +185,10 @@ euler_mixture_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double ghost[1] = -ghost[1]; } -static void -euler_mixture_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void euler_mixture_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -192,16 +196,16 @@ euler_mixture_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const dou for (int i = 0; i < 4 + (2 * num_species); i++) { if (i > 0 && i < 4) { ghost[i] = -skin[i]; - } - else { + } else { ghost[i] = skin[i]; } } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -215,9 +219,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[3] = (qglobal[1] * tau2[0]) + (qglobal[2] * tau2[1]) + (qglobal[3] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -231,12 +236,14 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[3] = (qlocal[1] * norm[2]) + (qlocal[2] * tau1[2]) + (qlocal[3] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; - double* gas_gamma_s = euler_mixture->gas_gamma_s; + double *gas_gamma_s = euler_mixture->gas_gamma_s; double sl = gkyl_euler_mixture_max_abs_speed(num_species, gas_gamma_s, ql); double sr = gkyl_euler_mixture_max_abs_speed(num_species, gas_gamma_s, qr); @@ -262,8 +269,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -278,21 +287,27 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -338,7 +353,8 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double gamma1_over_a_sq = (gas_gamma_total - 1.0) / a_sq; double internal_enth = enth - vel_sq; - double a4 = gamma1_over_a_sq * ((internal_enth * delta[0]) + (vx * delta[1]) + (vy * delta[2]) + (vz * delta[3]) - delta[4]); + double a4 = gamma1_over_a_sq * ((internal_enth * delta[0]) + (vx * delta[1]) + (vy * delta[2]) + + (vz * delta[3]) - delta[4]); double a2 = delta[2] - (vy * delta[0]); double a3 = delta[3] - (vz * delta[0]); double a5 = 0.5 * (delta[1] + (((a - vx) * delta[0]) - (a * a4))) / a; @@ -353,7 +369,9 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double *a_rho2 = gkyl_malloc(sizeof(double[num_species])); double *a_rho3 = gkyl_malloc(sizeof(double[num_species])); for (int i = 0; i < num_species; i++) { - a_rho2[i] = gamma1_over_a_sq * -((internal_enth * delta[4 + num_species + i]) + (vx * delta[1]) + (vy * delta[2]) + (vz * delta[3]) - delta[4]); + a_rho2[i] = + gamma1_over_a_sq * -((internal_enth * delta[4 + num_species + i]) + (vx * delta[1]) + + (vy * delta[2]) + (vz * delta[3]) - delta[4]); a_rho3[i] = 0.5 * (delta[1] + (((a - vx) * delta[4 + num_species + i]) - (a * a_rho2[i]))) / a; a_rho1[i] = delta[4 + num_species + i] - a_rho2[i] - a_rho3[i]; } @@ -412,13 +430,16 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return fabs(vx) + a; } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; - - const double *w0 = &waves[0], *w1 = &waves[4 + (2 * num_species)], *w2 = &waves[8 + (4 * num_species)]; + + const double *w0 = &waves[0], *w1 = &waves[4 + (2 * num_species)], + *w2 = &waves[8 + (4 * num_species)]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]); @@ -428,33 +449,35 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -471,15 +494,14 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou double amaxl = gkyl_euler_mixture_max_abs_speed(num_species, gas_gamma_s, ql); double amaxr = gkyl_euler_mixture_max_abs_speed(num_species, gas_gamma_s, qr); - + gkyl_free(fr); gkyl_free(fl); return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -494,7 +516,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q) return false; } } - + double vol_frac_total = 0.0; for (int i = 0; i < num_species - 1; i++) { vol_frac_total += v[5 + i]; @@ -507,25 +529,23 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q) if (v[0] < 0.0 || v[4] < 0.0) { gkyl_free(v); return false; - } - else { + } else { gkyl_free(v); return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; - double* gas_gamma_s = euler_mixture->gas_gamma_s; + double *gas_gamma_s = euler_mixture->gas_gamma_s; return gkyl_euler_mixture_max_abs_speed(num_species, gas_gamma_s, q); } static inline void -euler_mixture_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +euler_mixture_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -536,7 +556,7 @@ euler_mixture_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, dou } static inline void -euler_mixture_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +euler_mixture_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -546,14 +566,14 @@ euler_mixture_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* s } } -void -gkyl_euler_mixture_free(const struct gkyl_ref_count* ref) +void gkyl_euler_mixture_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. - struct wv_euler_mixture *euler_mixture = container_of(base->on_dev, struct wv_euler_mixture, eqn); + struct wv_euler_mixture *euler_mixture = + container_of(base->on_dev, struct wv_euler_mixture, eqn); gkyl_cu_free(euler_mixture); } @@ -561,20 +581,16 @@ gkyl_euler_mixture_free(const struct gkyl_ref_count* ref) gkyl_free(euler_mixture); } -struct gkyl_wv_eqn* -gkyl_wv_euler_mixture_new(int num_species, double* gas_gamma_s, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_euler_mixture_new(int num_species, double *gas_gamma_s, bool use_gpu) { - return gkyl_wv_euler_mixture_inew(&(struct gkyl_wv_euler_mixture_inp) { - .num_species = num_species, - .gas_gamma_s = gas_gamma_s, - .rp_type = WV_EULER_MIXTURE_RP_LAX, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_euler_mixture_inew(&(struct gkyl_wv_euler_mixture_inp + ){.num_species = num_species, + .gas_gamma_s = gas_gamma_s, + .rp_type = WV_EULER_MIXTURE_RP_LAX, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_euler_mixture_inew(const struct gkyl_wv_euler_mixture_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_euler_mixture_inew(const struct gkyl_wv_euler_mixture_inp *inp) { struct wv_euler_mixture *euler_mixture = gkyl_malloc(sizeof(struct wv_euler_mixture)); @@ -589,8 +605,7 @@ gkyl_wv_euler_mixture_inew(const struct gkyl_wv_euler_mixture_inp* inp) euler_mixture->eqn.num_waves = 2; euler_mixture->eqn.waves_func = wave_lax_l; euler_mixture->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_EULER_MIXTURE_RP_ROE) { + } else if (inp->rp_type == WV_EULER_MIXTURE_RP_ROE) { euler_mixture->eqn.num_waves = 3; euler_mixture->eqn.waves_func = wave_roe_l; euler_mixture->eqn.qfluct_func = qfluct_roe_l; @@ -601,7 +616,7 @@ gkyl_wv_euler_mixture_inew(const struct gkyl_wv_euler_mixture_inp* inp) euler_mixture->eqn.max_speed_func = max_speed; euler_mixture->eqn.rotate_to_local_func = rot_to_local; euler_mixture->eqn.rotate_to_global_func = rot_to_global; - + euler_mixture->eqn.wall_bc_func = euler_mixture_wall; euler_mixture->eqn.no_slip_bc_func = euler_mixture_no_slip; @@ -615,15 +630,15 @@ gkyl_wv_euler_mixture_inew(const struct gkyl_wv_euler_mixture_inp* inp) euler_mixture->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(euler_mixture->eqn.flags); euler_mixture->eqn.ref_count = gkyl_ref_count_init(gkyl_euler_mixture_free); - euler_mixture->eqn.on_dev = &euler_mixture->eqn; // On the CPU, the equation object points ot itself. + euler_mixture->eqn.on_dev = + &euler_mixture->eqn; // On the CPU, the equation object points ot itself. euler_mixture->eqn.embed_geo = NULL; return &euler_mixture->eqn; } -int -gkyl_wv_euler_mixture_num_species(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_euler_mixture_num_species(const struct gkyl_wv_eqn *eqn) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); int num_species = euler_mixture->num_species; @@ -631,8 +646,7 @@ gkyl_wv_euler_mixture_num_species(const struct gkyl_wv_eqn* eqn) return num_species; } -double* -gkyl_wv_euler_mixture_gas_gamma_s(const struct gkyl_wv_eqn* eqn) +double *gkyl_wv_euler_mixture_gas_gamma_s(const struct gkyl_wv_eqn *eqn) { const struct wv_euler_mixture *euler_mixture = container_of(eqn, struct wv_euler_mixture, eqn); double *gas_gamma_s = euler_mixture->gas_gamma_s; diff --git a/moments/zero/wv_euler_rgfm.c b/moments/zero/wv_euler_rgfm.c index 1a34ad1eff..f585a8041a 100644 --- a/moments/zero/wv_euler_rgfm.c +++ b/moments/zero/wv_euler_rgfm.c @@ -6,8 +6,7 @@ #include #include -void -gkyl_euler_rgfm_prim_vars(int num_species, double* gas_gamma_s, const double* q, double* v) +void gkyl_euler_rgfm_prim_vars(int num_species, double *gas_gamma_s, const double *q, double *v) { double rho_total = q[0]; double momx_total = q[1]; @@ -45,7 +44,9 @@ gkyl_euler_rgfm_prim_vars(int num_species, double* gas_gamma_s, const double* q, double *p_s = gkyl_malloc(sizeof(double[num_species])); for (int i = 0; i < num_species; i++) { - p_s[i] = (gas_gamma_s[i] - 1.0) * (E_total - (0.5 * rho_total * ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total)))); + p_s[i] = (gas_gamma_s[i] - 1.0) * + (E_total - (0.5 * rho_total * + ((vx_total * vx_total) + (vy_total * vy_total) + (vz_total * vz_total)))); } double p_total = 0.0; @@ -74,7 +75,7 @@ gkyl_euler_rgfm_prim_vars(int num_species, double* gas_gamma_s, const double* q, } static inline double -gkyl_euler_rgfm_max_abs_speed(int num_species, double* gas_gamma_s, const double* q) +gkyl_euler_rgfm_max_abs_speed(int num_species, double *gas_gamma_s, const double *q) { double *v = gkyl_malloc(sizeof(double[5 + (2 * num_species)])); gkyl_euler_rgfm_prim_vars(num_species, gas_gamma_s, q, v); @@ -104,8 +105,7 @@ gkyl_euler_rgfm_max_abs_speed(int num_species, double* gas_gamma_s, const double return max_abs_speed; } -void -gkyl_euler_rgfm_flux(int num_species, double* gas_gamma_s, const double* q, double* flux) +void gkyl_euler_rgfm_flux(int num_species, double *gas_gamma_s, const double *q, double *flux) { double *v = gkyl_malloc(sizeof(double[5 + (2 * num_species)])); gkyl_euler_rgfm_prim_vars(num_species, gas_gamma_s, q, v); @@ -136,7 +136,7 @@ gkyl_euler_rgfm_flux(int num_species, double* gas_gamma_s, const double* q, doub flux[2] = rho_total * (vx_total * vy_total); flux[3] = rho_total * (vx_total * vz_total); flux[4] = (E_total * vx_total) + (vx_total * p_total); - + for (int i = 0; i < num_species - 1; i++) { flux[5 + i] = rho_total * (vx_total * level_set_s[i]); } @@ -152,7 +152,7 @@ gkyl_euler_rgfm_flux(int num_species, double* gas_gamma_s, const double* q, doub } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -164,7 +164,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -175,8 +175,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -euler_rgfm_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void euler_rgfm_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -188,8 +190,10 @@ euler_rgfm_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* s ghost[1] = -ghost[1]; } -static void -euler_rgfm_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void euler_rgfm_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -197,16 +201,16 @@ euler_rgfm_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double for (int i = 0; i < 5 + (2 * num_species); i++) { if (i > 0 && i < 4) { ghost[i] = -skin[i]; - } - else { + } else { ghost[i] = skin[i]; } } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -220,9 +224,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[3] = (qglobal[1] * tau2[0]) + (qglobal[2] * tau2[1]) + (qglobal[3] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -236,12 +241,14 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[3] = (qlocal[1] * norm[2]) + (qlocal[2] * tau1[2]) + (qlocal[3] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; - double* gas_gamma_s = euler_rgfm->gas_gamma_s; + double *gas_gamma_s = euler_rgfm->gas_gamma_s; int reinit_freq = euler_rgfm->reinit_freq; double sl = gkyl_euler_rgfm_max_abs_speed(num_species, gas_gamma_s, ql); @@ -268,8 +275,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -284,21 +293,25 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -316,15 +329,14 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou double amaxl = gkyl_euler_rgfm_max_abs_speed(num_species, gas_gamma_s, ql); double amaxr = gkyl_euler_rgfm_max_abs_speed(num_species, gas_gamma_s, qr); - + gkyl_free(fr); gkyl_free(fl); return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -339,7 +351,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q) return false; } } - + double level_set_total = 0.0; for (int i = 0; i < num_species - 1; i++) { level_set_total += v[5 + i]; @@ -352,25 +364,23 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q) if (v[0] < 0.0 || v[4] < 0.0) { gkyl_free(v); return false; - } - else { + } else { gkyl_free(v); return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; - double* gas_gamma_s = euler_rgfm->gas_gamma_s; + double *gas_gamma_s = euler_rgfm->gas_gamma_s; return gkyl_euler_rgfm_max_abs_speed(num_species, gas_gamma_s, q); } static inline void -euler_rgfm_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +euler_rgfm_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -380,8 +390,7 @@ euler_rgfm_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double } } -static inline void -euler_rgfm_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void euler_rgfm_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -391,10 +400,9 @@ euler_rgfm_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout } } -void -gkyl_euler_rgfm_free(const struct gkyl_ref_count* ref) +void gkyl_euler_rgfm_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. @@ -406,21 +414,18 @@ gkyl_euler_rgfm_free(const struct gkyl_ref_count* ref) gkyl_free(euler_rgfm); } -struct gkyl_wv_eqn* -gkyl_wv_euler_rgfm_new(int num_species, double* gas_gamma_s, int reinit_freq, bool use_gpu) +struct gkyl_wv_eqn * +gkyl_wv_euler_rgfm_new(int num_species, double *gas_gamma_s, int reinit_freq, bool use_gpu) { - return gkyl_wv_euler_rgfm_inew(&(struct gkyl_wv_euler_rgfm_inp) { - .num_species = num_species, - .gas_gamma_s = gas_gamma_s, - .reinit_freq = reinit_freq, - .rp_type = WV_EULER_RGFM_RP_LAX, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_euler_rgfm_inew(&(struct gkyl_wv_euler_rgfm_inp + ){.num_species = num_species, + .gas_gamma_s = gas_gamma_s, + .reinit_freq = reinit_freq, + .rp_type = WV_EULER_RGFM_RP_LAX, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_euler_rgfm_inew(const struct gkyl_wv_euler_rgfm_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_euler_rgfm_inew(const struct gkyl_wv_euler_rgfm_inp *inp) { struct wv_euler_rgfm *euler_rgfm = gkyl_malloc(sizeof(struct wv_euler_rgfm)); @@ -443,7 +448,7 @@ gkyl_wv_euler_rgfm_inew(const struct gkyl_wv_euler_rgfm_inp* inp) euler_rgfm->eqn.max_speed_func = max_speed; euler_rgfm->eqn.rotate_to_local_func = rot_to_local; euler_rgfm->eqn.rotate_to_global_func = rot_to_global; - + euler_rgfm->eqn.wall_bc_func = euler_rgfm_wall; euler_rgfm->eqn.no_slip_bc_func = euler_rgfm_no_slip; @@ -464,8 +469,7 @@ gkyl_wv_euler_rgfm_inew(const struct gkyl_wv_euler_rgfm_inp* inp) return &euler_rgfm->eqn; } -int -gkyl_wv_euler_rgfm_num_species(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_euler_rgfm_num_species(const struct gkyl_wv_eqn *eqn) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int num_species = euler_rgfm->num_species; @@ -473,8 +477,7 @@ gkyl_wv_euler_rgfm_num_species(const struct gkyl_wv_eqn* eqn) return num_species; } -double* -gkyl_wv_euler_rgfm_gas_gamma_s(const struct gkyl_wv_eqn* eqn) +double *gkyl_wv_euler_rgfm_gas_gamma_s(const struct gkyl_wv_eqn *eqn) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); double *gas_gamma_s = euler_rgfm->gas_gamma_s; @@ -482,8 +485,7 @@ gkyl_wv_euler_rgfm_gas_gamma_s(const struct gkyl_wv_eqn* eqn) return gas_gamma_s; } -int -gkyl_wv_euler_rgfm_reinit_freq(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_euler_rgfm_reinit_freq(const struct gkyl_wv_eqn *eqn) { const struct wv_euler_rgfm *euler_rgfm = container_of(eqn, struct wv_euler_rgfm, eqn); int reinit_freq = euler_rgfm->reinit_freq; diff --git a/moments/zero/wv_gr_euler.c b/moments/zero/wv_gr_euler.c index 4eb4190ec9..9fd66662c8 100644 --- a/moments/zero/wv_gr_euler.c +++ b/moments/zero/wv_gr_euler.c @@ -6,12 +6,11 @@ #include #include -void -gkyl_gr_euler_flux(double gas_gamma, const double q[71], double flux[71]) +void gkyl_gr_euler_flux(double gas_gamma, const double q[71], double flux[71]) { - double v[71] = { 0.0 }; + double v[71] = {0.0}; gkyl_gr_euler_prim_vars(gas_gamma, q, v); - double rho = v[0]; + double rho = v[0]; double vx = v[1]; double vy = v[2]; double vz = v[3]; @@ -21,23 +20,34 @@ gkyl_gr_euler_flux(double gas_gamma, const double q[71], double flux[71]) double shift_x = v[6]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[9]; spatial_metric[0][1] = v[10]; spatial_metric[0][2] = v[11]; - spatial_metric[1][0] = v[12]; spatial_metric[1][1] = v[13]; spatial_metric[1][2] = v[14]; - spatial_metric[2][0] = v[15]; spatial_metric[2][1] = v[16]; spatial_metric[2][2] = v[17]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = v[9]; + spatial_metric[0][1] = v[10]; + spatial_metric[0][2] = v[11]; + spatial_metric[1][0] = v[12]; + spatial_metric[1][1] = v[13]; + spatial_metric[1][2] = v[14]; + spatial_metric[2][0] = v[15]; + spatial_metric[2][1] = v[16]; + spatial_metric[2][2] = v[17]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + bool in_excision_region = false; if (v[27] < pow(10.0, -8.0)) { in_excision_region = true; } - + if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -53,24 +63,24 @@ gkyl_gr_euler_flux(double gas_gamma, const double q[71], double flux[71]) double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); flux[0] = (lapse * sqrt(spatial_det)) * (rho * W * (vx - (shift_x / lapse))); - flux[1] = (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vx * (vx - (shift_x / lapse))) + p); + flux[1] = + (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vx * (vx - (shift_x / lapse))) + p); flux[2] = (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vy * (vx - (shift_x / lapse)))); flux[3] = (lapse * sqrt(spatial_det)) * (rho * h * (W * W) * (vz * (vx - (shift_x / lapse)))); - flux[4] = (lapse * sqrt(spatial_det)) * (((rho * h * (W * W)) - p - (rho * W)) * (vx - (shift_x / lapse)) + (p * vx)); + flux[4] = (lapse * sqrt(spatial_det)) * + (((rho * h * (W * W)) - p - (rho * W)) * (vx - (shift_x / lapse)) + (p * vx)); for (int i = 5; i < 71; i++) { flux[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 71; i++) { flux[i] = 0.0; } } } -void -gkyl_gr_euler_prim_vars(double gas_gamma, const double q[71], double v[71]) +void gkyl_gr_euler_prim_vars(double gas_gamma, const double q[71], double v[71]) { double lapse = q[5]; double shift_x = q[6]; @@ -78,14 +88,26 @@ gkyl_gr_euler_prim_vars(double gas_gamma, const double q[71], double v[71]) double shift_z = q[8]; double spatial_metric[3][3]; - spatial_metric[0][0] = q[9]; spatial_metric[0][1] = q[10]; spatial_metric[0][2] = q[11]; - spatial_metric[1][0] = q[12]; spatial_metric[1][1] = q[13]; spatial_metric[1][2] = q[14]; - spatial_metric[2][0] = q[15]; spatial_metric[2][1] = q[16]; spatial_metric[2][2] = q[17]; - + spatial_metric[0][0] = q[9]; + spatial_metric[0][1] = q[10]; + spatial_metric[0][2] = q[11]; + spatial_metric[1][0] = q[12]; + spatial_metric[1][1] = q[13]; + spatial_metric[1][2] = q[14]; + spatial_metric[2][0] = q[15]; + spatial_metric[2][1] = q[16]; + spatial_metric[2][2] = q[17]; + double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = q[18]; extrinsic_curvature[0][1] = q[19]; extrinsic_curvature[0][2] = q[20]; - extrinsic_curvature[1][0] = q[21]; extrinsic_curvature[1][1] = q[22]; extrinsic_curvature[1][2] = q[23]; - extrinsic_curvature[2][0] = q[24]; extrinsic_curvature[2][1] = q[25]; extrinsic_curvature[2][2] = q[26]; + extrinsic_curvature[0][0] = q[18]; + extrinsic_curvature[0][1] = q[19]; + extrinsic_curvature[0][2] = q[20]; + extrinsic_curvature[1][0] = q[21]; + extrinsic_curvature[1][1] = q[22]; + extrinsic_curvature[1][2] = q[23]; + extrinsic_curvature[2][0] = q[24]; + extrinsic_curvature[2][1] = q[25]; + extrinsic_curvature[2][2] = q[26]; double lapse_der[3]; lapse_der[0] = q[28]; @@ -93,22 +115,46 @@ gkyl_gr_euler_prim_vars(double gas_gamma, const double q[71], double v[71]) lapse_der[2] = q[30]; double shift_der[3][3]; - shift_der[0][0] = q[31]; shift_der[0][1] = q[32]; shift_der[0][2] = q[33]; - shift_der[1][0] = q[34]; shift_der[1][1] = q[35]; shift_der[1][2] = q[36]; - shift_der[2][0] = q[37]; shift_der[2][1] = q[38]; shift_der[2][2] = q[39]; + shift_der[0][0] = q[31]; + shift_der[0][1] = q[32]; + shift_der[0][2] = q[33]; + shift_der[1][0] = q[34]; + shift_der[1][1] = q[35]; + shift_der[1][2] = q[36]; + shift_der[2][0] = q[37]; + shift_der[2][1] = q[38]; + shift_der[2][2] = q[39]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = q[40]; spatial_metric_der[0][0][1] = q[41]; spatial_metric_der[0][0][2] = q[42]; - spatial_metric_der[0][1][0] = q[43]; spatial_metric_der[0][1][1] = q[44]; spatial_metric_der[0][1][2] = q[45]; - spatial_metric_der[0][2][0] = q[46]; spatial_metric_der[0][2][1] = q[47]; spatial_metric_der[0][2][2] = q[48]; - - spatial_metric_der[1][0][0] = q[49]; spatial_metric_der[1][0][1] = q[50]; spatial_metric_der[1][0][2] = q[51]; - spatial_metric_der[1][1][0] = q[52]; spatial_metric_der[1][1][1] = q[53]; spatial_metric_der[1][1][2] = q[54]; - spatial_metric_der[1][2][0] = q[55]; spatial_metric_der[1][2][1] = q[56]; spatial_metric_der[1][2][2] = q[57]; - - spatial_metric_der[0][0][0] = q[58]; spatial_metric_der[0][0][1] = q[59]; spatial_metric_der[0][0][2] = q[60]; - spatial_metric_der[0][1][0] = q[61]; spatial_metric_der[0][1][1] = q[62]; spatial_metric_der[0][1][2] = q[63]; - spatial_metric_der[0][2][0] = q[64]; spatial_metric_der[0][2][1] = q[65]; spatial_metric_der[0][2][2] = q[66]; + spatial_metric_der[0][0][0] = q[40]; + spatial_metric_der[0][0][1] = q[41]; + spatial_metric_der[0][0][2] = q[42]; + spatial_metric_der[0][1][0] = q[43]; + spatial_metric_der[0][1][1] = q[44]; + spatial_metric_der[0][1][2] = q[45]; + spatial_metric_der[0][2][0] = q[46]; + spatial_metric_der[0][2][1] = q[47]; + spatial_metric_der[0][2][2] = q[48]; + + spatial_metric_der[1][0][0] = q[49]; + spatial_metric_der[1][0][1] = q[50]; + spatial_metric_der[1][0][2] = q[51]; + spatial_metric_der[1][1][0] = q[52]; + spatial_metric_der[1][1][1] = q[53]; + spatial_metric_der[1][1][2] = q[54]; + spatial_metric_der[1][2][0] = q[55]; + spatial_metric_der[1][2][1] = q[56]; + spatial_metric_der[1][2][2] = q[57]; + + spatial_metric_der[0][0][0] = q[58]; + spatial_metric_der[0][0][1] = q[59]; + spatial_metric_der[0][0][2] = q[60]; + spatial_metric_der[0][1][0] = q[61]; + spatial_metric_der[0][1][1] = q[62]; + spatial_metric_der[0][1][2] = q[63]; + spatial_metric_der[0][2][0] = q[64]; + spatial_metric_der[0][2][1] = q[65]; + spatial_metric_der[0][2][2] = q[66]; double evol_param = q[67]; double x = q[68]; @@ -121,9 +167,12 @@ gkyl_gr_euler_prim_vars(double gas_gamma, const double q[71], double v[71]) } if (!in_excision_region) { - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double D = q[0] / sqrt(spatial_det); double momx = q[1] / sqrt(spatial_det); @@ -131,41 +180,50 @@ gkyl_gr_euler_prim_vars(double gas_gamma, const double q[71], double v[71]) double momz = q[3] / sqrt(spatial_det); double Etot = q[4] / sqrt(spatial_det); - double C = D / sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); - double C0 = (D + Etot) / sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); - if (((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz)) < pow(10.0, -8.0)) { + double C = + D / sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); + double C0 = (D + Etot) / + sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); + if (((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz)) < + pow(10.0, -8.0)) { C = D / sqrt(pow(10.0, -8.0)); C0 = (D + Etot) / sqrt(pow(10.0, -8.0)); } double alpha0 = -1.0 / (gas_gamma * gas_gamma); double alpha1 = -2.0 * C * ((gas_gamma - 1.0) / (gas_gamma * gas_gamma)); - double alpha2 = ((gas_gamma - 2.0) / gas_gamma) * ((C0 * C0) - 1.0) + 1.0 - (C * C) * ((gas_gamma - 1.0) / gas_gamma) * ((gas_gamma - 1.0) / gas_gamma); + double alpha2 = ((gas_gamma - 2.0) / gas_gamma) * ((C0 * C0) - 1.0) + 1.0 - + (C * C) * ((gas_gamma - 1.0) / gas_gamma) * ((gas_gamma - 1.0) / gas_gamma); double alpha4 = (C0 * C0) - 1.0; - double eta = 2.0 * C *((gas_gamma - 1.0) / gas_gamma); + double eta = 2.0 * C * ((gas_gamma - 1.0) / gas_gamma); double guess = 1.0; int iter = 0; while (iter < 100) { - double poly = (alpha4 * (guess * guess * guess) * (guess - eta)) + (alpha2 * (guess * guess)) + (alpha1 * guess) + alpha0; - double poly_der = alpha1 + (2.0 * alpha2 * guess) + (4.0 * alpha4 * (guess * guess * guess)) - (3.0 * eta * alpha4 * (guess * guess)); + double poly = (alpha4 * (guess * guess * guess) * (guess - eta)) + + (alpha2 * (guess * guess)) + (alpha1 * guess) + alpha0; + double poly_der = alpha1 + (2.0 * alpha2 * guess) + (4.0 * alpha4 * (guess * guess * guess)) - + (3.0 * eta * alpha4 * (guess * guess)); double guess_new = guess - (poly / poly_der); if (fabs(guess - guess_new) < pow(10.0, -8.0)) { iter = 100; - } - else { + } else { iter += 1; guess = guess_new; } } - double W = 0.5 * C0 * guess * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma - 1.0) / gas_gamma) * ((1.0 - (C * guess)) / ((C0 * C0) * (guess * guess)))))); + double W = 0.5 * C0 * guess * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma - 1.0) / gas_gamma) * + ((1.0 - (C * guess)) / ((C0 * C0) * (guess * guess)))) + )); double h = 1.0 / (C * guess); - v[0] = D / W; + v[0] = D / W; v[1] = momx / (v[0] * h * (W * W)); v[2] = momy / (v[0] * h * (W * W)); v[3] = momz / (v[0] * h * (W * W)); @@ -183,13 +241,25 @@ gkyl_gr_euler_prim_vars(double gas_gamma, const double q[71], double v[71]) v[7] = shift_y; v[8] = shift_z; - v[9] = spatial_metric[0][0]; v[10] = spatial_metric[0][1]; v[11] = spatial_metric[0][2]; - v[12] = spatial_metric[1][0]; v[13] = spatial_metric[1][1]; v[14] = spatial_metric[1][2]; - v[15] = spatial_metric[2][0]; v[16] = spatial_metric[2][1]; v[17] = spatial_metric[2][2]; - - v[18] = extrinsic_curvature[0][0]; v[19] = extrinsic_curvature[0][1]; v[20] = extrinsic_curvature[0][2]; - v[21] = extrinsic_curvature[1][0]; v[22] = extrinsic_curvature[1][1]; v[23] = extrinsic_curvature[1][2]; - v[24] = extrinsic_curvature[2][0]; v[25] = extrinsic_curvature[2][1]; v[26] = extrinsic_curvature[2][2]; + v[9] = spatial_metric[0][0]; + v[10] = spatial_metric[0][1]; + v[11] = spatial_metric[0][2]; + v[12] = spatial_metric[1][0]; + v[13] = spatial_metric[1][1]; + v[14] = spatial_metric[1][2]; + v[15] = spatial_metric[2][0]; + v[16] = spatial_metric[2][1]; + v[17] = spatial_metric[2][2]; + + v[18] = extrinsic_curvature[0][0]; + v[19] = extrinsic_curvature[0][1]; + v[20] = extrinsic_curvature[0][2]; + v[21] = extrinsic_curvature[1][0]; + v[22] = extrinsic_curvature[1][1]; + v[23] = extrinsic_curvature[1][2]; + v[24] = extrinsic_curvature[2][0]; + v[25] = extrinsic_curvature[2][1]; + v[26] = extrinsic_curvature[2][2]; v[27] = 1.0; @@ -197,48 +267,79 @@ gkyl_gr_euler_prim_vars(double gas_gamma, const double q[71], double v[71]) v[29] = lapse_der[1]; v[30] = lapse_der[2]; - v[31] = shift_der[0][0]; v[32] = shift_der[0][1]; v[33] = shift_der[0][2]; - v[34] = shift_der[1][0]; v[35] = shift_der[1][1]; v[36] = shift_der[1][2]; - v[37] = shift_der[2][0]; v[38] = shift_der[2][1]; v[39] = shift_der[2][2]; - - v[40] = spatial_metric_der[0][0][0]; v[41] = spatial_metric_der[0][0][1]; v[42] = spatial_metric_der[0][0][2]; - v[43] = spatial_metric_der[0][1][0]; v[44] = spatial_metric_der[0][1][1]; v[45] = spatial_metric_der[0][1][2]; - v[46] = spatial_metric_der[0][2][0]; v[47] = spatial_metric_der[0][2][1]; v[48] = spatial_metric_der[0][2][2]; - - v[49] = spatial_metric_der[1][0][0]; v[50] = spatial_metric_der[1][0][1]; v[51] = spatial_metric_der[1][0][2]; - v[52] = spatial_metric_der[1][1][0]; v[53] = spatial_metric_der[1][1][1]; v[54] = spatial_metric_der[1][1][2]; - v[55] = spatial_metric_der[1][2][0]; v[56] = spatial_metric_der[1][2][1]; v[57] = spatial_metric_der[1][2][2]; - - v[58] = spatial_metric_der[2][0][0]; v[59] = spatial_metric_der[2][0][1]; v[60] = spatial_metric_der[2][0][2]; - v[61] = spatial_metric_der[2][1][0]; v[62] = spatial_metric_der[2][1][1]; v[63] = spatial_metric_der[2][1][2]; - v[64] = spatial_metric_der[2][2][0]; v[65] = spatial_metric_der[2][2][1]; v[66] = spatial_metric_der[2][2][2]; + v[31] = shift_der[0][0]; + v[32] = shift_der[0][1]; + v[33] = shift_der[0][2]; + v[34] = shift_der[1][0]; + v[35] = shift_der[1][1]; + v[36] = shift_der[1][2]; + v[37] = shift_der[2][0]; + v[38] = shift_der[2][1]; + v[39] = shift_der[2][2]; + + v[40] = spatial_metric_der[0][0][0]; + v[41] = spatial_metric_der[0][0][1]; + v[42] = spatial_metric_der[0][0][2]; + v[43] = spatial_metric_der[0][1][0]; + v[44] = spatial_metric_der[0][1][1]; + v[45] = spatial_metric_der[0][1][2]; + v[46] = spatial_metric_der[0][2][0]; + v[47] = spatial_metric_der[0][2][1]; + v[48] = spatial_metric_der[0][2][2]; + + v[49] = spatial_metric_der[1][0][0]; + v[50] = spatial_metric_der[1][0][1]; + v[51] = spatial_metric_der[1][0][2]; + v[52] = spatial_metric_der[1][1][0]; + v[53] = spatial_metric_der[1][1][1]; + v[54] = spatial_metric_der[1][1][2]; + v[55] = spatial_metric_der[1][2][0]; + v[56] = spatial_metric_der[1][2][1]; + v[57] = spatial_metric_der[1][2][2]; + + v[58] = spatial_metric_der[2][0][0]; + v[59] = spatial_metric_der[2][0][1]; + v[60] = spatial_metric_der[2][0][2]; + v[61] = spatial_metric_der[2][1][0]; + v[62] = spatial_metric_der[2][1][1]; + v[63] = spatial_metric_der[2][1][2]; + v[64] = spatial_metric_der[2][2][0]; + v[65] = spatial_metric_der[2][2][1]; + v[66] = spatial_metric_der[2][2][2]; v[67] = evol_param; v[68] = x; v[69] = y; v[70] = z; - } - else { + } else { for (int i = 0; i < 71; i++) { v[i] = 0.0; } - + v[27] = -1.0; } } -void -gkyl_gr_euler_inv_spatial_metric(const double q[71], double ***inv_spatial_metric) +void gkyl_gr_euler_inv_spatial_metric(const double q[71], double ***inv_spatial_metric) { double spatial_metric[3][3]; - spatial_metric[0][0] = q[9]; spatial_metric[0][1] = q[10]; spatial_metric[0][2] = q[11]; - spatial_metric[1][0] = q[12]; spatial_metric[1][1] = q[13]; spatial_metric[1][2] = q[14]; - spatial_metric[2][0] = q[15]; spatial_metric[2][1] = q[16]; spatial_metric[2][2] = q[17]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = q[9]; + spatial_metric[0][1] = q[10]; + spatial_metric[0][2] = q[11]; + spatial_metric[1][0] = q[12]; + spatial_metric[1][1] = q[13]; + spatial_metric[1][2] = q[14]; + spatial_metric[2][0] = q[15]; + spatial_metric[2][1] = q[16]; + spatial_metric[2][2] = q[17]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -269,8 +370,7 @@ gkyl_gr_euler_inv_spatial_metric(const double q[71], double ***inv_spatial_metri for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -278,16 +378,18 @@ gkyl_gr_euler_inv_spatial_metric(const double q[71], double ***inv_spatial_metri for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*inv_spatial_metric)[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*inv_spatial_metric)[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } } -void -gkyl_gr_euler_stress_energy_tensor(double gas_gamma, const double q[71], double ***stress_energy) +void gkyl_gr_euler_stress_energy_tensor( + double gas_gamma, const double q[71], double ***stress_energy +) { - double v[71] = { 0.0 }; + double v[71] = {0.0}; gkyl_gr_euler_prim_vars(gas_gamma, q, v); double rho = v[0]; double vx = v[1]; @@ -301,11 +403,17 @@ gkyl_gr_euler_stress_energy_tensor(double gas_gamma, const double q[71], double double shift_z = v[8]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[9]; spatial_metric[0][1] = v[10]; spatial_metric[0][2] = v[11]; - spatial_metric[1][0] = v[12]; spatial_metric[1][1] = v[13]; spatial_metric[1][2] = v[14]; - spatial_metric[2][0] = v[15]; spatial_metric[2][1] = v[16]; spatial_metric[2][2] = v[17]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[9]; + spatial_metric[0][1] = v[10]; + spatial_metric[0][2] = v[11]; + spatial_metric[1][0] = v[12]; + spatial_metric[1][1] = v[13]; + spatial_metric[1][2] = v[14]; + spatial_metric[2][0] = v[15]; + spatial_metric[2][1] = v[16]; + spatial_metric[2][2] = v[17]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -320,7 +428,9 @@ gkyl_gr_euler_stress_energy_tensor(double gas_gamma, const double q[71], double if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -342,27 +452,30 @@ gkyl_gr_euler_stress_energy_tensor(double gas_gamma, const double q[71], double spacetime_vel[3] = (W * vz) - (shift_z * (W / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*stress_energy)[i][j] = (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); + (*stress_energy)[i][j] = + (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); } } - } - else { + } else { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { (*stress_energy)[i][j] = 0.0; @@ -376,12 +489,11 @@ gkyl_gr_euler_stress_energy_tensor(double gas_gamma, const double q[71], double gkyl_free(inv_spatial_metric); } -static inline double -gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]) +static inline double gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]) { - double v[71] = { 0.0 }; + double v[71] = {0.0}; gkyl_gr_euler_prim_vars(gas_gamma, q, v); - double rho = v[0]; + double rho = v[0]; double vx = v[1]; double vy = v[2]; double vz = v[3]; @@ -393,11 +505,17 @@ gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]) double shift_z = v[8]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[9]; spatial_metric[0][1] = v[10]; spatial_metric[0][2] = v[11]; - spatial_metric[1][0] = v[12]; spatial_metric[1][1] = v[13]; spatial_metric[1][2] = v[14]; - spatial_metric[2][0] = v[15]; spatial_metric[2][1] = v[16]; spatial_metric[2][2] = v[17]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[9]; + spatial_metric[0][1] = v[10]; + spatial_metric[0][2] = v[11]; + spatial_metric[1][0] = v[12]; + spatial_metric[1][1] = v[13]; + spatial_metric[1][2] = v[14]; + spatial_metric[2][0] = v[15]; + spatial_metric[2][1] = v[16]; + spatial_metric[2][2] = v[17]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -420,16 +538,15 @@ gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]) if (fabs(spatial_metric[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime = true; } - } - else { + } else { if (fabs(spatial_metric[i][j]) > pow(10.0, -8.0)) { curved_spacetime = true; } } } } - if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || fabs(shift_y) > pow(10.0, -8.0) || - fabs(shift_z) > pow(10.0, -8.0)) { + if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || + fabs(shift_y) > pow(10.0, -8.0) || fabs(shift_z) > pow(10.0, -8.0)) { curved_spacetime = true; } @@ -437,7 +554,9 @@ gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]) if (curved_spacetime) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -446,7 +565,9 @@ gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]) } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double material_eigs[3]; double fast_acoustic_eigs[3]; @@ -455,11 +576,23 @@ gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]) for (int i = 0; i < 3; i++) { material_eigs[i] = (lapse * vel[i]) - shift[i]; - fast_acoustic_eigs[i] = (lapse / (1.0 - (v_sq * (c_s * c_s)))) * ((vel[i] * (1.0 - (c_s * c_s))) + - (c_s * sqrt((1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - (vel[i] * vel[i]) * (1.0 - (c_s * c_s)))))) - shift[i]; - - slow_acoustic_eigs[i] = (lapse / (1.0 - (v_sq * (c_s * c_s)))) * ((vel[i] * (1.0 - (c_s * c_s))) - - (c_s * sqrt((1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - (vel[i] * vel[i]) * (1.0 - (c_s * c_s)))))) - shift[i]; + fast_acoustic_eigs[i] = + (lapse / (1.0 - (v_sq * (c_s * c_s)))) * + ((vel[i] * (1.0 - (c_s * c_s))) + + (c_s * sqrt( + (1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - + (vel[i] * vel[i]) * (1.0 - (c_s * c_s))) + ))) - + shift[i]; + + slow_acoustic_eigs[i] = + (lapse / (1.0 - (v_sq * (c_s * c_s)))) * + ((vel[i] * (1.0 - (c_s * c_s))) - + (c_s * sqrt( + (1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - + (vel[i] * vel[i]) * (1.0 - (c_s * c_s))) + ))) - + shift[i]; } double max_eig = 0.0; @@ -481,8 +614,7 @@ gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]) gkyl_free(inv_spatial_metric); return fabs(v_sq) + max_eig; - } - else { + } else { double v_sq = sqrt((vx * vx) + (vy * vy) + (vz * vz)); for (int i = 0; i < 3; i++) { @@ -492,8 +624,7 @@ gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]) return fabs(v_sq) + c_s; } - } - else { + } else { for (int i = 0; i < 3; i++) { gkyl_free(inv_spatial_metric[i]); } @@ -504,7 +635,7 @@ gkyl_gr_euler_max_abs_speed(double gas_gamma, const double q[71]) } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 71; i++) { @@ -513,7 +644,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 71; i++) { @@ -521,8 +652,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -gr_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_euler_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 0; i < 71; i++) { ghost[i] = skin[i]; @@ -531,8 +664,10 @@ gr_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* ski ghost[1] = -ghost[1]; } -static void -gr_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_euler_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 1; i < 4; i++) { ghost[i] = -skin[i]; @@ -546,9 +681,10 @@ gr_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; qlocal[1] = (qglobal[1] * norm[0]) + (qglobal[2] * norm[1]) + (qglobal[3] * norm[2]); @@ -590,9 +726,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinate frame. - qlocal[9] = v1[0]; qlocal[10] = v1[1]; qlocal[11] = v1[2]; - qlocal[12] = v2[0]; qlocal[13] = v2[1]; qlocal[14] = v2[2]; - qlocal[15] = v3[0]; qlocal[16] = v3[1]; qlocal[17] = v3[2]; + qlocal[9] = v1[0]; + qlocal[10] = v1[1]; + qlocal[11] = v1[2]; + qlocal[12] = v2[0]; + qlocal[13] = v2[1]; + qlocal[14] = v2[2]; + qlocal[15] = v3[0]; + qlocal[16] = v3[1]; + qlocal[17] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -623,9 +765,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta inv_v3[2] = (extr_r1[2] * tau2[0]) + (extr_r2[2] * tau2[1]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor to local coordinate frame. - qlocal[18] = inv_v1[0]; qlocal[19] = inv_v1[1]; qlocal[20] = inv_v1[2]; - qlocal[21] = inv_v2[0]; qlocal[22] = inv_v2[1]; qlocal[23] = inv_v2[2]; - qlocal[24] = inv_v3[0]; qlocal[25] = inv_v3[1]; qlocal[26] = inv_v3[2]; + qlocal[18] = inv_v1[0]; + qlocal[19] = inv_v1[1]; + qlocal[20] = inv_v1[2]; + qlocal[21] = inv_v2[0]; + qlocal[22] = inv_v2[1]; + qlocal[23] = inv_v2[2]; + qlocal[24] = inv_v3[0]; + qlocal[25] = inv_v3[1]; + qlocal[26] = inv_v3[2]; qlocal[27] = qglobal[27]; @@ -649,22 +797,37 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); - shiftder_v1[1] = (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); - shiftder_v1[2] = (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); - shiftder_v2[1] = (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); - shiftder_v2[2] = (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); - shiftder_v3[1] = (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); - shiftder_v3[2] = (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); + shiftder_v1[1] = + (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); + shiftder_v1[2] = + (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); + shiftder_v2[1] = + (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); + shiftder_v2[2] = + (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); + shiftder_v3[1] = + (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); + shiftder_v3[2] = + (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative to local coordinate frame. - qlocal[31] = shiftder_v1[0]; qlocal[32] = shiftder_v1[1]; qlocal[33] = shiftder_v1[2]; - qlocal[34] = shiftder_v2[0]; qlocal[35] = shiftder_v2[1]; qlocal[36] = shiftder_v2[2]; - qlocal[37] = shiftder_v3[0]; qlocal[38] = shiftder_v3[1]; qlocal[39] = shiftder_v3[2]; + qlocal[31] = shiftder_v1[0]; + qlocal[32] = shiftder_v1[1]; + qlocal[33] = shiftder_v1[2]; + qlocal[34] = shiftder_v2[0]; + qlocal[35] = shiftder_v2[1]; + qlocal[36] = shiftder_v2[2]; + qlocal[37] = shiftder_v3[0]; + qlocal[38] = shiftder_v3[1]; + qlocal[39] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -747,7 +910,7 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta s33[0] = (r31[0] * tau2[0]) + (r32[0] * tau2[1]) + (r33[0] * tau2[2]); s33[1] = (r31[1] * tau2[0]) + (r32[1] * tau2[1]) + (r33[1] * tau2[2]); s33[2] = (r31[2] * tau2[0]) + (r32[2] * tau2[1]) + (r33[2] * tau2[2]); - + // Rotate spatial metric tensor derivative to local coordinate frame. qlocal[40] = (s11[0] * norm[0]) + (s21[0] * norm[1]) + (s31[0] * norm[2]); qlocal[41] = (s11[1] * norm[0]) + (s21[1] * norm[1]) + (s31[1] * norm[2]); @@ -791,9 +954,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[70] = (qglobal[68] * tau2[0]) + (qglobal[69] * tau2[1]) + (qglobal[70] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; qglobal[1] = (qlocal[1] * norm[0]) + (qlocal[2] * tau1[0]) + (qlocal[3] * tau2[0]); @@ -835,9 +999,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor back to global coordinate frame. - qglobal[9] = v1[0]; qglobal[10] = v1[1]; qglobal[11] = v1[2]; - qglobal[12] = v2[0]; qglobal[13] = v2[1]; qglobal[14] = v2[2]; - qglobal[15] = v3[0]; qglobal[16] = v3[1]; qglobal[17] = v3[2]; + qglobal[9] = v1[0]; + qglobal[10] = v1[1]; + qglobal[11] = v1[2]; + qglobal[12] = v2[0]; + qglobal[13] = v2[1]; + qglobal[14] = v2[2]; + qglobal[15] = v3[0]; + qglobal[16] = v3[1]; + qglobal[17] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -868,9 +1038,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t inv_v3[2] = (extr_r1[2] * norm[2]) + (extr_r2[2] * tau1[2]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor back to global coordinate frame. - qglobal[18] = inv_v1[0]; qglobal[19] = inv_v1[1]; qglobal[20] = inv_v1[2]; - qglobal[21] = inv_v2[0]; qglobal[22] = inv_v2[1]; qglobal[23] = inv_v2[2]; - qglobal[24] = inv_v3[0]; qglobal[25] = inv_v3[1]; qglobal[26] = inv_v3[2]; + qglobal[18] = inv_v1[0]; + qglobal[19] = inv_v1[1]; + qglobal[20] = inv_v1[2]; + qglobal[21] = inv_v2[0]; + qglobal[22] = inv_v2[1]; + qglobal[23] = inv_v2[2]; + qglobal[24] = inv_v3[0]; + qglobal[25] = inv_v3[1]; + qglobal[26] = inv_v3[2]; qglobal[27] = qlocal[27]; @@ -894,22 +1070,37 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); - shiftder_v1[1] = (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); - shiftder_v1[2] = (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); - shiftder_v2[1] = (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); - shiftder_v2[2] = (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); - shiftder_v3[1] = (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); - shiftder_v3[2] = (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); + shiftder_v1[1] = + (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); + shiftder_v1[2] = + (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); + shiftder_v2[1] = + (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); + shiftder_v2[2] = + (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); + shiftder_v3[1] = + (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); + shiftder_v3[2] = + (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative back to global coordinate frame. - qglobal[31] = shiftder_v1[0]; qglobal[32] = shiftder_v1[1]; qglobal[33] = shiftder_v1[2]; - qglobal[34] = shiftder_v2[0]; qglobal[35] = shiftder_v2[1]; qglobal[36] = shiftder_v2[2]; - qglobal[37] = shiftder_v3[0]; qglobal[38] = shiftder_v3[1]; qglobal[39] = shiftder_v3[2]; + qglobal[31] = shiftder_v1[0]; + qglobal[32] = shiftder_v1[1]; + qglobal[33] = shiftder_v1[2]; + qglobal[34] = shiftder_v2[0]; + qglobal[35] = shiftder_v2[1]; + qglobal[36] = shiftder_v2[2]; + qglobal[37] = shiftder_v3[0]; + qglobal[38] = shiftder_v3[1]; + qglobal[39] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -1036,8 +1227,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[70] = (qlocal[68] * norm[2]) + (qlocal[69] * tau1[2]) + (qlocal[70] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); double gas_gamma = gr_euler->gas_gamma; @@ -1066,8 +1259,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr[i] - fl[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr[i] - fl[i]) / amax); } - } - else { + } else { for (int i = 0; i < 71; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1080,8 +1272,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[71]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1093,26 +1287,32 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); double vl[71], vr[71]; double gas_gamma = gr_euler->gas_gamma; - + gkyl_gr_euler_prim_vars(gas_gamma, ql, vl); gkyl_gr_euler_prim_vars(gas_gamma, qr, vr); @@ -1148,15 +1348,21 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double c_plus = 1.0 + ((gas_gamma / (gas_gamma - 1.0)) * v4); double v_alpha_sq = -(v0 * v0) + (v1 * v1) + (v2 * v2) + (v3 * v3); - double s_sq = (0.5 * gas_gamma * v4 * (1.0 - v_alpha_sq)) - (0.5 * (gas_gamma - 1.0) * (1.0 + v_alpha_sq)); + double s_sq = + (0.5 * gas_gamma * v4 * (1.0 - v_alpha_sq)) - (0.5 * (gas_gamma - 1.0) * (1.0 + v_alpha_sq)); double energy = (v0 * v0) - (v1 * v1); double y = sqrt(((1.0 - (gas_gamma * v4)) * energy) + s_sq); double k = (v0 * delta[4]) - (v1 * delta[1]); double v_delta = (-v0 * delta[4]) + (v1 * delta[1]) + (v2 * delta[2]) + (v3 * delta[3]); - double a1 = -((s_sq * k) + (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[4])) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / (2.0 * energy * s_sq); - double a2 = -((s_sq * k) - (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[4])) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / (2.0 * energy * s_sq); - double a3 = ((2.0 * s_sq * k) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta)))) / (energy * s_sq); + double a1 = -((s_sq * k) + (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[4])) + + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / + (2.0 * energy * s_sq); + double a2 = -((s_sq * k) - (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[4])) + + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / + (2.0 * energy * s_sq); + double a3 = ((2.0 * s_sq * k) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta)))) / + (energy * s_sq); double a4 = delta[2] - ((k * v2) / energy); double a5 = delta[3] - ((k * v3) / energy); @@ -1171,7 +1377,8 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c wv[2] = a1 * v2; wv[3] = a1 * v3; wv[4] = a1 * (v0 - ((sqrt(s_sq) * v1) / y)); - s[0] = (((1.0 - (gas_gamma * v4)) * v0 * v1) - (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); + s[0] = (((1.0 - (gas_gamma * v4)) * v0 * v1) - (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); wv = &waves[1 * 71]; wv[0] = (a3 * (c_minus + (s_sq / (gas_gamma - 1.0)))) - (a4 * c_plus * v2) - (a5 * c_plus * v3); @@ -1187,17 +1394,21 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c wv[2] = a2 * v2; wv[3] = a2 * v3; wv[4] = a2 * (v0 + ((sqrt(s_sq) * v1) / y)); - s[2] = (((1.0 - (gas_gamma * v4)) * v0 * v1) + (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); + s[2] = (((1.0 - (gas_gamma * v4)) * v0 * v1) + (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); - return (((1.0 - (gas_gamma * v4)) * v0 * fabs(v1)) + (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); + return (((1.0 - (gas_gamma * v4)) * v0 * fabs(v1)) + (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { - const double* w0 = &waves[0 * 71]; - const double* w1 = &waves[1 * 71]; - const double* w2 = &waves[2 * 71]; + const double *w0 = &waves[0 * 71]; + const double *w1 = &waves[1 * 71]; + const double *w2 = &waves[2 * 71]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]); @@ -1212,31 +1423,35 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } } -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); double gas_gamma = gr_euler->gas_gamma; @@ -1257,11 +1472,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_zl = vl[8]; double spatial_metric_l[3][3]; - spatial_metric_l[0][0] = vl[9]; spatial_metric_l[0][1] = vl[10]; spatial_metric_l[0][2] = vl[11]; - spatial_metric_l[1][0] = vl[12]; spatial_metric_l[1][1] = vl[13]; spatial_metric_l[1][2] = vl[14]; - spatial_metric_l[2][0] = vl[15]; spatial_metric_l[2][1] = vl[16]; spatial_metric_l[2][2] = vl[17]; - - double **inv_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); + spatial_metric_l[0][0] = vl[9]; + spatial_metric_l[0][1] = vl[10]; + spatial_metric_l[0][2] = vl[11]; + spatial_metric_l[1][0] = vl[12]; + spatial_metric_l[1][1] = vl[13]; + spatial_metric_l[1][2] = vl[14]; + spatial_metric_l[2][0] = vl[15]; + spatial_metric_l[2][1] = vl[16]; + spatial_metric_l[2][2] = vl[17]; + + double **inv_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); } @@ -1280,16 +1501,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_l[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_l = true; } - } - else { + } else { if (fabs(spatial_metric_l[i][j]) > pow(10.0, -8.0)) { curved_spacetime_l = true; } } } } - if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_xl) > pow(10.0, -8.0) || fabs(shift_yl) > pow(10.0, -8.0) || - fabs(shift_zl) > pow(10.0, -8.0)) { + if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_xl) > pow(10.0, -8.0) || + fabs(shift_yl) > pow(10.0, -8.0) || fabs(shift_zl) > pow(10.0, -8.0)) { curved_spacetime_l = true; } @@ -1305,11 +1525,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_zr = vr[8]; double spatial_metric_r[3][3]; - spatial_metric_r[0][0] = vr[9]; spatial_metric_r[0][1] = vr[10]; spatial_metric_r[0][2] = vr[11]; - spatial_metric_r[1][0] = vr[12]; spatial_metric_r[1][1] = vr[13]; spatial_metric_r[1][2] = vr[14]; - spatial_metric_r[2][0] = vr[15]; spatial_metric_r[2][1] = vr[16]; spatial_metric_r[2][2] = vr[17]; - - double **inv_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + spatial_metric_r[0][0] = vr[9]; + spatial_metric_r[0][1] = vr[10]; + spatial_metric_r[0][2] = vr[11]; + spatial_metric_r[1][0] = vr[12]; + spatial_metric_r[1][1] = vr[13]; + spatial_metric_r[1][2] = vr[14]; + spatial_metric_r[2][0] = vr[15]; + spatial_metric_r[2][1] = vr[16]; + spatial_metric_r[2][2] = vr[17]; + + double **inv_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } @@ -1328,16 +1554,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_r[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_r = true; } - } - else { + } else { if (fabs(spatial_metric_l[i][j]) > pow(10.0, -8.0)) { curved_spacetime_r = true; } } } } - if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_xr) > pow(10.0, -8.0) || fabs(shift_yr) > pow(10.0, -8.0) || - fabs(shift_zr) > pow(10.0, -8.0)) { + if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_xr) > pow(10.0, -8.0) || + fabs(shift_yr) > pow(10.0, -8.0) || fabs(shift_zr) > pow(10.0, -8.0)) { curved_spacetime_r = true; } @@ -1357,7 +1582,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (curved_spacetime_l || curved_spacetime_r) { double vel_l[3]; double v_sq_l = 0.0; - vel_l[0] = vx_l; vel_l[1] = vy_l; vel_l[2] = vz_l; + vel_l[0] = vx_l; + vel_l[1] = vy_l; + vel_l[2] = vz_l; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1366,7 +1593,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_l[3]; - shift_l[0] = shift_xl; shift_l[1] = shift_yl; shift_l[2] = shift_zl; + shift_l[0] = shift_xl; + shift_l[1] = shift_yl; + shift_l[2] = shift_zl; double material_eigs_l[3]; double fast_acoustic_eigs_l[3]; @@ -1375,11 +1604,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_l[i] = (lapse_l * vel_l[i]) - shift_l[i]; - fast_acoustic_eigs_l[i] = (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * ((vel_l[i] * (1.0 - (c_sl * c_sl))) + - (c_sl * sqrt((1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl)))))) - shift_l[i]; - - slow_acoustic_eigs_l[i] = (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * ((vel_l[i] * (1.0 - (c_sl * c_sl))) - - (c_sl * sqrt((1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl)))))) - shift_l[i]; + fast_acoustic_eigs_l[i] = + (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * + ((vel_l[i] * (1.0 - (c_sl * c_sl))) + + (c_sl * + sqrt( + (1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - + (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_l[i]; + + slow_acoustic_eigs_l[i] = + (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * + ((vel_l[i] * (1.0 - (c_sl * c_sl))) - + (c_sl * + sqrt( + (1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - + (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_l[i]; } double max_eig_l = 0.0; @@ -1397,7 +1640,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_r[3]; double v_sq_r = 0.0; - vel_r[0] = vx_r; vel_r[1] = vy_r; vel_r[2] = vz_r; + vel_r[0] = vx_r; + vel_r[1] = vy_r; + vel_r[2] = vz_r; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1406,7 +1651,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_r[3]; - shift_r[0] = shift_xr; shift_r[1] = shift_yr; shift_r[2] = shift_zr; + shift_r[0] = shift_xr; + shift_r[1] = shift_yr; + shift_r[2] = shift_zr; double material_eigs_r[3]; double fast_acoustic_eigs_r[3]; @@ -1415,11 +1662,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_r[i] = (lapse_r * vel_r[i]) - shift_r[i]; - fast_acoustic_eigs_r[i] = (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * ((vel_r[i] * (1.0 - (c_sl * c_sl))) + - (c_sl * sqrt((1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl)))))) - shift_r[i]; - - slow_acoustic_eigs_r[i] = (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * ((vel_r[i] * (1.0 - (c_sl * c_sl))) - - (c_sl * sqrt((1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl)))))) - shift_r[i]; + fast_acoustic_eigs_r[i] = + (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * + ((vel_r[i] * (1.0 - (c_sl * c_sl))) + + (c_sl * + sqrt( + (1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - + (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_r[i]; + + slow_acoustic_eigs_r[i] = + (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * + ((vel_r[i] * (1.0 - (c_sl * c_sl))) - + (c_sl * + sqrt( + (1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - + (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_r[i]; } double max_eig_r = 0.0; @@ -1436,11 +1697,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double max_eig_avg = 0.5 * (max_eig_l + max_eig_r); - + sl = (vx_avg - max_eig_avg) / (1.0 - (vx_avg * max_eig_avg)); sr = (vx_avg + max_eig_avg) / (1.0 + (vx_avg * max_eig_avg)); - } - else { + } else { sl = (vx_avg - cs_avg) / (1.0 - (vx_avg * cs_avg)); sr = (vx_avg + cs_avg) / (1.0 + (vx_avg * cs_avg)); } @@ -1460,8 +1720,7 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = qm[i] - ql[i]; w1[i] = qr[i] - qm[i]; } - } - else { + } else { for (int i = 0; i < 71; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1481,8 +1740,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return fmax(fabs(sl), fabs(sr)); } -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[71]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1494,33 +1755,35 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hll(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_hll(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); double gas_gamma = gr_euler->gas_gamma; @@ -1543,8 +1806,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 71; m++) { flux_jump[m] = fr[m] - fl[m]; } - } - else { + } else { for (int m = 0; m < 71; m++) { flux_jump[m] = 0.0; } @@ -1556,25 +1818,22 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); double gas_gamma = gr_euler->gas_gamma; - double v[71] = { 0.0 }; + double v[71] = {0.0}; gkyl_gr_euler_prim_vars(gas_gamma, q, v); if (v[0] < 0.0 || v[4] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); double gas_gamma = gr_euler->gas_gamma; @@ -1583,20 +1842,19 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) } static inline void -gr_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +gr_euler_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 5; i++) { diag[i] = qin[i]; } } -static inline void -gr_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void gr_euler_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); double gas_gamma = gr_euler->gas_gamma; - double v[71] = { 0.0 }; + double v[71] = {0.0}; gkyl_gr_euler_prim_vars(gas_gamma, qin, v); double rho = v[0]; double vx = v[1]; @@ -1610,14 +1868,26 @@ gr_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) double shift_z = v[8]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[9]; spatial_metric[0][1] = v[10]; spatial_metric[0][2] = v[11]; - spatial_metric[1][0] = v[12]; spatial_metric[1][1] = v[13]; spatial_metric[1][2] = v[14]; - spatial_metric[2][0] = v[15]; spatial_metric[2][1] = v[16]; spatial_metric[2][2] = v[17]; + spatial_metric[0][0] = v[9]; + spatial_metric[0][1] = v[10]; + spatial_metric[0][2] = v[11]; + spatial_metric[1][0] = v[12]; + spatial_metric[1][1] = v[13]; + spatial_metric[1][2] = v[14]; + spatial_metric[2][0] = v[15]; + spatial_metric[2][1] = v[16]; + spatial_metric[2][2] = v[17]; double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = v[18]; extrinsic_curvature[0][1] = v[19]; extrinsic_curvature[0][2] = v[20]; - extrinsic_curvature[1][0] = v[21]; extrinsic_curvature[1][1] = v[22]; extrinsic_curvature[1][2] = v[23]; - extrinsic_curvature[2][0] = v[24]; extrinsic_curvature[2][1] = v[25]; extrinsic_curvature[2][2] = v[26]; + extrinsic_curvature[0][0] = v[18]; + extrinsic_curvature[0][1] = v[19]; + extrinsic_curvature[0][2] = v[20]; + extrinsic_curvature[1][0] = v[21]; + extrinsic_curvature[1][1] = v[22]; + extrinsic_curvature[1][2] = v[23]; + extrinsic_curvature[2][0] = v[24]; + extrinsic_curvature[2][1] = v[25]; + extrinsic_curvature[2][2] = v[26]; double lapse_der[3]; lapse_der[0] = v[28]; @@ -1625,24 +1895,48 @@ gr_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) lapse_der[2] = v[30]; double shift_der[3][3]; - shift_der[0][0] = v[31]; shift_der[0][1] = v[32]; shift_der[0][2] = v[33]; - shift_der[1][0] = v[34]; shift_der[1][1] = v[35]; shift_der[1][2] = v[36]; - shift_der[2][0] = v[37]; shift_der[2][1] = v[38]; shift_der[2][2] = v[39]; + shift_der[0][0] = v[31]; + shift_der[0][1] = v[32]; + shift_der[0][2] = v[33]; + shift_der[1][0] = v[34]; + shift_der[1][1] = v[35]; + shift_der[1][2] = v[36]; + shift_der[2][0] = v[37]; + shift_der[2][1] = v[38]; + shift_der[2][2] = v[39]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = v[40]; spatial_metric_der[0][0][1] = v[41]; spatial_metric_der[0][0][2] = v[42]; - spatial_metric_der[0][1][0] = v[43]; spatial_metric_der[0][1][1] = v[44]; spatial_metric_der[0][1][2] = v[45]; - spatial_metric_der[0][2][0] = v[46]; spatial_metric_der[0][2][1] = v[47]; spatial_metric_der[0][2][2] = v[48]; - - spatial_metric_der[1][0][0] = v[49]; spatial_metric_der[1][0][1] = v[50]; spatial_metric_der[1][0][2] = v[51]; - spatial_metric_der[1][1][0] = v[52]; spatial_metric_der[1][1][1] = v[53]; spatial_metric_der[1][1][2] = v[54]; - spatial_metric_der[1][2][0] = v[55]; spatial_metric_der[1][2][1] = v[56]; spatial_metric_der[1][2][2] = v[57]; - - spatial_metric_der[0][0][0] = v[58]; spatial_metric_der[0][0][1] = v[59]; spatial_metric_der[0][0][2] = v[60]; - spatial_metric_der[0][1][0] = v[61]; spatial_metric_der[0][1][1] = v[62]; spatial_metric_der[0][1][2] = v[63]; - spatial_metric_der[0][2][0] = v[64]; spatial_metric_der[0][2][1] = v[65]; spatial_metric_der[0][2][2] = v[66]; - - double **stress_energy = gkyl_malloc(sizeof(double*[4])); + spatial_metric_der[0][0][0] = v[40]; + spatial_metric_der[0][0][1] = v[41]; + spatial_metric_der[0][0][2] = v[42]; + spatial_metric_der[0][1][0] = v[43]; + spatial_metric_der[0][1][1] = v[44]; + spatial_metric_der[0][1][2] = v[45]; + spatial_metric_der[0][2][0] = v[46]; + spatial_metric_der[0][2][1] = v[47]; + spatial_metric_der[0][2][2] = v[48]; + + spatial_metric_der[1][0][0] = v[49]; + spatial_metric_der[1][0][1] = v[50]; + spatial_metric_der[1][0][2] = v[51]; + spatial_metric_der[1][1][0] = v[52]; + spatial_metric_der[1][1][1] = v[53]; + spatial_metric_der[1][1][2] = v[54]; + spatial_metric_der[1][2][0] = v[55]; + spatial_metric_der[1][2][1] = v[56]; + spatial_metric_der[1][2][2] = v[57]; + + spatial_metric_der[0][0][0] = v[58]; + spatial_metric_der[0][0][1] = v[59]; + spatial_metric_der[0][0][2] = v[60]; + spatial_metric_der[0][1][0] = v[61]; + spatial_metric_der[0][1][1] = v[62]; + spatial_metric_der[0][1][2] = v[63]; + spatial_metric_der[0][2][0] = v[64]; + spatial_metric_der[0][2][1] = v[65]; + spatial_metric_der[0][2][2] = v[66]; + + double **stress_energy = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { stress_energy[i] = gkyl_malloc(sizeof(double[4])); } @@ -1656,11 +1950,15 @@ gr_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) if (!in_excision_region) { double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1674,7 +1972,7 @@ gr_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double mom[3]; mom[0] = (rho * h) * (W * W) * vx; mom[1] = (rho * h) * (W * W) * vy; @@ -1699,7 +1997,8 @@ gr_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - sout[1 + j] += 0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]; + sout[1 + j] += + 0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]; sout[1 + j] += 0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]; } @@ -1710,8 +2009,7 @@ gr_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) } } } - } - else { + } else { for (int i = 0; i < 71; i++) { sout[i] = 0.0; } @@ -1723,10 +2021,9 @@ gr_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) gkyl_free(stress_energy); } -void -gkyl_gr_euler_free(const struct gkyl_ref_count* ref) +void gkyl_gr_euler_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. @@ -1738,22 +2035,21 @@ gkyl_gr_euler_free(const struct gkyl_ref_count* ref) gkyl_free(gr_euler); } -struct gkyl_wv_eqn* -gkyl_wv_gr_euler_new(double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_gr_euler_new( + double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, + struct gkyl_gr_spacetime *spacetime, bool use_gpu +) { - return gkyl_wv_gr_euler_inew(&(struct gkyl_wv_gr_euler_inp) { - .gas_gamma = gas_gamma, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .spacetime = spacetime, - .rp_type = WV_GR_EULER_RP_HLL, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_gr_euler_inew(&(struct gkyl_wv_gr_euler_inp + ){.gas_gamma = gas_gamma, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .spacetime = spacetime, + .rp_type = WV_GR_EULER_RP_HLL, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_gr_euler_inew(const struct gkyl_wv_gr_euler_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_gr_euler_inew(const struct gkyl_wv_gr_euler_inp *inp) { struct wv_gr_euler *gr_euler = gkyl_malloc(sizeof(struct wv_gr_euler)); @@ -1770,13 +2066,11 @@ gkyl_wv_gr_euler_inew(const struct gkyl_wv_gr_euler_inp* inp) gr_euler->eqn.num_waves = 2; gr_euler->eqn.waves_func = wave_lax_l; gr_euler->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_GR_EULER_RP_ROE) { + } else if (inp->rp_type == WV_GR_EULER_RP_ROE) { gr_euler->eqn.num_waves = 3; gr_euler->eqn.waves_func = wave_roe_l; gr_euler->eqn.qfluct_func = qfluct_roe_l; - } - else if (inp->rp_type == WV_GR_EULER_RP_HLL) { + } else if (inp->rp_type == WV_GR_EULER_RP_HLL) { gr_euler->eqn.num_waves = 2; gr_euler->eqn.waves_func = wave_hll_l; gr_euler->eqn.qfluct_func = qfluct_hll_l; @@ -1808,8 +2102,7 @@ gkyl_wv_gr_euler_inew(const struct gkyl_wv_gr_euler_inp* inp) return &gr_euler->eqn; } -double -gkyl_wv_gr_euler_gas_gamma(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_euler_gas_gamma(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); double gas_gamma = gr_euler->gas_gamma; @@ -1817,8 +2110,7 @@ gkyl_wv_gr_euler_gas_gamma(const struct gkyl_wv_eqn* eqn) return gas_gamma; } -enum gkyl_spacetime_gauge -gkyl_wv_gr_euler_spacetime_gauge(const struct gkyl_wv_eqn* eqn) +enum gkyl_spacetime_gauge gkyl_wv_gr_euler_spacetime_gauge(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); enum gkyl_spacetime_gauge spacetime_gauge = gr_euler->spacetime_gauge; @@ -1826,8 +2118,7 @@ gkyl_wv_gr_euler_spacetime_gauge(const struct gkyl_wv_eqn* eqn) return spacetime_gauge; } -int -gkyl_wv_gr_euler_reinit_freq(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_gr_euler_reinit_freq(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); int reinit_freq = gr_euler->reinit_freq; @@ -1835,8 +2126,7 @@ gkyl_wv_gr_euler_reinit_freq(const struct gkyl_wv_eqn* eqn) return reinit_freq; } -struct gkyl_gr_spacetime* -gkyl_wv_gr_euler_spacetime(const struct gkyl_wv_eqn* eqn) +struct gkyl_gr_spacetime *gkyl_wv_gr_euler_spacetime(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_euler *gr_euler = container_of(eqn, struct wv_gr_euler, eqn); struct gkyl_gr_spacetime *spacetime = gr_euler->spacetime; diff --git a/moments/zero/wv_gr_euler_tetrad.c b/moments/zero/wv_gr_euler_tetrad.c index 522e94bd6b..23dabb99b2 100644 --- a/moments/zero/wv_gr_euler_tetrad.c +++ b/moments/zero/wv_gr_euler_tetrad.c @@ -6,12 +6,11 @@ #include #include -void -gkyl_gr_euler_tetrad_flux(double gas_gamma, const double q[71], double flux[71]) +void gkyl_gr_euler_tetrad_flux(double gas_gamma, const double q[71], double flux[71]) { - double v[71] = { 0.0 }; + double v[71] = {0.0}; gkyl_gr_euler_tetrad_prim_vars(gas_gamma, q, v); - double rho = v[0]; + double rho = v[0]; double vx = v[1]; double vy = v[2]; double vz = v[3]; @@ -39,20 +38,20 @@ gkyl_gr_euler_tetrad_flux(double gas_gamma, const double q[71], double flux[71]) for (int i = 5; i < 71; i++) { flux[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 71; i++) { flux[i] = 0.0; } } } -void -gkyl_gr_euler_tetrad_flux_correction(double gas_gamma, const double q[71], const double flux_sr[71], double flux_gr[71]) +void gkyl_gr_euler_tetrad_flux_correction( + double gas_gamma, const double q[71], const double flux_sr[71], double flux_gr[71] +) { - double v[71] = { 0.0 }; + double v[71] = {0.0}; gkyl_gr_euler_tetrad_prim_vars(gas_gamma, q, v); - double rho = v[0]; + double rho = v[0]; double vx = v[1]; double vy = v[2]; double vz = v[3]; @@ -62,14 +61,23 @@ gkyl_gr_euler_tetrad_flux_correction(double gas_gamma, const double q[71], const double shift_x = v[6]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[9]; spatial_metric[0][1] = v[10]; spatial_metric[0][2] = v[11]; - spatial_metric[1][0] = v[12]; spatial_metric[1][1] = v[13]; spatial_metric[1][2] = v[14]; - spatial_metric[2][0] = v[15]; spatial_metric[2][1] = v[16]; spatial_metric[2][2] = v[17]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = v[9]; + spatial_metric[0][1] = v[10]; + spatial_metric[0][2] = v[11]; + spatial_metric[1][0] = v[12]; + spatial_metric[1][1] = v[13]; + spatial_metric[1][2] = v[14]; + spatial_metric[2][0] = v[15]; + spatial_metric[2][1] = v[16]; + spatial_metric[2][2] = v[17]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + bool in_excision_region = false; if (v[27] < pow(10.0, -8.0)) { in_excision_region = true; @@ -78,7 +86,9 @@ gkyl_gr_euler_tetrad_flux_correction(double gas_gamma, const double q[71], const if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -99,32 +109,41 @@ gkyl_gr_euler_tetrad_flux_correction(double gas_gamma, const double q[71], const if (fabs(vx) < pow(10.0, -8.0)) { if (vx > 0.0) { vx = pow(10.0, -8.0); - } - else { + } else { vx = -pow(10.0, -8.0); } } - flux_gr[0] = (lapse * sqrt(spatial_det)) * ((flux_sr[0] * (vx - (shift_x / lapse)) * W_curved) / (vx * W_flat)); - flux_gr[1] = (lapse * sqrt(spatial_det)) * ((((flux_sr[1] - p) * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))) + p); - flux_gr[2] = (lapse * sqrt(spatial_det)) * ((flux_sr[2] * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))); - flux_gr[3] = (lapse * sqrt(spatial_det)) * ((flux_sr[3] * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))); - flux_gr[4] = (lapse * sqrt(spatial_det)) * (((((flux_sr[4] + (rho * vx * W_flat)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))) - p - - (rho * W_curved)) * (vx - (shift_x / lapse)) + (p * vx)); + flux_gr[0] = (lapse * sqrt(spatial_det)) * + ((flux_sr[0] * (vx - (shift_x / lapse)) * W_curved) / (vx * W_flat)); + flux_gr[1] = (lapse * sqrt(spatial_det)) * + ((((flux_sr[1] - p) * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / + (vx * (W_flat * W_flat))) + + p); + flux_gr[2] = + (lapse * sqrt(spatial_det)) * + ((flux_sr[2] * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))); + flux_gr[3] = + (lapse * sqrt(spatial_det)) * + ((flux_sr[3] * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))); + flux_gr[4] = + (lapse * sqrt(spatial_det)) * + (((((flux_sr[4] + (rho * vx * W_flat)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))) - + p - (rho * W_curved)) * + (vx - (shift_x / lapse)) + + (p * vx)); for (int i = 5; i < 71; i++) { flux_gr[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 71; i++) { flux_gr[i] = 0.0; } } } -void -gkyl_gr_euler_tetrad_prim_vars(double gas_gamma, const double q[71], double v[71]) +void gkyl_gr_euler_tetrad_prim_vars(double gas_gamma, const double q[71], double v[71]) { double lapse = q[5]; double shift_x = q[6]; @@ -132,14 +151,26 @@ gkyl_gr_euler_tetrad_prim_vars(double gas_gamma, const double q[71], double v[71 double shift_z = q[8]; double spatial_metric[3][3]; - spatial_metric[0][0] = q[9]; spatial_metric[0][1] = q[10]; spatial_metric[0][2] = q[11]; - spatial_metric[1][0] = q[12]; spatial_metric[1][1] = q[13]; spatial_metric[1][2] = q[14]; - spatial_metric[2][0] = q[15]; spatial_metric[2][1] = q[16]; spatial_metric[2][2] = q[17]; - + spatial_metric[0][0] = q[9]; + spatial_metric[0][1] = q[10]; + spatial_metric[0][2] = q[11]; + spatial_metric[1][0] = q[12]; + spatial_metric[1][1] = q[13]; + spatial_metric[1][2] = q[14]; + spatial_metric[2][0] = q[15]; + spatial_metric[2][1] = q[16]; + spatial_metric[2][2] = q[17]; + double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = q[18]; extrinsic_curvature[0][1] = q[19]; extrinsic_curvature[0][2] = q[20]; - extrinsic_curvature[1][0] = q[21]; extrinsic_curvature[1][1] = q[22]; extrinsic_curvature[1][2] = q[23]; - extrinsic_curvature[2][0] = q[24]; extrinsic_curvature[2][1] = q[25]; extrinsic_curvature[2][2] = q[26]; + extrinsic_curvature[0][0] = q[18]; + extrinsic_curvature[0][1] = q[19]; + extrinsic_curvature[0][2] = q[20]; + extrinsic_curvature[1][0] = q[21]; + extrinsic_curvature[1][1] = q[22]; + extrinsic_curvature[1][2] = q[23]; + extrinsic_curvature[2][0] = q[24]; + extrinsic_curvature[2][1] = q[25]; + extrinsic_curvature[2][2] = q[26]; double lapse_der[3]; lapse_der[0] = q[28]; @@ -147,22 +178,46 @@ gkyl_gr_euler_tetrad_prim_vars(double gas_gamma, const double q[71], double v[71 lapse_der[2] = q[30]; double shift_der[3][3]; - shift_der[0][0] = q[31]; shift_der[0][1] = q[32]; shift_der[0][2] = q[33]; - shift_der[1][0] = q[34]; shift_der[1][1] = q[35]; shift_der[1][2] = q[36]; - shift_der[2][0] = q[37]; shift_der[2][1] = q[38]; shift_der[2][2] = q[39]; + shift_der[0][0] = q[31]; + shift_der[0][1] = q[32]; + shift_der[0][2] = q[33]; + shift_der[1][0] = q[34]; + shift_der[1][1] = q[35]; + shift_der[1][2] = q[36]; + shift_der[2][0] = q[37]; + shift_der[2][1] = q[38]; + shift_der[2][2] = q[39]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = q[40]; spatial_metric_der[0][0][1] = q[41]; spatial_metric_der[0][0][2] = q[42]; - spatial_metric_der[0][1][0] = q[43]; spatial_metric_der[0][1][1] = q[44]; spatial_metric_der[0][1][2] = q[45]; - spatial_metric_der[0][2][0] = q[46]; spatial_metric_der[0][2][1] = q[47]; spatial_metric_der[0][2][2] = q[48]; - - spatial_metric_der[1][0][0] = q[49]; spatial_metric_der[1][0][1] = q[50]; spatial_metric_der[1][0][2] = q[51]; - spatial_metric_der[1][1][0] = q[52]; spatial_metric_der[1][1][1] = q[53]; spatial_metric_der[1][1][2] = q[54]; - spatial_metric_der[1][2][0] = q[55]; spatial_metric_der[1][2][1] = q[56]; spatial_metric_der[1][2][2] = q[57]; - - spatial_metric_der[0][0][0] = q[58]; spatial_metric_der[0][0][1] = q[59]; spatial_metric_der[0][0][2] = q[60]; - spatial_metric_der[0][1][0] = q[61]; spatial_metric_der[0][1][1] = q[62]; spatial_metric_der[0][1][2] = q[63]; - spatial_metric_der[0][2][0] = q[64]; spatial_metric_der[0][2][1] = q[65]; spatial_metric_der[0][2][2] = q[66]; + spatial_metric_der[0][0][0] = q[40]; + spatial_metric_der[0][0][1] = q[41]; + spatial_metric_der[0][0][2] = q[42]; + spatial_metric_der[0][1][0] = q[43]; + spatial_metric_der[0][1][1] = q[44]; + spatial_metric_der[0][1][2] = q[45]; + spatial_metric_der[0][2][0] = q[46]; + spatial_metric_der[0][2][1] = q[47]; + spatial_metric_der[0][2][2] = q[48]; + + spatial_metric_der[1][0][0] = q[49]; + spatial_metric_der[1][0][1] = q[50]; + spatial_metric_der[1][0][2] = q[51]; + spatial_metric_der[1][1][0] = q[52]; + spatial_metric_der[1][1][1] = q[53]; + spatial_metric_der[1][1][2] = q[54]; + spatial_metric_der[1][2][0] = q[55]; + spatial_metric_der[1][2][1] = q[56]; + spatial_metric_der[1][2][2] = q[57]; + + spatial_metric_der[0][0][0] = q[58]; + spatial_metric_der[0][0][1] = q[59]; + spatial_metric_der[0][0][2] = q[60]; + spatial_metric_der[0][1][0] = q[61]; + spatial_metric_der[0][1][1] = q[62]; + spatial_metric_der[0][1][2] = q[63]; + spatial_metric_der[0][2][0] = q[64]; + spatial_metric_der[0][2][1] = q[65]; + spatial_metric_der[0][2][2] = q[66]; double evol_param = q[67]; double x = q[68]; @@ -175,9 +230,12 @@ gkyl_gr_euler_tetrad_prim_vars(double gas_gamma, const double q[71], double v[71 } if (!in_excision_region) { - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double D = q[0] / sqrt(spatial_det); double momx = q[1] / sqrt(spatial_det); @@ -185,38 +243,47 @@ gkyl_gr_euler_tetrad_prim_vars(double gas_gamma, const double q[71], double v[71 double momz = q[3] / sqrt(spatial_det); double Etot = q[4] / sqrt(spatial_det); - double C = D / sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); - double C0 = (D + Etot) / sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); - if (((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz)) < pow(10.0, -8.0)) { + double C = + D / sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); + double C0 = (D + Etot) / + sqrt(((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz))); + if (((Etot + D) * (Etot + D)) - ((momx * momx) + (momy * momy) + (momz * momz)) < + pow(10.0, -8.0)) { C = D / sqrt(pow(10.0, -8.0)); C0 = (D + Etot) / sqrt(pow(10.0, -8.0)); } double alpha0 = -1.0 / (gas_gamma * gas_gamma); double alpha1 = -2.0 * C * ((gas_gamma - 1.0) / (gas_gamma * gas_gamma)); - double alpha2 = ((gas_gamma - 2.0) / gas_gamma) * ((C0 * C0) - 1.0) + 1.0 - (C * C) * ((gas_gamma - 1.0) / gas_gamma) * ((gas_gamma - 1.0) / gas_gamma); + double alpha2 = ((gas_gamma - 2.0) / gas_gamma) * ((C0 * C0) - 1.0) + 1.0 - + (C * C) * ((gas_gamma - 1.0) / gas_gamma) * ((gas_gamma - 1.0) / gas_gamma); double alpha4 = (C0 * C0) - 1.0; - double eta = 2.0 * C *((gas_gamma - 1.0) / gas_gamma); + double eta = 2.0 * C * ((gas_gamma - 1.0) / gas_gamma); double guess = 1.0; int iter = 0; while (iter < 100) { - double poly = (alpha4 * (guess * guess * guess) * (guess - eta)) + (alpha2 * (guess * guess)) + (alpha1 * guess) + alpha0; - double poly_der = alpha1 + (2.0 * alpha2 * guess) + (4.0 * alpha4 * (guess * guess * guess)) - (3.0 * eta * alpha4 * (guess * guess)); + double poly = (alpha4 * (guess * guess * guess) * (guess - eta)) + + (alpha2 * (guess * guess)) + (alpha1 * guess) + alpha0; + double poly_der = alpha1 + (2.0 * alpha2 * guess) + (4.0 * alpha4 * (guess * guess * guess)) - + (3.0 * eta * alpha4 * (guess * guess)); double guess_new = guess - (poly / poly_der); if (fabs(guess - guess_new) < pow(10.0, -8.0)) { iter = 100; - } - else { + } else { iter += 1; guess = guess_new; } } - double W = 0.5 * C0 * guess * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma - 1.0) / gas_gamma) * ((1.0 - (C * guess)) / ((C0 * C0) * (guess * guess)))))); + double W = 0.5 * C0 * guess * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma - 1.0) / gas_gamma) * + ((1.0 - (C * guess)) / ((C0 * C0) * (guess * guess)))) + )); double h = 1.0 / (C * guess); v[0] = D / W; @@ -237,13 +304,25 @@ gkyl_gr_euler_tetrad_prim_vars(double gas_gamma, const double q[71], double v[71 v[7] = shift_y; v[8] = shift_z; - v[9] = spatial_metric[0][0]; v[10] = spatial_metric[0][1]; v[11] = spatial_metric[0][2]; - v[12] = spatial_metric[1][0]; v[13] = spatial_metric[1][1]; v[14] = spatial_metric[1][2]; - v[15] = spatial_metric[2][0]; v[16] = spatial_metric[2][1]; v[17] = spatial_metric[2][2]; - - v[18] = extrinsic_curvature[0][0]; v[19] = extrinsic_curvature[0][1]; v[20] = extrinsic_curvature[0][2]; - v[21] = extrinsic_curvature[1][0]; v[22] = extrinsic_curvature[1][1]; v[23] = extrinsic_curvature[1][2]; - v[24] = extrinsic_curvature[2][0]; v[25] = extrinsic_curvature[2][1]; v[26] = extrinsic_curvature[2][2]; + v[9] = spatial_metric[0][0]; + v[10] = spatial_metric[0][1]; + v[11] = spatial_metric[0][2]; + v[12] = spatial_metric[1][0]; + v[13] = spatial_metric[1][1]; + v[14] = spatial_metric[1][2]; + v[15] = spatial_metric[2][0]; + v[16] = spatial_metric[2][1]; + v[17] = spatial_metric[2][2]; + + v[18] = extrinsic_curvature[0][0]; + v[19] = extrinsic_curvature[0][1]; + v[20] = extrinsic_curvature[0][2]; + v[21] = extrinsic_curvature[1][0]; + v[22] = extrinsic_curvature[1][1]; + v[23] = extrinsic_curvature[1][2]; + v[24] = extrinsic_curvature[2][0]; + v[25] = extrinsic_curvature[2][1]; + v[26] = extrinsic_curvature[2][2]; v[27] = 1.0; @@ -251,48 +330,79 @@ gkyl_gr_euler_tetrad_prim_vars(double gas_gamma, const double q[71], double v[71 v[29] = lapse_der[1]; v[30] = lapse_der[2]; - v[31] = shift_der[0][0]; v[32] = shift_der[0][1]; v[33] = shift_der[0][2]; - v[34] = shift_der[1][0]; v[35] = shift_der[1][1]; v[36] = shift_der[1][2]; - v[37] = shift_der[2][0]; v[38] = shift_der[2][1]; v[39] = shift_der[2][2]; - - v[40] = spatial_metric_der[0][0][0]; v[41] = spatial_metric_der[0][0][1]; v[42] = spatial_metric_der[0][0][2]; - v[43] = spatial_metric_der[0][1][0]; v[44] = spatial_metric_der[0][1][1]; v[45] = spatial_metric_der[0][1][2]; - v[46] = spatial_metric_der[0][2][0]; v[47] = spatial_metric_der[0][2][1]; v[48] = spatial_metric_der[0][2][2]; - - v[49] = spatial_metric_der[1][0][0]; v[50] = spatial_metric_der[1][0][1]; v[51] = spatial_metric_der[1][0][2]; - v[52] = spatial_metric_der[1][1][0]; v[53] = spatial_metric_der[1][1][1]; v[54] = spatial_metric_der[1][1][2]; - v[55] = spatial_metric_der[1][2][0]; v[56] = spatial_metric_der[1][2][1]; v[57] = spatial_metric_der[1][2][2]; - - v[58] = spatial_metric_der[2][0][0]; v[59] = spatial_metric_der[2][0][1]; v[60] = spatial_metric_der[2][0][2]; - v[61] = spatial_metric_der[2][1][0]; v[62] = spatial_metric_der[2][1][1]; v[63] = spatial_metric_der[2][1][2]; - v[64] = spatial_metric_der[2][2][0]; v[65] = spatial_metric_der[2][2][1]; v[66] = spatial_metric_der[2][2][2]; + v[31] = shift_der[0][0]; + v[32] = shift_der[0][1]; + v[33] = shift_der[0][2]; + v[34] = shift_der[1][0]; + v[35] = shift_der[1][1]; + v[36] = shift_der[1][2]; + v[37] = shift_der[2][0]; + v[38] = shift_der[2][1]; + v[39] = shift_der[2][2]; + + v[40] = spatial_metric_der[0][0][0]; + v[41] = spatial_metric_der[0][0][1]; + v[42] = spatial_metric_der[0][0][2]; + v[43] = spatial_metric_der[0][1][0]; + v[44] = spatial_metric_der[0][1][1]; + v[45] = spatial_metric_der[0][1][2]; + v[46] = spatial_metric_der[0][2][0]; + v[47] = spatial_metric_der[0][2][1]; + v[48] = spatial_metric_der[0][2][2]; + + v[49] = spatial_metric_der[1][0][0]; + v[50] = spatial_metric_der[1][0][1]; + v[51] = spatial_metric_der[1][0][2]; + v[52] = spatial_metric_der[1][1][0]; + v[53] = spatial_metric_der[1][1][1]; + v[54] = spatial_metric_der[1][1][2]; + v[55] = spatial_metric_der[1][2][0]; + v[56] = spatial_metric_der[1][2][1]; + v[57] = spatial_metric_der[1][2][2]; + + v[58] = spatial_metric_der[2][0][0]; + v[59] = spatial_metric_der[2][0][1]; + v[60] = spatial_metric_der[2][0][2]; + v[61] = spatial_metric_der[2][1][0]; + v[62] = spatial_metric_der[2][1][1]; + v[63] = spatial_metric_der[2][1][2]; + v[64] = spatial_metric_der[2][2][0]; + v[65] = spatial_metric_der[2][2][1]; + v[66] = spatial_metric_der[2][2][2]; v[67] = evol_param; v[68] = x; v[69] = y; v[70] = z; - } - else { + } else { for (int i = 0; i < 71; i++) { v[i] = 0.0; } - + v[27] = -1.0; } } -void -gkyl_gr_euler_tetrad_inv_spatial_metric(const double q[71], double ***inv_spatial_metric) +void gkyl_gr_euler_tetrad_inv_spatial_metric(const double q[71], double ***inv_spatial_metric) { double spatial_metric[3][3]; - spatial_metric[0][0] = q[9]; spatial_metric[0][1] = q[10]; spatial_metric[0][2] = q[11]; - spatial_metric[1][0] = q[12]; spatial_metric[1][1] = q[13]; spatial_metric[1][2] = q[14]; - spatial_metric[2][0] = q[15]; spatial_metric[2][1] = q[16]; spatial_metric[2][2] = q[17]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = q[9]; + spatial_metric[0][1] = q[10]; + spatial_metric[0][2] = q[11]; + spatial_metric[1][0] = q[12]; + spatial_metric[1][1] = q[13]; + spatial_metric[1][2] = q[14]; + spatial_metric[2][0] = q[15]; + spatial_metric[2][1] = q[16]; + spatial_metric[2][2] = q[17]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -323,8 +433,7 @@ gkyl_gr_euler_tetrad_inv_spatial_metric(const double q[71], double ***inv_spatia for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -332,16 +441,18 @@ gkyl_gr_euler_tetrad_inv_spatial_metric(const double q[71], double ***inv_spatia for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*inv_spatial_metric)[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*inv_spatial_metric)[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } } -void -gkyl_gr_euler_tetrad_stress_energy_tensor(double gas_gamma, const double q[71], double ***stress_energy) +void gkyl_gr_euler_tetrad_stress_energy_tensor( + double gas_gamma, const double q[71], double ***stress_energy +) { - double v[71] = { 0.0 }; + double v[71] = {0.0}; gkyl_gr_euler_tetrad_prim_vars(gas_gamma, q, v); double rho = v[0]; double vx = v[1]; @@ -355,11 +466,17 @@ gkyl_gr_euler_tetrad_stress_energy_tensor(double gas_gamma, const double q[71], double shift_z = v[8]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[9]; spatial_metric[0][1] = v[10]; spatial_metric[0][2] = v[11]; - spatial_metric[1][0] = v[12]; spatial_metric[1][1] = v[13]; spatial_metric[1][2] = v[14]; - spatial_metric[2][0] = v[15]; spatial_metric[2][1] = v[16]; spatial_metric[2][2] = v[17]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[9]; + spatial_metric[0][1] = v[10]; + spatial_metric[0][2] = v[11]; + spatial_metric[1][0] = v[12]; + spatial_metric[1][1] = v[13]; + spatial_metric[1][2] = v[14]; + spatial_metric[2][0] = v[15]; + spatial_metric[2][1] = v[16]; + spatial_metric[2][2] = v[17]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -374,7 +491,9 @@ gkyl_gr_euler_tetrad_stress_energy_tensor(double gas_gamma, const double q[71], if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -396,27 +515,30 @@ gkyl_gr_euler_tetrad_stress_energy_tensor(double gas_gamma, const double q[71], spacetime_vel[3] = (W * vz) - (shift_z * (W / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*stress_energy)[i][j] = (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); + (*stress_energy)[i][j] = + (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); } } - } - else { + } else { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { (*stress_energy)[i][j] = 0.0; @@ -430,12 +552,11 @@ gkyl_gr_euler_tetrad_stress_energy_tensor(double gas_gamma, const double q[71], gkyl_free(inv_spatial_metric); } -static inline double -gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]) +static inline double gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]) { - double v[71] = { 0.0 }; + double v[71] = {0.0}; gkyl_gr_euler_tetrad_prim_vars(gas_gamma, q, v); - double rho = v[0]; + double rho = v[0]; double vx = v[1]; double vy = v[2]; double vz = v[3]; @@ -447,11 +568,17 @@ gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]) double shift_z = v[8]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[9]; spatial_metric[0][1] = v[10]; spatial_metric[0][2] = v[11]; - spatial_metric[1][0] = v[12]; spatial_metric[1][1] = v[13]; spatial_metric[1][2] = v[14]; - spatial_metric[2][0] = v[15]; spatial_metric[2][1] = v[16]; spatial_metric[2][2] = v[17]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[9]; + spatial_metric[0][1] = v[10]; + spatial_metric[0][2] = v[11]; + spatial_metric[1][0] = v[12]; + spatial_metric[1][1] = v[13]; + spatial_metric[1][2] = v[14]; + spatial_metric[2][0] = v[15]; + spatial_metric[2][1] = v[16]; + spatial_metric[2][2] = v[17]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -474,16 +601,15 @@ gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]) if (fabs(spatial_metric[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime = true; } - } - else { + } else { if (fabs(spatial_metric[i][j]) > pow(10.0, -8.0)) { curved_spacetime = true; } } } } - if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || fabs(shift_y) > pow(10.0, -8.0) || - fabs(shift_z) > pow(10.0, -8.0)) { + if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || + fabs(shift_y) > pow(10.0, -8.0) || fabs(shift_z) > pow(10.0, -8.0)) { curved_spacetime = true; } @@ -491,7 +617,9 @@ gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]) if (curved_spacetime) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -500,7 +628,9 @@ gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]) } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double material_eigs[3]; double fast_acoustic_eigs[3]; @@ -509,11 +639,23 @@ gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]) for (int i = 0; i < 3; i++) { material_eigs[i] = (lapse * vel[i]) - shift[i]; - fast_acoustic_eigs[i] = (lapse / (1.0 - (v_sq * (c_s * c_s)))) * ((vel[i] * (1.0 - (c_s * c_s))) + - (c_s * sqrt((1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - (vel[i] * vel[i]) * (1.0 - (c_s * c_s)))))) - shift[i]; - - slow_acoustic_eigs[i] = (lapse / (1.0 - (v_sq * (c_s * c_s)))) * ((vel[i] * (1.0 - (c_s * c_s))) - - (c_s * sqrt((1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - (vel[i] * vel[i]) * (1.0 - (c_s * c_s)))))) - shift[i]; + fast_acoustic_eigs[i] = + (lapse / (1.0 - (v_sq * (c_s * c_s)))) * + ((vel[i] * (1.0 - (c_s * c_s))) + + (c_s * sqrt( + (1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - + (vel[i] * vel[i]) * (1.0 - (c_s * c_s))) + ))) - + shift[i]; + + slow_acoustic_eigs[i] = + (lapse / (1.0 - (v_sq * (c_s * c_s)))) * + ((vel[i] * (1.0 - (c_s * c_s))) - + (c_s * sqrt( + (1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - + (vel[i] * vel[i]) * (1.0 - (c_s * c_s))) + ))) - + shift[i]; } double max_eig = 0.0; @@ -535,8 +677,7 @@ gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]) gkyl_free(inv_spatial_metric); return fabs(v_sq) + max_eig; - } - else { + } else { double v_sq = sqrt((vx * vx) + (vy * vy) + (vz * vz)); for (int i = 0; i < 3; i++) { @@ -546,8 +687,7 @@ gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]) return fabs(v_sq) + c_s; } - } - else { + } else { for (int i = 0; i < 3; i++) { gkyl_free(inv_spatial_metric[i]); } @@ -558,7 +698,7 @@ gkyl_gr_euler_tetrad_max_abs_speed(double gas_gamma, const double q[71]) } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 71; i++) { @@ -567,7 +707,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 71; i++) { @@ -575,8 +715,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -gr_euler_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_euler_tetrad_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 0; i < 71; i++) { ghost[i] = skin[i]; @@ -585,8 +727,10 @@ gr_euler_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const doub ghost[1] = -ghost[1]; } -static void -gr_euler_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_euler_tetrad_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 1; i < 4; i++) { ghost[i] = -skin[i]; @@ -600,9 +744,10 @@ gr_euler_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const d } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; qlocal[1] = (qglobal[1] * norm[0]) + (qglobal[2] * norm[1]) + (qglobal[3] * norm[2]); @@ -644,9 +789,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinate frame. - qlocal[9] = v1[0]; qlocal[10] = v1[1]; qlocal[11] = v1[2]; - qlocal[12] = v2[0]; qlocal[13] = v2[1]; qlocal[14] = v2[2]; - qlocal[15] = v3[0]; qlocal[16] = v3[1]; qlocal[17] = v3[2]; + qlocal[9] = v1[0]; + qlocal[10] = v1[1]; + qlocal[11] = v1[2]; + qlocal[12] = v2[0]; + qlocal[13] = v2[1]; + qlocal[14] = v2[2]; + qlocal[15] = v3[0]; + qlocal[16] = v3[1]; + qlocal[17] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -677,9 +828,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta inv_v3[2] = (extr_r1[2] * tau2[0]) + (extr_r2[2] * tau2[1]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor to local coordinate frame. - qlocal[18] = inv_v1[0]; qlocal[19] = inv_v1[1]; qlocal[20] = inv_v1[2]; - qlocal[21] = inv_v2[0]; qlocal[22] = inv_v2[1]; qlocal[23] = inv_v2[2]; - qlocal[24] = inv_v3[0]; qlocal[25] = inv_v3[1]; qlocal[26] = inv_v3[2]; + qlocal[18] = inv_v1[0]; + qlocal[19] = inv_v1[1]; + qlocal[20] = inv_v1[2]; + qlocal[21] = inv_v2[0]; + qlocal[22] = inv_v2[1]; + qlocal[23] = inv_v2[2]; + qlocal[24] = inv_v3[0]; + qlocal[25] = inv_v3[1]; + qlocal[26] = inv_v3[2]; qlocal[27] = qglobal[27]; @@ -703,22 +860,37 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); - shiftder_v1[1] = (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); - shiftder_v1[2] = (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); - shiftder_v2[1] = (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); - shiftder_v2[2] = (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); - shiftder_v3[1] = (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); - shiftder_v3[2] = (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); + shiftder_v1[1] = + (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); + shiftder_v1[2] = + (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); + shiftder_v2[1] = + (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); + shiftder_v2[2] = + (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); + shiftder_v3[1] = + (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); + shiftder_v3[2] = + (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative to local coordinate frame. - qlocal[31] = shiftder_v1[0]; qlocal[32] = shiftder_v1[1]; qlocal[33] = shiftder_v1[2]; - qlocal[34] = shiftder_v2[0]; qlocal[35] = shiftder_v2[1]; qlocal[36] = shiftder_v2[2]; - qlocal[37] = shiftder_v3[0]; qlocal[38] = shiftder_v3[1]; qlocal[39] = shiftder_v3[2]; + qlocal[31] = shiftder_v1[0]; + qlocal[32] = shiftder_v1[1]; + qlocal[33] = shiftder_v1[2]; + qlocal[34] = shiftder_v2[0]; + qlocal[35] = shiftder_v2[1]; + qlocal[36] = shiftder_v2[2]; + qlocal[37] = shiftder_v3[0]; + qlocal[38] = shiftder_v3[1]; + qlocal[39] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -801,7 +973,7 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta s33[0] = (r31[0] * tau2[0]) + (r32[0] * tau2[1]) + (r33[0] * tau2[2]); s33[1] = (r31[1] * tau2[0]) + (r32[1] * tau2[1]) + (r33[1] * tau2[2]); s33[2] = (r31[2] * tau2[0]) + (r32[2] * tau2[1]) + (r33[2] * tau2[2]); - + // Rotate spatial metric tensor derivative to local coordinate frame. qlocal[40] = (s11[0] * norm[0]) + (s21[0] * norm[1]) + (s31[0] * norm[2]); qlocal[41] = (s11[1] * norm[0]) + (s21[1] * norm[1]) + (s31[1] * norm[2]); @@ -845,9 +1017,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[70] = (qglobal[68] * tau2[0]) + (qglobal[69] * tau2[1]) + (qglobal[70] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; qglobal[1] = (qlocal[1] * norm[0]) + (qlocal[2] * tau1[0]) + (qlocal[3] * tau2[0]); @@ -889,9 +1062,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor back to global coordinate frame. - qglobal[9] = v1[0]; qglobal[10] = v1[1]; qglobal[11] = v1[2]; - qglobal[12] = v2[0]; qglobal[13] = v2[1]; qglobal[14] = v2[2]; - qglobal[15] = v3[0]; qglobal[16] = v3[1]; qglobal[17] = v3[2]; + qglobal[9] = v1[0]; + qglobal[10] = v1[1]; + qglobal[11] = v1[2]; + qglobal[12] = v2[0]; + qglobal[13] = v2[1]; + qglobal[14] = v2[2]; + qglobal[15] = v3[0]; + qglobal[16] = v3[1]; + qglobal[17] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -922,9 +1101,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t inv_v3[2] = (extr_r1[2] * norm[2]) + (extr_r2[2] * tau1[2]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor back to global coordinate frame. - qglobal[18] = inv_v1[0]; qglobal[19] = inv_v1[1]; qglobal[20] = inv_v1[2]; - qglobal[21] = inv_v2[0]; qglobal[22] = inv_v2[1]; qglobal[23] = inv_v2[2]; - qglobal[24] = inv_v3[0]; qglobal[25] = inv_v3[1]; qglobal[26] = inv_v3[2]; + qglobal[18] = inv_v1[0]; + qglobal[19] = inv_v1[1]; + qglobal[20] = inv_v1[2]; + qglobal[21] = inv_v2[0]; + qglobal[22] = inv_v2[1]; + qglobal[23] = inv_v2[2]; + qglobal[24] = inv_v3[0]; + qglobal[25] = inv_v3[1]; + qglobal[26] = inv_v3[2]; qglobal[27] = qlocal[27]; @@ -948,22 +1133,37 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); - shiftder_v1[1] = (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); - shiftder_v1[2] = (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); - shiftder_v2[1] = (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); - shiftder_v2[2] = (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); - shiftder_v3[1] = (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); - shiftder_v3[2] = (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); + shiftder_v1[1] = + (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); + shiftder_v1[2] = + (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); + shiftder_v2[1] = + (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); + shiftder_v2[2] = + (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); + shiftder_v3[1] = + (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); + shiftder_v3[2] = + (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative back to global coordinate frame. - qglobal[31] = shiftder_v1[0]; qglobal[32] = shiftder_v1[1]; qglobal[33] = shiftder_v1[2]; - qglobal[34] = shiftder_v2[0]; qglobal[35] = shiftder_v2[1]; qglobal[36] = shiftder_v2[2]; - qglobal[37] = shiftder_v3[0]; qglobal[38] = shiftder_v3[1]; qglobal[39] = shiftder_v3[2]; + qglobal[31] = shiftder_v1[0]; + qglobal[32] = shiftder_v1[1]; + qglobal[33] = shiftder_v1[2]; + qglobal[34] = shiftder_v2[0]; + qglobal[35] = shiftder_v2[1]; + qglobal[36] = shiftder_v2[2]; + qglobal[37] = shiftder_v3[0]; + qglobal[38] = shiftder_v3[1]; + qglobal[39] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -1090,10 +1290,13 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[70] = (qlocal[68] * norm[2]) + (qlocal[69] * tau1[2]) + (qlocal[70] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); double gas_gamma = gr_euler_tetrad->gas_gamma; double sl = gkyl_gr_euler_tetrad_max_abs_speed(gas_gamma, ql); @@ -1124,8 +1327,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr_gr[i] - fl_gr[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr_gr[i] - fl_gr[i]) / amax); } - } - else { + } else { for (int i = 0; i < 71; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1138,8 +1340,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[71]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1151,26 +1355,33 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); double vl[71], vr[71]; double gas_gamma = gr_euler_tetrad->gas_gamma; - + gkyl_gr_euler_tetrad_prim_vars(gas_gamma, ql, vl); gkyl_gr_euler_tetrad_prim_vars(gas_gamma, qr, vr); @@ -1206,15 +1417,21 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double c_plus = 1.0 + ((gas_gamma / (gas_gamma - 1.0)) * v4); double v_alpha_sq = -(v0 * v0) + (v1 * v1) + (v2 * v2) + (v3 * v3); - double s_sq = (0.5 * gas_gamma * v4 * (1.0 - v_alpha_sq)) - (0.5 * (gas_gamma - 1.0) * (1.0 + v_alpha_sq)); + double s_sq = + (0.5 * gas_gamma * v4 * (1.0 - v_alpha_sq)) - (0.5 * (gas_gamma - 1.0) * (1.0 + v_alpha_sq)); double energy = (v0 * v0) - (v1 * v1); double y = sqrt(((1.0 - (gas_gamma * v4)) * energy) + s_sq); double k = (v0 * delta[4]) - (v1 * delta[1]); double v_delta = (-v0 * delta[4]) + (v1 * delta[1]) + (v2 * delta[2]) + (v3 * delta[3]); - double a1 = -((s_sq * k) + (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[4])) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / (2.0 * energy * s_sq); - double a2 = -((s_sq * k) - (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[4])) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / (2.0 * energy * s_sq); - double a3 = ((2.0 * s_sq * k) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta)))) / (energy * s_sq); + double a1 = -((s_sq * k) + (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[4])) + + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / + (2.0 * energy * s_sq); + double a2 = -((s_sq * k) - (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[4])) + + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / + (2.0 * energy * s_sq); + double a3 = ((2.0 * s_sq * k) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta)))) / + (energy * s_sq); double a4 = delta[2] - ((k * v2) / energy); double a5 = delta[3] - ((k * v3) / energy); @@ -1229,7 +1446,8 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c wv[2] = a1 * v2; wv[3] = a1 * v3; wv[4] = a1 * (v0 - ((sqrt(s_sq) * v1) / y)); - s[0] = (((1.0 - (gas_gamma * v4)) * v0 * v1) - (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); + s[0] = (((1.0 - (gas_gamma * v4)) * v0 * v1) - (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); wv = &waves[1 * 71]; wv[0] = (a3 * (c_minus + (s_sq / (gas_gamma - 1.0)))) - (a4 * c_plus * v2) - (a5 * c_plus * v3); @@ -1245,16 +1463,20 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c wv[2] = a2 * v2; wv[3] = a2 * v3; wv[4] = a2 * (v0 + ((sqrt(s_sq) * v1) / y)); - s[2] = (((1.0 - (gas_gamma * v4)) * v0 * v1) + (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); + s[2] = (((1.0 - (gas_gamma * v4)) * v0 * v1) + (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); - return (((1.0 - (gas_gamma * v4)) * v0 * fabs(v1)) + (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); + return (((1.0 - (gas_gamma * v4)) * v0 * fabs(v1)) + (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v4)) * v0 * v0) + s_sq); } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { - const double* w0 = &waves[0 * 71]; - const double* w1 = &waves[1 * 71]; - const double* w2 = &waves[2 * 71]; + const double *w0 = &waves[0 * 71]; + const double *w1 = &waves[1 * 71]; + const double *w2 = &waves[2 * 71]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]); @@ -1268,32 +1490,37 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co apdq[i] = 0.0; } } -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } } -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); double gas_gamma = gr_euler_tetrad->gas_gamma; double vl[71], vr[71]; @@ -1312,11 +1539,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_zl = vl[8]; double spatial_metric_l[3][3]; - spatial_metric_l[0][0] = vl[9]; spatial_metric_l[0][1] = vl[10]; spatial_metric_l[0][2] = vl[11]; - spatial_metric_l[1][0] = vl[12]; spatial_metric_l[1][1] = vl[13]; spatial_metric_l[1][2] = vl[14]; - spatial_metric_l[2][0] = vl[15]; spatial_metric_l[2][1] = vl[16]; spatial_metric_l[2][2] = vl[17]; - - double **inv_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); + spatial_metric_l[0][0] = vl[9]; + spatial_metric_l[0][1] = vl[10]; + spatial_metric_l[0][2] = vl[11]; + spatial_metric_l[1][0] = vl[12]; + spatial_metric_l[1][1] = vl[13]; + spatial_metric_l[1][2] = vl[14]; + spatial_metric_l[2][0] = vl[15]; + spatial_metric_l[2][1] = vl[16]; + spatial_metric_l[2][2] = vl[17]; + + double **inv_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); } @@ -1335,16 +1568,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_l[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_l = true; } - } - else { + } else { if (fabs(spatial_metric_l[i][j]) > pow(10.0, -8.0)) { curved_spacetime_l = true; } } } } - if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_xl) > pow(10.0, -8.0) || fabs(shift_yl) > pow(10.0, -8.0) || - fabs(shift_zl) > pow(10.0, -8.0)) { + if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_xl) > pow(10.0, -8.0) || + fabs(shift_yl) > pow(10.0, -8.0) || fabs(shift_zl) > pow(10.0, -8.0)) { curved_spacetime_l = true; } @@ -1360,11 +1592,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_zr = vr[8]; double spatial_metric_r[3][3]; - spatial_metric_r[0][0] = vr[9]; spatial_metric_r[0][1] = vr[10]; spatial_metric_r[0][2] = vr[11]; - spatial_metric_r[1][0] = vr[12]; spatial_metric_r[1][1] = vr[13]; spatial_metric_r[1][2] = vr[14]; - spatial_metric_r[2][0] = vr[15]; spatial_metric_r[2][1] = vr[16]; spatial_metric_r[2][2] = vr[17]; - - double **inv_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + spatial_metric_r[0][0] = vr[9]; + spatial_metric_r[0][1] = vr[10]; + spatial_metric_r[0][2] = vr[11]; + spatial_metric_r[1][0] = vr[12]; + spatial_metric_r[1][1] = vr[13]; + spatial_metric_r[1][2] = vr[14]; + spatial_metric_r[2][0] = vr[15]; + spatial_metric_r[2][1] = vr[16]; + spatial_metric_r[2][2] = vr[17]; + + double **inv_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } @@ -1383,16 +1621,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_r[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_r = true; } - } - else { + } else { if (fabs(spatial_metric_l[i][j]) > pow(10.0, -8.0)) { curved_spacetime_r = true; } } } } - if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_xr) > pow(10.0, -8.0) || fabs(shift_yr) > pow(10.0, -8.0) || - fabs(shift_zr) > pow(10.0, -8.0)) { + if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_xr) > pow(10.0, -8.0) || + fabs(shift_yr) > pow(10.0, -8.0) || fabs(shift_zr) > pow(10.0, -8.0)) { curved_spacetime_r = true; } @@ -1412,7 +1649,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (curved_spacetime_l || curved_spacetime_r) { double vel_l[3]; double v_sq_l = 0.0; - vel_l[0] = vx_l; vel_l[1] = vy_l; vel_l[2] = vz_l; + vel_l[0] = vx_l; + vel_l[1] = vy_l; + vel_l[2] = vz_l; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1421,7 +1660,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_l[3]; - shift_l[0] = shift_xl; shift_l[1] = shift_yl; shift_l[2] = shift_zl; + shift_l[0] = shift_xl; + shift_l[1] = shift_yl; + shift_l[2] = shift_zl; double material_eigs_l[3]; double fast_acoustic_eigs_l[3]; @@ -1430,11 +1671,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_l[i] = (lapse_l * vel_l[i]) - shift_l[i]; - fast_acoustic_eigs_l[i] = (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * ((vel_l[i] * (1.0 - (c_sl * c_sl))) + - (c_sl * sqrt((1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl)))))) - shift_l[i]; - - slow_acoustic_eigs_l[i] = (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * ((vel_l[i] * (1.0 - (c_sl * c_sl))) - - (c_sl * sqrt((1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl)))))) - shift_l[i]; + fast_acoustic_eigs_l[i] = + (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * + ((vel_l[i] * (1.0 - (c_sl * c_sl))) + + (c_sl * + sqrt( + (1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - + (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_l[i]; + + slow_acoustic_eigs_l[i] = + (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * + ((vel_l[i] * (1.0 - (c_sl * c_sl))) - + (c_sl * + sqrt( + (1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - + (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_l[i]; } double max_eig_l = 0.0; @@ -1452,7 +1707,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_r[3]; double v_sq_r = 0.0; - vel_r[0] = vx_r; vel_r[1] = vy_r; vel_r[2] = vz_r; + vel_r[0] = vx_r; + vel_r[1] = vy_r; + vel_r[2] = vz_r; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1461,7 +1718,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_r[3]; - shift_r[0] = shift_xr; shift_r[1] = shift_yr; shift_r[2] = shift_zr; + shift_r[0] = shift_xr; + shift_r[1] = shift_yr; + shift_r[2] = shift_zr; double material_eigs_r[3]; double fast_acoustic_eigs_r[3]; @@ -1470,11 +1729,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_r[i] = (lapse_r * vel_r[i]) - shift_r[i]; - fast_acoustic_eigs_r[i] = (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * ((vel_r[i] * (1.0 - (c_sl * c_sl))) + - (c_sl * sqrt((1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl)))))) - shift_r[i]; - - slow_acoustic_eigs_r[i] = (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * ((vel_r[i] * (1.0 - (c_sl * c_sl))) - - (c_sl * sqrt((1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl)))))) - shift_r[i]; + fast_acoustic_eigs_r[i] = + (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * + ((vel_r[i] * (1.0 - (c_sl * c_sl))) + + (c_sl * + sqrt( + (1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - + (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_r[i]; + + slow_acoustic_eigs_r[i] = + (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * + ((vel_r[i] * (1.0 - (c_sl * c_sl))) - + (c_sl * + sqrt( + (1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - + (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_r[i]; } double max_eig_r = 0.0; @@ -1491,11 +1764,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double max_eig_avg = 0.5 * (max_eig_l + max_eig_r); - + sl = (vx_avg - max_eig_avg) / (1.0 - (vx_avg * max_eig_avg)); sr = (vx_avg + max_eig_avg) / (1.0 + (vx_avg * max_eig_avg)); - } - else { + } else { sl = (vx_avg - cs_avg) / (1.0 - (vx_avg * cs_avg)); sr = (vx_avg + cs_avg) / (1.0 + (vx_avg * cs_avg)); } @@ -1519,8 +1791,7 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = qm[i] - ql[i]; w1[i] = qr[i] - qm[i]; } - } - else { + } else { for (int i = 0; i < 71; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1540,8 +1811,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return fmax(fabs(sl), fabs(sr)); } -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[71]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1553,35 +1826,38 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hll(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_hll(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); double gas_gamma = gr_euler_tetrad->gas_gamma; double fr_sr[71], fl_sr[71]; @@ -1606,8 +1882,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 71; m++) { flux_jump[m] = fr_gr[m] - fl_gr[m]; } - } - else { + } else { for (int m = 0; m < 71; m++) { flux_jump[m] = 0.0; } @@ -1619,34 +1894,33 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); double gas_gamma = gr_euler_tetrad->gas_gamma; - double v[71] = { 0.0 }; + double v[71] = {0.0}; gkyl_gr_euler_tetrad_prim_vars(gas_gamma, q, v); if (v[0] < 0.0 || v[4] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); double gas_gamma = gr_euler_tetrad->gas_gamma; return gkyl_gr_euler_tetrad_max_abs_speed(gas_gamma, q); } static inline void -gr_euler_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +gr_euler_tetrad_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 5; i++) { diag[i] = qin[i]; @@ -1654,12 +1928,13 @@ gr_euler_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, d } static inline void -gr_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +gr_euler_tetrad_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); double gas_gamma = gr_euler_tetrad->gas_gamma; - double v[71] = { 0.0 }; + double v[71] = {0.0}; gkyl_gr_euler_tetrad_prim_vars(gas_gamma, qin, v); double rho = v[0]; double vx = v[1]; @@ -1673,14 +1948,26 @@ gr_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* double shift_z = v[8]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[9]; spatial_metric[0][1] = v[10]; spatial_metric[0][2] = v[11]; - spatial_metric[1][0] = v[12]; spatial_metric[1][1] = v[13]; spatial_metric[1][2] = v[14]; - spatial_metric[2][0] = v[15]; spatial_metric[2][1] = v[16]; spatial_metric[2][2] = v[17]; + spatial_metric[0][0] = v[9]; + spatial_metric[0][1] = v[10]; + spatial_metric[0][2] = v[11]; + spatial_metric[1][0] = v[12]; + spatial_metric[1][1] = v[13]; + spatial_metric[1][2] = v[14]; + spatial_metric[2][0] = v[15]; + spatial_metric[2][1] = v[16]; + spatial_metric[2][2] = v[17]; double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = v[18]; extrinsic_curvature[0][1] = v[19]; extrinsic_curvature[0][2] = v[20]; - extrinsic_curvature[1][0] = v[21]; extrinsic_curvature[1][1] = v[22]; extrinsic_curvature[1][2] = v[23]; - extrinsic_curvature[2][0] = v[24]; extrinsic_curvature[2][1] = v[25]; extrinsic_curvature[2][2] = v[26]; + extrinsic_curvature[0][0] = v[18]; + extrinsic_curvature[0][1] = v[19]; + extrinsic_curvature[0][2] = v[20]; + extrinsic_curvature[1][0] = v[21]; + extrinsic_curvature[1][1] = v[22]; + extrinsic_curvature[1][2] = v[23]; + extrinsic_curvature[2][0] = v[24]; + extrinsic_curvature[2][1] = v[25]; + extrinsic_curvature[2][2] = v[26]; double lapse_der[3]; lapse_der[0] = v[28]; @@ -1688,24 +1975,48 @@ gr_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* lapse_der[2] = v[30]; double shift_der[3][3]; - shift_der[0][0] = v[31]; shift_der[0][1] = v[32]; shift_der[0][2] = v[33]; - shift_der[1][0] = v[34]; shift_der[1][1] = v[35]; shift_der[1][2] = v[36]; - shift_der[2][0] = v[37]; shift_der[2][1] = v[38]; shift_der[2][2] = v[39]; + shift_der[0][0] = v[31]; + shift_der[0][1] = v[32]; + shift_der[0][2] = v[33]; + shift_der[1][0] = v[34]; + shift_der[1][1] = v[35]; + shift_der[1][2] = v[36]; + shift_der[2][0] = v[37]; + shift_der[2][1] = v[38]; + shift_der[2][2] = v[39]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = v[40]; spatial_metric_der[0][0][1] = v[41]; spatial_metric_der[0][0][2] = v[42]; - spatial_metric_der[0][1][0] = v[43]; spatial_metric_der[0][1][1] = v[44]; spatial_metric_der[0][1][2] = v[45]; - spatial_metric_der[0][2][0] = v[46]; spatial_metric_der[0][2][1] = v[47]; spatial_metric_der[0][2][2] = v[48]; - - spatial_metric_der[1][0][0] = v[49]; spatial_metric_der[1][0][1] = v[50]; spatial_metric_der[1][0][2] = v[51]; - spatial_metric_der[1][1][0] = v[52]; spatial_metric_der[1][1][1] = v[53]; spatial_metric_der[1][1][2] = v[54]; - spatial_metric_der[1][2][0] = v[55]; spatial_metric_der[1][2][1] = v[56]; spatial_metric_der[1][2][2] = v[57]; - - spatial_metric_der[0][0][0] = v[58]; spatial_metric_der[0][0][1] = v[59]; spatial_metric_der[0][0][2] = v[60]; - spatial_metric_der[0][1][0] = v[61]; spatial_metric_der[0][1][1] = v[62]; spatial_metric_der[0][1][2] = v[63]; - spatial_metric_der[0][2][0] = v[64]; spatial_metric_der[0][2][1] = v[65]; spatial_metric_der[0][2][2] = v[66]; - - double **stress_energy = gkyl_malloc(sizeof(double*[4])); + spatial_metric_der[0][0][0] = v[40]; + spatial_metric_der[0][0][1] = v[41]; + spatial_metric_der[0][0][2] = v[42]; + spatial_metric_der[0][1][0] = v[43]; + spatial_metric_der[0][1][1] = v[44]; + spatial_metric_der[0][1][2] = v[45]; + spatial_metric_der[0][2][0] = v[46]; + spatial_metric_der[0][2][1] = v[47]; + spatial_metric_der[0][2][2] = v[48]; + + spatial_metric_der[1][0][0] = v[49]; + spatial_metric_der[1][0][1] = v[50]; + spatial_metric_der[1][0][2] = v[51]; + spatial_metric_der[1][1][0] = v[52]; + spatial_metric_der[1][1][1] = v[53]; + spatial_metric_der[1][1][2] = v[54]; + spatial_metric_der[1][2][0] = v[55]; + spatial_metric_der[1][2][1] = v[56]; + spatial_metric_der[1][2][2] = v[57]; + + spatial_metric_der[0][0][0] = v[58]; + spatial_metric_der[0][0][1] = v[59]; + spatial_metric_der[0][0][2] = v[60]; + spatial_metric_der[0][1][0] = v[61]; + spatial_metric_der[0][1][1] = v[62]; + spatial_metric_der[0][1][2] = v[63]; + spatial_metric_der[0][2][0] = v[64]; + spatial_metric_der[0][2][1] = v[65]; + spatial_metric_der[0][2][2] = v[66]; + + double **stress_energy = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { stress_energy[i] = gkyl_malloc(sizeof(double[4])); } @@ -1719,11 +2030,15 @@ gr_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* if (!in_excision_region) { double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1737,7 +2052,7 @@ gr_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* } double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); - + double mom[3]; mom[0] = (rho * h) * (W * W) * vx; mom[1] = (rho * h) * (W * W) * vy; @@ -1762,7 +2077,8 @@ gr_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - sout[1 + j] += 0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]; + sout[1 + j] += + 0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]; sout[1 + j] += 0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]; } @@ -1773,8 +2089,7 @@ gr_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* } } } - } - else { + } else { for (int i = 0; i < 71; i++) { sout[i] = 0.0; } @@ -1786,14 +2101,14 @@ gr_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* gkyl_free(stress_energy); } -void -gkyl_gr_euler_tetrad_free(const struct gkyl_ref_count* ref) +void gkyl_gr_euler_tetrad_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. - struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(base->on_dev, struct wv_gr_euler_tetrad, eqn); + struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(base->on_dev, struct wv_gr_euler_tetrad, eqn); gkyl_cu_free(gr_euler_tetrad); } @@ -1801,22 +2116,21 @@ gkyl_gr_euler_tetrad_free(const struct gkyl_ref_count* ref) gkyl_free(gr_euler_tetrad); } -struct gkyl_wv_eqn* -gkyl_wv_gr_euler_tetrad_new(double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_gr_euler_tetrad_new( + double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, + struct gkyl_gr_spacetime *spacetime, bool use_gpu +) { - return gkyl_wv_gr_euler_tetrad_inew(&(struct gkyl_wv_gr_euler_tetrad_inp) { - .gas_gamma = gas_gamma, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .spacetime = spacetime, - .rp_type = WV_GR_EULER_TETRAD_RP_HLL, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_gr_euler_tetrad_inew(&(struct gkyl_wv_gr_euler_tetrad_inp + ){.gas_gamma = gas_gamma, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .spacetime = spacetime, + .rp_type = WV_GR_EULER_TETRAD_RP_HLL, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_gr_euler_tetrad_inew(const struct gkyl_wv_gr_euler_tetrad_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_gr_euler_tetrad_inew(const struct gkyl_wv_gr_euler_tetrad_inp *inp) { struct wv_gr_euler_tetrad *gr_euler_tetrad = gkyl_malloc(sizeof(struct wv_gr_euler_tetrad)); @@ -1833,13 +2147,11 @@ gkyl_wv_gr_euler_tetrad_inew(const struct gkyl_wv_gr_euler_tetrad_inp* inp) gr_euler_tetrad->eqn.num_waves = 2; gr_euler_tetrad->eqn.waves_func = wave_lax_l; gr_euler_tetrad->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_GR_EULER_TETRAD_RP_ROE) { + } else if (inp->rp_type == WV_GR_EULER_TETRAD_RP_ROE) { gr_euler_tetrad->eqn.num_waves = 3; gr_euler_tetrad->eqn.waves_func = wave_roe_l; gr_euler_tetrad->eqn.qfluct_func = qfluct_roe_l; - } - else if (inp->rp_type == WV_GR_EULER_TETRAD_RP_HLL) { + } else if (inp->rp_type == WV_GR_EULER_TETRAD_RP_HLL) { gr_euler_tetrad->eqn.num_waves = 2; gr_euler_tetrad->eqn.waves_func = wave_hll_l; gr_euler_tetrad->eqn.qfluct_func = qfluct_hll_l; @@ -1864,44 +2176,45 @@ gkyl_wv_gr_euler_tetrad_inew(const struct gkyl_wv_gr_euler_tetrad_inp* inp) gr_euler_tetrad->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(gr_euler_tetrad->eqn.flags); gr_euler_tetrad->eqn.ref_count = gkyl_ref_count_init(gkyl_gr_euler_tetrad_free); - gr_euler_tetrad->eqn.on_dev = &gr_euler_tetrad->eqn; // On the CPU, the equation object points to itself. + gr_euler_tetrad->eqn.on_dev = + &gr_euler_tetrad->eqn; // On the CPU, the equation object points to itself. gr_euler_tetrad->eqn.embed_geo = NULL; return &gr_euler_tetrad->eqn; } -double -gkyl_wv_gr_euler_tetrad_gas_gamma(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_euler_tetrad_gas_gamma(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); double gas_gamma = gr_euler_tetrad->gas_gamma; return gas_gamma; } -enum gkyl_spacetime_gauge -gkyl_wv_gr_euler_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn) +enum gkyl_spacetime_gauge gkyl_wv_gr_euler_tetrad_spacetime_gauge(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); enum gkyl_spacetime_gauge spacetime_gauge = gr_euler_tetrad->spacetime_gauge; return spacetime_gauge; } -int -gkyl_wv_gr_euler_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_gr_euler_tetrad_reinit_freq(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); int reinit_freq = gr_euler_tetrad->reinit_freq; return reinit_freq; } -struct gkyl_gr_spacetime* -gkyl_wv_gr_euler_tetrad_spacetime(const struct gkyl_wv_eqn* eqn) +struct gkyl_gr_spacetime *gkyl_wv_gr_euler_tetrad_spacetime(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_euler_tetrad *gr_euler_tetrad = container_of(eqn, struct wv_gr_euler_tetrad, eqn); + const struct wv_gr_euler_tetrad *gr_euler_tetrad = + container_of(eqn, struct wv_gr_euler_tetrad, eqn); struct gkyl_gr_spacetime *spacetime = gr_euler_tetrad->spacetime; return spacetime; diff --git a/moments/zero/wv_gr_maxwell.c b/moments/zero/wv_gr_maxwell.c index 451cae09c1..6169aa405b 100644 --- a/moments/zero/wv_gr_maxwell.c +++ b/moments/zero/wv_gr_maxwell.c @@ -6,8 +6,9 @@ #include #include -void -gkyl_gr_maxwell_flux(double light_speed, double e_fact, double b_fact, const double q[26], double flux[26]) +void gkyl_gr_maxwell_flux( + double light_speed, double e_fact, double b_fact, const double q[26], double flux[26] +) { double Dx = q[0], Dy = q[1], Dz = q[2]; double Bx = q[3], By = q[4], Bz = q[5]; @@ -46,16 +47,14 @@ gkyl_gr_maxwell_flux(double light_speed, double e_fact, double b_fact, const dou for (int i = 8; i < 26; i++) { flux[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 26; i++) { flux[i] = 0.0; } } } -static inline double -gkyl_gr_maxwell_max_abs_speed(double light_speed, const double q[26]) +static inline double gkyl_gr_maxwell_max_abs_speed(double light_speed, const double q[26]) { bool in_excision_region = false; if (q[21] < pow(10.0, -8.0)) { @@ -66,23 +65,32 @@ gkyl_gr_maxwell_max_abs_speed(double light_speed, const double q[26]) double lapse = q[8]; double spatial_metric[3][3]; - spatial_metric[0][0] = q[12]; spatial_metric[0][1] = q[13]; spatial_metric[0][2] = q[14]; - spatial_metric[1][0] = q[15]; spatial_metric[1][1] = q[16]; spatial_metric[1][2] = q[17]; - spatial_metric[2][0] = q[18]; spatial_metric[2][1] = q[19]; spatial_metric[2][2] = q[20]; - - double spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + spatial_metric[0][0] = q[12]; + spatial_metric[0][1] = q[13]; + spatial_metric[0][2] = q[14]; + spatial_metric[1][0] = q[15]; + spatial_metric[1][1] = q[16]; + spatial_metric[1][2] = q[17]; + spatial_metric[2][0] = q[18]; + spatial_metric[2][1] = q[19]; + spatial_metric[2][2] = q[20]; + + double spatial_metric_det = + (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); return light_speed * sqrt(spatial_metric_det) * lapse; - } - else { + } else { return pow(10.0, -8.0); } } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 26; i++) { @@ -91,7 +99,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 26; i++) { @@ -99,8 +107,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -gr_maxwell_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_maxwell_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { // Zero tangent for the electric field. ghost[0] = skin[0]; @@ -121,11 +131,12 @@ gr_maxwell_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* s } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { - // Rotate electric field vector to local coordinates. + // Rotate electric field vector to local coordinates. qlocal[0] = (qglobal[0] * norm[0]) + (qglobal[1] * norm[1]) + (qglobal[2] * norm[2]); qlocal[1] = (qglobal[0] * tau1[0]) + (qglobal[1] * tau1[1]) + (qglobal[2] * tau1[2]); qlocal[2] = (qglobal[0] * tau2[0]) + (qglobal[1] * tau2[1]) + (qglobal[2] * tau2[2]); @@ -176,9 +187,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinates. - qlocal[12] = v1[0]; qlocal[13] = v1[1]; qlocal[14] = v1[2]; - qlocal[15] = v2[0]; qlocal[16] = v2[1]; qlocal[17] = v2[2]; - qlocal[18] = v3[0]; qlocal[19] = v3[1]; qlocal[20] = v3[2]; + qlocal[12] = v1[0]; + qlocal[13] = v1[1]; + qlocal[14] = v1[2]; + qlocal[15] = v2[0]; + qlocal[16] = v2[1]; + qlocal[17] = v2[2]; + qlocal[18] = v3[0]; + qlocal[19] = v3[1]; + qlocal[20] = v3[2]; // Excision parameter is a scalar (so remains unchanged). qlocal[21] = qglobal[21]; @@ -189,9 +206,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[25] = (qglobal[23] * tau2[0]) + (qglobal[24] * tau2[1]) + (qglobal[25] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { // Rotate electric field vector to global coordinates. qglobal[0] = (qlocal[0] * norm[0]) + (qlocal[1] * tau1[0]) + (qlocal[2] * tau2[0]); @@ -244,9 +262,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to global coordinates. - qglobal[12] = v1[0]; qglobal[13] = v1[1]; qglobal[14] = v1[2]; - qglobal[15] = v2[0]; qglobal[16] = v2[1]; qglobal[17] = v2[2]; - qglobal[18] = v3[0]; qglobal[19] = v3[1]; qglobal[20] = v3[2]; + qglobal[12] = v1[0]; + qglobal[13] = v1[1]; + qglobal[14] = v1[2]; + qglobal[15] = v2[0]; + qglobal[16] = v2[1]; + qglobal[17] = v2[2]; + qglobal[18] = v3[0]; + qglobal[19] = v3[1]; + qglobal[20] = v3[2]; // Excision parameter is a scalar (so remains unchanged). qglobal[21] = qlocal[21]; @@ -257,8 +281,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[25] = (qlocal[23] * norm[2]) + (qlocal[24] * tau1[2]) + (qlocal[25] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_maxwell *gr_maxwell = container_of(eqn, struct wv_gr_maxwell, eqn); double light_speed = gr_maxwell->light_speed; @@ -289,8 +315,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr[i] - fl[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr[i] - fl[i]) / amax); } - } - else { + } else { for (int i = 0; i < 26; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -303,8 +328,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[26]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -316,21 +343,27 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_maxwell *gr_maxwell = container_of(eqn, struct wv_gr_maxwell, eqn); double light_speed = gr_maxwell->light_speed; @@ -350,7 +383,7 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c waves[i] = 0.0; } - double *wv ; + double *wv; wv = &waves[0 * 26]; wv[3] = a1; wv[7] = -a1 * light_speed; @@ -388,8 +421,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return light_speed; } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0 * 26], *w1 = &waves[1 * 26], *w2 = &waves[2 * 26]; const double *w3 = &waves[3 * 26], *w4 = &waves[4 * 26], *w5 = &waves[5 * 26]; @@ -401,38 +436,42 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co double s3p = fmax(0.0, s[3]), s4p = fmax(0.0, s[4]), s5p = fmax(0.0, s[5]); for (int i = 0; i < 26; i++) { - amdq[i] = (s0m * w0[i]) + (s1m * w1[i]) + (s2m * w2[i]) + (s3m * w3[i]) + (s4m * w4[i]) + (s5m * w5[i]); - apdq[i] = (s0p * w0[i]) + (s1p * w1[i]) + (s2p * w2[i]) + (s3p * w3[i]) + (s4p * w4[i]) + (s5p * w5[i]); + amdq[i] = + (s0m * w0[i]) + (s1m * w1[i]) + (s2m * w2[i]) + (s3m * w3[i]) + (s4m * w4[i]) + (s5m * w5[i]); + apdq[i] = + (s0p * w0[i]) + (s1p * w1[i]) + (s2p * w2[i]) + (s3p * w3[i]) + (s4p * w4[i]) + (s5p * w5[i]); } } -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_gr_maxwell *gr_maxwell = container_of(eqn, struct wv_gr_maxwell, eqn); const double light_speed = gr_maxwell->light_speed; @@ -457,8 +496,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 26; m++) { flux_jump[m] = fr[m] - fl[m]; } - } - else { + } else { for (int m = 0; m < 26; m++) { flux_jump[m] = 0.0; } @@ -470,15 +508,13 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { // No invalid states for general relativistic Maxwell. return true; } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_gr_maxwell *gr_maxwell = container_of(eqn, struct wv_gr_maxwell, eqn); double light_speed = gr_maxwell->light_speed; @@ -487,25 +523,23 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) } static inline void -gr_maxwell_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +gr_maxwell_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 8; i++) { diag[i] = qin[i]; } } -static inline void -gr_maxwell_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void gr_maxwell_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < 26; i++) { sout[i] = 0.0; } } -void -gkyl_gr_maxwell_free(const struct gkyl_ref_count* ref) +void gkyl_gr_maxwell_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. @@ -517,24 +551,23 @@ gkyl_gr_maxwell_free(const struct gkyl_ref_count* ref) gkyl_free(gr_maxwell); } -struct gkyl_wv_eqn* -gkyl_wv_gr_maxwell_new(double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_gr_maxwell_new( + double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, + int reinit_freq, struct gkyl_gr_spacetime *spacetime, bool use_gpu +) { - return gkyl_wv_gr_maxwell_inew(&(struct gkyl_wv_gr_maxwell_inp) { - .light_speed = light_speed, - .e_fact = e_fact, - .b_fact = b_fact, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .spacetime = spacetime, - .rp_type = WV_GR_MAXWELL_RP_ROE, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_gr_maxwell_inew(&(struct gkyl_wv_gr_maxwell_inp + ){.light_speed = light_speed, + .e_fact = e_fact, + .b_fact = b_fact, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .spacetime = spacetime, + .rp_type = WV_GR_MAXWELL_RP_ROE, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_gr_maxwell_inew(const struct gkyl_wv_gr_maxwell_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_gr_maxwell_inew(const struct gkyl_wv_gr_maxwell_inp *inp) { struct wv_gr_maxwell *gr_maxwell = gkyl_malloc(sizeof(struct wv_gr_maxwell)); @@ -553,8 +586,7 @@ gkyl_wv_gr_maxwell_inew(const struct gkyl_wv_gr_maxwell_inp* inp) gr_maxwell->eqn.num_waves = 2; gr_maxwell->eqn.waves_func = wave_lax_l; gr_maxwell->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_GR_MAXWELL_RP_ROE) { + } else if (inp->rp_type == WV_GR_MAXWELL_RP_ROE) { gr_maxwell->eqn.num_waves = 6; gr_maxwell->eqn.waves_func = wave_roe_l; gr_maxwell->eqn.qfluct_func = qfluct_roe_l; @@ -585,8 +617,7 @@ gkyl_wv_gr_maxwell_inew(const struct gkyl_wv_gr_maxwell_inp* inp) return &gr_maxwell->eqn; } -double -gkyl_wv_gr_maxwell_light_speed(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_maxwell_light_speed(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_maxwell *gr_maxwell = container_of(eqn, struct wv_gr_maxwell, eqn); double light_speed = gr_maxwell->light_speed; @@ -594,8 +625,7 @@ gkyl_wv_gr_maxwell_light_speed(const struct gkyl_wv_eqn* eqn) return light_speed; } -double -gkyl_wv_gr_maxwell_e_fact(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_maxwell_e_fact(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_maxwell *gr_maxwell = container_of(eqn, struct wv_gr_maxwell, eqn); double e_fact = gr_maxwell->e_fact; @@ -603,8 +633,7 @@ gkyl_wv_gr_maxwell_e_fact(const struct gkyl_wv_eqn* eqn) return e_fact; } -double -gkyl_wv_gr_maxwell_b_fact(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_maxwell_b_fact(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_maxwell *gr_maxwell = container_of(eqn, struct wv_gr_maxwell, eqn); double b_fact = gr_maxwell->b_fact; @@ -612,8 +641,7 @@ gkyl_wv_gr_maxwell_b_fact(const struct gkyl_wv_eqn* eqn) return b_fact; } -enum gkyl_spacetime_gauge -gkyl_wv_gr_maxwell_spacetime_gauge(const struct gkyl_wv_eqn* eqn) +enum gkyl_spacetime_gauge gkyl_wv_gr_maxwell_spacetime_gauge(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_maxwell *gr_maxwell = container_of(eqn, struct wv_gr_maxwell, eqn); enum gkyl_spacetime_gauge spacetime_gauge = gr_maxwell->spacetime_gauge; @@ -621,8 +649,7 @@ gkyl_wv_gr_maxwell_spacetime_gauge(const struct gkyl_wv_eqn* eqn) return spacetime_gauge; } -int -gkyl_wv_gr_maxwell_reinit_freq(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_gr_maxwell_reinit_freq(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_maxwell *gr_maxwell = container_of(eqn, struct wv_gr_maxwell, eqn); int reinit_freq = gr_maxwell->reinit_freq; @@ -630,8 +657,7 @@ gkyl_wv_gr_maxwell_reinit_freq(const struct gkyl_wv_eqn* eqn) return reinit_freq; } -struct gkyl_gr_spacetime* -gkyl_wv_gr_maxwell_spacetime(const struct gkyl_wv_eqn* eqn) +struct gkyl_gr_spacetime *gkyl_wv_gr_maxwell_spacetime(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_maxwell *gr_maxwell = container_of(eqn, struct wv_gr_maxwell, eqn); struct gkyl_gr_spacetime *spacetime = gr_maxwell->spacetime; diff --git a/moments/zero/wv_gr_maxwell_tetrad.c b/moments/zero/wv_gr_maxwell_tetrad.c index 87d59e1452..de77435543 100644 --- a/moments/zero/wv_gr_maxwell_tetrad.c +++ b/moments/zero/wv_gr_maxwell_tetrad.c @@ -6,8 +6,9 @@ #include #include -void -gkyl_gr_maxwell_tetrad_flux(double light_speed, double e_fact, double b_fact, const double q[26], double flux[26]) +void gkyl_gr_maxwell_tetrad_flux( + double light_speed, double e_fact, double b_fact, const double q[26], double flux[26] +) { double Ex = q[0], Ey = q[1], Ez = q[2]; double Bx = q[3], By = q[4], Bz = q[5]; @@ -33,16 +34,17 @@ gkyl_gr_maxwell_tetrad_flux(double light_speed, double e_fact, double b_fact, co for (int i = 8; i < 26; i++) { flux[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 26; i++) { flux[i] = 0.0; } } } -void -gkyl_gr_maxwell_tetrad_flux_correction(double light_speed, double e_fact, double b_fact, const double q[26], const double flux_sr[26], double flux_gr[26]) +void gkyl_gr_maxwell_tetrad_flux_correction( + double light_speed, double e_fact, double b_fact, const double q[26], const double flux_sr[26], + double flux_gr[26] +) { // The flux transformation is _almost_ purely geometrical, but requires knowledge of Ex and Bx for hyperbolic divergence cleaning. double Ex = q[0]; @@ -60,27 +62,29 @@ gkyl_gr_maxwell_tetrad_flux_correction(double light_speed, double e_fact, double if (!in_excision_region) { flux_gr[0] = flux_sr[0]; - flux_gr[1] = (lapse * flux_sr[1]) - (light_speed * light_speed) * ((shift_x * flux_sr[5]) - (shift_y * Ex)); - flux_gr[2] = (lapse * flux_sr[2]) + (light_speed * light_speed) * ((shift_x * flux_sr[4]) + (shift_z * Ex)); + flux_gr[1] = (lapse * flux_sr[1]) - + (light_speed * light_speed) * ((shift_x * flux_sr[5]) - (shift_y * Ex)); + flux_gr[2] = (lapse * flux_sr[2]) + + (light_speed * light_speed) * ((shift_x * flux_sr[4]) + (shift_z * Ex)); flux_gr[3] = flux_sr[3]; - flux_gr[4] = (lapse * flux_sr[4]) + ((shift_x * (flux_sr[2] / (light_speed * light_speed))) + (shift_y * Bx)); - flux_gr[5] = (lapse * flux_sr[5]) - ((shift_x * (flux_sr[1] / (light_speed * light_speed))) - (shift_z * Bx)); + flux_gr[4] = (lapse * flux_sr[4]) + + ((shift_x * (flux_sr[2] / (light_speed * light_speed))) + (shift_y * Bx)); + flux_gr[5] = (lapse * flux_sr[5]) - + ((shift_x * (flux_sr[1] / (light_speed * light_speed))) - (shift_z * Bx)); flux_gr[6] = flux_sr[6]; flux_gr[7] = flux_sr[7]; for (int i = 8; i < 26; i++) { flux_gr[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 26; i++) { flux_gr[i] = 0.0; } } } -static inline double -gkyl_gr_maxwell_tetrad_max_abs_speed(double light_speed, const double q[26]) +static inline double gkyl_gr_maxwell_tetrad_max_abs_speed(double light_speed, const double q[26]) { bool in_excision_region = false; if (q[21] < pow(10.0, -8.0)) { @@ -91,23 +95,32 @@ gkyl_gr_maxwell_tetrad_max_abs_speed(double light_speed, const double q[26]) double lapse = q[8]; double spatial_metric[3][3]; - spatial_metric[0][0] = q[12]; spatial_metric[0][1] = q[13]; spatial_metric[0][2] = q[14]; - spatial_metric[1][0] = q[15]; spatial_metric[1][1] = q[16]; spatial_metric[1][2] = q[17]; - spatial_metric[2][0] = q[18]; spatial_metric[2][1] = q[19]; spatial_metric[2][2] = q[20]; - - double spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + spatial_metric[0][0] = q[12]; + spatial_metric[0][1] = q[13]; + spatial_metric[0][2] = q[14]; + spatial_metric[1][0] = q[15]; + spatial_metric[1][1] = q[16]; + spatial_metric[1][2] = q[17]; + spatial_metric[2][0] = q[18]; + spatial_metric[2][1] = q[19]; + spatial_metric[2][2] = q[20]; + + double spatial_metric_det = + (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); return light_speed * sqrt(spatial_metric_det) * lapse; - } - else { + } else { return pow(10.0, -8.0); } } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 26; i++) { @@ -116,7 +129,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 26; i++) { @@ -124,8 +137,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -gr_maxwell_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_maxwell_tetrad_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { // Zero tangent for the electric field. ghost[0] = skin[0]; @@ -146,11 +161,12 @@ gr_maxwell_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const do } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { - // Rotate electric field vector to local coordinates. + // Rotate electric field vector to local coordinates. qlocal[0] = (qglobal[0] * norm[0]) + (qglobal[1] * norm[1]) + (qglobal[2] * norm[2]); qlocal[1] = (qglobal[0] * tau1[0]) + (qglobal[1] * tau1[1]) + (qglobal[2] * tau1[2]); qlocal[2] = (qglobal[0] * tau2[0]) + (qglobal[1] * tau2[1]) + (qglobal[2] * tau2[2]); @@ -201,9 +217,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinates. - qlocal[12] = v1[0]; qlocal[13] = v1[1]; qlocal[14] = v1[2]; - qlocal[15] = v2[0]; qlocal[16] = v2[1]; qlocal[17] = v2[2]; - qlocal[18] = v3[0]; qlocal[19] = v3[1]; qlocal[20] = v3[2]; + qlocal[12] = v1[0]; + qlocal[13] = v1[1]; + qlocal[14] = v1[2]; + qlocal[15] = v2[0]; + qlocal[16] = v2[1]; + qlocal[17] = v2[2]; + qlocal[18] = v3[0]; + qlocal[19] = v3[1]; + qlocal[20] = v3[2]; // Excision parameter is a scalar (so remains unchanged). qlocal[21] = qglobal[21]; @@ -214,9 +236,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[25] = (qglobal[23] * tau2[0]) + (qglobal[24] * tau2[1]) + (qglobal[25] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { // Rotate electric field vector to global coordinates. qglobal[0] = (qlocal[0] * norm[0]) + (qlocal[1] * tau1[0]) + (qlocal[2] * tau2[0]); @@ -269,9 +292,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to global coordinates. - qglobal[12] = v1[0]; qglobal[13] = v1[1]; qglobal[14] = v1[2]; - qglobal[15] = v2[0]; qglobal[16] = v2[1]; qglobal[17] = v2[2]; - qglobal[18] = v3[0]; qglobal[19] = v3[1]; qglobal[20] = v3[2]; + qglobal[12] = v1[0]; + qglobal[13] = v1[1]; + qglobal[14] = v1[2]; + qglobal[15] = v2[0]; + qglobal[16] = v2[1]; + qglobal[17] = v2[2]; + qglobal[18] = v3[0]; + qglobal[19] = v3[1]; + qglobal[20] = v3[2]; // Excision parameter is a scalar (so remains unchanged). qglobal[21] = qlocal[21]; @@ -282,10 +311,13 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[25] = (qlocal[23] * norm[2]) + (qlocal[24] * tau1[2]) + (qlocal[25] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); + const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); double light_speed = gr_maxwell_tetrad->light_speed; double e_fact = gr_maxwell_tetrad->e_fact; double b_fact = gr_maxwell_tetrad->b_fact; @@ -318,8 +350,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr_gr[i] - fl_gr[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr_gr[i] - fl_gr[i]) / amax); } - } - else { + } else { for (int i = 0; i < 26; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -332,8 +363,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[26]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -345,23 +378,30 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); + const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); double light_speed = gr_maxwell_tetrad->light_speed; double e_fact = gr_maxwell_tetrad->e_fact; double b_fact = gr_maxwell_tetrad->b_fact; @@ -379,7 +419,7 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c waves[i] = 0.0; } - double *wv ; + double *wv; wv = &waves[0 * 26]; wv[3] = a1; wv[7] = -a1 * light_speed; @@ -417,8 +457,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return light_speed; } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0 * 26], *w1 = &waves[1 * 26], *w2 = &waves[2 * 26]; const double *w3 = &waves[3 * 26], *w4 = &waves[4 * 26], *w5 = &waves[5 * 26]; @@ -430,40 +472,45 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co double s3p = fmax(0.0, s[3]), s4p = fmax(0.0, s[4]), s5p = fmax(0.0, s[5]); for (int i = 0; i < 26; i++) { - amdq[i] = (s0m * w0[i]) + (s1m * w1[i]) + (s2m * w2[i]) + (s3m * w3[i]) + (s4m * w4[i]) + (s5m * w5[i]); - apdq[i] = (s0p * w0[i]) + (s1p * w1[i]) + (s2p * w2[i]) + (s3p * w3[i]) + (s4p * w4[i]) + (s5p * w5[i]); + amdq[i] = + (s0m * w0[i]) + (s1m * w1[i]) + (s2m * w2[i]) + (s3m * w3[i]) + (s4m * w4[i]) + (s5m * w5[i]); + apdq[i] = + (s0p * w0[i]) + (s1p * w1[i]) + (s2p * w2[i]) + (s3p * w3[i]) + (s4p * w4[i]) + (s5p * w5[i]); } } -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { - const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); + const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); const double light_speed = gr_maxwell_tetrad->light_speed; const double e_fact = gr_maxwell_tetrad->e_fact; const double b_fact = gr_maxwell_tetrad->b_fact; @@ -490,8 +537,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 26; m++) { flux_jump[m] = fr_gr[m] - fl_gr[m]; } - } - else { + } else { for (int m = 0; m < 26; m++) { flux_jump[m] = 0.0; } @@ -503,24 +549,23 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { // No invalid states for general relativistic Maxwell in the tetrad basis. return true; } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); + const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); double light_speed = gr_maxwell_tetrad->light_speed; return gkyl_gr_maxwell_tetrad_max_abs_speed(light_speed, q); } static inline void -gr_maxwell_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +gr_maxwell_tetrad_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 8; i++) { diag[i] = qin[i]; @@ -528,46 +573,46 @@ gr_maxwell_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, } static inline void -gr_maxwell_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +gr_maxwell_tetrad_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < 26; i++) { sout[i] = 0.0; } } -void -gkyl_gr_maxwell_tetrad_free(const struct gkyl_ref_count* ref) +void gkyl_gr_maxwell_tetrad_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. - struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(base->on_dev, struct wv_gr_maxwell_tetrad, eqn); + struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(base->on_dev, struct wv_gr_maxwell_tetrad, eqn); gkyl_cu_free(gr_maxwell_tetrad); } - struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(base, struct wv_gr_maxwell_tetrad, eqn); + struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(base, struct wv_gr_maxwell_tetrad, eqn); gkyl_free(gr_maxwell_tetrad); } -struct gkyl_wv_eqn* -gkyl_wv_gr_maxwell_tetrad_new(double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_gr_maxwell_tetrad_new( + double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, + int reinit_freq, struct gkyl_gr_spacetime *spacetime, bool use_gpu +) { - return gkyl_wv_gr_maxwell_tetrad_inew(&(struct gkyl_wv_gr_maxwell_tetrad_inp) { - .light_speed = light_speed, - .e_fact = e_fact, - .b_fact = b_fact, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .spacetime = spacetime, - .rp_type = WV_GR_MAXWELL_TETRAD_RP_ROE, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_gr_maxwell_tetrad_inew(&(struct gkyl_wv_gr_maxwell_tetrad_inp + ){.light_speed = light_speed, + .e_fact = e_fact, + .b_fact = b_fact, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .spacetime = spacetime, + .rp_type = WV_GR_MAXWELL_TETRAD_RP_ROE, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_gr_maxwell_tetrad_inew(const struct gkyl_wv_gr_maxwell_tetrad_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_gr_maxwell_tetrad_inew(const struct gkyl_wv_gr_maxwell_tetrad_inp *inp) { struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = gkyl_malloc(sizeof(struct wv_gr_maxwell_tetrad)); @@ -586,8 +631,7 @@ gkyl_wv_gr_maxwell_tetrad_inew(const struct gkyl_wv_gr_maxwell_tetrad_inp* inp) gr_maxwell_tetrad->eqn.num_waves = 2; gr_maxwell_tetrad->eqn.waves_func = wave_lax_l; gr_maxwell_tetrad->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_GR_MAXWELL_TETRAD_RP_ROE) { + } else if (inp->rp_type == WV_GR_MAXWELL_TETRAD_RP_ROE) { gr_maxwell_tetrad->eqn.num_waves = 6; gr_maxwell_tetrad->eqn.waves_func = wave_roe_l; gr_maxwell_tetrad->eqn.qfluct_func = qfluct_roe_l; @@ -611,62 +655,63 @@ gkyl_wv_gr_maxwell_tetrad_inew(const struct gkyl_wv_gr_maxwell_tetrad_inp* inp) gr_maxwell_tetrad->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(gr_maxwell_tetrad->eqn.flags); gr_maxwell_tetrad->eqn.ref_count = gkyl_ref_count_init(gkyl_gr_maxwell_tetrad_free); - gr_maxwell_tetrad->eqn.on_dev = &gr_maxwell_tetrad->eqn; // On the CPU, the equation object points to itself. + gr_maxwell_tetrad->eqn.on_dev = + &gr_maxwell_tetrad->eqn; // On the CPU, the equation object points to itself. gr_maxwell_tetrad->eqn.embed_geo = NULL; return &gr_maxwell_tetrad->eqn; } -double -gkyl_wv_gr_maxwell_tetrad_light_speed(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_maxwell_tetrad_light_speed(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); + const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); double light_speed = gr_maxwell_tetrad->light_speed; return light_speed; } -double -gkyl_wv_gr_maxwell_tetrad_e_fact(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_maxwell_tetrad_e_fact(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); + const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); double e_fact = gr_maxwell_tetrad->e_fact; return e_fact; } -double -gkyl_wv_gr_maxwell_tetrad_b_fact(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_maxwell_tetrad_b_fact(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); + const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); double b_fact = gr_maxwell_tetrad->b_fact; return b_fact; } -enum gkyl_spacetime_gauge -gkyl_wv_gr_maxwell_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn) +enum gkyl_spacetime_gauge gkyl_wv_gr_maxwell_tetrad_spacetime_gauge(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); + const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); enum gkyl_spacetime_gauge spacetime_gauge = gr_maxwell_tetrad->spacetime_gauge; return spacetime_gauge; } -int -gkyl_wv_gr_maxwell_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_gr_maxwell_tetrad_reinit_freq(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); + const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); int reinit_freq = gr_maxwell_tetrad->reinit_freq; return reinit_freq; } -struct gkyl_gr_spacetime* -gkyl_wv_gr_maxwell_tetrad_spacetime(const struct gkyl_wv_eqn* eqn) +struct gkyl_gr_spacetime *gkyl_wv_gr_maxwell_tetrad_spacetime(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); + const struct wv_gr_maxwell_tetrad *gr_maxwell_tetrad = + container_of(eqn, struct wv_gr_maxwell_tetrad, eqn); struct gkyl_gr_spacetime *spacetime = gr_maxwell_tetrad->spacetime; return spacetime; diff --git a/moments/zero/wv_gr_medium.c b/moments/zero/wv_gr_medium.c index d5ecd3f938..a18658bbc6 100644 --- a/moments/zero/wv_gr_medium.c +++ b/moments/zero/wv_gr_medium.c @@ -6,15 +6,14 @@ #include #include -void -gkyl_gr_medium_prim_vars(double gas_gamma, const double q[15], double v[15]) +void gkyl_gr_medium_prim_vars(double gas_gamma, const double q[15], double v[15]) { double exp_2a = q[0]; double a_dt = q[1], a_dx = q[2]; double b_dt = q[3], b_dx = q[4]; double c_dt = q[5], c_dx = q[6]; - + double a_dt_dx = q[7], a_dx_dx = q[8]; double b_dt_dx = q[9], b_dx_dx = q[10]; double c_dt_dx = q[11], c_dx_dx = q[12]; @@ -22,32 +21,42 @@ gkyl_gr_medium_prim_vars(double gas_gamma, const double q[15], double v[15]) double Etot = q[13]; double mom = q[14]; - double rho = (1.0 / (gas_gamma - 1.0)) * ((-0.5 * (2.0 - gas_gamma) * Etot) + sqrt((0.25 * (2.0 - gas_gamma) * (2.0 - gas_gamma) * Etot * Etot) + - ((gas_gamma - 1.0) * ((Etot * Etot) - (mom * mom))))); + double rho = + (1.0 / (gas_gamma - 1.0)) * ((-0.5 * (2.0 - gas_gamma) * Etot) + + sqrt( + (0.25 * (2.0 - gas_gamma) * (2.0 - gas_gamma) * Etot * Etot) + + ((gas_gamma - 1.0) * ((Etot * Etot) - (mom * mom))) + )); double vel = 0.0; if (fabs(mom) > pow(10.0, -8.0)) { - vel = ((gas_gamma * rho) / (2.0 * mom)) * (sqrt(1.0 + ((4 * mom * mom) / ((gas_gamma * gas_gamma) * (rho * rho)))) - 1.0); + vel = ((gas_gamma * rho) / (2.0 * mom)) * + (sqrt(1.0 + ((4 * mom * mom) / ((gas_gamma * gas_gamma) * (rho * rho)))) - 1.0); } v[0] = exp_2a; - v[1] = a_dt; v[2] = a_dx; - v[3] = b_dt; v[4] = b_dx; - v[5] = c_dt; v[6] = c_dx; + v[1] = a_dt; + v[2] = a_dx; + v[3] = b_dt; + v[4] = b_dx; + v[5] = c_dt; + v[6] = c_dx; - v[7] = a_dt_dx; v[8] = a_dx_dx; - v[9] = b_dt_dx; v[10] = b_dx_dx; - v[11] = c_dt_dx; v[12] = c_dx_dx; + v[7] = a_dt_dx; + v[8] = a_dx_dx; + v[9] = b_dt_dx; + v[10] = b_dx_dx; + v[11] = c_dt_dx; + v[12] = c_dx_dx; v[13] = rho; v[14] = vel; } -static inline double -gkyl_gr_medium_max_abs_speed(double gas_gamma, const double q[15]) +static inline double gkyl_gr_medium_max_abs_speed(double gas_gamma, const double q[15]) { - double v[15] = { 0.0 }; + double v[15] = {0.0}; gkyl_gr_medium_prim_vars(gas_gamma, q, v); double vel = v[14]; @@ -57,13 +66,12 @@ gkyl_gr_medium_max_abs_speed(double gas_gamma, const double q[15]) return 1.0; // Return speed of light. } -void -gkyl_gr_medium_flux(double gas_gamma, double kappa, const double q[15], double flux[15]) +void gkyl_gr_medium_flux(double gas_gamma, double kappa, const double q[15], double flux[15]) { - double v[15] = { 0.0 }; + double v[15] = {0.0}; gkyl_gr_medium_prim_vars(gas_gamma, q, v); double exp_2a = v[0]; - + double a_dt = v[1], a_dx = v[2]; double b_dt = v[3], b_dx = v[4]; double c_dt = v[5], c_dx = v[6]; @@ -86,9 +94,12 @@ gkyl_gr_medium_flux(double gas_gamma, double kappa, const double q[15], double f flux[0] = 0.0; - flux[1] = 0.0; flux[2] = 0.0; - flux[3] = 0.0; flux[4] = 0.0; - flux[5] = 0.0; flux[6] = 0.0; + flux[1] = 0.0; + flux[2] = 0.0; + flux[3] = 0.0; + flux[4] = 0.0; + flux[5] = 0.0; + flux[6] = 0.0; flux[7] = -a_dx_dx + (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))); flux[8] = -a_dt_dx; @@ -102,7 +113,7 @@ gkyl_gr_medium_flux(double gas_gamma, double kappa, const double q[15], double f } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 15; i++) { @@ -111,7 +122,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 15; i++) { @@ -119,36 +130,42 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -gr_medium_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_medium_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 0; i < 14; i++) { ghost[i] = skin[i]; } - + ghost[14] = -skin[14]; } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { for (int i = 0; i < 15; i++) { qlocal[i] = qglobal[i]; } } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { for (int i = 0; i < 15; i++) { qglobal[i] = qlocal[i]; } } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_medium *gr_medium = container_of(eqn, struct wv_gr_medium, eqn); double gas_gamma = gr_medium->gas_gamma; @@ -174,8 +191,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[15]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -187,21 +206,25 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_gr_medium *gr_medium = container_of(eqn, struct wv_gr_medium, eqn); double gas_gamma = gr_medium->gas_gamma; @@ -221,25 +244,22 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_gr_medium *gr_medium = container_of(eqn, struct wv_gr_medium, eqn); double gas_gamma = gr_medium->gas_gamma; - double v[15] = { 0.0 }; + double v[15] = {0.0}; gkyl_gr_medium_prim_vars(gas_gamma, q, v); if (v[13] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_gr_medium *gr_medium = container_of(eqn, struct wv_gr_medium, eqn); double gas_gamma = gr_medium->gas_gamma; @@ -248,21 +268,20 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) } static inline void -gr_medium_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +gr_medium_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 15; i++) { diag[i] = qin[i]; } } -static inline void -gr_medium_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void gr_medium_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { const struct wv_gr_medium *gr_medium = container_of(eqn, struct wv_gr_medium, eqn); double gas_gamma = gr_medium->gas_gamma; double kappa = gr_medium->kappa; - double v[15] = { 0.0 }; + double v[15] = {0.0}; gkyl_gr_medium_prim_vars(gas_gamma, qin, v); double exp_2a = v[0]; @@ -288,28 +307,32 @@ gr_medium_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) sout[0] = 2.0 * a_dt * exp_2a; - sout[1] = a_dx_dx + (b_dt * b_dt) - (b_dx * b_dx) - (c_dt * c_dt) + (c_dx * c_dx) - (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))); + sout[1] = a_dx_dx + (b_dt * b_dt) - (b_dx * b_dx) - (c_dt * c_dt) + (c_dx * c_dx) - + (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))); sout[2] = a_dt_dx; - sout[3] = b_dx_dx - (2.0 * (b_dt * b_dt)) + (2.0 * (b_dx * b_dx)) + (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))); + sout[3] = b_dx_dx - (2.0 * (b_dt * b_dt)) + (2.0 * (b_dx * b_dx)) + + (0.5 * kappa * exp_2a * (Etot - ((mom * vel) + p))); sout[4] = b_dt_dx; sout[5] = c_dx_dx - (2.0 * ((b_dt * c_dt) - (b_dx * c_dx))); sout[6] = c_dt_dx; - sout[7] = (2.0 * (b_dt * b_dt_dx)) - (2.0 * (b_dx * b_dx_dx)) - (2.0 * (c_dt * c_dt_dx)) + (2.0 * (c_dx * c_dx_dx)); + sout[7] = (2.0 * (b_dt * b_dt_dx)) - (2.0 * (b_dx * b_dx_dx)) - (2.0 * (c_dt * c_dt_dx)) + + (2.0 * (c_dx * c_dx_dx)); sout[8] = 0.0; sout[9] = -(4.0 * (b_dt * b_dt_dx)) + (4.0 * (b_dx * b_dx_dx)); sout[10] = 0.0; sout[11] = -2.0 * ((b_dt * c_dt_dx) - (b_dx * c_dx_dx) + (b_dt_dx * c_dt) - (b_dx_dx * c_dx)); sout[12] = 0.0; - sout[13] = (-Etot * (a_dt + (2.0 * b_dt))) - (2.0 * mom * (a_dx + b_dx)) - (((mom * vel) + p) * a_dt) - (2.0 * p * b_dt); - sout[14] = (-Etot * a_dx) - (2.0 * mom * (a_dt + b_dt)) - (((mom * vel) + p) * (a_dx + (2.0 * b_dx))) + (2.0 * p * b_dx); + sout[13] = (-Etot * (a_dt + (2.0 * b_dt))) - (2.0 * mom * (a_dx + b_dx)) - + (((mom * vel) + p) * a_dt) - (2.0 * p * b_dt); + sout[14] = (-Etot * a_dx) - (2.0 * mom * (a_dt + b_dt)) - + (((mom * vel) + p) * (a_dx + (2.0 * b_dx))) + (2.0 * p * b_dx); } -void -gkyl_gr_medium_free(const struct gkyl_ref_count* ref) +void gkyl_gr_medium_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. @@ -321,20 +344,13 @@ gkyl_gr_medium_free(const struct gkyl_ref_count* ref) gkyl_free(gr_medium); } -struct gkyl_wv_eqn* -gkyl_wv_gr_medium_new(double gas_gamma, double kappa, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_gr_medium_new(double gas_gamma, double kappa, bool use_gpu) { - return gkyl_wv_gr_medium_inew(&(struct gkyl_wv_gr_medium_inp) { - .gas_gamma = gas_gamma, - .kappa = kappa, - .rp_type = WV_GR_MEDIUM_RP_LAX, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_gr_medium_inew(&(struct gkyl_wv_gr_medium_inp + ){.gas_gamma = gas_gamma, .kappa = kappa, .rp_type = WV_GR_MEDIUM_RP_LAX, .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_gr_medium_inew(const struct gkyl_wv_gr_medium_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_gr_medium_inew(const struct gkyl_wv_gr_medium_inp *inp) { struct wv_gr_medium *gr_medium = gkyl_malloc(sizeof(struct wv_gr_medium)); @@ -358,7 +374,7 @@ gkyl_wv_gr_medium_inew(const struct gkyl_wv_gr_medium_inp* inp) gr_medium->eqn.rotate_to_global_func = rot_to_global; gr_medium->eqn.wall_bc_func = gr_medium_wall; - + gr_medium->eqn.cons_to_riem = cons_to_riem; gr_medium->eqn.riem_to_cons = riem_to_cons; @@ -376,8 +392,7 @@ gkyl_wv_gr_medium_inew(const struct gkyl_wv_gr_medium_inp* inp) return &gr_medium->eqn; } -double -gkyl_wv_gr_medium_gas_gamma(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_medium_gas_gamma(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_medium *gr_medium = container_of(eqn, struct wv_gr_medium, eqn); double gas_gamma = gr_medium->gas_gamma; @@ -385,8 +400,7 @@ gkyl_wv_gr_medium_gas_gamma(const struct gkyl_wv_eqn* eqn) return gas_gamma; } -double -gkyl_wv_gr_medium_kappa(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_medium_kappa(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_medium *gr_medium = container_of(eqn, struct wv_gr_medium, eqn); double kappa = gr_medium->kappa; diff --git a/moments/zero/wv_gr_mhd.c b/moments/zero/wv_gr_mhd.c index 795bfa8d1b..d4af2d0078 100644 --- a/moments/zero/wv_gr_mhd.c +++ b/moments/zero/wv_gr_mhd.c @@ -6,10 +6,11 @@ #include #include -void -gkyl_gr_mhd_flux(double gas_gamma, double light_speed, double b_fact, const double q[75], double flux[75]) +void gkyl_gr_mhd_flux( + double gas_gamma, double light_speed, double b_fact, const double q[75], double flux[75] +) { - double v[75] = { 0.0 }; + double v[75] = {0.0}; gkyl_gr_mhd_prim_vars(gas_gamma, q, v); double rho = v[0]; double vx = v[1]; @@ -28,13 +29,22 @@ gkyl_gr_mhd_flux(double gas_gamma, double light_speed, double b_fact, const doub double shift_z = v[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[13]; spatial_metric[0][1] = v[14]; spatial_metric[0][2] = v[15]; - spatial_metric[1][0] = v[16]; spatial_metric[1][1] = v[17]; spatial_metric[1][2] = v[18]; - spatial_metric[2][0] = v[19]; spatial_metric[2][1] = v[20]; spatial_metric[2][2] = v[21]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + spatial_metric[0][0] = v[13]; + spatial_metric[0][1] = v[14]; + spatial_metric[0][2] = v[15]; + spatial_metric[1][0] = v[16]; + spatial_metric[1][1] = v[17]; + spatial_metric[1][2] = v[18]; + spatial_metric[2][0] = v[19]; + spatial_metric[2][1] = v[20]; + spatial_metric[2][2] = v[21]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); bool in_excision_region = false; if (v[31] < pow(10.0, -8.0)) { @@ -44,7 +54,9 @@ gkyl_gr_mhd_flux(double gas_gamma, double light_speed, double b_fact, const doub if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -58,7 +70,9 @@ gkyl_gr_mhd_flux(double gas_gamma, double light_speed, double b_fact, const doub } double mag[3]; - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double cov_mag[3]; for (int i = 0; i < 3; i++) { @@ -77,14 +91,16 @@ gkyl_gr_mhd_flux(double gas_gamma, double light_speed, double b_fact, const doub cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double spacetime_vel[4]; spacetime_vel[0] = W / lapse; @@ -122,29 +138,34 @@ gkyl_gr_mhd_flux(double gas_gamma, double light_speed, double b_fact, const doub double Etot = (rho * h_star * (W * W)) - p_star - ((lapse * lapse) * (b0 * b0)) - (rho * W); flux[0] = (lapse * sqrt(spatial_det)) * (D * (vx - (shift_x / lapse))); - flux[1] = (lapse * sqrt(spatial_det)) * ((Sx * (vx - (shift_x / lapse))) + p_star - ((cov_b[0] * mag_x) / W)); - flux[2] = (lapse * sqrt(spatial_det)) * ((Sy * (vx - (shift_x / lapse))) - ((cov_b[1] * mag_x) / W)); - flux[3] = (lapse * sqrt(spatial_det)) * ((Sz * (vx - (shift_x / lapse))) - ((cov_b[2] * mag_x) / W)); - flux[4] = (lapse * sqrt(spatial_det)) * ((Etot * (vx - (shift_x / lapse))) + (p_star * vx) - ((lapse * b0 * mag_x) / W)); - - flux[5] = (lapse * sqrt(spatial_det)) * (((vx - (shift_x / lapse)) * mag_x) - ((vx - (shift_x / lapse)) * mag_x) + (b_fact * psi)); - flux[6] = (lapse * sqrt(spatial_det)) * (((vx - (shift_x / lapse)) * mag_y) - ((vy - (shift_y / lapse)) * mag_x)); - flux[7] = (lapse * sqrt(spatial_det)) * (((vx - (shift_x / lapse)) * mag_z) - ((vz - (shift_z / lapse)) * mag_x)); + flux[1] = (lapse * sqrt(spatial_det)) * + ((Sx * (vx - (shift_x / lapse))) + p_star - ((cov_b[0] * mag_x) / W)); + flux[2] = + (lapse * sqrt(spatial_det)) * ((Sy * (vx - (shift_x / lapse))) - ((cov_b[1] * mag_x) / W)); + flux[3] = + (lapse * sqrt(spatial_det)) * ((Sz * (vx - (shift_x / lapse))) - ((cov_b[2] * mag_x) / W)); + flux[4] = (lapse * sqrt(spatial_det)) * + ((Etot * (vx - (shift_x / lapse))) + (p_star * vx) - ((lapse * b0 * mag_x) / W)); + + flux[5] = (lapse * sqrt(spatial_det)) * (((vx - (shift_x / lapse)) * mag_x) - + ((vx - (shift_x / lapse)) * mag_x) + (b_fact * psi)); + flux[6] = (lapse * sqrt(spatial_det)) * + (((vx - (shift_x / lapse)) * mag_y) - ((vy - (shift_y / lapse)) * mag_x)); + flux[7] = (lapse * sqrt(spatial_det)) * + (((vx - (shift_x / lapse)) * mag_z) - ((vz - (shift_z / lapse)) * mag_x)); flux[8] = (lapse * sqrt(spatial_det)) * (b_fact * (light_speed * light_speed) * mag_x); for (int i = 9; i < 75; i++) { flux[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 75; i++) { flux[i] = 0.0; } } } -void -gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) +void gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) { double lapse = q[9]; double shift_x = q[10]; @@ -152,21 +173,33 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) double shift_z = q[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = q[13]; spatial_metric[0][1] = q[14]; spatial_metric[0][2] = q[15]; - spatial_metric[1][0] = q[16]; spatial_metric[1][1] = q[17]; spatial_metric[1][2] = q[18]; - spatial_metric[2][0] = q[19]; spatial_metric[2][1] = q[20]; spatial_metric[2][2] = q[21]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = q[13]; + spatial_metric[0][1] = q[14]; + spatial_metric[0][2] = q[15]; + spatial_metric[1][0] = q[16]; + spatial_metric[1][1] = q[17]; + spatial_metric[1][2] = q[18]; + spatial_metric[2][0] = q[19]; + spatial_metric[2][1] = q[20]; + spatial_metric[2][2] = q[21]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } gkyl_gr_mhd_inv_spatial_metric(q, &inv_spatial_metric); - + double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = q[22]; extrinsic_curvature[0][1] = q[23]; extrinsic_curvature[0][2] = q[24]; - extrinsic_curvature[1][0] = q[25]; extrinsic_curvature[1][1] = q[26]; extrinsic_curvature[1][2] = q[27]; - extrinsic_curvature[2][0] = q[28]; extrinsic_curvature[2][1] = q[29]; extrinsic_curvature[2][2] = q[30]; + extrinsic_curvature[0][0] = q[22]; + extrinsic_curvature[0][1] = q[23]; + extrinsic_curvature[0][2] = q[24]; + extrinsic_curvature[1][0] = q[25]; + extrinsic_curvature[1][1] = q[26]; + extrinsic_curvature[1][2] = q[27]; + extrinsic_curvature[2][0] = q[28]; + extrinsic_curvature[2][1] = q[29]; + extrinsic_curvature[2][2] = q[30]; double lapse_der[3]; lapse_der[0] = q[32]; @@ -174,22 +207,46 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) lapse_der[2] = q[34]; double shift_der[3][3]; - shift_der[0][0] = q[35]; shift_der[0][1] = q[36]; shift_der[0][2] = q[37]; - shift_der[1][0] = q[38]; shift_der[1][1] = q[39]; shift_der[1][2] = q[40]; - shift_der[2][0] = q[41]; shift_der[2][1] = q[42]; shift_der[2][2] = q[43]; + shift_der[0][0] = q[35]; + shift_der[0][1] = q[36]; + shift_der[0][2] = q[37]; + shift_der[1][0] = q[38]; + shift_der[1][1] = q[39]; + shift_der[1][2] = q[40]; + shift_der[2][0] = q[41]; + shift_der[2][1] = q[42]; + shift_der[2][2] = q[43]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = q[44]; spatial_metric_der[0][0][1] = q[45]; spatial_metric_der[0][0][2] = q[46]; - spatial_metric_der[0][1][0] = q[47]; spatial_metric_der[0][1][1] = q[48]; spatial_metric_der[0][1][2] = q[49]; - spatial_metric_der[0][2][0] = q[50]; spatial_metric_der[0][2][1] = q[51]; spatial_metric_der[0][2][2] = q[52]; - - spatial_metric_der[1][0][0] = q[53]; spatial_metric_der[1][0][1] = q[54]; spatial_metric_der[1][0][2] = q[55]; - spatial_metric_der[1][1][0] = q[56]; spatial_metric_der[1][1][1] = q[57]; spatial_metric_der[1][1][2] = q[58]; - spatial_metric_der[1][2][0] = q[59]; spatial_metric_der[1][2][1] = q[60]; spatial_metric_der[1][2][2] = q[61]; - - spatial_metric_der[0][0][0] = q[62]; spatial_metric_der[0][0][1] = q[63]; spatial_metric_der[0][0][2] = q[64]; - spatial_metric_der[0][1][0] = q[65]; spatial_metric_der[0][1][1] = q[66]; spatial_metric_der[0][1][2] = q[67]; - spatial_metric_der[0][2][0] = q[68]; spatial_metric_der[0][2][1] = q[69]; spatial_metric_der[0][2][2] = q[70]; + spatial_metric_der[0][0][0] = q[44]; + spatial_metric_der[0][0][1] = q[45]; + spatial_metric_der[0][0][2] = q[46]; + spatial_metric_der[0][1][0] = q[47]; + spatial_metric_der[0][1][1] = q[48]; + spatial_metric_der[0][1][2] = q[49]; + spatial_metric_der[0][2][0] = q[50]; + spatial_metric_der[0][2][1] = q[51]; + spatial_metric_der[0][2][2] = q[52]; + + spatial_metric_der[1][0][0] = q[53]; + spatial_metric_der[1][0][1] = q[54]; + spatial_metric_der[1][0][2] = q[55]; + spatial_metric_der[1][1][0] = q[56]; + spatial_metric_der[1][1][1] = q[57]; + spatial_metric_der[1][1][2] = q[58]; + spatial_metric_der[1][2][0] = q[59]; + spatial_metric_der[1][2][1] = q[60]; + spatial_metric_der[1][2][2] = q[61]; + + spatial_metric_der[0][0][0] = q[62]; + spatial_metric_der[0][0][1] = q[63]; + spatial_metric_der[0][0][2] = q[64]; + spatial_metric_der[0][1][0] = q[65]; + spatial_metric_der[0][1][1] = q[66]; + spatial_metric_der[0][1][2] = q[67]; + spatial_metric_der[0][2][0] = q[68]; + spatial_metric_der[0][2][1] = q[69]; + spatial_metric_der[0][2][2] = q[70]; double evol_param = q[71]; double x = q[72]; @@ -202,9 +259,12 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) } if (!in_excision_region) { - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double D = q[0] / sqrt(spatial_det); double momx = q[1] / sqrt(spatial_det); @@ -218,7 +278,9 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) double psi = q[8] / sqrt(spatial_det); double cov_mom[3]; - cov_mom[0] = momx; cov_mom[1] = momy; cov_mom[2] = momz; + cov_mom[0] = momx; + cov_mom[1] = momy; + cov_mom[2] = momz; double mom[3]; for (int i = 0; i < 3; i++) { @@ -235,7 +297,9 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) } double mag[3]; - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double cov_mag[3]; for (int i = 0; i < 3; i++) { @@ -245,7 +309,7 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) cov_mag[i] += spatial_metric[i][j] * mag[j]; } } - + double mag_sq = 0.0; for (int i = 0; i < 3; i++) { mag_sq += mag[i] * cov_mag[i]; @@ -264,10 +328,12 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) double d = 0.5 * ((M_sq * mag_sq) - (tau_star * tau_star)); double phi = acos((1.0 / a) * sqrt((27.0 * d) / (4.0 * a))); - double epsilon1 = ((1.0 / 3.0) * a) - ((2.0 / 3.0) * a * cos(((2.0 / 3.0) * phi) + ((2.0 / 3.0) * M_PI))); + double epsilon1 = + ((1.0 / 3.0) * a) - ((2.0 / 3.0) * a * cos(((2.0 / 3.0) * phi) + ((2.0 / 3.0) * M_PI))); z = epsilon1 - mag_sq; - double v_sq = ((M_sq * (z * z)) + ((tau_star * tau_star) * (mag_sq + (2.0 * z)))) / ((z * z) * (mag_sq + z) * (mag_sq + z)); + double v_sq = ((M_sq * (z * z)) + ((tau_star * tau_star) * (mag_sq + (2.0 * z)))) / + ((z * z) * (mag_sq + z) * (mag_sq + z)); double W = 1.0 / sqrt(1.0 - v_sq); rho = D / W; double h = z / (W * W * rho); @@ -276,8 +342,7 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) if (fabs(p_guess - p_new) < pow(10.0, -15.0)) { iter = 100; - } - else { + } else { iter += 1; p_guess = p_new; } @@ -316,13 +381,25 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) v[11] = shift_y; v[12] = shift_z; - v[13] = spatial_metric[0][0]; v[14] = spatial_metric[0][1]; v[15] = spatial_metric[0][2]; - v[16] = spatial_metric[1][0]; v[17] = spatial_metric[1][1]; v[18] = spatial_metric[1][2]; - v[19] = spatial_metric[2][0]; v[20] = spatial_metric[2][1]; v[21] = spatial_metric[2][2]; - - v[22] = extrinsic_curvature[0][0]; v[23] = extrinsic_curvature[0][1]; v[24] = extrinsic_curvature[0][2]; - v[25] = extrinsic_curvature[1][0]; v[26] = extrinsic_curvature[1][1]; v[27] = extrinsic_curvature[1][2]; - v[28] = extrinsic_curvature[2][0]; v[29] = extrinsic_curvature[2][1]; v[30] = extrinsic_curvature[2][2]; + v[13] = spatial_metric[0][0]; + v[14] = spatial_metric[0][1]; + v[15] = spatial_metric[0][2]; + v[16] = spatial_metric[1][0]; + v[17] = spatial_metric[1][1]; + v[18] = spatial_metric[1][2]; + v[19] = spatial_metric[2][0]; + v[20] = spatial_metric[2][1]; + v[21] = spatial_metric[2][2]; + + v[22] = extrinsic_curvature[0][0]; + v[23] = extrinsic_curvature[0][1]; + v[24] = extrinsic_curvature[0][2]; + v[25] = extrinsic_curvature[1][0]; + v[26] = extrinsic_curvature[1][1]; + v[27] = extrinsic_curvature[1][2]; + v[28] = extrinsic_curvature[2][0]; + v[29] = extrinsic_curvature[2][1]; + v[30] = extrinsic_curvature[2][2]; v[31] = 1.0; @@ -330,32 +407,55 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) v[33] = lapse_der[1]; v[34] = lapse_der[2]; - v[35] = shift_der[0][0]; v[36] = shift_der[0][1]; v[37] = shift_der[0][2]; - v[38] = shift_der[1][0]; v[39] = shift_der[1][1]; v[40] = shift_der[1][2]; - v[41] = shift_der[2][0]; v[42] = shift_der[2][1]; v[43] = shift_der[2][2]; - - v[44] = spatial_metric_der[0][0][0]; v[45] = spatial_metric_der[0][0][1]; v[46] = spatial_metric_der[0][0][2]; - v[47] = spatial_metric_der[0][1][0]; v[48] = spatial_metric_der[0][1][1]; v[49] = spatial_metric_der[0][1][2]; - v[50] = spatial_metric_der[0][2][0]; v[51] = spatial_metric_der[0][2][1]; v[52] = spatial_metric_der[0][2][2]; - - v[53] = spatial_metric_der[1][0][0]; v[54] = spatial_metric_der[1][0][1]; v[55] = spatial_metric_der[1][0][2]; - v[56] = spatial_metric_der[1][1][0]; v[57] = spatial_metric_der[1][1][1]; v[58] = spatial_metric_der[1][1][2]; - v[59] = spatial_metric_der[1][2][0]; v[60] = spatial_metric_der[1][2][1]; v[61] = spatial_metric_der[1][2][2]; - - v[62] = spatial_metric_der[2][0][0]; v[63] = spatial_metric_der[2][0][1]; v[64] = spatial_metric_der[2][0][2]; - v[65] = spatial_metric_der[2][1][0]; v[66] = spatial_metric_der[2][1][1]; v[67] = spatial_metric_der[2][1][2]; - v[68] = spatial_metric_der[2][2][0]; v[69] = spatial_metric_der[2][2][1]; v[70] = spatial_metric_der[2][2][2]; + v[35] = shift_der[0][0]; + v[36] = shift_der[0][1]; + v[37] = shift_der[0][2]; + v[38] = shift_der[1][0]; + v[39] = shift_der[1][1]; + v[40] = shift_der[1][2]; + v[41] = shift_der[2][0]; + v[42] = shift_der[2][1]; + v[43] = shift_der[2][2]; + + v[44] = spatial_metric_der[0][0][0]; + v[45] = spatial_metric_der[0][0][1]; + v[46] = spatial_metric_der[0][0][2]; + v[47] = spatial_metric_der[0][1][0]; + v[48] = spatial_metric_der[0][1][1]; + v[49] = spatial_metric_der[0][1][2]; + v[50] = spatial_metric_der[0][2][0]; + v[51] = spatial_metric_der[0][2][1]; + v[52] = spatial_metric_der[0][2][2]; + + v[53] = spatial_metric_der[1][0][0]; + v[54] = spatial_metric_der[1][0][1]; + v[55] = spatial_metric_der[1][0][2]; + v[56] = spatial_metric_der[1][1][0]; + v[57] = spatial_metric_der[1][1][1]; + v[58] = spatial_metric_der[1][1][2]; + v[59] = spatial_metric_der[1][2][0]; + v[60] = spatial_metric_der[1][2][1]; + v[61] = spatial_metric_der[1][2][2]; + + v[62] = spatial_metric_der[2][0][0]; + v[63] = spatial_metric_der[2][0][1]; + v[64] = spatial_metric_der[2][0][2]; + v[65] = spatial_metric_der[2][1][0]; + v[66] = spatial_metric_der[2][1][1]; + v[67] = spatial_metric_der[2][1][2]; + v[68] = spatial_metric_der[2][2][0]; + v[69] = spatial_metric_der[2][2][1]; + v[70] = spatial_metric_der[2][2][2]; v[71] = evol_param; v[72] = x; v[73] = y; v[74] = z; - } - else { + } else { for (int i = 0; i < 75; i++) { v[i] = 0.0; } - + v[31] = -1.0; } @@ -365,18 +465,26 @@ gkyl_gr_mhd_prim_vars(double gas_gamma, const double q[75], double v[75]) gkyl_free(inv_spatial_metric); } -void -gkyl_gr_mhd_inv_spatial_metric(const double q[75], double ***inv_spatial_metric) +void gkyl_gr_mhd_inv_spatial_metric(const double q[75], double ***inv_spatial_metric) { double spatial_metric[3][3]; - spatial_metric[0][0] = q[13]; spatial_metric[0][1] = q[14]; spatial_metric[0][2] = q[15]; - spatial_metric[1][0] = q[16]; spatial_metric[1][1] = q[17]; spatial_metric[1][2] = q[18]; - spatial_metric[2][0] = q[19]; spatial_metric[2][1] = q[20]; spatial_metric[2][2] = q[21]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = q[13]; + spatial_metric[0][1] = q[14]; + spatial_metric[0][2] = q[15]; + spatial_metric[1][0] = q[16]; + spatial_metric[1][1] = q[17]; + spatial_metric[1][2] = q[18]; + spatial_metric[2][0] = q[19]; + spatial_metric[2][1] = q[20]; + spatial_metric[2][2] = q[21]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -407,8 +515,7 @@ gkyl_gr_mhd_inv_spatial_metric(const double q[75], double ***inv_spatial_metric) for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -416,16 +523,16 @@ gkyl_gr_mhd_inv_spatial_metric(const double q[75], double ***inv_spatial_metric) for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*inv_spatial_metric)[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*inv_spatial_metric)[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } } -void -gkyl_gr_mhd_stress_energy_tensor(double gas_gamma, const double q[75], double ***stress_energy) +void gkyl_gr_mhd_stress_energy_tensor(double gas_gamma, const double q[75], double ***stress_energy) { - double v[75] = { 0.0 }; + double v[75] = {0.0}; gkyl_gr_mhd_prim_vars(gas_gamma, q, v); double rho = v[0]; double vx = v[1]; @@ -444,11 +551,17 @@ gkyl_gr_mhd_stress_energy_tensor(double gas_gamma, const double q[75], double ** double shift_z = v[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[13]; spatial_metric[0][1] = v[14]; spatial_metric[0][2] = v[15]; - spatial_metric[1][0] = v[16]; spatial_metric[1][1] = v[17]; spatial_metric[1][2] = v[18]; - spatial_metric[2][0] = v[19]; spatial_metric[2][1] = v[20]; spatial_metric[2][2] = v[21]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[13]; + spatial_metric[0][1] = v[14]; + spatial_metric[0][2] = v[15]; + spatial_metric[1][0] = v[16]; + spatial_metric[1][1] = v[17]; + spatial_metric[1][2] = v[18]; + spatial_metric[2][0] = v[19]; + spatial_metric[2][1] = v[20]; + spatial_metric[2][2] = v[21]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -463,7 +576,9 @@ gkyl_gr_mhd_stress_energy_tensor(double gas_gamma, const double q[75], double ** if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -477,7 +592,9 @@ gkyl_gr_mhd_stress_energy_tensor(double gas_gamma, const double q[75], double ** } double mag[3]; - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double cov_mag[3]; for (int i = 0; i < 3; i++) { @@ -496,14 +613,16 @@ gkyl_gr_mhd_stress_energy_tensor(double gas_gamma, const double q[75], double ** cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double spacetime_vel[4]; spacetime_vel[0] = W / lapse; @@ -535,14 +654,15 @@ gkyl_gr_mhd_stress_energy_tensor(double gas_gamma, const double q[75], double ** double p_star = p + (0.5 * b_sq); double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } @@ -554,11 +674,12 @@ gkyl_gr_mhd_stress_energy_tensor(double gas_gamma, const double q[75], double ** for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*stress_energy)[i][j] = (rho * h_star * spacetime_vel[i] * spacetime_vel[j]) + (p_star * inv_spacetime_metric[i][j]) - (spacetime_b[i] * spacetime_b[j]); + (*stress_energy)[i][j] = (rho * h_star * spacetime_vel[i] * spacetime_vel[j]) + + (p_star * inv_spacetime_metric[i][j]) - + (spacetime_b[i] * spacetime_b[j]); } } - } - else { + } else { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { (*stress_energy)[i][j] = 0.0; @@ -572,10 +693,9 @@ gkyl_gr_mhd_stress_energy_tensor(double gas_gamma, const double q[75], double ** gkyl_free(inv_spatial_metric); } -static inline double -gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]) +static inline double gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]) { - double v[75] = { 0.0 }; + double v[75] = {0.0}; gkyl_gr_mhd_prim_vars(gas_gamma, q, v); double rho = v[0]; double vx = v[1]; @@ -594,11 +714,17 @@ gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]) double shift_z = v[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[13]; spatial_metric[0][1] = v[14]; spatial_metric[0][2] = v[15]; - spatial_metric[1][0] = v[16]; spatial_metric[1][1] = v[17]; spatial_metric[1][2] = v[18]; - spatial_metric[2][0] = v[19]; spatial_metric[2][1] = v[20]; spatial_metric[2][2] = v[21]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[13]; + spatial_metric[0][1] = v[14]; + spatial_metric[0][2] = v[15]; + spatial_metric[1][0] = v[16]; + spatial_metric[1][1] = v[17]; + spatial_metric[1][2] = v[18]; + spatial_metric[2][0] = v[19]; + spatial_metric[2][1] = v[20]; + spatial_metric[2][2] = v[21]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -613,7 +739,9 @@ gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]) if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -627,7 +755,9 @@ gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]) } double mag[3]; - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double cov_mag[3]; for (int i = 0; i < 3; i++) { @@ -646,14 +776,16 @@ gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]) cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double spacetime_vel[4]; spacetime_vel[0] = W / lapse; @@ -688,11 +820,19 @@ gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]) for (int i = 0; i < 3; i++) { entropy_eigs[i] = (lapse * vel[i] - shift[i]); - fast_alfven_eigs[i] = (b[i] + (sqrt(C) * spacetime_vel[i + 1])) / (b0 + (sqrt(C) * spacetime_vel[0])); - slow_alfven_eigs[i] = (b[i] - (sqrt(C) * spacetime_vel[i + 1])) / (b0 - (sqrt(C) * spacetime_vel[0])); + fast_alfven_eigs[i] = + (b[i] + (sqrt(C) * spacetime_vel[i + 1])) / (b0 + (sqrt(C) * spacetime_vel[0])); + slow_alfven_eigs[i] = + (b[i] - (sqrt(C) * spacetime_vel[i + 1])) / (b0 - (sqrt(C) * spacetime_vel[0])); - fast_magnetosonic_eigs[i] = sqrt((fast_alfven_eigs[i] * fast_alfven_eigs[i]) + ((c_s * c_s) * (1.0 - (fast_alfven_eigs[i] * fast_alfven_eigs[i])))); - slow_magnetosonic_eigs[i] = sqrt((slow_alfven_eigs[i] * slow_alfven_eigs[i]) + ((c_s * c_s) * (1.0 - (slow_alfven_eigs[i] * slow_alfven_eigs[i])))); + fast_magnetosonic_eigs[i] = sqrt( + (fast_alfven_eigs[i] * fast_alfven_eigs[i]) + + ((c_s * c_s) * (1.0 - (fast_alfven_eigs[i] * fast_alfven_eigs[i]))) + ); + slow_magnetosonic_eigs[i] = sqrt( + (slow_alfven_eigs[i] * slow_alfven_eigs[i]) + + ((c_s * c_s) * (1.0 - (slow_alfven_eigs[i] * slow_alfven_eigs[i]))) + ); } double max_eig = 0.0; @@ -720,8 +860,7 @@ gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]) gkyl_free(inv_spatial_metric); return fabs(v_sq) + max_eig; - } - else { + } else { for (int i = 0; i < 3; i++) { gkyl_free(inv_spatial_metric[i]); } @@ -732,7 +871,7 @@ gkyl_gr_mhd_max_abs_speed(double gas_gamma, const double q[75]) } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 75; i++) { @@ -741,7 +880,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 75; i++) { @@ -749,8 +888,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -gr_mhd_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_mhd_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 0; i < 75; i++) { ghost[i] = skin[i]; @@ -759,8 +900,10 @@ gr_mhd_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, ghost[1] = -ghost[1]; } -static void -gr_mhd_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_mhd_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 1; i < 4; i++) { ghost[i] = -skin[i]; @@ -774,9 +917,10 @@ gr_mhd_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* sk } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; qlocal[1] = (qglobal[1] * norm[0]) + (qglobal[2] * norm[1]) + (qglobal[3] * norm[2]); @@ -823,9 +967,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinate frame. - qlocal[13] = v1[0]; qlocal[14] = v1[1]; qlocal[15] = v1[2]; - qlocal[16] = v2[0]; qlocal[17] = v2[1]; qlocal[18] = v2[2]; - qlocal[19] = v3[0]; qlocal[20] = v3[1]; qlocal[21] = v3[2]; + qlocal[13] = v1[0]; + qlocal[14] = v1[1]; + qlocal[15] = v1[2]; + qlocal[16] = v2[0]; + qlocal[17] = v2[1]; + qlocal[18] = v2[2]; + qlocal[19] = v3[0]; + qlocal[20] = v3[1]; + qlocal[21] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -856,9 +1006,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta inv_v3[2] = (extr_r1[2] * tau2[0]) + (extr_r2[2] * tau2[1]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor to local coordinate frame. - qlocal[22] = inv_v1[0]; qlocal[23] = inv_v1[1]; qlocal[24] = inv_v1[2]; - qlocal[25] = inv_v2[0]; qlocal[26] = inv_v2[1]; qlocal[27] = inv_v2[2]; - qlocal[28] = inv_v3[0]; qlocal[29] = inv_v3[1]; qlocal[30] = inv_v3[2]; + qlocal[22] = inv_v1[0]; + qlocal[23] = inv_v1[1]; + qlocal[24] = inv_v1[2]; + qlocal[25] = inv_v2[0]; + qlocal[26] = inv_v2[1]; + qlocal[27] = inv_v2[2]; + qlocal[28] = inv_v3[0]; + qlocal[29] = inv_v3[1]; + qlocal[30] = inv_v3[2]; qlocal[31] = qglobal[31]; @@ -882,22 +1038,37 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); - shiftder_v1[1] = (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); - shiftder_v1[2] = (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); - shiftder_v2[1] = (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); - shiftder_v2[2] = (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); - shiftder_v3[1] = (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); - shiftder_v3[2] = (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); + shiftder_v1[1] = + (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); + shiftder_v1[2] = + (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); + shiftder_v2[1] = + (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); + shiftder_v2[2] = + (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); + shiftder_v3[1] = + (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); + shiftder_v3[2] = + (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative to local coordinate frame. - qlocal[35] = shiftder_v1[0]; qlocal[36] = shiftder_v1[1]; qlocal[37] = shiftder_v1[2]; - qlocal[38] = shiftder_v2[0]; qlocal[39] = shiftder_v2[1]; qlocal[40] = shiftder_v2[2]; - qlocal[41] = shiftder_v3[0]; qlocal[42] = shiftder_v3[1]; qlocal[43] = shiftder_v3[2]; + qlocal[35] = shiftder_v1[0]; + qlocal[36] = shiftder_v1[1]; + qlocal[37] = shiftder_v1[2]; + qlocal[38] = shiftder_v2[0]; + qlocal[39] = shiftder_v2[1]; + qlocal[40] = shiftder_v2[2]; + qlocal[41] = shiftder_v3[0]; + qlocal[42] = shiftder_v3[1]; + qlocal[43] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -980,7 +1151,7 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta s33[0] = (r31[0] * tau2[0]) + (r32[0] * tau2[1]) + (r33[0] * tau2[2]); s33[1] = (r31[1] * tau2[0]) + (r32[1] * tau2[1]) + (r33[1] * tau2[2]); s33[2] = (r31[2] * tau2[0]) + (r32[2] * tau2[1]) + (r33[2] * tau2[2]); - + // Rotate spatial metric tensor derivative to local coordinate frame. qlocal[44] = (s11[0] * norm[0]) + (s21[0] * norm[1]) + (s31[0] * norm[2]); qlocal[45] = (s11[1] * norm[0]) + (s21[1] * norm[1]) + (s31[1] * norm[2]); @@ -1024,9 +1195,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[74] = (qglobal[72] * tau2[0]) + (qglobal[73] * tau2[1]) + (qglobal[74] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; qglobal[1] = (qlocal[1] * norm[0]) + (qlocal[2] * tau1[0]) + (qlocal[3] * tau2[0]); @@ -1073,9 +1245,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor back to global coordinate frame. - qglobal[13] = v1[0]; qglobal[14] = v1[1]; qglobal[15] = v1[2]; - qglobal[16] = v2[0]; qglobal[17] = v2[1]; qglobal[18] = v2[2]; - qglobal[19] = v3[0]; qglobal[20] = v3[1]; qglobal[21] = v3[2]; + qglobal[13] = v1[0]; + qglobal[14] = v1[1]; + qglobal[15] = v1[2]; + qglobal[16] = v2[0]; + qglobal[17] = v2[1]; + qglobal[18] = v2[2]; + qglobal[19] = v3[0]; + qglobal[20] = v3[1]; + qglobal[21] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -1106,9 +1284,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t inv_v3[2] = (extr_r1[2] * norm[2]) + (extr_r2[2] * tau1[2]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor back to global coordinate frame. - qglobal[22] = inv_v1[0]; qglobal[23] = inv_v1[1]; qglobal[24] = inv_v1[2]; - qglobal[25] = inv_v2[0]; qglobal[26] = inv_v2[1]; qglobal[27] = inv_v2[2]; - qglobal[28] = inv_v3[0]; qglobal[29] = inv_v3[1]; qglobal[30] = inv_v3[2]; + qglobal[22] = inv_v1[0]; + qglobal[23] = inv_v1[1]; + qglobal[24] = inv_v1[2]; + qglobal[25] = inv_v2[0]; + qglobal[26] = inv_v2[1]; + qglobal[27] = inv_v2[2]; + qglobal[28] = inv_v3[0]; + qglobal[29] = inv_v3[1]; + qglobal[30] = inv_v3[2]; qglobal[31] = qlocal[31]; @@ -1132,22 +1316,37 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); - shiftder_v1[1] = (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); - shiftder_v1[2] = (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); - shiftder_v2[1] = (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); - shiftder_v2[2] = (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); - shiftder_v3[1] = (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); - shiftder_v3[2] = (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); + shiftder_v1[1] = + (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); + shiftder_v1[2] = + (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); + shiftder_v2[1] = + (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); + shiftder_v2[2] = + (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); + shiftder_v3[1] = + (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); + shiftder_v3[2] = + (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative back to global coordinate frame. - qglobal[35] = shiftder_v1[0]; qglobal[36] = shiftder_v1[1]; qglobal[37] = shiftder_v1[2]; - qglobal[38] = shiftder_v2[0]; qglobal[39] = shiftder_v2[1]; qglobal[40] = shiftder_v2[2]; - qglobal[41] = shiftder_v3[0]; qglobal[42] = shiftder_v3[1]; qglobal[43] = shiftder_v3[2]; + qglobal[35] = shiftder_v1[0]; + qglobal[36] = shiftder_v1[1]; + qglobal[37] = shiftder_v1[2]; + qglobal[38] = shiftder_v2[0]; + qglobal[39] = shiftder_v2[1]; + qglobal[40] = shiftder_v2[2]; + qglobal[41] = shiftder_v3[0]; + qglobal[42] = shiftder_v3[1]; + qglobal[43] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -1274,8 +1473,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[74] = (qlocal[72] * norm[2]) + (qlocal[73] * tau1[2]) + (qlocal[74] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); double gas_gamma = gr_mhd->gas_gamma; @@ -1306,8 +1507,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr[i] - fl[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr[i] - fl[i]) / amax); } - } - else { + } else { for (int i = 0; i < 75; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1320,8 +1520,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[75]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1333,21 +1535,27 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); double gas_gamma = gr_mhd->gas_gamma; @@ -1375,11 +1583,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_z_l = vl[12]; double spatial_metric_l[3][3]; - spatial_metric_l[0][0] = vl[13]; spatial_metric_l[0][1] = vl[14]; spatial_metric_l[0][2] = vl[15]; - spatial_metric_l[1][0] = vl[16]; spatial_metric_l[1][1] = vl[17]; spatial_metric_l[1][2] = vl[18]; - spatial_metric_l[2][0] = vl[19]; spatial_metric_l[2][1] = vl[20]; spatial_metric_l[2][2] = vl[21]; - - double **inv_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); + spatial_metric_l[0][0] = vl[13]; + spatial_metric_l[0][1] = vl[14]; + spatial_metric_l[0][2] = vl[15]; + spatial_metric_l[1][0] = vl[16]; + spatial_metric_l[1][1] = vl[17]; + spatial_metric_l[1][2] = vl[18]; + spatial_metric_l[2][0] = vl[19]; + spatial_metric_l[2][1] = vl[20]; + spatial_metric_l[2][2] = vl[21]; + + double **inv_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); } @@ -1393,7 +1607,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_l[3]; double v_sq_l = 0.0; - vel_l[0] = vx_l; vel_l[1] = vy_l; vel_l[2] = vz_l; + vel_l[0] = vx_l; + vel_l[1] = vy_l; + vel_l[2] = vz_l; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1407,7 +1623,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double mag_l[3]; - mag_l[0] = mag_x_l; mag_l[1] = mag_y_l; mag_l[2] = mag_z_l; + mag_l[0] = mag_x_l; + mag_l[1] = mag_y_l; + mag_l[2] = mag_z_l; double cov_mag_l[3]; for (int i = 0; i < 3; i++) { @@ -1433,7 +1651,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_l[3]; - shift_l[0] = shift_x_l; shift_l[1] = shift_y_l; shift_l[2] = shift_z_l; + shift_l[0] = shift_x_l; + shift_l[1] = shift_y_l; + shift_l[2] = shift_z_l; double spacetime_vel_l[4]; spacetime_vel_l[0] = W_l / lapse_l; @@ -1476,11 +1696,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_z_r = vr[12]; double spatial_metric_r[3][3]; - spatial_metric_r[0][0] = vr[13]; spatial_metric_r[0][1] = vr[14]; spatial_metric_r[0][2] = vr[15]; - spatial_metric_r[1][0] = vr[16]; spatial_metric_r[1][1] = vr[17]; spatial_metric_r[1][2] = vr[18]; - spatial_metric_r[2][0] = vr[19]; spatial_metric_r[2][1] = vr[20]; spatial_metric_r[2][2] = vr[21]; - - double **inv_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + spatial_metric_r[0][0] = vr[13]; + spatial_metric_r[0][1] = vr[14]; + spatial_metric_r[0][2] = vr[15]; + spatial_metric_r[1][0] = vr[16]; + spatial_metric_r[1][1] = vr[17]; + spatial_metric_r[1][2] = vr[18]; + spatial_metric_r[2][0] = vr[19]; + spatial_metric_r[2][1] = vr[20]; + spatial_metric_r[2][2] = vr[21]; + + double **inv_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } @@ -1494,7 +1720,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_r[3]; double v_sq_r = 0.0; - vel_r[0] = vx_r; vel_r[1] = vy_r; vel_r[2] = vz_r; + vel_r[0] = vx_r; + vel_r[1] = vy_r; + vel_r[2] = vz_r; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1508,7 +1736,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double mag_r[3]; - mag_r[0] = mag_x_r; mag_r[1] = mag_y_r; mag_r[2] = mag_z_r; + mag_r[0] = mag_x_r; + mag_r[1] = mag_y_r; + mag_r[2] = mag_z_r; double cov_mag_r[3]; for (int i = 0; i < 3; i++) { @@ -1534,7 +1764,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_r[3]; - shift_r[0] = shift_x_r; shift_r[1] = shift_y_r; shift_r[2] = shift_z_r; + shift_r[0] = shift_x_r; + shift_r[1] = shift_y_r; + shift_r[2] = shift_z_r; double spacetime_vel_r[4]; spacetime_vel_r[0] = W_r / lapse_r; @@ -1560,19 +1792,35 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double den_r = 1.0 + ((p_r / rho_r) * (gas_gamma) / (gas_gamma - 1.0)); double c_sr = sqrt(num_r / den_r); - double fast_alfven_eig_l = (b_l[0] + (sqrt(C_l) * spacetime_vel_l[1])) / (b0_l + (sqrt(C_l) * spacetime_vel_l[0])); - double slow_alfven_eig_l = (b_l[0] - (sqrt(C_l) * spacetime_vel_l[1])) / (b0_l - (sqrt(C_l) * spacetime_vel_l[0])); - - double fast_magnetosonic_eig_l = sqrt((fast_alfven_eig_l * fast_alfven_eig_l) + ((c_sl * c_sl) * (1.0 - (fast_alfven_eig_l * fast_alfven_eig_l)))); - double slow_magnetosonic_eig_l = sqrt((slow_alfven_eig_l * slow_alfven_eig_l) + ((c_sl * c_sl) * (1.0 - (slow_alfven_eig_l * slow_alfven_eig_l)))); + double fast_alfven_eig_l = + (b_l[0] + (sqrt(C_l) * spacetime_vel_l[1])) / (b0_l + (sqrt(C_l) * spacetime_vel_l[0])); + double slow_alfven_eig_l = + (b_l[0] - (sqrt(C_l) * spacetime_vel_l[1])) / (b0_l - (sqrt(C_l) * spacetime_vel_l[0])); + + double fast_magnetosonic_eig_l = sqrt( + (fast_alfven_eig_l * fast_alfven_eig_l) + + ((c_sl * c_sl) * (1.0 - (fast_alfven_eig_l * fast_alfven_eig_l))) + ); + double slow_magnetosonic_eig_l = sqrt( + (slow_alfven_eig_l * slow_alfven_eig_l) + + ((c_sl * c_sl) * (1.0 - (slow_alfven_eig_l * slow_alfven_eig_l))) + ); double max_eig_l = fmax(fast_magnetosonic_eig_l, slow_magnetosonic_eig_l); - double fast_alfven_eig_r = (b_r[0] + (sqrt(C_r) * spacetime_vel_r[1])) / (b0_r + (sqrt(C_r) * spacetime_vel_r[0])); - double slow_alfven_eig_r = (b_r[0] - (sqrt(C_r) * spacetime_vel_r[1])) / (b0_r - (sqrt(C_r) * spacetime_vel_r[0])); - - double fast_magnetosonic_eig_r = sqrt((fast_alfven_eig_r * fast_alfven_eig_r) + ((c_sr * c_sr) * (1.0 - (fast_alfven_eig_r * fast_alfven_eig_r)))); - double slow_magnetosonic_eig_r = sqrt((slow_alfven_eig_r * slow_alfven_eig_r) + ((c_sr * c_sr) * (1.0 - (slow_alfven_eig_r * slow_alfven_eig_r)))); + double fast_alfven_eig_r = + (b_r[0] + (sqrt(C_r) * spacetime_vel_r[1])) / (b0_r + (sqrt(C_r) * spacetime_vel_r[0])); + double slow_alfven_eig_r = + (b_r[0] - (sqrt(C_r) * spacetime_vel_r[1])) / (b0_r - (sqrt(C_r) * spacetime_vel_r[0])); + + double fast_magnetosonic_eig_r = sqrt( + (fast_alfven_eig_r * fast_alfven_eig_r) + + ((c_sr * c_sr) * (1.0 - (fast_alfven_eig_r * fast_alfven_eig_r))) + ); + double slow_magnetosonic_eig_r = sqrt( + (slow_alfven_eig_r * slow_alfven_eig_r) + + ((c_sr * c_sr) * (1.0 - (slow_alfven_eig_r * slow_alfven_eig_r))) + ); double max_eig_r = fmax(fast_magnetosonic_eig_r, slow_magnetosonic_eig_r); @@ -1597,8 +1845,7 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = qm[i] - ql[i]; w1[i] = qr[i] - qm[i]; } - } - else { + } else { for (int i = 0; i < 75; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1618,8 +1865,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return fmax(fabs(sl), fabs(sr)); } -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[75]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1631,33 +1880,35 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hll(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_hll(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); double gas_gamma = gr_mhd->gas_gamma; @@ -1682,8 +1933,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 75; m++) { flux_jump[m] = fr[m] - fl[m]; } - } - else { + } else { for (int m = 0; m < 75; m++) { flux_jump[m] = 0.0; } @@ -1695,25 +1945,22 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); double gas_gamma = gr_mhd->gas_gamma; - double v[75] = { 0.0 }; + double v[75] = {0.0}; gkyl_gr_mhd_prim_vars(gas_gamma, q, v); if (v[0] < 0.0 || v[4] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); double gas_gamma = gr_mhd->gas_gamma; @@ -1722,20 +1969,19 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) } static inline void -gr_mhd_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +gr_mhd_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 8; i++) { diag[i] = qin[i]; } } -static inline void -gr_mhd_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void gr_mhd_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); double gas_gamma = gr_mhd->gas_gamma; - double v[75] = { 0.0 }; + double v[75] = {0.0}; gkyl_gr_mhd_prim_vars(gas_gamma, qin, v); double rho = v[0]; double vx = v[1]; @@ -1754,18 +2000,33 @@ gr_mhd_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) double shift_z = v[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[13]; spatial_metric[0][1] = v[14]; spatial_metric[0][2] = v[15]; - spatial_metric[1][0] = v[16]; spatial_metric[1][1] = v[17]; spatial_metric[1][2] = v[18]; - spatial_metric[2][0] = v[19]; spatial_metric[2][1] = v[20]; spatial_metric[2][2] = v[21]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + spatial_metric[0][0] = v[13]; + spatial_metric[0][1] = v[14]; + spatial_metric[0][2] = v[15]; + spatial_metric[1][0] = v[16]; + spatial_metric[1][1] = v[17]; + spatial_metric[1][2] = v[18]; + spatial_metric[2][0] = v[19]; + spatial_metric[2][1] = v[20]; + spatial_metric[2][2] = v[21]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = v[22]; extrinsic_curvature[0][1] = v[23]; extrinsic_curvature[0][2] = v[24]; - extrinsic_curvature[1][0] = v[25]; extrinsic_curvature[1][1] = v[26]; extrinsic_curvature[1][2] = v[27]; - extrinsic_curvature[2][0] = v[28]; extrinsic_curvature[2][1] = v[29]; extrinsic_curvature[2][2] = v[30]; + extrinsic_curvature[0][0] = v[22]; + extrinsic_curvature[0][1] = v[23]; + extrinsic_curvature[0][2] = v[24]; + extrinsic_curvature[1][0] = v[25]; + extrinsic_curvature[1][1] = v[26]; + extrinsic_curvature[1][2] = v[27]; + extrinsic_curvature[2][0] = v[28]; + extrinsic_curvature[2][1] = v[29]; + extrinsic_curvature[2][2] = v[30]; double lapse_der[3]; lapse_der[0] = v[32]; @@ -1773,24 +2034,48 @@ gr_mhd_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) lapse_der[2] = v[34]; double shift_der[3][3]; - shift_der[0][0] = v[35]; shift_der[0][1] = v[36]; shift_der[0][2] = v[37]; - shift_der[1][0] = v[38]; shift_der[1][1] = v[39]; shift_der[1][2] = v[40]; - shift_der[2][0] = v[41]; shift_der[2][1] = v[42]; shift_der[2][2] = v[43]; + shift_der[0][0] = v[35]; + shift_der[0][1] = v[36]; + shift_der[0][2] = v[37]; + shift_der[1][0] = v[38]; + shift_der[1][1] = v[39]; + shift_der[1][2] = v[40]; + shift_der[2][0] = v[41]; + shift_der[2][1] = v[42]; + shift_der[2][2] = v[43]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = v[44]; spatial_metric_der[0][0][1] = v[45]; spatial_metric_der[0][0][2] = v[46]; - spatial_metric_der[0][1][0] = v[47]; spatial_metric_der[0][1][1] = v[48]; spatial_metric_der[0][1][2] = v[49]; - spatial_metric_der[0][2][0] = v[50]; spatial_metric_der[0][2][1] = v[51]; spatial_metric_der[0][2][2] = v[52]; - - spatial_metric_der[1][0][0] = v[53]; spatial_metric_der[1][0][1] = v[54]; spatial_metric_der[1][0][2] = v[55]; - spatial_metric_der[1][1][0] = v[56]; spatial_metric_der[1][1][1] = v[57]; spatial_metric_der[1][1][2] = v[58]; - spatial_metric_der[1][2][0] = v[59]; spatial_metric_der[1][2][1] = v[60]; spatial_metric_der[1][2][2] = v[61]; - - spatial_metric_der[0][0][0] = v[62]; spatial_metric_der[0][0][1] = v[63]; spatial_metric_der[0][0][2] = v[64]; - spatial_metric_der[0][1][0] = v[65]; spatial_metric_der[0][1][1] = v[66]; spatial_metric_der[0][1][2] = v[67]; - spatial_metric_der[0][2][0] = v[68]; spatial_metric_der[0][2][1] = v[69]; spatial_metric_der[0][2][2] = v[70]; - - double **stress_energy = gkyl_malloc(sizeof(double*[4])); + spatial_metric_der[0][0][0] = v[44]; + spatial_metric_der[0][0][1] = v[45]; + spatial_metric_der[0][0][2] = v[46]; + spatial_metric_der[0][1][0] = v[47]; + spatial_metric_der[0][1][1] = v[48]; + spatial_metric_der[0][1][2] = v[49]; + spatial_metric_der[0][2][0] = v[50]; + spatial_metric_der[0][2][1] = v[51]; + spatial_metric_der[0][2][2] = v[52]; + + spatial_metric_der[1][0][0] = v[53]; + spatial_metric_der[1][0][1] = v[54]; + spatial_metric_der[1][0][2] = v[55]; + spatial_metric_der[1][1][0] = v[56]; + spatial_metric_der[1][1][1] = v[57]; + spatial_metric_der[1][1][2] = v[58]; + spatial_metric_der[1][2][0] = v[59]; + spatial_metric_der[1][2][1] = v[60]; + spatial_metric_der[1][2][2] = v[61]; + + spatial_metric_der[0][0][0] = v[62]; + spatial_metric_der[0][0][1] = v[63]; + spatial_metric_der[0][0][2] = v[64]; + spatial_metric_der[0][1][0] = v[65]; + spatial_metric_der[0][1][1] = v[66]; + spatial_metric_der[0][1][2] = v[67]; + spatial_metric_der[0][2][0] = v[68]; + spatial_metric_der[0][2][1] = v[69]; + spatial_metric_der[0][2][2] = v[70]; + + double **stress_energy = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { stress_energy[i] = gkyl_malloc(sizeof(double[4])); } @@ -1805,7 +2090,9 @@ gr_mhd_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1819,7 +2106,9 @@ gr_mhd_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) } double mag[3]; - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double cov_mag[3]; for (int i = 0; i < 3; i++) { @@ -1838,14 +2127,16 @@ gr_mhd_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double spacetime_vel[4]; spacetime_vel[0] = W / lapse; @@ -1884,9 +2175,12 @@ gr_mhd_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) sout[4] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - sout[4] += (lapse * sqrt(spatial_det)) * (stress_energy[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); - sout[4] += (lapse * sqrt(spatial_det)) * (2.0 * stress_energy[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); - sout[4] += (lapse * sqrt(spatial_det)) * (stress_energy[i + 1][j + 1] * extrinsic_curvature[i][j]); + sout[4] += (lapse * sqrt(spatial_det)) * + (stress_energy[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); + sout[4] += (lapse * sqrt(spatial_det)) * + (2.0 * stress_energy[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); + sout[4] += + (lapse * sqrt(spatial_det)) * (stress_energy[i + 1][j + 1] * extrinsic_curvature[i][j]); } sout[4] -= (lapse * sqrt(spatial_det)) * (stress_energy[0][0] * shift[i] * lapse_der[i]); @@ -1899,19 +2193,21 @@ gr_mhd_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - sout[1 + j] += (lapse * sqrt(spatial_det)) * (0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]); - sout[1 + j] += (lapse * sqrt(spatial_det)) * (0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]); + sout[1 + j] += (lapse * sqrt(spatial_det)) * (0.5 * stress_energy[0][0] * shift[k] * + shift[l] * spatial_metric_der[j][k][l]); + sout[1 + j] += (lapse * sqrt(spatial_det)) * + (0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]); } sout[1 + j] += (lapse * sqrt(spatial_det)) * ((mom[k] / lapse) * shift_der[j][k]); for (int i = 0; i < 3; i++) { - sout[1 + j] += (lapse * sqrt(spatial_det)) * (stress_energy[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); + sout[1 + j] += (lapse * sqrt(spatial_det)) * + (stress_energy[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); } } } - } - else { + } else { for (int i = 0; i < 75; i++) { sout[i] = 0.0; } @@ -1923,10 +2219,9 @@ gr_mhd_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) gkyl_free(stress_energy); } -void -gkyl_gr_mhd_free(const struct gkyl_ref_count* ref) +void gkyl_gr_mhd_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. @@ -1938,25 +2233,23 @@ gkyl_gr_mhd_free(const struct gkyl_ref_count* ref) gkyl_free(gr_mhd); } -struct gkyl_wv_eqn* -gkyl_wv_gr_mhd_new(double gas_gamma, double light_speed, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, - struct gkyl_gr_spacetime* spacetime, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_gr_mhd_new( + double gas_gamma, double light_speed, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, + int reinit_freq, struct gkyl_gr_spacetime *spacetime, bool use_gpu +) { - return gkyl_wv_gr_mhd_inew(&(struct gkyl_wv_gr_mhd_inp) { - .gas_gamma = gas_gamma, - .light_speed = light_speed, - .b_fact = b_fact, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .spacetime = spacetime, - .rp_type = WV_GR_MHD_RP_HLL, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_gr_mhd_inew(&(struct gkyl_wv_gr_mhd_inp + ){.gas_gamma = gas_gamma, + .light_speed = light_speed, + .b_fact = b_fact, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .spacetime = spacetime, + .rp_type = WV_GR_MHD_RP_HLL, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_gr_mhd_inew(const struct gkyl_wv_gr_mhd_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_gr_mhd_inew(const struct gkyl_wv_gr_mhd_inp *inp) { struct wv_gr_mhd *gr_mhd = gkyl_malloc(sizeof(struct wv_gr_mhd)); @@ -1975,8 +2268,7 @@ gkyl_wv_gr_mhd_inew(const struct gkyl_wv_gr_mhd_inp* inp) gr_mhd->eqn.num_waves = 2; gr_mhd->eqn.waves_func = wave_lax_l; gr_mhd->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_GR_MHD_RP_HLL) { + } else if (inp->rp_type == WV_GR_MHD_RP_HLL) { gr_mhd->eqn.num_waves = 2; gr_mhd->eqn.waves_func = wave_hll_l; gr_mhd->eqn.qfluct_func = qfluct_hll_l; @@ -2008,8 +2300,7 @@ gkyl_wv_gr_mhd_inew(const struct gkyl_wv_gr_mhd_inp* inp) return &gr_mhd->eqn; } -double -gkyl_wv_gr_mhd_gas_gamma(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_mhd_gas_gamma(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); double gas_gamma = gr_mhd->gas_gamma; @@ -2017,8 +2308,7 @@ gkyl_wv_gr_mhd_gas_gamma(const struct gkyl_wv_eqn* eqn) return gas_gamma; } -double -gkyl_wv_gr_mhd_light_speed(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_mhd_light_speed(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); double light_speed = gr_mhd->light_speed; @@ -2026,8 +2316,7 @@ gkyl_wv_gr_mhd_light_speed(const struct gkyl_wv_eqn* eqn) return light_speed; } -double -gkyl_wv_gr_mhd_b_fact(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_mhd_b_fact(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); double b_fact = gr_mhd->b_fact; @@ -2035,8 +2324,7 @@ gkyl_wv_gr_mhd_b_fact(const struct gkyl_wv_eqn* eqn) return b_fact; } -enum gkyl_spacetime_gauge -gkyl_wv_gr_mhd_spacetime_gauge(const struct gkyl_wv_eqn* eqn) +enum gkyl_spacetime_gauge gkyl_wv_gr_mhd_spacetime_gauge(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); enum gkyl_spacetime_gauge spacetime_gauge = gr_mhd->spacetime_gauge; @@ -2044,8 +2332,7 @@ gkyl_wv_gr_mhd_spacetime_gauge(const struct gkyl_wv_eqn* eqn) return spacetime_gauge; } -int -gkyl_wv_gr_mhd_reinit_freq(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_gr_mhd_reinit_freq(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); int reinit_freq = gr_mhd->reinit_freq; @@ -2053,8 +2340,7 @@ gkyl_wv_gr_mhd_reinit_freq(const struct gkyl_wv_eqn* eqn) return reinit_freq; } -struct gkyl_gr_spacetime* -gkyl_wv_gr_mhd_spacetime(const struct gkyl_wv_eqn* eqn) +struct gkyl_gr_spacetime *gkyl_wv_gr_mhd_spacetime(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd *gr_mhd = container_of(eqn, struct wv_gr_mhd, eqn); struct gkyl_gr_spacetime *spacetime = gr_mhd->spacetime; diff --git a/moments/zero/wv_gr_mhd_tetrad.c b/moments/zero/wv_gr_mhd_tetrad.c index 09152ba958..d8f0dd9551 100644 --- a/moments/zero/wv_gr_mhd_tetrad.c +++ b/moments/zero/wv_gr_mhd_tetrad.c @@ -6,10 +6,11 @@ #include #include -void -gkyl_gr_mhd_tetrad_flux(double gas_gamma, double light_speed, double b_fact, const double q[75], double flux[75]) +void gkyl_gr_mhd_tetrad_flux( + double gas_gamma, double light_speed, double b_fact, const double q[75], double flux[75] +) { - double v[75] = { 0.0 }; + double v[75] = {0.0}; gkyl_gr_mhd_tetrad_prim_vars(gas_gamma, q, v); double rho = v[0]; double vx = v[1]; @@ -62,18 +63,19 @@ gkyl_gr_mhd_tetrad_flux(double gas_gamma, double light_speed, double b_fact, con for (int i = 9; i < 75; i++) { flux[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 75; i++) { flux[i] = 0.0; } } } -void -gkyl_gr_mhd_tetrad_flux_correction(double gas_gamma, double light_speed, double b_fact, const double q[75], const double flux_sr[75], double flux_gr[75]) +void gkyl_gr_mhd_tetrad_flux_correction( + double gas_gamma, double light_speed, double b_fact, const double q[75], const double flux_sr[75], + double flux_gr[75] +) { - double v[75] = { 0.0 }; + double v[75] = {0.0}; gkyl_gr_mhd_tetrad_prim_vars(gas_gamma, q, v); double rho = v[0]; double vx = v[1]; @@ -92,13 +94,22 @@ gkyl_gr_mhd_tetrad_flux_correction(double gas_gamma, double light_speed, double double shift_z = v[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[13]; spatial_metric[0][1] = v[14]; spatial_metric[0][2] = v[15]; - spatial_metric[1][0] = v[16]; spatial_metric[1][1] = v[17]; spatial_metric[1][2] = v[18]; - spatial_metric[2][0] = v[19]; spatial_metric[2][1] = v[20]; spatial_metric[2][2] = v[21]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + spatial_metric[0][0] = v[13]; + spatial_metric[0][1] = v[14]; + spatial_metric[0][2] = v[15]; + spatial_metric[1][0] = v[16]; + spatial_metric[1][1] = v[17]; + spatial_metric[1][2] = v[18]; + spatial_metric[2][0] = v[19]; + spatial_metric[2][1] = v[20]; + spatial_metric[2][2] = v[21]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); bool in_excision_region = false; if (v[31] < pow(10.0, -8.0)) { @@ -108,7 +119,9 @@ gkyl_gr_mhd_tetrad_flux_correction(double gas_gamma, double light_speed, double if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -130,10 +143,13 @@ gkyl_gr_mhd_tetrad_flux_correction(double gas_gamma, double light_speed, double double b1_flat = (mag_x / W_flat) + (b0_flat * vx); double b2_flat = (mag_y / W_flat) + (b0_flat * vy); double b3_flat = (mag_z / W_flat) + (b0_flat * vz); - double b_sq_flat = ((mag_x * mag_x) + (mag_y * mag_y) + (mag_z * mag_z) + (b0_flat * b0_flat)) / (W_flat * W_flat); + double b_sq_flat = ((mag_x * mag_x) + (mag_y * mag_y) + (mag_z * mag_z) + (b0_flat * b0_flat)) / + (W_flat * W_flat); double mag[3]; - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double cov_mag[3]; for (int i = 0; i < 3; i++) { @@ -152,14 +168,16 @@ gkyl_gr_mhd_tetrad_flux_correction(double gas_gamma, double light_speed, double cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0_curved = 0.0; for (int i = 0; i < 3; i++) { b0_curved += W_curved * mag[i] * (cov_vel[i] / lapse); } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double spacetime_vel[4]; spacetime_vel[0] = W_curved / lapse; @@ -190,69 +208,85 @@ gkyl_gr_mhd_tetrad_flux_correction(double gas_gamma, double light_speed, double double h_star_flat = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))) + (b_sq_flat / rho); double p_star_flat = p + (0.5 * b_sq_flat); - double h_star_curved = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))) + (b_sq_curved / rho); + double h_star_curved = + 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))) + (b_sq_curved / rho); double p_star_curved = p + (0.5 * b_sq_curved); if (fabs(vx) < pow(10.0, -12.0)) { if (vx > 0.0) { vx = pow(10.0, -12.0); - } - else { + } else { vx = -pow(10.0, -12.0); } } if (fabs(vy) < pow(10.0, -12.0)) { if (vy > 0.0) { vy = pow(10.0, -12.0); - } - else { + } else { vy = -pow(10.0, -12.0); } } if (fabs(vz) < pow(10.0, -12.0)) { if (vz > 0.0) { vz = pow(10.0, -12.0); - } - else { + } else { vz = -pow(10.0, -12.0); } } - flux_gr[0] = (lapse * sqrt(spatial_det)) * ((flux_sr[0] * (vx - (shift_x / lapse)) * W_curved) / (vx * W_flat)); - - flux_gr[1] = (lapse * sqrt(spatial_det)) * (((((((flux_sr[1] - p_star_flat + ((b1_flat * mag_x) / W_flat)) / vx) + (b0_flat * b1_flat)) * - ((h_star_curved * (W_curved * W_curved) * cov_vel[0]) / (h_star_flat * (W_flat * W_flat) * vx))) - (lapse * b0_curved * cov_b[0])) * - (vx - (shift_x / lapse))) + p_star_curved - ((cov_b[0] * mag_x) / W_curved)); - flux_gr[2] = (lapse * sqrt(spatial_det)) * (((((((flux_sr[2] + ((b2_flat * mag_x) / W_flat)) / vx) + (b0_flat * b2_flat)) * - ((h_star_curved * (W_curved * W_curved) * cov_vel[1]) / (h_star_flat * (W_flat * W_flat) * vy))) - (lapse * b0_curved * cov_b[1])) * - (vx - (shift_x / lapse))) - ((cov_b[1] * mag_x) / W_curved)); - flux_gr[3] = (lapse * sqrt(spatial_det)) * (((((((flux_sr[3] + ((b3_flat * mag_x) / W_flat)) / vx) + (b0_flat * b3_flat)) * - ((h_star_curved * (W_curved * W_curved) * cov_vel[2]) / (h_star_flat * (W_flat * W_flat) * vz))) - (lapse * b0_curved * cov_b[2])) * - (vx - (shift_x / lapse))) - ((cov_b[2] * mag_x) / W_curved)); - - flux_gr[4] = (lapse * sqrt(spatial_det)) * (((((((flux_sr[4] - (p_star_flat * vx) + ((b0_flat * mag_x) / W_flat)) / vx) + p_star_flat + - (b0_flat * b0_flat) + (rho * W_flat)) * ((h_star_curved * (W_curved * W_curved)) / (h_star_flat * (W_flat * W_flat)))) - p_star_curved - - ((lapse * lapse) * (b0_curved * b0_curved)) - (rho * W_curved)) * (vx - (shift_x / lapse))) + (p_star_curved * vx) - - (lapse * ((b0_curved * mag_x) / W_curved))); + flux_gr[0] = (lapse * sqrt(spatial_det)) * + ((flux_sr[0] * (vx - (shift_x / lapse)) * W_curved) / (vx * W_flat)); + + flux_gr[1] = + (lapse * sqrt(spatial_det)) * + (((((((flux_sr[1] - p_star_flat + ((b1_flat * mag_x) / W_flat)) / vx) + (b0_flat * b1_flat)) * + ((h_star_curved * (W_curved * W_curved) * cov_vel[0]) / + (h_star_flat * (W_flat * W_flat) * vx))) - + (lapse * b0_curved * cov_b[0])) * + (vx - (shift_x / lapse))) + + p_star_curved - ((cov_b[0] * mag_x) / W_curved)); + flux_gr[2] = (lapse * sqrt(spatial_det)) * + (((((((flux_sr[2] + ((b2_flat * mag_x) / W_flat)) / vx) + (b0_flat * b2_flat)) * + ((h_star_curved * (W_curved * W_curved) * cov_vel[1]) / + (h_star_flat * (W_flat * W_flat) * vy))) - + (lapse * b0_curved * cov_b[1])) * + (vx - (shift_x / lapse))) - + ((cov_b[1] * mag_x) / W_curved)); + flux_gr[3] = (lapse * sqrt(spatial_det)) * + (((((((flux_sr[3] + ((b3_flat * mag_x) / W_flat)) / vx) + (b0_flat * b3_flat)) * + ((h_star_curved * (W_curved * W_curved) * cov_vel[2]) / + (h_star_flat * (W_flat * W_flat) * vz))) - + (lapse * b0_curved * cov_b[2])) * + (vx - (shift_x / lapse))) - + ((cov_b[2] * mag_x) / W_curved)); + + flux_gr[4] = + (lapse * sqrt(spatial_det)) * + (((((((flux_sr[4] - (p_star_flat * vx) + ((b0_flat * mag_x) / W_flat)) / vx) + p_star_flat + + (b0_flat * b0_flat) + (rho * W_flat)) * + ((h_star_curved * (W_curved * W_curved)) / (h_star_flat * (W_flat * W_flat)))) - + p_star_curved - ((lapse * lapse) * (b0_curved * b0_curved)) - (rho * W_curved)) * + (vx - (shift_x / lapse))) + + (p_star_curved * vx) - (lapse * ((b0_curved * mag_x) / W_curved))); flux_gr[5] = (lapse * sqrt(spatial_det)) * flux_sr[5]; - flux_gr[6] = (lapse * sqrt(spatial_det)) * (flux_sr[6] - ((shift_x / lapse) * mag_y) + ((shift_y / lapse) * mag_x)); - flux_gr[7] = (lapse * sqrt(spatial_det)) * (flux_sr[7] - ((shift_x / lapse) * mag_z) + ((shift_z / lapse) * mag_x)); + flux_gr[6] = (lapse * sqrt(spatial_det)) * + (flux_sr[6] - ((shift_x / lapse) * mag_y) + ((shift_y / lapse) * mag_x)); + flux_gr[7] = (lapse * sqrt(spatial_det)) * + (flux_sr[7] - ((shift_x / lapse) * mag_z) + ((shift_z / lapse) * mag_x)); flux_gr[8] = (lapse * sqrt(spatial_det)) * flux_sr[8]; for (int i = 9; i < 75; i++) { flux_gr[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 75; i++) { flux_gr[i] = 0.0; } } } -void -gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) +void gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) { double lapse = q[9]; double shift_x = q[10]; @@ -260,21 +294,33 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) double shift_z = q[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = q[13]; spatial_metric[0][1] = q[14]; spatial_metric[0][2] = q[15]; - spatial_metric[1][0] = q[16]; spatial_metric[1][1] = q[17]; spatial_metric[1][2] = q[18]; - spatial_metric[2][0] = q[19]; spatial_metric[2][1] = q[20]; spatial_metric[2][2] = q[21]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = q[13]; + spatial_metric[0][1] = q[14]; + spatial_metric[0][2] = q[15]; + spatial_metric[1][0] = q[16]; + spatial_metric[1][1] = q[17]; + spatial_metric[1][2] = q[18]; + spatial_metric[2][0] = q[19]; + spatial_metric[2][1] = q[20]; + spatial_metric[2][2] = q[21]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } gkyl_gr_mhd_tetrad_inv_spatial_metric(q, &inv_spatial_metric); - + double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = q[22]; extrinsic_curvature[0][1] = q[23]; extrinsic_curvature[0][2] = q[24]; - extrinsic_curvature[1][0] = q[25]; extrinsic_curvature[1][1] = q[26]; extrinsic_curvature[1][2] = q[27]; - extrinsic_curvature[2][0] = q[28]; extrinsic_curvature[2][1] = q[29]; extrinsic_curvature[2][2] = q[30]; + extrinsic_curvature[0][0] = q[22]; + extrinsic_curvature[0][1] = q[23]; + extrinsic_curvature[0][2] = q[24]; + extrinsic_curvature[1][0] = q[25]; + extrinsic_curvature[1][1] = q[26]; + extrinsic_curvature[1][2] = q[27]; + extrinsic_curvature[2][0] = q[28]; + extrinsic_curvature[2][1] = q[29]; + extrinsic_curvature[2][2] = q[30]; double lapse_der[3]; lapse_der[0] = q[32]; @@ -282,22 +328,46 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) lapse_der[2] = q[34]; double shift_der[3][3]; - shift_der[0][0] = q[35]; shift_der[0][1] = q[36]; shift_der[0][2] = q[37]; - shift_der[1][0] = q[38]; shift_der[1][1] = q[39]; shift_der[1][2] = q[40]; - shift_der[2][0] = q[41]; shift_der[2][1] = q[42]; shift_der[2][2] = q[43]; + shift_der[0][0] = q[35]; + shift_der[0][1] = q[36]; + shift_der[0][2] = q[37]; + shift_der[1][0] = q[38]; + shift_der[1][1] = q[39]; + shift_der[1][2] = q[40]; + shift_der[2][0] = q[41]; + shift_der[2][1] = q[42]; + shift_der[2][2] = q[43]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = q[44]; spatial_metric_der[0][0][1] = q[45]; spatial_metric_der[0][0][2] = q[46]; - spatial_metric_der[0][1][0] = q[47]; spatial_metric_der[0][1][1] = q[48]; spatial_metric_der[0][1][2] = q[49]; - spatial_metric_der[0][2][0] = q[50]; spatial_metric_der[0][2][1] = q[51]; spatial_metric_der[0][2][2] = q[52]; - - spatial_metric_der[1][0][0] = q[53]; spatial_metric_der[1][0][1] = q[54]; spatial_metric_der[1][0][2] = q[55]; - spatial_metric_der[1][1][0] = q[56]; spatial_metric_der[1][1][1] = q[57]; spatial_metric_der[1][1][2] = q[58]; - spatial_metric_der[1][2][0] = q[59]; spatial_metric_der[1][2][1] = q[60]; spatial_metric_der[1][2][2] = q[61]; - - spatial_metric_der[0][0][0] = q[62]; spatial_metric_der[0][0][1] = q[63]; spatial_metric_der[0][0][2] = q[64]; - spatial_metric_der[0][1][0] = q[65]; spatial_metric_der[0][1][1] = q[66]; spatial_metric_der[0][1][2] = q[67]; - spatial_metric_der[0][2][0] = q[68]; spatial_metric_der[0][2][1] = q[69]; spatial_metric_der[0][2][2] = q[70]; + spatial_metric_der[0][0][0] = q[44]; + spatial_metric_der[0][0][1] = q[45]; + spatial_metric_der[0][0][2] = q[46]; + spatial_metric_der[0][1][0] = q[47]; + spatial_metric_der[0][1][1] = q[48]; + spatial_metric_der[0][1][2] = q[49]; + spatial_metric_der[0][2][0] = q[50]; + spatial_metric_der[0][2][1] = q[51]; + spatial_metric_der[0][2][2] = q[52]; + + spatial_metric_der[1][0][0] = q[53]; + spatial_metric_der[1][0][1] = q[54]; + spatial_metric_der[1][0][2] = q[55]; + spatial_metric_der[1][1][0] = q[56]; + spatial_metric_der[1][1][1] = q[57]; + spatial_metric_der[1][1][2] = q[58]; + spatial_metric_der[1][2][0] = q[59]; + spatial_metric_der[1][2][1] = q[60]; + spatial_metric_der[1][2][2] = q[61]; + + spatial_metric_der[0][0][0] = q[62]; + spatial_metric_der[0][0][1] = q[63]; + spatial_metric_der[0][0][2] = q[64]; + spatial_metric_der[0][1][0] = q[65]; + spatial_metric_der[0][1][1] = q[66]; + spatial_metric_der[0][1][2] = q[67]; + spatial_metric_der[0][2][0] = q[68]; + spatial_metric_der[0][2][1] = q[69]; + spatial_metric_der[0][2][2] = q[70]; double evol_param = q[71]; double x = q[72]; @@ -310,9 +380,12 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) } if (!in_excision_region) { - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double D = q[0] / sqrt(spatial_det); double momx = q[1] / sqrt(spatial_det); @@ -326,7 +399,9 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) double psi = q[8] / sqrt(spatial_det); double cov_mom[3]; - cov_mom[0] = momx; cov_mom[1] = momy; cov_mom[2] = momz; + cov_mom[0] = momx; + cov_mom[1] = momy; + cov_mom[2] = momz; double mom[3]; for (int i = 0; i < 3; i++) { @@ -343,7 +418,9 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) } double mag[3]; - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double cov_mag[3]; for (int i = 0; i < 3; i++) { @@ -353,7 +430,7 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) cov_mag[i] += spatial_metric[i][j] * mag[j]; } } - + double mag_sq = 0.0; for (int i = 0; i < 3; i++) { mag_sq += mag[i] * cov_mag[i]; @@ -372,10 +449,12 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) double d = 0.5 * ((M_sq * mag_sq) - (tau_star * tau_star)); double phi = acos((1.0 / a) * sqrt((27.0 * d) / (4.0 * a))); - double epsilon1 = ((1.0 / 3.0) * a) - ((2.0 / 3.0) * a * cos(((2.0 / 3.0) * phi) + ((2.0 / 3.0) * M_PI))); + double epsilon1 = + ((1.0 / 3.0) * a) - ((2.0 / 3.0) * a * cos(((2.0 / 3.0) * phi) + ((2.0 / 3.0) * M_PI))); z = epsilon1 - mag_sq; - double v_sq = ((M_sq * (z * z)) + ((tau_star * tau_star) * (mag_sq + (2.0 * z)))) / ((z * z) * (mag_sq + z) * (mag_sq + z)); + double v_sq = ((M_sq * (z * z)) + ((tau_star * tau_star) * (mag_sq + (2.0 * z)))) / + ((z * z) * (mag_sq + z) * (mag_sq + z)); double W = 1.0 / sqrt(1.0 - v_sq); rho = D / W; double h = z / (W * W * rho); @@ -384,8 +463,7 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) if (fabs(p_guess - p_new) < pow(10.0, -15.0)) { iter = 100; - } - else { + } else { iter += 1; p_guess = p_new; } @@ -424,13 +502,25 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) v[11] = shift_y; v[12] = shift_z; - v[13] = spatial_metric[0][0]; v[14] = spatial_metric[0][1]; v[15] = spatial_metric[0][2]; - v[16] = spatial_metric[1][0]; v[17] = spatial_metric[1][1]; v[18] = spatial_metric[1][2]; - v[19] = spatial_metric[2][0]; v[20] = spatial_metric[2][1]; v[21] = spatial_metric[2][2]; - - v[22] = extrinsic_curvature[0][0]; v[23] = extrinsic_curvature[0][1]; v[24] = extrinsic_curvature[0][2]; - v[25] = extrinsic_curvature[1][0]; v[26] = extrinsic_curvature[1][1]; v[27] = extrinsic_curvature[1][2]; - v[28] = extrinsic_curvature[2][0]; v[29] = extrinsic_curvature[2][1]; v[30] = extrinsic_curvature[2][2]; + v[13] = spatial_metric[0][0]; + v[14] = spatial_metric[0][1]; + v[15] = spatial_metric[0][2]; + v[16] = spatial_metric[1][0]; + v[17] = spatial_metric[1][1]; + v[18] = spatial_metric[1][2]; + v[19] = spatial_metric[2][0]; + v[20] = spatial_metric[2][1]; + v[21] = spatial_metric[2][2]; + + v[22] = extrinsic_curvature[0][0]; + v[23] = extrinsic_curvature[0][1]; + v[24] = extrinsic_curvature[0][2]; + v[25] = extrinsic_curvature[1][0]; + v[26] = extrinsic_curvature[1][1]; + v[27] = extrinsic_curvature[1][2]; + v[28] = extrinsic_curvature[2][0]; + v[29] = extrinsic_curvature[2][1]; + v[30] = extrinsic_curvature[2][2]; v[31] = 1.0; @@ -438,32 +528,55 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) v[33] = lapse_der[1]; v[34] = lapse_der[2]; - v[35] = shift_der[0][0]; v[36] = shift_der[0][1]; v[37] = shift_der[0][2]; - v[38] = shift_der[1][0]; v[39] = shift_der[1][1]; v[40] = shift_der[1][2]; - v[41] = shift_der[2][0]; v[42] = shift_der[2][1]; v[43] = shift_der[2][2]; - - v[44] = spatial_metric_der[0][0][0]; v[45] = spatial_metric_der[0][0][1]; v[46] = spatial_metric_der[0][0][2]; - v[47] = spatial_metric_der[0][1][0]; v[48] = spatial_metric_der[0][1][1]; v[49] = spatial_metric_der[0][1][2]; - v[50] = spatial_metric_der[0][2][0]; v[51] = spatial_metric_der[0][2][1]; v[52] = spatial_metric_der[0][2][2]; - - v[53] = spatial_metric_der[1][0][0]; v[54] = spatial_metric_der[1][0][1]; v[55] = spatial_metric_der[1][0][2]; - v[56] = spatial_metric_der[1][1][0]; v[57] = spatial_metric_der[1][1][1]; v[58] = spatial_metric_der[1][1][2]; - v[59] = spatial_metric_der[1][2][0]; v[60] = spatial_metric_der[1][2][1]; v[61] = spatial_metric_der[1][2][2]; - - v[62] = spatial_metric_der[2][0][0]; v[63] = spatial_metric_der[2][0][1]; v[64] = spatial_metric_der[2][0][2]; - v[65] = spatial_metric_der[2][1][0]; v[66] = spatial_metric_der[2][1][1]; v[67] = spatial_metric_der[2][1][2]; - v[68] = spatial_metric_der[2][2][0]; v[69] = spatial_metric_der[2][2][1]; v[70] = spatial_metric_der[2][2][2]; + v[35] = shift_der[0][0]; + v[36] = shift_der[0][1]; + v[37] = shift_der[0][2]; + v[38] = shift_der[1][0]; + v[39] = shift_der[1][1]; + v[40] = shift_der[1][2]; + v[41] = shift_der[2][0]; + v[42] = shift_der[2][1]; + v[43] = shift_der[2][2]; + + v[44] = spatial_metric_der[0][0][0]; + v[45] = spatial_metric_der[0][0][1]; + v[46] = spatial_metric_der[0][0][2]; + v[47] = spatial_metric_der[0][1][0]; + v[48] = spatial_metric_der[0][1][1]; + v[49] = spatial_metric_der[0][1][2]; + v[50] = spatial_metric_der[0][2][0]; + v[51] = spatial_metric_der[0][2][1]; + v[52] = spatial_metric_der[0][2][2]; + + v[53] = spatial_metric_der[1][0][0]; + v[54] = spatial_metric_der[1][0][1]; + v[55] = spatial_metric_der[1][0][2]; + v[56] = spatial_metric_der[1][1][0]; + v[57] = spatial_metric_der[1][1][1]; + v[58] = spatial_metric_der[1][1][2]; + v[59] = spatial_metric_der[1][2][0]; + v[60] = spatial_metric_der[1][2][1]; + v[61] = spatial_metric_der[1][2][2]; + + v[62] = spatial_metric_der[2][0][0]; + v[63] = spatial_metric_der[2][0][1]; + v[64] = spatial_metric_der[2][0][2]; + v[65] = spatial_metric_der[2][1][0]; + v[66] = spatial_metric_der[2][1][1]; + v[67] = spatial_metric_der[2][1][2]; + v[68] = spatial_metric_der[2][2][0]; + v[69] = spatial_metric_der[2][2][1]; + v[70] = spatial_metric_der[2][2][2]; v[71] = evol_param; v[72] = x; v[73] = y; v[74] = z; - } - else { + } else { for (int i = 0; i < 75; i++) { v[i] = 0.0; } - + v[31] = -1.0; } @@ -473,18 +586,26 @@ gkyl_gr_mhd_tetrad_prim_vars(double gas_gamma, const double q[75], double v[75]) gkyl_free(inv_spatial_metric); } -void -gkyl_gr_mhd_tetrad_inv_spatial_metric(const double q[75], double ***inv_spatial_metric) +void gkyl_gr_mhd_tetrad_inv_spatial_metric(const double q[75], double ***inv_spatial_metric) { double spatial_metric[3][3]; - spatial_metric[0][0] = q[13]; spatial_metric[0][1] = q[14]; spatial_metric[0][2] = q[15]; - spatial_metric[1][0] = q[16]; spatial_metric[1][1] = q[17]; spatial_metric[1][2] = q[18]; - spatial_metric[2][0] = q[19]; spatial_metric[2][1] = q[20]; spatial_metric[2][2] = q[21]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = q[13]; + spatial_metric[0][1] = q[14]; + spatial_metric[0][2] = q[15]; + spatial_metric[1][0] = q[16]; + spatial_metric[1][1] = q[17]; + spatial_metric[1][2] = q[18]; + spatial_metric[2][0] = q[19]; + spatial_metric[2][1] = q[20]; + spatial_metric[2][2] = q[21]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -515,8 +636,7 @@ gkyl_gr_mhd_tetrad_inv_spatial_metric(const double q[75], double ***inv_spatial_ for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -524,16 +644,18 @@ gkyl_gr_mhd_tetrad_inv_spatial_metric(const double q[75], double ***inv_spatial_ for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*inv_spatial_metric)[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*inv_spatial_metric)[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } } -void -gkyl_gr_mhd_tetrad_stress_energy_tensor(double gas_gamma, const double q[75], double ***stress_energy) +void gkyl_gr_mhd_tetrad_stress_energy_tensor( + double gas_gamma, const double q[75], double ***stress_energy +) { - double v[75] = { 0.0 }; + double v[75] = {0.0}; gkyl_gr_mhd_tetrad_prim_vars(gas_gamma, q, v); double rho = v[0]; double vx = v[1]; @@ -552,11 +674,17 @@ gkyl_gr_mhd_tetrad_stress_energy_tensor(double gas_gamma, const double q[75], do double shift_z = v[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[13]; spatial_metric[0][1] = v[14]; spatial_metric[0][2] = v[15]; - spatial_metric[1][0] = v[16]; spatial_metric[1][1] = v[17]; spatial_metric[1][2] = v[18]; - spatial_metric[2][0] = v[19]; spatial_metric[2][1] = v[20]; spatial_metric[2][2] = v[21]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[13]; + spatial_metric[0][1] = v[14]; + spatial_metric[0][2] = v[15]; + spatial_metric[1][0] = v[16]; + spatial_metric[1][1] = v[17]; + spatial_metric[1][2] = v[18]; + spatial_metric[2][0] = v[19]; + spatial_metric[2][1] = v[20]; + spatial_metric[2][2] = v[21]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -571,7 +699,9 @@ gkyl_gr_mhd_tetrad_stress_energy_tensor(double gas_gamma, const double q[75], do if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -585,7 +715,9 @@ gkyl_gr_mhd_tetrad_stress_energy_tensor(double gas_gamma, const double q[75], do } double mag[3]; - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double cov_mag[3]; for (int i = 0; i < 3; i++) { @@ -604,14 +736,16 @@ gkyl_gr_mhd_tetrad_stress_energy_tensor(double gas_gamma, const double q[75], do cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double spacetime_vel[4]; spacetime_vel[0] = W / lapse; @@ -643,14 +777,15 @@ gkyl_gr_mhd_tetrad_stress_energy_tensor(double gas_gamma, const double q[75], do double p_star = p + (0.5 * b_sq); double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } @@ -662,11 +797,12 @@ gkyl_gr_mhd_tetrad_stress_energy_tensor(double gas_gamma, const double q[75], do for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*stress_energy)[i][j] = (rho * h_star * spacetime_vel[i] * spacetime_vel[j]) + (p_star * inv_spacetime_metric[i][j]) - (spacetime_b[i] * spacetime_b[j]); + (*stress_energy)[i][j] = (rho * h_star * spacetime_vel[i] * spacetime_vel[j]) + + (p_star * inv_spacetime_metric[i][j]) - + (spacetime_b[i] * spacetime_b[j]); } } - } - else { + } else { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { (*stress_energy)[i][j] = 0.0; @@ -680,10 +816,9 @@ gkyl_gr_mhd_tetrad_stress_energy_tensor(double gas_gamma, const double q[75], do gkyl_free(inv_spatial_metric); } -static inline double -gkyl_gr_mhd_tetrad_max_abs_speed(double gas_gamma, const double q[75]) +static inline double gkyl_gr_mhd_tetrad_max_abs_speed(double gas_gamma, const double q[75]) { - double v[75] = { 0.0 }; + double v[75] = {0.0}; gkyl_gr_mhd_tetrad_prim_vars(gas_gamma, q, v); double rho = v[0]; double vx = v[1]; @@ -702,11 +837,17 @@ gkyl_gr_mhd_tetrad_max_abs_speed(double gas_gamma, const double q[75]) double shift_z = v[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[13]; spatial_metric[0][1] = v[14]; spatial_metric[0][2] = v[15]; - spatial_metric[1][0] = v[16]; spatial_metric[1][1] = v[17]; spatial_metric[1][2] = v[18]; - spatial_metric[2][0] = v[19]; spatial_metric[2][1] = v[20]; spatial_metric[2][2] = v[21]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[13]; + spatial_metric[0][1] = v[14]; + spatial_metric[0][2] = v[15]; + spatial_metric[1][0] = v[16]; + spatial_metric[1][1] = v[17]; + spatial_metric[1][2] = v[18]; + spatial_metric[2][0] = v[19]; + spatial_metric[2][1] = v[20]; + spatial_metric[2][2] = v[21]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -721,7 +862,9 @@ gkyl_gr_mhd_tetrad_max_abs_speed(double gas_gamma, const double q[75]) if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -735,7 +878,9 @@ gkyl_gr_mhd_tetrad_max_abs_speed(double gas_gamma, const double q[75]) } double mag[3]; - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double cov_mag[3]; for (int i = 0; i < 3; i++) { @@ -754,14 +899,16 @@ gkyl_gr_mhd_tetrad_max_abs_speed(double gas_gamma, const double q[75]) cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double spacetime_vel[4]; spacetime_vel[0] = W / lapse; @@ -796,11 +943,19 @@ gkyl_gr_mhd_tetrad_max_abs_speed(double gas_gamma, const double q[75]) for (int i = 0; i < 3; i++) { entropy_eigs[i] = (lapse * vel[i] - shift[i]); - fast_alfven_eigs[i] = (b[i] + (sqrt(C) * spacetime_vel[i + 1])) / (b0 + (sqrt(C) * spacetime_vel[0])); - slow_alfven_eigs[i] = (b[i] - (sqrt(C) * spacetime_vel[i + 1])) / (b0 - (sqrt(C) * spacetime_vel[0])); + fast_alfven_eigs[i] = + (b[i] + (sqrt(C) * spacetime_vel[i + 1])) / (b0 + (sqrt(C) * spacetime_vel[0])); + slow_alfven_eigs[i] = + (b[i] - (sqrt(C) * spacetime_vel[i + 1])) / (b0 - (sqrt(C) * spacetime_vel[0])); - fast_magnetosonic_eigs[i] = sqrt((fast_alfven_eigs[i] * fast_alfven_eigs[i]) + ((c_s * c_s) * (1.0 - (fast_alfven_eigs[i] * fast_alfven_eigs[i])))); - slow_magnetosonic_eigs[i] = sqrt((slow_alfven_eigs[i] * slow_alfven_eigs[i]) + ((c_s * c_s) * (1.0 - (slow_alfven_eigs[i] * slow_alfven_eigs[i])))); + fast_magnetosonic_eigs[i] = sqrt( + (fast_alfven_eigs[i] * fast_alfven_eigs[i]) + + ((c_s * c_s) * (1.0 - (fast_alfven_eigs[i] * fast_alfven_eigs[i]))) + ); + slow_magnetosonic_eigs[i] = sqrt( + (slow_alfven_eigs[i] * slow_alfven_eigs[i]) + + ((c_s * c_s) * (1.0 - (slow_alfven_eigs[i] * slow_alfven_eigs[i]))) + ); } double max_eig = 0.0; @@ -828,8 +983,7 @@ gkyl_gr_mhd_tetrad_max_abs_speed(double gas_gamma, const double q[75]) gkyl_free(inv_spatial_metric); return fabs(v_sq) + max_eig; - } - else { + } else { for (int i = 0; i < 3; i++) { gkyl_free(inv_spatial_metric[i]); } @@ -840,7 +994,7 @@ gkyl_gr_mhd_tetrad_max_abs_speed(double gas_gamma, const double q[75]) } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 75; i++) { @@ -849,7 +1003,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 75; i++) { @@ -857,8 +1011,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -gr_mhd_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_mhd_tetrad_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 0; i < 75; i++) { ghost[i] = skin[i]; @@ -867,8 +1023,10 @@ gr_mhd_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double ghost[1] = -ghost[1]; } -static void -gr_mhd_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_mhd_tetrad_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 1; i < 4; i++) { ghost[i] = -skin[i]; @@ -882,9 +1040,10 @@ gr_mhd_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const dou } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; qlocal[1] = (qglobal[1] * norm[0]) + (qglobal[2] * norm[1]) + (qglobal[3] * norm[2]); @@ -931,9 +1090,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinate frame. - qlocal[13] = v1[0]; qlocal[14] = v1[1]; qlocal[15] = v1[2]; - qlocal[16] = v2[0]; qlocal[17] = v2[1]; qlocal[18] = v2[2]; - qlocal[19] = v3[0]; qlocal[20] = v3[1]; qlocal[21] = v3[2]; + qlocal[13] = v1[0]; + qlocal[14] = v1[1]; + qlocal[15] = v1[2]; + qlocal[16] = v2[0]; + qlocal[17] = v2[1]; + qlocal[18] = v2[2]; + qlocal[19] = v3[0]; + qlocal[20] = v3[1]; + qlocal[21] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -964,9 +1129,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta inv_v3[2] = (extr_r1[2] * tau2[0]) + (extr_r2[2] * tau2[1]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor to local coordinate frame. - qlocal[22] = inv_v1[0]; qlocal[23] = inv_v1[1]; qlocal[24] = inv_v1[2]; - qlocal[25] = inv_v2[0]; qlocal[26] = inv_v2[1]; qlocal[27] = inv_v2[2]; - qlocal[28] = inv_v3[0]; qlocal[29] = inv_v3[1]; qlocal[30] = inv_v3[2]; + qlocal[22] = inv_v1[0]; + qlocal[23] = inv_v1[1]; + qlocal[24] = inv_v1[2]; + qlocal[25] = inv_v2[0]; + qlocal[26] = inv_v2[1]; + qlocal[27] = inv_v2[2]; + qlocal[28] = inv_v3[0]; + qlocal[29] = inv_v3[1]; + qlocal[30] = inv_v3[2]; qlocal[31] = qglobal[31]; @@ -990,22 +1161,37 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); - shiftder_v1[1] = (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); - shiftder_v1[2] = (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); - shiftder_v2[1] = (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); - shiftder_v2[2] = (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); - shiftder_v3[1] = (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); - shiftder_v3[2] = (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); + shiftder_v1[1] = + (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); + shiftder_v1[2] = + (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); + shiftder_v2[1] = + (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); + shiftder_v2[2] = + (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); + shiftder_v3[1] = + (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); + shiftder_v3[2] = + (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative to local coordinate frame. - qlocal[35] = shiftder_v1[0]; qlocal[36] = shiftder_v1[1]; qlocal[37] = shiftder_v1[2]; - qlocal[38] = shiftder_v2[0]; qlocal[39] = shiftder_v2[1]; qlocal[40] = shiftder_v2[2]; - qlocal[41] = shiftder_v3[0]; qlocal[42] = shiftder_v3[1]; qlocal[43] = shiftder_v3[2]; + qlocal[35] = shiftder_v1[0]; + qlocal[36] = shiftder_v1[1]; + qlocal[37] = shiftder_v1[2]; + qlocal[38] = shiftder_v2[0]; + qlocal[39] = shiftder_v2[1]; + qlocal[40] = shiftder_v2[2]; + qlocal[41] = shiftder_v3[0]; + qlocal[42] = shiftder_v3[1]; + qlocal[43] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -1088,7 +1274,7 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta s33[0] = (r31[0] * tau2[0]) + (r32[0] * tau2[1]) + (r33[0] * tau2[2]); s33[1] = (r31[1] * tau2[0]) + (r32[1] * tau2[1]) + (r33[1] * tau2[2]); s33[2] = (r31[2] * tau2[0]) + (r32[2] * tau2[1]) + (r33[2] * tau2[2]); - + // Rotate spatial metric tensor derivative to local coordinate frame. qlocal[44] = (s11[0] * norm[0]) + (s21[0] * norm[1]) + (s31[0] * norm[2]); qlocal[45] = (s11[1] * norm[0]) + (s21[1] * norm[1]) + (s31[1] * norm[2]); @@ -1132,9 +1318,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[74] = (qglobal[72] * tau2[0]) + (qglobal[73] * tau2[1]) + (qglobal[74] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; qglobal[1] = (qlocal[1] * norm[0]) + (qlocal[2] * tau1[0]) + (qlocal[3] * tau2[0]); @@ -1181,9 +1368,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor back to global coordinate frame. - qglobal[13] = v1[0]; qglobal[14] = v1[1]; qglobal[15] = v1[2]; - qglobal[16] = v2[0]; qglobal[17] = v2[1]; qglobal[18] = v2[2]; - qglobal[19] = v3[0]; qglobal[20] = v3[1]; qglobal[21] = v3[2]; + qglobal[13] = v1[0]; + qglobal[14] = v1[1]; + qglobal[15] = v1[2]; + qglobal[16] = v2[0]; + qglobal[17] = v2[1]; + qglobal[18] = v2[2]; + qglobal[19] = v3[0]; + qglobal[20] = v3[1]; + qglobal[21] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -1214,9 +1407,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t inv_v3[2] = (extr_r1[2] * norm[2]) + (extr_r2[2] * tau1[2]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor back to global coordinate frame. - qglobal[22] = inv_v1[0]; qglobal[23] = inv_v1[1]; qglobal[24] = inv_v1[2]; - qglobal[25] = inv_v2[0]; qglobal[26] = inv_v2[1]; qglobal[27] = inv_v2[2]; - qglobal[28] = inv_v3[0]; qglobal[29] = inv_v3[1]; qglobal[30] = inv_v3[2]; + qglobal[22] = inv_v1[0]; + qglobal[23] = inv_v1[1]; + qglobal[24] = inv_v1[2]; + qglobal[25] = inv_v2[0]; + qglobal[26] = inv_v2[1]; + qglobal[27] = inv_v2[2]; + qglobal[28] = inv_v3[0]; + qglobal[29] = inv_v3[1]; + qglobal[30] = inv_v3[2]; qglobal[31] = qlocal[31]; @@ -1240,22 +1439,37 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); - shiftder_v1[1] = (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); - shiftder_v1[2] = (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); - shiftder_v2[1] = (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); - shiftder_v2[2] = (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); - shiftder_v3[1] = (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); - shiftder_v3[2] = (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); + shiftder_v1[1] = + (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); + shiftder_v1[2] = + (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); + shiftder_v2[1] = + (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); + shiftder_v2[2] = + (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); + shiftder_v3[1] = + (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); + shiftder_v3[2] = + (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative back to global coordinate frame. - qglobal[35] = shiftder_v1[0]; qglobal[36] = shiftder_v1[1]; qglobal[37] = shiftder_v1[2]; - qglobal[38] = shiftder_v2[0]; qglobal[39] = shiftder_v2[1]; qglobal[40] = shiftder_v2[2]; - qglobal[41] = shiftder_v3[0]; qglobal[42] = shiftder_v3[1]; qglobal[43] = shiftder_v3[2]; + qglobal[35] = shiftder_v1[0]; + qglobal[36] = shiftder_v1[1]; + qglobal[37] = shiftder_v1[2]; + qglobal[38] = shiftder_v2[0]; + qglobal[39] = shiftder_v2[1]; + qglobal[40] = shiftder_v2[2]; + qglobal[41] = shiftder_v3[0]; + qglobal[42] = shiftder_v3[1]; + qglobal[43] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -1382,8 +1596,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[74] = (qlocal[72] * norm[2]) + (qlocal[73] * tau1[2]) + (qlocal[74] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); double gas_gamma = gr_mhd_tetrad->gas_gamma; @@ -1418,8 +1634,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr_gr[i] - fl_gr[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr_gr[i] - fl_gr[i]) / amax); } - } - else { + } else { for (int i = 0; i < 75; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1432,8 +1647,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[75]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1445,21 +1662,27 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); double gas_gamma = gr_mhd_tetrad->gas_gamma; @@ -1487,11 +1710,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_z_l = vl[12]; double spatial_metric_l[3][3]; - spatial_metric_l[0][0] = vl[13]; spatial_metric_l[0][1] = vl[14]; spatial_metric_l[0][2] = vl[15]; - spatial_metric_l[1][0] = vl[16]; spatial_metric_l[1][1] = vl[17]; spatial_metric_l[1][2] = vl[18]; - spatial_metric_l[2][0] = vl[19]; spatial_metric_l[2][1] = vl[20]; spatial_metric_l[2][2] = vl[21]; - - double **inv_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); + spatial_metric_l[0][0] = vl[13]; + spatial_metric_l[0][1] = vl[14]; + spatial_metric_l[0][2] = vl[15]; + spatial_metric_l[1][0] = vl[16]; + spatial_metric_l[1][1] = vl[17]; + spatial_metric_l[1][2] = vl[18]; + spatial_metric_l[2][0] = vl[19]; + spatial_metric_l[2][1] = vl[20]; + spatial_metric_l[2][2] = vl[21]; + + double **inv_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); } @@ -1505,7 +1734,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_l[3]; double v_sq_l = 0.0; - vel_l[0] = vx_l; vel_l[1] = vy_l; vel_l[2] = vz_l; + vel_l[0] = vx_l; + vel_l[1] = vy_l; + vel_l[2] = vz_l; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1519,7 +1750,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double mag_l[3]; - mag_l[0] = mag_x_l; mag_l[1] = mag_y_l; mag_l[2] = mag_z_l; + mag_l[0] = mag_x_l; + mag_l[1] = mag_y_l; + mag_l[2] = mag_z_l; double cov_mag_l[3]; for (int i = 0; i < 3; i++) { @@ -1545,7 +1778,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_l[3]; - shift_l[0] = shift_x_l; shift_l[1] = shift_y_l; shift_l[2] = shift_z_l; + shift_l[0] = shift_x_l; + shift_l[1] = shift_y_l; + shift_l[2] = shift_z_l; double spacetime_vel_l[4]; spacetime_vel_l[0] = W_l / lapse_l; @@ -1588,11 +1823,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_z_r = vr[12]; double spatial_metric_r[3][3]; - spatial_metric_r[0][0] = vr[13]; spatial_metric_r[0][1] = vr[14]; spatial_metric_r[0][2] = vr[15]; - spatial_metric_r[1][0] = vr[16]; spatial_metric_r[1][1] = vr[17]; spatial_metric_r[1][2] = vr[18]; - spatial_metric_r[2][0] = vr[19]; spatial_metric_r[2][1] = vr[20]; spatial_metric_r[2][2] = vr[21]; - - double **inv_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + spatial_metric_r[0][0] = vr[13]; + spatial_metric_r[0][1] = vr[14]; + spatial_metric_r[0][2] = vr[15]; + spatial_metric_r[1][0] = vr[16]; + spatial_metric_r[1][1] = vr[17]; + spatial_metric_r[1][2] = vr[18]; + spatial_metric_r[2][0] = vr[19]; + spatial_metric_r[2][1] = vr[20]; + spatial_metric_r[2][2] = vr[21]; + + double **inv_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } @@ -1606,7 +1847,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_r[3]; double v_sq_r = 0.0; - vel_r[0] = vx_r; vel_r[1] = vy_r; vel_r[2] = vz_r; + vel_r[0] = vx_r; + vel_r[1] = vy_r; + vel_r[2] = vz_r; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1620,7 +1863,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double mag_r[3]; - mag_r[0] = mag_x_r; mag_r[1] = mag_y_r; mag_r[2] = mag_z_r; + mag_r[0] = mag_x_r; + mag_r[1] = mag_y_r; + mag_r[2] = mag_z_r; double cov_mag_r[3]; for (int i = 0; i < 3; i++) { @@ -1646,7 +1891,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_r[3]; - shift_r[0] = shift_x_r; shift_r[1] = shift_y_r; shift_r[2] = shift_z_r; + shift_r[0] = shift_x_r; + shift_r[1] = shift_y_r; + shift_r[2] = shift_z_r; double spacetime_vel_r[4]; spacetime_vel_r[0] = W_r / lapse_r; @@ -1672,19 +1919,35 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double den_r = 1.0 + ((p_r / rho_r) * (gas_gamma) / (gas_gamma - 1.0)); double c_sr = sqrt(num_r / den_r); - double fast_alfven_eig_l = (b_l[0] + (sqrt(C_l) * spacetime_vel_l[1])) / (b0_l + (sqrt(C_l) * spacetime_vel_l[0])); - double slow_alfven_eig_l = (b_l[0] - (sqrt(C_l) * spacetime_vel_l[1])) / (b0_l - (sqrt(C_l) * spacetime_vel_l[0])); - - double fast_magnetosonic_eig_l = sqrt((fast_alfven_eig_l * fast_alfven_eig_l) + ((c_sl * c_sl) * (1.0 - (fast_alfven_eig_l * fast_alfven_eig_l)))); - double slow_magnetosonic_eig_l = sqrt((slow_alfven_eig_l * slow_alfven_eig_l) + ((c_sl * c_sl) * (1.0 - (slow_alfven_eig_l * slow_alfven_eig_l)))); + double fast_alfven_eig_l = + (b_l[0] + (sqrt(C_l) * spacetime_vel_l[1])) / (b0_l + (sqrt(C_l) * spacetime_vel_l[0])); + double slow_alfven_eig_l = + (b_l[0] - (sqrt(C_l) * spacetime_vel_l[1])) / (b0_l - (sqrt(C_l) * spacetime_vel_l[0])); + + double fast_magnetosonic_eig_l = sqrt( + (fast_alfven_eig_l * fast_alfven_eig_l) + + ((c_sl * c_sl) * (1.0 - (fast_alfven_eig_l * fast_alfven_eig_l))) + ); + double slow_magnetosonic_eig_l = sqrt( + (slow_alfven_eig_l * slow_alfven_eig_l) + + ((c_sl * c_sl) * (1.0 - (slow_alfven_eig_l * slow_alfven_eig_l))) + ); double max_eig_l = fmax(fast_magnetosonic_eig_l, slow_magnetosonic_eig_l); - double fast_alfven_eig_r = (b_r[0] + (sqrt(C_r) * spacetime_vel_r[1])) / (b0_r + (sqrt(C_r) * spacetime_vel_r[0])); - double slow_alfven_eig_r = (b_r[0] - (sqrt(C_r) * spacetime_vel_r[1])) / (b0_r - (sqrt(C_r) * spacetime_vel_r[0])); - - double fast_magnetosonic_eig_r = sqrt((fast_alfven_eig_r * fast_alfven_eig_r) + ((c_sr * c_sr) * (1.0 - (fast_alfven_eig_r * fast_alfven_eig_r)))); - double slow_magnetosonic_eig_r = sqrt((slow_alfven_eig_r * slow_alfven_eig_r) + ((c_sr * c_sr) * (1.0 - (slow_alfven_eig_r * slow_alfven_eig_r)))); + double fast_alfven_eig_r = + (b_r[0] + (sqrt(C_r) * spacetime_vel_r[1])) / (b0_r + (sqrt(C_r) * spacetime_vel_r[0])); + double slow_alfven_eig_r = + (b_r[0] - (sqrt(C_r) * spacetime_vel_r[1])) / (b0_r - (sqrt(C_r) * spacetime_vel_r[0])); + + double fast_magnetosonic_eig_r = sqrt( + (fast_alfven_eig_r * fast_alfven_eig_r) + + ((c_sr * c_sr) * (1.0 - (fast_alfven_eig_r * fast_alfven_eig_r))) + ); + double slow_magnetosonic_eig_r = sqrt( + (slow_alfven_eig_r * slow_alfven_eig_r) + + ((c_sr * c_sr) * (1.0 - (slow_alfven_eig_r * slow_alfven_eig_r))) + ); double max_eig_r = fmax(fast_magnetosonic_eig_r, slow_magnetosonic_eig_r); @@ -1713,8 +1976,7 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = qm[i] - ql[i]; w1[i] = qr[i] - qm[i]; } - } - else { + } else { for (int i = 0; i < 75; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1734,8 +1996,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return fmax(fabs(sl), fabs(sr)); } -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[75]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1747,33 +2011,35 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hll(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_hll(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); double gas_gamma = gr_mhd_tetrad->gas_gamma; @@ -1802,8 +2068,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 75; m++) { flux_jump[m] = fr_gr[m] - fl_gr[m]; } - } - else { + } else { for (int m = 0; m < 75; m++) { flux_jump[m] = 0.0; } @@ -1815,25 +2080,22 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); double gas_gamma = gr_mhd_tetrad->gas_gamma; - double v[75] = { 0.0 }; + double v[75] = {0.0}; gkyl_gr_mhd_tetrad_prim_vars(gas_gamma, q, v); if (v[0] < 0.0 || v[4] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); double gas_gamma = gr_mhd_tetrad->gas_gamma; @@ -1842,7 +2104,7 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) } static inline void -gr_mhd_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +gr_mhd_tetrad_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 8; i++) { diag[i] = qin[i]; @@ -1850,12 +2112,12 @@ gr_mhd_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, dou } static inline void -gr_mhd_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +gr_mhd_tetrad_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); double gas_gamma = gr_mhd_tetrad->gas_gamma; - double v[75] = { 0.0 }; + double v[75] = {0.0}; gkyl_gr_mhd_tetrad_prim_vars(gas_gamma, qin, v); double rho = v[0]; double vx = v[1]; @@ -1874,18 +2136,33 @@ gr_mhd_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* s double shift_z = v[12]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[13]; spatial_metric[0][1] = v[14]; spatial_metric[0][2] = v[15]; - spatial_metric[1][0] = v[16]; spatial_metric[1][1] = v[17]; spatial_metric[1][2] = v[18]; - spatial_metric[2][0] = v[19]; spatial_metric[2][1] = v[20]; spatial_metric[2][2] = v[21]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + spatial_metric[0][0] = v[13]; + spatial_metric[0][1] = v[14]; + spatial_metric[0][2] = v[15]; + spatial_metric[1][0] = v[16]; + spatial_metric[1][1] = v[17]; + spatial_metric[1][2] = v[18]; + spatial_metric[2][0] = v[19]; + spatial_metric[2][1] = v[20]; + spatial_metric[2][2] = v[21]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = v[22]; extrinsic_curvature[0][1] = v[23]; extrinsic_curvature[0][2] = v[24]; - extrinsic_curvature[1][0] = v[25]; extrinsic_curvature[1][1] = v[26]; extrinsic_curvature[1][2] = v[27]; - extrinsic_curvature[2][0] = v[28]; extrinsic_curvature[2][1] = v[29]; extrinsic_curvature[2][2] = v[30]; + extrinsic_curvature[0][0] = v[22]; + extrinsic_curvature[0][1] = v[23]; + extrinsic_curvature[0][2] = v[24]; + extrinsic_curvature[1][0] = v[25]; + extrinsic_curvature[1][1] = v[26]; + extrinsic_curvature[1][2] = v[27]; + extrinsic_curvature[2][0] = v[28]; + extrinsic_curvature[2][1] = v[29]; + extrinsic_curvature[2][2] = v[30]; double lapse_der[3]; lapse_der[0] = v[32]; @@ -1893,24 +2170,48 @@ gr_mhd_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* s lapse_der[2] = v[34]; double shift_der[3][3]; - shift_der[0][0] = v[35]; shift_der[0][1] = v[36]; shift_der[0][2] = v[37]; - shift_der[1][0] = v[38]; shift_der[1][1] = v[39]; shift_der[1][2] = v[40]; - shift_der[2][0] = v[41]; shift_der[2][1] = v[42]; shift_der[2][2] = v[43]; + shift_der[0][0] = v[35]; + shift_der[0][1] = v[36]; + shift_der[0][2] = v[37]; + shift_der[1][0] = v[38]; + shift_der[1][1] = v[39]; + shift_der[1][2] = v[40]; + shift_der[2][0] = v[41]; + shift_der[2][1] = v[42]; + shift_der[2][2] = v[43]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = v[44]; spatial_metric_der[0][0][1] = v[45]; spatial_metric_der[0][0][2] = v[46]; - spatial_metric_der[0][1][0] = v[47]; spatial_metric_der[0][1][1] = v[48]; spatial_metric_der[0][1][2] = v[49]; - spatial_metric_der[0][2][0] = v[50]; spatial_metric_der[0][2][1] = v[51]; spatial_metric_der[0][2][2] = v[52]; - - spatial_metric_der[1][0][0] = v[53]; spatial_metric_der[1][0][1] = v[54]; spatial_metric_der[1][0][2] = v[55]; - spatial_metric_der[1][1][0] = v[56]; spatial_metric_der[1][1][1] = v[57]; spatial_metric_der[1][1][2] = v[58]; - spatial_metric_der[1][2][0] = v[59]; spatial_metric_der[1][2][1] = v[60]; spatial_metric_der[1][2][2] = v[61]; - - spatial_metric_der[0][0][0] = v[62]; spatial_metric_der[0][0][1] = v[63]; spatial_metric_der[0][0][2] = v[64]; - spatial_metric_der[0][1][0] = v[65]; spatial_metric_der[0][1][1] = v[66]; spatial_metric_der[0][1][2] = v[67]; - spatial_metric_der[0][2][0] = v[68]; spatial_metric_der[0][2][1] = v[69]; spatial_metric_der[0][2][2] = v[70]; - - double **stress_energy = gkyl_malloc(sizeof(double*[4])); + spatial_metric_der[0][0][0] = v[44]; + spatial_metric_der[0][0][1] = v[45]; + spatial_metric_der[0][0][2] = v[46]; + spatial_metric_der[0][1][0] = v[47]; + spatial_metric_der[0][1][1] = v[48]; + spatial_metric_der[0][1][2] = v[49]; + spatial_metric_der[0][2][0] = v[50]; + spatial_metric_der[0][2][1] = v[51]; + spatial_metric_der[0][2][2] = v[52]; + + spatial_metric_der[1][0][0] = v[53]; + spatial_metric_der[1][0][1] = v[54]; + spatial_metric_der[1][0][2] = v[55]; + spatial_metric_der[1][1][0] = v[56]; + spatial_metric_der[1][1][1] = v[57]; + spatial_metric_der[1][1][2] = v[58]; + spatial_metric_der[1][2][0] = v[59]; + spatial_metric_der[1][2][1] = v[60]; + spatial_metric_der[1][2][2] = v[61]; + + spatial_metric_der[0][0][0] = v[62]; + spatial_metric_der[0][0][1] = v[63]; + spatial_metric_der[0][0][2] = v[64]; + spatial_metric_der[0][1][0] = v[65]; + spatial_metric_der[0][1][1] = v[66]; + spatial_metric_der[0][1][2] = v[67]; + spatial_metric_der[0][2][0] = v[68]; + spatial_metric_der[0][2][1] = v[69]; + spatial_metric_der[0][2][2] = v[70]; + + double **stress_energy = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { stress_energy[i] = gkyl_malloc(sizeof(double[4])); } @@ -1925,7 +2226,9 @@ gr_mhd_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* s if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1939,7 +2242,9 @@ gr_mhd_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* s } double mag[3]; - mag[0] = mag_x; mag[1] = mag_y; mag[2] = mag_z; + mag[0] = mag_x; + mag[1] = mag_y; + mag[2] = mag_z; double cov_mag[3]; for (int i = 0; i < 3; i++) { @@ -1958,14 +2263,16 @@ gr_mhd_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* s cov_vel[i] += spatial_metric[i][j] * vel[j]; } } - + double b0 = 0.0; for (int i = 0; i < 3; i++) { b0 += W * mag[i] * (cov_vel[i] / lapse); } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double spacetime_vel[4]; spacetime_vel[0] = W / lapse; @@ -2004,9 +2311,12 @@ gr_mhd_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* s sout[4] = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - sout[4] += (lapse * sqrt(spatial_det)) * (stress_energy[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); - sout[4] += (lapse * sqrt(spatial_det)) * (2.0 * stress_energy[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); - sout[4] += (lapse * sqrt(spatial_det)) * (stress_energy[i + 1][j + 1] * extrinsic_curvature[i][j]); + sout[4] += (lapse * sqrt(spatial_det)) * + (stress_energy[0][0] * shift[i] * shift[j] * extrinsic_curvature[i][j]); + sout[4] += (lapse * sqrt(spatial_det)) * + (2.0 * stress_energy[0][i + 1] * shift[j] * extrinsic_curvature[i][j]); + sout[4] += + (lapse * sqrt(spatial_det)) * (stress_energy[i + 1][j + 1] * extrinsic_curvature[i][j]); } sout[4] -= (lapse * sqrt(spatial_det)) * (stress_energy[0][0] * shift[i] * lapse_der[i]); @@ -2019,19 +2329,21 @@ gr_mhd_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* s for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - sout[1 + j] += (lapse * sqrt(spatial_det)) * (0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]); - sout[1 + j] += (lapse * sqrt(spatial_det)) * (0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]); + sout[1 + j] += (lapse * sqrt(spatial_det)) * (0.5 * stress_energy[0][0] * shift[k] * + shift[l] * spatial_metric_der[j][k][l]); + sout[1 + j] += (lapse * sqrt(spatial_det)) * + (0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]); } sout[1 + j] += (lapse * sqrt(spatial_det)) * ((mom[k] / lapse) * shift_der[j][k]); for (int i = 0; i < 3; i++) { - sout[1 + j] += (lapse * sqrt(spatial_det)) * (stress_energy[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); + sout[1 + j] += (lapse * sqrt(spatial_det)) * + (stress_energy[0][i + 1] * shift[k] * spatial_metric_der[j][i][k]); } } } - } - else { + } else { for (int i = 0; i < 75; i++) { sout[i] = 0.0; } @@ -2043,14 +2355,14 @@ gr_mhd_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* s gkyl_free(stress_energy); } -void -gkyl_gr_mhd_tetrad_free(const struct gkyl_ref_count* ref) +void gkyl_gr_mhd_tetrad_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. - struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(base->on_dev, struct wv_gr_mhd_tetrad, eqn); + struct wv_gr_mhd_tetrad *gr_mhd_tetrad = + container_of(base->on_dev, struct wv_gr_mhd_tetrad, eqn); gkyl_cu_free(gr_mhd_tetrad); } @@ -2058,25 +2370,23 @@ gkyl_gr_mhd_tetrad_free(const struct gkyl_ref_count* ref) gkyl_free(gr_mhd_tetrad); } -struct gkyl_wv_eqn* -gkyl_wv_gr_mhd_tetrad_new(double gas_gamma, double light_speed, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, - struct gkyl_gr_spacetime* spacetime, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_gr_mhd_tetrad_new( + double gas_gamma, double light_speed, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, + int reinit_freq, struct gkyl_gr_spacetime *spacetime, bool use_gpu +) { - return gkyl_wv_gr_mhd_tetrad_inew(&(struct gkyl_wv_gr_mhd_tetrad_inp) { - .gas_gamma = gas_gamma, - .light_speed = light_speed, - .b_fact = b_fact, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .spacetime = spacetime, - .rp_type = WV_GR_MHD_TETRAD_RP_HLL, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_gr_mhd_tetrad_inew(&(struct gkyl_wv_gr_mhd_tetrad_inp + ){.gas_gamma = gas_gamma, + .light_speed = light_speed, + .b_fact = b_fact, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .spacetime = spacetime, + .rp_type = WV_GR_MHD_TETRAD_RP_HLL, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_gr_mhd_tetrad_inew(const struct gkyl_wv_gr_mhd_tetrad_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_gr_mhd_tetrad_inew(const struct gkyl_wv_gr_mhd_tetrad_inp *inp) { struct wv_gr_mhd_tetrad *gr_mhd_tetrad = gkyl_malloc(sizeof(struct wv_gr_mhd_tetrad)); @@ -2095,8 +2405,7 @@ gkyl_wv_gr_mhd_tetrad_inew(const struct gkyl_wv_gr_mhd_tetrad_inp* inp) gr_mhd_tetrad->eqn.num_waves = 2; gr_mhd_tetrad->eqn.waves_func = wave_lax_l; gr_mhd_tetrad->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_GR_MHD_TETRAD_RP_HLL) { + } else if (inp->rp_type == WV_GR_MHD_TETRAD_RP_HLL) { gr_mhd_tetrad->eqn.num_waves = 2; gr_mhd_tetrad->eqn.waves_func = wave_hll_l; gr_mhd_tetrad->eqn.qfluct_func = qfluct_hll_l; @@ -2121,15 +2430,15 @@ gkyl_wv_gr_mhd_tetrad_inew(const struct gkyl_wv_gr_mhd_tetrad_inp* inp) gr_mhd_tetrad->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(gr_mhd_tetrad->eqn.flags); gr_mhd_tetrad->eqn.ref_count = gkyl_ref_count_init(gkyl_gr_mhd_tetrad_free); - gr_mhd_tetrad->eqn.on_dev = &gr_mhd_tetrad->eqn; // On the CPU, the equation object points to itself. + gr_mhd_tetrad->eqn.on_dev = + &gr_mhd_tetrad->eqn; // On the CPU, the equation object points to itself. gr_mhd_tetrad->eqn.embed_geo = NULL; return &gr_mhd_tetrad->eqn; } -double -gkyl_wv_gr_mhd_tetrad_gas_gamma(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_mhd_tetrad_gas_gamma(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); double gas_gamma = gr_mhd_tetrad->gas_gamma; @@ -2137,8 +2446,7 @@ gkyl_wv_gr_mhd_tetrad_gas_gamma(const struct gkyl_wv_eqn* eqn) return gas_gamma; } -double -gkyl_wv_gr_mhd_tetrad_light_speed(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_mhd_tetrad_light_speed(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); double light_speed = gr_mhd_tetrad->light_speed; @@ -2146,8 +2454,7 @@ gkyl_wv_gr_mhd_tetrad_light_speed(const struct gkyl_wv_eqn* eqn) return light_speed; } -double -gkyl_wv_gr_mhd_tetrad_b_fact(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_mhd_tetrad_b_fact(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); double b_fact = gr_mhd_tetrad->b_fact; @@ -2155,8 +2462,7 @@ gkyl_wv_gr_mhd_tetrad_b_fact(const struct gkyl_wv_eqn* eqn) return b_fact; } -enum gkyl_spacetime_gauge -gkyl_wv_gr_mhd_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn) +enum gkyl_spacetime_gauge gkyl_wv_gr_mhd_tetrad_spacetime_gauge(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); enum gkyl_spacetime_gauge spacetime_gauge = gr_mhd_tetrad->spacetime_gauge; @@ -2164,8 +2470,7 @@ gkyl_wv_gr_mhd_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn) return spacetime_gauge; } -int -gkyl_wv_gr_mhd_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_gr_mhd_tetrad_reinit_freq(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); int reinit_freq = gr_mhd_tetrad->reinit_freq; @@ -2173,8 +2478,7 @@ gkyl_wv_gr_mhd_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn) return reinit_freq; } -struct gkyl_gr_spacetime* -gkyl_wv_gr_mhd_tetrad_spacetime(const struct gkyl_wv_eqn* eqn) +struct gkyl_gr_spacetime *gkyl_wv_gr_mhd_tetrad_spacetime(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_mhd_tetrad *gr_mhd_tetrad = container_of(eqn, struct wv_gr_mhd_tetrad, eqn); struct gkyl_gr_spacetime *spacetime = gr_mhd_tetrad->spacetime; diff --git a/moments/zero/wv_gr_twofluid.c b/moments/zero/wv_gr_twofluid.c index 2f2aa3200d..96fd0c83d8 100644 --- a/moments/zero/wv_gr_twofluid.c +++ b/moments/zero/wv_gr_twofluid.c @@ -6,10 +6,12 @@ #include #include -void -gkyl_gr_twofluid_flux(double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, const double q[84], double flux[84]) +void gkyl_gr_twofluid_flux( + double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, + const double q[84], double flux[84] +) { - double v[84] = { 0.0 }; + double v[84] = {0.0}; gkyl_gr_twofluid_prim_vars(gas_gamma_elc, gas_gamma_ion, q, v); double rho_elc = v[0]; double vx_elc = v[1]; @@ -35,14 +37,23 @@ gkyl_gr_twofluid_flux(double gas_gamma_elc, double gas_gamma_ion, double light_s double shift_z = v[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[22]; spatial_metric[0][1] = v[23]; spatial_metric[0][2] = v[24]; - spatial_metric[1][0] = v[25]; spatial_metric[1][1] = v[26]; spatial_metric[1][2] = v[27]; - spatial_metric[2][0] = v[28]; spatial_metric[2][1] = v[29]; spatial_metric[2][2] = v[30]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = v[22]; + spatial_metric[0][1] = v[23]; + spatial_metric[0][2] = v[24]; + spatial_metric[1][0] = v[25]; + spatial_metric[1][1] = v[26]; + spatial_metric[1][2] = v[27]; + spatial_metric[2][0] = v[28]; + spatial_metric[2][1] = v[29]; + spatial_metric[2][2] = v[30]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + bool in_excision_region = false; if (v[40] < pow(10.0, -8.0)) { in_excision_region = true; @@ -51,7 +62,9 @@ gkyl_gr_twofluid_flux(double gas_gamma_elc, double gas_gamma_ion, double light_s if (!in_excision_region) { double vel_elc[3]; double v_sq_elc = 0.0; - vel_elc[0] = vx_elc; vel_elc[1] = vy_elc; vel_elc[2] = vz_elc; + vel_elc[0] = vx_elc; + vel_elc[1] = vy_elc; + vel_elc[2] = vz_elc; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -67,14 +80,22 @@ gkyl_gr_twofluid_flux(double gas_gamma_elc, double gas_gamma_ion, double light_s double h_elc = 1.0 + ((p_elc / rho_elc) * (gas_gamma_elc / (gas_gamma_elc - 1.0))); flux[0] = (lapse * sqrt(spatial_det)) * (rho_elc * W_elc * (vx_elc - (shift_x / lapse))); - flux[1] = (lapse * sqrt(spatial_det)) * (rho_elc * h_elc * (W_elc * W_elc) * (vx_elc * (vx_elc - (shift_x / lapse))) + p_elc); - flux[2] = (lapse * sqrt(spatial_det)) * (rho_elc * h_elc * (W_elc * W_elc) * (vy_elc * (vx_elc - (shift_x / lapse)))); - flux[3] = (lapse * sqrt(spatial_det)) * (rho_elc * h_elc * (W_elc * W_elc) * (vz_elc * (vx_elc - (shift_x / lapse)))); - flux[4] = (lapse * sqrt(spatial_det)) * (((rho_elc * h_elc * (W_elc * W_elc)) - p_elc - (rho_elc * W_elc)) * (vx_elc - (shift_x / lapse)) + (p_elc * vx_elc)); + flux[1] = (lapse * sqrt(spatial_det)) * + (rho_elc * h_elc * (W_elc * W_elc) * (vx_elc * (vx_elc - (shift_x / lapse))) + p_elc); + flux[2] = (lapse * sqrt(spatial_det)) * + (rho_elc * h_elc * (W_elc * W_elc) * (vy_elc * (vx_elc - (shift_x / lapse)))); + flux[3] = (lapse * sqrt(spatial_det)) * + (rho_elc * h_elc * (W_elc * W_elc) * (vz_elc * (vx_elc - (shift_x / lapse)))); + flux[4] = (lapse * sqrt(spatial_det)) * + (((rho_elc * h_elc * (W_elc * W_elc)) - p_elc - (rho_elc * W_elc)) * + (vx_elc - (shift_x / lapse)) + + (p_elc * vx_elc)); double vel_ion[3]; double v_sq_ion = 0.0; - vel_ion[0] = vx_ion; vel_ion[1] = vy_ion; vel_ion[2] = vz_ion; + vel_ion[0] = vx_ion; + vel_ion[1] = vy_ion; + vel_ion[2] = vz_ion; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -90,10 +111,16 @@ gkyl_gr_twofluid_flux(double gas_gamma_elc, double gas_gamma_ion, double light_s double h_ion = 1.0 + ((p_ion / rho_ion) * (gas_gamma_ion / (gas_gamma_ion - 1.0))); flux[5] = (lapse * sqrt(spatial_det)) * (rho_ion * W_ion * (vx_ion - (shift_x / lapse))); - flux[6] = (lapse * sqrt(spatial_det)) * (rho_ion * h_ion * (W_ion * W_ion) * (vx_ion * (vx_ion - (shift_x / lapse))) + p_ion); - flux[7] = (lapse * sqrt(spatial_det)) * (rho_ion * h_ion * (W_ion * W_ion) * (vy_ion * (vx_ion - (shift_x / lapse)))); - flux[8] = (lapse * sqrt(spatial_det)) * (rho_ion * h_ion * (W_ion * W_ion) * (vz_ion * (vx_ion - (shift_x / lapse)))); - flux[9] = (lapse * sqrt(spatial_det)) * (((rho_ion * h_ion * (W_ion * W_ion)) - p_ion - (rho_ion * W_ion)) * (vx_ion - (shift_x / lapse)) + (p_ion * vx_ion)); + flux[6] = (lapse * sqrt(spatial_det)) * + (rho_ion * h_ion * (W_ion * W_ion) * (vx_ion * (vx_ion - (shift_x / lapse))) + p_ion); + flux[7] = (lapse * sqrt(spatial_det)) * + (rho_ion * h_ion * (W_ion * W_ion) * (vy_ion * (vx_ion - (shift_x / lapse)))); + flux[8] = (lapse * sqrt(spatial_det)) * + (rho_ion * h_ion * (W_ion * W_ion) * (vz_ion * (vx_ion - (shift_x / lapse)))); + flux[9] = (lapse * sqrt(spatial_det)) * + (((rho_ion * h_ion * (W_ion * W_ion)) - p_ion - (rho_ion * W_ion)) * + (vx_ion - (shift_x / lapse)) + + (p_ion * vx_ion)); double Ex = (lapse * Dx) + ((shift_y * Bz) - (shift_z * By)); double Ey = (lapse * Dy) - ((shift_x * Bz) - (shift_z * Bx)); @@ -115,16 +142,16 @@ gkyl_gr_twofluid_flux(double gas_gamma_elc, double gas_gamma_ion, double light_s for (int i = 18; i < 84; i++) { flux[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 84; i++) { flux[i] = 0.0; } } } -void -gkyl_gr_twofluid_prim_vars(double gas_gamma_elc, double gas_gamma_ion, const double q[84], double v[84]) +void gkyl_gr_twofluid_prim_vars( + double gas_gamma_elc, double gas_gamma_ion, const double q[84], double v[84] +) { double Dx = q[10], Dy = q[11], Dz = q[12]; double Bx = q[13], By = q[14], Bz = q[15]; @@ -138,14 +165,26 @@ gkyl_gr_twofluid_prim_vars(double gas_gamma_elc, double gas_gamma_ion, const dou double shift_z = q[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = q[22]; spatial_metric[0][1] = q[23]; spatial_metric[0][2] = q[24]; - spatial_metric[1][0] = q[25]; spatial_metric[1][1] = q[26]; spatial_metric[1][2] = q[27]; - spatial_metric[2][0] = q[28]; spatial_metric[2][1] = q[29]; spatial_metric[2][2] = q[30]; - + spatial_metric[0][0] = q[22]; + spatial_metric[0][1] = q[23]; + spatial_metric[0][2] = q[24]; + spatial_metric[1][0] = q[25]; + spatial_metric[1][1] = q[26]; + spatial_metric[1][2] = q[27]; + spatial_metric[2][0] = q[28]; + spatial_metric[2][1] = q[29]; + spatial_metric[2][2] = q[30]; + double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = q[31]; extrinsic_curvature[0][1] = q[32]; extrinsic_curvature[0][2] = q[33]; - extrinsic_curvature[1][0] = q[34]; extrinsic_curvature[1][1] = q[35]; extrinsic_curvature[1][2] = q[36]; - extrinsic_curvature[2][0] = q[37]; extrinsic_curvature[2][1] = q[38]; extrinsic_curvature[2][2] = q[39]; + extrinsic_curvature[0][0] = q[31]; + extrinsic_curvature[0][1] = q[32]; + extrinsic_curvature[0][2] = q[33]; + extrinsic_curvature[1][0] = q[34]; + extrinsic_curvature[1][1] = q[35]; + extrinsic_curvature[1][2] = q[36]; + extrinsic_curvature[2][0] = q[37]; + extrinsic_curvature[2][1] = q[38]; + extrinsic_curvature[2][2] = q[39]; double lapse_der[3]; lapse_der[0] = q[41]; @@ -153,22 +192,46 @@ gkyl_gr_twofluid_prim_vars(double gas_gamma_elc, double gas_gamma_ion, const dou lapse_der[2] = q[43]; double shift_der[3][3]; - shift_der[0][0] = q[44]; shift_der[0][1] = q[45]; shift_der[0][2] = q[46]; - shift_der[1][0] = q[47]; shift_der[1][1] = q[48]; shift_der[1][2] = q[49]; - shift_der[2][0] = q[50]; shift_der[2][1] = q[51]; shift_der[2][2] = q[52]; + shift_der[0][0] = q[44]; + shift_der[0][1] = q[45]; + shift_der[0][2] = q[46]; + shift_der[1][0] = q[47]; + shift_der[1][1] = q[48]; + shift_der[1][2] = q[49]; + shift_der[2][0] = q[50]; + shift_der[2][1] = q[51]; + shift_der[2][2] = q[52]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = q[53]; spatial_metric_der[0][0][1] = q[54]; spatial_metric_der[0][0][2] = q[55]; - spatial_metric_der[0][1][0] = q[56]; spatial_metric_der[0][1][1] = q[57]; spatial_metric_der[0][1][2] = q[58]; - spatial_metric_der[0][2][0] = q[59]; spatial_metric_der[0][2][1] = q[60]; spatial_metric_der[0][2][2] = q[61]; - - spatial_metric_der[1][0][0] = q[62]; spatial_metric_der[1][0][1] = q[63]; spatial_metric_der[1][0][2] = q[64]; - spatial_metric_der[1][1][0] = q[65]; spatial_metric_der[1][1][1] = q[66]; spatial_metric_der[1][1][2] = q[67]; - spatial_metric_der[1][2][0] = q[68]; spatial_metric_der[1][2][1] = q[69]; spatial_metric_der[1][2][2] = q[70]; - - spatial_metric_der[0][0][0] = q[71]; spatial_metric_der[0][0][1] = q[72]; spatial_metric_der[0][0][2] = q[73]; - spatial_metric_der[0][1][0] = q[74]; spatial_metric_der[0][1][1] = q[75]; spatial_metric_der[0][1][2] = q[76]; - spatial_metric_der[0][2][0] = q[77]; spatial_metric_der[0][2][1] = q[78]; spatial_metric_der[0][2][2] = q[79]; + spatial_metric_der[0][0][0] = q[53]; + spatial_metric_der[0][0][1] = q[54]; + spatial_metric_der[0][0][2] = q[55]; + spatial_metric_der[0][1][0] = q[56]; + spatial_metric_der[0][1][1] = q[57]; + spatial_metric_der[0][1][2] = q[58]; + spatial_metric_der[0][2][0] = q[59]; + spatial_metric_der[0][2][1] = q[60]; + spatial_metric_der[0][2][2] = q[61]; + + spatial_metric_der[1][0][0] = q[62]; + spatial_metric_der[1][0][1] = q[63]; + spatial_metric_der[1][0][2] = q[64]; + spatial_metric_der[1][1][0] = q[65]; + spatial_metric_der[1][1][1] = q[66]; + spatial_metric_der[1][1][2] = q[67]; + spatial_metric_der[1][2][0] = q[68]; + spatial_metric_der[1][2][1] = q[69]; + spatial_metric_der[1][2][2] = q[70]; + + spatial_metric_der[0][0][0] = q[71]; + spatial_metric_der[0][0][1] = q[72]; + spatial_metric_der[0][0][2] = q[73]; + spatial_metric_der[0][1][0] = q[74]; + spatial_metric_der[0][1][1] = q[75]; + spatial_metric_der[0][1][2] = q[76]; + spatial_metric_der[0][2][0] = q[77]; + spatial_metric_der[0][2][1] = q[78]; + spatial_metric_der[0][2][2] = q[79]; double evol_param = q[80]; double x = q[81]; @@ -181,9 +244,12 @@ gkyl_gr_twofluid_prim_vars(double gas_gamma_elc, double gas_gamma_ion, const dou } if (!in_excision_region) { - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double D_elc = q[0] / sqrt(spatial_det); double momx_elc = q[1] / sqrt(spatial_det); @@ -191,45 +257,60 @@ gkyl_gr_twofluid_prim_vars(double gas_gamma_elc, double gas_gamma_ion, const dou double momz_elc = q[3] / sqrt(spatial_det); double Etot_elc = q[4] / sqrt(spatial_det); - double C_elc = D_elc / sqrt(((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc))); - double C0_elc = (D_elc + Etot_elc) / sqrt(((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc))); - if (((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) < pow(10.0, -8.0)) { + double C_elc = D_elc / sqrt( + ((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) + ); + double C0_elc = + (D_elc + Etot_elc) / sqrt( + ((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) + ); + if (((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) < + pow(10.0, -8.0)) { C_elc = D_elc / sqrt(pow(10.0, -8.0)); C0_elc = (D_elc + Etot_elc) / sqrt(pow(10.0, -8.0)); } double alpha0_elc = -1.0 / (gas_gamma_elc * gas_gamma_elc); double alpha1_elc = -2.0 * C_elc * ((gas_gamma_elc - 1.0) / (gas_gamma_elc * gas_gamma_elc)); - double alpha2_elc = ((gas_gamma_elc - 2.0) / gas_gamma_elc) * ((C0_elc * C0_elc) - 1.0) + 1.0 - (C_elc * C_elc) * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * - ((gas_gamma_elc - 1.0) / gas_gamma_elc); + double alpha2_elc = ((gas_gamma_elc - 2.0) / gas_gamma_elc) * ((C0_elc * C0_elc) - 1.0) + 1.0 - + (C_elc * C_elc) * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * + ((gas_gamma_elc - 1.0) / gas_gamma_elc); double alpha4_elc = (C0_elc * C0_elc) - 1.0; - double eta_elc = 2.0 * C_elc *((gas_gamma_elc - 1.0) / gas_gamma_elc); + double eta_elc = 2.0 * C_elc * ((gas_gamma_elc - 1.0) / gas_gamma_elc); double guess_elc = 1.0; int iter_elc = 0; while (iter_elc < 100) { - double poly_elc = (alpha4_elc * (guess_elc * guess_elc * guess_elc) * (guess_elc - eta_elc)) + (alpha2_elc * (guess_elc * guess_elc)) + - (alpha1_elc * guess_elc) + alpha0_elc; - double poly_der_elc = alpha1_elc + (2.0 * alpha2_elc * guess_elc) + (4.0 * alpha4_elc * (guess_elc * guess_elc * guess_elc)) - - (3.0 * eta_elc * alpha4_elc * (guess_elc * guess_elc)); + double poly_elc = (alpha4_elc * (guess_elc * guess_elc * guess_elc) * (guess_elc - eta_elc)) + + (alpha2_elc * (guess_elc * guess_elc)) + (alpha1_elc * guess_elc) + + alpha0_elc; + double poly_der_elc = alpha1_elc + (2.0 * alpha2_elc * guess_elc) + + (4.0 * alpha4_elc * (guess_elc * guess_elc * guess_elc)) - + (3.0 * eta_elc * alpha4_elc * (guess_elc * guess_elc)); double guess_new_elc = guess_elc - (poly_elc / poly_der_elc); if (fabs(guess_elc - guess_new_elc) < pow(10.0, -8.0)) { iter_elc = 100; - } - else { + } else { iter_elc += 1; guess_elc = guess_new_elc; } } - double W_elc = 0.5 * C0_elc * guess_elc * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * ((1.0 - (C_elc * guess_elc)) / - ((C0_elc * C0_elc) * (guess_elc * guess_elc)))))); + double W_elc = + 0.5 * C0_elc * guess_elc * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * + ((1.0 - (C_elc * guess_elc)) / ((C0_elc * C0_elc) * (guess_elc * guess_elc)))) + )); double h_elc = 1.0 / (C_elc * guess_elc); - v[0] = D_elc / W_elc; + v[0] = D_elc / W_elc; v[1] = momx_elc / (v[0] * h_elc * (W_elc * W_elc)); v[2] = momy_elc / (v[0] * h_elc * (W_elc * W_elc)); v[3] = momz_elc / (v[0] * h_elc * (W_elc * W_elc)); @@ -248,45 +329,60 @@ gkyl_gr_twofluid_prim_vars(double gas_gamma_elc, double gas_gamma_ion, const dou double momz_ion = q[8] / sqrt(spatial_det); double Etot_ion = q[9] / sqrt(spatial_det); - double C_ion = D_ion / sqrt(((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion))); - double C0_ion = (D_ion + Etot_ion) / sqrt(((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion))); - if (((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) < pow(10.0, -8.0)) { + double C_ion = D_ion / sqrt( + ((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) + ); + double C0_ion = + (D_ion + Etot_ion) / sqrt( + ((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) + ); + if (((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) < + pow(10.0, -8.0)) { C_ion = D_ion / sqrt(pow(10.0, -8.0)); C0_ion = (D_ion + Etot_ion) / sqrt(pow(10.0, -8.0)); } double alpha0_ion = -1.0 / (gas_gamma_ion * gas_gamma_ion); double alpha1_ion = -2.0 * C_ion * ((gas_gamma_ion - 1.0) / (gas_gamma_ion * gas_gamma_ion)); - double alpha2_ion = ((gas_gamma_ion - 2.0) / gas_gamma_ion) * ((C0_ion * C0_ion) - 1.0) + 1.0 - (C_ion * C_ion) * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * - ((gas_gamma_ion - 1.0) / gas_gamma_ion); + double alpha2_ion = ((gas_gamma_ion - 2.0) / gas_gamma_ion) * ((C0_ion * C0_ion) - 1.0) + 1.0 - + (C_ion * C_ion) * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * + ((gas_gamma_ion - 1.0) / gas_gamma_ion); double alpha4_ion = (C0_ion * C0_ion) - 1.0; - double eta_ion = 2.0 * C_ion *((gas_gamma_ion - 1.0) / gas_gamma_ion); + double eta_ion = 2.0 * C_ion * ((gas_gamma_ion - 1.0) / gas_gamma_ion); double guess_ion = 1.0; int iter_ion = 0; while (iter_ion < 100) { - double poly_ion = (alpha4_ion * (guess_ion * guess_ion * guess_ion) * (guess_ion - eta_ion)) + (alpha2_ion * (guess_ion * guess_ion)) + - (alpha1_ion * guess_ion) + alpha0_ion; - double poly_der_ion = alpha1_ion + (2.0 * alpha2_ion * guess_ion) + (4.0 * alpha4_ion * (guess_ion * guess_ion * guess_ion)) - - (3.0 * eta_ion * alpha4_ion * (guess_ion * guess_ion)); + double poly_ion = (alpha4_ion * (guess_ion * guess_ion * guess_ion) * (guess_ion - eta_ion)) + + (alpha2_ion * (guess_ion * guess_ion)) + (alpha1_ion * guess_ion) + + alpha0_ion; + double poly_der_ion = alpha1_ion + (2.0 * alpha2_ion * guess_ion) + + (4.0 * alpha4_ion * (guess_ion * guess_ion * guess_ion)) - + (3.0 * eta_ion * alpha4_ion * (guess_ion * guess_ion)); double guess_new_ion = guess_ion - (poly_ion / poly_der_ion); if (fabs(guess_ion - guess_new_ion) < pow(10.0, -8.0)) { iter_ion = 100; - } - else { + } else { iter_ion += 1; guess_ion = guess_new_ion; } } - double W_ion = 0.5 * C0_ion * guess_ion * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * ((1.0 - (C_ion * guess_ion)) / - ((C0_ion * C0_ion) * (guess_ion * guess_ion)))))); + double W_ion = + 0.5 * C0_ion * guess_ion * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * + ((1.0 - (C_ion * guess_ion)) / ((C0_ion * C0_ion) * (guess_ion * guess_ion)))) + )); double h_ion = 1.0 / (C_ion * guess_ion); - v[5] = D_ion / W_ion; + v[5] = D_ion / W_ion; v[6] = momx_ion / (v[5] * h_ion * (W_ion * W_ion)); v[7] = momy_ion / (v[5] * h_ion * (W_ion * W_ion)); v[8] = momz_ion / (v[5] * h_ion * (W_ion * W_ion)); @@ -299,8 +395,12 @@ gkyl_gr_twofluid_prim_vars(double gas_gamma_elc, double gas_gamma_ion, const dou v[9] = pow(10.0, -8.0); } - v[10] = Dx; v[11] = Dy; v[12] = Dz; - v[13] = Bx; v[14] = By; v[15] = Bz; + v[10] = Dx; + v[11] = Dy; + v[12] = Dz; + v[13] = Bx; + v[14] = By; + v[15] = Bz; v[16] = phi; v[17] = psi; @@ -310,13 +410,25 @@ gkyl_gr_twofluid_prim_vars(double gas_gamma_elc, double gas_gamma_ion, const dou v[20] = shift_y; v[21] = shift_z; - v[22] = spatial_metric[0][0]; v[23] = spatial_metric[0][1]; v[24] = spatial_metric[0][2]; - v[25] = spatial_metric[1][0]; v[26] = spatial_metric[1][1]; v[27] = spatial_metric[1][2]; - v[28] = spatial_metric[2][0]; v[29] = spatial_metric[2][1]; v[30] = spatial_metric[2][2]; - - v[31] = extrinsic_curvature[0][0]; v[32] = extrinsic_curvature[0][1]; v[33] = extrinsic_curvature[0][2]; - v[34] = extrinsic_curvature[1][0]; v[35] = extrinsic_curvature[1][1]; v[36] = extrinsic_curvature[1][2]; - v[37] = extrinsic_curvature[2][0]; v[38] = extrinsic_curvature[2][1]; v[39] = extrinsic_curvature[2][2]; + v[22] = spatial_metric[0][0]; + v[23] = spatial_metric[0][1]; + v[24] = spatial_metric[0][2]; + v[25] = spatial_metric[1][0]; + v[26] = spatial_metric[1][1]; + v[27] = spatial_metric[1][2]; + v[28] = spatial_metric[2][0]; + v[29] = spatial_metric[2][1]; + v[30] = spatial_metric[2][2]; + + v[31] = extrinsic_curvature[0][0]; + v[32] = extrinsic_curvature[0][1]; + v[33] = extrinsic_curvature[0][2]; + v[34] = extrinsic_curvature[1][0]; + v[35] = extrinsic_curvature[1][1]; + v[36] = extrinsic_curvature[1][2]; + v[37] = extrinsic_curvature[2][0]; + v[38] = extrinsic_curvature[2][1]; + v[39] = extrinsic_curvature[2][2]; v[40] = 1.0; @@ -324,48 +436,79 @@ gkyl_gr_twofluid_prim_vars(double gas_gamma_elc, double gas_gamma_ion, const dou v[42] = lapse_der[1]; v[43] = lapse_der[2]; - v[44] = shift_der[0][0]; v[45] = shift_der[0][1]; v[46] = shift_der[0][2]; - v[47] = shift_der[1][0]; v[48] = shift_der[1][1]; v[49] = shift_der[1][2]; - v[50] = shift_der[2][0]; v[51] = shift_der[2][1]; v[52] = shift_der[2][2]; - - v[53] = spatial_metric_der[0][0][0]; v[54] = spatial_metric_der[0][0][1]; v[55] = spatial_metric_der[0][0][2]; - v[56] = spatial_metric_der[0][1][0]; v[57] = spatial_metric_der[0][1][1]; v[58] = spatial_metric_der[0][1][2]; - v[59] = spatial_metric_der[0][2][0]; v[60] = spatial_metric_der[0][2][1]; v[61] = spatial_metric_der[0][2][2]; - - v[62] = spatial_metric_der[1][0][0]; v[63] = spatial_metric_der[1][0][1]; v[64] = spatial_metric_der[1][0][2]; - v[65] = spatial_metric_der[1][1][0]; v[66] = spatial_metric_der[1][1][1]; v[67] = spatial_metric_der[1][1][2]; - v[68] = spatial_metric_der[1][2][0]; v[69] = spatial_metric_der[1][2][1]; v[70] = spatial_metric_der[1][2][2]; - - v[71] = spatial_metric_der[2][0][0]; v[72] = spatial_metric_der[2][0][1]; v[73] = spatial_metric_der[2][0][2]; - v[74] = spatial_metric_der[2][1][0]; v[75] = spatial_metric_der[2][1][1]; v[76] = spatial_metric_der[2][1][2]; - v[77] = spatial_metric_der[2][2][0]; v[78] = spatial_metric_der[2][2][1]; v[79] = spatial_metric_der[2][2][2]; + v[44] = shift_der[0][0]; + v[45] = shift_der[0][1]; + v[46] = shift_der[0][2]; + v[47] = shift_der[1][0]; + v[48] = shift_der[1][1]; + v[49] = shift_der[1][2]; + v[50] = shift_der[2][0]; + v[51] = shift_der[2][1]; + v[52] = shift_der[2][2]; + + v[53] = spatial_metric_der[0][0][0]; + v[54] = spatial_metric_der[0][0][1]; + v[55] = spatial_metric_der[0][0][2]; + v[56] = spatial_metric_der[0][1][0]; + v[57] = spatial_metric_der[0][1][1]; + v[58] = spatial_metric_der[0][1][2]; + v[59] = spatial_metric_der[0][2][0]; + v[60] = spatial_metric_der[0][2][1]; + v[61] = spatial_metric_der[0][2][2]; + + v[62] = spatial_metric_der[1][0][0]; + v[63] = spatial_metric_der[1][0][1]; + v[64] = spatial_metric_der[1][0][2]; + v[65] = spatial_metric_der[1][1][0]; + v[66] = spatial_metric_der[1][1][1]; + v[67] = spatial_metric_der[1][1][2]; + v[68] = spatial_metric_der[1][2][0]; + v[69] = spatial_metric_der[1][2][1]; + v[70] = spatial_metric_der[1][2][2]; + + v[71] = spatial_metric_der[2][0][0]; + v[72] = spatial_metric_der[2][0][1]; + v[73] = spatial_metric_der[2][0][2]; + v[74] = spatial_metric_der[2][1][0]; + v[75] = spatial_metric_der[2][1][1]; + v[76] = spatial_metric_der[2][1][2]; + v[77] = spatial_metric_der[2][2][0]; + v[78] = spatial_metric_der[2][2][1]; + v[79] = spatial_metric_der[2][2][2]; v[80] = evol_param; v[81] = x; v[82] = y; v[83] = z; - } - else { + } else { for (int i = 0; i < 84; i++) { v[i] = 0.0; } - + v[40] = -1.0; } } -void -gkyl_gr_twofluid_inv_spatial_metric(const double q[84], double ***inv_spatial_metric) +void gkyl_gr_twofluid_inv_spatial_metric(const double q[84], double ***inv_spatial_metric) { double spatial_metric[3][3]; - spatial_metric[0][0] = q[22]; spatial_metric[0][1] = q[23]; spatial_metric[0][2] = q[24]; - spatial_metric[1][0] = q[25]; spatial_metric[1][1] = q[26]; spatial_metric[1][2] = q[27]; - spatial_metric[2][0] = q[28]; spatial_metric[2][1] = q[29]; spatial_metric[2][2] = q[30]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = q[22]; + spatial_metric[0][1] = q[23]; + spatial_metric[0][2] = q[24]; + spatial_metric[1][0] = q[25]; + spatial_metric[1][1] = q[26]; + spatial_metric[1][2] = q[27]; + spatial_metric[2][0] = q[28]; + spatial_metric[2][1] = q[29]; + spatial_metric[2][2] = q[30]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -396,8 +539,7 @@ gkyl_gr_twofluid_inv_spatial_metric(const double q[84], double ***inv_spatial_me for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -405,16 +547,18 @@ gkyl_gr_twofluid_inv_spatial_metric(const double q[84], double ***inv_spatial_me for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*inv_spatial_metric)[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*inv_spatial_metric)[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } } -void -gkyl_gr_twofluid_stress_energy_tensor_elc(double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_elc) +void gkyl_gr_twofluid_stress_energy_tensor_elc( + double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_elc +) { - double v[84] = { 0.0 }; + double v[84] = {0.0}; gkyl_gr_twofluid_prim_vars(gas_gamma_elc, gas_gamma_ion, q, v); double rho_elc = v[0]; double vx_elc = v[1]; @@ -428,11 +572,17 @@ gkyl_gr_twofluid_stress_energy_tensor_elc(double gas_gamma_elc, double gas_gamma double shift_z = v[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[22]; spatial_metric[0][1] = v[23]; spatial_metric[0][2] = v[24]; - spatial_metric[1][0] = v[25]; spatial_metric[1][1] = v[26]; spatial_metric[1][2] = v[27]; - spatial_metric[2][0] = v[28]; spatial_metric[2][1] = v[29]; spatial_metric[2][2] = v[30]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[22]; + spatial_metric[0][1] = v[23]; + spatial_metric[0][2] = v[24]; + spatial_metric[1][0] = v[25]; + spatial_metric[1][1] = v[26]; + spatial_metric[1][2] = v[27]; + spatial_metric[2][0] = v[28]; + spatial_metric[2][1] = v[29]; + spatial_metric[2][2] = v[30]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -447,7 +597,9 @@ gkyl_gr_twofluid_stress_energy_tensor_elc(double gas_gamma_elc, double gas_gamma if (!in_excision_region) { double vel_elc[3]; double v_sq_elc = 0.0; - vel_elc[0] = vx_elc; vel_elc[1] = vy_elc; vel_elc[2] = vz_elc; + vel_elc[0] = vx_elc; + vel_elc[1] = vy_elc; + vel_elc[2] = vz_elc; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -469,27 +621,31 @@ gkyl_gr_twofluid_stress_energy_tensor_elc(double gas_gamma_elc, double gas_gamma spacetime_vel_elc[3] = (W_elc * vz_elc) - (shift_z * (W_elc / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*stress_energy_elc)[i][j] = (rho_elc * h_elc * spacetime_vel_elc[i] * spacetime_vel_elc[j]) + (p_elc * inv_spacetime_metric[i][j]); + (*stress_energy_elc)[i][j] = + (rho_elc * h_elc * spacetime_vel_elc[i] * spacetime_vel_elc[j]) + + (p_elc * inv_spacetime_metric[i][j]); } } - } - else { + } else { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { (*stress_energy_elc)[i][j] = 0.0; @@ -503,10 +659,11 @@ gkyl_gr_twofluid_stress_energy_tensor_elc(double gas_gamma_elc, double gas_gamma gkyl_free(inv_spatial_metric); } -void -gkyl_gr_twofluid_stress_energy_tensor_ion(double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_ion) +void gkyl_gr_twofluid_stress_energy_tensor_ion( + double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_ion +) { - double v[84] = { 0.0 }; + double v[84] = {0.0}; gkyl_gr_twofluid_prim_vars(gas_gamma_elc, gas_gamma_ion, q, v); double rho_ion = v[5]; double vx_ion = v[6]; @@ -520,11 +677,17 @@ gkyl_gr_twofluid_stress_energy_tensor_ion(double gas_gamma_elc, double gas_gamma double shift_z = v[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[22]; spatial_metric[0][1] = v[23]; spatial_metric[0][2] = v[24]; - spatial_metric[1][0] = v[25]; spatial_metric[1][1] = v[26]; spatial_metric[1][2] = v[27]; - spatial_metric[2][0] = v[28]; spatial_metric[2][1] = v[29]; spatial_metric[2][2] = v[30]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[22]; + spatial_metric[0][1] = v[23]; + spatial_metric[0][2] = v[24]; + spatial_metric[1][0] = v[25]; + spatial_metric[1][1] = v[26]; + spatial_metric[1][2] = v[27]; + spatial_metric[2][0] = v[28]; + spatial_metric[2][1] = v[29]; + spatial_metric[2][2] = v[30]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -539,7 +702,9 @@ gkyl_gr_twofluid_stress_energy_tensor_ion(double gas_gamma_elc, double gas_gamma if (!in_excision_region) { double vel_ion[3]; double v_sq_ion = 0.0; - vel_ion[0] = vx_ion; vel_ion[1] = vy_ion; vel_ion[2] = vz_ion; + vel_ion[0] = vx_ion; + vel_ion[1] = vy_ion; + vel_ion[2] = vz_ion; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -561,27 +726,31 @@ gkyl_gr_twofluid_stress_energy_tensor_ion(double gas_gamma_elc, double gas_gamma spacetime_vel_ion[3] = (W_ion * vz_ion) - (shift_z * (W_ion / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*stress_energy_ion)[i][j] = (rho_ion * h_ion * spacetime_vel_ion[i] * spacetime_vel_ion[j]) + (p_ion * inv_spacetime_metric[i][j]); + (*stress_energy_ion)[i][j] = + (rho_ion * h_ion * spacetime_vel_ion[i] * spacetime_vel_ion[j]) + + (p_ion * inv_spacetime_metric[i][j]); } } - } - else { + } else { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { (*stress_energy_ion)[i][j] = 0.0; @@ -595,10 +764,11 @@ gkyl_gr_twofluid_stress_energy_tensor_ion(double gas_gamma_elc, double gas_gamma gkyl_free(inv_spatial_metric); } -static inline double -gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, double light_speed, const double q[84]) +static inline double gkyl_gr_twofluid_max_abs_speed( + double gas_gamma_elc, double gas_gamma_ion, double light_speed, const double q[84] +) { - double v[84] = { 0.0 }; + double v[84] = {0.0}; gkyl_gr_twofluid_prim_vars(gas_gamma_elc, gas_gamma_ion, q, v); double rho_elc = v[0]; double vx_elc = v[1]; @@ -618,15 +788,25 @@ gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, doubl double shift_z = v[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[22]; spatial_metric[0][1] = v[23]; spatial_metric[0][2] = v[24]; - spatial_metric[1][0] = v[25]; spatial_metric[1][1] = v[26]; spatial_metric[1][2] = v[27]; - spatial_metric[2][0] = v[28]; spatial_metric[2][1] = v[29]; spatial_metric[2][2] = v[30]; - - double spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[22]; + spatial_metric[0][1] = v[23]; + spatial_metric[0][2] = v[24]; + spatial_metric[1][0] = v[25]; + spatial_metric[1][1] = v[26]; + spatial_metric[1][2] = v[27]; + spatial_metric[2][0] = v[28]; + spatial_metric[2][1] = v[29]; + spatial_metric[2][2] = v[30]; + + double spatial_metric_det = + (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -653,16 +833,15 @@ gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, doubl if (fabs(spatial_metric[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime = true; } - } - else { + } else { if (fabs(spatial_metric[i][j]) > pow(10.0, -8.0)) { curved_spacetime = true; } } } } - if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || fabs(shift_y) > pow(10.0, -8.0) || - fabs(shift_z) > pow(10.0, -8.0)) { + if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || + fabs(shift_y) > pow(10.0, -8.0) || fabs(shift_z) > pow(10.0, -8.0)) { curved_spacetime = true; } @@ -670,8 +849,10 @@ gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, doubl if (curved_spacetime) { double vel_elc[3]; double v_sq_elc = 0.0; - vel_elc[0] = vx_elc; vel_elc[1] = vy_elc; vel_elc[2] = vz_elc; - + vel_elc[0] = vx_elc; + vel_elc[1] = vy_elc; + vel_elc[2] = vz_elc; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_elc += spatial_metric[i][j] * vel_elc[i] * vel_elc[j]; @@ -679,7 +860,9 @@ gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, doubl } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double material_eigs_elc[3]; double fast_acoustic_eigs_elc[3]; @@ -688,19 +871,33 @@ gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, doubl for (int i = 0; i < 3; i++) { material_eigs_elc[i] = (lapse * vel_elc[i]) - shift[i]; - fast_acoustic_eigs_elc[i] = (lapse / (1.0 - (v_sq_elc * (c_s_elc * c_s_elc)))) * ((vel_elc[i] * (1.0 - (c_s_elc * c_s_elc))) + - (c_s_elc * sqrt((1.0 - v_sq_elc) * (inv_spatial_metric[i][i] * (1.0 - (v_sq_elc * (c_s_elc * c_s_elc))) - - (vel_elc[i] * vel_elc[i]) * (1.0 - (c_s_elc * c_s_elc)))))) - shift[i]; - - slow_acoustic_eigs_elc[i] = (lapse / (1.0 - (v_sq_elc * (c_s_elc * c_s_elc)))) * ((vel_elc[i] * (1.0 - (c_s_elc * c_s_elc))) - - (c_s_elc * sqrt((1.0 - v_sq_elc) * (inv_spatial_metric[i][i] * (1.0 - (v_sq_elc * (c_s_elc * c_s_elc))) - - (vel_elc[i] * vel_elc[i]) * (1.0 - (c_s_elc * c_s_elc)))))) - shift[i]; + fast_acoustic_eigs_elc[i] = + (lapse / (1.0 - (v_sq_elc * (c_s_elc * c_s_elc)))) * + ((vel_elc[i] * (1.0 - (c_s_elc * c_s_elc))) + + (c_s_elc * sqrt( + (1.0 - v_sq_elc) * + (inv_spatial_metric[i][i] * (1.0 - (v_sq_elc * (c_s_elc * c_s_elc))) - + (vel_elc[i] * vel_elc[i]) * (1.0 - (c_s_elc * c_s_elc))) + ))) - + shift[i]; + + slow_acoustic_eigs_elc[i] = + (lapse / (1.0 - (v_sq_elc * (c_s_elc * c_s_elc)))) * + ((vel_elc[i] * (1.0 - (c_s_elc * c_s_elc))) - + (c_s_elc * sqrt( + (1.0 - v_sq_elc) * + (inv_spatial_metric[i][i] * (1.0 - (v_sq_elc * (c_s_elc * c_s_elc))) - + (vel_elc[i] * vel_elc[i]) * (1.0 - (c_s_elc * c_s_elc))) + ))) - + shift[i]; } double vel_ion[3]; double v_sq_ion = 0.0; - vel_ion[0] = vx_ion; vel_ion[1] = vy_ion; vel_ion[2] = vz_ion; - + vel_ion[0] = vx_ion; + vel_ion[1] = vy_ion; + vel_ion[2] = vz_ion; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_ion += spatial_metric[i][j] * vel_ion[i] * vel_ion[j]; @@ -714,13 +911,25 @@ gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, doubl for (int i = 0; i < 3; i++) { material_eigs_ion[i] = (lapse * vel_ion[i]) - shift[i]; - fast_acoustic_eigs_ion[i] = (lapse / (1.0 - (v_sq_ion * (c_s_ion * c_s_ion)))) * ((vel_ion[i] * (1.0 - (c_s_ion * c_s_ion))) + - (c_s_ion * sqrt((1.0 - v_sq_ion) * (inv_spatial_metric[i][i] * (1.0 - (v_sq_ion * (c_s_ion * c_s_ion))) - - (vel_ion[i] * vel_ion[i]) * (1.0 - (c_s_ion * c_s_ion)))))) - shift[i]; - - slow_acoustic_eigs_ion[i] = (lapse / (1.0 - (v_sq_ion * (c_s_ion * c_s_ion)))) * ((vel_ion[i] * (1.0 - (c_s_ion * c_s_ion))) - - (c_s_ion * sqrt((1.0 - v_sq_ion) * (inv_spatial_metric[i][i] * (1.0 - (v_sq_ion * (c_s_ion * c_s_ion))) - - (vel_ion[i] * vel_ion[i]) * (1.0 - (c_s_ion * c_s_ion)))))) - shift[i]; + fast_acoustic_eigs_ion[i] = + (lapse / (1.0 - (v_sq_ion * (c_s_ion * c_s_ion)))) * + ((vel_ion[i] * (1.0 - (c_s_ion * c_s_ion))) + + (c_s_ion * sqrt( + (1.0 - v_sq_ion) * + (inv_spatial_metric[i][i] * (1.0 - (v_sq_ion * (c_s_ion * c_s_ion))) - + (vel_ion[i] * vel_ion[i]) * (1.0 - (c_s_ion * c_s_ion))) + ))) - + shift[i]; + + slow_acoustic_eigs_ion[i] = + (lapse / (1.0 - (v_sq_ion * (c_s_ion * c_s_ion)))) * + ((vel_ion[i] * (1.0 - (c_s_ion * c_s_ion))) - + (c_s_ion * sqrt( + (1.0 - v_sq_ion) * + (inv_spatial_metric[i][i] * (1.0 - (v_sq_ion * (c_s_ion * c_s_ion))) - + (vel_ion[i] * vel_ion[i]) * (1.0 - (c_s_ion * c_s_ion))) + ))) - + shift[i]; } double max_eig = 0.0; @@ -754,35 +963,30 @@ gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, doubl double v_sq = 0.0; if (v_sq_elc > v_sq_ion) { v_sq = v_sq_elc; - } - else { + } else { v_sq = v_sq_ion; } if (fabs(v_sq) + max_eig > light_speed * sqrt(spatial_metric_det) * lapse) { return fabs(v_sq) + max_eig; - } - else { + } else { return light_speed * sqrt(spatial_metric_det) * lapse; } - } - else { + } else { double v_sq_elc = sqrt((vx_elc * vx_elc) + (vy_elc * vy_elc) + (vz_elc * vz_elc)); double v_sq_ion = sqrt((vx_ion * vx_ion) + (vy_ion * vy_ion) + (vz_ion * vz_ion)); double v_sq = 0.0; if (v_sq_elc > v_sq_ion) { v_sq = v_sq_elc; - } - else { + } else { v_sq = v_sq_ion; } double c_s = 0.0; if (c_s_elc > c_s_ion) { c_s = c_s_elc; - } - else { + } else { c_s = c_s_ion; } @@ -793,13 +997,11 @@ gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, doubl if (fabs(v_sq) + c_s > light_speed * sqrt(spatial_metric_det) * lapse) { return fabs(v_sq) + c_s; - } - else { + } else { return light_speed * sqrt(spatial_metric_det) * lapse; } } - } - else { + } else { for (int i = 0; i < 3; i++) { gkyl_free(inv_spatial_metric[i]); } @@ -810,7 +1012,7 @@ gkyl_gr_twofluid_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, doubl } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 84; i++) { @@ -819,7 +1021,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 84; i++) { @@ -827,8 +1029,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -gr_twofluid_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_twofluid_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 0; i < 84; i++) { ghost[i] = skin[i]; @@ -838,8 +1042,10 @@ gr_twofluid_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* ghost[6] = -ghost[6]; } -static void -gr_twofluid_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_twofluid_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 1; i < 4; i++) { ghost[i] = -skin[i]; @@ -860,9 +1066,10 @@ gr_twofluid_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const doubl } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; qlocal[1] = (qglobal[1] * norm[0]) + (qglobal[2] * norm[1]) + (qglobal[3] * norm[2]); @@ -921,9 +1128,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinate frame. - qlocal[22] = v1[0]; qlocal[23] = v1[1]; qlocal[24] = v1[2]; - qlocal[25] = v2[0]; qlocal[26] = v2[1]; qlocal[27] = v2[2]; - qlocal[28] = v3[0]; qlocal[29] = v3[1]; qlocal[30] = v3[2]; + qlocal[22] = v1[0]; + qlocal[23] = v1[1]; + qlocal[24] = v1[2]; + qlocal[25] = v2[0]; + qlocal[26] = v2[1]; + qlocal[27] = v2[2]; + qlocal[28] = v3[0]; + qlocal[29] = v3[1]; + qlocal[30] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -954,9 +1167,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta inv_v3[2] = (extr_r1[2] * tau2[0]) + (extr_r2[2] * tau2[1]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor to local coordinate frame. - qlocal[31] = inv_v1[0]; qlocal[32] = inv_v1[1]; qlocal[33] = inv_v1[2]; - qlocal[34] = inv_v2[0]; qlocal[35] = inv_v2[1]; qlocal[36] = inv_v2[2]; - qlocal[37] = inv_v3[0]; qlocal[38] = inv_v3[1]; qlocal[39] = inv_v3[2]; + qlocal[31] = inv_v1[0]; + qlocal[32] = inv_v1[1]; + qlocal[33] = inv_v1[2]; + qlocal[34] = inv_v2[0]; + qlocal[35] = inv_v2[1]; + qlocal[36] = inv_v2[2]; + qlocal[37] = inv_v3[0]; + qlocal[38] = inv_v3[1]; + qlocal[39] = inv_v3[2]; qlocal[40] = qglobal[40]; @@ -980,22 +1199,37 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); - shiftder_v1[1] = (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); - shiftder_v1[2] = (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); - shiftder_v2[1] = (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); - shiftder_v2[2] = (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); - shiftder_v3[1] = (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); - shiftder_v3[2] = (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); + shiftder_v1[1] = + (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); + shiftder_v1[2] = + (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); + shiftder_v2[1] = + (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); + shiftder_v2[2] = + (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); + shiftder_v3[1] = + (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); + shiftder_v3[2] = + (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative to local coordinate frame. - qlocal[44] = shiftder_v1[0]; qlocal[45] = shiftder_v1[1]; qlocal[46] = shiftder_v1[2]; - qlocal[47] = shiftder_v2[0]; qlocal[48] = shiftder_v2[1]; qlocal[49] = shiftder_v2[2]; - qlocal[50] = shiftder_v3[0]; qlocal[51] = shiftder_v3[1]; qlocal[52] = shiftder_v3[2]; + qlocal[44] = shiftder_v1[0]; + qlocal[45] = shiftder_v1[1]; + qlocal[46] = shiftder_v1[2]; + qlocal[47] = shiftder_v2[0]; + qlocal[48] = shiftder_v2[1]; + qlocal[49] = shiftder_v2[2]; + qlocal[50] = shiftder_v3[0]; + qlocal[51] = shiftder_v3[1]; + qlocal[52] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -1078,7 +1312,7 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta s33[0] = (r31[0] * tau2[0]) + (r32[0] * tau2[1]) + (r33[0] * tau2[2]); s33[1] = (r31[1] * tau2[0]) + (r32[1] * tau2[1]) + (r33[1] * tau2[2]); s33[2] = (r31[2] * tau2[0]) + (r32[2] * tau2[1]) + (r33[2] * tau2[2]); - + // Rotate spatial metric tensor derivative to local coordinate frame. qlocal[53] = (s11[0] * norm[0]) + (s21[0] * norm[1]) + (s31[0] * norm[2]); qlocal[54] = (s11[1] * norm[0]) + (s21[1] * norm[1]) + (s31[1] * norm[2]); @@ -1122,9 +1356,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[83] = (qglobal[81] * tau2[0]) + (qglobal[82] * tau2[1]) + (qglobal[83] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; qglobal[1] = (qlocal[1] * norm[0]) + (qlocal[2] * tau1[0]) + (qlocal[3] * tau2[0]); @@ -1183,9 +1418,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor back to global coordinate frame. - qglobal[22] = v1[0]; qglobal[23] = v1[1]; qglobal[24] = v1[2]; - qglobal[25] = v2[0]; qglobal[26] = v2[1]; qglobal[27] = v2[2]; - qglobal[28] = v3[0]; qglobal[29] = v3[1]; qglobal[30] = v3[2]; + qglobal[22] = v1[0]; + qglobal[23] = v1[1]; + qglobal[24] = v1[2]; + qglobal[25] = v2[0]; + qglobal[26] = v2[1]; + qglobal[27] = v2[2]; + qglobal[28] = v3[0]; + qglobal[29] = v3[1]; + qglobal[30] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -1216,9 +1457,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t inv_v3[2] = (extr_r1[2] * norm[2]) + (extr_r2[2] * tau1[2]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor back to global coordinate frame. - qglobal[31] = inv_v1[0]; qglobal[32] = inv_v1[1]; qglobal[33] = inv_v1[2]; - qglobal[34] = inv_v2[0]; qglobal[35] = inv_v2[1]; qglobal[36] = inv_v2[2]; - qglobal[37] = inv_v3[0]; qglobal[38] = inv_v3[1]; qglobal[39] = inv_v3[2]; + qglobal[31] = inv_v1[0]; + qglobal[32] = inv_v1[1]; + qglobal[33] = inv_v1[2]; + qglobal[34] = inv_v2[0]; + qglobal[35] = inv_v2[1]; + qglobal[36] = inv_v2[2]; + qglobal[37] = inv_v3[0]; + qglobal[38] = inv_v3[1]; + qglobal[39] = inv_v3[2]; qglobal[40] = qlocal[40]; @@ -1242,22 +1489,37 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); - shiftder_v1[1] = (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); - shiftder_v1[2] = (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); - shiftder_v2[1] = (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); - shiftder_v2[2] = (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); - shiftder_v3[1] = (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); - shiftder_v3[2] = (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); + shiftder_v1[1] = + (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); + shiftder_v1[2] = + (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); + shiftder_v2[1] = + (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); + shiftder_v2[2] = + (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); + shiftder_v3[1] = + (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); + shiftder_v3[2] = + (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative back to global coordinate frame. - qglobal[44] = shiftder_v1[0]; qglobal[45] = shiftder_v1[1]; qglobal[46] = shiftder_v1[2]; - qglobal[47] = shiftder_v2[0]; qglobal[48] = shiftder_v2[1]; qglobal[49] = shiftder_v2[2]; - qglobal[50] = shiftder_v3[0]; qglobal[51] = shiftder_v3[1]; qglobal[52] = shiftder_v3[2]; + qglobal[44] = shiftder_v1[0]; + qglobal[45] = shiftder_v1[1]; + qglobal[46] = shiftder_v1[2]; + qglobal[47] = shiftder_v2[0]; + qglobal[48] = shiftder_v2[1]; + qglobal[49] = shiftder_v2[2]; + qglobal[50] = shiftder_v3[0]; + qglobal[51] = shiftder_v3[1]; + qglobal[52] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -1384,8 +1646,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[83] = (qlocal[81] * norm[2]) + (qlocal[82] * tau1[2]) + (qlocal[83] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double gas_gamma_elc = gr_twofluid->gas_gamma_elc; @@ -1418,8 +1682,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr[i] - fl[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr[i] - fl[i]) / amax); } - } - else { + } else { for (int i = 0; i < 84; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1432,8 +1695,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[84]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1445,21 +1710,27 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double gas_gamma_elc = gr_twofluid->gas_gamma_elc; @@ -1490,15 +1761,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_z_l = vl[21]; double spatial_metric_l[3][3]; - spatial_metric_l[0][0] = vl[22]; spatial_metric_l[0][1] = vl[23]; spatial_metric_l[0][2] = vl[24]; - spatial_metric_l[1][0] = vl[25]; spatial_metric_l[1][1] = vl[26]; spatial_metric_l[1][2] = vl[27]; - spatial_metric_l[2][0] = vl[28]; spatial_metric_l[2][1] = vl[29]; spatial_metric_l[2][2] = vl[30]; - - double spatial_metric_det_l = (spatial_metric_l[0][0] * ((spatial_metric_l[1][1] * spatial_metric_l[2][2]) - (spatial_metric_l[2][1] * spatial_metric_l[1][2]))) - - (spatial_metric_l[0][1] * ((spatial_metric_l[1][0] * spatial_metric_l[2][2]) - (spatial_metric_l[1][2] * spatial_metric_l[2][0]))) + - (spatial_metric_l[0][2] * ((spatial_metric_l[1][0] * spatial_metric_l[2][1]) - (spatial_metric_l[1][1] * spatial_metric_l[2][0]))); - - double **inv_spatial_metric_l= gkyl_malloc(sizeof(double*[3])); + spatial_metric_l[0][0] = vl[22]; + spatial_metric_l[0][1] = vl[23]; + spatial_metric_l[0][2] = vl[24]; + spatial_metric_l[1][0] = vl[25]; + spatial_metric_l[1][1] = vl[26]; + spatial_metric_l[1][2] = vl[27]; + spatial_metric_l[2][0] = vl[28]; + spatial_metric_l[2][1] = vl[29]; + spatial_metric_l[2][2] = vl[30]; + + double spatial_metric_det_l = + (spatial_metric_l[0][0] * ((spatial_metric_l[1][1] * spatial_metric_l[2][2]) - + (spatial_metric_l[2][1] * spatial_metric_l[1][2]))) - + (spatial_metric_l[0][1] * ((spatial_metric_l[1][0] * spatial_metric_l[2][2]) - + (spatial_metric_l[1][2] * spatial_metric_l[2][0]))) + + (spatial_metric_l[0][2] * ((spatial_metric_l[1][0] * spatial_metric_l[2][1]) - + (spatial_metric_l[1][1] * spatial_metric_l[2][0]))); + + double **inv_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); } @@ -1517,16 +1798,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_l[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_l = true; } - } - else { + } else { if (fabs(spatial_metric_l[i][j]) > pow(10.0, -8.0)) { curved_spacetime_l = true; } } } } - if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_x_l) > pow(10.0, -8.0) || fabs(shift_y_l) > pow(10.0, -8.0) || - fabs(shift_z_l) > pow(10.0, -8.0)) { + if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_x_l) > pow(10.0, -8.0) || + fabs(shift_y_l) > pow(10.0, -8.0) || fabs(shift_z_l) > pow(10.0, -8.0)) { curved_spacetime_l = true; } @@ -1548,15 +1828,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_z_r = vr[21]; double spatial_metric_r[3][3]; - spatial_metric_r[0][0] = vr[22]; spatial_metric_r[0][1] = vr[23]; spatial_metric_r[0][2] = vr[24]; - spatial_metric_r[1][0] = vr[25]; spatial_metric_r[1][1] = vr[26]; spatial_metric_r[1][2] = vr[27]; - spatial_metric_r[2][0] = vr[28]; spatial_metric_r[2][1] = vr[29]; spatial_metric_r[2][2] = vr[30]; - - double spatial_metric_det_r = (spatial_metric_r[0][0] * ((spatial_metric_r[1][1] * spatial_metric_r[2][2]) - (spatial_metric_r[2][1] * spatial_metric_r[1][2]))) - - (spatial_metric_r[0][1] * ((spatial_metric_r[1][0] * spatial_metric_r[2][2]) - (spatial_metric_r[1][2] * spatial_metric_r[2][0]))) + - (spatial_metric_r[0][2] * ((spatial_metric_r[1][0] * spatial_metric_r[2][1]) - (spatial_metric_r[1][1] * spatial_metric_r[2][0]))); - - double **inv_spatial_metric_r= gkyl_malloc(sizeof(double*[3])); + spatial_metric_r[0][0] = vr[22]; + spatial_metric_r[0][1] = vr[23]; + spatial_metric_r[0][2] = vr[24]; + spatial_metric_r[1][0] = vr[25]; + spatial_metric_r[1][1] = vr[26]; + spatial_metric_r[1][2] = vr[27]; + spatial_metric_r[2][0] = vr[28]; + spatial_metric_r[2][1] = vr[29]; + spatial_metric_r[2][2] = vr[30]; + + double spatial_metric_det_r = + (spatial_metric_r[0][0] * ((spatial_metric_r[1][1] * spatial_metric_r[2][2]) - + (spatial_metric_r[2][1] * spatial_metric_r[1][2]))) - + (spatial_metric_r[0][1] * ((spatial_metric_r[1][0] * spatial_metric_r[2][2]) - + (spatial_metric_r[1][2] * spatial_metric_r[2][0]))) + + (spatial_metric_r[0][2] * ((spatial_metric_r[1][0] * spatial_metric_r[2][1]) - + (spatial_metric_r[1][1] * spatial_metric_r[2][0]))); + + double **inv_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } @@ -1575,16 +1865,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_r[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_r = true; } - } - else { + } else { if (fabs(spatial_metric_r[i][j]) > pow(10.0, -8.0)) { curved_spacetime_r = true; } } } } - if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_x_r) > pow(10.0, -8.0) || fabs(shift_y_r) > pow(10.0, -8.0) || - fabs(shift_z_r) > pow(10.0, -8.0)) { + if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_x_r) > pow(10.0, -8.0) || + fabs(shift_y_r) > pow(10.0, -8.0) || fabs(shift_z_r) > pow(10.0, -8.0)) { curved_spacetime_r = true; } @@ -1617,8 +1906,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (curved_spacetime_l || curved_spacetime_r) { double vel_elc_l[3]; double v_sq_elc_l = 0.0; - vel_elc_l[0] = vx_elc_l; vel_elc_l[1] = vy_elc_l; vel_elc_l[2] = vz_elc_l; - + vel_elc_l[0] = vx_elc_l; + vel_elc_l[1] = vy_elc_l; + vel_elc_l[2] = vz_elc_l; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_elc_l += spatial_metric_l[i][j] * vel_elc_l[i] * vel_elc_l[j]; @@ -1626,7 +1917,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_l[3]; - shift_l[0] = shift_x_l; shift_l[1] = shift_y_l; shift_l[2] = shift_z_l; + shift_l[0] = shift_x_l; + shift_l[1] = shift_y_l; + shift_l[2] = shift_z_l; double material_eigs_elc_l[3]; double fast_acoustic_eigs_elc_l[3]; @@ -1635,13 +1928,27 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_elc_l[i] = (lapse_l * vel_elc_l[i]) - shift_l[i]; - fast_acoustic_eigs_elc_l[i] = (lapse_l / (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l)))) * ((vel_elc_l[i] * (1.0 - (c_s_elc_l * c_s_elc_l))) + - (c_s_elc_l * sqrt((1.0 - v_sq_elc_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l))) - - (vel_elc_l[i] * vel_elc_l[i]) * (1.0 - (c_s_elc_l * c_s_elc_l)))))) - shift_l[i]; - - slow_acoustic_eigs_elc_l[i] = (lapse_l / (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l)))) * ((vel_elc_l[i] * (1.0 - (c_s_elc_l * c_s_elc_l))) - - (c_s_elc_l * sqrt((1.0 - v_sq_elc_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l))) - - (vel_elc_l[i] * vel_elc_l[i]) * (1.0 - (c_s_elc_l * c_s_elc_l)))))) - shift_l[i]; + fast_acoustic_eigs_elc_l[i] = + (lapse_l / (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l)))) * + ((vel_elc_l[i] * (1.0 - (c_s_elc_l * c_s_elc_l))) + + (c_s_elc_l * + sqrt( + (1.0 - v_sq_elc_l) * + (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l))) - + (vel_elc_l[i] * vel_elc_l[i]) * (1.0 - (c_s_elc_l * c_s_elc_l))) + ))) - + shift_l[i]; + + slow_acoustic_eigs_elc_l[i] = + (lapse_l / (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l)))) * + ((vel_elc_l[i] * (1.0 - (c_s_elc_l * c_s_elc_l))) - + (c_s_elc_l * + sqrt( + (1.0 - v_sq_elc_l) * + (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l))) - + (vel_elc_l[i] * vel_elc_l[i]) * (1.0 - (c_s_elc_l * c_s_elc_l))) + ))) - + shift_l[i]; } double max_eig_elc_l = 0.0; @@ -1659,8 +1966,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_elc_r[3]; double v_sq_elc_r = 0.0; - vel_elc_r[0] = vx_elc_r; vel_elc_r[1] = vy_elc_r; vel_elc_r[2] = vz_elc_r; - + vel_elc_r[0] = vx_elc_r; + vel_elc_r[1] = vy_elc_r; + vel_elc_r[2] = vz_elc_r; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_elc_r += spatial_metric_r[i][j] * vel_elc_r[i] * vel_elc_r[j]; @@ -1668,7 +1977,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_r[3]; - shift_r[0] = shift_x_r; shift_r[1] = shift_y_r; shift_r[2] = shift_z_r; + shift_r[0] = shift_x_r; + shift_r[1] = shift_y_r; + shift_r[2] = shift_z_r; double material_eigs_elc_r[3]; double fast_acoustic_eigs_elc_r[3]; @@ -1677,13 +1988,27 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_elc_r[i] = (lapse_r * vel_elc_r[i]) - shift_r[i]; - fast_acoustic_eigs_elc_r[i] = (lapse_r / (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r)))) * ((vel_elc_r[i] * (1.0 - (c_s_elc_r * c_s_elc_r))) + - (c_s_elc_r * sqrt((1.0 - v_sq_elc_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r))) - - (vel_elc_r[i] * vel_elc_r[i]) * (1.0 - (c_s_elc_r * c_s_elc_r)))))) - shift_r[i]; - - slow_acoustic_eigs_elc_r[i] = (lapse_r / (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r)))) * ((vel_elc_r[i] * (1.0 - (c_s_elc_r * c_s_elc_r))) - - (c_s_elc_r * sqrt((1.0 - v_sq_elc_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r))) - - (vel_elc_r[i] * vel_elc_r[i]) * (1.0 - (c_s_elc_r * c_s_elc_r)))))) - shift_r[i]; + fast_acoustic_eigs_elc_r[i] = + (lapse_r / (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r)))) * + ((vel_elc_r[i] * (1.0 - (c_s_elc_r * c_s_elc_r))) + + (c_s_elc_r * + sqrt( + (1.0 - v_sq_elc_r) * + (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r))) - + (vel_elc_r[i] * vel_elc_r[i]) * (1.0 - (c_s_elc_r * c_s_elc_r))) + ))) - + shift_r[i]; + + slow_acoustic_eigs_elc_r[i] = + (lapse_r / (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r)))) * + ((vel_elc_r[i] * (1.0 - (c_s_elc_r * c_s_elc_r))) - + (c_s_elc_r * + sqrt( + (1.0 - v_sq_elc_r) * + (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r))) - + (vel_elc_r[i] * vel_elc_r[i]) * (1.0 - (c_s_elc_r * c_s_elc_r))) + ))) - + shift_r[i]; } double max_eig_elc_r = 0.0; @@ -1706,8 +2031,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_ion_l[3]; double v_sq_ion_l = 0.0; - vel_ion_l[0] = vx_ion_l; vel_ion_l[1] = vy_ion_l; vel_ion_l[2] = vz_ion_l; - + vel_ion_l[0] = vx_ion_l; + vel_ion_l[1] = vy_ion_l; + vel_ion_l[2] = vz_ion_l; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_ion_l += spatial_metric_l[i][j] * vel_ion_l[i] * vel_ion_l[j]; @@ -1721,13 +2048,27 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_ion_l[i] = (lapse_l * vel_ion_l[i]) - shift_l[i]; - fast_acoustic_eigs_ion_l[i] = (lapse_l / (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l)))) * ((vel_ion_l[i] * (1.0 - (c_s_ion_l * c_s_ion_l))) + - (c_s_ion_l * sqrt((1.0 - v_sq_ion_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l))) - - (vel_ion_l[i] * vel_ion_l[i]) * (1.0 - (c_s_ion_l * c_s_ion_l)))))) - shift_l[i]; - - slow_acoustic_eigs_ion_l[i] = (lapse_l / (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l)))) * ((vel_ion_l[i] * (1.0 - (c_s_ion_l * c_s_ion_l))) - - (c_s_ion_l * sqrt((1.0 - v_sq_ion_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l))) - - (vel_ion_l[i] * vel_ion_l[i]) * (1.0 - (c_s_ion_l * c_s_ion_l)))))) - shift_l[i]; + fast_acoustic_eigs_ion_l[i] = + (lapse_l / (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l)))) * + ((vel_ion_l[i] * (1.0 - (c_s_ion_l * c_s_ion_l))) + + (c_s_ion_l * + sqrt( + (1.0 - v_sq_ion_l) * + (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l))) - + (vel_ion_l[i] * vel_ion_l[i]) * (1.0 - (c_s_ion_l * c_s_ion_l))) + ))) - + shift_l[i]; + + slow_acoustic_eigs_ion_l[i] = + (lapse_l / (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l)))) * + ((vel_ion_l[i] * (1.0 - (c_s_ion_l * c_s_ion_l))) - + (c_s_ion_l * + sqrt( + (1.0 - v_sq_ion_l) * + (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l))) - + (vel_ion_l[i] * vel_ion_l[i]) * (1.0 - (c_s_ion_l * c_s_ion_l))) + ))) - + shift_l[i]; } double max_eig_ion_l = 0.0; @@ -1745,8 +2086,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_ion_r[3]; double v_sq_ion_r = 0.0; - vel_ion_r[0] = vx_ion_r; vel_ion_r[1] = vy_ion_r; vel_ion_r[2] = vz_ion_r; - + vel_ion_r[0] = vx_ion_r; + vel_ion_r[1] = vy_ion_r; + vel_ion_r[2] = vz_ion_r; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_ion_r += spatial_metric_r[i][j] * vel_ion_r[i] * vel_ion_r[j]; @@ -1760,13 +2103,27 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_ion_r[i] = (lapse_r * vel_ion_r[i]) - shift_r[i]; - fast_acoustic_eigs_ion_r[i] = (lapse_r / (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r)))) * ((vel_ion_r[i] * (1.0 - (c_s_ion_r * c_s_ion_r))) + - (c_s_ion_r * sqrt((1.0 - v_sq_ion_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r))) - - (vel_ion_r[i] * vel_ion_r[i]) * (1.0 - (c_s_ion_r * c_s_ion_r)))))) - shift_r[i]; - - slow_acoustic_eigs_ion_r[i] = (lapse_r / (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r)))) * ((vel_ion_r[i] * (1.0 - (c_s_ion_r * c_s_ion_r))) - - (c_s_ion_r * sqrt((1.0 - v_sq_ion_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r))) - - (vel_ion_r[i] * vel_ion_r[i]) * (1.0 - (c_s_ion_r * c_s_ion_r)))))) - shift_r[i]; + fast_acoustic_eigs_ion_r[i] = + (lapse_r / (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r)))) * + ((vel_ion_r[i] * (1.0 - (c_s_ion_r * c_s_ion_r))) + + (c_s_ion_r * + sqrt( + (1.0 - v_sq_ion_r) * + (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r))) - + (vel_ion_r[i] * vel_ion_r[i]) * (1.0 - (c_s_ion_r * c_s_ion_r))) + ))) - + shift_r[i]; + + slow_acoustic_eigs_ion_r[i] = + (lapse_r / (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r)))) * + ((vel_ion_r[i] * (1.0 - (c_s_ion_r * c_s_ion_r))) - + (c_s_ion_r * + sqrt( + (1.0 - v_sq_ion_r) * + (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r))) - + (vel_ion_r[i] * vel_ion_r[i]) * (1.0 - (c_s_ion_r * c_s_ion_r))) + ))) - + shift_r[i]; } double max_eig_ion_r = 0.0; @@ -1789,8 +2146,7 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c sl_em = -light_speed * sqrt(spatial_metric_det_l) * lapse_l; sr_em = light_speed * sqrt(spatial_metric_det_r) * lapse_r; - } - else { + } else { sl_elc = (vx_avg_elc - cs_avg_elc) / (1.0 - (vx_avg_elc * cs_avg_elc)); sr_elc = (vx_avg_elc + cs_avg_elc) / (1.0 + (vx_avg_elc * cs_avg_elc)); @@ -1816,7 +2172,8 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c qm[i] = ((sr_em * qr[i]) - (sl_em * ql[i]) + (fl[i] - fr[i])) / (sr_em - sl_em); } - double *w0 = &waves[0 * 84], *w1 = &waves[1 * 84], *w2 = &waves[2 * 84], *w3 = &waves[3 * 84], *w4 = &waves[4 * 84], *w5 = &waves[5 * 84]; + double *w0 = &waves[0 * 84], *w1 = &waves[1 * 84], *w2 = &waves[2 * 84], *w3 = &waves[3 * 84], + *w4 = &waves[4 * 84], *w5 = &waves[5 * 84]; for (int i = 0; i < 84; i++) { w0[i] = 0.0; @@ -1858,49 +2215,61 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c gkyl_free(inv_spatial_metric_l); gkyl_free(inv_spatial_metric_r); - return fmax(fmax(fmax(fabs(sl_elc), fabs(sr_elc)), fmax(fabs(sl_ion), fabs(sr_ion))), fmax(fabs(sl_em), fabs(sr_em))); + return fmax( + fmax(fmax(fabs(sl_elc), fabs(sr_elc)), fmax(fabs(sl_ion), fabs(sr_ion))), + fmax(fabs(sl_em), fabs(sr_em)) + ); } -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { - const double *w0 = &waves[0 * 84], *w1 = &waves[1 * 84], *w2 = &waves[2 * 84], *w3 = &waves[3 * 84], *w4 = &waves[4 * 84], *w5 = &waves[5 * 84]; - double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]), s3m = fmin(0.0, s[3]), s4m = fmin(0.0, s[4]), s5m = fmin(0.0, s[5]); - double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]), s3p = fmax(0.0, s[3]), s4p = fmax(0.0, s[4]), s5p = fmax(0.0, s[5]); + const double *w0 = &waves[0 * 84], *w1 = &waves[1 * 84], *w2 = &waves[2 * 84], + *w3 = &waves[3 * 84], *w4 = &waves[4 * 84], *w5 = &waves[5 * 84]; + double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]), s3m = fmin(0.0, s[3]), + s4m = fmin(0.0, s[4]), s5m = fmin(0.0, s[5]); + double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]), s3p = fmax(0.0, s[3]), + s4p = fmax(0.0, s[4]), s5p = fmax(0.0, s[5]); for (int i = 0; i < 84; i++) { - amdq[i] = (s0m * w0[i]) + (s1m * w1[i]) + (s2m * w2[i]) + (s3m * w3[i]) + (s4m * w4[i]) + (s5m * w5[i]); - apdq[i] = (s0p * w0[i]) + (s1p * w1[i]) + (s2p * w2[i]) + (s3p * w3[i]) + (s4p * w4[i]) + (s5p * w5[i]); + amdq[i] = + (s0m * w0[i]) + (s1m * w1[i]) + (s2m * w2[i]) + (s3m * w3[i]) + (s4m * w4[i]) + (s5m * w5[i]); + apdq[i] = + (s0p * w0[i]) + (s1p * w1[i]) + (s2p * w2[i]) + (s3p * w3[i]) + (s4p * w4[i]) + (s5p * w5[i]); } } -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hll(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_hll(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double gas_gamma_elc = gr_twofluid->gas_gamma_elc; @@ -1927,8 +2296,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 84; m++) { flux_jump[m] = fr[m] - fl[m]; } - } - else { + } else { for (int m = 0; m < 84; m++) { flux_jump[m] = 0.0; } @@ -1940,26 +2308,23 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double gas_gamma_elc = gr_twofluid->gas_gamma_elc; double gas_gamma_ion = gr_twofluid->gas_gamma_ion; - double v[84] = { 0.0 }; + double v[84] = {0.0}; gkyl_gr_twofluid_prim_vars(gas_gamma_elc, gas_gamma_ion, q, v); if (v[0] < 0.0 || v[4] < 0.0 || v[5] < 0.0 || v[9] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double gas_gamma_elc = gr_twofluid->gas_gamma_elc; @@ -1970,7 +2335,7 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) } static inline void -gr_twofluid_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +gr_twofluid_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 5; i++) { diag[i] = qin[i]; @@ -1978,17 +2343,16 @@ gr_twofluid_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, doubl } static inline void -gr_twofluid_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +gr_twofluid_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < 84; i++) { sout[i] = 0.0; } } -void -gkyl_gr_twofluid_free(const struct gkyl_ref_count* ref) +void gkyl_gr_twofluid_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. @@ -2000,32 +2364,31 @@ gkyl_gr_twofluid_free(const struct gkyl_ref_count* ref) gkyl_free(gr_twofluid); } -struct gkyl_wv_eqn* -gkyl_wv_gr_twofluid_new(double mass_elc, double mass_ion, double charge_elc, double charge_ion, double gas_gamma_elc, double gas_gamma_ion, - double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, - bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_gr_twofluid_new( + double mass_elc, double mass_ion, double charge_elc, double charge_ion, double gas_gamma_elc, + double gas_gamma_ion, double light_speed, double e_fact, double b_fact, + enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime *spacetime, + bool use_gpu +) { - return gkyl_wv_gr_twofluid_inew(&(struct gkyl_wv_gr_twofluid_inp) { - .mass_elc = mass_elc, - .mass_ion = mass_ion, - .charge_elc = charge_elc, - .charge_ion = charge_ion, - .gas_gamma_elc = gas_gamma_elc, - .gas_gamma_ion = gas_gamma_ion, - .light_speed = light_speed, - .e_fact = e_fact, - .b_fact = b_fact, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .spacetime = spacetime, - .rp_type = WV_GR_TWOFLUID_RP_HLL, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_gr_twofluid_inew(&(struct gkyl_wv_gr_twofluid_inp + ){.mass_elc = mass_elc, + .mass_ion = mass_ion, + .charge_elc = charge_elc, + .charge_ion = charge_ion, + .gas_gamma_elc = gas_gamma_elc, + .gas_gamma_ion = gas_gamma_ion, + .light_speed = light_speed, + .e_fact = e_fact, + .b_fact = b_fact, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .spacetime = spacetime, + .rp_type = WV_GR_TWOFLUID_RP_HLL, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_gr_twofluid_inew(const struct gkyl_wv_gr_twofluid_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_gr_twofluid_inew(const struct gkyl_wv_gr_twofluid_inp *inp) { struct wv_gr_twofluid *gr_twofluid = gkyl_malloc(sizeof(struct wv_gr_twofluid)); @@ -2051,8 +2414,7 @@ gkyl_wv_gr_twofluid_inew(const struct gkyl_wv_gr_twofluid_inp* inp) gr_twofluid->eqn.num_waves = 2; gr_twofluid->eqn.waves_func = wave_lax_l; gr_twofluid->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_GR_TWOFLUID_RP_HLL) { + } else if (inp->rp_type == WV_GR_TWOFLUID_RP_HLL) { gr_twofluid->eqn.num_waves = 6; gr_twofluid->eqn.waves_func = wave_hll_l; gr_twofluid->eqn.qfluct_func = qfluct_hll_l; @@ -2084,8 +2446,7 @@ gkyl_wv_gr_twofluid_inew(const struct gkyl_wv_gr_twofluid_inp* inp) return &gr_twofluid->eqn; } -double -gkyl_wv_gr_twofluid_mass_elc(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_mass_elc(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double mass_elc = gr_twofluid->mass_elc; @@ -2093,8 +2454,7 @@ gkyl_wv_gr_twofluid_mass_elc(const struct gkyl_wv_eqn* eqn) return mass_elc; } -double -gkyl_wv_gr_twofluid_mass_ion(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_mass_ion(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double mass_ion = gr_twofluid->mass_ion; @@ -2102,8 +2462,7 @@ gkyl_wv_gr_twofluid_mass_ion(const struct gkyl_wv_eqn* eqn) return mass_ion; } -double -gkyl_wv_gr_twofluid_charge_elc(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_charge_elc(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double charge_elc = gr_twofluid->charge_elc; @@ -2111,8 +2470,7 @@ gkyl_wv_gr_twofluid_charge_elc(const struct gkyl_wv_eqn* eqn) return charge_elc; } -double -gkyl_wv_gr_twofluid_charge_ion(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_charge_ion(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double charge_ion = gr_twofluid->charge_ion; @@ -2120,8 +2478,7 @@ gkyl_wv_gr_twofluid_charge_ion(const struct gkyl_wv_eqn* eqn) return charge_ion; } -double -gkyl_wv_gr_twofluid_gas_gamma_elc(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_gas_gamma_elc(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double gas_gamma_elc = gr_twofluid->gas_gamma_elc; @@ -2129,8 +2486,7 @@ gkyl_wv_gr_twofluid_gas_gamma_elc(const struct gkyl_wv_eqn* eqn) return gas_gamma_elc; } -double -gkyl_wv_gr_twofluid_gas_gamma_ion(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_gas_gamma_ion(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double gas_gamma_ion = gr_twofluid->gas_gamma_ion; @@ -2138,8 +2494,7 @@ gkyl_wv_gr_twofluid_gas_gamma_ion(const struct gkyl_wv_eqn* eqn) return gas_gamma_ion; } -double -gkyl_wv_gr_twofluid_light_speed(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_light_speed(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double light_speed = gr_twofluid->light_speed; @@ -2147,8 +2502,7 @@ gkyl_wv_gr_twofluid_light_speed(const struct gkyl_wv_eqn* eqn) return light_speed; } -double -gkyl_wv_gr_twofluid_e_fact(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_e_fact(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double e_fact = gr_twofluid->e_fact; @@ -2156,8 +2510,7 @@ gkyl_wv_gr_twofluid_e_fact(const struct gkyl_wv_eqn* eqn) return e_fact; } -double -gkyl_wv_gr_twofluid_b_fact(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_b_fact(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); double b_fact = gr_twofluid->b_fact; @@ -2165,8 +2518,7 @@ gkyl_wv_gr_twofluid_b_fact(const struct gkyl_wv_eqn* eqn) return b_fact; } -enum gkyl_spacetime_gauge -gkyl_wv_gr_twofluid_spacetime_gauge(const struct gkyl_wv_eqn* eqn) +enum gkyl_spacetime_gauge gkyl_wv_gr_twofluid_spacetime_gauge(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); enum gkyl_spacetime_gauge spacetime_gauge = gr_twofluid->spacetime_gauge; @@ -2174,8 +2526,7 @@ gkyl_wv_gr_twofluid_spacetime_gauge(const struct gkyl_wv_eqn* eqn) return spacetime_gauge; } -int -gkyl_wv_gr_twofluid_reinit_freq(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_gr_twofluid_reinit_freq(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); int reinit_freq = gr_twofluid->reinit_freq; @@ -2183,8 +2534,7 @@ gkyl_wv_gr_twofluid_reinit_freq(const struct gkyl_wv_eqn* eqn) return reinit_freq; } -struct gkyl_gr_spacetime* -gkyl_wv_gr_twofluid_spacetime(const struct gkyl_wv_eqn* eqn) +struct gkyl_gr_spacetime *gkyl_wv_gr_twofluid_spacetime(const struct gkyl_wv_eqn *eqn) { const struct wv_gr_twofluid *gr_twofluid = container_of(eqn, struct wv_gr_twofluid, eqn); struct gkyl_gr_spacetime *spacetime = gr_twofluid->spacetime; diff --git a/moments/zero/wv_gr_twofluid_tetrad.c b/moments/zero/wv_gr_twofluid_tetrad.c index 44c32b94cd..faeb6dce3e 100644 --- a/moments/zero/wv_gr_twofluid_tetrad.c +++ b/moments/zero/wv_gr_twofluid_tetrad.c @@ -6,10 +6,12 @@ #include #include -void -gkyl_gr_twofluid_tetrad_flux(double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, const double q[84], double flux[84]) +void gkyl_gr_twofluid_tetrad_flux( + double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, + const double q[84], double flux[84] +) { - double v[84] = { 0.0 }; + double v[84] = {0.0}; gkyl_gr_twofluid_tetrad_prim_vars(gas_gamma_elc, gas_gamma_ion, q, v); double rho_elc = v[0]; double vx_elc = v[1]; @@ -28,7 +30,7 @@ gkyl_gr_twofluid_tetrad_flux(double gas_gamma_elc, double gas_gamma_ion, double double phi = v[16]; double psi = v[17]; - + bool in_excision_region = false; if (v[40] < pow(10.0, -8.0)) { in_excision_region = true; @@ -46,7 +48,7 @@ gkyl_gr_twofluid_tetrad_flux(double gas_gamma_elc, double gas_gamma_ion, double flux[1] = (rho_elc * h_elc * (W_elc * W_elc) * (vx_elc * vx_elc)) + p_elc; flux[2] = rho_elc * h_elc * (W_elc * W_elc) * (vy_elc * vx_elc); flux[3] = rho_elc * h_elc * (W_elc * W_elc) * (vz_elc * vx_elc); - flux[4] = ((rho_elc * h_elc * (W_elc * W_elc)) - (rho_elc * W_elc)) * vx_elc; + flux[4] = ((rho_elc * h_elc * (W_elc * W_elc)) - (rho_elc * W_elc)) * vx_elc; double W_ion = 1.0 / (sqrt(1.0 - ((vx_ion * vx_ion) + (vy_ion * vy_ion) + (vz_ion * vz_ion)))); if ((vx_ion * vx_ion) + (vy_ion * vy_ion) + (vz_ion * vz_ion) > 1.0 - pow(10.0, -8.0)) { @@ -59,7 +61,7 @@ gkyl_gr_twofluid_tetrad_flux(double gas_gamma_elc, double gas_gamma_ion, double flux[6] = (rho_ion * h_ion * (W_ion * W_ion) * (vx_ion * vx_ion)) + p_ion; flux[7] = rho_ion * h_ion * (W_ion * W_ion) * (vy_ion * vx_ion); flux[8] = rho_ion * h_ion * (W_ion * W_ion) * (vz_ion * vx_ion); - flux[9] = ((rho_ion * h_ion * (W_ion * W_ion)) - (rho_ion * W_ion)) * vx_ion; + flux[9] = ((rho_ion * h_ion * (W_ion * W_ion)) - (rho_ion * W_ion)) * vx_ion; flux[10] = e_fact * (light_speed * light_speed) * phi; flux[11] = (light_speed * light_speed) * Bz; @@ -73,18 +75,19 @@ gkyl_gr_twofluid_tetrad_flux(double gas_gamma_elc, double gas_gamma_ion, double for (int i = 18; i < 84; i++) { flux[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 84; i++) { flux[i] = 0.0; } } } -void -gkyl_gr_twofluid_tetrad_flux_correction(double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, const double q[84], const double flux_sr[84], double flux_gr[84]) +void gkyl_gr_twofluid_tetrad_flux_correction( + double gas_gamma_elc, double gas_gamma_ion, double light_speed, double e_fact, double b_fact, + const double q[84], const double flux_sr[84], double flux_gr[84] +) { - double v[84] = { 0.0 }; + double v[84] = {0.0}; gkyl_gr_twofluid_tetrad_prim_vars(gas_gamma_elc, gas_gamma_ion, q, v); double rho_elc = v[0]; double vx_elc = v[1]; @@ -107,13 +110,22 @@ gkyl_gr_twofluid_tetrad_flux_correction(double gas_gamma_elc, double gas_gamma_i double shift_z = v[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[22]; spatial_metric[0][1] = v[23]; spatial_metric[0][2] = v[24]; - spatial_metric[1][0] = v[25]; spatial_metric[1][1] = v[26]; spatial_metric[1][2] = v[27]; - spatial_metric[2][0] = v[28]; spatial_metric[2][1] = v[29]; spatial_metric[2][2] = v[30]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + spatial_metric[0][0] = v[22]; + spatial_metric[0][1] = v[23]; + spatial_metric[0][2] = v[24]; + spatial_metric[1][0] = v[25]; + spatial_metric[1][1] = v[26]; + spatial_metric[1][2] = v[27]; + spatial_metric[2][0] = v[28]; + spatial_metric[2][1] = v[29]; + spatial_metric[2][2] = v[30]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); bool in_excision_region = false; if (v[40] < pow(10.0, -8.0)) { @@ -123,7 +135,9 @@ gkyl_gr_twofluid_tetrad_flux_correction(double gas_gamma_elc, double gas_gamma_i if (!in_excision_region) { double vel_elc[3]; double v_sq_elc = 0.0; - vel_elc[0] = vx_elc; vel_elc[1] = vy_elc; vel_elc[2] = vz_elc; + vel_elc[0] = vx_elc; + vel_elc[1] = vy_elc; + vel_elc[2] = vz_elc; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -131,7 +145,8 @@ gkyl_gr_twofluid_tetrad_flux_correction(double gas_gamma_elc, double gas_gamma_i } } - double W_flat_elc = 1.0 / (sqrt(1.0 - ((vx_elc * vx_elc) + (vy_elc * vy_elc) + (vz_elc * vz_elc)))); + double W_flat_elc = + 1.0 / (sqrt(1.0 - ((vx_elc * vx_elc) + (vy_elc * vy_elc) + (vz_elc * vz_elc)))); if ((vx_elc * vx_elc) + (vy_elc * vy_elc) + (vz_elc * vz_elc) > 1.0 - pow(10.0, -8.0)) { W_flat_elc = 1.0 / sqrt(pow(10.0, -8.0)); } @@ -144,22 +159,38 @@ gkyl_gr_twofluid_tetrad_flux_correction(double gas_gamma_elc, double gas_gamma_i if (fabs(vx_elc) < pow(10.0, -8.0)) { if (vx_elc > 0.0) { vx_elc = pow(10.0, -8.0); - } - else { + } else { vx_elc = -pow(10.0, -8.0); } } - flux_gr[0] = (lapse * sqrt(spatial_det)) * ((flux_sr[0] * (vx_elc - (shift_x / lapse)) * W_curved_elc) / (vx_elc * W_flat_elc)); - flux_gr[1] = (lapse * sqrt(spatial_det)) * ((((flux_sr[1] - p_elc) * (vx_elc - (shift_x / lapse)) * (W_curved_elc * W_curved_elc)) / (vx_elc * (W_flat_elc * W_flat_elc))) + p_elc); - flux_gr[2] = (lapse * sqrt(spatial_det)) * ((flux_sr[2] * (vx_elc - (shift_x / lapse)) * (W_curved_elc * W_curved_elc)) / (vx_elc * (W_flat_elc * W_flat_elc))); - flux_gr[3] = (lapse * sqrt(spatial_det)) * ((flux_sr[3] * (vx_elc - (shift_x / lapse)) * (W_curved_elc * W_curved_elc)) / (vx_elc * (W_flat_elc * W_flat_elc))); - flux_gr[4] = (lapse * sqrt(spatial_det)) * (((((flux_sr[4] + (rho_elc * vx_elc * W_flat_elc)) * (W_curved_elc * W_curved_elc)) / (vx_elc * (W_flat_elc * W_flat_elc))) - p_elc - - (rho_elc * W_curved_elc)) * (vx_elc - (shift_x / lapse)) + (p_elc * vx_elc)); - + flux_gr[0] = + (lapse * sqrt(spatial_det)) * + ((flux_sr[0] * (vx_elc - (shift_x / lapse)) * W_curved_elc) / (vx_elc * W_flat_elc)); + flux_gr[1] = + (lapse * sqrt(spatial_det)) * + ((((flux_sr[1] - p_elc) * (vx_elc - (shift_x / lapse)) * (W_curved_elc * W_curved_elc)) / + (vx_elc * (W_flat_elc * W_flat_elc))) + + p_elc); + flux_gr[2] = (lapse * sqrt(spatial_det)) * + ((flux_sr[2] * (vx_elc - (shift_x / lapse)) * (W_curved_elc * W_curved_elc)) / + (vx_elc * (W_flat_elc * W_flat_elc))); + flux_gr[3] = (lapse * sqrt(spatial_det)) * + ((flux_sr[3] * (vx_elc - (shift_x / lapse)) * (W_curved_elc * W_curved_elc)) / + (vx_elc * (W_flat_elc * W_flat_elc))); + flux_gr[4] = + (lapse * sqrt(spatial_det)) * + (((((flux_sr[4] + (rho_elc * vx_elc * W_flat_elc)) * (W_curved_elc * W_curved_elc)) / + (vx_elc * (W_flat_elc * W_flat_elc))) - + p_elc - (rho_elc * W_curved_elc)) * + (vx_elc - (shift_x / lapse)) + + (p_elc * vx_elc)); + double vel_ion[3]; double v_sq_ion = 0.0; - vel_ion[0] = vx_ion; vel_ion[1] = vy_ion; vel_ion[2] = vz_ion; + vel_ion[0] = vx_ion; + vel_ion[1] = vy_ion; + vel_ion[2] = vz_ion; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -167,7 +198,8 @@ gkyl_gr_twofluid_tetrad_flux_correction(double gas_gamma_elc, double gas_gamma_i } } - double W_flat_ion = 1.0 / (sqrt(1.0 - ((vx_ion * vx_ion) + (vy_ion * vy_ion) + (vz_ion * vz_ion)))); + double W_flat_ion = + 1.0 / (sqrt(1.0 - ((vx_ion * vx_ion) + (vy_ion * vy_ion) + (vz_ion * vz_ion)))); if ((vx_ion * vx_ion) + (vy_ion * vy_ion) + (vz_ion * vz_ion) > 1.0 - pow(10.0, -8.0)) { W_flat_ion = 1.0 / sqrt(pow(10.0, -8.0)); } @@ -180,41 +212,59 @@ gkyl_gr_twofluid_tetrad_flux_correction(double gas_gamma_elc, double gas_gamma_i if (fabs(vx_ion) < pow(10.0, -8.0)) { if (vx_ion > 0.0) { vx_ion = pow(10.0, -8.0); - } - else { + } else { vx_ion = -pow(10.0, -8.0); } } - flux_gr[5] = (lapse * sqrt(spatial_det)) * ((flux_sr[5] * (vx_ion - (shift_x / lapse)) * W_curved_ion) / (vx_ion * W_flat_ion)); - flux_gr[6] = (lapse * sqrt(spatial_det)) * ((((flux_sr[6] - p_ion) * (vx_ion - (shift_x / lapse)) * (W_curved_ion * W_curved_ion)) / (vx_ion * (W_flat_ion * W_flat_ion))) + p_ion); - flux_gr[7] = (lapse * sqrt(spatial_det)) * ((flux_sr[7] * (vx_ion - (shift_x / lapse)) * (W_curved_ion * W_curved_ion)) / (vx_ion * (W_flat_ion * W_flat_ion))); - flux_gr[8] = (lapse * sqrt(spatial_det)) * ((flux_sr[8] * (vx_ion - (shift_x / lapse)) * (W_curved_ion * W_curved_ion)) / (vx_ion * (W_flat_ion * W_flat_ion))); - flux_gr[9] = (lapse * sqrt(spatial_det)) * (((((flux_sr[9] + (rho_ion * vx_ion * W_flat_ion)) * (W_curved_ion * W_curved_ion)) / (vx_ion * (W_flat_ion * W_flat_ion))) - p_ion - - (rho_ion * W_curved_ion)) * (vx_ion - (shift_x / lapse)) + (p_ion * vx_ion)); + flux_gr[5] = + (lapse * sqrt(spatial_det)) * + ((flux_sr[5] * (vx_ion - (shift_x / lapse)) * W_curved_ion) / (vx_ion * W_flat_ion)); + flux_gr[6] = + (lapse * sqrt(spatial_det)) * + ((((flux_sr[6] - p_ion) * (vx_ion - (shift_x / lapse)) * (W_curved_ion * W_curved_ion)) / + (vx_ion * (W_flat_ion * W_flat_ion))) + + p_ion); + flux_gr[7] = (lapse * sqrt(spatial_det)) * + ((flux_sr[7] * (vx_ion - (shift_x / lapse)) * (W_curved_ion * W_curved_ion)) / + (vx_ion * (W_flat_ion * W_flat_ion))); + flux_gr[8] = (lapse * sqrt(spatial_det)) * + ((flux_sr[8] * (vx_ion - (shift_x / lapse)) * (W_curved_ion * W_curved_ion)) / + (vx_ion * (W_flat_ion * W_flat_ion))); + flux_gr[9] = + (lapse * sqrt(spatial_det)) * + (((((flux_sr[9] + (rho_ion * vx_ion * W_flat_ion)) * (W_curved_ion * W_curved_ion)) / + (vx_ion * (W_flat_ion * W_flat_ion))) - + p_ion - (rho_ion * W_curved_ion)) * + (vx_ion - (shift_x / lapse)) + + (p_ion * vx_ion)); flux_gr[10] = flux_sr[10]; - flux_gr[11] = (lapse * flux_sr[11]) - (light_speed * light_speed) * ((shift_x * flux_sr[15]) - (shift_y * Ex)); - flux_gr[12] = (lapse * flux_sr[12]) + (light_speed * light_speed) * ((shift_x * flux_sr[14]) + (shift_z * Ex)); + flux_gr[11] = (lapse * flux_sr[11]) - + (light_speed * light_speed) * ((shift_x * flux_sr[15]) - (shift_y * Ex)); + flux_gr[12] = (lapse * flux_sr[12]) + + (light_speed * light_speed) * ((shift_x * flux_sr[14]) + (shift_z * Ex)); flux_gr[13] = flux_sr[13]; - flux_gr[14] = (lapse * flux_sr[14]) + ((shift_x * (flux_sr[12] / (light_speed * light_speed))) + (shift_y * Bx)); - flux_gr[15] = (lapse * flux_sr[15]) - ((shift_x * (flux_sr[11] / (light_speed * light_speed))) - (shift_z * Bx)); + flux_gr[14] = (lapse * flux_sr[14]) + + ((shift_x * (flux_sr[12] / (light_speed * light_speed))) + (shift_y * Bx)); + flux_gr[15] = (lapse * flux_sr[15]) - + ((shift_x * (flux_sr[11] / (light_speed * light_speed))) - (shift_z * Bx)); flux_gr[16] = flux_sr[16]; flux_gr[17] = flux_sr[17]; for (int i = 18; i < 84; i++) { flux_gr[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 84; i++) { flux_gr[i] = 0.0; } } } -void -gkyl_gr_twofluid_tetrad_prim_vars(double gas_gamma_elc, double gas_gamma_ion, const double q[84], double v[84]) +void gkyl_gr_twofluid_tetrad_prim_vars( + double gas_gamma_elc, double gas_gamma_ion, const double q[84], double v[84] +) { double Dx = q[10], Dy = q[11], Dz = q[12]; double Bx = q[13], By = q[14], Bz = q[15]; @@ -228,14 +278,26 @@ gkyl_gr_twofluid_tetrad_prim_vars(double gas_gamma_elc, double gas_gamma_ion, co double shift_z = q[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = q[22]; spatial_metric[0][1] = q[23]; spatial_metric[0][2] = q[24]; - spatial_metric[1][0] = q[25]; spatial_metric[1][1] = q[26]; spatial_metric[1][2] = q[27]; - spatial_metric[2][0] = q[28]; spatial_metric[2][1] = q[29]; spatial_metric[2][2] = q[30]; - + spatial_metric[0][0] = q[22]; + spatial_metric[0][1] = q[23]; + spatial_metric[0][2] = q[24]; + spatial_metric[1][0] = q[25]; + spatial_metric[1][1] = q[26]; + spatial_metric[1][2] = q[27]; + spatial_metric[2][0] = q[28]; + spatial_metric[2][1] = q[29]; + spatial_metric[2][2] = q[30]; + double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = q[31]; extrinsic_curvature[0][1] = q[32]; extrinsic_curvature[0][2] = q[33]; - extrinsic_curvature[1][0] = q[34]; extrinsic_curvature[1][1] = q[35]; extrinsic_curvature[1][2] = q[36]; - extrinsic_curvature[2][0] = q[37]; extrinsic_curvature[2][1] = q[38]; extrinsic_curvature[2][2] = q[39]; + extrinsic_curvature[0][0] = q[31]; + extrinsic_curvature[0][1] = q[32]; + extrinsic_curvature[0][2] = q[33]; + extrinsic_curvature[1][0] = q[34]; + extrinsic_curvature[1][1] = q[35]; + extrinsic_curvature[1][2] = q[36]; + extrinsic_curvature[2][0] = q[37]; + extrinsic_curvature[2][1] = q[38]; + extrinsic_curvature[2][2] = q[39]; double lapse_der[3]; lapse_der[0] = q[41]; @@ -243,22 +305,46 @@ gkyl_gr_twofluid_tetrad_prim_vars(double gas_gamma_elc, double gas_gamma_ion, co lapse_der[2] = q[43]; double shift_der[3][3]; - shift_der[0][0] = q[44]; shift_der[0][1] = q[45]; shift_der[0][2] = q[46]; - shift_der[1][0] = q[47]; shift_der[1][1] = q[48]; shift_der[1][2] = q[49]; - shift_der[2][0] = q[50]; shift_der[2][1] = q[51]; shift_der[2][2] = q[52]; + shift_der[0][0] = q[44]; + shift_der[0][1] = q[45]; + shift_der[0][2] = q[46]; + shift_der[1][0] = q[47]; + shift_der[1][1] = q[48]; + shift_der[1][2] = q[49]; + shift_der[2][0] = q[50]; + shift_der[2][1] = q[51]; + shift_der[2][2] = q[52]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = q[53]; spatial_metric_der[0][0][1] = q[54]; spatial_metric_der[0][0][2] = q[55]; - spatial_metric_der[0][1][0] = q[56]; spatial_metric_der[0][1][1] = q[57]; spatial_metric_der[0][1][2] = q[58]; - spatial_metric_der[0][2][0] = q[59]; spatial_metric_der[0][2][1] = q[60]; spatial_metric_der[0][2][2] = q[61]; - - spatial_metric_der[1][0][0] = q[62]; spatial_metric_der[1][0][1] = q[63]; spatial_metric_der[1][0][2] = q[64]; - spatial_metric_der[1][1][0] = q[65]; spatial_metric_der[1][1][1] = q[66]; spatial_metric_der[1][1][2] = q[67]; - spatial_metric_der[1][2][0] = q[68]; spatial_metric_der[1][2][1] = q[69]; spatial_metric_der[1][2][2] = q[70]; - - spatial_metric_der[0][0][0] = q[71]; spatial_metric_der[0][0][1] = q[72]; spatial_metric_der[0][0][2] = q[73]; - spatial_metric_der[0][1][0] = q[74]; spatial_metric_der[0][1][1] = q[75]; spatial_metric_der[0][1][2] = q[76]; - spatial_metric_der[0][2][0] = q[77]; spatial_metric_der[0][2][1] = q[78]; spatial_metric_der[0][2][2] = q[79]; + spatial_metric_der[0][0][0] = q[53]; + spatial_metric_der[0][0][1] = q[54]; + spatial_metric_der[0][0][2] = q[55]; + spatial_metric_der[0][1][0] = q[56]; + spatial_metric_der[0][1][1] = q[57]; + spatial_metric_der[0][1][2] = q[58]; + spatial_metric_der[0][2][0] = q[59]; + spatial_metric_der[0][2][1] = q[60]; + spatial_metric_der[0][2][2] = q[61]; + + spatial_metric_der[1][0][0] = q[62]; + spatial_metric_der[1][0][1] = q[63]; + spatial_metric_der[1][0][2] = q[64]; + spatial_metric_der[1][1][0] = q[65]; + spatial_metric_der[1][1][1] = q[66]; + spatial_metric_der[1][1][2] = q[67]; + spatial_metric_der[1][2][0] = q[68]; + spatial_metric_der[1][2][1] = q[69]; + spatial_metric_der[1][2][2] = q[70]; + + spatial_metric_der[0][0][0] = q[71]; + spatial_metric_der[0][0][1] = q[72]; + spatial_metric_der[0][0][2] = q[73]; + spatial_metric_der[0][1][0] = q[74]; + spatial_metric_der[0][1][1] = q[75]; + spatial_metric_der[0][1][2] = q[76]; + spatial_metric_der[0][2][0] = q[77]; + spatial_metric_der[0][2][1] = q[78]; + spatial_metric_der[0][2][2] = q[79]; double evol_param = q[80]; double x = q[81]; @@ -271,9 +357,12 @@ gkyl_gr_twofluid_tetrad_prim_vars(double gas_gamma_elc, double gas_gamma_ion, co } if (!in_excision_region) { - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double D_elc = q[0] / sqrt(spatial_det); double momx_elc = q[1] / sqrt(spatial_det); @@ -281,45 +370,60 @@ gkyl_gr_twofluid_tetrad_prim_vars(double gas_gamma_elc, double gas_gamma_ion, co double momz_elc = q[3] / sqrt(spatial_det); double Etot_elc = q[4] / sqrt(spatial_det); - double C_elc = D_elc / sqrt(((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc))); - double C0_elc = (D_elc + Etot_elc) / sqrt(((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc))); - if (((Etot_elc + D_elc) * (Etot_elc + D_elc)) - ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) < pow(10.0, -8.0)) { + double C_elc = D_elc / sqrt( + ((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) + ); + double C0_elc = + (D_elc + Etot_elc) / sqrt( + ((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) + ); + if (((Etot_elc + D_elc) * (Etot_elc + D_elc)) - + ((momx_elc * momx_elc) + (momy_elc * momy_elc) + (momz_elc * momz_elc)) < + pow(10.0, -8.0)) { C_elc = D_elc / sqrt(pow(10.0, -8.0)); C0_elc = (D_elc + Etot_elc) / sqrt(pow(10.0, -8.0)); } double alpha0_elc = -1.0 / (gas_gamma_elc * gas_gamma_elc); double alpha1_elc = -2.0 * C_elc * ((gas_gamma_elc - 1.0) / (gas_gamma_elc * gas_gamma_elc)); - double alpha2_elc = ((gas_gamma_elc - 2.0) / gas_gamma_elc) * ((C0_elc * C0_elc) - 1.0) + 1.0 - (C_elc * C_elc) * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * - ((gas_gamma_elc - 1.0) / gas_gamma_elc); + double alpha2_elc = ((gas_gamma_elc - 2.0) / gas_gamma_elc) * ((C0_elc * C0_elc) - 1.0) + 1.0 - + (C_elc * C_elc) * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * + ((gas_gamma_elc - 1.0) / gas_gamma_elc); double alpha4_elc = (C0_elc * C0_elc) - 1.0; - double eta_elc = 2.0 * C_elc *((gas_gamma_elc - 1.0) / gas_gamma_elc); + double eta_elc = 2.0 * C_elc * ((gas_gamma_elc - 1.0) / gas_gamma_elc); double guess_elc = 1.0; int iter_elc = 0; while (iter_elc < 100) { - double poly_elc = (alpha4_elc * (guess_elc * guess_elc * guess_elc) * (guess_elc - eta_elc)) + (alpha2_elc * (guess_elc * guess_elc)) + - (alpha1_elc * guess_elc) + alpha0_elc; - double poly_der_elc = alpha1_elc + (2.0 * alpha2_elc * guess_elc) + (4.0 * alpha4_elc * (guess_elc * guess_elc * guess_elc)) - - (3.0 * eta_elc * alpha4_elc * (guess_elc * guess_elc)); + double poly_elc = (alpha4_elc * (guess_elc * guess_elc * guess_elc) * (guess_elc - eta_elc)) + + (alpha2_elc * (guess_elc * guess_elc)) + (alpha1_elc * guess_elc) + + alpha0_elc; + double poly_der_elc = alpha1_elc + (2.0 * alpha2_elc * guess_elc) + + (4.0 * alpha4_elc * (guess_elc * guess_elc * guess_elc)) - + (3.0 * eta_elc * alpha4_elc * (guess_elc * guess_elc)); double guess_new_elc = guess_elc - (poly_elc / poly_der_elc); if (fabs(guess_elc - guess_new_elc) < pow(10.0, -8.0)) { iter_elc = 100; - } - else { + } else { iter_elc += 1; guess_elc = guess_new_elc; } } - double W_elc = 0.5 * C0_elc * guess_elc * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * ((1.0 - (C_elc * guess_elc)) / - ((C0_elc * C0_elc) * (guess_elc * guess_elc)))))); + double W_elc = + 0.5 * C0_elc * guess_elc * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma_elc - 1.0) / gas_gamma_elc) * + ((1.0 - (C_elc * guess_elc)) / ((C0_elc * C0_elc) * (guess_elc * guess_elc)))) + )); double h_elc = 1.0 / (C_elc * guess_elc); - v[0] = D_elc / W_elc; + v[0] = D_elc / W_elc; v[1] = momx_elc / (v[0] * h_elc * (W_elc * W_elc)); v[2] = momy_elc / (v[0] * h_elc * (W_elc * W_elc)); v[3] = momz_elc / (v[0] * h_elc * (W_elc * W_elc)); @@ -338,45 +442,60 @@ gkyl_gr_twofluid_tetrad_prim_vars(double gas_gamma_elc, double gas_gamma_ion, co double momz_ion = q[8] / sqrt(spatial_det); double Etot_ion = q[9] / sqrt(spatial_det); - double C_ion = D_ion / sqrt(((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion))); - double C0_ion = (D_ion + Etot_ion) / sqrt(((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion))); - if (((Etot_ion + D_ion) * (Etot_ion + D_ion)) - ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) < pow(10.0, -8.0)) { + double C_ion = D_ion / sqrt( + ((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) + ); + double C0_ion = + (D_ion + Etot_ion) / sqrt( + ((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) + ); + if (((Etot_ion + D_ion) * (Etot_ion + D_ion)) - + ((momx_ion * momx_ion) + (momy_ion * momy_ion) + (momz_ion * momz_ion)) < + pow(10.0, -8.0)) { C_ion = D_ion / sqrt(pow(10.0, -8.0)); C0_ion = (D_ion + Etot_ion) / sqrt(pow(10.0, -8.0)); } double alpha0_ion = -1.0 / (gas_gamma_ion * gas_gamma_ion); double alpha1_ion = -2.0 * C_ion * ((gas_gamma_ion - 1.0) / (gas_gamma_ion * gas_gamma_ion)); - double alpha2_ion = ((gas_gamma_ion - 2.0) / gas_gamma_ion) * ((C0_ion * C0_ion) - 1.0) + 1.0 - (C_ion * C_ion) * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * - ((gas_gamma_ion - 1.0) / gas_gamma_ion); + double alpha2_ion = ((gas_gamma_ion - 2.0) / gas_gamma_ion) * ((C0_ion * C0_ion) - 1.0) + 1.0 - + (C_ion * C_ion) * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * + ((gas_gamma_ion - 1.0) / gas_gamma_ion); double alpha4_ion = (C0_ion * C0_ion) - 1.0; - double eta_ion = 2.0 * C_ion *((gas_gamma_ion - 1.0) / gas_gamma_ion); + double eta_ion = 2.0 * C_ion * ((gas_gamma_ion - 1.0) / gas_gamma_ion); double guess_ion = 1.0; int iter_ion = 0; while (iter_ion < 100) { - double poly_ion = (alpha4_ion * (guess_ion * guess_ion * guess_ion) * (guess_ion - eta_ion)) + (alpha2_ion * (guess_ion * guess_ion)) + - (alpha1_ion * guess_ion) + alpha0_ion; - double poly_der_ion = alpha1_ion + (2.0 * alpha2_ion * guess_ion) + (4.0 * alpha4_ion * (guess_ion * guess_ion * guess_ion)) - - (3.0 * eta_ion * alpha4_ion * (guess_ion * guess_ion)); + double poly_ion = (alpha4_ion * (guess_ion * guess_ion * guess_ion) * (guess_ion - eta_ion)) + + (alpha2_ion * (guess_ion * guess_ion)) + (alpha1_ion * guess_ion) + + alpha0_ion; + double poly_der_ion = alpha1_ion + (2.0 * alpha2_ion * guess_ion) + + (4.0 * alpha4_ion * (guess_ion * guess_ion * guess_ion)) - + (3.0 * eta_ion * alpha4_ion * (guess_ion * guess_ion)); double guess_new_ion = guess_ion - (poly_ion / poly_der_ion); if (fabs(guess_ion - guess_new_ion) < pow(10.0, -8.0)) { iter_ion = 100; - } - else { + } else { iter_ion += 1; guess_ion = guess_new_ion; } } - double W_ion = 0.5 * C0_ion * guess_ion * (1.0 + sqrt(1.0 + (4.0 * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * ((1.0 - (C_ion * guess_ion)) / - ((C0_ion * C0_ion) * (guess_ion * guess_ion)))))); + double W_ion = + 0.5 * C0_ion * guess_ion * + (1.0 + sqrt( + 1.0 + (4.0 * ((gas_gamma_ion - 1.0) / gas_gamma_ion) * + ((1.0 - (C_ion * guess_ion)) / ((C0_ion * C0_ion) * (guess_ion * guess_ion)))) + )); double h_ion = 1.0 / (C_ion * guess_ion); - v[5] = D_ion / W_ion; + v[5] = D_ion / W_ion; v[6] = momx_ion / (v[5] * h_ion * (W_ion * W_ion)); v[7] = momy_ion / (v[5] * h_ion * (W_ion * W_ion)); v[8] = momz_ion / (v[5] * h_ion * (W_ion * W_ion)); @@ -389,8 +508,12 @@ gkyl_gr_twofluid_tetrad_prim_vars(double gas_gamma_elc, double gas_gamma_ion, co v[9] = pow(10.0, -8.0); } - v[10] = Dx; v[11] = Dy; v[12] = Dz; - v[13] = Bx; v[14] = By; v[15] = Bz; + v[10] = Dx; + v[11] = Dy; + v[12] = Dz; + v[13] = Bx; + v[14] = By; + v[15] = Bz; v[16] = phi; v[17] = psi; @@ -400,13 +523,25 @@ gkyl_gr_twofluid_tetrad_prim_vars(double gas_gamma_elc, double gas_gamma_ion, co v[20] = shift_y; v[21] = shift_z; - v[22] = spatial_metric[0][0]; v[23] = spatial_metric[0][1]; v[24] = spatial_metric[0][2]; - v[25] = spatial_metric[1][0]; v[26] = spatial_metric[1][1]; v[27] = spatial_metric[1][2]; - v[28] = spatial_metric[2][0]; v[29] = spatial_metric[2][1]; v[30] = spatial_metric[2][2]; - - v[31] = extrinsic_curvature[0][0]; v[32] = extrinsic_curvature[0][1]; v[33] = extrinsic_curvature[0][2]; - v[34] = extrinsic_curvature[1][0]; v[35] = extrinsic_curvature[1][1]; v[36] = extrinsic_curvature[1][2]; - v[37] = extrinsic_curvature[2][0]; v[38] = extrinsic_curvature[2][1]; v[39] = extrinsic_curvature[2][2]; + v[22] = spatial_metric[0][0]; + v[23] = spatial_metric[0][1]; + v[24] = spatial_metric[0][2]; + v[25] = spatial_metric[1][0]; + v[26] = spatial_metric[1][1]; + v[27] = spatial_metric[1][2]; + v[28] = spatial_metric[2][0]; + v[29] = spatial_metric[2][1]; + v[30] = spatial_metric[2][2]; + + v[31] = extrinsic_curvature[0][0]; + v[32] = extrinsic_curvature[0][1]; + v[33] = extrinsic_curvature[0][2]; + v[34] = extrinsic_curvature[1][0]; + v[35] = extrinsic_curvature[1][1]; + v[36] = extrinsic_curvature[1][2]; + v[37] = extrinsic_curvature[2][0]; + v[38] = extrinsic_curvature[2][1]; + v[39] = extrinsic_curvature[2][2]; v[40] = 1.0; @@ -414,48 +549,79 @@ gkyl_gr_twofluid_tetrad_prim_vars(double gas_gamma_elc, double gas_gamma_ion, co v[42] = lapse_der[1]; v[43] = lapse_der[2]; - v[44] = shift_der[0][0]; v[45] = shift_der[0][1]; v[46] = shift_der[0][2]; - v[47] = shift_der[1][0]; v[48] = shift_der[1][1]; v[49] = shift_der[1][2]; - v[50] = shift_der[2][0]; v[51] = shift_der[2][1]; v[52] = shift_der[2][2]; - - v[53] = spatial_metric_der[0][0][0]; v[54] = spatial_metric_der[0][0][1]; v[55] = spatial_metric_der[0][0][2]; - v[56] = spatial_metric_der[0][1][0]; v[57] = spatial_metric_der[0][1][1]; v[58] = spatial_metric_der[0][1][2]; - v[59] = spatial_metric_der[0][2][0]; v[60] = spatial_metric_der[0][2][1]; v[61] = spatial_metric_der[0][2][2]; - - v[62] = spatial_metric_der[1][0][0]; v[63] = spatial_metric_der[1][0][1]; v[64] = spatial_metric_der[1][0][2]; - v[65] = spatial_metric_der[1][1][0]; v[66] = spatial_metric_der[1][1][1]; v[67] = spatial_metric_der[1][1][2]; - v[68] = spatial_metric_der[1][2][0]; v[69] = spatial_metric_der[1][2][1]; v[70] = spatial_metric_der[1][2][2]; - - v[71] = spatial_metric_der[2][0][0]; v[72] = spatial_metric_der[2][0][1]; v[73] = spatial_metric_der[2][0][2]; - v[74] = spatial_metric_der[2][1][0]; v[75] = spatial_metric_der[2][1][1]; v[76] = spatial_metric_der[2][1][2]; - v[77] = spatial_metric_der[2][2][0]; v[78] = spatial_metric_der[2][2][1]; v[79] = spatial_metric_der[2][2][2]; + v[44] = shift_der[0][0]; + v[45] = shift_der[0][1]; + v[46] = shift_der[0][2]; + v[47] = shift_der[1][0]; + v[48] = shift_der[1][1]; + v[49] = shift_der[1][2]; + v[50] = shift_der[2][0]; + v[51] = shift_der[2][1]; + v[52] = shift_der[2][2]; + + v[53] = spatial_metric_der[0][0][0]; + v[54] = spatial_metric_der[0][0][1]; + v[55] = spatial_metric_der[0][0][2]; + v[56] = spatial_metric_der[0][1][0]; + v[57] = spatial_metric_der[0][1][1]; + v[58] = spatial_metric_der[0][1][2]; + v[59] = spatial_metric_der[0][2][0]; + v[60] = spatial_metric_der[0][2][1]; + v[61] = spatial_metric_der[0][2][2]; + + v[62] = spatial_metric_der[1][0][0]; + v[63] = spatial_metric_der[1][0][1]; + v[64] = spatial_metric_der[1][0][2]; + v[65] = spatial_metric_der[1][1][0]; + v[66] = spatial_metric_der[1][1][1]; + v[67] = spatial_metric_der[1][1][2]; + v[68] = spatial_metric_der[1][2][0]; + v[69] = spatial_metric_der[1][2][1]; + v[70] = spatial_metric_der[1][2][2]; + + v[71] = spatial_metric_der[2][0][0]; + v[72] = spatial_metric_der[2][0][1]; + v[73] = spatial_metric_der[2][0][2]; + v[74] = spatial_metric_der[2][1][0]; + v[75] = spatial_metric_der[2][1][1]; + v[76] = spatial_metric_der[2][1][2]; + v[77] = spatial_metric_der[2][2][0]; + v[78] = spatial_metric_der[2][2][1]; + v[79] = spatial_metric_der[2][2][2]; v[80] = evol_param; v[81] = x; v[82] = y; v[83] = z; - } - else { + } else { for (int i = 0; i < 84; i++) { v[i] = 0.0; } - + v[40] = -1.0; } } -void -gkyl_gr_twofluid_tetrad_inv_spatial_metric(const double q[84], double ***inv_spatial_metric) +void gkyl_gr_twofluid_tetrad_inv_spatial_metric(const double q[84], double ***inv_spatial_metric) { double spatial_metric[3][3]; - spatial_metric[0][0] = q[22]; spatial_metric[0][1] = q[23]; spatial_metric[0][2] = q[24]; - spatial_metric[1][0] = q[25]; spatial_metric[1][1] = q[26]; spatial_metric[1][2] = q[27]; - spatial_metric[2][0] = q[28]; spatial_metric[2][1] = q[29]; spatial_metric[2][2] = q[30]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = q[22]; + spatial_metric[0][1] = q[23]; + spatial_metric[0][2] = q[24]; + spatial_metric[1][0] = q[25]; + spatial_metric[1][1] = q[26]; + spatial_metric[1][2] = q[27]; + spatial_metric[2][0] = q[28]; + spatial_metric[2][1] = q[29]; + spatial_metric[2][2] = q[30]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -486,8 +652,7 @@ gkyl_gr_twofluid_tetrad_inv_spatial_metric(const double q[84], double ***inv_spa for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -495,16 +660,18 @@ gkyl_gr_twofluid_tetrad_inv_spatial_metric(const double q[84], double ***inv_spa for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*inv_spatial_metric)[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*inv_spatial_metric)[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } } -void -gkyl_gr_twofluid_tetrad_stress_energy_tensor_elc(double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_elc) +void gkyl_gr_twofluid_tetrad_stress_energy_tensor_elc( + double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_elc +) { - double v[84] = { 0.0 }; + double v[84] = {0.0}; gkyl_gr_twofluid_tetrad_prim_vars(gas_gamma_elc, gas_gamma_ion, q, v); double rho_elc = v[0]; double vx_elc = v[1]; @@ -518,11 +685,17 @@ gkyl_gr_twofluid_tetrad_stress_energy_tensor_elc(double gas_gamma_elc, double ga double shift_z = v[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[22]; spatial_metric[0][1] = v[23]; spatial_metric[0][2] = v[24]; - spatial_metric[1][0] = v[25]; spatial_metric[1][1] = v[26]; spatial_metric[1][2] = v[27]; - spatial_metric[2][0] = v[28]; spatial_metric[2][1] = v[29]; spatial_metric[2][2] = v[30]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[22]; + spatial_metric[0][1] = v[23]; + spatial_metric[0][2] = v[24]; + spatial_metric[1][0] = v[25]; + spatial_metric[1][1] = v[26]; + spatial_metric[1][2] = v[27]; + spatial_metric[2][0] = v[28]; + spatial_metric[2][1] = v[29]; + spatial_metric[2][2] = v[30]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -537,7 +710,9 @@ gkyl_gr_twofluid_tetrad_stress_energy_tensor_elc(double gas_gamma_elc, double ga if (!in_excision_region) { double vel_elc[3]; double v_sq_elc = 0.0; - vel_elc[0] = vx_elc; vel_elc[1] = vy_elc; vel_elc[2] = vz_elc; + vel_elc[0] = vx_elc; + vel_elc[1] = vy_elc; + vel_elc[2] = vz_elc; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -559,27 +734,31 @@ gkyl_gr_twofluid_tetrad_stress_energy_tensor_elc(double gas_gamma_elc, double ga spacetime_vel_elc[3] = (W_elc * vz_elc) - (shift_z * (W_elc / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*stress_energy_elc)[i][j] = (rho_elc * h_elc * spacetime_vel_elc[i] * spacetime_vel_elc[j]) + (p_elc * inv_spacetime_metric[i][j]); + (*stress_energy_elc)[i][j] = + (rho_elc * h_elc * spacetime_vel_elc[i] * spacetime_vel_elc[j]) + + (p_elc * inv_spacetime_metric[i][j]); } } - } - else { + } else { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { (*stress_energy_elc)[i][j] = 0.0; @@ -593,10 +772,11 @@ gkyl_gr_twofluid_tetrad_stress_energy_tensor_elc(double gas_gamma_elc, double ga gkyl_free(inv_spatial_metric); } -void -gkyl_gr_twofluid_tetrad_stress_energy_tensor_ion(double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_ion) +void gkyl_gr_twofluid_tetrad_stress_energy_tensor_ion( + double gas_gamma_elc, double gas_gamma_ion, const double q[84], double ***stress_energy_ion +) { - double v[84] = { 0.0 }; + double v[84] = {0.0}; gkyl_gr_twofluid_tetrad_prim_vars(gas_gamma_elc, gas_gamma_ion, q, v); double rho_ion = v[5]; double vx_ion = v[6]; @@ -610,11 +790,17 @@ gkyl_gr_twofluid_tetrad_stress_energy_tensor_ion(double gas_gamma_elc, double ga double shift_z = v[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[22]; spatial_metric[0][1] = v[23]; spatial_metric[0][2] = v[24]; - spatial_metric[1][0] = v[25]; spatial_metric[1][1] = v[26]; spatial_metric[1][2] = v[27]; - spatial_metric[2][0] = v[28]; spatial_metric[2][1] = v[29]; spatial_metric[2][2] = v[30]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[22]; + spatial_metric[0][1] = v[23]; + spatial_metric[0][2] = v[24]; + spatial_metric[1][0] = v[25]; + spatial_metric[1][1] = v[26]; + spatial_metric[1][2] = v[27]; + spatial_metric[2][0] = v[28]; + spatial_metric[2][1] = v[29]; + spatial_metric[2][2] = v[30]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -629,7 +815,9 @@ gkyl_gr_twofluid_tetrad_stress_energy_tensor_ion(double gas_gamma_elc, double ga if (!in_excision_region) { double vel_ion[3]; double v_sq_ion = 0.0; - vel_ion[0] = vx_ion; vel_ion[1] = vy_ion; vel_ion[2] = vz_ion; + vel_ion[0] = vx_ion; + vel_ion[1] = vy_ion; + vel_ion[2] = vz_ion; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -651,27 +839,31 @@ gkyl_gr_twofluid_tetrad_stress_energy_tensor_ion(double gas_gamma_elc, double ga spacetime_vel_ion[3] = (W_ion * vz_ion) - (shift_z * (W_ion / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*stress_energy_ion)[i][j] = (rho_ion * h_ion * spacetime_vel_ion[i] * spacetime_vel_ion[j]) + (p_ion * inv_spacetime_metric[i][j]); + (*stress_energy_ion)[i][j] = + (rho_ion * h_ion * spacetime_vel_ion[i] * spacetime_vel_ion[j]) + + (p_ion * inv_spacetime_metric[i][j]); } } - } - else { + } else { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { (*stress_energy_ion)[i][j] = 0.0; @@ -685,10 +877,11 @@ gkyl_gr_twofluid_tetrad_stress_energy_tensor_ion(double gas_gamma_elc, double ga gkyl_free(inv_spatial_metric); } -static inline double -gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion, double light_speed, const double q[84]) +static inline double gkyl_gr_twofluid_tetrad_max_abs_speed( + double gas_gamma_elc, double gas_gamma_ion, double light_speed, const double q[84] +) { - double v[84] = { 0.0 }; + double v[84] = {0.0}; gkyl_gr_twofluid_tetrad_prim_vars(gas_gamma_elc, gas_gamma_ion, q, v); double rho_elc = v[0]; double vx_elc = v[1]; @@ -708,15 +901,25 @@ gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion double shift_z = v[21]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[22]; spatial_metric[0][1] = v[23]; spatial_metric[0][2] = v[24]; - spatial_metric[1][0] = v[25]; spatial_metric[1][1] = v[26]; spatial_metric[1][2] = v[27]; - spatial_metric[2][0] = v[28]; spatial_metric[2][1] = v[29]; spatial_metric[2][2] = v[30]; - - double spatial_metric_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[22]; + spatial_metric[0][1] = v[23]; + spatial_metric[0][2] = v[24]; + spatial_metric[1][0] = v[25]; + spatial_metric[1][1] = v[26]; + spatial_metric[1][2] = v[27]; + spatial_metric[2][0] = v[28]; + spatial_metric[2][1] = v[29]; + spatial_metric[2][2] = v[30]; + + double spatial_metric_det = + (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -743,16 +946,15 @@ gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion if (fabs(spatial_metric[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime = true; } - } - else { + } else { if (fabs(spatial_metric[i][j]) > pow(10.0, -8.0)) { curved_spacetime = true; } } } } - if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || fabs(shift_y) > pow(10.0, -8.0) || - fabs(shift_z) > pow(10.0, -8.0)) { + if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || + fabs(shift_y) > pow(10.0, -8.0) || fabs(shift_z) > pow(10.0, -8.0)) { curved_spacetime = true; } @@ -760,8 +962,10 @@ gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion if (curved_spacetime) { double vel_elc[3]; double v_sq_elc = 0.0; - vel_elc[0] = vx_elc; vel_elc[1] = vy_elc; vel_elc[2] = vz_elc; - + vel_elc[0] = vx_elc; + vel_elc[1] = vy_elc; + vel_elc[2] = vz_elc; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_elc += spatial_metric[i][j] * vel_elc[i] * vel_elc[j]; @@ -769,7 +973,9 @@ gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double material_eigs_elc[3]; double fast_acoustic_eigs_elc[3]; @@ -778,19 +984,33 @@ gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion for (int i = 0; i < 3; i++) { material_eigs_elc[i] = (lapse * vel_elc[i]) - shift[i]; - fast_acoustic_eigs_elc[i] = (lapse / (1.0 - (v_sq_elc * (c_s_elc * c_s_elc)))) * ((vel_elc[i] * (1.0 - (c_s_elc * c_s_elc))) + - (c_s_elc * sqrt((1.0 - v_sq_elc) * (inv_spatial_metric[i][i] * (1.0 - (v_sq_elc * (c_s_elc * c_s_elc))) - - (vel_elc[i] * vel_elc[i]) * (1.0 - (c_s_elc * c_s_elc)))))) - shift[i]; - - slow_acoustic_eigs_elc[i] = (lapse / (1.0 - (v_sq_elc * (c_s_elc * c_s_elc)))) * ((vel_elc[i] * (1.0 - (c_s_elc * c_s_elc))) - - (c_s_elc * sqrt((1.0 - v_sq_elc) * (inv_spatial_metric[i][i] * (1.0 - (v_sq_elc * (c_s_elc * c_s_elc))) - - (vel_elc[i] * vel_elc[i]) * (1.0 - (c_s_elc * c_s_elc)))))) - shift[i]; + fast_acoustic_eigs_elc[i] = + (lapse / (1.0 - (v_sq_elc * (c_s_elc * c_s_elc)))) * + ((vel_elc[i] * (1.0 - (c_s_elc * c_s_elc))) + + (c_s_elc * sqrt( + (1.0 - v_sq_elc) * + (inv_spatial_metric[i][i] * (1.0 - (v_sq_elc * (c_s_elc * c_s_elc))) - + (vel_elc[i] * vel_elc[i]) * (1.0 - (c_s_elc * c_s_elc))) + ))) - + shift[i]; + + slow_acoustic_eigs_elc[i] = + (lapse / (1.0 - (v_sq_elc * (c_s_elc * c_s_elc)))) * + ((vel_elc[i] * (1.0 - (c_s_elc * c_s_elc))) - + (c_s_elc * sqrt( + (1.0 - v_sq_elc) * + (inv_spatial_metric[i][i] * (1.0 - (v_sq_elc * (c_s_elc * c_s_elc))) - + (vel_elc[i] * vel_elc[i]) * (1.0 - (c_s_elc * c_s_elc))) + ))) - + shift[i]; } double vel_ion[3]; double v_sq_ion = 0.0; - vel_ion[0] = vx_ion; vel_ion[1] = vy_ion; vel_ion[2] = vz_ion; - + vel_ion[0] = vx_ion; + vel_ion[1] = vy_ion; + vel_ion[2] = vz_ion; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_ion += spatial_metric[i][j] * vel_ion[i] * vel_ion[j]; @@ -804,13 +1024,25 @@ gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion for (int i = 0; i < 3; i++) { material_eigs_ion[i] = (lapse * vel_ion[i]) - shift[i]; - fast_acoustic_eigs_ion[i] = (lapse / (1.0 - (v_sq_ion * (c_s_ion * c_s_ion)))) * ((vel_ion[i] * (1.0 - (c_s_ion * c_s_ion))) + - (c_s_ion * sqrt((1.0 - v_sq_ion) * (inv_spatial_metric[i][i] * (1.0 - (v_sq_ion * (c_s_ion * c_s_ion))) - - (vel_ion[i] * vel_ion[i]) * (1.0 - (c_s_ion * c_s_ion)))))) - shift[i]; - - slow_acoustic_eigs_ion[i] = (lapse / (1.0 - (v_sq_ion * (c_s_ion * c_s_ion)))) * ((vel_ion[i] * (1.0 - (c_s_ion * c_s_ion))) - - (c_s_ion * sqrt((1.0 - v_sq_ion) * (inv_spatial_metric[i][i] * (1.0 - (v_sq_ion * (c_s_ion * c_s_ion))) - - (vel_ion[i] * vel_ion[i]) * (1.0 - (c_s_ion * c_s_ion)))))) - shift[i]; + fast_acoustic_eigs_ion[i] = + (lapse / (1.0 - (v_sq_ion * (c_s_ion * c_s_ion)))) * + ((vel_ion[i] * (1.0 - (c_s_ion * c_s_ion))) + + (c_s_ion * sqrt( + (1.0 - v_sq_ion) * + (inv_spatial_metric[i][i] * (1.0 - (v_sq_ion * (c_s_ion * c_s_ion))) - + (vel_ion[i] * vel_ion[i]) * (1.0 - (c_s_ion * c_s_ion))) + ))) - + shift[i]; + + slow_acoustic_eigs_ion[i] = + (lapse / (1.0 - (v_sq_ion * (c_s_ion * c_s_ion)))) * + ((vel_ion[i] * (1.0 - (c_s_ion * c_s_ion))) - + (c_s_ion * sqrt( + (1.0 - v_sq_ion) * + (inv_spatial_metric[i][i] * (1.0 - (v_sq_ion * (c_s_ion * c_s_ion))) - + (vel_ion[i] * vel_ion[i]) * (1.0 - (c_s_ion * c_s_ion))) + ))) - + shift[i]; } double max_eig = 0.0; @@ -844,35 +1076,30 @@ gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion double v_sq = 0.0; if (v_sq_elc > v_sq_ion) { v_sq = v_sq_elc; - } - else { + } else { v_sq = v_sq_ion; } if (fabs(v_sq) + max_eig > light_speed * sqrt(spatial_metric_det) * lapse) { return fabs(v_sq) + max_eig; - } - else { + } else { return light_speed * sqrt(spatial_metric_det) * lapse; } - } - else { + } else { double v_sq_elc = sqrt((vx_elc * vx_elc) + (vy_elc * vy_elc) + (vz_elc * vz_elc)); double v_sq_ion = sqrt((vx_ion * vx_ion) + (vy_ion * vy_ion) + (vz_ion * vz_ion)); double v_sq = 0.0; if (v_sq_elc > v_sq_ion) { v_sq = v_sq_elc; - } - else { + } else { v_sq = v_sq_ion; } double c_s = 0.0; if (c_s_elc > c_s_ion) { c_s = c_s_elc; - } - else { + } else { c_s = c_s_ion; } @@ -883,13 +1110,11 @@ gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion if (fabs(v_sq) + c_s > light_speed * sqrt(spatial_metric_det) * lapse) { return fabs(v_sq) + c_s; - } - else { + } else { return light_speed * sqrt(spatial_metric_det) * lapse; } } - } - else { + } else { for (int i = 0; i < 3; i++) { gkyl_free(inv_spatial_metric[i]); } @@ -900,7 +1125,7 @@ gkyl_gr_twofluid_tetrad_max_abs_speed(double gas_gamma_elc, double gas_gamma_ion } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 84; i++) { @@ -909,7 +1134,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 84; i++) { @@ -917,8 +1142,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -gr_twofluid_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_twofluid_tetrad_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 0; i < 84; i++) { ghost[i] = skin[i]; @@ -928,8 +1155,10 @@ gr_twofluid_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const d ghost[6] = -ghost[6]; } -static void -gr_twofluid_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_twofluid_tetrad_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 1; i < 4; i++) { ghost[i] = -skin[i]; @@ -950,9 +1179,10 @@ gr_twofluid_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, cons } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; qlocal[1] = (qglobal[1] * norm[0]) + (qglobal[2] * norm[1]) + (qglobal[3] * norm[2]); @@ -1011,9 +1241,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinate frame. - qlocal[22] = v1[0]; qlocal[23] = v1[1]; qlocal[24] = v1[2]; - qlocal[25] = v2[0]; qlocal[26] = v2[1]; qlocal[27] = v2[2]; - qlocal[28] = v3[0]; qlocal[29] = v3[1]; qlocal[30] = v3[2]; + qlocal[22] = v1[0]; + qlocal[23] = v1[1]; + qlocal[24] = v1[2]; + qlocal[25] = v2[0]; + qlocal[26] = v2[1]; + qlocal[27] = v2[2]; + qlocal[28] = v3[0]; + qlocal[29] = v3[1]; + qlocal[30] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -1044,9 +1280,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta inv_v3[2] = (extr_r1[2] * tau2[0]) + (extr_r2[2] * tau2[1]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor to local coordinate frame. - qlocal[31] = inv_v1[0]; qlocal[32] = inv_v1[1]; qlocal[33] = inv_v1[2]; - qlocal[34] = inv_v2[0]; qlocal[35] = inv_v2[1]; qlocal[36] = inv_v2[2]; - qlocal[37] = inv_v3[0]; qlocal[38] = inv_v3[1]; qlocal[39] = inv_v3[2]; + qlocal[31] = inv_v1[0]; + qlocal[32] = inv_v1[1]; + qlocal[33] = inv_v1[2]; + qlocal[34] = inv_v2[0]; + qlocal[35] = inv_v2[1]; + qlocal[36] = inv_v2[2]; + qlocal[37] = inv_v3[0]; + qlocal[38] = inv_v3[1]; + qlocal[39] = inv_v3[2]; qlocal[40] = qglobal[40]; @@ -1070,22 +1312,37 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); - shiftder_v1[1] = (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); - shiftder_v1[2] = (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); - shiftder_v2[1] = (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); - shiftder_v2[2] = (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); - shiftder_v3[1] = (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); - shiftder_v3[2] = (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); + shiftder_v1[1] = + (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); + shiftder_v1[2] = + (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); + shiftder_v2[1] = + (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); + shiftder_v2[2] = + (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); + shiftder_v3[1] = + (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); + shiftder_v3[2] = + (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative to local coordinate frame. - qlocal[44] = shiftder_v1[0]; qlocal[45] = shiftder_v1[1]; qlocal[46] = shiftder_v1[2]; - qlocal[47] = shiftder_v2[0]; qlocal[48] = shiftder_v2[1]; qlocal[49] = shiftder_v2[2]; - qlocal[50] = shiftder_v3[0]; qlocal[51] = shiftder_v3[1]; qlocal[52] = shiftder_v3[2]; + qlocal[44] = shiftder_v1[0]; + qlocal[45] = shiftder_v1[1]; + qlocal[46] = shiftder_v1[2]; + qlocal[47] = shiftder_v2[0]; + qlocal[48] = shiftder_v2[1]; + qlocal[49] = shiftder_v2[2]; + qlocal[50] = shiftder_v3[0]; + qlocal[51] = shiftder_v3[1]; + qlocal[52] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -1168,7 +1425,7 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta s33[0] = (r31[0] * tau2[0]) + (r32[0] * tau2[1]) + (r33[0] * tau2[2]); s33[1] = (r31[1] * tau2[0]) + (r32[1] * tau2[1]) + (r33[1] * tau2[2]); s33[2] = (r31[2] * tau2[0]) + (r32[2] * tau2[1]) + (r33[2] * tau2[2]); - + // Rotate spatial metric tensor derivative to local coordinate frame. qlocal[53] = (s11[0] * norm[0]) + (s21[0] * norm[1]) + (s31[0] * norm[2]); qlocal[54] = (s11[1] * norm[0]) + (s21[1] * norm[1]) + (s31[1] * norm[2]); @@ -1212,9 +1469,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[83] = (qglobal[81] * tau2[0]) + (qglobal[82] * tau2[1]) + (qglobal[83] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; qglobal[1] = (qlocal[1] * norm[0]) + (qlocal[2] * tau1[0]) + (qlocal[3] * tau2[0]); @@ -1273,9 +1531,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor back to global coordinate frame. - qglobal[22] = v1[0]; qglobal[23] = v1[1]; qglobal[24] = v1[2]; - qglobal[25] = v2[0]; qglobal[26] = v2[1]; qglobal[27] = v2[2]; - qglobal[28] = v3[0]; qglobal[29] = v3[1]; qglobal[30] = v3[2]; + qglobal[22] = v1[0]; + qglobal[23] = v1[1]; + qglobal[24] = v1[2]; + qglobal[25] = v2[0]; + qglobal[26] = v2[1]; + qglobal[27] = v2[2]; + qglobal[28] = v3[0]; + qglobal[29] = v3[1]; + qglobal[30] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -1306,9 +1570,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t inv_v3[2] = (extr_r1[2] * norm[2]) + (extr_r2[2] * tau1[2]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor back to global coordinate frame. - qglobal[31] = inv_v1[0]; qglobal[32] = inv_v1[1]; qglobal[33] = inv_v1[2]; - qglobal[34] = inv_v2[0]; qglobal[35] = inv_v2[1]; qglobal[36] = inv_v2[2]; - qglobal[37] = inv_v3[0]; qglobal[38] = inv_v3[1]; qglobal[39] = inv_v3[2]; + qglobal[31] = inv_v1[0]; + qglobal[32] = inv_v1[1]; + qglobal[33] = inv_v1[2]; + qglobal[34] = inv_v2[0]; + qglobal[35] = inv_v2[1]; + qglobal[36] = inv_v2[2]; + qglobal[37] = inv_v3[0]; + qglobal[38] = inv_v3[1]; + qglobal[39] = inv_v3[2]; qglobal[40] = qlocal[40]; @@ -1332,22 +1602,37 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); - shiftder_v1[1] = (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); - shiftder_v1[2] = (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); - shiftder_v2[1] = (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); - shiftder_v2[2] = (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); - shiftder_v3[1] = (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); - shiftder_v3[2] = (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); + shiftder_v1[1] = + (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); + shiftder_v1[2] = + (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); + shiftder_v2[1] = + (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); + shiftder_v2[2] = + (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); + shiftder_v3[1] = + (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); + shiftder_v3[2] = + (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative back to global coordinate frame. - qglobal[44] = shiftder_v1[0]; qglobal[45] = shiftder_v1[1]; qglobal[46] = shiftder_v1[2]; - qglobal[47] = shiftder_v2[0]; qglobal[48] = shiftder_v2[1]; qglobal[49] = shiftder_v2[2]; - qglobal[50] = shiftder_v3[0]; qglobal[51] = shiftder_v3[1]; qglobal[52] = shiftder_v3[2]; + qglobal[44] = shiftder_v1[0]; + qglobal[45] = shiftder_v1[1]; + qglobal[46] = shiftder_v1[2]; + qglobal[47] = shiftder_v2[0]; + qglobal[48] = shiftder_v2[1]; + qglobal[49] = shiftder_v2[2]; + qglobal[50] = shiftder_v3[0]; + qglobal[51] = shiftder_v3[1]; + qglobal[52] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -1474,10 +1759,13 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[83] = (qlocal[81] * norm[2]) + (qlocal[82] * tau1[2]) + (qlocal[83] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double gas_gamma_elc = gr_twofluid_tetrad->gas_gamma_elc; double gas_gamma_ion = gr_twofluid_tetrad->gas_gamma_ion; double light_speed = gr_twofluid_tetrad->light_speed; @@ -1493,8 +1781,12 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr, fr_sr); double fl_gr[84], fr_gr[84]; - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql, fl_sr, fl_gr); - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr, fr_sr, fr_gr); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql, fl_sr, fl_gr + ); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr, fr_sr, fr_gr + ); bool in_excision_region_l = false; if (ql[40] < pow(10.0, -8.0)) { @@ -1512,8 +1804,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr_gr[i] - fl_gr[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr_gr[i] - fl_gr[i]) / amax); } - } - else { + } else { for (int i = 0; i < 84; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1526,8 +1817,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[84]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1539,23 +1832,30 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double gas_gamma_elc = gr_twofluid_tetrad->gas_gamma_elc; double gas_gamma_ion = gr_twofluid_tetrad->gas_gamma_ion; double light_speed = gr_twofluid_tetrad->light_speed; @@ -1584,15 +1884,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_z_l = vl[21]; double spatial_metric_l[3][3]; - spatial_metric_l[0][0] = vl[22]; spatial_metric_l[0][1] = vl[23]; spatial_metric_l[0][2] = vl[24]; - spatial_metric_l[1][0] = vl[25]; spatial_metric_l[1][1] = vl[26]; spatial_metric_l[1][2] = vl[27]; - spatial_metric_l[2][0] = vl[28]; spatial_metric_l[2][1] = vl[29]; spatial_metric_l[2][2] = vl[30]; - - double spatial_metric_det_l = (spatial_metric_l[0][0] * ((spatial_metric_l[1][1] * spatial_metric_l[2][2]) - (spatial_metric_l[2][1] * spatial_metric_l[1][2]))) - - (spatial_metric_l[0][1] * ((spatial_metric_l[1][0] * spatial_metric_l[2][2]) - (spatial_metric_l[1][2] * spatial_metric_l[2][0]))) + - (spatial_metric_l[0][2] * ((spatial_metric_l[1][0] * spatial_metric_l[2][1]) - (spatial_metric_l[1][1] * spatial_metric_l[2][0]))); - - double **inv_spatial_metric_l= gkyl_malloc(sizeof(double*[3])); + spatial_metric_l[0][0] = vl[22]; + spatial_metric_l[0][1] = vl[23]; + spatial_metric_l[0][2] = vl[24]; + spatial_metric_l[1][0] = vl[25]; + spatial_metric_l[1][1] = vl[26]; + spatial_metric_l[1][2] = vl[27]; + spatial_metric_l[2][0] = vl[28]; + spatial_metric_l[2][1] = vl[29]; + spatial_metric_l[2][2] = vl[30]; + + double spatial_metric_det_l = + (spatial_metric_l[0][0] * ((spatial_metric_l[1][1] * spatial_metric_l[2][2]) - + (spatial_metric_l[2][1] * spatial_metric_l[1][2]))) - + (spatial_metric_l[0][1] * ((spatial_metric_l[1][0] * spatial_metric_l[2][2]) - + (spatial_metric_l[1][2] * spatial_metric_l[2][0]))) + + (spatial_metric_l[0][2] * ((spatial_metric_l[1][0] * spatial_metric_l[2][1]) - + (spatial_metric_l[1][1] * spatial_metric_l[2][0]))); + + double **inv_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); } @@ -1611,16 +1921,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_l[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_l = true; } - } - else { + } else { if (fabs(spatial_metric_l[i][j]) > pow(10.0, -8.0)) { curved_spacetime_l = true; } } } } - if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_x_l) > pow(10.0, -8.0) || fabs(shift_y_l) > pow(10.0, -8.0) || - fabs(shift_z_l) > pow(10.0, -8.0)) { + if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_x_l) > pow(10.0, -8.0) || + fabs(shift_y_l) > pow(10.0, -8.0) || fabs(shift_z_l) > pow(10.0, -8.0)) { curved_spacetime_l = true; } @@ -1642,15 +1951,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_z_r = vr[21]; double spatial_metric_r[3][3]; - spatial_metric_r[0][0] = vr[22]; spatial_metric_r[0][1] = vr[23]; spatial_metric_r[0][2] = vr[24]; - spatial_metric_r[1][0] = vr[25]; spatial_metric_r[1][1] = vr[26]; spatial_metric_r[1][2] = vr[27]; - spatial_metric_r[2][0] = vr[28]; spatial_metric_r[2][1] = vr[29]; spatial_metric_r[2][2] = vr[30]; - - double spatial_metric_det_r = (spatial_metric_r[0][0] * ((spatial_metric_r[1][1] * spatial_metric_r[2][2]) - (spatial_metric_r[2][1] * spatial_metric_r[1][2]))) - - (spatial_metric_r[0][1] * ((spatial_metric_r[1][0] * spatial_metric_r[2][2]) - (spatial_metric_r[1][2] * spatial_metric_r[2][0]))) + - (spatial_metric_r[0][2] * ((spatial_metric_r[1][0] * spatial_metric_r[2][1]) - (spatial_metric_r[1][1] * spatial_metric_r[2][0]))); - - double **inv_spatial_metric_r= gkyl_malloc(sizeof(double*[3])); + spatial_metric_r[0][0] = vr[22]; + spatial_metric_r[0][1] = vr[23]; + spatial_metric_r[0][2] = vr[24]; + spatial_metric_r[1][0] = vr[25]; + spatial_metric_r[1][1] = vr[26]; + spatial_metric_r[1][2] = vr[27]; + spatial_metric_r[2][0] = vr[28]; + spatial_metric_r[2][1] = vr[29]; + spatial_metric_r[2][2] = vr[30]; + + double spatial_metric_det_r = + (spatial_metric_r[0][0] * ((spatial_metric_r[1][1] * spatial_metric_r[2][2]) - + (spatial_metric_r[2][1] * spatial_metric_r[1][2]))) - + (spatial_metric_r[0][1] * ((spatial_metric_r[1][0] * spatial_metric_r[2][2]) - + (spatial_metric_r[1][2] * spatial_metric_r[2][0]))) + + (spatial_metric_r[0][2] * ((spatial_metric_r[1][0] * spatial_metric_r[2][1]) - + (spatial_metric_r[1][1] * spatial_metric_r[2][0]))); + + double **inv_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } @@ -1669,16 +1988,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_r[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_r = true; } - } - else { + } else { if (fabs(spatial_metric_r[i][j]) > pow(10.0, -8.0)) { curved_spacetime_r = true; } } } } - if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_x_r) > pow(10.0, -8.0) || fabs(shift_y_r) > pow(10.0, -8.0) || - fabs(shift_z_r) > pow(10.0, -8.0)) { + if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_x_r) > pow(10.0, -8.0) || + fabs(shift_y_r) > pow(10.0, -8.0) || fabs(shift_z_r) > pow(10.0, -8.0)) { curved_spacetime_r = true; } @@ -1711,8 +2029,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (curved_spacetime_l || curved_spacetime_r) { double vel_elc_l[3]; double v_sq_elc_l = 0.0; - vel_elc_l[0] = vx_elc_l; vel_elc_l[1] = vy_elc_l; vel_elc_l[2] = vz_elc_l; - + vel_elc_l[0] = vx_elc_l; + vel_elc_l[1] = vy_elc_l; + vel_elc_l[2] = vz_elc_l; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_elc_l += spatial_metric_l[i][j] * vel_elc_l[i] * vel_elc_l[j]; @@ -1720,7 +2040,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_l[3]; - shift_l[0] = shift_x_l; shift_l[1] = shift_y_l; shift_l[2] = shift_z_l; + shift_l[0] = shift_x_l; + shift_l[1] = shift_y_l; + shift_l[2] = shift_z_l; double material_eigs_elc_l[3]; double fast_acoustic_eigs_elc_l[3]; @@ -1729,13 +2051,27 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_elc_l[i] = (lapse_l * vel_elc_l[i]) - shift_l[i]; - fast_acoustic_eigs_elc_l[i] = (lapse_l / (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l)))) * ((vel_elc_l[i] * (1.0 - (c_s_elc_l * c_s_elc_l))) + - (c_s_elc_l * sqrt((1.0 - v_sq_elc_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l))) - - (vel_elc_l[i] * vel_elc_l[i]) * (1.0 - (c_s_elc_l * c_s_elc_l)))))) - shift_l[i]; - - slow_acoustic_eigs_elc_l[i] = (lapse_l / (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l)))) * ((vel_elc_l[i] * (1.0 - (c_s_elc_l * c_s_elc_l))) - - (c_s_elc_l * sqrt((1.0 - v_sq_elc_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l))) - - (vel_elc_l[i] * vel_elc_l[i]) * (1.0 - (c_s_elc_l * c_s_elc_l)))))) - shift_l[i]; + fast_acoustic_eigs_elc_l[i] = + (lapse_l / (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l)))) * + ((vel_elc_l[i] * (1.0 - (c_s_elc_l * c_s_elc_l))) + + (c_s_elc_l * + sqrt( + (1.0 - v_sq_elc_l) * + (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l))) - + (vel_elc_l[i] * vel_elc_l[i]) * (1.0 - (c_s_elc_l * c_s_elc_l))) + ))) - + shift_l[i]; + + slow_acoustic_eigs_elc_l[i] = + (lapse_l / (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l)))) * + ((vel_elc_l[i] * (1.0 - (c_s_elc_l * c_s_elc_l))) - + (c_s_elc_l * + sqrt( + (1.0 - v_sq_elc_l) * + (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_elc_l * (c_s_elc_l * c_s_elc_l))) - + (vel_elc_l[i] * vel_elc_l[i]) * (1.0 - (c_s_elc_l * c_s_elc_l))) + ))) - + shift_l[i]; } double max_eig_elc_l = 0.0; @@ -1753,8 +2089,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_elc_r[3]; double v_sq_elc_r = 0.0; - vel_elc_r[0] = vx_elc_r; vel_elc_r[1] = vy_elc_r; vel_elc_r[2] = vz_elc_r; - + vel_elc_r[0] = vx_elc_r; + vel_elc_r[1] = vy_elc_r; + vel_elc_r[2] = vz_elc_r; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_elc_r += spatial_metric_r[i][j] * vel_elc_r[i] * vel_elc_r[j]; @@ -1762,7 +2100,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_r[3]; - shift_r[0] = shift_x_r; shift_r[1] = shift_y_r; shift_r[2] = shift_z_r; + shift_r[0] = shift_x_r; + shift_r[1] = shift_y_r; + shift_r[2] = shift_z_r; double material_eigs_elc_r[3]; double fast_acoustic_eigs_elc_r[3]; @@ -1771,13 +2111,27 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_elc_r[i] = (lapse_r * vel_elc_r[i]) - shift_r[i]; - fast_acoustic_eigs_elc_r[i] = (lapse_r / (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r)))) * ((vel_elc_r[i] * (1.0 - (c_s_elc_r * c_s_elc_r))) + - (c_s_elc_r * sqrt((1.0 - v_sq_elc_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r))) - - (vel_elc_r[i] * vel_elc_r[i]) * (1.0 - (c_s_elc_r * c_s_elc_r)))))) - shift_r[i]; - - slow_acoustic_eigs_elc_r[i] = (lapse_r / (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r)))) * ((vel_elc_r[i] * (1.0 - (c_s_elc_r * c_s_elc_r))) - - (c_s_elc_r * sqrt((1.0 - v_sq_elc_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r))) - - (vel_elc_r[i] * vel_elc_r[i]) * (1.0 - (c_s_elc_r * c_s_elc_r)))))) - shift_r[i]; + fast_acoustic_eigs_elc_r[i] = + (lapse_r / (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r)))) * + ((vel_elc_r[i] * (1.0 - (c_s_elc_r * c_s_elc_r))) + + (c_s_elc_r * + sqrt( + (1.0 - v_sq_elc_r) * + (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r))) - + (vel_elc_r[i] * vel_elc_r[i]) * (1.0 - (c_s_elc_r * c_s_elc_r))) + ))) - + shift_r[i]; + + slow_acoustic_eigs_elc_r[i] = + (lapse_r / (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r)))) * + ((vel_elc_r[i] * (1.0 - (c_s_elc_r * c_s_elc_r))) - + (c_s_elc_r * + sqrt( + (1.0 - v_sq_elc_r) * + (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_elc_r * (c_s_elc_r * c_s_elc_r))) - + (vel_elc_r[i] * vel_elc_r[i]) * (1.0 - (c_s_elc_r * c_s_elc_r))) + ))) - + shift_r[i]; } double max_eig_elc_r = 0.0; @@ -1800,8 +2154,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_ion_l[3]; double v_sq_ion_l = 0.0; - vel_ion_l[0] = vx_ion_l; vel_ion_l[1] = vy_ion_l; vel_ion_l[2] = vz_ion_l; - + vel_ion_l[0] = vx_ion_l; + vel_ion_l[1] = vy_ion_l; + vel_ion_l[2] = vz_ion_l; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_ion_l += spatial_metric_l[i][j] * vel_ion_l[i] * vel_ion_l[j]; @@ -1815,13 +2171,27 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_ion_l[i] = (lapse_l * vel_ion_l[i]) - shift_l[i]; - fast_acoustic_eigs_ion_l[i] = (lapse_l / (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l)))) * ((vel_ion_l[i] * (1.0 - (c_s_ion_l * c_s_ion_l))) + - (c_s_ion_l * sqrt((1.0 - v_sq_ion_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l))) - - (vel_ion_l[i] * vel_ion_l[i]) * (1.0 - (c_s_ion_l * c_s_ion_l)))))) - shift_l[i]; - - slow_acoustic_eigs_ion_l[i] = (lapse_l / (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l)))) * ((vel_ion_l[i] * (1.0 - (c_s_ion_l * c_s_ion_l))) - - (c_s_ion_l * sqrt((1.0 - v_sq_ion_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l))) - - (vel_ion_l[i] * vel_ion_l[i]) * (1.0 - (c_s_ion_l * c_s_ion_l)))))) - shift_l[i]; + fast_acoustic_eigs_ion_l[i] = + (lapse_l / (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l)))) * + ((vel_ion_l[i] * (1.0 - (c_s_ion_l * c_s_ion_l))) + + (c_s_ion_l * + sqrt( + (1.0 - v_sq_ion_l) * + (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l))) - + (vel_ion_l[i] * vel_ion_l[i]) * (1.0 - (c_s_ion_l * c_s_ion_l))) + ))) - + shift_l[i]; + + slow_acoustic_eigs_ion_l[i] = + (lapse_l / (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l)))) * + ((vel_ion_l[i] * (1.0 - (c_s_ion_l * c_s_ion_l))) - + (c_s_ion_l * + sqrt( + (1.0 - v_sq_ion_l) * + (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_ion_l * (c_s_ion_l * c_s_ion_l))) - + (vel_ion_l[i] * vel_ion_l[i]) * (1.0 - (c_s_ion_l * c_s_ion_l))) + ))) - + shift_l[i]; } double max_eig_ion_l = 0.0; @@ -1839,8 +2209,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_ion_r[3]; double v_sq_ion_r = 0.0; - vel_ion_r[0] = vx_ion_r; vel_ion_r[1] = vy_ion_r; vel_ion_r[2] = vz_ion_r; - + vel_ion_r[0] = vx_ion_r; + vel_ion_r[1] = vy_ion_r; + vel_ion_r[2] = vz_ion_r; + for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { v_sq_ion_r += spatial_metric_r[i][j] * vel_ion_r[i] * vel_ion_r[j]; @@ -1854,13 +2226,27 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_ion_r[i] = (lapse_r * vel_ion_r[i]) - shift_r[i]; - fast_acoustic_eigs_ion_r[i] = (lapse_r / (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r)))) * ((vel_ion_r[i] * (1.0 - (c_s_ion_r * c_s_ion_r))) + - (c_s_ion_r * sqrt((1.0 - v_sq_ion_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r))) - - (vel_ion_r[i] * vel_ion_r[i]) * (1.0 - (c_s_ion_r * c_s_ion_r)))))) - shift_r[i]; - - slow_acoustic_eigs_ion_r[i] = (lapse_r / (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r)))) * ((vel_ion_r[i] * (1.0 - (c_s_ion_r * c_s_ion_r))) - - (c_s_ion_r * sqrt((1.0 - v_sq_ion_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r))) - - (vel_ion_r[i] * vel_ion_r[i]) * (1.0 - (c_s_ion_r * c_s_ion_r)))))) - shift_r[i]; + fast_acoustic_eigs_ion_r[i] = + (lapse_r / (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r)))) * + ((vel_ion_r[i] * (1.0 - (c_s_ion_r * c_s_ion_r))) + + (c_s_ion_r * + sqrt( + (1.0 - v_sq_ion_r) * + (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r))) - + (vel_ion_r[i] * vel_ion_r[i]) * (1.0 - (c_s_ion_r * c_s_ion_r))) + ))) - + shift_r[i]; + + slow_acoustic_eigs_ion_r[i] = + (lapse_r / (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r)))) * + ((vel_ion_r[i] * (1.0 - (c_s_ion_r * c_s_ion_r))) - + (c_s_ion_r * + sqrt( + (1.0 - v_sq_ion_r) * + (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_ion_r * (c_s_ion_r * c_s_ion_r))) - + (vel_ion_r[i] * vel_ion_r[i]) * (1.0 - (c_s_ion_r * c_s_ion_r))) + ))) - + shift_r[i]; } double max_eig_ion_r = 0.0; @@ -1883,8 +2269,7 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c sl_em = -light_speed * sqrt(spatial_metric_det_l) * lapse_l; sr_em = light_speed * sqrt(spatial_metric_det_r) * lapse_r; - } - else { + } else { sl_elc = (vx_avg_elc - cs_avg_elc) / (1.0 - (vx_avg_elc * cs_avg_elc)); sr_elc = (vx_avg_elc + cs_avg_elc) / (1.0 + (vx_avg_elc * cs_avg_elc)); @@ -1900,8 +2285,12 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr, fr_sr); double fl_gr[84], fr_gr[84]; - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql, fl_sr, fl_gr); - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr, fr_sr, fr_gr); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql, fl_sr, fl_gr + ); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr, fr_sr, fr_gr + ); double qm[84]; for (int i = 0; i < 5; i++) { @@ -1914,7 +2303,8 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c qm[i] = ((sr_em * qr[i]) - (sl_em * ql[i]) + (fl_gr[i] - fr_gr[i])) / (sr_em - sl_em); } - double *w0 = &waves[0 * 84], *w1 = &waves[1 * 84], *w2 = &waves[2 * 84], *w3 = &waves[3 * 84], *w4 = &waves[4 * 84], *w5 = &waves[5 * 84]; + double *w0 = &waves[0 * 84], *w1 = &waves[1 * 84], *w2 = &waves[2 * 84], *w3 = &waves[3 * 84], + *w4 = &waves[4 * 84], *w5 = &waves[5 * 84]; for (int i = 0; i < 84; i++) { w0[i] = 0.0; @@ -1956,51 +2346,64 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c gkyl_free(inv_spatial_metric_l); gkyl_free(inv_spatial_metric_r); - return fmax(fmax(fmax(fabs(sl_elc), fabs(sr_elc)), fmax(fabs(sl_ion), fabs(sr_ion))), fmax(fabs(sl_em), fabs(sr_em))); + return fmax( + fmax(fmax(fabs(sl_elc), fabs(sr_elc)), fmax(fabs(sl_ion), fabs(sr_ion))), + fmax(fabs(sl_em), fabs(sr_em)) + ); } -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { - const double *w0 = &waves[0 * 84], *w1 = &waves[1 * 84], *w2 = &waves[2 * 84], *w3 = &waves[3 * 84], *w4 = &waves[4 * 84], *w5 = &waves[5 * 84]; - double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]), s3m = fmin(0.0, s[3]), s4m = fmin(0.0, s[4]), s5m = fmin(0.0, s[5]); - double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]), s3p = fmax(0.0, s[3]), s4p = fmax(0.0, s[4]), s5p = fmax(0.0, s[5]); + const double *w0 = &waves[0 * 84], *w1 = &waves[1 * 84], *w2 = &waves[2 * 84], + *w3 = &waves[3 * 84], *w4 = &waves[4 * 84], *w5 = &waves[5 * 84]; + double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]), s3m = fmin(0.0, s[3]), + s4m = fmin(0.0, s[4]), s5m = fmin(0.0, s[5]); + double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]), s3p = fmax(0.0, s[3]), + s4p = fmax(0.0, s[4]), s5p = fmax(0.0, s[5]); for (int i = 0; i < 84; i++) { - amdq[i] = (s0m * w0[i]) + (s1m * w1[i]) + (s2m * w2[i]) + (s3m * w3[i]) + (s4m * w4[i]) + (s5m * w5[i]); - apdq[i] = (s0p * w0[i]) + (s1p * w1[i]) + (s2p * w2[i]) + (s3p * w3[i]) + (s4p * w4[i]) + (s5p * w5[i]); + amdq[i] = + (s0m * w0[i]) + (s1m * w1[i]) + (s2m * w2[i]) + (s3m * w3[i]) + (s4m * w4[i]) + (s5m * w5[i]); + apdq[i] = + (s0p * w0[i]) + (s1p * w1[i]) + (s2p * w2[i]) + (s3p * w3[i]) + (s4p * w4[i]) + (s5p * w5[i]); } } -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hll(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_hll(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double gas_gamma_elc = gr_twofluid_tetrad->gas_gamma_elc; double gas_gamma_ion = gr_twofluid_tetrad->gas_gamma_ion; double light_speed = gr_twofluid_tetrad->light_speed; @@ -2012,8 +2415,12 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou gkyl_gr_twofluid_tetrad_flux(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr, fr_sr); double fr_gr[84], fl_gr[84]; - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql, fl_sr, fl_gr); - gkyl_gr_twofluid_tetrad_flux_correction(gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr, fr_sr, fr_gr); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, ql, fl_sr, fl_gr + ); + gkyl_gr_twofluid_tetrad_flux_correction( + gas_gamma_elc, gas_gamma_ion, light_speed, e_fact, b_fact, qr, fr_sr, fr_gr + ); bool in_excision_region_l = false; if (ql[40] < pow(10.0, -8.0)) { @@ -2029,41 +2436,41 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 84; m++) { flux_jump[m] = fr_gr[m] - fl_gr[m]; } - } - else { + } else { for (int m = 0; m < 84; m++) { flux_jump[m] = 0.0; } } - double amaxl = gkyl_gr_twofluid_tetrad_max_abs_speed(gas_gamma_elc, gas_gamma_ion, light_speed, ql); - double amaxr = gkyl_gr_twofluid_tetrad_max_abs_speed(gas_gamma_elc, gas_gamma_ion, light_speed, qr); + double amaxl = + gkyl_gr_twofluid_tetrad_max_abs_speed(gas_gamma_elc, gas_gamma_ion, light_speed, ql); + double amaxr = + gkyl_gr_twofluid_tetrad_max_abs_speed(gas_gamma_elc, gas_gamma_ion, light_speed, qr); return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double gas_gamma_elc = gr_twofluid_tetrad->gas_gamma_elc; double gas_gamma_ion = gr_twofluid_tetrad->gas_gamma_ion; - double v[84] = { 0.0 }; + double v[84] = {0.0}; gkyl_gr_twofluid_tetrad_prim_vars(gas_gamma_elc, gas_gamma_ion, q, v); if (v[0] < 0.0 || v[4] < 0.0 || v[5] < 0.0 || v[9] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double gas_gamma_elc = gr_twofluid_tetrad->gas_gamma_elc; double gas_gamma_ion = gr_twofluid_tetrad->gas_gamma_ion; double light_speed = gr_twofluid_tetrad->light_speed; @@ -2072,7 +2479,7 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) } static inline void -gr_twofluid_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +gr_twofluid_tetrad_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 5; i++) { diag[i] = qin[i]; @@ -2080,56 +2487,58 @@ gr_twofluid_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin } static inline void -gr_twofluid_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +gr_twofluid_tetrad_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < 84; i++) { sout[i] = 0.0; } } -void -gkyl_gr_twofluid_tetrad_free(const struct gkyl_ref_count* ref) +void gkyl_gr_twofluid_tetrad_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. - struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(base->on_dev, struct wv_gr_twofluid_tetrad, eqn); + struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(base->on_dev, struct wv_gr_twofluid_tetrad, eqn); gkyl_cu_free(gr_twofluid_tetrad); } - struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(base, struct wv_gr_twofluid_tetrad, eqn); + struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(base, struct wv_gr_twofluid_tetrad, eqn); gkyl_free(gr_twofluid_tetrad); } -struct gkyl_wv_eqn* -gkyl_wv_gr_twofluid_tetrad_new(double mass_elc, double mass_ion, double charge_elc, double charge_ion, double gas_gamma_elc, double gas_gamma_ion, - double light_speed, double e_fact, double b_fact, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, - bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_gr_twofluid_tetrad_new( + double mass_elc, double mass_ion, double charge_elc, double charge_ion, double gas_gamma_elc, + double gas_gamma_ion, double light_speed, double e_fact, double b_fact, + enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime *spacetime, + bool use_gpu +) { - return gkyl_wv_gr_twofluid_tetrad_inew(&(struct gkyl_wv_gr_twofluid_tetrad_inp) { - .mass_elc = mass_elc, - .mass_ion = mass_ion, - .charge_elc = charge_elc, - .charge_ion = charge_ion, - .gas_gamma_elc = gas_gamma_elc, - .gas_gamma_ion = gas_gamma_ion, - .light_speed = light_speed, - .e_fact = e_fact, - .b_fact = b_fact, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .spacetime = spacetime, - .rp_type = WV_GR_TWOFLUID_TETRAD_RP_HLL, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_gr_twofluid_tetrad_inew(&(struct gkyl_wv_gr_twofluid_tetrad_inp + ){.mass_elc = mass_elc, + .mass_ion = mass_ion, + .charge_elc = charge_elc, + .charge_ion = charge_ion, + .gas_gamma_elc = gas_gamma_elc, + .gas_gamma_ion = gas_gamma_ion, + .light_speed = light_speed, + .e_fact = e_fact, + .b_fact = b_fact, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .spacetime = spacetime, + .rp_type = WV_GR_TWOFLUID_TETRAD_RP_HLL, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_gr_twofluid_tetrad_inew(const struct gkyl_wv_gr_twofluid_tetrad_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_gr_twofluid_tetrad_inew(const struct gkyl_wv_gr_twofluid_tetrad_inp *inp +) { - struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = gkyl_malloc(sizeof(struct wv_gr_twofluid_tetrad)); + struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + gkyl_malloc(sizeof(struct wv_gr_twofluid_tetrad)); gr_twofluid_tetrad->eqn.type = GKYL_EQN_GR_TWOFLUID_TETRAD; gr_twofluid_tetrad->eqn.num_equations = 84; @@ -2153,8 +2562,7 @@ gkyl_wv_gr_twofluid_tetrad_inew(const struct gkyl_wv_gr_twofluid_tetrad_inp* inp gr_twofluid_tetrad->eqn.num_waves = 2; gr_twofluid_tetrad->eqn.waves_func = wave_lax_l; gr_twofluid_tetrad->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_GR_TWOFLUID_TETRAD_RP_HLL) { + } else if (inp->rp_type == WV_GR_TWOFLUID_TETRAD_RP_HLL) { gr_twofluid_tetrad->eqn.num_waves = 6; gr_twofluid_tetrad->eqn.waves_func = wave_hll_l; gr_twofluid_tetrad->eqn.qfluct_func = qfluct_hll_l; @@ -2179,114 +2587,115 @@ gkyl_wv_gr_twofluid_tetrad_inew(const struct gkyl_wv_gr_twofluid_tetrad_inp* inp gr_twofluid_tetrad->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(gr_twofluid_tetrad->eqn.flags); gr_twofluid_tetrad->eqn.ref_count = gkyl_ref_count_init(gkyl_gr_twofluid_tetrad_free); - gr_twofluid_tetrad->eqn.on_dev = &gr_twofluid_tetrad->eqn; // On the CPU, the equation object points to itself. + gr_twofluid_tetrad->eqn.on_dev = + &gr_twofluid_tetrad->eqn; // On the CPU, the equation object points to itself. return &gr_twofluid_tetrad->eqn; } -double -gkyl_wv_gr_twofluid_tetrad_mass_elc(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_tetrad_mass_elc(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double mass_elc = gr_twofluid_tetrad->mass_elc; return mass_elc; } -double -gkyl_wv_gr_twofluid_tetrad_mass_ion(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_tetrad_mass_ion(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double mass_ion = gr_twofluid_tetrad->mass_ion; return mass_ion; } -double -gkyl_wv_gr_twofluid_tetrad_charge_elc(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_tetrad_charge_elc(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double charge_elc = gr_twofluid_tetrad->charge_elc; return charge_elc; } -double -gkyl_wv_gr_twofluid_tetrad_charge_ion(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_tetrad_charge_ion(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double charge_ion = gr_twofluid_tetrad->charge_ion; return charge_ion; } -double -gkyl_wv_gr_twofluid_tetrad_gas_gamma_elc(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_tetrad_gas_gamma_elc(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double gas_gamma_elc = gr_twofluid_tetrad->gas_gamma_elc; return gas_gamma_elc; } -double -gkyl_wv_gr_twofluid_tetrad_gas_gamma_ion(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_tetrad_gas_gamma_ion(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double gas_gamma_ion = gr_twofluid_tetrad->gas_gamma_ion; return gas_gamma_ion; } -double -gkyl_wv_gr_twofluid_tetrad_light_speed(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_tetrad_light_speed(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double light_speed = gr_twofluid_tetrad->light_speed; return light_speed; } -double -gkyl_wv_gr_twofluid_tetrad_e_fact(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_tetrad_e_fact(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double e_fact = gr_twofluid_tetrad->e_fact; return e_fact; } -double -gkyl_wv_gr_twofluid_tetrad_b_fact(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_twofluid_tetrad_b_fact(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); double b_fact = gr_twofluid_tetrad->b_fact; return b_fact; } -enum gkyl_spacetime_gauge -gkyl_wv_gr_twofluid_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn) +enum gkyl_spacetime_gauge gkyl_wv_gr_twofluid_tetrad_spacetime_gauge(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); enum gkyl_spacetime_gauge spacetime_gauge = gr_twofluid_tetrad->spacetime_gauge; return spacetime_gauge; } -int -gkyl_wv_gr_twofluid_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_gr_twofluid_tetrad_reinit_freq(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); int reinit_freq = gr_twofluid_tetrad->reinit_freq; return reinit_freq; } -struct gkyl_gr_spacetime* -gkyl_wv_gr_twofluid_tetrad_spacetime(const struct gkyl_wv_eqn* eqn) +struct gkyl_gr_spacetime *gkyl_wv_gr_twofluid_tetrad_spacetime(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); + const struct wv_gr_twofluid_tetrad *gr_twofluid_tetrad = + container_of(eqn, struct wv_gr_twofluid_tetrad, eqn); struct gkyl_gr_spacetime *spacetime = gr_twofluid_tetrad->spacetime; return spacetime; diff --git a/moments/zero/wv_gr_ultra_rel_euler.c b/moments/zero/wv_gr_ultra_rel_euler.c index 61495b6cca..1f79af9fce 100644 --- a/moments/zero/wv_gr_ultra_rel_euler.c +++ b/moments/zero/wv_gr_ultra_rel_euler.c @@ -6,12 +6,11 @@ #include #include -void -gkyl_gr_ultra_rel_euler_flux(double gas_gamma, const double q[70], double flux[70]) +void gkyl_gr_ultra_rel_euler_flux(double gas_gamma, const double q[70], double flux[70]) { - double v[70] = { 0.0 }; + double v[70] = {0.0}; gkyl_gr_ultra_rel_euler_prim_vars(gas_gamma, q, v); - double rho = v[0]; + double rho = v[0]; double vx = v[1]; double vy = v[2]; double vz = v[3]; @@ -21,14 +20,23 @@ gkyl_gr_ultra_rel_euler_flux(double gas_gamma, const double q[70], double flux[7 double shift_x = v[5]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[8]; spatial_metric[0][1] = v[9]; spatial_metric[0][2] = v[10]; - spatial_metric[1][0] = v[11]; spatial_metric[1][1] = v[12]; spatial_metric[1][2] = v[13]; - spatial_metric[2][0] = v[14]; spatial_metric[2][1] = v[15]; spatial_metric[2][2] = v[16]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = v[8]; + spatial_metric[0][1] = v[9]; + spatial_metric[0][2] = v[10]; + spatial_metric[1][0] = v[11]; + spatial_metric[1][1] = v[12]; + spatial_metric[1][2] = v[13]; + spatial_metric[2][0] = v[14]; + spatial_metric[2][1] = v[15]; + spatial_metric[2][2] = v[16]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + bool in_excision_region = false; if (v[26] < pow(10.0, -8.0)) { in_excision_region = true; @@ -37,7 +45,9 @@ gkyl_gr_ultra_rel_euler_flux(double gas_gamma, const double q[70], double flux[7 if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -50,24 +60,24 @@ gkyl_gr_ultra_rel_euler_flux(double gas_gamma, const double q[70], double flux[7 W = 1.0 / sqrt(pow(10.0, -8.0)); } - flux[0] = (lapse * sqrt(spatial_det)) * ((((rho + p) * (W * W)) - p) * (vx - (shift_x / lapse)) + (p * vx)); - flux[1] = (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vx * (vx - (shift_x / lapse))) + p); + flux[0] = (lapse * sqrt(spatial_det)) * + ((((rho + p) * (W * W)) - p) * (vx - (shift_x / lapse)) + (p * vx)); + flux[1] = + (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vx * (vx - (shift_x / lapse))) + p); flux[2] = (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vy * (vx - (shift_x / lapse)))); flux[3] = (lapse * sqrt(spatial_det)) * ((rho + p) * (W * W) * (vz * (vx - (shift_x / lapse)))); for (int i = 4; i < 70; i++) { flux[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 70; i++) { flux[i] = 0.0; } } } -void -gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v[70]) +void gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v[70]) { double lapse = q[4]; double shift_x = q[5]; @@ -75,21 +85,33 @@ gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v double shift_z = q[7]; double spatial_metric[3][3]; - spatial_metric[0][0] = q[8]; spatial_metric[0][1] = q[9]; spatial_metric[0][2] = q[10]; - spatial_metric[1][0] = q[11]; spatial_metric[1][1] = q[12]; spatial_metric[1][2] = q[13]; - spatial_metric[2][0] = q[14]; spatial_metric[2][1] = q[15]; spatial_metric[2][2] = q[16]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = q[8]; + spatial_metric[0][1] = q[9]; + spatial_metric[0][2] = q[10]; + spatial_metric[1][0] = q[11]; + spatial_metric[1][1] = q[12]; + spatial_metric[1][2] = q[13]; + spatial_metric[2][0] = q[14]; + spatial_metric[2][1] = q[15]; + spatial_metric[2][2] = q[16]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } gkyl_gr_ultra_rel_euler_inv_spatial_metric(q, &inv_spatial_metric); - + double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = q[17]; extrinsic_curvature[0][1] = q[18]; extrinsic_curvature[0][2] = q[19]; - extrinsic_curvature[1][0] = q[20]; extrinsic_curvature[1][1] = q[21]; extrinsic_curvature[1][2] = q[22]; - extrinsic_curvature[2][0] = q[23]; extrinsic_curvature[2][1] = q[24]; extrinsic_curvature[2][2] = q[25]; + extrinsic_curvature[0][0] = q[17]; + extrinsic_curvature[0][1] = q[18]; + extrinsic_curvature[0][2] = q[19]; + extrinsic_curvature[1][0] = q[20]; + extrinsic_curvature[1][1] = q[21]; + extrinsic_curvature[1][2] = q[22]; + extrinsic_curvature[2][0] = q[23]; + extrinsic_curvature[2][1] = q[24]; + extrinsic_curvature[2][2] = q[25]; double lapse_der[3]; lapse_der[0] = q[27]; @@ -97,22 +119,46 @@ gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v lapse_der[2] = q[29]; double shift_der[3][3]; - shift_der[0][0] = q[30]; shift_der[0][1] = q[31]; shift_der[0][2] = q[32]; - shift_der[1][0] = q[33]; shift_der[1][1] = q[34]; shift_der[1][2] = q[35]; - shift_der[2][0] = q[36]; shift_der[2][1] = q[37]; shift_der[2][2] = q[38]; + shift_der[0][0] = q[30]; + shift_der[0][1] = q[31]; + shift_der[0][2] = q[32]; + shift_der[1][0] = q[33]; + shift_der[1][1] = q[34]; + shift_der[1][2] = q[35]; + shift_der[2][0] = q[36]; + shift_der[2][1] = q[37]; + shift_der[2][2] = q[38]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = q[39]; spatial_metric_der[0][0][1] = q[40]; spatial_metric_der[0][0][2] = q[41]; - spatial_metric_der[0][1][0] = q[42]; spatial_metric_der[0][1][1] = q[43]; spatial_metric_der[0][1][2] = q[44]; - spatial_metric_der[0][2][0] = q[45]; spatial_metric_der[0][2][1] = q[46]; spatial_metric_der[0][2][2] = q[47]; - - spatial_metric_der[1][0][0] = q[48]; spatial_metric_der[1][0][1] = q[49]; spatial_metric_der[1][0][2] = q[50]; - spatial_metric_der[1][1][0] = q[51]; spatial_metric_der[1][1][1] = q[52]; spatial_metric_der[1][1][2] = q[53]; - spatial_metric_der[1][2][0] = q[54]; spatial_metric_der[1][2][1] = q[55]; spatial_metric_der[1][2][2] = q[56]; - - spatial_metric_der[0][0][0] = q[57]; spatial_metric_der[0][0][1] = q[58]; spatial_metric_der[0][0][2] = q[59]; - spatial_metric_der[0][1][0] = q[60]; spatial_metric_der[0][1][1] = q[61]; spatial_metric_der[0][1][2] = q[62]; - spatial_metric_der[0][2][0] = q[63]; spatial_metric_der[0][2][1] = q[64]; spatial_metric_der[0][2][2] = q[65]; + spatial_metric_der[0][0][0] = q[39]; + spatial_metric_der[0][0][1] = q[40]; + spatial_metric_der[0][0][2] = q[41]; + spatial_metric_der[0][1][0] = q[42]; + spatial_metric_der[0][1][1] = q[43]; + spatial_metric_der[0][1][2] = q[44]; + spatial_metric_der[0][2][0] = q[45]; + spatial_metric_der[0][2][1] = q[46]; + spatial_metric_der[0][2][2] = q[47]; + + spatial_metric_der[1][0][0] = q[48]; + spatial_metric_der[1][0][1] = q[49]; + spatial_metric_der[1][0][2] = q[50]; + spatial_metric_der[1][1][0] = q[51]; + spatial_metric_der[1][1][1] = q[52]; + spatial_metric_der[1][1][2] = q[53]; + spatial_metric_der[1][2][0] = q[54]; + spatial_metric_der[1][2][1] = q[55]; + spatial_metric_der[1][2][2] = q[56]; + + spatial_metric_der[0][0][0] = q[57]; + spatial_metric_der[0][0][1] = q[58]; + spatial_metric_der[0][0][2] = q[59]; + spatial_metric_der[0][1][0] = q[60]; + spatial_metric_der[0][1][1] = q[61]; + spatial_metric_der[0][1][2] = q[62]; + spatial_metric_der[0][2][0] = q[63]; + spatial_metric_der[0][2][1] = q[64]; + spatial_metric_der[0][2][2] = q[65]; double evol_param = q[66]; double x = q[67]; @@ -125,9 +171,12 @@ gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v } if (!in_excision_region) { - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double Etot = q[0] / sqrt(spatial_det); double momx = q[1] / sqrt(spatial_det); @@ -136,7 +185,9 @@ gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v double mom[3]; double mom_sq = 0.0; - mom[0] = momx; mom[1] = momy; mom[2] = momz; + mom[0] = momx; + mom[1] = momy; + mom[2] = momz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -145,7 +196,9 @@ gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v } double beta = 0.25 * (2.0 - gas_gamma); - double p = -(2.0 * beta * Etot) + sqrt((4.0 * (beta * beta) * (Etot * Etot)) + ((gas_gamma - 1.0) * ((Etot * Etot) - mom_sq))); + double p = + -(2.0 * beta * Etot) + + sqrt((4.0 * (beta * beta) * (Etot * Etot)) + ((gas_gamma - 1.0) * ((Etot * Etot) - mom_sq))); if (p < pow(10.0, -8.0)) { p = pow(10.0, -8.0); } @@ -172,7 +225,9 @@ gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v } double cov_vel[3]; - cov_vel[0] = cov_vx; cov_vel[1] = cov_vy; cov_vel[2] = cov_vz; + cov_vel[0] = cov_vx; + cov_vel[1] = cov_vy; + cov_vel[2] = cov_vz; double vel[3]; for (int i = 0; i < 3; i++) { @@ -193,13 +248,25 @@ gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v v[6] = shift_y; v[7] = shift_z; - v[8] = spatial_metric[0][0]; v[9] = spatial_metric[0][1]; v[10] = spatial_metric[0][2]; - v[11] = spatial_metric[1][0]; v[12] = spatial_metric[1][1]; v[13] = spatial_metric[1][2]; - v[14] = spatial_metric[2][0]; v[15] = spatial_metric[2][1]; v[16] = spatial_metric[2][2]; - - v[17] = extrinsic_curvature[0][0]; v[18] = extrinsic_curvature[0][1]; v[19] = extrinsic_curvature[0][2]; - v[20] = extrinsic_curvature[1][0]; v[21] = extrinsic_curvature[1][1]; v[22] = extrinsic_curvature[1][2]; - v[23] = extrinsic_curvature[2][0]; v[24] = extrinsic_curvature[2][1]; v[25] = extrinsic_curvature[2][2]; + v[8] = spatial_metric[0][0]; + v[9] = spatial_metric[0][1]; + v[10] = spatial_metric[0][2]; + v[11] = spatial_metric[1][0]; + v[12] = spatial_metric[1][1]; + v[13] = spatial_metric[1][2]; + v[14] = spatial_metric[2][0]; + v[15] = spatial_metric[2][1]; + v[16] = spatial_metric[2][2]; + + v[17] = extrinsic_curvature[0][0]; + v[18] = extrinsic_curvature[0][1]; + v[19] = extrinsic_curvature[0][2]; + v[20] = extrinsic_curvature[1][0]; + v[21] = extrinsic_curvature[1][1]; + v[22] = extrinsic_curvature[1][2]; + v[23] = extrinsic_curvature[2][0]; + v[24] = extrinsic_curvature[2][1]; + v[25] = extrinsic_curvature[2][2]; v[26] = 1.0; @@ -207,28 +274,51 @@ gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v v[28] = lapse_der[1]; v[29] = lapse_der[2]; - v[30] = shift_der[0][0]; v[31] = shift_der[0][1]; v[32] = shift_der[0][2]; - v[33] = shift_der[1][0]; v[34] = shift_der[1][1]; v[35] = shift_der[1][2]; - v[36] = shift_der[2][0]; v[37] = shift_der[2][1]; v[38] = shift_der[2][2]; - - v[39] = spatial_metric_der[0][0][0]; v[40] = spatial_metric_der[0][0][1]; v[41] = spatial_metric_der[0][0][2]; - v[42] = spatial_metric_der[0][1][0]; v[43] = spatial_metric_der[0][1][1]; v[44] = spatial_metric_der[0][1][2]; - v[45] = spatial_metric_der[0][2][0]; v[46] = spatial_metric_der[0][2][1]; v[47] = spatial_metric_der[0][2][2]; - - v[48] = spatial_metric_der[1][0][0]; v[49] = spatial_metric_der[1][0][1]; v[50] = spatial_metric_der[1][0][2]; - v[51] = spatial_metric_der[1][1][0]; v[52] = spatial_metric_der[1][1][1]; v[53] = spatial_metric_der[1][1][2]; - v[54] = spatial_metric_der[1][2][0]; v[55] = spatial_metric_der[1][2][1]; v[56] = spatial_metric_der[1][2][2]; - - v[57] = spatial_metric_der[2][0][0]; v[58] = spatial_metric_der[2][0][1]; v[59] = spatial_metric_der[2][0][2]; - v[60] = spatial_metric_der[2][1][0]; v[61] = spatial_metric_der[2][1][1]; v[62] = spatial_metric_der[2][1][2]; - v[63] = spatial_metric_der[2][2][0]; v[64] = spatial_metric_der[2][2][1]; v[65] = spatial_metric_der[2][2][2]; + v[30] = shift_der[0][0]; + v[31] = shift_der[0][1]; + v[32] = shift_der[0][2]; + v[33] = shift_der[1][0]; + v[34] = shift_der[1][1]; + v[35] = shift_der[1][2]; + v[36] = shift_der[2][0]; + v[37] = shift_der[2][1]; + v[38] = shift_der[2][2]; + + v[39] = spatial_metric_der[0][0][0]; + v[40] = spatial_metric_der[0][0][1]; + v[41] = spatial_metric_der[0][0][2]; + v[42] = spatial_metric_der[0][1][0]; + v[43] = spatial_metric_der[0][1][1]; + v[44] = spatial_metric_der[0][1][2]; + v[45] = spatial_metric_der[0][2][0]; + v[46] = spatial_metric_der[0][2][1]; + v[47] = spatial_metric_der[0][2][2]; + + v[48] = spatial_metric_der[1][0][0]; + v[49] = spatial_metric_der[1][0][1]; + v[50] = spatial_metric_der[1][0][2]; + v[51] = spatial_metric_der[1][1][0]; + v[52] = spatial_metric_der[1][1][1]; + v[53] = spatial_metric_der[1][1][2]; + v[54] = spatial_metric_der[1][2][0]; + v[55] = spatial_metric_der[1][2][1]; + v[56] = spatial_metric_der[1][2][2]; + + v[57] = spatial_metric_der[2][0][0]; + v[58] = spatial_metric_der[2][0][1]; + v[59] = spatial_metric_der[2][0][2]; + v[60] = spatial_metric_der[2][1][0]; + v[61] = spatial_metric_der[2][1][1]; + v[62] = spatial_metric_der[2][1][2]; + v[63] = spatial_metric_der[2][2][0]; + v[64] = spatial_metric_der[2][2][1]; + v[65] = spatial_metric_der[2][2][2]; v[66] = evol_param; v[67] = x; v[68] = y; v[69] = z; - } - else { + } else { for (int i = 0; i < 70; i++) { v[i] = 0.0; } @@ -242,18 +332,26 @@ gkyl_gr_ultra_rel_euler_prim_vars(double gas_gamma, const double q[70], double v gkyl_free(inv_spatial_metric); } -void -gkyl_gr_ultra_rel_euler_inv_spatial_metric(const double q[70], double ***inv_spatial_metric) +void gkyl_gr_ultra_rel_euler_inv_spatial_metric(const double q[70], double ***inv_spatial_metric) { double spatial_metric[3][3]; - spatial_metric[0][0] = q[8]; spatial_metric[0][1] = q[9]; spatial_metric[0][2] = q[10]; - spatial_metric[1][0] = q[11]; spatial_metric[1][1] = q[12]; spatial_metric[1][2] = q[13]; - spatial_metric[2][0] = q[14]; spatial_metric[2][1] = q[15]; spatial_metric[2][2] = q[16]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = q[8]; + spatial_metric[0][1] = q[9]; + spatial_metric[0][2] = q[10]; + spatial_metric[1][0] = q[11]; + spatial_metric[1][1] = q[12]; + spatial_metric[1][2] = q[13]; + spatial_metric[2][0] = q[14]; + spatial_metric[2][1] = q[15]; + spatial_metric[2][2] = q[16]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -284,8 +382,7 @@ gkyl_gr_ultra_rel_euler_inv_spatial_metric(const double q[70], double ***inv_spa for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -293,16 +390,18 @@ gkyl_gr_ultra_rel_euler_inv_spatial_metric(const double q[70], double ***inv_spa for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*inv_spatial_metric)[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*inv_spatial_metric)[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } } -void -gkyl_gr_ultra_rel_euler_stress_energy_tensor(double gas_gamma, const double q[70], double ***stress_energy) +void gkyl_gr_ultra_rel_euler_stress_energy_tensor( + double gas_gamma, const double q[70], double ***stress_energy +) { - double v[70] = { 0.0 }; + double v[70] = {0.0}; gkyl_gr_ultra_rel_euler_prim_vars(gas_gamma, q, v); double rho = v[0]; double vx = v[1]; @@ -316,11 +415,17 @@ gkyl_gr_ultra_rel_euler_stress_energy_tensor(double gas_gamma, const double q[70 double shift_z = v[7]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[8]; spatial_metric[0][1] = v[9]; spatial_metric[0][2] = v[10]; - spatial_metric[1][0] = v[11]; spatial_metric[1][1] = v[12]; spatial_metric[1][2] = v[13]; - spatial_metric[2][0] = v[14]; spatial_metric[2][1] = v[15]; spatial_metric[2][2] = v[16]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[8]; + spatial_metric[0][1] = v[9]; + spatial_metric[0][2] = v[10]; + spatial_metric[1][0] = v[11]; + spatial_metric[1][1] = v[12]; + spatial_metric[1][2] = v[13]; + spatial_metric[2][0] = v[14]; + spatial_metric[2][1] = v[15]; + spatial_metric[2][2] = v[16]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -335,7 +440,9 @@ gkyl_gr_ultra_rel_euler_stress_energy_tensor(double gas_gamma, const double q[70 if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -357,27 +464,30 @@ gkyl_gr_ultra_rel_euler_stress_energy_tensor(double gas_gamma, const double q[70 spacetime_vel[3] = (W * vz) - (shift_z * (W / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*stress_energy)[i][j] = (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); + (*stress_energy)[i][j] = + (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); } } - } - else { + } else { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { (*stress_energy)[i][j] = 0.0; @@ -391,10 +501,9 @@ gkyl_gr_ultra_rel_euler_stress_energy_tensor(double gas_gamma, const double q[70 gkyl_free(inv_spatial_metric); } -static inline double -gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]) +static inline double gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]) { - double v[70] = { 0.0 }; + double v[70] = {0.0}; gkyl_gr_ultra_rel_euler_prim_vars(gas_gamma, q, v); double vx = v[1]; double vy = v[2]; @@ -406,11 +515,17 @@ gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]) double shift_z = v[7]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[8]; spatial_metric[0][1] = v[9]; spatial_metric[0][2] = v[10]; - spatial_metric[1][0] = v[11]; spatial_metric[1][1] = v[12]; spatial_metric[1][2] = v[13]; - spatial_metric[2][0] = v[14]; spatial_metric[2][1] = v[15]; spatial_metric[2][2] = v[16]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[8]; + spatial_metric[0][1] = v[9]; + spatial_metric[0][2] = v[10]; + spatial_metric[1][0] = v[11]; + spatial_metric[1][1] = v[12]; + spatial_metric[1][2] = v[13]; + spatial_metric[2][0] = v[14]; + spatial_metric[2][1] = v[15]; + spatial_metric[2][2] = v[16]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -431,16 +546,15 @@ gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]) if (fabs(spatial_metric[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime = true; } - } - else { + } else { if (fabs(spatial_metric[i][j]) > pow(10.0, -8.0)) { curved_spacetime = true; } } } } - if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || fabs(shift_y) > pow(10.0, -8.0) || - fabs(shift_z) > pow(10.0, -8.0)) { + if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || + fabs(shift_y) > pow(10.0, -8.0) || fabs(shift_z) > pow(10.0, -8.0)) { curved_spacetime = true; } @@ -448,7 +562,9 @@ gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]) if (curved_spacetime) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -457,7 +573,9 @@ gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]) } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double material_eigs[3]; double fast_acoustic_eigs[3]; @@ -466,11 +584,23 @@ gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]) for (int i = 0; i < 3; i++) { material_eigs[i] = (lapse * vel[i]) - shift[i]; - fast_acoustic_eigs[i] = (lapse / (1.0 - (v_sq * (c_s * c_s)))) * ((vel[i] * (1.0 - (c_s * c_s))) + - (c_s * sqrt((1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - (vel[i] * vel[i]) * (1.0 - (c_s * c_s)))))) - shift[i]; - - slow_acoustic_eigs[i] = (lapse / (1.0 - (v_sq * (c_s * c_s)))) * ((vel[i] * (1.0 - (c_s * c_s))) - - (c_s * sqrt((1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - (vel[i] * vel[i]) * (1.0 - (c_s * c_s)))))) - shift[i]; + fast_acoustic_eigs[i] = + (lapse / (1.0 - (v_sq * (c_s * c_s)))) * + ((vel[i] * (1.0 - (c_s * c_s))) + + (c_s * sqrt( + (1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - + (vel[i] * vel[i]) * (1.0 - (c_s * c_s))) + ))) - + shift[i]; + + slow_acoustic_eigs[i] = + (lapse / (1.0 - (v_sq * (c_s * c_s)))) * + ((vel[i] * (1.0 - (c_s * c_s))) - + (c_s * sqrt( + (1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - + (vel[i] * vel[i]) * (1.0 - (c_s * c_s))) + ))) - + shift[i]; } double max_eig = 0.0; @@ -492,8 +622,7 @@ gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]) gkyl_free(inv_spatial_metric); return fabs(v_sq) + max_eig; - } - else { + } else { double v_sq = sqrt((vx * vx) + (vy * vy) + (vz * vz)); for (int i = 0; i < 3; i++) { @@ -503,8 +632,7 @@ gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]) return fabs(v_sq) + c_s; } - } - else { + } else { for (int i = 0; i < 3; i++) { gkyl_free(inv_spatial_metric[i]); } @@ -515,7 +643,7 @@ gkyl_gr_ultra_rel_euler_max_abs_speed(double gas_gamma, const double q[70]) } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 70; i++) { @@ -524,7 +652,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 70; i++) { @@ -532,8 +660,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -gr_ultra_rel_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_ultra_rel_euler_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 0; i < 70; i++) { ghost[i] = skin[i]; @@ -542,8 +672,10 @@ gr_ultra_rel_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const d ghost[1] = -ghost[1]; } -static void -gr_ultra_rel_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_ultra_rel_euler_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 1; i < 4; i++) { ghost[i] = -skin[i]; @@ -556,9 +688,10 @@ gr_ultra_rel_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, cons } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; qlocal[1] = (qglobal[1] * norm[0]) + (qglobal[2] * norm[1]) + (qglobal[3] * norm[2]); @@ -599,9 +732,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinate frame. - qlocal[8] = v1[0]; qlocal[9] = v1[1]; qlocal[10] = v1[2]; - qlocal[11] = v2[0]; qlocal[12] = v2[1]; qlocal[13] = v2[2]; - qlocal[14] = v3[0]; qlocal[15] = v3[1]; qlocal[16] = v3[2]; + qlocal[8] = v1[0]; + qlocal[9] = v1[1]; + qlocal[10] = v1[2]; + qlocal[11] = v2[0]; + qlocal[12] = v2[1]; + qlocal[13] = v2[2]; + qlocal[14] = v3[0]; + qlocal[15] = v3[1]; + qlocal[16] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -632,9 +771,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta extr_v3[2] = (extr_r1[2] * tau2[0]) + (extr_r2[2] * tau2[1]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor to local coordinate frame. - qlocal[17] = extr_v1[0]; qlocal[18] = extr_v1[1]; qlocal[19] = extr_v1[2]; - qlocal[20] = extr_v2[0]; qlocal[21] = extr_v2[1]; qlocal[22] = extr_v2[2]; - qlocal[23] = extr_v3[0]; qlocal[24] = extr_v3[1]; qlocal[25] = extr_v3[2]; + qlocal[17] = extr_v1[0]; + qlocal[18] = extr_v1[1]; + qlocal[19] = extr_v1[2]; + qlocal[20] = extr_v2[0]; + qlocal[21] = extr_v2[1]; + qlocal[22] = extr_v2[2]; + qlocal[23] = extr_v3[0]; + qlocal[24] = extr_v3[1]; + qlocal[25] = extr_v3[2]; qlocal[26] = qglobal[26]; @@ -658,22 +803,37 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); - shiftder_v1[1] = (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); - shiftder_v1[2] = (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); - shiftder_v2[1] = (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); - shiftder_v2[2] = (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); - shiftder_v3[1] = (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); - shiftder_v3[2] = (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); + shiftder_v1[1] = + (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); + shiftder_v1[2] = + (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); + shiftder_v2[1] = + (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); + shiftder_v2[2] = + (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); + shiftder_v3[1] = + (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); + shiftder_v3[2] = + (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative to local coordinate frame. - qlocal[30] = shiftder_v1[0]; qlocal[31] = shiftder_v1[1]; qlocal[32] = shiftder_v1[2]; - qlocal[33] = shiftder_v2[0]; qlocal[34] = shiftder_v2[1]; qlocal[35] = shiftder_v2[2]; - qlocal[36] = shiftder_v3[0]; qlocal[37] = shiftder_v3[1]; qlocal[38] = shiftder_v3[2]; + qlocal[30] = shiftder_v1[0]; + qlocal[31] = shiftder_v1[1]; + qlocal[32] = shiftder_v1[2]; + qlocal[33] = shiftder_v2[0]; + qlocal[34] = shiftder_v2[1]; + qlocal[35] = shiftder_v2[2]; + qlocal[36] = shiftder_v3[0]; + qlocal[37] = shiftder_v3[1]; + qlocal[38] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -756,7 +916,7 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta s33[0] = (r31[0] * tau2[0]) + (r32[0] * tau2[1]) + (r33[0] * tau2[2]); s33[1] = (r31[1] * tau2[0]) + (r32[1] * tau2[1]) + (r33[1] * tau2[2]); s33[2] = (r31[2] * tau2[0]) + (r32[2] * tau2[1]) + (r33[2] * tau2[2]); - + // Rotate spatial metric tensor derivative to local coordinate frame. qlocal[39] = (s11[0] * norm[0]) + (s21[0] * norm[1]) + (s31[0] * norm[2]); qlocal[40] = (s11[1] * norm[0]) + (s21[1] * norm[1]) + (s31[1] * norm[2]); @@ -800,9 +960,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[69] = (qglobal[67] * tau2[0]) + (qglobal[68] * tau2[1]) + (qglobal[69] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; qglobal[1] = (qlocal[1] * norm[0]) + (qlocal[2] * tau1[0]) + (qlocal[3] * tau2[0]); @@ -843,9 +1004,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor back to global coordinate frame. - qglobal[8] = v1[0]; qglobal[9] = v1[1]; qglobal[10] = v1[2]; - qglobal[11] = v2[0]; qglobal[12] = v2[1]; qglobal[13] = v2[2]; - qglobal[14] = v3[0]; qglobal[15] = v3[1]; qglobal[16] = v3[2]; + qglobal[8] = v1[0]; + qglobal[9] = v1[1]; + qglobal[10] = v1[2]; + qglobal[11] = v2[0]; + qglobal[12] = v2[1]; + qglobal[13] = v2[2]; + qglobal[14] = v3[0]; + qglobal[15] = v3[1]; + qglobal[16] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -876,9 +1043,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t extr_v3[2] = (extr_r1[2] * norm[2]) + (extr_r2[2] * tau1[2]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor back to global coordinate frame. - qglobal[17] = extr_v1[0]; qglobal[18] = extr_v1[1]; qglobal[19] = extr_v1[2]; - qglobal[20] = extr_v2[0]; qglobal[21] = extr_v2[1]; qglobal[22] = extr_v2[2]; - qglobal[23] = extr_v3[0]; qglobal[24] = extr_v3[1]; qglobal[25] = extr_v3[2]; + qglobal[17] = extr_v1[0]; + qglobal[18] = extr_v1[1]; + qglobal[19] = extr_v1[2]; + qglobal[20] = extr_v2[0]; + qglobal[21] = extr_v2[1]; + qglobal[22] = extr_v2[2]; + qglobal[23] = extr_v3[0]; + qglobal[24] = extr_v3[1]; + qglobal[25] = extr_v3[2]; qglobal[26] = qlocal[26]; @@ -902,22 +1075,37 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); - shiftder_v1[1] = (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); - shiftder_v1[2] = (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); - shiftder_v2[1] = (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); - shiftder_v2[2] = (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); - shiftder_v3[1] = (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); - shiftder_v3[2] = (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); + shiftder_v1[1] = + (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); + shiftder_v1[2] = + (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); + shiftder_v2[1] = + (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); + shiftder_v2[2] = + (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); + shiftder_v3[1] = + (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); + shiftder_v3[2] = + (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative back to global coordinate frame. - qglobal[30] = shiftder_v1[0]; qglobal[31] = shiftder_v1[1]; qglobal[32] = shiftder_v1[2]; - qglobal[33] = shiftder_v2[0]; qglobal[34] = shiftder_v2[1]; qglobal[35] = shiftder_v2[2]; - qglobal[36] = shiftder_v3[0]; qglobal[37] = shiftder_v3[1]; qglobal[38] = shiftder_v3[2]; + qglobal[30] = shiftder_v1[0]; + qglobal[31] = shiftder_v1[1]; + qglobal[32] = shiftder_v1[2]; + qglobal[33] = shiftder_v2[0]; + qglobal[34] = shiftder_v2[1]; + qglobal[35] = shiftder_v2[2]; + qglobal[36] = shiftder_v3[0]; + qglobal[37] = shiftder_v3[1]; + qglobal[38] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -1044,10 +1232,13 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[69] = (qlocal[67] * norm[2]) + (qlocal[68] * tau1[2]) + (qlocal[69] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); double gas_gamma = gr_ultra_rel_euler->gas_gamma; double sl = gkyl_gr_ultra_rel_euler_max_abs_speed(gas_gamma, ql); @@ -1074,8 +1265,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr[i] - fl[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr[i] - fl[i]) / amax); } - } - else { + } else { for (int i = 0; i < 70; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1088,8 +1278,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[70]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1101,26 +1293,33 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); double vl[70], vr[70]; double gas_gamma = gr_ultra_rel_euler->gas_gamma; - + gkyl_gr_ultra_rel_euler_prim_vars(gas_gamma, ql, vl); gkyl_gr_ultra_rel_euler_prim_vars(gas_gamma, qr, vr); @@ -1155,15 +1354,21 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double c_plus = 1.0 + ((gas_gamma / (gas_gamma - 1.0)) * v0); double v_alpha_sq = -(v0 * v0) + (v1 * v1) + (v2 * v2) + (v3 * v3); - double s_sq = (0.5 * gas_gamma * v0 * (1.0 - v_alpha_sq)) - (0.5 * (gas_gamma - 1.0) * (1.0 + v_alpha_sq)); + double s_sq = + (0.5 * gas_gamma * v0 * (1.0 - v_alpha_sq)) - (0.5 * (gas_gamma - 1.0) * (1.0 + v_alpha_sq)); double energy = (v0 * v0) - (v1 * v1); double y = sqrt(((1.0 - (gas_gamma * v0)) * energy) + s_sq); double k = (v0 * delta[4]) - (v1 * delta[1]); double v_delta = (-v0 * delta[0]) + (v1 * delta[1]) + (v2 * delta[2]) + (v3 * delta[3]); - double a1 = -((s_sq * k) + (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[0])) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / (2.0 * energy * s_sq); - double a2 = -((s_sq * k) - (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[0])) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / (2.0 * energy * s_sq); - double a3 = ((2.0 * s_sq * k) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta)))) / (energy * s_sq); + double a1 = -((s_sq * k) + (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[0])) + + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / + (2.0 * energy * s_sq); + double a2 = -((s_sq * k) - (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[0])) + + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / + (2.0 * energy * s_sq); + double a3 = ((2.0 * s_sq * k) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta)))) / + (energy * s_sq); double a4 = delta[2] - ((k * v2) / energy); double a5 = delta[3] - ((k * v3) / energy); @@ -1177,7 +1382,8 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c wv[1] = a1 * (v1 - ((sqrt(s_sq) * v0) / y)); wv[2] = a1 * v2; wv[3] = a1 * v3; - s[0] = (((1.0 - (gas_gamma * v0)) * v0 * v1) - (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); + s[0] = (((1.0 - (gas_gamma * v0)) * v0 * v1) - (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); wv = &waves[1 * 70]; wv[0] = a3 * v0; @@ -1191,17 +1397,21 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c wv[1] = a2 * (v1 + ((sqrt(s_sq) * v0) / y)); wv[2] = a2 * v2; wv[3] = a2 * v3; - s[2] = (((1.0 - (gas_gamma * v0)) * v0 * v1) + (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); + s[2] = (((1.0 - (gas_gamma * v0)) * v0 * v1) + (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); - return (((1.0 - (gas_gamma * v0)) * v0 * fabs(v1)) + (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); + return (((1.0 - (gas_gamma * v0)) * v0 * fabs(v1)) + (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { - const double* w0 = &waves[0 * 70]; - const double* w1 = &waves[1 * 70]; - const double* w2 = &waves[2 * 70]; + const double *w0 = &waves[0 * 70]; + const double *w1 = &waves[1 * 70]; + const double *w2 = &waves[2 * 70]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]); @@ -1216,33 +1426,38 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } } -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); double gas_gamma = gr_ultra_rel_euler->gas_gamma; double vl[70], vr[70]; @@ -1260,11 +1475,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_zl = vl[7]; double spatial_metric_l[3][3]; - spatial_metric_l[0][0] = vl[8]; spatial_metric_l[0][1] = vl[9]; spatial_metric_l[0][2] = vl[10]; - spatial_metric_l[1][0] = vl[11]; spatial_metric_l[1][1] = vl[12]; spatial_metric_l[1][2] = vl[13]; - spatial_metric_l[2][0] = vl[14]; spatial_metric_l[2][1] = vl[15]; spatial_metric_l[2][2] = vl[16]; - - double **inv_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); + spatial_metric_l[0][0] = vl[8]; + spatial_metric_l[0][1] = vl[9]; + spatial_metric_l[0][2] = vl[10]; + spatial_metric_l[1][0] = vl[11]; + spatial_metric_l[1][1] = vl[12]; + spatial_metric_l[1][2] = vl[13]; + spatial_metric_l[2][0] = vl[14]; + spatial_metric_l[2][1] = vl[15]; + spatial_metric_l[2][2] = vl[16]; + + double **inv_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); } @@ -1283,16 +1504,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_l[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_l = true; } - } - else { + } else { if (fabs(spatial_metric_l[i][j]) > pow(10.0, -8.0)) { curved_spacetime_l = true; } } } } - if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_xl) > pow(10.0, -8.0) || fabs(shift_yl) > pow(10.0, -8.0) || - fabs(shift_zl) > pow(10.0, -8.0)) { + if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_xl) > pow(10.0, -8.0) || + fabs(shift_yl) > pow(10.0, -8.0) || fabs(shift_zl) > pow(10.0, -8.0)) { curved_spacetime_l = true; } @@ -1307,11 +1527,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_zr = vr[7]; double spatial_metric_r[3][3]; - spatial_metric_r[0][0] = vr[8]; spatial_metric_r[0][1] = vr[9]; spatial_metric_r[0][2] = vr[10]; - spatial_metric_r[1][0] = vr[11]; spatial_metric_r[1][1] = vr[12]; spatial_metric_r[1][2] = vr[13]; - spatial_metric_r[2][0] = vr[14]; spatial_metric_r[2][1] = vr[15]; spatial_metric_r[2][2] = vr[16]; - - double **inv_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + spatial_metric_r[0][0] = vr[8]; + spatial_metric_r[0][1] = vr[9]; + spatial_metric_r[0][2] = vr[10]; + spatial_metric_r[1][0] = vr[11]; + spatial_metric_r[1][1] = vr[12]; + spatial_metric_r[1][2] = vr[13]; + spatial_metric_r[2][0] = vr[14]; + spatial_metric_r[2][1] = vr[15]; + spatial_metric_r[2][2] = vr[16]; + + double **inv_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } @@ -1330,16 +1556,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_r[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_r = true; } - } - else { + } else { if (fabs(spatial_metric_l[i][j]) > pow(10.0, -8.0)) { curved_spacetime_r = true; } } } } - if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_xr) > pow(10.0, -8.0) || fabs(shift_yr) > pow(10.0, -8.0) || - fabs(shift_zr) > pow(10.0, -8.0)) { + if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_xr) > pow(10.0, -8.0) || + fabs(shift_yr) > pow(10.0, -8.0) || fabs(shift_zr) > pow(10.0, -8.0)) { curved_spacetime_r = true; } @@ -1354,7 +1579,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (curved_spacetime_l || curved_spacetime_r) { double vel_l[3]; double v_sq_l = 0.0; - vel_l[0] = vx_l; vel_l[1] = vy_l; vel_l[2] = vz_l; + vel_l[0] = vx_l; + vel_l[1] = vy_l; + vel_l[2] = vz_l; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1363,7 +1590,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_l[3]; - shift_l[0] = shift_xl; shift_l[1] = shift_yl; shift_l[2] = shift_zl; + shift_l[0] = shift_xl; + shift_l[1] = shift_yl; + shift_l[2] = shift_zl; double material_eigs_l[3]; double fast_acoustic_eigs_l[3]; @@ -1372,11 +1601,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_l[i] = (lapse_l * vel_l[i]) - shift_l[i]; - fast_acoustic_eigs_l[i] = (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * ((vel_l[i] * (1.0 - (c_sl * c_sl))) + - (c_sl * sqrt((1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl)))))) - shift_l[i]; - - slow_acoustic_eigs_l[i] = (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * ((vel_l[i] * (1.0 - (c_sl * c_sl))) - - (c_sl * sqrt((1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl)))))) - shift_l[i]; + fast_acoustic_eigs_l[i] = + (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * + ((vel_l[i] * (1.0 - (c_sl * c_sl))) + + (c_sl * + sqrt( + (1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - + (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_l[i]; + + slow_acoustic_eigs_l[i] = + (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * + ((vel_l[i] * (1.0 - (c_sl * c_sl))) - + (c_sl * + sqrt( + (1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - + (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_l[i]; } double max_eig_l = 0.0; @@ -1394,7 +1637,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_r[3]; double v_sq_r = 0.0; - vel_r[0] = vx_r; vel_r[1] = vy_r; vel_r[2] = vz_r; + vel_r[0] = vx_r; + vel_r[1] = vy_r; + vel_r[2] = vz_r; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1403,7 +1648,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_r[3]; - shift_r[0] = shift_xr; shift_r[1] = shift_yr; shift_r[2] = shift_zr; + shift_r[0] = shift_xr; + shift_r[1] = shift_yr; + shift_r[2] = shift_zr; double material_eigs_r[3]; double fast_acoustic_eigs_r[3]; @@ -1412,11 +1659,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_r[i] = (lapse_r * vel_r[i]) - shift_r[i]; - fast_acoustic_eigs_r[i] = (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * ((vel_r[i] * (1.0 - (c_sl * c_sl))) + - (c_sl * sqrt((1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl)))))) - shift_r[i]; - - slow_acoustic_eigs_r[i] = (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * ((vel_r[i] * (1.0 - (c_sl * c_sl))) - - (c_sl * sqrt((1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl)))))) - shift_r[i]; + fast_acoustic_eigs_r[i] = + (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * + ((vel_r[i] * (1.0 - (c_sl * c_sl))) + + (c_sl * + sqrt( + (1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - + (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_r[i]; + + slow_acoustic_eigs_r[i] = + (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * + ((vel_r[i] * (1.0 - (c_sl * c_sl))) - + (c_sl * + sqrt( + (1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - + (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_r[i]; } double max_eig_r = 0.0; @@ -1433,11 +1694,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double max_eig_avg = 0.5 * (max_eig_l + max_eig_r); - + sl = (vx_avg - max_eig_avg) / (1.0 - (vx_avg * max_eig_avg)); sr = (vx_avg + max_eig_avg) / (1.0 + (vx_avg * max_eig_avg)); - } - else { + } else { sl = (vx_avg - cs_avg) / (1.0 - (vx_avg * cs_avg)); sr = (vx_avg + cs_avg) / (1.0 + (vx_avg * cs_avg)); } @@ -1457,8 +1717,7 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = qm[i] - ql[i]; w1[i] = qr[i] - qm[i]; } - } - else { + } else { for (int i = 0; i < 70; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1478,8 +1737,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return fmax(fabs(sl), fabs(sr)); } -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[70]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1491,35 +1752,38 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hll(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_hll(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); double gas_gamma = gr_ultra_rel_euler->gas_gamma; double fr[70], fl[70]; @@ -1540,8 +1804,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 70; m++) { flux_jump[m] = fr[m] - fl[m]; } - } - else { + } else { for (int m = 0; m < 70; m++) { flux_jump[m] = 0.0; } @@ -1553,34 +1816,33 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); double gas_gamma = gr_ultra_rel_euler->gas_gamma; - double v[70] = { 0.0 }; + double v[70] = {0.0}; gkyl_gr_ultra_rel_euler_prim_vars(gas_gamma, q, v); if (v[0] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); double gas_gamma = gr_ultra_rel_euler->gas_gamma; return gkyl_gr_ultra_rel_euler_max_abs_speed(gas_gamma, q); } static inline void -gr_ultra_rel_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +gr_ultra_rel_euler_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 4; i++) { diag[i] = qin[i]; @@ -1588,12 +1850,13 @@ gr_ultra_rel_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin } static inline void -gr_ultra_rel_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +gr_ultra_rel_euler_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); double gas_gamma = gr_ultra_rel_euler->gas_gamma; - double v[70] = { 0.0 }; + double v[70] = {0.0}; gkyl_gr_ultra_rel_euler_prim_vars(gas_gamma, qin, v); double rho = v[0]; double vx = v[1]; @@ -1607,14 +1870,26 @@ gr_ultra_rel_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, doub double shift_z = v[7]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[8]; spatial_metric[0][1] = v[9]; spatial_metric[0][2] = v[10]; - spatial_metric[1][0] = v[11]; spatial_metric[1][1] = v[12]; spatial_metric[1][2] = v[13]; - spatial_metric[2][0] = v[14]; spatial_metric[2][1] = v[15]; spatial_metric[2][2] = v[16]; + spatial_metric[0][0] = v[8]; + spatial_metric[0][1] = v[9]; + spatial_metric[0][2] = v[10]; + spatial_metric[1][0] = v[11]; + spatial_metric[1][1] = v[12]; + spatial_metric[1][2] = v[13]; + spatial_metric[2][0] = v[14]; + spatial_metric[2][1] = v[15]; + spatial_metric[2][2] = v[16]; double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = v[17]; extrinsic_curvature[0][1] = v[18]; extrinsic_curvature[0][2] = v[19]; - extrinsic_curvature[1][0] = v[20]; extrinsic_curvature[1][1] = v[21]; extrinsic_curvature[1][2] = v[22]; - extrinsic_curvature[2][0] = v[23]; extrinsic_curvature[2][1] = v[24]; extrinsic_curvature[2][2] = v[25]; + extrinsic_curvature[0][0] = v[17]; + extrinsic_curvature[0][1] = v[18]; + extrinsic_curvature[0][2] = v[19]; + extrinsic_curvature[1][0] = v[20]; + extrinsic_curvature[1][1] = v[21]; + extrinsic_curvature[1][2] = v[22]; + extrinsic_curvature[2][0] = v[23]; + extrinsic_curvature[2][1] = v[24]; + extrinsic_curvature[2][2] = v[25]; double lapse_der[3]; lapse_der[0] = v[27]; @@ -1622,24 +1897,48 @@ gr_ultra_rel_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, doub lapse_der[2] = v[29]; double shift_der[3][3]; - shift_der[0][0] = v[30]; shift_der[0][1] = v[31]; shift_der[0][2] = v[32]; - shift_der[1][0] = v[33]; shift_der[1][1] = v[34]; shift_der[1][2] = v[35]; - shift_der[2][0] = v[36]; shift_der[2][1] = v[37]; shift_der[2][2] = v[38]; + shift_der[0][0] = v[30]; + shift_der[0][1] = v[31]; + shift_der[0][2] = v[32]; + shift_der[1][0] = v[33]; + shift_der[1][1] = v[34]; + shift_der[1][2] = v[35]; + shift_der[2][0] = v[36]; + shift_der[2][1] = v[37]; + shift_der[2][2] = v[38]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = v[39]; spatial_metric_der[0][0][1] = v[40]; spatial_metric_der[0][0][2] = v[41]; - spatial_metric_der[0][1][0] = v[42]; spatial_metric_der[0][1][1] = v[43]; spatial_metric_der[0][1][2] = v[44]; - spatial_metric_der[0][2][0] = v[45]; spatial_metric_der[0][2][1] = v[46]; spatial_metric_der[0][2][2] = v[47]; - - spatial_metric_der[1][0][0] = v[48]; spatial_metric_der[1][0][1] = v[49]; spatial_metric_der[1][0][2] = v[50]; - spatial_metric_der[1][1][0] = v[51]; spatial_metric_der[1][1][1] = v[52]; spatial_metric_der[1][1][2] = v[53]; - spatial_metric_der[1][2][0] = v[54]; spatial_metric_der[1][2][1] = v[55]; spatial_metric_der[1][2][2] = v[56]; - - spatial_metric_der[0][0][0] = v[57]; spatial_metric_der[0][0][1] = v[58]; spatial_metric_der[0][0][2] = v[59]; - spatial_metric_der[0][1][0] = v[60]; spatial_metric_der[0][1][1] = v[61]; spatial_metric_der[0][1][2] = v[62]; - spatial_metric_der[0][2][0] = v[63]; spatial_metric_der[0][2][1] = v[64]; spatial_metric_der[0][2][2] = v[65]; - - double **stress_energy = gkyl_malloc(sizeof(double*[4])); + spatial_metric_der[0][0][0] = v[39]; + spatial_metric_der[0][0][1] = v[40]; + spatial_metric_der[0][0][2] = v[41]; + spatial_metric_der[0][1][0] = v[42]; + spatial_metric_der[0][1][1] = v[43]; + spatial_metric_der[0][1][2] = v[44]; + spatial_metric_der[0][2][0] = v[45]; + spatial_metric_der[0][2][1] = v[46]; + spatial_metric_der[0][2][2] = v[47]; + + spatial_metric_der[1][0][0] = v[48]; + spatial_metric_der[1][0][1] = v[49]; + spatial_metric_der[1][0][2] = v[50]; + spatial_metric_der[1][1][0] = v[51]; + spatial_metric_der[1][1][1] = v[52]; + spatial_metric_der[1][1][2] = v[53]; + spatial_metric_der[1][2][0] = v[54]; + spatial_metric_der[1][2][1] = v[55]; + spatial_metric_der[1][2][2] = v[56]; + + spatial_metric_der[0][0][0] = v[57]; + spatial_metric_der[0][0][1] = v[58]; + spatial_metric_der[0][0][2] = v[59]; + spatial_metric_der[0][1][0] = v[60]; + spatial_metric_der[0][1][1] = v[61]; + spatial_metric_der[0][1][2] = v[62]; + spatial_metric_der[0][2][0] = v[63]; + spatial_metric_der[0][2][1] = v[64]; + spatial_metric_der[0][2][2] = v[65]; + + double **stress_energy = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { stress_energy[i] = gkyl_malloc(sizeof(double[4])); } @@ -1653,11 +1952,15 @@ gr_ultra_rel_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, doub if (!in_excision_region) { double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1669,7 +1972,7 @@ gr_ultra_rel_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, doub if (v_sq > 1.0 - pow(10.0, -8.0)) { W = 1.0 / sqrt(1.0 - pow(10.0, -8.0)); } - + double mom[3]; mom[0] = (rho + p) * (W * W) * vx; mom[1] = (rho + p) * (W * W) * vy; @@ -1694,7 +1997,8 @@ gr_ultra_rel_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, doub for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - sout[1 + j] += 0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]; + sout[1 + j] += + 0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]; sout[1 + j] += 0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]; } @@ -1705,8 +2009,7 @@ gr_ultra_rel_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, doub } } } - } - else { + } else { for (int i = 0; i < 70; i++) { sout[i] = 0.0; } @@ -1718,39 +2021,41 @@ gr_ultra_rel_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, doub gkyl_free(stress_energy); } -void -gkyl_gr_ultra_rel_euler_free(const struct gkyl_ref_count* ref) +void gkyl_gr_ultra_rel_euler_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. - struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(base->on_dev, struct wv_gr_ultra_rel_euler, eqn); + struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(base->on_dev, struct wv_gr_ultra_rel_euler, eqn); gkyl_cu_free(gr_ultra_rel_euler); } - struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(base, struct wv_gr_ultra_rel_euler, eqn); + struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(base, struct wv_gr_ultra_rel_euler, eqn); gkyl_free(gr_ultra_rel_euler); } -struct gkyl_wv_eqn* -gkyl_wv_gr_ultra_rel_euler_new(double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_gr_ultra_rel_euler_new( + double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, + struct gkyl_gr_spacetime *spacetime, bool use_gpu +) { - return gkyl_wv_gr_ultra_rel_euler_inew(&(struct gkyl_wv_gr_ultra_rel_euler_inp) { - .gas_gamma = gas_gamma, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .spacetime = spacetime, - .rp_type = WV_GR_ULTRA_REL_EULER_RP_HLL, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_gr_ultra_rel_euler_inew(&(struct gkyl_wv_gr_ultra_rel_euler_inp + ){.gas_gamma = gas_gamma, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .spacetime = spacetime, + .rp_type = WV_GR_ULTRA_REL_EULER_RP_HLL, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_gr_ultra_rel_euler_inew(const struct gkyl_wv_gr_ultra_rel_euler_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_gr_ultra_rel_euler_inew(const struct gkyl_wv_gr_ultra_rel_euler_inp *inp +) { - struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = gkyl_malloc(sizeof(struct wv_gr_ultra_rel_euler)); + struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + gkyl_malloc(sizeof(struct wv_gr_ultra_rel_euler)); gr_ultra_rel_euler->eqn.type = GKYL_EQN_GR_ULTRA_REL_EULER; gr_ultra_rel_euler->eqn.num_equations = 70; @@ -1765,13 +2070,11 @@ gkyl_wv_gr_ultra_rel_euler_inew(const struct gkyl_wv_gr_ultra_rel_euler_inp* inp gr_ultra_rel_euler->eqn.num_waves = 2; gr_ultra_rel_euler->eqn.waves_func = wave_lax_l; gr_ultra_rel_euler->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_GR_ULTRA_REL_EULER_RP_ROE) { + } else if (inp->rp_type == WV_GR_ULTRA_REL_EULER_RP_ROE) { gr_ultra_rel_euler->eqn.num_waves = 3; gr_ultra_rel_euler->eqn.waves_func = wave_roe_l; gr_ultra_rel_euler->eqn.qfluct_func = qfluct_roe_l; - } - else if (inp->rp_type == WV_GR_ULTRA_REL_EULER_RP_HLL) { + } else if (inp->rp_type == WV_GR_ULTRA_REL_EULER_RP_HLL) { gr_ultra_rel_euler->eqn.num_waves = 2; gr_ultra_rel_euler->eqn.waves_func = wave_hll_l; gr_ultra_rel_euler->eqn.qfluct_func = qfluct_hll_l; @@ -1796,44 +2099,45 @@ gkyl_wv_gr_ultra_rel_euler_inew(const struct gkyl_wv_gr_ultra_rel_euler_inp* inp gr_ultra_rel_euler->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(gr_ultra_rel_euler->eqn.flags); gr_ultra_rel_euler->eqn.ref_count = gkyl_ref_count_init(gkyl_gr_ultra_rel_euler_free); - gr_ultra_rel_euler->eqn.on_dev = &gr_ultra_rel_euler->eqn; // On the CPU, the equation object points to itself. + gr_ultra_rel_euler->eqn.on_dev = + &gr_ultra_rel_euler->eqn; // On the CPU, the equation object points to itself. gr_ultra_rel_euler->eqn.embed_geo = NULL; return &gr_ultra_rel_euler->eqn; } -double -gkyl_wv_gr_ultra_rel_euler_gas_gamma(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_ultra_rel_euler_gas_gamma(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); double gas_gamma = gr_ultra_rel_euler->gas_gamma; return gas_gamma; } -enum gkyl_spacetime_gauge -gkyl_wv_gr_ultra_rel_euler_spacetime_gauge(const struct gkyl_wv_eqn* eqn) +enum gkyl_spacetime_gauge gkyl_wv_gr_ultra_rel_euler_spacetime_gauge(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); enum gkyl_spacetime_gauge spacetime_gauge = gr_ultra_rel_euler->spacetime_gauge; return spacetime_gauge; } -int -gkyl_wv_gr_ultra_rel_euler_reinit_freq(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_gr_ultra_rel_euler_reinit_freq(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); int reinit_freq = gr_ultra_rel_euler->reinit_freq; return reinit_freq; } -struct gkyl_gr_spacetime* -gkyl_wv_gr_ultra_rel_euler_spacetime(const struct gkyl_wv_eqn* eqn) +struct gkyl_gr_spacetime *gkyl_wv_gr_ultra_rel_euler_spacetime(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); + const struct wv_gr_ultra_rel_euler *gr_ultra_rel_euler = + container_of(eqn, struct wv_gr_ultra_rel_euler, eqn); struct gkyl_gr_spacetime *spacetime = gr_ultra_rel_euler->spacetime; return spacetime; diff --git a/moments/zero/wv_gr_ultra_rel_euler_tetrad.c b/moments/zero/wv_gr_ultra_rel_euler_tetrad.c index 1d8127eb3e..fb6b774e01 100644 --- a/moments/zero/wv_gr_ultra_rel_euler_tetrad.c +++ b/moments/zero/wv_gr_ultra_rel_euler_tetrad.c @@ -6,17 +6,16 @@ #include #include -void -gkyl_gr_ultra_rel_euler_tetrad_flux(double gas_gamma, const double q[70], double flux[70]) +void gkyl_gr_ultra_rel_euler_tetrad_flux(double gas_gamma, const double q[70], double flux[70]) { - double v[70] = { 0.0 }; + double v[70] = {0.0}; gkyl_gr_ultra_rel_euler_tetrad_prim_vars(gas_gamma, q, v); - double rho = v[0]; + double rho = v[0]; double vx = v[1]; double vy = v[2]; double vz = v[3]; double p = (gas_gamma - 1.0) * rho; - + bool in_excision_region = false; if (v[26] < pow(10.0, -8.0)) { in_excision_region = true; @@ -36,20 +35,20 @@ gkyl_gr_ultra_rel_euler_tetrad_flux(double gas_gamma, const double q[70], double for (int i = 4; i < 70; i++) { flux[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 70; i++) { flux[i] = 0.0; } } } -void -gkyl_gr_ultra_rel_euler_tetrad_flux_correction(double gas_gamma, const double q[70], const double flux_sr[70], double flux_gr[70]) +void gkyl_gr_ultra_rel_euler_tetrad_flux_correction( + double gas_gamma, const double q[70], const double flux_sr[70], double flux_gr[70] +) { - double v[70] = { 0.0 }; + double v[70] = {0.0}; gkyl_gr_ultra_rel_euler_tetrad_prim_vars(gas_gamma, q, v); - double rho = v[0]; + double rho = v[0]; double vx = v[1]; double vy = v[2]; double vz = v[3]; @@ -59,14 +58,23 @@ gkyl_gr_ultra_rel_euler_tetrad_flux_correction(double gas_gamma, const double q[ double shift_x = v[5]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[8]; spatial_metric[0][1] = v[9]; spatial_metric[0][2] = v[10]; - spatial_metric[1][0] = v[11]; spatial_metric[1][1] = v[12]; spatial_metric[1][2] = v[13]; - spatial_metric[2][0] = v[14]; spatial_metric[2][1] = v[15]; spatial_metric[2][2] = v[16]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = v[8]; + spatial_metric[0][1] = v[9]; + spatial_metric[0][2] = v[10]; + spatial_metric[1][0] = v[11]; + spatial_metric[1][1] = v[12]; + spatial_metric[1][2] = v[13]; + spatial_metric[2][0] = v[14]; + spatial_metric[2][1] = v[15]; + spatial_metric[2][2] = v[16]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + bool in_excision_region = false; if (v[26] < pow(10.0, -8.0)) { in_excision_region = true; @@ -75,7 +83,9 @@ gkyl_gr_ultra_rel_euler_tetrad_flux_correction(double gas_gamma, const double q[ if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -96,31 +106,38 @@ gkyl_gr_ultra_rel_euler_tetrad_flux_correction(double gas_gamma, const double q[ if (fabs(vx) < pow(10.0, -8.0)) { if (vx > 0.0) { vx = pow(10.0, -8.0); - } - else { + } else { vx = -pow(10.0, -8.0); } } - flux_gr[0] = (lapse * sqrt(spatial_det)) * ((flux_sr[0] * ((W_curved * W_curved) / (W_flat * W_flat))) + - ((shift_x * (p - ((flux_sr[0] * (W_curved * W_curved)) / (vx * (W_flat * W_flat))))) / lapse)); - flux_gr[1] = (lapse * sqrt(spatial_det)) * ((((flux_sr[1] - p) * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))) + p); - flux_gr[2] = (lapse * sqrt(spatial_det)) * ((flux_sr[2] * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))); - flux_gr[3] = (lapse * sqrt(spatial_det)) * ((flux_sr[3] * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))); + flux_gr[0] = + (lapse * sqrt(spatial_det)) * + ((flux_sr[0] * ((W_curved * W_curved) / (W_flat * W_flat))) + + ((shift_x * (p - ((flux_sr[0] * (W_curved * W_curved)) / (vx * (W_flat * W_flat))))) / lapse) + ); + flux_gr[1] = (lapse * sqrt(spatial_det)) * + ((((flux_sr[1] - p) * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / + (vx * (W_flat * W_flat))) + + p); + flux_gr[2] = + (lapse * sqrt(spatial_det)) * + ((flux_sr[2] * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))); + flux_gr[3] = + (lapse * sqrt(spatial_det)) * + ((flux_sr[3] * (vx - (shift_x / lapse)) * (W_curved * W_curved)) / (vx * (W_flat * W_flat))); for (int i = 4; i < 70; i++) { flux_gr[i] = 0.0; } - } - else { + } else { for (int i = 0; i < 70; i++) { flux_gr[i] = 0.0; } } } -void -gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[70], double v[70]) +void gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[70], double v[70]) { double lapse = q[4]; double shift_x = q[5]; @@ -128,21 +145,33 @@ gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[70], d double shift_z = q[7]; double spatial_metric[3][3]; - spatial_metric[0][0] = q[8]; spatial_metric[0][1] = q[9]; spatial_metric[0][2] = q[10]; - spatial_metric[1][0] = q[11]; spatial_metric[1][1] = q[12]; spatial_metric[1][2] = q[13]; - spatial_metric[2][0] = q[14]; spatial_metric[2][1] = q[15]; spatial_metric[2][2] = q[16]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = q[8]; + spatial_metric[0][1] = q[9]; + spatial_metric[0][2] = q[10]; + spatial_metric[1][0] = q[11]; + spatial_metric[1][1] = q[12]; + spatial_metric[1][2] = q[13]; + spatial_metric[2][0] = q[14]; + spatial_metric[2][1] = q[15]; + spatial_metric[2][2] = q[16]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } gkyl_gr_ultra_rel_euler_tetrad_inv_spatial_metric(q, &inv_spatial_metric); - + double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = q[17]; extrinsic_curvature[0][1] = q[18]; extrinsic_curvature[0][2] = q[19]; - extrinsic_curvature[1][0] = q[20]; extrinsic_curvature[1][1] = q[21]; extrinsic_curvature[1][2] = q[22]; - extrinsic_curvature[2][0] = q[23]; extrinsic_curvature[2][1] = q[24]; extrinsic_curvature[2][2] = q[25]; + extrinsic_curvature[0][0] = q[17]; + extrinsic_curvature[0][1] = q[18]; + extrinsic_curvature[0][2] = q[19]; + extrinsic_curvature[1][0] = q[20]; + extrinsic_curvature[1][1] = q[21]; + extrinsic_curvature[1][2] = q[22]; + extrinsic_curvature[2][0] = q[23]; + extrinsic_curvature[2][1] = q[24]; + extrinsic_curvature[2][2] = q[25]; double lapse_der[3]; lapse_der[0] = q[27]; @@ -150,22 +179,46 @@ gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[70], d lapse_der[2] = q[29]; double shift_der[3][3]; - shift_der[0][0] = q[30]; shift_der[0][1] = q[31]; shift_der[0][2] = q[32]; - shift_der[1][0] = q[33]; shift_der[1][1] = q[34]; shift_der[1][2] = q[35]; - shift_der[2][0] = q[36]; shift_der[2][1] = q[37]; shift_der[2][2] = q[38]; + shift_der[0][0] = q[30]; + shift_der[0][1] = q[31]; + shift_der[0][2] = q[32]; + shift_der[1][0] = q[33]; + shift_der[1][1] = q[34]; + shift_der[1][2] = q[35]; + shift_der[2][0] = q[36]; + shift_der[2][1] = q[37]; + shift_der[2][2] = q[38]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = q[39]; spatial_metric_der[0][0][1] = q[40]; spatial_metric_der[0][0][2] = q[41]; - spatial_metric_der[0][1][0] = q[42]; spatial_metric_der[0][1][1] = q[43]; spatial_metric_der[0][1][2] = q[44]; - spatial_metric_der[0][2][0] = q[45]; spatial_metric_der[0][2][1] = q[46]; spatial_metric_der[0][2][2] = q[47]; - - spatial_metric_der[1][0][0] = q[48]; spatial_metric_der[1][0][1] = q[49]; spatial_metric_der[1][0][2] = q[50]; - spatial_metric_der[1][1][0] = q[51]; spatial_metric_der[1][1][1] = q[52]; spatial_metric_der[1][1][2] = q[53]; - spatial_metric_der[1][2][0] = q[54]; spatial_metric_der[1][2][1] = q[55]; spatial_metric_der[1][2][2] = q[56]; - - spatial_metric_der[0][0][0] = q[57]; spatial_metric_der[0][0][1] = q[58]; spatial_metric_der[0][0][2] = q[59]; - spatial_metric_der[0][1][0] = q[60]; spatial_metric_der[0][1][1] = q[61]; spatial_metric_der[0][1][2] = q[62]; - spatial_metric_der[0][2][0] = q[63]; spatial_metric_der[0][2][1] = q[64]; spatial_metric_der[0][2][2] = q[65]; + spatial_metric_der[0][0][0] = q[39]; + spatial_metric_der[0][0][1] = q[40]; + spatial_metric_der[0][0][2] = q[41]; + spatial_metric_der[0][1][0] = q[42]; + spatial_metric_der[0][1][1] = q[43]; + spatial_metric_der[0][1][2] = q[44]; + spatial_metric_der[0][2][0] = q[45]; + spatial_metric_der[0][2][1] = q[46]; + spatial_metric_der[0][2][2] = q[47]; + + spatial_metric_der[1][0][0] = q[48]; + spatial_metric_der[1][0][1] = q[49]; + spatial_metric_der[1][0][2] = q[50]; + spatial_metric_der[1][1][0] = q[51]; + spatial_metric_der[1][1][1] = q[52]; + spatial_metric_der[1][1][2] = q[53]; + spatial_metric_der[1][2][0] = q[54]; + spatial_metric_der[1][2][1] = q[55]; + spatial_metric_der[1][2][2] = q[56]; + + spatial_metric_der[0][0][0] = q[57]; + spatial_metric_der[0][0][1] = q[58]; + spatial_metric_der[0][0][2] = q[59]; + spatial_metric_der[0][1][0] = q[60]; + spatial_metric_der[0][1][1] = q[61]; + spatial_metric_der[0][1][2] = q[62]; + spatial_metric_der[0][2][0] = q[63]; + spatial_metric_der[0][2][1] = q[64]; + spatial_metric_der[0][2][2] = q[65]; double evol_param = q[66]; double x = q[67]; @@ -178,9 +231,12 @@ gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[70], d } if (!in_excision_region) { - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); double Etot = q[0] / sqrt(spatial_det); double momx = q[1] / sqrt(spatial_det); @@ -189,7 +245,9 @@ gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[70], d double mom[3]; double mom_sq = 0.0; - mom[0] = momx; mom[1] = momy; mom[2] = momz; + mom[0] = momx; + mom[1] = momy; + mom[2] = momz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -198,7 +256,9 @@ gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[70], d } double beta = 0.25 * (2.0 - gas_gamma); - double p = -(2.0 * beta * Etot) + sqrt((4.0 * (beta * beta) * (Etot * Etot)) + ((gas_gamma - 1.0) * ((Etot * Etot) - mom_sq))); + double p = + -(2.0 * beta * Etot) + + sqrt((4.0 * (beta * beta) * (Etot * Etot)) + ((gas_gamma - 1.0) * ((Etot * Etot) - mom_sq))); if (p < pow(10.0, -8.0)) { p = pow(10.0, -8.0); } @@ -225,7 +285,9 @@ gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[70], d } double cov_vel[3]; - cov_vel[0] = cov_vx; cov_vel[1] = cov_vy; cov_vel[2] = cov_vz; + cov_vel[0] = cov_vx; + cov_vel[1] = cov_vy; + cov_vel[2] = cov_vz; double vel[3]; for (int i = 0; i < 3; i++) { @@ -246,13 +308,25 @@ gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[70], d v[6] = shift_y; v[7] = shift_z; - v[8] = spatial_metric[0][0]; v[9] = spatial_metric[0][1]; v[10] = spatial_metric[0][2]; - v[11] = spatial_metric[1][0]; v[12] = spatial_metric[1][1]; v[13] = spatial_metric[1][2]; - v[14] = spatial_metric[2][0]; v[15] = spatial_metric[2][1]; v[16] = spatial_metric[2][2]; - - v[17] = extrinsic_curvature[0][0]; v[18] = extrinsic_curvature[0][1]; v[19] = extrinsic_curvature[0][2]; - v[20] = extrinsic_curvature[1][0]; v[21] = extrinsic_curvature[1][1]; v[22] = extrinsic_curvature[1][2]; - v[23] = extrinsic_curvature[2][0]; v[24] = extrinsic_curvature[2][1]; v[25] = extrinsic_curvature[2][2]; + v[8] = spatial_metric[0][0]; + v[9] = spatial_metric[0][1]; + v[10] = spatial_metric[0][2]; + v[11] = spatial_metric[1][0]; + v[12] = spatial_metric[1][1]; + v[13] = spatial_metric[1][2]; + v[14] = spatial_metric[2][0]; + v[15] = spatial_metric[2][1]; + v[16] = spatial_metric[2][2]; + + v[17] = extrinsic_curvature[0][0]; + v[18] = extrinsic_curvature[0][1]; + v[19] = extrinsic_curvature[0][2]; + v[20] = extrinsic_curvature[1][0]; + v[21] = extrinsic_curvature[1][1]; + v[22] = extrinsic_curvature[1][2]; + v[23] = extrinsic_curvature[2][0]; + v[24] = extrinsic_curvature[2][1]; + v[25] = extrinsic_curvature[2][2]; v[26] = 1.0; @@ -260,28 +334,51 @@ gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[70], d v[28] = lapse_der[1]; v[29] = lapse_der[2]; - v[30] = shift_der[0][0]; v[31] = shift_der[0][1]; v[32] = shift_der[0][2]; - v[33] = shift_der[1][0]; v[34] = shift_der[1][1]; v[35] = shift_der[1][2]; - v[36] = shift_der[2][0]; v[37] = shift_der[2][1]; v[38] = shift_der[2][2]; - - v[39] = spatial_metric_der[0][0][0]; v[40] = spatial_metric_der[0][0][1]; v[41] = spatial_metric_der[0][0][2]; - v[42] = spatial_metric_der[0][1][0]; v[43] = spatial_metric_der[0][1][1]; v[44] = spatial_metric_der[0][1][2]; - v[45] = spatial_metric_der[0][2][0]; v[46] = spatial_metric_der[0][2][1]; v[47] = spatial_metric_der[0][2][2]; - - v[48] = spatial_metric_der[1][0][0]; v[49] = spatial_metric_der[1][0][1]; v[50] = spatial_metric_der[1][0][2]; - v[51] = spatial_metric_der[1][1][0]; v[52] = spatial_metric_der[1][1][1]; v[53] = spatial_metric_der[1][1][2]; - v[54] = spatial_metric_der[1][2][0]; v[55] = spatial_metric_der[1][2][1]; v[56] = spatial_metric_der[1][2][2]; - - v[57] = spatial_metric_der[2][0][0]; v[58] = spatial_metric_der[2][0][1]; v[59] = spatial_metric_der[2][0][2]; - v[60] = spatial_metric_der[2][1][0]; v[61] = spatial_metric_der[2][1][1]; v[62] = spatial_metric_der[2][1][2]; - v[63] = spatial_metric_der[2][2][0]; v[64] = spatial_metric_der[2][2][1]; v[65] = spatial_metric_der[2][2][2]; + v[30] = shift_der[0][0]; + v[31] = shift_der[0][1]; + v[32] = shift_der[0][2]; + v[33] = shift_der[1][0]; + v[34] = shift_der[1][1]; + v[35] = shift_der[1][2]; + v[36] = shift_der[2][0]; + v[37] = shift_der[2][1]; + v[38] = shift_der[2][2]; + + v[39] = spatial_metric_der[0][0][0]; + v[40] = spatial_metric_der[0][0][1]; + v[41] = spatial_metric_der[0][0][2]; + v[42] = spatial_metric_der[0][1][0]; + v[43] = spatial_metric_der[0][1][1]; + v[44] = spatial_metric_der[0][1][2]; + v[45] = spatial_metric_der[0][2][0]; + v[46] = spatial_metric_der[0][2][1]; + v[47] = spatial_metric_der[0][2][2]; + + v[48] = spatial_metric_der[1][0][0]; + v[49] = spatial_metric_der[1][0][1]; + v[50] = spatial_metric_der[1][0][2]; + v[51] = spatial_metric_der[1][1][0]; + v[52] = spatial_metric_der[1][1][1]; + v[53] = spatial_metric_der[1][1][2]; + v[54] = spatial_metric_der[1][2][0]; + v[55] = spatial_metric_der[1][2][1]; + v[56] = spatial_metric_der[1][2][2]; + + v[57] = spatial_metric_der[2][0][0]; + v[58] = spatial_metric_der[2][0][1]; + v[59] = spatial_metric_der[2][0][2]; + v[60] = spatial_metric_der[2][1][0]; + v[61] = spatial_metric_der[2][1][1]; + v[62] = spatial_metric_der[2][1][2]; + v[63] = spatial_metric_der[2][2][0]; + v[64] = spatial_metric_der[2][2][1]; + v[65] = spatial_metric_der[2][2][2]; v[66] = evol_param; v[67] = x; v[68] = y; v[69] = z; - } - else { + } else { for (int i = 0; i < 70; i++) { v[i] = 0.0; } @@ -295,18 +392,28 @@ gkyl_gr_ultra_rel_euler_tetrad_prim_vars(double gas_gamma, const double q[70], d gkyl_free(inv_spatial_metric); } -void -gkyl_gr_ultra_rel_euler_tetrad_inv_spatial_metric(const double q[70], double ***inv_spatial_metric) +void gkyl_gr_ultra_rel_euler_tetrad_inv_spatial_metric( + const double q[70], double ***inv_spatial_metric +) { double spatial_metric[3][3]; - spatial_metric[0][0] = q[8]; spatial_metric[0][1] = q[9]; spatial_metric[0][2] = q[10]; - spatial_metric[1][0] = q[11]; spatial_metric[1][1] = q[12]; spatial_metric[1][2] = q[13]; - spatial_metric[2][0] = q[14]; spatial_metric[2][1] = q[15]; spatial_metric[2][2] = q[16]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = q[8]; + spatial_metric[0][1] = q[9]; + spatial_metric[0][2] = q[10]; + spatial_metric[1][0] = q[11]; + spatial_metric[1][1] = q[12]; + spatial_metric[1][2] = q[13]; + spatial_metric[2][0] = q[14]; + spatial_metric[2][1] = q[15]; + spatial_metric[2][2] = q[16]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -337,8 +444,7 @@ gkyl_gr_ultra_rel_euler_tetrad_inv_spatial_metric(const double q[70], double *** for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -346,16 +452,18 @@ gkyl_gr_ultra_rel_euler_tetrad_inv_spatial_metric(const double q[70], double *** for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*inv_spatial_metric)[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*inv_spatial_metric)[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } } -void -gkyl_gr_ultra_rel_euler_tetrad_stress_energy_tensor(double gas_gamma, const double q[70], double ***stress_energy) +void gkyl_gr_ultra_rel_euler_tetrad_stress_energy_tensor( + double gas_gamma, const double q[70], double ***stress_energy +) { - double v[70] = { 0.0 }; + double v[70] = {0.0}; gkyl_gr_ultra_rel_euler_tetrad_prim_vars(gas_gamma, q, v); double rho = v[0]; double vx = v[1]; @@ -369,11 +477,17 @@ gkyl_gr_ultra_rel_euler_tetrad_stress_energy_tensor(double gas_gamma, const doub double shift_z = v[7]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[8]; spatial_metric[0][1] = v[9]; spatial_metric[0][2] = v[10]; - spatial_metric[1][0] = v[11]; spatial_metric[1][1] = v[12]; spatial_metric[1][2] = v[13]; - spatial_metric[2][0] = v[14]; spatial_metric[2][1] = v[15]; spatial_metric[2][2] = v[16]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[8]; + spatial_metric[0][1] = v[9]; + spatial_metric[0][2] = v[10]; + spatial_metric[1][0] = v[11]; + spatial_metric[1][1] = v[12]; + spatial_metric[1][2] = v[13]; + spatial_metric[2][0] = v[14]; + spatial_metric[2][1] = v[15]; + spatial_metric[2][2] = v[16]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -388,7 +502,9 @@ gkyl_gr_ultra_rel_euler_tetrad_stress_energy_tensor(double gas_gamma, const doub if (!in_excision_region) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -410,27 +526,30 @@ gkyl_gr_ultra_rel_euler_tetrad_stress_energy_tensor(double gas_gamma, const doub spacetime_vel[3] = (W * vz) - (shift_z * (W / lapse)); double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double inv_spacetime_metric[4][4]; - inv_spacetime_metric[0][0] = - (1.0 / (lapse * lapse)); + inv_spacetime_metric[0][0] = -(1.0 / (lapse * lapse)); for (int i = 0; i < 3; i++) { inv_spacetime_metric[0][i] = (1.0 / (lapse * lapse)) * shift[i]; inv_spacetime_metric[i][0] = (1.0 / (lapse * lapse)) * shift[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - inv_spacetime_metric[i][j] = inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); + inv_spacetime_metric[i][j] = + inv_spatial_metric[i][j] - ((1.0 / (lapse * lapse)) * shift[i] * shift[j]); } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - (*stress_energy)[i][j] = (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); + (*stress_energy)[i][j] = + (rho * h * spacetime_vel[i] * spacetime_vel[j]) + (p * inv_spacetime_metric[i][j]); } } - } - else { + } else { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { (*stress_energy)[i][j] = 0.0; @@ -447,7 +566,7 @@ gkyl_gr_ultra_rel_euler_tetrad_stress_energy_tensor(double gas_gamma, const doub static inline double gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(double gas_gamma, const double q[70]) { - double v[70] = { 0.0 }; + double v[70] = {0.0}; gkyl_gr_ultra_rel_euler_tetrad_prim_vars(gas_gamma, q, v); double vx = v[1]; double vy = v[2]; @@ -459,11 +578,17 @@ gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(double gas_gamma, const double q[70 double shift_z = v[7]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[8]; spatial_metric[0][1] = v[9]; spatial_metric[0][2] = v[10]; - spatial_metric[1][0] = v[11]; spatial_metric[1][1] = v[12]; spatial_metric[1][2] = v[13]; - spatial_metric[2][0] = v[14]; spatial_metric[2][1] = v[15]; spatial_metric[2][2] = v[16]; - - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + spatial_metric[0][0] = v[8]; + spatial_metric[0][1] = v[9]; + spatial_metric[0][2] = v[10]; + spatial_metric[1][0] = v[11]; + spatial_metric[1][1] = v[12]; + spatial_metric[1][2] = v[13]; + spatial_metric[2][0] = v[14]; + spatial_metric[2][1] = v[15]; + spatial_metric[2][2] = v[16]; + + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -484,16 +609,15 @@ gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(double gas_gamma, const double q[70 if (fabs(spatial_metric[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime = true; } - } - else { + } else { if (fabs(spatial_metric[i][j]) > pow(10.0, -8.0)) { curved_spacetime = true; } } } } - if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || fabs(shift_y) > pow(10.0, -8.0) || - fabs(shift_z) > pow(10.0, -8.0)) { + if (fabs(lapse - 1.0) > pow(10.0, -8.0) || fabs(shift_x) > pow(10.0, -8.0) || + fabs(shift_y) > pow(10.0, -8.0) || fabs(shift_z) > pow(10.0, -8.0)) { curved_spacetime = true; } @@ -501,7 +625,9 @@ gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(double gas_gamma, const double q[70 if (curved_spacetime) { double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -510,7 +636,9 @@ gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(double gas_gamma, const double q[70 } double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double material_eigs[3]; double fast_acoustic_eigs[3]; @@ -519,11 +647,23 @@ gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(double gas_gamma, const double q[70 for (int i = 0; i < 3; i++) { material_eigs[i] = (lapse * vel[i]) - shift[i]; - fast_acoustic_eigs[i] = (lapse / (1.0 - (v_sq * (c_s * c_s)))) * ((vel[i] * (1.0 - (c_s * c_s))) + - (c_s * sqrt((1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - (vel[i] * vel[i]) * (1.0 - (c_s * c_s)))))) - shift[i]; - - slow_acoustic_eigs[i] = (lapse / (1.0 - (v_sq * (c_s * c_s)))) * ((vel[i] * (1.0 - (c_s * c_s))) - - (c_s * sqrt((1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - (vel[i] * vel[i]) * (1.0 - (c_s * c_s)))))) - shift[i]; + fast_acoustic_eigs[i] = + (lapse / (1.0 - (v_sq * (c_s * c_s)))) * + ((vel[i] * (1.0 - (c_s * c_s))) + + (c_s * sqrt( + (1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - + (vel[i] * vel[i]) * (1.0 - (c_s * c_s))) + ))) - + shift[i]; + + slow_acoustic_eigs[i] = + (lapse / (1.0 - (v_sq * (c_s * c_s)))) * + ((vel[i] * (1.0 - (c_s * c_s))) - + (c_s * sqrt( + (1.0 - v_sq) * (inv_spatial_metric[i][i] * (1.0 - (v_sq * (c_s * c_s))) - + (vel[i] * vel[i]) * (1.0 - (c_s * c_s))) + ))) - + shift[i]; } double max_eig = 0.0; @@ -545,8 +685,7 @@ gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(double gas_gamma, const double q[70 gkyl_free(inv_spatial_metric); return fabs(v_sq) + max_eig; - } - else { + } else { double v_sq = sqrt((vx * vx) + (vy * vy) + (vz * vz)); for (int i = 0; i < 3; i++) { @@ -556,8 +695,7 @@ gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(double gas_gamma, const double q[70 return fabs(v_sq) + c_s; } - } - else { + } else { for (int i = 0; i < 3; i++) { gkyl_free(inv_spatial_metric[i]); } @@ -568,7 +706,7 @@ gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(double gas_gamma, const double q[70 } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 70; i++) { @@ -577,7 +715,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 70; i++) { @@ -585,8 +723,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -gr_ultra_rel_euler_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_ultra_rel_euler_tetrad_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 0; i < 70; i++) { ghost[i] = skin[i]; @@ -595,8 +735,10 @@ gr_ultra_rel_euler_tetrad_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, ghost[1] = -ghost[1]; } -static void -gr_ultra_rel_euler_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void gr_ultra_rel_euler_tetrad_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 1; i < 4; i++) { ghost[i] = -skin[i]; @@ -609,9 +751,10 @@ gr_ultra_rel_euler_tetrad_no_slip(const struct gkyl_wv_eqn* eqn, double t, int n } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; qlocal[1] = (qglobal[1] * norm[0]) + (qglobal[2] * norm[1]) + (qglobal[3] * norm[2]); @@ -652,9 +795,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinate frame. - qlocal[8] = v1[0]; qlocal[9] = v1[1]; qlocal[10] = v1[2]; - qlocal[11] = v2[0]; qlocal[12] = v2[1]; qlocal[13] = v2[2]; - qlocal[14] = v3[0]; qlocal[15] = v3[1]; qlocal[16] = v3[2]; + qlocal[8] = v1[0]; + qlocal[9] = v1[1]; + qlocal[10] = v1[2]; + qlocal[11] = v2[0]; + qlocal[12] = v2[1]; + qlocal[13] = v2[2]; + qlocal[14] = v3[0]; + qlocal[15] = v3[1]; + qlocal[16] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -685,9 +834,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta inv_v3[2] = (extr_r1[2] * tau2[0]) + (extr_r2[2] * tau2[1]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor to local coordinate frame. - qlocal[17] = inv_v1[0]; qlocal[18] = inv_v1[1]; qlocal[19] = inv_v1[2]; - qlocal[20] = inv_v2[0]; qlocal[21] = inv_v2[1]; qlocal[22] = inv_v2[2]; - qlocal[23] = inv_v3[0]; qlocal[24] = inv_v3[1]; qlocal[25] = inv_v3[2]; + qlocal[17] = inv_v1[0]; + qlocal[18] = inv_v1[1]; + qlocal[19] = inv_v1[2]; + qlocal[20] = inv_v2[0]; + qlocal[21] = inv_v2[1]; + qlocal[22] = inv_v2[2]; + qlocal[23] = inv_v3[0]; + qlocal[24] = inv_v3[1]; + qlocal[25] = inv_v3[2]; qlocal[26] = qglobal[26]; @@ -711,22 +866,37 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); - shiftder_v1[1] = (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); - shiftder_v1[2] = (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); - shiftder_v2[1] = (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); - shiftder_v2[2] = (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); - shiftder_v3[1] = (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); - shiftder_v3[2] = (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); + shiftder_v1[1] = + (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); + shiftder_v1[2] = + (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); + shiftder_v2[1] = + (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); + shiftder_v2[2] = + (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); + shiftder_v3[1] = + (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); + shiftder_v3[2] = + (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative to local coordinate frame. - qlocal[30] = shiftder_v1[0]; qlocal[31] = shiftder_v1[1]; qlocal[32] = shiftder_v1[2]; - qlocal[33] = shiftder_v2[0]; qlocal[34] = shiftder_v2[1]; qlocal[35] = shiftder_v2[2]; - qlocal[36] = shiftder_v3[0]; qlocal[37] = shiftder_v3[1]; qlocal[38] = shiftder_v3[2]; + qlocal[30] = shiftder_v1[0]; + qlocal[31] = shiftder_v1[1]; + qlocal[32] = shiftder_v1[2]; + qlocal[33] = shiftder_v2[0]; + qlocal[34] = shiftder_v2[1]; + qlocal[35] = shiftder_v2[2]; + qlocal[36] = shiftder_v3[0]; + qlocal[37] = shiftder_v3[1]; + qlocal[38] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -809,7 +979,7 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta s33[0] = (r31[0] * tau2[0]) + (r32[0] * tau2[1]) + (r33[0] * tau2[2]); s33[1] = (r31[1] * tau2[0]) + (r32[1] * tau2[1]) + (r33[1] * tau2[2]); s33[2] = (r31[2] * tau2[0]) + (r32[2] * tau2[1]) + (r33[2] * tau2[2]); - + // Rotate spatial metric tensor derivative to local coordinate frame. qlocal[39] = (s11[0] * norm[0]) + (s21[0] * norm[1]) + (s31[0] * norm[2]); qlocal[40] = (s11[1] * norm[0]) + (s21[1] * norm[1]) + (s31[1] * norm[2]); @@ -853,9 +1023,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[69] = (qglobal[67] * tau2[0]) + (qglobal[68] * tau2[1]) + (qglobal[69] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; qglobal[1] = (qlocal[1] * norm[0]) + (qlocal[2] * tau1[0]) + (qlocal[3] * tau2[0]); @@ -896,9 +1067,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor back to global coordinate frame. - qglobal[8] = v1[0]; qglobal[9] = v1[1]; qglobal[10] = v1[2]; - qglobal[11] = v2[0]; qglobal[12] = v2[1]; qglobal[13] = v2[2]; - qglobal[14] = v3[0]; qglobal[15] = v3[1]; qglobal[16] = v3[2]; + qglobal[8] = v1[0]; + qglobal[9] = v1[1]; + qglobal[10] = v1[2]; + qglobal[11] = v2[0]; + qglobal[12] = v2[1]; + qglobal[13] = v2[2]; + qglobal[14] = v3[0]; + qglobal[15] = v3[1]; + qglobal[16] = v3[2]; // Temporary arrays to store rotated extrinsic column vectors. double extr_r1[3], extr_r2[3], extr_r3[3]; @@ -929,9 +1106,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t inv_v3[2] = (extr_r1[2] * norm[2]) + (extr_r2[2] * tau1[2]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor back to global coordinate frame. - qglobal[17] = inv_v1[0]; qglobal[18] = inv_v1[1]; qglobal[19] = inv_v1[2]; - qglobal[20] = inv_v2[0]; qglobal[21] = inv_v2[1]; qglobal[22] = inv_v2[2]; - qglobal[23] = inv_v3[0]; qglobal[24] = inv_v3[1]; qglobal[25] = inv_v3[2]; + qglobal[17] = inv_v1[0]; + qglobal[18] = inv_v1[1]; + qglobal[19] = inv_v1[2]; + qglobal[20] = inv_v2[0]; + qglobal[21] = inv_v2[1]; + qglobal[22] = inv_v2[2]; + qglobal[23] = inv_v3[0]; + qglobal[24] = inv_v3[1]; + qglobal[25] = inv_v3[2]; qglobal[26] = qlocal[26]; @@ -955,22 +1138,37 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); - shiftder_v1[1] = (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); - shiftder_v1[2] = (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); - shiftder_v2[1] = (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); - shiftder_v2[2] = (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); - shiftder_v3[1] = (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); - shiftder_v3[2] = (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); + shiftder_v1[1] = + (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); + shiftder_v1[2] = + (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); + shiftder_v2[1] = + (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); + shiftder_v2[2] = + (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); + shiftder_v3[1] = + (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); + shiftder_v3[2] = + (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative back to global coordinate frame. - qglobal[30] = shiftder_v1[0]; qglobal[31] = shiftder_v1[1]; qglobal[32] = shiftder_v1[2]; - qglobal[33] = shiftder_v2[0]; qglobal[34] = shiftder_v2[1]; qglobal[35] = shiftder_v2[2]; - qglobal[36] = shiftder_v3[0]; qglobal[37] = shiftder_v3[1]; qglobal[38] = shiftder_v3[2]; + qglobal[30] = shiftder_v1[0]; + qglobal[31] = shiftder_v1[1]; + qglobal[32] = shiftder_v1[2]; + qglobal[33] = shiftder_v2[0]; + qglobal[34] = shiftder_v2[1]; + qglobal[35] = shiftder_v2[2]; + qglobal[36] = shiftder_v3[0]; + qglobal[37] = shiftder_v3[1]; + qglobal[38] = shiftder_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -1097,10 +1295,13 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[69] = (qlocal[67] * norm[2]) + (qlocal[68] * tau1[2]) + (qlocal[69] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); double gas_gamma = gr_ultra_rel_euler_tetrad->gas_gamma; double sl = gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(gas_gamma, ql); @@ -1131,8 +1332,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr_gr[i] - fl_gr[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr_gr[i] - fl_gr[i]) / amax); } - } - else { + } else { for (int i = 0; i < 70; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1145,8 +1345,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[70]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1158,26 +1360,33 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); double vl[70], vr[70]; double gas_gamma = gr_ultra_rel_euler_tetrad->gas_gamma; - + gkyl_gr_ultra_rel_euler_tetrad_prim_vars(gas_gamma, ql, vl); gkyl_gr_ultra_rel_euler_tetrad_prim_vars(gas_gamma, qr, vr); @@ -1212,15 +1421,21 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double c_plus = 1.0 + ((gas_gamma / (gas_gamma - 1.0)) * v0); double v_alpha_sq = -(v0 * v0) + (v1 * v1) + (v2 * v2) + (v3 * v3); - double s_sq = (0.5 * gas_gamma * v0 * (1.0 - v_alpha_sq)) - (0.5 * (gas_gamma - 1.0) * (1.0 + v_alpha_sq)); + double s_sq = + (0.5 * gas_gamma * v0 * (1.0 - v_alpha_sq)) - (0.5 * (gas_gamma - 1.0) * (1.0 + v_alpha_sq)); double energy = (v0 * v0) - (v1 * v1); double y = sqrt(((1.0 - (gas_gamma * v0)) * energy) + s_sq); double k = (v0 * delta[4]) - (v1 * delta[1]); double v_delta = (-v0 * delta[0]) + (v1 * delta[1]) + (v2 * delta[2]) + (v3 * delta[3]); - double a1 = -((s_sq * k) + (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[0])) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / (2.0 * energy * s_sq); - double a2 = -((s_sq * k) - (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[0])) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / (2.0 * energy * s_sq); - double a3 = ((2.0 * s_sq * k) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta)))) / (energy * s_sq); + double a1 = -((s_sq * k) + (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[0])) + + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / + (2.0 * energy * s_sq); + double a2 = -((s_sq * k) - (sqrt(s_sq) * y * ((v0 * delta[1]) - (v1 * delta[0])) + + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta))))) / + (2.0 * energy * s_sq); + double a3 = ((2.0 * s_sq * k) + ((gas_gamma - 1.0) * energy * (delta[0] + (c_plus * v_delta)))) / + (energy * s_sq); double a4 = delta[2] - ((k * v2) / energy); double a5 = delta[3] - ((k * v3) / energy); @@ -1234,7 +1449,8 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c wv[1] = a1 * (v1 - ((sqrt(s_sq) * v0) / y)); wv[2] = a1 * v2; wv[3] = a1 * v3; - s[0] = (((1.0 - (gas_gamma * v0)) * v0 * v1) - (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); + s[0] = (((1.0 - (gas_gamma * v0)) * v0 * v1) - (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); wv = &waves[1 * 70]; wv[0] = a3 * v0; @@ -1248,17 +1464,21 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c wv[1] = a2 * (v1 + ((sqrt(s_sq) * v0) / y)); wv[2] = a2 * v2; wv[3] = a2 * v3; - s[2] = (((1.0 - (gas_gamma * v0)) * v0 * v1) + (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); + s[2] = (((1.0 - (gas_gamma * v0)) * v0 * v1) + (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); - return (((1.0 - (gas_gamma * v0)) * v0 * fabs(v1)) + (sqrt(s_sq) * y)) / (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); + return (((1.0 - (gas_gamma * v0)) * v0 * fabs(v1)) + (sqrt(s_sq) * y)) / + (((1.0 - (gas_gamma * v0)) * v0 * v0) + s_sq); } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { - const double* w0 = &waves[0 * 70]; - const double* w1 = &waves[1 * 70]; - const double* w2 = &waves[2 * 70]; + const double *w0 = &waves[0 * 70]; + const double *w1 = &waves[1 * 70]; + const double *w2 = &waves[2 * 70]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]); @@ -1273,33 +1493,38 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } } -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); double gas_gamma = gr_ultra_rel_euler_tetrad->gas_gamma; double vl[70], vr[70]; @@ -1317,11 +1542,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_zl = vl[7]; double spatial_metric_l[3][3]; - spatial_metric_l[0][0] = vl[8]; spatial_metric_l[0][1] = vl[9]; spatial_metric_l[0][2] = vl[10]; - spatial_metric_l[1][0] = vl[11]; spatial_metric_l[1][1] = vl[12]; spatial_metric_l[1][2] = vl[13]; - spatial_metric_l[2][0] = vl[14]; spatial_metric_l[2][1] = vl[15]; spatial_metric_l[2][2] = vl[16]; - - double **inv_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); + spatial_metric_l[0][0] = vl[8]; + spatial_metric_l[0][1] = vl[9]; + spatial_metric_l[0][2] = vl[10]; + spatial_metric_l[1][0] = vl[11]; + spatial_metric_l[1][1] = vl[12]; + spatial_metric_l[1][2] = vl[13]; + spatial_metric_l[2][0] = vl[14]; + spatial_metric_l[2][1] = vl[15]; + spatial_metric_l[2][2] = vl[16]; + + double **inv_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); } @@ -1340,16 +1571,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_l[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_l = true; } - } - else { + } else { if (fabs(spatial_metric_l[i][j]) > pow(10.0, -8.0)) { curved_spacetime_l = true; } } } } - if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_xl) > pow(10.0, -8.0) || fabs(shift_yl) > pow(10.0, -8.0) || - fabs(shift_zl) > pow(10.0, -8.0)) { + if (fabs(lapse_l - 1.0) > pow(10.0, -8.0) || fabs(shift_xl) > pow(10.0, -8.0) || + fabs(shift_yl) > pow(10.0, -8.0) || fabs(shift_zl) > pow(10.0, -8.0)) { curved_spacetime_l = true; } @@ -1364,11 +1594,17 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double shift_zr = vr[7]; double spatial_metric_r[3][3]; - spatial_metric_r[0][0] = vr[8]; spatial_metric_r[0][1] = vr[9]; spatial_metric_r[0][2] = vr[10]; - spatial_metric_r[1][0] = vr[11]; spatial_metric_r[1][1] = vr[12]; spatial_metric_r[1][2] = vr[13]; - spatial_metric_r[2][0] = vr[14]; spatial_metric_r[2][1] = vr[15]; spatial_metric_r[2][2] = vr[16]; - - double **inv_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + spatial_metric_r[0][0] = vr[8]; + spatial_metric_r[0][1] = vr[9]; + spatial_metric_r[0][2] = vr[10]; + spatial_metric_r[1][0] = vr[11]; + spatial_metric_r[1][1] = vr[12]; + spatial_metric_r[1][2] = vr[13]; + spatial_metric_r[2][0] = vr[14]; + spatial_metric_r[2][1] = vr[15]; + spatial_metric_r[2][2] = vr[16]; + + double **inv_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } @@ -1387,16 +1623,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (fabs(spatial_metric_r[i][j] - 1.0) > pow(10.0, -8.0)) { curved_spacetime_r = true; } - } - else { + } else { if (fabs(spatial_metric_l[i][j]) > pow(10.0, -8.0)) { curved_spacetime_r = true; } } } } - if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_xr) > pow(10.0, -8.0) || fabs(shift_yr) > pow(10.0, -8.0) || - fabs(shift_zr) > pow(10.0, -8.0)) { + if (fabs(lapse_r - 1.0) > pow(10.0, -8.0) || fabs(shift_xr) > pow(10.0, -8.0) || + fabs(shift_yr) > pow(10.0, -8.0) || fabs(shift_zr) > pow(10.0, -8.0)) { curved_spacetime_r = true; } @@ -1411,7 +1646,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c if (curved_spacetime_l || curved_spacetime_r) { double vel_l[3]; double v_sq_l = 0.0; - vel_l[0] = vx_l; vel_l[1] = vy_l; vel_l[2] = vz_l; + vel_l[0] = vx_l; + vel_l[1] = vy_l; + vel_l[2] = vz_l; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1420,7 +1657,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_l[3]; - shift_l[0] = shift_xl; shift_l[1] = shift_yl; shift_l[2] = shift_zl; + shift_l[0] = shift_xl; + shift_l[1] = shift_yl; + shift_l[2] = shift_zl; double material_eigs_l[3]; double fast_acoustic_eigs_l[3]; @@ -1429,11 +1668,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_l[i] = (lapse_l * vel_l[i]) - shift_l[i]; - fast_acoustic_eigs_l[i] = (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * ((vel_l[i] * (1.0 - (c_sl * c_sl))) + - (c_sl * sqrt((1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl)))))) - shift_l[i]; - - slow_acoustic_eigs_l[i] = (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * ((vel_l[i] * (1.0 - (c_sl * c_sl))) - - (c_sl * sqrt((1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl)))))) - shift_l[i]; + fast_acoustic_eigs_l[i] = + (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * + ((vel_l[i] * (1.0 - (c_sl * c_sl))) + + (c_sl * + sqrt( + (1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - + (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_l[i]; + + slow_acoustic_eigs_l[i] = + (lapse_l / (1.0 - (v_sq_l * (c_sl * c_sl)))) * + ((vel_l[i] * (1.0 - (c_sl * c_sl))) - + (c_sl * + sqrt( + (1.0 - v_sq_l) * (inv_spatial_metric_l[i][i] * (1.0 - (v_sq_l * (c_sl * c_sl))) - + (vel_l[i] * vel_l[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_l[i]; } double max_eig_l = 0.0; @@ -1451,7 +1704,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vel_r[3]; double v_sq_r = 0.0; - vel_r[0] = vx_r; vel_r[1] = vy_r; vel_r[2] = vz_r; + vel_r[0] = vx_r; + vel_r[1] = vy_r; + vel_r[2] = vz_r; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1460,7 +1715,9 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double shift_r[3]; - shift_r[0] = shift_xr; shift_r[1] = shift_yr; shift_r[2] = shift_zr; + shift_r[0] = shift_xr; + shift_r[1] = shift_yr; + shift_r[2] = shift_zr; double material_eigs_r[3]; double fast_acoustic_eigs_r[3]; @@ -1469,11 +1726,25 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c for (int i = 0; i < 3; i++) { material_eigs_r[i] = (lapse_r * vel_r[i]) - shift_r[i]; - fast_acoustic_eigs_r[i] = (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * ((vel_r[i] * (1.0 - (c_sl * c_sl))) + - (c_sl * sqrt((1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl)))))) - shift_r[i]; - - slow_acoustic_eigs_r[i] = (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * ((vel_r[i] * (1.0 - (c_sl * c_sl))) - - (c_sl * sqrt((1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl)))))) - shift_r[i]; + fast_acoustic_eigs_r[i] = + (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * + ((vel_r[i] * (1.0 - (c_sl * c_sl))) + + (c_sl * + sqrt( + (1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - + (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_r[i]; + + slow_acoustic_eigs_r[i] = + (lapse_r / (1.0 - (v_sq_r * (c_sl * c_sl)))) * + ((vel_r[i] * (1.0 - (c_sl * c_sl))) - + (c_sl * + sqrt( + (1.0 - v_sq_r) * (inv_spatial_metric_r[i][i] * (1.0 - (v_sq_r * (c_sl * c_sl))) - + (vel_r[i] * vel_r[i]) * (1.0 - (c_sl * c_sl))) + ))) - + shift_r[i]; } double max_eig_r = 0.0; @@ -1490,11 +1761,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c } double max_eig_avg = 0.5 * (max_eig_l + max_eig_r); - + sl = (vx_avg - max_eig_avg) / (1.0 - (vx_avg * max_eig_avg)); sr = (vx_avg + max_eig_avg) / (1.0 + (vx_avg * max_eig_avg)); - } - else { + } else { sl = (vx_avg - cs_avg) / (1.0 - (vx_avg * cs_avg)); sr = (vx_avg + cs_avg) / (1.0 + (vx_avg * cs_avg)); } @@ -1518,8 +1788,7 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = qm[i] - ql[i]; w1[i] = qr[i] - qm[i]; } - } - else { + } else { for (int i = 0; i < 70; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1539,8 +1808,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return fmax(fabs(sl), fabs(sr)); } -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[70]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1552,35 +1823,38 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hll(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_hll(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); double gas_gamma = gr_ultra_rel_euler_tetrad->gas_gamma; double fr_sr[70], fl_sr[70]; @@ -1605,47 +1879,48 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 70; m++) { flux_jump[m] = fr_gr[m] - fl_gr[m]; } - } - else { + } else { for (int m = 0; m < 70; m++) { flux_jump[m] = 0.0; } } - double amaxl = gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(gr_ultra_rel_euler_tetrad->gas_gamma, ql); - double amaxr = gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(gr_ultra_rel_euler_tetrad->gas_gamma, qr); + double amaxl = + gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(gr_ultra_rel_euler_tetrad->gas_gamma, ql); + double amaxr = + gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(gr_ultra_rel_euler_tetrad->gas_gamma, qr); return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); double gas_gamma = gr_ultra_rel_euler_tetrad->gas_gamma; - double v[70] = { 0.0 }; + double v[70] = {0.0}; gkyl_gr_ultra_rel_euler_tetrad_prim_vars(gas_gamma, q, v); if (v[0] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); double gas_gamma = gr_ultra_rel_euler_tetrad->gas_gamma; return gkyl_gr_ultra_rel_euler_tetrad_max_abs_speed(gas_gamma, q); } -static inline void -gr_ultra_rel_euler_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +static inline void gr_ultra_rel_euler_tetrad_cons_to_diag( + const struct gkyl_wv_eqn *eqn, const double *qin, double *diag +) { for (int i = 0; i < 4; i++) { diag[i] = qin[i]; @@ -1653,12 +1928,13 @@ gr_ultra_rel_euler_tetrad_cons_to_diag(const struct gkyl_wv_eqn* eqn, const doub } static inline void -gr_ultra_rel_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +gr_ultra_rel_euler_tetrad_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); double gas_gamma = gr_ultra_rel_euler_tetrad->gas_gamma; - double v[70] = { 0.0 }; + double v[70] = {0.0}; gkyl_gr_ultra_rel_euler_tetrad_prim_vars(gas_gamma, qin, v); double rho = v[0]; double vx = v[1]; @@ -1672,14 +1948,26 @@ gr_ultra_rel_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qi double shift_z = v[7]; double spatial_metric[3][3]; - spatial_metric[0][0] = v[8]; spatial_metric[0][1] = v[9]; spatial_metric[0][2] = v[10]; - spatial_metric[1][0] = v[11]; spatial_metric[1][1] = v[12]; spatial_metric[1][2] = v[13]; - spatial_metric[2][0] = v[14]; spatial_metric[2][1] = v[15]; spatial_metric[2][2] = v[16]; + spatial_metric[0][0] = v[8]; + spatial_metric[0][1] = v[9]; + spatial_metric[0][2] = v[10]; + spatial_metric[1][0] = v[11]; + spatial_metric[1][1] = v[12]; + spatial_metric[1][2] = v[13]; + spatial_metric[2][0] = v[14]; + spatial_metric[2][1] = v[15]; + spatial_metric[2][2] = v[16]; double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = v[17]; extrinsic_curvature[0][1] = v[18]; extrinsic_curvature[0][2] = v[19]; - extrinsic_curvature[1][0] = v[20]; extrinsic_curvature[1][1] = v[21]; extrinsic_curvature[1][2] = v[22]; - extrinsic_curvature[2][0] = v[23]; extrinsic_curvature[2][1] = v[24]; extrinsic_curvature[2][2] = v[25]; + extrinsic_curvature[0][0] = v[17]; + extrinsic_curvature[0][1] = v[18]; + extrinsic_curvature[0][2] = v[19]; + extrinsic_curvature[1][0] = v[20]; + extrinsic_curvature[1][1] = v[21]; + extrinsic_curvature[1][2] = v[22]; + extrinsic_curvature[2][0] = v[23]; + extrinsic_curvature[2][1] = v[24]; + extrinsic_curvature[2][2] = v[25]; double lapse_der[3]; lapse_der[0] = v[27]; @@ -1687,24 +1975,48 @@ gr_ultra_rel_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qi lapse_der[2] = v[29]; double shift_der[3][3]; - shift_der[0][0] = v[30]; shift_der[0][1] = v[31]; shift_der[0][2] = v[32]; - shift_der[1][0] = v[33]; shift_der[1][1] = v[34]; shift_der[1][2] = v[35]; - shift_der[2][0] = v[36]; shift_der[2][1] = v[37]; shift_der[2][2] = v[38]; + shift_der[0][0] = v[30]; + shift_der[0][1] = v[31]; + shift_der[0][2] = v[32]; + shift_der[1][0] = v[33]; + shift_der[1][1] = v[34]; + shift_der[1][2] = v[35]; + shift_der[2][0] = v[36]; + shift_der[2][1] = v[37]; + shift_der[2][2] = v[38]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = v[39]; spatial_metric_der[0][0][1] = v[40]; spatial_metric_der[0][0][2] = v[41]; - spatial_metric_der[0][1][0] = v[42]; spatial_metric_der[0][1][1] = v[43]; spatial_metric_der[0][1][2] = v[44]; - spatial_metric_der[0][2][0] = v[45]; spatial_metric_der[0][2][1] = v[46]; spatial_metric_der[0][2][2] = v[47]; - - spatial_metric_der[1][0][0] = v[48]; spatial_metric_der[1][0][1] = v[49]; spatial_metric_der[1][0][2] = v[50]; - spatial_metric_der[1][1][0] = v[51]; spatial_metric_der[1][1][1] = v[52]; spatial_metric_der[1][1][2] = v[53]; - spatial_metric_der[1][2][0] = v[54]; spatial_metric_der[1][2][1] = v[55]; spatial_metric_der[1][2][2] = v[56]; - - spatial_metric_der[0][0][0] = v[57]; spatial_metric_der[0][0][1] = v[58]; spatial_metric_der[0][0][2] = v[59]; - spatial_metric_der[0][1][0] = v[60]; spatial_metric_der[0][1][1] = v[61]; spatial_metric_der[0][1][2] = v[62]; - spatial_metric_der[0][2][0] = v[63]; spatial_metric_der[0][2][1] = v[64]; spatial_metric_der[0][2][2] = v[65]; - - double **stress_energy = gkyl_malloc(sizeof(double*[4])); + spatial_metric_der[0][0][0] = v[39]; + spatial_metric_der[0][0][1] = v[40]; + spatial_metric_der[0][0][2] = v[41]; + spatial_metric_der[0][1][0] = v[42]; + spatial_metric_der[0][1][1] = v[43]; + spatial_metric_der[0][1][2] = v[44]; + spatial_metric_der[0][2][0] = v[45]; + spatial_metric_der[0][2][1] = v[46]; + spatial_metric_der[0][2][2] = v[47]; + + spatial_metric_der[1][0][0] = v[48]; + spatial_metric_der[1][0][1] = v[49]; + spatial_metric_der[1][0][2] = v[50]; + spatial_metric_der[1][1][0] = v[51]; + spatial_metric_der[1][1][1] = v[52]; + spatial_metric_der[1][1][2] = v[53]; + spatial_metric_der[1][2][0] = v[54]; + spatial_metric_der[1][2][1] = v[55]; + spatial_metric_der[1][2][2] = v[56]; + + spatial_metric_der[0][0][0] = v[57]; + spatial_metric_der[0][0][1] = v[58]; + spatial_metric_der[0][0][2] = v[59]; + spatial_metric_der[0][1][0] = v[60]; + spatial_metric_der[0][1][1] = v[61]; + spatial_metric_der[0][1][2] = v[62]; + spatial_metric_der[0][2][0] = v[63]; + spatial_metric_der[0][2][1] = v[64]; + spatial_metric_der[0][2][2] = v[65]; + + double **stress_energy = gkyl_malloc(sizeof(double *[4])); for (int i = 0; i < 4; i++) { stress_energy[i] = gkyl_malloc(sizeof(double[4])); } @@ -1718,11 +2030,15 @@ gr_ultra_rel_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qi if (!in_excision_region) { double shift[3]; - shift[0] = shift_x; shift[1] = shift_y; shift[2] = shift_z; + shift[0] = shift_x; + shift[1] = shift_y; + shift[2] = shift_z; double vel[3]; double v_sq = 0.0; - vel[0] = vx; vel[1] = vy; vel[2] = vz; + vel[0] = vx; + vel[1] = vy; + vel[2] = vz; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -1734,7 +2050,7 @@ gr_ultra_rel_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qi if (v_sq > 1.0 - pow(10.0, -8.0)) { W = 1.0 / sqrt(1.0 - pow(10.0, -8.0)); } - + double mom[3]; mom[0] = (rho + p) * (W * W) * vx; mom[1] = (rho + p) * (W * W) * vy; @@ -1759,7 +2075,8 @@ gr_ultra_rel_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qi for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { - sout[1 + j] += 0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]; + sout[1 + j] += + 0.5 * stress_energy[0][0] * shift[k] * shift[l] * spatial_metric_der[j][k][l]; sout[1 + j] += 0.5 * stress_energy[k + 1][l + 1] * spatial_metric_der[j][k][l]; } @@ -1770,8 +2087,7 @@ gr_ultra_rel_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qi } } } - } - else { + } else { for (int i = 0; i < 70; i++) { sout[i] = 0.0; } @@ -1783,39 +2099,41 @@ gr_ultra_rel_euler_tetrad_source(const struct gkyl_wv_eqn* eqn, const double* qi gkyl_free(stress_energy); } -void -gkyl_gr_ultra_rel_euler_tetrad_free(const struct gkyl_ref_count* ref) +void gkyl_gr_ultra_rel_euler_tetrad_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. - struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(base->on_dev, struct wv_gr_ultra_rel_euler_tetrad, eqn); + struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(base->on_dev, struct wv_gr_ultra_rel_euler_tetrad, eqn); gkyl_cu_free(gr_ultra_rel_euler_tetrad); } - struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(base, struct wv_gr_ultra_rel_euler_tetrad, eqn); + struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(base, struct wv_gr_ultra_rel_euler_tetrad, eqn); gkyl_free(gr_ultra_rel_euler_tetrad); } -struct gkyl_wv_eqn* -gkyl_wv_gr_ultra_rel_euler_tetrad_new(double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, struct gkyl_gr_spacetime* spacetime, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_gr_ultra_rel_euler_tetrad_new( + double gas_gamma, enum gkyl_spacetime_gauge spacetime_gauge, int reinit_freq, + struct gkyl_gr_spacetime *spacetime, bool use_gpu +) { - return gkyl_wv_gr_ultra_rel_euler_tetrad_inew(&(struct gkyl_wv_gr_ultra_rel_euler_tetrad_inp) { - .gas_gamma = gas_gamma, - .spacetime_gauge = spacetime_gauge, - .reinit_freq = reinit_freq, - .spacetime = spacetime, - .rp_type = WV_GR_ULTRA_REL_EULER_TETRAD_RP_HLL, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_gr_ultra_rel_euler_tetrad_inew(&(struct gkyl_wv_gr_ultra_rel_euler_tetrad_inp + ){.gas_gamma = gas_gamma, + .spacetime_gauge = spacetime_gauge, + .reinit_freq = reinit_freq, + .spacetime = spacetime, + .rp_type = WV_GR_ULTRA_REL_EULER_TETRAD_RP_HLL, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_gr_ultra_rel_euler_tetrad_inew(const struct gkyl_wv_gr_ultra_rel_euler_tetrad_inp* inp) +struct gkyl_wv_eqn * +gkyl_wv_gr_ultra_rel_euler_tetrad_inew(const struct gkyl_wv_gr_ultra_rel_euler_tetrad_inp *inp) { - struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = gkyl_malloc(sizeof(struct wv_gr_ultra_rel_euler_tetrad)); + struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + gkyl_malloc(sizeof(struct wv_gr_ultra_rel_euler_tetrad)); gr_ultra_rel_euler_tetrad->eqn.type = GKYL_EQN_GR_ULTRA_REL_EULER_TETRAD; gr_ultra_rel_euler_tetrad->eqn.num_equations = 70; @@ -1830,13 +2148,11 @@ gkyl_wv_gr_ultra_rel_euler_tetrad_inew(const struct gkyl_wv_gr_ultra_rel_euler_t gr_ultra_rel_euler_tetrad->eqn.num_waves = 2; gr_ultra_rel_euler_tetrad->eqn.waves_func = wave_lax_l; gr_ultra_rel_euler_tetrad->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_GR_ULTRA_REL_EULER_TETRAD_RP_ROE) { + } else if (inp->rp_type == WV_GR_ULTRA_REL_EULER_TETRAD_RP_ROE) { gr_ultra_rel_euler_tetrad->eqn.num_waves = 3; gr_ultra_rel_euler_tetrad->eqn.waves_func = wave_roe_l; gr_ultra_rel_euler_tetrad->eqn.qfluct_func = qfluct_roe_l; - } - else if (inp->rp_type == WV_GR_ULTRA_REL_EULER_TETRAD_RP_HLL) { + } else if (inp->rp_type == WV_GR_ULTRA_REL_EULER_TETRAD_RP_HLL) { gr_ultra_rel_euler_tetrad->eqn.num_waves = 2; gr_ultra_rel_euler_tetrad->eqn.waves_func = wave_hll_l; gr_ultra_rel_euler_tetrad->eqn.qfluct_func = qfluct_hll_l; @@ -1860,45 +2176,48 @@ gkyl_wv_gr_ultra_rel_euler_tetrad_inew(const struct gkyl_wv_gr_ultra_rel_euler_t gr_ultra_rel_euler_tetrad->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(gr_ultra_rel_euler_tetrad->eqn.flags); - gr_ultra_rel_euler_tetrad->eqn.ref_count = gkyl_ref_count_init(gkyl_gr_ultra_rel_euler_tetrad_free); - gr_ultra_rel_euler_tetrad->eqn.on_dev = &gr_ultra_rel_euler_tetrad->eqn; // On the CPU, the equation object points to itself. + gr_ultra_rel_euler_tetrad->eqn.ref_count = + gkyl_ref_count_init(gkyl_gr_ultra_rel_euler_tetrad_free); + gr_ultra_rel_euler_tetrad->eqn.on_dev = + &gr_ultra_rel_euler_tetrad->eqn; // On the CPU, the equation object points to itself. gr_ultra_rel_euler_tetrad->eqn.embed_geo = NULL; return &gr_ultra_rel_euler_tetrad->eqn; } -double -gkyl_wv_gr_ultra_rel_euler_tetrad_gas_gamma(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_gr_ultra_rel_euler_tetrad_gas_gamma(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); double gas_gamma = gr_ultra_rel_euler_tetrad->gas_gamma; return gas_gamma; } enum gkyl_spacetime_gauge -gkyl_wv_gr_ultra_rel_euler_tetrad_spacetime_gauge(const struct gkyl_wv_eqn* eqn) +gkyl_wv_gr_ultra_rel_euler_tetrad_spacetime_gauge(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); enum gkyl_spacetime_gauge spacetime_gauge = gr_ultra_rel_euler_tetrad->spacetime_gauge; return spacetime_gauge; } -int -gkyl_wv_gr_ultra_rel_euler_tetrad_reinit_freq(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_gr_ultra_rel_euler_tetrad_reinit_freq(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); int reinit_freq = gr_ultra_rel_euler_tetrad->reinit_freq; return reinit_freq; } -struct gkyl_gr_spacetime* -gkyl_wv_gr_ultra_rel_euler_tetrad_spacetime(const struct gkyl_wv_eqn* eqn) +struct gkyl_gr_spacetime *gkyl_wv_gr_ultra_rel_euler_tetrad_spacetime(const struct gkyl_wv_eqn *eqn) { - const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); + const struct wv_gr_ultra_rel_euler_tetrad *gr_ultra_rel_euler_tetrad = + container_of(eqn, struct wv_gr_ultra_rel_euler_tetrad, eqn); struct gkyl_gr_spacetime *spacetime = gr_ultra_rel_euler_tetrad->spacetime; return spacetime; diff --git a/moments/zero/wv_iso_euler.c b/moments/zero/wv_iso_euler.c index 6e202befb7..945c638399 100644 --- a/moments/zero/wv_iso_euler.c +++ b/moments/zero/wv_iso_euler.c @@ -24,14 +24,12 @@ #include #include -static inline double -gkyl_iso_euler_max_abs_speed(double vt, const double* q) +static inline double gkyl_iso_euler_max_abs_speed(double vt, const double *q) { return fmax(fabs(((q[1] / q[0]) - vt)), fabs(((q[1] / q[0]) + vt))); } -void -gkyl_iso_euler_flux(double vt, const double* q, double* flux) +void gkyl_iso_euler_flux(double vt, const double *q, double *flux) { flux[0] = q[1]; flux[1] = (((q[1] * q[1]) / q[0]) + (q[0] * vt * vt)); @@ -40,7 +38,7 @@ gkyl_iso_euler_flux(double vt, const double* q, double* flux) } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 4; i++) { @@ -49,7 +47,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 4; i++) { @@ -57,8 +55,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -iso_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void iso_euler_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { // Copy density. ghost[0] = skin[0]; @@ -69,8 +69,10 @@ iso_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* sk ghost[3] = skin[3]; } -static void -iso_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void iso_euler_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { // Copy density. ghost[0] = skin[0]; @@ -81,9 +83,10 @@ iso_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* ghost[3] = -skin[3]; } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { // Density is a scalar (so remains unchanged). qlocal[0] = qglobal[0]; @@ -94,9 +97,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[3] = (qglobal[1] * tau2[0]) + (qglobal[2] * tau2[1]) + (qglobal[3] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { // Density is a scalar (so remains unchanged). qglobal[0] = qlocal[0]; @@ -107,8 +111,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[3] = (qlocal[1] * norm[2]) + (qlocal[2] * tau1[2]) + (qlocal[3] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_iso_euler *iso_euler = container_of(eqn, struct wv_iso_euler, eqn); double vt = iso_euler->vt; // Thermal velocity. @@ -137,8 +143,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[4]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -150,58 +158,97 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_iso_euler *iso_euler = container_of(eqn, struct wv_iso_euler, eqn); double vt = iso_euler->vt; // Thermal velocity. - double a0 = (delta[0] * (vt + ((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0])))) / vt / 2.0) - (delta[1] / vt / 2.0); - double a1 = delta[2] - (delta[0] * ((ql[2] * (1.0 / sqrt(ql[0]))) + (qr[2] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0])))); - double a2 = delta[3] - (delta[0] * ((ql[3] * (1.0 / sqrt(ql[0]))) + (qr[3] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0])))); - double a3 = (delta[0] * (vt - ((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0])))) / vt / 2.0) + (delta[1] / vt / 2.0); + double a0 = (delta[0] * + (vt + ((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0])))) / + vt / 2.0) - + (delta[1] / vt / 2.0); + double a1 = + delta[2] - (delta[0] * ((ql[2] * (1.0 / sqrt(ql[0]))) + (qr[2] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0])))); + double a2 = + delta[3] - (delta[0] * ((ql[3] * (1.0 / sqrt(ql[0]))) + (qr[3] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0])))); + double a3 = (delta[0] * + (vt - ((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0])))) / + vt / 2.0) + + (delta[1] / vt / 2.0); double *w0 = &waves[0 * 4], *w1 = &waves[1 * 4], *w2 = &waves[2 * 4]; for (int i = 0; i < 4; i++) { - w0[i] = 0.0; w1[i] = 0.0; w2[i] = 0.0; + w0[i] = 0.0; + w1[i] = 0.0; + w2[i] = 0.0; } w0[0] = a0; - w0[1] = a0 * (((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))) - vt); - w0[2] = a0 * ((ql[2] * (1.0 / sqrt(ql[0]))) + (qr[2] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))); - w0[3] = a0 * ((ql[3] * (1.0 / sqrt(ql[0]))) + (qr[3] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))); - s[0] = ((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))) - vt; + w0[1] = a0 * (((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))) - + vt); + w0[2] = a0 * ((ql[2] * (1.0 / sqrt(ql[0]))) + (qr[2] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))); + w0[3] = a0 * ((ql[3] * (1.0 / sqrt(ql[0]))) + (qr[3] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))); + s[0] = ((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))) - + vt; w1[0] = 0.0; w1[1] = 0.0; w1[2] = a1; w1[3] = a2; - s[1] = ((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))); + s[1] = ((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))); w2[0] = a3; - w2[1] = a3 * (((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))) + vt); - w2[2] = a3 * ((ql[2] * (1.0 / sqrt(ql[0]))) + (qr[2] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))); - w2[3] = a3 * ((ql[3] * (1.0 / sqrt(ql[0]))) + (qr[3] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))); - s[2] = ((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))) + vt; - - return fabs(((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * (1.0 / (sqrt(ql[0]) + sqrt(qr[0])))) + vt; + w2[1] = a3 * (((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))) + + vt); + w2[2] = a3 * ((ql[2] * (1.0 / sqrt(ql[0]))) + (qr[2] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))); + w2[3] = a3 * ((ql[3] * (1.0 / sqrt(ql[0]))) + (qr[3] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))); + s[2] = ((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))) + + vt; + + return fabs( + ((ql[1] * (1.0 / sqrt(ql[0]))) + (qr[1] * (1.0 / sqrt(qr[0])))) * + (1.0 / (sqrt(ql[0]) + sqrt(qr[0]))) + ) + + vt; } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0 * 4], *w1 = &waves[1 * 4], *w2 = &waves[2 * 4]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); @@ -213,33 +260,35 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_iso_euler *iso_euler = container_of(eqn, struct wv_iso_euler, eqn); double vt = iso_euler->vt; // Thermal velocity. @@ -255,21 +304,19 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou double amaxl = gkyl_iso_euler_max_abs_speed(vt, ql); double amaxr = gkyl_iso_euler_max_abs_speed(vt, qr); - + gkyl_free(fr); gkyl_free(fl); return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { return q[0] > 0.0; // Density must be positive. } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_iso_euler *iso_euler = container_of(eqn, struct wv_iso_euler, eqn); double vt = iso_euler->vt; // Thermal velocity. @@ -278,25 +325,23 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) } static inline void -iso_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +iso_euler_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 4; i++) { diag[i] = qin[i]; } } -static inline void -iso_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void iso_euler_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < 4; i++) { sout[i] = 0.0; } } -void -gkyl_iso_euler_free(const struct gkyl_ref_count* ref) +void gkyl_iso_euler_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. @@ -308,19 +353,13 @@ gkyl_iso_euler_free(const struct gkyl_ref_count* ref) gkyl_free(iso_euler); } -struct gkyl_wv_eqn* -gkyl_wv_iso_euler_new(double vt, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_iso_euler_new(double vt, bool use_gpu) { - return gkyl_wv_iso_euler_inew(&(struct gkyl_wv_iso_euler_inp) { - .vt = vt, - .rp_type = WV_ISO_EULER_RP_ROE, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_iso_euler_inew(&(struct gkyl_wv_iso_euler_inp + ){.vt = vt, .rp_type = WV_ISO_EULER_RP_ROE, .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_iso_euler_inew(const struct gkyl_wv_iso_euler_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_iso_euler_inew(const struct gkyl_wv_iso_euler_inp *inp) { struct wv_iso_euler *iso_euler = gkyl_malloc(sizeof(struct wv_iso_euler)); @@ -334,8 +373,7 @@ gkyl_wv_iso_euler_inew(const struct gkyl_wv_iso_euler_inp* inp) iso_euler->eqn.num_waves = 2; iso_euler->eqn.waves_func = wave_lax_l; iso_euler->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_ISO_EULER_RP_ROE) { + } else if (inp->rp_type == WV_ISO_EULER_RP_ROE) { iso_euler->eqn.num_waves = 3; iso_euler->eqn.waves_func = wave_roe_l; iso_euler->eqn.qfluct_func = qfluct_roe_l; @@ -346,7 +384,7 @@ gkyl_wv_iso_euler_inew(const struct gkyl_wv_iso_euler_inp* inp) iso_euler->eqn.max_speed_func = max_speed; iso_euler->eqn.rotate_to_local_func = rot_to_local; iso_euler->eqn.rotate_to_global_func = rot_to_global; - + iso_euler->eqn.wall_bc_func = iso_euler_wall; iso_euler->eqn.no_slip_bc_func = iso_euler_no_slip; @@ -367,8 +405,7 @@ gkyl_wv_iso_euler_inew(const struct gkyl_wv_iso_euler_inp* inp) return &iso_euler->eqn; } -double -gkyl_wv_iso_euler_vt(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_iso_euler_vt(const struct gkyl_wv_eqn *eqn) { const struct wv_iso_euler *iso_euler = container_of(eqn, struct wv_iso_euler, eqn); double vt = iso_euler->vt; diff --git a/moments/zero/wv_iso_euler_mixture.c b/moments/zero/wv_iso_euler_mixture.c index 81b622ef7f..df6b33b11d 100644 --- a/moments/zero/wv_iso_euler_mixture.c +++ b/moments/zero/wv_iso_euler_mixture.c @@ -6,8 +6,7 @@ #include #include -void -gkyl_iso_euler_mixture_prim_vars(int num_species, double* vt_s, const double* q, double* v) +void gkyl_iso_euler_mixture_prim_vars(int num_species, double *vt_s, const double *q, double *v) { double rho_total = q[0]; double momx_total = q[1]; @@ -59,7 +58,7 @@ gkyl_iso_euler_mixture_prim_vars(int num_species, double* vt_s, const double* q, } static inline double -gkyl_iso_euler_mixture_max_abs_speed(int num_species, double* vt_s, const double* q) +gkyl_iso_euler_mixture_max_abs_speed(int num_species, double *vt_s, const double *q) { double *v = gkyl_malloc(sizeof(double[3 + (2 * num_species)])); gkyl_iso_euler_mixture_prim_vars(num_species, vt_s, q, v); @@ -82,8 +81,7 @@ gkyl_iso_euler_mixture_max_abs_speed(int num_species, double* vt_s, const double return max_abs_speed; } -void -gkyl_iso_euler_mixture_flux(int num_species, double* vt_s, const double* q, double* flux) +void gkyl_iso_euler_mixture_flux(int num_species, double *vt_s, const double *q, double *flux) { double *v = gkyl_malloc(sizeof(double[3 + (2 * num_species)])); gkyl_iso_euler_mixture_prim_vars(num_species, vt_s, q, v); @@ -115,7 +113,7 @@ gkyl_iso_euler_mixture_flux(int num_species, double* vt_s, const double* q, doub flux[1] = (rho_total * (vx_total * vx_total)) + (rho_total * (vt_total * vt_total)); flux[2] = rho_total * (vx_total * vy_total); flux[3] = rho_total * (vx_total * vz_total); - + for (int i = 0; i < num_species - 1; i++) { flux[4 + i] = rho_total * (vx_total * vol_frac_s[i]); } @@ -129,9 +127,10 @@ gkyl_iso_euler_mixture_flux(int num_species, double* vt_s, const double* q, doub } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; // TODO: This should use a proper L matrix. @@ -141,9 +140,10 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; // TODO: This should use a proper L matrix. @@ -152,10 +152,13 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -iso_euler_mixture_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void iso_euler_mixture_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; for (int i = 0; i < 3 + (2 * num_species); i++) { @@ -165,27 +168,31 @@ iso_euler_mixture_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const do ghost[1] = -ghost[1]; } -static void -iso_euler_mixture_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void iso_euler_mixture_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; for (int i = 0; i < 3 + (2 * num_species); i++) { if (i > 0 && i < 4) { ghost[i] = -skin[i]; - } - else { + } else { ghost[i] = skin[i]; } } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; for (int i = 0; i < 3 + (2 * num_species); i++) { @@ -197,11 +204,13 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[3] = (qglobal[1] * tau2[0]) + (qglobal[2] * tau2[1]) + (qglobal[3] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; for (int i = 0; i < 3 + (2 * num_species); i++) { @@ -213,12 +222,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[3] = (qlocal[1] * norm[2]) + (qlocal[2] * tau1[2]) + (qlocal[3] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; - double* vt_s = iso_euler_mixture->vt_s; + double *vt_s = iso_euler_mixture->vt_s; double sl = gkyl_iso_euler_mixture_max_abs_speed(num_species, vt_s, ql); double sr = gkyl_iso_euler_mixture_max_abs_speed(num_species, vt_s, qr); @@ -244,10 +256,13 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; const double *w0 = &waves[0], *w1 = &waves[3 + (2 * num_species)]; @@ -260,23 +275,30 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; double *vt_s = iso_euler_mixture->vt_s; @@ -292,7 +314,7 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double vx = ((ql[1] * roe_avg_l) + (qr[1] * roe_avg_r)) * roe_avg_sq; double vy = ((ql[2] * roe_avg_l) + (qr[2] * roe_avg_r)) * roe_avg_sq; double vz = ((ql[3] * roe_avg_l) + (qr[3] * roe_avg_r)) * roe_avg_sq; - + double *vol_frac_s = gkyl_malloc(sizeof(double[num_species])); double vol_frac_total = 0.0; for (int i = 0; i < num_species - 1; i++) { @@ -300,7 +322,7 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c vol_frac_total += vol_frac_s[i]; } vol_frac_s[num_species - 1] = 1.0 - vol_frac_total; - + double vt_total = 0.0; for (int i = 0; i < num_species; i++) { vt_total += vol_frac_s[i] * vt_s[i]; @@ -319,8 +341,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double *a_rho1 = gkyl_malloc(sizeof(double[num_species])); double *a_rho2 = gkyl_malloc(sizeof(double[num_species])); for (int i = 0; i < num_species; i++) { - a_rho1[i] = (delta[3 + num_species + i] * (vt_total + vx) / vt_total / 2.0) - (delta[1] / vt_total / 2.0); - a_rho2[i] = (delta[3 + num_species + i] * (vt_total - vx) / vt_total / 2.0) + (delta[1] / vt_total / 2.0); + a_rho1[i] = + (delta[3 + num_species + i] * (vt_total + vx) / vt_total / 2.0) - (delta[1] / vt_total / 2.0); + a_rho2[i] = + (delta[3 + num_species + i] * (vt_total - vx) / vt_total / 2.0) + (delta[1] / vt_total / 2.0); } double *wv; @@ -371,13 +395,17 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return fabs(vx) + vt_total; } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; - - const double *w0 = &waves[0], *w1 = &waves[3 + (2 * num_species)], *w2 = &waves[6 + (4 * num_species)]; + + const double *w0 = &waves[0], *w1 = &waves[3 + (2 * num_species)], + *w2 = &waves[6 + (4 * num_species)]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]); @@ -387,35 +415,38 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; double *vt_s = iso_euler_mixture->vt_s; @@ -430,17 +461,17 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou double amaxl = gkyl_iso_euler_mixture_max_abs_speed(num_species, vt_s, ql); double amaxr = gkyl_iso_euler_mixture_max_abs_speed(num_species, vt_s, qr); - + gkyl_free(fr); gkyl_free(fl); return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; double *vt_s = iso_euler_mixture->vt_s; @@ -453,7 +484,7 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q) return false; } } - + double vol_frac_total = 0.0; for (int i = 0; i < num_species - 1; i++) { vol_frac_total += v[4 + i]; @@ -466,27 +497,27 @@ check_inv(const struct gkyl_wv_eqn* eqn, const double* q) if (v[0] < 0.0) { gkyl_free(v); return false; - } - else { + } else { gkyl_free(v); return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; - double* vt_s = iso_euler_mixture->vt_s; + double *vt_s = iso_euler_mixture->vt_s; return gkyl_iso_euler_mixture_max_abs_speed(num_species, vt_s, q); } static inline void -iso_euler_mixture_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +iso_euler_mixture_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; for (int i = 0; i < 3 + (2 * num_species); i++) { @@ -495,9 +526,10 @@ iso_euler_mixture_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, } static inline void -iso_euler_mixture_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +iso_euler_mixture_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; for (int i = 0; i < 3 + (2 * num_species); i++) { @@ -505,35 +537,32 @@ iso_euler_mixture_source(const struct gkyl_wv_eqn* eqn, const double* qin, doubl } } -void -gkyl_iso_euler_mixture_free(const struct gkyl_ref_count* ref) +void gkyl_iso_euler_mixture_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. - struct wv_iso_euler_mixture *iso_euler_mixture = container_of(base->on_dev, struct wv_iso_euler_mixture, eqn); + struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(base->on_dev, struct wv_iso_euler_mixture, eqn); gkyl_cu_free(iso_euler_mixture); } - struct wv_iso_euler_mixture *iso_euler_mixture = container_of(base, struct wv_iso_euler_mixture, eqn); + struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(base, struct wv_iso_euler_mixture, eqn); gkyl_free(iso_euler_mixture); } -struct gkyl_wv_eqn* -gkyl_wv_iso_euler_mixture_new(int num_species, double* vt_s, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_iso_euler_mixture_new(int num_species, double *vt_s, bool use_gpu) { - return gkyl_wv_iso_euler_mixture_inew(&(struct gkyl_wv_iso_euler_mixture_inp) { - .num_species = num_species, - .vt_s = vt_s, - .rp_type = WV_ISO_EULER_MIXTURE_RP_LAX, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_iso_euler_mixture_inew(&(struct gkyl_wv_iso_euler_mixture_inp + ){.num_species = num_species, + .vt_s = vt_s, + .rp_type = WV_ISO_EULER_MIXTURE_RP_LAX, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_iso_euler_mixture_inew(const struct gkyl_wv_iso_euler_mixture_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_iso_euler_mixture_inew(const struct gkyl_wv_iso_euler_mixture_inp *inp) { struct wv_iso_euler_mixture *iso_euler_mixture = gkyl_malloc(sizeof(struct wv_iso_euler_mixture)); @@ -548,8 +577,7 @@ gkyl_wv_iso_euler_mixture_inew(const struct gkyl_wv_iso_euler_mixture_inp* inp) iso_euler_mixture->eqn.num_waves = 2; iso_euler_mixture->eqn.waves_func = wave_lax_l; iso_euler_mixture->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_ISO_EULER_MIXTURE_RP_ROE) { + } else if (inp->rp_type == WV_ISO_EULER_MIXTURE_RP_ROE) { iso_euler_mixture->eqn.num_waves = 3; iso_euler_mixture->eqn.waves_func = wave_roe_l; iso_euler_mixture->eqn.qfluct_func = qfluct_roe_l; @@ -560,7 +588,7 @@ gkyl_wv_iso_euler_mixture_inew(const struct gkyl_wv_iso_euler_mixture_inp* inp) iso_euler_mixture->eqn.max_speed_func = max_speed; iso_euler_mixture->eqn.rotate_to_local_func = rot_to_local; iso_euler_mixture->eqn.rotate_to_global_func = rot_to_global; - + iso_euler_mixture->eqn.wall_bc_func = iso_euler_mixture_wall; iso_euler_mixture->eqn.no_slip_bc_func = iso_euler_mixture_no_slip; @@ -574,26 +602,27 @@ gkyl_wv_iso_euler_mixture_inew(const struct gkyl_wv_iso_euler_mixture_inp* inp) iso_euler_mixture->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(iso_euler_mixture->eqn.flags); iso_euler_mixture->eqn.ref_count = gkyl_ref_count_init(gkyl_iso_euler_mixture_free); - iso_euler_mixture->eqn.on_dev = &iso_euler_mixture->eqn; // On the CPU, the equation object points ot itself. + iso_euler_mixture->eqn.on_dev = + &iso_euler_mixture->eqn; // On the CPU, the equation object points ot itself. iso_euler_mixture->eqn.embed_geo = NULL; return &iso_euler_mixture->eqn; } -int -gkyl_wv_iso_euler_mixture_num_species(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_iso_euler_mixture_num_species(const struct gkyl_wv_eqn *eqn) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); int num_species = iso_euler_mixture->num_species; return num_species; } -double* -gkyl_wv_iso_euler_mixture_vt_s(const struct gkyl_wv_eqn* eqn) +double *gkyl_wv_iso_euler_mixture_vt_s(const struct gkyl_wv_eqn *eqn) { - const struct wv_iso_euler_mixture *iso_euler_mixture = container_of(eqn, struct wv_iso_euler_mixture, eqn); + const struct wv_iso_euler_mixture *iso_euler_mixture = + container_of(eqn, struct wv_iso_euler_mixture, eqn); double *vt_s = iso_euler_mixture->vt_s; return vt_s; diff --git a/moments/zero/wv_maxwell.c b/moments/zero/wv_maxwell.c index 1adeba241c..26c466dcaf 100644 --- a/moments/zero/wv_maxwell.c +++ b/moments/zero/wv_maxwell.c @@ -38,18 +38,16 @@ #include #include -static inline void -maxwell_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void maxwell_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < 8; i++) { sout[i] = 0.0; } } -void -gkyl_wv_maxwell_free(const struct gkyl_ref_count* ref) +void gkyl_wv_maxwell_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. @@ -61,27 +59,19 @@ gkyl_wv_maxwell_free(const struct gkyl_ref_count* ref) gkyl_free(maxwell); } -struct gkyl_wv_eqn* -gkyl_wv_maxwell_new(double c, double e_fact, double b_fact, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_maxwell_new(double c, double e_fact, double b_fact, bool use_gpu) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_wv_maxwell_cu_dev_new(c, e_fact, b_fact); - } + } #endif - return gkyl_wv_maxwell_inew(&(struct gkyl_wv_maxwell_inp) { - .c = c, - .e_fact = e_fact, - .b_fact = b_fact, - .rp_type = WV_MAXWELL_RP_ROE, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_maxwell_inew(&(struct gkyl_wv_maxwell_inp + ){.c = c, .e_fact = e_fact, .b_fact = b_fact, .rp_type = WV_MAXWELL_RP_ROE, .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_maxwell_inew(const struct gkyl_wv_maxwell_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_maxwell_inew(const struct gkyl_wv_maxwell_inp *inp) { struct wv_maxwell *maxwell = gkyl_malloc(sizeof(struct wv_maxwell)); @@ -97,8 +87,7 @@ gkyl_wv_maxwell_inew(const struct gkyl_wv_maxwell_inp* inp) maxwell->eqn.num_waves = 6; maxwell->eqn.waves_func = wave; maxwell->eqn.qfluct_func = qfluct; - } - else if (inp->rp_type == WV_MAXWELL_RP_LAX) { + } else if (inp->rp_type == WV_MAXWELL_RP_LAX) { maxwell->eqn.num_waves = 2; maxwell->eqn.waves_func = wave_lax_l; maxwell->eqn.qfluct_func = qfluct_lax_l; @@ -109,7 +98,7 @@ gkyl_wv_maxwell_inew(const struct gkyl_wv_maxwell_inp* inp) maxwell->eqn.max_speed_func = max_speed; maxwell->eqn.rotate_to_local_func = rot_to_local; maxwell->eqn.rotate_to_global_func = rot_to_global; - + maxwell->eqn.wall_bc_func = maxwell_wall; maxwell->eqn.no_slip_bc_func = maxwell_no_slip; @@ -128,20 +117,20 @@ gkyl_wv_maxwell_inew(const struct gkyl_wv_maxwell_inp* inp) maxwell->eqn.embed_geo = inp->embed_geo; if (maxwell->eqn.embed_geo) { switch (maxwell->eqn.embed_geo->type) { - case GKYL_EMBED_COPY_B: - maxwell->eqn.embed_geo->embed_func = wave_embed_copy_B; - break; + case GKYL_EMBED_COPY_B: + maxwell->eqn.embed_geo->embed_func = wave_embed_copy_B; + break; - case GKYL_EMBED_PEC: - maxwell->eqn.embed_geo->embed_func = wave_embed_pec; - break; + case GKYL_EMBED_PEC: + maxwell->eqn.embed_geo->embed_func = wave_embed_pec; + break; - case GKYL_EMBED_FUNC: - break; // already set by gkyl_wv_embed_geo_new + case GKYL_EMBED_FUNC: + break; // already set by gkyl_wv_embed_geo_new - default: - assert(false); - break; + default: + assert(false); + break; } } diff --git a/moments/zero/wv_maxwell_cu.cu b/moments/zero/wv_maxwell_cu.cu index 3eaa08b65a..d6962c016c 100644 --- a/moments/zero/wv_maxwell_cu.cu +++ b/moments/zero/wv_maxwell_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include } @@ -11,8 +11,7 @@ extern "C" { // CUDA kernel to set device pointers to maxwell kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -wv_maxwell_set_cu_dev_ptrs(struct wv_maxwell *maxwell) +__global__ static void wv_maxwell_set_cu_dev_ptrs(struct wv_maxwell *maxwell) { maxwell->eqn.waves_func = wave; maxwell->eqn.qfluct_func = qfluct; @@ -31,16 +30,15 @@ wv_maxwell_set_cu_dev_ptrs(struct wv_maxwell *maxwell) maxwell->eqn.cons_to_diag = maxwell_cons_to_diag; } -struct gkyl_wv_eqn* -gkyl_wv_maxwell_cu_dev_new(double c, double e_fact, double b_fact) +struct gkyl_wv_eqn *gkyl_wv_maxwell_cu_dev_new(double c, double e_fact, double b_fact) { - struct wv_maxwell *maxwell = (struct wv_maxwell*) gkyl_malloc(sizeof(struct wv_maxwell)); + struct wv_maxwell *maxwell = (struct wv_maxwell *)gkyl_malloc(sizeof(struct wv_maxwell)); maxwell->eqn.type = GKYL_EQN_MAXWELL; - maxwell->eqn.num_equations = 8; + maxwell->eqn.num_equations = 8; maxwell->eqn.num_waves = 6; maxwell->eqn.num_diag = 6; // Ex^2, Ey^2, Ez^2, Bx^2, By^2, Bz^2 - + maxwell->c = c; maxwell->e_fact = e_fact; maxwell->b_fact = b_fact; @@ -50,10 +48,10 @@ gkyl_wv_maxwell_cu_dev_new(double c, double e_fact, double b_fact) maxwell->eqn.ref_count = gkyl_ref_count_init(gkyl_wv_maxwell_free); // copy the host struct to device struct - struct wv_maxwell *maxwell_cu = (struct wv_maxwell*) gkyl_cu_malloc(sizeof(struct wv_maxwell)); + struct wv_maxwell *maxwell_cu = (struct wv_maxwell *)gkyl_cu_malloc(sizeof(struct wv_maxwell)); gkyl_cu_memcpy(maxwell_cu, maxwell, sizeof(struct wv_maxwell), GKYL_CU_MEMCPY_H2D); - wv_maxwell_set_cu_dev_ptrs<<<1,1>>>(maxwell_cu); + wv_maxwell_set_cu_dev_ptrs<<<1, 1> > >(maxwell_cu); maxwell->eqn.on_dev = &maxwell_cu->eqn; // CPU eqn obj points to itself return &maxwell->eqn; diff --git a/moments/zero/wv_mhd.c b/moments/zero/wv_mhd.c index c4a251c6ca..71baea958b 100644 --- a/moments/zero/wv_mhd.c +++ b/moments/zero/wv_mhd.c @@ -20,86 +20,90 @@ #define sq(x) ((x) * (x)) static inline void -cons_to_riem_8(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *qin, double *wout) +cons_to_riem_8(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: this should use proper L matrix - for (int i=0; i<8; ++i) + for (int i = 0; i < 8; ++i) { wout[i] = qin[i]; + } } static inline void -riem_to_cons_8(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *win, double *qout) +riem_to_cons_8(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: this should use proper L matrix - for (int i=0; i<8; ++i) + for (int i = 0; i < 8; ++i) { qout[i] = win[i]; + } } static inline void -cons_to_riem_9(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *qin, double *wout) +cons_to_riem_9(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: this should use proper L matrix - for (int i=0; i<9; ++i) + for (int i = 0; i < 9; ++i) { wout[i] = qin[i]; + } } static inline void -riem_to_cons_9(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *win, double *qout) +riem_to_cons_9(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: this should use proper L matrix - for (int i=0; i<9; ++i) + for (int i = 0; i < 9; ++i) { qout[i] = win[i]; + } } -static inline void -rot_to_local_rect(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qglobal, double* GKYL_RESTRICT qlocal) +static inline void rot_to_local_rect( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { // Mass density is a scalar qlocal[0] = qglobal[0]; // Rotate momentum to local coordinates - qlocal[1] = qglobal[1]*norm[0] + qglobal[2]*norm[1] + qglobal[3]*norm[2]; - qlocal[2] = qglobal[1]*tau1[0] + qglobal[2]*tau1[1] + qglobal[3]*tau1[2]; - qlocal[3] = qglobal[1]*tau2[0] + qglobal[2]*tau2[1] + qglobal[3]*tau2[2]; + qlocal[1] = qglobal[1] * norm[0] + qglobal[2] * norm[1] + qglobal[3] * norm[2]; + qlocal[2] = qglobal[1] * tau1[0] + qglobal[2] * tau1[1] + qglobal[3] * tau1[2]; + qlocal[3] = qglobal[1] * tau2[0] + qglobal[2] * tau2[1] + qglobal[3] * tau2[2]; // Total energy is a scalar qlocal[4] = qglobal[4]; // Rotate B to local coordinates - qlocal[5] = qglobal[5]*norm[0] + qglobal[6]*norm[1] + qglobal[7]*norm[2]; - qlocal[6] = qglobal[5]*tau1[0] + qglobal[6]*tau1[1] + qglobal[7]*tau1[2]; - qlocal[7] = qglobal[5]*tau2[0] + qglobal[6]*tau2[1] + qglobal[7]*tau2[2]; + qlocal[5] = qglobal[5] * norm[0] + qglobal[6] * norm[1] + qglobal[7] * norm[2]; + qlocal[6] = qglobal[5] * tau1[0] + qglobal[6] * tau1[1] + qglobal[7] * tau1[2]; + qlocal[7] = qglobal[5] * tau2[0] + qglobal[6] * tau2[1] + qglobal[7] * tau2[2]; } -static inline void -rot_to_global_rect(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qlocal, double* GKYL_RESTRICT qglobal) +static inline void rot_to_global_rect( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { // Mass density is a scalar qglobal[0] = qlocal[0]; // Rotate momentum back to global coordinates - qglobal[1] = qlocal[1]*norm[0] + qlocal[2]*tau1[0] + qlocal[3]*tau2[0]; - qglobal[2] = qlocal[1]*norm[1] + qlocal[2]*tau1[1] + qlocal[3]*tau2[1]; - qglobal[3] = qlocal[1]*norm[2] + qlocal[2]*tau1[2] + qlocal[3]*tau2[2]; + qglobal[1] = qlocal[1] * norm[0] + qlocal[2] * tau1[0] + qlocal[3] * tau2[0]; + qglobal[2] = qlocal[1] * norm[1] + qlocal[2] * tau1[1] + qlocal[3] * tau2[1]; + qglobal[3] = qlocal[1] * norm[2] + qlocal[2] * tau1[2] + qlocal[3] * tau2[2]; // Total energy is a scalar qglobal[4] = qlocal[4]; // Rotate B back to global coordinates - qglobal[5] = qlocal[5]*norm[0] + qlocal[6]*tau1[0] + qlocal[7]*tau2[0]; - qglobal[6] = qlocal[5]*norm[1] + qlocal[6]*tau1[1] + qlocal[7]*tau2[1]; - qglobal[7] = qlocal[5]*norm[2] + qlocal[6]*tau1[2] + qlocal[7]*tau2[2]; + qglobal[5] = qlocal[5] * norm[0] + qlocal[6] * tau1[0] + qlocal[7] * tau2[0]; + qglobal[6] = qlocal[5] * norm[1] + qlocal[6] * tau1[1] + qlocal[7] * tau2[1]; + qglobal[7] = qlocal[5] * norm[2] + qlocal[6] * tau1[2] + qlocal[7] * tau2[2]; } -static inline void -rot_to_local_rect_glm(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qglobal, double* GKYL_RESTRICT qlocal) +static inline void rot_to_local_rect_glm( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { rot_to_local_rect(eqn, tau1, tau2, norm, qglobal, qlocal); qlocal[8] = qglobal[8]; } -static inline void -rot_to_global_rect_glm(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qlocal, double* GKYL_RESTRICT qglobal) +static inline void rot_to_global_rect_glm( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { rot_to_global_rect(eqn, tau1, tau2, norm, qlocal, qglobal); qglobal[8] = qlocal[8]; @@ -113,8 +117,7 @@ struct wv_mhd { double glm_alpha; // Mignone & Tzeferacos, JCP (2010) 229, 2117, Eq (27). }; -static void -mhd_free(const struct gkyl_ref_count *ref) +static void mhd_free(const struct gkyl_ref_count *ref) { struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); struct wv_mhd *mhd = container_of(base, struct wv_mhd, eqn); @@ -125,9 +128,10 @@ mhd_free(const struct gkyl_ref_count *ref) // Following Cargo & Gallice 1997 section 4.2. // FIXME: is CG97 linearization consistent with the flux difference when the jump // in Bx is nonzero? -static double -wave_roe(const struct gkyl_wv_eqn *eqn, - const double *dQ, const double *ql, const double *qr, double *waves, double *ev) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, const double *qr, + double *waves, double *ev +) { const struct wv_mhd *mhd = container_of(eqn, struct wv_mhd, eqn); double gamma = mhd->gas_gamma; @@ -158,7 +162,7 @@ wave_roe(const struct gkyl_wv_eqn *eqn, double u = sl * ul + sr * ur; double v = sl * vl + sr * vr; double w = sl * wl + sr * wr; - double H = sl * Hl + sr * Hr; // total enthalpy + double H = sl * Hl + sr * Hr; // total enthalpy double Bx = sr * ql[BX] + sl * qr[BX]; double By = sr * ql[BY] + sl * qr[BY]; double Bz = sr * ql[BZ] + sl * qr[BZ]; @@ -169,34 +173,34 @@ wave_roe(const struct gkyl_wv_eqn *eqn, // CG97 eq. 4.12, including jump in Bx seems to give correct jump in pressure // according to the equation bewteen CG97 eq. 4.15 and 4.16; X may also be // computed from CG97 eq. 4.15 - double X = (sq(dQ[BX]) + sq(dQ[BY]) + sq(dQ[BZ])) / (2*sq(srrhol+srrhor)); + double X = (sq(dQ[BX]) + sq(dQ[BY]) + sq(dQ[BZ])) / (2 * sq(srrhol + srrhor)); // CG97 eq 4.17, wave speeds - double ca2 = Bx*Bx/rho; // for alfven speed due to normal B field - double b2 = (Bx*Bx+By*By+Bz*Bz) / rho; // for alfven speed due to full B field - double v2 = u*u+v*v+w*w; - double Hgas = H - b2; // enthalpy of the gas - double a2 = (2-gamma)*X + (gamma-1)*(Hgas-0.5*v2); // for sound speed + double ca2 = Bx * Bx / rho; // for alfven speed due to normal B field + double b2 = (Bx * Bx + By * By + Bz * Bz) / rho; // for alfven speed due to full B field + double v2 = u * u + v * v + w * w; + double Hgas = H - b2; // enthalpy of the gas + double a2 = (2 - gamma) * X + (gamma - 1) * (Hgas - 0.5 * v2); // for sound speed double astar2 = a2 + b2; - double cf2 = (astar2 + sqrt(sq(astar2)-4*a2*ca2)) / 2; // fast wave speed - double cs2 = (astar2 - sqrt(sq(astar2)-4*a2*ca2)) / 2; // slow wave speed + double cf2 = (astar2 + sqrt(sq(astar2) - 4 * a2 * ca2)) / 2; // fast wave speed + double cs2 = (astar2 - sqrt(sq(astar2) - 4 * a2 * ca2)) / 2; // slow wave speed - double a = sqrt(a2); // sound speed - double ca = sqrt(ca2); // alfven speed due to normal B field - double cf = sqrt(cf2); // fast magnetosonic speed - double cs = sqrt(cs2); // slow magnetosonic speed + double a = sqrt(a2); // sound speed + double ca = sqrt(ca2); // alfven speed due to normal B field + double cf = sqrt(cf2); // fast magnetosonic speed + double cs = sqrt(cs2); // slow magnetosonic speed // CG97 eq 4.21, S, beta, and alpha - double S = Bx >=0? 1: -1; + double S = Bx >= 0 ? 1 : -1; - double Bt = sqrt(By*By+Bz*Bz); + double Bt = sqrt(By * By + Bz * Bz); double betay, betaz; - if (Bt>0) { // TODO compare wtih a tiny number + if (Bt > 0) { // TODO compare wtih a tiny number betay = By / Bt; betaz = Bz / Bt; } else { - betay = betaz = 1/sqrt(2); + betay = betaz = 1 / sqrt(2); } double alphaf2 = (a2 - cs2) / (cf2 - cs2); @@ -229,7 +233,9 @@ wave_roe(const struct gkyl_wv_eqn *eqn, const int meqns = eqn->num_equations; const int mwaves = eqn->num_waves; - for (int i=0; idivergence_constraint == GKYL_MHD_DIVB_EIGHT_WAVES) { ev[7] = u; - wv = &waves[7*meqns]; + wv = &waves[7 * meqns]; wv[BX] = dQ[BX]; } // For the GLM Bx and psi waves, solve the linear Riemann problem. // TODO create and use a separate glm RP solver - if (mhd->divergence_constraint == GKYL_MHD_DIVB_GLM) - { + if (mhd->divergence_constraint == GKYL_MHD_DIVB_GLM) { double ch = mhd->glm_ch; // L = 0.5*(-ch, 1), R = (-1/ch, 1) ev[7] = -ch; - eta[7] = 0.5 * (-dQ[BX]*ch+dQ[PSI_GLM]); - wv = &waves[7*meqns]; - wv[BX] = -eta[7]/ch; + eta[7] = 0.5 * (-dQ[BX] * ch + dQ[PSI_GLM]); + wv = &waves[7 * meqns]; + wv[BX] = -eta[7] / ch; wv[PSI_GLM] = eta[7]; // L = 0.5*(+ch, 1), R = (+1/ch, 1) ev[8] = ch; - eta[8] = 0.5 * (dQ[BX]*ch+dQ[PSI_GLM]); - wv = &waves[8*meqns]; - wv[BX] = eta[8]/ch; + eta[8] = 0.5 * (dQ[BX] * ch + dQ[PSI_GLM]); + wv = &waves[8 * meqns]; + wv[BX] = eta[8] / ch; wv[PSI_GLM] = eta[8]; max_speed = max_speed > ch ? max_speed : ch; @@ -402,26 +407,27 @@ wave_roe(const struct gkyl_wv_eqn *eqn, return max_speed; } -static void -qfluct_roe(const struct gkyl_wv_eqn *eqn, - const double *ql, const double *qr, const double *waves, const double *s, double *amdq, - double *apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { int meqn = eqn->num_equations; - for (int i=0; inum_waves; ++mw) { - amdq[i] += fmin(0.0, s[mw]) * waves[meqn*mw+i]; - apdq[i] += fmax(0.0, s[mw]) * waves[meqn*mw+i]; + for (int mw = 1; mw < eqn->num_waves; ++mw) { + amdq[i] += fmin(0.0, s[mw]) * waves[meqn * mw + i]; + apdq[i] += fmax(0.0, s[mw]) * waves[meqn * mw + i]; } } } // Computing waves and waves speeds from Lax fluxes -static double -wave_lax(const struct gkyl_wv_eqn *eqn, - const double *dQ, const double *ql, const double *qr, double *waves, double *ev) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, const double *qr, + double *waves, double *ev +) { const struct wv_mhd *mhd = container_of(eqn, struct wv_mhd, eqn); int meqn = eqn->num_equations; @@ -448,34 +454,35 @@ wave_lax(const struct gkyl_wv_eqn *eqn, } double *w0 = &waves[0], *w1 = &waves[meqn]; - for (int i=0; inum_equations; const double *w0 = &waves[0], *w1 = &waves[meqn]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]); - for (int i=0; igas_gamma; @@ -520,23 +527,25 @@ wave_hlld(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, #endif // FIXME Miyoshi & Kusano did not specify Bx - double Bx = (sr*qr[BX] - sl*ql[BX]) / (sr - sl); - double sign = Bx > 0? 1 : -1; + double Bx = (sr * qr[BX] - sl * ql[BX]) / (sr - sl); + double sign = Bx > 0 ? 1 : -1; // STEP 2. compute intermediate wave speeds // middle wave speed,eq. 39 - double tmp = 1 / (rr*(sr-ur) - rl*(sl-ul)); - double sm = (rr*ur*(sr-ur) - rl*ul*(sl-ul) - ptr+ptl) * tmp; + double tmp = 1 / (rr * (sr - ur) - rl * (sl - ul)); + double sm = (rr * ur * (sr - ur) - rl * ul * (sl - ul) - ptr + ptl) * tmp; // eq. 41, p^*_T - double pt = ((sr-ur)*rr*ptl-(sl-ul)*rl*ptr+rl*rr*(sr-ur)*(sl-ul)*(ur-ul))*tmp; + double pt = + ((sr - ur) * rr * ptl - (sl - ul) * rl * ptr + rl * rr * (sr - ur) * (sl - ul) * (ur - ul)) * + tmp; // sl: outer left, ssl: inner left, ssr: inner right, sr: outer right - double rsl = rl * (sl-ul) / (sl-sm); // eq. 43 - double rsr = rr * (sr-ur) / (sr-sm); // eq. 43 + double rsl = rl * (sl - ul) / (sl - sm); // eq. 43 + double rsr = rr * (sr - ur) / (sr - sm); // eq. 43 double sqrtl = sqrt(rsl); double sqrtr = sqrt(rsr); - double ssl = sm - Bx*sign / sqrtl; // eq. 51 - double ssr = sm + Bx*sign / sqrtr; // eq. 51 + double ssl = sm - Bx * sign / sqrtl; // eq. 51 + double ssr = sm + Bx * sign / sqrtr; // eq. 51 // STEP 3. compute intermediate states // outer left, inner left, inner right, outer right; s: star, ss: two star @@ -544,9 +553,9 @@ wave_hlld(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, double tmp1, tmp2, tmp3; // convenience temporary variables // left and right outer intermediate states - tmp = 1 / (rl*(sl-ul)*(sl-sm)-Bx*Bx); - tmp1 = Bx * (sm-ul) * tmp; - tmp2 = (rl*sq(sl-ul)-sq(Bx)) * tmp; + tmp = 1 / (rl * (sl - ul) * (sl - sm) - Bx * Bx); + tmp1 = Bx * (sm - ul) * tmp; + tmp2 = (rl * sq(sl - ul) - sq(Bx)) * tmp; double usl = sm; // eq. 39 double vsl = vl - ql[BY] * tmp1; // eq. 44 double wsl = wl - ql[BZ] * tmp1; // eq. 46 @@ -557,36 +566,36 @@ wave_hlld(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, qsl[BX] = Bx; // FIXME qsl[BY] = ql[BY] * tmp2; // eq. 45 qsl[BZ] = ql[BZ] * tmp2; // eq. 47 - tmp3 = ul*ql[BX]+vl*ql[BY]+wl*ql[BZ] - (usl*qsl[BX]+vsl*qsl[BY]+wsl*qsl[BZ]); - qsl[ER] = ((sl-ul)*ql[ER] -ptl*ul + pt*sm + Bx*tmp3) / (sl-sm); // eq. 48 + tmp3 = ul * ql[BX] + vl * ql[BY] + wl * ql[BZ] - (usl * qsl[BX] + vsl * qsl[BY] + wsl * qsl[BZ]); + qsl[ER] = ((sl - ul) * ql[ER] - ptl * ul + pt * sm + Bx * tmp3) / (sl - sm); // eq. 48 - tmp = 1 / (rr*(sr-ur)*(sr-sm)-Bx*Bx); - tmp1 = Bx * (sm-ur) * tmp; - tmp2 = (rr*sq(sr-ur)-sq(Bx)) * tmp; + tmp = 1 / (rr * (sr - ur) * (sr - sm) - Bx * Bx); + tmp1 = Bx * (sm - ur) * tmp; + tmp2 = (rr * sq(sr - ur) - sq(Bx)) * tmp; double usr = sm; // eq. 39 double vsr = vr - qr[BY] * tmp1; // eq. 44 double wsr = wr - qr[BZ] * tmp1; // eq. 46 - qsr[DN] = rsr ; + qsr[DN] = rsr; qsr[MX] = qsr[DN] * usr; qsr[MY] = qsr[DN] * vsr; qsr[MZ] = qsr[DN] * wsr; qsr[BX] = Bx; // FIXME qsr[BY] = qr[BY] * tmp2; // eq. 45 qsr[BZ] = qr[BZ] * tmp2; // eq. 47 - tmp3 = ur*qr[BX]+vr*qr[BY]+wr*qr[BZ] - (usr*qsr[BX]+vsr*qsr[BY]+wsr*qsr[BZ]); - qsr[ER] = ((sr-ur)*qr[ER] - ptr*ur + pt*sm + Bx*tmp3) / (sr-sm); // eq. 48 + tmp3 = ur * qr[BX] + vr * qr[BY] + wr * qr[BZ] - (usr * qsr[BX] + vsr * qsr[BY] + wsr * qsr[BZ]); + qsr[ER] = ((sr - ur) * qr[ER] - ptr * ur + pt * sm + Bx * tmp3) / (sr - sm); // eq. 48 // left and right inner intermediate states tmp = 1 / (sqrtl + sqrtr); double uss = sm; // eq. 39 // eq. 59, 60 - double vss = (sqrtl*vsl + sqrtr*vsr + (qsr[BY] - qsl[BY]) * sign) * tmp; - double wss = (sqrtl*wsl + sqrtr*wsr + (qsr[BZ] - qsl[BZ]) * sign) * tmp; + double vss = (sqrtl * vsl + sqrtr * vsr + (qsr[BY] - qsl[BY]) * sign) * tmp; + double wss = (sqrtl * wsl + sqrtr * wsr + (qsr[BZ] - qsl[BZ]) * sign) * tmp; // eq. 61, 62 - tmp1 = sqrtl*sqrtr*sign; - double Byss = (sqrtl*qsr[BY] + sqrtr*qsl[BY] + (vsr-vsl)*tmp1) * tmp; - double Bzss = (sqrtl*qsr[BZ] + sqrtr*qsl[BZ] + (wsr-wsl)*tmp1) * tmp; - tmp2 = uss*Bx + vss*Byss + wss*Bzss; + tmp1 = sqrtl * sqrtr * sign; + double Byss = (sqrtl * qsr[BY] + sqrtr * qsl[BY] + (vsr - vsl) * tmp1) * tmp; + double Bzss = (sqrtl * qsr[BZ] + sqrtr * qsl[BZ] + (wsr - wsl) * tmp1) * tmp; + tmp2 = uss * Bx + vss * Byss + wss * Bzss; qssl[DN] = qsl[DN]; // eq. 49 qssl[MX] = qssl[DN] * uss; // eq. 39 @@ -595,8 +604,8 @@ wave_hlld(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, qssl[BX] = Bx; // FIXME qssl[BY] = Byss; // eq. 56 qssl[BZ] = Bzss; // eq. 56 - tmp3 = usl*qsl[BX]+vsl*qsl[BY]+wsl*qsl[BZ] - tmp2; - qssl[ER] = qsl[ER] - sqrtl*tmp3*sign; // eq. 63 + tmp3 = usl * qsl[BX] + vsl * qsl[BY] + wsl * qsl[BZ] - tmp2; + qssl[ER] = qsl[ER] - sqrtl * tmp3 * sign; // eq. 63 qssr[DN] = qsr[DN]; // eq. 49 qssr[MX] = qssr[DN] * uss; // eq. 39 @@ -605,8 +614,8 @@ wave_hlld(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, qssr[BX] = Bx; // FIXME qssr[BY] = Byss; // eq. 56 qssr[BZ] = Bzss; // eq. 56 - tmp3 = usr*qsr[BX]+vsr*qsr[BY]+wsr*qsr[BZ] - tmp2; - qssr[ER] = qsr[ER] + sqrtr*tmp3*sign; // eq. 63 + tmp3 = usr * qsr[BX] + vsr * qsr[BY] + wsr * qsr[BZ] - tmp2; + qssr[ER] = qsr[ER] + sqrtr * tmp3 * sign; // eq. 63 // STEP 4. collect all waves and wave speeds speeds[0] = sl; @@ -618,19 +627,29 @@ wave_hlld(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, double *wv; wv = waves; - for (int i=0; i<8; ++i) wv[i] = qsl[i] - ql[i]; + for (int i = 0; i < 8; ++i) { + wv[i] = qsl[i] - ql[i]; + } wv += meqn; - for (int i=0; i<8; ++i) wv[i] = qssl[i] - qsl[i]; + for (int i = 0; i < 8; ++i) { + wv[i] = qssl[i] - qsl[i]; + } wv += meqn; - for (int i=0; i<8; ++i) wv[i] = qssr[i] - qssl[i]; + for (int i = 0; i < 8; ++i) { + wv[i] = qssr[i] - qssl[i]; + } wv += meqn; - for (int i=0; i<8; ++i) wv[i] = qsr[i] - qssr[i]; + for (int i = 0; i < 8; ++i) { + wv[i] = qsr[i] - qssr[i]; + } wv += meqn; - for (int i=0; i<8; ++i) wv[i] = qr[i] - qsr[i]; + for (int i = 0; i < 8; ++i) { + wv[i] = qr[i] - qsr[i]; + } double max_speed = sr; @@ -639,17 +658,17 @@ wave_hlld(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, if (mhd->divergence_constraint == GKYL_MHD_DIVB_EIGHT_WAVES) { speeds[5] = sm; wv += meqn; - for (int i=0; i<8; ++i) wv[i] = 0.0; + for (int i = 0; i < 8; ++i) { + wv[i] = 0.0; + } wv[BX] = dQ[BX]; } // For the GLM Bx and psi waves, solve the linear Riemann problem. // XXX is this correct? TODO create and use a separate glm RP solver - if (mhd->divergence_constraint == GKYL_MHD_DIVB_GLM) - { - for (int w=0; w<5; ++w) - { - waves[w*meqn + PSI_GLM] = 0.0; + if (mhd->divergence_constraint == GKYL_MHD_DIVB_GLM) { + for (int w = 0; w < 5; ++w) { + waves[w * meqn + PSI_GLM] = 0.0; } double ch = mhd->glm_ch; @@ -657,17 +676,21 @@ wave_hlld(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, // L = 0.5*(-ch, 1), R = (-1/ch, 1) speeds[5] = -ch; wv += meqn; - for (int i=0; i<8; ++i) wv[i] = 0.0; - double eta = 0.5 * (-dQ[BX]*ch+dQ[PSI_GLM]); - wv[BX] = -eta/ch; + for (int i = 0; i < 8; ++i) { + wv[i] = 0.0; + } + double eta = 0.5 * (-dQ[BX] * ch + dQ[PSI_GLM]); + wv[BX] = -eta / ch; wv[PSI_GLM] = eta; // L = 0.5*(+ch, 1), R = (+1/ch, 1) speeds[6] = ch; wv += meqn; - for (int i=0; i<8; ++i) wv[i] = 0.0; - eta = 0.5 * (dQ[BX]*ch+dQ[PSI_GLM]); - wv[BX] = eta/ch; + for (int i = 0; i < 8; ++i) { + wv[i] = 0.0; + } + eta = 0.5 * (dQ[BX] * ch + dQ[PSI_GLM]); + wv[BX] = eta / ch; wv[PSI_GLM] = eta; max_speed = max_speed > ch ? max_speed : ch; @@ -676,115 +699,124 @@ wave_hlld(const struct gkyl_wv_eqn *eqn, const double *dQ, const double *ql, return max_speed; } -static void -qfluct_hlld(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, - const double *waves, const double *s, double *amdq, double *apdq) +static void qfluct_hlld( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { int meqn = eqn->num_equations; int mwave = eqn->num_waves; - for (int i=0; igas_gamma, q); - if (pr < 0.0) + if (pr < 0.0) { return false; + } return true; } -static double -max_speed(const struct gkyl_wv_eqn *eqn, const double *q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_mhd *mhd = container_of(eqn, struct wv_mhd, eqn); return gkyl_mhd_max_abs_speed(mhd->gas_gamma, q); } -static inline void -mhd_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void mhd_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < 8; i++) { sout[i] = 0.0; } } -struct gkyl_wv_eqn* -gkyl_wv_mhd_new(const struct gkyl_wv_mhd_inp *inp) +struct gkyl_wv_eqn *gkyl_wv_mhd_new(const struct gkyl_wv_mhd_inp *inp) { struct wv_mhd *mhd = gkyl_malloc(sizeof(struct wv_mhd)); @@ -792,26 +824,26 @@ gkyl_wv_mhd_new(const struct gkyl_wv_mhd_inp *inp) mhd->gas_gamma = inp->gas_gamma; switch (inp->rp_type) { - case WV_MHD_RP_ROE: - mhd->eqn.num_equations = 8; - mhd->eqn.num_waves = 7; - mhd->eqn.waves_func = wave_roe_l; - mhd->eqn.qfluct_func = qfluct_roe_l; - break; - - case WV_MHD_RP_HLLD: - mhd->eqn.num_equations = 8; - mhd->eqn.num_waves = 5; - mhd->eqn.waves_func = wave_hlld_l; - mhd->eqn.qfluct_func = qfluct_hlld_l; - break; - - case WV_MHD_RP_LAX: - mhd->eqn.num_equations = 8; - mhd->eqn.num_waves = 2; - mhd->eqn.waves_func = wave_lax_l; - mhd->eqn.qfluct_func = qfluct_lax_l; - break; + case WV_MHD_RP_ROE: + mhd->eqn.num_equations = 8; + mhd->eqn.num_waves = 7; + mhd->eqn.waves_func = wave_roe_l; + mhd->eqn.qfluct_func = qfluct_roe_l; + break; + + case WV_MHD_RP_HLLD: + mhd->eqn.num_equations = 8; + mhd->eqn.num_waves = 5; + mhd->eqn.waves_func = wave_hlld_l; + mhd->eqn.qfluct_func = qfluct_hlld_l; + break; + + case WV_MHD_RP_LAX: + mhd->eqn.num_equations = 8; + mhd->eqn.num_waves = 2; + mhd->eqn.waves_func = wave_lax_l; + mhd->eqn.qfluct_func = qfluct_lax_l; + break; } mhd->eqn.check_inv_func = check_inv; @@ -824,29 +856,31 @@ gkyl_wv_mhd_new(const struct gkyl_wv_mhd_inp *inp) mhd->divergence_constraint = inp->divergence_constraint; switch (inp->divergence_constraint) { - case GKYL_MHD_DIVB_NONE: - break; - - case GKYL_MHD_DIVB_EIGHT_WAVES: - if (inp->rp_type != WV_MHD_RP_LAX) - mhd->eqn.num_waves += 1; - break; - - case GKYL_MHD_DIVB_GLM: - mhd->eqn.num_equations += 1; - if (inp->rp_type != WV_MHD_RP_LAX) - mhd->eqn.num_waves += 2; - mhd->eqn.cons_to_riem = cons_to_riem_9; - mhd->eqn.riem_to_cons = riem_to_cons_9; - mhd->eqn.rotate_to_local_func = rot_to_local_rect_glm; - mhd->eqn.rotate_to_global_func = rot_to_global_rect_glm; - mhd->glm_ch = inp->glm_ch; - mhd->glm_alpha = inp->glm_alpha; - break; + case GKYL_MHD_DIVB_NONE: + break; + + case GKYL_MHD_DIVB_EIGHT_WAVES: + if (inp->rp_type != WV_MHD_RP_LAX) { + mhd->eqn.num_waves += 1; + } + break; + + case GKYL_MHD_DIVB_GLM: + mhd->eqn.num_equations += 1; + if (inp->rp_type != WV_MHD_RP_LAX) { + mhd->eqn.num_waves += 2; + } + mhd->eqn.cons_to_riem = cons_to_riem_9; + mhd->eqn.riem_to_cons = riem_to_cons_9; + mhd->eqn.rotate_to_local_func = rot_to_local_rect_glm; + mhd->eqn.rotate_to_global_func = rot_to_global_rect_glm; + mhd->glm_ch = inp->glm_ch; + mhd->glm_alpha = inp->glm_alpha; + break; } mhd->eqn.num_diag = mhd->eqn.num_equations; - // probably want to change this to store magnetic, internal and KE + // probably want to change this to store magnetic, internal and KE mhd->eqn.cons_to_diag = gkyl_default_cons_to_diag; mhd->eqn.source_func = mhd_source; @@ -862,38 +896,32 @@ gkyl_wv_mhd_new(const struct gkyl_wv_mhd_inp *inp) // member getters and setters // //////////////////////////////// -double -gkyl_wv_mhd_gas_gamma(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_mhd_gas_gamma(const struct gkyl_wv_eqn *eqn) { const struct wv_mhd *mhd = container_of(eqn, struct wv_mhd, eqn); return mhd->gas_gamma; } -double -gkyl_wv_mhd_divergence_constraint(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_mhd_divergence_constraint(const struct gkyl_wv_eqn *eqn) { const struct wv_mhd *mhd = container_of(eqn, struct wv_mhd, eqn); return mhd->divergence_constraint; } -double -gkyl_wv_mhd_glm_ch(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_mhd_glm_ch(const struct gkyl_wv_eqn *eqn) { const struct wv_mhd *mhd = container_of(eqn, struct wv_mhd, eqn); return mhd->glm_ch; } -double -gkyl_wv_mhd_glm_alpha(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_mhd_glm_alpha(const struct gkyl_wv_eqn *eqn) { const struct wv_mhd *mhd = container_of(eqn, struct wv_mhd, eqn); return mhd->glm_alpha; } -void -gkyl_wv_mhd_set_glm_ch(struct gkyl_wv_eqn* eqn, const double glm_ch) +void gkyl_wv_mhd_set_glm_ch(struct gkyl_wv_eqn *eqn, const double glm_ch) { struct wv_mhd *mhd = container_of(eqn, struct wv_mhd, eqn); mhd->glm_ch = glm_ch; } - diff --git a/moments/zero/wv_reactive_euler.c b/moments/zero/wv_reactive_euler.c index 3174eeb8b4..bf7a658735 100644 --- a/moments/zero/wv_reactive_euler.c +++ b/moments/zero/wv_reactive_euler.c @@ -6,8 +6,9 @@ #include #include -void -gkyl_reactive_euler_prim_vars(double gas_gamma, double energy_of_formation, const double q[6], double v[6]) +void gkyl_reactive_euler_prim_vars( + double gas_gamma, double energy_of_formation, const double q[6], double v[6] +) { double rho = q[0]; double momx = q[1]; @@ -16,7 +17,8 @@ gkyl_reactive_euler_prim_vars(double gas_gamma, double energy_of_formation, cons double Etot = q[4]; double reaction_density = q[5]; - double specific_internal_energy = (Etot / rho) - (0.5 * ((momx * momx) + (momy * momy) + (momz * momz)) / (rho * rho)) - + double specific_internal_energy = + (Etot / rho) - (0.5 * ((momx * momx) + (momy * momy) + (momz * momz)) / (rho * rho)) - (energy_of_formation * ((reaction_density / rho) - 1.0)); v[0] = rho; @@ -30,9 +32,9 @@ gkyl_reactive_euler_prim_vars(double gas_gamma, double energy_of_formation, cons static inline double gkyl_reactive_euler_max_abs_speed(double gas_gamma, double energy_of_formation, const double q[6]) { - double v[6] = { 0.0 }; + double v[6] = {0.0}; gkyl_reactive_euler_prim_vars(gas_gamma, energy_of_formation, q, v); - + double rho = v[0]; double vx = v[1]; double vy = v[2]; @@ -44,10 +46,11 @@ gkyl_reactive_euler_max_abs_speed(double gas_gamma, double energy_of_formation, return fabs(v_mag) + sqrt(gas_gamma * (p / rho)); } -void -gkyl_reactive_euler_flux(double gas_gamma, double energy_of_formation, const double q[6], double flux[6]) +void gkyl_reactive_euler_flux( + double gas_gamma, double energy_of_formation, const double q[6], double flux[6] +) { - double v[6] = { 0.0 }; + double v[6] = {0.0}; gkyl_reactive_euler_prim_vars(gas_gamma, energy_of_formation, q, v); double rho = v[0]; @@ -68,7 +71,7 @@ gkyl_reactive_euler_flux(double gas_gamma, double energy_of_formation, const dou } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 6; i++) { @@ -77,7 +80,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 6; i++) { @@ -85,8 +88,10 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -reactive_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void reactive_euler_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 0; i < 6; i++) { ghost[i] = skin[i]; @@ -95,8 +100,10 @@ reactive_euler_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const doubl ghost[1] = -ghost[1]; } -static void -reactive_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void reactive_euler_no_slip( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { for (int i = 1; i < 4; i++) { ghost[i] = -skin[i]; @@ -107,9 +114,10 @@ reactive_euler_no_slip(const struct gkyl_wv_eqn* eqn, double t, int nc, const do ghost[5] = skin[5]; } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { qlocal[0] = qglobal[0]; qlocal[1] = (qglobal[1] * norm[0]) + (qglobal[2] * norm[1]) + (qglobal[3] * norm[2]); @@ -119,9 +127,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[5] = qglobal[5]; } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { qglobal[0] = qlocal[0]; qglobal[1] = (qlocal[1] * norm[0]) + (qlocal[2] * tau1[0]) + (qlocal[3] * tau2[0]); @@ -131,8 +140,10 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[5] = qlocal[5]; } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_reactive_euler *reactive_euler = container_of(eqn, struct wv_reactive_euler, eqn); double gas_gamma = reactive_euler->gas_gamma; @@ -158,8 +169,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[6]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -171,21 +184,27 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { const struct wv_reactive_euler *reactive_euler = container_of(eqn, struct wv_reactive_euler, eqn); double gas_gamma = reactive_euler->gas_gamma; @@ -194,8 +213,8 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double rho_l = ql[0]; double rho_r = qr[0]; - double vl[6] = { 0.0 }; - double vr[6] = { 0.0 }; + double vl[6] = {0.0}; + double vr[6] = {0.0}; gkyl_reactive_euler_prim_vars(gas_gamma, energy_of_formation, ql, vl); gkyl_reactive_euler_prim_vars(gas_gamma, energy_of_formation, qr, vr); double p_l = vl[4]; @@ -214,12 +233,14 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double reaction_progress = ((ql[5] * roe_avg_l) + (qr[5] * roe_avg_r)) * roe_avg_sq; double vel_sq = ((vx * vx) + (vy * vy) + (vz * vz)); - double a_sq = (gas_gamma - 1.0) * (enth - (0.5 * vel_sq) - (energy_of_formation * (reaction_progress - 1.0))); + double a_sq = + (gas_gamma - 1.0) * (enth - (0.5 * vel_sq) - (energy_of_formation * (reaction_progress - 1.0))); double a = sqrt(a_sq); double gamma1_over_a_sq = (gas_gamma - 1.0) / a_sq; double internal_enth = enth - vel_sq; - double a4 = gamma1_over_a_sq * ((internal_enth * delta[0]) + (vx * delta[1]) + (vy * delta[2]) + (vz * delta[3]) - delta[4]); + double a4 = gamma1_over_a_sq * ((internal_enth * delta[0]) + (vx * delta[1]) + (vy * delta[2]) + + (vz * delta[3]) - delta[4]); double a2 = delta[2] - (vy * delta[0]); double a3 = delta[3] - (vz * delta[0]); double a5 = 0.5 * (delta[1] + (((a - vx) * delta[0]) - (a * a4))) / a; @@ -257,8 +278,10 @@ wave_roe(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return fabs(vx) + a; } -static void -qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[6], *w2 = &waves[12]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); @@ -270,33 +293,35 @@ qfluct_roe(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, double* waves, double* s) +static double wave_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_roe(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_roe_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, const double* waves, const double* s, - double* amdq, double* apdq) +static void qfluct_roe_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_roe(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { const struct wv_reactive_euler *reactive_euler = container_of(eqn, struct wv_reactive_euler, eqn); double gas_gamma = reactive_euler->gas_gamma; @@ -316,26 +341,23 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_reactive_euler *reactive_euler = container_of(eqn, struct wv_reactive_euler, eqn); double gas_gamma = reactive_euler->gas_gamma; double energy_of_formation = reactive_euler->energy_of_formation; - double v[6] = { 0.0 }; + double v[6] = {0.0}; gkyl_reactive_euler_prim_vars(gas_gamma, energy_of_formation, q, v); if (v[0] < 0.0 || v[4] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_reactive_euler *reactive_euler = container_of(eqn, struct wv_reactive_euler, eqn); double gas_gamma = reactive_euler->gas_gamma; @@ -345,7 +367,7 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) } static inline void -reactive_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +reactive_euler_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { for (int i = 0; i < 5; i++) { diag[i] = qin[i]; @@ -353,7 +375,7 @@ reactive_euler_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, do } static inline void -reactive_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +reactive_euler_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { const struct wv_reactive_euler *reactive_euler = container_of(eqn, struct wv_reactive_euler, eqn); double gas_gamma = reactive_euler->gas_gamma; @@ -362,7 +384,7 @@ reactive_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* double ignition_temperature = reactive_euler->ignition_temperature; double reaction_rate = reactive_euler->reaction_rate; - double v[6] = { 0.0 }; + double v[6] = {0.0}; gkyl_reactive_euler_prim_vars(gas_gamma, energy_of_formation, qin, v); double rho = v[0]; @@ -372,7 +394,7 @@ reactive_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* double reaction_progress = v[5]; double specific_internal_energy = (qin[4] / rho) - (0.5 * ((vx * vx) + (vy * vy) + (vz * vz))) - - (energy_of_formation * (reaction_progress - 1.0)); + (energy_of_formation * (reaction_progress - 1.0)); double temperature = specific_internal_energy / specific_heat_capacity; for (int i = 0; i < 5; i++) { @@ -381,20 +403,19 @@ reactive_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* if (temperature > ignition_temperature) { sout[5] = -(rho * reaction_progress * reaction_rate); - } - else { + } else { sout[5] = 0.0; } } -void -gkyl_reactive_euler_free(const struct gkyl_ref_count* ref) +void gkyl_reactive_euler_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. - struct wv_reactive_euler *reactive_euler = container_of(base->on_dev, struct wv_reactive_euler, eqn); + struct wv_reactive_euler *reactive_euler = + container_of(base->on_dev, struct wv_reactive_euler, eqn); gkyl_cu_free(reactive_euler); } @@ -402,24 +423,22 @@ gkyl_reactive_euler_free(const struct gkyl_ref_count* ref) gkyl_free(reactive_euler); } -struct gkyl_wv_eqn* -gkyl_wv_reactive_euler_new(double gas_gamma, double specific_heat_capacity, double energy_of_formation, double ignition_temperature, - double reaction_rate, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_reactive_euler_new( + double gas_gamma, double specific_heat_capacity, double energy_of_formation, + double ignition_temperature, double reaction_rate, bool use_gpu +) { - return gkyl_wv_reactive_euler_inew(&(struct gkyl_wv_reactive_euler_inp) { - .gas_gamma = gas_gamma, - .specific_heat_capacity = specific_heat_capacity, - .energy_of_formation = energy_of_formation, - .ignition_temperature = ignition_temperature, - .reaction_rate = reaction_rate, - .rp_type = WV_REACTIVE_EULER_RP_LAX, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_reactive_euler_inew(&(struct gkyl_wv_reactive_euler_inp + ){.gas_gamma = gas_gamma, + .specific_heat_capacity = specific_heat_capacity, + .energy_of_formation = energy_of_formation, + .ignition_temperature = ignition_temperature, + .reaction_rate = reaction_rate, + .rp_type = WV_REACTIVE_EULER_RP_LAX, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_reactive_euler_inew(const struct gkyl_wv_reactive_euler_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_reactive_euler_inew(const struct gkyl_wv_reactive_euler_inp *inp) { struct wv_reactive_euler *reactive_euler = gkyl_malloc(sizeof(struct wv_reactive_euler)); @@ -437,8 +456,7 @@ gkyl_wv_reactive_euler_inew(const struct gkyl_wv_reactive_euler_inp* inp) reactive_euler->eqn.num_waves = 2; reactive_euler->eqn.waves_func = wave_lax_l; reactive_euler->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_REACTIVE_EULER_RP_ROE) { + } else if (inp->rp_type == WV_REACTIVE_EULER_RP_ROE) { reactive_euler->eqn.num_waves = 3; reactive_euler->eqn.waves_func = wave_roe_l; reactive_euler->eqn.qfluct_func = qfluct_roe_l; @@ -463,15 +481,15 @@ gkyl_wv_reactive_euler_inew(const struct gkyl_wv_reactive_euler_inp* inp) reactive_euler->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(reactive_euler->eqn.flags); reactive_euler->eqn.ref_count = gkyl_ref_count_init(gkyl_reactive_euler_free); - reactive_euler->eqn.on_dev = &reactive_euler->eqn; // On the CPU, the equation object points to itself. + reactive_euler->eqn.on_dev = + &reactive_euler->eqn; // On the CPU, the equation object points to itself. reactive_euler->eqn.embed_geo = NULL; return &reactive_euler->eqn; } -double -gkyl_wv_reactive_euler_gas_gamma(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_reactive_euler_gas_gamma(const struct gkyl_wv_eqn *eqn) { const struct wv_reactive_euler *reactive_euler = container_of(eqn, struct wv_reactive_euler, eqn); double gas_gamma = reactive_euler->gas_gamma; @@ -479,8 +497,7 @@ gkyl_wv_reactive_euler_gas_gamma(const struct gkyl_wv_eqn* eqn) return gas_gamma; } -double -gkyl_wv_reactive_euler_specific_heat_capacity(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_reactive_euler_specific_heat_capacity(const struct gkyl_wv_eqn *eqn) { const struct wv_reactive_euler *reactive_euler = container_of(eqn, struct wv_reactive_euler, eqn); double specific_heat_capacity = reactive_euler->specific_heat_capacity; @@ -488,8 +505,7 @@ gkyl_wv_reactive_euler_specific_heat_capacity(const struct gkyl_wv_eqn* eqn) return specific_heat_capacity; } -double -gkyl_wv_reactive_euler_energy_of_formation(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_reactive_euler_energy_of_formation(const struct gkyl_wv_eqn *eqn) { const struct wv_reactive_euler *reactive_euler = container_of(eqn, struct wv_reactive_euler, eqn); double energy_of_formation = reactive_euler->energy_of_formation; @@ -497,8 +513,7 @@ gkyl_wv_reactive_euler_energy_of_formation(const struct gkyl_wv_eqn* eqn) return energy_of_formation; } -double -gkyl_wv_reactive_euler_ignition_temperature(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_reactive_euler_ignition_temperature(const struct gkyl_wv_eqn *eqn) { const struct wv_reactive_euler *reactive_euler = container_of(eqn, struct wv_reactive_euler, eqn); double ignition_temperature = reactive_euler->ignition_temperature; @@ -506,8 +521,7 @@ gkyl_wv_reactive_euler_ignition_temperature(const struct gkyl_wv_eqn* eqn) return ignition_temperature; } -double -gkyl_wv_reactive_euler_reaction_rate(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_reactive_euler_reaction_rate(const struct gkyl_wv_eqn *eqn) { const struct wv_reactive_euler *reactive_euler = container_of(eqn, struct wv_reactive_euler, eqn); double reaction_rate = reactive_euler->reaction_rate; diff --git a/moments/zero/wv_sr_euler.c b/moments/zero/wv_sr_euler.c index 65203c1d5e..7606d304b3 100644 --- a/moments/zero/wv_sr_euler.c +++ b/moments/zero/wv_sr_euler.c @@ -9,8 +9,7 @@ struct wv_sr_euler { double gas_gamma; // gas adiabatic constant }; -static void -sr_euler_free(const struct gkyl_ref_count *ref) +static void sr_euler_free(const struct gkyl_ref_count *ref) { struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); struct wv_sr_euler *sr_euler = container_of(base, struct wv_sr_euler, eqn); @@ -18,167 +17,173 @@ sr_euler_free(const struct gkyl_ref_count *ref) } static inline void -cons_to_riem(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *qin, double *wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: this should use proper L matrix - for (int i=0; i<5; ++i) + for (int i = 0; i < 5; ++i) { wout[i] = qin[i]; + } } static inline void -riem_to_cons(const struct gkyl_wv_eqn *eqn, - const double *qstate, const double *win, double *qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: this should use proper L matrix - for (int i=0; i<5; ++i) + for (int i = 0; i < 5; ++i) { qout[i] = win[i]; + } } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qglobal, double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { // Mass density and energy are scalars qlocal[0] = qglobal[0]; qlocal[1] = qglobal[1]; // Rotate momentum to local coordinates - qlocal[2] = qglobal[2]*norm[0] + qglobal[3]*norm[1] + qglobal[4]*norm[2]; - qlocal[3] = qglobal[2]*tau1[0] + qglobal[3]*tau1[1] + qglobal[4]*tau1[2]; - qlocal[4] = qglobal[2]*tau2[0] + qglobal[3]*tau2[1] + qglobal[4]*tau2[2]; + qlocal[2] = qglobal[2] * norm[0] + qglobal[3] * norm[1] + qglobal[4] * norm[2]; + qlocal[3] = qglobal[2] * tau1[0] + qglobal[3] * tau1[1] + qglobal[4] * tau1[2]; + qlocal[4] = qglobal[2] * tau2[0] + qglobal[3] * tau2[1] + qglobal[4] * tau2[2]; } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, - const double* GKYL_RESTRICT qlocal, double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { // Mass density and energy are scalars qglobal[0] = qlocal[0]; qglobal[1] = qlocal[1]; // Rotate momentum back to global coordinates - qglobal[2] = qlocal[2]*norm[0] + qlocal[3]*tau1[0] + qlocal[4]*tau2[0]; - qglobal[3] = qlocal[2]*norm[1] + qlocal[3]*tau1[1] + qlocal[4]*tau2[1]; - qglobal[4] = qlocal[2]*norm[2] + qlocal[3]*tau1[2] + qlocal[4]*tau2[2]; - + qglobal[2] = qlocal[2] * norm[0] + qlocal[3] * tau1[0] + qlocal[4] * tau2[0]; + qglobal[3] = qlocal[2] * norm[1] + qlocal[3] * tau1[1] + qlocal[4] * tau2[1]; + qglobal[4] = qlocal[2] * norm[2] + qlocal[3] * tau1[2] + qlocal[4] * tau2[2]; } // Waves and speeds using Roe averaging -static double -wave_roe(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *delta, const double *ql, const double *qr, - const double phil, const double phir, double *waves, double *s) +static double wave_roe( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { const struct wv_sr_euler *sr_euler = container_of(eqn, struct wv_sr_euler, eqn); double vl[5], vr[5]; double gas_gamma = sr_euler->gas_gamma; double g1 = gas_gamma - 1.; - double gFrac = gas_gamma/g1; + double gFrac = gas_gamma / g1; - // Get prim variables rho, p, u, v, w. + // Get prim variables rho, p, u, v, w. gkyl_sr_euler_prim_vars(gas_gamma, ql, vl); gkyl_sr_euler_prim_vars(gas_gamma, qr, vr); - double gammal = 1. / sqrt(1. - (vl[2]*vl[2] + vl[3]*vl[3] + vl[4]*vl[4])); + double gammal = 1. / sqrt(1. - (vl[2] * vl[2] + vl[3] * vl[3] + vl[4] * vl[4])); double pl = vl[1]; - double gammar = 1. / sqrt(1. - (vr[2]*vr[2] + vr[3]*vr[3] + vr[4]*vr[4])); + double gammar = 1. / sqrt(1. - (vr[2] * vr[2] + vr[3] * vr[3] + vr[4] * vr[4])); double pr = vr[1]; - + //Equation numbers in all of the following follows Eulderink AASS 110, 587 (1995) //Roe Averages //double Kl = sqrt(rhol + gFrac*pl), Kr = sqrt(rhor + gFrac*pr); //sqrt(10.3) - - double Kl = sqrt(ql[1] + pl) / gammal, Kr = sqrt(qr[1] + pr) / gammar; //sqrt(10.3) - double ravgK = 1./(Kl + Kr); - double v0 = (Kl*gammal + Kr*gammar)*ravgK; //10.7 - double v1 = (Kl*gammal*vl[2] + Kr*gammar*vr[2])*ravgK; - double v2 = (Kl*gammal*vl[3] + Kr*gammar*vr[3])*ravgK; - double v3 = (Kl*gammal*vl[4] + Kr*gammar*vr[4])*ravgK; - double v4 = (pl/Kl + pr/Kr)*ravgK; - double cm = 1. - gFrac*v4, cp = 1. + gFrac*v4; - - double vava = -v0*v0 + v1*v1 + v2*v2 + v3*v3; //v_alpha v^alpha - - double s2 = 0.5*gas_gamma*v4*(1-vava) - 0.5*g1*(1+vava); //10.13 - double e = v0*v0 - v1*v1; //10.14 - double y = sqrt((1-gas_gamma*v4)*e + s2); //10.14 - - + + double Kl = sqrt(ql[1] + pl) / gammal, Kr = sqrt(qr[1] + pr) / gammar; //sqrt(10.3) + double ravgK = 1. / (Kl + Kr); + double v0 = (Kl * gammal + Kr * gammar) * ravgK; //10.7 + double v1 = (Kl * gammal * vl[2] + Kr * gammar * vr[2]) * ravgK; + double v2 = (Kl * gammal * vl[3] + Kr * gammar * vr[3]) * ravgK; + double v3 = (Kl * gammal * vl[4] + Kr * gammar * vr[4]) * ravgK; + double v4 = (pl / Kl + pr / Kr) * ravgK; + double cm = 1. - gFrac * v4, cp = 1. + gFrac * v4; + + double vava = -v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3; //v_alpha v^alpha + + double s2 = 0.5 * gas_gamma * v4 * (1 - vava) - 0.5 * g1 * (1 + vava); //10.13 + double e = v0 * v0 - v1 * v1; //10.14 + double y = sqrt((1 - gas_gamma * v4) * e + s2); //10.14 + // Compute projections of jump, Eq 10.16 - double k = v0*delta[1] - v1*delta[2]; - double vada = -v0*delta[1] + v1*delta[2] + v2*delta[3] + v3*delta[4]; // v_alpha Delta^alpha - double a1 = -(s2*k + sqrt(s2)*y*(v0*delta[2] - v1*delta[1]) + g1*e*(delta[0]+cp*vada))/(2.*e*s2); - double a2 = -(s2*k - sqrt(s2)*y*(v0*delta[2] - v1*delta[1]) + g1*e*(delta[0]+cp*vada))/(2.*e*s2); - double a3 = (2.*s2*k + g1*e*(delta[0]+cp*vada))/(e*s2); - double a4 = delta[3] - k*v2 / e; - double a5 = delta[4] - k*v3 / e; + double k = v0 * delta[1] - v1 * delta[2]; + double vada = + -v0 * delta[1] + v1 * delta[2] + v2 * delta[3] + v3 * delta[4]; // v_alpha Delta^alpha + double a1 = + -(s2 * k + sqrt(s2) * y * (v0 * delta[2] - v1 * delta[1]) + g1 * e * (delta[0] + cp * vada)) / + (2. * e * s2); + double a2 = + -(s2 * k - sqrt(s2) * y * (v0 * delta[2] - v1 * delta[1]) + g1 * e * (delta[0] + cp * vada)) / + (2. * e * s2); + double a3 = (2. * s2 * k + g1 * e * (delta[0] + cp * vada)) / (e * s2); + double a4 = delta[3] - k * v2 / e; + double a5 = delta[4] - k * v3 / e; double *wv; - // Wave 1: eigenvalue is lambda- + // Wave 1: eigenvalue is lambda- wv = &waves[0]; - wv[0] = a1*cm; - wv[1] = a1*(v0-sqrt(s2)*v1/y); - wv[2] = a1*(v1-sqrt(s2)*v0/y); - wv[3] = a1*v2; - wv[4] = a1*v3; - s[0] = ((1.-gas_gamma*v4)*v0*v1 - sqrt(s2)*y)/((1.-gas_gamma*v4)*v0*v0+s2);//10.12 + wv[0] = a1 * cm; + wv[1] = a1 * (v0 - sqrt(s2) * v1 / y); + wv[2] = a1 * (v1 - sqrt(s2) * v0 / y); + wv[3] = a1 * v2; + wv[4] = a1 * v3; + s[0] = ((1. - gas_gamma * v4) * v0 * v1 - sqrt(s2) * y) / + ((1. - gas_gamma * v4) * v0 * v0 + s2); //10.12 // Wave 2: eigenvalue is u, u, u three waves are lumped into one wv = &waves[5]; - wv[0] = a3*(cm+s2/g1) - a4*cp*v2 - a5*cp*v3; - wv[1] = a3*v0; - wv[2] = a3*v1; - wv[3] = a3*v2 + a4; - wv[4] = a3*v3 + a5; + wv[0] = a3 * (cm + s2 / g1) - a4 * cp * v2 - a5 * cp * v3; + wv[1] = a3 * v0; + wv[2] = a3 * v1; + wv[3] = a3 * v2 + a4; + wv[4] = a3 * v3 + a5; s[1] = v1 / v0; // Wave 3: eigenvalue is lambda+ wv = &waves[10]; - wv[0] = a2*cm; - wv[1] = a2*(v0+sqrt(s2)*v1/y); - wv[2] = a2*(v1+sqrt(s2)*v0/y); - wv[3] = a2*v2; - wv[4] = a2*v3;; - s[2] = ((1.-gas_gamma*v4)*v0*v1 + sqrt(s2)*y)/((1.-gas_gamma*v4)*v0*v0+s2);//10.12 - - return ((1.-gas_gamma*v4)*v0*fabs(v1) + sqrt(s2)*y)/((1.-gas_gamma*v4)*v0*v0+s2); + wv[0] = a2 * cm; + wv[1] = a2 * (v0 + sqrt(s2) * v1 / y); + wv[2] = a2 * (v1 + sqrt(s2) * v0 / y); + wv[3] = a2 * v2; + wv[4] = a2 * v3; + ; + s[2] = ((1. - gas_gamma * v4) * v0 * v1 + sqrt(s2) * y) / + ((1. - gas_gamma * v4) * v0 * v0 + s2); //10.12 + + return ((1. - gas_gamma * v4) * v0 * fabs(v1) + sqrt(s2) * y) / + ((1. - gas_gamma * v4) * v0 * v0 + s2); } -static void -qfluct_roe(const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, - const double *ql, const double *qr, const double phil, const double phir, const double *waves, const double *s, - double *amdq, double *apdq) +static void qfluct_roe( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[5], *w2 = &waves[10]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]), s2m = fmin(0.0, s[2]); double s0p = fmax(0.0, s[0]), s1p = fmax(0.0, s[1]), s2p = fmax(0.0, s[2]); - for (int i=0; i<5; ++i) { - amdq[i] = s0m*w0[i] + s1m*w1[i] + s2m*w2[i]; - apdq[i] = s0p*w0[i] + s1p*w1[i] + s2p*w2[i]; + for (int i = 0; i < 5; ++i) { + amdq[i] = s0m * w0[i] + s1m * w1[i] + s2m * w2[i]; + apdq[i] = s0p * w0[i] + s1p * w1[i] + s2p * w2[i]; } } -static bool -check_inv(const struct gkyl_wv_eqn *eqn, const double *q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { return true; // TODO } -static double -max_speed(const struct gkyl_wv_eqn *eqn, const double *q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { const struct wv_sr_euler *sr_euler = container_of(eqn, struct wv_sr_euler, eqn); return gkyl_sr_euler_max_abs_speed(sr_euler->gas_gamma, q); } -static inline void -sr_euler_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void sr_euler_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < 5; i++) { sout[i] = 0.0; } } -struct gkyl_wv_eqn* -gkyl_wv_sr_euler_new(double gas_gamma) +struct gkyl_wv_eqn *gkyl_wv_sr_euler_new(double gas_gamma) { struct wv_sr_euler *sr_euler = gkyl_malloc(sizeof(struct wv_sr_euler)); @@ -186,7 +191,7 @@ gkyl_wv_sr_euler_new(double gas_gamma) sr_euler->eqn.num_equations = 5; sr_euler->eqn.num_waves = 3; sr_euler->eqn.num_diag = 5; - + sr_euler->gas_gamma = gas_gamma; sr_euler->eqn.waves_func = wave_roe; sr_euler->eqn.qfluct_func = qfluct_roe; @@ -208,8 +213,7 @@ gkyl_wv_sr_euler_new(double gas_gamma) return &sr_euler->eqn; } -double -gkyl_wv_sr_euler_gas_gamma(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_sr_euler_gas_gamma(const struct gkyl_wv_eqn *eqn) { const struct wv_sr_euler *sr_euler = container_of(eqn, struct wv_sr_euler, eqn); return sr_euler->gas_gamma; diff --git a/moments/zero/wv_ten_moment.c b/moments/zero/wv_ten_moment.c index bed7d70ed5..ca64129947 100644 --- a/moments/zero/wv_ten_moment.c +++ b/moments/zero/wv_ten_moment.c @@ -6,8 +6,7 @@ #include #include -void -gkyl_ten_moment_free(const struct gkyl_ref_count *ref) +void gkyl_ten_moment_free(const struct gkyl_ref_count *ref) { struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); @@ -21,29 +20,29 @@ gkyl_ten_moment_free(const struct gkyl_ref_count *ref) gkyl_free(ten_moment); } -static inline void -ten_moment_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +static inline void ten_moment_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { for (int i = 0; i < 10; i++) { sout[i] = 0.0; } } -struct gkyl_wv_eqn* -gkyl_wv_ten_moment_inew(const struct gkyl_wv_ten_moment_inp *inp) +struct gkyl_wv_eqn *gkyl_wv_ten_moment_inew(const struct gkyl_wv_ten_moment_inp *inp) { double k0 = inp->k0; bool use_grad_closure = inp->use_grad_closure; bool use_nn_closure = inp->use_nn_closure; int poly_order = inp->poly_order; - struct gkyl_kann_net* ann = inp->ann; + struct gkyl_kann_net *ann = inp->ann; bool use_gpu = inp->use_gpu; #ifdef GKYL_HAVE_CUDA if (use_gpu) { - return gkyl_wv_ten_moment_cu_dev_new(k0, use_grad_closure, use_nn_closure, poly_order, ann, use_gpu); - } -#endif + return gkyl_wv_ten_moment_cu_dev_new( + k0, use_grad_closure, use_nn_closure, poly_order, ann, use_gpu + ); + } +#endif struct wv_ten_moment *ten_moment = gkyl_malloc(sizeof(struct wv_ten_moment)); ten_moment->k0 = k0; @@ -56,7 +55,7 @@ gkyl_wv_ten_moment_inew(const struct gkyl_wv_ten_moment_inp *inp) ten_moment->eqn.num_equations = 10; ten_moment->eqn.num_waves = 5; ten_moment->eqn.num_diag = 10; - + ten_moment->eqn.waves_func = wave; ten_moment->eqn.qfluct_func = qfluct; @@ -82,70 +81,65 @@ gkyl_wv_ten_moment_inew(const struct gkyl_wv_ten_moment_inp *inp) ten_moment->eqn.embed_geo = inp->embed_geo; if (ten_moment->eqn.embed_geo) { switch (ten_moment->eqn.embed_geo->type) { - case GKYL_EMBED_ABSORB: - ten_moment->eqn.embed_geo->embed_func = wave_embed_absorb; - break; + case GKYL_EMBED_ABSORB: + ten_moment->eqn.embed_geo->embed_func = wave_embed_absorb; + break; - case GKYL_EMBED_REFLECT: - ten_moment->eqn.embed_geo->embed_func = wave_embed_reflect; - break; + case GKYL_EMBED_REFLECT: + ten_moment->eqn.embed_geo->embed_func = wave_embed_reflect; + break; - case GKYL_EMBED_FUNC: - break; // already set by gkyl_wv_embed_geo_new + case GKYL_EMBED_FUNC: + break; // already set by gkyl_wv_embed_geo_new - default: - assert(false); - break; + default: + assert(false); + break; } - } + } return &ten_moment->eqn; } -struct gkyl_wv_eqn* -gkyl_wv_ten_moment_new(double k0, bool use_grad_closure, bool use_nn_closure, int poly_order, struct gkyl_kann_net* ann, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_ten_moment_new( + double k0, bool use_grad_closure, bool use_nn_closure, int poly_order, struct gkyl_kann_net *ann, + bool use_gpu +) { - return gkyl_wv_ten_moment_inew( &(struct gkyl_wv_ten_moment_inp) { - .k0 = k0, - .use_grad_closure = use_grad_closure, - .use_nn_closure = use_nn_closure, - .poly_order = poly_order, - .ann = ann, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_ten_moment_inew(&(struct gkyl_wv_ten_moment_inp + ){.k0 = k0, + .use_grad_closure = use_grad_closure, + .use_nn_closure = use_nn_closure, + .poly_order = poly_order, + .ann = ann, + .use_gpu = use_gpu}); } -double -gkyl_wv_ten_moment_k0(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_ten_moment_k0(const struct gkyl_wv_eqn *eqn) { const struct wv_ten_moment *tm = container_of(eqn, struct wv_ten_moment, eqn); return tm->k0; } -bool -gkyl_wv_ten_moment_use_grad_closure(const struct gkyl_wv_eqn* eqn) +bool gkyl_wv_ten_moment_use_grad_closure(const struct gkyl_wv_eqn *eqn) { const struct wv_ten_moment *tm = container_of(eqn, struct wv_ten_moment, eqn); return tm->use_grad_closure; } -bool -gkyl_wv_ten_moment_use_nn_closure(const struct gkyl_wv_eqn* eqn) +bool gkyl_wv_ten_moment_use_nn_closure(const struct gkyl_wv_eqn *eqn) { const struct wv_ten_moment *tm = container_of(eqn, struct wv_ten_moment, eqn); return tm->use_nn_closure; } -int -gkyl_wv_ten_moment_poly_order(const struct gkyl_wv_eqn* eqn) +int gkyl_wv_ten_moment_poly_order(const struct gkyl_wv_eqn *eqn) { const struct wv_ten_moment *tm = container_of(eqn, struct wv_ten_moment, eqn); return tm->poly_order; } -struct gkyl_kann_net* -gkyl_wv_ten_moment_ann(const struct gkyl_wv_eqn* eqn) +struct gkyl_kann_net *gkyl_wv_ten_moment_ann(const struct gkyl_wv_eqn *eqn) { const struct wv_ten_moment *tm = container_of(eqn, struct wv_ten_moment, eqn); return tm->ann; diff --git a/moments/zero/wv_ten_moment_cu.cu b/moments/zero/wv_ten_moment_cu.cu index a240259aaa..40d4e32b96 100644 --- a/moments/zero/wv_ten_moment_cu.cu +++ b/moments/zero/wv_ten_moment_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include } @@ -11,8 +11,7 @@ extern "C" { // CUDA kernel to set device pointers to ten moment kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -wv_ten_moment_set_cu_dev_ptrs(struct wv_ten_moment *ten_moment) +__global__ static void wv_ten_moment_set_cu_dev_ptrs(struct wv_ten_moment *ten_moment) { ten_moment->eqn.waves_func = wave; ten_moment->eqn.qfluct_func = qfluct; @@ -30,17 +29,17 @@ wv_ten_moment_set_cu_dev_ptrs(struct wv_ten_moment *ten_moment) ten_moment->eqn.cons_to_diag = gkyl_default_cons_to_diag; } -struct gkyl_wv_eqn* -gkyl_wv_ten_moment_cu_dev_inew(const struct gkyl_wv_ten_moment_inp *inp) +struct gkyl_wv_eqn *gkyl_wv_ten_moment_cu_dev_inew(const struct gkyl_wv_ten_moment_inp *inp) { double k0 = inp->k0; bool use_grad_closure = inp->use_grad_closure; bool use_nn_closure = inp->use_nn_closure; int poly_order = inp->poly_order; - struct gkyl_kann_net* ann = inp->ann; + struct gkyl_kann_net *ann = inp->ann; bool use_gpu = inp->use_gpu; - struct wv_ten_moment *ten_moment = (struct wv_ten_moment*) gkyl_malloc(sizeof(struct wv_ten_moment)); + struct wv_ten_moment *ten_moment = + (struct wv_ten_moment *)gkyl_malloc(sizeof(struct wv_ten_moment)); ten_moment->k0 = k0; ten_moment->use_grad_closure = use_grad_closure; @@ -58,17 +57,20 @@ gkyl_wv_ten_moment_cu_dev_inew(const struct gkyl_wv_ten_moment_inp *inp) ten_moment->eqn.ref_count = gkyl_ref_count_init(gkyl_ten_moment_free); // copy the host struct to device struct - struct wv_ten_moment *ten_moment_cu = (struct wv_ten_moment*) gkyl_cu_malloc(sizeof(struct wv_ten_moment)); + struct wv_ten_moment *ten_moment_cu = + (struct wv_ten_moment *)gkyl_cu_malloc(sizeof(struct wv_ten_moment)); gkyl_cu_memcpy(ten_moment_cu, ten_moment, sizeof(struct wv_ten_moment), GKYL_CU_MEMCPY_H2D); - wv_ten_moment_set_cu_dev_ptrs<<<1,1>>>(ten_moment_cu); + wv_ten_moment_set_cu_dev_ptrs<<<1, 1> > >(ten_moment_cu); ten_moment->eqn.on_dev = &ten_moment_cu->eqn; // CPU eqn obj points to itself return &ten_moment->eqn; } -struct gkyl_wv_eqn* -gkyl_wv_ten_moment_cu_dev_new(double k0, bool use_grad_closure, bool use_nn_closure, int poly_order, struct gkyl_kann_net* ann, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_ten_moment_cu_dev_new( + double k0, bool use_grad_closure, bool use_nn_closure, int poly_order, struct gkyl_kann_net *ann, + bool use_gpu +) { struct gkyl_wv_ten_moment_inp ten_moment_inp = { .k0 = k0, @@ -76,7 +78,7 @@ gkyl_wv_ten_moment_cu_dev_new(double k0, bool use_grad_closure, bool use_nn_clos .use_nn_closure = use_nn_closure, .poly_order = poly_order, .ann = ann, - .use_gpu = use_gpu, + .use_gpu = use_gpu }; return gkyl_wv_ten_moment_cu_dev_inew(&ten_moment_inp); diff --git a/moments/zero/wv_vacuum_einstein.c b/moments/zero/wv_vacuum_einstein.c index 02a7000889..0e5ba05d39 100644 --- a/moments/zero/wv_vacuum_einstein.c +++ b/moments/zero/wv_vacuum_einstein.c @@ -6,34 +6,65 @@ #include #include -void -gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, enum gkyl_spacetime_evolution spacetime_evolution, - const double q[64], double flux[64]) +void gkyl_vacuum_einstein_flux( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, + enum gkyl_spacetime_evolution spacetime_evolution, const double q[64], double flux[64] +) { double spatial_metric[3][3]; - spatial_metric[0][0] = q[0]; spatial_metric[0][1] = q[1]; spatial_metric[0][2] = q[2]; - spatial_metric[1][0] = q[3]; spatial_metric[1][1] = q[4]; spatial_metric[1][2] = q[5]; - spatial_metric[2][0] = q[6]; spatial_metric[2][1] = q[7]; spatial_metric[2][2] = q[8]; + spatial_metric[0][0] = q[0]; + spatial_metric[0][1] = q[1]; + spatial_metric[0][2] = q[2]; + spatial_metric[1][0] = q[3]; + spatial_metric[1][1] = q[4]; + spatial_metric[1][2] = q[5]; + spatial_metric[2][0] = q[6]; + spatial_metric[2][1] = q[7]; + spatial_metric[2][2] = q[8]; double lapse = q[9]; double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = q[10]; extrinsic_curvature[0][1] = q[11]; extrinsic_curvature[0][2] = q[12]; - extrinsic_curvature[1][0] = q[13]; extrinsic_curvature[1][1] = q[14]; extrinsic_curvature[1][2] = q[15]; - extrinsic_curvature[2][0] = q[16]; extrinsic_curvature[2][1] = q[17]; extrinsic_curvature[2][2] = q[18]; + extrinsic_curvature[0][0] = q[10]; + extrinsic_curvature[0][1] = q[11]; + extrinsic_curvature[0][2] = q[12]; + extrinsic_curvature[1][0] = q[13]; + extrinsic_curvature[1][1] = q[14]; + extrinsic_curvature[1][2] = q[15]; + extrinsic_curvature[2][0] = q[16]; + extrinsic_curvature[2][1] = q[17]; + extrinsic_curvature[2][2] = q[18]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = q[19]; spatial_metric_der[0][0][1] = q[20]; spatial_metric_der[0][0][2] = q[21]; - spatial_metric_der[0][1][0] = q[22]; spatial_metric_der[0][1][1] = q[23]; spatial_metric_der[0][1][2] = q[24]; - spatial_metric_der[0][2][0] = q[25]; spatial_metric_der[0][2][1] = q[26]; spatial_metric_der[0][2][2] = q[27]; - - spatial_metric_der[1][0][0] = q[28]; spatial_metric_der[1][0][1] = q[29]; spatial_metric_der[1][0][2] = q[30]; - spatial_metric_der[1][1][0] = q[31]; spatial_metric_der[1][1][1] = q[32]; spatial_metric_der[1][1][2] = q[33]; - spatial_metric_der[1][2][0] = q[34]; spatial_metric_der[1][2][1] = q[35]; spatial_metric_der[1][2][2] = q[36]; - - spatial_metric_der[2][0][0] = q[37]; spatial_metric_der[2][0][1] = q[38]; spatial_metric_der[2][0][2] = q[39]; - spatial_metric_der[2][1][0] = q[40]; spatial_metric_der[2][1][1] = q[41]; spatial_metric_der[2][1][2] = q[42]; - spatial_metric_der[2][2][0] = q[43]; spatial_metric_der[2][2][1] = q[44]; spatial_metric_der[2][2][2] = q[45]; + spatial_metric_der[0][0][0] = q[19]; + spatial_metric_der[0][0][1] = q[20]; + spatial_metric_der[0][0][2] = q[21]; + spatial_metric_der[0][1][0] = q[22]; + spatial_metric_der[0][1][1] = q[23]; + spatial_metric_der[0][1][2] = q[24]; + spatial_metric_der[0][2][0] = q[25]; + spatial_metric_der[0][2][1] = q[26]; + spatial_metric_der[0][2][2] = q[27]; + + spatial_metric_der[1][0][0] = q[28]; + spatial_metric_der[1][0][1] = q[29]; + spatial_metric_der[1][0][2] = q[30]; + spatial_metric_der[1][1][0] = q[31]; + spatial_metric_der[1][1][1] = q[32]; + spatial_metric_der[1][1][2] = q[33]; + spatial_metric_der[1][2][0] = q[34]; + spatial_metric_der[1][2][1] = q[35]; + spatial_metric_der[1][2][2] = q[36]; + + spatial_metric_der[2][0][0] = q[37]; + spatial_metric_der[2][0][1] = q[38]; + spatial_metric_der[2][0][2] = q[39]; + spatial_metric_der[2][1][0] = q[40]; + spatial_metric_der[2][1][1] = q[41]; + spatial_metric_der[2][1][2] = q[42]; + spatial_metric_der[2][2][0] = q[43]; + spatial_metric_der[2][2][1] = q[44]; + spatial_metric_der[2][2][2] = q[45]; double lapse_der[3]; lapse_der[0] = q[46]; @@ -51,9 +82,15 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing shift_vect[2] = q[54]; double shift_vect_der[3][3]; - shift_vect_der[0][0] = q[55]; shift_vect_der[0][1] = q[56]; shift_vect_der[0][2] = q[57]; - shift_vect_der[1][0] = q[58]; shift_vect_der[1][1] = q[59]; shift_vect_der[1][2] = q[60]; - shift_vect_der[2][0] = q[61]; shift_vect_der[2][1] = q[62]; shift_vect_der[2][2] = q[63]; + shift_vect_der[0][0] = q[55]; + shift_vect_der[0][1] = q[56]; + shift_vect_der[0][2] = q[57]; + shift_vect_der[1][0] = q[58]; + shift_vect_der[1][1] = q[59]; + shift_vect_der[1][2] = q[60]; + shift_vect_der[2][0] = q[61]; + shift_vect_der[2][1] = q[62]; + shift_vect_der[2][2] = q[63]; bool in_excision_region = false; if (lapse < excision_threshold) { @@ -61,7 +98,7 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing } if (!in_excision_region) { - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -71,8 +108,7 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing double evolution_func = 0.0; if (spacetime_evolution == GKYL_RICCI_EVOLUTION) { evolution_func = 0.0; - } - else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { + } else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { evolution_func = 1.0; } @@ -86,11 +122,9 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing double slicing_func = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { slicing_func = extrinsic_curvature_trace; - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { slicing_func = 2.0 * extrinsic_curvature_trace / lapse; } @@ -99,9 +133,10 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1[k][i][j] += inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; + spatial_metric_der_raised1[k][i][j] += + inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; } } } @@ -114,7 +149,8 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3[i][j][k] += inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; + spatial_metric_der_raised3[i][j][k] += + inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; } } } @@ -123,7 +159,7 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing double aux_vect_raised[3]; for (int k = 0; k < 3; k++) { aux_vect_raised[k] = 0.0; - + for (int l = 0; l < 3; l++) { aux_vect_raised[k] += inv_spatial_metric[k][l] * aux_vect[l]; } @@ -147,7 +183,8 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - shift_vect_der_switched[i][k] += inv_spatial_metric[i][l] * spatial_metric[m][k] * shift_vect_der[l][m]; + shift_vect_der_switched[i][k] += + inv_spatial_metric[i][l] * spatial_metric[m][k] * shift_vect_der[l][m]; } } } @@ -156,7 +193,8 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing double symmetrized_shift[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - symmetrized_shift[i][j] = (1.0 / lapse) * (shift_vect_der_lowered[i][j] + shift_vect_der_lowered[j][i]); + symmetrized_shift[i][j] = + (1.0 / lapse) * (shift_vect_der_lowered[i][j] + shift_vect_der_lowered[j][i]); } } @@ -165,7 +203,8 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing for (int j = 0; j < 3; j++) { extrinsic_curvature_flux[i][j] = -shift_vect[0] * extrinsic_curvature[i][j]; extrinsic_curvature_flux[i][j] += lapse * spatial_metric_der_raised1[0][i][j]; - extrinsic_curvature_flux[i][j] -= lapse * (0.5 * evolution_func) * aux_vect_raised[0] * spatial_metric[i][j]; + extrinsic_curvature_flux[i][j] -= + lapse * (0.5 * evolution_func) * aux_vect_raised[0] * spatial_metric[i][j]; if (i == 0) { extrinsic_curvature_flux[i][j] += 0.5 * lapse * lapse_der[j]; @@ -196,7 +235,8 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing spatial_metric_der_flux[0][i][j] -= shift_vect[r] * spatial_metric_der[r][i][j]; } - spatial_metric_der_flux[0][i][j] += lapse * (extrinsic_curvature[i][j] - symmetrized_shift[i][j]); + spatial_metric_der_flux[0][i][j] += + lapse * (extrinsic_curvature[i][j] - symmetrized_shift[i][j]); } } @@ -215,26 +255,50 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing aux_vect_flux[i] += shift_vect_der_switched[0][i]; aux_vect_flux[i] -= shift_vect_der[i][0]; } - + for (int i = 0; i < 10; i++) { flux[i] = 0.0; } - flux[10] = extrinsic_curvature_flux[0][0]; flux[11] = extrinsic_curvature_flux[0][1]; flux[12] = extrinsic_curvature_flux[0][2]; - flux[13] = extrinsic_curvature_flux[1][0]; flux[14] = extrinsic_curvature_flux[1][1]; flux[15] = extrinsic_curvature_flux[1][2]; - flux[16] = extrinsic_curvature_flux[2][0]; flux[17] = extrinsic_curvature_flux[2][1]; flux[18] = extrinsic_curvature_flux[2][2]; - - flux[19] = spatial_metric_der_flux[0][0][0]; flux[20] = spatial_metric_der_flux[0][0][1]; flux[21] = spatial_metric_der_flux[0][0][2]; - flux[22] = spatial_metric_der_flux[0][1][0]; flux[23] = spatial_metric_der_flux[0][1][1]; flux[24] = spatial_metric_der_flux[0][1][2]; - flux[25] = spatial_metric_der_flux[0][2][0]; flux[26] = spatial_metric_der_flux[0][2][1]; flux[27] = spatial_metric_der_flux[0][2][2]; - - flux[28] = spatial_metric_der_flux[1][0][0]; flux[29] = spatial_metric_der_flux[1][0][1]; flux[30] = spatial_metric_der_flux[1][0][2]; - flux[31] = spatial_metric_der_flux[1][1][0]; flux[32] = spatial_metric_der_flux[1][1][1]; flux[33] = spatial_metric_der_flux[1][1][2]; - flux[34] = spatial_metric_der_flux[1][2][0]; flux[35] = spatial_metric_der_flux[1][2][1]; flux[36] = spatial_metric_der_flux[1][2][2]; - - flux[37] = spatial_metric_der_flux[2][0][0]; flux[38] = spatial_metric_der_flux[2][0][1]; flux[39] = spatial_metric_der_flux[2][0][2]; - flux[40] = spatial_metric_der_flux[2][1][0]; flux[41] = spatial_metric_der_flux[2][1][1]; flux[42] = spatial_metric_der_flux[2][1][2]; - flux[43] = spatial_metric_der_flux[2][2][0]; flux[44] = spatial_metric_der_flux[2][2][1]; flux[45] = spatial_metric_der_flux[2][2][2]; + flux[10] = extrinsic_curvature_flux[0][0]; + flux[11] = extrinsic_curvature_flux[0][1]; + flux[12] = extrinsic_curvature_flux[0][2]; + flux[13] = extrinsic_curvature_flux[1][0]; + flux[14] = extrinsic_curvature_flux[1][1]; + flux[15] = extrinsic_curvature_flux[1][2]; + flux[16] = extrinsic_curvature_flux[2][0]; + flux[17] = extrinsic_curvature_flux[2][1]; + flux[18] = extrinsic_curvature_flux[2][2]; + + flux[19] = spatial_metric_der_flux[0][0][0]; + flux[20] = spatial_metric_der_flux[0][0][1]; + flux[21] = spatial_metric_der_flux[0][0][2]; + flux[22] = spatial_metric_der_flux[0][1][0]; + flux[23] = spatial_metric_der_flux[0][1][1]; + flux[24] = spatial_metric_der_flux[0][1][2]; + flux[25] = spatial_metric_der_flux[0][2][0]; + flux[26] = spatial_metric_der_flux[0][2][1]; + flux[27] = spatial_metric_der_flux[0][2][2]; + + flux[28] = spatial_metric_der_flux[1][0][0]; + flux[29] = spatial_metric_der_flux[1][0][1]; + flux[30] = spatial_metric_der_flux[1][0][2]; + flux[31] = spatial_metric_der_flux[1][1][0]; + flux[32] = spatial_metric_der_flux[1][1][1]; + flux[33] = spatial_metric_der_flux[1][1][2]; + flux[34] = spatial_metric_der_flux[1][2][0]; + flux[35] = spatial_metric_der_flux[1][2][1]; + flux[36] = spatial_metric_der_flux[1][2][2]; + + flux[37] = spatial_metric_der_flux[2][0][0]; + flux[38] = spatial_metric_der_flux[2][0][1]; + flux[39] = spatial_metric_der_flux[2][0][2]; + flux[40] = spatial_metric_der_flux[2][1][0]; + flux[41] = spatial_metric_der_flux[2][1][1]; + flux[42] = spatial_metric_der_flux[2][1][2]; + flux[43] = spatial_metric_der_flux[2][2][0]; + flux[44] = spatial_metric_der_flux[2][2][1]; + flux[45] = spatial_metric_der_flux[2][2][2]; flux[46] = lapse_der_flux[0]; flux[47] = lapse_der_flux[1]; @@ -247,31 +311,38 @@ gkyl_vacuum_einstein_flux(double excision_threshold, enum gkyl_spacetime_slicing for (int i = 52; i < 64; i++) { flux[i] = 0.0; } - + for (int i = 0; i < 3; i++) { gkyl_free(inv_spatial_metric[i]); } gkyl_free(inv_spatial_metric); - } - else { + } else { for (int i = 0; i < 64; i++) { flux[i] = 0.0; } } } -void -gkyl_vacuum_einstein_inv_spatial_metric(const double q[64], double ***inv_spatial_metric) +void gkyl_vacuum_einstein_inv_spatial_metric(const double q[64], double ***inv_spatial_metric) { double spatial_metric[3][3]; - spatial_metric[0][0] = q[0]; spatial_metric[0][1] = q[1]; spatial_metric[0][2] = q[2]; - spatial_metric[1][0] = q[3]; spatial_metric[1][1] = q[4]; spatial_metric[1][2] = q[5]; - spatial_metric[2][0] = q[6]; spatial_metric[2][1] = q[7]; spatial_metric[2][2] = q[8]; - - double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - (spatial_metric[2][1] * spatial_metric[1][2]))) - - (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - (spatial_metric[1][2] * spatial_metric[2][0]))) + - (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - (spatial_metric[1][1] * spatial_metric[2][0]))); - + spatial_metric[0][0] = q[0]; + spatial_metric[0][1] = q[1]; + spatial_metric[0][2] = q[2]; + spatial_metric[1][0] = q[3]; + spatial_metric[1][1] = q[4]; + spatial_metric[1][2] = q[5]; + spatial_metric[2][0] = q[6]; + spatial_metric[2][1] = q[7]; + spatial_metric[2][2] = q[8]; + + double spatial_det = (spatial_metric[0][0] * ((spatial_metric[1][1] * spatial_metric[2][2]) - + (spatial_metric[2][1] * spatial_metric[1][2]))) - + (spatial_metric[0][1] * ((spatial_metric[1][0] * spatial_metric[2][2]) - + (spatial_metric[1][2] * spatial_metric[2][0]))) + + (spatial_metric[0][2] * ((spatial_metric[1][0] * spatial_metric[2][1]) - + (spatial_metric[1][1] * spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += spatial_metric[i][i]; @@ -302,8 +373,7 @@ gkyl_vacuum_einstein_inv_spatial_metric(const double q[64], double ***inv_spatia for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -311,14 +381,16 @@ gkyl_vacuum_einstein_inv_spatial_metric(const double q[64], double ***inv_spatia for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*inv_spatial_metric)[i][j] = (1.0 / spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); + (*inv_spatial_metric)[i][j] = + (1.0 / spatial_det) * ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * spatial_metric[i][j]) + spatial_metric_sq[i][j]); } } } -static inline double -gkyl_vacuum_einstein_max_abs_speed(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, const double q[64]) +static inline double gkyl_vacuum_einstein_max_abs_speed( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, const double q[64] +) { double lapse = q[9]; @@ -327,7 +399,7 @@ gkyl_vacuum_einstein_max_abs_speed(double excision_threshold, enum gkyl_spacetim shift_vect[1] = q[53]; shift_vect[2] = q[54]; - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -337,11 +409,9 @@ gkyl_vacuum_einstein_max_abs_speed(double excision_threshold, enum gkyl_spacetim double slicing_func = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { slicing_func = 1.0; - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { slicing_func = 2.0 / lapse; } @@ -357,22 +427,23 @@ gkyl_vacuum_einstein_max_abs_speed(double excision_threshold, enum gkyl_spacetim if (fabs(shift_vect[i]) > max_eig) { max_eig = fabs(shift_vect[i]); } - if (fabs(-shift_vect[i] + (lapse * sqrt(slicing_func * inv_spatial_metric[i][i]))) > max_eig) { + if (fabs(-shift_vect[i] + (lapse * sqrt(slicing_func * inv_spatial_metric[i][i]))) > + max_eig) { max_eig = fabs(-shift_vect[i] + (lapse * sqrt(slicing_func * inv_spatial_metric[i][i]))); } - if (fabs(-shift_vect[i] - (lapse * sqrt(slicing_func * inv_spatial_metric[i][i]))) > max_eig) { + if (fabs(-shift_vect[i] - (lapse * sqrt(slicing_func * inv_spatial_metric[i][i]))) > + max_eig) { max_eig = fabs(-shift_vect[i] - (lapse * sqrt(slicing_func * inv_spatial_metric[i][i]))); } } - + for (int i = 0; i < 3; i++) { gkyl_free(inv_spatial_metric[i]); } gkyl_free(inv_spatial_metric); return max_eig; - } - else { + } else { for (int i = 0; i < 3; i++) { gkyl_free(inv_spatial_metric[i]); } @@ -383,7 +454,7 @@ gkyl_vacuum_einstein_max_abs_speed(double excision_threshold, enum gkyl_spacetim } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 64; i++) { @@ -392,7 +463,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 64; i++) { @@ -400,53 +471,98 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -vacuum_einstein_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void vacuum_einstein_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { // Set spatial metric tensor. - ghost[0] = 1.0; ghost[1] = 0.0; ghost[2] = 0.0; - ghost[3] = 0.0; ghost[4] = 1.0; ghost[5] = 0.0; - ghost[6] = 0.0; ghost[7] = 0.0; ghost[8] = 1.0; + ghost[0] = 1.0; + ghost[1] = 0.0; + ghost[2] = 0.0; + ghost[3] = 0.0; + ghost[4] = 1.0; + ghost[5] = 0.0; + ghost[6] = 0.0; + ghost[7] = 0.0; + ghost[8] = 1.0; // Set lapse gauge variable. ghost[9] = 1.0; // Set extrinsic curvature tensor. - ghost[10] = 0.0; ghost[11] = 0.0; ghost[12] = 0.0; - ghost[13] = 0.0; ghost[14] = 0.0; ghost[15] = 0.0; - ghost[16] = 0.0; ghost[17] = 0.0; ghost[18] = 0.0; + ghost[10] = 0.0; + ghost[11] = 0.0; + ghost[12] = 0.0; + ghost[13] = 0.0; + ghost[14] = 0.0; + ghost[15] = 0.0; + ghost[16] = 0.0; + ghost[17] = 0.0; + ghost[18] = 0.0; // Set spatial metric tensor derivatives. - ghost[19] = 0.0; ghost[20] = 0.0; ghost[21] = 0.0; - ghost[22] = 0.0; ghost[23] = 0.0; ghost[24] = 0.0; - ghost[25] = 0.0; ghost[26] = 0.0; ghost[27] = 0.0; - - ghost[28] = 0.0; ghost[29] = 0.0; ghost[30] = 0.0; - ghost[31] = 0.0; ghost[32] = 0.0; ghost[33] = 0.0; - ghost[34] = 0.0; ghost[35] = 0.0; ghost[36] = 0.0; - - ghost[37] = 0.0; ghost[38] = 0.0; ghost[39] = 0.0; - ghost[40] = 0.0; ghost[41] = 0.0; ghost[42] = 0.0; - ghost[43] = 0.0; ghost[44] = 0.0; ghost[45] = 0.0; + ghost[19] = 0.0; + ghost[20] = 0.0; + ghost[21] = 0.0; + ghost[22] = 0.0; + ghost[23] = 0.0; + ghost[24] = 0.0; + ghost[25] = 0.0; + ghost[26] = 0.0; + ghost[27] = 0.0; + + ghost[28] = 0.0; + ghost[29] = 0.0; + ghost[30] = 0.0; + ghost[31] = 0.0; + ghost[32] = 0.0; + ghost[33] = 0.0; + ghost[34] = 0.0; + ghost[35] = 0.0; + ghost[36] = 0.0; + + ghost[37] = 0.0; + ghost[38] = 0.0; + ghost[39] = 0.0; + ghost[40] = 0.0; + ghost[41] = 0.0; + ghost[42] = 0.0; + ghost[43] = 0.0; + ghost[44] = 0.0; + ghost[45] = 0.0; // Set lapse function derivatives. - ghost[46] = 0.0; ghost[47] = 0.0; ghost[48] = 0.0; + ghost[46] = 0.0; + ghost[47] = 0.0; + ghost[48] = 0.0; // Set auxiliary vector. - ghost[49] = 0.0; ghost[50] = 0.0; ghost[51] = 0.0; + ghost[49] = 0.0; + ghost[50] = 0.0; + ghost[51] = 0.0; // Set shift gauge variables. - ghost[52] = 0.0; ghost[53] = 0.0; ghost[54] = 0.0; + ghost[52] = 0.0; + ghost[53] = 0.0; + ghost[54] = 0.0; // Set shift vector derivatives. - ghost[55] = 0.0; ghost[56] = 0.0; ghost[57] = 0.0; - ghost[58] = 0.0; ghost[59] = 0.0; ghost[60] = 0.0; - ghost[61] = 0.0; ghost[62] = 0.0; ghost[63] = 0.0; + ghost[55] = 0.0; + ghost[56] = 0.0; + ghost[57] = 0.0; + ghost[58] = 0.0; + ghost[59] = 0.0; + ghost[60] = 0.0; + ghost[61] = 0.0; + ghost[62] = 0.0; + ghost[63] = 0.0; } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { // Temporary arrays to store rotated column vectors. double r1[3], r2[3], r3[3]; @@ -477,9 +593,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinate frame. - qlocal[0] = v1[0]; qlocal[1] = v1[1]; qlocal[2] = v1[2]; - qlocal[3] = v2[0]; qlocal[4] = v2[1]; qlocal[5] = v2[2]; - qlocal[6] = v3[0]; qlocal[7] = v3[1]; qlocal[8] = v3[2]; + qlocal[0] = v1[0]; + qlocal[1] = v1[1]; + qlocal[2] = v1[2]; + qlocal[3] = v2[0]; + qlocal[4] = v2[1]; + qlocal[5] = v2[2]; + qlocal[6] = v3[0]; + qlocal[7] = v3[1]; + qlocal[8] = v3[2]; qlocal[9] = qglobal[9]; @@ -512,9 +634,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta inv_v3[2] = (extr_r1[2] * tau2[0]) + (extr_r2[2] * tau2[1]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor to local coordinate frame. - qlocal[10] = inv_v1[0]; qlocal[11] = inv_v1[1]; qlocal[12] = inv_v1[2]; - qlocal[13] = inv_v2[0]; qlocal[14] = inv_v2[1]; qlocal[15] = inv_v2[2]; - qlocal[16] = inv_v3[0]; qlocal[17] = inv_v3[1]; qlocal[18] = inv_v3[2]; + qlocal[10] = inv_v1[0]; + qlocal[11] = inv_v1[1]; + qlocal[12] = inv_v1[2]; + qlocal[13] = inv_v2[0]; + qlocal[14] = inv_v2[1]; + qlocal[15] = inv_v2[2]; + qlocal[16] = inv_v3[0]; + qlocal[17] = inv_v3[1]; + qlocal[18] = inv_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -597,7 +725,7 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta s33[0] = (r31[0] * tau2[0]) + (r32[0] * tau2[1]) + (r33[0] * tau2[2]); s33[1] = (r31[1] * tau2[0]) + (r32[1] * tau2[1]) + (r33[1] * tau2[2]); s33[2] = (r31[2] * tau2[0]) + (r32[2] * tau2[1]) + (r33[2] * tau2[2]); - + // Rotate spatial metric tensor derivative to local coordinate frame. qlocal[19] = (s11[0] * norm[0]) + (s21[0] * norm[1]) + (s31[0] * norm[2]); qlocal[20] = (s11[1] * norm[0]) + (s21[1] * norm[1]) + (s31[1] * norm[2]); @@ -663,27 +791,43 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); - shiftder_v1[1] = (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); - shiftder_v1[2] = (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); - shiftder_v2[1] = (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); - shiftder_v2[2] = (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); - shiftder_v3[1] = (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); - shiftder_v3[2] = (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); + shiftder_v1[1] = + (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); + shiftder_v1[2] = + (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); + shiftder_v2[1] = + (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); + shiftder_v2[2] = + (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); + shiftder_v3[1] = + (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); + shiftder_v3[2] = + (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative to local coordinate frame. - qlocal[55] = shiftder_v1[0]; qlocal[56] = shiftder_v1[1]; qlocal[57] = shiftder_v1[2]; - qlocal[58] = shiftder_v2[0]; qlocal[59] = shiftder_v2[1]; qlocal[60] = shiftder_v2[2]; - qlocal[61] = shiftder_v3[0]; qlocal[62] = shiftder_v3[1]; qlocal[63] = shiftder_v3[2]; + qlocal[55] = shiftder_v1[0]; + qlocal[56] = shiftder_v1[1]; + qlocal[57] = shiftder_v1[2]; + qlocal[58] = shiftder_v2[0]; + qlocal[59] = shiftder_v2[1]; + qlocal[60] = shiftder_v2[2]; + qlocal[61] = shiftder_v3[0]; + qlocal[62] = shiftder_v3[1]; + qlocal[63] = shiftder_v3[2]; } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { // Temporary arrays to store rotated column vectors. double r1[3], r2[3], r3[3]; @@ -714,9 +858,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor back to global coordinate frame. - qglobal[0] = v1[0]; qglobal[1] = v1[1]; qglobal[2] = v1[2]; - qglobal[3] = v2[0]; qglobal[4] = v2[1]; qglobal[5] = v2[2]; - qglobal[6] = v3[0]; qglobal[7] = v3[1]; qglobal[8] = v3[2]; + qglobal[0] = v1[0]; + qglobal[1] = v1[1]; + qglobal[2] = v1[2]; + qglobal[3] = v2[0]; + qglobal[4] = v2[1]; + qglobal[5] = v2[2]; + qglobal[6] = v3[0]; + qglobal[7] = v3[1]; + qglobal[8] = v3[2]; qglobal[9] = qlocal[9]; @@ -749,9 +899,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t inv_v3[2] = (extr_r1[2] * norm[2]) + (extr_r2[2] * tau1[2]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor back to global coordinate frame. - qglobal[10] = inv_v1[0]; qglobal[11] = inv_v1[1]; qglobal[12] = inv_v1[2]; - qglobal[13] = inv_v2[0]; qglobal[14] = inv_v2[1]; qglobal[15] = inv_v2[2]; - qglobal[16] = inv_v3[0]; qglobal[17] = inv_v3[1]; qglobal[18] = inv_v3[2]; + qglobal[10] = inv_v1[0]; + qglobal[11] = inv_v1[1]; + qglobal[12] = inv_v1[2]; + qglobal[13] = inv_v2[0]; + qglobal[14] = inv_v2[1]; + qglobal[15] = inv_v2[2]; + qglobal[16] = inv_v3[0]; + qglobal[17] = inv_v3[1]; + qglobal[18] = inv_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -900,28 +1056,46 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); - shiftder_v1[1] = (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); - shiftder_v1[2] = (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); - shiftder_v2[1] = (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); - shiftder_v2[2] = (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); - shiftder_v3[1] = (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); - shiftder_v3[2] = (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); + shiftder_v1[1] = + (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); + shiftder_v1[2] = + (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); + shiftder_v2[1] = + (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); + shiftder_v2[2] = + (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); + shiftder_v3[1] = + (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); + shiftder_v3[2] = + (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative back to global coordinate frame. - qglobal[55] = shiftder_v1[0]; qglobal[56] = shiftder_v1[1]; qglobal[57] = shiftder_v1[2]; - qglobal[58] = shiftder_v2[0]; qglobal[59] = shiftder_v2[1]; qglobal[60] = shiftder_v2[2]; - qglobal[61] = shiftder_v3[0]; qglobal[62] = shiftder_v3[1]; qglobal[63] = shiftder_v3[2]; + qglobal[55] = shiftder_v1[0]; + qglobal[56] = shiftder_v1[1]; + qglobal[57] = shiftder_v1[2]; + qglobal[58] = shiftder_v2[0]; + qglobal[59] = shiftder_v2[1]; + qglobal[60] = shiftder_v2[2]; + qglobal[61] = shiftder_v3[0]; + qglobal[62] = shiftder_v3[1]; + qglobal[63] = shiftder_v3[2]; } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_vacuum_einstein *vacuum_einstein = container_of(eqn, struct wv_vacuum_einstein, eqn); + const struct wv_vacuum_einstein *vacuum_einstein = + container_of(eqn, struct wv_vacuum_einstein, eqn); double excision_threshold = vacuum_einstein->excision_threshold; enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein->spacetime_slicing; enum gkyl_spacetime_evolution spacetime_evolution = vacuum_einstein->spacetime_evolution; @@ -950,8 +1124,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr[i] - fl[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr[i] - fl[i]) / amax); } - } - else { + } else { for (int i = 0; i < 64; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -964,8 +1137,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[64]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -977,24 +1152,30 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, - double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, - const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_vacuum_einstein *vacuum_einstein = container_of(eqn, struct wv_vacuum_einstein, eqn); + const struct wv_vacuum_einstein *vacuum_einstein = + container_of(eqn, struct wv_vacuum_einstein, eqn); double excision_threshold = vacuum_einstein->excision_threshold; enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein->spacetime_slicing; enum gkyl_spacetime_evolution spacetime_evolution = vacuum_einstein->spacetime_evolution; @@ -1005,15 +1186,13 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double slicing_func_l = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func_l = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { slicing_func_l = 1.0; - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { slicing_func_l = 2.0 / lapse_l; } - double **inv_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); } @@ -1031,15 +1210,13 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double slicing_func_r = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func_r = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { slicing_func_r = 1.0; - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { slicing_func_r = 2.0 / lapse_l; } - double **inv_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } @@ -1077,8 +1254,7 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = qm[i] - ql[i]; w1[i] = qr[i] - qm[i]; } - } - else { + } else { for (int i = 0; i < 64; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1098,8 +1274,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return fmax(fabs(sl), fabs(sr)); } -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[64]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1111,36 +1289,38 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, - double* waves, double* s) +static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hll(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, - const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_hll(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { - const struct wv_vacuum_einstein *vacuum_einstein = container_of(eqn, struct wv_vacuum_einstein, eqn); + const struct wv_vacuum_einstein *vacuum_einstein = + container_of(eqn, struct wv_vacuum_einstein, eqn); double excision_threshold = vacuum_einstein->excision_threshold; enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein->spacetime_slicing; enum gkyl_spacetime_evolution spacetime_evolution = vacuum_einstein->spacetime_evolution; @@ -1163,8 +1343,7 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 64; m++) { flux_jump[m] = fr[m] - fl[m]; } - } - else { + } else { for (int m = 0; m < 64; m++) { flux_jump[m] = 0.0; } @@ -1176,21 +1355,19 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { if (q[9] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_vacuum_einstein *vacuum_einstein = container_of(eqn, struct wv_vacuum_einstein, eqn); + const struct wv_vacuum_einstein *vacuum_einstein = + container_of(eqn, struct wv_vacuum_einstein, eqn); double excision_threshold = vacuum_einstein->excision_threshold; enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein->spacetime_slicing; @@ -1198,43 +1375,74 @@ max_speed(const struct gkyl_wv_eqn* eqn, const double* q) } static inline void -vacuum_einstein_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +vacuum_einstein_cons_to_diag(const struct gkyl_wv_eqn *eqn, const double *qin, double *diag) { diag[0] = qin[9]; } static inline void -vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +vacuum_einstein_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { - const struct wv_vacuum_einstein *vacuum_einstein = container_of(eqn, struct wv_vacuum_einstein, eqn); + const struct wv_vacuum_einstein *vacuum_einstein = + container_of(eqn, struct wv_vacuum_einstein, eqn); double excision_threshold = vacuum_einstein->excision_threshold; enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein->spacetime_slicing; enum gkyl_spacetime_evolution spacetime_evolution = vacuum_einstein->spacetime_evolution; double spatial_metric[3][3]; - spatial_metric[0][0] = qin[0]; spatial_metric[0][1] = qin[1]; spatial_metric[0][2] = qin[2]; - spatial_metric[1][0] = qin[3]; spatial_metric[1][1] = qin[4]; spatial_metric[1][2] = qin[5]; - spatial_metric[2][0] = qin[6]; spatial_metric[2][1] = qin[7]; spatial_metric[2][2] = qin[8]; + spatial_metric[0][0] = qin[0]; + spatial_metric[0][1] = qin[1]; + spatial_metric[0][2] = qin[2]; + spatial_metric[1][0] = qin[3]; + spatial_metric[1][1] = qin[4]; + spatial_metric[1][2] = qin[5]; + spatial_metric[2][0] = qin[6]; + spatial_metric[2][1] = qin[7]; + spatial_metric[2][2] = qin[8]; double lapse = qin[9]; double extrinsic_curvature[3][3]; - extrinsic_curvature[0][0] = qin[10]; extrinsic_curvature[0][1] = qin[11]; extrinsic_curvature[0][2] = qin[12]; - extrinsic_curvature[1][0] = qin[13]; extrinsic_curvature[1][1] = qin[14]; extrinsic_curvature[1][2] = qin[15]; - extrinsic_curvature[2][0] = qin[16]; extrinsic_curvature[2][1] = qin[17]; extrinsic_curvature[2][2] = qin[18]; + extrinsic_curvature[0][0] = qin[10]; + extrinsic_curvature[0][1] = qin[11]; + extrinsic_curvature[0][2] = qin[12]; + extrinsic_curvature[1][0] = qin[13]; + extrinsic_curvature[1][1] = qin[14]; + extrinsic_curvature[1][2] = qin[15]; + extrinsic_curvature[2][0] = qin[16]; + extrinsic_curvature[2][1] = qin[17]; + extrinsic_curvature[2][2] = qin[18]; double spatial_metric_der[3][3][3]; - spatial_metric_der[0][0][0] = qin[19]; spatial_metric_der[0][0][1] = qin[20]; spatial_metric_der[0][0][2] = qin[21]; - spatial_metric_der[0][1][0] = qin[22]; spatial_metric_der[0][1][1] = qin[23]; spatial_metric_der[0][1][2] = qin[24]; - spatial_metric_der[0][2][0] = qin[25]; spatial_metric_der[0][2][1] = qin[26]; spatial_metric_der[0][2][2] = qin[27]; - - spatial_metric_der[1][0][0] = qin[28]; spatial_metric_der[1][0][1] = qin[29]; spatial_metric_der[1][0][2] = qin[30]; - spatial_metric_der[1][1][0] = qin[31]; spatial_metric_der[1][1][1] = qin[32]; spatial_metric_der[1][1][2] = qin[33]; - spatial_metric_der[1][2][0] = qin[34]; spatial_metric_der[1][2][1] = qin[35]; spatial_metric_der[1][2][2] = qin[36]; - - spatial_metric_der[2][0][0] = qin[37]; spatial_metric_der[2][0][1] = qin[38]; spatial_metric_der[2][0][2] = qin[39]; - spatial_metric_der[2][1][0] = qin[40]; spatial_metric_der[2][1][1] = qin[41]; spatial_metric_der[2][1][2] = qin[42]; - spatial_metric_der[2][2][0] = qin[43]; spatial_metric_der[2][2][1] = qin[44]; spatial_metric_der[2][2][2] = qin[45]; + spatial_metric_der[0][0][0] = qin[19]; + spatial_metric_der[0][0][1] = qin[20]; + spatial_metric_der[0][0][2] = qin[21]; + spatial_metric_der[0][1][0] = qin[22]; + spatial_metric_der[0][1][1] = qin[23]; + spatial_metric_der[0][1][2] = qin[24]; + spatial_metric_der[0][2][0] = qin[25]; + spatial_metric_der[0][2][1] = qin[26]; + spatial_metric_der[0][2][2] = qin[27]; + + spatial_metric_der[1][0][0] = qin[28]; + spatial_metric_der[1][0][1] = qin[29]; + spatial_metric_der[1][0][2] = qin[30]; + spatial_metric_der[1][1][0] = qin[31]; + spatial_metric_der[1][1][1] = qin[32]; + spatial_metric_der[1][1][2] = qin[33]; + spatial_metric_der[1][2][0] = qin[34]; + spatial_metric_der[1][2][1] = qin[35]; + spatial_metric_der[1][2][2] = qin[36]; + + spatial_metric_der[2][0][0] = qin[37]; + spatial_metric_der[2][0][1] = qin[38]; + spatial_metric_der[2][0][2] = qin[39]; + spatial_metric_der[2][1][0] = qin[40]; + spatial_metric_der[2][1][1] = qin[41]; + spatial_metric_der[2][1][2] = qin[42]; + spatial_metric_der[2][2][0] = qin[43]; + spatial_metric_der[2][2][1] = qin[44]; + spatial_metric_der[2][2][2] = qin[45]; double lapse_der[3]; lapse_der[0] = qin[46]; @@ -1252,9 +1460,15 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* shift_vect[2] = qin[54]; double shift_vect_der[3][3]; - shift_vect_der[0][0] = qin[55]; shift_vect_der[0][1] = qin[56]; shift_vect_der[0][2] = qin[57]; - shift_vect_der[1][0] = qin[58]; shift_vect_der[1][1] = qin[59]; shift_vect_der[1][2] = qin[60]; - shift_vect_der[2][0] = qin[61]; shift_vect_der[2][1] = qin[62]; shift_vect_der[2][2] = qin[63]; + shift_vect_der[0][0] = qin[55]; + shift_vect_der[0][1] = qin[56]; + shift_vect_der[0][2] = qin[57]; + shift_vect_der[1][0] = qin[58]; + shift_vect_der[1][1] = qin[59]; + shift_vect_der[1][2] = qin[60]; + shift_vect_der[2][0] = qin[61]; + shift_vect_der[2][1] = qin[62]; + shift_vect_der[2][2] = qin[63]; bool in_excision_region = false; if (lapse < excision_threshold) { @@ -1262,7 +1476,7 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* } if (!in_excision_region) { - double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -1272,8 +1486,7 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* double evolution_func = 0.0; if (spacetime_evolution == GKYL_RICCI_EVOLUTION) { evolution_func = 0.0; - } - else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { + } else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { evolution_func = 1.0; } @@ -1302,7 +1515,8 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - extrinsic_curvature_raised[i][j] += inv_spatial_metric[i][l] * inv_spatial_metric[m][j] * extrinsic_curvature[l][m]; + extrinsic_curvature_raised[i][j] += + inv_spatial_metric[i][l] * inv_spatial_metric[m][j] * extrinsic_curvature[l][m]; } } } @@ -1326,7 +1540,8 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - shift_vect_der_switched[i][k] += inv_spatial_metric[i][l] * spatial_metric[m][k] * shift_vect_der[l][m]; + shift_vect_der_switched[i][k] += + inv_spatial_metric[i][l] * spatial_metric[m][k] * shift_vect_der[l][m]; } } } @@ -1340,18 +1555,17 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* double symmetrized_shift[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - symmetrized_shift[i][j] = (1.0 / lapse) * (shift_vect_der_lowered[i][j] + shift_vect_der_lowered[j][i]); + symmetrized_shift[i][j] = + (1.0 / lapse) * (shift_vect_der_lowered[i][j] + shift_vect_der_lowered[j][i]); } } double slicing_func = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { slicing_func = extrinsic_curvature_trace; - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { slicing_func = 2.0 * extrinsic_curvature_trace / lapse; } @@ -1360,9 +1574,10 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - spatial_metric_der_raised1[k][i][j] += inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; + spatial_metric_der_raised1[k][i][j] += + inv_spatial_metric[k][l] * spatial_metric_der[l][i][j]; } } } @@ -1375,7 +1590,8 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - spatial_metric_der_raised3[i][j][k] += inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; + spatial_metric_der_raised3[i][j][k] += + inv_spatial_metric[l][k] * spatial_metric_der[i][j][l]; } } } @@ -1389,7 +1605,8 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - spatial_metric_der_lowered1[i][j][k] += inv_spatial_metric[j][l] * inv_spatial_metric[m][k] * spatial_metric_der[i][l][m]; + spatial_metric_der_lowered1[i][j][k] += + inv_spatial_metric[j][l] * inv_spatial_metric[m][k] * spatial_metric_der[i][l][m]; } } } @@ -1404,7 +1621,8 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - spatial_metric_der_lowered3[i][j][k] += inv_spatial_metric[i][l] * inv_spatial_metric[m][j] * spatial_metric_der[l][m][k]; + spatial_metric_der_lowered3[i][j][k] += + inv_spatial_metric[i][l] * inv_spatial_metric[m][j] * spatial_metric_der[l][m][k]; } } } @@ -1414,7 +1632,7 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* double aux_vect_raised[3]; for (int k = 0; k < 3; k++) { aux_vect_raised[k] = 0.0; - + for (int l = 0; l < 3; l++) { aux_vect_raised[k] += inv_spatial_metric[k][l] * aux_vect[l]; } @@ -1438,7 +1656,8 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* double spatial_metric_source[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - spatial_metric_source[i][j] = -2.0 * lapse * (extrinsic_curvature[i][j] - symmetrized_shift[i][j]); + spatial_metric_source[i][j] = + -2.0 * lapse * (extrinsic_curvature[i][j] - symmetrized_shift[i][j]); for (int r = 0; r < 3; r++) { spatial_metric_source[i][j] += 2.0 * shift_vect[r] * spatial_metric_der[r][i][j]; @@ -1457,49 +1676,72 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* extrinsic_curvature_source[i][j] = 0.0; for (int r = 0; r < 3; r++) { - extrinsic_curvature_source[i][j] += 2.0 * extrinsic_curvature[i][r] * shift_vect_der[j][r]; - extrinsic_curvature_source[i][j] += 2.0 * extrinsic_curvature[j][r] * shift_vect_der[i][r]; - extrinsic_curvature_source[i][j] -= 2.0 * extrinsic_curvature[i][j] * shift_vect_der[r][r]; + extrinsic_curvature_source[i][j] += + 2.0 * extrinsic_curvature[i][r] * shift_vect_der[j][r]; + extrinsic_curvature_source[i][j] += + 2.0 * extrinsic_curvature[j][r] * shift_vect_der[i][r]; + extrinsic_curvature_source[i][j] -= + 2.0 * extrinsic_curvature[i][j] * shift_vect_der[r][r]; } for (int k = 0; k < 3; k++) { - extrinsic_curvature_source[i][j] -= 2.0 * lapse * extrinsic_curvature_mixed[i][k] * extrinsic_curvature[k][j]; - extrinsic_curvature_source[i][j] += lapse * extrinsic_curvature_trace * extrinsic_curvature[i][j]; + extrinsic_curvature_source[i][j] -= + 2.0 * lapse * extrinsic_curvature_mixed[i][k] * extrinsic_curvature[k][j]; + extrinsic_curvature_source[i][j] += + lapse * extrinsic_curvature_trace * extrinsic_curvature[i][j]; for (int r = 0; r < 3; r++) { - extrinsic_curvature_source[i][j] -= lapse * spatial_christoffel[k][r][i] * spatial_christoffel[r][k][j]; - - extrinsic_curvature_source[i][j] += 2.0 * lapse * spatial_metric_der_raised3[i][k][r] * spatial_metric_der_raised3[r][j][k]; - extrinsic_curvature_source[i][j] += 2.0 * lapse * spatial_metric_der_raised3[j][k][r] * spatial_metric_der_raised3[r][i][k]; - extrinsic_curvature_source[i][j] += lapse * spatial_christoffel[k][k][r] * spatial_christoffel[r][i][j]; - - extrinsic_curvature_source[i][j] -= lapse * (2.0 * spatial_metric_der_raised3[k][r][k] - lapse_der[r]) * (spatial_metric_der_raised3[i][j][r] + spatial_metric_der_raised3[j][i][r]); + extrinsic_curvature_source[i][j] -= + lapse * spatial_christoffel[k][r][i] * spatial_christoffel[r][k][j]; + + extrinsic_curvature_source[i][j] += 2.0 * lapse * spatial_metric_der_raised3[i][k][r] * + spatial_metric_der_raised3[r][j][k]; + extrinsic_curvature_source[i][j] += 2.0 * lapse * spatial_metric_der_raised3[j][k][r] * + spatial_metric_der_raised3[r][i][k]; + extrinsic_curvature_source[i][j] += + lapse * spatial_christoffel[k][k][r] * spatial_christoffel[r][i][j]; + + extrinsic_curvature_source[i][j] -= + lapse * (2.0 * spatial_metric_der_raised3[k][r][k] - lapse_der[r]) * + (spatial_metric_der_raised3[i][j][r] + spatial_metric_der_raised3[j][i][r]); } - extrinsic_curvature_source[i][j] += lapse * lapse_der[i] * (aux_vect[j] - (0.5 * spatial_metric_der_raised3[j][k][k])); - extrinsic_curvature_source[i][j] += lapse * lapse_der[j] * (aux_vect[i] - (0.5 * spatial_metric_der_raised3[i][k][k])); + extrinsic_curvature_source[i][j] += + lapse * lapse_der[i] * (aux_vect[j] - (0.5 * spatial_metric_der_raised3[j][k][k])); + extrinsic_curvature_source[i][j] += + lapse * lapse_der[j] * (aux_vect[i] - (0.5 * spatial_metric_der_raised3[i][k][k])); - extrinsic_curvature_source[i][j] -= lapse * evolution_func * aux_vect_raised[k] * spatial_metric_der[k][i][j]; + extrinsic_curvature_source[i][j] -= + lapse * evolution_func * aux_vect_raised[k] * spatial_metric_der[k][i][j]; } for (int k = 0; k < 3; k++) { for (int r = 0; r < 3; r++) { for (int s = 0; s < 3; s++) { - extrinsic_curvature_source[i][j] -= (0.25 * evolution_func * lapse * spatial_metric[i][j]) * spatial_metric_der_lowered1[k][r][s] * spatial_christoffel[k][r][s]; - extrinsic_curvature_source[i][j] += (0.25 * evolution_func * lapse * spatial_metric[i][j]) * spatial_metric_der_raised3[k][r][r] * spatial_metric_der_lowered3[k][s][s]; + extrinsic_curvature_source[i][j] -= + (0.25 * evolution_func * lapse * spatial_metric[i][j]) * + spatial_metric_der_lowered1[k][r][s] * spatial_christoffel[k][r][s]; + extrinsic_curvature_source[i][j] += + (0.25 * evolution_func * lapse * spatial_metric[i][j]) * + spatial_metric_der_raised3[k][r][r] * spatial_metric_der_lowered3[k][s][s]; } } - extrinsic_curvature_source[i][j] -= (0.5 * evolution_func * lapse * spatial_metric[i][j]) * aux_vect_raised[k] * lapse_der[k]; + extrinsic_curvature_source[i][j] -= + (0.5 * evolution_func * lapse * spatial_metric[i][j]) * aux_vect_raised[k] * + lapse_der[k]; } for (int r = 0; r < 3; r++) { for (int s = 0; s < 3; s++) { - extrinsic_curvature_source[i][j] += (0.25 * evolution_func * lapse * spatial_metric[i][j]) * extrinsic_curvature_raised[r][s] * extrinsic_curvature[r][s]; + extrinsic_curvature_source[i][j] += + (0.25 * evolution_func * lapse * spatial_metric[i][j]) * + extrinsic_curvature_raised[r][s] * extrinsic_curvature[r][s]; } } - extrinsic_curvature_source[i][j] -= (0.25 * evolution_func * lapse * spatial_metric[i][j]) * (extrinsic_curvature_trace * extrinsic_curvature_trace); + extrinsic_curvature_source[i][j] -= (0.25 * evolution_func * lapse * spatial_metric[i][j]) * + (extrinsic_curvature_trace * extrinsic_curvature_trace); } } @@ -1509,17 +1751,21 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* for (int r = 0; r < 3; r++) { aux_vect_source[i] += lapse * lapse_der[r] * extrinsic_curvature_mixed[i][r]; - + if (i == r) { aux_vect_source[i] -= lapse * lapse_der[r] * extrinsic_curvature_trace; } for (int s = 0; s < 3; s++) { - aux_vect_source[i] += lapse * extrinsic_curvature_mixed[s][r] * spatial_metric_der_raised3[i][r][s]; - aux_vect_source[i] -= 2.0 * lapse * extrinsic_curvature_mixed[s][r] * spatial_metric_der_raised3[r][i][s]; - - aux_vect_source[i] -= lapse * extrinsic_curvature_mixed[i][r] * spatial_metric_der_raised3[r][s][s]; - aux_vect_source[i] += 2.0 * lapse * extrinsic_curvature_mixed[i][r] * spatial_metric_der_raised3[s][r][s]; + aux_vect_source[i] += + lapse * extrinsic_curvature_mixed[s][r] * spatial_metric_der_raised3[i][r][s]; + aux_vect_source[i] -= + 2.0 * lapse * extrinsic_curvature_mixed[s][r] * spatial_metric_der_raised3[r][i][s]; + + aux_vect_source[i] -= + lapse * extrinsic_curvature_mixed[i][r] * spatial_metric_der_raised3[r][s][s]; + aux_vect_source[i] += + 2.0 * lapse * extrinsic_curvature_mixed[i][r] * spatial_metric_der_raised3[s][r][s]; } aux_vect_source[i] += 2.0 * shift_vect_der[i][r] * aux_vect[r]; @@ -1529,26 +1775,40 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* } for (int s = 0; s < 3; s++) { - aux_vect_source[i] += 2.0 * spatial_metric_der_raised3[r][i][s] * shift_vect_der_switched[r][s]; + aux_vect_source[i] += + 2.0 * spatial_metric_der_raised3[r][i][s] * shift_vect_der_switched[r][s]; if (i == s) { for (int j = 0; j < 3; j++) { - aux_vect_source[i] -= 2.0 * spatial_metric_der_raised1[j][j][r] * shift_vect_der_switched[r][s]; + aux_vect_source[i] -= + 2.0 * spatial_metric_der_raised1[j][j][r] * shift_vect_der_switched[r][s]; } } } } } - sout[0] = spatial_metric_source[0][0]; sout[1] = spatial_metric_source[0][1]; sout[2] = spatial_metric_source[0][2]; - sout[3] = spatial_metric_source[1][0]; sout[4] = spatial_metric_source[1][1]; sout[5] = spatial_metric_source[1][2]; - sout[6] = spatial_metric_source[2][0]; sout[7] = spatial_metric_source[2][1]; sout[8] = spatial_metric_source[2][2]; + sout[0] = spatial_metric_source[0][0]; + sout[1] = spatial_metric_source[0][1]; + sout[2] = spatial_metric_source[0][2]; + sout[3] = spatial_metric_source[1][0]; + sout[4] = spatial_metric_source[1][1]; + sout[5] = spatial_metric_source[1][2]; + sout[6] = spatial_metric_source[2][0]; + sout[7] = spatial_metric_source[2][1]; + sout[8] = spatial_metric_source[2][2]; sout[9] = lapse_source; - sout[10] = extrinsic_curvature_source[0][0]; sout[11] = extrinsic_curvature_source[0][1]; sout[12] = extrinsic_curvature_source[0][2]; - sout[13] = extrinsic_curvature_source[1][0]; sout[14] = extrinsic_curvature_source[1][1]; sout[15] = extrinsic_curvature_source[1][2]; - sout[16] = extrinsic_curvature_source[2][0]; sout[17] = extrinsic_curvature_source[2][1]; sout[18] = extrinsic_curvature_source[2][2]; + sout[10] = extrinsic_curvature_source[0][0]; + sout[11] = extrinsic_curvature_source[0][1]; + sout[12] = extrinsic_curvature_source[0][2]; + sout[13] = extrinsic_curvature_source[1][0]; + sout[14] = extrinsic_curvature_source[1][1]; + sout[15] = extrinsic_curvature_source[1][2]; + sout[16] = extrinsic_curvature_source[2][0]; + sout[17] = extrinsic_curvature_source[2][1]; + sout[18] = extrinsic_curvature_source[2][2]; for (int i = 19; i < 49; i++) { sout[i] = 0.0; @@ -1566,22 +1826,21 @@ vacuum_einstein_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* gkyl_free(inv_spatial_metric[i]); } gkyl_free(inv_spatial_metric); - } - else { + } else { for (int i = 0; i < 64; i++) { sout[i] = 0.0; } } } -void -gkyl_vacuum_einstein_free(const struct gkyl_ref_count* ref) +void gkyl_vacuum_einstein_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. - struct wv_vacuum_einstein *vacuum_einstein = container_of(base->on_dev, struct wv_vacuum_einstein, eqn); + struct wv_vacuum_einstein *vacuum_einstein = + container_of(base->on_dev, struct wv_vacuum_einstein, eqn); gkyl_cu_free(vacuum_einstein); } @@ -1589,21 +1848,20 @@ gkyl_vacuum_einstein_free(const struct gkyl_ref_count* ref) gkyl_free(vacuum_einstein); } -struct gkyl_wv_eqn* -gkyl_wv_vacuum_einstein_new(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, enum gkyl_spacetime_evolution spacetime_evolution, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_vacuum_einstein_new( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, + enum gkyl_spacetime_evolution spacetime_evolution, bool use_gpu +) { - return gkyl_wv_vacuum_einstein_inew(&(struct gkyl_wv_vacuum_einstein_inp) { - .excision_threshold = excision_threshold, - .spacetime_slicing = spacetime_slicing, - .spacetime_evolution = spacetime_evolution, - .rp_type = WV_VACUUM_EINSTEIN_RP_HLL, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_vacuum_einstein_inew(&(struct gkyl_wv_vacuum_einstein_inp + ){.excision_threshold = excision_threshold, + .spacetime_slicing = spacetime_slicing, + .spacetime_evolution = spacetime_evolution, + .rp_type = WV_VACUUM_EINSTEIN_RP_HLL, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_vacuum_einstein_inew(const struct gkyl_wv_vacuum_einstein_inp* inp) +struct gkyl_wv_eqn *gkyl_wv_vacuum_einstein_inew(const struct gkyl_wv_vacuum_einstein_inp *inp) { struct wv_vacuum_einstein *vacuum_einstein = gkyl_malloc(sizeof(struct wv_vacuum_einstein)); @@ -1619,13 +1877,12 @@ gkyl_wv_vacuum_einstein_inew(const struct gkyl_wv_vacuum_einstein_inp* inp) vacuum_einstein->eqn.num_waves = 2; vacuum_einstein->eqn.waves_func = wave_lax_l; vacuum_einstein->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_VACUUM_EINSTEIN_RP_HLL) { + } else if (inp->rp_type == WV_VACUUM_EINSTEIN_RP_HLL) { vacuum_einstein->eqn.num_waves = 2; vacuum_einstein->eqn.waves_func = wave_hll_l; vacuum_einstein->eqn.qfluct_func = qfluct_hll_l; } - + vacuum_einstein->eqn.flux_jump = flux_jump; vacuum_einstein->eqn.check_inv_func = check_inv; vacuum_einstein->eqn.max_speed_func = max_speed; @@ -1644,33 +1901,35 @@ gkyl_wv_vacuum_einstein_inew(const struct gkyl_wv_vacuum_einstein_inp* inp) vacuum_einstein->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(vacuum_einstein->eqn.flags); vacuum_einstein->eqn.ref_count = gkyl_ref_count_init(gkyl_vacuum_einstein_free); - vacuum_einstein->eqn.on_dev = &vacuum_einstein->eqn; // On the CPU, the equation object points to itself. + vacuum_einstein->eqn.on_dev = + &vacuum_einstein->eqn; // On the CPU, the equation object points to itself. return &vacuum_einstein->eqn; } -double -gkyl_wv_vacuum_einstein_excision_threshold(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_vacuum_einstein_excision_threshold(const struct gkyl_wv_eqn *eqn) { - const struct wv_vacuum_einstein *vacuum_einstein = container_of(eqn, struct wv_vacuum_einstein, eqn); + const struct wv_vacuum_einstein *vacuum_einstein = + container_of(eqn, struct wv_vacuum_einstein, eqn); double excision_threshold = vacuum_einstein->excision_threshold; return excision_threshold; } -enum gkyl_spacetime_slicing -gkyl_wv_vacuum_einstein_spacetime_slicing(const struct gkyl_wv_eqn* eqn) +enum gkyl_spacetime_slicing gkyl_wv_vacuum_einstein_spacetime_slicing(const struct gkyl_wv_eqn *eqn) { - const struct wv_vacuum_einstein *vacuum_einstein = container_of(eqn, struct wv_vacuum_einstein, eqn); + const struct wv_vacuum_einstein *vacuum_einstein = + container_of(eqn, struct wv_vacuum_einstein, eqn); enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein->spacetime_slicing; return spacetime_slicing; } enum gkyl_spacetime_evolution -gkyl_wv_vacuum_einstein_spacetime_evolution(const struct gkyl_wv_eqn* eqn) +gkyl_wv_vacuum_einstein_spacetime_evolution(const struct gkyl_wv_eqn *eqn) { - const struct wv_vacuum_einstein *vacuum_einstein = container_of(eqn, struct wv_vacuum_einstein, eqn); + const struct wv_vacuum_einstein *vacuum_einstein = + container_of(eqn, struct wv_vacuum_einstein, eqn); enum gkyl_spacetime_evolution spacetime_evolution = vacuum_einstein->spacetime_evolution; return spacetime_evolution; diff --git a/moments/zero/wv_vacuum_einstein_conformal.c b/moments/zero/wv_vacuum_einstein_conformal.c index 0da105eec9..8a0d339c9f 100644 --- a/moments/zero/wv_vacuum_einstein_conformal.c +++ b/moments/zero/wv_vacuum_einstein_conformal.c @@ -6,44 +6,78 @@ #include #include -void -gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, enum gkyl_spacetime_evolution spacetime_evolution, - const double q[77], double flux[77]) +void gkyl_vacuum_einstein_conformal_flux( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, + enum gkyl_spacetime_evolution spacetime_evolution, const double q[77], double flux[77] +) { double bssn_conformal_fact = q[64]; double conformal_fact = 1.0 / sqrt(bssn_conformal_fact); double bssn_conformal_fact_der[3]; - bssn_conformal_fact_der[0] = q[65]; bssn_conformal_fact_der[1] = q[66]; bssn_conformal_fact_der[2] = q[67]; + bssn_conformal_fact_der[0] = q[65]; + bssn_conformal_fact_der[1] = q[66]; + bssn_conformal_fact_der[2] = q[67]; double conformal_fact_der[3]; for (int i = 0; i < 3; i++) { - conformal_fact_der[i] = -(0.5 * bssn_conformal_fact_der[i]) / (pow(bssn_conformal_fact, 1.5) * conformal_fact); + conformal_fact_der[i] = + -(0.5 * bssn_conformal_fact_der[i]) / (pow(bssn_conformal_fact, 1.5) * conformal_fact); } double conformal_spatial_metric[3][3]; - conformal_spatial_metric[0][0] = q[0]; conformal_spatial_metric[0][1] = q[1]; conformal_spatial_metric[0][2] = q[2]; - conformal_spatial_metric[1][0] = q[3]; conformal_spatial_metric[1][1] = q[4]; conformal_spatial_metric[1][2] = q[5]; - conformal_spatial_metric[2][0] = q[6]; conformal_spatial_metric[2][1] = q[7]; conformal_spatial_metric[2][2] = q[8]; + conformal_spatial_metric[0][0] = q[0]; + conformal_spatial_metric[0][1] = q[1]; + conformal_spatial_metric[0][2] = q[2]; + conformal_spatial_metric[1][0] = q[3]; + conformal_spatial_metric[1][1] = q[4]; + conformal_spatial_metric[1][2] = q[5]; + conformal_spatial_metric[2][0] = q[6]; + conformal_spatial_metric[2][1] = q[7]; + conformal_spatial_metric[2][2] = q[8]; double conformal_lapse = q[9]; double conformal_extrinsic_curvature[3][3]; - conformal_extrinsic_curvature[0][0] = q[10]; conformal_extrinsic_curvature[0][1] = q[11]; conformal_extrinsic_curvature[0][2] = q[12]; - conformal_extrinsic_curvature[1][0] = q[13]; conformal_extrinsic_curvature[1][1] = q[14]; conformal_extrinsic_curvature[1][2] = q[15]; - conformal_extrinsic_curvature[2][0] = q[16]; conformal_extrinsic_curvature[2][1] = q[17]; conformal_extrinsic_curvature[2][2] = q[18]; + conformal_extrinsic_curvature[0][0] = q[10]; + conformal_extrinsic_curvature[0][1] = q[11]; + conformal_extrinsic_curvature[0][2] = q[12]; + conformal_extrinsic_curvature[1][0] = q[13]; + conformal_extrinsic_curvature[1][1] = q[14]; + conformal_extrinsic_curvature[1][2] = q[15]; + conformal_extrinsic_curvature[2][0] = q[16]; + conformal_extrinsic_curvature[2][1] = q[17]; + conformal_extrinsic_curvature[2][2] = q[18]; double conformal_spatial_metric_der[3][3][3]; - conformal_spatial_metric_der[0][0][0] = q[19]; conformal_spatial_metric_der[0][0][1] = q[20]; conformal_spatial_metric_der[0][0][2] = q[21]; - conformal_spatial_metric_der[0][1][0] = q[22]; conformal_spatial_metric_der[0][1][1] = q[23]; conformal_spatial_metric_der[0][1][2] = q[24]; - conformal_spatial_metric_der[0][2][0] = q[25]; conformal_spatial_metric_der[0][2][1] = q[26]; conformal_spatial_metric_der[0][2][2] = q[27]; - - conformal_spatial_metric_der[1][0][0] = q[28]; conformal_spatial_metric_der[1][0][1] = q[29]; conformal_spatial_metric_der[1][0][2] = q[30]; - conformal_spatial_metric_der[1][1][0] = q[31]; conformal_spatial_metric_der[1][1][1] = q[32]; conformal_spatial_metric_der[1][1][2] = q[33]; - conformal_spatial_metric_der[1][2][0] = q[34]; conformal_spatial_metric_der[1][2][1] = q[35]; conformal_spatial_metric_der[1][2][2] = q[36]; - - conformal_spatial_metric_der[2][0][0] = q[37]; conformal_spatial_metric_der[2][0][1] = q[38]; conformal_spatial_metric_der[2][0][2] = q[39]; - conformal_spatial_metric_der[2][1][0] = q[40]; conformal_spatial_metric_der[2][1][1] = q[41]; conformal_spatial_metric_der[2][1][2] = q[42]; - conformal_spatial_metric_der[2][2][0] = q[43]; conformal_spatial_metric_der[2][2][1] = q[44]; conformal_spatial_metric_der[2][2][2] = q[45]; + conformal_spatial_metric_der[0][0][0] = q[19]; + conformal_spatial_metric_der[0][0][1] = q[20]; + conformal_spatial_metric_der[0][0][2] = q[21]; + conformal_spatial_metric_der[0][1][0] = q[22]; + conformal_spatial_metric_der[0][1][1] = q[23]; + conformal_spatial_metric_der[0][1][2] = q[24]; + conformal_spatial_metric_der[0][2][0] = q[25]; + conformal_spatial_metric_der[0][2][1] = q[26]; + conformal_spatial_metric_der[0][2][2] = q[27]; + + conformal_spatial_metric_der[1][0][0] = q[28]; + conformal_spatial_metric_der[1][0][1] = q[29]; + conformal_spatial_metric_der[1][0][2] = q[30]; + conformal_spatial_metric_der[1][1][0] = q[31]; + conformal_spatial_metric_der[1][1][1] = q[32]; + conformal_spatial_metric_der[1][1][2] = q[33]; + conformal_spatial_metric_der[1][2][0] = q[34]; + conformal_spatial_metric_der[1][2][1] = q[35]; + conformal_spatial_metric_der[1][2][2] = q[36]; + + conformal_spatial_metric_der[2][0][0] = q[37]; + conformal_spatial_metric_der[2][0][1] = q[38]; + conformal_spatial_metric_der[2][0][2] = q[39]; + conformal_spatial_metric_der[2][1][0] = q[40]; + conformal_spatial_metric_der[2][1][1] = q[41]; + conformal_spatial_metric_der[2][1][2] = q[42]; + conformal_spatial_metric_der[2][2][0] = q[43]; + conformal_spatial_metric_der[2][2][1] = q[44]; + conformal_spatial_metric_der[2][2][2] = q[45]; double conformal_lapse_der[3]; conformal_lapse_der[0] = q[46]; @@ -61,9 +95,15 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti conformal_shift_vect[2] = q[54]; double conformal_shift_vect_der[3][3]; - conformal_shift_vect_der[0][0] = q[55]; conformal_shift_vect_der[0][1] = q[56]; conformal_shift_vect_der[0][2] = q[57]; - conformal_shift_vect_der[1][0] = q[58]; conformal_shift_vect_der[1][1] = q[59]; conformal_shift_vect_der[1][2] = q[60]; - conformal_shift_vect_der[2][0] = q[61]; conformal_shift_vect_der[2][1] = q[62]; conformal_shift_vect_der[2][2] = q[63]; + conformal_shift_vect_der[0][0] = q[55]; + conformal_shift_vect_der[0][1] = q[56]; + conformal_shift_vect_der[0][2] = q[57]; + conformal_shift_vect_der[1][0] = q[58]; + conformal_shift_vect_der[1][1] = q[59]; + conformal_shift_vect_der[1][2] = q[60]; + conformal_shift_vect_der[2][0] = q[61]; + conformal_shift_vect_der[2][1] = q[62]; + conformal_shift_vect_der[2][2] = q[63]; bool in_excision_region = false; if (conformal_lapse < excision_threshold) { @@ -71,7 +111,7 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti } if (!in_excision_region) { - double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -81,27 +121,28 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti double evolution_func = 0.0; if (spacetime_evolution == GKYL_RICCI_EVOLUTION) { evolution_func = 0.0; - } - else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { + } else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { evolution_func = 1.0; } double conformal_extrinsic_curvature_trace = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_extrinsic_curvature_trace += inv_conformal_spatial_metric[i][j] * conformal_extrinsic_curvature[i][j]; + conformal_extrinsic_curvature_trace += + inv_conformal_spatial_metric[i][j] * conformal_extrinsic_curvature[i][j]; } } double slicing_func = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { - slicing_func = conformal_extrinsic_curvature_trace / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { - slicing_func = 2.0 * conformal_extrinsic_curvature_trace / (conformal_lapse * (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + slicing_func = conformal_extrinsic_curvature_trace / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + slicing_func = + 2.0 * conformal_extrinsic_curvature_trace / + (conformal_lapse * (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); } double conformal_spatial_metric_der_raised1[3][3][3]; @@ -109,9 +150,10 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1[k][i][j] += inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; + conformal_spatial_metric_der_raised1[k][i][j] += + inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; } } } @@ -124,7 +166,8 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti conformal_spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3[i][j][k] += inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; + conformal_spatial_metric_der_raised3[i][j][k] += + inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; } } } @@ -133,7 +176,7 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti double conformal_aux_vect_raised[3]; for (int k = 0; k < 3; k++) { conformal_aux_vect_raised[k] = 0.0; - + for (int l = 0; l < 3; l++) { conformal_aux_vect_raised[k] += inv_conformal_spatial_metric[k][l] * conformal_aux_vect[l]; } @@ -145,7 +188,8 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti conformal_shift_vect_der_lowered[i][j] = 0.0; for (int k = 0; k < 3; k++) { - conformal_shift_vect_der_lowered[i][j] += conformal_spatial_metric[k][j] * conformal_shift_vect_der[i][k]; + conformal_shift_vect_der_lowered[i][j] += + conformal_spatial_metric[k][j] * conformal_shift_vect_der[i][k]; } } } @@ -157,7 +201,9 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_shift_vect_der_switched[i][k] += inv_conformal_spatial_metric[i][l] * conformal_spatial_metric[m][k] * conformal_shift_vect_der[l][m]; + conformal_shift_vect_der_switched[i][k] += inv_conformal_spatial_metric[i][l] * + conformal_spatial_metric[m][k] * + conformal_shift_vect_der[l][m]; } } } @@ -166,30 +212,40 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti double conformal_symmetrized_shift[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_symmetrized_shift[i][j] = (1.0 / conformal_lapse) * (conformal_shift_vect_der_lowered[i][j] + conformal_shift_vect_der_lowered[j][i]); + conformal_symmetrized_shift[i][j] = + (1.0 / conformal_lapse) * + (conformal_shift_vect_der_lowered[i][j] + conformal_shift_vect_der_lowered[j][i]); } } double conformal_extrinsic_curvature_flux[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_extrinsic_curvature_flux[i][j] = -conformal_shift_vect[0] * conformal_extrinsic_curvature[i][j]; - conformal_extrinsic_curvature_flux[i][j] += conformal_lapse * conformal_spatial_metric_der_raised1[0][i][j]; - conformal_extrinsic_curvature_flux[i][j] -= conformal_lapse * (0.5 * evolution_func) * conformal_aux_vect_raised[0] * conformal_spatial_metric[i][j]; + conformal_extrinsic_curvature_flux[i][j] = + -conformal_shift_vect[0] * conformal_extrinsic_curvature[i][j]; + conformal_extrinsic_curvature_flux[i][j] += + conformal_lapse * conformal_spatial_metric_der_raised1[0][i][j]; + conformal_extrinsic_curvature_flux[i][j] -= conformal_lapse * (0.5 * evolution_func) * + conformal_aux_vect_raised[0] * + conformal_spatial_metric[i][j]; if (i == 0) { - conformal_extrinsic_curvature_flux[i][j] += 0.5 * conformal_lapse * conformal_lapse_der[j]; + conformal_extrinsic_curvature_flux[i][j] += + 0.5 * conformal_lapse * conformal_lapse_der[j]; conformal_extrinsic_curvature_flux[i][j] += conformal_lapse * conformal_aux_vect[j]; for (int r = 0; r < 3; r++) { - conformal_extrinsic_curvature_flux[i][j] -= 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[j][r][r]; + conformal_extrinsic_curvature_flux[i][j] -= + 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[j][r][r]; } } if (j == 0) { - conformal_extrinsic_curvature_flux[i][j] += 0.5 * conformal_lapse * conformal_lapse_der[i]; + conformal_extrinsic_curvature_flux[i][j] += + 0.5 * conformal_lapse * conformal_lapse_der[i]; conformal_extrinsic_curvature_flux[i][j] += conformal_lapse * conformal_aux_vect[i]; for (int r = 0; r < 3; r++) { - conformal_extrinsic_curvature_flux[i][j] -= 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[i][r][r]; + conformal_extrinsic_curvature_flux[i][j] -= + 0.5 * conformal_lapse * conformal_spatial_metric_der_raised3[i][r][r]; } } } @@ -203,13 +259,17 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti } for (int r = 0; r < 3; r++) { - conformal_spatial_metric_der_flux[0][i][j] -= conformal_shift_vect[r] * conformal_spatial_metric_der[r][i][j]; - conformal_spatial_metric_der_flux[0][i][j] -= 2.0 * conformal_shift_vect[r] * conformal_fact_der[r] * conformal_spatial_metric[i][j]; + conformal_spatial_metric_der_flux[0][i][j] -= + conformal_shift_vect[r] * conformal_spatial_metric_der[r][i][j]; + conformal_spatial_metric_der_flux[0][i][j] -= + 2.0 * conformal_shift_vect[r] * conformal_fact_der[r] * conformal_spatial_metric[i][j]; } - conformal_spatial_metric_der_flux[0][i][j] += conformal_lapse * (conformal_extrinsic_curvature[i][j] / - (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); - conformal_spatial_metric_der_flux[0][i][j] -= conformal_lapse * conformal_symmetrized_shift[i][j]; + conformal_spatial_metric_der_flux[0][i][j] += + conformal_lapse * (conformal_extrinsic_curvature[i][j] / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); + conformal_spatial_metric_der_flux[0][i][j] -= + conformal_lapse * conformal_symmetrized_shift[i][j]; } } @@ -229,26 +289,50 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti conformal_aux_vect_flux[i] += conformal_shift_vect_der_switched[0][i]; conformal_aux_vect_flux[i] -= conformal_shift_vect_der[i][0]; } - + for (int i = 0; i < 10; i++) { flux[i] = 0.0; } - flux[10] = conformal_extrinsic_curvature_flux[0][0]; flux[11] = conformal_extrinsic_curvature_flux[0][1]; flux[12] = conformal_extrinsic_curvature_flux[0][2]; - flux[13] = conformal_extrinsic_curvature_flux[1][0]; flux[14] = conformal_extrinsic_curvature_flux[1][1]; flux[15] = conformal_extrinsic_curvature_flux[1][2]; - flux[16] = conformal_extrinsic_curvature_flux[2][0]; flux[17] = conformal_extrinsic_curvature_flux[2][1]; flux[18] = conformal_extrinsic_curvature_flux[2][2]; - - flux[19] = conformal_spatial_metric_der_flux[0][0][0]; flux[20] = conformal_spatial_metric_der_flux[0][0][1]; flux[21] = conformal_spatial_metric_der_flux[0][0][2]; - flux[22] = conformal_spatial_metric_der_flux[0][1][0]; flux[23] = conformal_spatial_metric_der_flux[0][1][1]; flux[24] = conformal_spatial_metric_der_flux[0][1][2]; - flux[25] = conformal_spatial_metric_der_flux[0][2][0]; flux[26] = conformal_spatial_metric_der_flux[0][2][1]; flux[27] = conformal_spatial_metric_der_flux[0][2][2]; - - flux[28] = conformal_spatial_metric_der_flux[1][0][0]; flux[29] = conformal_spatial_metric_der_flux[1][0][1]; flux[30] = conformal_spatial_metric_der_flux[1][0][2]; - flux[31] = conformal_spatial_metric_der_flux[1][1][0]; flux[32] = conformal_spatial_metric_der_flux[1][1][1]; flux[33] = conformal_spatial_metric_der_flux[1][1][2]; - flux[34] = conformal_spatial_metric_der_flux[1][2][0]; flux[35] = conformal_spatial_metric_der_flux[1][2][1]; flux[36] = conformal_spatial_metric_der_flux[1][2][2]; - - flux[37] = conformal_spatial_metric_der_flux[2][0][0]; flux[38] = conformal_spatial_metric_der_flux[2][0][1]; flux[39] = conformal_spatial_metric_der_flux[2][0][2]; - flux[40] = conformal_spatial_metric_der_flux[2][1][0]; flux[41] = conformal_spatial_metric_der_flux[2][1][1]; flux[42] = conformal_spatial_metric_der_flux[2][1][2]; - flux[43] = conformal_spatial_metric_der_flux[2][2][0]; flux[44] = conformal_spatial_metric_der_flux[2][2][1]; flux[45] = conformal_spatial_metric_der_flux[2][2][2]; + flux[10] = conformal_extrinsic_curvature_flux[0][0]; + flux[11] = conformal_extrinsic_curvature_flux[0][1]; + flux[12] = conformal_extrinsic_curvature_flux[0][2]; + flux[13] = conformal_extrinsic_curvature_flux[1][0]; + flux[14] = conformal_extrinsic_curvature_flux[1][1]; + flux[15] = conformal_extrinsic_curvature_flux[1][2]; + flux[16] = conformal_extrinsic_curvature_flux[2][0]; + flux[17] = conformal_extrinsic_curvature_flux[2][1]; + flux[18] = conformal_extrinsic_curvature_flux[2][2]; + + flux[19] = conformal_spatial_metric_der_flux[0][0][0]; + flux[20] = conformal_spatial_metric_der_flux[0][0][1]; + flux[21] = conformal_spatial_metric_der_flux[0][0][2]; + flux[22] = conformal_spatial_metric_der_flux[0][1][0]; + flux[23] = conformal_spatial_metric_der_flux[0][1][1]; + flux[24] = conformal_spatial_metric_der_flux[0][1][2]; + flux[25] = conformal_spatial_metric_der_flux[0][2][0]; + flux[26] = conformal_spatial_metric_der_flux[0][2][1]; + flux[27] = conformal_spatial_metric_der_flux[0][2][2]; + + flux[28] = conformal_spatial_metric_der_flux[1][0][0]; + flux[29] = conformal_spatial_metric_der_flux[1][0][1]; + flux[30] = conformal_spatial_metric_der_flux[1][0][2]; + flux[31] = conformal_spatial_metric_der_flux[1][1][0]; + flux[32] = conformal_spatial_metric_der_flux[1][1][1]; + flux[33] = conformal_spatial_metric_der_flux[1][1][2]; + flux[34] = conformal_spatial_metric_der_flux[1][2][0]; + flux[35] = conformal_spatial_metric_der_flux[1][2][1]; + flux[36] = conformal_spatial_metric_der_flux[1][2][2]; + + flux[37] = conformal_spatial_metric_der_flux[2][0][0]; + flux[38] = conformal_spatial_metric_der_flux[2][0][1]; + flux[39] = conformal_spatial_metric_der_flux[2][0][2]; + flux[40] = conformal_spatial_metric_der_flux[2][1][0]; + flux[41] = conformal_spatial_metric_der_flux[2][1][1]; + flux[42] = conformal_spatial_metric_der_flux[2][1][2]; + flux[43] = conformal_spatial_metric_der_flux[2][2][0]; + flux[44] = conformal_spatial_metric_der_flux[2][2][1]; + flux[45] = conformal_spatial_metric_der_flux[2][2][2]; flux[46] = conformal_lapse_der_flux[0]; flux[47] = conformal_lapse_der_flux[1]; @@ -261,32 +345,44 @@ gkyl_vacuum_einstein_conformal_flux(double excision_threshold, enum gkyl_spaceti for (int i = 52; i < 77; i++) { flux[i] = 0.0; } - + for (int i = 0; i < 3; i++) { gkyl_free(inv_conformal_spatial_metric[i]); } gkyl_free(inv_conformal_spatial_metric); - } - else { + } else { for (int i = 0; i < 77; i++) { flux[i] = 0.0; } } } -void -gkyl_vacuum_einstein_conformal_inv_spatial_metric(const double q[77], double ***inv_conformal_spatial_metric) +void gkyl_vacuum_einstein_conformal_inv_spatial_metric( + const double q[77], double ***inv_conformal_spatial_metric +) { double conformal_spatial_metric[3][3]; - conformal_spatial_metric[0][0] = q[0]; conformal_spatial_metric[0][1] = q[1]; conformal_spatial_metric[0][2] = q[2]; - conformal_spatial_metric[1][0] = q[3]; conformal_spatial_metric[1][1] = q[4]; conformal_spatial_metric[1][2] = q[5]; - conformal_spatial_metric[2][0] = q[6]; conformal_spatial_metric[2][1] = q[7]; conformal_spatial_metric[2][2] = q[8]; + conformal_spatial_metric[0][0] = q[0]; + conformal_spatial_metric[0][1] = q[1]; + conformal_spatial_metric[0][2] = q[2]; + conformal_spatial_metric[1][0] = q[3]; + conformal_spatial_metric[1][1] = q[4]; + conformal_spatial_metric[1][2] = q[5]; + conformal_spatial_metric[2][0] = q[6]; + conformal_spatial_metric[2][1] = q[7]; + conformal_spatial_metric[2][2] = q[8]; double conformal_spatial_det = - (conformal_spatial_metric[0][0] * ((conformal_spatial_metric[1][1] * conformal_spatial_metric[2][2]) - (conformal_spatial_metric[2][1] * conformal_spatial_metric[1][2]))) - - (conformal_spatial_metric[0][1] * ((conformal_spatial_metric[1][0] * conformal_spatial_metric[2][2]) - (conformal_spatial_metric[1][2] * conformal_spatial_metric[2][0]))) + - (conformal_spatial_metric[0][2] * ((conformal_spatial_metric[1][0] * conformal_spatial_metric[2][1]) - (conformal_spatial_metric[1][1] * conformal_spatial_metric[2][0]))); - + (conformal_spatial_metric[0][0] * + ((conformal_spatial_metric[1][1] * conformal_spatial_metric[2][2]) - + (conformal_spatial_metric[2][1] * conformal_spatial_metric[1][2]))) - + (conformal_spatial_metric[0][1] * + ((conformal_spatial_metric[1][0] * conformal_spatial_metric[2][2]) - + (conformal_spatial_metric[1][2] * conformal_spatial_metric[2][0]))) + + (conformal_spatial_metric[0][2] * + ((conformal_spatial_metric[1][0] * conformal_spatial_metric[2][1]) - + (conformal_spatial_metric[1][1] * conformal_spatial_metric[2][0]))); + double trace = 0.0; for (int i = 0; i < 3; i++) { trace += conformal_spatial_metric[i][i]; @@ -302,7 +398,8 @@ gkyl_vacuum_einstein_conformal_inv_spatial_metric(const double q[77], double *** for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { - conformal_spatial_metric_sq[i][j] += conformal_spatial_metric[i][k] * conformal_spatial_metric[k][j]; + conformal_spatial_metric_sq[i][j] += + conformal_spatial_metric[i][k] * conformal_spatial_metric[k][j]; } } } @@ -317,8 +414,7 @@ gkyl_vacuum_einstein_conformal_inv_spatial_metric(const double q[77], double *** for (int j = 0; j < 3; j++) { if (i == j) { euclidean_metric[i][j] = 1.0; - } - else { + } else { euclidean_metric[i][j] = 0.0; } } @@ -326,14 +422,17 @@ gkyl_vacuum_einstein_conformal_inv_spatial_metric(const double q[77], double *** for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - (*inv_conformal_spatial_metric)[i][j] = (1.0 / conformal_spatial_det) * - ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - (trace * conformal_spatial_metric[i][j]) + conformal_spatial_metric_sq[i][j]); + (*inv_conformal_spatial_metric)[i][j] = + (1.0 / conformal_spatial_det) * + ((0.5 * ((trace * trace) - sq_trace) * euclidean_metric[i][j]) - + (trace * conformal_spatial_metric[i][j]) + conformal_spatial_metric_sq[i][j]); } } } -static inline double -gkyl_vacuum_einstein_conformal_max_abs_speed(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, const double q[77]) +static inline double gkyl_vacuum_einstein_conformal_max_abs_speed( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, const double q[77] +) { double bssn_conformal_fact = q[64]; double conformal_fact = 1.0 / sqrt(bssn_conformal_fact); @@ -345,7 +444,7 @@ gkyl_vacuum_einstein_conformal_max_abs_speed(double excision_threshold, enum gky conformal_shift_vect[1] = q[53]; conformal_shift_vect[2] = q[54]; - double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -355,12 +454,11 @@ gkyl_vacuum_einstein_conformal_max_abs_speed(double excision_threshold, enum gky double slicing_func = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { slicing_func = 1.0 / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { - slicing_func = 2.0 / (conformal_lapse * (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + slicing_func = + 2.0 / (conformal_lapse * (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); } bool in_excision_region = false; @@ -375,22 +473,33 @@ gkyl_vacuum_einstein_conformal_max_abs_speed(double excision_threshold, enum gky if (fabs(conformal_shift_vect[i]) > max_eig) { max_eig = fabs(conformal_shift_vect[i]); } - if (fabs(-conformal_shift_vect[i] + (conformal_lapse * sqrt(slicing_func * inv_conformal_spatial_metric[i][i]))) > max_eig) { - max_eig = fabs(-conformal_shift_vect[i] + (conformal_lapse * sqrt(slicing_func * inv_conformal_spatial_metric[i][i]))); + if (fabs( + -conformal_shift_vect[i] + + (conformal_lapse * sqrt(slicing_func * inv_conformal_spatial_metric[i][i])) + ) > max_eig) { + max_eig = fabs( + -conformal_shift_vect[i] + + (conformal_lapse * sqrt(slicing_func * inv_conformal_spatial_metric[i][i])) + ); } - if (fabs(-conformal_shift_vect[i] - (conformal_lapse * sqrt(slicing_func * inv_conformal_spatial_metric[i][i]))) > max_eig) { - max_eig = fabs(-conformal_shift_vect[i] - (conformal_lapse * sqrt(slicing_func * inv_conformal_spatial_metric[i][i]))); + if (fabs( + -conformal_shift_vect[i] - + (conformal_lapse * sqrt(slicing_func * inv_conformal_spatial_metric[i][i])) + ) > max_eig) { + max_eig = fabs( + -conformal_shift_vect[i] - + (conformal_lapse * sqrt(slicing_func * inv_conformal_spatial_metric[i][i])) + ); } } - + for (int i = 0; i < 3; i++) { gkyl_free(inv_conformal_spatial_metric[i]); } gkyl_free(inv_conformal_spatial_metric); return max_eig; - } - else { + } else { for (int i = 0; i < 3; i++) { gkyl_free(inv_conformal_spatial_metric[i]); } @@ -401,7 +510,7 @@ gkyl_vacuum_einstein_conformal_max_abs_speed(double excision_threshold, enum gky } static inline void -cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* qin, double* wout) +cons_to_riem(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *qin, double *wout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 77; i++) { @@ -410,7 +519,7 @@ cons_to_riem(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } static inline void -riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* win, double* qout) +riem_to_cons(const struct gkyl_wv_eqn *eqn, const double *qstate, const double *win, double *qout) { // TODO: This should use a proper L matrix. for (int i = 0; i < 77; i++) { @@ -418,57 +527,104 @@ riem_to_cons(const struct gkyl_wv_eqn* eqn, const double* qstate, const double* } } -static void -vacuum_einstein_conformal_wall(const struct gkyl_wv_eqn* eqn, double t, int nc, const double* skin, double* GKYL_RESTRICT ghost, void* ctx) +static void vacuum_einstein_conformal_wall( + const struct gkyl_wv_eqn *eqn, double t, int nc, const double *skin, double *GKYL_RESTRICT ghost, + void *ctx +) { // Set spatial metric tensor. - ghost[0] = 1.0; ghost[1] = 0.0; ghost[2] = 0.0; - ghost[3] = 0.0; ghost[4] = 1.0; ghost[5] = 0.0; - ghost[6] = 0.0; ghost[7] = 0.0; ghost[8] = 1.0; + ghost[0] = 1.0; + ghost[1] = 0.0; + ghost[2] = 0.0; + ghost[3] = 0.0; + ghost[4] = 1.0; + ghost[5] = 0.0; + ghost[6] = 0.0; + ghost[7] = 0.0; + ghost[8] = 1.0; // Set lapse gauge variable. ghost[9] = 1.0; // Set extrinsic curvature tensor. - ghost[10] = 0.0; ghost[11] = 0.0; ghost[12] = 0.0; - ghost[13] = 0.0; ghost[14] = 0.0; ghost[15] = 0.0; - ghost[16] = 0.0; ghost[17] = 0.0; ghost[18] = 0.0; + ghost[10] = 0.0; + ghost[11] = 0.0; + ghost[12] = 0.0; + ghost[13] = 0.0; + ghost[14] = 0.0; + ghost[15] = 0.0; + ghost[16] = 0.0; + ghost[17] = 0.0; + ghost[18] = 0.0; // Set spatial metric tensor derivatives. - ghost[19] = 0.0; ghost[20] = 0.0; ghost[21] = 0.0; - ghost[22] = 0.0; ghost[23] = 0.0; ghost[24] = 0.0; - ghost[25] = 0.0; ghost[26] = 0.0; ghost[27] = 0.0; - - ghost[28] = 0.0; ghost[29] = 0.0; ghost[30] = 0.0; - ghost[31] = 0.0; ghost[32] = 0.0; ghost[33] = 0.0; - ghost[34] = 0.0; ghost[35] = 0.0; ghost[36] = 0.0; - - ghost[37] = 0.0; ghost[38] = 0.0; ghost[39] = 0.0; - ghost[40] = 0.0; ghost[41] = 0.0; ghost[42] = 0.0; - ghost[43] = 0.0; ghost[44] = 0.0; ghost[45] = 0.0; + ghost[19] = 0.0; + ghost[20] = 0.0; + ghost[21] = 0.0; + ghost[22] = 0.0; + ghost[23] = 0.0; + ghost[24] = 0.0; + ghost[25] = 0.0; + ghost[26] = 0.0; + ghost[27] = 0.0; + + ghost[28] = 0.0; + ghost[29] = 0.0; + ghost[30] = 0.0; + ghost[31] = 0.0; + ghost[32] = 0.0; + ghost[33] = 0.0; + ghost[34] = 0.0; + ghost[35] = 0.0; + ghost[36] = 0.0; + + ghost[37] = 0.0; + ghost[38] = 0.0; + ghost[39] = 0.0; + ghost[40] = 0.0; + ghost[41] = 0.0; + ghost[42] = 0.0; + ghost[43] = 0.0; + ghost[44] = 0.0; + ghost[45] = 0.0; // Set lapse function derivatives. - ghost[46] = 0.0; ghost[47] = 0.0; ghost[48] = 0.0; + ghost[46] = 0.0; + ghost[47] = 0.0; + ghost[48] = 0.0; // Set auxiliary vector. - ghost[49] = 0.0; ghost[50] = 0.0; ghost[51] = 0.0; + ghost[49] = 0.0; + ghost[50] = 0.0; + ghost[51] = 0.0; // Set shift gauge variables. - ghost[52] = 0.0; ghost[53] = 0.0; ghost[54] = 0.0; + ghost[52] = 0.0; + ghost[53] = 0.0; + ghost[54] = 0.0; // Set shift vector derivatives. - ghost[55] = 0.0; ghost[56] = 0.0; ghost[57] = 0.0; - ghost[58] = 0.0; ghost[59] = 0.0; ghost[60] = 0.0; - ghost[61] = 0.0; ghost[62] = 0.0; ghost[63] = 0.0; + ghost[55] = 0.0; + ghost[56] = 0.0; + ghost[57] = 0.0; + ghost[58] = 0.0; + ghost[59] = 0.0; + ghost[60] = 0.0; + ghost[61] = 0.0; + ghost[62] = 0.0; + ghost[63] = 0.0; // Set BSSN conformal factor and derivatives. ghost[64] = 1.0; - ghost[65] = 0.0; ghost[66] = 0.0; ghost[67] = 0.0; + ghost[65] = 0.0; + ghost[66] = 0.0; + ghost[67] = 0.0; } -static inline void -rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qglobal, - double* GKYL_RESTRICT qlocal) +static inline void rot_to_local( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qglobal, double *GKYL_RESTRICT qlocal +) { // Temporary arrays to store rotated column vectors. double r1[3], r2[3], r3[3]; @@ -499,9 +655,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta v3[2] = (r1[2] * tau2[0]) + (r2[2] * tau2[1]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor to local coordinate frame. - qlocal[0] = v1[0]; qlocal[1] = v1[1]; qlocal[2] = v1[2]; - qlocal[3] = v2[0]; qlocal[4] = v2[1]; qlocal[5] = v2[2]; - qlocal[6] = v3[0]; qlocal[7] = v3[1]; qlocal[8] = v3[2]; + qlocal[0] = v1[0]; + qlocal[1] = v1[1]; + qlocal[2] = v1[2]; + qlocal[3] = v2[0]; + qlocal[4] = v2[1]; + qlocal[5] = v2[2]; + qlocal[6] = v3[0]; + qlocal[7] = v3[1]; + qlocal[8] = v3[2]; qlocal[9] = qglobal[9]; @@ -534,9 +696,15 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta inv_v3[2] = (extr_r1[2] * tau2[0]) + (extr_r2[2] * tau2[1]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor to local coordinate frame. - qlocal[10] = inv_v1[0]; qlocal[11] = inv_v1[1]; qlocal[12] = inv_v1[2]; - qlocal[13] = inv_v2[0]; qlocal[14] = inv_v2[1]; qlocal[15] = inv_v2[2]; - qlocal[16] = inv_v3[0]; qlocal[17] = inv_v3[1]; qlocal[18] = inv_v3[2]; + qlocal[10] = inv_v1[0]; + qlocal[11] = inv_v1[1]; + qlocal[12] = inv_v1[2]; + qlocal[13] = inv_v2[0]; + qlocal[14] = inv_v2[1]; + qlocal[15] = inv_v2[2]; + qlocal[16] = inv_v3[0]; + qlocal[17] = inv_v3[1]; + qlocal[18] = inv_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -619,7 +787,7 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta s33[0] = (r31[0] * tau2[0]) + (r32[0] * tau2[1]) + (r33[0] * tau2[2]); s33[1] = (r31[1] * tau2[0]) + (r32[1] * tau2[1]) + (r33[1] * tau2[2]); s33[2] = (r31[2] * tau2[0]) + (r32[2] * tau2[1]) + (r33[2] * tau2[2]); - + // Rotate spatial metric tensor derivative to local coordinate frame. qlocal[19] = (s11[0] * norm[0]) + (s21[0] * norm[1]) + (s31[0] * norm[2]); qlocal[20] = (s11[1] * norm[0]) + (s21[1] * norm[1]) + (s31[1] * norm[2]); @@ -685,22 +853,37 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); - shiftder_v1[1] = (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); - shiftder_v1[2] = (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); - shiftder_v2[1] = (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); - shiftder_v2[2] = (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); - shiftder_v3[1] = (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); - shiftder_v3[2] = (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * norm[1]) + (shiftder_r3[0] * norm[2]); + shiftder_v1[1] = + (shiftder_r1[0] * tau1[0]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau1[2]); + shiftder_v1[2] = + (shiftder_r1[0] * tau2[0]) + (shiftder_r2[0] * tau2[1]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * norm[1]) + (shiftder_r3[1] * norm[2]); + shiftder_v2[1] = + (shiftder_r1[1] * tau1[0]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau1[2]); + shiftder_v2[2] = + (shiftder_r1[1] * tau2[0]) + (shiftder_r2[1] * tau2[1]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * norm[1]) + (shiftder_r3[2] * norm[2]); + shiftder_v3[1] = + (shiftder_r1[2] * tau1[0]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau1[2]); + shiftder_v3[2] = + (shiftder_r1[2] * tau2[0]) + (shiftder_r2[2] * tau2[1]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative to local coordinate frame. - qlocal[55] = shiftder_v1[0]; qlocal[56] = shiftder_v1[1]; qlocal[57] = shiftder_v1[2]; - qlocal[58] = shiftder_v2[0]; qlocal[59] = shiftder_v2[1]; qlocal[60] = shiftder_v2[2]; - qlocal[61] = shiftder_v3[0]; qlocal[62] = shiftder_v3[1]; qlocal[63] = shiftder_v3[2]; + qlocal[55] = shiftder_v1[0]; + qlocal[56] = shiftder_v1[1]; + qlocal[57] = shiftder_v1[2]; + qlocal[58] = shiftder_v2[0]; + qlocal[59] = shiftder_v2[1]; + qlocal[60] = shiftder_v2[2]; + qlocal[61] = shiftder_v3[0]; + qlocal[62] = shiftder_v3[1]; + qlocal[63] = shiftder_v3[2]; qlocal[64] = qglobal[64]; qlocal[65] = (qglobal[65] * norm[0]) + (qglobal[66] * norm[1]) + (qglobal[67] * norm[2]); @@ -708,9 +891,10 @@ rot_to_local(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* ta qlocal[67] = (qglobal[65] * tau2[0]) + (qglobal[66] * tau2[1]) + (qglobal[67] * tau2[2]); } -static inline void -rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* tau2, const double* norm, const double* GKYL_RESTRICT qlocal, - double* GKYL_RESTRICT qglobal) +static inline void rot_to_global( + const struct gkyl_wv_eqn *eqn, const double *tau1, const double *tau2, const double *norm, + const double *GKYL_RESTRICT qlocal, double *GKYL_RESTRICT qglobal +) { // Temporary arrays to store rotated column vectors. double r1[3], r2[3], r3[3]; @@ -741,9 +925,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t v3[2] = (r1[2] * norm[2]) + (r2[2] * tau1[2]) + (r3[2] * tau2[2]); // Rotate spatial metric tensor back to global coordinate frame. - qglobal[0] = v1[0]; qglobal[1] = v1[1]; qglobal[2] = v1[2]; - qglobal[3] = v2[0]; qglobal[4] = v2[1]; qglobal[5] = v2[2]; - qglobal[6] = v3[0]; qglobal[7] = v3[1]; qglobal[8] = v3[2]; + qglobal[0] = v1[0]; + qglobal[1] = v1[1]; + qglobal[2] = v1[2]; + qglobal[3] = v2[0]; + qglobal[4] = v2[1]; + qglobal[5] = v2[2]; + qglobal[6] = v3[0]; + qglobal[7] = v3[1]; + qglobal[8] = v3[2]; qglobal[9] = qlocal[9]; @@ -776,9 +966,15 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t inv_v3[2] = (extr_r1[2] * norm[2]) + (extr_r2[2] * tau1[2]) + (extr_r3[2] * tau2[2]); // Rotate extrinsic curvature tensor back to global coordinate frame. - qglobal[10] = inv_v1[0]; qglobal[11] = inv_v1[1]; qglobal[12] = inv_v1[2]; - qglobal[13] = inv_v2[0]; qglobal[14] = inv_v2[1]; qglobal[15] = inv_v2[2]; - qglobal[16] = inv_v3[0]; qglobal[17] = inv_v3[1]; qglobal[18] = inv_v3[2]; + qglobal[10] = inv_v1[0]; + qglobal[11] = inv_v1[1]; + qglobal[12] = inv_v1[2]; + qglobal[13] = inv_v2[0]; + qglobal[14] = inv_v2[1]; + qglobal[15] = inv_v2[2]; + qglobal[16] = inv_v3[0]; + qglobal[17] = inv_v3[1]; + qglobal[18] = inv_v3[2]; // Temporary arrays to store rotated column vectors. double r11[3], r12[3], r13[3]; @@ -927,22 +1123,37 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t // Temporary arrays to store rotated shift derivative row vectors. double shiftder_v1[3], shiftder_v2[3], shiftder_v3[3]; - shiftder_v1[0] = (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); - shiftder_v1[1] = (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); - shiftder_v1[2] = (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); - - shiftder_v2[0] = (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); - shiftder_v2[1] = (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); - shiftder_v2[2] = (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); - - shiftder_v3[0] = (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); - shiftder_v3[1] = (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); - shiftder_v3[2] = (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); + shiftder_v1[0] = + (shiftder_r1[0] * norm[0]) + (shiftder_r2[0] * tau1[0]) + (shiftder_r3[0] * tau2[0]); + shiftder_v1[1] = + (shiftder_r1[0] * norm[1]) + (shiftder_r2[0] * tau1[1]) + (shiftder_r3[0] * tau2[1]); + shiftder_v1[2] = + (shiftder_r1[0] * norm[2]) + (shiftder_r2[0] * tau1[2]) + (shiftder_r3[0] * tau2[2]); + + shiftder_v2[0] = + (shiftder_r1[1] * norm[0]) + (shiftder_r2[1] * tau1[0]) + (shiftder_r3[1] * tau2[0]); + shiftder_v2[1] = + (shiftder_r1[1] * norm[1]) + (shiftder_r2[1] * tau1[1]) + (shiftder_r3[1] * tau2[1]); + shiftder_v2[2] = + (shiftder_r1[1] * norm[2]) + (shiftder_r2[1] * tau1[2]) + (shiftder_r3[1] * tau2[2]); + + shiftder_v3[0] = + (shiftder_r1[2] * norm[0]) + (shiftder_r2[2] * tau1[0]) + (shiftder_r3[2] * tau2[0]); + shiftder_v3[1] = + (shiftder_r1[2] * norm[1]) + (shiftder_r2[2] * tau1[1]) + (shiftder_r3[2] * tau2[1]); + shiftder_v3[2] = + (shiftder_r1[2] * norm[2]) + (shiftder_r2[2] * tau1[2]) + (shiftder_r3[2] * tau2[2]); // Rotate shift vector derivative back to global coordinate frame. - qglobal[55] = shiftder_v1[0]; qglobal[56] = shiftder_v1[1]; qglobal[57] = shiftder_v1[2]; - qglobal[58] = shiftder_v2[0]; qglobal[59] = shiftder_v2[1]; qglobal[60] = shiftder_v2[2]; - qglobal[61] = shiftder_v3[0]; qglobal[62] = shiftder_v3[1]; qglobal[63] = shiftder_v3[2]; + qglobal[55] = shiftder_v1[0]; + qglobal[56] = shiftder_v1[1]; + qglobal[57] = shiftder_v1[2]; + qglobal[58] = shiftder_v2[0]; + qglobal[59] = shiftder_v2[1]; + qglobal[60] = shiftder_v2[2]; + qglobal[61] = shiftder_v3[0]; + qglobal[62] = shiftder_v3[1]; + qglobal[63] = shiftder_v3[2]; qglobal[64] = qlocal[64]; qglobal[65] = (qlocal[65] * norm[0]) + (qlocal[66] * tau1[0]) + (qlocal[67] * tau2[0]); @@ -950,21 +1161,31 @@ rot_to_global(const struct gkyl_wv_eqn* eqn, const double* tau1, const double* t qglobal[67] = (qlocal[65] * norm[2]) + (qlocal[66] * tau1[2]) + (qlocal[67] * tau2[2]); } -static double -wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_lax( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); + const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = + container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); double excision_threshold = vacuum_einstein_conformal->excision_threshold; enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein_conformal->spacetime_slicing; - enum gkyl_spacetime_evolution spacetime_evolution = vacuum_einstein_conformal->spacetime_evolution; + enum gkyl_spacetime_evolution spacetime_evolution = + vacuum_einstein_conformal->spacetime_evolution; - double sl = gkyl_vacuum_einstein_conformal_max_abs_speed(excision_threshold, spacetime_slicing, ql); - double sr = gkyl_vacuum_einstein_conformal_max_abs_speed(excision_threshold, spacetime_slicing, qr); + double sl = + gkyl_vacuum_einstein_conformal_max_abs_speed(excision_threshold, spacetime_slicing, ql); + double sr = + gkyl_vacuum_einstein_conformal_max_abs_speed(excision_threshold, spacetime_slicing, qr); double amax = fmax(sl, sr); double fl[77], fr[77]; - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, ql, fl); - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, qr, fr); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, ql, fl + ); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, qr, fr + ); bool in_excision_region_l = false; if (ql[9] < excision_threshold) { @@ -982,8 +1203,7 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = 0.5 * ((qr[i] - ql[i]) - (fr[i] - fl[i]) / amax); w1[i] = 0.5 * ((qr[i] - ql[i]) + (fr[i] - fl[i]) / amax); } - } - else { + } else { for (int i = 0; i < 77; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -996,8 +1216,10 @@ wave_lax(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return s[1]; } -static void -qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[77]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1009,27 +1231,34 @@ qfluct_lax(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, - double* waves, double* s) +static double wave_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { return wave_lax(eqn, delta, ql, qr, waves, s); } -static void -qfluct_lax_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, - const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_lax_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } -static double -wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, const double* qr, double* waves, double* s) +static double wave_hll( + const struct gkyl_wv_eqn *eqn, const double *delta, const double *ql, const double *qr, + double *waves, double *s +) { - const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); + const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = + container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); double excision_threshold = vacuum_einstein_conformal->excision_threshold; enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein_conformal->spacetime_slicing; - enum gkyl_spacetime_evolution spacetime_evolution = vacuum_einstein_conformal->spacetime_evolution; + enum gkyl_spacetime_evolution spacetime_evolution = + vacuum_einstein_conformal->spacetime_evolution; double conformal_lapse_l = ql[9]; double conformal_shiftx_l = ql[52]; @@ -1040,15 +1269,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double slicing_func_l = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func_l = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { - slicing_func_l = 1.0 / (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { - slicing_func_l = 2.0 / (conformal_lapse_l * (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l)); + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + slicing_func_l = + 1.0 / (conformal_fact_l * conformal_fact_l * conformal_fact_l * conformal_fact_l); + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + slicing_func_l = 2.0 / (conformal_lapse_l * (conformal_fact_l * conformal_fact_l * + conformal_fact_l * conformal_fact_l)); } - double **inv_conformal_spatial_metric_l = gkyl_malloc(sizeof(double*[3])); + double **inv_conformal_spatial_metric_l = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_conformal_spatial_metric_l[i] = gkyl_malloc(sizeof(double[3])); } @@ -1069,15 +1298,15 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double slicing_func_r = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func_r = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { - slicing_func_r = 1.0 / (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { - slicing_func_r = 2.0 / (conformal_lapse_l / (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r)); + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + slicing_func_r = + 1.0 / (conformal_fact_r * conformal_fact_r * conformal_fact_r * conformal_fact_r); + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + slicing_func_r = 2.0 / (conformal_lapse_l / (conformal_fact_r * conformal_fact_r * + conformal_fact_r * conformal_fact_r)); } - double **inv_conformal_spatial_metric_r = gkyl_malloc(sizeof(double*[3])); + double **inv_conformal_spatial_metric_r = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_conformal_spatial_metric_r[i] = gkyl_malloc(sizeof(double[3])); } @@ -1101,8 +1330,12 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c double sr = (vx_avg + cs_avg) / (1.0 + (vx_avg * cs_avg)); double fl[77], fr[77]; - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, ql, fl); - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, qr, fr); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, ql, fl + ); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, qr, fr + ); double qm[77]; for (int i = 0; i < 77; i++) { @@ -1115,8 +1348,7 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c w0[i] = qm[i] - ql[i]; w1[i] = qr[i] - qm[i]; } - } - else { + } else { for (int i = 0; i < 77; i++) { w0[i] = 0.0; w1[i] = 0.0; @@ -1136,8 +1368,10 @@ wave_hll(const struct gkyl_wv_eqn* eqn, const double* delta, const double* ql, c return fmax(fabs(sl), fabs(sr)); } -static void -qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll( + const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, const double *waves, + const double *s, double *amdq, double *apdq +) { const double *w0 = &waves[0], *w1 = &waves[77]; double s0m = fmin(0.0, s[0]), s1m = fmin(0.0, s[1]); @@ -1149,43 +1383,50 @@ qfluct_hll(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, co } } -static double -wave_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* delta, const double* ql, const double* qr, const double phil, const double phir, - double* waves, double* s) +static double wave_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *delta, const double *ql, + const double *qr, const double phil, const double phir, double *waves, double *s +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return wave_hll(eqn, delta, ql, qr, waves, s); - } - else { + } else { return wave_lax(eqn, delta, ql, qr, waves, s); } return 0.0; // Unreachable code. } -static void -qfluct_hll_l(const struct gkyl_wv_eqn* eqn, enum gkyl_wv_flux_type type, const double* ql, const double* qr, const double phil, const double phir, - const double* waves, const double* s, double* amdq, double* apdq) +static void qfluct_hll_l( + const struct gkyl_wv_eqn *eqn, enum gkyl_wv_flux_type type, const double *ql, const double *qr, + const double phil, const double phir, const double *waves, const double *s, double *amdq, + double *apdq +) { if (type == GKYL_WV_HIGH_ORDER_FLUX) { return qfluct_hll(eqn, ql, qr, waves, s, amdq, apdq); - } - else { + } else { return qfluct_lax(eqn, ql, qr, waves, s, amdq, apdq); } } static double -flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, double* flux_jump) +flux_jump(const struct gkyl_wv_eqn *eqn, const double *ql, const double *qr, double *flux_jump) { - const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); + const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = + container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); double excision_threshold = vacuum_einstein_conformal->excision_threshold; enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein_conformal->spacetime_slicing; - enum gkyl_spacetime_evolution spacetime_evolution = vacuum_einstein_conformal->spacetime_evolution; + enum gkyl_spacetime_evolution spacetime_evolution = + vacuum_einstein_conformal->spacetime_evolution; double fr[77], fl[77]; - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, ql, fl); - gkyl_vacuum_einstein_conformal_flux(excision_threshold, spacetime_slicing, spacetime_evolution, qr, fr); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, ql, fl + ); + gkyl_vacuum_einstein_conformal_flux( + excision_threshold, spacetime_slicing, spacetime_evolution, qr, fr + ); bool in_excision_region_l = false; if (ql[9] < excision_threshold) { @@ -1201,100 +1442,144 @@ flux_jump(const struct gkyl_wv_eqn* eqn, const double* ql, const double* qr, dou for (int m = 0; m < 77; m++) { flux_jump[m] = fr[m] - fl[m]; } - } - else { + } else { for (int m = 0; m < 77; m++) { flux_jump[m] = 0.0; } } - double amaxl = gkyl_vacuum_einstein_conformal_max_abs_speed(excision_threshold, spacetime_slicing, ql); - double amaxr = gkyl_vacuum_einstein_conformal_max_abs_speed(excision_threshold, spacetime_slicing, qr); + double amaxl = + gkyl_vacuum_einstein_conformal_max_abs_speed(excision_threshold, spacetime_slicing, ql); + double amaxr = + gkyl_vacuum_einstein_conformal_max_abs_speed(excision_threshold, spacetime_slicing, qr); return fmax(amaxl, amaxr); } -static bool -check_inv(const struct gkyl_wv_eqn* eqn, const double* q) +static bool check_inv(const struct gkyl_wv_eqn *eqn, const double *q) { if (q[9] < 0.0) { return false; - } - else { + } else { return true; } } -static double -max_speed(const struct gkyl_wv_eqn* eqn, const double* q) +static double max_speed(const struct gkyl_wv_eqn *eqn, const double *q) { - const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); + const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = + container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); double excision_threshold = vacuum_einstein_conformal->excision_threshold; enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein_conformal->spacetime_slicing; return gkyl_vacuum_einstein_conformal_max_abs_speed(excision_threshold, spacetime_slicing, q); } -static inline void -vacuum_einstein_conformal_cons_to_diag(const struct gkyl_wv_eqn* eqn, const double* qin, double* diag) +static inline void vacuum_einstein_conformal_cons_to_diag( + const struct gkyl_wv_eqn *eqn, const double *qin, double *diag +) { diag[0] = qin[9]; } static inline void -vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qin, double* sout) +vacuum_einstein_conformal_source(const struct gkyl_wv_eqn *eqn, const double *qin, double *sout) { - const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); + const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = + container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); double excision_threshold = vacuum_einstein_conformal->excision_threshold; enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein_conformal->spacetime_slicing; - enum gkyl_spacetime_evolution spacetime_evolution = vacuum_einstein_conformal->spacetime_evolution; + enum gkyl_spacetime_evolution spacetime_evolution = + vacuum_einstein_conformal->spacetime_evolution; double bssn_conformal_fact = qin[64]; double conformal_fact = 1.0 / sqrt(bssn_conformal_fact); double bssn_conformal_fact_der[3]; - bssn_conformal_fact_der[0] = qin[65]; bssn_conformal_fact_der[1] = qin[66]; bssn_conformal_fact_der[2] = qin[67]; + bssn_conformal_fact_der[0] = qin[65]; + bssn_conformal_fact_der[1] = qin[66]; + bssn_conformal_fact_der[2] = qin[67]; double conformal_fact_der[3]; for (int i = 0; i < 3; i++) { - conformal_fact_der[i] = -(0.5 * bssn_conformal_fact_der[i]) / (pow(bssn_conformal_fact, 1.5) * conformal_fact); + conformal_fact_der[i] = + -(0.5 * bssn_conformal_fact_der[i]) / (pow(bssn_conformal_fact, 1.5) * conformal_fact); } double bssn_conformal_fact_der2[3][3]; - bssn_conformal_fact_der2[0][0] = qin[68]; bssn_conformal_fact_der2[0][1] = qin[69]; bssn_conformal_fact_der2[0][2] = qin[70]; - bssn_conformal_fact_der2[1][0] = qin[71]; bssn_conformal_fact_der2[1][1] = qin[72]; bssn_conformal_fact_der2[1][2] = qin[73]; - bssn_conformal_fact_der2[2][0] = qin[74]; bssn_conformal_fact_der2[2][1] = qin[75]; bssn_conformal_fact_der2[2][2] = qin[76]; + bssn_conformal_fact_der2[0][0] = qin[68]; + bssn_conformal_fact_der2[0][1] = qin[69]; + bssn_conformal_fact_der2[0][2] = qin[70]; + bssn_conformal_fact_der2[1][0] = qin[71]; + bssn_conformal_fact_der2[1][1] = qin[72]; + bssn_conformal_fact_der2[1][2] = qin[73]; + bssn_conformal_fact_der2[2][0] = qin[74]; + bssn_conformal_fact_der2[2][1] = qin[75]; + bssn_conformal_fact_der2[2][2] = qin[76]; double conformal_fact_der2[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_fact_der2[i][j] = -(0.5 * bssn_conformal_fact_der2[i][j]) / (pow(bssn_conformal_fact, 1.5) * conformal_fact); - conformal_fact_der2[i][j] += (0.75 * bssn_conformal_fact_der[i] * bssn_conformal_fact_der[j]) / (pow(bssn_conformal_fact, 2.5) * conformal_fact); + conformal_fact_der2[i][j] = + -(0.5 * bssn_conformal_fact_der2[i][j]) / (pow(bssn_conformal_fact, 1.5) * conformal_fact); + conformal_fact_der2[i][j] += + (0.75 * bssn_conformal_fact_der[i] * bssn_conformal_fact_der[j]) / + (pow(bssn_conformal_fact, 2.5) * conformal_fact); } } double conformal_spatial_metric[3][3]; - conformal_spatial_metric[0][0] = qin[0]; conformal_spatial_metric[0][1] = qin[1]; conformal_spatial_metric[0][2] = qin[2]; - conformal_spatial_metric[1][0] = qin[3]; conformal_spatial_metric[1][1] = qin[4]; conformal_spatial_metric[1][2] = qin[5]; - conformal_spatial_metric[2][0] = qin[6]; conformal_spatial_metric[2][1] = qin[7]; conformal_spatial_metric[2][2] = qin[8]; + conformal_spatial_metric[0][0] = qin[0]; + conformal_spatial_metric[0][1] = qin[1]; + conformal_spatial_metric[0][2] = qin[2]; + conformal_spatial_metric[1][0] = qin[3]; + conformal_spatial_metric[1][1] = qin[4]; + conformal_spatial_metric[1][2] = qin[5]; + conformal_spatial_metric[2][0] = qin[6]; + conformal_spatial_metric[2][1] = qin[7]; + conformal_spatial_metric[2][2] = qin[8]; double conformal_lapse = qin[9]; double conformal_extrinsic_curvature[3][3]; - conformal_extrinsic_curvature[0][0] = qin[10]; conformal_extrinsic_curvature[0][1] = qin[11]; conformal_extrinsic_curvature[0][2] = qin[12]; - conformal_extrinsic_curvature[1][0] = qin[13]; conformal_extrinsic_curvature[1][1] = qin[14]; conformal_extrinsic_curvature[1][2] = qin[15]; - conformal_extrinsic_curvature[2][0] = qin[16]; conformal_extrinsic_curvature[2][1] = qin[17]; conformal_extrinsic_curvature[2][2] = qin[18]; + conformal_extrinsic_curvature[0][0] = qin[10]; + conformal_extrinsic_curvature[0][1] = qin[11]; + conformal_extrinsic_curvature[0][2] = qin[12]; + conformal_extrinsic_curvature[1][0] = qin[13]; + conformal_extrinsic_curvature[1][1] = qin[14]; + conformal_extrinsic_curvature[1][2] = qin[15]; + conformal_extrinsic_curvature[2][0] = qin[16]; + conformal_extrinsic_curvature[2][1] = qin[17]; + conformal_extrinsic_curvature[2][2] = qin[18]; double conformal_spatial_metric_der[3][3][3]; - conformal_spatial_metric_der[0][0][0] = qin[19]; conformal_spatial_metric_der[0][0][1] = qin[20]; conformal_spatial_metric_der[0][0][2] = qin[21]; - conformal_spatial_metric_der[0][1][0] = qin[22]; conformal_spatial_metric_der[0][1][1] = qin[23]; conformal_spatial_metric_der[0][1][2] = qin[24]; - conformal_spatial_metric_der[0][2][0] = qin[25]; conformal_spatial_metric_der[0][2][1] = qin[26]; conformal_spatial_metric_der[0][2][2] = qin[27]; - - conformal_spatial_metric_der[1][0][0] = qin[28]; conformal_spatial_metric_der[1][0][1] = qin[29]; conformal_spatial_metric_der[1][0][2] = qin[30]; - conformal_spatial_metric_der[1][1][0] = qin[31]; conformal_spatial_metric_der[1][1][1] = qin[32]; conformal_spatial_metric_der[1][1][2] = qin[33]; - conformal_spatial_metric_der[1][2][0] = qin[34]; conformal_spatial_metric_der[1][2][1] = qin[35]; conformal_spatial_metric_der[1][2][2] = qin[36]; - - conformal_spatial_metric_der[2][0][0] = qin[37]; conformal_spatial_metric_der[2][0][1] = qin[38]; conformal_spatial_metric_der[2][0][2] = qin[39]; - conformal_spatial_metric_der[2][1][0] = qin[40]; conformal_spatial_metric_der[2][1][1] = qin[41]; conformal_spatial_metric_der[2][1][2] = qin[42]; - conformal_spatial_metric_der[2][2][0] = qin[43]; conformal_spatial_metric_der[2][2][1] = qin[44]; conformal_spatial_metric_der[2][2][2] = qin[45]; + conformal_spatial_metric_der[0][0][0] = qin[19]; + conformal_spatial_metric_der[0][0][1] = qin[20]; + conformal_spatial_metric_der[0][0][2] = qin[21]; + conformal_spatial_metric_der[0][1][0] = qin[22]; + conformal_spatial_metric_der[0][1][1] = qin[23]; + conformal_spatial_metric_der[0][1][2] = qin[24]; + conformal_spatial_metric_der[0][2][0] = qin[25]; + conformal_spatial_metric_der[0][2][1] = qin[26]; + conformal_spatial_metric_der[0][2][2] = qin[27]; + + conformal_spatial_metric_der[1][0][0] = qin[28]; + conformal_spatial_metric_der[1][0][1] = qin[29]; + conformal_spatial_metric_der[1][0][2] = qin[30]; + conformal_spatial_metric_der[1][1][0] = qin[31]; + conformal_spatial_metric_der[1][1][1] = qin[32]; + conformal_spatial_metric_der[1][1][2] = qin[33]; + conformal_spatial_metric_der[1][2][0] = qin[34]; + conformal_spatial_metric_der[1][2][1] = qin[35]; + conformal_spatial_metric_der[1][2][2] = qin[36]; + + conformal_spatial_metric_der[2][0][0] = qin[37]; + conformal_spatial_metric_der[2][0][1] = qin[38]; + conformal_spatial_metric_der[2][0][2] = qin[39]; + conformal_spatial_metric_der[2][1][0] = qin[40]; + conformal_spatial_metric_der[2][1][1] = qin[41]; + conformal_spatial_metric_der[2][1][2] = qin[42]; + conformal_spatial_metric_der[2][2][0] = qin[43]; + conformal_spatial_metric_der[2][2][1] = qin[44]; + conformal_spatial_metric_der[2][2][2] = qin[45]; double conformal_lapse_der[3]; conformal_lapse_der[0] = qin[46]; @@ -1312,9 +1597,15 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi conformal_shift_vect[2] = qin[54]; double conformal_shift_vect_der[3][3]; - conformal_shift_vect_der[0][0] = qin[55]; conformal_shift_vect_der[0][1] = qin[56]; conformal_shift_vect_der[0][2] = qin[57]; - conformal_shift_vect_der[1][0] = qin[58]; conformal_shift_vect_der[1][1] = qin[59]; conformal_shift_vect_der[1][2] = qin[60]; - conformal_shift_vect_der[2][0] = qin[61]; conformal_shift_vect_der[2][1] = qin[62]; conformal_shift_vect_der[2][2] = qin[63]; + conformal_shift_vect_der[0][0] = qin[55]; + conformal_shift_vect_der[0][1] = qin[56]; + conformal_shift_vect_der[0][2] = qin[57]; + conformal_shift_vect_der[1][0] = qin[58]; + conformal_shift_vect_der[1][1] = qin[59]; + conformal_shift_vect_der[1][2] = qin[60]; + conformal_shift_vect_der[2][0] = qin[61]; + conformal_shift_vect_der[2][1] = qin[62]; + conformal_shift_vect_der[2][2] = qin[63]; bool in_excision_region = false; if (conformal_lapse < excision_threshold) { @@ -1322,7 +1613,7 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi } if (!in_excision_region) { - double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double*[3])); + double **inv_conformal_spatial_metric = gkyl_malloc(sizeof(double *[3])); for (int i = 0; i < 3; i++) { inv_conformal_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); } @@ -1332,15 +1623,15 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi double evolution_func = 0.0; if (spacetime_evolution == GKYL_RICCI_EVOLUTION) { evolution_func = 0.0; - } - else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { + } else if (spacetime_evolution == GKYL_EINSTEIN_EVOLUTION) { evolution_func = 1.0; } double conformal_extrinsic_curvature_trace = 0.0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_extrinsic_curvature_trace += inv_conformal_spatial_metric[i][j] * conformal_extrinsic_curvature[i][j]; + conformal_extrinsic_curvature_trace += + inv_conformal_spatial_metric[i][j] * conformal_extrinsic_curvature[i][j]; } } @@ -1350,7 +1641,8 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi conformal_extrinsic_curvature_mixed[i][j] = 0.0; for (int l = 0; l < 3; l++) { - conformal_extrinsic_curvature_mixed[i][j] += inv_conformal_spatial_metric[l][j] * conformal_extrinsic_curvature[i][l]; + conformal_extrinsic_curvature_mixed[i][j] += + inv_conformal_spatial_metric[l][j] * conformal_extrinsic_curvature[i][l]; } } } @@ -1362,7 +1654,9 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_extrinsic_curvature_raised[i][j] += inv_conformal_spatial_metric[i][l] * inv_conformal_spatial_metric[m][j] * conformal_extrinsic_curvature[l][m]; + conformal_extrinsic_curvature_raised[i][j] += inv_conformal_spatial_metric[i][l] * + inv_conformal_spatial_metric[m][j] * + conformal_extrinsic_curvature[l][m]; } } } @@ -1374,7 +1668,8 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi conformal_shift_vect_der_lowered[i][j] = 0.0; for (int k = 0; k < 3; k++) { - conformal_shift_vect_der_lowered[i][j] += conformal_spatial_metric[k][j] * conformal_shift_vect_der[i][k]; + conformal_shift_vect_der_lowered[i][j] += + conformal_spatial_metric[k][j] * conformal_shift_vect_der[i][k]; } } } @@ -1386,7 +1681,9 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_shift_vect_der_switched[i][k] += inv_conformal_spatial_metric[i][l] * conformal_spatial_metric[m][k] * conformal_shift_vect_der[l][m]; + conformal_shift_vect_der_switched[i][k] += inv_conformal_spatial_metric[i][l] * + conformal_spatial_metric[m][k] * + conformal_shift_vect_der[l][m]; } } } @@ -1400,19 +1697,22 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi double conformal_symmetrized_shift[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_symmetrized_shift[i][j] = (1.0 / conformal_lapse) * (conformal_shift_vect_der_lowered[i][j] + conformal_shift_vect_der_lowered[j][i]); + conformal_symmetrized_shift[i][j] = + (1.0 / conformal_lapse) * + (conformal_shift_vect_der_lowered[i][j] + conformal_shift_vect_der_lowered[j][i]); } } double slicing_func = 0.0; if (spacetime_slicing == GKYL_GEODESIC_SLICING) { slicing_func = 0.0; - } - else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { - slicing_func = conformal_extrinsic_curvature_trace / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - } - else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { - slicing_func = 2.0 * conformal_extrinsic_curvature_trace / (conformal_lapse * (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); + } else if (spacetime_slicing == GKYL_HARMONIC_SLICING) { + slicing_func = conformal_extrinsic_curvature_trace / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + } else if (spacetime_slicing == GKYL_1PLUSLOG_SLICING) { + slicing_func = + 2.0 * conformal_extrinsic_curvature_trace / + (conformal_lapse * (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); } double conformal_spatial_metric_der_raised1[3][3][3]; @@ -1420,9 +1720,10 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { conformal_spatial_metric_der_raised1[k][i][j] = 0.0; - + for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised1[k][i][j] += inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; + conformal_spatial_metric_der_raised1[k][i][j] += + inv_conformal_spatial_metric[k][l] * conformal_spatial_metric_der[l][i][j]; } } } @@ -1435,7 +1736,8 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi conformal_spatial_metric_der_raised3[i][j][k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_spatial_metric_der_raised3[i][j][k] += inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; + conformal_spatial_metric_der_raised3[i][j][k] += + inv_conformal_spatial_metric[l][k] * conformal_spatial_metric_der[i][j][l]; } } } @@ -1449,7 +1751,9 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_spatial_metric_der_lowered1[i][j][k] += inv_conformal_spatial_metric[j][l] * inv_conformal_spatial_metric[m][k] * conformal_spatial_metric_der[i][l][m]; + conformal_spatial_metric_der_lowered1[i][j][k] += + inv_conformal_spatial_metric[j][l] * inv_conformal_spatial_metric[m][k] * + conformal_spatial_metric_der[i][l][m]; } } } @@ -1464,7 +1768,9 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { - conformal_spatial_metric_der_lowered3[i][j][k] += inv_conformal_spatial_metric[i][l] * inv_conformal_spatial_metric[m][j] * conformal_spatial_metric_der[l][m][k]; + conformal_spatial_metric_der_lowered3[i][j][k] += + inv_conformal_spatial_metric[i][l] * inv_conformal_spatial_metric[m][j] * + conformal_spatial_metric_der[l][m][k]; } } } @@ -1474,7 +1780,7 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi double conformal_aux_vect_raised[3]; for (int k = 0; k < 3; k++) { conformal_aux_vect_raised[k] = 0.0; - + for (int l = 0; l < 3; l++) { conformal_aux_vect_raised[k] += inv_conformal_spatial_metric[k][l] * conformal_aux_vect[l]; } @@ -1487,9 +1793,12 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi conformal_spatial_christoffel[i][k][l] = 0.0; for (int m = 0; m < 3; m++) { - conformal_spatial_christoffel[i][k][l] += inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[l][m][k]; - conformal_spatial_christoffel[i][k][l] += inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[k][m][l]; - conformal_spatial_christoffel[i][k][l] -= inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[m][k][l]; + conformal_spatial_christoffel[i][k][l] += + inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[l][m][k]; + conformal_spatial_christoffel[i][k][l] += + inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[k][m][l]; + conformal_spatial_christoffel[i][k][l] -= + inv_conformal_spatial_metric[i][m] * conformal_spatial_metric_der[m][k][l]; } } } @@ -1500,7 +1809,8 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi conformal_lapse_der_raised[k] = 0.0; for (int l = 0; l < 3; l++) { - conformal_lapse_der_raised[k] += inv_conformal_spatial_metric[k][l] * conformal_lapse_der[l]; + conformal_lapse_der_raised[k] += + inv_conformal_spatial_metric[k][l] * conformal_lapse_der[l]; } } @@ -1519,7 +1829,8 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi Y_tensor[i][j] = 2.0 * conformal_fact_der2[i][j]; for (int k = 0; k < 3; k++) { - Y_tensor[i][j] += 2.0 * conformal_spatial_metric[i][j] * conformal_fact_der_raised[k] * conformal_fact_der[k]; + Y_tensor[i][j] += 2.0 * conformal_spatial_metric[i][j] * conformal_fact_der_raised[k] * + conformal_fact_der[k]; } for (int r = 0; r < 3; r++) { @@ -1543,12 +1854,18 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi double conformal_spatial_metric_source[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - conformal_spatial_metric_source[i][j] = -2.0 * conformal_lapse * (conformal_extrinsic_curvature[i][j] / (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); - conformal_spatial_metric_source[i][j] += 2.0 * conformal_lapse * conformal_symmetrized_shift[i][j]; + conformal_spatial_metric_source[i][j] = + -2.0 * conformal_lapse * + (conformal_extrinsic_curvature[i][j] / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact)); + conformal_spatial_metric_source[i][j] += + 2.0 * conformal_lapse * conformal_symmetrized_shift[i][j]; for (int r = 0; r < 3; r++) { - conformal_spatial_metric_source[i][j] += 2.0 * conformal_shift_vect[r] * conformal_spatial_metric_der[r][i][j]; - conformal_spatial_metric_source[i][j] += 4.0 * conformal_shift_vect[r] * conformal_fact_der[r] * conformal_spatial_metric[i][j]; + conformal_spatial_metric_source[i][j] += + 2.0 * conformal_shift_vect[r] * conformal_spatial_metric_der[r][i][j]; + conformal_spatial_metric_source[i][j] += + 4.0 * conformal_shift_vect[r] * conformal_fact_der[r] * conformal_spatial_metric[i][j]; } } } @@ -1564,64 +1881,103 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi conformal_extrinsic_curvature_source[i][j] = 0.0; for (int r = 0; r < 3; r++) { - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_extrinsic_curvature[i][r] * conformal_shift_vect_der[j][r]; - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_extrinsic_curvature[j][r] * conformal_shift_vect_der[i][r]; - conformal_extrinsic_curvature_source[i][j] -= 2.0 * conformal_extrinsic_curvature[i][j] * conformal_shift_vect_der[r][r]; + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_extrinsic_curvature[i][r] * conformal_shift_vect_der[j][r]; + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_extrinsic_curvature[j][r] * conformal_shift_vect_der[i][r]; + conformal_extrinsic_curvature_source[i][j] -= + 2.0 * conformal_extrinsic_curvature[i][j] * conformal_shift_vect_der[r][r]; } for (int k = 0; k < 3; k++) { - conformal_extrinsic_curvature_source[i][j] -= (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[i][k] * conformal_extrinsic_curvature[k][j]) / + conformal_extrinsic_curvature_source[i][j] -= + (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[i][k] * + conformal_extrinsic_curvature[k][j]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_extrinsic_curvature_source[i][j] += (conformal_lapse * conformal_extrinsic_curvature_trace * conformal_extrinsic_curvature[i][j]) / + conformal_extrinsic_curvature_source[i][j] += + (conformal_lapse * conformal_extrinsic_curvature_trace * + conformal_extrinsic_curvature[i][j]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); for (int r = 0; r < 3; r++) { - conformal_extrinsic_curvature_source[i][j] -= conformal_lapse * conformal_spatial_christoffel[k][r][i] * conformal_spatial_christoffel[r][k][j]; - - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_lapse * conformal_spatial_metric_der_raised3[i][k][r] * conformal_spatial_metric_der_raised3[r][j][k]; - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_lapse * conformal_spatial_metric_der_raised3[j][k][r] * conformal_spatial_metric_der_raised3[r][i][k]; - conformal_extrinsic_curvature_source[i][j] += conformal_lapse * conformal_spatial_christoffel[k][k][r] * conformal_spatial_christoffel[r][i][j]; - - conformal_extrinsic_curvature_source[i][j] -= conformal_lapse * (2.0 * conformal_spatial_metric_der_raised3[k][r][k] - conformal_lapse_der[r]) * - (conformal_spatial_metric_der_raised3[i][j][r] + conformal_spatial_metric_der_raised3[j][i][r]); + conformal_extrinsic_curvature_source[i][j] -= conformal_lapse * + conformal_spatial_christoffel[k][r][i] * + conformal_spatial_christoffel[r][k][j]; + + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_lapse * conformal_spatial_metric_der_raised3[i][k][r] * + conformal_spatial_metric_der_raised3[r][j][k]; + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_lapse * conformal_spatial_metric_der_raised3[j][k][r] * + conformal_spatial_metric_der_raised3[r][i][k]; + conformal_extrinsic_curvature_source[i][j] += conformal_lapse * + conformal_spatial_christoffel[k][k][r] * + conformal_spatial_christoffel[r][i][j]; + + conformal_extrinsic_curvature_source[i][j] -= + conformal_lapse * + (2.0 * conformal_spatial_metric_der_raised3[k][r][k] - conformal_lapse_der[r]) * + (conformal_spatial_metric_der_raised3[i][j][r] + + conformal_spatial_metric_der_raised3[j][i][r]); } - conformal_extrinsic_curvature_source[i][j] += conformal_lapse * conformal_lapse_der[i] * (conformal_aux_vect[j] - (0.5 * conformal_spatial_metric_der_raised3[j][k][k])); - conformal_extrinsic_curvature_source[i][j] += conformal_lapse * conformal_lapse_der[j] * (conformal_aux_vect[i] - (0.5 * conformal_spatial_metric_der_raised3[i][k][k])); + conformal_extrinsic_curvature_source[i][j] += + conformal_lapse * conformal_lapse_der[i] * + (conformal_aux_vect[j] - (0.5 * conformal_spatial_metric_der_raised3[j][k][k])); + conformal_extrinsic_curvature_source[i][j] += + conformal_lapse * conformal_lapse_der[j] * + (conformal_aux_vect[i] - (0.5 * conformal_spatial_metric_der_raised3[i][k][k])); - conformal_extrinsic_curvature_source[i][j] -= conformal_lapse * evolution_func * conformal_aux_vect_raised[k] * conformal_spatial_metric_der[k][i][j]; + conformal_extrinsic_curvature_source[i][j] -= conformal_lapse * evolution_func * + conformal_aux_vect_raised[k] * + conformal_spatial_metric_der[k][i][j]; } for (int k = 0; k < 3; k++) { for (int r = 0; r < 3; r++) { for (int s = 0; s < 3; s++) { - conformal_extrinsic_curvature_source[i][j] -= (0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * - conformal_spatial_metric_der_lowered1[k][r][s] * conformal_spatial_christoffel[k][r][s]; - conformal_extrinsic_curvature_source[i][j] += (0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * - conformal_spatial_metric_der_raised3[k][r][r] * conformal_spatial_metric_der_lowered3[k][s][s]; + conformal_extrinsic_curvature_source[i][j] -= + (0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * + conformal_spatial_metric_der_lowered1[k][r][s] * + conformal_spatial_christoffel[k][r][s]; + conformal_extrinsic_curvature_source[i][j] += + (0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * + conformal_spatial_metric_der_raised3[k][r][r] * + conformal_spatial_metric_der_lowered3[k][s][s]; } } - conformal_extrinsic_curvature_source[i][j] -= (0.5 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * conformal_aux_vect_raised[k] * conformal_lapse_der[k]; + conformal_extrinsic_curvature_source[i][j] -= + (0.5 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * + conformal_aux_vect_raised[k] * conformal_lapse_der[k]; } for (int r = 0; r < 3; r++) { for (int s = 0; s < 3; s++) { - conformal_extrinsic_curvature_source[i][j] += ((0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * - conformal_extrinsic_curvature_raised[r][s] * conformal_extrinsic_curvature[r][s]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_extrinsic_curvature_source[i][j] += + ((0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * + conformal_extrinsic_curvature_raised[r][s] * conformal_extrinsic_curvature[r][s]) / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); } } - conformal_extrinsic_curvature_source[i][j] -= ((0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * - (conformal_extrinsic_curvature_trace * conformal_extrinsic_curvature_trace)) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); + conformal_extrinsic_curvature_source[i][j] -= + ((0.25 * evolution_func * conformal_lapse * conformal_spatial_metric[i][j]) * + (conformal_extrinsic_curvature_trace * conformal_extrinsic_curvature_trace)) / + (conformal_fact * conformal_fact * conformal_fact * conformal_fact); conformal_extrinsic_curvature_source[i][j] -= Y_tensor[i][j]; - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_lapse_der[i] * conformal_fact_der[j]; - conformal_extrinsic_curvature_source[i][j] += 2.0 * conformal_lapse_der[j] * conformal_fact_der[i]; - + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_lapse_der[i] * conformal_fact_der[j]; + conformal_extrinsic_curvature_source[i][j] += + 2.0 * conformal_lapse_der[j] * conformal_fact_der[i]; + for (int k = 0; k < 3; k++) { - conformal_extrinsic_curvature_source[i][j] += conformal_spatial_metric[i][j] * (evolution_func - 1.0) * Y_tensor_mixed[k][k]; - conformal_extrinsic_curvature_source[i][j] -= 2.0 * conformal_spatial_metric[i][j] * conformal_lapse_der_raised[k] * conformal_fact_der[k]; + conformal_extrinsic_curvature_source[i][j] += + conformal_spatial_metric[i][j] * (evolution_func - 1.0) * Y_tensor_mixed[k][k]; + conformal_extrinsic_curvature_source[i][j] -= 2.0 * conformal_spatial_metric[i][j] * + conformal_lapse_der_raised[k] * + conformal_fact_der[k]; } } } @@ -1631,67 +1987,101 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi conformal_aux_vect_source[i] = 0.0; for (int r = 0; r < 3; r++) { - conformal_aux_vect_source[i] += (conformal_lapse * conformal_lapse_der[r] * conformal_extrinsic_curvature_mixed[i][r]) / + conformal_aux_vect_source[i] += + (conformal_lapse * conformal_lapse_der[r] * conformal_extrinsic_curvature_mixed[i][r]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - + if (i == r) { - conformal_aux_vect_source[i] -= (conformal_lapse * conformal_lapse_der[r] * conformal_extrinsic_curvature_trace) / + conformal_aux_vect_source[i] -= + (conformal_lapse * conformal_lapse_der[r] * conformal_extrinsic_curvature_trace) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); } for (int s = 0; s < 3; s++) { - conformal_aux_vect_source[i] += (conformal_lapse * conformal_extrinsic_curvature_mixed[s][r] * conformal_spatial_metric_der_raised3[i][r][s]) / + conformal_aux_vect_source[i] += + (conformal_lapse * conformal_extrinsic_curvature_mixed[s][r] * + conformal_spatial_metric_der_raised3[i][r][s]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_aux_vect_source[i] -= (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[s][r] * conformal_spatial_metric_der_raised3[r][i][s]) / + conformal_aux_vect_source[i] -= + (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[s][r] * + conformal_spatial_metric_der_raised3[r][i][s]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_aux_vect_source[i] -= (conformal_lapse * conformal_extrinsic_curvature_mixed[i][r] * conformal_spatial_metric_der_raised3[r][s][s]) / + conformal_aux_vect_source[i] -= + (conformal_lapse * conformal_extrinsic_curvature_mixed[i][r] * + conformal_spatial_metric_der_raised3[r][s][s]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_aux_vect_source[i] += (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[i][r] * conformal_spatial_metric_der_raised3[s][r][s]) / + conformal_aux_vect_source[i] += + (2.0 * conformal_lapse * conformal_extrinsic_curvature_mixed[i][r] * + conformal_spatial_metric_der_raised3[s][r][s]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); - conformal_aux_vect_source[i] -= (6.0 * conformal_lapse * conformal_fact_der[r] * conformal_extrinsic_curvature_mixed[s][r]) / + conformal_aux_vect_source[i] -= + (6.0 * conformal_lapse * conformal_fact_der[r] * + conformal_extrinsic_curvature_mixed[s][r]) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); if (s == r) { - conformal_aux_vect_source[i] += (2.0 * conformal_lapse * conformal_fact_der[r] * conformal_extrinsic_curvature_trace) / + conformal_aux_vect_source[i] += + (2.0 * conformal_lapse * conformal_fact_der[r] * conformal_extrinsic_curvature_trace + ) / (conformal_fact * conformal_fact * conformal_fact * conformal_fact); } } - conformal_aux_vect_source[i] += 2.0 * conformal_shift_vect_der[i][r] * conformal_aux_vect[r]; + conformal_aux_vect_source[i] += + 2.0 * conformal_shift_vect_der[i][r] * conformal_aux_vect[r]; if (i == r) { - conformal_aux_vect_source[i] -= 2.0 * conformal_shift_vect_der_trace * conformal_aux_vect[r]; + conformal_aux_vect_source[i] -= + 2.0 * conformal_shift_vect_der_trace * conformal_aux_vect[r]; } for (int s = 0; s < 3; s++) { - conformal_aux_vect_source[i] += 2.0 * conformal_spatial_metric_der_raised3[r][i][s] * conformal_shift_vect_der_switched[r][s]; + conformal_aux_vect_source[i] += 2.0 * conformal_spatial_metric_der_raised3[r][i][s] * + conformal_shift_vect_der_switched[r][s]; if (i == s) { for (int j = 0; j < 3; j++) { - conformal_aux_vect_source[i] -= 2.0 * conformal_spatial_metric_der_raised1[j][j][r] * conformal_shift_vect_der_switched[r][s]; + conformal_aux_vect_source[i] -= 2.0 * conformal_spatial_metric_der_raised1[j][j][r] * + conformal_shift_vect_der_switched[r][s]; } } } - conformal_aux_vect_source[i] += 4.0 * conformal_shift_vect_der[i][r] * conformal_fact_der[r]; - conformal_aux_vect_source[i] -= 4.0 * conformal_shift_vect_der_trace * conformal_fact_der[i]; + conformal_aux_vect_source[i] += + 4.0 * conformal_shift_vect_der[i][r] * conformal_fact_der[r]; + conformal_aux_vect_source[i] -= + 4.0 * conformal_shift_vect_der_trace * conformal_fact_der[i]; } } - double bssn_conformal_fact_source = (1.0 / 3.0) * conformal_lapse * conformal_extrinsic_curvature_trace * bssn_conformal_fact; - bssn_conformal_fact_source -= (8.0 / 3.0) * conformal_shift_vect_der_trace * bssn_conformal_fact; + double bssn_conformal_fact_source = + (1.0 / 3.0) * conformal_lapse * conformal_extrinsic_curvature_trace * bssn_conformal_fact; + bssn_conformal_fact_source -= + (8.0 / 3.0) * conformal_shift_vect_der_trace * bssn_conformal_fact; - sout[0] = conformal_spatial_metric_source[0][0]; sout[1] = conformal_spatial_metric_source[0][1]; sout[2] = conformal_spatial_metric_source[0][2]; - sout[3] = conformal_spatial_metric_source[1][0]; sout[4] = conformal_spatial_metric_source[1][1]; sout[5] = conformal_spatial_metric_source[1][2]; - sout[6] = conformal_spatial_metric_source[2][0]; sout[7] = conformal_spatial_metric_source[2][1]; sout[8] = conformal_spatial_metric_source[2][2]; + sout[0] = conformal_spatial_metric_source[0][0]; + sout[1] = conformal_spatial_metric_source[0][1]; + sout[2] = conformal_spatial_metric_source[0][2]; + sout[3] = conformal_spatial_metric_source[1][0]; + sout[4] = conformal_spatial_metric_source[1][1]; + sout[5] = conformal_spatial_metric_source[1][2]; + sout[6] = conformal_spatial_metric_source[2][0]; + sout[7] = conformal_spatial_metric_source[2][1]; + sout[8] = conformal_spatial_metric_source[2][2]; sout[9] = conformal_lapse_source; - sout[10] = conformal_extrinsic_curvature_source[0][0]; sout[11] = conformal_extrinsic_curvature_source[0][1]; sout[12] = conformal_extrinsic_curvature_source[0][2]; - sout[13] = conformal_extrinsic_curvature_source[1][0]; sout[14] = conformal_extrinsic_curvature_source[1][1]; sout[15] = conformal_extrinsic_curvature_source[1][2]; - sout[16] = conformal_extrinsic_curvature_source[2][0]; sout[17] = conformal_extrinsic_curvature_source[2][1]; sout[18] = conformal_extrinsic_curvature_source[2][2]; + sout[10] = conformal_extrinsic_curvature_source[0][0]; + sout[11] = conformal_extrinsic_curvature_source[0][1]; + sout[12] = conformal_extrinsic_curvature_source[0][2]; + sout[13] = conformal_extrinsic_curvature_source[1][0]; + sout[14] = conformal_extrinsic_curvature_source[1][1]; + sout[15] = conformal_extrinsic_curvature_source[1][2]; + sout[16] = conformal_extrinsic_curvature_source[2][0]; + sout[17] = conformal_extrinsic_curvature_source[2][1]; + sout[18] = conformal_extrinsic_curvature_source[2][2]; for (int i = 19; i < 49; i++) { sout[i] = 0.0; @@ -1709,46 +2099,47 @@ vacuum_einstein_conformal_source(const struct gkyl_wv_eqn* eqn, const double* qi gkyl_free(inv_conformal_spatial_metric[i]); } gkyl_free(inv_conformal_spatial_metric); - } - else { + } else { for (int i = 0; i < 77; i++) { sout[i] = 0.0; } } } -void -gkyl_vacuum_einstein_conformal_free(const struct gkyl_ref_count* ref) +void gkyl_vacuum_einstein_conformal_free(const struct gkyl_ref_count *ref) { - struct gkyl_wv_eqn* base = container_of(ref, struct gkyl_wv_eqn, ref_count); + struct gkyl_wv_eqn *base = container_of(ref, struct gkyl_wv_eqn, ref_count); if (gkyl_wv_eqn_is_cu_dev(base)) { // Free inner on_dev object. - struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = container_of(base->on_dev, struct wv_vacuum_einstein_conformal, eqn); + struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = + container_of(base->on_dev, struct wv_vacuum_einstein_conformal, eqn); gkyl_cu_free(vacuum_einstein_conformal); } - struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = container_of(base, struct wv_vacuum_einstein_conformal, eqn); + struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = + container_of(base, struct wv_vacuum_einstein_conformal, eqn); gkyl_free(vacuum_einstein_conformal); } -struct gkyl_wv_eqn* -gkyl_wv_vacuum_einstein_conformal_new(double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, enum gkyl_spacetime_evolution spacetime_evolution, bool use_gpu) +struct gkyl_wv_eqn *gkyl_wv_vacuum_einstein_conformal_new( + double excision_threshold, enum gkyl_spacetime_slicing spacetime_slicing, + enum gkyl_spacetime_evolution spacetime_evolution, bool use_gpu +) { - return gkyl_wv_vacuum_einstein_conformal_inew(&(struct gkyl_wv_vacuum_einstein_conformal_inp) { - .excision_threshold = excision_threshold, - .spacetime_slicing = spacetime_slicing, - .spacetime_evolution = spacetime_evolution, - .rp_type = WV_VACUUM_EINSTEIN_CONFORMAL_RP_HLL, - .use_gpu = use_gpu, - } - ); + return gkyl_wv_vacuum_einstein_conformal_inew(&(struct gkyl_wv_vacuum_einstein_conformal_inp + ){.excision_threshold = excision_threshold, + .spacetime_slicing = spacetime_slicing, + .spacetime_evolution = spacetime_evolution, + .rp_type = WV_VACUUM_EINSTEIN_CONFORMAL_RP_HLL, + .use_gpu = use_gpu}); } -struct gkyl_wv_eqn* -gkyl_wv_vacuum_einstein_conformal_inew(const struct gkyl_wv_vacuum_einstein_conformal_inp* inp) +struct gkyl_wv_eqn * +gkyl_wv_vacuum_einstein_conformal_inew(const struct gkyl_wv_vacuum_einstein_conformal_inp *inp) { - struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = gkyl_malloc(sizeof(struct wv_vacuum_einstein_conformal)); + struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = + gkyl_malloc(sizeof(struct wv_vacuum_einstein_conformal)); vacuum_einstein_conformal->eqn.type = GKYL_EQN_VACUUM_EINSTEIN_CONFORMAL; vacuum_einstein_conformal->eqn.num_equations = 77; @@ -1762,13 +2153,12 @@ gkyl_wv_vacuum_einstein_conformal_inew(const struct gkyl_wv_vacuum_einstein_conf vacuum_einstein_conformal->eqn.num_waves = 2; vacuum_einstein_conformal->eqn.waves_func = wave_lax_l; vacuum_einstein_conformal->eqn.qfluct_func = qfluct_lax_l; - } - else if (inp->rp_type == WV_VACUUM_EINSTEIN_CONFORMAL_RP_HLL) { + } else if (inp->rp_type == WV_VACUUM_EINSTEIN_CONFORMAL_RP_HLL) { vacuum_einstein_conformal->eqn.num_waves = 2; vacuum_einstein_conformal->eqn.waves_func = wave_hll_l; vacuum_einstein_conformal->eqn.qfluct_func = qfluct_hll_l; } - + vacuum_einstein_conformal->eqn.flux_jump = flux_jump; vacuum_einstein_conformal->eqn.check_inv_func = check_inv; vacuum_einstein_conformal->eqn.max_speed_func = max_speed; @@ -1786,35 +2176,40 @@ gkyl_wv_vacuum_einstein_conformal_inew(const struct gkyl_wv_vacuum_einstein_conf vacuum_einstein_conformal->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(vacuum_einstein_conformal->eqn.flags); - vacuum_einstein_conformal->eqn.ref_count = gkyl_ref_count_init(gkyl_vacuum_einstein_conformal_free); - vacuum_einstein_conformal->eqn.on_dev = &vacuum_einstein_conformal->eqn; // On the CPU, the equation object points to itself. + vacuum_einstein_conformal->eqn.ref_count = + gkyl_ref_count_init(gkyl_vacuum_einstein_conformal_free); + vacuum_einstein_conformal->eqn.on_dev = + &vacuum_einstein_conformal->eqn; // On the CPU, the equation object points to itself. return &vacuum_einstein_conformal->eqn; } -double -gkyl_wv_vacuum_einstein_conformal_excision_threshold(const struct gkyl_wv_eqn* eqn) +double gkyl_wv_vacuum_einstein_conformal_excision_threshold(const struct gkyl_wv_eqn *eqn) { - const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); + const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = + container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); double excision_threshold = vacuum_einstein_conformal->excision_threshold; return excision_threshold; } enum gkyl_spacetime_slicing -gkyl_wv_vacuum_einstein_conformal_spacetime_slicing(const struct gkyl_wv_eqn* eqn) +gkyl_wv_vacuum_einstein_conformal_spacetime_slicing(const struct gkyl_wv_eqn *eqn) { - const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); + const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = + container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); enum gkyl_spacetime_slicing spacetime_slicing = vacuum_einstein_conformal->spacetime_slicing; return spacetime_slicing; } enum gkyl_spacetime_evolution -gkyl_wv_vacuum_einstein_conformal_spacetime_evolution(const struct gkyl_wv_eqn* eqn) +gkyl_wv_vacuum_einstein_conformal_spacetime_evolution(const struct gkyl_wv_eqn *eqn) { - const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); - enum gkyl_spacetime_evolution spacetime_evolution = vacuum_einstein_conformal->spacetime_evolution; + const struct wv_vacuum_einstein_conformal *vacuum_einstein_conformal = + container_of(eqn, struct wv_vacuum_einstein_conformal, eqn); + enum gkyl_spacetime_evolution spacetime_evolution = + vacuum_einstein_conformal->spacetime_evolution; return spacetime_evolution; } \ No newline at end of file diff --git a/pkpm/apps/gkyl_pkpm.h b/pkpm/apps/gkyl_pkpm.h index f44ce10875..79cf84cc14 100644 --- a/pkpm/apps/gkyl_pkpm.h +++ b/pkpm/apps/gkyl_pkpm.h @@ -21,7 +21,7 @@ struct gkyl_pkpm_collisions { // inputs for Spitzer collisionality bool normNu; // Set to true if you want to rescale collision frequency double nuFrac; // Parameter for rescaling collision frequency from SI values - double hbar; // Planck's constant/2 pi + double hbar; // Planck's constant/2 pi int num_cross_collisions; // number of species to cross-collide with char collide_with[GKYL_MAX_SPECIES][128]; // names of species to cross collide with @@ -31,17 +31,17 @@ struct gkyl_pkpm_collisions { struct gkyl_pkpm_fluid_diffusion { double D; // constant diffusion coefficient int order; // integer for order of the diffusion (4 for grad^4, 6 for grad^6, default is grad^2) - void* Dij_ctx; // context for applied diffusion function if using general diffusion tensor - // pointer to applied diffusion function is using general diffusion tensor - void (*Dij)(double t, const double* xn, double* Dout, void* ctx); + void *Dij_ctx; // context for applied diffusion function if using general diffusion tensor + // pointer to applied diffusion function is using general diffusion tensor + void (*Dij)(double t, const double *xn, double *Dout, void *ctx); }; // Parameters for PKPM species struct gkyl_pkpm_species { char name[128]; // species name - enum gkyl_model_id model_id; // type of model - // (e.g., SR, general geometry, PKPM, see gkyl_eqn_type.h) + enum gkyl_model_id model_id; // type of model + // (e.g., SR, general geometry, PKPM, see gkyl_eqn_type.h) double charge, mass; // charge and mass double lower[3], upper[3]; // lower, upper bounds of velocity-space @@ -51,7 +51,7 @@ struct gkyl_pkpm_species { void *ctx_fluid; // context for initial condition init function // pointer to initialization distribution function void (*init_dist)(double t, const double *xn, double *fout, void *ctx); - // pointer to initialization momentum + // pointer to initialization momentum void (*init_fluid)(double t, const double *xn, double *fout, void *ctx); // collisions to include @@ -74,8 +74,8 @@ struct gkyl_pkpm_species { // Parameter for EM field struct gkyl_pkpm_field { - enum gkyl_field_id field_id; // type of field - // (e.g., Maxwell's, Poisson, see gkyl_eqn_type.h) + enum gkyl_field_id field_id; // type of field + // (e.g., Maxwell's, Poisson, see gkyl_eqn_type.h) bool is_static; // set to true if field does not change in time double epsilon0, mu0; @@ -94,10 +94,10 @@ struct gkyl_pkpm_field { // pointer to external electromagnetic fields function void (*app_current)(double t, const double *xn, double *app_current_out, void *ctx); bool app_current_evolve; // set to true if applied current function is time dependent - + double limiter_fac; // Optional input parameter for adjusting diffusion in slope limiter bool limit_em; // Optional input parameter for applying limiters to EM fields - + // boundary conditions enum gkyl_field_bc_type bcx[2], bcy[2], bcz[2]; }; @@ -125,12 +125,12 @@ struct gkyl_pkpm { int num_species; // number of species struct gkyl_pkpm_species species[GKYL_MAX_SPECIES]; // species objects - + struct gkyl_pkpm_field field; // field object - bool use_explicit_source; // Use fully explicit SSP RK3 scheme - // Default is a first-order operator split with - // implicit fluid-EM coupling. + bool use_explicit_source; // Use fully explicit SSP RK3 scheme + // Default is a first-order operator split with + // implicit fluid-EM coupling. struct gkyl_app_parallelism_inp parallelism; // Parallelism-related inputs. }; @@ -138,16 +138,16 @@ struct gkyl_pkpm { // Simulation statistics struct gkyl_pkpm_stat { bool use_gpu; // did this sim use GPU? - + long nup; // calls to update long nfeuler; // calls to forward-Euler method - + long nstage_2_fail; // number of failed RK stage-2s long nstage_3_fail; // number of failed RK stage-3s double stage_2_dt_diff[2]; // [min,max] rel-diff for stage-2 failure double stage_3_dt_diff[2]; // [min,max] rel-diff for stage-3 failure - + double total_tm; // time for simulation (not including ICs) double rk3_tm; // time for SSP RK3 step double pkpm_em_tm; // time for implicit fluid-EM coupling step @@ -157,22 +157,22 @@ struct gkyl_pkpm_stat { double species_rhs_tm; // time to compute species collisionless RHS double fluid_species_rhs_tm; // time to compute fluid species RHS - + double species_coll_mom_tm; // time needed to compute various moments needed in LBO double species_lbo_coll_drag_tm[GKYL_MAX_SPECIES]; // time to compute LBO drag terms double species_lbo_coll_diff_tm[GKYL_MAX_SPECIES]; // time to compute LBO diffusion terms double species_coll_tm; // total time for collision updater (excluded moments) double species_pkpm_vars_tm; // time to compute pkpm vars - // These are the coupling moments [rho, p_par, p_perp], the self-consistent - // pressure force (div(p_par b_hat)), and the primitive variables - // along with the acceleration variables in the kinetic equation - // and the source distribution functions for Laguerre couplings. + // These are the coupling moments [rho, p_par, p_perp], the self-consistent + // pressure force (div(p_par b_hat)), and the primitive variables + // along with the acceleration variables in the kinetic equation + // and the source distribution functions for Laguerre couplings. double species_bc_tm; // time to compute species BCs double fluid_species_bc_tm; // time to compute fluid species BCs double field_bc_tm; // time to compute field - + double field_rhs_tm; // time to compute field RHS double field_em_vars_tm; // time to compute EM auxiliary variables (e.g., bvar and E x B) double current_tm; // time to compute currents and accumulation @@ -203,7 +203,7 @@ typedef struct gkyl_pkpm_app gkyl_pkpm_app; * initialized * @return New PKPM app object. */ -gkyl_pkpm_app* gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm); +gkyl_pkpm_app *gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm); /** * Initialize species and field by projecting initial conditions on @@ -212,7 +212,7 @@ gkyl_pkpm_app* gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm); * @param app App object. * @param t0 Time for initial conditions. */ -void gkyl_pkpm_app_apply_ic(gkyl_pkpm_app* app, double t0); +void gkyl_pkpm_app_apply_ic(gkyl_pkpm_app *app, double t0); /** * Initialize field by projecting initial conditions on basis @@ -221,7 +221,7 @@ void gkyl_pkpm_app_apply_ic(gkyl_pkpm_app* app, double t0); * @param app App object. * @param t0 Time for initial conditions */ -void gkyl_pkpm_app_apply_ic_field(gkyl_pkpm_app* app, double t0); +void gkyl_pkpm_app_apply_ic_field(gkyl_pkpm_app *app, double t0); /** * Initialize species by projecting initial conditions on basis @@ -232,7 +232,7 @@ void gkyl_pkpm_app_apply_ic_field(gkyl_pkpm_app* app, double t0); * @param sidx Index of species to initialize. * @param t0 Time for initial conditions */ -void gkyl_pkpm_app_apply_ic_species(gkyl_pkpm_app* app, int sidx, double t0); +void gkyl_pkpm_app_apply_ic_species(gkyl_pkpm_app *app, int sidx, double t0); /** * Calculate integrated diagnostic moments. @@ -240,7 +240,7 @@ void gkyl_pkpm_app_apply_ic_species(gkyl_pkpm_app* app, int sidx, double t0); * @param tm Time at which integrated diagnostic are to be computed * @param app App object. */ -void gkyl_pkpm_app_calc_integrated_mom(gkyl_pkpm_app* app, double tm); +void gkyl_pkpm_app_calc_integrated_mom(gkyl_pkpm_app *app, double tm); /** * Calculate integrated L2 norm of the distribution function, f^2. @@ -248,7 +248,7 @@ void gkyl_pkpm_app_calc_integrated_mom(gkyl_pkpm_app* app, double tm); * @param tm Time at which integrated diagnostic are to be computed * @param app App object. */ -void gkyl_pkpm_app_calc_integrated_L2_f(gkyl_pkpm_app* app, double tm); +void gkyl_pkpm_app_calc_integrated_L2_f(gkyl_pkpm_app *app, double tm); /** * Calculate integrated field energy @@ -256,7 +256,7 @@ void gkyl_pkpm_app_calc_integrated_L2_f(gkyl_pkpm_app* app, double tm); * @param tm Time at which integrated diagnostic are to be computed * @param app App object. */ -void gkyl_pkpm_app_calc_field_energy(gkyl_pkpm_app* app, double tm); +void gkyl_pkpm_app_calc_field_energy(gkyl_pkpm_app *app, double tm); /** * Write field and species data to file. @@ -265,7 +265,7 @@ void gkyl_pkpm_app_calc_field_energy(gkyl_pkpm_app* app, double tm); * @param tm Time-stamp * @param frame Frame number */ -void gkyl_pkpm_app_write(gkyl_pkpm_app* app, double tm, int frame); +void gkyl_pkpm_app_write(gkyl_pkpm_app *app, double tm, int frame); /** * Write field data to file. @@ -274,7 +274,7 @@ void gkyl_pkpm_app_write(gkyl_pkpm_app* app, double tm, int frame); * @param tm Time-stamp * @param frame Frame number */ -void gkyl_pkpm_app_write_field(gkyl_pkpm_app* app, double tm, int frame); +void gkyl_pkpm_app_write_field(gkyl_pkpm_app *app, double tm, int frame); /** * Write species data to file. @@ -284,7 +284,7 @@ void gkyl_pkpm_app_write_field(gkyl_pkpm_app* app, double tm, int frame); * @param tm Time-stamp * @param frame Frame number */ -void gkyl_pkpm_app_write_species(gkyl_pkpm_app* app, int sidx, double tm, int frame); +void gkyl_pkpm_app_write_species(gkyl_pkpm_app *app, int sidx, double tm, int frame); /** * Write pkpm auxiliar data to files. Includes: @@ -301,7 +301,7 @@ void gkyl_pkpm_app_write_species(gkyl_pkpm_app* app, int sidx, double tm, int fr * @param tm Time-stamp * @param frame Frame number */ -void gkyl_pkpm_app_write_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame); +void gkyl_pkpm_app_write_mom(gkyl_pkpm_app *app, int sidx, double tm, int frame); /** * Write integrated diagnostic moments for species to file. Integrated @@ -325,14 +325,14 @@ void gkyl_pkpm_app_write_integrated_L2_f(gkyl_pkpm_app *app); * * @param app App object. */ -void gkyl_pkpm_app_write_field_energy(gkyl_pkpm_app* app); +void gkyl_pkpm_app_write_field_energy(gkyl_pkpm_app *app); /** * Write stats to file. Data is written in json format. * * @param app App object. */ -void gkyl_pkpm_app_stat_write(gkyl_pkpm_app* app); +void gkyl_pkpm_app_stat_write(gkyl_pkpm_app *app); /** * Train neural network on PKPM moments data for each fluid species. @@ -348,11 +348,13 @@ void gkyl_pkpm_app_stat_write(gkyl_pkpm_app* app); * @param input_data Array of input data to train on (across the computational domain). * @param output_data Array of output data to train on (across the computational domain). */ -void -gkyl_pkpm_app_train(gkyl_pkpm_app* app, double tm, int frame, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data); +void gkyl_pkpm_app_train( + gkyl_pkpm_app *app, double tm, int frame, struct gkyl_kann_net **ann, int num_input_moms, + int *input_moms, int num_output_moms, int *output_moms, struct gkyl_kn_vec *input_data, + struct gkyl_kn_vec *output_data +); - /** +/** * Train neural network on PKPM moments data for a particular fluid species. * * @param app App object. @@ -367,9 +369,11 @@ gkyl_pkpm_app_train(gkyl_pkpm_app* app, double tm, int frame, struct gkyl_kann_n * @param input_data Array of input data to train on (across the computational domain). * @param output_data Array of output data to train on (across the computational domain). */ -void -gkyl_pkpm_app_train_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data); +void gkyl_pkpm_app_train_mom( + gkyl_pkpm_app *app, int sidx, double tm, int frame, struct gkyl_kann_net **ann, + int num_input_moms, int *input_moms, int num_output_moms, int *output_moms, + struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +); /** * Write out PKPM moments neural network for each fluid species. @@ -379,10 +383,9 @@ gkyl_pkpm_app_train_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, stru * @param frame Frame number. * @param ann Neural network architecture. */ -void -gkyl_pkpm_app_write_nn(gkyl_pkpm_app* app, double tm, int frame, struct gkyl_kann_net** ann); +void gkyl_pkpm_app_write_nn(gkyl_pkpm_app *app, double tm, int frame, struct gkyl_kann_net **ann); - /** +/** * Write out PKPM moments neural network for a particular fluid species. * * @param app App object. @@ -391,8 +394,9 @@ gkyl_pkpm_app_write_nn(gkyl_pkpm_app* app, double tm, int frame, struct gkyl_kan * @param frame Frame number. * @param ann Neural network architecture. */ -void -gkyl_pkpm_app_write_nn_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struct gkyl_kann_net** ann); +void gkyl_pkpm_app_write_nn_mom( + gkyl_pkpm_app *app, int sidx, double tm, int frame, struct gkyl_kann_net **ann +); /** * Test neural network on PKPM moments data for each fluid species, and write moments to a file. @@ -409,11 +413,13 @@ gkyl_pkpm_app_write_nn_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, s * @param output_data_real Array of real output data to validate against (across the computational domain). * @param output_data_predicted Array of predicted output data to validate (across the computational domain). */ -void -gkyl_pkpm_app_test(gkyl_pkpm_app* app, double tm, int frame, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted); +void gkyl_pkpm_app_test( + gkyl_pkpm_app *app, double tm, int frame, struct gkyl_kann_net **ann, int num_input_moms, + int *input_moms, int num_output_moms, int *output_moms, struct gkyl_kn_vec *input_data_real, + struct gkyl_kn_vec *output_data_real, struct gkyl_kn_vec *output_data_predicted +); - /** +/** * Test neural network on PKPM moments data for a particular fluid species, and write moments to a file. * * @param app App object. @@ -429,9 +435,12 @@ gkyl_pkpm_app_test(gkyl_pkpm_app* app, double tm, int frame, struct gkyl_kann_ne * @param output_data_real Array of real output data to validate against (across the computational domain). * @param output_data_predicted Array of predicted output data to validate (across the computational domain). */ -void -gkyl_pkpm_app_test_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted); +void gkyl_pkpm_app_test_mom( + gkyl_pkpm_app *app, int sidx, double tm, int frame, struct gkyl_kann_net **ann, + int num_input_moms, int *input_moms, int num_output_moms, int *output_moms, + struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +); /** * Initialize field from file @@ -439,8 +448,7 @@ gkyl_pkpm_app_test_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struc * @param app App object * @param fname file to read */ -struct gkyl_app_restart_status -gkyl_pkpm_app_from_file_field(gkyl_pkpm_app *app, const char *fname); +struct gkyl_app_restart_status gkyl_pkpm_app_from_file_field(gkyl_pkpm_app *app, const char *fname); /** * Initialize pkpm species from file @@ -449,9 +457,8 @@ gkyl_pkpm_app_from_file_field(gkyl_pkpm_app *app, const char *fname); * @param sidx gk species index * @param fname file to read */ -struct gkyl_app_restart_status -gkyl_pkpm_app_from_file_species(gkyl_pkpm_app *app, int sidx, - const char *fname); +struct gkyl_app_restart_status +gkyl_pkpm_app_from_file_species(gkyl_pkpm_app *app, int sidx, const char *fname); /** * Initialize pkpm fluid species from file @@ -460,9 +467,8 @@ gkyl_pkpm_app_from_file_species(gkyl_pkpm_app *app, int sidx, * @param sidx gk species index * @param fname file to read */ -struct gkyl_app_restart_status -gkyl_pkpm_app_from_file_fluid_species(gkyl_pkpm_app *app, int sidx, - const char *fname); +struct gkyl_app_restart_status +gkyl_pkpm_app_from_file_fluid_species(gkyl_pkpm_app *app, int sidx, const char *fname); /** * Initialize field from frame @@ -470,8 +476,7 @@ gkyl_pkpm_app_from_file_fluid_species(gkyl_pkpm_app *app, int sidx, * @param app App object * @param frame frame to read */ -struct gkyl_app_restart_status -gkyl_pkpm_app_from_frame_field(gkyl_pkpm_app *app, int frame); +struct gkyl_app_restart_status gkyl_pkpm_app_from_frame_field(gkyl_pkpm_app *app, int frame); /** * Initialize pkpm species and fluid species from frame @@ -489,8 +494,7 @@ gkyl_pkpm_app_from_frame_species(gkyl_pkpm_app *app, int sidx, int frame); * @param app App object * @param frame frame to read */ -struct gkyl_app_restart_status -gkyl_pkpm_app_read_from_frame(gkyl_pkpm_app *app, int frame); +struct gkyl_app_restart_status gkyl_pkpm_app_read_from_frame(gkyl_pkpm_app *app, int frame); /** * Write output to console: this is mainly for diagnostic messages the @@ -502,7 +506,7 @@ gkyl_pkpm_app_read_from_frame(gkyl_pkpm_app *app, int frame); * @param fmt Format string for console output * @param argp Objects to write */ -void gkyl_pkpm_app_cout(const gkyl_pkpm_app* app, FILE *fp, const char *fmt, ...); +void gkyl_pkpm_app_cout(const gkyl_pkpm_app *app, FILE *fp, const char *fmt, ...); /** * Advance simulation by a suggested time-step 'dt'. The dt may be too @@ -520,18 +524,18 @@ void gkyl_pkpm_app_cout(const gkyl_pkpm_app* app, FILE *fp, const char *fmt, ... * @param dt Suggested time-step to advance simulation * @return Status of update. */ -struct gkyl_update_status gkyl_pkpm_update(gkyl_pkpm_app* app, double dt); +struct gkyl_update_status gkyl_pkpm_update(gkyl_pkpm_app *app, double dt); /** * Return simulation statistics. * * @return Return statistics object. */ -struct gkyl_pkpm_stat gkyl_pkpm_app_stat(gkyl_pkpm_app* app); +struct gkyl_pkpm_stat gkyl_pkpm_app_stat(gkyl_pkpm_app *app); /** * Free PKPM app. * * @param app App to release. */ -void gkyl_pkpm_app_release(gkyl_pkpm_app* app); +void gkyl_pkpm_app_release(gkyl_pkpm_app *app); diff --git a/pkpm/apps/gkyl_pkpm_priv.h b/pkpm/apps/gkyl_pkpm_priv.h index 9f8c4abb0a..66e0316209 100644 --- a/pkpm/apps/gkyl_pkpm_priv.h +++ b/pkpm/apps/gkyl_pkpm_priv.h @@ -78,27 +78,32 @@ struct pkpm_species_moment { // forward declare species struct struct pkpm_species; -struct pkpm_lbo_collisions { +struct pkpm_lbo_collisions { struct gkyl_array *boundary_corrections; // LBO boundary corrections struct gkyl_mom_calc_bcorr *bcorr_calc; // LBO boundary corrections calculator struct gkyl_array *nu_sum, *prim_moms, *nu_prim_moms; // LBO primitive moments bool normNu; // Boolean to determine if using Spitzer value - struct gkyl_array *norm_nu; // Array for normalization factor computed from Spitzer updater n/sqrt(2 vt^2)^3 + struct gkyl_array + *norm_nu; // Array for normalization factor computed from Spitzer updater n/sqrt(2 vt^2)^3 struct gkyl_array *nu_init; // Array for initial collisionality when using Spitzer updater - struct gkyl_spitzer_coll_freq* spitzer_calc; // Updater for Spitzer collisionality if computing Spitzer value + struct gkyl_spitzer_coll_freq + *spitzer_calc; // Updater for Spitzer collisionality if computing Spitzer value struct gkyl_array *maxwellian_moms; // Maxwellian moments n, t, v_t^2. double betaGreenep1; // value of Greene's factor beta + 1 double other_m[GKYL_MAX_SPECIES]; // masses of species being collided with - struct gkyl_array *other_prim_moms[GKYL_MAX_SPECIES]; // self-primitive moments of species being collided with + struct gkyl_array + *other_prim_moms[GKYL_MAX_SPECIES]; // self-primitive moments of species being collided with struct gkyl_array *cross_prim_moms[GKYL_MAX_SPECIES]; // LBO cross-primitive moments struct gkyl_array *cross_nu[GKYL_MAX_SPECIES]; // LBO cross-species collision frequencies struct gkyl_array *other_nu[GKYL_MAX_SPECIES]; - struct gkyl_array *cross_nu_prim_moms; // weak multiplication of collision frequency and primitive moments - + struct gkyl_array + *cross_nu_prim_moms; // weak multiplication of collision frequency and primitive moments + struct gkyl_array *self_nu, *self_nu_prim_moms; // LBO self-primitive moments - struct pkpm_species_moment moms; // moments needed in LBO (single array includes Zeroth, First, and Second moment) + struct pkpm_species_moment + moms; // moments needed in LBO (single array includes Zeroth, First, and Second moment) struct gkyl_array *m0; struct gkyl_array *self_mnu_m0[GKYL_MAX_SPECIES], *self_mnu[GKYL_MAX_SPECIES]; struct gkyl_array *other_mnu_m0[GKYL_MAX_SPECIES], *other_mnu[GKYL_MAX_SPECIES]; @@ -117,13 +122,13 @@ struct pkpm_lbo_collisions { // species data struct pkpm_species { struct gkyl_pkpm_species info; // data for species - + struct gkyl_job_pool *job_pool; // Job pool struct gkyl_rect_grid grid; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges - struct gkyl_range global, global_ext; // global, global-ext conf-space ranges + struct gkyl_range global, global_ext; // global, global-ext conf-space ranges - struct gkyl_comm *comm; // communicator object for phase-space arrays + struct gkyl_comm *comm; // communicator object for phase-space arrays int nghost[GKYL_MAX_DIM]; // number of ghost-cells in each direction struct gkyl_rect_grid grid_vel; // velocity space grid @@ -136,67 +141,78 @@ struct pkpm_species { struct gkyl_array *cflrate_fluid; // CFL rate in each cell for momentum update struct gkyl_array *bc_buffer_dist; // buffer for BCs for distribution functions (used by bc_basic) - struct gkyl_array *bc_buffer_lo_fixed_dist, *bc_buffer_up_fixed_dist; // fixed buffers for time independent BCs for distribution functions + struct gkyl_array *bc_buffer_lo_fixed_dist, + *bc_buffer_up_fixed_dist; // fixed buffers for time independent BCs for distribution functions struct gkyl_array *bc_buffer_fluid; // buffer for BCs for momentum (used by bc_basic) - struct gkyl_array *bc_buffer_lo_fixed_fluid, *bc_buffer_up_fixed_fluid; // fixed buffers for time independent BCs for momentum + struct gkyl_array *bc_buffer_lo_fixed_fluid, + *bc_buffer_up_fixed_fluid; // fixed buffers for time independent BCs for momentum struct gkyl_array *f_host; // host copy of distribution function for use IO and initialization struct gkyl_array *fluid_host; // host copy of momentum for use IO and initialization // Duplicate copy of fluid data in case time step fails. - // Needed because of implicit source split which modifies solution and - // is always successful, so if a time step fails due to the SSP RK3 + // Needed because of implicit source split which modifies solution and + // is always successful, so if a time step fails due to the SSP RK3 // we must restore the old solution before restarting the time step - struct gkyl_array *fluid_dup; + struct gkyl_array *fluid_dup; - struct gkyl_wv_eqn *equation; // For storing 10 moment equation object for upwinding fluid equations with Roe solve + struct gkyl_wv_eqn + *equation; // For storing 10 moment equation object for upwinding fluid equations with Roe solve struct gkyl_array *qmem; // array for q/m*(E,B) for use in *explicit* update - // Note: this array is *only* used if the PKPM self-consistent EM fields are static - // If PKPM self-consistent EM fields are dynamics we utilize an implicit source update - // for the momentum equations and Ampere's Law + // Note: this array is *only* used if the PKPM self-consistent EM fields are static + // If PKPM self-consistent EM fields are dynamics we utilize an implicit source update + // for the momentum equations and Ampere's Law struct pkpm_species_moment pkpm_moms; // for computing pkpm moments needed in update struct pkpm_species_moment pkpm_moms_diag; // for computing pkpm moments diagnostics // PKPM distribution function variables - struct gkyl_array *g_dist_source; // g_dist_source = [2.0*T_perp/m*(2.0*T_perp/m G + T_perp/m (F_2 - F_0)), - // (-vpar div(b) + bb:grad(u) - div(u) - 2 nu) T_perp/m G + 2 nu vth^2 F_0 ] - struct gkyl_array *F_k_p_1; // k+1 distribution function (first NP components are F_2) + struct gkyl_array + *g_dist_source; // g_dist_source = [2.0*T_perp/m*(2.0*T_perp/m G + T_perp/m (F_2 - F_0)), + // (-vpar div(b) + bb:grad(u) - div(u) - 2 nu) T_perp/m G + 2 nu vth^2 F_0 ] + struct gkyl_array *F_k_p_1; // k+1 distribution function (first NP components are F_2) struct gkyl_array *F_k_m_1; // k-1 distribution function (first NP components are F_1) // PKPM variables - struct gkyl_array *pkpm_div_ppar; // div(p_parallel b_hat) used for computing self-consistent total pressure force + struct gkyl_array + *pkpm_div_ppar; // div(p_parallel b_hat) used for computing self-consistent total pressure force struct gkyl_array *pkpm_prim; // [ux, uy, uz, 1/rho*div(p_par b), T_perp/m, m/T_perp] struct gkyl_array *pkpm_prim_surf; // Surface primitive variables. Ordered as: - // [ux_xl, ux_xr, uy_xl, uy_xr, uz_xl, uz_xr, 3.0*Txx_xl/m, 3.0*Txx_xr/m, - // ux_yl, ux_yr, uy_yl, uy_yr, uz_yl, uz_yr, 3.0*Tyy_yl/m, 3.0*Tyy_yr/m, - // ux_zl, ux_zr, uy_zl, uy_zr, uz_zl, uz_zr, 3.0*Tzz_zl/m, 3.0*Tzz_zr/m] + // [ux_xl, ux_xr, uy_xl, uy_xr, uz_xl, uz_xr, 3.0*Txx_xl/m, 3.0*Txx_xr/m, + // ux_yl, ux_yr, uy_yl, uy_yr, uz_yl, uz_yr, 3.0*Tyy_yl/m, 3.0*Tyy_yr/m, + // ux_zl, ux_zr, uy_zl, uy_zr, uz_zl, uz_zr, 3.0*Tzz_zl/m, 3.0*Tzz_zr/m] struct gkyl_array *pkpm_u; // [ux, uy, uz] struct gkyl_array *pkpm_p_ij; // (p_par - p_perp) b_i b_j + p_perp g_ij - struct gkyl_array *cell_avg_prim; // Integer array for whether rho, p_par, or p_perp < 0.0 at control points - // *only* currently used for diagnostic purposes + struct gkyl_array + *cell_avg_prim; // Integer array for whether rho, p_par, or p_perp < 0.0 at control points + // *only* currently used for diagnostic purposes struct gkyl_array *pkpm_accel; // Acceleration variables for PKPM, pkpm_accel: - // 0: p_perp_div_b (p_perp/rho*div(b) = T_perp/m*div(b)) - // 1: bb_grad_u (bb : grad(u)) - // 2: p_force (total pressure forces in kinetic equation 1/rho div(p_parallel b_hat) - T_perp/m*div(b) - // 3: p_perp_source (pressure source for higher Laguerre moments -> bb : grad(u) - div(u) - 2*nu) - struct gkyl_array *integ_pkpm_mom; // integrated PKPM variables [rho, rho ux, rho uy, rho uz, rho ux^2, rho uy^2, rho uz^2, p_par, p_perp] - - // Note: Each cell owns the *lower* surface expansions for pkpm_lax and pkpm_penalization - struct gkyl_array *pkpm_lax; // Surface expansion of Lax penalization lambda_i = |u_i| + sqrt(3.0*T_ii/m) + // 0: p_perp_div_b (p_perp/rho*div(b) = T_perp/m*div(b)) + // 1: bb_grad_u (bb : grad(u)) + // 2: p_force (total pressure forces in kinetic equation 1/rho div(p_parallel b_hat) - T_perp/m*div(b) + // 3: p_perp_source (pressure source for higher Laguerre moments -> bb : grad(u) - div(u) - 2*nu) + struct gkyl_array * + integ_pkpm_mom; // integrated PKPM variables [rho, rho ux, rho uy, rho uz, rho ux^2, rho uy^2, rho uz^2, p_par, p_perp] + + // Note: Each cell owns the *lower* surface expansions for pkpm_lax and pkpm_penalization + struct gkyl_array + *pkpm_lax; // Surface expansion of Lax penalization lambda_i = |u_i| + sqrt(3.0*T_ii/m) struct gkyl_array *pkpm_penalization; // Surface expansion of total momentum penalization - struct gkyl_dg_calc_pkpm_vars *calc_pkpm_vars; // Updater to compute PKPM variables (primitive and acceleration variables) - struct gkyl_dg_calc_pkpm_vars *calc_pkpm_vars_ext; // Updater to compute PKPM variables (primitive and acceleration variables) - // over extended range (used when BCs are not absorbing to minimize apply BCs calls) - struct gkyl_dg_calc_pkpm_dist_vars *calc_pkpm_dist_vars; // Updater to compute PKPM distribution function variables - // div(p_parallel b_hat) and distribution function sources + struct gkyl_dg_calc_pkpm_vars + *calc_pkpm_vars; // Updater to compute PKPM variables (primitive and acceleration variables) + struct gkyl_dg_calc_pkpm_vars + *calc_pkpm_vars_ext; // Updater to compute PKPM variables (primitive and acceleration variables) + // over extended range (used when BCs are not absorbing to minimize apply BCs calls) + struct gkyl_dg_calc_pkpm_dist_vars + *calc_pkpm_dist_vars; // Updater to compute PKPM distribution function variables + // div(p_parallel b_hat) and distribution function sources bool limit_fluid; // boolean for whether or not we are limiting fluid variables // Pointers for io for PKPM fluid variables, handled by kinetic species because of fluid-kinetic coupling. - // For PKPM we construct the 10 moment conserved variables for ease of analysis + // For PKPM we construct the 10 moment conserved variables for ease of analysis // along with an array of the various update variables, primitive and acceleration struct gkyl_array *fluid_io; struct gkyl_array *fluid_io_host; @@ -213,7 +229,7 @@ struct pkpm_species { gkyl_dg_updater_pkpm *slvr; // PKPM solver for both momentum and kinetic equation - // boundary conditions on lower/upper edges in each direction + // boundary conditions on lower/upper edges in each direction enum gkyl_species_bc_type lower_bc[3], upper_bc[3]; // Pointers to updaters that apply BC on distribution functions and momentum. struct gkyl_bc_basic *bc_lo_dist[3]; @@ -226,7 +242,7 @@ struct pkpm_species { struct gkyl_range upper_skin_dist[GKYL_MAX_DIM]; struct gkyl_range upper_ghost_dist[GKYL_MAX_DIM]; bool bc_is_absorb; // boolean for absorbing BCs since 1/rho is undefined in absorbing BCs - // If BCs are *not* absorbing, primitive variables can be calculated on *extended* range + // If BCs are *not* absorbing, primitive variables can be calculated on *extended* range bool has_app_accel; // flag to indicate there is applied acceleration bool app_accel_evolve; // flag to indicate applied acceleration is time-dependent @@ -250,42 +266,45 @@ struct pkpm_species { struct pkpm_field { struct gkyl_pkpm_field info; // data for field - struct gkyl_job_pool *job_pool; // Job pool + struct gkyl_job_pool *job_pool; // Job pool struct gkyl_array *em, *em1, *emnew; // arrays for updates struct gkyl_array *cflrate; // CFL rate in each cell struct gkyl_array *bc_buffer; // buffer for BCs (used for both copy and periodic) - struct gkyl_array *em_host; // host copy for use IO and initialization + struct gkyl_array *em_host; // host copy for use IO and initialization // Duplicate copy of EM data in case time step fails. - // Needed because of implicit source split which modifies solution and - // is always successful, so if a time step fails due to the SSP RK3 + // Needed because of implicit source split which modifies solution and + // is always successful, so if a time step fails due to the SSP RK3 // we must restore the old solution before restarting the time step - struct gkyl_array *em_dup; + struct gkyl_array *em_dup; bool has_ext_em; // flag to indicate there is external electromagnetic field bool ext_em_evolve; // flag to indicate external electromagnetic field is time dependent struct gkyl_array *ext_em; // external electromagnetic field struct gkyl_array *ext_em_host; // host copy for use in IO and projecting struct gkyl_array *tot_em; // total electromagnetic field - gkyl_proj_on_basis *ext_em_proj; // projector for external electromagnetic field + gkyl_proj_on_basis *ext_em_proj; // projector for external electromagnetic field - bool has_app_current; // flag to indicate there is an applied current + bool has_app_current; // flag to indicate there is an applied current bool app_current_evolve; // flag to indicate applied current is time dependent struct gkyl_array *app_current; // applied current struct gkyl_array *app_current_host; // host copy for use in IO and projecting - gkyl_proj_on_basis *app_current_proj; // projector for applied current - - struct gkyl_array *cell_avg_magB2; // Integer array for whether |B|^2 *only* uses cell averages for weak division - // Determined when constructing the matrix if |B|^2 < 0.0 at control points - struct gkyl_array *bvar; // magnetic field unit vector and tensor (diagnostic and for use in pkpm model) - struct gkyl_array *bvar_surf; // Surface expansion magnetic field unit vector and tensor (for use in pkpm model) + gkyl_proj_on_basis *app_current_proj; // projector for applied current + + struct gkyl_array + *cell_avg_magB2; // Integer array for whether |B|^2 *only* uses cell averages for weak division + // Determined when constructing the matrix if |B|^2 < 0.0 at control points + struct gkyl_array + *bvar; // magnetic field unit vector and tensor (diagnostic and for use in pkpm model) + struct gkyl_array + *bvar_surf; // Surface expansion magnetic field unit vector and tensor (for use in pkpm model) struct gkyl_array *div_b; // Volume expansion of div(b) (for use in pkpm model) struct gkyl_array *max_b; // max(|b_i|) penalization (for use in pkpm model) struct gkyl_dg_calc_em_vars *calc_bvar; // Updater to compute magnetic field unit vector and tensor bool limit_em; // boolean for whether or not we are limiting EM fields - struct gkyl_dg_calc_em_vars *calc_em_vars; // Updater to limit EM fields + struct gkyl_dg_calc_em_vars *calc_em_vars; // Updater to limit EM fields gkyl_hyper_dg *slvr; // Maxwell solver @@ -295,26 +314,26 @@ struct pkpm_field { bool is_first_energy_write_call; // flag for energy dynvec written first time - // boundary conditions on lower/upper edges in each direction + // boundary conditions on lower/upper edges in each direction enum gkyl_field_bc_type lower_bc[3], upper_bc[3]; // Pointers to updaters that apply BC. struct gkyl_bc_basic *bc_lo[3]; struct gkyl_bc_basic *bc_up[3]; - double* omegaCfl_ptr; + double *omegaCfl_ptr; }; // fluid-EM coupling data in PKPM system struct pkpm_fluid_em_coupling { double qbym[GKYL_MAX_SPECIES]; // charge/mass ratio for each species - struct gkyl_dg_calc_pkpm_em_coupling* slvr; // fluid-EM coupling solver + struct gkyl_dg_calc_pkpm_em_coupling *slvr; // fluid-EM coupling solver }; // PKPM object: used as opaque pointer in user code struct gkyl_pkpm_app { char name[128]; // name of app struct gkyl_job_pool *job_pool; // Job pool - + int cdim, vdim; // conf, velocity space dimensions int poly_order; // polynomial order double tcurr; // current time @@ -327,7 +346,7 @@ struct gkyl_pkpm_app { struct gkyl_rect_grid grid; // config-space grid struct gkyl_range local, local_ext; // local, local-ext conf-space ranges - struct gkyl_range global, global_ext; // global, global-ext conf-space ranges + struct gkyl_range global, global_ext; // global, global-ext conf-space ranges // To simplify BC application, store local skin and ghost ranges struct gkyl_range lower_skin[GKYL_MAX_DIM]; struct gkyl_range lower_ghost[GKYL_MAX_DIM]; @@ -337,22 +356,22 @@ struct gkyl_pkpm_app { struct gkyl_basis basis, confBasis, velBasis; // phase-space, conf-space basis, vel-space basis struct gkyl_rect_decomp *decomp; // decomposition object - struct gkyl_comm *comm; // communicator object for conf-space arrays + struct gkyl_comm *comm; // communicator object for conf-space arrays bool has_mapc2p; // flag to indicate if we have mapc2p - void *c2p_ctx; // context for mapc2p function + void *c2p_ctx; // context for mapc2p function // pointer to mapc2p function void (*mapc2p)(double t, const double *xc, double *xp, void *ctx); - struct gkyl_wave_geom *geom; // geometry needed for species and field solvers (*only* p=1 right now JJ: 05/03/24) - + struct gkyl_wave_geom + *geom; // geometry needed for species and field solvers (*only* p=1 right now JJ: 05/03/24) + // pointers to basis on device (these point to host structs if not // on GPU) struct { struct gkyl_basis *basis, *confBasis; } basis_on_dev; - struct pkpm_field *field; // pointer to field object // species data int num_species; @@ -362,23 +381,22 @@ struct gkyl_pkpm_app { struct pkpm_fluid_em_coupling *pkpm_em; // fluid-EM coupling data // pointer to function that takes a single-step of simulation struct gkyl_update_status (*update_func)(gkyl_pkpm_app *app, double dt0); - + struct gkyl_pkpm_stat stat; // statistics }; -// Take a single forward Euler step of the PKPM system with the suggested time-step dt. -void pkpm_forward_euler(gkyl_pkpm_app* app, double tcurr, double dt, - const struct gkyl_array *fin[], const struct gkyl_array *fluidin[], const struct gkyl_array *emin, - struct gkyl_array *fout[], struct gkyl_array *fluidout[], struct gkyl_array *emout, - struct gkyl_update_status *st); +// Take a single forward Euler step of the PKPM system with the suggested time-step dt. +void pkpm_forward_euler( + gkyl_pkpm_app *app, double tcurr, double dt, const struct gkyl_array *fin[], + const struct gkyl_array *fluidin[], const struct gkyl_array *emin, struct gkyl_array *fout[], + struct gkyl_array *fluidout[], struct gkyl_array *emout, struct gkyl_update_status *st +); // Take a single time-step using a first-order operator split implicit fluid-EM coupling + SSP RK3 -struct gkyl_update_status pkpm_update_op_split(gkyl_pkpm_app *app, - double dt0); +struct gkyl_update_status pkpm_update_op_split(gkyl_pkpm_app *app, double dt0); // Take a fully explicit single time-step using a SSP RK3 (including explicit fluid-EM coupling) -struct gkyl_update_status pkpm_update_explicit_ssp_rk3(gkyl_pkpm_app *app, - double dt0); +struct gkyl_update_status pkpm_update_explicit_ssp_rk3(gkyl_pkpm_app *app, double dt0); /** gkyl_pkpm_app private API */ @@ -389,7 +407,7 @@ struct gkyl_update_status pkpm_update_explicit_ssp_rk3(gkyl_pkpm_app *app, * @param nm Name of species * @return Pointer to species with given name. NULL if not found. */ -struct pkpm_species* pkpm_find_species(const gkyl_pkpm_app *app, const char *nm); +struct pkpm_species *pkpm_find_species(const gkyl_pkpm_app *app, const char *nm); /** * Return index of species in the order it appears in the input. @@ -410,8 +428,9 @@ int pkpm_find_species_idx(const gkyl_pkpm_app *app, const char *nm); * @param sm Species moment object * @param nm Name string indicating moment type */ -void pkpm_species_moment_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, - struct pkpm_species_moment *sm, bool is_diag); +void pkpm_species_moment_init( + struct gkyl_pkpm_app *app, struct pkpm_species *s, struct pkpm_species_moment *sm, bool is_diag +); /** * Calculate moment, given distribution function @a fin. @@ -420,9 +439,10 @@ void pkpm_species_moment_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, * @param conf_rng Config-space range * @param fin Input distribution function array */ -void pkpm_species_moment_calc(const struct pkpm_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin); +void pkpm_species_moment_calc( + const struct pkpm_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +); /** * Release species moment object. @@ -430,8 +450,9 @@ void pkpm_species_moment_calc(const struct pkpm_species_moment *sm, * @param app PKPM app object * @param sm Species moment object to release */ -void pkpm_species_moment_release(const struct gkyl_pkpm_app *app, - const struct pkpm_species_moment *sm); +void pkpm_species_moment_release( + const struct gkyl_pkpm_app *app, const struct pkpm_species_moment *sm +); /** pkpm_species_lbo API */ @@ -443,8 +464,9 @@ void pkpm_species_moment_release(const struct gkyl_pkpm_app *app, * @param lbo Species LBO object * @param collides_with_fluid Boolean for if kinetic species collides with a fluid species */ -void pkpm_species_lbo_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, - struct pkpm_lbo_collisions *lbo); +void pkpm_species_lbo_init( + struct gkyl_pkpm_app *app, struct pkpm_species *s, struct pkpm_lbo_collisions *lbo +); /** * Initialize species LBO cross-collisions object. @@ -453,8 +475,9 @@ void pkpm_species_lbo_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, * @param s Species object * @param lbo Species LBO object */ -void pkpm_species_lbo_cross_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, - struct pkpm_lbo_collisions *lbo); +void pkpm_species_lbo_cross_init( + struct gkyl_pkpm_app *app, struct pkpm_species *s, struct pkpm_lbo_collisions *lbo +); /** * Compute necessary moments and boundary @@ -465,10 +488,10 @@ void pkpm_species_lbo_cross_init(struct gkyl_pkpm_app *app, struct pkpm_species * @param lbo Pointer to LBO * @param fin Input distribution function */ -void pkpm_species_lbo_moms(gkyl_pkpm_app *app, - const struct pkpm_species *species, - struct pkpm_lbo_collisions *lbo, - const struct gkyl_array *fin); +void pkpm_species_lbo_moms( + gkyl_pkpm_app *app, const struct pkpm_species *species, struct pkpm_lbo_collisions *lbo, + const struct gkyl_array *fin +); /** * Compute necessary moments for cross-species LBO collisions @@ -480,10 +503,10 @@ void pkpm_species_lbo_moms(gkyl_pkpm_app *app, * @param collides_with_fluid Boolean for if kinetic species collides with a fluid species * @param fluidin Input fluid array (size: num_fluid_species) */ -void pkpm_species_lbo_cross_moms(gkyl_pkpm_app *app, - const struct pkpm_species *species, - struct pkpm_lbo_collisions *lbo, - const struct gkyl_array *fin); +void pkpm_species_lbo_cross_moms( + gkyl_pkpm_app *app, const struct pkpm_species *species, struct pkpm_lbo_collisions *lbo, + const struct gkyl_array *fin +); /** * Compute RHS from LBO collisions @@ -495,10 +518,10 @@ void pkpm_species_lbo_cross_moms(gkyl_pkpm_app *app, * @param rhs On output, the RHS from LBO * @return Maximum stable time-step */ -void pkpm_species_lbo_rhs(gkyl_pkpm_app *app, - const struct pkpm_species *species, - struct pkpm_lbo_collisions *lbo, - const struct gkyl_array *fin, struct gkyl_array *rhs); +void pkpm_species_lbo_rhs( + gkyl_pkpm_app *app, const struct pkpm_species *species, struct pkpm_lbo_collisions *lbo, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Release species LBO object. @@ -506,7 +529,9 @@ void pkpm_species_lbo_rhs(gkyl_pkpm_app *app, * @param app PKPM app object * @param sm Species LBO object to release */ -void pkpm_species_lbo_release(const struct gkyl_pkpm_app *app, const struct pkpm_lbo_collisions *lbo); +void pkpm_species_lbo_release( + const struct gkyl_pkpm_app *app, const struct pkpm_lbo_collisions *lbo +); /** pkpm_species API */ @@ -547,8 +572,10 @@ void pkpm_species_calc_app_accel(gkyl_pkpm_app *app, struct pkpm_species *specie * @param fin Input distribution function * @param fluidin Input fluid species array (size: num_fluid_species) */ -void pkpm_species_calc_pkpm_vars(gkyl_pkpm_app *app, struct pkpm_species *species, - const struct gkyl_array *fin, const struct gkyl_array *fluidin); +void pkpm_species_calc_pkpm_vars( + gkyl_pkpm_app *app, struct pkpm_species *species, const struct gkyl_array *fin, + const struct gkyl_array *fluidin +); /** * Compute parallel-kinetic-perpendicular-moment (pkpm) model update variables @@ -559,7 +586,9 @@ void pkpm_species_calc_pkpm_vars(gkyl_pkpm_app *app, struct pkpm_species *specie * @param species Species object * @param fin Input distribution function */ -void pkpm_species_calc_pkpm_update_vars(gkyl_pkpm_app *app, struct pkpm_species *species, const struct gkyl_array *fin); +void pkpm_species_calc_pkpm_update_vars( + gkyl_pkpm_app *app, struct pkpm_species *species, const struct gkyl_array *fin +); /** * Limit slopes of solution of fluid variables @@ -569,8 +598,9 @@ void pkpm_species_calc_pkpm_update_vars(gkyl_pkpm_app *app, struct pkpm_species * @param fin Input distribution function * @param fluid Input (and Output after limiting) array fluid species */ -void pkpm_fluid_species_limiter(gkyl_pkpm_app *app, struct pkpm_species *species, - struct gkyl_array *fin, struct gkyl_array *fluid); +void pkpm_fluid_species_limiter( + gkyl_pkpm_app *app, struct pkpm_species *species, struct gkyl_array *fin, struct gkyl_array *fluid +); /** * Compute RHS from species distribution function @@ -583,9 +613,11 @@ void pkpm_fluid_species_limiter(gkyl_pkpm_app *app, struct pkpm_species *species * @param fluidin Input fluid array for potential fluid force (size: num_fluid_species) * @return Maximum stable time-step */ -double pkpm_species_rhs(gkyl_pkpm_app *app, struct pkpm_species *species, - const struct gkyl_array *fin, const struct gkyl_array *fluidin, const struct gkyl_array *em, - struct gkyl_array *rhs_f, struct gkyl_array *rhs_fluid); +double pkpm_species_rhs( + gkyl_pkpm_app *app, struct pkpm_species *species, const struct gkyl_array *fin, + const struct gkyl_array *fluidin, const struct gkyl_array *em, struct gkyl_array *rhs_f, + struct gkyl_array *rhs_fluid +); /** * Apply BCs to species distribution functions @@ -594,8 +626,9 @@ double pkpm_species_rhs(gkyl_pkpm_app *app, struct pkpm_species *species, * @param species Pointer to species * @param f Distribution function to apply BCs to */ -void pkpm_species_apply_bc(gkyl_pkpm_app *app, const struct pkpm_species *species, - struct gkyl_array *f); +void pkpm_species_apply_bc( + gkyl_pkpm_app *app, const struct pkpm_species *species, struct gkyl_array *f +); /** * Apply BCs to species momentum @@ -604,8 +637,9 @@ void pkpm_species_apply_bc(gkyl_pkpm_app *app, const struct pkpm_species *specie * @param species Pointer to species * @param fluid momentum to apply BCs to */ -void pkpm_fluid_species_apply_bc(gkyl_pkpm_app *app, const struct pkpm_species *species, - struct gkyl_array *fluid); +void pkpm_fluid_species_apply_bc( + gkyl_pkpm_app *app, const struct pkpm_species *species, struct gkyl_array *fluid +); /** * Compute L2 norm (f^2) of the distribution function diagnostic @@ -636,7 +670,7 @@ void pkpm_species_tm(gkyl_pkpm_app *app); * @param app PKPM app object * @param species Species object to delete */ -void pkpm_species_release(const gkyl_pkpm_app* app, const struct pkpm_species *s); +void pkpm_species_release(const gkyl_pkpm_app *app, const struct pkpm_species *s); /** pkpm_field API */ @@ -647,7 +681,7 @@ void pkpm_species_release(const gkyl_pkpm_app* app, const struct pkpm_species *s * @param app PKPM app object * @return Newly created field */ -struct pkpm_field* pkpm_field_new(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app); +struct pkpm_field *pkpm_field_new(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app); /** * Compute field initial conditions. @@ -701,8 +735,9 @@ void pkpm_field_calc_ExB(gkyl_pkpm_app *app, struct pkpm_field *field, const str * @param fluidin[] Input fluid array (num_species size) * @param emout On output, the RHS from the field solver *with* accumulated current density */ -void pkpm_field_accumulate_current(gkyl_pkpm_app *app, - const struct gkyl_array *fluidin[], struct gkyl_array *emout); +void pkpm_field_accumulate_current( + gkyl_pkpm_app *app, const struct gkyl_array *fluidin[], struct gkyl_array *emout +); /** * Limit slopes of solution of EM variables @@ -721,8 +756,10 @@ void pkpm_field_limiter(gkyl_pkpm_app *app, struct pkpm_field *field, struct gky * @param fluidin[] Input fluid array (num_species size) * @param emout On output, the RHS from the field solver *with* accumulated current density */ -void pkpm_field_explicit_accumulate_current(gkyl_pkpm_app *app, struct pkpm_field *field, - const struct gkyl_array *fluidin[], struct gkyl_array *emout); +void pkpm_field_explicit_accumulate_current( + gkyl_pkpm_app *app, struct pkpm_field *field, const struct gkyl_array *fluidin[], + struct gkyl_array *emout +); /** * Compute RHS from field equations @@ -733,7 +770,9 @@ void pkpm_field_explicit_accumulate_current(gkyl_pkpm_app *app, struct pkpm_fiel * @param rhs On output, the RHS from the field solver * @return Maximum stable time-step */ -double pkpm_field_rhs(gkyl_pkpm_app *app, struct pkpm_field *field, const struct gkyl_array *em, struct gkyl_array *rhs); +double pkpm_field_rhs( + gkyl_pkpm_app *app, struct pkpm_field *field, const struct gkyl_array *em, struct gkyl_array *rhs +); /** * Apply BCs to field @@ -742,8 +781,7 @@ double pkpm_field_rhs(gkyl_pkpm_app *app, struct pkpm_field *field, const struct * @param field Pointer to field * @param f Field to apply BCs */ -void pkpm_field_apply_bc(gkyl_pkpm_app *app, const struct pkpm_field *field, - struct gkyl_array *f); +void pkpm_field_apply_bc(gkyl_pkpm_app *app, const struct pkpm_field *field, struct gkyl_array *f); /** * Compute field energy diagnostic @@ -760,7 +798,7 @@ void pkpm_field_calc_energy(gkyl_pkpm_app *app, double tm, const struct pkpm_fie * @param app PKPM app object * @param f Field object to release */ -void pkpm_field_release(const gkyl_pkpm_app* app, struct pkpm_field *f); +void pkpm_field_release(const gkyl_pkpm_app *app, struct pkpm_field *f); /** * Create new fluid-EM coupling updater for the PKPM system @@ -768,7 +806,7 @@ void pkpm_field_release(const gkyl_pkpm_app* app, struct pkpm_field *f); * @param app PKPM app object * @return Newly created fluid-EM coupling updater */ -struct pkpm_fluid_em_coupling* pkpm_fluid_em_coupling_init(struct gkyl_pkpm_app *app); +struct pkpm_fluid_em_coupling *pkpm_fluid_em_coupling_init(struct gkyl_pkpm_app *app); /** * Compute implicit update of fluid-EM coupling for the PKPM system @@ -778,8 +816,9 @@ struct pkpm_fluid_em_coupling* pkpm_fluid_em_coupling_init(struct gkyl_pkpm_app * @param tcurr Current time * @param dt Time step size */ -void pkpm_fluid_em_coupling_update(struct gkyl_pkpm_app *app, - struct pkpm_fluid_em_coupling *pkpm_em, double tcurr, double dt); +void pkpm_fluid_em_coupling_update( + struct gkyl_pkpm_app *app, struct pkpm_fluid_em_coupling *pkpm_em, double tcurr, double dt +); /** * Release resources allocated by fluid-EM coupling object for the PKPM system @@ -787,5 +826,6 @@ void pkpm_fluid_em_coupling_update(struct gkyl_pkpm_app *app, * @param app PKPM app object * @param pkpm_em fluid-EM coupling updater to release */ -void pkpm_fluid_em_coupling_release(struct gkyl_pkpm_app *app, - struct pkpm_fluid_em_coupling *pkpm_em); +void pkpm_fluid_em_coupling_release( + struct gkyl_pkpm_app *app, struct pkpm_fluid_em_coupling *pkpm_em +); diff --git a/pkpm/apps/pkpm.c b/pkpm/apps/pkpm.c index e76b6e5268..59577f7605 100644 --- a/pkpm/apps/pkpm.c +++ b/pkpm/apps/pkpm.c @@ -14,8 +14,7 @@ #include // returned gkyl_array_meta must be freed using pkpm_array_meta_release -static struct gkyl_msgpack_data* -pkpm_array_meta_new(struct pkpm_output_meta meta) +static struct gkyl_msgpack_data *pkpm_array_meta_new(struct pkpm_output_meta meta) { struct gkyl_msgpack_data *mt = gkyl_malloc(sizeof(*mt)); @@ -25,7 +24,7 @@ pkpm_array_meta_new(struct pkpm_output_meta meta) // add some data to mpack mpack_build_map(&writer); - + mpack_write_cstr(&writer, "time"); mpack_write_double(&writer, meta.stime); @@ -51,18 +50,18 @@ pkpm_array_meta_new(struct pkpm_output_meta meta) return mt; } -static void -pkpm_array_meta_release(struct gkyl_msgpack_data *mt) +static void pkpm_array_meta_release(struct gkyl_msgpack_data *mt) { - if (!mt) return; + if (!mt) { + return; + } MPACK_FREE(mt->meta); gkyl_free(mt); } -static struct pkpm_output_meta -pkpm_meta_from_mpack(struct gkyl_msgpack_data *mt) +static struct pkpm_output_meta pkpm_meta_from_mpack(struct gkyl_msgpack_data *mt) { - struct pkpm_output_meta meta = { .frame = 0, .stime = 0.0 }; + struct pkpm_output_meta meta = {.frame = 0, .stime = 0.0}; if (mt->meta_sz > 0) { mpack_tree_t tree; @@ -90,8 +89,7 @@ pkpm_meta_from_mpack(struct gkyl_msgpack_data *mt) return meta; } -gkyl_pkpm_app* -gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm) +gkyl_pkpm_app *gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm) { disable_denorm_float(); @@ -101,7 +99,7 @@ gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm) int cdim = app->cdim = pkpm->cdim; int vdim = app->vdim = pkpm->vdim; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int poly_order = app->poly_order = pkpm->poly_order; int ns = app->num_species = pkpm->num_species; @@ -115,8 +113,9 @@ gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm) #endif app->num_periodic_dir = pkpm->num_periodic_dir; - for (int d=0; dperiodic_dirs[d] = pkpm->periodic_dirs[d]; + } strcpy(app->name, pkpm->name); app->tcurr = 0.0; // reset on init @@ -125,70 +124,68 @@ gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm) // allocate device basis if we are using GPUs app->basis_on_dev.basis = gkyl_cu_malloc(sizeof(struct gkyl_basis)); app->basis_on_dev.confBasis = gkyl_cu_malloc(sizeof(struct gkyl_basis)); - } - else { + } else { app->basis_on_dev.basis = &app->basis; app->basis_on_dev.confBasis = &app->confBasis; } // basis functions switch (pkpm->basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - gkyl_cart_modal_serendip(&app->confBasis, cdim, poly_order); + case GKYL_BASIS_MODAL_SERENDIPITY: + gkyl_cart_modal_serendip(&app->confBasis, cdim, poly_order); + if (poly_order > 1) { + gkyl_cart_modal_serendip(&app->basis, pdim, poly_order); + if (vdim > 0) { + gkyl_cart_modal_serendip(&app->velBasis, vdim, poly_order); + } + } else if (poly_order == 1) { + /* Force hybrid basis (p=2 in velocity space). */ + gkyl_cart_modal_hybrid(&app->basis, cdim, vdim); + if (vdim > 0) { + gkyl_cart_modal_serendip(&app->velBasis, vdim, 2); + } + } + + if (app->use_gpu) { + gkyl_cart_modal_serendip_cu_dev(app->basis_on_dev.confBasis, cdim, poly_order); if (poly_order > 1) { - gkyl_cart_modal_serendip(&app->basis, pdim, poly_order); - if (vdim > 0) - gkyl_cart_modal_serendip(&app->velBasis, vdim, poly_order); + gkyl_cart_modal_serendip_cu_dev(app->basis_on_dev.basis, pdim, poly_order); } else if (poly_order == 1) { /* Force hybrid basis (p=2 in velocity space). */ - gkyl_cart_modal_hybrid(&app->basis, cdim, vdim); - if (vdim > 0) - gkyl_cart_modal_serendip(&app->velBasis, vdim, 2); + gkyl_cart_modal_hybrid_cu_dev(app->basis_on_dev.basis, cdim, vdim); } + } + break; - if (app->use_gpu) { - gkyl_cart_modal_serendip_cu_dev(app->basis_on_dev.confBasis, cdim, poly_order); - if (poly_order > 1) { - gkyl_cart_modal_serendip_cu_dev(app->basis_on_dev.basis, pdim, poly_order); - } else if (poly_order == 1) { - /* Force hybrid basis (p=2 in velocity space). */ - gkyl_cart_modal_hybrid_cu_dev(app->basis_on_dev.basis, cdim, vdim); - } - } - break; - - case GKYL_BASIS_MODAL_TENSOR: - gkyl_cart_modal_tensor(&app->basis, pdim, poly_order); - gkyl_cart_modal_tensor(&app->confBasis, cdim, poly_order); - if (vdim > 0) - gkyl_cart_modal_tensor(&app->velBasis, vdim, poly_order); - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_TENSOR: + gkyl_cart_modal_tensor(&app->basis, pdim, poly_order); + gkyl_cart_modal_tensor(&app->confBasis, cdim, poly_order); + if (vdim > 0) { + gkyl_cart_modal_tensor(&app->velBasis, vdim, poly_order); + } + break; + + default: + assert(false); + break; } gkyl_rect_grid_init(&app->grid, cdim, pkpm->lower, pkpm->upper, pkpm->cells); - int ghost[] = { 1, 1, 1 }; + int ghost[] = {1, 1, 1}; gkyl_create_grid_ranges(&app->grid, ghost, &app->global_ext, &app->global); if (pkpm->parallelism.comm == 0) { - int cuts[3] = { 1, 1, 1 }; + int cuts[3] = {1, 1, 1}; app->decomp = gkyl_rect_decomp_new_from_cuts(cdim, cuts, &app->global); - - app->comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = app->decomp, - .use_gpu = app->use_gpu - } - ); - + + app->comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.decomp = app->decomp, .use_gpu = app->use_gpu}); + // Global and local ranges are same, and so just copy them. memcpy(&app->local, &app->global, sizeof(struct gkyl_range)); memcpy(&app->local_ext, &app->global_ext, sizeof(struct gkyl_range)); - } - else { + } else { // Create decomp. app->decomp = gkyl_rect_decomp_new_from_cuts(app->cdim, pkpm->parallelism.cuts, &app->global); @@ -202,14 +199,18 @@ gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm) } // local skin and ghost ranges for configuration space fields - for (int dir=0; dirlower_skin[dir], &app->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &app->local_ext, ghost); - gkyl_skin_ghost_ranges(&app->upper_skin[dir], &app->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &app->local_ext, ghost); + for (int dir = 0; dir < cdim; ++dir) { + gkyl_skin_ghost_ranges( + &app->lower_skin[dir], &app->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &app->local_ext, ghost + ); + gkyl_skin_ghost_ranges( + &app->upper_skin[dir], &app->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &app->local_ext, ghost + ); } // Configuration space geometry initialization // Note: *only* uses a p=1 DG representation of the geometry (JJ: 05/03/24) - app->c2p_ctx = app->mapc2p = 0; + app->c2p_ctx = app->mapc2p = 0; app->has_mapc2p = pkpm->mapc2p ? true : false; if (app->has_mapc2p) { @@ -222,8 +223,9 @@ gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm) gkyl_cart_modal_tensor(&basis, cdim, 1); // initialize DG field representing mapping - struct gkyl_array *c2p = mkarr(false, cdim*basis.num_basis, app->local_ext.volume); - gkyl_eval_on_nodes *ev_c2p = gkyl_eval_on_nodes_new(&app->grid, &basis, cdim, pkpm->mapc2p, pkpm->c2p_ctx); + struct gkyl_array *c2p = mkarr(false, cdim * basis.num_basis, app->local_ext.volume); + gkyl_eval_on_nodes *ev_c2p = + gkyl_eval_on_nodes_new(&app->grid, &basis, cdim, pkpm->mapc2p, pkpm->c2p_ctx); gkyl_eval_on_nodes_advance(ev_c2p, 0.0, &app->local_ext, c2p); // write DG projection of mapc2p to file @@ -236,30 +238,32 @@ gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm) } // create geometry object - app->geom = gkyl_wave_geom_new(&app->grid, &app->local_ext, - app->mapc2p, app->c2p_ctx, app->use_gpu); + app->geom = + gkyl_wave_geom_new(&app->grid, &app->local_ext, app->mapc2p, app->c2p_ctx, app->use_gpu); // PKPM system *always* has a field to define the local magnetic field direction app->field = pkpm_field_new(pkpm, app); // allocate space to store species objects - app->species = ns>0 ? gkyl_malloc(sizeof(struct pkpm_species[ns])) : 0; + app->species = ns > 0 ? gkyl_malloc(sizeof(struct pkpm_species[ns])) : 0; // set info for each species: this needs to be done here as we need // to access species name from pkpm_species_init - for (int i=0; ispecies[i].info = pkpm->species[i]; + } // initialize each species - for (int i=0; ispecies[i]); + } // initialize each species cross-species terms: this has to be done here // as need pointers to colliding species' collision objects // allocated in the previous step - for (int i=0; ispecies[i].collision_id == GKYL_LBO_COLLISIONS - && app->species[i].lbo.num_cross_collisions) { + for (int i = 0; i < ns; ++i) { + if (app->species[i].collision_id == GKYL_LBO_COLLISIONS && + app->species[i].lbo.num_cross_collisions) { pkpm_species_lbo_cross_init(app, &app->species[i], &app->species[i].lbo); } } @@ -267,57 +271,53 @@ gkyl_pkpm_app_new(struct gkyl_pkpm *pkpm) // Set the appropriate update function for taking a single time step app->use_explicit_source = pkpm->use_explicit_source; if (app->use_explicit_source) { - // If momentum-EM field coupling is explicit, + // If momentum-EM field coupling is explicit, // we use a pure explicit SSP RK3 method. app->update_func = pkpm_update_explicit_ssp_rk3; - } - else { - // By default: we perform a first-order operator split - // to implicitly treat the momentum-EM field coupling. + } else { + // By default: we perform a first-order operator split + // to implicitly treat the momentum-EM field coupling. app->pkpm_em = pkpm_fluid_em_coupling_init(app); app->update_func = pkpm_update_op_split; } - + // initialize stat object - app->stat = (struct gkyl_pkpm_stat) { - .use_gpu = app->use_gpu, - .stage_2_dt_diff = { DBL_MAX, 0.0 }, - .stage_3_dt_diff = { DBL_MAX, 0.0 }, - }; + app->stat = (struct gkyl_pkpm_stat + ){.use_gpu = app->use_gpu, .stage_2_dt_diff = {DBL_MAX, 0.0}, .stage_3_dt_diff = {DBL_MAX, 0.0}}; return app; } -struct pkpm_species * -pkpm_find_species(const gkyl_pkpm_app *app, const char *nm) +struct pkpm_species *pkpm_find_species(const gkyl_pkpm_app *app, const char *nm) { - for (int i=0; inum_species; ++i) - if (strcmp(nm, app->species[i].info.name) == 0) + for (int i = 0; i < app->num_species; ++i) { + if (strcmp(nm, app->species[i].info.name) == 0) { return &app->species[i]; + } + } return 0; } -int -pkpm_find_species_idx(const gkyl_pkpm_app *app, const char *nm) +int pkpm_find_species_idx(const gkyl_pkpm_app *app, const char *nm) { - for (int i=0; inum_species; ++i) - if (strcmp(nm, app->species[i].info.name) == 0) + for (int i = 0; i < app->num_species; ++i) { + if (strcmp(nm, app->species[i].info.name) == 0) { return i; + } + } return -1; } -void -gkyl_pkpm_app_apply_ic(gkyl_pkpm_app* app, double t0) +void gkyl_pkpm_app_apply_ic(gkyl_pkpm_app *app, double t0) { app->tcurr = t0; gkyl_pkpm_app_apply_ic_field(app, t0); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_pkpm_app_apply_ic_species(app, i, t0); } } -void -gkyl_pkpm_app_apply_ic_field(gkyl_pkpm_app* app, double t0) +void gkyl_pkpm_app_apply_ic_field(gkyl_pkpm_app *app, double t0) { app->tcurr = t0; @@ -330,11 +330,10 @@ gkyl_pkpm_app_apply_ic_field(gkyl_pkpm_app* app, double t0) // we apply BCs in the initialization step. Note that the apply_bc call // may not apply BCs in the corner cells and the corner values will just // be what comes from initializing the EM field over the extended range - pkpm_field_calc_bvar(app, app->field, app->field->em); + pkpm_field_calc_bvar(app, app->field, app->field->em); } -void -gkyl_pkpm_app_apply_ic_species(gkyl_pkpm_app* app, int sidx, double t0) +void gkyl_pkpm_app_apply_ic_species(gkyl_pkpm_app *app, int sidx, double t0) { assert(sidx < app->num_species); @@ -347,27 +346,25 @@ gkyl_pkpm_app_apply_ic_species(gkyl_pkpm_app* app, int sidx, double t0) pkpm_fluid_species_apply_bc(app, &app->species[sidx], app->species[sidx].fluid); } -void -gkyl_pkpm_app_calc_integrated_mom(gkyl_pkpm_app* app, double tm) +void gkyl_pkpm_app_calc_integrated_mom(gkyl_pkpm_app *app, double tm) { double avals[9], avals_global[9]; struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct pkpm_species *s = &app->species[i]; gkyl_array_clear(s->integ_pkpm_mom, 0.0); pkpm_species_calc_pkpm_vars(app, s, s->f, s->fluid); - gkyl_dg_calc_pkpm_integrated_vars(s->calc_pkpm_vars, &app->local, - s->pkpm_moms.marr, s->fluid, - s->pkpm_prim, s->integ_pkpm_mom); + gkyl_dg_calc_pkpm_integrated_vars( + s->calc_pkpm_vars, &app->local, s->pkpm_moms.marr, s->fluid, s->pkpm_prim, s->integ_pkpm_mom + ); gkyl_array_scale_range(s->integ_pkpm_mom, app->grid.cellVolume, &(app->local)); if (app->use_gpu) { gkyl_array_reduce_range(s->red_integ_diag, s->integ_pkpm_mom, GKYL_SUM, &(app->local)); gkyl_cu_memcpy(avals, s->red_integ_diag, sizeof(double[9]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { gkyl_array_reduce_range(avals, s->integ_pkpm_mom, GKYL_SUM, &(app->local)); } @@ -379,11 +376,10 @@ gkyl_pkpm_app_calc_integrated_mom(gkyl_pkpm_app* app, double tm) app->stat.n_diag += app->num_species; } -void -gkyl_pkpm_app_calc_integrated_L2_f(gkyl_pkpm_app* app, double tm) +void gkyl_pkpm_app_calc_integrated_L2_f(gkyl_pkpm_app *app, double tm) { struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct pkpm_species *s = &app->species[i]; pkpm_species_calc_L2(app, tm, s); } @@ -391,8 +387,7 @@ gkyl_pkpm_app_calc_integrated_L2_f(gkyl_pkpm_app* app, double tm) app->stat.n_diag += app->num_species; } -void -gkyl_pkpm_app_calc_field_energy(gkyl_pkpm_app* app, double tm) +void gkyl_pkpm_app_calc_field_energy(gkyl_pkpm_app *app, double tm) { struct timespec wst = gkyl_wall_clock(); pkpm_field_calc_energy(app, tm, app->field); @@ -400,14 +395,13 @@ gkyl_pkpm_app_calc_field_energy(gkyl_pkpm_app* app, double tm) app->stat.n_diag += 1; } -void -gkyl_pkpm_app_write(gkyl_pkpm_app* app, double tm, int frame) +void gkyl_pkpm_app_write(gkyl_pkpm_app *app, double tm, int frame) { app->stat.n_io += 1; struct timespec wtm = gkyl_wall_clock(); - + gkyl_pkpm_app_write_field(app, tm, frame); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_pkpm_app_write_species(app, i, tm, frame); gkyl_pkpm_app_write_mom(app, i, tm, frame); } @@ -415,41 +409,35 @@ gkyl_pkpm_app_write(gkyl_pkpm_app* app, double tm, int frame) app->stat.io_tm += gkyl_time_diff_now_sec(wtm); } -void -gkyl_pkpm_app_write_field(gkyl_pkpm_app* app, double tm, int frame) +void gkyl_pkpm_app_write_field(gkyl_pkpm_app *app, double tm, int frame) { - struct gkyl_msgpack_data *mt = pkpm_array_meta_new( (struct pkpm_output_meta) { - .frame = frame, - .stime = tm, - .poly_order = app->poly_order, - .basis_type = app->confBasis.id - } - ); + struct gkyl_msgpack_data *mt = pkpm_array_meta_new((struct pkpm_output_meta + ){.frame = frame, .stime = tm, .poly_order = app->poly_order, .basis_type = app->confBasis.id}); const char *fmt = "%s-field_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, frame); if (app->use_gpu) { // copy data from device to host before writing it out gkyl_array_copy(app->field->em_host, app->field->em); } - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, app->field->em_host, fileNm); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, app->field->em_host, fileNm); if (app->field->has_ext_em) { // Only write out external fields at t=0 or if they are time-dependent if (frame == 0 || app->field->ext_em_evolve) { const char *fmt_ext_em = "%s-field_ext_em_%d.gkyl"; int sz_ext_em = gkyl_calc_strlen(fmt_ext_em, app->name, frame); - char fileNm_ext_em[sz_ext_em+1]; // ensures no buffer overflow + char fileNm_ext_em[sz_ext_em + 1]; // ensures no buffer overflow snprintf(fileNm_ext_em, sizeof fileNm_ext_em, fmt_ext_em, app->name, frame); - // External EM field computed with project on basis, so just use host copy + // External EM field computed with project on basis, so just use host copy pkpm_field_calc_ext_em(app, app->field, tm); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, app->field->ext_em_host, fileNm_ext_em); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, app->field->ext_em_host, fileNm_ext_em + ); } } @@ -458,85 +446,73 @@ gkyl_pkpm_app_write_field(gkyl_pkpm_app* app, double tm, int frame) if (frame == 0 || app->field->app_current_evolve) { const char *fmt_app_current = "%s-field_app_current_%d.gkyl"; int sz_app_current = gkyl_calc_strlen(fmt_app_current, app->name, frame); - char fileNm_app_current[sz_app_current+1]; // ensures no buffer overflow + char fileNm_app_current[sz_app_current + 1]; // ensures no buffer overflow snprintf(fileNm_app_current, sizeof fileNm_app_current, fmt_app_current, app->name, frame); - // Applied currents computed with project on basis, so just use host copy + // Applied currents computed with project on basis, so just use host copy pkpm_field_calc_app_current(app, app->field, tm); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, app->field->app_current_host, fileNm_app_current); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, app->field->app_current_host, fileNm_app_current + ); } - } + } - pkpm_array_meta_release(mt); + pkpm_array_meta_release(mt); } -void -gkyl_pkpm_app_write_species(gkyl_pkpm_app* app, int sidx, double tm, int frame) +void gkyl_pkpm_app_write_species(gkyl_pkpm_app *app, int sidx, double tm, int frame) { - struct gkyl_msgpack_data *mt = pkpm_array_meta_new( (struct pkpm_output_meta) { - .frame = frame, - .stime = tm, - .poly_order = app->poly_order, - .basis_type = app->basis.id - } - ); + struct gkyl_msgpack_data *mt = pkpm_array_meta_new((struct pkpm_output_meta + ){.frame = frame, .stime = tm, .poly_order = app->poly_order, .basis_type = app->basis.id}); struct pkpm_species *s = &app->species[sidx]; const char *fmt = "%s-%s_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, s->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, s->info.name, frame); if (app->use_gpu) { // copy data from device to host before writing it out gkyl_array_copy(s->f_host, s->f); } - gkyl_comm_array_write(s->comm, &s->grid, &s->local, - mt, s->f_host, fileNm); + gkyl_comm_array_write(s->comm, &s->grid, &s->local, mt, s->f_host, fileNm); - pkpm_array_meta_release(mt); + pkpm_array_meta_release(mt); } -void -gkyl_pkpm_app_write_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame) +void gkyl_pkpm_app_write_mom(gkyl_pkpm_app *app, int sidx, double tm, int frame) { - struct gkyl_msgpack_data *mt = pkpm_array_meta_new( (struct pkpm_output_meta) { - .frame = frame, - .stime = tm, - .poly_order = app->poly_order, - .basis_type = app->confBasis.id - } - ); + struct gkyl_msgpack_data *mt = pkpm_array_meta_new((struct pkpm_output_meta + ){.frame = frame, .stime = tm, .poly_order = app->poly_order, .basis_type = app->confBasis.id}); struct pkpm_species *s = &app->species[sidx]; // Construct the file handles for the three quantities (PKPM moments, PKPM fluid variables, PKPM update variables) const char *fmt = "%s-%s_pkpm_moms_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, s->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, s->info.name, frame); const char *fmt_fluid = "%s-%s_pkpm_fluid_%d.gkyl"; int sz_fluid = gkyl_calc_strlen(fmt_fluid, app->name, s->info.name, frame); - char fileNm_fluid[sz_fluid+1]; // ensures no buffer overflow + char fileNm_fluid[sz_fluid + 1]; // ensures no buffer overflow snprintf(fileNm_fluid, sizeof fileNm_fluid, fmt_fluid, app->name, s->info.name, frame); const char *fmt_pkpm_vars = "%s-%s_pkpm_vars_%d.gkyl"; int sz_pkpm_vars = gkyl_calc_strlen(fmt_pkpm_vars, app->name, s->info.name, frame); - char fileNm_pkpm_vars[sz_pkpm_vars+1]; // ensures no buffer overflow + char fileNm_pkpm_vars[sz_pkpm_vars + 1]; // ensures no buffer overflow snprintf(fileNm_pkpm_vars, sizeof fileNm_pkpm_vars, fmt_pkpm_vars, app->name, s->info.name, frame); - // Compute the PKPM variables including moments and primitive variables + // Compute the PKPM variables including moments and primitive variables // and construct arrays for writing out fluid and other pkpm variables. pkpm_species_moment_calc(&s->pkpm_moms_diag, s->local, app->local, s->f); pkpm_species_calc_pkpm_vars(app, s, s->f, s->fluid); - pkpm_species_calc_pkpm_update_vars(app, s, s->f); - gkyl_dg_calc_pkpm_vars_io(s->calc_pkpm_vars, &app->local, - s->pkpm_moms.marr, s->fluid, - s->pkpm_p_ij, s->pkpm_prim, - s->pkpm_accel, s->fluid_io, s->pkpm_vars_io); + pkpm_species_calc_pkpm_update_vars(app, s, s->f); + gkyl_dg_calc_pkpm_vars_io( + s->calc_pkpm_vars, &app->local, s->pkpm_moms.marr, s->fluid, s->pkpm_p_ij, s->pkpm_prim, + s->pkpm_accel, s->fluid_io, s->pkpm_vars_io + ); // copy data from device to host before writing it out if (app->use_gpu) { @@ -545,36 +521,31 @@ gkyl_pkpm_app_write_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame) gkyl_array_copy(s->pkpm_vars_io_host, s->pkpm_vars_io); } - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, s->pkpm_moms_diag.marr_host, fileNm); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, s->fluid_io_host, fileNm_fluid); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, s->pkpm_vars_io_host, fileNm_pkpm_vars); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, s->pkpm_moms_diag.marr_host, fileNm); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, s->fluid_io_host, fileNm_fluid); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, s->pkpm_vars_io_host, fileNm_pkpm_vars + ); - pkpm_array_meta_release(mt); + pkpm_array_meta_release(mt); } -void -gkyl_pkpm_app_write_integrated_mom(gkyl_pkpm_app *app) +void gkyl_pkpm_app_write_integrated_mom(gkyl_pkpm_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { int rank; gkyl_comm_get_rank(app->comm, &rank); if (rank == 0) { // write out integrated diagnostic moments const char *fmt = "%s-%s-%s.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, app->species[i].info.name, - "imom"); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, app->species[i].info.name, - "imom"); + int sz = gkyl_calc_strlen(fmt, app->name, app->species[i].info.name, "imom"); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf(fileNm, sizeof fileNm, fmt, app->name, app->species[i].info.name, "imom"); if (app->species[i].is_first_integ_write_call) { gkyl_dynvec_write(app->species[i].integ_diag, fileNm); app->species[i].is_first_integ_write_call = false; - } - else { + } else { gkyl_dynvec_awrite(app->species[i].integ_diag, fileNm); } } @@ -582,27 +553,23 @@ gkyl_pkpm_app_write_integrated_mom(gkyl_pkpm_app *app) } } -void -gkyl_pkpm_app_write_integrated_L2_f(gkyl_pkpm_app* app) +void gkyl_pkpm_app_write_integrated_L2_f(gkyl_pkpm_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { int rank; gkyl_comm_get_rank(app->comm, &rank); if (rank == 0) { // write out integrated L^2 const char *fmt = "%s-%s-%s.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, app->species[i].info.name, - "L2"); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, app->species[i].info.name, - "L2"); + int sz = gkyl_calc_strlen(fmt, app->name, app->species[i].info.name, "L2"); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf(fileNm, sizeof fileNm, fmt, app->name, app->species[i].info.name, "L2"); if (app->species[i].is_first_integ_L2_write_call) { // write to a new file (this ensure previous output is removed) gkyl_dynvec_write(app->species[i].integ_L2_f, fileNm); app->species[i].is_first_integ_L2_write_call = false; - } - else { + } else { // append to existing file gkyl_dynvec_awrite(app->species[i].integ_L2_f, fileNm); } @@ -611,13 +578,12 @@ gkyl_pkpm_app_write_integrated_L2_f(gkyl_pkpm_app* app) } } -void -gkyl_pkpm_app_write_field_energy(gkyl_pkpm_app* app) +void gkyl_pkpm_app_write_field_energy(gkyl_pkpm_app *app) { // write out diagnostic moments const char *fmt = "%s-field-energy.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name); int rank; @@ -628,8 +594,7 @@ gkyl_pkpm_app_write_field_energy(gkyl_pkpm_app* app) // write to a new file (this ensure previous output is removed) gkyl_dynvec_write(app->field->integ_energy, fileNm); app->field->is_first_energy_write_call = false; - } - else { + } else { // append to existing file gkyl_dynvec_awrite(app->field->integ_energy, fileNm); } @@ -637,18 +602,25 @@ gkyl_pkpm_app_write_field_energy(gkyl_pkpm_app* app) gkyl_dynvec_clear(app->field->integ_energy); } -void -gkyl_pkpm_app_train(gkyl_pkpm_app* app, double tm, int frame, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void gkyl_pkpm_app_train( + gkyl_pkpm_app *app, double tm, int frame, struct gkyl_kann_net **ann, int num_input_moms, + int *input_moms, int num_output_moms, int *output_moms, struct gkyl_kn_vec *input_data, + struct gkyl_kn_vec *output_data +) { for (int i = 0; i < app->num_species; i++) { - gkyl_pkpm_app_train_mom(app, i, tm, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train_mom( + app, i, tm, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -gkyl_pkpm_app_train_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void gkyl_pkpm_app_train_mom( + gkyl_pkpm_app *app, int sidx, double tm, int frame, struct gkyl_kann_net **ann, + int num_input_moms, int *input_moms, int num_output_moms, int *output_moms, + struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { struct pkpm_species *s = &app->species[sidx]; pkpm_species_moment_calc(&s->pkpm_moms_diag, s->local, app->local, s->f); @@ -660,8 +632,7 @@ gkyl_pkpm_app_train_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, stru int cell_count = 0; if (app->cdim == 1) { cell_count = app->grid.cells[0]; - } - else if (app->cdim == 2) { + } else if (app->cdim == 2) { cell_count = app->grid.cells[0] * app->grid.cells[1]; } @@ -678,15 +649,13 @@ gkyl_pkpm_app_train_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, stru if (app->cdim == 1) { input_data->vals[count][i * 2] = (float)pkpm_moms_diag_d[input_moms[i] * 2]; input_data->vals[count][(i * 2) + 1] = (float)pkpm_moms_diag_d[(input_moms[i] * 2) + 1]; - } - else if (app->cdim == 2) { + } else if (app->cdim == 2) { input_data->vals[count][i * 4] = (float)pkpm_moms_diag_d[input_moms[i] * 4]; input_data->vals[count][(i * 4) + 1] = (float)pkpm_moms_diag_d[(input_moms[i] * 4) + 1]; input_data->vals[count][(i * 4) + 2] = (float)pkpm_moms_diag_d[(input_moms[i] * 4) + 2]; input_data->vals[count][(i * 4) + 3] = (float)pkpm_moms_diag_d[(input_moms[i] * 4) + 3]; } - } - else if (app->poly_order == 2) { + } else if (app->poly_order == 2) { input_data->vals[count][i * 3] = (float)pkpm_moms_diag_d[input_moms[i] * 3]; input_data->vals[count][(i * 3) + 1] = (float)pkpm_moms_diag_d[(input_moms[i] * 3) + 1]; input_data->vals[count][(i * 3) + 2] = (float)pkpm_moms_diag_d[(input_moms[i] * 3) + 2]; @@ -698,15 +667,13 @@ gkyl_pkpm_app_train_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, stru if (app->cdim == 1) { output_data->vals[count][i * 2] = (float)pkpm_moms_diag_d[output_moms[i] * 2]; output_data->vals[count][(i * 2) + 1] = (float)pkpm_moms_diag_d[(output_moms[i] * 2) + 1]; - } - else if (app->cdim == 2) { + } else if (app->cdim == 2) { output_data->vals[count][i * 4] = (float)pkpm_moms_diag_d[output_moms[i] * 4]; output_data->vals[count][(i * 4) + 1] = (float)pkpm_moms_diag_d[(output_moms[i] * 4) + 1]; output_data->vals[count][(i * 4) + 2] = (float)pkpm_moms_diag_d[(output_moms[i] * 4) + 2]; output_data->vals[count][(i * 4) + 3] = (float)pkpm_moms_diag_d[(output_moms[i] * 4) + 3]; } - } - else if (app->poly_order == 2) { + } else if (app->poly_order == 2) { output_data->vals[count][i * 3] = (float)pkpm_moms_diag_d[output_moms[i] * 3]; output_data->vals[count][(i * 3) + 1] = (float)pkpm_moms_diag_d[(output_moms[i] * 3) + 1]; output_data->vals[count][(i * 3) + 2] = (float)pkpm_moms_diag_d[(output_moms[i] * 3) + 2]; @@ -721,7 +688,7 @@ gkyl_pkpm_app_train_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, stru .mini_size = 64, .max_epoch = 50, .max_drop_streak = 10, - .frac_val = 0.1f, + .frac_val = 0.1f }; if (gkyl_kann_net_is_cu_dev(ann[sidx])) { @@ -735,22 +702,21 @@ gkyl_pkpm_app_train_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, stru gkyl_kn_vec_release(input_data_cu); gkyl_kn_vec_release(output_data_cu); - } - else { + } else { gkyl_kann_net_train_fnn1(ann[sidx], ¶ms, input_data, output_data); } } -void -gkyl_pkpm_app_write_nn(gkyl_pkpm_app* app, double tm, int frame, struct gkyl_kann_net** ann) +void gkyl_pkpm_app_write_nn(gkyl_pkpm_app *app, double tm, int frame, struct gkyl_kann_net **ann) { for (int i = 0; i < app->num_species; i++) { gkyl_pkpm_app_write_nn_mom(app, i, tm, frame, ann); } } -void -gkyl_pkpm_app_write_nn_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struct gkyl_kann_net** ann) +void gkyl_pkpm_app_write_nn_mom( + gkyl_pkpm_app *app, int sidx, double tm, int frame, struct gkyl_kann_net **ann +) { struct pkpm_species *s = &app->species[sidx]; @@ -762,27 +728,29 @@ gkyl_pkpm_app_write_nn_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, s gkyl_kann_net_save(ann[sidx], fileNm); } -void -gkyl_pkpm_app_test(gkyl_pkpm_app* app, double tm, int frame, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void gkyl_pkpm_app_test( + gkyl_pkpm_app *app, double tm, int frame, struct gkyl_kann_net **ann, int num_input_moms, + int *input_moms, int num_output_moms, int *output_moms, struct gkyl_kn_vec *input_data_real, + struct gkyl_kn_vec *output_data_real, struct gkyl_kn_vec *output_data_predicted +) { for (int i = 0; i < app->num_species; i++) { - gkyl_pkpm_app_test_mom(app, i, tm, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, - input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test_mom( + app, i, tm, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -void -gkyl_pkpm_app_test_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void gkyl_pkpm_app_test_mom( + gkyl_pkpm_app *app, int sidx, double tm, int frame, struct gkyl_kann_net **ann, + int num_input_moms, int *input_moms, int num_output_moms, int *output_moms, + struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { - struct gkyl_msgpack_data *mt = pkpm_array_meta_new( (struct pkpm_output_meta) { - .frame = frame, - .stime = tm, - .poly_order = app->poly_order, - .basis_type = app->confBasis.id - } - ); + struct gkyl_msgpack_data *mt = pkpm_array_meta_new((struct pkpm_output_meta + ){.frame = frame, .stime = tm, .poly_order = app->poly_order, .basis_type = app->confBasis.id}); struct pkpm_species *s = &app->species[sidx]; pkpm_species_moment_calc(&s->pkpm_moms_diag, s->local, app->local, s->f); @@ -803,19 +771,23 @@ gkyl_pkpm_app_test_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struc if (app->poly_order == 1) { if (app->cdim == 1) { input_data_real->vals[count][i * 2] = (float)pkpm_moms_diag_d[input_moms[i] * 2]; - input_data_real->vals[count][(i * 2) + 1] = (float)pkpm_moms_diag_d[(input_moms[i] * 2) + 1]; - } - else if (app->cdim == 2) { + input_data_real->vals[count][(i * 2) + 1] = + (float)pkpm_moms_diag_d[(input_moms[i] * 2) + 1]; + } else if (app->cdim == 2) { input_data_real->vals[count][i * 4] = (float)pkpm_moms_diag_d[input_moms[i] * 4]; - input_data_real->vals[count][(i * 4) + 1] = (float)pkpm_moms_diag_d[(input_moms[i] * 4) + 1]; - input_data_real->vals[count][(i * 4) + 2] = (float)pkpm_moms_diag_d[(input_moms[i] * 4) + 2]; - input_data_real->vals[count][(i * 4) + 3] = (float)pkpm_moms_diag_d[(input_moms[i] * 4) + 3]; + input_data_real->vals[count][(i * 4) + 1] = + (float)pkpm_moms_diag_d[(input_moms[i] * 4) + 1]; + input_data_real->vals[count][(i * 4) + 2] = + (float)pkpm_moms_diag_d[(input_moms[i] * 4) + 2]; + input_data_real->vals[count][(i * 4) + 3] = + (float)pkpm_moms_diag_d[(input_moms[i] * 4) + 3]; } - } - else if (app->poly_order == 2) { + } else if (app->poly_order == 2) { input_data_real->vals[count][i * 3] = (float)pkpm_moms_diag_d[input_moms[i] * 3]; - input_data_real->vals[count][(i * 3) + 1] = (float)pkpm_moms_diag_d[(input_moms[i] * 3) + 1]; - input_data_real->vals[count][(i * 3) + 2] = (float)pkpm_moms_diag_d[(input_moms[i] * 3) + 2]; + input_data_real->vals[count][(i * 3) + 1] = + (float)pkpm_moms_diag_d[(input_moms[i] * 3) + 1]; + input_data_real->vals[count][(i * 3) + 2] = + (float)pkpm_moms_diag_d[(input_moms[i] * 3) + 2]; } } @@ -823,19 +795,23 @@ gkyl_pkpm_app_test_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struc if (app->poly_order == 1) { if (app->cdim == 1) { output_data_real->vals[count][i * 2] = (float)pkpm_moms_diag_d[output_moms[i] * 2]; - output_data_real->vals[count][(i * 2) + 1] = (float)pkpm_moms_diag_d[(output_moms[i] * 2) + 1]; - } - else if (app->cdim == 2) { + output_data_real->vals[count][(i * 2) + 1] = + (float)pkpm_moms_diag_d[(output_moms[i] * 2) + 1]; + } else if (app->cdim == 2) { output_data_real->vals[count][i * 4] = (float)pkpm_moms_diag_d[output_moms[i] * 4]; - output_data_real->vals[count][(i * 4) + 1] = (float)pkpm_moms_diag_d[(output_moms[i] * 4) + 1]; - output_data_real->vals[count][(i * 4) + 2] = (float)pkpm_moms_diag_d[(output_moms[i] * 4) + 2]; - output_data_real->vals[count][(i * 4) + 3] = (float)pkpm_moms_diag_d[(output_moms[i] * 4) + 3]; + output_data_real->vals[count][(i * 4) + 1] = + (float)pkpm_moms_diag_d[(output_moms[i] * 4) + 1]; + output_data_real->vals[count][(i * 4) + 2] = + (float)pkpm_moms_diag_d[(output_moms[i] * 4) + 2]; + output_data_real->vals[count][(i * 4) + 3] = + (float)pkpm_moms_diag_d[(output_moms[i] * 4) + 3]; } - } - else if (app->poly_order == 2) { + } else if (app->poly_order == 2) { output_data_real->vals[count][i * 3] = (float)pkpm_moms_diag_d[output_moms[i] * 3]; - output_data_real->vals[count][(i * 3) + 1] = (float)pkpm_moms_diag_d[(output_moms[i] * 3) + 1]; - output_data_real->vals[count][(i * 3) + 2] = (float)pkpm_moms_diag_d[(output_moms[i] * 3) + 2]; + output_data_real->vals[count][(i * 3) + 1] = + (float)pkpm_moms_diag_d[(output_moms[i] * 3) + 1]; + output_data_real->vals[count][(i * 3) + 2] = + (float)pkpm_moms_diag_d[(output_moms[i] * 3) + 2]; } } @@ -845,8 +821,10 @@ gkyl_pkpm_app_test_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struc // Batched inference over all sampled cells. On GPU, stage the input and // predicted output through device kn_vecs. if (gkyl_kann_net_is_cu_dev(ann[sidx])) { - struct gkyl_kn_vec *input_data_cu = gkyl_kn_vec_cu_dev_new(input_data_real->nvec, input_data_real->N); - struct gkyl_kn_vec *output_data_cu = gkyl_kn_vec_cu_dev_new(output_data_predicted->nvec, output_data_predicted->N); + struct gkyl_kn_vec *input_data_cu = + gkyl_kn_vec_cu_dev_new(input_data_real->nvec, input_data_real->N); + struct gkyl_kn_vec *output_data_cu = + gkyl_kn_vec_cu_dev_new(output_data_predicted->nvec, output_data_predicted->N); gkyl_kn_vec_copy(input_data_cu, input_data_real); gkyl_kann_net_apply(ann[sidx], input_data_cu, output_data_cu); @@ -854,8 +832,7 @@ gkyl_pkpm_app_test_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struc gkyl_kn_vec_copy(output_data_predicted, output_data_cu); gkyl_kn_vec_release(input_data_cu); gkyl_kn_vec_release(output_data_cu); - } - else { + } else { gkyl_kann_net_apply(ann[sidx], input_data_real, output_data_predicted); } @@ -870,20 +847,27 @@ gkyl_pkpm_app_test_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struc for (int i = 0; i < num_output_moms; i++) { if (app->poly_order == 1) { if (app->cdim == 1) { - pkpm_moms_diag_d_new[output_moms[i] * 2] = (double)output_data_predicted->vals[count_new][i * 2]; - pkpm_moms_diag_d_new[(output_moms[i] * 2) + 1] = (double)output_data_predicted->vals[count_new][(i * 2) + 1]; - } - else if (app->cdim == 2) { - pkpm_moms_diag_d_new[output_moms[i] * 4] = (double)output_data_predicted->vals[count_new][i * 4]; - pkpm_moms_diag_d_new[(output_moms[i] * 4) + 1] = (double)output_data_predicted->vals[count_new][(i * 4) + 1]; - pkpm_moms_diag_d_new[(output_moms[i] * 4) + 2] = (double)output_data_predicted->vals[count_new][(i * 4) + 2]; - pkpm_moms_diag_d_new[(output_moms[i] * 4) + 3] = (double)output_data_predicted->vals[count_new][(i * 4) + 3]; + pkpm_moms_diag_d_new[output_moms[i] * 2] = + (double)output_data_predicted->vals[count_new][i * 2]; + pkpm_moms_diag_d_new[(output_moms[i] * 2) + 1] = + (double)output_data_predicted->vals[count_new][(i * 2) + 1]; + } else if (app->cdim == 2) { + pkpm_moms_diag_d_new[output_moms[i] * 4] = + (double)output_data_predicted->vals[count_new][i * 4]; + pkpm_moms_diag_d_new[(output_moms[i] * 4) + 1] = + (double)output_data_predicted->vals[count_new][(i * 4) + 1]; + pkpm_moms_diag_d_new[(output_moms[i] * 4) + 2] = + (double)output_data_predicted->vals[count_new][(i * 4) + 2]; + pkpm_moms_diag_d_new[(output_moms[i] * 4) + 3] = + (double)output_data_predicted->vals[count_new][(i * 4) + 3]; } - } - else if (app->poly_order == 2) { - pkpm_moms_diag_d_new[output_moms[i] * 3] = (double)output_data_predicted->vals[count_new][i * 3]; - pkpm_moms_diag_d_new[(output_moms[i] * 3) + 1] = (double)output_data_predicted->vals[count_new][(i * 3) + 1]; - pkpm_moms_diag_d_new[(output_moms[i] * 3) + 2] = (double)output_data_predicted->vals[count_new][(i * 3) + 2]; + } else if (app->poly_order == 2) { + pkpm_moms_diag_d_new[output_moms[i] * 3] = + (double)output_data_predicted->vals[count_new][i * 3]; + pkpm_moms_diag_d_new[(output_moms[i] * 3) + 1] = + (double)output_data_predicted->vals[count_new][(i * 3) + 1]; + pkpm_moms_diag_d_new[(output_moms[i] * 3) + 2] = + (double)output_data_predicted->vals[count_new][(i * 3) + 2]; } } @@ -908,20 +892,26 @@ gkyl_pkpm_app_test_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struc for (int i = 0; i < num_output_moms; i++) { if (app->poly_order == 1) { if (app->cdim == 1) { - pkpm_moms_diag_d_old[output_moms[i] * 2] = (double)output_data_real->vals[count_old][i * 2]; - pkpm_moms_diag_d_old[(output_moms[i] * 2) + 1] = (double)output_data_real->vals[count_old][(i * 2) + 1]; - } - else if (app->cdim == 2) { - pkpm_moms_diag_d_old[output_moms[i] * 4] = (double)output_data_real->vals[count_old][i * 4]; - pkpm_moms_diag_d_old[(output_moms[i] * 4) + 1] = (double)output_data_real->vals[count_old][(i * 4) + 1]; - pkpm_moms_diag_d_old[(output_moms[i] * 4) + 2] = (double)output_data_real->vals[count_old][(i * 4) + 2]; - pkpm_moms_diag_d_old[(output_moms[i] * 4) + 3] = (double)output_data_real->vals[count_old][(i * 4) + 3]; + pkpm_moms_diag_d_old[output_moms[i] * 2] = + (double)output_data_real->vals[count_old][i * 2]; + pkpm_moms_diag_d_old[(output_moms[i] * 2) + 1] = + (double)output_data_real->vals[count_old][(i * 2) + 1]; + } else if (app->cdim == 2) { + pkpm_moms_diag_d_old[output_moms[i] * 4] = + (double)output_data_real->vals[count_old][i * 4]; + pkpm_moms_diag_d_old[(output_moms[i] * 4) + 1] = + (double)output_data_real->vals[count_old][(i * 4) + 1]; + pkpm_moms_diag_d_old[(output_moms[i] * 4) + 2] = + (double)output_data_real->vals[count_old][(i * 4) + 2]; + pkpm_moms_diag_d_old[(output_moms[i] * 4) + 3] = + (double)output_data_real->vals[count_old][(i * 4) + 3]; } - } - else if (app->poly_order == 2) { + } else if (app->poly_order == 2) { pkpm_moms_diag_d_old[output_moms[i] * 3] = (double)output_data_real->vals[count_old][i * 3]; - pkpm_moms_diag_d_old[(output_moms[i] * 3) + 1] = (double)output_data_real->vals[count_old][(i * 3) + 1]; - pkpm_moms_diag_d_old[(output_moms[i] * 3) + 2] = (double)output_data_real->vals[count_old][(i * 3) + 2]; + pkpm_moms_diag_d_old[(output_moms[i] * 3) + 1] = + (double)output_data_real->vals[count_old][(i * 3) + 1]; + pkpm_moms_diag_d_old[(output_moms[i] * 3) + 2] = + (double)output_data_real->vals[count_old][(i * 3) + 2]; } } @@ -929,8 +919,7 @@ gkyl_pkpm_app_test_mom(gkyl_pkpm_app* app, int sidx, double tm, int frame, struc } } -struct gkyl_update_status -gkyl_pkpm_update(gkyl_pkpm_app* app, double dt) +struct gkyl_update_status gkyl_pkpm_update(gkyl_pkpm_app *app, double dt) { app->stat.nup += 1; @@ -941,13 +930,13 @@ gkyl_pkpm_update(gkyl_pkpm_app* app, double dt) app->stat.total_tm += gkyl_time_diff_now_sec(wst); // Check for any CUDA errors during time step - if (app->use_gpu) + if (app->use_gpu) { checkCuda(cudaGetLastError()); + } return status; } -struct gkyl_pkpm_stat -gkyl_pkpm_app_stat(gkyl_pkpm_app* app) +struct gkyl_pkpm_stat gkyl_pkpm_app_stat(gkyl_pkpm_app *app) { pkpm_species_tm(app); pkpm_species_coll_tm(app); @@ -955,18 +944,19 @@ gkyl_pkpm_app_stat(gkyl_pkpm_app* app) } static void -range_stat_write(gkyl_pkpm_app* app, const char *nm, const struct gkyl_range *r, FILE *fp) +range_stat_write(gkyl_pkpm_app *app, const char *nm, const struct gkyl_range *r, FILE *fp) { gkyl_pkpm_app_cout(app, fp, " %s_cells : [ ", nm); - for (int i=0; indim; ++i) + for (int i = 0; i < r->ndim; ++i) { gkyl_pkpm_app_cout(app, fp, " %d, ", gkyl_range_shape(r, i)); + } gkyl_pkpm_app_cout(app, fp, " ],\n"); } // ensure stats across processors are made consistent -static void -comm_reduce_app_stat(const gkyl_pkpm_app* app, - const struct gkyl_pkpm_stat *local, struct gkyl_pkpm_stat *global) +static void comm_reduce_app_stat( + const gkyl_pkpm_app *app, const struct gkyl_pkpm_stat *local, struct gkyl_pkpm_stat *global +) { int comm_sz; gkyl_comm_get_size(app->comm, &comm_sz); @@ -991,14 +981,30 @@ comm_reduce_app_stat(const gkyl_pkpm_app* app, global->nup = l_red_global[NUP]; global->nfeuler = l_red_global[NFEULER]; global->nstage_2_fail = l_red_global[NSTAGE_2_FAIL]; - global->nstage_3_fail = l_red_global[NSTAGE_3_FAIL]; + global->nstage_3_fail = l_red_global[NSTAGE_3_FAIL]; enum { - TOTAL_TM, RK3_TM, PKPM_EM_TM, INIT_SPECIES_TM, INIT_FLUID_SPECIES_TM, INIT_FIELD_TM, - SPECIES_RHS_TM, FLUID_SPECIES_RHS_TM, SPECIES_COLL_MOM_TM, - SPECIES_COL_TM, SPECIES_PKPM_VARS_TM, FIELD_RHS_TM, FIELD_EM_VARS_TM, CURRENT_TM, - SPECIES_OMEGA_CFL_TM, FIELD_OMEGA_CFL_TM, DIAG_TM, IO_TM, - SPECIES_BC_TM, FLUID_SPECIES_BC_TM, FIELD_BC_TM, + TOTAL_TM, + RK3_TM, + PKPM_EM_TM, + INIT_SPECIES_TM, + INIT_FLUID_SPECIES_TM, + INIT_FIELD_TM, + SPECIES_RHS_TM, + FLUID_SPECIES_RHS_TM, + SPECIES_COLL_MOM_TM, + SPECIES_COL_TM, + SPECIES_PKPM_VARS_TM, + FIELD_RHS_TM, + FIELD_EM_VARS_TM, + CURRENT_TM, + SPECIES_OMEGA_CFL_TM, + FIELD_OMEGA_CFL_TM, + DIAG_TM, + IO_TM, + SPECIES_BC_TM, + FLUID_SPECIES_BC_TM, + FIELD_BC_TM, D_END }; @@ -1028,7 +1034,7 @@ comm_reduce_app_stat(const gkyl_pkpm_app* app, double d_red_global[D_END]; gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, D_END, d_red, d_red_global); - + global->total_tm = d_red_global[TOTAL_TM]; global->rk3_tm = d_red_global[RK3_TM]; global->pkpm_em_tm = d_red_global[PKPM_EM_TM]; @@ -1053,23 +1059,28 @@ comm_reduce_app_stat(const gkyl_pkpm_app* app, // misc data needing reduction - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_2_dt_diff, - global->stage_2_dt_diff); - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_3_dt_diff, - global->stage_3_dt_diff); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_2_dt_diff, global->stage_2_dt_diff + ); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_3_dt_diff, global->stage_3_dt_diff + ); - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, GKYL_MAX_SPECIES, local->species_lbo_coll_drag_tm, - global->species_lbo_coll_drag_tm); - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, GKYL_MAX_SPECIES, local->species_lbo_coll_diff_tm, - global->species_lbo_coll_diff_tm); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, GKYL_MAX_SPECIES, local->species_lbo_coll_drag_tm, + global->species_lbo_coll_drag_tm + ); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, GKYL_MAX_SPECIES, local->species_lbo_coll_diff_tm, + global->species_lbo_coll_diff_tm + ); } -void -gkyl_pkpm_app_stat_write(gkyl_pkpm_app* app) +void gkyl_pkpm_app_stat_write(gkyl_pkpm_app *app) { const char *fmt = "%s-%s"; int sz = gkyl_calc_strlen(fmt, app->name, "stat.json"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, "stat.json"); int num_ranks; @@ -1082,35 +1093,41 @@ gkyl_pkpm_app_stat_write(gkyl_pkpm_app* app) pkpm_species_coll_tm(app); pkpm_species_tm(app); - struct gkyl_pkpm_stat stat = { }; + struct gkyl_pkpm_stat stat = {}; comm_reduce_app_stat(app, &app->stat, &stat); - + int rank; gkyl_comm_get_rank(app->comm, &rank); // append to existing file so we have a history of different runs FILE *fp = 0; - if (rank == 0) fp = fopen(fileNm, "a"); + if (rank == 0) { + fp = fopen(fileNm, "a"); + } gkyl_pkpm_app_cout(app, fp, "{\n"); - if (strftime(buff, sizeof buff, "%c", &curr_tm)) + if (strftime(buff, sizeof buff, "%c", &curr_tm)) { gkyl_pkpm_app_cout(app, fp, " date : %s,\n", buff); + } gkyl_pkpm_app_cout(app, fp, " use_gpu : %d,\n", stat.use_gpu); - gkyl_pkpm_app_cout(app, fp, " num_ranks : %d,\n", num_ranks); - - for (int s=0; snum_species; ++s) + gkyl_pkpm_app_cout(app, fp, " num_ranks : %d,\n", num_ranks); + + for (int s = 0; s < app->num_species; ++s) { range_stat_write(app, app->species[s].info.name, &app->species[s].global, fp); - + } + gkyl_pkpm_app_cout(app, fp, " nup : %ld,\n", stat.nup); gkyl_pkpm_app_cout(app, fp, " nfeuler : %ld,\n", stat.nfeuler); gkyl_pkpm_app_cout(app, fp, " nstage_2_fail : %ld,\n", stat.nstage_2_fail); gkyl_pkpm_app_cout(app, fp, " nstage_3_fail : %ld,\n", stat.nstage_3_fail); - gkyl_pkpm_app_cout(app, fp, " stage_2_dt_diff : [ %lg, %lg ],\n", - stat.stage_2_dt_diff[0], stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, fp, " stage_3_dt_diff : [ %lg, %lg ],\n", - stat.stage_3_dt_diff[0], stat.stage_3_dt_diff[1]); + gkyl_pkpm_app_cout( + app, fp, " stage_2_dt_diff : [ %lg, %lg ],\n", stat.stage_2_dt_diff[0], stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, fp, " stage_3_dt_diff : [ %lg, %lg ],\n", stat.stage_3_dt_diff[0], stat.stage_3_dt_diff[1] + ); gkyl_pkpm_app_cout(app, fp, " total_tm : %lg,\n", stat.total_tm); gkyl_pkpm_app_cout(app, fp, " rk3_tm : %lg,\n", stat.rk3_tm); @@ -1119,20 +1136,22 @@ gkyl_pkpm_app_stat_write(gkyl_pkpm_app* app) } gkyl_pkpm_app_cout(app, fp, " init_species_tm : %lg,\n", stat.init_species_tm); gkyl_pkpm_app_cout(app, fp, " init_field_tm : %lg,\n", stat.init_field_tm); - + gkyl_pkpm_app_cout(app, fp, " species_rhs_tm : %lg,\n", stat.species_rhs_tm); gkyl_pkpm_app_cout(app, fp, " species_bc_tm : %lg,\n", stat.species_bc_tm); gkyl_pkpm_app_cout(app, fp, " species_pkpm_vars_tm : %lg,\n", stat.species_pkpm_vars_tm); gkyl_pkpm_app_cout(app, fp, " species_coll_mom_tm : %lg,\n", stat.species_coll_mom_tm); gkyl_pkpm_app_cout(app, fp, " species_coll_tm : %lg,\n", stat.species_coll_tm); - for (int s=0; snum_species; ++s) { - gkyl_pkpm_app_cout(app, fp, " species_coll_drag_tm[%d] : %lg,\n", s, - stat.species_lbo_coll_drag_tm[s]); - gkyl_pkpm_app_cout(app, fp, " species_coll_diff_tm[%d] : %lg,\n", s, - stat.species_lbo_coll_diff_tm[s]); + for (int s = 0; s < app->num_species; ++s) { + gkyl_pkpm_app_cout( + app, fp, " species_coll_drag_tm[%d] : %lg,\n", s, stat.species_lbo_coll_drag_tm[s] + ); + gkyl_pkpm_app_cout( + app, fp, " species_coll_diff_tm[%d] : %lg,\n", s, stat.species_lbo_coll_diff_tm[s] + ); } - + gkyl_pkpm_app_cout(app, fp, " fluid_species_rhs_tm : %lg,\n", stat.fluid_species_rhs_tm); gkyl_pkpm_app_cout(app, fp, " fluid_species_bc_tm : %lg,\n", stat.fluid_species_bc_tm); @@ -1145,7 +1164,7 @@ gkyl_pkpm_app_stat_write(gkyl_pkpm_app* app) gkyl_pkpm_app_cout(app, fp, " ndiag : %ld,\n", stat.n_diag); gkyl_pkpm_app_cout(app, fp, " diag_tm : %lg\n", stat.diag_tm); - + gkyl_pkpm_app_cout(app, fp, " nspecies_omega_cfl : %ld,\n", stat.n_species_omega_cfl); gkyl_pkpm_app_cout(app, fp, " species_omega_cfl_tm : %lg\n", stat.species_omega_cfl_tm); @@ -1154,48 +1173,44 @@ gkyl_pkpm_app_stat_write(gkyl_pkpm_app* app) gkyl_pkpm_app_cout(app, fp, " nio : %ld,\n", stat.n_io); gkyl_pkpm_app_cout(app, fp, " io_tm : %lg\n", stat.io_tm); - - gkyl_pkpm_app_cout(app, fp, "}\n"); - if (rank == 0) - fclose(fp); + gkyl_pkpm_app_cout(app, fp, "}\n"); + if (rank == 0) { + fclose(fp); + } } -static struct gkyl_app_restart_status -header_from_file(gkyl_pkpm_app *app, const char *fname) +static struct gkyl_app_restart_status header_from_file(gkyl_pkpm_app *app, const char *fname) { - struct gkyl_app_restart_status rstat = { .io_status = 0 }; - + struct gkyl_app_restart_status rstat = {.io_status = 0}; + FILE *fp = 0; - with_file(fp, fname, "r") { + with_file(fp, fname, "r") + { struct gkyl_rect_grid grid; struct gkyl_array_header_info hdr; rstat.io_status = gkyl_grid_sub_array_header_read_fp(&grid, &hdr, fp); if (GKYL_ARRAY_RIO_SUCCESS == rstat.io_status) { - if (hdr.etype != GKYL_DOUBLE) + if (hdr.etype != GKYL_DOUBLE) { rstat.io_status = GKYL_ARRAY_RIO_DATA_MISMATCH; + } } struct pkpm_output_meta meta = - pkpm_meta_from_mpack( &(struct gkyl_msgpack_data) { - .meta = hdr.meta, - .meta_sz = hdr.meta_size - } - ); + pkpm_meta_from_mpack(&(struct gkyl_msgpack_data){.meta = hdr.meta, .meta_sz = hdr.meta_size}); rstat.frame = meta.frame; rstat.stime = meta.stime; gkyl_grid_sub_array_header_release(&hdr); } - + return rstat; } -struct gkyl_app_restart_status -gkyl_pkpm_app_from_file_field(gkyl_pkpm_app *app, const char *fname) +struct gkyl_app_restart_status gkyl_pkpm_app_from_file_field(gkyl_pkpm_app *app, const char *fname) { struct gkyl_app_restart_status rstat = header_from_file(app, fname); @@ -1213,24 +1228,22 @@ gkyl_pkpm_app_from_file_field(gkyl_pkpm_app *app, const char *fname) // Compute external EM field and applied current if present // Computation necessary in case external EM field or applied current // are time-independent and not computed in the time-stepping loop - // since they are not read-in as part of restarts. + // since they are not read-in as part of restarts. pkpm_field_calc_ext_em(app, app->field, rstat.stime); pkpm_field_calc_app_current(app, app->field, rstat.stime); return rstat; } -struct gkyl_app_restart_status -gkyl_pkpm_app_from_file_species(gkyl_pkpm_app *app, int sidx, - const char *fname) +struct gkyl_app_restart_status +gkyl_pkpm_app_from_file_species(gkyl_pkpm_app *app, int sidx, const char *fname) { struct gkyl_app_restart_status rstat = header_from_file(app, fname); struct pkpm_species *s = &app->species[sidx]; - + if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { - rstat.io_status = - gkyl_comm_array_read(s->comm, &s->grid, &s->local, s->f_host, fname); + rstat.io_status = gkyl_comm_array_read(s->comm, &s->grid, &s->local, s->f_host, fname); if (app->use_gpu) { gkyl_array_copy(s->f, s->f_host); } @@ -1242,20 +1255,19 @@ gkyl_pkpm_app_from_file_species(gkyl_pkpm_app *app, int sidx, // Compute applied acceleration if present. // Computation necessary in case applied acceleration // is time-independent and not computed in the time-stepping loop - // since it is not read-in as part of restarts. + // since it is not read-in as part of restarts. pkpm_species_calc_app_accel(app, s, rstat.stime); return rstat; } -struct gkyl_app_restart_status -gkyl_pkpm_app_from_file_fluid_species(gkyl_pkpm_app *app, int sidx, - const char *fname) +struct gkyl_app_restart_status +gkyl_pkpm_app_from_file_fluid_species(gkyl_pkpm_app *app, int sidx, const char *fname) { struct gkyl_app_restart_status rstat = header_from_file(app, fname); struct pkpm_species *s = &app->species[sidx]; - + if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { // Read in the full 10 component fluid array rstat.io_status = @@ -1273,14 +1285,13 @@ gkyl_pkpm_app_from_file_fluid_species(gkyl_pkpm_app *app, int sidx, return rstat; } -struct gkyl_app_restart_status -gkyl_pkpm_app_from_frame_field(gkyl_pkpm_app *app, int frame) +struct gkyl_app_restart_status gkyl_pkpm_app_from_frame_field(gkyl_pkpm_app *app, int frame) { cstr fileNm = cstr_from_fmt("%s-%s_%d.gkyl", app->name, "field", frame); struct gkyl_app_restart_status rstat = gkyl_pkpm_app_from_file_field(app, fileNm.str); app->field->is_first_energy_write_call = false; // append to existing diagnostic cstr_drop(&fileNm); - + return rstat; } @@ -1293,23 +1304,23 @@ gkyl_pkpm_app_from_frame_species(gkyl_pkpm_app *app, int sidx, int frame) struct gkyl_app_restart_status rstat = gkyl_pkpm_app_from_file_species(app, sidx, fileNm.str); cstr fileNm_fluid = cstr_from_fmt("%s-%s_pkpm_fluid_%d.gkyl", app->name, s->info.name, frame); - struct gkyl_app_restart_status rstat_fluid = gkyl_pkpm_app_from_file_fluid_species(app, sidx, fileNm_fluid.str); + struct gkyl_app_restart_status rstat_fluid = + gkyl_pkpm_app_from_file_fluid_species(app, sidx, fileNm_fluid.str); app->species[sidx].is_first_integ_write_call = false; // append to existing diagnostic app->species[sidx].is_first_integ_L2_write_call = false; // append to existing diagnostic cstr_drop(&fileNm); - + return rstat; } -struct gkyl_app_restart_status -gkyl_pkpm_app_read_from_frame(gkyl_pkpm_app *app, int frame) +struct gkyl_app_restart_status gkyl_pkpm_app_read_from_frame(gkyl_pkpm_app *app, int frame) { struct gkyl_app_restart_status rstat; - + rstat = gkyl_pkpm_app_from_frame_field(app, frame); - for (int i=0; inum_species; i++) { + for (int i = 0; i < app->num_species; i++) { rstat = gkyl_pkpm_app_from_frame_species(app, i, frame); } @@ -1317,8 +1328,7 @@ gkyl_pkpm_app_read_from_frame(gkyl_pkpm_app *app, int frame) } // private function to handle variable argument list for printing -static void -v_pkpm_app_cout(const gkyl_pkpm_app* app, FILE *fp, const char *fmt, va_list argp) +static void v_pkpm_app_cout(const gkyl_pkpm_app *app, FILE *fp, const char *fmt, va_list argp) { int rank, r = 0; gkyl_comm_get_rank(app->comm, &rank); @@ -1328,8 +1338,7 @@ v_pkpm_app_cout(const gkyl_pkpm_app* app, FILE *fp, const char *fmt, va_list arg } } -void -gkyl_pkpm_app_cout(const gkyl_pkpm_app* app, FILE *fp, const char *fmt, ...) +void gkyl_pkpm_app_cout(const gkyl_pkpm_app *app, FILE *fp, const char *fmt, ...) { va_list argp; va_start(argp, fmt); @@ -1337,10 +1346,9 @@ gkyl_pkpm_app_cout(const gkyl_pkpm_app* app, FILE *fp, const char *fmt, ...) va_end(argp); } -void -gkyl_pkpm_app_release(gkyl_pkpm_app* app) +void gkyl_pkpm_app_release(gkyl_pkpm_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { pkpm_species_release(app, &app->species[i]); } if (app->num_species > 0) { @@ -1354,7 +1362,7 @@ gkyl_pkpm_app_release(gkyl_pkpm_app* app) gkyl_comm_release(app->comm); gkyl_rect_decomp_release(app->decomp); - + gkyl_wave_geom_release(app->geom); if (app->use_gpu) { diff --git a/pkpm/apps/pkpm_field.c b/pkpm/apps/pkpm_field.c index 804af3d2b7..cbd3c5b829 100644 --- a/pkpm/apps/pkpm_field.c +++ b/pkpm/apps/pkpm_field.c @@ -10,39 +10,38 @@ #include // initialize field object -struct pkpm_field* -pkpm_field_new(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app) +struct pkpm_field *pkpm_field_new(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app) { struct pkpm_field *f = gkyl_malloc(sizeof(struct pkpm_field)); f->info = pkpm->field; // allocate EM arrays - f->em = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); - f->em1 = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); - f->emnew = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); + f->em = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); + f->em1 = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); + f->emnew = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); f->em_energy = mkarr(app->use_gpu, 6, app->local_ext.volume); // allocate a total field variable for methods which require ext_em + em such as b_hat calculation - f->tot_em = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); + f->tot_em = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); - f->em_host = f->em; + f->em_host = f->em; if (app->use_gpu) { - f->em_host = mkarr(false, 8*app->confBasis.num_basis, app->local_ext.volume); + f->em_host = mkarr(false, 8 * app->confBasis.num_basis, app->local_ext.volume); f->em_energy_red = gkyl_cu_malloc(sizeof(double[6])); } // Duplicate copy of EM data in case time step fails. - // Needed because of implicit source split which modifies solution and - // is always successful, so if a time step fails due to the SSP RK3 + // Needed because of implicit source split which modifies solution and + // is always successful, so if a time step fails due to the SSP RK3 // we must restore the old solution before restarting the time step - f->em_dup = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); + f->em_dup = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); f->integ_energy = gkyl_dynvec_new(GKYL_DOUBLE, 6); f->is_first_energy_write_call = true; - // Initialize external EM fields (always used by implicit fluid sources, so always initialize) - f->ext_em = mkarr(app->use_gpu, 6*app->confBasis.num_basis, app->local_ext.volume); + // Initialize external EM fields (always used by implicit fluid sources, so always initialize) + f->ext_em = mkarr(app->use_gpu, 6 * app->confBasis.num_basis, app->local_ext.volume); gkyl_array_clear(f->ext_em, 0.0); f->has_ext_em = false; f->ext_em_evolve = false; @@ -55,14 +54,16 @@ pkpm_field_new(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app) f->ext_em_host = f->ext_em; if (app->use_gpu) { - f->ext_em_host = mkarr(false, 6*app->confBasis.num_basis, app->local_ext.volume); + f->ext_em_host = mkarr(false, 6 * app->confBasis.num_basis, app->local_ext.volume); } - f->ext_em_proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, app->confBasis.poly_order+1, - 6, f->info.ext_em, f->info.ext_em_ctx); + f->ext_em_proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->confBasis.poly_order + 1, 6, f->info.ext_em, + f->info.ext_em_ctx + ); } - // Initialize applied currents (always used by implicit fluid sources, so always initialize) - f->app_current = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); + // Initialize applied currents (always used by implicit fluid sources, so always initialize) + f->app_current = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); gkyl_array_clear(f->app_current, 0.0); f->has_app_current = false; f->app_current_evolve = false; @@ -75,121 +76,136 @@ pkpm_field_new(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app) f->app_current_host = f->app_current; if (app->use_gpu) { - f->app_current_host = mkarr(false, 3*app->confBasis.num_basis, app->local_ext.volume); + f->app_current_host = mkarr(false, 3 * app->confBasis.num_basis, app->local_ext.volume); } - f->app_current_proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, app->confBasis.poly_order+1, - 3, f->info.app_current, f->info.app_current_ctx); + f->app_current_proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->confBasis.poly_order + 1, 3, f->info.app_current, + f->info.app_current_ctx + ); } // allocate cflrate (scalar array) f->cflrate = mkarr(app->use_gpu, 1, app->local_ext.volume); - if (app->use_gpu) + if (app->use_gpu) { f->omegaCfl_ptr = gkyl_cu_malloc(sizeof(double)); - else + } else { f->omegaCfl_ptr = gkyl_malloc(sizeof(double)); + } // equation object - double c = 1/sqrt(f->info.epsilon0*f->info.mu0); + double c = 1 / sqrt(f->info.epsilon0 * f->info.mu0); double ef = f->info.elcErrorSpeedFactor, mf = f->info.mgnErrorSpeedFactor; struct gkyl_dg_eqn *eqn; eqn = gkyl_dg_maxwell_new(&app->confBasis, c, ef, mf, app->use_gpu); - int up_dirs[GKYL_MAX_DIM] = {0, 1, 2}, zero_flux_flags[2*GKYL_MAX_DIM] = {0, 0, 0, 0, 0, 0}; + int up_dirs[GKYL_MAX_DIM] = {0, 1, 2}, zero_flux_flags[2 * GKYL_MAX_DIM] = {0, 0, 0, 0, 0, 0}; // Maxwell solver - f->slvr = gkyl_hyper_dg_new(&app->grid, &app->confBasis, eqn, - app->cdim, up_dirs, zero_flux_flags, 1, app->use_gpu); + f->slvr = gkyl_hyper_dg_new( + &app->grid, &app->confBasis, eqn, app->cdim, up_dirs, zero_flux_flags, 1, app->use_gpu + ); // Allocate arrays for diagonstics/parallel-kinetic-perpendicular-moment arrays: // bvar = magnetic field unit vector (first 3 components) and unit tensor (last 6 components) // ExB = E x B velocity, E x B/|B|^2 f->cell_avg_magB2 = mk_int_arr(app->use_gpu, 1, app->local_ext.volume); - f->bvar = mkarr(app->use_gpu, 9*app->confBasis.num_basis, app->local_ext.volume); + f->bvar = mkarr(app->use_gpu, 9 * app->confBasis.num_basis, app->local_ext.volume); // Surface magnetic field vector organized as: // [bx_xl, bx_xr, bxbx_xl, bxbx_xr, bxby_xl, bxby_xr, bxbz_xl, bxbz_xr, // by_yl, by_yr, bxby_yl, bxby_yr, byby_yl, byby_yr, bybz_yl, bybz_yr, - // bz_zl, bz_zr, bxbz_zl, bxbz_zr, bybz_zl, bybz_zr, bzbz_zl, bzbz_zr] + // bz_zl, bz_zr, bxbz_zl, bxbz_zr, bybz_zl, bybz_zr, bzbz_zl, bzbz_zr] int cdim = app->cdim; - int Ncomp_surf = 2*cdim*4; - int Nbasis_surf = app->confBasis.num_basis/(app->confBasis.poly_order + 1); // *only valid for tensor bases for cdim > 1* - f->bvar_surf = mkarr(app->use_gpu, Ncomp_surf*Nbasis_surf, app->local_ext.volume); + int Ncomp_surf = 2 * cdim * 4; + int Nbasis_surf = app->confBasis.num_basis / + (app->confBasis.poly_order + 1); // *only valid for tensor bases for cdim > 1* + f->bvar_surf = mkarr(app->use_gpu, Ncomp_surf * Nbasis_surf, app->local_ext.volume); // Volume expansion of div(b) f->div_b = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); // Surface expansion of max b penalization for streaming in PKPM system max(|b_i_l|, |b_i_r|) - f->max_b = mkarr(app->use_gpu, 2*cdim*Nbasis_surf, app->local_ext.volume); + f->max_b = mkarr(app->use_gpu, 2 * cdim * Nbasis_surf, app->local_ext.volume); // Check if limiter_fac is specified for adjusting how much diffusion is applied through slope limiter // If not specified, set to 0.0 and updater sets default behavior (1/sqrt(3); see gkyl_dg_calc_em_vars.h) double limiter_fac = f->info.limiter_fac == 0 ? 0.0 : f->info.limiter_fac; f->limit_em = f->info.limit_em; - + struct gkyl_wv_eqn *maxwell = gkyl_wv_maxwell_new(c, ef, mf, app->use_gpu); // Create updaters for bvar (needed by PKPM model) - f->calc_bvar = gkyl_dg_calc_em_vars_new(&app->grid, &app->confBasis, &app->local_ext, - maxwell, app->geom, limiter_fac, 0, app->use_gpu); + f->calc_bvar = gkyl_dg_calc_em_vars_new( + &app->grid, &app->confBasis, &app->local_ext, maxwell, app->geom, limiter_fac, 0, app->use_gpu + ); // Create updaters for limiting EM fields - f->calc_em_vars = gkyl_dg_calc_em_vars_new(&app->grid, &app->confBasis, &app->local_ext, - maxwell, app->geom, limiter_fac, 0, app->use_gpu); + f->calc_em_vars = gkyl_dg_calc_em_vars_new( + &app->grid, &app->confBasis, &app->local_ext, maxwell, app->geom, limiter_fac, 0, app->use_gpu + ); gkyl_wv_eqn_release(maxwell); // determine which directions are not periodic int num_periodic_dir = app->num_periodic_dir, is_np[3] = {1, 1, 1}; - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int dir=0; dircdim; ++dir) { + for (int dir = 0; dir < app->cdim; ++dir) { f->lower_bc[dir] = f->upper_bc[dir] = GKYL_FIELD_COPY; if (is_np[dir]) { const enum gkyl_field_bc_type *bc; - if (dir == 0) + if (dir == 0) { bc = f->info.bcx; - else if (dir == 1) + } else if (dir == 1) { bc = f->info.bcy; - else + } else { bc = f->info.bcz; + } f->lower_bc[dir] = bc[0]; f->upper_bc[dir] = bc[1]; } } - // allocate buffer for applying BCs + // allocate buffer for applying BCs long buff_sz = 0; // compute buffer size needed - for (int dir=0; dircdim; ++dir) { + for (int dir = 0; dir < app->cdim; ++dir) { long vol = GKYL_MAX2(app->lower_skin[dir].volume, app->upper_skin[dir].volume); buff_sz = buff_sz > vol ? buff_sz : vol; } - f->bc_buffer = mkarr(app->use_gpu, 8*app->confBasis.num_basis, buff_sz); - - for (int d=0; dcdim; ++d) { + f->bc_buffer = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, buff_sz); + + for (int d = 0; d < app->cdim; ++d) { // Lower BC updater. Copy BCs by default. enum gkyl_bc_basic_type bctype = GKYL_BC_COPY; - if (f->lower_bc[d] == GKYL_FIELD_COPY) + if (f->lower_bc[d] == GKYL_FIELD_COPY) { bctype = GKYL_BC_COPY; - else if (f->lower_bc[d] == GKYL_FIELD_PEC_WALL) + } else if (f->lower_bc[d] == GKYL_FIELD_PEC_WALL) { bctype = GKYL_BC_MAXWELL_PEC; - else if (f->lower_bc[d] == GKYL_FIELD_SYM_WALL) + } else if (f->lower_bc[d] == GKYL_FIELD_SYM_WALL) { bctype = GKYL_BC_MAXWELL_SYM; - else if (f->lower_bc[d] == GKYL_FIELD_RESERVOIR) + } else if (f->lower_bc[d] == GKYL_FIELD_RESERVOIR) { bctype = GKYL_BC_MAXWELL_RESERVOIR; + } - f->bc_lo[d] = gkyl_bc_basic_new(d, GKYL_LOWER_EDGE, bctype, app->basis_on_dev.confBasis, - &app->lower_skin[d], &app->lower_ghost[d], f->em->ncomp, app->cdim, app->use_gpu); + f->bc_lo[d] = gkyl_bc_basic_new( + d, GKYL_LOWER_EDGE, bctype, app->basis_on_dev.confBasis, &app->lower_skin[d], + &app->lower_ghost[d], f->em->ncomp, app->cdim, app->use_gpu + ); // Upper BC updater. Copy BCs by default. - if (f->upper_bc[d] == GKYL_FIELD_COPY) + if (f->upper_bc[d] == GKYL_FIELD_COPY) { bctype = GKYL_BC_COPY; - else if (f->upper_bc[d] == GKYL_FIELD_PEC_WALL) + } else if (f->upper_bc[d] == GKYL_FIELD_PEC_WALL) { bctype = GKYL_BC_MAXWELL_PEC; - else if (f->upper_bc[d] == GKYL_FIELD_SYM_WALL) + } else if (f->upper_bc[d] == GKYL_FIELD_SYM_WALL) { bctype = GKYL_BC_MAXWELL_SYM; - else if (f->upper_bc[d] == GKYL_FIELD_RESERVOIR) + } else if (f->upper_bc[d] == GKYL_FIELD_RESERVOIR) { bctype = GKYL_BC_MAXWELL_RESERVOIR; + } - f->bc_up[d] = gkyl_bc_basic_new(d, GKYL_UPPER_EDGE, bctype, app->basis_on_dev.confBasis, - &app->upper_skin[d], &app->upper_ghost[d], f->em->ncomp, app->cdim, app->use_gpu); + f->bc_up[d] = gkyl_bc_basic_new( + d, GKYL_UPPER_EDGE, bctype, app->basis_on_dev.confBasis, &app->upper_skin[d], + &app->upper_ghost[d], f->em->ncomp, app->cdim, app->use_gpu + ); } gkyl_dg_eqn_release(eqn); @@ -197,12 +213,12 @@ pkpm_field_new(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app) return f; } -void -pkpm_field_apply_ic(gkyl_pkpm_app *app, struct pkpm_field *field, double t0) +void pkpm_field_apply_ic(gkyl_pkpm_app *app, struct pkpm_field *field, double t0) { int poly_order = app->poly_order; - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - poly_order+1, 8, field->info.init, field->info.ctx); + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, poly_order + 1, 8, field->info.init, field->info.ctx + ); // run updater; need to project onto extended range for ease of handling // subsequent operations over extended range such as magnetic field unit vector computation @@ -211,8 +227,9 @@ pkpm_field_apply_ic(gkyl_pkpm_app *app, struct pkpm_field *field, double t0) gkyl_proj_on_basis_advance(proj, t0, &app->local_ext, field->em_host); gkyl_proj_on_basis_release(proj); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(field->em, field->em_host); + } // pre-compute external EM field and applied current if present // pre-computation necessary in case external EM field or applied current @@ -221,33 +238,31 @@ pkpm_field_apply_ic(gkyl_pkpm_app *app, struct pkpm_field *field, double t0) pkpm_field_calc_app_current(app, field, t0); } -void -pkpm_field_calc_ext_em(gkyl_pkpm_app *app, struct pkpm_field *field, double tm) +void pkpm_field_calc_ext_em(gkyl_pkpm_app *app, struct pkpm_field *field, double tm) { if (field->has_ext_em) { gkyl_proj_on_basis_advance(field->ext_em_proj, tm, &app->local_ext, field->ext_em_host); - if (app->use_gpu) { + if (app->use_gpu) { // note: ext_em_host is same as ext_em when not on GPUs gkyl_array_copy(field->ext_em, field->ext_em_host); } } } -void -pkpm_field_calc_app_current(gkyl_pkpm_app *app, struct pkpm_field *field, double tm) +void pkpm_field_calc_app_current(gkyl_pkpm_app *app, struct pkpm_field *field, double tm) { if (field->has_app_current) { - gkyl_proj_on_basis_advance(field->app_current_proj, tm, &app->local_ext, field->app_current_host); - if (app->use_gpu) { + gkyl_proj_on_basis_advance( + field->app_current_proj, tm, &app->local_ext, field->app_current_host + ); + if (app->use_gpu) { // note: app_current_host is same as app_current when not on GPUs - gkyl_array_copy(field->app_current, field->app_current_host); + gkyl_array_copy(field->app_current, field->app_current_host); } } } -void -pkpm_field_calc_bvar(gkyl_pkpm_app *app, struct pkpm_field *field, - const struct gkyl_array *em) +void pkpm_field_calc_bvar(gkyl_pkpm_app *app, struct pkpm_field *field, const struct gkyl_array *em) { struct timespec tm = gkyl_wall_clock(); @@ -256,22 +271,22 @@ pkpm_field_calc_bvar(gkyl_pkpm_app *app, struct pkpm_field *field, if (field->has_ext_em) { gkyl_array_accumulate_range(field->tot_em, 1.0, field->ext_em, &app->local_ext); } - // Assumes magnetic field boundary conditions applied so magnetic field + // Assumes magnetic field boundary conditions applied so magnetic field // unit vector and unit tensor are defined everywhere in the domain - gkyl_dg_calc_em_vars_advance(field->calc_bvar, field->tot_em, - field->cell_avg_magB2, field->bvar, field->bvar_surf); + gkyl_dg_calc_em_vars_advance( + field->calc_bvar, field->tot_em, field->cell_avg_magB2, field->bvar, field->bvar_surf + ); // Compute div(b) and max_b = max(|b_i_l|, |b_i_r|) gkyl_array_clear(field->div_b, 0.0); // Incremented in each dimension, so clear beforehand - gkyl_dg_calc_em_vars_div_b(field->calc_bvar, &app->local, - field->bvar_surf, field->bvar, - field->max_b, field->div_b); + gkyl_dg_calc_em_vars_div_b( + field->calc_bvar, &app->local, field->bvar_surf, field->bvar, field->max_b, field->div_b + ); app->stat.field_em_vars_tm += gkyl_time_diff_now_sec(tm); } -void -pkpm_field_limiter(gkyl_pkpm_app *app, struct pkpm_field *field, struct gkyl_array *em) +void pkpm_field_limiter(gkyl_pkpm_app *app, struct pkpm_field *field, struct gkyl_array *em) { if (field->limit_em) { struct timespec tm = gkyl_wall_clock(); @@ -286,103 +301,107 @@ pkpm_field_limiter(gkyl_pkpm_app *app, struct pkpm_field *field, struct gkyl_arr } } -void -pkpm_field_explicit_accumulate_current(gkyl_pkpm_app *app, struct pkpm_field *field, - const struct gkyl_array *fluidin[], struct gkyl_array *emout) +void pkpm_field_explicit_accumulate_current( + gkyl_pkpm_app *app, struct pkpm_field *field, const struct gkyl_array *fluidin[], + struct gkyl_array *emout +) { - struct timespec wst = gkyl_wall_clock(); - if (!field->info.is_static) { - for (int i=0; inum_species; ++i) { + struct timespec wst = gkyl_wall_clock(); + if (!field->info.is_static) { + for (int i = 0; i < app->num_species; ++i) { struct pkpm_species *s = &app->species[i]; // Need to divide out the mass in pkpm model since we evolve momentum - double qbymeps = s->info.charge/(s->info.mass*field->info.epsilon0); - gkyl_array_accumulate_range(emout, -qbymeps, fluidin[i], &app->local); - } + double qbymeps = s->info.charge / (s->info.mass * field->info.epsilon0); + gkyl_array_accumulate_range(emout, -qbymeps, fluidin[i], &app->local); + } // Accumulate applied current to electric field terms if (field->has_app_current) { - gkyl_array_accumulate_range(emout, -1.0/field->info.epsilon0, field->app_current, &app->local); + gkyl_array_accumulate_range( + emout, -1.0 / field->info.epsilon0, field->app_current, &app->local + ); } } - app->stat.current_tm += gkyl_time_diff_now_sec(wst); + app->stat.current_tm += gkyl_time_diff_now_sec(wst); } // Compute the RHS for field update, returning maximum stable // time-step. -double -pkpm_field_rhs(gkyl_pkpm_app *app, struct pkpm_field *field, - const struct gkyl_array *em, struct gkyl_array *rhs) +double pkpm_field_rhs( + gkyl_pkpm_app *app, struct pkpm_field *field, const struct gkyl_array *em, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - - double omegaCfl = 1/DBL_MAX; - + + double omegaCfl = 1 / DBL_MAX; + gkyl_array_clear(field->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); if (!field->info.is_static) { gkyl_hyper_dg_advance(field->slvr, &app->local, em, field->cflrate, rhs); - + gkyl_array_reduce_range(field->omegaCfl_ptr, field->cflrate, GKYL_MAX, &app->local); app->stat.n_field_omega_cfl += 1; struct timespec tm = gkyl_wall_clock(); - + double omegaCfl_ho[1]; - if (app->use_gpu) + if (app->use_gpu) { gkyl_cu_memcpy(omegaCfl_ho, field->omegaCfl_ptr, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { omegaCfl_ho[0] = field->omegaCfl_ptr[0]; + } omegaCfl = omegaCfl_ho[0]; app->stat.field_omega_cfl_tm += gkyl_time_diff_now_sec(tm); } app->stat.field_rhs_tm += gkyl_time_diff_now_sec(wst); - - return app->cfl/omegaCfl; + + return app->cfl / omegaCfl; } // Determine which directions are periodic and which directions are not periodic, // and then apply boundary conditions for EM fields -void -pkpm_field_apply_bc(gkyl_pkpm_app *app, const struct pkpm_field *field, struct gkyl_array *f) +void pkpm_field_apply_bc(gkyl_pkpm_app *app, const struct pkpm_field *field, struct gkyl_array *f) { - struct timespec wst = gkyl_wall_clock(); - + struct timespec wst = gkyl_wall_clock(); + int num_periodic_dir = app->num_periodic_dir, cdim = app->cdim; - gkyl_comm_array_per_sync(app->comm, &app->local, &app->local_ext, - num_periodic_dir, app->periodic_dirs, f); - + gkyl_comm_array_per_sync( + app->comm, &app->local, &app->local_ext, num_periodic_dir, app->periodic_dirs, f + ); + int is_np_bc[3] = {1, 1, 1}; // flags to indicate if direction is periodic - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int d=0; dlower_bc[d]) { - case GKYL_FIELD_COPY: - case GKYL_FIELD_PEC_WALL: - case GKYL_FIELD_SYM_WALL: - case GKYL_FIELD_RESERVOIR: - gkyl_bc_basic_advance(field->bc_lo[d], field->bc_buffer, f); - break; - - default: - break; + case GKYL_FIELD_COPY: + case GKYL_FIELD_PEC_WALL: + case GKYL_FIELD_SYM_WALL: + case GKYL_FIELD_RESERVOIR: + gkyl_bc_basic_advance(field->bc_lo[d], field->bc_buffer, f); + break; + + default: + break; } switch (field->upper_bc[d]) { - case GKYL_FIELD_COPY: - case GKYL_FIELD_PEC_WALL: - case GKYL_FIELD_SYM_WALL: - case GKYL_FIELD_RESERVOIR: - gkyl_bc_basic_advance(field->bc_up[d], field->bc_buffer, f); - break; - - default: - break; - } + case GKYL_FIELD_COPY: + case GKYL_FIELD_PEC_WALL: + case GKYL_FIELD_SYM_WALL: + case GKYL_FIELD_RESERVOIR: + gkyl_bc_basic_advance(field->bc_up[d], field->bc_buffer, f); + break; + + default: + break; + } } } @@ -391,38 +410,36 @@ pkpm_field_apply_bc(gkyl_pkpm_app *app, const struct pkpm_field *field, struct g app->stat.field_bc_tm += gkyl_time_diff_now_sec(wst); } -void -pkpm_field_calc_energy(gkyl_pkpm_app *app, double tm, const struct pkpm_field *field) +void pkpm_field_calc_energy(gkyl_pkpm_app *app, double tm, const struct pkpm_field *field) { - for (int i=0; i<6; ++i) + for (int i = 0; i < 6; ++i) { gkyl_dg_calc_l2_range(&app->confBasis, i, field->em_energy, i, field->em, app->local); + } gkyl_array_scale_range(field->em_energy, app->grid.cellVolume, &app->local); - - double energy[6] = { 0.0 }; + + double energy[6] = {0.0}; if (app->use_gpu) { gkyl_array_reduce_range(field->em_energy_red, field->em_energy, GKYL_SUM, &app->local); gkyl_cu_memcpy(energy, field->em_energy_red, sizeof(double[6]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { gkyl_array_reduce_range(energy, field->em_energy, GKYL_SUM, &app->local); } - double energy_global[6] = { 0.0 }; + double energy_global[6] = {0.0}; gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 6, energy, energy_global); - + gkyl_dynvec_append(field->integ_energy, tm, energy_global); } // release resources for field -void -pkpm_field_release(const gkyl_pkpm_app* app, struct pkpm_field *f) +void pkpm_field_release(const gkyl_pkpm_app *app, struct pkpm_field *f) { gkyl_array_release(f->em); gkyl_array_release(f->em1); gkyl_array_release(f->emnew); gkyl_array_release(f->tot_em); gkyl_array_release(f->em_dup); - + gkyl_array_release(f->bc_buffer); gkyl_array_release(f->cflrate); gkyl_array_release(f->em_energy); @@ -457,16 +474,14 @@ pkpm_field_release(const gkyl_pkpm_app* app, struct pkpm_field *f) gkyl_array_release(f->em_host); gkyl_cu_free(f->omegaCfl_ptr); gkyl_cu_free(f->em_energy_red); - } - else { + } else { gkyl_free(f->omegaCfl_ptr); } // Copy BCs are allocated by default. Need to free. - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { gkyl_bc_basic_release(f->bc_lo[d]); gkyl_bc_basic_release(f->bc_up[d]); } gkyl_free(f); } - diff --git a/pkpm/apps/pkpm_fluid_em_coupling.c b/pkpm/apps/pkpm_fluid_em_coupling.c index c48516d048..562a279e40 100644 --- a/pkpm/apps/pkpm_fluid_em_coupling.c +++ b/pkpm/apps/pkpm_fluid_em_coupling.c @@ -8,28 +8,29 @@ #include // initialize implicit fluid-EM coupling object for PKPM system -struct pkpm_fluid_em_coupling* -pkpm_fluid_em_coupling_init(struct gkyl_pkpm_app *app) +struct pkpm_fluid_em_coupling *pkpm_fluid_em_coupling_init(struct gkyl_pkpm_app *app) { struct pkpm_fluid_em_coupling *pkpm_em = gkyl_malloc(sizeof(struct pkpm_fluid_em_coupling)); int num_species = app->num_species; double qbym[GKYL_MAX_SPECIES] = {0.0}; - for (int i=0; ispecies[i]; - qbym[i] = s->info.charge/s->info.mass; + qbym[i] = s->info.charge / s->info.mass; } // Initialize solver - pkpm_em->slvr = gkyl_dg_calc_pkpm_em_coupling_new(&app->confBasis, &app->local, - num_species, qbym, app->field->info.epsilon0, app->field->info.is_static, app->use_gpu); + pkpm_em->slvr = gkyl_dg_calc_pkpm_em_coupling_new( + &app->confBasis, &app->local, num_species, qbym, app->field->info.epsilon0, + app->field->info.is_static, app->use_gpu + ); - return pkpm_em; + return pkpm_em; } -void -pkpm_fluid_em_coupling_update(struct gkyl_pkpm_app *app, struct pkpm_fluid_em_coupling *pkpm_em, - double tcurr, double dt) +void pkpm_fluid_em_coupling_update( + struct gkyl_pkpm_app *app, struct pkpm_fluid_em_coupling *pkpm_em, double tcurr, double dt +) { int num_species = app->num_species; @@ -38,15 +39,15 @@ pkpm_fluid_em_coupling_update(struct gkyl_pkpm_app *app, struct pkpm_fluid_em_co const struct gkyl_array *vlasov_pkpm_moms[GKYL_MAX_SPECIES]; const struct gkyl_array *pkpm_u[GKYL_MAX_SPECIES]; - for (int i=0; ispecies[i]; - // Compute the PKPM moments from the kinetic equation at the current time + // Compute the PKPM moments from the kinetic equation at the current time pkpm_species_moment_calc(&s->pkpm_moms, s->local, app->local, s->f); // Compute the flow velocity at the current time - gkyl_dg_calc_pkpm_vars_u(s->calc_pkpm_vars, - s->pkpm_moms.marr, s->fluid, - s->cell_avg_prim, s->pkpm_u); + gkyl_dg_calc_pkpm_vars_u( + s->calc_pkpm_vars, s->pkpm_moms.marr, s->fluid, s->cell_avg_prim, s->pkpm_u + ); fluids[i] = s->fluid; vlasov_pkpm_moms[i] = s->pkpm_moms.marr; @@ -59,29 +60,31 @@ pkpm_fluid_em_coupling_update(struct gkyl_pkpm_app *app, struct pkpm_fluid_em_co pkpm_field_calc_ext_em(app, app->field, tcurr); } if (app->field->app_current_evolve) { - pkpm_field_calc_app_current(app, app->field, tcurr); + pkpm_field_calc_app_current(app, app->field, tcurr); } - for (int i=0; ispecies[i]; if (s->app_accel_evolve) { pkpm_species_calc_app_accel(app, s, tcurr); - } - app_accels[i] = s->app_accel; + } + app_accels[i] = s->app_accel; } - gkyl_dg_calc_pkpm_em_coupling_advance(pkpm_em->slvr, dt, - app_accels, app->field->ext_em, app->field->app_current, - vlasov_pkpm_moms, pkpm_u, fluids, app->field->em); + gkyl_dg_calc_pkpm_em_coupling_advance( + pkpm_em->slvr, dt, app_accels, app->field->ext_em, app->field->app_current, vlasov_pkpm_moms, + pkpm_u, fluids, app->field->em + ); - for (int i=0; ispecies[i]; pkpm_fluid_species_apply_bc(app, s, fluids[i]); } pkpm_field_apply_bc(app, app->field, app->field->em); } -void -pkpm_fluid_em_coupling_release(struct gkyl_pkpm_app *app, struct pkpm_fluid_em_coupling *pkpm_em) +void pkpm_fluid_em_coupling_release( + struct gkyl_pkpm_app *app, struct pkpm_fluid_em_coupling *pkpm_em +) { gkyl_dg_calc_pkpm_em_coupling_release(pkpm_em->slvr); gkyl_free(pkpm_em); diff --git a/pkpm/apps/pkpm_forward_euler.c b/pkpm/apps/pkpm_forward_euler.c index 0ab78b80b3..a19ddea899 100644 --- a/pkpm/apps/pkpm_forward_euler.c +++ b/pkpm/apps/pkpm_forward_euler.c @@ -1,14 +1,14 @@ #include -// Take a forward Euler step of the PKPM system of equations with the suggested time-step dt. +// Take a forward Euler step of the PKPM system of equations with the suggested time-step dt. // Note: this may not be the actual time-step taken. However, the function will never -// take a time-step larger than dt even if it is allowed by stability. +// take a time-step larger than dt even if it is allowed by stability. // The actual time-step and dt_suggested are returned in the status object. -void -pkpm_forward_euler(gkyl_pkpm_app* app, double tcurr, double dt, - const struct gkyl_array *fin[], const struct gkyl_array *fluidin[], const struct gkyl_array *emin, - struct gkyl_array *fout[], struct gkyl_array *fluidout[], struct gkyl_array *emout, - struct gkyl_update_status *st) +void pkpm_forward_euler( + gkyl_pkpm_app *app, double tcurr, double dt, const struct gkyl_array *fin[], + const struct gkyl_array *fluidin[], const struct gkyl_array *emin, struct gkyl_array *fout[], + struct gkyl_array *fluidout[], struct gkyl_array *emout, struct gkyl_update_status *st +) { app->stat.nfeuler += 1; @@ -22,19 +22,19 @@ pkpm_forward_euler(gkyl_pkpm_app* app, double tcurr, double dt, pkpm_field_calc_ext_em(app, app->field, tcurr); } if (app->field->app_current_evolve && app->use_explicit_source) { - pkpm_field_calc_app_current(app, app->field, tcurr); + pkpm_field_calc_app_current(app, app->field, tcurr); } - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { if (app->species[i].app_accel_evolve && app->use_explicit_source) { pkpm_species_calc_app_accel(app, &app->species[i], tcurr); } } // Compute magnetic field unit vector and tensor, and div(b) - pkpm_field_calc_bvar(app, app->field, emin); + pkpm_field_calc_bvar(app, app->field, emin); // Two separate loops over number of species to compute needed auxiliary quantities. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { // Compute parallel-kinetic-perpendicular moment (pkpm) variables. // These are the coupling moments [rho, p_par, p_perp], the self-consistent // pressure force (div(p_par b_hat)), and the primitive variables @@ -44,11 +44,11 @@ pkpm_forward_euler(gkyl_pkpm_app* app, double tcurr, double dt, pkpm_species_lbo_moms(app, &app->species[i], &app->species[i].lbo, fin[i]); } } - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { // compute necessary moments for cross-species collisions // needs to be done after self-collisions moments, so separate loop over species - if (app->species[i].collision_id == GKYL_LBO_COLLISIONS - && app->species[i].lbo.num_cross_collisions) { + if (app->species[i].collision_id == GKYL_LBO_COLLISIONS && + app->species[i].lbo.num_cross_collisions) { pkpm_species_lbo_cross_moms(app, &app->species[i], &app->species[i].lbo, fin[i]); } // Finish computing parallel-kinetic-perpendicular moment (pkpm) variables. @@ -56,12 +56,13 @@ pkpm_forward_euler(gkyl_pkpm_app* app, double tcurr, double dt, // equation and the source distribution functions for Laguerre couplings. // Needs to be done after all collisional moment computations for collisional sources // in Laguerre couplings. - pkpm_species_calc_pkpm_update_vars(app, &app->species[i], fin[i]); + pkpm_species_calc_pkpm_update_vars(app, &app->species[i], fin[i]); } // compute RHS of pkpm equations - for (int i=0; inum_species; ++i) { - double dt1 = pkpm_species_rhs(app, &app->species[i], fin[i], fluidin[i], emin, fout[i], fluidout[i]); + for (int i = 0; i < app->num_species; ++i) { + double dt1 = + pkpm_species_rhs(app, &app->species[i], fin[i], fluidin[i], emin, fout[i], fluidout[i]); dtmin = fmin(dtmin, dt1); } @@ -72,21 +73,22 @@ pkpm_forward_euler(gkyl_pkpm_app* app, double tcurr, double dt, double dt_max_rel_diff = 0.01; // check if dtmin is slightly smaller than dt. Use dt if it is // (avoids retaking steps if dt changes are very small). - double dt_rel_diff = (dt-dtmin)/dt; - if (dt_rel_diff > 0 && dt_rel_diff < dt_max_rel_diff) + double dt_rel_diff = (dt - dtmin) / dt; + if (dt_rel_diff > 0 && dt_rel_diff < dt_max_rel_diff) { dtmin = dt; + } // compute minimum time-step across all processors double dtmin_local = dtmin, dtmin_global; gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MIN, 1, &dtmin_local, &dtmin_global); dtmin = dtmin_global; - + // don't take a time-step larger that input dt double dta = st->dt_actual = dt < dtmin ? dt : dtmin; st->dt_suggested = dtmin; // complete update of distribution function - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_array_accumulate(gkyl_array_scale(fout[i], dta), 1.0, fin[i]); gkyl_array_accumulate(gkyl_array_scale(fluidout[i], dta), 1.0, fluidin[i]); pkpm_species_apply_bc(app, &app->species[i], fout[i]); diff --git a/pkpm/apps/pkpm_lw.c b/pkpm/apps/pkpm_lw.c index c90be55293..c99a98ec53 100644 --- a/pkpm/apps/pkpm_lw.c +++ b/pkpm/apps/pkpm_lw.c @@ -31,7 +31,7 @@ // Magic IDs for use in distinguishing various species and field types. enum pkpm_magic_ids { PKPM_SPECIES_DEFAULT = 100, // Non-relativistic PKPM species. - PKPM_FIELD_DEFAULT, // Maxwell equations. + PKPM_FIELD_DEFAULT // Maxwell equations. }; /* *************** */ @@ -44,46 +44,49 @@ enum pkpm_magic_ids { // Lua userdata object for constructing species input. struct pkpm_species_lw { int magic; // This must be first element in the struct. - + struct gkyl_pkpm_species pkpm_species; // Input struct to construct species. int vdim; // Velocity space dimensions. bool evolve; // Is this species evolved? bool has_dist_init_func; // Is there a distribution initialization function? - struct lua_func_ctx dist_init_func_ref; // Lua registry reference to distribution initialization function. + struct lua_func_ctx + dist_init_func_ref; // Lua registry reference to distribution initialization function. bool has_fluid_init_func; // Is there a fluid initialization function? struct lua_func_ctx fluid_init_func_ref; // Lua registry reference to fluid initialization function. bool has_applied_acceleration_func; // Is there an applied acceleration initialization function? - struct lua_func_ctx applied_acceleration_func_ref; // Lua registry reference to applied acceleration initialization function. + struct lua_func_ctx + applied_acceleration_func_ref; // Lua registry reference to applied acceleration initialization function. bool evolve_applied_acceleration; // Is the applied acceleration evolved? - bool has_diffusion; // Is there a diffusion operator? - double D; // Diffusion coefficient. - double order; // Diffusion order (e.g., grad^2, grad^4, grad^6). + bool has_diffusion; // Is there a diffusion operator? + double D; // Diffusion coefficient. + double order; // Diffusion order (e.g., grad^2, grad^4, grad^6). enum gkyl_collision_id collision_id; // Collision type. - + bool has_self_nu_func; // Is there a self-collision frequency function? - struct lua_func_ctx self_nu_func_ref; // Lua registry reference to self-collision frequency function. + struct lua_func_ctx + self_nu_func_ref; // Lua registry reference to self-collision frequency function. int num_cross_collisions; // Number of species that we cross-collide with. char collide_with[GKYL_MAX_SPECIES][128]; // Names of species that we cross-collide with. }; -static int -pkpm_species_lw_new(lua_State *L) +static int pkpm_species_lw_new(lua_State *L) { - int vdim = 0; - struct gkyl_pkpm_species pkpm_species = { }; + int vdim = 0; + struct gkyl_pkpm_species pkpm_species = {}; pkpm_species.model_id = GKYL_MODEL_DEFAULT; - + pkpm_species.charge = glua_tbl_get_number(L, "charge", 0.0); pkpm_species.mass = glua_tbl_get_number(L, "mass", 1.0); - with_lua_tbl_tbl(L, "cells") { + with_lua_tbl_tbl(L, "cells") + { vdim = glua_objlen(L); for (int d = 0; d < vdim; d++) { @@ -91,13 +94,15 @@ pkpm_species_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "lower") { + with_lua_tbl_tbl(L, "lower") + { for (int d = 0; d < vdim; d++) { pkpm_species.lower[d] = glua_tbl_iget_number(L, d + 1, 0); } } - with_lua_tbl_tbl(L, "upper") { + with_lua_tbl_tbl(L, "upper") + { for (int d = 0; d < vdim; d++) { pkpm_species.upper[d] = glua_tbl_iget_number(L, d + 1, 0); } @@ -105,7 +110,8 @@ pkpm_species_lw_new(lua_State *L) bool evolve = glua_tbl_get_bool(L, "evolve", true); - with_lua_tbl_tbl(L, "bcx") { + with_lua_tbl_tbl(L, "bcx") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -113,7 +119,8 @@ pkpm_species_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcy") { + with_lua_tbl_tbl(L, "bcy") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -121,7 +128,8 @@ pkpm_species_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcz") { + with_lua_tbl_tbl(L, "bcz") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -156,11 +164,12 @@ pkpm_species_lw_new(lua_State *L) evolve_applied_acceleration = glua_tbl_get_bool(L, "evolveAppliedAcceleration", false); } - bool has_diffusion = false; - double D = 0.0; - int order = 0; - with_lua_tbl_tbl(L, "diffusion") { - has_diffusion = true; + bool has_diffusion = false; + double D = 0.0; + int order = 0; + with_lua_tbl_tbl(L, "diffusion") + { + has_diffusion = true; D = glua_tbl_get_number(L, "D", 0.0); order = glua_tbl_get_integer(L, "order", 0); } @@ -173,7 +182,8 @@ pkpm_species_lw_new(lua_State *L) int num_cross_collisions = 0; char collide_with[GKYL_MAX_SPECIES][128]; - with_lua_tbl_tbl(L, "collisions") { + with_lua_tbl_tbl(L, "collisions") + { collision_id = glua_tbl_get_integer(L, "collisionID", 0); if (glua_tbl_get_func(L, "selfNu")) { @@ -182,14 +192,15 @@ pkpm_species_lw_new(lua_State *L) } num_cross_collisions = glua_tbl_get_integer(L, "numCrossCollisions", 0); - with_lua_tbl_tbl(L, "collideWith") { + with_lua_tbl_tbl(L, "collideWith") + { for (int i = 0; i < num_cross_collisions; i++) { - const char* collide_with_char = glua_tbl_iget_string(L, i + 1, ""); + const char *collide_with_char = glua_tbl_iget_string(L, i + 1, ""); strcpy(collide_with[i], collide_with_char); } } } - + struct pkpm_species_lw *pkpm_s_lw = lua_newuserdata(L, sizeof(*pkpm_s_lw)); pkpm_s_lw->magic = PKPM_SPECIES_DEFAULT; pkpm_s_lw->vdim = vdim; @@ -197,61 +208,51 @@ pkpm_species_lw_new(lua_State *L) pkpm_s_lw->pkpm_species = pkpm_species; pkpm_s_lw->has_dist_init_func = has_dist_init_func; - pkpm_s_lw->dist_init_func_ref = (struct lua_func_ctx) { - .func_ref = dist_init_func_ref, + pkpm_s_lw->dist_init_func_ref = (struct lua_func_ctx + ){.func_ref = dist_init_func_ref, .ndim = 0, // This will be set later. .nret = 2, - .L = L, - }; + .L = L}; pkpm_s_lw->has_fluid_init_func = has_fluid_init_func; - pkpm_s_lw->fluid_init_func_ref = (struct lua_func_ctx) { - .func_ref = fluid_init_func_ref, + pkpm_s_lw->fluid_init_func_ref = (struct lua_func_ctx + ){.func_ref = fluid_init_func_ref, .ndim = 0, // This will be set later. .nret = 3, - .L = L, - }; + .L = L}; pkpm_s_lw->has_applied_acceleration_func = has_applied_acceleration_func; - pkpm_s_lw->applied_acceleration_func_ref = (struct lua_func_ctx) { - .func_ref = applied_acceleration_func_ref, + pkpm_s_lw->applied_acceleration_func_ref = (struct lua_func_ctx + ){.func_ref = applied_acceleration_func_ref, .ndim = 0, // This will be set later. .nret = 3, - .L = L, - }; + .L = L}; pkpm_s_lw->evolve_applied_acceleration = evolve_applied_acceleration; - pkpm_s_lw->has_diffusion = has_diffusion; - pkpm_s_lw->D = D; - pkpm_s_lw->order = order; + pkpm_s_lw->has_diffusion = has_diffusion; + pkpm_s_lw->D = D; + pkpm_s_lw->order = order; pkpm_s_lw->collision_id = collision_id; pkpm_s_lw->has_self_nu_func = has_self_nu_func; - pkpm_s_lw->self_nu_func_ref = (struct lua_func_ctx) { - .func_ref = self_nu_func_ref, - .ndim = 0, - .nret = 1, - .L = L, - }; + pkpm_s_lw->self_nu_func_ref = + (struct lua_func_ctx){.func_ref = self_nu_func_ref, .ndim = 0, .nret = 1, .L = L}; pkpm_s_lw->num_cross_collisions = num_cross_collisions; for (int i = 0; i < num_cross_collisions; i++) { strcpy(pkpm_s_lw->collide_with[i], collide_with[i]); } - + // Set metatable. luaL_getmetatable(L, PKPM_SPECIES_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Species constructor. -static struct luaL_Reg pkpm_species_ctor[] = { - { "new", pkpm_species_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg pkpm_species_ctor[] = {{"new", pkpm_species_lw_new}, {0, 0}}; /* ************* */ /* Field methods */ @@ -263,28 +264,29 @@ static struct luaL_Reg pkpm_species_ctor[] = { // Lua userdata object for constructing field input. struct pkpm_field_lw { int magic; // This must be first element in the struct. - + struct gkyl_pkpm_field pkpm_field; // Input struct to construct field. bool evolve; // Is this field evolved? struct lua_func_ctx init_ref; // Lua registry reference to initilization function. bool has_external_field_func; // Is there an external field initialization function? - struct lua_func_ctx external_field_func_ref; // Lua registry reference to external field initialization function. + struct lua_func_ctx + external_field_func_ref; // Lua registry reference to external field initialization function. bool evolve_external_field; // Is the external field evolved? bool has_applied_current_func; // Is there an applied current initialization function? - struct lua_func_ctx applied_current_func_ref; // Lua registry reference to applied current initialization function. + struct lua_func_ctx + applied_current_func_ref; // Lua registry reference to applied current initialization function. bool evolve_applied_current; // Is the applied current evolved? }; -static int -pkpm_field_lw_new(lua_State *L) +static int pkpm_field_lw_new(lua_State *L) { - int vdim = 0; - struct gkyl_pkpm_field pkpm_field = { }; + int vdim = 0; + struct gkyl_pkpm_field pkpm_field = {}; + + pkpm_field.field_id = GKYL_FIELD_E_B; - pkpm_field.field_id = GKYL_FIELD_E_B; - pkpm_field.epsilon0 = glua_tbl_get_number(L, "epsilon0", 1.0); pkpm_field.mu0 = glua_tbl_get_number(L, "mu0", 1.0); pkpm_field.elcErrorSpeedFactor = glua_tbl_get_number(L, "elcErrorSpeedFactor", 0.0); @@ -298,7 +300,8 @@ pkpm_field_lw_new(lua_State *L) init_ref = luaL_ref(L, LUA_REGISTRYINDEX); } - with_lua_tbl_tbl(L, "bcx") { + with_lua_tbl_tbl(L, "bcx") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -306,7 +309,8 @@ pkpm_field_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcy") { + with_lua_tbl_tbl(L, "bcy") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -314,7 +318,8 @@ pkpm_field_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcz") { + with_lua_tbl_tbl(L, "bcz") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -349,44 +354,38 @@ pkpm_field_lw_new(lua_State *L) pkpm_f_lw->magic = PKPM_FIELD_DEFAULT; pkpm_f_lw->evolve = evolve; pkpm_f_lw->pkpm_field = pkpm_field; - - pkpm_f_lw->init_ref = (struct lua_func_ctx) { - .func_ref = init_ref, + + pkpm_f_lw->init_ref = (struct lua_func_ctx + ){.func_ref = init_ref, .ndim = 0, // This will be set later. .nret = 6, - .L = L, - }; + .L = L}; pkpm_f_lw->has_external_field_func = has_external_field_func; - pkpm_f_lw->external_field_func_ref = (struct lua_func_ctx) { - .func_ref = external_field_func_ref, + pkpm_f_lw->external_field_func_ref = (struct lua_func_ctx + ){.func_ref = external_field_func_ref, .ndim = 0, // This will be set later. .nret = 6, - .L = L, - }; + .L = L}; pkpm_f_lw->evolve_external_field = evolve_external_field; pkpm_f_lw->has_applied_current_func = has_applied_current_func; - pkpm_f_lw->applied_current_func_ref = (struct lua_func_ctx) { - .func_ref = applied_current_func_ref, + pkpm_f_lw->applied_current_func_ref = (struct lua_func_ctx + ){.func_ref = applied_current_func_ref, .ndim = 0, // This will be set later. .nret = 3, - .L = L, - }; + .L = L}; pkpm_f_lw->evolve_applied_current = evolve_applied_current; - + // Set metatable. luaL_getmetatable(L, PKPM_FIELD_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Species constructor. -static struct luaL_Reg pkpm_field_ctor[] = { - { "new", pkpm_field_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg pkpm_field_ctor[] = {{"new", pkpm_field_lw_new}, {0, 0}}; /* *********** */ /* App methods */ @@ -399,21 +398,26 @@ static struct luaL_Reg pkpm_field_ctor[] = { struct pkpm_app_lw { gkyl_pkpm_app *app; // PKPM app object. - struct lua_func_ctx dist_init_func_ctx[GKYL_MAX_SPECIES]; // Context for distribution initialization function. - struct lua_func_ctx fluid_init_func_ctx[GKYL_MAX_SPECIES]; // Context for fluid initialization function. - struct lua_func_ctx applied_acceleration_func_ctx[GKYL_MAX_SPECIES]; // Context for applied acceleration function. + struct lua_func_ctx + dist_init_func_ctx[GKYL_MAX_SPECIES]; // Context for distribution initialization function. + struct lua_func_ctx + fluid_init_func_ctx[GKYL_MAX_SPECIES]; // Context for fluid initialization function. + struct lua_func_ctx + applied_acceleration_func_ctx[GKYL_MAX_SPECIES]; // Context for applied acceleration function. enum gkyl_collision_id collision_id[GKYL_MAX_SPECIES]; // Collision type. - struct lua_func_ctx self_nu_func_ctx[GKYL_MAX_SPECIES]; // Context for self-collision frequency function. + struct lua_func_ctx + self_nu_func_ctx[GKYL_MAX_SPECIES]; // Context for self-collision frequency function. int num_cross_collisions[GKYL_MAX_SPECIES]; // Number of species that we cross-collide with. - char collide_with[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES][128]; // Names of species that we cross-collide with. + char collide_with[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES] + [128]; // Names of species that we cross-collide with. struct lua_func_ctx field_func_ctx; // Function context for field. struct lua_func_ctx external_field_func_ctx; // Function context for external field. struct lua_func_ctx applied_current_func_ctx; // Function context for applied current. - + double t_start, t_end; // Start and end times of simulation. int num_frames; // Number of data frames to write. int field_energy_calcs; // Number of times to calculate field energy. @@ -431,9 +435,9 @@ struct pkpm_app_lw { int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? char test_nn_file[256]; // File path of neural network to test. int num_tests; // Number of times to test neural network. @@ -446,7 +450,7 @@ static int get_species_inp(lua_State *L, int cdim, struct pkpm_species_lw *species[GKYL_MAX_SPECIES]) { enum { TKEY = -2, TVAL = -1 }; - + int curr = 0; lua_pushnil(L); // Initial key is nil. while (lua_next(L, TKEY) != 0) { @@ -459,18 +463,18 @@ get_species_inp(lua_State *L, int cdim, struct pkpm_species_lw *species[GKYL_MAX pkpm_s->dist_init_func_ref.ndim = cdim + pkpm_s->vdim; } - if(pkpm_s->has_fluid_init_func) { + if (pkpm_s->has_fluid_init_func) { pkpm_s->fluid_init_func_ref.ndim = cdim; } - if(pkpm_s->has_applied_acceleration_func) { + if (pkpm_s->has_applied_acceleration_func) { pkpm_s->applied_acceleration_func_ref.ndim = cdim; } if (pkpm_s->has_self_nu_func) { pkpm_s->self_nu_func_ref.ndim = cdim; } - + if (lua_type(L, TKEY) == LUA_TSTRING) { const char *key = lua_tolstring(L, TKEY, 0); strcpy(pkpm_s->pkpm_species.name, key); @@ -485,28 +489,26 @@ get_species_inp(lua_State *L, int cdim, struct pkpm_species_lw *species[GKYL_MAX } // Comparison method to sort species array by species name. -static int -species_compare_func(const void *a, const void *b) +static int species_compare_func(const void *a, const void *b) { const struct pkpm_species_lw *const *spa = a; const struct pkpm_species_lw *const *spb = b; return strcmp((*spa)->pkpm_species.name, (*spb)->pkpm_species.name); } -static struct gkyl_tool_args * -tool_args_from_argv(int optind, int argc, char *const*argv) +static struct gkyl_tool_args *tool_args_from_argv(int optind, int argc, char *const *argv) { struct gkyl_tool_args *targs = gkyl_malloc(sizeof *targs); - - targs->argc = argc-optind; + + targs->argc = argc - optind; targs->argv = 0; if (targs->argc > 0) { - targs->argv = gkyl_malloc(targs->argc*sizeof(char *)); - for (int i = optind, j = 0; i < argc; ++i, ++j) { - targs->argv[j] = gkyl_malloc(strlen(argv[i])+1); - strcpy(targs->argv[j], argv[i]); - } + targs->argv = gkyl_malloc(targs->argc * sizeof(char *)); + for (int i = optind, j = 0; i < argc; ++i, ++j) { + targs->argv[j] = gkyl_malloc(strlen(argv[i]) + 1); + strcpy(targs->argv[j], argv[i]); + } } return targs; @@ -522,16 +524,15 @@ struct script_cli { bool trace_mem; // Should we trace memory allocation/deallocation? bool use_verbose; // Should we use verbose output? bool is_restart; // Is this a restarted simulation? - int restart_frame; // Which frame to restart simulation from. - + int restart_frame; // Which frame to restart simulation from. + struct gkyl_tool_args *rest; }; -static struct script_cli -pkpm_parse_script_cli(struct gkyl_tool_args *acv) +static struct script_cli pkpm_parse_script_cli(struct gkyl_tool_args *acv) { struct script_cli cli = { - .help =- false, + .help = -false, .step_mode = false, .num_steps = INT_MAX, .use_mpi = false, @@ -539,7 +540,7 @@ pkpm_parse_script_cli(struct gkyl_tool_args *acv) .trace_mem = false, .use_verbose = false, .is_restart = false, - .restart_frame = 0, + .restart_frame = 0 }; #ifdef GKYL_HAVE_MPI @@ -548,58 +549,55 @@ pkpm_parse_script_cli(struct gkyl_tool_args *acv) #ifdef GKYL_HAVE_CUDA cli.use_gpu = true; #endif - - coption_long longopts[] = { - { 0 } - }; - const char* shortopts = "+hVs:SGmr:"; + + coption_long longopts[] = {{0}}; + const char *shortopts = "+hVs:SGmr:"; coption opt = coption_init(); int c; while ((c = coption_get(&opt, acv->argc, acv->argv, shortopts, longopts)) != -1) { switch (c) { - case 'h': - cli.help = true; - break; + case 'h': + cli.help = true; + break; - case 's': - cli.num_steps = atoi(opt.arg); - break; - - case 'S': - cli.use_mpi = false; - break; - - case 'G': - cli.use_gpu = false; - break; - - case 'm': - cli.trace_mem = true; - break; - - case 'V': - cli.use_verbose = true; - break; - - case 'r': - cli.is_restart = true; - cli.restart_frame = atoi(opt.arg); - break; - - case '?': - break; + case 's': + cli.num_steps = atoi(opt.arg); + break; + + case 'S': + cli.use_mpi = false; + break; + + case 'G': + cli.use_gpu = false; + break; + + case 'm': + cli.trace_mem = true; + break; + + case 'V': + cli.use_verbose = true; + break; + + case 'r': + cli.is_restart = true; + cli.restart_frame = atoi(opt.arg); + break; + + case '?': + break; } } cli.rest = tool_args_from_argv(opt.ind, acv->argc, acv->argv); - + return cli; } // Create top-level App object. -static int -pkpm_app_new(lua_State *L) +static int pkpm_app_new(lua_State *L) { struct pkpm_app_lw *app_lw = gkyl_malloc(sizeof(*app_lw)); @@ -607,12 +605,13 @@ pkpm_app_new(lua_State *L) // GKYL_OUT_PREFIX. If this is not found then "g0-pkpm" is used. const char *sim_name = "g0-pkpm"; - with_lua_global(L, "GKYL_OUT_PREFIX") { + with_lua_global(L, "GKYL_OUT_PREFIX") + { if (lua_isstring(L, -1)) { sim_name = lua_tostring(L, -1); } } - + // Initialize app using table inputs (table is on top of stack). app_lw->t_start = glua_tbl_get_number(L, "tStart", 0.0); @@ -629,14 +628,15 @@ pkpm_app_new(lua_State *L) app_lw->train_ab_initio = glua_tbl_get_bool(L, "trainAbInitio", true); app_lw->nn_width = glua_tbl_get_integer(L, "NNWidth", 256); app_lw->nn_depth = glua_tbl_get_integer(L, "NNDepth", 5); - const char* train_nn_file_char = glua_tbl_get_string(L, "trainNNFile", ""); + const char *train_nn_file_char = glua_tbl_get_string(L, "trainNNFile", ""); strcpy(app_lw->train_nn_file, train_nn_file_char); app_lw->num_trains = glua_tbl_get_integer(L, "numTrains", INT_MAX); app_lw->num_nn_writes = glua_tbl_get_integer(L, "numNNWrites", 1); app_lw->num_input_moms = 0; if (glua_tbl_has_key(L, "inputMoms")) { - with_lua_tbl_tbl(L, "inputMoms") { + with_lua_tbl_tbl(L, "inputMoms") + { app_lw->num_input_moms = glua_objlen(L); app_lw->input_moms = gkyl_malloc(sizeof(int[app_lw->num_input_moms])); @@ -649,7 +649,8 @@ pkpm_app_new(lua_State *L) app_lw->num_output_moms = 0; if (glua_tbl_has_key(L, "outputMoms")) { - with_lua_tbl_tbl(L, "outputMoms") { + with_lua_tbl_tbl(L, "outputMoms") + { app_lw->num_output_moms = glua_objlen(L); app_lw->output_moms = gkyl_malloc(sizeof(int[app_lw->num_output_moms])); @@ -661,16 +662,17 @@ pkpm_app_new(lua_State *L) } app_lw->test_nn = glua_tbl_get_bool(L, "testNN", false); - const char* test_nn_file_char = glua_tbl_get_string(L, "testNNFile", ""); + const char *test_nn_file_char = glua_tbl_get_string(L, "testNNFile", ""); strcpy(app_lw->test_nn_file, test_nn_file_char); app_lw->num_tests = glua_tbl_get_integer(L, "numTests", 1); - struct gkyl_pkpm pkpm = { }; // Input table for app. + struct gkyl_pkpm pkpm = {}; // Input table for app. strcpy(pkpm.name, sim_name); - + int cdim = 0; - with_lua_tbl_tbl(L, "cells") { + with_lua_tbl_tbl(L, "cells") + { pkpm.cdim = cdim = glua_objlen(L); for (int d = 0; d < cdim; d++) { @@ -682,22 +684,25 @@ pkpm_app_new(lua_State *L) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } - - with_lua_tbl_tbl(L, "decompCuts") { + + with_lua_tbl_tbl(L, "decompCuts") + { int ncuts = glua_objlen(L); for (int d = 0; d < ncuts; d++) { cuts[d] = glua_tbl_iget_integer(L, d + 1, 0); } - } + } - with_lua_tbl_tbl(L, "lower") { + with_lua_tbl_tbl(L, "lower") + { for (int d = 0; d < cdim; d++) { pkpm.lower[d] = glua_tbl_iget_number(L, d + 1, 0); } } - with_lua_tbl_tbl(L, "upper") { + with_lua_tbl_tbl(L, "upper") + { for (int d = 0; d < cdim; d++) { pkpm.upper[d] = glua_tbl_iget_number(L, d + 1, 0); } @@ -708,13 +713,12 @@ pkpm_app_new(lua_State *L) pkpm.use_explicit_source = glua_tbl_get_bool(L, "useExplicitSource", false); - pkpm.basis_type = get_basis_type( - glua_tbl_get_string(L, "basis", "serendipity") - ); + pkpm.basis_type = get_basis_type(glua_tbl_get_string(L, "basis", "serendipity")); pkpm.num_periodic_dir = 0; if (glua_tbl_has_key(L, "periodicDirs")) { - with_lua_tbl_tbl(L, "periodicDirs") { + with_lua_tbl_tbl(L, "periodicDirs") + { pkpm.num_periodic_dir = glua_objlen(L); for (int d = 0; d < pkpm.num_periodic_dir; d++) { @@ -733,7 +737,7 @@ pkpm_app_new(lua_State *L) // proceeding as there is no way to ensure that all cores loop over // Lua tables in the same order qsort(species, pkpm.num_species, sizeof(struct pkpm_species_lw *), species_compare_func); - + for (int s = 0; s < pkpm.num_species; s++) { pkpm.species[s] = species[s]->pkpm_species; pkpm.vdim = species[s]->vdim; @@ -757,8 +761,8 @@ pkpm_app_new(lua_State *L) } if (species[s]->has_diffusion) { - pkpm.species[s].diffusion.D = species[s]->D; - pkpm.species[s].diffusion.order = species[s]->order; + pkpm.species[s].diffusion.D = species[s]->D; + pkpm.species[s].diffusion.order = species[s]->order; } app_lw->collision_id[s] = species[s]->collision_id; @@ -782,7 +786,8 @@ pkpm_app_new(lua_State *L) } // Set field input. - with_lua_tbl_key(L, "field") { + with_lua_tbl_key(L, "field") + { if (lua_type(L, -1) == LUA_TUSERDATA) { struct pkpm_field_lw *pkpm_f = lua_touserdata(L, -1); @@ -822,7 +827,7 @@ pkpm_app_new(lua_State *L) struct gkyl_comm *comm = 0; for (int d = 0; d < cdim; d++) { - pkpm.parallelism.cuts[d] = cuts[d]; + pkpm.parallelism.cuts[d] = cuts[d]; } struct gkyl_tool_args *args = gkyl_tool_args_new(L); @@ -831,52 +836,44 @@ pkpm_app_new(lua_State *L) #ifdef GKYL_HAVE_MPI if (script_cli.use_gpu && script_cli.use_mpi) { #ifdef GKYL_HAVE_NCCL - with_lua_global(L, "GKYL_MPI_COMM") { + with_lua_global(L, "GKYL_MPI_COMM") + { if (lua_islightuserdata(L, -1)) { - struct { MPI_Comm comm; } *lw_mpi_comm_world = lua_touserdata(L, -1); + struct { + MPI_Comm comm; + } *lw_mpi_comm_world = lua_touserdata(L, -1); MPI_Comm mpi_comm = lw_mpi_comm_world->comm; int nrank = 1; // Number of processors in simulation. MPI_Comm_size(mpi_comm, &nrank); - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = mpi_comm, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = mpi_comm}); } } #else printf("Using CUDA and MPI together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (script_cli.use_mpi) { - with_lua_global(L, "GKYL_MPI_COMM") { + } else if (script_cli.use_mpi) { + with_lua_global(L, "GKYL_MPI_COMM") + { if (lua_islightuserdata(L, -1)) { - struct { MPI_Comm comm; } *lw_mpi_comm_world = lua_touserdata(L, -1); + struct { + MPI_Comm comm; + } *lw_mpi_comm_world = lua_touserdata(L, -1); MPI_Comm mpi_comm = lw_mpi_comm_world->comm; int nrank = 1; // Number of processors in simulation. MPI_Comm_size(mpi_comm, &nrank); - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = mpi_comm, - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = mpi_comm}); } } - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = script_cli.use_gpu, - } - ); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = script_cli.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = script_cli.use_gpu, - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = script_cli.use_gpu}); #endif pkpm.parallelism.comm = comm; @@ -897,25 +894,24 @@ pkpm_app_new(lua_State *L) printf("tot_cuts = %d (%d)\n", tot_cuts, comm_sz); luaL_error(L, "Number of ranks and cuts do not match!"); } - + app_lw->app = gkyl_pkpm_app_new(&pkpm); gkyl_comm_release(comm); // Create Lua userdata. - struct pkpm_app_lw **l_app_lw = lua_newuserdata(L, sizeof(struct pkpm_app_lw*)); + struct pkpm_app_lw **l_app_lw = lua_newuserdata(L, sizeof(struct pkpm_app_lw *)); *l_app_lw = app_lw; // Point it to the Lua app pointer. // Set metatable. luaL_getmetatable(L, PKPM_APP_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Apply initial conditions. (time) -> bool. -static int -pkpm_app_apply_ic(lua_State *L) +static int pkpm_app_apply_ic(lua_State *L) { bool status = true; @@ -925,13 +921,12 @@ pkpm_app_apply_ic(lua_State *L) double t0 = luaL_optnumber(L, 2, app_lw->t_start); gkyl_pkpm_app_apply_ic(app_lw->app, t0); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Apply initial conditions to field. (time) -> bool. -static int -pkpm_app_apply_ic_field(lua_State *L) +static int pkpm_app_apply_ic_field(lua_State *L) { bool status = true; @@ -941,13 +936,12 @@ pkpm_app_apply_ic_field(lua_State *L) double t0 = luaL_optnumber(L, 2, app_lw->t_start); gkyl_pkpm_app_apply_ic_field(app_lw->app, t0); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Apply initial conditions to species. (sidx, time) -> bool. -static int -pkpm_app_apply_ic_species(lua_State *L) +static int pkpm_app_apply_ic_species(lua_State *L) { bool status = true; @@ -958,13 +952,12 @@ pkpm_app_apply_ic_species(lua_State *L) double t0 = luaL_optnumber(L, 3, app_lw->t_start); gkyl_pkpm_app_apply_ic_species(app_lw->app, sidx, t0); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Compute integrated moments. (tm) -> bool. -static int -pkpm_app_calc_integrated_mom(lua_State *L) +static int pkpm_app_calc_integrated_mom(lua_State *L) { bool status = true; @@ -974,13 +967,12 @@ pkpm_app_calc_integrated_mom(lua_State *L) double tm = luaL_checknumber(L, 2); gkyl_pkpm_app_calc_integrated_mom(app_lw->app, tm); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Compute integrated L2 norm of distribution function. (tm) -> bool. -static int -pkpm_app_calc_integrated_L2_f(lua_State *L) +static int pkpm_app_calc_integrated_L2_f(lua_State *L) { bool status = true; @@ -990,14 +982,13 @@ pkpm_app_calc_integrated_L2_f(lua_State *L) double tm = luaL_checknumber(L, 2); gkyl_pkpm_app_calc_integrated_L2_f(app_lw->app, tm); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Compute integrated field energy (L2 norm of each field // component). (tm) -> bool. -static int -pkpm_app_calc_field_energy(lua_State *L) +static int pkpm_app_calc_field_energy(lua_State *L) { bool status = true; @@ -1007,13 +998,12 @@ pkpm_app_calc_field_energy(lua_State *L) double tm = luaL_checknumber(L, 2); gkyl_pkpm_app_calc_field_energy(app_lw->app, tm); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write solution (field and species) to file (time, frame) -> bool. -static int -pkpm_app_write(lua_State *L) +static int pkpm_app_write(lua_State *L) { bool status = true; @@ -1024,13 +1014,12 @@ pkpm_app_write(lua_State *L) int frame = luaL_checkinteger(L, 3); gkyl_pkpm_app_write(app_lw->app, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write field to file (time, frame) -> bool. -static int -pkpm_app_write_field(lua_State *L) +static int pkpm_app_write_field(lua_State *L) { bool status = true; @@ -1041,13 +1030,12 @@ pkpm_app_write_field(lua_State *L) int frame = luaL_checkinteger(L, 3); gkyl_pkpm_app_write_field(app_lw->app, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write species solution to file (sidx, time, frame) -> bool. -static int -pkpm_app_write_species(lua_State *L) +static int pkpm_app_write_species(lua_State *L) { bool status = true; @@ -1059,13 +1047,12 @@ pkpm_app_write_species(lua_State *L) int frame = luaL_checkinteger(L, 4); gkyl_pkpm_app_write_species(app_lw->app, sidx, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write integrated moments to file () -> bool. -static int -pkpm_app_write_integrated_mom(lua_State *L) +static int pkpm_app_write_integrated_mom(lua_State *L) { bool status = true; @@ -1074,13 +1061,12 @@ pkpm_app_write_integrated_mom(lua_State *L) gkyl_pkpm_app_write_integrated_mom(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write integrated L2 norm of f to file () -> bool. -static int -pkpm_app_write_integrated_L2_f(lua_State *L) +static int pkpm_app_write_integrated_L2_f(lua_State *L) { bool status = true; @@ -1089,13 +1075,12 @@ pkpm_app_write_integrated_L2_f(lua_State *L) gkyl_pkpm_app_write_integrated_L2_f(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write integrated field energy to file () -> bool. -static int -pkpm_app_write_field_energy(lua_State *L) +static int pkpm_app_write_field_energy(lua_State *L) { bool status = true; @@ -1104,13 +1089,12 @@ pkpm_app_write_field_energy(lua_State *L) gkyl_pkpm_app_write_field_energy(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write simulation statistics to JSON. () -> bool. -static int -pkpm_app_stat_write(lua_State *L) +static int pkpm_app_stat_write(lua_State *L) { bool status = true; @@ -1120,12 +1104,12 @@ pkpm_app_stat_write(lua_State *L) gkyl_pkpm_app_stat_write(app_lw->app); lua_pushboolean(L, status); - return 1; + return 1; } // Write data from simulation to file. static void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -1142,7 +1126,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool // Calculate and append field energy to dynvector. static void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +calc_field_energy(struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); @@ -1151,7 +1135,7 @@ calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr // Calculate and append integrated moments to dynvector. static void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +calc_integrated_mom(struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); @@ -1160,16 +1144,18 @@ calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_cu // Calculate and append integrated L2 norm of distribution function to dynvector. static void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +calc_integrated_L2_f(struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -static void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +static void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -1177,12 +1163,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -static void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +static void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -1194,9 +1185,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -static void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +static void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -1204,40 +1198,46 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } // Step message context. struct step_message_trigs { int log_count; // Number of times logging called. - int tenth, p1c; + int tenth, p1c; struct gkyl_tm_trigger log_trig; // 10% trigger. struct gkyl_tm_trigger log_trig_1p; // 1% trigger. }; // Write log message to console. -static void -write_step_message(const struct gkyl_pkpm_app *app, struct step_message_trigs *trigs, int step, double t_curr, double dt_next) +static void write_step_message( + const struct gkyl_pkpm_app *app, struct step_message_trigs *trigs, int step, double t_curr, + double dt_next +) { if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig, t_curr)) { if (trigs->log_count > 0) { - gkyl_pkpm_app_cout(app, stdout, " Step %6d at time %#11.8g. Time-step %.6e. Completed %g%s\n", step, t_curr, dt_next, trigs->tenth * 10.0, "%"); - } - else { + gkyl_pkpm_app_cout( + app, stdout, " Step %6d at time %#11.8g. Time-step %.6e. Completed %g%s\n", step, t_curr, + dt_next, trigs->tenth * 10.0, "%" + ); + } else { trigs->log_count += 1; } - + trigs->tenth += 1; } if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig_1p, t_curr)) { gkyl_pkpm_app_cout(app, stdout, "%d", trigs->p1c); - trigs->p1c = (trigs->p1c+1) % 10; + trigs->p1c = (trigs->p1c + 1) % 10; } } -static void -show_help(const struct gkyl_pkpm_app *app) +static void show_help(const struct gkyl_pkpm_app *app) { gkyl_pkpm_app_cout(app, stdout, "PKPM script takes the following arguments:\n"); gkyl_pkpm_app_cout(app, stdout, " -h Print this help message and exit\n"); @@ -1252,8 +1252,7 @@ show_help(const struct gkyl_pkpm_app *app) } // Run simulation. (num_steps) -> bool. num_steps is optional. -static int -pkpm_app_run(lua_State *L) +static int pkpm_app_run(lua_State *L) { bool ret_status = true; @@ -1274,7 +1273,7 @@ pkpm_app_run(lua_State *L) } gkyl_tool_args_release(script_cli.rest); - gkyl_tool_args_release(args); + gkyl_tool_args_release(args); // Initial and final simulation times. double t_curr = app_lw->t_start, t_end = app_lw->t_end; @@ -1289,14 +1288,17 @@ pkpm_app_run(lua_State *L) // Initialize simulation. bool is_restart = script_cli.is_restart; - int restart_frame = script_cli.restart_frame; + int restart_frame = script_cli.restart_frame; int frame_curr = 0; if (is_restart) { struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -1305,8 +1307,7 @@ pkpm_app_run(lua_State *L) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } @@ -1315,17 +1316,25 @@ pkpm_app_run(lua_State *L) int integrated_mom_calcs = app_lw->integrated_mom_calcs; int integrated_L2_f_calcs = app_lw->integrated_L2_f_calcs; // Triggers for IO and logging. - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; struct step_message_trigs m_trig = { .log_count = 0, - .tenth = t_curr > 0.0 ? (int) floor(t_curr / t_end * 10.0) : 0.0, - .p1c = t_curr > 0.0 ? (int) floor(t_curr / t_end * 100.0) % 10 : 0.0, - .log_trig = { .dt = t_end / 10.0, .tcurr = t_curr }, - .log_trig_1p = { .dt = t_end / 100.0, .tcurr = t_curr }, + .tenth = t_curr > 0.0 ? (int)floor(t_curr / t_end * 10.0) : 0.0, + .p1c = t_curr > 0.0 ? (int)floor(t_curr / t_end * 100.0) % 10 : 0.0, + .log_trig = {.dt = t_end / 10.0, .tcurr = t_curr}, + .log_trig_1p = {.dt = t_end / 100.0, .tcurr = t_curr} }; struct timespec tm_ic0 = gkyl_wall_clock(); @@ -1337,22 +1346,20 @@ pkpm_app_run(lua_State *L) // Create trigger for neural network training. int num_trains = app_lw->num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app->num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app->num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app->num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app->num_species); if (app_lw->train_nn) { if (app_lw->train_ab_initio) { - for (int i = 0; i < app->num_species; i++ ) { + for (int i = 0; i < app->num_species; i++) { if (app->poly_order == 1) { if (app->cdim == 1) { t[i] = kann_layer_input(app_lw->num_input_moms * 2); - } - else if (app->cdim == 2) { + } else if (app->cdim == 2) { t[i] = kann_layer_input(app_lw->num_input_moms * 4); } - } - else if (app->poly_order == 2) { + } else if (app->poly_order == 2) { t[i] = kann_layer_input(app_lw->num_input_moms * 3); } @@ -1360,22 +1367,19 @@ pkpm_app_run(lua_State *L) t[i] = kann_layer_dense(t[i], app_lw->nn_width); t[i] = kad_tanh(t[i]); } - + if (app->poly_order == 1) { if (app->cdim == 1) { t[i] = kann_layer_cost(t[i], app_lw->num_output_moms * 2, KANN_C_MSE); - } - else if (app->cdim == 2) { + } else if (app->cdim == 2) { t[i] = kann_layer_cost(t[i], app_lw->num_output_moms * 4, KANN_C_MSE); } - } - else if (app->poly_order == 2) { + } else if (app->poly_order == 2) { t[i] = kann_layer_cost(t[i], app_lw->num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app->use_gpu); } - } - else { + } else { for (int i = 0; i < app->num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, app_lw->train_nn_file, app->species[i].info.name); @@ -1386,11 +1390,13 @@ pkpm_app_run(lua_State *L) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app->use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; app_lw->train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app->species[i].info.name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app->species[i].info.name + ); } } } @@ -1399,8 +1405,7 @@ pkpm_app_run(lua_State *L) int cell_count = 0; if (app->cdim == 1) { cell_count = app->grid.cells[0]; - } - else if (app->cdim == 2) { + } else if (app->cdim == 2) { cell_count = app->grid.cells[0] * app->grid.cells[1]; } @@ -1413,12 +1418,17 @@ pkpm_app_run(lua_State *L) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (app_lw->train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, app_lw->num_input_moms, app_lw->input_moms, app_lw->num_output_moms, app_lw->output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, app_lw->num_input_moms, app_lw->input_moms, + app_lw->num_output_moms, app_lw->output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = app_lw->num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (app_lw->train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -1426,9 +1436,9 @@ pkpm_app_run(lua_State *L) // Create trigger for neural network testing. int num_tests = app_lw->num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app->num_species); + struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app->num_species); if (app_lw->test_nn) { for (int i = 0; i < app->num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -1440,11 +1450,13 @@ pkpm_app_run(lua_State *L) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app->use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; app_lw->test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app->species[i].info.name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app->species[i].info.name + ); } } } @@ -1454,12 +1466,17 @@ pkpm_app_run(lua_State *L) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (app_lw->test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, app_lw->num_input_moms, app_lw->input_moms, app_lw->num_output_moms, app_lw->output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, app_lw->num_input_moms, app_lw->input_moms, + app_lw->num_output_moms, app_lw->output_moms, input_data_real, output_data_real, + output_data_predicted + ); } - gkyl_pkpm_app_cout(app, stdout, "Initialization completed in %g sec\n\n", gkyl_time_diff_now_sec(tm_ic0)); - + gkyl_pkpm_app_cout( + app, stdout, "Initialization completed in %g sec\n\n", gkyl_time_diff_now_sec(tm_ic0) + ); + // Compute initial guess of maximum stable time-step. double dt = t_end - t_curr; @@ -1492,18 +1509,23 @@ pkpm_app_run(lua_State *L) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (app_lw->train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, app_lw->num_input_moms, app_lw->input_moms, app_lw->num_output_moms, app_lw->output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, app_lw->num_input_moms, app_lw->input_moms, + app_lw->num_output_moms, app_lw->output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (app_lw->test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, app_lw->num_input_moms, app_lw->input_moms, app_lw->num_output_moms, app_lw->output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, app_lw->num_input_moms, app_lw->input_moms, + app_lw->num_output_moms, app_lw->output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -1511,32 +1533,39 @@ pkpm_app_run(lua_State *L) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (app_lw->train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, app_lw->num_input_moms, app_lw->input_moms, app_lw->num_output_moms, app_lw->output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, app_lw->num_input_moms, app_lw->input_moms, + app_lw->num_output_moms, app_lw->output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (app_lw->test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, app_lw->num_input_moms, app_lw->input_moms, app_lw->num_output_moms, app_lw->output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, app_lw->num_input_moms, app_lw->input_moms, + app_lw->num_output_moms, app_lw->output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } if (!use_verbose) { write_step_message(app, &m_trig, step, t_curr, status.dt_suggested); } - + step += 1; } @@ -1545,7 +1574,10 @@ pkpm_app_run(lua_State *L) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (app_lw->train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, app_lw->num_input_moms, app_lw->input_moms, app_lw->num_output_moms, app_lw->output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, app_lw->num_input_moms, app_lw->input_moms, + app_lw->num_output_moms, app_lw->output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app->num_species; i++) { @@ -1553,8 +1585,11 @@ pkpm_app_run(lua_State *L) } } if (app_lw->test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, app_lw->num_input_moms, app_lw->input_moms, app_lw->num_output_moms, app_lw->output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, app_lw->num_input_moms, app_lw->input_moms, + app_lw->num_output_moms, app_lw->output_moms, input_data_real, output_data_real, + output_data_predicted + ); for (int i = 0; i < app->num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -1569,18 +1604,30 @@ pkpm_app_run(lua_State *L) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); @@ -1605,45 +1652,40 @@ pkpm_app_run(lua_State *L) } // Clean up memory allocated for simulation. -static int -pkpm_app_gc(lua_State *L) +static int pkpm_app_gc(lua_State *L) { struct pkpm_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, PKPM_APP_METATABLE_NM); struct pkpm_app_lw *app_lw = *l_app_lw; gkyl_pkpm_app_release(app_lw->app); gkyl_free(*l_app_lw); - + return 0; } // App constructor. -static struct luaL_Reg pkpm_app_ctor[] = { - { "new", pkpm_app_new }, - { 0, 0 } -}; +static struct luaL_Reg pkpm_app_ctor[] = {{"new", pkpm_app_new}, {0, 0}}; // App methods. static struct luaL_Reg pkpm_app_funcs[] = { - { "apply_ic", pkpm_app_apply_ic }, - { "apply_ic_field", pkpm_app_apply_ic_field }, - { "apply_ic_species", pkpm_app_apply_ic_species }, - { "calc_integrated_mom", pkpm_app_calc_integrated_mom }, - { "calc_integrated_L2_f", pkpm_app_calc_integrated_L2_f }, - { "calc_field_energy", pkpm_app_calc_field_energy }, - { "write", pkpm_app_write }, - { "write_field", pkpm_app_write_field }, - { "write_species", pkpm_app_write_species }, - { "write_integrated_mom", pkpm_app_write_integrated_mom }, - { "write_integrated_L2_f", pkpm_app_write_integrated_L2_f }, - { "write_field_energy", pkpm_app_write_field_energy }, - { "stat_write", pkpm_app_stat_write }, - { "run", pkpm_app_run }, - { 0, 0 } + {"apply_ic", pkpm_app_apply_ic}, + {"apply_ic_field", pkpm_app_apply_ic_field}, + {"apply_ic_species", pkpm_app_apply_ic_species}, + {"calc_integrated_mom", pkpm_app_calc_integrated_mom}, + {"calc_integrated_L2_f", pkpm_app_calc_integrated_L2_f}, + {"calc_field_energy", pkpm_app_calc_field_energy}, + {"write", pkpm_app_write}, + {"write_field", pkpm_app_write_field}, + {"write_species", pkpm_app_write_species}, + {"write_integrated_mom", pkpm_app_write_integrated_mom}, + {"write_integrated_L2_f", pkpm_app_write_integrated_L2_f}, + {"write_field_energy", pkpm_app_write_field_energy}, + {"stat_write", pkpm_app_stat_write}, + {"run", pkpm_app_run}, + {0, 0} }; -static void -app_openlibs(lua_State *L) +static void app_openlibs(lua_State *L) { // Register top-level App. do { @@ -1656,29 +1698,25 @@ app_openlibs(lua_State *L) lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_register(L, NULL, pkpm_app_funcs); - + luaL_register(L, "G0.PKPM.App", pkpm_app_ctor); - - } - while (0); + + } while (0); // Register Species input struct. do { luaL_newmetatable(L, PKPM_SPECIES_METATABLE_NM); luaL_register(L, "G0.PKPM.Species", pkpm_species_ctor); - } - while (0); + } while (0); // Register Field input struct. do { luaL_newmetatable(L, PKPM_FIELD_METATABLE_NM); luaL_register(L, "G0.PKPM.Field", pkpm_field_ctor); - } - while (0); + } while (0); } -void -gkyl_pkpm_lw_openlibs(lua_State *L) +void gkyl_pkpm_lw_openlibs(lua_State *L) { app_openlibs(L); } diff --git a/pkpm/apps/pkpm_species.c b/pkpm/apps/pkpm_species.c index 00b3d43b3b..ef05af7c4c 100644 --- a/pkpm/apps/pkpm_species.c +++ b/pkpm/apps/pkpm_species.c @@ -13,11 +13,10 @@ #include // initialize species object -void -pkpm_species_init(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app, struct pkpm_species *s) +void pkpm_species_init(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app, struct pkpm_species *s) { int cdim = app->cdim, vdim = app->vdim; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int cells[GKYL_MAX_DIM], ghost[GKYL_MAX_DIM]; double lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; @@ -25,18 +24,18 @@ pkpm_species_init(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app, struct pkpm int cells_vel[GKYL_MAX_DIM], ghost_vel[GKYL_MAX_DIM]; double lower_vel[GKYL_MAX_DIM], upper_vel[GKYL_MAX_DIM]; - for (int d=0; dcells[d]; lower[d] = pkpm->lower[d]; upper[d] = pkpm->upper[d]; ghost[d] = 1; } - for (int d=0; dinfo.cells[d]; - lower[cdim+d] = s->info.lower[d]; - upper[cdim+d] = s->info.upper[d]; - ghost[cdim+d] = 0; // no ghost-cells in velocity space + cells[cdim + d] = s->info.cells[d]; + lower[cdim + d] = s->info.lower[d]; + upper[cdim + d] = s->info.upper[d]; + ghost[cdim + d] = 0; // no ghost-cells in velocity space // only velocity space cells_vel[d] = s->info.cells[d]; @@ -47,7 +46,7 @@ pkpm_species_init(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app, struct pkpm // full phase space grid gkyl_rect_grid_init(&s->grid, pdim, lower, upper, cells); gkyl_create_grid_ranges(&s->grid, ghost, &s->global_ext, &s->global); - + // velocity space grid gkyl_rect_grid_init(&s->grid_vel, vdim, lower_vel, upper_vel, cells_vel); gkyl_create_grid_ranges(&s->grid_vel, ghost_vel, &s->local_ext_vel, &s->local_vel); @@ -63,42 +62,42 @@ pkpm_species_init(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app, struct pkpm // allocate distribution function arrays // PKPM has two distribution functions F_0 and T_perp*G, first two Laguerre moments - s->f = mkarr(app->use_gpu, 2*app->basis.num_basis, s->local_ext.volume); - s->f1 = mkarr(app->use_gpu, 2*app->basis.num_basis, s->local_ext.volume); - s->fnew = mkarr(app->use_gpu, 2*app->basis.num_basis, s->local_ext.volume); + s->f = mkarr(app->use_gpu, 2 * app->basis.num_basis, s->local_ext.volume); + s->f1 = mkarr(app->use_gpu, 2 * app->basis.num_basis, s->local_ext.volume); + s->fnew = mkarr(app->use_gpu, 2 * app->basis.num_basis, s->local_ext.volume); // allocate momentum arrays (rho ux, rho uy, rho uz) - s->fluid = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); - s->fluid1 = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); - s->fluidnew = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); + s->fluid = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); + s->fluid1 = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); + s->fluidnew = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); // create host arrays if on GPUs so initialization occurs host-side s->f_host = s->f; s->fluid_host = s->fluid; if (app->use_gpu) { - s->f_host = mkarr(false, 2*app->basis.num_basis, s->local_ext.volume); - s->fluid_host = mkarr(false, 3*app->confBasis.num_basis, app->local_ext.volume); + s->f_host = mkarr(false, 2 * app->basis.num_basis, s->local_ext.volume); + s->fluid_host = mkarr(false, 3 * app->confBasis.num_basis, app->local_ext.volume); } // Duplicate copy of momentum data in case time step fails. - // Needed because of implicit source split which modifies solution and - // is always successful, so if a time step fails due to the SSP RK3 + // Needed because of implicit source split which modifies solution and + // is always successful, so if a time step fails due to the SSP RK3 // we must restore the old solution before restarting the time step - s->fluid_dup = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); + s->fluid_dup = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); // Wave equation object for upwinding fluid equations // We use the 10 moment system since PKPM model generates a full pressure tensor - // k0 = 0.0 and use_grad_closure = false because we do not need a closure + // k0 = 0.0 and use_grad_closure = false because we do not need a closure // (the kinetic equations are the closure) - s->equation = gkyl_wv_ten_moment_new(0.0, false, false, 0, 0, app->use_gpu); + s->equation = gkyl_wv_ten_moment_new(0.0, false, false, 0, 0, app->use_gpu); // Distribution function arrays for coupling different Laguerre moments - // g_dist_source has two components: - // [2.0*T_perp/m*(2.0*T_perp/m G + T_perp/m (F_2 - F_0)), + // g_dist_source has two components: + // [2.0*T_perp/m*(2.0*T_perp/m G + T_perp/m (F_2 - F_0)), // (-vpar div(b) + bb:grad(u) - div(u) - 2 nu) T_perp/m G + 2 nu vth^2 F_0] // First component is mirror force source *distribution*, second component is *total* vperp characteristics source. - s->g_dist_source = mkarr(app->use_gpu, 2*app->basis.num_basis, s->local_ext.volume); - s->F_k_p_1 = mkarr(app->use_gpu, app->basis.num_basis, s->local_ext.volume); - s->F_k_m_1 = mkarr(app->use_gpu, app->basis.num_basis, s->local_ext.volume); + s->g_dist_source = mkarr(app->use_gpu, 2 * app->basis.num_basis, s->local_ext.volume); + s->F_k_p_1 = mkarr(app->use_gpu, app->basis.num_basis, s->local_ext.volume); + s->F_k_m_1 = mkarr(app->use_gpu, app->basis.num_basis, s->local_ext.volume); // allocate cflrate for distribution function and momentum updates (scalar arrays) s->cflrate_f = mkarr(app->use_gpu, 1, s->local_ext.volume); @@ -107,14 +106,13 @@ pkpm_species_init(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app, struct pkpm if (app->use_gpu) { s->omegaCfl_ptr_dist = gkyl_cu_malloc(sizeof(double)); s->omegaCfl_ptr_fluid = gkyl_cu_malloc(sizeof(double)); - } - else { + } else { s->omegaCfl_ptr_dist = gkyl_malloc(sizeof(double)); s->omegaCfl_ptr_fluid = gkyl_malloc(sizeof(double)); } // allocate array to store q/m*(E,B) if using a fully explicit update - s->qmem = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); + s->qmem = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); // pkpm moments for update (rho, p_par, p_perp, M1) pkpm_species_moment_init(app, s, &s->pkpm_moms, false); @@ -124,53 +122,56 @@ pkpm_species_init(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app, struct pkpm // div(p_par b_hat), for self-consistent total pressure force s->pkpm_div_ppar = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - // allocate array to store primitive moments : + // allocate array to store primitive moments : // [ux, uy, uz, 1/rho*div(p_par b), T_perp/m, m/T_perp, 3*T_xx/m, 3*T_yy/m, 3*T_zz/m] // pressure p_ij : (p_par - p_perp) b_i b_j + p_perp g_ij - s->pkpm_prim = mkarr(app->use_gpu, 9*app->confBasis.num_basis, app->local_ext.volume); - s->pkpm_u = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); - s->pkpm_p_ij = mkarr(app->use_gpu, 6*app->confBasis.num_basis, app->local_ext.volume); + s->pkpm_prim = mkarr(app->use_gpu, 9 * app->confBasis.num_basis, app->local_ext.volume); + s->pkpm_u = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); + s->pkpm_p_ij = mkarr(app->use_gpu, 6 * app->confBasis.num_basis, app->local_ext.volume); // boolean array for primitive variables [rho, p_par, p_perp] is negative at control points // *only used for diagnostic purposes* s->cell_avg_prim = mk_int_arr(app->use_gpu, 1, app->local_ext.volume); - int Nbasis_surf = app->confBasis.num_basis/(app->confBasis.poly_order + 1); // *only valid for tensor bases for cdim > 1* + int Nbasis_surf = app->confBasis.num_basis / + (app->confBasis.poly_order + 1); // *only valid for tensor bases for cdim > 1* // Surface primitive variables (2*cdim*4 components). Ordered as: - // [ux_xl, ux_xr, uy_xl, uy_xr, uz_xl, uz_xr, 3.0*Txx_xl/m, 3.0*Txx_xr/m, - // ux_yl, ux_yr, uy_yl, uy_yr, uz_yl, uz_yr, 3.0*Tyy_yl/m, 3.0*Tyy_yr/m, - // ux_zl, ux_zr, uy_zl, uy_zr, uz_zl, uz_zr, 3.0*Tzz_zl/m, 3.0*Tzz_zr/m] - s->pkpm_prim_surf = mkarr(app->use_gpu, 2*cdim*4*Nbasis_surf, app->local_ext.volume); + // [ux_xl, ux_xr, uy_xl, uy_xr, uz_xl, uz_xr, 3.0*Txx_xl/m, 3.0*Txx_xr/m, + // ux_yl, ux_yr, uy_yl, uy_yr, uz_yl, uz_yr, 3.0*Tyy_yl/m, 3.0*Tyy_yr/m, + // ux_zl, ux_zr, uy_zl, uy_zr, uz_zl, uz_zr, 3.0*Tzz_zl/m, 3.0*Tzz_zr/m] + s->pkpm_prim_surf = mkarr(app->use_gpu, 2 * cdim * 4 * Nbasis_surf, app->local_ext.volume); // Surface expansions of: // 1. Lax penalization maximum speed lambda_i = |u_i| + sqrt(3*P_ii/rho) // 2. Momentum solve penalization (either 10 moment Roe solve or Lax penalization) // Momentum penalization returns the full penalization, e.g., the modal surface expansion of // jump in the fluctuations from the 10 moment Roe solve 1/2 (A^+ Delta Q - A^- Delta Q) - s->pkpm_lax = mkarr(app->use_gpu, cdim*Nbasis_surf, app->local_ext.volume); - s->pkpm_penalization = mkarr(app->use_gpu, 3*cdim*Nbasis_surf, app->local_ext.volume); + s->pkpm_lax = mkarr(app->use_gpu, cdim * Nbasis_surf, app->local_ext.volume); + s->pkpm_penalization = mkarr(app->use_gpu, 3 * cdim * Nbasis_surf, app->local_ext.volume); - // allocate array for pkpm acceleration variables, stored in pkpm_accel: + // allocate array for pkpm acceleration variables, stored in pkpm_accel: // 0: p_perp_div_b (p_perp/rho*div(b) = T_perp/m*div(b)) // 1: bb_grad_u (bb : grad(u)) // 2: p_force (total pressure forces in kinetic equation 1/rho div(p_parallel b_hat) - T_perp/m*div(b) // 3: p_perp_source (pressure source for higher Laguerre moments -> bb : grad(u) - div(u) - 2*nu) - s->pkpm_accel = mkarr(app->use_gpu, 4*app->confBasis.num_basis, app->local_ext.volume); + s->pkpm_accel = mkarr(app->use_gpu, 4 * app->confBasis.num_basis, app->local_ext.volume); // Check if limiter_fac is specified for adjusting how much diffusion is applied through slope limiter // If not specified, set to 0.0 and updater sets default behavior (1/sqrt(3); see gkyl_dg_calc_pkpm_vars.h) double limiter_fac = s->info.limiter_fac == 0 ? 0.0 : s->info.limiter_fac; s->limit_fluid = s->info.limit_fluid; - // updater for computing pkpm variables + // updater for computing pkpm variables // pressure, primitive variables, and acceleration variables // also stores kernels for computing source terms, integrated variables // Two instances, one over extended range and one over local range for ease of handling boundary conditions - s->calc_pkpm_vars_ext = gkyl_dg_calc_pkpm_vars_new(&app->grid, &app->confBasis, &app->local_ext, - s->equation, app->geom, limiter_fac, app->use_gpu); - s->calc_pkpm_vars = gkyl_dg_calc_pkpm_vars_new(&app->grid, &app->confBasis, &app->local, - s->equation, app->geom, limiter_fac, app->use_gpu); + s->calc_pkpm_vars_ext = gkyl_dg_calc_pkpm_vars_new( + &app->grid, &app->confBasis, &app->local_ext, s->equation, app->geom, limiter_fac, app->use_gpu + ); + s->calc_pkpm_vars = gkyl_dg_calc_pkpm_vars_new( + &app->grid, &app->confBasis, &app->local, s->equation, app->geom, limiter_fac, app->use_gpu + ); // updater for computing pkpm distribution function variables // div(p_par b_hat) for self-consistent total pressure force and distribution function sources for - // Laguerre couplings and vperp characteristics + // Laguerre couplings and vperp characteristics s->calc_pkpm_dist_vars = gkyl_dg_calc_pkpm_dist_vars_new(&s->grid, &app->confBasis, app->use_gpu); // array for storing integrated fluid variables in each cell @@ -179,31 +180,42 @@ pkpm_species_init(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app, struct pkpm // arrays for I/O, fluid_io and pkpm_vars_io // fluid_io : [rho, rhoux, rhouy, rhouz, P_xx+rhoux^2, P_xy+rhouxuy, P_xz+rhouxuz, P_yy+rhouy^2, P_yz+rhouyuz, P_zz+rhouz^2] // pkpm_vars_io : [ux, uy, uz, T_perp/m, m/T_perp, 1/rho div(p_par b), p_perp/rho div(b), bb : grad(u)] - s->fluid_io = mkarr(app->use_gpu, 10*app->confBasis.num_basis, app->local_ext.volume); - s->pkpm_vars_io = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); + s->fluid_io = mkarr(app->use_gpu, 10 * app->confBasis.num_basis, app->local_ext.volume); + s->pkpm_vars_io = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); s->fluid_io_host = s->fluid_io; s->pkpm_vars_io_host = s->pkpm_vars_io; if (app->use_gpu) { - s->fluid_io_host = mkarr(false, 10*app->confBasis.num_basis, app->local_ext.volume); - s->pkpm_vars_io_host = mkarr(false, 8*app->confBasis.num_basis, app->local_ext.volume); + s->fluid_io_host = mkarr(false, 10 * app->confBasis.num_basis, app->local_ext.volume); + s->pkpm_vars_io_host = mkarr(false, 8 * app->confBasis.num_basis, app->local_ext.volume); } // by default, we do not have zero-flux boundary conditions in any direction bool is_zero_flux[GKYL_MAX_DIM] = {false}; - struct gkyl_dg_vlasov_pkpm_auxfields vlasov_pkpm_inp = {.bvar = app->field->bvar, .bvar_surf = app->field->bvar_surf, - .pkpm_prim = s->pkpm_prim, .pkpm_prim_surf = s->pkpm_prim_surf, - .max_b = app->field->max_b, .pkpm_lax = s->pkpm_lax, - .div_b = app->field->div_b, .pkpm_accel_vars = s->pkpm_accel, - .g_dist_source = s->g_dist_source}; - struct gkyl_dg_euler_pkpm_auxfields euler_pkpm_inp = {.vlasov_pkpm_moms = s->pkpm_moms.marr, - .pkpm_prim = s->pkpm_prim, .pkpm_prim_surf = s->pkpm_prim_surf, .pkpm_p_ij = s->pkpm_p_ij, - .pkpm_lax = s->pkpm_lax, .pkpm_penalization = s->pkpm_penalization}; + struct gkyl_dg_vlasov_pkpm_auxfields vlasov_pkpm_inp = { + .bvar = app->field->bvar, + .bvar_surf = app->field->bvar_surf, + .pkpm_prim = s->pkpm_prim, + .pkpm_prim_surf = s->pkpm_prim_surf, + .max_b = app->field->max_b, + .pkpm_lax = s->pkpm_lax, + .div_b = app->field->div_b, + .pkpm_accel_vars = s->pkpm_accel, + .g_dist_source = s->g_dist_source + }; + struct gkyl_dg_euler_pkpm_auxfields euler_pkpm_inp = { + .vlasov_pkpm_moms = s->pkpm_moms.marr, + .pkpm_prim = s->pkpm_prim, + .pkpm_prim_surf = s->pkpm_prim_surf, + .pkpm_p_ij = s->pkpm_p_ij, + .pkpm_lax = s->pkpm_lax, + .pkpm_penalization = s->pkpm_penalization + }; // create solver - s->slvr = gkyl_dg_updater_pkpm_new(&app->grid, &s->grid, - &app->confBasis, &app->basis, - &app->local, &s->local, - is_zero_flux, &vlasov_pkpm_inp, &euler_pkpm_inp, app->use_gpu); + s->slvr = gkyl_dg_updater_pkpm_new( + &app->grid, &s->grid, &app->confBasis, &app->basis, &app->local, &s->local, is_zero_flux, + &vlasov_pkpm_inp, &euler_pkpm_inp, app->use_gpu + ); // array for storing F_0^2 (0th Laguerre coefficient) in each cell s->L2_f = mkarr(app->use_gpu, 1, s->local_ext.volume); @@ -217,8 +229,8 @@ pkpm_species_init(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app, struct pkpm s->is_first_integ_L2_write_call = true; s->is_first_integ_write_call = true; - // Initialize applied acceleration for use in force update. - s->app_accel = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); + // Initialize applied acceleration for use in force update. + s->app_accel = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); gkyl_array_clear(s->app_accel, 0.0); s->has_app_accel = false; s->app_accel_evolve = false; @@ -231,12 +243,14 @@ pkpm_species_init(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app, struct pkpm s->app_accel_host = s->app_accel; if (app->use_gpu) { - s->app_accel_host = mkarr(false, 3*app->confBasis.num_basis, app->local_ext.volume); + s->app_accel_host = mkarr(false, 3 * app->confBasis.num_basis, app->local_ext.volume); } - s->app_accel_proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, app->confBasis.poly_order+1, - 3, s->info.app_accel, s->info.app_accel_ctx); + s->app_accel_proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->confBasis.poly_order + 1, 3, s->info.app_accel, + s->info.app_accel_ctx + ); } - + // determine collision type to use in PKPM update s->collision_id = s->info.collisions.collision_id; if (s->collision_id == GKYL_LBO_COLLISIONS) { @@ -244,190 +258,217 @@ pkpm_species_init(struct gkyl_pkpm *pkpm, struct gkyl_pkpm_app *app, struct pkpm } // initialize diffusion if present - s->has_diffusion = false; + s->has_diffusion = false; if (s->info.diffusion.D) { s->has_diffusion = true; - s->info.diffusion.order = s->info.diffusion.order<2? 2 : s->info.diffusion.order; + s->info.diffusion.order = s->info.diffusion.order < 2 ? 2 : s->info.diffusion.order; int num_eqn = 3; int szD = cdim; s->diffD = mkarr(app->use_gpu, szD, 1); struct gkyl_array *diffD_host = s->diffD; - if (app->use_gpu) + if (app->use_gpu) { diffD_host = mkarr(false, szD, 1); + } // Set diffusion coefficient in each direction to input value. gkyl_array_clear(diffD_host, 0.); - for (int d=0; dinfo.diffusion.D, d); + for (int d = 0; d < cdim; d++) { + gkyl_array_shiftc(diffD_host, s->info.diffusion.D, d); + } - if (app->use_gpu) {// note: diffD_host is same as diffD when not on GPUs + if (app->use_gpu) { // note: diffD_host is same as diffD when not on GPUs gkyl_array_copy(s->diffD, diffD_host); gkyl_array_release(diffD_host); } bool is_zero_flux[GKYL_MAX_CDIM] = {false}; - s->diff_slvr = gkyl_dg_updater_diffusion_fluid_new(&app->grid, &app->confBasis, - true, num_eqn, NULL, s->info.diffusion.order, &app->local, is_zero_flux, app->use_gpu); + s->diff_slvr = gkyl_dg_updater_diffusion_fluid_new( + &app->grid, &app->confBasis, true, num_eqn, NULL, s->info.diffusion.order, &app->local, + is_zero_flux, app->use_gpu + ); } // determine which directions are not periodic and get non-periodic BC info // also create local skin-ghost ranges for ease of handling non-periodic BCs int num_periodic_dir = app->num_periodic_dir, is_np[3] = {1, 1, 1}; - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int dir=0; dirlower_bc[dir] = s->upper_bc[dir] = GKYL_SPECIES_COPY; if (is_np[dir]) { const enum gkyl_species_bc_type *bc; - if (dir == 0) + if (dir == 0) { bc = s->info.bcx; - else if (dir == 1) + } else if (dir == 1) { bc = s->info.bcy; - else + } else { bc = s->info.bcz; + } s->lower_bc[dir] = bc[0]; s->upper_bc[dir] = bc[1]; } // Create local lower skin and ghost ranges for distribution function - gkyl_skin_ghost_ranges(&s->lower_skin_dist[dir], &s->lower_ghost_dist[dir], dir, GKYL_LOWER_EDGE, &s->local_ext, ghost); + gkyl_skin_ghost_ranges( + &s->lower_skin_dist[dir], &s->lower_ghost_dist[dir], dir, GKYL_LOWER_EDGE, &s->local_ext, + ghost + ); // Create local upper skin and ghost ranges for distribution function - gkyl_skin_ghost_ranges(&s->upper_skin_dist[dir], &s->upper_ghost_dist[dir], dir, GKYL_UPPER_EDGE, &s->local_ext, ghost); + gkyl_skin_ghost_ranges( + &s->upper_skin_dist[dir], &s->upper_ghost_dist[dir], dir, GKYL_UPPER_EDGE, &s->local_ext, + ghost + ); } // allocate buffer for applying BCs long buff_sz_dist = 0; long buff_sz_fluid = 0; // compute buffer size needed - for (int dir=0; dirlower_skin_dist[dir].volume, s->upper_skin_dist[dir].volume); buff_sz_dist = buff_sz_dist > vol_dist ? buff_sz_dist : vol_dist; long vol_fluid = GKYL_MAX2(app->lower_skin[dir].volume, app->upper_skin[dir].volume); buff_sz_fluid = buff_sz_fluid > vol_fluid ? buff_sz_fluid : vol_fluid; } - s->bc_buffer_dist = mkarr(app->use_gpu, 2*app->basis.num_basis, buff_sz_dist); + s->bc_buffer_dist = mkarr(app->use_gpu, 2 * app->basis.num_basis, buff_sz_dist); // buffer arrays for fixed function boundary conditions on distribution function - s->bc_buffer_lo_fixed_dist = mkarr(app->use_gpu, 2*app->basis.num_basis, buff_sz_dist); - s->bc_buffer_up_fixed_dist = mkarr(app->use_gpu, 2*app->basis.num_basis, buff_sz_dist); + s->bc_buffer_lo_fixed_dist = mkarr(app->use_gpu, 2 * app->basis.num_basis, buff_sz_dist); + s->bc_buffer_up_fixed_dist = mkarr(app->use_gpu, 2 * app->basis.num_basis, buff_sz_dist); - s->bc_buffer_fluid = mkarr(app->use_gpu, 3*app->confBasis.num_basis, buff_sz_fluid); + s->bc_buffer_fluid = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, buff_sz_fluid); // buffer arrays for fixed function boundary conditions on momentum - s->bc_buffer_lo_fixed_fluid = mkarr(app->use_gpu, 3*app->confBasis.num_basis, buff_sz_fluid); - s->bc_buffer_up_fixed_fluid = mkarr(app->use_gpu, 3*app->confBasis.num_basis, buff_sz_fluid); + s->bc_buffer_lo_fixed_fluid = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, buff_sz_fluid); + s->bc_buffer_up_fixed_fluid = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, buff_sz_fluid); - // Certain operations fail if absorbing BCs used because absorbing BCs + // Certain operations fail if absorbing BCs used because absorbing BCs // means the mass density is 0 in the ghost cells (divide by zero) s->bc_is_absorb = false; - for (int d=0; dlower_bc[d] == GKYL_SPECIES_COPY) { bctype_dist = GKYL_BC_COPY; bctype_fluid = GKYL_BC_COPY; - } - else if (s->lower_bc[d] == GKYL_SPECIES_ABSORB) { + } else if (s->lower_bc[d] == GKYL_SPECIES_ABSORB) { bctype_dist = GKYL_BC_ABSORB; bctype_fluid = GKYL_BC_ABSORB; s->bc_is_absorb = true; - } - else if (s->lower_bc[d] == GKYL_SPECIES_REFLECT) { + } else if (s->lower_bc[d] == GKYL_SPECIES_REFLECT) { bctype_dist = GKYL_BC_PKPM_SPECIES_REFLECT; bctype_fluid = GKYL_BC_PKPM_MOM_REFLECT; - } - else if (s->lower_bc[d] == GKYL_SPECIES_FIXED_FUNC) { + } else if (s->lower_bc[d] == GKYL_SPECIES_FIXED_FUNC) { bctype_dist = GKYL_BC_FIXED_FUNC; bctype_fluid = GKYL_BC_FIXED_FUNC; } // Distribution function non-periodic lower boundary conditions - s->bc_lo_dist[d] = gkyl_bc_basic_new(d, GKYL_LOWER_EDGE, bctype_dist, app->basis_on_dev.basis, - &s->lower_skin_dist[d], &s->lower_ghost_dist[d], s->f->ncomp, app->cdim, app->use_gpu); + s->bc_lo_dist[d] = gkyl_bc_basic_new( + d, GKYL_LOWER_EDGE, bctype_dist, app->basis_on_dev.basis, &s->lower_skin_dist[d], + &s->lower_ghost_dist[d], s->f->ncomp, app->cdim, app->use_gpu + ); // Momentum non-periodic lower boundary conditions - s->bc_lo_fluid[d] = gkyl_bc_basic_new(d, GKYL_LOWER_EDGE, bctype_fluid, app->basis_on_dev.confBasis, - &app->lower_skin[d], &app->lower_ghost[d], s->fluid->ncomp, app->cdim, app->use_gpu); + s->bc_lo_fluid[d] = gkyl_bc_basic_new( + d, GKYL_LOWER_EDGE, bctype_fluid, app->basis_on_dev.confBasis, &app->lower_skin[d], + &app->lower_ghost[d], s->fluid->ncomp, app->cdim, app->use_gpu + ); // Upper BC updater. Copy BCs by default. if (s->upper_bc[d] == GKYL_SPECIES_COPY) { bctype_dist = GKYL_BC_COPY; bctype_fluid = GKYL_BC_COPY; - } - else if (s->upper_bc[d] == GKYL_SPECIES_ABSORB) { + } else if (s->upper_bc[d] == GKYL_SPECIES_ABSORB) { bctype_dist = GKYL_BC_ABSORB; bctype_fluid = GKYL_BC_ABSORB; s->bc_is_absorb = true; - } - else if (s->upper_bc[d] == GKYL_SPECIES_REFLECT) { + } else if (s->upper_bc[d] == GKYL_SPECIES_REFLECT) { bctype_dist = GKYL_BC_PKPM_SPECIES_REFLECT; bctype_fluid = GKYL_BC_PKPM_MOM_REFLECT; - } - else if (s->upper_bc[d] == GKYL_SPECIES_FIXED_FUNC) { + } else if (s->upper_bc[d] == GKYL_SPECIES_FIXED_FUNC) { bctype_dist = GKYL_BC_FIXED_FUNC; bctype_fluid = GKYL_BC_FIXED_FUNC; } // Distribution function non-periodic upper boundary conditions - s->bc_up_dist[d] = gkyl_bc_basic_new(d, GKYL_UPPER_EDGE, bctype_dist, app->basis_on_dev.basis, - &s->upper_skin_dist[d], &s->upper_ghost_dist[d], s->f->ncomp, app->cdim, app->use_gpu); + s->bc_up_dist[d] = gkyl_bc_basic_new( + d, GKYL_UPPER_EDGE, bctype_dist, app->basis_on_dev.basis, &s->upper_skin_dist[d], + &s->upper_ghost_dist[d], s->f->ncomp, app->cdim, app->use_gpu + ); // Momentum non-periodic upper boundary conditions - s->bc_up_fluid[d] = gkyl_bc_basic_new(d, GKYL_UPPER_EDGE, bctype_fluid, app->basis_on_dev.confBasis, - &app->upper_skin[d], &app->upper_ghost[d], s->fluid->ncomp, app->cdim, app->use_gpu); + s->bc_up_fluid[d] = gkyl_bc_basic_new( + d, GKYL_UPPER_EDGE, bctype_fluid, app->basis_on_dev.confBasis, &app->upper_skin[d], + &app->upper_ghost[d], s->fluid->ncomp, app->cdim, app->use_gpu + ); } } -void -pkpm_species_apply_ic(gkyl_pkpm_app *app, struct pkpm_species *species, double t0) +void pkpm_species_apply_ic(gkyl_pkpm_app *app, struct pkpm_species *species, double t0) { int poly_order = app->poly_order; gkyl_proj_on_basis *proj_dist; - proj_dist = gkyl_proj_on_basis_new(&species->grid, &app->basis, - 8, 2, species->info.init_dist, species->info.ctx_dist); + proj_dist = gkyl_proj_on_basis_new( + &species->grid, &app->basis, 8, 2, species->info.init_dist, species->info.ctx_dist + ); gkyl_proj_on_basis *proj_fluid; - proj_fluid = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - poly_order+1, 3, species->info.init_fluid, species->info.ctx_fluid); + proj_fluid = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, poly_order + 1, 3, species->info.init_fluid, + species->info.ctx_fluid + ); // run updaters; need to project onto extended range for ease of handling // subsequent operations over extended range such as primitive variable computations // This is needed to fill the corner cells as the corner cells may not be filled by // boundary conditions and we cannot divide by 0 anywhere or the weak divisions will fail gkyl_proj_on_basis_advance(proj_dist, t0, &species->local_ext, species->f_host); - gkyl_proj_on_basis_release(proj_dist); + gkyl_proj_on_basis_release(proj_dist); gkyl_proj_on_basis_advance(proj_fluid, t0, &app->local_ext, species->fluid_host); - gkyl_proj_on_basis_release(proj_fluid); + gkyl_proj_on_basis_release(proj_fluid); // note: f_host and fluid_host are the same as f and fluid respectively when not on GPUs if (app->use_gpu) { gkyl_array_copy(species->f, species->f_host); gkyl_array_copy(species->fluid, species->fluid_host); - } + } // we are pre-computing acceleration for now in case is time-independent pkpm_species_calc_app_accel(app, species, t0); // copy contents of initial conditions into buffer if specific BCs require them // *only works in x dimension for now* - gkyl_bc_basic_buffer_fixed_func(species->bc_lo_dist[0], species->bc_buffer_lo_fixed_dist, species->f); - gkyl_bc_basic_buffer_fixed_func(species->bc_up_dist[0], species->bc_buffer_up_fixed_dist, species->f); - gkyl_bc_basic_buffer_fixed_func(species->bc_lo_fluid[0], species->bc_buffer_lo_fixed_fluid, species->fluid); - gkyl_bc_basic_buffer_fixed_func(species->bc_up_fluid[0], species->bc_buffer_up_fixed_fluid, species->fluid); + gkyl_bc_basic_buffer_fixed_func( + species->bc_lo_dist[0], species->bc_buffer_lo_fixed_dist, species->f + ); + gkyl_bc_basic_buffer_fixed_func( + species->bc_up_dist[0], species->bc_buffer_up_fixed_dist, species->f + ); + gkyl_bc_basic_buffer_fixed_func( + species->bc_lo_fluid[0], species->bc_buffer_lo_fixed_fluid, species->fluid + ); + gkyl_bc_basic_buffer_fixed_func( + species->bc_up_fluid[0], species->bc_buffer_up_fixed_fluid, species->fluid + ); } -void -pkpm_species_calc_app_accel(gkyl_pkpm_app *app, struct pkpm_species *species, double tm) +void pkpm_species_calc_app_accel(gkyl_pkpm_app *app, struct pkpm_species *species, double tm) { if (species->has_app_accel) { - gkyl_proj_on_basis_advance(species->app_accel_proj, tm, &app->local_ext, species->app_accel_host); + gkyl_proj_on_basis_advance( + species->app_accel_proj, tm, &app->local_ext, species->app_accel_host + ); if (app->use_gpu) { // note: app_accel_host is same as app_accel when not on GPUs - gkyl_array_copy(species->app_accel, species->app_accel_host); + gkyl_array_copy(species->app_accel, species->app_accel_host); } } } -void -pkpm_species_calc_pkpm_vars(gkyl_pkpm_app *app, struct pkpm_species *species, - const struct gkyl_array *fin, const struct gkyl_array *fluidin) +void pkpm_species_calc_pkpm_vars( + gkyl_pkpm_app *app, struct pkpm_species *species, const struct gkyl_array *fin, + const struct gkyl_array *fluidin +) { struct timespec tm = gkyl_wall_clock(); @@ -437,86 +478,88 @@ pkpm_species_calc_pkpm_vars(gkyl_pkpm_app *app, struct pkpm_species *species, gkyl_array_clear(species->pkpm_prim_surf, 0.0); // Compute rho, p_par, & p_perp - pkpm_species_moment_calc(&species->pkpm_moms, species->local_ext, - app->local_ext, fin); + pkpm_species_moment_calc(&species->pkpm_moms, species->local_ext, app->local_ext, fin); // Compute div(p_par b_hat) for consistent pressure force in vpar acceleration - gkyl_dg_calc_pkpm_dist_vars_div_ppar(species->calc_pkpm_dist_vars, - &app->local, &species->local, - app->field->bvar_surf, app->field->bvar, fin, - app->field->max_b, species->pkpm_div_ppar); + gkyl_dg_calc_pkpm_dist_vars_div_ppar( + species->calc_pkpm_dist_vars, &app->local, &species->local, app->field->bvar_surf, + app->field->bvar, fin, app->field->max_b, species->pkpm_div_ppar + ); gkyl_array_scale(species->pkpm_div_ppar, species->info.mass); // Compute p_ij = (p_par - p_perp) b_i b_j + p_perp g_ij in the volume - gkyl_dg_calc_pkpm_vars_pressure(species->calc_pkpm_vars, &app->local_ext, - app->field->bvar, species->pkpm_moms.marr, species->pkpm_p_ij); + gkyl_dg_calc_pkpm_vars_pressure( + species->calc_pkpm_vars, &app->local_ext, app->field->bvar, species->pkpm_moms.marr, + species->pkpm_p_ij + ); // Compute primitive variables in both the volume and on surfaces if (species->bc_is_absorb) { - gkyl_dg_calc_pkpm_vars_advance(species->calc_pkpm_vars, - species->pkpm_moms.marr, fluidin, - species->pkpm_p_ij, species->pkpm_div_ppar, - species->cell_avg_prim, species->pkpm_prim, species->pkpm_prim_surf); - } - else { - gkyl_dg_calc_pkpm_vars_advance(species->calc_pkpm_vars_ext, - species->pkpm_moms.marr, fluidin, - species->pkpm_p_ij, species->pkpm_div_ppar, - species->cell_avg_prim, species->pkpm_prim, species->pkpm_prim_surf); + gkyl_dg_calc_pkpm_vars_advance( + species->calc_pkpm_vars, species->pkpm_moms.marr, fluidin, species->pkpm_p_ij, + species->pkpm_div_ppar, species->cell_avg_prim, species->pkpm_prim, species->pkpm_prim_surf + ); + } else { + gkyl_dg_calc_pkpm_vars_advance( + species->calc_pkpm_vars_ext, species->pkpm_moms.marr, fluidin, species->pkpm_p_ij, + species->pkpm_div_ppar, species->cell_avg_prim, species->pkpm_prim, species->pkpm_prim_surf + ); } // Compute the penalization terms, both the maximum speed used in Lax fluxes // and the total momentum penalization (either 10 moment Roe solve or Lax penalization) gkyl_array_clear(species->pkpm_lax, 0.0); gkyl_array_clear(species->pkpm_penalization, 0.0); - gkyl_dg_calc_pkpm_vars_penalization(species->calc_pkpm_vars, - &app->local, &app->local_ext, - species->pkpm_moms.marr, species->pkpm_p_ij, species->pkpm_prim, fluidin, - species->pkpm_lax, species->pkpm_penalization); + gkyl_dg_calc_pkpm_vars_penalization( + species->calc_pkpm_vars, &app->local, &app->local_ext, species->pkpm_moms.marr, + species->pkpm_p_ij, species->pkpm_prim, fluidin, species->pkpm_lax, species->pkpm_penalization + ); app->stat.species_pkpm_vars_tm += gkyl_time_diff_now_sec(tm); } -void -pkpm_species_calc_pkpm_update_vars(gkyl_pkpm_app *app, struct pkpm_species *species, - const struct gkyl_array *fin) +void pkpm_species_calc_pkpm_update_vars( + gkyl_pkpm_app *app, struct pkpm_species *species, const struct gkyl_array *fin +) { struct timespec tm = gkyl_wall_clock(); gkyl_array_clear(species->pkpm_accel, 0.0); // Incremented in each dimension, so clear beforehand - gkyl_dg_calc_pkpm_vars_accel(species->calc_pkpm_vars, &app->local, - species->pkpm_prim_surf, species->pkpm_prim, - app->field->bvar, app->field->div_b, species->lbo.nu_sum, - species->pkpm_accel); + gkyl_dg_calc_pkpm_vars_accel( + species->calc_pkpm_vars, &app->local, species->pkpm_prim_surf, species->pkpm_prim, + app->field->bvar, app->field->div_b, species->lbo.nu_sum, species->pkpm_accel + ); // Calculate distrbution functions for coupling different Laguerre moments - gkyl_dg_calc_pkpm_dist_vars_mirror_force(species->calc_pkpm_dist_vars, - &app->local, &species->local, - species->pkpm_prim, species->lbo.nu_prim_moms, - app->field->div_b, species->pkpm_accel, - fin, species->F_k_p_1, - species->g_dist_source, species->F_k_m_1); + gkyl_dg_calc_pkpm_dist_vars_mirror_force( + species->calc_pkpm_dist_vars, &app->local, &species->local, species->pkpm_prim, + species->lbo.nu_prim_moms, app->field->div_b, species->pkpm_accel, fin, species->F_k_p_1, + species->g_dist_source, species->F_k_m_1 + ); app->stat.species_pkpm_vars_tm += gkyl_time_diff_now_sec(tm); } -void -pkpm_fluid_species_limiter(gkyl_pkpm_app *app, struct pkpm_species *species, - struct gkyl_array *fin, struct gkyl_array *fluid) +void pkpm_fluid_species_limiter( + gkyl_pkpm_app *app, struct pkpm_species *species, struct gkyl_array *fin, struct gkyl_array *fluid +) { - if (species->limit_fluid) { + if (species->limit_fluid) { struct timespec tm = gkyl_wall_clock(); - // Compute the PKPM moments from the kinetic equation + // Compute the PKPM moments from the kinetic equation pkpm_species_moment_calc(&species->pkpm_moms, species->local, app->local, fin); - // Compute the flow velocity - gkyl_dg_calc_pkpm_vars_u(species->calc_pkpm_vars, - species->pkpm_moms.marr, fluid, - species->cell_avg_prim, species->pkpm_u); + // Compute the flow velocity + gkyl_dg_calc_pkpm_vars_u( + species->calc_pkpm_vars, species->pkpm_moms.marr, fluid, species->cell_avg_prim, + species->pkpm_u + ); // Limit the slopes of the solution of the fluid system - gkyl_dg_calc_pkpm_vars_limiter(species->calc_pkpm_vars, &app->local, species->pkpm_u, - species->pkpm_moms.marr, species->pkpm_p_ij, fluid); + gkyl_dg_calc_pkpm_vars_limiter( + species->calc_pkpm_vars, &app->local, species->pkpm_u, species->pkpm_moms.marr, + species->pkpm_p_ij, fluid + ); app->stat.species_pkpm_vars_tm += gkyl_time_diff_now_sec(tm); @@ -527,34 +570,35 @@ pkpm_fluid_species_limiter(gkyl_pkpm_app *app, struct pkpm_species *species, // Compute the RHS for species update, returning maximum stable // time-step. -double -pkpm_species_rhs(gkyl_pkpm_app *app, struct pkpm_species *species, - const struct gkyl_array *fin, const struct gkyl_array *fluidin, const struct gkyl_array *em, - struct gkyl_array *rhs_f, struct gkyl_array *rhs_fluid) +double pkpm_species_rhs( + gkyl_pkpm_app *app, struct pkpm_species *species, const struct gkyl_array *fin, + const struct gkyl_array *fluidin, const struct gkyl_array *em, struct gkyl_array *rhs_f, + struct gkyl_array *rhs_fluid +) { gkyl_array_clear(species->cflrate_f, 0.0); gkyl_array_clear(species->cflrate_fluid, 0.0); gkyl_array_clear(rhs_f, 0.0); gkyl_array_clear(rhs_fluid, 0.0); - gkyl_dg_updater_pkpm_advance(species->slvr, - &species->local, &app->local, - fin, fluidin, - species->cflrate_f, species->cflrate_fluid, - rhs_f, rhs_fluid); + gkyl_dg_updater_pkpm_advance( + species->slvr, &species->local, &app->local, fin, fluidin, species->cflrate_f, + species->cflrate_fluid, rhs_f, rhs_fluid + ); if (species->collision_id == GKYL_LBO_COLLISIONS) { pkpm_species_lbo_rhs(app, species, &species->lbo, fin, rhs_f); } if (species->has_diffusion) { - gkyl_dg_updater_diffusion_fluid_advance(species->diff_slvr, - &app->local, species->diffD, fluidin, species->cflrate_fluid, rhs_fluid); + gkyl_dg_updater_diffusion_fluid_advance( + species->diff_slvr, &app->local, species->diffD, fluidin, species->cflrate_fluid, rhs_fluid + ); } // If PKPM update is fully explicit, include the fluid-EM coupling in fluid update - if (app->use_explicit_source) { - double qbym = species->info.charge/species->info.mass; + if (app->use_explicit_source) { + double qbym = species->info.charge / species->info.mass; gkyl_array_set(species->qmem, qbym, em); // Accumulate applied acceleration and/or q/m*(external electromagnetic) @@ -563,25 +607,30 @@ pkpm_species_rhs(gkyl_pkpm_app *app, struct pkpm_species *species, gkyl_array_accumulate_range(species->qmem, 1.0, species->app_accel, &app->local); } if (app->field->has_ext_em) { - gkyl_array_accumulate_range(species->qmem, qbym, app->field->ext_em, &app->local); + gkyl_array_accumulate_range(species->qmem, qbym, app->field->ext_em, &app->local); } - gkyl_dg_calc_pkpm_vars_source(species->calc_pkpm_vars, &app->local, - species->qmem, species->pkpm_moms.marr, fluidin, rhs_fluid); + gkyl_dg_calc_pkpm_vars_source( + species->calc_pkpm_vars, &app->local, species->qmem, species->pkpm_moms.marr, fluidin, + rhs_fluid + ); } - app->stat.n_species_omega_cfl +=1; + app->stat.n_species_omega_cfl += 1; struct timespec tm = gkyl_wall_clock(); gkyl_array_reduce_range(species->omegaCfl_ptr_dist, species->cflrate_f, GKYL_MAX, &species->local); - gkyl_array_reduce_range(species->omegaCfl_ptr_fluid, species->cflrate_fluid, GKYL_MAX, &app->local); + gkyl_array_reduce_range( + species->omegaCfl_ptr_fluid, species->cflrate_fluid, GKYL_MAX, &app->local + ); double omegaCfl_ho_dist[1]; double omegaCfl_ho_fluid[1]; if (app->use_gpu) { gkyl_cu_memcpy(omegaCfl_ho_dist, species->omegaCfl_ptr_dist, sizeof(double), GKYL_CU_MEMCPY_D2H); - gkyl_cu_memcpy(omegaCfl_ho_fluid, species->omegaCfl_ptr_fluid, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + omegaCfl_ho_fluid, species->omegaCfl_ptr_fluid, sizeof(double), GKYL_CU_MEMCPY_D2H + ); + } else { omegaCfl_ho_dist[0] = species->omegaCfl_ptr_dist[0]; omegaCfl_ho_fluid[0] = species->omegaCfl_ptr_fluid[0]; } @@ -589,61 +638,62 @@ pkpm_species_rhs(gkyl_pkpm_app *app, struct pkpm_species *species, app->stat.species_omega_cfl_tm += gkyl_time_diff_now_sec(tm); - return app->cfl/omegaCfl; + return app->cfl / omegaCfl; } // Determine which directions are periodic and which directions are not periodic, // and then apply boundary conditions for distribution function -void -pkpm_species_apply_bc(gkyl_pkpm_app *app, const struct pkpm_species *species, - struct gkyl_array *f) +void pkpm_species_apply_bc( + gkyl_pkpm_app *app, const struct pkpm_species *species, struct gkyl_array *f +) { struct timespec wst = gkyl_wall_clock(); - + int num_periodic_dir = app->num_periodic_dir, cdim = app->cdim; - gkyl_comm_array_per_sync(species->comm, &species->local, &species->local_ext, - num_periodic_dir, app->periodic_dirs, f); + gkyl_comm_array_per_sync( + species->comm, &species->local, &species->local_ext, num_periodic_dir, app->periodic_dirs, f + ); int is_np_bc[3] = {1, 1, 1}; // flags to indicate if direction is periodic - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int d=0; dlower_bc[d]) { - case GKYL_SPECIES_COPY: - case GKYL_SPECIES_REFLECT: - case GKYL_SPECIES_ABSORB: - gkyl_bc_basic_advance(species->bc_lo_dist[d], species->bc_buffer_dist, f); - break; - case GKYL_SPECIES_FIXED_FUNC: - gkyl_bc_basic_advance(species->bc_lo_dist[d], species->bc_buffer_lo_fixed_dist, f); - break; - case GKYL_SPECIES_NO_SLIP: - case GKYL_SPECIES_WEDGE: - assert(false); - break; - default: - break; + case GKYL_SPECIES_COPY: + case GKYL_SPECIES_REFLECT: + case GKYL_SPECIES_ABSORB: + gkyl_bc_basic_advance(species->bc_lo_dist[d], species->bc_buffer_dist, f); + break; + case GKYL_SPECIES_FIXED_FUNC: + gkyl_bc_basic_advance(species->bc_lo_dist[d], species->bc_buffer_lo_fixed_dist, f); + break; + case GKYL_SPECIES_NO_SLIP: + case GKYL_SPECIES_WEDGE: + assert(false); + break; + default: + break; } switch (species->upper_bc[d]) { - case GKYL_SPECIES_COPY: - case GKYL_SPECIES_REFLECT: - case GKYL_SPECIES_ABSORB: - gkyl_bc_basic_advance(species->bc_up_dist[d], species->bc_buffer_dist, f); - break; - case GKYL_SPECIES_FIXED_FUNC: - gkyl_bc_basic_advance(species->bc_up_dist[d], species->bc_buffer_up_fixed_dist, f); - break; - case GKYL_SPECIES_NO_SLIP: - case GKYL_SPECIES_WEDGE: - assert(false); - break; - default: - break; - } + case GKYL_SPECIES_COPY: + case GKYL_SPECIES_REFLECT: + case GKYL_SPECIES_ABSORB: + gkyl_bc_basic_advance(species->bc_up_dist[d], species->bc_buffer_dist, f); + break; + case GKYL_SPECIES_FIXED_FUNC: + gkyl_bc_basic_advance(species->bc_up_dist[d], species->bc_buffer_up_fixed_dist, f); + break; + case GKYL_SPECIES_NO_SLIP: + case GKYL_SPECIES_WEDGE: + assert(false); + break; + default: + break; + } } } @@ -654,56 +704,57 @@ pkpm_species_apply_bc(gkyl_pkpm_app *app, const struct pkpm_species *species, // Determine which directions are periodic and which directions are not periodic, // and then apply boundary conditions for distribution function -void -pkpm_fluid_species_apply_bc(gkyl_pkpm_app *app, const struct pkpm_species *species, - struct gkyl_array *fluid) +void pkpm_fluid_species_apply_bc( + gkyl_pkpm_app *app, const struct pkpm_species *species, struct gkyl_array *fluid +) { struct timespec wst = gkyl_wall_clock(); - + int num_periodic_dir = app->num_periodic_dir, cdim = app->cdim; - gkyl_comm_array_per_sync(app->comm, &app->local, &app->local_ext, - num_periodic_dir, app->periodic_dirs, fluid); + gkyl_comm_array_per_sync( + app->comm, &app->local, &app->local_ext, num_periodic_dir, app->periodic_dirs, fluid + ); int is_np_bc[3] = {1, 1, 1}; // flags to indicate if direction is periodic - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int d=0; dlower_bc[d]) { - case GKYL_SPECIES_COPY: - case GKYL_SPECIES_REFLECT: - case GKYL_SPECIES_ABSORB: - gkyl_bc_basic_advance(species->bc_lo_fluid[d], species->bc_buffer_fluid, fluid); - break; - case GKYL_SPECIES_FIXED_FUNC: - gkyl_bc_basic_advance(species->bc_lo_fluid[d], species->bc_buffer_lo_fixed_fluid, fluid); - break; - case GKYL_SPECIES_NO_SLIP: - case GKYL_SPECIES_WEDGE: - assert(false); - break; - default: - break; + case GKYL_SPECIES_COPY: + case GKYL_SPECIES_REFLECT: + case GKYL_SPECIES_ABSORB: + gkyl_bc_basic_advance(species->bc_lo_fluid[d], species->bc_buffer_fluid, fluid); + break; + case GKYL_SPECIES_FIXED_FUNC: + gkyl_bc_basic_advance(species->bc_lo_fluid[d], species->bc_buffer_lo_fixed_fluid, fluid); + break; + case GKYL_SPECIES_NO_SLIP: + case GKYL_SPECIES_WEDGE: + assert(false); + break; + default: + break; } switch (species->upper_bc[d]) { - case GKYL_SPECIES_COPY: - case GKYL_SPECIES_REFLECT: - case GKYL_SPECIES_ABSORB: - gkyl_bc_basic_advance(species->bc_up_fluid[d], species->bc_buffer_fluid, fluid); - break; - case GKYL_SPECIES_FIXED_FUNC: - gkyl_bc_basic_advance(species->bc_up_fluid[d], species->bc_buffer_up_fixed_fluid, fluid); - break; - case GKYL_SPECIES_NO_SLIP: - case GKYL_SPECIES_WEDGE: - assert(false); - break; - default: - break; - } + case GKYL_SPECIES_COPY: + case GKYL_SPECIES_REFLECT: + case GKYL_SPECIES_ABSORB: + gkyl_bc_basic_advance(species->bc_up_fluid[d], species->bc_buffer_fluid, fluid); + break; + case GKYL_SPECIES_FIXED_FUNC: + gkyl_bc_basic_advance(species->bc_up_fluid[d], species->bc_buffer_up_fixed_fluid, fluid); + break; + case GKYL_SPECIES_NO_SLIP: + case GKYL_SPECIES_WEDGE: + assert(false); + break; + default: + break; + } } } @@ -712,30 +763,27 @@ pkpm_fluid_species_apply_bc(gkyl_pkpm_app *app, const struct pkpm_species *speci app->stat.species_bc_tm += gkyl_time_diff_now_sec(wst); } -void -pkpm_species_calc_L2(gkyl_pkpm_app *app, double tm, const struct pkpm_species *species) +void pkpm_species_calc_L2(gkyl_pkpm_app *app, double tm, const struct pkpm_species *species) { gkyl_dg_calc_l2_range(&app->basis, 0, species->L2_f, 0, species->f, species->local); gkyl_array_scale_range(species->L2_f, species->grid.cellVolume, &species->local); - - double L2[1] = { 0.0 }; + + double L2[1] = {0.0}; if (app->use_gpu) { gkyl_array_reduce_range(species->red_L2_f, species->L2_f, GKYL_SUM, &species->local); gkyl_cu_memcpy(L2, species->red_L2_f, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { gkyl_array_reduce_range(L2, species->L2_f, GKYL_SUM, &species->local); } - double L2_global[1] = { 0.0 }; + double L2_global[1] = {0.0}; gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, L2, L2_global); - - gkyl_dynvec_append(species->integ_L2_f, tm, L2_global); + + gkyl_dynvec_append(species->integ_L2_f, tm, L2_global); } -void -pkpm_species_coll_tm(gkyl_pkpm_app *app) +void pkpm_species_coll_tm(gkyl_pkpm_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { if (app->species[i].collision_id == GKYL_LBO_COLLISIONS) { struct gkyl_dg_updater_lbo_pkpm_tm tm = gkyl_dg_updater_lbo_pkpm_get_tm(app->species[i].lbo.coll_slvr); @@ -745,22 +793,19 @@ pkpm_species_coll_tm(gkyl_pkpm_app *app) } } -void -pkpm_species_tm(gkyl_pkpm_app *app) +void pkpm_species_tm(gkyl_pkpm_app *app) { app->stat.species_rhs_tm = 0.0; app->stat.fluid_species_rhs_tm = 0.0; - for (int i=0; inum_species; ++i) { - struct gkyl_dg_updater_pkpm_tm tm = - gkyl_dg_updater_pkpm_get_tm(app->species[i].slvr); + for (int i = 0; i < app->num_species; ++i) { + struct gkyl_dg_updater_pkpm_tm tm = gkyl_dg_updater_pkpm_get_tm(app->species[i].slvr); app->stat.species_rhs_tm += tm.vlasov_tm; app->stat.fluid_species_rhs_tm += tm.fluid_tm; } } // release resources for PKPM species -void -pkpm_species_release(const gkyl_pkpm_app* app, const struct pkpm_species *s) +void pkpm_species_release(const gkyl_pkpm_app *app, const struct pkpm_species *s) { // release various arrays gkyl_array_release(s->f); @@ -790,7 +835,7 @@ pkpm_species_release(const gkyl_pkpm_app* app, const struct pkpm_species *s) gkyl_array_release(s->fluid_host); } - gkyl_array_release(s->qmem); + gkyl_array_release(s->qmem); // release moment data pkpm_species_moment_release(app, &s->pkpm_moms); @@ -821,7 +866,7 @@ pkpm_species_release(const gkyl_pkpm_app* app, const struct pkpm_species *s) gkyl_array_release(s->L2_f); gkyl_dynvec_release(s->integ_L2_f); gkyl_dynvec_release(s->integ_diag); - + gkyl_array_release(s->app_accel); if (s->has_app_accel) { if (app->use_gpu) { @@ -835,20 +880,19 @@ pkpm_species_release(const gkyl_pkpm_app* app, const struct pkpm_species *s) } // Copy BCs are allocated by default. Need to free. - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { gkyl_bc_basic_release(s->bc_lo_dist[d]); gkyl_bc_basic_release(s->bc_up_dist[d]); gkyl_bc_basic_release(s->bc_lo_fluid[d]); gkyl_bc_basic_release(s->bc_up_fluid[d]); } - + if (app->use_gpu) { gkyl_cu_free(s->omegaCfl_ptr_dist); gkyl_cu_free(s->omegaCfl_ptr_fluid); gkyl_cu_free(s->red_L2_f); gkyl_cu_free(s->red_integ_diag); - } - else { + } else { gkyl_free(s->omegaCfl_ptr_dist); gkyl_free(s->omegaCfl_ptr_fluid); } diff --git a/pkpm/apps/pkpm_species_lbo.c b/pkpm/apps/pkpm_species_lbo.c index 2838d9064f..01e6a30043 100644 --- a/pkpm/apps/pkpm_species_lbo.c +++ b/pkpm/apps/pkpm_species_lbo.c @@ -1,12 +1,13 @@ #include #include -void -pkpm_species_lbo_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, struct pkpm_lbo_collisions *lbo) +void pkpm_species_lbo_init( + struct gkyl_pkpm_app *app, struct pkpm_species *s, struct pkpm_lbo_collisions *lbo +) { int cdim = app->cdim, vdim = app->vdim; - double v_bounds[2*GKYL_MAX_DIM]; - for (int d=0; dinfo.lower[d]; v_bounds[d + vdim] = s->info.upper[d]; } @@ -17,9 +18,11 @@ pkpm_species_lbo_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, struct struct gkyl_array *self_nu = mkarr(false, app->confBasis.num_basis, app->local_ext.volume); lbo->num_cross_collisions = s->info.collisions.num_cross_collisions; - - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - app->poly_order+1, 1, s->info.collisions.self_nu, s->info.collisions.ctx); + + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->poly_order + 1, 1, s->info.collisions.self_nu, + s->info.collisions.ctx + ); gkyl_proj_on_basis_advance(proj, 0.0, &app->local, self_nu); gkyl_proj_on_basis_release(proj); gkyl_array_copy(lbo->self_nu, self_nu); @@ -33,8 +36,9 @@ pkpm_species_lbo_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, struct double nuFrac = s->info.collisions.nuFrac ? s->info.collisions.nuFrac : 1.0; double eps0 = app->field->info.epsilon0 ? app->field->info.epsilon0 : 1.0; double hbar = s->info.collisions.hbar ? s->info.collisions.hbar : 1.0; - lbo->spitzer_calc = gkyl_spitzer_coll_freq_new(&app->confBasis, app->poly_order+1, - nuFrac, eps0, hbar, app->use_gpu); + lbo->spitzer_calc = gkyl_spitzer_coll_freq_new( + &app->confBasis, app->poly_order + 1, nuFrac, eps0, hbar, app->use_gpu + ); // Create arrays for scaling collisionality by normalization factor // norm_nu is computed from Spitzer calc and is the normalization factor for the local // density and thermal velocity, norm_nu_sr = n/(vth_s^2 + vth_r^2)^(3/2) @@ -43,66 +47,84 @@ pkpm_species_lbo_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, struct lbo->norm_nu = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); lbo->nu_init = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); gkyl_array_copy(lbo->nu_init, lbo->self_nu); - lbo->maxwellian_moms = mkarr(app->use_gpu, (vdim+2)*app->confBasis.num_basis, app->local_ext.volume); + lbo->maxwellian_moms = + mkarr(app->use_gpu, (vdim + 2) * app->confBasis.num_basis, app->local_ext.volume); } // Allocate needed arrays (boundary corrections, primitive moments, and nu*primitive moments) - lbo->boundary_corrections = mkarr(app->use_gpu, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); + lbo->boundary_corrections = + mkarr(app->use_gpu, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); - lbo->prim_moms = mkarr(app->use_gpu, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); - lbo->nu_prim_moms = mkarr(app->use_gpu, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); + lbo->prim_moms = + mkarr(app->use_gpu, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); + lbo->nu_prim_moms = + mkarr(app->use_gpu, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); lbo->m0 = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - // edge of velocity space corrections to momentum and energy + // edge of velocity space corrections to momentum and energy // Note: PKPM model still has a momentum correction to insure M1 = 0 from collisions - lbo->bcorr_calc = gkyl_mom_calc_bcorr_lbo_pkpm_new(&s->grid, - &app->confBasis, &app->basis, v_bounds, s->info.mass, app->use_gpu); + lbo->bcorr_calc = gkyl_mom_calc_bcorr_lbo_pkpm_new( + &s->grid, &app->confBasis, &app->basis, v_bounds, s->info.mass, app->use_gpu + ); // primitive moment calculators - lbo->coll_pcalc = gkyl_prim_lbo_pkpm_calc_new(&s->grid, - &app->confBasis, &app->basis, &app->local, app->use_gpu); - + lbo->coll_pcalc = + gkyl_prim_lbo_pkpm_calc_new(&s->grid, &app->confBasis, &app->basis, &app->local, app->use_gpu); + // LBO updater - struct gkyl_dg_lbo_pkpm_drag_auxfields drag_inp = { .nuSum = lbo->nu_sum, .nuPrimMomsSum = lbo->nu_prim_moms }; - struct gkyl_dg_lbo_pkpm_diff_auxfields diff_inp = { .nuSum = lbo->nu_sum, .nuPrimMomsSum = lbo->nu_prim_moms }; - lbo->coll_slvr = gkyl_dg_updater_lbo_pkpm_new(&s->grid, - &app->confBasis, &app->basis, &app->local, &drag_inp, &diff_inp, app->use_gpu); + struct gkyl_dg_lbo_pkpm_drag_auxfields drag_inp = { + .nuSum = lbo->nu_sum, .nuPrimMomsSum = lbo->nu_prim_moms + }; + struct gkyl_dg_lbo_pkpm_diff_auxfields diff_inp = { + .nuSum = lbo->nu_sum, .nuPrimMomsSum = lbo->nu_prim_moms + }; + lbo->coll_slvr = gkyl_dg_updater_lbo_pkpm_new( + &s->grid, &app->confBasis, &app->basis, &app->local, &drag_inp, &diff_inp, app->use_gpu + ); } -void -pkpm_species_lbo_cross_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, struct pkpm_lbo_collisions *lbo) +void pkpm_species_lbo_cross_init( + struct gkyl_pkpm_app *app, struct pkpm_species *s, struct pkpm_lbo_collisions *lbo +) { int vdim = app->vdim; - lbo->cross_calc = gkyl_prim_lbo_vlasov_cross_calc_new(&s->grid, - &app->confBasis, &app->basis, &app->local, app->use_gpu); - - lbo->cross_nu_prim_moms = mkarr(app->use_gpu, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); + lbo->cross_calc = gkyl_prim_lbo_vlasov_cross_calc_new( + &s->grid, &app->confBasis, &app->basis, &app->local, app->use_gpu + ); + + lbo->cross_nu_prim_moms = + mkarr(app->use_gpu, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); lbo->greene_factor_mem = 0; - if (app->use_gpu) - lbo->greene_factor_mem = gkyl_dg_bin_op_mem_cu_dev_new(app->local.volume, app->confBasis.num_basis); - else + if (app->use_gpu) { + lbo->greene_factor_mem = + gkyl_dg_bin_op_mem_cu_dev_new(app->local.volume, app->confBasis.num_basis); + } else { lbo->greene_factor_mem = gkyl_dg_bin_op_mem_new(app->local.volume, app->confBasis.num_basis); + } // set pointers to species we cross-collide with - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < lbo->num_cross_collisions; ++i) { lbo->collide_with[i] = pkpm_find_species(app, s->info.collisions.collide_with[i]); lbo->other_m[i] = lbo->collide_with[i]->info.mass; lbo->other_prim_moms[i] = lbo->collide_with[i]->lbo.prim_moms; lbo->other_nu[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - lbo->cross_prim_moms[i] = mkarr(app->use_gpu, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); + lbo->cross_prim_moms[i] = + mkarr(app->use_gpu, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); lbo->cross_nu[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); lbo->greene_num[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); lbo->greene_den[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); lbo->greene_factor[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - + if (lbo->other_m[i] > s->info.mass) { gkyl_array_set(lbo->cross_nu[i], sqrt(2), lbo->self_nu); - gkyl_array_set(lbo->other_nu[i], (s->info.mass)/(lbo->other_m[i]), lbo->self_nu); + gkyl_array_set(lbo->other_nu[i], (s->info.mass) / (lbo->other_m[i]), lbo->self_nu); } else { - gkyl_array_set(lbo->cross_nu[i], (lbo->other_m[i])/(s->info.mass), lbo->collide_with[i]->lbo.self_nu); + gkyl_array_set( + lbo->cross_nu[i], (lbo->other_m[i]) / (s->info.mass), lbo->collide_with[i]->lbo.self_nu + ); gkyl_array_set(lbo->other_nu[i], sqrt(2), lbo->collide_with[i]->lbo.self_nu); } - + gkyl_array_accumulate(lbo->nu_sum, 1.0, lbo->cross_nu[i]); lbo->other_mnu[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); @@ -114,26 +136,30 @@ pkpm_species_lbo_cross_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, s gkyl_array_set(lbo->self_mnu[i], s->info.mass, lbo->cross_nu[i]); gkyl_array_set(lbo->other_mnu[i], lbo->other_m[i], lbo->other_nu[i]); } - + lbo->betaGreenep1 = 1.0; } // computes moments, boundary corrections, and primitive moments -void -pkpm_species_lbo_moms(gkyl_pkpm_app *app, const struct pkpm_species *species, - struct pkpm_lbo_collisions *lbo, const struct gkyl_array *fin) +void pkpm_species_lbo_moms( + gkyl_pkpm_app *app, const struct pkpm_species *species, struct pkpm_lbo_collisions *lbo, + const struct gkyl_array *fin +) { struct timespec wst = gkyl_wall_clock(); gkyl_array_set_range(lbo->m0, 1.0, species->pkpm_moms.marr, &app->local); // construct boundary corrections - gkyl_mom_calc_bcorr_advance(lbo->bcorr_calc, - &species->local, &app->local, fin, lbo->boundary_corrections); + gkyl_mom_calc_bcorr_advance( + lbo->bcorr_calc, &species->local, &app->local, fin, lbo->boundary_corrections + ); // Compute primitive moments. - gkyl_prim_lbo_calc_advance(lbo->coll_pcalc, &app->local, - species->pkpm_moms.marr, lbo->boundary_corrections, lbo->self_nu, lbo->prim_moms); + gkyl_prim_lbo_calc_advance( + lbo->coll_pcalc, &app->local, species->pkpm_moms.marr, lbo->boundary_corrections, lbo->self_nu, + lbo->prim_moms + ); if (app->use_gpu) { // PKPM moments already computed before this, so just fetch results @@ -141,89 +167,113 @@ pkpm_species_lbo_moms(gkyl_pkpm_app *app, const struct pkpm_species *species, gkyl_array_clear(lbo->norm_nu, 0.0); gkyl_array_clear(lbo->self_nu, 0.0); // Get density information (and scale out mass factor in PKPM moments) - gkyl_array_set_range(lbo->maxwellian_moms, 1.0/species->info.mass, species->pkpm_moms.marr, &app->local); - gkyl_array_set_offset_range(lbo->maxwellian_moms, 1.0, lbo->prim_moms, app->confBasis.num_basis, &app->local); - gkyl_spitzer_coll_freq_advance_normnu(lbo->spitzer_calc, &app->local, lbo->maxwellian_moms, 0., lbo->maxwellian_moms, 0., 1.0, lbo->norm_nu); + gkyl_array_set_range( + lbo->maxwellian_moms, 1.0 / species->info.mass, species->pkpm_moms.marr, &app->local + ); + gkyl_array_set_offset_range( + lbo->maxwellian_moms, 1.0, lbo->prim_moms, app->confBasis.num_basis, &app->local + ); + gkyl_spitzer_coll_freq_advance_normnu( + lbo->spitzer_calc, &app->local, lbo->maxwellian_moms, 0., lbo->maxwellian_moms, 0., 1.0, + lbo->norm_nu + ); gkyl_dg_mul_op(&app->confBasis, 0, lbo->self_nu, 0, lbo->nu_init, 0, lbo->norm_nu); } - } - else { - + } else { // PKPM moments already computed before this, so just fetch results if (lbo->normNu) { gkyl_array_clear(lbo->norm_nu, 0.0); gkyl_array_clear(lbo->self_nu, 0.0); // Get density information (and scale out mass factor in PKPM moments) - gkyl_array_set_range(lbo->maxwellian_moms, 1.0/species->info.mass, species->pkpm_moms.marr, &app->local); - gkyl_array_set_offset_range(lbo->maxwellian_moms, 1.0, lbo->prim_moms, app->confBasis.num_basis, &app->local); - gkyl_spitzer_coll_freq_advance_normnu(lbo->spitzer_calc, &app->local, lbo->maxwellian_moms, 0., lbo->maxwellian_moms, 0.0, 1.0, lbo->norm_nu); + gkyl_array_set_range( + lbo->maxwellian_moms, 1.0 / species->info.mass, species->pkpm_moms.marr, &app->local + ); + gkyl_array_set_offset_range( + lbo->maxwellian_moms, 1.0, lbo->prim_moms, app->confBasis.num_basis, &app->local + ); + gkyl_spitzer_coll_freq_advance_normnu( + lbo->spitzer_calc, &app->local, lbo->maxwellian_moms, 0., lbo->maxwellian_moms, 0.0, 1.0, + lbo->norm_nu + ); gkyl_dg_mul_op(&app->confBasis, 0, lbo->self_nu, 0, lbo->nu_init, 0, lbo->norm_nu); } } - for (int d=0; dvdim; d++) + for (int d = 0; d < app->vdim; d++) { gkyl_dg_mul_op(&app->confBasis, d, lbo->nu_prim_moms, d, lbo->prim_moms, 0, lbo->self_nu); - gkyl_dg_mul_op(&app->confBasis, app->vdim, lbo->nu_prim_moms, app->vdim, lbo->prim_moms, 0, lbo->self_nu); - - app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); + } + gkyl_dg_mul_op( + &app->confBasis, app->vdim, lbo->nu_prim_moms, app->vdim, lbo->prim_moms, 0, lbo->self_nu + ); + + app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); } // computes moments from cross-species collisions -void -pkpm_species_lbo_cross_moms(gkyl_pkpm_app *app, const struct pkpm_species *species, - struct pkpm_lbo_collisions *lbo, const struct gkyl_array *fin) +void pkpm_species_lbo_cross_moms( + gkyl_pkpm_app *app, const struct pkpm_species *species, struct pkpm_lbo_collisions *lbo, + const struct gkyl_array *fin +) { struct timespec wst = gkyl_wall_clock(); - - wst = gkyl_wall_clock(); - for (int i=0; inum_cross_collisions; ++i) { - gkyl_dg_mul_op_range(&app->confBasis, 0, lbo->self_mnu_m0[i], 0, - lbo->self_mnu[i], 0, lbo->m0, &app->local); - gkyl_dg_mul_op_range(&app->confBasis, 0, lbo->other_mnu_m0[i], 0, - lbo->other_mnu[i], 0, lbo->collide_with[i]->lbo.m0, &app->local); - gkyl_dg_mul_op_range(&app->confBasis, 0, lbo->greene_num[i], 0, - lbo->other_mnu_m0[i], 0, lbo->m0, &app->local); + wst = gkyl_wall_clock(); + for (int i = 0; i < lbo->num_cross_collisions; ++i) { + gkyl_dg_mul_op_range( + &app->confBasis, 0, lbo->self_mnu_m0[i], 0, lbo->self_mnu[i], 0, lbo->m0, &app->local + ); + gkyl_dg_mul_op_range( + &app->confBasis, 0, lbo->other_mnu_m0[i], 0, lbo->other_mnu[i], 0, + lbo->collide_with[i]->lbo.m0, &app->local + ); + + gkyl_dg_mul_op_range( + &app->confBasis, 0, lbo->greene_num[i], 0, lbo->other_mnu_m0[i], 0, lbo->m0, &app->local + ); gkyl_array_set(lbo->greene_den[i], 1.0, lbo->self_mnu_m0[i]); gkyl_array_accumulate(lbo->greene_den[i], 1.0, lbo->other_mnu_m0[i]); - gkyl_dg_div_op_range(lbo->greene_factor_mem, &app->confBasis, 0, lbo->greene_factor[i], 0, - lbo->greene_num[i], 0, lbo->greene_den[i], &app->local); - gkyl_array_scale(lbo->greene_factor[i], 2*lbo->betaGreenep1); - - gkyl_prim_lbo_cross_calc_advance(lbo->cross_calc, - &app->local, - lbo->greene_factor[i], - species->info.mass, lbo->moms.marr, lbo->prim_moms, - lbo->other_m[i], lbo->collide_with[i]->lbo.moms.marr, lbo->other_prim_moms[i], - lbo->boundary_corrections, lbo->cross_nu[i], - lbo->cross_prim_moms[i]); - - - for (int d=0; dvdim; d++) - gkyl_dg_mul_op(&app->confBasis, d, lbo->cross_nu_prim_moms, d, lbo->cross_prim_moms[i], 0, lbo->cross_nu[i]); - gkyl_dg_mul_op(&app->confBasis, app->vdim, lbo->cross_nu_prim_moms, app->vdim, lbo->cross_prim_moms[i], 0, lbo->cross_nu[i]); + gkyl_dg_div_op_range( + lbo->greene_factor_mem, &app->confBasis, 0, lbo->greene_factor[i], 0, lbo->greene_num[i], 0, + lbo->greene_den[i], &app->local + ); + gkyl_array_scale(lbo->greene_factor[i], 2 * lbo->betaGreenep1); + + gkyl_prim_lbo_cross_calc_advance( + lbo->cross_calc, &app->local, lbo->greene_factor[i], species->info.mass, lbo->moms.marr, + lbo->prim_moms, lbo->other_m[i], lbo->collide_with[i]->lbo.moms.marr, lbo->other_prim_moms[i], + lbo->boundary_corrections, lbo->cross_nu[i], lbo->cross_prim_moms[i] + ); + + for (int d = 0; d < app->vdim; d++) { + gkyl_dg_mul_op( + &app->confBasis, d, lbo->cross_nu_prim_moms, d, lbo->cross_prim_moms[i], 0, lbo->cross_nu[i] + ); + } + gkyl_dg_mul_op( + &app->confBasis, app->vdim, lbo->cross_nu_prim_moms, app->vdim, lbo->cross_prim_moms[i], 0, + lbo->cross_nu[i] + ); gkyl_array_accumulate(lbo->nu_prim_moms, 1.0, lbo->cross_nu_prim_moms); } - app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); + app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); } -void -pkpm_species_lbo_rhs(gkyl_pkpm_app *app, const struct pkpm_species *species, - struct pkpm_lbo_collisions *lbo, const struct gkyl_array *fin, struct gkyl_array *rhs) +void pkpm_species_lbo_rhs( + gkyl_pkpm_app *app, const struct pkpm_species *species, struct pkpm_lbo_collisions *lbo, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - + // accumulate update due to collisions onto rhs - gkyl_dg_updater_lbo_pkpm_advance(lbo->coll_slvr, &species->local, - fin, species->cflrate_f, rhs); - + gkyl_dg_updater_lbo_pkpm_advance(lbo->coll_slvr, &species->local, fin, species->cflrate_f, rhs); + app->stat.species_coll_tm += gkyl_time_diff_now_sec(wst); } -void -pkpm_species_lbo_release(const struct gkyl_pkpm_app *app, const struct pkpm_lbo_collisions *lbo) +void pkpm_species_lbo_release(const struct gkyl_pkpm_app *app, const struct pkpm_lbo_collisions *lbo) { gkyl_array_release(lbo->boundary_corrections); gkyl_array_release(lbo->prim_moms); @@ -245,7 +295,7 @@ pkpm_species_lbo_release(const struct gkyl_pkpm_app *app, const struct pkpm_lbo_ if (lbo->num_cross_collisions) { gkyl_dg_bin_op_mem_release(lbo->greene_factor_mem); gkyl_array_release(lbo->cross_nu_prim_moms); - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < lbo->num_cross_collisions; ++i) { gkyl_array_release(lbo->cross_prim_moms[i]); gkyl_array_release(lbo->cross_nu[i]); gkyl_array_release(lbo->other_nu[i]); @@ -260,4 +310,4 @@ pkpm_species_lbo_release(const struct gkyl_pkpm_app *app, const struct pkpm_lbo_ gkyl_prim_lbo_cross_calc_release(lbo->cross_calc); } gkyl_dg_updater_lbo_pkpm_release(lbo->coll_slvr); - } +} diff --git a/pkpm/apps/pkpm_species_moment.c b/pkpm/apps/pkpm_species_moment.c index dad5365e9f..b6151ca697 100644 --- a/pkpm/apps/pkpm_species_moment.c +++ b/pkpm/apps/pkpm_species_moment.c @@ -2,34 +2,39 @@ #include // initialize species moment object -void -pkpm_species_moment_init(struct gkyl_pkpm_app *app, struct pkpm_species *s, - struct pkpm_species_moment *sm, bool is_diag) +void pkpm_species_moment_init( + struct gkyl_pkpm_app *app, struct pkpm_species *s, struct pkpm_species_moment *sm, bool is_diag +) { - sm->mcalc = gkyl_dg_updater_moment_pkpm_new(&s->grid, &app->confBasis, - &app->basis, &app->local, &s->local_vel, s->info.mass, is_diag, app->use_gpu); + sm->mcalc = gkyl_dg_updater_moment_pkpm_new( + &s->grid, &app->confBasis, &app->basis, &app->local, &s->local_vel, s->info.mass, is_diag, + app->use_gpu + ); int num_mom = gkyl_dg_updater_moment_pkpm_num_mom(sm->mcalc); - sm->marr = mkarr(app->use_gpu, num_mom*app->confBasis.num_basis, app->local_ext.volume); + sm->marr = mkarr(app->use_gpu, num_mom * app->confBasis.num_basis, app->local_ext.volume); sm->marr_host = sm->marr; - if (app->use_gpu) - sm->marr_host = mkarr(false, num_mom*app->confBasis.num_basis, app->local_ext.volume); + if (app->use_gpu) { + sm->marr_host = mkarr(false, num_mom * app->confBasis.num_basis, app->local_ext.volume); + } } -void -pkpm_species_moment_calc(const struct pkpm_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin) +void pkpm_species_moment_calc( + const struct pkpm_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +) { gkyl_dg_updater_moment_pkpm_advance(sm->mcalc, &phase_rng, &conf_rng, fin, sm->marr); } // release memory for moment data object -void -pkpm_species_moment_release(const struct gkyl_pkpm_app *app, const struct pkpm_species_moment *sm) +void pkpm_species_moment_release( + const struct gkyl_pkpm_app *app, const struct pkpm_species_moment *sm +) { - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_release(sm->marr_host); + } gkyl_dg_updater_moment_pkpm_release(sm->mcalc); gkyl_array_release(sm->marr); diff --git a/pkpm/apps/pkpm_update_explicit_ssp_rk3.c b/pkpm/apps/pkpm_update_explicit_ssp_rk3.c index d7bb7b625e..b7efe241f1 100644 --- a/pkpm/apps/pkpm_update_explicit_ssp_rk3.c +++ b/pkpm/apps/pkpm_update_explicit_ssp_rk3.c @@ -3,16 +3,15 @@ // Take time-step using the RK3 method. Also sets the status object // which has the actual and suggested dts used. These can be different // from the actual time-step. -struct gkyl_update_status -pkpm_update_explicit_ssp_rk3(gkyl_pkpm_app* app, double dt0) +struct gkyl_update_status pkpm_update_explicit_ssp_rk3(gkyl_pkpm_app *app, double dt0) { - int ns = app->num_species; + int ns = app->num_species; const struct gkyl_array *fin[ns]; struct gkyl_array *fout[ns]; const struct gkyl_array *fluidin[ns]; struct gkyl_array *fluidout[ns]; - struct gkyl_update_status st = { .success = true }; + struct gkyl_update_status st = {.success = true}; // time-stepper state enum { RK_STAGE_1, RK_STAGE_2, RK_STAGE_3, RK_COMPLETE } state = RK_STAGE_1; @@ -20,142 +19,146 @@ pkpm_update_explicit_ssp_rk3(gkyl_pkpm_app* app, double dt0) double tcurr = app->tcurr, dt = dt0; while (state != RK_COMPLETE) { switch (state) { - case RK_STAGE_1: - do { - struct timespec rk3_s1_tm = gkyl_wall_clock(); - - for (int i=0; ispecies[i].f; - fluidin[i] = app->species[i].fluid; - fout[i] = app->species[i].f1; - fluidout[i] = app->species[i].fluid1; - } - pkpm_forward_euler(app, tcurr, dt, fin, fluidin, app->field->em, - fout, fluidout, app->field->em1, - &st - ); - // Limit fluid and EM solutions if desired (done after update as post-hoc fix) - for (int i=0; ispecies[i], fout[i], fluidout[i]); - } - pkpm_field_limiter(app, app->field, app->field->emnew); + case RK_STAGE_1: + do { + struct timespec rk3_s1_tm = gkyl_wall_clock(); + + for (int i = 0; i < ns; ++i) { + fin[i] = app->species[i].f; + fluidin[i] = app->species[i].fluid; + fout[i] = app->species[i].f1; + fluidout[i] = app->species[i].fluid1; + } + pkpm_forward_euler( + app, tcurr, dt, fin, fluidin, app->field->em, fout, fluidout, app->field->em1, &st + ); + // Limit fluid and EM solutions if desired (done after update as post-hoc fix) + for (int i = 0; i < ns; ++i) { + pkpm_fluid_species_limiter(app, &app->species[i], fout[i], fluidout[i]); + } + pkpm_field_limiter(app, app->field, app->field->emnew); + + dt = st.dt_actual; + state = RK_STAGE_2; + + app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s1_tm); + } while (0); + break; + + case RK_STAGE_2: + do { + struct timespec rk3_s2_tm = gkyl_wall_clock(); + + for (int i = 0; i < ns; ++i) { + fin[i] = app->species[i].f1; + fluidin[i] = app->species[i].fluid1; + fout[i] = app->species[i].fnew; + fluidout[i] = app->species[i].fluidnew; + } + pkpm_forward_euler( + app, tcurr + dt, dt, fin, fluidin, app->field->em1, fout, fluidout, app->field->emnew, &st + ); + // Limit fluid and EM solutions if desired (done after update as post-hoc fix) + for (int i = 0; i < ns; ++i) { + pkpm_fluid_species_limiter(app, &app->species[i], fout[i], fluidout[i]); + } + pkpm_field_limiter(app, app->field, app->field->emnew); + + if (st.dt_actual < dt) { + // collect stats + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], dt_rel_diff); + app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], dt_rel_diff); + app->stat.nstage_2_fail += 1; dt = st.dt_actual; - state = RK_STAGE_2; - - app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s1_tm); - } while(0); - break; - - case RK_STAGE_2: - do { - struct timespec rk3_s2_tm = gkyl_wall_clock(); - - for (int i=0; ispecies[i].f1; - fluidin[i] = app->species[i].fluid1; - fout[i] = app->species[i].fnew; - fluidout[i] = app->species[i].fluidnew; - } - pkpm_forward_euler(app, tcurr+dt, dt, fin, fluidin, app->field->em1, - fout, fluidout, app->field->emnew, - &st - ); - // Limit fluid and EM solutions if desired (done after update as post-hoc fix) - for (int i=0; ispecies[i], fout[i], fluidout[i]); + state = RK_STAGE_1; // restart from stage 1 + } else { + for (int i = 0; i < ns; ++i) { + array_combine( + app->species[i].f1, 3.0 / 4.0, app->species[i].f, 1.0 / 4.0, app->species[i].fnew, + &app->species[i].local_ext + ); } - pkpm_field_limiter(app, app->field, app->field->emnew); - - if (st.dt_actual < dt) { - // collect stats - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], - dt_rel_diff); - app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], - dt_rel_diff); - app->stat.nstage_2_fail += 1; - - dt = st.dt_actual; - state = RK_STAGE_1; // restart from stage 1 - } - else { - for (int i=0; ispecies[i].f1, - 3.0/4.0, app->species[i].f, 1.0/4.0, app->species[i].fnew, &app->species[i].local_ext); - } - for (int i=0; ispecies[i].fluid1, - 3.0/4.0, app->species[i].fluid, 1.0/4.0, app->species[i].fluidnew, &app->local_ext); - } - array_combine(app->field->em1, - 3.0/4.0, app->field->em, 1.0/4.0, app->field->emnew, &app->local_ext); - - state = RK_STAGE_3; + for (int i = 0; i < ns; ++i) { + array_combine( + app->species[i].fluid1, 3.0 / 4.0, app->species[i].fluid, 1.0 / 4.0, + app->species[i].fluidnew, &app->local_ext + ); } + array_combine( + app->field->em1, 3.0 / 4.0, app->field->em, 1.0 / 4.0, app->field->emnew, + &app->local_ext + ); - app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s2_tm); - } while(0); - break; - - case RK_STAGE_3: - do { - struct timespec rk3_s3_tm = gkyl_wall_clock(); + state = RK_STAGE_3; + } + + app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s2_tm); + } while (0); + break; + + case RK_STAGE_3: + do { + struct timespec rk3_s3_tm = gkyl_wall_clock(); + + for (int i = 0; i < ns; ++i) { + fin[i] = app->species[i].f1; + fluidin[i] = app->species[i].fluid1; + fout[i] = app->species[i].fnew; + fluidout[i] = app->species[i].fluidnew; + } + pkpm_forward_euler( + app, tcurr + dt / 2, dt, fin, fluidin, app->field->em1, fout, fluidout, app->field->emnew, + &st + ); + // Limit fluid and EM solutions if desired (done after update as post-hoc fix) + for (int i = 0; i < ns; ++i) { + pkpm_fluid_species_limiter(app, &app->species[i], fout[i], fluidout[i]); + } + pkpm_field_limiter(app, app->field, app->field->emnew); + + if (st.dt_actual < dt) { + // collect stats + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], dt_rel_diff); + app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], dt_rel_diff); + app->stat.nstage_3_fail += 1; - for (int i=0; ispecies[i].f1; - fluidin[i] = app->species[i].fluid1; - fout[i] = app->species[i].fnew; - fluidout[i] = app->species[i].fluidnew; + dt = st.dt_actual; + state = RK_STAGE_1; // restart from stage 1 + + app->stat.nstage_2_fail += 1; + } else { + for (int i = 0; i < ns; ++i) { + array_combine( + app->species[i].f1, 1.0 / 3.0, app->species[i].f, 2.0 / 3.0, app->species[i].fnew, + &app->species[i].local_ext + ); + gkyl_array_copy_range(app->species[i].f, app->species[i].f1, &app->species[i].local_ext); } - pkpm_forward_euler(app, tcurr+dt/2, dt, fin, fluidin, app->field->em1, - fout, fluidout, app->field->emnew, - &st - ); - // Limit fluid and EM solutions if desired (done after update as post-hoc fix) - for (int i=0; ispecies[i], fout[i], fluidout[i]); + for (int i = 0; i < ns; ++i) { + array_combine( + app->species[i].fluid1, 1.0 / 3.0, app->species[i].fluid, 2.0 / 3.0, + app->species[i].fluidnew, &app->local_ext + ); + gkyl_array_copy_range(app->species[i].fluid, app->species[i].fluid1, &app->local_ext); } - pkpm_field_limiter(app, app->field, app->field->emnew); - - if (st.dt_actual < dt) { - // collect stats - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], - dt_rel_diff); - app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], - dt_rel_diff); - app->stat.nstage_3_fail += 1; + array_combine( + app->field->em1, 1.0 / 3.0, app->field->em, 2.0 / 3.0, app->field->emnew, + &app->local_ext + ); + gkyl_array_copy_range(app->field->em, app->field->em1, &app->local_ext); - dt = st.dt_actual; - state = RK_STAGE_1; // restart from stage 1 + state = RK_COMPLETE; + } - app->stat.nstage_2_fail += 1; - } - else { - for (int i=0; ispecies[i].f1, - 1.0/3.0, app->species[i].f, 2.0/3.0, app->species[i].fnew, &app->species[i].local_ext); - gkyl_array_copy_range(app->species[i].f, app->species[i].f1, &app->species[i].local_ext); - } - for (int i=0; ispecies[i].fluid1, - 1.0/3.0, app->species[i].fluid, 2.0/3.0, app->species[i].fluidnew, &app->local_ext); - gkyl_array_copy_range(app->species[i].fluid, app->species[i].fluid1, &app->local_ext); - } - array_combine(app->field->em1, - 1.0/3.0, app->field->em, 2.0/3.0, app->field->emnew, &app->local_ext); - gkyl_array_copy_range(app->field->em, app->field->em1, &app->local_ext); - - state = RK_COMPLETE; - } - - app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s3_tm); - } while(0); - break; + app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s3_tm); + } while (0); + break; - case RK_COMPLETE: // can't happen: suppresses warning - break; + case RK_COMPLETE: // can't happen: suppresses warning + break; } } diff --git a/pkpm/apps/pkpm_update_op_split.c b/pkpm/apps/pkpm_update_op_split.c index 67f9157910..ee4c829728 100644 --- a/pkpm/apps/pkpm_update_op_split.c +++ b/pkpm/apps/pkpm_update_op_split.c @@ -3,8 +3,7 @@ // Take time-step using the SSP-RK3 method for the hyperbolic components // Then, we use the actual timestep taken with the SSP-RK3 method to update // fluid-EM coupling implicitly. -struct gkyl_update_status -pkpm_update_op_split(gkyl_pkpm_app* app, double dt0) +struct gkyl_update_status pkpm_update_op_split(gkyl_pkpm_app *app, double dt0) { struct gkyl_update_status st = pkpm_update_explicit_ssp_rk3(app, dt0); diff --git a/pkpm/creg/rt_arg_parse.h b/pkpm/creg/rt_arg_parse.h index ac622fc504..ac9855fda7 100644 --- a/pkpm/creg/rt_arg_parse.h +++ b/pkpm/creg/rt_arg_parse.h @@ -17,7 +17,7 @@ struct gkyl_app_args { bool use_gpu; // should this be run on GPU? - bool use_mpi; // should this be run on MPI? + bool use_mpi; // should this be run on MPI? bool step_mode; // run for fixed number of steps? (for valgrind/cuda-memcheck) bool trace_mem; // should we trace memory allocation/deallocations? int num_steps; // number of steps @@ -26,7 +26,8 @@ struct gkyl_app_args { int vcells[3]; // velocity space cells int cuts[3]; // domain decomposition "cuts" char file_name[1024]; // name of input file - char app_name[128]; // basename of argv[0] — use with snprintf/strcpy to set char[] name fields (cannot assign directly in compound literals) + char app_name + [128]; // basename of argv[0] — use with snprintf/strcpy to set char[] name fields (cannot assign directly in compound literals) enum gkyl_basis_type basis_type; // type of basis functions to use enum gkyl_mp_recon mp_recon; // the XX in MP-XX bool skip_limiters; // should we skip limiters? @@ -35,45 +36,36 @@ struct gkyl_app_args { char opt_args[128]; // optional arguments }; -static int -get_basis_type(const char *nm) +static int get_basis_type(const char *nm) { if (strcmp(nm, "ms") == 0) { return GKYL_BASIS_MODAL_SERENDIPITY; - } - else if (strcmp(nm, "mt") == 0) { + } else if (strcmp(nm, "mt") == 0) { return GKYL_BASIS_MODAL_TENSOR; } return -1; } -static int -get_mp_recon_type(const char *nm) +static int get_mp_recon_type(const char *nm) { if (strcmp(nm, "u1") == 0) { return GKYL_MP_U1; - } - else if (strcmp(nm, "u3") == 0) { + } else if (strcmp(nm, "u3") == 0) { return GKYL_MP_U3; - } - else if (strcmp(nm, "u5") == 0) { + } else if (strcmp(nm, "u5") == 0) { return GKYL_MP_U5; - } - else if (strcmp(nm, "c2") == 0) { + } else if (strcmp(nm, "c2") == 0) { return GKYL_MP_C2; - } - else if (strcmp(nm, "c4") == 0) { + } else if (strcmp(nm, "c4") == 0) { return GKYL_MP_C4; - } - else if (strcmp(nm, "c6") == 0) { + } else if (strcmp(nm, "c6") == 0) { return GKYL_MP_C6; - } - + } + return -1; } -static struct gkyl_app_args -parse_app_args(int argc, char **argv) +static struct gkyl_app_args parse_app_args(int argc, char **argv) { bool use_gpu = false; bool use_mpi = false; @@ -85,134 +77,130 @@ parse_app_args(int argc, char **argv) int num_steps = INT_MAX; int num_threads = 1; // by default use only 1 thread - struct gkyl_app_args args = { - .xcells = { 0 }, - .vcells = { 0 }, - .cuts = { 1, 1, 1 }, - }; + struct gkyl_app_args args = {.xcells = {0}, .vcells = {0}, .cuts = {1, 1, 1}}; strcpy(args.file_name, APP_ARGS_DEFAULT_FILE_NAME); // default args.basis_type = GKYL_BASIS_MODAL_SERENDIPITY; int c; while ((c = getopt(argc, argv, "+hjgmMt:s:i:b:x:y:z:u:v:w:r:c:d:e:o:")) != -1) { - switch (c) - { - case 'h': - printf("Usage: -g -m -s nsteps -t nthreads -i inp -b [ms|mt] -x NX -y NY -z NZ -u VX -v VY -w VZ\n"); - printf(" All flags and parameters are optional.\n"); - printf(" -g Run on GPUs if GPUs are present and code built for GPUs\n"); - printf(" -M Run with MPI if code built with MPI\n"); - printf(" -sN Only run N steps of simulation\n"); - printf(" -tN Use N threads (when available)\n"); - printf(" -b Basis function to use (ms: Modal serendipity; mt: Modal tensor-product)\n"); - printf(" (Ignored for finite-volume solvers)\n"); - printf(" -j Recovery scheme. One of u1, u3, u5, c2, c4, c6\n"); - printf(" (Only used for MP-XX solvers)\n"); - printf(" -l Turn off limiters\n"); - printf(" -rN Restart the simulation from frame N\n"); - printf(" -m Turn on memory allocation/deallocation tracing\n"); - printf(" -o Optional arguments (as string, requires parsing)\n"); - printf("\n"); - printf(" Grid resolution in configuration space:\n"); - printf(" -xNX -yNY -zNZ\n"); - printf(" Grid resolution in velocity space:\n"); - printf(" -uVX -vVY -wVZ\n"); - printf(" Domain decomposition in each direction:\n"); - printf(" -cPX -dPY -ePZ\n"); - exit(-1); - break; - - case 'g': - use_gpu = true; - break; - - case 'M': - use_mpi = true; - break; - - case 'm': - trace_mem = true; - break; - - case 'l': - skip_limiters = true; - break; - - case 'r': - is_restart = true; - restart_frame = atoi(optarg); - break; - - case 's': - step_mode = true; - num_steps = atoi(optarg); - break; - - case 't': - num_threads = atoi(optarg); - break; - - case 'c': - args.cuts[0] = atoi(optarg); - break; - - case 'd': - args.cuts[1] = atoi(optarg); - break; - - case 'e': - args.cuts[2] = atoi(optarg); - break; - - case 'x': - args.xcells[0] = atoi(optarg); - break; - - case 'y': - args.xcells[1] = atoi(optarg); - break; - - case 'z': - args.xcells[2] = atoi(optarg); - break; - - case 'u': - args.vcells[0] = atoi(optarg); - break; - - case 'v': - args.vcells[1] = atoi(optarg); - break; - - case 'w': - args.vcells[2] = atoi(optarg); - break; - - case 'i': - strcpy(args.file_name, optarg); - break; - - case 'b': - args.basis_type = get_basis_type(optarg); - assert(args.basis_type != -1); - break; - - case 'j': - args.mp_recon = get_mp_recon_type(optarg); - assert(args.mp_recon != -1); - break; - - case 'o': - assert(strlen(optarg) < sizeof(args.opt_args)); - strcpy(args.opt_args, optarg); - break; - - case '?': - break; + switch (c) { + case 'h': + printf("Usage: -g -m -s nsteps -t nthreads -i inp -b [ms|mt] -x NX -y NY -z NZ -u " + "VX -v VY -w VZ\n"); + printf(" All flags and parameters are optional.\n"); + printf(" -g Run on GPUs if GPUs are present and code built for GPUs\n"); + printf(" -M Run with MPI if code built with MPI\n"); + printf(" -sN Only run N steps of simulation\n"); + printf(" -tN Use N threads (when available)\n"); + printf(" -b Basis function to use (ms: Modal serendipity; mt: Modal tensor-product)\n"); + printf(" (Ignored for finite-volume solvers)\n"); + printf(" -j Recovery scheme. One of u1, u3, u5, c2, c4, c6\n"); + printf(" (Only used for MP-XX solvers)\n"); + printf(" -l Turn off limiters\n"); + printf(" -rN Restart the simulation from frame N\n"); + printf(" -m Turn on memory allocation/deallocation tracing\n"); + printf(" -o Optional arguments (as string, requires parsing)\n"); + printf("\n"); + printf(" Grid resolution in configuration space:\n"); + printf(" -xNX -yNY -zNZ\n"); + printf(" Grid resolution in velocity space:\n"); + printf(" -uVX -vVY -wVZ\n"); + printf(" Domain decomposition in each direction:\n"); + printf(" -cPX -dPY -ePZ\n"); + exit(-1); + break; + + case 'g': + use_gpu = true; + break; + + case 'M': + use_mpi = true; + break; + + case 'm': + trace_mem = true; + break; + + case 'l': + skip_limiters = true; + break; + + case 'r': + is_restart = true; + restart_frame = atoi(optarg); + break; + + case 's': + step_mode = true; + num_steps = atoi(optarg); + break; + + case 't': + num_threads = atoi(optarg); + break; + + case 'c': + args.cuts[0] = atoi(optarg); + break; + + case 'd': + args.cuts[1] = atoi(optarg); + break; + + case 'e': + args.cuts[2] = atoi(optarg); + break; + + case 'x': + args.xcells[0] = atoi(optarg); + break; + + case 'y': + args.xcells[1] = atoi(optarg); + break; + + case 'z': + args.xcells[2] = atoi(optarg); + break; + + case 'u': + args.vcells[0] = atoi(optarg); + break; + + case 'v': + args.vcells[1] = atoi(optarg); + break; + + case 'w': + args.vcells[2] = atoi(optarg); + break; + + case 'i': + strcpy(args.file_name, optarg); + break; + + case 'b': + args.basis_type = get_basis_type(optarg); + assert(args.basis_type != -1); + break; + + case 'j': + args.mp_recon = get_mp_recon_type(optarg); + assert(args.mp_recon != -1); + break; + + case 'o': + assert(strlen(optarg) < sizeof(args.opt_args)); + strcpy(args.opt_args, optarg); + break; + + case '?': + break; } } - + args.use_gpu = use_gpu; args.use_mpi = use_mpi; args.trace_mem = trace_mem; diff --git a/pkpm/creg/rt_pkpm_2d_travel_pulse_p1.c b/pkpm/creg/rt_pkpm_2d_travel_pulse_p1.c index 44815ed0c4..65c83ab42b 100644 --- a/pkpm/creg/rt_pkpm_2d_travel_pulse_p1.c +++ b/pkpm/creg/rt_pkpm_2d_travel_pulse_p1.c @@ -21,8 +21,7 @@ #include #include -struct travel_pulse_ctx -{ +struct travel_pulse_ctx { // Mathematical constants (dimensionless). double pi; @@ -65,20 +64,19 @@ struct travel_pulse_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct travel_pulse_ctx -create_ctx(void) +struct travel_pulse_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -113,7 +111,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -122,17 +121,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_2d_travel_pulse_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_2d_travel_pulse_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = true; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_2d_travel_pulse_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_2d_travel_pulse_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct travel_pulse_ctx ctx = { @@ -176,14 +180,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; double x = xn[0], y = xn[1], vx = xn[2]; @@ -197,15 +200,16 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double n_perturb = n0 + (alpha * sin(pi * x) * sin(pi * y)); double T0 = sqrt(pr0 / n_perturb); - double F0 = (n_perturb / sqrt(2.0 * pi * T0 * T0)) * (exp(-(vx * vx) / (2.0 * T0 * T0))); // Distribution function (F0). + double F0 = (n_perturb / sqrt(2.0 * pi * T0 * T0)) * + (exp(-(vx * vx) / (2.0 * T0 * T0))); // Distribution function (F0). double G = (T0 * T0) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFluidInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -223,14 +227,15 @@ evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; - + double B0 = app->B0; double Ex = 0.0; // Total electric field (x-direction). @@ -240,17 +245,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = B0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; @@ -260,8 +268,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -276,33 +283,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -310,12 +322,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -327,9 +344,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -337,12 +357,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -368,18 +390,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -387,39 +408,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -442,60 +449,56 @@ main(int argc, char **argv) // Neutral species. struct gkyl_pkpm_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalDistInit, .ctx_dist = &ctx, .init_fluid = evalFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 2, .vdim = 1, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 1, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 1, - .species = { neut }, + .species = {neut}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -509,10 +512,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -521,53 +528,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -575,22 +587,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -601,11 +610,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -614,8 +625,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -628,12 +638,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -641,9 +656,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -655,11 +671,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -669,8 +687,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -685,7 +705,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -699,18 +719,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -718,25 +743,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -748,7 +780,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -756,8 +791,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -772,18 +809,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_alf_soliton_1x_p2.c b/pkpm/creg/rt_pkpm_alf_soliton_1x_p2.c index 8d7b466922..051300dc15 100644 --- a/pkpm/creg/rt_pkpm_alf_soliton_1x_p2.c +++ b/pkpm/creg/rt_pkpm_alf_soliton_1x_p2.c @@ -36,7 +36,7 @@ struct pkpm_alf_ctx { double vt_ion; double nuElc; double nuIon; - double di; + double di; double a; double delta_B0; double Lx; // Domain size (x-direction). @@ -50,99 +50,92 @@ struct pkpm_alf_ctx { bool use_gpu; }; -static inline double -maxwellian(double n, double v, double vth) +static inline double maxwellian(double n, double v, double vth) { - double v2 = v*v; - return n/sqrt(2*M_PI*vth*vth)*exp(-v2/(2*vth*vth)); + double v2 = v * v; + return n / sqrt(2 * M_PI * vth * vth) * exp(-v2 / (2 * vth * vth)); } -static inline double -sech(double x) +static inline double sech(double x) { - return 1.0/(cosh(x)); + return 1.0 / (cosh(x)); } -static inline double -sech2(double x) +static inline double sech2(double x) { - return 1.0/(cosh(x)*cosh(x)); + return 1.0 / (cosh(x) * cosh(x)); } -static inline double -tanh2(double x) +static inline double tanh2(double x) { - return tanh(x)*tanh(x); + return tanh(x) * tanh(x); } -void -evalDistFuncElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_alf_ctx *app = ctx; - + double x = xn[0], vx = xn[1]; double me = app->massElc; double B0 = app->B0; double n0 = app->n0; - double beta_elc = app->beta_elc; + double beta_elc = app->beta_elc; double B0perp = app->delta_B0; double a = app->a; - double di = app->di; - double n = 2.0*a*sech(a*x/di) + n0; + double di = app->di; + double n = 2.0 * a * sech(a * x / di) + n0; - double arg = 0.5*a*x/di; - double phi = 4.0*atan(tanh(arg)); + double arg = 0.5 * a * x / di; + double phi = 4.0 * atan(tanh(arg)); double B_x = B0; - double B_y = B0perp*sin(phi); - double B_z = B0perp*cos(phi); + double B_y = B0perp * sin(phi); + double B_z = B0perp * cos(phi); + + double magB2 = 0.5 * (B_x * B_x + B_y * B_y + B_z * B_z); + double Te = magB2 * beta_elc / n; + double vt_elc = sqrt(Te / me); - double magB2 = 0.5*(B_x*B_x + B_y*B_y + B_z*B_z); - double Te = magB2*beta_elc/n; - double vt_elc = sqrt(Te/me); - double fv = maxwellian(n, vx, vt_elc); - + fout[0] = fv; - fout[1] = vt_elc*vt_elc*fv; + fout[1] = vt_elc * vt_elc * fv; } -void -evalDistFuncIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_alf_ctx *app = ctx; - + double x = xn[0], vx = xn[1]; double mi = app->massIon; double B0 = app->B0; double n0 = app->n0; - double beta_ion = app->beta_ion; + double beta_ion = app->beta_ion; double B0perp = app->delta_B0; double a = app->a; - double di = app->di; - double n = 2.0*a*sech(a*x/di) + n0; + double di = app->di; + double n = 2.0 * a * sech(a * x / di) + n0; - double arg = 0.5*a*x/di; - double phi = 4.0*atan(tanh(arg)); + double arg = 0.5 * a * x / di; + double phi = 4.0 * atan(tanh(arg)); double B_x = B0; - double B_y = B0perp*sin(phi); - double B_z = B0perp*cos(phi); + double B_y = B0perp * sin(phi); + double B_z = B0perp * cos(phi); - double magB2 = 0.5*(B_x*B_x + B_y*B_y + B_z*B_z); - double Ti = magB2*beta_ion/n; - double vt_ion = sqrt(Ti/mi); + double magB2 = 0.5 * (B_x * B_x + B_y * B_y + B_z * B_z); + double Ti = magB2 * beta_ion / n; + double vt_ion = sqrt(Ti / mi); double fv = maxwellian(n, vx, vt_ion); - + fout[0] = fv; - fout[1] = vt_ion*vt_ion*fv; + fout[1] = vt_ion * vt_ion * fv; } -void -evalFluidElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFluidElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_alf_ctx *app = ctx; - + double x = xn[0]; double qe = app->chargeElc; @@ -152,26 +145,25 @@ evalFluidElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double B0perp = app->delta_B0; double a = app->a; - double di = app->di; - double arg = 0.5*a*x/di; - double phi = 4.0*atan(tanh(arg)); - double Jy = 2.0*B0perp*(a*sech2(arg)*sin(phi)/(di*tanh2(arg) + di)); - double Jz = 2.0*B0perp*(a*sech2(arg)*cos(phi)/(di*tanh2(arg) + di)); + double di = app->di; + double arg = 0.5 * a * x / di; + double phi = 4.0 * atan(tanh(arg)); + double Jy = 2.0 * B0perp * (a * sech2(arg) * sin(phi) / (di * tanh2(arg) + di)); + double Jz = 2.0 * B0perp * (a * sech2(arg) * cos(phi) / (di * tanh2(arg) + di)); double vdrift_x = 0.0; - double vdrift_y = Jy/qe; - double vdrift_z = Jz/qe; + double vdrift_y = Jy / qe; + double vdrift_z = Jz / qe; - fout[0] = me*vdrift_x; - fout[1] = me*vdrift_y; - fout[2] = me*vdrift_z; + fout[0] = me * vdrift_x; + fout[1] = me * vdrift_y; + fout[2] = me * vdrift_z; } -void -evalFluidIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFluidIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_alf_ctx *app = ctx; - + double x = xn[0]; double qe = app->chargeElc; @@ -184,13 +176,12 @@ evalFluidIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double vdrift_y = 0.0; double vdrift_z = 0.0; - fout[0] = mi*vdrift_x; - fout[1] = mi*vdrift_y; - fout[2] = mi*vdrift_z; + fout[0] = mi * vdrift_x; + fout[1] = mi * vdrift_y; + fout[2] = mi * vdrift_z; } -void -evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_alf_ctx *app = ctx; @@ -203,48 +194,49 @@ evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double B0perp = app->delta_B0; double a = app->a; - double di = app->di; - double arg = 0.5*a*x/di; - double phi = 4.0*atan(tanh(arg)); + double di = app->di; + double arg = 0.5 * a * x / di; + double phi = 4.0 * atan(tanh(arg)); double B_x = B0; - double B_y = B0perp*sin(phi); - double B_z = B0perp*cos(phi); + double B_y = B0perp * sin(phi); + double B_z = B0perp * cos(phi); // Assumes qi = abs(qe) - double Jy = 2.0*B0perp*(a*sech2(arg)*sin(phi)/(di*tanh2(arg) + di)); - double Jz = 2.0*B0perp*(a*sech2(arg)*cos(phi)/(di*tanh2(arg) + di)); - double n = 2.0*a*sech(a*x/di); + double Jy = 2.0 * B0perp * (a * sech2(arg) * sin(phi) / (di * tanh2(arg) + di)); + double Jz = 2.0 * B0perp * (a * sech2(arg) * cos(phi) / (di * tanh2(arg) + di)); + double n = 2.0 * a * sech(a * x / di); double u_xe = 0.0; - double u_ye = Jy/(n*qe); - double u_ze = Jz/(n*qe); + double u_ye = Jy / (n * qe); + double u_ze = Jz / (n * qe); // E = - v_e x B ~ (J - u) x B - double E_x = - (u_ye*B_z - u_ze*B_y); - double E_y = - (u_ze*B_x - u_xe*B_z); - double E_z = - (u_xe*B_y - u_ye*B_x); - - fout[0] = E_x; fout[1] = E_y, fout[2] = E_z; - fout[3] = B_x; fout[4] = B_y; fout[5] = B_z; - fout[6] = 0.0; fout[7] = 0.0; + double E_x = -(u_ye * B_z - u_ze * B_y); + double E_y = -(u_ze * B_x - u_xe * B_z); + double E_z = -(u_xe * B_y - u_ye * B_x); + + fout[0] = E_x; + fout[1] = E_y, fout[2] = E_z; + fout[3] = B_x; + fout[4] = B_y; + fout[5] = B_z; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNuElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_alf_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_alf_ctx *app = ctx; fout[0] = app->nuIon; } -struct pkpm_alf_ctx -create_ctx(void) +struct pkpm_alf_ctx create_ctx(void) { double epsilon0 = 1.0; // permittivity of free space double mu0 = 1.0; // pemiability of free space @@ -257,36 +249,36 @@ create_ctx(void) double Te_Ti = 1.0; // ratio of electron to ion temperature // initial conditions double a = 0.01; - double n0 = 1.0; // initial number density + double n0 = 1.0; // initial number density double vAe = 0.25; double beta_elc = 0.5; - double B0 = vAe*sqrt(mu0*n0*massElc); - double delta_B0 = a*B0; - double vt_elc = vAe*sqrt(beta_elc/2.0); + double B0 = vAe * sqrt(mu0 * n0 * massElc); + double delta_B0 = a * B0; + double vt_elc = vAe * sqrt(beta_elc / 2.0); // ion velocities - double vAi = vAe/sqrt(massIon); - double vt_ion = vt_elc/sqrt(massIon*Te_Ti); //Ti/Te = 1.0 - double beta_ion = beta_elc/Te_Ti; + double vAi = vAe / sqrt(massIon); + double vt_ion = vt_elc / sqrt(massIon * Te_Ti); //Ti/Te = 1.0 + double beta_ion = beta_elc / Te_Ti; // ion cyclotron frequency and gyroradius - double omegaCi = chargeIon*B0/massIon; - double di = vAi/omegaCi; - double rhoi = sqrt(2.0)*vt_ion/omegaCi; + double omegaCi = chargeIon * B0 / massIon; + double di = vAi / omegaCi; + double rhoi = sqrt(2.0) * vt_ion / omegaCi; // collision frequencies - double nuElc = 0.0001*omegaCi; - double nuIon = 0.0001*omegaCi/sqrt(massIon); + double nuElc = 0.0001 * omegaCi; + double nuIon = 0.0001 * omegaCi / sqrt(massIon); - double Lx = 10.0*(di/a); - int Nx = 16; - double dx = Lx/Nx; + double Lx = 10.0 * (di / a); + int Nx = 16; + double dx = Lx / Nx; double cfl_frac = 1.0; // CFL coefficient. - double t_end = 10000.0/omegaCi; // Final simulation time. + double t_end = 10000.0 / omegaCi; // Final simulation time. int num_frames = 1; // Number of output frames. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - double init_dt = (Lx/Nx)/(5.0); + double init_dt = (Lx / Nx) / (5.0); struct pkpm_alf_ctx ctx = { .epsilon0 = epsilon0, @@ -305,23 +297,22 @@ create_ctx(void) .vt_ion = vt_ion, .nuElc = nuElc, .nuIon = nuIon, - .di = di, - .a = a, + .di = di, + .a = a, .delta_B0 = delta_B0, .Lx = Lx, - .Nx = Nx, + .Nx = Nx, .cfl_frac = cfl_frac, .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .init_dt = init_dt, + .init_dt = init_dt }; return ctx; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -329,12 +320,11 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool frame = iot->curr; } - gkyl_pkpm_app_write(app, t_curr, iot->curr-1); + gkyl_pkpm_app_write(app, t_curr, iot->curr - 1); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -353,52 +343,53 @@ main(int argc, char **argv) gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } - + // electrons struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.chargeElc, .mass = ctx.massElc, - .lower = { -6.0 * ctx.vt_elc}, - .upper = { 6.0 * ctx.vt_elc}, - .cells = { VX }, + .charge = ctx.chargeElc, + .mass = ctx.massElc, + .lower = {-6.0 * ctx.vt_elc}, + .upper = {6.0 * ctx.vt_elc}, + .cells = {VX}, .ctx_dist = &ctx, .ctx_fluid = &ctx, .init_dist = evalDistFuncElc, .init_fluid = evalFluidElc, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, - .ctx = &ctx, - .self_nu = evalNuElc, - }, + .ctx = &ctx, + .self_nu = evalNuElc} }; - + // ions struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.chargeIon, .mass = ctx.massIon, - .lower = { -6.0 * ctx.vt_ion}, - .upper = { 6.0 * ctx.vt_ion}, - .cells = { VX }, + .charge = ctx.chargeIon, + .mass = ctx.massIon, + .lower = {-6.0 * ctx.vt_ion}, + .upper = {6.0 * ctx.vt_ion}, + .cells = {VX}, .ctx_dist = &ctx, .ctx_fluid = &ctx, .init_dist = evalDistFuncIon, .init_fluid = evalFluidIon, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, - .ctx = &ctx, - .self_nu = evalNuIon, - }, + .ctx = &ctx, + .self_nu = evalNuIon} }; // field struct gkyl_pkpm_field field = { - .epsilon0 = 1.0, .mu0 = 1.0, + .epsilon0 = 1.0, + .mu0 = 1.0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, @@ -418,32 +409,18 @@ main(int argc, char **argv) #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -451,7 +428,7 @@ main(int argc, char **argv) int comm_size; gkyl_comm_get_size(comm, &comm_size); - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int ncuts = 1; for (int d = 0; d < cdim; d++) { @@ -468,28 +445,25 @@ main(int argc, char **argv) // pkpm app struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -ctx.Lx }, - .upper = { ctx.Lx }, - .cells = { NX}, + .cdim = 1, + .vdim = 1, + .lower = {-ctx.Lx}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = 2, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - // .use_explicit_source = true, - + // .use_explicit_source = true, + .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // create app object @@ -503,11 +477,11 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // initialize simulation gkyl_pkpm_app_apply_ic(app, t_curr); - write_data(&io_trig, app, t_curr, false); + write_data(&io_trig, app, t_curr, false); // Initialize small time-step check. double dt_init = -1.0, dt_failure_tol = ctx.dt_failure_tol; @@ -518,7 +492,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -531,8 +505,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -540,11 +513,12 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -561,25 +535,39 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid Species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid Species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM Vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); - gkyl_pkpm_app_cout(app, stdout, "EM Variables (bvar) calculation took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "EM Variables (bvar) calculation took %g secs\n", stat.field_em_vars_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Species BCs took %g secs\n", stat.species_bc_tm); gkyl_pkpm_app_cout(app, stdout, "Fluid Species BCs took %g secs\n", stat.fluid_species_bc_tm); gkyl_pkpm_app_cout(app, stdout, "Field BCs took %g secs\n", stat.field_bc_tm); - + gkyl_pkpm_app_cout(app, stdout, "Updates took %g secs\n", stat.total_tm); - + gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld,\n", stat.n_io); gkyl_pkpm_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); @@ -588,12 +576,12 @@ main(int argc, char **argv) // simulation complete, free app gkyl_pkpm_app_release(app); - mpifinalize: - ; +mpifinalize:; #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); -#endif - + } +#endif + return 0; } diff --git a/pkpm/creg/rt_pkpm_alf_wave_1x_p1.c b/pkpm/creg/rt_pkpm_alf_wave_1x_p1.c index 33b70eeace..84b75c5755 100644 --- a/pkpm/creg/rt_pkpm_alf_wave_1x_p1.c +++ b/pkpm/creg/rt_pkpm_alf_wave_1x_p1.c @@ -21,8 +21,7 @@ #include #include -struct alf_wave_ctx -{ +struct alf_wave_ctx { // Mathematical constants (dimensionless). double pi; @@ -81,20 +80,19 @@ struct alf_wave_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct alf_wave_ctx -create_ctx(void) +struct alf_wave_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -145,7 +143,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -154,17 +153,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_alf_wave_1x_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_alf_wave_1x_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_alf_wave_1x_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_alf_wave_1x_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct alf_wave_ctx ctx = { @@ -219,14 +223,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double vx = xn[1]; @@ -236,15 +239,18 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vte = app->vte; - double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). double G = (vte * vte) * F0; // Electron distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -268,11 +274,12 @@ evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = mass_elc * vz_drift; // Electron total momentum density (z-direction). // Set electron total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double vx = xn[1]; @@ -282,15 +289,18 @@ evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vti = app->vti; - double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). double G = (vti * vti) * F0; // Ion distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -309,11 +319,12 @@ evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = mass_ion * vz_drift; // Ion total momentum density (z-direction). // Set ion total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -342,17 +353,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = -((vy_drift * Bz) - (vz_drift * By)); // Total electric field (x-direction). double Ey = -((vz_drift * Bx) - (vx_drift * Bz)); // Total electric field (y-direction). double Ez = -((vx_drift * By) - (vy_drift * Bx)); // Total electric field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; @@ -362,8 +376,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; @@ -373,8 +386,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -389,33 +401,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -423,12 +440,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -440,9 +462,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -450,12 +475,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -480,18 +507,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -499,39 +525,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -554,60 +566,56 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalElcNu, .ctx = &ctx} }; // Ions. struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .init_dist = evalIonDistInit, .ctx_dist = &ctx, .init_fluid = evalIonFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalIonNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, @@ -616,18 +624,14 @@ main(int argc, char **argv) .use_explicit_source = false, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -641,10 +645,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -653,53 +661,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -707,22 +720,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -733,11 +743,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -746,8 +758,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -760,12 +771,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -773,9 +789,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -787,11 +804,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -801,8 +820,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -817,7 +838,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -831,18 +852,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -850,25 +876,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -880,7 +913,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -888,8 +924,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -904,18 +942,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_alf_wave_1x_p2.c b/pkpm/creg/rt_pkpm_alf_wave_1x_p2.c index 179f08e65c..cb1519e5de 100644 --- a/pkpm/creg/rt_pkpm_alf_wave_1x_p2.c +++ b/pkpm/creg/rt_pkpm_alf_wave_1x_p2.c @@ -21,8 +21,7 @@ #include #include -struct alf_wave_ctx -{ +struct alf_wave_ctx { // Mathematical constants (dimensionless). double pi; @@ -81,20 +80,19 @@ struct alf_wave_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct alf_wave_ctx -create_ctx(void) +struct alf_wave_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -145,7 +143,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -154,17 +153,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_alf_wave_1x_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_alf_wave_1x_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_alf_wave_1x_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_alf_wave_1x_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct alf_wave_ctx ctx = { @@ -219,14 +223,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double vx = xn[1]; @@ -236,15 +239,18 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vte = app->vte; - double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). double G = (vte * vte) * F0; // Electron distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -268,11 +274,12 @@ evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = mass_elc * vz_drift; // Electron total momentum density (z-direction). // Set electron total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double vx = xn[1]; @@ -282,15 +289,18 @@ evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vti = app->vti; - double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). double G = (vti * vti) * F0; // Ion distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -309,11 +319,12 @@ evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = mass_ion * vz_drift; // Ion total momentum density (z-direction). // Set ion total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -342,17 +353,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = -((vy_drift * Bz) - (vz_drift * By)); // Total electric field (x-direction). double Ey = -((vz_drift * Bx) - (vx_drift * Bz)); // Total electric field (y-direction). double Ez = -((vx_drift * By) - (vy_drift * Bx)); // Total electric field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; @@ -362,8 +376,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; @@ -373,8 +386,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -389,33 +401,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -423,12 +440,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -440,9 +462,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -450,12 +475,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -480,18 +507,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -499,39 +525,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -554,60 +566,56 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalElcNu, .ctx = &ctx} }; // Ions. struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .init_dist = evalIonDistInit, .ctx_dist = &ctx, .init_fluid = evalIonFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalIonNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, @@ -616,18 +624,14 @@ main(int argc, char **argv) .use_explicit_source = false, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -641,10 +645,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -653,53 +661,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -707,22 +720,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -733,11 +743,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -746,8 +758,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -760,12 +771,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -773,9 +789,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -787,11 +804,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -801,8 +820,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -817,7 +838,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -831,18 +852,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -850,25 +876,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -880,7 +913,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -888,8 +924,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -904,18 +942,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_alf_wave_explicit_1x_p1.c b/pkpm/creg/rt_pkpm_alf_wave_explicit_1x_p1.c index 78f1935b8b..61c04e39ab 100644 --- a/pkpm/creg/rt_pkpm_alf_wave_explicit_1x_p1.c +++ b/pkpm/creg/rt_pkpm_alf_wave_explicit_1x_p1.c @@ -21,8 +21,7 @@ #include #include -struct alf_wave_ctx -{ +struct alf_wave_ctx { // Mathematical constants (dimensionless). double pi; @@ -81,20 +80,19 @@ struct alf_wave_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct alf_wave_ctx -create_ctx(void) +struct alf_wave_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -145,7 +143,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -154,17 +153,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_alf_wave_explicit_1x_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_alf_wave_explicit_1x_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_alf_wave_explicit_1x_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_alf_wave_explicit_1x_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct alf_wave_ctx ctx = { @@ -219,14 +223,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double vx = xn[1]; @@ -236,15 +239,18 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vte = app->vte; - double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). double G = (vte * vte) * F0; // Electron distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -268,11 +274,12 @@ evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = mass_elc * vz_drift; // Electron total momentum density (z-direction). // Set electron total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double vx = xn[1]; @@ -282,15 +289,18 @@ evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vti = app->vti; - double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). double G = (vti * vti) * F0; // Ion distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -309,11 +319,12 @@ evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = mass_ion * vz_drift; // Ion total momentum density (z-direction). // Set ion total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -342,17 +353,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = -((vy_drift * Bz) - (vz_drift * By)); // Total electric field (x-direction). double Ey = -((vz_drift * Bx) - (vx_drift * Bz)); // Total electric field (y-direction). double Ez = -((vx_drift * By) - (vy_drift * Bx)); // Total electric field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; @@ -362,8 +376,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; @@ -373,8 +386,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -389,33 +401,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -423,12 +440,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -440,9 +462,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -450,12 +475,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -480,18 +507,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -499,39 +525,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -554,60 +566,56 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalElcNu, .ctx = &ctx} }; // Ions. struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .init_dist = evalIonDistInit, .ctx_dist = &ctx, .init_fluid = evalIonFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalIonNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, @@ -616,18 +624,14 @@ main(int argc, char **argv) .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -641,10 +645,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -653,53 +661,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -707,22 +720,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -733,11 +743,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -746,8 +758,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -760,12 +771,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -773,9 +789,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -787,11 +804,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -801,8 +820,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -817,7 +838,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -831,18 +852,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -850,25 +876,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -880,7 +913,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -888,8 +924,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -904,18 +942,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_alf_wave_explicit_1x_p2.c b/pkpm/creg/rt_pkpm_alf_wave_explicit_1x_p2.c index a361fde36e..c1fab917ad 100644 --- a/pkpm/creg/rt_pkpm_alf_wave_explicit_1x_p2.c +++ b/pkpm/creg/rt_pkpm_alf_wave_explicit_1x_p2.c @@ -21,8 +21,7 @@ #include #include -struct alf_wave_ctx -{ +struct alf_wave_ctx { // Mathematical constants (dimensionless). double pi; @@ -81,20 +80,19 @@ struct alf_wave_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct alf_wave_ctx -create_ctx(void) +struct alf_wave_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -145,7 +143,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -154,17 +153,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_alf_wave_explicit_1x_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_alf_wave_explicit_1x_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_alf_wave_explicit_1x_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_alf_wave_explicit_1x_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct alf_wave_ctx ctx = { @@ -219,14 +223,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double vx = xn[1]; @@ -236,15 +239,18 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vte = app->vte; - double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). double G = (vte * vte) * F0; // Electron distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -268,11 +274,12 @@ evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = mass_elc * vz_drift; // Electron total momentum density (z-direction). // Set electron total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double vx = xn[1]; @@ -282,15 +289,18 @@ evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vti = app->vti; - double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). double G = (vti * vti) * F0; // Ion distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -309,11 +319,12 @@ evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = mass_ion * vz_drift; // Ion total momentum density (z-direction). // Set ion total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; double x = xn[0]; @@ -342,17 +353,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = -((vy_drift * Bz) - (vz_drift * By)); // Total electric field (x-direction). double Ey = -((vz_drift * Bx) - (vx_drift * Bz)); // Total electric field (y-direction). double Ez = -((vx_drift * By) - (vy_drift * Bx)); // Total electric field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; @@ -362,8 +376,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct alf_wave_ctx *app = ctx; @@ -373,8 +386,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -389,33 +401,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -423,12 +440,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -440,9 +462,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -450,12 +475,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -480,18 +507,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -499,39 +525,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -554,60 +566,56 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalElcNu, .ctx = &ctx} }; // Ions. struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .init_dist = evalIonDistInit, .ctx_dist = &ctx, .init_fluid = evalIonFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalIonNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, @@ -616,18 +624,14 @@ main(int argc, char **argv) .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -641,10 +645,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -653,53 +661,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -707,22 +720,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -733,11 +743,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -746,8 +758,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -760,12 +771,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -773,9 +789,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -787,11 +804,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -801,8 +820,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -817,7 +838,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -831,18 +852,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -850,25 +876,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -880,7 +913,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -888,8 +924,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -904,18 +942,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_alf_wave_p1.c b/pkpm/creg/rt_pkpm_alf_wave_p1.c index 19109b8a8f..da7c7c0170 100644 --- a/pkpm/creg/rt_pkpm_alf_wave_p1.c +++ b/pkpm/creg/rt_pkpm_alf_wave_p1.c @@ -33,7 +33,7 @@ struct pkpm_kalf_ctx { double vtIon; double nuElc; double nuIon; - double Bx; + double Bx; double By; double Bz; double uxi; @@ -50,7 +50,7 @@ struct pkpm_kalf_ctx { double uziPhi; double uxePhi; double uyePhi; - double uzePhi; + double uzePhi; double kpar; double kperp; double Lpar; @@ -60,77 +60,72 @@ struct pkpm_kalf_ctx { bool use_gpu; }; -static inline double -maxwellian(double n, double v, double vth) +static inline double maxwellian(double n, double v, double vth) { - double v2 = v*v; - return n/sqrt(2*M_PI*vth*vth)*exp(-v2/(2*vth*vth)); + double v2 = v * v; + return n / sqrt(2 * M_PI * vth * vth) * exp(-v2 / (2 * vth * vth)); } -void -evalDistFuncElc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_kalf_ctx *app = ctx; - + double x = xn[0], y = xn[1], vx = xn[2]; double qe = app->chargeElc; double qi = app->chargeIon; - + double fv = maxwellian(app->n0, vx, app->vtElc); - + fout[0] = fv; - fout[1] = app->vtElc*app->vtElc*fv; + fout[1] = app->vtElc * app->vtElc * fv; } -void -evalDistFuncIon(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_kalf_ctx *app = ctx; - + double x = xn[0], y = xn[1], vx = xn[2]; double qe = app->chargeElc; double qi = app->chargeIon; double fv = maxwellian(app->n0, vx, app->vtIon); - + fout[0] = fv; - fout[1] = app->vtIon*app->vtIon*fv; + fout[1] = app->vtIon * app->vtIon * fv; } -void -evalFluidElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFluidElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_kalf_ctx *app = ctx; - + double x = xn[0], y = xn[1]; double me = app->massElc; double kpar = app->kpar; - double kperp = app->kperp; + double kperp = app->kperp; double uxe = app->uxe; double uye = app->uye; double uze = app->uze; double uxePhi = app->uxePhi; double uyePhi = app->uyePhi; - double uzePhi = app->uzePhi; + double uzePhi = app->uzePhi; - // rotate PLUME data about x by -90 degrees - double u_xe = uxe*cos(kperp*x + kpar*y + uxePhi); - double u_ye = uze*cos(kperp*x + kpar*y + uzePhi); - double u_ze = -uye*cos(kperp*x + kpar*y + uyePhi); + // rotate PLUME data about x by -90 degrees + double u_xe = uxe * cos(kperp * x + kpar * y + uxePhi); + double u_ye = uze * cos(kperp * x + kpar * y + uzePhi); + double u_ze = -uye * cos(kperp * x + kpar * y + uyePhi); // n0 = 1, so initially uniform density - fout[0] = me*u_xe; - fout[1] = me*u_ye; - fout[2] = me*u_ze; + fout[0] = me * u_xe; + fout[1] = me * u_ye; + fout[2] = me * u_ze; } -void -evalFluidIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFluidIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_kalf_ctx *app = ctx; - + double x = xn[0], y = xn[1]; double mi = app->massIon; @@ -143,19 +138,18 @@ evalFluidIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double uyiPhi = app->uyiPhi; double uziPhi = app->uziPhi; - // rotate PLUME data about x by -90 degrees - double u_xi = uxi*cos(kperp*x + kpar*y + uxiPhi); - double u_yi = uzi*cos(kperp*x + kpar*y + uziPhi); - double u_zi = -uyi*cos(kperp*x + kpar*y + uyiPhi); + // rotate PLUME data about x by -90 degrees + double u_xi = uxi * cos(kperp * x + kpar * y + uxiPhi); + double u_yi = uzi * cos(kperp * x + kpar * y + uziPhi); + double u_zi = -uyi * cos(kperp * x + kpar * y + uyiPhi); // n0 = 1, so initially uniform density - fout[0] = mi*u_xi; - fout[1] = mi*u_yi; - fout[2] = mi*u_zi; + fout[0] = mi * u_xi; + fout[1] = mi * u_yi; + fout[2] = mi * u_zi; } -void -evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_kalf_ctx *app = ctx; @@ -177,41 +171,42 @@ evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double uyePhi = app->uyePhi; double uzePhi = app->uzePhi; - // rotate PLUME data about x by -90 degrees - double B_x = Bx*cos(kperp*x+kpar*y+BxPhi); - double B_y = (B0+Bz*cos(kperp*x+kpar*y+BzPhi)); - double B_z = -By*cos(kperp*x+kpar*y+ByPhi); + // rotate PLUME data about x by -90 degrees + double B_x = Bx * cos(kperp * x + kpar * y + BxPhi); + double B_y = (B0 + Bz * cos(kperp * x + kpar * y + BzPhi)); + double B_z = -By * cos(kperp * x + kpar * y + ByPhi); - double u_xe = uxe*cos(kperp*x + kpar*y + uxePhi); - double u_ye = uze*cos(kperp*x + kpar*y + uzePhi); - double u_ze = -uye*cos(kperp*x + kpar*y + uyePhi); + double u_xe = uxe * cos(kperp * x + kpar * y + uxePhi); + double u_ye = uze * cos(kperp * x + kpar * y + uzePhi); + double u_ze = -uye * cos(kperp * x + kpar * y + uyePhi); // E = - v_e x B ~ (J - u) x B - double E_x = - (u_ye*B_z - u_ze*B_y); - double E_y = - (u_ze*B_x - u_xe*B_z); - double E_z = - (u_xe*B_y - u_ye*B_x); - - fout[0] = E_x; fout[1] = E_y, fout[2] = E_z; - fout[3] = B_x; fout[4] = B_y; fout[5] = B_z; - fout[6] = 0.0; fout[7] = 0.0; + double E_x = -(u_ye * B_z - u_ze * B_y); + double E_y = -(u_ze * B_x - u_xe * B_z); + double E_z = -(u_xe * B_y - u_ye * B_x); + + fout[0] = E_x; + fout[1] = E_y, fout[2] = E_z; + fout[3] = B_x; + fout[4] = B_y; + fout[5] = B_z; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNuElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_kalf_ctx *app = ctx; fout[0] = app->nuElc; } -void -evalNuIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct pkpm_kalf_ctx *app = ctx; fout[0] = app->nuIon; } -struct pkpm_kalf_ctx -create_ctx(void) +struct pkpm_kalf_ctx create_ctx(void) { double epsilon0 = 1.0; // permittivity of free space double mu0 = 1.0; // pemiability of free space @@ -226,75 +221,75 @@ create_ctx(void) double vAe = 0.045; double beta = 1.0; - double B0 = vAe*sqrt(mu0*n0*massElc); - double vtElc = vAe*sqrt(beta/2.0); + double B0 = vAe * sqrt(mu0 * n0 * massElc); + double vtElc = vAe * sqrt(beta / 2.0); // ion velocities - double vAi = vAe/sqrt(massIon); - double vtIon = vtElc/sqrt(massIon); //Ti/Te = 1.0 + double vAi = vAe / sqrt(massIon); + double vtIon = vtElc / sqrt(massIon); //Ti/Te = 1.0 // ion cyclotron frequency and gyroradius - double omegaCi = chargeIon*B0/massIon; - double di = vAi/omegaCi; - double rhoi = sqrt(2.)*vtIon/omegaCi; + double omegaCi = chargeIon * B0 / massIon; + double di = vAi / omegaCi; + double rhoi = sqrt(2.) * vtIon / omegaCi; // collision frequencies - double nuElc = 1.0e-4*omegaCi; - double nuIon = 1.0e-4*omegaCi/sqrt(massIon); + double nuElc = 1.0e-4 * omegaCi; + double nuIon = 1.0e-4 * omegaCi / sqrt(massIon); // initial conditions double a = 1.e-2; // modified from 1./3. - double delta_B0 = a*B0; - double delta_u0 = a*vAi; + double delta_B0 = a * B0; + double delta_u0 = a * vAi; // kperp rhoi = 0.1 - //double kperp = 0.1 / rhoi; + //double kperp = 0.1 / rhoi; //double kpar = 0.00872 / rhoi; // Theta = 85 degrees - + // kperp rhoi = 0.2 - //double kperp = 0.201 / rhoi; + //double kperp = 0.201 / rhoi; //double kpar = 0.0175 / rhoi; // Theta = 85 degrees // kperp rhoi = 0.5 - //double kperp = 0.5 / rhoi; + //double kperp = 0.5 / rhoi; //double kpar = 0.0436 / rhoi; // Theta = 85 degrees // kperp rhoi = 1 - //double kperp = 1.005412 / rhoi; + //double kperp = 1.005412 / rhoi; //double kpar = 0.087627 / rhoi; // Theta = 85 degrees // kpar rhoi = 1 - //double kperp = 0.01 / rhoi; + //double kperp = 0.01 / rhoi; //double kpar = 1. / rhoi; // Theta_kB = 0.6 degrees // kperp rhoi = 2.09 - double kperp = 2.0908 / rhoi; + double kperp = 2.0908 / rhoi; double kpar = 0.095 / rhoi; // Theta = 87.4 degrees - double Bx = 0.031191*delta_B0; // new - double By = 1.035059*delta_B0; - double Bz = 0.686470*delta_B0; + double Bx = 0.031191 * delta_B0; // new + double By = 1.035059 * delta_B0; + double Bz = 0.686470 * delta_B0; double BxPhi = -1.504895; double ByPhi = -0.133840; double BzPhi = 1.636697; - double uxi = 0.047635*delta_u0; - double uyi = 0.228177*delta_u0; - double uzi = 0.135527*delta_u0; + double uxi = 0.047635 * delta_u0; + double uyi = 0.228177 * delta_u0; + double uzi = 0.135527 * delta_u0; double uxiPhi = -1.745406; double uyiPhi = -3.053345; double uziPhi = 0.135527; - double uxe = 0.050772*delta_u0; - double uye = 1.666362*delta_u0; - double uze = 2.208089*delta_u0; + double uxe = 0.050772 * delta_u0; + double uye = 1.666362 * delta_u0; + double uze = 2.208089 * delta_u0; double uxePhi = 1.475205; double uyePhi = -3.072632; - double uzePhi = -1.7021012; // end new + double uzePhi = -1.7021012; // end new // domain size and simulation time - double Lpar = 2.0*M_PI/kpar; - double Lperp = 2.0*M_PI/kperp; + double Lpar = 2.0 * M_PI / kpar; + double Lperp = 2.0 * M_PI / kperp; - double tend = 1.0/omegaCi; + double tend = 1.0 / omegaCi; struct pkpm_kalf_ctx ctx = { .epsilon0 = epsilon0, @@ -312,7 +307,7 @@ create_ctx(void) .vtIon = vtIon, .nuElc = nuElc, .nuIon = nuIon, - .Bx = Bx, // new + .Bx = Bx, // new .By = By, .Bz = Bz, .uxi = uxi, @@ -329,32 +324,32 @@ create_ctx(void) .uziPhi = uziPhi, .uxePhi = uxePhi, .uyePhi = uyePhi, - .uzePhi = uzePhi, - .kpar = kpar, - .kperp = kperp, - .Lpar = Lpar, - .Lperp = Lperp, + .uzePhi = uzePhi, + .kpar = kpar, + .kperp = kperp, + .Lpar = Lpar, + .Lperp = Lperp, .tend = tend, - .min_dt = 1.0e-2, + .min_dt = 1.0e-2 }; return ctx; } -void -write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double tcurr) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double tcurr) { - if (gkyl_tm_trigger_check_and_bump(iot, tcurr)) - gkyl_pkpm_app_write(app, tcurr, iot->curr-1); + if (gkyl_tm_trigger_check_and_bump(iot, tcurr)) { + gkyl_pkpm_app_write(app, tcurr, iot->curr - 1); + } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Init(&argc, &argv); + } #endif int NX = APP_ARGS_CHOOSE(app_args.xcells[0], 32); @@ -365,54 +360,55 @@ main(int argc, char **argv) gkyl_cu_dev_mem_debug_set(true); gkyl_mem_debug_set(true); } - + struct pkpm_kalf_ctx ctx = create_ctx(); // context for init functions // electrons struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.chargeElc, .mass = ctx.massElc, - .lower = { -6.0 * ctx.vtElc}, - .upper = { 6.0 * ctx.vtElc}, - .cells = { VX }, + .charge = ctx.chargeElc, + .mass = ctx.massElc, + .lower = {-6.0 * ctx.vtElc}, + .upper = {6.0 * ctx.vtElc}, + .cells = {VX}, .ctx_dist = &ctx, .ctx_fluid = &ctx, .init_dist = evalDistFuncElc, .init_fluid = evalFluidElc, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, - .ctx = &ctx, - .self_nu = evalNuElc, - }, + .ctx = &ctx, + .self_nu = evalNuElc} }; - + // ions struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.chargeIon, .mass = ctx.massIon, - .lower = { -6.0 * ctx.vtIon}, - .upper = { 6.0 * ctx.vtIon}, - .cells = { VX }, + .charge = ctx.chargeIon, + .mass = ctx.massIon, + .lower = {-6.0 * ctx.vtIon}, + .upper = {6.0 * ctx.vtIon}, + .cells = {VX}, .ctx_dist = &ctx, .ctx_fluid = &ctx, .init_dist = evalDistFuncIon, .init_fluid = evalFluidIon, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, - .ctx = &ctx, - .self_nu = evalNuIon, - }, + .ctx = &ctx, + .self_nu = evalNuIon} }; // field struct gkyl_pkpm_field field = { - .epsilon0 = 1.0, .mu0 = 1.0, + .epsilon0 = 1.0, + .mu0 = 1.0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, @@ -422,41 +418,28 @@ main(int argc, char **argv) int nrank = 1; // number of processors in simulation #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); -#endif + } +#endif // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -464,7 +447,7 @@ main(int argc, char **argv) int comm_size; gkyl_comm_get_size(comm, &comm_size); - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int ncuts = 1; for (int d = 0; d < cdim; d++) { @@ -481,25 +464,23 @@ main(int argc, char **argv) // pkpm app struct gkyl_pkpm app_inp = { - .cdim = 2, .vdim = 1, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lperp, ctx.Lpar }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 1, + .lower = {0.0, 0.0}, + .upper = {ctx.Lperp, ctx.Lpar}, + .cells = {NX, NY}, .poly_order = 1, .basis_type = app_args.basis_type, - + .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // create app object @@ -509,10 +490,10 @@ main(int argc, char **argv) // start, end and initial time-step double tcurr = 0.0, tend = ctx.tend; - double dt = tend-tcurr; + double dt = tend - tcurr; int nframe = 1; // create trigger for IO - struct gkyl_tm_trigger io_trig = { .dt = tend/nframe }; + struct gkyl_tm_trigger io_trig = {.dt = tend / nframe}; // initialize simulation gkyl_pkpm_app_apply_ic(app, tcurr); @@ -536,7 +517,9 @@ main(int argc, char **argv) break; } if (status.dt_actual < ctx.min_dt) { - gkyl_pkpm_app_cout(app, stdout, "** Time step crashing! Aborting simulation and writing out last output ....\n"); + gkyl_pkpm_app_cout( + app, stdout, "** Time step crashing! Aborting simulation and writing out last output ....\n" + ); gkyl_pkpm_app_write(app, tcurr, 1000); break; } @@ -563,25 +546,39 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid Species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid Species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM Vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); - gkyl_pkpm_app_cout(app, stdout, "EM Variables (bvar) calculation took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "EM Variables (bvar) calculation took %g secs\n", stat.field_em_vars_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Species BCs took %g secs\n", stat.species_bc_tm); gkyl_pkpm_app_cout(app, stdout, "Fluid Species BCs took %g secs\n", stat.fluid_species_bc_tm); gkyl_pkpm_app_cout(app, stdout, "Field BCs took %g secs\n", stat.field_bc_tm); - + gkyl_pkpm_app_cout(app, stdout, "Updates took %g secs\n", stat.total_tm); - + gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld,\n", stat.n_io); gkyl_pkpm_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); @@ -590,12 +587,12 @@ main(int argc, char **argv) // simulation complete, free app gkyl_pkpm_app_release(app); - mpifinalize: - ; +mpifinalize:; #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); -#endif - + } +#endif + return 0; } \ No newline at end of file diff --git a/pkpm/creg/rt_pkpm_em_advect_p1.c b/pkpm/creg/rt_pkpm_em_advect_p1.c index f98a0f38ce..062ff2cb59 100644 --- a/pkpm/creg/rt_pkpm_em_advect_p1.c +++ b/pkpm/creg/rt_pkpm_em_advect_p1.c @@ -1,7 +1,7 @@ // Advection in specified electromagnetic fields for the PKPM system of equations. // Input parameters match the initial conditions found in entry JE32 of Ammar's Simulation Journal (https://ammar-hakim.org/sj/je/je32/je32-vlasov-test-ptcl.html) -// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. -// Solution is given by the non-resonant case, omega = 0.5*Omega_c where Omega_c = q B/m is the cyclotron frequency. +// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. +// Solution is given by the non-resonant case, omega = 0.5*Omega_c where Omega_c = q B/m is the cyclotron frequency. #include #include @@ -26,8 +26,7 @@ #include #include -struct em_advect_ctx -{ +struct em_advect_ctx { // Mathematical constants (dimensionless). double pi; @@ -63,20 +62,19 @@ struct em_advect_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct em_advect_ctx -create_ctx(void) +struct em_advect_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -104,7 +102,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -113,17 +112,21 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_em_advect_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_em_advect_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_em_advect_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = "pkpm_em_advect_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct em_advect_ctx ctx = { @@ -162,14 +165,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_ctx *app = ctx; double vx = xn[1]; @@ -177,26 +179,30 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double pi = app->pi; double vt = app->vt; - double F0 = (1.0 / sqrt(2.0 * pi * vt * vt)) * (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). + double F0 = (1.0 / sqrt(2.0 * pi * vt * vt)) * + (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). double G = (vt * vt) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -205,17 +211,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct em_advect_ctx *app = ctx; @@ -231,13 +242,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_ctx *app = ctx; @@ -247,8 +261,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -263,33 +276,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -297,12 +315,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -314,9 +337,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -324,12 +350,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -354,18 +382,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -373,39 +400,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -428,64 +441,59 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, - .is_static = true, + .is_static = true, .init = evalFieldInit, .ctx = &ctx, .ext_em = evalExternalFieldInit, .ext_em_ctx = &ctx, - .ext_em_evolve = true, + .ext_em_evolve = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -499,10 +507,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -511,53 +523,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -565,22 +582,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -591,11 +605,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -604,8 +620,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -618,12 +633,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -631,9 +651,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -645,11 +666,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -659,8 +682,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -675,7 +700,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -689,18 +714,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -708,25 +738,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -738,7 +775,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -746,8 +786,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -762,18 +804,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_em_advect_resonant_p1.c b/pkpm/creg/rt_pkpm_em_advect_resonant_p1.c index 19b1ec876e..c8a2860d33 100644 --- a/pkpm/creg/rt_pkpm_em_advect_resonant_p1.c +++ b/pkpm/creg/rt_pkpm_em_advect_resonant_p1.c @@ -1,7 +1,7 @@ // Advection in specified electromagnetic fields for the PKPM system of equations. // Input parameters match the initial conditions found in entry JE32 of Ammar's Simulation Journal (https://ammar-hakim.org/sj/je/je32/je32-vlasov-test-ptcl.html) -// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. -// Solution is given by the resonant case, omega = Omega_c where Omega_c = q B/m is the cyclotron frequency. +// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. +// Solution is given by the resonant case, omega = Omega_c where Omega_c = q B/m is the cyclotron frequency. #include #include @@ -26,8 +26,7 @@ #include #include -struct em_advect_resonant_ctx -{ +struct em_advect_resonant_ctx { // Mathematical constants (dimensionless). double pi; @@ -63,20 +62,19 @@ struct em_advect_resonant_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct em_advect_resonant_ctx -create_ctx(void) +struct em_advect_resonant_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -104,7 +102,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -113,17 +112,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_em_advect_resonant_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_em_advect_resonant_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_em_advect_resonant_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_em_advect_resonant_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct em_advect_resonant_ctx ctx = { @@ -162,14 +166,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_resonant_ctx *app = ctx; double vx = xn[1]; @@ -177,26 +180,30 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double pi = app->pi; double vt = app->vt; - double F0 = (1.0 / sqrt(2.0 * pi * vt * vt)) * (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). + double F0 = (1.0 / sqrt(2.0 * pi * vt * vt)) * + (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). double G = (vt * vt) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -205,17 +212,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct em_advect_resonant_ctx *app = ctx; @@ -231,13 +243,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_resonant_ctx *app = ctx; @@ -247,8 +262,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -263,33 +277,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -297,12 +316,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -314,9 +338,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -324,12 +351,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -354,18 +383,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -373,39 +401,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -428,64 +442,59 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, - .is_static = true, + .is_static = true, .init = evalFieldInit, .ctx = &ctx, .ext_em = evalExternalFieldInit, .ext_em_ctx = &ctx, - .ext_em_evolve = true, + .ext_em_evolve = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -499,10 +508,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -511,53 +524,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -565,22 +583,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -591,11 +606,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -604,8 +621,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -618,12 +634,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -631,9 +652,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -645,11 +667,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -659,8 +683,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -675,7 +701,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -689,18 +715,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -708,25 +739,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -738,7 +776,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -746,8 +787,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -762,18 +805,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_es_pot_well_1x_p1.c b/pkpm/creg/rt_pkpm_es_pot_well_1x_p1.c index c755ef91cb..97784bd618 100644 --- a/pkpm/creg/rt_pkpm_es_pot_well_1x_p1.c +++ b/pkpm/creg/rt_pkpm_es_pot_well_1x_p1.c @@ -21,8 +21,7 @@ #include #include -struct es_pot_well_ctx -{ +struct es_pot_well_ctx { // Mathematical constants (dimensionless). double pi; @@ -58,20 +57,19 @@ struct es_pot_well_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct es_pot_well_ctx -create_ctx(void) +struct es_pot_well_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -99,7 +97,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -108,17 +107,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_es_pot_well_1x_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_es_pot_well_1x_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_es_pot_well_1x_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_es_pot_well_1x_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct es_pot_well_ctx ctx = { @@ -156,14 +160,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_pot_well_ctx *app = ctx; double vx = xn[1]; @@ -171,26 +174,30 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double pi = app->pi; double vt = app->vt; - double F0 = (1.0 / sqrt(2.0 * pi * vt * vt)) * (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). + double F0 = (1.0 / sqrt(2.0 * pi * vt * vt)) * + (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). double G = (vt * vt) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_pot_well_ctx *app = ctx; double x = xn[0]; @@ -204,17 +211,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_pot_well_ctx *app = ctx; @@ -224,8 +234,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -240,33 +249,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -274,12 +288,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -291,9 +310,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -301,12 +323,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -331,18 +355,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -350,39 +373,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -405,62 +414,57 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -474,10 +478,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -486,53 +494,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -540,22 +553,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -566,11 +576,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -579,8 +591,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -593,12 +604,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -606,9 +622,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -620,11 +637,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -634,8 +653,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -650,7 +671,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -664,18 +685,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -683,25 +709,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -713,7 +746,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -721,8 +757,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -737,18 +775,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_es_pot_well_1x_p2.c b/pkpm/creg/rt_pkpm_es_pot_well_1x_p2.c index 8acde7c32a..6fc9995fce 100644 --- a/pkpm/creg/rt_pkpm_es_pot_well_1x_p2.c +++ b/pkpm/creg/rt_pkpm_es_pot_well_1x_p2.c @@ -21,8 +21,7 @@ #include #include -struct es_pot_well_ctx -{ +struct es_pot_well_ctx { // Mathematical constants (dimensionless). double pi; @@ -58,20 +57,19 @@ struct es_pot_well_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct es_pot_well_ctx -create_ctx(void) +struct es_pot_well_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -99,7 +97,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -108,17 +107,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_es_pot_well_1x_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_es_pot_well_1x_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_es_pot_well_1x_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_es_pot_well_1x_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct es_pot_well_ctx ctx = { @@ -156,14 +160,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_pot_well_ctx *app = ctx; double vx = xn[1]; @@ -171,26 +174,30 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double pi = app->pi; double vt = app->vt; - double F0 = (1.0 / sqrt(2.0 * pi * vt * vt)) * (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). + double F0 = (1.0 / sqrt(2.0 * pi * vt * vt)) * + (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). double G = (vt * vt) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_pot_well_ctx *app = ctx; double x = xn[0]; @@ -204,17 +211,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_pot_well_ctx *app = ctx; @@ -224,8 +234,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -240,33 +249,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -274,12 +288,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -291,9 +310,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -301,12 +323,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -331,18 +355,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -350,39 +373,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -405,62 +414,57 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -474,10 +478,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -486,53 +494,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -540,22 +553,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -566,11 +576,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -579,8 +591,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -593,12 +604,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -606,9 +622,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -620,11 +637,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -634,8 +653,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -650,7 +671,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -664,18 +685,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -683,25 +709,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -713,7 +746,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -721,8 +757,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -737,18 +775,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_es_shock_p2.c b/pkpm/creg/rt_pkpm_es_shock_p2.c index 21f27c82ee..493346c4ae 100644 --- a/pkpm/creg/rt_pkpm_es_shock_p2.c +++ b/pkpm/creg/rt_pkpm_es_shock_p2.c @@ -21,8 +21,7 @@ #include #include -struct es_shock_ctx -{ +struct es_shock_ctx { // Mathematical constants (dimensionless). double pi; @@ -71,20 +70,19 @@ struct es_shock_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct es_shock_ctx -create_ctx(void) +struct es_shock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -108,9 +106,10 @@ create_ctx(void) double cs = vte / sqrt(mass_ion); // Sound speed. double Vx_drift = 2.0 * cs; // Drift velocity (x-direction). - + double nu_elc = 1.0e-4; // Electron collision frequency. - double nu_ion = 1.0e-4 / sqrt(mass_ion) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. + double nu_ion = + 1.0e-4 / sqrt(mass_ion) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. // Simulation parameters. int Nx = 128; // Cell count (configuration space: x-direction). @@ -125,7 +124,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -134,17 +134,20 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_es_shock_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = "pkpm_es_shock_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_es_shock_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = "pkpm_es_shock_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct es_shock_ctx ctx = { @@ -191,14 +194,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; double vx = xn[1]; @@ -208,34 +210,39 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vte = app->vte; - double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). double G = (vte * vte) * F0; // Electron distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct es_shock_ctx *app = ctx; double x = xn[0]; double mass_elc = app->mass_elc; - + double n0 = app->n0; double Vx_drift = app->Vx_drift; - double mom_x = -n0 * mass_elc * Vx_drift * tanh(x); // Electron total momentum density (x-direction). + double mom_x = + -n0 * mass_elc * Vx_drift * tanh(x); // Electron total momentum density (x-direction). double mom_y = 0.0; // Electron total momentum density (y-direction). double mom_z = 0.0; // Electron total momentum density (z-direction). // Set electron total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; double vx = xn[1]; @@ -245,15 +252,18 @@ evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vti = app->vti; - double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). double G = (vti * vti) * F0; // Ion distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct es_shock_ctx *app = ctx; double x = xn[0]; @@ -268,11 +278,12 @@ evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = 0.0; // Ion total momentum density (z-direction). // Set ion total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -281,17 +292,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct es_shock_ctx *app = ctx; @@ -306,13 +322,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; @@ -322,8 +341,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; @@ -333,8 +351,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -349,33 +366,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -383,12 +405,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -400,9 +427,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -410,12 +440,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -440,18 +472,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -459,39 +490,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -514,50 +531,45 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalElcNu, .ctx = &ctx}, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; // Ions. struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .init_dist = evalIonDistInit, .ctx_dist = &ctx, .init_fluid = evalIonFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalIonNu, .ctx = &ctx}, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, @@ -567,16 +579,17 @@ main(int argc, char **argv) .ext_em = evalExternalFieldInit, .ext_em_ctx = &ctx, - .bcx = { GKYL_FIELD_COPY, GKYL_FIELD_COPY }, + .bcx = {GKYL_FIELD_COPY, GKYL_FIELD_COPY} }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, @@ -585,18 +598,14 @@ main(int argc, char **argv) .use_explicit_source = true, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -610,10 +619,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -622,53 +635,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -676,22 +694,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -702,11 +717,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -715,8 +732,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -729,12 +745,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -742,9 +763,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -756,11 +778,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -770,8 +794,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -786,7 +812,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -800,18 +826,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -819,25 +850,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -849,7 +887,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -857,8 +898,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -873,18 +916,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_es_shock_reflect_p2.c b/pkpm/creg/rt_pkpm_es_shock_reflect_p2.c index 7c34c40441..5d0512d42e 100644 --- a/pkpm/creg/rt_pkpm_es_shock_reflect_p2.c +++ b/pkpm/creg/rt_pkpm_es_shock_reflect_p2.c @@ -21,8 +21,7 @@ #include #include -struct es_shock_ctx -{ +struct es_shock_ctx { // Mathematical constants (dimensionless). double pi; @@ -71,20 +70,19 @@ struct es_shock_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct es_shock_ctx -create_ctx(void) +struct es_shock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -108,9 +106,10 @@ create_ctx(void) double cs = vte / sqrt(mass_ion); // Sound speed. double Vx_drift = 2.0 * cs; // Drift velocity (x-direction). - + double nu_elc = 1.0e-4; // Electron collision frequency. - double nu_ion = 1.0e-4 / sqrt(mass_ion) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. + double nu_ion = + 1.0e-4 / sqrt(mass_ion) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. // Simulation parameters. int Nx = 64; // Cell count (configuration space: x-direction). @@ -125,7 +124,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -134,17 +134,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_es_shock_reflect_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_es_shock_reflect_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_es_shock_reflect_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_es_shock_reflect_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct es_shock_ctx ctx = { @@ -191,14 +196,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; double vx = xn[1]; @@ -208,34 +212,39 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vte = app->vte; - double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). double G = (vte * vte) * F0; // Electron distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct es_shock_ctx *app = ctx; double x = xn[0]; double mass_elc = app->mass_elc; - + double n0 = app->n0; double Vx_drift = app->Vx_drift; - double mom_x = -n0 * mass_elc * Vx_drift * tanh(x); // Electron total momentum density (x-direction). + double mom_x = + -n0 * mass_elc * Vx_drift * tanh(x); // Electron total momentum density (x-direction). double mom_y = 0.0; // Electron total momentum density (y-direction). double mom_z = 0.0; // Electron total momentum density (z-direction). // Set electron total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; double vx = xn[1]; @@ -245,15 +254,18 @@ evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vti = app->vti; - double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). double G = (vti * vti) * F0; // Ion distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct es_shock_ctx *app = ctx; double x = xn[0]; @@ -268,11 +280,12 @@ evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = 0.0; // Ion total momentum density (z-direction). // Set ion total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -281,17 +294,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct es_shock_ctx *app = ctx; @@ -306,13 +324,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; @@ -322,8 +343,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; @@ -333,8 +353,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -349,33 +368,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -383,12 +407,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -400,9 +429,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -410,12 +442,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -440,18 +474,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -459,39 +492,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -514,50 +533,45 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalElcNu, .ctx = &ctx}, - .bcx = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_COPY} }; // Ions. struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .init_dist = evalIonDistInit, .ctx_dist = &ctx, .init_fluid = evalIonFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalIonNu, .ctx = &ctx}, - .bcx = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_COPY} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, @@ -567,16 +581,17 @@ main(int argc, char **argv) .ext_em = evalExternalFieldInit, .ext_em_ctx = &ctx, - .bcx = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_COPY }, + .bcx = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_COPY} }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0}, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, @@ -585,18 +600,14 @@ main(int argc, char **argv) .use_explicit_source = true, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -610,10 +621,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -622,53 +637,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -676,22 +696,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -702,11 +719,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -715,8 +734,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -729,12 +747,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -742,9 +765,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -756,11 +780,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -770,8 +796,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -786,7 +814,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -800,18 +828,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -819,25 +852,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -849,7 +889,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -857,8 +900,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -873,18 +918,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_landau_damping_p1.c b/pkpm/creg/rt_pkpm_landau_damping_p1.c index 007a8af44f..98bc823367 100644 --- a/pkpm/creg/rt_pkpm_landau_damping_p1.c +++ b/pkpm/creg/rt_pkpm_landau_damping_p1.c @@ -21,8 +21,7 @@ #include #include -struct landau_damping_ctx -{ +struct landau_damping_ctx { // Mathematical constants (dimensionless). double pi; @@ -61,20 +60,19 @@ struct landau_damping_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct landau_damping_ctx -create_ctx(void) +struct landau_damping_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -105,7 +103,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -114,17 +113,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_landau_damping_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_landau_damping_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_landau_damping_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_landau_damping_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct landau_damping_ctx ctx = { @@ -164,14 +168,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -182,27 +185,30 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double alpha = app->alpha; double k0 = app->k0; - double F0 = (1.0 + alpha * cos(k0 * x)) * - (1.0 / sqrt(2.0 * pi * vt * vt)) * (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). + double F0 = (1.0 + alpha * cos(k0 * x)) * (1.0 / sqrt(2.0 * pi * vt * vt)) * + (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). double G = (vt * vt) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; double x = xn[0]; @@ -217,17 +223,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct landau_damping_ctx *app = ctx; @@ -242,13 +253,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; @@ -258,8 +272,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -274,33 +287,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -308,12 +326,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -325,9 +348,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -335,12 +361,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -365,18 +393,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -384,39 +411,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -439,26 +452,24 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, @@ -466,36 +477,33 @@ main(int argc, char **argv) .ctx = &ctx, .ext_em = evalExternalFieldInit, - .ext_em_ctx = &ctx, + .ext_em_ctx = &ctx }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -509,10 +517,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -521,53 +533,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -575,22 +592,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -601,11 +615,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -614,8 +630,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -628,12 +643,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -641,9 +661,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -655,11 +676,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -669,8 +692,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -685,7 +710,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -699,18 +724,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -718,25 +748,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -748,7 +785,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -756,8 +796,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -772,18 +814,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_landau_damping_p2.c b/pkpm/creg/rt_pkpm_landau_damping_p2.c index ccd514a17c..2300cbb869 100644 --- a/pkpm/creg/rt_pkpm_landau_damping_p2.c +++ b/pkpm/creg/rt_pkpm_landau_damping_p2.c @@ -21,8 +21,7 @@ #include #include -struct landau_damping_ctx -{ +struct landau_damping_ctx { // Mathematical constants (dimensionless). double pi; @@ -61,20 +60,19 @@ struct landau_damping_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct landau_damping_ctx -create_ctx(void) +struct landau_damping_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -105,7 +103,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -114,17 +113,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_landau_damping_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_landau_damping_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_landau_damping_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_landau_damping_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct landau_damping_ctx ctx = { @@ -164,14 +168,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -182,27 +185,30 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double alpha = app->alpha; double k0 = app->k0; - double F0 = (1.0 + alpha * cos(k0 * x)) * - (1.0 / sqrt(2.0 * pi * vt * vt)) * (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). + double F0 = (1.0 + alpha * cos(k0 * x)) * (1.0 / sqrt(2.0 * pi * vt * vt)) * + (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function (F0). double G = (vt * vt) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; double x = xn[0]; @@ -217,17 +223,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct landau_damping_ctx *app = ctx; @@ -242,13 +253,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; @@ -258,8 +272,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -274,33 +287,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -308,12 +326,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -325,9 +348,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -335,12 +361,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -365,18 +393,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -384,39 +411,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -439,26 +452,24 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, @@ -466,36 +477,33 @@ main(int argc, char **argv) .ctx = &ctx, .ext_em = evalExternalFieldInit, - .ext_em_ctx = &ctx, + .ext_em_ctx = &ctx }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -509,10 +517,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -521,53 +533,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -575,22 +592,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -601,11 +615,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -614,8 +630,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -628,12 +643,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -641,9 +661,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -655,11 +676,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -669,8 +692,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -685,7 +710,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -699,18 +724,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -718,25 +748,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -748,7 +785,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -756,8 +796,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -772,18 +814,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_mom_beach_p2.c b/pkpm/creg/rt_pkpm_mom_beach_p2.c index 439d439cbe..8e25cbf9e7 100644 --- a/pkpm/creg/rt_pkpm_mom_beach_p2.c +++ b/pkpm/creg/rt_pkpm_mom_beach_p2.c @@ -4,7 +4,7 @@ // Physics of Plasmas, Volume 14 (5): 056104. // https://pubs.aip.org/aip/pop/article/14/5/056104/929539/Finite-difference-time-domain-simulation-of-fusion // NOTE: This simulation is a magnetized variant of JE8 and the Smithe Physics of Plasmas paper -// There is an initial Bx that causes the driven Jy to rotate between Jy and Jz. +// There is an initial Bx that causes the driven Jy to rotate between Jy and Jz. #include #include @@ -27,8 +27,7 @@ #include -struct mom_beach_ctx -{ +struct mom_beach_ctx { // Mathematical constants (dimensionless). double pi; @@ -39,11 +38,11 @@ struct mom_beach_ctx double mass_elc; // Electron mass. double charge_elc; // Electron charge. double vt_elc; // Electron thermal velocity. - double nu_elc; // Electron-electron collision frequency. - double density_floor; // Electron density floor to avoid negative density in low-density region. + double nu_elc; // Electron-electron collision frequency. + double density_floor; // Electron density floor to avoid negative density in low-density region. double J0; // Reference current density (Amps / m^3). - + // Derived physical quantities (using non-normalized physical units). double light_speed; // Speed of light. @@ -65,8 +64,7 @@ struct mom_beach_ctx double omega_drive; // Drive current angular frequency. }; -struct mom_beach_ctx -create_ctx(void) +struct mom_beach_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -77,12 +75,13 @@ create_ctx(void) double mu0 = 12.56637061435917295385057353311801153679e-7; // Permeability of free space. double mass_elc = 9.10938215e-31; // Electron mass. double charge_elc = -1.602176487e-19; // Electron charge. - double T_elc = -charge_elc; // Electron temperature. - double vt_elc = sqrt(T_elc/mass_elc); // Electron thermal velocity. - double density_floor = 1.0e1; // Electron density floor to avoid negative density in low-density region. + double T_elc = -charge_elc; // Electron temperature. + double vt_elc = sqrt(T_elc / mass_elc); // Electron thermal velocity. + double density_floor = + 1.0e1; // Electron density floor to avoid negative density in low-density region. double J0 = 1.0e-12; // Reference current density (Amps / m^3). - + // Derived physical quantities (using non-normalized physical units). double light_speed = 1.0 / sqrt(mu0 * epsilon0); // Speed of light. @@ -98,17 +97,20 @@ create_ctx(void) int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double deltaT = Lx100 / light_speed; // Arbitrary constant, with units of time. - double factor = deltaT * deltaT * charge_elc * charge_elc / (mass_elc * epsilon0); // Numerical factor for calculation of electron number density. + double factor = + deltaT * deltaT * charge_elc * charge_elc / + (mass_elc * epsilon0); // Numerical factor for calculation of electron number density. double omega_drive = pi / 10.0 / deltaT; // Drive current angular frequency. // initial dt guess so first step does not generate NaN - double init_dt = ((Lx/Nx)/light_speed)/(5.0); + double init_dt = ((Lx / Nx) / light_speed) / (5.0); // Coulomb logarithms. - double n0 = 1.0/factor; // reference density + double n0 = 1.0 / factor; // reference density double log_lambda_elc = 6.6 - 0.5 * log(n0 / 1.0e20) + 1.5 * log(T_elc / (-charge_elc)); // Collision frequencies. - double nu_elc = log_lambda_elc * pow(charge_elc,4) * n0 / - (6.0 * sqrt(2.0) * pow(pi,3.0/2.0) * pow(epsilon0,2) * sqrt(mass_elc) * pow(T_elc,3.0/2.0)); + double nu_elc = log_lambda_elc * pow(charge_elc, 4) * n0 / + (6.0 * sqrt(2.0) * pow(pi, 3.0 / 2.0) * pow(epsilon0, 2) * sqrt(mass_elc) * + pow(T_elc, 3.0 / 2.0)); struct mom_beach_ctx ctx = { .pi = pi, @@ -117,10 +119,10 @@ create_ctx(void) .mu0 = mu0, .mass_elc = mass_elc, .charge_elc = charge_elc, - .density_floor = density_floor, + .density_floor = density_floor, .J0 = J0, - .vt_elc = vt_elc, - .nu_elc = nu_elc, + .vt_elc = vt_elc, + .nu_elc = nu_elc, .light_speed = light_speed, .Nx = Nx, .Lx = Lx, @@ -134,21 +136,19 @@ create_ctx(void) .deltaT = deltaT, .factor = factor, .omega_drive = omega_drive, - .init_dt = init_dt, + .init_dt = init_dt }; return ctx; } -static inline double -maxwellian(double n, double v, double vth) +static inline double maxwellian(double n, double v, double vth) { - double v2 = v*v; - return n/sqrt(2*M_PI*vth*vth)*exp(-v2/(2*vth*vth)); + double v2 = v * v; + return n / sqrt(2 * M_PI * vth * vth) * exp(-v2 / (2 * vth * vth)); } -void -evalDistFuncElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], v = xn[1]; struct mom_beach_ctx *app = ctx; @@ -157,24 +157,26 @@ evalDistFuncElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT double epsilon0 = app->epsilon0; double mass_elc = app->mass_elc; double charge_elc = app->charge_elc; - double density_floor = app->density_floor; + double density_floor = app->density_floor; double light_speed = app->light_speed; double Lx100 = app->Lx100; - double factor = app ->factor; + double factor = app->factor; - double omegaPdt = 25.0 * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x); // Plasma frequency profile. - double ne = omegaPdt * omegaPdt / factor + density_floor; // Electron number density (with a floor for avoiding negative density). - double vt_elc = app->vt_elc; // Electron thermal velocity. + double omegaPdt = + 25.0 * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x); // Plasma frequency profile. + double ne = + omegaPdt * omegaPdt / factor + + density_floor; // Electron number density (with a floor for avoiding negative density). + double vt_elc = app->vt_elc; // Electron thermal velocity. fout[0] = maxwellian(ne, v, vt_elc); - fout[1] = vt_elc*vt_elc*maxwellian(ne, v, vt_elc); + fout[1] = vt_elc * vt_elc * maxwellian(ne, v, vt_elc); } -void -evalFluidElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFluidElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; // no initial flow @@ -183,30 +185,33 @@ evalFluidElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fo fout[2] = 0.0; } -void -evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electric field. - fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + fout[0] = 0.0, fout[1] = 0.0; + fout[2] = 0.0; // Set magnetic field. - fout[3] = 0.0, fout[4] = 0.0; fout[5] = 0.0; + fout[3] = 0.0, fout[4] = 0.0; + fout[5] = 0.0; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExtEmFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalExtEmFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct mom_beach_ctx *app = ctx; double x = xn[0]; double B_x = 1.0; - - fout[0] = 0.0; fout[1] = 0.0, fout[2] = 0.0; - fout[3] = B_x; fout[4] = 0.0; fout[5] = 0.0; + + fout[0] = 0.0; + fout[1] = 0.0, fout[2] = 0.0; + fout[3] = B_x; + fout[4] = 0.0; + fout[5] = 0.0; } -void -evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAppCurrent(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct mom_beach_ctx *app = ctx; @@ -231,15 +236,13 @@ evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f } } -void -evalNuElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalNuElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct mom_beach_ctx *app = ctx; fout[0] = app->nu_elc; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -247,12 +250,11 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool frame = iot->curr; } - gkyl_pkpm_app_write(app, t_curr, iot->curr-1); + gkyl_pkpm_app_write(app, t_curr, iot->curr - 1); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -275,28 +277,29 @@ main(int argc, char **argv) // electrons struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -6.0 * ctx.vt_elc}, - .upper = { 6.0 * ctx.vt_elc}, - .cells = { NV }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-6.0 * ctx.vt_elc}, + .upper = {6.0 * ctx.vt_elc}, + .cells = {NV}, .ctx_dist = &ctx, .ctx_fluid = &ctx, .init_dist = evalDistFuncElc, .init_fluid = evalFluidElc, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, - .ctx = &ctx, - .self_nu = evalNuElc, - }, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .ctx = &ctx, + .self_nu = evalNuElc}, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; // field struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, @@ -305,10 +308,10 @@ main(int argc, char **argv) .ext_em = evalExtEmFunc, .ext_em_ctx = &ctx, - .app_current = evalAppCurrent, - .app_current_ctx = &ctx, + .app_current = evalAppCurrent, + .app_current_ctx = &ctx, .app_current_evolve = true, - .bcx = { GKYL_FIELD_COPY, GKYL_FIELD_COPY }, + .bcx = {GKYL_FIELD_COPY, GKYL_FIELD_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -323,32 +326,18 @@ main(int argc, char **argv) #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -356,7 +345,7 @@ main(int argc, char **argv) int comm_size; gkyl_comm_get_size(comm, &comm_size); - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int ncuts = 1; for (int d = 0; d < cdim; d++) { @@ -373,26 +362,23 @@ main(int argc, char **argv) // PKPM app struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = 2, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // create app object @@ -406,11 +392,11 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // initialize simulation gkyl_pkpm_app_apply_ic(app, t_curr); - write_data(&io_trig, app, t_curr, false); + write_data(&io_trig, app, t_curr, false); // Initialize small time-step check. double dt_init = -1.0, dt_failure_tol = ctx.dt_failure_tol; @@ -421,7 +407,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -434,8 +420,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -443,11 +428,12 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -464,25 +450,39 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, "Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, "Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid Species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid Species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM Vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); - gkyl_pkpm_app_cout(app, stdout, "EM Variables (bvar) calculation took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "EM Variables (bvar) calculation took %g secs\n", stat.field_em_vars_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Species BCs took %g secs\n", stat.species_bc_tm); gkyl_pkpm_app_cout(app, stdout, "Fluid Species BCs took %g secs\n", stat.fluid_species_bc_tm); gkyl_pkpm_app_cout(app, stdout, "Field BCs took %g secs\n", stat.field_bc_tm); - + gkyl_pkpm_app_cout(app, stdout, "Updates took %g secs\n", stat.total_tm); - + gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld,\n", stat.n_io); gkyl_pkpm_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); @@ -491,12 +491,12 @@ main(int argc, char **argv) // simulation complete, free app gkyl_pkpm_app_release(app); - mpifinalize: - ; +mpifinalize:; #ifdef GKYL_HAVE_MPI - if (app_args.use_mpi) + if (app_args.use_mpi) { MPI_Finalize(); -#endif - + } +#endif + return 0; } diff --git a/pkpm/creg/rt_pkpm_neut_sodshock_p1.c b/pkpm/creg/rt_pkpm_neut_sodshock_p1.c index dd593bec95..0462dbd9d4 100644 --- a/pkpm/creg/rt_pkpm_neut_sodshock_p1.c +++ b/pkpm/creg/rt_pkpm_neut_sodshock_p1.c @@ -21,8 +21,7 @@ #include #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -64,20 +63,19 @@ struct sodshock_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -111,7 +109,8 @@ create_ctx(void) int num_frames = 10; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -120,17 +119,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_neut_sodshock_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_neut_sodshock_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = true; // Test neural network on simulation data? - const char* test_nn_file = "rt_pkpm_neut_sodshock_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "rt_pkpm_neut_sodshock_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 10; // Number of times to test neural network. struct sodshock_ctx ctx = { @@ -172,14 +176,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -196,36 +199,38 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double T = 0.0; if (x < 0.5) { - F0 = (nl / sqrt(2.0 * pi * Tl * Tl)) * (exp(-(vx * vx) / (2.0 * Tl * Tl))); // Distribution function (F0, left). + F0 = (nl / sqrt(2.0 * pi * Tl * Tl)) * + (exp(-(vx * vx) / (2.0 * Tl * Tl))); // Distribution function (F0, left). T = Tl; // Isotropic temperature (left). - } - else { - F0 = (nr / sqrt(2.0 * pi * Tr * Tr)) * (exp(-(vx * vx) / (2.0 * Tr * Tr))); // Distribution function (F0, right). + } else { + F0 = (nr / sqrt(2.0 * pi * Tr * Tr)) * + (exp(-(vx * vx) / (2.0 * Tr * Tr))); // Distribution function (F0, right). T = Tr; // Isotropic temperature (right). } double G = (T * T) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFluidInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; - + double B0 = app->B0; double Ex = 0.0; // Total electric field (x-direction). @@ -235,17 +240,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -255,8 +263,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -271,33 +278,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -305,12 +317,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -322,9 +339,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -332,12 +352,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -362,18 +384,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -381,39 +402,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -436,62 +443,57 @@ main(int argc, char **argv) // Neutral species. struct gkyl_pkpm_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalDistInit, .ctx_dist = &ctx, .init_fluid = evalFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 1, - .species = { neut }, + .species = {neut}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -505,10 +507,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -517,53 +523,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -571,22 +582,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -597,11 +605,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -610,8 +620,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -624,12 +633,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -637,9 +651,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -651,11 +666,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -665,8 +682,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -681,7 +700,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -695,18 +714,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -714,25 +738,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -744,7 +775,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -752,8 +786,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -768,18 +804,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_neut_sodshock_p2.c b/pkpm/creg/rt_pkpm_neut_sodshock_p2.c index 4fe32f3d20..322330eb9b 100644 --- a/pkpm/creg/rt_pkpm_neut_sodshock_p2.c +++ b/pkpm/creg/rt_pkpm_neut_sodshock_p2.c @@ -21,8 +21,7 @@ #include #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -64,20 +63,19 @@ struct sodshock_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -111,7 +109,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -120,17 +119,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_neut_sodshock_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_neut_sodshock_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_neut_sodshock_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_neut_sodshock_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct sodshock_ctx ctx = { @@ -172,14 +176,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -196,36 +199,38 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double T = 0.0; if (x < 0.5) { - F0 = (nl / sqrt(2.0 * pi * Tl * Tl)) * (exp(-(vx * vx) / (2.0 * Tl * Tl))); // Distribution function (F0, left). + F0 = (nl / sqrt(2.0 * pi * Tl * Tl)) * + (exp(-(vx * vx) / (2.0 * Tl * Tl))); // Distribution function (F0, left). T = Tl; // Isotropic temperature (left). - } - else { - F0 = (nr / sqrt(2.0 * pi * Tr * Tr)) * (exp(-(vx * vx) / (2.0 * Tr * Tr))); // Distribution function (F0, right). + } else { + F0 = (nr / sqrt(2.0 * pi * Tr * Tr)) * + (exp(-(vx * vx) / (2.0 * Tr * Tr))); // Distribution function (F0, right). T = Tr; // Isotropic temperature (right). } double G = (T * T) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFluidInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; - + double B0 = app->B0; double Ex = 0.0; // Total electric field (x-direction). @@ -235,17 +240,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -255,8 +263,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -271,33 +278,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -305,12 +317,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -322,9 +339,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -332,12 +352,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -362,18 +384,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -381,39 +402,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -436,62 +443,57 @@ main(int argc, char **argv) // Neutral species. struct gkyl_pkpm_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalDistInit, .ctx_dist = &ctx, .init_fluid = evalFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 1, - .species = { neut }, + .species = {neut}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -505,10 +507,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -517,53 +523,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -571,22 +582,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -597,11 +605,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -610,8 +620,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -624,12 +633,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -637,9 +651,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -651,11 +666,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -665,8 +682,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -681,7 +700,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -695,18 +714,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -714,25 +738,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -744,7 +775,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -752,8 +786,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -768,18 +804,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_ot_p1.c b/pkpm/creg/rt_pkpm_ot_p1.c index 917a15ad7e..e381751bcd 100644 --- a/pkpm/creg/rt_pkpm_ot_p1.c +++ b/pkpm/creg/rt_pkpm_ot_p1.c @@ -21,8 +21,7 @@ #include #include -struct ot_ctx -{ +struct ot_ctx { // Mathematical constants (dimensionless). double pi; @@ -78,20 +77,19 @@ struct ot_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct ot_ctx -create_ctx(void) +struct ot_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -139,7 +137,8 @@ create_ctx(void) int num_frames = 15; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -148,17 +147,21 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_ot_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = "pkpm_ot_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. - int num_nn_writes = 15; // Number of times to write out neural network (periodic checkpoints during the long run). + int num_nn_writes = + 15; // Number of times to write out neural network (periodic checkpoints during the long run). int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = true; // Test neural network on simulation data? - const char* test_nn_file = "rt_pkpm_ot_p1_moms_nn_15"; // File path of neural network to test. + const char *test_nn_file = "rt_pkpm_ot_p1_moms_nn_15"; // File path of neural network to test. int num_tests = 15; // Number of times to test neural network. struct ot_ctx ctx = { @@ -211,14 +214,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_ctx *app = ctx; double vx = xn[2]; @@ -228,15 +230,18 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vte = app->vte; - double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). double G = (vte * vte) * F0; // Electron distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct ot_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -252,7 +257,9 @@ evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double Lx = app->Lx; double Ly = app->Ly; - double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / mu0; + double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / + mu0; double vx_drift = -delta_u0 * sin(2.0 * pi * y / Ly); // Electron drift velocity (x-direction). double vy_drift = delta_u0 * sin(2.0 * pi * x / Lx); // Electron drift velocity (y-direction). @@ -263,11 +270,12 @@ evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = mass_elc * vz_drift; // Electron total momentum density (z-direction). // Set electron total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_ctx *app = ctx; double vx = xn[2]; @@ -277,15 +285,18 @@ evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vti = app->vti; - double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). double G = (vti * vti) * F0; // Ion distribution function (G). // Set ion distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct ot_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -307,11 +318,12 @@ evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double mom_z = mass_ion * vz_drift; // Ion total momentum density (z-direction). // Set ion total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -328,7 +340,9 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Lx = app->Lx; double Ly = app->Ly; - double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / mu0; + double Jz = (delta_B0 * (4.0 * pi / Lx) * cos(4.0 * pi * x / Lx) + + delta_B0 * (2.0 * pi / Ly) * cos(2.0 * pi * y / Ly)) / + mu0; double Bx = -delta_B0 * sin(2.0 * pi * y / Ly); // Total magnetic field (x-direction). double By = delta_B0 * sin(4.0 * pi * x / Lx); // Total magnetic field (y-direction). @@ -341,17 +355,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Ex = -((vy_drift * Bz) - (vz_drift * By)); // Total electric field (x-direction). double Ey = -((vz_drift * Bx) - (vx_drift * Bz)); // Total electric field (y-direction). double Ez = -((vx_drift * By) - (vy_drift * Bx)); // Total electric field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_ctx *app = ctx; @@ -361,8 +378,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct ot_ctx *app = ctx; @@ -372,8 +388,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -388,33 +403,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -422,12 +442,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -439,9 +464,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -449,12 +477,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -480,18 +510,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -499,39 +528,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -554,64 +569,60 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalElcNu, .ctx = &ctx}, - .diffusion = { .D = 1.0e-4, .order = 4 }, + .diffusion = {.D = 1.0e-4, .order = 4} }; // Ions. struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .init_dist = evalIonDistInit, .ctx_dist = &ctx, .init_fluid = evalIonFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalIonNu, .ctx = &ctx}, - .diffusion = { .D = 1.0e-4, .order = 4 }, + .diffusion = {.D = 1.0e-4, .order = 4} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 2, .vdim = 1, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 1, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, @@ -620,18 +631,15 @@ main(int argc, char **argv) .use_explicit_source = false, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -645,10 +653,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -657,53 +669,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -711,22 +728,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -737,11 +751,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -750,8 +766,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -764,12 +779,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -777,9 +797,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -791,11 +812,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -805,8 +828,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -821,7 +846,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -835,18 +860,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -854,25 +884,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -884,7 +921,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -892,8 +932,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -908,18 +950,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_periodic_es_shock_p1.c b/pkpm/creg/rt_pkpm_periodic_es_shock_p1.c index 95e045bb4b..6a32ce442f 100644 --- a/pkpm/creg/rt_pkpm_periodic_es_shock_p1.c +++ b/pkpm/creg/rt_pkpm_periodic_es_shock_p1.c @@ -21,8 +21,7 @@ #include #include -struct es_shock_ctx -{ +struct es_shock_ctx { // Mathematical constants (dimensionless). double pi; @@ -75,20 +74,19 @@ struct es_shock_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct es_shock_ctx -create_ctx(void) +struct es_shock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -118,7 +116,8 @@ create_ctx(void) double Ti_r = sqrt(0.1 / 0.125) * vti; // Right ion temperature. double nu_elc = 1.0e-4; // Electron collision frequency. - double nu_ion = 1.0e-4 / sqrt(mass_ion) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. + double nu_ion = + 1.0e-4 / sqrt(mass_ion) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. // Simulation parameters. int Nx = 256; // Cell count (configuration space: x-direction). @@ -133,7 +132,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -142,17 +142,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = true; // Test neural network on simulation data? - const char* test_nn_file = "rt_pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "rt_pkpm_periodic_es_shock_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct es_shock_ctx ctx = { @@ -202,14 +207,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -228,33 +232,37 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double T = 0.0; if (fabs(x) < 0.25 * Lx) { - F0 = (n0_l / sqrt(2.0 * pi * Te_l * Te_l)) * (exp(-(vx * vx) / (2.0 * Te_l * Te_l))); // Left electron distribution function (F0). + F0 = (n0_l / sqrt(2.0 * pi * Te_l * Te_l)) * + (exp(-(vx * vx) / (2.0 * Te_l * Te_l))); // Left electron distribution function (F0). T = Te_l; // Left electron temperature. - } - else { - F0 = (n0_r / sqrt(2.0 * pi * Te_r * Te_r)) * (exp(-(vx * vx) / (2.0 * Te_r * Te_r))); // Right electron distribution function (F0). + } else { + F0 = (n0_r / sqrt(2.0 * pi * Te_r * Te_r)) * + (exp(-(vx * vx) / (2.0 * Te_r * Te_r))); // Right electron distribution function (F0). T = Te_r; // Right electron temperature. } double G = (T * T) * F0; // Electron distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Electron total momentum density (x-direction). double mom_y = 0.0; // Electron total momentum density (y-direction). double mom_z = 0.0; // Electron total momentum density (z-direction). // Set electron total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -273,33 +281,37 @@ evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double T = 0.0; if (fabs(x) < 0.25 * Lx) { - F0 = (n0_l / sqrt(2.0 * pi * Ti_l * Ti_l)) * (exp(-(vx * vx) / (2.0 * Ti_l * Ti_l))); // Left ion distribution function (F0). + F0 = (n0_l / sqrt(2.0 * pi * Ti_l * Ti_l)) * + (exp(-(vx * vx) / (2.0 * Ti_l * Ti_l))); // Left ion distribution function (F0). T = Ti_l; // Left ion temperature. - } - else { - F0 = (n0_r / sqrt(2.0 * pi * Ti_r * Ti_r)) * (exp(-(vx * vx) / (2.0 * Ti_r * Ti_r))); // Right ion distribution function (F0). + } else { + F0 = (n0_r / sqrt(2.0 * pi * Ti_r * Ti_r)) * + (exp(-(vx * vx) / (2.0 * Ti_r * Ti_r))); // Right ion distribution function (F0). T = Ti_r; // Right ion temperature. } double G = (T * T) * F0; // Ion distribution function (G). // Set ion distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Ion total momentum density (x-direction). double mom_y = 0.0; // Ion total momentum density (y-direction). double mom_z = 0.0; // Ion total momentum density (z-direction). // Set ion total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -308,17 +320,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct es_shock_ctx *app = ctx; @@ -333,13 +350,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; @@ -349,8 +369,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; @@ -360,8 +379,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -376,33 +394,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -410,12 +433,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -427,9 +455,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -437,12 +468,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -467,18 +500,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -486,39 +518,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -541,46 +559,41 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalElcNu, .ctx = &ctx} }; // Ions. struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .init_dist = evalIonDistInit, .ctx_dist = &ctx, .init_fluid = evalIonFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalIonNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, @@ -588,36 +601,33 @@ main(int argc, char **argv) .ctx = &ctx, .ext_em = evalExternalFieldInit, - .ext_em_ctx = &ctx, + .ext_em_ctx = &ctx }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -631,10 +641,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -643,53 +657,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -697,22 +716,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -723,11 +739,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -736,8 +754,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -750,12 +767,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -763,9 +785,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -777,11 +800,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -791,8 +816,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -807,7 +834,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -821,18 +848,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -840,25 +872,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -870,7 +909,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -878,8 +920,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -894,18 +938,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_periodic_es_shock_p2.c b/pkpm/creg/rt_pkpm_periodic_es_shock_p2.c index 9c369c7dbd..3571a49233 100644 --- a/pkpm/creg/rt_pkpm_periodic_es_shock_p2.c +++ b/pkpm/creg/rt_pkpm_periodic_es_shock_p2.c @@ -21,8 +21,7 @@ #include #include -struct es_shock_ctx -{ +struct es_shock_ctx { // Mathematical constants (dimensionless). double pi; @@ -75,20 +74,19 @@ struct es_shock_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct es_shock_ctx -create_ctx(void) +struct es_shock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -118,7 +116,8 @@ create_ctx(void) double Ti_r = sqrt(0.1 / 0.125) * vti; // Right ion temperature. double nu_elc = 1.0e-4; // Electron collision frequency. - double nu_ion = 1.0e-4 / sqrt(mass_ion) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. + double nu_ion = + 1.0e-4 / sqrt(mass_ion) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. // Simulation parameters. int Nx = 256; // Cell count (configuration space: x-direction). @@ -133,7 +132,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -142,17 +142,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_periodic_es_shock_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_periodic_es_shock_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_periodic_es_shock_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_periodic_es_shock_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct es_shock_ctx ctx = { @@ -202,14 +207,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -228,33 +232,37 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double T = 0.0; if (fabs(x) < 0.25 * Lx) { - F0 = (n0_l / sqrt(2.0 * pi * Te_l * Te_l)) * (exp(-(vx * vx) / (2.0 * Te_l * Te_l))); // Left electron distribution function (F0). + F0 = (n0_l / sqrt(2.0 * pi * Te_l * Te_l)) * + (exp(-(vx * vx) / (2.0 * Te_l * Te_l))); // Left electron distribution function (F0). T = Te_l; // Left electron temperature. - } - else { - F0 = (n0_r / sqrt(2.0 * pi * Te_r * Te_r)) * (exp(-(vx * vx) / (2.0 * Te_r * Te_r))); // Right electron distribution function (F0). + } else { + F0 = (n0_r / sqrt(2.0 * pi * Te_r * Te_r)) * + (exp(-(vx * vx) / (2.0 * Te_r * Te_r))); // Right electron distribution function (F0). T = Te_r; // Right electron temperature. } double G = (T * T) * F0; // Electron distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Electron total momentum density (x-direction). double mom_y = 0.0; // Electron total momentum density (y-direction). double mom_z = 0.0; // Electron total momentum density (z-direction). // Set electron total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -273,33 +281,37 @@ evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double T = 0.0; if (fabs(x) < 0.25 * Lx) { - F0 = (n0_l / sqrt(2.0 * pi * Ti_l * Ti_l)) * (exp(-(vx * vx) / (2.0 * Ti_l * Ti_l))); // Left ion distribution function (F0). + F0 = (n0_l / sqrt(2.0 * pi * Ti_l * Ti_l)) * + (exp(-(vx * vx) / (2.0 * Ti_l * Ti_l))); // Left ion distribution function (F0). T = Ti_l; // Left ion temperature. - } - else { - F0 = (n0_r / sqrt(2.0 * pi * Ti_r * Ti_r)) * (exp(-(vx * vx) / (2.0 * Ti_r * Ti_r))); // Right ion distribution function (F0). + } else { + F0 = (n0_r / sqrt(2.0 * pi * Ti_r * Ti_r)) * + (exp(-(vx * vx) / (2.0 * Ti_r * Ti_r))); // Right ion distribution function (F0). T = Ti_r; // Right ion temperature. } double G = (T * T) * F0; // Ion distribution function (G). // Set ion distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Ion total momentum density (x-direction). double mom_y = 0.0; // Ion total momentum density (y-direction). double mom_z = 0.0; // Ion total momentum density (z-direction). // Set ion total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -308,17 +320,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct es_shock_ctx *app = ctx; @@ -333,13 +350,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; @@ -349,8 +369,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; @@ -360,8 +379,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -376,33 +394,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -410,12 +433,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -427,9 +455,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -437,12 +468,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -467,18 +500,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -486,39 +518,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -541,46 +559,41 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalElcNu, .ctx = &ctx} }; // Ions. struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .init_dist = evalIonDistInit, .ctx_dist = &ctx, .init_fluid = evalIonFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalIonNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, @@ -588,36 +601,33 @@ main(int argc, char **argv) .ctx = &ctx, .ext_em = evalExternalFieldInit, - .ext_em_ctx = &ctx, + .ext_em_ctx = &ctx }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -631,10 +641,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -643,53 +657,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -697,22 +716,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -723,11 +739,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -736,8 +754,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -750,12 +767,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -763,9 +785,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -777,11 +800,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -791,8 +816,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -807,7 +834,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -821,18 +848,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -840,25 +872,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -870,7 +909,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -878,8 +920,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -894,18 +938,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_periodic_neut_sodshock_p1.c b/pkpm/creg/rt_pkpm_periodic_neut_sodshock_p1.c index f045c21cef..30a0d6b55f 100644 --- a/pkpm/creg/rt_pkpm_periodic_neut_sodshock_p1.c +++ b/pkpm/creg/rt_pkpm_periodic_neut_sodshock_p1.c @@ -21,8 +21,7 @@ #include #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -64,20 +63,19 @@ struct sodshock_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -111,7 +109,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -120,17 +119,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_periodic_neut_sodshock_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_periodic_neut_sodshock_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_periodic_neut_sodshock_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_periodic_neut_sodshock_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct sodshock_ctx ctx = { @@ -172,14 +176,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -196,36 +199,38 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double T = 0.0; if (fabs(x) < 0.5) { - F0 = (nl / sqrt(2.0 * pi * Tl * Tl)) * (exp(-(vx * vx) / (2.0 * Tl * Tl))); // Distribution function (F0, left). + F0 = (nl / sqrt(2.0 * pi * Tl * Tl)) * + (exp(-(vx * vx) / (2.0 * Tl * Tl))); // Distribution function (F0, left). T = Tl; // Isotropic temperature (left). - } - else { - F0 = (nr / sqrt(2.0 * pi * Tr * Tr)) * (exp(-(vx * vx) / (2.0 * Tr * Tr))); // Distribution function (F0, right). + } else { + F0 = (nr / sqrt(2.0 * pi * Tr * Tr)) * + (exp(-(vx * vx) / (2.0 * Tr * Tr))); // Distribution function (F0, right). T = Tr; // Isotropic temperature (right). } double G = (T * T) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFluidInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; - + double B0 = app->B0; double Ex = 0.0; // Total electric field (x-direction). @@ -235,17 +240,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -255,8 +263,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -271,33 +278,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -305,12 +317,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -322,9 +339,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -332,12 +352,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -362,18 +384,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -381,39 +402,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -436,62 +443,57 @@ main(int argc, char **argv) // Neutral species. struct gkyl_pkpm_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalDistInit, .ctx_dist = &ctx, .init_fluid = evalFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { neut }, + .species = {neut}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -505,10 +507,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -517,53 +523,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -571,22 +582,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -597,11 +605,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -610,8 +620,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -624,12 +633,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -637,9 +651,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -651,11 +666,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -665,8 +682,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -681,7 +700,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -695,18 +714,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -714,25 +738,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -744,7 +775,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -752,8 +786,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -768,18 +804,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_periodic_neut_sodshock_p2.c b/pkpm/creg/rt_pkpm_periodic_neut_sodshock_p2.c index fd38d54f9c..636a4baa41 100644 --- a/pkpm/creg/rt_pkpm_periodic_neut_sodshock_p2.c +++ b/pkpm/creg/rt_pkpm_periodic_neut_sodshock_p2.c @@ -21,8 +21,7 @@ #include #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -64,20 +63,19 @@ struct sodshock_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -111,7 +109,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -120,17 +119,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_periodic_neut_sodshock_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_periodic_neut_sodshock_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_periodic_neut_sodshock_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_periodic_neut_sodshock_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct sodshock_ctx ctx = { @@ -172,14 +176,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -196,36 +199,38 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double T = 0.0; if (fabs(x) < 0.5) { - F0 = (nl / sqrt(2.0 * pi * Tl * Tl)) * (exp(-(vx * vx) / (2.0 * Tl * Tl))); // Distribution function (F0, left). + F0 = (nl / sqrt(2.0 * pi * Tl * Tl)) * + (exp(-(vx * vx) / (2.0 * Tl * Tl))); // Distribution function (F0, left). T = Tl; // Isotropic temperature (left). - } - else { - F0 = (nr / sqrt(2.0 * pi * Tr * Tr)) * (exp(-(vx * vx) / (2.0 * Tr * Tr))); // Distribution function (F0, right). + } else { + F0 = (nr / sqrt(2.0 * pi * Tr * Tr)) * + (exp(-(vx * vx) / (2.0 * Tr * Tr))); // Distribution function (F0, right). T = Tr; // Isotropic temperature (right). } double G = (T * T) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFluidInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double mom_x = 0.0; // Total momentum density (x-direction). double mom_y = 0.0; // Total momentum density (y-direction). double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; - + double B0 = app->B0; double Ex = 0.0; // Total electric field (x-direction). @@ -235,17 +240,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -255,8 +263,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -271,33 +278,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -305,12 +317,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -322,9 +339,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -332,12 +352,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -362,18 +384,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -381,39 +402,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -436,62 +443,57 @@ main(int argc, char **argv) // Neutral species. struct gkyl_pkpm_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalDistInit, .ctx_dist = &ctx, .init_fluid = evalFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { neut }, + .species = {neut}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -505,10 +507,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -517,53 +523,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -571,22 +582,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -597,11 +605,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -610,8 +620,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -624,12 +633,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -637,9 +651,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -651,11 +666,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -665,8 +682,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -681,7 +700,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -695,18 +714,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -714,25 +738,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -744,7 +775,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -752,8 +786,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -768,18 +804,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_sheath_p1.c b/pkpm/creg/rt_pkpm_sheath_p1.c index 8db6b1d6c6..475b70dca5 100644 --- a/pkpm/creg/rt_pkpm_sheath_p1.c +++ b/pkpm/creg/rt_pkpm_sheath_p1.c @@ -21,8 +21,7 @@ #include #include -struct sheath_ctx -{ +struct sheath_ctx { // Mathematical constants (dimensionless). double pi; @@ -68,20 +67,19 @@ struct sheath_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -104,7 +102,8 @@ create_ctx(void) double vti = vte / sqrt(Te_over_Ti * mass_ion); // Ion thermal velocity. double nu_elc = 1.0e-5; // Electron collision frequency. - double nu_ion = 1.0e-5 / sqrt(mass_ion) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. + double nu_ion = + 1.0e-5 / sqrt(mass_ion) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. // Simulation parameters. int Nx = 128; // Cell count (configuration space: x-direction). @@ -119,7 +118,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -128,17 +128,20 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_sheath_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = "pkpm_sheath_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_sheath_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = "pkpm_sheath_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct sheath_ctx ctx = { @@ -183,14 +186,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double vx = xn[1]; @@ -200,26 +202,30 @@ evalElcDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vte = app->vte; - double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron distribution function (F0). double G = (vte * vte) * F0; // Electron distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalElcFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Electron total momentum density (x-direction). double mom_y = 0.0; // Electron total momentum density (y-direction). double mom_z = 0.0; // Electron total momentum density (z-direction). // Set electron total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double vx = xn[1]; @@ -229,26 +235,30 @@ evalIonDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double n0 = app->n0; double vti = app->vti; - double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-(vx * vx) / (2.0 * vti * vti))); // Ion distribution function (F0). double G = (vti * vti) * F0; // Ion distribution function (G). // Set electron distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalIonFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonFluidInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double mom_x = 0.0; // Ion total momentum density (x-direction). double mom_y = 0.0; // Ion total momentum density (y-direction). double mom_z = 0.0; // Ion total momentum density (z-direction). // Set ion total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -257,17 +267,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -282,13 +297,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -298,8 +316,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -309,8 +326,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -325,33 +341,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -359,12 +380,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -376,9 +402,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -386,12 +415,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -416,18 +447,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -435,39 +465,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -490,50 +506,45 @@ main(int argc, char **argv) // Electrons. struct gkyl_pkpm_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .init_dist = evalElcDistInit, .ctx_dist = &ctx, .init_fluid = evalElcFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalElcNu, .ctx = &ctx}, - .bcx = { GKYL_SPECIES_ABSORB, GKYL_SPECIES_ABSORB }, + .bcx = {GKYL_SPECIES_ABSORB, GKYL_SPECIES_ABSORB} }; // Ions. struct gkyl_pkpm_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .init_dist = evalIonDistInit, .ctx_dist = &ctx, .init_fluid = evalIonFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalIonNu, .ctx = &ctx}, - .bcx = { GKYL_SPECIES_ABSORB, GKYL_SPECIES_ABSORB }, + .bcx = {GKYL_SPECIES_ABSORB, GKYL_SPECIES_ABSORB} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, @@ -543,34 +554,31 @@ main(int argc, char **argv) .ext_em = evalExternalFieldInit, .ext_em_ctx = &ctx, - .bcx = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + .bcx = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -584,10 +592,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -596,53 +608,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -650,22 +667,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -676,11 +690,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -689,8 +705,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -703,12 +718,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -716,9 +736,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -730,22 +751,26 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } - + struct gkyl_kn_vec *input_data_real = gkyl_kn_vec_new(cell_count, nn_input_dim); struct gkyl_kn_vec *output_data_real = gkyl_kn_vec_new(cell_count, nn_output_dim); struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -760,7 +785,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -774,18 +799,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -793,25 +823,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -823,7 +860,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -831,8 +871,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -847,18 +889,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_square_relax_1x_p1.c b/pkpm/creg/rt_pkpm_square_relax_1x_p1.c index af70a16ce6..308f2ac4cd 100644 --- a/pkpm/creg/rt_pkpm_square_relax_1x_p1.c +++ b/pkpm/creg/rt_pkpm_square_relax_1x_p1.c @@ -21,8 +21,7 @@ #include #include -struct square_relax_ctx -{ +struct square_relax_ctx { // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -59,20 +58,19 @@ struct square_relax_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct square_relax_ctx -create_ctx(void) +struct square_relax_ctx create_ctx(void) { // Physical constants (using normalized code units). double epsilon0 = 1.0; // Permittivity of free space. @@ -101,7 +99,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -110,17 +109,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_square_relax_1x_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_square_relax_1x_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_square_relax_1x_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_square_relax_1x_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct square_relax_ctx ctx = { @@ -160,14 +164,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct square_relax_ctx *app = ctx; double vx = xn[1]; @@ -181,8 +184,7 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (fabs(vx) < 1.0) { F0 = 0.5 * n0; // Distribution function (F0, low velocity). T = 0.5 * T0; // Isotropic temperature (low velocity). - } - else { + } else { F0 = 0.0; // Distribution function (F0, high velocity). T = 0.0; // Isotropic temperature (high velocity). } @@ -190,14 +192,14 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double G = (T0 * T0) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFluidInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct square_relax_ctx *app = ctx; - + double mom_x0 = app->mom_x0; double mom_x = mom_x0; // Total momentum density (x-direction). @@ -205,14 +207,15 @@ evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct square_relax_ctx *app = ctx; - + double B0 = app->B0; double Ex = 0.0; // Total electric field (x-direction). @@ -222,17 +225,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct square_relax_ctx *app = ctx; @@ -242,8 +248,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -258,33 +263,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -292,12 +302,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -309,9 +324,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -319,12 +337,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -349,18 +369,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -368,39 +387,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -423,62 +428,57 @@ main(int argc, char **argv) // Neutral species. struct gkyl_pkpm_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalDistInit, .ctx_dist = &ctx, .init_fluid = evalFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { neut }, + .species = {neut}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -492,10 +492,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -504,53 +508,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -558,22 +567,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -584,11 +590,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -597,8 +605,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -611,12 +618,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -624,9 +636,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -638,11 +651,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -652,8 +667,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -668,7 +685,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -682,18 +699,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -701,25 +723,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -731,7 +760,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -739,8 +771,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -755,18 +789,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_square_relax_1x_p2.c b/pkpm/creg/rt_pkpm_square_relax_1x_p2.c index 67f20bf43c..fa04ccd00c 100644 --- a/pkpm/creg/rt_pkpm_square_relax_1x_p2.c +++ b/pkpm/creg/rt_pkpm_square_relax_1x_p2.c @@ -21,8 +21,7 @@ #include #include -struct square_relax_ctx -{ +struct square_relax_ctx { // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mu0; // Permeability of free space. @@ -59,20 +58,19 @@ struct square_relax_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct square_relax_ctx -create_ctx(void) +struct square_relax_ctx create_ctx(void) { // Physical constants (using normalized code units). double epsilon0 = 1.0; // Permittivity of free space. @@ -101,7 +99,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -110,17 +109,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_square_relax_1x_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_square_relax_1x_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_square_relax_1x_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_square_relax_1x_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct square_relax_ctx ctx = { @@ -160,14 +164,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct square_relax_ctx *app = ctx; double vx = xn[1]; @@ -181,8 +184,7 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (fabs(vx) < 1.0) { F0 = 0.5 * n0; // Distribution function (F0, low velocity). T = 0.5 * T0; // Isotropic temperature (low velocity). - } - else { + } else { F0 = 0.0; // Distribution function (F0, high velocity). T = 0.0; // Isotropic temperature (high velocity). } @@ -190,14 +192,14 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double G = (T0 * T0) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFluidInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct square_relax_ctx *app = ctx; - + double mom_x0 = app->mom_x0; double mom_x = mom_x0; // Total momentum density (x-direction). @@ -205,14 +207,15 @@ evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct square_relax_ctx *app = ctx; - + double B0 = app->B0; double Ex = 0.0; // Total electric field (x-direction). @@ -222,17 +225,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct square_relax_ctx *app = ctx; @@ -242,8 +248,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -258,33 +263,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -292,12 +302,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -309,9 +324,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -319,12 +337,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -349,18 +369,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -368,39 +387,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -423,62 +428,57 @@ main(int argc, char **argv) // Neutral species. struct gkyl_pkpm_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalDistInit, .ctx_dist = &ctx, .init_fluid = evalFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { neut }, + .species = {neut}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -492,10 +492,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -504,53 +508,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -558,22 +567,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -584,11 +590,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -597,8 +605,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -611,12 +618,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -624,9 +636,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -638,11 +651,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -652,8 +667,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -668,7 +685,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -682,18 +699,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -701,25 +723,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -731,7 +760,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -739,8 +771,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -755,18 +789,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_travel_pulse_p1.c b/pkpm/creg/rt_pkpm_travel_pulse_p1.c index 64ea10917f..bc0b57bf84 100644 --- a/pkpm/creg/rt_pkpm_travel_pulse_p1.c +++ b/pkpm/creg/rt_pkpm_travel_pulse_p1.c @@ -21,8 +21,7 @@ #include #include -struct travel_pulse_ctx -{ +struct travel_pulse_ctx { // Mathematical constants (dimensionless). double pi; @@ -63,20 +62,19 @@ struct travel_pulse_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct travel_pulse_ctx -create_ctx(void) +struct travel_pulse_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -109,7 +107,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -118,17 +117,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_travel_pulse_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_travel_pulse_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_travel_pulse_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_travel_pulse_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct travel_pulse_ctx ctx = { @@ -170,14 +174,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -191,15 +194,16 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double n_perturb = n0 + (alpha * sin(pi * x)); double T0 = sqrt(pr0 / n_perturb); - double F0 = (n_perturb / sqrt(2.0 * pi * T0 * T0)) * (exp(-(vx * vx) / (2.0 * T0 * T0))); // Distribution function (F0). + double F0 = (n_perturb / sqrt(2.0 * pi * T0 * T0)) * + (exp(-(vx * vx) / (2.0 * T0 * T0))); // Distribution function (F0). double G = (T0 * T0) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFluidInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; double x = xn[0]; @@ -217,14 +221,15 @@ evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; - + double B0 = app->B0; double Ex = 0.0; // Total electric field (x-direction). @@ -234,17 +239,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; @@ -254,8 +262,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -270,33 +277,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -304,12 +316,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -321,9 +338,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -331,12 +351,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -361,18 +383,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -380,39 +401,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -435,62 +442,57 @@ main(int argc, char **argv) // Neutral species. struct gkyl_pkpm_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalDistInit, .ctx_dist = &ctx, .init_fluid = evalFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { neut }, + .species = {neut}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -504,10 +506,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -516,53 +522,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -570,22 +581,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -596,11 +604,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -609,8 +619,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -623,12 +632,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -636,9 +650,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -650,11 +665,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -664,8 +681,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -680,7 +699,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -694,18 +713,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -713,25 +737,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -743,7 +774,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -751,8 +785,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -767,18 +803,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_travel_pulse_p2.c b/pkpm/creg/rt_pkpm_travel_pulse_p2.c index d5acce5729..ce9ca34404 100644 --- a/pkpm/creg/rt_pkpm_travel_pulse_p2.c +++ b/pkpm/creg/rt_pkpm_travel_pulse_p2.c @@ -21,8 +21,7 @@ #include #include -struct travel_pulse_ctx -{ +struct travel_pulse_ctx { // Mathematical constants (dimensionless). double pi; @@ -63,20 +62,19 @@ struct travel_pulse_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct travel_pulse_ctx -create_ctx(void) +struct travel_pulse_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -109,7 +107,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -118,17 +117,22 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_travel_pulse_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = + "pkpm_travel_pulse_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_travel_pulse_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = + "pkpm_travel_pulse_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct travel_pulse_ctx ctx = { @@ -170,14 +174,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -191,15 +194,16 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double n_perturb = n0 + (alpha * sin(pi * x)); double T0 = sqrt(pr0 / n_perturb); - double F0 = (n_perturb / sqrt(2.0 * pi * T0 * T0)) * (exp(-(vx * vx) / (2.0 * T0 * T0))); // Distribution function (F0). + double F0 = (n_perturb / sqrt(2.0 * pi * T0 * T0)) * + (exp(-(vx * vx) / (2.0 * T0 * T0))); // Distribution function (F0). double G = (T0 * T0) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFluidInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; double x = xn[0]; @@ -217,14 +221,15 @@ evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; - + double B0 = app->B0; double Ex = 0.0; // Total electric field (x-direction). @@ -234,17 +239,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct travel_pulse_ctx *app = ctx; @@ -254,8 +262,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -270,33 +277,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -304,12 +316,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -321,9 +338,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -331,12 +351,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -361,18 +383,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -380,39 +401,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -435,62 +442,57 @@ main(int argc, char **argv) // Neutral species. struct gkyl_pkpm_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalDistInit, .ctx_dist = &ctx, .init_fluid = evalFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { neut }, + .species = {neut}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -504,10 +506,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -516,53 +522,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -570,22 +581,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -596,11 +604,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -609,8 +619,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -623,12 +632,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -636,9 +650,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -650,11 +665,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -664,8 +681,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -680,7 +699,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -694,18 +713,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -713,25 +737,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -743,7 +774,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -751,8 +785,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -767,18 +803,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_wall_p1.c b/pkpm/creg/rt_pkpm_wall_p1.c index 979c21e7cb..bca3383764 100644 --- a/pkpm/creg/rt_pkpm_wall_p1.c +++ b/pkpm/creg/rt_pkpm_wall_p1.c @@ -21,8 +21,7 @@ #include #include -struct wall_ctx -{ +struct wall_ctx { // Mathematical constants (dimensionless). double pi; @@ -62,20 +61,19 @@ struct wall_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct wall_ctx -create_ctx(void) +struct wall_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -107,7 +105,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -116,17 +115,20 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_wall_p1_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = "pkpm_wall_p1_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_wall_p1_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = "pkpm_wall_p1_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct wall_ctx ctx = { @@ -167,14 +169,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct wall_ctx *app = ctx; double vx = xn[1]; @@ -184,17 +185,18 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double n0 = app->n0; double T0 = app->T0; - double F0 = (n0 / sqrt(2.0 * pi * T0 * T0)) * (exp(-(vx * vx) / (2.0 * T0 * T0))); // Distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * T0 * T0)) * + (exp(-(vx * vx) / (2.0 * T0 * T0))); // Distribution function (F0). double T = T0; // Isotropic temperature. double G = (T * T) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFluidInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct wall_ctx *app = ctx; @@ -206,14 +208,15 @@ evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct wall_ctx *app = ctx; - + double B0 = app->B0; double Ex = 0.0; // Total electric field (x-direction). @@ -223,17 +226,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct wall_ctx *app = ctx; @@ -243,8 +249,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -259,33 +264,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -293,12 +303,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -310,9 +325,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -320,12 +338,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -350,18 +370,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -369,39 +388,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -424,64 +429,59 @@ main(int argc, char **argv) // Neutral species. struct gkyl_pkpm_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalDistInit, .ctx_dist = &ctx, .init_fluid = evalFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, - .bcx = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcx = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 1, - .species = { neut }, + .species = {neut}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -495,10 +495,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -507,53 +511,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -561,22 +570,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -587,11 +593,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -600,8 +608,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -614,12 +621,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -627,9 +639,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -641,11 +654,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -655,8 +670,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -671,7 +688,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -685,18 +702,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -704,25 +726,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -734,7 +763,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -742,8 +774,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -758,18 +792,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/creg/rt_pkpm_wall_p2.c b/pkpm/creg/rt_pkpm_wall_p2.c index 26c433b154..71b14dbc6d 100644 --- a/pkpm/creg/rt_pkpm_wall_p2.c +++ b/pkpm/creg/rt_pkpm_wall_p2.c @@ -21,8 +21,7 @@ #include #include -struct wall_ctx -{ +struct wall_ctx { // Mathematical constants (dimensionless). double pi; @@ -62,20 +61,19 @@ struct wall_ctx bool train_ab_initio; // Train neural network ab initio? int nn_width; // Number of neurons to use per layer. int nn_depth; // Number of layers to use. - const char* train_nn_file; // File path of neural network to train. + const char *train_nn_file; // File path of neural network to train. int num_trains; // Number of times to train neural network. int num_nn_writes; // Number of times to write out neural network. int num_input_moms; // Number of "input" moments to train on. - int* input_moms; // Array of "input" moments to train on. + int *input_moms; // Array of "input" moments to train on. int num_output_moms; // Number of "output" moments to train on. - int* output_moms; // Array of "output" moments to train on. + int *output_moms; // Array of "output" moments to train on. bool test_nn; // Test neural network on simulation data? - const char* test_nn_file; // File path of neural network to test. + const char *test_nn_file; // File path of neural network to test. int num_tests; // Number of times to test neural network. }; -struct wall_ctx -create_ctx(void) +struct wall_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -107,7 +105,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -116,17 +115,20 @@ create_ctx(void) bool train_ab_initio = true; // Train neural network ab initio? int nn_width = 256; // Number of neurons to use per layer. int nn_depth = 5; // Number of layers to use. - const char* train_nn_file = "pkpm_wall_p2_moms_nn_1"; // File path of neural network to train. + const char *train_nn_file = "pkpm_wall_p2_moms_nn_1"; // File path of neural network to train. int num_trains = INT_MAX; // Number of times to train neural network. int num_nn_writes = 1; // Number of times to write out neural network. int num_input_moms = 3; // Number of "input" moments to train on. - int* input_moms = gkyl_malloc(sizeof(int[3])); - input_moms[0] = 0; input_moms[1] = 2; input_moms[2] = 3; // Array of "input" moments to train on. + int *input_moms = gkyl_malloc(sizeof(int[3])); + input_moms[0] = 0; + input_moms[1] = 2; + input_moms[2] = 3; // Array of "input" moments to train on. int num_output_moms = 2; // Number of "output" moments to train on. - int* output_moms = gkyl_malloc(sizeof(int[2])); - output_moms[0] = 4; output_moms[1] = 5; // Array of "output" moments to train on. + int *output_moms = gkyl_malloc(sizeof(int[2])); + output_moms[0] = 4; + output_moms[1] = 5; // Array of "output" moments to train on. bool test_nn = false; // Test neural network on simulation data? - const char* test_nn_file = "pkpm_wall_p2_moms_nn_1"; // File path of neural network to test. + const char *test_nn_file = "pkpm_wall_p2_moms_nn_1"; // File path of neural network to test. int num_tests = 1; // Number of times to test neural network. struct wall_ctx ctx = { @@ -167,14 +169,13 @@ create_ctx(void) .output_moms = output_moms, .test_nn = test_nn, .test_nn_file = test_nn_file, - .num_tests = num_tests, + .num_tests = num_tests }; return ctx; } -void -evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDistInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct wall_ctx *app = ctx; double vx = xn[1]; @@ -184,17 +185,18 @@ evalDistInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double n0 = app->n0; double T0 = app->T0; - double F0 = (n0 / sqrt(2.0 * pi * T0 * T0)) * (exp(-(vx * vx) / (2.0 * T0 * T0))); // Distribution function (F0). + double F0 = (n0 / sqrt(2.0 * pi * T0 * T0)) * + (exp(-(vx * vx) / (2.0 * T0 * T0))); // Distribution function (F0). double T = T0; // Isotropic temperature. double G = (T * T) * F0; // Distribution function (G). // Set distribution function. - fout[0] = F0; fout[1] = G; + fout[0] = F0; + fout[1] = G; } -void -evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFluidInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct wall_ctx *app = ctx; @@ -206,14 +208,15 @@ evalFluidInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double mom_z = 0.0; // Total momentum density (z-direction). // Set total momentum density. - fout[0] = mom_x; fout[1] = mom_y; fout[2] = mom_z; + fout[0] = mom_x; + fout[1] = mom_y; + fout[2] = mom_z; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct wall_ctx *app = ctx; - + double B0 = app->B0; double Ex = 0.0; // Total electric field (x-direction). @@ -223,17 +226,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = B0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct wall_ctx *app = ctx; @@ -243,8 +249,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_pkpm_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -259,33 +264,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_pkpm_app* app, double t_curr, bool } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_pkpm_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_pkpm_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_pkpm_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_pkpm_app_calc_integrated_L2_f(app, t_curr); } } -void -train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool force_train, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data, struct gkyl_kn_vec* output_data) +void train_mom( + struct gkyl_tm_trigger *nn, gkyl_pkpm_app *app, double t_curr, bool force_train, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data, struct gkyl_kn_vec *output_data +) { if (gkyl_tm_trigger_check_and_bump(nn, t_curr) || force_train) { int frame = nn->curr - 1; @@ -293,12 +303,17 @@ train_mom(struct gkyl_tm_trigger* nn, gkyl_pkpm_app* app, double t_curr, bool fo frame = nn->curr; } - gkyl_pkpm_app_train(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, output_data); + gkyl_pkpm_app_train( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data, + output_data + ); } } -void -write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool force_write, struct gkyl_kann_net** ann) +void write_nn( + struct gkyl_tm_trigger *nnw, gkyl_pkpm_app *app, double t_curr, bool force_write, + struct gkyl_kann_net **ann +) { if (gkyl_tm_trigger_check_and_bump(nnw, t_curr) || force_write) { int frame = nnw->curr - 1; @@ -310,9 +325,12 @@ write_nn(struct gkyl_tm_trigger* nnw, gkyl_pkpm_app* app, double t_curr, bool fo } } -void -test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool force_test, struct gkyl_kann_net** ann, int num_input_moms, int* input_moms, int num_output_moms, int* output_moms, - struct gkyl_kn_vec* input_data_real, struct gkyl_kn_vec* output_data_real, struct gkyl_kn_vec* output_data_predicted) +void test_mom( + struct gkyl_tm_trigger *nnt, gkyl_pkpm_app *app, double t_curr, bool force_test, + struct gkyl_kann_net **ann, int num_input_moms, int *input_moms, int num_output_moms, + int *output_moms, struct gkyl_kn_vec *input_data_real, struct gkyl_kn_vec *output_data_real, + struct gkyl_kn_vec *output_data_predicted +) { if (gkyl_tm_trigger_check_and_bump(nnt, t_curr) || force_test) { int frame = nnt->curr - 1; @@ -320,12 +338,14 @@ test_mom(struct gkyl_tm_trigger* nnt, gkyl_pkpm_app* app, double t_curr, bool fo frame = nnt->curr; } - gkyl_pkpm_app_test(app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, input_data_real, output_data_real, output_data_predicted); + gkyl_pkpm_app_test( + app, t_curr, frame, ann, num_input_moms, input_moms, num_output_moms, output_moms, + input_data_real, output_data_real, output_data_predicted + ); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -350,18 +370,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -369,39 +388,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -424,64 +429,59 @@ main(int argc, char **argv) // Neutral species. struct gkyl_pkpm_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .init_dist = evalDistInit, .ctx_dist = &ctx, .init_fluid = evalFluidInit, .ctx_fluid = &ctx, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, - .bcx = { GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT }, + .bcx = {GKYL_SPECIES_REFLECT, GKYL_SPECIES_REFLECT} }; // Field. struct gkyl_pkpm_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .is_static = true, + .is_static = true }; // PKPM app. struct gkyl_pkpm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, - .use_explicit_source = true, + .use_explicit_source = true, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 1, - .species = { neut }, + .species = {neut}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -495,10 +495,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_pkpm_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_pkpm_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_pkpm_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -507,53 +511,58 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_pkpm_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_pkpm_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); // Create trigger for neural network training. int num_trains = ctx.num_trains; - struct gkyl_tm_trigger nn_trig = { .dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nn_trig = {.dt = t_end / num_trains, .tcurr = t_curr, .curr = frame_curr}; - kad_node_t **t = gkyl_malloc(sizeof(kad_node_t*) * app_inp.num_species); - struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + kad_node_t **t = gkyl_malloc(sizeof(kad_node_t *) * app_inp.num_species); + struct gkyl_kann_net **ann = gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.train_nn) { if (ctx.train_ab_initio) { - for (int i = 0; i < app_inp.num_species; i++ ) { + for (int i = 0; i < app_inp.num_species; i++) { if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_input(ctx.num_input_moms * 2); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 4); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_input(ctx.num_input_moms * 3); } @@ -561,22 +570,19 @@ main(int argc, char **argv) t[i] = kann_layer_dense(t[i], ctx.nn_width); t[i] = kad_tanh(t[i]); } - + if (ctx.poly_order == 1) { if (cdim == 1) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 2, KANN_C_MSE); - } - else if (cdim == 2) { + } else if (cdim == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 4, KANN_C_MSE); } - } - else if (ctx.poly_order == 2) { + } else if (ctx.poly_order == 2) { t[i] = kann_layer_cost(t[i], ctx.num_output_moms * 3, KANN_C_MSE); } ann[i] = gkyl_kann_net_new(t[i], app_args.use_gpu); } - } - else { + } else { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; int sz = gkyl_calc_strlen(fmt, ctx.train_nn_file, app_inp.species[i].name); @@ -587,11 +593,13 @@ main(int argc, char **argv) if (file != NULL) { ann[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann[i] = 0; ctx.train_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN training.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN training.\n", + app_inp.species[i].name + ); } } } @@ -600,8 +608,7 @@ main(int argc, char **argv) int cell_count = 0; if (app_inp.cdim == 1) { cell_count = app_inp.cells[0]; - } - else if (app_inp.cdim == 2) { + } else if (app_inp.cdim == 2) { cell_count = app_inp.cells[0] * app_inp.cells[1]; } @@ -614,12 +621,17 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); } // Create trigger for neural network writing. int num_nn_writes = ctx.num_nn_writes; - struct gkyl_tm_trigger nnw_trig = { .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnw_trig = { + .dt = t_end / num_nn_writes, .tcurr = t_curr, .curr = frame_curr + }; if (ctx.train_nn) { write_nn(&nnw_trig, app, t_curr, false, ann); @@ -627,9 +639,10 @@ main(int argc, char **argv) // Create trigger for neural network testing. int num_tests = ctx.num_tests; - struct gkyl_tm_trigger nnt_trig = { .dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger nnt_trig = {.dt = t_end / num_tests, .tcurr = t_curr, .curr = frame_curr}; - struct gkyl_kann_net **ann_test = gkyl_malloc(sizeof(struct gkyl_kann_net*) * app_inp.num_species); + struct gkyl_kann_net **ann_test = + gkyl_malloc(sizeof(struct gkyl_kann_net *) * app_inp.num_species); if (ctx.test_nn) { for (int i = 0; i < app_inp.num_species; i++) { const char *fmt = "%s-%s.dat"; @@ -641,11 +654,13 @@ main(int argc, char **argv) if (file != NULL) { ann_test[i] = gkyl_kann_net_load(fileNm, app_args.use_gpu); fclose(file); - } - else { + } else { ann_test[i] = 0; ctx.test_nn = false; - fprintf(stderr, "Neural network for species %s not found! Disabling NN testing.\n", app_inp.species[i].name); + fprintf( + stderr, "Neural network for species %s not found! Disabling NN testing.\n", + app_inp.species[i].name + ); } } } @@ -655,8 +670,10 @@ main(int argc, char **argv) struct gkyl_kn_vec *output_data_predicted = gkyl_kn_vec_new(cell_count, nn_output_dim); if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); } // Compute initial guess of maximum stable time-step. @@ -671,7 +688,7 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_pkpm_update(app, dt); gkyl_pkpm_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_pkpm_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -685,18 +702,23 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_pkpm_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -704,25 +726,32 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_pkpm_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_pkpm_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_pkpm_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); calc_integrated_L2_f(&l2f_trig, app, t_curr, true); write_data(&io_trig, app, t_curr, true); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, true, ann, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, true, ann); } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, true, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, + output_data_predicted + ); } break; } - } - else { + } else { num_failures = 0; } @@ -734,7 +763,10 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); if (ctx.train_nn) { - train_mom(&nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, input_data, output_data); + train_mom( + &nn_trig, app, t_curr, false, ann, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, + ctx.output_moms, input_data, output_data + ); write_nn(&nnw_trig, app, t_curr, false, ann); for (int i = 0; i < app_inp.num_species; i++) { @@ -742,8 +774,10 @@ main(int argc, char **argv) } } if (ctx.test_nn) { - test_mom(&nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, ctx.num_output_moms, ctx.output_moms, - input_data_real, output_data_real, output_data_predicted); + test_mom( + &nnt_trig, app, t_curr, false, ann_test, ctx.num_input_moms, ctx.input_moms, + ctx.num_output_moms, ctx.output_moms, input_data_real, output_data_real, output_data_predicted + ); for (int i = 0; i < app_inp.num_species; i++) { gkyl_kann_net_release(ann_test[i]); @@ -758,18 +792,30 @@ main(int argc, char **argv) gkyl_pkpm_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_pkpm_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_pkpm_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_pkpm_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_pkpm_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_pkpm_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_pkpm_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_pkpm_app_cout(app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_pkpm_app_cout( + app, stdout, "Fluid species RHS calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_pkpm_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); gkyl_pkpm_app_cout(app, stdout, "Species PKPM vars took %g secs\n", stat.species_pkpm_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_pkpm_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_pkpm_app_cout(app, stdout, "EM variables (bvar) calc took %g secs\n", stat.field_em_vars_tm); - gkyl_pkpm_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_pkpm_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_pkpm_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_pkpm_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/pkpm/zero/dg_calc_pkpm_dist_vars.c b/pkpm/zero/dg_calc_pkpm_dist_vars.c index d6c8eb53e8..72446c30e3 100644 --- a/pkpm/zero/dg_calc_pkpm_dist_vars.c +++ b/pkpm/zero/dg_calc_pkpm_dist_vars.c @@ -8,15 +8,15 @@ #include #include -gkyl_dg_calc_pkpm_dist_vars* -gkyl_dg_calc_pkpm_dist_vars_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis* cbasis, bool use_gpu) +gkyl_dg_calc_pkpm_dist_vars *gkyl_dg_calc_pkpm_dist_vars_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *cbasis, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_calc_pkpm_dist_vars_cu_dev_new(phase_grid, cbasis); - } -#endif + } +#endif gkyl_dg_calc_pkpm_dist_vars *up = gkyl_malloc(sizeof(gkyl_dg_calc_pkpm_dist_vars)); up->phase_grid = *phase_grid; @@ -27,34 +27,36 @@ gkyl_dg_calc_pkpm_dist_vars_new(const struct gkyl_rect_grid *phase_grid, up->pkpm_dist_mirror_force = choose_pkpm_dist_mirror_force_kern(b_type, cdim, poly_order); // Fetch the kernels in each direction - for (int d=0; dpkpm_dist_div_ppar[d] = choose_pkpm_dist_div_ppar_kern(d, b_type, cdim, poly_order); + } up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void gkyl_dg_calc_pkpm_dist_vars_mirror_force(struct gkyl_dg_calc_pkpm_dist_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* pkpm_prim, const struct gkyl_array* nu_prim_moms_sum, - const struct gkyl_array* div_b, const struct gkyl_array* pkpm_accel, - const struct gkyl_array* fIn, const struct gkyl_array* F_k_p_1, - struct gkyl_array* g_dist_source, struct gkyl_array* F_k_m_1) +void gkyl_dg_calc_pkpm_dist_vars_mirror_force( + struct gkyl_dg_calc_pkpm_dist_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *pkpm_prim, + const struct gkyl_array *nu_prim_moms_sum, const struct gkyl_array *div_b, + const struct gkyl_array *pkpm_accel, const struct gkyl_array *fIn, + const struct gkyl_array *F_k_p_1, struct gkyl_array *g_dist_source, struct gkyl_array *F_k_m_1 +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(g_dist_source)) { - return gkyl_dg_calc_pkpm_dist_vars_mirror_force_cu(up, - conf_range, phase_range, - pkpm_prim, nu_prim_moms_sum, div_b, pkpm_accel, - fIn, F_k_p_1, g_dist_source, F_k_m_1); + return gkyl_dg_calc_pkpm_dist_vars_mirror_force_cu( + up, conf_range, phase_range, pkpm_prim, nu_prim_moms_sum, div_b, pkpm_accel, fIn, F_k_p_1, + g_dist_source, F_k_m_1 + ); } -#endif +#endif // Cell center array double xc[GKYL_MAX_DIM]; - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, phase_range); while (gkyl_range_iter_next(&iter)) { @@ -72,25 +74,27 @@ void gkyl_dg_calc_pkpm_dist_vars_mirror_force(struct gkyl_dg_calc_pkpm_dist_vars double *g_dist_source_d = gkyl_array_fetch(g_dist_source, loc_phase); double *F_k_m_1_d = gkyl_array_fetch(F_k_m_1, loc_phase); - up->pkpm_dist_mirror_force(xc, up->phase_grid.dx, - pkpm_prim_d, nu_prim_moms_sum_d, div_b_d, pkpm_accel_d, - fIn_d, F_k_p_1_d, g_dist_source_d, F_k_m_1_d); - } + up->pkpm_dist_mirror_force( + xc, up->phase_grid.dx, pkpm_prim_d, nu_prim_moms_sum_d, div_b_d, pkpm_accel_d, fIn_d, + F_k_p_1_d, g_dist_source_d, F_k_m_1_d + ); + } } -void gkyl_dg_calc_pkpm_dist_vars_div_ppar(struct gkyl_dg_calc_pkpm_dist_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* bvar_surf, const struct gkyl_array* bvar, const struct gkyl_array* fIn, - const struct gkyl_array* max_b, struct gkyl_array* pkpm_div_ppar) +void gkyl_dg_calc_pkpm_dist_vars_div_ppar( + struct gkyl_dg_calc_pkpm_dist_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *bvar_surf, + const struct gkyl_array *bvar, const struct gkyl_array *fIn, const struct gkyl_array *max_b, + struct gkyl_array *pkpm_div_ppar +) { -// Check if more than one of the output arrays is on device? +// Check if more than one of the output arrays is on device? // Probably a better way to do this (JJ: 11/16/22) #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(pkpm_div_ppar)) { - return gkyl_dg_calc_pkpm_dist_vars_div_ppar_cu(up, - conf_range, phase_range, - bvar_surf, bvar, fIn, - max_b, pkpm_div_ppar); + return gkyl_dg_calc_pkpm_dist_vars_div_ppar_cu( + up, conf_range, phase_range, bvar_surf, bvar, fIn, max_b, pkpm_div_ppar + ); } #endif int cdim = up->cdim; @@ -101,7 +105,7 @@ void gkyl_dg_calc_pkpm_dist_vars_div_ppar(struct gkyl_dg_calc_pkpm_dist_vars *up struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, phase_range); while (gkyl_range_iter_next(&iter)) { - gkyl_copy_int_arr(cdim+1, iter.idx, idxc); + gkyl_copy_int_arr(cdim + 1, iter.idx, idxc); gkyl_rect_grid_cell_center(&up->phase_grid, idxc, xc); long loc_conf_c = gkyl_range_idx(conf_range, idxc); long loc_phase_c = gkyl_range_idx(phase_range, idxc); @@ -111,12 +115,13 @@ void gkyl_dg_calc_pkpm_dist_vars_div_ppar(struct gkyl_dg_calc_pkpm_dist_vars *up const double *f_c = gkyl_array_cfetch(fIn, loc_phase_c); const double *max_b_c = gkyl_array_cfetch(max_b, loc_conf_c); double *pkpm_div_ppar_d = gkyl_array_fetch(pkpm_div_ppar, loc_conf_c); - - for (int dir=0; dirpkpm_dist_div_ppar[dir](xc, up->phase_grid.dx, - bvar_surf_l, bvar_surf_c, bvar_surf_r, - f_l, f_c, f_r, - bvar_c, max_b_c, pkpm_div_ppar_d); - } - } + up->pkpm_dist_div_ppar[dir]( + xc, up->phase_grid.dx, bvar_surf_l, bvar_surf_c, bvar_surf_r, f_l, f_c, f_r, bvar_c, + max_b_c, pkpm_div_ppar_d + ); + } + } } void gkyl_dg_calc_pkpm_dist_vars_release(gkyl_dg_calc_pkpm_dist_vars *up) -{ - if (GKYL_IS_CU_ALLOC(up->flags)) +{ + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/pkpm/zero/dg_calc_pkpm_dist_vars_cu.cu b/pkpm/zero/dg_calc_pkpm_dist_vars_cu.cu index afef3b7ce9..58fc4541bb 100644 --- a/pkpm/zero/dg_calc_pkpm_dist_vars_cu.cu +++ b/pkpm/zero/dg_calc_pkpm_dist_vars_cu.cu @@ -13,20 +13,18 @@ extern "C" { #include } -__global__ void -gkyl_dg_calc_pkpm_dist_vars_mirror_force_cu_kernel(struct gkyl_dg_calc_pkpm_dist_vars *up, - struct gkyl_range conf_range, struct gkyl_range phase_range, - const struct gkyl_array* pkpm_prim, const struct gkyl_array* nu_prim_moms_sum, - const struct gkyl_array* div_b, const struct gkyl_array* pkpm_accel, - const struct gkyl_array* fIn, const struct gkyl_array* F_k_p_1, - struct gkyl_array* g_dist_source, struct gkyl_array* F_k_m_1) +__global__ void gkyl_dg_calc_pkpm_dist_vars_mirror_force_cu_kernel( + struct gkyl_dg_calc_pkpm_dist_vars *up, struct gkyl_range conf_range, + struct gkyl_range phase_range, const struct gkyl_array *pkpm_prim, + const struct gkyl_array *nu_prim_moms_sum, const struct gkyl_array *div_b, + const struct gkyl_array *pkpm_accel, const struct gkyl_array *fIn, + const struct gkyl_array *F_k_p_1, struct gkyl_array *g_dist_source, struct gkyl_array *F_k_m_1 +) { double xc[GKYL_MAX_DIM] = {0.0}; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < phase_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < phase_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -38,52 +36,51 @@ gkyl_dg_calc_pkpm_dist_vars_mirror_force_cu_kernel(struct gkyl_dg_calc_pkpm_dist long loc_conf = gkyl_range_idx(&conf_range, idx); long loc_phase = gkyl_range_idx(&phase_range, idx); - const double *pkpm_prim_d = (const double*) gkyl_array_cfetch(pkpm_prim, loc_conf); - const double *nu_prim_moms_sum_d = (const double*) gkyl_array_cfetch(nu_prim_moms_sum, loc_conf); - const double *div_b_d = (const double*) gkyl_array_cfetch(div_b, loc_conf); - const double *pkpm_accel_d = (const double*) gkyl_array_cfetch(pkpm_accel, loc_conf); - const double *fIn_d = (const double*) gkyl_array_cfetch(fIn, loc_phase); - const double *F_k_p_1_d = (const double*) gkyl_array_cfetch(F_k_p_1, loc_phase); - - double *g_dist_source_d = (double*) gkyl_array_fetch(g_dist_source, loc_phase); - double *F_k_m_1_d = (double*) gkyl_array_fetch(F_k_m_1, loc_phase); - - up->pkpm_dist_mirror_force(xc, up->phase_grid.dx, - pkpm_prim_d, nu_prim_moms_sum_d, div_b_d, pkpm_accel_d, - fIn_d, F_k_p_1_d, g_dist_source_d, F_k_m_1_d); - } + const double *pkpm_prim_d = (const double *)gkyl_array_cfetch(pkpm_prim, loc_conf); + const double *nu_prim_moms_sum_d = + (const double *)gkyl_array_cfetch(nu_prim_moms_sum, loc_conf); + const double *div_b_d = (const double *)gkyl_array_cfetch(div_b, loc_conf); + const double *pkpm_accel_d = (const double *)gkyl_array_cfetch(pkpm_accel, loc_conf); + const double *fIn_d = (const double *)gkyl_array_cfetch(fIn, loc_phase); + const double *F_k_p_1_d = (const double *)gkyl_array_cfetch(F_k_p_1, loc_phase); + + double *g_dist_source_d = (double *)gkyl_array_fetch(g_dist_source, loc_phase); + double *F_k_m_1_d = (double *)gkyl_array_fetch(F_k_m_1, loc_phase); + + up->pkpm_dist_mirror_force( + xc, up->phase_grid.dx, pkpm_prim_d, nu_prim_moms_sum_d, div_b_d, pkpm_accel_d, fIn_d, + F_k_p_1_d, g_dist_source_d, F_k_m_1_d + ); + } } // Host-side wrapper for pkpm mirror force source distribution function calculation -void -gkyl_dg_calc_pkpm_dist_vars_mirror_force_cu(struct gkyl_dg_calc_pkpm_dist_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* pkpm_prim, const struct gkyl_array* nu_prim_moms_sum, - const struct gkyl_array* div_b, const struct gkyl_array* pkpm_accel, - const struct gkyl_array* fIn, const struct gkyl_array* F_k_p_1, - struct gkyl_array* g_dist_source, struct gkyl_array* F_k_m_1) +void gkyl_dg_calc_pkpm_dist_vars_mirror_force_cu( + struct gkyl_dg_calc_pkpm_dist_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *pkpm_prim, + const struct gkyl_array *nu_prim_moms_sum, const struct gkyl_array *div_b, + const struct gkyl_array *pkpm_accel, const struct gkyl_array *fIn, + const struct gkyl_array *F_k_p_1, struct gkyl_array *g_dist_source, struct gkyl_array *F_k_m_1 +) { int nblocks = phase_range->nblocks; int nthreads = phase_range->nthreads; - gkyl_dg_calc_pkpm_dist_vars_mirror_force_cu_kernel<<>>(up->on_dev, - *conf_range, *phase_range, - pkpm_prim->on_dev, nu_prim_moms_sum->on_dev, - div_b->on_dev, pkpm_accel->on_dev, - fIn->on_dev, F_k_p_1->on_dev, - g_dist_source->on_dev, F_k_m_1->on_dev); + gkyl_dg_calc_pkpm_dist_vars_mirror_force_cu_kernel<< > >( + up->on_dev, *conf_range, *phase_range, pkpm_prim->on_dev, nu_prim_moms_sum->on_dev, + div_b->on_dev, pkpm_accel->on_dev, fIn->on_dev, F_k_p_1->on_dev, g_dist_source->on_dev, + F_k_m_1->on_dev + ); } -__global__ void -gkyl_dg_calc_pkpm_dist_vars_div_ppar_cu_kernel(struct gkyl_dg_calc_pkpm_dist_vars *up, - struct gkyl_range conf_range, struct gkyl_range phase_range, - const struct gkyl_array* bvar_surf, const struct gkyl_array* bvar, const struct gkyl_array* fIn, - const struct gkyl_array* max_b, struct gkyl_array* pkpm_div_ppar) +__global__ void gkyl_dg_calc_pkpm_dist_vars_div_ppar_cu_kernel( + struct gkyl_dg_calc_pkpm_dist_vars *up, struct gkyl_range conf_range, + struct gkyl_range phase_range, const struct gkyl_array *bvar_surf, const struct gkyl_array *bvar, + const struct gkyl_array *fIn, const struct gkyl_array *max_b, struct gkyl_array *pkpm_div_ppar +) { double xc[GKYL_MAX_DIM] = {0.0}; int idxl[GKYL_MAX_DIM], idxc[GKYL_MAX_DIM], idxr[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < phase_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < phase_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idxc // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -95,75 +92,80 @@ gkyl_dg_calc_pkpm_dist_vars_div_ppar_cu_kernel(struct gkyl_dg_calc_pkpm_dist_var long linc_conf = gkyl_range_idx(&conf_range, idxc); long linc_phase = gkyl_range_idx(&phase_range, idxc); - const double *bvar_surf_c = (const double*) gkyl_array_cfetch(bvar_surf, linc_conf); - const double *bvar_c = (const double*) gkyl_array_cfetch(bvar, linc_conf); - const double *f_c = (const double*) gkyl_array_cfetch(fIn, linc_phase); - const double *max_b_c = (const double*) gkyl_array_cfetch(max_b, linc_conf); + const double *bvar_surf_c = (const double *)gkyl_array_cfetch(bvar_surf, linc_conf); + const double *bvar_c = (const double *)gkyl_array_cfetch(bvar, linc_conf); + const double *f_c = (const double *)gkyl_array_cfetch(fIn, linc_phase); + const double *max_b_c = (const double *)gkyl_array_cfetch(max_b, linc_conf); double momLocal[96]; // hard-coded to 3 * max confBasis.num_basis (3x p=3 Ser) for now. - for (unsigned int k=0; k<96; ++k) + for (unsigned int k = 0; k < 96; ++k) { momLocal[k] = 0.0; + } - for (int dir=0; dircdim; ++dir) { - gkyl_copy_int_arr(up->cdim+1, idxc, idxl); - gkyl_copy_int_arr(up->cdim+1, idxc, idxr); + for (int dir = 0; dir < up->cdim; ++dir) { + gkyl_copy_int_arr(up->cdim + 1, idxc, idxl); + gkyl_copy_int_arr(up->cdim + 1, idxc, idxr); - idxl[dir] = idxl[dir]-1; idxr[dir] = idxr[dir]+1; + idxl[dir] = idxl[dir] - 1; + idxr[dir] = idxr[dir] + 1; - long linl_conf = gkyl_range_idx(&conf_range, idxl); - long linl_phase = gkyl_range_idx(&phase_range, idxl); - long linr_conf = gkyl_range_idx(&conf_range, idxr); - long linr_phase = gkyl_range_idx(&phase_range, idxr); + long linl_conf = gkyl_range_idx(&conf_range, idxl); + long linl_phase = gkyl_range_idx(&phase_range, idxl); + long linr_conf = gkyl_range_idx(&conf_range, idxr); + long linr_phase = gkyl_range_idx(&phase_range, idxr); - const double *bvar_surf_l = (const double*) gkyl_array_cfetch(bvar_surf, linl_conf); - const double *f_l = (const double*) gkyl_array_cfetch(fIn, linl_phase); - const double *bvar_surf_r = (const double*) gkyl_array_cfetch(bvar_surf, linr_conf); - const double *f_r = (const double*) gkyl_array_cfetch(fIn, linr_phase); + const double *bvar_surf_l = (const double *)gkyl_array_cfetch(bvar_surf, linl_conf); + const double *f_l = (const double *)gkyl_array_cfetch(fIn, linl_phase); + const double *bvar_surf_r = (const double *)gkyl_array_cfetch(bvar_surf, linr_conf); + const double *f_r = (const double *)gkyl_array_cfetch(fIn, linr_phase); - up->pkpm_dist_div_ppar[dir](xc, up->phase_grid.dx, - bvar_surf_l, bvar_surf_c, bvar_surf_r, - f_l, f_c, f_r, - bvar_c, max_b_c, &momLocal[0]); + up->pkpm_dist_div_ppar[dir]( + xc, up->phase_grid.dx, bvar_surf_l, bvar_surf_c, bvar_surf_r, f_l, f_c, f_r, bvar_c, + max_b_c, &momLocal[0] + ); } // Accumulate output to output array atomically to avoid race conditions - double *pkpm_div_ppar_d = (double*) gkyl_array_fetch(pkpm_div_ppar, linc_conf); + double *pkpm_div_ppar_d = (double *)gkyl_array_fetch(pkpm_div_ppar, linc_conf); for (unsigned int k = 0; k < pkpm_div_ppar->ncomp; ++k) { - atomicAdd(&pkpm_div_ppar_d[k], momLocal[k]); - } - } + atomicAdd(&pkpm_div_ppar_d[k], momLocal[k]); + } + } } // Host-side wrapper for pkpm div(p_parallel b_hat) calculation -void -gkyl_dg_calc_pkpm_dist_vars_div_ppar_cu(struct gkyl_dg_calc_pkpm_dist_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* bvar_surf, const struct gkyl_array* bvar, const struct gkyl_array* fIn, - const struct gkyl_array* max_b, struct gkyl_array* pkpm_div_ppar) +void gkyl_dg_calc_pkpm_dist_vars_div_ppar_cu( + struct gkyl_dg_calc_pkpm_dist_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *bvar_surf, + const struct gkyl_array *bvar, const struct gkyl_array *fIn, const struct gkyl_array *max_b, + struct gkyl_array *pkpm_div_ppar +) { int nblocks = phase_range->nblocks; int nthreads = phase_range->nthreads; - gkyl_dg_calc_pkpm_dist_vars_div_ppar_cu_kernel<<>>(up->on_dev, - *conf_range, *phase_range, - bvar_surf->on_dev, bvar->on_dev, fIn->on_dev, - max_b->on_dev, pkpm_div_ppar->on_dev); + gkyl_dg_calc_pkpm_dist_vars_div_ppar_cu_kernel<< > >( + up->on_dev, *conf_range, *phase_range, bvar_surf->on_dev, bvar->on_dev, fIn->on_dev, + max_b->on_dev, pkpm_div_ppar->on_dev + ); } // CUDA kernel to set device pointers to pkpm dist vars kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_calc_pkpm_dist_vars_set_cu_dev_ptrs(struct gkyl_dg_calc_pkpm_dist_vars *up, enum gkyl_basis_type b_type, - int cdim,int poly_order) +__global__ static void dg_calc_pkpm_dist_vars_set_cu_dev_ptrs( + struct gkyl_dg_calc_pkpm_dist_vars *up, enum gkyl_basis_type b_type, int cdim, int poly_order +) { up->pkpm_dist_mirror_force = choose_pkpm_dist_mirror_force_kern(b_type, cdim, poly_order); // Fetch the kernels in each direction - for (int d=0; dpkpm_dist_div_ppar[d] = choose_pkpm_dist_div_ppar_kern(d, b_type, cdim, poly_order); + } } -gkyl_dg_calc_pkpm_dist_vars* -gkyl_dg_calc_pkpm_dist_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis* cbasis) +gkyl_dg_calc_pkpm_dist_vars *gkyl_dg_calc_pkpm_dist_vars_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *cbasis +) { - struct gkyl_dg_calc_pkpm_dist_vars *up = (struct gkyl_dg_calc_pkpm_dist_vars*) gkyl_malloc(sizeof(gkyl_dg_calc_pkpm_dist_vars)); + struct gkyl_dg_calc_pkpm_dist_vars *up = + (struct gkyl_dg_calc_pkpm_dist_vars *)gkyl_malloc(sizeof(gkyl_dg_calc_pkpm_dist_vars)); up->phase_grid = *phase_grid; enum gkyl_basis_type b_type = cbasis->b_type; @@ -174,13 +176,14 @@ gkyl_dg_calc_pkpm_dist_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_calc_pkpm_dist_vars *up_cu = (struct gkyl_dg_calc_pkpm_dist_vars*) gkyl_cu_malloc(sizeof(gkyl_dg_calc_pkpm_dist_vars)); + struct gkyl_dg_calc_pkpm_dist_vars *up_cu = + (struct gkyl_dg_calc_pkpm_dist_vars *)gkyl_cu_malloc(sizeof(gkyl_dg_calc_pkpm_dist_vars)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_calc_pkpm_dist_vars), GKYL_CU_MEMCPY_H2D); - dg_calc_pkpm_dist_vars_set_cu_dev_ptrs<<<1,1>>>(up_cu, b_type, cdim, poly_order); + dg_calc_pkpm_dist_vars_set_cu_dev_ptrs<<<1, 1> > >(up_cu, b_type, cdim, poly_order); // set parent on_dev pointer up->on_dev = up_cu; - + return up; } diff --git a/pkpm/zero/dg_calc_pkpm_em_coupling.c b/pkpm/zero/dg_calc_pkpm_em_coupling.c index aefa43a594..84ed1592eb 100644 --- a/pkpm/zero/dg_calc_pkpm_em_coupling.c +++ b/pkpm/zero/dg_calc_pkpm_em_coupling.c @@ -8,18 +8,18 @@ #include #include -struct gkyl_dg_calc_pkpm_em_coupling* -gkyl_dg_calc_pkpm_em_coupling_new(const struct gkyl_basis* cbasis, - const struct gkyl_range *mem_range, - int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, - bool pkpm_field_static, bool use_gpu) +struct gkyl_dg_calc_pkpm_em_coupling *gkyl_dg_calc_pkpm_em_coupling_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, int num_species, + double qbym[GKYL_MAX_SPECIES], double epsilon0, bool pkpm_field_static, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { - return gkyl_dg_calc_pkpm_em_coupling_cu_dev_new(cbasis, mem_range, - num_species, qbym, epsilon0, pkpm_field_static); - } -#endif + if (use_gpu) { + return gkyl_dg_calc_pkpm_em_coupling_cu_dev_new( + cbasis, mem_range, num_species, qbym, epsilon0, pkpm_field_static + ); + } +#endif gkyl_dg_calc_pkpm_em_coupling *up = gkyl_malloc(sizeof(gkyl_dg_calc_pkpm_em_coupling)); int nc = cbasis->num_basis; @@ -33,13 +33,15 @@ gkyl_dg_calc_pkpm_em_coupling_new(const struct gkyl_basis* cbasis, // Linear system size is nc*(3*num_species + 3) up->num_species = num_species; - up->As = gkyl_nmat_new(mem_range->volume, nc*(3*up->num_species + 3), nc*(3*up->num_species + 3)); - up->xs = gkyl_nmat_new(mem_range->volume, nc*(3*up->num_species + 3), 1); + up->As = gkyl_nmat_new( + mem_range->volume, nc * (3 * up->num_species + 3), nc * (3 * up->num_species + 3) + ); + up->xs = gkyl_nmat_new(mem_range->volume, nc * (3 * up->num_species + 3), 1); up->mem = gkyl_nmat_linsolve_lu_new(up->As->num, up->As->nr); // Boolean for whether or not self-consistent EM fields are static up->pkpm_field_static = pkpm_field_static; - + // Needed constants for the source solve up->epsilon0 = epsilon0; for (int n = 0; n < num_species; ++n) { @@ -49,22 +51,23 @@ gkyl_dg_calc_pkpm_em_coupling_new(const struct gkyl_basis* cbasis, up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void -gkyl_dg_calc_pkpm_em_coupling_advance(struct gkyl_dg_calc_pkpm_em_coupling *up, double dt, - const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - const struct gkyl_array* vlasov_pkpm_moms[GKYL_MAX_SPECIES], const struct gkyl_array* pkpm_u[GKYL_MAX_SPECIES], - struct gkyl_array* euler_pkpm[GKYL_MAX_SPECIES], struct gkyl_array* em) +void gkyl_dg_calc_pkpm_em_coupling_advance( + struct gkyl_dg_calc_pkpm_em_coupling *up, double dt, + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], const struct gkyl_array *ext_em, + const struct gkyl_array *app_current, const struct gkyl_array *vlasov_pkpm_moms[GKYL_MAX_SPECIES], + const struct gkyl_array *pkpm_u[GKYL_MAX_SPECIES], + struct gkyl_array *euler_pkpm[GKYL_MAX_SPECIES], struct gkyl_array *em +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(em)) { - return gkyl_dg_calc_pkpm_em_coupling_advance_cu(up, - dt, app_accel, ext_em, app_current, vlasov_pkpm_moms, pkpm_u, - euler_pkpm, em); + return gkyl_dg_calc_pkpm_em_coupling_advance_cu( + up, dt, app_accel, ext_em, app_current, vlasov_pkpm_moms, pkpm_u, euler_pkpm, em + ); } #endif int num_species = up->num_species; @@ -80,7 +83,7 @@ gkyl_dg_calc_pkpm_em_coupling_advance(struct gkyl_dg_calc_pkpm_em_coupling *up, while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&up->mem_range, iter.idx); - for (int n=0; npkpm_em_coupling_set(count, - up->num_species, up->qbym, up->epsilon0, up->pkpm_field_static, dt, - up->As, up->xs, - app_accels, ext_em_d, app_current_d, pkpm_moms, pkpm_flows, em_d); + up->pkpm_em_coupling_set( + count, up->num_species, up->qbym, up->epsilon0, up->pkpm_field_static, dt, up->As, up->xs, + app_accels, ext_em_d, app_current_d, pkpm_moms, pkpm_flows, em_d + ); count += 1; } @@ -105,29 +108,30 @@ gkyl_dg_calc_pkpm_em_coupling_advance(struct gkyl_dg_calc_pkpm_em_coupling *up, while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&up->mem_range, iter.idx); - for (int n=0; npkpm_em_coupling_copy(count, up->num_species, up->qbym, up->epsilon0, - up->xs, pkpm_moms, pkpm_flows, fluids, em_d); + up->pkpm_em_coupling_copy( + count, up->num_species, up->qbym, up->epsilon0, up->xs, pkpm_moms, pkpm_flows, fluids, em_d + ); count += 1; } } -void -gkyl_dg_calc_pkpm_em_coupling_release(gkyl_dg_calc_pkpm_em_coupling *up) +void gkyl_dg_calc_pkpm_em_coupling_release(gkyl_dg_calc_pkpm_em_coupling *up) { gkyl_nmat_release(up->As); gkyl_nmat_release(up->xs); gkyl_nmat_linsolve_lu_release(up->mem); - - if (GKYL_IS_CU_ALLOC(up->flags)) + + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/pkpm/zero/dg_calc_pkpm_em_coupling_cu.cu b/pkpm/zero/dg_calc_pkpm_em_coupling_cu.cu index ef4a06aad5..1980e593ae 100644 --- a/pkpm/zero/dg_calc_pkpm_em_coupling_cu.cu +++ b/pkpm/zero/dg_calc_pkpm_em_coupling_cu.cu @@ -13,23 +13,20 @@ extern "C" { #include } -__global__ static void -gkyl_dg_calc_pkpm_em_coupling_set_one_fluid_cu_kernel(gkyl_dg_calc_pkpm_em_coupling* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, double dt, - const struct gkyl_array* app_accel, - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* pkpm_u, - struct gkyl_array* em) +__global__ static void gkyl_dg_calc_pkpm_em_coupling_set_one_fluid_cu_kernel( + gkyl_dg_calc_pkpm_em_coupling *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, double dt, const struct gkyl_array *app_accel, + const struct gkyl_array *ext_em, const struct gkyl_array *app_current, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *pkpm_u, struct gkyl_array *em +) { - const double *app_accels[GKYL_MAX_SPECIES]; + const double *app_accels[GKYL_MAX_SPECIES]; const double *pkpm_moms[GKYL_MAX_SPECIES]; const double *pkpm_flows[GKYL_MAX_SPECIES]; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -39,36 +36,34 @@ gkyl_dg_calc_pkpm_em_coupling_set_one_fluid_cu_kernel(gkyl_dg_calc_pkpm_em_coupl // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - app_accels[0] = (const double*) gkyl_array_cfetch(app_accel, loc); - pkpm_moms[0] = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms, loc); - pkpm_flows[0] = (const double*) gkyl_array_cfetch(pkpm_u, loc); + app_accels[0] = (const double *)gkyl_array_cfetch(app_accel, loc); + pkpm_moms[0] = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms, loc); + pkpm_flows[0] = (const double *)gkyl_array_cfetch(pkpm_u, loc); - const double *ext_em_d = (const double*) gkyl_array_cfetch(ext_em, loc); - const double *app_current_d = (const double*) gkyl_array_cfetch(app_current, loc); - double *em_d = (double*) gkyl_array_fetch(em, loc); + const double *ext_em_d = (const double *)gkyl_array_cfetch(ext_em, loc); + const double *app_current_d = (const double *)gkyl_array_cfetch(app_current, loc); + double *em_d = (double *)gkyl_array_fetch(em, loc); - up->pkpm_em_coupling_set(linc1, - up->num_species, up->qbym, up->epsilon0, up->pkpm_field_static, dt, - As, xs, - app_accels, ext_em_d, app_current_d, pkpm_moms, pkpm_flows, em_d); + up->pkpm_em_coupling_set( + linc1, up->num_species, up->qbym, up->epsilon0, up->pkpm_field_static, dt, As, xs, app_accels, + ext_em_d, app_current_d, pkpm_moms, pkpm_flows, em_d + ); } } -__global__ static void -gkyl_dg_calc_pkpm_em_coupling_copy_one_fluid_cu_kernel(gkyl_dg_calc_pkpm_em_coupling* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* pkpm_u, - struct gkyl_array* euler_pkpm, struct gkyl_array* em) +__global__ static void gkyl_dg_calc_pkpm_em_coupling_copy_one_fluid_cu_kernel( + gkyl_dg_calc_pkpm_em_coupling *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *pkpm_u, + struct gkyl_array *euler_pkpm, struct gkyl_array *em +) { const double *pkpm_moms[GKYL_MAX_SPECIES]; - const double *pkpm_flows[GKYL_MAX_SPECIES]; - double *fluids[GKYL_MAX_SPECIES]; + const double *pkpm_flows[GKYL_MAX_SPECIES]; + double *fluids[GKYL_MAX_SPECIES]; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -78,34 +73,33 @@ gkyl_dg_calc_pkpm_em_coupling_copy_one_fluid_cu_kernel(gkyl_dg_calc_pkpm_em_coup // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - pkpm_moms[0] = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms, loc); - pkpm_flows[0] = (const double*) gkyl_array_cfetch(pkpm_u, loc); - fluids[0] = (double*) gkyl_array_fetch(euler_pkpm, loc); - double *em_d = (double*) gkyl_array_fetch(em, loc); + pkpm_moms[0] = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms, loc); + pkpm_flows[0] = (const double *)gkyl_array_cfetch(pkpm_u, loc); + fluids[0] = (double *)gkyl_array_fetch(euler_pkpm, loc); + double *em_d = (double *)gkyl_array_fetch(em, loc); - up->pkpm_em_coupling_copy(linc1, up->num_species, up->qbym, up->epsilon0, - xs, pkpm_moms, pkpm_flows, fluids, em_d); + up->pkpm_em_coupling_copy( + linc1, up->num_species, up->qbym, up->epsilon0, xs, pkpm_moms, pkpm_flows, fluids, em_d + ); } } -__global__ static void -gkyl_dg_calc_pkpm_em_coupling_set_two_fluids_cu_kernel(gkyl_dg_calc_pkpm_em_coupling* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, double dt, - const struct gkyl_array* app_accel_1, const struct gkyl_array* app_accel_2, - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - const struct gkyl_array* vlasov_pkpm_moms_1, const struct gkyl_array* vlasov_pkpm_moms_2, - const struct gkyl_array* pkpm_u_1, const struct gkyl_array* pkpm_u_2, - struct gkyl_array* em) +__global__ static void gkyl_dg_calc_pkpm_em_coupling_set_two_fluids_cu_kernel( + gkyl_dg_calc_pkpm_em_coupling *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, double dt, const struct gkyl_array *app_accel_1, + const struct gkyl_array *app_accel_2, const struct gkyl_array *ext_em, + const struct gkyl_array *app_current, const struct gkyl_array *vlasov_pkpm_moms_1, + const struct gkyl_array *vlasov_pkpm_moms_2, const struct gkyl_array *pkpm_u_1, + const struct gkyl_array *pkpm_u_2, struct gkyl_array *em +) { - const double *app_accels[GKYL_MAX_SPECIES]; + const double *app_accels[GKYL_MAX_SPECIES]; const double *pkpm_moms[GKYL_MAX_SPECIES]; const double *pkpm_flows[GKYL_MAX_SPECIES]; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -115,40 +109,38 @@ gkyl_dg_calc_pkpm_em_coupling_set_two_fluids_cu_kernel(gkyl_dg_calc_pkpm_em_coup // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - app_accels[0] = (const double*) gkyl_array_cfetch(app_accel_1, loc); - app_accels[1] = (const double*) gkyl_array_cfetch(app_accel_2, loc); - pkpm_moms[0] = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms_1, loc); - pkpm_moms[1] = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms_2, loc); - pkpm_flows[0] = (const double*) gkyl_array_cfetch(pkpm_u_1, loc); - pkpm_flows[1] = (const double*) gkyl_array_cfetch(pkpm_u_2, loc); - - const double *ext_em_d = (const double*) gkyl_array_cfetch(ext_em, loc); - const double *app_current_d = (const double*) gkyl_array_cfetch(app_current, loc); - double *em_d = (double*) gkyl_array_fetch(em, loc); - - up->pkpm_em_coupling_set(linc1, - up->num_species, up->qbym, up->epsilon0, up->pkpm_field_static, dt, - As, xs, - app_accels, ext_em_d, app_current_d, pkpm_moms, pkpm_flows, em_d); + app_accels[0] = (const double *)gkyl_array_cfetch(app_accel_1, loc); + app_accels[1] = (const double *)gkyl_array_cfetch(app_accel_2, loc); + pkpm_moms[0] = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms_1, loc); + pkpm_moms[1] = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms_2, loc); + pkpm_flows[0] = (const double *)gkyl_array_cfetch(pkpm_u_1, loc); + pkpm_flows[1] = (const double *)gkyl_array_cfetch(pkpm_u_2, loc); + + const double *ext_em_d = (const double *)gkyl_array_cfetch(ext_em, loc); + const double *app_current_d = (const double *)gkyl_array_cfetch(app_current, loc); + double *em_d = (double *)gkyl_array_fetch(em, loc); + + up->pkpm_em_coupling_set( + linc1, up->num_species, up->qbym, up->epsilon0, up->pkpm_field_static, dt, As, xs, app_accels, + ext_em_d, app_current_d, pkpm_moms, pkpm_flows, em_d + ); } } -__global__ static void -gkyl_dg_calc_pkpm_em_coupling_copy_two_fluids_cu_kernel(gkyl_dg_calc_pkpm_em_coupling* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* vlasov_pkpm_moms_1, const struct gkyl_array* vlasov_pkpm_moms_2, - const struct gkyl_array* pkpm_u_1, const struct gkyl_array* pkpm_u_2, - struct gkyl_array* euler_pkpm_1, struct gkyl_array* euler_pkpm_2, struct gkyl_array* em) +__global__ static void gkyl_dg_calc_pkpm_em_coupling_copy_two_fluids_cu_kernel( + gkyl_dg_calc_pkpm_em_coupling *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + const struct gkyl_array *vlasov_pkpm_moms_1, const struct gkyl_array *vlasov_pkpm_moms_2, + const struct gkyl_array *pkpm_u_1, const struct gkyl_array *pkpm_u_2, + struct gkyl_array *euler_pkpm_1, struct gkyl_array *euler_pkpm_2, struct gkyl_array *em +) { const double *pkpm_moms[GKYL_MAX_SPECIES]; - const double *pkpm_flows[GKYL_MAX_SPECIES]; - double *fluids[GKYL_MAX_SPECIES]; + const double *pkpm_flows[GKYL_MAX_SPECIES]; + double *fluids[GKYL_MAX_SPECIES]; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -158,81 +150,85 @@ gkyl_dg_calc_pkpm_em_coupling_copy_two_fluids_cu_kernel(gkyl_dg_calc_pkpm_em_cou // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - pkpm_moms[0] = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms_1, loc); - pkpm_moms[1] = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms_2, loc); - pkpm_flows[0] = (const double*) gkyl_array_cfetch(pkpm_u_1, loc); - pkpm_flows[1] = (const double*) gkyl_array_cfetch(pkpm_u_2, loc); - fluids[0] = (double*) gkyl_array_fetch(euler_pkpm_1, loc); - fluids[1] = (double*) gkyl_array_fetch(euler_pkpm_2, loc); - double *em_d = (double*) gkyl_array_fetch(em, loc); - - up->pkpm_em_coupling_copy(linc1, up->num_species, up->qbym, up->epsilon0, - xs, pkpm_moms, pkpm_flows, fluids, em_d); + pkpm_moms[0] = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms_1, loc); + pkpm_moms[1] = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms_2, loc); + pkpm_flows[0] = (const double *)gkyl_array_cfetch(pkpm_u_1, loc); + pkpm_flows[1] = (const double *)gkyl_array_cfetch(pkpm_u_2, loc); + fluids[0] = (double *)gkyl_array_fetch(euler_pkpm_1, loc); + fluids[1] = (double *)gkyl_array_fetch(euler_pkpm_2, loc); + double *em_d = (double *)gkyl_array_fetch(em, loc); + + up->pkpm_em_coupling_copy( + linc1, up->num_species, up->qbym, up->epsilon0, xs, pkpm_moms, pkpm_flows, fluids, em_d + ); } } // Host-side wrapper for primitive variable calculation -void gkyl_dg_calc_pkpm_em_coupling_advance_cu(struct gkyl_dg_calc_pkpm_em_coupling *up, double dt, - const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - const struct gkyl_array* vlasov_pkpm_moms[GKYL_MAX_SPECIES], const struct gkyl_array* pkpm_u[GKYL_MAX_SPECIES], - struct gkyl_array* euler_pkpm[GKYL_MAX_SPECIES], struct gkyl_array* em) +void gkyl_dg_calc_pkpm_em_coupling_advance_cu( + struct gkyl_dg_calc_pkpm_em_coupling *up, double dt, + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], const struct gkyl_array *ext_em, + const struct gkyl_array *app_current, const struct gkyl_array *vlasov_pkpm_moms[GKYL_MAX_SPECIES], + const struct gkyl_array *pkpm_u[GKYL_MAX_SPECIES], + struct gkyl_array *euler_pkpm[GKYL_MAX_SPECIES], struct gkyl_array *em +) { struct gkyl_range conf_range = up->mem_range; int num_species = up->num_species; if (num_species == 1) { - gkyl_dg_calc_pkpm_em_coupling_set_one_fluid_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, dt, - app_accel[0]->on_dev, ext_em->on_dev, app_current->on_dev, - vlasov_pkpm_moms[0]->on_dev, pkpm_u[0]->on_dev, - em->on_dev); - } - else if (num_species == 2) { - gkyl_dg_calc_pkpm_em_coupling_set_two_fluids_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, dt, - app_accel[0]->on_dev, app_accel[1]->on_dev, ext_em->on_dev, app_current->on_dev, - vlasov_pkpm_moms[0]->on_dev, vlasov_pkpm_moms[1]->on_dev, - pkpm_u[0]->on_dev, pkpm_u[1]->on_dev, - em->on_dev); + gkyl_dg_calc_pkpm_em_coupling_set_one_fluid_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, dt, app_accel[0]->on_dev, + ext_em->on_dev, app_current->on_dev, vlasov_pkpm_moms[0]->on_dev, pkpm_u[0]->on_dev, + em->on_dev + ); + } else if (num_species == 2) { + gkyl_dg_calc_pkpm_em_coupling_set_two_fluids_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, dt, app_accel[0]->on_dev, + app_accel[1]->on_dev, ext_em->on_dev, app_current->on_dev, vlasov_pkpm_moms[0]->on_dev, + vlasov_pkpm_moms[1]->on_dev, pkpm_u[0]->on_dev, pkpm_u[1]->on_dev, em->on_dev + ); } bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); if (num_species == 1) { - gkyl_dg_calc_pkpm_em_coupling_copy_one_fluid_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, - vlasov_pkpm_moms[0]->on_dev, pkpm_u[0]->on_dev, - euler_pkpm[0]->on_dev, em->on_dev); - } - else if (num_species == 2) { - gkyl_dg_calc_pkpm_em_coupling_copy_two_fluids_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, - vlasov_pkpm_moms[0]->on_dev, vlasov_pkpm_moms[1]->on_dev, - pkpm_u[0]->on_dev, pkpm_u[1]->on_dev, - euler_pkpm[0]->on_dev, euler_pkpm[1]->on_dev, em->on_dev); + gkyl_dg_calc_pkpm_em_coupling_copy_one_fluid_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->xs->on_dev, conf_range, vlasov_pkpm_moms[0]->on_dev, pkpm_u[0]->on_dev, + euler_pkpm[0]->on_dev, em->on_dev + ); + } else if (num_species == 2) { + gkyl_dg_calc_pkpm_em_coupling_copy_two_fluids_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->xs->on_dev, conf_range, vlasov_pkpm_moms[0]->on_dev, + vlasov_pkpm_moms[1]->on_dev, pkpm_u[0]->on_dev, pkpm_u[1]->on_dev, euler_pkpm[0]->on_dev, + euler_pkpm[1]->on_dev, em->on_dev + ); } } // CUDA kernel to set device pointers to pkpm-em coupling kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_calc_pkpm_em_coupling_set_cu_dev_ptrs(struct gkyl_dg_calc_pkpm_em_coupling *up, - enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ static void dg_calc_pkpm_em_coupling_set_cu_dev_ptrs( + struct gkyl_dg_calc_pkpm_em_coupling *up, enum gkyl_basis_type b_type, int cdim, int poly_order +) { up->pkpm_em_coupling_set = choose_pkpm_em_coupling_set_kern(b_type, cdim, poly_order); up->pkpm_em_coupling_copy = choose_pkpm_em_coupling_copy_kern(b_type, cdim, poly_order); } -gkyl_dg_calc_pkpm_em_coupling* -gkyl_dg_calc_pkpm_em_coupling_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_range *mem_range, - int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, - bool pkpm_field_static) +gkyl_dg_calc_pkpm_em_coupling *gkyl_dg_calc_pkpm_em_coupling_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, int num_species, + double qbym[GKYL_MAX_SPECIES], double epsilon0, bool pkpm_field_static +) { - struct gkyl_dg_calc_pkpm_em_coupling *up = (struct gkyl_dg_calc_pkpm_em_coupling*) gkyl_malloc(sizeof(gkyl_dg_calc_pkpm_em_coupling)); + struct gkyl_dg_calc_pkpm_em_coupling *up = + (struct gkyl_dg_calc_pkpm_em_coupling *)gkyl_malloc(sizeof(gkyl_dg_calc_pkpm_em_coupling)); int nc = cbasis->num_basis; int cdim = cbasis->ndim; @@ -242,8 +238,10 @@ gkyl_dg_calc_pkpm_em_coupling_cu_dev_new(const struct gkyl_basis* cbasis, // Linear system size is nc*(3*num_species + 3) up->num_species = num_species; - up->As = gkyl_nmat_cu_dev_new(mem_range->volume, nc*(3*up->num_species + 3), nc*(3*up->num_species + 3)); - up->xs = gkyl_nmat_cu_dev_new(mem_range->volume, nc*(3*up->num_species + 3), 1); + up->As = gkyl_nmat_cu_dev_new( + mem_range->volume, nc * (3 * up->num_species + 3), nc * (3 * up->num_species + 3) + ); + up->xs = gkyl_nmat_cu_dev_new(mem_range->volume, nc * (3 * up->num_species + 3), 1); up->mem = gkyl_nmat_linsolve_lu_cu_dev_new(up->As->num, up->As->nr); // Boolean for whether or not self-consistent EM fields are static @@ -258,10 +256,11 @@ gkyl_dg_calc_pkpm_em_coupling_cu_dev_new(const struct gkyl_basis* cbasis, up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_calc_pkpm_em_coupling *up_cu = (struct gkyl_dg_calc_pkpm_em_coupling*) gkyl_cu_malloc(sizeof(gkyl_dg_calc_pkpm_em_coupling)); + struct gkyl_dg_calc_pkpm_em_coupling *up_cu = + (struct gkyl_dg_calc_pkpm_em_coupling *)gkyl_cu_malloc(sizeof(gkyl_dg_calc_pkpm_em_coupling)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_calc_pkpm_em_coupling), GKYL_CU_MEMCPY_H2D); - dg_calc_pkpm_em_coupling_set_cu_dev_ptrs<<<1,1>>>(up_cu, b_type, cdim, poly_order); + dg_calc_pkpm_em_coupling_set_cu_dev_ptrs<<<1, 1> > >(up_cu, b_type, cdim, poly_order); // set parent on_dev pointer up->on_dev = up_cu; diff --git a/pkpm/zero/dg_calc_pkpm_vars.c b/pkpm/zero/dg_calc_pkpm_vars.c index 9663880d25..35167ae9f4 100644 --- a/pkpm/zero/dg_calc_pkpm_vars.c +++ b/pkpm/zero/dg_calc_pkpm_vars.c @@ -11,16 +11,19 @@ #include #include -gkyl_dg_calc_pkpm_vars* -gkyl_dg_calc_pkpm_vars_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, double limiter_fac, bool use_gpu) +gkyl_dg_calc_pkpm_vars *gkyl_dg_calc_pkpm_vars_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *cbasis, + const struct gkyl_range *mem_range, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_geom *geom, double limiter_fac, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { - return gkyl_dg_calc_pkpm_vars_cu_dev_new(conf_grid, cbasis, mem_range, wv_eqn, geom, limiter_fac); - } -#endif + if (use_gpu) { + return gkyl_dg_calc_pkpm_vars_cu_dev_new( + conf_grid, cbasis, mem_range, wv_eqn, geom, limiter_fac + ); + } +#endif gkyl_dg_calc_pkpm_vars *up = gkyl_malloc(sizeof(gkyl_dg_calc_pkpm_vars)); up->conf_grid = *conf_grid; @@ -37,14 +40,13 @@ gkyl_dg_calc_pkpm_vars_new(const struct gkyl_rect_grid *conf_grid, up->geom = gkyl_wave_geom_acquire(geom); // Limiter factor for relationship between slopes and cell average differences // By default, this factor is 1/sqrt(3) because cell_avg(f) = f0/sqrt(2^cdim) - // and a cell slope estimate from two adjacent cells is (for the x variation): + // and a cell slope estimate from two adjacent cells is (for the x variation): // integral(psi_1 [cell_avg(f_{i+1}) - cell_avg(f_{i})]*x) = sqrt(2^cdim)/sqrt(3)*[cell_avg(f_{i+1}) - cell_avg(f_{i})] // where psi_1 is the x cell slope basis in our orthonormal expansion psi_1 = sqrt(3)/sqrt(2^cdim)*x // This factor can be made smaller (larger) to increase (decrease) the diffusion from the slope limiter if (limiter_fac == 0.0) { up->limiter_fac = 0.5773502691896258; - } - else { + } else { up->limiter_fac = limiter_fac; } @@ -56,48 +58,49 @@ gkyl_dg_calc_pkpm_vars_new(const struct gkyl_rect_grid *conf_grid, up->pkpm_set = choose_pkpm_set_kern(b_type, cdim, poly_order); up->pkpm_copy = choose_pkpm_copy_kern(b_type, cdim, poly_order); up->pkpm_u_set = choose_pkpm_u_set_kern(b_type, cdim, poly_order); - up->pkpm_u_copy = choose_pkpm_u_copy_kern(b_type, cdim, poly_order); + up->pkpm_u_copy = choose_pkpm_u_copy_kern(b_type, cdim, poly_order); up->pkpm_pressure = choose_pkpm_pressure_kern(b_type, cdim, poly_order); up->pkpm_p_force = choose_pkpm_p_force_kern(b_type, cdim, poly_order); up->pkpm_source = choose_pkpm_source_kern(b_type, cdim, poly_order); up->pkpm_int = choose_pkpm_int_kern(b_type, cdim, poly_order); up->pkpm_io = choose_pkpm_io_kern(b_type, cdim, poly_order); // Fetch the kernels in each direction - for (int d=0; dpkpm_accel[d] = choose_pkpm_accel_kern(d, b_type, cdim, poly_order); up->pkpm_penalization[d] = choose_pkpm_penalization_kern(d, b_type, cdim, poly_order); up->pkpm_limiter[d] = choose_pkpm_limiter_kern(d, b_type, cdim, poly_order); } - // There are Ncomp*range->volume linear systems to be solved + // There are Ncomp*range->volume linear systems to be solved // 6 components: ux, uy, uz, div(p_par b)/rho, p_perp/rho, rho/p_perp - up->As = gkyl_nmat_new(up->Ncomp*mem_range->volume, nc, nc); - up->xs = gkyl_nmat_new(up->Ncomp*mem_range->volume, nc, 1); + up->As = gkyl_nmat_new(up->Ncomp * mem_range->volume, nc, nc); + up->xs = gkyl_nmat_new(up->Ncomp * mem_range->volume, nc, 1); up->mem = gkyl_nmat_linsolve_lu_new(up->As->num, up->As->nr); // Linear system for just solving for ux, uy, uz - up->As_u = gkyl_nmat_new(3*mem_range->volume, nc, nc); - up->xs_u = gkyl_nmat_new(3*mem_range->volume, nc, 1); + up->As_u = gkyl_nmat_new(3 * mem_range->volume, nc, nc); + up->xs_u = gkyl_nmat_new(3 * mem_range->volume, nc, 1); up->mem_u = gkyl_nmat_linsolve_lu_new(up->As_u->num, up->As_u->nr); up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void gkyl_dg_calc_pkpm_vars_advance(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - const struct gkyl_array* p_ij, const struct gkyl_array* pkpm_div_ppar, - struct gkyl_array* cell_avg_prim, struct gkyl_array* prim, struct gkyl_array* prim_surf) +void gkyl_dg_calc_pkpm_vars_advance( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, const struct gkyl_array *p_ij, + const struct gkyl_array *pkpm_div_ppar, struct gkyl_array *cell_avg_prim, struct gkyl_array *prim, + struct gkyl_array *prim_surf +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(prim)) { - return gkyl_dg_calc_pkpm_vars_advance_cu(up, - vlasov_pkpm_moms, euler_pkpm, - p_ij, pkpm_div_ppar, - cell_avg_prim, prim, prim_surf); + return gkyl_dg_calc_pkpm_vars_advance_cu( + up, vlasov_pkpm_moms, euler_pkpm, p_ij, pkpm_div_ppar, cell_avg_prim, prim, prim_surf + ); } #endif @@ -113,10 +116,11 @@ void gkyl_dg_calc_pkpm_vars_advance(struct gkyl_dg_calc_pkpm_vars *up, const double *p_ij_d = gkyl_array_cfetch(p_ij, loc); const double *pkpm_div_ppar_d = gkyl_array_cfetch(pkpm_div_ppar, loc); - int* cell_avg_prim_d = gkyl_array_fetch(cell_avg_prim, loc); + int *cell_avg_prim_d = gkyl_array_fetch(cell_avg_prim, loc); - cell_avg_prim_d[0] = up->pkpm_set(count, up->As, up->xs, - vlasov_pkpm_moms_d, euler_pkpm_d, p_ij_d, pkpm_div_ppar_d); + cell_avg_prim_d[0] = up->pkpm_set( + count, up->As, up->xs, vlasov_pkpm_moms_d, euler_pkpm_d, p_ij_d, pkpm_div_ppar_d + ); count += up->Ncomp; } @@ -131,8 +135,8 @@ void gkyl_dg_calc_pkpm_vars_advance(struct gkyl_dg_calc_pkpm_vars *up, while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&up->mem_range, iter.idx); - double* prim_d = gkyl_array_fetch(prim, loc); - double* prim_surf_d = gkyl_array_fetch(prim_surf, loc); + double *prim_d = gkyl_array_fetch(prim, loc); + double *prim_surf_d = gkyl_array_fetch(prim_surf, loc); up->pkpm_copy(count, up->xs, prim_d, prim_surf_d); @@ -140,15 +144,14 @@ void gkyl_dg_calc_pkpm_vars_advance(struct gkyl_dg_calc_pkpm_vars *up, } } -void gkyl_dg_calc_pkpm_vars_u(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - struct gkyl_array* cell_avg_prim, struct gkyl_array* pkpm_u) +void gkyl_dg_calc_pkpm_vars_u( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, struct gkyl_array *cell_avg_prim, struct gkyl_array *pkpm_u +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(pkpm_u)) { - return gkyl_dg_calc_pkpm_vars_u_cu(up, - vlasov_pkpm_moms, euler_pkpm, - cell_avg_prim, pkpm_u); + return gkyl_dg_calc_pkpm_vars_u_cu(up, vlasov_pkpm_moms, euler_pkpm, cell_avg_prim, pkpm_u); } #endif @@ -162,10 +165,10 @@ void gkyl_dg_calc_pkpm_vars_u(struct gkyl_dg_calc_pkpm_vars *up, const double *vlasov_pkpm_moms_d = gkyl_array_cfetch(vlasov_pkpm_moms, loc); const double *euler_pkpm_d = gkyl_array_cfetch(euler_pkpm, loc); - int* cell_avg_prim_d = gkyl_array_fetch(cell_avg_prim, loc); + int *cell_avg_prim_d = gkyl_array_fetch(cell_avg_prim, loc); - cell_avg_prim_d[0] = up->pkpm_u_set(count, up->As_u, up->xs_u, - vlasov_pkpm_moms_d, euler_pkpm_d); + cell_avg_prim_d[0] = + up->pkpm_u_set(count, up->As_u, up->xs_u, vlasov_pkpm_moms_d, euler_pkpm_d); count += 3; } @@ -180,7 +183,7 @@ void gkyl_dg_calc_pkpm_vars_u(struct gkyl_dg_calc_pkpm_vars *up, while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&up->mem_range, iter.idx); - double* pkpm_u_d = gkyl_array_fetch(pkpm_u, loc); + double *pkpm_u_d = gkyl_array_fetch(pkpm_u, loc); up->pkpm_u_copy(count, up->xs_u, pkpm_u_d); @@ -188,13 +191,14 @@ void gkyl_dg_calc_pkpm_vars_u(struct gkyl_dg_calc_pkpm_vars *up, } } -void gkyl_dg_calc_pkpm_vars_pressure(struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* bvar, const struct gkyl_array* vlasov_pkpm_moms, struct gkyl_array* p_ij) +void gkyl_dg_calc_pkpm_vars_pressure( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *bvar, const struct gkyl_array *vlasov_pkpm_moms, struct gkyl_array *p_ij +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(p_ij)) { - return gkyl_dg_calc_pkpm_vars_pressure_cu(up, conf_range, - bvar, vlasov_pkpm_moms, p_ij); + return gkyl_dg_calc_pkpm_vars_pressure_cu(up, conf_range, bvar, vlasov_pkpm_moms, p_ij); } #endif struct gkyl_range_iter iter; @@ -206,21 +210,23 @@ void gkyl_dg_calc_pkpm_vars_pressure(struct gkyl_dg_calc_pkpm_vars *up, const st const double *bvar_d = gkyl_array_cfetch(bvar, loc); const double *vlasov_pkpm_moms_d = gkyl_array_cfetch(vlasov_pkpm_moms, loc); - double* p_ij_d = gkyl_array_fetch(p_ij, loc); + double *p_ij_d = gkyl_array_fetch(p_ij, loc); up->pkpm_pressure(bvar_d, vlasov_pkpm_moms_d, p_ij_d); } } -void gkyl_dg_calc_pkpm_vars_accel(struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* prim_surf, const struct gkyl_array* prim, - const struct gkyl_array* bvar, const struct gkyl_array* div_b, const struct gkyl_array* nu, - struct gkyl_array* pkpm_accel) +void gkyl_dg_calc_pkpm_vars_accel( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *prim_surf, const struct gkyl_array *prim, const struct gkyl_array *bvar, + const struct gkyl_array *div_b, const struct gkyl_array *nu, struct gkyl_array *pkpm_accel +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(pkpm_accel)) { - return gkyl_dg_calc_pkpm_vars_accel_cu(up, conf_range, - prim_surf, prim, bvar, div_b, nu, pkpm_accel); + return gkyl_dg_calc_pkpm_vars_accel_cu( + up, conf_range, prim_surf, prim, bvar, div_b, nu, pkpm_accel + ); } #endif @@ -234,7 +240,7 @@ void gkyl_dg_calc_pkpm_vars_accel(struct gkyl_dg_calc_pkpm_vars *up, const struc long linc = gkyl_range_idx(conf_range, idxc); const double *prim_surf_c = gkyl_array_cfetch(prim_surf, linc); - + const double *prim_d = gkyl_array_cfetch(prim, linc); const double *bvar_d = gkyl_array_cfetch(bvar, linc); const double *div_b_d = gkyl_array_cfetch(div_b, linc); @@ -245,38 +251,39 @@ void gkyl_dg_calc_pkpm_vars_accel(struct gkyl_dg_calc_pkpm_vars *up, const struc // Compute T_perp/m div(b) and p_force up->pkpm_p_force(prim_d, div_b_d, pkpm_accel_d); - for (int dir=0; dirpkpm_accel[dir](up->conf_grid.dx, - prim_surf_l, prim_surf_c, prim_surf_r, - prim_d, bvar_d, nu_d, - pkpm_accel_d); + up->pkpm_accel[dir]( + up->conf_grid.dx, prim_surf_l, prim_surf_c, prim_surf_r, prim_d, bvar_d, nu_d, pkpm_accel_d + ); } } } -void gkyl_dg_calc_pkpm_vars_penalization(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *conf_range_ext, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* p_ij, - const struct gkyl_array* prim, const struct gkyl_array* euler_pkpm, - struct gkyl_array* pkpm_lax, struct gkyl_array* pkpm_penalization) +void gkyl_dg_calc_pkpm_vars_penalization( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *conf_range_ext, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *p_ij, const struct gkyl_array *prim, const struct gkyl_array *euler_pkpm, + struct gkyl_array *pkpm_lax, struct gkyl_array *pkpm_penalization +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(pkpm_penalization)) { - return gkyl_dg_calc_pkpm_vars_penalization_cu(up, - conf_range, conf_range_ext, - vlasov_pkpm_moms, p_ij, prim, euler_pkpm, - pkpm_lax, pkpm_penalization); + return gkyl_dg_calc_pkpm_vars_penalization_cu( + up, conf_range, conf_range_ext, vlasov_pkpm_moms, p_ij, prim, euler_pkpm, pkpm_lax, + pkpm_penalization + ); } #endif @@ -289,7 +296,7 @@ void gkyl_dg_calc_pkpm_vars_penalization(struct gkyl_dg_calc_pkpm_vars *up, gkyl_copy_int_arr(cdim, iter.idx, idxc); long linc = gkyl_range_idx(conf_range, idxc); const struct gkyl_wave_cell_geom *geom = gkyl_wave_geom_get(up->geom, idxc); - + const double *vlasov_pkpm_moms_d = gkyl_array_cfetch(vlasov_pkpm_moms, linc); const double *p_ij_d = gkyl_array_cfetch(p_ij, linc); const double *prim_d = gkyl_array_cfetch(prim, linc); @@ -298,33 +305,33 @@ void gkyl_dg_calc_pkpm_vars_penalization(struct gkyl_dg_calc_pkpm_vars *up, double *pkpm_lax_d = gkyl_array_fetch(pkpm_lax, linc); double *pkpm_penalization_d = gkyl_array_fetch(pkpm_penalization, linc); - for (int dir=0; dirpkpm_penalization[dir](up->tol, up->force_lax, up->wv_eqn, geom, - vlasov_pkpm_moms_l, vlasov_pkpm_moms_d, p_ij_l, p_ij_d, - prim_l, prim_d, euler_pkpm_l, euler_pkpm_d, - pkpm_lax_d, pkpm_penalization_d); + up->pkpm_penalization[dir]( + up->tol, up->force_lax, up->wv_eqn, geom, vlasov_pkpm_moms_l, vlasov_pkpm_moms_d, p_ij_l, + p_ij_d, prim_l, prim_d, euler_pkpm_l, euler_pkpm_d, pkpm_lax_d, pkpm_penalization_d + ); - // If the configuration-space index is at the local configuration space upper value, - // we are at the configuration space upper edge and we also need to evaluate the + // If the configuration-space index is at the local configuration space upper value, + // we are at the configuration space upper edge and we also need to evaluate the // penalization terms at the upper edge interface. We index into the ghost cells (linr) // and following the convention of each cell owning their lower surface expansion, - // the upper edge surface expansions are store in the ghost cells of the array. + // the upper edge surface expansions are store in the ghost cells of the array. if (idxc[dir] == conf_range->upper[dir]) { gkyl_copy_int_arr(cdim, idxc, idxr); - idxr[dir] = idxr[dir]+1; + idxr[dir] = idxr[dir] + 1; long linr = gkyl_range_idx(conf_range_ext, idxr); const struct gkyl_wave_cell_geom *geom_r = gkyl_wave_geom_get(up->geom, idxr); @@ -337,26 +344,29 @@ void gkyl_dg_calc_pkpm_vars_penalization(struct gkyl_dg_calc_pkpm_vars *up, double *pkpm_lax_r = gkyl_array_fetch(pkpm_lax, linr); double *pkpm_penalization_r = gkyl_array_fetch(pkpm_penalization, linr); - up->pkpm_penalization[dir](up->tol, up->force_lax, up->wv_eqn, geom_r, - vlasov_pkpm_moms_d, vlasov_pkpm_moms_r, p_ij_d, p_ij_r, - prim_d, prim_r, euler_pkpm_d, euler_pkpm_r, - pkpm_lax_r, pkpm_penalization_r); + up->pkpm_penalization[dir]( + up->tol, up->force_lax, up->wv_eqn, geom_r, vlasov_pkpm_moms_d, vlasov_pkpm_moms_r, + p_ij_d, p_ij_r, prim_d, prim_r, euler_pkpm_d, euler_pkpm_r, pkpm_lax_r, + pkpm_penalization_r + ); } } } } -void gkyl_dg_calc_pkpm_integrated_vars(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* vlasov_pkpm_moms, - const struct gkyl_array* euler_pkpm, const struct gkyl_array* prim, - struct gkyl_array* pkpm_int_vars) +void gkyl_dg_calc_pkpm_integrated_vars( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *euler_pkpm, + const struct gkyl_array *prim, struct gkyl_array *pkpm_int_vars +) { -// Check if more than one of the output arrays is on device? +// Check if more than one of the output arrays is on device? // Probably a better way to do this (JJ: 11/16/22) #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(pkpm_int_vars)) { - return gkyl_dg_calc_pkpm_integrated_vars_cu(up, conf_range, - vlasov_pkpm_moms, euler_pkpm, prim, pkpm_int_vars); + return gkyl_dg_calc_pkpm_integrated_vars_cu( + up, conf_range, vlasov_pkpm_moms, euler_pkpm, prim, pkpm_int_vars + ); } #endif @@ -368,21 +378,21 @@ void gkyl_dg_calc_pkpm_integrated_vars(struct gkyl_dg_calc_pkpm_vars *up, const double *vlasov_pkpm_moms_d = gkyl_array_cfetch(vlasov_pkpm_moms, loc); const double *euler_pkpm_d = gkyl_array_cfetch(euler_pkpm, loc); const double *prim_d = gkyl_array_cfetch(prim, loc); - + double *pkpm_int_vars_d = gkyl_array_fetch(pkpm_int_vars, loc); up->pkpm_int(vlasov_pkpm_moms_d, euler_pkpm_d, prim_d, pkpm_int_vars_d); } } -void gkyl_dg_calc_pkpm_vars_source(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* qmem, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - struct gkyl_array* rhs) +void gkyl_dg_calc_pkpm_vars_source( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *qmem, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, struct gkyl_array *rhs +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(rhs)) { - return gkyl_dg_calc_pkpm_vars_source_cu(up, conf_range, - qmem, vlasov_pkpm_moms, euler_pkpm, rhs); + return gkyl_dg_calc_pkpm_vars_source_cu(up, conf_range, qmem, vlasov_pkpm_moms, euler_pkpm, rhs); } #endif @@ -400,19 +410,20 @@ void gkyl_dg_calc_pkpm_vars_source(struct gkyl_dg_calc_pkpm_vars *up, } } -void gkyl_dg_calc_pkpm_vars_io(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* vlasov_pkpm_moms, - const struct gkyl_array* euler_pkpm, const struct gkyl_array* p_ij, - const struct gkyl_array* prim, const struct gkyl_array* pkpm_accel, - struct gkyl_array* fluid_io, struct gkyl_array* pkpm_vars_io) +void gkyl_dg_calc_pkpm_vars_io( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *euler_pkpm, + const struct gkyl_array *p_ij, const struct gkyl_array *prim, const struct gkyl_array *pkpm_accel, + struct gkyl_array *fluid_io, struct gkyl_array *pkpm_vars_io +) { -// Check if more than one of the output arrays is on device? +// Check if more than one of the output arrays is on device? // Probably a better way to do this (JJ: 11/16/22) #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(pkpm_vars_io)) { - return gkyl_dg_calc_pkpm_vars_io_cu(up, conf_range, - vlasov_pkpm_moms, euler_pkpm, p_ij, prim, pkpm_accel, - fluid_io, pkpm_vars_io); + return gkyl_dg_calc_pkpm_vars_io_cu( + up, conf_range, vlasov_pkpm_moms, euler_pkpm, p_ij, prim, pkpm_accel, fluid_io, pkpm_vars_io + ); } #endif @@ -426,23 +437,24 @@ void gkyl_dg_calc_pkpm_vars_io(struct gkyl_dg_calc_pkpm_vars *up, const double *p_ij_d = gkyl_array_cfetch(p_ij, loc); const double *prim_d = gkyl_array_cfetch(prim, loc); const double *pkpm_accel_d = gkyl_array_cfetch(pkpm_accel, loc); - + double *fluid_io_d = gkyl_array_fetch(fluid_io, loc); double *pkpm_vars_io_d = gkyl_array_fetch(pkpm_vars_io, loc); - up->pkpm_io(vlasov_pkpm_moms_d, euler_pkpm_d, p_ij_d, prim_d, pkpm_accel_d, - fluid_io_d, pkpm_vars_io_d); + up->pkpm_io( + vlasov_pkpm_moms_d, euler_pkpm_d, p_ij_d, prim_d, pkpm_accel_d, fluid_io_d, pkpm_vars_io_d + ); } } -void gkyl_dg_calc_pkpm_vars_limiter(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* prim, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* p_ij, - struct gkyl_array* fluid) +void gkyl_dg_calc_pkpm_vars_limiter( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *prim, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *p_ij, struct gkyl_array *fluid +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(fluid)) { - return gkyl_dg_calc_pkpm_vars_limiter_cu(up, conf_range, - prim, vlasov_pkpm_moms, p_ij, fluid); + return gkyl_dg_calc_pkpm_vars_limiter_cu(up, conf_range, prim, vlasov_pkpm_moms, p_ij, fluid); } #endif int cdim = up->cdim; @@ -460,13 +472,14 @@ void gkyl_dg_calc_pkpm_vars_limiter(struct gkyl_dg_calc_pkpm_vars *up, const double *p_ij_c = gkyl_array_cfetch(p_ij, linc); double *fluid_c = gkyl_array_fetch(fluid, linc); - for (int dir=0; dirpkpm_limiter[dir](up->limiter_fac, up->wv_eqn, geom, prim_c, - vlasov_pkpm_moms_l, vlasov_pkpm_moms_c, vlasov_pkpm_moms_r, - p_ij_l, p_ij_c, p_ij_r, - fluid_l, fluid_c, fluid_r); + up->pkpm_limiter[dir]( + up->limiter_fac, up->wv_eqn, geom, prim_c, vlasov_pkpm_moms_l, vlasov_pkpm_moms_c, + vlasov_pkpm_moms_r, p_ij_l, p_ij_c, p_ij_r, fluid_l, fluid_c, fluid_r + ); } } } @@ -497,8 +510,9 @@ void gkyl_dg_calc_pkpm_vars_release(gkyl_dg_calc_pkpm_vars *up) gkyl_nmat_release(up->As_u); gkyl_nmat_release(up->xs_u); gkyl_nmat_linsolve_lu_release(up->mem_u); - - if (GKYL_IS_CU_ALLOC(up->flags)) + + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/pkpm/zero/dg_calc_pkpm_vars_cu.cu b/pkpm/zero/dg_calc_pkpm_vars_cu.cu index e333a4e245..e4c9d2f9a9 100644 --- a/pkpm/zero/dg_calc_pkpm_vars_cu.cu +++ b/pkpm/zero/dg_calc_pkpm_vars_cu.cu @@ -15,19 +15,17 @@ extern "C" { #include } -__global__ static void -gkyl_dg_calc_pkpm_vars_set_cu_kernel(gkyl_dg_calc_pkpm_vars* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - const struct gkyl_array* p_ij, const struct gkyl_array* pkpm_div_ppar, - struct gkyl_array* cell_avg_prim) +__global__ static void gkyl_dg_calc_pkpm_vars_set_cu_kernel( + gkyl_dg_calc_pkpm_vars *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, const struct gkyl_array *p_ij, + const struct gkyl_array *pkpm_div_ppar, struct gkyl_array *cell_avg_prim +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -37,31 +35,29 @@ gkyl_dg_calc_pkpm_vars_set_cu_kernel(gkyl_dg_calc_pkpm_vars* up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->Ncomp; + long count = linc1 * up->Ncomp; - const double *vlasov_pkpm_moms_d = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms, loc); - const double *euler_pkpm_d = (const double*) gkyl_array_cfetch(euler_pkpm, loc); - const double *p_ij_d = (const double*) gkyl_array_cfetch(p_ij, loc); - const double *pkpm_div_ppar_d = (const double*) gkyl_array_cfetch(pkpm_div_ppar, loc); + const double *vlasov_pkpm_moms_d = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms, loc); + const double *euler_pkpm_d = (const double *)gkyl_array_cfetch(euler_pkpm, loc); + const double *p_ij_d = (const double *)gkyl_array_cfetch(p_ij, loc); + const double *pkpm_div_ppar_d = (const double *)gkyl_array_cfetch(pkpm_div_ppar, loc); - int* cell_avg_prim_d = (int*) gkyl_array_fetch(cell_avg_prim, loc); + int *cell_avg_prim_d = (int *)gkyl_array_fetch(cell_avg_prim, loc); - cell_avg_prim_d[0] = up->pkpm_set(count, As, xs, - vlasov_pkpm_moms_d, euler_pkpm_d, p_ij_d, pkpm_div_ppar_d); + cell_avg_prim_d[0] = + up->pkpm_set(count, As, xs, vlasov_pkpm_moms_d, euler_pkpm_d, p_ij_d, pkpm_div_ppar_d); } } -__global__ static void -gkyl_dg_calc_pkpm_vars_copy_cu_kernel(gkyl_dg_calc_pkpm_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, - struct gkyl_array* prim, struct gkyl_array* prim_surf) +__global__ static void gkyl_dg_calc_pkpm_vars_copy_cu_kernel( + gkyl_dg_calc_pkpm_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + struct gkyl_array *prim, struct gkyl_array *prim_surf +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -71,50 +67,50 @@ gkyl_dg_calc_pkpm_vars_copy_cu_kernel(gkyl_dg_calc_pkpm_vars* up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->Ncomp; + long count = linc1 * up->Ncomp; - double* prim_d = (double*) gkyl_array_fetch(prim, loc); - double* prim_surf_d = (double*) gkyl_array_fetch(prim_surf, loc); + double *prim_d = (double *)gkyl_array_fetch(prim, loc); + double *prim_surf_d = (double *)gkyl_array_fetch(prim_surf, loc); up->pkpm_copy(count, xs, prim_d, prim_surf_d); } } // Host-side wrapper for pkpm primitive variable calculation -void gkyl_dg_calc_pkpm_vars_advance_cu(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - const struct gkyl_array* p_ij, const struct gkyl_array* pkpm_div_ppar, - struct gkyl_array* cell_avg_prim, struct gkyl_array* prim, struct gkyl_array* prim_surf) +void gkyl_dg_calc_pkpm_vars_advance_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, const struct gkyl_array *p_ij, + const struct gkyl_array *pkpm_div_ppar, struct gkyl_array *cell_avg_prim, struct gkyl_array *prim, + struct gkyl_array *prim_surf +) { struct gkyl_range conf_range = up->mem_range; - - gkyl_dg_calc_pkpm_vars_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, - vlasov_pkpm_moms->on_dev, euler_pkpm->on_dev, - p_ij->on_dev, pkpm_div_ppar->on_dev, - cell_avg_prim->on_dev); + + gkyl_dg_calc_pkpm_vars_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, vlasov_pkpm_moms->on_dev, + euler_pkpm->on_dev, p_ij->on_dev, pkpm_div_ppar->on_dev, cell_avg_prim->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_dg_calc_pkpm_vars_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, prim->on_dev, prim_surf->on_dev); + gkyl_dg_calc_pkpm_vars_copy_cu_kernel<< > >( + up->on_dev, up->xs->on_dev, conf_range, prim->on_dev, prim_surf->on_dev + ); } -__global__ static void -gkyl_dg_calc_pkpm_vars_u_set_cu_kernel(gkyl_dg_calc_pkpm_vars* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - struct gkyl_array* cell_avg_prim) +__global__ static void gkyl_dg_calc_pkpm_vars_u_set_cu_kernel( + gkyl_dg_calc_pkpm_vars *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, struct gkyl_array *cell_avg_prim +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -124,29 +120,26 @@ gkyl_dg_calc_pkpm_vars_u_set_cu_kernel(gkyl_dg_calc_pkpm_vars* up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*3; + long count = linc1 * 3; - const double *vlasov_pkpm_moms_d = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms, loc); - const double *euler_pkpm_d = (const double*) gkyl_array_cfetch(euler_pkpm, loc); + const double *vlasov_pkpm_moms_d = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms, loc); + const double *euler_pkpm_d = (const double *)gkyl_array_cfetch(euler_pkpm, loc); - int* cell_avg_prim_d = (int*) gkyl_array_fetch(cell_avg_prim, loc); + int *cell_avg_prim_d = (int *)gkyl_array_fetch(cell_avg_prim, loc); - cell_avg_prim_d[0] = up->pkpm_u_set(count, As, xs, - vlasov_pkpm_moms_d, euler_pkpm_d); + cell_avg_prim_d[0] = up->pkpm_u_set(count, As, xs, vlasov_pkpm_moms_d, euler_pkpm_d); } } -__global__ static void -gkyl_dg_calc_pkpm_vars_u_copy_cu_kernel(gkyl_dg_calc_pkpm_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, - struct gkyl_array* pkpm_u) +__global__ static void gkyl_dg_calc_pkpm_vars_u_copy_cu_kernel( + gkyl_dg_calc_pkpm_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + struct gkyl_array *pkpm_u +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -156,45 +149,46 @@ gkyl_dg_calc_pkpm_vars_u_copy_cu_kernel(gkyl_dg_calc_pkpm_vars* up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*3; + long count = linc1 * 3; - double* pkpm_u_d = (double*) gkyl_array_fetch(pkpm_u, loc); + double *pkpm_u_d = (double *)gkyl_array_fetch(pkpm_u, loc); up->pkpm_u_copy(count, xs, pkpm_u_d); } } // Host-side wrapper for pkpm flow velocity calculation -void gkyl_dg_calc_pkpm_vars_u_cu(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - struct gkyl_array* cell_avg_prim, struct gkyl_array* pkpm_u) +void gkyl_dg_calc_pkpm_vars_u_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, struct gkyl_array *cell_avg_prim, struct gkyl_array *pkpm_u +) { struct gkyl_range conf_range = up->mem_range; - - gkyl_dg_calc_pkpm_vars_u_set_cu_kernel<<>>(up->on_dev, - up->As_u->on_dev, up->xs_u->on_dev, conf_range, - vlasov_pkpm_moms->on_dev, euler_pkpm->on_dev, - cell_avg_prim->on_dev); + + gkyl_dg_calc_pkpm_vars_u_set_cu_kernel<< > >( + up->on_dev, up->As_u->on_dev, up->xs_u->on_dev, conf_range, vlasov_pkpm_moms->on_dev, + euler_pkpm->on_dev, cell_avg_prim->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem_u, up->As_u, up->xs_u); assert(status); } - gkyl_dg_calc_pkpm_vars_u_copy_cu_kernel<<>>(up->on_dev, - up->xs_u->on_dev, conf_range, pkpm_u->on_dev); + gkyl_dg_calc_pkpm_vars_u_copy_cu_kernel<< > >( + up->on_dev, up->xs_u->on_dev, conf_range, pkpm_u->on_dev + ); } -__global__ void -gkyl_calc_pkpm_vars_pressure_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, - const struct gkyl_array* bvar, const struct gkyl_array* vlasov_pkpm_moms, struct gkyl_array* p_ij) -{ +__global__ void gkyl_calc_pkpm_vars_pressure_cu_kernel( + struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, const struct gkyl_array *bvar, + const struct gkyl_array *vlasov_pkpm_moms, struct gkyl_array *p_ij +) +{ int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -204,36 +198,37 @@ gkyl_calc_pkpm_vars_pressure_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, struct // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *bvar_d = (const double*) gkyl_array_cfetch(bvar, loc); - const double *vlasov_pkpm_moms_d = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms, loc); + const double *bvar_d = (const double *)gkyl_array_cfetch(bvar, loc); + const double *vlasov_pkpm_moms_d = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms, loc); - double *p_ij_d = (double*) gkyl_array_fetch(p_ij, loc); + double *p_ij_d = (double *)gkyl_array_fetch(p_ij, loc); up->pkpm_pressure(bvar_d, vlasov_pkpm_moms_d, p_ij_d); } } // Host-side wrapper for pkpm pressure calculation -void gkyl_dg_calc_pkpm_vars_pressure_cu(struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* bvar, const struct gkyl_array* vlasov_pkpm_moms, struct gkyl_array* p_ij) +void gkyl_dg_calc_pkpm_vars_pressure_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *bvar, const struct gkyl_array *vlasov_pkpm_moms, struct gkyl_array *p_ij +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_calc_pkpm_vars_pressure_cu_kernel<<>>(up->on_dev, *conf_range, - bvar->on_dev, vlasov_pkpm_moms->on_dev, p_ij->on_dev); + gkyl_calc_pkpm_vars_pressure_cu_kernel<< > >( + up->on_dev, *conf_range, bvar->on_dev, vlasov_pkpm_moms->on_dev, p_ij->on_dev + ); } -__global__ void -gkyl_dg_calc_pkpm_vars_accel_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, - const struct gkyl_array* prim_surf, const struct gkyl_array* prim, - const struct gkyl_array* bvar, const struct gkyl_array* div_b, const struct gkyl_array* nu, - struct gkyl_array* pkpm_accel) +__global__ void gkyl_dg_calc_pkpm_vars_accel_cu_kernel( + struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, + const struct gkyl_array *prim_surf, const struct gkyl_array *prim, const struct gkyl_array *bvar, + const struct gkyl_array *div_b, const struct gkyl_array *nu, struct gkyl_array *pkpm_accel +) { int cdim = up->cdim; int idxl[GKYL_MAX_DIM], idxc[GKYL_MAX_DIM], idxr[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -243,66 +238,64 @@ gkyl_dg_calc_pkpm_vars_accel_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, struct // linc will have jumps in it to jump over ghost cells long linc = gkyl_range_idx(&conf_range, idxc); - const double *prim_surf_c = (const double*) gkyl_array_cfetch(prim_surf, linc); + const double *prim_surf_c = (const double *)gkyl_array_cfetch(prim_surf, linc); - const double *prim_d = (const double*) gkyl_array_cfetch(prim, linc); - const double *bvar_d = (const double*) gkyl_array_cfetch(bvar, linc); - const double *div_b_d = (const double*) gkyl_array_cfetch(div_b, linc); - const double *nu_d = (const double*) gkyl_array_cfetch(nu, linc); + const double *prim_d = (const double *)gkyl_array_cfetch(prim, linc); + const double *bvar_d = (const double *)gkyl_array_cfetch(bvar, linc); + const double *div_b_d = (const double *)gkyl_array_cfetch(div_b, linc); + const double *nu_d = (const double *)gkyl_array_cfetch(nu, linc); - double *pkpm_accel_d = (double*) gkyl_array_fetch(pkpm_accel, linc); + double *pkpm_accel_d = (double *)gkyl_array_fetch(pkpm_accel, linc); // Compute T_perp/m div(b) and p_force up->pkpm_p_force(prim_d, div_b_d, pkpm_accel_d); - for (int dir=0; dirpkpm_accel[dir](up->conf_grid.dx, - prim_surf_l, prim_surf_c, prim_surf_r, - prim_d, bvar_d, nu_d, - pkpm_accel_d); + const double *prim_surf_l = (const double *)gkyl_array_cfetch(prim_surf, linl); + const double *prim_surf_r = (const double *)gkyl_array_cfetch(prim_surf, linr); + + up->pkpm_accel[dir]( + up->conf_grid.dx, prim_surf_l, prim_surf_c, prim_surf_r, prim_d, bvar_d, nu_d, pkpm_accel_d + ); } } } // Host-side wrapper for pkpm acceleration variable calculations with averaging for gradients -void -gkyl_dg_calc_pkpm_vars_accel_cu(struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* prim_surf, const struct gkyl_array* prim, - const struct gkyl_array* bvar, const struct gkyl_array* div_b, const struct gkyl_array* nu, - struct gkyl_array* pkpm_accel) +void gkyl_dg_calc_pkpm_vars_accel_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *prim_surf, const struct gkyl_array *prim, const struct gkyl_array *bvar, + const struct gkyl_array *div_b, const struct gkyl_array *nu, struct gkyl_array *pkpm_accel +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_pkpm_vars_accel_cu_kernel<<>>(up->on_dev, *conf_range, - prim_surf->on_dev, prim->on_dev, - bvar->on_dev, div_b->on_dev, nu->on_dev, - pkpm_accel->on_dev); + gkyl_dg_calc_pkpm_vars_accel_cu_kernel<< > >( + up->on_dev, *conf_range, prim_surf->on_dev, prim->on_dev, bvar->on_dev, div_b->on_dev, + nu->on_dev, pkpm_accel->on_dev + ); } -__global__ void -gkyl_dg_calc_pkpm_vars_penalization_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, - struct gkyl_range conf_range, struct gkyl_range conf_range_ext, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* p_ij, - const struct gkyl_array* prim, const struct gkyl_array* euler_pkpm, - struct gkyl_array* pkpm_lax, struct gkyl_array* pkpm_penalization) +__global__ void gkyl_dg_calc_pkpm_vars_penalization_cu_kernel( + struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, struct gkyl_range conf_range_ext, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *p_ij, + const struct gkyl_array *prim, const struct gkyl_array *euler_pkpm, struct gkyl_array *pkpm_lax, + struct gkyl_array *pkpm_penalization +) { int cdim = up->cdim; int idxl[GKYL_MAX_DIM], idxc[GKYL_MAX_DIM], idxr[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -313,90 +306,91 @@ gkyl_dg_calc_pkpm_vars_penalization_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, // convert back to a linear index on the super-range (with ghost cells) // linc will have jumps in it to jump over ghost cells long linc = gkyl_range_idx(&conf_range, idxc); - - const double *vlasov_pkpm_moms_d = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms, linc); - const double *p_ij_d = (const double*) gkyl_array_cfetch(p_ij, linc); - const double *prim_d = (const double*) gkyl_array_cfetch(prim, linc); - const double *euler_pkpm_d = (const double*) gkyl_array_cfetch(euler_pkpm, linc); - double *pkpm_lax_d = (double*) gkyl_array_fetch(pkpm_lax, linc); - double *pkpm_penalization_d = (double*) gkyl_array_fetch(pkpm_penalization, linc); + const double *vlasov_pkpm_moms_d = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms, linc); + const double *p_ij_d = (const double *)gkyl_array_cfetch(p_ij, linc); + const double *prim_d = (const double *)gkyl_array_cfetch(prim, linc); + const double *euler_pkpm_d = (const double *)gkyl_array_cfetch(euler_pkpm, linc); - for (int dir=0; dirpkpm_penalization[dir](up->tol, up->force_lax, up->wv_eqn, geom, - vlasov_pkpm_moms_l, vlasov_pkpm_moms_d, p_ij_l, p_ij_d, - prim_l, prim_d, euler_pkpm_l, euler_pkpm_d, - pkpm_lax_d, pkpm_penalization_d); + up->pkpm_penalization[dir]( + up->tol, up->force_lax, up->wv_eqn, geom, vlasov_pkpm_moms_l, vlasov_pkpm_moms_d, p_ij_l, + p_ij_d, prim_l, prim_d, euler_pkpm_l, euler_pkpm_d, pkpm_lax_d, pkpm_penalization_d + ); - // If the configuration-space index is at the local configuration space upper value, - // we are at the configuration space upper edge and we also need to evaluate the + // If the configuration-space index is at the local configuration space upper value, + // we are at the configuration space upper edge and we also need to evaluate the // penalization terms at the upper edge interface. We index into the ghost cells (linr) // and following the convention of each cell owning their lower surface expansion, - // the upper edge surface expansions are store in the ghost cells of the array. + // the upper edge surface expansions are store in the ghost cells of the array. if (idxc[dir] == conf_range.upper[dir]) { gkyl_copy_int_arr(cdim, idxc, idxr); - idxr[dir] = idxr[dir]+1; + idxr[dir] = idxr[dir] + 1; long linr = gkyl_range_idx(&conf_range_ext, idxr); const struct gkyl_wave_cell_geom *geom_r = gkyl_wave_geom_get(up->geom, idxr); - const double *vlasov_pkpm_moms_r = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms, linr); - const double *p_ij_r = (const double*) gkyl_array_cfetch(p_ij, linr); - const double *prim_r = (const double*) gkyl_array_cfetch(prim, linr); - const double *euler_pkpm_r = (const double*) gkyl_array_cfetch(euler_pkpm, linr); + const double *vlasov_pkpm_moms_r = + (const double *)gkyl_array_cfetch(vlasov_pkpm_moms, linr); + const double *p_ij_r = (const double *)gkyl_array_cfetch(p_ij, linr); + const double *prim_r = (const double *)gkyl_array_cfetch(prim, linr); + const double *euler_pkpm_r = (const double *)gkyl_array_cfetch(euler_pkpm, linr); - double *pkpm_lax_r = (double*) gkyl_array_fetch(pkpm_lax, linr); - double *pkpm_penalization_r = (double*) gkyl_array_fetch(pkpm_penalization, linr); + double *pkpm_lax_r = (double *)gkyl_array_fetch(pkpm_lax, linr); + double *pkpm_penalization_r = (double *)gkyl_array_fetch(pkpm_penalization, linr); - up->pkpm_penalization[dir](up->tol, up->force_lax, up->wv_eqn, geom_r, - vlasov_pkpm_moms_d, vlasov_pkpm_moms_r, p_ij_d, p_ij_r, - prim_d, prim_r, euler_pkpm_d, euler_pkpm_r, - pkpm_lax_r, pkpm_penalization_r); + up->pkpm_penalization[dir]( + up->tol, up->force_lax, up->wv_eqn, geom_r, vlasov_pkpm_moms_d, vlasov_pkpm_moms_r, + p_ij_d, p_ij_r, prim_d, prim_r, euler_pkpm_d, euler_pkpm_r, pkpm_lax_r, + pkpm_penalization_r + ); } } } } // Host-side wrapper for surface expansions of pkpm penalization variables calculation -void -gkyl_dg_calc_pkpm_vars_penalization_cu(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *conf_range_ext, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* p_ij, - const struct gkyl_array* prim, const struct gkyl_array* euler_pkpm, - struct gkyl_array* pkpm_lax, struct gkyl_array* pkpm_penalization) +void gkyl_dg_calc_pkpm_vars_penalization_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *conf_range_ext, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *p_ij, const struct gkyl_array *prim, const struct gkyl_array *euler_pkpm, + struct gkyl_array *pkpm_lax, struct gkyl_array *pkpm_penalization +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_pkpm_vars_penalization_cu_kernel<<>>(up->on_dev, - *conf_range, *conf_range_ext, - vlasov_pkpm_moms->on_dev, p_ij->on_dev, prim->on_dev, euler_pkpm->on_dev, - pkpm_lax->on_dev, pkpm_penalization->on_dev); + gkyl_dg_calc_pkpm_vars_penalization_cu_kernel<< > >( + up->on_dev, *conf_range, *conf_range_ext, vlasov_pkpm_moms->on_dev, p_ij->on_dev, prim->on_dev, + euler_pkpm->on_dev, pkpm_lax->on_dev, pkpm_penalization->on_dev + ); } -__global__ void -gkyl_dg_calc_pkpm_integrated_vars_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - const struct gkyl_array* prim, struct gkyl_array* int_pkpm_vars) +__global__ void gkyl_dg_calc_pkpm_integrated_vars_cu_kernel( + struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *euler_pkpm, + const struct gkyl_array *prim, struct gkyl_array *int_pkpm_vars +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -406,39 +400,40 @@ gkyl_dg_calc_pkpm_integrated_vars_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, s // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *vlasov_pkpm_moms_d = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms, loc); - const double *euler_pkpm_d = (const double*) gkyl_array_cfetch(euler_pkpm, loc); - const double *prim_d = (const double*) gkyl_array_cfetch(prim, loc); + const double *vlasov_pkpm_moms_d = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms, loc); + const double *euler_pkpm_d = (const double *)gkyl_array_cfetch(euler_pkpm, loc); + const double *prim_d = (const double *)gkyl_array_cfetch(prim, loc); - double *int_pkpm_vars_d = (double*) gkyl_array_fetch(int_pkpm_vars, loc); + double *int_pkpm_vars_d = (double *)gkyl_array_fetch(int_pkpm_vars, loc); up->pkpm_int(vlasov_pkpm_moms_d, euler_pkpm_d, prim_d, int_pkpm_vars_d); } } // Host-side wrapper for pkpm integrated variables calculation -void -gkyl_dg_calc_pkpm_integrated_vars_cu(struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - const struct gkyl_array* prim, struct gkyl_array* int_pkpm_vars) +void gkyl_dg_calc_pkpm_integrated_vars_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *euler_pkpm, + const struct gkyl_array *prim, struct gkyl_array *int_pkpm_vars +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_pkpm_integrated_vars_cu_kernel<<>>(up->on_dev, *conf_range, - vlasov_pkpm_moms->on_dev, euler_pkpm->on_dev, prim->on_dev, - int_pkpm_vars->on_dev); + gkyl_dg_calc_pkpm_integrated_vars_cu_kernel<< > >( + up->on_dev, *conf_range, vlasov_pkpm_moms->on_dev, euler_pkpm->on_dev, prim->on_dev, + int_pkpm_vars->on_dev + ); } -__global__ void -gkyl_dg_calc_pkpm_vars_source_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, - const struct gkyl_array* qmem, const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - struct gkyl_array* rhs) +__global__ void gkyl_dg_calc_pkpm_vars_source_cu_kernel( + struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, const struct gkyl_array *qmem, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *euler_pkpm, + struct gkyl_array *rhs +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -448,41 +443,40 @@ gkyl_dg_calc_pkpm_vars_source_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, struc // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *qmem_d = (const double*) gkyl_array_cfetch(qmem, loc); - const double *vlasov_pkpm_moms_d = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms, loc); - const double *euler_pkpm_d = (const double*) gkyl_array_cfetch(euler_pkpm, loc); + const double *qmem_d = (const double *)gkyl_array_cfetch(qmem, loc); + const double *vlasov_pkpm_moms_d = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms, loc); + const double *euler_pkpm_d = (const double *)gkyl_array_cfetch(euler_pkpm, loc); - double *rhs_d = (double*) gkyl_array_fetch(rhs, loc); + double *rhs_d = (double *)gkyl_array_fetch(rhs, loc); up->pkpm_source(qmem_d, vlasov_pkpm_moms_d, euler_pkpm_d, rhs_d); } } // Host-side wrapper for pkpm source term calculations -void -gkyl_dg_calc_pkpm_vars_source_cu(struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* qmem, const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - struct gkyl_array* rhs) +void gkyl_dg_calc_pkpm_vars_source_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *qmem, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, struct gkyl_array *rhs +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_pkpm_vars_source_cu_kernel<<>>(up->on_dev, *conf_range, - qmem->on_dev, vlasov_pkpm_moms->on_dev, euler_pkpm->on_dev, - rhs->on_dev); + gkyl_dg_calc_pkpm_vars_source_cu_kernel<< > >( + up->on_dev, *conf_range, qmem->on_dev, vlasov_pkpm_moms->on_dev, euler_pkpm->on_dev, rhs->on_dev + ); } -__global__ void -gkyl_dg_calc_pkpm_vars_io_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, - const struct gkyl_array* vlasov_pkpm_moms, - const struct gkyl_array* euler_pkpm, const struct gkyl_array* p_ij, - const struct gkyl_array* prim, const struct gkyl_array* pkpm_accel, - struct gkyl_array* fluid_io, struct gkyl_array* pkpm_vars_io) +__global__ void gkyl_dg_calc_pkpm_vars_io_cu_kernel( + struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *euler_pkpm, + const struct gkyl_array *p_ij, const struct gkyl_array *prim, const struct gkyl_array *pkpm_accel, + struct gkyl_array *fluid_io, struct gkyl_array *pkpm_vars_io +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -492,46 +486,45 @@ gkyl_dg_calc_pkpm_vars_io_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, struct gk // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *vlasov_pkpm_moms_d = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms, loc); - const double *euler_pkpm_d = (const double*) gkyl_array_cfetch(euler_pkpm, loc); - const double *p_ij_d = (const double*) gkyl_array_cfetch(p_ij, loc); - const double *prim_d = (const double*) gkyl_array_cfetch(prim, loc); - const double *pkpm_accel_d = (const double*) gkyl_array_cfetch(pkpm_accel, loc); - - double *fluid_io_d = (double*) gkyl_array_fetch(fluid_io, loc); - double *pkpm_vars_io_d = (double*) gkyl_array_fetch(pkpm_vars_io, loc); - up->pkpm_io(vlasov_pkpm_moms_d, euler_pkpm_d, p_ij_d, prim_d, pkpm_accel_d, - fluid_io_d, pkpm_vars_io_d); + const double *vlasov_pkpm_moms_d = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms, loc); + const double *euler_pkpm_d = (const double *)gkyl_array_cfetch(euler_pkpm, loc); + const double *p_ij_d = (const double *)gkyl_array_cfetch(p_ij, loc); + const double *prim_d = (const double *)gkyl_array_cfetch(prim, loc); + const double *pkpm_accel_d = (const double *)gkyl_array_cfetch(pkpm_accel, loc); + + double *fluid_io_d = (double *)gkyl_array_fetch(fluid_io, loc); + double *pkpm_vars_io_d = (double *)gkyl_array_fetch(pkpm_vars_io, loc); + up->pkpm_io( + vlasov_pkpm_moms_d, euler_pkpm_d, p_ij_d, prim_d, pkpm_accel_d, fluid_io_d, pkpm_vars_io_d + ); } } // Host-side wrapper for pkpm io. Computes conserved variables and copies primitive and acceleration variables to output array -void -gkyl_dg_calc_pkpm_vars_io_cu(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* vlasov_pkpm_moms, - const struct gkyl_array* euler_pkpm, const struct gkyl_array* p_ij, - const struct gkyl_array* prim, const struct gkyl_array* pkpm_accel, - struct gkyl_array* fluid_io, struct gkyl_array* pkpm_vars_io) +void gkyl_dg_calc_pkpm_vars_io_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *euler_pkpm, + const struct gkyl_array *p_ij, const struct gkyl_array *prim, const struct gkyl_array *pkpm_accel, + struct gkyl_array *fluid_io, struct gkyl_array *pkpm_vars_io +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_pkpm_vars_io_cu_kernel<<>>(up->on_dev, *conf_range, - vlasov_pkpm_moms->on_dev, euler_pkpm->on_dev, p_ij->on_dev, prim->on_dev, pkpm_accel->on_dev, - fluid_io->on_dev, pkpm_vars_io->on_dev); + gkyl_dg_calc_pkpm_vars_io_cu_kernel<< > >( + up->on_dev, *conf_range, vlasov_pkpm_moms->on_dev, euler_pkpm->on_dev, p_ij->on_dev, + prim->on_dev, pkpm_accel->on_dev, fluid_io->on_dev, pkpm_vars_io->on_dev + ); } -__global__ void -gkyl_dg_calc_pkpm_vars_limiter_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, - struct gkyl_range conf_range, const struct gkyl_array* prim, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* p_ij, - struct gkyl_array* fluid) +__global__ void gkyl_dg_calc_pkpm_vars_limiter_cu_kernel( + struct gkyl_dg_calc_pkpm_vars *up, struct gkyl_range conf_range, const struct gkyl_array *prim, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *p_ij, struct gkyl_array *fluid +) { int cdim = up->cdim; int idxl[GKYL_MAX_DIM], idxc[GKYL_MAX_DIM], idxr[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -542,79 +535,82 @@ gkyl_dg_calc_pkpm_vars_limiter_cu_kernel(struct gkyl_dg_calc_pkpm_vars *up, // linc will have jumps in it to jump over ghost cells long linc = gkyl_range_idx(&conf_range, idxc); - const double *prim_c = (const double*) gkyl_array_cfetch(prim, linc); - const double *vlasov_pkpm_moms_c = (const double*) gkyl_array_cfetch(vlasov_pkpm_moms, linc); - const double *p_ij_c = (const double*) gkyl_array_cfetch(p_ij, linc); + const double *prim_c = (const double *)gkyl_array_cfetch(prim, linc); + const double *vlasov_pkpm_moms_c = (const double *)gkyl_array_cfetch(vlasov_pkpm_moms, linc); + const double *p_ij_c = (const double *)gkyl_array_cfetch(p_ij, linc); - double *fluid_c = (double*) gkyl_array_fetch(fluid, linc); - for (int dir=0; dirpkpm_limiter[dir](up->limiter_fac, up->wv_eqn, geom, prim_c, - vlasov_pkpm_moms_l, vlasov_pkpm_moms_c, vlasov_pkpm_moms_r, - p_ij_l, p_ij_c, p_ij_r, - fluid_l, fluid_c, fluid_r); + up->pkpm_limiter[dir]( + up->limiter_fac, up->wv_eqn, geom, prim_c, vlasov_pkpm_moms_l, vlasov_pkpm_moms_c, + vlasov_pkpm_moms_r, p_ij_l, p_ij_c, p_ij_r, fluid_l, fluid_c, fluid_r + ); } } } // Host-side wrapper for slope limiter of fluid variables -void -gkyl_dg_calc_pkpm_vars_limiter_cu(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* prim, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* p_ij, - struct gkyl_array* fluid) +void gkyl_dg_calc_pkpm_vars_limiter_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *prim, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *p_ij, struct gkyl_array *fluid +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_pkpm_vars_limiter_cu_kernel<<>>(up->on_dev, *conf_range, - prim->on_dev, vlasov_pkpm_moms->on_dev, p_ij->on_dev, - fluid->on_dev); + gkyl_dg_calc_pkpm_vars_limiter_cu_kernel<< > >( + up->on_dev, *conf_range, prim->on_dev, vlasov_pkpm_moms->on_dev, p_ij->on_dev, fluid->on_dev + ); } // CUDA kernel to set device pointers to pkpm vars kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_calc_pkpm_vars_set_cu_dev_ptrs(struct gkyl_dg_calc_pkpm_vars *up, enum gkyl_basis_type b_type, - int cdim, int poly_order) +__global__ static void dg_calc_pkpm_vars_set_cu_dev_ptrs( + struct gkyl_dg_calc_pkpm_vars *up, enum gkyl_basis_type b_type, int cdim, int poly_order +) { up->pkpm_set = choose_pkpm_set_kern(b_type, cdim, poly_order); up->pkpm_copy = choose_pkpm_copy_kern(b_type, cdim, poly_order); up->pkpm_u_set = choose_pkpm_u_set_kern(b_type, cdim, poly_order); - up->pkpm_u_copy = choose_pkpm_u_copy_kern(b_type, cdim, poly_order); + up->pkpm_u_copy = choose_pkpm_u_copy_kern(b_type, cdim, poly_order); up->pkpm_pressure = choose_pkpm_pressure_kern(b_type, cdim, poly_order); up->pkpm_p_force = choose_pkpm_p_force_kern(b_type, cdim, poly_order); up->pkpm_source = choose_pkpm_source_kern(b_type, cdim, poly_order); up->pkpm_int = choose_pkpm_int_kern(b_type, cdim, poly_order); up->pkpm_io = choose_pkpm_io_kern(b_type, cdim, poly_order); // Fetch the kernels in each direction - for (int d=0; dpkpm_accel[d] = choose_pkpm_accel_kern(d, b_type, cdim, poly_order); up->pkpm_penalization[d] = choose_pkpm_penalization_kern(d, b_type, cdim, poly_order); up->pkpm_limiter[d] = choose_pkpm_limiter_kern(d, b_type, cdim, poly_order); } } -gkyl_dg_calc_pkpm_vars* -gkyl_dg_calc_pkpm_vars_cu_dev_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis* cbasis, const struct gkyl_range *mem_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *wg, double limiter_fac) +gkyl_dg_calc_pkpm_vars *gkyl_dg_calc_pkpm_vars_cu_dev_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *cbasis, + const struct gkyl_range *mem_range, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_geom *wg, double limiter_fac +) { - struct gkyl_dg_calc_pkpm_vars *up = (struct gkyl_dg_calc_pkpm_vars*) gkyl_malloc(sizeof(gkyl_dg_calc_pkpm_vars)); + struct gkyl_dg_calc_pkpm_vars *up = + (struct gkyl_dg_calc_pkpm_vars *)gkyl_malloc(sizeof(gkyl_dg_calc_pkpm_vars)); up->conf_grid = *conf_grid; int nc = cbasis->num_basis; @@ -636,46 +632,46 @@ gkyl_dg_calc_pkpm_vars_cu_dev_new(const struct gkyl_rect_grid *conf_grid, // Limiter factor for relationship between slopes and cell average differences // By default, this factor is 1/sqrt(3) because cell_avg(f) = f0/sqrt(2^cdim) - // and a cell slope estimate from two adjacent cells is (for the x variation): + // and a cell slope estimate from two adjacent cells is (for the x variation): // integral(psi_1 [cell_avg(f_{i+1}) - cell_avg(f_{i})]*x) = sqrt(2^cdim)/sqrt(3)*[cell_avg(f_{i+1}) - cell_avg(f_{i})] // where psi_1 is the x cell slope basis in our orthonormal expansion psi_1 = sqrt(3)/sqrt(2^cdim)*x // This factor can be made smaller (larger) to increase (decrease) the diffusion from the slope limiter if (limiter_fac == 0.0) { up->limiter_fac = 0.5773502691896258; - } - else { + } else { up->limiter_fac = limiter_fac; } // Tolerance in mass density and average normal velocity at the interface // for switching to Lax fluxes in computing penalization of the momentum solve up->tol = 1.0e-12; - up->force_lax = false; + up->force_lax = false; - // There are Ncomp*range->volume linear systems to be solved + // There are Ncomp*range->volume linear systems to be solved // 6 components: ux, uy, uz, div(p_par b)/rho, p_perp/rho, rho/p_perp - up->As = gkyl_nmat_cu_dev_new(up->Ncomp*mem_range->volume, nc, nc); - up->xs = gkyl_nmat_cu_dev_new(up->Ncomp*mem_range->volume, nc, 1); + up->As = gkyl_nmat_cu_dev_new(up->Ncomp * mem_range->volume, nc, nc); + up->xs = gkyl_nmat_cu_dev_new(up->Ncomp * mem_range->volume, nc, 1); up->mem = gkyl_nmat_linsolve_lu_cu_dev_new(up->As->num, up->As->nr); // Linear system for just solving for ux, uy, uz - up->As_u = gkyl_nmat_cu_dev_new(3*mem_range->volume, nc, nc); - up->xs_u = gkyl_nmat_cu_dev_new(3*mem_range->volume, nc, 1); + up->As_u = gkyl_nmat_cu_dev_new(3 * mem_range->volume, nc, nc); + up->xs_u = gkyl_nmat_cu_dev_new(3 * mem_range->volume, nc, 1); up->mem_u = gkyl_nmat_linsolve_lu_cu_dev_new(up->As_u->num, up->As_u->nr); up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_calc_pkpm_vars *up_cu = (struct gkyl_dg_calc_pkpm_vars*) gkyl_cu_malloc(sizeof(gkyl_dg_calc_pkpm_vars)); + struct gkyl_dg_calc_pkpm_vars *up_cu = + (struct gkyl_dg_calc_pkpm_vars *)gkyl_cu_malloc(sizeof(gkyl_dg_calc_pkpm_vars)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_calc_pkpm_vars), GKYL_CU_MEMCPY_H2D); - dg_calc_pkpm_vars_set_cu_dev_ptrs<<<1,1>>>(up_cu, b_type, cdim, poly_order); + dg_calc_pkpm_vars_set_cu_dev_ptrs<<<1, 1> > >(up_cu, b_type, cdim, poly_order); // set parent on_dev pointer up->on_dev = up_cu; - up->wv_eqn = eqn; // updater should store host pointer - up->geom = geom; - + up->wv_eqn = eqn; // updater should store host pointer + up->geom = geom; + return up; } diff --git a/pkpm/zero/dg_euler_pkpm.c b/pkpm/zero/dg_euler_pkpm.c index dc16090cd6..84eaa3ba69 100644 --- a/pkpm/zero/dg_euler_pkpm.c +++ b/pkpm/zero/dg_euler_pkpm.c @@ -9,10 +9,9 @@ #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_euler_pkpm_free(const struct gkyl_ref_count *ref) +void gkyl_euler_pkpm_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); struct dg_euler_pkpm *euler_pkpm = container_of(base, struct dg_euler_pkpm, eqn); @@ -21,12 +20,13 @@ gkyl_euler_pkpm_free(const struct gkyl_ref_count *ref) // free inner on_dev object struct dg_euler_pkpm *euler_pkpm = container_of(base->on_dev, struct dg_euler_pkpm, eqn); gkyl_cu_free(euler_pkpm); - } + } gkyl_free(euler_pkpm); } -void -gkyl_euler_pkpm_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_pkpm_auxfields auxin) +void gkyl_euler_pkpm_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_pkpm_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_dg_eqn_is_cu_dev(eqn)) { @@ -44,14 +44,14 @@ gkyl_euler_pkpm_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_eule euler_pkpm->auxfields.pkpm_penalization = auxin.pkpm_penalization; } -struct gkyl_dg_eqn* -gkyl_dg_euler_pkpm_new(const struct gkyl_basis* cbasis, - const struct gkyl_range* conf_range, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_euler_pkpm_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_euler_pkpm_cu_dev_new(cbasis, conf_range); - } + } #endif struct dg_euler_pkpm *euler_pkpm = gkyl_malloc(sizeof(struct dg_euler_pkpm)); @@ -62,27 +62,27 @@ gkyl_dg_euler_pkpm_new(const struct gkyl_basis* cbasis, const gkyl_dg_euler_pkpm_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - surf_z_kernels = ser_surf_z_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - surf_x_kernels = ten_surf_x_kernels; - surf_y_kernels = ten_surf_y_kernels; - surf_z_kernels = ten_surf_z_kernels; - - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + surf_z_kernels = ser_surf_z_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + surf_x_kernels = ten_surf_x_kernels; + surf_y_kernels = ten_surf_y_kernels; + surf_z_kernels = ten_surf_z_kernels; + + break; + + default: + assert(false); + break; + } + euler_pkpm->eqn.num_equations = 3; euler_pkpm->eqn.surf_term = surf; euler_pkpm->eqn.boundary_surf_term = boundary_surf; @@ -90,35 +90,38 @@ gkyl_dg_euler_pkpm_new(const struct gkyl_basis* cbasis, euler_pkpm->eqn.vol_term = CK(vol_kernels, cdim, poly_order); euler_pkpm->surf[0] = CK(surf_x_kernels, cdim, poly_order); - if (cdim>1) + if (cdim > 1) { euler_pkpm->surf[1] = CK(surf_y_kernels, cdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { euler_pkpm->surf[2] = CK(surf_z_kernels, cdim, poly_order); + } - // ensure non-NULL pointers - for (int i=0; isurf[i]); + // ensure non-NULL pointers + for (int i = 0; i < cdim; ++i) { + assert(euler_pkpm->surf[i]); + } - euler_pkpm->auxfields.vlasov_pkpm_moms = 0; + euler_pkpm->auxfields.vlasov_pkpm_moms = 0; euler_pkpm->auxfields.pkpm_prim = 0; - euler_pkpm->auxfields.pkpm_prim_surf = 0; + euler_pkpm->auxfields.pkpm_prim_surf = 0; euler_pkpm->auxfields.pkpm_p_ij = 0; - euler_pkpm->auxfields.pkpm_lax = 0; - euler_pkpm->auxfields.pkpm_penalization = 0; + euler_pkpm->auxfields.pkpm_lax = 0; + euler_pkpm->auxfields.pkpm_penalization = 0; euler_pkpm->conf_range = *conf_range; - + euler_pkpm->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(euler_pkpm->eqn.flags); euler_pkpm->eqn.ref_count = gkyl_ref_count_init(gkyl_euler_pkpm_free); euler_pkpm->eqn.on_dev = &euler_pkpm->eqn; // CPU eqn obj points to itself - + return &euler_pkpm->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_euler_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_range* conf_range) +struct gkyl_dg_eqn * +gkyl_dg_euler_pkpm_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range) { assert(false); return 0; diff --git a/pkpm/zero/dg_euler_pkpm_cu.cu b/pkpm/zero/dg_euler_pkpm_cu.cu index 6f7ccd2c54..4333a5e9d8 100644 --- a/pkpm/zero/dg_euler_pkpm_cu.cu +++ b/pkpm/zero/dg_euler_pkpm_cu.cu @@ -3,24 +3,24 @@ extern "C" { #include #include -#include +#include #include #include } #include -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_euler_pkpm_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array *vlasov_pkpm_moms, - const struct gkyl_array *pkpm_prim, const struct gkyl_array *pkpm_prim_surf, - const struct gkyl_array *pkpm_p_ij, const struct gkyl_array *pkpm_lax, - const struct gkyl_array *pkpm_penalization) +__global__ static void gkyl_euler_pkpm_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *pkpm_prim, const struct gkyl_array *pkpm_prim_surf, + const struct gkyl_array *pkpm_p_ij, const struct gkyl_array *pkpm_lax, + const struct gkyl_array *pkpm_penalization +) { struct dg_euler_pkpm *euler_pkpm = container_of(eqn, struct dg_euler_pkpm, eqn); euler_pkpm->auxfields.vlasov_pkpm_moms = vlasov_pkpm_moms; @@ -32,66 +32,71 @@ gkyl_euler_pkpm_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_euler_pkpm_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_pkpm_auxfields auxin) +void gkyl_euler_pkpm_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_pkpm_auxfields auxin +) { - gkyl_euler_pkpm_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.vlasov_pkpm_moms->on_dev, - auxin.pkpm_prim->on_dev, auxin.pkpm_prim_surf->on_dev, - auxin.pkpm_p_ij->on_dev, auxin.pkpm_lax->on_dev, auxin.pkpm_penalization->on_dev); + gkyl_euler_pkpm_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.vlasov_pkpm_moms->on_dev, auxin.pkpm_prim->on_dev, auxin.pkpm_prim_surf->on_dev, + auxin.pkpm_p_ij->on_dev, auxin.pkpm_lax->on_dev, auxin.pkpm_penalization->on_dev + ); } -__global__ void static -dg_euler_pkpm_set_cu_dev_ptrs(struct dg_euler_pkpm* euler_pkpm, enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ void static dg_euler_pkpm_set_cu_dev_ptrs( + struct dg_euler_pkpm *euler_pkpm, enum gkyl_basis_type b_type, int cdim, int poly_order +) { - euler_pkpm->auxfields.vlasov_pkpm_moms = 0; + euler_pkpm->auxfields.vlasov_pkpm_moms = 0; euler_pkpm->auxfields.pkpm_prim = 0; - euler_pkpm->auxfields.pkpm_prim_surf = 0; + euler_pkpm->auxfields.pkpm_prim_surf = 0; euler_pkpm->auxfields.pkpm_p_ij = 0; - euler_pkpm->auxfields.pkpm_lax = 0; - euler_pkpm->auxfields.pkpm_penalization = 0; - + euler_pkpm->auxfields.pkpm_lax = 0; + euler_pkpm->auxfields.pkpm_penalization = 0; + const gkyl_dg_euler_pkpm_vol_kern_list *vol_kernels; - const gkyl_dg_euler_pkpm_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; - + const gkyl_dg_euler_pkpm_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - surf_z_kernels = ser_surf_z_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - surf_x_kernels = ten_surf_x_kernels; - surf_y_kernels = ten_surf_y_kernels; - surf_z_kernels = ten_surf_z_kernels; - - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + surf_z_kernels = ser_surf_z_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + surf_x_kernels = ten_surf_x_kernels; + surf_y_kernels = ten_surf_y_kernels; + surf_z_kernels = ten_surf_z_kernels; + + break; + + default: + assert(false); + break; + } + euler_pkpm->eqn.surf_term = surf; euler_pkpm->eqn.boundary_surf_term = boundary_surf; - euler_pkpm->eqn.vol_term = CK(vol_kernels, cdim, poly_order); + euler_pkpm->eqn.vol_term = CK(vol_kernels, cdim, poly_order); euler_pkpm->surf[0] = CK(surf_x_kernels, cdim, poly_order); - if (cdim>1) + if (cdim > 1) { euler_pkpm->surf[1] = CK(surf_y_kernels, cdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { euler_pkpm->surf[2] = CK(surf_z_kernels, cdim, poly_order); + } } -struct gkyl_dg_eqn* -gkyl_dg_euler_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_range* conf_range) +struct gkyl_dg_eqn * +gkyl_dg_euler_pkpm_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range) { - struct dg_euler_pkpm *euler_pkpm = (struct dg_euler_pkpm*) gkyl_malloc(sizeof(struct dg_euler_pkpm)); + struct dg_euler_pkpm *euler_pkpm = + (struct dg_euler_pkpm *)gkyl_malloc(sizeof(struct dg_euler_pkpm)); // set basic parameters euler_pkpm->eqn.num_equations = 3; @@ -103,9 +108,12 @@ gkyl_dg_euler_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, euler_pkpm->eqn.ref_count = gkyl_ref_count_init(gkyl_euler_pkpm_free); // copy the host struct to device struct - struct dg_euler_pkpm *euler_pkpm_cu = (struct dg_euler_pkpm*) gkyl_cu_malloc(sizeof(struct dg_euler_pkpm)); + struct dg_euler_pkpm *euler_pkpm_cu = + (struct dg_euler_pkpm *)gkyl_cu_malloc(sizeof(struct dg_euler_pkpm)); gkyl_cu_memcpy(euler_pkpm_cu, euler_pkpm, sizeof(struct dg_euler_pkpm), GKYL_CU_MEMCPY_H2D); - dg_euler_pkpm_set_cu_dev_ptrs<<<1,1>>>(euler_pkpm_cu, cbasis->b_type, cbasis->ndim, cbasis->poly_order); + dg_euler_pkpm_set_cu_dev_ptrs<<<1, 1> > >( + euler_pkpm_cu, cbasis->b_type, cbasis->ndim, cbasis->poly_order + ); // set parent on_dev pointer euler_pkpm->eqn.on_dev = &euler_pkpm_cu->eqn; diff --git a/pkpm/zero/dg_lbo_pkpm_diff.c b/pkpm/zero/dg_lbo_pkpm_diff.c index 9386ac1d26..263b946f4c 100644 --- a/pkpm/zero/dg_lbo_pkpm_diff.c +++ b/pkpm/zero/dg_lbo_pkpm_diff.c @@ -9,29 +9,29 @@ #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_lbo_pkpm_diff_free(const struct gkyl_ref_count* ref) +void gkyl_lbo_pkpm_diff_free(const struct gkyl_ref_count *ref) { - struct gkyl_dg_eqn* base = container_of(ref, struct gkyl_dg_eqn, ref_count); - struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(base, struct dg_lbo_pkpm_diff, eqn); + struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); + struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(base, struct dg_lbo_pkpm_diff, eqn); - if (GKYL_IS_CU_ALLOC(lbo_pkpm_diff->eqn.flags)) + if (GKYL_IS_CU_ALLOC(lbo_pkpm_diff->eqn.flags)) { gkyl_cu_free(lbo_pkpm_diff->eqn.on_dev); - + } + gkyl_free(lbo_pkpm_diff); } -void -gkyl_lbo_pkpm_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, const struct gkyl_dg_lbo_pkpm_diff_auxfields auxin) +void gkyl_lbo_pkpm_diff_set_auxfields( + const struct gkyl_dg_eqn *eqn, const struct gkyl_dg_lbo_pkpm_diff_auxfields auxin +) { - #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(auxin.nuSum) && gkyl_array_is_cu_dev(auxin.nuPrimMomsSum)) { - gkyl_lbo_pkpm_diff_set_auxfields_cu(eqn->on_dev, auxin); - return; - } + if (gkyl_array_is_cu_dev(auxin.nuSum) && gkyl_array_is_cu_dev(auxin.nuPrimMomsSum)) { + gkyl_lbo_pkpm_diff_set_auxfields_cu(eqn->on_dev, auxin); + return; + } #endif struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(eqn, struct dg_lbo_pkpm_diff, eqn); @@ -39,16 +39,17 @@ gkyl_lbo_pkpm_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, const struct gky lbo_pkpm_diff->auxfields.nuPrimMomsSum = auxin.nuPrimMomsSum; } -struct gkyl_dg_eqn* -gkyl_dg_lbo_pkpm_diff_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_lbo_pkpm_diff_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_lbo_pkpm_diff_cu_dev_new(cbasis, pbasis, conf_range, pgrid); - } + } #endif - struct dg_lbo_pkpm_diff* lbo_pkpm_diff = gkyl_malloc(sizeof(struct dg_lbo_pkpm_diff)); + struct dg_lbo_pkpm_diff *lbo_pkpm_diff = gkyl_malloc(sizeof(struct dg_lbo_pkpm_diff)); int cdim = cbasis->ndim, pdim = pbasis->ndim; int poly_order = cbasis->poly_order; @@ -63,26 +64,26 @@ gkyl_dg_lbo_pkpm_diff_new(const struct gkyl_basis* cbasis, const struct gkyl_bas const gkyl_dg_lbo_pkpm_diff_vol_kern_list *vol_kernels; const gkyl_dg_lbo_pkpm_diff_surf_kern_list *surf_vpar_kernels; const gkyl_dg_lbo_pkpm_diff_boundary_surf_kern_list *boundary_surf_vpar_kernels; - + switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vpar_kernels = ser_surf_vpar_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - surf_vpar_kernels = ten_surf_vpar_kernels; - boundary_surf_vpar_kernels = ten_boundary_surf_vpar_kernels; - - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vpar_kernels = ser_surf_vpar_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + surf_vpar_kernels = ten_surf_vpar_kernels; + boundary_surf_vpar_kernels = ten_boundary_surf_vpar_kernels; + + break; + + default: + assert(false); + break; + } lbo_pkpm_diff->eqn.vol_term = CK(vol_kernels, cdim, poly_order); @@ -97,22 +98,23 @@ gkyl_dg_lbo_pkpm_diff_new(const struct gkyl_basis* cbasis, const struct gkyl_bas lbo_pkpm_diff->auxfields.nuSum = 0; lbo_pkpm_diff->auxfields.nuPrimMomsSum = 0; lbo_pkpm_diff->conf_range = *conf_range; - lbo_pkpm_diff->vMaxSq = pow(pgrid->upper[cdim],2); + lbo_pkpm_diff->vMaxSq = pow(pgrid->upper[cdim], 2); lbo_pkpm_diff->num_cbasis = cbasis->num_basis; lbo_pkpm_diff->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(lbo_pkpm_diff->eqn.flags); lbo_pkpm_diff->eqn.ref_count = gkyl_ref_count_init(gkyl_lbo_pkpm_diff_free); lbo_pkpm_diff->eqn.on_dev = &lbo_pkpm_diff->eqn; - + return &lbo_pkpm_diff->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_lbo_pkpm_diff_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid) +struct gkyl_dg_eqn *gkyl_dg_lbo_pkpm_diff_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +) { assert(false); return 0; diff --git a/pkpm/zero/dg_lbo_pkpm_diff_cu.cu b/pkpm/zero/dg_lbo_pkpm_diff_cu.cu index f864773db0..48675c9121 100644 --- a/pkpm/zero/dg_lbo_pkpm_diff_cu.cu +++ b/pkpm/zero/dg_lbo_pkpm_diff_cu.cu @@ -3,20 +3,22 @@ extern "C" { #include #include -#include +#include #include } #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] // CUDA kernel to set pointer to nuSum and nuPrimMomsSum (collision frequency * primitive moments) // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_lbo_pkpm_diff_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nuSum, const struct gkyl_array *nuPrimMomsSum) +__global__ static void gkyl_lbo_pkpm_diff_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nuSum, + const struct gkyl_array *nuPrimMomsSum +) { struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(eqn, struct dg_lbo_pkpm_diff, eqn); lbo_pkpm_diff->auxfields.nuSum = nuSum; @@ -24,20 +26,23 @@ gkyl_lbo_pkpm_diff_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, const } // Host-side wrapper for device kernels setting nuSum and nuPrimMomsSum. -void -gkyl_lbo_pkpm_diff_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_diff_auxfields auxin) +void gkyl_lbo_pkpm_diff_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_diff_auxfields auxin +) { - gkyl_lbo_pkpm_diff_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.nuSum->on_dev, auxin.nuPrimMomsSum->on_dev); + gkyl_lbo_pkpm_diff_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.nuSum->on_dev, auxin.nuPrimMomsSum->on_dev + ); } // CUDA kernel to set device pointers to range object and Vlasov PKPM LBO diffusion kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_lbo_pkpm_diff_set_cu_dev_ptrs(struct dg_lbo_pkpm_diff *lbo_pkpm_diff, enum gkyl_basis_type b_type, - int cdim, int poly_order) +__global__ static void dg_lbo_pkpm_diff_set_cu_dev_ptrs( + struct dg_lbo_pkpm_diff *lbo_pkpm_diff, enum gkyl_basis_type b_type, int cdim, int poly_order +) { - lbo_pkpm_diff->auxfields.nuSum = 0; - lbo_pkpm_diff->auxfields.nuPrimMomsSum = 0; + lbo_pkpm_diff->auxfields.nuSum = 0; + lbo_pkpm_diff->auxfields.nuPrimMomsSum = 0; lbo_pkpm_diff->eqn.surf_term = surf; lbo_pkpm_diff->eqn.boundary_surf_term = boundary_surf; @@ -45,27 +50,27 @@ dg_lbo_pkpm_diff_set_cu_dev_ptrs(struct dg_lbo_pkpm_diff *lbo_pkpm_diff, enum gk const gkyl_dg_lbo_pkpm_diff_vol_kern_list *vol_kernels; const gkyl_dg_lbo_pkpm_diff_surf_kern_list *surf_vpar_kernels; const gkyl_dg_lbo_pkpm_diff_boundary_surf_kern_list *boundary_surf_vpar_kernels; - + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vpar_kernels = ser_surf_vpar_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - surf_vpar_kernels = ten_surf_vpar_kernels; - boundary_surf_vpar_kernels = ten_boundary_surf_vpar_kernels; - - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vpar_kernels = ser_surf_vpar_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + surf_vpar_kernels = ten_surf_vpar_kernels; + boundary_surf_vpar_kernels = ten_boundary_surf_vpar_kernels; + + break; + + default: + assert(false); + break; + } + lbo_pkpm_diff->eqn.vol_term = CK(vol_kernels, cdim, poly_order); lbo_pkpm_diff->surf = CK(surf_vpar_kernels, cdim, poly_order); @@ -73,12 +78,13 @@ dg_lbo_pkpm_diff_set_cu_dev_ptrs(struct dg_lbo_pkpm_diff *lbo_pkpm_diff, enum gk lbo_pkpm_diff->boundary_surf = CK(boundary_surf_vpar_kernels, cdim, poly_order); } -struct gkyl_dg_eqn* -gkyl_dg_lbo_pkpm_diff_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid) +struct gkyl_dg_eqn *gkyl_dg_lbo_pkpm_diff_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +) { struct dg_lbo_pkpm_diff *lbo_pkpm_diff = - (struct dg_lbo_pkpm_diff*) gkyl_malloc(sizeof(struct dg_lbo_pkpm_diff)); + (struct dg_lbo_pkpm_diff *)gkyl_malloc(sizeof(struct dg_lbo_pkpm_diff)); int cdim = cbasis->ndim, pdim = pbasis->ndim; int poly_order = cbasis->poly_order; @@ -88,7 +94,7 @@ gkyl_dg_lbo_pkpm_diff_cu_dev_new(const struct gkyl_basis* cbasis, const struct g lbo_pkpm_diff->eqn.num_equations = 2; lbo_pkpm_diff->conf_range = *conf_range; - lbo_pkpm_diff->vMaxSq = pow(pgrid->upper[cdim],2); + lbo_pkpm_diff->vMaxSq = pow(pgrid->upper[cdim], 2); lbo_pkpm_diff->num_cbasis = cbasis->num_basis; lbo_pkpm_diff->eqn.flags = 0; @@ -97,15 +103,15 @@ gkyl_dg_lbo_pkpm_diff_cu_dev_new(const struct gkyl_basis* cbasis, const struct g // copy the host struct to device struct struct dg_lbo_pkpm_diff *lbo_pkpm_diff_cu = - (struct dg_lbo_pkpm_diff*) gkyl_cu_malloc(sizeof(struct dg_lbo_pkpm_diff)); + (struct dg_lbo_pkpm_diff *)gkyl_cu_malloc(sizeof(struct dg_lbo_pkpm_diff)); + + gkyl_cu_memcpy( + lbo_pkpm_diff_cu, lbo_pkpm_diff, sizeof(struct dg_lbo_pkpm_diff), GKYL_CU_MEMCPY_H2D + ); - gkyl_cu_memcpy(lbo_pkpm_diff_cu, lbo_pkpm_diff, - sizeof(struct dg_lbo_pkpm_diff), GKYL_CU_MEMCPY_H2D); + dg_lbo_pkpm_diff_set_cu_dev_ptrs<<<1, 1> > >(lbo_pkpm_diff_cu, cbasis->b_type, cdim, poly_order); - dg_lbo_pkpm_diff_set_cu_dev_ptrs<<<1,1>>>(lbo_pkpm_diff_cu, - cbasis->b_type, cdim, poly_order); + lbo_pkpm_diff->eqn.on_dev = &lbo_pkpm_diff_cu->eqn; - lbo_pkpm_diff->eqn.on_dev = &lbo_pkpm_diff_cu->eqn; - return &lbo_pkpm_diff->eqn; } diff --git a/pkpm/zero/dg_lbo_pkpm_drag.c b/pkpm/zero/dg_lbo_pkpm_drag.c index 9b3331072e..78672b3da0 100644 --- a/pkpm/zero/dg_lbo_pkpm_drag.c +++ b/pkpm/zero/dg_lbo_pkpm_drag.c @@ -9,29 +9,29 @@ #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_lbo_pkpm_drag_free(const struct gkyl_ref_count* ref) +void gkyl_lbo_pkpm_drag_free(const struct gkyl_ref_count *ref) { - struct gkyl_dg_eqn* base = container_of(ref, struct gkyl_dg_eqn, ref_count); - struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(base, struct dg_lbo_pkpm_drag, eqn); + struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); + struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(base, struct dg_lbo_pkpm_drag, eqn); - if (GKYL_IS_CU_ALLOC(lbo_pkpm_drag->eqn.flags)) + if (GKYL_IS_CU_ALLOC(lbo_pkpm_drag->eqn.flags)) { gkyl_cu_free(lbo_pkpm_drag->eqn.on_dev); - + } + gkyl_free(lbo_pkpm_drag); } -void -gkyl_lbo_pkpm_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, const struct gkyl_dg_lbo_pkpm_drag_auxfields auxin) +void gkyl_lbo_pkpm_drag_set_auxfields( + const struct gkyl_dg_eqn *eqn, const struct gkyl_dg_lbo_pkpm_drag_auxfields auxin +) { - #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(auxin.nuSum) && gkyl_array_is_cu_dev(auxin.nuPrimMomsSum)) { - gkyl_lbo_pkpm_drag_set_auxfields_cu(eqn->on_dev, auxin); - return; - } + if (gkyl_array_is_cu_dev(auxin.nuSum) && gkyl_array_is_cu_dev(auxin.nuPrimMomsSum)) { + gkyl_lbo_pkpm_drag_set_auxfields_cu(eqn->on_dev, auxin); + return; + } #endif struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(eqn, struct dg_lbo_pkpm_drag, eqn); @@ -39,16 +39,17 @@ gkyl_lbo_pkpm_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, const struct gky lbo_pkpm_drag->auxfields.nuPrimMomsSum = auxin.nuPrimMomsSum; } -struct gkyl_dg_eqn* -gkyl_dg_lbo_pkpm_drag_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_lbo_pkpm_drag_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_lbo_pkpm_drag_cu_dev_new(cbasis, pbasis, conf_range, pgrid); - } + } #endif - struct dg_lbo_pkpm_drag* lbo_pkpm_drag = gkyl_malloc(sizeof(struct dg_lbo_pkpm_drag)); + struct dg_lbo_pkpm_drag *lbo_pkpm_drag = gkyl_malloc(sizeof(struct dg_lbo_pkpm_drag)); int cdim = cbasis->ndim, pdim = pbasis->ndim; int poly_order = cbasis->poly_order; @@ -63,26 +64,26 @@ gkyl_dg_lbo_pkpm_drag_new(const struct gkyl_basis* cbasis, const struct gkyl_bas const gkyl_dg_lbo_pkpm_drag_vol_kern_list *vol_kernels; const gkyl_dg_lbo_pkpm_drag_surf_kern_list *surf_vpar_kernels; const gkyl_dg_lbo_pkpm_drag_boundary_surf_kern_list *boundary_surf_vpar_kernels; - + switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vpar_kernels = ser_surf_vpar_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - surf_vpar_kernels = ten_surf_vpar_kernels; - boundary_surf_vpar_kernels = ten_boundary_surf_vpar_kernels; - - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vpar_kernels = ser_surf_vpar_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + surf_vpar_kernels = ten_surf_vpar_kernels; + boundary_surf_vpar_kernels = ten_boundary_surf_vpar_kernels; + + break; + + default: + assert(false); + break; + } lbo_pkpm_drag->eqn.vol_term = CK(vol_kernels, cdim, poly_order); @@ -97,22 +98,23 @@ gkyl_dg_lbo_pkpm_drag_new(const struct gkyl_basis* cbasis, const struct gkyl_bas lbo_pkpm_drag->auxfields.nuSum = 0; lbo_pkpm_drag->auxfields.nuPrimMomsSum = 0; lbo_pkpm_drag->conf_range = *conf_range; - lbo_pkpm_drag->vMaxSq = pow(pgrid->upper[cdim],2); + lbo_pkpm_drag->vMaxSq = pow(pgrid->upper[cdim], 2); lbo_pkpm_drag->num_cbasis = cbasis->num_basis; - + lbo_pkpm_drag->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(lbo_pkpm_drag->eqn.flags); lbo_pkpm_drag->eqn.ref_count = gkyl_ref_count_init(gkyl_lbo_pkpm_drag_free); lbo_pkpm_drag->eqn.on_dev = &lbo_pkpm_drag->eqn; - + return &lbo_pkpm_drag->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_lbo_pkpm_drag_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid) +struct gkyl_dg_eqn *gkyl_dg_lbo_pkpm_drag_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +) { assert(false); return 0; diff --git a/pkpm/zero/dg_lbo_pkpm_drag_cu.cu b/pkpm/zero/dg_lbo_pkpm_drag_cu.cu index 6426c0fb12..6611523c65 100644 --- a/pkpm/zero/dg_lbo_pkpm_drag_cu.cu +++ b/pkpm/zero/dg_lbo_pkpm_drag_cu.cu @@ -3,20 +3,22 @@ extern "C" { #include #include -#include +#include #include } #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] // CUDA kernel to set pointer to nuSum and nuPrimMomsSum (collision frequency * primitive moments) // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_lbo_pkpm_drag_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nuSum, const struct gkyl_array *nuPrimMomsSum) +__global__ static void gkyl_lbo_pkpm_drag_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nuSum, + const struct gkyl_array *nuPrimMomsSum +) { struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(eqn, struct dg_lbo_pkpm_drag, eqn); lbo_pkpm_drag->auxfields.nuSum = nuSum; @@ -24,20 +26,23 @@ gkyl_lbo_pkpm_drag_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, const } // Host-side wrapper for device kernels setting nuSum and nuPrimMomsSum. -void -gkyl_lbo_pkpm_drag_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_drag_auxfields auxin) +void gkyl_lbo_pkpm_drag_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_drag_auxfields auxin +) { - gkyl_lbo_pkpm_drag_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.nuSum->on_dev, auxin.nuPrimMomsSum->on_dev); + gkyl_lbo_pkpm_drag_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.nuSum->on_dev, auxin.nuPrimMomsSum->on_dev + ); } // CUDA kernel to set device pointers to range object and Vlasov PKPM LBO drag kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_lbo_pkpm_drag_set_cu_dev_ptrs(struct dg_lbo_pkpm_drag *lbo_pkpm_drag, enum gkyl_basis_type b_type, - int cdim, int poly_order) +__global__ static void dg_lbo_pkpm_drag_set_cu_dev_ptrs( + struct dg_lbo_pkpm_drag *lbo_pkpm_drag, enum gkyl_basis_type b_type, int cdim, int poly_order +) { - lbo_pkpm_drag->auxfields.nuSum = 0; - lbo_pkpm_drag->auxfields.nuPrimMomsSum = 0; + lbo_pkpm_drag->auxfields.nuSum = 0; + lbo_pkpm_drag->auxfields.nuPrimMomsSum = 0; lbo_pkpm_drag->eqn.surf_term = surf; lbo_pkpm_drag->eqn.boundary_surf_term = boundary_surf; @@ -45,27 +50,27 @@ dg_lbo_pkpm_drag_set_cu_dev_ptrs(struct dg_lbo_pkpm_drag *lbo_pkpm_drag, enum gk const gkyl_dg_lbo_pkpm_drag_vol_kern_list *vol_kernels; const gkyl_dg_lbo_pkpm_drag_surf_kern_list *surf_vpar_kernels; const gkyl_dg_lbo_pkpm_drag_boundary_surf_kern_list *boundary_surf_vpar_kernels; - + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vpar_kernels = ser_surf_vpar_kernels; - boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - surf_vpar_kernels = ten_surf_vpar_kernels; - boundary_surf_vpar_kernels = ten_boundary_surf_vpar_kernels; - - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vpar_kernels = ser_surf_vpar_kernels; + boundary_surf_vpar_kernels = ser_boundary_surf_vpar_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + surf_vpar_kernels = ten_surf_vpar_kernels; + boundary_surf_vpar_kernels = ten_boundary_surf_vpar_kernels; + + break; + + default: + assert(false); + break; + } + lbo_pkpm_drag->eqn.vol_term = CK(vol_kernels, cdim, poly_order); lbo_pkpm_drag->surf = CK(surf_vpar_kernels, cdim, poly_order); @@ -73,12 +78,13 @@ dg_lbo_pkpm_drag_set_cu_dev_ptrs(struct dg_lbo_pkpm_drag *lbo_pkpm_drag, enum gk lbo_pkpm_drag->boundary_surf = CK(boundary_surf_vpar_kernels, cdim, poly_order); } -struct gkyl_dg_eqn* -gkyl_dg_lbo_pkpm_drag_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid) +struct gkyl_dg_eqn *gkyl_dg_lbo_pkpm_drag_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +) { struct dg_lbo_pkpm_drag *lbo_pkpm_drag = - (struct dg_lbo_pkpm_drag*) gkyl_malloc(sizeof(struct dg_lbo_pkpm_drag)); + (struct dg_lbo_pkpm_drag *)gkyl_malloc(sizeof(struct dg_lbo_pkpm_drag)); int cdim = cbasis->ndim, pdim = pbasis->ndim; int poly_order = cbasis->poly_order; @@ -88,24 +94,24 @@ gkyl_dg_lbo_pkpm_drag_cu_dev_new(const struct gkyl_basis* cbasis, const struct g lbo_pkpm_drag->eqn.num_equations = 2; lbo_pkpm_drag->conf_range = *conf_range; - lbo_pkpm_drag->vMaxSq = pow(pgrid->upper[cdim],2); + lbo_pkpm_drag->vMaxSq = pow(pgrid->upper[cdim], 2); lbo_pkpm_drag->num_cbasis = cbasis->num_basis; - + lbo_pkpm_drag->eqn.flags = 0; GKYL_SET_CU_ALLOC(lbo_pkpm_drag->eqn.flags); lbo_pkpm_drag->eqn.ref_count = gkyl_ref_count_init(gkyl_lbo_pkpm_drag_free); // copy the host struct to device struct struct dg_lbo_pkpm_drag *lbo_pkpm_drag_cu = - (struct dg_lbo_pkpm_drag*) gkyl_cu_malloc(sizeof(struct dg_lbo_pkpm_drag)); + (struct dg_lbo_pkpm_drag *)gkyl_cu_malloc(sizeof(struct dg_lbo_pkpm_drag)); + + gkyl_cu_memcpy( + lbo_pkpm_drag_cu, lbo_pkpm_drag, sizeof(struct dg_lbo_pkpm_drag), GKYL_CU_MEMCPY_H2D + ); - gkyl_cu_memcpy(lbo_pkpm_drag_cu, lbo_pkpm_drag, - sizeof(struct dg_lbo_pkpm_drag), GKYL_CU_MEMCPY_H2D); + dg_lbo_pkpm_drag_set_cu_dev_ptrs<<<1, 1> > >(lbo_pkpm_drag_cu, cbasis->b_type, cdim, poly_order); - dg_lbo_pkpm_drag_set_cu_dev_ptrs<<<1,1>>>(lbo_pkpm_drag_cu, - cbasis->b_type, cdim, poly_order); + lbo_pkpm_drag->eqn.on_dev = &lbo_pkpm_drag_cu->eqn; - lbo_pkpm_drag->eqn.on_dev = &lbo_pkpm_drag_cu->eqn; - return &lbo_pkpm_drag->eqn; } diff --git a/pkpm/zero/dg_updater_lbo_pkpm.c b/pkpm/zero/dg_updater_lbo_pkpm.c index 09a16d86e5..89b37a82bb 100644 --- a/pkpm/zero/dg_updater_lbo_pkpm.c +++ b/pkpm/zero/dg_updater_lbo_pkpm.c @@ -9,45 +9,54 @@ #include #include -struct gkyl_dg_updater_collisions* -gkyl_dg_updater_lbo_pkpm_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *conf_range, - struct gkyl_dg_lbo_pkpm_drag_auxfields *drag_inp, struct gkyl_dg_lbo_pkpm_diff_auxfields *diff_inp, - bool use_gpu) +struct gkyl_dg_updater_collisions *gkyl_dg_updater_lbo_pkpm_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, + struct gkyl_dg_lbo_pkpm_drag_auxfields *drag_inp, + struct gkyl_dg_lbo_pkpm_diff_auxfields *diff_inp, bool use_gpu +) { struct gkyl_dg_updater_collisions *up = gkyl_malloc(sizeof(gkyl_dg_updater_collisions)); up->use_gpu = use_gpu; - up->coll_drag = gkyl_dg_lbo_pkpm_drag_new(conf_basis, phase_basis, conf_range, phase_grid, use_gpu); + up->coll_drag = + gkyl_dg_lbo_pkpm_drag_new(conf_basis, phase_basis, conf_range, phase_grid, use_gpu); gkyl_lbo_pkpm_drag_set_auxfields(up->coll_drag, *drag_inp); - up->coll_diff = gkyl_dg_lbo_pkpm_diff_new(conf_basis, phase_basis, conf_range, phase_grid, use_gpu); + up->coll_diff = + gkyl_dg_lbo_pkpm_diff_new(conf_basis, phase_basis, conf_range, phase_grid, use_gpu); gkyl_lbo_pkpm_diff_set_auxfields(up->coll_diff, *diff_inp); int cdim = conf_basis->ndim, pdim = phase_basis->ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int num_up_dirs = vdim; - int up_dirs[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim - vdim; + } - int zero_flux_flags[2*GKYL_MAX_DIM] = { 0 }; - for (int d=cdim; ddrag = gkyl_hyper_dg_new(phase_grid, phase_basis, up->coll_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu); - up->diff = gkyl_hyper_dg_new(phase_grid, phase_basis, up->coll_diff, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu); + int zero_flux_flags[2 * GKYL_MAX_DIM] = {0}; + for (int d = cdim; d < pdim; ++d) { + zero_flux_flags[d] = zero_flux_flags[d + pdim] = 1; + } - up->diff_tm = 0.0; + up->drag = gkyl_hyper_dg_new( + phase_grid, phase_basis, up->coll_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu + ); + up->diff = gkyl_hyper_dg_new( + phase_grid, phase_basis, up->coll_diff, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu + ); + + up->diff_tm = 0.0; up->drag_tm = 0.0; - + return up; } -void -gkyl_dg_updater_lbo_pkpm_advance(struct gkyl_dg_updater_collisions *lbo, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_lbo_pkpm_advance( + struct gkyl_dg_updater_collisions *lbo, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(lbo->drag, update_rng, fIn, cflrate, rhs); @@ -61,14 +70,10 @@ gkyl_dg_updater_lbo_pkpm_advance(struct gkyl_dg_updater_collisions *lbo, struct gkyl_dg_updater_lbo_pkpm_tm gkyl_dg_updater_lbo_pkpm_get_tm(const gkyl_dg_updater_collisions *coll) { - return (struct gkyl_dg_updater_lbo_pkpm_tm) { - .drag_tm = coll->drag_tm, - .diff_tm = coll->diff_tm - }; + return (struct gkyl_dg_updater_lbo_pkpm_tm){.drag_tm = coll->drag_tm, .diff_tm = coll->diff_tm}; } -void -gkyl_dg_updater_lbo_pkpm_release(gkyl_dg_updater_collisions* coll) +void gkyl_dg_updater_lbo_pkpm_release(gkyl_dg_updater_collisions *coll) { gkyl_dg_eqn_release(coll->coll_drag); gkyl_dg_eqn_release(coll->coll_diff); diff --git a/pkpm/zero/dg_updater_moment_pkpm.c b/pkpm/zero/dg_updater_moment_pkpm.c index 0f65722df2..1f837313c9 100644 --- a/pkpm/zero/dg_updater_moment_pkpm.c +++ b/pkpm/zero/dg_updater_moment_pkpm.c @@ -10,23 +10,21 @@ #include #include -struct gkyl_mom_type* -gkyl_dg_updater_moment_pkpm_acquire_type(const gkyl_dg_updater_moment* moment) +struct gkyl_mom_type *gkyl_dg_updater_moment_pkpm_acquire_type(const gkyl_dg_updater_moment *moment) { return gkyl_mom_type_acquire(moment->type); } -int -gkyl_dg_updater_moment_pkpm_num_mom(const gkyl_dg_updater_moment* moment) +int gkyl_dg_updater_moment_pkpm_num_mom(const gkyl_dg_updater_moment *moment) { return gkyl_mom_type_num_mom(moment->type); } -struct gkyl_dg_updater_moment* -gkyl_dg_updater_moment_pkpm_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, - double mass, bool is_diag, bool use_gpu) +struct gkyl_dg_updater_moment *gkyl_dg_updater_moment_pkpm_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, + const struct gkyl_range *vel_range, double mass, bool is_diag, bool use_gpu +) { gkyl_dg_updater_moment *up = gkyl_malloc(sizeof(gkyl_dg_updater_moment)); up->use_gpu = use_gpu; @@ -35,33 +33,32 @@ gkyl_dg_updater_moment_pkpm_new(const struct gkyl_rect_grid *grid, up->up_moment = gkyl_mom_calc_new(grid, up->type, use_gpu); up->moment_tm = 0.0; - + return up; } -void -gkyl_dg_updater_moment_pkpm_advance(struct gkyl_dg_updater_moment *moment, - const struct gkyl_range *update_phase_rng, const struct gkyl_range *update_conf_rng, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT mout) -{ +void gkyl_dg_updater_moment_pkpm_advance( + struct gkyl_dg_updater_moment *moment, const struct gkyl_range *update_phase_rng, + const struct gkyl_range *update_conf_rng, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT mout +) +{ struct timespec wst = gkyl_wall_clock(); - if (moment->use_gpu) + if (moment->use_gpu) { gkyl_mom_calc_advance_cu(moment->up_moment, update_phase_rng, update_conf_rng, fIn, mout); - else + } else { gkyl_mom_calc_advance(moment->up_moment, update_phase_rng, update_conf_rng, fIn, mout); + } moment->moment_tm += gkyl_time_diff_now_sec(wst); } struct gkyl_dg_updater_moment_tm gkyl_dg_updater_moment_pkpm_get_tm(const gkyl_dg_updater_moment *moment) { - return (struct gkyl_dg_updater_moment_tm) { - .moment_tm = moment->moment_tm, - }; + return (struct gkyl_dg_updater_moment_tm){.moment_tm = moment->moment_tm}; } -void -gkyl_dg_updater_moment_pkpm_release(gkyl_dg_updater_moment* moment) +void gkyl_dg_updater_moment_pkpm_release(gkyl_dg_updater_moment *moment) { gkyl_mom_type_release(moment->type); gkyl_mom_calc_release(moment->up_moment); diff --git a/pkpm/zero/dg_updater_pkpm.c b/pkpm/zero/dg_updater_pkpm.c index c076cead41..87349fea27 100644 --- a/pkpm/zero/dg_updater_pkpm.c +++ b/pkpm/zero/dg_updater_pkpm.c @@ -9,56 +9,64 @@ #include #include -gkyl_dg_updater_pkpm* -gkyl_dg_updater_pkpm_new(const struct gkyl_rect_grid *conf_grid, const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, +gkyl_dg_updater_pkpm *gkyl_dg_updater_pkpm_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_rect_grid *phase_grid, + const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const bool *is_zero_flux_dir, - struct gkyl_dg_vlasov_pkpm_auxfields *vlasov_pkpm_inp, struct gkyl_dg_euler_pkpm_auxfields *euler_pkpm_inp, - bool use_gpu) + const bool *is_zero_flux_dir, struct gkyl_dg_vlasov_pkpm_auxfields *vlasov_pkpm_inp, + struct gkyl_dg_euler_pkpm_auxfields *euler_pkpm_inp, bool use_gpu +) { gkyl_dg_updater_pkpm *up = gkyl_malloc(sizeof(gkyl_dg_updater_pkpm)); up->use_gpu = use_gpu; - up->eqn_vlasov = gkyl_dg_vlasov_pkpm_new(conf_basis, phase_basis, conf_range, phase_range, up->use_gpu); + up->eqn_vlasov = + gkyl_dg_vlasov_pkpm_new(conf_basis, phase_basis, conf_range, phase_range, up->use_gpu); gkyl_vlasov_pkpm_set_auxfields(up->eqn_vlasov, *vlasov_pkpm_inp); up->eqn_fluid = gkyl_dg_euler_pkpm_new(conf_basis, conf_range, up->use_gpu); gkyl_euler_pkpm_set_auxfields(up->eqn_fluid, *euler_pkpm_inp); int cdim = conf_basis->ndim, pdim = phase_basis->ndim; - int vdim = pdim-cdim; - int up_dirs_conf[GKYL_MAX_DIM], zero_flux_flags_conf[2*GKYL_MAX_DIM]; - int up_dirs_phase[GKYL_MAX_DIM], zero_flux_flags_phase[2*GKYL_MAX_DIM]; - for (int d=0; dup_vlasov = gkyl_hyper_dg_new(phase_grid, phase_basis, up->eqn_vlasov, num_up_dirs_phase, up_dirs_phase, zero_flux_flags_phase, 1, up->use_gpu); - up->up_fluid = gkyl_hyper_dg_new(conf_grid, conf_basis, up->eqn_fluid, num_up_dirs_conf, up_dirs_conf, zero_flux_flags_conf, 1, up->use_gpu); + up->up_vlasov = gkyl_hyper_dg_new( + phase_grid, phase_basis, up->eqn_vlasov, num_up_dirs_phase, up_dirs_phase, + zero_flux_flags_phase, 1, up->use_gpu + ); + up->up_fluid = gkyl_hyper_dg_new( + conf_grid, conf_basis, up->eqn_fluid, num_up_dirs_conf, up_dirs_conf, zero_flux_flags_conf, 1, + up->use_gpu + ); up->vlasov_tm = 0.0; up->fluid_tm = 0.0; - + return up; } -void -gkyl_dg_updater_pkpm_advance(gkyl_dg_updater_pkpm *pkpm, - const struct gkyl_range *update_phase_rng, const struct gkyl_range *update_conf_rng, - const struct gkyl_array* GKYL_RESTRICT fIn, const struct gkyl_array* GKYL_RESTRICT fluidIn, - struct gkyl_array* GKYL_RESTRICT cflrate_f, struct gkyl_array* GKYL_RESTRICT cflrate_fluid, - struct gkyl_array* GKYL_RESTRICT rhs_f, struct gkyl_array* GKYL_RESTRICT rhs_fluid) +void gkyl_dg_updater_pkpm_advance( + gkyl_dg_updater_pkpm *pkpm, const struct gkyl_range *update_phase_rng, + const struct gkyl_range *update_conf_rng, const struct gkyl_array *GKYL_RESTRICT fIn, + const struct gkyl_array *GKYL_RESTRICT fluidIn, struct gkyl_array *GKYL_RESTRICT cflrate_f, + struct gkyl_array *GKYL_RESTRICT cflrate_fluid, struct gkyl_array *GKYL_RESTRICT rhs_f, + struct gkyl_array *GKYL_RESTRICT rhs_fluid +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(pkpm->up_vlasov, update_phase_rng, fIn, cflrate_f, rhs_f); @@ -69,17 +77,12 @@ gkyl_dg_updater_pkpm_advance(gkyl_dg_updater_pkpm *pkpm, pkpm->fluid_tm += gkyl_time_diff_now_sec(wst); } -struct gkyl_dg_updater_pkpm_tm -gkyl_dg_updater_pkpm_get_tm(const gkyl_dg_updater_pkpm *pkpm) +struct gkyl_dg_updater_pkpm_tm gkyl_dg_updater_pkpm_get_tm(const gkyl_dg_updater_pkpm *pkpm) { - return (struct gkyl_dg_updater_pkpm_tm) { - .vlasov_tm = pkpm->vlasov_tm, - .fluid_tm = pkpm->fluid_tm, - }; + return (struct gkyl_dg_updater_pkpm_tm){.vlasov_tm = pkpm->vlasov_tm, .fluid_tm = pkpm->fluid_tm}; } -void -gkyl_dg_updater_pkpm_release(gkyl_dg_updater_pkpm* pkpm) +void gkyl_dg_updater_pkpm_release(gkyl_dg_updater_pkpm *pkpm) { gkyl_dg_eqn_release(pkpm->eqn_vlasov); gkyl_dg_eqn_release(pkpm->eqn_fluid); diff --git a/pkpm/zero/dg_vlasov_pkpm.c b/pkpm/zero/dg_vlasov_pkpm.c index c1731399b9..92021d0cb6 100644 --- a/pkpm/zero/dg_vlasov_pkpm.c +++ b/pkpm/zero/dg_vlasov_pkpm.c @@ -10,25 +10,25 @@ #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_vlasov_pkpm_free(const struct gkyl_ref_count *ref) +void gkyl_vlasov_pkpm_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); - + if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object struct dg_vlasov_pkpm *vlasov_pkpm = container_of(base->on_dev, struct dg_vlasov_pkpm, eqn); gkyl_cu_free(vlasov_pkpm); } - + struct dg_vlasov_pkpm *vlasov_pkpm = container_of(base, struct dg_vlasov_pkpm, eqn); gkyl_free(vlasov_pkpm); } -void -gkyl_vlasov_pkpm_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_pkpm_auxfields auxin) +void gkyl_vlasov_pkpm_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_pkpm_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_dg_eqn_is_cu_dev(eqn)) { @@ -44,19 +44,20 @@ gkyl_vlasov_pkpm_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vla vlasov_pkpm->auxfields.pkpm_prim_surf = auxin.pkpm_prim_surf; vlasov_pkpm->auxfields.max_b = auxin.max_b; vlasov_pkpm->auxfields.pkpm_lax = auxin.pkpm_lax; - vlasov_pkpm->auxfields.div_b = auxin.div_b; + vlasov_pkpm->auxfields.div_b = auxin.div_b; vlasov_pkpm->auxfields.pkpm_accel_vars = auxin.pkpm_accel_vars; vlasov_pkpm->auxfields.g_dist_source = auxin.g_dist_source; } -struct gkyl_dg_eqn* -gkyl_dg_vlasov_pkpm_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* phase_range, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_vlasov_pkpm_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_vlasov_pkpm_cu_dev_new(cbasis, pbasis, conf_range, phase_range); - } + } #endif struct dg_vlasov_pkpm *vlasov_pkpm = gkyl_malloc(sizeof(struct dg_vlasov_pkpm)); @@ -71,55 +72,60 @@ gkyl_dg_vlasov_pkpm_new(const struct gkyl_basis* cbasis, const struct gkyl_basis vlasov_pkpm->eqn.boundary_surf_term = boundary_surf; const gkyl_dg_vlasov_pkpm_vol_kern_list *vol_kernels; - const gkyl_dg_vlasov_pkpm_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, *stream_surf_z_kernels; + const gkyl_dg_vlasov_pkpm_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, + *stream_surf_z_kernels; const gkyl_dg_vlasov_pkpm_accel_surf_kern_list *accel_surf_vpar_kernels; const gkyl_dg_vlasov_pkpm_accel_boundary_surf_kern_list *accel_boundary_surf_vpar_kernels; - + switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - stream_surf_x_kernels = ser_stream_surf_x_kernels; - stream_surf_y_kernels = ser_stream_surf_y_kernels; - stream_surf_z_kernels = ser_stream_surf_z_kernels; - accel_surf_vpar_kernels = ser_accel_surf_vpar_kernels; - accel_boundary_surf_vpar_kernels = ser_accel_boundary_surf_vpar_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - stream_surf_x_kernels = ten_stream_surf_x_kernels; - stream_surf_y_kernels = ten_stream_surf_y_kernels; - stream_surf_z_kernels = ten_stream_surf_z_kernels; - accel_surf_vpar_kernels = ten_accel_surf_vpar_kernels; - accel_boundary_surf_vpar_kernels = ten_accel_boundary_surf_vpar_kernels; - - break; - - default: - assert(false); - break; - } - - vlasov_pkpm->eqn.vol_term = CK(vol_kernels,cdim,poly_order); - - vlasov_pkpm->stream_surf[0] = CK(stream_surf_x_kernels,cdim,poly_order); - if (cdim>1) - vlasov_pkpm->stream_surf[1] = CK(stream_surf_y_kernels,cdim,poly_order); - if (cdim>2) - vlasov_pkpm->stream_surf[2] = CK(stream_surf_z_kernels,cdim,poly_order); - - vlasov_pkpm->accel_surf = CK(accel_surf_vpar_kernels,cdim,poly_order); - - vlasov_pkpm->accel_boundary_surf = CK(accel_boundary_surf_vpar_kernels,cdim,poly_order); + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + stream_surf_x_kernels = ser_stream_surf_x_kernels; + stream_surf_y_kernels = ser_stream_surf_y_kernels; + stream_surf_z_kernels = ser_stream_surf_z_kernels; + accel_surf_vpar_kernels = ser_accel_surf_vpar_kernels; + accel_boundary_surf_vpar_kernels = ser_accel_boundary_surf_vpar_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + stream_surf_x_kernels = ten_stream_surf_x_kernels; + stream_surf_y_kernels = ten_stream_surf_y_kernels; + stream_surf_z_kernels = ten_stream_surf_z_kernels; + accel_surf_vpar_kernels = ten_accel_surf_vpar_kernels; + accel_boundary_surf_vpar_kernels = ten_accel_boundary_surf_vpar_kernels; + + break; + + default: + assert(false); + break; + } + + vlasov_pkpm->eqn.vol_term = CK(vol_kernels, cdim, poly_order); + + vlasov_pkpm->stream_surf[0] = CK(stream_surf_x_kernels, cdim, poly_order); + if (cdim > 1) { + vlasov_pkpm->stream_surf[1] = CK(stream_surf_y_kernels, cdim, poly_order); + } + if (cdim > 2) { + vlasov_pkpm->stream_surf[2] = CK(stream_surf_z_kernels, cdim, poly_order); + } + + vlasov_pkpm->accel_surf = CK(accel_surf_vpar_kernels, cdim, poly_order); + + vlasov_pkpm->accel_boundary_surf = CK(accel_boundary_surf_vpar_kernels, cdim, poly_order); // ensure non-NULL pointers - for (int i=0; istream_surf[i]); + for (int i = 0; i < cdim; ++i) { + assert(vlasov_pkpm->stream_surf[i]); + } assert(vlasov_pkpm->accel_surf); assert(vlasov_pkpm->accel_boundary_surf); - vlasov_pkpm->auxfields.bvar = 0; - vlasov_pkpm->auxfields.bvar_surf = 0; + vlasov_pkpm->auxfields.bvar = 0; + vlasov_pkpm->auxfields.bvar_surf = 0; vlasov_pkpm->auxfields.pkpm_prim = 0; vlasov_pkpm->auxfields.pkpm_prim_surf = 0; vlasov_pkpm->auxfields.max_b = 0; @@ -135,15 +141,16 @@ gkyl_dg_vlasov_pkpm_new(const struct gkyl_basis* cbasis, const struct gkyl_basis vlasov_pkpm->eqn.ref_count = gkyl_ref_count_init(gkyl_vlasov_pkpm_free); vlasov_pkpm->eqn.on_dev = &vlasov_pkpm->eqn; // CPU eqn obj points to itself - + return &vlasov_pkpm->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_vlasov_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* phase_range) +struct gkyl_dg_eqn *gkyl_dg_vlasov_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range +) { assert(false); return 0; diff --git a/pkpm/zero/dg_vlasov_pkpm_cu.cu b/pkpm/zero/dg_vlasov_pkpm_cu.cu index 7204b58698..01260f33bf 100644 --- a/pkpm/zero/dg_vlasov_pkpm_cu.cu +++ b/pkpm/zero/dg_vlasov_pkpm_cu.cu @@ -3,25 +3,24 @@ extern "C" { #include #include -#include +#include #include } #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_vlasov_pkpm_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array *bvar, const struct gkyl_array *bvar_surf, - const struct gkyl_array *pkpm_prim, const struct gkyl_array *pkpm_prim_surf, - const struct gkyl_array *max_b, const struct gkyl_array *pkpm_lax, - const struct gkyl_array *div_b, const struct gkyl_array *pkpm_accel_vars, - const struct gkyl_array *g_dist_source) +__global__ static void gkyl_vlasov_pkpm_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *bvar, const struct gkyl_array *bvar_surf, + const struct gkyl_array *pkpm_prim, const struct gkyl_array *pkpm_prim_surf, + const struct gkyl_array *max_b, const struct gkyl_array *pkpm_lax, const struct gkyl_array *div_b, + const struct gkyl_array *pkpm_accel_vars, const struct gkyl_array *g_dist_source +) { struct dg_vlasov_pkpm *vlasov_pkpm = container_of(eqn, struct dg_vlasov_pkpm, eqn); vlasov_pkpm->auxfields.bvar = bvar; @@ -36,25 +35,25 @@ gkyl_vlasov_pkpm_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_vlasov_pkpm_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_pkpm_auxfields auxin) +void gkyl_vlasov_pkpm_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_pkpm_auxfields auxin +) { - gkyl_vlasov_pkpm_set_auxfields_cu_kernel<<<1,1>>>(eqn, - auxin.bvar->on_dev, auxin.bvar_surf->on_dev, - auxin.pkpm_prim->on_dev, auxin.pkpm_prim_surf->on_dev, - auxin.max_b->on_dev, auxin.pkpm_lax->on_dev, - auxin.div_b->on_dev, auxin.pkpm_accel_vars->on_dev, - auxin.g_dist_source->on_dev); + gkyl_vlasov_pkpm_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.bvar->on_dev, auxin.bvar_surf->on_dev, auxin.pkpm_prim->on_dev, + auxin.pkpm_prim_surf->on_dev, auxin.max_b->on_dev, auxin.pkpm_lax->on_dev, auxin.div_b->on_dev, + auxin.pkpm_accel_vars->on_dev, auxin.g_dist_source->on_dev + ); } // CUDA kernel to set device pointers to range object and vlasov_pkpm kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_vlasov_pkpm_set_cu_dev_ptrs(struct dg_vlasov_pkpm *vlasov_pkpm, enum gkyl_basis_type b_type, - int cdim, int poly_order) +__global__ static void dg_vlasov_pkpm_set_cu_dev_ptrs( + struct dg_vlasov_pkpm *vlasov_pkpm, enum gkyl_basis_type b_type, int cdim, int poly_order +) { - vlasov_pkpm->auxfields.bvar = 0; - vlasov_pkpm->auxfields.bvar_surf = 0; + vlasov_pkpm->auxfields.bvar = 0; + vlasov_pkpm->auxfields.bvar_surf = 0; vlasov_pkpm->auxfields.pkpm_prim = 0; vlasov_pkpm->auxfields.pkpm_prim_surf = 0; vlasov_pkpm->auxfields.max_b = 0; @@ -67,54 +66,59 @@ dg_vlasov_pkpm_set_cu_dev_ptrs(struct dg_vlasov_pkpm *vlasov_pkpm, enum gkyl_bas vlasov_pkpm->eqn.boundary_surf_term = boundary_surf; const gkyl_dg_vlasov_pkpm_vol_kern_list *vol_kernels; - const gkyl_dg_vlasov_pkpm_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, *stream_surf_z_kernels; + const gkyl_dg_vlasov_pkpm_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, + *stream_surf_z_kernels; const gkyl_dg_vlasov_pkpm_accel_surf_kern_list *accel_surf_vpar_kernels; const gkyl_dg_vlasov_pkpm_accel_boundary_surf_kern_list *accel_boundary_surf_vpar_kernels; - + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - stream_surf_x_kernels = ser_stream_surf_x_kernels; - stream_surf_y_kernels = ser_stream_surf_y_kernels; - stream_surf_z_kernels = ser_stream_surf_z_kernels; - accel_surf_vpar_kernels = ser_accel_surf_vpar_kernels; - accel_boundary_surf_vpar_kernels = ser_accel_boundary_surf_vpar_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - stream_surf_x_kernels = ten_stream_surf_x_kernels; - stream_surf_y_kernels = ten_stream_surf_y_kernels; - stream_surf_z_kernels = ten_stream_surf_z_kernels; - accel_surf_vpar_kernels = ten_accel_surf_vpar_kernels; - accel_boundary_surf_vpar_kernels = ten_accel_boundary_surf_vpar_kernels; - - break; - - default: - assert(false); - break; - } - - vlasov_pkpm->eqn.vol_term = CK(vol_kernels,cdim,poly_order); - - vlasov_pkpm->stream_surf[0] = CK(stream_surf_x_kernels,cdim,poly_order); - if (cdim>1) - vlasov_pkpm->stream_surf[1] = CK(stream_surf_y_kernels,cdim,poly_order); - if (cdim>2) - vlasov_pkpm->stream_surf[2] = CK(stream_surf_z_kernels,cdim,poly_order); - - vlasov_pkpm->accel_surf = CK(accel_surf_vpar_kernels,cdim,poly_order); - - vlasov_pkpm->accel_boundary_surf = CK(accel_boundary_surf_vpar_kernels,cdim,poly_order); + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + stream_surf_x_kernels = ser_stream_surf_x_kernels; + stream_surf_y_kernels = ser_stream_surf_y_kernels; + stream_surf_z_kernels = ser_stream_surf_z_kernels; + accel_surf_vpar_kernels = ser_accel_surf_vpar_kernels; + accel_boundary_surf_vpar_kernels = ser_accel_boundary_surf_vpar_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + stream_surf_x_kernels = ten_stream_surf_x_kernels; + stream_surf_y_kernels = ten_stream_surf_y_kernels; + stream_surf_z_kernels = ten_stream_surf_z_kernels; + accel_surf_vpar_kernels = ten_accel_surf_vpar_kernels; + accel_boundary_surf_vpar_kernels = ten_accel_boundary_surf_vpar_kernels; + + break; + + default: + assert(false); + break; + } + + vlasov_pkpm->eqn.vol_term = CK(vol_kernels, cdim, poly_order); + + vlasov_pkpm->stream_surf[0] = CK(stream_surf_x_kernels, cdim, poly_order); + if (cdim > 1) { + vlasov_pkpm->stream_surf[1] = CK(stream_surf_y_kernels, cdim, poly_order); + } + if (cdim > 2) { + vlasov_pkpm->stream_surf[2] = CK(stream_surf_z_kernels, cdim, poly_order); + } + + vlasov_pkpm->accel_surf = CK(accel_surf_vpar_kernels, cdim, poly_order); + + vlasov_pkpm->accel_boundary_surf = CK(accel_boundary_surf_vpar_kernels, cdim, poly_order); } -struct gkyl_dg_eqn* -gkyl_dg_vlasov_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* phase_range) +struct gkyl_dg_eqn *gkyl_dg_vlasov_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range +) { - struct dg_vlasov_pkpm *vlasov_pkpm = (struct dg_vlasov_pkpm*) gkyl_malloc(sizeof(struct dg_vlasov_pkpm)); + struct dg_vlasov_pkpm *vlasov_pkpm = + (struct dg_vlasov_pkpm *)gkyl_malloc(sizeof(struct dg_vlasov_pkpm)); int cdim = cbasis->ndim, pdim = pbasis->ndim; int poly_order = cbasis->poly_order; @@ -131,13 +135,14 @@ gkyl_dg_vlasov_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, const struct gky vlasov_pkpm->eqn.ref_count = gkyl_ref_count_init(gkyl_vlasov_pkpm_free); // copy the host struct to device struct - struct dg_vlasov_pkpm *vlasov_pkpm_cu = (struct dg_vlasov_pkpm*) gkyl_cu_malloc(sizeof(struct dg_vlasov_pkpm)); + struct dg_vlasov_pkpm *vlasov_pkpm_cu = + (struct dg_vlasov_pkpm *)gkyl_cu_malloc(sizeof(struct dg_vlasov_pkpm)); gkyl_cu_memcpy(vlasov_pkpm_cu, vlasov_pkpm, sizeof(struct dg_vlasov_pkpm), GKYL_CU_MEMCPY_H2D); - dg_vlasov_pkpm_set_cu_dev_ptrs<<<1,1>>>(vlasov_pkpm_cu, cbasis->b_type, cdim, poly_order); + dg_vlasov_pkpm_set_cu_dev_ptrs<<<1, 1> > >(vlasov_pkpm_cu, cbasis->b_type, cdim, poly_order); // set parent on_dev pointer vlasov_pkpm->eqn.on_dev = &vlasov_pkpm_cu->eqn; - + return &vlasov_pkpm->eqn; } diff --git a/pkpm/zero/gkyl_dg_calc_pkpm_dist_vars.h b/pkpm/zero/gkyl_dg_calc_pkpm_dist_vars.h index 5378288af9..58d43bf7b4 100644 --- a/pkpm/zero/gkyl_dg_calc_pkpm_dist_vars.h +++ b/pkpm/zero/gkyl_dg_calc_pkpm_dist_vars.h @@ -22,17 +22,17 @@ typedef struct gkyl_dg_calc_pkpm_dist_vars gkyl_dg_calc_pkpm_dist_vars; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_dg_calc_pkpm_dist_vars* -gkyl_dg_calc_pkpm_dist_vars_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis* cbasis, bool use_gpu); +struct gkyl_dg_calc_pkpm_dist_vars *gkyl_dg_calc_pkpm_dist_vars_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *cbasis, bool use_gpu +); /** * Create new updater to compute pkpm variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_dg_calc_pkpm_dist_vars* -gkyl_dg_calc_pkpm_dist_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis* cbasis); +struct gkyl_dg_calc_pkpm_dist_vars *gkyl_dg_calc_pkpm_dist_vars_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *cbasis +); /** * Compute parallel-kinetic-perpendicular-moment model distribution function @@ -63,12 +63,13 @@ gkyl_dg_calc_pkpm_dist_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, * @param g_dist_source Output array: 2.0*(T_perp/m*G) + T_perp/m*(F_2 - F_0) * @param F_k_m_1 Output array of k-1 distribution function. F_1 expansion is the first NP coefficients. */ -void gkyl_dg_calc_pkpm_dist_vars_mirror_force(struct gkyl_dg_calc_pkpm_dist_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* pkpm_prim, const struct gkyl_array* nu_prim_moms_sum, - const struct gkyl_array* div_b, const struct gkyl_array* pkpm_accel_vars, - const struct gkyl_array* fIn, const struct gkyl_array* F_k_p_1, - struct gkyl_array* g_dist_source, struct gkyl_array* F_k_m_1); +void gkyl_dg_calc_pkpm_dist_vars_mirror_force( + struct gkyl_dg_calc_pkpm_dist_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *pkpm_prim, + const struct gkyl_array *nu_prim_moms_sum, const struct gkyl_array *div_b, + const struct gkyl_array *pkpm_accel_vars, const struct gkyl_array *fIn, + const struct gkyl_array *F_k_p_1, struct gkyl_array *g_dist_source, struct gkyl_array *F_k_m_1 +); /** * Compute divergence of parallel pressure for use in pressure force in kinetic equation. @@ -83,10 +84,12 @@ void gkyl_dg_calc_pkpm_dist_vars_mirror_force(struct gkyl_dg_calc_pkpm_dist_vars * @param max_b Input array of surface expansion of max(|b_i|) penalization * @param pkpm_div_ppar Output array of divergence of p_parallel b_hat */ -void gkyl_dg_calc_pkpm_dist_vars_div_ppar(struct gkyl_dg_calc_pkpm_dist_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* bvar_surf, const struct gkyl_array* bvar, const struct gkyl_array* fIn, - const struct gkyl_array* max_b, struct gkyl_array* pkpm_div_ppar); +void gkyl_dg_calc_pkpm_dist_vars_div_ppar( + struct gkyl_dg_calc_pkpm_dist_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *bvar_surf, + const struct gkyl_array *bvar, const struct gkyl_array *fIn, const struct gkyl_array *max_b, + struct gkyl_array *pkpm_div_ppar +); /** * Delete pointer to updater to compute pkpm variables. @@ -99,15 +102,17 @@ void gkyl_dg_calc_pkpm_dist_vars_release(struct gkyl_dg_calc_pkpm_dist_vars *up) * Host-side wrappers for pkpm dist vars operations on device */ -void gkyl_dg_calc_pkpm_dist_vars_mirror_force_cu(struct gkyl_dg_calc_pkpm_dist_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* pkpm_prim, const struct gkyl_array* nu_prim_moms_sum, - const struct gkyl_array* div_b, const struct gkyl_array* pkpm_accel_vars, - const struct gkyl_array* fIn, const struct gkyl_array* F_k_p_1, - struct gkyl_array* g_dist_source, struct gkyl_array* F_k_m_1); - -void gkyl_dg_calc_pkpm_dist_vars_div_ppar_cu(struct gkyl_dg_calc_pkpm_dist_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* bvar_surf, const struct gkyl_array* bvar, const struct gkyl_array* fIn, - const struct gkyl_array* max_b, struct gkyl_array* pkpm_div_ppar); +void gkyl_dg_calc_pkpm_dist_vars_mirror_force_cu( + struct gkyl_dg_calc_pkpm_dist_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *pkpm_prim, + const struct gkyl_array *nu_prim_moms_sum, const struct gkyl_array *div_b, + const struct gkyl_array *pkpm_accel_vars, const struct gkyl_array *fIn, + const struct gkyl_array *F_k_p_1, struct gkyl_array *g_dist_source, struct gkyl_array *F_k_m_1 +); +void gkyl_dg_calc_pkpm_dist_vars_div_ppar_cu( + struct gkyl_dg_calc_pkpm_dist_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *bvar_surf, + const struct gkyl_array *bvar, const struct gkyl_array *fIn, const struct gkyl_array *max_b, + struct gkyl_array *pkpm_div_ppar +); diff --git a/pkpm/zero/gkyl_dg_calc_pkpm_dist_vars_priv.h b/pkpm/zero/gkyl_dg_calc_pkpm_dist_vars_priv.h index 967d49f9dc..8afc4d6e93 100644 --- a/pkpm/zero/gkyl_dg_calc_pkpm_dist_vars_priv.h +++ b/pkpm/zero/gkyl_dg_calc_pkpm_dist_vars_priv.h @@ -10,139 +10,139 @@ #include #include -typedef void (*pkpm_dist_mirror_force_t)(const double *w, const double *dxv, - const double *pkpm_prim, const double *nu_prim_moms_sum, - const double *div_b, const double *pkpm_accel_vars, - const double *f, const double *F_k_p_1, - double* GKYL_RESTRICT g_dist_source, double* GKYL_RESTRICT F_k_m_1); - -typedef void (*pkpm_dist_div_ppar_t)(const double *w, const double *dxv, - const double *bvar_surf_l, const double *bvar_surf_c, const double *bvar_surf_r, - const double *fl, const double *fc, const double *fr, - const double *bvar_c, const double *pkpm_max_b, double* GKYL_RESTRICT pkpm_div_ppar); +typedef void (*pkpm_dist_mirror_force_t)( + const double *w, const double *dxv, const double *pkpm_prim, const double *nu_prim_moms_sum, + const double *div_b, const double *pkpm_accel_vars, const double *f, const double *F_k_p_1, + double *GKYL_RESTRICT g_dist_source, double *GKYL_RESTRICT F_k_m_1 +); + +typedef void (*pkpm_dist_div_ppar_t)( + const double *w, const double *dxv, const double *bvar_surf_l, const double *bvar_surf_c, + const double *bvar_surf_r, const double *fl, const double *fc, const double *fr, + const double *bvar_c, const double *pkpm_max_b, double *GKYL_RESTRICT pkpm_div_ppar +); // for use in kernel tables -typedef struct { pkpm_dist_mirror_force_t kernels[3]; } gkyl_dg_pkpm_dist_mirror_force_kern_list; -typedef struct { pkpm_dist_div_ppar_t kernels[3]; } gkyl_dg_pkpm_dist_div_ppar_kern_list; +typedef struct { + pkpm_dist_mirror_force_t kernels[3]; +} gkyl_dg_pkpm_dist_mirror_force_kern_list; +typedef struct { + pkpm_dist_div_ppar_t kernels[3]; +} gkyl_dg_pkpm_dist_div_ppar_kern_list; struct gkyl_dg_calc_pkpm_dist_vars { struct gkyl_rect_grid phase_grid; // Phase space grid for cell spacing and cell center int cdim; // Configuration space dimensionality - pkpm_dist_mirror_force_t pkpm_dist_mirror_force; // kernel for computing distribution function sources - pkpm_dist_div_ppar_t pkpm_dist_div_ppar[3]; // kernel for computing consistent div(p_par b) + pkpm_dist_mirror_force_t + pkpm_dist_mirror_force; // kernel for computing distribution function sources + pkpm_dist_div_ppar_t pkpm_dist_div_ppar[3]; // kernel for computing consistent div(p_par b) uint32_t flags; struct gkyl_dg_calc_pkpm_dist_vars *on_dev; // pointer to itself or device data }; // PKPM distribution function source in mirror force and vperp characteristics (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_dist_mirror_force_kern_list ser_pkpm_dist_mirror_force_kernels[] = { - { NULL, pkpm_dist_mirror_force_1x1v_ser_p1, pkpm_dist_mirror_force_1x1v_ser_p2 }, // 0 - { NULL, pkpm_dist_mirror_force_2x1v_ser_p1, NULL }, // 1 - { NULL, pkpm_dist_mirror_force_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_dist_mirror_force_kern_list + ser_pkpm_dist_mirror_force_kernels[] = { + {NULL, pkpm_dist_mirror_force_1x1v_ser_p1, pkpm_dist_mirror_force_1x1v_ser_p2}, // 0 + {NULL, pkpm_dist_mirror_force_2x1v_ser_p1, NULL}, // 1 + {NULL, pkpm_dist_mirror_force_3x1v_ser_p1, NULL} // 2 }; // PKPM distribution function source in mirror force and vperp characteristics (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_dist_mirror_force_kern_list ten_pkpm_dist_mirror_force_kernels[] = { - { NULL, pkpm_dist_mirror_force_1x1v_ser_p1, pkpm_dist_mirror_force_1x1v_tensor_p2 }, // 0 - { NULL, pkpm_dist_mirror_force_2x1v_ser_p1, pkpm_dist_mirror_force_2x1v_tensor_p2 }, // 1 - { NULL, pkpm_dist_mirror_force_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_dist_mirror_force_kern_list + ten_pkpm_dist_mirror_force_kernels[] = { + {NULL, pkpm_dist_mirror_force_1x1v_ser_p1, pkpm_dist_mirror_force_1x1v_tensor_p2}, // 0 + {NULL, pkpm_dist_mirror_force_2x1v_ser_p1, pkpm_dist_mirror_force_2x1v_tensor_p2}, // 1 + {NULL, pkpm_dist_mirror_force_3x1v_ser_p1, NULL} // 2 }; // PKPM consistent div(p_par b) (in x) kernels (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_dist_div_ppar_kern_list ser_pkpm_dist_div_ppar_x_kernels[] = { - { NULL, pkpm_dist_div_ppar_x_1x1v_ser_p1, pkpm_dist_div_ppar_x_1x1v_ser_p2 }, // 0 - { NULL, pkpm_dist_div_ppar_x_2x1v_ser_p1, NULL }, // 1 - { NULL, pkpm_dist_div_ppar_x_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_dist_div_ppar_kern_list ser_pkpm_dist_div_ppar_x_kernels[] = { + {NULL, pkpm_dist_div_ppar_x_1x1v_ser_p1, pkpm_dist_div_ppar_x_1x1v_ser_p2}, // 0 + {NULL, pkpm_dist_div_ppar_x_2x1v_ser_p1, NULL}, // 1 + {NULL, pkpm_dist_div_ppar_x_3x1v_ser_p1, NULL} // 2 }; // PKPM consistent div(p_par b) (in y) kernels (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_dist_div_ppar_kern_list ser_pkpm_dist_div_ppar_y_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, pkpm_dist_div_ppar_y_2x1v_ser_p1, NULL }, // 1 - { NULL, pkpm_dist_div_ppar_y_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_dist_div_ppar_kern_list ser_pkpm_dist_div_ppar_y_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, pkpm_dist_div_ppar_y_2x1v_ser_p1, NULL}, // 1 + {NULL, pkpm_dist_div_ppar_y_3x1v_ser_p1, NULL} // 2 }; // PKPM consistent div(p_par b) (in z) kernels (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_dist_div_ppar_kern_list ser_pkpm_dist_div_ppar_z_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, pkpm_dist_div_ppar_z_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_dist_div_ppar_kern_list ser_pkpm_dist_div_ppar_z_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, pkpm_dist_div_ppar_z_3x1v_ser_p1, NULL} // 2 }; // PKPM consistent div(p_par b) (in x) kernels (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_dist_div_ppar_kern_list ten_pkpm_dist_div_ppar_x_kernels[] = { - { NULL, pkpm_dist_div_ppar_x_1x1v_ser_p1, pkpm_dist_div_ppar_x_1x1v_tensor_p2 }, // 0 - { NULL, pkpm_dist_div_ppar_x_2x1v_ser_p1, pkpm_dist_div_ppar_x_2x1v_tensor_p2 }, // 1 - { NULL, pkpm_dist_div_ppar_x_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_dist_div_ppar_kern_list ten_pkpm_dist_div_ppar_x_kernels[] = { + {NULL, pkpm_dist_div_ppar_x_1x1v_ser_p1, pkpm_dist_div_ppar_x_1x1v_tensor_p2}, // 0 + {NULL, pkpm_dist_div_ppar_x_2x1v_ser_p1, pkpm_dist_div_ppar_x_2x1v_tensor_p2}, // 1 + {NULL, pkpm_dist_div_ppar_x_3x1v_ser_p1, NULL} // 2 }; // PKPM consistent div(p_par b) (in y) kernels (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_dist_div_ppar_kern_list ten_pkpm_dist_div_ppar_y_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, pkpm_dist_div_ppar_y_2x1v_ser_p1, pkpm_dist_div_ppar_y_2x1v_tensor_p2 }, // 1 - { NULL, pkpm_dist_div_ppar_y_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_dist_div_ppar_kern_list ten_pkpm_dist_div_ppar_y_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, pkpm_dist_div_ppar_y_2x1v_ser_p1, pkpm_dist_div_ppar_y_2x1v_tensor_p2}, // 1 + {NULL, pkpm_dist_div_ppar_y_3x1v_ser_p1, NULL} // 2 }; // PKPM consistent div(p_par b) (in z) kernels (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_dist_div_ppar_kern_list ten_pkpm_dist_div_ppar_z_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, pkpm_dist_div_ppar_z_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_dist_div_ppar_kern_list ten_pkpm_dist_div_ppar_z_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, pkpm_dist_div_ppar_z_3x1v_ser_p1, NULL} // 2 }; -GKYL_CU_D -static pkpm_dist_mirror_force_t +GKYL_CU_D static pkpm_dist_mirror_force_t choose_pkpm_dist_mirror_force_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_dist_mirror_force_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_dist_mirror_force_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_dist_mirror_force_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_dist_mirror_force_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_dist_div_ppar_t +GKYL_CU_D static pkpm_dist_div_ppar_t choose_pkpm_dist_div_ppar_kern(int dir, enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (dir == 0) - return ser_pkpm_dist_div_ppar_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ser_pkpm_dist_div_ppar_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ser_pkpm_dist_div_ppar_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return ten_pkpm_dist_div_ppar_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ten_pkpm_dist_div_ppar_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ten_pkpm_dist_div_ppar_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + if (dir == 0) { + return ser_pkpm_dist_div_ppar_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ser_pkpm_dist_div_ppar_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ser_pkpm_dist_div_ppar_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return ten_pkpm_dist_div_ppar_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ten_pkpm_dist_div_ppar_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ten_pkpm_dist_div_ppar_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } diff --git a/pkpm/zero/gkyl_dg_calc_pkpm_em_coupling.h b/pkpm/zero/gkyl_dg_calc_pkpm_em_coupling.h index 137ab49c33..004c8dd02a 100644 --- a/pkpm/zero/gkyl_dg_calc_pkpm_em_coupling.h +++ b/pkpm/zero/gkyl_dg_calc_pkpm_em_coupling.h @@ -31,21 +31,19 @@ typedef struct gkyl_dg_calc_pkpm_em_coupling gkyl_dg_calc_pkpm_em_coupling; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_dg_calc_pkpm_em_coupling* -gkyl_dg_calc_pkpm_em_coupling_new(const struct gkyl_basis* cbasis, - const struct gkyl_range *mem_range, - int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, - bool pkpm_field_static, bool use_gpu); +struct gkyl_dg_calc_pkpm_em_coupling *gkyl_dg_calc_pkpm_em_coupling_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, int num_species, + double qbym[GKYL_MAX_SPECIES], double epsilon0, bool pkpm_field_static, bool use_gpu +); /** * Create new updater to compute fluid variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_dg_calc_pkpm_em_coupling* -gkyl_dg_calc_pkpm_em_coupling_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_range *mem_range, - int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, - bool pkpm_field_static); +struct gkyl_dg_calc_pkpm_em_coupling *gkyl_dg_calc_pkpm_em_coupling_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, int num_species, + double qbym[GKYL_MAX_SPECIES], double epsilon0, bool pkpm_field_static +); /** * Compute the updated fluid momentum and electric field implicitly from time-centered source solve. @@ -61,11 +59,13 @@ gkyl_dg_calc_pkpm_em_coupling_cu_dev_new(const struct gkyl_basis* cbasis, * (update is done in place with electric field modified to new time) * */ -void gkyl_dg_calc_pkpm_em_coupling_advance(struct gkyl_dg_calc_pkpm_em_coupling *up, double dt, - const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - const struct gkyl_array* vlasov_pkpm_moms[GKYL_MAX_SPECIES], const struct gkyl_array* pkpm_u[GKYL_MAX_SPECIES], - struct gkyl_array* euler_pkpm[GKYL_MAX_SPECIES], struct gkyl_array* em); +void gkyl_dg_calc_pkpm_em_coupling_advance( + struct gkyl_dg_calc_pkpm_em_coupling *up, double dt, + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], const struct gkyl_array *ext_em, + const struct gkyl_array *app_current, const struct gkyl_array *vlasov_pkpm_moms[GKYL_MAX_SPECIES], + const struct gkyl_array *pkpm_u[GKYL_MAX_SPECIES], + struct gkyl_array *euler_pkpm[GKYL_MAX_SPECIES], struct gkyl_array *em +); /** * Delete pointer to updater to compute fluid variables. @@ -78,8 +78,10 @@ void gkyl_dg_calc_pkpm_em_coupling_release(struct gkyl_dg_calc_pkpm_em_coupling * Host-side wrappers for fluid vars operations on device */ -void gkyl_dg_calc_pkpm_em_coupling_advance_cu(struct gkyl_dg_calc_pkpm_em_coupling *up, double dt, - const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - const struct gkyl_array* vlasov_pkpm_moms[GKYL_MAX_SPECIES], const struct gkyl_array* pkpm_u[GKYL_MAX_SPECIES], - struct gkyl_array* euler_pkpm[GKYL_MAX_SPECIES], struct gkyl_array* em); +void gkyl_dg_calc_pkpm_em_coupling_advance_cu( + struct gkyl_dg_calc_pkpm_em_coupling *up, double dt, + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], const struct gkyl_array *ext_em, + const struct gkyl_array *app_current, const struct gkyl_array *vlasov_pkpm_moms[GKYL_MAX_SPECIES], + const struct gkyl_array *pkpm_u[GKYL_MAX_SPECIES], + struct gkyl_array *euler_pkpm[GKYL_MAX_SPECIES], struct gkyl_array *em +); diff --git a/pkpm/zero/gkyl_dg_calc_pkpm_em_coupling_priv.h b/pkpm/zero/gkyl_dg_calc_pkpm_em_coupling_priv.h index 2bc05fd6cb..61bdaa1dc2 100644 --- a/pkpm/zero/gkyl_dg_calc_pkpm_em_coupling_priv.h +++ b/pkpm/zero/gkyl_dg_calc_pkpm_em_coupling_priv.h @@ -11,22 +11,27 @@ #include #include -typedef void (*pkpm_em_coupling_set_t)(int count, - int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, bool pkpm_field_static, double dt, - struct gkyl_nmat *A, struct gkyl_nmat *rhs, - const double *app_accel[GKYL_MAX_SPECIES], const double *ext_em, const double *app_current, +typedef void (*pkpm_em_coupling_set_t)( + int count, int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, + bool pkpm_field_static, double dt, struct gkyl_nmat *A, struct gkyl_nmat *rhs, + const double *app_accel[GKYL_MAX_SPECIES], const double *ext_em, const double *app_current, const double *vlasov_pkpm_moms[GKYL_MAX_SPECIES], const double *pkpm_u[GKYL_MAX_SPECIES], - double* GKYL_RESTRICT em); + double *GKYL_RESTRICT em +); -typedef void (*pkpm_em_coupling_copy_t)(int count, - int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, - struct gkyl_nmat *x, - const double *vlasov_pkpm_moms[GKYL_MAX_SPECIES], const double *pkpm_u[GKYL_MAX_SPECIES], - double* GKYL_RESTRICT euler_pkpm[GKYL_MAX_SPECIES], double* GKYL_RESTRICT em); +typedef void (*pkpm_em_coupling_copy_t)( + int count, int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, struct gkyl_nmat *x, + const double *vlasov_pkpm_moms[GKYL_MAX_SPECIES], const double *pkpm_u[GKYL_MAX_SPECIES], + double *GKYL_RESTRICT euler_pkpm[GKYL_MAX_SPECIES], double *GKYL_RESTRICT em +); // for use in kernel tables -typedef struct { pkpm_em_coupling_set_t kernels[4]; } gkyl_dg_pkpm_em_coupling_set_kern_list; -typedef struct { pkpm_em_coupling_copy_t kernels[4]; } gkyl_dg_pkpm_em_coupling_copy_kern_list; +typedef struct { + pkpm_em_coupling_set_t kernels[4]; +} gkyl_dg_pkpm_em_coupling_set_kern_list; +typedef struct { + pkpm_em_coupling_copy_t kernels[4]; +} gkyl_dg_pkpm_em_coupling_copy_kern_list; struct gkyl_dg_calc_pkpm_em_coupling { struct gkyl_range mem_range; // Configuration space range for linear solve @@ -34,10 +39,11 @@ struct gkyl_dg_calc_pkpm_em_coupling { struct gkyl_nmat *As, *xs; // matrices for LHS and RHS gkyl_nmat_mem *mem; // memory for use in batched linear solve - pkpm_em_coupling_set_t pkpm_em_coupling_set; // kernel for setting matrices for linear solve + pkpm_em_coupling_set_t pkpm_em_coupling_set; // kernel for setting matrices for linear solve pkpm_em_coupling_copy_t pkpm_em_coupling_copy; // kernel for copying solution to output - bool pkpm_field_static; // bool to determine if we are updating the self-consistent EM fields (dE/dt) + bool + pkpm_field_static; // bool to determine if we are updating the self-consistent EM fields (dE/dt) int num_species; // number of species being implicitly solved for double qbym[GKYL_MAX_SPECIES]; // charge/mass ratio for each species @@ -48,67 +54,68 @@ struct gkyl_dg_calc_pkpm_em_coupling { }; // Set matrices for computing implicit source solve for fluid-em coupling in the PKPM system. (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_em_coupling_set_kern_list ser_pkpm_em_coupling_set_kernels[] = { - { NULL, euler_pkpm_em_coupling_set_1x_ser_p1, euler_pkpm_em_coupling_set_1x_ser_p2, euler_pkpm_em_coupling_set_1x_ser_p3 }, // 0 - { NULL, euler_pkpm_em_coupling_set_2x_ser_p1, NULL, NULL }, // 1 - { NULL, euler_pkpm_em_coupling_set_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_em_coupling_set_kern_list ser_pkpm_em_coupling_set_kernels[] = { + {NULL, euler_pkpm_em_coupling_set_1x_ser_p1, euler_pkpm_em_coupling_set_1x_ser_p2, + euler_pkpm_em_coupling_set_1x_ser_p3}, // 0 + {NULL, euler_pkpm_em_coupling_set_2x_ser_p1, NULL, NULL}, // 1 + {NULL, euler_pkpm_em_coupling_set_3x_ser_p1, NULL, NULL} // 2 }; // Set matrices for computing implicit source solve for fluid-em coupling in the PKPM system. (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_em_coupling_set_kern_list ten_pkpm_em_coupling_set_kernels[] = { - { NULL, euler_pkpm_em_coupling_set_1x_ser_p1, euler_pkpm_em_coupling_set_1x_ser_p2, euler_pkpm_em_coupling_set_1x_ser_p3 }, // 0 - { NULL, euler_pkpm_em_coupling_set_2x_ser_p1, euler_pkpm_em_coupling_set_2x_tensor_p2, NULL }, // 1 - { NULL, euler_pkpm_em_coupling_set_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_em_coupling_set_kern_list ten_pkpm_em_coupling_set_kernels[] = { + {NULL, euler_pkpm_em_coupling_set_1x_ser_p1, euler_pkpm_em_coupling_set_1x_ser_p2, + euler_pkpm_em_coupling_set_1x_ser_p3}, // 0 + {NULL, euler_pkpm_em_coupling_set_2x_ser_p1, euler_pkpm_em_coupling_set_2x_tensor_p2, NULL}, // 1 + {NULL, euler_pkpm_em_coupling_set_3x_ser_p1, NULL, NULL} // 2 }; // Copy solution for implicit source solve for fluid-em coupling in the PKPM system. (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_em_coupling_copy_kern_list ser_pkpm_em_coupling_copy_kernels[] = { - { NULL, euler_pkpm_em_coupling_copy_1x_ser_p1, euler_pkpm_em_coupling_copy_1x_ser_p2, euler_pkpm_em_coupling_copy_1x_ser_p3 }, // 0 - { NULL, euler_pkpm_em_coupling_copy_2x_ser_p1, NULL, NULL }, // 1 - { NULL, euler_pkpm_em_coupling_copy_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_em_coupling_copy_kern_list ser_pkpm_em_coupling_copy_kernels[] = + { + {NULL, euler_pkpm_em_coupling_copy_1x_ser_p1, euler_pkpm_em_coupling_copy_1x_ser_p2, + euler_pkpm_em_coupling_copy_1x_ser_p3}, // 0 + {NULL, euler_pkpm_em_coupling_copy_2x_ser_p1, NULL, NULL}, // 1 + {NULL, euler_pkpm_em_coupling_copy_3x_ser_p1, NULL, NULL} // 2 }; // Copy solution for implicit source solve for fluid-em coupling in the PKPM system. (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_em_coupling_copy_kern_list ten_pkpm_em_coupling_copy_kernels[] = { - { NULL, euler_pkpm_em_coupling_copy_1x_ser_p1, euler_pkpm_em_coupling_copy_1x_ser_p2, euler_pkpm_em_coupling_copy_1x_ser_p3 }, // 0 - { NULL, euler_pkpm_em_coupling_copy_2x_ser_p1, euler_pkpm_em_coupling_copy_2x_tensor_p2, NULL }, // 1 - { NULL, euler_pkpm_em_coupling_copy_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_em_coupling_copy_kern_list ten_pkpm_em_coupling_copy_kernels[] = + { + {NULL, euler_pkpm_em_coupling_copy_1x_ser_p1, euler_pkpm_em_coupling_copy_1x_ser_p2, + euler_pkpm_em_coupling_copy_1x_ser_p3}, // 0 + {NULL, euler_pkpm_em_coupling_copy_2x_ser_p1, euler_pkpm_em_coupling_copy_2x_tensor_p2, NULL + }, // 1 + {NULL, euler_pkpm_em_coupling_copy_3x_ser_p1, NULL, NULL} // 2 }; -GKYL_CU_D -static pkpm_em_coupling_set_t +GKYL_CU_D static pkpm_em_coupling_set_t choose_pkpm_em_coupling_set_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_em_coupling_set_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_em_coupling_set_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_em_coupling_set_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_em_coupling_set_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_em_coupling_copy_t +GKYL_CU_D static pkpm_em_coupling_copy_t choose_pkpm_em_coupling_copy_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_em_coupling_copy_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_em_coupling_copy_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_em_coupling_copy_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_em_coupling_copy_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } diff --git a/pkpm/zero/gkyl_dg_calc_pkpm_vars.h b/pkpm/zero/gkyl_dg_calc_pkpm_vars.h index 859f613337..df75f3b7e0 100644 --- a/pkpm/zero/gkyl_dg_calc_pkpm_vars.h +++ b/pkpm/zero/gkyl_dg_calc_pkpm_vars.h @@ -45,19 +45,21 @@ typedef struct gkyl_dg_calc_pkpm_vars gkyl_dg_calc_pkpm_vars; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_dg_calc_pkpm_vars* -gkyl_dg_calc_pkpm_vars_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis* cbasis, const struct gkyl_range *mem_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, double limiter_fac, bool use_gpu); +struct gkyl_dg_calc_pkpm_vars *gkyl_dg_calc_pkpm_vars_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *cbasis, + const struct gkyl_range *mem_range, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_geom *geom, double limiter_fac, bool use_gpu +); /** * Create new updater to compute pkpm variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_dg_calc_pkpm_vars* -gkyl_dg_calc_pkpm_vars_cu_dev_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis* cbasis, const struct gkyl_range *mem_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, double limiter_fac); +struct gkyl_dg_calc_pkpm_vars *gkyl_dg_calc_pkpm_vars_cu_dev_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *cbasis, + const struct gkyl_range *mem_range, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_geom *geom, double limiter_fac +); /** * Compute all of the pkpm primitive moments. @@ -76,10 +78,12 @@ gkyl_dg_calc_pkpm_vars_cu_dev_new(const struct gkyl_rect_grid *conf_grid, * ux_yl, ux_yr, uy_yl, uy_yr, uz_yl, uz_yr, 3.0*Tyy_yl/m, 3.0*Tyy_yr/m, * ux_zl, ux_zr, uy_zl, uy_zr, uz_zl, uz_zr, 3.0*Tzz_zl/m, 3.0*Tzz_zr/m] */ -void gkyl_dg_calc_pkpm_vars_advance(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - const struct gkyl_array* p_ij, const struct gkyl_array* pkpm_div_ppar, - struct gkyl_array* cell_avg_prim, struct gkyl_array* prim, struct gkyl_array* prim_surf); +void gkyl_dg_calc_pkpm_vars_advance( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, const struct gkyl_array *p_ij, + const struct gkyl_array *pkpm_div_ppar, struct gkyl_array *cell_avg_prim, struct gkyl_array *prim, + struct gkyl_array *prim_surf +); /** * Compute volume expansion of flow velocity u in the PKPM system. @@ -91,9 +95,10 @@ void gkyl_dg_calc_pkpm_vars_advance(struct gkyl_dg_calc_pkpm_vars *up, * Note: Only used for diagnostic purposes (not for adjusting solution) * @param pkpm_u Output array of volume expansion of flow velocity [ux, uy, uz] */ -void gkyl_dg_calc_pkpm_vars_u(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - struct gkyl_array* cell_avg_prim, struct gkyl_array* pkpm_u); +void gkyl_dg_calc_pkpm_vars_u( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, struct gkyl_array *cell_avg_prim, struct gkyl_array *pkpm_u +); /** * Compute pkpm pressure p_ij = (p_par - p_perp) b_i b_j + p_perp g_ij in the volume @@ -104,8 +109,10 @@ void gkyl_dg_calc_pkpm_vars_u(struct gkyl_dg_calc_pkpm_vars *up, * @param vlasov_pkpm_moms Input array of pkpm kinetic moments [rho, p_parallel, p_perp] * @param p_ij Output array of volume expansion of pressure tensor p_ij = (p_par - p_perp) b_i b_j + p_perp g_ij */ -void gkyl_dg_calc_pkpm_vars_pressure(struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* bvar, const struct gkyl_array* vlasov_pkpm_moms, struct gkyl_array* p_ij); +void gkyl_dg_calc_pkpm_vars_pressure( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *bvar, const struct gkyl_array *vlasov_pkpm_moms, struct gkyl_array *p_ij +); /** * Compute pkpm acceleration variables @@ -123,10 +130,11 @@ void gkyl_dg_calc_pkpm_vars_pressure(struct gkyl_dg_calc_pkpm_vars *up, const st 2: p_force (total pressure forces in kinetic equation 1/rho div(p_parallel b_hat) - T_perp/m*div(b) 3: p_perp_source (pressure source for higher Laguerre moments -> bb : grad(u) - div(u) - 2 nu) */ -void gkyl_dg_calc_pkpm_vars_accel(struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* prim_surf, const struct gkyl_array* prim, - const struct gkyl_array* bvar, const struct gkyl_array* div_b, const struct gkyl_array* nu, - struct gkyl_array* pkpm_accel); +void gkyl_dg_calc_pkpm_vars_accel( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *prim_surf, const struct gkyl_array *prim, const struct gkyl_array *bvar, + const struct gkyl_array *div_b, const struct gkyl_array *nu, struct gkyl_array *pkpm_accel +); /** * Compute surface expansions of pkpm penalization variables. These include: @@ -153,11 +161,12 @@ void gkyl_dg_calc_pkpm_vars_accel(struct gkyl_dg_calc_pkpm_vars *up, const struc * @param pkpm_lax Output array of surface expansion of Lax penalization lambda_i = |u_i| + sqrt(3.0*T_ii/m) * @param pkpm_penalization Output array of surface expansion of total momentum penalization */ -void gkyl_dg_calc_pkpm_vars_penalization(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *conf_range_ext, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* p_ij, - const struct gkyl_array* prim, const struct gkyl_array* euler_pkpm, - struct gkyl_array* pkpm_lax, struct gkyl_array* pkpm_penalization); +void gkyl_dg_calc_pkpm_vars_penalization( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *conf_range_ext, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *p_ij, const struct gkyl_array *prim, const struct gkyl_array *euler_pkpm, + struct gkyl_array *pkpm_lax, struct gkyl_array *pkpm_penalization +); /** * Compute integrated PKPM variables (rho, rhoux, rhouy, rhouz, rhoux^2, rhouy^2, rhouz^2, p_parallel, p_perp). @@ -169,10 +178,11 @@ void gkyl_dg_calc_pkpm_vars_penalization(struct gkyl_dg_calc_pkpm_vars *up, * @param prim Input array of primitive moments [ux, uy, uz, 1/rho*div(p_par b), T_perp/m, m/T_perp] * @param int_pkpm_vars Output array of integrated variables (6 components) */ -void gkyl_dg_calc_pkpm_integrated_vars(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* vlasov_pkpm_moms, - const struct gkyl_array* euler_pkpm, const struct gkyl_array* prim, - struct gkyl_array* pkpm_int_vars); +void gkyl_dg_calc_pkpm_integrated_vars( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *euler_pkpm, + const struct gkyl_array *prim, struct gkyl_array *pkpm_int_vars +); /** * Compute pkpm model source terms. @@ -184,10 +194,11 @@ void gkyl_dg_calc_pkpm_integrated_vars(struct gkyl_dg_calc_pkpm_vars *up, * @param euler_pkpm Input array of pkpm fluid variables [rho ux, rho uy, rho uz] * @param rhs Output increment to fluid variables */ -void gkyl_dg_calc_pkpm_vars_source(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* qmem, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - struct gkyl_array* rhs); +void gkyl_dg_calc_pkpm_vars_source( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *qmem, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, struct gkyl_array *rhs +); /** * Construct PKPM variables for I/O. Computes the conserved fluid variables @@ -209,11 +220,12 @@ void gkyl_dg_calc_pkpm_vars_source(struct gkyl_dg_calc_pkpm_vars *up, * @param fluid_io Output array of conserved fluid variables (10 components) * @param pkpm_vars_io Output array of pkpm variables, primitive and acceleration (8 components) */ -void gkyl_dg_calc_pkpm_vars_io(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* vlasov_pkpm_moms, - const struct gkyl_array* euler_pkpm, const struct gkyl_array* p_ij, - const struct gkyl_array* prim, const struct gkyl_array* pkpm_accel, - struct gkyl_array* fluid_io, struct gkyl_array* pkpm_vars_io); +void gkyl_dg_calc_pkpm_vars_io( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *euler_pkpm, + const struct gkyl_array *p_ij, const struct gkyl_array *prim, const struct gkyl_array *pkpm_accel, + struct gkyl_array *fluid_io, struct gkyl_array *pkpm_vars_io +); /** * Limit slopes for fluid variables in the PKPM system @@ -225,10 +237,11 @@ void gkyl_dg_calc_pkpm_vars_io(struct gkyl_dg_calc_pkpm_vars *up, * @param p_ij Input pressure tensor p_ij = (p_par - p_perp) b_i b_j + p_perp g_ij * @param fluid Input (and Output after limiting) array of fluid variables [rho ux, rho uy, rho uz] */ -void gkyl_dg_calc_pkpm_vars_limiter(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* prim, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* p_ij, - struct gkyl_array* fluid); +void gkyl_dg_calc_pkpm_vars_limiter( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *prim, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *p_ij, struct gkyl_array *fluid +); /** * Delete pointer to updater to compute pkpm variables. @@ -241,46 +254,57 @@ void gkyl_dg_calc_pkpm_vars_release(struct gkyl_dg_calc_pkpm_vars *up); * Host-side wrappers for pkpm vars operations on device */ -void gkyl_dg_calc_pkpm_vars_advance_cu(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - const struct gkyl_array* p_ij, const struct gkyl_array* pkpm_div_ppar, - struct gkyl_array* cell_avg_prim, struct gkyl_array* prim, struct gkyl_array* prim_surf); +void gkyl_dg_calc_pkpm_vars_advance_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, const struct gkyl_array *p_ij, + const struct gkyl_array *pkpm_div_ppar, struct gkyl_array *cell_avg_prim, struct gkyl_array *prim, + struct gkyl_array *prim_surf +); -void gkyl_dg_calc_pkpm_vars_u_cu(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - struct gkyl_array* cell_avg_prim, struct gkyl_array* pkpm_u); +void gkyl_dg_calc_pkpm_vars_u_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, struct gkyl_array *cell_avg_prim, struct gkyl_array *pkpm_u +); -void gkyl_dg_calc_pkpm_vars_pressure_cu(struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* bvar, const struct gkyl_array* vlasov_pkpm_moms, struct gkyl_array* p_ij); +void gkyl_dg_calc_pkpm_vars_pressure_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *bvar, const struct gkyl_array *vlasov_pkpm_moms, struct gkyl_array *p_ij +); -void gkyl_dg_calc_pkpm_vars_accel_cu(struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* prim_surf, const struct gkyl_array* prim, - const struct gkyl_array* bvar, const struct gkyl_array* div_b, const struct gkyl_array* nu, - struct gkyl_array* pkpm_accel); +void gkyl_dg_calc_pkpm_vars_accel_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *prim_surf, const struct gkyl_array *prim, const struct gkyl_array *bvar, + const struct gkyl_array *div_b, const struct gkyl_array *nu, struct gkyl_array *pkpm_accel +); -void gkyl_dg_calc_pkpm_vars_penalization_cu(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *conf_range_ext, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* p_ij, - const struct gkyl_array* prim, const struct gkyl_array* euler_pkpm, - struct gkyl_array* pkpm_lax, struct gkyl_array* pkpm_penalization); +void gkyl_dg_calc_pkpm_vars_penalization_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *conf_range_ext, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *p_ij, const struct gkyl_array *prim, const struct gkyl_array *euler_pkpm, + struct gkyl_array *pkpm_lax, struct gkyl_array *pkpm_penalization +); -void gkyl_dg_calc_pkpm_integrated_vars_cu(struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - const struct gkyl_array* prim, struct gkyl_array* pkpm_int_vars); +void gkyl_dg_calc_pkpm_integrated_vars_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *euler_pkpm, + const struct gkyl_array *prim, struct gkyl_array *pkpm_int_vars +); -void gkyl_dg_calc_pkpm_vars_source_cu(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* qmem, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* euler_pkpm, - struct gkyl_array* rhs); +void gkyl_dg_calc_pkpm_vars_source_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *qmem, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *euler_pkpm, struct gkyl_array *rhs +); -void gkyl_dg_calc_pkpm_vars_io_cu(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* vlasov_pkpm_moms, - const struct gkyl_array* euler_pkpm, const struct gkyl_array* p_ij, - const struct gkyl_array* prim, const struct gkyl_array* pkpm_accel, - struct gkyl_array* fluid_io, struct gkyl_array* pkpm_vars_io); - -void gkyl_dg_calc_pkpm_vars_limiter_cu(struct gkyl_dg_calc_pkpm_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* prim, - const struct gkyl_array* vlasov_pkpm_moms, const struct gkyl_array* p_ij, - struct gkyl_array* fluid); +void gkyl_dg_calc_pkpm_vars_io_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *vlasov_pkpm_moms, const struct gkyl_array *euler_pkpm, + const struct gkyl_array *p_ij, const struct gkyl_array *prim, const struct gkyl_array *pkpm_accel, + struct gkyl_array *fluid_io, struct gkyl_array *pkpm_vars_io +); +void gkyl_dg_calc_pkpm_vars_limiter_cu( + struct gkyl_dg_calc_pkpm_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *prim, const struct gkyl_array *vlasov_pkpm_moms, + const struct gkyl_array *p_ij, struct gkyl_array *fluid +); diff --git a/pkpm/zero/gkyl_dg_calc_pkpm_vars_priv.h b/pkpm/zero/gkyl_dg_calc_pkpm_vars_priv.h index d517dc3e34..ff535fe959 100644 --- a/pkpm/zero/gkyl_dg_calc_pkpm_vars_priv.h +++ b/pkpm/zero/gkyl_dg_calc_pkpm_vars_priv.h @@ -11,70 +11,106 @@ #include #include -typedef int (*pkpm_set_t)(int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, - const double *vlasov_pkpm_moms, const double *euler_pkpm, - const double *p_ij, const double *pkpm_div_ppar); - -typedef void (*pkpm_copy_t)(int count, struct gkyl_nmat *x, double* GKYL_RESTRICT prim, double* GKYL_RESTRICT prim_surf); - -typedef int (*pkpm_u_set_t)(int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, - const double *vlasov_pkpm_moms, const double *euler_pkpm); - -typedef void (*pkpm_u_copy_t)(int count, struct gkyl_nmat *x, double* GKYL_RESTRICT pkpm_u); - -typedef void (*pkpm_pressure_t)(const double *bvar, const double *vlasov_pkpm_moms, - double* GKYL_RESTRICT p_ij); - -typedef void (*pkpm_p_force_t)(const double *prim_c, const double *div_b, - double* GKYL_RESTRICT pkpm_accel); - -typedef void (*pkpm_int_t)(const double *vlasov_pkpm_moms, - const double *euler_pkpm, const double* prim, - double* GKYL_RESTRICT int_pkpm_vars); - -typedef void (*pkpm_source_t)(const double* qmem, - const double *vlasov_pkpm_moms, const double *euler_pkpm, - double* GKYL_RESTRICT out); - -typedef void (*pkpm_io_t)(const double *vlasov_pkpm_moms, - const double *euler_pkpm, const double* p_ij, - const double* prim, const double* pkpm_accel, - double* GKYL_RESTRICT fluid_io, double* GKYL_RESTRICT pkpm_vars_io); - -typedef void (*pkpm_accel_t)(const double *dxv, - const double *prim_surf_l, const double *prim_surf_c, const double *prim_surf_r, - const double *prim_c, const double *bvar_c, const double *nu_c, - double* GKYL_RESTRICT pkpm_accel); - -typedef void (*pkpm_penalization_t)(double tol, bool force_lax, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_cell_geom *geom, - const double *vlasov_pkpm_moms_l, const double *vlasov_pkpm_moms_r, - const double *p_ij_l, const double *p_ij_r, - const double *prim_l, const double *prim_r, - const double *euler_pkpm_l, const double *euler_pkpm_r, - double* GKYL_RESTRICT pkpm_lax, double* GKYL_RESTRICT pkpm_penalization); - -typedef void (*pkpm_limiter_t)(double limiter_fac, const struct gkyl_wv_eqn *wv_eqn, - const struct gkyl_wave_cell_geom *geom, const double *prim_c, - const double *vlasov_pkpm_moms_l, const double *vlasov_pkpm_moms_c, const double *vlasov_pkpm_moms_r, - const double *p_ij_l, const double *p_ij_c, const double *p_ij_r, - double *euler_pkpm_l, double *euler_pkpm_c, double *euler_pkpm_r); +typedef int (*pkpm_set_t)( + int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, const double *vlasov_pkpm_moms, + const double *euler_pkpm, const double *p_ij, const double *pkpm_div_ppar +); + +typedef void (*pkpm_copy_t)( + int count, struct gkyl_nmat *x, double *GKYL_RESTRICT prim, double *GKYL_RESTRICT prim_surf +); + +typedef int (*pkpm_u_set_t)( + int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, const double *vlasov_pkpm_moms, + const double *euler_pkpm +); + +typedef void (*pkpm_u_copy_t)(int count, struct gkyl_nmat *x, double *GKYL_RESTRICT pkpm_u); + +typedef void (*pkpm_pressure_t)( + const double *bvar, const double *vlasov_pkpm_moms, double *GKYL_RESTRICT p_ij +); + +typedef void (*pkpm_p_force_t)( + const double *prim_c, const double *div_b, double *GKYL_RESTRICT pkpm_accel +); + +typedef void (*pkpm_int_t)( + const double *vlasov_pkpm_moms, const double *euler_pkpm, const double *prim, + double *GKYL_RESTRICT int_pkpm_vars +); + +typedef void (*pkpm_source_t)( + const double *qmem, const double *vlasov_pkpm_moms, const double *euler_pkpm, + double *GKYL_RESTRICT out +); + +typedef void (*pkpm_io_t)( + const double *vlasov_pkpm_moms, const double *euler_pkpm, const double *p_ij, const double *prim, + const double *pkpm_accel, double *GKYL_RESTRICT fluid_io, double *GKYL_RESTRICT pkpm_vars_io +); + +typedef void (*pkpm_accel_t)( + const double *dxv, const double *prim_surf_l, const double *prim_surf_c, + const double *prim_surf_r, const double *prim_c, const double *bvar_c, const double *nu_c, + double *GKYL_RESTRICT pkpm_accel +); + +typedef void (*pkpm_penalization_t)( + double tol, bool force_lax, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_cell_geom *geom, const double *vlasov_pkpm_moms_l, + const double *vlasov_pkpm_moms_r, const double *p_ij_l, const double *p_ij_r, + const double *prim_l, const double *prim_r, const double *euler_pkpm_l, + const double *euler_pkpm_r, double *GKYL_RESTRICT pkpm_lax, + double *GKYL_RESTRICT pkpm_penalization +); + +typedef void (*pkpm_limiter_t)( + double limiter_fac, const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_cell_geom *geom, + const double *prim_c, const double *vlasov_pkpm_moms_l, const double *vlasov_pkpm_moms_c, + const double *vlasov_pkpm_moms_r, const double *p_ij_l, const double *p_ij_c, + const double *p_ij_r, double *euler_pkpm_l, double *euler_pkpm_c, double *euler_pkpm_r +); // for use in kernel tables -typedef struct { pkpm_set_t kernels[3]; } gkyl_dg_pkpm_set_kern_list; -typedef struct { pkpm_copy_t kernels[3]; } gkyl_dg_pkpm_copy_kern_list; -typedef struct { pkpm_u_set_t kernels[3]; } gkyl_dg_pkpm_u_set_kern_list; -typedef struct { pkpm_u_copy_t kernels[3]; } gkyl_dg_pkpm_u_copy_kern_list; -typedef struct { pkpm_pressure_t kernels[3]; } gkyl_dg_pkpm_pressure_kern_list; -typedef struct { pkpm_p_force_t kernels[3]; } gkyl_dg_pkpm_p_force_kern_list; - -typedef struct { pkpm_int_t kernels[3]; } gkyl_dg_pkpm_int_kern_list; -typedef struct { pkpm_source_t kernels[3]; } gkyl_dg_pkpm_source_kern_list; -typedef struct { pkpm_io_t kernels[3]; } gkyl_dg_pkpm_io_kern_list; - -typedef struct { pkpm_accel_t kernels[3]; } gkyl_dg_pkpm_accel_kern_list; -typedef struct { pkpm_penalization_t kernels[3]; } gkyl_dg_pkpm_penalization_kern_list; -typedef struct { pkpm_limiter_t kernels[4]; } gkyl_dg_pkpm_limiter_kern_list; +typedef struct { + pkpm_set_t kernels[3]; +} gkyl_dg_pkpm_set_kern_list; +typedef struct { + pkpm_copy_t kernels[3]; +} gkyl_dg_pkpm_copy_kern_list; +typedef struct { + pkpm_u_set_t kernels[3]; +} gkyl_dg_pkpm_u_set_kern_list; +typedef struct { + pkpm_u_copy_t kernels[3]; +} gkyl_dg_pkpm_u_copy_kern_list; +typedef struct { + pkpm_pressure_t kernels[3]; +} gkyl_dg_pkpm_pressure_kern_list; +typedef struct { + pkpm_p_force_t kernels[3]; +} gkyl_dg_pkpm_p_force_kern_list; + +typedef struct { + pkpm_int_t kernels[3]; +} gkyl_dg_pkpm_int_kern_list; +typedef struct { + pkpm_source_t kernels[3]; +} gkyl_dg_pkpm_source_kern_list; +typedef struct { + pkpm_io_t kernels[3]; +} gkyl_dg_pkpm_io_kern_list; + +typedef struct { + pkpm_accel_t kernels[3]; +} gkyl_dg_pkpm_accel_kern_list; +typedef struct { + pkpm_penalization_t kernels[3]; +} gkyl_dg_pkpm_penalization_kern_list; +typedef struct { + pkpm_limiter_t kernels[4]; +} gkyl_dg_pkpm_limiter_kern_list; struct gkyl_dg_calc_pkpm_vars { struct gkyl_rect_grid conf_grid; // Configuration space grid for cell spacing and cell center @@ -84,11 +120,13 @@ struct gkyl_dg_calc_pkpm_vars { const struct gkyl_wv_eqn *wv_eqn; // Wave equation for characteristic limiting of solution const struct gkyl_wave_geom *geom; // Wave geometry for rotating solution - double limiter_fac; // Factor for relationship between cell slopes and cell average differences (default: 1/sqrt(3)) + double + limiter_fac; // Factor for relationship between cell slopes and cell average differences (default: 1/sqrt(3)) double tol; // Tolerance in mass density and average normal velocity at the interface - // for switching to Lax fluxes in computing penalization of the momentum solve (default: 1.0e-12) - bool force_lax; // Boolean for forcing the system to use Lax fluxes for the momentum (default: false) + // for switching to Lax fluxes in computing penalization of the momentum solve (default: 1.0e-12) + bool + force_lax; // Boolean for forcing the system to use Lax fluxes for the momentum (default: false) struct gkyl_nmat *As, *xs; // matrices for LHS and RHS gkyl_nmat_mem *mem; // memory for use in batched linear solve @@ -97,19 +135,22 @@ struct gkyl_dg_calc_pkpm_vars { struct gkyl_nmat *As_u, *xs_u; // matrices for LHS and RHS for flow velocity solve gkyl_nmat_mem *mem_u; // memory for use in batched linear solve for velocity - pkpm_set_t pkpm_set; // kernel for setting matrices for linear solve - pkpm_copy_t pkpm_copy; // kernel for copying solution to output; also computed needed surface expansions - pkpm_u_set_t pkpm_u_set; // kernel for setting matrices for linear solve for flow velocity + pkpm_set_t pkpm_set; // kernel for setting matrices for linear solve + pkpm_copy_t + pkpm_copy; // kernel for copying solution to output; also computed needed surface expansions + pkpm_u_set_t pkpm_u_set; // kernel for setting matrices for linear solve for flow velocity pkpm_u_copy_t pkpm_u_copy; // kernel for copying solution for flow velocity to output pkpm_pressure_t pkpm_pressure; // kernel for computing pressure (Volume and surface expansion) - pkpm_p_force_t pkpm_p_force; // kernel for computing pressure force p_force = 1/rho div(p_par b) - T_perp/m div(b) + pkpm_p_force_t + pkpm_p_force; // kernel for computing pressure force p_force = 1/rho div(p_par b) - T_perp/m div(b) pkpm_int_t pkpm_int; // kernel for computing integrated pkpm variables pkpm_source_t pkpm_source; // kernel for computing pkpm source update pkpm_io_t pkpm_io; // kernel for constructing I/O arrays for pkpm diagnostics pkpm_accel_t pkpm_accel[3]; // kernel for computing pkpm acceleration and Lax variables - pkpm_penalization_t pkpm_penalization[3]; // kernel for computing pkpm acceleration and Lax variables + pkpm_penalization_t + pkpm_penalization[3]; // kernel for computing pkpm acceleration and Lax variables pkpm_limiter_t pkpm_limiter[3]; // kernel for limiting slopes of fluid variables uint32_t flags; @@ -117,547 +158,507 @@ struct gkyl_dg_calc_pkpm_vars { }; // Set matrices for computing pkpm primitive vars, e.g., ux,uy,uz (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_set_kern_list ser_pkpm_set_kernels[] = { - { NULL, pkpm_vars_set_1x_ser_p1, pkpm_vars_set_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_set_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_set_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_set_kern_list ser_pkpm_set_kernels[] = { + {NULL, pkpm_vars_set_1x_ser_p1, pkpm_vars_set_1x_ser_p2}, // 0 + {NULL, pkpm_vars_set_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_set_3x_ser_p1, NULL} // 2 }; // Set matrices for computing pkpm primitive vars, e.g., ux,uy,uz (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_set_kern_list ten_pkpm_set_kernels[] = { - { NULL, pkpm_vars_set_1x_ser_p1, pkpm_vars_set_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_set_2x_ser_p1, pkpm_vars_set_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_set_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_set_kern_list ten_pkpm_set_kernels[] = { + {NULL, pkpm_vars_set_1x_ser_p1, pkpm_vars_set_1x_ser_p2}, // 0 + {NULL, pkpm_vars_set_2x_ser_p1, pkpm_vars_set_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_set_3x_ser_p1, NULL} // 2 }; // Copy solution for pkpm primitive vars, e.g., ux,uy,uz (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_copy_kern_list ser_pkpm_copy_kernels[] = { - { NULL, pkpm_vars_copy_1x_ser_p1, pkpm_vars_copy_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_copy_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_copy_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_copy_kern_list ser_pkpm_copy_kernels[] = { + {NULL, pkpm_vars_copy_1x_ser_p1, pkpm_vars_copy_1x_ser_p2}, // 0 + {NULL, pkpm_vars_copy_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_copy_3x_ser_p1, NULL} // 2 }; // Copy solution for pkpm primitive vars, e.g., ux,uy,uz (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_copy_kern_list ten_pkpm_copy_kernels[] = { - { NULL, pkpm_vars_copy_1x_ser_p1, pkpm_vars_copy_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_copy_2x_ser_p1, pkpm_vars_copy_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_copy_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_copy_kern_list ten_pkpm_copy_kernels[] = { + {NULL, pkpm_vars_copy_1x_ser_p1, pkpm_vars_copy_1x_ser_p2}, // 0 + {NULL, pkpm_vars_copy_2x_ser_p1, pkpm_vars_copy_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_copy_3x_ser_p1, NULL} // 2 }; // Set matrices for computing flow velocity (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_u_set_kern_list ser_pkpm_u_set_kernels[] = { - { NULL, pkpm_vars_u_set_1x_ser_p1, pkpm_vars_u_set_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_u_set_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_u_set_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_u_set_kern_list ser_pkpm_u_set_kernels[] = { + {NULL, pkpm_vars_u_set_1x_ser_p1, pkpm_vars_u_set_1x_ser_p2}, // 0 + {NULL, pkpm_vars_u_set_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_u_set_3x_ser_p1, NULL} // 2 }; // Set matrices for computing flow velocity (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_u_set_kern_list ten_pkpm_u_set_kernels[] = { - { NULL, pkpm_vars_u_set_1x_ser_p1, pkpm_vars_u_set_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_u_set_2x_ser_p1, pkpm_vars_u_set_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_u_set_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_u_set_kern_list ten_pkpm_u_set_kernels[] = { + {NULL, pkpm_vars_u_set_1x_ser_p1, pkpm_vars_u_set_1x_ser_p2}, // 0 + {NULL, pkpm_vars_u_set_2x_ser_p1, pkpm_vars_u_set_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_u_set_3x_ser_p1, NULL} // 2 }; // Copy solution for flow velocity (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_u_copy_kern_list ser_pkpm_u_copy_kernels[] = { - { NULL, pkpm_vars_u_copy_1x_ser_p1, pkpm_vars_u_copy_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_u_copy_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_u_copy_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_u_copy_kern_list ser_pkpm_u_copy_kernels[] = { + {NULL, pkpm_vars_u_copy_1x_ser_p1, pkpm_vars_u_copy_1x_ser_p2}, // 0 + {NULL, pkpm_vars_u_copy_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_u_copy_3x_ser_p1, NULL} // 2 }; // Copy solution for flow velocity (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_u_copy_kern_list ten_pkpm_u_copy_kernels[] = { - { NULL, pkpm_vars_u_copy_1x_ser_p1, pkpm_vars_u_copy_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_u_copy_2x_ser_p1, pkpm_vars_u_copy_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_u_copy_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_u_copy_kern_list ten_pkpm_u_copy_kernels[] = { + {NULL, pkpm_vars_u_copy_1x_ser_p1, pkpm_vars_u_copy_1x_ser_p2}, // 0 + {NULL, pkpm_vars_u_copy_2x_ser_p1, pkpm_vars_u_copy_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_u_copy_3x_ser_p1, NULL} // 2 }; // PKPM Pressure (p_ij = (p_par - p_perp)b_i b_j + p_perp g_ij) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_pressure_kern_list ser_pkpm_pressure_kernels[] = { - { NULL, pkpm_vars_pressure_1x_ser_p1, pkpm_vars_pressure_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_pressure_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_pressure_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_pressure_kern_list ser_pkpm_pressure_kernels[] = { + {NULL, pkpm_vars_pressure_1x_ser_p1, pkpm_vars_pressure_1x_ser_p2}, // 0 + {NULL, pkpm_vars_pressure_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_pressure_3x_ser_p1, NULL} // 2 }; // PKPM Pressure (p_ij = (p_ij = (p_par - p_perp)b_i b_j + p_perp g_ij) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_pressure_kern_list ten_pkpm_pressure_kernels[] = { - { NULL, pkpm_vars_pressure_1x_ser_p1, pkpm_vars_pressure_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_pressure_2x_ser_p1, pkpm_vars_pressure_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_pressure_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_pressure_kern_list ten_pkpm_pressure_kernels[] = { + {NULL, pkpm_vars_pressure_1x_ser_p1, pkpm_vars_pressure_1x_ser_p2}, // 0 + {NULL, pkpm_vars_pressure_2x_ser_p1, pkpm_vars_pressure_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_pressure_3x_ser_p1, NULL} // 2 }; // PKPM Pressure force p_force = 1/rho div(p_par b) - T_perp/m div(b) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_p_force_kern_list ser_pkpm_p_force_kernels[] = { - { NULL, pkpm_vars_p_force_1x_ser_p1, pkpm_vars_p_force_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_p_force_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_p_force_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_p_force_kern_list ser_pkpm_p_force_kernels[] = { + {NULL, pkpm_vars_p_force_1x_ser_p1, pkpm_vars_p_force_1x_ser_p2}, // 0 + {NULL, pkpm_vars_p_force_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_p_force_3x_ser_p1, NULL} // 2 }; // PKPM Pressure force p_force = 1/rho div(p_par b) - T_perp/m div(b) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_p_force_kern_list ten_pkpm_p_force_kernels[] = { - { NULL, pkpm_vars_p_force_1x_ser_p1, pkpm_vars_p_force_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_p_force_2x_ser_p1, pkpm_vars_p_force_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_p_force_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_p_force_kern_list ten_pkpm_p_force_kernels[] = { + {NULL, pkpm_vars_p_force_1x_ser_p1, pkpm_vars_p_force_1x_ser_p2}, // 0 + {NULL, pkpm_vars_p_force_2x_ser_p1, pkpm_vars_p_force_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_p_force_3x_ser_p1, NULL} // 2 }; // PKPM integrated variables integral (rho, rhoux, rhouy, rhouz, rhoux^2, rhouy^2, rhouz^2, p_parallel, p_perp) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_int_kern_list ser_pkpm_int_kernels[] = { - { NULL, pkpm_vars_integrated_1x_ser_p1, pkpm_vars_integrated_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_integrated_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_integrated_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_int_kern_list ser_pkpm_int_kernels[] = { + {NULL, pkpm_vars_integrated_1x_ser_p1, pkpm_vars_integrated_1x_ser_p2}, // 0 + {NULL, pkpm_vars_integrated_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_integrated_3x_ser_p1, NULL} // 2 }; // PKPM integrated variables integral (rho, rhoux, rhouy, rhouz, rhoux^2, rhouy^2, rhouz^2, p_parallel, p_perp) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_int_kern_list ten_pkpm_int_kernels[] = { - { NULL, pkpm_vars_integrated_1x_ser_p1, pkpm_vars_integrated_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_integrated_2x_ser_p1, pkpm_vars_integrated_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_integrated_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_int_kern_list ten_pkpm_int_kernels[] = { + {NULL, pkpm_vars_integrated_1x_ser_p1, pkpm_vars_integrated_1x_ser_p2}, // 0 + {NULL, pkpm_vars_integrated_2x_ser_p1, pkpm_vars_integrated_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_integrated_3x_ser_p1, NULL} // 2 }; // PKPM explicit source solve (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_source_kern_list ser_pkpm_source_kernels[] = { - { NULL, euler_pkpm_source_1x_ser_p1, euler_pkpm_source_1x_ser_p2 }, // 0 - { NULL, euler_pkpm_source_2x_ser_p1, NULL }, // 1 - { NULL, euler_pkpm_source_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_source_kern_list ser_pkpm_source_kernels[] = { + {NULL, euler_pkpm_source_1x_ser_p1, euler_pkpm_source_1x_ser_p2}, // 0 + {NULL, euler_pkpm_source_2x_ser_p1, NULL}, // 1 + {NULL, euler_pkpm_source_3x_ser_p1, NULL} // 2 }; // PKPM explicit source solve (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_source_kern_list ten_pkpm_source_kernels[] = { - { NULL, euler_pkpm_source_1x_ser_p1, euler_pkpm_source_1x_ser_p2 }, // 0 - { NULL, euler_pkpm_source_2x_ser_p1, euler_pkpm_source_2x_tensor_p2 }, // 1 - { NULL, euler_pkpm_source_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_source_kern_list ten_pkpm_source_kernels[] = { + {NULL, euler_pkpm_source_1x_ser_p1, euler_pkpm_source_1x_ser_p2}, // 0 + {NULL, euler_pkpm_source_2x_ser_p1, euler_pkpm_source_2x_tensor_p2}, // 1 + {NULL, euler_pkpm_source_3x_ser_p1, NULL} // 2 }; // PKPM io variables (Serendipity kernels) // Conserved fluid variables: [rho, rho ux, rho uy, rho uz, Pxx + rho ux^2, Pxy + rho ux uy, Pxz + rho ux uz, Pyy + rho uy^2, Pyz + rho uy uz, Pzz + rho uz^2] -// PKPM primitive and acceleration variables: +// PKPM primitive and acceleration variables: // [ux, uy, uz, T_perp/m, m/T_perp, 1/rho div(p_par b), T_perp/m div(b), bb : grad(u)] -GKYL_CU_D -static const gkyl_dg_pkpm_io_kern_list ser_pkpm_io_kernels[] = { - { NULL, pkpm_vars_io_1x_ser_p1, pkpm_vars_io_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_io_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_io_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_io_kern_list ser_pkpm_io_kernels[] = { + {NULL, pkpm_vars_io_1x_ser_p1, pkpm_vars_io_1x_ser_p2}, // 0 + {NULL, pkpm_vars_io_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_io_3x_ser_p1, NULL} // 2 }; // PKPM io variables (Tensor kernels) // Conserved fluid variables: [rho, rho ux, rho uy, rho uz, Pxx + rho ux^2, Pxy + rho ux uy, Pxz + rho ux uz, Pyy + rho uy^2, Pyz + rho uy uz, Pzz + rho uz^2] -// PKPM primitive and acceleration variables: +// PKPM primitive and acceleration variables: // [ux, uy, uz, T_perp/m, m/T_perp, 1/rho div(p_par b), T_perp/m div(b), bb : grad(u)] -GKYL_CU_D -static const gkyl_dg_pkpm_io_kern_list ten_pkpm_io_kernels[] = { - { NULL, pkpm_vars_io_1x_ser_p1, pkpm_vars_io_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_io_2x_ser_p1, pkpm_vars_io_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_io_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_io_kern_list ten_pkpm_io_kernels[] = { + {NULL, pkpm_vars_io_1x_ser_p1, pkpm_vars_io_1x_ser_p2}, // 0 + {NULL, pkpm_vars_io_2x_ser_p1, pkpm_vars_io_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_io_3x_ser_p1, NULL} // 2 }; // PKPM acceleration variables, e.g., bb:grad(u), (in x) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_accel_kern_list ser_pkpm_accel_x_kernels[] = { - { NULL, pkpm_vars_accel_x_1x_ser_p1, pkpm_vars_accel_x_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_accel_x_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_accel_x_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_accel_kern_list ser_pkpm_accel_x_kernels[] = { + {NULL, pkpm_vars_accel_x_1x_ser_p1, pkpm_vars_accel_x_1x_ser_p2}, // 0 + {NULL, pkpm_vars_accel_x_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_accel_x_3x_ser_p1, NULL} // 2 }; // PKPM acceleration variables, e.g., bb:grad(u), (in y) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_accel_kern_list ser_pkpm_accel_y_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, pkpm_vars_accel_y_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_accel_y_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_accel_kern_list ser_pkpm_accel_y_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, pkpm_vars_accel_y_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_accel_y_3x_ser_p1, NULL} // 2 }; // PKPM acceleration variables, e.g., bb:grad(u), (in z) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_accel_kern_list ser_pkpm_accel_z_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, pkpm_vars_accel_z_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_accel_kern_list ser_pkpm_accel_z_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, pkpm_vars_accel_z_3x_ser_p1, NULL} // 2 }; // PKPM acceleration variables, e.g., bb:grad(u), (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_accel_kern_list ten_pkpm_accel_x_kernels[] = { - { NULL, pkpm_vars_accel_x_1x_ser_p1, pkpm_vars_accel_x_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_accel_x_2x_ser_p1, pkpm_vars_accel_x_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_accel_x_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_accel_kern_list ten_pkpm_accel_x_kernels[] = { + {NULL, pkpm_vars_accel_x_1x_ser_p1, pkpm_vars_accel_x_1x_ser_p2}, // 0 + {NULL, pkpm_vars_accel_x_2x_ser_p1, pkpm_vars_accel_x_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_accel_x_3x_ser_p1, NULL} // 2 }; // PKPM acceleration variables, e.g., bb:grad(u), (in y) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_accel_kern_list ten_pkpm_accel_y_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, pkpm_vars_accel_y_2x_ser_p1, pkpm_vars_accel_y_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_accel_y_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_accel_kern_list ten_pkpm_accel_y_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, pkpm_vars_accel_y_2x_ser_p1, pkpm_vars_accel_y_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_accel_y_3x_ser_p1, NULL} // 2 }; // PKPM acceleration variables, e.g., bb:grad(u), (in z) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_accel_kern_list ten_pkpm_accel_z_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, pkpm_vars_accel_z_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_accel_kern_list ten_pkpm_accel_z_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, pkpm_vars_accel_z_3x_ser_p1, NULL} // 2 }; // PKPM penalization variables, e.g., total momentum penalization and // Lax penalization (lambda_i = |u_i| + sqrt(3*T_ii/m)) (in x) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_penalization_kern_list ser_pkpm_penalization_x_kernels[] = { - { NULL, pkpm_vars_penalization_x_1x_ser_p1, pkpm_vars_penalization_x_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_penalization_x_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_penalization_x_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_penalization_kern_list ser_pkpm_penalization_x_kernels[] = { + {NULL, pkpm_vars_penalization_x_1x_ser_p1, pkpm_vars_penalization_x_1x_ser_p2}, // 0 + {NULL, pkpm_vars_penalization_x_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_penalization_x_3x_ser_p1, NULL} // 2 }; -// PKPM penalization variables, e.g., total momentum penalization and +// PKPM penalization variables, e.g., total momentum penalization and // Lax penalization (lambda_i = |u_i| + sqrt(3*T_ii/m)) (in y) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_penalization_kern_list ser_pkpm_penalization_y_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, pkpm_vars_penalization_y_2x_ser_p1, NULL }, // 1 - { NULL, pkpm_vars_penalization_y_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_penalization_kern_list ser_pkpm_penalization_y_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, pkpm_vars_penalization_y_2x_ser_p1, NULL}, // 1 + {NULL, pkpm_vars_penalization_y_3x_ser_p1, NULL} // 2 }; -// PKPM penalization variables, e.g., total momentum penalization and +// PKPM penalization variables, e.g., total momentum penalization and // Lax penalization (lambda_i = |u_i| + sqrt(3*T_ii/m)) (in z) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_penalization_kern_list ser_pkpm_penalization_z_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, pkpm_vars_penalization_z_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_penalization_kern_list ser_pkpm_penalization_z_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, pkpm_vars_penalization_z_3x_ser_p1, NULL} // 2 }; -// PKPM penalization variables, e.g., total momentum penalization and +// PKPM penalization variables, e.g., total momentum penalization and // Lax penalization (lambda_i = |u_i| + sqrt(3*T_ii/m)) (in x) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_penalization_kern_list ten_pkpm_penalization_x_kernels[] = { - { NULL, pkpm_vars_penalization_x_1x_ser_p1, pkpm_vars_penalization_x_1x_ser_p2 }, // 0 - { NULL, pkpm_vars_penalization_x_2x_ser_p1, pkpm_vars_penalization_x_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_penalization_x_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_penalization_kern_list ten_pkpm_penalization_x_kernels[] = { + {NULL, pkpm_vars_penalization_x_1x_ser_p1, pkpm_vars_penalization_x_1x_ser_p2}, // 0 + {NULL, pkpm_vars_penalization_x_2x_ser_p1, pkpm_vars_penalization_x_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_penalization_x_3x_ser_p1, NULL} // 2 }; -// PKPM penalization variables, e.g., total momentum penalization and +// PKPM penalization variables, e.g., total momentum penalization and // Lax penalization (lambda_i = |u_i| + sqrt(3*T_ii/m)) (in y) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_penalization_kern_list ten_pkpm_penalization_y_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, pkpm_vars_penalization_y_2x_ser_p1, pkpm_vars_penalization_y_2x_tensor_p2 }, // 1 - { NULL, pkpm_vars_penalization_y_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_penalization_kern_list ten_pkpm_penalization_y_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, pkpm_vars_penalization_y_2x_ser_p1, pkpm_vars_penalization_y_2x_tensor_p2}, // 1 + {NULL, pkpm_vars_penalization_y_3x_ser_p1, NULL} // 2 }; -// PKPM penalization variables, e.g., total momentum penalization and +// PKPM penalization variables, e.g., total momentum penalization and // Lax penalization (lambda_i = |u_i| + sqrt(3*T_ii/m)) (in z) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_penalization_kern_list ten_pkpm_penalization_z_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, pkpm_vars_penalization_z_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_penalization_kern_list ten_pkpm_penalization_z_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, pkpm_vars_penalization_z_3x_ser_p1, NULL} // 2 }; // Characteristic limiter in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_limiter_kern_list ser_pkpm_limiter_x_kernels[] = { - { NULL, euler_pkpm_limiter_x_1x_ser_p1, euler_pkpm_limiter_x_1x_ser_p2, euler_pkpm_limiter_x_1x_ser_p3 }, // 0 - { NULL, euler_pkpm_limiter_x_2x_ser_p1, NULL, NULL }, // 1 - { NULL, euler_pkpm_limiter_x_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_limiter_kern_list ser_pkpm_limiter_x_kernels[] = { + {NULL, euler_pkpm_limiter_x_1x_ser_p1, euler_pkpm_limiter_x_1x_ser_p2, + euler_pkpm_limiter_x_1x_ser_p3}, // 0 + {NULL, euler_pkpm_limiter_x_2x_ser_p1, NULL, NULL}, // 1 + {NULL, euler_pkpm_limiter_x_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_limiter_kern_list ser_pkpm_limiter_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, euler_pkpm_limiter_y_2x_ser_p1, NULL, NULL }, // 1 - { NULL, euler_pkpm_limiter_y_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_limiter_kern_list ser_pkpm_limiter_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, euler_pkpm_limiter_y_2x_ser_p1, NULL, NULL}, // 1 + {NULL, euler_pkpm_limiter_y_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_limiter_kern_list ser_pkpm_limiter_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, euler_pkpm_limiter_z_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_limiter_kern_list ser_pkpm_limiter_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, euler_pkpm_limiter_z_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in x (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_limiter_kern_list ten_pkpm_limiter_x_kernels[] = { - { NULL, euler_pkpm_limiter_x_1x_ser_p1, euler_pkpm_limiter_x_1x_ser_p2, euler_pkpm_limiter_x_1x_ser_p3 }, // 0 - { NULL, euler_pkpm_limiter_x_2x_ser_p1, euler_pkpm_limiter_x_2x_tensor_p2, NULL }, // 1 - { NULL, euler_pkpm_limiter_x_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_limiter_kern_list ten_pkpm_limiter_x_kernels[] = { + {NULL, euler_pkpm_limiter_x_1x_ser_p1, euler_pkpm_limiter_x_1x_ser_p2, + euler_pkpm_limiter_x_1x_ser_p3}, // 0 + {NULL, euler_pkpm_limiter_x_2x_ser_p1, euler_pkpm_limiter_x_2x_tensor_p2, NULL}, // 1 + {NULL, euler_pkpm_limiter_x_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in y (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_limiter_kern_list ten_pkpm_limiter_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, euler_pkpm_limiter_y_2x_ser_p1, euler_pkpm_limiter_y_2x_tensor_p2, NULL }, // 1 - { NULL, euler_pkpm_limiter_y_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_limiter_kern_list ten_pkpm_limiter_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, euler_pkpm_limiter_y_2x_ser_p1, euler_pkpm_limiter_y_2x_tensor_p2, NULL}, // 1 + {NULL, euler_pkpm_limiter_y_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in z (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_pkpm_limiter_kern_list ten_pkpm_limiter_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, euler_pkpm_limiter_z_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_pkpm_limiter_kern_list ten_pkpm_limiter_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, euler_pkpm_limiter_z_3x_ser_p1, NULL, NULL} // 2 }; -GKYL_CU_D -static pkpm_set_t +GKYL_CU_D static pkpm_set_t choose_pkpm_set_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_set_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_set_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_set_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_set_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_copy_t +GKYL_CU_D static pkpm_copy_t choose_pkpm_copy_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_copy_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_copy_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_copy_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_copy_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_u_set_t +GKYL_CU_D static pkpm_u_set_t choose_pkpm_u_set_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_u_set_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_u_set_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_u_set_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_u_set_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_u_copy_t +GKYL_CU_D static pkpm_u_copy_t choose_pkpm_u_copy_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_u_copy_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_u_copy_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_u_copy_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_u_copy_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_pressure_t +GKYL_CU_D static pkpm_pressure_t choose_pkpm_pressure_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_pressure_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_pressure_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_pressure_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_pressure_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_p_force_t +GKYL_CU_D static pkpm_p_force_t choose_pkpm_p_force_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_p_force_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_p_force_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_p_force_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_p_force_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_int_t +GKYL_CU_D static pkpm_int_t choose_pkpm_int_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_int_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_int_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_int_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_int_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_source_t +GKYL_CU_D static pkpm_source_t choose_pkpm_source_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_source_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_source_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_source_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_source_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_io_t +GKYL_CU_D static pkpm_io_t choose_pkpm_io_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_pkpm_io_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_pkpm_io_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_pkpm_io_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_pkpm_io_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_accel_t +GKYL_CU_D static pkpm_accel_t choose_pkpm_accel_kern(int dir, enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (dir == 0) - return ser_pkpm_accel_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ser_pkpm_accel_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ser_pkpm_accel_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return ten_pkpm_accel_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ten_pkpm_accel_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ten_pkpm_accel_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + if (dir == 0) { + return ser_pkpm_accel_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ser_pkpm_accel_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ser_pkpm_accel_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return ten_pkpm_accel_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ten_pkpm_accel_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ten_pkpm_accel_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_penalization_t +GKYL_CU_D static pkpm_penalization_t choose_pkpm_penalization_kern(int dir, enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (dir == 0) - return ser_pkpm_penalization_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ser_pkpm_penalization_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ser_pkpm_penalization_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return ten_pkpm_penalization_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ten_pkpm_penalization_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ten_pkpm_penalization_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + if (dir == 0) { + return ser_pkpm_penalization_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ser_pkpm_penalization_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ser_pkpm_penalization_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return ten_pkpm_penalization_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ten_pkpm_penalization_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ten_pkpm_penalization_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } -GKYL_CU_D -static pkpm_limiter_t +GKYL_CU_D static pkpm_limiter_t choose_pkpm_limiter_kern(int dir, enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (dir == 0) - return ser_pkpm_limiter_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ser_pkpm_limiter_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ser_pkpm_limiter_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return ten_pkpm_limiter_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ten_pkpm_limiter_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ten_pkpm_limiter_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + if (dir == 0) { + return ser_pkpm_limiter_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ser_pkpm_limiter_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ser_pkpm_limiter_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return ten_pkpm_limiter_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ten_pkpm_limiter_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ten_pkpm_limiter_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } diff --git a/pkpm/zero/gkyl_dg_euler_pkpm.h b/pkpm/zero/gkyl_dg_euler_pkpm.h index 0d5652ccf2..4cb23f52c2 100644 --- a/pkpm/zero/gkyl_dg_euler_pkpm.h +++ b/pkpm/zero/gkyl_dg_euler_pkpm.h @@ -8,7 +8,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_euler_pkpm_auxfields { +struct gkyl_dg_euler_pkpm_auxfields { const struct gkyl_array *vlasov_pkpm_moms; const struct gkyl_array *pkpm_prim; const struct gkyl_array *pkpm_prim_surf; @@ -24,15 +24,16 @@ struct gkyl_dg_euler_pkpm_auxfields { * @param conf_range Configuration space range for use in indexing auxiliary variables * @return Pointer to Euler equation object for parallel-kinetic-perpendicular-moment (pkpm) model */ -struct gkyl_dg_eqn* gkyl_dg_euler_pkpm_new(const struct gkyl_basis* cbasis, - const struct gkyl_range* conf_range, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_euler_pkpm_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, bool use_gpu +); /** * Create new Euler equation object arallel-kinetic-perpendicular-moment (pkpm) model the lives on NV-GPU: * see new() method above for documentation. */ -struct gkyl_dg_eqn* gkyl_dg_euler_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_range* conf_range); +struct gkyl_dg_eqn * +gkyl_dg_euler_pkpm_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range); /** * Set the auxiliary fields (e.g. velocity u = rho*u/rho) needed in updating Euler equation for parallel-kinetic-perpendicular-moment (pkpm) model. @@ -40,7 +41,9 @@ struct gkyl_dg_eqn* gkyl_dg_euler_pkpm_cu_dev_new(const struct gkyl_basis* cbasi * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_euler_pkpm_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_pkpm_auxfields auxin); +void gkyl_euler_pkpm_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_pkpm_auxfields auxin +); #ifdef GKYL_HAVE_CUDA /** @@ -49,6 +52,8 @@ void gkyl_euler_pkpm_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_euler_pkpm_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_pkpm_auxfields auxin); +void gkyl_euler_pkpm_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_pkpm_auxfields auxin +); #endif diff --git a/pkpm/zero/gkyl_dg_euler_pkpm_priv.h b/pkpm/zero/gkyl_dg_euler_pkpm_priv.h index 18a9d7fdfc..46f6709f2f 100644 --- a/pkpm/zero/gkyl_dg_euler_pkpm_priv.h +++ b/pkpm/zero/gkyl_dg_euler_pkpm_priv.h @@ -10,21 +10,25 @@ // functions // Types for various kernels -typedef double (*euler_pkpm_surf_t)(const double *w, const double *dxv, - const double *vlasov_pkpm_moms_l, const double *vlasov_pkpm_moms_c, const double *vlasov_pkpm_moms_r, - const double *prim_surf_l, const double *prim_surf_c, const double *prim_surf_r, - const double *p_ij_l, const double *p_ij_c, const double *p_ij_r, - const double *euler_pkpm_l, const double *euler_pkpm_c, const double *euler_pkpm_r, - const double *pkpm_lax_l, const double *pkpm_lax_r, - const double *pkpm_penalization_l, const double *pkpm_penalization_r, - double* GKYL_RESTRICT out); +typedef double (*euler_pkpm_surf_t)( + const double *w, const double *dxv, const double *vlasov_pkpm_moms_l, + const double *vlasov_pkpm_moms_c, const double *vlasov_pkpm_moms_r, const double *prim_surf_l, + const double *prim_surf_c, const double *prim_surf_r, const double *p_ij_l, const double *p_ij_c, + const double *p_ij_r, const double *euler_pkpm_l, const double *euler_pkpm_c, + const double *euler_pkpm_r, const double *pkpm_lax_l, const double *pkpm_lax_r, + const double *pkpm_penalization_l, const double *pkpm_penalization_r, double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_euler_pkpm_vol_kern_list; -typedef struct { euler_pkpm_surf_t kernels[3]; } gkyl_dg_euler_pkpm_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_euler_pkpm_vol_kern_list; +typedef struct { + euler_pkpm_surf_t kernels[3]; +} gkyl_dg_euler_pkpm_surf_kern_list; struct dg_euler_pkpm { - struct gkyl_dg_eqn eqn; // Base object + struct gkyl_dg_eqn eqn; // Base object euler_pkpm_surf_t surf[3]; // pointers to surface kernels struct gkyl_range conf_range; // configuration space range struct gkyl_dg_euler_pkpm_auxfields auxfields; // Auxiliary fields. @@ -35,138 +39,130 @@ struct dg_euler_pkpm { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_euler_pkpm_vol_1x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_euler_pkpm_vol_1x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_euler_pkpm *euler_pkpm = container_of(eqn, struct dg_euler_pkpm, eqn); long cidx = gkyl_range_idx(&euler_pkpm->conf_range, idx); - return euler_pkpm_vol_1x_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim, cidx), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx), - qIn, qRhsOut); + return euler_pkpm_vol_1x_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim, cidx), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_euler_pkpm_vol_1x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_euler_pkpm_vol_1x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_euler_pkpm *euler_pkpm = container_of(eqn, struct dg_euler_pkpm, eqn); long cidx = gkyl_range_idx(&euler_pkpm->conf_range, idx); - return euler_pkpm_vol_1x_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim, cidx), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx), - qIn, qRhsOut); + return euler_pkpm_vol_1x_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim, cidx), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_euler_pkpm_vol_2x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_euler_pkpm_vol_2x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_euler_pkpm *euler_pkpm = container_of(eqn, struct dg_euler_pkpm, eqn); long cidx = gkyl_range_idx(&euler_pkpm->conf_range, idx); - return euler_pkpm_vol_2x_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim, cidx), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx), - qIn, qRhsOut); + return euler_pkpm_vol_2x_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim, cidx), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_euler_pkpm_vol_2x_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_euler_pkpm_vol_2x_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_euler_pkpm *euler_pkpm = container_of(eqn, struct dg_euler_pkpm, eqn); long cidx = gkyl_range_idx(&euler_pkpm->conf_range, idx); - return euler_pkpm_vol_2x_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim, cidx), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx), - qIn, qRhsOut); + return euler_pkpm_vol_2x_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim, cidx), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_euler_pkpm_vol_3x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_euler_pkpm_vol_3x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_euler_pkpm *euler_pkpm = container_of(eqn, struct dg_euler_pkpm, eqn); long cidx = gkyl_range_idx(&euler_pkpm->conf_range, idx); - return euler_pkpm_vol_3x_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim, cidx), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx), - qIn, qRhsOut); + return euler_pkpm_vol_3x_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim, cidx), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx), qIn, qRhsOut + ); } // PKPM Fluid Volume kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_euler_pkpm_vol_kern_list ser_vol_kernels[] = { - { NULL, kernel_euler_pkpm_vol_1x_ser_p1, kernel_euler_pkpm_vol_1x_ser_p2 }, // 0 - { NULL, kernel_euler_pkpm_vol_2x_ser_p1, NULL }, // 1 - { NULL, kernel_euler_pkpm_vol_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_pkpm_vol_kern_list ser_vol_kernels[] = { + {NULL, kernel_euler_pkpm_vol_1x_ser_p1, kernel_euler_pkpm_vol_1x_ser_p2}, // 0 + {NULL, kernel_euler_pkpm_vol_2x_ser_p1, NULL}, // 1 + {NULL, kernel_euler_pkpm_vol_3x_ser_p1, NULL} // 2 }; // PKPM Fluid Volume kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_dg_euler_pkpm_vol_kern_list ten_vol_kernels[] = { - { NULL, kernel_euler_pkpm_vol_1x_ser_p1, kernel_euler_pkpm_vol_1x_ser_p2 }, // 0 - { NULL, kernel_euler_pkpm_vol_2x_ser_p1, kernel_euler_pkpm_vol_2x_tensor_p2 }, // 1 - { NULL, kernel_euler_pkpm_vol_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_pkpm_vol_kern_list ten_vol_kernels[] = { + {NULL, kernel_euler_pkpm_vol_1x_ser_p1, kernel_euler_pkpm_vol_1x_ser_p2}, // 0 + {NULL, kernel_euler_pkpm_vol_2x_ser_p1, kernel_euler_pkpm_vol_2x_tensor_p2}, // 1 + {NULL, kernel_euler_pkpm_vol_3x_ser_p1, NULL} // 2 }; // PKPM Fluid Surface kernel list: x-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_euler_pkpm_surf_kern_list ser_surf_x_kernels[] = { - { NULL, euler_pkpm_surfx_1x_ser_p1, euler_pkpm_surfx_1x_ser_p2 }, // 0 - { NULL, euler_pkpm_surfx_2x_ser_p1, NULL }, // 1 - { NULL, euler_pkpm_surfx_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_pkpm_surf_kern_list ser_surf_x_kernels[] = { + {NULL, euler_pkpm_surfx_1x_ser_p1, euler_pkpm_surfx_1x_ser_p2}, // 0 + {NULL, euler_pkpm_surfx_2x_ser_p1, NULL}, // 1 + {NULL, euler_pkpm_surfx_3x_ser_p1, NULL} // 2 }; // PKPM Fluid Surface kernel list: x-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_euler_pkpm_surf_kern_list ten_surf_x_kernels[] = { - { NULL, euler_pkpm_surfx_1x_ser_p1, euler_pkpm_surfx_1x_ser_p2 }, // 0 - { NULL, euler_pkpm_surfx_2x_ser_p1, euler_pkpm_surfx_2x_tensor_p2 }, // 1 - { NULL, euler_pkpm_surfx_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_pkpm_surf_kern_list ten_surf_x_kernels[] = { + {NULL, euler_pkpm_surfx_1x_ser_p1, euler_pkpm_surfx_1x_ser_p2}, // 0 + {NULL, euler_pkpm_surfx_2x_ser_p1, euler_pkpm_surfx_2x_tensor_p2}, // 1 + {NULL, euler_pkpm_surfx_3x_ser_p1, NULL} // 2 }; // PKPM Fluid Surface kernel list: y-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_euler_pkpm_surf_kern_list ser_surf_y_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, euler_pkpm_surfy_2x_ser_p1, NULL }, // 1 - { NULL, euler_pkpm_surfy_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_pkpm_surf_kern_list ser_surf_y_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, euler_pkpm_surfy_2x_ser_p1, NULL}, // 1 + {NULL, euler_pkpm_surfy_3x_ser_p1, NULL} // 2 }; // PKPM Fluid Surface kernel list: y-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_euler_pkpm_surf_kern_list ten_surf_y_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, euler_pkpm_surfy_2x_ser_p1, euler_pkpm_surfy_2x_tensor_p2 }, // 1 - { NULL, euler_pkpm_surfy_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_pkpm_surf_kern_list ten_surf_y_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, euler_pkpm_surfy_2x_ser_p1, euler_pkpm_surfy_2x_tensor_p2}, // 1 + {NULL, euler_pkpm_surfy_3x_ser_p1, NULL} // 2 }; // PKPM Fluid Surface kernel list: z-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_euler_pkpm_surf_kern_list ser_surf_z_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, euler_pkpm_surfz_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_pkpm_surf_kern_list ser_surf_z_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, euler_pkpm_surfz_3x_ser_p1, NULL} // 2 }; // PKPM Fluid Surface kernel list: z-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_euler_pkpm_surf_kern_list ten_surf_z_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, euler_pkpm_surfz_3x_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_pkpm_surf_kern_list ten_surf_z_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, euler_pkpm_surfz_3x_ser_p1, NULL} // 2 }; /** @@ -176,14 +172,12 @@ static const gkyl_dg_euler_pkpm_surf_kern_list ten_surf_z_kernels[] = { */ void gkyl_euler_pkpm_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_euler_pkpm *euler_pkpm = container_of(eqn, struct dg_euler_pkpm, eqn); @@ -191,32 +185,28 @@ surf(const struct gkyl_dg_eqn *eqn, long cidx_c = gkyl_range_idx(&euler_pkpm->conf_range, idxC); long cidx_r = gkyl_range_idx(&euler_pkpm->conf_range, idxR); - return euler_pkpm->surf[dir](xcC, dxC, - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.vlasov_pkpm_moms, cidx_l), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.vlasov_pkpm_moms, cidx_c), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.vlasov_pkpm_moms, cidx_r), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim_surf, cidx_l), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim_surf, cidx_c), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim_surf, cidx_r), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx_l), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx_c), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx_r), - qInL, qInC, qInR, - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_lax, cidx_c), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_lax, cidx_r), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_penalization, cidx_c), - (const double*) gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_penalization, cidx_r), - qRhsOut); + return euler_pkpm->surf[dir]( + xcC, dxC, (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.vlasov_pkpm_moms, cidx_l), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.vlasov_pkpm_moms, cidx_c), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.vlasov_pkpm_moms, cidx_r), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim_surf, cidx_l), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim_surf, cidx_c), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_prim_surf, cidx_r), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx_l), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx_c), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_p_ij, cidx_r), qInL, qInC, qInR, + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_lax, cidx_c), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_lax, cidx_r), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_penalization, cidx_c), + (const double *)gkyl_array_cfetch(euler_pkpm->auxfields.pkpm_penalization, cidx_r), qRhsOut + ); } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) -{ +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) +{ return 0.; } diff --git a/pkpm/zero/gkyl_dg_lbo_pkpm_diff.h b/pkpm/zero/gkyl_dg_lbo_pkpm_diff.h index d6f9ee7a19..7ffb4b8c57 100644 --- a/pkpm/zero/gkyl_dg_lbo_pkpm_diff.h +++ b/pkpm/zero/gkyl_dg_lbo_pkpm_diff.h @@ -7,7 +7,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_lbo_pkpm_diff_auxfields { +struct gkyl_dg_lbo_pkpm_diff_auxfields { const struct gkyl_array *nuSum; const struct gkyl_array *nuPrimMomsSum; }; @@ -23,13 +23,15 @@ struct gkyl_dg_lbo_pkpm_diff_auxfields { * @param use_gpu Bool to determine if equation object is on host or device * @return Pointer to LBO diffusion term equation object */ -struct gkyl_dg_eqn* gkyl_dg_lbo_pkpm_diff_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - const struct gkyl_rect_grid *pgrid, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_lbo_pkpm_diff_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu +); -struct gkyl_dg_eqn* gkyl_dg_lbo_pkpm_diff_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - const struct gkyl_rect_grid *pgrid); +struct gkyl_dg_eqn *gkyl_dg_lbo_pkpm_diff_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +); /** * Set auxiliary fields needed in updating the diffusion flux term, @@ -38,7 +40,9 @@ struct gkyl_dg_eqn* gkyl_dg_lbo_pkpm_diff_cu_dev_new(const struct gkyl_basis* cb * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_lbo_pkpm_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_diff_auxfields auxin); +void gkyl_lbo_pkpm_diff_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_diff_auxfields auxin +); #ifdef GKYL_HAVE_CUDA @@ -49,6 +53,8 @@ void gkyl_lbo_pkpm_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_lbo_pkpm_diff_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_diff_auxfields auxin); +void gkyl_lbo_pkpm_diff_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_diff_auxfields auxin +); #endif diff --git a/pkpm/zero/gkyl_dg_lbo_pkpm_diff_priv.h b/pkpm/zero/gkyl_dg_lbo_pkpm_diff_priv.h index 43bbc0efdd..86d2e3115e 100644 --- a/pkpm/zero/gkyl_dg_lbo_pkpm_diff_priv.h +++ b/pkpm/zero/gkyl_dg_lbo_pkpm_diff_priv.h @@ -5,19 +5,26 @@ #include // Types for various kernels -typedef double (*lbo_pkpm_diff_surf_t)(const double *w, const double *dxv, - const double *nuSum, const double *nuPrimMomsSum, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); - -typedef double (*lbo_pkpm_diff_boundary_surf_t)(const double *w, const double *dxv, - const double *nuSum, const double *nuPrimMomsSum, - const int edge, const double *fSkin, const double *fEdge, double* GKYL_RESTRICT out); +typedef double (*lbo_pkpm_diff_surf_t)( + const double *w, const double *dxv, const double *nuSum, const double *nuPrimMomsSum, + const double *fl, const double *fc, const double *fr, double *GKYL_RESTRICT out +); +typedef double (*lbo_pkpm_diff_boundary_surf_t)( + const double *w, const double *dxv, const double *nuSum, const double *nuPrimMomsSum, + const int edge, const double *fSkin, const double *fEdge, double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_lbo_pkpm_diff_vol_kern_list; -typedef struct { lbo_pkpm_diff_surf_t kernels[3]; } gkyl_dg_lbo_pkpm_diff_surf_kern_list; -typedef struct { lbo_pkpm_diff_boundary_surf_t kernels[3]; } gkyl_dg_lbo_pkpm_diff_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_lbo_pkpm_diff_vol_kern_list; +typedef struct { + lbo_pkpm_diff_surf_t kernels[3]; +} gkyl_dg_lbo_pkpm_diff_surf_kern_list; +typedef struct { + lbo_pkpm_diff_boundary_surf_t kernels[3]; +} gkyl_dg_lbo_pkpm_diff_boundary_surf_kern_list; struct dg_lbo_pkpm_diff { struct gkyl_dg_eqn eqn; // Base object @@ -31,13 +38,13 @@ struct dg_lbo_pkpm_diff { int num_cbasis; }; -GKYL_CU_DH -static inline bool -checkPrimMomCross(struct dg_lbo_pkpm_diff *lbo_pkpm_diff, - const double* nuSum_p, const double* nuVtSqSum_p) { +GKYL_CU_DH static inline bool checkPrimMomCross( + struct dg_lbo_pkpm_diff *lbo_pkpm_diff, const double *nuSum_p, const double *nuVtSqSum_p +) +{ bool noPrimMomCross = true; - noPrimMomCross = noPrimMomCross && ((nuVtSqSum_p[0]>0.) - && (nuVtSqSum_p[0]/nuSum_p[0] < lbo_pkpm_diff->vMaxSq)); + noPrimMomCross = noPrimMomCross && + ((nuVtSqSum_p[0] > 0.) && (nuVtSqSum_p[0] / nuSum_p[0] < lbo_pkpm_diff->vMaxSq)); return noPrimMomCross; } @@ -46,17 +53,18 @@ checkPrimMomCross(struct dg_lbo_pkpm_diff *lbo_pkpm_diff, // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_lbo_pkpm_diff_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_diff_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(eqn, struct dg_lbo_pkpm_diff, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_diff, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_diff_vol_1x1v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -65,17 +73,18 @@ kernel_lbo_pkpm_diff_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double } } -GKYL_CU_DH -static double -kernel_lbo_pkpm_diff_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_diff_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(eqn, struct dg_lbo_pkpm_diff, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_diff, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_diff_vol_1x1v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -84,17 +93,18 @@ kernel_lbo_pkpm_diff_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double } } -GKYL_CU_DH -static double -kernel_lbo_pkpm_diff_vol_1x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_diff_vol_1x1v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(eqn, struct dg_lbo_pkpm_diff, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_diff, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_diff_vol_1x1v_tensor_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -103,17 +113,18 @@ kernel_lbo_pkpm_diff_vol_1x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const dou } } -GKYL_CU_DH -static double -kernel_lbo_pkpm_diff_vol_2x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_diff_vol_2x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(eqn, struct dg_lbo_pkpm_diff, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_diff, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_diff_vol_2x1v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -122,17 +133,18 @@ kernel_lbo_pkpm_diff_vol_2x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double } } -GKYL_CU_DH -static double -kernel_lbo_pkpm_diff_vol_2x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_diff_vol_2x1v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(eqn, struct dg_lbo_pkpm_diff, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_diff, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_diff_vol_2x1v_tensor_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -141,17 +153,18 @@ kernel_lbo_pkpm_diff_vol_2x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const dou } } -GKYL_CU_DH -static double -kernel_lbo_pkpm_diff_vol_3x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_diff_vol_3x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(eqn, struct dg_lbo_pkpm_diff, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_diff, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_diff_vol_3x1v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -161,116 +174,111 @@ kernel_lbo_pkpm_diff_vol_3x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double } // Volume kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_diff_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_pkpm_diff_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, kernel_lbo_pkpm_diff_vol_1x1v_ser_p1, kernel_lbo_pkpm_diff_vol_1x1v_ser_p2 }, // 0 + {NULL, kernel_lbo_pkpm_diff_vol_1x1v_ser_p1, kernel_lbo_pkpm_diff_vol_1x1v_ser_p2}, // 0 // 2x kernels - { NULL, kernel_lbo_pkpm_diff_vol_2x1v_ser_p1, NULL }, // 1 + {NULL, kernel_lbo_pkpm_diff_vol_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, kernel_lbo_pkpm_diff_vol_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_lbo_pkpm_diff_vol_3x1v_ser_p1, NULL} // 2 }; // Volume kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_diff_vol_kern_list ten_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_pkpm_diff_vol_kern_list ten_vol_kernels[] = { // 1x kernels - { NULL, kernel_lbo_pkpm_diff_vol_1x1v_ser_p1, kernel_lbo_pkpm_diff_vol_1x1v_tensor_p2 }, // 0 + {NULL, kernel_lbo_pkpm_diff_vol_1x1v_ser_p1, kernel_lbo_pkpm_diff_vol_1x1v_tensor_p2}, // 0 // 2x kernels - { NULL, kernel_lbo_pkpm_diff_vol_2x1v_ser_p1, kernel_lbo_pkpm_diff_vol_2x1v_tensor_p2 }, // 1 + {NULL, kernel_lbo_pkpm_diff_vol_2x1v_ser_p1, kernel_lbo_pkpm_diff_vol_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, kernel_lbo_pkpm_diff_vol_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_lbo_pkpm_diff_vol_3x1v_ser_p1, NULL} // 2 }; // Constant nu surface kernel list: vpar-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_diff_surf_kern_list ser_surf_vpar_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_pkpm_diff_surf_kern_list ser_surf_vpar_kernels[] = { // 1x kernels - { NULL, lbo_pkpm_diff_surfvpar_1x1v_ser_p1, lbo_pkpm_diff_surfvpar_1x1v_ser_p2 }, // 0 + {NULL, lbo_pkpm_diff_surfvpar_1x1v_ser_p1, lbo_pkpm_diff_surfvpar_1x1v_ser_p2}, // 0 // 2x kernels - { NULL, lbo_pkpm_diff_surfvpar_2x1v_ser_p1, NULL }, // 1 + {NULL, lbo_pkpm_diff_surfvpar_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, lbo_pkpm_diff_surfvpar_3x1v_ser_p1, NULL }, // 2 + {NULL, lbo_pkpm_diff_surfvpar_3x1v_ser_p1, NULL} // 2 }; // Constant nu surface kernel list: vpar-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_diff_surf_kern_list ten_surf_vpar_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_pkpm_diff_surf_kern_list ten_surf_vpar_kernels[] = { // 1x kernels - { NULL, lbo_pkpm_diff_surfvpar_1x1v_ser_p1, lbo_pkpm_diff_surfvpar_1x1v_tensor_p2 }, // 0 + {NULL, lbo_pkpm_diff_surfvpar_1x1v_ser_p1, lbo_pkpm_diff_surfvpar_1x1v_tensor_p2}, // 0 // 2x kernels - { NULL, lbo_pkpm_diff_surfvpar_2x1v_ser_p1, lbo_pkpm_diff_surfvpar_2x1v_tensor_p2 }, // 1 + {NULL, lbo_pkpm_diff_surfvpar_2x1v_ser_p1, lbo_pkpm_diff_surfvpar_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, lbo_pkpm_diff_surfvpar_3x1v_ser_p1, NULL }, // 2 + {NULL, lbo_pkpm_diff_surfvpar_3x1v_ser_p1, NULL} // 2 }; // Constant nu boundary surface kernel (zero-flux BCs) list: vpar-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_diff_boundary_surf_kern_list ser_boundary_surf_vpar_kernels[] = { - // 1x kernels - { NULL, lbo_pkpm_diff_boundary_surfvpar_1x1v_ser_p1, lbo_pkpm_diff_boundary_surfvpar_1x1v_ser_p2 }, // 0 - // 2x kernels - { NULL, lbo_pkpm_diff_boundary_surfvpar_2x1v_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, lbo_pkpm_diff_boundary_surfvpar_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_lbo_pkpm_diff_boundary_surf_kern_list + ser_boundary_surf_vpar_kernels[] = { + // 1x kernels + {NULL, lbo_pkpm_diff_boundary_surfvpar_1x1v_ser_p1, lbo_pkpm_diff_boundary_surfvpar_1x1v_ser_p2 + }, // 0 + // 2x kernels + {NULL, lbo_pkpm_diff_boundary_surfvpar_2x1v_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, lbo_pkpm_diff_boundary_surfvpar_3x1v_ser_p1, NULL} // 2 }; // Constant nu boundary surface kernel (zero-flux BCs) list: vpar-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_diff_boundary_surf_kern_list ten_boundary_surf_vpar_kernels[] = { - // 1x kernels - { NULL, lbo_pkpm_diff_boundary_surfvpar_1x1v_ser_p1, lbo_pkpm_diff_boundary_surfvpar_1x1v_tensor_p2 }, // 0 - // 2x kernels - { NULL, lbo_pkpm_diff_boundary_surfvpar_2x1v_ser_p1, lbo_pkpm_diff_boundary_surfvpar_2x1v_tensor_p2 }, // 1 - // 3x kernels - { NULL, lbo_pkpm_diff_boundary_surfvpar_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_lbo_pkpm_diff_boundary_surf_kern_list + ten_boundary_surf_vpar_kernels[] = { + // 1x kernels + {NULL, lbo_pkpm_diff_boundary_surfvpar_1x1v_ser_p1, + lbo_pkpm_diff_boundary_surfvpar_1x1v_tensor_p2}, // 0 + // 2x kernels + {NULL, lbo_pkpm_diff_boundary_surfvpar_2x1v_ser_p1, + lbo_pkpm_diff_boundary_surfvpar_2x1v_tensor_p2}, // 1 + // 3x kernels + {NULL, lbo_pkpm_diff_boundary_surfvpar_3x1v_ser_p1, NULL} // 2 }; -void gkyl_lbo_pkpm_diff_free(const struct gkyl_ref_count* ref); +void gkyl_lbo_pkpm_diff_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(eqn, struct dg_lbo_pkpm_diff, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_diff->conf_range, idxC); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_diff, nuSum_p, nuVtSqSum_p); if ((dir >= lbo_pkpm_diff->cdim) && (noPrimMomCross)) { - return lbo_pkpm_diff->surf(xcC, dxC, - nuSum_p, nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut); + return lbo_pkpm_diff->surf(xcC, dxC, nuSum_p, nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut); } return 0.; } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_diff *lbo_pkpm_diff = container_of(eqn, struct dg_lbo_pkpm_diff, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_diff->conf_range, idxSkin); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_diff, nuSum_p, nuVtSqSum_p); if ((dir >= lbo_pkpm_diff->cdim) && (noPrimMomCross)) { - return lbo_pkpm_diff->boundary_surf(xcSkin, dxSkin, - nuSum_p, nuPrimMomsSum_p, edge, qInSkin, qInEdge, qRhsOut); + return lbo_pkpm_diff->boundary_surf( + xcSkin, dxSkin, nuSum_p, nuPrimMomsSum_p, edge, qInSkin, qInEdge, qRhsOut + ); } return 0.; } - diff --git a/pkpm/zero/gkyl_dg_lbo_pkpm_drag.h b/pkpm/zero/gkyl_dg_lbo_pkpm_drag.h index e1fd286599..2faf0bd181 100644 --- a/pkpm/zero/gkyl_dg_lbo_pkpm_drag.h +++ b/pkpm/zero/gkyl_dg_lbo_pkpm_drag.h @@ -26,13 +26,15 @@ struct gkyl_dg_lbo_pkpm_drag_auxfields { * @param use_gpu Bool to determine if equation object is on host or device * @return Pointer to LBO drag term equation object */ -struct gkyl_dg_eqn* gkyl_dg_lbo_pkpm_drag_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - const struct gkyl_rect_grid *pgrid, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_lbo_pkpm_drag_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu +); -struct gkyl_dg_eqn* gkyl_dg_lbo_pkpm_drag_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - const struct gkyl_rect_grid *pgrid); +struct gkyl_dg_eqn *gkyl_dg_lbo_pkpm_drag_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +); /** * Set auxiliary fields needed in updating the drag flux term (nu = the collision frequency). @@ -40,7 +42,9 @@ struct gkyl_dg_eqn* gkyl_dg_lbo_pkpm_drag_cu_dev_new(const struct gkyl_basis* cb * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_lbo_pkpm_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_drag_auxfields auxin); +void gkyl_lbo_pkpm_drag_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_drag_auxfields auxin +); #ifdef GKYL_HAVE_CUDA @@ -50,6 +54,8 @@ void gkyl_lbo_pkpm_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_lbo_pkpm_drag_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_drag_auxfields auxin); +void gkyl_lbo_pkpm_drag_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_pkpm_drag_auxfields auxin +); #endif diff --git a/pkpm/zero/gkyl_dg_lbo_pkpm_drag_priv.h b/pkpm/zero/gkyl_dg_lbo_pkpm_drag_priv.h index 43cdf7ce65..6cd15fe0d2 100644 --- a/pkpm/zero/gkyl_dg_lbo_pkpm_drag_priv.h +++ b/pkpm/zero/gkyl_dg_lbo_pkpm_drag_priv.h @@ -5,18 +5,26 @@ #include // Types for various kernels -typedef double (*lbo_pkpm_drag_surf_t)(const double *w, const double *dxv, - const double *nuSum, const double *nuPrimMomsSum, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); +typedef double (*lbo_pkpm_drag_surf_t)( + const double *w, const double *dxv, const double *nuSum, const double *nuPrimMomsSum, + const double *fl, const double *fc, const double *fr, double *GKYL_RESTRICT out +); -typedef double (*lbo_pkpm_drag_boundary_surf_t)(const double *w, const double *dxv, - const double *nuSum, const double *nuPrimMomsSum, - const int edge, const double *fSkin, const double *fEdge, double* GKYL_RESTRICT out); +typedef double (*lbo_pkpm_drag_boundary_surf_t)( + const double *w, const double *dxv, const double *nuSum, const double *nuPrimMomsSum, + const int edge, const double *fSkin, const double *fEdge, double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_lbo_pkpm_drag_vol_kern_list; -typedef struct { lbo_pkpm_drag_surf_t kernels[3]; } gkyl_dg_lbo_pkpm_drag_surf_kern_list; -typedef struct { lbo_pkpm_drag_boundary_surf_t kernels[3]; } gkyl_dg_lbo_pkpm_drag_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_lbo_pkpm_drag_vol_kern_list; +typedef struct { + lbo_pkpm_drag_surf_t kernels[3]; +} gkyl_dg_lbo_pkpm_drag_surf_kern_list; +typedef struct { + lbo_pkpm_drag_boundary_surf_t kernels[3]; +} gkyl_dg_lbo_pkpm_drag_boundary_surf_kern_list; struct dg_lbo_pkpm_drag { struct gkyl_dg_eqn eqn; // Base object @@ -30,13 +38,13 @@ struct dg_lbo_pkpm_drag { int num_cbasis; }; -GKYL_CU_DH -static inline bool -checkPrimMomCross(struct dg_lbo_pkpm_drag *lbo_pkpm_drag, - const double* nuSum_p, const double* nuVtSqSum_p) { +GKYL_CU_DH static inline bool checkPrimMomCross( + struct dg_lbo_pkpm_drag *lbo_pkpm_drag, const double *nuSum_p, const double *nuVtSqSum_p +) +{ bool noPrimMomCross = true; - noPrimMomCross = noPrimMomCross && ((nuVtSqSum_p[0]>0.) - && (nuVtSqSum_p[0]/nuSum_p[0] < lbo_pkpm_drag->vMaxSq)); + noPrimMomCross = noPrimMomCross && + ((nuVtSqSum_p[0] > 0.) && (nuVtSqSum_p[0] / nuSum_p[0] < lbo_pkpm_drag->vMaxSq)); return noPrimMomCross; } @@ -45,17 +53,18 @@ checkPrimMomCross(struct dg_lbo_pkpm_drag *lbo_pkpm_drag, // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_lbo_pkpm_drag_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_drag_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(eqn, struct dg_lbo_pkpm_drag, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_drag, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_drag_vol_1x1v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -64,17 +73,18 @@ kernel_lbo_pkpm_drag_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double } } -GKYL_CU_DH -static double -kernel_lbo_pkpm_drag_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_drag_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(eqn, struct dg_lbo_pkpm_drag, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_drag, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_drag_vol_1x1v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -83,17 +93,18 @@ kernel_lbo_pkpm_drag_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double } } -GKYL_CU_DH -static double -kernel_lbo_pkpm_drag_vol_1x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_drag_vol_1x1v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(eqn, struct dg_lbo_pkpm_drag, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_drag, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_drag_vol_1x1v_tensor_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -102,17 +113,18 @@ kernel_lbo_pkpm_drag_vol_1x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const dou } } -GKYL_CU_DH -static double -kernel_lbo_pkpm_drag_vol_2x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_drag_vol_2x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(eqn, struct dg_lbo_pkpm_drag, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_drag, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_drag_vol_2x1v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -121,17 +133,18 @@ kernel_lbo_pkpm_drag_vol_2x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double } } -GKYL_CU_DH -static double -kernel_lbo_pkpm_drag_vol_2x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_drag_vol_2x1v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(eqn, struct dg_lbo_pkpm_drag, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_drag, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_drag_vol_2x1v_tensor_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -140,17 +153,18 @@ kernel_lbo_pkpm_drag_vol_2x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const dou } } -GKYL_CU_DH -static double -kernel_lbo_pkpm_drag_vol_3x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_pkpm_drag_vol_3x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(eqn, struct dg_lbo_pkpm_drag, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_drag, nuSum_p, nuVtSqSum_p); if (noPrimMomCross) { return lbo_pkpm_drag_vol_3x1v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); @@ -160,117 +174,111 @@ kernel_lbo_pkpm_drag_vol_3x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double } // Volume kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_drag_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_pkpm_drag_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, kernel_lbo_pkpm_drag_vol_1x1v_ser_p1, kernel_lbo_pkpm_drag_vol_1x1v_ser_p2 }, // 0 + {NULL, kernel_lbo_pkpm_drag_vol_1x1v_ser_p1, kernel_lbo_pkpm_drag_vol_1x1v_ser_p2}, // 0 // 2x kernels - { NULL, kernel_lbo_pkpm_drag_vol_2x1v_ser_p1, NULL }, // 1 + {NULL, kernel_lbo_pkpm_drag_vol_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, kernel_lbo_pkpm_drag_vol_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_lbo_pkpm_drag_vol_3x1v_ser_p1, NULL} // 2 }; // Volume kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_drag_vol_kern_list ten_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_pkpm_drag_vol_kern_list ten_vol_kernels[] = { // 1x kernels - { NULL, kernel_lbo_pkpm_drag_vol_1x1v_ser_p1, kernel_lbo_pkpm_drag_vol_1x1v_tensor_p2 }, // 0 + {NULL, kernel_lbo_pkpm_drag_vol_1x1v_ser_p1, kernel_lbo_pkpm_drag_vol_1x1v_tensor_p2}, // 0 // 2x kernels - { NULL, kernel_lbo_pkpm_drag_vol_2x1v_ser_p1, kernel_lbo_pkpm_drag_vol_2x1v_tensor_p2 }, // 1 + {NULL, kernel_lbo_pkpm_drag_vol_2x1v_ser_p1, kernel_lbo_pkpm_drag_vol_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, kernel_lbo_pkpm_drag_vol_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_lbo_pkpm_drag_vol_3x1v_ser_p1, NULL} // 2 }; - // Constant nu surface kernel list: vpar-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_drag_surf_kern_list ser_surf_vpar_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_pkpm_drag_surf_kern_list ser_surf_vpar_kernels[] = { // 1x kernels - { NULL, lbo_pkpm_drag_surfvpar_1x1v_ser_p1, lbo_pkpm_drag_surfvpar_1x1v_ser_p2 }, // 0 + {NULL, lbo_pkpm_drag_surfvpar_1x1v_ser_p1, lbo_pkpm_drag_surfvpar_1x1v_ser_p2}, // 0 // 2x kernels - { NULL, lbo_pkpm_drag_surfvpar_2x1v_ser_p1, NULL }, // 1 + {NULL, lbo_pkpm_drag_surfvpar_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, lbo_pkpm_drag_surfvpar_3x1v_ser_p1, NULL }, // 2 + {NULL, lbo_pkpm_drag_surfvpar_3x1v_ser_p1, NULL} // 2 }; // Constant nu surface kernel list: vpar-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_drag_surf_kern_list ten_surf_vpar_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_pkpm_drag_surf_kern_list ten_surf_vpar_kernels[] = { // 1x kernels - { NULL, lbo_pkpm_drag_surfvpar_1x1v_ser_p1, lbo_pkpm_drag_surfvpar_1x1v_tensor_p2 }, // 0 + {NULL, lbo_pkpm_drag_surfvpar_1x1v_ser_p1, lbo_pkpm_drag_surfvpar_1x1v_tensor_p2}, // 0 // 2x kernels - { NULL, lbo_pkpm_drag_surfvpar_2x1v_ser_p1, lbo_pkpm_drag_surfvpar_2x1v_tensor_p2 }, // 1 + {NULL, lbo_pkpm_drag_surfvpar_2x1v_ser_p1, lbo_pkpm_drag_surfvpar_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, lbo_pkpm_drag_surfvpar_3x1v_ser_p1, NULL }, // 2 + {NULL, lbo_pkpm_drag_surfvpar_3x1v_ser_p1, NULL} // 2 }; // Constant nu boundary surface kernel (zero-flux BCs) list: vpar-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_drag_boundary_surf_kern_list ser_boundary_surf_vpar_kernels[] = { - // 1x kernels - { NULL, lbo_pkpm_drag_boundary_surfvpar_1x1v_ser_p1, lbo_pkpm_drag_boundary_surfvpar_1x1v_ser_p2 }, // 0 - // 2x kernels - { NULL, lbo_pkpm_drag_boundary_surfvpar_2x1v_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, lbo_pkpm_drag_boundary_surfvpar_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_lbo_pkpm_drag_boundary_surf_kern_list + ser_boundary_surf_vpar_kernels[] = { + // 1x kernels + {NULL, lbo_pkpm_drag_boundary_surfvpar_1x1v_ser_p1, lbo_pkpm_drag_boundary_surfvpar_1x1v_ser_p2 + }, // 0 + // 2x kernels + {NULL, lbo_pkpm_drag_boundary_surfvpar_2x1v_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, lbo_pkpm_drag_boundary_surfvpar_3x1v_ser_p1, NULL} // 2 }; // Constant nu boundary surface kernel (zero-flux BCs) list: vpar-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_lbo_pkpm_drag_boundary_surf_kern_list ten_boundary_surf_vpar_kernels[] = { - // 1x kernels - { NULL, lbo_pkpm_drag_boundary_surfvpar_1x1v_ser_p1, lbo_pkpm_drag_boundary_surfvpar_1x1v_tensor_p2 }, // 0 - // 2x kernels - { NULL, lbo_pkpm_drag_boundary_surfvpar_2x1v_ser_p1, lbo_pkpm_drag_boundary_surfvpar_2x1v_tensor_p2 }, // 1 - // 3x kernels - { NULL, lbo_pkpm_drag_boundary_surfvpar_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_lbo_pkpm_drag_boundary_surf_kern_list + ten_boundary_surf_vpar_kernels[] = { + // 1x kernels + {NULL, lbo_pkpm_drag_boundary_surfvpar_1x1v_ser_p1, + lbo_pkpm_drag_boundary_surfvpar_1x1v_tensor_p2}, // 0 + // 2x kernels + {NULL, lbo_pkpm_drag_boundary_surfvpar_2x1v_ser_p1, + lbo_pkpm_drag_boundary_surfvpar_2x1v_tensor_p2}, // 1 + // 3x kernels + {NULL, lbo_pkpm_drag_boundary_surfvpar_3x1v_ser_p1, NULL} // 2 }; -void gkyl_lbo_pkpm_drag_free(const struct gkyl_ref_count* ref); +void gkyl_lbo_pkpm_drag_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(eqn, struct dg_lbo_pkpm_drag, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_drag->conf_range, idxC); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_drag, nuSum_p, nuVtSqSum_p); if ((dir >= lbo_pkpm_drag->cdim) && (noPrimMomCross)) { - return lbo_pkpm_drag->surf(xcC, dxC, - nuSum_p, nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut); + return lbo_pkpm_drag->surf(xcC, dxC, nuSum_p, nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut); } return 0.; } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_pkpm_drag *lbo_pkpm_drag = container_of(eqn, struct dg_lbo_pkpm_drag, eqn); long cidx = gkyl_range_idx(&lbo_pkpm_drag->conf_range, idxSkin); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_pkpm_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_pkpm_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_pkpm_drag, nuSum_p, nuVtSqSum_p); if ((dir >= lbo_pkpm_drag->cdim) && (noPrimMomCross)) { - return lbo_pkpm_drag->boundary_surf(xcSkin, dxSkin, - nuSum_p, nuPrimMomsSum_p, edge, qInSkin, qInEdge, qRhsOut); + return lbo_pkpm_drag->boundary_surf( + xcSkin, dxSkin, nuSum_p, nuPrimMomsSum_p, edge, qInSkin, qInEdge, qRhsOut + ); } return 0.; } - diff --git a/pkpm/zero/gkyl_dg_updater_lbo_pkpm.h b/pkpm/zero/gkyl_dg_updater_lbo_pkpm.h index 6a71f42b27..3d1151f8b6 100644 --- a/pkpm/zero/gkyl_dg_updater_lbo_pkpm.h +++ b/pkpm/zero/gkyl_dg_updater_lbo_pkpm.h @@ -28,12 +28,12 @@ struct gkyl_dg_updater_lbo_pkpm_tm { * @param use_gpu Bool for whether updater is on host or device * @return New PKPM LBO updater object */ -struct gkyl_dg_updater_collisions* -gkyl_dg_updater_lbo_pkpm_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *conf_range, - struct gkyl_dg_lbo_pkpm_drag_auxfields *drag_inp, struct gkyl_dg_lbo_pkpm_diff_auxfields *diff_inp, - bool use_gpu); +struct gkyl_dg_updater_collisions *gkyl_dg_updater_lbo_pkpm_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, + struct gkyl_dg_lbo_pkpm_drag_auxfields *drag_inp, + struct gkyl_dg_lbo_pkpm_diff_auxfields *diff_inp, bool use_gpu +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -47,9 +47,11 @@ gkyl_dg_updater_lbo_pkpm_new(const struct gkyl_rect_grid *phase_grid, * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_lbo_pkpm_advance(struct gkyl_dg_updater_collisions *lbo, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_lbo_pkpm_advance( + struct gkyl_dg_updater_collisions *lbo, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in drag and diffusion terms @@ -57,11 +59,12 @@ void gkyl_dg_updater_lbo_pkpm_advance(struct gkyl_dg_updater_collisions *lbo, * @param lbo Updater object * @return timers */ -struct gkyl_dg_updater_lbo_pkpm_tm gkyl_dg_updater_lbo_pkpm_get_tm(const struct gkyl_dg_updater_collisions *coll); +struct gkyl_dg_updater_lbo_pkpm_tm +gkyl_dg_updater_lbo_pkpm_get_tm(const struct gkyl_dg_updater_collisions *coll); /** * Delete updater. * * @param lbo Updater to delete. */ -void gkyl_dg_updater_lbo_pkpm_release(struct gkyl_dg_updater_collisions* coll); +void gkyl_dg_updater_lbo_pkpm_release(struct gkyl_dg_updater_collisions *coll); diff --git a/pkpm/zero/gkyl_dg_updater_moment_pkpm.h b/pkpm/zero/gkyl_dg_updater_moment_pkpm.h index ad9c028d47..1dbea387e1 100644 --- a/pkpm/zero/gkyl_dg_updater_moment_pkpm.h +++ b/pkpm/zero/gkyl_dg_updater_moment_pkpm.h @@ -27,11 +27,11 @@ typedef struct gkyl_dg_updater_moment_tm gkyl_dg_updater_moment_tm; * * @return New moment updater object */ -struct gkyl_dg_updater_moment* -gkyl_dg_updater_moment_pkpm_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, - double mass, bool is_diag, bool use_gpu); +struct gkyl_dg_updater_moment *gkyl_dg_updater_moment_pkpm_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, + const struct gkyl_range *vel_range, double mass, bool is_diag, bool use_gpu +); /** * Acquire moment object @@ -40,8 +40,8 @@ gkyl_dg_updater_moment_pkpm_new(const struct gkyl_rect_grid *grid, * * @return moment type object */ -struct gkyl_mom_type* -gkyl_dg_updater_moment_pkpm_acquire_type(const struct gkyl_dg_updater_moment* moment); +struct gkyl_mom_type * +gkyl_dg_updater_moment_pkpm_acquire_type(const struct gkyl_dg_updater_moment *moment); /** * Acquire number of moments @@ -50,8 +50,7 @@ gkyl_dg_updater_moment_pkpm_acquire_type(const struct gkyl_dg_updater_moment* mo * * @return number of moments */ -int -gkyl_dg_updater_moment_pkpm_num_mom(const struct gkyl_dg_updater_moment* moment); +int gkyl_dg_updater_moment_pkpm_num_mom(const struct gkyl_dg_updater_moment *moment); /** * Compute moment. The update_phase_rng and update_conf_rng MUST be a sub-range of the @@ -65,10 +64,11 @@ gkyl_dg_updater_moment_pkpm_num_mom(const struct gkyl_dg_updater_moment* moment) * @param fIn Input to updater * @param mout Output moment */ -void -gkyl_dg_updater_moment_pkpm_advance(struct gkyl_dg_updater_moment *moment, - const struct gkyl_range *update_phase_rng, const struct gkyl_range *update_conf_rng, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT mout); +void gkyl_dg_updater_moment_pkpm_advance( + struct gkyl_dg_updater_moment *moment, const struct gkyl_range *update_phase_rng, + const struct gkyl_range *update_conf_rng, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT mout +); /** * Return total time spent in computing moments @@ -76,11 +76,12 @@ gkyl_dg_updater_moment_pkpm_advance(struct gkyl_dg_updater_moment *moment, * @param moment Updater object * @return timers */ -struct gkyl_dg_updater_moment_tm gkyl_dg_updater_moment_pkpm_get_tm(const struct gkyl_dg_updater_moment *moment); +struct gkyl_dg_updater_moment_tm +gkyl_dg_updater_moment_pkpm_get_tm(const struct gkyl_dg_updater_moment *moment); /** * Delete updater. * * @param moment Updater to delete. */ -void gkyl_dg_updater_moment_pkpm_release(struct gkyl_dg_updater_moment* moment); \ No newline at end of file +void gkyl_dg_updater_moment_pkpm_release(struct gkyl_dg_updater_moment *moment); \ No newline at end of file diff --git a/pkpm/zero/gkyl_dg_updater_pkpm.h b/pkpm/zero/gkyl_dg_updater_pkpm.h index c668930d0b..d1cc6601f1 100644 --- a/pkpm/zero/gkyl_dg_updater_pkpm.h +++ b/pkpm/zero/gkyl_dg_updater_pkpm.h @@ -35,12 +35,13 @@ struct gkyl_dg_updater_pkpm_tm { * * @return New PKPM updater object */ -gkyl_dg_updater_pkpm* gkyl_dg_updater_pkpm_new(const struct gkyl_rect_grid *conf_grid, const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, +gkyl_dg_updater_pkpm *gkyl_dg_updater_pkpm_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_rect_grid *phase_grid, + const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const bool *is_zero_flux_dir, - struct gkyl_dg_vlasov_pkpm_auxfields *vlasov_pkpm_inp, struct gkyl_dg_euler_pkpm_auxfields *euler_pkpm_inp, - bool use_gpu); + const bool *is_zero_flux_dir, struct gkyl_dg_vlasov_pkpm_auxfields *vlasov_pkpm_inp, + struct gkyl_dg_euler_pkpm_auxfields *euler_pkpm_inp, bool use_gpu +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -54,11 +55,13 @@ gkyl_dg_updater_pkpm* gkyl_dg_updater_pkpm_new(const struct gkyl_rect_grid *conf * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_pkpm_advance(gkyl_dg_updater_pkpm *pkpm, - const struct gkyl_range *update_phase_rng, const struct gkyl_range *update_conf_rng, - const struct gkyl_array* GKYL_RESTRICT fIn, const struct gkyl_array* GKYL_RESTRICT fluidIn, - struct gkyl_array* GKYL_RESTRICT cflrate_f, struct gkyl_array* GKYL_RESTRICT cflrate_fluid, - struct gkyl_array* GKYL_RESTRICT rhs_f, struct gkyl_array* GKYL_RESTRICT rhs_fluid); +void gkyl_dg_updater_pkpm_advance( + gkyl_dg_updater_pkpm *pkpm, const struct gkyl_range *update_phase_rng, + const struct gkyl_range *update_conf_rng, const struct gkyl_array *GKYL_RESTRICT fIn, + const struct gkyl_array *GKYL_RESTRICT fluidIn, struct gkyl_array *GKYL_RESTRICT cflrate_f, + struct gkyl_array *GKYL_RESTRICT cflrate_fluid, struct gkyl_array *GKYL_RESTRICT rhs_f, + struct gkyl_array *GKYL_RESTRICT rhs_fluid +); /** * Return total time spent in PKPM kinetic equations and fluid equations @@ -73,4 +76,4 @@ struct gkyl_dg_updater_pkpm_tm gkyl_dg_updater_pkpm_get_tm(const gkyl_dg_updater * * @param pkpm Updater to delete. */ -void gkyl_dg_updater_pkpm_release(gkyl_dg_updater_pkpm* pkpm); +void gkyl_dg_updater_pkpm_release(gkyl_dg_updater_pkpm *pkpm); diff --git a/pkpm/zero/gkyl_dg_vlasov_pkpm.h b/pkpm/zero/gkyl_dg_vlasov_pkpm.h index a0a188e324..027678b4c5 100644 --- a/pkpm/zero/gkyl_dg_vlasov_pkpm.h +++ b/pkpm/zero/gkyl_dg_vlasov_pkpm.h @@ -8,7 +8,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_vlasov_pkpm_auxfields { +struct gkyl_dg_vlasov_pkpm_auxfields { const struct gkyl_array *bvar; const struct gkyl_array *bvar_surf; const struct gkyl_array *pkpm_prim; @@ -30,11 +30,15 @@ struct gkyl_dg_vlasov_pkpm_auxfields { * @param use_gpu bool to determine if on GPU * @return Pointer to Vlasov equation object for parallel-kinetic-perpendicular-moment (pkpm) model. */ -struct gkyl_dg_eqn* gkyl_dg_vlasov_pkpm_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* phase_range, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_vlasov_pkpm_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, bool use_gpu +); -struct gkyl_dg_eqn* gkyl_dg_vlasov_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* phase_range); +struct gkyl_dg_eqn *gkyl_dg_vlasov_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range +); /** * Set the auxiliary fields @@ -44,7 +48,9 @@ struct gkyl_dg_eqn* gkyl_dg_vlasov_pkpm_cu_dev_new(const struct gkyl_basis* cbas * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_vlasov_pkpm_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_pkpm_auxfields auxin); +void gkyl_vlasov_pkpm_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_pkpm_auxfields auxin +); #ifdef GKYL_HAVE_CUDA /** @@ -55,7 +61,8 @@ void gkyl_vlasov_pkpm_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_d * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_vlasov_pkpm_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_pkpm_auxfields auxin); - +void gkyl_vlasov_pkpm_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_pkpm_auxfields auxin +); #endif diff --git a/pkpm/zero/gkyl_dg_vlasov_pkpm_priv.h b/pkpm/zero/gkyl_dg_vlasov_pkpm_priv.h index 6347fbaed0..9d182864ff 100644 --- a/pkpm/zero/gkyl_dg_vlasov_pkpm_priv.h +++ b/pkpm/zero/gkyl_dg_vlasov_pkpm_priv.h @@ -10,28 +10,38 @@ #include // Types for various kernels -typedef double (*vlasov_pkpm_stream_surf_t)(const double *w, const double *dxv, - const double *bvar_surf_l, const double *bvar_surf_c, const double *bvar_surf_r, - const double *pkpm_prim_surf_l, const double *pkpm_prim_surf_c, const double *pkpm_prim_surf_r, - const double *fl, const double *fc, const double *fr, - const double *max_b, const double *pkpm_lax_l, const double *pkpm_lax_r, - double* GKYL_RESTRICT out); - -typedef double (*vlasov_pkpm_accel_surf_t)(const double *w, const double *dxv, - const double *div_b, const double *pkpm_accel_vars, - const double *g_dist_sourcel, const double *g_dist_sourcec, const double *g_dist_sourcer, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); - -typedef double (*vlasov_pkpm_accel_boundary_surf_t)(const double *w, const double *dxv, - const double *div_b, const double *pkpm_accel_vars, - const double *g_dist_sourceEdge, const double *g_dist_sourceSkin, - const int edge, const double *fEdge, const double *fSkin, double* GKYL_RESTRICT out); +typedef double (*vlasov_pkpm_stream_surf_t)( + const double *w, const double *dxv, const double *bvar_surf_l, const double *bvar_surf_c, + const double *bvar_surf_r, const double *pkpm_prim_surf_l, const double *pkpm_prim_surf_c, + const double *pkpm_prim_surf_r, const double *fl, const double *fc, const double *fr, + const double *max_b, const double *pkpm_lax_l, const double *pkpm_lax_r, double *GKYL_RESTRICT out +); + +typedef double (*vlasov_pkpm_accel_surf_t)( + const double *w, const double *dxv, const double *div_b, const double *pkpm_accel_vars, + const double *g_dist_sourcel, const double *g_dist_sourcec, const double *g_dist_sourcer, + const double *fl, const double *fc, const double *fr, double *GKYL_RESTRICT out +); + +typedef double (*vlasov_pkpm_accel_boundary_surf_t)( + const double *w, const double *dxv, const double *div_b, const double *pkpm_accel_vars, + const double *g_dist_sourceEdge, const double *g_dist_sourceSkin, const int edge, + const double *fEdge, const double *fSkin, double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_vlasov_pkpm_vol_kern_list; -typedef struct { vlasov_pkpm_stream_surf_t kernels[3]; } gkyl_dg_vlasov_pkpm_stream_surf_kern_list; -typedef struct { vlasov_pkpm_accel_surf_t kernels[3]; } gkyl_dg_vlasov_pkpm_accel_surf_kern_list; -typedef struct { vlasov_pkpm_accel_boundary_surf_t kernels[3]; } gkyl_dg_vlasov_pkpm_accel_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_vlasov_pkpm_vol_kern_list; +typedef struct { + vlasov_pkpm_stream_surf_t kernels[3]; +} gkyl_dg_vlasov_pkpm_stream_surf_kern_list; +typedef struct { + vlasov_pkpm_accel_surf_t kernels[3]; +} gkyl_dg_vlasov_pkpm_accel_surf_kern_list; +typedef struct { + vlasov_pkpm_accel_boundary_surf_t kernels[3]; +} gkyl_dg_vlasov_pkpm_accel_boundary_surf_kern_list; struct dg_vlasov_pkpm { struct gkyl_dg_eqn eqn; // Base object @@ -50,244 +60,237 @@ struct dg_vlasov_pkpm { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_vlasov_pkpm_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_pkpm_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_pkpm *vlasov_pkpm = container_of(eqn, struct dg_vlasov_pkpm, eqn); long cidx = gkyl_range_idx(&vlasov_pkpm->conf_range, idx); long pidx = gkyl_range_idx(&vlasov_pkpm->phase_range, idx); - return vlasov_pkpm_vol_1x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), - qIn, qRhsOut); + return vlasov_pkpm_vol_1x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_pkpm_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_pkpm_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_pkpm *vlasov_pkpm = container_of(eqn, struct dg_vlasov_pkpm, eqn); long cidx = gkyl_range_idx(&vlasov_pkpm->conf_range, idx); long pidx = gkyl_range_idx(&vlasov_pkpm->phase_range, idx); - return vlasov_pkpm_vol_1x1v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), - qIn, qRhsOut); + return vlasov_pkpm_vol_1x1v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_pkpm_vol_1x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_pkpm_vol_1x1v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_pkpm *vlasov_pkpm = container_of(eqn, struct dg_vlasov_pkpm, eqn); long cidx = gkyl_range_idx(&vlasov_pkpm->conf_range, idx); long pidx = gkyl_range_idx(&vlasov_pkpm->phase_range, idx); - return vlasov_pkpm_vol_1x1v_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), - qIn, qRhsOut); + return vlasov_pkpm_vol_1x1v_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_pkpm_vol_2x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_pkpm_vol_2x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_pkpm *vlasov_pkpm = container_of(eqn, struct dg_vlasov_pkpm, eqn); long cidx = gkyl_range_idx(&vlasov_pkpm->conf_range, idx); long pidx = gkyl_range_idx(&vlasov_pkpm->phase_range, idx); - return vlasov_pkpm_vol_2x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), - qIn, qRhsOut); + return vlasov_pkpm_vol_2x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_pkpm_vol_2x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_pkpm_vol_2x1v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_pkpm *vlasov_pkpm = container_of(eqn, struct dg_vlasov_pkpm, eqn); long cidx = gkyl_range_idx(&vlasov_pkpm->conf_range, idx); long pidx = gkyl_range_idx(&vlasov_pkpm->phase_range, idx); - return vlasov_pkpm_vol_2x1v_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), - qIn, qRhsOut); + return vlasov_pkpm_vol_2x1v_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_pkpm_vol_3x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_pkpm_vol_3x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_pkpm *vlasov_pkpm = container_of(eqn, struct dg_vlasov_pkpm, eqn); long cidx = gkyl_range_idx(&vlasov_pkpm->conf_range, idx); long pidx = gkyl_range_idx(&vlasov_pkpm->phase_range, idx); - return vlasov_pkpm_vol_3x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), - qIn, qRhsOut); + return vlasov_pkpm_vol_3x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx), qIn, qRhsOut + ); } // Volume kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_pkpm_vol_1x1v_ser_p1, kernel_vlasov_pkpm_vol_1x1v_ser_p2 }, // 0 + {NULL, kernel_vlasov_pkpm_vol_1x1v_ser_p1, kernel_vlasov_pkpm_vol_1x1v_ser_p2}, // 0 // 2x kernels - { NULL, kernel_vlasov_pkpm_vol_2x1v_ser_p1, NULL }, // 1 + {NULL, kernel_vlasov_pkpm_vol_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, kernel_vlasov_pkpm_vol_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_vlasov_pkpm_vol_3x1v_ser_p1, NULL} // 2 }; // Volume kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_vol_kern_list ten_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_vol_kern_list ten_vol_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_pkpm_vol_1x1v_ser_p1, kernel_vlasov_pkpm_vol_1x1v_tensor_p2 }, // 0 + {NULL, kernel_vlasov_pkpm_vol_1x1v_ser_p1, kernel_vlasov_pkpm_vol_1x1v_tensor_p2}, // 0 // 2x kernels - { NULL, kernel_vlasov_pkpm_vol_2x1v_ser_p1, kernel_vlasov_pkpm_vol_2x1v_tensor_p2 }, // 1 + {NULL, kernel_vlasov_pkpm_vol_2x1v_ser_p1, kernel_vlasov_pkpm_vol_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, kernel_vlasov_pkpm_vol_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_vlasov_pkpm_vol_3x1v_ser_p1, NULL} // 2 }; // Streaming surface kernel list: x-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ser_stream_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ser_stream_surf_x_kernels[] = { // 1x kernels - { NULL, vlasov_pkpm_surfx_1x1v_ser_p1, vlasov_pkpm_surfx_1x1v_ser_p2 }, // 0 + {NULL, vlasov_pkpm_surfx_1x1v_ser_p1, vlasov_pkpm_surfx_1x1v_ser_p2}, // 0 // 2x kernels - { NULL, vlasov_pkpm_surfx_2x1v_ser_p1, NULL }, // 1 + {NULL, vlasov_pkpm_surfx_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, vlasov_pkpm_surfx_3x1v_ser_p1, NULL }, // 2 + {NULL, vlasov_pkpm_surfx_3x1v_ser_p1, NULL} // 2 }; // Streaming surface kernel list: x-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ten_stream_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ten_stream_surf_x_kernels[] = { // 1x kernels - { NULL, vlasov_pkpm_surfx_1x1v_ser_p1, vlasov_pkpm_surfx_1x1v_tensor_p2 }, // 0 + {NULL, vlasov_pkpm_surfx_1x1v_ser_p1, vlasov_pkpm_surfx_1x1v_tensor_p2}, // 0 // 2x kernels - { NULL, vlasov_pkpm_surfx_2x1v_ser_p1, vlasov_pkpm_surfx_2x1v_tensor_p2 }, // 1 + {NULL, vlasov_pkpm_surfx_2x1v_ser_p1, vlasov_pkpm_surfx_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, vlasov_pkpm_surfx_3x1v_ser_p1, NULL }, // 2 + {NULL, vlasov_pkpm_surfx_3x1v_ser_p1, NULL} // 2 }; // Streaming surface kernel list: y-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ser_stream_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ser_stream_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, vlasov_pkpm_surfy_2x1v_ser_p1, NULL }, // 1 + {NULL, vlasov_pkpm_surfy_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, vlasov_pkpm_surfy_3x1v_ser_p1, NULL }, // 2 + {NULL, vlasov_pkpm_surfy_3x1v_ser_p1, NULL} // 2 }; // Streaming surface kernel list: y-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ten_stream_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ten_stream_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, vlasov_pkpm_surfy_2x1v_ser_p1, vlasov_pkpm_surfy_2x1v_tensor_p2 }, // 1 + {NULL, vlasov_pkpm_surfy_2x1v_ser_p1, vlasov_pkpm_surfy_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, vlasov_pkpm_surfy_3x1v_ser_p1, NULL }, // 2 + {NULL, vlasov_pkpm_surfy_3x1v_ser_p1, NULL} // 2 }; // Streaming surface kernel list: z-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ser_stream_surf_z_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ser_stream_surf_z_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, NULL, NULL }, // 1 + {NULL, NULL, NULL}, // 1 // 3x kernels - { NULL, vlasov_pkpm_surfz_3x1v_ser_p1, NULL }, // 2 + {NULL, vlasov_pkpm_surfz_3x1v_ser_p1, NULL} // 2 }; // Streaming surface kernel list: z-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ten_stream_surf_z_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_stream_surf_kern_list ten_stream_surf_z_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, NULL, NULL }, // 1 + {NULL, NULL, NULL}, // 1 // 3x kernels - { NULL, vlasov_pkpm_surfz_3x1v_ser_p1, NULL }, // 2 + {NULL, vlasov_pkpm_surfz_3x1v_ser_p1, NULL} // 2 }; // Acceleration surface kernel list: vpar-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_accel_surf_kern_list ser_accel_surf_vpar_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_accel_surf_kern_list ser_accel_surf_vpar_kernels[] = { // 1x kernels - { NULL, vlasov_pkpm_surfvpar_1x1v_ser_p1, vlasov_pkpm_surfvpar_1x1v_ser_p2 }, // 0 + {NULL, vlasov_pkpm_surfvpar_1x1v_ser_p1, vlasov_pkpm_surfvpar_1x1v_ser_p2}, // 0 // 2x kernels - { NULL, vlasov_pkpm_surfvpar_2x1v_ser_p1, NULL }, // 1 + {NULL, vlasov_pkpm_surfvpar_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, vlasov_pkpm_surfvpar_3x1v_ser_p1, NULL }, // 2 + {NULL, vlasov_pkpm_surfvpar_3x1v_ser_p1, NULL} // 2 }; // Acceleration surface kernel list: vpar-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_accel_surf_kern_list ten_accel_surf_vpar_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_accel_surf_kern_list ten_accel_surf_vpar_kernels[] = { // 1x kernels - { NULL, vlasov_pkpm_surfvpar_1x1v_ser_p1, vlasov_pkpm_surfvpar_1x1v_tensor_p2 }, // 0 + {NULL, vlasov_pkpm_surfvpar_1x1v_ser_p1, vlasov_pkpm_surfvpar_1x1v_tensor_p2}, // 0 // 2x kernels - { NULL, vlasov_pkpm_surfvpar_2x1v_ser_p1, vlasov_pkpm_surfvpar_2x1v_tensor_p2 }, // 1 + {NULL, vlasov_pkpm_surfvpar_2x1v_ser_p1, vlasov_pkpm_surfvpar_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, vlasov_pkpm_surfvpar_3x1v_ser_p1, NULL }, // 2 + {NULL, vlasov_pkpm_surfvpar_3x1v_ser_p1, NULL} // 2 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vpar-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_accel_boundary_surf_kern_list ser_accel_boundary_surf_vpar_kernels[] = { - // 1x kernels - { NULL, vlasov_pkpm_boundary_surfvpar_1x1v_ser_p1, vlasov_pkpm_boundary_surfvpar_1x1v_ser_p2 }, // 0 - // 2x kernels - { NULL, vlasov_pkpm_boundary_surfvpar_2x1v_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, vlasov_pkpm_boundary_surfvpar_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_accel_boundary_surf_kern_list + ser_accel_boundary_surf_vpar_kernels[] = { + // 1x kernels + {NULL, vlasov_pkpm_boundary_surfvpar_1x1v_ser_p1, vlasov_pkpm_boundary_surfvpar_1x1v_ser_p2 + }, // 0 + // 2x kernels + {NULL, vlasov_pkpm_boundary_surfvpar_2x1v_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, vlasov_pkpm_boundary_surfvpar_3x1v_ser_p1, NULL} // 2 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vpar-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_pkpm_accel_boundary_surf_kern_list ten_accel_boundary_surf_vpar_kernels[] = { - // 1x kernels - { NULL, vlasov_pkpm_boundary_surfvpar_1x1v_ser_p1, vlasov_pkpm_boundary_surfvpar_1x1v_tensor_p2 }, // 0 - // 2x kernels - { NULL, vlasov_pkpm_boundary_surfvpar_2x1v_ser_p1, vlasov_pkpm_boundary_surfvpar_2x1v_tensor_p2 }, // 1 - // 3x kernels - { NULL, vlasov_pkpm_boundary_surfvpar_3x1v_ser_p1, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_vlasov_pkpm_accel_boundary_surf_kern_list + ten_accel_boundary_surf_vpar_kernels[] = { + // 1x kernels + {NULL, vlasov_pkpm_boundary_surfvpar_1x1v_ser_p1, vlasov_pkpm_boundary_surfvpar_1x1v_tensor_p2 + }, // 0 + // 2x kernels + {NULL, vlasov_pkpm_boundary_surfvpar_2x1v_ser_p1, vlasov_pkpm_boundary_surfvpar_2x1v_tensor_p2 + }, // 1 + // 3x kernels + {NULL, vlasov_pkpm_boundary_surfvpar_3x1v_ser_p1, NULL} // 2 }; /** @@ -297,14 +300,12 @@ static const gkyl_dg_vlasov_pkpm_accel_boundary_surf_kern_list ten_accel_boundar */ void gkyl_vlasov_pkpm_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_pkpm *vlasov_pkpm = container_of(eqn, struct dg_vlasov_pkpm, eqn); long cidx_c = gkyl_range_idx(&vlasov_pkpm->conf_range, idxC); @@ -312,41 +313,36 @@ surf(const struct gkyl_dg_eqn *eqn, if (dir < vlasov_pkpm->cdim) { long cidx_l = gkyl_range_idx(&vlasov_pkpm->conf_range, idxL); long cidx_r = gkyl_range_idx(&vlasov_pkpm->conf_range, idxR); - return vlasov_pkpm->stream_surf[dir] - (xcC, dxC, - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar_surf, cidx_l), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar_surf, cidx_c), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar_surf, cidx_r), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim_surf, cidx_l), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim_surf, cidx_c), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim_surf, cidx_r), - qInL, qInC, qInR, - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.max_b, cidx_c), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_lax, cidx_c), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_lax, cidx_r), - qRhsOut); - } - else { + return vlasov_pkpm->stream_surf[dir]( + xcC, dxC, (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar_surf, cidx_l), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar_surf, cidx_c), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.bvar_surf, cidx_r), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim_surf, cidx_l), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim_surf, cidx_c), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_prim_surf, cidx_r), qInL, qInC, + qInR, (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.max_b, cidx_c), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_lax, cidx_c), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_lax, cidx_r), qRhsOut + ); + } else { long pidx_l = gkyl_range_idx(&vlasov_pkpm->phase_range, idxL); long pidx_r = gkyl_range_idx(&vlasov_pkpm->phase_range, idxR); - return vlasov_pkpm->accel_surf(xcC, dxC, - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx_c), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx_c), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx_l), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx_c), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx_r), - qInL, qInC, qInR, qRhsOut); + return vlasov_pkpm->accel_surf( + xcC, dxC, (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx_c), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx_c), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx_l), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx_c), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidx_r), qInL, qInC, + qInR, qRhsOut + ); } } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_pkpm *vlasov_pkpm = container_of(eqn, struct dg_vlasov_pkpm, eqn); @@ -355,12 +351,13 @@ boundary_surf(const struct gkyl_dg_eqn *eqn, long cidx = gkyl_range_idx(&vlasov_pkpm->conf_range, idxSkin); long pidxSkin = gkyl_range_idx(&vlasov_pkpm->phase_range, idxSkin); long pidxEdge = gkyl_range_idx(&vlasov_pkpm->phase_range, idxEdge); - return vlasov_pkpm->accel_boundary_surf(xcSkin, dxSkin, - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidxEdge), - (const double*) gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidxSkin), - edge, qInEdge, qInSkin, qRhsOut); + return vlasov_pkpm->accel_boundary_surf( + xcSkin, dxSkin, (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.div_b, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.pkpm_accel_vars, cidx), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidxEdge), + (const double *)gkyl_array_cfetch(vlasov_pkpm->auxfields.g_dist_source, pidxSkin), edge, + qInEdge, qInSkin, qRhsOut + ); } return 0.; } diff --git a/pkpm/zero/gkyl_mom_bcorr_lbo_pkpm.h b/pkpm/zero/gkyl_mom_bcorr_lbo_pkpm.h index c43f4951c9..acafa47153 100644 --- a/pkpm/zero/gkyl_mom_bcorr_lbo_pkpm.h +++ b/pkpm/zero/gkyl_mom_bcorr_lbo_pkpm.h @@ -14,17 +14,17 @@ * @param mass Mass of species * @param use_gpu bool to determine if on GPU */ -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_pkpm_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const double* vBoundary, - double mass, bool use_gpu); +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_pkpm_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, const double *vBoundary, + double mass, bool use_gpu +); /** * Create new LBO Vlasov boundary correction moment type object * for the parallel-kinetic-perpendicular-moment (pkpm) model on NV-GPU: * see new() method above for documentation. */ -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const double* vBoundary, - double mass); +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, const double *vBoundary, + double mass +); diff --git a/pkpm/zero/gkyl_mom_bcorr_lbo_pkpm_priv.h b/pkpm/zero/gkyl_mom_bcorr_lbo_pkpm_priv.h index 70a3c51726..aa4f40db07 100644 --- a/pkpm/zero/gkyl_mom_bcorr_lbo_pkpm_priv.h +++ b/pkpm/zero/gkyl_mom_bcorr_lbo_pkpm_priv.h @@ -19,92 +19,100 @@ typedef struct { momf_t kernels[3]; } gkyl_mom_bcorr_lbo_pkpm_kern_list; -GKYL_CU_DH -static void -kernel_mom_bcorr_lbo_pkpm_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_bcorr_lbo_pkpm_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - struct mom_type_bcorr_lbo_pkpm *mom_pkpm = container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); + struct mom_type_bcorr_lbo_pkpm *mom_pkpm = + container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); enum gkyl_vel_edge edge = *(enum gkyl_vel_edge *)param; - return mom_bcorr_lbo_pkpm_1x1v_ser_p1(idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out); + return mom_bcorr_lbo_pkpm_1x1v_ser_p1(idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_bcorr_lbo_pkpm_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_bcorr_lbo_pkpm_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - struct mom_type_bcorr_lbo_pkpm *mom_pkpm = container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); + struct mom_type_bcorr_lbo_pkpm *mom_pkpm = + container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); enum gkyl_vel_edge edge = *(enum gkyl_vel_edge *)param; - return mom_bcorr_lbo_pkpm_1x1v_ser_p2(idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out); + return mom_bcorr_lbo_pkpm_1x1v_ser_p2(idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_bcorr_lbo_pkpm_1x1v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_bcorr_lbo_pkpm_1x1v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - struct mom_type_bcorr_lbo_pkpm *mom_pkpm = container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); + struct mom_type_bcorr_lbo_pkpm *mom_pkpm = + container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); enum gkyl_vel_edge edge = *(enum gkyl_vel_edge *)param; - return mom_bcorr_lbo_pkpm_1x1v_tensor_p2(idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out); + return mom_bcorr_lbo_pkpm_1x1v_tensor_p2( + idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out + ); } -GKYL_CU_DH -static void -kernel_mom_bcorr_lbo_pkpm_2x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_bcorr_lbo_pkpm_2x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - struct mom_type_bcorr_lbo_pkpm *mom_pkpm = container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); + struct mom_type_bcorr_lbo_pkpm *mom_pkpm = + container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); enum gkyl_vel_edge edge = *(enum gkyl_vel_edge *)param; - return mom_bcorr_lbo_pkpm_2x1v_ser_p1(idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out); + return mom_bcorr_lbo_pkpm_2x1v_ser_p1(idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_bcorr_lbo_pkpm_2x1v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_bcorr_lbo_pkpm_2x1v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - struct mom_type_bcorr_lbo_pkpm *mom_pkpm = container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); + struct mom_type_bcorr_lbo_pkpm *mom_pkpm = + container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); enum gkyl_vel_edge edge = *(enum gkyl_vel_edge *)param; - return mom_bcorr_lbo_pkpm_2x1v_tensor_p2(idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out); + return mom_bcorr_lbo_pkpm_2x1v_tensor_p2( + idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out + ); } -GKYL_CU_DH -static void -kernel_mom_bcorr_lbo_pkpm_3x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_bcorr_lbo_pkpm_3x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - struct mom_type_bcorr_lbo_pkpm *mom_pkpm = container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); + struct mom_type_bcorr_lbo_pkpm *mom_pkpm = + container_of(momt, struct mom_type_bcorr_lbo_pkpm, momt); enum gkyl_vel_edge edge = *(enum gkyl_vel_edge *)param; - return mom_bcorr_lbo_pkpm_3x1v_ser_p1(idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out); + return mom_bcorr_lbo_pkpm_3x1v_ser_p1(idx, edge, mom_pkpm->vBoundary, dx, mom_pkpm->mass, f, out); } // Moment boundary correction kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_mom_bcorr_lbo_pkpm_kern_list ser_mom_bcorr_lbo_pkpm_kernels[] = { +GKYL_CU_D static const gkyl_mom_bcorr_lbo_pkpm_kern_list ser_mom_bcorr_lbo_pkpm_kernels[] = { // 1x kernels - { NULL, kernel_mom_bcorr_lbo_pkpm_1x1v_ser_p1, kernel_mom_bcorr_lbo_pkpm_1x1v_ser_p2 }, // 0 + {NULL, kernel_mom_bcorr_lbo_pkpm_1x1v_ser_p1, kernel_mom_bcorr_lbo_pkpm_1x1v_ser_p2}, // 0 // 2x kernels - { NULL, kernel_mom_bcorr_lbo_pkpm_2x1v_ser_p1, NULL }, // 1 + {NULL, kernel_mom_bcorr_lbo_pkpm_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, kernel_mom_bcorr_lbo_pkpm_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_mom_bcorr_lbo_pkpm_3x1v_ser_p1, NULL} // 2 }; // Moment boundary correction kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_mom_bcorr_lbo_pkpm_kern_list ten_mom_bcorr_lbo_pkpm_kernels[] = { +GKYL_CU_D static const gkyl_mom_bcorr_lbo_pkpm_kern_list ten_mom_bcorr_lbo_pkpm_kernels[] = { // 1x kernels - { NULL, kernel_mom_bcorr_lbo_pkpm_1x1v_ser_p1, kernel_mom_bcorr_lbo_pkpm_1x1v_tensor_p2 }, // 0 + {NULL, kernel_mom_bcorr_lbo_pkpm_1x1v_ser_p1, kernel_mom_bcorr_lbo_pkpm_1x1v_tensor_p2}, // 0 // 2x kernels - { NULL, kernel_mom_bcorr_lbo_pkpm_2x1v_ser_p1, kernel_mom_bcorr_lbo_pkpm_2x1v_tensor_p2 }, // 1 + {NULL, kernel_mom_bcorr_lbo_pkpm_2x1v_ser_p1, kernel_mom_bcorr_lbo_pkpm_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, kernel_mom_bcorr_lbo_pkpm_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_mom_bcorr_lbo_pkpm_3x1v_ser_p1, NULL} // 2 }; /** diff --git a/pkpm/zero/gkyl_mom_pkpm.h b/pkpm/zero/gkyl_mom_pkpm.h index d94e22c2d2..a03504dcc6 100644 --- a/pkpm/zero/gkyl_mom_pkpm.h +++ b/pkpm/zero/gkyl_mom_pkpm.h @@ -16,12 +16,15 @@ * @param diag bool to determine if computing diagnostic moments * @param use_gpu bool to determine if on GPU */ -struct gkyl_mom_type* gkyl_mom_pkpm_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, double mass, bool diag, bool use_gpu); +struct gkyl_mom_type *gkyl_mom_pkpm_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, double mass, bool diag, + bool use_gpu +); /** * Create new Vlasov moment type object on NV-GPU: see new() method * above for documentation. */ -struct gkyl_mom_type* gkyl_mom_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, double mass, bool diag); +struct gkyl_mom_type *gkyl_mom_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, double mass, bool diag +); diff --git a/pkpm/zero/gkyl_mom_pkpm_priv.h b/pkpm/zero/gkyl_mom_pkpm_priv.h index 6c7289d44f..093a1931ac 100644 --- a/pkpm/zero/gkyl_mom_pkpm_priv.h +++ b/pkpm/zero/gkyl_mom_pkpm_priv.h @@ -19,168 +19,164 @@ typedef struct { momf_t kernels[3]; } gkyl_mom_pkpm_kern_list; -GKYL_CU_DH -static void -kernel_mom_pkpm_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_1x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_1x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_pkpm_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_1x1v_ser_p2(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_1x1v_ser_p2(xc, dx, idx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_pkpm_1x1v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_1x1v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_1x1v_tensor_p2(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_1x1v_tensor_p2(xc, dx, idx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_pkpm_2x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_2x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_2x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_2x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_pkpm_2x1v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_2x1v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_2x1v_tensor_p2(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_2x1v_tensor_p2(xc, dx, idx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_pkpm_3x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_3x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_3x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_3x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); } // PKPM coupling moment kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_mom_pkpm_kern_list ser_mom_pkpm_kernels[] = { +GKYL_CU_D static const gkyl_mom_pkpm_kern_list ser_mom_pkpm_kernels[] = { // 1x kernels - { NULL, kernel_mom_pkpm_1x1v_ser_p1, kernel_mom_pkpm_1x1v_ser_p2 }, // 0 + {NULL, kernel_mom_pkpm_1x1v_ser_p1, kernel_mom_pkpm_1x1v_ser_p2}, // 0 // 2x kernels - { NULL, kernel_mom_pkpm_2x1v_ser_p1, NULL }, // 1 + {NULL, kernel_mom_pkpm_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, kernel_mom_pkpm_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_mom_pkpm_3x1v_ser_p1, NULL} // 2 }; // PKPM coupling moment kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_mom_pkpm_kern_list ten_mom_pkpm_kernels[] = { +GKYL_CU_D static const gkyl_mom_pkpm_kern_list ten_mom_pkpm_kernels[] = { // 1x kernels - { NULL, kernel_mom_pkpm_1x1v_ser_p1, kernel_mom_pkpm_1x1v_tensor_p2 }, // 0 + {NULL, kernel_mom_pkpm_1x1v_ser_p1, kernel_mom_pkpm_1x1v_tensor_p2}, // 0 // 2x kernels - { NULL, kernel_mom_pkpm_2x1v_ser_p1, kernel_mom_pkpm_2x1v_tensor_p2 }, // 1 + {NULL, kernel_mom_pkpm_2x1v_ser_p1, kernel_mom_pkpm_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, kernel_mom_pkpm_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_mom_pkpm_3x1v_ser_p1, NULL} // 2 }; -GKYL_CU_DH -static void -kernel_mom_pkpm_diag_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_diag_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_diag_1x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_diag_1x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_pkpm_diag_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_diag_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_diag_1x1v_ser_p2(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_diag_1x1v_ser_p2(xc, dx, idx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_pkpm_diag_1x1v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_diag_1x1v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_diag_1x1v_tensor_p2(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_diag_1x1v_tensor_p2(xc, dx, idx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_pkpm_diag_2x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_diag_2x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_diag_2x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_diag_2x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_pkpm_diag_2x1v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_diag_2x1v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_diag_2x1v_tensor_p2(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_diag_2x1v_tensor_p2(xc, dx, idx, mom_pkpm->mass, f, out); } -GKYL_CU_DH -static void -kernel_mom_pkpm_diag_3x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_mom_pkpm_diag_3x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_pkpm *mom_pkpm = container_of(momt, struct mom_type_pkpm, momt); - return mom_pkpm_diag_3x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); + return mom_pkpm_diag_3x1v_ser_p1(xc, dx, idx, mom_pkpm->mass, f, out); } // PKPM diagnostic kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_mom_pkpm_kern_list ser_mom_pkpm_diag_kernels[] = { +GKYL_CU_D static const gkyl_mom_pkpm_kern_list ser_mom_pkpm_diag_kernels[] = { // 1x kernels - { NULL, kernel_mom_pkpm_diag_1x1v_ser_p1, kernel_mom_pkpm_diag_1x1v_ser_p2 }, // 0 + {NULL, kernel_mom_pkpm_diag_1x1v_ser_p1, kernel_mom_pkpm_diag_1x1v_ser_p2}, // 0 // 2x kernels - { NULL, kernel_mom_pkpm_diag_2x1v_ser_p1, NULL }, // 1 + {NULL, kernel_mom_pkpm_diag_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, kernel_mom_pkpm_diag_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_mom_pkpm_diag_3x1v_ser_p1, NULL} // 2 }; // PKPM diagnostic kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_mom_pkpm_kern_list ten_mom_pkpm_diag_kernels[] = { +GKYL_CU_D static const gkyl_mom_pkpm_kern_list ten_mom_pkpm_diag_kernels[] = { // 1x kernels - { NULL, kernel_mom_pkpm_diag_1x1v_ser_p1, kernel_mom_pkpm_diag_1x1v_tensor_p2 }, // 0 + {NULL, kernel_mom_pkpm_diag_1x1v_ser_p1, kernel_mom_pkpm_diag_1x1v_tensor_p2}, // 0 // 2x kernels - { NULL, kernel_mom_pkpm_diag_2x1v_ser_p1, kernel_mom_pkpm_diag_2x1v_tensor_p2 }, // 1 + {NULL, kernel_mom_pkpm_diag_2x1v_ser_p1, kernel_mom_pkpm_diag_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, kernel_mom_pkpm_diag_3x1v_ser_p1, NULL }, // 2 + {NULL, kernel_mom_pkpm_diag_3x1v_ser_p1, NULL} // 2 }; /** diff --git a/pkpm/zero/gkyl_prim_lbo_pkpm.h b/pkpm/zero/gkyl_prim_lbo_pkpm.h index fc1aa85d21..db4f1f7206 100644 --- a/pkpm/zero/gkyl_prim_lbo_pkpm.h +++ b/pkpm/zero/gkyl_prim_lbo_pkpm.h @@ -13,15 +13,16 @@ * @param use_gpu bool to determine if on GPU * @return Pointer to Vlasov (with fluid coupling) primitive moment object */ -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_pkpm_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - bool use_gpu); +struct gkyl_prim_lbo_type *gkyl_prim_lbo_pkpm_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, bool use_gpu +); /** * Create a new Vlasov PKPM primitive moment object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range); +struct gkyl_prim_lbo_type *gkyl_prim_lbo_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range +); diff --git a/pkpm/zero/gkyl_prim_lbo_pkpm_priv.h b/pkpm/zero/gkyl_prim_lbo_pkpm_priv.h index 952f4c58dc..bec789d59e 100644 --- a/pkpm/zero/gkyl_prim_lbo_pkpm_priv.h +++ b/pkpm/zero/gkyl_prim_lbo_pkpm_priv.h @@ -8,32 +8,34 @@ #include #include -typedef void (*pkpm_self_prim_t)(struct gkyl_mat *A, struct gkyl_mat *rhs, - const double *moms, const double *boundary_corrections, const double *nu); +typedef void (*pkpm_self_prim_t)( + struct gkyl_mat *A, struct gkyl_mat *rhs, const double *moms, const double *boundary_corrections, + const double *nu +); // for use in kernel tables -typedef struct { pkpm_self_prim_t kernels[3]; } gkyl_prim_lbo_pkpm_self_kern_list; +typedef struct { + pkpm_self_prim_t kernels[3]; +} gkyl_prim_lbo_pkpm_self_kern_list; // PKPM self-primitive moment kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_prim_lbo_pkpm_self_kern_list ser_self_prim_kernels[] = { +GKYL_CU_D static const gkyl_prim_lbo_pkpm_self_kern_list ser_self_prim_kernels[] = { // 1x kernels - { NULL, pkpm_self_prim_moments_1x1v_ser_p1, pkpm_self_prim_moments_1x1v_ser_p2 }, // 0 + {NULL, pkpm_self_prim_moments_1x1v_ser_p1, pkpm_self_prim_moments_1x1v_ser_p2}, // 0 // 2x kernels - { NULL, pkpm_self_prim_moments_2x1v_ser_p1, NULL }, // 1 + {NULL, pkpm_self_prim_moments_2x1v_ser_p1, NULL}, // 1 // 3x kernels - { NULL, pkpm_self_prim_moments_3x1v_ser_p1, NULL }, // 2 + {NULL, pkpm_self_prim_moments_3x1v_ser_p1, NULL} // 2 }; // PKPM self-primitive moment kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_prim_lbo_pkpm_self_kern_list ten_self_prim_kernels[] = { +GKYL_CU_D static const gkyl_prim_lbo_pkpm_self_kern_list ten_self_prim_kernels[] = { // 1x kernels - { NULL, pkpm_self_prim_moments_1x1v_ser_p1, pkpm_self_prim_moments_1x1v_tensor_p2 }, // 0 + {NULL, pkpm_self_prim_moments_1x1v_ser_p1, pkpm_self_prim_moments_1x1v_tensor_p2}, // 0 // 2x kernels - { NULL, pkpm_self_prim_moments_2x1v_ser_p1, pkpm_self_prim_moments_2x1v_tensor_p2 }, // 1 + {NULL, pkpm_self_prim_moments_2x1v_ser_p1, pkpm_self_prim_moments_2x1v_tensor_p2}, // 1 // 3x kernels - { NULL, pkpm_self_prim_moments_3x1v_ser_p1, NULL }, // 2 + {NULL, pkpm_self_prim_moments_3x1v_ser_p1, NULL} // 2 }; struct prim_lbo_type_pkpm { @@ -49,10 +51,10 @@ struct prim_lbo_type_pkpm { */ void prim_lbo_pkpm_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static void -self_prim(const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, - const int* idx, const double *moms, const double *boundary_corrections, const double *nu) +GKYL_CU_D static void self_prim( + const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, const int *idx, + const double *moms, const double *boundary_corrections, const double *nu +) { struct prim_lbo_type_pkpm *prim_pkpm = container_of(prim, struct prim_lbo_type_pkpm, prim); diff --git a/pkpm/zero/mom_bcorr_lbo_pkpm.c b/pkpm/zero/mom_bcorr_lbo_pkpm.c index 3264e17246..a426f256e9 100644 --- a/pkpm/zero/mom_bcorr_lbo_pkpm.c +++ b/pkpm/zero/mom_bcorr_lbo_pkpm.c @@ -9,31 +9,31 @@ #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_mom_bcorr_lbo_pkpm_free(const struct gkyl_ref_count *ref) +void gkyl_mom_bcorr_lbo_pkpm_free(const struct gkyl_ref_count *ref) { struct gkyl_mom_type *momt = container_of(ref, struct gkyl_mom_type, ref_count); - if (GKYL_IS_CU_ALLOC(momt->flags)) + if (GKYL_IS_CU_ALLOC(momt->flags)) { gkyl_cu_free(momt->on_dev); + } gkyl_free(momt); } - -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_pkpm_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const double* vBoundary, double mass, bool use_gpu) +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_pkpm_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, const double *vBoundary, + double mass, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_mom_bcorr_lbo_pkpm_cu_dev_new(cbasis, pbasis, vBoundary, mass); - } -#endif + } +#endif struct mom_type_bcorr_lbo_pkpm *mom_bcorr = gkyl_malloc(sizeof(struct mom_type_bcorr_lbo_pkpm)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_bcorr->momt.cdim = cdim; @@ -50,19 +50,19 @@ gkyl_mom_bcorr_lbo_pkpm_new(const struct gkyl_basis* cbasis, const struct gkyl_b const gkyl_mom_bcorr_lbo_pkpm_kern_list *mom_bcorr_lbo_pkpm_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - mom_bcorr_lbo_pkpm_kernels = ser_mom_bcorr_lbo_pkpm_kernels; + case GKYL_BASIS_MODAL_SERENDIPITY: + mom_bcorr_lbo_pkpm_kernels = ser_mom_bcorr_lbo_pkpm_kernels; + + break; - break; + case GKYL_BASIS_MODAL_TENSOR: + mom_bcorr_lbo_pkpm_kernels = ten_mom_bcorr_lbo_pkpm_kernels; - case GKYL_BASIS_MODAL_TENSOR: - mom_bcorr_lbo_pkpm_kernels = ten_mom_bcorr_lbo_pkpm_kernels; - - break; + break; - default: - assert(false); - break; + default: + assert(false); + break; } mom_bcorr->momt.kernel = CK(mom_bcorr_lbo_pkpm_kernels, cdim, poly_order); @@ -73,15 +73,16 @@ gkyl_mom_bcorr_lbo_pkpm_new(const struct gkyl_basis* cbasis, const struct gkyl_b mom_bcorr->momt.ref_count = gkyl_ref_count_init(gkyl_mom_bcorr_lbo_pkpm_free); mom_bcorr->momt.on_dev = &mom_bcorr->momt; - + return &mom_bcorr->momt; } #ifndef GKYL_HAVE_CUDA -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const double* vBoundary, double mass) +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, const double *vBoundary, + double mass +) { assert(false); } diff --git a/pkpm/zero/mom_bcorr_lbo_pkpm_cu.cu b/pkpm/zero/mom_bcorr_lbo_pkpm_cu.cu index 00cbc9e44f..40d2bbcc04 100644 --- a/pkpm/zero/mom_bcorr_lbo_pkpm_cu.cu +++ b/pkpm/zero/mom_bcorr_lbo_pkpm_cu.cu @@ -10,41 +10,42 @@ extern "C" { #include } -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -__global__ -static void -gkyl_mom_bcorr_lbo_pkpm_set_cu_dev_ptrs(struct mom_type_bcorr_lbo_pkpm* mom_bcorr, - enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ static void gkyl_mom_bcorr_lbo_pkpm_set_cu_dev_ptrs( + struct mom_type_bcorr_lbo_pkpm *mom_bcorr, enum gkyl_basis_type b_type, int cdim, int poly_order +) { // choose kernel tables based on basis-function type const gkyl_mom_bcorr_lbo_pkpm_kern_list *mom_bcorr_lbo_pkpm_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - mom_bcorr_lbo_pkpm_kernels = ser_mom_bcorr_lbo_pkpm_kernels; + case GKYL_BASIS_MODAL_SERENDIPITY: + mom_bcorr_lbo_pkpm_kernels = ser_mom_bcorr_lbo_pkpm_kernels; - break; + break; - case GKYL_BASIS_MODAL_TENSOR: - mom_bcorr_lbo_pkpm_kernels = ten_mom_bcorr_lbo_pkpm_kernels; - - break; + case GKYL_BASIS_MODAL_TENSOR: + mom_bcorr_lbo_pkpm_kernels = ten_mom_bcorr_lbo_pkpm_kernels; - default: - assert(false); - break; + break; + + default: + assert(false); + break; } mom_bcorr->momt.kernel = CK(mom_bcorr_lbo_pkpm_kernels, cdim, poly_order); } -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const double *vBoundary, double mass) +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, const double *vBoundary, + double mass +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_bcorr_lbo_pkpm *mom_bcorr = (struct mom_type_bcorr_lbo_pkpm*) gkyl_malloc(sizeof(struct mom_type_bcorr_lbo_pkpm)); + struct mom_type_bcorr_lbo_pkpm *mom_bcorr = + (struct mom_type_bcorr_lbo_pkpm *)gkyl_malloc(sizeof(struct mom_type_bcorr_lbo_pkpm)); int cdim = cbasis->ndim, pdim = pbasis->ndim; int poly_order = cbasis->poly_order; @@ -65,12 +66,15 @@ gkyl_mom_bcorr_lbo_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, const struct mom_bcorr->momt.ref_count = gkyl_ref_count_init(gkyl_mom_bcorr_lbo_pkpm_free); // copy struct to device - struct mom_type_bcorr_lbo_pkpm *mom_bcorr_cu = (struct mom_type_bcorr_lbo_pkpm*) - gkyl_cu_malloc(sizeof(struct mom_type_bcorr_lbo_pkpm)); - gkyl_cu_memcpy(mom_bcorr_cu, mom_bcorr, sizeof(struct mom_type_bcorr_lbo_pkpm), GKYL_CU_MEMCPY_H2D); - - - gkyl_mom_bcorr_lbo_pkpm_set_cu_dev_ptrs<<<1,1>>>(mom_bcorr_cu, cbasis->b_type, cdim, poly_order); + struct mom_type_bcorr_lbo_pkpm *mom_bcorr_cu = + (struct mom_type_bcorr_lbo_pkpm *)gkyl_cu_malloc(sizeof(struct mom_type_bcorr_lbo_pkpm)); + gkyl_cu_memcpy( + mom_bcorr_cu, mom_bcorr, sizeof(struct mom_type_bcorr_lbo_pkpm), GKYL_CU_MEMCPY_H2D + ); + + gkyl_mom_bcorr_lbo_pkpm_set_cu_dev_ptrs<<<1, 1> > >( + mom_bcorr_cu, cbasis->b_type, cdim, poly_order + ); mom_bcorr->momt.on_dev = &mom_bcorr_cu->momt; diff --git a/pkpm/zero/mom_calc_bcorr_pkpm.c b/pkpm/zero/mom_calc_bcorr_pkpm.c index 270342fd67..e34845047c 100644 --- a/pkpm/zero/mom_calc_bcorr_pkpm.c +++ b/pkpm/zero/mom_calc_bcorr_pkpm.c @@ -12,14 +12,14 @@ #include // "derived" class constructors -struct gkyl_mom_calc_bcorr* -gkyl_mom_calc_bcorr_lbo_pkpm_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const double* vBoundary, double mass, bool use_gpu) +struct gkyl_mom_calc_bcorr *gkyl_mom_calc_bcorr_lbo_pkpm_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const double *vBoundary, double mass, bool use_gpu +) { struct gkyl_mom_type *bcorr_type; // LBO boundary corrections moment type - bcorr_type = gkyl_mom_bcorr_lbo_pkpm_new(cbasis, pbasis, vBoundary, mass, use_gpu); - struct gkyl_mom_calc_bcorr* calc = gkyl_mom_calc_bcorr_new(grid, bcorr_type, use_gpu); + bcorr_type = gkyl_mom_bcorr_lbo_pkpm_new(cbasis, pbasis, vBoundary, mass, use_gpu); + struct gkyl_mom_calc_bcorr *calc = gkyl_mom_calc_bcorr_new(grid, bcorr_type, use_gpu); // Since calc now has pointer to specific type, decrease reference counter of type // so that eventual gkyl_mom_calc_bcorr_release method on calculator deallocates specific type data gkyl_mom_type_release(bcorr_type); diff --git a/pkpm/zero/mom_pkpm.c b/pkpm/zero/mom_pkpm.c index b9f8fea93c..88db8e74ba 100644 --- a/pkpm/zero/mom_pkpm.c +++ b/pkpm/zero/mom_pkpm.c @@ -9,30 +9,31 @@ #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_mom_pkpm_free(const struct gkyl_ref_count *ref) +void gkyl_mom_pkpm_free(const struct gkyl_ref_count *ref) { struct gkyl_mom_type *momt = container_of(ref, struct gkyl_mom_type, ref_count); - if (GKYL_IS_CU_ALLOC(momt->flags)) + if (GKYL_IS_CU_ALLOC(momt->flags)) { gkyl_cu_free(momt->on_dev); + } gkyl_free(momt); } -struct gkyl_mom_type* -gkyl_mom_pkpm_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - double mass, bool diag, bool use_gpu) +struct gkyl_mom_type *gkyl_mom_pkpm_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, double mass, bool diag, + bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_mom_pkpm_cu_dev_new(cbasis, pbasis, mass, diag); - } -#endif + } +#endif struct mom_type_pkpm *mom_pkpm = gkyl_malloc(sizeof(struct mom_type_pkpm)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_pkpm->momt.cdim = cdim; @@ -45,48 +46,47 @@ gkyl_mom_pkpm_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbas const gkyl_mom_pkpm_kern_list *mom_pkpm_kernels, *mom_pkpm_diag_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - mom_pkpm_kernels = ser_mom_pkpm_kernels; - mom_pkpm_diag_kernels = ser_mom_pkpm_diag_kernels; + case GKYL_BASIS_MODAL_SERENDIPITY: + mom_pkpm_kernels = ser_mom_pkpm_kernels; + mom_pkpm_diag_kernels = ser_mom_pkpm_diag_kernels; + + break; - break; + case GKYL_BASIS_MODAL_TENSOR: + mom_pkpm_kernels = ten_mom_pkpm_kernels; + mom_pkpm_diag_kernels = ten_mom_pkpm_diag_kernels; - case GKYL_BASIS_MODAL_TENSOR: - mom_pkpm_kernels = ten_mom_pkpm_kernels; - mom_pkpm_diag_kernels = ten_mom_pkpm_diag_kernels; - - break; + break; - default: - assert(false); - break; + default: + assert(false); + break; } if (diag) { mom_pkpm->momt.kernel = CK(mom_pkpm_diag_kernels, cdim, poly_order); mom_pkpm->momt.num_mom = 8; // rho, M1, p_par, p_perp, q_par, q_perp, r_parpar, r_parperp - } - else { + } else { mom_pkpm->momt.kernel = CK(mom_pkpm_kernels, cdim, poly_order); mom_pkpm->momt.num_mom = 4; // rho, p_par, p_perp, M1 } mom_pkpm->mass = mass; - + mom_pkpm->momt.flags = 0; GKYL_CLEAR_CU_ALLOC(mom_pkpm->momt.flags); mom_pkpm->momt.ref_count = gkyl_ref_count_init(gkyl_mom_pkpm_free); - + mom_pkpm->momt.on_dev = &mom_pkpm->momt; // on host, self-reference - + return &mom_pkpm->momt; } #ifndef GKYL_HAVE_CUDA -struct gkyl_mom_type* -gkyl_mom_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - double mass, bool diag) +struct gkyl_mom_type *gkyl_mom_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, double mass, bool diag +) { assert(false); return 0; diff --git a/pkpm/zero/mom_pkpm_cu.cu b/pkpm/zero/mom_pkpm_cu.cu index 07e92a8288..4370633dcf 100644 --- a/pkpm/zero/mom_pkpm_cu.cu +++ b/pkpm/zero/mom_pkpm_cu.cu @@ -12,53 +12,51 @@ extern "C" { #include } -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -__global__ -static void -set_cu_ptrs(struct mom_type_pkpm *mom_pkpm, - enum gkyl_basis_type b_type, int cdim, int poly_order, bool diag) +__global__ static void set_cu_ptrs( + struct mom_type_pkpm *mom_pkpm, enum gkyl_basis_type b_type, int cdim, int poly_order, bool diag +) { // choose kernel tables based on basis-function type const gkyl_mom_pkpm_kern_list *mom_pkpm_kernels, *mom_pkpm_diag_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - mom_pkpm_kernels = ser_mom_pkpm_kernels; - mom_pkpm_diag_kernels = ser_mom_pkpm_diag_kernels; + case GKYL_BASIS_MODAL_SERENDIPITY: + mom_pkpm_kernels = ser_mom_pkpm_kernels; + mom_pkpm_diag_kernels = ser_mom_pkpm_diag_kernels; - break; + break; - case GKYL_BASIS_MODAL_TENSOR: - mom_pkpm_kernels = ten_mom_pkpm_kernels; - mom_pkpm_diag_kernels = ten_mom_pkpm_diag_kernels; - - break; + case GKYL_BASIS_MODAL_TENSOR: + mom_pkpm_kernels = ten_mom_pkpm_kernels; + mom_pkpm_diag_kernels = ten_mom_pkpm_diag_kernels; - default: - assert(false); - break; + break; + + default: + assert(false); + break; } if (diag) { mom_pkpm->momt.kernel = CK(mom_pkpm_diag_kernels, cdim, poly_order); mom_pkpm->momt.num_mom = 8; // rho, M1, p_par, p_perp, q_par, q_perp, r_parpar, r_parperp - } - else { + } else { mom_pkpm->momt.kernel = CK(mom_pkpm_kernels, cdim, poly_order); mom_pkpm->momt.num_mom = 3; // rho, p_par, p_perp } } -struct gkyl_mom_type* -gkyl_mom_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - double mass, bool diag) +struct gkyl_mom_type *gkyl_mom_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, double mass, bool diag +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_pkpm *mom_pkpm = (struct mom_type_pkpm*) - gkyl_malloc(sizeof(struct mom_type_pkpm)); - + struct mom_type_pkpm *mom_pkpm = + (struct mom_type_pkpm *)gkyl_malloc(sizeof(struct mom_type_pkpm)); + int cdim = cbasis->ndim, pdim = pbasis->ndim; int poly_order = cbasis->poly_order; @@ -68,24 +66,25 @@ gkyl_mom_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basi mom_pkpm->momt.num_config = cbasis->num_basis; mom_pkpm->momt.num_phase = pbasis->num_basis; - if (diag) + if (diag) { mom_pkpm->momt.num_mom = 8; // rho, M1, p_par, p_perp, q_par, q_perp, r_parpar, r_parperp - else + } else { mom_pkpm->momt.num_mom = 4; // rho, p_par, p_perp, M1 + } mom_pkpm->mass = mass; mom_pkpm->momt.flags = 0; GKYL_SET_CU_ALLOC(mom_pkpm->momt.flags); mom_pkpm->momt.ref_count = gkyl_ref_count_init(gkyl_mom_pkpm_free); - + // copy struct to device - struct mom_type_pkpm *mom_pkpm_cu = (struct mom_type_pkpm*) - gkyl_cu_malloc(sizeof(struct mom_type_pkpm)); + struct mom_type_pkpm *mom_pkpm_cu = + (struct mom_type_pkpm *)gkyl_cu_malloc(sizeof(struct mom_type_pkpm)); gkyl_cu_memcpy(mom_pkpm_cu, mom_pkpm, sizeof(struct mom_type_pkpm), GKYL_CU_MEMCPY_H2D); - set_cu_ptrs<<<1,1>>>(mom_pkpm_cu, cbasis->b_type, cdim, poly_order, diag); + set_cu_ptrs<<<1, 1> > >(mom_pkpm_cu, cbasis->b_type, cdim, poly_order, diag); mom_pkpm->momt.on_dev = &mom_pkpm_cu->momt; - + return &mom_pkpm->momt; } diff --git a/pkpm/zero/prim_lbo_calc_pkpm.c b/pkpm/zero/prim_lbo_calc_pkpm.c index ae7b2e52ea..16708dbff2 100644 --- a/pkpm/zero/prim_lbo_calc_pkpm.c +++ b/pkpm/zero/prim_lbo_calc_pkpm.c @@ -9,10 +9,10 @@ #include // "derived" class constructors -struct gkyl_prim_lbo_calc* -gkyl_prim_lbo_pkpm_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_rng, bool use_gpu) +struct gkyl_prim_lbo_calc *gkyl_prim_lbo_pkpm_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_rng, bool use_gpu +) { struct gkyl_prim_lbo_type *prim; // LBO primitive moments type prim = gkyl_prim_lbo_pkpm_new(cbasis, pbasis, conf_rng, use_gpu); diff --git a/pkpm/zero/prim_lbo_pkpm.c b/pkpm/zero/prim_lbo_pkpm.c index e0f48a94e4..b56fdefda3 100644 --- a/pkpm/zero/prim_lbo_pkpm.c +++ b/pkpm/zero/prim_lbo_pkpm.c @@ -9,28 +9,29 @@ #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -prim_lbo_pkpm_free(const struct gkyl_ref_count *ref) +void prim_lbo_pkpm_free(const struct gkyl_ref_count *ref) { struct gkyl_prim_lbo_type *prim = container_of(ref, struct gkyl_prim_lbo_type, ref_count); - if (GKYL_IS_CU_ALLOC(prim->flag)) + if (GKYL_IS_CU_ALLOC(prim->flag)) { gkyl_cu_free(prim->on_dev); + } gkyl_free(prim); } -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_pkpm_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, bool use_gpu) +struct gkyl_prim_lbo_type *gkyl_prim_lbo_pkpm_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_prim_lbo_pkpm_cu_dev_new(cbasis, pbasis, conf_range); - } -#endif + } +#endif struct prim_lbo_type_pkpm *prim_pkpm = gkyl_malloc(sizeof(struct prim_lbo_type_pkpm)); int cdim = prim_pkpm->prim.cdim = cbasis->ndim; int pdim = prim_pkpm->prim.pdim = pbasis->ndim; @@ -47,39 +48,40 @@ gkyl_prim_lbo_pkpm_new(const struct gkyl_basis* cbasis, const gkyl_prim_lbo_pkpm_self_kern_list *self_prim_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - self_prim_kernels = ser_self_prim_kernels; + case GKYL_BASIS_MODAL_SERENDIPITY: + self_prim_kernels = ser_self_prim_kernels; + + break; - break; + case GKYL_BASIS_MODAL_TENSOR: + self_prim_kernels = ten_self_prim_kernels; - case GKYL_BASIS_MODAL_TENSOR: - self_prim_kernels = ten_self_prim_kernels; - - break; + break; - default: - assert(false); - break; + default: + assert(false); + break; } - + prim_pkpm->self_prim = CK(self_prim_kernels, cdim, poly_order); prim_pkpm->conf_range = *conf_range; - + prim_pkpm->prim.flag = 0; GKYL_CLEAR_CU_ALLOC(prim_pkpm->prim.flag); prim_pkpm->prim.ref_count = gkyl_ref_count_init(prim_lbo_pkpm_free); prim_pkpm->prim.on_dev = &prim_pkpm->prim; - + return &prim_pkpm->prim; } #ifndef GKYL_HAVE_CUDA -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range) +struct gkyl_prim_lbo_type *gkyl_prim_lbo_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range +) { assert(false); return 0; diff --git a/pkpm/zero/prim_lbo_pkpm_cu.cu b/pkpm/zero/prim_lbo_pkpm_cu.cu index ec7a713c19..6531b2b162 100644 --- a/pkpm/zero/prim_lbo_pkpm_cu.cu +++ b/pkpm/zero/prim_lbo_pkpm_cu.cu @@ -10,45 +10,46 @@ extern "C" { #include } -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -__global__ static void -gkyl_prim_lbo_pkpm_set_cu_dev_ptrs(struct prim_lbo_type_pkpm *prim_pkpm, - enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ static void gkyl_prim_lbo_pkpm_set_cu_dev_ptrs( + struct prim_lbo_type_pkpm *prim_pkpm, enum gkyl_basis_type b_type, int cdim, int poly_order +) { prim_pkpm->prim.self_prim = self_prim; - + // choose kernel tables based on basis-function type const gkyl_prim_lbo_pkpm_self_kern_list *self_prim_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - self_prim_kernels = ser_self_prim_kernels; + case GKYL_BASIS_MODAL_SERENDIPITY: + self_prim_kernels = ser_self_prim_kernels; + + break; - break; + case GKYL_BASIS_MODAL_TENSOR: + self_prim_kernels = ten_self_prim_kernels; - case GKYL_BASIS_MODAL_TENSOR: - self_prim_kernels = ten_self_prim_kernels; - - break; + break; - default: - assert(false); - break; + default: + assert(false); + break; } prim_pkpm->self_prim = CK(self_prim_kernels, cdim, poly_order); } -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range) +struct gkyl_prim_lbo_type *gkyl_prim_lbo_pkpm_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range +) { assert(cbasis->poly_order == pbasis->poly_order); - + struct prim_lbo_type_pkpm *prim_pkpm = - (struct prim_lbo_type_pkpm*) gkyl_malloc(sizeof(struct prim_lbo_type_pkpm)); - + (struct prim_lbo_type_pkpm *)gkyl_malloc(sizeof(struct prim_lbo_type_pkpm)); + int cdim = prim_pkpm->prim.cdim = cbasis->ndim; int pdim = prim_pkpm->prim.pdim = pbasis->ndim; @@ -62,15 +63,15 @@ gkyl_prim_lbo_pkpm_cu_dev_new(const struct gkyl_basis* cbasis, prim_pkpm->prim.flag = 0; GKYL_SET_CU_ALLOC(prim_pkpm->prim.flag); prim_pkpm->prim.ref_count = gkyl_ref_count_init(prim_lbo_pkpm_free); - + // copy the host struct to device struct - struct prim_lbo_type_pkpm *prim_pkpm_cu = (struct prim_lbo_type_pkpm*) - gkyl_cu_malloc(sizeof(struct prim_lbo_type_pkpm)); + struct prim_lbo_type_pkpm *prim_pkpm_cu = + (struct prim_lbo_type_pkpm *)gkyl_cu_malloc(sizeof(struct prim_lbo_type_pkpm)); gkyl_cu_memcpy(prim_pkpm_cu, prim_pkpm, sizeof(struct prim_lbo_type_pkpm), GKYL_CU_MEMCPY_H2D); - - gkyl_prim_lbo_pkpm_set_cu_dev_ptrs<<<1,1>>>(prim_pkpm_cu, cbasis->b_type, cdim, poly_order); + + gkyl_prim_lbo_pkpm_set_cu_dev_ptrs<<<1, 1> > >(prim_pkpm_cu, cbasis->b_type, cdim, poly_order); prim_pkpm->prim.on_dev = &prim_pkpm_cu->prim; - + return &prim_pkpm->prim; } diff --git a/vlasov/apps/gkyl_vlasov.h b/vlasov/apps/gkyl_vlasov.h index edccb8f9cf..eccfab079a 100644 --- a/vlasov/apps/gkyl_vlasov.h +++ b/vlasov/apps/gkyl_vlasov.h @@ -16,12 +16,12 @@ struct gkyl_vlasov_projection { enum gkyl_projection_id proj_id; // type of projection (see gkyl_eqn_type.h) enum gkyl_quad_type quad_type; // quadrature scheme to use: defaults to Gaussian - + union { struct { - // pointer and context to initialization function - void *ctx_func; - void (*func)(double t, const double *xn, double *fout, void *ctx); + // pointer and context to initialization function + void *ctx_func; + void (*func)(double t, const double *xn, double *fout, void *ctx); }; struct { // pointers and contexts to initialization functions for LTE distribution projection @@ -34,7 +34,7 @@ struct gkyl_vlasov_projection { void (*temp)(double t, const double *xn, double *fout, void *ctx); // boolean if we are correcting all the moments or only density - bool correct_all_moms; + bool correct_all_moms; double iter_eps; // error tolerance for moment fixes (density is always exact) int max_iter; // maximum number of iteration bool use_last_converged; // use last iteration value regardless of convergence? @@ -53,7 +53,7 @@ struct gkyl_vlasov_collisions { // inputs for Spitzer collisionality bool normNu; // Set to true if you want to rescale collision frequency double nuFrac; // Parameter for rescaling collision frequency from SI values - double hbar; // Planck's constant/2 pi + double hbar; // Planck's constant/2 pi // BGK collisions specific inputs bool correct_all_moms; // boolean if we are correcting all the moments or only density @@ -62,8 +62,8 @@ struct gkyl_vlasov_collisions { bool fixed_temp_relax; // Are BGK collisions relaxing to a fixed input temperature? bool use_last_converged; // use last iteration value regardless of convergence? - // Boolean for using implicit BGK collisions (replaces rk3) - bool has_implicit_coll_scheme; + // Boolean for using implicit BGK collisions (replaces rk3) + bool has_implicit_coll_scheme; int num_cross_collisions; // number of species to cross-collide with char collide_with[GKYL_MAX_SPECIES][128]; // names of species to cross collide with @@ -81,7 +81,7 @@ struct gkyl_vlasov_radiation { void *ctx_nu_rad_drag; // context for collision frequency * drag // function for computing collision frequency * drag - void (*nu_rad_drag)(double t, const double *xn, double *fout, void *ctx); + void (*nu_rad_drag)(double t, const double *xn, double *fout, void *ctx); }; // Parameters for species source @@ -92,7 +92,7 @@ struct gkyl_vlasov_source { double source_length; // required for boundary flux source char source_species[128]; - + // sources using projection routine struct gkyl_vlasov_projection projection[GKYL_MAX_PROJ]; }; @@ -101,7 +101,7 @@ struct gkyl_vlasov_source { struct gkyl_vlasov_bc { enum gkyl_species_bc_type type; void *aux_ctx; - void (*aux_profile)(double t, const double *xn, double *fout, void *ctx); + void (*aux_profile)(double t, const double *xn, double *fout, void *ctx); double aux_parameter; }; @@ -129,17 +129,17 @@ struct gkyl_vlasov_fluid_advection { struct gkyl_vlasov_fluid_diffusion { double D; // constant diffusion coefficient int order; // integer for order of the diffusion (4 for grad^4, 6 for grad^6, default is grad^2) - void* Dij_ctx; // context for applied diffusion function if using general diffusion tensor - // pointer to applied diffusion function is using general diffusion tensor - void (*Dij)(double t, const double* xn, double* Dout, void* ctx); + void *Dij_ctx; // context for applied diffusion function if using general diffusion tensor + // pointer to applied diffusion function is using general diffusion tensor + void (*Dij)(double t, const double *xn, double *Dout, void *ctx); }; // Parameters for Vlasov species struct gkyl_vlasov_species { char name[128]; // species name - enum gkyl_model_id model_id; // type of model - // (e.g., SR, general geometry, see gkyl_eqn_type.h) + enum gkyl_model_id model_id; // type of model + // (e.g., SR, general geometry, see gkyl_eqn_type.h) double charge, mass; // charge and mass double lower[3], upper[3]; // lower, upper bounds of velocity-space @@ -193,8 +193,8 @@ struct gkyl_vlasov_species { // Parameter for EM field struct gkyl_vlasov_field { - enum gkyl_field_id field_id; // type of field - // (e.g., Maxwell's, Poisson, see gkyl_eqn_type.h) + enum gkyl_field_id field_id; // type of field + // (e.g., Maxwell's, Poisson, see gkyl_eqn_type.h) bool is_static; // set to true if field does not change in time double epsilon0, mu0; @@ -213,12 +213,12 @@ struct gkyl_vlasov_field { // pointer to external electromagnetic fields function void (*app_current)(double t, const double *xn, double *app_current_out, void *ctx); bool app_current_evolve; // set to true if applied current function is time dependent - + double limiter_fac; // Optional input parameter for adjusting diffusion in slope limiter bool limit_em; // Optional input parameter for applying limiters to EM fields bool use_ghost_current; // Are we using ghost currents to correct dE/dt = -J in 1x - + // boundary conditions enum gkyl_field_bc_type bcx[2], bcy[2], bcz[2]; @@ -236,7 +236,7 @@ struct gkyl_vlasov_fluid_species { char name[128]; // species name double charge, mass; // charge and mass - + void *ctx; // context for initial condition init function // pointer to initialization function void (*init)(double t, const double *xn, double *fout, void *ctx); @@ -253,7 +253,7 @@ struct gkyl_vlasov_fluid_species { // source term struct gkyl_vlasov_fluid_source source; - + // diffusion coupling to include struct gkyl_vlasov_fluid_diffusion diffusion; @@ -265,7 +265,7 @@ struct gkyl_vlasov_fluid_species { // pointer to applied acceleration function void (*app_accel)(double t, const double *xn, double *aout, void *ctx); bool app_accel_evolve; // set to true if applied acceleration function is time dependent - + // boundary conditions enum gkyl_species_bc_type bcx[2], bcy[2], bcz[2]; }; @@ -296,7 +296,7 @@ struct gkyl_vm { int num_fluid_species; // number of fluid species struct gkyl_vlasov_fluid_species fluid_species[GKYL_MAX_SPECIES]; // fluid species objects - + bool skip_field; // Skip field update or no field specified struct gkyl_vlasov_field field; // field object bool is_electrostatic; // Indicate whether to use Vlasov-Poisson. @@ -307,16 +307,16 @@ struct gkyl_vm { // Simulation statistics struct gkyl_vlasov_stat { bool use_gpu; // did this sim use GPU? - + long nup; // calls to update long nfeuler; // calls to forward-Euler method - + long nstage_2_fail; // number of failed RK stage-2s long nstage_3_fail; // number of failed RK stage-3s double stage_2_dt_diff[2]; // [min,max] rel-diff for stage-2 failure double stage_3_dt_diff[2]; // [min,max] rel-diff for stage-3 failure - + double total_tm; // time for simulation (not including ICs) double rk3_tm; // time for SSP RK3 step double fl_em_tm; // time for implicit fluid-EM coupling step @@ -327,22 +327,23 @@ struct gkyl_vlasov_stat { double species_rhs_tm; // time to compute species collisionless RHS double fluid_species_rhs_tm; // time to compute fluid species RHS double fluid_species_vars_tm; // time to compute fluid variables (flow velocity and pressure) - + double species_coll_mom_tm; // time needed to compute various moments needed in LBO double species_lbo_coll_drag_tm[GKYL_MAX_SPECIES]; // time to compute LBO drag terms double species_lbo_coll_diff_tm[GKYL_MAX_SPECIES]; // time to compute LBO diffusion terms double species_coll_tm; // total time for collision updater (excluded moments) - double species_rad_tm; // total time for radiation updater + double species_rad_tm; // total time for radiation updater double species_lte_tm; // time needed to compute the lte equilibrium - long niter_self_bgk_corr[GKYL_MAX_SPECIES]; // number of iterations used to correct self collisions in BGK + long niter_self_bgk_corr + [GKYL_MAX_SPECIES]; // number of iterations used to correct self collisions in BGK double species_bc_tm; // time to compute species BCs double fluid_species_bc_tm; // time to compute fluid species BCs double field_bc_tm; // time to compute field - + double field_rhs_tm; // time to compute field RHS double current_tm; // time to compute currents and accumulation @@ -372,7 +373,7 @@ typedef struct gkyl_vlasov_app gkyl_vlasov_app; * initialized * @return New vlasov app object. */ -gkyl_vlasov_app* gkyl_vlasov_app_new(struct gkyl_vm *vm); +gkyl_vlasov_app *gkyl_vlasov_app_new(struct gkyl_vm *vm); /** * Initialize species and field by projecting initial conditions on @@ -381,7 +382,7 @@ gkyl_vlasov_app* gkyl_vlasov_app_new(struct gkyl_vm *vm); * @param app App object. * @param t0 Time for initial conditions. */ -void gkyl_vlasov_app_apply_ic(gkyl_vlasov_app* app, double t0); +void gkyl_vlasov_app_apply_ic(gkyl_vlasov_app *app, double t0); /** * Initialize field by projecting initial conditions on basis @@ -390,7 +391,7 @@ void gkyl_vlasov_app_apply_ic(gkyl_vlasov_app* app, double t0); * @param app App object. * @param t0 Time for initial conditions */ -void gkyl_vlasov_app_apply_ic_field(gkyl_vlasov_app* app, double t0); +void gkyl_vlasov_app_apply_ic_field(gkyl_vlasov_app *app, double t0); /** * Initialize species by projecting initial conditions on basis @@ -401,7 +402,7 @@ void gkyl_vlasov_app_apply_ic_field(gkyl_vlasov_app* app, double t0); * @param sidx Index of species to initialize. * @param t0 Time for initial conditions */ -void gkyl_vlasov_app_apply_ic_species(gkyl_vlasov_app* app, int sidx, double t0); +void gkyl_vlasov_app_apply_ic_species(gkyl_vlasov_app *app, int sidx, double t0); /** * Initialize fluid species by projecting initial conditions on basis @@ -412,7 +413,7 @@ void gkyl_vlasov_app_apply_ic_species(gkyl_vlasov_app* app, int sidx, double t0) * @param sidx Index of fluid species to initialize. * @param t0 Time for initial conditions */ -void gkyl_vlasov_app_apply_ic_fluid_species(gkyl_vlasov_app* app, int sidx, double t0); +void gkyl_vlasov_app_apply_ic_fluid_species(gkyl_vlasov_app *app, int sidx, double t0); /** * Initialize field from file @@ -430,9 +431,8 @@ gkyl_vlasov_app_from_file_field(gkyl_vlasov_app *app, const char *fname); * @param sidx gk species index * @param fname file to read */ -struct gkyl_app_restart_status -gkyl_vlasov_app_from_file_species(gkyl_vlasov_app *app, int sidx, - const char *fname); +struct gkyl_app_restart_status +gkyl_vlasov_app_from_file_species(gkyl_vlasov_app *app, int sidx, const char *fname); /** * Initialize fluid species from file @@ -441,9 +441,8 @@ gkyl_vlasov_app_from_file_species(gkyl_vlasov_app *app, int sidx, * @param sidx gk species index * @param fname file to read */ -struct gkyl_app_restart_status -gkyl_vlasov_app_from_file_fluid_species(gkyl_vlasov_app *app, int sidx, - const char *fname); +struct gkyl_app_restart_status +gkyl_vlasov_app_from_file_fluid_species(gkyl_vlasov_app *app, int sidx, const char *fname); /** * Initialize field from frame @@ -451,8 +450,7 @@ gkyl_vlasov_app_from_file_fluid_species(gkyl_vlasov_app *app, int sidx, * @param app App object * @param frame frame to read */ -struct gkyl_app_restart_status -gkyl_vlasov_app_from_frame_field(gkyl_vlasov_app *app, int frame); +struct gkyl_app_restart_status gkyl_vlasov_app_from_frame_field(gkyl_vlasov_app *app, int frame); /** * Initialize Vlasov species from frame @@ -480,8 +478,7 @@ gkyl_vlasov_app_from_frame_fluid_species(gkyl_vlasov_app *app, int sidx, int fra * @param app App object * @param frame frame to read */ -struct gkyl_app_restart_status -gkyl_vlasov_app_read_from_frame(gkyl_vlasov_app *app, int frame); +struct gkyl_app_restart_status gkyl_vlasov_app_read_from_frame(gkyl_vlasov_app *app, int frame); /** * Calculate diagnostic moments. @@ -496,7 +493,7 @@ void gkyl_vlasov_app_calc_mom(gkyl_vlasov_app *app); * @param tm Time at which integrated diagnostic are to be computed * @param app App object. */ -void gkyl_vlasov_app_calc_integrated_mom(gkyl_vlasov_app* app, double tm); +void gkyl_vlasov_app_calc_integrated_mom(gkyl_vlasov_app *app, double tm); /** * Calculate integrated L2 norm of the distribution function, f^2. @@ -504,7 +501,7 @@ void gkyl_vlasov_app_calc_integrated_mom(gkyl_vlasov_app* app, double tm); * @param tm Time at which integrated diagnostic are to be computed * @param app App object. */ -void gkyl_vlasov_app_calc_integrated_L2_f(gkyl_vlasov_app* app, double tm); +void gkyl_vlasov_app_calc_integrated_L2_f(gkyl_vlasov_app *app, double tm); /** * Calculate integrated field energy @@ -512,7 +509,7 @@ void gkyl_vlasov_app_calc_integrated_L2_f(gkyl_vlasov_app* app, double tm); * @param tm Time at which integrated diagnostic are to be computed * @param app App object. */ -void gkyl_vlasov_app_calc_field_energy(gkyl_vlasov_app* app, double tm); +void gkyl_vlasov_app_calc_field_energy(gkyl_vlasov_app *app, double tm); /** * Write field and species data to file. @@ -521,7 +518,7 @@ void gkyl_vlasov_app_calc_field_energy(gkyl_vlasov_app* app, double tm); * @param tm Time-stamp * @param frame Frame number */ -void gkyl_vlasov_app_write(gkyl_vlasov_app* app, double tm, int frame); +void gkyl_vlasov_app_write(gkyl_vlasov_app *app, double tm, int frame); /** * Write field data to file. @@ -530,7 +527,7 @@ void gkyl_vlasov_app_write(gkyl_vlasov_app* app, double tm, int frame); * @param tm Time-stamp * @param frame Frame number */ -void gkyl_vlasov_app_write_field(gkyl_vlasov_app* app, double tm, int frame); +void gkyl_vlasov_app_write_field(gkyl_vlasov_app *app, double tm, int frame); /** * Write species data to file. @@ -540,7 +537,7 @@ void gkyl_vlasov_app_write_field(gkyl_vlasov_app* app, double tm, int frame); * @param tm Time-stamp * @param frame Frame number */ -void gkyl_vlasov_app_write_species(gkyl_vlasov_app* app, int sidx, double tm, int frame); +void gkyl_vlasov_app_write_species(gkyl_vlasov_app *app, int sidx, double tm, int frame); /** * Write species data to file - for the local equilbrium. @@ -550,7 +547,7 @@ void gkyl_vlasov_app_write_species(gkyl_vlasov_app* app, int sidx, double tm, in * @param tm Time-stamp * @param frame Frame number */ -void gkyl_vlasov_app_write_species_lte(gkyl_vlasov_app* app, int sidx, double tm, int frame); +void gkyl_vlasov_app_write_species_lte(gkyl_vlasov_app *app, int sidx, double tm, int frame); /** * Write fluid species data to file. @@ -560,7 +557,7 @@ void gkyl_vlasov_app_write_species_lte(gkyl_vlasov_app* app, int sidx, double tm * @param tm Time-stamp * @param frame Frame number */ -void gkyl_vlasov_app_write_fluid_species(gkyl_vlasov_app* app, int sidx, double tm, int frame); +void gkyl_vlasov_app_write_fluid_species(gkyl_vlasov_app *app, int sidx, double tm, int frame); /** * Write diagnostic moments for species to file. @@ -609,14 +606,14 @@ void gkyl_vlasov_app_write_lte_corr_status(gkyl_vlasov_app *app); * * @param app App object. */ -void gkyl_vlasov_app_write_field_energy(gkyl_vlasov_app* app); +void gkyl_vlasov_app_write_field_energy(gkyl_vlasov_app *app); /** * Write stats to file. Data is written in json format. * * @param app App object. */ -void gkyl_vlasov_app_stat_write(gkyl_vlasov_app* app); +void gkyl_vlasov_app_stat_write(gkyl_vlasov_app *app); /** * Write output to console: this is mainly for diagnostic messages the @@ -628,7 +625,7 @@ void gkyl_vlasov_app_stat_write(gkyl_vlasov_app* app); * @param fmt Format string for console output * @param argp Objects to write */ -void gkyl_vlasov_app_cout(const gkyl_vlasov_app* app, FILE *fp, const char *fmt, ...); +void gkyl_vlasov_app_cout(const gkyl_vlasov_app *app, FILE *fp, const char *fmt, ...); /** * Advance simulation by a suggested time-step 'dt'. The dt may be too @@ -646,14 +643,14 @@ void gkyl_vlasov_app_cout(const gkyl_vlasov_app* app, FILE *fp, const char *fmt, * @param dt Suggested time-step to advance simulation * @return Status of update. */ -struct gkyl_update_status gkyl_vlasov_update(gkyl_vlasov_app* app, double dt); +struct gkyl_update_status gkyl_vlasov_update(gkyl_vlasov_app *app, double dt); /** * Return simulation statistics. * * @return Return statistics object. */ -struct gkyl_vlasov_stat gkyl_vlasov_app_stat(gkyl_vlasov_app* app); +struct gkyl_vlasov_stat gkyl_vlasov_app_stat(gkyl_vlasov_app *app); /** * Run the RHS for the species update. This is used to compute kernel @@ -663,11 +660,11 @@ struct gkyl_vlasov_stat gkyl_vlasov_app_stat(gkyl_vlasov_app* app); * @param app App object. * @param update_vol_term Set to 1 to update vol term also, 0 otherwise */ -void gkyl_vlasov_app_species_ktm_rhs(gkyl_vlasov_app* app, int update_vol_term); +void gkyl_vlasov_app_species_ktm_rhs(gkyl_vlasov_app *app, int update_vol_term); /** * Free Vlasov app. * * @param app App to release. */ -void gkyl_vlasov_app_release(gkyl_vlasov_app* app); +void gkyl_vlasov_app_release(gkyl_vlasov_app *app); diff --git a/vlasov/apps/gkyl_vlasov_comms.h b/vlasov/apps/gkyl_vlasov_comms.h index b4a68cf5ce..c35989138c 100644 --- a/vlasov/apps/gkyl_vlasov_comms.h +++ b/vlasov/apps/gkyl_vlasov_comms.h @@ -20,8 +20,7 @@ * @param Pointer to place where to put error messages. * @return New gkyl_comm communicator object. */ -struct gkyl_comm* -gkyl_vlasov_comms_new(bool use_mpi, bool use_gpu, FILE *iostream); +struct gkyl_comm *gkyl_vlasov_comms_new(bool use_mpi, bool use_gpu, FILE *iostream); /** * Free gyrokinetic app decomp and comm objects. @@ -29,5 +28,4 @@ gkyl_vlasov_comms_new(bool use_mpi, bool use_gpu, FILE *iostream); * @param decomp Decomposition object. * @param comm Communicator object. */ -void -gkyl_vlasov_comms_release(struct gkyl_comm *comm); +void gkyl_vlasov_comms_release(struct gkyl_comm *comm); diff --git a/vlasov/apps/gkyl_vlasov_lw.h b/vlasov/apps/gkyl_vlasov_lw.h index 4007182edc..9210c27010 100644 --- a/vlasov/apps/gkyl_vlasov_lw.h +++ b/vlasov/apps/gkyl_vlasov_lw.h @@ -17,40 +17,34 @@ void gkyl_vlasov_lw_openlibs(lua_State *L); * * @param L Lua state to use. */ -void -gkyl_register_poisson_bc_types(lua_State *L); +void gkyl_register_poisson_bc_types(lua_State *L); /** * Add projection type flags for Vlasov species initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_vlasov_projection_types(lua_State *L); +void gkyl_register_vlasov_projection_types(lua_State *L); /** * Add model type flags for Vlasov species initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_vlasov_model_types(lua_State *L); +void gkyl_register_vlasov_model_types(lua_State *L); /** * Add collision type flags for Vlasov species initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_vlasov_collision_types(lua_State *L); +void gkyl_register_vlasov_collision_types(lua_State *L); /** * Add source type flags for Vlasov species initialization into Lua interpreter. * * @param L Lua state to use. */ -void -gkyl_register_vlasov_source_types(lua_State *L); - +void gkyl_register_vlasov_source_types(lua_State *L); #endif diff --git a/vlasov/apps/gkyl_vlasov_priv.h b/vlasov/apps/gkyl_vlasov_priv.h index 8a76646812..01306e5257 100644 --- a/vlasov/apps/gkyl_vlasov_priv.h +++ b/vlasov/apps/gkyl_vlasov_priv.h @@ -101,7 +101,7 @@ struct correct_all_moms_inp { struct vm_species_moment { struct gkyl_array *marr; // array to moment data struct gkyl_array *marr_host; // host copy (same as marr if not on GPUs) - // Options for moment calculation: + // Options for moment calculation: // 1. Compute the moment directly with dg_updater_moment // 2. Compute the moments of the equivalent LTE (local thermodynamic equilibrium) // distribution (n, V_drift, T/m) with specialized updater @@ -122,26 +122,31 @@ struct vm_species_moment { // forward declare species struct struct vm_species; -struct vm_lbo_collisions { +struct vm_lbo_collisions { struct gkyl_array *boundary_corrections; // LBO boundary corrections struct gkyl_mom_calc_bcorr *bcorr_calc; // LBO boundary corrections calculator struct gkyl_array *nu_sum, *prim_moms, *nu_prim_moms; // LBO primitive moments bool normNu; // Boolean to determine if using Spitzer value - struct gkyl_array *norm_nu; // Array for normalization factor computed from Spitzer updater n/sqrt(2 vt^2)^3 + struct gkyl_array + *norm_nu; // Array for normalization factor computed from Spitzer updater n/sqrt(2 vt^2)^3 struct gkyl_array *nu_init; // Array for initial collisionality when using Spitzer updater - struct gkyl_spitzer_coll_freq* spitzer_calc; // Updater for Spitzer collisionality if computing Spitzer value + struct gkyl_spitzer_coll_freq + *spitzer_calc; // Updater for Spitzer collisionality if computing Spitzer value double betaGreenep1; // value of Greene's factor beta + 1 double other_m[GKYL_MAX_SPECIES]; // masses of species being collided with - struct gkyl_array *other_prim_moms[GKYL_MAX_SPECIES]; // self-primitive moments of species being collided with + struct gkyl_array + *other_prim_moms[GKYL_MAX_SPECIES]; // self-primitive moments of species being collided with struct gkyl_array *cross_prim_moms[GKYL_MAX_SPECIES]; // LBO cross-primitive moments struct gkyl_array *cross_nu[GKYL_MAX_SPECIES]; // LBO cross-species collision frequencies struct gkyl_array *other_nu[GKYL_MAX_SPECIES]; - struct gkyl_array *cross_nu_prim_moms; // weak multiplication of collision frequency and primitive moments - + struct gkyl_array + *cross_nu_prim_moms; // weak multiplication of collision frequency and primitive moments + struct gkyl_array *self_nu, *self_nu_prim_moms; // LBO self-primitive moments - struct vm_species_moment moms; // moments needed in LBO (single array includes Zeroth, First, and Second moment) + struct vm_species_moment + moms; // moments needed in LBO (single array includes Zeroth, First, and Second moment) struct gkyl_array *m0; struct gkyl_array *self_mnu_m0[GKYL_MAX_SPECIES], *self_mnu[GKYL_MAX_SPECIES]; struct gkyl_array *other_mnu_m0[GKYL_MAX_SPECIES], *other_mnu[GKYL_MAX_SPECIES]; @@ -157,33 +162,35 @@ struct vm_lbo_collisions { gkyl_dg_updater_collisions *coll_slvr; // collision solver }; -struct vm_lte { +struct vm_lte { struct gkyl_array *f_lte; struct vm_species_moment moms; // moments needed in the equilibrium // LTE distribution function projection object // also corrects the density of projected distribution function - struct gkyl_vlasov_lte_proj_on_basis *proj_lte; + struct gkyl_vlasov_lte_proj_on_basis *proj_lte; long niter; // total number of iterations correcting self collisions // Correction updater for insuring LTE distribution has desired LTE (n, V_drift, T/m) moments bool correct_all_moms; // boolean if we are correcting all the moments - struct gkyl_vlasov_lte_correct *corr_lte; + struct gkyl_vlasov_lte_correct *corr_lte; gkyl_dynvec corr_stat; bool is_first_corr_status_write_call; }; -struct vm_bgk_collisions { - struct gkyl_array *nu_sum; // BGK collision frequency +struct vm_bgk_collisions { + struct gkyl_array *nu_sum; // BGK collision frequency struct gkyl_array *nu_sum_host; // BGK collision frequency host-side for I/O struct gkyl_array *self_nu; // BGK self-collision frequency bool normNu; // Boolean to determine if using Spitzer value - struct gkyl_array *norm_nu; // Array for normalization factor computed from Spitzer updater n/sqrt(2 vt^2)^3 + struct gkyl_array + *norm_nu; // Array for normalization factor computed from Spitzer updater n/sqrt(2 vt^2)^3 struct gkyl_array *nu_init; // Array for initial collisionality when using Spitzer updater - struct gkyl_spitzer_coll_freq* spitzer_calc; // Updater for Spitzer collisionality if computing Spitzer value + struct gkyl_spitzer_coll_freq + *spitzer_calc; // Updater for Spitzer collisionality if computing Spitzer value struct vm_lte lte; // lte data and updater @@ -199,19 +206,19 @@ struct vm_bgk_collisions { double dt_implicit; // timestep used by the implicit collisions }; -struct vm_rad_drag { +struct vm_rad_drag { struct gkyl_array *nu; // collision frequency for radiation struct gkyl_array *nu_rad_drag; // nu*drag for drag force gkyl_dg_updater_rad_vlasov *rad_slvr; // radiation solver }; struct vm_boundary_fluxes { - struct gkyl_rect_grid boundary_grid[2*GKYL_MAX_CDIM]; - struct gkyl_array *flux_arr[2*GKYL_MAX_CDIM]; - struct gkyl_array *mom_arr[2*GKYL_MAX_CDIM]; - struct gkyl_range flux_r[2*GKYL_MAX_CDIM]; - struct gkyl_range conf_r[2*GKYL_MAX_CDIM]; - struct gkyl_dg_updater_moment *integ_moms[2*GKYL_MAX_CDIM]; // integrated moments + struct gkyl_rect_grid boundary_grid[2 * GKYL_MAX_CDIM]; + struct gkyl_array *flux_arr[2 * GKYL_MAX_CDIM]; + struct gkyl_array *mom_arr[2 * GKYL_MAX_CDIM]; + struct gkyl_range flux_r[2 * GKYL_MAX_CDIM]; + struct gkyl_range conf_r[2 * GKYL_MAX_CDIM]; + struct gkyl_dg_updater_moment *integ_moms[2 * GKYL_MAX_CDIM]; // integrated moments gkyl_ghost_surf_calc *flux_slvr; // boundary flux solver }; @@ -251,7 +258,7 @@ struct vm_emitting_wall { struct gkyl_range *impact_skin_r[GKYL_MAX_SPECIES]; struct gkyl_range *impact_buff_r[GKYL_MAX_SPECIES]; struct gkyl_range *impact_cbuff_r[GKYL_MAX_SPECIES]; - + struct gkyl_rect_grid *emit_grid; struct gkyl_range *emit_buff_r; struct gkyl_range *emit_ghost_r; @@ -281,14 +288,14 @@ struct vm_proj { struct gkyl_proj_on_basis *proj_dens; // projection operator for density struct gkyl_proj_on_basis *proj_V_drift; // projection operator for V_drift struct gkyl_proj_on_basis *proj_temp; // projection operator for temperature - + // LTE distribution function projection object // also corrects the density of projected distribution function - struct gkyl_vlasov_lte_proj_on_basis *proj_lte; + struct gkyl_vlasov_lte_proj_on_basis *proj_lte; // Correction updater for insuring LTE distribution has desired LTE (n, V_drift, T/m) moments bool correct_all_moms; // boolean if we are correcting all the moments - struct gkyl_vlasov_lte_correct *corr_lte; + struct gkyl_vlasov_lte_correct *corr_lte; }; }; }; @@ -304,7 +311,7 @@ struct vm_source { int source_species_idx; // index of source species struct gkyl_array *source; // applied source - struct gkyl_array *source_host; // host copy for use in IO + struct gkyl_array *source_host; // host copy for use in IO struct gkyl_array *source_tmp; // temporary array for sources for accumulation if num_sources>1 struct vm_proj proj_source[GKYL_MAX_PROJ]; // projector for source int num_sources; // Number of sources. @@ -320,13 +327,13 @@ struct vm_source { // species data struct vm_species { struct gkyl_vlasov_species info; // data for species - + struct gkyl_job_pool *job_pool; // Job pool struct gkyl_rect_grid grid; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges - struct gkyl_range global, global_ext; // global, global-ext conf-space ranges + struct gkyl_range global, global_ext; // global, global-ext conf-space ranges - struct gkyl_comm *comm; // communicator object for phase-space arrays + struct gkyl_comm *comm; // communicator object for phase-space arrays int nghost[GKYL_MAX_DIM]; // number of ghost-cells in each direction struct gkyl_rect_grid grid_vel; // velocity space grid @@ -335,7 +342,8 @@ struct vm_species { struct gkyl_array *f, *f1, *fnew; // arrays for updates struct gkyl_array *cflrate; // CFL rate in each cell struct gkyl_array *bc_buffer; // buffer for BCs (used by bc_basic) - struct gkyl_array *bc_buffer_lo_fixed, *bc_buffer_up_fixed; // fixed buffers for time independent BCs + struct gkyl_array *bc_buffer_lo_fixed, + *bc_buffer_up_fixed; // fixed buffers for time independent BCs struct gkyl_array *f_host; // host copy for use IO and initialization @@ -348,8 +356,8 @@ struct vm_species { union { // Special relativistic Vlasov-Maxwell model struct { - struct gkyl_array *gamma; // array for gamma = sqrt(1 + p^2) - struct gkyl_array *gamma_inv; // array for 1/gamma = 1.0/sqrt(1 + p^2) + struct gkyl_array *gamma; // array for gamma = sqrt(1 + p^2) + struct gkyl_array *gamma_inv; // array for 1/gamma = 1.0/sqrt(1 + p^2) struct gkyl_array *gamma_host; // host copy for I/O struct gkyl_array *gamma_inv_host; // host copy for I/O struct gkyl_dg_calc_sr_vars *sr_vars; // updater for computing SR variables @@ -367,7 +375,8 @@ struct vm_species { struct gkyl_array *alpha_surf; // Surface phase space velocity struct gkyl_array *sgn_alpha_surf; // sign(alpha_surf) at quadrature points - struct gkyl_array *const_sgn_alpha; // boolean for if sign(alpha_surf) is a constant, either +1 or -1 + struct gkyl_array + *const_sgn_alpha; // boolean for if sign(alpha_surf) is a constant, either +1 or -1 }; }; @@ -383,10 +392,10 @@ struct vm_species { bool is_first_integ_L2_write_call; // flag for integrated L^2 norm dynvec written first time bool is_first_integ_write_call; // flag for integrated moments dynvec written first time - gkyl_dg_updater_vlasov *slvr; // Vlasov solver + gkyl_dg_updater_vlasov *slvr; // Vlasov solver struct gkyl_dg_eqn *eqn_vlasov; // Vlasov equation object - - // boundary conditions on lower/upper edges in each direction + + // boundary conditions on lower/upper edges in each direction struct gkyl_vlasov_bc lower_bc[3], upper_bc[3]; // emitting wall sheath boundary conditions struct vm_emitting_wall bc_emission_lo; @@ -411,7 +420,7 @@ struct vm_species { int num_init; // Number of initial condition functions. struct vm_proj proj_init[GKYL_MAX_PROJ]; // projectors for initial conditions struct gkyl_array *f_tmp; // temporary array for accumulating initial conditions - + bool calc_bflux; // are we computing boundary fluxes? struct vm_boundary_fluxes bflux; // boundary flux object @@ -429,7 +438,7 @@ struct vm_species { struct { struct vm_bgk_collisions bgk; // BGK collisions object }; - }; + }; enum gkyl_radiation_id radiation_id; // type of radiation struct vm_rad_drag rad; // Vlasov radiation object @@ -445,36 +454,36 @@ struct vm_field { union { // Vlasov-Maxwell. struct { - struct gkyl_job_pool *job_pool; // Job pool + struct gkyl_job_pool *job_pool; // Job pool struct gkyl_array *em, *em1, *emnew; // arrays for updates struct gkyl_array *cflrate; // CFL rate in each cell struct gkyl_array *bc_buffer; // buffer for BCs (used for both copy and periodic) - struct gkyl_array *em_host; // host copy for use IO and initialization + struct gkyl_array *em_host; // host copy for use IO and initialization // Duplicate copy of EM data in case time step fails. - // Needed because of implicit source split which modifies solution and - // is always successful, so if a time step fails due to the SSP RK3 + // Needed because of implicit source split which modifies solution and + // is always successful, so if a time step fails due to the SSP RK3 // we must restore the old solution before restarting the time step - struct gkyl_array *em_dup; + struct gkyl_array *em_dup; bool has_ext_em; // flag to indicate there is external electromagnetic field bool ext_em_evolve; // flag to indicate external electromagnetic field is time dependent struct gkyl_array *ext_em; // external electromagnetic field struct gkyl_array *ext_em_host; // host copy for use in IO and projecting struct gkyl_array *tot_em; // total electromagnetic field - gkyl_proj_on_basis *ext_em_proj; // projector for external electromagnetic field + gkyl_proj_on_basis *ext_em_proj; // projector for external electromagnetic field - bool has_app_current; // flag to indicate there is an applied current + bool has_app_current; // flag to indicate there is an applied current bool app_current_evolve; // flag to indicate applied current is time dependent struct gkyl_array *app_current; // applied current struct gkyl_array *app_current_host; // host copy for use in IO and projecting - gkyl_proj_on_basis *app_current_proj; // projector for applied current + gkyl_proj_on_basis *app_current_proj; // projector for applied current gkyl_hyper_dg *slvr; // Maxwell solver bool limit_em; // boolean for whether or not we are limiting EM fields - struct gkyl_dg_calc_em_vars *calc_em_vars; // Updater to limit EM fields + struct gkyl_dg_calc_em_vars *calc_em_vars; // Updater to limit EM fields struct gkyl_array *em_energy; // EM energy components in each cell double *em_energy_red; // memory for use in GPU reduction of EM energy @@ -483,35 +492,36 @@ struct vm_field { struct gkyl_array *ghost_current; // Array for storying global average of current density double *red_ghost_current; // memory for use in GPU reduction of average of current density - // boundary conditions on lower/upper edges in each direction + // boundary conditions on lower/upper edges in each direction enum gkyl_field_bc_type lower_bc[3], upper_bc[3]; // Pointers to updaters that apply BC. struct gkyl_bc_basic *bc_lo[3]; struct gkyl_bc_basic *bc_up[3]; - double* omegaCfl_ptr; + double *omegaCfl_ptr; }; // Vlasov-Poisson. struct { - struct gkyl_array *epsilon; // Permittivity in Poisson equation. - + struct gkyl_array *epsilon; // Permittivity in Poisson equation. + struct gkyl_array *rho_c, *rho_c_global; // Local and global charge density. struct gkyl_array *phi, *phi_global; // Local and global potential. - - struct gkyl_array *phi_host; // host copy for use IO and initialization - + + struct gkyl_array *phi_host; // host copy for use IO and initialization + struct gkyl_range global_sub_range; // sub range of intersection of global range and local range - // for solving subset of Poisson solves with parallelization in z - - struct gkyl_fem_poisson *fem_poisson; // Poisson solver for - nabla . (epsilon * nabla phi) - kSq * phi = rho. - + // for solving subset of Poisson solves with parallelization in z + + struct gkyl_fem_poisson + *fem_poisson; // Poisson solver for - nabla . (epsilon * nabla phi) - kSq * phi = rho. + bool has_ext_pot; // flag to indicate there is external electromagnetic field bool ext_pot_evolve; // flag to indicate external electromagnetic field is time dependent struct gkyl_array *ext_pot; // external electromagnetic field struct gkyl_array *ext_pot_host; // host copy for use in IO and projecting - gkyl_eval_on_nodes *ext_pot_proj; // projector for external electromagnetic field - + gkyl_eval_on_nodes *ext_pot_proj; // projector for external electromagnetic field + struct gkyl_array *es_energy_fac; // Factor in calculation of ES energy diagnostic. struct gkyl_array_integrate *calc_es_energy; double *es_energy_red, *es_energy_red_global; // Memory for use in GPU reduction of ES energy. @@ -534,21 +544,21 @@ struct vm_fluid_source { struct vm_fluid_species { struct gkyl_vlasov_fluid_species info; // data for fluid - struct gkyl_job_pool *job_pool; // Job pool + struct gkyl_job_pool *job_pool; // Job pool struct gkyl_array *fluid, *fluid1, *fluidnew; // arrays for updates struct gkyl_array *cflrate; // CFL rate in each cell struct gkyl_array *bc_buffer; // buffer for BCs (used by bc_basic) - struct gkyl_array *fluid_host; // host copy for use IO and initialization + struct gkyl_array *fluid_host; // host copy for use IO and initialization // Duplicate copy of fluid data in case time step fails. - // Needed because of implicit source split which modifies solution and - // is always successful, so if a time step fails due to the SSP RK3 + // Needed because of implicit source split which modifies solution and + // is always successful, so if a time step fails due to the SSP RK3 // we must restore the old solution before restarting the time step - struct gkyl_array *fluid_dup; + struct gkyl_array *fluid_dup; - enum gkyl_eqn_type eqn_type; // type ID of equation - int num_equations; // number of equations in species + enum gkyl_eqn_type eqn_type; // type ID of equation + int num_equations; // number of equations in species struct gkyl_wv_eqn *equation; // equation object bool has_poisson; // organization of the different equation objects and the required data and solvers @@ -563,47 +573,62 @@ struct vm_fluid_species { // For isothermal Euler, u : (ux, uy, uz), p : (vth*rho) // For Euler, u : (ux, uy, uz, T/m), p : (gamma - 1)*(E - 1/2 rho u^2) // Also a prim_vars and prim_vars_host array for I/O of (u,p) - struct gkyl_array *u; - struct gkyl_array *p; - struct gkyl_array *prim_vars; - struct gkyl_array *prim_vars_host; - struct gkyl_array *cell_avg_prim; // Integer array for whether e.g., rho *only* uses cell averages for weak division - // Determined when constructing the matrix if rho < 0.0 at control points + struct gkyl_array *u; + struct gkyl_array *p; + struct gkyl_array *prim_vars; + struct gkyl_array *prim_vars_host; + struct gkyl_array * + cell_avg_prim; // Integer array for whether e.g., rho *only* uses cell averages for weak division + // Determined when constructing the matrix if rho < 0.0 at control points // Arrays for kinetic energy at old and new time steps. - // These are used because implicit source solve updates momentum but does not affect + // These are used because implicit source solve updates momentum but does not affect // the pressure, so we can construct the updated energy from the updated momentum. - struct gkyl_array *ke_old; - struct gkyl_array *ke_new; + struct gkyl_array *ke_old; + struct gkyl_array *ke_new; - struct gkyl_array *u_surf; + struct gkyl_array *u_surf; struct gkyl_array *p_surf; - struct gkyl_dg_calc_fluid_vars *calc_fluid_vars; // Updater to compute fluid variables (flow velocity and pressure) - struct gkyl_dg_calc_fluid_vars *calc_fluid_vars_ext; // Updater to compute fluid variables (flow velocity and pressure) - // over extended range (used when BCs are not absorbing to minimize apply BCs calls) + struct gkyl_dg_calc_fluid_vars + *calc_fluid_vars; // Updater to compute fluid variables (flow velocity and pressure) + struct gkyl_dg_calc_fluid_vars + *calc_fluid_vars_ext; // Updater to compute fluid variables (flow velocity and pressure) + // over extended range (used when BCs are not absorbing to minimize apply BCs calls) }; // Canonical PB Fluid such as incompressible Euler or Hasegawa-Wakatani struct { - struct gkyl_array *phi; // potential determined by canonical PB Poisson equation on local range used by updater - struct gkyl_array *phi_global; // potential determined by canonical PB Poisson equation on global range given by Poisson solver - struct gkyl_array *poisson_rhs_global; // global RHS of Poisson equation, simply an all-gather of, e.g., the vorticity + struct gkyl_array * + phi; // potential determined by canonical PB Poisson equation on local range used by updater + struct gkyl_array * + phi_global; // potential determined by canonical PB Poisson equation on global range given by Poisson solver + struct gkyl_array * + poisson_rhs_global; // global RHS of Poisson equation, simply an all-gather of, e.g., the vorticity struct gkyl_array *phi_host; // host copy for use IO - struct gkyl_array *can_pb_n0; // background density gradient for driving turbulence in some fluid systems. - struct gkyl_array *epsilon; // Permittivity in Poisson equation, set to -1.0 for canonical PB Poisson equations. - struct gkyl_array *kSq; // k^2 factor in Helmholtz equation needed for Hasegawa-Mima where we solve (grad^2 - 1) phi = RHS + struct gkyl_array + *can_pb_n0; // background density gradient for driving turbulence in some fluid systems. + struct gkyl_array * + epsilon; // Permittivity in Poisson equation, set to -1.0 for canonical PB Poisson equations. + struct gkyl_array * + kSq; // k^2 factor in Helmholtz equation needed for Hasegawa-Mima where we solve (grad^2 - 1) phi = RHS struct gkyl_range global_sub_range; // sub range of intersection of global range and local range - // for solving Poisson equation on each MPI process in parallel - - struct gkyl_fem_poisson *fem_poisson; // Poisson solver for - nabla . (epsilon * nabla phi) - kSq * phi = rho. + // for solving Poisson equation on each MPI process in parallel + + struct gkyl_fem_poisson + *fem_poisson; // Poisson solver for - nabla . (epsilon * nabla phi) - kSq * phi = rho. - struct gkyl_array *alpha_surf; // Surface configuration space velocity (derivatives of potential, phi) + struct gkyl_array + *alpha_surf; // Surface configuration space velocity (derivatives of potential, phi) struct gkyl_array *sgn_alpha_surf; // sign(alpha_surf) at quadrature points - struct gkyl_array *const_sgn_alpha; // boolean for if sign(alpha_surf) is a constant, either +1 or -1 - struct gkyl_dg_calc_canonical_pb_fluid_vars *calc_can_pb_fluid_vars; // Updater for computing surface alpha and sources. - struct gkyl_array *can_pb_energy_fac; // Factor in calculation of canonical PB energy diagnostic. + struct gkyl_array + *const_sgn_alpha; // boolean for if sign(alpha_surf) is a constant, either +1 or -1 + struct gkyl_dg_calc_canonical_pb_fluid_vars + *calc_can_pb_fluid_vars; // Updater for computing surface alpha and sources. + struct gkyl_array + *can_pb_energy_fac; // Factor in calculation of canonical PB energy diagnostic. struct gkyl_array_integrate *calc_can_pb_energy; - double *red_can_pb_energy, *red_can_pb_energy_global; // Memory for use in GPU reduction of canonical PB energy. + double *red_can_pb_energy, + *red_can_pb_energy_global; // Memory for use in GPU reduction of canonical PB energy. }; }; @@ -615,13 +640,13 @@ struct vm_fluid_species { struct gkyl_dg_updater_diffusion_fluid *diff_slvr; // Fluid equation solver struct gkyl_dg_updater_diffusion_gen *diff_slvr_gen; - // boundary conditions on lower/upper edges in each direction + // boundary conditions on lower/upper edges in each direction enum gkyl_species_bc_type lower_bc[3], upper_bc[3]; // Pointers to updaters that apply BC. struct gkyl_bc_basic *bc_lo[3]; struct gkyl_bc_basic *bc_up[3]; bool bc_is_absorb; // boolean for absorbing BCs since 1/rho is undefined in absorbing BCs - // If BCs are *not* absorbing, primitive variables can be calculated on *extended* range + // If BCs are *not* absorbing, primitive variables can be calculated on *extended* range struct gkyl_array *integ_mom; // Integrated moments double *red_integ_diag; // for reduction on GPU @@ -638,27 +663,29 @@ struct vm_fluid_species { enum gkyl_source_id source_id; // type of source struct vm_fluid_source src; // applied source - double* omegaCfl_ptr; + double *omegaCfl_ptr; - // Function pointers for computing primitive/auxiliary variables, - // and also write method, release method, and method for calculating integrated quantities. - void (*prim_vars_func)(gkyl_vlasov_app *app, struct vm_fluid_species *f, const struct gkyl_array *fluid); - void (*calc_integrated_mom_func)(gkyl_vlasov_app* app, struct vm_fluid_species *f, double tm); - void (*write_func)(gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm, int frame); - void (*release_func)(const gkyl_vlasov_app *app, struct vm_fluid_species *f); + // Function pointers for computing primitive/auxiliary variables, + // and also write method, release method, and method for calculating integrated quantities. + void (*prim_vars_func)( + gkyl_vlasov_app *app, struct vm_fluid_species *f, const struct gkyl_array *fluid + ); + void (*calc_integrated_mom_func)(gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm); + void (*write_func)(gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm, int frame); + void (*release_func)(const gkyl_vlasov_app *app, struct vm_fluid_species *f); }; // fluid-EM coupling data struct vm_fluid_em_coupling { double qbym[GKYL_MAX_SPECIES]; // charge/mass ratio for each species - struct gkyl_dg_calc_fluid_em_coupling* slvr; // fluid-EM coupling solver + struct gkyl_dg_calc_fluid_em_coupling *slvr; // fluid-EM coupling solver }; // Vlasov object: used as opaque pointer in user code struct gkyl_vlasov_app { char name[128]; // name of app struct gkyl_job_pool *job_pool; // Job pool - + int cdim, vdim; // conf, velocity space dimensions int poly_order; // polynomial order double tcurr; // current time @@ -668,10 +695,10 @@ struct gkyl_vlasov_app { int num_periodic_dir; // number of periodic directions int periodic_dirs[3]; // list of periodic directions - + struct gkyl_rect_grid grid; // config-space grid struct gkyl_range local, local_ext; // local, local-ext conf-space ranges - struct gkyl_range global, global_ext; // global, global-ext conf-space ranges + struct gkyl_range global, global_ext; // global, global-ext conf-space ranges // To simplify BC application, store local skin and ghost ranges struct gkyl_range lower_skin[GKYL_MAX_DIM]; struct gkyl_range lower_ghost[GKYL_MAX_DIM]; @@ -681,15 +708,16 @@ struct gkyl_vlasov_app { struct gkyl_basis basis, confBasis, velBasis; // phase-space, conf-space basis, vel-space basis struct gkyl_rect_decomp *decomp; // decomposition object - struct gkyl_comm *comm; // communicator object for conf-space arrays + struct gkyl_comm *comm; // communicator object for conf-space arrays bool has_mapc2p; // flag to indicate if we have mapc2p - void *c2p_ctx; // context for mapc2p function + void *c2p_ctx; // context for mapc2p function // pointer to mapc2p function void (*mapc2p)(double t, const double *xc, double *xp, void *ctx); - struct gkyl_wave_geom *geom; // geometry needed for species and field solvers (*only* p=1 right now JJ: 11/24/23) - + struct gkyl_wave_geom + *geom; // geometry needed for species and field solvers (*only* p=1 right now JJ: 11/24/23) + // pointers to basis on device (these point to host structs if not // on GPU) struct { @@ -702,7 +730,7 @@ struct gkyl_vlasov_app { // species data int num_species; struct vm_species *species; // data for each species - + // fluid data int num_fluid_species; struct vm_fluid_species *fluid_species; // data for each fluid species @@ -714,36 +742,35 @@ struct gkyl_vlasov_app { // pointer to function that takes a single-step of simulation struct gkyl_update_status (*update_func)(gkyl_vlasov_app *app, double dt0); - // Function used to compute the field energy. + // Function used to compute the field energy. void (*field_energy_calc)(gkyl_vlasov_app *app, double tm, const struct vm_field *field); struct gkyl_vlasov_stat stat; // statistics - + // Pointer to function that calculates the external E and B. void (*field_calc_ext_em)(gkyl_vlasov_app *app, struct vm_field *field, double tm); }; -// Take a single forward Euler step of the Vlasov-Maxwell system +// Take a single forward Euler step of the Vlasov-Maxwell system // with the suggested time-step dt. Also supports just Maxwell's equations -// and fluid equations (Euler's) with potential Vlasov-fluid coupling. -void vlasov_forward_euler(gkyl_vlasov_app* app, double tcurr, double dt, - const struct gkyl_array *fin[], const struct gkyl_array *fluidin[], const struct gkyl_array *emin, - struct gkyl_array *fout[], struct gkyl_array *fluidout[], struct gkyl_array *emout, - struct gkyl_update_status *st); +// and fluid equations (Euler's) with potential Vlasov-fluid coupling. +void vlasov_forward_euler( + gkyl_vlasov_app *app, double tcurr, double dt, const struct gkyl_array *fin[], + const struct gkyl_array *fluidin[], const struct gkyl_array *emin, struct gkyl_array *fout[], + struct gkyl_array *fluidout[], struct gkyl_array *emout, struct gkyl_update_status *st +); // Calls the vlasov implicit contribution for all vm species -void vlasov_update_implicit_coll(gkyl_vlasov_app *app, double dt0); +void vlasov_update_implicit_coll(gkyl_vlasov_app *app, double dt0); -// Take a single time-step using a first-order operator split +// Take a single time-step using a first-order operator split // implicit fluid-EM coupling and/or implicit BGK collisions + SSP RK3 -struct gkyl_update_status vlasov_update_op_split(gkyl_vlasov_app *app, double dt0); +struct gkyl_update_status vlasov_update_op_split(gkyl_vlasov_app *app, double dt0); // Take a single time-step using a SSP-RK3 stepper -struct gkyl_update_status vlasov_update_ssp_rk3(gkyl_vlasov_app *app, - double dt0); +struct gkyl_update_status vlasov_update_ssp_rk3(gkyl_vlasov_app *app, double dt0); // Take a single time-step in Vlasov-Poisson using a SSP-RK3 stepper. -struct gkyl_update_status vlasov_poisson_update_ssp_rk3(gkyl_vlasov_app *app, - double dt0); +struct gkyl_update_status vlasov_poisson_update_ssp_rk3(gkyl_vlasov_app *app, double dt0); /** gkyl_vlasov_app private API */ @@ -754,16 +781,14 @@ struct gkyl_update_status vlasov_poisson_update_ssp_rk3(gkyl_vlasov_app *app, * @param meta Vlasov metadata object. * @return Array metadata object. */ -struct gkyl_msgpack_data* -vlasov_array_meta_new(struct vlasov_output_meta meta); +struct gkyl_msgpack_data *vlasov_array_meta_new(struct vlasov_output_meta meta); /** * Free memory for array metadata object. * * @param mt Array metadata object. */ -void -vlasov_array_meta_release(struct gkyl_msgpack_data *mt); +void vlasov_array_meta_release(struct gkyl_msgpack_data *mt); /** * Return the metadata for outputing vlasov data. @@ -771,8 +796,7 @@ vlasov_array_meta_release(struct gkyl_msgpack_data *mt); * @param mt Array metadata object. * @return A vlasov metadata object. */ -struct vlasov_output_meta -vlasov_meta_from_mpack(struct gkyl_msgpack_data *mt); +struct vlasov_output_meta vlasov_meta_from_mpack(struct gkyl_msgpack_data *mt); /** * Apply BCs to kinetic species, fluid species and EM fields. @@ -783,8 +807,10 @@ vlasov_meta_from_mpack(struct gkyl_msgpack_data *mt); * @param fluid Array of moments (for each species). * @param emfield Electromagnetic fields. */ -void vm_apply_bc(gkyl_vlasov_app* app, double tcurr, - struct gkyl_array *distf[], struct gkyl_array *fluid[], struct gkyl_array *emfield); +void vm_apply_bc( + gkyl_vlasov_app *app, double tcurr, struct gkyl_array *distf[], struct gkyl_array *fluid[], + struct gkyl_array *emfield +); /** * Find species with given name. @@ -793,7 +819,7 @@ void vm_apply_bc(gkyl_vlasov_app* app, double tcurr, * @param nm Name of species * @return Pointer to species with given name. NULL if not found. */ -struct vm_species* vm_find_species(const gkyl_vlasov_app *app, const char *nm); +struct vm_species *vm_find_species(const gkyl_vlasov_app *app, const char *nm); /** * Return index of species in the order it appears in the input. @@ -822,7 +848,6 @@ struct vm_fluid_species *vm_find_fluid_species(const gkyl_vlasov_app *app, const */ int vm_find_fluid_species_idx(const gkyl_vlasov_app *app, const char *nm); - /** vm_species_moment API */ /** @@ -834,8 +859,10 @@ int vm_find_fluid_species_idx(const gkyl_vlasov_app *app, const char *nm); * @param mom_type Type of moment to compute. * @param is_integrated Whether to compute volume-integrated moment. */ -void vm_species_moment_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_species_moment *sm, enum gkyl_distribution_moments mom_type, bool is_integrated); +void vm_species_moment_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_species_moment *sm, + enum gkyl_distribution_moments mom_type, bool is_integrated +); /** * Calculate moment, given distribution function @a fin. @@ -845,9 +872,10 @@ void vm_species_moment_init(struct gkyl_vlasov_app *app, struct vm_species *s, * @param conf_rng Config-space range * @param fin Input distribution function array */ -void vm_species_moment_calc(const struct vm_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin); +void vm_species_moment_calc( + const struct vm_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +); /** * Release species moment object. @@ -855,8 +883,9 @@ void vm_species_moment_calc(const struct vm_species_moment *sm, * @param app Vlasov app object * @param sm Species moment object to release */ -void vm_species_moment_release(const struct gkyl_vlasov_app *app, - const struct vm_species_moment *sm); +void vm_species_moment_release( + const struct gkyl_vlasov_app *app, const struct vm_species_moment *sm +); /** vm_species_emission API */ @@ -869,8 +898,10 @@ void vm_species_moment_release(const struct gkyl_vlasov_app *app, * @param edge Edge of configuration space * @param ctx Emission context */ -void vm_species_emission_init(struct gkyl_vlasov_app *app, struct vm_emitting_wall *emit, - int dir, enum gkyl_edge_loc edge, void *ctx); +void vm_species_emission_init( + struct gkyl_vlasov_app *app, struct vm_emitting_wall *emit, int dir, enum gkyl_edge_loc edge, + void *ctx +); /** * Initialize emission BC cross-species object. @@ -879,8 +910,9 @@ void vm_species_emission_init(struct gkyl_vlasov_app *app, struct vm_emitting_wa * @param s Species object * @param emit Species emission object */ -void vm_species_emission_cross_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_emitting_wall *emit); +void vm_species_emission_cross_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_emitting_wall *emit +); /** * Apply emission BCs to species distribution function @@ -890,8 +922,10 @@ void vm_species_emission_cross_init(struct gkyl_vlasov_app *app, struct vm_speci * @param fout Field to apply BCs * @param tcurr Current time */ -void vm_species_emission_apply_bc(struct gkyl_vlasov_app *app, const struct vm_emitting_wall *emit, - struct gkyl_array *fout, double tcurr); +void vm_species_emission_apply_bc( + struct gkyl_vlasov_app *app, const struct vm_emitting_wall *emit, struct gkyl_array *fout, + double tcurr +); /** * Write emission spectrum distribution function @@ -902,8 +936,10 @@ void vm_species_emission_apply_bc(struct gkyl_vlasov_app *app, const struct vm_e * @param mt Write meta * @param frame Current frame */ -void vm_species_emission_write(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_emitting_wall *emit, struct gkyl_msgpack_data *mt, int frame); +void vm_species_emission_write( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_emitting_wall *emit, + struct gkyl_msgpack_data *mt, int frame +); /** * Release species emission object. @@ -922,8 +958,9 @@ void vm_species_emission_release(const struct vm_emitting_wall *emit); * @param s Species object * @param lbo Species LBO object */ -void vm_species_lbo_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_lbo_collisions *lbo); +void vm_species_lbo_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_lbo_collisions *lbo +); /** * Initialize species LBO cross-collisions object. @@ -932,8 +969,9 @@ void vm_species_lbo_init(struct gkyl_vlasov_app *app, struct vm_species *s, * @param s Species object * @param lbo Species LBO object */ -void vm_species_lbo_cross_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_lbo_collisions *lbo); +void vm_species_lbo_cross_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_lbo_collisions *lbo +); /** * Compute necessary moments and boundary @@ -944,10 +982,10 @@ void vm_species_lbo_cross_init(struct gkyl_vlasov_app *app, struct vm_species *s * @param lbo Pointer to LBO * @param fin Input distribution function */ -void vm_species_lbo_moms(gkyl_vlasov_app *app, - const struct vm_species *species, - struct vm_lbo_collisions *lbo, - const struct gkyl_array *fin); +void vm_species_lbo_moms( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_lbo_collisions *lbo, + const struct gkyl_array *fin +); /** * Compute necessary moments for cross-species LBO collisions @@ -957,10 +995,10 @@ void vm_species_lbo_moms(gkyl_vlasov_app *app, * @param lbo Pointer to LBO * @param fin Input distribution function */ -void vm_species_lbo_cross_moms(gkyl_vlasov_app *app, - const struct vm_species *species, - struct vm_lbo_collisions *lbo, - const struct gkyl_array *fin); +void vm_species_lbo_cross_moms( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_lbo_collisions *lbo, + const struct gkyl_array *fin +); /** * Compute RHS from LBO collisions @@ -972,10 +1010,10 @@ void vm_species_lbo_cross_moms(gkyl_vlasov_app *app, * @param rhs On output, the RHS from LBO * @return Maximum stable time-step */ -void vm_species_lbo_rhs(gkyl_vlasov_app *app, - const struct vm_species *species, - struct vm_lbo_collisions *lbo, - const struct gkyl_array *fin, struct gkyl_array *rhs); +void vm_species_lbo_rhs( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_lbo_collisions *lbo, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Release species LBO object. @@ -993,8 +1031,10 @@ void vm_species_lbo_release(const struct gkyl_vlasov_app *app, const struct vm_l * @param lte Species lte object * @param corr_inp Input struct with moment correction inputs */ -void vm_species_lte_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_lte *lte, struct correct_all_moms_inp corr_inp); +void vm_species_lte_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_lte *lte, + struct correct_all_moms_inp corr_inp +); /** * Compute LTE distribution from input moments @@ -1004,10 +1044,10 @@ void vm_species_lte_init(struct gkyl_vlasov_app *app, struct vm_species *s, * @param lte Pointer to lte object * @param moms_lte Input LTE moments */ -void vm_species_lte_from_moms(gkyl_vlasov_app *app, - const struct vm_species *species, - struct vm_lte *lte, - const struct gkyl_array *moms_lte); +void vm_species_lte_from_moms( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_lte *lte, + const struct gkyl_array *moms_lte +); /** * Compute equivalent LTE distribution from input distribution function. @@ -1017,10 +1057,10 @@ void vm_species_lte_from_moms(gkyl_vlasov_app *app, * @param lte Pointer to lte * @param fin Input distribution function */ -void vm_species_lte(gkyl_vlasov_app *app, - const struct vm_species *species, - struct vm_lte *lte, - const struct gkyl_array *fin); +void vm_species_lte( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_lte *lte, + const struct gkyl_array *fin +); /** * Release species lte object. @@ -1039,8 +1079,9 @@ void vm_species_lte_release(const struct gkyl_vlasov_app *app, const struct vm_l * @param s Species object * @param bgk Species BGK object */ -void vm_species_bgk_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_bgk_collisions *bgk); +void vm_species_bgk_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_bgk_collisions *bgk +); /** * Compute necessary moments for BGK collisions @@ -1050,10 +1091,10 @@ void vm_species_bgk_init(struct gkyl_vlasov_app *app, struct vm_species *s, * @param bgk Pointer to BGK * @param fin Input distribution function */ -void vm_species_bgk_moms(gkyl_vlasov_app *app, - const struct vm_species *species, - struct vm_bgk_collisions *bgk, - const struct gkyl_array *fin); +void vm_species_bgk_moms( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_bgk_collisions *bgk, + const struct gkyl_array *fin +); /** * Compute and store a fixed temperature for BGK collisions @@ -1063,10 +1104,10 @@ void vm_species_bgk_moms(gkyl_vlasov_app *app, * @param bgk Pointer to BGK * @param fin Input distribution function */ -void vm_species_bgk_moms_fixed_temp(gkyl_vlasov_app *app, - const struct vm_species *species, - struct vm_bgk_collisions *bgk, - const struct gkyl_array *fin); +void vm_species_bgk_moms_fixed_temp( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_bgk_collisions *bgk, + const struct gkyl_array *fin +); /** * Compute RHS from BGK collisions @@ -1077,10 +1118,10 @@ void vm_species_bgk_moms_fixed_temp(gkyl_vlasov_app *app, * @param fin Input distribution function * @param rhs On output, the RHS from bgk */ -void vm_species_bgk_rhs(gkyl_vlasov_app *app, - struct vm_species *species, - struct vm_bgk_collisions *bgk, - const struct gkyl_array *fin, struct gkyl_array *rhs); +void vm_species_bgk_rhs( + gkyl_vlasov_app *app, struct vm_species *species, struct vm_bgk_collisions *bgk, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Release species BGK object. @@ -1099,8 +1140,9 @@ void vm_species_bgk_release(const struct gkyl_vlasov_app *app, const struct vm_b * @param s Species object * @param rad Species radiation object */ -void vm_species_radiation_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_rad_drag *rad); +void vm_species_radiation_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_rad_drag *rad +); /** * Compute RHS from radiation operator @@ -1111,10 +1153,10 @@ void vm_species_radiation_init(struct gkyl_vlasov_app *app, struct vm_species *s * @param fin Input distribution function * @param rhs On output, the RHS from radiation */ -void vm_species_radiation_rhs(gkyl_vlasov_app *app, - const struct vm_species *species, - struct vm_rad_drag *rad, - const struct gkyl_array *fin, struct gkyl_array *rhs); +void vm_species_radiation_rhs( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_rad_drag *rad, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Release species radiation object. @@ -1133,8 +1175,9 @@ void vm_species_radiation_release(const struct gkyl_vlasov_app *app, const struc * @param s Species object * @param bflux Species boundary flux object */ -void vm_species_bflux_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_boundary_fluxes *bflux); +void vm_species_bflux_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_boundary_fluxes *bflux +); /** * Compute boundary flux from rhs @@ -1145,8 +1188,10 @@ void vm_species_bflux_init(struct gkyl_vlasov_app *app, struct vm_species *s, * @param fin Input distribution function * @param rhs On output, the RHS from LBO */ -void vm_species_bflux_rhs(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_boundary_fluxes *bflux, const struct gkyl_array *fin, struct gkyl_array *rhs); +void vm_species_bflux_rhs( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_boundary_fluxes *bflux, + const struct gkyl_array *fin, struct gkyl_array *rhs +); /** * Release species boundary flux object. @@ -1154,7 +1199,9 @@ void vm_species_bflux_rhs(gkyl_vlasov_app *app, const struct vm_species *species * @param app Vlasov app object * @param bflux Species boundary flux object to release */ -void vm_species_bflux_release(const struct gkyl_vlasov_app *app, const struct vm_boundary_fluxes *bflux); +void vm_species_bflux_release( + const struct gkyl_vlasov_app *app, const struct vm_boundary_fluxes *bflux +); /** vm_species_projection API */ @@ -1166,8 +1213,10 @@ void vm_species_bflux_release(const struct gkyl_vlasov_app *app, const struct vm * @param inp Input struct for projection (contains functions pointers for type of projection) * @param proj Species projection object */ -void vm_species_projection_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct gkyl_vlasov_projection inp, struct vm_proj *proj); +void vm_species_projection_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct gkyl_vlasov_projection inp, + struct vm_proj *proj +); /** * Compute species projection @@ -1178,8 +1227,10 @@ void vm_species_projection_init(struct gkyl_vlasov_app *app, struct vm_species * * @param f Output distribution function from projection * @param tm Time for use in projection */ -void vm_species_projection_calc(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_proj *proj, struct gkyl_array *f, double tm); +void vm_species_projection_calc( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_proj *proj, + struct gkyl_array *f, double tm +); /** * Release species projection object. @@ -1198,7 +1249,9 @@ void vm_species_projection_release(const struct gkyl_vlasov_app *app, const stru * @param s Species object * @param src Species source object */ -void vm_species_source_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_source *src); +void vm_species_source_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_source *src +); /** * Compute species applied source term @@ -1208,8 +1261,9 @@ void vm_species_source_init(struct gkyl_vlasov_app *app, struct vm_species *s, s * @param src Pointer to source * @param tm Time for use in source */ -void vm_species_source_calc(gkyl_vlasov_app *app, struct vm_species *species, - struct vm_source *src, double tm); +void vm_species_source_calc( + gkyl_vlasov_app *app, struct vm_species *species, struct vm_source *src, double tm +); /** * Compute RHS contribution from source @@ -1220,8 +1274,10 @@ void vm_species_source_calc(gkyl_vlasov_app *app, struct vm_species *species, * @param fin Input distribution function * @param rhs On output, the distribution function */ -void vm_species_source_rhs(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_source *src, const struct gkyl_array *fin[], struct gkyl_array *rhs[]); +void vm_species_source_rhs( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_source *src, + const struct gkyl_array *fin[], struct gkyl_array *rhs[] +); /** * Release species source object. @@ -1270,9 +1326,10 @@ void vm_species_calc_app_accel(gkyl_vlasov_app *app, struct vm_species *species, * @param rhs On output, the RHS from the species object * @return Maximum stable time-step */ -double vm_species_rhs(gkyl_vlasov_app *app, struct vm_species *species, - const struct gkyl_array *fin, const struct gkyl_array *em, - struct gkyl_array *rhs); +double vm_species_rhs( + gkyl_vlasov_app *app, struct vm_species *species, const struct gkyl_array *fin, + const struct gkyl_array *em, struct gkyl_array *rhs +); /** * Compute the *implicit* RHS from species distribution function @@ -1284,8 +1341,10 @@ double vm_species_rhs(gkyl_vlasov_app *app, struct vm_species *species, * @param dt timestep size (used in the implcit coef.) * @return Maximum stable time-step */ -double vm_species_rhs_implicit(gkyl_vlasov_app *app, struct vm_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, double dt); +double vm_species_rhs_implicit( + gkyl_vlasov_app *app, struct vm_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, double dt +); /** * Apply BCs to species distribution function @@ -1295,7 +1354,9 @@ double vm_species_rhs_implicit(gkyl_vlasov_app *app, struct vm_species *species, * @param f Field to apply BCs * @param tcurr Current time */ -void vm_species_apply_bc(gkyl_vlasov_app *app, const struct vm_species *species, struct gkyl_array *f, double tcurr); +void vm_species_apply_bc( + gkyl_vlasov_app *app, const struct vm_species *species, struct gkyl_array *f, double tcurr +); /** * Compute L2 norm (f^2) of the distribution function diagnostic @@ -1321,7 +1382,6 @@ void vm_species_coll_tm(gkyl_vlasov_app *app); */ void vm_species_bgk_niter(gkyl_vlasov_app *app); - /** * Fill stat object in app with collisionless timers. * @@ -1342,7 +1402,7 @@ void vm_species_rad_tm(gkyl_vlasov_app *app); * @param app Vlasov app object * @param species Species object to delete */ -void vm_species_release(const gkyl_vlasov_app* app, const struct vm_species *s); +void vm_species_release(const gkyl_vlasov_app *app, const struct vm_species *s); /** vm_field API */ @@ -1353,7 +1413,7 @@ void vm_species_release(const gkyl_vlasov_app* app, const struct vm_species *s); * @param app Vlasov app object * @return Newly created field */ -struct vm_field* vm_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app); +struct vm_field *vm_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app); /** * Compute field initial conditions. @@ -1390,8 +1450,10 @@ void vm_field_calc_app_current(gkyl_vlasov_app *app, struct vm_field *field, dou * @param fluidin[] Input fluid array (num_fluid_species size) * @param emout On output, the RHS from the field solver *with* accumulated current density */ -void vm_field_accumulate_current(gkyl_vlasov_app *app, - const struct gkyl_array *fin[], const struct gkyl_array *fluidin[], struct gkyl_array *emout); +void vm_field_accumulate_current( + gkyl_vlasov_app *app, const struct gkyl_array *fin[], const struct gkyl_array *fluidin[], + struct gkyl_array *emout +); /** * Limit slopes of solution of EM variables @@ -1411,7 +1473,9 @@ void vm_field_limiter(gkyl_vlasov_app *app, struct vm_field *field, struct gkyl_ * @param rhs On output, the RHS from the field solver * @return Maximum stable time-step */ -double vm_field_rhs(gkyl_vlasov_app *app, struct vm_field *field, const struct gkyl_array *em, struct gkyl_array *rhs); +double vm_field_rhs( + gkyl_vlasov_app *app, struct vm_field *field, const struct gkyl_array *em, struct gkyl_array *rhs +); /** * Apply BCs to field @@ -1420,8 +1484,7 @@ double vm_field_rhs(gkyl_vlasov_app *app, struct vm_field *field, const struct g * @param field Pointer to field * @param f Field to apply BCs */ -void vm_field_apply_bc(gkyl_vlasov_app *app, const struct vm_field *field, - struct gkyl_array *f); +void vm_field_apply_bc(gkyl_vlasov_app *app, const struct vm_field *field, struct gkyl_array *f); /** * Compute field energy diagnostic @@ -1438,7 +1501,7 @@ void vm_field_calc_energy(gkyl_vlasov_app *app, double tm, const struct vm_field * @param app Vlasov app object * @param f Field object to release */ -void vm_field_release(const gkyl_vlasov_app* app, struct vm_field *f); +void vm_field_release(const gkyl_vlasov_app *app, struct vm_field *f); /** vp_field API */ @@ -1449,7 +1512,7 @@ void vm_field_release(const gkyl_vlasov_app* app, struct vm_field *f); * @param app Vlasov app object. * @return Newly created field. */ -struct vm_field* vp_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app); +struct vm_field *vp_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app); /** * Compute external potentials. @@ -1477,8 +1540,9 @@ void vp_field_calc_ext_em(gkyl_vlasov_app *app, struct vm_field *field, double t * @param fin[] Input distribution function (num_species size). * @param t0 Time for use in ICs. */ -void vp_field_apply_ic(gkyl_vlasov_app *app, struct vm_field *field, - const struct gkyl_array *fin[], double t0); +void vp_field_apply_ic( + gkyl_vlasov_app *app, struct vm_field *field, const struct gkyl_array *fin[], double t0 +); /** * Accumulate charge density for Poisson solve. @@ -1487,8 +1551,9 @@ void vp_field_apply_ic(gkyl_vlasov_app *app, struct vm_field *field, * @param field Pointer to field. * @param fin[] Input distribution function (num_species size). */ -void vp_field_accumulate_charge_dens(gkyl_vlasov_app *app, struct vm_field *field, - const struct gkyl_array *fin[]); +void vp_field_accumulate_charge_dens( + gkyl_vlasov_app *app, struct vm_field *field, const struct gkyl_array *fin[] +); /** * Compute RHS from field equations @@ -1505,8 +1570,7 @@ void vp_field_solve(gkyl_vlasov_app *app, struct vm_field *field); * @param tcurr Current time. * @param field Pointer to field. */ -void -vp_calc_field(gkyl_vlasov_app* app, double tcurr, const struct gkyl_array *fin[]); +void vp_calc_field(gkyl_vlasov_app *app, double tcurr, const struct gkyl_array *fin[]); /** * Compute the electrostatic potential for Vlasov-Poisson and apply BCs. @@ -1515,8 +1579,7 @@ vp_calc_field(gkyl_vlasov_app* app, double tcurr, const struct gkyl_array *fin[] * @param tcurr Current time. * @param field Pointer to field. */ -void -vp_calc_field_and_apply_bc(gkyl_vlasov_app* app, double tcurr, struct gkyl_array *distf[]); +void vp_calc_field_and_apply_bc(gkyl_vlasov_app *app, double tcurr, struct gkyl_array *distf[]); /** * Compute field energy diagnostic. @@ -1533,7 +1596,7 @@ void vp_field_calc_energy(gkyl_vlasov_app *app, double tm, const struct vm_field * @param app Vlasov app object. * @param f Field object to release. */ -void vp_field_release(const gkyl_vlasov_app* app, struct vm_field *f); +void vp_field_release(const gkyl_vlasov_app *app, struct vm_field *f); /** vm_fluid_species_source API */ @@ -1544,7 +1607,9 @@ void vp_field_release(const gkyl_vlasov_app* app, struct vm_field *f); * @param s Species object * @param src Species source object */ -void vm_fluid_species_source_init(struct gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, struct vm_fluid_source *src); +void vm_fluid_species_source_init( + struct gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, struct vm_fluid_source *src +); /** * Compute fluid species applied source term @@ -1553,7 +1618,9 @@ void vm_fluid_species_source_init(struct gkyl_vlasov_app *app, struct vm_fluid_s * @param species Species object * @param tm Time for use in source */ -void vm_fluid_species_source_calc(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm); +void vm_fluid_species_source_calc( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm +); /** * Compute RHS contribution from source @@ -1564,8 +1631,10 @@ void vm_fluid_species_source_calc(gkyl_vlasov_app *app, struct vm_fluid_species * @param fin Input distribution function * @param rhs On output, the distribution function RHS */ -void vm_fluid_species_source_rhs(gkyl_vlasov_app *app, const struct vm_fluid_species *species, - struct vm_fluid_source *src, const struct gkyl_array *fin[], struct gkyl_array *rhs[]); +void vm_fluid_species_source_rhs( + gkyl_vlasov_app *app, const struct vm_fluid_species *species, struct vm_fluid_source *src, + const struct gkyl_array *fin[], struct gkyl_array *rhs[] +); /** * Release fluid species source object. @@ -1573,7 +1642,9 @@ void vm_fluid_species_source_rhs(gkyl_vlasov_app *app, const struct vm_fluid_spe * @param app Vlasov app object * @param src Species source object to release */ -void vm_fluid_species_source_release(const struct gkyl_vlasov_app *app, const struct vm_fluid_source *src); +void vm_fluid_species_source_release( + const struct gkyl_vlasov_app *app, const struct vm_fluid_source *src +); /** vm_fluid_species API */ @@ -1584,7 +1655,9 @@ void vm_fluid_species_source_release(const struct gkyl_vlasov_app *app, const st * @param app Vlasov app object * @param f On output, initialized fluid species object */ -void vm_fluid_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_fluid_species *f); +void vm_fluid_species_init( + struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_fluid_species *f +); /** * Compute fluid species initial conditions. @@ -1593,7 +1666,9 @@ void vm_fluid_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, stru * @param fluid_species Fluid Species object * @param t0 Time for use in ICs */ -void vm_fluid_species_apply_ic(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double t0); +void vm_fluid_species_apply_ic( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double t0 +); /** * Compute fluid species applied acceleration term @@ -1602,7 +1677,9 @@ void vm_fluid_species_apply_ic(gkyl_vlasov_app *app, struct vm_fluid_species *fl * @param fluid_species Fluid Species object * @param tm Time for use in acceleration */ -void vm_fluid_species_calc_app_accel(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm); +void vm_fluid_species_calc_app_accel( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm +); /** * Compute primitive variables (bulk velocity, u, and pressure, p, if pressure present) @@ -1611,8 +1688,9 @@ void vm_fluid_species_calc_app_accel(gkyl_vlasov_app *app, struct vm_fluid_speci * @param fluid_species Fluid Species object (where primitive variables are stored) * @param fluid Input array fluid species */ -void vm_fluid_species_prim_vars(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, - const struct gkyl_array *fluid); +void vm_fluid_species_prim_vars( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, const struct gkyl_array *fluid +); /** * Limit slopes of solution of fluid variables @@ -1621,8 +1699,9 @@ void vm_fluid_species_prim_vars(gkyl_vlasov_app *app, struct vm_fluid_species *f * @param fluid_species Pointer to fluid species (where primitive variables are stored) * @param fluid Input (and Output after limiting) array fluid species */ -void vm_fluid_species_limiter(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, - struct gkyl_array *fluid); +void vm_fluid_species_limiter( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, struct gkyl_array *fluid +); /** * Compute RHS from fluid species equations @@ -1634,9 +1713,10 @@ void vm_fluid_species_limiter(gkyl_vlasov_app *app, struct vm_fluid_species *flu * @param rhs On output, the RHS from the fluid species solver * @return Maximum stable time-step */ -double vm_fluid_species_rhs(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, - const struct gkyl_array *fluid, const struct gkyl_array *em, - struct gkyl_array *rhs); +double vm_fluid_species_rhs( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, const struct gkyl_array *fluid, + const struct gkyl_array *em, struct gkyl_array *rhs +); /** * Apply BCs to fluid species @@ -1645,7 +1725,9 @@ double vm_fluid_species_rhs(gkyl_vlasov_app *app, struct vm_fluid_species *fluid * @param fluid_species Pointer to fluid species * @param f Fluid Species to apply BCs */ -void vm_fluid_species_apply_bc(gkyl_vlasov_app *app, const struct vm_fluid_species *fluid_species, struct gkyl_array *f); +void vm_fluid_species_apply_bc( + gkyl_vlasov_app *app, const struct vm_fluid_species *fluid_species, struct gkyl_array *f +); /** * Computed the integrated quantities for the fluid system. @@ -1654,7 +1736,9 @@ void vm_fluid_species_apply_bc(gkyl_vlasov_app *app, const struct vm_fluid_speci * @param fluid_species Pointer to fluid species * @param tm Time integrated quantities are being computed at. */ -void vm_fluid_species_calc_integrated_mom(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm); +void vm_fluid_species_calc_integrated_mom( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm +); /** * Write out the evolved fluid species and other potential primitive/auxiliary variables. @@ -1664,7 +1748,9 @@ void vm_fluid_species_calc_integrated_mom(gkyl_vlasov_app *app, struct vm_fluid_ * @param tm Time fluid quantities are being written at. * @param frame Frame number for I/O. */ -void vm_fluid_species_write(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm, int frame); +void vm_fluid_species_write( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm, int frame +); /** * Release resources allocated by fluid species @@ -1672,7 +1758,7 @@ void vm_fluid_species_write(gkyl_vlasov_app *app, struct vm_fluid_species *fluid * @param app Vlasov app object * @param f Fluid_Species object to release */ -void vm_fluid_species_release(const gkyl_vlasov_app* app, struct vm_fluid_species *f); +void vm_fluid_species_release(const gkyl_vlasov_app *app, struct vm_fluid_species *f); /** vm_fluid_em_coupling API */ @@ -1682,7 +1768,7 @@ void vm_fluid_species_release(const gkyl_vlasov_app* app, struct vm_fluid_specie * @param app Vlasov app object * @return Newly created fluid-EM coupling updater */ -struct vm_fluid_em_coupling* vm_fluid_em_coupling_init(struct gkyl_vlasov_app *app); +struct vm_fluid_em_coupling *vm_fluid_em_coupling_init(struct gkyl_vlasov_app *app); /** * Compute implicit update of fluid-EM coupling @@ -1692,8 +1778,9 @@ struct vm_fluid_em_coupling* vm_fluid_em_coupling_init(struct gkyl_vlasov_app *a * @param tcurr Current time * @param dt Time step size */ -void vm_fluid_em_coupling_update(struct gkyl_vlasov_app *app, - struct vm_fluid_em_coupling *fl_em, double tcurr, double dt); +void vm_fluid_em_coupling_update( + struct gkyl_vlasov_app *app, struct vm_fluid_em_coupling *fl_em, double tcurr, double dt +); /** * Release resources allocated by fluid-EM coupling object @@ -1701,5 +1788,4 @@ void vm_fluid_em_coupling_update(struct gkyl_vlasov_app *app, * @param app Vlasov app object * @param fl_em fluid-EM coupling updater to release */ -void vm_fluid_em_coupling_release(struct gkyl_vlasov_app *app, - struct vm_fluid_em_coupling *fl_em); +void vm_fluid_em_coupling_release(struct gkyl_vlasov_app *app, struct vm_fluid_em_coupling *fl_em); diff --git a/vlasov/apps/vlasov.c b/vlasov/apps/vlasov.c index b5f8896209..a53e68363e 100644 --- a/vlasov/apps/vlasov.c +++ b/vlasov/apps/vlasov.c @@ -15,8 +15,7 @@ #include // returned gkyl_array_meta must be freed using vlasov_array_meta_release -struct gkyl_msgpack_data* -vlasov_array_meta_new(struct vlasov_output_meta meta) +struct gkyl_msgpack_data *vlasov_array_meta_new(struct vlasov_output_meta meta) { struct gkyl_msgpack_data *mt = gkyl_malloc(sizeof(*mt)); @@ -26,7 +25,7 @@ vlasov_array_meta_new(struct vlasov_output_meta meta) // add some data to mpack mpack_build_map(&writer); - + mpack_write_cstr(&writer, "time"); mpack_write_double(&writer, meta.stime); @@ -52,18 +51,18 @@ vlasov_array_meta_new(struct vlasov_output_meta meta) return mt; } -void -vlasov_array_meta_release(struct gkyl_msgpack_data *mt) +void vlasov_array_meta_release(struct gkyl_msgpack_data *mt) { - if (!mt) return; + if (!mt) { + return; + } MPACK_FREE(mt->meta); gkyl_free(mt); } -struct vlasov_output_meta -vlasov_meta_from_mpack(struct gkyl_msgpack_data *mt) +struct vlasov_output_meta vlasov_meta_from_mpack(struct gkyl_msgpack_data *mt) { - struct vlasov_output_meta meta = { .frame = 0, .stime = 0.0 }; + struct vlasov_output_meta meta = {.frame = 0, .stime = 0.0}; if (mt->meta_sz > 0) { mpack_tree_t tree; @@ -91,8 +90,7 @@ vlasov_meta_from_mpack(struct gkyl_msgpack_data *mt) return meta; } -gkyl_vlasov_app* -gkyl_vlasov_app_new(struct gkyl_vm *vm) +gkyl_vlasov_app *gkyl_vlasov_app_new(struct gkyl_vm *vm) { disable_denorm_float(); @@ -102,7 +100,7 @@ gkyl_vlasov_app_new(struct gkyl_vm *vm) int cdim = app->cdim = vm->cdim; int vdim = app->vdim = vm->vdim; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int poly_order = app->poly_order = vm->poly_order; int ns = app->num_species = vm->num_species; int nsf = app->num_fluid_species = vm->num_fluid_species; @@ -117,8 +115,9 @@ gkyl_vlasov_app_new(struct gkyl_vm *vm) #endif app->num_periodic_dir = vm->num_periodic_dir; - for (int d=0; dperiodic_dirs[d] = vm->periodic_dirs[d]; + } strcpy(app->name, vm->name); app->tcurr = 0.0; // reset on init @@ -127,80 +126,73 @@ gkyl_vlasov_app_new(struct gkyl_vm *vm) // allocate device basis if we are using GPUs app->basis_on_dev.basis = gkyl_cu_malloc(sizeof(struct gkyl_basis)); app->basis_on_dev.confBasis = gkyl_cu_malloc(sizeof(struct gkyl_basis)); - } - else { + } else { app->basis_on_dev.basis = &app->basis; app->basis_on_dev.confBasis = &app->confBasis; } // basis functions switch (vm->basis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - gkyl_cart_modal_serendip(&app->confBasis, cdim, poly_order); - if (vdim > 0) { + case GKYL_BASIS_MODAL_SERENDIPITY: + gkyl_cart_modal_serendip(&app->confBasis, cdim, poly_order); + if (vdim > 0) { + if (poly_order == 1) { + /* Force hybrid basis (p=2 in velocity space). */ + gkyl_cart_modal_hybrid(&app->basis, cdim, vdim); + gkyl_cart_modal_serendip(&app->velBasis, vdim, 2); + } else { + gkyl_cart_modal_serendip(&app->basis, pdim, poly_order); + gkyl_cart_modal_serendip(&app->velBasis, vdim, poly_order); + } + } + if (app->use_gpu) { + gkyl_cart_modal_serendip_cu_dev(app->basis_on_dev.confBasis, cdim, poly_order); + if (vdim > 0) { if (poly_order == 1) { /* Force hybrid basis (p=2 in velocity space). */ - gkyl_cart_modal_hybrid(&app->basis, cdim, vdim); - gkyl_cart_modal_serendip(&app->velBasis, vdim, 2); - } - else { - gkyl_cart_modal_serendip(&app->basis, pdim, poly_order); - gkyl_cart_modal_serendip(&app->velBasis, vdim, poly_order); - } - } - if (app->use_gpu) { - gkyl_cart_modal_serendip_cu_dev(app->basis_on_dev.confBasis, cdim, poly_order); - if (vdim > 0) { - if (poly_order == 1) { - /* Force hybrid basis (p=2 in velocity space). */ - gkyl_cart_modal_hybrid_cu_dev(app->basis_on_dev.basis, cdim, vdim); - } - else { - gkyl_cart_modal_serendip_cu_dev(app->basis_on_dev.basis, pdim, poly_order); - } + gkyl_cart_modal_hybrid_cu_dev(app->basis_on_dev.basis, cdim, vdim); + } else { + gkyl_cart_modal_serendip_cu_dev(app->basis_on_dev.basis, pdim, poly_order); } } - break; + } + break; - case GKYL_BASIS_MODAL_TENSOR: - gkyl_cart_modal_tensor(&app->confBasis, cdim, poly_order); + case GKYL_BASIS_MODAL_TENSOR: + gkyl_cart_modal_tensor(&app->confBasis, cdim, poly_order); + if (vdim > 0) { + gkyl_cart_modal_tensor(&app->basis, pdim, poly_order); + gkyl_cart_modal_tensor(&app->velBasis, vdim, poly_order); + } + if (app->use_gpu) { + gkyl_cart_modal_tensor_cu_dev(app->basis_on_dev.confBasis, cdim, poly_order); if (vdim > 0) { - gkyl_cart_modal_tensor(&app->basis, pdim, poly_order); - gkyl_cart_modal_tensor(&app->velBasis, vdim, poly_order); + gkyl_cart_modal_tensor_cu_dev(app->basis_on_dev.basis, pdim, poly_order); } - if (app->use_gpu) { - gkyl_cart_modal_tensor_cu_dev(app->basis_on_dev.confBasis, cdim, poly_order); - if (vdim > 0) { - gkyl_cart_modal_tensor_cu_dev(app->basis_on_dev.basis, pdim, poly_order); - } - } - break; + } + break; - default: - assert(false); - break; + default: + assert(false); + break; } gkyl_rect_grid_init(&app->grid, cdim, vm->lower, vm->upper, vm->cells); - int ghost[] = { 1, 1, 1 }; + int ghost[] = {1, 1, 1}; gkyl_create_grid_ranges(&app->grid, ghost, &app->global_ext, &app->global); if (vm->parallelism.comm == 0) { - int cuts[3] = { 1, 1, 1 }; + int cuts[3] = {1, 1, 1}; app->decomp = gkyl_rect_decomp_new_from_cuts(cdim, cuts, &app->global); - - app->comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .decomp = app->decomp, - .use_gpu = app->use_gpu - } - ); - + + app->comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp + ){.decomp = app->decomp, .use_gpu = app->use_gpu}); + // Global and local ranges are same, and so just copy them. memcpy(&app->local, &app->global, sizeof(struct gkyl_range)); memcpy(&app->local_ext, &app->global_ext, sizeof(struct gkyl_range)); - } - else { + } else { // Create decomp. app->decomp = gkyl_rect_decomp_new_from_cuts(app->cdim, vm->parallelism.cuts, &app->global); @@ -214,14 +206,18 @@ gkyl_vlasov_app_new(struct gkyl_vm *vm) } // local skin and ghost ranges for configuration space fields - for (int dir=0; dirlower_skin[dir], &app->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &app->local_ext, ghost); - gkyl_skin_ghost_ranges(&app->upper_skin[dir], &app->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &app->local_ext, ghost); + for (int dir = 0; dir < cdim; ++dir) { + gkyl_skin_ghost_ranges( + &app->lower_skin[dir], &app->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &app->local_ext, ghost + ); + gkyl_skin_ghost_ranges( + &app->upper_skin[dir], &app->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &app->local_ext, ghost + ); } // Configuration space geometry initialization // Note: *only* uses a p=1 DG representation of the geometry (JJ: 11/24/23) - app->c2p_ctx = app->mapc2p = 0; + app->c2p_ctx = app->mapc2p = 0; app->has_mapc2p = vm->mapc2p ? true : false; if (app->has_mapc2p) { @@ -234,8 +230,9 @@ gkyl_vlasov_app_new(struct gkyl_vm *vm) gkyl_cart_modal_tensor(&basis, cdim, 1); // initialize DG field representing mapping - struct gkyl_array *c2p = mkarr(false, cdim*basis.num_basis, app->local_ext.volume); - gkyl_eval_on_nodes *ev_c2p = gkyl_eval_on_nodes_new(&app->grid, &basis, cdim, vm->mapc2p, vm->c2p_ctx); + struct gkyl_array *c2p = mkarr(false, cdim * basis.num_basis, app->local_ext.volume); + gkyl_eval_on_nodes *ev_c2p = + gkyl_eval_on_nodes_new(&app->grid, &basis, cdim, vm->mapc2p, vm->c2p_ctx); gkyl_eval_on_nodes_advance(ev_c2p, 0.0, &app->local_ext, c2p); // write DG projection of mapc2p to file @@ -248,79 +245,91 @@ gkyl_vlasov_app_new(struct gkyl_vm *vm) } // create geometry object - app->geom = gkyl_wave_geom_new(&app->grid, &app->local_ext, - app->mapc2p, app->c2p_ctx, app->use_gpu); + app->geom = + gkyl_wave_geom_new(&app->grid, &app->local_ext, app->mapc2p, app->c2p_ctx, app->use_gpu); app->has_field = !vm->skip_field; // note inversion of truth value if (app->has_field) { if (vm->is_electrostatic) { app->field = vp_field_new(vm, app); app->field_energy_calc = vp_field_calc_energy; - } - else { + } else { app->field = vm_field_new(vm, app); app->field_energy_calc = vm_field_calc_energy; } } // allocate space to store species objects - app->species = ns>0 ? gkyl_malloc(sizeof(struct vm_species[ns])) : 0; - for (int i=0; ispecies[i] = (struct vm_species) { }; + app->species = ns > 0 ? gkyl_malloc(sizeof(struct vm_species[ns])) : 0; + for (int i = 0; i < ns; ++i) { + app->species[i] = (struct vm_species){}; + } // set info for each species: this needs to be done here as we need // to access species name from vm_species_init - for (int i=0; ispecies[i].info = vm->species[i]; + } // allocate space to store fluid species objects - app->fluid_species = nsf>0 ? gkyl_malloc(sizeof(struct vm_fluid_species[nsf])) : 0; + app->fluid_species = nsf > 0 ? gkyl_malloc(sizeof(struct vm_fluid_species[nsf])) : 0; // set info for each fluid species: this needs to be done here as we // need to access species name from vm_fluid_species_init - for (int i=0; ifluid_species[i].info = vm->fluid_species[i]; + } // initialize each species - for (int i=0; ispecies[i]); + } // initialize species wall emission terms: these rely // on other species which must be allocated in the previous step - for (int i=0; ispecies[i].emit_lo) + for (int i = 0; i < ns; ++i) { + if (app->species[i].emit_lo) { vm_species_emission_cross_init(app, &app->species[i], &app->species[i].bc_emission_lo); - if (app->species[i].emit_up) + } + if (app->species[i].emit_up) { vm_species_emission_cross_init(app, &app->species[i], &app->species[i].bc_emission_up); + } } - + // initialize each species cross-species terms: this has to be done here // as need pointers to colliding species' collision objects // allocated in the previous step - for (int i=0; ispecies[i].collision_id == GKYL_LBO_COLLISIONS && - app->species[i].lbo.num_cross_collisions) + app->species[i].lbo.num_cross_collisions) { vm_species_lbo_cross_init(app, &app->species[i], &app->species[i].lbo); + } + } // initialize each species source terms: this has to be done here // as they may initialize a bflux updater for their source species. // initialize each species source terms - for (int i=0; ispecies[i].source_id) + for (int i = 0; i < ns; ++i) { + if (app->species[i].source_id) { vm_species_source_init(app, &app->species[i], &app->species[i].src); + } + } // initialize each fluid species // Fluid species must be initialized after kinetic species, as some fluid species couple // to kinetic species and pointers are allocated by the kinetic species objects - for (int i=0; ifluid_species[i]); + } - for (int i=0; ifluid_species[i].source_id) + for (int i = 0; i < nsf; ++i) { + if (app->fluid_species[i].source_id) { vm_fluid_species_source_init(app, &app->fluid_species[i], &app->fluid_species[i].src); + } + } - // Check if there are both any fluid species and an EM field. + // Check if there are both any fluid species and an EM field. // If there are, initialize the implicit fluid-EM coupling solver. app->has_fluid_em_coupling = false; if (nsf > 0 && app->has_field) { @@ -330,94 +339,94 @@ gkyl_vlasov_app_new(struct gkyl_vm *vm) // Use implicit BGK collisions if specified app->has_implicit_coll_scheme = false; - for (int i=0; ispecies[i].collisions.has_implicit_coll_scheme){ + for (int i = 0; i < ns; ++i) { + if (vm->species[i].collisions.has_implicit_coll_scheme) { app->has_implicit_coll_scheme = true; } } // Set the appropriate update function for taking a single time step - // If we have implicit fluid-EM coupling or implicit BGK collisions, + // If we have implicit fluid-EM coupling or implicit BGK collisions, // we perform a first-order operator split and treat those terms implicitly. - // Otherwise, we default to an SSP-RK3 method. + // Otherwise, we default to an SSP-RK3 method. if (vm->is_electrostatic) { app->update_func = vlasov_poisson_update_ssp_rk3; app->field_calc_ext_em = vp_field_calc_ext_em; - } - else { + } else { if (app->has_implicit_coll_scheme || app->has_fluid_em_coupling) { app->update_func = vlasov_update_op_split; - } - else { + } else { app->update_func = vlasov_update_ssp_rk3; } app->field_calc_ext_em = vm_field_calc_ext_em; } // initialize stat object - app->stat = (struct gkyl_vlasov_stat) { - .use_gpu = app->use_gpu, - .stage_2_dt_diff = { DBL_MAX, 0.0 }, - .stage_3_dt_diff = { DBL_MAX, 0.0 }, - }; + app->stat = (struct gkyl_vlasov_stat + ){.use_gpu = app->use_gpu, .stage_2_dt_diff = {DBL_MAX, 0.0}, .stage_3_dt_diff = {DBL_MAX, 0.0}}; return app; } -struct vm_species * -vm_find_species(const gkyl_vlasov_app *app, const char *nm) +struct vm_species *vm_find_species(const gkyl_vlasov_app *app, const char *nm) { - for (int i=0; inum_species; ++i) - if (strcmp(nm, app->species[i].info.name) == 0) + for (int i = 0; i < app->num_species; ++i) { + if (strcmp(nm, app->species[i].info.name) == 0) { return &app->species[i]; + } + } return 0; } -int -vm_find_species_idx(const gkyl_vlasov_app *app, const char *nm) +int vm_find_species_idx(const gkyl_vlasov_app *app, const char *nm) { - for (int i=0; inum_species; ++i) - if (strcmp(nm, app->species[i].info.name) == 0) + for (int i = 0; i < app->num_species; ++i) { + if (strcmp(nm, app->species[i].info.name) == 0) { return i; + } + } return -1; } -struct vm_fluid_species * -vm_find_fluid_species(const gkyl_vlasov_app *app, const char *nm) +struct vm_fluid_species *vm_find_fluid_species(const gkyl_vlasov_app *app, const char *nm) { - for (int i=0; inum_fluid_species; ++i) - if (strcmp(nm, app->fluid_species[i].info.name) == 0) + for (int i = 0; i < app->num_fluid_species; ++i) { + if (strcmp(nm, app->fluid_species[i].info.name) == 0) { return &app->fluid_species[i]; + } + } return 0; } -int -vm_find_fluid_species_idx(const gkyl_vlasov_app *app, const char *nm) +int vm_find_fluid_species_idx(const gkyl_vlasov_app *app, const char *nm) { - for (int i=0; inum_fluid_species; ++i) - if (strcmp(nm, app->fluid_species[i].info.name) == 0) + for (int i = 0; i < app->num_fluid_species; ++i) { + if (strcmp(nm, app->fluid_species[i].info.name) == 0) { return i; + } + } return -1; } -void -vm_apply_bc(gkyl_vlasov_app* app, double tcurr, - struct gkyl_array *distf[], struct gkyl_array *fluid[], struct gkyl_array *emfield) +void vm_apply_bc( + gkyl_vlasov_app *app, double tcurr, struct gkyl_array *distf[], struct gkyl_array *fluid[], + struct gkyl_array *emfield +) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { vm_species_apply_bc(app, &app->species[i], distf[i], tcurr); } - for (int i=0; inum_fluid_species; ++i) { + for (int i = 0; i < app->num_fluid_species; ++i) { vm_fluid_species_apply_bc(app, &app->fluid_species[i], fluid[i]); } if (app->has_field) { - if (app->field->field_id == GKYL_FIELD_E_B) + if (app->field->field_id == GKYL_FIELD_E_B) { vm_field_apply_bc(app, app->field, emfield); + } } } -void -vp_calc_field(gkyl_vlasov_app* app, double tcurr, const struct gkyl_array *fin[]) +void vp_calc_field(gkyl_vlasov_app *app, double tcurr, const struct gkyl_array *fin[]) { // Compute electrostatic potential from Poisson's equation. vp_field_accumulate_charge_dens(app, app->field, fin); @@ -426,66 +435,68 @@ vp_calc_field(gkyl_vlasov_app* app, double tcurr, const struct gkyl_array *fin[] vp_field_solve(app, app->field); } -void -vp_calc_field_and_apply_bc(gkyl_vlasov_app* app, double tcurr, struct gkyl_array *distf[]) +void vp_calc_field_and_apply_bc(gkyl_vlasov_app *app, double tcurr, struct gkyl_array *distf[]) { // Compute the field. // MF 2024/09/27/: Need the cast here for consistency. Fixing // this may require removing 'const' from a lot of places. - vp_calc_field(app, tcurr, (const struct gkyl_array **) distf); + vp_calc_field(app, tcurr, (const struct gkyl_array **)distf); // Apply boundary conditions. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { vm_species_apply_bc(app, &app->species[i], distf[i], tcurr); } } -void -gkyl_vlasov_app_apply_ic(gkyl_vlasov_app* app, double t0) +void gkyl_vlasov_app_apply_ic(gkyl_vlasov_app *app, double t0) { app->tcurr = t0; - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { gkyl_vlasov_app_apply_ic_species(app, i, t0); + } - for (int i=0; inum_fluid_species; ++i) + for (int i = 0; i < app->num_fluid_species; ++i) { gkyl_vlasov_app_apply_ic_fluid_species(app, i, t0); + } - if (app->has_field) + if (app->has_field) { gkyl_vlasov_app_apply_ic_field(app, t0); + } struct gkyl_array *distf[app->num_species]; struct gkyl_array *fluid[app->num_fluid_species]; - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { distf[i] = app->species[i].f; - for (int i=0; inum_fluid_species; ++i) + } + for (int i = 0; i < app->num_fluid_species; ++i) { fluid[i] = app->fluid_species[i].fluid; + } // BCs must be done after all species initialize for emission BCs to work. vm_apply_bc(app, t0, distf, fluid, app->has_field ? app->field->em : 0); } -void -gkyl_vlasov_app_apply_ic_field(gkyl_vlasov_app* app, double t0) +void gkyl_vlasov_app_apply_ic_field(gkyl_vlasov_app *app, double t0) { app->tcurr = t0; struct timespec wtm = gkyl_wall_clock(); - if (app->field->field_id == GKYL_FIELD_E_B) + if (app->field->field_id == GKYL_FIELD_E_B) { vm_field_apply_ic(app, app->field, t0); - else if (app->field->field_id != GKYL_FIELD_NULL) { + } else if (app->field->field_id != GKYL_FIELD_NULL) { struct gkyl_array *distf[app->num_species]; - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { distf[i] = app->species[i].f; + } // MF 2024/09/27/: Need the cast here for consistency. Fixing // this may require removing 'const' from a lot of places. - vp_field_apply_ic(app, app->field, (const struct gkyl_array **) distf, t0); + vp_field_apply_ic(app, app->field, (const struct gkyl_array **)distf, t0); } app->stat.init_field_tm += gkyl_time_diff_now_sec(wtm); } -void -gkyl_vlasov_app_apply_ic_species(gkyl_vlasov_app* app, int sidx, double t0) +void gkyl_vlasov_app_apply_ic_species(gkyl_vlasov_app *app, int sidx, double t0) { assert(sidx < app->num_species); @@ -495,8 +506,7 @@ gkyl_vlasov_app_apply_ic_species(gkyl_vlasov_app* app, int sidx, double t0) app->stat.init_species_tm += gkyl_time_diff_now_sec(wtm); } -void -gkyl_vlasov_app_apply_ic_fluid_species(gkyl_vlasov_app* app, int sidx, double t0) +void gkyl_vlasov_app_apply_ic_fluid_species(gkyl_vlasov_app *app, int sidx, double t0) { assert(sidx < app->num_fluid_species); @@ -506,13 +516,12 @@ gkyl_vlasov_app_apply_ic_fluid_species(gkyl_vlasov_app* app, int sidx, double t0 app->stat.init_fluid_species_tm += gkyl_time_diff_now_sec(wtm); } -void -gkyl_vlasov_app_calc_mom(gkyl_vlasov_app* app) +void gkyl_vlasov_app_calc_mom(gkyl_vlasov_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct vm_species *vm_s = &app->species[i]; - for (int m=0; minfo.num_diag_moments; ++m) { + for (int m = 0; m < vm_s->info.num_diag_moments; ++m) { struct timespec wst = gkyl_wall_clock(); vm_species_moment_calc(&vm_s->moms[m], vm_s->local, app->local, vm_s->f); app->stat.mom_tm += gkyl_time_diff_now_sec(wst); @@ -521,15 +530,14 @@ gkyl_vlasov_app_calc_mom(gkyl_vlasov_app* app) } } -void -gkyl_vlasov_app_calc_integrated_mom(gkyl_vlasov_app* app, double tm) +void gkyl_vlasov_app_calc_integrated_mom(gkyl_vlasov_app *app, double tm) { int vdim = app->vdim; - double avals[2+vdim], avals_global[2+vdim]; + double avals[2 + vdim], avals_global[2 + vdim]; struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct vm_species *vm_s = &app->species[i]; struct timespec wst = gkyl_wall_clock(); @@ -538,26 +546,28 @@ gkyl_vlasov_app_calc_integrated_mom(gkyl_vlasov_app* app, double tm) // reduce to compute sum over whole domain, append to diagnostics if (app->use_gpu) { gkyl_array_reduce_range(vm_s->red_integ_diag, vm_s->integ_moms.marr, GKYL_SUM, &app->local); - gkyl_cu_memcpy(avals, vm_s->red_integ_diag, sizeof(double[2+vdim]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy(avals, vm_s->red_integ_diag, sizeof(double[2 + vdim]), GKYL_CU_MEMCPY_D2H); + } else { gkyl_array_reduce_range(avals, vm_s->integ_moms.marr_host, GKYL_SUM, &app->local); } - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 2+vdim, avals, avals_global); + gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 2 + vdim, avals, avals_global); gkyl_dynvec_append(vm_s->integ_diag, tm, avals_global); if (vm_s->source_id) { - vm_species_moment_calc(&vm_s->src.integ_moms, vm_s->local, app->local, vm_s->src.source); + vm_species_moment_calc(&vm_s->src.integ_moms, vm_s->local, app->local, vm_s->src.source); // reduce to compute sum over whole domain, append to diagnostics if (app->use_gpu) { - gkyl_array_reduce_range(vm_s->src.red_integ_diag, vm_s->src.integ_moms.marr, GKYL_SUM, &app->local); - gkyl_cu_memcpy(avals, vm_s->src.red_integ_diag, sizeof(double[2+vdim]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_array_reduce_range( + vm_s->src.red_integ_diag, vm_s->src.integ_moms.marr, GKYL_SUM, &app->local + ); + gkyl_cu_memcpy( + avals, vm_s->src.red_integ_diag, sizeof(double[2 + vdim]), GKYL_CU_MEMCPY_D2H + ); + } else { gkyl_array_reduce_range(avals, vm_s->integ_moms.marr_host, GKYL_SUM, &app->local); } - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 2+vdim, avals, avals_global); + gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 2 + vdim, avals, avals_global); gkyl_dynvec_append(vm_s->src.integ_diag, tm, avals_global); } @@ -565,20 +575,19 @@ gkyl_vlasov_app_calc_integrated_mom(gkyl_vlasov_app* app, double tm) app->stat.n_mom += 1; } - for (int i=0; inum_fluid_species; ++i) { + for (int i = 0; i < app->num_fluid_species; ++i) { struct vm_fluid_species *f = &app->fluid_species[i]; - vm_fluid_species_calc_integrated_mom(app, f, tm); + vm_fluid_species_calc_integrated_mom(app, f, tm); } app->stat.diag_tm += gkyl_time_diff_now_sec(wst); app->stat.n_diag += 1; } -void -gkyl_vlasov_app_calc_integrated_L2_f(gkyl_vlasov_app* app, double tm) +void gkyl_vlasov_app_calc_integrated_L2_f(gkyl_vlasov_app *app, double tm) { struct timespec wst = gkyl_wall_clock(); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct vm_species *vm_s = &app->species[i]; vm_species_calc_L2(app, tm, vm_s); } @@ -586,8 +595,7 @@ gkyl_vlasov_app_calc_integrated_L2_f(gkyl_vlasov_app* app, double tm) app->stat.n_diag += 1; } -void -gkyl_vlasov_app_calc_field_energy(gkyl_vlasov_app* app, double tm) +void gkyl_vlasov_app_calc_field_energy(gkyl_vlasov_app *app, double tm) { if (app->has_field) { struct timespec wst = gkyl_wall_clock(); @@ -597,54 +605,48 @@ gkyl_vlasov_app_calc_field_energy(gkyl_vlasov_app* app, double tm) } } -void -gkyl_vlasov_app_write(gkyl_vlasov_app* app, double tm, int frame) +void gkyl_vlasov_app_write(gkyl_vlasov_app *app, double tm, int frame) { app->stat.n_io += 1; struct timespec wtm = gkyl_wall_clock(); - - if (app->has_field) + + if (app->has_field) { gkyl_vlasov_app_write_field(app, tm, frame); - for (int i=0; inum_species; ++i) { + } + for (int i = 0; i < app->num_species; ++i) { gkyl_vlasov_app_write_species(app, i, tm, frame); if (app->species[i].info.output_f_lte) { gkyl_vlasov_app_write_species_lte(app, i, tm, frame); } } - for (int i=0; inum_fluid_species; ++i) { + for (int i = 0; i < app->num_fluid_species; ++i) { gkyl_vlasov_app_write_fluid_species(app, i, tm, frame); } app->stat.io_tm += gkyl_time_diff_now_sec(wtm); } -void -gkyl_vlasov_app_write_field(gkyl_vlasov_app* app, double tm, int frame) +void gkyl_vlasov_app_write_field(gkyl_vlasov_app *app, double tm, int frame) { - struct gkyl_msgpack_data *mt = vlasov_array_meta_new( (struct vlasov_output_meta) { - .frame = frame, - .stime = tm, - .poly_order = app->poly_order, - .basis_type = app->confBasis.id - } - ); - + struct gkyl_msgpack_data *mt = vlasov_array_meta_new((struct vlasov_output_meta + ){.frame = frame, .stime = tm, .poly_order = app->poly_order, .basis_type = app->confBasis.id}); + const char *fmt = "%s-field_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, frame); struct gkyl_array *fld, *fld_host; if (app->field->field_id == GKYL_FIELD_E_B) { fld = app->field->em; fld_host = app->field->em_host; - } - else { + } else { fld = app->field->phi; fld_host = app->field->phi_host; } - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(fld_host, fld); // copy data from device before writing it. + } gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, fld_host, fileNm); if (app->field->has_ext_em) { @@ -652,14 +654,15 @@ gkyl_vlasov_app_write_field(gkyl_vlasov_app* app, double tm, int frame) if (frame == 0 || app->field->ext_em_evolve) { const char *fmt_ext_em = "%s-field_ext_em_%d.gkyl"; int sz_ext_em = gkyl_calc_strlen(fmt_ext_em, app->name, frame); - char fileNm_ext_em[sz_ext_em+1]; // ensures no buffer overflow + char fileNm_ext_em[sz_ext_em + 1]; // ensures no buffer overflow snprintf(fileNm_ext_em, sizeof fileNm_ext_em, fmt_ext_em, app->name, frame); - // External EM field computed with project on basis, so just use host copy + // External EM field computed with project on basis, so just use host copy vm_field_calc_ext_em(app, app->field, tm); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, app->field->ext_em_host, fileNm_ext_em); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, app->field->ext_em_host, fileNm_ext_em + ); } } if (app->field->has_app_current) { @@ -667,170 +670,159 @@ gkyl_vlasov_app_write_field(gkyl_vlasov_app* app, double tm, int frame) if (frame == 0 || app->field->app_current_evolve) { const char *fmt_app_current = "%s-field_app_current_%d.gkyl"; int sz_app_current = gkyl_calc_strlen(fmt_app_current, app->name, frame); - char fileNm_app_current[sz_app_current+1]; // ensures no buffer overflow + char fileNm_app_current[sz_app_current + 1]; // ensures no buffer overflow snprintf(fileNm_app_current, sizeof fileNm_app_current, fmt_app_current, app->name, frame); - // External EM field computed with project on basis, so just use host copy + // External EM field computed with project on basis, so just use host copy vm_field_calc_app_current(app, app->field, tm); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, app->field->app_current_host, fileNm_app_current); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, app->field->app_current_host, fileNm_app_current + ); } - } + } if (app->field->has_ext_pot) { if (frame == 0 || app->field->ext_pot_evolve) { const char *fmt_ext_pot = "%s-field_ext_pot_%d.gkyl"; int sz_ext_pot = gkyl_calc_strlen(fmt_ext_pot, app->name, frame); - char fileNm_ext_pot[sz_ext_pot+1]; // ensures no buffer overflow + char fileNm_ext_pot[sz_ext_pot + 1]; // ensures no buffer overflow snprintf(fileNm_ext_pot, sizeof fileNm_ext_pot, fmt_ext_pot, app->name, frame); - // External EM field computed with project on basis, so just use host copy + // External EM field computed with project on basis, so just use host copy vp_field_calc_ext_pot(app, app->field, tm); - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, app->field->ext_pot_host, fileNm_ext_pot); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, app->field->ext_pot_host, fileNm_ext_pot + ); } } - vlasov_array_meta_release(mt); + vlasov_array_meta_release(mt); } -void -gkyl_vlasov_app_write_species(gkyl_vlasov_app* app, int sidx, double tm, int frame) +void gkyl_vlasov_app_write_species(gkyl_vlasov_app *app, int sidx, double tm, int frame) { - struct gkyl_msgpack_data *mt = vlasov_array_meta_new( (struct vlasov_output_meta) { - .frame = frame, - .stime = tm, - .poly_order = app->poly_order, - .basis_type = app->basis.id - } - ); - + struct gkyl_msgpack_data *mt = vlasov_array_meta_new((struct vlasov_output_meta + ){.frame = frame, .stime = tm, .poly_order = app->poly_order, .basis_type = app->basis.id}); + struct vm_species *vm_s = &app->species[sidx]; const char *fmt = "%s-%s_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, vm_s->info.name, frame); if (app->use_gpu) { // copy data from device to host before writing it out gkyl_array_copy(vm_s->f_host, vm_s->f); } - gkyl_comm_array_write(vm_s->comm, &vm_s->grid, &vm_s->local, - mt, vm_s->f_host, fileNm); + gkyl_comm_array_write(vm_s->comm, &vm_s->grid, &vm_s->local, mt, vm_s->f_host, fileNm); if (vm_s->source_id) { if (vm_s->src.write_source) { // Write out the source distribution function const char *fmt_source = "%s-%s_source_%d.gkyl"; int sz_source = gkyl_calc_strlen(fmt_source, app->name, vm_s->info.name, frame); - char fileNm_source[sz_source+1]; // ensures no buffer overflow + char fileNm_source[sz_source + 1]; // ensures no buffer overflow snprintf(fileNm_source, sizeof fileNm_source, fmt_source, app->name, vm_s->info.name, frame); // copy data from device to host before writing it out if (app->use_gpu) { gkyl_array_copy(vm_s->src.source_host, vm_s->src.source); } - gkyl_comm_array_write(vm_s->comm, &vm_s->grid, &vm_s->local, - mt, vm_s->src.source_host, fileNm); + gkyl_comm_array_write( + vm_s->comm, &vm_s->grid, &vm_s->local, mt, vm_s->src.source_host, fileNm + ); } } - if (app->species[sidx].emit_lo) + if (app->species[sidx].emit_lo) { vm_species_emission_write(app, vm_s, &vm_s->bc_emission_lo, mt, frame); - if (app->species[sidx].emit_up) + } + if (app->species[sidx].emit_up) { vm_species_emission_write(app, vm_s, &vm_s->bc_emission_up, mt, frame); + } - vlasov_array_meta_release(mt); + vlasov_array_meta_release(mt); } -void -gkyl_vlasov_app_write_species_lte(gkyl_vlasov_app* app, int sidx, double tm, int frame) +void gkyl_vlasov_app_write_species_lte(gkyl_vlasov_app *app, int sidx, double tm, int frame) { - struct gkyl_msgpack_data *mt = vlasov_array_meta_new( (struct vlasov_output_meta) { - .frame = frame, - .stime = tm, - .poly_order = app->poly_order, - .basis_type = app->basis.id - } - ); + struct gkyl_msgpack_data *mt = vlasov_array_meta_new((struct vlasov_output_meta + ){.frame = frame, .stime = tm, .poly_order = app->poly_order, .basis_type = app->basis.id}); struct vm_species *vm_s = &app->species[sidx]; const char *fmt = "%s-%s_%d_lte.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, vm_s->info.name, frame); vm_species_lte(app, vm_s, &vm_s->lte, vm_s->f); - + // copy data from device to host before writing it out - // Just re-use f_host host-side array to avoid allocating - // more distribution function-size arrays. + // Just re-use f_host host-side array to avoid allocating + // more distribution function-size arrays. if (app->use_gpu) { // copy data from device to host before writing it out gkyl_array_copy(vm_s->f_host, vm_s->lte.f_lte); - gkyl_comm_array_write(vm_s->comm, &vm_s->grid, &vm_s->local, - mt, vm_s->f_host, fileNm); - } - else { - gkyl_comm_array_write(vm_s->comm, &vm_s->grid, &vm_s->local, - mt, vm_s->lte.f_lte, fileNm); + gkyl_comm_array_write(vm_s->comm, &vm_s->grid, &vm_s->local, mt, vm_s->f_host, fileNm); + } else { + gkyl_comm_array_write(vm_s->comm, &vm_s->grid, &vm_s->local, mt, vm_s->lte.f_lte, fileNm); } - vlasov_array_meta_release(mt); + vlasov_array_meta_release(mt); } -void -gkyl_vlasov_app_write_fluid_species(gkyl_vlasov_app* app, int sidx, double tm, int frame) +void gkyl_vlasov_app_write_fluid_species(gkyl_vlasov_app *app, int sidx, double tm, int frame) { struct vm_fluid_species *vm_fs = &app->fluid_species[sidx]; - vm_fluid_species_write(app, vm_fs, tm, frame); + vm_fluid_species_write(app, vm_fs, tm, frame); } -void -gkyl_vlasov_app_write_mom(gkyl_vlasov_app* app, double tm, int frame) +void gkyl_vlasov_app_write_mom(gkyl_vlasov_app *app, double tm, int frame) { - struct gkyl_msgpack_data *mt = vlasov_array_meta_new( (struct vlasov_output_meta) { - .frame = frame, - .stime = tm, - .poly_order = app->poly_order, - .basis_type = app->confBasis.id - } - ); - - for (int i=0; inum_species; ++i) { - struct vm_species *vm_s = &app->species[i]; + struct gkyl_msgpack_data *mt = vlasov_array_meta_new((struct vlasov_output_meta + ){.frame = frame, .stime = tm, .poly_order = app->poly_order, .basis_type = app->confBasis.id}); - for (int m=0; minfo.num_diag_moments; ++m) { + for (int i = 0; i < app->num_species; ++i) { + struct vm_species *vm_s = &app->species[i]; + for (int m = 0; m < vm_s->info.num_diag_moments; ++m) { const char *fmt = "%s-%s_%s_%d.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, - gkyl_distribution_moments_strs[vm_s->info.diag_moments[m]], frame); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, vm_s->info.name, - gkyl_distribution_moments_strs[vm_s->info.diag_moments[m]], frame); + int sz = gkyl_calc_strlen( + fmt, app->name, vm_s->info.name, gkyl_distribution_moments_strs[vm_s->info.diag_moments[m]], + frame + ); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf( + fileNm, sizeof fileNm, fmt, app->name, vm_s->info.name, + gkyl_distribution_moments_strs[vm_s->info.diag_moments[m]], frame + ); if (app->use_gpu) { gkyl_array_copy(vm_s->moms[m].marr_host, vm_s->moms[m].marr); } - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, vm_s->moms[m].marr_host, fileNm); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, vm_s->moms[m].marr_host, fileNm); if (vm_s->source_id) { if (vm_s->src.write_source) { const char *fmt_source = "%s-%s_source_%s_%d.gkyl"; - int sz_source = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, - gkyl_distribution_moments_strs[vm_s->info.diag_moments[m]], frame); - char fileNm_source[sz_source+1]; // ensures no buffer overflow - snprintf(fileNm_source, sizeof fileNm_source, fmt_source, app->name, vm_s->info.name, - gkyl_distribution_moments_strs[vm_s->info.diag_moments[m]], frame); + int sz_source = gkyl_calc_strlen( + fmt, app->name, vm_s->info.name, + gkyl_distribution_moments_strs[vm_s->info.diag_moments[m]], frame + ); + char fileNm_source[sz_source + 1]; // ensures no buffer overflow + snprintf( + fileNm_source, sizeof fileNm_source, fmt_source, app->name, vm_s->info.name, + gkyl_distribution_moments_strs[vm_s->info.diag_moments[m]], frame + ); if (app->use_gpu) { gkyl_array_copy(vm_s->src.moms[m].marr_host, vm_s->src.moms[m].marr); } - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, vm_s->src.moms[m].marr_host, fileNm_source); + gkyl_comm_array_write( + app->comm, &app->grid, &app->local, mt, vm_s->src.moms[m].marr_host, fileNm_source + ); } } } @@ -839,10 +831,9 @@ gkyl_vlasov_app_write_mom(gkyl_vlasov_app* app, double tm, int frame) vlasov_array_meta_release(mt); } -void -gkyl_vlasov_app_write_integrated_mom(gkyl_vlasov_app *app) +void gkyl_vlasov_app_write_integrated_mom(gkyl_vlasov_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct vm_species *vm_s = &app->species[i]; int rank; @@ -850,53 +841,48 @@ gkyl_vlasov_app_write_integrated_mom(gkyl_vlasov_app *app) if (rank == 0) { // write out integrated diagnostic moments const char *fmt = "%s-%s-%s.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, - "imom"); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, vm_s->info.name, - "imom"); + int sz = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, "imom"); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf(fileNm, sizeof fileNm, fmt, app->name, vm_s->info.name, "imom"); if (vm_s->is_first_integ_write_call) { gkyl_dynvec_write(vm_s->integ_diag, fileNm); vm_s->is_first_integ_write_call = false; - } - else { + } else { gkyl_dynvec_awrite(vm_s->integ_diag, fileNm); } if (vm_s->source_id) { - if (vm_s->src.write_source) { + if (vm_s->src.write_source) { // write out integrated diagnostic moments from sources const char *fmt_source = "%s-%s-source-%s.gkyl"; - int sz_source = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, - "imom"); - char fileNm_source[sz_source+1]; // ensures no buffer overflow - snprintf(fileNm_source, sizeof fileNm_source, fmt_source, app->name, vm_s->info.name, - "imom"); + int sz_source = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, "imom"); + char fileNm_source[sz_source + 1]; // ensures no buffer overflow + snprintf( + fileNm_source, sizeof fileNm_source, fmt_source, app->name, vm_s->info.name, "imom" + ); if (vm_s->src.is_first_integ_write_call) { gkyl_dynvec_write(vm_s->src.integ_diag, fileNm_source); vm_s->src.is_first_integ_write_call = false; - } - else { + } else { gkyl_dynvec_awrite(vm_s->src.integ_diag, fileNm_source); - } + } } - } + } } gkyl_dynvec_clear(vm_s->integ_diag); if (vm_s->source_id) { - if (vm_s->src.write_source) { + if (vm_s->src.write_source) { gkyl_dynvec_clear(vm_s->src.integ_diag); } } } } -void -gkyl_vlasov_app_write_fluid_integrated_mom(gkyl_vlasov_app *app) +void gkyl_vlasov_app_write_fluid_integrated_mom(gkyl_vlasov_app *app) { - for (int i=0; inum_fluid_species; ++i) { + for (int i = 0; i < app->num_fluid_species; ++i) { struct vm_fluid_species *vm_fs = &app->fluid_species[i]; int rank; @@ -904,28 +890,24 @@ gkyl_vlasov_app_write_fluid_integrated_mom(gkyl_vlasov_app *app) if (rank == 0) { // write out integrated diagnostic moments const char *fmt = "%s-%s-%s.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, vm_fs->info.name, - "imom"); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, vm_fs->info.name, - "imom"); + int sz = gkyl_calc_strlen(fmt, app->name, vm_fs->info.name, "imom"); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf(fileNm, sizeof fileNm, fmt, app->name, vm_fs->info.name, "imom"); if (vm_fs->is_first_integ_write_call) { gkyl_dynvec_write(vm_fs->integ_diag, fileNm); vm_fs->is_first_integ_write_call = false; - } - else { + } else { gkyl_dynvec_awrite(vm_fs->integ_diag, fileNm); - } + } } gkyl_dynvec_clear(vm_fs->integ_diag); } } -void -gkyl_vlasov_app_write_integrated_L2_f(gkyl_vlasov_app* app) +void gkyl_vlasov_app_write_integrated_L2_f(gkyl_vlasov_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct vm_species *vm_s = &app->species[i]; int rank; @@ -933,18 +915,15 @@ gkyl_vlasov_app_write_integrated_L2_f(gkyl_vlasov_app* app) if (rank == 0) { // write out integrated L^2 const char *fmt = "%s-%s-%s.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, - "L2"); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, vm_s->info.name, - "L2"); + int sz = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, "L2"); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf(fileNm, sizeof fileNm, fmt, app->name, vm_s->info.name, "L2"); if (vm_s->is_first_integ_L2_write_call) { // write to a new file (this ensure previous output is removed) gkyl_dynvec_write(vm_s->integ_L2_f, fileNm); vm_s->is_first_integ_L2_write_call = false; - } - else { + } else { // append to existing file gkyl_dynvec_awrite(vm_s->integ_L2_f, fileNm); } @@ -953,14 +932,13 @@ gkyl_vlasov_app_write_integrated_L2_f(gkyl_vlasov_app* app) } } -void -gkyl_vlasov_app_write_field_energy(gkyl_vlasov_app* app) +void gkyl_vlasov_app_write_field_energy(gkyl_vlasov_app *app) { if (app->has_field) { // write out diagnostic moments const char *fmt = "%s-field-energy.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name); int rank; @@ -971,8 +949,7 @@ gkyl_vlasov_app_write_field_energy(gkyl_vlasov_app* app) // write to a new file (this ensure previous output is removed) gkyl_dynvec_write(app->field->integ_energy, fileNm); app->field->is_first_energy_write_call = false; - } - else { + } else { // append to existing file gkyl_dynvec_awrite(app->field->integ_energy, fileNm); } @@ -981,42 +958,36 @@ gkyl_vlasov_app_write_field_energy(gkyl_vlasov_app* app) } } -void -gkyl_vlasov_app_write_lte_corr_status(gkyl_vlasov_app* app) +void gkyl_vlasov_app_write_lte_corr_status(gkyl_vlasov_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct vm_species *vm_s = &app->species[i]; if (vm_s->collision_id == GKYL_BGK_COLLISIONS) { - int rank; gkyl_comm_get_rank(app->comm, &rank); if (rank == 0) { - // write out correction statistics + // write out correction statistics const char *fmt = "%s-%s-%s.gkyl"; - int sz = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, - "corr-lte-stat"); - char fileNm[sz+1]; // ensures no buffer overflow - snprintf(fileNm, sizeof fileNm, fmt, app->name, vm_s->info.name, - "corr-lte-stat"); - + int sz = gkyl_calc_strlen(fmt, app->name, vm_s->info.name, "corr-lte-stat"); + char fileNm[sz + 1]; // ensures no buffer overflow + snprintf(fileNm, sizeof fileNm, fmt, app->name, vm_s->info.name, "corr-lte-stat"); + if (vm_s->bgk.lte.is_first_corr_status_write_call) { // write to a new file (this ensure previous output is removed) gkyl_dynvec_write(vm_s->bgk.lte.corr_stat, fileNm); vm_s->bgk.lte.is_first_corr_status_write_call = false; - } - else { + } else { // append to existing file gkyl_dynvec_awrite(vm_s->bgk.lte.corr_stat, fileNm); } } gkyl_dynvec_clear(vm_s->bgk.lte.corr_stat); } - } + } } -struct gkyl_update_status -gkyl_vlasov_update(gkyl_vlasov_app* app, double dt) +struct gkyl_update_status gkyl_vlasov_update(gkyl_vlasov_app *app, double dt) { app->stat.nup += 1; @@ -1027,13 +998,13 @@ gkyl_vlasov_update(gkyl_vlasov_app* app, double dt) app->stat.total_tm += gkyl_time_diff_now_sec(wst); // Check for any CUDA errors during time step - if (app->use_gpu) + if (app->use_gpu) { checkCuda(cudaGetLastError()); + } return status; } -struct gkyl_vlasov_stat -gkyl_vlasov_app_stat(gkyl_vlasov_app* app) +struct gkyl_vlasov_stat gkyl_vlasov_app_stat(gkyl_vlasov_app *app) { vm_species_coll_tm(app); vm_species_bgk_niter(app); @@ -1042,35 +1013,33 @@ gkyl_vlasov_app_stat(gkyl_vlasov_app* app) return app->stat; } -void -gkyl_vlasov_app_species_ktm_rhs(gkyl_vlasov_app* app, int update_vol_term) +void gkyl_vlasov_app_species_ktm_rhs(gkyl_vlasov_app *app, int update_vol_term) { - for (int i=0; inum_species; ++i) { - + for (int i = 0; i < app->num_species; ++i) { struct vm_species *species = &app->species[i]; const struct gkyl_array *fin = species->f; struct gkyl_array *rhs = species->f1; gkyl_array_clear(rhs, 0.0); - gkyl_dg_updater_vlasov_advance(species->slvr, &species->local, - fin, species->cflrate, rhs); + gkyl_dg_updater_vlasov_advance(species->slvr, &species->local, fin, species->cflrate, rhs); } } static void -range_stat_write(gkyl_vlasov_app* app, const char *nm, const struct gkyl_range *r, FILE *fp) +range_stat_write(gkyl_vlasov_app *app, const char *nm, const struct gkyl_range *r, FILE *fp) { gkyl_vlasov_app_cout(app, fp, " %s_cells : [ ", nm); - for (int i=0; indim; ++i) + for (int i = 0; i < r->ndim; ++i) { gkyl_vlasov_app_cout(app, fp, " %d, ", gkyl_range_shape(r, i)); + } gkyl_vlasov_app_cout(app, fp, " ],\n"); } // ensure stats across processors are made consistent -static void -comm_reduce_app_stat(const gkyl_vlasov_app* app, - const struct gkyl_vlasov_stat *local, struct gkyl_vlasov_stat *global) +static void comm_reduce_app_stat( + const gkyl_vlasov_app *app, const struct gkyl_vlasov_stat *local, struct gkyl_vlasov_stat *global +) { int comm_sz; gkyl_comm_get_size(app->comm, &comm_sz); @@ -1095,29 +1064,46 @@ comm_reduce_app_stat(const gkyl_vlasov_app* app, global->nup = l_red_global[NUP]; global->nfeuler = l_red_global[NFEULER]; global->nstage_2_fail = l_red_global[NSTAGE_2_FAIL]; - global->nstage_3_fail = l_red_global[NSTAGE_3_FAIL]; + global->nstage_3_fail = l_red_global[NSTAGE_3_FAIL]; int64_t l_red_bgk_corr[app->num_species]; - for (int s=0; snum_species; ++s) { + for (int s = 0; s < app->num_species; ++s) { l_red_bgk_corr[s] = local->niter_self_bgk_corr[s]; } int64_t l_red_global_bgk_corr[app->num_species]; - gkyl_comm_allreduce_host(app->comm, GKYL_INT_64, GKYL_MAX, app->num_species, - l_red_bgk_corr, l_red_global_bgk_corr); + gkyl_comm_allreduce_host( + app->comm, GKYL_INT_64, GKYL_MAX, app->num_species, l_red_bgk_corr, l_red_global_bgk_corr + ); - for (int s=0; snum_species; ++s) { + for (int s = 0; s < app->num_species; ++s) { global->niter_self_bgk_corr[s] = l_red_bgk_corr[s]; } enum { - TOTAL_TM, RK3_TM, FL_EM_TM, - INIT_SPECIES_TM, INIT_FLUID_SPECIES_TM, INIT_FIELD_TM, - SPECIES_RHS_TM, FLUID_SPECIES_RHS_TM, FLUID_SPECIES_VARS_TM, - SPECIES_COLL_MOM_TM, SPECIES_COL_TM, SPECIES_RAD_TM, SPECIES_LTE_TM, - FIELD_RHS_TM, CURRENT_TM, - SPECIES_OMEGA_CFL_TM, FIELD_OMEGA_CFL_TM, MOM_TM, DIAG_TM, IO_TM, - SPECIES_BC_TM, FLUID_SPECIES_BC_TM, FIELD_BC_TM, + TOTAL_TM, + RK3_TM, + FL_EM_TM, + INIT_SPECIES_TM, + INIT_FLUID_SPECIES_TM, + INIT_FIELD_TM, + SPECIES_RHS_TM, + FLUID_SPECIES_RHS_TM, + FLUID_SPECIES_VARS_TM, + SPECIES_COLL_MOM_TM, + SPECIES_COL_TM, + SPECIES_RAD_TM, + SPECIES_LTE_TM, + FIELD_RHS_TM, + CURRENT_TM, + SPECIES_OMEGA_CFL_TM, + FIELD_OMEGA_CFL_TM, + MOM_TM, + DIAG_TM, + IO_TM, + SPECIES_BC_TM, + FLUID_SPECIES_BC_TM, + FIELD_BC_TM, D_END }; @@ -1149,7 +1135,7 @@ comm_reduce_app_stat(const gkyl_vlasov_app* app, double d_red_global[D_END]; gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, D_END, d_red, d_red_global); - + global->total_tm = d_red_global[TOTAL_TM]; global->rk3_tm = d_red_global[RK3_TM]; global->fl_em_tm = d_red_global[FL_EM_TM]; @@ -1176,23 +1162,28 @@ comm_reduce_app_stat(const gkyl_vlasov_app* app, // misc data needing reduction - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_2_dt_diff, - global->stage_2_dt_diff); - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_3_dt_diff, - global->stage_3_dt_diff); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_2_dt_diff, global->stage_2_dt_diff + ); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, 2, local->stage_3_dt_diff, global->stage_3_dt_diff + ); - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, GKYL_MAX_SPECIES, local->species_lbo_coll_drag_tm, - global->species_lbo_coll_drag_tm); - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, GKYL_MAX_SPECIES, local->species_lbo_coll_diff_tm, - global->species_lbo_coll_diff_tm); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, GKYL_MAX_SPECIES, local->species_lbo_coll_drag_tm, + global->species_lbo_coll_drag_tm + ); + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_MAX, GKYL_MAX_SPECIES, local->species_lbo_coll_diff_tm, + global->species_lbo_coll_diff_tm + ); } -void -gkyl_vlasov_app_stat_write(gkyl_vlasov_app* app) +void gkyl_vlasov_app_stat_write(gkyl_vlasov_app *app) { const char *fmt = "%s-%s"; int sz = gkyl_calc_strlen(fmt, app->name, "stat.json"); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, "stat.json"); int num_ranks; @@ -1207,52 +1198,62 @@ gkyl_vlasov_app_stat_write(gkyl_vlasov_app* app) vm_species_tm(app); vm_species_rad_tm(app); - struct gkyl_vlasov_stat stat = { }; + struct gkyl_vlasov_stat stat = {}; comm_reduce_app_stat(app, &app->stat, &stat); - + int rank; gkyl_comm_get_rank(app->comm, &rank); // append to existing file so we have a history of different runs FILE *fp = 0; - if (rank == 0) fp = fopen(fileNm, "a"); + if (rank == 0) { + fp = fopen(fileNm, "a"); + } gkyl_vlasov_app_cout(app, fp, "{\n"); - if (strftime(buff, sizeof buff, "%c", &curr_tm)) + if (strftime(buff, sizeof buff, "%c", &curr_tm)) { gkyl_vlasov_app_cout(app, fp, " date : %s,\n", buff); + } gkyl_vlasov_app_cout(app, fp, " use_gpu : %d,\n", stat.use_gpu); - gkyl_vlasov_app_cout(app, fp, " num_ranks : %d,\n", num_ranks); - - for (int s=0; snum_species; ++s) + gkyl_vlasov_app_cout(app, fp, " num_ranks : %d,\n", num_ranks); + + for (int s = 0; s < app->num_species; ++s) { range_stat_write(app, app->species[s].info.name, &app->species[s].global, fp); - + } + gkyl_vlasov_app_cout(app, fp, " nup : %ld,\n", stat.nup); gkyl_vlasov_app_cout(app, fp, " nfeuler : %ld,\n", stat.nfeuler); gkyl_vlasov_app_cout(app, fp, " nstage_2_fail : %ld,\n", stat.nstage_2_fail); gkyl_vlasov_app_cout(app, fp, " nstage_3_fail : %ld,\n", stat.nstage_3_fail); - gkyl_vlasov_app_cout(app, fp, " stage_2_dt_diff : [ %lg, %lg ],\n", - stat.stage_2_dt_diff[0], stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, fp, " stage_3_dt_diff : [ %lg, %lg ],\n", - stat.stage_3_dt_diff[0], stat.stage_3_dt_diff[1]); + gkyl_vlasov_app_cout( + app, fp, " stage_2_dt_diff : [ %lg, %lg ],\n", stat.stage_2_dt_diff[0], stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, fp, " stage_3_dt_diff : [ %lg, %lg ],\n", stat.stage_3_dt_diff[0], stat.stage_3_dt_diff[1] + ); gkyl_vlasov_app_cout(app, fp, " total_tm : %lg,\n", stat.total_tm); gkyl_vlasov_app_cout(app, fp, " rk3_tm : %lg,\n", stat.rk3_tm); gkyl_vlasov_app_cout(app, fp, " fluid_em_coupling_tm : %lg,\n", stat.fl_em_tm); gkyl_vlasov_app_cout(app, fp, " init_species_tm : %lg,\n", stat.init_species_tm); - if (app->has_field) + if (app->has_field) { gkyl_vlasov_app_cout(app, fp, " init_field_tm : %lg,\n", stat.init_field_tm); - + } + gkyl_vlasov_app_cout(app, fp, " species_rhs_tm : %lg,\n", stat.species_rhs_tm); - for (int s=0; snum_species; ++s) { - gkyl_vlasov_app_cout(app, fp, " species_coll_drag_tm[%d] : %lg,\n", s, - stat.species_lbo_coll_drag_tm[s]); - gkyl_vlasov_app_cout(app, fp, " species_coll_diff_tm[%d] : %lg,\n", s, - stat.species_lbo_coll_diff_tm[s]); - gkyl_vlasov_app_cout(app, fp, " niter_self_bgk_corr[%d] : %ld,\n", s, - stat.niter_self_bgk_corr[s]); + for (int s = 0; s < app->num_species; ++s) { + gkyl_vlasov_app_cout( + app, fp, " species_coll_drag_tm[%d] : %lg,\n", s, stat.species_lbo_coll_drag_tm[s] + ); + gkyl_vlasov_app_cout( + app, fp, " species_coll_diff_tm[%d] : %lg,\n", s, stat.species_lbo_coll_diff_tm[s] + ); + gkyl_vlasov_app_cout( + app, fp, " niter_self_bgk_corr[%d] : %ld,\n", s, stat.niter_self_bgk_corr[s] + ); } gkyl_vlasov_app_cout(app, fp, " species_coll_mom_tm : %lg,\n", stat.species_coll_mom_tm); @@ -1262,7 +1263,7 @@ gkyl_vlasov_app_stat_write(gkyl_vlasov_app* app) gkyl_vlasov_app_cout(app, fp, " species_lte_tm : %lg,\n", stat.species_lte_tm); gkyl_vlasov_app_cout(app, fp, " species_bc_tm : %lg,\n", stat.species_bc_tm); - + gkyl_vlasov_app_cout(app, fp, " fluid_species_rhs_tm : %lg,\n", stat.fluid_species_rhs_tm); gkyl_vlasov_app_cout(app, fp, " fluid_species_bc_tm : %lg,\n", stat.fluid_species_bc_tm); @@ -1270,7 +1271,7 @@ gkyl_vlasov_app_stat_write(gkyl_vlasov_app* app) if (app->has_field) { gkyl_vlasov_app_cout(app, fp, " field_rhs_tm : %lg,\n", stat.field_rhs_tm); gkyl_vlasov_app_cout(app, fp, " field_bc_tm : %lg,\n", stat.field_bc_tm); - + gkyl_vlasov_app_cout(app, fp, " current_tm : %lg,\n", stat.current_tm); } @@ -1279,7 +1280,7 @@ gkyl_vlasov_app_stat_write(gkyl_vlasov_app* app) gkyl_vlasov_app_cout(app, fp, " ndiag : %ld,\n", stat.n_diag); gkyl_vlasov_app_cout(app, fp, " diag_tm : %lg\n", stat.diag_tm); - + gkyl_vlasov_app_cout(app, fp, " nspecies_omega_cfl : %ld,\n", stat.n_species_omega_cfl); gkyl_vlasov_app_cout(app, fp, " species_omega_cfl_tm : %lg\n", stat.species_omega_cfl_tm); @@ -1288,85 +1289,81 @@ gkyl_vlasov_app_stat_write(gkyl_vlasov_app* app) gkyl_vlasov_app_cout(app, fp, " nio : %ld,\n", stat.n_io); gkyl_vlasov_app_cout(app, fp, " io_tm : %lg\n", stat.io_tm); - - gkyl_vlasov_app_cout(app, fp, "}\n"); - if (rank == 0) - fclose(fp); + gkyl_vlasov_app_cout(app, fp, "}\n"); + if (rank == 0) { + fclose(fp); + } } -static struct gkyl_app_restart_status -header_from_file(gkyl_vlasov_app *app, const char *fname) +static struct gkyl_app_restart_status header_from_file(gkyl_vlasov_app *app, const char *fname) { - struct gkyl_app_restart_status rstat = { .io_status = 0 }; - + struct gkyl_app_restart_status rstat = {.io_status = 0}; + FILE *fp = 0; - with_file(fp, fname, "r") { + with_file(fp, fname, "r") + { struct gkyl_rect_grid grid; struct gkyl_array_header_info hdr; rstat.io_status = gkyl_grid_sub_array_header_read_fp(&grid, &hdr, fp); if (GKYL_ARRAY_RIO_SUCCESS == rstat.io_status) { - if (hdr.etype != GKYL_DOUBLE) + if (hdr.etype != GKYL_DOUBLE) { rstat.io_status = GKYL_ARRAY_RIO_DATA_MISMATCH; + } } - struct vlasov_output_meta meta = - vlasov_meta_from_mpack( &(struct gkyl_msgpack_data) { - .meta = hdr.meta, - .meta_sz = hdr.meta_size - } - ); + struct vlasov_output_meta meta = vlasov_meta_from_mpack(&(struct gkyl_msgpack_data + ){.meta = hdr.meta, .meta_sz = hdr.meta_size}); rstat.frame = meta.frame; rstat.stime = meta.stime; gkyl_grid_sub_array_header_release(&hdr); } - + return rstat; } struct gkyl_app_restart_status gkyl_vlasov_app_from_file_field(gkyl_vlasov_app *app, const char *fname) { - if (app->has_field != 1) - return (struct gkyl_app_restart_status) { - .io_status = GKYL_ARRAY_RIO_SUCCESS, - .frame = 0, - .stime = 0.0 - }; + if (app->has_field != 1) { + return (struct gkyl_app_restart_status + ){.io_status = GKYL_ARRAY_RIO_SUCCESS, .frame = 0, .stime = 0.0}; + } struct gkyl_app_restart_status rstat = header_from_file(app, fname); if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { rstat.io_status = gkyl_comm_array_read(app->comm, &app->grid, &app->local, app->field->em_host, fname); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(app->field->em, app->field->em_host); - if (GKYL_ARRAY_RIO_SUCCESS == rstat.io_status) + } + if (GKYL_ARRAY_RIO_SUCCESS == rstat.io_status) { vm_field_apply_bc(app, app->field, app->field->em); + } } // Compute external EM field and applied current if present // Computation necessary in case external EM field or applied current // are time-independent and not computed in the time-stepping loop - // since they are not read-in as part of restarts. + // since they are not read-in as part of restarts. vm_field_calc_ext_em(app, app->field, rstat.stime); - vm_field_calc_app_current(app, app->field, rstat.stime); + vm_field_calc_app_current(app, app->field, rstat.stime); return rstat; } -struct gkyl_app_restart_status -gkyl_vlasov_app_from_file_species(gkyl_vlasov_app *app, int sidx, - const char *fname) +struct gkyl_app_restart_status +gkyl_vlasov_app_from_file_species(gkyl_vlasov_app *app, int sidx, const char *fname) { struct gkyl_app_restart_status rstat = header_from_file(app, fname); struct vm_species *vm_s = &app->species[sidx]; - + if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { rstat.io_status = gkyl_comm_array_read(vm_s->comm, &vm_s->grid, &vm_s->local, vm_s->f_host, fname); @@ -1374,7 +1371,7 @@ gkyl_vlasov_app_from_file_species(gkyl_vlasov_app *app, int sidx, gkyl_array_copy(vm_s->f, vm_s->f_host); } if (GKYL_ARRAY_RIO_SUCCESS == rstat.io_status) { - if (vm_s->calc_bflux) { + if (vm_s->calc_bflux) { vm_species_bflux_rhs(app, vm_s, &vm_s->bflux, vm_s->f, vm_s->f); } vm_species_apply_bc(app, vm_s, vm_s->f, rstat.stime); @@ -1387,12 +1384,12 @@ gkyl_vlasov_app_from_file_species(gkyl_vlasov_app *app, int sidx, // Compute applied acceleration if present. // Computation necessary in case applied acceleration // is time-independent and not computed in the time-stepping loop - // since it is not read-in as part of restarts. + // since it is not read-in as part of restarts. vm_species_calc_app_accel(app, vm_s, rstat.stime); - // Optional runtime configuration to use BGK collisions but with fixed input - // temperature relaxation based on the initial temperature value. - // Need to reinitialize the fixed temperature at restarts. + // Optional runtime configuration to use BGK collisions but with fixed input + // temperature relaxation based on the initial temperature value. + // Need to reinitialize the fixed temperature at restarts. if (vm_s->bgk.fixed_temp_relax) { vm_species_bgk_moms_fixed_temp(app, vm_s, &vm_s->bgk, vm_s->f); } @@ -1400,14 +1397,13 @@ gkyl_vlasov_app_from_file_species(gkyl_vlasov_app *app, int sidx, return rstat; } -struct gkyl_app_restart_status -gkyl_vlasov_app_from_file_fluid_species(gkyl_vlasov_app *app, int sidx, - const char *fname) +struct gkyl_app_restart_status +gkyl_vlasov_app_from_file_fluid_species(gkyl_vlasov_app *app, int sidx, const char *fname) { struct gkyl_app_restart_status rstat = header_from_file(app, fname); struct vm_fluid_species *vm_fs = &app->fluid_species[sidx]; - + if (rstat.io_status == GKYL_ARRAY_RIO_SUCCESS) { rstat.io_status = gkyl_comm_array_read(app->comm, &app->grid, &app->local, vm_fs->fluid_host, fname); @@ -1425,14 +1421,13 @@ gkyl_vlasov_app_from_file_fluid_species(gkyl_vlasov_app *app, int sidx, // Compute applied acceleration if present. // Computation necessary in case applied acceleration // is time-independent and not computed in the time-stepping loop - // since it is not read-in as part of restarts. + // since it is not read-in as part of restarts. vm_fluid_species_calc_app_accel(app, vm_fs, rstat.stime); return rstat; } -struct gkyl_app_restart_status -gkyl_vlasov_app_from_frame_field(gkyl_vlasov_app *app, int frame) +struct gkyl_app_restart_status gkyl_vlasov_app_from_frame_field(gkyl_vlasov_app *app, int frame) { struct gkyl_app_restart_status rstat; if (app->has_field) { @@ -1444,7 +1439,7 @@ gkyl_vlasov_app_from_frame_field(gkyl_vlasov_app *app, int frame) } app->field->is_first_energy_write_call = false; // append to existing diagnostic - + return rstat; } @@ -1456,26 +1451,27 @@ gkyl_vlasov_app_from_frame_species(gkyl_vlasov_app *app, int sidx, int frame) app->species[sidx].is_first_integ_write_call = false; // append to existing diagnostic app->species[sidx].is_first_integ_L2_write_call = false; // append to existing diagnostic cstr_drop(&fileNm); - + return rstat; } struct gkyl_app_restart_status gkyl_vlasov_app_from_frame_fluid_species(gkyl_vlasov_app *app, int sidx, int frame) { - cstr fileNm = cstr_from_fmt("%s-%s_%d.gkyl", app->name, app->fluid_species[sidx].info.name, frame); - struct gkyl_app_restart_status rstat = gkyl_vlasov_app_from_file_fluid_species(app, sidx, fileNm.str); + cstr fileNm = + cstr_from_fmt("%s-%s_%d.gkyl", app->name, app->fluid_species[sidx].info.name, frame); + struct gkyl_app_restart_status rstat = + gkyl_vlasov_app_from_file_fluid_species(app, sidx, fileNm.str); app->fluid_species[sidx].is_first_integ_write_call = false; // append to existing diagnostic cstr_drop(&fileNm); - + return rstat; } -struct gkyl_app_restart_status -gkyl_vlasov_app_read_from_frame(gkyl_vlasov_app *app, int frame) +struct gkyl_app_restart_status gkyl_vlasov_app_read_from_frame(gkyl_vlasov_app *app, int frame) { struct gkyl_app_restart_status rstat; - + if (app->has_field) { rstat = gkyl_vlasov_app_from_frame_field(app, frame); } @@ -1491,14 +1487,15 @@ gkyl_vlasov_app_read_from_frame(gkyl_vlasov_app *app, int frame) // Compute the fields and apply BCs. if ((app->field->field_id != GKYL_FIELD_E_B) && (app->field->field_id != GKYL_FIELD_NULL)) { struct gkyl_array *distf[app->num_species]; - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { distf[i] = app->species[i].f; + } // MF 2024/09/27/: Need the cast here for consistency. Fixing // this may require removing 'const' from a lot of places. - vp_field_apply_ic(app, app->field, (const struct gkyl_array **) distf, rstat.stime); + vp_field_apply_ic(app, app->field, (const struct gkyl_array **)distf, rstat.stime); // Apply boundary conditions. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { vm_species_apply_bc(app, &app->species[i], distf[i], rstat.stime); } } @@ -1508,8 +1505,7 @@ gkyl_vlasov_app_read_from_frame(gkyl_vlasov_app *app, int frame) } // private function to handle variable argument list for printing -static void -v_vlasov_app_cout(const gkyl_vlasov_app* app, FILE *fp, const char *fmt, va_list argp) +static void v_vlasov_app_cout(const gkyl_vlasov_app *app, FILE *fp, const char *fmt, va_list argp) { int rank, r = 0; gkyl_comm_get_rank(app->comm, &rank); @@ -1519,8 +1515,7 @@ v_vlasov_app_cout(const gkyl_vlasov_app* app, FILE *fp, const char *fmt, va_list } } -void -gkyl_vlasov_app_cout(const gkyl_vlasov_app* app, FILE *fp, const char *fmt, ...) +void gkyl_vlasov_app_cout(const gkyl_vlasov_app *app, FILE *fp, const char *fmt, ...) { va_list argp; va_start(argp, fmt); @@ -1528,25 +1523,30 @@ gkyl_vlasov_app_cout(const gkyl_vlasov_app* app, FILE *fp, const char *fmt, ...) va_end(argp); } -void -gkyl_vlasov_app_release(gkyl_vlasov_app* app) +void gkyl_vlasov_app_release(gkyl_vlasov_app *app) { - for (int i=0; inum_species; ++i) + for (int i = 0; i < app->num_species; ++i) { vm_species_release(app, &app->species[i]); - for (int i=0; inum_fluid_species; ++i) + } + for (int i = 0; i < app->num_fluid_species; ++i) { vm_fluid_species_release(app, &app->fluid_species[i]); - if (app->num_species > 0) + } + if (app->num_species > 0) { gkyl_free(app->species); - if (app->num_fluid_species > 0) + } + if (app->num_fluid_species > 0) { gkyl_free(app->fluid_species); + } if (app->has_field) { - if (app->field->field_id == GKYL_FIELD_E_B) + if (app->field->field_id == GKYL_FIELD_E_B) { vm_field_release(app, app->field); - else + } else { vp_field_release(app, app->field); + } } - if (app->has_fluid_em_coupling) + if (app->has_fluid_em_coupling) { vm_fluid_em_coupling_release(app, app->fl_em); + } gkyl_comm_release(app->comm); gkyl_rect_decomp_release(app->decomp); diff --git a/vlasov/apps/vlasov_comms.c b/vlasov/apps/vlasov_comms.c index c85307829e..16300f557b 100644 --- a/vlasov/apps/vlasov_comms.c +++ b/vlasov/apps/vlasov_comms.c @@ -1,8 +1,7 @@ #include #include -struct gkyl_comm* -gkyl_vlasov_comms_new(bool use_mpi, bool use_gpu, FILE *iostream) +struct gkyl_comm *gkyl_vlasov_comms_new(bool use_mpi, bool use_gpu, FILE *iostream) { // Construct communicator for use in app. struct gkyl_comm *comm = 0; @@ -10,40 +9,26 @@ gkyl_vlasov_comms_new(bool use_mpi, bool use_gpu, FILE *iostream) #ifdef GKYL_HAVE_MPI if (use_gpu && use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else fprintf(iostream, " Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = use_gpu - } - ); + } else if (use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = use_gpu}); #endif return comm; } -void -gkyl_vlasov_comms_release(struct gkyl_comm *comm) +void gkyl_vlasov_comms_release(struct gkyl_comm *comm) { - if (comm != 0) + if (comm != 0) { gkyl_comm_release(comm); + } } diff --git a/vlasov/apps/vlasov_forward_euler.c b/vlasov/apps/vlasov_forward_euler.c index fd08c1465a..8fb763fb6d 100644 --- a/vlasov/apps/vlasov_forward_euler.c +++ b/vlasov/apps/vlasov_forward_euler.c @@ -1,27 +1,27 @@ #include -// Take a forward Euler step of the Vlasov-Maxwell system of equations +// Take a forward Euler step of the Vlasov-Maxwell system of equations // with the suggested time-step dt. Also supports just Maxwell's equations -// and fluid equations (Euler's) with potential Vlasov-fluid coupling. +// and fluid equations (Euler's) with potential Vlasov-fluid coupling. // Note: this may not be the actual time-step taken. However, the function will never -// take a time-step larger than dt even if it is allowed by stability. +// take a time-step larger than dt even if it is allowed by stability. // The actual time-step and dt_suggested are returned in the status object. -void -vlasov_forward_euler(gkyl_vlasov_app* app, double tcurr, double dt, - const struct gkyl_array *fin[], const struct gkyl_array *fluidin[], const struct gkyl_array *emin, - struct gkyl_array *fout[], struct gkyl_array *fluidout[], struct gkyl_array *emout, - struct gkyl_update_status *st) +void vlasov_forward_euler( + gkyl_vlasov_app *app, double tcurr, double dt, const struct gkyl_array *fin[], + const struct gkyl_array *fluidin[], const struct gkyl_array *emin, struct gkyl_array *fout[], + struct gkyl_array *fluidout[], struct gkyl_array *emout, struct gkyl_update_status *st +) { app->stat.nfeuler += 1; double dtmin = DBL_MAX; // Compute external EM field or applied currents if present and time-dependent. - // Note: external EM field and applied currents use proj_on_basis + // Note: external EM field and applied currents use proj_on_basis // so does copy to GPU every call if app->use_gpu = true. if (app->has_field) { if (app->field->app_current_evolve && !app->has_fluid_em_coupling) { - vm_field_calc_app_current(app, app->field, tcurr); + vm_field_calc_app_current(app, app->field, tcurr); } if (app->field->ext_em_evolve) { vm_field_calc_ext_em(app, app->field, tcurr); @@ -31,56 +31,58 @@ vlasov_forward_euler(gkyl_vlasov_app* app, double tcurr, double dt, } } // Compute applied acceleration if if present and time-dependent. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { if (app->species[i].app_accel_evolve) { vm_species_calc_app_accel(app, &app->species[i], tcurr); } } // compute necessary moments and boundary corrections for collisions - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { if (app->species[i].collision_id == GKYL_LBO_COLLISIONS) { vm_species_lbo_moms(app, &app->species[i], &app->species[i].lbo, fin[i]); - } - else if (app->species[i].collision_id == GKYL_BGK_COLLISIONS && !app->has_implicit_coll_scheme) { - vm_species_bgk_moms(app, &app->species[i], - &app->species[i].bgk, fin[i]); + } else if (app->species[i].collision_id == GKYL_BGK_COLLISIONS && + !app->has_implicit_coll_scheme) { + vm_species_bgk_moms(app, &app->species[i], &app->species[i].bgk, fin[i]); } } // compute necessary moments for cross-species collisions // needs to be done after self-collisions moments, so separate loop over species - for (int i=0; inum_species; ++i) { - if (app->species[i].collision_id == GKYL_LBO_COLLISIONS - && app->species[i].lbo.num_cross_collisions) { + for (int i = 0; i < app->num_species; ++i) { + if (app->species[i].collision_id == GKYL_LBO_COLLISIONS && + app->species[i].lbo.num_cross_collisions) { vm_species_lbo_cross_moms(app, &app->species[i], &app->species[i].lbo, fin[i]); } } // Compute primitive moments for fluid species evolution - for (int i=0; inum_fluid_species; ++i) + for (int i = 0; i < app->num_fluid_species; ++i) { vm_fluid_species_prim_vars(app, &app->fluid_species[i], fluidin[i]); + } // compute RHS of Vlasov equations - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { double dt1 = vm_species_rhs(app, &app->species[i], fin[i], emin, fout[i]); dtmin = fmin(dtmin, dt1); } - for (int i=0; inum_fluid_species; ++i) { + for (int i = 0; i < app->num_fluid_species; ++i) { double dt1 = vm_fluid_species_rhs(app, &app->fluid_species[i], fluidin[i], emin, fluidout[i]); dtmin = fmin(dtmin, dt1); } // compute source term // done here as the RHS update for all species should be complete before // bflux calculation of the source species - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { if (app->species[i].source_id) { vm_species_source_rhs(app, &app->species[i], &app->species[i].src, fin, fout); } } - for (int i=0; inum_fluid_species; ++i) { + for (int i = 0; i < app->num_fluid_species; ++i) { if (app->fluid_species[i].source_id) { - vm_fluid_species_source_rhs(app, &app->fluid_species[i], &app->fluid_species[i].src, fluidin, fluidout); + vm_fluid_species_source_rhs( + app, &app->fluid_species[i], &app->fluid_species[i].src, fluidin, fluidout + ); } } // compute RHS of Maxwell equations @@ -94,26 +96,27 @@ vlasov_forward_euler(gkyl_vlasov_app* app, double tcurr, double dt, double dt_max_rel_diff = 0.01; // check if dtmin is slightly smaller than dt. Use dt if it is // (avoids retaking steps if dt changes are very small). - double dt_rel_diff = (dt-dtmin)/dt; - if (dt_rel_diff > 0 && dt_rel_diff < dt_max_rel_diff) + double dt_rel_diff = (dt - dtmin) / dt; + if (dt_rel_diff > 0 && dt_rel_diff < dt_max_rel_diff) { dtmin = dt; + } // compute minimum time-step across all processors double dtmin_local = dtmin, dtmin_global; gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MIN, 1, &dtmin_local, &dtmin_global); dtmin = dtmin_global; - + // don't take a time-step larger that input dt double dta = st->dt_actual = dt < dtmin ? dt : dtmin; st->dt_suggested = dtmin; // complete update of distribution function - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_array_accumulate(gkyl_array_scale(fout[i], dta), 1.0, fin[i]); } // complete update of fluid species - for (int i=0; inum_fluid_species; ++i) { + for (int i = 0; i < app->num_fluid_species; ++i) { gkyl_array_accumulate(gkyl_array_scale(fluidout[i], dta), 1.0, fluidin[i]); } diff --git a/vlasov/apps/vlasov_lw.c b/vlasov/apps/vlasov_lw.c index 3b23e324b3..5c321adc8f 100644 --- a/vlasov/apps/vlasov_lw.c +++ b/vlasov/apps/vlasov_lw.c @@ -32,76 +32,71 @@ // Poisson boundary conditions -> enum map. static const struct gkyl_str_int_pair poisson_bcs[] = { - { "bcPeriodic", GKYL_POISSON_PERIODIC }, - { "bcDirichlet", GKYL_POISSON_DIRICHLET }, - { "bcNeumann", GKYL_POISSON_NEUMANN }, - { "bcRobin", GKYL_POISSON_ROBIN }, - { 0, 0 } + {"bcPeriodic", GKYL_POISSON_PERIODIC}, + {"bcDirichlet", GKYL_POISSON_DIRICHLET}, + {"bcNeumann", GKYL_POISSON_NEUMANN}, + {"bcRobin", GKYL_POISSON_ROBIN}, + {0, 0} }; // Vlasov projection type -> enum map. static const struct gkyl_str_int_pair projection_type[] = { - { "Func", GKYL_PROJ_FUNC }, - { "MaxwellianPrimitive", GKYL_PROJ_MAXWELLIAN_PRIM }, - { "MaxwellianLab", GKYL_PROJ_MAXWELLIAN_LAB }, - { "BiMaxwellian", GKYL_PROJ_BIMAXWELLIAN }, - { "LTE", GKYL_PROJ_VLASOV_LTE }, - { 0, 0 } + {"Func", GKYL_PROJ_FUNC}, + {"MaxwellianPrimitive", GKYL_PROJ_MAXWELLIAN_PRIM}, + {"MaxwellianLab", GKYL_PROJ_MAXWELLIAN_LAB}, + {"BiMaxwellian", GKYL_PROJ_BIMAXWELLIAN}, + {"LTE", GKYL_PROJ_VLASOV_LTE}, + {0, 0} }; // Vlasov model type -> enum map. static const struct gkyl_str_int_pair model_type[] = { - { "Default", GKYL_MODEL_DEFAULT }, - { "SR", GKYL_MODEL_SR }, - { "CanonicalPB", GKYL_MODEL_CANONICAL_PB }, - { "CanonicalPBGR", GKYL_MODEL_CANONICAL_PB_GR }, - { 0, 0 } + {"Default", GKYL_MODEL_DEFAULT}, + {"SR", GKYL_MODEL_SR}, + {"CanonicalPB", GKYL_MODEL_CANONICAL_PB}, + {"CanonicalPBGR", GKYL_MODEL_CANONICAL_PB_GR}, + {0, 0} }; // Vlasov collision type -> enum map. static const struct gkyl_str_int_pair collision_type[] = { - { "None", GKYL_NO_COLLISIONS }, - { "BGK", GKYL_BGK_COLLISIONS }, - { "LBO", GKYL_LBO_COLLISIONS }, - { "FPO", GKYL_FPO_COLLISIONS }, - { 0, 0 } + {"None", GKYL_NO_COLLISIONS}, + {"BGK", GKYL_BGK_COLLISIONS}, + {"LBO", GKYL_LBO_COLLISIONS}, + {"FPO", GKYL_FPO_COLLISIONS}, + {0, 0} }; // Vlasov source type -> enum map. static const struct gkyl_str_int_pair source_type[] = { - { "None", GKYL_NO_SOURCE }, - { "Func", GKYL_FUNC_SOURCE }, - { "Proj", GKYL_PROJ_SOURCE }, - { "BoundaryFlux", GKYL_BFLUX_SOURCE }, - { 0, 0 } + {"None", GKYL_NO_SOURCE}, + {"Func", GKYL_FUNC_SOURCE}, + {"Proj", GKYL_PROJ_SOURCE}, + {"BoundaryFlux", GKYL_BFLUX_SOURCE}, + {0, 0} }; -void -gkyl_register_poisson_bc_types(lua_State *L) +void gkyl_register_poisson_bc_types(lua_State *L) { register_types(L, poisson_bcs, "PoissonBc"); } -void -gkyl_register_vlasov_projection_types(lua_State *L) +void gkyl_register_vlasov_projection_types(lua_State *L) { register_types(L, projection_type, "Projection"); } -void -gkyl_register_vlasov_model_types(lua_State *L) +void gkyl_register_vlasov_model_types(lua_State *L) { register_types(L, model_type, "Model"); } -void -gkyl_register_vlasov_collision_types(lua_State *L) +void gkyl_register_vlasov_collision_types(lua_State *L) { register_types(L, collision_type, "Collisions"); } -void -gkyl_register_vlasov_source_types(lua_State *L) +void gkyl_register_vlasov_source_types(lua_State *L) { register_types(L, source_type, "Source"); } @@ -111,7 +106,7 @@ enum vlasov_magic_ids { VLASOV_SPECIES_DEFAULT = 100, // Non-relativistic kinetic species. VLASOV_FIELD_DEFAULT, // Maxwell equations. VLASOV_FLUID_SPECIES_DEFAULT, // Fluid species. - VLASOV_EQN_DEFAULT, // Equation object. + VLASOV_EQN_DEFAULT // Equation object. }; // Metatable name for equation object input struct. @@ -126,21 +121,19 @@ struct wv_eqn_lw { }; // Clean up memory allocated for equation object. -static int -wv_eqn_lw_gc(lua_State *L) +static int wv_eqn_lw_gc(lua_State *L) { struct wv_eqn_lw **l_wv_lw = GKYL_CHECK_UDATA(L, VLASOV_WAVE_EQN_METATABLE_NM); struct wv_eqn_lw *wv_lw = *l_wv_lw; gkyl_wv_eqn_release(wv_lw->eqn); gkyl_free(*l_wv_lw); - + return 0; } // Acquire equation object. -static struct gkyl_wv_eqn* -wv_eqn_get(lua_State *L) +static struct gkyl_wv_eqn *wv_eqn_get(lua_State *L) { struct wv_eqn_lw **l_wv_lw = luaL_checkudata(L, -1, VLASOV_WAVE_EQN_METATABLE_NM); struct wv_eqn_lw *wv_lw = *l_wv_lw; @@ -154,8 +147,7 @@ wv_eqn_get(lua_State *L) // Euler.new { gasGamma = 1.4, rpType = G0.EulerRP.Roe } // where rpType is one of G0.EulerRP.Roe, G0.EulerRP.Lax, G0.EulerRP.HLL or G0.EulerRP.HLLC. -static int -eqn_euler_lw_new(lua_State *L) +static int eqn_euler_lw_new(lua_State *L) { struct wv_eqn_lw *euler_lw = gkyl_malloc(sizeof(*euler_lw)); @@ -163,69 +155,57 @@ eqn_euler_lw_new(lua_State *L) enum gkyl_wv_euler_rp rp_type = glua_tbl_get_integer(L, "rpType", WV_EULER_RP_ROE); euler_lw->magic = VLASOV_EQN_DEFAULT; - euler_lw->eqn = gkyl_wv_euler_inew( &(struct gkyl_wv_euler_inp) { - .gas_gamma = gas_gamma, - .rp_type = rp_type, - .use_gpu = false - } - ); + euler_lw->eqn = gkyl_wv_euler_inew(&(struct gkyl_wv_euler_inp + ){.gas_gamma = gas_gamma, .rp_type = rp_type, .use_gpu = false}); // Create Lua userdata. - struct wv_eqn_lw **l_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_euler_lw = euler_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, VLASOV_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_euler_ctor[] = { - { "new", eqn_euler_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_euler_ctor[] = {{"new", eqn_euler_lw_new}, {0, 0}}; /* ****************************** */ /* Advection Equation */ /* ****************************** */ // Advect.new { } -static int -eqn_advect_lw_new(lua_State *L) +static int eqn_advect_lw_new(lua_State *L) { struct wv_eqn_lw *advect_lw = gkyl_malloc(sizeof(*advect_lw)); advect_lw->magic = VLASOV_EQN_DEFAULT; // Set a constant speed of 1.0; Advection velocity in DG advection equation - // is handled by the app_advect function initialized in the FluidSpecies table. + // is handled by the app_advect function initialized in the FluidSpecies table. advect_lw->eqn = gkyl_wv_advect_new(1.0, false); // Create Lua userdata. - struct wv_eqn_lw **l_advect_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_advect_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_advect_lw = advect_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, VLASOV_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_advect_ctor[] = { - { "new", eqn_advect_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_advect_ctor[] = {{"new", eqn_advect_lw_new}, {0, 0}}; /* ****************************** */ /* incompressible Euler Equations */ /* ****************************** */ // IncompressEuler.new { } -static int -eqn_incompress_euler_lw_new(lua_State *L) +static int eqn_incompress_euler_lw_new(lua_State *L) { struct wv_eqn_lw *incompress_euler_lw = gkyl_malloc(sizeof(*incompress_euler_lw)); @@ -233,29 +213,25 @@ eqn_incompress_euler_lw_new(lua_State *L) incompress_euler_lw->eqn = gkyl_wv_can_pb_incompress_euler_new(); // Create Lua userdata. - struct wv_eqn_lw **l_incompress_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_incompress_euler_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_incompress_euler_lw = incompress_euler_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, VLASOV_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_incompress_euler_ctor[] = { - { "new", eqn_incompress_euler_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_incompress_euler_ctor[] = {{"new", eqn_incompress_euler_lw_new}, {0, 0}}; /* *********************** */ /* Hasegawa-Mima Equations */ /* *********************** */ // HasegawaMima.new { } -static int -eqn_hasegawa_mima_lw_new(lua_State *L) +static int eqn_hasegawa_mima_lw_new(lua_State *L) { struct wv_eqn_lw *hasegawa_mima_lw = gkyl_malloc(sizeof(*hasegawa_mima_lw)); @@ -263,21 +239,18 @@ eqn_hasegawa_mima_lw_new(lua_State *L) hasegawa_mima_lw->eqn = gkyl_wv_can_pb_hasegawa_mima_new(); // Create Lua userdata. - struct wv_eqn_lw **l_hasegawa_mima_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_hasegawa_mima_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_hasegawa_mima_lw = hasegawa_mima_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, VLASOV_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. -static struct luaL_Reg eqn_hasegawa_mima_ctor[] = { - { "new", eqn_hasegawa_mima_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg eqn_hasegawa_mima_ctor[] = {{"new", eqn_hasegawa_mima_lw_new}, {0, 0}}; /* *************************** */ /* Hasegawa-Wakatani Equations */ @@ -285,38 +258,36 @@ static struct luaL_Reg eqn_hasegawa_mima_ctor[] = { // HasegawaWakatani.new { alpha = 1.0, is_modified = false } // Set is_modified=true to utilized modified Hasegawa-Wakatani system which -// subtracts off zonal component of adiabatic coupling term. -static int -eqn_hasegawa_wakatani_lw_new(lua_State *L) +// subtracts off zonal component of adiabatic coupling term. +static int eqn_hasegawa_wakatani_lw_new(lua_State *L) { struct wv_eqn_lw *hasegawa_wakatani_lw = gkyl_malloc(sizeof(*hasegawa_wakatani_lw)); double alpha = glua_tbl_get_number(L, "alpha", 1.0); - bool is_modified = glua_tbl_get_bool(L, "is_modified", false); + bool is_modified = glua_tbl_get_bool(L, "is_modified", false); hasegawa_wakatani_lw->magic = VLASOV_EQN_DEFAULT; hasegawa_wakatani_lw->eqn = gkyl_wv_can_pb_hasegawa_wakatani_new(alpha, is_modified); // Create Lua userdata. - struct wv_eqn_lw **l_hasegawa_wakatani_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw*)); + struct wv_eqn_lw **l_hasegawa_wakatani_lw = lua_newuserdata(L, sizeof(struct wv_eqn_lw *)); *l_hasegawa_wakatani_lw = hasegawa_wakatani_lw; // Point userdata to the equation object. - + // Set metatable. luaL_getmetatable(L, VLASOV_WAVE_EQN_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Equation constructor. static struct luaL_Reg eqn_hasegawa_wakatani_ctor[] = { - { "new", eqn_hasegawa_wakatani_lw_new }, - { 0, 0 } + {"new", eqn_hasegawa_wakatani_lw_new}, + {0, 0} }; // Register and load all wave equation objects. -static void -eqn_openlibs(lua_State *L) +static void eqn_openlibs(lua_State *L) { luaL_newmetatable(L, VLASOV_WAVE_EQN_METATABLE_NM); @@ -341,7 +312,7 @@ eqn_openlibs(lua_State *L) // Lua userdata object for constructing species input. struct vlasov_species_lw { int magic; // This must be first element in the struct. - + struct gkyl_vlasov_species vm_species; // Input struct to construct species. int vdim; // Velocity space dimensions. bool evolve; // Is this species evolved? @@ -353,10 +324,12 @@ struct vlasov_species_lw { struct lua_func_ctx metric_func_ref; // Lua registry reference to metric tensor function. bool has_inverse_metric_func; // Is there an inverse metric tensor function? - struct lua_func_ctx inverse_metric_func_ref; // Lua registry reference to inverse metric tensor function. + struct lua_func_ctx + inverse_metric_func_ref; // Lua registry reference to inverse metric tensor function. bool has_metric_determinant_func; // Is there a metric determinant function? - struct lua_func_ctx metric_determinant_func_ref; // Lua registry reference to metric determinant function. + struct lua_func_ctx + metric_determinant_func_ref; // Lua registry reference to metric determinant function. bool output_f_lte; // Should f_lte be written out (for calculating transport coefficients)? @@ -364,35 +337,45 @@ struct vlasov_species_lw { enum gkyl_projection_id proj_id[GKYL_MAX_PROJ]; // Projection type. bool has_init_func[GKYL_MAX_PROJ]; // Is there an initialization function? - struct lua_func_ctx init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to initialization function. + struct lua_func_ctx + init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to initialization function. bool has_density_init_func[GKYL_MAX_PROJ]; // Is there a density initialization function? - struct lua_func_ctx density_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to density initialization function. + struct lua_func_ctx + density_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to density initialization function. bool has_V_drift_init_func[GKYL_MAX_PROJ]; // Is there a drift velocity initialiation function? - struct lua_func_ctx V_drift_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to drift velocity initialization function. + struct lua_func_ctx V_drift_init_func_ref + [GKYL_MAX_PROJ]; // Lua registry reference to drift velocity initialization function. bool has_temp_init_func[GKYL_MAX_PROJ]; // Is there a temperature initialization function? - struct lua_func_ctx temp_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to temperature initialization function. + struct lua_func_ctx temp_init_func_ref + [GKYL_MAX_PROJ]; // Lua registry reference to temperature initialization function. - bool correct_all_moms[GKYL_MAX_PROJ]; // Are we correcting all moments in projections, or only density? - double iter_eps[GKYL_MAX_PROJ]; // Error tolerance for moment fixes in projections (density is always exact). + bool + correct_all_moms[GKYL_MAX_PROJ]; // Are we correcting all moments in projections, or only density? + double iter_eps + [GKYL_MAX_PROJ]; // Error tolerance for moment fixes in projections (density is always exact). int max_iter[GKYL_MAX_PROJ]; // Maximum number of iterations for moment fixes in projections. - bool use_last_converged[GKYL_MAX_PROJ]; // Use last iteration value in projections regardless of convergence? + bool use_last_converged + [GKYL_MAX_PROJ]; // Use last iteration value in projections regardless of convergence? enum gkyl_collision_id collision_id; // Collision type. - + bool has_self_nu_func; // Is there a self-collision frequency function? - struct lua_func_ctx self_nu_func_ref; // Lua registry reference to self-collision frequency function. + struct lua_func_ctx + self_nu_func_ref; // Lua registry reference to self-collision frequency function. int num_cross_collisions; // Number of species that we cross-collide with. char collide_with[GKYL_MAX_SPECIES][128]; // Names of species that we cross-collide with. bool collision_correct_all_moms; // Are we correcting all moments in collisions, or only density? - double collision_iter_eps; // Error tolerance for moment fixes in collisions (density is always exact). + double + collision_iter_eps; // Error tolerance for moment fixes in collisions (density is always exact). int collision_max_iter; // Maximum number of iterations for moment fixes in collisions. bool fixed_temp_relax; // Are BGK collisions relaxing to a fixed input temperature? - bool collision_use_last_converged; // Use last iteration value in collisions regardless of convergence? + bool + collision_use_last_converged; // Use last iteration value in collisions regardless of convergence? bool has_implicit_coll_scheme; // Use implicit scheme for collisions? enum gkyl_source_id source_id; // Source type. @@ -404,35 +387,46 @@ struct vlasov_species_lw { enum gkyl_projection_id source_proj_id[GKYL_MAX_PROJ]; // Projection type in source. bool source_has_init_func[GKYL_MAX_PROJ]; // Is there an initialization function in source? - struct lua_func_ctx source_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to initialization function in source. - - bool source_has_density_init_func[GKYL_MAX_PROJ]; // Is there a density initialization function in source? - struct lua_func_ctx source_density_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to density initialization function in source. - - bool source_has_V_drift_init_func[GKYL_MAX_PROJ]; // Is there a drift velocity initialization function in source? - struct lua_func_ctx source_V_drift_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to drift velocity initialization function in source. - - bool source_has_temp_init_func[GKYL_MAX_PROJ]; // Is there a temperature initialization function in source? - struct lua_func_ctx source_temp_init_func_ref[GKYL_MAX_PROJ]; // Lua registry reference to temperature initialization function in source. - - bool source_correct_all_moms[GKYL_MAX_PROJ]; // Are we correcting all moments in projections, or only density, in source? - double source_iter_eps[GKYL_MAX_PROJ]; // Error tolerance for moment fixes in projections (density is always exact) in source. - int source_max_iter[GKYL_MAX_PROJ]; // Maximum number of iterations for moment fixes in projections in source. - bool source_use_last_converged[GKYL_MAX_PROJ]; // Use last iteration value in projection regardless of convergence in source? + struct lua_func_ctx source_init_func_ref + [GKYL_MAX_PROJ]; // Lua registry reference to initialization function in source. + + bool source_has_density_init_func + [GKYL_MAX_PROJ]; // Is there a density initialization function in source? + struct lua_func_ctx source_density_init_func_ref + [GKYL_MAX_PROJ]; // Lua registry reference to density initialization function in source. + + bool source_has_V_drift_init_func + [GKYL_MAX_PROJ]; // Is there a drift velocity initialization function in source? + struct lua_func_ctx source_V_drift_init_func_ref + [GKYL_MAX_PROJ]; // Lua registry reference to drift velocity initialization function in source. + + bool source_has_temp_init_func + [GKYL_MAX_PROJ]; // Is there a temperature initialization function in source? + struct lua_func_ctx source_temp_init_func_ref + [GKYL_MAX_PROJ]; // Lua registry reference to temperature initialization function in source. + + bool source_correct_all_moms + [GKYL_MAX_PROJ]; // Are we correcting all moments in projections, or only density, in source? + double source_iter_eps + [GKYL_MAX_PROJ]; // Error tolerance for moment fixes in projections (density is always exact) in source. + int source_max_iter + [GKYL_MAX_PROJ]; // Maximum number of iterations for moment fixes in projections in source. + bool source_use_last_converged + [GKYL_MAX_PROJ]; // Use last iteration value in projection regardless of convergence in source? }; -static int -vlasov_species_lw_new(lua_State *L) +static int vlasov_species_lw_new(lua_State *L) { - int vdim = 0; - struct gkyl_vlasov_species vm_species = { }; + int vdim = 0; + struct gkyl_vlasov_species vm_species = {}; vm_species.model_id = glua_tbl_get_integer(L, "modelID", 0); - + vm_species.charge = glua_tbl_get_number(L, "charge", 0.0); vm_species.mass = glua_tbl_get_number(L, "mass", 1.0); - with_lua_tbl_tbl(L, "cells") { + with_lua_tbl_tbl(L, "cells") + { vdim = glua_objlen(L); for (int d = 0; d < vdim; d++) { @@ -440,13 +434,15 @@ vlasov_species_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "lower") { + with_lua_tbl_tbl(L, "lower") + { for (int d = 0; d < vdim; d++) { vm_species.lower[d] = glua_tbl_iget_number(L, d + 1, 0); } } - with_lua_tbl_tbl(L, "upper") { + with_lua_tbl_tbl(L, "upper") + { for (int d = 0; d < vdim; d++) { vm_species.upper[d] = glua_tbl_iget_number(L, d + 1, 0); } @@ -454,42 +450,52 @@ vlasov_species_lw_new(lua_State *L) bool evolve = glua_tbl_get_bool(L, "evolve", true); - with_lua_tbl_tbl(L, "diagnostics") { + with_lua_tbl_tbl(L, "diagnostics") + { int num_diag_moments = glua_objlen(L); - for (int i = 0; i < num_diag_moments; i ++) { - vm_species.diag_moments[i] = glua_tbl_iget_integer(L, i+1, 0); + for (int i = 0; i < num_diag_moments; i++) { + vm_species.diag_moments[i] = glua_tbl_iget_integer(L, i + 1, 0); } vm_species.num_diag_moments = num_diag_moments; } - with_lua_tbl_tbl(L, "bcx") { - with_lua_tbl_tbl(L, "lower") { + with_lua_tbl_tbl(L, "bcx") + { + with_lua_tbl_tbl(L, "lower") + { vm_species.bcx.lower.type = glua_tbl_get_integer(L, "type", 0); } - - with_lua_tbl_tbl(L, "upper") { + + with_lua_tbl_tbl(L, "upper") + { vm_species.bcx.upper.type = glua_tbl_get_integer(L, "type", 0); } } - with_lua_tbl_tbl(L, "bcy") { - with_lua_tbl_tbl(L, "lower") { + with_lua_tbl_tbl(L, "bcy") + { + with_lua_tbl_tbl(L, "lower") + { vm_species.bcy.lower.type = glua_tbl_get_integer(L, "type", 0); } - with_lua_tbl_tbl(L, "upper") { + with_lua_tbl_tbl(L, "upper") + { vm_species.bcy.upper.type = glua_tbl_get_integer(L, "type", 0); } } - with_lua_tbl_tbl(L, "bcz") { - with_lua_tbl_tbl(L, "lower") { + with_lua_tbl_tbl(L, "bcz") + { + with_lua_tbl_tbl(L, "lower") + { vm_species.bcz.lower.type = glua_tbl_get_integer(L, "type", 0); } - with_lua_tbl_tbl(L, "upper") { + with_lua_tbl_tbl(L, "upper") + { vm_species.bcz.upper.type = glua_tbl_get_integer(L, "type", 0); } } @@ -527,7 +533,7 @@ vlasov_species_lw_new(lua_State *L) } bool output_f_lte = glua_tbl_get_bool(L, "outputfLTE", false); - + enum gkyl_projection_id proj_id[GKYL_MAX_PROJ]; bool has_init_func[GKYL_MAX_PROJ]; @@ -541,7 +547,7 @@ vlasov_species_lw_new(lua_State *L) bool has_temp_init_func[GKYL_MAX_PROJ]; int temp_init_func_ref[GKYL_MAX_PROJ]; - + bool correct_all_moms[GKYL_MAX_PROJ]; double iter_eps[GKYL_MAX_PROJ]; int max_iter[GKYL_MAX_PROJ]; @@ -549,7 +555,8 @@ vlasov_species_lw_new(lua_State *L) int num_init = glua_tbl_get_integer(L, "numInit", 0); - with_lua_tbl_tbl(L, "projections") { + with_lua_tbl_tbl(L, "projections") + { for (int i = 0; i < num_init; i++) { if (glua_tbl_iget_tbl(L, i + 1)) { proj_id[i] = glua_tbl_get_integer(L, "projectionID", 0); @@ -607,7 +614,8 @@ vlasov_species_lw_new(lua_State *L) bool collision_use_last_converged = true; bool has_implicit_coll_scheme = false; - with_lua_tbl_tbl(L, "collisions") { + with_lua_tbl_tbl(L, "collisions") + { collision_id = glua_tbl_get_integer(L, "collisionID", 0); if (glua_tbl_get_func(L, "selfNu")) { @@ -616,9 +624,10 @@ vlasov_species_lw_new(lua_State *L) } num_cross_collisions = glua_tbl_get_integer(L, "numCrossCollisions", 0); - with_lua_tbl_tbl(L, "collideWith") { + with_lua_tbl_tbl(L, "collideWith") + { for (int i = 0; i < num_cross_collisions; i++) { - const char* collide_with_char = glua_tbl_iget_string(L, i + 1, ""); + const char *collide_with_char = glua_tbl_iget_string(L, i + 1, ""); strcpy(collide_with[i], collide_with_char); } } @@ -634,7 +643,7 @@ vlasov_species_lw_new(lua_State *L) enum gkyl_source_id source_id = GKYL_NO_SOURCE; double source_length = 1.0; - char source_species[128] = { '\0' }; + char source_species[128] = {'\0'}; int num_sources = 0; enum gkyl_projection_id source_proj_id[GKYL_MAX_PROJ]; @@ -656,16 +665,18 @@ vlasov_species_lw_new(lua_State *L) int source_max_iter[GKYL_MAX_PROJ]; bool source_use_last_converged[GKYL_MAX_PROJ]; - with_lua_tbl_tbl(L, "source") { + with_lua_tbl_tbl(L, "source") + { source_id = glua_tbl_get_integer(L, "sourceID", 0); source_length = glua_tbl_get_number(L, "sourceLength", 1.0); - const char* source_species_char = glua_tbl_get_string(L, "sourceSpecies", ""); + const char *source_species_char = glua_tbl_get_string(L, "sourceSpecies", ""); strcpy(source_species, source_species_char); num_sources = glua_tbl_get_integer(L, "numSources", 0); - with_lua_tbl_tbl(L, "projections") { + with_lua_tbl_tbl(L, "projections") + { for (int i = 0; i < num_sources; i++) { if (glua_tbl_iget_tbl(L, i + 1)) { source_proj_id[i] = glua_tbl_get_integer(L, "projectionID", 0); @@ -708,7 +719,7 @@ vlasov_species_lw_new(lua_State *L) } } } - + struct vlasov_species_lw *vms_lw = lua_newuserdata(L, sizeof(*vms_lw)); vms_lw->magic = VLASOV_SPECIES_DEFAULT; vms_lw->vdim = vdim; @@ -716,37 +727,32 @@ vlasov_species_lw_new(lua_State *L) vms_lw->vm_species = vm_species; vms_lw->has_hamiltonian_func = has_hamiltonian_func; - vms_lw->hamiltonian_func_ref = (struct lua_func_ctx) { - .func_ref = hamiltonian_func_ref, + vms_lw->hamiltonian_func_ref = (struct lua_func_ctx + ){.func_ref = hamiltonian_func_ref, .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; vms_lw->has_metric_func = has_metric_func; - vms_lw->metric_func_ref = (struct lua_func_ctx) { - .func_ref = metric_func_ref, + vms_lw->metric_func_ref = (struct lua_func_ctx + ){.func_ref = metric_func_ref, .ndim = 0, // This will be set later. .nret = (vdim * (vdim + 1)) / 2, - .L = L, - }; - + .L = L}; vms_lw->has_inverse_metric_func = has_inverse_metric_func; - vms_lw->inverse_metric_func_ref = (struct lua_func_ctx) { - .func_ref = inverse_metric_func_ref, + vms_lw->inverse_metric_func_ref = (struct lua_func_ctx + ){.func_ref = inverse_metric_func_ref, .ndim = 0, // This will be set later. .nret = (vdim * (vdim + 1)) / 2, - .L = L, - }; + .L = L}; vms_lw->has_metric_determinant_func = has_metric_determinant_func; - vms_lw->metric_determinant_func_ref = (struct lua_func_ctx) { - .func_ref = metric_determinant_func_ref, + vms_lw->metric_determinant_func_ref = (struct lua_func_ctx + ){.func_ref = metric_determinant_func_ref, .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; vms_lw->output_f_lte = output_f_lte; @@ -755,36 +761,32 @@ vlasov_species_lw_new(lua_State *L) vms_lw->proj_id[i] = proj_id[i]; vms_lw->has_init_func[i] = has_init_func[i]; - vms_lw->init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = init_func_ref[i], + vms_lw->init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = init_func_ref[i], .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; vms_lw->has_density_init_func[i] = has_density_init_func[i]; - vms_lw->density_init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = density_init_func_ref[i], + vms_lw->density_init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = density_init_func_ref[i], .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; vms_lw->has_V_drift_init_func[i] = has_V_drift_init_func[i]; - vms_lw->V_drift_init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = V_drift_init_func_ref[i], + vms_lw->V_drift_init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = V_drift_init_func_ref[i], .ndim = 0, // This will be set later. .nret = vdim, - .L = L, - }; + .L = L}; vms_lw->has_temp_init_func[i] = has_temp_init_func[i]; - vms_lw->temp_init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = temp_init_func_ref[i], + vms_lw->temp_init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = temp_init_func_ref[i], .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; vms_lw->correct_all_moms[i] = correct_all_moms[i]; vms_lw->iter_eps[i] = iter_eps[i]; @@ -797,52 +799,44 @@ vlasov_species_lw_new(lua_State *L) strcpy(vms_lw->source_species, source_species); vms_lw->source_length = source_length; - + for (int i = 0; i < num_sources; i++) { vms_lw->source_proj_id[i] = source_proj_id[i]; vms_lw->source_has_init_func[i] = source_has_init_func[i]; - vms_lw->source_init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = source_init_func_ref[i], + vms_lw->source_init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = source_init_func_ref[i], .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; vms_lw->source_has_density_init_func[i] = source_has_density_init_func[i]; - vms_lw->source_density_init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = source_density_init_func_ref[i], + vms_lw->source_density_init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = source_density_init_func_ref[i], .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; vms_lw->source_has_V_drift_init_func[i] = source_has_V_drift_init_func[i]; - vms_lw->source_V_drift_init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = source_V_drift_init_func_ref[i], + vms_lw->source_V_drift_init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = source_V_drift_init_func_ref[i], .ndim = 0, // This will be set later. .nret = vdim, - .L = L, - }; + .L = L}; vms_lw->source_has_temp_init_func[i] = source_has_temp_init_func[i]; - vms_lw->source_temp_init_func_ref[i] = (struct lua_func_ctx) { - .func_ref = source_temp_init_func_ref[i], + vms_lw->source_temp_init_func_ref[i] = (struct lua_func_ctx + ){.func_ref = source_temp_init_func_ref[i], .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; } vms_lw->collision_id = collision_id; vms_lw->has_self_nu_func = has_self_nu_func; - vms_lw->self_nu_func_ref = (struct lua_func_ctx) { - .func_ref = self_nu_func_ref, - .ndim = 0, - .nret = 1, - .L = L, - }; + vms_lw->self_nu_func_ref = + (struct lua_func_ctx){.func_ref = self_nu_func_ref, .ndim = 0, .nret = 1, .L = L}; vms_lw->num_cross_collisions = num_cross_collisions; for (int i = 0; i < num_cross_collisions; i++) { @@ -855,19 +849,16 @@ vlasov_species_lw_new(lua_State *L) vms_lw->fixed_temp_relax = fixed_temp_relax; vms_lw->collision_use_last_converged = collision_use_last_converged; vms_lw->has_implicit_coll_scheme = has_implicit_coll_scheme; - + // Set metatable. luaL_getmetatable(L, VLASOV_SPECIES_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Species constructor. -static struct luaL_Reg vm_species_ctor[] = { - { "new", vlasov_species_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg vm_species_ctor[] = {{"new", vlasov_species_lw_new}, {0, 0}}; /* ********************* */ /* Fluid Species methods */ @@ -879,7 +870,7 @@ static struct luaL_Reg vm_species_ctor[] = { // Lua userdata object for constructing fluid species input. struct vlasov_fluid_species_lw { int magic; // This must be first element in the struct. - + struct gkyl_vlasov_fluid_species vlasov_fluid_species; // Input struct to construct fluid species. struct lua_func_ctx init_ctx; // Lua registry reference to initialization function. @@ -888,22 +879,22 @@ struct vlasov_fluid_species_lw { bool has_n0_func; // Is there a background density function? struct lua_func_ctx n0_func_ref; // Lua registry reference to background density function. - + bool has_diffusion_func; // Is there a diffusion tensor function? struct lua_func_ctx diffusion_func_ref; // Lua registry reference to diffusion tensor function. }; -static int -vlasov_fluid_species_lw_new(lua_State *L) +static int vlasov_fluid_species_lw_new(lua_State *L) { - int vdim = 0; - struct gkyl_vlasov_fluid_species vm_fluid_species = { }; + int vdim = 0; + struct gkyl_vlasov_fluid_species vm_fluid_species = {}; vm_fluid_species.charge = glua_tbl_get_number(L, "charge", 0.0); vm_fluid_species.mass = glua_tbl_get_number(L, "mass", 1.0); bool has_eqn = false; - with_lua_tbl_key(L, "equation") { + with_lua_tbl_key(L, "equation") + { vm_fluid_species.equation = wv_eqn_get(L); has_eqn = true; } @@ -914,24 +905,22 @@ vlasov_fluid_species_lw_new(lua_State *L) // simulation is being set up. lua_getfield(L, -1, "equation"); int eq_ref = luaL_ref(L, LUA_REGISTRYINDEX); - + lua_getglobal(L, "__vlasov_ref_table"); int eqtbl_len = glua_objlen(L); - lua_pushinteger(L, eqtbl_len+1); + lua_pushinteger(L, eqtbl_len + 1); lua_rawgeti(L, LUA_REGISTRYINDEX, eq_ref); lua_rawset(L, -3); lua_pop(L, 1); - } - else { + } else { return luaL_error(L, "Fluid species \"equation\" not specfied or incorrect type!"); } int init_ref = LUA_NOREF; if (glua_tbl_get_func(L, "init")) { init_ref = luaL_ref(L, LUA_REGISTRYINDEX); - } - else { + } else { return luaL_error(L, "Fluid species must have an \"init\" function for initial conditions!"); } @@ -954,17 +943,19 @@ vlasov_fluid_species_lw_new(lua_State *L) bool has_diffusion_func = false; int diffusion_func_ref = LUA_NOREF; - with_lua_tbl_tbl(L, "diffusion") { + with_lua_tbl_tbl(L, "diffusion") + { vm_fluid_species.diffusion.D = glua_tbl_get_number(L, "diffusionCoefficient", 0.0); vm_fluid_species.diffusion.order = glua_tbl_get_integer(L, "diffusionOrder", 2); - + if (glua_tbl_get_func(L, "diffusionTensor")) { diffusion_func_ref = luaL_ref(L, LUA_REGISTRYINDEX); has_diffusion_func = true; } } - with_lua_tbl_tbl(L, "bcx") { + with_lua_tbl_tbl(L, "bcx") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -972,7 +963,8 @@ vlasov_fluid_species_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcy") { + with_lua_tbl_tbl(L, "bcy") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -980,7 +972,8 @@ vlasov_fluid_species_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcz") { + with_lua_tbl_tbl(L, "bcz") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -992,49 +985,42 @@ vlasov_fluid_species_lw_new(lua_State *L) vmfs_lw->magic = VLASOV_FLUID_SPECIES_DEFAULT; vmfs_lw->vlasov_fluid_species = vm_fluid_species; - vmfs_lw->init_ctx = (struct lua_func_ctx) { - .func_ref = init_ref, + vmfs_lw->init_ctx = (struct lua_func_ctx + ){.func_ref = init_ref, .ndim = 0, // This will be set later. .nret = vm_fluid_species.equation->num_equations, - .L = L, - }; + .L = L}; vmfs_lw->has_app_advect_func = has_app_advect_func; - vmfs_lw->app_advect_func_ref = (struct lua_func_ctx) { - .func_ref = app_advect_func_ref, + vmfs_lw->app_advect_func_ref = (struct lua_func_ctx + ){.func_ref = app_advect_func_ref, .ndim = 0, // This will be set later. .nret = 3, - .L = L, - }; + .L = L}; vmfs_lw->has_n0_func = has_n0_func; - vmfs_lw->n0_func_ref = (struct lua_func_ctx) { - .func_ref = n0_func_ref, + vmfs_lw->n0_func_ref = (struct lua_func_ctx + ){.func_ref = n0_func_ref, .ndim = 0, // This will be set later. .nret = 1, - .L = L, - }; + .L = L}; vmfs_lw->has_diffusion_func = has_diffusion_func; - vmfs_lw->diffusion_func_ref = (struct lua_func_ctx) { - .func_ref = diffusion_func_ref, + vmfs_lw->diffusion_func_ref = (struct lua_func_ctx + ){.func_ref = diffusion_func_ref, .ndim = 0, // This will be set later. .nret = 1, // This will be set later. - .L = L, - }; - + .L = L}; + // Set metatable. luaL_getmetatable(L, VLASOV_FLUID_SPECIES_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Species constructor. -static struct luaL_Reg vm_fluid_species_ctor[] = { - { "new", vlasov_fluid_species_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg vm_fluid_species_ctor[] = {{"new", vlasov_fluid_species_lw_new}, {0, 0}}; /* ************* */ /* Field methods */ @@ -1046,32 +1032,34 @@ static struct luaL_Reg vm_fluid_species_ctor[] = { // Lua userdata object for constructing field input. struct vlasov_field_lw { int magic; // This must be first element in the struct. - + struct gkyl_vlasov_field vm_field; // Input struct to construct field. bool evolve; // Is this field evolved? struct lua_func_ctx init_ref; // Lua registry reference to initilization function. bool has_external_potential_func; // Is there an external potential initialization function? - struct lua_func_ctx external_potential_func_ref; // Lua registry reference to external potential initialization function. + struct lua_func_ctx + external_potential_func_ref; // Lua registry reference to external potential initialization function. bool evolve_external_potential; // Is the external potential evolved? bool has_external_field_func; // Is there an external field initialization function? - struct lua_func_ctx external_field_func_ref; // Lua registry reference to external field initialization function. + struct lua_func_ctx + external_field_func_ref; // Lua registry reference to external field initialization function. bool evolve_external_field; // Is the external field evolved? bool has_applied_current_func; // Is there an applied current initialization function? - struct lua_func_ctx applied_current_func_ref; // Lua registry reference to applied current initialization function. + struct lua_func_ctx + applied_current_func_ref; // Lua registry reference to applied current initialization function. bool evolve_applied_current; // Is the applied current evolved? }; -static int -vlasov_field_lw_new(lua_State *L) +static int vlasov_field_lw_new(lua_State *L) { - int vdim = 0; - struct gkyl_vlasov_field vm_field = { }; + int vdim = 0; + struct gkyl_vlasov_field vm_field = {}; vm_field.field_id = GKYL_FIELD_E_B; - + vm_field.epsilon0 = glua_tbl_get_number(L, "epsilon0", 1.0); vm_field.mu0 = glua_tbl_get_number(L, "mu0", 1.0); vm_field.elcErrorSpeedFactor = glua_tbl_get_number(L, "elcErrorSpeedFactor", 0.0); @@ -1087,7 +1075,8 @@ vlasov_field_lw_new(lua_State *L) init_ref = luaL_ref(L, LUA_REGISTRYINDEX); } - with_lua_tbl_tbl(L, "bcx") { + with_lua_tbl_tbl(L, "bcx") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -1095,7 +1084,8 @@ vlasov_field_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcy") { + with_lua_tbl_tbl(L, "bcy") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -1103,7 +1093,8 @@ vlasov_field_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "bcz") { + with_lua_tbl_tbl(L, "bcz") + { int nbc = glua_objlen(L); for (int i = 0; i < (nbc > 2 ? 2 : nbc); i++) { @@ -1111,16 +1102,19 @@ vlasov_field_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "poissonBcs") { - with_lua_tbl_tbl(L, "lowerType") { + with_lua_tbl_tbl(L, "poissonBcs") + { + with_lua_tbl_tbl(L, "lowerType") + { int nbc = glua_objlen(L); - + for (int i = 0; i < nbc; i++) { vm_field.poisson_bcs.lo_type[i] = glua_tbl_iget_integer(L, i + 1, 0); } } - with_lua_tbl_tbl(L, "upperType") { + with_lua_tbl_tbl(L, "upperType") + { int nbc = glua_objlen(L); for (int i = 0; i < nbc; i++) { @@ -1128,25 +1122,23 @@ vlasov_field_lw_new(lua_State *L) } } - with_lua_tbl_tbl(L, "lowerValue") { + with_lua_tbl_tbl(L, "lowerValue") + { int nbc = glua_objlen(L); for (int i = 0; i < nbc; i++) { - struct gkyl_poisson_bc_value lower_bc = { - .v = { glua_tbl_iget_number(L, i + 1, 0.0) }, - }; + struct gkyl_poisson_bc_value lower_bc = {.v = {glua_tbl_iget_number(L, i + 1, 0.0)}}; vm_field.poisson_bcs.lo_value[i] = lower_bc; } } - with_lua_tbl_tbl(L, "upperValue") { + with_lua_tbl_tbl(L, "upperValue") + { int nbc = glua_objlen(L); for (int i = 0; i < nbc; i++) { - struct gkyl_poisson_bc_value upper_bc = { - .v = { glua_tbl_iget_number(L, i + 1, 0.0) }, - }; + struct gkyl_poisson_bc_value upper_bc = {.v = {glua_tbl_iget_number(L, i + 1, 0.0)}}; vm_field.poisson_bcs.up_value[i] = upper_bc; } @@ -1191,53 +1183,46 @@ vlasov_field_lw_new(lua_State *L) vmf_lw->magic = VLASOV_FIELD_DEFAULT; vmf_lw->evolve = evolve; vmf_lw->vm_field = vm_field; - - vmf_lw->init_ref = (struct lua_func_ctx) { - .func_ref = init_ref, + + vmf_lw->init_ref = (struct lua_func_ctx + ){.func_ref = init_ref, .ndim = 0, // This will be set later. .nret = 6, - .L = L, - }; + .L = L}; vmf_lw->has_external_potential_func = has_external_potential_func; - vmf_lw->external_potential_func_ref = (struct lua_func_ctx) { - .func_ref = external_potential_func_ref, + vmf_lw->external_potential_func_ref = (struct lua_func_ctx + ){.func_ref = external_potential_func_ref, .ndim = 0, // This will be set later. .nret = 4, - .L = L, - }; + .L = L}; vmf_lw->evolve_external_potential = evolve_external_potential; vmf_lw->has_external_field_func = has_external_field_func; - vmf_lw->external_field_func_ref = (struct lua_func_ctx) { - .func_ref = external_field_func_ref, + vmf_lw->external_field_func_ref = (struct lua_func_ctx + ){.func_ref = external_field_func_ref, .ndim = 0, // This will be set later. .nret = 6, - .L = L, - }; + .L = L}; vmf_lw->evolve_external_field = evolve_external_field; vmf_lw->has_applied_current_func = has_applied_current_func; - vmf_lw->applied_current_func_ref = (struct lua_func_ctx) { - .func_ref = applied_current_func_ref, + vmf_lw->applied_current_func_ref = (struct lua_func_ctx + ){.func_ref = applied_current_func_ref, .ndim = 0, // This will be set later. .nret = 3, - .L = L, - }; + .L = L}; vmf_lw->evolve_applied_current = evolve_applied_current; - + // Set metatable. luaL_getmetatable(L, VLASOV_FIELD_METATABLE_NM); lua_setmetatable(L, -2); - + return 1; } // Field constructor. -static struct luaL_Reg vm_field_ctor[] = { - { "new", vlasov_field_lw_new }, - { 0, 0 } -}; +static struct luaL_Reg vm_field_ctor[] = {{"new", vlasov_field_lw_new}, {0, 0}}; /* *********** */ /* App methods */ @@ -1251,52 +1236,81 @@ struct vlasov_app_lw { gkyl_vlasov_app *app; // Vlasov app object. bool has_hamiltonian_func[GKYL_MAX_SPECIES]; // Is there a Hamiltonian function? - struct lua_func_ctx hamiltonian_func_ctx[GKYL_MAX_SPECIES]; // Lua registry reference to Hamiltonian function. + struct lua_func_ctx + hamiltonian_func_ctx[GKYL_MAX_SPECIES]; // Lua registry reference to Hamiltonian function. bool has_metric_func[GKYL_MAX_SPECIES]; // Is there an inverse metric tensor function? - struct lua_func_ctx metric_func_ctx[GKYL_MAX_SPECIES]; // Lua registry reference to inverse metric tensor function. + struct lua_func_ctx + metric_func_ctx[GKYL_MAX_SPECIES]; // Lua registry reference to inverse metric tensor function. bool has_inverse_metric_func[GKYL_MAX_SPECIES]; // Is there an inverse metric tensor function? - struct lua_func_ctx inverse_metric_func_ctx[GKYL_MAX_SPECIES]; // Lua registry reference to inverse metric tensor function. + struct lua_func_ctx inverse_metric_func_ctx + [GKYL_MAX_SPECIES]; // Lua registry reference to inverse metric tensor function. bool has_metric_determinant_func[GKYL_MAX_SPECIES]; // Is there a metric determinant function? - struct lua_func_ctx metric_determinant_func_ctx[GKYL_MAX_SPECIES]; // Lua registry reference to metric determinant function. + struct lua_func_ctx metric_determinant_func_ctx + [GKYL_MAX_SPECIES]; // Lua registry reference to metric determinant function. - bool output_f_lte[GKYL_MAX_SPECIES]; // Should f_lte be written out (for calculating transport coefficients)? + bool output_f_lte + [GKYL_MAX_SPECIES]; // Should f_lte be written out (for calculating transport coefficients)? int num_init[GKYL_MAX_SPECIES]; // Number of projection objects. enum gkyl_projection_id proj_id[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Projection type. bool has_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there an initialization function? - struct lua_func_ctx init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for initialization function. - - bool has_density_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a density initialization function? - struct lua_func_ctx density_init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for density initialization function. - - bool has_V_drift_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a drift velocity initialization function? - struct lua_func_ctx V_drift_init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for drift velocity initialziation function. - - bool has_temp_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a temperature initialization function? - struct lua_func_ctx temp_init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for temperature initialization function. - - bool correct_all_moms[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Are we correcting all moments in projections, or only density? - double iter_eps[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Error tolerance for moment fixes in projections (density is always exact). - int max_iter[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Maximum number of iterations for moment fixes in projections. - bool use_last_converged[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Use last iteration value in projections regardless of convergence? + struct lua_func_ctx init_func_ctx[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Context for initialization function. + + bool has_density_init_func[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Is there a density initialization function? + struct lua_func_ctx + density_init_func_ctx[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Context for density initialization function. + + bool has_V_drift_init_func[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Is there a drift velocity initialization function? + struct lua_func_ctx + V_drift_init_func_ctx[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Context for drift velocity initialziation function. + + bool has_temp_init_func[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Is there a temperature initialization function? + struct lua_func_ctx + temp_init_func_ctx[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Context for temperature initialization function. + + bool + correct_all_moms[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Are we correcting all moments in projections, or only density? + double iter_eps + [GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Error tolerance for moment fixes in projections (density is always exact). + int max_iter[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Maximum number of iterations for moment fixes in projections. + bool use_last_converged + [GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Use last iteration value in projections regardless of convergence? enum gkyl_collision_id collision_id[GKYL_MAX_SPECIES]; // Collision type. bool has_self_nu_func[GKYL_MAX_SPECIES]; // Is there a self-collision frequency function? - struct lua_func_ctx self_nu_func_ctx[GKYL_MAX_SPECIES]; // Context for self-collision frequency function. + struct lua_func_ctx + self_nu_func_ctx[GKYL_MAX_SPECIES]; // Context for self-collision frequency function. int num_cross_collisions[GKYL_MAX_SPECIES]; // Number of species that we cross-collide with. - char collide_with[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES][128]; // Names of species that we cross-collide with. - - bool collision_correct_all_moms[GKYL_MAX_SPECIES]; // Are we correcting all moments in collisions, or only density? - double collision_iter_eps[GKYL_MAX_SPECIES]; // Error tolerance for moment fixes in collision (density is always exact). - int collision_max_iter[GKYL_MAX_SPECIES]; // Maximum number of iterations for moment fixes in collisions. - bool fixed_temp_relax[GKYL_MAX_SPECIES]; // Are BGK collisions relaxing to a fixed input temperature? - bool collision_use_last_converged[GKYL_MAX_SPECIES]; // Use last iteration value in collisions regardless of convergence? + char collide_with[GKYL_MAX_SPECIES][GKYL_MAX_SPECIES] + [128]; // Names of species that we cross-collide with. + + bool collision_correct_all_moms + [GKYL_MAX_SPECIES]; // Are we correcting all moments in collisions, or only density? + double collision_iter_eps + [GKYL_MAX_SPECIES]; // Error tolerance for moment fixes in collision (density is always exact). + int collision_max_iter + [GKYL_MAX_SPECIES]; // Maximum number of iterations for moment fixes in collisions. + bool + fixed_temp_relax[GKYL_MAX_SPECIES]; // Are BGK collisions relaxing to a fixed input temperature? + bool collision_use_last_converged + [GKYL_MAX_SPECIES]; // Use last iteration value in collisions regardless of convergence? bool has_implicit_coll_scheme[GKYL_MAX_SPECIES]; // Use implicit scheme for collisions? enum gkyl_source_id source_id[GKYL_MAX_SPECIES]; // Source type. @@ -1305,36 +1319,59 @@ struct vlasov_app_lw { char source_species[GKYL_MAX_SPECIES][128]; // Name of speccies to use for the source. int num_sources[GKYL_MAX_SPECIES]; // Number of projection objects in source. - enum gkyl_projection_id source_proj_id[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Projection type in source. - - bool source_has_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there an initialization function in source? - struct lua_func_ctx source_init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for initialization function in source. - - bool source_has_density_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a density initialization function in source? - struct lua_func_ctx source_density_init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for density initialization function in source. - - bool source_has_V_drift_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a drift velocity initialization function in source? - struct lua_func_ctx source_V_drift_init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for drift velocity initialization function in source. - - bool source_has_temp_init_func[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a temperature initialization function in source? - struct lua_func_ctx source_temp_init_func_ctx[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for temperature initialization function in source. - - bool source_correct_all_moms[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Are we correcting all moments in projections, or only density, in source? - double source_iter_eps[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Error tolerance for moment fixes in projections (density is always exact) in source. - int source_max_iter[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Maximum number of iterations for moment fixes in projections in source. - bool source_use_last_converged[GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Use last iteration value in projection regardless of convergence in source? - - struct lua_func_ctx fluid_species_init_ctx[GKYL_MAX_SPECIES]; // Function context for fluid species initial conditions. - - struct lua_func_ctx app_advect_func_ctx[GKYL_MAX_SPECIES]; // Function context for fluid species applied advection. - struct lua_func_ctx n0_func_ctx[GKYL_MAX_SPECIES]; // Function context for fluid species background density. - struct lua_func_ctx diffusion_func_ctx[GKYL_MAX_SPECIES]; // Function context for fluid species diffusion tensor. + enum gkyl_projection_id source_proj_id[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Projection type in source. + + bool source_has_init_func[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Is there an initialization function in source? + struct lua_func_ctx + source_init_func_ctx[GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Context for initialization function in source. + + bool source_has_density_init_func + [GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a density initialization function in source? + struct lua_func_ctx source_density_init_func_ctx + [GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for density initialization function in source. + + bool source_has_V_drift_init_func + [GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a drift velocity initialization function in source? + struct lua_func_ctx source_V_drift_init_func_ctx + [GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Context for drift velocity initialization function in source. + + bool source_has_temp_init_func + [GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Is there a temperature initialization function in source? + struct lua_func_ctx source_temp_init_func_ctx + [GKYL_MAX_SPECIES][GKYL_MAX_PROJ]; // Context for temperature initialization function in source. + + bool source_correct_all_moms + [GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Are we correcting all moments in projections, or only density, in source? + double source_iter_eps + [GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Error tolerance for moment fixes in projections (density is always exact) in source. + int source_max_iter + [GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Maximum number of iterations for moment fixes in projections in source. + bool source_use_last_converged + [GKYL_MAX_SPECIES] + [GKYL_MAX_PROJ]; // Use last iteration value in projection regardless of convergence in source? + + struct lua_func_ctx + fluid_species_init_ctx[GKYL_MAX_SPECIES]; // Function context for fluid species initial conditions. + + struct lua_func_ctx + app_advect_func_ctx[GKYL_MAX_SPECIES]; // Function context for fluid species applied advection. + struct lua_func_ctx + n0_func_ctx[GKYL_MAX_SPECIES]; // Function context for fluid species background density. + struct lua_func_ctx + diffusion_func_ctx[GKYL_MAX_SPECIES]; // Function context for fluid species diffusion tensor. struct lua_func_ctx field_func_ctx; // Function context for field. struct lua_func_ctx external_potential_func_ctx; // Function context for external potential. struct lua_func_ctx external_field_func_ctx; // Function context for external field. struct lua_func_ctx applied_current_func_ctx; // Function context for applied current. - + double t_start, t_end; // Start and end times of simulation. int num_frames; // Number of data frames to write. int field_energy_calcs; // Number of times to calculate field energy. @@ -1351,7 +1388,7 @@ static int get_species_inp(lua_State *L, int cdim, struct vlasov_species_lw *species[GKYL_MAX_SPECIES]) { enum { TKEY = -2, TVAL = -1 }; - + int curr = 0; lua_pushnil(L); // Initial key is nil. while (lua_next(L, TKEY) != 0) { @@ -1384,7 +1421,7 @@ get_species_inp(lua_State *L, int cdim, struct vlasov_species_lw *species[GKYL_M if (vms->has_density_init_func[i]) { vms->density_init_func_ref[i].ndim = cdim; } - + if (vms->has_V_drift_init_func[i]) { vms->V_drift_init_func_ref[i].ndim = cdim; } @@ -1415,8 +1452,8 @@ get_species_inp(lua_State *L, int cdim, struct vlasov_species_lw *species[GKYL_M vms->source_temp_init_func_ref[i].ndim = cdim; } } - - if (lua_type(L,TKEY) == LUA_TSTRING) { + + if (lua_type(L, TKEY) == LUA_TSTRING) { const char *key = lua_tolstring(L, TKEY, 0); strcpy(vms->vm_species.name, key); } @@ -1430,8 +1467,7 @@ get_species_inp(lua_State *L, int cdim, struct vlasov_species_lw *species[GKYL_M } // Comparison method to sort species array by species name. -static int -species_compare_func(const void *a, const void *b) +static int species_compare_func(const void *a, const void *b) { const struct vlasov_species_lw *const *spa = a; const struct vlasov_species_lw *const *spb = b; @@ -1441,11 +1477,12 @@ species_compare_func(const void *a, const void *b) // Gets all fluid species objects from the App table, which must on top of // the stack. The number of fluid species is returned and the appropriate // pointers set in the fluid species pointer array. -static int -get_fluid_species_inp(lua_State *L, int cdim, struct vlasov_fluid_species_lw *fluid_species[GKYL_MAX_SPECIES]) +static int get_fluid_species_inp( + lua_State *L, int cdim, struct vlasov_fluid_species_lw *fluid_species[GKYL_MAX_SPECIES] +) { enum { TKEY = -2, TVAL = -1 }; - + int curr = 0; lua_pushnil(L); // Initial key is nil. while (lua_next(L, TKEY) != 0) { @@ -1454,10 +1491,9 @@ get_fluid_species_inp(lua_State *L, int cdim, struct vlasov_fluid_species_lw *fl struct vlasov_fluid_species_lw *vmfs = lua_touserdata(L, TVAL); if (vmfs->magic == VLASOV_FLUID_SPECIES_DEFAULT) { - vmfs->init_ctx.ndim = cdim; - - if (lua_type(L,TKEY) == LUA_TSTRING) { + + if (lua_type(L, TKEY) == LUA_TSTRING) { const char *key = lua_tolstring(L, TKEY, 0); strcpy(vmfs->vlasov_fluid_species.name, key); } @@ -1471,28 +1507,26 @@ get_fluid_species_inp(lua_State *L, int cdim, struct vlasov_fluid_species_lw *fl } // Comparison method to sort fluid species array by fluid species name. -static int -fluid_species_compare_func(const void *a, const void *b) +static int fluid_species_compare_func(const void *a, const void *b) { const struct vlasov_fluid_species_lw *const *spa = a; const struct vlasov_fluid_species_lw *const *spb = b; return strcmp((*spa)->vlasov_fluid_species.name, (*spb)->vlasov_fluid_species.name); } -static struct gkyl_tool_args * -tool_args_from_argv(int optind, int argc, char *const*argv) +static struct gkyl_tool_args *tool_args_from_argv(int optind, int argc, char *const *argv) { struct gkyl_tool_args *targs = gkyl_malloc(sizeof *targs); - - targs->argc = argc-optind; + + targs->argc = argc - optind; targs->argv = 0; if (targs->argc > 0) { - targs->argv = gkyl_malloc(targs->argc*sizeof(char *)); - for (int i = optind, j = 0; i < argc; ++i, ++j) { - targs->argv[j] = gkyl_malloc(strlen(argv[i])+1); - strcpy(targs->argv[j], argv[i]); - } + targs->argv = gkyl_malloc(targs->argc * sizeof(char *)); + for (int i = optind, j = 0; i < argc; ++i, ++j) { + targs->argv[j] = gkyl_malloc(strlen(argv[i]) + 1); + strcpy(targs->argv[j], argv[i]); + } } return targs; @@ -1509,15 +1543,14 @@ struct script_cli { bool use_verbose; // Should we use verbose output? bool is_restart; // Is this a restarted simulation? int restart_frame; // Which frame to restart simulation from. - + struct gkyl_tool_args *rest; }; -static struct script_cli -vm_parse_script_cli(struct gkyl_tool_args *acv) +static struct script_cli vm_parse_script_cli(struct gkyl_tool_args *acv) { struct script_cli cli = { - .help =- false, + .help = -false, .step_mode = false, .num_steps = INT_MAX, .use_mpi = false, @@ -1525,7 +1558,7 @@ vm_parse_script_cli(struct gkyl_tool_args *acv) .trace_mem = false, .use_verbose = false, .is_restart = false, - .restart_frame = 0, + .restart_frame = 0 }; #ifdef GKYL_HAVE_MPI @@ -1534,58 +1567,55 @@ vm_parse_script_cli(struct gkyl_tool_args *acv) #ifdef GKYL_HAVE_CUDA cli.use_gpu = true; #endif - - coption_long longopts[] = { - { 0 } - }; - const char* shortopts = "+hVs:SGmr:"; + + coption_long longopts[] = {{0}}; + const char *shortopts = "+hVs:SGmr:"; coption opt = coption_init(); int c; while ((c = coption_get(&opt, acv->argc, acv->argv, shortopts, longopts)) != -1) { switch (c) { - case 'h': - cli.help = true; - break; + case 'h': + cli.help = true; + break; - case 's': - cli.num_steps = atoi(opt.arg); - break; - - case 'S': - cli.use_mpi = false; - break; - - case 'G': - cli.use_gpu = false; - break; - - case 'm': - cli.trace_mem = true; - break; - - case 'V': - cli.use_verbose = true; - break; - - case 'r': - cli.is_restart = true; - cli.restart_frame = atoi(opt.arg); - break; - - case '?': - break; + case 's': + cli.num_steps = atoi(opt.arg); + break; + + case 'S': + cli.use_mpi = false; + break; + + case 'G': + cli.use_gpu = false; + break; + + case 'm': + cli.trace_mem = true; + break; + + case 'V': + cli.use_verbose = true; + break; + + case 'r': + cli.is_restart = true; + cli.restart_frame = atoi(opt.arg); + break; + + case '?': + break; } } cli.rest = tool_args_from_argv(opt.ind, acv->argc, acv->argv); - + return cli; } // Create top-level App object. -static int -vm_app_new(lua_State *L) +static int vm_app_new(lua_State *L) { struct vlasov_app_lw *app_lw = gkyl_malloc(sizeof(*app_lw)); @@ -1593,12 +1623,13 @@ vm_app_new(lua_State *L) // GKYL_OUT_PREFIX. If this is not found then "g0-vlasov" is used. const char *sim_name = "g0-vlasov"; - with_lua_global(L, "GKYL_OUT_PREFIX") { + with_lua_global(L, "GKYL_OUT_PREFIX") + { if (lua_isstring(L, -1)) { sim_name = lua_tostring(L, -1); } } - + // Initialize app using table inputs (table is on top of stack). app_lw->t_start = glua_tbl_get_number(L, "tStart", 0.0); @@ -1610,12 +1641,13 @@ vm_app_new(lua_State *L) app_lw->dt_failure_tol = glua_tbl_get_number(L, "dtFailureTol", 1.0e-4); app_lw->num_failures_max = glua_tbl_get_integer(L, "numFailuresMax", 20); - struct gkyl_vm vm = { }; // Input table for app. + struct gkyl_vm vm = {}; // Input table for app. strcpy(vm.name, sim_name); - + int cdim = 0; - with_lua_tbl_tbl(L, "cells") { + with_lua_tbl_tbl(L, "cells") + { vm.cdim = cdim = glua_objlen(L); for (int d = 0; d < cdim; d++) { @@ -1627,22 +1659,25 @@ vm_app_new(lua_State *L) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } - - with_lua_tbl_tbl(L, "decompCuts") { + + with_lua_tbl_tbl(L, "decompCuts") + { int ncuts = glua_objlen(L); for (int d = 0; d < ncuts; d++) { cuts[d] = glua_tbl_iget_integer(L, d + 1, 0); } - } + } - with_lua_tbl_tbl(L, "lower") { + with_lua_tbl_tbl(L, "lower") + { for (int d = 0; d < cdim; d++) { vm.lower[d] = glua_tbl_iget_number(L, d + 1, 0); } } - with_lua_tbl_tbl(L, "upper") { + with_lua_tbl_tbl(L, "upper") + { for (int d = 0; d < cdim; d++) { vm.upper[d] = glua_tbl_iget_number(L, d + 1, 0); } @@ -1651,13 +1686,12 @@ vm_app_new(lua_State *L) vm.cfl_frac = glua_tbl_get_number(L, "cflFrac", 0.95); vm.poly_order = glua_tbl_get_integer(L, "polyOrder", 1); - vm.basis_type = get_basis_type( - glua_tbl_get_string(L, "basis", "serendipity") - ); + vm.basis_type = get_basis_type(glua_tbl_get_string(L, "basis", "serendipity")); vm.num_periodic_dir = 0; if (glua_tbl_has_key(L, "periodicDirs")) { - with_lua_tbl_tbl(L, "periodicDirs") { + with_lua_tbl_tbl(L, "periodicDirs") + { vm.num_periodic_dir = glua_objlen(L); for (int d = 0; d < vm.num_periodic_dir; d++) { @@ -1675,8 +1709,8 @@ vm_app_new(lua_State *L) // Need to sort the species[] array by name of the species before // proceeding as there is no way to ensure that all cores loop over // Lua tables in the same order. - qsort(species, vm.num_species, sizeof(struct vlasov_species_lw *), species_compare_func); - + qsort(species, vm.num_species, sizeof(struct vlasov_species_lw *), species_compare_func); + for (int s = 0; s < vm.num_species; s++) { vm.species[s] = species[s]->vm_species; vm.vdim = species[s]->vdim; @@ -1727,7 +1761,7 @@ vm_app_new(lua_State *L) app_lw->has_V_drift_init_func[s][i] = species[s]->has_V_drift_init_func[i]; app_lw->V_drift_init_func_ctx[s][i] = species[s]->V_drift_init_func_ref[i]; - + app_lw->has_temp_init_func[s][i] = species[s]->has_temp_init_func[i]; app_lw->temp_init_func_ctx[s][i] = species[s]->temp_init_func_ref[i]; @@ -1848,12 +1882,14 @@ vm_app_new(lua_State *L) if (species[s]->source_has_density_init_func[i]) { vm.species[s].source.projection[i].density = gkyl_lw_eval_cb; - vm.species[s].source.projection[i].ctx_density = &app_lw->source_density_init_func_ctx[s][i]; + vm.species[s].source.projection[i].ctx_density = + &app_lw->source_density_init_func_ctx[s][i]; } if (species[s]->source_has_V_drift_init_func[i]) { vm.species[s].source.projection[i].V_drift = gkyl_lw_eval_cb; - vm.species[s].source.projection[i].ctx_V_drift = &app_lw->source_V_drift_init_func_ctx[s][i]; + vm.species[s].source.projection[i].ctx_V_drift = + &app_lw->source_V_drift_init_func_ctx[s][i]; } if (species[s]->source_has_temp_init_func[i]) { @@ -1864,7 +1900,8 @@ vm_app_new(lua_State *L) vm.species[s].source.projection[i].correct_all_moms = app_lw->source_correct_all_moms[s][i]; vm.species[s].source.projection[i].iter_eps = app_lw->source_iter_eps[s][i]; vm.species[s].source.projection[i].max_iter = app_lw->source_max_iter[s][i]; - vm.species[s].source.projection[i].use_last_converged = app_lw->source_use_last_converged[s][i]; + vm.species[s].source.projection[i].use_last_converged = + app_lw->source_use_last_converged[s][i]; } } @@ -1876,25 +1913,28 @@ vm_app_new(lua_State *L) // Need to sort the fluid_species[] array by name of the fluid species before // proceeding as there is no way to ensure that all cores loop over // Lua tables in the same order. - qsort(fluid_species, vm.num_fluid_species, sizeof(struct vlasov_fluid_species_lw *), fluid_species_compare_func); - + qsort( + fluid_species, vm.num_fluid_species, sizeof(struct vlasov_fluid_species_lw *), + fluid_species_compare_func + ); + for (int s = 0; s < vm.num_fluid_species; s++) { vm.fluid_species[s] = fluid_species[s]->vlasov_fluid_species; - fluid_species[s]->init_ctx.ndim = cdim; + fluid_species[s]->init_ctx.ndim = cdim; app_lw->fluid_species_init_ctx[s] = fluid_species[s]->init_ctx; vm.fluid_species[s].init = gkyl_lw_eval_cb; vm.fluid_species[s].ctx = &app_lw->fluid_species_init_ctx[s]; if (fluid_species[s]->has_app_advect_func) { - fluid_species[s]->app_advect_func_ref.ndim = cdim; + fluid_species[s]->app_advect_func_ref.ndim = cdim; app_lw->app_advect_func_ctx[s] = fluid_species[s]->app_advect_func_ref; vm.fluid_species[s].advection.velocity = gkyl_lw_eval_cb; vm.fluid_species[s].advection.velocity_ctx = &app_lw->app_advect_func_ctx[s]; } if (fluid_species[s]->has_n0_func) { - fluid_species[s]->n0_func_ref.ndim = cdim; + fluid_species[s]->n0_func_ref.ndim = cdim; app_lw->n0_func_ctx[s] = fluid_species[s]->n0_func_ref; vm.fluid_species[s].can_pb_n0 = gkyl_lw_eval_cb; vm.fluid_species[s].can_pb_n0_ctx = &app_lw->n0_func_ctx[s]; @@ -1904,8 +1944,7 @@ vm_app_new(lua_State *L) fluid_species[s]->diffusion_func_ref.ndim = cdim; if (cdim == 2) { fluid_species[s]->diffusion_func_ref.nret = 3; - } - else { + } else { fluid_species[s]->diffusion_func_ref.nret = 6; } app_lw->diffusion_func_ctx[s] = fluid_species[s]->diffusion_func_ref; @@ -1918,7 +1957,8 @@ vm_app_new(lua_State *L) vm.skip_field = glua_tbl_get_bool(L, "skipField", false); vm.is_electrostatic = glua_tbl_get_bool(L, "isElectrostatic", false); - with_lua_tbl_key(L, "field") { + with_lua_tbl_key(L, "field") + { if (lua_type(L, -1) == LUA_TUSERDATA) { struct vlasov_field_lw *vmf = lua_touserdata(L, -1); @@ -1968,14 +2008,15 @@ vm_app_new(lua_State *L) struct gkyl_comm *comm = 0; for (int d = 0; d < cdim; d++) { - vm.parallelism.cuts[d] = cuts[d]; + vm.parallelism.cuts[d] = cuts[d]; } struct gkyl_tool_args *args = gkyl_tool_args_new(L); struct script_cli script_cli = vm_parse_script_cli(args); script_cli.use_mpi = false; - with_lua_global(L, "GKYL_MPI_COMM") { + with_lua_global(L, "GKYL_MPI_COMM") + { if (lua_islightuserdata(L, -1)) { script_cli.use_mpi = true; } @@ -1984,59 +2025,49 @@ vm_app_new(lua_State *L) #ifdef GKYL_HAVE_MPI if (script_cli.use_gpu && script_cli.use_mpi) { #ifdef GKYL_HAVE_NCCL - with_lua_global(L, "GKYL_MPI_COMM") { + with_lua_global(L, "GKYL_MPI_COMM") + { if (lua_islightuserdata(L, -1)) { - struct { MPI_Comm comm; } *lw_mpi_comm_world = lua_touserdata(L, -1); + struct { + MPI_Comm comm; + } *lw_mpi_comm_world = lua_touserdata(L, -1); MPI_Comm mpi_comm = lw_mpi_comm_world->comm; int nrank = 1; // Number of processors in simulation. MPI_Comm_size(mpi_comm, &nrank); - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = mpi_comm, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = mpi_comm}); } } #else printf("Using CUDA and MPI together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (script_cli.use_mpi) { - with_lua_global(L, "GKYL_MPI_COMM") { + } else if (script_cli.use_mpi) { + with_lua_global(L, "GKYL_MPI_COMM") + { if (lua_islightuserdata(L, -1)) { - struct { MPI_Comm comm; } *lw_mpi_comm_world = lua_touserdata(L, -1); + struct { + MPI_Comm comm; + } *lw_mpi_comm_world = lua_touserdata(L, -1); MPI_Comm mpi_comm = lw_mpi_comm_world->comm; int nrank = 1; // Number of processors in simulation. MPI_Comm_size(mpi_comm, &nrank); - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = mpi_comm, - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = mpi_comm}); } } - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = script_cli.use_gpu, - } - ); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = script_cli.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = script_cli.use_gpu, - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = script_cli.use_gpu}); #endif - if (comm == 0) - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = script_cli.use_gpu, - } - ); + if (comm == 0) { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = script_cli.use_gpu}); + } vm.parallelism.comm = comm; vm.parallelism.use_gpu = script_cli.use_gpu; @@ -2056,13 +2087,13 @@ vm_app_new(lua_State *L) printf("tot_cuts = %d (%d)\n", tot_cuts, comm_sz); luaL_error(L, "Number of ranks and cuts do not match!"); } - + app_lw->app = gkyl_vlasov_app_new(&vm); gkyl_comm_release(comm); // Create Lua userdata. - struct vlasov_app_lw **l_app_lw = lua_newuserdata(L, sizeof(struct vlasov_app_lw*)); + struct vlasov_app_lw **l_app_lw = lua_newuserdata(L, sizeof(struct vlasov_app_lw *)); *l_app_lw = app_lw; // Point it to the Lua app pointer. // Set metatable. @@ -2071,13 +2102,12 @@ vm_app_new(lua_State *L) gkyl_tool_args_release(script_cli.rest); gkyl_tool_args_release(args); - + return 1; } // Apply initial conditions. (time) -> bool. -static int -vm_app_apply_ic(lua_State *L) +static int vm_app_apply_ic(lua_State *L) { bool status = true; @@ -2087,13 +2117,12 @@ vm_app_apply_ic(lua_State *L) double t0 = luaL_optnumber(L, 2, app_lw->t_start); gkyl_vlasov_app_apply_ic(app_lw->app, t0); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Apply initial conditions to field. (time) -> bool. -static int -vm_app_apply_ic_field(lua_State *L) +static int vm_app_apply_ic_field(lua_State *L) { bool status = true; @@ -2103,13 +2132,12 @@ vm_app_apply_ic_field(lua_State *L) double t0 = luaL_optnumber(L, 2, app_lw->t_start); gkyl_vlasov_app_apply_ic_field(app_lw->app, t0); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Apply initial conditions to species. (sidx, time) -> bool. -static int -vm_app_apply_ic_species(lua_State *L) +static int vm_app_apply_ic_species(lua_State *L) { bool status = true; @@ -2120,13 +2148,12 @@ vm_app_apply_ic_species(lua_State *L) double t0 = luaL_optnumber(L, 3, app_lw->t_start); gkyl_vlasov_app_apply_ic_species(app_lw->app, sidx, t0); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Compute diagnostic moments. () -> bool. -static int -vm_app_calc_mom(lua_State *L) +static int vm_app_calc_mom(lua_State *L) { bool status = true; @@ -2135,13 +2162,12 @@ vm_app_calc_mom(lua_State *L) gkyl_vlasov_app_calc_mom(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Compute integrated moments. (tm) -> bool. -static int -vm_app_calc_integrated_mom(lua_State *L) +static int vm_app_calc_integrated_mom(lua_State *L) { bool status = true; @@ -2151,13 +2177,12 @@ vm_app_calc_integrated_mom(lua_State *L) double tm = luaL_checknumber(L, 2); gkyl_vlasov_app_calc_integrated_mom(app_lw->app, tm); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Compute integrated L2 norm of distribution function. (tm) -> bool. -static int -vm_app_calc_integrated_L2_f(lua_State *L) +static int vm_app_calc_integrated_L2_f(lua_State *L) { bool status = true; @@ -2167,14 +2192,13 @@ vm_app_calc_integrated_L2_f(lua_State *L) double tm = luaL_checknumber(L, 2); gkyl_vlasov_app_calc_integrated_L2_f(app_lw->app, tm); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Compute integrated field energy (L2 norm of each field // component). (tm) -> bool. -static int -vm_app_calc_field_energy(lua_State *L) +static int vm_app_calc_field_energy(lua_State *L) { bool status = true; @@ -2184,13 +2208,12 @@ vm_app_calc_field_energy(lua_State *L) double tm = luaL_checknumber(L, 2); gkyl_vlasov_app_calc_field_energy(app_lw->app, tm); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write solution (field and species) to file (time, frame) -> bool. -static int -vm_app_write(lua_State *L) +static int vm_app_write(lua_State *L) { bool status = true; @@ -2201,13 +2224,12 @@ vm_app_write(lua_State *L) int frame = luaL_checkinteger(L, 3); gkyl_vlasov_app_write(app_lw->app, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write field to file (time, frame) -> bool. -static int -vm_app_write_field(lua_State *L) +static int vm_app_write_field(lua_State *L) { bool status = true; @@ -2218,13 +2240,12 @@ vm_app_write_field(lua_State *L) int frame = luaL_checkinteger(L, 3); gkyl_vlasov_app_write_field(app_lw->app, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write species solution to file (sidx, time, frame) -> bool. -static int -vm_app_write_species(lua_State *L) +static int vm_app_write_species(lua_State *L) { bool status = true; @@ -2236,13 +2257,12 @@ vm_app_write_species(lua_State *L) int frame = luaL_checkinteger(L, 4); gkyl_vlasov_app_write_species(app_lw->app, sidx, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write diagnostic moments to file (time, frame) -> bool. -static int -vm_app_write_mom(lua_State *L) +static int vm_app_write_mom(lua_State *L) { bool status = true; @@ -2253,13 +2273,12 @@ vm_app_write_mom(lua_State *L) int frame = luaL_checkinteger(L, 3); gkyl_vlasov_app_write_mom(app_lw->app, tm, frame); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write integrated moments to file () -> bool. -static int -vm_app_write_integrated_mom(lua_State *L) +static int vm_app_write_integrated_mom(lua_State *L) { bool status = true; @@ -2268,13 +2287,12 @@ vm_app_write_integrated_mom(lua_State *L) gkyl_vlasov_app_write_integrated_mom(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write integrated fluid moments to file () -> bool. -static int -vm_app_write_fluid_integrated_mom(lua_State *L) +static int vm_app_write_fluid_integrated_mom(lua_State *L) { bool status = true; @@ -2283,13 +2301,12 @@ vm_app_write_fluid_integrated_mom(lua_State *L) gkyl_vlasov_app_write_fluid_integrated_mom(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write integrated L2 norm of f to file () -> bool. -static int -vm_app_write_integrated_L2_f(lua_State *L) +static int vm_app_write_integrated_L2_f(lua_State *L) { bool status = true; @@ -2298,13 +2315,12 @@ vm_app_write_integrated_L2_f(lua_State *L) gkyl_vlasov_app_write_integrated_L2_f(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write integrated field energy to file () -> bool. -static int -vm_app_write_field_energy(lua_State *L) +static int vm_app_write_field_energy(lua_State *L) { bool status = true; @@ -2313,13 +2329,12 @@ vm_app_write_field_energy(lua_State *L) gkyl_vlasov_app_write_field_energy(app_lw->app); - lua_pushboolean(L, status); + lua_pushboolean(L, status); return 1; } // Write simulation statistics to JSON. () -> bool. -static int -vm_app_stat_write(lua_State *L) +static int vm_app_stat_write(lua_State *L) { bool status = true; @@ -2329,12 +2344,12 @@ vm_app_stat_write(lua_State *L) gkyl_vlasov_app_stat_write(app_lw->app); lua_pushboolean(L, status); - return 1; + return 1; } // Write data from simulation to file. static void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -2355,7 +2370,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo // Calculate and append field energy to dynvector. static void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +calc_field_energy(struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); @@ -2363,8 +2378,9 @@ calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_cu } // Calculate and append integrated moments to dynvector. -static void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +static void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); @@ -2372,8 +2388,9 @@ calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_ } // Calculate and append integrated L2 norm of distribution function to dynvector. -static void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +static void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); @@ -2383,33 +2400,36 @@ calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t // Step message context. struct step_message_trigs { int log_count; // Number of times logging called. - int tenth, p1c; + int tenth, p1c; struct gkyl_tm_trigger log_trig; // 10% trigger. struct gkyl_tm_trigger log_trig_1p; // 1% trigger. }; // Write log message to console. -static void -write_step_message(const struct gkyl_vlasov_app *app, struct step_message_trigs *trigs, int step, double t_curr, double dt_next) +static void write_step_message( + const struct gkyl_vlasov_app *app, struct step_message_trigs *trigs, int step, double t_curr, + double dt_next +) { if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig, t_curr)) { if (trigs->log_count > 0) { - gkyl_vlasov_app_cout(app, stdout, " Step %6d at time %#11.8g. Time-step %.6e. Completed %g%s\n", step, t_curr, dt_next, trigs->tenth * 10.0, "%"); - } - else { + gkyl_vlasov_app_cout( + app, stdout, " Step %6d at time %#11.8g. Time-step %.6e. Completed %g%s\n", step, t_curr, + dt_next, trigs->tenth * 10.0, "%" + ); + } else { trigs->log_count += 1; } - + trigs->tenth += 1; } if (gkyl_tm_trigger_check_and_bump(&trigs->log_trig_1p, t_curr)) { gkyl_vlasov_app_cout(app, stdout, "%d", trigs->p1c); - trigs->p1c = (trigs->p1c+1) % 10; + trigs->p1c = (trigs->p1c + 1) % 10; } } -static void -show_help(const struct gkyl_vlasov_app *app) +static void show_help(const struct gkyl_vlasov_app *app) { gkyl_vlasov_app_cout(app, stdout, "Vlasov script takes the following arguments:\n"); gkyl_vlasov_app_cout(app, stdout, " -h Print this help message and exit\n"); @@ -2424,8 +2444,7 @@ show_help(const struct gkyl_vlasov_app *app) } // Run simulation. (num_steps) -> bool. num_steps is optional. -static int -vm_app_run(lua_State *L) +static int vm_app_run(lua_State *L) { bool ret_status = true; @@ -2435,8 +2454,8 @@ vm_app_run(lua_State *L) struct gkyl_vlasov_app *app = app_lw->app; // Parse command lines arguments passed to input file. - struct gkyl_tool_args *args = gkyl_tool_args_new(L); - + struct gkyl_tool_args *args = gkyl_tool_args_new(L); + struct script_cli script_cli = vm_parse_script_cli(args); if (script_cli.help) { show_help(app); @@ -2446,7 +2465,7 @@ vm_app_run(lua_State *L) } gkyl_tool_args_release(script_cli.rest); - gkyl_tool_args_release(args); + gkyl_tool_args_release(args); // Initial and final simulation times. double t_curr = app_lw->t_start, t_end = app_lw->t_end; @@ -2468,7 +2487,10 @@ vm_app_run(lua_State *L) struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -2477,8 +2499,7 @@ vm_app_run(lua_State *L) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } @@ -2487,17 +2508,25 @@ vm_app_run(lua_State *L) int integrated_mom_calcs = app_lw->integrated_mom_calcs; int integrated_L2_f_calcs = app_lw->integrated_L2_f_calcs; // Triggers for IO and logging. - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; struct step_message_trigs m_trig = { .log_count = 0, - .tenth = t_curr > 0.0 ? (int) floor(t_curr / t_end * 10.0) : 0.0, - .p1c = t_curr > 0.0 ? (int) floor(t_curr / t_end * 100.0) % 10 : 0.0, - .log_trig = { .dt = t_end / 10.0, .tcurr = t_curr }, - .log_trig_1p = { .dt = t_end / 100.0, .tcurr = t_curr }, + .tenth = t_curr > 0.0 ? (int)floor(t_curr / t_end * 10.0) : 0.0, + .p1c = t_curr > 0.0 ? (int)floor(t_curr / t_end * 100.0) % 10 : 0.0, + .log_trig = {.dt = t_end / 10.0, .tcurr = t_curr}, + .log_trig_1p = {.dt = t_end / 100.0, .tcurr = t_curr} }; struct timespec tm_ic0 = gkyl_wall_clock(); @@ -2507,7 +2536,9 @@ vm_app_run(lua_State *L) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); - gkyl_vlasov_app_cout(app, stdout, "Initialization completed in %g sec\n\n", gkyl_time_diff_now_sec(tm_ic0)); + gkyl_vlasov_app_cout( + app, stdout, "Initialization completed in %g sec\n\n", gkyl_time_diff_now_sec(tm_ic0) + ); // Compute initial guess of maximum stable time-step. double dt = t_end - t_curr; @@ -2543,8 +2574,7 @@ vm_app_run(lua_State *L) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -2552,7 +2582,9 @@ vm_app_run(lua_State *L) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -2561,8 +2593,7 @@ vm_app_run(lua_State *L) break; } - } - else { + } else { num_failures = 0; } @@ -2586,14 +2617,22 @@ vm_app_run(lua_State *L) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); @@ -2606,47 +2645,42 @@ vm_app_run(lua_State *L) } // Clean up memory allocated for simulation. -static int -vm_app_gc(lua_State *L) +static int vm_app_gc(lua_State *L) { struct vlasov_app_lw **l_app_lw = GKYL_CHECK_UDATA(L, VLASOV_APP_METATABLE_NM); struct vlasov_app_lw *app_lw = *l_app_lw; gkyl_vlasov_app_release(app_lw->app); gkyl_free(*l_app_lw); - + return 0; } // App constructor. -static struct luaL_Reg vm_app_ctor[] = { - { "new", vm_app_new }, - { 0, 0 } -}; +static struct luaL_Reg vm_app_ctor[] = {{"new", vm_app_new}, {0, 0}}; // App methods. static struct luaL_Reg vm_app_funcs[] = { - { "apply_ic", vm_app_apply_ic }, - { "apply_ic_field", vm_app_apply_ic_field }, - { "apply_ic_species", vm_app_apply_ic_species }, - { "calc_mom", vm_app_calc_mom }, - { "calc_integrated_mom", vm_app_calc_integrated_mom }, - { "calc_integrated_L2_f", vm_app_calc_integrated_L2_f }, - { "calc_field_energy", vm_app_calc_field_energy }, - { "write", vm_app_write }, - { "write_field", vm_app_write_field }, - { "write_species", vm_app_write_species }, - { "write_mom", vm_app_write_mom }, - { "write_integrated_mom", vm_app_write_integrated_mom }, - { "write_integrated_L2_f", vm_app_write_integrated_L2_f }, - { "write_field_energy", vm_app_write_field_energy }, - { "stat_write", vm_app_stat_write }, - { "run", vm_app_run }, - { 0, 0 } + {"apply_ic", vm_app_apply_ic}, + {"apply_ic_field", vm_app_apply_ic_field}, + {"apply_ic_species", vm_app_apply_ic_species}, + {"calc_mom", vm_app_calc_mom}, + {"calc_integrated_mom", vm_app_calc_integrated_mom}, + {"calc_integrated_L2_f", vm_app_calc_integrated_L2_f}, + {"calc_field_energy", vm_app_calc_field_energy}, + {"write", vm_app_write}, + {"write_field", vm_app_write_field}, + {"write_species", vm_app_write_species}, + {"write_mom", vm_app_write_mom}, + {"write_integrated_mom", vm_app_write_integrated_mom}, + {"write_integrated_L2_f", vm_app_write_integrated_L2_f}, + {"write_field_energy", vm_app_write_field_energy}, + {"stat_write", vm_app_stat_write}, + {"run", vm_app_run}, + {0, 0} }; -static void -app_openlibs(lua_State *L) +static void app_openlibs(lua_State *L) { // Register top-level App. do { @@ -2659,44 +2693,38 @@ app_openlibs(lua_State *L) lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_register(L, NULL, vm_app_funcs); - + luaL_register(L, "G0.Vlasov.App", vm_app_ctor); - - } - while (0); + + } while (0); // Register Species input struct. do { luaL_newmetatable(L, VLASOV_SPECIES_METATABLE_NM); luaL_register(L, "G0.Vlasov.Species", vm_species_ctor); - } - while (0); + } while (0); // Register Fluid Species input struct. do { luaL_newmetatable(L, VLASOV_FLUID_SPECIES_METATABLE_NM); luaL_register(L, "G0.Vlasov.FluidSpecies", vm_fluid_species_ctor); - } - while (0); + } while (0); // Register Field input struct. do { luaL_newmetatable(L, VLASOV_FIELD_METATABLE_NM); luaL_register(L, "G0.Vlasov.Field", vm_field_ctor); - } - while (0); + } while (0); // Add globals and other parameters. do { // Table to store references so the objects do not get garbage-collected. lua_newtable(L); lua_setglobal(L, "__vlasov_ref_table"); - } - while (0); + } while (0); } -void -gkyl_vlasov_lw_openlibs(lua_State *L) +void gkyl_vlasov_lw_openlibs(lua_State *L) { gkyl_register_poisson_bc_types(L); @@ -2704,8 +2732,8 @@ gkyl_vlasov_lw_openlibs(lua_State *L) gkyl_register_vlasov_projection_types(L); gkyl_register_vlasov_model_types(L); gkyl_register_vlasov_collision_types(L); - gkyl_register_vlasov_source_types(L); - + gkyl_register_vlasov_source_types(L); + eqn_openlibs(L); app_openlibs(L); } diff --git a/vlasov/apps/vlasov_poisson_update_ssp_rk3.c b/vlasov/apps/vlasov_poisson_update_ssp_rk3.c index c38d1e5b51..5d80df432e 100644 --- a/vlasov/apps/vlasov_poisson_update_ssp_rk3.c +++ b/vlasov/apps/vlasov_poisson_update_ssp_rk3.c @@ -3,8 +3,7 @@ // Take time-step using the RK3 method. Also sets the status object // which has the actual and suggested dts used. These can be different // from the actual time-step. -struct gkyl_update_status -vlasov_poisson_update_ssp_rk3(gkyl_vlasov_app* app, double dt0) +struct gkyl_update_status vlasov_poisson_update_ssp_rk3(gkyl_vlasov_app *app, double dt0) { int ns = app->num_species; int nfs = app->num_fluid_species; @@ -13,7 +12,7 @@ vlasov_poisson_update_ssp_rk3(gkyl_vlasov_app* app, double dt0) const struct gkyl_array *fluidin[nfs]; struct gkyl_array *fout[ns]; struct gkyl_array *fluidout[nfs]; - struct gkyl_update_status st = { .success = true }; + struct gkyl_update_status st = {.success = true}; // Time-stepper state. enum { RK_STAGE_1, RK_STAGE_2, RK_STAGE_3, RK_COMPLETE } state = RK_STAGE_1; @@ -21,126 +20,127 @@ vlasov_poisson_update_ssp_rk3(gkyl_vlasov_app* app, double dt0) double tcurr = app->tcurr, dt = dt0; while (state != RK_COMPLETE) { switch (state) { - case RK_STAGE_1: - do { - struct timespec rk3_s1_tm = gkyl_wall_clock(); + case RK_STAGE_1: + do { + struct timespec rk3_s1_tm = gkyl_wall_clock(); - for (int i=0; ispecies[i].f; + fout[i] = app->species[i].f1; + } + + vlasov_forward_euler(app, tcurr, dt, fin, fluidin, 0, fout, fluidout, 0, &st); + + // Compute the fields and apply BCs. + vp_calc_field_and_apply_bc(app, tcurr, fout); + + dt = st.dt_actual; + state = RK_STAGE_2; + + app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s1_tm); + } while (0); + break; + + case RK_STAGE_2: + do { + struct timespec rk3_s2_tm = gkyl_wall_clock(); + + for (int i = 0; i < ns; ++i) { + fin[i] = app->species[i].f1; + fout[i] = app->species[i].fnew; + } + + vlasov_forward_euler(app, tcurr + dt, dt, fin, fluidin, 0, fout, fluidout, 0, &st); + + if (st.dt_actual < dt) { + // Recalculate the field. + for (int i = 0; i < ns; ++i) { fin[i] = app->species[i].f; - fout[i] = app->species[i].f1; } - - vlasov_forward_euler(app, tcurr, dt, fin, fluidin, 0, fout, fluidout, 0, &st); + vp_calc_field(app, tcurr, fin); + + // collect stats + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], dt_rel_diff); + app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], dt_rel_diff); + app->stat.nstage_2_fail += 1; + + dt = st.dt_actual; + state = RK_STAGE_1; // restart from stage 1 + + } else { + for (int i = 0; i < ns; ++i) { + array_combine( + app->species[i].f1, 3.0 / 4.0, app->species[i].f, 1.0 / 4.0, app->species[i].fnew, + &app->species[i].local_ext + ); + } // Compute the fields and apply BCs. + for (int i = 0; i < ns; ++i) { + fout[i] = app->species[i].f1; + } vp_calc_field_and_apply_bc(app, tcurr, fout); - - dt = st.dt_actual; - state = RK_STAGE_2; - app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s1_tm); - } while (0); - break; + state = RK_STAGE_3; + } - case RK_STAGE_2: - do { - struct timespec rk3_s2_tm = gkyl_wall_clock(); + app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s2_tm); + } while (0); + break; - for (int i=0; ispecies[i].f1; - fout[i] = app->species[i].fnew; - } - - vlasov_forward_euler(app, tcurr+dt, dt, fin, fluidin, 0, fout, fluidout, 0, &st); - - if (st.dt_actual < dt) { - - // Recalculate the field. - for (int i=0; ispecies[i].f; - vp_calc_field(app, tcurr, fin); - - // collect stats - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], - dt_rel_diff); - app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], - dt_rel_diff); - app->stat.nstage_2_fail += 1; - - dt = st.dt_actual; - state = RK_STAGE_1; // restart from stage 1 - - } else { - for (int i=0; ispecies[i].f1, - 3.0/4.0, app->species[i].f, 1.0/4.0, app->species[i].fnew, &app->species[i].local_ext); - - // Compute the fields and apply BCs. - for (int i=0; ispecies[i].f1; - } - vp_calc_field_and_apply_bc(app, tcurr, fout); - - state = RK_STAGE_3; - } + case RK_STAGE_3: + do { + struct timespec rk3_s3_tm = gkyl_wall_clock(); - app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s2_tm); - } while(0); - break; + for (int i = 0; i < ns; ++i) { + fin[i] = app->species[i].f1; + fout[i] = app->species[i].fnew; + } - case RK_STAGE_3: - do { - struct timespec rk3_s3_tm = gkyl_wall_clock(); + vlasov_forward_euler(app, tcurr + dt / 2, dt, fin, fluidin, 0, fout, fluidout, 0, &st); - for (int i=0; ispecies[i].f1; - fout[i] = app->species[i].fnew; + if (st.dt_actual < dt) { + // Recalculate the field. + for (int i = 0; i < ns; ++i) { + fin[i] = app->species[i].f; } - - vlasov_forward_euler(app, tcurr+dt/2, dt, fin, fluidin, 0, fout, fluidout, 0, &st); - - if (st.dt_actual < dt) { - // Recalculate the field. - for (int i=0; ispecies[i].f; - vp_calc_field(app, tcurr, fin); - - // collect stats - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], - dt_rel_diff); - app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], - dt_rel_diff); - app->stat.nstage_3_fail += 1; - - dt = st.dt_actual; - state = RK_STAGE_1; // restart from stage 1 - - app->stat.nstage_2_fail += 1; + vp_calc_field(app, tcurr, fin); + + // collect stats + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], dt_rel_diff); + app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], dt_rel_diff); + app->stat.nstage_3_fail += 1; + + dt = st.dt_actual; + state = RK_STAGE_1; // restart from stage 1 + + app->stat.nstage_2_fail += 1; + } else { + for (int i = 0; i < ns; ++i) { + array_combine( + app->species[i].f1, 1.0 / 3.0, app->species[i].f, 2.0 / 3.0, app->species[i].fnew, + &app->species[i].local_ext + ); + gkyl_array_copy_range(app->species[i].f, app->species[i].f1, &app->species[i].local_ext); } - else { - for (int i=0; ispecies[i].f1, - 1.0/3.0, app->species[i].f, 2.0/3.0, app->species[i].fnew, &app->species[i].local_ext); - gkyl_array_copy_range(app->species[i].f, app->species[i].f1, &app->species[i].local_ext); - } - - // Compute the fields and apply BCs - for (int i=0; ispecies[i].f; - } - vp_calc_field_and_apply_bc(app, tcurr, fout); - - state = RK_COMPLETE; + + // Compute the fields and apply BCs + for (int i = 0; i < ns; ++i) { + fout[i] = app->species[i].f; } + vp_calc_field_and_apply_bc(app, tcurr, fout); + + state = RK_COMPLETE; + } - app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s3_tm); - } while(0); - break; + app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s3_tm); + } while (0); + break; - case RK_COMPLETE: // can't happen: suppresses warning - break; + case RK_COMPLETE: // can't happen: suppresses warning + break; } } diff --git a/vlasov/apps/vlasov_update_implicit_coll.c b/vlasov/apps/vlasov_update_implicit_coll.c index 6e7050d248..e734b33e12 100644 --- a/vlasov/apps/vlasov_update_implicit_coll.c +++ b/vlasov/apps/vlasov_update_implicit_coll.c @@ -1,41 +1,39 @@ #include // Take time-step using the RK3 method for the explicit advective comps. -// Use the actual timestep used to update -void -vlasov_update_implicit_coll(gkyl_vlasov_app* app, double dt0) +// Use the actual timestep used to update +void vlasov_update_implicit_coll(gkyl_vlasov_app *app, double dt0) { - int ns = app->num_species; + int ns = app->num_species; const struct gkyl_array *fin[ns]; struct gkyl_array *fout[ns]; - for (int i=0; ispecies[i].f; fout[i] = app->species[i].f1; } // compute necessary moments and boundary corrections for collisions - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { if (app->species[i].collision_id == GKYL_BGK_COLLISIONS) { - vm_species_bgk_moms(app, &app->species[i], - &app->species[i].bgk, fin[i]); + vm_species_bgk_moms(app, &app->species[i], &app->species[i].bgk, fin[i]); } } - + // implicit BGK contributions - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { app->species[i].bgk.implicit_step = true; app->species[i].bgk.dt_implicit = dt0; vm_species_rhs_implicit(app, &app->species[i], fin[i], fout[i], dt0); } // complete update of distribution function - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { gkyl_array_accumulate(gkyl_array_scale(fout[i], dt0), 1.0, fin[i]); vm_species_apply_bc(app, &app->species[i], fout[i], app->tcurr); } - - for (int i=0; ispecies[i].f, app->species[i].f1, &app->species[i].local_ext); }; } \ No newline at end of file diff --git a/vlasov/apps/vlasov_update_op_split.c b/vlasov/apps/vlasov_update_op_split.c index 30712f5504..f23db23311 100644 --- a/vlasov/apps/vlasov_update_op_split.c +++ b/vlasov/apps/vlasov_update_op_split.c @@ -3,10 +3,9 @@ // Take time-step using the SSP-RK3 method for the hyperbolic components // Then, we use the actual timestep taken with the SSP-RK3 method to update // fluid-EM coupling and/or BGK collisions implicitly. -struct gkyl_update_status -vlasov_update_op_split(gkyl_vlasov_app* app, double dt0) +struct gkyl_update_status vlasov_update_op_split(gkyl_vlasov_app *app, double dt0) { - struct gkyl_update_status st = vlasov_update_ssp_rk3(app,dt0); + struct gkyl_update_status st = vlasov_update_ssp_rk3(app, dt0); // Take the implicit timestep for BGK collisions if (app->has_implicit_coll_scheme) { diff --git a/vlasov/apps/vlasov_update_ssp_rk3.c b/vlasov/apps/vlasov_update_ssp_rk3.c index 816eb1e325..3d86c3fa64 100644 --- a/vlasov/apps/vlasov_update_ssp_rk3.c +++ b/vlasov/apps/vlasov_update_ssp_rk3.c @@ -3,17 +3,16 @@ // Take time-step using the RK3 method. Also sets the status object // which has the actual and suggested dts used. These can be different // from the actual time-step. -struct gkyl_update_status -vlasov_update_ssp_rk3(gkyl_vlasov_app* app, double dt0) +struct gkyl_update_status vlasov_update_ssp_rk3(gkyl_vlasov_app *app, double dt0) { - int ns = app->num_species; - int nfs = app->num_fluid_species; + int ns = app->num_species; + int nfs = app->num_fluid_species; const struct gkyl_array *fin[ns]; struct gkyl_array *fout[ns]; const struct gkyl_array *fluidin[nfs]; struct gkyl_array *fluidout[nfs]; - struct gkyl_update_status st = { .success = true }; + struct gkyl_update_status st = {.success = true}; // time-stepper state enum { RK_STAGE_1, RK_STAGE_2, RK_STAGE_3, RK_COMPLETE } state = RK_STAGE_1; @@ -21,161 +20,172 @@ vlasov_update_ssp_rk3(gkyl_vlasov_app* app, double dt0) double tcurr = app->tcurr, dt = dt0; while (state != RK_COMPLETE) { switch (state) { - case RK_STAGE_1: - do { - struct timespec rk3_s1_tm = gkyl_wall_clock(); + case RK_STAGE_1: + do { + struct timespec rk3_s1_tm = gkyl_wall_clock(); + + for (int i = 0; i < ns; ++i) { + fin[i] = app->species[i].f; + fout[i] = app->species[i].f1; + } + for (int i = 0; i < nfs; ++i) { + fluidin[i] = app->fluid_species[i].fluid; + fluidout[i] = app->fluid_species[i].fluid1; + } + vlasov_forward_euler( + app, tcurr, dt, fin, fluidin, app->has_field ? app->field->em : 0, fout, fluidout, + app->has_field ? app->field->em1 : 0, &st + ); + + vm_apply_bc(app, tcurr, fout, fluidout, app->has_field ? app->field->em1 : 0); + + // Limit fluid and EM solutions if desired (done after update as post-hoc fix) + for (int i = 0; i < nfs; ++i) { + vm_fluid_species_limiter(app, &app->fluid_species[i], fluidout[i]); + } + if (app->has_field) { + vm_field_limiter(app, app->field, app->field->em1); + } + dt = st.dt_actual; + state = RK_STAGE_2; + + app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s1_tm); + } while (0); + break; + + case RK_STAGE_2: + do { + struct timespec rk3_s2_tm = gkyl_wall_clock(); + + for (int i = 0; i < ns; ++i) { + fin[i] = app->species[i].f1; + fout[i] = app->species[i].fnew; + } + for (int i = 0; i < nfs; ++i) { + fluidin[i] = app->fluid_species[i].fluid1; + fluidout[i] = app->fluid_species[i].fluidnew; + } + vlasov_forward_euler( + app, tcurr + dt, dt, fin, fluidin, app->has_field ? app->field->em1 : 0, fout, fluidout, + app->has_field ? app->field->emnew : 0, &st + ); + + vm_apply_bc(app, tcurr, fout, fluidout, app->has_field ? app->field->emnew : 0); + + // Limit fluid and EM solutions if desired (done after update as post-hoc fix) + for (int i = 0; i < nfs; ++i) { + vm_fluid_species_limiter(app, &app->fluid_species[i], fluidout[i]); + } + if (app->has_field) { + vm_field_limiter(app, app->field, app->field->emnew); + } + if (st.dt_actual < dt) { + // collect stats + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], dt_rel_diff); + app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], dt_rel_diff); + app->stat.nstage_2_fail += 1; - for (int i=0; ispecies[i].f; - fout[i] = app->species[i].f1; - } - for (int i=0; ifluid_species[i].fluid; - fluidout[i] = app->fluid_species[i].fluid1; - } - vlasov_forward_euler(app, tcurr, dt, fin, fluidin, app->has_field ? app->field->em : 0, - fout, fluidout, app->has_field ? app->field->em1 : 0, - &st - ); - - vm_apply_bc(app, tcurr, fout, fluidout, app->has_field ? app->field->em1 : 0); - - // Limit fluid and EM solutions if desired (done after update as post-hoc fix) - for (int i=0; ifluid_species[i], fluidout[i]); - } - if (app->has_field) { - vm_field_limiter(app, app->field, app->field->em1); - } dt = st.dt_actual; - state = RK_STAGE_2; - - app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s1_tm); - } while(0); - break; - - case RK_STAGE_2: - do { - struct timespec rk3_s2_tm = gkyl_wall_clock(); - - for (int i=0; ispecies[i].f1; - fout[i] = app->species[i].fnew; - } - for (int i=0; ifluid_species[i].fluid1; - fluidout[i] = app->fluid_species[i].fluidnew; + state = RK_STAGE_1; // restart from stage 1 + } else { + for (int i = 0; i < ns; ++i) { + array_combine( + app->species[i].f1, 3.0 / 4.0, app->species[i].f, 1.0 / 4.0, app->species[i].fnew, + &app->species[i].local_ext + ); } - vlasov_forward_euler(app, tcurr+dt, dt, fin, fluidin, app->has_field ? app->field->em1 : 0, - fout, fluidout, app->has_field ? app->field->emnew : 0, - &st - ); - - vm_apply_bc(app, tcurr, fout, fluidout, app->has_field ? app->field->emnew : 0); - - // Limit fluid and EM solutions if desired (done after update as post-hoc fix) - for (int i=0; ifluid_species[i], fluidout[i]); + for (int i = 0; i < nfs; ++i) { + array_combine( + app->fluid_species[i].fluid1, 3.0 / 4.0, app->fluid_species[i].fluid, 1.0 / 4.0, + app->fluid_species[i].fluidnew, &app->local_ext + ); } if (app->has_field) { - vm_field_limiter(app, app->field, app->field->emnew); - } - if (st.dt_actual < dt) { - // collect stats - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_2_dt_diff[0] = fmin(app->stat.stage_2_dt_diff[0], - dt_rel_diff); - app->stat.stage_2_dt_diff[1] = fmax(app->stat.stage_2_dt_diff[1], - dt_rel_diff); - app->stat.nstage_2_fail += 1; - - dt = st.dt_actual; - state = RK_STAGE_1; // restart from stage 1 - } - else { - for (int i=0; ispecies[i].f1, - 3.0/4.0, app->species[i].f, 1.0/4.0, app->species[i].fnew, &app->species[i].local_ext); - for (int i=0; ifluid_species[i].fluid1, - 3.0/4.0, app->fluid_species[i].fluid, 1.0/4.0, app->fluid_species[i].fluidnew, &app->local_ext); - if (app->has_field) - array_combine(app->field->em1, - 3.0/4.0, app->field->em, 1.0/4.0, app->field->emnew, &app->local_ext); - - state = RK_STAGE_3; + array_combine( + app->field->em1, 3.0 / 4.0, app->field->em, 1.0 / 4.0, app->field->emnew, + &app->local_ext + ); } - app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s2_tm); - } while(0); - break; + state = RK_STAGE_3; + } + + app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s2_tm); + } while (0); + break; + + case RK_STAGE_3: + do { + struct timespec rk3_s3_tm = gkyl_wall_clock(); + + for (int i = 0; i < ns; ++i) { + fin[i] = app->species[i].f1; + fout[i] = app->species[i].fnew; + } + for (int i = 0; i < nfs; ++i) { + fluidin[i] = app->fluid_species[i].fluid1; + fluidout[i] = app->fluid_species[i].fluidnew; + } + vlasov_forward_euler( + app, tcurr + dt / 2, dt, fin, fluidin, app->has_field ? app->field->em1 : 0, fout, + fluidout, app->has_field ? app->field->emnew : 0, &st + ); + + vm_apply_bc(app, tcurr, fout, fluidout, app->has_field ? app->field->emnew : 0); + + // Limit fluid and EM solutions if desired (done after update as post-hoc fix) + for (int i = 0; i < nfs; ++i) { + vm_fluid_species_limiter(app, &app->fluid_species[i], fluidout[i]); + } + if (app->has_field) { + vm_field_limiter(app, app->field, app->field->emnew); + } + if (st.dt_actual < dt) { + // collect stats + double dt_rel_diff = (dt - st.dt_actual) / st.dt_actual; + app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], dt_rel_diff); + app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], dt_rel_diff); + app->stat.nstage_3_fail += 1; - case RK_STAGE_3: - do { - struct timespec rk3_s3_tm = gkyl_wall_clock(); - - for (int i=0; ispecies[i].f1; - fout[i] = app->species[i].fnew; + dt = st.dt_actual; + state = RK_STAGE_1; // restart from stage 1 + + app->stat.nstage_2_fail += 1; + } else { + for (int i = 0; i < ns; ++i) { + array_combine( + app->species[i].f1, 1.0 / 3.0, app->species[i].f, 2.0 / 3.0, app->species[i].fnew, + &app->species[i].local_ext + ); + gkyl_array_copy_range(app->species[i].f, app->species[i].f1, &app->species[i].local_ext); } - for (int i=0; ifluid_species[i].fluid1; - fluidout[i] = app->fluid_species[i].fluidnew; - } - vlasov_forward_euler(app, tcurr+dt/2, dt, fin, fluidin, app->has_field ? app->field->em1 : 0, - fout, fluidout, app->has_field ? app->field->emnew : 0, - &st - ); - - vm_apply_bc(app, tcurr, fout, fluidout, app->has_field ? app->field->emnew : 0); - - // Limit fluid and EM solutions if desired (done after update as post-hoc fix) - for (int i=0; ifluid_species[i], fluidout[i]); + for (int i = 0; i < nfs; ++i) { + array_combine( + app->fluid_species[i].fluid1, 1.0 / 3.0, app->fluid_species[i].fluid, 2.0 / 3.0, + app->fluid_species[i].fluidnew, &app->local_ext + ); + gkyl_array_copy_range( + app->fluid_species[i].fluid, app->fluid_species[i].fluid1, &app->local_ext + ); } if (app->has_field) { - vm_field_limiter(app, app->field, app->field->emnew); - } - if (st.dt_actual < dt) { - // collect stats - double dt_rel_diff = (dt-st.dt_actual)/st.dt_actual; - app->stat.stage_3_dt_diff[0] = fmin(app->stat.stage_3_dt_diff[0], - dt_rel_diff); - app->stat.stage_3_dt_diff[1] = fmax(app->stat.stage_3_dt_diff[1], - dt_rel_diff); - app->stat.nstage_3_fail += 1; - - dt = st.dt_actual; - state = RK_STAGE_1; // restart from stage 1 - - app->stat.nstage_2_fail += 1; - } - else { - for (int i=0; ispecies[i].f1, - 1.0/3.0, app->species[i].f, 2.0/3.0, app->species[i].fnew, &app->species[i].local_ext); - gkyl_array_copy_range(app->species[i].f, app->species[i].f1, &app->species[i].local_ext); - } - for (int i=0; ifluid_species[i].fluid1, - 1.0/3.0, app->fluid_species[i].fluid, 2.0/3.0, app->fluid_species[i].fluidnew, &app->local_ext); - gkyl_array_copy_range(app->fluid_species[i].fluid, app->fluid_species[i].fluid1, &app->local_ext); - } - if (app->has_field) { - array_combine(app->field->em1, - 1.0/3.0, app->field->em, 2.0/3.0, app->field->emnew, &app->local_ext); - gkyl_array_copy_range(app->field->em, app->field->em1, &app->local_ext); - } - - state = RK_COMPLETE; + array_combine( + app->field->em1, 1.0 / 3.0, app->field->em, 2.0 / 3.0, app->field->emnew, + &app->local_ext + ); + gkyl_array_copy_range(app->field->em, app->field->em1, &app->local_ext); } - app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s3_tm); - } while(0); - break; + state = RK_COMPLETE; + } + + app->stat.rk3_tm += gkyl_time_diff_now_sec(rk3_s3_tm); + } while (0); + break; - case RK_COMPLETE: // can't happen: suppresses warning - break; + case RK_COMPLETE: // can't happen: suppresses warning + break; } } diff --git a/vlasov/apps/vm_field.c b/vlasov/apps/vm_field.c index 385296a91e..119363a1cc 100644 --- a/vlasov/apps/vm_field.c +++ b/vlasov/apps/vm_field.c @@ -10,8 +10,7 @@ #include // initialize field object -struct vm_field* -vm_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) +struct vm_field *vm_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) { struct vm_field *f = gkyl_malloc(sizeof(struct vm_field)); @@ -19,31 +18,31 @@ vm_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) f->field_id = f->info.field_id; // allocate EM arrays - f->em = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); - f->em1 = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); - f->emnew = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); + f->em = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); + f->em1 = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); + f->emnew = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); f->em_energy = mkarr(app->use_gpu, 6, app->local_ext.volume); // allocate a total field variable for methods which require ext_em + em such as b_hat calculation - f->tot_em = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); + f->tot_em = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); - f->em_host = f->em; + f->em_host = f->em; if (app->use_gpu) { - f->em_host = mkarr(false, 8*app->confBasis.num_basis, app->local_ext.volume); + f->em_host = mkarr(false, 8 * app->confBasis.num_basis, app->local_ext.volume); f->em_energy_red = gkyl_cu_malloc(sizeof(double[6])); } // Duplicate copy of EM data in case time step fails. - // Needed because of implicit source split which modifies solution and - // is always successful, so if a time step fails due to the SSP RK3 + // Needed because of implicit source split which modifies solution and + // is always successful, so if a time step fails due to the SSP RK3 // we must restore the old solution before restarting the time step - f->em_dup = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); + f->em_dup = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); f->integ_energy = gkyl_dynvec_new(GKYL_DOUBLE, 6); f->is_first_energy_write_call = true; - // Initialize external EM fields (always used by implicit fluid sources, so always initialize) - f->ext_em = mkarr(app->use_gpu, 6*app->confBasis.num_basis, app->local_ext.volume); + // Initialize external EM fields (always used by implicit fluid sources, so always initialize) + f->ext_em = mkarr(app->use_gpu, 6 * app->confBasis.num_basis, app->local_ext.volume); gkyl_array_clear(f->ext_em, 0.0); f->has_ext_em = false; f->ext_em_evolve = false; @@ -56,17 +55,19 @@ vm_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) f->ext_em_host = f->ext_em; if (app->use_gpu) { - f->ext_em_host = mkarr(false, 6*app->confBasis.num_basis, app->local_ext.volume); + f->ext_em_host = mkarr(false, 6 * app->confBasis.num_basis, app->local_ext.volume); } - f->ext_em_proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, app->confBasis.poly_order+1, - 6, f->info.ext_em, f->info.ext_em_ctx); + f->ext_em_proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->confBasis.poly_order + 1, 6, f->info.ext_em, + f->info.ext_em_ctx + ); } // Vlasov-Maxwell doesn't presently use external potentials. f->has_ext_pot = f->ext_pot_evolve = false; - // Initialize applied currents (always used by implicit fluid sources, so always initialize) - f->app_current = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); + // Initialize applied currents (always used by implicit fluid sources, so always initialize) + f->app_current = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); gkyl_array_clear(f->app_current, 0.0); f->has_app_current = false; f->app_current_evolve = false; @@ -79,31 +80,35 @@ vm_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) f->app_current_host = f->app_current; if (app->use_gpu) { - f->app_current_host = mkarr(false, 3*app->confBasis.num_basis, app->local_ext.volume); + f->app_current_host = mkarr(false, 3 * app->confBasis.num_basis, app->local_ext.volume); } - f->app_current_proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, app->confBasis.poly_order+1, - 3, f->info.app_current, f->info.app_current_ctx); + f->app_current_proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->confBasis.poly_order + 1, 3, f->info.app_current, + f->info.app_current_ctx + ); } // allocate cflrate (scalar array) f->cflrate = mkarr(app->use_gpu, 1, app->local_ext.volume); - if (app->use_gpu) + if (app->use_gpu) { f->omegaCfl_ptr = gkyl_cu_malloc(sizeof(double)); - else + } else { f->omegaCfl_ptr = gkyl_malloc(sizeof(double)); + } // equation object - double c = 1/sqrt(f->info.epsilon0*f->info.mu0); + double c = 1 / sqrt(f->info.epsilon0 * f->info.mu0); double ef = f->info.elcErrorSpeedFactor, mf = f->info.mgnErrorSpeedFactor; struct gkyl_dg_eqn *eqn; eqn = gkyl_dg_maxwell_new(&app->confBasis, c, ef, mf, app->use_gpu); - int up_dirs[GKYL_MAX_DIM] = {0, 1, 2}, zero_flux_flags[2*GKYL_MAX_DIM] = {0, 0, 0, 0, 0, 0}; + int up_dirs[GKYL_MAX_DIM] = {0, 1, 2}, zero_flux_flags[2 * GKYL_MAX_DIM] = {0, 0, 0, 0, 0, 0}; // Maxwell solver - f->slvr = gkyl_hyper_dg_new(&app->grid, &app->confBasis, eqn, - app->cdim, up_dirs, zero_flux_flags, 1, app->use_gpu); + f->slvr = gkyl_hyper_dg_new( + &app->grid, &app->confBasis, eqn, app->cdim, up_dirs, zero_flux_flags, 1, app->use_gpu + ); // Check if limiter_fac is specified for adjusting how much diffusion is applied through slope limiter // If not specified, set to 0.0 and updater sets default behavior (1/sqrt(3); see gkyl_dg_calc_em_vars.h) @@ -112,25 +117,28 @@ vm_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) struct gkyl_wv_eqn *maxwell = gkyl_wv_maxwell_new(c, ef, mf, app->use_gpu); // Create updaters for limiting EM fields - f->calc_em_vars = gkyl_dg_calc_em_vars_new(&app->grid, &app->confBasis, &app->local_ext, - maxwell, app->geom, limiter_fac, 0, app->use_gpu); + f->calc_em_vars = gkyl_dg_calc_em_vars_new( + &app->grid, &app->confBasis, &app->local_ext, maxwell, app->geom, limiter_fac, 0, app->use_gpu + ); gkyl_wv_eqn_release(maxwell); // determine which directions are not periodic int num_periodic_dir = app->num_periodic_dir, is_np[3] = {1, 1, 1}; - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int dir=0; dircdim; ++dir) { + for (int dir = 0; dir < app->cdim; ++dir) { f->lower_bc[dir] = f->upper_bc[dir] = GKYL_FIELD_COPY; if (is_np[dir]) { const enum gkyl_field_bc_type *bc; - if (dir == 0) + if (dir == 0) { bc = f->info.bcx; - else if (dir == 1) + } else if (dir == 1) { bc = f->info.bcy; - else + } else { bc = f->info.bcz; + } f->lower_bc[dir] = bc[0]; f->upper_bc[dir] = bc[1]; @@ -143,49 +151,55 @@ vm_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) // Ghost currents do not make sense with cdim > 1 or non-periodic boundary conditions. assert(false); } - f->use_ghost_current = true; + f->use_ghost_current = true; f->ghost_current = mkarr(app->use_gpu, 1, app->local_ext.volume); if (app->use_gpu) { f->red_ghost_current = gkyl_cu_malloc(sizeof(double[1])); - } + } } - // allocate buffer for applying BCs + // allocate buffer for applying BCs long buff_sz = 0; // compute buffer size needed - for (int dir=0; dircdim; ++dir) { + for (int dir = 0; dir < app->cdim; ++dir) { long vol = GKYL_MAX2(app->lower_skin[dir].volume, app->upper_skin[dir].volume); buff_sz = buff_sz > vol ? buff_sz : vol; } - f->bc_buffer = mkarr(app->use_gpu, 8*app->confBasis.num_basis, buff_sz); - - for (int d=0; dcdim; ++d) { + f->bc_buffer = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, buff_sz); + + for (int d = 0; d < app->cdim; ++d) { // Lower BC updater. Copy BCs by default. enum gkyl_bc_basic_type bctype = GKYL_BC_COPY; - if (f->lower_bc[d] == GKYL_FIELD_COPY) + if (f->lower_bc[d] == GKYL_FIELD_COPY) { bctype = GKYL_BC_COPY; - else if (f->lower_bc[d] == GKYL_FIELD_PEC_WALL) + } else if (f->lower_bc[d] == GKYL_FIELD_PEC_WALL) { bctype = GKYL_BC_MAXWELL_PEC; - else if (f->lower_bc[d] == GKYL_FIELD_SYM_WALL) + } else if (f->lower_bc[d] == GKYL_FIELD_SYM_WALL) { bctype = GKYL_BC_MAXWELL_SYM; - else if (f->lower_bc[d] == GKYL_FIELD_RESERVOIR) + } else if (f->lower_bc[d] == GKYL_FIELD_RESERVOIR) { bctype = GKYL_BC_MAXWELL_RESERVOIR; + } - f->bc_lo[d] = gkyl_bc_basic_new(d, GKYL_LOWER_EDGE, bctype, app->basis_on_dev.confBasis, - &app->lower_skin[d], &app->lower_ghost[d], f->em->ncomp, app->cdim, app->use_gpu); + f->bc_lo[d] = gkyl_bc_basic_new( + d, GKYL_LOWER_EDGE, bctype, app->basis_on_dev.confBasis, &app->lower_skin[d], + &app->lower_ghost[d], f->em->ncomp, app->cdim, app->use_gpu + ); // Upper BC updater. Copy BCs by default. - if (f->upper_bc[d] == GKYL_FIELD_COPY) + if (f->upper_bc[d] == GKYL_FIELD_COPY) { bctype = GKYL_BC_COPY; - else if (f->upper_bc[d] == GKYL_FIELD_PEC_WALL) + } else if (f->upper_bc[d] == GKYL_FIELD_PEC_WALL) { bctype = GKYL_BC_MAXWELL_PEC; - else if (f->upper_bc[d] == GKYL_FIELD_SYM_WALL) + } else if (f->upper_bc[d] == GKYL_FIELD_SYM_WALL) { bctype = GKYL_BC_MAXWELL_SYM; - else if (f->upper_bc[d] == GKYL_FIELD_RESERVOIR) + } else if (f->upper_bc[d] == GKYL_FIELD_RESERVOIR) { bctype = GKYL_BC_MAXWELL_RESERVOIR; + } - f->bc_up[d] = gkyl_bc_basic_new(d, GKYL_UPPER_EDGE, bctype, app->basis_on_dev.confBasis, - &app->upper_skin[d], &app->upper_ghost[d], f->em->ncomp, app->cdim, app->use_gpu); + f->bc_up[d] = gkyl_bc_basic_new( + d, GKYL_UPPER_EDGE, bctype, app->basis_on_dev.confBasis, &app->upper_skin[d], + &app->upper_ghost[d], f->em->ncomp, app->cdim, app->use_gpu + ); } gkyl_dg_eqn_release(eqn); @@ -193,14 +207,16 @@ vm_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) return f; } -void -vm_field_apply_ic(gkyl_vlasov_app *app, struct vm_field *field, double t0) +void vm_field_apply_ic(gkyl_vlasov_app *app, struct vm_field *field, double t0) { - if (!app->has_field) return; - + if (!app->has_field) { + return; + } + int poly_order = app->poly_order; - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - poly_order+1, 8, field->info.init, field->info.ctx); + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, poly_order + 1, 8, field->info.init, field->info.ctx + ); // run updater; need to project onto extended range for ease of handling // subsequent operations over extended range such as magnetic field unit vector computation @@ -222,8 +238,7 @@ vm_field_apply_ic(gkyl_vlasov_app *app, struct vm_field *field, double t0) vm_field_calc_app_current(app, field, t0); } -void -vm_field_calc_ext_em(gkyl_vlasov_app *app, struct vm_field *field, double tm) +void vm_field_calc_ext_em(gkyl_vlasov_app *app, struct vm_field *field, double tm) { if (field->has_ext_em) { gkyl_proj_on_basis_advance(field->ext_em_proj, tm, &app->local_ext, field->ext_em_host); @@ -234,11 +249,12 @@ vm_field_calc_ext_em(gkyl_vlasov_app *app, struct vm_field *field, double tm) } } -void -vm_field_calc_app_current(gkyl_vlasov_app *app, struct vm_field *field, double tm) +void vm_field_calc_app_current(gkyl_vlasov_app *app, struct vm_field *field, double tm) { if (field->has_app_current) { - gkyl_proj_on_basis_advance(field->app_current_proj, tm, &app->local_ext, field->app_current_host); + gkyl_proj_on_basis_advance( + field->app_current_proj, tm, &app->local_ext, field->app_current_host + ); if (app->use_gpu) { // note: app_current_host is same as app_current when not on GPUs gkyl_array_copy(field->app_current, field->app_current_host); @@ -246,48 +262,58 @@ vm_field_calc_app_current(gkyl_vlasov_app *app, struct vm_field *field, double t } } -void -vm_field_accumulate_current(gkyl_vlasov_app *app, - const struct gkyl_array *fin[], const struct gkyl_array *fluidin[], - struct gkyl_array *emout) +void vm_field_accumulate_current( + gkyl_vlasov_app *app, const struct gkyl_array *fin[], const struct gkyl_array *fluidin[], + struct gkyl_array *emout +) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct vm_species *s = &app->species[i]; - double qbyeps = s->info.charge/app->field->info.epsilon0; + double qbyeps = s->info.charge / app->field->info.epsilon0; vm_species_moment_calc(&s->m1i, s->local, app->local, fin[i]); gkyl_array_accumulate_range(emout, -qbyeps, s->m1i.marr, &app->local); if (app->field->use_ghost_current) { - double avals_ghost_current[1], avals_ghost_current_global[1]; - // First set the scalar ghost current array to the cell average - // current/(epsilon0*nx) where nx is the number of x cells. - gkyl_array_set_range(app->field->ghost_current, qbyeps/app->grid.cells[0], s->m1i.marr, &app->local); - // Integrate the current over the whole domain to find the globally averaged ghost current. + double avals_ghost_current[1], avals_ghost_current_global[1]; + // First set the scalar ghost current array to the cell average + // current/(epsilon0*nx) where nx is the number of x cells. + gkyl_array_set_range( + app->field->ghost_current, qbyeps / app->grid.cells[0], s->m1i.marr, &app->local + ); + // Integrate the current over the whole domain to find the globally averaged ghost current. if (app->use_gpu) { - gkyl_array_reduce_range(app->field->red_ghost_current, app->field->ghost_current, GKYL_SUM, &app->local); - gkyl_cu_memcpy(avals_ghost_current, app->field->red_ghost_current, sizeof(double[1]), GKYL_CU_MEMCPY_D2H); - } - else { - gkyl_array_reduce_range(avals_ghost_current, app->field->ghost_current, GKYL_SUM, &app->local); + gkyl_array_reduce_range( + app->field->red_ghost_current, app->field->ghost_current, GKYL_SUM, &app->local + ); + gkyl_cu_memcpy( + avals_ghost_current, app->field->red_ghost_current, sizeof(double[1]), GKYL_CU_MEMCPY_D2H + ); + } else { + gkyl_array_reduce_range( + avals_ghost_current, app->field->ghost_current, GKYL_SUM, &app->local + ); } - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, avals_ghost_current, avals_ghost_current_global); - // Set the scalar ghost current array to the global average current and accumulate to the electric field. + gkyl_comm_allreduce_host( + app->comm, GKYL_DOUBLE, GKYL_SUM, 1, avals_ghost_current, avals_ghost_current_global + ); + // Set the scalar ghost current array to the global average current and accumulate to the electric field. gkyl_array_clear(app->field->ghost_current, avals_ghost_current_global[0]); - gkyl_array_accumulate_range(emout, 1.0, app->field->ghost_current, &app->local); - } - } + gkyl_array_accumulate_range(emout, 1.0, app->field->ghost_current, &app->local); + } + } // Accumulate applied current to electric field terms // *Only* accumulate applied currents if num_fluid_species = 0 and there is no fluid-EM coupling. // If there are fluid species, then applied current coupling handled by implicit fluid-EM coupling // See vm_fluid_em_coupling.c if (app->field->has_app_current && !app->has_fluid_em_coupling) { - gkyl_array_accumulate_range(emout, -1.0/app->field->info.epsilon0, app->field->app_current, &app->local); + gkyl_array_accumulate_range( + emout, -1.0 / app->field->info.epsilon0, app->field->app_current, &app->local + ); } } -void -vm_field_limiter(gkyl_vlasov_app *app, struct vm_field *field, struct gkyl_array *em) +void vm_field_limiter(gkyl_vlasov_app *app, struct vm_field *field, struct gkyl_array *em) { if (field->limit_em) { // Limit the slopes of the solution @@ -300,81 +326,82 @@ vm_field_limiter(gkyl_vlasov_app *app, struct vm_field *field, struct gkyl_array // Compute the RHS for field update, returning maximum stable // time-step. -double -vm_field_rhs(gkyl_vlasov_app *app, struct vm_field *field, - const struct gkyl_array *em, struct gkyl_array *rhs) +double vm_field_rhs( + gkyl_vlasov_app *app, struct vm_field *field, const struct gkyl_array *em, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - - double omegaCfl = 1/DBL_MAX; - + + double omegaCfl = 1 / DBL_MAX; + gkyl_array_clear(field->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); if (!field->info.is_static) { gkyl_hyper_dg_advance(field->slvr, &app->local, em, field->cflrate, rhs); - + gkyl_array_reduce_range(field->omegaCfl_ptr, field->cflrate, GKYL_MAX, &app->local); app->stat.n_field_omega_cfl += 1; struct timespec tm = gkyl_wall_clock(); - + double omegaCfl_ho[1]; - if (app->use_gpu) + if (app->use_gpu) { gkyl_cu_memcpy(omegaCfl_ho, field->omegaCfl_ptr, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { omegaCfl_ho[0] = field->omegaCfl_ptr[0]; + } omegaCfl = omegaCfl_ho[0]; app->stat.field_omega_cfl_tm += gkyl_time_diff_now_sec(tm); } app->stat.field_rhs_tm += gkyl_time_diff_now_sec(wst); - - return app->cfl/omegaCfl; + + return app->cfl / omegaCfl; } // Determine which directions are periodic and which directions are not periodic, // and then apply boundary conditions for EM fields -void -vm_field_apply_bc(gkyl_vlasov_app *app, const struct vm_field *field, struct gkyl_array *f) +void vm_field_apply_bc(gkyl_vlasov_app *app, const struct vm_field *field, struct gkyl_array *f) { - struct timespec wst = gkyl_wall_clock(); - + struct timespec wst = gkyl_wall_clock(); + int num_periodic_dir = app->num_periodic_dir, cdim = app->cdim; - gkyl_comm_array_per_sync(app->comm, &app->local, &app->local_ext, - num_periodic_dir, app->periodic_dirs, f); - + gkyl_comm_array_per_sync( + app->comm, &app->local, &app->local_ext, num_periodic_dir, app->periodic_dirs, f + ); + int is_np_bc[3] = {1, 1, 1}; // flags to indicate if direction is periodic - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int d=0; dlower_bc[d]) { - case GKYL_FIELD_COPY: - case GKYL_FIELD_PEC_WALL: - case GKYL_FIELD_SYM_WALL: - case GKYL_FIELD_RESERVOIR: - gkyl_bc_basic_advance(field->bc_lo[d], field->bc_buffer, f); - break; - - default: - break; + case GKYL_FIELD_COPY: + case GKYL_FIELD_PEC_WALL: + case GKYL_FIELD_SYM_WALL: + case GKYL_FIELD_RESERVOIR: + gkyl_bc_basic_advance(field->bc_lo[d], field->bc_buffer, f); + break; + + default: + break; } switch (field->upper_bc[d]) { - case GKYL_FIELD_COPY: - case GKYL_FIELD_PEC_WALL: - case GKYL_FIELD_SYM_WALL: - case GKYL_FIELD_RESERVOIR: - gkyl_bc_basic_advance(field->bc_up[d], field->bc_buffer, f); - break; - - default: - break; - } + case GKYL_FIELD_COPY: + case GKYL_FIELD_PEC_WALL: + case GKYL_FIELD_SYM_WALL: + case GKYL_FIELD_RESERVOIR: + gkyl_bc_basic_advance(field->bc_up[d], field->bc_buffer, f); + break; + + default: + break; + } } } @@ -383,38 +410,36 @@ vm_field_apply_bc(gkyl_vlasov_app *app, const struct vm_field *field, struct gky app->stat.field_bc_tm += gkyl_time_diff_now_sec(wst); } -void -vm_field_calc_energy(gkyl_vlasov_app *app, double tm, const struct vm_field *field) +void vm_field_calc_energy(gkyl_vlasov_app *app, double tm, const struct vm_field *field) { - for (int i=0; i<6; ++i) + for (int i = 0; i < 6; ++i) { gkyl_dg_calc_l2_range(&app->confBasis, i, field->em_energy, i, field->em, app->local); + } gkyl_array_scale_range(field->em_energy, app->grid.cellVolume, &app->local); - - double energy[6] = { 0.0 }; + + double energy[6] = {0.0}; if (app->use_gpu) { gkyl_array_reduce_range(field->em_energy_red, field->em_energy, GKYL_SUM, &app->local); gkyl_cu_memcpy(energy, field->em_energy_red, sizeof(double[6]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { gkyl_array_reduce_range(energy, field->em_energy, GKYL_SUM, &app->local); } - double energy_global[6] = { 0.0 }; + double energy_global[6] = {0.0}; gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 6, energy, energy_global); - + gkyl_dynvec_append(field->integ_energy, tm, energy_global); } // release resources for field -void -vm_field_release(const gkyl_vlasov_app* app, struct vm_field *f) +void vm_field_release(const gkyl_vlasov_app *app, struct vm_field *f) { gkyl_array_release(f->em); gkyl_array_release(f->em1); gkyl_array_release(f->emnew); gkyl_array_release(f->tot_em); gkyl_array_release(f->em_dup); - + gkyl_array_release(f->bc_buffer); gkyl_array_release(f->cflrate); gkyl_array_release(f->em_energy); @@ -443,24 +468,22 @@ vm_field_release(const gkyl_vlasov_app* app, struct vm_field *f) gkyl_array_release(f->em_host); gkyl_cu_free(f->omegaCfl_ptr); gkyl_cu_free(f->em_energy_red); - } - else { + } else { gkyl_free(f->omegaCfl_ptr); } if (f->use_ghost_current) { - gkyl_array_release(f->ghost_current); + gkyl_array_release(f->ghost_current); if (app->use_gpu) { - gkyl_cu_free(f->red_ghost_current); + gkyl_cu_free(f->red_ghost_current); } } // Copy BCs are allocated by default. Need to free. - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { gkyl_bc_basic_release(f->bc_lo[d]); gkyl_bc_basic_release(f->bc_up[d]); } gkyl_free(f); } - diff --git a/vlasov/apps/vm_fluid_em_coupling.c b/vlasov/apps/vm_fluid_em_coupling.c index 2dea442ad3..b3e71fd0fd 100644 --- a/vlasov/apps/vm_fluid_em_coupling.c +++ b/vlasov/apps/vm_fluid_em_coupling.c @@ -8,86 +8,84 @@ #include // initialize fluid-EM coupling object -struct vm_fluid_em_coupling* -vm_fluid_em_coupling_init(struct gkyl_vlasov_app *app) +struct vm_fluid_em_coupling *vm_fluid_em_coupling_init(struct gkyl_vlasov_app *app) { struct vm_fluid_em_coupling *fl_em = gkyl_malloc(sizeof(struct vm_fluid_em_coupling)); int num_fluid_species = app->num_fluid_species; double qbym[GKYL_MAX_SPECIES] = {0.0}; - for (int i=0; ifluid_species[i]; - qbym[i] = fs->info.charge/fs->info.mass; + qbym[i] = fs->info.charge / fs->info.mass; } // Initialize solver - fl_em->slvr = gkyl_dg_calc_fluid_em_coupling_new(&app->confBasis, &app->local, - num_fluid_species, qbym, app->field->info.epsilon0, app->use_gpu); + fl_em->slvr = gkyl_dg_calc_fluid_em_coupling_new( + &app->confBasis, &app->local, num_fluid_species, qbym, app->field->info.epsilon0, app->use_gpu + ); - return fl_em; + return fl_em; } -void -vm_fluid_em_coupling_update(struct gkyl_vlasov_app *app, struct vm_fluid_em_coupling *fl_em, - double tcurr, double dt) +void vm_fluid_em_coupling_update( + struct gkyl_vlasov_app *app, struct vm_fluid_em_coupling *fl_em, double tcurr, double dt +) { int num_fluid_species = app->num_fluid_species; struct gkyl_array *fluids[GKYL_MAX_SPECIES]; const struct gkyl_array *app_accels[GKYL_MAX_SPECIES]; - for (int i=0; ifluid_species[i]; fluids[i] = fs->fluid; if (fs->eqn_type == GKYL_EQN_EULER) { - gkyl_dg_calc_fluid_vars_advance(fs->calc_fluid_vars, - fluids[i], fs->cell_avg_prim, fs->u, fs->u_surf); - gkyl_dg_calc_fluid_vars_ke(fs->calc_fluid_vars, &app->local, - fluids[i], fs->u, fs->ke_old); + gkyl_dg_calc_fluid_vars_advance( + fs->calc_fluid_vars, fluids[i], fs->cell_avg_prim, fs->u, fs->u_surf + ); + gkyl_dg_calc_fluid_vars_ke(fs->calc_fluid_vars, &app->local, fluids[i], fs->u, fs->ke_old); } - app_accels[i] = fs->app_accel; + app_accels[i] = fs->app_accel; // Compute applied accelerations if present and time-dependent. - // Note: applied accelerations use proj_on_basis + // Note: applied accelerations use proj_on_basis // so does copy to GPU every call if app->use_gpu = true. if (fs->app_accel_evolve) { vm_fluid_species_calc_app_accel(app, fs, tcurr); } } // Compute external EM field or applied currents if present and time-dependent. - // Note: external EM field and applied currents use proj_on_basis + // Note: external EM field and applied currents use proj_on_basis // so does copy to GPU every call if app->use_gpu = true. if (app->has_field) { if (app->field->ext_em_evolve) { vm_field_calc_ext_em(app, app->field, tcurr); } if (app->field->app_current_evolve) { - vm_field_calc_app_current(app, app->field, tcurr); + vm_field_calc_app_current(app, app->field, tcurr); } } - gkyl_dg_calc_fluid_em_coupling_advance(fl_em->slvr, dt, - app_accels, app->field->ext_em, app->field->app_current, - fluids, app->field->em); + gkyl_dg_calc_fluid_em_coupling_advance( + fl_em->slvr, dt, app_accels, app->field->ext_em, app->field->app_current, fluids, app->field->em + ); - for (int i=0; ifluid_species[i]; // Compute the updated energy from the old and new kinetic energies if (app->fluid_species[i].eqn_type == GKYL_EQN_EULER) { - gkyl_dg_calc_fluid_vars_advance(fs->calc_fluid_vars, - fluids[i], fs->cell_avg_prim, fs->u, fs->u_surf); - gkyl_dg_calc_fluid_vars_ke(fs->calc_fluid_vars, &app->local, - fluids[i], fs->u, fs->ke_new); - gkyl_dg_calc_fluid_em_coupling_energy(fl_em->slvr, - fs->ke_old, fs->ke_new, fluids[i]); + gkyl_dg_calc_fluid_vars_advance( + fs->calc_fluid_vars, fluids[i], fs->cell_avg_prim, fs->u, fs->u_surf + ); + gkyl_dg_calc_fluid_vars_ke(fs->calc_fluid_vars, &app->local, fluids[i], fs->u, fs->ke_new); + gkyl_dg_calc_fluid_em_coupling_energy(fl_em->slvr, fs->ke_old, fs->ke_new, fluids[i]); } vm_fluid_species_apply_bc(app, fs, fluids[i]); } vm_field_apply_bc(app, app->field, app->field->em); } -void -vm_fluid_em_coupling_release(struct gkyl_vlasov_app *app, struct vm_fluid_em_coupling *fl_em) +void vm_fluid_em_coupling_release(struct gkyl_vlasov_app *app, struct vm_fluid_em_coupling *fl_em) { gkyl_dg_calc_fluid_em_coupling_release(fl_em->slvr); gkyl_free(fl_em); diff --git a/vlasov/apps/vm_fluid_species.c b/vlasov/apps/vm_fluid_species.c index dea50dd085..d9595f3178 100644 --- a/vlasov/apps/vm_fluid_species.c +++ b/vlasov/apps/vm_fluid_species.c @@ -9,49 +9,50 @@ #include #include -// Euler and isothermal Euler function pointers for primitive/auxiliary variables, -// including computing the flow velocity, u, from rhou and rho with weak division, and +// Euler and isothermal Euler function pointers for primitive/auxiliary variables, +// including computing the flow velocity, u, from rhou and rho with weak division, and // p, the pressure, from the energy in Euler (and just vth*rho in isothermal Euler), -// and also write method, release method, and method for calculating integrated quantities. -static void -vm_fluid_species_euler_prim_vars(gkyl_vlasov_app *app, struct vm_fluid_species *f, - const struct gkyl_array *fluid) +// and also write method, release method, and method for calculating integrated quantities. +static void vm_fluid_species_euler_prim_vars( + gkyl_vlasov_app *app, struct vm_fluid_species *f, const struct gkyl_array *fluid +) { struct timespec tm = gkyl_wall_clock(); // Compute flow velocity in both the volume and on surfaces if (f->bc_is_absorb) { - gkyl_dg_calc_fluid_vars_advance(f->calc_fluid_vars, - fluid, f->cell_avg_prim, f->u, f->u_surf); - } - else { - gkyl_dg_calc_fluid_vars_advance(f->calc_fluid_vars_ext, - fluid, f->cell_avg_prim, f->u, f->u_surf); + gkyl_dg_calc_fluid_vars_advance(f->calc_fluid_vars, fluid, f->cell_avg_prim, f->u, f->u_surf); + } else { + gkyl_dg_calc_fluid_vars_advance( + f->calc_fluid_vars_ext, fluid, f->cell_avg_prim, f->u, f->u_surf + ); } // Compute scalar pressure in the volume and at needed surfaces - gkyl_dg_calc_fluid_vars_pressure(f->calc_fluid_vars, - &app->local_ext, fluid, f->u, f->p, f->p_surf); + gkyl_dg_calc_fluid_vars_pressure( + f->calc_fluid_vars, &app->local_ext, fluid, f->u, f->p, f->p_surf + ); - app->stat.fluid_species_vars_tm += gkyl_time_diff_now_sec(tm); + app->stat.fluid_species_vars_tm += gkyl_time_diff_now_sec(tm); } -static void -vm_fluid_species_euler_calc_integrated(struct gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm) +static void vm_fluid_species_euler_calc_integrated( + struct gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm +) { - double avals_fluid[6], avals_fluid_global[6]; + double avals_fluid[6], avals_fluid_global[6]; gkyl_array_clear(f->integ_mom, 0.0); vm_fluid_species_prim_vars(app, f, f->fluid); // Euler and isothermal Euler integrated quantities: rho, rhoux, rhouy, rhouz, ke, ie // where ke is the kinetic energy 1/2 rhou^2 and ie is the internal energy (for ideal Euler = p/(gas_gamma - 1)) - gkyl_dg_calc_fluid_integrated_vars(f->calc_fluid_vars, &app->local, - f->fluid, f->u, f->p, f->integ_mom); + gkyl_dg_calc_fluid_integrated_vars( + f->calc_fluid_vars, &app->local, f->fluid, f->u, f->p, f->integ_mom + ); gkyl_array_scale_range(f->integ_mom, app->grid.cellVolume, &app->local); if (app->use_gpu) { gkyl_array_reduce_range(f->red_integ_diag, f->integ_mom, GKYL_SUM, &app->local); gkyl_cu_memcpy(avals_fluid, f->red_integ_diag, sizeof(double[6]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { gkyl_array_reduce_range(avals_fluid, f->integ_mom, GKYL_SUM, &app->local); } @@ -60,54 +61,45 @@ vm_fluid_species_euler_calc_integrated(struct gkyl_vlasov_app *app, struct vm_fl } static void -vm_fluid_species_euler_write(gkyl_vlasov_app *app, struct vm_fluid_species *f, - double tm, int frame) +vm_fluid_species_euler_write(gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm, int frame) { - struct gkyl_msgpack_data *mt = vlasov_array_meta_new( (struct vlasov_output_meta) { - .frame = frame, - .stime = tm, - .poly_order = app->poly_order, - .basis_type = app->confBasis.id - } - ); + struct gkyl_msgpack_data *mt = vlasov_array_meta_new((struct vlasov_output_meta + ){.frame = frame, .stime = tm, .poly_order = app->poly_order, .basis_type = app->confBasis.id}); const char *fmt = "%s-%s_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, f->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, f->info.name, frame); // copy data from device to host before writing it out if (app->use_gpu) { gkyl_array_copy(f->fluid_host, f->fluid); } - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, f->fluid_host, fileNm); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, f->fluid_host, fileNm); // Also write out the primitive variables (u, p) vm_fluid_species_prim_vars(app, f, f->fluid); const char *fmt_prim = "%s-%s_prim_vars_%d.gkyl"; int sz_prim = gkyl_calc_strlen(fmt_prim, app->name, f->info.name, frame); - char fileNm_prim[sz_prim+1]; // ensures no buffer overflow + char fileNm_prim[sz_prim + 1]; // ensures no buffer overflow snprintf(fileNm_prim, sizeof fileNm_prim, fmt_prim, app->name, f->info.name, frame); // copy data to single array and then from device to host (if on GPUs) before writing it out - gkyl_array_set(f->prim_vars, 1.0, f->u); - gkyl_array_set_offset(f->prim_vars, 1.0, f->p, 3*app->confBasis.num_basis); + gkyl_array_set(f->prim_vars, 1.0, f->u); + gkyl_array_set_offset(f->prim_vars, 1.0, f->p, 3 * app->confBasis.num_basis); if (app->use_gpu) { gkyl_array_copy(f->prim_vars_host, f->prim_vars); } - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, f->prim_vars_host, fileNm_prim); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, f->prim_vars_host, fileNm_prim); - vlasov_array_meta_release(mt); + vlasov_array_meta_release(mt); } -static void -vm_fluid_species_euler_release(const gkyl_vlasov_app *app, struct vm_fluid_species *f) +static void vm_fluid_species_euler_release(const gkyl_vlasov_app *app, struct vm_fluid_species *f) { gkyl_array_release(f->u); gkyl_array_release(f->p); - gkyl_array_release(f->prim_vars); + gkyl_array_release(f->prim_vars); gkyl_array_release(f->prim_vars_host); gkyl_array_release(f->cell_avg_prim); gkyl_array_release(f->u_surf); @@ -118,38 +110,41 @@ vm_fluid_species_euler_release(const gkyl_vlasov_app *app, struct vm_fluid_speci gkyl_dg_calc_fluid_vars_release(f->calc_fluid_vars_ext); } -// Initialize the necessary pieces to solve Euler's or isothermal Euler's equations with DG. -static void -vm_fluid_species_euler_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_fluid_species *f) +// Initialize the necessary pieces to solve Euler's or isothermal Euler's equations with DG. +static void vm_fluid_species_euler_init( + struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_fluid_species *f +) { // allocate array to store fluid velocity (ux, uy, uz) and pressure // For isothermal Euler, p : (vth*rho) // For Euler, p : (gamma - 1)*(E - 1/2 rho u^2) - f->u = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); + f->u = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); f->p = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - // Combined (u, p) primitive variables array for I/O. - f->prim_vars = mkarr(app->use_gpu, 4*app->confBasis.num_basis, app->local_ext.volume); - f->prim_vars_host = app->use_gpu ? mkarr(false, 4*app->confBasis.num_basis, app->local_ext.volume) - : gkyl_array_acquire(f->prim_vars); + // Combined (u, p) primitive variables array for I/O. + f->prim_vars = mkarr(app->use_gpu, 4 * app->confBasis.num_basis, app->local_ext.volume); + f->prim_vars_host = app->use_gpu ? + mkarr(false, 4 * app->confBasis.num_basis, app->local_ext.volume) : + gkyl_array_acquire(f->prim_vars); // boolean array for if we are only using the cell average for primitive variables f->cell_avg_prim = mk_int_arr(app->use_gpu, 1, app->local_ext.volume); // Allocate arrays for kinetic energy at old and new time steps. - // These are used because implicit source solve updates momentum but does not affect + // These are used because implicit source solve updates momentum but does not affect // the pressure, so we can construct the updated energy from the updated momentum. - f->ke_old = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - f->ke_new = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); + f->ke_old = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); + f->ke_new = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - int Nbasis_surf = app->confBasis.num_basis/(app->confBasis.poly_order + 1); // *only valid for tensor bases for cdim > 1* + int Nbasis_surf = app->confBasis.num_basis / + (app->confBasis.poly_order + 1); // *only valid for tensor bases for cdim > 1* // Surface primitive variables (2*cdim*3 components). Ordered as: - // [ux_xl, ux_xr, uy_xl, uy_xr, uz_xl, uz_xr, - // ux_yl, ux_yr, uy_yl, uy_yr, uz_yl, uz_yr, - // ux_zl, ux_zr, uy_zl, uy_zr, uz_zl, uz_zr] - f->u_surf = mkarr(app->use_gpu, 2*app->cdim*3*Nbasis_surf, app->local_ext.volume); + // [ux_xl, ux_xr, uy_xl, uy_xr, uz_xl, uz_xr, + // ux_yl, ux_yr, uy_yl, uy_yr, uz_yl, uz_yr, + // ux_zl, ux_zr, uy_zl, uy_zr, uz_zl, uz_zr] + f->u_surf = mkarr(app->use_gpu, 2 * app->cdim * 3 * Nbasis_surf, app->local_ext.volume); // Surface pressure tensor (2*cdim components). Ordered as: // [p_xl, p_xr, p_yl, p_yr, p_zl, p_zr] - f->p_surf = mkarr(app->use_gpu, 2*app->cdim*Nbasis_surf, app->local_ext.volume); + f->p_surf = mkarr(app->use_gpu, 2 * app->cdim * Nbasis_surf, app->local_ext.volume); // Check if limiter_fac is specified for adjusting how much diffusion is applied through slope limiter // If not specified, set to 0.0 and updater sets default behavior (1/sqrt(3); see gkyl_dg_calc_fluid_vars.h) @@ -158,13 +153,19 @@ vm_fluid_species_euler_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, str // updater for computing fluid variables: flow velocity and pressure // also stores kernels for computing source terms, integrated variables // Two instances, one over extended range and one over local range for ease of handling boundary conditions - f->calc_fluid_vars_ext = gkyl_dg_calc_fluid_vars_new(f->equation, app->geom, &app->confBasis, &app->local_ext, limiter_fac, app->use_gpu); - f->calc_fluid_vars = gkyl_dg_calc_fluid_vars_new(f->equation, app->geom, &app->confBasis, &app->local, limiter_fac, app->use_gpu); + f->calc_fluid_vars_ext = gkyl_dg_calc_fluid_vars_new( + f->equation, app->geom, &app->confBasis, &app->local_ext, limiter_fac, app->use_gpu + ); + f->calc_fluid_vars = gkyl_dg_calc_fluid_vars_new( + f->equation, app->geom, &app->confBasis, &app->local, limiter_fac, app->use_gpu + ); - struct gkyl_dg_euler_auxfields aux_inp = {.u = f->u, .p = f->p, - .u_surf = f->u_surf, .p_surf = f->p_surf}; - f->advect_slvr = gkyl_dg_updater_fluid_new(&app->grid, &app->confBasis, - &app->local, f->equation, app->geom, &aux_inp, app->use_gpu); + struct gkyl_dg_euler_auxfields aux_inp = { + .u = f->u, .p = f->p, .u_surf = f->u_surf, .p_surf = f->p_surf + }; + f->advect_slvr = gkyl_dg_updater_fluid_new( + &app->grid, &app->confBasis, &app->local, f->equation, app->geom, &aux_inp, app->use_gpu + ); // Euler and isothermal Euler integrated quantities: rho, rhoux, rhouy, rhouz, ke, ie // where ke is the kinetic energy 1/2 rhou^2 and ie is the internal energy (for ideal Euler = p/(gas_gamma - 1)) @@ -172,55 +173,54 @@ vm_fluid_species_euler_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, str if (app->use_gpu) { f->red_integ_diag = gkyl_cu_malloc(sizeof(double[6])); } - // allocate dynamic-vector to store all-reduced integrated moments + // allocate dynamic-vector to store all-reduced integrated moments f->integ_diag = gkyl_dynvec_new(GKYL_DOUBLE, 6); f->is_first_integ_write_call = true; - f->prim_vars_func = vm_fluid_species_euler_prim_vars; - f->calc_integrated_mom_func = vm_fluid_species_euler_calc_integrated; - f->write_func = vm_fluid_species_euler_write; - f->release_func = vm_fluid_species_euler_release; + f->prim_vars_func = vm_fluid_species_euler_prim_vars; + f->calc_integrated_mom_func = vm_fluid_species_euler_calc_integrated; + f->write_func = vm_fluid_species_euler_write; + f->release_func = vm_fluid_species_euler_release; } -// Advection function pointers for primitive/auxiliary variables, -// and also write method, release method, and method for calculating integrated quantities. -static void -vm_fluid_species_advect_prim_vars(gkyl_vlasov_app *app, struct vm_fluid_species *f, - const struct gkyl_array *fluid) +// Advection function pointers for primitive/auxiliary variables, +// and also write method, release method, and method for calculating integrated quantities. +static void vm_fluid_species_advect_prim_vars( + gkyl_vlasov_app *app, struct vm_fluid_species *f, const struct gkyl_array *fluid +) { - // No primitive variables in advection equation. + // No primitive variables in advection equation. } -static void -vm_fluid_species_advect_calc_integrated(struct gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm) +static void vm_fluid_species_advect_calc_integrated( + struct gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm +) { - double avals_fluid[1], avals_fluid_global[1]; + double avals_fluid[1], avals_fluid_global[1]; // Advection equation integrated quantity: f, f^2 double advect_int[2]; // First calculate f - gkyl_array_clear(f->integ_mom, 0.0); + gkyl_array_clear(f->integ_mom, 0.0); gkyl_dg_calc_average_range(&app->confBasis, 0, f->integ_mom, 0, f->fluid, app->local); gkyl_array_scale_range(f->integ_mom, app->grid.cellVolume, &app->local); if (app->use_gpu) { gkyl_array_reduce_range(f->red_integ_diag, f->integ_mom, GKYL_SUM, &app->local); gkyl_cu_memcpy(avals_fluid, f->red_integ_diag, sizeof(double[1]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { gkyl_array_reduce_range(avals_fluid, f->integ_mom, GKYL_SUM, &app->local); } gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, avals_fluid, avals_fluid_global); advect_int[0] = avals_fluid_global[0]; // Now calculate f^2 - gkyl_array_clear(f->integ_mom, 0.0); + gkyl_array_clear(f->integ_mom, 0.0); gkyl_dg_calc_l2_range(&app->confBasis, 0, f->integ_mom, 0, f->fluid, app->local); gkyl_array_scale_range(f->integ_mom, app->grid.cellVolume, &app->local); if (app->use_gpu) { gkyl_array_reduce_range(f->red_integ_diag, f->integ_mom, GKYL_SUM, &app->local); gkyl_cu_memcpy(avals_fluid, f->red_integ_diag, sizeof(double[1]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { gkyl_array_reduce_range(avals_fluid, f->integ_mom, GKYL_SUM, &app->local); } gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, avals_fluid, avals_fluid_global); @@ -230,49 +230,40 @@ vm_fluid_species_advect_calc_integrated(struct gkyl_vlasov_app *app, struct vm_f } static void -vm_fluid_species_advect_write(gkyl_vlasov_app *app, struct vm_fluid_species *f, - double tm, int frame) +vm_fluid_species_advect_write(gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm, int frame) { - struct gkyl_msgpack_data *mt = vlasov_array_meta_new( (struct vlasov_output_meta) { - .frame = frame, - .stime = tm, - .poly_order = app->poly_order, - .basis_type = app->confBasis.id - } - ); + struct gkyl_msgpack_data *mt = vlasov_array_meta_new((struct vlasov_output_meta + ){.frame = frame, .stime = tm, .poly_order = app->poly_order, .basis_type = app->confBasis.id}); const char *fmt = "%s-%s_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, f->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, f->info.name, frame); // copy data from device to host before writing it out if (app->use_gpu) { gkyl_array_copy(f->fluid_host, f->fluid); } - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, f->fluid_host, fileNm); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, f->fluid_host, fileNm); - // If frame = 0, as part of initial conditions also write out the applied advection. + // If frame = 0, as part of initial conditions also write out the applied advection. if (frame == 0) { const char *fmt_advect = "%s-%s_advect_%d.gkyl"; int sz_advect = gkyl_calc_strlen(fmt_advect, app->name, f->info.name, frame); - char fileNm_advect[sz_advect+1]; // ensures no buffer overflow + char fileNm_advect[sz_advect + 1]; // ensures no buffer overflow snprintf(fileNm_advect, sizeof fileNm_advect, fmt_advect, app->name, f->info.name, frame); // copy data from device to host before writing it out if (app->use_gpu) { gkyl_array_copy(f->app_advect_host, f->app_advect); } - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, f->app_advect_host, fileNm_advect); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, f->app_advect_host, fileNm_advect); } - vlasov_array_meta_release(mt); + vlasov_array_meta_release(mt); } -static void -vm_fluid_species_advect_release(const gkyl_vlasov_app *app, struct vm_fluid_species *f) +static void vm_fluid_species_advect_release(const gkyl_vlasov_app *app, struct vm_fluid_species *f) { gkyl_array_release(f->app_advect); if (app->use_gpu) { @@ -280,21 +271,23 @@ vm_fluid_species_advect_release(const gkyl_vlasov_app *app, struct vm_fluid_spec } } -// Initialize the necessary pieces to solve an advection equation with DG. -static void -vm_fluid_species_advect_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_fluid_species *f) +// Initialize the necessary pieces to solve an advection equation with DG. +static void vm_fluid_species_advect_init( + struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_fluid_species *f +) { - // setup FEM representation of applied advection - // - f->app_advect = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); + // setup FEM representation of applied advection + // + f->app_advect = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); f->app_advect_host = f->app_advect; if (app->use_gpu) { - f->app_advect_host = mkarr(false, 3*app->confBasis.num_basis, app->local_ext.volume); + f->app_advect_host = mkarr(false, 3 * app->confBasis.num_basis, app->local_ext.volume); } // Evaluate specified advection function at nodes to insure continuity of advection velocity - struct gkyl_eval_on_nodes* app_advect_proj = gkyl_eval_on_nodes_new(&app->grid, &app->confBasis, 3, - f->info.advection.velocity, f->info.advection.velocity_ctx); + struct gkyl_eval_on_nodes *app_advect_proj = gkyl_eval_on_nodes_new( + &app->grid, &app->confBasis, 3, f->info.advection.velocity, f->info.advection.velocity_ctx + ); gkyl_eval_on_nodes_advance(app_advect_proj, 0.0, &app->local_ext, f->app_advect_host); if (app->use_gpu) { gkyl_array_copy(f->app_advect, f->app_advect_host); @@ -302,8 +295,9 @@ vm_fluid_species_advect_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, st gkyl_eval_on_nodes_release(app_advect_proj); struct gkyl_dg_advection_auxfields aux_inp = {.u_i = f->app_advect}; - f->advect_slvr = gkyl_dg_updater_fluid_new(&app->grid, &app->confBasis, - &app->local, f->equation, app->geom, &aux_inp, app->use_gpu); + f->advect_slvr = gkyl_dg_updater_fluid_new( + &app->grid, &app->confBasis, &app->local, f->equation, app->geom, &aux_inp, app->use_gpu + ); // array for storing integrated quantities in each cell = f, f^2 // We compute each separate and then write them to the dynvector f->integ_diag @@ -315,133 +309,127 @@ vm_fluid_species_advect_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, st f->integ_diag = gkyl_dynvec_new(GKYL_DOUBLE, 2); f->is_first_integ_write_call = true; - f->prim_vars_func = vm_fluid_species_advect_prim_vars; - f->calc_integrated_mom_func = vm_fluid_species_advect_calc_integrated; - f->write_func = vm_fluid_species_advect_write; - f->release_func = vm_fluid_species_advect_release; + f->prim_vars_func = vm_fluid_species_advect_prim_vars; + f->calc_integrated_mom_func = vm_fluid_species_advect_calc_integrated; + f->write_func = vm_fluid_species_advect_write; + f->release_func = vm_fluid_species_advect_release; } -// Canonical Poisson Bracket fluid function pointers for primitive/auxiliary variables, -// including computing grad^2 phi = f, where f is (one of) the evolved quantities by -// the canonical Poisson bracket system such as vorticity in incompressible Euler, -// and also write method, release method, and method for calculating integrated quantities. -static void -vm_fluid_species_can_pb_fluid_prim_vars(gkyl_vlasov_app *app, struct vm_fluid_species *f, - const struct gkyl_array *fluid) +// Canonical Poisson Bracket fluid function pointers for primitive/auxiliary variables, +// including computing grad^2 phi = f, where f is (one of) the evolved quantities by +// the canonical Poisson bracket system such as vorticity in incompressible Euler, +// and also write method, release method, and method for calculating integrated quantities. +static void vm_fluid_species_can_pb_fluid_prim_vars( + gkyl_vlasov_app *app, struct vm_fluid_species *f, const struct gkyl_array *fluid +) { struct timespec wst = gkyl_wall_clock(); // Gather RHS of Poisson solve into global array. - gkyl_comm_array_allgather(app->comm, &app->local, &app->global, - fluid, f->poisson_rhs_global); + gkyl_comm_array_allgather(app->comm, &app->local, &app->global, fluid, f->poisson_rhs_global); // Solve the Poisson problem. gkyl_fem_poisson_set_rhs(f->fem_poisson, f->poisson_rhs_global, 0); gkyl_fem_poisson_solve(f->fem_poisson, f->phi_global); // Copy the portion of global potential corresponding to this MPI process to the local potential. - gkyl_array_copy_range_to_range(f->phi, f->phi_global, - &app->local, &f->global_sub_range); + gkyl_array_copy_range_to_range(f->phi, f->phi_global, &app->local, &f->global_sub_range); - app->stat.field_rhs_tm += gkyl_time_diff_now_sec(wst); + app->stat.field_rhs_tm += gkyl_time_diff_now_sec(wst); } -static void -vm_fluid_species_can_pb_fluid_calc_integrated(struct gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm) -{ - double avals_fluid[1], avals_fluid_global[1]; +static void vm_fluid_species_can_pb_fluid_calc_integrated( + struct gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm +) +{ + double avals_fluid[1], avals_fluid_global[1]; // Canonical Poisson bracket for fluid equations integrated quantities: f, f^2, E // where E is the integrated energy = integral(phi*f) since f = grad^2 phi -> E = integral(|grad phi|^2) double can_pb_int[3]; // First calculate f - gkyl_array_clear(f->integ_mom, 0.0); + gkyl_array_clear(f->integ_mom, 0.0); gkyl_dg_calc_average_range(&app->confBasis, 0, f->integ_mom, 0, f->fluid, app->local); gkyl_array_scale_range(f->integ_mom, app->grid.cellVolume, &app->local); if (app->use_gpu) { gkyl_array_reduce_range(f->red_integ_diag, f->integ_mom, GKYL_SUM, &app->local); gkyl_cu_memcpy(avals_fluid, f->red_integ_diag, sizeof(double[1]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { gkyl_array_reduce_range(avals_fluid, f->integ_mom, GKYL_SUM, &app->local); } gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, avals_fluid, avals_fluid_global); can_pb_int[0] = avals_fluid_global[0]; // Now calculate f^2 - gkyl_array_clear(f->integ_mom, 0.0); + gkyl_array_clear(f->integ_mom, 0.0); gkyl_dg_calc_l2_range(&app->confBasis, 0, f->integ_mom, 0, f->fluid, app->local); gkyl_array_scale_range(f->integ_mom, app->grid.cellVolume, &app->local); if (app->use_gpu) { gkyl_array_reduce_range(f->red_integ_diag, f->integ_mom, GKYL_SUM, &app->local); gkyl_cu_memcpy(avals_fluid, f->red_integ_diag, sizeof(double[1]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { gkyl_array_reduce_range(avals_fluid, f->integ_mom, GKYL_SUM, &app->local); } gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, avals_fluid, avals_fluid_global); can_pb_int[1] = avals_fluid_global[0]; - // Now calculate E - // First solve the Poisson equation for phi + // Now calculate E + // First solve the Poisson equation for phi vm_fluid_species_prim_vars(app, f, f->fluid); // integrate |grad phi|^2 - gkyl_array_integrate_advance(f->calc_can_pb_energy, f->phi, - app->grid.cellVolume, f->can_pb_energy_fac, &app->local, &app->local, f->red_can_pb_energy); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, f->red_can_pb_energy, f->red_can_pb_energy_global); + gkyl_array_integrate_advance( + f->calc_can_pb_energy, f->phi, app->grid.cellVolume, f->can_pb_energy_fac, &app->local, + &app->local, f->red_can_pb_energy + ); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, 1, f->red_can_pb_energy, f->red_can_pb_energy_global + ); if (app->use_gpu) { - gkyl_cu_memcpy(avals_fluid_global, f->red_can_pb_energy_global, sizeof(double[1]), GKYL_CU_MEMCPY_D2H); - } - else { + gkyl_cu_memcpy( + avals_fluid_global, f->red_can_pb_energy_global, sizeof(double[1]), GKYL_CU_MEMCPY_D2H + ); + } else { avals_fluid_global[0] = f->red_can_pb_energy_global[0]; } can_pb_int[2] = avals_fluid_global[0]; gkyl_dynvec_append(f->integ_diag, tm, can_pb_int); - } -static void -vm_fluid_species_can_pb_fluid_write(gkyl_vlasov_app *app, struct vm_fluid_species *f, - double tm, int frame) +static void vm_fluid_species_can_pb_fluid_write( + gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm, int frame +) { - struct gkyl_msgpack_data *mt = vlasov_array_meta_new( (struct vlasov_output_meta) { - .frame = frame, - .stime = tm, - .poly_order = app->poly_order, - .basis_type = app->confBasis.id - } - ); + struct gkyl_msgpack_data *mt = vlasov_array_meta_new((struct vlasov_output_meta + ){.frame = frame, .stime = tm, .poly_order = app->poly_order, .basis_type = app->confBasis.id}); const char *fmt = "%s-%s_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, f->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, f->info.name, frame); // copy data from device to host before writing it out if (app->use_gpu) { gkyl_array_copy(f->fluid_host, f->fluid); } - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, f->fluid_host, fileNm); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, f->fluid_host, fileNm); // If fluid species is a canonical PB fluid and we are also solving a - // Poisson equation, also write out phi, the potential. + // Poisson equation, also write out phi, the potential. vm_fluid_species_prim_vars(app, f, f->fluid); const char *fmt_phi = "%s-phi_%d.gkyl"; int sz_phi = gkyl_calc_strlen(fmt_phi, app->name, frame); - char fileNm_phi[sz_phi+1]; // ensures no buffer overflow + char fileNm_phi[sz_phi + 1]; // ensures no buffer overflow snprintf(fileNm_phi, sizeof fileNm_phi, fmt_phi, app->name, frame); // copy data from device to host before writing it out if (app->use_gpu) { gkyl_array_copy(f->phi_host, f->phi); } - gkyl_comm_array_write(app->comm, &app->grid, &app->local, - mt, f->phi_host, fileNm_phi); + gkyl_comm_array_write(app->comm, &app->grid, &app->local, mt, f->phi_host, fileNm_phi); - vlasov_array_meta_release(mt); + vlasov_array_meta_release(mt); } static void @@ -451,62 +439,66 @@ vm_fluid_species_can_pb_fluid_release(const gkyl_vlasov_app *app, struct vm_flui gkyl_array_release(f->phi_global); gkyl_array_release(f->phi_host); gkyl_array_release(f->poisson_rhs_global); - gkyl_array_release(f->can_pb_n0); + gkyl_array_release(f->can_pb_n0); gkyl_array_release(f->epsilon); if (f->eqn_type == GKYL_EQN_CAN_PB_HASEGAWA_MIMA) { gkyl_array_release(f->kSq); } gkyl_fem_poisson_release(f->fem_poisson); - gkyl_array_release(f->alpha_surf); - gkyl_array_release(f->sgn_alpha_surf); - gkyl_array_release(f->const_sgn_alpha); - gkyl_dg_calc_canonical_pb_fluid_vars_release(f->calc_can_pb_fluid_vars); + gkyl_array_release(f->alpha_surf); + gkyl_array_release(f->sgn_alpha_surf); + gkyl_array_release(f->const_sgn_alpha); + gkyl_dg_calc_canonical_pb_fluid_vars_release(f->calc_can_pb_fluid_vars); gkyl_array_integrate_release(f->calc_can_pb_energy); gkyl_array_release(f->can_pb_energy_fac); if (app->use_gpu) { gkyl_cu_free(f->red_can_pb_energy); gkyl_cu_free(f->red_can_pb_energy_global); - } - else { + } else { gkyl_free(f->red_can_pb_energy); gkyl_free(f->red_can_pb_energy_global); } } -// Initialize the necessary pieces to solve an canonical Poisson bracket fluid system with DG +// Initialize the necessary pieces to solve an canonical Poisson bracket fluid system with DG // such as incompressible Euler, Hasegawa-Mima, and (modified) Hasegawa-Wakatani. -static void -vm_fluid_species_can_pb_fluid_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_fluid_species *f) +static void vm_fluid_species_can_pb_fluid_init( + struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_fluid_species *f +) { - assert(app->cdim == 2); // Canonical PB fluid only works with cdim = 2. + assert(app->cdim == 2); // Canonical PB fluid only works with cdim = 2. // canonical PB fluids couple to a Poisson equation; initialize that - // here for now, though it might be better to utilize the vp_field + // here for now, though it might be better to utilize the vp_field // infrastructure once that becomes more flexible (JJ: 02/03/2025) // Allocate arrays for potential and global rhs of Poisson solve. f->phi = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); f->phi_global = mkarr(app->use_gpu, app->confBasis.num_basis, app->global_ext.volume); - f->poisson_rhs_global = mkarr(app->use_gpu, f->num_equations*app->confBasis.num_basis, app->global_ext.volume); + f->poisson_rhs_global = + mkarr(app->use_gpu, f->num_equations * app->confBasis.num_basis, app->global_ext.volume); // Host potential for I/O. - f->phi_host = app->use_gpu ? mkarr(false, app->confBasis.num_basis, app->local_ext.volume) - : gkyl_array_acquire(f->phi); + f->phi_host = app->use_gpu ? mkarr(false, app->confBasis.num_basis, app->local_ext.volume) : + gkyl_array_acquire(f->phi); // Initialize background gradient which drives turbulence in some fluid systems such as - // Hasegawa-Mima and Hasegawa-Wakatani. This background is included as a source via + // Hasegawa-Mima and Hasegawa-Wakatani. This background is included as a source via // the Poisson bracket: source = {phi, n0} where {., .} is the canonical bracket. f->can_pb_n0 = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - gkyl_array_clear(f->can_pb_n0, 0.0); - if (f->eqn_type == GKYL_EQN_CAN_PB_HASEGAWA_MIMA || f->eqn_type == GKYL_EQN_CAN_PB_HASEGAWA_WAKATANI) { - struct gkyl_array* can_pb_n0_host = mkarr(false, app->confBasis.num_basis, app->local_ext.volume); + gkyl_array_clear(f->can_pb_n0, 0.0); + if (f->eqn_type == GKYL_EQN_CAN_PB_HASEGAWA_MIMA || + f->eqn_type == GKYL_EQN_CAN_PB_HASEGAWA_WAKATANI) { + struct gkyl_array *can_pb_n0_host = + mkarr(false, app->confBasis.num_basis, app->local_ext.volume); // Evaluate specified background gradient function at nodes to insure continuity of gradient - struct gkyl_eval_on_nodes* can_pb_n0_proj = gkyl_eval_on_nodes_new(&app->grid, &app->confBasis, 1, - f->info.can_pb_n0, f->info.can_pb_n0_ctx); + struct gkyl_eval_on_nodes *can_pb_n0_proj = gkyl_eval_on_nodes_new( + &app->grid, &app->confBasis, 1, f->info.can_pb_n0, f->info.can_pb_n0_ctx + ); gkyl_eval_on_nodes_advance(can_pb_n0_proj, 0.0, &app->local_ext, can_pb_n0_host); gkyl_array_copy(f->can_pb_n0, can_pb_n0_host); - gkyl_eval_on_nodes_release(can_pb_n0_proj); - gkyl_array_release(can_pb_n0_host); + gkyl_eval_on_nodes_release(can_pb_n0_proj); + gkyl_array_release(can_pb_n0_host); } // Create global subrange we'll copy the field solver solution from (into local). @@ -514,47 +506,49 @@ vm_fluid_species_can_pb_fluid_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *a // Set the permittivity in the Poisson equation. Just a constant value of -1.0 // so that overall Poisson equation becomes grad^2 phi = RHS since FEM Poisson - // solver by default assumes Poisson equation of the form -nabla . (epsilon . grad phi) = RHS. + // solver by default assumes Poisson equation of the form -nabla . (epsilon . grad phi) = RHS. f->epsilon = mkarr(app->use_gpu, app->confBasis.num_basis, app->global_ext.volume); gkyl_array_clear(f->epsilon, 0.0); - gkyl_array_shiftc(f->epsilon, -1.0*pow(sqrt(2.0),app->cdim), 0); + gkyl_array_shiftc(f->epsilon, -1.0 * pow(sqrt(2.0), app->cdim), 0); - // Create Poisson solver. Only supports periodic boundary conditions for now. + // Create Poisson solver. Only supports periodic boundary conditions for now. struct gkyl_poisson_bc poisson_bcs = { - .lo_type = { GKYL_POISSON_PERIODIC, GKYL_POISSON_PERIODIC }, - .up_type = { GKYL_POISSON_PERIODIC, GKYL_POISSON_PERIODIC }, + .lo_type = {GKYL_POISSON_PERIODIC, GKYL_POISSON_PERIODIC}, + .up_type = {GKYL_POISSON_PERIODIC, GKYL_POISSON_PERIODIC} }; if (f->eqn_type == GKYL_EQN_CAN_PB_HASEGAWA_MIMA) { // If Hasegawa-Mima, we solve a Helmholtz equations (grad^2 - 1)phi = zeta - // where zeta is vorticity (the quantity we are evolving). + // where zeta is vorticity (the quantity we are evolving). f->kSq = mkarr(app->use_gpu, app->confBasis.num_basis, app->global_ext.volume); gkyl_array_clear(f->kSq, 0.0); - gkyl_array_shiftc(f->kSq, pow(sqrt(2.0),app->cdim), 0); - f->fem_poisson = gkyl_fem_poisson_new(&app->global, &app->grid, app->confBasis, - &poisson_bcs, 0, f->epsilon, f->kSq, true, app->use_gpu); - } - else { - f->fem_poisson = gkyl_fem_poisson_new(&app->global, &app->grid, app->confBasis, - &poisson_bcs, 0, f->epsilon, NULL, true, app->use_gpu); + gkyl_array_shiftc(f->kSq, pow(sqrt(2.0), app->cdim), 0); + f->fem_poisson = gkyl_fem_poisson_new( + &app->global, &app->grid, app->confBasis, &poisson_bcs, 0, f->epsilon, f->kSq, true, + app->use_gpu + ); + } else { + f->fem_poisson = gkyl_fem_poisson_new( + &app->global, &app->grid, app->confBasis, &poisson_bcs, 0, f->epsilon, NULL, true, + app->use_gpu + ); } - f->has_poisson = true; + f->has_poisson = true; - // Need to figure out size of alpha_surf and sgn_alpha_surf by finding size of surface basis set - struct gkyl_basis surf_basis, surf_quad_basis; + // Need to figure out size of alpha_surf and sgn_alpha_surf by finding size of surface basis set + struct gkyl_basis surf_basis, surf_quad_basis; if (app->confBasis.b_type == GKYL_BASIS_MODAL_SERENDIPITY) { - gkyl_cart_modal_serendip(&surf_basis, app->cdim-1, app->poly_order); - } - else if (app->confBasis.b_type == GKYL_BASIS_MODAL_TENSOR) { - gkyl_cart_modal_tensor(&surf_basis, app->cdim-1, app->poly_order); - } - else { + gkyl_cart_modal_serendip(&surf_basis, app->cdim - 1, app->poly_order); + } else if (app->confBasis.b_type == GKYL_BASIS_MODAL_TENSOR) { + gkyl_cart_modal_tensor(&surf_basis, app->cdim - 1, app->poly_order); + } else { assert(false); } - gkyl_cart_modal_tensor(&surf_quad_basis, app->cdim-1, app->poly_order); - int alpha_surf_sz = app->cdim*surf_basis.num_basis; - int sgn_alpha_surf_sz = app->cdim*surf_quad_basis.num_basis; // sign(alpha) is store at quadrature points + gkyl_cart_modal_tensor(&surf_quad_basis, app->cdim - 1, app->poly_order); + int alpha_surf_sz = app->cdim * surf_basis.num_basis; + int sgn_alpha_surf_sz = + app->cdim * surf_quad_basis.num_basis; // sign(alpha) is store at quadrature points - // allocate arrays to store fields: + // allocate arrays to store fields: // 1. alpha_surf (surface configuration space velocity) // 2. sgn_alpha_surf (sign(alpha_surf) at quadrature points) // 3. const_sgn_alpha (boolean for if sign(alpha_surf) is a constant, either +1 or -1) @@ -562,16 +556,22 @@ vm_fluid_species_can_pb_fluid_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *a f->sgn_alpha_surf = mkarr(app->use_gpu, sgn_alpha_surf_sz, app->local_ext.volume); f->const_sgn_alpha = mk_int_arr(app->use_gpu, app->cdim, app->local_ext.volume); - // Initialize alpha_surf calculator and source functions for different canonical PB fluids. + // Initialize alpha_surf calculator and source functions for different canonical PB fluids. // NOTE: If solving the modified Hasegawa-Wakatani system which subtracts the zonal components - // of n and phi, the simulation *must not* have any decomposition in y. - f->calc_can_pb_fluid_vars = gkyl_dg_calc_canonical_pb_fluid_vars_new(&app->grid, - &app->confBasis, &app->local, &app->local_ext, f->equation, app->use_gpu); + // of n and phi, the simulation *must not* have any decomposition in y. + f->calc_can_pb_fluid_vars = gkyl_dg_calc_canonical_pb_fluid_vars_new( + &app->grid, &app->confBasis, &app->local, &app->local_ext, f->equation, app->use_gpu + ); - struct gkyl_dg_canonical_pb_fluid_auxfields aux_inp = {.phi = f->phi, .alpha_surf = f->alpha_surf, - .sgn_alpha_surf = f->sgn_alpha_surf, .const_sgn_alpha = f->const_sgn_alpha}; - f->advect_slvr = gkyl_dg_updater_fluid_new(&app->grid, &app->confBasis, - &app->local, f->equation, app->geom, &aux_inp, app->use_gpu); + struct gkyl_dg_canonical_pb_fluid_auxfields aux_inp = { + .phi = f->phi, + .alpha_surf = f->alpha_surf, + .sgn_alpha_surf = f->sgn_alpha_surf, + .const_sgn_alpha = f->const_sgn_alpha + }; + f->advect_slvr = gkyl_dg_updater_fluid_new( + &app->grid, &app->confBasis, &app->local, f->equation, app->geom, &aux_inp, app->use_gpu + ); // Canonical Poisson bracket for fluid equations integrated quantities: f, f^2, E // where E is the integrated energy = integral(phi*f) since f = grad^2 phi -> E = integral(|grad phi|^2) @@ -581,30 +581,34 @@ vm_fluid_species_can_pb_fluid_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *a f->red_integ_diag = gkyl_cu_malloc(sizeof(double[1])); f->red_can_pb_energy = gkyl_cu_malloc(sizeof(double[1])); f->red_can_pb_energy_global = gkyl_cu_malloc(sizeof(double[1])); - } - else { + } else { f->red_can_pb_energy = gkyl_malloc(sizeof(double[1])); f->red_can_pb_energy_global = gkyl_malloc(sizeof(double[1])); } // allocate dynamic-vector to store all-reduced integrated quantities f->integ_diag = gkyl_dynvec_new(GKYL_DOUBLE, 3); - f->is_first_integ_write_call = true; + f->is_first_integ_write_call = true; // Specialized updater for integrating |grad phi|^2 f->can_pb_energy_fac = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - gkyl_array_shiftc(f->can_pb_energy_fac, pow(sqrt(2.0),app->cdim), 0); // Sets can_pb_energy_fac = 1. - f->calc_can_pb_energy = gkyl_array_integrate_new(&app->grid, &app->confBasis, - 1, GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ, app->use_gpu); - - f->prim_vars_func = vm_fluid_species_can_pb_fluid_prim_vars; - f->calc_integrated_mom_func = vm_fluid_species_can_pb_fluid_calc_integrated; - f->write_func = vm_fluid_species_can_pb_fluid_write; - f->release_func = vm_fluid_species_can_pb_fluid_release; + gkyl_array_shiftc( + f->can_pb_energy_fac, pow(sqrt(2.0), app->cdim), + 0 + ); // Sets can_pb_energy_fac = 1. + f->calc_can_pb_energy = gkyl_array_integrate_new( + &app->grid, &app->confBasis, 1, GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ, app->use_gpu + ); + + f->prim_vars_func = vm_fluid_species_can_pb_fluid_prim_vars; + f->calc_integrated_mom_func = vm_fluid_species_can_pb_fluid_calc_integrated; + f->write_func = vm_fluid_species_can_pb_fluid_write; + f->release_func = vm_fluid_species_can_pb_fluid_release; } // initialize fluid species object -void -vm_fluid_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_fluid_species *f) +void vm_fluid_species_init( + struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_fluid_species *f +) { int cdim = app->cdim; // Setup equation-specific memory and equation type/number of equations based on input table @@ -613,38 +617,40 @@ vm_fluid_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm f->equation = gkyl_wv_eqn_acquire(f->info.equation); if (f->eqn_type == GKYL_EQN_ADVECTION) { vm_fluid_species_advect_init(vm, app, f); - } - else if (f->eqn_type == GKYL_EQN_EULER || f->eqn_type == GKYL_EQN_ISO_EULER) { + } else if (f->eqn_type == GKYL_EQN_EULER || f->eqn_type == GKYL_EQN_ISO_EULER) { vm_fluid_species_euler_init(vm, app, f); - } - else { + } else { // Equation type is a Canonical Poisson Bracket (PB) fluid such as - // incompressible Euler, Hasegawa-Mima, or Hasegawa-Wakatani. + // incompressible Euler, Hasegawa-Mima, or Hasegawa-Wakatani. vm_fluid_species_can_pb_fluid_init(vm, app, f); } // allocate fluid arrays - f->fluid = mkarr(app->use_gpu, f->num_equations*app->confBasis.num_basis, app->local_ext.volume); - f->fluid1 = mkarr(app->use_gpu, f->num_equations*app->confBasis.num_basis, app->local_ext.volume); - f->fluidnew = mkarr(app->use_gpu, f->num_equations*app->confBasis.num_basis, app->local_ext.volume); + f->fluid = + mkarr(app->use_gpu, f->num_equations * app->confBasis.num_basis, app->local_ext.volume); + f->fluid1 = + mkarr(app->use_gpu, f->num_equations * app->confBasis.num_basis, app->local_ext.volume); + f->fluidnew = + mkarr(app->use_gpu, f->num_equations * app->confBasis.num_basis, app->local_ext.volume); f->fluid_host = f->fluid; if (app->use_gpu) { - f->fluid_host = mkarr(false, f->num_equations*app->confBasis.num_basis, app->local_ext.volume); + f->fluid_host = + mkarr(false, f->num_equations * app->confBasis.num_basis, app->local_ext.volume); } // Duplicate copy of fluid data in case time step fails. - // Needed because of implicit source split which modifies solution and - // is always successful, so if a time step fails due to the SSP RK3 + // Needed because of implicit source split which modifies solution and + // is always successful, so if a time step fails due to the SSP RK3 // we must restore the old solution before restarting the time step - f->fluid_dup = mkarr(app->use_gpu, f->num_equations*app->confBasis.num_basis, app->local_ext.volume); + f->fluid_dup = + mkarr(app->use_gpu, f->num_equations * app->confBasis.num_basis, app->local_ext.volume); // allocate cflrate (scalar array) f->cflrate = mkarr(app->use_gpu, 1, app->local_ext.volume); if (app->use_gpu) { f->omegaCfl_ptr = gkyl_cu_malloc(sizeof(double)); - } - else { + } else { f->omegaCfl_ptr = gkyl_malloc(sizeof(double)); } @@ -654,62 +660,65 @@ vm_fluid_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm f->diffD = NULL; if (f->info.diffusion.Dij) { f->has_diffusion = true; - // allocate space for full diffusion tensor - int szD = cdim*(cdim+1)/2; + // allocate space for full diffusion tensor + int szD = cdim * (cdim + 1) / 2; - f->diffD = mkarr(app->use_gpu, szD*app->confBasis.num_basis, app->local_ext.volume); + f->diffD = mkarr(app->use_gpu, szD * app->confBasis.num_basis, app->local_ext.volume); struct gkyl_array *diffD_host = f->diffD; - if (app->use_gpu) - diffD_host = mkarr(false, szD*app->confBasis.num_basis, app->local_ext.volume); - - gkyl_proj_on_basis *diff_proj = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &app->grid, - .basis = &app->confBasis, - .qtype = GKYL_GAUSS_LOBATTO_QUAD, - .num_quad = 8, - .num_ret_vals = szD, - .eval = f->info.diffusion.Dij, - .ctx = f->info.diffusion.Dij_ctx - } - ); + if (app->use_gpu) { + diffD_host = mkarr(false, szD * app->confBasis.num_basis, app->local_ext.volume); + } + + gkyl_proj_on_basis *diff_proj = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &app->grid, + .basis = &app->confBasis, + .qtype = GKYL_GAUSS_LOBATTO_QUAD, + .num_quad = 8, + .num_ret_vals = szD, + .eval = f->info.diffusion.Dij, + .ctx = f->info.diffusion.Dij_ctx}); gkyl_proj_on_basis_advance(diff_proj, 0.0, &app->local_ext, diffD_host); - if (app->use_gpu) {// note: diffD_host is same as diffD when not on GPUs + if (app->use_gpu) { // note: diffD_host is same as diffD when not on GPUs gkyl_array_copy(f->diffD, diffD_host); gkyl_array_release(diffD_host); } // Free projection object gkyl_proj_on_basis_release(diff_proj); - f->diff_slvr_gen = gkyl_dg_updater_diffusion_gen_new(&app->grid, &app->confBasis, - &app->local, app->use_gpu); - } - else if (f->info.diffusion.D) { + f->diff_slvr_gen = + gkyl_dg_updater_diffusion_gen_new(&app->grid, &app->confBasis, &app->local, app->use_gpu); + } else if (f->info.diffusion.D) { f->has_diffusion = true; - f->info.diffusion.order = f->info.diffusion.order<2? 2 : f->info.diffusion.order; + f->info.diffusion.order = f->info.diffusion.order < 2 ? 2 : f->info.diffusion.order; int szD = cdim; f->diffD = mkarr(app->use_gpu, szD, 1); struct gkyl_array *diffD_host = f->diffD; - if (app->use_gpu) + if (app->use_gpu) { diffD_host = mkarr(false, szD, 1); + } // Set diffusion coefficient in each direction to input value. gkyl_array_clear(diffD_host, 0.); - for (int d=0; dinfo.diffusion.D, d); + for (int d = 0; d < cdim; d++) { + gkyl_array_shiftc(diffD_host, f->info.diffusion.D, d); + } - if (app->use_gpu) {// note: diffD_host is same as diffD when not on GPUs + if (app->use_gpu) { // note: diffD_host is same as diffD when not on GPUs gkyl_array_copy(f->diffD, diffD_host); gkyl_array_release(diffD_host); } const bool is_zero_flux[GKYL_MAX_CDIM] = {false}; - f->diff_slvr = gkyl_dg_updater_diffusion_fluid_new(&app->grid, &app->confBasis, - true, f->num_equations, NULL, f->info.diffusion.order, &app->local, is_zero_flux, app->use_gpu); + f->diff_slvr = gkyl_dg_updater_diffusion_fluid_new( + &app->grid, &app->confBasis, true, f->num_equations, NULL, f->info.diffusion.order, + &app->local, is_zero_flux, app->use_gpu + ); } - // Initialize applied acceleration for use in force update. + // Initialize applied acceleration for use in force update. // Always used by fluid implicit sources, so always initialize. - f->app_accel = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); + f->app_accel = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); gkyl_array_clear(f->app_accel, 0.0); f->has_app_accel = false; f->app_accel_evolve = false; @@ -722,10 +731,12 @@ vm_fluid_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm f->app_accel_host = f->app_accel; if (app->use_gpu) { - f->app_accel_host = mkarr(false, 3*app->confBasis.num_basis, app->local_ext.volume); + f->app_accel_host = mkarr(false, 3 * app->confBasis.num_basis, app->local_ext.volume); } - f->app_accel_proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, app->confBasis.poly_order+1, - 3, f->info.app_accel, f->info.app_accel_ctx); + f->app_accel_proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->confBasis.poly_order + 1, 3, f->info.app_accel, + f->info.app_accel_ctx + ); } // set species source id @@ -733,84 +744,87 @@ vm_fluid_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm // determine which directions are not periodic int num_periodic_dir = app->num_periodic_dir, is_np[3] = {1, 1, 1}; - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int dir=0; dircdim; ++dir) { + for (int dir = 0; dir < app->cdim; ++dir) { f->lower_bc[dir] = f->upper_bc[dir] = GKYL_SPECIES_COPY; if (is_np[dir]) { const enum gkyl_species_bc_type *bc; - if (dir == 0) + if (dir == 0) { bc = f->info.bcx; - else if (dir == 1) + } else if (dir == 1) { bc = f->info.bcy; - else + } else { bc = f->info.bcz; + } f->lower_bc[dir] = bc[0]; f->upper_bc[dir] = bc[1]; } } - // allocate buffer for applying BCs + // allocate buffer for applying BCs long buff_sz = 0; // compute buffer size needed - for (int dir=0; dircdim; ++dir) { + for (int dir = 0; dir < app->cdim; ++dir) { long vol = GKYL_MAX2(app->lower_skin[dir].volume, app->upper_skin[dir].volume); buff_sz = buff_sz > vol ? buff_sz : vol; } - f->bc_buffer = mkarr(app->use_gpu, f->num_equations*app->confBasis.num_basis, buff_sz); + f->bc_buffer = mkarr(app->use_gpu, f->num_equations * app->confBasis.num_basis, buff_sz); - // Certain operations fail if absorbing BCs used because absorbing BCs + // Certain operations fail if absorbing BCs used because absorbing BCs // means the mass density is 0 in the ghost cells (divide by zero) f->bc_is_absorb = false; - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { // Lower BC updater. Copy BCs by default. enum gkyl_bc_basic_type bctype = GKYL_BC_COPY; if (f->lower_bc[d] == GKYL_SPECIES_COPY) { bctype = GKYL_BC_COPY; - } - else if (f->lower_bc[d] == GKYL_SPECIES_ABSORB) { + } else if (f->lower_bc[d] == GKYL_SPECIES_ABSORB) { bctype = GKYL_BC_ABSORB; f->bc_is_absorb = true; - } - else if (f->lower_bc[d] == GKYL_SPECIES_REFLECT) { + } else if (f->lower_bc[d] == GKYL_SPECIES_REFLECT) { bctype = GKYL_BC_EULER_REFLECT; - } - else if (f->lower_bc[d] == GKYL_SPECIES_NO_SLIP) { + } else if (f->lower_bc[d] == GKYL_SPECIES_NO_SLIP) { bctype = GKYL_BC_EULER_NO_SLIP; } - f->bc_lo[d] = gkyl_bc_basic_new(d, GKYL_LOWER_EDGE, bctype, app->basis_on_dev.confBasis, - &app->lower_skin[d], &app->lower_ghost[d], f->fluid->ncomp, app->cdim, app->use_gpu); + f->bc_lo[d] = gkyl_bc_basic_new( + d, GKYL_LOWER_EDGE, bctype, app->basis_on_dev.confBasis, &app->lower_skin[d], + &app->lower_ghost[d], f->fluid->ncomp, app->cdim, app->use_gpu + ); // Upper BC updater. Copy BCs by default. if (f->upper_bc[d] == GKYL_SPECIES_COPY) { bctype = GKYL_BC_COPY; - } - else if (f->upper_bc[d] == GKYL_SPECIES_ABSORB) { + } else if (f->upper_bc[d] == GKYL_SPECIES_ABSORB) { bctype = GKYL_BC_ABSORB; f->bc_is_absorb = true; - } - else if (f->upper_bc[d] == GKYL_SPECIES_REFLECT) { + } else if (f->upper_bc[d] == GKYL_SPECIES_REFLECT) { bctype = GKYL_BC_EULER_REFLECT; - } - else if (f->upper_bc[d] == GKYL_SPECIES_NO_SLIP) { + } else if (f->upper_bc[d] == GKYL_SPECIES_NO_SLIP) { bctype = GKYL_BC_EULER_NO_SLIP; } - f->bc_up[d] = gkyl_bc_basic_new(d, GKYL_UPPER_EDGE, bctype, app->basis_on_dev.confBasis, - &app->upper_skin[d], &app->upper_ghost[d], f->fluid->ncomp, app->cdim, app->use_gpu); + f->bc_up[d] = gkyl_bc_basic_new( + d, GKYL_UPPER_EDGE, bctype, app->basis_on_dev.confBasis, &app->upper_skin[d], + &app->upper_ghost[d], f->fluid->ncomp, app->cdim, app->use_gpu + ); } } -void -vm_fluid_species_apply_ic(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double t0) +void vm_fluid_species_apply_ic( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double t0 +) { int poly_order = app->poly_order; - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - poly_order+1, fluid_species->num_equations, fluid_species->info.init, fluid_species->info.ctx); + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, poly_order + 1, fluid_species->num_equations, + fluid_species->info.init, fluid_species->info.ctx + ); // run updater gkyl_proj_on_basis_advance(proj, t0, &app->local_ext, fluid_species->fluid_host); @@ -829,11 +843,14 @@ vm_fluid_species_apply_ic(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_s vm_fluid_species_source_calc(app, fluid_species, t0); } -void -vm_fluid_species_calc_app_accel(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm) +void vm_fluid_species_calc_app_accel( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm +) { if (fluid_species->has_app_accel) { - gkyl_proj_on_basis_advance(fluid_species->app_accel_proj, tm, &app->local_ext, fluid_species->app_accel_host); + gkyl_proj_on_basis_advance( + fluid_species->app_accel_proj, tm, &app->local_ext, fluid_species->app_accel_host + ); // note: app_accel_host is same as app_accel when not on GPUs if (app->use_gpu) { gkyl_array_copy(fluid_species->app_accel, fluid_species->app_accel_host); @@ -841,18 +858,18 @@ vm_fluid_species_calc_app_accel(gkyl_vlasov_app *app, struct vm_fluid_species *f } } -void -vm_fluid_species_prim_vars(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, - const struct gkyl_array *fluid) +void vm_fluid_species_prim_vars( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, const struct gkyl_array *fluid +) { fluid_species->prim_vars_func(app, fluid_species, fluid); } -void -vm_fluid_species_limiter(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, - struct gkyl_array *fluid) +void vm_fluid_species_limiter( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, struct gkyl_array *fluid +) { - if (fluid_species->eqn_type == GKYL_EQN_EULER || fluid_species->eqn_type == GKYL_EQN_ISO_EULER) { + if (fluid_species->eqn_type == GKYL_EQN_EULER || fluid_species->eqn_type == GKYL_EQN_ISO_EULER) { struct timespec tm = gkyl_wall_clock(); // Limit the slopes of the solution @@ -867,118 +884,130 @@ vm_fluid_species_limiter(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_sp // Compute the RHS for fluid species update, returning maximum stable // time-step. -double -vm_fluid_species_rhs(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, - const struct gkyl_array *fluid, const struct gkyl_array *em, struct gkyl_array *rhs) +double vm_fluid_species_rhs( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, const struct gkyl_array *fluid, + const struct gkyl_array *em, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - double omegaCfl = 1/DBL_MAX; + double omegaCfl = 1 / DBL_MAX; gkyl_array_clear(fluid_species->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); - // If we are solving a Poisson equation, need to compute + // If we are solving a Poisson equation, need to compute // surface characteristics from potential and source update. if (fluid_species->has_poisson) { struct timespec tm = gkyl_wall_clock(); - // Compute the surface characteristics from the potential. - gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf(fluid_species->calc_can_pb_fluid_vars, - &app->local, &app->local_ext, fluid_species->phi, - fluid_species->alpha_surf, fluid_species->sgn_alpha_surf, fluid_species->const_sgn_alpha); + // Compute the surface characteristics from the potential. + gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf( + fluid_species->calc_can_pb_fluid_vars, &app->local, &app->local_ext, fluid_species->phi, + fluid_species->alpha_surf, fluid_species->sgn_alpha_surf, fluid_species->const_sgn_alpha + ); - // Increment the source contribution for certain canonical PB fluids onto the RHS. - gkyl_canonical_pb_fluid_vars_source(fluid_species->calc_can_pb_fluid_vars, - &app->local, fluid_species->phi, fluid_species->can_pb_n0, fluid, rhs); + // Increment the source contribution for certain canonical PB fluids onto the RHS. + gkyl_canonical_pb_fluid_vars_source( + fluid_species->calc_can_pb_fluid_vars, &app->local, fluid_species->phi, + fluid_species->can_pb_n0, fluid, rhs + ); - app->stat.fluid_species_vars_tm += gkyl_time_diff_now_sec(tm); + app->stat.fluid_species_vars_tm += gkyl_time_diff_now_sec(tm); } - gkyl_dg_updater_fluid_advance(fluid_species->advect_slvr, - &app->local, fluid, fluid_species->cflrate, rhs); + gkyl_dg_updater_fluid_advance( + fluid_species->advect_slvr, &app->local, fluid, fluid_species->cflrate, rhs + ); // Accumulate explicit source contribution, e.g., external forces // Only done if there are external forces and no EM fields, as fluid-EM coupling - // is handled by implicit source solve, see vm_fluid_em_coupling.c. + // is handled by implicit source solve, see vm_fluid_em_coupling.c. if (fluid_species->has_app_accel && !app->has_field) { - gkyl_dg_calc_fluid_vars_source(fluid_species->calc_fluid_vars, &app->local, - fluid_species->app_accel, fluid, rhs); + gkyl_dg_calc_fluid_vars_source( + fluid_species->calc_fluid_vars, &app->local, fluid_species->app_accel, fluid, rhs + ); } if (fluid_species->has_diffusion) { if (fluid_species->info.diffusion.Dij) { - gkyl_dg_updater_diffusion_gen_advance(fluid_species->diff_slvr_gen, - &app->local, fluid_species->diffD, fluid, fluid_species->cflrate, rhs); - } - else if (fluid_species->info.diffusion.D) { - gkyl_dg_updater_diffusion_fluid_advance(fluid_species->diff_slvr, - &app->local, fluid_species->diffD, fluid, fluid_species->cflrate, rhs); + gkyl_dg_updater_diffusion_gen_advance( + fluid_species->diff_slvr_gen, &app->local, fluid_species->diffD, fluid, + fluid_species->cflrate, rhs + ); + } else if (fluid_species->info.diffusion.D) { + gkyl_dg_updater_diffusion_fluid_advance( + fluid_species->diff_slvr, &app->local, fluid_species->diffD, fluid, fluid_species->cflrate, + rhs + ); } } - gkyl_array_reduce_range(fluid_species->omegaCfl_ptr, fluid_species->cflrate, GKYL_MAX, &app->local); + gkyl_array_reduce_range( + fluid_species->omegaCfl_ptr, fluid_species->cflrate, GKYL_MAX, &app->local + ); double omegaCfl_ho[1]; if (app->use_gpu) { gkyl_cu_memcpy(omegaCfl_ho, fluid_species->omegaCfl_ptr, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { omegaCfl_ho[0] = fluid_species->omegaCfl_ptr[0]; } omegaCfl = omegaCfl_ho[0]; app->stat.fluid_species_rhs_tm += gkyl_time_diff_now_sec(wst); - return app->cfl/omegaCfl; + return app->cfl / omegaCfl; } // Determine which directions are periodic and which directions are not periodic, // and then apply boundary conditions for fluid species -void -vm_fluid_species_apply_bc(gkyl_vlasov_app *app, const struct vm_fluid_species *fluid_species, struct gkyl_array *f) +void vm_fluid_species_apply_bc( + gkyl_vlasov_app *app, const struct vm_fluid_species *fluid_species, struct gkyl_array *f +) { - struct timespec wst = gkyl_wall_clock(); - + struct timespec wst = gkyl_wall_clock(); + int num_periodic_dir = app->num_periodic_dir, cdim = app->cdim; - gkyl_comm_array_per_sync(app->comm, &app->local, &app->local_ext, - num_periodic_dir, app->periodic_dirs, f); - + gkyl_comm_array_per_sync( + app->comm, &app->local, &app->local_ext, num_periodic_dir, app->periodic_dirs, f + ); + int is_np_bc[3] = {1, 1, 1}; // flags to indicate if direction is periodic - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int d=0; dlower_bc[d]) { - case GKYL_SPECIES_COPY: - case GKYL_SPECIES_ABSORB: - case GKYL_SPECIES_REFLECT: - case GKYL_SPECIES_NO_SLIP: - gkyl_bc_basic_advance(fluid_species->bc_lo[d], fluid_species->bc_buffer, f); - break; - case GKYL_SPECIES_WEDGE: - case GKYL_SPECIES_FIXED_FUNC: - assert(false); - break; - default: - break; + case GKYL_SPECIES_COPY: + case GKYL_SPECIES_ABSORB: + case GKYL_SPECIES_REFLECT: + case GKYL_SPECIES_NO_SLIP: + gkyl_bc_basic_advance(fluid_species->bc_lo[d], fluid_species->bc_buffer, f); + break; + case GKYL_SPECIES_WEDGE: + case GKYL_SPECIES_FIXED_FUNC: + assert(false); + break; + default: + break; } switch (fluid_species->upper_bc[d]) { - case GKYL_SPECIES_COPY: - case GKYL_SPECIES_ABSORB: - case GKYL_SPECIES_REFLECT: - case GKYL_SPECIES_NO_SLIP: - gkyl_bc_basic_advance(fluid_species->bc_up[d], fluid_species->bc_buffer, f); - break; - case GKYL_SPECIES_WEDGE: - case GKYL_SPECIES_FIXED_FUNC: - assert(false); - break; - default: - break; + case GKYL_SPECIES_COPY: + case GKYL_SPECIES_ABSORB: + case GKYL_SPECIES_REFLECT: + case GKYL_SPECIES_NO_SLIP: + gkyl_bc_basic_advance(fluid_species->bc_up[d], fluid_species->bc_buffer, f); + break; + case GKYL_SPECIES_WEDGE: + case GKYL_SPECIES_FIXED_FUNC: + assert(false); + break; + default: + break; } } } @@ -989,29 +1018,28 @@ vm_fluid_species_apply_bc(gkyl_vlasov_app *app, const struct vm_fluid_species *f } // Integrated quantities calculator for different fluid equations. -void -vm_fluid_species_calc_integrated_mom(gkyl_vlasov_app* app, struct vm_fluid_species *f, double tm) +void vm_fluid_species_calc_integrated_mom( + gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm +) { - f->calc_integrated_mom_func(app, f, tm); + f->calc_integrated_mom_func(app, f, tm); } -// Write method for different fluid equations. -void -vm_fluid_species_write(gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm, int frame) +// Write method for different fluid equations. +void vm_fluid_species_write(gkyl_vlasov_app *app, struct vm_fluid_species *f, double tm, int frame) { f->write_func(app, f, tm, frame); } // Release resources for fluid species. -void -vm_fluid_species_release(const gkyl_vlasov_app* app, struct vm_fluid_species *f) +void vm_fluid_species_release(const gkyl_vlasov_app *app, struct vm_fluid_species *f) { - // Release acquired equation object pointer - // along with other equation specific data. - gkyl_wv_eqn_release(f->equation); - f->release_func(app, f); + // Release acquired equation object pointer + // along with other equation specific data. + gkyl_wv_eqn_release(f->equation); + f->release_func(app, f); - // Release solver and fluid arrays for update. + // Release solver and fluid arrays for update. gkyl_dg_updater_fluid_release(f->advect_slvr); gkyl_array_release(f->fluid); gkyl_array_release(f->fluid1); @@ -1024,8 +1052,7 @@ vm_fluid_species_release(const gkyl_vlasov_app* app, struct vm_fluid_species *f) gkyl_array_release(f->diffD); if (f->info.diffusion.Dij) { gkyl_dg_updater_diffusion_gen_release(f->diff_slvr_gen); - } - else if (f->info.diffusion.D) { + } else if (f->info.diffusion.D) { gkyl_dg_updater_diffusion_fluid_release(f->diff_slvr); } } @@ -1049,12 +1076,11 @@ vm_fluid_species_release(const gkyl_vlasov_app* app, struct vm_fluid_species *f) gkyl_array_release(f->fluid_host); gkyl_cu_free(f->omegaCfl_ptr); gkyl_cu_free(f->red_integ_diag); - } - else { + } else { gkyl_free(f->omegaCfl_ptr); } // Copy BCs are allocated by default. Need to free. - for (int d=0; dcdim; ++d) { + for (int d = 0; d < app->cdim; ++d) { gkyl_bc_basic_release(f->bc_lo[d]); gkyl_bc_basic_release(f->bc_up[d]); } diff --git a/vlasov/apps/vm_fluid_species_source.c b/vlasov/apps/vm_fluid_species_source.c index 690248460d..f997b6bb24 100644 --- a/vlasov/apps/vm_fluid_species_source.c +++ b/vlasov/apps/vm_fluid_species_source.c @@ -1,51 +1,57 @@ #include #include -void -vm_fluid_species_source_init(struct gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, struct vm_fluid_source *src) +void vm_fluid_species_source_init( + struct gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, struct vm_fluid_source *src +) { // we need to ensure source has same shape as distribution function src->source = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - + src->source_host = src->source; - if (app->use_gpu) + if (app->use_gpu) { src->source_host = mkarr(false, app->confBasis.num_basis, app->local_ext.volume); + } - src->source_proj = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &app->grid, - .basis = &app->confBasis, - .qtype = GKYL_GAUSS_QUAD, - .num_quad = app->basis.poly_order+1, - .num_ret_vals = 1, - .eval = fluid_species->info.source.profile, - .ctx = fluid_species->info.source.ctx - } - ); + src->source_proj = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &app->grid, + .basis = &app->confBasis, + .qtype = GKYL_GAUSS_QUAD, + .num_quad = app->basis.poly_order + 1, + .num_ret_vals = 1, + .eval = fluid_species->info.source.profile, + .ctx = fluid_species->info.source.ctx}); } -void -vm_fluid_species_source_calc(gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm) +void vm_fluid_species_source_calc( + gkyl_vlasov_app *app, struct vm_fluid_species *fluid_species, double tm +) { if (fluid_species->source_id) { - gkyl_proj_on_basis_advance(fluid_species->src.source_proj, tm, &app->local_ext, fluid_species->src.source_host); - if (app->use_gpu) // note: source_host is same as source when not on GPUs + gkyl_proj_on_basis_advance( + fluid_species->src.source_proj, tm, &app->local_ext, fluid_species->src.source_host + ); + if (app->use_gpu) { // note: source_host is same as source when not on GPUs gkyl_array_copy(fluid_species->src.source, fluid_species->src.source_host); + } } } // computes rhs of the boundary flux -void -vm_fluid_species_source_rhs(gkyl_vlasov_app *app, const struct vm_fluid_species *species, - struct vm_fluid_source *src, const struct gkyl_array *fluid[], struct gkyl_array *rhs[]) +void vm_fluid_species_source_rhs( + gkyl_vlasov_app *app, const struct vm_fluid_species *species, struct vm_fluid_source *src, + const struct gkyl_array *fluid[], struct gkyl_array *rhs[] +) { int species_idx; species_idx = vm_find_fluid_species_idx(app, species->info.name); - + gkyl_array_accumulate(rhs[species_idx], 1.0, src->source); } -void -vm_fluid_species_source_release(const struct gkyl_vlasov_app *app, const struct vm_fluid_source *src) +void vm_fluid_species_source_release( + const struct gkyl_vlasov_app *app, const struct vm_fluid_source *src +) { gkyl_array_release(src->source); if (app->use_gpu) { diff --git a/vlasov/apps/vm_species.c b/vlasov/apps/vm_species.c index 0d85dfaac6..eca5a70156 100644 --- a/vlasov/apps/vm_species.c +++ b/vlasov/apps/vm_species.c @@ -13,11 +13,10 @@ #include // initialize species object -void -vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_species *s) +void vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_species *s) { int cdim = app->cdim, vdim = app->vdim; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int cells[GKYL_MAX_DIM], ghost[GKYL_MAX_DIM]; double lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; @@ -25,18 +24,18 @@ vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_speci int cells_vel[GKYL_MAX_DIM], ghost_vel[GKYL_MAX_DIM]; double lower_vel[GKYL_MAX_DIM], upper_vel[GKYL_MAX_DIM]; - for (int d=0; dcells[d]; lower[d] = vm->lower[d]; upper[d] = vm->upper[d]; ghost[d] = 1; } - for (int d=0; dinfo.cells[d]; - lower[cdim+d] = s->info.lower[d]; - upper[cdim+d] = s->info.upper[d]; - ghost[cdim+d] = 0; // no ghost-cells in velocity space + cells[cdim + d] = s->info.cells[d]; + lower[cdim + d] = s->info.lower[d]; + upper[cdim + d] = s->info.upper[d]; + ghost[cdim + d] = 0; // no ghost-cells in velocity space // only velocity space cells_vel[d] = s->info.cells[d]; @@ -47,7 +46,7 @@ vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_speci // full phase space grid gkyl_rect_grid_init(&s->grid, pdim, lower, upper, cells); gkyl_create_grid_ranges(&s->grid, ghost, &s->global_ext, &s->global); - + // velocity space grid gkyl_rect_grid_init(&s->grid_vel, vdim, lower_vel, upper_vel, cells_vel); gkyl_create_grid_ranges(&s->grid_vel, ghost_vel, &s->local_ext_vel, &s->local_vel); @@ -70,42 +69,46 @@ vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_speci s->fnew = mkarr(app->use_gpu, app->basis.num_basis, s->local_ext.volume); s->f_host = s->f; - if (app->use_gpu) + if (app->use_gpu) { s->f_host = mkarr(false, app->basis.num_basis, s->local_ext.volume); + } // allocate cflrate (scalar array) s->cflrate = mkarr(app->use_gpu, 1, s->local_ext.volume); - if (app->use_gpu) + if (app->use_gpu) { s->omegaCfl_ptr = gkyl_cu_malloc(sizeof(double)); - else + } else { s->omegaCfl_ptr = gkyl_malloc(sizeof(double)); + } // allocate array to store q/m*(E,B) or potentials (phi, A) depending on equation system - s->qbym = s->info.charge/s->info.mass; - if (s->field_id == GKYL_FIELD_E_B) - s->qmem = mkarr(app->use_gpu, 8*app->confBasis.num_basis, app->local_ext.volume); - else if (s->field_id != GKYL_FIELD_NULL) { - s->qmem = mkarr(app->use_gpu, 4*app->confBasis.num_basis, app->local_ext.volume); - s->qmem_ext = mkarr(app->use_gpu, 6*app->confBasis.num_basis, app->local_ext.volume); + s->qbym = s->info.charge / s->info.mass; + if (s->field_id == GKYL_FIELD_E_B) { + s->qmem = mkarr(app->use_gpu, 8 * app->confBasis.num_basis, app->local_ext.volume); + } else if (s->field_id != GKYL_FIELD_NULL) { + s->qmem = mkarr(app->use_gpu, 4 * app->confBasis.num_basis, app->local_ext.volume); + s->qmem_ext = mkarr(app->use_gpu, 6 * app->confBasis.num_basis, app->local_ext.volume); } // Determine which directions are not periodic. int num_periodic_dir = app->num_periodic_dir, is_np[3] = {1, 1, 1}; - for (int d=0; dperiodic_dirs[d]] = 0; + } - bool is_zero_flux[2*GKYL_MAX_DIM] = {false}; // Default: no zero-flux BCs in any direction. - for (int dir=0; dircdim; ++dir) { + bool is_zero_flux[2 * GKYL_MAX_DIM] = {false}; // Default: no zero-flux BCs in any direction. + for (int dir = 0; dir < app->cdim; ++dir) { s->lower_bc[dir].type = s->upper_bc[dir].type = GKYL_SPECIES_COPY; if (is_np[dir]) { const struct gkyl_vlasov_bcs *bc; - if (dir == 0) + if (dir == 0) { bc = &s->info.bcx; - else if (dir == 1) + } else if (dir == 1) { bc = &s->info.bcy; - else + } else { bc = &s->info.bcz; + } s->lower_bc[dir] = bc->lower; s->upper_bc[dir] = bc->upper; @@ -113,12 +116,12 @@ vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_speci is_zero_flux[dir] = true; } if (s->upper_bc[dir].type == GKYL_SPECIES_ZERO_FLUX) { - is_zero_flux[dir+pdim] = true; + is_zero_flux[dir + pdim] = true; } } } - if (s->model_id == GKYL_MODEL_SR) { + if (s->model_id == GKYL_MODEL_SR) { // Allocate special relativistic variables gamma and its inverse s->gamma = mkarr(app->use_gpu, app->velBasis.num_basis, s->local_vel.volume); s->gamma_host = s->gamma; @@ -129,95 +132,108 @@ vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_speci s->gamma_host = mkarr(false, app->velBasis.num_basis, s->local_vel.volume); s->gamma_inv_host = mkarr(false, app->velBasis.num_basis, s->local_vel.volume); } - s->sr_vars = gkyl_dg_calc_sr_vars_new(&s->grid, &s->grid_vel, - &app->confBasis, &app->velBasis, &app->local, &s->local_vel, app->use_gpu); + s->sr_vars = gkyl_dg_calc_sr_vars_new( + &s->grid, &s->grid_vel, &app->confBasis, &app->velBasis, &app->local, &s->local_vel, + app->use_gpu + ); // Project gamma and its inverse gkyl_calc_sr_vars_init_p_vars(s->sr_vars, s->gamma, s->gamma_inv); struct gkyl_dg_vlasov_sr_auxfields aux_inp = {.qmem = s->qmem, .gamma = s->gamma}; // create solver - s->slvr = gkyl_dg_updater_vlasov_new(&s->grid, &app->confBasis, &app->basis, - &app->local, &s->local_vel, &s->local, is_zero_flux, s->model_id, s->field_id, &aux_inp, app->use_gpu); - } - else if (s->model_id == GKYL_MODEL_CANONICAL_PB || s->model_id == GKYL_MODEL_CANONICAL_PB_GR) { + s->slvr = gkyl_dg_updater_vlasov_new( + &s->grid, &app->confBasis, &app->basis, &app->local, &s->local_vel, &s->local, is_zero_flux, + s->model_id, s->field_id, &aux_inp, app->use_gpu + ); + } else if (s->model_id == GKYL_MODEL_CANONICAL_PB || s->model_id == GKYL_MODEL_CANONICAL_PB_GR) { // Allocate arrays for specified hamiltonian s->hamil = mkarr(app->use_gpu, app->basis.num_basis, s->local_ext.volume); s->hamil_host = s->hamil; - if (app->use_gpu){ + if (app->use_gpu) { s->hamil_host = mkarr(false, app->basis.num_basis, s->local_ext.volume); } // Allocate arrays for specified metric inverse - s->h_ij = mkarr(app->use_gpu, app->confBasis.num_basis*vdim*(vdim+1)/2, app->local_ext.volume); + s->h_ij = + mkarr(app->use_gpu, app->confBasis.num_basis * vdim * (vdim + 1) / 2, app->local_ext.volume); s->h_ij_host = s->h_ij; - if (app->use_gpu){ - s->h_ij_host = mkarr(false, app->confBasis.num_basis*vdim*(vdim+1)/2, app->local_ext.volume); + if (app->use_gpu) { + s->h_ij_host = + mkarr(false, app->confBasis.num_basis * vdim * (vdim + 1) / 2, app->local_ext.volume); } // Allocate arrays for specified metric inverse - s->h_ij_inv = mkarr(app->use_gpu, app->confBasis.num_basis*vdim*(vdim+1)/2, app->local_ext.volume); + s->h_ij_inv = + mkarr(app->use_gpu, app->confBasis.num_basis * vdim * (vdim + 1) / 2, app->local_ext.volume); s->h_ij_inv_host = s->h_ij_inv; - if (app->use_gpu){ - s->h_ij_inv_host = mkarr(false, app->confBasis.num_basis*vdim*(vdim+1)/2, app->local_ext.volume); + if (app->use_gpu) { + s->h_ij_inv_host = + mkarr(false, app->confBasis.num_basis * vdim * (vdim + 1) / 2, app->local_ext.volume); } // Allocate arrays for specified metric determinant s->det_h = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); s->det_h_host = s->det_h; - if (app->use_gpu){ + if (app->use_gpu) { s->det_h_host = mkarr(false, app->confBasis.num_basis, app->local_ext.volume); } // Evaluate specified hamiltonian function at nodes to insure continuity of hamiltoniam - struct gkyl_eval_on_nodes* hamil_proj = gkyl_eval_on_nodes_new(&s->grid, &app->basis, 1, s->info.hamil, s->info.hamil_ctx); + struct gkyl_eval_on_nodes *hamil_proj = + gkyl_eval_on_nodes_new(&s->grid, &app->basis, 1, s->info.hamil, s->info.hamil_ctx); gkyl_eval_on_nodes_advance(hamil_proj, 0.0, &s->local_ext, s->hamil_host); - if (app->use_gpu){ + if (app->use_gpu) { gkyl_array_copy(s->hamil, s->hamil_host); } gkyl_eval_on_nodes_release(hamil_proj); // Evaluate specified metric function at nodes to insure continuity - struct gkyl_eval_on_nodes* h_ij_proj = gkyl_eval_on_nodes_new(&app->grid, &app->confBasis, vdim*(vdim+1)/2, s->info.h_ij, s->info.h_ij_ctx); + struct gkyl_eval_on_nodes *h_ij_proj = gkyl_eval_on_nodes_new( + &app->grid, &app->confBasis, vdim * (vdim + 1) / 2, s->info.h_ij, s->info.h_ij_ctx + ); gkyl_eval_on_nodes_advance(h_ij_proj, 0.0, &app->local, s->h_ij_host); - if (app->use_gpu){ + if (app->use_gpu) { gkyl_array_copy(s->h_ij, s->h_ij_host); } gkyl_eval_on_nodes_release(h_ij_proj); - // Evaluate specified inverse metric function at nodes to insure continuity of the inverse - struct gkyl_eval_on_nodes* h_ij_inv_proj = gkyl_eval_on_nodes_new(&app->grid, &app->confBasis, vdim*(vdim+1)/2, s->info.h_ij_inv, s->info.h_ij_inv_ctx); + // Evaluate specified inverse metric function at nodes to insure continuity of the inverse + struct gkyl_eval_on_nodes *h_ij_inv_proj = gkyl_eval_on_nodes_new( + &app->grid, &app->confBasis, vdim * (vdim + 1) / 2, s->info.h_ij_inv, s->info.h_ij_inv_ctx + ); gkyl_eval_on_nodes_advance(h_ij_inv_proj, 0.0, &app->local, s->h_ij_inv_host); - if (app->use_gpu){ + if (app->use_gpu) { gkyl_array_copy(s->h_ij_inv, s->h_ij_inv_host); } gkyl_eval_on_nodes_release(h_ij_inv_proj); // Evaluate specified determinant metric function at nodes to insure continuity of the determinant - struct gkyl_eval_on_nodes* det_h_proj = gkyl_eval_on_nodes_new(&app->grid, &app->confBasis, 1, s->info.det_h, s->info.det_h_ctx); + struct gkyl_eval_on_nodes *det_h_proj = + gkyl_eval_on_nodes_new(&app->grid, &app->confBasis, 1, s->info.det_h, s->info.det_h_ctx); gkyl_eval_on_nodes_advance(det_h_proj, 0.0, &app->local, s->det_h_host); - if (app->use_gpu){ + if (app->use_gpu) { gkyl_array_copy(s->det_h, s->det_h_host); } gkyl_eval_on_nodes_release(det_h_proj); - // Need to figure out size of alpha_surf and sgn_alpha_surf by finding size of surface basis set + // Need to figure out size of alpha_surf and sgn_alpha_surf by finding size of surface basis set struct gkyl_basis surf_basis, surf_quad_basis; if (app->basis.b_type == GKYL_BASIS_MODAL_HYBRID) { // NOTE: If we are hybrid, allocate more memory than we need to avoid surface basis are different // sizes in each direction. - gkyl_cart_modal_serendip(&surf_basis, pdim-1, 2); - gkyl_cart_modal_tensor(&surf_quad_basis, pdim-1, 2); - } - else { - gkyl_cart_modal_serendip(&surf_basis, pdim-1, app->poly_order); - gkyl_cart_modal_tensor(&surf_quad_basis, pdim-1, app->poly_order); + gkyl_cart_modal_serendip(&surf_basis, pdim - 1, 2); + gkyl_cart_modal_tensor(&surf_quad_basis, pdim - 1, 2); + } else { + gkyl_cart_modal_serendip(&surf_basis, pdim - 1, app->poly_order); + gkyl_cart_modal_tensor(&surf_quad_basis, pdim - 1, app->poly_order); } - int alpha_surf_sz = (cdim + vdim)*surf_basis.num_basis; - int sgn_alpha_surf_sz = (cdim + vdim)*surf_quad_basis.num_basis; // sign(alpha) is store at quadrature points + int alpha_surf_sz = (cdim + vdim) * surf_basis.num_basis; + int sgn_alpha_surf_sz = + (cdim + vdim) * surf_quad_basis.num_basis; // sign(alpha) is store at quadrature points - // allocate arrays to store fields: + // allocate arrays to store fields: // 1. alpha_surf (surface phase space velocity) // 2. sgn_alpha_surf (sign(alpha_surf) at quadrature points) // 3. const_sgn_alpha (boolean for if sign(alpha_surf) is a constant, either +1 or -1) @@ -226,67 +242,84 @@ vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_speci s->const_sgn_alpha = mk_int_arr(app->use_gpu, (cdim + vdim), s->local_ext.volume); // Pre-compute alpha_surf, sgn_alpha_surf, const_sgn_alpha, and cot_vec since they are time-independent - struct gkyl_dg_calc_canonical_pb_vars *calc_vars = gkyl_dg_calc_canonical_pb_vars_new(&s->grid, - &app->confBasis, &app->basis, app->use_gpu); - gkyl_dg_calc_canonical_pb_vars_alpha_surf(calc_vars, &app->local, &s->local, &s->local_ext, s->hamil, - s->alpha_surf, s->sgn_alpha_surf, s->const_sgn_alpha); + struct gkyl_dg_calc_canonical_pb_vars *calc_vars = + gkyl_dg_calc_canonical_pb_vars_new(&s->grid, &app->confBasis, &app->basis, app->use_gpu); + gkyl_dg_calc_canonical_pb_vars_alpha_surf( + calc_vars, &app->local, &s->local, &s->local_ext, s->hamil, s->alpha_surf, s->sgn_alpha_surf, + s->const_sgn_alpha + ); gkyl_dg_calc_canonical_pb_vars_release(calc_vars); - struct gkyl_dg_canonical_pb_auxfields aux_inp = {.hamil = s->hamil, .alpha_surf = s->alpha_surf, - .sgn_alpha_surf = s->sgn_alpha_surf, .const_sgn_alpha = s->const_sgn_alpha}; + struct gkyl_dg_canonical_pb_auxfields aux_inp = { + .hamil = s->hamil, + .alpha_surf = s->alpha_surf, + .sgn_alpha_surf = s->sgn_alpha_surf, + .const_sgn_alpha = s->const_sgn_alpha + }; //create solver - s->slvr = gkyl_dg_updater_vlasov_new(&s->grid, &app->confBasis, &app->basis, - &app->local, &s->local_vel, &s->local, is_zero_flux, s->model_id, s->field_id, &aux_inp, app->use_gpu); - } - else { + s->slvr = gkyl_dg_updater_vlasov_new( + &s->grid, &app->confBasis, &app->basis, &app->local, &s->local_vel, &s->local, is_zero_flux, + s->model_id, s->field_id, &aux_inp, app->use_gpu + ); + } else { if (s->field_id == GKYL_FIELD_NULL || s->field_id == GKYL_FIELD_E_B) { - struct gkyl_dg_vlasov_auxfields aux_inp = {.field = s->qmem, .cot_vec = 0, - .alpha_surf = 0, .sgn_alpha_surf = 0, .const_sgn_alpha = 0 }; - s->slvr = gkyl_dg_updater_vlasov_new(&s->grid, &app->confBasis, &app->basis, - &app->local, &s->local_vel, &s->local, is_zero_flux, s->model_id, s->field_id, &aux_inp, app->use_gpu); - } - else { - struct gkyl_dg_vlasov_poisson_auxfields aux_inp = {.potentials = s->qmem, .fields_ext = s->qmem_ext}; - s->slvr = gkyl_dg_updater_vlasov_poisson_new(&s->grid, &app->confBasis, &app->basis, - &app->local, &s->local_vel, &s->local, is_zero_flux, s->model_id, s->field_id, &aux_inp, app->use_gpu); + struct gkyl_dg_vlasov_auxfields aux_inp = { + .field = s->qmem, .cot_vec = 0, .alpha_surf = 0, .sgn_alpha_surf = 0, .const_sgn_alpha = 0 + }; + s->slvr = gkyl_dg_updater_vlasov_new( + &s->grid, &app->confBasis, &app->basis, &app->local, &s->local_vel, &s->local, is_zero_flux, + s->model_id, s->field_id, &aux_inp, app->use_gpu + ); + } else { + struct gkyl_dg_vlasov_poisson_auxfields aux_inp = { + .potentials = s->qmem, .fields_ext = s->qmem_ext + }; + s->slvr = gkyl_dg_updater_vlasov_poisson_new( + &s->grid, &app->confBasis, &app->basis, &app->local, &s->local_vel, &s->local, is_zero_flux, + s->model_id, s->field_id, &aux_inp, app->use_gpu + ); } } // acquire equation object - if (s->field_id == GKYL_FIELD_NULL || s->field_id == GKYL_FIELD_E_B) + if (s->field_id == GKYL_FIELD_NULL || s->field_id == GKYL_FIELD_E_B) { s->eqn_vlasov = gkyl_dg_updater_vlasov_acquire_eqn(s->slvr); - else + } else { s->eqn_vlasov = gkyl_dg_updater_vlasov_poisson_acquire_eqn(s->slvr); + } // allocate data for momentum (for use in current accumulation) vm_species_moment_init(app, s, &s->m1i, GKYL_F_MOMENT_M1, false); // allocate date for density (for use in charge density accumulation and weak division for V_drift) vm_species_moment_init(app, s, &s->m0, GKYL_F_MOMENT_M0, false); // allocate data for integrated moments - vm_species_moment_init(app, s, &s->integ_moms, - s->model_id == GKYL_MODEL_SR? GKYL_F_MOMENT_M0ENERGYM3 : GKYL_F_MOMENT_M0M1M2, true); + vm_species_moment_init( + app, s, &s->integ_moms, + s->model_id == GKYL_MODEL_SR ? GKYL_F_MOMENT_M0ENERGYM3 : GKYL_F_MOMENT_M0M1M2, true + ); // allocate data for diagnostic moments int ndm = s->info.num_diag_moments; s->moms = gkyl_malloc(sizeof(struct vm_species_moment[ndm])); - for (int m=0; mmoms[m], s->info.diag_moments[m], false); + } // array for storing f^2 in each cell s->L2_f = mkarr(app->use_gpu, 1, s->local_ext.volume); if (app->use_gpu) { s->red_L2_f = gkyl_cu_malloc(sizeof(double)); - s->red_integ_diag = gkyl_cu_malloc(sizeof(double[vdim+2])); + s->red_integ_diag = gkyl_cu_malloc(sizeof(double[vdim + 2])); } // allocate dynamic-vector to store all-reduced integrated moments and f^2 s->integ_L2_f = gkyl_dynvec_new(GKYL_DOUBLE, 1); - s->integ_diag = gkyl_dynvec_new(GKYL_DOUBLE, vdim+2); + s->integ_diag = gkyl_dynvec_new(GKYL_DOUBLE, vdim + 2); s->is_first_integ_L2_write_call = true; s->is_first_integ_write_call = true; - // Initialize applied acceleration for use in force update. - s->app_accel = mkarr(app->use_gpu, 3*app->confBasis.num_basis, app->local_ext.volume); + // Initialize applied acceleration for use in force update. + s->app_accel = mkarr(app->use_gpu, 3 * app->confBasis.num_basis, app->local_ext.volume); gkyl_array_clear(s->app_accel, 0.0); s->has_app_accel = false; s->app_accel_evolve = false; @@ -299,15 +332,17 @@ vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_speci s->app_accel_host = s->app_accel; if (app->use_gpu) { - s->app_accel_host = mkarr(false, 3*app->confBasis.num_basis, app->local_ext.volume); + s->app_accel_host = mkarr(false, 3 * app->confBasis.num_basis, app->local_ext.volume); } - s->app_accel_proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, app->confBasis.poly_order+1, - 3, s->info.app_accel, s->info.app_accel_ctx); + s->app_accel_proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->confBasis.poly_order + 1, 3, s->info.app_accel, + s->info.app_accel_ctx + ); } // initialize projection routine for initial conditions s->num_init = s->info.num_init; - for (int k=0; knum_init; k++) { + for (int k = 0; k < s->num_init; k++) { vm_species_projection_init(app, s, s->info.projection[k], &s->proj_init[k]); } // If the number of initial condition functions > 1, make a temporary array for accumulation @@ -320,43 +355,49 @@ vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_speci if (s->source_id == GKYL_BFLUX_SOURCE) { s->calc_bflux = true; } - + // determine collision type to use in vlasov update s->collision_id = s->info.collisions.collision_id; - s->lte = (struct vm_lte) { }; + s->lte = (struct vm_lte){}; // initialize empty collision structs so inputs of structs are set to 0 - s->lbo = (struct vm_lbo_collisions) { }; - s->bgk = (struct vm_bgk_collisions) { }; - if (s->info.output_f_lte){ + s->lbo = (struct vm_lbo_collisions){}; + s->bgk = (struct vm_bgk_collisions){}; + if (s->info.output_f_lte) { // Always have correct moments on for the f_lte output - struct correct_all_moms_inp corr_inp = { .correct_all_moms = true, - .max_iter = s->info.max_iter, .iter_eps = s->info.iter_eps, - .use_last_converged = s->info.use_last_converged }; + struct correct_all_moms_inp corr_inp = { + .correct_all_moms = true, + .max_iter = s->info.max_iter, + .iter_eps = s->info.iter_eps, + .use_last_converged = s->info.use_last_converged + }; vm_species_lte_init(app, s, &s->lte, corr_inp); } if (s->collision_id == GKYL_LBO_COLLISIONS) { vm_species_lbo_init(app, s, &s->lbo); - } - else if (s->collision_id == GKYL_BGK_COLLISIONS) { + } else if (s->collision_id == GKYL_BGK_COLLISIONS) { vm_species_bgk_init(app, s, &s->bgk); } // determine radiation type to use in vlasov update s->radiation_id = s->info.radiation.radiation_id; - s->rad = (struct vm_rad_drag) { }; + s->rad = (struct vm_rad_drag){}; if (s->radiation_id == GKYL_VM_COMPTON_RADIATION) { vm_species_radiation_init(app, s, &s->rad); } // Local lower/upper skin and ghost ranges (for applying BCs). - for (int dir=0; dirlower_skin[dir], &s->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &s->local_ext, ghost); - gkyl_skin_ghost_ranges(&s->upper_skin[dir], &s->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &s->local_ext, ghost); + for (int dir = 0; dir < cdim; ++dir) { + gkyl_skin_ghost_ranges( + &s->lower_skin[dir], &s->lower_ghost[dir], dir, GKYL_LOWER_EDGE, &s->local_ext, ghost + ); + gkyl_skin_ghost_ranges( + &s->upper_skin[dir], &s->upper_ghost[dir], dir, GKYL_UPPER_EDGE, &s->local_ext, ghost + ); } // Allocate buffer for applying BCs. long buff_sz = 0; - for (int dir=0; dirlower_skin[dir].volume, s->upper_skin[dir].volume); buff_sz = buff_sz > vol ? buff_sz : vol; } @@ -365,27 +406,28 @@ vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_speci s->bc_buffer_lo_fixed = mkarr(app->use_gpu, app->basis.num_basis, buff_sz); s->bc_buffer_up_fixed = mkarr(app->use_gpu, app->basis.num_basis, buff_sz); - for (int d=0; dlower_bc[d].type == GKYL_SPECIES_EMISSION) { s->emit_lo = true; s->calc_bflux = true; vm_species_emission_init(app, &s->bc_emission_lo, d, GKYL_LOWER_EDGE, s->lower_bc[d].aux_ctx); - } - else { - if (s->lower_bc[d].type == GKYL_SPECIES_COPY) + } else { + if (s->lower_bc[d].type == GKYL_SPECIES_COPY) { bctype = GKYL_BC_COPY; - else if (s->lower_bc[d].type == GKYL_SPECIES_ABSORB) + } else if (s->lower_bc[d].type == GKYL_SPECIES_ABSORB) { bctype = GKYL_BC_ABSORB; - else if (s->lower_bc[d].type == GKYL_SPECIES_REFLECT) + } else if (s->lower_bc[d].type == GKYL_SPECIES_REFLECT) { bctype = GKYL_BC_DISTF_REFLECT; - else if (s->lower_bc[d].type == GKYL_SPECIES_FIXED_FUNC) + } else if (s->lower_bc[d].type == GKYL_SPECIES_FIXED_FUNC) { bctype = GKYL_BC_FIXED_FUNC; + } - s->bc_lo[d] = gkyl_bc_basic_new(d, GKYL_LOWER_EDGE, bctype, app->basis_on_dev.basis, - &s->lower_skin[d], &s->lower_ghost[d], s->f->ncomp, app->cdim, app->use_gpu); + s->bc_lo[d] = gkyl_bc_basic_new( + d, GKYL_LOWER_EDGE, bctype, app->basis_on_dev.basis, &s->lower_skin[d], &s->lower_ghost[d], + s->f->ncomp, app->cdim, app->use_gpu + ); } // Upper BC updater. Copy BCs by default. @@ -393,19 +435,21 @@ vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_speci s->emit_up = true; s->calc_bflux = true; vm_species_emission_init(app, &s->bc_emission_up, d, GKYL_UPPER_EDGE, s->upper_bc[d].aux_ctx); - } - else { - if (s->upper_bc[d].type == GKYL_SPECIES_COPY) + } else { + if (s->upper_bc[d].type == GKYL_SPECIES_COPY) { bctype = GKYL_BC_COPY; - else if (s->upper_bc[d].type == GKYL_SPECIES_ABSORB) + } else if (s->upper_bc[d].type == GKYL_SPECIES_ABSORB) { bctype = GKYL_BC_ABSORB; - else if (s->upper_bc[d].type == GKYL_SPECIES_REFLECT) + } else if (s->upper_bc[d].type == GKYL_SPECIES_REFLECT) { bctype = GKYL_BC_DISTF_REFLECT; - else if (s->upper_bc[d].type == GKYL_SPECIES_FIXED_FUNC) + } else if (s->upper_bc[d].type == GKYL_SPECIES_FIXED_FUNC) { bctype = GKYL_BC_FIXED_FUNC; + } - s->bc_up[d] = gkyl_bc_basic_new(d, GKYL_UPPER_EDGE, bctype, app->basis_on_dev.basis, - &s->upper_skin[d], &s->upper_ghost[d], s->f->ncomp, app->cdim, app->use_gpu); + s->bc_up[d] = gkyl_bc_basic_new( + d, GKYL_UPPER_EDGE, bctype, app->basis_on_dev.basis, &s->upper_skin[d], &s->upper_ghost[d], + s->f->ncomp, app->cdim, app->use_gpu + ); } } if (s->calc_bflux) { @@ -414,19 +458,17 @@ vm_species_init(struct gkyl_vm *vm, struct gkyl_vlasov_app *app, struct vm_speci } } -void -vm_species_apply_ic(gkyl_vlasov_app *app, struct vm_species *species, double t0) +void vm_species_apply_ic(gkyl_vlasov_app *app, struct vm_species *species, double t0) { if (species->num_init > 1) { - gkyl_array_clear(species->f, 0.0); - for (int k=0; knum_init; k++) { + gkyl_array_clear(species->f, 0.0); + for (int k = 0; k < species->num_init; k++) { vm_species_projection_calc(app, species, &species->proj_init[k], species->f_tmp, t0); gkyl_array_accumulate(species->f, 1.0, species->f_tmp); } // Free the temporary array now that initial conditions are complete gkyl_array_release(species->f_tmp); - } - else { + } else { vm_species_projection_calc(app, species, &species->proj_init[0], species->f, t0); } @@ -440,25 +482,28 @@ vm_species_apply_ic(gkyl_vlasov_app *app, struct vm_species *species, double t0) vm_species_bflux_rhs(app, species, &species->bflux, species->f, species->f1); } - // Optional runtime configuration to use BGK collisions but with fixed input - // temperature relaxation based on the initial temperature value. + // Optional runtime configuration to use BGK collisions but with fixed input + // temperature relaxation based on the initial temperature value. if (species->bgk.fixed_temp_relax) { vm_species_bgk_moms_fixed_temp(app, species, &species->bgk, species->f); } - + // copy contents of initial conditions into buffer if specific BCs require them // *only works in x dimension for now* - if (species->lower_bc[0].type == GKYL_SPECIES_FIXED_FUNC) + if (species->lower_bc[0].type == GKYL_SPECIES_FIXED_FUNC) { gkyl_bc_basic_buffer_fixed_func(species->bc_lo[0], species->bc_buffer_lo_fixed, species->f); - if (species->upper_bc[0].type == GKYL_SPECIES_FIXED_FUNC) + } + if (species->upper_bc[0].type == GKYL_SPECIES_FIXED_FUNC) { gkyl_bc_basic_buffer_fixed_func(species->bc_up[0], species->bc_buffer_up_fixed, species->f); + } } -void -vm_species_calc_app_accel(gkyl_vlasov_app *app, struct vm_species *species, double tm) +void vm_species_calc_app_accel(gkyl_vlasov_app *app, struct vm_species *species, double tm) { if (species->has_app_accel) { - gkyl_proj_on_basis_advance(species->app_accel_proj, tm, &app->local_ext, species->app_accel_host); + gkyl_proj_on_basis_advance( + species->app_accel_proj, tm, &app->local_ext, species->app_accel_host + ); if (app->use_gpu) { // note: app_accel_host is same as app_accel when not on GPUs gkyl_array_copy(species->app_accel, species->app_accel_host); @@ -468,15 +513,16 @@ vm_species_calc_app_accel(gkyl_vlasov_app *app, struct vm_species *species, doub // Compute the RHS for species update, returning maximum stable // time-step. -double -vm_species_rhs(gkyl_vlasov_app *app, struct vm_species *species, - const struct gkyl_array *fin, const struct gkyl_array *em, struct gkyl_array *rhs) +double vm_species_rhs( + gkyl_vlasov_app *app, struct vm_species *species, const struct gkyl_array *fin, + const struct gkyl_array *em, struct gkyl_array *rhs +) { gkyl_array_clear(species->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); - if (species->field_id == GKYL_FIELD_NULL || species->field_id == GKYL_FIELD_E_B) { - if (species->field_id == GKYL_FIELD_E_B) { + if (species->field_id == GKYL_FIELD_NULL || species->field_id == GKYL_FIELD_E_B) { + if (species->field_id == GKYL_FIELD_E_B) { gkyl_array_set(species->qmem, species->qbym, em); // Accumulate applied acceleration and/or q/m*(external electromagnetic) @@ -489,29 +535,26 @@ vm_species_rhs(gkyl_vlasov_app *app, struct vm_species *species, } } - gkyl_dg_updater_vlasov_advance(species->slvr, &species->local, - fin, species->cflrate, rhs); - } - else { + gkyl_dg_updater_vlasov_advance(species->slvr, &species->local, fin, species->cflrate, rhs); + } else { if (app->field->has_ext_pot) { gkyl_array_set_range(species->qmem, species->qbym, app->field->ext_pot, &app->local); gkyl_array_accumulate_offset(species->qmem, species->qbym, app->field->phi, 0); - } - else { + } else { gkyl_array_set_offset(species->qmem, species->qbym, app->field->phi, 0); if (app->field->ext_em_evolve) { gkyl_array_set_range(species->qmem_ext, species->qbym, app->field->ext_em, &app->local); } } - gkyl_dg_updater_vlasov_poisson_advance(species->slvr, &species->local, - fin, species->cflrate, rhs); + gkyl_dg_updater_vlasov_poisson_advance( + species->slvr, &species->local, fin, species->cflrate, rhs + ); } if (species->collision_id == GKYL_LBO_COLLISIONS) { vm_species_lbo_rhs(app, species, &species->lbo, fin, rhs); - } - else if (species->collision_id == GKYL_BGK_COLLISIONS && !app->has_implicit_coll_scheme) { + } else if (species->collision_id == GKYL_BGK_COLLISIONS && !app->has_implicit_coll_scheme) { species->bgk.implicit_step = false; vm_species_bgk_rhs(app, species, &species->bgk, fin, rhs); } @@ -523,31 +566,31 @@ vm_species_rhs(gkyl_vlasov_app *app, struct vm_species *species, if (species->radiation_id == GKYL_VM_COMPTON_RADIATION) { vm_species_radiation_rhs(app, species, &species->rad, fin, rhs); } - - app->stat.n_species_omega_cfl +=1; + + app->stat.n_species_omega_cfl += 1; struct timespec tm = gkyl_wall_clock(); gkyl_array_reduce_range(species->omegaCfl_ptr, species->cflrate, GKYL_MAX, &species->local); double omegaCfl_ho[1]; - if (app->use_gpu) + if (app->use_gpu) { gkyl_cu_memcpy(omegaCfl_ho, species->omegaCfl_ptr, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { omegaCfl_ho[0] = species->omegaCfl_ptr[0]; + } double omegaCfl = omegaCfl_ho[0]; app->stat.species_omega_cfl_tm += gkyl_time_diff_now_sec(tm); - - return app->cfl/omegaCfl; -} + return app->cfl / omegaCfl; +} // Compute the implicit RHS for species update, returning maximum stable // time-step. -double -vm_species_rhs_implicit(gkyl_vlasov_app *app, struct vm_species *species, - const struct gkyl_array *fin, struct gkyl_array *rhs, double dt) +double vm_species_rhs_implicit( + gkyl_vlasov_app *app, struct vm_species *species, const struct gkyl_array *fin, + struct gkyl_array *rhs, double dt +) { - gkyl_array_clear(species->cflrate, 0.0); gkyl_array_clear(rhs, 0.0); @@ -558,82 +601,83 @@ vm_species_rhs_implicit(gkyl_vlasov_app *app, struct vm_species *species, if (species->calc_bflux) { vm_species_bflux_rhs(app, species, &species->bflux, fin, rhs); } - - app->stat.n_species_omega_cfl +=1; + + app->stat.n_species_omega_cfl += 1; struct timespec tm = gkyl_wall_clock(); gkyl_array_reduce_range(species->omegaCfl_ptr, species->cflrate, GKYL_MAX, &species->local); double omegaCfl_ho[1]; - if (app->use_gpu) + if (app->use_gpu) { gkyl_cu_memcpy(omegaCfl_ho, species->omegaCfl_ptr, sizeof(double), GKYL_CU_MEMCPY_D2H); - else + } else { omegaCfl_ho[0] = species->omegaCfl_ptr[0]; + } double omegaCfl = omegaCfl_ho[0]; app->stat.species_omega_cfl_tm += gkyl_time_diff_now_sec(tm); - - return app->cfl/omegaCfl; -} + return app->cfl / omegaCfl; +} // Determine which directions are periodic and which directions are not periodic, // and then apply boundary conditions for distribution function -void -vm_species_apply_bc(gkyl_vlasov_app *app, const struct vm_species *species, struct gkyl_array *f, - double tcurr) +void vm_species_apply_bc( + gkyl_vlasov_app *app, const struct vm_species *species, struct gkyl_array *f, double tcurr +) { struct timespec wst = gkyl_wall_clock(); - + int num_periodic_dir = app->num_periodic_dir, cdim = app->cdim; - gkyl_comm_array_per_sync(species->comm, &species->local, &species->local_ext, - num_periodic_dir, app->periodic_dirs, f); - + gkyl_comm_array_per_sync( + species->comm, &species->local, &species->local_ext, num_periodic_dir, app->periodic_dirs, f + ); + int is_np_bc[3] = {1, 1, 1}; // flags to indicate if direction is periodic - for (int d=0; dperiodic_dirs[d]] = 0; + } - for (int d=0; dlower_bc[d].type) { - case GKYL_SPECIES_EMISSION: - vm_species_emission_apply_bc(app, &species->bc_emission_lo, f, tcurr); - break; - case GKYL_SPECIES_COPY: - case GKYL_SPECIES_REFLECT: - case GKYL_SPECIES_ABSORB: - gkyl_bc_basic_advance(species->bc_lo[d], species->bc_buffer, f); - break; - case GKYL_SPECIES_FIXED_FUNC: - gkyl_bc_basic_advance(species->bc_lo[d], species->bc_buffer_lo_fixed, f); - break; - case GKYL_SPECIES_NO_SLIP: - case GKYL_SPECIES_WEDGE: - assert(false); - break; - default: - break; + case GKYL_SPECIES_EMISSION: + vm_species_emission_apply_bc(app, &species->bc_emission_lo, f, tcurr); + break; + case GKYL_SPECIES_COPY: + case GKYL_SPECIES_REFLECT: + case GKYL_SPECIES_ABSORB: + gkyl_bc_basic_advance(species->bc_lo[d], species->bc_buffer, f); + break; + case GKYL_SPECIES_FIXED_FUNC: + gkyl_bc_basic_advance(species->bc_lo[d], species->bc_buffer_lo_fixed, f); + break; + case GKYL_SPECIES_NO_SLIP: + case GKYL_SPECIES_WEDGE: + assert(false); + break; + default: + break; } switch (species->upper_bc[d].type) { - case GKYL_SPECIES_EMISSION: - vm_species_emission_apply_bc(app, &species->bc_emission_up, f, tcurr); - break; - case GKYL_SPECIES_COPY: - case GKYL_SPECIES_REFLECT: - case GKYL_SPECIES_ABSORB: - gkyl_bc_basic_advance(species->bc_up[d], species->bc_buffer, f); - break; - case GKYL_SPECIES_FIXED_FUNC: - gkyl_bc_basic_advance(species->bc_up[d], species->bc_buffer_up_fixed, f); - break; - case GKYL_SPECIES_NO_SLIP: - case GKYL_SPECIES_WEDGE: - assert(false); - break; - default: - break; - } + case GKYL_SPECIES_EMISSION: + vm_species_emission_apply_bc(app, &species->bc_emission_up, f, tcurr); + break; + case GKYL_SPECIES_COPY: + case GKYL_SPECIES_REFLECT: + case GKYL_SPECIES_ABSORB: + gkyl_bc_basic_advance(species->bc_up[d], species->bc_buffer, f); + break; + case GKYL_SPECIES_FIXED_FUNC: + gkyl_bc_basic_advance(species->bc_up[d], species->bc_buffer_up_fixed, f); + break; + case GKYL_SPECIES_NO_SLIP: + case GKYL_SPECIES_WEDGE: + assert(false); + break; + default: + break; + } } } @@ -642,31 +686,27 @@ vm_species_apply_bc(gkyl_vlasov_app *app, const struct vm_species *species, stru app->stat.species_bc_tm += gkyl_time_diff_now_sec(wst); } - -void -vm_species_calc_L2(gkyl_vlasov_app *app, double tm, const struct vm_species *species) +void vm_species_calc_L2(gkyl_vlasov_app *app, double tm, const struct vm_species *species) { gkyl_dg_calc_l2_range(&app->basis, 0, species->L2_f, 0, species->f, species->local); gkyl_array_scale_range(species->L2_f, species->grid.cellVolume, &species->local); - - double L2[1] = { 0.0 }; + + double L2[1] = {0.0}; if (app->use_gpu) { gkyl_array_reduce_range(species->red_L2_f, species->L2_f, GKYL_SUM, &species->local); gkyl_cu_memcpy(L2, species->red_L2_f, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { gkyl_array_reduce_range(L2, species->L2_f, GKYL_SUM, &species->local); } - double L2_global[1] = { 0.0 }; + double L2_global[1] = {0.0}; gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, L2, L2_global); - - gkyl_dynvec_append(species->integ_L2_f, tm, L2_global); + + gkyl_dynvec_append(species->integ_L2_f, tm, L2_global); } -void -vm_species_coll_tm(gkyl_vlasov_app *app) +void vm_species_coll_tm(gkyl_vlasov_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { if (app->species[i].collision_id == GKYL_LBO_COLLISIONS) { struct gkyl_dg_updater_lbo_vlasov_tm tm = gkyl_dg_updater_lbo_vlasov_get_tm(app->species[i].lbo.coll_slvr); @@ -676,36 +716,33 @@ vm_species_coll_tm(gkyl_vlasov_app *app) } } -void -vm_species_bgk_niter(gkyl_vlasov_app *app) +void vm_species_bgk_niter(gkyl_vlasov_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { if (app->species[i].collision_id == GKYL_BGK_COLLISIONS) { app->stat.niter_self_bgk_corr[i] = app->species[i].bgk.lte.niter; } } } - -void -vm_species_tm(gkyl_vlasov_app *app) +void vm_species_tm(gkyl_vlasov_app *app) { app->stat.species_rhs_tm = 0.0; - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct vm_species *s = &app->species[i]; struct gkyl_dg_updater_vlasov_tm tm; - if (s->field_id == GKYL_FIELD_NULL || s->field_id == GKYL_FIELD_E_B) + if (s->field_id == GKYL_FIELD_NULL || s->field_id == GKYL_FIELD_E_B) { tm = gkyl_dg_updater_vlasov_get_tm(s->slvr); - else + } else { tm = gkyl_dg_updater_vlasov_poisson_get_tm(s->slvr); + } app->stat.species_rhs_tm += tm.vlasov_tm; } } -void -vm_species_rad_tm(gkyl_vlasov_app *app) +void vm_species_rad_tm(gkyl_vlasov_app *app) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { if (app->species[i].radiation_id == GKYL_VM_COMPTON_RADIATION) { struct gkyl_dg_updater_rad_vlasov_tm tm = gkyl_dg_updater_rad_vlasov_get_tm(app->species[i].rad.rad_slvr); @@ -715,8 +752,7 @@ vm_species_rad_tm(gkyl_vlasov_app *app) } // release resources for species -void -vm_species_release(const gkyl_vlasov_app* app, const struct vm_species *s) +void vm_species_release(const gkyl_vlasov_app *app, const struct vm_species *s) { // release various arrays gkyl_array_release(s->f); @@ -727,7 +763,7 @@ vm_species_release(const gkyl_vlasov_app* app, const struct vm_species *s) gkyl_array_release(s->bc_buffer_lo_fixed); gkyl_array_release(s->bc_buffer_up_fixed); - for (int k=0; knum_init; k++) { + for (int k = 0; k < s->num_init; k++) { vm_species_projection_release(app, &s->proj_init[k]); } @@ -737,11 +773,12 @@ vm_species_release(const gkyl_vlasov_app* app, const struct vm_species *s) gkyl_comm_release(s->comm); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_release(s->f_host); + } // Release arrays for different types of Vlasov equations - if (s->model_id == GKYL_MODEL_SR) { + if (s->model_id == GKYL_MODEL_SR) { gkyl_dg_calc_sr_vars_release(s->sr_vars); // release relativistic arrays data gkyl_array_release(s->gamma); @@ -750,8 +787,7 @@ vm_species_release(const gkyl_vlasov_app* app, const struct vm_species *s) gkyl_array_release(s->gamma_host); gkyl_array_release(s->gamma_inv_host); } - } - else if (s->model_id == GKYL_MODEL_CANONICAL_PB || s->model_id == GKYL_MODEL_CANONICAL_PB_GR) { + } else if (s->model_id == GKYL_MODEL_CANONICAL_PB || s->model_id == GKYL_MODEL_CANONICAL_PB_GR) { gkyl_array_release(s->hamil); gkyl_array_release(s->h_ij); gkyl_array_release(s->h_ij_inv); @@ -759,7 +795,7 @@ vm_species_release(const gkyl_vlasov_app* app, const struct vm_species *s) gkyl_array_release(s->alpha_surf); gkyl_array_release(s->sgn_alpha_surf); gkyl_array_release(s->const_sgn_alpha); - if (app->use_gpu){ + if (app->use_gpu) { gkyl_array_release(s->hamil_host); gkyl_array_release(s->h_ij_host); gkyl_array_release(s->h_ij_inv_host); @@ -771,9 +807,9 @@ vm_species_release(const gkyl_vlasov_app* app, const struct vm_species *s) // release equation object and solver gkyl_dg_eqn_release(s->eqn_vlasov); - if (s->field_id == GKYL_FIELD_NULL || s->field_id == GKYL_FIELD_E_B) + if (s->field_id == GKYL_FIELD_NULL || s->field_id == GKYL_FIELD_E_B) { gkyl_dg_updater_vlasov_release(s->slvr); - else { + } else { gkyl_array_release(s->qmem_ext); gkyl_dg_updater_vlasov_poisson_release(s->slvr); } @@ -781,19 +817,21 @@ vm_species_release(const gkyl_vlasov_app* app, const struct vm_species *s) // release moment data vm_species_moment_release(app, &s->m1i); vm_species_moment_release(app, &s->m0); - for (int i=0; iinfo.num_diag_moments; ++i) + for (int i = 0; i < s->info.num_diag_moments; ++i) { vm_species_moment_release(app, &s->moms[i]); + } gkyl_free(s->moms); - vm_species_moment_release(app, &s->integ_moms); + vm_species_moment_release(app, &s->integ_moms); gkyl_array_release(s->L2_f); gkyl_dynvec_release(s->integ_L2_f); gkyl_dynvec_release(s->integ_diag); - + gkyl_array_release(s->app_accel); if (s->has_app_accel) { - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_release(s->app_accel_host); + } gkyl_proj_on_basis_release(s->app_accel_proj); } @@ -801,13 +839,12 @@ vm_species_release(const gkyl_vlasov_app* app, const struct vm_species *s) if (s->source_id) { vm_species_source_release(app, &s->src); } - if (s->info.output_f_lte){ + if (s->info.output_f_lte) { vm_species_lte_release(app, &s->lte); } if (s->collision_id == GKYL_LBO_COLLISIONS) { vm_species_lbo_release(app, &s->lbo); - } - else if (s->collision_id == GKYL_BGK_COLLISIONS) { + } else if (s->collision_id == GKYL_BGK_COLLISIONS) { vm_species_bgk_release(app, &s->bgk); } @@ -816,24 +853,25 @@ vm_species_release(const gkyl_vlasov_app* app, const struct vm_species *s) } // Copy BCs are allocated by default. Need to free. - for (int d=0; dcdim; ++d) { - if (s->lower_bc[d].type == GKYL_SPECIES_EMISSION) + for (int d = 0; d < app->cdim; ++d) { + if (s->lower_bc[d].type == GKYL_SPECIES_EMISSION) { vm_species_emission_release(&s->bc_emission_lo); - else + } else { gkyl_bc_basic_release(s->bc_lo[d]); - - if (s->upper_bc[d].type == GKYL_SPECIES_EMISSION) + } + + if (s->upper_bc[d].type == GKYL_SPECIES_EMISSION) { vm_species_emission_release(&s->bc_emission_up); - else + } else { gkyl_bc_basic_release(s->bc_up[d]); + } } - + if (app->use_gpu) { gkyl_cu_free(s->omegaCfl_ptr); gkyl_cu_free(s->red_L2_f); gkyl_cu_free(s->red_integ_diag); - } - else { + } else { gkyl_free(s->omegaCfl_ptr); } } diff --git a/vlasov/apps/vm_species_bflux.c b/vlasov/apps/vm_species_bflux.c index 1207db0175..fbda91c06c 100644 --- a/vlasov/apps/vm_species_bflux.c +++ b/vlasov/apps/vm_species_bflux.c @@ -2,15 +2,16 @@ #include #include -void -vm_species_bflux_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_boundary_fluxes *bflux) -{ +void vm_species_bflux_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_boundary_fluxes *bflux +) +{ // allocate solver bflux->flux_slvr = gkyl_ghost_surf_calc_new(&s->grid, s->eqn_vlasov, app->cdim, app->use_gpu); int ndim = app->cdim + app->vdim; int cells[GKYL_MAX_DIM], ghost[GKYL_MAX_DIM]; double lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM]; - for (int d=0; dgrid.cells[d]; lower[d] = s->grid.lower[d]; upper[d] = s->grid.upper[d]; @@ -18,51 +19,60 @@ vm_species_bflux_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct } // initialize moment solver - for (int i=0; icdim; ++i) { + for (int i = 0; i < app->cdim; ++i) { cells[i] = 1; - bflux->flux_arr[2*i] = mkarr(app->use_gpu, app->basis.num_basis, s->lower_ghost[i].volume); - bflux->flux_arr[2*i+1] = mkarr(app->use_gpu, app->basis.num_basis, s->upper_ghost[i].volume); + bflux->flux_arr[2 * i] = mkarr(app->use_gpu, app->basis.num_basis, s->lower_ghost[i].volume); + bflux->flux_arr[2 * i + 1] = + mkarr(app->use_gpu, app->basis.num_basis, s->upper_ghost[i].volume); - gkyl_range_init(&bflux->flux_r[2*i], ndim, s->lower_ghost[i].lower, s->lower_ghost[i].upper); - gkyl_range_init(&bflux->flux_r[2*i+1], ndim, s->upper_ghost[i].lower, s->upper_ghost[i].upper); + gkyl_range_init(&bflux->flux_r[2 * i], ndim, s->lower_ghost[i].lower, s->lower_ghost[i].upper); + gkyl_range_init( + &bflux->flux_r[2 * i + 1], ndim, s->upper_ghost[i].lower, s->upper_ghost[i].upper + ); - gkyl_range_init(&bflux->conf_r[2*i], app->cdim, s->lower_ghost[i].lower, - s->lower_ghost[i].upper); - gkyl_range_init(&bflux->conf_r[2*i+1], app->cdim, s->upper_ghost[i].lower, - s->upper_ghost[i].upper); + gkyl_range_init( + &bflux->conf_r[2 * i], app->cdim, s->lower_ghost[i].lower, s->lower_ghost[i].upper + ); + gkyl_range_init( + &bflux->conf_r[2 * i + 1], app->cdim, s->upper_ghost[i].lower, s->upper_ghost[i].upper + ); upper[i] = s->grid.lower[i] + s->grid.dx[i]; - gkyl_rect_grid_init(&bflux->boundary_grid[2*i], ndim, lower, upper, cells); + gkyl_rect_grid_init(&bflux->boundary_grid[2 * i], ndim, lower, upper, cells); upper[i] = s->grid.upper[i]; lower[i] = s->grid.upper[i] - s->grid.dx[i]; - gkyl_rect_grid_init(&bflux->boundary_grid[2*i+1], ndim, lower, upper, cells); + gkyl_rect_grid_init(&bflux->boundary_grid[2 * i + 1], ndim, lower, upper, cells); - bflux->integ_moms[2*i] = gkyl_dg_updater_moment_new(&bflux->boundary_grid[2*i], - &app->confBasis, &app->basis, &bflux->conf_r[2*i], &s->local_vel, &s->local, - s->model_id, 0, GKYL_F_MOMENT_M0M1M2, true, app->use_gpu); - bflux->integ_moms[2*i+1] = gkyl_dg_updater_moment_new(&bflux->boundary_grid[2*i+1], - &app->confBasis, &app->basis, &bflux->conf_r[2*i+1], &s->local_vel, &s->local, - s->model_id, 0, GKYL_F_MOMENT_M0M1M2, true, app->use_gpu); + bflux->integ_moms[2 * i] = gkyl_dg_updater_moment_new( + &bflux->boundary_grid[2 * i], &app->confBasis, &app->basis, &bflux->conf_r[2 * i], + &s->local_vel, &s->local, s->model_id, 0, GKYL_F_MOMENT_M0M1M2, true, app->use_gpu + ); + bflux->integ_moms[2 * i + 1] = gkyl_dg_updater_moment_new( + &bflux->boundary_grid[2 * i + 1], &app->confBasis, &app->basis, &bflux->conf_r[2 * i + 1], + &s->local_vel, &s->local, s->model_id, 0, GKYL_F_MOMENT_M0M1M2, true, app->use_gpu + ); cells[i] = s->grid.cells[i]; - bflux->mom_arr[2*i] = mkarr(app->use_gpu, app->confBasis.num_basis, bflux->conf_r[2*i].volume); - bflux->mom_arr[2*i+1] = mkarr(app->use_gpu, app->confBasis.num_basis, bflux->conf_r[2*i+1].volume); + bflux->mom_arr[2 * i] = + mkarr(app->use_gpu, app->confBasis.num_basis, bflux->conf_r[2 * i].volume); + bflux->mom_arr[2 * i + 1] = + mkarr(app->use_gpu, app->confBasis.num_basis, bflux->conf_r[2 * i + 1].volume); } } // computes rhs of the boundary flux -void -vm_species_bflux_rhs(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_boundary_fluxes *bflux, const struct gkyl_array *fin, - struct gkyl_array *rhs) +void vm_species_bflux_rhs( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_boundary_fluxes *bflux, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { // zero ghost cells before calculation to ensure there's no residual data - for (int j=0; jcdim; ++j) { + for (int j = 0; j < app->cdim; ++j) { gkyl_array_clear_range(rhs, 0.0, &(species->lower_ghost[j])); gkyl_array_clear_range(rhs, 0.0, &(species->upper_ghost[j])); } @@ -77,24 +87,31 @@ vm_species_bflux_rhs(gkyl_vlasov_app *app, const struct vm_species *species, // only calculating integrated moments for use in the bflux source for now, // others can be added if applications require - for (int j=0; jcdim; ++j) { - gkyl_array_copy_range_to_range(bflux->flux_arr[2*j], rhs, &bflux->flux_r[2*j], - &species->lower_ghost[j]); - gkyl_array_copy_range_to_range(bflux->flux_arr[2*j+1], rhs, &bflux->flux_r[2*j+1], - &species->upper_ghost[j]); - - gkyl_dg_updater_moment_advance(bflux->integ_moms[2*j], &bflux->flux_r[2*j], - &bflux->conf_r[2*j], bflux->flux_arr[2*j], bflux->mom_arr[2*j]); - gkyl_dg_updater_moment_advance(bflux->integ_moms[2*j+1], &bflux->flux_r[2*j+1], - &bflux->conf_r[2*j+1], bflux->flux_arr[2*j+1], bflux->mom_arr[2*j+1]); + for (int j = 0; j < app->cdim; ++j) { + gkyl_array_copy_range_to_range( + bflux->flux_arr[2 * j], rhs, &bflux->flux_r[2 * j], &species->lower_ghost[j] + ); + gkyl_array_copy_range_to_range( + bflux->flux_arr[2 * j + 1], rhs, &bflux->flux_r[2 * j + 1], &species->upper_ghost[j] + ); + + gkyl_dg_updater_moment_advance( + bflux->integ_moms[2 * j], &bflux->flux_r[2 * j], &bflux->conf_r[2 * j], + bflux->flux_arr[2 * j], bflux->mom_arr[2 * j] + ); + gkyl_dg_updater_moment_advance( + bflux->integ_moms[2 * j + 1], &bflux->flux_r[2 * j + 1], &bflux->conf_r[2 * j + 1], + bflux->flux_arr[2 * j + 1], bflux->mom_arr[2 * j + 1] + ); } } -void -vm_species_bflux_release(const struct gkyl_vlasov_app *app, const struct vm_boundary_fluxes *bflux) +void vm_species_bflux_release( + const struct gkyl_vlasov_app *app, const struct vm_boundary_fluxes *bflux +) { gkyl_ghost_surf_calc_release(bflux->flux_slvr); - for (int i=0; i<2*app->cdim; ++i) { + for (int i = 0; i < 2 * app->cdim; ++i) { gkyl_array_release(bflux->mom_arr[i]); gkyl_array_release(bflux->flux_arr[i]); gkyl_dg_updater_moment_release(bflux->integ_moms[i]); diff --git a/vlasov/apps/vm_species_bgk.c b/vlasov/apps/vm_species_bgk.c index 76c11bbabb..3e645e7969 100644 --- a/vlasov/apps/vm_species_bgk.c +++ b/vlasov/apps/vm_species_bgk.c @@ -1,17 +1,20 @@ #include #include -void -vm_species_bgk_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_bgk_collisions *bgk) +void vm_species_bgk_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_bgk_collisions *bgk +) { int cdim = app->cdim, vdim = app->vdim; // allocate nu and initialize it bgk->nu_sum = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); bgk->self_nu = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); struct gkyl_array *self_nu = mkarr(false, app->confBasis.num_basis, app->local_ext.volume); - - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - app->poly_order+1, 1, s->info.collisions.self_nu, s->info.collisions.ctx); + + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->poly_order + 1, 1, s->info.collisions.self_nu, + s->info.collisions.ctx + ); gkyl_proj_on_basis_advance(proj, 0.0, &app->local, self_nu); gkyl_proj_on_basis_release(proj); gkyl_array_copy(bgk->self_nu, self_nu); @@ -25,8 +28,9 @@ vm_species_bgk_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm double nuFrac = s->info.collisions.nuFrac ? s->info.collisions.nuFrac : 1.0; double eps0 = 1.0; double hbar = 1.0; - bgk->spitzer_calc = gkyl_spitzer_coll_freq_new(&app->confBasis, app->poly_order+1, - nuFrac, eps0, hbar, app->use_gpu); + bgk->spitzer_calc = gkyl_spitzer_coll_freq_new( + &app->confBasis, app->poly_order + 1, nuFrac, eps0, hbar, app->use_gpu + ); // Create arrays for scaling collisionality by normalization factor // norm_nu is computed from Spitzer calc and is the normalization factor for the local // density and thermal velocity, norm_nu_sr = n/(vth_s^2 + vth_r^2)^(3/2) @@ -44,56 +48,66 @@ vm_species_bgk_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm } // Allocate everything needed to make f_lte - struct correct_all_moms_inp corr_inp = { .correct_all_moms = s->info.collisions.correct_all_moms, - .max_iter = s->info.collisions.max_iter, .iter_eps = s->info.collisions.iter_eps, - .use_last_converged = s->info.collisions.use_last_converged }; + struct correct_all_moms_inp corr_inp = { + .correct_all_moms = s->info.collisions.correct_all_moms, + .max_iter = s->info.collisions.max_iter, + .iter_eps = s->info.collisions.iter_eps, + .use_last_converged = s->info.collisions.use_last_converged + }; vm_species_lte_init(app, s, &bgk->lte, corr_inp); // Is the temperature being relaxed to fixed in time? bgk->fixed_temp_relax = s->info.collisions.fixed_temp_relax; if (bgk->fixed_temp_relax) { bgk->fixed_temp = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - } - + } + bgk->nu_f_lte = mkarr(app->use_gpu, app->basis.num_basis, s->local_ext.volume); // BGK updater (also computes stable timestep) bgk->up_bgk = gkyl_bgk_collisions_new(&app->confBasis, &app->basis, app->use_gpu); } // computes moments -void -vm_species_bgk_moms(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_bgk_collisions *bgk, const struct gkyl_array *fin) +void vm_species_bgk_moms( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_bgk_collisions *bgk, + const struct gkyl_array *fin +) { struct timespec wst = gkyl_wall_clock(); vm_species_moment_calc(&bgk->lte.moms, species->local, app->local, fin); - if (bgk->fixed_temp_relax) { + if (bgk->fixed_temp_relax) { // Set the temperature in the moment array to the pre-computed fixed value - gkyl_array_set_offset_range(bgk->lte.moms.marr, 1.0, bgk->fixed_temp, - (app->vdim+1)*app->confBasis.num_basis, &app->local); + gkyl_array_set_offset_range( + bgk->lte.moms.marr, 1.0, bgk->fixed_temp, (app->vdim + 1) * app->confBasis.num_basis, + &app->local + ); } - - app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); + + app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); } -// Compute a fixed temperature for BGK relaxation -void -vm_species_bgk_moms_fixed_temp(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_bgk_collisions *bgk, const struct gkyl_array *fin) +// Compute a fixed temperature for BGK relaxation +void vm_species_bgk_moms_fixed_temp( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_bgk_collisions *bgk, + const struct gkyl_array *fin +) { vm_species_moment_calc(&bgk->lte.moms, species->local, app->local, fin); - // Set the temperature to the fixed value - gkyl_array_set_offset_range(bgk->fixed_temp, 1.0, bgk->lte.moms.marr, - (app->vdim+1)*app->confBasis.num_basis, &app->local); + // Set the temperature to the fixed value + gkyl_array_set_offset_range( + bgk->fixed_temp, 1.0, bgk->lte.moms.marr, (app->vdim + 1) * app->confBasis.num_basis, + &app->local + ); } // updates the collision terms in the rhs -void -vm_species_bgk_rhs(gkyl_vlasov_app *app, struct vm_species *species, - struct vm_bgk_collisions *bgk, const struct gkyl_array *fin, struct gkyl_array *rhs) +void vm_species_bgk_rhs( + gkyl_vlasov_app *app, struct vm_species *species, struct vm_bgk_collisions *bgk, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_array_clear(bgk->nu_f_lte, 0.0); @@ -101,18 +115,21 @@ vm_species_bgk_rhs(gkyl_vlasov_app *app, struct vm_species *species, // Project the LTE distribution function from the computed LTE moments vm_species_lte_from_moms(app, species, &bgk->lte, bgk->lte.moms.marr); - gkyl_dg_mul_conf_phase_op_range(&app->confBasis, &app->basis, bgk->lte.f_lte, - bgk->self_nu, bgk->lte.f_lte, &app->local, &species->local); + gkyl_dg_mul_conf_phase_op_range( + &app->confBasis, &app->basis, bgk->lte.f_lte, bgk->self_nu, bgk->lte.f_lte, &app->local, + &species->local + ); gkyl_array_accumulate(bgk->nu_f_lte, 1.0, bgk->lte.f_lte); - gkyl_bgk_collisions_advance(bgk->up_bgk, &app->local, &species->local, - bgk->nu_sum, bgk->nu_f_lte, fin, bgk->implicit_step, bgk->dt_implicit, rhs, species->cflrate); + gkyl_bgk_collisions_advance( + bgk->up_bgk, &app->local, &species->local, bgk->nu_sum, bgk->nu_f_lte, fin, bgk->implicit_step, + bgk->dt_implicit, rhs, species->cflrate + ); app->stat.species_coll_tm += gkyl_time_diff_now_sec(wst); } -void -vm_species_bgk_release(const struct gkyl_vlasov_app *app, const struct vm_bgk_collisions *bgk) +void vm_species_bgk_release(const struct gkyl_vlasov_app *app, const struct vm_bgk_collisions *bgk) { gkyl_array_release(bgk->self_nu); gkyl_array_release(bgk->nu_sum); diff --git a/vlasov/apps/vm_species_emission.c b/vlasov/apps/vm_species_emission.c index cc0979a74c..04d5e8c5a5 100644 --- a/vlasov/apps/vm_species_emission.c +++ b/vlasov/apps/vm_species_emission.c @@ -1,9 +1,10 @@ #include #include -void -vm_species_emission_init(struct gkyl_vlasov_app *app, struct vm_emitting_wall *emit, - int dir, enum gkyl_edge_loc edge, void *ctx) +void vm_species_emission_init( + struct gkyl_vlasov_app *app, struct vm_emitting_wall *emit, int dir, enum gkyl_edge_loc edge, + void *ctx +) { struct gkyl_bc_emission_ctx *params = ctx; emit->params = params; @@ -14,20 +15,20 @@ vm_species_emission_init(struct gkyl_vlasov_app *app, struct vm_emitting_wall *e emit->t_bound = params->t_bound; } -void -vm_species_emission_cross_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_emitting_wall *emit) +void vm_species_emission_cross_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_emitting_wall *emit +) { int cdim = app->cdim; int vdim = app->vdim; - int bdir = (emit->edge == GKYL_LOWER_EDGE) ? 2*emit->dir : 2*emit->dir+1; + int bdir = (emit->edge == GKYL_LOWER_EDGE) ? 2 * emit->dir : 2 * emit->dir + 1; int ghost[GKYL_MAX_DIM]; - for (int d=0; dedge == GKYL_LOWER_EDGE) { @@ -38,111 +39,127 @@ vm_species_emission_cross_init(struct gkyl_vlasov_app *app, struct vm_species *s emit->emit_grid = &s->bflux.boundary_grid[bdir]; emit->emit_buff_r = &s->bflux.flux_r[bdir]; - emit->emit_ghost_r = (emit->edge == GKYL_LOWER_EDGE) ? &s->lower_ghost[emit->dir] : &s->upper_ghost[emit->dir]; - emit->emit_skin_r = (emit->edge == GKYL_LOWER_EDGE) ? &s->lower_skin[emit->dir] : &s->upper_skin[emit->dir]; + emit->emit_ghost_r = (emit->edge == GKYL_LOWER_EDGE) ? &s->lower_ghost[emit->dir] : + &s->upper_ghost[emit->dir]; + emit->emit_skin_r = (emit->edge == GKYL_LOWER_EDGE) ? &s->lower_skin[emit->dir] : + &s->upper_skin[emit->dir]; emit->buffer = s->bc_buffer; emit->f_emit = mkarr(app->use_gpu, app->basis.num_basis, emit->emit_buff_r->volume); - emit->f_emit_host = app->use_gpu? mkarr(false, emit->f_emit->ncomp, emit->f_emit->size) - : gkyl_array_acquire(emit->f_emit); + emit->f_emit_host = app->use_gpu ? mkarr(false, emit->f_emit->ncomp, emit->f_emit->size) : + gkyl_array_acquire(emit->f_emit); struct gkyl_array *proj_buffer = mkarr(false, app->basis.num_basis, emit->emit_buff_r->volume); // Initialize elastic component of emission if (emit->elastic) { emit->elastic_yield = mkarr(app->use_gpu, app->basis.num_basis, emit->emit_buff_r->volume); - emit->elastic_update = gkyl_bc_emission_elastic_new(emit->params->elastic_model, - emit->elastic_yield, emit->dir, emit->edge, cdim, vdim, s->info.mass, s->f->ncomp, emit->emit_grid, - emit->emit_buff_r, app->poly_order, app->basis_on_dev.basis, &app->basis, proj_buffer, - app->use_gpu); + emit->elastic_update = gkyl_bc_emission_elastic_new( + emit->params->elastic_model, emit->elastic_yield, emit->dir, emit->edge, cdim, vdim, + s->info.mass, s->f->ncomp, emit->emit_grid, emit->emit_buff_r, app->poly_order, + app->basis_on_dev.basis, &app->basis, proj_buffer, app->use_gpu + ); } // Initialize inelastic emission spectrums - for (int i=0; inum_species; ++i) { + for (int i = 0; i < emit->num_species; ++i) { emit->impact_species[i] = vm_find_species(app, emit->params->in_species[i]); emit->impact_grid[i] = &emit->impact_species[i]->bflux.boundary_grid[bdir]; - emit->flux_slvr[i] = gkyl_dg_updater_moment_new(emit->impact_grid[i], &app->confBasis, - &app->basis, NULL, NULL, NULL, emit->impact_species[i]->model_id, 0, GKYL_F_MOMENT_M0M1M2, true, - app->use_gpu); - - emit->impact_skin_r[i] = (emit->edge == GKYL_LOWER_EDGE) ? &emit->impact_species[i]->lower_skin[emit->dir] : &emit->impact_species[i]->upper_skin[emit->dir]; - emit->impact_ghost_r[i] = (emit->edge == GKYL_LOWER_EDGE) ? &emit->impact_species[i]->lower_ghost[emit->dir] : &emit->impact_species[i]->upper_ghost[emit->dir]; + emit->flux_slvr[i] = gkyl_dg_updater_moment_new( + emit->impact_grid[i], &app->confBasis, &app->basis, NULL, NULL, NULL, + emit->impact_species[i]->model_id, 0, GKYL_F_MOMENT_M0M1M2, true, app->use_gpu + ); + + emit->impact_skin_r[i] = (emit->edge == GKYL_LOWER_EDGE) ? + &emit->impact_species[i]->lower_skin[emit->dir] : + &emit->impact_species[i]->upper_skin[emit->dir]; + emit->impact_ghost_r[i] = (emit->edge == GKYL_LOWER_EDGE) ? + &emit->impact_species[i]->lower_ghost[emit->dir] : + &emit->impact_species[i]->upper_ghost[emit->dir]; emit->impact_buff_r[i] = &emit->impact_species[i]->bflux.flux_r[bdir]; emit->impact_cbuff_r[i] = &emit->impact_species[i]->bflux.conf_r[bdir]; emit->yield[i] = mkarr(app->use_gpu, app->basis.num_basis, emit->impact_buff_r[i]->volume); emit->spectrum[i] = mkarr(app->use_gpu, app->basis.num_basis, emit->emit_buff_r->volume); - emit->weight[i] = mkarr(app->use_gpu, app->confBasis.num_basis, - emit->impact_cbuff_r[i]->volume); + emit->weight[i] = + mkarr(app->use_gpu, app->confBasis.num_basis, emit->impact_cbuff_r[i]->volume); emit->flux[i] = mkarr(app->use_gpu, app->confBasis.num_basis, emit->impact_cbuff_r[i]->volume); emit->bflux_arr[i] = emit->impact_species[i]->bflux.flux_arr[bdir]; emit->k[i] = mkarr(app->use_gpu, app->confBasis.num_basis, emit->impact_cbuff_r[i]->volume); - gkyl_bc_emission_flux_ranges(&emit->impact_normal_r[i], emit->dir + cdim, - emit->impact_buff_r[i], ghost, emit->edge); - - emit->update[i] = gkyl_bc_emission_spectrum_new(emit->params->spectrum_model[i], - emit->params->yield_model[i], emit->yield[i], emit->spectrum[i], emit->dir, emit->edge, - cdim, vdim, emit->impact_species[i]->info.mass, s->info.mass, emit->impact_buff_r[i], - emit->emit_buff_r, emit->impact_grid[i], emit->emit_grid, app->poly_order, - &app->basis, proj_buffer, app->use_gpu); + gkyl_bc_emission_flux_ranges( + &emit->impact_normal_r[i], emit->dir + cdim, emit->impact_buff_r[i], ghost, emit->edge + ); + + emit->update[i] = gkyl_bc_emission_spectrum_new( + emit->params->spectrum_model[i], emit->params->yield_model[i], emit->yield[i], + emit->spectrum[i], emit->dir, emit->edge, cdim, vdim, emit->impact_species[i]->info.mass, + s->info.mass, emit->impact_buff_r[i], emit->emit_buff_r, emit->impact_grid[i], + emit->emit_grid, app->poly_order, &app->basis, proj_buffer, app->use_gpu + ); } gkyl_array_release(proj_buffer); } -void -vm_species_emission_apply_bc(struct gkyl_vlasov_app *app, const struct vm_emitting_wall *emit, - struct gkyl_array *fout, double tcurr) +void vm_species_emission_apply_bc( + struct gkyl_vlasov_app *app, const struct vm_emitting_wall *emit, struct gkyl_array *fout, + double tcurr +) { // Optional scaling of emission with time double t_scale = 1.0; - if (tcurr < emit->t_bound) - t_scale = sin(M_PI*tcurr/(2.0*emit->t_bound)); + if (tcurr < emit->t_bound) { + t_scale = sin(M_PI * tcurr / (2.0 * emit->t_bound)); + } gkyl_array_clear(emit->f_emit, 0.0); // Zero emitted distribution before beginning accumulate // Elastic emission contribution if (emit->elastic) { - gkyl_bc_emission_elastic_advance(emit->elastic_update, emit->emit_skin_r, emit->buffer, fout, - emit->f_emit, emit->elastic_yield, &app->basis); + gkyl_bc_emission_elastic_advance( + emit->elastic_update, emit->emit_skin_r, emit->buffer, fout, emit->f_emit, + emit->elastic_yield, &app->basis + ); } // Inelastic emission contribution - for (int i=0; inum_species; ++i) { + for (int i = 0; i < emit->num_species; ++i) { int species_idx; species_idx = vm_find_species_idx(app, emit->impact_species[i]->info.name); - gkyl_dg_updater_moment_advance(emit->flux_slvr[i], &emit->impact_normal_r[i], - emit->impact_cbuff_r[i], emit->bflux_arr[i], emit->flux[i]); - - gkyl_bc_emission_spectrum_advance(emit->update[i], emit->impact_buff_r[i], - emit->impact_cbuff_r[i], emit->emit_buff_r, emit->bflux_arr[i], - emit->f_emit, emit->yield[i], emit->spectrum[i], emit->weight[i], emit->flux[i], - emit->k[i]); + gkyl_dg_updater_moment_advance( + emit->flux_slvr[i], &emit->impact_normal_r[i], emit->impact_cbuff_r[i], emit->bflux_arr[i], + emit->flux[i] + ); + + gkyl_bc_emission_spectrum_advance( + emit->update[i], emit->impact_buff_r[i], emit->impact_cbuff_r[i], emit->emit_buff_r, + emit->bflux_arr[i], emit->f_emit, emit->yield[i], emit->spectrum[i], emit->weight[i], + emit->flux[i], emit->k[i] + ); } - gkyl_array_set_range_to_range(fout, t_scale, emit->f_emit, emit->emit_ghost_r, - emit->emit_buff_r); + gkyl_array_set_range_to_range(fout, t_scale, emit->f_emit, emit->emit_ghost_r, emit->emit_buff_r); } - // KB - The write function only works in 1x at the moment. // It expects a single rank to own the whole emit range. -void -vm_species_emission_write(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_emitting_wall *emit, struct gkyl_msgpack_data *mt, int frame) +void vm_species_emission_write( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_emitting_wall *emit, + struct gkyl_msgpack_data *mt, int frame +) { const char *fmt = (emit->edge == GKYL_LOWER_EDGE) ? "%s-%s_bc_lo_%d.gkyl" : "%s-%s_bc_up_%d.gkyl"; int sz = gkyl_calc_strlen(fmt, app->name, s->info.name, frame); - char fileNm[sz+1]; // ensures no buffer overflow + char fileNm[sz + 1]; // ensures no buffer overflow snprintf(fileNm, sizeof fileNm, fmt, app->name, s->info.name, frame); if (emit->write) { - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(emit->f_emit_host, emit->f_emit); + } gkyl_grid_sub_array_write(emit->emit_grid, emit->emit_buff_r, mt, emit->f_emit_host, fileNm); } } -void -vm_species_emission_release(const struct vm_emitting_wall *emit) +void vm_species_emission_release(const struct vm_emitting_wall *emit) { gkyl_array_release(emit->f_emit_host); gkyl_array_release(emit->f_emit); @@ -150,7 +167,7 @@ vm_species_emission_release(const struct vm_emitting_wall *emit) gkyl_array_release(emit->elastic_yield); gkyl_bc_emission_elastic_release(emit->elastic_update); } - for (int i=0; inum_species; ++i) { + for (int i = 0; i < emit->num_species; ++i) { gkyl_array_release(emit->yield[i]); gkyl_array_release(emit->spectrum[i]); gkyl_array_release(emit->weight[i]); diff --git a/vlasov/apps/vm_species_lbo.c b/vlasov/apps/vm_species_lbo.c index 87aef73fdd..2a70cd18f6 100644 --- a/vlasov/apps/vm_species_lbo.c +++ b/vlasov/apps/vm_species_lbo.c @@ -1,12 +1,13 @@ #include #include -void -vm_species_lbo_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_lbo_collisions *lbo) +void vm_species_lbo_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_lbo_collisions *lbo +) { int cdim = app->cdim, vdim = app->vdim; - double v_bounds[2*GKYL_MAX_DIM] = { 0.0 }; - for (int d=0; dinfo.lower[d]; v_bounds[d + vdim] = s->info.upper[d]; } @@ -17,9 +18,11 @@ vm_species_lbo_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm struct gkyl_array *self_nu = mkarr(false, app->confBasis.num_basis, app->local_ext.volume); lbo->num_cross_collisions = s->info.collisions.num_cross_collisions; - - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - app->poly_order+1, 1, s->info.collisions.self_nu, s->info.collisions.ctx); + + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->poly_order + 1, 1, s->info.collisions.self_nu, + s->info.collisions.ctx + ); gkyl_proj_on_basis_advance(proj, 0.0, &app->local, self_nu); gkyl_proj_on_basis_release(proj); gkyl_array_copy(lbo->self_nu, self_nu); @@ -33,8 +36,9 @@ vm_species_lbo_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm double nuFrac = s->info.collisions.nuFrac ? s->info.collisions.nuFrac : 1.0; double eps0 = app->field->info.epsilon0 ? app->field->info.epsilon0 : 1.0; double hbar = s->info.collisions.hbar ? s->info.collisions.hbar : 1.0; - lbo->spitzer_calc = gkyl_spitzer_coll_freq_new(&app->confBasis, app->poly_order+1, - nuFrac, eps0, hbar, app->use_gpu); + lbo->spitzer_calc = gkyl_spitzer_coll_freq_new( + &app->confBasis, app->poly_order + 1, nuFrac, eps0, hbar, app->use_gpu + ); // Create arrays for scaling collisionality by normalization factor // norm_nu is computed from Spitzer calc and is the normalization factor for the local // density and thermal velocity, norm_nu_sr = n/(vth_s^2 + vth_r^2)^(3/2) @@ -45,66 +49,85 @@ vm_species_lbo_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm gkyl_array_copy(lbo->nu_init, lbo->self_nu); } // Allocate needed arrays (boundary corrections, primitive moments, and nu*primitive moments) - lbo->boundary_corrections = mkarr(app->use_gpu, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); + lbo->boundary_corrections = + mkarr(app->use_gpu, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); - lbo->prim_moms = mkarr(app->use_gpu, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); - lbo->nu_prim_moms = mkarr(app->use_gpu, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); + lbo->prim_moms = + mkarr(app->use_gpu, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); + lbo->nu_prim_moms = + mkarr(app->use_gpu, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); lbo->m0 = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); // allocate moments needed for LBO update vm_species_moment_init(app, s, &lbo->moms, GKYL_F_MOMENT_M0M1M2, false); - // edge of velocity space corrections to momentum and energy - lbo->bcorr_calc = gkyl_mom_calc_bcorr_lbo_vlasov_new(&s->grid, - &app->confBasis, &app->basis, v_bounds, app->use_gpu); - + // edge of velocity space corrections to momentum and energy + lbo->bcorr_calc = gkyl_mom_calc_bcorr_lbo_vlasov_new( + &s->grid, &app->confBasis, &app->basis, v_bounds, app->use_gpu + ); + // primitive moment calculator - lbo->coll_pcalc = gkyl_prim_lbo_vlasov_calc_new(&s->grid, - &app->confBasis, &app->basis, &app->local, app->use_gpu); + lbo->coll_pcalc = gkyl_prim_lbo_vlasov_calc_new( + &s->grid, &app->confBasis, &app->basis, &app->local, app->use_gpu + ); // LBO updater - struct gkyl_dg_lbo_vlasov_drag_auxfields drag_inp = { .nuSum = lbo->nu_sum, .nuPrimMomsSum = lbo->nu_prim_moms }; - struct gkyl_dg_lbo_vlasov_diff_auxfields diff_inp = { .nuSum = lbo->nu_sum, .nuPrimMomsSum = lbo->nu_prim_moms }; - lbo->coll_slvr = gkyl_dg_updater_lbo_vlasov_new(&s->grid, - &app->confBasis, &app->basis, &app->local, &drag_inp, &diff_inp, app->use_gpu); + struct gkyl_dg_lbo_vlasov_drag_auxfields drag_inp = { + .nuSum = lbo->nu_sum, .nuPrimMomsSum = lbo->nu_prim_moms + }; + struct gkyl_dg_lbo_vlasov_diff_auxfields diff_inp = { + .nuSum = lbo->nu_sum, .nuPrimMomsSum = lbo->nu_prim_moms + }; + lbo->coll_slvr = gkyl_dg_updater_lbo_vlasov_new( + &s->grid, &app->confBasis, &app->basis, &app->local, &drag_inp, &diff_inp, app->use_gpu + ); } -void -vm_species_lbo_cross_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_lbo_collisions *lbo) +void vm_species_lbo_cross_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_lbo_collisions *lbo +) { int vdim = app->vdim; - lbo->cross_calc = gkyl_prim_lbo_vlasov_cross_calc_new(&s->grid, - &app->confBasis, &app->basis, &app->local, app->use_gpu); - - lbo->cross_nu_prim_moms = mkarr(app->use_gpu, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); + lbo->cross_calc = gkyl_prim_lbo_vlasov_cross_calc_new( + &s->grid, &app->confBasis, &app->basis, &app->local, app->use_gpu + ); + + lbo->cross_nu_prim_moms = + mkarr(app->use_gpu, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); lbo->greene_factor_mem = 0; - if (app->use_gpu) - lbo->greene_factor_mem = gkyl_dg_bin_op_mem_cu_dev_new(app->local.volume, app->confBasis.num_basis); - else + if (app->use_gpu) { + lbo->greene_factor_mem = + gkyl_dg_bin_op_mem_cu_dev_new(app->local.volume, app->confBasis.num_basis); + } else { lbo->greene_factor_mem = gkyl_dg_bin_op_mem_new(app->local.volume, app->confBasis.num_basis); + } // set pointers to species we cross-collide with - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < lbo->num_cross_collisions; ++i) { lbo->collide_with[i] = vm_find_species(app, s->info.collisions.collide_with[i]); lbo->other_m[i] = lbo->collide_with[i]->info.mass; lbo->other_prim_moms[i] = lbo->collide_with[i]->lbo.prim_moms; lbo->other_nu[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - lbo->cross_prim_moms[i] = mkarr(app->use_gpu, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); + lbo->cross_prim_moms[i] = + mkarr(app->use_gpu, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); lbo->cross_nu[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); lbo->greene_num[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); lbo->greene_den[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); lbo->greene_factor[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - + if (lbo->other_m[i] > s->info.mass) { gkyl_array_set(lbo->cross_nu[i], sqrt(2.0), lbo->self_nu); - gkyl_array_set(lbo->other_nu[i], sqrt(2.0)*(s->info.mass)/(lbo->other_m[i]), lbo->self_nu); + gkyl_array_set(lbo->other_nu[i], sqrt(2.0) * (s->info.mass) / (lbo->other_m[i]), lbo->self_nu); } else { - gkyl_array_set(lbo->cross_nu[i], sqrt(2.0)*(lbo->other_m[i])/(s->info.mass), lbo->collide_with[i]->lbo.self_nu); + gkyl_array_set( + lbo->cross_nu[i], sqrt(2.0) * (lbo->other_m[i]) / (s->info.mass), + lbo->collide_with[i]->lbo.self_nu + ); gkyl_array_set(lbo->other_nu[i], sqrt(2.0), lbo->collide_with[i]->lbo.self_nu); } - + gkyl_array_accumulate(lbo->nu_sum, 1.0, lbo->cross_nu[i]); lbo->other_mnu[i] = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); @@ -116,94 +139,110 @@ vm_species_lbo_cross_init(struct gkyl_vlasov_app *app, struct vm_species *s, str gkyl_array_set(lbo->self_mnu[i], s->info.mass, lbo->cross_nu[i]); gkyl_array_set(lbo->other_mnu[i], lbo->other_m[i], lbo->other_nu[i]); } - + lbo->betaGreenep1 = 1.0; } // computes moments, boundary corrections, and primitive moments -void -vm_species_lbo_moms(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_lbo_collisions *lbo, const struct gkyl_array *fin) +void vm_species_lbo_moms( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_lbo_collisions *lbo, + const struct gkyl_array *fin +) { struct timespec wst = gkyl_wall_clock(); // compute needed moments vm_species_moment_calc(&lbo->moms, species->local, app->local, fin); gkyl_array_set_range(lbo->m0, 1.0, lbo->moms.marr, &app->local); - + // construct boundary corrections - gkyl_mom_calc_bcorr_advance(lbo->bcorr_calc, - &species->local, &app->local, fin, lbo->boundary_corrections); + gkyl_mom_calc_bcorr_advance( + lbo->bcorr_calc, &species->local, &app->local, fin, lbo->boundary_corrections + ); - // construct primitive moments - gkyl_prim_lbo_calc_advance(lbo->coll_pcalc, &app->local, - lbo->moms.marr, lbo->boundary_corrections, lbo->self_nu, lbo->prim_moms); + // construct primitive moments + gkyl_prim_lbo_calc_advance( + lbo->coll_pcalc, &app->local, lbo->moms.marr, lbo->boundary_corrections, lbo->self_nu, + lbo->prim_moms + ); - for (int d=0; dvdim; d++) + for (int d = 0; d < app->vdim; d++) { gkyl_dg_mul_op(&app->confBasis, d, lbo->nu_prim_moms, d, lbo->prim_moms, 0, lbo->self_nu); - gkyl_dg_mul_op(&app->confBasis, app->vdim, lbo->nu_prim_moms, app->vdim, lbo->prim_moms, 0, lbo->self_nu); - - app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); + } + gkyl_dg_mul_op( + &app->confBasis, app->vdim, lbo->nu_prim_moms, app->vdim, lbo->prim_moms, 0, lbo->self_nu + ); + + app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); } // computes moments from cross-species collisions -void -vm_species_lbo_cross_moms(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_lbo_collisions *lbo, const struct gkyl_array *fin) +void vm_species_lbo_cross_moms( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_lbo_collisions *lbo, + const struct gkyl_array *fin +) { struct timespec wst = gkyl_wall_clock(); - - wst = gkyl_wall_clock(); - for (int i=0; inum_cross_collisions; ++i) { - gkyl_dg_mul_op_range(&app->confBasis, 0, lbo->self_mnu_m0[i], 0, - lbo->self_mnu[i], 0, lbo->m0, &app->local); - gkyl_dg_mul_op_range(&app->confBasis, 0, lbo->other_mnu_m0[i], 0, - lbo->other_mnu[i], 0, lbo->collide_with[i]->lbo.m0, &app->local); - gkyl_dg_mul_op_range(&app->confBasis, 0, lbo->greene_num[i], 0, - lbo->other_mnu_m0[i], 0, lbo->m0, &app->local); + wst = gkyl_wall_clock(); + for (int i = 0; i < lbo->num_cross_collisions; ++i) { + gkyl_dg_mul_op_range( + &app->confBasis, 0, lbo->self_mnu_m0[i], 0, lbo->self_mnu[i], 0, lbo->m0, &app->local + ); + gkyl_dg_mul_op_range( + &app->confBasis, 0, lbo->other_mnu_m0[i], 0, lbo->other_mnu[i], 0, + lbo->collide_with[i]->lbo.m0, &app->local + ); + + gkyl_dg_mul_op_range( + &app->confBasis, 0, lbo->greene_num[i], 0, lbo->other_mnu_m0[i], 0, lbo->m0, &app->local + ); gkyl_array_set(lbo->greene_den[i], 1.0, lbo->self_mnu_m0[i]); gkyl_array_accumulate(lbo->greene_den[i], 1.0, lbo->other_mnu_m0[i]); - gkyl_dg_div_op_range(lbo->greene_factor_mem, &app->confBasis, 0, lbo->greene_factor[i], 0, - lbo->greene_num[i], 0, lbo->greene_den[i], &app->local); - gkyl_array_scale(lbo->greene_factor[i], 2*lbo->betaGreenep1); - - gkyl_prim_lbo_cross_calc_advance(lbo->cross_calc, - &app->local, - lbo->greene_factor[i], - species->info.mass, lbo->moms.marr, lbo->prim_moms, - lbo->other_m[i], lbo->collide_with[i]->lbo.moms.marr, lbo->other_prim_moms[i], - lbo->boundary_corrections, lbo->cross_nu[i], - lbo->cross_prim_moms[i]); - - - for (int d=0; dvdim; d++) - gkyl_dg_mul_op(&app->confBasis, d, lbo->cross_nu_prim_moms, d, lbo->cross_prim_moms[i], 0, lbo->cross_nu[i]); - gkyl_dg_mul_op(&app->confBasis, app->vdim, lbo->cross_nu_prim_moms, app->vdim, lbo->cross_prim_moms[i], 0, lbo->cross_nu[i]); + gkyl_dg_div_op_range( + lbo->greene_factor_mem, &app->confBasis, 0, lbo->greene_factor[i], 0, lbo->greene_num[i], 0, + lbo->greene_den[i], &app->local + ); + gkyl_array_scale(lbo->greene_factor[i], 2 * lbo->betaGreenep1); + + gkyl_prim_lbo_cross_calc_advance( + lbo->cross_calc, &app->local, lbo->greene_factor[i], species->info.mass, lbo->moms.marr, + lbo->prim_moms, lbo->other_m[i], lbo->collide_with[i]->lbo.moms.marr, lbo->other_prim_moms[i], + lbo->boundary_corrections, lbo->cross_nu[i], lbo->cross_prim_moms[i] + ); + + for (int d = 0; d < app->vdim; d++) { + gkyl_dg_mul_op( + &app->confBasis, d, lbo->cross_nu_prim_moms, d, lbo->cross_prim_moms[i], 0, lbo->cross_nu[i] + ); + } + gkyl_dg_mul_op( + &app->confBasis, app->vdim, lbo->cross_nu_prim_moms, app->vdim, lbo->cross_prim_moms[i], 0, + lbo->cross_nu[i] + ); gkyl_array_accumulate(lbo->nu_prim_moms, 1.0, lbo->cross_nu_prim_moms); } - app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); + app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst); } // updates the collision terms in the rhs -void -vm_species_lbo_rhs(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_lbo_collisions *lbo, const struct gkyl_array *fin, struct gkyl_array *rhs) +void vm_species_lbo_rhs( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_lbo_collisions *lbo, + const struct gkyl_array *fin, struct gkyl_array *rhs +) { struct timespec wst = gkyl_wall_clock(); - + // accumulate update due to collisions onto rhs - gkyl_dg_updater_lbo_vlasov_advance(lbo->coll_slvr, &species->local, - fin, species->cflrate, rhs); - + gkyl_dg_updater_lbo_vlasov_advance(lbo->coll_slvr, &species->local, fin, species->cflrate, rhs); + app->stat.species_coll_tm += gkyl_time_diff_now_sec(wst); } -void -vm_species_lbo_release(const struct gkyl_vlasov_app *app, const struct vm_lbo_collisions *lbo) +void vm_species_lbo_release(const struct gkyl_vlasov_app *app, const struct vm_lbo_collisions *lbo) { gkyl_array_release(lbo->boundary_corrections); gkyl_array_release(lbo->prim_moms); @@ -226,7 +265,7 @@ vm_species_lbo_release(const struct gkyl_vlasov_app *app, const struct vm_lbo_co if (lbo->num_cross_collisions) { gkyl_dg_bin_op_mem_release(lbo->greene_factor_mem); gkyl_array_release(lbo->cross_nu_prim_moms); - for (int i=0; inum_cross_collisions; ++i) { + for (int i = 0; i < lbo->num_cross_collisions; ++i) { gkyl_array_release(lbo->cross_prim_moms[i]); gkyl_array_release(lbo->cross_nu[i]); gkyl_array_release(lbo->other_nu[i]); @@ -241,4 +280,4 @@ vm_species_lbo_release(const struct gkyl_vlasov_app *app, const struct vm_lbo_co gkyl_prim_lbo_cross_calc_release(lbo->cross_calc); } gkyl_dg_updater_lbo_vlasov_release(lbo->coll_slvr); - } +} diff --git a/vlasov/apps/vm_species_lte.c b/vlasov/apps/vm_species_lte.c index 1c73e940ba..ce6b06ece5 100644 --- a/vlasov/apps/vm_species_lte.c +++ b/vlasov/apps/vm_species_lte.c @@ -1,9 +1,10 @@ #include #include -void -vm_species_lte_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_lte *lte, - struct correct_all_moms_inp corr_inp) +void vm_species_lte_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_lte *lte, + struct correct_all_moms_inp corr_inp +) { int cdim = app->cdim, vdim = app->vdim; @@ -12,11 +13,11 @@ vm_species_lte_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm struct gkyl_vlasov_lte_proj_on_basis_inp inp_proj = { .phase_grid = &s->grid, - .vel_grid = &s->grid_vel, + .vel_grid = &s->grid_vel, .conf_basis = &app->confBasis, - .vel_basis = &app->velBasis, + .vel_basis = &app->velBasis, .phase_basis = &app->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .vel_range = &s->local_vel, .phase_range = &s->local, @@ -27,23 +28,23 @@ vm_species_lte_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm .det_h = s->det_h, .hamil = s->hamil, .model_id = s->model_id, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; - lte->proj_lte = gkyl_vlasov_lte_proj_on_basis_inew( &inp_proj ); + lte->proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_proj); lte->correct_all_moms = corr_inp.correct_all_moms; int max_iter = corr_inp.max_iter > 0 ? s->info.max_iter : 100; - double iter_eps = corr_inp.iter_eps > 0 ? s->info.iter_eps : 1e-12; + double iter_eps = corr_inp.iter_eps > 0 ? s->info.iter_eps : 1e-12; bool use_last_converged = corr_inp.use_last_converged; - + if (lte->correct_all_moms) { struct gkyl_vlasov_lte_correct_inp inp_corr = { .phase_grid = &s->grid, - .vel_grid = &s->grid_vel, + .vel_grid = &s->grid_vel, .conf_basis = &app->confBasis, - .vel_basis = &app->velBasis, + .vel_basis = &app->velBasis, .phase_basis = &app->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .vel_range = &s->local_vel, .phase_range = &s->local, @@ -57,10 +58,10 @@ vm_species_lte_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm .use_gpu = app->use_gpu, .max_iter = max_iter, .eps = iter_eps, - .use_last_converged = use_last_converged, + .use_last_converged = use_last_converged }; lte->niter = 0; - lte->corr_lte = gkyl_vlasov_lte_correct_inew( &inp_corr ); + lte->corr_lte = gkyl_vlasov_lte_correct_inew(&inp_corr); lte->corr_stat = gkyl_dynvec_new(GKYL_DOUBLE, 7); lte->is_first_corr_status_write_call = true; @@ -70,9 +71,10 @@ vm_species_lte_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm } // Compute f_lte from input LTE moments -void -vm_species_lte_from_moms(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_lte *lte, const struct gkyl_array *moms_lte) +void vm_species_lte_from_moms( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_lte *lte, + const struct gkyl_array *moms_lte +) { struct timespec wst = gkyl_wall_clock(); @@ -81,42 +83,44 @@ vm_species_lte_from_moms(gkyl_vlasov_app *app, const struct vm_species *species, // Project the LTE distribution function to obtain f_lte. // e.g., Maxwellian for non-relativistic and Maxwell-Juttner for relativistic. // Projection routine also corrects the density of the projected distribution function. - gkyl_vlasov_lte_proj_on_basis_advance(lte->proj_lte, &species->local, &app->local, - moms_lte, lte->f_lte); + gkyl_vlasov_lte_proj_on_basis_advance( + lte->proj_lte, &species->local, &app->local, moms_lte, lte->f_lte + ); // Correct all the moments of the projected LTE distribution function. if (lte->correct_all_moms) { struct gkyl_vlasov_lte_correct_status status_corr; - status_corr = gkyl_vlasov_lte_correct_all_moments(lte->corr_lte, lte->f_lte, moms_lte, - &species->local, &app->local); - double corr_vec[7] = { 0.0 }; + status_corr = gkyl_vlasov_lte_correct_all_moments( + lte->corr_lte, lte->f_lte, moms_lte, &species->local, &app->local + ); + double corr_vec[7] = {0.0}; corr_vec[0] = status_corr.num_iter; corr_vec[1] = status_corr.iter_converged; - for (int i=0; ivdim+2; ++i) { - corr_vec[2+i] = status_corr.error[i]; + for (int i = 0; i < app->vdim + 2; ++i) { + corr_vec[2 + i] = status_corr.error[i]; } - double corr_vec_global[7] = { 0.0 }; - gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 7, corr_vec, corr_vec_global); + double corr_vec_global[7] = {0.0}; + gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_MAX, 7, corr_vec, corr_vec_global); gkyl_dynvec_append(lte->corr_stat, app->tcurr, corr_vec_global); lte->niter += status_corr.num_iter; - } + } - app->stat.species_lte_tm += gkyl_time_diff_now_sec(wst); + app->stat.species_lte_tm += gkyl_time_diff_now_sec(wst); } // Compute equivalent f_lte from fin -void -vm_species_lte(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_lte *lte, const struct gkyl_array *fin) +void vm_species_lte( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_lte *lte, + const struct gkyl_array *fin +) { vm_species_moment_calc(<e->moms, species->local, app->local, fin); vm_species_lte_from_moms(app, species, lte, lte->moms.marr); } -void -vm_species_lte_release(const struct gkyl_vlasov_app *app, const struct vm_lte *lte) +void vm_species_lte_release(const struct gkyl_vlasov_app *app, const struct vm_lte *lte) { gkyl_array_release(lte->f_lte); diff --git a/vlasov/apps/vm_species_moment.c b/vlasov/apps/vm_species_moment.c index 29e65a249b..a09983bd01 100644 --- a/vlasov/apps/vm_species_moment.c +++ b/vlasov/apps/vm_species_moment.c @@ -3,9 +3,10 @@ #include // Initialize species moment object. -void -vm_species_moment_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct vm_species_moment *sm, enum gkyl_distribution_moments mom_type, bool is_integrated) +void vm_species_moment_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_species_moment *sm, + enum gkyl_distribution_moments mom_type, bool is_integrated +) { sm->is_integrated = is_integrated; @@ -14,11 +15,11 @@ vm_species_moment_init(struct gkyl_vlasov_app *app, struct vm_species *s, if (sm->is_vlasov_lte_moms) { struct gkyl_vlasov_lte_moments_inp inp_mom = { .phase_grid = &s->grid, - .vel_grid = &s->grid_vel, + .vel_grid = &s->grid_vel, .conf_basis = &app->confBasis, - .vel_basis = &app->velBasis, + .vel_basis = &app->velBasis, .phase_basis = &app->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .vel_range = &s->local_vel, .phase_range = &s->local, @@ -29,34 +30,36 @@ vm_species_moment_init(struct gkyl_vlasov_app *app, struct vm_species *s, .det_h = s->det_h, .hamil = s->hamil, .model_id = s->model_id, - .use_gpu = app->use_gpu, + .use_gpu = app->use_gpu }; // Compute (n, V_drift, T/m) sm->vlasov_lte_moms = gkyl_vlasov_lte_moments_inew(&inp_mom); num_mom = app->vdim + 2; - } - else { + } else { if (s->model_id == GKYL_MODEL_SR) { struct gkyl_mom_vlasov_sr_auxfields sr_inp = {.gamma = s->gamma}; - sm->mcalc = gkyl_dg_updater_moment_new(&s->grid, &app->confBasis, - &app->basis, &app->local, &s->local_vel, &s->local, s->model_id, &sr_inp, - mom_type, is_integrated, app->use_gpu); + sm->mcalc = gkyl_dg_updater_moment_new( + &s->grid, &app->confBasis, &app->basis, &app->local, &s->local_vel, &s->local, s->model_id, + &sr_inp, mom_type, is_integrated, app->use_gpu + ); num_mom = gkyl_dg_updater_moment_num_mom(sm->mcalc); - } else if ((s->model_id == GKYL_MODEL_CANONICAL_PB || s->model_id == GKYL_MODEL_CANONICAL_PB_GR) - && (mom_type == GKYL_F_MOMENT_M1_FROM_H || mom_type == GKYL_F_MOMENT_ENERGY - || (sm->is_integrated && mom_type == GKYL_F_MOMENT_M0M1M2))) { + } else if ((s->model_id == GKYL_MODEL_CANONICAL_PB || s->model_id == GKYL_MODEL_CANONICAL_PB_GR + ) && + (mom_type == GKYL_F_MOMENT_M1_FROM_H || mom_type == GKYL_F_MOMENT_ENERGY || + (sm->is_integrated && mom_type == GKYL_F_MOMENT_M0M1M2))) { struct gkyl_mom_canonical_pb_auxfields can_pb_inp = {.hamil = s->hamil}; - sm->mcalc = gkyl_dg_updater_moment_new(&s->grid, &app->confBasis, - &app->basis, &app->local, &s->local_vel, &s->local, s->model_id, &can_pb_inp, - mom_type, is_integrated, app->use_gpu); + sm->mcalc = gkyl_dg_updater_moment_new( + &s->grid, &app->confBasis, &app->basis, &app->local, &s->local_vel, &s->local, s->model_id, + &can_pb_inp, mom_type, is_integrated, app->use_gpu + ); + num_mom = gkyl_dg_updater_moment_num_mom(sm->mcalc); + } else { + // No auxiliary fields for moments if not SR + sm->mcalc = gkyl_dg_updater_moment_new( + &s->grid, &app->confBasis, &app->basis, &app->local, &s->local_vel, &s->local, s->model_id, + 0, mom_type, is_integrated, app->use_gpu + ); num_mom = gkyl_dg_updater_moment_num_mom(sm->mcalc); - } - else { - // No auxiliary fields for moments if not SR - sm->mcalc = gkyl_dg_updater_moment_new(&s->grid, &app->confBasis, - &app->basis, &app->local, &s->local_vel, &s->local, s->model_id, 0, - mom_type, is_integrated, app->use_gpu); - num_mom = gkyl_dg_updater_moment_num_mom(sm->mcalc); } } @@ -64,48 +67,40 @@ vm_species_moment_init(struct gkyl_vlasov_app *app, struct vm_species *s, sm->marr = mkarr(app->use_gpu, num_mom, app->local_ext.volume); sm->marr_host = sm->marr; if (app->use_gpu) { - sm->marr_host = mkarr(false, num_mom, app->local_ext.volume); + sm->marr_host = mkarr(false, num_mom, app->local_ext.volume); } - } - else { - sm->marr = mkarr(app->use_gpu, num_mom*app->confBasis.num_basis, - app->local_ext.volume); + } else { + sm->marr = mkarr(app->use_gpu, num_mom * app->confBasis.num_basis, app->local_ext.volume); sm->marr_host = sm->marr; if (app->use_gpu) { - sm->marr_host = mkarr(false, num_mom*app->confBasis.num_basis, - app->local_ext.volume); + sm->marr_host = mkarr(false, num_mom * app->confBasis.num_basis, app->local_ext.volume); } } } -void -vm_species_moment_calc(const struct vm_species_moment *sm, - const struct gkyl_range phase_rng, const struct gkyl_range conf_rng, - const struct gkyl_array *fin) +void vm_species_moment_calc( + const struct vm_species_moment *sm, const struct gkyl_range phase_rng, + const struct gkyl_range conf_rng, const struct gkyl_array *fin +) { if (sm->is_vlasov_lte_moms) { - gkyl_vlasov_lte_moments_advance(sm->vlasov_lte_moms, - &phase_rng, &conf_rng, fin, sm->marr); - } - else { - gkyl_dg_updater_moment_advance(sm->mcalc, - &phase_rng, &conf_rng, fin, sm->marr); + gkyl_vlasov_lte_moments_advance(sm->vlasov_lte_moms, &phase_rng, &conf_rng, fin, sm->marr); + } else { + gkyl_dg_updater_moment_advance(sm->mcalc, &phase_rng, &conf_rng, fin, sm->marr); } } // release memory for moment data object -void -vm_species_moment_release(const struct gkyl_vlasov_app *app, const struct vm_species_moment *sm) +void vm_species_moment_release(const struct gkyl_vlasov_app *app, const struct vm_species_moment *sm) { if (app->use_gpu) { gkyl_array_release(sm->marr_host); } gkyl_array_release(sm->marr); - if(sm->is_vlasov_lte_moms) { + if (sm->is_vlasov_lte_moms) { gkyl_vlasov_lte_moments_release(sm->vlasov_lte_moms); - } - else { + } else { gkyl_dg_updater_moment_release(sm->mcalc); } } diff --git a/vlasov/apps/vm_species_projection.c b/vlasov/apps/vm_species_projection.c index 5cd22f8218..8e7a3be7c0 100644 --- a/vlasov/apps/vm_species_projection.c +++ b/vlasov/apps/vm_species_projection.c @@ -1,80 +1,83 @@ #include #include -void -vm_species_projection_init(struct gkyl_vlasov_app *app, struct vm_species *s, - struct gkyl_vlasov_projection inp, struct vm_proj *proj) +void vm_species_projection_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct gkyl_vlasov_projection inp, + struct vm_proj *proj +) { proj->proj_id = inp.proj_id; proj->model_id = s->model_id; if (proj->proj_id == GKYL_PROJ_FUNC) { - proj->proj_func = gkyl_proj_on_basis_inew( &(struct gkyl_proj_on_basis_inp) { - .grid = &s->grid, - .basis = &app->basis, - .qtype = GKYL_GAUSS_QUAD, - .num_quad = app->basis.poly_order+1, - .num_ret_vals = 1, - .eval = inp.func, - .ctx = inp.ctx_func, - } - ); + proj->proj_func = gkyl_proj_on_basis_inew(&(struct gkyl_proj_on_basis_inp + ){.grid = &s->grid, + .basis = &app->basis, + .qtype = GKYL_GAUSS_QUAD, + .num_quad = app->basis.poly_order + 1, + .num_ret_vals = 1, + .eval = inp.func, + .ctx = inp.ctx_func}); if (app->use_gpu) { proj->proj_host = mkarr(false, app->basis.num_basis, s->local_ext.volume); } - } - else if (proj->proj_id == GKYL_PROJ_VLASOV_LTE) { - int vdim = app->vdim; + } else if (proj->proj_id == GKYL_PROJ_VLASOV_LTE) { + int vdim = app->vdim; proj->dens = mkarr(false, app->confBasis.num_basis, app->local_ext.volume); - proj->V_drift = mkarr(false, vdim*app->confBasis.num_basis, app->local_ext.volume); + proj->V_drift = mkarr(false, vdim * app->confBasis.num_basis, app->local_ext.volume); proj->T_over_m = mkarr(false, app->confBasis.num_basis, app->local_ext.volume); - proj->vlasov_lte_moms_host = mkarr(false, (vdim+2)*app->confBasis.num_basis, app->local_ext.volume); + proj->vlasov_lte_moms_host = + mkarr(false, (vdim + 2) * app->confBasis.num_basis, app->local_ext.volume); - proj->proj_dens = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - app->basis.poly_order+1, 1, inp.density, inp.ctx_density); - proj->proj_V_drift = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - app->basis.poly_order+1, vdim, inp.V_drift, inp.ctx_V_drift); - proj->proj_temp = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - app->basis.poly_order+1, 1, inp.temp, inp.ctx_temp); + proj->proj_dens = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->basis.poly_order + 1, 1, inp.density, inp.ctx_density + ); + proj->proj_V_drift = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->basis.poly_order + 1, vdim, inp.V_drift, inp.ctx_V_drift + ); + proj->proj_temp = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->basis.poly_order + 1, 1, inp.temp, inp.ctx_temp + ); - proj->vlasov_lte_moms = mkarr(app->use_gpu, (vdim+2)*app->confBasis.num_basis, app->local_ext.volume); + proj->vlasov_lte_moms = + mkarr(app->use_gpu, (vdim + 2) * app->confBasis.num_basis, app->local_ext.volume); struct gkyl_vlasov_lte_proj_on_basis_inp inp_proj = { .phase_grid = &s->grid, - .vel_grid = &s->grid_vel, + .vel_grid = &s->grid_vel, .conf_basis = &app->confBasis, - .vel_basis = &app->velBasis, + .vel_basis = &app->velBasis, .phase_basis = &app->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .vel_range = &s->local_vel, .phase_range = &s->local, .gamma = s->gamma, .gamma_inv = s->gamma_inv, - .h_ij = s->h_ij, - .h_ij_inv = s->h_ij_inv, + .h_ij = s->h_ij, + .h_ij_inv = s->h_ij_inv, .det_h = s->det_h, .hamil = s->hamil, .model_id = s->model_id, .use_gpu = app->use_gpu, .quad_type = inp.quad_type }; - proj->proj_lte = gkyl_vlasov_lte_proj_on_basis_inew( &inp_proj ); + proj->proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_proj); - proj->correct_all_moms = false; + proj->correct_all_moms = false; if (inp.correct_all_moms) { proj->correct_all_moms = true; int max_iter = inp.max_iter > 0 ? inp.max_iter : 100; - double iter_eps = inp.iter_eps > 0 ? inp.iter_eps : 1e-12; - bool use_last_converged = inp.use_last_converged; + double iter_eps = inp.iter_eps > 0 ? inp.iter_eps : 1e-12; + bool use_last_converged = inp.use_last_converged; struct gkyl_vlasov_lte_correct_inp inp_corr = { .phase_grid = &s->grid, - .vel_grid = &s->grid_vel, + .vel_grid = &s->grid_vel, .conf_basis = &app->confBasis, - .vel_basis = &app->velBasis, + .vel_basis = &app->velBasis, .phase_basis = &app->basis, - .conf_range = &app->local, + .conf_range = &app->local, .conf_range_ext = &app->local_ext, .vel_range = &s->local_vel, .phase_range = &s->local, @@ -89,66 +92,69 @@ vm_species_projection_init(struct gkyl_vlasov_app *app, struct vm_species *s, .quad_type = inp.quad_type, .max_iter = max_iter, .eps = iter_eps, - .use_last_converged = use_last_converged, + .use_last_converged = use_last_converged }; - proj->corr_lte = gkyl_vlasov_lte_correct_inew( &inp_corr ); + proj->corr_lte = gkyl_vlasov_lte_correct_inew(&inp_corr); } } } -void -vm_species_projection_calc(gkyl_vlasov_app *app, const struct vm_species *s, - struct vm_proj *proj, struct gkyl_array *f, double tm) +void vm_species_projection_calc( + gkyl_vlasov_app *app, const struct vm_species *s, struct vm_proj *proj, struct gkyl_array *f, + double tm +) { if (proj->proj_id == GKYL_PROJ_FUNC) { if (app->use_gpu) { gkyl_proj_on_basis_advance(proj->proj_func, tm, &s->local_ext, proj->proj_host); gkyl_array_copy(f, proj->proj_host); - } - else { + } else { gkyl_proj_on_basis_advance(proj->proj_func, tm, &s->local_ext, f); } - } - else if (proj->proj_id == GKYL_PROJ_VLASOV_LTE) { + } else if (proj->proj_id == GKYL_PROJ_VLASOV_LTE) { int vdim = app->vdim; - gkyl_proj_on_basis_advance(proj->proj_dens, tm, &app->local_ext, proj->dens); + gkyl_proj_on_basis_advance(proj->proj_dens, tm, &app->local_ext, proj->dens); gkyl_proj_on_basis_advance(proj->proj_V_drift, tm, &app->local_ext, proj->V_drift); gkyl_proj_on_basis_advance(proj->proj_temp, tm, &app->local_ext, proj->T_over_m); - gkyl_array_scale(proj->T_over_m, 1.0/s->info.mass); + gkyl_array_scale(proj->T_over_m, 1.0 / s->info.mass); // Projection routines expect the LTE moments as a single array. - gkyl_array_set_offset(proj->vlasov_lte_moms_host, 1.0, proj->dens, 0*app->confBasis.num_basis); - gkyl_array_set_offset(proj->vlasov_lte_moms_host, 1.0, proj->V_drift, 1*app->confBasis.num_basis); - gkyl_array_set_offset(proj->vlasov_lte_moms_host, 1.0, proj->T_over_m, (vdim+1)*app->confBasis.num_basis); + gkyl_array_set_offset(proj->vlasov_lte_moms_host, 1.0, proj->dens, 0 * app->confBasis.num_basis); + gkyl_array_set_offset( + proj->vlasov_lte_moms_host, 1.0, proj->V_drift, 1 * app->confBasis.num_basis + ); + gkyl_array_set_offset( + proj->vlasov_lte_moms_host, 1.0, proj->T_over_m, (vdim + 1) * app->confBasis.num_basis + ); // Copy the contents into the array we will use (potentially on GPUs). gkyl_array_copy(proj->vlasov_lte_moms, proj->vlasov_lte_moms_host); // Project the LTE distribution function. // Projection routine also corrects the density of the projected distribution function. - gkyl_vlasov_lte_proj_on_basis_advance(proj->proj_lte, &s->local, &app->local, - proj->vlasov_lte_moms, f); + gkyl_vlasov_lte_proj_on_basis_advance( + proj->proj_lte, &s->local, &app->local, proj->vlasov_lte_moms, f + ); // Correct all the moments of the projected LTE distribution function. if (proj->correct_all_moms) { - struct gkyl_vlasov_lte_correct_status status_corr = gkyl_vlasov_lte_correct_all_moments(proj->corr_lte, - f, proj->vlasov_lte_moms, &s->local, &app->local); - } - } + struct gkyl_vlasov_lte_correct_status status_corr = gkyl_vlasov_lte_correct_all_moments( + proj->corr_lte, f, proj->vlasov_lte_moms, &s->local, &app->local + ); + } + } } -void -vm_species_projection_release(const struct gkyl_vlasov_app *app, const struct vm_proj *proj) +void vm_species_projection_release(const struct gkyl_vlasov_app *app, const struct vm_proj *proj) { if (proj->proj_id == GKYL_PROJ_FUNC) { gkyl_proj_on_basis_release(proj->proj_func); if (app->use_gpu) { gkyl_array_release(proj->proj_host); } - } - else if (proj->proj_id == GKYL_PROJ_VLASOV_LTE) { + } else if (proj->proj_id == GKYL_PROJ_VLASOV_LTE) { gkyl_array_release(proj->dens); - gkyl_array_release(proj->V_drift); + gkyl_array_release(proj->V_drift); gkyl_array_release(proj->T_over_m); gkyl_array_release(proj->vlasov_lte_moms_host); gkyl_array_release(proj->vlasov_lte_moms); @@ -161,5 +167,5 @@ vm_species_projection_release(const struct gkyl_vlasov_app *app, const struct vm if (proj->correct_all_moms) { gkyl_vlasov_lte_correct_release(proj->corr_lte); } - } + } } diff --git a/vlasov/apps/vm_species_radiation.c b/vlasov/apps/vm_species_radiation.c index a8e04ed784..0de0b0c538 100644 --- a/vlasov/apps/vm_species_radiation.c +++ b/vlasov/apps/vm_species_radiation.c @@ -1,55 +1,64 @@ #include #include -void -vm_species_radiation_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_rad_drag *rad) +void vm_species_radiation_init( + struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_rad_drag *rad +) { int vdim = app->vdim; // allocate nu and initialize it rad->nu = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); struct gkyl_array *nu_host = mkarr(false, app->confBasis.num_basis, app->local_ext.volume); - - gkyl_proj_on_basis *proj_nu = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - app->poly_order+1, 1, s->info.radiation.nu, s->info.radiation.ctx_nu); + + gkyl_proj_on_basis *proj_nu = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->poly_order + 1, 1, s->info.radiation.nu, + s->info.radiation.ctx_nu + ); gkyl_proj_on_basis_advance(proj_nu, 0.0, &app->local, nu_host); gkyl_proj_on_basis_release(proj_nu); gkyl_array_copy(rad->nu, nu_host); gkyl_array_release(nu_host); // Using the LBO operator, which expects a vdim+1 primitive moments array - // Last array entry is T/m which is checked for positivity before applying drag operator. - rad->nu_rad_drag = mkarr(app->use_gpu, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); - struct gkyl_array *nu_rad_drag_host = mkarr(false, (vdim+1)*app->confBasis.num_basis, app->local_ext.volume); - - gkyl_proj_on_basis *proj_rad_drag = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, - app->poly_order+1, vdim+1, s->info.radiation.nu_rad_drag, s->info.radiation.ctx_nu_rad_drag); + // Last array entry is T/m which is checked for positivity before applying drag operator. + rad->nu_rad_drag = + mkarr(app->use_gpu, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); + struct gkyl_array *nu_rad_drag_host = + mkarr(false, (vdim + 1) * app->confBasis.num_basis, app->local_ext.volume); + + gkyl_proj_on_basis *proj_rad_drag = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->poly_order + 1, vdim + 1, s->info.radiation.nu_rad_drag, + s->info.radiation.ctx_nu_rad_drag + ); gkyl_proj_on_basis_advance(proj_rad_drag, 0.0, &app->local, nu_rad_drag_host); gkyl_proj_on_basis_release(proj_rad_drag); gkyl_array_copy(rad->nu_rad_drag, nu_rad_drag_host); gkyl_array_release(nu_rad_drag_host); // Radiation operator uses the LBO kernels, so create auxiliary field struct for LBO - struct gkyl_dg_lbo_vlasov_drag_auxfields drag_inp = { .nuSum = rad->nu, .nuPrimMomsSum = rad->nu_rad_drag }; - rad->rad_slvr = gkyl_dg_updater_rad_vlasov_new(&s->grid, - &app->confBasis, &app->basis, &app->local, &drag_inp, app->use_gpu); + struct gkyl_dg_lbo_vlasov_drag_auxfields drag_inp = { + .nuSum = rad->nu, .nuPrimMomsSum = rad->nu_rad_drag + }; + rad->rad_slvr = gkyl_dg_updater_rad_vlasov_new( + &s->grid, &app->confBasis, &app->basis, &app->local, &drag_inp, app->use_gpu + ); } -// updates the radiation terms in the rhs -void -vm_species_radiation_rhs(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_rad_drag *rad, const struct gkyl_array *fin, struct gkyl_array *rhs) -{ +// updates the radiation terms in the rhs +void vm_species_radiation_rhs( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_rad_drag *rad, + const struct gkyl_array *fin, struct gkyl_array *rhs +) +{ // accumulate update due to collisions onto rhs - gkyl_dg_updater_rad_vlasov_advance(rad->rad_slvr, &species->local, - fin, species->cflrate, rhs); + gkyl_dg_updater_rad_vlasov_advance(rad->rad_slvr, &species->local, fin, species->cflrate, rhs); } -void -vm_species_radiation_release(const struct gkyl_vlasov_app *app, const struct vm_rad_drag *rad) +void vm_species_radiation_release(const struct gkyl_vlasov_app *app, const struct vm_rad_drag *rad) { gkyl_array_release(rad->nu); gkyl_array_release(rad->nu_rad_drag); gkyl_dg_updater_rad_vlasov_release(rad->rad_slvr); - } +} diff --git a/vlasov/apps/vm_species_source.c b/vlasov/apps/vm_species_source.c index 9c8028d5d0..137a31282f 100644 --- a/vlasov/apps/vm_species_source.c +++ b/vlasov/apps/vm_species_source.c @@ -1,10 +1,9 @@ #include #include -void -vm_species_source_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_source *src) +void vm_species_source_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm_source *src) { - int vdim = app->vdim; + int vdim = app->vdim; src->calc_bflux = false; if (s->source_id == GKYL_BFLUX_SOURCE) { src->calc_bflux = true; @@ -14,10 +13,9 @@ vm_species_source_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct src->source_species = vm_find_species(app, s->info.source.source_species); src->source_species_idx = vm_find_species_idx(app, s->info.source.source_species); if (app->use_gpu) { - src->scale_ptr = gkyl_cu_malloc((vdim+2)*sizeof(double)); - } - else { - src->scale_ptr = gkyl_malloc((vdim+2)*sizeof(double)); + src->scale_ptr = gkyl_cu_malloc((vdim + 2) * sizeof(double)); + } else { + src->scale_ptr = gkyl_malloc((vdim + 2) * sizeof(double)); } } @@ -28,11 +26,11 @@ vm_species_source_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct src->source_host = mkarr(false, app->basis.num_basis, s->local_ext.volume); } src->scale_factor = 1.0; - + src->write_source = s->info.source.write_source; // optional flag to write out source src->num_sources = s->info.source.num_sources; - for (int k=0; kinfo.source.num_sources; k++) { + for (int k = 0; k < s->info.source.num_sources; k++) { vm_species_projection_init(app, s, s->info.source.projection[k], &src->proj_source[k]); } @@ -44,47 +42,46 @@ vm_species_source_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct // Allocate data and updaters for diagnostic moments. src->num_diag_moments = s->info.num_diag_moments; s->src.moms = gkyl_malloc(sizeof(struct vm_species_moment[src->num_diag_moments])); - for (int m=0; mnum_diag_moments; ++m) { + for (int m = 0; m < src->num_diag_moments; ++m) { vm_species_moment_init(app, s, &s->src.moms[m], s->info.diag_moments[m], false); } // Allocate data and updaters for integrated moments. vm_species_moment_init(app, s, &s->src.integ_moms, GKYL_F_MOMENT_M0M1M2, true); if (app->use_gpu) { - s->src.red_integ_diag = gkyl_cu_malloc(sizeof(double[vdim+2])); - s->src.red_integ_diag_global = gkyl_cu_malloc(sizeof(double[vdim+2])); - } - else { - s->src.red_integ_diag = gkyl_malloc(sizeof(double[vdim+2])); - s->src.red_integ_diag_global = gkyl_malloc(sizeof(double[vdim+2])); + s->src.red_integ_diag = gkyl_cu_malloc(sizeof(double[vdim + 2])); + s->src.red_integ_diag_global = gkyl_cu_malloc(sizeof(double[vdim + 2])); + } else { + s->src.red_integ_diag = gkyl_malloc(sizeof(double[vdim + 2])); + s->src.red_integ_diag_global = gkyl_malloc(sizeof(double[vdim + 2])); } - // allocate dynamic-vector to store all-reduced integrated moments - s->src.integ_diag = gkyl_dynvec_new(GKYL_DOUBLE, vdim+2); + // allocate dynamic-vector to store all-reduced integrated moments + s->src.integ_diag = gkyl_dynvec_new(GKYL_DOUBLE, vdim + 2); s->src.is_first_integ_write_call = true; } -void -vm_species_source_calc(gkyl_vlasov_app *app, struct vm_species *s, - struct vm_source *src, double tm) +void vm_species_source_calc( + gkyl_vlasov_app *app, struct vm_species *s, struct vm_source *src, double tm +) { if (s->source_id) { if (src->num_sources > 1) { gkyl_array_clear(src->source, 0.0); - for (int k=0; knum_sources; k++) { + for (int k = 0; k < src->num_sources; k++) { vm_species_projection_calc(app, s, &src->proj_source[k], src->source_tmp, tm); gkyl_array_accumulate(src->source, 1.0, src->source_tmp); } - } - else { + } else { vm_species_projection_calc(app, s, &src->proj_source[0], src->source, tm); } } } // computes rhs of the boundary flux -void -vm_species_source_rhs(gkyl_vlasov_app *app, const struct vm_species *species, - struct vm_source *src, const struct gkyl_array *fin[], struct gkyl_array *rhs[]) +void vm_species_source_rhs( + gkyl_vlasov_app *app, const struct vm_species *species, struct vm_source *src, + const struct gkyl_array *fin[], struct gkyl_array *rhs[] +) { int species_idx; species_idx = vm_find_species_idx(app, species->info.name); @@ -92,36 +89,33 @@ vm_species_source_rhs(gkyl_vlasov_app *app, const struct vm_species *species, if (src->calc_bflux) { src->scale_factor = 0.0; double z[app->confBasis.num_basis]; - double red_mom[1] = { 0.0 }; + double red_mom[1] = {0.0}; - for (int d=0; dcdim; ++d) { - gkyl_array_reduce(src->scale_ptr, src->source_species->bflux.mom_arr[2*d], GKYL_SUM); + for (int d = 0; d < app->cdim; ++d) { + gkyl_array_reduce(src->scale_ptr, src->source_species->bflux.mom_arr[2 * d], GKYL_SUM); if (app->use_gpu) { gkyl_cu_memcpy(red_mom, src->scale_ptr, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { red_mom[0] = src->scale_ptr[0]; } - double red_mom_global[1] = { 0.0 }; + double red_mom_global[1] = {0.0}; gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, red_mom, red_mom_global); src->scale_factor += red_mom_global[0]; - gkyl_array_reduce(src->scale_ptr, src->source_species->bflux.mom_arr[2*d+1], GKYL_SUM); + gkyl_array_reduce(src->scale_ptr, src->source_species->bflux.mom_arr[2 * d + 1], GKYL_SUM); if (app->use_gpu) { gkyl_cu_memcpy(red_mom, src->scale_ptr, sizeof(double), GKYL_CU_MEMCPY_D2H); - } - else { + } else { red_mom[0] = src->scale_ptr[0]; } gkyl_comm_allreduce_host(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, red_mom, red_mom_global); src->scale_factor += red_mom_global[0]; } - src->scale_factor = src->scale_factor/src->source_length; + src->scale_factor = src->scale_factor / src->source_length; } gkyl_array_accumulate(rhs[species_idx], src->scale_factor, src->source); } -void -vm_species_source_release(const struct gkyl_vlasov_app *app, const struct vm_source *src) +void vm_species_source_release(const struct gkyl_vlasov_app *app, const struct vm_source *src) { gkyl_array_release(src->source); @@ -132,13 +126,12 @@ vm_species_source_release(const struct gkyl_vlasov_app *app, const struct vm_sou if (src->calc_bflux) { if (app->use_gpu) { gkyl_cu_free(src->scale_ptr); - } - else { + } else { gkyl_free(src->scale_ptr); } } - for (int k=0; knum_sources; k++) { + for (int k = 0; k < src->num_sources; k++) { vm_species_projection_release(app, &src->proj_source[k]); } @@ -147,18 +140,17 @@ vm_species_source_release(const struct gkyl_vlasov_app *app, const struct vm_sou } // Release moment data. - for (int i=0; inum_diag_moments; ++i) { + for (int i = 0; i < src->num_diag_moments; ++i) { vm_species_moment_release(app, &src->moms[i]); } gkyl_free(src->moms); - vm_species_moment_release(app, &src->integ_moms); + vm_species_moment_release(app, &src->integ_moms); if (app->use_gpu) { gkyl_cu_free(src->red_integ_diag); gkyl_cu_free(src->red_integ_diag_global); - } - else { + } else { gkyl_free(src->red_integ_diag); gkyl_free(src->red_integ_diag_global); - } - gkyl_dynvec_release(src->integ_diag); + } + gkyl_dynvec_release(src->integ_diag); } diff --git a/vlasov/apps/vp_field.c b/vlasov/apps/vp_field.c index b85a25ed49..8b566d3e02 100644 --- a/vlasov/apps/vp_field.c +++ b/vlasov/apps/vp_field.c @@ -9,24 +9,23 @@ #include #include -void -vp_field_calc_ext_pot(gkyl_vlasov_app *app, struct vm_field *field, double tm) +void vp_field_calc_ext_pot(gkyl_vlasov_app *app, struct vm_field *field, double tm) { gkyl_eval_on_nodes_advance(field->ext_pot_proj, tm, &app->local, field->ext_pot_host); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(field->ext_pot, field->ext_pot_host); + } } -void -vp_field_calc_ext_em(gkyl_vlasov_app *app, struct vm_field *field, double tm) +void vp_field_calc_ext_em(gkyl_vlasov_app *app, struct vm_field *field, double tm) { gkyl_proj_on_basis_advance(field->ext_em_proj, tm, &app->local, field->ext_em_host); - if (app->use_gpu) + if (app->use_gpu) { gkyl_array_copy(field->ext_em, field->ext_em_host); + } } -struct vm_field* -vp_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) +struct vm_field *vp_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) { // Initialize field object. struct vm_field *vpf = gkyl_malloc(sizeof(struct vm_field)); @@ -34,16 +33,16 @@ vp_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) vpf->info = vm->field; // Allocate arrays for charge density. - vpf->rho_c = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); + vpf->rho_c = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); vpf->rho_c_global = mkarr(app->use_gpu, app->confBasis.num_basis, app->global_ext.volume); // Allocate arrays for electrostatic potential. - vpf->phi = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); + vpf->phi = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); vpf->phi_global = mkarr(app->use_gpu, app->confBasis.num_basis, app->global_ext.volume); // Host potential for I/O. - vpf->phi_host = app->use_gpu? mkarr(false, app->confBasis.num_basis, app->local_ext.volume) - : gkyl_array_acquire(vpf->phi); + vpf->phi_host = app->use_gpu ? mkarr(false, app->confBasis.num_basis, app->local_ext.volume) : + gkyl_array_acquire(vpf->phi); // Create global subrange we'll copy the field solver solution from (into local). int intersect = gkyl_sub_range_intersect(&vpf->global_sub_range, &app->global, &app->local); @@ -51,11 +50,13 @@ vp_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) // Set the permittivity in the Poisson equation. vpf->epsilon = mkarr(app->use_gpu, app->confBasis.num_basis, app->global_ext.volume); gkyl_array_clear(vpf->epsilon, 0.0); - gkyl_array_shiftc(vpf->epsilon, vpf->info.epsilon0*pow(sqrt(2.0),app->cdim), 0); + gkyl_array_shiftc(vpf->epsilon, vpf->info.epsilon0 * pow(sqrt(2.0), app->cdim), 0); // Create Poisson solver. - vpf->fem_poisson = gkyl_fem_poisson_new(&app->global, &app->grid, app->confBasis, - &vpf->info.poisson_bcs, NULL, vpf->epsilon, NULL, true, app->use_gpu); + vpf->fem_poisson = gkyl_fem_poisson_new( + &app->global, &app->grid, app->confBasis, &vpf->info.poisson_bcs, NULL, vpf->epsilon, NULL, + true, app->use_gpu + ); vpf->field_id = GKYL_FIELD_PHI; @@ -64,30 +65,37 @@ vp_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) if (vpf->info.external_potentials) { vpf->has_ext_pot = true; vpf->field_id = GKYL_FIELD_PHI_EXT_POTENTIALS; - if (vpf->info.external_potentials_evolve) + if (vpf->info.external_potentials_evolve) { vpf->ext_pot_evolve = vpf->info.external_potentials_evolve; + } - vpf->ext_pot = mkarr(app->use_gpu, 4*app->confBasis.num_basis, app->local_ext.volume); - vpf->ext_pot_host = app->use_gpu? mkarr(false, vpf->ext_pot->ncomp, vpf->ext_pot->size) - : gkyl_array_acquire(vpf->ext_pot); + vpf->ext_pot = mkarr(app->use_gpu, 4 * app->confBasis.num_basis, app->local_ext.volume); + vpf->ext_pot_host = app->use_gpu ? mkarr(false, vpf->ext_pot->ncomp, vpf->ext_pot->size) : + gkyl_array_acquire(vpf->ext_pot); - vpf->ext_pot_proj = gkyl_eval_on_nodes_new(&app->grid, &app->confBasis, - 4, vpf->info.external_potentials, vpf->info.external_potentials_ctx); + vpf->ext_pot_proj = gkyl_eval_on_nodes_new( + &app->grid, &app->confBasis, 4, vpf->info.external_potentials, + vpf->info.external_potentials_ctx + ); } // Initialize external E and B fields. - vpf->ext_em = mkarr(app->use_gpu, 6*app->confBasis.num_basis, app->local_ext.volume); + vpf->ext_em = mkarr(app->use_gpu, 6 * app->confBasis.num_basis, app->local_ext.volume); vpf->has_ext_em = vpf->ext_em_evolve = false; if (vpf->info.ext_em) { vpf->has_ext_em = true; vpf->field_id = GKYL_FIELD_PHI_EXT_FIELDS; - if (vpf->info.ext_em_evolve) + if (vpf->info.ext_em_evolve) { vpf->ext_em_evolve = vpf->info.ext_em_evolve; + } - vpf->ext_em_host = app->use_gpu? mkarr(false, 6*app->confBasis.num_basis, app->local_ext.volume) - : gkyl_array_acquire(vpf->ext_em); - vpf->ext_em_proj = gkyl_proj_on_basis_new(&app->grid, &app->confBasis, app->confBasis.poly_order+1, - 6, vpf->info.ext_em, vpf->info.ext_em_ctx); + vpf->ext_em_host = app->use_gpu ? + mkarr(false, 6 * app->confBasis.num_basis, app->local_ext.volume) : + gkyl_array_acquire(vpf->ext_em); + vpf->ext_em_proj = gkyl_proj_on_basis_new( + &app->grid, &app->confBasis, app->confBasis.poly_order + 1, 6, vpf->info.ext_em, + vpf->info.ext_em_ctx + ); } // Vlasov-Poisson doesn't presently use external currents or limiters. @@ -105,24 +113,25 @@ vp_field_new(struct gkyl_vm *vm, struct gkyl_vlasov_app *app) vpf->integ_energy = gkyl_dynvec_new(GKYL_DOUBLE, 1); vpf->es_energy_fac = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume); - gkyl_array_shiftc(vpf->es_energy_fac, pow(sqrt(2.0),app->cdim), 0); // Sets es_energy_fac=1. + gkyl_array_shiftc(vpf->es_energy_fac, pow(sqrt(2.0), app->cdim), 0); // Sets es_energy_fac=1. - vpf->calc_es_energy = gkyl_array_integrate_new(&app->grid, &app->confBasis, - 1, GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ, app->use_gpu); + vpf->calc_es_energy = gkyl_array_integrate_new( + &app->grid, &app->confBasis, 1, GKYL_ARRAY_INTEGRATE_OP_GRAD_SQ, app->use_gpu + ); vpf->is_first_energy_write_call = true; return vpf; } -void -vp_field_accumulate_charge_dens(gkyl_vlasov_app *app, struct vm_field *field, - const struct gkyl_array *fin[]) +void vp_field_accumulate_charge_dens( + gkyl_vlasov_app *app, struct vm_field *field, const struct gkyl_array *fin[] +) { // Calcualte the charge density. gkyl_array_clear(field->rho_c, 0.0); - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct vm_species *s = &app->species[i]; vm_species_moment_calc(&s->m0, s->local, app->local, fin[i]); @@ -131,8 +140,7 @@ vp_field_accumulate_charge_dens(gkyl_vlasov_app *app, struct vm_field *field, } } -void -vp_field_solve(gkyl_vlasov_app *app, struct vm_field *field) +void vp_field_solve(gkyl_vlasov_app *app, struct vm_field *field) { // Compute the electrostatic potential. @@ -145,17 +153,21 @@ vp_field_solve(gkyl_vlasov_app *app, struct vm_field *field) gkyl_fem_poisson_solve(field->fem_poisson, field->phi_global); // Copy the portion of global potential corresponding to this MPI pcross to the local potential. - gkyl_array_copy_range_to_range(field->phi, field->phi_global, &app->local, &field->global_sub_range); - + gkyl_array_copy_range_to_range( + field->phi, field->phi_global, &app->local, &field->global_sub_range + ); + app->stat.field_rhs_tm += gkyl_time_diff_now_sec(wst); } -void -vp_field_apply_ic(gkyl_vlasov_app *app, struct vm_field *field, - const struct gkyl_array *fin[], double t0) +void vp_field_apply_ic( + gkyl_vlasov_app *app, struct vm_field *field, const struct gkyl_array *fin[], double t0 +) { - if (!app->has_field) return; - + if (!app->has_field) { + return; + } + // Compute electrostatic potential from Poisson's equation. vp_field_accumulate_charge_dens(app, field, fin); @@ -163,37 +175,43 @@ vp_field_apply_ic(gkyl_vlasov_app *app, struct vm_field *field, vp_field_solve(app, field); // Pre-compute external potentials and/or fields. - if (field->has_ext_pot) + if (field->has_ext_pot) { vp_field_calc_ext_pot(app, field, t0); + } if (field->has_ext_em) { vp_field_calc_ext_em(app, field, t0); // Pass ext_em to the species now in case is time independent. - for (int i=0; inum_species; ++i) { + for (int i = 0; i < app->num_species; ++i) { struct vm_species *s = &app->species[i]; gkyl_array_set_range(s->qmem_ext, s->qbym, field->ext_em, &app->local); } } } -void -vp_field_calc_energy(gkyl_vlasov_app *app, double tm, const struct vm_field *field) +void vp_field_calc_energy(gkyl_vlasov_app *app, double tm, const struct vm_field *field) { - gkyl_array_integrate_advance(field->calc_es_energy, field->phi, - app->grid.cellVolume, field->es_energy_fac, &app->local, &app->local, field->es_energy_red); + gkyl_array_integrate_advance( + field->calc_es_energy, field->phi, app->grid.cellVolume, field->es_energy_fac, &app->local, + &app->local, field->es_energy_red + ); - gkyl_comm_allreduce(app->comm, GKYL_DOUBLE, GKYL_SUM, 1, field->es_energy_red, field->es_energy_red_global); + gkyl_comm_allreduce( + app->comm, GKYL_DOUBLE, GKYL_SUM, 1, field->es_energy_red, field->es_energy_red_global + ); - double energy_global[1] = { 0.0 }; - if (app->use_gpu) - gkyl_cu_memcpy(energy_global, field->es_energy_red_global, sizeof(double[1]), GKYL_CU_MEMCPY_D2H); - else + double energy_global[1] = {0.0}; + if (app->use_gpu) { + gkyl_cu_memcpy( + energy_global, field->es_energy_red_global, sizeof(double[1]), GKYL_CU_MEMCPY_D2H + ); + } else { energy_global[0] = field->es_energy_red_global[0]; + } gkyl_dynvec_append(field->integ_energy, tm, energy_global); } - -void -vp_field_release(const gkyl_vlasov_app* app, struct vm_field *vpf) + +void vp_field_release(const gkyl_vlasov_app *app, struct vm_field *vpf) { // Release resources for Vlasov-Poisson field. diff --git a/vlasov/creg/rt_arg_parse.h b/vlasov/creg/rt_arg_parse.h index ac622fc504..ac9855fda7 100644 --- a/vlasov/creg/rt_arg_parse.h +++ b/vlasov/creg/rt_arg_parse.h @@ -17,7 +17,7 @@ struct gkyl_app_args { bool use_gpu; // should this be run on GPU? - bool use_mpi; // should this be run on MPI? + bool use_mpi; // should this be run on MPI? bool step_mode; // run for fixed number of steps? (for valgrind/cuda-memcheck) bool trace_mem; // should we trace memory allocation/deallocations? int num_steps; // number of steps @@ -26,7 +26,8 @@ struct gkyl_app_args { int vcells[3]; // velocity space cells int cuts[3]; // domain decomposition "cuts" char file_name[1024]; // name of input file - char app_name[128]; // basename of argv[0] — use with snprintf/strcpy to set char[] name fields (cannot assign directly in compound literals) + char app_name + [128]; // basename of argv[0] — use with snprintf/strcpy to set char[] name fields (cannot assign directly in compound literals) enum gkyl_basis_type basis_type; // type of basis functions to use enum gkyl_mp_recon mp_recon; // the XX in MP-XX bool skip_limiters; // should we skip limiters? @@ -35,45 +36,36 @@ struct gkyl_app_args { char opt_args[128]; // optional arguments }; -static int -get_basis_type(const char *nm) +static int get_basis_type(const char *nm) { if (strcmp(nm, "ms") == 0) { return GKYL_BASIS_MODAL_SERENDIPITY; - } - else if (strcmp(nm, "mt") == 0) { + } else if (strcmp(nm, "mt") == 0) { return GKYL_BASIS_MODAL_TENSOR; } return -1; } -static int -get_mp_recon_type(const char *nm) +static int get_mp_recon_type(const char *nm) { if (strcmp(nm, "u1") == 0) { return GKYL_MP_U1; - } - else if (strcmp(nm, "u3") == 0) { + } else if (strcmp(nm, "u3") == 0) { return GKYL_MP_U3; - } - else if (strcmp(nm, "u5") == 0) { + } else if (strcmp(nm, "u5") == 0) { return GKYL_MP_U5; - } - else if (strcmp(nm, "c2") == 0) { + } else if (strcmp(nm, "c2") == 0) { return GKYL_MP_C2; - } - else if (strcmp(nm, "c4") == 0) { + } else if (strcmp(nm, "c4") == 0) { return GKYL_MP_C4; - } - else if (strcmp(nm, "c6") == 0) { + } else if (strcmp(nm, "c6") == 0) { return GKYL_MP_C6; - } - + } + return -1; } -static struct gkyl_app_args -parse_app_args(int argc, char **argv) +static struct gkyl_app_args parse_app_args(int argc, char **argv) { bool use_gpu = false; bool use_mpi = false; @@ -85,134 +77,130 @@ parse_app_args(int argc, char **argv) int num_steps = INT_MAX; int num_threads = 1; // by default use only 1 thread - struct gkyl_app_args args = { - .xcells = { 0 }, - .vcells = { 0 }, - .cuts = { 1, 1, 1 }, - }; + struct gkyl_app_args args = {.xcells = {0}, .vcells = {0}, .cuts = {1, 1, 1}}; strcpy(args.file_name, APP_ARGS_DEFAULT_FILE_NAME); // default args.basis_type = GKYL_BASIS_MODAL_SERENDIPITY; int c; while ((c = getopt(argc, argv, "+hjgmMt:s:i:b:x:y:z:u:v:w:r:c:d:e:o:")) != -1) { - switch (c) - { - case 'h': - printf("Usage: -g -m -s nsteps -t nthreads -i inp -b [ms|mt] -x NX -y NY -z NZ -u VX -v VY -w VZ\n"); - printf(" All flags and parameters are optional.\n"); - printf(" -g Run on GPUs if GPUs are present and code built for GPUs\n"); - printf(" -M Run with MPI if code built with MPI\n"); - printf(" -sN Only run N steps of simulation\n"); - printf(" -tN Use N threads (when available)\n"); - printf(" -b Basis function to use (ms: Modal serendipity; mt: Modal tensor-product)\n"); - printf(" (Ignored for finite-volume solvers)\n"); - printf(" -j Recovery scheme. One of u1, u3, u5, c2, c4, c6\n"); - printf(" (Only used for MP-XX solvers)\n"); - printf(" -l Turn off limiters\n"); - printf(" -rN Restart the simulation from frame N\n"); - printf(" -m Turn on memory allocation/deallocation tracing\n"); - printf(" -o Optional arguments (as string, requires parsing)\n"); - printf("\n"); - printf(" Grid resolution in configuration space:\n"); - printf(" -xNX -yNY -zNZ\n"); - printf(" Grid resolution in velocity space:\n"); - printf(" -uVX -vVY -wVZ\n"); - printf(" Domain decomposition in each direction:\n"); - printf(" -cPX -dPY -ePZ\n"); - exit(-1); - break; - - case 'g': - use_gpu = true; - break; - - case 'M': - use_mpi = true; - break; - - case 'm': - trace_mem = true; - break; - - case 'l': - skip_limiters = true; - break; - - case 'r': - is_restart = true; - restart_frame = atoi(optarg); - break; - - case 's': - step_mode = true; - num_steps = atoi(optarg); - break; - - case 't': - num_threads = atoi(optarg); - break; - - case 'c': - args.cuts[0] = atoi(optarg); - break; - - case 'd': - args.cuts[1] = atoi(optarg); - break; - - case 'e': - args.cuts[2] = atoi(optarg); - break; - - case 'x': - args.xcells[0] = atoi(optarg); - break; - - case 'y': - args.xcells[1] = atoi(optarg); - break; - - case 'z': - args.xcells[2] = atoi(optarg); - break; - - case 'u': - args.vcells[0] = atoi(optarg); - break; - - case 'v': - args.vcells[1] = atoi(optarg); - break; - - case 'w': - args.vcells[2] = atoi(optarg); - break; - - case 'i': - strcpy(args.file_name, optarg); - break; - - case 'b': - args.basis_type = get_basis_type(optarg); - assert(args.basis_type != -1); - break; - - case 'j': - args.mp_recon = get_mp_recon_type(optarg); - assert(args.mp_recon != -1); - break; - - case 'o': - assert(strlen(optarg) < sizeof(args.opt_args)); - strcpy(args.opt_args, optarg); - break; - - case '?': - break; + switch (c) { + case 'h': + printf("Usage: -g -m -s nsteps -t nthreads -i inp -b [ms|mt] -x NX -y NY -z NZ -u " + "VX -v VY -w VZ\n"); + printf(" All flags and parameters are optional.\n"); + printf(" -g Run on GPUs if GPUs are present and code built for GPUs\n"); + printf(" -M Run with MPI if code built with MPI\n"); + printf(" -sN Only run N steps of simulation\n"); + printf(" -tN Use N threads (when available)\n"); + printf(" -b Basis function to use (ms: Modal serendipity; mt: Modal tensor-product)\n"); + printf(" (Ignored for finite-volume solvers)\n"); + printf(" -j Recovery scheme. One of u1, u3, u5, c2, c4, c6\n"); + printf(" (Only used for MP-XX solvers)\n"); + printf(" -l Turn off limiters\n"); + printf(" -rN Restart the simulation from frame N\n"); + printf(" -m Turn on memory allocation/deallocation tracing\n"); + printf(" -o Optional arguments (as string, requires parsing)\n"); + printf("\n"); + printf(" Grid resolution in configuration space:\n"); + printf(" -xNX -yNY -zNZ\n"); + printf(" Grid resolution in velocity space:\n"); + printf(" -uVX -vVY -wVZ\n"); + printf(" Domain decomposition in each direction:\n"); + printf(" -cPX -dPY -ePZ\n"); + exit(-1); + break; + + case 'g': + use_gpu = true; + break; + + case 'M': + use_mpi = true; + break; + + case 'm': + trace_mem = true; + break; + + case 'l': + skip_limiters = true; + break; + + case 'r': + is_restart = true; + restart_frame = atoi(optarg); + break; + + case 's': + step_mode = true; + num_steps = atoi(optarg); + break; + + case 't': + num_threads = atoi(optarg); + break; + + case 'c': + args.cuts[0] = atoi(optarg); + break; + + case 'd': + args.cuts[1] = atoi(optarg); + break; + + case 'e': + args.cuts[2] = atoi(optarg); + break; + + case 'x': + args.xcells[0] = atoi(optarg); + break; + + case 'y': + args.xcells[1] = atoi(optarg); + break; + + case 'z': + args.xcells[2] = atoi(optarg); + break; + + case 'u': + args.vcells[0] = atoi(optarg); + break; + + case 'v': + args.vcells[1] = atoi(optarg); + break; + + case 'w': + args.vcells[2] = atoi(optarg); + break; + + case 'i': + strcpy(args.file_name, optarg); + break; + + case 'b': + args.basis_type = get_basis_type(optarg); + assert(args.basis_type != -1); + break; + + case 'j': + args.mp_recon = get_mp_recon_type(optarg); + assert(args.mp_recon != -1); + break; + + case 'o': + assert(strlen(optarg) < sizeof(args.opt_args)); + strcpy(args.opt_args, optarg); + break; + + case '?': + break; } } - + args.use_gpu = use_gpu; args.use_mpi = use_mpi; args.trace_mem = trace_mem; diff --git a/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_1x2v_p1.c b/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_1x2v_p1.c index 9afa67a5af..30b9fb87ca 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_1x2v_p1.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_1x2v_p1.c @@ -19,8 +19,7 @@ #include -struct annulus_sodshock_ctx -{ +struct annulus_sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -59,8 +58,7 @@ struct annulus_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct annulus_sodshock_ctx -create_ctx(void) +struct annulus_sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -93,7 +91,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -127,14 +126,13 @@ create_ctx(void) .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -147,8 +145,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -158,8 +155,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -172,8 +168,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -181,8 +176,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -201,18 +195,17 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (r < midplane) { V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Angular drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Angular drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; @@ -222,8 +215,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0], p_r_dot = xn[1], p_theta_dot = xn[2]; @@ -231,52 +223,55 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_r_theta = 0.0; double inv_metric_theta_theta = 1.0 / (q_r * q_r); - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + double hamiltonian = + (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot); // Canonical Hamiltonian. - + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). - + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_theta_theta; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_theta_theta; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_r_r = 1.0; // mMtric tensor (radial-radial component). double metric_r_theta = 0.0; // Metric tensor (radial-angular component). double metric_theta_theta = q_r * q_r; // Metric tensor (angular-angular component). - + // Set metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_theta_theta; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_theta_theta; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_det = q_r; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -294,32 +289,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -345,18 +342,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR }; + int ccells[] = {NR}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -364,39 +360,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -420,10 +402,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max }, - .upper = { ctx.vr_max, ctx.vtheta_max }, - .cells = { NVR, NVTHETA }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max}, + .upper = {ctx.vr_max, ctx.vtheta_max}, + .cells = {NVR, NVTHETA}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -434,65 +417,57 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.5 }, - .upper = { 0.5 + ctx.Lr }, - .cells = { NR }, + .cdim = 1, + .vdim = 2, + .lower = {0.5}, + .upper = {0.5 + ctx.Lr}, + .cells = {NR}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -506,10 +481,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -518,32 +497,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -559,7 +545,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -575,8 +561,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -584,7 +569,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -593,8 +580,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -614,14 +600,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_1x2v_p2.c b/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_1x2v_p2.c index cd87e9074a..3dc55c309e 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_1x2v_p2.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_1x2v_p2.c @@ -19,8 +19,7 @@ #include -struct annulus_sodshock_ctx -{ +struct annulus_sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -59,8 +58,7 @@ struct annulus_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct annulus_sodshock_ctx -create_ctx(void) +struct annulus_sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -93,7 +91,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -127,14 +126,13 @@ create_ctx(void) .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -147,8 +145,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -158,8 +155,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -172,8 +168,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -181,8 +176,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -201,18 +195,17 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (r < midplane) { V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Angular drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Angular drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; @@ -222,8 +215,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0], p_r_dot = xn[1], p_theta_dot = xn[2]; @@ -231,52 +223,55 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_r_theta = 0.0; double inv_metric_theta_theta = 1.0 / (q_r * q_r); - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + double hamiltonian = + (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot); // Canonical Hamiltonian. - + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). - + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_theta_theta; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_theta_theta; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_r_r = 1.0; // mMtric tensor (radial-radial component). double metric_r_theta = 0.0; // Metric tensor (radial-angular component). double metric_theta_theta = q_r * q_r; // Metric tensor (angular-angular component). - + // Set metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_theta_theta; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_theta_theta; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_det = q_r; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -294,32 +289,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -345,18 +342,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR }; + int ccells[] = {NR}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -364,39 +360,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -420,10 +402,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max }, - .upper = { ctx.vr_max, ctx.vtheta_max }, - .cells = { NVR, NVTHETA }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max}, + .upper = {ctx.vr_max, ctx.vtheta_max}, + .cells = {NVR, NVTHETA}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -434,65 +417,57 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.5 }, - .upper = { 0.5 + ctx.Lr }, - .cells = { NR }, + .cdim = 1, + .vdim = 2, + .lower = {0.5}, + .upper = {0.5 + ctx.Lr}, + .cells = {NR}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -506,10 +481,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -518,32 +497,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -559,7 +545,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -575,8 +561,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -584,7 +569,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -593,8 +580,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -614,14 +600,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_2x2v_p1.c b/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_2x2v_p1.c index d1385eac0c..bd4acd3a65 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_2x2v_p1.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_2x2v_p1.c @@ -19,8 +19,7 @@ #include -struct annulus_sodshock_ctx -{ +struct annulus_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -64,8 +63,7 @@ struct annulus_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct annulus_sodshock_ctx -create_ctx(void) +struct annulus_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -103,7 +101,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -140,14 +139,13 @@ create_ctx(void) .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -160,8 +158,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -171,8 +168,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -185,8 +181,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -194,8 +189,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -214,18 +208,17 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (r < midplane) { V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Angular drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Angular drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; @@ -235,8 +228,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0], p_r_dot = xn[2], p_theta_dot = xn[3]; @@ -244,52 +236,55 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_r_theta = 0.0; double inv_metric_theta_theta = 1.0 / (q_r * q_r); - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + double hamiltonian = + (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot); // Canonical Hamiltonian. - + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). - + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_theta_theta; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_theta_theta; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_r_r = 1.0; // mMtric tensor (radial-radial component). double metric_r_theta = 0.0; // Metric tensor (radial-angular component). double metric_theta_theta = q_r * q_r; // Metric tensor (angular-angular component). - + // Set metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_theta_theta; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_theta_theta; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_det = q_r; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -307,32 +302,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -359,18 +356,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR, NTHETA }; + int ccells[] = {NR, NTHETA}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -378,39 +374,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -434,10 +416,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max }, - .upper = { ctx.vr_max, ctx.vtheta_max }, - .cells = { NVR, NVTHETA }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max}, + .upper = {ctx.vr_max, ctx.vtheta_max}, + .cells = {NVR, NVTHETA}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -448,65 +431,58 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { 0.5, 0.0 }, - .upper = { 0.5 + ctx.Lr, ctx.Ltheta }, - .cells = { NR, NTHETA }, + .cdim = 2, + .vdim = 2, + .lower = {0.5, 0.0}, + .upper = {0.5 + ctx.Lr, ctx.Ltheta}, + .cells = {NR, NTHETA}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -520,10 +496,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -532,32 +512,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -573,7 +560,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -589,8 +576,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -598,7 +584,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -607,8 +595,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -628,14 +615,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_2x2v_p2.c b/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_2x2v_p2.c index c492beeb8f..1974e16bb0 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_2x2v_p2.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_annulus_sodshock_im_2x2v_p2.c @@ -19,8 +19,7 @@ #include -struct annulus_sodshock_ctx -{ +struct annulus_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -64,8 +63,7 @@ struct annulus_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct annulus_sodshock_ctx -create_ctx(void) +struct annulus_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -103,7 +101,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -140,14 +139,13 @@ create_ctx(void) .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -160,8 +158,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -171,8 +168,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -185,8 +181,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -194,8 +189,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; double r = xn[0]; @@ -214,18 +208,17 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (r < midplane) { V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Angular drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Angular drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct annulus_sodshock_ctx *app = ctx; @@ -235,8 +228,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0], p_r_dot = xn[2], p_theta_dot = xn[3]; @@ -244,52 +236,55 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_r_theta = 0.0; double inv_metric_theta_theta = 1.0 / (q_r * q_r); - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + double hamiltonian = + (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot); // Canonical Hamiltonian. - + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). - + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_theta_theta; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_theta_theta; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_r_r = 1.0; // mMtric tensor (radial-radial component). double metric_r_theta = 0.0; // Metric tensor (radial-angular component). double metric_theta_theta = q_r * q_r; // Metric tensor (angular-angular component). - + // Set metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_theta_theta; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_theta_theta; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_det = q_r; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -307,32 +302,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -359,18 +356,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR, NTHETA }; + int ccells[] = {NR, NTHETA}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -378,39 +374,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -434,10 +416,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max }, - .upper = { ctx.vr_max, ctx.vtheta_max }, - .cells = { NVR, NVTHETA }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max}, + .upper = {ctx.vr_max, ctx.vtheta_max}, + .cells = {NVR, NVTHETA}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -448,65 +431,58 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { 0.5, 0.0 }, - .upper = { 0.5 + ctx.Lr, ctx.Ltheta }, - .cells = { NR, NTHETA }, + .cdim = 2, + .vdim = 2, + .lower = {0.5, 0.0}, + .upper = {0.5 + ctx.Lr, ctx.Ltheta}, + .cells = {NR, NTHETA}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -520,10 +496,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -532,32 +512,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -573,7 +560,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -589,8 +576,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -598,7 +584,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -607,8 +595,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -628,14 +615,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_1x3v_p1.c b/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_1x3v_p1.c index b00d0898cc..9d709d7061 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_1x3v_p1.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_1x3v_p1.c @@ -19,8 +19,7 @@ #include -struct cylindrical_sodshock_ctx -{ +struct cylindrical_sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -63,8 +62,7 @@ struct cylindrical_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct cylindrical_sodshock_ctx -create_ctx(void) +struct cylindrical_sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -101,7 +99,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -139,14 +138,13 @@ create_ctx(void) .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -159,8 +157,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -170,8 +167,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -184,8 +180,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -193,8 +188,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -217,19 +211,19 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Angular drift velocity (left/inner). V_z_drift = V_z_drift_l; // Z drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Angular drift velocity (right/outer). V_z_drift = V_z_drift_r; // Z drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; fout[2] = V_z_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; + fout[2] = V_z_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; @@ -239,8 +233,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0], p_r_dot = xn[1], p_theta_dot = xn[2], p_z_dot = xn[3]; @@ -251,33 +244,39 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_theta_z = 0.0; double inv_metric_z_z = 1.0; - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + - (0.5 * (2.0 * inv_metric_r_z * p_r_dot * p_z_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + - (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + (0.5 * (2.0 * inv_metric_r_z * p_r_dot * p_z_dot)) + + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + + (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). double inv_metric_r_z = 0.0; // Inverse metric tensor (radial-z component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). double inv_metric_theta_z = 0.0; // Inverse metric tensor (angular-z component). double inv_metric_z_z = 1.0; // Inverse metric tensor (z-z component). - + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_r_z; - fout[3] = inv_metric_theta_theta; fout[4] = inv_metric_theta_z; fout[5] = inv_metric_z_z; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_r_z; + fout[3] = inv_metric_theta_theta; + fout[4] = inv_metric_theta_z; + fout[5] = inv_metric_z_z; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; @@ -287,25 +286,27 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = q_r * q_r; // Metric tensor (angular-angular component). double metric_theta_z = 0.0; // Metric tensor (angular-z component). double metric_z_z = 1.0; // Metric tensor (z-z component). - + // Set metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_r_z; - fout[3] = metric_theta_theta; fout[4] = metric_theta_z; fout[5] = metric_z_z; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_r_z; + fout[3] = metric_theta_theta; + fout[4] = metric_theta_z; + fout[5] = metric_z_z; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_det = q_r; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -323,32 +324,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -375,18 +378,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR }; + int ccells[] = {NR}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -394,39 +396,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -450,10 +438,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max, -ctx.vz_max }, - .upper = { ctx.vr_max, ctx.vtheta_max, ctx.vz_max }, - .cells = { NVR, NVTHETA, NVZ }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max, -ctx.vz_max}, + .upper = {ctx.vr_max, ctx.vtheta_max, ctx.vz_max}, + .cells = {NVR, NVTHETA, NVZ}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -464,65 +453,57 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 3, - .lower = { 0.5 }, - .upper = { 0.5 + ctx.Lr }, - .cells = { NR }, + .cdim = 1, + .vdim = 3, + .lower = {0.5}, + .upper = {0.5 + ctx.Lr}, + .cells = {NR}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -536,10 +517,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -548,32 +533,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -589,7 +581,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -605,8 +597,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -614,7 +605,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -623,8 +616,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -636,7 +628,7 @@ main(int argc, char **argv) calc_integrated_L2_f(&l2f_trig, app, t_curr, false); write_data(&io_trig, app, t_curr, false); gkyl_vlasov_app_stat_write(app); - + struct gkyl_vlasov_stat stat = gkyl_vlasov_app_stat(app); gkyl_vlasov_app_cout(app, stdout, "\n"); @@ -644,14 +636,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_1x3v_p2.c b/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_1x3v_p2.c index 6469f6af84..19ded8f1a7 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_1x3v_p2.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_1x3v_p2.c @@ -19,8 +19,7 @@ #include -struct cylindrical_sodshock_ctx -{ +struct cylindrical_sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -63,8 +62,7 @@ struct cylindrical_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct cylindrical_sodshock_ctx -create_ctx(void) +struct cylindrical_sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -101,7 +99,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -139,14 +138,13 @@ create_ctx(void) .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -159,8 +157,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -170,8 +167,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -184,8 +180,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -193,8 +188,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -217,19 +211,19 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Angular drift velocity (left/inner). V_z_drift = V_z_drift_l; // Z drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Angular drift velocity (right/outer). V_z_drift = V_z_drift_r; // Z drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; fout[2] = V_z_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; + fout[2] = V_z_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; @@ -239,8 +233,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0], p_r_dot = xn[1], p_theta_dot = xn[2], p_z_dot = xn[3]; @@ -251,33 +244,39 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_theta_z = 0.0; double inv_metric_z_z = 1.0; - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + - (0.5 * (2.0 * inv_metric_r_z * p_r_dot * p_z_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + - (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + (0.5 * (2.0 * inv_metric_r_z * p_r_dot * p_z_dot)) + + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + + (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). double inv_metric_r_z = 0.0; // Inverse metric tensor (radial-z component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). double inv_metric_theta_z = 0.0; // Inverse metric tensor (angular-z component). double inv_metric_z_z = 1.0; // Inverse metric tensor (z-z component). - + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_r_z; - fout[3] = inv_metric_theta_theta; fout[4] = inv_metric_theta_z; fout[5] = inv_metric_z_z; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_r_z; + fout[3] = inv_metric_theta_theta; + fout[4] = inv_metric_theta_z; + fout[5] = inv_metric_z_z; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; @@ -287,25 +286,27 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = q_r * q_r; // Metric tensor (angular-angular component). double metric_theta_z = 0.0; // Metric tensor (angular-z component). double metric_z_z = 1.0; // Metric tensor (z-z component). - + // Set metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_r_z; - fout[3] = metric_theta_theta; fout[4] = metric_theta_z; fout[5] = metric_z_z; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_r_z; + fout[3] = metric_theta_theta; + fout[4] = metric_theta_z; + fout[5] = metric_z_z; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_det = q_r; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -323,32 +324,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -375,18 +378,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR }; + int ccells[] = {NR}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -394,39 +396,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -450,10 +438,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max, -ctx.vz_max }, - .upper = { ctx.vr_max, ctx.vtheta_max, ctx.vz_max }, - .cells = { NVR, NVTHETA, NVZ }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max, -ctx.vz_max}, + .upper = {ctx.vr_max, ctx.vtheta_max, ctx.vz_max}, + .cells = {NVR, NVTHETA, NVZ}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -464,65 +453,57 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 3, - .lower = { 0.5 }, - .upper = { 0.5 + ctx.Lr }, - .cells = { NR }, + .cdim = 1, + .vdim = 3, + .lower = {0.5}, + .upper = {0.5 + ctx.Lr}, + .cells = {NR}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -536,10 +517,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -548,32 +533,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -589,7 +581,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -605,8 +597,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -614,7 +605,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -623,14 +616,13 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } step += 1; } - + calc_field_energy(&fe_trig, app, t_curr, false); calc_integrated_mom(&im_trig, app, t_curr, false); calc_integrated_L2_f(&l2f_trig, app, t_curr, false); @@ -644,14 +636,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_2x3v_p1.c b/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_2x3v_p1.c index 9ed06c11ea..052c0483fa 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_2x3v_p1.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_2x3v_p1.c @@ -19,8 +19,7 @@ #include -struct cylindrical_sodshock_ctx -{ +struct cylindrical_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -68,8 +67,7 @@ struct cylindrical_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct cylindrical_sodshock_ctx -create_ctx(void) +struct cylindrical_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -111,7 +109,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -152,14 +151,13 @@ create_ctx(void) .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -172,8 +170,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -183,8 +180,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -197,8 +193,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -206,8 +201,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -230,19 +224,19 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Angular drift velocity (left/inner). V_z_drift = V_z_drift_l; // Z drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Angular drift velocity (right/outer). V_z_drift = V_z_drift_r; // Z drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; fout[2] = V_z_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; + fout[2] = V_z_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; @@ -252,8 +246,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0], p_r_dot = xn[2], p_theta_dot = xn[3], p_z_dot = xn[4]; @@ -264,33 +257,39 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_theta_z = 0.0; double inv_metric_z_z = 1.0; - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + - (0.5 * (2.0 * inv_metric_r_z * p_r_dot * p_z_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + - (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + (0.5 * (2.0 * inv_metric_r_z * p_r_dot * p_z_dot)) + + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + + (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). double inv_metric_r_z = 0.0; // Inverse metric tensor (radial-z component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). double inv_metric_theta_z = 0.0; // Inverse metric tensor (angular-z component). double inv_metric_z_z = 1.0; // Inverse metric tensor (z-z component). - + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_r_z; - fout[3] = inv_metric_theta_theta; fout[4] = inv_metric_theta_z; fout[5] = inv_metric_z_z; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_r_z; + fout[3] = inv_metric_theta_theta; + fout[4] = inv_metric_theta_z; + fout[5] = inv_metric_z_z; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; @@ -300,25 +299,27 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = q_r * q_r; // Metric tensor (angular-angular component). double metric_theta_z = 0.0; // Metric tensor (angular-z component). double metric_z_z = 1.0; // Metric tensor (z-z component). - + // Set metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_r_z; - fout[3] = metric_theta_theta; fout[4] = metric_theta_z; fout[5] = metric_z_z; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_r_z; + fout[3] = metric_theta_theta; + fout[4] = metric_theta_z; + fout[5] = metric_z_z; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_det = q_r; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -336,32 +337,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -389,18 +392,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR, NTHETA }; + int ccells[] = {NR, NTHETA}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -408,39 +410,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -464,10 +452,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max, -ctx.vz_max }, - .upper = { ctx.vr_max, ctx.vtheta_max, ctx.vz_max }, - .cells = { NVR, NVTHETA, NVZ }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max, -ctx.vz_max}, + .upper = {ctx.vr_max, ctx.vtheta_max, ctx.vz_max}, + .cells = {NVR, NVTHETA, NVZ}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -478,65 +467,58 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 3, - .lower = { 0.5, 0.0 }, - .upper = { 0.5 + ctx.Lr, ctx.Ltheta }, - .cells = { NR, NTHETA }, + .cdim = 2, + .vdim = 3, + .lower = {0.5, 0.0}, + .upper = {0.5 + ctx.Lr, ctx.Ltheta}, + .cells = {NR, NTHETA}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -550,10 +532,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -562,32 +548,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -603,7 +596,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -619,8 +612,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -628,7 +620,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -637,8 +631,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -658,14 +651,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_2x3v_p2.c b/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_2x3v_p2.c index b8fa3b4513..fdd6ca3c76 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_2x3v_p2.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_2x3v_p2.c @@ -19,8 +19,7 @@ #include -struct cylindrical_sodshock_ctx -{ +struct cylindrical_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -68,8 +67,7 @@ struct cylindrical_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct cylindrical_sodshock_ctx -create_ctx(void) +struct cylindrical_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -111,7 +109,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -152,14 +151,13 @@ create_ctx(void) .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -172,8 +170,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -183,8 +180,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -197,8 +193,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -206,8 +201,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -230,19 +224,19 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Angular drift velocity (left/inner). V_z_drift = V_z_drift_l; // Z drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Angular drift velocity (right/outer). V_z_drift = V_z_drift_r; // Z drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; fout[2] = V_z_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; + fout[2] = V_z_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; @@ -252,8 +246,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0], p_r_dot = xn[2], p_theta_dot = xn[3], p_z_dot = xn[4]; @@ -264,33 +257,39 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_theta_z = 0.0; double inv_metric_z_z = 1.0; - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + - (0.5 * (2.0 * inv_metric_r_z * p_r_dot * p_z_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + - (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + (0.5 * (2.0 * inv_metric_r_z * p_r_dot * p_z_dot)) + + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + + (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). double inv_metric_r_z = 0.0; // Inverse metric tensor (radial-z component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). double inv_metric_theta_z = 0.0; // Inverse metric tensor (angular-z component). double inv_metric_z_z = 1.0; // Inverse metric tensor (z-z component). - + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_r_z; - fout[3] = inv_metric_theta_theta; fout[4] = inv_metric_theta_z; fout[5] = inv_metric_z_z; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_r_z; + fout[3] = inv_metric_theta_theta; + fout[4] = inv_metric_theta_z; + fout[5] = inv_metric_z_z; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; @@ -300,25 +299,27 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = q_r * q_r; // Metric tensor (angular-angular component). double metric_theta_z = 0.0; // Metric tensor (angular-z component). double metric_z_z = 1.0; // Metric tensor (z-z component). - + // Set metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_r_z; - fout[3] = metric_theta_theta; fout[4] = metric_theta_z; fout[5] = metric_z_z; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_r_z; + fout[3] = metric_theta_theta; + fout[4] = metric_theta_z; + fout[5] = metric_z_z; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_det = q_r; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -336,32 +337,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -389,18 +392,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR, NTHETA }; + int ccells[] = {NR, NTHETA}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -408,39 +410,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -464,10 +452,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max, -ctx.vz_max }, - .upper = { ctx.vr_max, ctx.vtheta_max, ctx.vz_max }, - .cells = { NVR, NVTHETA, NVZ }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max, -ctx.vz_max}, + .upper = {ctx.vr_max, ctx.vtheta_max, ctx.vz_max}, + .cells = {NVR, NVTHETA, NVZ}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -478,65 +467,58 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 3, - .lower = { 0.5, 0.0 }, - .upper = { 0.5 + ctx.Lr, ctx.Ltheta }, - .cells = { NR, NTHETA }, + .cdim = 2, + .vdim = 3, + .lower = {0.5, 0.0}, + .upper = {0.5 + ctx.Lr, ctx.Ltheta}, + .cells = {NR, NTHETA}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -550,10 +532,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -562,32 +548,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -603,7 +596,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -619,8 +612,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -628,7 +620,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -637,8 +631,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -658,14 +651,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_3x3v_p1.c b/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_3x3v_p1.c index cd2ac90a29..f3e2dfc5db 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_3x3v_p1.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_cylindrical_sodshock_im_3x3v_p1.c @@ -19,8 +19,7 @@ #include -struct cylindrical_sodshock_ctx -{ +struct cylindrical_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -70,8 +69,7 @@ struct cylindrical_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct cylindrical_sodshock_ctx -create_ctx(void) +struct cylindrical_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -115,7 +113,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -158,14 +157,13 @@ create_ctx(void) .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -178,8 +176,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -189,8 +186,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -203,8 +199,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -212,8 +207,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; double r = xn[0]; @@ -236,19 +230,19 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Angular drift velocity (left/inner). V_z_drift = V_z_drift_l; // Z drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Angular drift velocity (right/outer). V_z_drift = V_z_drift_r; // Z drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; fout[2] = V_z_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; + fout[2] = V_z_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct cylindrical_sodshock_ctx *app = ctx; @@ -258,8 +252,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0], p_r_dot = xn[3], p_theta_dot = xn[4], p_z_dot = xn[5]; @@ -270,33 +263,39 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_theta_z = 0.0; double inv_metric_z_z = 1.0; - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + - (0.5 * (2.0 * inv_metric_r_z * p_r_dot * p_z_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + - (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + (0.5 * (2.0 * inv_metric_r_z * p_r_dot * p_z_dot)) + + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + + (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). double inv_metric_r_z = 0.0; // Inverse metric tensor (radial-z component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). double inv_metric_theta_z = 0.0; // Inverse metric tensor (angular-z component). double inv_metric_z_z = 1.0; // Inverse metric tensor (z-z component). - + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_r_z; - fout[3] = inv_metric_theta_theta; fout[4] = inv_metric_theta_z; fout[5] = inv_metric_z_z; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_r_z; + fout[3] = inv_metric_theta_theta; + fout[4] = inv_metric_theta_z; + fout[5] = inv_metric_z_z; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; @@ -306,25 +305,27 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = q_r * q_r; // Metric tensor (angular-angular component). double metric_theta_z = 0.0; // Metric tensor (angular-z component). double metric_z_z = 1.0; // Metric tensor (z-z component). - + // Set metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_r_z; - fout[3] = metric_theta_theta; fout[4] = metric_theta_z; fout[5] = metric_z_z; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_r_z; + fout[3] = metric_theta_theta; + fout[4] = metric_theta_z; + fout[5] = metric_z_z; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_det = q_r; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -342,32 +343,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -396,18 +399,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR, NTHETA, NZ }; + int ccells[] = {NR, NTHETA, NZ}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -415,39 +417,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -471,10 +459,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max, -ctx.vz_max }, - .upper = { ctx.vr_max, ctx.vtheta_max, ctx.vz_max }, - .cells = { NVR, NVTHETA, NVZ }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max, -ctx.vz_max}, + .upper = {ctx.vr_max, ctx.vtheta_max, ctx.vz_max}, + .cells = {NVR, NVTHETA, NVZ}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -485,65 +474,60 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 3, .vdim = 3, - .lower = { 0.5, 0.0, -0.5 * ctx.Lz }, - .upper = { 0.5 + ctx.Lr, ctx.Ltheta, 0.5 * ctx.Lz }, - .cells = { NR, NTHETA, NZ }, + .cdim = 3, + .vdim = 3, + .lower = {0.5, 0.0, -0.5 * ctx.Lz}, + .upper = {0.5 + ctx.Lr, ctx.Ltheta, 0.5 * ctx.Lz}, + .cells = {NR, NTHETA, NZ}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 2, - .periodic_dirs = { 1, 2 }, + .num_periodic_dir = 2, + .periodic_dirs = {1, 2}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1], app_args.cuts[2] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, + .cuts = {app_args.cuts[0], app_args.cuts[1], app_args.cuts[2]}, + .comm = comm} }; // Create app object. @@ -557,10 +541,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -569,32 +557,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -610,7 +605,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -626,8 +621,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -635,7 +629,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -644,8 +640,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -665,14 +660,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_hyperbolic_khi_im_2x2v_p2.c b/vlasov/creg/rt_can_pb_bgk_surf_hyperbolic_khi_im_2x2v_p2.c index 3500691397..0bb79fd166 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_hyperbolic_khi_im_2x2v_p2.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_hyperbolic_khi_im_2x2v_p2.c @@ -19,8 +19,7 @@ #include -struct hyp_khi_ctx -{ +struct hyp_khi_ctx { // Mathematical constants (dimensionless). double pi; @@ -66,8 +65,7 @@ struct hyp_khi_ctx double z_loc; // Cuttoff between lower and upper layers. }; -struct hyp_khi_ctx -create_ctx(void) +struct hyp_khi_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -105,7 +103,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -146,14 +145,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .R = R, .z_midplane = z_midplane, - .z_loc = z_loc, + .z_loc = z_loc }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hyp_khi_ctx *app = ctx; double theta = xn[0], q_z = xn[1]; @@ -169,19 +167,17 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (fabs(q_z - z_midplane) < z_loc) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } - double metric_det = sqrt( R * R + 2.0 * q_z * q_z ); + double metric_det = sqrt(R * R + 2.0 * q_z * q_z); // Set total number density. fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hyp_khi_ctx *app = ctx; double theta = xn[0], q_z = xn[1]; @@ -197,18 +193,16 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double T = 0.0; if (fabs(q_z - z_midplane) < z_loc) { - T = Pl/nl; // Isotropic temperature (left/inner). - } - else { - T = Pr/nr; // Isotropic temperature (right/outer). + T = Pl / nl; // Isotropic temperature (left/inner). + } else { + T = Pr / nr; // Isotropic temperature (right/outer). } // Set isotropic temperature. fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hyp_khi_ctx *app = ctx; double theta = xn[0]; @@ -229,8 +223,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (fabs(z - z_midplane) < z_loc) { V_theta_drift = V_theta_drift_l; // Azimuthal angular drift velocity (left/inner). - } - else { + } else { V_theta_drift = V_theta_drift_r; // Azimuthal angular drift velocity (right/outer). } @@ -238,22 +231,25 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f // Initalize noise double alpha = 1.0e-2; - double k_theta = 2.0 * pi/app->Ltheta; - double k_z = 2.0 * pi/app->Lz; + double k_theta = 2.0 * pi / app->Ltheta; + double k_z = 2.0 * pi / app->Lz; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - V_theta_drift += alpha * gkyl_pcg64_rand_double(&rng) * sin(i * k_theta * theta + j * k_z * z + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); - V_z_drift += alpha * gkyl_pcg64_rand_double(&rng) * sin(i * k_theta * theta + j * k_z * z + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); + V_theta_drift += + alpha * gkyl_pcg64_rand_double(&rng) * + sin(i * k_theta * theta + j * k_z * z + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); + V_z_drift += alpha * gkyl_pcg64_rand_double(&rng) * + sin(i * k_theta * theta + j * k_z * z + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); } } // Set total drift velocity. - fout[0] = V_theta_drift; fout[1] = V_z_drift; + fout[0] = V_theta_drift; + fout[1] = V_z_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hyp_khi_ctx *app = ctx; @@ -263,72 +259,79 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hyp_khi_ctx *app = ctx; double q_theta = xn[0], q_z = xn[1], p_theta_dot = xn[2], p_z_dot = xn[3]; double R = app->R; - double inv_metric_theta_theta = 1.0 / ( R * R + q_z * q_z); // Inverse metric tensor (polar-polar component). + double inv_metric_theta_theta = + 1.0 / (R * R + q_z * q_z); // Inverse metric tensor (polar-polar component). double inv_metric_theta_z = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_z_z = ( R * R + q_z * q_z) / ( R * R + 2.0 * q_z * q_z ); // Inverse metric tensor (azimuthal-azimuthal component). + double inv_metric_z_z = + (R * R + q_z * q_z) / + (R * R + 2.0 * q_z * q_z); // Inverse metric tensor (azimuthal-azimuthal component). + + double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + + (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. - double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + (0.5 * (2.0 * inv_metric_theta_z * p_theta_dot * p_z_dot)) + - (0.5 * inv_metric_z_z * p_z_dot * p_z_dot); // Canonical Hamiltonian. - // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hyp_khi_ctx *app = ctx; double q_theta = xn[0]; double q_z = xn[1]; double R = app->R; - double inv_metric_theta_theta = 1.0 / ( R * R + q_z * q_z ); // Inverse metric tensor (polar-polar component). + double inv_metric_theta_theta = + 1.0 / (R * R + q_z * q_z); // Inverse metric tensor (polar-polar component). double inv_metric_theta_z = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_z_z = ( R * R + q_z * q_z ) / ( R * R + 2.0 * q_z * q_z ); // Inverse metric tensor (azimuthal-azimuthal component). - + double inv_metric_z_z = + (R * R + q_z * q_z) / + (R * R + 2.0 * q_z * q_z); // Inverse metric tensor (azimuthal-azimuthal component). + // Set inverse metric tensor. - fout[0] = inv_metric_theta_theta; fout[1] = inv_metric_theta_z; fout[2] = inv_metric_z_z; + fout[0] = inv_metric_theta_theta; + fout[1] = inv_metric_theta_z; + fout[2] = inv_metric_z_z; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hyp_khi_ctx *app = ctx; double q_theta = xn[0]; double q_z = xn[1]; double R = app->R; - double metric_theta_theta = R * R + q_z * q_z ; // Metric tensor (polar-polar component). + double metric_theta_theta = R * R + q_z * q_z; // Metric tensor (polar-polar component). double metric_theta_z = 0.0; // Metric tensor (polar-azimuthal component). - double metric_z_z = ( R * R + 2.0 * q_z * q_z ) / ( R * R + q_z * q_z ); // Metric tensor (azimuthal-azimuthal component). - + double metric_z_z = (R * R + 2.0 * q_z * q_z) / + (R * R + q_z * q_z); // Metric tensor (azimuthal-azimuthal component). + // Set metric tensor. - fout[0] = metric_theta_theta; fout[1] = metric_theta_z; fout[2] = metric_z_z; + fout[0] = metric_theta_theta; + fout[1] = metric_theta_z; + fout[2] = metric_z_z; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct hyp_khi_ctx *app = ctx; double q_z = xn[1]; double R = app->R; - double metric_det = sqrt( R * R + 2.0 * q_z * q_z ); // Metric tensor determinant. - + double metric_det = sqrt(R * R + 2.0 * q_z * q_z); // Metric tensor determinant. + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -346,32 +349,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -398,18 +403,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NTHETA, NZ }; + int ccells[] = {NTHETA, NZ}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -417,39 +421,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -473,10 +463,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vtheta_max, -ctx.vz_max }, - .upper = { ctx.vtheta_max, ctx.vz_max }, - .cells = { NVTHETA, NVZ }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vtheta_max, -ctx.vz_max}, + .upper = {ctx.vtheta_max, ctx.vz_max}, + .cells = {NVTHETA, NVZ}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -488,65 +479,58 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = true, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcy = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcy = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { 0.0, -ctx.Lz }, - .upper = { ctx.Ltheta, ctx.Lz }, - .cells = { NTHETA, NZ }, + .cdim = 2, + .vdim = 2, + .lower = {0.0, -ctx.Lz}, + .upper = {ctx.Ltheta, ctx.Lz}, + .cells = {NTHETA, NZ}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .num_periodic_dir = 1, + .periodic_dirs = {0}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -560,10 +544,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -572,32 +560,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -613,7 +608,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -629,8 +624,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -638,7 +632,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -647,8 +643,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -668,14 +663,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_sphere.c b/vlasov/creg/rt_can_pb_bgk_surf_sphere.c index d7d8e53a90..ab0441df36 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_sphere.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_sphere.c @@ -19,8 +19,7 @@ #include -struct bgk_surf_sphere_ctx -{ +struct bgk_surf_sphere_ctx { // Mathematical constants (dimensionless). double pi; @@ -59,8 +58,7 @@ struct bgk_surf_sphere_ctx double R; // Radius of the sphere. }; -struct bgk_surf_sphere_ctx -create_ctx(void) +struct bgk_surf_sphere_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -93,7 +91,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -126,14 +125,13 @@ create_ctx(void) .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .R = R, + .R = R }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_sphere_ctx *app = ctx; double theta = xn[0]; @@ -147,8 +145,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n0; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_sphere_ctx *app = ctx; @@ -158,8 +155,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T0; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_sphere_ctx *app = ctx; @@ -167,11 +163,11 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double V_phi_drift = app->V_phi_drift; // Set total drift velocity. - fout[0] = V_theta_drift; fout[1] = V_phi_drift; + fout[0] = V_theta_drift; + fout[1] = V_phi_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_sphere_ctx *app = ctx; @@ -181,27 +177,26 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_sphere_ctx *app = ctx; double q_theta = xn[0], p_theta_dot = xn[2], p_phi_dot = xn[3]; - + double R = app->R; double inv_metric_theta_theta = 1.0 / (R * R); double inv_metric_theta_phi = 0.0; double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); - double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + - (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_sphere_ctx *app = ctx; double q_theta = xn[0]; @@ -210,14 +205,16 @@ evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double inv_metric_theta_theta = 1.0 / (R * R); // Inverse metric tensor (polar-polar component). double inv_metric_theta_phi = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); // Inverse metric tensor (azimuthal-azimuthal component). - + double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta)) + ); // Inverse metric tensor (azimuthal-azimuthal component). + // Set inverse metric tensor. - fout[0] = inv_metric_theta_theta; fout[1] = inv_metric_theta_phi; fout[2] = inv_metric_phi_phi; + fout[0] = inv_metric_theta_theta; + fout[1] = inv_metric_theta_phi; + fout[2] = inv_metric_phi_phi; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_sphere_ctx *app = ctx; double q_theta = xn[0]; @@ -226,14 +223,16 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = R * R; // Metric tensor (polar-polar component). double metric_theta_phi = 0.0; // Metric tensor (polar-azimuthal component). - double metric_phi_phi = (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). - + double metric_phi_phi = + (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). + // Set metric tensor. - fout[0] = metric_theta_theta; fout[1] = metric_theta_phi; fout[2] = metric_phi_phi; + fout[0] = metric_theta_theta; + fout[1] = metric_theta_phi; + fout[2] = metric_phi_phi; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_sphere_ctx *app = ctx; double q_theta = xn[0]; @@ -241,13 +240,12 @@ evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double R = app->R; double metric_det = (R * R) * sin(q_theta); // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -265,32 +263,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -317,18 +317,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NTHETA, NPHI }; + int ccells[] = {NTHETA, NPHI}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -336,39 +335,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -392,10 +377,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vtheta_max, -ctx.vphi_max }, - .upper = { ctx.vtheta_max, ctx.vphi_max }, - .cells = { NVTHETA, NVPHI }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vtheta_max, -ctx.vphi_max}, + .upper = {ctx.vtheta_max, ctx.vphi_max}, + .cells = {NVTHETA, NVPHI}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -405,65 +391,58 @@ main(int argc, char **argv) .h_ij_inv_ctx = &ctx, .det_h = evalMetricDet, .det_h_ctx = &ctx, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { ctx.pi / 4.0, 0.0 }, - .upper = { (ctx.pi / 4.0) + ctx.Ltheta, ctx.Lphi }, - .cells = { NTHETA, NPHI }, + .cdim = 2, + .vdim = 2, + .lower = {ctx.pi / 4.0, 0.0}, + .upper = {(ctx.pi / 4.0) + ctx.Ltheta, ctx.Lphi}, + .cells = {NTHETA, NPHI}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -477,10 +456,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -489,32 +472,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -530,7 +520,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -546,8 +536,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -555,7 +544,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -564,8 +555,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -585,14 +575,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_sphere_khi_im_2x2v_p2.c b/vlasov/creg/rt_can_pb_bgk_surf_sphere_khi_im_2x2v_p2.c index e30fdd13aa..79ad473024 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_sphere_khi_im_2x2v_p2.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_sphere_khi_im_2x2v_p2.c @@ -19,8 +19,7 @@ #include -struct sphere_khi_ctx -{ +struct sphere_khi_ctx { // Mathematical constants (dimensionless). double pi; @@ -66,8 +65,7 @@ struct sphere_khi_ctx double theta_loc; // Polar angular boundary location designating jump in quantities. }; -struct sphere_khi_ctx -create_ctx(void) +struct sphere_khi_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -105,7 +103,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -146,14 +145,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .R = R, .midplane = midplane, - .theta_loc = theta_loc, + .theta_loc = theta_loc }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_khi_ctx *app = ctx; double theta = xn[0]; @@ -169,8 +167,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (fabs(theta - midplane) < theta_loc) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -180,8 +177,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_khi_ctx *app = ctx; double theta = xn[0]; @@ -197,18 +193,16 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double T = 0.0; if (fabs(theta - midplane) < theta_loc) { - T = Pl/nl; // Isotropic temperature (left/inner). - } - else { - T = Pr/nr; // Isotropic temperature (right/outer). + T = Pl / nl; // Isotropic temperature (left/inner). + } else { + T = Pr / nr; // Isotropic temperature (right/outer). } // Set isotropic temperature. fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_khi_ctx *app = ctx; double theta = xn[0]; @@ -229,8 +223,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (fabs(theta - midplane) < theta_loc) { V_phi_drift = V_phi_drift_l; // Azimuthal angular drift velocity (left/inner). - } - else { + } else { V_phi_drift = V_phi_drift_r; // Azimuthal angular drift velocity (right/outer). } @@ -239,21 +232,25 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f // Initalize noise double alpha = 1.0e-2; double k_theta = 2.0 * pi; - double k_phi = 2.0 * pi/app->Lphi; + double k_phi = 2.0 * pi / app->Lphi; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - V_theta_drift += alpha * gkyl_pcg64_rand_double(&rng) * sin(i * k_theta * theta + j * k_phi * phi + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); - V_phi_drift += alpha * gkyl_pcg64_rand_double(&rng) * sin(i * k_theta * theta + j * k_phi * phi + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); + V_theta_drift += + alpha * gkyl_pcg64_rand_double(&rng) * + sin(i * k_theta * theta + j * k_phi * phi + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); + V_phi_drift += + alpha * gkyl_pcg64_rand_double(&rng) * + sin(i * k_theta * theta + j * k_phi * phi + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); } } // Set total drift velocity. - fout[0] = V_theta_drift; fout[1] = V_phi_drift; + fout[0] = V_theta_drift; + fout[1] = V_phi_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_khi_ctx *app = ctx; @@ -263,27 +260,26 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_khi_ctx *app = ctx; double q_theta = xn[0], p_theta_dot = xn[2], p_phi_dot = xn[3]; - + double R = app->R; double inv_metric_theta_theta = 1.0 / (R * R); double inv_metric_theta_phi = 0.0; double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); - double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + - (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_khi_ctx *app = ctx; double q_theta = xn[0]; @@ -292,14 +288,16 @@ evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double inv_metric_theta_theta = 1.0 / (R * R); // Inverse metric tensor (polar-polar component). double inv_metric_theta_phi = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); // Inverse metric tensor (azimuthal-azimuthal component). - + double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta)) + ); // Inverse metric tensor (azimuthal-azimuthal component). + // Set inverse metric tensor. - fout[0] = inv_metric_theta_theta; fout[1] = inv_metric_theta_phi; fout[2] = inv_metric_phi_phi; + fout[0] = inv_metric_theta_theta; + fout[1] = inv_metric_theta_phi; + fout[2] = inv_metric_phi_phi; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_khi_ctx *app = ctx; double q_theta = xn[0]; @@ -308,14 +306,16 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = R * R; // Metric tensor (polar-polar component). double metric_theta_phi = 0.0; // Metric tensor (polar-azimuthal component). - double metric_phi_phi = (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). - + double metric_phi_phi = + (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). + // Set metric tensor. - fout[0] = metric_theta_theta; fout[1] = metric_theta_phi; fout[2] = metric_phi_phi; + fout[0] = metric_theta_theta; + fout[1] = metric_theta_phi; + fout[2] = metric_phi_phi; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_khi_ctx *app = ctx; double q_theta = xn[0]; @@ -323,13 +323,12 @@ evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double R = app->R; double metric_det = (R * R) * sin(q_theta); // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -347,32 +346,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -399,18 +400,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NTHETA, NPHI }; + int ccells[] = {NTHETA, NPHI}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -418,39 +418,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -474,10 +460,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vtheta_max, -ctx.vphi_max }, - .upper = { ctx.vtheta_max, ctx.vphi_max }, - .cells = { NVTHETA, NVPHI }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vtheta_max, -ctx.vphi_max}, + .upper = {ctx.vtheta_max, ctx.vphi_max}, + .cells = {NVTHETA, NVPHI}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -489,65 +476,58 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = true, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { ctx.pi / 4.0, 0.0 }, - .upper = { (ctx.pi / 4.0) + ctx.Ltheta, ctx.Lphi }, - .cells = { NTHETA, NPHI }, + .cdim = 2, + .vdim = 2, + .lower = {ctx.pi / 4.0, 0.0}, + .upper = {(ctx.pi / 4.0) + ctx.Ltheta, ctx.Lphi}, + .cells = {NTHETA, NPHI}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -561,10 +541,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -573,32 +557,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -614,7 +605,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -630,8 +621,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -639,7 +629,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -648,8 +640,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -669,14 +660,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_1x2v_p1.c b/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_1x2v_p1.c index b7684a1df2..8122df2252 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_1x2v_p1.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_1x2v_p1.c @@ -19,8 +19,7 @@ #include -struct sphere_sodshock_ctx -{ +struct sphere_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -64,8 +63,7 @@ struct sphere_sodshock_ctx double theta_loc; // Polar angular boundary location designating jump in quantities. }; -struct sphere_sodshock_ctx -create_ctx(void) +struct sphere_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -101,7 +99,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -140,14 +139,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .R = R, .midplane = midplane, - .theta_loc = theta_loc, + .theta_loc = theta_loc }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -163,8 +161,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (fabs(theta - midplane) < theta_loc) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -174,8 +171,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -190,8 +186,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (fabs(theta - midplane) < theta_loc) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -199,8 +194,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -220,18 +214,17 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (fabs(theta - midplane) < theta_loc) { V_theta_drift = V_theta_drift_l; // Polar angular drift velocity (left/inner). V_phi_drift = V_phi_drift_l; // Azimuthal angular drift velocity (left/inner). - } - else { + } else { V_theta_drift = V_theta_drift_r; // Polar angular drift velocity (right/outer). V_phi_drift = V_phi_drift_r; // Azimuthal angular drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_theta_drift; fout[1] = V_phi_drift; + fout[0] = V_theta_drift; + fout[1] = V_phi_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; @@ -241,27 +234,26 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0], p_theta_dot = xn[1], p_phi_dot = xn[2]; - + double R = app->R; double inv_metric_theta_theta = 1.0 / (R * R); double inv_metric_theta_phi = 0.0; double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); - double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + - (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -270,14 +262,16 @@ evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double inv_metric_theta_theta = 1.0 / (R * R); // Inverse metric tensor (polar-polar component). double inv_metric_theta_phi = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); // Inverse metric tensor (azimuthal-azimuthal component). - + double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta)) + ); // Inverse metric tensor (azimuthal-azimuthal component). + // Set inverse metric tensor. - fout[0] = inv_metric_theta_theta; fout[1] = inv_metric_theta_phi; fout[2] = inv_metric_phi_phi; + fout[0] = inv_metric_theta_theta; + fout[1] = inv_metric_theta_phi; + fout[2] = inv_metric_phi_phi; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -286,14 +280,16 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = R * R; // Metric tensor (polar-polar component). double metric_theta_phi = 0.0; // Metric tensor (polar-azimuthal component). - double metric_phi_phi = (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). - + double metric_phi_phi = + (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). + // Set metric tensor. - fout[0] = metric_theta_theta; fout[1] = metric_theta_phi; fout[2] = metric_phi_phi; + fout[0] = metric_theta_theta; + fout[1] = metric_theta_phi; + fout[2] = metric_phi_phi; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -301,13 +297,12 @@ evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double R = app->R; double metric_det = (R * R) * sin(q_theta); // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -325,32 +320,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -376,18 +373,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NTHETA }; + int ccells[] = {NTHETA}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -395,39 +391,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -451,10 +433,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vtheta_max, -ctx.vphi_max }, - .upper = { ctx.vtheta_max, ctx.vphi_max }, - .cells = { NVTHETA, NVPHI }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vtheta_max, -ctx.vphi_max}, + .upper = {ctx.vtheta_max, ctx.vphi_max}, + .cells = {NVTHETA, NVPHI}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -466,65 +449,57 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = true, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { ctx.pi / 8.0 }, - .upper = { (ctx.pi / 8.0) + ctx.Ltheta }, - .cells = { NTHETA }, + .cdim = 1, + .vdim = 2, + .lower = {ctx.pi / 8.0}, + .upper = {(ctx.pi / 8.0) + ctx.Ltheta}, + .cells = {NTHETA}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -538,10 +513,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -550,32 +529,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -591,7 +577,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -607,8 +593,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -616,7 +601,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -625,8 +612,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -646,14 +632,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_1x2v_p2.c b/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_1x2v_p2.c index fa063dc153..4fc1a6bd3c 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_1x2v_p2.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_1x2v_p2.c @@ -19,8 +19,7 @@ #include -struct sphere_sodshock_ctx -{ +struct sphere_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -64,8 +63,7 @@ struct sphere_sodshock_ctx double theta_loc; // Polar angular boundary location designating jump in quantities. }; -struct sphere_sodshock_ctx -create_ctx(void) +struct sphere_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -101,7 +99,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -140,14 +139,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .R = R, .midplane = midplane, - .theta_loc = theta_loc, + .theta_loc = theta_loc }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -163,8 +161,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (fabs(theta - midplane) < theta_loc) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -174,8 +171,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -190,8 +186,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (fabs(theta - midplane) < theta_loc) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -199,8 +194,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -220,18 +214,17 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (fabs(theta - midplane) < theta_loc) { V_theta_drift = V_theta_drift_l; // Polar angular drift velocity (left/inner). V_phi_drift = V_phi_drift_l; // Azimuthal angular drift velocity (left/inner). - } - else { + } else { V_theta_drift = V_theta_drift_r; // Polar angular drift velocity (right/outer). V_phi_drift = V_phi_drift_r; // Azimuthal angular drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_theta_drift; fout[1] = V_phi_drift; + fout[0] = V_theta_drift; + fout[1] = V_phi_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; @@ -241,27 +234,26 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0], p_theta_dot = xn[1], p_phi_dot = xn[2]; - + double R = app->R; double inv_metric_theta_theta = 1.0 / (R * R); double inv_metric_theta_phi = 0.0; double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); - double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + - (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -270,14 +262,16 @@ evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double inv_metric_theta_theta = 1.0 / (R * R); // Inverse metric tensor (polar-polar component). double inv_metric_theta_phi = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); // Inverse metric tensor (azimuthal-azimuthal component). - + double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta)) + ); // Inverse metric tensor (azimuthal-azimuthal component). + // Set inverse metric tensor. - fout[0] = inv_metric_theta_theta; fout[1] = inv_metric_theta_phi; fout[2] = inv_metric_phi_phi; + fout[0] = inv_metric_theta_theta; + fout[1] = inv_metric_theta_phi; + fout[2] = inv_metric_phi_phi; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -286,14 +280,16 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = R * R; // Metric tensor (polar-polar component). double metric_theta_phi = 0.0; // Metric tensor (polar-azimuthal component). - double metric_phi_phi = (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). - + double metric_phi_phi = + (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). + // Set metric tensor. - fout[0] = metric_theta_theta; fout[1] = metric_theta_phi; fout[2] = metric_phi_phi; + fout[0] = metric_theta_theta; + fout[1] = metric_theta_phi; + fout[2] = metric_phi_phi; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -301,13 +297,12 @@ evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double R = app->R; double metric_det = (R * R) * sin(q_theta); // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -325,32 +320,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -376,18 +373,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NTHETA }; + int ccells[] = {NTHETA}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -395,39 +391,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -451,10 +433,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vtheta_max, -ctx.vphi_max }, - .upper = { ctx.vtheta_max, ctx.vphi_max }, - .cells = { NVTHETA, NVPHI }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vtheta_max, -ctx.vphi_max}, + .upper = {ctx.vtheta_max, ctx.vphi_max}, + .cells = {NVTHETA, NVPHI}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -466,65 +449,57 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = true, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { ctx.pi / 8.0 }, - .upper = { (ctx.pi / 8.0) + ctx.Ltheta }, - .cells = { NTHETA }, + .cdim = 1, + .vdim = 2, + .lower = {ctx.pi / 8.0}, + .upper = {(ctx.pi / 8.0) + ctx.Ltheta}, + .cells = {NTHETA}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -538,10 +513,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -550,32 +529,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -591,7 +577,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -607,8 +593,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -616,7 +601,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -625,8 +612,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -646,14 +632,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_2x2v_p1.c b/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_2x2v_p1.c index b8d48f702f..f86dba9429 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_2x2v_p1.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_2x2v_p1.c @@ -19,8 +19,7 @@ #include -struct sphere_sodshock_ctx -{ +struct sphere_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -66,8 +65,7 @@ struct sphere_sodshock_ctx double theta_loc; // Polar angular boundary location designating jump in quantities. }; -struct sphere_sodshock_ctx -create_ctx(void) +struct sphere_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -105,7 +103,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -146,14 +145,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .R = R, .midplane = midplane, - .theta_loc = theta_loc, + .theta_loc = theta_loc }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -169,8 +167,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (fabs(theta - midplane) < theta_loc) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -180,8 +177,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -196,8 +192,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (fabs(theta - midplane) < theta_loc) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -205,8 +200,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -226,18 +220,17 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (fabs(theta - midplane) < theta_loc) { V_theta_drift = V_theta_drift_l; // Polar angular drift velocity (left/inner). V_phi_drift = V_phi_drift_l; // Azimuthal angular drift velocity (left/inner). - } - else { + } else { V_theta_drift = V_theta_drift_r; // Polar angular drift velocity (right/outer). V_phi_drift = V_phi_drift_r; // Azimuthal angular drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_theta_drift; fout[1] = V_phi_drift; + fout[0] = V_theta_drift; + fout[1] = V_phi_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; @@ -247,27 +240,26 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0], p_theta_dot = xn[2], p_phi_dot = xn[3]; - + double R = app->R; double inv_metric_theta_theta = 1.0 / (R * R); double inv_metric_theta_phi = 0.0; double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); - double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + - (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -276,14 +268,16 @@ evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double inv_metric_theta_theta = 1.0 / (R * R); // Inverse metric tensor (polar-polar component). double inv_metric_theta_phi = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); // Inverse metric tensor (azimuthal-azimuthal component). - + double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta)) + ); // Inverse metric tensor (azimuthal-azimuthal component). + // Set inverse metric tensor. - fout[0] = inv_metric_theta_theta; fout[1] = inv_metric_theta_phi; fout[2] = inv_metric_phi_phi; + fout[0] = inv_metric_theta_theta; + fout[1] = inv_metric_theta_phi; + fout[2] = inv_metric_phi_phi; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -292,14 +286,16 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = R * R; // Metric tensor (polar-polar component). double metric_theta_phi = 0.0; // Metric tensor (polar-azimuthal component). - double metric_phi_phi = (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). - + double metric_phi_phi = + (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). + // Set metric tensor. - fout[0] = metric_theta_theta; fout[1] = metric_theta_phi; fout[2] = metric_phi_phi; + fout[0] = metric_theta_theta; + fout[1] = metric_theta_phi; + fout[2] = metric_phi_phi; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -307,13 +303,12 @@ evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double R = app->R; double metric_det = (R * R) * sin(q_theta); // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -331,32 +326,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -383,18 +380,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NTHETA, NPHI }; + int ccells[] = {NTHETA, NPHI}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -402,39 +398,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -458,10 +440,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vtheta_max, -ctx.vphi_max }, - .upper = { ctx.vtheta_max, ctx.vphi_max }, - .cells = { NVTHETA, NVPHI }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vtheta_max, -ctx.vphi_max}, + .upper = {ctx.vtheta_max, ctx.vphi_max}, + .cells = {NVTHETA, NVPHI}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -473,65 +456,58 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = true, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { ctx.pi / 8.0, 0.0 }, - .upper = { (ctx.pi / 8.0) + ctx.Ltheta, ctx.Lphi }, - .cells = { NTHETA, NPHI }, + .cdim = 2, + .vdim = 2, + .lower = {ctx.pi / 8.0, 0.0}, + .upper = {(ctx.pi / 8.0) + ctx.Ltheta, ctx.Lphi}, + .cells = {NTHETA, NPHI}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -545,10 +521,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -557,32 +537,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -598,7 +585,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -614,8 +601,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -623,7 +609,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -632,8 +620,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -653,14 +640,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_2x2v_p2.c b/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_2x2v_p2.c index a0a2745848..fae4898e10 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_2x2v_p2.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_sphere_sodshock_im_2x2v_p2.c @@ -19,8 +19,7 @@ #include -struct sphere_sodshock_ctx -{ +struct sphere_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -66,8 +65,7 @@ struct sphere_sodshock_ctx double theta_loc; // Polar angular boundary location designating jump in quantities. }; -struct sphere_sodshock_ctx -create_ctx(void) +struct sphere_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -105,7 +103,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -146,14 +145,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .R = R, .midplane = midplane, - .theta_loc = theta_loc, + .theta_loc = theta_loc }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -169,8 +167,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (fabs(theta - midplane) < theta_loc) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -180,8 +177,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -196,8 +192,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (fabs(theta - midplane) < theta_loc) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -205,8 +200,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double theta = xn[0]; @@ -226,18 +220,17 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (fabs(theta - midplane) < theta_loc) { V_theta_drift = V_theta_drift_l; // Polar angular drift velocity (left/inner). V_phi_drift = V_phi_drift_l; // Azimuthal angular drift velocity (left/inner). - } - else { + } else { V_theta_drift = V_theta_drift_r; // Polar angular drift velocity (right/outer). V_phi_drift = V_phi_drift_r; // Azimuthal angular drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_theta_drift; fout[1] = V_phi_drift; + fout[0] = V_theta_drift; + fout[1] = V_phi_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; @@ -247,27 +240,26 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0], p_theta_dot = xn[2], p_phi_dot = xn[3]; - + double R = app->R; double inv_metric_theta_theta = 1.0 / (R * R); double inv_metric_theta_phi = 0.0; double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); - double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + - (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -276,14 +268,16 @@ evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double inv_metric_theta_theta = 1.0 / (R * R); // Inverse metric tensor (polar-polar component). double inv_metric_theta_phi = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); // Inverse metric tensor (azimuthal-azimuthal component). - + double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta)) + ); // Inverse metric tensor (azimuthal-azimuthal component). + // Set inverse metric tensor. - fout[0] = inv_metric_theta_theta; fout[1] = inv_metric_theta_phi; fout[2] = inv_metric_phi_phi; + fout[0] = inv_metric_theta_theta; + fout[1] = inv_metric_theta_phi; + fout[2] = inv_metric_phi_phi; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -292,14 +286,16 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = R * R; // Metric tensor (polar-polar component). double metric_theta_phi = 0.0; // Metric tensor (polar-azimuthal component). - double metric_phi_phi = (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). - + double metric_phi_phi = + (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). + // Set metric tensor. - fout[0] = metric_theta_theta; fout[1] = metric_theta_phi; fout[2] = metric_phi_phi; + fout[0] = metric_theta_theta; + fout[1] = metric_theta_phi; + fout[2] = metric_phi_phi; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sphere_sodshock_ctx *app = ctx; double q_theta = xn[0]; @@ -307,13 +303,12 @@ evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double R = app->R; double metric_det = (R * R) * sin(q_theta); // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -331,32 +326,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -383,18 +380,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NTHETA, NPHI }; + int ccells[] = {NTHETA, NPHI}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -402,39 +398,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -458,10 +440,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vtheta_max, -ctx.vphi_max }, - .upper = { ctx.vtheta_max, ctx.vphi_max }, - .cells = { NVTHETA, NVPHI }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vtheta_max, -ctx.vphi_max}, + .upper = {ctx.vtheta_max, ctx.vphi_max}, + .cells = {NVTHETA, NVPHI}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -473,65 +456,58 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = true, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { ctx.pi / 8.0, 0.0 }, - .upper = { (ctx.pi / 8.0) + ctx.Ltheta, ctx.Lphi }, - .cells = { NTHETA, NPHI }, + .cdim = 2, + .vdim = 2, + .lower = {ctx.pi / 8.0, 0.0}, + .upper = {(ctx.pi / 8.0) + ctx.Ltheta, ctx.Lphi}, + .cells = {NTHETA, NPHI}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -545,10 +521,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -557,32 +537,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -598,7 +585,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -614,8 +601,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -623,7 +609,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -632,8 +620,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -653,14 +640,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_2x3v_p1.c b/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_2x3v_p1.c index d9154a2bbe..ce95baf207 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_2x3v_p1.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_2x3v_p1.c @@ -19,8 +19,7 @@ #include -struct toroidal_sodshock_ctx -{ +struct toroidal_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -69,8 +68,7 @@ struct toroidal_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct toroidal_sodshock_ctx -create_ctx(void) +struct toroidal_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -112,7 +110,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -155,14 +154,13 @@ create_ctx(void) .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, .R = R, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double r = xn[0], theta = xn[1]; @@ -177,8 +175,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -188,8 +185,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double r = xn[0]; @@ -202,8 +198,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -211,8 +206,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double r = xn[0]; @@ -235,19 +229,19 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Polar angular drift velocity (left/inner). V_phi_drift = V_phi_drift_l; // Azimuthal angular drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Polar angular drift velocity (right/outer). V_phi_drift = V_phi_drift_r; // Azimuthal angular drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; fout[2] = V_phi_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; + fout[2] = V_phi_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; @@ -257,8 +251,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1], p_r_dot = xn[2], p_theta_dot = xn[3], p_phi_dot = xn[4]; @@ -272,16 +265,18 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_theta_phi = 0.0; double inv_metric_phi_phi = 1.0 / ((R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta)))); - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + - (0.5 * (2.0 * inv_metric_r_phi * p_r_dot * p_phi_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + - (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + (0.5 * (2.0 * inv_metric_r_phi * p_r_dot * p_phi_dot)) + + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1]; @@ -291,17 +286,22 @@ evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-polar component). double inv_metric_r_phi = 0.0; // Inverse metric tensor (radial-azimuthal component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (polar-polar component). + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (polar-polar component). double inv_metric_theta_phi = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_phi_phi = 1.0 / ((R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta)))); // Inverse metric tensor (azimuthal-azimuthal component). - + double inv_metric_phi_phi = 1.0 / ((R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta))) + ); // Inverse metric tensor (azimuthal-azimuthal component). + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_r_phi; - fout[3] = inv_metric_theta_theta; fout[4] = inv_metric_theta_phi; fout[5] = inv_metric_phi_phi; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_r_phi; + fout[3] = inv_metric_theta_theta; + fout[4] = inv_metric_theta_phi; + fout[5] = inv_metric_phi_phi; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1]; @@ -313,29 +313,33 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_r_phi = 0.0; // Metric tensor (radial-azimuthal component). double metric_theta_theta = q_r * q_r; // Metric tensor (polar-polar component). double metric_theta_phi = 0.0; // Metric tensor (polar-azimuthal component). - double metric_phi_phi = (R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta))); // Metric tensor (azimuthal-azimuthal component). - + double metric_phi_phi = + (R + (q_r * cos(q_theta))) * + (R + (q_r * cos(q_theta))); // Metric tensor (azimuthal-azimuthal component). + // Set Metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_r_phi; - fout[3] = metric_theta_theta; fout[4] = metric_theta_phi; fout[5] = metric_phi_phi; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_r_phi; + fout[3] = metric_theta_theta; + fout[4] = metric_theta_phi; + fout[5] = metric_phi_phi; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - struct toroidal_sodshock_ctx *app =ctx; + struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1]; double R = app->R; double metric_det = q_r * (R + (q_r * cos(q_theta))); // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -353,32 +357,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -406,18 +412,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR, NTHETA }; + int ccells[] = {NR, NTHETA}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -425,39 +430,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -481,10 +472,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max, -ctx.vphi_max }, - .upper = { ctx.vr_max, ctx.vtheta_max, ctx.vphi_max }, - .cells = { NVR, NVTHETA, NVPHI }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max, -ctx.vphi_max}, + .upper = {ctx.vr_max, ctx.vtheta_max, ctx.vphi_max}, + .cells = {NVR, NVTHETA, NVPHI}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -495,65 +487,58 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 3, - .lower = { 0.5, 0.0 }, - .upper = { 0.5 + ctx.Lr, ctx.Ltheta }, - .cells = { NR, NTHETA }, + .cdim = 2, + .vdim = 3, + .lower = {0.5, 0.0}, + .upper = {0.5 + ctx.Lr, ctx.Ltheta}, + .cells = {NR, NTHETA}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -567,10 +552,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -579,32 +568,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -620,7 +616,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -636,8 +632,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -645,7 +640,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -654,8 +651,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -675,14 +671,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_2x3v_p2.c b/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_2x3v_p2.c index 0709ce672a..d9cd5f8570 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_2x3v_p2.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_2x3v_p2.c @@ -19,8 +19,7 @@ #include -struct toroidal_sodshock_ctx -{ +struct toroidal_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -69,8 +68,7 @@ struct toroidal_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct toroidal_sodshock_ctx -create_ctx(void) +struct toroidal_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -112,7 +110,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -155,14 +154,13 @@ create_ctx(void) .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, .R = R, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double r = xn[0], theta = xn[1]; @@ -177,8 +175,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -188,8 +185,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double r = xn[0]; @@ -202,8 +198,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -211,8 +206,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double r = xn[0]; @@ -235,19 +229,19 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Polar angular drift velocity (left/inner). V_phi_drift = V_phi_drift_l; // Azimuthal angular drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Polar angular drift velocity (right/outer). V_phi_drift = V_phi_drift_r; // Azimuthal angular drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; fout[2] = V_phi_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; + fout[2] = V_phi_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; @@ -257,8 +251,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1], p_r_dot = xn[2], p_theta_dot = xn[3], p_phi_dot = xn[4]; @@ -272,16 +265,18 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_theta_phi = 0.0; double inv_metric_phi_phi = 1.0 / ((R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta)))); - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + - (0.5 * (2.0 * inv_metric_r_phi * p_r_dot * p_phi_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + - (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + (0.5 * (2.0 * inv_metric_r_phi * p_r_dot * p_phi_dot)) + + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1]; @@ -291,17 +286,22 @@ evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-polar component). double inv_metric_r_phi = 0.0; // Inverse metric tensor (radial-azimuthal component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (polar-polar component). + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (polar-polar component). double inv_metric_theta_phi = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_phi_phi = 1.0 / ((R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta)))); // Inverse metric tensor (azimuthal-azimuthal component). - + double inv_metric_phi_phi = 1.0 / ((R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta))) + ); // Inverse metric tensor (azimuthal-azimuthal component). + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_r_phi; - fout[3] = inv_metric_theta_theta; fout[4] = inv_metric_theta_phi; fout[5] = inv_metric_phi_phi; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_r_phi; + fout[3] = inv_metric_theta_theta; + fout[4] = inv_metric_theta_phi; + fout[5] = inv_metric_phi_phi; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1]; @@ -313,30 +313,33 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_r_phi = 0.0; // Metric tensor (radial-azimuthal component). double metric_theta_theta = q_r * q_r; // Metric tensor (polar-polar component). double metric_theta_phi = 0.0; // Metric tensor (polar-azimuthal component). - double metric_phi_phi = (R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta))); // Metric tensor (azimuthal-azimuthal component). - + double metric_phi_phi = + (R + (q_r * cos(q_theta))) * + (R + (q_r * cos(q_theta))); // Metric tensor (azimuthal-azimuthal component). + // Set Metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_r_phi; - fout[3] = metric_theta_theta; fout[4] = metric_theta_phi; fout[5] = metric_phi_phi; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_r_phi; + fout[3] = metric_theta_theta; + fout[4] = metric_theta_phi; + fout[5] = metric_phi_phi; } - -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - struct toroidal_sodshock_ctx *app =ctx; + struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1]; double R = app->R; double metric_det = q_r * (R + (q_r * cos(q_theta))); // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -354,32 +357,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -407,18 +412,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR, NTHETA }; + int ccells[] = {NR, NTHETA}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -426,39 +430,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -482,10 +472,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max, -ctx.vphi_max }, - .upper = { ctx.vr_max, ctx.vtheta_max, ctx.vphi_max }, - .cells = { NVR, NVTHETA, NVPHI }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max, -ctx.vphi_max}, + .upper = {ctx.vr_max, ctx.vtheta_max, ctx.vphi_max}, + .cells = {NVR, NVTHETA, NVPHI}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -496,65 +487,58 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 3, - .lower = { 0.5, 0.0 }, - .upper = { 0.5 + ctx.Lr, ctx.Ltheta }, - .cells = { NR, NTHETA }, + .cdim = 2, + .vdim = 3, + .lower = {0.5, 0.0}, + .upper = {0.5 + ctx.Lr, ctx.Ltheta}, + .cells = {NR, NTHETA}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -568,10 +552,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -580,32 +568,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -621,7 +616,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -637,8 +632,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -646,7 +640,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -655,8 +651,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -676,14 +671,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_3x3v_p1.c b/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_3x3v_p1.c index 84539e208d..cde8cc136e 100644 --- a/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_3x3v_p1.c +++ b/vlasov/creg/rt_can_pb_bgk_surf_toroidal_sodshock_im_3x3v_p1.c @@ -19,8 +19,7 @@ #include -struct toroidal_sodshock_ctx -{ +struct toroidal_sodshock_ctx { // Mathematical constants (dimensionless). double pi; @@ -71,8 +70,7 @@ struct toroidal_sodshock_ctx double midplane; // Radial midplane location designating jump in quantities. }; -struct toroidal_sodshock_ctx -create_ctx(void) +struct toroidal_sodshock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -116,7 +114,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -161,14 +160,13 @@ create_ctx(void) .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, .R = R, - .midplane = midplane, + .midplane = midplane }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double r = xn[0], theta = xn[1]; @@ -183,8 +181,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (r < midplane) { n = nl; // Total number density (left/inner). - } - else { + } else { n = nr; // Total number density (right/outer). } @@ -194,8 +191,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double r = xn[0]; @@ -208,8 +204,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (r < midplane) { T = Tl; // Isotropic temperature (left/inner). - } - else { + } else { T = Tr; // Isotropic temperature (right/outer). } @@ -217,8 +212,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double r = xn[0]; @@ -241,19 +235,19 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f V_r_drift = V_r_drift_l; // Radial drift velocity (left/inner). V_theta_drift = V_theta_drift_l; // Polar angular drift velocity (left/inner). V_phi_drift = V_phi_drift_l; // Azimuthal angular drift velocity (left/inner). - } - else { + } else { V_r_drift = V_r_drift_r; // Radial drift velocity (right/outer). V_theta_drift = V_theta_drift_r; // Polar angular drift velocity (right/outer). V_phi_drift = V_phi_drift_r; // Azimuthal angular drift velocity (right/outer). } // Set total drift velocity. - fout[0] = V_r_drift; fout[1] = V_theta_drift; fout[2] = V_phi_drift; + fout[0] = V_r_drift; + fout[1] = V_theta_drift; + fout[2] = V_phi_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; @@ -263,8 +257,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1], p_r_dot = xn[3], p_theta_dot = xn[4], p_phi_dot = xn[5]; @@ -278,16 +271,18 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_theta_phi = 0.0; double inv_metric_phi_phi = 1.0 / ((R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta)))); - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + - (0.5 * (2.0 * inv_metric_r_phi * p_r_dot * p_phi_dot)) + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + - (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + (0.5 * (2.0 * inv_metric_r_phi * p_r_dot * p_phi_dot)) + + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1]; @@ -297,17 +292,22 @@ evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-polar component). double inv_metric_r_phi = 0.0; // Inverse metric tensor (radial-azimuthal component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (polar-polar component). + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (polar-polar component). double inv_metric_theta_phi = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_phi_phi = 1.0 / ((R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta)))); // Inverse metric tensor (azimuthal-azimuthal component). - + double inv_metric_phi_phi = 1.0 / ((R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta))) + ); // Inverse metric tensor (azimuthal-azimuthal component). + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_r_phi; - fout[3] = inv_metric_theta_theta; fout[4] = inv_metric_theta_phi; fout[5] = inv_metric_phi_phi; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_r_phi; + fout[3] = inv_metric_theta_theta; + fout[4] = inv_metric_theta_phi; + fout[5] = inv_metric_phi_phi; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1]; @@ -319,30 +319,33 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_r_phi = 0.0; // Metric tensor (radial-azimuthal component). double metric_theta_theta = q_r * q_r; // Metric tensor (polar-polar component). double metric_theta_phi = 0.0; // Metric tensor (polar-azimuthal component). - double metric_phi_phi = (R + (q_r * cos(q_theta))) * (R + (q_r * cos(q_theta))); // Metric tensor (azimuthal-azimuthal component). - + double metric_phi_phi = + (R + (q_r * cos(q_theta))) * + (R + (q_r * cos(q_theta))); // Metric tensor (azimuthal-azimuthal component). + // Set Metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_r_phi; - fout[3] = metric_theta_theta; fout[4] = metric_theta_phi; fout[5] = metric_phi_phi; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_r_phi; + fout[3] = metric_theta_theta; + fout[4] = metric_theta_phi; + fout[5] = metric_phi_phi; } - -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - struct toroidal_sodshock_ctx *app =ctx; + struct toroidal_sodshock_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1]; double R = app->R; double metric_det = q_r * (R + (q_r * cos(q_theta))); // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -360,32 +363,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -414,18 +419,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NR, NTHETA, NPHI }; + int ccells[] = {NR, NTHETA, NPHI}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -433,39 +437,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -489,10 +479,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vr_max, -ctx.vtheta_max, -ctx.vphi_max }, - .upper = { ctx.vr_max, ctx.vtheta_max, ctx.vphi_max }, - .cells = { NVR, NVTHETA, NVPHI }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vr_max, -ctx.vtheta_max, -ctx.vphi_max}, + .upper = {ctx.vr_max, ctx.vtheta_max, ctx.vphi_max}, + .cells = {NVR, NVTHETA, NVPHI}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -503,65 +494,60 @@ main(int argc, char **argv) .det_h = evalMetricDet, .det_h_ctx = &ctx, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 3, .vdim = 3, - .lower = { 0.5, 0.0, 0.0 }, - .upper = { 0.5 + ctx.Lr, ctx.Ltheta, ctx.Lphi }, - .cells = { NR, NTHETA, NPHI }, + .cdim = 3, + .vdim = 3, + .lower = {0.5, 0.0, 0.0}, + .upper = {0.5 + ctx.Lr, ctx.Ltheta, ctx.Lphi}, + .cells = {NR, NTHETA, NPHI}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 2, - .periodic_dirs = { 1, 2 }, + .num_periodic_dir = 2, + .periodic_dirs = {1, 2}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1], app_args.cuts[2] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, + .cuts = {app_args.cuts[0], app_args.cuts[1], app_args.cuts[2]}, + .comm = comm} }; // Create app object. @@ -575,10 +561,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -587,32 +577,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -628,7 +625,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -644,8 +641,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -653,7 +649,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -662,8 +660,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -683,14 +680,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_ex_bgk_surf_flat.c b/vlasov/creg/rt_can_pb_ex_bgk_surf_flat.c index 34d1062e64..383e361022 100644 --- a/vlasov/creg/rt_can_pb_ex_bgk_surf_flat.c +++ b/vlasov/creg/rt_can_pb_ex_bgk_surf_flat.c @@ -19,8 +19,7 @@ #include -struct bgk_surf_flat_ctx -{ +struct bgk_surf_flat_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -54,8 +53,7 @@ struct bgk_surf_flat_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_surf_flat_ctx -create_ctx(void) +struct bgk_surf_flat_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -85,7 +83,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -114,14 +113,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_ctx *app = ctx; @@ -132,8 +130,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n0; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_ctx *app = ctx; @@ -143,8 +140,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T0; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_ctx *app = ctx; @@ -152,11 +148,11 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double Vy_drift = app->Vy_drift; // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_ctx *app = ctx; @@ -166,8 +162,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double p_x_dot = xn[2], p_y_dot = xn[3]; @@ -175,46 +170,47 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_x_y = 0.0; double inv_metric_y_y = 1.0; - double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + - (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + + (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double inv_metric_x_x = 1.0; // Inverse metric tensor (x-x component). double inv_metric_x_y = 0.0; // Inverse metric tensor (x-y component). double inv_metric_y_y = 1.0; // Inverse metric tensor (y-y component). - + // Set inverse metric tensor. - fout[0] = inv_metric_x_x; fout[1] = inv_metric_x_y; fout[2] = inv_metric_y_y; + fout[0] = inv_metric_x_x; + fout[1] = inv_metric_x_y; + fout[2] = inv_metric_y_y; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_x_x = 1.0; // Metric tensor (x-x component). double metric_x_y = 0.0; // Metric tensor (x-y component). double metric_y_y = 1.0; // Metric tensor (y-y component). - + // Set Metric tensor. - fout[0] = metric_x_x; fout[1] = metric_x_y; fout[2] = metric_y_y; + fout[0] = metric_x_x; + fout[1] = metric_x_y; + fout[2] = metric_y_y; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_det = 1.0; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -232,32 +228,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -284,18 +282,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -303,39 +300,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -359,10 +342,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -372,61 +356,57 @@ main(int argc, char **argv) .h_ij_inv_ctx = &ctx, .det_h = evalMetricDet, .det_h_ctx = &ctx, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = false, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = false, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 2, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .num_periodic_dir = 2, + .periodic_dirs = {0, 1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -440,10 +420,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -452,32 +436,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -493,7 +484,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -509,8 +500,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -518,7 +508,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -527,8 +519,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -548,14 +539,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_ex_bgk_surf_flat_sq_ic.c b/vlasov/creg/rt_can_pb_ex_bgk_surf_flat_sq_ic.c index 533fa74b9e..11c0d88be4 100644 --- a/vlasov/creg/rt_can_pb_ex_bgk_surf_flat_sq_ic.c +++ b/vlasov/creg/rt_can_pb_ex_bgk_surf_flat_sq_ic.c @@ -19,8 +19,7 @@ #include -struct bgk_surf_flat_sq_ctx -{ +struct bgk_surf_flat_sq_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -51,8 +50,7 @@ struct bgk_surf_flat_sq_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_surf_flat_sq_ctx -create_ctx(void) +struct bgk_surf_flat_sq_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -79,7 +77,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -105,14 +104,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeutInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_sq_ctx *app = ctx; double vx = xn[2], vy = xn[3]; @@ -124,8 +122,7 @@ evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if ((fabs(vx) < 1.0) && (fabs(vy) < 1.0)) { n = n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -133,8 +130,7 @@ evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = metric_det * n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_sq_ctx *app = ctx; @@ -144,8 +140,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double p_x_dot = xn[2], p_y_dot = xn[3]; @@ -153,46 +148,47 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_x_y = 0.0; double inv_metric_y_y = 1.0; - double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + - (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + + (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double inv_metric_x_x = 1.0; // Inverse metric tensor (x-x component). double inv_metric_x_y = 0.0; // Inverse metric tensor (x-y component). double inv_metric_y_y = 1.0; // Inverse metric tensor (y-y component). - + // Set inverse metric tensor. - fout[0] = inv_metric_x_x; fout[1] = inv_metric_x_y; fout[2] = inv_metric_y_y; + fout[0] = inv_metric_x_x; + fout[1] = inv_metric_x_y; + fout[2] = inv_metric_y_y; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_x_x = 1.0; // Metric tensor (x-x component). double metric_x_y = 0.0; // Metric tensor (x-y component). double metric_y_y = 1.0; // Metric tensor (y-y component). - + // Set Metric tensor. - fout[0] = metric_x_x; fout[1] = metric_x_y; fout[2] = metric_y_y; + fout[0] = metric_x_x; + fout[1] = metric_x_y; + fout[2] = metric_y_y; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_det = 1.0; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -210,32 +206,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -262,18 +260,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -281,39 +278,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -337,10 +320,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -350,53 +334,46 @@ main(int argc, char **argv) .h_ij_inv_ctx = &ctx, .det_h = evalMetricDet, .det_h_ctx = &ctx, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalNeutInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = false, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalNeutInit, .ctx_func = &ctx}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = false, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 2, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .num_periodic_dir = 2, + .periodic_dirs = {0, 1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -410,10 +387,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -422,32 +403,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -463,7 +451,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -479,8 +467,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -488,7 +475,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -497,8 +486,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -518,14 +506,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_free_streaming_surf_sphere.c b/vlasov/creg/rt_can_pb_free_streaming_surf_sphere.c index b2e63fa6a3..a5db3bb346 100644 --- a/vlasov/creg/rt_can_pb_free_streaming_surf_sphere.c +++ b/vlasov/creg/rt_can_pb_free_streaming_surf_sphere.c @@ -19,8 +19,7 @@ #include -struct surf_sphere_ctx -{ +struct surf_sphere_ctx { // Mathematical constants (dimensionless). double pi; @@ -58,8 +57,7 @@ struct surf_sphere_ctx double R; // Radius of the sphere. }; -struct surf_sphere_ctx -create_ctx(void) +struct surf_sphere_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -91,7 +89,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -123,14 +122,13 @@ create_ctx(void) .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, - .R = R, + .R = R }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct surf_sphere_ctx *app = ctx; double theta = xn[0], phi = xn[1]; @@ -140,14 +138,14 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double metric_det = (R * R) * sin(theta); - double n = n0 + (pow(sin(1.5 * phi), 4.0) * (2.0 * pow(sin(theta), 4.0))); // Total number density. + double n = + n0 + (pow(sin(1.5 * phi), 4.0) * (2.0 * pow(sin(theta), 4.0))); // Total number density. // Set total number density. fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct surf_sphere_ctx *app = ctx; @@ -157,8 +155,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T0; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct surf_sphere_ctx *app = ctx; @@ -166,30 +163,30 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double V_phi_drift = app->V_phi_drift; // Set total drift velocity. - fout[0] = V_theta_drift; fout[1] = V_phi_drift; + fout[0] = V_theta_drift; + fout[1] = V_phi_drift; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct surf_sphere_ctx *app = ctx; double q_theta = xn[0], p_theta_dot = xn[2], p_phi_dot = xn[3]; - + double R = app->R; double inv_metric_theta_theta = 1.0 / (R * R); double inv_metric_theta_phi = 0.0; double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); - double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + - (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) + + (0.5 * (2.0 * inv_metric_theta_phi * p_theta_dot * p_phi_dot)) + + (0.5 * inv_metric_phi_phi * p_phi_dot * p_phi_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct surf_sphere_ctx *app = ctx; double q_theta = xn[0]; @@ -198,14 +195,16 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_theta_theta = R * R; // Metric tensor (polar-polar component). double metric_theta_phi = 0.0; // Metric tensor (polar-azimuthal component). - double metric_phi_phi = (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). - + double metric_phi_phi = + (R * sin(q_theta)) * (R * sin(q_theta)); // Metric tensor (azimuthal-azimuthal component). + // Set metric tensor. - fout[0] = metric_theta_theta; fout[1] = metric_theta_phi; fout[2] = metric_phi_phi; + fout[0] = metric_theta_theta; + fout[1] = metric_theta_phi; + fout[2] = metric_phi_phi; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct surf_sphere_ctx *app = ctx; double q_theta = xn[0]; @@ -214,14 +213,16 @@ evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double inv_metric_theta_theta = 1.0 / (R * R); // Inverse metric tensor (polar-polar component). double inv_metric_theta_phi = 0.0; // Inverse metric tensor (polar-azimuthal component). - double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta))); // Inverse metric tensor (azimuthal-azimuthal component). - + double inv_metric_phi_phi = 1.0 / ((R * sin(q_theta)) * (R * sin(q_theta)) + ); // Inverse metric tensor (azimuthal-azimuthal component). + // Set inverse metric tensor. - fout[0] = inv_metric_theta_theta; fout[1] = inv_metric_theta_phi; fout[2] = inv_metric_phi_phi; + fout[0] = inv_metric_theta_theta; + fout[1] = inv_metric_theta_phi; + fout[2] = inv_metric_phi_phi; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct surf_sphere_ctx *app = ctx; double q_theta = xn[0]; @@ -229,13 +230,12 @@ evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double R = app->R; double metric_det = (R * R) * sin(q_theta); // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -253,32 +253,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -305,18 +307,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NTHETA, NPHI }; + int ccells[] = {NTHETA, NPHI}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -324,39 +325,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -380,10 +367,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vtheta_max, -ctx.vphi_max }, - .upper = { ctx.vtheta_max, ctx.vphi_max }, - .cells = { NVTHETA, NVPHI }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vtheta_max, -ctx.vphi_max}, + .upper = {ctx.vtheta_max, ctx.vphi_max}, + .cells = {NVTHETA, NVPHI}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -393,56 +381,50 @@ main(int argc, char **argv) .h_ij_inv_ctx = &ctx, .det_h = evalMetricDet, .det_h_ctx = &ctx, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { ctx.pi / 4.0, 0.0 }, - .upper = { (ctx.pi / 4.0) + ctx.Ltheta, ctx.Lphi }, - .cells = { NTHETA, NPHI }, + .cdim = 2, + .vdim = 2, + .lower = {ctx.pi / 4.0, 0.0}, + .upper = {(ctx.pi / 4.0) + ctx.Ltheta, ctx.Lphi}, + .cells = {NTHETA, NPHI}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -456,10 +438,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -468,32 +454,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -509,7 +502,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -525,8 +518,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -534,7 +526,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -543,8 +537,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -564,14 +557,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_im_bgk_surf_flat.c b/vlasov/creg/rt_can_pb_im_bgk_surf_flat.c index e003c0f788..1e910040c2 100644 --- a/vlasov/creg/rt_can_pb_im_bgk_surf_flat.c +++ b/vlasov/creg/rt_can_pb_im_bgk_surf_flat.c @@ -19,8 +19,7 @@ #include -struct bgk_surf_flat_ctx -{ +struct bgk_surf_flat_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -54,8 +53,7 @@ struct bgk_surf_flat_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_surf_flat_ctx -create_ctx(void) +struct bgk_surf_flat_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -85,7 +83,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -114,14 +113,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_ctx *app = ctx; @@ -132,8 +130,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n0; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_ctx *app = ctx; @@ -143,8 +140,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T0; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_ctx *app = ctx; @@ -152,11 +148,11 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double Vy_drift = app->Vy_drift; // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_ctx *app = ctx; @@ -166,8 +162,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double p_x_dot = xn[2], p_y_dot = xn[3]; @@ -175,47 +170,47 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_x_y = 0.0; double inv_metric_y_y = 1.0; - double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + - (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + + (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double inv_metric_x_x = 1.0; // Inverse metric tensor (x-x component). double inv_metric_x_y = 0.0; // Inverse metric tensor (x-y component). double inv_metric_y_y = 1.0; // Inverse metric tensor (y-y component). - + // Set inverse metric tensor. - fout[0] = inv_metric_x_x; fout[1] = inv_metric_x_y; fout[2] = inv_metric_y_y; + fout[0] = inv_metric_x_x; + fout[1] = inv_metric_x_y; + fout[2] = inv_metric_y_y; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_x_x = 1.0; // Metric tensor (x-x component). double metric_x_y = 0.0; // Metric tensor (x-y component). double metric_y_y = 1.0; // Metric tensor (y-y component). - + // Set Metric tensor. - fout[0] = metric_x_x; fout[1] = metric_x_y; fout[2] = metric_y_y; + fout[0] = metric_x_x; + fout[1] = metric_x_y; + fout[2] = metric_y_y; } - -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_det = 1.0; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -233,32 +228,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -285,18 +282,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -304,39 +300,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -360,10 +342,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -373,61 +356,57 @@ main(int argc, char **argv) .h_ij_inv_ctx = &ctx, .det_h = evalMetricDet, .det_h_ctx = &ctx, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 2, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .num_periodic_dir = 2, + .periodic_dirs = {0, 1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -441,10 +420,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -453,32 +436,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -494,7 +484,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -510,8 +500,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -519,7 +508,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -528,8 +519,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -549,14 +539,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_im_bgk_surf_flat_sq_ic.c b/vlasov/creg/rt_can_pb_im_bgk_surf_flat_sq_ic.c index 10897f43ad..69c7dfb85b 100644 --- a/vlasov/creg/rt_can_pb_im_bgk_surf_flat_sq_ic.c +++ b/vlasov/creg/rt_can_pb_im_bgk_surf_flat_sq_ic.c @@ -19,8 +19,7 @@ #include -struct bgk_surf_flat_sq_ctx -{ +struct bgk_surf_flat_sq_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -51,8 +50,7 @@ struct bgk_surf_flat_sq_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_surf_flat_sq_ctx -create_ctx(void) +struct bgk_surf_flat_sq_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -79,7 +77,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -105,14 +104,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeutInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_sq_ctx *app = ctx; double vx = xn[2], vy = xn[3]; @@ -124,8 +122,7 @@ evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if ((fabs(vx) < 1.0) && (fabs(vy) < 1.0)) { n = n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -133,8 +130,7 @@ evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = metric_det * n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_surf_flat_sq_ctx *app = ctx; @@ -144,8 +140,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double p_x_dot = xn[2], p_y_dot = xn[3]; @@ -153,47 +148,47 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_x_y = 0.0; double inv_metric_y_y = 1.0; - double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + - (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + + (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double inv_metric_x_x = 1.0; // Inverse metric tensor (x-x component). double inv_metric_x_y = 0.0; // Inverse metric tensor (x-y component). double inv_metric_y_y = 1.0; // Inverse metric tensor (y-y component). - + // Set inverse metric tensor. - fout[0] = inv_metric_x_x; fout[1] = inv_metric_x_y; fout[2] = inv_metric_y_y; + fout[0] = inv_metric_x_x; + fout[1] = inv_metric_x_y; + fout[2] = inv_metric_y_y; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_x_x = 1.0; // Metric tensor (x-x component). double metric_x_y = 0.0; // Metric tensor (x-y component). double metric_y_y = 1.0; // Metric tensor (y-y component). - + // Set Metric tensor. - fout[0] = metric_x_x; fout[1] = metric_x_y; fout[2] = metric_y_y; + fout[0] = metric_x_x; + fout[1] = metric_x_y; + fout[2] = metric_y_y; } - -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_det = 1.0; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -211,32 +206,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -263,18 +260,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -282,39 +278,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -338,10 +320,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -351,53 +334,46 @@ main(int argc, char **argv) .h_ij_inv_ctx = &ctx, .det_h = evalMetricDet, .det_h_ctx = &ctx, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalNeutInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalNeutInit, .ctx_func = &ctx}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 2, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .num_periodic_dir = 2, + .periodic_dirs = {0, 1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -411,10 +387,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -423,32 +403,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -464,7 +451,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -480,8 +467,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -489,7 +475,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -498,8 +486,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -519,14 +506,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_neut_bgk_sodshock_1x1v_p2.c b/vlasov/creg/rt_can_pb_neut_bgk_sodshock_1x1v_p2.c index 28d2581768..515a299a21 100644 --- a/vlasov/creg/rt_can_pb_neut_bgk_sodshock_1x1v_p2.c +++ b/vlasov/creg/rt_can_pb_neut_bgk_sodshock_1x1v_p2.c @@ -20,8 +20,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -54,8 +53,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -84,9 +82,10 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. - int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct sodshock_ctx ctx = { .mass = mass, @@ -111,14 +110,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -130,8 +128,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -141,8 +138,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -154,8 +150,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -163,8 +158,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -176,8 +170,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (x < 0.5) { Vx_drift = Vx_drift_l; // Total drift velocity (left). - } - else { + } else { Vx_drift = Vx_drift_r; // Total drift velocity (right). } @@ -185,8 +178,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = Vx_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -196,47 +188,42 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double p_x_dot = xn[1]; double inv_metric_x_x = 1.0; double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot); // Canonical Hamiltonian. - + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double inv_metric_x_x = 1.0; // Inverse metric tensor (x-x component). - + // Set inverse metric tensor. fout[0] = inv_metric_x_x; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_x_x = 1.0; // Metric tensor (x-x component). - + // Set metric tensor. fout[0] = metric_x_x; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_det = 1.0; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -254,32 +241,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -304,18 +293,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -323,39 +311,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -379,10 +353,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -394,60 +369,55 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = true, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = false, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = false, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 1, - .species = { neut }, + .species = {neut}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -461,10 +431,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -473,32 +447,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -514,7 +495,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -530,8 +511,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -539,7 +519,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -548,8 +530,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -569,14 +550,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x1v_p1.c b/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x1v_p1.c index 3fb21e50ff..e01577c8a4 100644 --- a/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x1v_p1.c +++ b/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x1v_p1.c @@ -20,8 +20,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -54,8 +53,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -84,9 +82,10 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. - int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct sodshock_ctx ctx = { .mass = mass, @@ -111,14 +110,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -130,8 +128,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -141,8 +138,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -154,8 +150,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -163,8 +158,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -176,8 +170,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (x < 0.5) { Vx_drift = Vx_drift_l; // Total drift velocity (left). - } - else { + } else { Vx_drift = Vx_drift_r; // Total drift velocity (right). } @@ -185,8 +178,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = Vx_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -196,47 +188,42 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double p_x_dot = xn[1]; double inv_metric_x_x = 1.0; double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot); // Canonical Hamiltonian. - + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double inv_metric_x_x = 1.0; // Inverse metric tensor (x-x component). - + // Set inverse metric tensor. fout[0] = inv_metric_x_x; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_x_x = 1.0; // Metric tensor (x-x component). - + // Set metric tensor. fout[0] = metric_x_x; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_det = 1.0; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -254,32 +241,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -304,18 +293,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -323,39 +311,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -379,10 +353,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -394,60 +369,55 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = true, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 1, - .species = { neut }, + .species = {neut}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -461,10 +431,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -473,32 +447,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -514,7 +495,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -530,8 +511,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -539,7 +519,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -548,8 +530,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -569,14 +550,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x1v_p2.c b/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x1v_p2.c index 3e53175af7..d9e39346b7 100644 --- a/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x1v_p2.c +++ b/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x1v_p2.c @@ -20,8 +20,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -54,8 +53,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -84,9 +82,10 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. - int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct sodshock_ctx ctx = { .mass = mass, @@ -111,14 +110,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -130,19 +128,17 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } - + double metric_det = 1.0; // Set total number density. fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -154,8 +150,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -163,8 +158,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -176,8 +170,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (x < 0.5) { Vx_drift = Vx_drift_l; // Total drift velocity (left). - } - else { + } else { Vx_drift = Vx_drift_r; // Total drift velocity (right). } @@ -185,8 +178,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = Vx_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -196,47 +188,42 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double p_x_dot = xn[1]; double inv_metric_x_x = 1.0; double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot); // Canonical Hamiltonian. - + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double inv_metric_x_x = 1.0; // Inverse metric tensor (x-x component). - + // Set inverse metric tensor. fout[0] = inv_metric_x_x; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_x_x = 1.0; // Metric tensor (x-x component). - + // Set metric tensor. fout[0] = metric_x_x; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_det = 1.0; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -254,32 +241,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -304,18 +293,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -323,39 +311,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -379,10 +353,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -394,60 +369,55 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = true, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 1, - .species = { neut }, + .species = {neut}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -461,10 +431,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -473,32 +447,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -514,7 +495,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -530,8 +511,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -539,7 +519,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -548,8 +530,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -569,14 +550,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x2v_p1.c b/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x2v_p1.c index f59367e92d..976a3e6886 100644 --- a/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x2v_p1.c +++ b/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x2v_p1.c @@ -20,8 +20,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -58,8 +57,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -92,9 +90,10 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. - int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct sodshock_ctx ctx = { .mass = mass, @@ -123,14 +122,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -142,8 +140,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -153,8 +150,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -166,8 +162,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -175,8 +170,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -193,18 +187,17 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (x < 0.5) { Vx_drift = Vx_drift_l; // Left drift velocity (x-direction). Vy_drift = Vy_drift_l; // Left drift velocity (y-direction). - } - else { + } else { Vx_drift = Vx_drift_r; // Right drift velocity (x-direction). Vy_drift = Vy_drift_r; // Right drift velocity (y-direction). } // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -214,8 +207,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double p_x_dot = xn[1], p_y_dot = xn[2]; @@ -223,46 +215,47 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_x_y = 0.0; double inv_metric_y_y = 1.0; - double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + - (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + + (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double inv_metric_x_x = 1.0; // Inverse metric tensor (x-x component). double inv_metric_x_y = 0.0; // Inverse metric tensor (x-y component). double inv_metric_y_y = 1.0; // Inverse mteric tensor (y-y component). - + // Set inverse metric tensor. - fout[0] = inv_metric_x_x; fout[1] = inv_metric_x_y; fout[2] = inv_metric_y_y; + fout[0] = inv_metric_x_x; + fout[1] = inv_metric_x_y; + fout[2] = inv_metric_y_y; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_x_x = 1.0; // Metric tensor (x-x component). double metric_x_y = 0.0; // Metric tensor (x-y component). double metric_y_y = 1.0; // Mteric tensor (y-y component). - + // Set Metric tensor. - fout[0] = metric_x_x; fout[1] = metric_x_y; fout[2] = metric_y_y; + fout[0] = metric_x_x; + fout[1] = metric_x_y; + fout[2] = metric_y_y; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_det = 1.0; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -280,32 +273,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -331,18 +326,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -350,39 +344,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -406,10 +386,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -421,60 +402,55 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = true, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 1, - .species = { neut }, + .species = {neut}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -488,10 +464,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -500,32 +480,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -541,7 +528,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -557,8 +544,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -566,7 +552,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -575,8 +563,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -596,14 +583,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x2v_p2.c b/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x2v_p2.c index 3dd5aae46d..e92d67f6e0 100644 --- a/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x2v_p2.c +++ b/vlasov/creg/rt_can_pb_neut_bgk_sodshock_im_1x2v_p2.c @@ -20,8 +20,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -58,8 +57,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -92,9 +90,10 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. - int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct sodshock_ctx ctx = { .mass = mass, @@ -123,14 +122,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -142,8 +140,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -153,8 +150,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = metric_det * n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -166,8 +162,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -175,8 +170,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -193,18 +187,17 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (x < 0.5) { Vx_drift = Vx_drift_l; // Left drift velocity (x-direction). Vy_drift = Vy_drift_l; // Left drift velocity (y-direction). - } - else { + } else { Vx_drift = Vx_drift_r; // Right drift velocity (x-direction). Vy_drift = Vy_drift_r; // Right drift velocity (y-direction). } // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -214,8 +207,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double p_x_dot = xn[1], p_y_dot = xn[2]; @@ -223,46 +215,47 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_x_y = 0.0; double inv_metric_y_y = 1.0; - double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + - (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. - + double hamiltonian = (0.5 * inv_metric_x_x * p_x_dot * p_x_dot) + + (0.5 * (2.0 * inv_metric_x_y * p_x_dot * p_y_dot)) + + (0.5 * inv_metric_y_y * p_y_dot * p_y_dot); // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double inv_metric_x_x = 1.0; // Inverse metric tensor (x-x component). double inv_metric_x_y = 0.0; // Inverse metric tensor (x-y component). double inv_metric_y_y = 1.0; // Inverse mteric tensor (y-y component). - + // Set inverse metric tensor. - fout[0] = inv_metric_x_x; fout[1] = inv_metric_x_y; fout[2] = inv_metric_y_y; + fout[0] = inv_metric_x_x; + fout[1] = inv_metric_x_y; + fout[2] = inv_metric_y_y; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_x_x = 1.0; // Metric tensor (x-x component). double metric_x_y = 0.0; // Metric tensor (x-y component). double metric_y_y = 1.0; // Mteric tensor (y-y component). - + // Set Metric tensor. - fout[0] = metric_x_x; fout[1] = metric_x_y; fout[2] = metric_y_y; + fout[0] = metric_x_x; + fout[1] = metric_x_y; + fout[2] = metric_y_y; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double metric_det = 1.0; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -280,32 +273,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -331,18 +326,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -350,39 +344,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -406,10 +386,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -421,60 +402,55 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = true, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = true, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = true, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + .num_diag_moments = 4, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE, GKYL_F_MOMENT_ENERGY} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 1, - .species = { neut }, + .species = {neut}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -488,10 +464,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -500,32 +480,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -541,7 +528,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -557,8 +544,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -566,7 +552,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -575,8 +563,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -596,14 +583,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_can_pb_newtonian_orbits_2x2v_p2.c b/vlasov/creg/rt_can_pb_newtonian_orbits_2x2v_p2.c index 4684ba85f6..6a32e98438 100644 --- a/vlasov/creg/rt_can_pb_newtonian_orbits_2x2v_p2.c +++ b/vlasov/creg/rt_can_pb_newtonian_orbits_2x2v_p2.c @@ -22,8 +22,7 @@ #include -struct star_newtonian_static_ctx -{ +struct star_newtonian_static_ctx { // Mathematical constants (dimensionless). double pi; @@ -59,8 +58,7 @@ struct star_newtonian_static_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct star_newtonian_static_ctx -create_ctx(void) +struct star_newtonian_static_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -68,8 +66,8 @@ create_ctx(void) // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. double charge = 0.0; // Neutral charge. - double nu = 2*pi; // Collision frequency. - + double nu = 2 * pi; // Collision frequency. + // Spacetime parameters (using geometric units). double star_mass = 1.0; // Mass of the black hole. double bh_spin = 0.0; // Spin of the black hole. @@ -87,8 +85,10 @@ create_ctx(void) int Nvtheta = 32; // Cell count (velocity space: azimuthal angular direction). double Lr_min = 0.5; // Domain size radius min (configuration space: radial direction). double Lr_max = 2.0; // Domain size radius max (configuration space: radial direction). - double Ltheta_min = 0.0; // Domain size minimum (configuration space: azimuthal angular direction). - double Ltheta_max = 2.0 * pi; // Domain size maximum (configuration space: azimuthal angular direction). + double Ltheta_min = + 0.0; // Domain size minimum (configuration space: azimuthal angular direction). + double Ltheta_max = + 2.0 * pi; // Domain size maximum (configuration space: azimuthal angular direction). double v_r_max = 0.5 * vt; // Domain boundary (velocity space: radial direction). double v_theta_max = 3.0 * vt; // Domain boundary (velocity space: azimuthal angular direction). int poly_order = 2; // Polynomial order. @@ -98,7 +98,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -127,14 +128,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct star_newtonian_static_ctx *app = ctx; @@ -144,36 +144,33 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -evalInitialf(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInitialf(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct star_newtonian_static_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1], p_r_dot = xn[2], p_theta_dot = xn[3]; double metric_det = q_r; // Metric tensor determinant. - double dr = (app->Lr_max - app->Lr_min)/app->Nr; - double dtheta = (app->Ltheta_max - app->Ltheta_min)/app->Ntheta; - double dpr = (2.0*app->v_r_max)/app->Nvr; - double dptheta = (2.0*app->v_theta_max)/app->Nvtheta; + double dr = (app->Lr_max - app->Lr_min) / app->Nr; + double dtheta = (app->Ltheta_max - app->Ltheta_min) / app->Ntheta; + double dpr = (2.0 * app->v_r_max) / app->Nvr; + double dptheta = (2.0 * app->v_theta_max) / app->Nvtheta; double pi = app->pi; double f = 0.0; // background distribution function - - // Initalize f's positisional amplitude in space + + // Initalize f's positisional amplitude in space // Init with a sqaure function in momentum space // around orbital speed p_theta = r (for circular orbits) // and r_dot = 0 const double sigma = 0.15; - if ((p_r_dot > - 0.1) && (p_r_dot < 0.1)){ - if ((p_theta_dot > sqrt(q_r - 0.1)) && (p_theta_dot < sqrt(q_r + 0.1))){ + if ((p_r_dot > -0.1) && (p_r_dot < 0.1)) { + if ((p_theta_dot > sqrt(q_r - 0.1)) && (p_theta_dot < sqrt(q_r + 0.1))) { if (q_r < 1.0) { - f = 0.1 + 0.9 * exp(-((q_r - 1.0) * (q_r - 1.0)) / (2.0 * sigma * sigma)); - } - else if (q_r > 1.5) { - f = 0.1 + 0.9 * exp(-((q_r - 1.5) * (q_r - 1.5)) / (2.0 * sigma * sigma)); - } - else { - f = 1.0; + f = 0.1 + 0.9 * exp(-((q_r - 1.0) * (q_r - 1.0)) / (2.0 * sigma * sigma)); + } else if (q_r > 1.5) { + f = 0.1 + 0.9 * exp(-((q_r - 1.5) * (q_r - 1.5)) / (2.0 * sigma * sigma)); + } else { + f = 1.0; } } } @@ -182,11 +179,10 @@ evalInitialf(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou // Set distribution function, multiply by jacobian for the correct density double jac = q_r; - fout[0] = jac*f; + fout[0] = jac * f; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct star_newtonian_static_ctx *app = ctx; @@ -194,32 +190,36 @@ evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). - + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + // H = \alpha \gamma - \beta \cdot p - double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + - (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) - 1.0/q_r; // Canonical Hamiltonian, with gravity (Newtonian) - + double hamiltonian = (0.5 * inv_metric_r_r * p_r_dot * p_r_dot) + + (0.5 * (2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot)) + + (0.5 * inv_metric_theta_theta * p_theta_dot * p_theta_dot) - + 1.0 / q_r; // Canonical Hamiltonian, with gravity (Newtonian) + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct star_newtonian_static_ctx *app = ctx; double q_r = xn[0]; double inv_metric_r_r = 1.0; // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). - + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_theta_theta; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_theta_theta; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct star_newtonian_static_ctx *app = ctx; double q_r = xn[0]; @@ -227,24 +227,24 @@ evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double metric_r_r = 1.0; //Metric tensor (radial-radial component). double metric_r_theta = 0.0; //Metric tensor (radial-angular component). double metric_theta_theta = q_r * q_r; //Metric tensor (angular-angular component). - + // Set metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_theta_theta; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_theta_theta; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_det = q_r; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -262,32 +262,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -314,18 +316,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { Nr, Ntheta }; + int ccells[] = {Nr, Ntheta}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -333,39 +334,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -389,10 +376,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.v_r_max, -1.0 }, - .upper = { ctx.v_r_max, ctx.v_theta_max}, - .cells = { Nvr, Nvtheta }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.v_r_max, -1.0}, + .upper = {ctx.v_r_max, ctx.v_theta_max}, + .cells = {Nvr, Nvtheta}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -404,57 +392,47 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = false, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalInitialf, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .has_implicit_coll_scheme = true, - .correct_all_moms = false, - .iter_eps = 0.0, - .max_iter = 0, - .use_last_converged = false, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_ABSORB, }, - }, - + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalInitialf, .ctx_func = &ctx}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + .ctx = &ctx, + .has_implicit_coll_scheme = true, + .correct_all_moms = false, + .iter_eps = 0.0, + .max_iter = 0, + .use_last_converged = false}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_ABSORB}}, + .num_diag_moments = 2, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1_FROM_H }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1_FROM_H} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { ctx.Lr_min, ctx.Ltheta_min }, - .upper = { ctx.Lr_max, ctx.Ltheta_max }, - .cells = { Nr, Ntheta }, + .cdim = 2, + .vdim = 2, + .lower = {ctx.Lr_min, ctx.Ltheta_min}, + .upper = {ctx.Lr_max, ctx.Ltheta_max}, + .cells = {Nr, Ntheta}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -468,10 +446,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -480,32 +462,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -521,7 +510,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -537,8 +526,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -546,7 +534,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -555,8 +545,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -576,14 +565,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_dg_5m_mom_beach_p2.c b/vlasov/creg/rt_dg_5m_mom_beach_p2.c index 9bc890dfa8..247ef7e567 100644 --- a/vlasov/creg/rt_dg_5m_mom_beach_p2.c +++ b/vlasov/creg/rt_dg_5m_mom_beach_p2.c @@ -23,8 +23,7 @@ #include -struct mom_beach_ctx -{ +struct mom_beach_ctx { // Mathematical constants (dimensionless). double pi; @@ -36,7 +35,7 @@ struct mom_beach_ctx double charge_elc; // Electron charge. double J0; // Reference current density (Amps / m^3). - + // Derived physical quantities (using non-normalized physical units). double light_speed; // Speed of light. @@ -61,8 +60,7 @@ struct mom_beach_ctx double omega_drive; // Drive current angular frequency. }; -struct mom_beach_ctx -create_ctx(void) +struct mom_beach_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -75,7 +73,7 @@ create_ctx(void) double charge_elc = -1.602176487e-19; // Electron charge. double J0 = 1.0e-12; // Reference current density (Amps / m^3). - + // Derived physical quantities (using non-normalized physical units). double light_speed = 1.0 / sqrt(mu0 * epsilon0); // Speed of light. @@ -91,12 +89,15 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double deltaT = Lx100 / light_speed; // Arbitrary constant, with units of time. - double factor = deltaT * deltaT * charge_elc * charge_elc / (mass_elc * epsilon0); // Numerical factor for calculation of electron number density. + double factor = + deltaT * deltaT * charge_elc * charge_elc / + (mass_elc * epsilon0); // Numerical factor for calculation of electron number density. double omega_drive = pi / 10.0 / deltaT; // Drive current angular frequency. struct mom_beach_ctx ctx = { @@ -123,14 +124,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .deltaT = deltaT, .factor = factor, - .omega_drive = omega_drive, + .omega_drive = omega_drive }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct mom_beach_ctx *app = ctx; @@ -139,9 +139,10 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double mass_elc = app->mass_elc; double charge_elc = app->charge_elc; - double factor = app ->factor; + double factor = app->factor; - double omegaPdt = 25.0 * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x); // Plasma frequency profile. + double omegaPdt = + 25.0 * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x); // Plasma frequency profile. double ne = omegaPdt * omegaPdt / factor + 1.0; // Electron number density (with density floor). double rhoe = mass_elc * ne; // Electron mass density. @@ -153,13 +154,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -170,15 +172,17 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAppCurrent(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct mom_beach_ctx *app = ctx; @@ -193,17 +197,17 @@ evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (x > x_last_edge) { app_y = -J0 * sin(omega_drive * t); // Applied current (y-direction, right). - } - else { + } else { app_y = 0.0; // Applied current (y-direction, left). } - + // Set applied current. - fout[0] = app_x; fout[1] = app_y; fout[2] = app_z; + fout[0] = app_x; + fout[1] = app_y; + fout[2] = app_z; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -221,32 +225,28 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr) +void calc_field_energy(struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr)) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr) +void calc_integrated_mom(struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr)) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr) +void calc_integrated_L2_f(struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr)) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -270,28 +270,30 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, .init = evalElcInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .limit_em = true, - + .init = evalFieldInit, .ctx = &ctx, .app_current = evalAppCurrent, .app_current_ctx = &ctx, .app_current_evolve = true, - .bcx = { GKYL_FIELD_COPY, GKYL_FIELD_COPY }, + .bcx = {GKYL_FIELD_COPY, GKYL_FIELD_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -301,7 +303,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -309,8 +311,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -324,22 +325,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -362,31 +353,28 @@ main(int argc, char **argv) // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 0, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 0, - .species = { }, + .species = {}, .num_fluid_species = 1, - .fluid_species = { elc }, + .fluid_species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -400,10 +388,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -412,32 +404,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -453,7 +452,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -469,8 +468,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -478,11 +476,12 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -502,19 +501,27 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - + freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(elc_euler); @@ -527,6 +534,6 @@ main(int argc, char **argv) MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_5m_mom_beach_p3.c b/vlasov/creg/rt_dg_5m_mom_beach_p3.c index 79e8ff927d..10bb9f5977 100644 --- a/vlasov/creg/rt_dg_5m_mom_beach_p3.c +++ b/vlasov/creg/rt_dg_5m_mom_beach_p3.c @@ -23,8 +23,7 @@ #include -struct mom_beach_ctx -{ +struct mom_beach_ctx { // Mathematical constants (dimensionless). double pi; @@ -36,7 +35,7 @@ struct mom_beach_ctx double charge_elc; // Electron charge. double J0; // Reference current density (Amps / m^3). - + // Derived physical quantities (using non-normalized physical units). double light_speed; // Speed of light. @@ -61,8 +60,7 @@ struct mom_beach_ctx double omega_drive; // Drive current angular frequency. }; -struct mom_beach_ctx -create_ctx(void) +struct mom_beach_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -75,7 +73,7 @@ create_ctx(void) double charge_elc = -1.602176487e-19; // Electron charge. double J0 = 1.0e-12; // Reference current density (Amps / m^3). - + // Derived physical quantities (using non-normalized physical units). double light_speed = 1.0 / sqrt(mu0 * epsilon0); // Speed of light. @@ -91,12 +89,15 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. double deltaT = Lx100 / light_speed; // Arbitrary constant, with units of time. - double factor = deltaT * deltaT * charge_elc * charge_elc / (mass_elc * epsilon0); // Numerical factor for calculation of electron number density. + double factor = + deltaT * deltaT * charge_elc * charge_elc / + (mass_elc * epsilon0); // Numerical factor for calculation of electron number density. double omega_drive = pi / 10.0 / deltaT; // Drive current angular frequency. struct mom_beach_ctx ctx = { @@ -123,14 +124,13 @@ create_ctx(void) .num_failures_max = num_failures_max, .deltaT = deltaT, .factor = factor, - .omega_drive = omega_drive, + .omega_drive = omega_drive }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct mom_beach_ctx *app = ctx; @@ -139,9 +139,10 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double mass_elc = app->mass_elc; double charge_elc = app->charge_elc; - double factor = app ->factor; + double factor = app->factor; - double omegaPdt = 25.0 * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x); // Plasma frequency profile. + double omegaPdt = + 25.0 * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x) * (1.0 - x); // Plasma frequency profile. double ne = omegaPdt * omegaPdt / factor + 1.0; // Electron number density (with density floor). double rhoe = mass_elc * ne; // Electron mass density. @@ -153,13 +154,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout // Set electron mass density. fout[0] = rhoe; // Set electron momentum density. - fout[1] = mome_x; fout[2] = mome_y; fout[3] = mome_z; + fout[1] = mome_x; + fout[2] = mome_y; + fout[3] = mome_z; // Set electron total energy density. fout[4] = Ee_tot; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -170,15 +172,17 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAppCurrent(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct mom_beach_ctx *app = ctx; @@ -193,17 +197,17 @@ evalAppCurrent(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f if (x > x_last_edge) { app_y = -J0 * sin(omega_drive * t); // Applied current (y-direction, right). - } - else { + } else { app_y = 0.0; // Applied current (y-direction, left). } - + // Set applied current. - fout[0] = app_x; fout[1] = app_y; fout[2] = app_z; + fout[0] = app_x; + fout[1] = app_y; + fout[2] = app_z; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -221,32 +225,28 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr) +void calc_field_energy(struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr)) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr) +void calc_integrated_mom(struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr)) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr) +void calc_integrated_L2_f(struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr)) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -270,28 +270,30 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, .equation = elc_euler, .init = evalElcInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .limit_em = true, - + .init = evalFieldInit, .ctx = &ctx, .app_current = evalAppCurrent, .app_current_ctx = &ctx, .app_current_evolve = true, - .bcx = { GKYL_FIELD_COPY, GKYL_FIELD_COPY }, + .bcx = {GKYL_FIELD_COPY, GKYL_FIELD_COPY} }; int nrank = 1; // Number of processes in simulation. @@ -301,7 +303,7 @@ main(int argc, char **argv) } #endif - int cells[] = { NX }; + int cells[] = {NX}; int dim = sizeof(cells) / sizeof(cells[0]); int cuts[dim]; @@ -309,8 +311,7 @@ main(int argc, char **argv) for (int d = 0; d < dim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -324,22 +325,12 @@ main(int argc, char **argv) struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -362,31 +353,28 @@ main(int argc, char **argv) // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 0, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 0, - .species = { }, + .species = {}, .num_fluid_species = 1, - .fluid_species = { elc }, + .fluid_species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -400,10 +388,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -412,32 +404,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -453,7 +452,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -469,8 +468,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -478,11 +476,12 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -502,19 +501,27 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - + freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(elc_euler); @@ -527,6 +534,6 @@ main(int argc, char **argv) MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_accel_1x1v.c b/vlasov/creg/rt_dg_accel_1x1v.c index 271d6c5758..867214aaeb 100644 --- a/vlasov/creg/rt_dg_accel_1x1v.c +++ b/vlasov/creg/rt_dg_accel_1x1v.c @@ -19,8 +19,7 @@ #include -struct accel_ctx -{ +struct accel_ctx { // Mathematical constants (dimensionless). double pi; @@ -44,8 +43,7 @@ struct accel_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct accel_ctx -create_ctx(void) +struct accel_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -63,12 +61,12 @@ create_ctx(void) double Lvx = 12.0; // Domain size (velocity space: vx-direction). int poly_order = 2; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. - + double t_end = 3.0; // Final simulation time. int num_frames = 1; // Number of output frames. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct accel_ctx ctx = { .pi = pi, .epsilon0 = epsilon0, @@ -84,46 +82,47 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double vx = xn[1]; struct accel_ctx *app = ctx; double pi = app->pi; - + // Set electron distribution function. fout[0] = 1 / sqrt(2.0 * pi) * exp(-0.5 * (vx * vx)); } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { // Set electric field. - fout[0] = 0.0; fout[1] = 0.0, fout[2] = 0.0; + fout[0] = 0.0; + fout[1] = 0.0, fout[2] = 0.0; // Set magnetic field. - fout[3] = 0.0; fout[4] = 0.0; fout[5] = 0.0; + fout[3] = 0.0; + fout[4] = 0.0; + fout[5] = 0.0; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalAppAccel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAppAccel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; // Set applied acceleration. - fout[0] = sin(x); fout[1] = 0.0, fout[2] = 0.0; + fout[0] = sin(x); + fout[1] = 0.0, fout[2] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -138,8 +137,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -162,35 +160,33 @@ main(int argc, char **argv) // Electron species. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -0.5 * ctx.Lvx }, - .upper = { 0.5 * ctx.Lvx }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-0.5 * ctx.Lvx}, + .upper = {0.5 * ctx.Lvx}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, .app_accel = evalAppAccel, .app_accel_ctx = &ctx, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2, }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .is_static = true, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -198,18 +194,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -217,39 +212,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -271,29 +252,26 @@ main(int argc, char **argv) // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -306,7 +284,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_vlasov_app_apply_ic(app, t_curr); @@ -324,7 +302,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -337,8 +315,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -346,11 +323,12 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -367,14 +345,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); @@ -390,6 +376,6 @@ main(int argc, char **argv) MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_advect_1x_p1.c b/vlasov/creg/rt_dg_advect_1x_p1.c index f17d2a8423..bbbb5d42ca 100644 --- a/vlasov/creg/rt_dg_advect_1x_p1.c +++ b/vlasov/creg/rt_dg_advect_1x_p1.c @@ -22,8 +22,7 @@ #include -struct advect_ctx -{ +struct advect_ctx { // Mathematical constants (dimensionless). double pi; @@ -45,8 +44,7 @@ struct advect_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct advect_ctx -create_ctx(void) +struct advect_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -64,10 +62,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct advect_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -81,14 +80,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; @@ -98,8 +96,7 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct advect_ctx *app = ctx; @@ -110,11 +107,12 @@ evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -132,32 +130,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -182,13 +182,10 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -196,58 +193,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -270,31 +252,28 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 0, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -308,10 +287,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -320,32 +303,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -361,7 +351,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -377,8 +367,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -386,7 +375,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -395,8 +386,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -416,20 +406,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -441,6 +439,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_advect_1x_p2.c b/vlasov/creg/rt_dg_advect_1x_p2.c index bd044cabbd..54761239b8 100644 --- a/vlasov/creg/rt_dg_advect_1x_p2.c +++ b/vlasov/creg/rt_dg_advect_1x_p2.c @@ -22,8 +22,7 @@ #include -struct advect_ctx -{ +struct advect_ctx { // Mathematical constants (dimensionless). double pi; @@ -45,8 +44,7 @@ struct advect_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct advect_ctx -create_ctx(void) +struct advect_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -64,10 +62,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct advect_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -81,14 +80,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; @@ -98,8 +96,7 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct advect_ctx *app = ctx; @@ -110,11 +107,12 @@ evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -132,32 +130,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -182,13 +182,10 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -196,58 +193,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -270,31 +252,28 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 0, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -308,10 +287,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -320,32 +303,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -361,7 +351,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -377,8 +367,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -386,7 +375,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -395,8 +386,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -416,20 +406,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -441,6 +439,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_advect_2x_p1.c b/vlasov/creg/rt_dg_advect_2x_p1.c index adff6cd407..c2c00269e2 100644 --- a/vlasov/creg/rt_dg_advect_2x_p1.c +++ b/vlasov/creg/rt_dg_advect_2x_p1.c @@ -1,4 +1,4 @@ -// Constant advection in 2x using a p1 DG discretization of the advection equation. +// Constant advection in 2x using a p1 DG discretization of the advection equation. #include #include @@ -22,8 +22,7 @@ #include -struct advect_ctx -{ +struct advect_ctx { // Mathematical constants (dimensionless). double pi; @@ -51,15 +50,14 @@ struct advect_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct advect_ctx -create_ctx(void) +struct advect_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; // Physical constants (using normalized code units). double v_advect = 1.0; // Advection velocity. - + double r0 = 0.2; // Distribution radius. double x0 = 1.0 / 4.0; // Distribution center (x-coordinate). double y0 = 1.0 / 2.0; // Distribution center (y-coordinate). @@ -76,10 +74,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct advect_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -98,14 +97,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct advect_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -123,8 +121,7 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; @@ -133,11 +130,12 @@ evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -155,32 +153,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -206,13 +206,10 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -220,58 +217,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX, NY }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX, NY}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -294,31 +276,29 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 0, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 0, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -332,10 +312,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -344,32 +328,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -385,7 +376,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -401,8 +392,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -410,7 +400,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -419,8 +411,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -440,20 +431,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -465,6 +464,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_advect_2x_p2.c b/vlasov/creg/rt_dg_advect_2x_p2.c index 496b49115f..5f71954c8e 100644 --- a/vlasov/creg/rt_dg_advect_2x_p2.c +++ b/vlasov/creg/rt_dg_advect_2x_p2.c @@ -1,4 +1,4 @@ -// Constant advection in 2x using a p2 DG discretization of the advection equation. +// Constant advection in 2x using a p2 DG discretization of the advection equation. #include #include @@ -22,8 +22,7 @@ #include -struct advect_ctx -{ +struct advect_ctx { // Mathematical constants (dimensionless). double pi; @@ -51,15 +50,14 @@ struct advect_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct advect_ctx -create_ctx(void) +struct advect_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; // Physical constants (using normalized code units). double v_advect = 1.0; // Advection velocity. - + double r0 = 0.2; // Distribution radius. double x0 = 1.0 / 4.0; // Distribution center (x-coordinate). double y0 = 1.0 / 2.0; // Distribution center (y-coordinate). @@ -76,10 +74,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct advect_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -98,14 +97,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct advect_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -123,8 +121,7 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; @@ -133,11 +130,12 @@ evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -155,32 +153,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -206,13 +206,10 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -220,58 +217,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX, NY }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX, NY}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -294,31 +276,29 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 0, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 0, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -332,10 +312,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -344,32 +328,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -385,7 +376,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -401,8 +392,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -410,7 +400,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -419,8 +411,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -440,20 +431,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -465,6 +464,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_diffusion4_const_1x.c b/vlasov/creg/rt_dg_diffusion4_const_1x.c index c91c6034ac..018b434a91 100644 --- a/vlasov/creg/rt_dg_diffusion4_const_1x.c +++ b/vlasov/creg/rt_dg_diffusion4_const_1x.c @@ -22,8 +22,7 @@ #include -struct diffusion_ctx -{ +struct diffusion_ctx { // Mathematical constants (dimensionless). double pi; @@ -47,8 +46,7 @@ struct diffusion_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct diffusion_ctx -create_ctx(void) +struct diffusion_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -68,10 +66,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct diffusion_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -87,14 +86,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; @@ -104,19 +102,19 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double ux = 0.0; // Advection velocity (x-direction). double uy = 0.0; // Advection velocity (y-direction). double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -134,32 +132,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -184,17 +184,11 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, - .diffusion = { - .D = ctx.diffusion_coeff, - .order = ctx.diffusion_order, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, + .diffusion = {.D = ctx.diffusion_coeff, .order = ctx.diffusion_order}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -202,58 +196,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -276,31 +255,28 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 0, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -314,10 +290,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -326,32 +306,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -367,7 +354,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -383,8 +370,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -392,7 +378,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -401,8 +389,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -422,20 +409,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -447,6 +442,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_diffusion4_const_2x.c b/vlasov/creg/rt_dg_diffusion4_const_2x.c index 615d4fbd25..1e0a67c06e 100644 --- a/vlasov/creg/rt_dg_diffusion4_const_2x.c +++ b/vlasov/creg/rt_dg_diffusion4_const_2x.c @@ -22,8 +22,7 @@ #include -struct diffusion_ctx -{ +struct diffusion_ctx { // Mathematical constants (dimensionless). double pi; @@ -49,8 +48,7 @@ struct diffusion_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct diffusion_ctx -create_ctx(void) +struct diffusion_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -72,10 +70,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct diffusion_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -93,14 +92,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; @@ -110,19 +108,19 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double ux = 0.0; // Advection velocity (x-direction). double uy = 0.0; // Advection velocity (y-direction). double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -140,32 +138,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -191,17 +191,11 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, - .diffusion = { - .D = ctx.diffusion_coeff, - .order = ctx.diffusion_order, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, + .diffusion = {.D = ctx.diffusion_coeff, .order = ctx.diffusion_order}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -209,58 +203,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX, NY }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX, NY}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -283,31 +262,29 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 0, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 0, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -321,10 +298,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -333,32 +314,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -374,7 +362,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -390,8 +378,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -399,7 +386,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -408,8 +397,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -429,20 +417,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -454,6 +450,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_diffusion4_const_3x.c b/vlasov/creg/rt_dg_diffusion4_const_3x.c index 8ffd4bf5c2..17d2a4fe94 100644 --- a/vlasov/creg/rt_dg_diffusion4_const_3x.c +++ b/vlasov/creg/rt_dg_diffusion4_const_3x.c @@ -22,8 +22,7 @@ #include -struct diffusion_ctx -{ +struct diffusion_ctx { // Mathematical constants (dimensionless). double pi; @@ -51,8 +50,7 @@ struct diffusion_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct diffusion_ctx -create_ctx(void) +struct diffusion_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -76,10 +74,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct diffusion_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -99,14 +98,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; @@ -116,19 +114,19 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double ux = 0.0; // Advection velocity (x-direction). double uy = 0.0; // Advection velocity (y-direction). double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -146,32 +144,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -198,17 +198,11 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, - .diffusion = { - .D = ctx.diffusion_coeff, - .order = ctx.diffusion_order, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, + .diffusion = {.D = ctx.diffusion_coeff, .order = ctx.diffusion_order}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -216,58 +210,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX, NY, NZ }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX, NY, NZ}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -290,31 +269,31 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 3, .vdim = 0, - .lower = { 0.0, 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly, ctx.Lz }, - .cells = { NX, NY, NZ }, + .cdim = 3, + .vdim = 0, + .lower = {0.0, 0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly, ctx.Lz}, + .cells = {NX, NY, NZ}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 3, - .periodic_dirs = { 0, 1, 2 }, + .periodic_dirs = {0, 1, 2}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1], app_args.cuts[2] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, + .cuts = {app_args.cuts[0], app_args.cuts[1], app_args.cuts[2]}, + .comm = comm} }; // Create app object. @@ -328,10 +307,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -340,32 +323,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -381,7 +371,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -397,8 +387,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -406,7 +395,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -415,8 +406,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -436,20 +426,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -461,6 +459,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_diffusion6_const_1x.c b/vlasov/creg/rt_dg_diffusion6_const_1x.c index 26fb845695..f19ecbb6d7 100644 --- a/vlasov/creg/rt_dg_diffusion6_const_1x.c +++ b/vlasov/creg/rt_dg_diffusion6_const_1x.c @@ -22,8 +22,7 @@ #include -struct diffusion_ctx -{ +struct diffusion_ctx { // Mathematical constants (dimensionless). double pi; @@ -47,8 +46,7 @@ struct diffusion_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct diffusion_ctx -create_ctx(void) +struct diffusion_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -68,10 +66,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct diffusion_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -87,14 +86,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; @@ -104,19 +102,19 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double ux = 0.0; // Advection velocity (x-direction). double uy = 0.0; // Advection velocity (y-direction). double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -134,32 +132,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -184,17 +184,11 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, - .diffusion = { - .D = ctx.diffusion_coeff, - .order = ctx.diffusion_order, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, + .diffusion = {.D = ctx.diffusion_coeff, .order = ctx.diffusion_order}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -202,58 +196,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -276,31 +255,28 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 0, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -314,10 +290,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -326,32 +306,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -367,7 +354,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -383,8 +370,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -392,7 +378,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -401,8 +389,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -422,20 +409,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -447,6 +442,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_diffusion6_const_2x.c b/vlasov/creg/rt_dg_diffusion6_const_2x.c index d55d57d2aa..9307698a05 100644 --- a/vlasov/creg/rt_dg_diffusion6_const_2x.c +++ b/vlasov/creg/rt_dg_diffusion6_const_2x.c @@ -22,8 +22,7 @@ #include -struct diffusion_ctx -{ +struct diffusion_ctx { // Mathematical constants (dimensionless). double pi; @@ -49,8 +48,7 @@ struct diffusion_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct diffusion_ctx -create_ctx(void) +struct diffusion_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -72,10 +70,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct diffusion_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -93,14 +92,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; @@ -110,19 +108,19 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double ux = 0.0; // Advection velocity (x-direction). double uy = 0.0; // Advection velocity (y-direction). double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -140,32 +138,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -191,17 +191,11 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, - .diffusion = { - .D = ctx.diffusion_coeff, - .order = ctx.diffusion_order, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, + .diffusion = {.D = ctx.diffusion_coeff, .order = ctx.diffusion_order}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -209,58 +203,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX, NY }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX, NY}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -283,31 +262,29 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 0, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 0, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -321,10 +298,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -333,32 +314,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -374,7 +362,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -390,8 +378,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -399,7 +386,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -408,8 +397,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -429,20 +417,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -454,6 +450,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_diffusion6_const_3x.c b/vlasov/creg/rt_dg_diffusion6_const_3x.c index 26d316fecd..8c58686041 100644 --- a/vlasov/creg/rt_dg_diffusion6_const_3x.c +++ b/vlasov/creg/rt_dg_diffusion6_const_3x.c @@ -22,8 +22,7 @@ #include -struct diffusion_ctx -{ +struct diffusion_ctx { // Mathematical constants (dimensionless). double pi; @@ -51,8 +50,7 @@ struct diffusion_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct diffusion_ctx -create_ctx(void) +struct diffusion_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -76,10 +74,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct diffusion_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -99,14 +98,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; @@ -116,19 +114,19 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double ux = 0.0; // Advection velocity (x-direction). double uy = 0.0; // Advection velocity (y-direction). double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -146,32 +144,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -198,17 +198,11 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, - .diffusion = { - .D = ctx.diffusion_coeff, - .order = ctx.diffusion_order, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, + .diffusion = {.D = ctx.diffusion_coeff, .order = ctx.diffusion_order}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -216,58 +210,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX, NY, NZ }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX, NY, NZ}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -290,31 +269,31 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 3, .vdim = 0, - .lower = { 0.0, 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly, ctx.Lz }, - .cells = { NX, NY, NZ }, + .cdim = 3, + .vdim = 0, + .lower = {0.0, 0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly, ctx.Lz}, + .cells = {NX, NY, NZ}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 3, - .periodic_dirs = { 0, 1, 2 }, + .periodic_dirs = {0, 1, 2}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1], app_args.cuts[2] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, + .cuts = {app_args.cuts[0], app_args.cuts[1], app_args.cuts[2]}, + .comm = comm} }; // Create app object. @@ -328,10 +307,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -340,32 +323,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -381,7 +371,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -397,8 +387,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -406,7 +395,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -415,8 +406,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -436,20 +426,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -461,6 +459,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_diffusion_const_1x.c b/vlasov/creg/rt_dg_diffusion_const_1x.c index 3466ac8b4d..bfa1194723 100644 --- a/vlasov/creg/rt_dg_diffusion_const_1x.c +++ b/vlasov/creg/rt_dg_diffusion_const_1x.c @@ -22,8 +22,7 @@ #include -struct diffusion_ctx -{ +struct diffusion_ctx { // Mathematical constants (dimensionless). double pi; @@ -46,8 +45,7 @@ struct diffusion_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct diffusion_ctx -create_ctx(void) +struct diffusion_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -66,10 +64,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct diffusion_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -84,14 +83,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; @@ -101,19 +99,19 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double ux = 0.0; // Advection velocity (x-direction). double uy = 0.0; // Advection velocity (y-direction). double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -131,32 +129,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -181,16 +181,11 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, - .diffusion = { - .D = ctx.diffusion_coeff, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, + .diffusion = {.D = ctx.diffusion_coeff}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -198,58 +193,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -272,31 +252,28 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 0, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -310,10 +287,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -322,32 +303,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -363,7 +351,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -379,8 +367,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -388,7 +375,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -397,8 +386,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -418,20 +406,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -443,6 +439,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_diffusion_const_2x.c b/vlasov/creg/rt_dg_diffusion_const_2x.c index 45b8a62ba4..085c478bcb 100644 --- a/vlasov/creg/rt_dg_diffusion_const_2x.c +++ b/vlasov/creg/rt_dg_diffusion_const_2x.c @@ -22,8 +22,7 @@ #include -struct diffusion_ctx -{ +struct diffusion_ctx { // Mathematical constants (dimensionless). double pi; @@ -48,8 +47,7 @@ struct diffusion_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct diffusion_ctx -create_ctx(void) +struct diffusion_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -70,10 +68,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct diffusion_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -90,14 +89,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; @@ -107,19 +105,19 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double ux = 0.0; // Advection velocity (x-direction). double uy = 0.0; // Advection velocity (y-direction). double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -137,32 +135,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -188,16 +188,11 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, - .diffusion = { - .D = ctx.diffusion_coeff, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, + .diffusion = {.D = ctx.diffusion_coeff}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -205,58 +200,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX, NY }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX, NY}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -279,31 +259,29 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 0, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 0, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -317,10 +295,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -329,32 +311,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -370,7 +359,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -386,8 +375,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -395,7 +383,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -404,8 +394,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -425,20 +414,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -450,6 +447,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_diffusion_const_3x.c b/vlasov/creg/rt_dg_diffusion_const_3x.c index 53490bf3b2..214fde0e04 100644 --- a/vlasov/creg/rt_dg_diffusion_const_3x.c +++ b/vlasov/creg/rt_dg_diffusion_const_3x.c @@ -22,8 +22,7 @@ #include -struct diffusion_ctx -{ +struct diffusion_ctx { // Mathematical constants (dimensionless). double pi; @@ -50,8 +49,7 @@ struct diffusion_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct diffusion_ctx -create_ctx(void) +struct diffusion_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -74,10 +72,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct diffusion_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -96,14 +95,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; @@ -113,19 +111,19 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double ux = 0.0; // Advection velocity (x-direction). double uy = 0.0; // Advection velocity (y-direction). double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -143,32 +141,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -195,16 +195,11 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, - .diffusion = { - .D = ctx.diffusion_coeff, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, + .diffusion = {.D = ctx.diffusion_coeff}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -212,58 +207,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX, NY, NZ }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX, NY, NZ}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -286,31 +266,31 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 3, .vdim = 0, - .lower = { 0.0, 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly, ctx.Lz }, - .cells = { NX, NY, NZ }, + .cdim = 3, + .vdim = 0, + .lower = {0.0, 0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly, ctx.Lz}, + .cells = {NX, NY, NZ}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 3, - .periodic_dirs = { 0, 1, 2 }, + .periodic_dirs = {0, 1, 2}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1], app_args.cuts[2] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, + .cuts = {app_args.cuts[0], app_args.cuts[1], app_args.cuts[2]}, + .comm = comm} }; // Create app object. @@ -324,10 +304,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -336,32 +320,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -377,7 +368,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -393,8 +384,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -402,7 +392,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -411,8 +403,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -432,20 +423,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -457,6 +456,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_diffusion_gen_2x.c b/vlasov/creg/rt_dg_diffusion_gen_2x.c index 03b71ba9ab..8436153c87 100644 --- a/vlasov/creg/rt_dg_diffusion_gen_2x.c +++ b/vlasov/creg/rt_dg_diffusion_gen_2x.c @@ -22,8 +22,7 @@ #include -struct diffusion_ctx -{ +struct diffusion_ctx { // Mathematical constants (dimensionless). double pi; @@ -48,8 +47,7 @@ struct diffusion_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct diffusion_ctx -create_ctx(void) +struct diffusion_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -70,10 +68,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct diffusion_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -90,22 +89,20 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; double f = 0.0; if (fabs(x) < 1.0 && fabs(y) < 1.0) { f = 1.0; // Advected quantity (interior). - } - else { + } else { f = 0.0; // Advected quantity (exterior). } @@ -113,19 +110,21 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double ux = 0.0; // Advection velocity (x-direction). double uy = 0.0; // Advection velocity (y-direction). double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -evalDiffusionInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDiffusionInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct diffusion_ctx *app = ctx; @@ -134,13 +133,14 @@ evalDiffusionInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double diffusion_xx = diffusion_coeff; // Diffusion tensor (xx-component). double diffusion_xy = diffusion_coeff; // Diffusion tensor (xy-component). double diffusion_yy = diffusion_coeff; // Diffusion tensor (yy-component). - + // Set diffusion tensor. - fout[0] = diffusion_xx; fout[1] = diffusion_xy; fout[2] = diffusion_yy; + fout[0] = diffusion_xx; + fout[1] = diffusion_xy; + fout[2] = diffusion_yy; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -158,32 +158,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -209,17 +211,11 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, - .diffusion = { - .Dij = evalDiffusionInit, - .Dij_ctx = &ctx, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, + .diffusion = {.Dij = evalDiffusionInit, .Dij_ctx = &ctx}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -227,58 +223,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX, NY }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX, NY}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -301,31 +282,29 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 0, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 0, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -339,10 +318,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -351,32 +334,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -392,7 +382,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -408,8 +398,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -417,7 +406,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -426,8 +417,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -447,20 +437,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -472,6 +470,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_diffusion_gen_3x.c b/vlasov/creg/rt_dg_diffusion_gen_3x.c index 3ea756326a..605f02ccb6 100644 --- a/vlasov/creg/rt_dg_diffusion_gen_3x.c +++ b/vlasov/creg/rt_dg_diffusion_gen_3x.c @@ -22,8 +22,7 @@ #include -struct diffusion_ctx -{ +struct diffusion_ctx { // Mathematical constants (dimensionless). double pi; @@ -50,8 +49,7 @@ struct diffusion_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct diffusion_ctx -create_ctx(void) +struct diffusion_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -74,10 +72,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct diffusion_ctx ctx = { .pi = pi, .v_advect = v_advect, @@ -96,22 +95,20 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1], z = xn[2]; double f = 0.0; if (fabs(x) < 1.0 && fabs(y) < 1.0 && fabs(z) < 1.0) { f = 1.0; // Advected quantity (interior). - } - else { + } else { f = 0.0; // Advected quantity (exterior). } @@ -119,19 +116,21 @@ evalAdvectInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = f; } -void -evalAdvectVel(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalAdvectVel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double ux = 0.0; // Advection velocity (x-direction). double uy = 0.0; // Advection velocity (y-direction). double uz = 0.0; // Advection velocity (z-direction). // Set advection velocity. - fout[0] = ux; fout[1] = uy; fout[2] = uz; + fout[0] = ux; + fout[1] = uy; + fout[2] = uz; } -void -evalDiffusionInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDiffusionInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct diffusion_ctx *app = ctx; @@ -143,14 +142,17 @@ evalDiffusionInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double diffusion_yy = diffusion_coeff; // Diffusion tensor (yy-component). double diffusion_yz = diffusion_coeff; // Diffusion tensor (yz-component). double diffusion_zz = diffusion_coeff; // Diffusion tensor (zz-component). - + // Set diffusion tensor. - fout[0] = diffusion_xx; fout[1] = diffusion_xy; fout[2] = diffusion_xz; - fout[3] = diffusion_yy; fout[4] = diffusion_yz; fout[5] = diffusion_zz; + fout[0] = diffusion_xx; + fout[1] = diffusion_xy; + fout[2] = diffusion_xz; + fout[3] = diffusion_yy; + fout[4] = diffusion_yz; + fout[5] = diffusion_zz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -168,32 +170,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -220,17 +224,11 @@ main(int argc, char **argv) struct gkyl_vlasov_fluid_species fluid = { .name = "q", .equation = advect, - .advection = { - .velocity = evalAdvectVel, - .velocity_ctx = &ctx, - }, - .diffusion = { - .Dij = evalDiffusionInit, - .Dij_ctx = &ctx, - }, + .advection = {.velocity = evalAdvectVel, .velocity_ctx = &ctx}, + .diffusion = {.Dij = evalDiffusionInit, .Dij_ctx = &ctx}, .init = evalAdvectInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -238,58 +236,43 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif -int ccells[] = { NX, NY, NZ }; -int cdim = sizeof(ccells) / sizeof(ccells[0]); + int ccells[] = {NX, NY, NZ}; + int cdim = sizeof(ccells) / sizeof(ccells[0]); -int cuts[cdim]; -#ifdef GKYL_HAVE_MPI -for (int d = 0; d < cdim; d++) { - if (app_args.use_mpi) { - cuts[d] = app_args.cuts[d]; + int cuts[cdim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < cdim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } else { + cuts[d] = 1; + } } - else { +#else + for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -} -#else -for (int d = 0; d < cdim; d++) { - cuts[d] = 1; -} #endif - + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -312,31 +295,31 @@ for (int d = 0; d < cdim; d++) { // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 3, .vdim = 0, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly, -0.5 * ctx.Lz }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly, 0.5 * ctx.Lz }, - .cells = { NX, NY, NZ }, + .cdim = 3, + .vdim = 0, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly, -0.5 * ctx.Lz}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly, 0.5 * ctx.Lz}, + .cells = {NX, NY, NZ}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 3, - .periodic_dirs = { 0, 1, 2 }, + .periodic_dirs = {0, 1, 2}, .num_species = 0, - .species = { }, - + .species = {}, + .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1], app_args.cuts[2] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, + .cuts = {app_args.cuts[0], app_args.cuts[1], app_args.cuts[2]}, + .comm = comm} }; // Create app object. @@ -350,10 +333,14 @@ for (int d = 0; d < cdim; d++) { // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -362,32 +349,39 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } - + // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -403,7 +397,7 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -419,8 +413,7 @@ for (int d = 0; d < cdim; d++) { if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -428,7 +421,9 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -437,8 +432,7 @@ for (int d = 0; d < cdim; d++) { break; } - } - else { + } else { num_failures = 0; } @@ -458,20 +452,28 @@ for (int d = 0; d < cdim; d++) { gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(advect); gkyl_comm_release(comm); @@ -483,6 +485,6 @@ for (int d = 0; d < cdim; d++) { MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_euler_kh_2d.c b/vlasov/creg/rt_dg_euler_kh_2d.c index 3951497223..a0fabc61d6 100644 --- a/vlasov/creg/rt_dg_euler_kh_2d.c +++ b/vlasov/creg/rt_dg_euler_kh_2d.c @@ -26,8 +26,7 @@ #include -struct kh_2d_ctx -{ +struct kh_2d_ctx { // Mathematical constants (dimensionless). double pi; @@ -58,8 +57,7 @@ struct kh_2d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct kh_2d_ctx -create_ctx(void) +struct kh_2d_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -109,31 +107,30 @@ create_ctx(void) .t_end = t_end, .num_frames = num_frames, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct kh_2d_ctx *app = ctx; - double pi = app -> pi; + double pi = app->pi; + + double gas_gamma = app->gas_gamma; - double gas_gamma = app -> gas_gamma; - - double rhol = app -> rhol; - double ul = app -> ul; - double pl = app -> pl; + double rhol = app->rhol; + double ul = app->ul; + double pl = app->pl; - double rhor = app -> rhor; - double ur = app -> ur; - double pr = app -> pr; + double rhor = app->rhor; + double ur = app->ur; + double pr = app->pr; - double yloc = app -> yloc; + double yloc = app->yloc; double rho = 0.0; double vx = 0.0; @@ -144,8 +141,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left/inner). vx = ul; // Fluid x-velocity (left/inner). p = pl; // Fluid pressure (left/inner). - } - else { + } else { rho = rhor; // Fluid mass density (right/outer). vx = ur; // Fluid x-velocity (right/outer). p = pr; // Fluid pressure (right/outer). @@ -158,21 +154,24 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - vx += alpha * gkyl_pcg64_rand_double(&rng) * sin(i * k * x + j * k * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); - vy += alpha * gkyl_pcg64_rand_double(&rng) * sin(i * k * x + j * k * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); + vx += alpha * gkyl_pcg64_rand_double(&rng) * + sin(i * k * x + j * k * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); + vy += alpha * gkyl_pcg64_rand_double(&rng) * + sin(i * k * x + j * k * y + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); } } // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = rho * vx; fout[2] = rho * vy; fout[3] = 0.0; + fout[1] = rho * vx; + fout[2] = rho * vy; + fout[3] = 0.0; // Set fluid total energy density. fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * (vx * vx + vy * vy); } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { int frame = iot->curr - 1; @@ -187,8 +186,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -212,10 +210,7 @@ main(int argc, char **argv) struct gkyl_wv_eqn *euler = gkyl_wv_euler_new(ctx.gas_gamma, app_args.use_gpu); struct gkyl_vlasov_fluid_species fluid = { - .name = "euler", - .equation = euler, - .init = evalEulerInit, - .ctx = &ctx, + .name = "euler", .equation = euler, .init = evalEulerInit, .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -223,18 +218,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -242,39 +236,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -297,31 +277,29 @@ main(int argc, char **argv) // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 0, - .lower = { -0.5 * ctx.Lx, -0.5 * ctx.Ly }, - .upper = { 0.5 * ctx.Lx, 0.5 * ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 0, + .lower = {-0.5 * ctx.Lx, -0.5 * ctx.Ly}, + .upper = {0.5 * ctx.Lx, 0.5 * ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 0, - .species = { }, + .species = {}, .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -334,7 +312,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_vlasov_app_apply_ic(app, t_curr); @@ -352,7 +330,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -365,8 +343,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -374,11 +351,12 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -395,14 +373,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_dg_euler_p_perturbation_p1.c b/vlasov/creg/rt_dg_euler_p_perturbation_p1.c index ac045b39c4..a770548470 100644 --- a/vlasov/creg/rt_dg_euler_p_perturbation_p1.c +++ b/vlasov/creg/rt_dg_euler_p_perturbation_p1.c @@ -20,8 +20,7 @@ #include -struct p_perturbation_ctx -{ +struct p_perturbation_ctx { // Mathematical constants (dimensionless). double pi; @@ -45,8 +44,7 @@ struct p_perturbation_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct p_perturbation_ctx -create_ctx(void) +struct p_perturbation_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -66,7 +64,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -84,14 +83,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct p_perturbation_ctx *app = ctx; @@ -109,13 +107,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -133,32 +132,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -181,10 +182,7 @@ main(int argc, char **argv) struct gkyl_wv_eqn *euler = gkyl_wv_euler_new(ctx.gas_gamma, app_args.use_gpu); struct gkyl_vlasov_fluid_species fluid = { - .name = "euler", - .equation = euler, - .init = evalEulerInit, - .ctx = &ctx, + .name = "euler", .equation = euler, .init = evalEulerInit, .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -192,18 +190,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -211,39 +208,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -266,31 +249,28 @@ main(int argc, char **argv) // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 0, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 0, - .species = { }, + .species = {}, .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -304,10 +284,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -316,32 +300,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -357,7 +348,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -373,8 +364,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -382,7 +372,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -391,8 +383,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -412,19 +403,27 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - + freeresources: // Free resources after simulation completion. gkyl_wv_eqn_release(euler); @@ -437,6 +436,6 @@ main(int argc, char **argv) MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_euler_p_perturbation_p2.c b/vlasov/creg/rt_dg_euler_p_perturbation_p2.c index c78a0dfe21..ce89be63e4 100644 --- a/vlasov/creg/rt_dg_euler_p_perturbation_p2.c +++ b/vlasov/creg/rt_dg_euler_p_perturbation_p2.c @@ -20,8 +20,7 @@ #include -struct p_perturbation_ctx -{ +struct p_perturbation_ctx { // Mathematical constants (dimensionless). double pi; @@ -45,8 +44,7 @@ struct p_perturbation_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct p_perturbation_ctx -create_ctx(void) +struct p_perturbation_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -66,7 +64,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -84,14 +83,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct p_perturbation_ctx *app = ctx; @@ -109,13 +107,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -133,32 +132,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -181,29 +182,25 @@ main(int argc, char **argv) struct gkyl_wv_eqn *euler = gkyl_wv_euler_new(ctx.gas_gamma, app_args.use_gpu); struct gkyl_vlasov_fluid_species fluid = { - .name = "euler", - .equation = euler, - .init = evalEulerInit, - .ctx = &ctx, + .name = "euler", .equation = euler, .init = evalEulerInit, .ctx = &ctx }; -int nrank = 1; // Number of processors in simulation. + int nrank = 1; // Number of processors in simulation. #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -211,39 +208,25 @@ int nrank = 1; // Number of processors in simulation. for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -266,31 +249,28 @@ int nrank = 1; // Number of processors in simulation. // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 0, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 0, - .species = { }, + .species = {}, .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -304,10 +284,14 @@ int nrank = 1; // Number of processors in simulation. // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -316,32 +300,39 @@ int nrank = 1; // Number of processors in simulation. gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -357,7 +348,7 @@ int nrank = 1; // Number of processors in simulation. gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -373,8 +364,7 @@ int nrank = 1; // Number of processors in simulation. if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -382,7 +372,9 @@ int nrank = 1; // Number of processors in simulation. gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -391,8 +383,7 @@ int nrank = 1; // Number of processors in simulation. break; } - } - else { + } else { num_failures = 0; } @@ -412,14 +403,22 @@ int nrank = 1; // Number of processors in simulation. gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); @@ -437,6 +436,6 @@ int nrank = 1; // Number of processors in simulation. MPI_Finalize(); } #endif - + return 0; } diff --git a/vlasov/creg/rt_dg_euler_sodshock_p1.c b/vlasov/creg/rt_dg_euler_sodshock_p1.c index fe74eefc4d..2804320318 100644 --- a/vlasov/creg/rt_dg_euler_sodshock_p1.c +++ b/vlasov/creg/rt_dg_euler_sodshock_p1.c @@ -26,8 +26,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -54,8 +53,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -78,7 +76,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -100,14 +99,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct sodshock_ctx *app = ctx; @@ -130,8 +128,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -145,13 +142,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -169,32 +167,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -222,7 +222,7 @@ main(int argc, char **argv) .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processors in simulation. @@ -230,18 +230,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -249,39 +248,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -304,31 +289,28 @@ main(int argc, char **argv) // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { 0.25 }, - .upper = { 0.25 + ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 0, + .lower = {0.25}, + .upper = {0.25 + ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 0, - .species = { }, + .species = {}, .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -342,10 +324,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -354,32 +340,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -395,7 +388,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -411,8 +404,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -420,7 +412,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -429,8 +423,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -450,14 +443,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_dg_euler_sodshock_p2.c b/vlasov/creg/rt_dg_euler_sodshock_p2.c index 8bc60b195c..3f69033aec 100644 --- a/vlasov/creg/rt_dg_euler_sodshock_p2.c +++ b/vlasov/creg/rt_dg_euler_sodshock_p2.c @@ -26,8 +26,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double gas_gamma; // Adiabatic index. @@ -54,8 +53,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double gas_gamma = 1.4; // Adiabatic index. @@ -73,12 +71,13 @@ create_ctx(void) double Lx = 1.0; // Domain size (configuration space: x-direction). int poly_order = 2; // Polynomial order. double cfl_frac = 0.9; // CFL coefficient. - + double t_end = 0.1; // Final simulation time. int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -100,14 +99,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalEulerInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; struct sodshock_ctx *app = ctx; @@ -130,8 +128,7 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo rho = rhol; // Fluid mass density (left). u = ul; // Fluid velocity (left). p = pl; // Fluid pressure (left). - } - else { + } else { rho = rhor; // Fluid mass density (right). u = ur; // Fluid velocity (right). p = pr; // Fluid pressure (right). @@ -145,13 +142,14 @@ evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Set fluid mass density. fout[0] = rho; // Set fluid momentum density. - fout[1] = mom_x; fout[2] = mom_y; fout[3] = mom_z; + fout[1] = mom_x; + fout[2] = mom_y; + fout[3] = mom_z; // Set fluid total energy density. fout[4] = Etot; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -169,32 +167,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -222,7 +222,7 @@ main(int argc, char **argv) .init = evalEulerInit, .ctx = &ctx, - .bcx = { GKYL_SPECIES_COPY, GKYL_SPECIES_COPY }, + .bcx = {GKYL_SPECIES_COPY, GKYL_SPECIES_COPY} }; int nrank = 1; // Number of processors in simulation. @@ -230,18 +230,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -249,39 +248,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -304,31 +289,28 @@ main(int argc, char **argv) // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { 0.25 }, - .upper = { 0.25 + ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 0, + .lower = {0.25}, + .upper = {0.25 + ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 0, - .species = { }, + .species = {}, .num_fluid_species = 1, - .fluid_species = { fluid }, + .fluid_species = {fluid}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -342,10 +324,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -354,32 +340,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -395,7 +388,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -411,8 +404,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -420,7 +412,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -429,8 +423,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -450,14 +443,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_dg_maxwell_plane_wave_2d.c b/vlasov/creg/rt_dg_maxwell_plane_wave_2d.c index cff35040ba..33f6dbb293 100644 --- a/vlasov/creg/rt_dg_maxwell_plane_wave_2d.c +++ b/vlasov/creg/rt_dg_maxwell_plane_wave_2d.c @@ -20,8 +20,7 @@ #include -struct plane_wave_2d_ctx -{ +struct plane_wave_2d_ctx { // Mathematical constants (dimensionless). double pi; @@ -55,8 +54,7 @@ struct plane_wave_2d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct plane_wave_2d_ctx -create_ctx(void) +struct plane_wave_2d_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -70,7 +68,8 @@ create_ctx(void) double k_wave_y = 2.0; // Wave number (y-direction). // Derived physical quantities (using normalized code units). - double k_norm = sqrt((k_wave_x * k_wave_x) + (k_wave_y * k_wave_y)); // Wave number normalization factor. + double k_norm = + sqrt((k_wave_x * k_wave_x) + (k_wave_y * k_wave_y)); // Wave number normalization factor. double k_xn = k_wave_x / k_norm; // Normalized wave number (x-direction). double k_yn = k_wave_y / k_norm; // Normalized wave number (y-direction). @@ -86,7 +85,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -112,14 +112,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct plane_wave_2d_ctx *app = ctx; @@ -131,7 +130,7 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double k_wave_y = app->k_wave_y; double k_xn = app->k_xn; double k_yn = app->k_yn; - + double Lx = app->Lx; double Ly = app->Ly; @@ -143,18 +142,21 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = E0 * cos(phi) * ((2.0 * pi) / Ly) * k_yn; // Total magnetic field (x-direction). double By = -E0 * cos(phi) * ((2.0 * pi) / Lx) * k_xn; // Total magnetic field (y-direction). - double Bz = E0 * cos(phi) * ((2.0 * pi) / Ly) * (-k_xn - k_yn); // Total magnetic field (z-direction). + double Bz = + E0 * cos(phi) * ((2.0 * pi) / Ly) * (-k_xn - k_yn); // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -172,32 +174,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -219,10 +223,11 @@ main(int argc, char **argv) // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; int nrank = 1; // Number of processors in simulation. @@ -230,18 +235,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -249,39 +253,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -304,28 +294,26 @@ main(int argc, char **argv) // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 0, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 0, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 0, - .species = { }, + .species = {}, .field = field, - - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -339,10 +327,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -351,32 +343,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -392,7 +391,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -408,8 +407,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -417,7 +415,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -426,8 +426,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -447,14 +446,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_dg_maxwell_wg_2d.c b/vlasov/creg/rt_dg_maxwell_wg_2d.c index 8b6b3057c3..010ae1fb90 100644 --- a/vlasov/creg/rt_dg_maxwell_wg_2d.c +++ b/vlasov/creg/rt_dg_maxwell_wg_2d.c @@ -20,8 +20,7 @@ #include -struct wg_2d_ctx -{ +struct wg_2d_ctx { // Mathematical constants (dimensionless). double pi; @@ -50,8 +49,7 @@ struct wg_2d_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct wg_2d_ctx -create_ctx(void) +struct wg_2d_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -76,7 +74,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -98,14 +97,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0], y = xn[1]; struct wg_2d_ctx *app = ctx; @@ -121,15 +119,17 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = cos(pi * x) * cos(pi * y); // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex, fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex, fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx, fout[4] = By; fout[5] = Bz; + fout[3] = Bx, fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -147,32 +147,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -194,13 +196,14 @@ main(int argc, char **argv) // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, - + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, + .init = evalFieldInit, .ctx = &ctx, - .bcx = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, - .bcy = { GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL }, + .bcx = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL}, + .bcy = {GKYL_FIELD_PEC_WALL, GKYL_FIELD_PEC_WALL} }; int nrank = 1; // Number of processors in simulation. @@ -208,18 +211,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -227,39 +229,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -282,28 +270,26 @@ main(int argc, char **argv) // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 0, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + .cdim = 2, + .vdim = 0, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 0, - .species = { }, + .species = {}, .field = field, - - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -317,10 +303,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -329,32 +319,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -370,7 +367,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -386,8 +383,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -395,7 +391,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -404,8 +402,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -425,14 +422,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_diffusion_1x.c b/vlasov/creg/rt_diffusion_1x.c index 68f7c1f08a..262ff51493 100644 --- a/vlasov/creg/rt_diffusion_1x.c +++ b/vlasov/creg/rt_diffusion_1x.c @@ -14,8 +14,7 @@ struct sim_ctx { double Lx; // size of the box }; -void -evalInit(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sim_ctx *app = ctx; double x = xn[0]; @@ -26,35 +25,29 @@ evalInit(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, } } -void -D(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void D(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sim_ctx *app = ctx; double x = xn[0]; fout[0] = x + 2.0; } -void -eval_advect_vel(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_advect_vel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sim_ctx *app = ctx; double x = xn[0]; fout[0] = 0.0; - fout[1] = 0.0; - fout[2] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; } -struct sim_ctx -create_ctx(void) +struct sim_ctx create_ctx(void) { - struct sim_ctx ctx = { - .Lx = 2, - }; + struct sim_ctx ctx = {.Lx = 2}; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -63,12 +56,12 @@ main(int argc, char **argv) gkyl_mem_debug_set(true); } struct sim_ctx ctx = create_ctx(); // context for init functions - - // Equation object for getting equation type, - // advection velocity is set by eval_advect_vel function. + + // Equation object for getting equation type, + // advection velocity is set by eval_advect_vel function. double c = 1.0; struct gkyl_wv_eqn *advect = gkyl_wv_advect_new(c, false); - + struct gkyl_vlasov_fluid_species f = { .name = "f", @@ -78,37 +71,33 @@ main(int argc, char **argv) .ctx = &ctx, .init = evalInit, .equation = advect, - .advection = { - .velocity = eval_advect_vel, - .velocity_ctx = &ctx, - }, - .diffusion = {.Dij = D, .Dij_ctx = 0}, - }; + .advection = {.velocity = eval_advect_vel, .velocity_ctx = &ctx}, + .diffusion = {.Dij = D, .Dij_ctx = 0} + }; // VM app struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 0, - .lower = { -2 }, - .upper = { 2 }, - .cells = { 256 }, + .cdim = 1, + .vdim = 0, + .lower = {-2}, + .upper = {2}, + .cells = {256}, .poly_order = 2, .basis_type = app_args.basis_type, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 0, - .species = { }, + .species = {}, .num_fluid_species = 1, - .fluid_species = { f }, + .fluid_species = {f}, .cfl_frac = 0.5, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - }, + .parallelism = {.use_gpu = app_args.use_gpu} }; // create app object @@ -118,20 +107,21 @@ main(int argc, char **argv) // start, end and initial time-step double tcurr = 0.0, tend = 0.01; - double dt = tend-tcurr; + double dt = tend - tcurr; // initialize simulation gkyl_vlasov_app_apply_ic(app, tcurr); - + gkyl_vlasov_app_write(app, tcurr, 0); - gkyl_vlasov_app_calc_mom(app); gkyl_vlasov_app_write_mom(app, tcurr, 0); + gkyl_vlasov_app_calc_mom(app); + gkyl_vlasov_app_write_mom(app, tcurr, 0); long step = 1, num_steps = app_args.num_steps; while ((tcurr < tend) && (step <= num_steps)) { printf("Taking time-step at t = %g ...", tcurr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); printf(" dt = %g\n", status.dt_actual); - + if (!status.success) { printf("** Update method failed! Aborting simulation ....\n"); break; @@ -142,7 +132,8 @@ main(int argc, char **argv) } gkyl_vlasov_app_write(app, tcurr, 1); - gkyl_vlasov_app_calc_mom(app); gkyl_vlasov_app_write_mom(app, tcurr, 1); + gkyl_vlasov_app_calc_mom(app); + gkyl_vlasov_app_write_mom(app, tcurr, 1); gkyl_vlasov_app_stat_write(app); // fetch simulation statistics @@ -159,12 +150,12 @@ main(int argc, char **argv) if (stat.nstage_2_fail > 0) { printf("Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); printf("Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + } printf("Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); printf("Species RHS calc took %g secs\n", stat.species_rhs_tm); //printf("Field RHS calc took %g secs\n", stat.field_rhs_tm); //printf("Current evaluation and accumulate took %g secs\n", stat.current_tm); printf("Updates took %g secs\n", stat.total_tm); - + return 0; } diff --git a/vlasov/creg/rt_diffusion_2x.c b/vlasov/creg/rt_diffusion_2x.c index 64f3d4ae65..6b34b804ca 100644 --- a/vlasov/creg/rt_diffusion_2x.c +++ b/vlasov/creg/rt_diffusion_2x.c @@ -14,20 +14,18 @@ struct sim_ctx { double Lx; // size of the box }; -void -evalInit(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sim_ctx *app = ctx; double x = xn[0], y = xn[1]; - if (x > -1 & x < 1 & y > -1 & y < 1) { + if (x > -1 & x<1 & y> - 1 & y < 1) { fout[0] = 1.0; } else { fout[0] = 0.0; } } -void -D(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void D(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sim_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -36,27 +34,22 @@ D(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *c fout[2] = y + 2.0; } -void -eval_advect_vel(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void eval_advect_vel(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sim_ctx *app = ctx; double x = xn[0], y = xn[1]; fout[0] = 0.0; - fout[1] = 0.0; - fout[2] = 0.0; + fout[1] = 0.0; + fout[2] = 0.0; } -struct sim_ctx -create_ctx(void) +struct sim_ctx create_ctx(void) { - struct sim_ctx ctx = { - .Lx = 2, - }; + struct sim_ctx ctx = {.Lx = 2}; return ctx; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -65,12 +58,12 @@ main(int argc, char **argv) gkyl_mem_debug_set(true); } struct sim_ctx ctx = create_ctx(); // context for init functions - - // Equation object for getting equation type, - // advection velocity is set by eval_advect_vel function. + + // Equation object for getting equation type, + // advection velocity is set by eval_advect_vel function. double c = 1.0; struct gkyl_wv_eqn *advect = gkyl_wv_advect_new(c, false); - + struct gkyl_vlasov_fluid_species f = { .name = "f", @@ -80,37 +73,33 @@ main(int argc, char **argv) .ctx = &ctx, .init = evalInit, .equation = advect, - .advection = { - .velocity = eval_advect_vel, - .velocity_ctx = &ctx, - }, - .diffusion = {.Dij = D, .Dij_ctx = 0}, - }; + .advection = {.velocity = eval_advect_vel, .velocity_ctx = &ctx}, + .diffusion = {.Dij = D, .Dij_ctx = 0} + }; // VM app struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 0, - .lower = { -2, -2 }, - .upper = { 2, 2 }, - .cells = { 32, 32 }, + .cdim = 2, + .vdim = 0, + .lower = {-2, -2}, + .upper = {2, 2}, + .cells = {32, 32}, .poly_order = 2, .basis_type = app_args.basis_type, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 0, - .species = { }, + .species = {}, .num_fluid_species = 1, - .fluid_species = { f }, + .fluid_species = {f}, .cfl_frac = 0.5, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - }, + .parallelism = {.use_gpu = app_args.use_gpu} }; // create app object @@ -120,20 +109,21 @@ main(int argc, char **argv) // start, end and initial time-step double tcurr = 0.0, tend = 0.01; - double dt = tend-tcurr; + double dt = tend - tcurr; // initialize simulation gkyl_vlasov_app_apply_ic(app, tcurr); - + gkyl_vlasov_app_write(app, tcurr, 0); - gkyl_vlasov_app_calc_mom(app); gkyl_vlasov_app_write_mom(app, tcurr, 0); + gkyl_vlasov_app_calc_mom(app); + gkyl_vlasov_app_write_mom(app, tcurr, 0); long step = 1, num_steps = app_args.num_steps; while ((tcurr < tend) && (step <= num_steps)) { printf("Taking time-step at t = %g ...", tcurr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); printf(" dt = %g\n", status.dt_actual); - + if (!status.success) { printf("** Update method failed! Aborting simulation ....\n"); break; @@ -144,7 +134,8 @@ main(int argc, char **argv) } gkyl_vlasov_app_write(app, tcurr, 1); - gkyl_vlasov_app_calc_mom(app); gkyl_vlasov_app_write_mom(app, tcurr, 1); + gkyl_vlasov_app_calc_mom(app); + gkyl_vlasov_app_write_mom(app, tcurr, 1); gkyl_vlasov_app_stat_write(app); // fetch simulation statistics @@ -161,12 +152,12 @@ main(int argc, char **argv) if (stat.nstage_2_fail > 0) { printf("Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); printf("Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + } printf("Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); printf("Species RHS calc took %g secs\n", stat.species_rhs_tm); //printf("Field RHS calc took %g secs\n", stat.field_rhs_tm); //printf("Current evaluation and accumulate took %g secs\n", stat.current_tm); printf("Updates took %g secs\n", stat.total_tm); - + return 0; } diff --git a/vlasov/creg/rt_escreen_sr.c b/vlasov/creg/rt_escreen_sr.c index 6c34a6cf81..62a3b01d82 100644 --- a/vlasov/creg/rt_escreen_sr.c +++ b/vlasov/creg/rt_escreen_sr.c @@ -20,8 +20,7 @@ #include -struct escreen_ctx -{ +struct escreen_ctx { // Mathematical constants (dimensionless). double pi; @@ -50,13 +49,12 @@ struct escreen_ctx double t_end; // Final simulation time. int num_frames; // Number of output frames. - int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). + int int_diag_calc_num; // Number of integrated diagnostics computations (=INT_MAX for every step). double dt_failure_tol; // Minimum allowable fraction of initial time-step. int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct escreen_ctx -create_ctx(void) +struct escreen_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -87,21 +85,21 @@ create_ctx(void) double t_end = 10.0; // Final simulation time. int num_frames = 2; // Number of output frames. - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - return (struct escreen_ctx) { - .pi = pi, + return (struct escreen_ctx + ){.pi = pi, .epsilon0 = epsilon0, .mu0 = mu0, .mass_ion = mass_ion, .charge_ion = charge_ion, .mass_elc = mass_elc, .charge_elc = charge_elc, - .n0 = n0, + .n0 = n0, .T = T, - .E0 = E0, + .E0 = E0, .noise_amp = noise_amp, .mode_init = mode_init, .mode_final = mode_final, @@ -115,12 +113,10 @@ create_ctx(void) .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, - }; + .num_failures_max = num_failures_max}; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct escreen_ctx *app = ctx; @@ -130,15 +126,16 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalDensityPerturbInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityPerturbInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct escreen_ctx *app = ctx; double x = xn[0]; // Perturbation to initial density to satisfy div(E) = rho_c double n = app->n0; - double pi = app->pi; + double pi = app->pi; double noise_amp = app->noise_amp; double mode_init = app->mode_init; double mode_final = app->mode_final; @@ -149,15 +146,15 @@ evalDensityPerturbInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RE double kx = 2.0 * pi / Lx; // Wave number (x-direction). pcg64_random_t rng = gkyl_pcg64_init(0); // Random number generator. for (int i = mode_init; i < mode_final; i++) { - n -= alpha * gkyl_pcg64_rand_double(&rng) * cos(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); + n -= alpha * gkyl_pcg64_rand_double(&rng) * + cos(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); } // Set density (no perturbation). fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct escreen_ctx *app = ctx; @@ -167,8 +164,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct escreen_ctx *app = ctx; @@ -176,8 +172,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = 0.0; } -void -evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct escreen_ctx *app = ctx; double x = xn[0]; @@ -195,29 +190,34 @@ evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo // Perturbation to initial electric field for (int i = mode_init; i < mode_final; i++) { - E_x += alpha * gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); + E_x += alpha * gkyl_pcg64_rand_double(&rng) * + sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); } - fout[0] = E_x; fout[1] = 0.0, fout[2] = 0.0; - fout[3] = 0.0; fout[4] = 0.0; fout[5] = 0.0; - fout[6] = 0.0; fout[7] = 0.0; + fout[0] = E_x; + fout[1] = 0.0, fout[2] = 0.0; + fout[3] = 0.0; + fout[4] = 0.0; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } void -calc_integrated_diagnostics(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_calc) +calc_integrated_diagnostics( + struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_calc) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { bool trig_now = gkyl_tm_trigger_check_and_bump(iot, t_curr); if (trig_now || force_write) { - int frame = (!trig_now) && force_write? iot->curr : iot->curr-1; + int frame = (!trig_now) && force_write ? iot->curr : iot->curr - 1; gkyl_vlasov_app_write(app, t_curr, frame); @@ -229,8 +229,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -255,18 +254,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -274,39 +272,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -330,123 +314,117 @@ main(int argc, char **argv) struct gkyl_vlasov_species elc = { .name = "elc", .model_id = GKYL_MODEL_SR, - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.px_max }, - .upper = { ctx.px_max }, - .cells = { NPX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityPerturbInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .use_last_converged = true, - }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.px_max}, + .upper = {ctx.px_max}, + .cells = {NPX}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityPerturbInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .use_last_converged = true}, // Source is the same as initial condition without perturbation. - .source = { - .source_id = GKYL_PROJ_SOURCE, - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .use_last_converged = true, - }, - }, + .source = + {.source_id = GKYL_PROJ_SOURCE, + .num_sources = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .use_last_converged = true}}, .num_diag_moments = 2, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1} }; // positrons struct gkyl_vlasov_species pos = { .name = "pos", .model_id = GKYL_MODEL_SR, - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.px_max }, - .upper = { ctx.px_max }, - .cells = { NPX }, - - .num_init = 1, - // No perturbation in positron initial conditions. - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - - .source = { - .source_id = GKYL_PROJ_SOURCE, - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.px_max}, + .upper = {ctx.px_max}, + .cells = {NPX}, + + .num_init = 1, + // No perturbation in positron initial conditions. + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + + .source = + {.source_id = GKYL_PROJ_SOURCE, + .num_sources = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}}, .num_diag_moments = 2, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1} }; // field struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .ctx = &ctx, - .init = evalFieldFunc, + .init = evalFieldFunc }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { elc, pos }, + .species = {elc, pos}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // create app object // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -457,11 +435,14 @@ main(int argc, char **argv) double t_curr = 0.0, t_end = ctx.t_end; // Initialize simulation. if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", - gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -470,16 +451,18 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); - } - + } + // Create triggers for IO. int num_frames = ctx.num_frames, num_int_diag_calc = ctx.int_diag_calc_num; - struct gkyl_tm_trigger trig_write = { .dt = t_end/num_frames, .tcurr = t_curr, .curr = frame_curr }; - struct gkyl_tm_trigger trig_calc_intdiag = { .dt = t_end/GKYL_MAX2(num_frames, num_int_diag_calc), - .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger trig_write = { + .dt = t_end / num_frames, .tcurr = t_curr, .curr = frame_curr + }; + struct gkyl_tm_trigger trig_calc_intdiag = { + .dt = t_end / GKYL_MAX2(num_frames, num_int_diag_calc), .tcurr = t_curr, .curr = frame_curr + }; // Write out ICs (if restart, it overwrites the restart frame). calc_integrated_diagnostics(&trig_calc_intdiag, app, t_curr, false); @@ -511,8 +494,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -520,13 +502,14 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_integrated_diagnostics(&trig_calc_intdiag, app, t_curr, true); write_data(&trig_write, app, t_curr, true); break; } - } - else { + } else { num_failures = 0; } @@ -542,25 +525,33 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_comm_release(comm); gkyl_vlasov_app_release(app); - mpifinalize: +mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Finalize(); diff --git a/vlasov/creg/rt_gr_can_pb_schwarzschild_bh_geodesics.c b/vlasov/creg/rt_gr_can_pb_schwarzschild_bh_geodesics.c index 09e1138911..f154362da1 100644 --- a/vlasov/creg/rt_gr_can_pb_schwarzschild_bh_geodesics.c +++ b/vlasov/creg/rt_gr_can_pb_schwarzschild_bh_geodesics.c @@ -22,8 +22,7 @@ #include -struct blackhole_static_ctx -{ +struct blackhole_static_ctx { // Mathematical constants (dimensionless). double pi; @@ -68,8 +67,7 @@ struct blackhole_static_ctx double eccentricity; }; -struct blackhole_static_ctx -create_ctx(void) +struct blackhole_static_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -77,9 +75,9 @@ create_ctx(void) // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. double charge = 0.0; // Neutral charge. - + // Spacetime parameters (using geometric units). - double bh_mass = 3.0/14.0; // Mass of the black hole. + double bh_mass = 3.0 / 14.0; // Mass of the black hole. double bh_spin = 0.0; // Spin of the black hole. double bh_pos_x = 0.0; // Position of the black hole (x-direction). @@ -95,8 +93,10 @@ create_ctx(void) int Nvtheta = 32; // Cell count (velocity space: azimuthal angular direction). double Lr_min = 5.0; // Domain size radius min (configuration space: radial direction). double Lr_max = 25.0; // Domain size radius max (configuration space: radial direction). - double Ltheta_min = 0.0; // Domain size minimum (configuration space: azimuthal angular direction). - double Ltheta_max = 2.0 * pi; // Domain size maximum (configuration space: azimuthal angular direction). + double Ltheta_min = + 0.0; // Domain size minimum (configuration space: azimuthal angular direction). + double Ltheta_max = + 2.0 * pi; // Domain size maximum (configuration space: azimuthal angular direction). double v_r_max = 0.5 * vt; // Domain boundary (velocity space: radial direction). double v_theta_max = 1.5 * vt; // Domain boundary (velocity space: azimuthal angular direction). int poly_order = 2; // Polynomial order. @@ -106,7 +106,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -144,29 +145,28 @@ create_ctx(void) .dt_failure_tol = dt_failure_tol, .num_failures_max = num_failures_max, .latus_rectum = latus_rectum, - .eccentricity = eccentricity, + .eccentricity = eccentricity }; return ctx; } // helper function for computing the inital distribution -double -gaussian(double x, double mean, double sigma) { - return exp(-0.5 * pow((x - mean) / sigma, 2)); +double gaussian(double x, double mean, double sigma) +{ + return exp(-0.5 * pow((x - mean) / sigma, 2)); } -void -evalInitialf(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInitialf(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct blackhole_static_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1], p_r_dot = xn[2], p_theta_dot = xn[3]; double metric_det = q_r; // Metric tensor determinant. - double dr = (app->Lr_max - app->Lr_min)/app->Nr; - double dtheta = (app->Ltheta_max - app->Ltheta_min)/app->Ntheta; - double dpr = (2.0*app->v_r_max)/app->Nvr; - double dptheta = (2.0*app->v_theta_max)/app->Nvtheta; + double dr = (app->Lr_max - app->Lr_min) / app->Nr; + double dtheta = (app->Ltheta_max - app->Ltheta_min) / app->Ntheta; + double dpr = (2.0 * app->v_r_max) / app->Nvr; + double dptheta = (2.0 * app->v_theta_max) / app->Nvtheta; double pi = app->pi; double f = 0.0; // background distribution function @@ -177,20 +177,23 @@ evalInitialf(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double bh_mass = app->bh_mass; // Particle Mass and energy - double angular_momentum = sqrt( (bh_mass*latus_rectum*latus_rectum) / (latus_rectum - bh_mass*(3 + pow(eccentricity,2))) ); - double energy = sqrt( 1 - (pow(angular_momentum,2)/pow(latus_rectum,3))*(latus_rectum - 4*bh_mass)*(1 - pow(eccentricity,2)) ); + double angular_momentum = sqrt( + (bh_mass * latus_rectum * latus_rectum) / (latus_rectum - bh_mass * (3 + pow(eccentricity, 2))) + ); + double energy = sqrt( + 1 - (pow(angular_momentum, 2) / pow(latus_rectum, 3)) * (latus_rectum - 4 * bh_mass) * + (1 - pow(eccentricity, 2)) + ); // Inital conditions for bound orbits - double r_0 = 1.0/((1.0 - eccentricity)/latus_rectum); //r_ap + double r_0 = 1.0 / ((1.0 - eccentricity) / latus_rectum); //r_ap double theta_0 = app->pi; double pr0 = 0.0; // At orbit ap. - double ptheta0 = - energy*angular_momentum/(1.0 - 2.0*bh_mass/q_r); - - // Initalize f as a geodesic around - f = gaussian(q_r, r_0, dr / 2.0) * - gaussian(q_theta, theta_0, dtheta / 2.0) * - gaussian(p_r_dot, pr0, dpr*4.0 / 2.0) * - gaussian(p_theta_dot, ptheta0, dptheta*4.0 / 2.0); + double ptheta0 = -energy * angular_momentum / (1.0 - 2.0 * bh_mass / q_r); + + // Initalize f as a geodesic around + f = gaussian(q_r, r_0, dr / 2.0) * gaussian(q_theta, theta_0, dtheta / 2.0) * + gaussian(p_r_dot, pr0, dpr * 4.0 / 2.0) * gaussian(p_theta_dot, ptheta0, dptheta * 4.0 / 2.0); //printf("dr: %1.3e, dtheta = %1.3e, dpr = %1.3e, dptheta = %1.3e \n",dr, dtheta, dpr, dptheta); @@ -198,84 +201,88 @@ evalInitialf(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = f; } -void -evalHamiltonian(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalHamiltonian(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct blackhole_static_ctx *app = ctx; double q_r = xn[0], q_theta = xn[1], p_r_dot = xn[2], p_theta_dot = xn[3]; - double x = q_r*cos(q_theta); - double y = q_r*sin(q_theta); + double x = q_r * cos(q_theta); + double y = q_r * sin(q_theta); - double inv_metric_r_r = (1.0 - 2.0*app->bh_mass/q_r); + double inv_metric_r_r = (1.0 - 2.0 * app->bh_mass / q_r); double inv_metric_r_theta = 0.0; double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Compute the terms for the general GR Hamiltonian - double gamma = sqrt( 1.0 + inv_metric_r_r * p_r_dot * p_r_dot - + 2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot + inv_metric_theta_theta * p_theta_dot * p_theta_dot ); - + double gamma = sqrt( + 1.0 + inv_metric_r_r * p_r_dot * p_r_dot + 2.0 * inv_metric_r_theta * p_r_dot * p_theta_dot + + inv_metric_theta_theta * p_theta_dot * p_theta_dot + ); // Grab lapse, shift from spacetime - double lapse = sqrt(1.0 - 2.0*app->bh_mass/q_r); + double lapse = sqrt(1.0 - 2.0 * app->bh_mass / q_r); - // Lapse and shift for the Schwarzschild BH + // Lapse and shift for the Schwarzschild BH double shift[2] = {0.0}; shift[0] = 0.0; shift[1] = 0.0; // beta^k = beta_vec \cdot e^k - double beta_contra_r = shift[0]*cos(q_theta) + shift[1]*sin(q_theta); - double beta_contra_theta = -shift[0]*sin(q_theta)/q_r + shift[1]*cos(q_theta)/q_r; + double beta_contra_r = shift[0] * cos(q_theta) + shift[1] * sin(q_theta); + double beta_contra_theta = -shift[0] * sin(q_theta) / q_r + shift[1] * cos(q_theta) / q_r; // H = \alpha \gamma - \beta \cdot p - double hamiltonian = lapse*gamma - beta_contra_r*p_r_dot - beta_contra_theta*p_theta_dot; // Canonical Hamiltonian. - + double hamiltonian = lapse * gamma - beta_contra_r * p_r_dot - + beta_contra_theta * p_theta_dot; // Canonical Hamiltonian. + // Set canonical Hamiltonian. fout[0] = hamiltonian; } -void -evalInvMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalInvMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct blackhole_static_ctx *app = ctx; double q_r = xn[0]; - double inv_metric_r_r = (1.0 - 2.0*app->bh_mass/q_r); // Inverse metric tensor (radial-radial component). + double inv_metric_r_r = + (1.0 - 2.0 * app->bh_mass / q_r); // Inverse metric tensor (radial-radial component). double inv_metric_r_theta = 0.0; // Inverse metric tensor (radial-angular component). - double inv_metric_theta_theta = 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). - + double inv_metric_theta_theta = + 1.0 / (q_r * q_r); // Inverse metric tensor (angular-angular component). + // Set inverse metric tensor. - fout[0] = inv_metric_r_r; fout[1] = inv_metric_r_theta; fout[2] = inv_metric_theta_theta; + fout[0] = inv_metric_r_r; + fout[1] = inv_metric_r_theta; + fout[2] = inv_metric_theta_theta; } -void -evalMetric(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetric(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct blackhole_static_ctx *app = ctx; double q_r = xn[0]; - double metric_r_r = 1.0/(1.0 - 2.0*app->bh_mass/q_r); // mMtric tensor (radial-radial component). + double metric_r_r = + 1.0 / (1.0 - 2.0 * app->bh_mass / q_r); // mMtric tensor (radial-radial component). double metric_r_theta = 0.0; // Metric tensor (radial-angular component). double metric_theta_theta = q_r * q_r; // Metric tensor (angular-angular component). - + // Set metric tensor. - fout[0] = metric_r_r; fout[1] = metric_r_theta; fout[2] = metric_theta_theta; + fout[0] = metric_r_r; + fout[1] = metric_r_theta; + fout[2] = metric_theta_theta; } -void -evalMetricDet(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalMetricDet(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double q_r = xn[0]; double metric_det = q_r; // Metric tensor determinant. - + // Set metric tensor determinant. fout[0] = metric_det; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -293,32 +300,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -345,18 +354,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { Nr, Ntheta }; + int ccells[] = {Nr, Ntheta}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -364,39 +372,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -420,10 +414,11 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_CANONICAL_PB_GR, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.v_r_max, -ctx.v_theta_max - 2.0 }, - .upper = { ctx.v_r_max, ctx.v_theta_max - 2.0 }, - .cells = { Nvr, Nvtheta }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.v_r_max, -ctx.v_theta_max - 2.0}, + .upper = {ctx.v_r_max, ctx.v_theta_max - 2.0}, + .cells = {Nvr, Nvtheta}, .hamil = evalHamiltonian, .hamil_ctx = &ctx, @@ -435,47 +430,38 @@ main(int argc, char **argv) .det_h_ctx = &ctx, .output_f_lte = false, - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalInitialf, - .ctx_func = &ctx, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_ABSORB, }, - }, - + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalInitialf, .ctx_func = &ctx}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_ABSORB}}, + .num_diag_moments = 2, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1_FROM_H }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1_FROM_H} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 2, .vdim = 2, - .lower = { ctx.Lr_min, ctx.Ltheta_min }, - .upper = { ctx.Lr_max, ctx.Ltheta_max }, - .cells = { Nr, Ntheta }, + .cdim = 2, + .vdim = 2, + .lower = {ctx.Lr_min, ctx.Ltheta_min}, + .upper = {ctx.Lr_max, ctx.Ltheta_max}, + .cells = {Nr, Ntheta}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 1, - .periodic_dirs = { 1 }, + .num_periodic_dir = 1, + .periodic_dirs = {1}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -489,10 +475,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -501,32 +491,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -542,7 +539,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -558,8 +555,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -567,7 +563,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -576,8 +574,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -597,14 +594,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_hyper_vlasov_tm.c b/vlasov/creg/rt_hyper_vlasov_tm.c index c84a6dfa51..df1fa6173c 100644 --- a/vlasov/creg/rt_hyper_vlasov_tm.c +++ b/vlasov/creg/rt_hyper_vlasov_tm.c @@ -15,29 +15,31 @@ #include #include -static struct gkyl_array* -mkarr1(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr1(bool use_gpu, long nc, long size) { - struct gkyl_array* a; - if (use_gpu) + struct gkyl_array *a; + if (use_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } -void -evalDistFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void -evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - fout[0] = 0.0; fout[1] = 0.0, fout[2] = 0.0; - fout[3] = 0.0; fout[4] = 0.0; fout[5] = 0.0; - fout[6] = 0.0; fout[7] = 0.0; + fout[0] = 0.0; + fout[1] = 0.0, fout[2] = 0.0; + fout[3] = 0.0; + fout[4] = 0.0; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } struct kerntm_inp { @@ -47,83 +49,80 @@ struct kerntm_inp { bool use_gpu; }; -struct kerntm_inp -get_inp(int argc, char **argv) +struct kerntm_inp get_inp(int argc, char **argv) { int c, cdim = 2, vdim = 2, poly_order = 2, nloop = 10; int nx, ny, nz = 8; int nvx, nvy, nvz = 16; bool use_gpu = false; while ((c = getopt(argc, argv, "+hgc:d:p:n:x:y:z:u:v:w:")) != -1) { - switch (c) - { - case 'h': - printf("Usage: app_vlasov_kerntm -c CDIM -d VDIM -p POLYORDER -x NX -y NY -z NZ -u VX -v VY -w VZ -n NLOOP -g\n"); - exit(-1); - break; - - case 'g': - use_gpu = true; - break; - - case 'c': - cdim = atoi(optarg); - break; - - case 'd': - vdim = atoi(optarg); - break; - - case 'p': - poly_order = atoi(optarg); - break; - - case 'n': - nloop = atoi(optarg); - break; - - case 'x': - nx = atoi(optarg); - break; - - case 'y': - ny = atoi(optarg); - break; - - case 'z': - nz = atoi(optarg); - break; - - case 'u': - nvx = atoi(optarg); - break; - - case 'v': - nvy = atoi(optarg); - break; - - case 'w': - nvz = atoi(optarg); - break; - - case '?': - break; + switch (c) { + case 'h': + printf("Usage: app_vlasov_kerntm -c CDIM -d VDIM -p POLYORDER -x NX -y NY -z NZ -u VX -v VY " + "-w VZ -n NLOOP -g\n"); + exit(-1); + break; + + case 'g': + use_gpu = true; + break; + + case 'c': + cdim = atoi(optarg); + break; + + case 'd': + vdim = atoi(optarg); + break; + + case 'p': + poly_order = atoi(optarg); + break; + + case 'n': + nloop = atoi(optarg); + break; + + case 'x': + nx = atoi(optarg); + break; + + case 'y': + ny = atoi(optarg); + break; + + case 'z': + nz = atoi(optarg); + break; + + case 'u': + nvx = atoi(optarg); + break; + + case 'v': + nvy = atoi(optarg); + break; + + case 'w': + nvz = atoi(optarg); + break; + + case '?': + break; } } - - return (struct kerntm_inp) { - .cdim = cdim, + + return (struct kerntm_inp + ){.cdim = cdim, .vdim = vdim, .poly_order = poly_order, - .ccells = { nx, ny, nz }, - .vcells = { nvx, nvy, nvz}, + .ccells = {nx, ny, nz}, + .vcells = {nvx, nvy, nvz}, .nloop = nloop, - .use_gpu = use_gpu, - }; + .use_gpu = use_gpu}; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct kerntm_inp inp = get_inp(argc, argv); @@ -149,10 +148,10 @@ main(int argc, char **argv) double upper[6]; int up_dirs[GKYL_MAX_DIM]; int zero_flux_flags[GKYL_MAX_DIM]; - + printf("cdim = %d; vdim = %d; poly_order = %d\n", inp.cdim, inp.vdim, inp.poly_order); printf("cells = ["); - for (int d=0; ddata; } - for(int i=0; i< nf; i++) { - fin_d[i] = (double)(2*i+11 % nf) / nf * ((i%2 == 0) ? 1 : -1); + for (int i = 0; i < nf; i++) { + fin_d[i] = (double)(2 * i + 11 % nf) / nf * ((i % 2 == 0) ? 1 : -1); + } + if (use_gpu) { + gkyl_array_copy(fin, fin_h); } - if (use_gpu) gkyl_array_copy(fin, fin_h); - int nem = confRange_ext.volume*confBasis.num_basis; + int nem = confRange_ext.volume * confBasis.num_basis; double *qmem_d; if (use_gpu) { - qmem_h = mkarr1(false, 8*confBasis.num_basis, confRange_ext.volume); + qmem_h = mkarr1(false, 8 * confBasis.num_basis, confRange_ext.volume); qmem_d = qmem_h->data; } else { qmem_d = qmem->data; } - for(int i=0; i< nem; i++) { - qmem_d[i] = (double)(-i+27 % nem) / nem * ((i%2 == 0) ? 1 : -1); + for (int i = 0; i < nem; i++) { + qmem_d[i] = (double)(-i + 27 % nem) / nem * ((i % 2 == 0) ? 1 : -1); + } + if (use_gpu) { + gkyl_array_copy(qmem, qmem_h); } - if (use_gpu) gkyl_array_copy(qmem, qmem_h); // run hyper_dg_advance int nrep = inp.nloop; @@ -244,20 +248,23 @@ main(int argc, char **argv) cudaDeviceSynchronize(); #endif struct timespec tm_start = gkyl_wall_clock(); - for(int n=0; n -struct bgk_relax_ctx -{ +struct bgk_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double u0; // Reference velocity. @@ -55,8 +54,7 @@ struct bgk_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_relax_ctx -create_ctx(void) +struct bgk_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -87,10 +85,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct bgk_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -115,26 +114,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1]; - + double n0 = app->n0; double n = 0.0; if (fabs(vx) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -142,8 +139,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1]; @@ -155,22 +151,22 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ub = app->ub; double vtb = app->vtb; double v_sq = (vx - u0) * (vx - u0); double vb_sq = (vx - ub) * (vx - ub); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -180,8 +176,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -199,32 +194,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -249,19 +246,18 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif // Create global range. - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -269,39 +265,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -324,76 +306,59 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -407,10 +372,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -419,32 +388,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -460,7 +436,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -476,8 +452,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -485,7 +460,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -494,8 +471,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -515,14 +491,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_bgk_relax_1x1v_p2.c b/vlasov/creg/rt_vlasov_bgk_relax_1x1v_p2.c index 368f153ce5..eaf41fea2f 100644 --- a/vlasov/creg/rt_vlasov_bgk_relax_1x1v_p2.c +++ b/vlasov/creg/rt_vlasov_bgk_relax_1x1v_p2.c @@ -19,14 +19,13 @@ #include -struct bgk_relax_ctx -{ +struct bgk_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double u0; // Reference velocity. @@ -55,8 +54,7 @@ struct bgk_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_relax_ctx -create_ctx(void) +struct bgk_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -87,10 +85,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct bgk_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -115,26 +114,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1]; - + double n0 = app->n0; double n = 0.0; if (fabs(vx) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -142,8 +139,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1]; @@ -155,22 +151,22 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ub = app->ub; double vtb = app->vtb; double v_sq = (vx - u0) * (vx - u0); double vb_sq = (vx - ub) * (vx - ub); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -180,8 +176,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -199,32 +194,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -249,19 +246,18 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif // Create global range. - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -269,39 +265,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -324,76 +306,59 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -407,10 +372,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -419,32 +388,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -460,7 +436,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -476,8 +452,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -485,7 +460,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -494,8 +471,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -515,14 +491,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_bgk_relax_1x2v_p1.c b/vlasov/creg/rt_vlasov_bgk_relax_1x2v_p1.c index b49a734096..49161b66b1 100644 --- a/vlasov/creg/rt_vlasov_bgk_relax_1x2v_p1.c +++ b/vlasov/creg/rt_vlasov_bgk_relax_1x2v_p1.c @@ -19,14 +19,13 @@ #include -struct bgk_relax_ctx -{ +struct bgk_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double ux0; // Reference velocity (x-direction). @@ -59,8 +58,7 @@ struct bgk_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_relax_ctx -create_ctx(void) +struct bgk_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -95,10 +93,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct bgk_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -127,26 +126,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2]; - + double n0 = app->n0; double n = 0.0; - if(fabs(vx) < 1.0 && fabs(vy) < 1.0) { + if (fabs(vx) < 1.0 && fabs(vy) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -154,8 +151,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2]; @@ -168,7 +164,7 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ubx = app->ubx; double uby = app->uby; double vtb = app->vtb; @@ -176,15 +172,15 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vx - ux0) * (vx - ux0)) + ((vy - uy0) * (vy - uy0)); double vb_sq = ((vx - ubx) * (vx - ubx)) + ((vy - uby) * (vy - uby)); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -194,8 +190,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -213,32 +208,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -264,19 +261,18 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif // Create global range. - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -284,39 +280,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -339,76 +321,59 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -422,10 +387,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -434,32 +403,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -475,7 +451,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -491,8 +467,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -500,7 +475,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -509,8 +486,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -530,14 +506,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_bgk_relax_1x2v_p2.c b/vlasov/creg/rt_vlasov_bgk_relax_1x2v_p2.c index 092329f1a5..92e3ebbc6e 100644 --- a/vlasov/creg/rt_vlasov_bgk_relax_1x2v_p2.c +++ b/vlasov/creg/rt_vlasov_bgk_relax_1x2v_p2.c @@ -19,14 +19,13 @@ #include -struct bgk_relax_ctx -{ +struct bgk_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double ux0; // Reference velocity (x-direction). @@ -59,8 +58,7 @@ struct bgk_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_relax_ctx -create_ctx(void) +struct bgk_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -95,10 +93,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct bgk_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -127,26 +126,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2]; - + double n0 = app->n0; double n = 0.0; - if(fabs(vx) < 1.0 && fabs(vy) < 1.0) { + if (fabs(vx) < 1.0 && fabs(vy) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -154,8 +151,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2]; @@ -168,7 +164,7 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ubx = app->ubx; double uby = app->uby; double vtb = app->vtb; @@ -176,15 +172,15 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vx - ux0) * (vx - ux0)) + ((vy - uy0) * (vy - uy0)); double vb_sq = ((vx - ubx) * (vx - ubx)) + ((vy - uby) * (vy - uby)); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -194,8 +190,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -213,32 +208,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -264,19 +261,18 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif // Create global range. - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -284,39 +280,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -339,78 +321,61 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -422,10 +387,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -434,32 +403,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -475,7 +451,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -491,8 +467,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -500,7 +475,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -509,8 +486,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -530,14 +506,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_bgk_relax_1x3v_p1.c b/vlasov/creg/rt_vlasov_bgk_relax_1x3v_p1.c index e95be562de..01138b536b 100644 --- a/vlasov/creg/rt_vlasov_bgk_relax_1x3v_p1.c +++ b/vlasov/creg/rt_vlasov_bgk_relax_1x3v_p1.c @@ -19,14 +19,13 @@ #include -struct bgk_relax_ctx -{ +struct bgk_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double ux0; // Reference velocity (x-direction). @@ -63,8 +62,7 @@ struct bgk_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_relax_ctx -create_ctx(void) +struct bgk_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -103,10 +101,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct bgk_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -139,26 +138,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2], vz = xn[3]; - + double n0 = app->n0; double n = 0.0; - if(fabs(vx) < 1.0 && fabs(vy) < 1.0 && fabs(vz) < 1.0) { + if (fabs(vx) < 1.0 && fabs(vy) < 1.0 && fabs(vz) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -166,8 +163,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2], vz = xn[3]; @@ -181,7 +177,7 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ubx = app->ubx; double uby = app->uby; double ubz = app->ubz; @@ -190,15 +186,15 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vx - ux0) * (vx - ux0)) + ((vy - uy0) * (vy - uy0)) + ((vz - uz0) * (vz - uz0)); double vb_sq = ((vx - ubx) * (vx - ubx)) + ((vy - uby) * (vy - uby)) + ((vz - ubz) * (vz - ubz)); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -208,8 +204,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -227,32 +222,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -279,19 +276,18 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif // Create global range. - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -299,39 +295,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -354,76 +336,59 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 3, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 3, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -437,10 +402,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -449,32 +418,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -490,7 +466,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -506,8 +482,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -515,7 +490,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -524,8 +501,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -545,14 +521,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld,\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_bgk_relax_1x3v_p2.c b/vlasov/creg/rt_vlasov_bgk_relax_1x3v_p2.c index 9de720f8d6..55ae7b3892 100644 --- a/vlasov/creg/rt_vlasov_bgk_relax_1x3v_p2.c +++ b/vlasov/creg/rt_vlasov_bgk_relax_1x3v_p2.c @@ -19,14 +19,13 @@ #include -struct bgk_relax_ctx -{ +struct bgk_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double ux0; // Reference velocity (x-direction). @@ -63,8 +62,7 @@ struct bgk_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_relax_ctx -create_ctx(void) +struct bgk_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -103,10 +101,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct bgk_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -139,26 +138,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2], vz = xn[3]; - + double n0 = app->n0; double n = 0.0; - if(fabs(vx) < 1.0 && fabs(vy) < 1.0 && fabs(vz) < 1.0) { + if (fabs(vx) < 1.0 && fabs(vy) < 1.0 && fabs(vz) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -166,8 +163,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2], vz = xn[3]; @@ -181,7 +177,7 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ubx = app->ubx; double uby = app->uby; double ubz = app->ubz; @@ -190,15 +186,15 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vx - ux0) * (vx - ux0)) + ((vy - uy0) * (vy - uy0)) + ((vz - uz0) * (vz - uz0)); double vb_sq = ((vx - ubx) * (vx - ubx)) + ((vy - uby) * (vy - uby)) + ((vz - ubz) * (vz - ubz)); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -208,8 +204,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -227,32 +222,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -279,19 +276,18 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif // Create global range. - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -299,39 +295,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -354,76 +336,59 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 3, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 3, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -437,10 +402,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -449,32 +418,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -490,7 +466,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -506,8 +482,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -515,7 +490,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -524,8 +501,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -545,14 +521,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld,\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_em_advect_1x3v_p1.c b/vlasov/creg/rt_vlasov_em_advect_1x3v_p1.c index 619bc4a362..e796f2ad70 100644 --- a/vlasov/creg/rt_vlasov_em_advect_1x3v_p1.c +++ b/vlasov/creg/rt_vlasov_em_advect_1x3v_p1.c @@ -1,7 +1,7 @@ // Advection in specified electromagnetic fields for the Vlasov-Maxwell system of equations. // Input parameters match the initial conditions found in entry JE32 of Ammar's Simulation Journal (https://ammar-hakim.org/sj/je/je32/je32-vlasov-test-ptcl.html) -// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. -// Solution is given by the non-resonant case, omega = 0.5*Omega_c where Omega_c = q B/m is the cyclotron frequency. +// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. +// Solution is given by the non-resonant case, omega = 0.5*Omega_c where Omega_c = q B/m is the cyclotron frequency. #include #include @@ -24,8 +24,7 @@ #include -struct em_advect_ctx -{ +struct em_advect_ctx { // Mathematical constants (dimensionless). double pi; @@ -61,8 +60,7 @@ struct em_advect_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct em_advect_ctx -create_ctx(void) +struct em_advect_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -94,7 +92,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -105,7 +104,7 @@ create_ctx(void) .mass_elc = mass_elc, .charge_elc = charge_elc, .vt = vt, - .n0 = n0, + .n0 = n0, .B0 = B0, .omega = omega, .Nx = Nx, @@ -124,14 +123,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_ctx *app = ctx; double x = xn[0]; @@ -142,22 +140,20 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_ctx *app = ctx; double x = xn[0]; double mass_elc = app->mass_elc; double vt = app->vt; - double T = vt*vt*mass_elc; + double T = vt * vt * mass_elc; // Set isotropic temperature. fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_ctx *app = ctx; @@ -166,12 +162,12 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double Vz_drift = 0.0; // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; fout[2] = Vz_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; + fout[2] = Vz_drift; } - -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -180,17 +176,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct em_advect_ctx *app = ctx; @@ -206,13 +207,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -230,32 +234,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -282,18 +288,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -301,39 +306,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -356,68 +347,66 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, - .is_static = true, + .is_static = true, .init = evalFieldInit, .ctx = &ctx, .ext_em = evalExternalFieldInit, .ext_em_ctx = &ctx, - .ext_em_evolve = true, + .ext_em_evolve = true }; // Vlasov app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 3, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 3, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -431,10 +420,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -443,32 +436,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -484,7 +484,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -500,8 +500,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -509,7 +508,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -518,8 +519,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -539,16 +539,28 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_vlasov_app_cout(app, stdout, "Fluid species RHD calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_vlasov_app_cout( + app, stdout, "Fluid species RHD calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); - gkyl_vlasov_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); + gkyl_vlasov_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_em_advect_resonant_1x3v_p1.c b/vlasov/creg/rt_vlasov_em_advect_resonant_1x3v_p1.c index fb0755df81..af4803abd7 100644 --- a/vlasov/creg/rt_vlasov_em_advect_resonant_1x3v_p1.c +++ b/vlasov/creg/rt_vlasov_em_advect_resonant_1x3v_p1.c @@ -1,7 +1,7 @@ // Advection in specified electromagnetic fields for the Vlasov-Maxwell system of equations. // Input parameters match the initial conditions found in entry JE32 of Ammar's Simulation Journal (https://ammar-hakim.org/sj/je/je32/je32-vlasov-test-ptcl.html) -// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. -// Solution is given by the non-resonant case, omega = 0.5*Omega_c where Omega_c = q B/m is the cyclotron frequency. +// but with a rotation so that the oscillating electric field is in the z_hat direction and the background magnetic field in the x_hat direction. +// Solution is given by the non-resonant case, omega = 0.5*Omega_c where Omega_c = q B/m is the cyclotron frequency. #include #include @@ -24,8 +24,7 @@ #include -struct em_advect_resonant_ctx -{ +struct em_advect_resonant_ctx { // Mathematical constants (dimensionless). double pi; @@ -61,8 +60,7 @@ struct em_advect_resonant_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct em_advect_resonant_ctx -create_ctx(void) +struct em_advect_resonant_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -94,7 +92,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -105,7 +104,7 @@ create_ctx(void) .mass_elc = mass_elc, .charge_elc = charge_elc, .vt = vt, - .n0 = n0, + .n0 = n0, .B0 = B0, .omega = omega, .Nx = Nx, @@ -124,14 +123,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_resonant_ctx *app = ctx; double x = xn[0]; @@ -142,22 +140,20 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_resonant_ctx *app = ctx; double x = xn[0]; double mass_elc = app->mass_elc; double vt = app->vt; - double T = vt*vt*mass_elc; + double T = vt * vt * mass_elc; // Set isotropic temperature. fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct em_advect_resonant_ctx *app = ctx; @@ -166,12 +162,12 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double Vz_drift = 0.0; // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; fout[2] = Vz_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; + fout[2] = Vz_drift; } - -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -180,17 +176,22 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct em_advect_resonant_ctx *app = ctx; @@ -206,13 +207,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = 0.0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -230,32 +234,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -282,18 +288,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -301,39 +306,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -356,68 +347,66 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, - .is_static = true, + .is_static = true, .init = evalFieldInit, .ctx = &ctx, .ext_em = evalExternalFieldInit, .ext_em_ctx = &ctx, - .ext_em_evolve = true, + .ext_em_evolve = true }; // Vlasov app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 3, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 3, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -431,10 +420,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -443,32 +436,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -484,7 +484,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -500,8 +500,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -509,7 +508,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -518,8 +519,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -539,16 +539,28 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); - gkyl_vlasov_app_cout(app, stdout, "Fluid species RHD calc took %g secs\n", stat.fluid_species_rhs_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); + gkyl_vlasov_app_cout( + app, stdout, "Fluid species RHD calc took %g secs\n", stat.fluid_species_rhs_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); - gkyl_vlasov_app_cout(app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); + gkyl_vlasov_app_cout( + app, stdout, "Current evaluation and accumulate took %g secs\n", stat.current_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_emission_spectrum_1x1v_p2.c b/vlasov/creg/rt_vlasov_emission_spectrum_1x1v_p2.c index 64a85417fe..0e7a639d5f 100644 --- a/vlasov/creg/rt_vlasov_emission_spectrum_1x1v_p2.c +++ b/vlasov/creg/rt_vlasov_emission_spectrum_1x1v_p2.c @@ -56,73 +56,78 @@ struct sheath_ctx { int num_failures_max; }; -static inline double sq(double x) { return x*x; } +static inline double sq(double x) +{ + return x * x; +} -void -evalDistFuncElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0], v = xn[1]; double vt = app->vte; double n = app->n0; - double fv = n/sqrt(2.0*M_PI*sq(vt))*(exp(-sq(v)/(2*sq(vt)))); + double fv = n / sqrt(2.0 * M_PI * sq(vt)) * (exp(-sq(v) / (2 * sq(vt)))); fout[0] = fv; } -void -evalDistFuncElcSource(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncElcSource( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], v = xn[1]; double vt = app->vte; double Ls = app->Ls; - double fv = 1.0/sqrt(2.0*M_PI*sq(vt))*(exp(-sq(v)/(2*sq(vt)))); - if(fabs(x) < Ls) { - fout[0] = 2*(Ls - fabs(x))/Ls*fv; + double fv = 1.0 / sqrt(2.0 * M_PI * sq(vt)) * (exp(-sq(v) / (2 * sq(vt)))); + if (fabs(x) < Ls) { + fout[0] = 2 * (Ls - fabs(x)) / Ls * fv; } else { fout[0] = 0.0; } } -void -evalDistFuncIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0], v = xn[1]; double vt = app->vti; double n = app->n0; - double fv = n/sqrt(2.0*M_PI*sq(vt))*(exp(-sq(v)/(2*sq(vt)))); + double fv = n / sqrt(2.0 * M_PI * sq(vt)) * (exp(-sq(v) / (2 * sq(vt)))); fout[0] = fv; } -void -evalDistFuncIonSource(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncIonSource( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], v = xn[1]; double vt = app->vti; double Ls = app->Ls; - double fv = 1.0/sqrt(2.0*M_PI*sq(vt))*(exp(-sq(v)/(2*sq(vt)))); - if(fabs(x) < Ls) { - fout[0] = 2*(Ls - fabs(x))/Ls*fv; + double fv = 1.0 / sqrt(2.0 * M_PI * sq(vt)) * (exp(-sq(v) / (2 * sq(vt)))); + if (fabs(x) < Ls) { + fout[0] = 2 * (Ls - fabs(x)) / Ls * fv; } else { fout[0] = 0.0; } } -void -evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; - - fout[0] = 0.0; fout[1] = 0.0, fout[2] = 0.0; - fout[3] = 0.0; fout[4] = 0.0; fout[5] = 0.0; - fout[6] = 0.0; fout[7] = 0.0; + + fout[0] = 0.0; + fout[1] = 0.0, fout[2] = 0.0; + fout[3] = 0.0; + fout[4] = 0.0; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { double massElc = 9.109e-31; double q0 = 1.602e-19; @@ -148,16 +153,16 @@ create_ctx(void) .chargeElc = -q0, .massElc = massElc, .chargeIon = q0, - .massIon = 1836.153*massElc, + .massIon = 1836.153 * massElc, .n0 = 1.0e17, - .Te = 10.0*q0, - .Ti = 10.0*q0, - .vte = sqrt(ctx.Te/massElc), - .vti = sqrt(ctx.Ti/ctx.massIon), - .lambda_D = sqrt(ctx.epsilon0*ctx.Te/(ctx.n0*q0*q0)), - .Lx = 128.0*ctx.lambda_D, - .Ls = 100.0*ctx.lambda_D, - .omega_pe = sqrt(ctx.n0*q0*q0/(ctx.epsilon0*massElc)), + .Te = 10.0 * q0, + .Ti = 10.0 * q0, + .vte = sqrt(ctx.Te / massElc), + .vti = sqrt(ctx.Ti / ctx.massIon), + .lambda_D = sqrt(ctx.epsilon0 * ctx.Te / (ctx.n0 * q0 * q0)), + .Lx = 128.0 * ctx.lambda_D, + .Ls = 100.0 * ctx.lambda_D, + .omega_pe = sqrt(ctx.n0 * q0 * q0 / (ctx.epsilon0 * massElc)), .phi = phi, .deltahat_ts = deltahat_ts, .Ehat_ts = Ehat_ts, @@ -174,16 +179,15 @@ create_ctx(void) .Nx = 128, .Nv = 32, .num_emission_species = 1, - .t_end = 10.0/ctx.omega_pe, + .t_end = 10.0 / ctx.omega_pe, .num_frames = 1, .dt_failure_tol = 1.0e-4, - .num_failures_max = 20, + .num_failures_max = 20 }; return ctx; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { @@ -199,12 +203,11 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); - #ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Init(&argc, &argv); } @@ -227,16 +230,15 @@ main(int argc, char **argv) } #endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -251,32 +253,18 @@ main(int argc, char **argv) #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -296,12 +284,12 @@ main(int argc, char **argv) goto mpifinalize; } - char in_species[1][128] = { "elc" }; + char in_species[1][128] = {"elc"}; // Copper preset for emission BC where models and parameters are chosen automatically - struct gkyl_bc_emission_ctx *bc_ctx = - gkyl_bc_emission_secondary_electron_copper_new(ctx.num_emission_species, 0.0, - in_species, app_args.use_gpu); + struct gkyl_bc_emission_ctx *bc_ctx = gkyl_bc_emission_secondary_electron_copper_new( + ctx.num_emission_species, 0.0, in_species, app_args.use_gpu + ); // Full specification of the BC with user-defined models and parameters // Uncomment and use this if no material preset is available @@ -319,110 +307,89 @@ main(int argc, char **argv) // electrons struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.chargeElc, .mass = ctx.massElc, - .lower = { -4.0*ctx.vte}, - .upper = { 4.0*ctx.vte}, - .cells = { NV }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalDistFuncElc, - .ctx_func = &ctx, - }, - - .source = { - .source_id = GKYL_BFLUX_SOURCE, - .source_length = ctx.Ls, - .source_species = "ion", - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalDistFuncElcSource, - .ctx_func = &ctx, + .charge = ctx.chargeElc, + .mass = ctx.massElc, + .lower = {-4.0 * ctx.vte}, + .upper = {4.0 * ctx.vte}, + .cells = {NV}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalDistFuncElc, .ctx_func = &ctx}, + + .source = + {.source_id = GKYL_BFLUX_SOURCE, + .source_length = ctx.Ls, + .source_species = "ion", + .num_sources = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalDistFuncElcSource, .ctx_func = &ctx} }, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_EMISSION, - .aux_ctx = bc_ctx, }, - }, - + + .bcx = + {.lower = {.type = GKYL_SPECIES_REFLECT}, + .upper = {.type = GKYL_SPECIES_EMISSION, .aux_ctx = bc_ctx}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // ions struct gkyl_vlasov_species ion = { .name = "ion", - .charge = ctx.chargeIon, .mass = ctx.massIon, - .lower = { -4.0*ctx.vti}, - .upper = { 4.0*ctx.vti}, - .cells = { NV }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalDistFuncIon, - .ctx_func = &ctx, - }, - - .source = { - .source_id = GKYL_BFLUX_SOURCE, - .source_length = ctx.Ls, - .source_species = "ion", - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalDistFuncIonSource, - .ctx_func = &ctx, + .charge = ctx.chargeIon, + .mass = ctx.massIon, + .lower = {-4.0 * ctx.vti}, + .upper = {4.0 * ctx.vti}, + .cells = {NV}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalDistFuncIon, .ctx_func = &ctx}, + + .source = + {.source_id = GKYL_BFLUX_SOURCE, + .source_length = ctx.Ls, + .source_species = "ion", + .num_sources = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalDistFuncIonSource, .ctx_func = &ctx} }, - }, - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_ABSORB, }, - }, - + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_ABSORB}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // field struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .ctx = &ctx, .init = evalFieldFunc, - .bcx = { GKYL_FIELD_SYM_WALL, GKYL_FIELD_PEC_WALL } + .bcx = {GKYL_FIELD_SYM_WALL, GKYL_FIELD_PEC_WALL} }; // VM app struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = 2, .basis_type = app_args.basis_type, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -435,7 +402,7 @@ main(int argc, char **argv) // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + struct gkyl_tm_trigger io_trig = {.dt = t_end / num_frames}; // Initialize simulation. gkyl_vlasov_app_apply_ic(app, t_curr); @@ -453,7 +420,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -466,8 +433,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -475,11 +441,12 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); break; } - } - else { + } else { num_failures = 0; } @@ -497,14 +464,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_es_pot_well.c b/vlasov/creg/rt_vlasov_es_pot_well.c index 31b416d549..6ec7d5c382 100644 --- a/vlasov/creg/rt_vlasov_es_pot_well.c +++ b/vlasov/creg/rt_vlasov_es_pot_well.c @@ -19,8 +19,7 @@ #include -struct es_pot_well_ctx -{ +struct es_pot_well_ctx { // Mathematical constants (dimensionless). double pi; @@ -47,8 +46,7 @@ struct es_pot_well_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct es_pot_well_ctx -create_ctx(void) +struct es_pot_well_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -71,7 +69,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -93,28 +92,26 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_pot_well_ctx *app = ctx; double v = xn[1]; double pi = app->pi; - double n = (1.0 / sqrt(2.0 * pi)) * (exp(-(v * v) / 2.0)); // Distribution function. + double n = (1.0 / sqrt(2.0 * pi)) * (exp(-(v * v) / 2.0)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double x = xn[0]; @@ -127,15 +124,18 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -153,32 +153,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -203,18 +205,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -222,39 +223,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -277,61 +264,56 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .is_static = true, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -343,10 +325,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -355,32 +341,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -396,7 +389,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -412,8 +405,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -421,7 +413,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -430,8 +424,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -451,14 +444,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_es_shock.c b/vlasov/creg/rt_vlasov_es_shock.c index 85a29e04b9..1dd56dce08 100644 --- a/vlasov/creg/rt_vlasov_es_shock.c +++ b/vlasov/creg/rt_vlasov_es_shock.c @@ -19,8 +19,7 @@ #include -struct es_shock_ctx -{ +struct es_shock_ctx { // Mathematical constants (dimensionless). double pi; @@ -59,8 +58,7 @@ struct es_shock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct es_shock_ctx -create_ctx(void) +struct es_shock_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -95,7 +93,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -125,14 +124,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -148,18 +146,18 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double n = 0.0; if (x < 0.0) { - n = (1.0 / sqrt(2.0 * pi * vte * vte)) * (exp(-v_sq_m / (2.0 * vte * vte))); // Distribution function (left). - } - else { - n = (1.0 / sqrt(2.0 * pi * vte * vte)) * (exp(-v_sq_p / (2.0 * vte * vte))); // Distribution function (right). + n = (1.0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-v_sq_m / (2.0 * vte * vte))); // Distribution function (left). + } else { + n = (1.0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-v_sq_p / (2.0 * vte * vte))); // Distribution function (right). } // Set distribution function. fout[0] = n; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -175,18 +173,18 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double n = 0.0; if (x < 0.0) { - n = (1.0 / sqrt(2.0 * pi * vti * vti)) * (exp(-v_sq_m / (2.0 * vti * vti))); // Distribution function (left). - } - else { - n = (1.0 / sqrt(2.0 * pi * vti * vti)) * (exp(-v_sq_p / (2.0 * vti * vti))); // Distribution function (right). + n = (1.0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-v_sq_m / (2.0 * vti * vti))); // Distribution function (left). + } else { + n = (1.0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-v_sq_p / (2.0 * vti * vti))); // Distribution function (right). } // Set distribution function. fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -197,15 +195,18 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -223,32 +224,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -273,18 +276,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -292,39 +294,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -347,78 +335,70 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Ions. struct gkyl_vlasov_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalIonInit, - .ctx_func = &ctx, - }, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalIonInit, .ctx_func = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx}, - .cells = { NX }, + + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -430,10 +410,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -442,32 +426,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -483,7 +474,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -499,8 +490,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -508,7 +498,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -517,8 +509,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -538,14 +529,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_es_shock_lbo_1x1v.c b/vlasov/creg/rt_vlasov_es_shock_lbo_1x1v.c index a84081f453..474f274075 100644 --- a/vlasov/creg/rt_vlasov_es_shock_lbo_1x1v.c +++ b/vlasov/creg/rt_vlasov_es_shock_lbo_1x1v.c @@ -19,8 +19,7 @@ #include -struct es_shock_lbo_ctx -{ +struct es_shock_lbo_ctx { // Mathematical constants (dimensionless). double pi; @@ -40,7 +39,7 @@ struct es_shock_lbo_ctx double cs; // Sound speed. double Vx_drift; // Drift velocity (x-direction). - + double nu_elc; // Electron collision frequency. double nu_ion; // Ion collision frequency. @@ -62,8 +61,7 @@ struct es_shock_lbo_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct es_shock_lbo_ctx -create_ctx(void) +struct es_shock_lbo_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -86,7 +84,8 @@ create_ctx(void) double Vx_drift = 2.0 * cs; // Drift velocity (x-direction). double nu_elc = 1.0e-4; // Electron collision frequency. - double nu_ion = (nu_elc / sqrt(mass_ion)) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. + double nu_ion = + (nu_elc / sqrt(mass_ion)) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. // Simulation parameters. int Nx = 256; // Cell count (configuration space: x-direction). @@ -101,7 +100,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -133,14 +133,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_lbo_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -156,18 +155,18 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double n = 0.0; if (x < 0.0) { - n = (1.0 / sqrt(2.0 * pi * vte * vte)) * (exp(-v_sq_m / (2.0 * vte * vte))); // Distribution function (left). - } - else { - n = (1.0 / sqrt(2.0 * pi * vte * vte)) * (exp(-v_sq_p / (2.0 * vte * vte))); // Distribution function (right). + n = (1.0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-v_sq_m / (2.0 * vte * vte))); // Distribution function (left). + } else { + n = (1.0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-v_sq_p / (2.0 * vte * vte))); // Distribution function (right). } // Set distribution function. fout[0] = n; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_lbo_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -183,18 +182,18 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double n = 0.0; if (x < 0.0) { - n = (1.0 / sqrt(2.0 * pi * vti * vti)) * (exp(-v_sq_m / (2.0 * vti * vti))); // Distribution function (left). - } - else { - n = (1.0 / sqrt(2.0 * pi * vti * vti)) * (exp(-v_sq_p / (2.0 * vti * vti))); // Distribution function (right). + n = (1.0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-v_sq_m / (2.0 * vti * vti))); // Distribution function (left). + } else { + n = (1.0 / sqrt(2.0 * pi * vti * vti)) * + (exp(-v_sq_p / (2.0 * vti * vti))); // Distribution function (right). } // Set distribution function. fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -205,15 +204,18 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_lbo_ctx *app = ctx; @@ -223,8 +225,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_lbo_ctx *app = ctx; @@ -234,8 +235,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -253,32 +253,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -303,18 +305,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -322,39 +323,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -377,93 +364,82 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - .num_cross_collisions = 1, - .collide_with = { "ion" }, - }, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, + .self_nu = evalElcNu, + .ctx = &ctx, + .num_cross_collisions = 1, + .collide_with = {"ion"}}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Ions. struct gkyl_vlasov_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalIonInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - .num_cross_collisions = 1, - .collide_with = { "elc" }, - }, - + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalIonInit, .ctx_func = &ctx}, + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, + .self_nu = evalIonNu, + .ctx = &ctx, + .num_cross_collisions = 1, + .collide_with = {"elc"}}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx}, - .cells = { NX }, + + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -475,10 +451,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -487,32 +467,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -528,7 +515,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -544,8 +531,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -553,7 +539,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -562,8 +550,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -583,14 +570,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_es_shock_lbo_1x3v.c b/vlasov/creg/rt_vlasov_es_shock_lbo_1x3v.c index f3bb8a7600..cf18898529 100644 --- a/vlasov/creg/rt_vlasov_es_shock_lbo_1x3v.c +++ b/vlasov/creg/rt_vlasov_es_shock_lbo_1x3v.c @@ -19,8 +19,7 @@ #include -struct es_shock_lbo_ctx -{ +struct es_shock_lbo_ctx { // Mathematical constants (dimensionless). double pi; @@ -40,7 +39,7 @@ struct es_shock_lbo_ctx double cs; // Sound speed. double Vx_drift; // Drift velocity (x-direction). - + double nu_elc; // Electron collision frequency. double nu_ion; // Ion collision frequency. @@ -68,8 +67,7 @@ struct es_shock_lbo_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct es_shock_lbo_ctx -create_ctx(void) +struct es_shock_lbo_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -92,7 +90,8 @@ create_ctx(void) double Vx_drift = 2.0 * cs; // Drift velocity (x-direction). double nu_elc = 1.0e-4; // Electron collision frequency. - double nu_ion = (nu_elc / sqrt(mass_ion)) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. + double nu_ion = + (nu_elc / sqrt(mass_ion)) * (Te_over_Ti * sqrt(Te_over_Ti)); // Ion collision frequency. // Simulation parameters. int Nx = 32; // Cell count (configuration space: x-direction). @@ -113,7 +112,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -151,14 +151,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_lbo_ctx *app = ctx; double x = xn[0], vx = xn[1], vy = xn[2], vz = xn[3]; @@ -174,18 +173,18 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double n = 0.0; if (x < 0.0) { - n = (1.0 / pow(sqrt(2.0 * pi * vte * vte), 3.0)) * (exp(-v_sq_m / (2.0 * vte * vte))); // Distribution function (left). - } - else { - n = (1.0 / pow(sqrt(2.0 * pi * vte * vte), 3.0)) * (exp(-v_sq_p / (2.0 * vte * vte))); // Distribution function (right). + n = (1.0 / pow(sqrt(2.0 * pi * vte * vte), 3.0)) * + (exp(-v_sq_m / (2.0 * vte * vte))); // Distribution function (left). + } else { + n = (1.0 / pow(sqrt(2.0 * pi * vte * vte), 3.0)) * + (exp(-v_sq_p / (2.0 * vte * vte))); // Distribution function (right). } // Set distribution function. fout[0] = n; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_lbo_ctx *app = ctx; double x = xn[0], vx = xn[1], vy = xn[2], vz = xn[3]; @@ -201,18 +200,18 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double n = 0.0; if (x < 0.0) { - n = (1.0 / pow(sqrt(2.0 * pi * vti * vti), 3.0)) * (exp(-v_sq_m / (2.0 * vti * vti))); // Distribution function (left). - } - else { - n = (1.0 / pow(sqrt(2.0 * pi * vti * vti), 3.0)) * (exp(-v_sq_p / (2.0 * vti * vti))); // Distribution function (right). + n = (1.0 / pow(sqrt(2.0 * pi * vti * vti), 3.0)) * + (exp(-v_sq_m / (2.0 * vti * vti))); // Distribution function (left). + } else { + n = (1.0 / pow(sqrt(2.0 * pi * vti * vti), 3.0)) * + (exp(-v_sq_p / (2.0 * vti * vti))); // Distribution function (right). } // Set distribution function. fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -223,15 +222,18 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_lbo_ctx *app = ctx; @@ -241,8 +243,7 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_elc; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct es_shock_lbo_ctx *app = ctx; @@ -252,8 +253,7 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, fout[0] = nu_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -271,32 +271,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -323,18 +325,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -342,39 +343,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -397,89 +384,72 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc, -ctx.vy_max_elc, -ctx.vz_max_elc }, - .upper = { ctx.vx_max_elc, ctx.vy_max_elc, ctx.vz_max_elc }, - .cells = { NVX, NVY, NVZ }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc, -ctx.vy_max_elc, -ctx.vz_max_elc}, + .upper = {ctx.vx_max_elc, ctx.vy_max_elc, ctx.vz_max_elc}, + .cells = {NVX, NVY, NVZ}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - }, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalElcNu, .ctx = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Ions. struct gkyl_vlasov_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion, -ctx.vy_max_ion, -ctx.vz_max_ion }, - .upper = { ctx.vx_max_ion, ctx.vy_max_ion, ctx.vz_max_ion }, - .cells = { NVX, NVY, NVZ }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion, -ctx.vy_max_ion, -ctx.vz_max_ion}, + .upper = {ctx.vx_max_ion, ctx.vy_max_ion, ctx.vz_max_ion}, + .cells = {NVX, NVY, NVZ}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalIonInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - }, - + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalIonInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalIonNu, .ctx = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 3, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx}, - .cells = { NX }, + + .cdim = 1, + .vdim = 3, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -491,10 +461,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -503,32 +477,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -544,7 +525,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -560,8 +541,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -569,7 +549,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -578,8 +560,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -599,14 +580,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_freestream_p1.c b/vlasov/creg/rt_vlasov_freestream_p1.c index 207b31b5ac..9257907265 100644 --- a/vlasov/creg/rt_vlasov_freestream_p1.c +++ b/vlasov/creg/rt_vlasov_freestream_p1.c @@ -19,8 +19,7 @@ #include -struct freestream_ctx -{ +struct freestream_ctx { // Mathematical constants (dimensionless). double pi; @@ -47,8 +46,7 @@ struct freestream_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct freestream_ctx -create_ctx(void) +struct freestream_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -71,7 +69,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -92,14 +91,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeutInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct freestream_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -107,14 +105,14 @@ evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double pi = app->pi; double vt = app->vt; - double n = (cos(x) / sqrt(2.0 * pi * vt * vt)) * exp(-(vx * vx) / (2.0 * vt * vt)); // Distribution function. + double n = (cos(x) / sqrt(2.0 * pi * vt * vt)) * + exp(-(vx * vx) / (2.0 * vt * vt)); // Distribution function. // Set distribution function. fout[0] = n; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -132,32 +130,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -182,18 +182,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -201,39 +200,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -256,46 +241,40 @@ main(int argc, char **argv) // Neutral species. struct gkyl_vlasov_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalNeutInit, - .ctx_func = &ctx, - }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalNeutInit, .ctx_func = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { neut }, + .species = {neut}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -309,10 +288,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -321,32 +304,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -362,7 +352,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -378,8 +368,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -387,7 +376,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -396,8 +387,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -417,14 +407,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); @@ -434,7 +432,7 @@ main(int argc, char **argv) // Free resources after simulation completion. gkyl_comm_release(comm); gkyl_vlasov_app_release(app); - + mpifinalize: #ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { diff --git a/vlasov/creg/rt_vlasov_freestream_p2.c b/vlasov/creg/rt_vlasov_freestream_p2.c index 16144a17bd..e850a410b6 100644 --- a/vlasov/creg/rt_vlasov_freestream_p2.c +++ b/vlasov/creg/rt_vlasov_freestream_p2.c @@ -19,8 +19,7 @@ #include -struct freestream_ctx -{ +struct freestream_ctx { // Mathematical constants (dimensionless). double pi; @@ -47,8 +46,7 @@ struct freestream_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct freestream_ctx -create_ctx(void) +struct freestream_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -71,7 +69,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -92,14 +91,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeutInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct freestream_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -107,14 +105,14 @@ evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double pi = app->pi; double vt = app->vt; - double n = (cos(x) / sqrt(2.0 * pi * vt * vt)) * exp(-(vx * vx) / (2.0 * vt * vt)); // Distribution function. + double n = (cos(x) / sqrt(2.0 * pi * vt * vt)) * + exp(-(vx * vx) / (2.0 * vt * vt)); // Distribution function. // Set distribution function. fout[0] = n; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -132,32 +130,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -182,18 +182,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -201,39 +200,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -256,46 +241,40 @@ main(int argc, char **argv) // Neutral species. struct gkyl_vlasov_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalNeutInit, - .ctx_func = &ctx, - }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalNeutInit, .ctx_func = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { neut }, + .species = {neut}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -309,10 +288,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -321,32 +304,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -362,7 +352,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -378,8 +368,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -387,7 +376,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -396,8 +387,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -417,14 +407,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_kerntm.c b/vlasov/creg/rt_vlasov_kerntm.c index 456d23d482..f0c1404b25 100644 --- a/vlasov/creg/rt_vlasov_kerntm.c +++ b/vlasov/creg/rt_vlasov_kerntm.c @@ -8,18 +8,20 @@ #include #include -void -evalDistFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { fout[0] = 0.0; } -void -evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - fout[0] = 0.0; fout[1] = 0.0, fout[2] = 0.0; - fout[3] = 0.0; fout[4] = 0.0; fout[5] = 0.0; - fout[6] = 0.0; fout[7] = 0.0; + fout[0] = 0.0; + fout[1] = 0.0, fout[2] = 0.0; + fout[3] = 0.0; + fout[4] = 0.0; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } struct kerntm_inp { @@ -29,116 +31,108 @@ struct kerntm_inp { bool use_gpu; }; -struct kerntm_inp -get_inp(int argc, char **argv) +struct kerntm_inp get_inp(int argc, char **argv) { int c, cdim = 2, vdim = 2, poly_order = 2, nloop = 10; bool use_gpu = false; while ((c = getopt(argc, argv, "+hgc:v:p:n:")) != -1) { - switch (c) - { - case 'h': - printf("Usage: app_vlasov_kerntm -c CDIM -v VDIM -p POLYORDER -n NLOOP -g\n"); - exit(-1); - break; - - case 'g': - use_gpu = true; - break; - - case 'c': - cdim = atoi(optarg); - break; - - case 'v': - vdim = atoi(optarg); - break; - - case 'p': - poly_order = atoi(optarg); - break; - - case 'n': - nloop = atoi(optarg); - break; - - case '?': - break; + switch (c) { + case 'h': + printf("Usage: app_vlasov_kerntm -c CDIM -v VDIM -p POLYORDER -n NLOOP -g\n"); + exit(-1); + break; + + case 'g': + use_gpu = true; + break; + + case 'c': + cdim = atoi(optarg); + break; + + case 'v': + vdim = atoi(optarg); + break; + + case 'p': + poly_order = atoi(optarg); + break; + + case 'n': + nloop = atoi(optarg); + break; + + case '?': + break; } } - - return (struct kerntm_inp) { - .cdim = cdim, + + return (struct kerntm_inp + ){.cdim = cdim, .vdim = vdim, .poly_order = poly_order, - .ccells = { 8, 8, 8 }, - .vcells = { 16, 16, 16 }, + .ccells = {8, 8, 8}, + .vcells = {16, 16, 16}, .nloop = nloop, - .use_gpu = use_gpu, - }; + .use_gpu = use_gpu}; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct kerntm_inp inp = get_inp(argc, argv); #ifdef GKYL_HAVE_CUDA - if (inp.use_gpu) + if (inp.use_gpu) { printf("Running kernel timers on GPU with:\n"); - else + } else { printf("Running kernel timers on CPU with:\n"); + } #else printf("Running kernel timers on CPU with:\n"); #endif - + printf("cdim = %d; vdim = %d; poly_order = %d\n", inp.cdim, inp.vdim, inp.poly_order); printf("cells = ["); - for (int d=0; d -struct landau_damping_ctx -{ +struct landau_damping_ctx { // Mathematical constants (dimensionless). double pi; @@ -53,8 +52,7 @@ struct landau_damping_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct landau_damping_ctx -create_ctx(void) +struct landau_damping_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -83,7 +81,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -109,14 +108,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -127,15 +125,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double alpha = app->alpha; double k0 = app->k0; - double n = (1.0 + alpha * cos(k0 * x)) * - (1.0 / sqrt(2.0 * pi * vt * vt)) * (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function. + double n = (1.0 + alpha * cos(k0 * x)) * (1.0 / sqrt(2.0 * pi * vt * vt)) * + (exp(-(vx * vx) / (2.0 * vt * vt))); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; double x = xn[0]; @@ -150,17 +147,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; @@ -170,8 +170,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -189,32 +188,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -239,18 +240,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -258,39 +258,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -313,62 +299,53 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -380,10 +357,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -392,32 +373,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -433,7 +421,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -449,8 +437,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -458,7 +445,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -467,8 +456,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -488,14 +476,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_landau_damping_1x3v_p2.c b/vlasov/creg/rt_vlasov_landau_damping_1x3v_p2.c index 9a6d445a39..c8ac48dff7 100644 --- a/vlasov/creg/rt_vlasov_landau_damping_1x3v_p2.c +++ b/vlasov/creg/rt_vlasov_landau_damping_1x3v_p2.c @@ -19,8 +19,7 @@ #include -struct landau_damping_ctx -{ +struct landau_damping_ctx { // Mathematical constants (dimensionless). double pi; @@ -57,8 +56,7 @@ struct landau_damping_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct landau_damping_ctx -create_ctx(void) +struct landau_damping_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -91,7 +89,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -121,14 +120,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; double x = xn[0], vx = xn[1], vy = xn[2], vz = xn[3]; @@ -140,15 +138,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double k0 = app->k0; double v_sq = (vx * vx) + (vy * vy) + (vz * vz); - double n = (1.0 + alpha * cos(k0 * x)) * - (1.0 / (pow(sqrt(2.0 * pi * vt * vt), 3.0))) * (exp(-v_sq / (2.0 * vt * vt))); // Distribution function. + double n = (1.0 + alpha * cos(k0 * x)) * (1.0 / (pow(sqrt(2.0 * pi * vt * vt), 3.0))) * + (exp(-v_sq / (2.0 * vt * vt))); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; double x = xn[0]; @@ -163,17 +160,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; @@ -183,8 +183,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -202,32 +201,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -254,18 +255,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -273,39 +273,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -328,62 +314,53 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 3, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 3, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -395,10 +372,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -407,32 +388,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -448,7 +436,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -464,8 +452,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -473,7 +460,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -482,8 +471,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -503,14 +491,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_lbo_cross_1x1v_p2.c b/vlasov/creg/rt_vlasov_lbo_cross_1x1v_p2.c index 46f75c1124..b787d8ddde 100644 --- a/vlasov/creg/rt_vlasov_lbo_cross_1x1v_p2.c +++ b/vlasov/creg/rt_vlasov_lbo_cross_1x1v_p2.c @@ -19,8 +19,7 @@ #include -struct lbo_cross_ctx -{ +struct lbo_cross_ctx { // Mathematical constants (dimensionless). double pi; @@ -62,8 +61,7 @@ struct lbo_cross_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_cross_ctx -create_ctx(void) +struct lbo_cross_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -92,8 +90,10 @@ create_ctx(void) int Nx = 16; // Cell count (configuration space: x-direction). int Nvx = 32; // Cell count (velocity space: vx-direction). double Lx = 1.0; // Domain size (configuration space: x-direction). - double vx_max_neut1 = 6.0 * vt_neut1; // First neutral domain boundary (velocity space: vx-direction). - double vx_max_neut2 = 6.0 * vt_neut2; // Second neutral domain boundary (velocity space: vx-direction). + double vx_max_neut1 = + 6.0 * vt_neut1; // First neutral domain boundary (velocity space: vx-direction). + double vx_max_neut2 = + 6.0 * vt_neut2; // Second neutral domain boundary (velocity space: vx-direction). int poly_order = 2; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. @@ -101,10 +101,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lbo_cross_ctx ctx = { .pi = pi, .mass_neut1 = mass_neut1, @@ -134,18 +135,17 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalNeut1Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeut1Init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_ctx *app = ctx; double vx = xn[1]; - + double pi = app->pi; double n0_neut1 = app->n0_neut1; @@ -154,18 +154,18 @@ evalNeut1Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double v_sq = (vx - ux0_neut1) * (vx - ux0_neut1); - double n = (n0_neut1 / sqrt(2.0 * pi * vt_neut1 * vt_neut1)) * exp(-v_sq / (2.0 * vt_neut1 * vt_neut1)); // Distribution function. + double n = (n0_neut1 / sqrt(2.0 * pi * vt_neut1 * vt_neut1)) * + exp(-v_sq / (2.0 * vt_neut1 * vt_neut1)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNeut2Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeut2Init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_ctx *app = ctx; double vx = xn[1]; - + double pi = app->pi; double n0_neut2 = app->n0_neut2; @@ -174,14 +174,14 @@ evalNeut2Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double v_sq = (vx - ux0_neut2) * (vx - ux0_neut2); - double n = (n0_neut2 / sqrt(2.0 * pi * vt_neut2 * vt_neut2)) * exp(-v_sq / (2.0 * vt_neut2 * vt_neut2)); // Distribution function. + double n = (n0_neut2 / sqrt(2.0 * pi * vt_neut2 * vt_neut2)) * + exp(-v_sq / (2.0 * vt_neut2 * vt_neut2)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNeut1Nu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeut1Nu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_ctx *app = ctx; @@ -191,8 +191,7 @@ evalNeut1Nu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout fout[0] = nu_neut1; } -void -evalNeut2Nu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeut2Nu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_ctx *app = ctx; @@ -202,8 +201,7 @@ evalNeut2Nu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout fout[0] = nu_neut2; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -221,32 +219,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -271,18 +271,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -290,39 +289,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -345,80 +330,69 @@ main(int argc, char **argv) // First neutral species. struct gkyl_vlasov_species neut1 = { .name = "neut1", - .charge = ctx.charge_neut1, .mass = ctx.mass_neut1, - .lower = { -ctx.vx_max_neut1 }, - .upper = { ctx.vx_max_neut1 }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalNeut1Init, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNeut1Nu, - .ctx = &ctx, - .num_cross_collisions = 1, - .collide_with = { "neut2" }, - }, - + .charge = ctx.charge_neut1, + .mass = ctx.mass_neut1, + .lower = {-ctx.vx_max_neut1}, + .upper = {ctx.vx_max_neut1}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalNeut1Init, .ctx_func = &ctx}, + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, + .self_nu = evalNeut1Nu, + .ctx = &ctx, + .num_cross_collisions = 1, + .collide_with = {"neut2"}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Second neutral species. struct gkyl_vlasov_species neut2 = { .name = "neut2", - .charge = ctx.charge_neut2, .mass = ctx.mass_neut2, - .lower = { -ctx.vx_max_neut2 }, - .upper = { ctx.vx_max_neut2 }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalNeut2Init, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNeut2Nu, - .ctx = &ctx, - .num_cross_collisions = 1, - .collide_with = { "neut1" }, - }, - + .charge = ctx.charge_neut2, + .mass = ctx.mass_neut2, + .lower = {-ctx.vx_max_neut2}, + .upper = {ctx.vx_max_neut2}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalNeut2Init, .ctx_func = &ctx}, + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, + .self_nu = evalNeut2Nu, + .ctx = &ctx, + .num_cross_collisions = 1, + .collide_with = {"neut1"}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { neut1, neut2 }, + .species = {neut1, neut2}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -432,10 +406,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -444,32 +422,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -485,7 +470,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -501,8 +486,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -510,7 +494,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -519,14 +505,13 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } step += 1; } - + calc_field_energy(&fe_trig, app, t_curr, false); calc_integrated_mom(&im_trig, app, t_curr, false); calc_integrated_L2_f(&l2f_trig, app, t_curr, false); @@ -540,14 +525,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_lbo_cross_1x2v_p2.c b/vlasov/creg/rt_vlasov_lbo_cross_1x2v_p2.c index 4166f97f1c..c4dbef6e05 100644 --- a/vlasov/creg/rt_vlasov_lbo_cross_1x2v_p2.c +++ b/vlasov/creg/rt_vlasov_lbo_cross_1x2v_p2.c @@ -19,8 +19,7 @@ #include -struct lbo_cross_ctx -{ +struct lbo_cross_ctx { // Mathematical constants (dimensionless). double pi; @@ -67,8 +66,7 @@ struct lbo_cross_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_cross_ctx -create_ctx(void) +struct lbo_cross_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -76,7 +74,7 @@ create_ctx(void) // Physical constants (using normalized code units). double mass_neut1 = 1.0; // First neutral mass. double mass_neut2 = 0.05; // Second neutral mass. - double charge_neut1 = 0.0; // First neutral charge. + double charge_neut1 = 0.0; // First neutral charge. double charge_neut2 = 0.0; // Second neutral charge. double p_neut1 = 1.0; // First neutral pressure. @@ -100,10 +98,14 @@ create_ctx(void) int Nvx = 32; // Cell count (velocity space: vx-direction). int Nvy = 32; // Cell count (velocity space: vy-direction). double Lx = 1.0; // Domain size (configuration space: x-direction). - double vx_max_neut1 = 6.0 * vt_neut1; // First neutral domain boundary (velocity space: vx-direction). - double vx_max_neut2 = 6.0 * vt_neut2; // Second neutral domain boundary (velocity space: vx-direction). - double vy_max_neut1 = 6.0 * vt_neut1; // First neutral domain boundary (velocity space: vy-direction). - double vy_max_neut2 = 6.0 * vt_neut2; // Second neutral domain boundary (velocity space: vy-direction). + double vx_max_neut1 = + 6.0 * vt_neut1; // First neutral domain boundary (velocity space: vx-direction). + double vx_max_neut2 = + 6.0 * vt_neut2; // Second neutral domain boundary (velocity space: vx-direction). + double vy_max_neut1 = + 6.0 * vt_neut1; // First neutral domain boundary (velocity space: vy-direction). + double vy_max_neut2 = + 6.0 * vt_neut2; // Second neutral domain boundary (velocity space: vy-direction). int poly_order = 2; // Polynomial order. double cfl_frac = 1.0; // CFL coefficient. @@ -111,10 +113,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lbo_cross_ctx ctx = { .pi = pi, .mass_neut1 = mass_neut1, @@ -149,18 +152,17 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalNeut1Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeut1Init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_ctx *app = ctx; double vx = xn[1], vy = xn[2]; - + double pi = app->pi; double n0_neut1 = app->n0_neut1; @@ -170,18 +172,18 @@ evalNeut1Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double v_sq = ((vx - ux0_neut1) * (vx - ux0_neut1)) + ((vy - uy0_neut1) * (vy - uy0_neut1)); - double n = (n0_neut1 / (2.0 * pi * vt_neut1 * vt_neut1)) * exp(-v_sq / (2.0 * vt_neut1 * vt_neut1)); // Distribution function. + double n = (n0_neut1 / (2.0 * pi * vt_neut1 * vt_neut1)) * + exp(-v_sq / (2.0 * vt_neut1 * vt_neut1)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNeut2Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeut2Init(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_ctx *app = ctx; double vx = xn[1], vy = xn[2]; - + double pi = app->pi; double n0_neut2 = app->n0_neut2; @@ -191,14 +193,14 @@ evalNeut2Init(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double v_sq = ((vx - ux0_neut2) * (vx - ux0_neut2)) + ((vy - uy0_neut2) * (vy - uy0_neut2)); - double n = (n0_neut2 / (2.0 * pi * vt_neut2 * vt_neut2)) * exp(-v_sq / (2.0 * vt_neut2 * vt_neut2)); // Distribution function. + double n = (n0_neut2 / (2.0 * pi * vt_neut2 * vt_neut2)) * + exp(-v_sq / (2.0 * vt_neut2 * vt_neut2)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNeut1Nu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeut1Nu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_ctx *app = ctx; @@ -208,8 +210,7 @@ evalNeut1Nu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout fout[0] = nu_neut1; } -void -evalNeut2Nu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeut2Nu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_cross_ctx *app = ctx; @@ -219,8 +220,7 @@ evalNeut2Nu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout fout[0] = nu_neut2; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -238,32 +238,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -289,18 +291,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -308,39 +309,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -363,80 +350,69 @@ main(int argc, char **argv) // First neutral species. struct gkyl_vlasov_species neut1 = { .name = "neut1", - .charge = ctx.charge_neut1, .mass = ctx.mass_neut1, - .lower = { -ctx.vx_max_neut1, -ctx.vy_max_neut1 }, - .upper = { ctx.vx_max_neut1, ctx.vy_max_neut1 }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalNeut1Init, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNeut1Nu, - .ctx = &ctx, - .num_cross_collisions = 1, - .collide_with = { "neut2" }, - }, - + .charge = ctx.charge_neut1, + .mass = ctx.mass_neut1, + .lower = {-ctx.vx_max_neut1, -ctx.vy_max_neut1}, + .upper = {ctx.vx_max_neut1, ctx.vy_max_neut1}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalNeut1Init, .ctx_func = &ctx}, + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, + .self_nu = evalNeut1Nu, + .ctx = &ctx, + .num_cross_collisions = 1, + .collide_with = {"neut2"}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Second neutral species. struct gkyl_vlasov_species neut2 = { .name = "neut2", - .charge = ctx.charge_neut2, .mass = ctx.mass_neut2, - .lower = { -ctx.vx_max_neut2, -ctx.vy_max_neut2 }, - .upper = { ctx.vx_max_neut2, ctx.vy_max_neut2 }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalNeut2Init, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNeut2Nu, - .ctx = &ctx, - .num_cross_collisions = 1, - .collide_with = { "neut1" }, - }, - + .charge = ctx.charge_neut2, + .mass = ctx.mass_neut2, + .lower = {-ctx.vx_max_neut2, -ctx.vy_max_neut2}, + .upper = {ctx.vx_max_neut2, ctx.vy_max_neut2}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalNeut2Init, .ctx_func = &ctx}, + .collisions = + {.collision_id = GKYL_LBO_COLLISIONS, + .self_nu = evalNeut2Nu, + .ctx = &ctx, + .num_cross_collisions = 1, + .collide_with = {"neut1"}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { neut1, neut2 }, + .species = {neut1, neut2}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -450,10 +426,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -462,32 +442,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -503,7 +490,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -519,8 +506,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -528,7 +514,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -537,8 +525,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -558,14 +545,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_lbo_relax_1x1v_p1.c b/vlasov/creg/rt_vlasov_lbo_relax_1x1v_p1.c index 11732ce46d..287685f508 100644 --- a/vlasov/creg/rt_vlasov_lbo_relax_1x1v_p1.c +++ b/vlasov/creg/rt_vlasov_lbo_relax_1x1v_p1.c @@ -19,14 +19,13 @@ #include -struct lbo_relax_ctx -{ +struct lbo_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double u0; // Reference velocity. @@ -55,8 +54,7 @@ struct lbo_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_relax_ctx -create_ctx(void) +struct lbo_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -87,10 +85,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lbo_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -115,26 +114,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1]; - + double n0 = app->n0; double n = 0.0; if (fabs(vx) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -142,8 +139,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1]; @@ -155,22 +151,22 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ub = app->ub; double vtb = app->vtb; double v_sq = (vx - u0) * (vx - u0); double vb_sq = (vx - ub) * (vx - ub); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -180,8 +176,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -199,32 +194,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -249,18 +246,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -268,39 +264,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -323,76 +305,59 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -406,10 +371,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -418,32 +387,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -459,7 +435,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -475,8 +451,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -484,7 +459,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -493,8 +470,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -514,14 +490,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_lbo_relax_1x1v_p2.c b/vlasov/creg/rt_vlasov_lbo_relax_1x1v_p2.c index ee5b0ca744..f371cc6f26 100644 --- a/vlasov/creg/rt_vlasov_lbo_relax_1x1v_p2.c +++ b/vlasov/creg/rt_vlasov_lbo_relax_1x1v_p2.c @@ -19,14 +19,13 @@ #include -struct lbo_relax_ctx -{ +struct lbo_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double u0; // Reference velocity. @@ -55,8 +54,7 @@ struct lbo_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_relax_ctx -create_ctx(void) +struct lbo_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -87,10 +85,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lbo_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -115,26 +114,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1]; - + double n0 = app->n0; double n = 0.0; if (fabs(vx) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -142,8 +139,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1]; @@ -155,22 +151,22 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ub = app->ub; double vtb = app->vtb; double v_sq = (vx - u0) * (vx - u0); double vb_sq = (vx - ub) * (vx - ub); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -180,8 +176,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -199,32 +194,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -249,18 +246,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -268,39 +264,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -323,76 +305,59 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -406,10 +371,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -418,32 +387,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -459,7 +435,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -475,8 +451,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -484,7 +459,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -493,8 +470,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -514,14 +490,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_lbo_relax_1x2v_p1.c b/vlasov/creg/rt_vlasov_lbo_relax_1x2v_p1.c index 24c00fdad4..f4f0cedc56 100644 --- a/vlasov/creg/rt_vlasov_lbo_relax_1x2v_p1.c +++ b/vlasov/creg/rt_vlasov_lbo_relax_1x2v_p1.c @@ -19,14 +19,13 @@ #include -struct lbo_relax_ctx -{ +struct lbo_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double ux0; // Reference velocity (x-direction). @@ -59,8 +58,7 @@ struct lbo_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_relax_ctx -create_ctx(void) +struct lbo_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -95,10 +93,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lbo_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -127,26 +126,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2]; - + double n0 = app->n0; double n = 0.0; - if(fabs(vx) < 1.0 && fabs(vy) < 1.0) { + if (fabs(vx) < 1.0 && fabs(vy) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -154,8 +151,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2]; @@ -168,7 +164,7 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ubx = app->ubx; double uby = app->uby; double vtb = app->vtb; @@ -176,15 +172,15 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vx - ux0) * (vx - ux0)) + ((vy - uy0) * (vy - uy0)); double vb_sq = ((vx - ubx) * (vx - ubx)) + ((vy - uby) * (vy - uby)); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -194,8 +190,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -213,32 +208,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -264,18 +261,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -283,39 +279,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -338,76 +320,59 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -421,10 +386,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -433,32 +402,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -474,7 +450,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -490,8 +466,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -499,7 +474,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -508,8 +485,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -529,14 +505,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_lbo_relax_1x2v_p2.c b/vlasov/creg/rt_vlasov_lbo_relax_1x2v_p2.c index 1496886264..27660d3096 100644 --- a/vlasov/creg/rt_vlasov_lbo_relax_1x2v_p2.c +++ b/vlasov/creg/rt_vlasov_lbo_relax_1x2v_p2.c @@ -19,14 +19,13 @@ #include -struct lbo_relax_ctx -{ +struct lbo_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double ux0; // Reference velocity (x-direction). @@ -59,8 +58,7 @@ struct lbo_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_relax_ctx -create_ctx(void) +struct lbo_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -95,10 +93,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lbo_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -127,26 +126,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2]; - + double n0 = app->n0; double n = 0.0; - if(fabs(vx) < 1.0 && fabs(vy) < 1.0) { + if (fabs(vx) < 1.0 && fabs(vy) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -154,8 +151,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2]; @@ -168,7 +164,7 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ubx = app->ubx; double uby = app->uby; double vtb = app->vtb; @@ -176,15 +172,15 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vx - ux0) * (vx - ux0)) + ((vy - uy0) * (vy - uy0)); double vb_sq = ((vx - ubx) * (vx - ubx)) + ((vy - uby) * (vy - uby)); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -194,8 +190,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -213,32 +208,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -264,18 +261,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -283,39 +279,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -338,76 +320,59 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -421,10 +386,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -433,32 +402,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -474,7 +450,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -490,8 +466,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -499,7 +474,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -508,8 +485,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -529,14 +505,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_lbo_relax_1x3v_p1.c b/vlasov/creg/rt_vlasov_lbo_relax_1x3v_p1.c index 0faf1ad881..61a8777070 100644 --- a/vlasov/creg/rt_vlasov_lbo_relax_1x3v_p1.c +++ b/vlasov/creg/rt_vlasov_lbo_relax_1x3v_p1.c @@ -19,14 +19,13 @@ #include -struct lbo_relax_ctx -{ +struct lbo_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double ux0; // Reference velocity (x-direction). @@ -63,8 +62,7 @@ struct lbo_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_relax_ctx -create_ctx(void) +struct lbo_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -103,10 +101,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lbo_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -139,26 +138,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2], vz = xn[3]; - + double n0 = app->n0; double n = 0.0; - if(fabs(vx) < 1.0 && fabs(vy) < 1.0 && fabs(vz) < 1.0) { + if (fabs(vx) < 1.0 && fabs(vy) < 1.0 && fabs(vz) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -166,8 +163,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2], vz = xn[3]; @@ -181,7 +177,7 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ubx = app->ubx; double uby = app->uby; double ubz = app->ubz; @@ -190,15 +186,15 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vx - ux0) * (vx - ux0)) + ((vy - uy0) * (vy - uy0)) + ((vz - uz0) * (vz - uz0)); double vb_sq = ((vx - ubx) * (vx - ubx)) + ((vy - uby) * (vy - uby)) + ((vz - ubz) * (vz - ubz)); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -208,8 +204,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -227,32 +222,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -279,18 +276,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -298,39 +294,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -353,76 +335,59 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 3, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 3, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -436,10 +401,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -448,32 +417,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -489,7 +465,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -505,8 +481,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -514,7 +489,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -523,8 +500,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -544,14 +520,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_lbo_relax_1x3v_p2.c b/vlasov/creg/rt_vlasov_lbo_relax_1x3v_p2.c index 52579f68f0..7127061459 100644 --- a/vlasov/creg/rt_vlasov_lbo_relax_1x3v_p2.c +++ b/vlasov/creg/rt_vlasov_lbo_relax_1x3v_p2.c @@ -19,14 +19,13 @@ #include -struct lbo_relax_ctx -{ +struct lbo_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double ux0; // Reference velocity (x-direction). @@ -63,8 +62,7 @@ struct lbo_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct lbo_relax_ctx -create_ctx(void) +struct lbo_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -103,10 +101,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct lbo_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -139,26 +138,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2], vz = xn[3]; - + double n0 = app->n0; double n = 0.0; - if(fabs(vx) < 1.0 && fabs(vy) < 1.0 && fabs(vz) < 1.0) { + if (fabs(vx) < 1.0 && fabs(vy) < 1.0 && fabs(vz) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -166,8 +163,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; double vx = xn[1], vy = xn[2], vz = xn[3]; @@ -181,7 +177,7 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ubx = app->ubx; double uby = app->uby; double ubz = app->ubz; @@ -190,15 +186,15 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double v_sq = ((vx - ux0) * (vx - ux0)) + ((vy - uy0) * (vy - uy0)) + ((vz - uz0) * (vz - uz0)); double vb_sq = ((vx - ubx) * (vx - ubx)) + ((vy - uby) * (vy - uby)) + ((vz - ubz) * (vz - ubz)); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct lbo_relax_ctx *app = ctx; @@ -208,8 +204,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -227,32 +222,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -279,18 +276,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -298,39 +294,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -353,76 +335,59 @@ main(int argc, char **argv) // Top hat species. struct gkyl_vlasov_species square = { .name = "square", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 3, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 3, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -436,10 +401,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -448,32 +417,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -489,7 +465,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -505,8 +481,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -514,7 +489,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -523,8 +500,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -544,14 +520,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_moments.c b/vlasov/creg/rt_vlasov_moments.c index d55365fc32..7194841ded 100644 --- a/vlasov/creg/rt_vlasov_moments.c +++ b/vlasov/creg/rt_vlasov_moments.c @@ -8,139 +8,170 @@ #include #include -void -evalDistFunc1x1v(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFunc1x1v( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], vx = xn[1]; - double n = 1.0*sin(2*M_PI*x); - double ux = 0.1*cos(2*M_PI*x); - double Txx = 0.75 + 0.25*cos(2*M_PI*x); - - double u2 = (vx-ux)*(vx-ux)/(2*Txx); - fout[0] = n/sqrt(2*M_PI*Txx)*exp(-u2); + double n = 1.0 * sin(2 * M_PI * x); + double ux = 0.1 * cos(2 * M_PI * x); + double Txx = 0.75 + 0.25 * cos(2 * M_PI * x); + + double u2 = (vx - ux) * (vx - ux) / (2 * Txx); + fout[0] = n / sqrt(2 * M_PI * Txx) * exp(-u2); } -void -evalDistFunc1x2v(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFunc1x2v( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], vx = xn[1], vy = xn[2]; - double n = 1.0*sin(2*M_PI*x); - double ux = 0.1*cos(2*M_PI*x); - double uy = 0.2*sin(2*M_PI*x); - double Txx = 0.75 + 0.25*cos(2*M_PI*x); - double Tyy = 0.75 + 0.25*sin(2*M_PI*x); - double Txy = 0.1 + 0.01*sin(2*M_PI*x)*cos(2*M_PI*x); - - double detT = Txx*Tyy-Txy*Txy; - double cx = vx-ux; - double cy = vy-uy; - - double u2 = (cx*(cx*Tyy-cy*Txy)+cy*(cy*Txx-cx*Txy))/(2*detT); - fout[0] = n/(2*M_PI*sqrt(detT))*exp(-u2); + double n = 1.0 * sin(2 * M_PI * x); + double ux = 0.1 * cos(2 * M_PI * x); + double uy = 0.2 * sin(2 * M_PI * x); + double Txx = 0.75 + 0.25 * cos(2 * M_PI * x); + double Tyy = 0.75 + 0.25 * sin(2 * M_PI * x); + double Txy = 0.1 + 0.01 * sin(2 * M_PI * x) * cos(2 * M_PI * x); + + double detT = Txx * Tyy - Txy * Txy; + double cx = vx - ux; + double cy = vy - uy; + + double u2 = (cx * (cx * Tyy - cy * Txy) + cy * (cy * Txx - cx * Txy)) / (2 * detT); + fout[0] = n / (2 * M_PI * sqrt(detT)) * exp(-u2); } -void -evalDistFunc1x3v(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFunc1x3v( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], vx = xn[1], vy = xn[2], vz = xn[3]; - double n = 1.0*sin(2*M_PI*x); - double ux = 0.1*cos(2*M_PI*x); - double uy = 0.2*sin(2*M_PI*x); - double uz = 0.1*cos(2*M_PI*x); - double Txx = 0.75 + 0.25*cos(2*M_PI*x); - double Tyy = 0.75 + 0.25*sin(2*M_PI*x); - double Tzz = 0.75 + 0.1*sin(2*M_PI*x); - double Txy = 0.5 + 0.1*sin(2*M_PI*x); - double Txz = 0.25 + 0.1*sin(2*M_PI*x); - double Tyz = 0.125 + 0.1*sin(2*M_PI*x); - - double cx = vx-ux; - double cy = vy-uy; - double cz = vz-uz; - - double detT = Txx*(Tyy*Tzz-Tyz*Tyz)-Txy*(Txy*Tzz-Txz*Tyz)+Txz*(Txy*Tyz-Txz*Tyy); - double u2 = cx*(cx*(Tyy*Tzz-Tyz*Tyz)+cy*(Txz*Tyz-Txy*Tzz)+cz*(Txy*Tyz-Txz*Tyy))+cy*(cx*(Txz*Tyz-Txy*Tzz)+cy*(Txx*Tzz-Txz*Txz)+cz*(Txy*Txz-Txx*Tyz))+cz*(cx*(Txy*Tyz-Txz*Tyy)+cy*(Txy*Txz-Txx*Tyz)+cz*(Txx*Tyy-Txy*Txy)); - u2 = u2/(2*detT); - fout[0] = n/sqrt((2*M_PI)*(2*M_PI)*(2*M_PI)*detT)*exp(-u2); + double n = 1.0 * sin(2 * M_PI * x); + double ux = 0.1 * cos(2 * M_PI * x); + double uy = 0.2 * sin(2 * M_PI * x); + double uz = 0.1 * cos(2 * M_PI * x); + double Txx = 0.75 + 0.25 * cos(2 * M_PI * x); + double Tyy = 0.75 + 0.25 * sin(2 * M_PI * x); + double Tzz = 0.75 + 0.1 * sin(2 * M_PI * x); + double Txy = 0.5 + 0.1 * sin(2 * M_PI * x); + double Txz = 0.25 + 0.1 * sin(2 * M_PI * x); + double Tyz = 0.125 + 0.1 * sin(2 * M_PI * x); + + double cx = vx - ux; + double cy = vy - uy; + double cz = vz - uz; + + double detT = + Txx * (Tyy * Tzz - Tyz * Tyz) - Txy * (Txy * Tzz - Txz * Tyz) + Txz * (Txy * Tyz - Txz * Tyy); + double u2 = + cx * + (cx * (Tyy * Tzz - Tyz * Tyz) + cy * (Txz * Tyz - Txy * Tzz) + cz * (Txy * Tyz - Txz * Tyy)) + + cy * + (cx * (Txz * Tyz - Txy * Tzz) + cy * (Txx * Tzz - Txz * Txz) + cz * (Txy * Txz - Txx * Tyz)) + + cz * + (cx * (Txy * Tyz - Txz * Tyy) + cy * (Txy * Txz - Txx * Tyz) + cz * (Txx * Tyy - Txy * Txy)); + u2 = u2 / (2 * detT); + fout[0] = n / sqrt((2 * M_PI) * (2 * M_PI) * (2 * M_PI) * detT) * exp(-u2); } -void -evalDistFunc2x2v(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFunc2x2v( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1], vx = xn[2], vy = xn[3]; - double n = 1.0*sin(2*M_PI*x)*sin(2*M_PI*y); - double ux = 0.1*cos(2*M_PI*x)*cos(2*M_PI*y); - double uy = 0.2*sin(2*M_PI*x)*sin(2*M_PI*y); - double Txx = 0.75 + 0.25*cos(2*M_PI*x)*cos(2*M_PI*y); - double Tyy = 0.75 + 0.25*sin(2*M_PI*x)*sin(2*M_PI*y); - double Txy = 0.1 + 0.01*sin(2*M_PI*x)*cos(2*M_PI*x)*sin(2*M_PI*y)*cos(2*M_PI*y); - - double detT = Txx*Tyy-Txy*Txy; - double cx = vx-ux; - double cy = vy-uy; - - double u2 = (cx*(cx*Tyy-cy*Txy)+cy*(cy*Txx-cx*Txy))/(2*detT); - fout[0] = n/(2*M_PI*sqrt(detT))*exp(-u2); + double n = 1.0 * sin(2 * M_PI * x) * sin(2 * M_PI * y); + double ux = 0.1 * cos(2 * M_PI * x) * cos(2 * M_PI * y); + double uy = 0.2 * sin(2 * M_PI * x) * sin(2 * M_PI * y); + double Txx = 0.75 + 0.25 * cos(2 * M_PI * x) * cos(2 * M_PI * y); + double Tyy = 0.75 + 0.25 * sin(2 * M_PI * x) * sin(2 * M_PI * y); + double Txy = + 0.1 + 0.01 * sin(2 * M_PI * x) * cos(2 * M_PI * x) * sin(2 * M_PI * y) * cos(2 * M_PI * y); + + double detT = Txx * Tyy - Txy * Txy; + double cx = vx - ux; + double cy = vy - uy; + + double u2 = (cx * (cx * Tyy - cy * Txy) + cy * (cy * Txx - cx * Txy)) / (2 * detT); + fout[0] = n / (2 * M_PI * sqrt(detT)) * exp(-u2); } -void -evalDistFunc2x3v(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFunc2x3v( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1], vx = xn[2], vy = xn[3], vz = xn[4]; - double n = 1.0*sin(2*M_PI*x)*sin(2*M_PI*y); - double ux = 0.1*cos(2*M_PI*x)*cos(2*M_PI*y); - double uy = 0.2*sin(2*M_PI*x)*sin(2*M_PI*y); - double uz = 0.1*cos(2*M_PI*x)*cos(2*M_PI*y); - - double Txx = 0.75 + 0.25*cos(2*M_PI*x)*cos(2*M_PI*y); - double Tyy = 0.75 + 0.25*sin(2*M_PI*x)*sin(2*M_PI*y); - double Tzz = 0.75 + 0.1*sin(2*M_PI*x)*sin(2*M_PI*y); - double Txy = 0.5 + 0.1*sin(2*M_PI*x)*sin(2*M_PI*y); - double Txz = 0.25 + 0.1*sin(2*M_PI*x)*sin(2*M_PI*y); - double Tyz = 0.125 + 0.1*sin(2*M_PI*x)*sin(2*M_PI*y); - - double cx = vx-ux; - double cy = vy-uy; - double cz = vz-uz; - - double detT = Txx*(Tyy*Tzz-Tyz*Tyz)-Txy*(Txy*Tzz-Txz*Tyz)+Txz*(Txy*Tyz-Txz*Tyy); - double u2 = cx*(cx*(Tyy*Tzz-Tyz*Tyz)+cy*(Txz*Tyz-Txy*Tzz)+cz*(Txy*Tyz-Txz*Tyy))+cy*(cx*(Txz*Tyz-Txy*Tzz)+cy*(Txx*Tzz-Txz*Txz)+cz*(Txy*Txz-Txx*Tyz))+cz*(cx*(Txy*Tyz-Txz*Tyy)+cy*(Txy*Txz-Txx*Tyz)+cz*(Txx*Tyy-Txy*Txy)); - u2 = u2/(2*detT); - fout[0] = n/sqrt((2*M_PI)*(2*M_PI)*(2*M_PI)*detT)*exp(-u2); + double n = 1.0 * sin(2 * M_PI * x) * sin(2 * M_PI * y); + double ux = 0.1 * cos(2 * M_PI * x) * cos(2 * M_PI * y); + double uy = 0.2 * sin(2 * M_PI * x) * sin(2 * M_PI * y); + double uz = 0.1 * cos(2 * M_PI * x) * cos(2 * M_PI * y); + + double Txx = 0.75 + 0.25 * cos(2 * M_PI * x) * cos(2 * M_PI * y); + double Tyy = 0.75 + 0.25 * sin(2 * M_PI * x) * sin(2 * M_PI * y); + double Tzz = 0.75 + 0.1 * sin(2 * M_PI * x) * sin(2 * M_PI * y); + double Txy = 0.5 + 0.1 * sin(2 * M_PI * x) * sin(2 * M_PI * y); + double Txz = 0.25 + 0.1 * sin(2 * M_PI * x) * sin(2 * M_PI * y); + double Tyz = 0.125 + 0.1 * sin(2 * M_PI * x) * sin(2 * M_PI * y); + + double cx = vx - ux; + double cy = vy - uy; + double cz = vz - uz; + + double detT = + Txx * (Tyy * Tzz - Tyz * Tyz) - Txy * (Txy * Tzz - Txz * Tyz) + Txz * (Txy * Tyz - Txz * Tyy); + double u2 = + cx * + (cx * (Tyy * Tzz - Tyz * Tyz) + cy * (Txz * Tyz - Txy * Tzz) + cz * (Txy * Tyz - Txz * Tyy)) + + cy * + (cx * (Txz * Tyz - Txy * Tzz) + cy * (Txx * Tzz - Txz * Txz) + cz * (Txy * Txz - Txx * Tyz)) + + cz * + (cx * (Txy * Tyz - Txz * Tyy) + cy * (Txy * Txz - Txx * Tyz) + cz * (Txx * Tyy - Txy * Txy)); + u2 = u2 / (2 * detT); + fout[0] = n / sqrt((2 * M_PI) * (2 * M_PI) * (2 * M_PI) * detT) * exp(-u2); } -void -evalDistFunc3x3v(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFunc3x3v( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], y = xn[1], z = xn[2], vx = xn[3], vy = xn[4], vz = xn[5]; - double n = 1.0*sin(2*M_PI*x)*sin(2*M_PI*y)*sin(2*M_PI*z); - double ux = 0.1*cos(2*M_PI*x)*cos(2*M_PI*y)*cos(2*M_PI*z); - double uy = 0.2*sin(2*M_PI*x)*sin(2*M_PI*y)*sin(2*M_PI*z); - double uz = 0.1*cos(2*M_PI*x)*cos(2*M_PI*y)*cos(2*M_PI*z); - - double Txx = 0.75 + 0.25*cos(2*M_PI*x)*cos(2*M_PI*y)*cos(2*M_PI*z); - double Tyy = 0.75 + 0.25*sin(2*M_PI*x)*sin(2*M_PI*y)*sin(2*M_PI*z); - double Tzz = 0.75 + 0.1*sin(2*M_PI*x)*sin(2*M_PI*y)*sin(2*M_PI*z); - double Txy = 0.5 + 0.1*sin(2*M_PI*x)*sin(2*M_PI*y)*sin(2*M_PI*z); - double Txz = 0.25 + 0.1*sin(2*M_PI*x)*sin(2*M_PI*y)*sin(2*M_PI*z); - double Tyz = 0.125 + 0.1*sin(2*M_PI*x)*sin(2*M_PI*y)*sin(2*M_PI*z); - - double cx = vx-ux; - double cy = vy-uy; - double cz = vz-uz; - - double detT = Txx*(Tyy*Tzz-Tyz*Tyz)-Txy*(Txy*Tzz-Txz*Tyz)+Txz*(Txy*Tyz-Txz*Tyy); - double u2 = cx*(cx*(Tyy*Tzz-Tyz*Tyz)+cy*(Txz*Tyz-Txy*Tzz)+cz*(Txy*Tyz-Txz*Tyy))+cy*(cx*(Txz*Tyz-Txy*Tzz)+cy*(Txx*Tzz-Txz*Txz)+cz*(Txy*Txz-Txx*Tyz))+cz*(cx*(Txy*Tyz-Txz*Tyy)+cy*(Txy*Txz-Txx*Tyz)+cz*(Txx*Tyy-Txy*Txy)); - u2 = u2/(2*detT); - fout[0] = n/sqrt((2*M_PI)*(2*M_PI)*(2*M_PI)*detT)*exp(-u2); + double n = 1.0 * sin(2 * M_PI * x) * sin(2 * M_PI * y) * sin(2 * M_PI * z); + double ux = 0.1 * cos(2 * M_PI * x) * cos(2 * M_PI * y) * cos(2 * M_PI * z); + double uy = 0.2 * sin(2 * M_PI * x) * sin(2 * M_PI * y) * sin(2 * M_PI * z); + double uz = 0.1 * cos(2 * M_PI * x) * cos(2 * M_PI * y) * cos(2 * M_PI * z); + + double Txx = 0.75 + 0.25 * cos(2 * M_PI * x) * cos(2 * M_PI * y) * cos(2 * M_PI * z); + double Tyy = 0.75 + 0.25 * sin(2 * M_PI * x) * sin(2 * M_PI * y) * sin(2 * M_PI * z); + double Tzz = 0.75 + 0.1 * sin(2 * M_PI * x) * sin(2 * M_PI * y) * sin(2 * M_PI * z); + double Txy = 0.5 + 0.1 * sin(2 * M_PI * x) * sin(2 * M_PI * y) * sin(2 * M_PI * z); + double Txz = 0.25 + 0.1 * sin(2 * M_PI * x) * sin(2 * M_PI * y) * sin(2 * M_PI * z); + double Tyz = 0.125 + 0.1 * sin(2 * M_PI * x) * sin(2 * M_PI * y) * sin(2 * M_PI * z); + + double cx = vx - ux; + double cy = vy - uy; + double cz = vz - uz; + + double detT = + Txx * (Tyy * Tzz - Tyz * Tyz) - Txy * (Txy * Tzz - Txz * Tyz) + Txz * (Txy * Tyz - Txz * Tyy); + double u2 = + cx * + (cx * (Tyy * Tzz - Tyz * Tyz) + cy * (Txz * Tyz - Txy * Tzz) + cz * (Txy * Tyz - Txz * Tyy)) + + cy * + (cx * (Txz * Tyz - Txy * Tzz) + cy * (Txx * Tzz - Txz * Txz) + cz * (Txy * Txz - Txx * Tyz)) + + cz * + (cx * (Txy * Tyz - Txz * Tyy) + cy * (Txy * Txz - Txx * Tyz) + cz * (Txx * Tyy - Txy * Txy)); + u2 = u2 / (2 * detT); + fout[0] = n / sqrt((2 * M_PI) * (2 * M_PI) * (2 * M_PI) * detT) * exp(-u2); } -void -evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { - fout[0] = 0.0; fout[1] = 0.0, fout[2] = 0.0; - fout[3] = 0.0; fout[4] = 0.0; fout[5] = 0.0; - fout[6] = 0.0; fout[7] = 0.0; + fout[0] = 0.0; + fout[1] = 0.0, fout[2] = 0.0; + fout[3] = 0.0; + fout[4] = 0.0; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } struct moment_inp { @@ -151,132 +182,125 @@ struct moment_inp { evalf_t eval; // function to project }; -struct moment_inp -get_inp(int argc, char **argv) +struct moment_inp get_inp(int argc, char **argv) { int c, cdim = 2, vdim = 2, poly_order = 2, nloop = 10; bool use_gpu = false; evalf_t eval = evalDistFunc2x2v; while ((c = getopt(argc, argv, "+hgc:v:p:n:")) != -1) { - switch (c) - { - case 'h': - printf("Usage: app_vlasov_moments -c CDIM -v VDIM -p POLYORDER -n NLOOP -g\n"); - exit(-1); - break; - - case 'c': - cdim = atoi(optarg); - break; - - case 'v': - vdim = atoi(optarg); - break; - - case 'p': - poly_order = atoi(optarg); - break; - - case 'n': - nloop = atoi(optarg); - break; - - case 'g': - use_gpu = true; - break; - - case '?': - break; + switch (c) { + case 'h': + printf("Usage: app_vlasov_moments -c CDIM -v VDIM -p POLYORDER -n NLOOP -g\n"); + exit(-1); + break; + + case 'c': + cdim = atoi(optarg); + break; + + case 'v': + vdim = atoi(optarg); + break; + + case 'p': + poly_order = atoi(optarg); + break; + + case 'n': + nloop = atoi(optarg); + break; + + case 'g': + use_gpu = true; + break; + + case '?': + break; } } - - if (cdim == 1 && vdim == 1) + + if (cdim == 1 && vdim == 1) { eval = evalDistFunc1x1v; - else if (cdim == 1 && vdim == 2) + } else if (cdim == 1 && vdim == 2) { eval = evalDistFunc1x2v; - else if (cdim == 1 && vdim == 3) + } else if (cdim == 1 && vdim == 3) { eval = evalDistFunc1x3v; - else if (cdim == 2 && vdim == 3) + } else if (cdim == 2 && vdim == 3) { eval = evalDistFunc2x3v; - else if (cdim == 3 && vdim == 3) + } else if (cdim == 3 && vdim == 3) { eval = evalDistFunc3x3v; - - return (struct moment_inp) { - .cdim = cdim, + } + + return (struct moment_inp + ){.cdim = cdim, .vdim = vdim, .poly_order = poly_order, - .ccells = { 8, 8, 8 }, - .vcells = { 16, 16, 16 }, + .ccells = {8, 8, 8}, + .vcells = {16, 16, 16}, .nloop = nloop, .eval = eval, - .use_gpu = use_gpu, - }; + .use_gpu = use_gpu}; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct moment_inp inp = get_inp(argc, argv); #ifdef GKYL_HAVE_CUDA - if (inp.use_gpu) + if (inp.use_gpu) { printf("Running moment calculation on GPU with:\n"); - else + } else { printf("Running moment calculation on CPU with:\n"); + } #else printf("Running moment calculation on CPU with:\n"); #endif printf("cdim = %d; vdim = %d; poly_order = %d\n", inp.cdim, inp.vdim, inp.poly_order); printf("cells = ["); - for (int d=0; d -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -52,8 +51,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -81,7 +79,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -107,14 +106,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -126,8 +124,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -135,8 +132,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -148,8 +144,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -157,8 +152,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -168,8 +162,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = Vx_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -179,8 +172,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -198,32 +190,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -248,18 +242,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -267,39 +260,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -323,58 +302,52 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_DEFAULT, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .correct_all_moms = true, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx, .correct_all_moms = true + }, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -388,10 +361,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -400,32 +377,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -441,7 +425,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -457,8 +441,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -466,7 +449,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -475,8 +460,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -496,14 +480,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x1v_p2.c b/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x1v_p2.c index 3cb906f932..aa26aba298 100644 --- a/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x1v_p2.c +++ b/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x1v_p2.c @@ -19,8 +19,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -52,8 +51,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -81,7 +79,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -107,14 +106,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -126,8 +124,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -135,8 +132,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -148,8 +144,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -157,8 +152,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -168,8 +162,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = Vx_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -179,8 +172,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -198,32 +190,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -248,18 +242,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -267,39 +260,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -323,58 +302,52 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_DEFAULT, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .correct_all_moms = true, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx, .correct_all_moms = true + }, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -388,10 +361,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -400,32 +377,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -441,7 +425,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -457,8 +441,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -466,7 +449,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -475,8 +460,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -496,14 +480,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x2v_p1.c b/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x2v_p1.c index ee357498a2..a7c276b0ee 100644 --- a/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x2v_p1.c +++ b/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x2v_p1.c @@ -19,8 +19,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -55,8 +54,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -87,7 +85,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -116,14 +115,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -135,8 +133,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -144,8 +141,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -157,8 +153,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -166,8 +161,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -175,11 +169,11 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double Vy_drift = app->Vy_drift; // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -189,8 +183,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -208,32 +201,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -259,18 +254,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -278,39 +272,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -334,58 +314,52 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_DEFAULT, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .correct_all_moms = true, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx, .correct_all_moms = true + }, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -399,10 +373,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -411,32 +389,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -452,7 +437,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -468,8 +453,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -477,7 +461,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -486,8 +472,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -507,14 +492,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x2v_p2.c b/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x2v_p2.c index 8c24e08793..653e52a641 100644 --- a/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x2v_p2.c +++ b/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x2v_p2.c @@ -19,8 +19,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -55,8 +54,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -87,7 +85,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -116,14 +115,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -135,8 +133,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -144,8 +141,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -157,8 +153,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -166,8 +161,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -175,11 +169,11 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double Vy_drift = app->Vy_drift; // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -189,8 +183,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -208,32 +201,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -259,18 +254,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -278,39 +272,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -334,58 +314,52 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_DEFAULT, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .correct_all_moms = true, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx, .correct_all_moms = true + }, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -399,10 +373,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -411,32 +389,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -452,7 +437,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -468,8 +453,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -477,7 +461,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -486,8 +472,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -507,14 +492,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x3v_p1.c b/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x3v_p1.c index 1119133054..ad00710ab7 100644 --- a/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x3v_p1.c +++ b/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x3v_p1.c @@ -19,8 +19,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -58,8 +57,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -93,7 +91,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -125,14 +124,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -144,8 +142,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -153,8 +150,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -166,8 +162,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -175,8 +170,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -185,11 +179,12 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double Vz_drift = app->Vz_drift; // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; fout[2] = Vz_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; + fout[2] = Vz_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -199,8 +194,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -218,32 +212,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -270,18 +266,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -289,39 +284,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -345,58 +326,52 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_DEFAULT, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .correct_all_moms = true, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx, .correct_all_moms = true + }, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 3, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 3, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -410,10 +385,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -422,32 +401,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -463,7 +449,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -479,8 +465,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -488,7 +473,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -497,8 +484,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -518,14 +504,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x3v_p2.c b/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x3v_p2.c index 572f5ca8fa..5cc67434c5 100644 --- a/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x3v_p2.c +++ b/vlasov/creg/rt_vlasov_neut_bgk_sodshock_1x3v_p2.c @@ -19,8 +19,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -58,8 +57,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -93,7 +91,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -125,14 +124,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -144,8 +142,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -153,8 +150,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -166,8 +162,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -175,8 +170,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -185,11 +179,12 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double Vz_drift = app->Vz_drift; // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; fout[2] = Vz_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; + fout[2] = Vz_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -199,8 +194,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -218,32 +212,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -270,18 +266,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -289,39 +284,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -345,58 +326,52 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_DEFAULT, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .correct_all_moms = true, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx, .correct_all_moms = true + }, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 3, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 3, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -410,10 +385,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -422,32 +401,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -463,7 +449,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -479,8 +465,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -488,7 +473,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -497,8 +484,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -518,14 +504,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x1v_p2.c b/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x1v_p2.c index 3459770eab..35c3b2b8a7 100644 --- a/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x1v_p2.c +++ b/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x1v_p2.c @@ -19,8 +19,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -52,8 +51,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -81,7 +79,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -107,14 +106,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -126,8 +124,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -135,8 +132,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -148,8 +144,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -157,8 +152,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -168,8 +162,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = Vx_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -179,8 +172,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -198,32 +190,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -248,18 +242,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -267,39 +260,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -323,57 +302,50 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_DEFAULT, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -387,10 +359,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -399,32 +375,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -440,7 +423,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -456,8 +439,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -465,7 +447,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -474,8 +458,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -495,14 +478,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x2v_p2.c b/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x2v_p2.c index a1ba535380..a85261d73a 100644 --- a/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x2v_p2.c +++ b/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x2v_p2.c @@ -19,8 +19,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -55,8 +54,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -87,7 +85,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -116,14 +115,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -135,8 +133,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -144,8 +141,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -157,8 +153,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -166,8 +161,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -175,11 +169,11 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double Vy_drift = app->Vy_drift; // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -189,8 +183,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -208,32 +201,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -259,18 +254,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -278,39 +272,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -334,57 +314,50 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_DEFAULT, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -398,10 +371,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -410,32 +387,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -451,7 +435,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -467,8 +451,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -476,7 +459,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -485,8 +470,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -506,14 +490,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x3v_p2.c b/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x3v_p2.c index f5fb7449d8..b763002070 100644 --- a/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x3v_p2.c +++ b/vlasov/creg/rt_vlasov_neut_lbo_sodshock_1x3v_p2.c @@ -19,8 +19,7 @@ #include -struct sodshock_ctx -{ +struct sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -58,8 +57,7 @@ struct sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sodshock_ctx -create_ctx(void) +struct sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -93,7 +91,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -125,14 +124,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -144,8 +142,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -153,8 +150,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; double x = xn[0]; @@ -166,8 +162,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -175,8 +170,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -185,11 +179,12 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f double Vz_drift = app->Vz_drift; // Set total drift velocity. - fout[0] = Vx_drift; fout[1] = Vy_drift; fout[2] = Vz_drift; + fout[0] = Vx_drift; + fout[1] = Vy_drift; + fout[2] = Vz_drift; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sodshock_ctx *app = ctx; @@ -199,8 +194,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -218,32 +212,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -270,18 +266,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -289,39 +284,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -345,57 +326,50 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_DEFAULT, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 3, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 3, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -409,10 +383,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -421,32 +399,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -462,7 +447,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -478,8 +463,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -487,7 +471,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -496,8 +482,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -517,14 +502,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_neut_lbo_wall.c b/vlasov/creg/rt_vlasov_neut_lbo_wall.c index 804a9b8b83..3fa4460746 100644 --- a/vlasov/creg/rt_vlasov_neut_lbo_wall.c +++ b/vlasov/creg/rt_vlasov_neut_lbo_wall.c @@ -19,14 +19,13 @@ #include -struct neut_lbo_wall_ctx -{ +struct neut_lbo_wall_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Neutral mass. - double charge; // Neutral charge. + double charge; // Neutral charge. double n0; // Reference number density. double u0; // Reference velocity. @@ -50,8 +49,7 @@ struct neut_lbo_wall_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct neut_lbo_wall_ctx -create_ctx(void) +struct neut_lbo_wall_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -77,10 +75,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct neut_lbo_wall_ctx ctx = { .pi = pi, .mass = mass, @@ -101,14 +100,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeutInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct neut_lbo_wall_ctx *app = ctx; double v = xn[1]; @@ -120,14 +118,14 @@ evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double v_sq = (v - u0) * (v - u0); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)); // Distribution function. + double n = + (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct neut_lbo_wall_ctx *app = ctx; @@ -137,8 +135,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -156,32 +153,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -206,18 +205,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -225,39 +223,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -280,58 +264,45 @@ main(int argc, char **argv) // Neutral species. struct gkyl_vlasov_species neut = { .name = "neut", - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalNeutInit, - .ctx_func = &ctx, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, - - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalNeutInit, .ctx_func = &ctx}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_REFLECT}}, + + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -345,10 +316,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -357,32 +332,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -398,7 +380,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -414,8 +396,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -423,7 +404,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -432,8 +415,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -453,14 +435,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_poisson_emission_spectrum_1x1v_p2.c b/vlasov/creg/rt_vlasov_poisson_emission_spectrum_1x1v_p2.c index ab9472b5d2..375b1687ea 100644 --- a/vlasov/creg/rt_vlasov_poisson_emission_spectrum_1x1v_p2.c +++ b/vlasov/creg/rt_vlasov_poisson_emission_spectrum_1x1v_p2.c @@ -49,73 +49,78 @@ struct sheath_ctx { int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -static inline double sq(double x) { return x*x; } +static inline double sq(double x) +{ + return x * x; +} -void -evalDistFuncElc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncElc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0], v = xn[1]; double vt = app->vte; double n = app->n0; - double fv = n/sqrt(2.0*M_PI*sq(vt))*(exp(-sq(v)/(2*sq(vt)))); + double fv = n / sqrt(2.0 * M_PI * sq(vt)) * (exp(-sq(v) / (2 * sq(vt)))); fout[0] = fv; } -void -evalDistFuncElcSource(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncElcSource( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], v = xn[1]; double vt = app->vte; double Ls = app->Ls; - double fv = 1.0/sqrt(2.0*M_PI*sq(vt))*(exp(-sq(v)/(2*sq(vt)))); - if(fabs(x) < Ls) { - fout[0] = (Ls - fabs(x))/Ls*fv; + double fv = 1.0 / sqrt(2.0 * M_PI * sq(vt)) * (exp(-sq(v) / (2 * sq(vt)))); + if (fabs(x) < Ls) { + fout[0] = (Ls - fabs(x)) / Ls * fv; } else { fout[0] = 0.0; } } -void -evalDistFuncIon(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncIon(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0], v = xn[1]; double vt = app->vti; double n = app->n0; - double fv = n/sqrt(2.0*M_PI*sq(vt))*(exp(-sq(v)/(2*sq(vt)))); + double fv = n / sqrt(2.0 * M_PI * sq(vt)) * (exp(-sq(v) / (2 * sq(vt)))); fout[0] = fv; } -void -evalDistFuncIonSource(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFuncIonSource( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], v = xn[1]; double vt = app->vti; double Ls = app->Ls; - double fv = 1.0/sqrt(2.0*M_PI*sq(vt))*(exp(-sq(v)/(2*sq(vt)))); - if(fabs(x) < Ls) { - fout[0] = (Ls - fabs(x))/Ls*fv; + double fv = 1.0 / sqrt(2.0 * M_PI * sq(vt)) * (exp(-sq(v) / (2 * sq(vt)))); + if (fabs(x) < Ls) { + fout[0] = (Ls - fabs(x)) / Ls * fv; } else { fout[0] = 0.0; } } -void -evalFieldFunc(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldFunc(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double x = xn[0]; - - fout[0] = 0.0; fout[1] = 0.0, fout[2] = 0.0; - fout[3] = 0.0; fout[4] = 0.0; fout[5] = 0.0; - fout[6] = 0.0; fout[7] = 0.0; + + fout[0] = 0.0; + fout[1] = 0.0, fout[2] = 0.0; + fout[3] = 0.0; + fout[4] = 0.0; + fout[5] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { int cdim = 1, vdim = 1; // Dimensionality. @@ -123,25 +128,25 @@ create_ctx(void) double mu0 = 1.257e-6; double massElc = 9.109e-31; - double massIon = 1836.153*massElc; + double massIon = 1836.153 * massElc; double q0 = 1.602e-19; double n0 = 1.0e17; - double Te0 = 10.0*q0; - double Ti0 = 10.0*q0; + double Te0 = 10.0 * q0; + double Ti0 = 10.0 * q0; - double vte0 = sqrt(Te0/massElc); - double vti0 = sqrt(Ti0/massIon); + double vte0 = sqrt(Te0 / massElc); + double vti0 = sqrt(Ti0 / massIon); - double omega_pe = sqrt(n0*q0*q0/(epsilon0*massElc)); - double lambda_D = sqrt(epsilon0*Te0/(n0*q0*q0)); + double omega_pe = sqrt(n0 * q0 * q0 / (epsilon0 * massElc)); + double lambda_D = sqrt(epsilon0 * Te0 / (n0 * q0 * q0)); - double Lx = 128.0*lambda_D; - double Ls = 100.0*lambda_D; + double Lx = 128.0 * lambda_D; + double Ls = 100.0 * lambda_D; int Nx = 128; int Nvx = 32; - + // SEE parameters double phi = 4.68; double deltahat_ts = 1.885; @@ -157,14 +162,15 @@ create_ctx(void) double W = 60.86; double p = 1.0; - double t_end = 10.0/omega_pe; // Final simulation time. + double t_end = 10.0 / omega_pe; // Final simulation time. int num_frames = 1; // Number of output frames. - int int_diag_calc_num = num_frames*100; + int int_diag_calc_num = num_frames * 100; double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. struct sheath_ctx ctx = { - .cdim = cdim, .vdim = vdim, + .cdim = cdim, + .vdim = vdim, .epsilon0 = epsilon0, .mu0 = mu0, .q0 = q0, @@ -195,20 +201,21 @@ create_ctx(void) .W = W, .p = p, .Nx = Nx, - .Nvx = Nvx, + .Nvx = Nvx, .cells = {Nx, Nvx}, .num_emission_species = 1, .t_end = t_end, .num_frames = num_frames, .int_diag_calc_num = int_diag_calc_num, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -calc_integrated_diagnostics(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_diagnostics( + struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); @@ -216,12 +223,11 @@ calc_integrated_diagnostics(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, d } } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { bool trig_now = gkyl_tm_trigger_check_and_bump(iot, t_curr); if (trig_now || force_write) { - int frame = (!trig_now) && force_write? iot->curr : iot->curr-1; + int frame = (!trig_now) && force_write ? iot->curr : iot->curr - 1; gkyl_vlasov_app_write(app, t_curr, frame); @@ -236,8 +242,7 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -255,16 +260,20 @@ main(int argc, char **argv) struct sheath_ctx ctx = create_ctx(); // Context for initialization functions. int cells_x[ctx.cdim], cells_v[ctx.vdim]; - for (int d=0; d= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); - calc_integrated_diagnostics(&trig_calc_intdiag, app, t_curr, true); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); + calc_integrated_diagnostics(&trig_calc_intdiag, app, t_curr, true); write_data(&trig_write, app, t_curr, true); break; } - } - else { + } else { num_failures = 0; } @@ -476,20 +468,28 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); gkyl_vlasov_app_cout(app, stdout, "IO time took %g secs \n", stat.io_tm); - freeresources: +freeresources: // Free resources after simulation completion. gkyl_vlasov_app_release(app); gkyl_vlasov_comms_release(comm); diff --git a/vlasov/creg/rt_vlasov_sheath_1x1v_p2.c b/vlasov/creg/rt_vlasov_sheath_1x1v_p2.c index 6fd87134c1..38f2dd2b7f 100644 --- a/vlasov/creg/rt_vlasov_sheath_1x1v_p2.c +++ b/vlasov/creg/rt_vlasov_sheath_1x1v_p2.c @@ -19,8 +19,7 @@ #include -struct sheath_ctx -{ +struct sheath_ctx { // Mathematical constants (dimensionless). double pi; @@ -62,8 +61,7 @@ struct sheath_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -86,7 +84,8 @@ create_ctx(void) double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. double lambda_D = sqrt(epsilon0 * Te / (n0 * charge_ion * charge_ion)); // Electron Debye length. - double omega_pe = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. + double omega_pe = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. // Simulation parameters. int Nx = 128; // Cell count (configuration space: x-direction). @@ -101,7 +100,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -133,14 +133,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double vx = xn[1]; @@ -149,14 +148,16 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double vte = app->vte; double n0 = app->n0; - double n = n0 / sqrt(2.0 * pi * (vte * vte)) * (exp(-(vx * vx) / (2.0 * (vte * vte)))); // Electron distribution function. + double n = n0 / sqrt(2.0 * pi * (vte * vte)) * + (exp(-(vx * vx) / (2.0 * (vte * vte)))); // Electron distribution function. // Set electron distribution function. fout[0] = n; } -void -evalElcSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -168,9 +169,10 @@ evalElcSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double n = 0.0; if (fabs(x) < Ls) { - n = 2.0 * (Ls - fabs(x)) / Ls * (1.0 / sqrt(2.0 * pi * (vte * vte)) * (exp(-(vx * vx) / (2.0 * (vte * vte))))); // Electron source distribution function (left). - } - else { + n = 2.0 * (Ls - fabs(x)) / Ls * + (1.0 / sqrt(2.0 * pi * (vte * vte)) * (exp(-(vx * vx) / (2.0 * (vte * vte)))) + ); // Electron source distribution function (left). + } else { n = 0.0; // Electron source distribution function (right). } @@ -178,8 +180,7 @@ evalElcSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = n; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double vx = xn[1]; @@ -188,15 +189,16 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double vti = app->vti; double n0 = app->n0; - double n = n0 / sqrt(2.0 * pi * (vti * vti)) * (exp(-(vx * vx) / (2.0 * (vti * vti)))); // Ion distribution function. - + double n = n0 / sqrt(2.0 * pi * (vti * vti)) * + (exp(-(vx * vx) / (2.0 * (vti * vti)))); // Ion distribution function. // Set ion distribution function. fout[0] = n; } -void -evalIonSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -208,9 +210,10 @@ evalIonSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double n = 0.0; if (fabs(x) < Ls) { - n = 2.0 * (Ls - fabs(x)) / Ls * (1.0 / sqrt(2.0 * pi * (vti * vti)) * (exp(-(vx * vx) / (2.0 * (vti * vti))))); // Ion source distribution function (left). - } - else { + n = 2.0 * (Ls - fabs(x)) / Ls * + (1.0 / sqrt(2.0 * pi * (vti * vti)) * (exp(-(vx * vx) / (2.0 * (vti * vti)))) + ); // Ion source distribution function (left). + } else { n = 0.0; // Ion source distribution function (right). } @@ -218,8 +221,7 @@ evalIonSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -230,15 +232,19 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -256,36 +262,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); - #ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Init(&argc, &argv); } @@ -308,16 +316,15 @@ main(int argc, char **argv) } #endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -332,32 +339,18 @@ main(int argc, char **argv) #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -380,114 +373,90 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, - - .source = { - .source_id = GKYL_BFLUX_SOURCE, - .source_length = ctx.Ls, - .source_species = "ion", - - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcSourceInit, - .ctx_func = &ctx, - }, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_ABSORB, }, - }, - + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, + + .source = + {.source_id = GKYL_BFLUX_SOURCE, + .source_length = ctx.Ls, + .source_species = "ion", + + .num_sources = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcSourceInit, .ctx_func = &ctx}}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_ABSORB}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Ions. struct gkyl_vlasov_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalIonInit, - .ctx_func = &ctx, - }, - - .source = { - .source_id = GKYL_BFLUX_SOURCE, - .source_length = ctx.Ls, - .source_species = "ion", - - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalIonSourceInit, - .ctx_func = &ctx, - }, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_ABSORB, }, - }, - + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalIonInit, .ctx_func = &ctx}, + + .source = + {.source_id = GKYL_BFLUX_SOURCE, + .source_length = ctx.Ls, + .source_species = "ion", + + .num_sources = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalIonSourceInit, .ctx_func = &ctx}}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_ABSORB}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .bcx = { GKYL_FIELD_SYM_WALL, GKYL_FIELD_PEC_WALL } + .bcx = {GKYL_FIELD_SYM_WALL, GKYL_FIELD_PEC_WALL} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, - + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, + .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -501,10 +470,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -513,32 +486,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -554,7 +534,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -570,8 +550,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -579,7 +558,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -588,8 +569,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -609,14 +589,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_sheath_bgk_1x1v_p2.c b/vlasov/creg/rt_vlasov_sheath_bgk_1x1v_p2.c index 5db0c9d201..9611d4bfff 100644 --- a/vlasov/creg/rt_vlasov_sheath_bgk_1x1v_p2.c +++ b/vlasov/creg/rt_vlasov_sheath_bgk_1x1v_p2.c @@ -19,8 +19,7 @@ #include -struct sheath_ctx -{ +struct sheath_ctx { // Mathematical constants (dimensionless). double pi; @@ -65,8 +64,7 @@ struct sheath_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -89,7 +87,8 @@ create_ctx(void) double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. double lambda_D = sqrt(epsilon0 * Te / (n0 * charge_ion * charge_ion)); // Electron Debye length. - double omega_pe = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. + double omega_pe = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. double nu_ee = vte / (50.0 * lambda_D); // Electron-electron collision frequency. double nu_ii = vti / (50.0 * lambda_D); // Ion-ion collision frequency. @@ -107,7 +106,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -141,14 +141,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double vx = xn[1]; @@ -157,14 +156,16 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double vte = app->vte; double n0 = app->n0; - double n = n0 / sqrt(2.0 * pi * (vte * vte)) * (exp(-(vx * vx) / (2.0 * (vte * vte)))); // Electron distribution function. + double n = n0 / sqrt(2.0 * pi * (vte * vte)) * + (exp(-(vx * vx) / (2.0 * (vte * vte)))); // Electron distribution function. // Set electron distribution function. fout[0] = n; } -void -evalElcSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -176,9 +177,10 @@ evalElcSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double n = 0.0; if (fabs(x) < Ls) { - n = 2.0 * (Ls - fabs(x)) / Ls * (1.0 / sqrt(2.0 * pi * (vte * vte)) * (exp(-(vx * vx) / (2.0 * (vte * vte))))); // Electron source distribution function (left). - } - else { + n = 2.0 * (Ls - fabs(x)) / Ls * + (1.0 / sqrt(2.0 * pi * (vte * vte)) * (exp(-(vx * vx) / (2.0 * (vte * vte)))) + ); // Electron source distribution function (left). + } else { n = 0.0; // Electron source distribution function (right). } @@ -186,8 +188,7 @@ evalElcSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = n; } -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; double vx = xn[1]; @@ -196,15 +197,16 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double vti = app->vti; double n0 = app->n0; - double n = n0 / sqrt(2.0 * pi * (vti * vti)) * (exp(-(vx * vx) / (2.0 * (vti * vti)))); // Ion distribution function. - + double n = n0 / sqrt(2.0 * pi * (vti * vti)) * + (exp(-(vx * vx) / (2.0 * (vti * vti)))); // Ion distribution function. // Set ion distribution function. fout[0] = n; } -void -evalIonSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -216,9 +218,10 @@ evalIonSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double n = 0.0; if (fabs(x) < Ls) { - n = 2.0 * (Ls - fabs(x)) / Ls * (1.0 / sqrt(2.0 * pi * (vti * vti)) * (exp(-(vx * vx) / (2.0 * (vti * vti))))); // Ion source distribution function (left). - } - else { + n = 2.0 * (Ls - fabs(x)) / Ls * + (1.0 / sqrt(2.0 * pi * (vti * vti)) * (exp(-(vx * vx) / (2.0 * (vti * vti)))) + ); // Ion source distribution function (left). + } else { n = 0.0; // Ion source distribution function (right). } @@ -226,8 +229,7 @@ evalIonSourceInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { double Ex = 0.0; // Total electric field (x-direction). double Ey = 0.0; // Total electric field (y-direction). @@ -238,15 +240,19 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bz = 0.0; // Total magnetic field (z-direction). // Set electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -255,14 +261,14 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double nu_ee = app->nu_ee; double lambda_D = app->lambda_D; - double nu = nu_ee / (1.0 + exp(fabs(x) / (6.0 * lambda_D) - 8.0 / 1.5)); // Electron collision frequency. + double nu = + nu_ee / (1.0 + exp(fabs(x) / (6.0 * lambda_D) - 8.0 / 1.5)); // Electron collision frequency. // Set electron collision frequency. fout[0] = nu; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -271,14 +277,14 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double nu_ii = app->nu_ii; double lambda_D = app->lambda_D; - double nu = nu_ii / (1.0 + exp(fabs(x) / (6.0 * lambda_D) - 8.0 / 1.5)); // Ion collision frequency. + double nu = + nu_ii / (1.0 + exp(fabs(x) / (6.0 * lambda_D) - 8.0 / 1.5)); // Ion collision frequency. // Set ion collision frequency. fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -296,36 +302,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); - #ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Init(&argc, &argv); } @@ -348,16 +356,15 @@ main(int argc, char **argv) } #endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -372,32 +379,18 @@ main(int argc, char **argv) #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -420,126 +413,100 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - .fixed_temp_relax = true, - }, - - .source = { - .source_id = GKYL_BFLUX_SOURCE, - .source_length = ctx.Ls, - .source_species = "ion", - - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcSourceInit, - .ctx_func = &ctx, - }, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_ABSORB, }, - }, - + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalElcNu, + .ctx = &ctx, + .fixed_temp_relax = true}, + + .source = + {.source_id = GKYL_BFLUX_SOURCE, + .source_length = ctx.Ls, + .source_species = "ion", + + .num_sources = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcSourceInit, .ctx_func = &ctx}}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_ABSORB}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Ions. struct gkyl_vlasov_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalIonInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - .fixed_temp_relax = true, - }, - - .source = { - .source_id = GKYL_BFLUX_SOURCE, - .source_length = ctx.Ls, - .source_species = "ion", - - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalIonSourceInit, - .ctx_func = &ctx, - }, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_REFLECT, }, - .upper = { .type = GKYL_SPECIES_ABSORB, }, - }, - + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalIonInit, .ctx_func = &ctx}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalIonNu, + .ctx = &ctx, + .fixed_temp_relax = true}, + + .source = + {.source_id = GKYL_BFLUX_SOURCE, + .source_length = ctx.Ls, + .source_species = "ion", + + .num_sources = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalIonSourceInit, .ctx_func = &ctx}}, + + .bcx = {.lower = {.type = GKYL_SPECIES_REFLECT}, .upper = {.type = GKYL_SPECIES_ABSORB}}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, .ctx = &ctx, - .bcx = { GKYL_FIELD_SYM_WALL, GKYL_FIELD_PEC_WALL } + .bcx = {GKYL_FIELD_SYM_WALL, GKYL_FIELD_PEC_WALL} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, - + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, + .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -553,10 +520,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -565,32 +536,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -606,7 +584,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -622,8 +600,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -631,7 +608,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -640,8 +619,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -661,14 +639,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_sr_bgk_relax_1x1v_p2.c b/vlasov/creg/rt_vlasov_sr_bgk_relax_1x1v_p2.c index 2b17cf31ab..997336d057 100644 --- a/vlasov/creg/rt_vlasov_sr_bgk_relax_1x1v_p2.c +++ b/vlasov/creg/rt_vlasov_sr_bgk_relax_1x1v_p2.c @@ -19,14 +19,13 @@ #include -struct bgk_relax_ctx -{ +struct bgk_relax_ctx { // Mathematical constants (dimensionless). double pi; // Physical constants (using normalized code units). double mass; // Top hat/bump mass. - double charge; // Top hat/bump charge. + double charge; // Top hat/bump charge. double n0; // Reference number density. double u0; // Reference velocity. @@ -55,8 +54,7 @@ struct bgk_relax_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct bgk_relax_ctx -create_ctx(void) +struct bgk_relax_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -87,10 +85,11 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - + struct bgk_relax_ctx ctx = { .pi = pi, .mass = mass, @@ -115,26 +114,24 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTopHatInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1]; - + double n0 = app->n0; double n = 0.0; if (fabs(vx) < 1.0) { n = 0.5 * n0; // Distribution function (low velocity). - } - else { + } else { n = 0.0; // Distribution function (high velocity). } @@ -142,8 +139,7 @@ evalTopHatInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = n; } -void -evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalBumpInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; double vx = xn[1]; @@ -155,22 +151,22 @@ evalBumpInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double vt = app->vt; double ab = app->ab; - double sb = app->sb; + double sb = app->sb; double ub = app->ub; double vtb = app->vtb; double v_sq = (vx - u0) * (vx - u0); double vb_sq = (vx - ub) * (vx - ub); - double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + (n0 / sqrt(2.0 * pi * vtb * vtb)) * - exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / (vb_sq + (sb * sb)); // Distribution function. + double n = (n0 / sqrt(2.0 * pi * vt * vt)) * exp(-v_sq / (2.0 * vt * vt)) + + (n0 / sqrt(2.0 * pi * vtb * vtb)) * exp(-vb_sq / (2.0 * vtb * vtb)) * (ab * ab) / + (vb_sq + (sb * sb)); // Distribution function. // Set distribution function. fout[0] = n; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct bgk_relax_ctx *app = ctx; @@ -180,8 +176,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -199,32 +194,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -249,18 +246,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -268,39 +264,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -324,77 +306,60 @@ main(int argc, char **argv) struct gkyl_vlasov_species square = { .name = "square", .model_id = GKYL_MODEL_SR, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalTopHatInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalTopHatInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Bump species. struct gkyl_vlasov_species bump = { .name = "bump", .model_id = GKYL_MODEL_SR, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalBumpInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalBumpInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; - // Vlasov-Maxwell app. + // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 2, - .species = { square, bump }, + .species = {square, bump}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -408,10 +373,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -420,32 +389,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -461,7 +437,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -477,8 +453,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -486,7 +461,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -495,8 +472,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -516,14 +492,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_sr_freestream.c b/vlasov/creg/rt_vlasov_sr_freestream.c index 8578823b25..b625216de2 100644 --- a/vlasov/creg/rt_vlasov_sr_freestream.c +++ b/vlasov/creg/rt_vlasov_sr_freestream.c @@ -19,8 +19,7 @@ #include -struct freestream_sr_ctx -{ +struct freestream_sr_ctx { // Mathematical constants (dimensionless). double pi; @@ -50,8 +49,7 @@ struct freestream_sr_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct freestream_sr_ctx -create_ctx(void) +struct freestream_sr_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -77,7 +75,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -100,14 +99,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNeutInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct freestream_sr_ctx *app = ctx; double x = xn[0], v = xn[1]; @@ -118,14 +116,14 @@ evalNeutInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou double alpha = app->alpha; double kx = app->kx; - double n = (1.0 + alpha * cos(kx * x)) * exp(-(v * v) / (2.0 * vt * vt)); // Distribution function. + double n = + (1.0 + alpha * cos(kx * x)) * exp(-(v * v) / (2.0 * vt * vt)); // Distribution function. // Set distribution function. fout[0] = n; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -143,32 +141,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -193,18 +193,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -212,39 +211,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -268,48 +253,42 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_SR, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalNeutInit, - .ctx_func = &ctx, - }, + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalNeutInit, .ctx_func = &ctx}, .num_diag_moments = 2, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, - + + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, + .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { neut }, + .species = {neut}, .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -321,10 +300,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -333,32 +316,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -374,7 +364,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -390,8 +380,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -399,7 +388,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -408,8 +399,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -429,14 +419,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_sr_neut_bgk_sodshock_1x1v_p2.c b/vlasov/creg/rt_vlasov_sr_neut_bgk_sodshock_1x1v_p2.c index 069cfbf9b5..f0aa76f812 100644 --- a/vlasov/creg/rt_vlasov_sr_neut_bgk_sodshock_1x1v_p2.c +++ b/vlasov/creg/rt_vlasov_sr_neut_bgk_sodshock_1x1v_p2.c @@ -19,8 +19,7 @@ #include -struct sr_sodshock_ctx -{ +struct sr_sodshock_ctx { // Physical constants (using normalized code units). double mass; // Neutral mass. double charge; // Neutral charge. @@ -56,8 +55,7 @@ struct sr_sodshock_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sr_sodshock_ctx -create_ctx(void) +struct sr_sodshock_ctx create_ctx(void) { // Physical constants (using normalized code units). double mass = 1.0; // Neutral mass. @@ -89,7 +87,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -117,14 +116,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sr_sodshock_ctx *app = ctx; double x = xn[0]; @@ -136,8 +134,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT if (x < 0.5) { n = nl; // Total number density (left). - } - else { + } else { n = nr; // Total number density (right). } @@ -145,8 +142,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sr_sodshock_ctx *app = ctx; double x = xn[0]; @@ -158,8 +154,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou if (x < 0.5) { T = Tl; // Isotropic temperature (left). - } - else { + } else { T = Tr; // Isotropic temperature (right). } @@ -167,8 +162,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sr_sodshock_ctx *app = ctx; @@ -178,8 +172,7 @@ evalVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT f fout[0] = Vx_drift_SR; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sr_sodshock_ctx *app = ctx; @@ -189,8 +182,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -208,32 +200,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -258,18 +252,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -277,39 +270,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -333,58 +312,52 @@ main(int argc, char **argv) struct gkyl_vlasov_species neut = { .name = "neut", .model_id = GKYL_MODEL_SR, - .charge = ctx.charge, .mass = ctx.mass, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - .correct_all_moms = true, - }, - + .charge = ctx.charge, + .mass = ctx.mass, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, + + .num_init = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, .self_nu = evalNu, .ctx = &ctx, .correct_all_moms = true + }, + .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_LTE} }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, - .poly_order = ctx.poly_order, - .basis_type = app_args.basis_type, - .cfl_frac = ctx.cfl_frac, + .poly_order = ctx.poly_order, + .basis_type = app_args.basis_type, + .cfl_frac = ctx.cfl_frac, - .num_periodic_dir = 0, - .periodic_dirs = { }, + .num_periodic_dir = 0, + .periodic_dirs = {}, - .num_species = 1, - .species = { neut }, + .num_species = 1, + .species = {neut}, - .skip_field = true, + .skip_field = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -398,10 +371,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -410,32 +387,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -451,7 +435,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -459,7 +443,7 @@ main(int argc, char **argv) t_curr += status.dt_actual; dt = status.dt_suggested; - + calc_field_energy(&fe_trig, app, t_curr, false); calc_integrated_mom(&im_trig, app, t_curr, false); calc_integrated_L2_f(&l2f_trig, app, t_curr, false); @@ -467,8 +451,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -476,7 +459,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -485,8 +470,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -506,14 +490,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_sr_twostream_1x1v.c b/vlasov/creg/rt_vlasov_sr_twostream_1x1v.c index 6bb1f745fa..cec487d57a 100644 --- a/vlasov/creg/rt_vlasov_sr_twostream_1x1v.c +++ b/vlasov/creg/rt_vlasov_sr_twostream_1x1v.c @@ -19,8 +19,7 @@ #include -struct twostream_sr_ctx -{ +struct twostream_sr_ctx { // Mathematical constants (dimensionless). double pi; @@ -58,8 +57,7 @@ struct twostream_sr_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct twostream_sr_ctx -create_ctx(void) +struct twostream_sr_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -70,7 +68,7 @@ create_ctx(void) double mass_elc = 1.0; // Electron mass. double charge_elc = -1.0; // Electron charge. - double n0 = 1.0; // Reference density. + double n0 = 1.0; // Reference density. double T = 0.04; // Temperature (units of mc^2). double Vx_drift = 0.9; // Drift velocity (x-direction). @@ -93,7 +91,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -103,7 +102,7 @@ create_ctx(void) .mu0 = mu0, .mass_elc = mass_elc, .charge_elc = charge_elc, - .n0 = n0, + .n0 = n0, .T = T, .Vx_drift = Vx_drift, .alpha = alpha, @@ -122,14 +121,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_sr_ctx *app = ctx; double x = xn[0]; @@ -142,8 +140,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = 0.5 * (1.0 + alpha * cos(kx * x)) * n0; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_sr_ctx *app = ctx; @@ -153,8 +150,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftLInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_sr_ctx *app = ctx; @@ -164,8 +160,7 @@ evalVDriftLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Vx_drift_SR; } -void -evalVDriftRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftRInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_sr_ctx *app = ctx; @@ -175,8 +170,7 @@ evalVDriftRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = -Vx_drift_SR; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_sr_ctx *app = ctx; double x = xn[0]; @@ -191,17 +185,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -219,32 +216,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -269,18 +268,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -288,39 +286,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -344,78 +328,75 @@ main(int argc, char **argv) struct gkyl_vlasov_species elc = { .name = "elc", .model_id = GKYL_MODEL_SR, - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, - .num_init = 2, + .num_init = 2, // Two counter-streaming Maxwellians. - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftLInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .use_last_converged = true, - }, - .projection[1] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftRInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .use_last_converged = true, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftLInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .use_last_converged = true}, + .projection[1] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftRInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .use_last_converged = true}, .num_diag_moments = 2, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -427,10 +408,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -439,32 +424,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -480,7 +472,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -496,8 +488,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -505,7 +496,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -514,8 +507,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -535,14 +527,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_sr_twostream_1x3v.c b/vlasov/creg/rt_vlasov_sr_twostream_1x3v.c index 0426175d64..a294738c96 100644 --- a/vlasov/creg/rt_vlasov_sr_twostream_1x3v.c +++ b/vlasov/creg/rt_vlasov_sr_twostream_1x3v.c @@ -19,8 +19,7 @@ #include -struct twostream_sr_ctx -{ +struct twostream_sr_ctx { // Mathematical constants (dimensionless). double pi; @@ -76,8 +75,7 @@ struct twostream_sr_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct twostream_sr_ctx -create_ctx(void) +struct twostream_sr_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -103,8 +101,12 @@ create_ctx(void) double kx = 0.5; // Perturbed wave number (x-direction). // Derived physical quantities (using normalized code units). - double gamma_elc1 = 1.0 / sqrt(1.0 - (ux_elc1 * ux_elc1) - (uy_elc1 * uy_elc1) - (uz_elc1 * uz_elc1)); // First electron gamma factor. - double gamma_elc2 = 1.0 / sqrt(1.0 - (ux_elc2 * ux_elc2) - (uy_elc2 * uy_elc2) - (uz_elc2 * uz_elc2)); // Second electron gamma factor. + double gamma_elc1 = 1.0 / sqrt( + 1.0 - (ux_elc1 * ux_elc1) - (uy_elc1 * uy_elc1) - (uz_elc1 * uz_elc1) + ); // First electron gamma factor. + double gamma_elc2 = 1.0 / sqrt( + 1.0 - (ux_elc2 * ux_elc2) - (uy_elc2 * uy_elc2) - (uz_elc2 * uz_elc2) + ); // Second electron gamma factor. double ux_elc1_sr = gamma_elc1 * ux_elc1; // First electron relativistic velocity (x-direction). double ux_elc2_sr = gamma_elc2 * ux_elc2; // Second electron relativistic velocity (x-direction). @@ -129,7 +131,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -175,14 +178,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityLInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct twostream_sr_ctx *app = ctx; double x = xn[0]; @@ -195,8 +199,9 @@ evalDensityLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = (1.0 + alpha * cos(kx * x)) * n_elc1; } -void -evalDensityRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityRInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct twostream_sr_ctx *app = ctx; double x = xn[0]; @@ -209,8 +214,7 @@ evalDensityRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = (1.0 + alpha * cos(kx * x)) * n_elc2; } -void -evalTempLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempLInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_sr_ctx *app = ctx; @@ -220,8 +224,7 @@ evalTempLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo fout[0] = T_elc1; } -void -evalTempRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempRInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_sr_ctx *app = ctx; @@ -231,8 +234,7 @@ evalTempRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo fout[0] = T_elc2; } -void -evalVDriftLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftLInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_sr_ctx *app = ctx; @@ -241,11 +243,12 @@ evalVDriftLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double uz_elc1_sr = app->uz_elc1_sr; // Set left-going relativistic drift velocity. - fout[0] = ux_elc1_sr; fout[1] = uy_elc1_sr; fout[2] = uz_elc1_sr; + fout[0] = ux_elc1_sr; + fout[1] = uy_elc1_sr; + fout[2] = uz_elc1_sr; } -void -evalVDriftRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftRInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_sr_ctx *app = ctx; @@ -254,11 +257,12 @@ evalVDriftRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double uz_elc2_sr = app->uz_elc2_sr; // Set right-going relativistic drift velocity. - fout[0] = ux_elc2_sr; fout[1] = uy_elc2_sr; fout[2] = uz_elc2_sr; + fout[0] = ux_elc2_sr; + fout[1] = uy_elc2_sr; + fout[2] = uz_elc2_sr; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_sr_ctx *app = ctx; double x = xn[0]; @@ -273,17 +277,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -301,32 +308,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -353,18 +362,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -372,39 +380,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -428,78 +422,75 @@ main(int argc, char **argv) struct gkyl_vlasov_species elc = { .name = "elc", .model_id = GKYL_MODEL_SR, - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max, }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, - .num_init = 2, + .num_init = 2, // Two counter-streaming Maxwellians. - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityLInit, - .ctx_density = &ctx, - .temp = evalTempLInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftLInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .use_last_converged = true, - }, - .projection[1] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityRInit, - .ctx_density = &ctx, - .temp = evalTempRInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftRInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .use_last_converged = true, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityLInit, + .ctx_density = &ctx, + .temp = evalTempLInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftLInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .use_last_converged = true}, + .projection[1] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityRInit, + .ctx_density = &ctx, + .temp = evalTempRInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftRInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .use_last_converged = true}, .num_diag_moments = 2, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 3, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 3, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -511,10 +502,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -523,32 +518,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -564,7 +566,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -580,8 +582,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -589,7 +590,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -598,8 +601,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -619,14 +621,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_sr_weibel_1x3v.c b/vlasov/creg/rt_vlasov_sr_weibel_1x3v.c index 84a69eaac3..68f54fefc4 100644 --- a/vlasov/creg/rt_vlasov_sr_weibel_1x3v.c +++ b/vlasov/creg/rt_vlasov_sr_weibel_1x3v.c @@ -19,8 +19,7 @@ #include -struct weibel_sr_ctx -{ +struct weibel_sr_ctx { // Mathematical constants (dimensionless). double pi; @@ -76,8 +75,7 @@ struct weibel_sr_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct weibel_sr_ctx -create_ctx(void) +struct weibel_sr_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -103,8 +101,12 @@ create_ctx(void) double kx = 0.4; // Perturbed wave number (x-direction). // Derived physical quantities (using normalized code units). - double gamma_elc1 = 1.0 / sqrt(1.0 - (ux_elc1 * ux_elc1) - (uy_elc1 * uy_elc1) - (uz_elc1 * uz_elc1)); // First electron gamma factor. - double gamma_elc2 = 1.0 / sqrt(1.0 - (ux_elc2 * ux_elc2) - (uy_elc2 * uy_elc2) - (uz_elc2 * uz_elc2)); // Second electron gamma factor. + double gamma_elc1 = 1.0 / sqrt( + 1.0 - (ux_elc1 * ux_elc1) - (uy_elc1 * uy_elc1) - (uz_elc1 * uz_elc1) + ); // First electron gamma factor. + double gamma_elc2 = 1.0 / sqrt( + 1.0 - (ux_elc2 * ux_elc2) - (uy_elc2 * uy_elc2) - (uz_elc2 * uz_elc2) + ); // Second electron gamma factor. double ux_elc1_sr = gamma_elc1 * ux_elc1; // First electron relativistic velocity (x-direction). double ux_elc2_sr = gamma_elc2 * ux_elc2; // Second electron relativistic velocity (x-direction). @@ -129,7 +131,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -175,14 +178,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityLInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct weibel_sr_ctx *app = ctx; double x = xn[0]; @@ -195,8 +199,9 @@ evalDensityLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalDensityRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityRInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct weibel_sr_ctx *app = ctx; double x = xn[0]; @@ -209,8 +214,7 @@ evalDensityRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempLInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_sr_ctx *app = ctx; @@ -220,8 +224,7 @@ evalTempLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo fout[0] = T; } -void -evalTempRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempRInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_sr_ctx *app = ctx; @@ -231,8 +234,7 @@ evalTempRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo fout[0] = T; } -void -evalVDriftLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftLInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_sr_ctx *app = ctx; @@ -242,13 +244,12 @@ evalVDriftLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double uz_elc = app->uz_elc1; // Set left-going distribution drift (four-) velocity. - fout[0] = gamma*ux_elc; - fout[1] = gamma*uy_elc; - fout[2] = gamma*uz_elc; + fout[0] = gamma * ux_elc; + fout[1] = gamma * uy_elc; + fout[2] = gamma * uz_elc; } -void -evalVDriftRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftRInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_sr_ctx *app = ctx; @@ -258,13 +259,12 @@ evalVDriftRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT double uz_elc = app->uz_elc2; // Set right-going distribution drift (four-) velocity. - fout[0] = gamma*ux_elc; - fout[1] = gamma*uy_elc; - fout[2] = gamma*uz_elc; + fout[0] = gamma * ux_elc; + fout[1] = gamma * uy_elc; + fout[2] = gamma * uz_elc; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_sr_ctx *app = ctx; double x = xn[0]; @@ -273,17 +273,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double kx = app->kx; double B_z = alpha * sin(kx * x); - + // Set electric field. - fout[0] = 0.0; fout[1] = 0.0, fout[2] = 0.0; + fout[0] = 0.0; + fout[1] = 0.0, fout[2] = 0.0; // Set magnetic field. - fout[3] = 0.0; fout[4] = 0.0; fout[5] = B_z; + fout[3] = 0.0; + fout[4] = 0.0; + fout[5] = B_z; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -301,32 +304,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -353,18 +358,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -372,39 +376,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -428,78 +418,75 @@ main(int argc, char **argv) struct gkyl_vlasov_species elc = { .name = "elc", .model_id = GKYL_MODEL_SR, - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max, -ctx.vy_max, -ctx.vz_max, }, - .upper = { ctx.vx_max, ctx.vy_max, ctx.vz_max }, - .cells = { NVX, NVY, NVZ }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max, -ctx.vy_max, -ctx.vz_max}, + .upper = {ctx.vx_max, ctx.vy_max, ctx.vz_max}, + .cells = {NVX, NVY, NVZ}, - .num_init = 2, + .num_init = 2, // Two counter-streaming Maxwellians. - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityLInit, - .ctx_density = &ctx, - .temp = evalTempLInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftLInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .use_last_converged = true, - }, - .projection[1] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityRInit, - .ctx_density = &ctx, - .temp = evalTempRInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftRInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - .use_last_converged = true, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityLInit, + .ctx_density = &ctx, + .temp = evalTempLInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftLInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .use_last_converged = true}, + .projection[1] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityRInit, + .ctx_density = &ctx, + .temp = evalTempRInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftRInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true, + .use_last_converged = true}, .num_diag_moments = 2, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 3, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 3, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -511,10 +498,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -523,32 +514,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -564,7 +562,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -580,8 +578,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -589,7 +586,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -598,8 +597,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -619,14 +617,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_twostream_p1.c b/vlasov/creg/rt_vlasov_twostream_p1.c index cbb91ae541..3be7162774 100644 --- a/vlasov/creg/rt_vlasov_twostream_p1.c +++ b/vlasov/creg/rt_vlasov_twostream_p1.c @@ -19,8 +19,7 @@ #include -struct twostream_ctx -{ +struct twostream_ctx { // Mathematical constants (dimensionless). double pi; @@ -60,8 +59,7 @@ struct twostream_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct twostream_ctx -create_ctx(void) +struct twostream_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -97,7 +95,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -107,7 +106,7 @@ create_ctx(void) .mu0 = mu0, .mass_elc = mass_elc, .charge_elc = charge_elc, - .n0 = n0, + .n0 = n0, .vt = vt, .Vx_drift = Vx_drift, .lambda_D = lambda_D, @@ -127,14 +126,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_ctx *app = ctx; double x = xn[0]; @@ -149,8 +147,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_ctx *app = ctx; @@ -160,8 +157,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftLInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_ctx *app = ctx; @@ -171,8 +167,7 @@ evalVDriftLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Vx_drift; } -void -evalVDriftRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftRInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_ctx *app = ctx; @@ -182,8 +177,7 @@ evalVDriftRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = -Vx_drift; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_ctx *app = ctx; double x = xn[0]; @@ -198,17 +192,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -226,32 +223,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -276,18 +275,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -295,39 +293,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -350,76 +334,73 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, - .num_init = 2, + .num_init = 2, // Two counter-streaming Maxwellians. - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftLInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .projection[1] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftRInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftLInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .projection[1] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftRInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -431,10 +412,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -443,32 +428,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -484,7 +476,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -500,8 +492,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -509,7 +500,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -518,14 +511,13 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } step += 1; } - + calc_field_energy(&fe_trig, app, t_curr, false); calc_integrated_mom(&im_trig, app, t_curr, false); calc_integrated_L2_f(&l2f_trig, app, t_curr, false); @@ -539,14 +531,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_twostream_p2.c b/vlasov/creg/rt_vlasov_twostream_p2.c index 440af7c4bc..95d6d611b3 100644 --- a/vlasov/creg/rt_vlasov_twostream_p2.c +++ b/vlasov/creg/rt_vlasov_twostream_p2.c @@ -19,8 +19,7 @@ #include -struct twostream_ctx -{ +struct twostream_ctx { // Mathematical constants (dimensionless). double pi; @@ -60,8 +59,7 @@ struct twostream_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct twostream_ctx -create_ctx(void) +struct twostream_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -97,7 +95,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -107,7 +106,7 @@ create_ctx(void) .mu0 = mu0, .mass_elc = mass_elc, .charge_elc = charge_elc, - .n0 = n0, + .n0 = n0, .vt = vt, .Vx_drift = Vx_drift, .lambda_D = lambda_D, @@ -127,14 +126,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalDensityInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_ctx *app = ctx; double x = xn[0]; @@ -149,8 +147,7 @@ evalDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = n; } -void -evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_ctx *app = ctx; @@ -160,8 +157,7 @@ evalTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fou fout[0] = T; } -void -evalVDriftLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftLInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_ctx *app = ctx; @@ -171,8 +167,7 @@ evalVDriftLInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Vx_drift; } -void -evalVDriftRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalVDriftRInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_ctx *app = ctx; @@ -182,8 +177,7 @@ evalVDriftRInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = -Vx_drift; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct twostream_ctx *app = ctx; double x = xn[0]; @@ -198,17 +192,20 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = 0.0; // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey, fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey, fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -226,32 +223,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -276,18 +275,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -295,39 +293,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -350,76 +334,73 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, - .num_init = 2, + .num_init = 2, // Two counter-streaming Maxwellians. - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftLInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, - .projection[1] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalDensityInit, - .ctx_density = &ctx, - .temp = evalTempInit, - .ctx_temp = &ctx, - .V_drift = evalVDriftRInit, - .ctx_V_drift = &ctx, - .correct_all_moms = true, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftLInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, + .projection[1] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalDensityInit, + .ctx_density = &ctx, + .temp = evalTempInit, + .ctx_temp = &ctx, + .V_drift = evalVDriftRInit, + .ctx_V_drift = &ctx, + .correct_all_moms = true}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; - + // Create app object. // Set app output name from the executable name (argv[0]). snprintf(app_inp.name, sizeof(app_inp.name), "%s", app_args.app_name); @@ -431,10 +412,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -443,32 +428,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -484,7 +476,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -500,8 +492,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -509,7 +500,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -518,8 +511,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -539,14 +531,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_weibel_1x2v_p2.c b/vlasov/creg/rt_vlasov_weibel_1x2v_p2.c index 72f3b9295f..45e6cf0325 100644 --- a/vlasov/creg/rt_vlasov_weibel_1x2v_p2.c +++ b/vlasov/creg/rt_vlasov_weibel_1x2v_p2.c @@ -19,8 +19,7 @@ #include -struct weibel_ctx -{ +struct weibel_ctx { // Mathematical constants (dimensionless). double pi; @@ -65,8 +64,7 @@ struct weibel_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct weibel_ctx -create_ctx(void) +struct weibel_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -107,7 +105,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -143,14 +142,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_ctx *app = ctx; double x = xn[0], vx = xn[1], vy = xn[2]; @@ -169,16 +167,17 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double v_sq_elc1 = ((vx - ux_elc1) * (vx - ux_elc1)) + ((vy - uy_elc1) * (vy - uy_elc1)); double v_sq_elc2 = ((vx - ux_elc2) * (vx - ux_elc2)) + ((vy - uy_elc2) * (vy - uy_elc2)); - double maxwellian1 = (n_elc1 / (2.0 * pi * vt_elc1 * vt_elc1)) * exp(-v_sq_elc1 / (2.0 * vt_elc1 * vt_elc1)); - double maxwellian2 = (n_elc2 / (2.0 * pi * vt_elc2 * vt_elc2)) * exp(-v_sq_elc2 / (2.0 * vt_elc2 * vt_elc2)); + double maxwellian1 = + (n_elc1 / (2.0 * pi * vt_elc1 * vt_elc1)) * exp(-v_sq_elc1 / (2.0 * vt_elc1 * vt_elc1)); + double maxwellian2 = + (n_elc2 / (2.0 * pi * vt_elc2 * vt_elc2)) * exp(-v_sq_elc2 / (2.0 * vt_elc2 * vt_elc2)); double n = maxwellian1 + maxwellian2; // Distribution function. - + // Set distribution function. fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_ctx *app = ctx; double x = xn[0]; @@ -193,17 +192,21 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = alpha * sin(kx * x); // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -221,32 +224,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -272,18 +277,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -291,39 +295,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -346,55 +336,50 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -408,10 +393,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -420,32 +409,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -461,7 +457,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -477,8 +473,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -486,7 +481,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -495,8 +492,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -516,14 +512,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_weibel_2x2v_p1.c b/vlasov/creg/rt_vlasov_weibel_2x2v_p1.c index dc057d0227..4943cf89e0 100644 --- a/vlasov/creg/rt_vlasov_weibel_2x2v_p1.c +++ b/vlasov/creg/rt_vlasov_weibel_2x2v_p1.c @@ -19,8 +19,7 @@ #include -struct weibel_ctx -{ +struct weibel_ctx { // Mathematical constants (dimensionless). double pi; @@ -74,8 +73,7 @@ struct weibel_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct weibel_ctx -create_ctx(void) +struct weibel_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -102,7 +100,8 @@ create_ctx(void) // Derived physical quantities (using normalized code units). double T_elc1 = mass_elc * ((R_elc * uy_elc1) * (R_elc * uy_elc1)); // First electron temperature. - double T_elc2 = mass_elc * ((R_elc * uy_elc1) * (R_elc * uy_elc1)); // Second electron temperature. + double T_elc2 = + mass_elc * ((R_elc * uy_elc1) * (R_elc * uy_elc1)); // Second electron temperature. double vt_elc1 = sqrt(T_elc1 / mass_elc); // First electron thermal velocity. double vt_elc2 = sqrt(T_elc2 / mass_elc); // Second electron thermal velocity. @@ -125,7 +124,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -168,14 +168,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_ctx *app = ctx; double x = xn[0], y = xn[1], vx = xn[2], vy = xn[3]; @@ -198,16 +197,18 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double v_sq_elc1 = ((vx - ux_elc1) * (vx - ux_elc1)) + ((vy - uy_elc1) * (vy - uy_elc1)); double v_sq_elc2 = ((vx - ux_elc2) * (vx - ux_elc2)) + ((vy - uy_elc2) * (vy - uy_elc2)); - double maxwellian1 = (n_elc1 / (2.0 * pi * vt_elc1 * vt_elc1)) * exp(-v_sq_elc1 / (2.0 * vt_elc1 * vt_elc1)); - double maxwellian2 = (n_elc2 / (2.0 * pi * vt_elc2 * vt_elc2)) * exp(-v_sq_elc2 / (2.0 * vt_elc2 * vt_elc2)); - double n = (1.0 + (perturb_n * cos((kx * x) + (ky * y)))) * (maxwellian1 + maxwellian2); // Distribution function. - + double maxwellian1 = + (n_elc1 / (2.0 * pi * vt_elc1 * vt_elc1)) * exp(-v_sq_elc1 / (2.0 * vt_elc1 * vt_elc1)); + double maxwellian2 = + (n_elc2 / (2.0 * pi * vt_elc2 * vt_elc2)) * exp(-v_sq_elc2 / (2.0 * vt_elc2 * vt_elc2)); + double n = (1.0 + (perturb_n * cos((kx * x) + (ky * y)))) * + (maxwellian1 + maxwellian2); // Distribution function. + // Set distribution function. fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -218,24 +219,29 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double kx = app->kx; double ky = app->ky; - double Ex = -perturb_n * sin((kx * x) + (ky * y)) / (kx + (ky * alpha)); // Total electric field (x-direction). + double Ex = -perturb_n * sin((kx * x) + (ky * y)) / + (kx + (ky * alpha)); // Total electric field (x-direction). double Ey = alpha * Ex; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = (kx * Ey) - (ky * Ex); // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -253,32 +259,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -305,18 +313,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -324,39 +331,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -374,63 +367,59 @@ main(int argc, char **argv) fprintf(stderr, "*** Number of ranks, %d, does not match total cuts, %d!\n", comm_size, ncuts); } goto mpifinalize; - } - + } + // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, .num_diag_moments = 2, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 2, .vdim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + + .cdim = 2, + .vdim = 2, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -444,10 +433,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -456,32 +449,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -497,7 +497,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -513,8 +513,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -522,7 +521,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -531,8 +532,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -552,14 +552,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_weibel_2x2v_p2.c b/vlasov/creg/rt_vlasov_weibel_2x2v_p2.c index db44493ec9..24fed4ccb2 100644 --- a/vlasov/creg/rt_vlasov_weibel_2x2v_p2.c +++ b/vlasov/creg/rt_vlasov_weibel_2x2v_p2.c @@ -19,8 +19,7 @@ #include -struct weibel_ctx -{ +struct weibel_ctx { // Mathematical constants (dimensionless). double pi; @@ -74,8 +73,7 @@ struct weibel_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct weibel_ctx -create_ctx(void) +struct weibel_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -102,7 +100,8 @@ create_ctx(void) // Derived physical quantities (using normalized code units). double T_elc1 = mass_elc * ((R_elc * uy_elc1) * (R_elc * uy_elc1)); // First electron temperature. - double T_elc2 = mass_elc * ((R_elc * uy_elc1) * (R_elc * uy_elc1)); // Second electron temperature. + double T_elc2 = + mass_elc * ((R_elc * uy_elc1) * (R_elc * uy_elc1)); // Second electron temperature. double vt_elc1 = sqrt(T_elc1 / mass_elc); // First electron thermal velocity. double vt_elc2 = sqrt(T_elc2 / mass_elc); // Second electron thermal velocity. @@ -125,7 +124,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -168,14 +168,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_ctx *app = ctx; double x = xn[0], y = xn[1], vx = xn[2], vy = xn[3]; @@ -198,16 +197,18 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double v_sq_elc1 = ((vx - ux_elc1) * (vx - ux_elc1)) + ((vy - uy_elc1) * (vy - uy_elc1)); double v_sq_elc2 = ((vx - ux_elc2) * (vx - ux_elc2)) + ((vy - uy_elc2) * (vy - uy_elc2)); - double maxwellian1 = (n_elc1 / (2.0 * pi * vt_elc1 * vt_elc1)) * exp(-v_sq_elc1 / (2.0 * vt_elc1 * vt_elc1)); - double maxwellian2 = (n_elc2 / (2.0 * pi * vt_elc2 * vt_elc2)) * exp(-v_sq_elc2 / (2.0 * vt_elc2 * vt_elc2)); - double n = (1.0 + (perturb_n * cos((kx * x) + (ky * y)))) * (maxwellian1 + maxwellian2); // Distribution function. - + double maxwellian1 = + (n_elc1 / (2.0 * pi * vt_elc1 * vt_elc1)) * exp(-v_sq_elc1 / (2.0 * vt_elc1 * vt_elc1)); + double maxwellian2 = + (n_elc2 / (2.0 * pi * vt_elc2 * vt_elc2)) * exp(-v_sq_elc2 / (2.0 * vt_elc2 * vt_elc2)); + double n = (1.0 + (perturb_n * cos((kx * x) + (ky * y)))) * + (maxwellian1 + maxwellian2); // Distribution function. + // Set distribution function. fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -218,24 +219,29 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double kx = app->kx; double ky = app->ky; - double Ex = -perturb_n * sin((kx * x) + (ky * y)) / (kx + (ky * alpha)); // Total electric field (x-direction). + double Ex = -perturb_n * sin((kx * x) + (ky * y)) / + (kx + (ky * alpha)); // Total electric field (x-direction). double Ey = alpha * Ex; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = (kx * Ey) - (ky * Ex); // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -253,32 +259,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -305,18 +313,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -324,39 +331,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -374,63 +367,59 @@ main(int argc, char **argv) fprintf(stderr, "*** Number of ranks, %d, does not match total cuts, %d!\n", comm_size, ncuts); } goto mpifinalize; - } - + } + // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, .num_diag_moments = 2, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 2, .vdim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + + .cdim = 2, + .vdim = 2, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -444,10 +433,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -456,32 +449,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -497,7 +497,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -513,8 +513,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -522,7 +521,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -531,8 +532,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -552,14 +552,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vlasov_weibel_lbo_2x2v_p2.c b/vlasov/creg/rt_vlasov_weibel_lbo_2x2v_p2.c index af981f39ac..f3663657ab 100644 --- a/vlasov/creg/rt_vlasov_weibel_lbo_2x2v_p2.c +++ b/vlasov/creg/rt_vlasov_weibel_lbo_2x2v_p2.c @@ -19,8 +19,7 @@ #include -struct weibel_lbo_ctx -{ +struct weibel_lbo_ctx { // Mathematical constants (dimensionless). double pi; @@ -76,8 +75,7 @@ struct weibel_lbo_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct weibel_lbo_ctx -create_ctx(void) +struct weibel_lbo_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -106,7 +104,8 @@ create_ctx(void) // Derived physical quantities (using normalized code units). double T_elc1 = mass_elc * ((R_elc * uy_elc1) * (R_elc * uy_elc1)); // First electron temperature. - double T_elc2 = mass_elc * ((R_elc * uy_elc1) * (R_elc * uy_elc1)); // Second electron temperature. + double T_elc2 = + mass_elc * ((R_elc * uy_elc1) * (R_elc * uy_elc1)); // Second electron temperature. double vt_elc1 = sqrt(T_elc1 / mass_elc); // First electron thermal velocity. double vt_elc2 = sqrt(T_elc2 / mass_elc); // Second electron thermal velocity. @@ -129,7 +128,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -173,14 +173,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_lbo_ctx *app = ctx; double x = xn[0], y = xn[1], vx = xn[2], vy = xn[3]; @@ -203,16 +202,18 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double v_sq_elc1 = ((vx - ux_elc1) * (vx - ux_elc1)) + ((vy - uy_elc1) * (vy - uy_elc1)); double v_sq_elc2 = ((vx - ux_elc2) * (vx - ux_elc2)) + ((vy - uy_elc2) * (vy - uy_elc2)); - double maxwellian1 = (n_elc1 / (2.0 * pi * vt_elc1 * vt_elc1)) * exp(-v_sq_elc1 / (2.0 * vt_elc1 * vt_elc1)); - double maxwellian2 = (n_elc2 / (2.0 * pi * vt_elc2 * vt_elc2)) * exp(-v_sq_elc2 / (2.0 * vt_elc2 * vt_elc2)); - double n = (1.0 + (perturb_n * cos((kx * x) + (ky * y)))) * (maxwellian1 + maxwellian2); // Distribution function. - + double maxwellian1 = + (n_elc1 / (2.0 * pi * vt_elc1 * vt_elc1)) * exp(-v_sq_elc1 / (2.0 * vt_elc1 * vt_elc1)); + double maxwellian2 = + (n_elc2 / (2.0 * pi * vt_elc2 * vt_elc2)) * exp(-v_sq_elc2 / (2.0 * vt_elc2 * vt_elc2)); + double n = (1.0 + (perturb_n * cos((kx * x) + (ky * y)))) * + (maxwellian1 + maxwellian2); // Distribution function. + // Set distribution function. fout[0] = n; } -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalFieldInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_lbo_ctx *app = ctx; double x = xn[0], y = xn[1]; @@ -223,24 +224,29 @@ evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fo double kx = app->kx; double ky = app->ky; - double Ex = -perturb_n * sin((kx * x) + (ky * y)) / (kx + (ky * alpha)); // Total electric field (x-direction). + double Ex = -perturb_n * sin((kx * x) + (ky * y)) / + (kx + (ky * alpha)); // Total electric field (x-direction). double Ey = alpha * Ex; // Total electric field (y-direction). double Ez = 0.0; // Total electric field (z-direction). double Bx = 0.0; // Total magnetic field (x-direction). double By = 0.0; // Total magnetic field (y-direction). double Bz = (kx * Ey) - (ky * Ex); // Total magnetic field (z-direction). - + // Set electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; + fout[6] = 0.0; + fout[7] = 0.0; } -void -evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct weibel_lbo_ctx *app = ctx; @@ -250,8 +256,7 @@ evalNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, voi fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -269,32 +274,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -321,18 +328,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX, NY }; + int ccells[] = {NX, NY}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -340,39 +346,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -390,68 +382,60 @@ main(int argc, char **argv) fprintf(stderr, "*** Number of ranks, %d, does not match total cuts, %d!\n", comm_size, ncuts); } goto mpifinalize; - } - + } + // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max, -ctx.vy_max }, - .upper = { ctx.vx_max, ctx.vy_max }, - .cells = { NVX, NVY }, - - .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, - .collisions = { - .collision_id = GKYL_LBO_COLLISIONS, - .self_nu = evalNu, - .ctx = &ctx, - }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max, -ctx.vy_max}, + .upper = {ctx.vx_max, ctx.vy_max}, + .cells = {NVX, NVY}, + + .num_init = 1, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, + .collisions = {.collision_id = GKYL_LBO_COLLISIONS, .self_nu = evalNu, .ctx = &ctx}, .num_diag_moments = 2, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1} }; // Field. struct gkyl_vlasov_field field = { - .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + .epsilon0 = ctx.epsilon0, + .mu0 = ctx.mu0, .elcErrorSpeedFactor = 0.0, .mgnErrorSpeedFactor = 0.0, .init = evalFieldInit, - .ctx = &ctx, + .ctx = &ctx }; // Vlasov-Maxwell app. struct gkyl_vm app_inp = { - - .cdim = 2, .vdim = 2, - .lower = { 0.0, 0.0 }, - .upper = { ctx.Lx, ctx.Ly }, - .cells = { NX, NY }, + + .cdim = 2, + .vdim = 2, + .lower = {0.0, 0.0}, + .upper = {ctx.Lx, ctx.Ly}, + .cells = {NX, NY}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 2, - .periodic_dirs = { 0, 1 }, + .periodic_dirs = {0, 1}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, - - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0], app_args.cuts[1] }, - .comm = comm, - }, + + .parallelism = + {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0], app_args.cuts[1]}, .comm = comm} }; // Create app object. @@ -465,10 +449,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -477,32 +465,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -518,7 +513,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -534,8 +529,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -543,7 +537,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -552,8 +548,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -573,14 +568,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vp_landau_damping_1x1v_p1.c b/vlasov/creg/rt_vp_landau_damping_1x1v_p1.c index 3f41217d19..ea80a88fa6 100644 --- a/vlasov/creg/rt_vp_landau_damping_1x1v_p1.c +++ b/vlasov/creg/rt_vp_landau_damping_1x1v_p1.c @@ -19,8 +19,7 @@ #include -struct landau_damping_ctx -{ +struct landau_damping_ctx { // Mathematical constants (dimensionless). double pi; @@ -58,8 +57,7 @@ struct landau_damping_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct landau_damping_ctx -create_ctx(void) +struct landau_damping_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -76,7 +74,8 @@ create_ctx(void) // Derived physical quantities (using normalized code units). double vte = sqrt(Te / mass_elc); // Electron thermal velocity. - double omega_pe = sqrt((charge_elc * charge_elc) * n0 / (epsilon0 * mass_elc)); // Electron plasma frequency. + double omega_pe = + sqrt((charge_elc * charge_elc) * n0 / (epsilon0 * mass_elc)); // Electron plasma frequency. double lambda_D = vte / omega_pe; // Electron Debye length. double k0 = 0.5 / lambda_D; // Perturbed wave number. @@ -93,7 +92,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -121,14 +121,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -139,15 +138,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double alpha = app->alpha; double k0 = app->k0; - double n = (1.0 + alpha * cos(k0 * x)) * - (1.0 / sqrt(2.0 * pi * vte * vte)) * (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron Distribution function. + double n = (1.0 + alpha * cos(k0 * x)) * (1.0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron Distribution function. // Set distribution function. fout[0] = n; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -165,32 +163,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -215,18 +215,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -234,39 +233,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -289,58 +274,49 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { .epsilon0 = ctx.epsilon0, - .poisson_bcs = { - .lo_type = { GKYL_POISSON_PERIODIC }, - .up_type = { GKYL_POISSON_PERIODIC }, - }, + .poisson_bcs = {.lo_type = {GKYL_POISSON_PERIODIC}, .up_type = {GKYL_POISSON_PERIODIC}} }; // Vlasov-Poisson app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, .is_electrostatic = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - } + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -354,10 +330,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -366,32 +346,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -407,7 +394,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -423,8 +410,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -432,7 +418,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -441,8 +429,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -462,14 +449,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vp_landau_damping_1x1v_p2.c b/vlasov/creg/rt_vp_landau_damping_1x1v_p2.c index 31cbb16335..8055a89e3f 100644 --- a/vlasov/creg/rt_vp_landau_damping_1x1v_p2.c +++ b/vlasov/creg/rt_vp_landau_damping_1x1v_p2.c @@ -19,8 +19,7 @@ #include -struct landau_damping_ctx -{ +struct landau_damping_ctx { // Mathematical constants (dimensionless). double pi; @@ -58,8 +57,7 @@ struct landau_damping_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct landau_damping_ctx -create_ctx(void) +struct landau_damping_ctx create_ctx(void) { // Mathematical constants (dimensionless). double pi = M_PI; @@ -76,7 +74,8 @@ create_ctx(void) // Derived physical quantities (using normalized code units). double vte = sqrt(Te / mass_elc); // Electron thermal velocity. - double omega_pe = sqrt((charge_elc * charge_elc) * n0 / (epsilon0 * mass_elc)); // Electron plasma frequency. + double omega_pe = + sqrt((charge_elc * charge_elc) * n0 / (epsilon0 * mass_elc)); // Electron plasma frequency. double lambda_D = vte / omega_pe; // Electron Debye length. double k0 = 0.5 / lambda_D; // Perturbed wave number. @@ -93,7 +92,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -121,14 +121,13 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct landau_damping_ctx *app = ctx; double x = xn[0], vx = xn[1]; @@ -139,15 +138,14 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double alpha = app->alpha; double k0 = app->k0; - double n = (1.0 + alpha * cos(k0 * x)) * - (1.0 / sqrt(2.0 * pi * vte * vte)) * (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron Distribution function. + double n = (1.0 + alpha * cos(k0 * x)) * (1.0 / sqrt(2.0 * pi * vte * vte)) * + (exp(-(vx * vx) / (2.0 * vte * vte))); // Electron Distribution function. // Set distribution function. fout[0] = n; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -165,32 +163,34 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); @@ -215,18 +215,17 @@ main(int argc, char **argv) if (app_args.use_mpi) { MPI_Comm_size(MPI_COMM_WORLD, &nrank); } -#endif +#endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -234,39 +233,25 @@ main(int argc, char **argv) for (int d = 0; d < cdim; d++) { cuts[d] = 1; } -#endif - +#endif + // Construct communicator for use in app. struct gkyl_comm *comm; #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -289,58 +274,49 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max }, - .upper = { ctx.vx_max }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max}, + .upper = {ctx.vx_max}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_FUNC, - .func = evalElcInit, - .ctx_func = &ctx, - }, + .projection[0] = {.proj_id = GKYL_PROJ_FUNC, .func = evalElcInit, .ctx_func = &ctx}, .num_diag_moments = 3, - .diag_moments = { GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2 }, + .diag_moments = {GKYL_F_MOMENT_M0, GKYL_F_MOMENT_M1, GKYL_F_MOMENT_M2} }; // Field. struct gkyl_vlasov_field field = { .epsilon0 = ctx.epsilon0, - .poisson_bcs = { - .lo_type = { GKYL_POISSON_PERIODIC }, - .up_type = { GKYL_POISSON_PERIODIC }, - }, + .poisson_bcs = {.lo_type = {GKYL_POISSON_PERIODIC}, .up_type = {GKYL_POISSON_PERIODIC}} }; // Vlasov-Poisson app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 1, - .periodic_dirs = { 0 }, + .periodic_dirs = {0}, .num_species = 1, - .species = { elc }, + .species = {elc}, .field = field, .is_electrostatic = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - } + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -354,10 +330,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -366,32 +346,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -407,7 +394,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -423,8 +410,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -432,7 +418,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -441,8 +429,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -462,14 +449,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vp_sheath_1x1v_p2.c b/vlasov/creg/rt_vp_sheath_1x1v_p2.c index 7e3a9dc444..1a97516360 100644 --- a/vlasov/creg/rt_vp_sheath_1x1v_p2.c +++ b/vlasov/creg/rt_vp_sheath_1x1v_p2.c @@ -20,8 +20,7 @@ #include -struct sheath_ctx -{ +struct sheath_ctx { // Physical constants (using non-normalized physical units). double epsilon0; // Permittivity of free space. double mass_elc; // Electron mass. @@ -61,8 +60,7 @@ struct sheath_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { // Physical constants (using non-normalized physical units). double epsilon0 = GKYL_EPSILON0; // Permittivity of free space. @@ -83,7 +81,8 @@ create_ctx(void) double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. double lambda_D = sqrt(epsilon0 * Te / (n0 * charge_ion * charge_ion)); // Electron Debye length. - double omega_pe = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. + double omega_pe = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. // Simulation parameters. int Nx = 64; // Cell count (configuration space: x-direction). @@ -98,7 +97,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -130,14 +130,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -147,8 +148,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -158,8 +158,9 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -169,8 +170,9 @@ evalElcVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = Vx_drift_elc; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -180,8 +182,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -191,8 +192,9 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -202,8 +204,7 @@ evalIonVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = Vx_drift_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -221,36 +222,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); - #ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Init(&argc, &argv); } @@ -273,16 +276,15 @@ main(int argc, char **argv) } #endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -297,32 +299,18 @@ main(int argc, char **argv) #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -345,98 +333,88 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalElcDensityInit, - .ctx_density = &ctx, - .temp = evalElcTempInit, - .ctx_temp = &ctx, - .V_drift = evalElcVDriftInit, - .ctx_V_drift = &ctx, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalElcDensityInit, + .ctx_density = &ctx, + .temp = evalElcTempInit, + .ctx_temp = &ctx, + .V_drift = evalElcVDriftInit, + .ctx_V_drift = &ctx}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_REFLECT}}, .num_diag_moments = 1, - .diag_moments = { GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_LTE} }; // Ions. struct gkyl_vlasov_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalIonDensityInit, - .ctx_density = &ctx, - .temp = evalIonTempInit, - .ctx_temp = &ctx, - .V_drift = evalIonVDriftInit, - .ctx_V_drift = &ctx, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalIonDensityInit, + .ctx_density = &ctx, + .temp = evalIonTempInit, + .ctx_temp = &ctx, + .V_drift = evalIonVDriftInit, + .ctx_V_drift = &ctx}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_REFLECT}}, .num_diag_moments = 1, - .diag_moments = { GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_LTE} }; // Field. struct gkyl_vlasov_field field = { .epsilon0 = ctx.epsilon0, - .poisson_bcs = { - .lo_type = { GKYL_POISSON_DIRICHLET }, - .up_type = { GKYL_POISSON_NEUMANN }, + .poisson_bcs = + {.lo_type = {GKYL_POISSON_DIRICHLET}, + .up_type = {GKYL_POISSON_NEUMANN}, - .lo_value = { 0.0 }, - .up_value = { 0.0 }, - }, + .lo_value = {0.0}, + .up_value = {0.0}} }; // Vlasov-Poisson app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, .is_electrostatic = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -450,10 +428,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -462,32 +444,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -503,7 +492,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -519,8 +508,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -528,7 +516,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -537,8 +527,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -558,14 +547,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vp_sheath_Aext_1x2v_p2.c b/vlasov/creg/rt_vp_sheath_Aext_1x2v_p2.c index e98a72bbe7..12ad61bb31 100644 --- a/vlasov/creg/rt_vp_sheath_Aext_1x2v_p2.c +++ b/vlasov/creg/rt_vp_sheath_Aext_1x2v_p2.c @@ -20,8 +20,7 @@ #include -struct sheath_ctx -{ +struct sheath_ctx { // Physical constants (using non-normalized physical units). double epsilon0; // Permittivity of free space. double mass_elc; // Electron mass. @@ -69,8 +68,7 @@ struct sheath_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { // Physical constants (using non-normalized physical units). double epsilon0 = GKYL_EPSILON0; // Permittivity of free space. @@ -95,7 +93,8 @@ create_ctx(void) double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. double lambda_D = sqrt(epsilon0 * Te / (n0 * charge_ion * charge_ion)); // Electron Debye length. - double omega_pe = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. + double omega_pe = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. // Simulation parameters. int Nx = 64; // Cell count (configuration space: x-direction). @@ -113,7 +112,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -151,14 +151,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -168,8 +169,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -179,8 +179,9 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -188,11 +189,13 @@ evalElcVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double Vy_drift_elc = app->Vy_drift_elc; // Set electron drift velocity. - fout[0] = Vx_drift_elc; fout[1] = Vy_drift_elc; + fout[0] = Vx_drift_elc; + fout[1] = Vy_drift_elc; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -202,8 +205,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -213,8 +215,9 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -222,11 +225,13 @@ evalIonVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double Vy_drift_ion = app->Vy_drift_ion; // Set ion drift velocity. - fout[0] = Vx_drift_ion; fout[1] = Vy_drift_ion; + fout[0] = Vx_drift_ion; + fout[1] = Vy_drift_ion; } -void -evalExternalPotentialInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalPotentialInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -241,11 +246,12 @@ evalExternalPotentialInit(double t, const double* GKYL_RESTRICT xn, double* GKYL // Set external electric scalar potential. fout[0] = phi; // Set external magnetic vector potential. - fout[1] = Ax; fout[2] = Ay; fout[3] = Az; + fout[1] = Ax; + fout[2] = Ay; + fout[3] = Az; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -263,36 +269,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); - #ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Init(&argc, &argv); } @@ -316,16 +324,15 @@ main(int argc, char **argv) } #endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -340,32 +347,18 @@ main(int argc, char **argv) #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -388,102 +381,92 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc, -ctx.vy_max_elc }, - .upper = { ctx.vx_max_elc, ctx.vy_max_elc }, - .cells = { NVX, NVY }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc, -ctx.vy_max_elc}, + .upper = {ctx.vx_max_elc, ctx.vy_max_elc}, + .cells = {NVX, NVY}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalElcDensityInit, - .ctx_density = &ctx, - .temp = evalElcTempInit, - .ctx_temp = &ctx, - .V_drift = evalElcVDriftInit, - .ctx_V_drift = &ctx, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalElcDensityInit, + .ctx_density = &ctx, + .temp = evalElcTempInit, + .ctx_temp = &ctx, + .V_drift = evalElcVDriftInit, + .ctx_V_drift = &ctx}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_REFLECT}}, .num_diag_moments = 1, - .diag_moments = { GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_LTE} }; // Ions. struct gkyl_vlasov_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion, -ctx.vy_max_ion }, - .upper = { ctx.vx_max_ion, ctx.vy_max_ion }, - .cells = { NVX, NVY }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion, -ctx.vy_max_ion}, + .upper = {ctx.vx_max_ion, ctx.vy_max_ion}, + .cells = {NVX, NVY}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalIonDensityInit, - .ctx_density = &ctx, - .temp = evalIonTempInit, - .ctx_temp = &ctx, - .V_drift = evalIonVDriftInit, - .ctx_V_drift = &ctx, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalIonDensityInit, + .ctx_density = &ctx, + .temp = evalIonTempInit, + .ctx_temp = &ctx, + .V_drift = evalIonVDriftInit, + .ctx_V_drift = &ctx}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_REFLECT}}, .num_diag_moments = 1, - .diag_moments = { GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_LTE} }; // Field. struct gkyl_vlasov_field field = { .epsilon0 = ctx.epsilon0, - .poisson_bcs = { - .lo_type = { GKYL_POISSON_DIRICHLET }, - .up_type = { GKYL_POISSON_NEUMANN }, + .poisson_bcs = + {.lo_type = {GKYL_POISSON_DIRICHLET}, + .up_type = {GKYL_POISSON_NEUMANN}, - .lo_value = { 0.0 }, - .up_value = { 0.0 }, - }, + .lo_value = {0.0}, + .up_value = {0.0}}, .external_potentials = evalExternalPotentialInit, .external_potentials_ctx = &ctx, - .external_potentials_evolve = false, + .external_potentials_evolve = false }; // Vlasov-Poisson app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, .is_electrostatic = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -497,10 +480,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -509,32 +496,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -550,7 +544,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -566,8 +560,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -575,7 +568,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -584,8 +579,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -605,14 +599,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vp_sheath_Bext_1x2v_p2.c b/vlasov/creg/rt_vp_sheath_Bext_1x2v_p2.c index 1206805d3a..8760d46c66 100644 --- a/vlasov/creg/rt_vp_sheath_Bext_1x2v_p2.c +++ b/vlasov/creg/rt_vp_sheath_Bext_1x2v_p2.c @@ -20,8 +20,7 @@ #include -struct sheath_ctx -{ +struct sheath_ctx { // Physical constants (using non-normalized physical units). double epsilon0; // Permittivity of free space. double mass_elc; // Electron mass. @@ -69,8 +68,7 @@ struct sheath_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { // Physical constants (using non-normalized physical units). double epsilon0 = GKYL_EPSILON0; // Permittivity of free space. @@ -95,7 +93,8 @@ create_ctx(void) double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. double lambda_D = sqrt(epsilon0 * Te / (n0 * charge_ion * charge_ion)); // Electron Debye length. - double omega_pe = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. + double omega_pe = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. // Simulation parameters. int Nx = 64; // Cell count (configuration space: x-direction). @@ -113,7 +112,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -151,14 +151,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -168,8 +169,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -179,8 +179,9 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -188,11 +189,13 @@ evalElcVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double Vy_drift_elc = app->Vy_drift_elc; // Set electron drift velocity. - fout[0] = Vx_drift_elc; fout[1] = Vy_drift_elc; + fout[0] = Vx_drift_elc; + fout[1] = Vy_drift_elc; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -202,8 +205,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -213,8 +215,9 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -222,11 +225,13 @@ evalIonVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC double Vy_drift_ion = app->Vy_drift_ion; // Set ion drift velocity. - fout[0] = Vx_drift_ion; fout[1] = Vy_drift_ion; + fout[0] = Vx_drift_ion; + fout[1] = Vy_drift_ion; } -void -evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalExternalFieldInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -241,13 +246,16 @@ evalExternalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES double Bz = B0; // External magnetic field (z-direction). // Set external electric field. - fout[0] = Ex; fout[1] = Ey; fout[2] = Ez; + fout[0] = Ex; + fout[1] = Ey; + fout[2] = Ez; // Set external magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; + fout[3] = Bx; + fout[4] = By; + fout[5] = Bz; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -265,36 +273,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); - #ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Init(&argc, &argv); } @@ -318,16 +328,15 @@ main(int argc, char **argv) } #endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -342,32 +351,18 @@ main(int argc, char **argv) #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -390,102 +385,92 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc, -ctx.vy_max_elc }, - .upper = { ctx.vx_max_elc, ctx.vy_max_elc }, - .cells = { NVX, NVY }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc, -ctx.vy_max_elc}, + .upper = {ctx.vx_max_elc, ctx.vy_max_elc}, + .cells = {NVX, NVY}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalElcDensityInit, - .ctx_density = &ctx, - .temp = evalElcTempInit, - .ctx_temp = &ctx, - .V_drift = evalElcVDriftInit, - .ctx_V_drift = &ctx, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalElcDensityInit, + .ctx_density = &ctx, + .temp = evalElcTempInit, + .ctx_temp = &ctx, + .V_drift = evalElcVDriftInit, + .ctx_V_drift = &ctx}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_REFLECT}}, .num_diag_moments = 1, - .diag_moments = { GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_LTE} }; // Ions. struct gkyl_vlasov_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion, -ctx.vy_max_ion }, - .upper = { ctx.vx_max_ion, ctx.vy_max_ion }, - .cells = { NVX, NVY }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion, -ctx.vy_max_ion}, + .upper = {ctx.vx_max_ion, ctx.vy_max_ion}, + .cells = {NVX, NVY}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalIonDensityInit, - .ctx_density = &ctx, - .temp = evalIonTempInit, - .ctx_temp = &ctx, - .V_drift = evalIonVDriftInit, - .ctx_V_drift = &ctx, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_REFLECT, }, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalIonDensityInit, + .ctx_density = &ctx, + .temp = evalIonTempInit, + .ctx_temp = &ctx, + .V_drift = evalIonVDriftInit, + .ctx_V_drift = &ctx}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_REFLECT}}, .num_diag_moments = 1, - .diag_moments = { GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_LTE} }; // Field. struct gkyl_vlasov_field field = { .epsilon0 = ctx.epsilon0, - .poisson_bcs = { - .lo_type = { GKYL_POISSON_DIRICHLET }, - .up_type = { GKYL_POISSON_NEUMANN }, + .poisson_bcs = + {.lo_type = {GKYL_POISSON_DIRICHLET}, + .up_type = {GKYL_POISSON_NEUMANN}, - .lo_value = { 0.0 }, - .up_value = { 0.0 }, - }, + .lo_value = {0.0}, + .up_value = {0.0}}, .ext_em = evalExternalFieldInit, .ext_em_ctx = &ctx, - .ext_em_evolve = false, + .ext_em_evolve = false }; // Vlasov-Poisson app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 2, - .lower = { 0.0 }, - .upper = { ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 2, + .lower = {0.0}, + .upper = {ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, .is_electrostatic = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -499,10 +484,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -511,32 +500,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -552,7 +548,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -568,8 +564,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -577,7 +572,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -586,8 +583,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -607,14 +603,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vp_sheath_feedback_sources_1x1v_p2.c b/vlasov/creg/rt_vp_sheath_feedback_sources_1x1v_p2.c index 115caae554..070876248e 100644 --- a/vlasov/creg/rt_vp_sheath_feedback_sources_1x1v_p2.c +++ b/vlasov/creg/rt_vp_sheath_feedback_sources_1x1v_p2.c @@ -19,8 +19,7 @@ #include -struct sheath_ctx -{ +struct sheath_ctx { // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mass_elc; // Electron mass. @@ -61,8 +60,7 @@ struct sheath_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { // Physical constants (using normalized code units). double epsilon0 = 1.0; // Permittivity of free space. @@ -83,7 +81,8 @@ create_ctx(void) double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. double lambda_D = sqrt(epsilon0 * Te / (n0 * charge_ion * charge_ion)); // Electron Debye length. - double omega_pe = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. + double omega_pe = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. // Simulation parameters. int Nx = 256; // Cell count (configuration space: x-direction). @@ -99,7 +98,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -132,14 +132,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -149,8 +150,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -160,8 +160,9 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -171,8 +172,9 @@ evalElcVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = Vx_drift_elc; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -183,8 +185,7 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(x) < Ls) { n = (Ls - fabs(x)) / Ls; // Electron source total number density (left). - } - else { + } else { n = 0.0; // Electron source total number density (right). } @@ -192,8 +193,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -203,8 +205,9 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = Te; } -void -evalElcSourceVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -214,8 +217,9 @@ evalElcSourceVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_R fout[0] = Vx_drift_elc; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -225,8 +229,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -236,8 +239,9 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -247,8 +251,9 @@ evalIonVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = Vx_drift_ion; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -259,8 +264,7 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(x) < Ls) { n = (Ls - fabs(x)) / Ls; // Ion source total number density (left). - } - else { + } else { n = 0.0; // Ion source total number density (right). } @@ -268,8 +272,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -279,8 +284,9 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = Ti; } -void -evalIonSourceVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -290,8 +296,7 @@ evalIonSourceVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_R fout[0] = Vx_drift_ion; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -309,36 +314,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); - #ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Init(&argc, &argv); } @@ -361,16 +368,15 @@ main(int argc, char **argv) } #endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -385,32 +391,18 @@ main(int argc, char **argv) #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -433,132 +425,118 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalElcDensityInit, - .ctx_density = &ctx, - .temp = evalElcTempInit, - .ctx_temp = &ctx, - .V_drift = evalElcVDriftInit, - .ctx_V_drift = &ctx, - }, - - .source = { - .source_id = GKYL_BFLUX_SOURCE, - .source_length = ctx.Ls, - .source_species = "ion", - - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalElcSourceDensityInit, - .ctx_density = &ctx, - .temp = evalElcSourceTempInit, - .ctx_temp = &ctx, - .V_drift = evalElcSourceVDriftInit, - .ctx_V_drift = &ctx, - }, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_ABSORB, }, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalElcDensityInit, + .ctx_density = &ctx, + .temp = evalElcTempInit, + .ctx_temp = &ctx, + .V_drift = evalElcVDriftInit, + .ctx_V_drift = &ctx}, + + .source = + {.source_id = GKYL_BFLUX_SOURCE, + .source_length = ctx.Ls, + .source_species = "ion", + + .num_sources = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalElcSourceDensityInit, + .ctx_density = &ctx, + .temp = evalElcSourceTempInit, + .ctx_temp = &ctx, + .V_drift = evalElcSourceVDriftInit, + .ctx_V_drift = &ctx}}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_ABSORB}}, .num_diag_moments = 1, - .diag_moments = { GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_LTE} }; // Ions. struct gkyl_vlasov_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalIonDensityInit, - .ctx_density = &ctx, - .temp = evalIonTempInit, - .ctx_temp = &ctx, - .V_drift = evalIonVDriftInit, - .ctx_V_drift = &ctx, - }, - - .source = { - .source_id = GKYL_BFLUX_SOURCE, - .source_length = ctx.Ls, - .source_species = "ion", - - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalIonSourceDensityInit, - .ctx_density = &ctx, - .temp = evalIonSourceTempInit, - .ctx_temp = &ctx, - .V_drift = evalIonSourceVDriftInit, - .ctx_V_drift = &ctx, - }, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_ABSORB, }, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalIonDensityInit, + .ctx_density = &ctx, + .temp = evalIonTempInit, + .ctx_temp = &ctx, + .V_drift = evalIonVDriftInit, + .ctx_V_drift = &ctx}, + + .source = + {.source_id = GKYL_BFLUX_SOURCE, + .source_length = ctx.Ls, + .source_species = "ion", + + .num_sources = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalIonSourceDensityInit, + .ctx_density = &ctx, + .temp = evalIonSourceTempInit, + .ctx_temp = &ctx, + .V_drift = evalIonSourceVDriftInit, + .ctx_V_drift = &ctx}}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_ABSORB}}, .num_diag_moments = 1, - .diag_moments = { GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_LTE} }; // Field. struct gkyl_vlasov_field field = { .epsilon0 = ctx.epsilon0, - - .poisson_bcs = { - .lo_type = { GKYL_POISSON_DIRICHLET }, - .up_type = { GKYL_POISSON_DIRICHLET }, - - .lo_value = { 0.0 }, - .up_value = { 0.0 }, - }, + + .poisson_bcs = + {.lo_type = {GKYL_POISSON_DIRICHLET}, + .up_type = {GKYL_POISSON_DIRICHLET}, + + .lo_value = {0.0}, + .up_value = {0.0}} }; // Vlasov-Poisson app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, .is_electrostatic = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -572,10 +550,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -584,32 +566,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -625,7 +614,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -641,8 +630,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -650,7 +638,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -659,8 +649,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -680,14 +669,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/creg/rt_vp_sheath_feedback_sources_bgk_1x1v_p2.c b/vlasov/creg/rt_vp_sheath_feedback_sources_bgk_1x1v_p2.c index 183be343d7..fef7b190aa 100644 --- a/vlasov/creg/rt_vp_sheath_feedback_sources_bgk_1x1v_p2.c +++ b/vlasov/creg/rt_vp_sheath_feedback_sources_bgk_1x1v_p2.c @@ -19,8 +19,7 @@ #include -struct sheath_ctx -{ +struct sheath_ctx { // Physical constants (using normalized code units). double epsilon0; // Permittivity of free space. double mass_elc; // Electron mass. @@ -64,8 +63,7 @@ struct sheath_ctx int num_failures_max; // Maximum allowable number of consecutive small time-steps. }; -struct sheath_ctx -create_ctx(void) +struct sheath_ctx create_ctx(void) { // Physical constants (using normalized code units). double epsilon0 = 1.0; // Permittivity of free space. @@ -86,7 +84,8 @@ create_ctx(void) double vti = sqrt(Ti / mass_ion); // Ion thermal velocity. double lambda_D = sqrt(epsilon0 * Te / (n0 * charge_ion * charge_ion)); // Electron Debye length. - double omega_pe = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. + double omega_pe = + sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_elc)); // Electron plasma frequency. double nu_ee = vte / (50.0 * lambda_D); // Electron-electron collision frequency. double nu_ii = vti / (50.0 * lambda_D); // Ion-ion collision frequency. @@ -105,7 +104,8 @@ create_ctx(void) int num_frames = 1; // Number of output frames. int field_energy_calcs = INT_MAX; // Number of times to calculate field energy. int integrated_mom_calcs = INT_MAX; // Number of times to calculate integrated moments. - int integrated_L2_f_calcs = INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. + int integrated_L2_f_calcs = + INT_MAX; // Number of times to calculate integrated L2 norm of distribution function. double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. @@ -140,14 +140,15 @@ create_ctx(void) .integrated_mom_calcs = integrated_mom_calcs, .integrated_L2_f_calcs = integrated_L2_f_calcs, .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, + .num_failures_max = num_failures_max }; return ctx; } -void -evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -157,8 +158,7 @@ evalElcDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -168,8 +168,9 @@ evalElcTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Te; } -void -evalElcVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -179,8 +180,9 @@ evalElcVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = Vx_drift_elc; } -void -evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -191,8 +193,7 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(x) < Ls) { n = (Ls - fabs(x)) / Ls; // Electron source total number density (left). - } - else { + } else { n = 0.0; // Electron source total number density (right). } @@ -200,8 +201,9 @@ evalElcSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -211,8 +213,9 @@ evalElcSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = Te; } -void -evalElcSourceVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcSourceVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -222,8 +225,9 @@ evalElcSourceVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_R fout[0] = Vx_drift_elc; } -void -evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -233,8 +237,7 @@ evalIonDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRI fout[0] = n0; } -void -evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonTempInit(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -244,8 +247,9 @@ evalIonTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout[0] = Ti; } -void -evalIonVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -255,8 +259,9 @@ evalIonVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRIC fout[0] = Vx_drift_ion; } -void -evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceDensityInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; double x = xn[0]; @@ -267,8 +272,7 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ if (fabs(x) < Ls) { n = (Ls - fabs(x)) / Ls; // Ion source total number density (left). - } - else { + } else { n = 0.0; // Ion source total number density (right). } @@ -276,8 +280,9 @@ evalIonSourceDensityInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_ fout[0] = n; } -void -evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceTempInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -287,8 +292,9 @@ evalIonSourceTempInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RES fout[0] = Ti; } -void -evalIonSourceVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonSourceVDriftInit( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { struct sheath_ctx *app = ctx; @@ -298,8 +304,7 @@ evalIonSourceVDriftInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_R fout[0] = Vx_drift_ion; } -void -evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalElcNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -308,14 +313,14 @@ evalElcNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double nu_ee = app->nu_ee; double lambda_D = app->lambda_D; - double nu = nu_ee / (1.0 + exp(fabs(x) / (6.0 * lambda_D) - 8.0 / 1.5)); // Electron collision frequency. + double nu = + nu_ee / (1.0 + exp(fabs(x) / (6.0 * lambda_D) - 8.0 / 1.5)); // Electron collision frequency. // Set electron collision frequency. fout[0] = nu; } -void -evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +void evalIonNu(double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx) { struct sheath_ctx *app = ctx; @@ -324,14 +329,14 @@ evalIonNu(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, double nu_ii = app->nu_ii; double lambda_D = app->lambda_D; - double nu = nu_ii / (1.0 + exp(fabs(x) / (6.0 * lambda_D) - 8.0 / 1.5)); // Ion collision frequency. + double nu = + nu_ii / (1.0 + exp(fabs(x) / (6.0 * lambda_D) - 8.0 / 1.5)); // Ion collision frequency. // Set ion collision frequency. fout[0] = nu; } -void -write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, bool force_write) +void write_data(struct gkyl_tm_trigger *iot, gkyl_vlasov_app *app, double t_curr, bool force_write) { if (gkyl_tm_trigger_check_and_bump(iot, t_curr) || force_write) { int frame = iot->curr - 1; @@ -349,36 +354,38 @@ write_data(struct gkyl_tm_trigger* iot, gkyl_vlasov_app* app, double t_curr, boo } } -void -calc_field_energy(struct gkyl_tm_trigger* fet, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_field_energy( + struct gkyl_tm_trigger *fet, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(fet, t_curr) || force_calc) { gkyl_vlasov_app_calc_field_energy(app, t_curr); } } -void -calc_integrated_mom(struct gkyl_tm_trigger* imt, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_mom( + struct gkyl_tm_trigger *imt, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(imt, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_mom(app, t_curr); } } -void -calc_integrated_L2_f(struct gkyl_tm_trigger* l2t, gkyl_vlasov_app* app, double t_curr, bool force_calc) +void calc_integrated_L2_f( + struct gkyl_tm_trigger *l2t, gkyl_vlasov_app *app, double t_curr, bool force_calc +) { if (gkyl_tm_trigger_check_and_bump(l2t, t_curr) || force_calc) { gkyl_vlasov_app_calc_integrated_L2_f(app, t_curr); } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct gkyl_app_args app_args = parse_app_args(argc, argv); - #ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI if (app_args.use_mpi) { MPI_Init(&argc, &argv); } @@ -401,16 +408,15 @@ main(int argc, char **argv) } #endif - int ccells[] = { NX }; + int ccells[] = {NX}; int cdim = sizeof(ccells) / sizeof(ccells[0]); int cuts[cdim]; -#ifdef GKYL_HAVE_MPI +#ifdef GKYL_HAVE_MPI for (int d = 0; d < cdim; d++) { if (app_args.use_mpi) { cuts[d] = app_args.cuts[d]; - } - else { + } else { cuts[d] = 1; } } @@ -425,32 +431,18 @@ main(int argc, char **argv) #ifdef GKYL_HAVE_MPI if (app_args.use_gpu && app_args.use_mpi) { #ifdef GKYL_HAVE_NCCL - comm = gkyl_nccl_comm_new( &(struct gkyl_nccl_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); + comm = gkyl_nccl_comm_new(&(struct gkyl_nccl_comm_inp){.mpi_comm = MPI_COMM_WORLD}); #else printf(" Using -g and -M together requires NCCL.\n"); assert(0 == 1); #endif - } - else if (app_args.use_mpi) { - comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { - .mpi_comm = MPI_COMM_WORLD, - } - ); - } - else { - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + } else if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new(&(struct gkyl_mpi_comm_inp){.mpi_comm = MPI_COMM_WORLD}); + } else { + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); } #else - comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { - .use_gpu = app_args.use_gpu - } - ); + comm = gkyl_null_comm_inew(&(struct gkyl_null_comm_inp){.use_gpu = app_args.use_gpu}); #endif int my_rank; @@ -473,144 +465,128 @@ main(int argc, char **argv) // Electrons. struct gkyl_vlasov_species elc = { .name = "elc", - .charge = ctx.charge_elc, .mass = ctx.mass_elc, - .lower = { -ctx.vx_max_elc }, - .upper = { ctx.vx_max_elc }, - .cells = { NVX }, + .charge = ctx.charge_elc, + .mass = ctx.mass_elc, + .lower = {-ctx.vx_max_elc}, + .upper = {ctx.vx_max_elc}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalElcDensityInit, - .ctx_density = &ctx, - .temp = evalElcTempInit, - .ctx_temp = &ctx, - .V_drift = evalElcVDriftInit, - .ctx_V_drift = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalElcNu, - .ctx = &ctx, - .fixed_temp_relax = true, - }, - - .source = { - .source_id = GKYL_BFLUX_SOURCE, - .source_length = ctx.Ls, - .source_species = "ion", - - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalElcSourceDensityInit, - .ctx_density = &ctx, - .temp = evalElcSourceTempInit, - .ctx_temp = &ctx, - .V_drift = evalElcSourceVDriftInit, - .ctx_V_drift = &ctx, - }, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_ABSORB, }, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalElcDensityInit, + .ctx_density = &ctx, + .temp = evalElcTempInit, + .ctx_temp = &ctx, + .V_drift = evalElcVDriftInit, + .ctx_V_drift = &ctx}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalElcNu, + .ctx = &ctx, + .fixed_temp_relax = true}, + + .source = + {.source_id = GKYL_BFLUX_SOURCE, + .source_length = ctx.Ls, + .source_species = "ion", + + .num_sources = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalElcSourceDensityInit, + .ctx_density = &ctx, + .temp = evalElcSourceTempInit, + .ctx_temp = &ctx, + .V_drift = evalElcSourceVDriftInit, + .ctx_V_drift = &ctx}}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_ABSORB}}, .num_diag_moments = 1, - .diag_moments = { GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_LTE} }; // Ions. struct gkyl_vlasov_species ion = { .name = "ion", - .charge = ctx.charge_ion, .mass = ctx.mass_ion, - .lower = { -ctx.vx_max_ion }, - .upper = { ctx.vx_max_ion }, - .cells = { NVX }, + .charge = ctx.charge_ion, + .mass = ctx.mass_ion, + .lower = {-ctx.vx_max_ion}, + .upper = {ctx.vx_max_ion}, + .cells = {NVX}, .num_init = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalIonDensityInit, - .ctx_density = &ctx, - .temp = evalIonTempInit, - .ctx_temp = &ctx, - .V_drift = evalIonVDriftInit, - .ctx_V_drift = &ctx, - }, - .collisions = { - .collision_id = GKYL_BGK_COLLISIONS, - .self_nu = evalIonNu, - .ctx = &ctx, - .fixed_temp_relax = true, - }, - - .source = { - .source_id = GKYL_BFLUX_SOURCE, - .source_length = ctx.Ls, - .source_species = "ion", - - .num_sources = 1, - .projection[0] = { - .proj_id = GKYL_PROJ_VLASOV_LTE, - .density = evalIonSourceDensityInit, - .ctx_density = &ctx, - .temp = evalIonSourceTempInit, - .ctx_temp = &ctx, - .V_drift = evalIonSourceVDriftInit, - .ctx_V_drift = &ctx, - }, - }, - - .bcx = { - .lower = { .type = GKYL_SPECIES_ABSORB, }, - .upper = { .type = GKYL_SPECIES_ABSORB, }, - }, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalIonDensityInit, + .ctx_density = &ctx, + .temp = evalIonTempInit, + .ctx_temp = &ctx, + .V_drift = evalIonVDriftInit, + .ctx_V_drift = &ctx}, + .collisions = + {.collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalIonNu, + .ctx = &ctx, + .fixed_temp_relax = true}, + + .source = + {.source_id = GKYL_BFLUX_SOURCE, + .source_length = ctx.Ls, + .source_species = "ion", + + .num_sources = 1, + .projection[0] = + {.proj_id = GKYL_PROJ_VLASOV_LTE, + .density = evalIonSourceDensityInit, + .ctx_density = &ctx, + .temp = evalIonSourceTempInit, + .ctx_temp = &ctx, + .V_drift = evalIonSourceVDriftInit, + .ctx_V_drift = &ctx}}, + + .bcx = {.lower = {.type = GKYL_SPECIES_ABSORB}, .upper = {.type = GKYL_SPECIES_ABSORB}}, .num_diag_moments = 1, - .diag_moments = { GKYL_F_MOMENT_LTE }, + .diag_moments = {GKYL_F_MOMENT_LTE} }; // Field. struct gkyl_vlasov_field field = { .epsilon0 = ctx.epsilon0, - - .poisson_bcs = { - .lo_type = { GKYL_POISSON_DIRICHLET }, - .up_type = { GKYL_POISSON_DIRICHLET }, - - .lo_value = { 0.0 }, - .up_value = { 0.0 }, - }, + + .poisson_bcs = + {.lo_type = {GKYL_POISSON_DIRICHLET}, + .up_type = {GKYL_POISSON_DIRICHLET}, + + .lo_value = {0.0}, + .up_value = {0.0}} }; // Vlasov-Poisson app. struct gkyl_vm app_inp = { - .cdim = 1, .vdim = 1, - .lower = { -0.5 * ctx.Lx }, - .upper = { 0.5 * ctx.Lx }, - .cells = { NX }, + .cdim = 1, + .vdim = 1, + .lower = {-0.5 * ctx.Lx}, + .upper = {0.5 * ctx.Lx}, + .cells = {NX}, .poly_order = ctx.poly_order, .basis_type = app_args.basis_type, .cfl_frac = ctx.cfl_frac, .num_periodic_dir = 0, - .periodic_dirs = { }, + .periodic_dirs = {}, .num_species = 2, - .species = { elc, ion }, + .species = {elc, ion}, .field = field, .is_electrostatic = true, - .parallelism = { - .use_gpu = app_args.use_gpu, - .cuts = { app_args.cuts[0] }, - .comm = comm, - }, + .parallelism = {.use_gpu = app_args.use_gpu, .cuts = {app_args.cuts[0]}, .comm = comm} }; // Create app object. @@ -624,10 +600,14 @@ main(int argc, char **argv) // Initialize simulation. int frame_curr = 0; if (app_args.is_restart) { - struct gkyl_app_restart_status status = gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); + struct gkyl_app_restart_status status = + gkyl_vlasov_app_read_from_frame(app, app_args.restart_frame); if (status.io_status != GKYL_ARRAY_RIO_SUCCESS) { - gkyl_vlasov_app_cout(app, stderr, "*** Failed to read restart file! (%s)\n", gkyl_array_rio_status_msg(status.io_status)); + gkyl_vlasov_app_cout( + app, stderr, "*** Failed to read restart file! (%s)\n", + gkyl_array_rio_status_msg(status.io_status) + ); goto freeresources; } @@ -636,32 +616,39 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Restarting from frame %d", frame_curr); gkyl_vlasov_app_cout(app, stdout, " at time = %g\n", t_curr); - } - else { + } else { gkyl_vlasov_app_apply_ic(app, t_curr); } // Create trigger for field energy. int field_energy_calcs = ctx.field_energy_calcs; - struct gkyl_tm_trigger fe_trig = { .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger fe_trig = { + .dt = t_end / field_energy_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_field_energy(&fe_trig, app, t_curr, false); // Create trigger for integrated moments. int integrated_mom_calcs = ctx.integrated_mom_calcs; - struct gkyl_tm_trigger im_trig = { .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger im_trig = { + .dt = t_end / integrated_mom_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_mom(&im_trig, app, t_curr, false); // Create trigger for integrated L2 norm of the distribution function. int integrated_L2_f_calcs = ctx.integrated_L2_f_calcs; - struct gkyl_tm_trigger l2f_trig = { .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr }; + struct gkyl_tm_trigger l2f_trig = { + .dt = t_end / integrated_L2_f_calcs, .tcurr = t_curr, .curr = frame_curr + }; calc_integrated_L2_f(&l2f_trig, app, t_curr, false); // Create trigger for IO. int num_frames = ctx.num_frames; - struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr }; + struct gkyl_tm_trigger io_trig = { + .dt = t_end / num_frames, .tcurr = frame_curr * (t_end / num_frames), .curr = frame_curr + }; write_data(&io_trig, app, t_curr, false); @@ -677,7 +664,7 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); struct gkyl_update_status status = gkyl_vlasov_update(app, dt); gkyl_vlasov_app_cout(app, stdout, " dt = %g\n", status.dt_actual); - + if (!status.success) { gkyl_vlasov_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); break; @@ -693,8 +680,7 @@ main(int argc, char **argv) if (dt_init < 0.0) { dt_init = status.dt_actual; - } - else if (status.dt_actual < dt_failure_tol * dt_init) { + } else if (status.dt_actual < dt_failure_tol * dt_init) { num_failures += 1; gkyl_vlasov_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); @@ -702,7 +688,9 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, " num_failures = %d\n", num_failures); if (num_failures >= num_failures_max) { gkyl_vlasov_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); - gkyl_vlasov_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + gkyl_vlasov_app_cout( + app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max + ); calc_field_energy(&fe_trig, app, t_curr, true); calc_integrated_mom(&im_trig, app, t_curr, true); @@ -711,8 +699,7 @@ main(int argc, char **argv) break; } - } - else { + } else { num_failures = 0; } @@ -732,14 +719,22 @@ main(int argc, char **argv) gkyl_vlasov_app_cout(app, stdout, "Number of forward-Euler calls %ld\n", stat.nfeuler); gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); if (stat.nstage_2_fail > 0) { - gkyl_vlasov_app_cout(app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); - gkyl_vlasov_app_cout(app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); - } + gkyl_vlasov_app_cout( + app, stdout, " Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1] + ); + gkyl_vlasov_app_cout( + app, stdout, " Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0] + ); + } gkyl_vlasov_app_cout(app, stdout, "Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); gkyl_vlasov_app_cout(app, stdout, "Species RHS calc took %g secs\n", stat.species_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisions RHS calc took %g secs\n", stat.species_coll_tm + ); gkyl_vlasov_app_cout(app, stdout, "Field RHS calc took %g secs\n", stat.field_rhs_tm); - gkyl_vlasov_app_cout(app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm); + gkyl_vlasov_app_cout( + app, stdout, "Species collisional moments took %g secs\n", stat.species_coll_mom_tm + ); gkyl_vlasov_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); gkyl_vlasov_app_cout(app, stdout, "Number of write calls %ld\n", stat.n_io); diff --git a/vlasov/unit/ctest_bc_basic.c b/vlasov/unit/ctest_bc_basic.c index 50b9c0344f..2d10d35a2e 100644 --- a/vlasov/unit/ctest_bc_basic.c +++ b/vlasov/unit/ctest_bc_basic.c @@ -12,46 +12,49 @@ #include #include -void evalFunc_1x1v(double t, const double *xn, double *restrict fout, - void *ctx) { +void evalFunc_1x1v(double t, const double *xn, double *restrict fout, void *ctx) +{ double x = xn[0], vx = xn[1]; fout[0] = (x) * (vx - 0.5) * (vx - 0.5); } -void evalFunc_1x2v(double t, const double *xn, double *restrict fout, - void *ctx) { +void evalFunc_1x2v(double t, const double *xn, double *restrict fout, void *ctx) +{ double x = xn[0], vx = xn[1], vy = xn[2]; fout[0] = (x * x) * (vx - 0.5) * (vy - 0.5); } -void evalFunc_2x2v(double t, const double *xn, double *restrict fout, - void *ctx) { +void evalFunc_2x2v(double t, const double *xn, double *restrict fout, void *ctx) +{ double x = xn[0], y = xn[1]; double vx = xn[2], vy = xn[3]; fout[0] = x * y * (vx - 1) * (vy - 2); } -void evalFunc_3x2v(double t, const double *xn, double *restrict fout, - void *ctx) { +void evalFunc_3x2v(double t, const double *xn, double *restrict fout, void *ctx) +{ double x = xn[0], y = xn[1], z = xn[2]; double vx = xn[3], vy = xn[4]; fout[0] = (x - 1) * y * (z + 1) * (vx - 1) * (vy - 2); } -GKYL_CU_DH static void buffer_fn(size_t nc, double *out, - const double *inp, void *ctx) { - for (size_t i=0; indim; for (int d = 0; d < ndim; ++d) { - gkyl_skin_ghost_ranges(&sgr->lower_skin[d], &sgr->lower_ghost[d], d, - GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], d, - GKYL_UPPER_EDGE, parent, ghost); + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } -void test_bc(int cdim, int vdim, int poly_order, char *boundary_type, bool useGPU) { +void test_bc(int cdim, int vdim, int poly_order, char *boundary_type, bool useGPU) +{ int ndim = cdim + vdim; double lower[ndim], upper[ndim]; int cells[ndim]; @@ -124,22 +132,18 @@ void test_bc(int cdim, int vdim, int poly_order, char *boundary_type, bool useGP struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); struct skin_ghost_ranges skin_ghost; // phase-space skin/ghost - skin_ghost_ranges_init(&skin_ghost, &local_ext, ghost); + skin_ghost_ranges_init(&skin_ghost, &local_ext, ghost); // Projection updater for dist-function gkyl_proj_on_basis *projDistf; if (cdim == 1 && vdim == 1) { - projDistf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, - evalFunc_1x1v, NULL); + projDistf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_1x1v, NULL); } else if (cdim == 1 && vdim == 2) { - projDistf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, - evalFunc_1x2v, NULL); + projDistf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_1x2v, NULL); } else if (cdim == 2 && vdim == 2) { - projDistf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, - evalFunc_2x2v, NULL); + projDistf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_2x2v, NULL); } else if (cdim == 3 && vdim == 2) { - projDistf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, - evalFunc_3x2v, NULL); + projDistf = gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc_3x2v, NULL); } // Create distribution function array @@ -153,7 +157,7 @@ void test_bc(int cdim, int vdim, int poly_order, char *boundary_type, bool useGP long buff_sz = 0; for (int d = 0; d < cdim; ++d) { long vol = skin_ghost.lower_skin[d].volume; - buff_sz = buff_sz > vol ? buff_sz : vol; + buff_sz = buff_sz > vol ? buff_sz : vol; } struct gkyl_array *bc_buffer; bc_buffer = mkarr(basis.num_basis, buff_sz); @@ -165,21 +169,25 @@ void test_bc(int cdim, int vdim, int poly_order, char *boundary_type, bool useGP basis_cu = gkyl_cu_malloc(sizeof(struct gkyl_basis)); gkyl_cart_modal_serendip_cu_dev(basis_cu, ndim, poly_order); bc_buffer_cu = mkarr_cu(basis.num_basis, buff_sz); - distf_cu = mkarr_cu(basis.num_basis, local_ext.volume); + distf_cu = mkarr_cu(basis.num_basis, local_ext.volume); gkyl_array_copy(distf_cu, distf); } else { basis_cu = &basis; } // Create and apply BC to the lower ghost cells - for (int bc_dir = 0; bc_dir < cdim; bc_dir++) { + for (int bc_dir = 0; bc_dir < cdim; bc_dir++) { struct gkyl_bc_basic *bclo; if (strcmp(boundary_type, "reflect") == 0) { - bclo = gkyl_bc_basic_new(bc_dir, GKYL_LOWER_EDGE, GKYL_BC_DISTF_REFLECT, basis_cu, - &skin_ghost.lower_skin[bc_dir], &skin_ghost.lower_ghost[bc_dir], distf->ncomp, cdim, useGPU); + bclo = gkyl_bc_basic_new( + bc_dir, GKYL_LOWER_EDGE, GKYL_BC_DISTF_REFLECT, basis_cu, &skin_ghost.lower_skin[bc_dir], + &skin_ghost.lower_ghost[bc_dir], distf->ncomp, cdim, useGPU + ); } else if (strcmp(boundary_type, "absorb") == 0) { - bclo = gkyl_bc_basic_new(bc_dir, GKYL_LOWER_EDGE, GKYL_BC_ABSORB, basis_cu, - &skin_ghost.lower_skin[bc_dir], &skin_ghost.lower_ghost[bc_dir], distf->ncomp, cdim, useGPU); + bclo = gkyl_bc_basic_new( + bc_dir, GKYL_LOWER_EDGE, GKYL_BC_ABSORB, basis_cu, &skin_ghost.lower_skin[bc_dir], + &skin_ghost.lower_ghost[bc_dir], distf->ncomp, cdim, useGPU + ); } if (useGPU) { #ifdef GKYL_HAVE_CUDA @@ -187,26 +195,30 @@ void test_bc(int cdim, int vdim, int poly_order, char *boundary_type, bool useGP #endif gkyl_bc_basic_advance(bclo, bc_buffer_cu, distf_cu); } else { - gkyl_bc_basic_advance(bclo, bc_buffer, distf); + gkyl_bc_basic_advance(bclo, bc_buffer, distf); } gkyl_bc_basic_release(bclo); // Create and apply BC to the upper ghost cells struct gkyl_bc_basic *bcup; if (strcmp(boundary_type, "reflect") == 0) { - bcup = gkyl_bc_basic_new(bc_dir, GKYL_UPPER_EDGE, GKYL_BC_DISTF_REFLECT, basis_cu, - &skin_ghost.upper_skin[bc_dir], &skin_ghost.upper_ghost[bc_dir], distf->ncomp, cdim, useGPU); - } else if (strcmp(boundary_type, "absorb") == 0) { - bcup = gkyl_bc_basic_new(bc_dir, GKYL_UPPER_EDGE, GKYL_BC_ABSORB, basis_cu, - &skin_ghost.upper_skin[bc_dir], &skin_ghost.upper_ghost[bc_dir], distf->ncomp, cdim, useGPU); - } + bcup = gkyl_bc_basic_new( + bc_dir, GKYL_UPPER_EDGE, GKYL_BC_DISTF_REFLECT, basis_cu, &skin_ghost.upper_skin[bc_dir], + &skin_ghost.upper_ghost[bc_dir], distf->ncomp, cdim, useGPU + ); + } else if (strcmp(boundary_type, "absorb") == 0) { + bcup = gkyl_bc_basic_new( + bc_dir, GKYL_UPPER_EDGE, GKYL_BC_ABSORB, basis_cu, &skin_ghost.upper_skin[bc_dir], + &skin_ghost.upper_ghost[bc_dir], distf->ncomp, cdim, useGPU + ); + } if (useGPU) { #ifdef GKYL_HAVE_CUDA cudaDeviceSynchronize(); #endif gkyl_bc_basic_advance(bcup, bc_buffer_cu, distf_cu); } else { - gkyl_bc_basic_advance(bcup, bc_buffer, distf); + gkyl_bc_basic_advance(bcup, bc_buffer, distf); } gkyl_bc_basic_release(bcup); } @@ -228,14 +240,16 @@ void test_bc(int cdim, int vdim, int poly_order, char *boundary_type, bool useGP gkyl_array_copy(distf_flip, distf); // Flip the skin value in velocity space to apply reflect BC to skin cell - gkyl_array_flip_copy_to_buffer_fn(bc_buffer->data, distf_flip, cdim+d, - &(skin_ghost.lower_skin[d]), &(struct gkyl_array_copy_func) - { .func = buffer_fn, .ctx = 0 }); + gkyl_array_flip_copy_to_buffer_fn( + bc_buffer->data, distf_flip, cdim + d, &(skin_ghost.lower_skin[d]), + &(struct gkyl_array_copy_func){.func = buffer_fn, .ctx = 0} + ); gkyl_array_copy_from_buffer(distf_flip, bc_buffer->data, &(skin_ghost.lower_skin[d])); - gkyl_array_flip_copy_to_buffer_fn(bc_buffer->data, distf_flip, cdim+d, - &( skin_ghost.upper_skin[d]), &(struct gkyl_array_copy_func) - { .func = buffer_fn, .ctx = 0 }); + gkyl_array_flip_copy_to_buffer_fn( + bc_buffer->data, distf_flip, cdim + d, &(skin_ghost.upper_skin[d]), + &(struct gkyl_array_copy_func){.func = buffer_fn, .ctx = 0} + ); gkyl_array_copy_from_buffer(distf_flip, bc_buffer->data, &(skin_ghost.upper_skin[d])); } while (gkyl_range_iter_next(&iter)) { @@ -243,14 +257,14 @@ void test_bc(int cdim, int vdim, int poly_order, char *boundary_type, bool useGP iter_skin = iter; iter_skin.idx[d] = iter.idx[d] + 1; int linidx_ghost = gkyl_range_idx(skin_ghost.lower_ghost, iter.idx); - int linidx_skin = gkyl_range_idx(skin_ghost.lower_skin, iter_skin.idx); + int linidx_skin = gkyl_range_idx(skin_ghost.lower_skin, iter_skin.idx); const double *val_ghost = gkyl_array_cfetch(distf_flip, linidx_ghost); - const double *val_skin = gkyl_array_cfetch(distf_flip, linidx_skin); + const double *val_skin = gkyl_array_cfetch(distf_flip, linidx_skin); if (strcmp(boundary_type, "reflect") == 0) { double val_correct[basis.num_basis]; // Flip the DG coefficients - basis.flip_odd_sign(d, val_skin, val_correct); + basis.flip_odd_sign(d, val_skin, val_correct); basis.flip_odd_sign(d + cdim, val_correct, val_correct); // Check values @@ -271,14 +285,14 @@ void test_bc(int cdim, int vdim, int poly_order, char *boundary_type, bool useGP iter_skin = iter; iter_skin.idx[d] = iter.idx[d] - 1; int linidx_ghost = gkyl_range_idx(skin_ghost.upper_ghost, iter.idx); - int linidx_skin = gkyl_range_idx(skin_ghost.upper_skin, iter_skin.idx); + int linidx_skin = gkyl_range_idx(skin_ghost.upper_skin, iter_skin.idx); const double *val_ghost = gkyl_array_cfetch(distf_flip, linidx_ghost); - const double *val_skin = gkyl_array_cfetch(distf_flip, linidx_skin); + const double *val_skin = gkyl_array_cfetch(distf_flip, linidx_skin); if (strcmp(boundary_type, "reflect") == 0) { // Flip the DG coefficients double val_correct[basis.num_basis]; - basis.flip_odd_sign(d, val_skin, val_correct); + basis.flip_odd_sign(d, val_skin, val_correct); basis.flip_odd_sign(d + cdim, val_correct, val_correct); // Check values @@ -300,43 +314,138 @@ void test_bc(int cdim, int vdim, int poly_order, char *boundary_type, bool useGP gkyl_array_release(distf_flip); } -void test_bc_reflect_1x1v_p1_ho() { test_bc(1, 1, 1, "reflect", false); } -void test_bc_reflect_1x2v_p1_ho() { test_bc(1, 2, 1, "reflect", false); } -void test_bc_reflect_2x2v_p1_ho() { test_bc(2, 2, 1, "reflect", false); } -void test_bc_reflect_3x2v_p1_ho() { test_bc(3, 2, 1, "reflect", false); } -void test_bc_reflect_1x1v_p2_ho() { test_bc(1, 1, 2, "reflect", false); } -void test_bc_reflect_1x2v_p2_ho() { test_bc(1, 2, 2, "reflect", false); } -void test_bc_reflect_2x2v_p2_ho() { test_bc(2, 2, 2, "reflect", false); } -void test_bc_reflect_3x2v_p2_ho() { test_bc(3, 2, 2, "reflect", false); } - -void test_bc_absorb_1x1v_p1_ho() { test_bc(1, 1, 1, "absorb", false); } -void test_bc_absorb_1x2v_p1_ho() { test_bc(1, 2, 1, "absorb", false); } -void test_bc_absorb_2x2v_p1_ho() { test_bc(2, 2, 1, "absorb", false); } -void test_bc_absorb_3x2v_p1_ho() { test_bc(3, 2, 1, "absorb", false); } -void test_bc_absorb_1x1v_p2_ho() { test_bc(1, 1, 2, "absorb", false); } -void test_bc_absorb_1x2v_p2_ho() { test_bc(1, 2, 2, "absorb", false); } -void test_bc_absorb_2x2v_p2_ho() { test_bc(2, 2, 2, "absorb", false); } -void test_bc_absorb_3x2v_p2_ho() { test_bc(3, 2, 2, "absorb", false); } +void test_bc_reflect_1x1v_p1_ho() +{ + test_bc(1, 1, 1, "reflect", false); +} +void test_bc_reflect_1x2v_p1_ho() +{ + test_bc(1, 2, 1, "reflect", false); +} +void test_bc_reflect_2x2v_p1_ho() +{ + test_bc(2, 2, 1, "reflect", false); +} +void test_bc_reflect_3x2v_p1_ho() +{ + test_bc(3, 2, 1, "reflect", false); +} +void test_bc_reflect_1x1v_p2_ho() +{ + test_bc(1, 1, 2, "reflect", false); +} +void test_bc_reflect_1x2v_p2_ho() +{ + test_bc(1, 2, 2, "reflect", false); +} +void test_bc_reflect_2x2v_p2_ho() +{ + test_bc(2, 2, 2, "reflect", false); +} +void test_bc_reflect_3x2v_p2_ho() +{ + test_bc(3, 2, 2, "reflect", false); +} + +void test_bc_absorb_1x1v_p1_ho() +{ + test_bc(1, 1, 1, "absorb", false); +} +void test_bc_absorb_1x2v_p1_ho() +{ + test_bc(1, 2, 1, "absorb", false); +} +void test_bc_absorb_2x2v_p1_ho() +{ + test_bc(2, 2, 1, "absorb", false); +} +void test_bc_absorb_3x2v_p1_ho() +{ + test_bc(3, 2, 1, "absorb", false); +} +void test_bc_absorb_1x1v_p2_ho() +{ + test_bc(1, 1, 2, "absorb", false); +} +void test_bc_absorb_1x2v_p2_ho() +{ + test_bc(1, 2, 2, "absorb", false); +} +void test_bc_absorb_2x2v_p2_ho() +{ + test_bc(2, 2, 2, "absorb", false); +} +void test_bc_absorb_3x2v_p2_ho() +{ + test_bc(3, 2, 2, "absorb", false); +} #ifdef GKYL_HAVE_CUDA -void test_bc_reflect_1x1v_p1_dev() { test_bc(1, 1, 1, "reflect", true); } -void test_bc_reflect_1x2v_p1_dev() { test_bc(1, 2, 1, "reflect", true); } -void test_bc_reflect_2x2v_p1_dev() { test_bc(2, 2, 1, "reflect", true); } -void test_bc_reflect_3x2v_p1_dev() { test_bc(3, 2, 1, "reflect", true); } -void test_bc_reflect_1x1v_p2_dev() { test_bc(1, 1, 2, "reflect", true); } -void test_bc_reflect_1x2v_p2_dev() { test_bc(1, 2, 2, "reflect", true); } -void test_bc_reflect_2x2v_p2_dev() { test_bc(2, 2, 2, "reflect", true); } -void test_bc_reflect_3x2v_p2_dev() { test_bc(3, 2, 2, "reflect", true); } - - -void test_bc_absorb_1x1v_p1_dev() { test_bc(1, 1, 1, "absorb", true); } -void test_bc_absorb_1x2v_p1_dev() { test_bc(1, 2, 1, "absorb", true); } -void test_bc_absorb_2x2v_p1_dev() { test_bc(2, 2, 1, "absorb", true); } -void test_bc_absorb_3x2v_p1_dev() { test_bc(3, 2, 1, "absorb", true); } -void test_bc_absorb_1x1v_p2_dev() { test_bc(1, 1, 2, "absorb", true); } -void test_bc_absorb_1x2v_p2_dev() { test_bc(1, 2, 2, "absorb", true); } -void test_bc_absorb_2x2v_p2_dev() { test_bc(2, 2, 2, "absorb", true); } -void test_bc_absorb_3x2v_p2_dev() { test_bc(3, 2, 2, "absorb", true); } +void test_bc_reflect_1x1v_p1_dev() +{ + test_bc(1, 1, 1, "reflect", true); +} +void test_bc_reflect_1x2v_p1_dev() +{ + test_bc(1, 2, 1, "reflect", true); +} +void test_bc_reflect_2x2v_p1_dev() +{ + test_bc(2, 2, 1, "reflect", true); +} +void test_bc_reflect_3x2v_p1_dev() +{ + test_bc(3, 2, 1, "reflect", true); +} +void test_bc_reflect_1x1v_p2_dev() +{ + test_bc(1, 1, 2, "reflect", true); +} +void test_bc_reflect_1x2v_p2_dev() +{ + test_bc(1, 2, 2, "reflect", true); +} +void test_bc_reflect_2x2v_p2_dev() +{ + test_bc(2, 2, 2, "reflect", true); +} +void test_bc_reflect_3x2v_p2_dev() +{ + test_bc(3, 2, 2, "reflect", true); +} + +void test_bc_absorb_1x1v_p1_dev() +{ + test_bc(1, 1, 1, "absorb", true); +} +void test_bc_absorb_1x2v_p1_dev() +{ + test_bc(1, 2, 1, "absorb", true); +} +void test_bc_absorb_2x2v_p1_dev() +{ + test_bc(2, 2, 1, "absorb", true); +} +void test_bc_absorb_3x2v_p1_dev() +{ + test_bc(3, 2, 1, "absorb", true); +} +void test_bc_absorb_1x1v_p2_dev() +{ + test_bc(1, 1, 2, "absorb", true); +} +void test_bc_absorb_1x2v_p2_dev() +{ + test_bc(1, 2, 2, "absorb", true); +} +void test_bc_absorb_2x2v_p2_dev() +{ + test_bc(2, 2, 2, "absorb", true); +} +void test_bc_absorb_3x2v_p2_dev() +{ + test_bc(3, 2, 2, "absorb", true); +} #endif @@ -376,5 +485,5 @@ TEST_LIST = { {"test_bc_absorb_2x2v_p2_dev", test_bc_absorb_2x2v_p2_dev}, {"test_bc_absorb_3x2v_p2_dev", test_bc_absorb_3x2v_p2_dev}, #endif - {NULL, NULL}, + {NULL, NULL} }; diff --git a/vlasov/unit/ctest_canonical_pb_continuity.c b/vlasov/unit/ctest_canonical_pb_continuity.c index bdc6cf7b02..17cb323789 100644 --- a/vlasov/unit/ctest_canonical_pb_continuity.c +++ b/vlasov/unit/ctest_canonical_pb_continuity.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -21,32 +21,26 @@ #include #include - -void -info_h_ij_inv_1x1v(double t, const double* xn, double* fout, void* ctx) +void info_h_ij_inv_1x1v(double t, const double *xn, double *fout, void *ctx) { fout[0] = 1; } -void -info_det_h_1x1v(double t, const double* xn, double* fout, void* ctx) +void info_det_h_1x1v(double t, const double *xn, double *fout, void *ctx) { fout[0] = 1; } -void -info_hamil_1x1v(double t, const double* xn, double* fout, void* ctx) +void info_hamil_1x1v(double t, const double *xn, double *fout, void *ctx) { double x = xn[0], v = xn[1]; - fout[0] = 0.5*v*v; + fout[0] = 0.5 * v * v; } - -void -test_1x1v(int poly_order, enum gkyl_basis_type b_type) +void test_1x1v(int poly_order, enum gkyl_basis_type b_type) { double pi = 3.14159265359; - double lower[] = { 0.0, -5.0}, upper[] = {1.0, 5.0}; + double lower[] = {0.0, -5.0}, upper[] = {1.0, 5.0}; int cells[] = {4, 4}; int vdim = 1, cdim = 1; int pdim = cdim + vdim; @@ -66,62 +60,64 @@ test_1x1v(int poly_order, enum gkyl_basis_type b_type) // velocity range int velGhost[] = {0}; - struct gkyl_range velLocal, velLocal_ext; + struct gkyl_range velLocal, velLocal_ext; gkyl_create_grid_ranges(&vel_grid, velGhost, &velLocal_ext, &velLocal); // basis functions struct gkyl_basis basis, confBasis; if (poly_order == 1 && b_type == GKYL_BASIS_MODAL_SERENDIPITY) { gkyl_cart_modal_hybrid(&basis, cdim, vdim); - } - else if (b_type == GKYL_BASIS_MODAL_SERENDIPITY) { + } else if (b_type == GKYL_BASIS_MODAL_SERENDIPITY) { gkyl_cart_modal_serendip(&basis, pdim, poly_order); - } - else { - gkyl_cart_modal_tensor(&basis, pdim, poly_order);; + } else { + gkyl_cart_modal_tensor(&basis, pdim, poly_order); + ; } gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); int confGhost[] = {1}; - struct gkyl_range confLocal, confLocal_ext; + struct gkyl_range confLocal, confLocal_ext; gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); int ghost[] = {confGhost[0], 0}; - struct gkyl_range local, local_ext; + struct gkyl_range local, local_ext; gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // Allocate arrays for specified metric inverse, hamiltonian and metric determinant struct gkyl_array *h_ij_inv, *det_h, *hamil; - h_ij_inv = mkarr(false, confBasis.num_basis*vdim*(vdim+1)/2, local_ext.volume); + h_ij_inv = mkarr(false, confBasis.num_basis * vdim * (vdim + 1) / 2, local_ext.volume); det_h = mkarr(false, confBasis.num_basis, local_ext.volume); hamil = mkarr(false, basis.num_basis, local_ext.volume); // Evaluate specified inverse metric function and det. at nodes to insure continuity - struct gkyl_eval_on_nodes* h_ij_inv_proj = gkyl_eval_on_nodes_new(&confGrid, &confBasis, vdim*(vdim+1)/2, info_h_ij_inv_1x1v, 0); - struct gkyl_eval_on_nodes* det_h_proj = gkyl_eval_on_nodes_new(&confGrid, &confBasis, 1, info_det_h_1x1v, 0); - struct gkyl_eval_on_nodes* hamil_proj = gkyl_eval_on_nodes_new(&grid, &basis, 1, info_hamil_1x1v, 0); + struct gkyl_eval_on_nodes *h_ij_inv_proj = + gkyl_eval_on_nodes_new(&confGrid, &confBasis, vdim * (vdim + 1) / 2, info_h_ij_inv_1x1v, 0); + struct gkyl_eval_on_nodes *det_h_proj = + gkyl_eval_on_nodes_new(&confGrid, &confBasis, 1, info_det_h_1x1v, 0); + struct gkyl_eval_on_nodes *hamil_proj = + gkyl_eval_on_nodes_new(&grid, &basis, 1, info_hamil_1x1v, 0); gkyl_eval_on_nodes_advance(h_ij_inv_proj, 0.0, &confLocal, h_ij_inv); gkyl_eval_on_nodes_advance(det_h_proj, 0.0, &confLocal, det_h); gkyl_eval_on_nodes_advance(hamil_proj, 0.0, &local_ext, hamil); - // Need to figure out size of alpha_surf and sgn_alpha_surf by finding size of surface basis set + // Need to figure out size of alpha_surf and sgn_alpha_surf by finding size of surface basis set struct gkyl_basis surf_basis, surf_quad_basis; if (basis.b_type == GKYL_BASIS_MODAL_HYBRID) { // NOTE: If we are hybrid, allocate more memory than we need to avoid surface basis are different // sizes in each direction. - gkyl_cart_modal_serendip(&surf_basis, pdim-1, 2); - gkyl_cart_modal_tensor(&surf_quad_basis, pdim-1, 2); - } - else { - gkyl_cart_modal_serendip(&surf_basis, pdim-1, poly_order); - gkyl_cart_modal_tensor(&surf_quad_basis, pdim-1, poly_order); + gkyl_cart_modal_serendip(&surf_basis, pdim - 1, 2); + gkyl_cart_modal_tensor(&surf_quad_basis, pdim - 1, 2); + } else { + gkyl_cart_modal_serendip(&surf_basis, pdim - 1, poly_order); + gkyl_cart_modal_tensor(&surf_quad_basis, pdim - 1, poly_order); } // always vdim + cdim - int alpha_surf_sz = (vdim + cdim)*surf_basis.num_basis; - int sgn_alpha_surf_sz = (vdim + cdim)*surf_quad_basis.num_basis; // sign(alpha) is store at quadrature points + int alpha_surf_sz = (vdim + cdim) * surf_basis.num_basis; + int sgn_alpha_surf_sz = + (vdim + cdim) * surf_quad_basis.num_basis; // sign(alpha) is store at quadrature points - // allocate arrays to store fields: + // allocate arrays to store fields: // 1. alpha_surf (surface phase space velocity) // 2. sgn_alpha_surf (sign(alpha_surf) at quadrature points) // 3. const_sgn_alpha (boolean for if sign(alpha_surf) is a constant, either +1 or -1) @@ -130,76 +126,114 @@ test_1x1v(int poly_order, enum gkyl_basis_type b_type) struct gkyl_array *const_sgn_alpha = mk_int_arr(false, (vdim + cdim), local_ext.volume); // Pre-compute alpha_surf, sgn_alpha_surf, const_sgn_alpha, and cot_vec since they are time-independent - struct gkyl_dg_calc_canonical_pb_vars *calc_vars = gkyl_dg_calc_canonical_pb_vars_new(&grid, - &confBasis, &basis, false); - gkyl_dg_calc_canonical_pb_vars_alpha_surf(calc_vars, &confLocal, &local, &local_ext, hamil, - alpha_surf, sgn_alpha_surf, const_sgn_alpha); + struct gkyl_dg_calc_canonical_pb_vars *calc_vars = + gkyl_dg_calc_canonical_pb_vars_new(&grid, &confBasis, &basis, false); + gkyl_dg_calc_canonical_pb_vars_alpha_surf( + calc_vars, &confLocal, &local, &local_ext, hamil, alpha_surf, sgn_alpha_surf, const_sgn_alpha + ); // Check continuity (Directly via Kernels, Option 2) - double w_edge_not_used[2] = { 0.0, 0.0 }; - double dxv[2] = {confGrid.dx[0], vel_grid.dx[0] }; + double w_edge_not_used[2] = {0.0, 0.0}; + double dxv[2] = {confGrid.dx[0], vel_grid.dx[0]}; struct gkyl_array *alpha_surf_comp_L = mkarr(false, alpha_surf_sz, local_ext.volume); struct gkyl_array *alpha_surf_comp_R = mkarr(false, alpha_surf_sz, local_ext.volume); - struct gkyl_array *sgn_alpha_surf_comp_not_used = mkarr(false, sgn_alpha_surf_sz, local_ext.volume); + struct gkyl_array *sgn_alpha_surf_comp_not_used = + mkarr(false, sgn_alpha_surf_sz, local_ext.volume); // Loop over cells, get expansions in cells struct gkyl_range_iter piter; gkyl_range_iter_init(&piter, &local_ext); - while(gkyl_range_iter_next(&piter)){ + while (gkyl_range_iter_next(&piter)) { long pidx = gkyl_range_idx(&local_ext, piter.idx); - const double *hamil_local = gkyl_array_cfetch(hamil,pidx); - double *alpha_surf_comp_L_local = gkyl_array_fetch(alpha_surf_comp_L,pidx); - double *alpha_surf_comp_R_local = gkyl_array_fetch(alpha_surf_comp_R,pidx); - double *sgn_alpha_surf_comp_not_used_local = gkyl_array_fetch(sgn_alpha_surf_comp_not_used,pidx); + const double *hamil_local = gkyl_array_cfetch(hamil, pidx); + double *alpha_surf_comp_L_local = gkyl_array_fetch(alpha_surf_comp_L, pidx); + double *alpha_surf_comp_R_local = gkyl_array_fetch(alpha_surf_comp_R, pidx); + double *sgn_alpha_surf_comp_not_used_local = + gkyl_array_fetch(sgn_alpha_surf_comp_not_used, pidx); if (poly_order == 1 && b_type == GKYL_BASIS_MODAL_SERENDIPITY) { - int const_sgn_alpha_surf = canonical_pb_alpha_surfx_1x1v_ser_p1(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, sgn_alpha_surf_comp_not_used_local); - int const_sgn_alpha_surf_edge = canonical_pb_alpha_edge_surfx_1x1v_ser_p1(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_R_local, sgn_alpha_surf_comp_not_used_local); - const_sgn_alpha_surf = canonical_pb_alpha_surfvx_1x1v_ser_p1(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, sgn_alpha_surf_comp_not_used_local); - } - else if (b_type == GKYL_BASIS_MODAL_SERENDIPITY) { - int const_sgn_alpha_surf = canonical_pb_alpha_surfx_1x1v_ser_p2(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, sgn_alpha_surf_comp_not_used_local); - int const_sgn_alpha_surf_edge = canonical_pb_alpha_edge_surfx_1x1v_ser_p2(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_R_local, sgn_alpha_surf_comp_not_used_local); - const_sgn_alpha_surf = canonical_pb_alpha_surfvx_1x1v_ser_p2(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, sgn_alpha_surf_comp_not_used_local); - } - else if ((b_type == GKYL_BASIS_MODAL_TENSOR) && (poly_order == 1)) { - int const_sgn_alpha_surf = canonical_pb_alpha_surfx_1x1v_tensor_p1(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, sgn_alpha_surf_comp_not_used_local); - int const_sgn_alpha_surf_edge = canonical_pb_alpha_edge_surfx_1x1v_tensor_p1(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_R_local, sgn_alpha_surf_comp_not_used_local); - const_sgn_alpha_surf = canonical_pb_alpha_surfvx_1x1v_tensor_p1(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, sgn_alpha_surf_comp_not_used_local); - } - else if ((b_type == GKYL_BASIS_MODAL_TENSOR) && (poly_order == 2)) { - int const_sgn_alpha_surf = canonical_pb_alpha_surfx_1x1v_tensor_p2(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, sgn_alpha_surf_comp_not_used_local); - int const_sgn_alpha_surf_edge = canonical_pb_alpha_edge_surfx_1x1v_tensor_p2(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_R_local, sgn_alpha_surf_comp_not_used_local); - const_sgn_alpha_surf = canonical_pb_alpha_surfvx_1x1v_tensor_p2(w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, sgn_alpha_surf_comp_not_used_local); - } - else { + int const_sgn_alpha_surf = canonical_pb_alpha_surfx_1x1v_ser_p1( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, + sgn_alpha_surf_comp_not_used_local + ); + int const_sgn_alpha_surf_edge = canonical_pb_alpha_edge_surfx_1x1v_ser_p1( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_R_local, + sgn_alpha_surf_comp_not_used_local + ); + const_sgn_alpha_surf = canonical_pb_alpha_surfvx_1x1v_ser_p1( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, + sgn_alpha_surf_comp_not_used_local + ); + } else if (b_type == GKYL_BASIS_MODAL_SERENDIPITY) { + int const_sgn_alpha_surf = canonical_pb_alpha_surfx_1x1v_ser_p2( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, + sgn_alpha_surf_comp_not_used_local + ); + int const_sgn_alpha_surf_edge = canonical_pb_alpha_edge_surfx_1x1v_ser_p2( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_R_local, + sgn_alpha_surf_comp_not_used_local + ); + const_sgn_alpha_surf = canonical_pb_alpha_surfvx_1x1v_ser_p2( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, + sgn_alpha_surf_comp_not_used_local + ); + } else if ((b_type == GKYL_BASIS_MODAL_TENSOR) && (poly_order == 1)) { + int const_sgn_alpha_surf = canonical_pb_alpha_surfx_1x1v_tensor_p1( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, + sgn_alpha_surf_comp_not_used_local + ); + int const_sgn_alpha_surf_edge = canonical_pb_alpha_edge_surfx_1x1v_tensor_p1( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_R_local, + sgn_alpha_surf_comp_not_used_local + ); + const_sgn_alpha_surf = canonical_pb_alpha_surfvx_1x1v_tensor_p1( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, + sgn_alpha_surf_comp_not_used_local + ); + } else if ((b_type == GKYL_BASIS_MODAL_TENSOR) && (poly_order == 2)) { + int const_sgn_alpha_surf = canonical_pb_alpha_surfx_1x1v_tensor_p2( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, + sgn_alpha_surf_comp_not_used_local + ); + int const_sgn_alpha_surf_edge = canonical_pb_alpha_edge_surfx_1x1v_tensor_p2( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_R_local, + sgn_alpha_surf_comp_not_used_local + ); + const_sgn_alpha_surf = canonical_pb_alpha_surfvx_1x1v_tensor_p2( + w_edge_not_used, dxv, hamil_local, alpha_surf_comp_L_local, + sgn_alpha_surf_comp_not_used_local + ); + } else { assert(false); } } - // Compare suface wise element + // Compare suface wise element // Loop over Number of surface coeff gkyl_range_iter_init(&piter, &local); int pidxl[GKYL_MAX_DIM]; - while(gkyl_range_iter_next(&piter)){ + while (gkyl_range_iter_next(&piter)) { long pidx = gkyl_range_idx(&local, piter.idx); const double *alpha_surf_comp_L_local = gkyl_array_cfetch(alpha_surf_comp_L, pidx); // Iterate in the lower direction (only conf space comparison - becuase there are no velocity space ghost cells for comparison) - for (int dir = 0; dir // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { - struct gkyl_array* a = gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -void eval_M0(double t, const double *xn, double* restrict fout, void *ctx) +void eval_M0(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 1.25; } -void eval_M1i_1v(double t, const double *xn, double* restrict fout, void *ctx) +void eval_M1i_1v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 0.5; } -void eval_M2_1v(double t, const double *xn, double* restrict fout, void *ctx) +void eval_M2_1v(double t, const double *xn, double *restrict fout, void *ctx) { double n = 1.0, vth2 = 1.0, ux = 0.5; double x = xn[0]; - fout[0] = n*vth2 + n*ux*ux; + fout[0] = n * vth2 + n * ux * ux; } -void eval_udrift_1v(double t, const double *xn, double* restrict fout, void *ctx) +void eval_udrift_1v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 0.5; } -void eval_vtsq_1v(double t, const double *xn, double* restrict fout, void *ctx) +void eval_vtsq_1v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double vtsq = 1.0; fout[0] = vtsq; } -void eval_M1i_2v(double t, const double *xn, double* restrict fout, void *ctx) +void eval_M1i_2v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 0.5; fout[1] = 0.25; + fout[0] = 0.5; + fout[1] = 0.25; } -void eval_M2_2v(double t, const double *xn, double* restrict fout, void *ctx) +void eval_M2_2v(double t, const double *xn, double *restrict fout, void *ctx) { double n = 1.0, vth2 = 1.0, ux = 0.5, uy = 0.25; double x = xn[0]; - fout[0] = 2*n*vth2 + n*(ux*ux+uy*uy); + fout[0] = 2 * n * vth2 + n * (ux * ux + uy * uy); } -void eval_udrift_2v(double t, const double *xn, double* restrict fout, void *ctx) +void eval_udrift_2v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 0.5; fout[1] = 0.25; + fout[0] = 0.5; + fout[1] = 0.25; } -void eval_vtsq_2v(double t, const double *xn, double* restrict fout, void *ctx) +void eval_vtsq_2v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double vtsq = 1.0; fout[0] = vtsq; } -void -test_1x1v(int poly_order, bool use_gpu) +void test_1x1v(int poly_order, bool use_gpu) { double lower[] = {0.1, -6.0}, upper[] = {1.0, 6.0}; int cells[] = {2, 32}; int vdim = 1, cdim = 1; - int ndim = cdim+vdim; + int ndim = cdim + vdim; double confLower[] = {lower[0]}, confUpper[] = {upper[0]}; int confCells[] = {cells[0]}; @@ -97,12 +97,12 @@ test_1x1v(int poly_order, bool use_gpu) struct gkyl_rect_grid confGrid; gkyl_rect_grid_init(&confGrid, cdim, confLower, confUpper, confCells); - struct gkyl_rect_grid vel_grid; + struct gkyl_rect_grid vel_grid; gkyl_rect_grid_init(&vel_grid, vdim, velLower, velUpper, velCells); // velocity range int velGhost[] = {0}; - struct gkyl_range velLocal, velLocal_ext; + struct gkyl_range velLocal, velLocal_ext; gkyl_create_grid_ranges(&vel_grid, velGhost, &velLocal_ext, &velLocal); // basis functions @@ -111,28 +111,28 @@ test_1x1v(int poly_order, bool use_gpu) gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); gkyl_cart_modal_serendip(&velBasis, vdim, poly_order); - int confGhost[] = { 1 }; + int confGhost[] = {1}; struct gkyl_range confLocal, confLocal_ext; // local, local-ext conf-space ranges gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); - int ghost[] = { confGhost[0], 0 }; + int ghost[] = {confGhost[0], 0}; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // create moment arrays struct gkyl_array *m0, *m1i, *m2, *moms, *moms_diag; m0 = mkarr(confBasis.num_basis, confLocal_ext.volume); - m1i = mkarr(vdim*confBasis.num_basis, confLocal_ext.volume); + m1i = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(confBasis.num_basis, confLocal_ext.volume); - moms = mkarr((vdim+2)*confBasis.num_basis, confLocal_ext.volume); - moms_diag = mkarr((vdim+2)*confBasis.num_basis, confLocal_ext.volume); + moms = mkarr((vdim + 2) * confBasis.num_basis, confLocal_ext.volume); + moms_diag = mkarr((vdim + 2) * confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, 1, eval_M0, NULL); - gkyl_proj_on_basis *proj_m1i = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, vdim, eval_M1i_1v, NULL); - gkyl_proj_on_basis *proj_m2 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order+1, 1, eval_M2_1v, NULL); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M0, NULL); + gkyl_proj_on_basis *proj_m1i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_M1i_1v, NULL); + gkyl_proj_on_basis *proj_m2 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M2_1v, NULL); gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i); @@ -141,7 +141,7 @@ test_1x1v(int poly_order, bool use_gpu) // Projection routine expects all the moments in a single array. gkyl_array_set_offset(moms, 1., m0, 0); gkyl_array_set_offset(moms, 1., m1i, confBasis.num_basis); - gkyl_array_set_offset(moms, 1., m2, (vdim+1)*confBasis.num_basis); + gkyl_array_set_offset(moms, 1., m2, (vdim + 1) * confBasis.num_basis); // create distribution function array struct gkyl_array *distf; @@ -150,57 +150,57 @@ test_1x1v(int poly_order, bool use_gpu) // projection updater to compute LTE distribution struct gkyl_vlasov_lte_proj_on_basis_inp inp_lte = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .model_id = GKYL_MODEL_DEFAULT, .mass = 1.0, - .use_gpu = false, - }; + .use_gpu = false + }; gkyl_vlasov_lte_proj_on_basis *proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_lte); gkyl_vlasov_lte_proj_on_basis_advance(proj_lte, &local, &confLocal, moms, distf); // Compute the moments of our corrected distribution function struct gkyl_vlasov_lte_moments_inp inp_mom = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .model_id = GKYL_MODEL_DEFAULT, .mass = 1.0, - .use_gpu = false, + .use_gpu = false }; - gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew( &inp_mom ); + gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew(&inp_mom); // correction updater struct gkyl_vlasov_lte_correct_inp inp = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .model_id = GKYL_MODEL_DEFAULT, .use_gpu = false, .max_iter = 100, - .eps = 1e-12, + .eps = 1e-12 }; - gkyl_vlasov_lte_correct *corr_lte = gkyl_vlasov_lte_correct_inew( &inp ); + gkyl_vlasov_lte_correct *corr_lte = gkyl_vlasov_lte_correct_inew(&inp); - // write distribution function to file + // write distribution function to file char fname[1024]; sprintf(fname, "ctest_correct_maxwellian_test_1x1v_p%d_corr_m0.gkyl", poly_order); gkyl_grid_sub_array_write(&grid, &local, 0, distf, fname); @@ -209,38 +209,41 @@ test_1x1v(int poly_order, bool use_gpu) gkyl_vlasov_lte_moments_advance(lte_moms, &local, &confLocal, distf, moms_diag); struct gkyl_array *m0_n_corr_only, *m1i_n_corr_only, *m2_n_corr_only; m0_n_corr_only = mkarr(confBasis.num_basis, confLocal_ext.volume); - m1i_n_corr_only = mkarr(vdim*confBasis.num_basis, confLocal_ext.volume); + m1i_n_corr_only = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); m2_n_corr_only = mkarr(confBasis.num_basis, confLocal_ext.volume); - gkyl_array_set_offset_range(m0_n_corr_only, 1.0, moms, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m1i_n_corr_only, 1.0, moms, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m2_n_corr_only, 1.0, moms, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m0_n_corr_only, 1.0, moms, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m1i_n_corr_only, 1.0, moms, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range( + m2_n_corr_only, 1.0, moms, (vdim + 1) * confBasis.num_basis, &confLocal + ); - struct gkyl_vlasov_lte_correct_status stat_corr = gkyl_vlasov_lte_correct_all_moments(corr_lte, - distf, moms, &local, &confLocal); + struct gkyl_vlasov_lte_correct_status stat_corr = + gkyl_vlasov_lte_correct_all_moments(corr_lte, distf, moms, &local, &confLocal); - // Moments computed from all-moment-corrected LTE distribution function + // Moments computed from all-moment-corrected LTE distribution function gkyl_vlasov_lte_moments_advance(lte_moms, &local, &confLocal, distf, moms); struct gkyl_array *m0_corr, *m1i_corr, *m2_corr; m0_corr = mkarr(confBasis.num_basis, confLocal_ext.volume); - m1i_corr = mkarr(vdim*confBasis.num_basis, confLocal_ext.volume); + m1i_corr = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); m2_corr = mkarr(confBasis.num_basis, confLocal_ext.volume); - gkyl_array_set_offset_range(m0_corr, 1.0, moms, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m1i_corr, 1.0, moms, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m2_corr, 1.0, moms, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m0_corr, 1.0, moms, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m1i_corr, 1.0, moms, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m2_corr, 1.0, moms, (vdim + 1) * confBasis.num_basis, &confLocal); - // write distribution function to file + // write distribution function to file sprintf(fname, "ctest_correct_maxwellian_test_1x1v_p%d_corr_all_moms.gkyl", poly_order); gkyl_grid_sub_array_write(&grid, &local, 0, distf, fname); - + // Compare m0 to the computed m0 (density correction only) struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &confLocal); while (gkyl_range_iter_next(&iter)) { const double *n0 = gkyl_array_cfetch(m0, gkyl_range_idx(&confLocal, iter.idx)); const double *nr = gkyl_array_cfetch(m0_n_corr_only, gkyl_range_idx(&confLocal, iter.idx)); - - for (int k=0; k // allocate array (filled with zeros) -static struct gkyl_array * -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -void -eval_M0(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M0(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 1.0; } -void -eval_M2(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M2(double t, const double *xn, double *restrict fout, void *ctx) { double T = 1.0; double x = xn[0]; fout[0] = T; } -void -eval_M1i_1v(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M1i_1v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 1.0; + fout[0] = 1.0; } -void -eval_M1i_2v(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M1i_2v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 1.0; fout[1] = 0.5; } -void -eval_M1i_3v(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M1i_3v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 1.5; - fout[1] = 1.0; + fout[0] = 1.5; + fout[1] = 1.0; fout[2] = 0.5; } -void -eval_M0_x(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M0_x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 1.1 + sin(xn[0]); } -void -eval_M1i_1v_x(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M1i_1v_x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 0.5*(sin(xn[0])); // 0.5; + fout[0] = 0.5 * (sin(xn[0])); // 0.5; } -void -eval_M2_x(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M2_x(double t, const double *xn, double *restrict fout, void *ctx) { double T = 1.0; double x = xn[0]; - fout[0] = T*(1.1 + sin(xn[0])); + fout[0] = T * (1.1 + sin(xn[0])); } -void -test_1x1v(int poly_order) +void test_1x1v(int poly_order) { double lower[] = {0.1, -10.0}, upper[] = {1.0, 10.0}; - int cells[] = {2, 32}; + int cells[] = {2, 32}; int vdim = 1, cdim = 1; int ndim = cdim + vdim; @@ -108,7 +98,7 @@ test_1x1v(int poly_order) // velocity range int velGhost[] = {0}; - struct gkyl_range velLocal, velLocal_ext; + struct gkyl_range velLocal, velLocal_ext; gkyl_create_grid_ranges(&vel_grid, velGhost, &velLocal_ext, &velLocal); // basis functions @@ -118,11 +108,11 @@ test_1x1v(int poly_order) gkyl_cart_modal_serendip(&velBasis, vdim, poly_order); int confGhost[] = {1}; - struct gkyl_range confLocal, confLocal_ext; + struct gkyl_range confLocal, confLocal_ext; gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); int ghost[] = {confGhost[0], 0}; - struct gkyl_range local, local_ext; + struct gkyl_range local, local_ext; gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // Create a copy for comparison @@ -130,27 +120,27 @@ test_1x1v(int poly_order) m0_corr = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); m1i_corr = gkyl_array_new(GKYL_DOUBLE, vdim * confBasis.num_basis, confLocal_ext.volume); m2_corr = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); - moms_corr = gkyl_array_new(GKYL_DOUBLE, (vdim+2) * confBasis.num_basis, confLocal_ext.volume); + moms_corr = gkyl_array_new(GKYL_DOUBLE, (vdim + 2) * confBasis.num_basis, confLocal_ext.volume); struct gkyl_array *m0, *m1i, *m2, *moms; m0 = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); m1i = gkyl_array_new(GKYL_DOUBLE, vdim * confBasis.num_basis, confLocal_ext.volume); m2 = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); - moms = gkyl_array_new(GKYL_DOUBLE, (vdim+2) * confBasis.num_basis, confLocal_ext.volume); + moms = gkyl_array_new(GKYL_DOUBLE, (vdim + 2) * confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M0, NULL); - gkyl_proj_on_basis *proj_m1i = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, vdim, eval_M1i_1v, NULL); - gkyl_proj_on_basis *proj_m2 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M2, NULL); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M0, NULL); + gkyl_proj_on_basis *proj_m1i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_M1i_1v, NULL); + gkyl_proj_on_basis *proj_m2 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M2, NULL); // create a copy for the correct intial value gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0_corr); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i_corr); gkyl_proj_on_basis_advance(proj_m2, 0.0, &confLocal, m2_corr); - gkyl_array_set_offset_range(moms_corr, 1.0, m0_corr, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms_corr, 1.0, m1i_corr, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms_corr, 1.0, m2_corr, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m0_corr, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m1i_corr, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m2_corr, (vdim + 1) * confBasis.num_basis, &confLocal); gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i); @@ -159,8 +149,8 @@ test_1x1v(int poly_order) // build gamma and gamma_inv struct gkyl_array *gamma = mkarr(velBasis.num_basis, velLocal.volume); struct gkyl_array *gamma_inv = mkarr(velBasis.num_basis, velLocal.volume); - struct gkyl_dg_calc_sr_vars *sr_vars = gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, - &confBasis, &velBasis, &confLocal, &velLocal, false); + struct gkyl_dg_calc_sr_vars *sr_vars = + gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, &confBasis, &velBasis, &confLocal, &velLocal, false); // Project gamma and its inverse gkyl_calc_sr_vars_init_p_vars(sr_vars, gamma, gamma_inv); // Free SR variable computation @@ -173,19 +163,19 @@ test_1x1v(int poly_order) // projection updater to compute LTE distribution struct gkyl_vlasov_lte_proj_on_basis_inp inp_lte = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, - }; + .use_gpu = false + }; gkyl_vlasov_lte_proj_on_basis *proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_lte); // Project LTE distribution function (and correct its density internally) gkyl_vlasov_lte_proj_on_basis_advance(proj_lte, &local, &confLocal, moms_corr, distf); @@ -193,11 +183,11 @@ test_1x1v(int poly_order) // Create a MJ with corrected moments struct gkyl_vlasov_lte_correct_inp inp_corr = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, @@ -206,10 +196,10 @@ test_1x1v(int poly_order) .model_id = GKYL_MODEL_SR, .use_gpu = false, .max_iter = 100, - .eps = 1e-12, + .eps = 1e-12 }; - gkyl_vlasov_lte_correct *corr_mj = gkyl_vlasov_lte_correct_inew( &inp_corr ); - // Correct the other moments (V_drift, T/m) + gkyl_vlasov_lte_correct *corr_mj = gkyl_vlasov_lte_correct_inew(&inp_corr); + // Correct the other moments (V_drift, T/m) gkyl_vlasov_lte_correct_all_moments(corr_mj, distf, moms_corr, &local, &confLocal); gkyl_vlasov_lte_correct_release(corr_mj); @@ -221,29 +211,29 @@ test_1x1v(int poly_order) // Correct the distribution function struct gkyl_vlasov_lte_moments_inp inp_mom = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, + .use_gpu = false }; - gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew( &inp_mom ); + gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew(&inp_mom); gkyl_vlasov_lte_moments_advance(lte_moms, &local, &confLocal, distf, moms); - gkyl_array_set_offset_range(m0, 1.0, moms, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m1i, 1.0, moms, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m2, 1.0, moms, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m0, 1.0, moms, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m1i, 1.0, moms, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m2, 1.0, moms, (vdim + 1) * confBasis.num_basis, &confLocal); // values to compare at index (1, 17) [remember, lower-left index is (1,1)] - double p2_vals[] = {2.7845923966306263e-01, 4.6204926597763572e-17, - 6.5920727847853647e-02, -1.4768663476574924e-19, -3.3457863588588799e-17, - 2.5460491687342435e-03, -4.0874057255360184e-17, -1.0795797155980702e-17}; + double p2_vals[] = {2.7845923966306263e-01, 4.6204926597763572e-17, 6.5920727847853647e-02, + -1.4768663476574924e-19, -3.3457863588588799e-17, 2.5460491687342435e-03, + -4.0874057255360184e-17, -1.0795797155980702e-17}; const double *fv = gkyl_array_cfetch(distf, gkyl_range_idx(&local_ext, (int[2]){1, 16})); @@ -273,9 +263,7 @@ test_1x1v(int poly_order) gkyl_array_release(gamma_inv); } - -void -test_1x1v_spatially_varied(int poly_order) +void test_1x1v_spatially_varied(int poly_order) { double lower[] = {0.0, -10.0}, upper[] = {10.0, 10.0}; int cells[] = {10, 32}; // 1001 @@ -297,7 +285,7 @@ test_1x1v_spatially_varied(int poly_order) // velocity range int velGhost[] = {0}; - struct gkyl_range velLocal, velLocal_ext; + struct gkyl_range velLocal, velLocal_ext; gkyl_create_grid_ranges(&vel_grid, velGhost, &velLocal_ext, &velLocal); // basis functions @@ -307,11 +295,11 @@ test_1x1v_spatially_varied(int poly_order) gkyl_cart_modal_serendip(&velBasis, vdim, poly_order); int confGhost[] = {1}; - struct gkyl_range confLocal, confLocal_ext; + struct gkyl_range confLocal, confLocal_ext; gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); int ghost[] = {confGhost[0], 0}; - struct gkyl_range local, local_ext; + struct gkyl_range local, local_ext; gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // Create a copy for comparison @@ -319,27 +307,27 @@ test_1x1v_spatially_varied(int poly_order) m0_corr = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); m1i_corr = gkyl_array_new(GKYL_DOUBLE, vdim * confBasis.num_basis, confLocal_ext.volume); m2_corr = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); - moms_corr = gkyl_array_new(GKYL_DOUBLE, (vdim+2) * confBasis.num_basis, confLocal_ext.volume); + moms_corr = gkyl_array_new(GKYL_DOUBLE, (vdim + 2) * confBasis.num_basis, confLocal_ext.volume); struct gkyl_array *m0, *m1i, *m2, *moms; m0 = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); m1i = gkyl_array_new(GKYL_DOUBLE, vdim * confBasis.num_basis, confLocal_ext.volume); m2 = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); - moms = gkyl_array_new(GKYL_DOUBLE, (vdim+2) * confBasis.num_basis, confLocal_ext.volume); + moms = gkyl_array_new(GKYL_DOUBLE, (vdim + 2) * confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M0_x, NULL); - gkyl_proj_on_basis *proj_m1i = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, vdim, eval_M1i_1v_x, NULL); - gkyl_proj_on_basis *proj_m2 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M2_x, NULL); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M0_x, NULL); + gkyl_proj_on_basis *proj_m1i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_M1i_1v_x, NULL); + gkyl_proj_on_basis *proj_m2 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M2_x, NULL); // create a copy for the correct intial value gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0_corr); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i_corr); gkyl_proj_on_basis_advance(proj_m2, 0.0, &confLocal, m2_corr); - gkyl_array_set_offset_range(moms_corr, 1.0, m0_corr, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms_corr, 1.0, m1i_corr, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms_corr, 1.0, m2_corr, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m0_corr, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m1i_corr, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m2_corr, (vdim + 1) * confBasis.num_basis, &confLocal); gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i); @@ -348,8 +336,8 @@ test_1x1v_spatially_varied(int poly_order) // build gamma and gamma_inv struct gkyl_array *gamma = mkarr(velBasis.num_basis, velLocal.volume); struct gkyl_array *gamma_inv = mkarr(velBasis.num_basis, velLocal.volume); - struct gkyl_dg_calc_sr_vars *sr_vars = gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, - &confBasis, &velBasis, &confLocal, &velLocal, false); + struct gkyl_dg_calc_sr_vars *sr_vars = + gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, &confBasis, &velBasis, &confLocal, &velLocal, false); // Project gamma and its inverse gkyl_calc_sr_vars_init_p_vars(sr_vars, gamma, gamma_inv); // Free SR variable computation @@ -362,19 +350,19 @@ test_1x1v_spatially_varied(int poly_order) // projection updater to compute LTE distribution struct gkyl_vlasov_lte_proj_on_basis_inp inp_lte = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, - }; + .use_gpu = false + }; gkyl_vlasov_lte_proj_on_basis *proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_lte); // Project LTE distribution function (and correct its density internally) gkyl_vlasov_lte_proj_on_basis_advance(proj_lte, &local, &confLocal, moms_corr, distf); @@ -382,11 +370,11 @@ test_1x1v_spatially_varied(int poly_order) // Create a MJ with corrected moments struct gkyl_vlasov_lte_correct_inp inp_corr = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, @@ -395,9 +383,9 @@ test_1x1v_spatially_varied(int poly_order) .model_id = GKYL_MODEL_SR, .use_gpu = false, .max_iter = 100, - .eps = 1e-12, + .eps = 1e-12 }; - gkyl_vlasov_lte_correct *corr_mj = gkyl_vlasov_lte_correct_inew( &inp_corr ); + gkyl_vlasov_lte_correct *corr_mj = gkyl_vlasov_lte_correct_inew(&inp_corr); // Correct the other moments (V_drift, T/m) gkyl_vlasov_lte_correct_all_moments(corr_mj, distf, moms_corr, &local, &confLocal); gkyl_vlasov_lte_correct_release(corr_mj); @@ -410,24 +398,24 @@ test_1x1v_spatially_varied(int poly_order) // Correct the distribution function struct gkyl_vlasov_lte_moments_inp inp_mom = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, + .use_gpu = false }; - gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew( &inp_mom ); + gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew(&inp_mom); gkyl_vlasov_lte_moments_advance(lte_moms, &local, &confLocal, distf, moms); - gkyl_array_set_offset_range(m0, 1.0, moms, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m1i, 1.0, moms, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m2, 1.0, moms, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m0, 1.0, moms, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m1i, 1.0, moms, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m2, 1.0, moms, (vdim + 1) * confBasis.num_basis, &confLocal); // Write the output (moments) //sprintf(fname, "ctest_correct_mj_integrated_1x1v_p%d_x_n_corr.gkyl", poly_order); @@ -437,7 +425,6 @@ test_1x1v_spatially_varied(int poly_order) //sprintf(fname, "ctest_correct_mj_integrated_1x1v_p%d_x_T_corr.gkyl", poly_order); //gkyl_grid_sub_array_write(&confGrid,&confLocal,0,m2_corr,fname); - // Write the output (moments) //sprintf(fname, "ctest_correct_mj_integrated_1x1v_p%d_x_n.gkyl", poly_order); //gkyl_grid_sub_array_write(&confGrid,&confLocal,0,m0,fname); @@ -446,24 +433,23 @@ test_1x1v_spatially_varied(int poly_order) //sprintf(fname, "ctest_correct_mj_integrated_1x1v_p%d_x_T.gkyl", poly_order); //gkyl_grid_sub_array_write(&confGrid,&confLocal,0,m2,fname); - // values to compare at index (1, 17) [remember, lower-left index is (1,1)] - double m0_vals[] = {2.2057459659974716e+00,3.4938172762332936e-01,-2.4953670224477906e-02}; - double m1i_vals[] = {3.2505552369353341e-01,1.7469086381166479e-01,-1.2476835112239079e-02}; - double m2_vals[] = {2.2057459659974712e+00,3.4938172762332981e-01,-2.4953670224477753e-02}; - + double m0_vals[] = {2.2057459659974716e+00, 3.4938172762332936e-01, -2.4953670224477906e-02}; + double m1i_vals[] = {3.2505552369353341e-01, 1.7469086381166479e-01, -1.2476835112239079e-02}; + double m2_vals[] = {2.2057459659974712e+00, 3.4938172762332981e-01, -2.4953670224477753e-02}; //const double *fv = gkyl_array_cfetch(distf, gkyl_range_idx(&local_ext, (int[2]){1, 16})); const double *m0_fixed = gkyl_array_cfetch(m0, gkyl_range_idx(&confLocal_ext, (int[1]){1})); const double *m1i_fixed = gkyl_array_cfetch(m1i, gkyl_range_idx(&confLocal_ext, (int[1]){1})); const double *m2_fixed = gkyl_array_cfetch(m2, gkyl_range_idx(&confLocal_ext, (int[1]){1})); - if (poly_order == 2) - for (int i = 0; i < confBasis.num_basis; ++i){ + if (poly_order == 2) { + for (int i = 0; i < confBasis.num_basis; ++i) { TEST_CHECK(gkyl_compare_double(m0_vals[i], m0_fixed[i], 1e-12)); TEST_CHECK(gkyl_compare_double(m1i_vals[i], m1i_fixed[i], 1e-12)); TEST_CHECK(gkyl_compare_double(m2_vals[i], m2_fixed[i], 1e-12)); } + } // release memory for moment data object gkyl_array_release(m0); @@ -484,9 +470,7 @@ test_1x1v_spatially_varied(int poly_order) gkyl_array_release(gamma_inv); } - -void -test_1x2v(int poly_order) +void test_1x2v(int poly_order) { double lower[] = {0.1, -10.0, -10.0}, upper[] = {1.0, 10.0, 10.0}; int cells[] = {2, 32, 32}; @@ -508,7 +492,7 @@ test_1x2v(int poly_order) // velocity range int velGhost[] = {0, 0}; - struct gkyl_range velLocal, velLocal_ext; + struct gkyl_range velLocal, velLocal_ext; gkyl_create_grid_ranges(&vel_grid, velGhost, &velLocal_ext, &velLocal); // basis functions @@ -518,11 +502,11 @@ test_1x2v(int poly_order) gkyl_cart_modal_serendip(&velBasis, vdim, poly_order); int confGhost[] = {1}; - struct gkyl_range confLocal, confLocal_ext; + struct gkyl_range confLocal, confLocal_ext; gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); int ghost[] = {confGhost[0], 0, 0}; - struct gkyl_range local, local_ext; + struct gkyl_range local, local_ext; gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // Create a copy for comparison @@ -530,27 +514,27 @@ test_1x2v(int poly_order) m0_corr = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); m1i_corr = gkyl_array_new(GKYL_DOUBLE, vdim * confBasis.num_basis, confLocal_ext.volume); m2_corr = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); - moms_corr = gkyl_array_new(GKYL_DOUBLE, (vdim+2) * confBasis.num_basis, confLocal_ext.volume); + moms_corr = gkyl_array_new(GKYL_DOUBLE, (vdim + 2) * confBasis.num_basis, confLocal_ext.volume); struct gkyl_array *m0, *m1i, *m2, *moms; m0 = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); m1i = gkyl_array_new(GKYL_DOUBLE, vdim * confBasis.num_basis, confLocal_ext.volume); m2 = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); - moms = gkyl_array_new(GKYL_DOUBLE, (vdim+2) * confBasis.num_basis, confLocal_ext.volume); + moms = gkyl_array_new(GKYL_DOUBLE, (vdim + 2) * confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M0, NULL); - gkyl_proj_on_basis *proj_m1i = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, vdim, eval_M1i_2v, NULL); - gkyl_proj_on_basis *proj_m2 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M2, NULL); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M0, NULL); + gkyl_proj_on_basis *proj_m1i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_M1i_2v, NULL); + gkyl_proj_on_basis *proj_m2 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M2, NULL); // create a copy for the correct intial value gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0_corr); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i_corr); gkyl_proj_on_basis_advance(proj_m2, 0.0, &confLocal, m2_corr); - gkyl_array_set_offset_range(moms_corr, 1.0, m0_corr, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms_corr, 1.0, m1i_corr, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms_corr, 1.0, m2_corr, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m0_corr, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m1i_corr, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m2_corr, (vdim + 1) * confBasis.num_basis, &confLocal); gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i); @@ -559,8 +543,8 @@ test_1x2v(int poly_order) // build gamma and gamma_inv struct gkyl_array *gamma = mkarr(velBasis.num_basis, velLocal.volume); struct gkyl_array *gamma_inv = mkarr(velBasis.num_basis, velLocal.volume); - struct gkyl_dg_calc_sr_vars *sr_vars = gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, - &confBasis, &velBasis, &confLocal, &velLocal, false); + struct gkyl_dg_calc_sr_vars *sr_vars = + gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, &confBasis, &velBasis, &confLocal, &velLocal, false); // Project gamma and its inverse gkyl_calc_sr_vars_init_p_vars(sr_vars, gamma, gamma_inv); // Free SR variable computation @@ -573,19 +557,19 @@ test_1x2v(int poly_order) // projection updater to compute LTE distribution struct gkyl_vlasov_lte_proj_on_basis_inp inp_lte = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, - }; + .use_gpu = false + }; gkyl_vlasov_lte_proj_on_basis *proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_lte); // Project LTE distribution function (and correct its density internally) gkyl_vlasov_lte_proj_on_basis_advance(proj_lte, &local, &confLocal, moms_corr, distf); @@ -593,11 +577,11 @@ test_1x2v(int poly_order) // Create a MJ with corrected moments struct gkyl_vlasov_lte_correct_inp inp_corr = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, @@ -606,9 +590,9 @@ test_1x2v(int poly_order) .model_id = GKYL_MODEL_SR, .use_gpu = false, .max_iter = 100, - .eps = 1e-12, + .eps = 1e-12 }; - gkyl_vlasov_lte_correct *corr_mj = gkyl_vlasov_lte_correct_inew( &inp_corr ); + gkyl_vlasov_lte_correct *corr_mj = gkyl_vlasov_lte_correct_inew(&inp_corr); // Correct the other moments (V_drift, T/m) gkyl_vlasov_lte_correct_all_moments(corr_mj, distf, moms_corr, &local, &confLocal); gkyl_vlasov_lte_correct_release(corr_mj); @@ -616,24 +600,24 @@ test_1x2v(int poly_order) // Correct the distribution function struct gkyl_vlasov_lte_moments_inp inp_mom = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, + .use_gpu = false }; - gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew( &inp_mom ); + gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew(&inp_mom); gkyl_vlasov_lte_moments_advance(lte_moms, &local, &confLocal, distf, moms); - gkyl_array_set_offset_range(m0, 1.0, moms, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m1i, 1.0, moms, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m2, 1.0, moms, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m0, 1.0, moms, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m1i, 1.0, moms, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m2, 1.0, moms, (vdim + 1) * confBasis.num_basis, &confLocal); // Write the output char fname[1024]; @@ -641,12 +625,13 @@ test_1x2v(int poly_order) gkyl_grid_sub_array_write(&grid, &local, 0, distf, fname); // values to compare at index (1, 17) [remember, lower-left index is (1,1)] - double p2_vals[] = {7.1154795741657104e-02, -1.0154349268741242e-17, 1.7043680613403746e-02, - 1.0985977050895525e-02, -7.6488419515851888e-18, -7.8668793275235743e-18, 2.8173732360475563e-03, - -1.2268169102706324e-17, 6.6921571942179570e-04, -4.4309884559864081e-04, -4.2230625985903307e-18, - -1.0393016114178111e-17, -5.8390877219590108e-19, -1.0792789352242940e-17, 1.0442989813709548e-04, - 5.9309279220864833e-19, -1.1960215598429369e-04, -2.6085561563408531e-18, 2.0845874350775922e-18, - -3.4160776312939708e-19}; + double p2_vals[] = {7.1154795741657104e-02, -1.0154349268741242e-17, 1.7043680613403746e-02, + 1.0985977050895525e-02, -7.6488419515851888e-18, -7.8668793275235743e-18, + 2.8173732360475563e-03, -1.2268169102706324e-17, 6.6921571942179570e-04, + -4.4309884559864081e-04, -4.2230625985903307e-18, -1.0393016114178111e-17, + -5.8390877219590108e-19, -1.0792789352242940e-17, 1.0442989813709548e-04, + 5.9309279220864833e-19, -1.1960215598429369e-04, -2.6085561563408531e-18, + 2.0845874350775922e-18, -3.4160776312939708e-19}; const double *fv = gkyl_array_cfetch(distf, gkyl_range_idx(&local_ext, (int[3]){1, 16, 16})); @@ -676,8 +661,7 @@ test_1x2v(int poly_order) gkyl_array_release(gamma_inv); } -void -test_1x3v(int poly_order) +void test_1x3v(int poly_order) { double lower[] = {0.1, -10.0, -10.0, -10.0}, upper[] = {1.0, 10.0, 10.0, 10.0}; int cells[] = {2, 16, 16, 16}; @@ -699,7 +683,7 @@ test_1x3v(int poly_order) // velocity range int velGhost[] = {0, 0, 0}; - struct gkyl_range velLocal, velLocal_ext; + struct gkyl_range velLocal, velLocal_ext; gkyl_create_grid_ranges(&vel_grid, velGhost, &velLocal_ext, &velLocal); // basis functions @@ -709,11 +693,11 @@ test_1x3v(int poly_order) gkyl_cart_modal_serendip(&velBasis, vdim, poly_order); int confGhost[] = {1}; - struct gkyl_range confLocal, confLocal_ext; + struct gkyl_range confLocal, confLocal_ext; gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); int ghost[] = {confGhost[0], 0, 0, 0}; - struct gkyl_range local, local_ext; + struct gkyl_range local, local_ext; gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); // Create a copy for comparison @@ -721,27 +705,27 @@ test_1x3v(int poly_order) m0_corr = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); m1i_corr = gkyl_array_new(GKYL_DOUBLE, vdim * confBasis.num_basis, confLocal_ext.volume); m2_corr = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); - moms_corr = gkyl_array_new(GKYL_DOUBLE, (vdim+2) * confBasis.num_basis, confLocal_ext.volume); + moms_corr = gkyl_array_new(GKYL_DOUBLE, (vdim + 2) * confBasis.num_basis, confLocal_ext.volume); struct gkyl_array *m0, *m1i, *m2, *moms; m0 = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); m1i = gkyl_array_new(GKYL_DOUBLE, vdim * confBasis.num_basis, confLocal_ext.volume); m2 = gkyl_array_new(GKYL_DOUBLE, confBasis.num_basis, confLocal_ext.volume); - moms = gkyl_array_new(GKYL_DOUBLE, (vdim+2) * confBasis.num_basis, confLocal_ext.volume); + moms = gkyl_array_new(GKYL_DOUBLE, (vdim + 2) * confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M0, NULL); - gkyl_proj_on_basis *proj_m1i = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, vdim, eval_M1i_3v, NULL); - gkyl_proj_on_basis *proj_m2 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M2, NULL); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M0, NULL); + gkyl_proj_on_basis *proj_m1i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_M1i_3v, NULL); + gkyl_proj_on_basis *proj_m2 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M2, NULL); // create a copy for the correct intial value gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0_corr); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i_corr); gkyl_proj_on_basis_advance(proj_m2, 0.0, &confLocal, m2_corr); - gkyl_array_set_offset_range(moms_corr, 1.0, m0_corr, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms_corr, 1.0, m1i_corr, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms_corr, 1.0, m2_corr, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m0_corr, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m1i_corr, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms_corr, 1.0, m2_corr, (vdim + 1) * confBasis.num_basis, &confLocal); gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i); @@ -750,8 +734,8 @@ test_1x3v(int poly_order) // build gamma and gamma_inv struct gkyl_array *gamma = mkarr(velBasis.num_basis, velLocal.volume); struct gkyl_array *gamma_inv = mkarr(velBasis.num_basis, velLocal.volume); - struct gkyl_dg_calc_sr_vars *sr_vars = gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, - &confBasis, &velBasis, &confLocal, &velLocal, false); + struct gkyl_dg_calc_sr_vars *sr_vars = + gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, &confBasis, &velBasis, &confLocal, &velLocal, false); // Project gamma and its inverse gkyl_calc_sr_vars_init_p_vars(sr_vars, gamma, gamma_inv); // Free SR variable computation @@ -764,19 +748,19 @@ test_1x3v(int poly_order) // projection updater to compute LTE distribution struct gkyl_vlasov_lte_proj_on_basis_inp inp_lte = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, - }; + .use_gpu = false + }; gkyl_vlasov_lte_proj_on_basis *proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_lte); // Project LTE distribution function (and correct its density internally) gkyl_vlasov_lte_proj_on_basis_advance(proj_lte, &local, &confLocal, moms_corr, distf); @@ -784,11 +768,11 @@ test_1x3v(int poly_order) // Create a MJ with corrected moments struct gkyl_vlasov_lte_correct_inp inp_corr = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, @@ -797,9 +781,9 @@ test_1x3v(int poly_order) .model_id = GKYL_MODEL_SR, .use_gpu = false, .max_iter = 100, - .eps = 1e-12, + .eps = 1e-12 }; - gkyl_vlasov_lte_correct *corr_mj = gkyl_vlasov_lte_correct_inew( &inp_corr ); + gkyl_vlasov_lte_correct *corr_mj = gkyl_vlasov_lte_correct_inew(&inp_corr); // Correct the other moments (V_drift, T/m) gkyl_vlasov_lte_correct_all_moments(corr_mj, distf, moms_corr, &local, &confLocal); gkyl_vlasov_lte_correct_release(corr_mj); @@ -807,24 +791,24 @@ test_1x3v(int poly_order) // Correct the distribution function struct gkyl_vlasov_lte_moments_inp inp_mom = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, + .use_gpu = false }; - gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew( &inp_mom ); + gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew(&inp_mom); gkyl_vlasov_lte_moments_advance(lte_moms, &local, &confLocal, distf, moms); - gkyl_array_set_offset_range(m0, 1.0, moms, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m1i, 1.0, moms, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m2, 1.0, moms, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m0, 1.0, moms, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m1i, 1.0, moms, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m2, 1.0, moms, (vdim + 1) * confBasis.num_basis, &confLocal); // Write the output char fname[1024]; @@ -832,19 +816,22 @@ test_1x3v(int poly_order) gkyl_grid_sub_array_write(&grid, &local, 0, distf, fname); // values to compare at index (1, 17) [remember, lower-left index is (1,1)] - double p2_vals[] = {2.3681169627173117e-03, -1.4446897638564469e-19, 1.7212114821089531e-03, - 1.4278819468396819e-03, 1.1009127860830206e-03, -1.3416643175438523e-20, -9.1242971227460240e-21, - 1.0665480449733901e-03, 9.1027098303971133e-20, 8.3350273031015259e-04, 7.0324247191191436e-04, - -4.4239730499907700e-19, 4.8462190085462665e-04, 2.7916039109363608e-04, 9.5955866471644934e-05, - 2.8545136484013421e-20, 3.5931632283878487e-21, 7.0377414655311627e-20, 5.4868903058922895e-04, - -2.4033547244859593e-19, -4.3147003734719234e-20, -1.1369323846038000e-19, 3.1070439565220937e-04, - -3.6244873179843119e-21, 2.1725375592137358e-04, -2.5466173336449186e-19, 2.4678946252732544e-04, - 1.4954398636806508e-04, 1.3237463325222323e-20, 8.1278508031050744e-05, 7.1527130914181915e-05, - -1.6410396660305442e-20, -6.0143678114279295e-20, -2.9118247539011877e-20, -2.7750766817365425e-20, - -1.0216466400671430e-19, -9.9249885235718083e-21, -1.7576662987358121e-19, 1.6898546616575218e-04, - 9.7560025734548306e-21, 1.2228452029340925e-04, -1.1579931030235590e-20, -1.1437237301704353e-20, - 6.2517215908454443e-05, -3.7022575562915509e-19, -2.1532599752429503e-20, -2.0849216060814057e-20, - 1.6541329748965388e-20}; + double p2_vals[] = {2.3681169627173117e-03, -1.4446897638564469e-19, 1.7212114821089531e-03, + 1.4278819468396819e-03, 1.1009127860830206e-03, -1.3416643175438523e-20, + -9.1242971227460240e-21, 1.0665480449733901e-03, 9.1027098303971133e-20, + 8.3350273031015259e-04, 7.0324247191191436e-04, -4.4239730499907700e-19, + 4.8462190085462665e-04, 2.7916039109363608e-04, 9.5955866471644934e-05, + 2.8545136484013421e-20, 3.5931632283878487e-21, 7.0377414655311627e-20, + 5.4868903058922895e-04, -2.4033547244859593e-19, -4.3147003734719234e-20, + -1.1369323846038000e-19, 3.1070439565220937e-04, -3.6244873179843119e-21, + 2.1725375592137358e-04, -2.5466173336449186e-19, 2.4678946252732544e-04, + 1.4954398636806508e-04, 1.3237463325222323e-20, 8.1278508031050744e-05, + 7.1527130914181915e-05, -1.6410396660305442e-20, -6.0143678114279295e-20, + -2.9118247539011877e-20, -2.7750766817365425e-20, -1.0216466400671430e-19, + -9.9249885235718083e-21, -1.7576662987358121e-19, 1.6898546616575218e-04, + 9.7560025734548306e-21, 1.2228452029340925e-04, -1.1579931030235590e-20, + -1.1437237301704353e-20, 6.2517215908454443e-05, -3.7022575562915509e-19, + -2.1532599752429503e-20, -2.0849216060814057e-20, 1.6541329748965388e-20}; const double *fv = gkyl_array_cfetch(distf, gkyl_range_idx(&local_ext, (int[4]){1, 8, 8, 8})); @@ -875,15 +862,28 @@ test_1x3v(int poly_order) } // special note, the p1 basis does not function -void test_correct_mj_integrated_1x1v_p2_ho() { test_1x1v(2); } -void test_correct_mj_integrated_1x1v_p2_spatially_varied_ho() { test_1x1v_spatially_varied(2); } -void test_correct_mj_integrated_1x2v_p2_ho() { test_1x2v(2); } -void test_correct_mj_integrated_1x3v_p2_ho() { test_1x3v(2); } +void test_correct_mj_integrated_1x1v_p2_ho() +{ + test_1x1v(2); +} +void test_correct_mj_integrated_1x1v_p2_spatially_varied_ho() +{ + test_1x1v_spatially_varied(2); +} +void test_correct_mj_integrated_1x2v_p2_ho() +{ + test_1x2v(2); +} +void test_correct_mj_integrated_1x3v_p2_ho() +{ + test_1x3v(2); +} TEST_LIST = { {"test_correct_mj_integrated_1x1v_p2_ho", test_correct_mj_integrated_1x1v_p2_ho}, - {"test_correct_mj_integrated_1x1v_p2_spatially_varied_ho", test_correct_mj_integrated_1x1v_p2_spatially_varied_ho}, + {"test_correct_mj_integrated_1x1v_p2_spatially_varied_ho", + test_correct_mj_integrated_1x1v_p2_spatially_varied_ho}, {"test_correct_mj_integrated_1x2v_p2_ho", test_correct_mj_integrated_1x2v_p2_ho}, {"test_correct_mj_integrated_1x3v_p2_ho", test_correct_mj_integrated_1x3v_p2_ho}, - {NULL, NULL}, + {NULL, NULL} }; diff --git a/vlasov/unit/ctest_dg_em_vars.c b/vlasov/unit/ctest_dg_em_vars.c index adc451dbf3..23e20bf113 100644 --- a/vlasov/unit/ctest_dg_em_vars.c +++ b/vlasov/unit/ctest_dg_em_vars.c @@ -18,25 +18,23 @@ #include // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { - struct gkyl_array* a = gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -static struct gkyl_array* -mk_int_arr(long nc, long size) +static struct gkyl_array *mk_int_arr(long nc, long size) { - struct gkyl_array* a = gkyl_array_new(GKYL_INT, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_INT, nc, size); return a; } -void eval_field_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_field_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - double Lx = 2.0*M_PI; - double kx = 2.0*M_PI/Lx; + double Lx = 2.0 * M_PI; + double kx = 2.0 * M_PI / Lx; pcg64_random_t rng = gkyl_pcg64_init(0); // RNG for use in IC @@ -46,11 +44,15 @@ void eval_field_1x(double t, const double *xn, double* restrict fout, void *ctx) double Bx = 1.0; double By = 0.0; double Bz = 0.0; - for (int i=0; i<4; ++i) { - Ey += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - Ez += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - By += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - Bz += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); + for (int i = 0; i < 4; ++i) { + Ey += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + Ez += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + By += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + Bz += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); } fout[0] = Ex; @@ -63,11 +65,11 @@ void eval_field_1x(double t, const double *xn, double* restrict fout, void *ctx) fout[7] = 0.0; } -void eval_analytic_bvar_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_analytic_bvar_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - double Lx = 2.0*M_PI; - double kx = 2.0*M_PI/Lx; + double Lx = 2.0 * M_PI; + double kx = 2.0 * M_PI / Lx; pcg64_random_t rng = gkyl_pcg64_init(0); // RNG for use in IC @@ -77,38 +79,45 @@ void eval_analytic_bvar_1x(double t, const double *xn, double* restrict fout, vo double Bx = 1.0; double By = 0.0; double Bz = 0.0; - for (int i=0; i<4; ++i) { - Ey += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - Ez += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - By += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - Bz += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); + for (int i = 0; i < 4; ++i) { + Ey += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + Ez += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + By += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + Bz += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); } - double magB2 = Bx*Bx + By*By + Bz*Bz; - double bxbx = Bx*Bx/magB2; - double bxby = Bx*By/magB2; - double bxbz = Bx*Bz/magB2; - double byby = By*By/magB2; - double bybz = By*Bz/magB2; - double bzbz = Bz*Bz/magB2; + double magB2 = Bx * Bx + By * By + Bz * Bz; + double bxbx = Bx * Bx / magB2; + double bxby = Bx * By / magB2; + double bxbz = Bx * Bz / magB2; + double byby = By * By / magB2; + double bybz = By * Bz / magB2; + double bzbz = Bz * Bz / magB2; double bx = 0.0; double by = 0.0; double bz = 0.0; - if (Bx < 0.0) + if (Bx < 0.0) { bx = -sqrt(bxbx); - else + } else { bx = sqrt(bxbx); + } - if (By < 0.0) + if (By < 0.0) { by = -sqrt(byby); - else + } else { by = sqrt(byby); + } - if (Bz < 0.0) + if (Bz < 0.0) { bz = -sqrt(bzbz); - else - bz = sqrt(bzbz); + } else { + bz = sqrt(bzbz); + } fout[0] = bx; fout[1] = by; @@ -121,11 +130,11 @@ void eval_analytic_bvar_1x(double t, const double *xn, double* restrict fout, vo fout[8] = bzbz; } -void eval_analytic_ExB_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_analytic_ExB_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - double Lx = 2.0*M_PI; - double kx = 2.0*M_PI/Lx; + double Lx = 2.0 * M_PI; + double kx = 2.0 * M_PI / Lx; pcg64_random_t rng = gkyl_pcg64_init(0); // RNG for use in IC @@ -135,31 +144,35 @@ void eval_analytic_ExB_1x(double t, const double *xn, double* restrict fout, voi double Bx = 1.0; double By = 0.0; double Bz = 0.0; - for (int i=0; i<4; ++i) { - Ey += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - Ez += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - By += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - Bz += gkyl_pcg64_rand_double(&rng)*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); + for (int i = 0; i < 4; ++i) { + Ey += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + Ez += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + By += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + Bz += + gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); } - double magB2 = Bx*Bx + By*By + Bz*Bz; - double num_ExB_x = Ey*Bz - Ez*By; - double num_ExB_y = Ez*Bx - Ex*Bz; - double num_ExB_z = Ex*By - Ey*Bx; + double magB2 = Bx * Bx + By * By + Bz * Bz; + double num_ExB_x = Ey * Bz - Ez * By; + double num_ExB_y = Ez * Bx - Ex * Bz; + double num_ExB_z = Ex * By - Ey * Bx; - fout[0] = num_ExB_x/magB2; - fout[1] = num_ExB_y/magB2; - fout[2] = num_ExB_z/magB2; + fout[0] = num_ExB_x / magB2; + fout[1] = num_ExB_y / magB2; + fout[2] = num_ExB_z / magB2; } -void eval_field_2x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_field_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double y = xn[1]; - double Lx = 2.0*M_PI; - double Ly = 2.0*M_PI; - double kx = 2.0*M_PI/Lx; - double ky = 2.0*M_PI/Ly; + double Lx = 2.0 * M_PI; + double Ly = 2.0 * M_PI; + double kx = 2.0 * M_PI / Lx; + double ky = 2.0 * M_PI / Ly; pcg64_random_t rng = gkyl_pcg64_init(0); // RNG for use in IC @@ -170,17 +183,25 @@ void eval_field_2x(double t, const double *xn, double* restrict fout, void *ctx) double By = 0.0; double Bz = 0.0; double rand_amp, rand_phase_x, rand_phase_y; - for (int i=0; i<4; ++i) { - for (int j=0; j<4; ++j) { + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { rand_amp = gkyl_pcg64_rand_double(&rng); rand_phase_x = gkyl_pcg64_rand_double(&rng); rand_phase_y = gkyl_pcg64_rand_double(&rng); - Ex += rand_amp*j*ky*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y); - Ey += -rand_amp*i*kx*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y); - Ez += gkyl_pcg64_rand_double(&rng)*j*ky*i*kx*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng))*cos(j*ky*y + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - Bx += rand_amp*j*ky*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y); - By += -rand_amp*i*kx*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y); - Bz += gkyl_pcg64_rand_double(&rng)*j*ky*i*kx*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng))*cos(j*ky*y + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); + Ex += rand_amp * j * ky * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y); + Ey += -rand_amp * i * kx * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y); + Ez += gkyl_pcg64_rand_double(&rng) * j * ky * i * kx * + sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)) * + cos(j * ky * y + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + Bx += rand_amp * j * ky * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y); + By += -rand_amp * i * kx * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y); + Bz += gkyl_pcg64_rand_double(&rng) * j * ky * i * kx * + sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)) * + cos(j * ky * y + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); } } @@ -194,14 +215,14 @@ void eval_field_2x(double t, const double *xn, double* restrict fout, void *ctx) fout[7] = 0.0; } -void eval_analytic_bvar_2x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_analytic_bvar_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double y = xn[1]; - double Lx = 2.0*M_PI; - double Ly = 2.0*M_PI; - double kx = 2.0*M_PI/Lx; - double ky = 2.0*M_PI/Ly; + double Lx = 2.0 * M_PI; + double Ly = 2.0 * M_PI; + double kx = 2.0 * M_PI / Lx; + double ky = 2.0 * M_PI / Ly; pcg64_random_t rng = gkyl_pcg64_init(0); // RNG for use in IC @@ -212,45 +233,56 @@ void eval_analytic_bvar_2x(double t, const double *xn, double* restrict fout, vo double By = 0.0; double Bz = 0.0; double rand_amp, rand_phase_x, rand_phase_y; - for (int i=0; i<4; ++i) { - for (int j=0; j<4; ++j) { + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { rand_amp = gkyl_pcg64_rand_double(&rng); rand_phase_x = gkyl_pcg64_rand_double(&rng); rand_phase_y = gkyl_pcg64_rand_double(&rng); - Ex += rand_amp*j*ky*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y); - Ey += -rand_amp*i*kx*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y); - Ez += gkyl_pcg64_rand_double(&rng)*j*ky*i*kx*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng))*cos(j*ky*y + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - Bx += rand_amp*j*ky*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y); - By += -rand_amp*i*kx*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y); - Bz += gkyl_pcg64_rand_double(&rng)*j*ky*i*kx*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng))*cos(j*ky*y + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); + Ex += rand_amp * j * ky * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y); + Ey += -rand_amp * i * kx * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y); + Ez += gkyl_pcg64_rand_double(&rng) * j * ky * i * kx * + sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)) * + cos(j * ky * y + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + Bx += rand_amp * j * ky * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y); + By += -rand_amp * i * kx * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y); + Bz += gkyl_pcg64_rand_double(&rng) * j * ky * i * kx * + sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)) * + cos(j * ky * y + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); } } - double magB2 = Bx*Bx + By*By + Bz*Bz; - double bxbx = Bx*Bx/magB2; - double bxby = Bx*By/magB2; - double bxbz = Bx*Bz/magB2; - double byby = By*By/magB2; - double bybz = By*Bz/magB2; - double bzbz = Bz*Bz/magB2; + double magB2 = Bx * Bx + By * By + Bz * Bz; + double bxbx = Bx * Bx / magB2; + double bxby = Bx * By / magB2; + double bxbz = Bx * Bz / magB2; + double byby = By * By / magB2; + double bybz = By * Bz / magB2; + double bzbz = Bz * Bz / magB2; double bx = 0.0; double by = 0.0; double bz = 0.0; - if (Bx < 0.0) + if (Bx < 0.0) { bx = -sqrt(bxbx); - else + } else { bx = sqrt(bxbx); + } - if (By < 0.0) + if (By < 0.0) { by = -sqrt(byby); - else + } else { by = sqrt(byby); + } - if (Bz < 0.0) + if (Bz < 0.0) { bz = -sqrt(bzbz); - else - bz = sqrt(bzbz); + } else { + bz = sqrt(bzbz); + } fout[0] = bx; fout[1] = by; @@ -263,14 +295,14 @@ void eval_analytic_bvar_2x(double t, const double *xn, double* restrict fout, vo fout[8] = bzbz; } -void eval_analytic_ExB_2x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_analytic_ExB_2x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double y = xn[1]; - double Lx = 2.0*M_PI; - double Ly = 2.0*M_PI; - double kx = 2.0*M_PI/Lx; - double ky = 2.0*M_PI/Ly; + double Lx = 2.0 * M_PI; + double Ly = 2.0 * M_PI; + double kx = 2.0 * M_PI / Lx; + double ky = 2.0 * M_PI / Ly; pcg64_random_t rng = gkyl_pcg64_init(0); // RNG for use in IC @@ -281,41 +313,49 @@ void eval_analytic_ExB_2x(double t, const double *xn, double* restrict fout, voi double By = 0.0; double Bz = 0.0; double rand_amp, rand_phase_x, rand_phase_y; - for (int i=0; i<4; ++i) { - for (int j=0; j<4; ++j) { + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { rand_amp = gkyl_pcg64_rand_double(&rng); rand_phase_x = gkyl_pcg64_rand_double(&rng); rand_phase_y = gkyl_pcg64_rand_double(&rng); - Ex += rand_amp*j*ky*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y); - Ey += -rand_amp*i*kx*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y); - Ez += gkyl_pcg64_rand_double(&rng)*j*ky*i*kx*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng))*cos(j*ky*y + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); - Bx += rand_amp*j*ky*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y); - By += -rand_amp*i*kx*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y); - Bz += gkyl_pcg64_rand_double(&rng)*j*ky*i*kx*sin(i*kx*x + 2.0*M_PI*gkyl_pcg64_rand_double(&rng))*cos(j*ky*y + 2.0*M_PI*gkyl_pcg64_rand_double(&rng)); + Ex += rand_amp * j * ky * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y); + Ey += -rand_amp * i * kx * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y); + Ez += gkyl_pcg64_rand_double(&rng) * j * ky * i * kx * + sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)) * + cos(j * ky * y + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); + Bx += rand_amp * j * ky * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y); + By += -rand_amp * i * kx * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y); + Bz += gkyl_pcg64_rand_double(&rng) * j * ky * i * kx * + sin(i * kx * x + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)) * + cos(j * ky * y + 2.0 * M_PI * gkyl_pcg64_rand_double(&rng)); } } - double magB2 = Bx*Bx + By*By + Bz*Bz; - double num_ExB_x = Ey*Bz - Ez*By; - double num_ExB_y = Ez*Bx - Ex*Bz; - double num_ExB_z = Ex*By - Ey*Bx; + double magB2 = Bx * Bx + By * By + Bz * Bz; + double num_ExB_x = Ey * Bz - Ez * By; + double num_ExB_y = Ez * Bx - Ex * Bz; + double num_ExB_z = Ex * By - Ey * Bx; - fout[0] = num_ExB_x/magB2; - fout[1] = num_ExB_y/magB2; - fout[2] = num_ExB_z/magB2; + fout[0] = num_ExB_x / magB2; + fout[1] = num_ExB_y / magB2; + fout[2] = num_ExB_z / magB2; } -void eval_field_3x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_field_3x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double y = xn[1]; double z = xn[2]; - double Lx = 2.0*M_PI; - double Ly = 2.0*M_PI; - double Lz = 2.0*M_PI; - double kx = 2.0*M_PI/Lx; - double ky = 2.0*M_PI/Ly; - double kz = 2.0*M_PI/Ly; + double Lx = 2.0 * M_PI; + double Ly = 2.0 * M_PI; + double Lz = 2.0 * M_PI; + double kx = 2.0 * M_PI / Lx; + double ky = 2.0 * M_PI / Ly; + double kz = 2.0 * M_PI / Ly; pcg64_random_t rng = gkyl_pcg64_init(0); // RNG for use in IC @@ -326,19 +366,31 @@ void eval_field_3x(double t, const double *xn, double* restrict fout, void *ctx) double By = 0.0; double Bz = 0.0; double rand_amp, rand_phase_x, rand_phase_y, rand_phase_z; - for (int i=0; i<4; ++i) { - for (int j=0; j<4; ++j) { - for (int k=0; k<4; ++k) { + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + for (int k = 0; k < 4; ++k) { rand_amp = gkyl_pcg64_rand_double(&rng); rand_phase_x = gkyl_pcg64_rand_double(&rng); rand_phase_y = gkyl_pcg64_rand_double(&rng); rand_phase_z = gkyl_pcg64_rand_double(&rng); - Ex += rand_amp*j*ky*k*kz*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - Ey += -2.0*rand_amp*i*kx*k*kz*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - Ez += rand_amp*i*kx*j*ky*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*sin(k*kz*z + 2.0*M_PI*rand_phase_z); - Bx += rand_amp*j*ky*k*kz*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - By += -2.0*rand_amp*i*kx*k*kz*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - Bz += rand_amp*i*kx*j*ky*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*sin(k*kz*z + 2.0*M_PI*rand_phase_z); + Ex += rand_amp * j * ky * k * kz * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + Ey += -2.0 * rand_amp * i * kx * k * kz * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + Ez += rand_amp * i * kx * j * ky * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + sin(k * kz * z + 2.0 * M_PI * rand_phase_z); + Bx += rand_amp * j * ky * k * kz * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + By += -2.0 * rand_amp * i * kx * k * kz * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + Bz += rand_amp * i * kx * j * ky * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + sin(k * kz * z + 2.0 * M_PI * rand_phase_z); } } } @@ -353,17 +405,17 @@ void eval_field_3x(double t, const double *xn, double* restrict fout, void *ctx) fout[7] = 0.0; } -void eval_analytic_bvar_3x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_analytic_bvar_3x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double y = xn[1]; double z = xn[2]; - double Lx = 2.0*M_PI; - double Ly = 2.0*M_PI; - double Lz = 2.0*M_PI; - double kx = 2.0*M_PI/Lx; - double ky = 2.0*M_PI/Ly; - double kz = 2.0*M_PI/Ly; + double Lx = 2.0 * M_PI; + double Ly = 2.0 * M_PI; + double Lz = 2.0 * M_PI; + double kx = 2.0 * M_PI / Lx; + double ky = 2.0 * M_PI / Ly; + double kz = 2.0 * M_PI / Ly; pcg64_random_t rng = gkyl_pcg64_init(0); // RNG for use in IC @@ -374,48 +426,63 @@ void eval_analytic_bvar_3x(double t, const double *xn, double* restrict fout, vo double By = 0.0; double Bz = 0.0; double rand_amp, rand_phase_x, rand_phase_y, rand_phase_z; - for (int i=0; i<4; ++i) { - for (int j=0; j<4; ++j) { - for (int k=0; k<4; ++k) { + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + for (int k = 0; k < 4; ++k) { rand_amp = gkyl_pcg64_rand_double(&rng); rand_phase_x = gkyl_pcg64_rand_double(&rng); rand_phase_y = gkyl_pcg64_rand_double(&rng); rand_phase_z = gkyl_pcg64_rand_double(&rng); - Ex += rand_amp*j*ky*k*kz*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - Ey += -2.0*rand_amp*i*kx*k*kz*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - Ez += rand_amp*i*kx*j*ky*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*sin(k*kz*z + 2.0*M_PI*rand_phase_z); - Bx += rand_amp*j*ky*k*kz*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - By += -2.0*rand_amp*i*kx*k*kz*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - Bz += rand_amp*i*kx*j*ky*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*sin(k*kz*z + 2.0*M_PI*rand_phase_z); + Ex += rand_amp * j * ky * k * kz * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + Ey += -2.0 * rand_amp * i * kx * k * kz * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + Ez += rand_amp * i * kx * j * ky * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + sin(k * kz * z + 2.0 * M_PI * rand_phase_z); + Bx += rand_amp * j * ky * k * kz * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + By += -2.0 * rand_amp * i * kx * k * kz * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + Bz += rand_amp * i * kx * j * ky * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + sin(k * kz * z + 2.0 * M_PI * rand_phase_z); } } } - double magB2 = Bx*Bx + By*By + Bz*Bz; - double bxbx = Bx*Bx/magB2; - double bxby = Bx*By/magB2; - double bxbz = Bx*Bz/magB2; - double byby = By*By/magB2; - double bybz = By*Bz/magB2; - double bzbz = Bz*Bz/magB2; + double magB2 = Bx * Bx + By * By + Bz * Bz; + double bxbx = Bx * Bx / magB2; + double bxby = Bx * By / magB2; + double bxbz = Bx * Bz / magB2; + double byby = By * By / magB2; + double bybz = By * Bz / magB2; + double bzbz = Bz * Bz / magB2; double bx = 0.0; double by = 0.0; double bz = 0.0; - if (Bx < 0.0) + if (Bx < 0.0) { bx = -sqrt(bxbx); - else + } else { bx = sqrt(bxbx); + } - if (By < 0.0) + if (By < 0.0) { by = -sqrt(byby); - else + } else { by = sqrt(byby); + } - if (Bz < 0.0) + if (Bz < 0.0) { bz = -sqrt(bzbz); - else - bz = sqrt(bzbz); + } else { + bz = sqrt(bzbz); + } fout[0] = bx; fout[1] = by; @@ -428,17 +495,17 @@ void eval_analytic_bvar_3x(double t, const double *xn, double* restrict fout, vo fout[8] = bzbz; } -void eval_analytic_ExB_3x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_analytic_ExB_3x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double y = xn[1]; double z = xn[2]; - double Lx = 2.0*M_PI; - double Ly = 2.0*M_PI; - double Lz = 2.0*M_PI; - double kx = 2.0*M_PI/Lx; - double ky = 2.0*M_PI/Ly; - double kz = 2.0*M_PI/Ly; + double Lx = 2.0 * M_PI; + double Ly = 2.0 * M_PI; + double Lz = 2.0 * M_PI; + double kx = 2.0 * M_PI / Lx; + double ky = 2.0 * M_PI / Ly; + double kz = 2.0 * M_PI / Ly; pcg64_random_t rng = gkyl_pcg64_init(0); // RNG for use in IC @@ -449,43 +516,56 @@ void eval_analytic_ExB_3x(double t, const double *xn, double* restrict fout, voi double By = 0.0; double Bz = 0.0; double rand_amp, rand_phase_x, rand_phase_y, rand_phase_z; - for (int i=0; i<4; ++i) { - for (int j=0; j<4; ++j) { - for (int k=0; k<4; ++k) { + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + for (int k = 0; k < 4; ++k) { rand_amp = gkyl_pcg64_rand_double(&rng); rand_phase_x = gkyl_pcg64_rand_double(&rng); rand_phase_y = gkyl_pcg64_rand_double(&rng); rand_phase_z = gkyl_pcg64_rand_double(&rng); - Ex += rand_amp*j*ky*k*kz*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - Ey += -2.0*rand_amp*i*kx*k*kz*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - Ez += rand_amp*i*kx*j*ky*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*sin(k*kz*z + 2.0*M_PI*rand_phase_z); - Bx += rand_amp*j*ky*k*kz*sin(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - By += -2.0*rand_amp*i*kx*k*kz*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*sin(j*ky*y + 2.0*M_PI*rand_phase_y)*cos(k*kz*z + 2.0*M_PI*rand_phase_z); - Bz += rand_amp*i*kx*j*ky*cos(i*kx*x + 2.0*M_PI*rand_phase_x)*cos(j*ky*y + 2.0*M_PI*rand_phase_y)*sin(k*kz*z + 2.0*M_PI*rand_phase_z); + Ex += rand_amp * j * ky * k * kz * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + Ey += -2.0 * rand_amp * i * kx * k * kz * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + Ez += rand_amp * i * kx * j * ky * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + sin(k * kz * z + 2.0 * M_PI * rand_phase_z); + Bx += rand_amp * j * ky * k * kz * sin(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + By += -2.0 * rand_amp * i * kx * k * kz * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + sin(j * ky * y + 2.0 * M_PI * rand_phase_y) * + cos(k * kz * z + 2.0 * M_PI * rand_phase_z); + Bz += rand_amp * i * kx * j * ky * cos(i * kx * x + 2.0 * M_PI * rand_phase_x) * + cos(j * ky * y + 2.0 * M_PI * rand_phase_y) * + sin(k * kz * z + 2.0 * M_PI * rand_phase_z); } } } - double magB2 = Bx*Bx + By*By + Bz*Bz; - double num_ExB_x = Ey*Bz - Ez*By; - double num_ExB_y = Ez*Bx - Ex*Bz; - double num_ExB_z = Ex*By - Ey*Bx; + double magB2 = Bx * Bx + By * By + Bz * Bz; + double num_ExB_x = Ey * Bz - Ez * By; + double num_ExB_y = Ez * Bx - Ex * Bz; + double num_ExB_z = Ex * By - Ey * Bx; - fout[0] = num_ExB_x/magB2; - fout[1] = num_ExB_y/magB2; - fout[2] = num_ExB_z/magB2; + fout[0] = num_ExB_x / magB2; + fout[1] = num_ExB_y / magB2; + fout[2] = num_ExB_z / magB2; } -void -test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_analytic, bool use_gpu) +void test( + int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_analytic, bool use_gpu +) { - double L = 2.*M_PI; + double L = 2. * M_PI; double lower[ndim], upper[ndim]; int cells[ndim], ghost[ndim]; - for (int n=0; n 1* - bvar_surf = mkarr(Ncomp_surf*Nbasis_surf, local_ext.volume); + int Ncomp_surf = 2 * ndim * 4; + int Nbasis_surf = + basis.num_basis / (basis.poly_order + 1); // *only valid for tensor bases for cdim > 1* + bvar_surf = mkarr(Ncomp_surf * Nbasis_surf, local_ext.volume); // Project initial conditions and analytic solution gkyl_proj_on_basis_advance(proj_field, 0.0, &local_ext, field); @@ -552,11 +623,11 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a struct gkyl_array *cell_avg_magB2_cu; struct gkyl_array *field_cu, *bvar_cu, *ExB_cu, *bvar_surf_cu; if (use_gpu) { // Create device copies - cell_avg_magB2_cu = gkyl_array_cu_dev_new(GKYL_INT, 1, local_ext.volume); - field_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 8*basis.num_basis, local_ext.volume); - bvar_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 9*basis.num_basis, local_ext.volume); - ExB_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3*basis.num_basis, local_ext.volume); - bvar_surf_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, Ncomp_surf*Nbasis_surf, local_ext.volume); + cell_avg_magB2_cu = gkyl_array_cu_dev_new(GKYL_INT, 1, local_ext.volume); + field_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 8 * basis.num_basis, local_ext.volume); + bvar_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 9 * basis.num_basis, local_ext.volume); + ExB_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3 * basis.num_basis, local_ext.volume); + bvar_surf_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, Ncomp_surf * Nbasis_surf, local_ext.volume); } if (use_gpu) { @@ -571,10 +642,10 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a double limiter_fac = 0.0; struct gkyl_dg_calc_em_vars *calc_bvar; struct gkyl_dg_calc_em_vars *calc_ExB; - calc_bvar = gkyl_dg_calc_em_vars_new(&grid, &basis, &local_ext, - maxwell, geom, limiter_fac, 0, use_gpu); - calc_ExB = gkyl_dg_calc_em_vars_new(&grid, &basis, &local_ext, - maxwell, geom, limiter_fac, 1, use_gpu); + calc_bvar = + gkyl_dg_calc_em_vars_new(&grid, &basis, &local_ext, maxwell, geom, limiter_fac, 0, use_gpu); + calc_ExB = + gkyl_dg_calc_em_vars_new(&grid, &basis, &local_ext, maxwell, geom, limiter_fac, 1, use_gpu); gkyl_wv_eqn_release(maxwell); gkyl_wave_geom_release(geom); @@ -582,10 +653,10 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a // Updaters to compute bvar and ExB with minimum number of loops and grouped operations // Note order of operations is designed to minimize aliasing errors - // 1. Compute B_i B_j or numerator (E x B)_i and denominator (|B|^2) using weak multiplication + // 1. Compute B_i B_j or numerator (E x B)_i and denominator (|B|^2) using weak multiplication // 2. Compute unit tensor (b_i b_j = B_i B_j/|B|^2, 6 components) or (E x B/|B|^2) using either // basis_inv operator (for p=1) or weak division (p>1) - // 3. For bvar, project diagonal components of bb onto quadrature points, evaluate square root point wise, + // 3. For bvar, project diagonal components of bb onto quadrature points, evaluate square root point wise, // and project back onto modal basis using basis_sqrt to obtain b_i (see gkyl_basis_*_sqrt.h in kernels/basis/) if (use_gpu) { // Advance also computed surface variables, but not currently testing surface variables JJ: 09/02/23 @@ -594,8 +665,7 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a // Copy host array to device. gkyl_array_copy(bvar, bvar_cu); gkyl_array_copy(ExB, ExB_cu); - } - else { + } else { gkyl_dg_calc_em_vars_advance(calc_bvar, field, cell_avg_magB2, bvar, bvar_surf); gkyl_dg_calc_em_vars_advance(calc_ExB, field, cell_avg_magB2, ExB, bvar_surf); } @@ -606,14 +676,14 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a // Check if b . b = 1 from EM vars computation struct gkyl_array *bibj_check, *b_dot_b; - bibj_check = mkarr(3*basis.num_basis, local_ext.volume); + bibj_check = mkarr(3 * basis.num_basis, local_ext.volume); b_dot_b = mkarr(basis.num_basis, local_ext.volume); - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { gkyl_dg_mul_op_range(&basis, i, bibj_check, i, bvar, i, bvar, &local); } - gkyl_array_accumulate_offset_range(b_dot_b, 1.0, bibj_check, 0*basis.num_basis, &local); - gkyl_array_accumulate_offset_range(b_dot_b, 1.0, bibj_check, 1*basis.num_basis, &local); - gkyl_array_accumulate_offset_range(b_dot_b, 1.0, bibj_check, 2*basis.num_basis, &local); + gkyl_array_accumulate_offset_range(b_dot_b, 1.0, bibj_check, 0 * basis.num_basis, &local); + gkyl_array_accumulate_offset_range(b_dot_b, 1.0, bibj_check, 1 * basis.num_basis, &local); + gkyl_array_accumulate_offset_range(b_dot_b, 1.0, bibj_check, 2 * basis.num_basis, &local); // Create intermediate arrays and dg_bin_op_memory to construct bvar // and ExB by the relevant sequence of operations @@ -621,33 +691,33 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a struct gkyl_array *alt_bibj_cu, *alt_ExB_cu; struct gkyl_dg_bin_op_mem *magB2_mem; - alt_bibj = mkarr(9*basis.num_basis, local_ext.volume); - alt_ExB = mkarr(3*basis.num_basis, local_ext.volume); + alt_bibj = mkarr(9 * basis.num_basis, local_ext.volume); + alt_ExB = mkarr(3 * basis.num_basis, local_ext.volume); struct timespec tm2 = gkyl_wall_clock(); if (use_gpu) { - alt_bibj_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 9*basis.num_basis, local_ext.volume); - alt_ExB_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3*basis.num_basis, local_ext.volume); + alt_bibj_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 9 * basis.num_basis, local_ext.volume); + alt_ExB_cu = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3 * basis.num_basis, local_ext.volume); magB2 = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis.num_basis, local_ext.volume); - int_BiBj = gkyl_array_cu_dev_new(GKYL_DOUBLE, 6*basis.num_basis, local_ext.volume); - int_ExB1 = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3*basis.num_basis, local_ext.volume); - int_ExB2 = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3*basis.num_basis, local_ext.volume); + int_BiBj = gkyl_array_cu_dev_new(GKYL_DOUBLE, 6 * basis.num_basis, local_ext.volume); + int_ExB1 = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3 * basis.num_basis, local_ext.volume); + int_ExB2 = gkyl_array_cu_dev_new(GKYL_DOUBLE, 3 * basis.num_basis, local_ext.volume); magB2_mem = gkyl_dg_bin_op_mem_cu_dev_new(local.volume, basis.num_basis); int ctr = 0; - for (int i=0; i<3; ++i) { - for (int j=i; j<3; ++j) { - gkyl_dg_mul_op_range(&basis, ctr, int_BiBj, i+3, field_cu, j+3, field_cu, &local); + for (int i = 0; i < 3; ++i) { + for (int j = i; j < 3; ++j) { + gkyl_dg_mul_op_range(&basis, ctr, int_BiBj, i + 3, field_cu, j + 3, field_cu, &local); ctr += 1; } } - gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 0*basis.num_basis, &local); - gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 3*basis.num_basis, &local); - gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 5*basis.num_basis, &local); + gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 0 * basis.num_basis, &local); + gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 3 * basis.num_basis, &local); + gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 5 * basis.num_basis, &local); - for (int i=0; i<6; ++i) { - gkyl_dg_div_op_range(magB2_mem, &basis, 3+i, alt_bibj_cu, i, int_BiBj, 0, magB2, &local); + for (int i = 0; i < 6; ++i) { + gkyl_dg_div_op_range(magB2_mem, &basis, 3 + i, alt_bibj_cu, i, int_BiBj, 0, magB2, &local); } gkyl_dg_mul_op_range(&basis, 0, int_ExB1, 1, field_cu, 5, field_cu, &local); @@ -660,35 +730,34 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a gkyl_dg_mul_op_range(&basis, 2, int_ExB2, 1, field_cu, 3, field_cu, &local); gkyl_array_accumulate_range(int_ExB1, -1.0, int_ExB2, &local); - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { gkyl_dg_div_op_range(magB2_mem, &basis, i, alt_ExB_cu, i, int_ExB1, 0, magB2, &local); - } + } // copy from device and check if things are ok gkyl_array_copy(alt_bibj, alt_bibj_cu); gkyl_array_copy(alt_ExB, alt_ExB_cu); - } - else { + } else { magB2 = mkarr(basis.num_basis, local_ext.volume); - int_BiBj = mkarr(6*basis.num_basis, local_ext.volume); - int_ExB1 = mkarr(3*basis.num_basis, local_ext.volume); - int_ExB2 = mkarr(3*basis.num_basis, local_ext.volume); + int_BiBj = mkarr(6 * basis.num_basis, local_ext.volume); + int_ExB1 = mkarr(3 * basis.num_basis, local_ext.volume); + int_ExB2 = mkarr(3 * basis.num_basis, local_ext.volume); magB2_mem = gkyl_dg_bin_op_mem_new(local.volume, basis.num_basis); int ctr = 0; - for (int i=0; i<3; ++i) { - for (int j=i; j<3; ++j) { - gkyl_dg_mul_op_range(&basis, ctr, int_BiBj, i+3, field, j+3, field, &local); + for (int i = 0; i < 3; ++i) { + for (int j = i; j < 3; ++j) { + gkyl_dg_mul_op_range(&basis, ctr, int_BiBj, i + 3, field, j + 3, field, &local); ctr += 1; } } - gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 0*basis.num_basis, &local); - gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 3*basis.num_basis, &local); - gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 5*basis.num_basis, &local); + gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 0 * basis.num_basis, &local); + gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 3 * basis.num_basis, &local); + gkyl_array_accumulate_offset_range(magB2, 1.0, int_BiBj, 5 * basis.num_basis, &local); - for (int i=0; i<6; ++i) { - gkyl_dg_div_op_range(magB2_mem, &basis, 3+i, alt_bibj, i, int_BiBj, 0, magB2, &local); + for (int i = 0; i < 6; ++i) { + gkyl_dg_div_op_range(magB2_mem, &basis, 3 + i, alt_bibj, i, int_BiBj, 0, magB2, &local); } gkyl_dg_mul_op_range(&basis, 0, int_ExB1, 1, field, 5, field, &local); @@ -701,21 +770,21 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a gkyl_dg_mul_op_range(&basis, 2, int_ExB2, 1, field, 3, field, &local); gkyl_array_accumulate_range(int_ExB1, -1.0, int_ExB2, &local); - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { gkyl_dg_div_op_range(magB2_mem, &basis, i, alt_ExB, i, int_ExB1, 0, magB2, &local); - } + } } double em_2_tm = gkyl_time_diff_now_sec(tm2); - // printf("dg_bin_op EM variable computation on (%d)^%d took %g sec\n", cells[0], ndim, em_2_tm); + // printf("dg_bin_op EM variable computation on (%d)^%d took %g sec\n", cells[0], ndim, em_2_tm); // Calculate L^2 errors from inverse and bin_op operators struct gkyl_array *bvar_err, *ExB_err, *alt_bvar_err, *alt_ExB_err; - bvar_err = mkarr(9*basis.num_basis, local_ext.volume); - ExB_err = mkarr(3*basis.num_basis, local_ext.volume); - alt_bvar_err = mkarr(9*basis.num_basis, local_ext.volume); - alt_ExB_err = mkarr(3*basis.num_basis, local_ext.volume); + bvar_err = mkarr(9 * basis.num_basis, local_ext.volume); + ExB_err = mkarr(3 * basis.num_basis, local_ext.volume); + alt_bvar_err = mkarr(9 * basis.num_basis, local_ext.volume); + alt_ExB_err = mkarr(3 * basis.num_basis, local_ext.volume); gkyl_array_set(bvar_err, 1.0, bvar); gkyl_array_accumulate(bvar_err, -1.0, analytic_bvar); gkyl_array_set(ExB_err, 1.0, ExB); @@ -730,11 +799,11 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a L2_ExB = mkarr(3, local_ext.volume); alt_L2_bvar = mkarr(9, local_ext.volume); alt_L2_ExB = mkarr(3, local_ext.volume); - for (int i=0; i<9; ++i) { + for (int i = 0; i < 9; ++i) { gkyl_dg_calc_l2_range(&basis, i, L2_bvar, i, bvar_err, local); gkyl_dg_calc_l2_range(&basis, i, alt_L2_bvar, i, alt_bvar_err, local); } - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { gkyl_dg_calc_l2_range(&basis, i, L2_ExB, i, ExB_err, local); gkyl_dg_calc_l2_range(&basis, i, alt_L2_ExB, i, alt_ExB_err, local); } @@ -756,7 +825,7 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &local); - + while (gkyl_range_iter_next(&iter)) { long linidx = gkyl_range_idx(&local, iter.idx); @@ -765,94 +834,159 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a const double *alt_bvar_p = gkyl_array_cfetch(alt_bibj, linidx); const double *analytic_bvar_p = gkyl_array_cfetch(analytic_bvar, linidx); // Check b_i b_j against bin_op - for (int m=3*basis.num_basis; m<9*basis.num_basis; ++m) { - TEST_CHECK( gkyl_compare(alt_bvar_p[m], bvar_p[m], eps) ); - if (ndim == 1) + for (int m = 3 * basis.num_basis; m < 9 * basis.num_basis; ++m) { + TEST_CHECK(gkyl_compare(alt_bvar_p[m], bvar_p[m], eps)); + if (ndim == 1) { TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d)", alt_bvar_p[m], m, iter.idx[0]); - else if (ndim == 2) - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d)", alt_bvar_p[m], m, iter.idx[0], iter.idx[1]); - else - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", alt_bvar_p[m], m, iter.idx[0], iter.idx[1], iter.idx[2]); + } else if (ndim == 2) { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d)", alt_bvar_p[m], m, iter.idx[0], + iter.idx[1] + ); + } else { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", alt_bvar_p[m], m, iter.idx[0], + iter.idx[1], iter.idx[2] + ); + } TEST_MSG("Produced: %.13e, coefficient (%d)", bvar_p[m], m); } if (check_analytic) { // Check bin_op solution against analytic solution - for (int m=3*basis.num_basis; m<9*basis.num_basis; ++m) { - TEST_CHECK( gkyl_compare(alt_bvar_p[m], analytic_bvar_p[m], eps) ); - if (ndim == 1) - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d)", analytic_bvar_p[m], m, iter.idx[0]); - else if (ndim == 2) - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d)", analytic_bvar_p[m], m, iter.idx[0], iter.idx[1]); - else - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", analytic_bvar_p[m], m, iter.idx[0], iter.idx[1], iter.idx[2]); + for (int m = 3 * basis.num_basis; m < 9 * basis.num_basis; ++m) { + TEST_CHECK(gkyl_compare(alt_bvar_p[m], analytic_bvar_p[m], eps)); + if (ndim == 1) { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d)", analytic_bvar_p[m], m, iter.idx[0] + ); + } else if (ndim == 2) { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d)", analytic_bvar_p[m], m, + iter.idx[0], iter.idx[1] + ); + } else { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", analytic_bvar_p[m], m, + iter.idx[0], iter.idx[1], iter.idx[2] + ); + } TEST_MSG("Produced: %.13e, coefficient (%d)", alt_bvar_p[m], m); } // Check b_i b_j from inverse operator against analytic solution - for (int m=0; m<9*basis.num_basis; ++m) { - TEST_CHECK( gkyl_compare(bvar_p[m], analytic_bvar_p[m], eps) ); - if (ndim == 1) - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d)", analytic_bvar_p[m], m, iter.idx[0]); - else if (ndim == 2) - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d)", analytic_bvar_p[m], m, iter.idx[0], iter.idx[1]); - else - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", analytic_bvar_p[m], m, iter.idx[0], iter.idx[1], iter.idx[2]); + for (int m = 0; m < 9 * basis.num_basis; ++m) { + TEST_CHECK(gkyl_compare(bvar_p[m], analytic_bvar_p[m], eps)); + if (ndim == 1) { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d)", analytic_bvar_p[m], m, iter.idx[0] + ); + } else if (ndim == 2) { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d)", analytic_bvar_p[m], m, + iter.idx[0], iter.idx[1] + ); + } else { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", analytic_bvar_p[m], m, + iter.idx[0], iter.idx[1], iter.idx[2] + ); + } TEST_MSG("Produced: %.13e, coefficient (%d)", bvar_p[m], m); } } - // Check if B . B/|B|^2 = 1 - TEST_CHECK( gkyl_compare(alt_bvar_p[3*basis.num_basis] + alt_bvar_p[6*basis.num_basis] + alt_bvar_p[8*basis.num_basis], - bvar_p[3*basis.num_basis] + bvar_p[6*basis.num_basis] + bvar_p[8*basis.num_basis], 1.0e-14) ); - if (ndim == 1) + // Check if B . B/|B|^2 = 1 + TEST_CHECK(gkyl_compare( + alt_bvar_p[3 * basis.num_basis] + alt_bvar_p[6 * basis.num_basis] + + alt_bvar_p[8 * basis.num_basis], + bvar_p[3 * basis.num_basis] + bvar_p[6 * basis.num_basis] + bvar_p[8 * basis.num_basis], + 1.0e-14 + )); + if (ndim == 1) { TEST_MSG("Expected: %.13e in cell (%d)", sqrt(2.0), iter.idx[0]); - else if (ndim == 2) + } else if (ndim == 2) { TEST_MSG("Expected: %.13e in cell (%d, %d)", 2.0, iter.idx[0], iter.idx[1]); - else - TEST_MSG("Expected: %.13e in cell (%d, %d, %d)", 2.0*sqrt(2.0), iter.idx[0], iter.idx[1], iter.idx[2]); + } else { + TEST_MSG( + "Expected: %.13e in cell (%d, %d, %d)", 2.0 * sqrt(2.0), iter.idx[0], iter.idx[1], + iter.idx[2] + ); + } - TEST_MSG("Cell average B . B/|B|^2 produced by EM vars computation: %.13e", bvar_p[3*basis.num_basis] + bvar_p[6*basis.num_basis] + bvar_p[8*basis.num_basis]); - TEST_MSG("Cell average B . B/|B|^2 Produced by dg_bin_op: %.13e", alt_bvar_p[3*basis.num_basis] + alt_bvar_p[6*basis.num_basis] + alt_bvar_p[8*basis.num_basis]); + TEST_MSG( + "Cell average B . B/|B|^2 produced by EM vars computation: %.13e", + bvar_p[3 * basis.num_basis] + bvar_p[6 * basis.num_basis] + bvar_p[8 * basis.num_basis] + ); + TEST_MSG( + "Cell average B . B/|B|^2 Produced by dg_bin_op: %.13e", alt_bvar_p[3 * basis.num_basis] + + alt_bvar_p[6 * basis.num_basis] + + alt_bvar_p[8 * basis.num_basis] + ); // Check b . b = 1 by checking cell average (should 2^d/2) and x slope (should be zero) const double *b_dot_b_p = gkyl_array_cfetch(b_dot_b, linidx); - TEST_CHECK( gkyl_compare(b_dot_b_p[0], pow(2.0, ndim/2.0), 1.0e-14) ); - TEST_CHECK( gkyl_compare(b_dot_b_p[1], 0.0, 1.0e-14) ); + TEST_CHECK(gkyl_compare(b_dot_b_p[0], pow(2.0, ndim / 2.0), 1.0e-14)); + TEST_CHECK(gkyl_compare(b_dot_b_p[1], 0.0, 1.0e-14)); TEST_MSG("b . b cell average from EM vars computation: %.13e", b_dot_b_p[0]); // Check E x B velocity const double *ExB_p = gkyl_array_cfetch(ExB, linidx); const double *alt_ExB_p = gkyl_array_cfetch(alt_ExB, linidx); const double *analytic_ExB_p = gkyl_array_cfetch(analytic_ExB, linidx); - for (int m=0; m<3*basis.num_basis; ++m) { + for (int m = 0; m < 3 * basis.num_basis; ++m) { // Check E x B against bin_op - TEST_CHECK( gkyl_compare(alt_ExB_p[m], ExB_p[m], eps) ); - if (ndim == 1) + TEST_CHECK(gkyl_compare(alt_ExB_p[m], ExB_p[m], eps)); + if (ndim == 1) { TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d)", alt_ExB_p[m], m, iter.idx[0]); - else if (ndim == 2) - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d)", alt_ExB_p[m], m, iter.idx[0], iter.idx[1]); - else - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", alt_ExB_p[m], m, iter.idx[0], iter.idx[1], iter.idx[2]); + } else if (ndim == 2) { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d)", alt_ExB_p[m], m, iter.idx[0], + iter.idx[1] + ); + } else { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", alt_ExB_p[m], m, iter.idx[0], + iter.idx[1], iter.idx[2] + ); + } TEST_MSG("Produced: %.13e, coefficient (%d)", ExB_p[m], m); if (check_analytic) { // Check bin_op solution against analytic solution - TEST_CHECK( gkyl_compare(alt_ExB_p[m], analytic_ExB_p[m], eps) ); - if (ndim == 1) - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d)", analytic_ExB_p[m], m, iter.idx[0]); - else if (ndim == 2) - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d)", analytic_ExB_p[m], m, iter.idx[0], iter.idx[1]); - else - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", analytic_ExB_p[m], m, iter.idx[0], iter.idx[1], iter.idx[2]); + TEST_CHECK(gkyl_compare(alt_ExB_p[m], analytic_ExB_p[m], eps)); + if (ndim == 1) { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d)", analytic_ExB_p[m], m, iter.idx[0] + ); + } else if (ndim == 2) { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d)", analytic_ExB_p[m], m, iter.idx[0], + iter.idx[1] + ); + } else { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", analytic_ExB_p[m], m, + iter.idx[0], iter.idx[1], iter.idx[2] + ); + } TEST_MSG("Produced: %.13e, coefficient (%d)", alt_ExB_p[m], m); // Check ExB from inverse operator against analytic solution - TEST_CHECK( gkyl_compare(ExB_p[m], analytic_ExB_p[m], eps) ); - if (ndim == 1) - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d)", analytic_ExB_p[m], m, iter.idx[0]); - else if (ndim == 2) - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d)", analytic_ExB_p[m], m, iter.idx[0], iter.idx[1]); - else - TEST_MSG("Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", analytic_ExB_p[m], m, iter.idx[0], iter.idx[1], iter.idx[2]); + TEST_CHECK(gkyl_compare(ExB_p[m], analytic_ExB_p[m], eps)); + if (ndim == 1) { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d)", analytic_ExB_p[m], m, iter.idx[0] + ); + } else if (ndim == 2) { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d)", analytic_ExB_p[m], m, iter.idx[0], + iter.idx[1] + ); + } else { + TEST_MSG( + "Expected: %.13e, coefficient (%d) in cell (%d, %d, %d)", analytic_ExB_p[m], m, + iter.idx[0], iter.idx[1], iter.idx[2] + ); + } TEST_MSG("Produced: %.13e, coefficient (%d)", ExB_p[m], m); - } + } } } @@ -926,7 +1060,7 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a gkyl_array_release(alt_bibj_cu); gkyl_array_release(alt_ExB_cu); - } + } gkyl_proj_on_basis_release(proj_field); gkyl_proj_on_basis_release(proj_analytic_bvar); @@ -936,51 +1070,86 @@ test(int ndim, int Nx, int poly_order, double eps, bool use_tensor, bool check_a gkyl_dg_calc_em_vars_release(calc_ExB); } -void test_dg_em_vars_1x_p1_ho() { test(1, 8, 1, 1.0e-12, 0, 0, false); } -void test_dg_em_vars_2x_p1_ho() { test(2, 8, 1, 1.0e-12, 0, 0, false); } -void test_dg_em_vars_3x_p1_ho() { test(3, 4, 1, 1.0e-12, 0, 0, false); } +void test_dg_em_vars_1x_p1_ho() +{ + test(1, 8, 1, 1.0e-12, 0, 0, false); +} +void test_dg_em_vars_2x_p1_ho() +{ + test(2, 8, 1, 1.0e-12, 0, 0, false); +} +void test_dg_em_vars_3x_p1_ho() +{ + test(3, 4, 1, 1.0e-12, 0, 0, false); +} -void test_dg_em_vars_1x_p2_ho() { test(1, 8, 2, 1.0e-12, 0, 0, false); } +void test_dg_em_vars_1x_p2_ho() +{ + test(1, 8, 2, 1.0e-12, 0, 0, false); +} // Higher dimensions, p=2, *only* testing is b . b = 1 like we expect -void test_dg_em_vars_2x_tensor_p2_ho() { test(2, 8, 2, 1.0e-12, 1, 0, false); } -void test_dg_em_vars_3x_tensor_p2_ho() { test(3, 8, 2, 1.0e-12, 1, 0, false); } +void test_dg_em_vars_2x_tensor_p2_ho() +{ + test(2, 8, 2, 1.0e-12, 1, 0, false); +} +void test_dg_em_vars_3x_tensor_p2_ho() +{ + test(3, 8, 2, 1.0e-12, 1, 0, false); +} #ifdef GKYL_HAVE_CUDA -void test_dg_em_vars_1x_p1_dev() { test(1, 8, 1, 1.0e-12, 0, 0, true); } -void test_dg_em_vars_2x_p1_dev() { test(2, 8, 1, 1.0e-12, 0, 0, true); } -void test_dg_em_vars_3x_p1_dev() { test(3, 8, 1, 1.0e-12, 0, 0, true); } - -void test_dg_em_vars_1x_p2_dev() { test(1, 8, 2, 1.0e-12, 0, 0, true); } -void test_dg_em_vars_2x_tensor_p2_dev() { test(2, 8, 2, 1.0e-12, 1, 0, true); } -void test_dg_em_vars_3x_tensor_p2_dev() { test(3, 8, 2, 1.0e-12, 1, 0, true); } +void test_dg_em_vars_1x_p1_dev() +{ + test(1, 8, 1, 1.0e-12, 0, 0, true); +} +void test_dg_em_vars_2x_p1_dev() +{ + test(2, 8, 1, 1.0e-12, 0, 0, true); +} +void test_dg_em_vars_3x_p1_dev() +{ + test(3, 8, 1, 1.0e-12, 0, 0, true); +} +void test_dg_em_vars_1x_p2_dev() +{ + test(1, 8, 2, 1.0e-12, 0, 0, true); +} +void test_dg_em_vars_2x_tensor_p2_dev() +{ + test(2, 8, 2, 1.0e-12, 1, 0, true); +} +void test_dg_em_vars_3x_tensor_p2_dev() +{ + test(3, 8, 2, 1.0e-12, 1, 0, true); +} #endif TEST_LIST = { - { "test_dg_em_vars_1x_p1_ho", test_dg_em_vars_1x_p1_ho }, - { "test_dg_em_vars_2x_p1_ho", test_dg_em_vars_2x_p1_ho }, - { "test_dg_em_vars_3x_p1_ho", test_dg_em_vars_3x_p1_ho }, - - { "test_dg_em_vars_1x_p2_ho", test_dg_em_vars_1x_p2_ho }, - // The tensor p2 bvar comparison is disabled (CPU and GPU): the em_vars - // operator's positivity-control fallback keeps only the cell average of - // b_i b_j in cells where b_i b_i is negative at control points, while the - // bin_op reference here does the plain weak division everywhere, so they - // disagree by design in those cells. - // { "test_dg_em_vars_2x_tensor_p2_ho", test_dg_em_vars_2x_tensor_p2_ho }, - // { "test_dg_em_vars_3x_tensor_p2_ho", test_dg_em_vars_3x_tensor_p2_ho }, + {"test_dg_em_vars_1x_p1_ho", test_dg_em_vars_1x_p1_ho}, + {"test_dg_em_vars_2x_p1_ho", test_dg_em_vars_2x_p1_ho}, + {"test_dg_em_vars_3x_p1_ho", test_dg_em_vars_3x_p1_ho}, + + {"test_dg_em_vars_1x_p2_ho", test_dg_em_vars_1x_p2_ho}, +// The tensor p2 bvar comparison is disabled (CPU and GPU): the em_vars +// operator's positivity-control fallback keeps only the cell average of +// b_i b_j in cells where b_i b_i is negative at control points, while the +// bin_op reference here does the plain weak division everywhere, so they +// disagree by design in those cells. +// { "test_dg_em_vars_2x_tensor_p2_ho", test_dg_em_vars_2x_tensor_p2_ho }, +// { "test_dg_em_vars_3x_tensor_p2_ho", test_dg_em_vars_3x_tensor_p2_ho }, #ifdef GKYL_HAVE_CUDA - { "test_dg_em_vars_1x_p1_dev", test_dg_em_vars_1x_p1_dev }, - { "test_dg_em_vars_2x_p1_dev", test_dg_em_vars_2x_p1_dev }, - { "test_dg_em_vars_3x_p1_dev", test_dg_em_vars_3x_p1_dev }, + {"test_dg_em_vars_1x_p1_dev", test_dg_em_vars_1x_p1_dev}, + {"test_dg_em_vars_2x_p1_dev", test_dg_em_vars_2x_p1_dev}, + {"test_dg_em_vars_3x_p1_dev", test_dg_em_vars_3x_p1_dev}, - { "test_dg_em_vars_1x_p2_dev", test_dg_em_vars_1x_p2_dev }, - // Disabled for the same positivity-fallback reason as the CPU tensor tests. - // { "test_dg_em_vars_2x_tensor_p2_dev", test_dg_em_vars_2x_tensor_p2_dev }, - // { "test_dg_em_vars_3x_tensor_p2_dev", test_dg_em_vars_3x_tensor_p2_dev }, + {"test_dg_em_vars_1x_p2_dev", test_dg_em_vars_1x_p2_dev}, +// Disabled for the same positivity-fallback reason as the CPU tensor tests. +// { "test_dg_em_vars_2x_tensor_p2_dev", test_dg_em_vars_2x_tensor_p2_dev }, +// { "test_dg_em_vars_3x_tensor_p2_dev", test_dg_em_vars_3x_tensor_p2_dev }, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/vlasov/unit/ctest_dg_lbo_vlasov.c b/vlasov/unit/ctest_dg_lbo_vlasov.c index d919404683..6f73ee31e8 100644 --- a/vlasov/unit/ctest_dg_lbo_vlasov.c +++ b/vlasov/unit/ctest_dg_lbo_vlasov.c @@ -16,50 +16,47 @@ #include // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { - struct gkyl_array* a = gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } // allocate cu_dev array -static struct gkyl_array* -mkarr_cu(long nc, long size) +static struct gkyl_array *mkarr_cu(long nc, long size) { - struct gkyl_array* a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); return a; } -void nu_prof(double t, const double *xn, double* restrict fout, void *ctx) +void nu_prof(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double vx = xn[1]; - double vy = xn[2]; + double vy = xn[2]; fout[0] = 1.0; } -void maxwellian1x2v(double t, const double *xn, double* restrict fout, void *ctx) +void maxwellian1x2v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double vx = xn[1]; - double vy = xn[2]; - fout[0] = 1.0/(2*M_PI)*exp(-(pow(vx, 2) + pow(vy, 2))/2); + double vy = xn[2]; + fout[0] = 1.0 / (2 * M_PI) * exp(-(pow(vx, 2) + pow(vy, 2)) / 2); } -void maxwellian1x1v(double t, const double *xn, double* restrict fout, void *ctx) +void maxwellian1x1v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double vx = xn[1]; - fout[0] = 1.0/sqrt(2*M_PI)*exp(-(pow(vx, 2))/2); + fout[0] = 1.0 / sqrt(2 * M_PI) * exp(-(pow(vx, 2)) / 2); } -void -test_dg_lbo_vlasov_1x1v_p2_ho() +void test_dg_lbo_vlasov_1x1v_p2_ho() { // initialize grid and ranges int cdim = 1, vdim = 1; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int cells[] = {2, 4}; int ghost[] = {0, 0}; @@ -83,27 +80,29 @@ test_dg_lbo_vlasov_1x1v_p2_ho() gkyl_cart_modal_serendip(&basis, pdim, poly_order); gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); - gkyl_proj_on_basis *projF = gkyl_proj_on_basis_new(&phaseGrid, &basis, poly_order+1, 1, maxwellian1x1v, NULL); - gkyl_proj_on_basis *projNu = gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order+1, 1, nu_prof, NULL); + gkyl_proj_on_basis *projF = + gkyl_proj_on_basis_new(&phaseGrid, &basis, poly_order + 1, 1, maxwellian1x1v, NULL); + gkyl_proj_on_basis *projNu = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, nu_prof, NULL); struct gkyl_array *cflrate, *rhs, *fin, *nuSum, *nuUSum, *nuVtSqSum, *nuPrimMomsSum; cflrate = mkarr(1, phaseRange_ext.volume); rhs = mkarr(basis.num_basis, phaseRange_ext.volume); fin = mkarr(basis.num_basis, phaseRange_ext.volume); nuSum = mkarr(confBasis.num_basis, confRange_ext.volume); - nuUSum = mkarr(vdim*confBasis.num_basis, confRange_ext.volume); + nuUSum = mkarr(vdim * confBasis.num_basis, confRange_ext.volume); nuVtSqSum = mkarr(confBasis.num_basis, confRange_ext.volume); - nuPrimMomsSum = mkarr((vdim+1)*confBasis.num_basis, confRange_ext.volume); + nuPrimMomsSum = mkarr((vdim + 1) * confBasis.num_basis, confRange_ext.volume); gkyl_proj_on_basis_advance(projF, 0.0, &phaseRange_ext, fin); gkyl_proj_on_basis_advance(projNu, 0.0, &confRange_ext, nuSum); gkyl_proj_on_basis_release(projF); gkyl_proj_on_basis_release(projNu); - + gkyl_array_clear(nuUSum, 0.0); gkyl_array_clear(nuVtSqSum, 1.0); gkyl_array_set_offset(nuPrimMomsSum, 1.0, nuUSum, 0); - gkyl_array_set_offset(nuPrimMomsSum, 1.0, nuVtSqSum, vdim*confBasis.num_basis); + gkyl_array_set_offset(nuPrimMomsSum, 1.0, nuVtSqSum, vdim * confBasis.num_basis); // initialize hyper_dg slvr int up_dirs[] = {1}; @@ -111,13 +110,19 @@ test_dg_lbo_vlasov_1x1v_p2_ho() gkyl_dg_updater_collisions *slvr; // LBO updater - struct gkyl_dg_lbo_vlasov_drag_auxfields drag_inp = { .nuSum = nuSum, .nuPrimMomsSum = nuPrimMomsSum }; - struct gkyl_dg_lbo_vlasov_diff_auxfields diff_inp = { .nuSum = nuSum, .nuPrimMomsSum = nuPrimMomsSum }; - slvr = gkyl_dg_updater_lbo_vlasov_new(&phaseGrid, &confBasis, &basis, &confRange, &drag_inp, &diff_inp, false); + struct gkyl_dg_lbo_vlasov_drag_auxfields drag_inp = { + .nuSum = nuSum, .nuPrimMomsSum = nuPrimMomsSum + }; + struct gkyl_dg_lbo_vlasov_diff_auxfields diff_inp = { + .nuSum = nuSum, .nuPrimMomsSum = nuPrimMomsSum + }; + slvr = gkyl_dg_updater_lbo_vlasov_new( + &phaseGrid, &confBasis, &basis, &confRange, &drag_inp, &diff_inp, false + ); // run hyper_dg_advance int nrep = 10; - for(int n=0; n #include -void -test_dg_max_ho() +void test_dg_max_ho() { struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, 1, 1); - struct gkyl_dg_eqn* eqn = gkyl_dg_maxwell_new(&basis, 1.0, 0.5, 0.25, false); + struct gkyl_dg_eqn *eqn = gkyl_dg_maxwell_new(&basis, 1.0, 0.5, 0.25, false); - TEST_CHECK( eqn->num_equations == 8 ); + TEST_CHECK(eqn->num_equations == 8); // this is not possible from user code and should NOT be done. This // is for testing only struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); - TEST_CHECK( maxwell->maxwell_data.c == 1.0 ); - TEST_CHECK( maxwell->maxwell_data.chi == 0.5 ); - TEST_CHECK( maxwell->maxwell_data.gamma == 0.25 ); + TEST_CHECK(maxwell->maxwell_data.c == 1.0); + TEST_CHECK(maxwell->maxwell_data.chi == 0.5); + TEST_CHECK(maxwell->maxwell_data.gamma == 0.25); - struct dg_maxwell *m_on_dev = container_of(eqn->on_dev, - struct dg_maxwell, eqn); + struct dg_maxwell *m_on_dev = container_of(eqn->on_dev, struct dg_maxwell, eqn); - TEST_CHECK( m_on_dev->maxwell_data.c == 1.0 ); - TEST_CHECK( m_on_dev->maxwell_data.chi == 0.5 ); - TEST_CHECK( m_on_dev->maxwell_data.gamma == 0.25 ); + TEST_CHECK(m_on_dev->maxwell_data.c == 1.0); + TEST_CHECK(m_on_dev->maxwell_data.chi == 0.5); + TEST_CHECK(m_on_dev->maxwell_data.gamma == 0.25); gkyl_dg_eqn_release(eqn); } @@ -37,22 +35,21 @@ test_dg_max_ho() int cu_maxwell_test(const struct gkyl_dg_eqn *eqn); -void -test_dg_max_dev() +void test_dg_max_dev() { struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, 1, 1); - struct gkyl_dg_eqn* eqn = gkyl_dg_maxwell_cu_dev_new(&basis, 1.0, 0.5, 0.25); + struct gkyl_dg_eqn *eqn = gkyl_dg_maxwell_cu_dev_new(&basis, 1.0, 0.5, 0.25); // this is not possible from user code and should NOT be done. This // is for testing only struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); - TEST_CHECK( maxwell->maxwell_data.c == 1.0 ); - TEST_CHECK( maxwell->maxwell_data.chi == 0.5 ); - TEST_CHECK( maxwell->maxwell_data.gamma == 0.25 ); - + TEST_CHECK(maxwell->maxwell_data.c == 1.0); + TEST_CHECK(maxwell->maxwell_data.chi == 0.5); + TEST_CHECK(maxwell->maxwell_data.gamma == 0.25); + // call CUDA test /* int nfail = cu_maxwell_test(eqn->on_dev); */ @@ -64,9 +61,9 @@ test_dg_max_dev() #endif TEST_LIST = { - { "dg_max_ho", test_dg_max_ho }, + {"dg_max_ho", test_dg_max_ho}, #ifdef GKYL_HAVE_CUDA - { "dg_max_dev", test_dg_max_dev }, -#endif - { NULL, NULL }, + {"dg_max_dev", test_dg_max_dev}, +#endif + {NULL, NULL} }; diff --git a/vlasov/unit/ctest_dg_vlasov.c b/vlasov/unit/ctest_dg_vlasov.c index 1545fac3e1..c894de9e5f 100644 --- a/vlasov/unit/ctest_dg_vlasov.c +++ b/vlasov/unit/ctest_dg_vlasov.c @@ -5,17 +5,16 @@ #include #include -void -test_dg_vlasov_ho() +void test_dg_vlasov_ho() { struct gkyl_basis cbasis, pbasis; gkyl_cart_modal_serendip(&cbasis, 1, 1); gkyl_cart_modal_serendip(&pbasis, 2, 1); struct gkyl_range crange; - gkyl_range_init_from_shape(&crange, 1, (int[]) { 100 } ); + gkyl_range_init_from_shape(&crange, 1, (int[]){100}); struct gkyl_range prange; - gkyl_range_init_from_shape(&prange, 2, (int[]) { 100, 100 } ); + gkyl_range_init_from_shape(&prange, 2, (int[]){100, 100}); // initialize eqn struct gkyl_dg_eqn *eqn; @@ -23,15 +22,15 @@ test_dg_vlasov_ho() enum gkyl_model_id model_id = GKYL_MODEL_DEFAULT; eqn = gkyl_dg_vlasov_new(&cbasis, &pbasis, &crange, &prange, model_id, field_id, false); - TEST_CHECK( eqn->num_equations == 1 ); + TEST_CHECK(eqn->num_equations == 1); // this is not possible from user code and should NOT be done. This // is for testing only struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); - TEST_CHECK( vlasov->cdim == 1 ); - TEST_CHECK( vlasov->pdim == 2 ); - TEST_CHECK( vlasov->conf_range.volume == 100 ); + TEST_CHECK(vlasov->cdim == 1); + TEST_CHECK(vlasov->pdim == 2); + TEST_CHECK(vlasov->conf_range.volume == 100); gkyl_dg_eqn_release(eqn); } @@ -40,17 +39,16 @@ test_dg_vlasov_ho() int cu_vlasov_test(const struct gkyl_dg_eqn *eqn); -void -test_dg_vlasov_dev() +void test_dg_vlasov_dev() { struct gkyl_basis cbasis, pbasis; gkyl_cart_modal_serendip(&cbasis, 1, 1); gkyl_cart_modal_serendip(&pbasis, 2, 1); struct gkyl_range crange; - gkyl_range_init_from_shape(&crange, 1, (int[]) { 100 } ); + gkyl_range_init_from_shape(&crange, 1, (int[]){100}); struct gkyl_range prange; - gkyl_range_init_from_shape(&prange, 2, (int[]) { 100, 100 } ); + gkyl_range_init_from_shape(&prange, 2, (int[]){100, 100}); // initialize eqn struct gkyl_dg_eqn *eqn; @@ -62,9 +60,9 @@ test_dg_vlasov_dev() // is for testing only struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); - TEST_CHECK( vlasov->cdim == 1 ); - TEST_CHECK( vlasov->pdim == 2 ); - TEST_CHECK( vlasov->conf_range.volume == 100 ); + TEST_CHECK(vlasov->cdim == 1); + TEST_CHECK(vlasov->pdim == 2); + TEST_CHECK(vlasov->conf_range.volume == 100); /* int nfail = cu_vlasov_test(eqn->on_dev); */ @@ -76,9 +74,9 @@ test_dg_vlasov_dev() #endif TEST_LIST = { - { "dg_vlasov_ho", test_dg_vlasov_ho }, + {"dg_vlasov_ho", test_dg_vlasov_ho}, #ifdef GKYL_HAVE_CUDA - { "dg_vlasov_dev", test_dg_vlasov_dev }, -#endif - { NULL, NULL }, + {"dg_vlasov_dev", test_dg_vlasov_dev}, +#endif + {NULL, NULL} }; diff --git a/vlasov/unit/ctest_hyper3x_dg.c b/vlasov/unit/ctest_hyper3x_dg.c index caa2aded02..9896ef181b 100644 --- a/vlasov/unit/ctest_hyper3x_dg.c +++ b/vlasov/unit/ctest_hyper3x_dg.c @@ -9,14 +9,14 @@ #include #include -static struct gkyl_array* -mkarr1(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr1(bool use_gpu, long nc, long size) { - struct gkyl_array* a; - if (use_gpu) + struct gkyl_array *a; + if (use_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } @@ -24,12 +24,11 @@ mkarr1(bool use_gpu, long nc, long size) int hyper_dg_kernel_test(const gkyl_hyper_dg *slvr); -void -test_vlasov_3x3v_p1_(bool use_gpu) +void test_vlasov_3x3v_p1_(bool use_gpu) { // initialize grid and ranges int cdim = 3, vdim = 3; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int cells[] = {8, 8, 8, 8, 8, 8}; int ghost[] = {1, 1, 1, 0, 0, 0}; @@ -62,27 +61,29 @@ test_vlasov_3x3v_p1_(bool use_gpu) struct gkyl_dg_eqn *eqn; enum gkyl_field_id field_id = GKYL_FIELD_NULL; enum gkyl_model_id model_id = GKYL_MODEL_DEFAULT; - eqn = gkyl_dg_vlasov_new(&confBasis, &basis, &confRange, &phaseRange, model_id, field_id, use_gpu); + eqn = + gkyl_dg_vlasov_new(&confBasis, &basis, &confRange, &phaseRange, model_id, field_id, use_gpu); - // initialize hyper_dg slvr + // initialize hyper_dg slvr // FIELD_NULL so only configuration space update, no velocity space update int up_dirs[GKYL_MAX_DIM] = {0, 1, 2}; - int zero_flux_flags[2*GKYL_MAX_DIM] = {0, 0, 0, 0, 0, 0}; - int num_up_dirs = cdim; + int zero_flux_flags[2 * GKYL_MAX_DIM] = {0, 0, 0, 0, 0, 0}; + int num_up_dirs = cdim; gkyl_hyper_dg *slvr; - slvr = gkyl_hyper_dg_new(&phaseGrid, &basis, eqn, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu); + slvr = + gkyl_hyper_dg_new(&phaseGrid, &basis, eqn, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu); // initialize arrays struct gkyl_array *fin, *rhs, *cflrate; struct gkyl_array *fin_h, *rhs_h; - + fin = mkarr1(use_gpu, basis.num_basis, phaseRange_ext.volume); rhs = mkarr1(use_gpu, basis.num_basis, phaseRange_ext.volume); cflrate = mkarr1(use_gpu, 1, phaseRange_ext.volume); // set initial condition - int nf = phaseRange_ext.volume*basis.num_basis; + int nf = phaseRange_ext.volume * basis.num_basis; double *fin_d; if (use_gpu) { fin_h = mkarr1(false, basis.num_basis, phaseRange_ext.volume); @@ -90,19 +91,22 @@ test_vlasov_3x3v_p1_(bool use_gpu) } else { fin_d = fin->data; } - for(int i=0; i< nf; i++) { - fin_d[i] = (double)(2*i+11 % nf) / nf * ((i%2 == 0) ? 1 : -1); + for (int i = 0; i < nf; i++) { + fin_d[i] = (double)(2 * i + 11 % nf) / nf * ((i % 2 == 0) ? 1 : -1); + } + if (use_gpu) { + gkyl_array_copy(fin, fin_h); } - if (use_gpu) gkyl_array_copy(fin, fin_h); // run hyper_dg_advance int nrep = 10; - for(int n=0; nncomp; i++) printf("%.16e\n", rhs_d[i]); //for(int i=0; incomp; i++) printf(" TEST_CHECK( gkyl_compare_double(rhs_d[%d], %.16e, 1e-12) );\n", i, rhs_d[i]); - TEST_CHECK( gkyl_compare_double(rhs_d[0], 3.8735549798502387e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[1], 1.6959259934263994e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[2], -4.8984121582866758e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[3], 5.0094536289262006e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[4], -1.2449694827016953e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[5], 3.5633095838952239e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[6], 3.4307333299092484e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[7], 2.5317237348814032e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[8], -2.5305142336381611e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[9], 1.6976562666517527e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[10], -1.3188217206179452e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[11], 1.1566279578878277e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[12], -1.0487240328165591e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[13], 9.4320746037960195e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[14], -9.4533250999594411e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[15], 1.0693888393608047e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[16], 3.3731060719665238e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[17], 1.4232063291190894e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[18], -1.1238200859276988e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[19], 8.4493461115432069e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[20], 3.7168983240080964e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[21], -3.4422939181393599e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[22], -3.5083447363027062e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[23], 2.1375305784636044e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[24], -2.0825739029971018e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[25], 1.7488681040300975e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[26], -2.0179782511044245e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[27], 2.0435157947684868e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[28], -1.6636355898951987e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[29], 1.3442391639742803e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[30], -1.0853876848206312e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[31], 1.0965697471325935e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[32], -2.0951764524448709e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[33], 1.9681787690876064e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[34], -1.6327928661319586e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[35], 1.5449923691405468e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[36], -1.0957323983061325e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[37], 9.7521904885660291e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[38], -1.4225790936968075e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[39], 1.0938543097641011e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[40], -1.0386797997392399e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[41], -3.4880098226412404e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[42], -3.2719711091781413e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[43], 3.4275232843717916e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[44], -2.2836372706768060e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[45], 2.0046113232551104e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[46], -1.6286898011836502e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[47], 3.6396222957973507e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[48], -1.8214304335963199e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[49], 1.9421272746405052e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[50], -2.1630418974003465e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[51], 2.3930071574221582e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[52], -2.2853209071137993e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[53], 2.3025619211231863e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[54], -1.5458366066464473e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[55], 7.1515312063012813e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[56], -7.0629012979087076e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[57], 3.5412075288314718e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[58], -3.2236018558034843e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[59], 2.6160256284435640e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[60], -2.3954488886068940e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[61], 2.4102710211474815e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[62], -1.2413660608970357e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[63], 3.1404312005369288e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[64], 3.8478463062984543e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[65], 1.6383893567995464e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[66], -9.8254789277861470e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[67], 1.0874361679351932e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[68], 3.4860754298984871e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[69], -4.0144054180961835e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[70], -2.2701650346193428e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[71], 2.0111297913693406e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[72], -2.0080280134615986e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[73], 1.4867323173528218e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[74], -4.7783457601632309e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[75], 4.8533857084924703e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[76], -1.7159060407537222e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[77], 6.5386083037954048e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[78], -6.4865099825069255e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[79], 9.2319002778701043e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[80], -2.9241883912606315e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[81], 2.7051634774399659e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[82], -2.6999541275348928e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[83], 1.6379088171963765e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[84], -2.3768994612383693e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[85], 2.3844039231662258e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[86], -1.3397291027561050e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[87], 1.1915163460450563e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[88], -1.1526371087392411e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[89], 8.9360187378766600e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[90], -3.5968321533258347e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[91], 3.5646551271490665e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[92], -1.9084162474935276e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[93], 2.0133047360266591e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[94], -1.5776559149735849e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[95], 3.3655193755196017e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[96], 3.4765338749530885e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[97], 1.4286349564885294e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[98], -1.0112338482133872e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[99], 1.1150930863744215e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[100], 3.4518779637733150e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[101], -3.8558779637733149e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[102], -2.1677973959573716e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[103], 2.0592000772753732e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[104], -1.8526642147186362e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[105], 1.4725144649176752e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[106], -4.8521922798635471e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[107], 4.8411612448282195e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[108], -1.6957738962444672e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[109], 5.0229451664849600e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[110], -6.5552330699909449e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[111], 9.5738749391218370e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[112], -3.0587723580006806e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[113], 2.7061391432184497e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[114], -2.7135368204699201e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[115], 1.6658891463003339e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[116], -2.5232806031213709e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[117], 2.3727686083107582e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[118], -1.5348828550137744e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[119], 1.2053183736637598e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[120], -1.1410362029896483e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[121], 8.9018513779220996e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[122], -3.5401022042449036e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[123], 3.3559361556510758e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[124], -1.9028085031190408e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[125], 1.9995127996263243e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[126], -1.5892669582706860e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[127], 3.3599151830280540e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[128], 3.4338880304476271e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[129], 1.4269014807977600e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[130], -1.1635169628913534e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[131], 9.6639648064887425e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[132], 3.4738880304476267e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[133], -3.8338880304476275e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[134], -2.1630741319338554e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[135], 2.0676527431156593e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[136], -1.8565090575750190e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[137], 1.4728594501959885e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[138], -4.7295692886806586e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[139], 4.9222976237120477e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[140], -1.6896409618195747e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[141], 6.5060001864290484e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[142], -5.0282663545078714e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[143], 9.7937742723787069e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[144], -3.0588791152729172e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[145], 2.7152337758829059e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[146], -2.7054978742680060e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[147], 1.6664574133151095e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[148], -2.3674068408778592e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[149], 2.5247172067018912e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[150], -1.5248151675977429e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[151], 1.2031229322141296e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[152], -9.9197930392987512e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[153], 1.0353108517654821e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[154], -3.4020199323497820e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[155], 3.3660199786841687e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[156], -2.0518750723189335e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[157], 1.8543965617470551e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[158], -1.5910122910463183e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[159], 3.3616635264207474e+01, 1e-12) ); + TEST_CHECK(gkyl_compare_double(rhs_d[0], 3.8735549798502387e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[1], 1.6959259934263994e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[2], -4.8984121582866758e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[3], 5.0094536289262006e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[4], -1.2449694827016953e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[5], 3.5633095838952239e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[6], 3.4307333299092484e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[7], 2.5317237348814032e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[8], -2.5305142336381611e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[9], 1.6976562666517527e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[10], -1.3188217206179452e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[11], 1.1566279578878277e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[12], -1.0487240328165591e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[13], 9.4320746037960195e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[14], -9.4533250999594411e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[15], 1.0693888393608047e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[16], 3.3731060719665238e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[17], 1.4232063291190894e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[18], -1.1238200859276988e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[19], 8.4493461115432069e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[20], 3.7168983240080964e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[21], -3.4422939181393599e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[22], -3.5083447363027062e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[23], 2.1375305784636044e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[24], -2.0825739029971018e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[25], 1.7488681040300975e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[26], -2.0179782511044245e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[27], 2.0435157947684868e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[28], -1.6636355898951987e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[29], 1.3442391639742803e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[30], -1.0853876848206312e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[31], 1.0965697471325935e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[32], -2.0951764524448709e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[33], 1.9681787690876064e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[34], -1.6327928661319586e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[35], 1.5449923691405468e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[36], -1.0957323983061325e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[37], 9.7521904885660291e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[38], -1.4225790936968075e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[39], 1.0938543097641011e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[40], -1.0386797997392399e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[41], -3.4880098226412404e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[42], -3.2719711091781413e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[43], 3.4275232843717916e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[44], -2.2836372706768060e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[45], 2.0046113232551104e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[46], -1.6286898011836502e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[47], 3.6396222957973507e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[48], -1.8214304335963199e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[49], 1.9421272746405052e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[50], -2.1630418974003465e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[51], 2.3930071574221582e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[52], -2.2853209071137993e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[53], 2.3025619211231863e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[54], -1.5458366066464473e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[55], 7.1515312063012813e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[56], -7.0629012979087076e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[57], 3.5412075288314718e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[58], -3.2236018558034843e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[59], 2.6160256284435640e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[60], -2.3954488886068940e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[61], 2.4102710211474815e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[62], -1.2413660608970357e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[63], 3.1404312005369288e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[64], 3.8478463062984543e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[65], 1.6383893567995464e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[66], -9.8254789277861470e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[67], 1.0874361679351932e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[68], 3.4860754298984871e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[69], -4.0144054180961835e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[70], -2.2701650346193428e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[71], 2.0111297913693406e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[72], -2.0080280134615986e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[73], 1.4867323173528218e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[74], -4.7783457601632309e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[75], 4.8533857084924703e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[76], -1.7159060407537222e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[77], 6.5386083037954048e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[78], -6.4865099825069255e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[79], 9.2319002778701043e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[80], -2.9241883912606315e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[81], 2.7051634774399659e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[82], -2.6999541275348928e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[83], 1.6379088171963765e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[84], -2.3768994612383693e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[85], 2.3844039231662258e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[86], -1.3397291027561050e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[87], 1.1915163460450563e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[88], -1.1526371087392411e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[89], 8.9360187378766600e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[90], -3.5968321533258347e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[91], 3.5646551271490665e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[92], -1.9084162474935276e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[93], 2.0133047360266591e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[94], -1.5776559149735849e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[95], 3.3655193755196017e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[96], 3.4765338749530885e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[97], 1.4286349564885294e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[98], -1.0112338482133872e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[99], 1.1150930863744215e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[100], 3.4518779637733150e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[101], -3.8558779637733149e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[102], -2.1677973959573716e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[103], 2.0592000772753732e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[104], -1.8526642147186362e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[105], 1.4725144649176752e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[106], -4.8521922798635471e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[107], 4.8411612448282195e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[108], -1.6957738962444672e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[109], 5.0229451664849600e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[110], -6.5552330699909449e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[111], 9.5738749391218370e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[112], -3.0587723580006806e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[113], 2.7061391432184497e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[114], -2.7135368204699201e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[115], 1.6658891463003339e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[116], -2.5232806031213709e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[117], 2.3727686083107582e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[118], -1.5348828550137744e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[119], 1.2053183736637598e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[120], -1.1410362029896483e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[121], 8.9018513779220996e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[122], -3.5401022042449036e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[123], 3.3559361556510758e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[124], -1.9028085031190408e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[125], 1.9995127996263243e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[126], -1.5892669582706860e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[127], 3.3599151830280540e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[128], 3.4338880304476271e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[129], 1.4269014807977600e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[130], -1.1635169628913534e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[131], 9.6639648064887425e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[132], 3.4738880304476267e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[133], -3.8338880304476275e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[134], -2.1630741319338554e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[135], 2.0676527431156593e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[136], -1.8565090575750190e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[137], 1.4728594501959885e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[138], -4.7295692886806586e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[139], 4.9222976237120477e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[140], -1.6896409618195747e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[141], 6.5060001864290484e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[142], -5.0282663545078714e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[143], 9.7937742723787069e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[144], -3.0588791152729172e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[145], 2.7152337758829059e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[146], -2.7054978742680060e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[147], 1.6664574133151095e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[148], -2.3674068408778592e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[149], 2.5247172067018912e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[150], -1.5248151675977429e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[151], 1.2031229322141296e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[152], -9.9197930392987512e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[153], 1.0353108517654821e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[154], -3.4020199323497820e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[155], 3.3660199786841687e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[156], -2.0518750723189335e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[157], 1.8543965617470551e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[158], -1.5910122910463183e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[159], 3.3616635264207474e+01, 1e-12)); -/* // get linear index of some other cell */ -/* // 1-indexed for interfacing with G2 Lua layer */ + /* // get linear index of some other cell */ + /* // 1-indexed for interfacing with G2 Lua layer */ int idx2[] = {6, 3, 5, 8, 2, 1}; int linl2 = gkyl_range_idx(&phaseRange, idx2); rhs_d = gkyl_array_fetch(rhs_h, linl2); @@ -302,166 +308,166 @@ test_vlasov_3x3v_p1_(bool use_gpu) // printf("second cell rhs\n"); //for(int i=0; incomp; i++) printf("%.16e\n", rhs_d[i]); //for(int i=0; incomp; i++) printf(" TEST_CHECK( gkyl_compare_double(rhs_d[%d], %.16e, 1e-12) );\n", i, rhs_d[i]); - TEST_CHECK( gkyl_compare_double(rhs_d[0], 7.0283701215299565e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[1], 4.7846177739417136e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[2], -3.2440580569657463e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[3], 4.7834435172957100e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[4], -3.3964806386044817e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[5], 3.6656129906922845e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[6], 1.0600153622120099e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[7], 9.8197929504110462e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[8], -1.1346864925832745e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[9], 9.9519188298106030e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[10], -3.8427607132713874e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[11], 4.6685208259857504e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[12], -6.1166112907734686e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[13], 5.0806785012409009e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[14], -3.4404297692371081e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[15], 6.1730531849577105e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[16], 1.3601589806692580e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[17], 5.5606774714677393e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[18], -4.6853462430480434e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[19], 4.8960263481450980e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[20], 9.8840947991088379e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[21], -1.0715759504421176e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[22], -1.5649149976122467e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[23], 9.0646874012320907e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[24], -1.0551869062512243e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[25], 9.9534967043384000e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[26], -8.9669280348657580e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[27], 1.0859866842168806e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[28], -9.5787783660800088e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[29], 5.9003194017868232e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[30], -4.2858735788656148e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[31], 6.1644570050895027e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[32], -9.3693889519560514e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[33], 1.0459267060273295e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[34], -9.6279354665355200e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[35], 5.1838536940564353e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[36], -4.6930351157227243e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[37], 5.7893976582206406e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[38], -5.5600505574220719e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[39], 4.2501170277772061e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[40], -5.7370813214632818e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[41], -7.5952097854402589e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[42], -1.5112521038242042e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[43], 1.5166281201815158e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[44], -9.3845022817631502e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[45], 9.5950426777163528e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[46], -9.5028250006771700e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[47], 1.4343455956661325e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[48], -8.8669420429927314e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[49], 1.1596206998529810e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[50], -9.9656228044263742e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[51], 8.9575579031755979e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[52], -1.0405867197686671e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[53], 1.1273492436504714e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[54], -5.2423958891702576e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[55], 4.5661639299989652e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[56], -6.0855838051600962e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[57], 1.4781355074540281e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[58], -1.2684443586352376e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[59], 1.2637828515811871e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[60], -8.1030760766532168e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[61], 9.6461812198928470e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[62], -7.3547047664692542e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[63], 1.4322009894672004e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[64], 7.1935746220124452e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[65], 4.7913444708426276e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[66], -3.7409857712756967e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[67], 6.1153234258921039e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[68], 1.0731283386012138e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[69], -8.8591657399897272e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[70], -8.6398599759795090e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[71], 9.2095110512420121e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[72], -9.5968996273635057e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[73], 5.5514941660377154e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[74], -3.3078263954184003e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[75], 4.8436138128923325e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[76], -4.7834501948352298e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[77], 4.1396081713442648e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[78], -5.6626818497470516e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[79], 3.4747011836898047e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[80], -1.4264972931737645e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[81], 9.0887141852893933e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[82], -1.0611788447974614e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[83], 9.9679463000264775e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[84], -8.8872500641148591e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[85], 1.0423038256781317e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[86], -8.2151469282290449e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[87], 4.2729166191391300e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[88], -4.6960818962577818e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[89], 5.2657335222913041e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[90], -1.3954254583181825e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[91], 1.3993631687859335e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[92], -8.4764645663605506e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[93], 1.0850803211201104e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[94], -9.0949727090642483e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[95], 1.4720160200709708e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[96], 1.1058159072558467e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[97], 5.5661072828562872e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[98], -3.8038399453442359e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[99], 6.1387574319713288e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[100], 1.0811599960760687e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[101], -6.8515999607606970e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[102], -7.7181652109862142e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[103], 9.1271728627705045e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[104], -8.7568400872410479e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[105], 5.5961302495084126e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[106], -3.3578250907422031e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[107], 4.8466142788859123e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[108], -4.7844638330728891e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[109], 3.2949002915137193e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[110], -5.6653312461354503e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[111], 3.4666695262149414e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[112], -1.5147327839312067e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[113], 9.0008888762480964e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[114], -1.0574963170297912e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[115], 9.8817565354966675e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[116], -9.7729562651682940e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[117], 1.0461811224142504e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[118], -9.0234403715862186e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[119], 4.2278649030128754e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[120], -4.6503108968744243e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[121], 5.2665396986558520e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[122], -1.5562513629902506e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[123], 1.4807822157984455e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[124], -8.5681017412682138e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[125], 1.0895865064874867e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[126], -9.1407519709951146e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[127], 1.4811801000515698e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[128], 1.0631700627503820e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[129], 5.5643743484313944e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[130], -4.6450398387617000e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[131], 5.3011431100062829e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[132], 1.1031700627503864e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[133], -6.6317006275038415e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[134], -7.6750483997030528e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[135], 9.1740170558386822e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[136], -8.7606839925974327e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[137], 5.5964757760526041e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[138], -3.3071697856301448e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[139], 4.8931199852680621e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[140], -4.7783303573821193e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[141], 4.1321225722476250e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[142], -4.8237168583476468e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[143], 3.4886594595406240e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[144], -1.5147434200350182e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[145], 9.0483740986404442e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[146], -1.0528531614336353e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[147], 9.8823238650114433e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[148], -8.9281643904511640e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[149], 1.1302678080039013e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[150], -9.0133717466701867e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[151], 4.2256689202973689e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[152], -3.8123353440751522e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[153], 6.1005831288686224e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[154], -1.4773905314027536e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[155], 1.4817905584783423e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[156], -9.4060856304734799e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[157], 1.0061831652021979e+02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[158], -9.1424963662707484e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[159], 1.4813548947674269e+02, 1e-12) ); + TEST_CHECK(gkyl_compare_double(rhs_d[0], 7.0283701215299565e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[1], 4.7846177739417136e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[2], -3.2440580569657463e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[3], 4.7834435172957100e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[4], -3.3964806386044817e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[5], 3.6656129906922845e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[6], 1.0600153622120099e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[7], 9.8197929504110462e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[8], -1.1346864925832745e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[9], 9.9519188298106030e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[10], -3.8427607132713874e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[11], 4.6685208259857504e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[12], -6.1166112907734686e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[13], 5.0806785012409009e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[14], -3.4404297692371081e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[15], 6.1730531849577105e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[16], 1.3601589806692580e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[17], 5.5606774714677393e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[18], -4.6853462430480434e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[19], 4.8960263481450980e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[20], 9.8840947991088379e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[21], -1.0715759504421176e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[22], -1.5649149976122467e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[23], 9.0646874012320907e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[24], -1.0551869062512243e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[25], 9.9534967043384000e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[26], -8.9669280348657580e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[27], 1.0859866842168806e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[28], -9.5787783660800088e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[29], 5.9003194017868232e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[30], -4.2858735788656148e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[31], 6.1644570050895027e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[32], -9.3693889519560514e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[33], 1.0459267060273295e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[34], -9.6279354665355200e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[35], 5.1838536940564353e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[36], -4.6930351157227243e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[37], 5.7893976582206406e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[38], -5.5600505574220719e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[39], 4.2501170277772061e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[40], -5.7370813214632818e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[41], -7.5952097854402589e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[42], -1.5112521038242042e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[43], 1.5166281201815158e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[44], -9.3845022817631502e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[45], 9.5950426777163528e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[46], -9.5028250006771700e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[47], 1.4343455956661325e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[48], -8.8669420429927314e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[49], 1.1596206998529810e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[50], -9.9656228044263742e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[51], 8.9575579031755979e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[52], -1.0405867197686671e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[53], 1.1273492436504714e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[54], -5.2423958891702576e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[55], 4.5661639299989652e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[56], -6.0855838051600962e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[57], 1.4781355074540281e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[58], -1.2684443586352376e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[59], 1.2637828515811871e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[60], -8.1030760766532168e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[61], 9.6461812198928470e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[62], -7.3547047664692542e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[63], 1.4322009894672004e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[64], 7.1935746220124452e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[65], 4.7913444708426276e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[66], -3.7409857712756967e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[67], 6.1153234258921039e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[68], 1.0731283386012138e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[69], -8.8591657399897272e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[70], -8.6398599759795090e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[71], 9.2095110512420121e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[72], -9.5968996273635057e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[73], 5.5514941660377154e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[74], -3.3078263954184003e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[75], 4.8436138128923325e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[76], -4.7834501948352298e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[77], 4.1396081713442648e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[78], -5.6626818497470516e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[79], 3.4747011836898047e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[80], -1.4264972931737645e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[81], 9.0887141852893933e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[82], -1.0611788447974614e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[83], 9.9679463000264775e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[84], -8.8872500641148591e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[85], 1.0423038256781317e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[86], -8.2151469282290449e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[87], 4.2729166191391300e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[88], -4.6960818962577818e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[89], 5.2657335222913041e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[90], -1.3954254583181825e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[91], 1.3993631687859335e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[92], -8.4764645663605506e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[93], 1.0850803211201104e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[94], -9.0949727090642483e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[95], 1.4720160200709708e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[96], 1.1058159072558467e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[97], 5.5661072828562872e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[98], -3.8038399453442359e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[99], 6.1387574319713288e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[100], 1.0811599960760687e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[101], -6.8515999607606970e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[102], -7.7181652109862142e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[103], 9.1271728627705045e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[104], -8.7568400872410479e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[105], 5.5961302495084126e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[106], -3.3578250907422031e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[107], 4.8466142788859123e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[108], -4.7844638330728891e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[109], 3.2949002915137193e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[110], -5.6653312461354503e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[111], 3.4666695262149414e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[112], -1.5147327839312067e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[113], 9.0008888762480964e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[114], -1.0574963170297912e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[115], 9.8817565354966675e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[116], -9.7729562651682940e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[117], 1.0461811224142504e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[118], -9.0234403715862186e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[119], 4.2278649030128754e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[120], -4.6503108968744243e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[121], 5.2665396986558520e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[122], -1.5562513629902506e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[123], 1.4807822157984455e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[124], -8.5681017412682138e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[125], 1.0895865064874867e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[126], -9.1407519709951146e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[127], 1.4811801000515698e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[128], 1.0631700627503820e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[129], 5.5643743484313944e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[130], -4.6450398387617000e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[131], 5.3011431100062829e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[132], 1.1031700627503864e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[133], -6.6317006275038415e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[134], -7.6750483997030528e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[135], 9.1740170558386822e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[136], -8.7606839925974327e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[137], 5.5964757760526041e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[138], -3.3071697856301448e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[139], 4.8931199852680621e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[140], -4.7783303573821193e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[141], 4.1321225722476250e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[142], -4.8237168583476468e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[143], 3.4886594595406240e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[144], -1.5147434200350182e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[145], 9.0483740986404442e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[146], -1.0528531614336353e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[147], 9.8823238650114433e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[148], -8.9281643904511640e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[149], 1.1302678080039013e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[150], -9.0133717466701867e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[151], 4.2256689202973689e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[152], -3.8123353440751522e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[153], 6.1005831288686224e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[154], -1.4773905314027536e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[155], 1.4817905584783423e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[156], -9.4060856304734799e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[157], 1.0061831652021979e+02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[158], -9.1424963662707484e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[159], 1.4813548947674269e+02, 1e-12)); // clean up gkyl_array_release(fin); @@ -477,14 +483,9 @@ test_vlasov_3x3v_p1_(bool use_gpu) } } -void -test_hyper3x_dg_vlasov_3x3v_p1_ho() +void test_hyper3x_dg_vlasov_3x3v_p1_ho() { test_vlasov_3x3v_p1_(false); } -TEST_LIST = { - { "test_hyper3x_dg_vlasov_3x3v_p1_ho", test_hyper3x_dg_vlasov_3x3v_p1_ho }, - { NULL, NULL }, -}; - +TEST_LIST = {{"test_hyper3x_dg_vlasov_3x3v_p1_ho", test_hyper3x_dg_vlasov_3x3v_p1_ho}, {NULL, NULL}}; diff --git a/vlasov/unit/ctest_hyper_dg.c b/vlasov/unit/ctest_hyper_dg.c index 027e26d868..9e493bd0d5 100644 --- a/vlasov/unit/ctest_hyper_dg.c +++ b/vlasov/unit/ctest_hyper_dg.c @@ -10,14 +10,14 @@ #include #include -static struct gkyl_array* -mkarr1(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr1(bool use_gpu, long nc, long size) { - struct gkyl_array* a; - if (use_gpu) + struct gkyl_array *a; + if (use_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } @@ -25,12 +25,11 @@ mkarr1(bool use_gpu, long nc, long size) int hyper_dg_kernel_test(const gkyl_hyper_dg *slvr); -void -test_vlasov_1x2v_p2_(bool use_gpu) +void test_vlasov_1x2v_p2_(bool use_gpu) { // initialize grid and ranges int cdim = 1, vdim = 2; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int cells[] = {24, 12, 12}; int ghost[] = {1, 0, 0}; @@ -63,11 +62,12 @@ test_vlasov_1x2v_p2_(bool use_gpu) struct gkyl_dg_eqn *eqn; enum gkyl_field_id field_id = GKYL_FIELD_E_B; enum gkyl_model_id model_id = GKYL_MODEL_DEFAULT; - eqn = gkyl_dg_vlasov_new(&confBasis, &basis, &confRange, &phaseRange, model_id, field_id, use_gpu); + eqn = + gkyl_dg_vlasov_new(&confBasis, &basis, &confRange, &phaseRange, model_id, field_id, use_gpu); // initialize hyper_dg slvr int up_dirs[GKYL_MAX_DIM] = {0, 1, 2}; - int zero_flux_flags[2*GKYL_MAX_DIM] = {0, 1, 1, 0, 1, 1}; + int zero_flux_flags[2 * GKYL_MAX_DIM] = {0, 1, 1, 0, 1, 1}; gkyl_hyper_dg *slvr; slvr = gkyl_hyper_dg_new(&phaseGrid, &basis, eqn, pdim, up_dirs, zero_flux_flags, 1, use_gpu); @@ -75,20 +75,21 @@ test_vlasov_1x2v_p2_(bool use_gpu) // initialize arrays struct gkyl_array *fin, *rhs, *cflrate, *qmem; struct gkyl_array *fin_h, *qmem_h, *rhs_h; - + fin = mkarr1(use_gpu, basis.num_basis, phaseRange_ext.volume); rhs = mkarr1(use_gpu, basis.num_basis, phaseRange_ext.volume); cflrate = mkarr1(use_gpu, 1, phaseRange_ext.volume); - qmem = mkarr1(use_gpu, 8*confBasis.num_basis, confRange_ext.volume); + qmem = mkarr1(use_gpu, 8 * confBasis.num_basis, confRange_ext.volume); double *cfl_ptr; - if (use_gpu) + if (use_gpu) { cfl_ptr = gkyl_cu_malloc(sizeof(double)); - else + } else { cfl_ptr = gkyl_malloc(sizeof(double)); + } // set initial condition - int nf = phaseRange_ext.volume*basis.num_basis; + int nf = phaseRange_ext.volume * basis.num_basis; double *fin_d; if (use_gpu) { fin_h = mkarr1(false, basis.num_basis, phaseRange_ext.volume); @@ -96,32 +97,38 @@ test_vlasov_1x2v_p2_(bool use_gpu) } else { fin_d = fin->data; } - for(int i=0; i< nf; i++) { - fin_d[i] = (double)(2*i+11 % nf) / nf * ((i%2 == 0) ? 1 : -1); + for (int i = 0; i < nf; i++) { + fin_d[i] = (double)(2 * i + 11 % nf) / nf * ((i % 2 == 0) ? 1 : -1); + } + if (use_gpu) { + gkyl_array_copy(fin, fin_h); } - if (use_gpu) gkyl_array_copy(fin, fin_h); - int nem = confRange_ext.volume*confBasis.num_basis; + int nem = confRange_ext.volume * confBasis.num_basis; double *qmem_d; if (use_gpu) { - qmem_h = mkarr1(false, 8*confBasis.num_basis, confRange_ext.volume); + qmem_h = mkarr1(false, 8 * confBasis.num_basis, confRange_ext.volume); qmem_d = qmem_h->data; } else { qmem_d = qmem->data; } - for(int i=0; i< nem; i++) { - qmem_d[i] = (double)(-i+27 % nem) / nem * ((i%2 == 0) ? 1 : -1); + for (int i = 0; i < nem; i++) { + qmem_d[i] = (double)(-i + 27 % nem) / nem * ((i % 2 == 0) ? 1 : -1); + } + if (use_gpu) { + gkyl_array_copy(qmem, qmem_h); } - if (use_gpu) gkyl_array_copy(qmem, qmem_h); // run hyper_dg_advance int nrep = 10; - for(int n=0; nncomp; i++) printf("%.16e\n", rhs_d[i]); - TEST_CHECK( gkyl_compare_double(rhs_d[0], 1.1873679155168162e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[1], 2.2131609273296690e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[2], -5.1421989058620037e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[3], -2.1015559414749911e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[4], -3.1274299616328875e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[5], -5.7980678014735298e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[6], -5.1794065426655207e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[7], 1.6555476342162777e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[8], -3.7839306076374341e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[9], 6.0821819985513692e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[10], -3.0765279980185458e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[11], -2.4545628123190717e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[12], -1.1912775540624752e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[13], 9.1266993445490581e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[14], -4.5599700127748999e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[15], 1.1971791673432133e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[16], 3.6053906660129060e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[17], -2.4385757910567278e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[18], -1.1795732611711490e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[19], 1.8857755500762241e+01, 1e-12) ); + TEST_CHECK(gkyl_compare_double(rhs_d[0], 1.1873679155168162e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[1], 2.2131609273296690e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[2], -5.1421989058620037e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[3], -2.1015559414749911e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[4], -3.1274299616328875e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[5], -5.7980678014735298e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[6], -5.1794065426655207e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[7], 1.6555476342162777e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[8], -3.7839306076374341e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[9], 6.0821819985513692e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[10], -3.0765279980185458e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[11], -2.4545628123190717e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[12], -1.1912775540624752e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[13], 9.1266993445490581e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[14], -4.5599700127748999e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[15], 1.1971791673432133e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[16], 3.6053906660129060e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[17], -2.4385757910567278e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[18], -1.1795732611711490e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[19], 1.8857755500762241e+01, 1e-12)); // get linear index of some other cell // 1-indexed for interfacing with G2 Lua layer @@ -188,26 +198,26 @@ test_vlasov_1x2v_p2_(bool use_gpu) //printf("second cell rhs\n"); //for(int i=0; incomp; i++) printf("%.16e\n", rhs_d[i]); - TEST_CHECK( gkyl_compare_double(rhs_d[0], 7.9777292154304547e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[1], -2.7182122357080729e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[2], -3.1823319852967562e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[3], -1.3560732323031073e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[4], -9.3361523823747120e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[5], -6.4546439524194774e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[6], -3.0046857486230238e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[7], 5.7739758711920011e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[8], -5.5255780047650804e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[9], 5.4569313596808011e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[10], -9.3082985569032914e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[11], -5.9264062443889756e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[12], -3.4252162191461366e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[13], 5.2936631523369066e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[14], -5.5255780047650571e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[15], 3.7711009940704315e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[16], 2.8771855264879638e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[17], -5.8883885687489283e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[18], -3.4263348605987986e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[19], 4.1758987770172105e+01, 1e-12) ); + TEST_CHECK(gkyl_compare_double(rhs_d[0], 7.9777292154304547e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[1], -2.7182122357080729e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[2], -3.1823319852967562e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[3], -1.3560732323031073e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[4], -9.3361523823747120e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[5], -6.4546439524194774e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[6], -3.0046857486230238e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[7], 5.7739758711920011e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[8], -5.5255780047650804e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[9], 5.4569313596808011e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[10], -9.3082985569032914e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[11], -5.9264062443889756e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[12], -3.4252162191461366e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[13], 5.2936631523369066e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[14], -5.5255780047650571e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[15], 3.7711009940704315e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[16], 2.8771855264879638e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[17], -5.8883885687489283e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[18], -3.4263348605987986e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[19], 4.1758987770172105e+01, 1e-12)); // clean up gkyl_array_release(fin); @@ -221,21 +231,19 @@ test_vlasov_1x2v_p2_(bool use_gpu) if (use_gpu) { gkyl_cu_free(cfl_ptr); - + gkyl_array_release(fin_h); gkyl_array_release(qmem_h); - } - else { + } else { gkyl_free(cfl_ptr); } } -void -test_vlasov_2x3v_p1_(bool use_gpu) +void test_vlasov_2x3v_p1_(bool use_gpu) { // initialize grid and ranges int cdim = 2, vdim = 3; - int pdim = cdim+vdim; + int pdim = cdim + vdim; int cells[] = {8, 8, 8, 8, 8}; int ghost[] = {1, 1, 0, 0, 0}; @@ -268,11 +276,12 @@ test_vlasov_2x3v_p1_(bool use_gpu) struct gkyl_dg_eqn *eqn; enum gkyl_field_id field_id = GKYL_FIELD_E_B; enum gkyl_model_id model_id = GKYL_MODEL_DEFAULT; - eqn = gkyl_dg_vlasov_new(&confBasis, &basis, &confRange, &phaseRange, model_id, field_id, use_gpu); + eqn = + gkyl_dg_vlasov_new(&confBasis, &basis, &confRange, &phaseRange, model_id, field_id, use_gpu); // initialize hyper_dg slvr int up_dirs[GKYL_MAX_DIM] = {0, 1, 2, 3, 4}; - int zero_flux_flags[2*GKYL_MAX_DIM] = {0, 0, 1, 1, 1, 0, 0, 1, 1, 1}; + int zero_flux_flags[2 * GKYL_MAX_DIM] = {0, 0, 1, 1, 1, 0, 0, 1, 1, 1}; gkyl_hyper_dg *slvr; slvr = gkyl_hyper_dg_new(&phaseGrid, &basis, eqn, pdim, up_dirs, zero_flux_flags, 1, use_gpu); @@ -280,14 +289,14 @@ test_vlasov_2x3v_p1_(bool use_gpu) // initialize arrays struct gkyl_array *fin, *rhs, *cflrate, *qmem; struct gkyl_array *fin_h, *qmem_h, *rhs_h; - + fin = mkarr1(use_gpu, basis.num_basis, phaseRange_ext.volume); rhs = mkarr1(use_gpu, basis.num_basis, phaseRange_ext.volume); cflrate = mkarr1(use_gpu, 1, phaseRange_ext.volume); - qmem = mkarr1(use_gpu, 8*confBasis.num_basis, confRange_ext.volume); + qmem = mkarr1(use_gpu, 8 * confBasis.num_basis, confRange_ext.volume); // set initial condition - int nf = phaseRange_ext.volume*basis.num_basis; + int nf = phaseRange_ext.volume * basis.num_basis; double *fin_d; if (use_gpu) { fin_h = mkarr1(false, basis.num_basis, phaseRange_ext.volume); @@ -295,32 +304,38 @@ test_vlasov_2x3v_p1_(bool use_gpu) } else { fin_d = fin->data; } - for(int i=0; i< nf; i++) { - fin_d[i] = (double)(2*i+11 % nf) / nf * ((i%2 == 0) ? 1 : -1); + for (int i = 0; i < nf; i++) { + fin_d[i] = (double)(2 * i + 11 % nf) / nf * ((i % 2 == 0) ? 1 : -1); + } + if (use_gpu) { + gkyl_array_copy(fin, fin_h); } - if (use_gpu) gkyl_array_copy(fin, fin_h); - int nem = confRange_ext.volume*confBasis.num_basis; + int nem = confRange_ext.volume * confBasis.num_basis; double *qmem_d; if (use_gpu) { - qmem_h = mkarr1(false, 8*confBasis.num_basis, confRange_ext.volume); + qmem_h = mkarr1(false, 8 * confBasis.num_basis, confRange_ext.volume); qmem_d = qmem_h->data; } else { qmem_d = qmem->data; } - for(int i=0; i< nem; i++) { - qmem_d[i] = (double)(-i+27 % nem) / nem * ((i%2 == 0) ? 1 : -1); + for (int i = 0; i < nem; i++) { + qmem_d[i] = (double)(-i + 27 % nem) / nem * ((i % 2 == 0) ? 1 : -1); + } + if (use_gpu) { + gkyl_array_copy(qmem, qmem_h); } - if (use_gpu) gkyl_array_copy(qmem, qmem_h); // run hyper_dg_advance int nrep = 10; - for(int n=0; nncomp; i++) printf("%.16e\n", rhs_d[i]); - TEST_CHECK( gkyl_compare_double(rhs_d[0 ], 1.5583125504656174e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[1 ], 2.6228222340877672e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[2 ], 2.3673600178359444e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[3 ], 2.0445381301295842e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[4 ], 5.8009947700332258e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[5 ],-4.3951673951369203e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[6 ],-3.2740808507907353e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[7 ], 6.1685466145806656e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[8 ],-9.9225900289967033e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[9 ], 1.5556139476411834e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[10],-2.0649266813526133e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[11],-2.0472420155729774e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[12],-1.6861158492781747e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[13], 5.7160667881100276e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[14],-3.7334543012748869e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[15],-4.0631107293252215e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[16],-2.2368678996807198e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[17], 2.4975896418604588e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[18],-1.7766928843531296e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[19], 6.9681762700869800e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[20],-2.5402211148036020e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[21], 2.5963072988336688e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[22],-1.2065136079090388e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[23], 1.4311020988985428e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[24],-1.7307228807072821e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[25], 1.0648291736093665e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[26],-2.8942763774151025e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[27], 3.4876234221247344e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[28],-1.6213472698033865e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[29],-1.3152058297652811e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[30], 5.5160829801207081e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[31], 1.3248009285063111e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[32], 2.0626248834060192e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[33],-1.8675890171358858e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[34], 1.0700556896733145e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[35], 1.0267345121490179e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[36],-2.9814328597585448e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[37], 8.2810622260402198e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[38],-2.8000677504722145e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[39], 2.5161866916865655e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[40], 1.6582163376892304e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[41],-2.2287681627701883e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[42],-6.5143195699025309e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[43], 7.6733697089938193e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[44], 1.6105940484870842e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[45], 2.5284590774855953e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[46],-1.6803923116017092e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[47], 3.4993021915577259e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[48],-6.4429006203071723e-02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[49], 2.1373817491282676e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[50],-9.0822803896705562e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[51], 6.3081769272408259e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[52],-1.1470246109901016e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[53], 2.7774567065033185e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[54],-2.7118393077830891e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[55], 1.9747275150178819e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[56],-1.8774237677748375e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[57],-4.0091254392929780e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[58], 1.1181326827391735e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[59], 1.0012387003982573e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[60],-1.5378762139131592e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[61], 1.9579525074768895e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[62],-7.2504813611281804e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[63], 2.8594267179149174e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[64], 3.3960460641818287e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[65],-1.2671905220786885e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[66], 2.3465937131321578e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[67],-2.5018574073021767e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[68],-7.6358915438484063e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[69],-4.8114279712708772e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[70], 4.2101152078896291e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[71],-1.0127724148100189e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[72],-5.7706791067934295e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[73],-1.0415188306383120e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[74],-5.6167239912421829e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[75], 3.9890443806074821e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[76],-2.0747338814618409e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[77], 2.6252175357150804e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[78],-1.5452629233319728e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[79], 3.5165336694630724e+01, 1e-12) ); + // printf("first cell rhs\n"); + // for(int i=0; incomp; i++) printf("%.16e\n", rhs_d[i]); + TEST_CHECK(gkyl_compare_double(rhs_d[0], 1.5583125504656174e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[1], 2.6228222340877672e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[2], 2.3673600178359444e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[3], 2.0445381301295842e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[4], 5.8009947700332258e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[5], -4.3951673951369203e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[6], -3.2740808507907353e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[7], 6.1685466145806656e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[8], -9.9225900289967033e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[9], 1.5556139476411834e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[10], -2.0649266813526133e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[11], -2.0472420155729774e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[12], -1.6861158492781747e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[13], 5.7160667881100276e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[14], -3.7334543012748869e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[15], -4.0631107293252215e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[16], -2.2368678996807198e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[17], 2.4975896418604588e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[18], -1.7766928843531296e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[19], 6.9681762700869800e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[20], -2.5402211148036020e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[21], 2.5963072988336688e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[22], -1.2065136079090388e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[23], 1.4311020988985428e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[24], -1.7307228807072821e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[25], 1.0648291736093665e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[26], -2.8942763774151025e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[27], 3.4876234221247344e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[28], -1.6213472698033865e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[29], -1.3152058297652811e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[30], 5.5160829801207081e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[31], 1.3248009285063111e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[32], 2.0626248834060192e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[33], -1.8675890171358858e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[34], 1.0700556896733145e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[35], 1.0267345121490179e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[36], -2.9814328597585448e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[37], 8.2810622260402198e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[38], -2.8000677504722145e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[39], 2.5161866916865655e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[40], 1.6582163376892304e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[41], -2.2287681627701883e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[42], -6.5143195699025309e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[43], 7.6733697089938193e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[44], 1.6105940484870842e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[45], 2.5284590774855953e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[46], -1.6803923116017092e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[47], 3.4993021915577259e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[48], -6.4429006203071723e-02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[49], 2.1373817491282676e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[50], -9.0822803896705562e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[51], 6.3081769272408259e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[52], -1.1470246109901016e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[53], 2.7774567065033185e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[54], -2.7118393077830891e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[55], 1.9747275150178819e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[56], -1.8774237677748375e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[57], -4.0091254392929780e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[58], 1.1181326827391735e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[59], 1.0012387003982573e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[60], -1.5378762139131592e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[61], 1.9579525074768895e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[62], -7.2504813611281804e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[63], 2.8594267179149174e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[64], 3.3960460641818287e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[65], -1.2671905220786885e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[66], 2.3465937131321578e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[67], -2.5018574073021767e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[68], -7.6358915438484063e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[69], -4.8114279712708772e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[70], 4.2101152078896291e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[71], -1.0127724148100189e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[72], -5.7706791067934295e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[73], -1.0415188306383120e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[74], -5.6167239912421829e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[75], 3.9890443806074821e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[76], -2.0747338814618409e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[77], 2.6252175357150804e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[78], -1.5452629233319728e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[79], 3.5165336694630724e+01, 1e-12)); // get linear index of some other cell // 1-indexed for interfacing with G2 Lua layer @@ -436,88 +453,88 @@ test_vlasov_2x3v_p1_(bool use_gpu) int linl2 = gkyl_range_idx(&phaseRange, idx2); rhs_d = gkyl_array_fetch(rhs_h, linl2); -// printf("second cell rhs\n"); -// for(int i=0; incomp; i++) printf("%.16e\n", rhs_d[i]); - TEST_CHECK( gkyl_compare_double(rhs_d[0 ], 4.7846096908267584e-02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[1 ], 1.1169581543468636e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[2 ],-5.7985569827277743e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[3 ], 6.3560588230111681e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[4 ],-3.8037040250162341e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[5 ], 3.1215390309173313e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[6 ],-5.9451450645977602e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[7 ], 1.4624629486937456e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[8 ],-4.9690031412084231e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[9 ], 3.5213109571593453e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[10],-6.0955021313238532e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[11], 2.6476452020050101e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[12],-3.5100041616767794e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[13], 4.8316996719345781e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[14],-6.1122488642299089e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[15], 7.9850069590596184e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[16],-6.4345760693277171e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[17], 5.5391125581775690e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[18],-7.3134438613368351e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[19], 5.2492380773845227e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[20],-6.0283166541522384e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[21], 7.9945201071625741e-02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[22],-5.7177859264242791e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[23], 1.0385552375417682e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[24],-4.5437126504480567e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[25], 7.7523547979949659e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[26],-5.2901252593887023e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[27], 5.6432376028981565e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[28],-6.3928564161796082e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[29], 1.4801034042997721e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[30],-6.1595791904709372e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[31], 6.8347478052667171e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[32], 7.7635047936775073e-02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[33], 1.1223967073645461e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[34],-4.8555037059507058e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[35], 1.2892406386095562e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[36],-3.9986417153680837e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[37], 6.1091198999195505e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[38],-1.1056795014088960e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[39], 4.8890197502476475e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[40],-3.2270859286785982e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[41], 4.8833583888325073e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[42], 5.4541037169184979e-02, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[43], 6.0485697373310906e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[44],-5.1988442558875640e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[45], 1.1184035513346096e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[46],-4.8157508893945355e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[47], 5.9610415538418607e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[48],-3.4882339711782762e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[49], 3.5298202468643511e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[50],-5.6203287350628727e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[51], 3.4882339711782717e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[52],-3.6695369052217031e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[53], 6.7906001630206347e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[54],-3.0448691264619017e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[55], 5.7296223828675863e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[56],-2.8163526802784560e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[57], 4.9266605122525164e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[58],-5.5910759361390594e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[59], 6.0312249472335431e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[60],-5.9820310601514130e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[61], 3.9298520202026186e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[62],-5.6639340789701137e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[63], 5.9784613439394072e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[64],-3.1215390309173785e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[65], 3.4700765537768121e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[66],-4.7918000752070810e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[67], 2.8905989232414975e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[68],-3.9094010767585058e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[69], 5.9660773305385845e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[70],-2.9851254333743560e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[71], 4.9050915156881537e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[72],-2.7772648983706874e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[73], 4.8843130373068703e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[74],-5.2000000000000235e-01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[75], 6.8558300614068344e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[76],-5.1539246260931648e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[77], 3.9101083271150761e+00, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[78],-4.8358250228732551e+01, 1e-12) ); - TEST_CHECK( gkyl_compare_double(rhs_d[79], 6.0284545971110632e+01, 1e-12) ); + // printf("second cell rhs\n"); + // for(int i=0; incomp; i++) printf("%.16e\n", rhs_d[i]); + TEST_CHECK(gkyl_compare_double(rhs_d[0], 4.7846096908267584e-02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[1], 1.1169581543468636e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[2], -5.7985569827277743e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[3], 6.3560588230111681e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[4], -3.8037040250162341e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[5], 3.1215390309173313e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[6], -5.9451450645977602e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[7], 1.4624629486937456e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[8], -4.9690031412084231e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[9], 3.5213109571593453e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[10], -6.0955021313238532e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[11], 2.6476452020050101e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[12], -3.5100041616767794e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[13], 4.8316996719345781e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[14], -6.1122488642299089e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[15], 7.9850069590596184e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[16], -6.4345760693277171e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[17], 5.5391125581775690e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[18], -7.3134438613368351e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[19], 5.2492380773845227e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[20], -6.0283166541522384e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[21], 7.9945201071625741e-02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[22], -5.7177859264242791e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[23], 1.0385552375417682e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[24], -4.5437126504480567e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[25], 7.7523547979949659e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[26], -5.2901252593887023e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[27], 5.6432376028981565e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[28], -6.3928564161796082e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[29], 1.4801034042997721e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[30], -6.1595791904709372e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[31], 6.8347478052667171e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[32], 7.7635047936775073e-02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[33], 1.1223967073645461e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[34], -4.8555037059507058e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[35], 1.2892406386095562e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[36], -3.9986417153680837e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[37], 6.1091198999195505e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[38], -1.1056795014088960e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[39], 4.8890197502476475e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[40], -3.2270859286785982e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[41], 4.8833583888325073e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[42], 5.4541037169184979e-02, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[43], 6.0485697373310906e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[44], -5.1988442558875640e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[45], 1.1184035513346096e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[46], -4.8157508893945355e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[47], 5.9610415538418607e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[48], -3.4882339711782762e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[49], 3.5298202468643511e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[50], -5.6203287350628727e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[51], 3.4882339711782717e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[52], -3.6695369052217031e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[53], 6.7906001630206347e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[54], -3.0448691264619017e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[55], 5.7296223828675863e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[56], -2.8163526802784560e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[57], 4.9266605122525164e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[58], -5.5910759361390594e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[59], 6.0312249472335431e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[60], -5.9820310601514130e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[61], 3.9298520202026186e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[62], -5.6639340789701137e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[63], 5.9784613439394072e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[64], -3.1215390309173785e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[65], 3.4700765537768121e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[66], -4.7918000752070810e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[67], 2.8905989232414975e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[68], -3.9094010767585058e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[69], 5.9660773305385845e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[70], -2.9851254333743560e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[71], 4.9050915156881537e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[72], -2.7772648983706874e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[73], 4.8843130373068703e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[74], -5.2000000000000235e-01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[75], 6.8558300614068344e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[76], -5.1539246260931648e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[77], 3.9101083271150761e+00, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[78], -4.8358250228732551e+01, 1e-12)); + TEST_CHECK(gkyl_compare_double(rhs_d[79], 6.0284545971110632e+01, 1e-12)); // clean up gkyl_array_release(fin); @@ -535,44 +552,39 @@ test_vlasov_2x3v_p1_(bool use_gpu) } } - -void -test_hyper_dg_vlasov_1x2v_p2_ho() +void test_hyper_dg_vlasov_1x2v_p2_ho() { test_vlasov_1x2v_p2_(false); } -void -test_hyper_dg_vlasov_1x2v_p2_dev() +void test_hyper_dg_vlasov_1x2v_p2_dev() { test_vlasov_1x2v_p2_(true); } -void -test_hyper_dg_vlasov_2x3v_p1_ho() +void test_hyper_dg_vlasov_2x3v_p1_ho() { test_vlasov_2x3v_p1_(false); } -void -test_hyper_dg_vlasov_2x3v_p1_dev() +void test_hyper_dg_vlasov_2x3v_p1_dev() { test_vlasov_2x3v_p1_(true); } #ifndef GKYL_HAVE_CUDA -int hyper_dg_kernel_test(const gkyl_hyper_dg *slvr) { +int hyper_dg_kernel_test(const gkyl_hyper_dg *slvr) +{ return 0; } #endif TEST_LIST = { - { "test_hyper_dg_vlasov_1x2v_p2_ho", test_hyper_dg_vlasov_1x2v_p2_ho }, - { "test_hyper_dg_vlasov_2x3v_p1_ho", test_hyper_dg_vlasov_2x3v_p1_ho }, + {"test_hyper_dg_vlasov_1x2v_p2_ho", test_hyper_dg_vlasov_1x2v_p2_ho}, + {"test_hyper_dg_vlasov_2x3v_p1_ho", test_hyper_dg_vlasov_2x3v_p1_ho}, #ifdef GKYL_HAVE_CUDA - { "test_hyper_dg_vlasov_1x2v_p2_dev", test_hyper_dg_vlasov_1x2v_p2_dev }, - { "test_hyper_dg_vlasov_2x3v_p1_dev", test_hyper_dg_vlasov_2x3v_p1_dev }, + {"test_hyper_dg_vlasov_1x2v_p2_dev", test_hyper_dg_vlasov_1x2v_p2_dev}, + {"test_hyper_dg_vlasov_2x3v_p1_dev", test_hyper_dg_vlasov_2x3v_p1_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; - diff --git a/vlasov/unit/ctest_mom_vlasov.c b/vlasov/unit/ctest_mom_vlasov.c index 559f2bb8c4..c94371d2e4 100644 --- a/vlasov/unit/ctest_mom_vlasov.c +++ b/vlasov/unit/ctest_mom_vlasov.c @@ -12,8 +12,7 @@ #include #include -void -test_mom_vlasov_ho() +void test_mom_vlasov_ho() { int poly_order = 2; struct gkyl_basis cbasis, pbasis; @@ -22,51 +21,49 @@ test_mom_vlasov_ho() struct gkyl_mom_type *m2ij = gkyl_mom_vlasov_new(&cbasis, &pbasis, GKYL_F_MOMENT_M2IJ, false); - TEST_CHECK( m2ij->cdim == 1 ); - TEST_CHECK( m2ij->pdim == 4 ); - TEST_CHECK( m2ij->poly_order == 2 ); - TEST_CHECK( m2ij->num_config == cbasis.num_basis ); - TEST_CHECK( m2ij->num_phase == pbasis.num_basis ); - TEST_CHECK( m2ij->num_mom == 6 ); + TEST_CHECK(m2ij->cdim == 1); + TEST_CHECK(m2ij->pdim == 4); + TEST_CHECK(m2ij->poly_order == 2); + TEST_CHECK(m2ij->num_config == cbasis.num_basis); + TEST_CHECK(m2ij->num_phase == pbasis.num_basis); + TEST_CHECK(m2ij->num_mom == 6); struct gkyl_mom_type *m3ijk = gkyl_mom_vlasov_new(&cbasis, &pbasis, GKYL_F_MOMENT_M3IJK, false); - TEST_CHECK( m3ijk->num_mom == 10 ); + TEST_CHECK(m3ijk->num_mom == 10); gkyl_mom_type_release(m2ij); gkyl_mom_type_release(m3ijk); } -void evalFunc(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], vx = xn[1]; - fout[0] = (x*x)*(vx-0.5)*(vx-0.5); + fout[0] = (x * x) * (vx - 0.5) * (vx - 0.5); } -void evalFuncSimple(double t, const double *xn, double* restrict fout, void *ctx) +void evalFuncSimple(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], vx = xn[1]; - fout[0] = 1./(2.0-(-2.0)); + fout[0] = 1. / (2.0 - (-2.0)); } -void evalFunc4d(double t, const double *xn, double* restrict fout, void *ctx) +void evalFunc4d(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], y = xn[1]; double vx = xn[2], vy = xn[3]; - fout[0] = (vx-1)*(vy-2); + fout[0] = (vx - 1) * (vy - 2); } // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { - struct gkyl_array* a = gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } // allocate cu_dev array -static struct gkyl_array* -mkarr_cu(long nc, long size) +static struct gkyl_array *mkarr_cu(long nc, long size) { - struct gkyl_array* a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); return a; } @@ -79,27 +76,28 @@ struct skin_ghost_ranges { }; // Create ghost and skin sub-ranges given a parent range -static void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { int ndim = parent->ndim; - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } -void -test_mom_vlasov_1x1v_p1_ho() +void test_mom_vlasov_1x1v_p1_ho() { int poly_order = 1; double lower[] = {-2.0, -2.0}, upper[] = {2.0, 2.0}; int cells[] = {4, 2}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int vdim = 1, cdim = 1; double confLower[] = {lower[0]}, confUpper[] = {upper[0]}; @@ -121,21 +119,21 @@ test_mom_vlasov_1x1v_p1_ho() } gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); - int confGhost[] = { 1 }; + int confGhost[] = {1}; struct gkyl_range confLocal, confLocal_ext; // local, local-ext conf-space ranges gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); struct skin_ghost_ranges confSkin_ghost; // conf-space skin/ghost skin_ghost_ranges_init(&confSkin_ghost, &confLocal_ext, confGhost); - int ghost[] = { confGhost[0], 0 }; + int ghost[] = {confGhost[0], 0}; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); struct skin_ghost_ranges skin_ghost; // phase-space skin/ghost skin_ghost_ranges_init(&skin_ghost, &local_ext, ghost); // projection updater for dist-function - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc, NULL); + gkyl_proj_on_basis *projDistf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc, NULL); // create distribution function array struct gkyl_array *distf; @@ -147,8 +145,9 @@ test_mom_vlasov_1x1v_p1_ho() struct gkyl_mom_type *vmM0_t = gkyl_mom_vlasov_new(&confBasis, &basis, GKYL_F_MOMENT_M0, false); struct gkyl_mom_type *vmM1i_t = gkyl_mom_vlasov_new(&confBasis, &basis, GKYL_F_MOMENT_M1, false); struct gkyl_mom_type *vmM2_t = gkyl_mom_vlasov_new(&confBasis, &basis, GKYL_F_MOMENT_M2, false); - struct gkyl_mom_type *int_t = gkyl_int_mom_vlasov_new(&confBasis, &basis, GKYL_F_MOMENT_M0M1M2, false); - + struct gkyl_mom_type *int_t = + gkyl_int_mom_vlasov_new(&confBasis, &basis, GKYL_F_MOMENT_M0M1M2, false); + gkyl_mom_calc *m0calc = gkyl_mom_calc_new(&grid, vmM0_t, false); gkyl_mom_calc *m1icalc = gkyl_mom_calc_new(&grid, vmM1i_t, false); gkyl_mom_calc *m2calc = gkyl_mom_calc_new(&grid, vmM2_t, false); @@ -157,59 +156,65 @@ test_mom_vlasov_1x1v_p1_ho() // create moment arrays struct gkyl_array *m0, *m1i, *m2, *int_mom; m0 = mkarr(confBasis.num_basis, confLocal_ext.volume); - m1i = mkarr(vdim*confBasis.num_basis, confLocal_ext.volume); + m1i = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(confBasis.num_basis, confLocal_ext.volume); - int_mom = mkarr(vdim+2, confLocal_ext.volume); - + int_mom = mkarr(vdim + 2, confLocal_ext.volume); + // compute the moments gkyl_mom_calc_advance(m0calc, &local, &confLocal, distf, m0); gkyl_mom_calc_advance(m1icalc, &local, &confLocal, distf, m1i); gkyl_mom_calc_advance(m2calc, &local, &confLocal, distf, m2); gkyl_mom_calc_advance(intcalc, &local, &confLocal, distf, int_mom); - + // Check M0. - double *m00 = gkyl_array_fetch(m0, 0+confGhost[0]); double *m01 = gkyl_array_fetch(m0, 1+confGhost[0]); - double *m02 = gkyl_array_fetch(m0, 2+confGhost[0]); double *m03 = gkyl_array_fetch(m0, 3+confGhost[0]); - TEST_CHECK( gkyl_compare( 20.898933755069070, m00[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -7.756717518813397, m00[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.985561965009867, m01[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -2.585572506271132, m01[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.985561965009867, m02[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.585572506271132, m02[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 20.898933755069070, m03[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 7.756717518813396, m03[1], 1e-12) ); + double *m00 = gkyl_array_fetch(m0, 0 + confGhost[0]); + double *m01 = gkyl_array_fetch(m0, 1 + confGhost[0]); + double *m02 = gkyl_array_fetch(m0, 2 + confGhost[0]); + double *m03 = gkyl_array_fetch(m0, 3 + confGhost[0]); + TEST_CHECK(gkyl_compare(20.898933755069070, m00[0], 1e-12)); + TEST_CHECK(gkyl_compare(-7.756717518813397, m00[1], 1e-12)); + TEST_CHECK(gkyl_compare(2.985561965009867, m01[0], 1e-12)); + TEST_CHECK(gkyl_compare(-2.585572506271132, m01[1], 1e-12)); + TEST_CHECK(gkyl_compare(2.985561965009867, m02[0], 1e-12)); + TEST_CHECK(gkyl_compare(2.585572506271132, m02[1], 1e-12)); + TEST_CHECK(gkyl_compare(20.898933755069070, m03[0], 1e-12)); + TEST_CHECK(gkyl_compare(7.756717518813396, m03[1], 1e-12)); // Check M1i. - double *m1i0 = gkyl_array_fetch(m1i, 0+confGhost[0]); double *m1i1 = gkyl_array_fetch(m1i, 1+confGhost[0]); - double *m1i2 = gkyl_array_fetch(m1i, 2+confGhost[0]); double *m1i3 = gkyl_array_fetch(m1i, 3+confGhost[0]); - TEST_CHECK( gkyl_compare( -17.599102109531849, m1i0[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.531972647421810, m1i0[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -2.514157444218835, m1i1[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 2.177324215807269, m1i1[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -2.514157444218835, m1i2[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -2.177324215807269, m1i2[1], 1e-12) ); - TEST_CHECK( gkyl_compare( -17.599102109531849, m1i3[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -6.531972647421808, m1i3[1], 1e-12) ); + double *m1i0 = gkyl_array_fetch(m1i, 0 + confGhost[0]); + double *m1i1 = gkyl_array_fetch(m1i, 1 + confGhost[0]); + double *m1i2 = gkyl_array_fetch(m1i, 2 + confGhost[0]); + double *m1i3 = gkyl_array_fetch(m1i, 3 + confGhost[0]); + TEST_CHECK(gkyl_compare(-17.599102109531849, m1i0[0], 1e-12)); + TEST_CHECK(gkyl_compare(6.531972647421810, m1i0[1], 1e-12)); + TEST_CHECK(gkyl_compare(-2.514157444218835, m1i1[0], 1e-12)); + TEST_CHECK(gkyl_compare(2.177324215807269, m1i1[1], 1e-12)); + TEST_CHECK(gkyl_compare(-2.514157444218835, m1i2[0], 1e-12)); + TEST_CHECK(gkyl_compare(-2.177324215807269, m1i2[1], 1e-12)); + TEST_CHECK(gkyl_compare(-17.599102109531849, m1i3[0], 1e-12)); + TEST_CHECK(gkyl_compare(-6.531972647421808, m1i3[1], 1e-12)); // Check M2. - double *m20 = gkyl_array_fetch(m2, 0+confGhost[0]); double *m21 = gkyl_array_fetch(m2, 1+confGhost[0]); - double *m22 = gkyl_array_fetch(m2, 2+confGhost[0]); double *m23 = gkyl_array_fetch(m2, 3+confGhost[0]); - TEST_CHECK( gkyl_compare( 45.464347116290611, m20[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -16.874262672506337, m20[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.494906730898657, m21[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -5.624754224168777, m21[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 6.494906730898657, m22[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 5.624754224168777, m22[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 45.464347116290611, m23[0], 1e-12) ); - TEST_CHECK( gkyl_compare( 16.874262672506337, m23[1], 1e-12) ); + double *m20 = gkyl_array_fetch(m2, 0 + confGhost[0]); + double *m21 = gkyl_array_fetch(m2, 1 + confGhost[0]); + double *m22 = gkyl_array_fetch(m2, 2 + confGhost[0]); + double *m23 = gkyl_array_fetch(m2, 3 + confGhost[0]); + TEST_CHECK(gkyl_compare(45.464347116290611, m20[0], 1e-12)); + TEST_CHECK(gkyl_compare(-16.874262672506337, m20[1], 1e-12)); + TEST_CHECK(gkyl_compare(6.494906730898657, m21[0], 1e-12)); + TEST_CHECK(gkyl_compare(-5.624754224168777, m21[1], 1e-12)); + TEST_CHECK(gkyl_compare(6.494906730898657, m22[0], 1e-12)); + TEST_CHECK(gkyl_compare(5.624754224168777, m22[1], 1e-12)); + TEST_CHECK(gkyl_compare(45.464347116290611, m23[0], 1e-12)); + TEST_CHECK(gkyl_compare(16.874262672506337, m23[1], 1e-12)); // sum the integrated moments - double red_mom[vdim+2]; + double red_mom[vdim + 2]; gkyl_array_reduce_range(red_mom, int_mom, GKYL_SUM, &confLocal); - TEST_CHECK( gkyl_compare( 33.7777777777778, red_mom[0], 1e-12) ); - TEST_CHECK( gkyl_compare( -28.4444444444444, red_mom[1], 1e-12) ); - TEST_CHECK( gkyl_compare( 73.4814814814815, red_mom[2], 1e-12) ); + TEST_CHECK(gkyl_compare(33.7777777777778, red_mom[0], 1e-12)); + TEST_CHECK(gkyl_compare(-28.4444444444444, red_mom[1], 1e-12)); + TEST_CHECK(gkyl_compare(73.4814814814815, red_mom[2], 1e-12)); //// Write the moment array to file. //const char *fmt = "%s-%s-%s_%d.gkyl"; @@ -223,26 +228,31 @@ test_mom_vlasov_1x1v_p1_ho() gkyl_grid_sub_array_write(&grid, &local, 0, distf, "ctest_mom_vlasov_distf_0.gkyl"); // release memory for moment data object - gkyl_array_release(m0); gkyl_array_release(m1i); gkyl_array_release(m2); + gkyl_array_release(m0); + gkyl_array_release(m1i); + gkyl_array_release(m2); gkyl_array_release(int_mom); - - gkyl_mom_calc_release(m0calc); gkyl_mom_calc_release(m1icalc); gkyl_mom_calc_release(m2calc); + + gkyl_mom_calc_release(m0calc); + gkyl_mom_calc_release(m1icalc); + gkyl_mom_calc_release(m2calc); gkyl_mom_calc_release(intcalc); - - gkyl_mom_type_release(vmM0_t); gkyl_mom_type_release(vmM1i_t); gkyl_mom_type_release(vmM2_t); + + gkyl_mom_type_release(vmM0_t); + gkyl_mom_type_release(vmM1i_t); + gkyl_mom_type_release(vmM2_t); gkyl_mom_type_release(int_t); gkyl_proj_on_basis_release(projDistf); gkyl_array_release(distf); } -void -test_mom_vlasov_1x2v_p1_ho() +void test_mom_vlasov_1x2v_p1_ho() { int poly_order = 1; double lower[] = {-2.0, -2.0, -2.0}, upper[] = {2.0, 2.0, 2.0}; int cells[] = {4, 2, 2}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int vdim = 2, cdim = 1; double confLower[] = {lower[0]}, confUpper[] = {upper[0]}; @@ -264,21 +274,21 @@ test_mom_vlasov_1x2v_p1_ho() } gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); - int confGhost[] = { 0 }; + int confGhost[] = {0}; struct gkyl_range confLocal, confLocal_ext; // local, local-ext conf-space ranges gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); struct skin_ghost_ranges confSkin_ghost; // conf-space skin/ghost skin_ghost_ranges_init(&confSkin_ghost, &confLocal_ext, confGhost); - int ghost[] = { confGhost[0], 0, 0}; + int ghost[] = {confGhost[0], 0, 0}; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); struct skin_ghost_ranges skin_ghost; // phase-space skin/ghost skin_ghost_ranges_init(&skin_ghost, &local_ext, ghost); // projection updater for dist-function - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFuncSimple, NULL); + gkyl_proj_on_basis *projDistf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFuncSimple, NULL); // create distribution function array struct gkyl_array *distf; @@ -293,63 +303,71 @@ test_mom_vlasov_1x2v_p1_ho() gkyl_mom_calc *m0calc = gkyl_mom_calc_new(&grid, vmM0_t, false); gkyl_mom_calc *m1icalc = gkyl_mom_calc_new(&grid, vmM1i_t, false); gkyl_mom_calc *m2calc = gkyl_mom_calc_new(&grid, vmM2_t, false); - + // create moment arrays struct gkyl_array *m0, *m1i, *m2; m0 = mkarr(confBasis.num_basis, confLocal_ext.volume); - m1i = mkarr(vdim*confBasis.num_basis, confLocal_ext.volume); + m1i = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(confBasis.num_basis, confLocal_ext.volume); // compute the moments gkyl_mom_calc_advance(m0calc, &local, &confLocal, distf, m0); gkyl_mom_calc_advance(m1icalc, &local, &confLocal, distf, m1i); gkyl_mom_calc_advance(m2calc, &local, &confLocal, distf, m2); - + // Check M0. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m1iptr[k], 1e-12) ); - }} + for (unsigned int k = 0; k < m1i->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m1iptr[k], 1e-12)); + } + } // Check M2. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m1iptr[k], 1e-12) ); - }}} + for (unsigned int k = 0; k < m1i->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m1iptr[k], 1e-12)); + } + } + } // Check M2. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m1iptr[k], 1e-12) ); - }}} + for (unsigned int k = 0; k < m1i->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m1iptr[k], 1e-12)); + } + } + } // Check M2. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m1iptr[k], 1e-12) ); - }} + for (unsigned int k = 0; k < m1i->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m1iptr[k], 1e-12)); + } + } // Check M2. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m0ptr[k], 1e-12) ); - }}} + TEST_CHECK(gkyl_compare(8.0, m0ptr[0], 1e-12)); + for (unsigned int k = 1; k < m0->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m0ptr[k], 1e-12)); + } + } + } //// Check M1i. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m1iptr[k], 1e-12) ); - }}} + for (unsigned int k = 0; k < m1i->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m1iptr[k], 1e-12)); + } + } + } // Check M2. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m2ptr[k], 1e-12) ); - }}} + TEST_CHECK(gkyl_compare(21.333333333333336, m2ptr[0], 1e-12)); + for (unsigned int k = 1; k < m2->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m2ptr[k], 1e-12)); + } + } + } // free allocated memory. gkyl_array_release(distf); gkyl_array_release(distf_cu); - gkyl_array_release(m0); gkyl_array_release(m1i); gkyl_array_release(m2); - gkyl_array_release(m0_cu); gkyl_array_release(m1i_cu); gkyl_array_release(m2_cu); - - gkyl_mom_calc_release(m0Calc); gkyl_mom_calc_release(m1iCalc); gkyl_mom_calc_release(m2Calc); - gkyl_mom_type_release(vmM0_t); gkyl_mom_type_release(vmM1i_t); gkyl_mom_type_release(vmM2_t); + gkyl_array_release(m0); + gkyl_array_release(m1i); + gkyl_array_release(m2); + gkyl_array_release(m0_cu); + gkyl_array_release(m1i_cu); + gkyl_array_release(m2_cu); + + gkyl_mom_calc_release(m0Calc); + gkyl_mom_calc_release(m1iCalc); + gkyl_mom_calc_release(m2Calc); + gkyl_mom_type_release(vmM0_t); + gkyl_mom_type_release(vmM1i_t); + gkyl_mom_type_release(vmM2_t); gkyl_proj_on_basis_release(projDistf); } -void -test_mom_vlasov_2x3v_p1_dev() +void test_mom_vlasov_2x3v_p1_dev() { int poly_order = 1; double lower[] = {-2.0, -2.0, -2.0, -2.0, -2.0}, upper[] = {2.0, 2.0, 2.0, 2.0, 2.0}; int cells[] = {4, 4, 2, 2, 2}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int vdim = 3, cdim = 2; double confLower[] = {lower[0], lower[1]}, confUpper[] = {upper[0], upper[1]}; @@ -1089,21 +1177,21 @@ test_mom_vlasov_2x3v_p1_dev() } gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); - int confGhost[] = { 1, 1 }; + int confGhost[] = {1, 1}; struct gkyl_range confLocal, confLocal_ext; // local, local-ext conf-space ranges gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); struct skin_ghost_ranges confSkin_ghost; // conf-space skin/ghost skin_ghost_ranges_init(&confSkin_ghost, &confLocal_ext, confGhost); - int ghost[] = { confGhost[0], confGhost[1], 0, 0, 0 }; + int ghost[] = {confGhost[0], confGhost[1], 0, 0, 0}; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); struct skin_ghost_ranges skin_ghost; // phase-space skin/ghost skin_ghost_ranges_init(&skin_ghost, &local_ext, ghost); // projection updater for dist-function - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFuncSimple, NULL); + gkyl_proj_on_basis *projDistf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFuncSimple, NULL); // create distribution function struct gkyl_array *distf, *distf_cu; @@ -1123,12 +1211,13 @@ test_mom_vlasov_2x3v_p1_dev() gkyl_mom_calc *m2Calc = gkyl_mom_calc_new(&grid, vmM2_t, true); // create moment arrays - struct gkyl_array *m0, *m1i, *m2, *m0_cu, *m1i_cu, *m2_cu;; + struct gkyl_array *m0, *m1i, *m2, *m0_cu, *m1i_cu, *m2_cu; + ; m0 = mkarr(confBasis.num_basis, confLocal_ext.volume); - m1i = mkarr(vdim*confBasis.num_basis, confLocal_ext.volume); + m1i = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(confBasis.num_basis, confLocal_ext.volume); m0_cu = mkarr_cu(confBasis.num_basis, confLocal_ext.volume); - m1i_cu = mkarr_cu(vdim*confBasis.num_basis, confLocal_ext.volume); + m1i_cu = mkarr_cu(vdim * confBasis.num_basis, confLocal_ext.volume); m2_cu = mkarr_cu(confBasis.num_basis, confLocal_ext.volume); // compute the moment and copy back to host @@ -1140,56 +1229,69 @@ test_mom_vlasov_2x3v_p1_dev() gkyl_array_copy(m2, m2_cu); // Check M0. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m0ptr[k], 1e-12) ); - }}} + TEST_CHECK(gkyl_compare(31.999999999999996, m0ptr[0], 1e-12)); + for (unsigned int k = 1; k < m0->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m0ptr[k], 1e-12)); + } + } + } // Check M1i. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m1iptr[k], 1e-12) ); - }}} + for (unsigned int k = 0; k < m1i->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m1iptr[k], 1e-12)); + } + } + } // Check M2. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m2ptr[k], 1e-12) ); - }}} + TEST_CHECK(gkyl_compare(127.999999999999972, m2ptr[0], 1e-12)); + for (unsigned int k = 1; k < m2->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m2ptr[k], 1e-12)); + } + } + } // free allocated memory. gkyl_array_release(distf); gkyl_array_release(distf_cu); - gkyl_array_release(m0); gkyl_array_release(m1i); gkyl_array_release(m2); - gkyl_array_release(m0_cu); gkyl_array_release(m1i_cu); gkyl_array_release(m2_cu); - - gkyl_mom_calc_release(m0Calc); gkyl_mom_calc_release(m1iCalc); gkyl_mom_calc_release(m2Calc); - gkyl_mom_type_release(vmM0_t); gkyl_mom_type_release(vmM1i_t); gkyl_mom_type_release(vmM2_t); + gkyl_array_release(m0); + gkyl_array_release(m1i); + gkyl_array_release(m2); + gkyl_array_release(m0_cu); + gkyl_array_release(m1i_cu); + gkyl_array_release(m2_cu); + + gkyl_mom_calc_release(m0Calc); + gkyl_mom_calc_release(m1iCalc); + gkyl_mom_calc_release(m2Calc); + gkyl_mom_type_release(vmM0_t); + gkyl_mom_type_release(vmM1i_t); + gkyl_mom_type_release(vmM2_t); gkyl_proj_on_basis_release(projDistf); } -void -test_mom_vlasov_big_2x2v_p2_dev() +void test_mom_vlasov_big_2x2v_p2_dev() { int poly_order = 2; double lower[] = {-2.0, -2.0, -2.0, -2.0}, upper[] = {2.0, 2.0, 2.0, 2.0}; int cells[] = {44, 44, 32, 32}; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); int vdim = 2, cdim = 2; double confLower[] = {lower[0], lower[1]}, confUpper[] = {upper[0], upper[1]}; @@ -1211,21 +1313,21 @@ test_mom_vlasov_big_2x2v_p2_dev() } gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); - int confGhost[] = { 1, 1 }; + int confGhost[] = {1, 1}; struct gkyl_range confLocal, confLocal_ext; // local, local-ext conf-space ranges gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); struct skin_ghost_ranges confSkin_ghost; // conf-space skin/ghost skin_ghost_ranges_init(&confSkin_ghost, &confLocal_ext, confGhost); - int ghost[] = { confGhost[0], confGhost[1], 0, 0 }; + int ghost[] = {confGhost[0], confGhost[1], 0, 0}; struct gkyl_range local, local_ext; // local, local-ext phase-space ranges gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); struct skin_ghost_ranges skin_ghost; // phase-space skin/ghost skin_ghost_ranges_init(&skin_ghost, &local_ext, ghost); // projection updater for dist-function - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, evalFunc4d, NULL); + gkyl_proj_on_basis *projDistf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, evalFunc4d, NULL); // create distribution function struct gkyl_array *distf, *distf_cu; @@ -1245,12 +1347,13 @@ test_mom_vlasov_big_2x2v_p2_dev() gkyl_mom_calc *m2Calc = gkyl_mom_calc_new(&grid, vmM2_t, true); // create moment arrays - struct gkyl_array *m0, *m1i, *m2, *m0_cu, *m1i_cu, *m2_cu;; + struct gkyl_array *m0, *m1i, *m2, *m0_cu, *m1i_cu, *m2_cu; + ; m0 = mkarr(confBasis.num_basis, confLocal_ext.volume); - m1i = mkarr(vdim*confBasis.num_basis, confLocal_ext.volume); + m1i = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(confBasis.num_basis, confLocal_ext.volume); m0_cu = mkarr_cu(confBasis.num_basis, confLocal_ext.volume); - m1i_cu = mkarr_cu(vdim*confBasis.num_basis, confLocal_ext.volume); + m1i_cu = mkarr_cu(vdim * confBasis.num_basis, confLocal_ext.volume); m2_cu = mkarr_cu(confBasis.num_basis, confLocal_ext.volume); // compute the moment and copy back to host @@ -1262,46 +1365,59 @@ test_mom_vlasov_big_2x2v_p2_dev() gkyl_array_copy(m2, m2_cu); // Check M0. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m0ptr[k], 1e-12) ); - }}} + TEST_CHECK(gkyl_compare(64.0, m0ptr[0], 1e-12)); + for (unsigned int k = 1; k < m0->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m0ptr[k], 1e-12)); + } + } + } //// Check M1i. - for (unsigned int i=1; incomp; ++k) { - TEST_CHECK( gkyl_compare( 0., m2ptr[k], 1e-12) ); - }}} + TEST_CHECK(gkyl_compare(170.666666666666667, m2ptr[0], 1e-12)); + for (unsigned int k = 1; k < m2->ncomp; ++k) { + TEST_CHECK(gkyl_compare(0., m2ptr[k], 1e-12)); + } + } + } // free allocated memory. gkyl_array_release(distf); gkyl_array_release(distf_cu); - gkyl_array_release(m0); gkyl_array_release(m1i); gkyl_array_release(m2); - gkyl_array_release(m0_cu); gkyl_array_release(m1i_cu); gkyl_array_release(m2_cu); - - gkyl_mom_calc_release(m0Calc); gkyl_mom_calc_release(m1iCalc); gkyl_mom_calc_release(m2Calc); - gkyl_mom_type_release(vmM0_t); gkyl_mom_type_release(vmM1i_t); gkyl_mom_type_release(vmM2_t); + gkyl_array_release(m0); + gkyl_array_release(m1i); + gkyl_array_release(m2); + gkyl_array_release(m0_cu); + gkyl_array_release(m1i_cu); + gkyl_array_release(m2_cu); + + gkyl_mom_calc_release(m0Calc); + gkyl_mom_calc_release(m1iCalc); + gkyl_mom_calc_release(m2Calc); + gkyl_mom_type_release(vmM0_t); + gkyl_mom_type_release(vmM1i_t); + gkyl_mom_type_release(vmM2_t); gkyl_proj_on_basis_release(projDistf); } @@ -1309,19 +1425,19 @@ test_mom_vlasov_big_2x2v_p2_dev() #endif TEST_LIST = { - { "mom_vlasov_ho", test_mom_vlasov_ho }, - { "test_mom_vlasov_1x1v_p1_ho", test_mom_vlasov_1x1v_p1_ho }, - { "test_mom_vlasov_1x2v_p1_ho", test_mom_vlasov_1x2v_p1_ho }, - { "test_mom_vlasov_2x2v_p1_ho", test_mom_vlasov_2x2v_p1_ho }, -// { "test_mom_vlasov_big_2x2v_p2_ho", test_mom_vlasov_big_2x2v_p2_ho }, - { "test_mom_vlasov_2x3v_p1_ho", test_mom_vlasov_2x3v_p1_ho }, + {"mom_vlasov_ho", test_mom_vlasov_ho}, + {"test_mom_vlasov_1x1v_p1_ho", test_mom_vlasov_1x1v_p1_ho}, + {"test_mom_vlasov_1x2v_p1_ho", test_mom_vlasov_1x2v_p1_ho}, + {"test_mom_vlasov_2x2v_p1_ho", test_mom_vlasov_2x2v_p1_ho}, + // { "test_mom_vlasov_big_2x2v_p2_ho", test_mom_vlasov_big_2x2v_p2_ho }, + {"test_mom_vlasov_2x3v_p1_ho", test_mom_vlasov_2x3v_p1_ho}, #ifdef GKYL_HAVE_CUDA - { "mom_vlasov_dev", test_mom_vlasov_dev }, - { "test_mom_vlasov_1x1v_p1_dev", test_mom_vlasov_1x1v_p1_dev }, - { "test_mom_vlasov_1x2v_p1_dev", test_mom_vlasov_1x2v_p1_dev }, - { "test_mom_vlasov_2x2v_p1_dev", test_mom_vlasov_2x2v_p1_dev }, - { "test_mom_vlasov_2x3v_p1_dev", test_mom_vlasov_2x3v_p1_dev }, + {"mom_vlasov_dev", test_mom_vlasov_dev}, + {"test_mom_vlasov_1x1v_p1_dev", test_mom_vlasov_1x1v_p1_dev}, + {"test_mom_vlasov_1x2v_p1_dev", test_mom_vlasov_1x2v_p1_dev}, + {"test_mom_vlasov_2x2v_p1_dev", test_mom_vlasov_2x2v_p1_dev}, + {"test_mom_vlasov_2x3v_p1_dev", test_mom_vlasov_2x3v_p1_dev}, // { "test_mom_vlasov_big_2x2v_p2_dev", test_mom_vlasov_big_2x2v_p2_dev }, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/vlasov/unit/ctest_positivity_shift_vlasov.c b/vlasov/unit/ctest_positivity_shift_vlasov.c index cf7c607a59..ab6575f6fa 100644 --- a/vlasov/unit/ctest_positivity_shift_vlasov.c +++ b/vlasov/unit/ctest_positivity_shift_vlasov.c @@ -1,4 +1,4 @@ - // Write m0 to file after the positivity shift. +// Write m0 to file after the positivity shift. #include #include #include @@ -13,14 +13,14 @@ #include // Allocate array (filled with zeros). -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } @@ -35,7 +35,7 @@ struct test_ctx { double vy_max; // Maximum vy of the grid. }; -void eval_distf_1x2v(double t, const double *xn, double* restrict fout, void *ctx) +void eval_distf_1x2v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0], vy = xn[1], vx = xn[2]; @@ -44,26 +44,27 @@ void eval_distf_1x2v(double t, const double *xn, double* restrict fout, void *ct double n0 = tctx->n0; double ux = tctx->ux; double uy = tctx->uy; - double vtsq = tctx->temp/mass; + double vtsq = tctx->temp / mass; int vdim = tctx->vdim; - fout[0] = (n0/pow(2.0*M_PI*vtsq,vdim/2.0)) * exp(-(pow(vx-ux,2)+pow(vy-uy,2))/(2.0*vtsq)); + fout[0] = (n0 / pow(2.0 * M_PI * vtsq, vdim / 2.0)) * + exp(-(pow(vx - ux, 2) + pow(vy - uy, 2)) / (2.0 * vtsq)); // Intentionally set some places to be negative. - if (fabs(vx) > 0.8*tctx->vx_max || fabs(vy) > 0.8*tctx->vy_max) - fout[0] = -0.2 * (n0/pow(2.0*M_PI*vtsq,vdim/2.0)); + if (fabs(vx) > 0.8 * tctx->vx_max || fabs(vy) > 0.8 * tctx->vy_max) { + fout[0] = -0.2 * (n0 / pow(2.0 * M_PI * vtsq, vdim / 2.0)); + } } -void -test_1x2v(int poly_order, bool use_gpu) +void test_1x2v(int poly_order, bool use_gpu) { int cdim = 1; double vx_max = 6.0, vy_max = 6.0; double lower[] = {0.0, -vx_max, -vy_max}, upper[] = {1.0, vx_max, vy_max}; int cells[] = {2, 12, 8}; - int ndim = sizeof(cells)/sizeof(cells[0]); - int vdim = ndim-cdim; + int ndim = sizeof(cells) / sizeof(cells[0]); + int vdim = ndim - cdim; struct test_ctx proj_ctx = { .n0 = 1.0, // Density. @@ -73,22 +74,22 @@ test_1x2v(int poly_order, bool use_gpu) .mass = 1.0, // Species mass. .vdim = vdim, // Number of velocity space dimensions. .vx_max = vx_max, // Maximum vx of the grid. - .vy_max = vy_max, // Maximum vy of the grid. + .vy_max = vy_max // Maximum vy of the grid. }; double confLower[cdim], confUpper[cdim]; int confCells[cdim]; - for (int d=0; dncomp, distf->size); - gkyl_proj_on_basis *proj_distf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_distf_1x2v, &proj_ctx); + } + gkyl_proj_on_basis *proj_distf = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_distf_1x2v, &proj_ctx); gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); gkyl_array_copy(distf, distf_ho); // Compute M0 of the original f. struct gkyl_dg_updater_moment *m0_mom_up = gkyl_dg_updater_moment_new( - &grid, &confBasis, &basis, &confLocal, 0, &local, 0, 0, GKYL_F_MOMENT_M0, false, use_gpu); + &grid, &confBasis, &basis, &confLocal, 0, &local, 0, 0, GKYL_F_MOMENT_M0, false, use_gpu + ); struct gkyl_array *m0_pre = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); gkyl_dg_updater_moment_advance(m0_mom_up, &local, &confLocal, distf, m0_pre); -// // Write m0 to file. -// char fname0M0[1024]; -// sprintf(fname0M0, "ctest_positivity_shift_vlasov_1x2v_p%d_m0_pre.gkyl", poly_order); -// gkyl_grid_sub_array_write(&confGrid, &confLocal, NULL, m0_pre, fname0M0); + // // Write m0 to file. + // char fname0M0[1024]; + // sprintf(fname0M0, "ctest_positivity_shift_vlasov_1x2v_p%d_m0_pre.gkyl", poly_order); + // gkyl_grid_sub_array_write(&confGrid, &confLocal, NULL, m0_pre, fname0M0); // Compute the integrated moments of the original f. struct gkyl_dg_updater_moment *int_mom_up = gkyl_dg_updater_moment_new( - &grid, &confBasis, &basis, &confLocal, 0, &local, 0, 0, GKYL_F_MOMENT_M0M1M2, true, use_gpu); + &grid, &confBasis, &basis, &confLocal, 0, &local, 0, 0, GKYL_F_MOMENT_M0M1M2, true, use_gpu + ); int num_mom = gkyl_dg_updater_moment_num_mom(int_mom_up); struct gkyl_array *intmom_grid = mkarr(use_gpu, num_mom, confLocal_ext.volume); double *red_intmom; - if (use_gpu) + if (use_gpu) { red_intmom = gkyl_cu_malloc(sizeof(double[num_mom])); - else + } else { red_intmom = gkyl_malloc(sizeof(double[num_mom])); + } gkyl_dg_updater_moment_advance(int_mom_up, &local, &confLocal, distf, intmom_grid); gkyl_array_reduce_range(red_intmom, intmom_grid, GKYL_SUM, &confLocal); double intmom_pre[num_mom]; - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(intmom_pre, red_intmom, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intmom_pre, red_intmom, sizeof(double[num_mom])); + } -// printf("\nintmom_pre = %16.14e %16.14e %16.14e %16.14e\n",intmom_pre[0],intmom_pre[1],intmom_pre[2],intmom_pre[3]); -// // Write distribution function to file. -// char fname0[1024]; -// sprintf(fname0, "ctest_positivity_shift_vlasov_1x2v_p%d_pre.gkyl", poly_order); -// gkyl_grid_sub_array_write(&grid, &local, NULL, distf, fname0); + // printf("\nintmom_pre = %16.14e %16.14e %16.14e %16.14e\n",intmom_pre[0],intmom_pre[1],intmom_pre[2],intmom_pre[3]); + // // Write distribution function to file. + // char fname0[1024]; + // sprintf(fname0, "ctest_positivity_shift_vlasov_1x2v_p%d_pre.gkyl", poly_order); + // gkyl_grid_sub_array_write(&grid, &local, NULL, distf, fname0); // Run the positivity shift. First time it sets ffloor in the pos_shift updater. struct gkyl_array *m0 = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); @@ -177,15 +188,15 @@ test_1x2v(int poly_order, bool use_gpu) deltaf = mkarr(use_gpu, basis.num_basis, local_ext.volume); gkyl_array_set(deltaf, -1.0, distf); - struct gkyl_positivity_shift_vlasov* pos_shift = gkyl_positivity_shift_vlasov_new(confBasis, - basis, grid, &confLocal_ext, use_gpu); + struct gkyl_positivity_shift_vlasov *pos_shift = + gkyl_positivity_shift_vlasov_new(confBasis, basis, grid, &confLocal_ext, use_gpu); gkyl_positivity_shift_vlasov_advance(pos_shift, &confLocal, &local, distf, m0, ps_delta_m0); -// // Commenting this out as we are now using f=0 as the floor. -// // Project distf and apply the positivity shift again (using new ffloor). -// gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); -// gkyl_array_copy(distf, distf_ho); -// gkyl_positivity_shift_vlasov_advance(pos_shift, &confLocal, &local, distf, m0, ps_delta_m0); + // // Commenting this out as we are now using f=0 as the floor. + // // Project distf and apply the positivity shift again (using new ffloor). + // gkyl_proj_on_basis_advance(proj_distf, 0.0, &local, distf_ho); + // gkyl_array_copy(distf, distf_ho); + // gkyl_positivity_shift_vlasov_advance(pos_shift, &confLocal, &local, distf, m0, ps_delta_m0); // Compute delta f: gkyl_array_accumulate(deltaf, 1.0, distf); @@ -194,46 +205,56 @@ test_1x2v(int poly_order, bool use_gpu) struct gkyl_array *m0_post = mkarr(use_gpu, confBasis.num_basis, confLocal_ext.volume); gkyl_dg_updater_moment_advance(m0_mom_up, &local, &confLocal, distf, m0_post); -// // Write m0 to file after the positivity shift. -// char fname1M0[1024]; -// sprintf(fname1M0, "ctest_positivity_shift_vlasov_1x2v_p%d_m0_post.gkyl", poly_order); -// gkyl_grid_sub_array_write(&confGrid, &confLocal, NULL, m0_post, fname1M0); + // // Write m0 to file after the positivity shift. + // char fname1M0[1024]; + // sprintf(fname1M0, "ctest_positivity_shift_vlasov_1x2v_p%d_m0_post.gkyl", poly_order); + // gkyl_grid_sub_array_write(&confGrid, &confLocal, NULL, m0_post, fname1M0); // Compute the integrated moments after the positivity shift. gkyl_dg_updater_moment_advance(int_mom_up, &local, &confLocal, distf, intmom_grid); gkyl_array_reduce_range(red_intmom, intmom_grid, GKYL_SUM, &confLocal); double intmom_post[num_mom]; - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(intmom_post, red_intmom, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intmom_post, red_intmom, sizeof(double[num_mom])); + } // Compute the integrated moments of the shift. struct gkyl_array *ps_intmom_grid = mkarr(use_gpu, num_mom, confLocal_ext.volume); gkyl_dg_updater_moment_advance(int_mom_up, &local, &confLocal, deltaf, ps_intmom_grid); gkyl_array_reduce_range(red_intmom, ps_intmom_grid, GKYL_SUM, &confLocal); double intmom_shift[num_mom]; - if (use_gpu) + if (use_gpu) { gkyl_cu_memcpy(intmom_shift, red_intmom, sizeof(double[num_mom]), GKYL_CU_MEMCPY_D2H); - else + } else { memcpy(intmom_shift, red_intmom, sizeof(double[num_mom])); + } + + // printf("intmom_post = %16.14e %16.14e %16.14e %16.14e\n",intmom_post[0],intmom_post[1],intmom_post[2],intmom_post[3]); + // printf("intmom_shift = %16.14e %16.14e %16.14e %16.14e\n",intmom_shift[0],intmom_shift[1],intmom_shift[2],intmom_shift[3]); + // // Write distribution function to file. + // char fname1[1024]; + // sprintf(fname1, "ctest_positivity_shift_vlasov_1x2v_p%d_post.gkyl", poly_order); + // gkyl_grid_sub_array_write(&grid, &local, NULL, distf, fname1); -// printf("intmom_post = %16.14e %16.14e %16.14e %16.14e\n",intmom_post[0],intmom_post[1],intmom_post[2],intmom_post[3]); -// printf("intmom_shift = %16.14e %16.14e %16.14e %16.14e\n",intmom_shift[0],intmom_shift[1],intmom_shift[2],intmom_shift[3]); -// // Write distribution function to file. -// char fname1[1024]; -// sprintf(fname1, "ctest_positivity_shift_vlasov_1x2v_p%d_post.gkyl", poly_order); -// gkyl_grid_sub_array_write(&grid, &local, NULL, distf, fname1); - // Check the integrated moments. - TEST_CHECK( gkyl_compare( intmom_shift[0],-4.22405166400353e-16, 1e-10)); - TEST_MSG("intmom_shift[0]: produced: %.14e | expected: %.14e", intmom_shift[0],-4.22405166400353e-16); - TEST_CHECK( gkyl_compare( intmom_shift[1], 4.16333634234434e-16, 1e-10)); - TEST_MSG("intmom_shift[1]: produced: %.14e | expected: %.14e", intmom_shift[1], 4.16333634234434e-16); - TEST_CHECK( gkyl_compare( intmom_shift[2], 1.38777878078145e-17, 1e-10)); - TEST_MSG("intmom_shift[2]: produced: %.14e | expected: %.14e", intmom_shift[2], 1.38777878078145e-17); - TEST_CHECK( gkyl_compare( intmom_shift[3], 2.09905432920501e+01, 1e-10)); - TEST_MSG("intmom_shift[3]: produced: %.14e | expected: %.14e", intmom_shift[3], 2.09905432920501e+01); + TEST_CHECK(gkyl_compare(intmom_shift[0], -4.22405166400353e-16, 1e-10)); + TEST_MSG( + "intmom_shift[0]: produced: %.14e | expected: %.14e", intmom_shift[0], -4.22405166400353e-16 + ); + TEST_CHECK(gkyl_compare(intmom_shift[1], 4.16333634234434e-16, 1e-10)); + TEST_MSG( + "intmom_shift[1]: produced: %.14e | expected: %.14e", intmom_shift[1], 4.16333634234434e-16 + ); + TEST_CHECK(gkyl_compare(intmom_shift[2], 1.38777878078145e-17, 1e-10)); + TEST_MSG( + "intmom_shift[2]: produced: %.14e | expected: %.14e", intmom_shift[2], 1.38777878078145e-17 + ); + TEST_CHECK(gkyl_compare(intmom_shift[3], 2.09905432920501e+01, 1e-10)); + TEST_MSG( + "intmom_shift[3]: produced: %.14e | expected: %.14e", intmom_shift[3], 2.09905432920501e+01 + ); gkyl_array_release(distf); gkyl_array_release(deltaf); @@ -246,7 +267,7 @@ test_1x2v(int poly_order, bool use_gpu) if (use_gpu) { gkyl_array_release(distf_ho); gkyl_cu_free(red_intmom); - } else{ + } else { gkyl_free(red_intmom); } gkyl_proj_on_basis_release(proj_distf); @@ -266,9 +287,9 @@ void test_positivity_shift_vlasov_1x2v_dev() } TEST_LIST = { - { "test_positivity_shift_vlasov_1x2v_ho", test_positivity_shift_vlasov_1x2v_ho }, + {"test_positivity_shift_vlasov_1x2v_ho", test_positivity_shift_vlasov_1x2v_ho}, #ifdef GKYL_HAVE_CUDA - { "test_positivity_shift_vlasov_1x2v_dev", test_positivity_shift_vlasov_1x2v_dev }, + {"test_positivity_shift_vlasov_1x2v_dev", test_positivity_shift_vlasov_1x2v_dev}, #endif - { NULL, NULL }, + {NULL, NULL} }; diff --git a/vlasov/unit/ctest_prim_vlasov.c b/vlasov/unit/ctest_prim_vlasov.c index b618506972..793db77973 100644 --- a/vlasov/unit/ctest_prim_vlasov.c +++ b/vlasov/unit/ctest_prim_vlasov.c @@ -15,44 +15,44 @@ #include #include -static inline double -maxwellian1D(double n, double vx, double ux, double vth) +static inline double maxwellian1D(double n, double vx, double ux, double vth) { - double v2 = (vx-ux)*(vx-ux); - return n/sqrt(2*M_PI*vth*vth)*exp(-v2/(2*vth*vth)); + double v2 = (vx - ux) * (vx - ux); + return n / sqrt(2 * M_PI * vth * vth) * exp(-v2 / (2 * vth * vth)); } -static inline double -maxwellian2D(double n, double vx, double vy, double ux, double uy, double vth) +static inline double maxwellian2D(double n, double vx, double vy, double ux, double uy, double vth) { - double v2 = (vx-ux)*(vx-ux) + (vy-uy)*(vy-uy); - return n/(2*M_PI*vth*vth)*exp(-v2/(2*vth*vth)); + double v2 = (vx - ux) * (vx - ux) + (vy - uy) * (vy - uy); + return n / (2 * M_PI * vth * vth) * exp(-v2 / (2 * vth * vth)); } -void -evalDistFunc1x1v(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFunc1x1v( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], vx = xn[1]; - + fout[0] = maxwellian1D(1.0, vx, 0.0, 1.0); } -void -evalDistFunc1x2v(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +void evalDistFunc1x2v( + double t, const double *GKYL_RESTRICT xn, double *GKYL_RESTRICT fout, void *ctx +) { double x = xn[0], vx = xn[1], vy = xn[2]; - + fout[0] = maxwellian2D(1.0, vx, vy, 0.0, 0.0, 1.0); } -void nu_prof_1x1v(double t, const double *xn, double* restrict fout, void *ctx) +void nu_prof_1x1v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double vx = xn[1]; fout[0] = 1.0; } -void nu_prof_1x2v(double t, const double *xn, double* restrict fout, void *ctx) +void nu_prof_1x2v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; double vx = xn[1]; @@ -61,17 +61,15 @@ void nu_prof_1x2v(double t, const double *xn, double* restrict fout, void *ctx) } // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { - struct gkyl_array* a = gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } // allocate cu_dev array -static struct gkyl_array* -mkarr_cu(long nc, long size) +static struct gkyl_array *mkarr_cu(long nc, long size) { - struct gkyl_array* a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); return a; } @@ -84,33 +82,35 @@ struct skin_ghost_ranges { }; // Create ghost and skin sub-ranges given a parent range -static void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) +static void skin_ghost_ranges_init( + struct skin_ghost_ranges *sgr, const struct gkyl_range *parent, const int *ghost +) { int ndim = parent->ndim; - for (int d=0; dlower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); + for (int d = 0; d < ndim; ++d) { + gkyl_skin_ghost_ranges( + &sgr->lower_skin[d], &sgr->lower_ghost[d], d, GKYL_LOWER_EDGE, parent, ghost + ); + gkyl_skin_ghost_ranges( + &sgr->upper_skin[d], &sgr->upper_ghost[d], d, GKYL_UPPER_EDGE, parent, ghost + ); } } -void -test_func(int cdim, int vdim, int poly_order, - evalf_t evalDistFunc, double f_check[], double vf_check[], - double u_check[], double vth_check[], double ucross_check[], double vthcross_check[]) +void test_func( + int cdim, int vdim, int poly_order, evalf_t evalDistFunc, double f_check[], double vf_check[], + double u_check[], double vth_check[], double ucross_check[], double vthcross_check[] +) { - int pdim = cdim + vdim; + int pdim = cdim + vdim; double lower[GKYL_MAX_DIM], upper[GKYL_MAX_DIM], confLower[GKYL_MAX_DIM], confUpper[GKYL_MAX_DIM]; int cells[GKYL_MAX_DIM], confCells[GKYL_MAX_DIM]; - - double v_bounds[2*vdim]; - - for (int i=0; icdim == cdim ); - TEST_CHECK( prim->pdim == pdim ); - TEST_CHECK( prim->poly_order == poly_order ); - TEST_CHECK( prim->num_config == confBasis.num_basis ); - TEST_CHECK( prim->num_phase == basis.num_basis ); - + TEST_CHECK(prim->cdim == cdim); + TEST_CHECK(prim->pdim == pdim); + TEST_CHECK(prim->poly_order == poly_order); + TEST_CHECK(prim->num_config == confBasis.num_basis); + TEST_CHECK(prim->num_phase == basis.num_basis); + // create moment arrays struct gkyl_array *u, *vth, *prim_moms; - u = mkarr(vdim*confBasis.num_basis, confLocal_ext.volume); + u = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); vth = mkarr(confBasis.num_basis, confLocal_ext.volume); - prim_moms = mkarr((vdim+1)*confBasis.num_basis, confLocal_ext.volume); + prim_moms = mkarr((vdim + 1) * confBasis.num_basis, confLocal_ext.volume); // compute the moment corrections gkyl_prim_lbo_calc_advance(primcalc, &confLocal, moms, boundary_corrections, nu, prim_moms); gkyl_array_set_offset(u, 1., prim_moms, 0); - gkyl_array_set_offset(vth, 1., prim_moms, vdim*confBasis.num_basis); + gkyl_array_set_offset(vth, 1., prim_moms, vdim * confBasis.num_basis); // Check u // 1-indexed for interfacing with G2 Lua layer - for (unsigned int i=1; i // allocate array (filled with zeros) -static struct gkyl_array * -mkarr(long nc, long size) +static struct gkyl_array *mkarr(long nc, long size) { struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -void -eval_M0(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M0(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 1.0; } -void -eval_M1i_1v_no_drift(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M1i_1v_no_drift(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 0.0; } -void -eval_M2_1v_no_drift(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M2_1v_no_drift(double t, const double *xn, double *restrict fout, void *ctx) { double T = 1.0; double x = xn[0]; fout[0] = T; } -void -eval_M1i_1v(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M1i_1v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - fout[0] = 0.5; + fout[0] = 0.5; } -void -eval_M2_1v(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M2_1v(double t, const double *xn, double *restrict fout, void *ctx) { double T = 1.0; double x = xn[0]; fout[0] = T; } -void -eval_M1i_2v(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M1i_2v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 0.5; fout[1] = 0.25; } -void -eval_M2_2v(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M2_2v(double t, const double *xn, double *restrict fout, void *ctx) { double T = 1.0; double x = xn[0]; fout[0] = T; } -void -eval_M1i_3v(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M1i_3v(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; fout[0] = 0.5; @@ -86,16 +77,14 @@ eval_M1i_3v(double t, const double *xn, double *restrict fout, void *ctx) fout[2] = -0.5; } -void -eval_M2_3v(double t, const double *xn, double *restrict fout, void *ctx) +void eval_M2_3v(double t, const double *xn, double *restrict fout, void *ctx) { double T = 1.0; double x = xn[0]; fout[0] = T; } -void -test_1x1v_no_drift(int poly_order) +void test_1x1v_no_drift(int poly_order) { double lower[] = {0.1, -15.0}, upper[] = {1.0, 15.0}; int cells[] = {2, 32}; @@ -137,27 +126,27 @@ test_1x1v_no_drift(int poly_order) m0 = mkarr(confBasis.num_basis, confLocal_ext.volume); m1i = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(confBasis.num_basis, confLocal_ext.volume); - moms = mkarr((vdim+2) * confBasis.num_basis, confLocal_ext.volume); + moms = mkarr((vdim + 2) * confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M0, NULL); - gkyl_proj_on_basis *proj_m1i = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, vdim, eval_M1i_1v_no_drift, NULL); - gkyl_proj_on_basis *proj_m2 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M2_1v_no_drift, NULL); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M0, NULL); + gkyl_proj_on_basis *proj_m1i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_M1i_1v_no_drift, NULL); + gkyl_proj_on_basis *proj_m2 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M2_1v_no_drift, NULL); gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i); gkyl_proj_on_basis_advance(proj_m2, 0.0, &confLocal, m2); - gkyl_array_set_offset_range(moms, 1.0, m0, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms, 1.0, m1i, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms, 1.0, m2, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m0, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m1i, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m2, (vdim + 1) * confBasis.num_basis, &confLocal); // build gamma and gamma_inv struct gkyl_array *gamma = mkarr(velBasis.num_basis, velLocal.volume); struct gkyl_array *gamma_inv = mkarr(velBasis.num_basis, velLocal.volume); - struct gkyl_dg_calc_sr_vars *sr_vars = gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, - &confBasis, &velBasis, &confLocal, &velLocal, false); + struct gkyl_dg_calc_sr_vars *sr_vars = + gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, &confBasis, &velBasis, &confLocal, &velLocal, false); // Project gamma and its inverse gkyl_calc_sr_vars_init_p_vars(sr_vars, gamma, gamma_inv); // Free SR variable computation @@ -170,38 +159,43 @@ test_1x1v_no_drift(int poly_order) // projection updater to compute LTE distribution struct gkyl_vlasov_lte_proj_on_basis_inp inp_lte = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, - }; + .use_gpu = false + }; gkyl_vlasov_lte_proj_on_basis *proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_lte); gkyl_vlasov_lte_proj_on_basis_advance(proj_lte, &local, &confLocal, moms, distf); // values to compare at index (1, 17) [remember, lower-left index is (1,1)] - double p1_vals[] = {5.3918752026566863e-01, -1.0910243387206232e-17, -6.0196985297046972e-02, - 5.0006050167249552e-18}; + double p1_vals[] = { + 5.3918752026566863e-01, -1.0910243387206232e-17, -6.0196985297046972e-02, 5.0006050167249552e-18 + }; double p2_vals[] = {5.3922143701031633e-01, -9.6625223288531320e-18, -5.7898881215132203e-02, - 7.8842251929957589e-18, 1.9166441863144966e-17, -1.0173903909543560e-02, - 1.7916734900988946e-17, 1.4245174569363429e-18}; + 7.8842251929957589e-18, 1.9166441863144966e-17, -1.0173903909543560e-02, + 1.7916734900988946e-17, 1.4245174569363429e-18}; const double *fv = gkyl_array_cfetch(distf, gkyl_range_idx(&local_ext, (int[2]){1, 17})); - if (poly_order == 1) - for (int i = 0; i < basis.num_basis; ++i) + if (poly_order == 1) { + for (int i = 0; i < basis.num_basis; ++i) { TEST_CHECK(gkyl_compare_double(p1_vals[i], fv[i], 1e-12)); + } + } - if (poly_order == 2) - for (int i = 0; i < basis.num_basis; ++i) + if (poly_order == 2) { + for (int i = 0; i < basis.num_basis; ++i) { TEST_CHECK(gkyl_compare_double(p2_vals[i], fv[i], 1e-12)); + } + } // write distribution function to file char fname[1024]; @@ -222,13 +216,15 @@ test_1x1v_no_drift(int poly_order) gkyl_array_release(gamma_inv); } -void test_proj_mj_on_basis_1x1v_no_drift_p2_ho() { test_1x1v_no_drift(2); } +void test_proj_mj_on_basis_1x1v_no_drift_p2_ho() +{ + test_1x1v_no_drift(2); +} -void -test_1x1v(int poly_order) +void test_1x1v(int poly_order) { double lower[] = {0.1, -15.0}, upper[] = {1.0, 15.0}; // +/- 15 on velocity - int cells[] = {2, 32}; // default {2, 32} + int cells[] = {2, 32}; // default {2, 32} int vdim = 1, cdim = 1; int ndim = cdim + vdim; @@ -268,27 +264,27 @@ test_1x1v(int poly_order) m0 = mkarr(confBasis.num_basis, confLocal_ext.volume); m1i = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(confBasis.num_basis, confLocal_ext.volume); - moms = mkarr((vdim+2)*confBasis.num_basis, confLocal_ext.volume); + moms = mkarr((vdim + 2) * confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M0, NULL); - gkyl_proj_on_basis *proj_m1i = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, vdim, eval_M1i_1v, NULL); - gkyl_proj_on_basis *proj_m2 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M2_1v, NULL); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M0, NULL); + gkyl_proj_on_basis *proj_m1i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_M1i_1v, NULL); + gkyl_proj_on_basis *proj_m2 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M2_1v, NULL); gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i); gkyl_proj_on_basis_advance(proj_m2, 0.0, &confLocal, m2); - gkyl_array_set_offset_range(moms, 1.0, m0, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms, 1.0, m1i, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms, 1.0, m2, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m0, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m1i, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m2, (vdim + 1) * confBasis.num_basis, &confLocal); // build gamma and gamma_inv struct gkyl_array *gamma = mkarr(velBasis.num_basis, velLocal.volume); struct gkyl_array *gamma_inv = mkarr(velBasis.num_basis, velLocal.volume); - struct gkyl_dg_calc_sr_vars *sr_vars = gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, - &confBasis, &velBasis, &confLocal, &velLocal, false); + struct gkyl_dg_calc_sr_vars *sr_vars = + gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, &confBasis, &velBasis, &confLocal, &velLocal, false); // Project gamma and its inverse gkyl_calc_sr_vars_init_p_vars(sr_vars, gamma, gamma_inv); // Free SR variable computation @@ -301,48 +297,48 @@ test_1x1v(int poly_order) // projection updater to compute LTE distribution struct gkyl_vlasov_lte_proj_on_basis_inp inp_lte = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, - }; + .use_gpu = false + }; gkyl_vlasov_lte_proj_on_basis *proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_lte); gkyl_vlasov_lte_proj_on_basis_advance(proj_lte, &local, &confLocal, moms, distf); // test accuracy of the projection: struct gkyl_vlasov_lte_moments_inp inp_mom = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, + .use_gpu = false }; - gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew( &inp_mom ); + gkyl_vlasov_lte_moments *lte_moms = gkyl_vlasov_lte_moments_inew(&inp_mom); gkyl_vlasov_lte_moments_advance(lte_moms, &local, &confLocal, distf, moms); - gkyl_array_set_offset_range(m0, 1.0, moms, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m1i, 1.0, moms, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(m2, 1.0, moms, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m0, 1.0, moms, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m1i, 1.0, moms, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(m2, 1.0, moms, (vdim + 1) * confBasis.num_basis, &confLocal); // values to compare at index (1, 17) [remember, lower-left index is (1,1)] - double p2_vals[] = {5.9297594654488650e-01, -4.1867292592431142e-18, 7.1286851491369927e-03, - 6.9143629007589357e-18, 1.0932899315657513e-17, -1.6063381083048084e-02, - -5.5123762524241300e-18, -3.3195546731973899e-18}; + double p2_vals[] = {5.9297594654488650e-01, -4.1867292592431142e-18, 7.1286851491369927e-03, + 6.9143629007589357e-18, 1.0932899315657513e-17, -1.6063381083048084e-02, + -5.5123762524241300e-18, -3.3195546731973899e-18}; const double *fv = gkyl_array_cfetch(distf, gkyl_range_idx(&local_ext, (int[2]){1, 17})); @@ -352,7 +348,7 @@ test_1x1v(int poly_order) // printf("p2_vals = %1.16e fv = %1.16e\n", p2_vals[i], fv[i]); } } - + // write distribution function to file char fname[1024]; sprintf(fname, "ctest_proj_mj_on_basis_test_1x1v_p%d.gkyl", poly_order); @@ -374,10 +370,12 @@ test_1x1v(int poly_order) } // special note, the p1 basis does not function -void test_proj_mj_on_basis_1x1v_p2_ho() { test_1x1v(2); } +void test_proj_mj_on_basis_1x1v_p2_ho() +{ + test_1x1v(2); +} -void -test_1x2v(int poly_order) +void test_1x2v(int poly_order) { double lower[] = {0.1, -15.0, -15.0}, upper[] = {1.0, 15.0, 15.0}; int cells[] = {2, 16, 16}; @@ -421,27 +419,27 @@ test_1x2v(int poly_order) m0 = mkarr(confBasis.num_basis, confLocal_ext.volume); m1i = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(confBasis.num_basis, confLocal_ext.volume); - moms = mkarr((vdim+2)*confBasis.num_basis, confLocal_ext.volume); + moms = mkarr((vdim + 2) * confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M0, NULL); - gkyl_proj_on_basis *proj_m1i = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, vdim, eval_M1i_2v, NULL); - gkyl_proj_on_basis *proj_m2 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M2_2v, NULL); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M0, NULL); + gkyl_proj_on_basis *proj_m1i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_M1i_2v, NULL); + gkyl_proj_on_basis *proj_m2 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M2_2v, NULL); gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i); gkyl_proj_on_basis_advance(proj_m2, 0.0, &confLocal, m2); - gkyl_array_set_offset_range(moms, 1.0, m0, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms, 1.0, m1i, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms, 1.0, m2, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m0, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m1i, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m2, (vdim + 1) * confBasis.num_basis, &confLocal); // build gamma and gamma_inv struct gkyl_array *gamma = mkarr(velBasis.num_basis, velLocal.volume); struct gkyl_array *gamma_inv = mkarr(velBasis.num_basis, velLocal.volume); - struct gkyl_dg_calc_sr_vars *sr_vars = gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, - &confBasis, &velBasis, &confLocal, &velLocal, false); + struct gkyl_dg_calc_sr_vars *sr_vars = + gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, &confBasis, &velBasis, &confLocal, &velLocal, false); // Project gamma and its inverse gkyl_calc_sr_vars_init_p_vars(sr_vars, gamma, gamma_inv); // Free SR variable computation @@ -454,30 +452,30 @@ test_1x2v(int poly_order) // projection updater to compute LTE distribution struct gkyl_vlasov_lte_proj_on_basis_inp inp_lte = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, - }; + .use_gpu = false + }; gkyl_vlasov_lte_proj_on_basis *proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_lte); gkyl_vlasov_lte_proj_on_basis_advance(proj_lte, &local, &confLocal, moms, distf); // values to compare at index (1, 9, 9) [remember, lower-left index is (1,1,1)] - double p2_vals[] = {1.6408879023240103e-01, -1.3576896184824113e-17, -9.8151809581183153e-03, - -2.9682559802577287e-02, 1.2829937358239629e-18, 3.8215290052990313e-19, - 8.6596866231148772e-03, -2.9507573862413946e-18, -9.7332674540940786e-03, - -7.2599184095971433e-03, 6.4445077190172000e-19, 1.4972406793044089e-17, - 1.6202061433993536e-20, 1.0653781194370923e-17, 1.7475225696783907e-03, - -5.7723245596542925e-19, -4.1851388419497057e-04, -4.9153245858838362e-19, - 5.5404332026569672e-19, 5.9845689181369784e-19}; + double p2_vals[] = {1.6408879023240103e-01, -1.3576896184824113e-17, -9.8151809581183153e-03, + -2.9682559802577287e-02, 1.2829937358239629e-18, 3.8215290052990313e-19, + 8.6596866231148772e-03, -2.9507573862413946e-18, -9.7332674540940786e-03, + -7.2599184095971433e-03, 6.4445077190172000e-19, 1.4972406793044089e-17, + 1.6202061433993536e-20, 1.0653781194370923e-17, 1.7475225696783907e-03, + -5.7723245596542925e-19, -4.1851388419497057e-04, -4.9153245858838362e-19, + 5.5404332026569672e-19, 5.9845689181369784e-19}; const double *fv = gkyl_array_cfetch(distf, gkyl_range_idx(&local_ext, (int[3]){1, 9, 9})); @@ -507,10 +505,12 @@ test_1x2v(int poly_order) gkyl_array_release(gamma_inv); } -void test_proj_mj_on_basis_1x2v_p2_ho() { test_1x2v(2); } +void test_proj_mj_on_basis_1x2v_p2_ho() +{ + test_1x2v(2); +} -void -test_1x3v(int poly_order) +void test_1x3v(int poly_order) { double lower[] = {0.1, -15.0, -15.0, -15.0}, upper[] = {1.0, 15.0, 15.0, 15.0}; int cells[] = {2, 16, 16, 16}; @@ -554,27 +554,27 @@ test_1x3v(int poly_order) m0 = mkarr(confBasis.num_basis, confLocal_ext.volume); m1i = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); m2 = mkarr(confBasis.num_basis, confLocal_ext.volume); - moms = mkarr((vdim+2)*confBasis.num_basis, confLocal_ext.volume); + moms = mkarr((vdim + 2) * confBasis.num_basis, confLocal_ext.volume); - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M0, NULL); - gkyl_proj_on_basis *proj_m1i = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, vdim, eval_M1i_3v, NULL); - gkyl_proj_on_basis *proj_m2 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M2_3v, NULL); + gkyl_proj_on_basis *proj_m0 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M0, NULL); + gkyl_proj_on_basis *proj_m1i = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, vdim, eval_M1i_3v, NULL); + gkyl_proj_on_basis *proj_m2 = + gkyl_proj_on_basis_new(&confGrid, &confBasis, poly_order + 1, 1, eval_M2_3v, NULL); gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i); gkyl_proj_on_basis_advance(proj_m2, 0.0, &confLocal, m2); - gkyl_array_set_offset_range(moms, 1.0, m0, 0*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms, 1.0, m1i, 1*confBasis.num_basis, &confLocal); - gkyl_array_set_offset_range(moms, 1.0, m2, (vdim+1)*confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m0, 0 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m1i, 1 * confBasis.num_basis, &confLocal); + gkyl_array_set_offset_range(moms, 1.0, m2, (vdim + 1) * confBasis.num_basis, &confLocal); // build gamma and gamma_inv struct gkyl_array *gamma = mkarr(velBasis.num_basis, velLocal.volume); struct gkyl_array *gamma_inv = mkarr(velBasis.num_basis, velLocal.volume); - struct gkyl_dg_calc_sr_vars *sr_vars = gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, - &confBasis, &velBasis, &confLocal, &velLocal, false); + struct gkyl_dg_calc_sr_vars *sr_vars = + gkyl_dg_calc_sr_vars_new(&grid, &vel_grid, &confBasis, &velBasis, &confLocal, &velLocal, false); // Project gamma and its inverse gkyl_calc_sr_vars_init_p_vars(sr_vars, gamma, gamma_inv); // Free SR variable computation @@ -587,39 +587,39 @@ test_1x3v(int poly_order) // projection updater to compute LTE distribution struct gkyl_vlasov_lte_proj_on_basis_inp inp_lte = { .phase_grid = &grid, - .vel_grid = &vel_grid, + .vel_grid = &vel_grid, .conf_basis = &confBasis, - .vel_basis = &velBasis, + .vel_basis = &velBasis, .phase_basis = &basis, - .conf_range = &confLocal, + .conf_range = &confLocal, .conf_range_ext = &confLocal_ext, .vel_range = &velLocal, .phase_range = &local, .gamma = gamma, .gamma_inv = gamma_inv, .model_id = GKYL_MODEL_SR, - .use_gpu = false, - }; + .use_gpu = false + }; gkyl_vlasov_lte_proj_on_basis *proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_lte); gkyl_vlasov_lte_proj_on_basis_advance(proj_lte, &local, &confLocal, moms, distf); // values to compare at index (1, 9, 9, 9) [remember, lower-left index is (1,1,1,1)] - double p2_vals[] = {2.2004825355599965e-02, 7.1324343268494727e-19, -1.2968205139278119e-03, - -3.9683045523914544e-03, -1.1492140196787010e-02, 2.0065506128885464e-19, - 2.6863348725598927e-19, 1.0399887120789773e-03, 6.2237804549528725e-19, - 1.2878059167286534e-03, 2.6451147610928889e-03, -6.3077058326192259e-18, - -1.3820826308538342e-03, -1.0478012443518811e-03, 1.6782192015094876e-03, - 7.3099489316101678e-20, -2.2315380074151361e-19, -1.5210474522584246e-19, - -8.4301245320312257e-04, 2.8388294826914462e-18, -5.5972719240227798e-19, - 2.7769888555314303e-18, 2.6587058568191109e-04, -2.6096614467447103e-19, - -2.0844243229831450e-05, 6.3431871295172754e-18, 7.3781907692053105e-04, - 4.9347115341968450e-04, 2.2046700923304946e-20, -3.7605267297870676e-04, - -5.6100948433461376e-04, 3.5408403867716293e-20, -3.8294647162266746e-19, - -3.0565669788894797e-20, -2.3269941088952652e-20, -1.0021845103459830e-18, - 2.4164727245648497e-19, -1.7030071204748659e-18, -1.4254568013549241e-04, - 1.2495807446563311e-19, 3.8839940617297632e-05, -5.3617945589348144e-20, - -4.8911545428669850e-20, 2.5014295050500632e-04, 2.0619708529882749e-19, - -6.1276211233163564e-20, -6.5891739087463357e-20, -1.0199525829477060e-19}; + double p2_vals[] = {2.2004825355599965e-02, 7.1324343268494727e-19, -1.2968205139278119e-03, + -3.9683045523914544e-03, -1.1492140196787010e-02, 2.0065506128885464e-19, + 2.6863348725598927e-19, 1.0399887120789773e-03, 6.2237804549528725e-19, + 1.2878059167286534e-03, 2.6451147610928889e-03, -6.3077058326192259e-18, + -1.3820826308538342e-03, -1.0478012443518811e-03, 1.6782192015094876e-03, + 7.3099489316101678e-20, -2.2315380074151361e-19, -1.5210474522584246e-19, + -8.4301245320312257e-04, 2.8388294826914462e-18, -5.5972719240227798e-19, + 2.7769888555314303e-18, 2.6587058568191109e-04, -2.6096614467447103e-19, + -2.0844243229831450e-05, 6.3431871295172754e-18, 7.3781907692053105e-04, + 4.9347115341968450e-04, 2.2046700923304946e-20, -3.7605267297870676e-04, + -5.6100948433461376e-04, 3.5408403867716293e-20, -3.8294647162266746e-19, + -3.0565669788894797e-20, -2.3269941088952652e-20, -1.0021845103459830e-18, + 2.4164727245648497e-19, -1.7030071204748659e-18, -1.4254568013549241e-04, + 1.2495807446563311e-19, 3.8839940617297632e-05, -5.3617945589348144e-20, + -4.8911545428669850e-20, 2.5014295050500632e-04, 2.0619708529882749e-19, + -6.1276211233163564e-20, -6.5891739087463357e-20, -1.0199525829477060e-19}; const double *fv = gkyl_array_cfetch(distf, gkyl_range_idx(&local_ext, (int[4]){1, 9, 9, 9})); @@ -649,12 +649,15 @@ test_1x3v(int poly_order) gkyl_array_release(gamma_inv); } -void test_proj_mj_on_basis_1x3v_p2_ho() { test_1x3v(2); } +void test_proj_mj_on_basis_1x3v_p2_ho() +{ + test_1x3v(2); +} TEST_LIST = { {"test_proj_mj_on_basis_1x1v_no_drift_p2_ho", test_proj_mj_on_basis_1x1v_no_drift_p2_ho}, {"test_proj_mj_on_basis_1x1v_p2_ho", test_proj_mj_on_basis_1x1v_p2_ho}, {"test_proj_mj_on_basis_1x2v_p2_ho", test_proj_mj_on_basis_1x2v_p2_ho}, {"test_proj_mj_on_basis_1x3v_p2_ho", test_proj_mj_on_basis_1x3v_p2_ho}, - {NULL, NULL}, + {NULL, NULL} }; diff --git a/vlasov/unit/ctest_spitzer_coll_freq.c b/vlasov/unit/ctest_spitzer_coll_freq.c index 3bbfac16b0..95303dbe31 100644 --- a/vlasov/unit/ctest_spitzer_coll_freq.c +++ b/vlasov/unit/ctest_spitzer_coll_freq.c @@ -12,60 +12,58 @@ #include "math.h" // allocate array (filled with zeros) -static struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { - struct gkyl_array* a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); return a; } -void eval_m0s_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_m0s_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - double Lx = 2.*M_PI; - fout[0] = 0.5*(1.+cos(0.5*2.*M_PI*x/Lx)); + double Lx = 2. * M_PI; + fout[0] = 0.5 * (1. + cos(0.5 * 2. * M_PI * x / Lx)); } -void eval_m0r_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_m0r_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - double Lx = 2.*M_PI; - fout[0] = 0.5*(1.+cos(0.5*2.*M_PI*x/Lx)); + double Lx = 2. * M_PI; + fout[0] = 0.5 * (1. + cos(0.5 * 2. * M_PI * x / Lx)); } -void eval_vtsqs_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_vtsqs_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - double Lx = 2.*M_PI; - fout[0] = -x*x+1.5*pow(M_PI,2); + double Lx = 2. * M_PI; + fout[0] = -x * x + 1.5 * pow(M_PI, 2); } -void eval_vtsqr_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_vtsqr_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - double Lx = 2.*M_PI; - fout[0] = -x*x+3.5*pow(M_PI,2); + double Lx = 2. * M_PI; + fout[0] = -x * x + 3.5 * pow(M_PI, 2); } -void eval_nu_1x(double t, const double *xn, double* restrict fout, void *ctx) +void eval_nu_1x(double t, const double *xn, double *restrict fout, void *ctx) { double x = xn[0]; - double Lx = 2.*M_PI; - double norm_nu = 1./3.; + double Lx = 2. * M_PI; + double norm_nu = 1. / 3.; double vtsqs[1], m0r[1], vtsqr[1]; eval_vtsqs_1x(t, xn, vtsqs, ctx); eval_m0r_1x(t, xn, m0r, ctx); eval_vtsqr_1x(t, xn, vtsqr, ctx); - fout[0] = norm_nu * m0r[0]/pow(vtsqs[0]+vtsqr[0],1.5); + fout[0] = norm_nu * m0r[0] / pow(vtsqs[0] + vtsqr[0], 1.5); } -void -test_1x(int poly_order, bool use_gpu) +void test_1x(int poly_order, bool use_gpu) { - double Lx = 2.*M_PI; - double lower[] = {-Lx/2.}, upper[] = {Lx/2.}; + double Lx = 2. * M_PI; + double lower[] = {-Lx / 2.}, upper[] = {Lx / 2.}; int cells[] = {32}; - double norm_nu = 1./3.; + double norm_nu = 1. / 3.; - int ndim = sizeof(lower)/sizeof(lower[0]); + int ndim = sizeof(lower) / sizeof(lower[0]); // Grids. struct gkyl_rect_grid grid; @@ -75,7 +73,7 @@ test_1x(int poly_order, bool use_gpu) struct gkyl_basis basis; gkyl_cart_modal_serendip(&basis, ndim, poly_order); - int ghost[] = { 1 }; + int ghost[] = {1}; struct gkyl_range local, local_ext; // Local, local-ext phase-space ranges. gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); @@ -87,26 +85,25 @@ test_1x(int poly_order, bool use_gpu) vtsqr = mkarr(use_gpu, basis.num_basis, local_ext.volume); struct gkyl_array *m0s_ho, *vtsqs_ho, *m0r_ho, *vtsqr_ho; if (use_gpu) { // Create device copies - m0s_ho = mkarr(false, m0s->ncomp, m0s->size); + m0s_ho = mkarr(false, m0s->ncomp, m0s->size); vtsqs_ho = mkarr(false, vtsqs->ncomp, vtsqs->size); - m0r_ho = mkarr(false, m0r->ncomp, m0r->size); + m0r_ho = mkarr(false, m0r->ncomp, m0r->size); vtsqr_ho = mkarr(false, vtsqr->ncomp, vtsqr->size); - } - else { - m0s_ho = gkyl_array_acquire(m0s ); + } else { + m0s_ho = gkyl_array_acquire(m0s); vtsqs_ho = gkyl_array_acquire(vtsqs); - m0r_ho = gkyl_array_acquire(m0r ); + m0r_ho = gkyl_array_acquire(m0r); vtsqr_ho = gkyl_array_acquire(vtsqr); } - gkyl_proj_on_basis *proj_m0s = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_m0s_1x, NULL); - gkyl_proj_on_basis *proj_vtsqs = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_vtsqs_1x, NULL); - gkyl_proj_on_basis *proj_m0r = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_m0r_1x, NULL); - gkyl_proj_on_basis *proj_vtsqr = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_vtsqr_1x, NULL); + gkyl_proj_on_basis *proj_m0s = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_m0s_1x, NULL); + gkyl_proj_on_basis *proj_vtsqs = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_vtsqs_1x, NULL); + gkyl_proj_on_basis *proj_m0r = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_m0r_1x, NULL); + gkyl_proj_on_basis *proj_vtsqr = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_vtsqr_1x, NULL); gkyl_proj_on_basis_advance(proj_m0s, 0.0, &local, m0s_ho); gkyl_proj_on_basis_advance(proj_vtsqs, 0.0, &local, vtsqs_ho); @@ -120,22 +117,22 @@ test_1x(int poly_order, bool use_gpu) gkyl_array_copy(vtsqr, vtsqr_ho); // Package moments into a Maxwellian moments array (u =0); - struct gkyl_array *moms_s = mkarr(use_gpu, 3*basis.num_basis, local_ext.volume); + struct gkyl_array *moms_s = mkarr(use_gpu, 3 * basis.num_basis, local_ext.volume); gkyl_array_set_offset(moms_s, 1.0, m0s, 0); - gkyl_array_set_offset(moms_s, 1.0, vtsqs, 2*basis.num_basis); - struct gkyl_array *moms_r = mkarr(use_gpu, 3*basis.num_basis, local_ext.volume); + gkyl_array_set_offset(moms_s, 1.0, vtsqs, 2 * basis.num_basis); + struct gkyl_array *moms_r = mkarr(use_gpu, 3 * basis.num_basis, local_ext.volume); gkyl_array_set_offset(moms_r, 1.0, m0r, 0); - gkyl_array_set_offset(moms_r, 1.0, vtsqr, 2*basis.num_basis); + gkyl_array_set_offset(moms_r, 1.0, vtsqr, 2 * basis.num_basis); // Create collision frequency array. struct gkyl_array *nu, *nu_ho; nu = mkarr(use_gpu, basis.num_basis, local_ext.volume); - nu_ho = use_gpu? mkarr(false, nu->ncomp, nu->size) - : gkyl_array_acquire(nu); + nu_ho = use_gpu ? mkarr(false, nu->ncomp, nu->size) : gkyl_array_acquire(nu); // Create Spitzer collision frequency updater. double nufrac = 1., epsilon_0 = 1., hbar = 1.; - gkyl_spitzer_coll_freq *spitz_up = gkyl_spitzer_coll_freq_new(&basis, poly_order+1, nufrac, epsilon_0, hbar, use_gpu); + gkyl_spitzer_coll_freq *spitz_up = + gkyl_spitzer_coll_freq_new(&basis, poly_order + 1, nufrac, epsilon_0, hbar, use_gpu); gkyl_spitzer_coll_freq_advance_normnu(spitz_up, &local, moms_s, 0., moms_r, 0., norm_nu, nu); gkyl_array_copy(nu_ho, nu); @@ -143,17 +140,17 @@ test_1x(int poly_order, bool use_gpu) // Project expected collision frequency and compare. struct gkyl_array *nuA_ho; nuA_ho = mkarr(false, basis.num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_nu = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_nu_1x, NULL); + gkyl_proj_on_basis *proj_nu = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_nu_1x, NULL); gkyl_proj_on_basis_advance(proj_nu, 0.0, &local, nuA_ho); - for (int k=0; kncomp, m0s->size); + m0s_ho = mkarr(false, m0s->ncomp, m0s->size); vtsqs_ho = mkarr(false, vtsqs->ncomp, vtsqs->size); - m0r_ho = mkarr(false, m0r->ncomp, m0r->size); + m0r_ho = mkarr(false, m0r->ncomp, m0r->size); vtsqr_ho = mkarr(false, vtsqr->ncomp, vtsqr->size); - } - else { - m0s_ho = gkyl_array_acquire(m0s ); + } else { + m0s_ho = gkyl_array_acquire(m0s); vtsqs_ho = gkyl_array_acquire(vtsqs); - m0r_ho = gkyl_array_acquire(m0r ); + m0r_ho = gkyl_array_acquire(m0r); vtsqr_ho = gkyl_array_acquire(vtsqr); } - gkyl_proj_on_basis *proj_m0s = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_m0s_2x, NULL); - gkyl_proj_on_basis *proj_vtsqs = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_vtsqs_2x, NULL); - gkyl_proj_on_basis *proj_m0r = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_m0r_2x, NULL); - gkyl_proj_on_basis *proj_vtsqr = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_vtsqr_2x, NULL); + gkyl_proj_on_basis *proj_m0s = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_m0s_2x, NULL); + gkyl_proj_on_basis *proj_vtsqs = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_vtsqs_2x, NULL); + gkyl_proj_on_basis *proj_m0r = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_m0r_2x, NULL); + gkyl_proj_on_basis *proj_vtsqr = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_vtsqr_2x, NULL); gkyl_proj_on_basis_advance(proj_m0s, 0.0, &local, m0s_ho); gkyl_proj_on_basis_advance(proj_vtsqs, 0.0, &local, vtsqs_ho); @@ -282,22 +277,22 @@ test_2x(int poly_order, bool use_gpu) gkyl_array_copy(vtsqr, vtsqr_ho); // Package moments into a Maxwellian moments array (u =0); - struct gkyl_array *moms_s = mkarr(use_gpu, 3*basis.num_basis, local_ext.volume); + struct gkyl_array *moms_s = mkarr(use_gpu, 3 * basis.num_basis, local_ext.volume); gkyl_array_set_offset(moms_s, 1.0, m0s, 0); - gkyl_array_set_offset(moms_s, 1.0, vtsqs, 2*basis.num_basis); - struct gkyl_array *moms_r = mkarr(use_gpu, 3*basis.num_basis, local_ext.volume); + gkyl_array_set_offset(moms_s, 1.0, vtsqs, 2 * basis.num_basis); + struct gkyl_array *moms_r = mkarr(use_gpu, 3 * basis.num_basis, local_ext.volume); gkyl_array_set_offset(moms_r, 1.0, m0r, 0); - gkyl_array_set_offset(moms_r, 1.0, vtsqr, 2*basis.num_basis); + gkyl_array_set_offset(moms_r, 1.0, vtsqr, 2 * basis.num_basis); // Create collision frequency array. struct gkyl_array *nu, *nu_ho; nu = mkarr(use_gpu, basis.num_basis, local_ext.volume); - nu_ho = use_gpu? mkarr(false, nu->ncomp, nu->size) - : gkyl_array_acquire(nu); + nu_ho = use_gpu ? mkarr(false, nu->ncomp, nu->size) : gkyl_array_acquire(nu); // Create Spitzer collision frequency updater. double nufrac = 1., epsilon_0 = 1., hbar = 1.; - gkyl_spitzer_coll_freq *spitz_up = gkyl_spitzer_coll_freq_new(&basis, poly_order+1, nufrac, epsilon_0, hbar, use_gpu); + gkyl_spitzer_coll_freq *spitz_up = + gkyl_spitzer_coll_freq_new(&basis, poly_order + 1, nufrac, epsilon_0, hbar, use_gpu); gkyl_spitzer_coll_freq_advance_normnu(spitz_up, &local, moms_s, 0., moms_r, 0., norm_nu, nu); gkyl_array_copy(nu_ho, nu); @@ -305,18 +300,18 @@ test_2x(int poly_order, bool use_gpu) // Project expected collision frequency and compare. struct gkyl_array *nuA_ho; nuA_ho = mkarr(false, basis.num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_nu = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_nu_2x, NULL); + gkyl_proj_on_basis *proj_nu = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_nu_2x, NULL); gkyl_proj_on_basis_advance(proj_nu, 0.0, &local, nuA_ho); - for (int j=0; jncomp, m0s->size); + m0s_ho = mkarr(false, m0s->ncomp, m0s->size); vtsqs_ho = mkarr(false, vtsqs->ncomp, vtsqs->size); - m0r_ho = mkarr(false, m0r->ncomp, m0r->size); + m0r_ho = mkarr(false, m0r->ncomp, m0r->size); vtsqr_ho = mkarr(false, vtsqr->ncomp, vtsqr->size); - } - else { - m0s_ho = gkyl_array_acquire(m0s ); + } else { + m0s_ho = gkyl_array_acquire(m0s); vtsqs_ho = gkyl_array_acquire(vtsqs); - m0r_ho = gkyl_array_acquire(m0r ); + m0r_ho = gkyl_array_acquire(m0r); vtsqr_ho = gkyl_array_acquire(vtsqr); } - gkyl_proj_on_basis *proj_m0s = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_m0s_3x, NULL); - gkyl_proj_on_basis *proj_vtsqs = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_vtsqs_3x, NULL); - gkyl_proj_on_basis *proj_m0r = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_m0r_3x, NULL); - gkyl_proj_on_basis *proj_vtsqr = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_vtsqr_3x, NULL); + gkyl_proj_on_basis *proj_m0s = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_m0s_3x, NULL); + gkyl_proj_on_basis *proj_vtsqs = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_vtsqs_3x, NULL); + gkyl_proj_on_basis *proj_m0r = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_m0r_3x, NULL); + gkyl_proj_on_basis *proj_vtsqr = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_vtsqr_3x, NULL); gkyl_proj_on_basis_advance(proj_m0s, 0.0, &local, m0s_ho); gkyl_proj_on_basis_advance(proj_vtsqs, 0.0, &local, vtsqs_ho); @@ -446,22 +443,22 @@ test_3x(int poly_order, bool use_gpu) gkyl_array_copy(vtsqr, vtsqr_ho); // Package moments into a Maxwellian moments array (u =0); - struct gkyl_array *moms_s = mkarr(use_gpu, 3*basis.num_basis, local_ext.volume); + struct gkyl_array *moms_s = mkarr(use_gpu, 3 * basis.num_basis, local_ext.volume); gkyl_array_set_offset(moms_s, 1.0, m0s, 0); - gkyl_array_set_offset(moms_s, 1.0, vtsqs, 2*basis.num_basis); - struct gkyl_array *moms_r = mkarr(use_gpu, 3*basis.num_basis, local_ext.volume); + gkyl_array_set_offset(moms_s, 1.0, vtsqs, 2 * basis.num_basis); + struct gkyl_array *moms_r = mkarr(use_gpu, 3 * basis.num_basis, local_ext.volume); gkyl_array_set_offset(moms_r, 1.0, m0r, 0); - gkyl_array_set_offset(moms_r, 1.0, vtsqr, 2*basis.num_basis); + gkyl_array_set_offset(moms_r, 1.0, vtsqr, 2 * basis.num_basis); // Create collision frequency array. struct gkyl_array *nu, *nu_ho; nu = mkarr(use_gpu, basis.num_basis, local_ext.volume); - nu_ho = use_gpu? mkarr(false, nu->ncomp, nu->size) - : gkyl_array_acquire(nu); + nu_ho = use_gpu ? mkarr(false, nu->ncomp, nu->size) : gkyl_array_acquire(nu); // Create Spitzer collision frequency updater. double nufrac = 1., epsilon_0 = 1., hbar = 1.; - gkyl_spitzer_coll_freq *spitz_up = gkyl_spitzer_coll_freq_new(&basis, poly_order+1, nufrac, epsilon_0, hbar, use_gpu); + gkyl_spitzer_coll_freq *spitz_up = + gkyl_spitzer_coll_freq_new(&basis, poly_order + 1, nufrac, epsilon_0, hbar, use_gpu); gkyl_spitzer_coll_freq_advance_normnu(spitz_up, &local, moms_s, 0., moms_r, 0., norm_nu, nu); gkyl_array_copy(nu_ho, nu); @@ -469,19 +466,19 @@ test_3x(int poly_order, bool use_gpu) // Project expected collision frequency and compare. struct gkyl_array *nuA_ho; nuA_ho = mkarr(false, basis.num_basis, local_ext.volume); - gkyl_proj_on_basis *proj_nu = gkyl_proj_on_basis_new(&grid, &basis, - poly_order+1, 1, eval_nu_3x, NULL); + gkyl_proj_on_basis *proj_nu = + gkyl_proj_on_basis_new(&grid, &basis, poly_order + 1, 1, eval_nu_3x, NULL); gkyl_proj_on_basis_advance(proj_nu, 0.0, &local, nuA_ho); - for (int i=0; i // Allocate array (filled with zeros). -static struct gkyl_array* -mkarr(bool use_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool use_gpu, long nc, long size) { #ifdef GKYL_HAVE_CUDA - struct gkyl_array* a = use_gpu? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) - : gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = use_gpu ? gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size) : + gkyl_array_new(GKYL_DOUBLE, nc, size); #else - struct gkyl_array* a = gkyl_array_new(GKYL_DOUBLE, nc, size); + struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); #endif return a; } -void test_vmap_1x2v_p1_mapc2p_vel_vpar(double t, const double *zc, double* GKYL_RESTRICT vp, void *ctx) +void test_vmap_1x2v_p1_mapc2p_vel_vpar( + double t, const double *zc, double *GKYL_RESTRICT vp, void *ctx +) { double vparc = zc[0]; - vp[0] = vparc<0.? -pow(vparc,2) : pow(vparc,2); // Quadratic mapping. + vp[0] = vparc < 0. ? -pow(vparc, 2) : pow(vparc, 2); // Quadratic mapping. } -void test_vmap_1x2v_p1_mapc2p_vel_mu(double t, const double *zc, double* GKYL_RESTRICT vp, void *ctx) +void test_vmap_1x2v_p1_mapc2p_vel_mu(double t, const double *zc, double *GKYL_RESTRICT vp, void *ctx) { double muc = zc[0]; - vp[0] = pow(muc,2); // Quadratic mapping. + vp[0] = pow(muc, 2); // Quadratic mapping. } -void test_vmap_1x2v_p1_mapc2p_vel(double t, const double *zc, double* GKYL_RESTRICT vp, void *ctx) +void test_vmap_1x2v_p1_mapc2p_vel(double t, const double *zc, double *GKYL_RESTRICT vp, void *ctx) { double vparc[] = {zc[0]}, muc[] = {zc[1]}; double vparp[1], mup[1]; @@ -51,29 +52,28 @@ void test_vmap_1x2v_p1_mapc2p_vel(double t, const double *zc, double* GKYL_RESTR vp[1] = mup[0]; } -void -test_vmap_1x2v_p1(bool use_gpu) +void test_vmap_1x2v_p1(bool use_gpu) { int poly_order = 1; double lower[] = {-M_PI, -1.0, 0.0}, upper[] = {M_PI, 1.0, 1.0}; int cells[] = {2, 12, 6}; int vdim = 2; - int pdim = sizeof(lower)/sizeof(lower[0]); + int pdim = sizeof(lower) / sizeof(lower[0]); int cdim = pdim - vdim; double lower_conf[cdim], upper_conf[cdim]; int cells_conf[cdim]; - for (int d=0; dvmap->ncomp, gvm->vmap->size); @@ -124,15 +130,15 @@ test_vmap_1x2v_p1(bool use_gpu) struct gkyl_array *vmap_ref; // Check vpar mapping. - lower_ref[0] = lower[cdim+0]; - upper_ref[0] = upper[cdim+0]; - cells_ref[0] = cells[cdim+0]; + lower_ref[0] = lower[cdim + 0]; + upper_ref[0] = upper[cdim + 0]; + cells_ref[0] = cells[cdim + 0]; gkyl_rect_grid_init(&grid_ref, 1, lower_ref, upper_ref, cells_ref); ghost_ref[0] = ghost_vel[0]; gkyl_create_grid_ranges(&grid_ref, ghost_ref, &local_ext_ref, &local_ref); vmap_ref = mkarr(false, basis_ref.num_basis, local_ext_ref.volume); - struct gkyl_eval_on_nodes* evOnNod_vpar = gkyl_eval_on_nodes_new(&grid_ref, &basis_ref, - 1, test_vmap_1x2v_p1_mapc2p_vel_vpar, NULL); + struct gkyl_eval_on_nodes *evOnNod_vpar = + gkyl_eval_on_nodes_new(&grid_ref, &basis_ref, 1, test_vmap_1x2v_p1_mapc2p_vel_vpar, NULL); gkyl_eval_on_nodes_advance(evOnNod_vpar, 0., &local_ref, vmap_ref); gkyl_eval_on_nodes_release(evOnNod_vpar); @@ -143,23 +149,23 @@ test_vmap_1x2v_p1(bool use_gpu) long loc_ref = gkyl_range_idx(&local_ref, idx_ref); double *vm = gkyl_array_fetch(vmap_ho, loc); double *vm_ref = gkyl_array_fetch(vmap_ref, loc_ref); - for (int i=0; ifunc = copy_bc; - break; - - case GKYL_BC_ABSORB: - fout->func = species_absorb_bc; - break; - - case GKYL_BC_REFLECT: - fout->func = reflect_bc; - break; - - case GKYL_BC_DISTF_REFLECT: - fout->func = species_reflect_bc; - break; - - case GKYL_BC_CONF_BOUNDARY_VALUE: - fout->func = conf_boundary_value_bc; - break; - - // Maxwell's perfect electrical conductor (zero normal B and zero tangent E) - case GKYL_BC_MAXWELL_PEC: - fout->func = maxwell_pec_bc; - break; - - // Maxwell's symmetry BC (zero normal E and zero tangent B) - case GKYL_BC_MAXWELL_SYM: - fout->func = maxwell_sym_bc; - break; - - // Reservoir Maxwell's BCs for heat flux problem - // Based on Roberg-Clark et al. PRL 2018 - // NOTE: ONLY WORKS WITH X BOUNDARY - case GKYL_BC_MAXWELL_RESERVOIR: - fout->func = maxwell_reservoir_bc; - break; - - // PKPM Reflecting wall for distribution function - case GKYL_BC_PKPM_SPECIES_REFLECT: - fout->func = pkpm_species_reflect_bc; - break; - - // PKPM Reflecting wall for momentum - case GKYL_BC_PKPM_MOM_REFLECT: - fout->func = pkpm_mom_reflect_bc; - break; - - // PKPM No-slip wall for momentum - case GKYL_BC_PKPM_MOM_NO_SLIP: - fout->func = pkpm_mom_no_slip_bc; - break; - - // Euler Reflecting wall - case GKYL_BC_EULER_REFLECT: - fout->func = euler_reflect_bc; - break; - - // Euler No-slip wall - case GKYL_BC_EULER_NO_SLIP: - fout->func = euler_no_slip_bc; - break; - - default: - assert(false); - break; + case GKYL_BC_COPY: + case GKYL_BC_FIXED_FUNC: + fout->func = copy_bc; + break; + + case GKYL_BC_ABSORB: + fout->func = species_absorb_bc; + break; + + case GKYL_BC_REFLECT: + fout->func = reflect_bc; + break; + + case GKYL_BC_DISTF_REFLECT: + fout->func = species_reflect_bc; + break; + + case GKYL_BC_CONF_BOUNDARY_VALUE: + fout->func = conf_boundary_value_bc; + break; + + // Maxwell's perfect electrical conductor (zero normal B and zero tangent E) + case GKYL_BC_MAXWELL_PEC: + fout->func = maxwell_pec_bc; + break; + + // Maxwell's symmetry BC (zero normal E and zero tangent B) + case GKYL_BC_MAXWELL_SYM: + fout->func = maxwell_sym_bc; + break; + + // Reservoir Maxwell's BCs for heat flux problem + // Based on Roberg-Clark et al. PRL 2018 + // NOTE: ONLY WORKS WITH X BOUNDARY + case GKYL_BC_MAXWELL_RESERVOIR: + fout->func = maxwell_reservoir_bc; + break; + + // PKPM Reflecting wall for distribution function + case GKYL_BC_PKPM_SPECIES_REFLECT: + fout->func = pkpm_species_reflect_bc; + break; + + // PKPM Reflecting wall for momentum + case GKYL_BC_PKPM_MOM_REFLECT: + fout->func = pkpm_mom_reflect_bc; + break; + + // PKPM No-slip wall for momentum + case GKYL_BC_PKPM_MOM_NO_SLIP: + fout->func = pkpm_mom_no_slip_bc; + break; + + // Euler Reflecting wall + case GKYL_BC_EULER_REFLECT: + fout->func = euler_reflect_bc; + break; + + // Euler No-slip wall + case GKYL_BC_EULER_NO_SLIP: + fout->func = euler_no_slip_bc; + break; + + default: + assert(false); + break; } fout->ctx = ctx; fout->ctx_on_dev = fout->ctx; @@ -99,12 +101,12 @@ gkyl_bc_basic_create_arr_copy_func(int dir, enum gkyl_edge_loc edge, int cdim, e return fout; } -struct gkyl_bc_basic* -gkyl_bc_basic_new(int dir, enum gkyl_edge_loc edge, enum gkyl_bc_basic_type bctype, - const struct gkyl_basis *basis, const struct gkyl_range *skin_r, - const struct gkyl_range *ghost_r, int num_comp, int cdim, bool use_gpu) +struct gkyl_bc_basic *gkyl_bc_basic_new( + int dir, enum gkyl_edge_loc edge, enum gkyl_bc_basic_type bctype, const struct gkyl_basis *basis, + const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, int num_comp, int cdim, + bool use_gpu +) { - // Allocate space for new updater. struct gkyl_bc_basic *up = gkyl_malloc(sizeof(struct gkyl_bc_basic)); @@ -118,51 +120,55 @@ gkyl_bc_basic_new(int dir, enum gkyl_edge_loc edge, enum gkyl_bc_basic_type bcty // Create function applied to array contents (DG coefficients) when // copying to/from buffer. - up->array_copy_func = gkyl_bc_basic_create_arr_copy_func(dir, edge, cdim, up->bctype, basis, num_comp, use_gpu); + up->array_copy_func = + gkyl_bc_basic_create_arr_copy_func(dir, edge, cdim, up->bctype, basis, num_comp, use_gpu); return up; } -void -gkyl_bc_basic_buffer_fixed_func(const struct gkyl_bc_basic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr) +void gkyl_bc_basic_buffer_fixed_func( + const struct gkyl_bc_basic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr +) { - if (up->bctype == GKYL_BC_FIXED_FUNC) - gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, - up->skin_r, up->array_copy_func->on_dev); + if (up->bctype == GKYL_BC_FIXED_FUNC) { + gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, up->skin_r, up->array_copy_func->on_dev); + } } -void -gkyl_bc_basic_advance(const struct gkyl_bc_basic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr) +void gkyl_bc_basic_advance( + const struct gkyl_bc_basic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr +) { // Apply BC in two steps: // 1) Copy skin to buffer while applying array_copy_func. switch (up->bctype) { - case GKYL_BC_COPY: - case GKYL_BC_ABSORB: - case GKYL_BC_REFLECT: - case GKYL_BC_MAXWELL_PEC: - case GKYL_BC_MAXWELL_SYM: - case GKYL_BC_MAXWELL_RESERVOIR: - case GKYL_BC_PKPM_MOM_REFLECT: - case GKYL_BC_PKPM_MOM_NO_SLIP: - case GKYL_BC_EULER_REFLECT: - case GKYL_BC_EULER_NO_SLIP: - gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, - up->skin_r, up->array_copy_func->on_dev); - break; - - case GKYL_BC_DISTF_REFLECT: - case GKYL_BC_PKPM_SPECIES_REFLECT: - gkyl_array_flip_copy_to_buffer_fn(buff_arr->data, f_arr, up->dir+up->cdim, - up->skin_r, up->array_copy_func->on_dev); - break; - - case GKYL_BC_CONF_BOUNDARY_VALUE: - gkyl_array_flip_copy_to_buffer_fn(buff_arr->data, f_arr, up->dir, - up->skin_r, up->array_copy_func->on_dev); - break; - - case GKYL_BC_FIXED_FUNC: // if BC is fixed func, do nothing, buffer already full - break; + case GKYL_BC_COPY: + case GKYL_BC_ABSORB: + case GKYL_BC_REFLECT: + case GKYL_BC_MAXWELL_PEC: + case GKYL_BC_MAXWELL_SYM: + case GKYL_BC_MAXWELL_RESERVOIR: + case GKYL_BC_PKPM_MOM_REFLECT: + case GKYL_BC_PKPM_MOM_NO_SLIP: + case GKYL_BC_EULER_REFLECT: + case GKYL_BC_EULER_NO_SLIP: + gkyl_array_copy_to_buffer_fn(buff_arr->data, f_arr, up->skin_r, up->array_copy_func->on_dev); + break; + + case GKYL_BC_DISTF_REFLECT: + case GKYL_BC_PKPM_SPECIES_REFLECT: + gkyl_array_flip_copy_to_buffer_fn( + buff_arr->data, f_arr, up->dir + up->cdim, up->skin_r, up->array_copy_func->on_dev + ); + break; + + case GKYL_BC_CONF_BOUNDARY_VALUE: + gkyl_array_flip_copy_to_buffer_fn( + buff_arr->data, f_arr, up->dir, up->skin_r, up->array_copy_func->on_dev + ); + break; + + case GKYL_BC_FIXED_FUNC: // if BC is fixed func, do nothing, buffer already full + break; } // 2) Copy from buffer to ghost. gkyl_array_copy_from_buffer(f_arr, buff_arr->data, up->ghost_r); diff --git a/vlasov/zero/bc_basic_cu.cu b/vlasov/zero/bc_basic_cu.cu index f15671a1c4..15ab7eb124 100644 --- a/vlasov/zero/bc_basic_cu.cu +++ b/vlasov/zero/bc_basic_cu.cu @@ -7,9 +7,11 @@ extern "C" { #include } -__global__ static void -gkyl_bc_basic_create_set_cu_dev_ptrs(int dir, enum gkyl_edge_loc edge, int cdim, enum gkyl_bc_basic_type bctype, - const struct gkyl_basis* basis, int ncomp, struct dg_bc_ctx *ctx, struct gkyl_array_copy_func *fout) +__global__ static void gkyl_bc_basic_create_set_cu_dev_ptrs( + int dir, enum gkyl_edge_loc edge, int cdim, enum gkyl_bc_basic_type bctype, + const struct gkyl_basis *basis, int ncomp, struct dg_bc_ctx *ctx, + struct gkyl_array_copy_func *fout +) { ctx->dir = dir; ctx->edge = edge; @@ -18,99 +20,103 @@ gkyl_bc_basic_create_set_cu_dev_ptrs(int dir, enum gkyl_edge_loc edge, int cdim, ctx->ncomp = ncomp; switch (bctype) { - case GKYL_BC_COPY: - case GKYL_BC_FIXED_FUNC: - fout->func = copy_bc; - break; - - case GKYL_BC_ABSORB: - fout->func = species_absorb_bc; - break; - - case GKYL_BC_REFLECT: - fout->func = reflect_bc; - break; - - case GKYL_BC_DISTF_REFLECT: - fout->func = species_reflect_bc; - break; - - // Maxwell's perfect electrical conductor (zero normal B and zero tangent E) - case GKYL_BC_MAXWELL_PEC: - fout->func = maxwell_pec_bc; - break; - - // Maxwell's symmetry BC (zero normal E and zero tangent B) - case GKYL_BC_MAXWELL_SYM: - fout->func = maxwell_sym_bc; - break; - - // Reservoir Maxwell's BCs for heat flux problem - // Based on Roberg-Clark et al. PRL 2018 - // NOTE: ONLY WORKS WITH X BOUNDARY - case GKYL_BC_MAXWELL_RESERVOIR: - fout->func = maxwell_reservoir_bc; - break; - - // PKPM Reflecting wall for distribution function - case GKYL_BC_PKPM_SPECIES_REFLECT: - fout->func = pkpm_species_reflect_bc; - break; - - // PKPM Reflecting wall for momentum - case GKYL_BC_PKPM_MOM_REFLECT: - fout->func = pkpm_mom_reflect_bc; - break; - - // PKPM No-slip wall for momentum - case GKYL_BC_PKPM_MOM_NO_SLIP: - fout->func = pkpm_mom_no_slip_bc; - break; - - // Euler Reflecting wall - case GKYL_BC_EULER_REFLECT: - fout->func = euler_reflect_bc; - break; - - // Euler No-slip wall - case GKYL_BC_EULER_NO_SLIP: - fout->func = euler_no_slip_bc; - break; - - - case GKYL_BC_CONF_BOUNDARY_VALUE: - fout->func = conf_boundary_value_bc; - break; - - default: - assert(false); - break; + case GKYL_BC_COPY: + case GKYL_BC_FIXED_FUNC: + fout->func = copy_bc; + break; + + case GKYL_BC_ABSORB: + fout->func = species_absorb_bc; + break; + + case GKYL_BC_REFLECT: + fout->func = reflect_bc; + break; + + case GKYL_BC_DISTF_REFLECT: + fout->func = species_reflect_bc; + break; + + // Maxwell's perfect electrical conductor (zero normal B and zero tangent E) + case GKYL_BC_MAXWELL_PEC: + fout->func = maxwell_pec_bc; + break; + + // Maxwell's symmetry BC (zero normal E and zero tangent B) + case GKYL_BC_MAXWELL_SYM: + fout->func = maxwell_sym_bc; + break; + + // Reservoir Maxwell's BCs for heat flux problem + // Based on Roberg-Clark et al. PRL 2018 + // NOTE: ONLY WORKS WITH X BOUNDARY + case GKYL_BC_MAXWELL_RESERVOIR: + fout->func = maxwell_reservoir_bc; + break; + + // PKPM Reflecting wall for distribution function + case GKYL_BC_PKPM_SPECIES_REFLECT: + fout->func = pkpm_species_reflect_bc; + break; + + // PKPM Reflecting wall for momentum + case GKYL_BC_PKPM_MOM_REFLECT: + fout->func = pkpm_mom_reflect_bc; + break; + + // PKPM No-slip wall for momentum + case GKYL_BC_PKPM_MOM_NO_SLIP: + fout->func = pkpm_mom_no_slip_bc; + break; + + // Euler Reflecting wall + case GKYL_BC_EULER_REFLECT: + fout->func = euler_reflect_bc; + break; + + // Euler No-slip wall + case GKYL_BC_EULER_NO_SLIP: + fout->func = euler_no_slip_bc; + break; + + case GKYL_BC_CONF_BOUNDARY_VALUE: + fout->func = conf_boundary_value_bc; + break; + + default: + assert(false); + break; } fout->ctx = ctx; } -struct gkyl_array_copy_func* -gkyl_bc_basic_create_arr_copy_func_cu(int dir, enum gkyl_edge_loc edge, int cdim, enum gkyl_bc_basic_type bctype, - const struct gkyl_basis *basis, int ncomp) +struct gkyl_array_copy_func *gkyl_bc_basic_create_arr_copy_func_cu( + int dir, enum gkyl_edge_loc edge, int cdim, enum gkyl_bc_basic_type bctype, + const struct gkyl_basis *basis, int ncomp +) { // create host context and bc func structs - struct dg_bc_ctx *ctx = (struct dg_bc_ctx*) gkyl_malloc(sizeof(struct dg_bc_ctx)); - struct gkyl_array_copy_func *fout = (struct gkyl_array_copy_func*) gkyl_malloc(sizeof(struct gkyl_array_copy_func)); + struct dg_bc_ctx *ctx = (struct dg_bc_ctx *)gkyl_malloc(sizeof(struct dg_bc_ctx)); + struct gkyl_array_copy_func *fout = + (struct gkyl_array_copy_func *)gkyl_malloc(sizeof(struct gkyl_array_copy_func)); fout->ctx = ctx; fout->flags = 0; GKYL_SET_CU_ALLOC(fout->flags); // create device context and bc func structs - struct dg_bc_ctx *ctx_cu = (struct dg_bc_ctx*) gkyl_cu_malloc(sizeof(struct dg_bc_ctx)); - struct gkyl_array_copy_func *fout_cu = (struct gkyl_array_copy_func*) gkyl_cu_malloc(sizeof(struct gkyl_array_copy_func)); + struct dg_bc_ctx *ctx_cu = (struct dg_bc_ctx *)gkyl_cu_malloc(sizeof(struct dg_bc_ctx)); + struct gkyl_array_copy_func *fout_cu = + (struct gkyl_array_copy_func *)gkyl_cu_malloc(sizeof(struct gkyl_array_copy_func)); gkyl_cu_memcpy(ctx_cu, ctx, sizeof(struct dg_bc_ctx), GKYL_CU_MEMCPY_H2D); gkyl_cu_memcpy(fout_cu, fout, sizeof(struct gkyl_array_copy_func), GKYL_CU_MEMCPY_H2D); fout->ctx_on_dev = ctx_cu; - gkyl_bc_basic_create_set_cu_dev_ptrs<<<1,1>>>(dir, edge, cdim, bctype, basis, ncomp, ctx_cu, fout_cu); + gkyl_bc_basic_create_set_cu_dev_ptrs<<<1, 1> > >( + dir, edge, cdim, bctype, basis, ncomp, ctx_cu, fout_cu + ); // set parent on_dev pointer fout->on_dev = fout_cu; diff --git a/vlasov/zero/bc_emission.c b/vlasov/zero/bc_emission.c index 6de0b68f11..dbd38089f9 100644 --- a/vlasov/zero/bc_emission.c +++ b/vlasov/zero/bc_emission.c @@ -2,34 +2,37 @@ #include // ctx with models specified by user -struct gkyl_bc_emission_ctx* -gkyl_bc_emission_new(int num_species, double t_bound, bool elastic, +struct gkyl_bc_emission_ctx *gkyl_bc_emission_new( + int num_species, double t_bound, bool elastic, struct gkyl_emission_spectrum_model *spectrum_model[], struct gkyl_emission_yield_model *yield_model[], - struct gkyl_emission_elastic_model *elastic_model, char in_species[][128]) + struct gkyl_emission_elastic_model *elastic_model, char in_species[][128] +) { struct gkyl_bc_emission_ctx *ctx = gkyl_malloc(sizeof(struct gkyl_bc_emission_ctx)); - + ctx->num_species = num_species; ctx->t_bound = t_bound; ctx->elastic = elastic; - for (int i=0; ispectrum_model[i] = gkyl_emission_spectrum_model_acquire(spectrum_model[i]); ctx->yield_model[i] = gkyl_emission_yield_model_acquire(yield_model[i]); strcpy(ctx->in_species[i], in_species[i]); } - if (elastic) ctx->elastic_model = gkyl_emission_elastic_model_acquire(elastic_model); + if (elastic) { + ctx->elastic_model = gkyl_emission_elastic_model_acquire(elastic_model); + } return ctx; } // SEE copper preset -struct gkyl_bc_emission_ctx* -gkyl_bc_emission_secondary_electron_copper_new(int num_species, double t_bound, - char in_species[][128], bool use_gpu) +struct gkyl_bc_emission_ctx *gkyl_bc_emission_secondary_electron_copper_new( + int num_species, double t_bound, char in_species[][128], bool use_gpu +) { struct gkyl_bc_emission_ctx *ctx = gkyl_malloc(sizeof(struct gkyl_bc_emission_ctx)); - + double q0 = 1.602e-19; double E_0 = 1.97; double tau = 0.88; @@ -52,25 +55,25 @@ gkyl_bc_emission_secondary_electron_copper_new(int num_species, double t_bound, ctx->t_bound = t_bound; ctx->elastic = true; - for (int i=0; ispectrum_model[i] = gkyl_emission_spectrum_gaussian_new(q0, E_0, tau, use_gpu); - ctx->yield_model[i] = gkyl_emission_yield_furman_pivi_new(q0, deltahat_ts, Ehat_ts, t1, t2, t3, - t4, s, use_gpu); + ctx->yield_model[i] = + gkyl_emission_yield_furman_pivi_new(q0, deltahat_ts, Ehat_ts, t1, t2, t3, t4, s, use_gpu); strcpy(ctx->in_species[i], in_species[i]); } - ctx->elastic_model = gkyl_emission_elastic_furman_pivi_new(q0, P1_inf, P1_hat, E_hat, - W, p, use_gpu); + ctx->elastic_model = + gkyl_emission_elastic_furman_pivi_new(q0, P1_inf, P1_hat, E_hat, W, p, use_gpu); return ctx; } // SEE oxidized lithium preset -struct gkyl_bc_emission_ctx* -gkyl_bc_emission_secondary_electron_lithium_oxidized_new(int num_species, double t_bound, - char in_species[][128], bool use_gpu) +struct gkyl_bc_emission_ctx *gkyl_bc_emission_secondary_electron_lithium_oxidized_new( + int num_species, double t_bound, char in_species[][128], bool use_gpu +) { struct gkyl_bc_emission_ctx *ctx = gkyl_malloc(sizeof(struct gkyl_bc_emission_ctx)); - + double q0 = 1.602e-19; double phi = 2.3; @@ -89,10 +92,10 @@ gkyl_bc_emission_secondary_electron_lithium_oxidized_new(int num_species, double ctx->t_bound = t_bound; ctx->elastic = true; - for (int i=0; ispectrum_model[i] = gkyl_emission_spectrum_chung_everhart_new(q0, phi, use_gpu); - ctx->yield_model[i] = gkyl_emission_yield_furman_pivi_new(q0, deltahat_ts, Ehat_ts, t1, t2, t3, - t4, s, use_gpu); + ctx->yield_model[i] = + gkyl_emission_yield_furman_pivi_new(q0, deltahat_ts, Ehat_ts, t1, t2, t3, t4, s, use_gpu); strcpy(ctx->in_species[i], in_species[i]); } ctx->elastic_model = gkyl_emission_elastic_cazaux_new(q0, E_f, phi_r, use_gpu); @@ -101,12 +104,12 @@ gkyl_bc_emission_secondary_electron_lithium_oxidized_new(int num_species, double } // SEE oxidized lithium preset -struct gkyl_bc_emission_ctx* -gkyl_bc_emission_secondary_electron_lithium_clean_new(int num_species, double t_bound, - char in_species[][128], bool use_gpu) +struct gkyl_bc_emission_ctx *gkyl_bc_emission_secondary_electron_lithium_clean_new( + int num_species, double t_bound, char in_species[][128], bool use_gpu +) { struct gkyl_bc_emission_ctx *ctx = gkyl_malloc(sizeof(struct gkyl_bc_emission_ctx)); - + double q0 = 1.602e-19; double phi = 2.3; @@ -122,10 +125,10 @@ gkyl_bc_emission_secondary_electron_lithium_clean_new(int num_species, double t_ ctx->t_bound = t_bound; ctx->elastic = false; - for (int i=0; ispectrum_model[i] = gkyl_emission_spectrum_chung_everhart_new(q0, phi, use_gpu); - ctx->yield_model[i] = gkyl_emission_yield_furman_pivi_new(q0, deltahat_ts, Ehat_ts, t1, t2, t3, - t4, s, use_gpu); + ctx->yield_model[i] = + gkyl_emission_yield_furman_pivi_new(q0, deltahat_ts, Ehat_ts, t1, t2, t3, t4, s, use_gpu); strcpy(ctx->in_species[i], in_species[i]); } @@ -133,28 +136,30 @@ gkyl_bc_emission_secondary_electron_lithium_clean_new(int num_species, double t_ } // Ion-impact SEE copper preset -struct gkyl_bc_emission_ctx* -gkyl_bc_emission_ion_impact_copper_new(int num_species, double t_bound, - char in_species[][128], bool use_gpu) +struct gkyl_bc_emission_ctx *gkyl_bc_emission_ion_impact_copper_new( + int num_species, double t_bound, char in_species[][128], bool use_gpu +) { struct gkyl_bc_emission_ctx *ctx = gkyl_malloc(sizeof(struct gkyl_bc_emission_ctx)); - + double q0 = 1.602e-19; double E_0 = 2.80670245635625; double tau = 1.21017574095341; - double A2 = 4.194; // a2-5 are empirical fits for ion stopping power - double A3 = 4.649e3; // Starting at a2 to match source and prevent confusion + double A2 = 4.194; // a2-5 are empirical fits for ion stopping power + double A3 = 4.649e3; // Starting at a2 to match source and prevent confusion double A4 = 8.113e1; double A5 = 2.242e-2; - double nw = 8.491231742083982e28; // Number density of the wall material (m^-3). Calculated a priori using rho/m/u where rho is density in kg/m^3, m is mass in amu, and u is the unified atomic mass unit - double int_wall = 6.33665090954913e7; // Integration of wall term (J/m). See the paper for more info on this. + double nw = + 8.491231742083982e28; // Number density of the wall material (m^-3). Calculated a priori using rho/m/u where rho is density in kg/m^3, m is mass in amu, and u is the unified atomic mass unit + double int_wall = + 6.33665090954913e7; // Integration of wall term (J/m). See the paper for more info on this. ctx->num_species = num_species; ctx->t_bound = t_bound; ctx->elastic = false; - for (int i=0; ispectrum_model[i] = gkyl_emission_spectrum_gaussian_new(q0, E_0, tau, use_gpu); ctx->yield_model[i] = gkyl_emission_yield_schou_new(q0, int_wall, A2, A3, A4, A5, nw, use_gpu); strcpy(ctx->in_species[i], in_species[i]); @@ -165,11 +170,13 @@ gkyl_bc_emission_ion_impact_copper_new(int num_species, double t_bound, void gkyl_bc_emission_release(struct gkyl_bc_emission_ctx *ctx) { - for (int i=0; inum_species; ++i) { + for (int i = 0; i < ctx->num_species; ++i) { gkyl_emission_spectrum_model_release(ctx->spectrum_model[i]); gkyl_emission_yield_model_release(ctx->yield_model[i]); } - if (ctx->elastic) gkyl_emission_elastic_model_release(ctx->elastic_model); + if (ctx->elastic) { + gkyl_emission_elastic_model_release(ctx->elastic_model); + } // Release ctx memory. gkyl_free(ctx); } diff --git a/vlasov/zero/bc_emission_elastic.c b/vlasov/zero/bc_emission_elastic.c index e9b564616c..9bb2972581 100644 --- a/vlasov/zero/bc_emission_elastic.c +++ b/vlasov/zero/bc_emission_elastic.c @@ -8,13 +8,14 @@ #include #include -struct gkyl_array_copy_func* -gkyl_bc_emission_elastic_create_arr_copy_func(int dir, int cdim, const struct gkyl_basis *basis, - int ncomp, bool use_gpu) +struct gkyl_array_copy_func *gkyl_bc_emission_elastic_create_arr_copy_func( + int dir, int cdim, const struct gkyl_basis *basis, int ncomp, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) + if (use_gpu) { return gkyl_bc_emission_elastic_create_arr_copy_func_cu(dir, cdim, basis, ncomp); + } #endif struct bc_elastic_ctx *ctx = gkyl_malloc(sizeof(*ctx)); @@ -34,12 +35,12 @@ gkyl_bc_emission_elastic_create_arr_copy_func(int dir, int cdim, const struct gk return fout; } -struct gkyl_bc_emission_elastic* -gkyl_bc_emission_elastic_new(struct gkyl_emission_elastic_model *elastic_model, - struct gkyl_array *elastic_yield, int dir, enum gkyl_edge_loc edge, int cdim, - int vdim, double mass, int ncomp, struct gkyl_rect_grid *grid, struct gkyl_range *emit_buff_r, - int poly_order, const struct gkyl_basis *dev_basis, struct gkyl_basis *basis, - struct gkyl_array *proj_buffer, bool use_gpu) +struct gkyl_bc_emission_elastic *gkyl_bc_emission_elastic_new( + struct gkyl_emission_elastic_model *elastic_model, struct gkyl_array *elastic_yield, int dir, + enum gkyl_edge_loc edge, int cdim, int vdim, double mass, int ncomp, struct gkyl_rect_grid *grid, + struct gkyl_range *emit_buff_r, int poly_order, const struct gkyl_basis *dev_basis, + struct gkyl_basis *basis, struct gkyl_array *proj_buffer, bool use_gpu +) { // Allocate space for new updater. struct gkyl_bc_emission_elastic *up = gkyl_malloc(sizeof(struct gkyl_bc_emission_elastic)); @@ -53,22 +54,22 @@ gkyl_bc_emission_elastic_new(struct gkyl_emission_elastic_model *elastic_model, // Need to pass on_dev basis to create_arr_copy_func, but host copy to proj_on_basis. // These are stored separately by the app, so new function takes both dev_basis and basis // as arguments. - up->reflect_func = gkyl_bc_emission_elastic_create_arr_copy_func(dir, cdim, dev_basis, ncomp, - use_gpu); + up->reflect_func = + gkyl_bc_emission_elastic_create_arr_copy_func(dir, cdim, dev_basis, ncomp, use_gpu); - up->elastic_model = gkyl_emission_elastic_model_acquire(elastic_model); up->elastic_model->cdim = cdim; up->elastic_model->vdim = vdim; up->elastic_model->mass = mass; - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(grid, basis, poly_order + 1, 1, - up->elastic_model->function, up->elastic_model); + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + grid, basis, poly_order + 1, 1, up->elastic_model->function, up->elastic_model + ); #ifdef GKYL_HAVE_CUDA if (use_gpu) { gkyl_proj_on_basis_advance(proj, 0.0, emit_buff_r, proj_buffer); - + gkyl_array_copy(elastic_yield, proj_buffer); } else { gkyl_proj_on_basis_advance(proj, 0.0, emit_buff_r, elastic_yield); @@ -81,22 +82,25 @@ gkyl_bc_emission_elastic_new(struct gkyl_emission_elastic_model *elastic_model, return up; } -static inline void -copy_idx_arrays(int cdim, int pdim, const int *cidx, const int *vidx, int *out) +static inline void copy_idx_arrays(int cdim, int pdim, const int *cidx, const int *vidx, int *out) { - for (int i=0; idata, f_skin, up->dir+up->cdim, emit_skin_r, - up->reflect_func->on_dev); + gkyl_array_flip_copy_to_buffer_fn( + buff_arr->data, f_skin, up->dir + up->cdim, emit_skin_r, up->reflect_func->on_dev + ); // Basis is passed directly instead of by pointer for bin op, so advance uses host copy. gkyl_dg_mul_op(basis, 0, f_emit, 0, buff_arr, 0, elastic_yield); } diff --git a/vlasov/zero/bc_emission_elastic_cu.cu b/vlasov/zero/bc_emission_elastic_cu.cu index 98611e0af9..604cf175d0 100644 --- a/vlasov/zero/bc_emission_elastic_cu.cu +++ b/vlasov/zero/bc_emission_elastic_cu.cu @@ -8,18 +8,19 @@ extern "C" { #include } -__global__ static void -gkyl_bc_emission_elastic_set_extern_params_cu_ker(struct gkyl_emission_elastic_model *elastic_model, - int cdim, int vdim, double mass) +__global__ static void gkyl_bc_emission_elastic_set_extern_params_cu_ker( + struct gkyl_emission_elastic_model *elastic_model, int cdim, int vdim, double mass +) { elastic_model->cdim = cdim; elastic_model->vdim = vdim; elastic_model->mass = mass; } -__global__ static void -gkyl_bc_emission_elastic_create_set_cu_dev_ptrs(int dir, int cdim, const struct gkyl_basis* basis, - int ncomp, struct bc_elastic_ctx *ctx, struct gkyl_array_copy_func *fout) +__global__ static void gkyl_bc_emission_elastic_create_set_cu_dev_ptrs( + int dir, int cdim, const struct gkyl_basis *basis, int ncomp, struct bc_elastic_ctx *ctx, + struct gkyl_array_copy_func *fout +) { ctx->dir = dir; ctx->cdim = cdim; @@ -30,38 +31,40 @@ gkyl_bc_emission_elastic_create_set_cu_dev_ptrs(int dir, int cdim, const struct fout->ctx = ctx; } -void -gkyl_bc_emission_elastic_set_extern_params_cu(const struct gkyl_bc_emission_elastic *up, - int cdim, int vdim, double mass) +void gkyl_bc_emission_elastic_set_extern_params_cu( + const struct gkyl_bc_emission_elastic *up, int cdim, int vdim, double mass +) { - gkyl_bc_emission_elastic_set_extern_params_cu_ker<<<1, 1>>>(up->elastic_model->on_dev, - cdim, vdim, mass); + gkyl_bc_emission_elastic_set_extern_params_cu_ker<<<1, 1> > >( + up->elastic_model->on_dev, cdim, vdim, mass + ); } -struct gkyl_array_copy_func* -gkyl_bc_emission_elastic_create_arr_copy_func_cu(int dir, int cdim, const struct gkyl_basis *basis, - int ncomp) +struct gkyl_array_copy_func *gkyl_bc_emission_elastic_create_arr_copy_func_cu( + int dir, int cdim, const struct gkyl_basis *basis, int ncomp +) { - struct bc_elastic_ctx *ctx = (struct bc_elastic_ctx*) gkyl_malloc(sizeof(struct bc_elastic_ctx)); - struct gkyl_array_copy_func *fout = (struct gkyl_array_copy_func*) - gkyl_malloc(sizeof(struct gkyl_array_copy_func)); + struct bc_elastic_ctx *ctx = (struct bc_elastic_ctx *)gkyl_malloc(sizeof(struct bc_elastic_ctx)); + struct gkyl_array_copy_func *fout = + (struct gkyl_array_copy_func *)gkyl_malloc(sizeof(struct gkyl_array_copy_func)); fout->ctx = ctx; - + fout->flags = 0; GKYL_SET_CU_ALLOC(fout->flags); - - struct bc_elastic_ctx *ctx_cu = (struct bc_elastic_ctx*) - gkyl_cu_malloc(sizeof(struct bc_elastic_ctx)); - struct gkyl_array_copy_func *fout_cu = (struct gkyl_array_copy_func*) - gkyl_cu_malloc(sizeof(struct gkyl_array_copy_func)); + + struct bc_elastic_ctx *ctx_cu = + (struct bc_elastic_ctx *)gkyl_cu_malloc(sizeof(struct bc_elastic_ctx)); + struct gkyl_array_copy_func *fout_cu = + (struct gkyl_array_copy_func *)gkyl_cu_malloc(sizeof(struct gkyl_array_copy_func)); gkyl_cu_memcpy(ctx_cu, ctx, sizeof(struct bc_elastic_ctx), GKYL_CU_MEMCPY_H2D); gkyl_cu_memcpy(fout_cu, fout, sizeof(struct gkyl_array_copy_func), GKYL_CU_MEMCPY_H2D); fout->ctx_on_dev = ctx_cu; - gkyl_bc_emission_elastic_create_set_cu_dev_ptrs<<<1,1>>>(dir, cdim, basis, ncomp, ctx_cu, - fout_cu); + gkyl_bc_emission_elastic_create_set_cu_dev_ptrs<<<1, 1> > >( + dir, cdim, basis, ncomp, ctx_cu, fout_cu + ); fout->on_dev = fout_cu; return fout; diff --git a/vlasov/zero/bc_emission_spectrum.c b/vlasov/zero/bc_emission_spectrum.c index a2c1d38e9b..c5883fd6ca 100644 --- a/vlasov/zero/bc_emission_spectrum.c +++ b/vlasov/zero/bc_emission_spectrum.c @@ -7,46 +7,50 @@ #include // Increment an int vector by fact*del[d] in each direction d. -static inline void -incr_int_array(int ndim, int fact, const int * GKYL_RESTRICT del, - const int * GKYL_RESTRICT inp, int *GKYL_RESTRICT out) +static inline void incr_int_array( + int ndim, int fact, const int *GKYL_RESTRICT del, const int *GKYL_RESTRICT inp, + int *GKYL_RESTRICT out +) { - for (int i=0; indim; int lo[GKYL_MAX_DIM] = {0}, up[GKYL_MAX_DIM] = {0}; - + if (edge == GKYL_LOWER_EDGE) { incr_int_array(ndim, 0, nghost, parent->lower, lo); incr_int_array(ndim, 0, nghost, parent->upper, up); - int nneg = (up[dir] - lo[dir] + 1)/2; - + int nneg = (up[dir] - lo[dir] + 1) / 2; + up[dir] = lo[dir] + nneg; gkyl_sub_range_init(flux_r, parent, lo, up); } else { incr_int_array(ndim, 0, nghost, parent->lower, lo); incr_int_array(ndim, 0, nghost, parent->upper, up); - int npos = (up[dir] - lo[dir] + 1)/2; - + int npos = (up[dir] - lo[dir] + 1) / 2; + lo[dir] = up[dir] - npos; gkyl_sub_range_init(flux_r, parent, lo, up); } } -void -gkyl_bc_emission_spectrum_sey_calc(const struct gkyl_bc_emission_spectrum *up, - struct gkyl_array *yield, struct gkyl_rect_grid *grid, const struct gkyl_range *impact_buff_r) +void gkyl_bc_emission_spectrum_sey_calc( + const struct gkyl_bc_emission_spectrum *up, struct gkyl_array *yield, struct gkyl_rect_grid *grid, + const struct gkyl_range *impact_buff_r +) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { @@ -55,7 +59,7 @@ gkyl_bc_emission_spectrum_sey_calc(const struct gkyl_bc_emission_spectrum *up, } #endif double xc[GKYL_MAX_DIM]; - + struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, impact_buff_r); while (gkyl_range_iter_next(&iter)) { @@ -66,13 +70,14 @@ gkyl_bc_emission_spectrum_sey_calc(const struct gkyl_bc_emission_spectrum *up, } } -struct gkyl_bc_emission_spectrum* -gkyl_bc_emission_spectrum_new(struct gkyl_emission_spectrum_model *spectrum_model, +struct gkyl_bc_emission_spectrum *gkyl_bc_emission_spectrum_new( + struct gkyl_emission_spectrum_model *spectrum_model, struct gkyl_emission_yield_model *yield_model, struct gkyl_array *yield, - struct gkyl_array *spectrum, int dir, enum gkyl_edge_loc edge, int cdim, int vdim, - double mass_in, double mass_out, struct gkyl_range *impact_buff_r, struct gkyl_range *emit_buff_r, + struct gkyl_array *spectrum, int dir, enum gkyl_edge_loc edge, int cdim, int vdim, double mass_in, + double mass_out, struct gkyl_range *impact_buff_r, struct gkyl_range *emit_buff_r, struct gkyl_rect_grid *impact_grid, struct gkyl_rect_grid *emit_grid, int poly_order, - struct gkyl_basis *basis, struct gkyl_array *proj_buffer, bool use_gpu) + struct gkyl_basis *basis, struct gkyl_array *proj_buffer, bool use_gpu +) { // Allocate space for new updater. struct gkyl_bc_emission_spectrum *up = gkyl_malloc(sizeof(struct gkyl_bc_emission_spectrum)); @@ -85,11 +90,11 @@ gkyl_bc_emission_spectrum_new(struct gkyl_emission_spectrum_model *spectrum_mode up->grid = impact_grid; int ghost[GKYL_MAX_DIM]; - for (int d=0; dspectrum_model = gkyl_emission_spectrum_model_acquire(spectrum_model); @@ -101,14 +106,15 @@ gkyl_bc_emission_spectrum_new(struct gkyl_emission_spectrum_model *spectrum_mode up->yield_model->vdim = vdim; up->yield_model->mass = mass_in; - gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new(emit_grid, basis, poly_order + 1, 1, - up->spectrum_model->distribution, up->spectrum_model); + gkyl_proj_on_basis *proj = gkyl_proj_on_basis_new( + emit_grid, basis, poly_order + 1, 1, up->spectrum_model->distribution, up->spectrum_model + ); #ifdef GKYL_HAVE_CUDA if (use_gpu) { gkyl_bc_emission_spectrum_set_extern_params_cu(up, cdim, vdim, mass_in, mass_out); gkyl_proj_on_basis_advance(proj, 0.0, emit_buff_r, proj_buffer); - + gkyl_array_copy(spectrum, proj_buffer); } else { gkyl_proj_on_basis_advance(proj, 0.0, emit_buff_r, spectrum); @@ -118,35 +124,40 @@ gkyl_bc_emission_spectrum_new(struct gkyl_emission_spectrum_model *spectrum_mode #endif gkyl_bc_emission_spectrum_sey_calc(up, yield, impact_grid, impact_buff_r); gkyl_proj_on_basis_release(proj); - + return up; } -static inline void -copy_idx_arrays(int cdim, int pdim, const int *cidx, const int *vidx, int *out) +static inline void copy_idx_arrays(int cdim, int pdim, const int *cidx, const int *vidx, int *out) { - for (int i=0; iuse_gpu) { - return gkyl_bc_emission_spectrum_advance_cu(up, impact_buff_r, impact_cbuff_r, emit_buff_r, - bflux, f_emit, yield, spectrum, weight, flux, k); + return gkyl_bc_emission_spectrum_advance_cu( + up, impact_buff_r, impact_cbuff_r, emit_buff_r, bflux, f_emit, yield, spectrum, weight, flux, + k + ); } #endif double xc[GKYL_MAX_DIM]; - int pidx[GKYL_MAX_DIM], rem_dir[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim; ++d) rem_dir[d] = 1; + int pidx[GKYL_MAX_DIM], rem_dir[GKYL_MAX_DIM] = {0}; + for (int d = 0; d < impact_cbuff_r->ndim; ++d) { + rem_dir[d] = 1; + } struct gkyl_range vel_buff_r; struct gkyl_range_iter conf_iter, vel_iter; @@ -161,22 +172,22 @@ gkyl_bc_emission_spectrum_advance(const struct gkyl_bc_emission_spectrum *up, gkyl_range_iter_no_split_init(&vel_iter, &vel_buff_r); double *w = gkyl_array_fetch(weight, midx); - + while (gkyl_range_iter_next(&vel_iter)) { copy_idx_arrays(impact_cbuff_r->ndim, impact_buff_r->ndim, conf_iter.idx, vel_iter.idx, pidx); gkyl_rect_grid_cell_center(up->grid, pidx, xc); - + long loc = gkyl_range_idx(&vel_buff_r, vel_iter.idx); - + const double *inp = gkyl_array_cfetch(bflux, loc); const double *gain = gkyl_array_cfetch(yield, loc); - + bc_weighted_delta(inp, up->cdim, up->dir, up->edge, xc, gain, w); } - double effective_delta = w[0]/w[1]; + double effective_delta = w[0] / w[1]; const double *boundary_flux = gkyl_array_cfetch(flux, midx); double *out = gkyl_array_fetch(k, midx); - + up->spectrum_model->normalization(out, up->spectrum_model, boundary_flux, effective_delta); gkyl_array_accumulate(f_emit, out[0], spectrum); } diff --git a/vlasov/zero/bc_emission_spectrum_cu.cu b/vlasov/zero/bc_emission_spectrum_cu.cu index ef94eec989..96f5758436 100644 --- a/vlasov/zero/bc_emission_spectrum_cu.cu +++ b/vlasov/zero/bc_emission_spectrum_cu.cu @@ -7,11 +7,12 @@ extern "C" { } // start ID for use in various loops -#define START_ID (threadIdx.x + blockIdx.x*blockDim.x) +#define START_ID (threadIdx.x + blockIdx.x * blockDim.x) -__global__ static void -gkyl_bc_emission_spectrum_set_exterm_params_cu_ker(struct gkyl_emission_spectrum_model *spectrum_model, - struct gkyl_emission_yield_model *yield_model, int cdim, int vdim, double mass_in, double mass_out) +__global__ static void gkyl_bc_emission_spectrum_set_exterm_params_cu_ker( + struct gkyl_emission_spectrum_model *spectrum_model, + struct gkyl_emission_yield_model *yield_model, int cdim, int vdim, double mass_in, double mass_out +) { spectrum_model->cdim = cdim; spectrum_model->vdim = vdim; @@ -22,140 +23,143 @@ gkyl_bc_emission_spectrum_set_exterm_params_cu_ker(struct gkyl_emission_spectrum yield_model->mass = mass_in; } -__global__ static void -gkyl_bc_emission_spectrum_sey_calc_cu_ker(struct gkyl_rect_grid grid, - const struct gkyl_range ghost_r, struct gkyl_array *yield, - struct gkyl_emission_yield_model *yield_model) +__global__ static void gkyl_bc_emission_spectrum_sey_calc_cu_ker( + struct gkyl_rect_grid grid, const struct gkyl_range ghost_r, struct gkyl_array *yield, + struct gkyl_emission_yield_model *yield_model +) { - double xc[GKYL_MAX_DIM]; int pidx[GKYL_MAX_DIM]; - for(unsigned long linc = threadIdx.x + blockIdx.x*blockDim.x; - linc < ghost_r.volume; linc += blockDim.x*gridDim.x) { - + for (unsigned long linc = threadIdx.x + blockIdx.x * blockDim.x; linc < ghost_r.volume; + linc += blockDim.x * gridDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange gkyl_sub_range_inv_idx(&ghost_r, linc, pidx); - + long loc = gkyl_range_idx(&ghost_r, pidx); - double *out = (double *) gkyl_array_fetch(yield, loc); + double *out = (double *)gkyl_array_fetch(yield, loc); gkyl_rect_grid_cell_center(&grid, pidx, xc); yield_model->function(out, yield_model, xc); } } -__global__ static void -gkyl_bc_emission_spectrum_advance_cu_weight_ker(int cdim, int dir, enum gkyl_edge_loc edge, - const struct gkyl_array *bflux, struct gkyl_array *weight, struct gkyl_rect_grid grid, - struct gkyl_array *yield, const struct gkyl_range impact_buff_r, - const struct gkyl_range impact_cbuff_r) +__global__ static void gkyl_bc_emission_spectrum_advance_cu_weight_ker( + int cdim, int dir, enum gkyl_edge_loc edge, const struct gkyl_array *bflux, + struct gkyl_array *weight, struct gkyl_rect_grid grid, struct gkyl_array *yield, + const struct gkyl_range impact_buff_r, const struct gkyl_range impact_cbuff_r +) { double xc[GKYL_MAX_DIM]; int pidx[GKYL_MAX_DIM], cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < impact_buff_r.volume; tid += blockDim.x*gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < impact_buff_r.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&impact_buff_r, tid, pidx); - + gkyl_rect_grid_cell_center(&grid, pidx, xc); long lincP = gkyl_range_idx(&impact_buff_r, pidx); - - const double* inp = (const double*) gkyl_array_cfetch(bflux, lincP); - const double* gain = (const double*) gkyl_array_cfetch(yield, lincP); + + const double *inp = (const double *)gkyl_array_cfetch(bflux, lincP); + const double *gain = (const double *)gkyl_array_cfetch(yield, lincP); double wLocal[2]; - for (unsigned int k=0; kncomp; ++k) + for (unsigned int k = 0; k < weight->ncomp; ++k) { wLocal[k] = 0.0; + } bc_weighted_delta(inp, cdim, dir, edge, xc, gain, &wLocal[0]); - + // get conf-space linear index. - for (unsigned int i = 0; i < impact_cbuff_r.ndim; i++) + for (unsigned int i = 0; i < impact_cbuff_r.ndim; i++) { cidx[i] = pidx[i]; + } long lincC = gkyl_range_idx(&impact_cbuff_r, cidx); - double* wptr = (double*) gkyl_array_fetch(weight, lincC); + double *wptr = (double *)gkyl_array_fetch(weight, lincC); for (unsigned int k = 0; k < weight->ncomp; ++k) { - atomicAdd(&wptr[k], wLocal[k]); + atomicAdd(&wptr[k], wLocal[k]); } } } -__global__ static void -gkyl_bc_emission_spectrum_advance_cu_accumulate_ker(const struct gkyl_array *spectrum, - struct gkyl_array *f_emit, struct gkyl_array *weight, struct gkyl_array *k, - const struct gkyl_array *flux, const struct gkyl_range emit_buff_r, - const struct gkyl_range impact_cbuff_r, struct gkyl_emission_spectrum_model *spectrum_model) +__global__ static void gkyl_bc_emission_spectrum_advance_cu_accumulate_ker( + const struct gkyl_array *spectrum, struct gkyl_array *f_emit, struct gkyl_array *weight, + struct gkyl_array *k, const struct gkyl_array *flux, const struct gkyl_range emit_buff_r, + const struct gkyl_range impact_cbuff_r, struct gkyl_emission_spectrum_model *spectrum_model +) { int pidx[GKYL_MAX_DIM], cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < emit_buff_r.volume; tid += blockDim.x*gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < emit_buff_r.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&emit_buff_r, tid, pidx); - + // get conf-space linear index. - for (unsigned int i = 0; i < impact_cbuff_r.ndim; i++) + for (unsigned int i = 0; i < impact_cbuff_r.ndim; i++) { cidx[i] = pidx[i]; + } long lincC = gkyl_range_idx(&impact_cbuff_r, cidx); long lincP = gkyl_range_idx(&emit_buff_r, pidx); - - const double* inp = (const double*) gkyl_array_cfetch(spectrum, lincP); - const double* w = (const double*) gkyl_array_cfetch(weight, lincC); - const double* boundary_flux = (const double*) gkyl_array_cfetch(flux, lincC); - double* fac = (double*) gkyl_array_fetch(k, lincC); - double* out = (double*) gkyl_array_fetch(f_emit, lincP); - double effective_delta = w[0]/w[1]; - spectrum_model->normalization(fac, spectrum_model, boundary_flux, effective_delta); - for (int c=0; cncomp; ++c) - out[c] += fac[0]*inp[c]; + const double *inp = (const double *)gkyl_array_cfetch(spectrum, lincP); + const double *w = (const double *)gkyl_array_cfetch(weight, lincC); + const double *boundary_flux = (const double *)gkyl_array_cfetch(flux, lincC); + double *fac = (double *)gkyl_array_fetch(k, lincC); + double *out = (double *)gkyl_array_fetch(f_emit, lincP); + double effective_delta = w[0] / w[1]; + spectrum_model->normalization(fac, spectrum_model, boundary_flux, effective_delta); + for (int c = 0; c < spectrum->ncomp; ++c) { + out[c] += fac[0] * inp[c]; + } } } -void -gkyl_bc_emission_spectrum_set_extern_params_cu(const struct gkyl_bc_emission_spectrum *up, - int cdim, int vdim, double mass_in, double mass_out) +void gkyl_bc_emission_spectrum_set_extern_params_cu( + const struct gkyl_bc_emission_spectrum *up, int cdim, int vdim, double mass_in, double mass_out +) { - gkyl_bc_emission_spectrum_set_exterm_params_cu_ker<<<1, 1>>>(up->spectrum_model->on_dev, - up->yield_model->on_dev, cdim, vdim, mass_in, mass_out); + gkyl_bc_emission_spectrum_set_exterm_params_cu_ker<<<1, 1> > >( + up->spectrum_model->on_dev, up->yield_model->on_dev, cdim, vdim, mass_in, mass_out + ); } -void -gkyl_bc_emission_spectrum_sey_calc_cu(const struct gkyl_bc_emission_spectrum *up, - struct gkyl_array *yield, struct gkyl_rect_grid *grid, const struct gkyl_range *impact_buff_r) +void gkyl_bc_emission_spectrum_sey_calc_cu( + const struct gkyl_bc_emission_spectrum *up, struct gkyl_array *yield, struct gkyl_rect_grid *grid, + const struct gkyl_range *impact_buff_r +) { int nblocks = impact_buff_r->nblocks, nthreads = impact_buff_r->nthreads; - gkyl_bc_emission_spectrum_sey_calc_cu_ker<<>>(*grid, - *impact_buff_r, yield->on_dev, up->yield_model->on_dev); + gkyl_bc_emission_spectrum_sey_calc_cu_ker<< > >( + *grid, *impact_buff_r, yield->on_dev, up->yield_model->on_dev + ); } -void -gkyl_bc_emission_spectrum_advance_cu(const struct gkyl_bc_emission_spectrum *up, - struct gkyl_range *impact_buff_r, struct gkyl_range *impact_cbuff_r, - struct gkyl_range *emit_buff_r, struct gkyl_array *bflux, struct gkyl_array *f_emit, - struct gkyl_array *yield, struct gkyl_array *spectrum, struct gkyl_array *weight, - struct gkyl_array *flux, struct gkyl_array *k) +void gkyl_bc_emission_spectrum_advance_cu( + const struct gkyl_bc_emission_spectrum *up, struct gkyl_range *impact_buff_r, + struct gkyl_range *impact_cbuff_r, struct gkyl_range *emit_buff_r, struct gkyl_array *bflux, + struct gkyl_array *f_emit, struct gkyl_array *yield, struct gkyl_array *spectrum, + struct gkyl_array *weight, struct gkyl_array *flux, struct gkyl_array *k +) { int nblocks = impact_buff_r->nblocks, nthreads = impact_buff_r->nthreads; // Calculate weighted mean numerator and denominator - gkyl_bc_emission_spectrum_advance_cu_weight_ker<<>>(up->cdim, up->dir, - up->edge, bflux->on_dev, weight->on_dev, *up->grid, yield->on_dev, *impact_buff_r, - *impact_cbuff_r); + gkyl_bc_emission_spectrum_advance_cu_weight_ker<< > >( + up->cdim, up->dir, up->edge, bflux->on_dev, weight->on_dev, *up->grid, yield->on_dev, + *impact_buff_r, *impact_cbuff_r + ); nblocks = emit_buff_r->nblocks; nthreads = emit_buff_r->nthreads; // Finish weighted mean calculation and accumulate to buffer - gkyl_bc_emission_spectrum_advance_cu_accumulate_ker<<>>(spectrum->on_dev, - f_emit->on_dev, weight->on_dev, k->on_dev, flux->on_dev, *emit_buff_r, *impact_cbuff_r, - up->spectrum_model->on_dev); + gkyl_bc_emission_spectrum_advance_cu_accumulate_ker<< > >( + spectrum->on_dev, f_emit->on_dev, weight->on_dev, k->on_dev, flux->on_dev, *emit_buff_r, + *impact_cbuff_r, up->spectrum_model->on_dev + ); } - diff --git a/vlasov/zero/bgk_collisions.c b/vlasov/zero/bgk_collisions.c index 9ac293176b..f8ad88b09c 100644 --- a/vlasov/zero/bgk_collisions.c +++ b/vlasov/zero/bgk_collisions.c @@ -6,14 +6,14 @@ #include #include -gkyl_bgk_collisions* -gkyl_bgk_collisions_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - bool use_gpu) +gkyl_bgk_collisions *gkyl_bgk_collisions_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, bool use_gpu +) { gkyl_bgk_collisions *up = gkyl_malloc(sizeof(gkyl_bgk_collisions)); up->cdim = cbasis->ndim; - up->vdim = pbasis->ndim-up->cdim; + up->vdim = pbasis->ndim - up->cdim; up->cnum_basis = cbasis->num_basis; up->pnum_basis = pbasis->num_basis; up->poly_order = cbasis->poly_order; @@ -23,32 +23,35 @@ gkyl_bgk_collisions_new(const struct gkyl_basis *cbasis, const struct gkyl_basis int poly_order = cbasis->poly_order; up->pb_type = pbasis->b_type; - if (!up->use_gpu) + if (!up->use_gpu) { up->mul_op = choose_mul_conf_phase_kern(up->pb_type, up->cdim, up->vdim, poly_order); + } - up->cellav_fac = 1./sqrt(pow(2,up->cdim)); + up->cellav_fac = 1. / sqrt(pow(2, up->cdim)); return up; } -void -gkyl_bgk_collisions_advance(const gkyl_bgk_collisions *up, - const struct gkyl_range *crange, const struct gkyl_range *prange, +void gkyl_bgk_collisions_advance( + const gkyl_bgk_collisions *up, const struct gkyl_range *crange, const struct gkyl_range *prange, const struct gkyl_array *nu, const struct gkyl_array *nufM, const struct gkyl_array *fin, - bool implicit_step, double dt, struct gkyl_array *out, struct gkyl_array *cflfreq) + bool implicit_step, double dt, struct gkyl_array *out, struct gkyl_array *cflfreq +) { // Compute nu*f_M - nu*f, and its contribution to the CFL rate. #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) - return gkyl_bgk_collisions_advance_cu(up, crange, prange, nu, nufM, fin, implicit_step, dt, out, cflfreq); + if (up->use_gpu) { + return gkyl_bgk_collisions_advance_cu( + up, crange, prange, nu, nufM, fin, implicit_step, dt, out, cflfreq + ); + } #endif struct gkyl_range_iter piter; gkyl_range_iter_init(&piter, prange); if (implicit_step) { - - const double cellav_fac_dt = up->cellav_fac*dt; + const double cellav_fac_dt = up->cellav_fac * dt; while (gkyl_range_iter_next(&piter)) { long ploc = gkyl_range_idx(prange, piter.idx); @@ -58,44 +61,42 @@ gkyl_bgk_collisions_advance(const gkyl_bgk_collisions *up, double *out_d = gkyl_array_fetch(out, ploc); // Add nu*f_M. - array_acc1(up->pnum_basis, out_d, 1./(1.0 + nu_d[0]*cellav_fac_dt), gkyl_array_cfetch(nufM, ploc)); + array_acc1( + up->pnum_basis, out_d, 1. / (1.0 + nu_d[0] * cellav_fac_dt), gkyl_array_cfetch(nufM, ploc) + ); // Calculate and add -nu*f. double incr[160]; // mul_op assigns, but need increment, so use a buffer. up->mul_op(nu_d, gkyl_array_cfetch(fin, ploc), incr); - array_acc1(up->pnum_basis, out_d, -1.0/(1.0 + nu_d[0]*cellav_fac_dt), incr); + array_acc1(up->pnum_basis, out_d, -1.0 / (1.0 + nu_d[0] * cellav_fac_dt), incr); // No CFL contribution in the implicit case. } - } - else { - + } else { while (gkyl_range_iter_next(&piter)) { long ploc = gkyl_range_idx(prange, piter.idx); long cloc = gkyl_range_idx(crange, piter.idx); - + const double *nu_d = gkyl_array_cfetch(nu, cloc); double *out_d = gkyl_array_fetch(out, ploc); - + // Add nu*f_M. array_acc1(up->pnum_basis, out_d, 1., gkyl_array_cfetch(nufM, ploc)); - + // Calculate and add -nu*f. double incr[160]; // mul_op assigns, but need increment, so use a buffer. up->mul_op(nu_d, gkyl_array_cfetch(fin, ploc), incr); array_acc1(up->pnum_basis, out_d, -1., incr); - + // Add contribution to CFL frequency. double *cflfreq_d = gkyl_array_fetch(cflfreq, ploc); - cflfreq_d[0] += nu_d[0]*up->cellav_fac; + cflfreq_d[0] += nu_d[0] * up->cellav_fac; } - } } -void -gkyl_bgk_collisions_release(gkyl_bgk_collisions* up) +void gkyl_bgk_collisions_release(gkyl_bgk_collisions *up) { gkyl_free(up); } diff --git a/vlasov/zero/bgk_collisions_cu.cu b/vlasov/zero/bgk_collisions_cu.cu index 3a570e4d8d..9002c66e44 100644 --- a/vlasov/zero/bgk_collisions_cu.cu +++ b/vlasov/zero/bgk_collisions_cu.cu @@ -9,21 +9,20 @@ extern "C" { #include } -__global__ void -gkyl_bgk_collisions_advance_cu_kernel(unsigned cdim, unsigned vdim, unsigned poly_order, - unsigned pnum_basis, enum gkyl_basis_type b_type, double cellav_fac, - struct gkyl_range crange, struct gkyl_range prange, - const struct gkyl_array* nu, const struct gkyl_array* nufM, const struct gkyl_array* fin, - bool implicit_step, double dt, struct gkyl_array* out, struct gkyl_array* cflfreq) +__global__ void gkyl_bgk_collisions_advance_cu_kernel( + unsigned cdim, unsigned vdim, unsigned poly_order, unsigned pnum_basis, + enum gkyl_basis_type b_type, double cellav_fac, struct gkyl_range crange, + struct gkyl_range prange, const struct gkyl_array *nu, const struct gkyl_array *nufM, + const struct gkyl_array *fin, bool implicit_step, double dt, struct gkyl_array *out, + struct gkyl_array *cflfreq +) { mul_op_t mul_op = choose_mul_conf_phase_kern(b_type, cdim, vdim, poly_order); int pidx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < prange.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < prange.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -34,26 +33,24 @@ gkyl_bgk_collisions_advance_cu_kernel(unsigned cdim, unsigned vdim, unsigned pol long pstart = gkyl_range_idx(&prange, pidx); long cstart = gkyl_range_idx(&crange, pidx); - const double *nufM_d = (const double*) gkyl_array_cfetch(nufM, pstart); - const double *fin_d = (const double*) gkyl_array_cfetch(fin, pstart); - double *out_d = (double*) gkyl_array_fetch(out, pstart); + const double *nufM_d = (const double *)gkyl_array_cfetch(nufM, pstart); + const double *fin_d = (const double *)gkyl_array_cfetch(fin, pstart); + double *out_d = (double *)gkyl_array_fetch(out, pstart); - const double *nu_d = (const double*) gkyl_array_cfetch(nu, cstart); + const double *nu_d = (const double *)gkyl_array_cfetch(nu, cstart); // Add contribution to CFL frequency. if (implicit_step) { - // Add nu*f_M. - array_acc1(pnum_basis, out_d, 1.0/(1.0 + nu_d[0]*cellav_fac*dt), nufM_d); + array_acc1(pnum_basis, out_d, 1.0 / (1.0 + nu_d[0] * cellav_fac * dt), nufM_d); // Calculate and add -nu*f. double incr[160]; // mul_op assigns, but need increment, so use a buffer. mul_op(nu_d, fin_d, incr); - array_acc1(pnum_basis, out_d, -1.0/(1.0 + nu_d[0]*cellav_fac*dt), incr); + array_acc1(pnum_basis, out_d, -1.0 / (1.0 + nu_d[0] * cellav_fac * dt), incr); // No CFL contribution in the implicit case - } - else { + } else { // Add nu*f_M. array_acc1(pnum_basis, out_d, 1., nufM_d); @@ -63,21 +60,22 @@ gkyl_bgk_collisions_advance_cu_kernel(unsigned cdim, unsigned vdim, unsigned pol array_acc1(pnum_basis, out_d, -1., incr); // Add contribution to CFL frequency. - double *cflfreq_d = (double *) gkyl_array_fetch(cflfreq, pstart); - cflfreq_d[0] += nu_d[0]*cellav_fac; + double *cflfreq_d = (double *)gkyl_array_fetch(cflfreq, pstart); + cflfreq_d[0] += nu_d[0] * cellav_fac; } } } -void -gkyl_bgk_collisions_advance_cu(const gkyl_bgk_collisions *up, - const struct gkyl_range *crange, const struct gkyl_range *prange, +void gkyl_bgk_collisions_advance_cu( + const gkyl_bgk_collisions *up, const struct gkyl_range *crange, const struct gkyl_range *prange, const struct gkyl_array *nu, const struct gkyl_array *nufM, const struct gkyl_array *fin, - bool implicit_step, double dt, struct gkyl_array *out, struct gkyl_array *cflfreq) + bool implicit_step, double dt, struct gkyl_array *out, struct gkyl_array *cflfreq +) { int nblocks = prange->nblocks; int nthreads = prange->nthreads; - gkyl_bgk_collisions_advance_cu_kernel<<>>(up->cdim, up->vdim, - up->poly_order, up->pnum_basis, up->pb_type, up->cellav_fac, *crange, *prange, - nu->on_dev, nufM->on_dev, fin->on_dev, implicit_step, dt, out->on_dev, cflfreq->on_dev); + gkyl_bgk_collisions_advance_cu_kernel<< > >( + up->cdim, up->vdim, up->poly_order, up->pnum_basis, up->pb_type, up->cellav_fac, *crange, + *prange, nu->on_dev, nufM->on_dev, fin->on_dev, implicit_step, dt, out->on_dev, cflfreq->on_dev + ); } diff --git a/vlasov/zero/dg_advection.c b/vlasov/zero/dg_advection.c index b75ba6ddbc..464f799977 100644 --- a/vlasov/zero/dg_advection.c +++ b/vlasov/zero/dg_advection.c @@ -9,10 +9,9 @@ #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_advection_free(const struct gkyl_ref_count *ref) +void gkyl_advection_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); @@ -20,14 +19,15 @@ gkyl_advection_free(const struct gkyl_ref_count *ref) // free inner on_dev object struct dg_advection *advection = container_of(base->on_dev, struct dg_advection, eqn); gkyl_cu_free(advection); - } - + } + struct dg_advection *advection = container_of(base, struct dg_advection, eqn); gkyl_free(advection); } -void -gkyl_advection_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_advection_auxfields auxin) +void gkyl_advection_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_advection_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(auxin.u_i)) { @@ -40,13 +40,14 @@ gkyl_advection_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_advec advection->auxfields.u_i = auxin.u_i; } -struct gkyl_dg_eqn* -gkyl_dg_advection_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_advection_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_advection_cu_dev_new(cbasis, conf_range); - } + } #endif struct dg_advection *advection = gkyl_malloc(sizeof(struct dg_advection)); @@ -57,48 +58,52 @@ gkyl_dg_advection_new(const struct gkyl_basis* cbasis, const struct gkyl_range* const gkyl_dg_advection_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - surf_z_kernels = ser_surf_z_kernels; - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + surf_z_kernels = ser_surf_z_kernels; + break; + + default: + assert(false); + break; + } + advection->eqn.num_equations = 1; advection->eqn.surf_term = surf; advection->eqn.boundary_surf_term = boundary_surf; - advection->eqn.vol_term = CK(vol_kernels, cdim, poly_order); + advection->eqn.vol_term = CK(vol_kernels, cdim, poly_order); advection->surf[0] = CK(surf_x_kernels, cdim, poly_order); - if (cdim>1) + if (cdim > 1) { advection->surf[1] = CK(surf_y_kernels, cdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { advection->surf[2] = CK(surf_z_kernels, cdim, poly_order); + } - // ensure non-NULL pointers - for (int i=0; isurf[i]); + // ensure non-NULL pointers + for (int i = 0; i < cdim; ++i) { + assert(advection->surf[i]); + } - advection->auxfields.u_i = 0; + advection->auxfields.u_i = 0; advection->conf_range = *conf_range; advection->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(advection->eqn.flags); advection->eqn.ref_count = gkyl_ref_count_init(gkyl_advection_free); advection->eqn.on_dev = &advection->eqn; // CPU eqn obj points to itself - + return &advection->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_advection_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range) +struct gkyl_dg_eqn * +gkyl_dg_advection_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range) { assert(false); return 0; diff --git a/vlasov/zero/dg_advection_cu.cu b/vlasov/zero/dg_advection_cu.cu index a5142d9268..34dcdd1f25 100644 --- a/vlasov/zero/dg_advection_cu.cu +++ b/vlasov/zero/dg_advection_cu.cu @@ -3,13 +3,13 @@ extern "C" { #include #include -#include +#include #include } #include -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, @@ -22,49 +22,53 @@ gkyl_advection_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, const stru } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_advection_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_advection_auxfields auxin) +void gkyl_advection_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_advection_auxfields auxin +) { - gkyl_advection_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.u_i->on_dev); + gkyl_advection_set_auxfields_cu_kernel<<<1, 1> > >(eqn, auxin.u_i->on_dev); } -__global__ void static -dg_advection_set_cu_dev_ptrs(struct dg_advection* advection, enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ void static dg_advection_set_cu_dev_ptrs( + struct dg_advection *advection, enum gkyl_basis_type b_type, int cdim, int poly_order +) { - advection->auxfields.u_i = 0; + advection->auxfields.u_i = 0; const gkyl_dg_advection_vol_kern_list *vol_kernels; - const gkyl_dg_advection_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; - + const gkyl_dg_advection_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - surf_z_kernels = ser_surf_z_kernels; - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + surf_z_kernels = ser_surf_z_kernels; + break; + + default: + assert(false); + break; + } + advection->eqn.surf_term = surf; advection->eqn.boundary_surf_term = boundary_surf; - advection->eqn.vol_term = CK(vol_kernels, cdim, poly_order); + advection->eqn.vol_term = CK(vol_kernels, cdim, poly_order); advection->surf[0] = CK(surf_x_kernels, cdim, poly_order); - if (cdim>1) + if (cdim > 1) { advection->surf[1] = CK(surf_y_kernels, cdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { advection->surf[2] = CK(surf_z_kernels, cdim, poly_order); + } } -struct gkyl_dg_eqn* -gkyl_dg_advection_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range) +struct gkyl_dg_eqn * +gkyl_dg_advection_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range) { - struct dg_advection *advection = (struct dg_advection*) gkyl_malloc(sizeof(struct dg_advection)); + struct dg_advection *advection = (struct dg_advection *)gkyl_malloc(sizeof(struct dg_advection)); // set basic parameters advection->eqn.num_equations = 1; @@ -75,9 +79,12 @@ gkyl_dg_advection_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_ advection->eqn.ref_count = gkyl_ref_count_init(gkyl_advection_free); // copy the host struct to device struct - struct dg_advection *advection_cu = (struct dg_advection*) gkyl_cu_malloc(sizeof(struct dg_advection)); + struct dg_advection *advection_cu = + (struct dg_advection *)gkyl_cu_malloc(sizeof(struct dg_advection)); gkyl_cu_memcpy(advection_cu, advection, sizeof(struct dg_advection), GKYL_CU_MEMCPY_H2D); - dg_advection_set_cu_dev_ptrs<<<1,1>>>(advection_cu, cbasis->b_type, cbasis->ndim, cbasis->poly_order); + dg_advection_set_cu_dev_ptrs<<<1, 1> > >( + advection_cu, cbasis->b_type, cbasis->ndim, cbasis->poly_order + ); // set parent on_dev pointer advection->eqn.on_dev = &advection_cu->eqn; diff --git a/vlasov/zero/dg_calc_canonical_pb_fluid_vars.c b/vlasov/zero/dg_calc_canonical_pb_fluid_vars.c index 7290966c92..3fd6083334 100644 --- a/vlasov/zero/dg_calc_canonical_pb_fluid_vars.c +++ b/vlasov/zero/dg_calc_canonical_pb_fluid_vars.c @@ -9,52 +9,56 @@ #include #include -gkyl_dg_calc_canonical_pb_fluid_vars* -gkyl_dg_calc_canonical_pb_fluid_vars_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, - const struct gkyl_wv_eqn *wv_eqn, bool use_gpu) +gkyl_dg_calc_canonical_pb_fluid_vars *gkyl_dg_calc_canonical_pb_fluid_vars_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_wv_eqn *wv_eqn, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { - return gkyl_dg_calc_canonical_pb_fluid_vars_cu_dev_new(conf_grid, - conf_basis, conf_range, conf_ext_range, wv_eqn); - } -#endif - gkyl_dg_calc_canonical_pb_fluid_vars *up = gkyl_malloc(sizeof(gkyl_dg_calc_canonical_pb_fluid_vars)); + if (use_gpu) { + return gkyl_dg_calc_canonical_pb_fluid_vars_cu_dev_new( + conf_grid, conf_basis, conf_range, conf_ext_range, wv_eqn + ); + } +#endif + gkyl_dg_calc_canonical_pb_fluid_vars *up = + gkyl_malloc(sizeof(gkyl_dg_calc_canonical_pb_fluid_vars)); up->conf_grid = *conf_grid; - up->conf_basis = *conf_basis; + up->conf_basis = *conf_basis; int cdim = conf_basis->ndim; int poly_order = conf_basis->poly_order; up->cdim = cdim; up->alpha = 0.0; - up->is_modified = 0; + up->is_modified = 0; up->adiabatic_coupling_phi_n = 0; if (wv_eqn->type == GKYL_EQN_CAN_PB_HASEGAWA_MIMA) { - up->canonical_pb_fluid_source = choose_canonical_pb_fluid_hasegawa_mima_source_kern(conf_basis->b_type, cdim, poly_order); - } - else if (wv_eqn->type == GKYL_EQN_CAN_PB_HASEGAWA_WAKATANI) { - up->alpha = gkyl_wv_can_pb_hasegawa_wakatani_alpha(wv_eqn); - up->is_modified = gkyl_wv_can_pb_hasegawa_wakatani_is_modified(wv_eqn); + up->canonical_pb_fluid_source = + choose_canonical_pb_fluid_hasegawa_mima_source_kern(conf_basis->b_type, cdim, poly_order); + } else if (wv_eqn->type == GKYL_EQN_CAN_PB_HASEGAWA_WAKATANI) { + up->alpha = gkyl_wv_can_pb_hasegawa_wakatani_alpha(wv_eqn); + up->is_modified = gkyl_wv_can_pb_hasegawa_wakatani_is_modified(wv_eqn); // Temporary array for holding the density and combined potential and density for computing the adiabatic coupling. // These are stored separately from the input phi and fluid arrays in case we are solving the - // modified Hasegawa-Wakatani system and need to subtract the zonal components. + // modified Hasegawa-Wakatani system and need to subtract the zonal components. up->n = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_ext_range->volume); - // Component 0 is n, Component 1 is phi. - up->adiabatic_coupling_phi_n = gkyl_array_new(GKYL_DOUBLE, 2*conf_basis->num_basis, conf_ext_range->volume); + // Component 0 is n, Component 1 is phi. + up->adiabatic_coupling_phi_n = + gkyl_array_new(GKYL_DOUBLE, 2 * conf_basis->num_basis, conf_ext_range->volume); // Set up the array averaging to correctly subtact the zonal component of fluctuations // Currently assumes that updater has *no decomposition* in y and thus owns the whole y range. if (up->is_modified) { - // Make the one-dimensional x basis, and ranges for constructing the average. + // Make the one-dimensional x basis, and ranges for constructing the average. struct gkyl_basis basis_x; gkyl_cart_modal_serendip(&basis_x, 1, poly_order); gkyl_range_init(&up->x_local, 1, &conf_range->lower[0], &conf_range->upper[0]); gkyl_range_init(&up->x_local_ext, 1, &conf_ext_range->lower[0], &conf_ext_range->upper[0]); // Integration over y only, (x,y) to (x). - int int_dim_y[] = {0,1,0}; + int int_dim_y[] = {0, 1, 0}; struct gkyl_array_average_inp inp_int_y = { .grid = &up->conf_grid, .basis = up->conf_basis, @@ -69,35 +73,42 @@ gkyl_dg_calc_canonical_pb_fluid_vars_new(const struct gkyl_rect_grid *conf_grid, up->int_y = gkyl_array_average_inew(&inp_int_y); up->phi_zonal = gkyl_array_new(GKYL_DOUBLE, basis_x.num_basis, up->x_local_ext.volume); up->n_zonal = gkyl_array_new(GKYL_DOUBLE, basis_x.num_basis, up->x_local_ext.volume); - up->subtract_zonal = choose_canonical_pb_fluid_subtract_zonal_kern(conf_basis->b_type, cdim, poly_order); + up->subtract_zonal = + choose_canonical_pb_fluid_subtract_zonal_kern(conf_basis->b_type, cdim, poly_order); } - up->canonical_pb_fluid_source = choose_canonical_pb_fluid_hasegawa_wakatani_source_kern(conf_basis->b_type, cdim, poly_order); + up->canonical_pb_fluid_source = + choose_canonical_pb_fluid_hasegawa_wakatani_source_kern(conf_basis->b_type, cdim, poly_order); + } else { + // Default source kernel; immediately returns and does not do anything. + up->canonical_pb_fluid_source = + choose_canonical_pb_fluid_default_source_kern(conf_basis->b_type, cdim, poly_order); } - else { - // Default source kernel; immediately returns and does not do anything. - up->canonical_pb_fluid_source = choose_canonical_pb_fluid_default_source_kern(conf_basis->b_type, cdim, poly_order); - } - for (int d=0; dalpha_surf[d] = choose_canonical_pb_fluid_alpha_surf_kern(conf_basis->b_type, d, cdim, poly_order); - up->alpha_edge_surf[d] = choose_canonical_pb_fluid_alpha_edge_surf_kern(conf_basis->b_type, d, cdim, poly_order); + for (int d = 0; d < cdim; ++d) { + up->alpha_surf[d] = + choose_canonical_pb_fluid_alpha_surf_kern(conf_basis->b_type, d, cdim, poly_order); + up->alpha_edge_surf[d] = + choose_canonical_pb_fluid_alpha_edge_surf_kern(conf_basis->b_type, d, cdim, poly_order); } up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, - const struct gkyl_array* phi, - struct gkyl_array* alpha_surf, struct gkyl_array* sgn_alpha_surf, struct gkyl_array* const_sgn_alpha) +void gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *conf_ext_range, const struct gkyl_array *phi, + struct gkyl_array *alpha_surf, struct gkyl_array *sgn_alpha_surf, + struct gkyl_array *const_sgn_alpha +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(alpha_surf)) { - return gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf_cu(up, conf_range, conf_ext_range, phi, - alpha_surf, sgn_alpha_surf, const_sgn_alpha); + return gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf_cu( + up, conf_range, conf_ext_range, phi, alpha_surf, sgn_alpha_surf, const_sgn_alpha + ); } #endif int cdim = up->cdim; @@ -111,81 +122,84 @@ void gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf(struct gkyl_dg_calc_canonic long loc = gkyl_range_idx(conf_range, idx); gkyl_rect_grid_cell_center(&up->conf_grid, idx, xc); - double* alpha_surf_d = gkyl_array_fetch(alpha_surf, loc); - double* sgn_alpha_surf_d = gkyl_array_fetch(sgn_alpha_surf, loc); - int* const_sgn_alpha_d = gkyl_array_fetch(const_sgn_alpha, loc); + double *alpha_surf_d = gkyl_array_fetch(alpha_surf, loc); + double *sgn_alpha_surf_d = gkyl_array_fetch(sgn_alpha_surf, loc); + int *const_sgn_alpha_d = gkyl_array_fetch(const_sgn_alpha, loc); // Fill in the configuration space alpha_surf - for (int dir = 0; diralpha_surf[dir](xc, up->conf_grid.dx, - (const double*) gkyl_array_cfetch(phi, loc), - alpha_surf_d, sgn_alpha_surf_d); + for (int dir = 0; dir < cdim; ++dir) { + const_sgn_alpha_d[dir] = up->alpha_surf[dir]( + xc, up->conf_grid.dx, (const double *)gkyl_array_cfetch(phi, loc), alpha_surf_d, + sgn_alpha_surf_d + ); // If the configuration space index is at the local configuration space upper value, we - // we are at the configuration space upper edge and we also need to evaluate - // alpha = +1 to avoid evaluating the potential in the ghost cells + // we are at the configuration space upper edge and we also need to evaluate + // alpha = +1 to avoid evaluating the potential in the ghost cells // where it is not defined when computing the final surface alpha we need // (since the surface alpha array stores only the *lower* surface expansion) if (idx[dir] == conf_range->upper[dir]) { gkyl_copy_int_arr(cdim, idx, idx_edge); - idx_edge[dir] = idx_edge[dir]+1; + idx_edge[dir] = idx_edge[dir] + 1; long loc_ext = gkyl_range_idx(conf_ext_range, idx_edge); - double* alpha_surf_ext_d = gkyl_array_fetch(alpha_surf, loc_ext); - double* sgn_alpha_surf_ext_d = gkyl_array_fetch(sgn_alpha_surf, loc_ext); - int* const_sgn_alpha_ext_d = gkyl_array_fetch(const_sgn_alpha, loc_ext); - const_sgn_alpha_ext_d[dir] = up->alpha_edge_surf[dir](xc, up->conf_grid.dx, - (const double*) gkyl_array_cfetch(phi, loc), - alpha_surf_ext_d, sgn_alpha_surf_ext_d); - } + double *alpha_surf_ext_d = gkyl_array_fetch(alpha_surf, loc_ext); + double *sgn_alpha_surf_ext_d = gkyl_array_fetch(sgn_alpha_surf, loc_ext); + int *const_sgn_alpha_ext_d = gkyl_array_fetch(const_sgn_alpha, loc_ext); + const_sgn_alpha_ext_d[dir] = up->alpha_edge_surf[dir]( + xc, up->conf_grid.dx, (const double *)gkyl_array_cfetch(phi, loc), alpha_surf_ext_d, + sgn_alpha_surf_ext_d + ); + } } } } -void gkyl_canonical_pb_fluid_vars_source(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array *phi, const struct gkyl_array *n0, - const struct gkyl_array *fluid, struct gkyl_array *rhs) +void gkyl_canonical_pb_fluid_vars_source( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *phi, const struct gkyl_array *n0, const struct gkyl_array *fluid, + struct gkyl_array *rhs +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(rhs)) { return gkyl_canonical_pb_fluid_vars_source_cu(up, conf_range, phi, n0, fluid, rhs); } #endif - // If alpha is specified, we are solving Hasegawa-Wakatani and need to check - // whether we are solving the modified version of Hasegawa-Wakatani which + // If alpha is specified, we are solving Hasegawa-Wakatani and need to check + // whether we are solving the modified version of Hasegawa-Wakatani which // requires computing the zonal components of phi, n: f_zonal = 1/Ly int f dy - // and subtracting the zonal components off the adiabatic coupling, f_tilde = f - f_zonal. + // and subtracting the zonal components off the adiabatic coupling, f_tilde = f - f_zonal. // Otherwise, we just copy n and phi into a temporary array for use in the updater. if (up->alpha > 0.0) { gkyl_array_set_offset(up->n, 1.0, fluid, up->conf_basis.num_basis); gkyl_array_set_offset(up->adiabatic_coupling_phi_n, 1.0, phi, 0); gkyl_array_set_offset(up->adiabatic_coupling_phi_n, 1.0, up->n, up->conf_basis.num_basis); if (up->is_modified) { - // Compute the zonal components of phi and n. + // Compute the zonal components of phi and n. gkyl_array_average_advance(up->int_y, phi, up->phi_zonal); gkyl_array_average_advance(up->int_y, up->n, up->n_zonal); // Iterate over the 2D grid and subtract off the 1D zonal component struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, conf_range); while (gkyl_range_iter_next(&iter)) { - long loc = gkyl_range_idx(conf_range, iter.idx); - long loc_1d = gkyl_range_idx(&up->x_local, iter.idx); + long loc = gkyl_range_idx(conf_range, iter.idx); + long loc_1d = gkyl_range_idx(&up->x_local, iter.idx); const double *phi_zonal_d = gkyl_array_cfetch(up->phi_zonal, loc_1d); const double *n_zonal_d = gkyl_array_cfetch(up->n_zonal, loc_1d); - double *adiabatic_coupling_phi_n_d = gkyl_array_fetch(up->adiabatic_coupling_phi_n, loc); - up->subtract_zonal(phi_zonal_d, n_zonal_d, adiabatic_coupling_phi_n_d); + double *adiabatic_coupling_phi_n_d = gkyl_array_fetch(up->adiabatic_coupling_phi_n, loc); + up->subtract_zonal(phi_zonal_d, n_zonal_d, adiabatic_coupling_phi_n_d); } } } - // Loop over the grid and compute the source update. + // Loop over the grid and compute the source update. // For equation systems such as incompressible Euler, this function returns immediately (no sources). // For Hasegawa-Mima, computes {phi, n0} where {., .} is the canonical Poisson bracket. // For Hasegawa-Wakatani, computes alpha*(phi - n) + {phi, n0}, where the first - // term potentially has the zonal components subtracted off if we are solving modified Hasegawa-Wakatani. + // term potentially has the zonal components subtracted off if we are solving modified Hasegawa-Wakatani. struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, conf_range); while (gkyl_range_iter_next(&iter)) { @@ -194,25 +208,29 @@ void gkyl_canonical_pb_fluid_vars_source(struct gkyl_dg_calc_canonical_pb_fluid_ const double *phi_d = gkyl_array_cfetch(phi, loc); const double *n0_d = gkyl_array_cfetch(n0, loc); - double* rhs_d = gkyl_array_fetch(rhs, loc); + double *rhs_d = gkyl_array_fetch(rhs, loc); - up->canonical_pb_fluid_source(up->conf_grid.dx, up->alpha, phi_d, n0_d, - up->adiabatic_coupling_phi_n ? (const double*) gkyl_array_cfetch(up->adiabatic_coupling_phi_n, loc) : 0, - rhs_d); + up->canonical_pb_fluid_source( + up->conf_grid.dx, up->alpha, phi_d, n0_d, + up->adiabatic_coupling_phi_n ? + (const double *)gkyl_array_cfetch(up->adiabatic_coupling_phi_n, loc) : + 0, + rhs_d + ); } } void gkyl_dg_calc_canonical_pb_fluid_vars_release(gkyl_dg_calc_canonical_pb_fluid_vars *up) { // If alpha was specified, we were solving Hasegawa-Wakatani - // and need to free specific Hasegawa-Wakatani allocated memory. + // and need to free specific Hasegawa-Wakatani allocated memory. if (up->alpha > 0.0) { - gkyl_array_release(up->n); - gkyl_array_release(up->adiabatic_coupling_phi_n); + gkyl_array_release(up->n); + gkyl_array_release(up->adiabatic_coupling_phi_n); if (up->is_modified) { - gkyl_array_release(up->phi_zonal); - gkyl_array_release(up->n_zonal); - gkyl_array_average_release(up->int_y); + gkyl_array_release(up->phi_zonal); + gkyl_array_release(up->n_zonal); + gkyl_array_average_release(up->int_y); } } diff --git a/vlasov/zero/dg_calc_canonical_pb_fluid_vars_cu.cu b/vlasov/zero/dg_calc_canonical_pb_fluid_vars_cu.cu index b1ecbe4136..28cf5959d9 100644 --- a/vlasov/zero/dg_calc_canonical_pb_fluid_vars_cu.cu +++ b/vlasov/zero/dg_calc_canonical_pb_fluid_vars_cu.cu @@ -14,79 +14,79 @@ extern "C" { #include } -__global__ void -gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf_cu_kernel(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - const struct gkyl_range conf_range, const struct gkyl_range conf_ext_range, - struct gkyl_array *phi, - struct gkyl_array* alpha_surf, struct gkyl_array* sgn_alpha_surf, struct gkyl_array* const_sgn_alpha) +__global__ void gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf_cu_kernel( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, const struct gkyl_range conf_range, + const struct gkyl_range conf_ext_range, struct gkyl_array *phi, struct gkyl_array *alpha_surf, + struct gkyl_array *sgn_alpha_surf, struct gkyl_array *const_sgn_alpha +) { int cdim = up->cdim; int idx[GKYL_MAX_DIM], idx_edge[GKYL_MAX_DIM]; double xc[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange - gkyl_sub_range_inv_idx(&conf_range, linc1, idx); + gkyl_sub_range_inv_idx(&conf_range, linc1, idx); long loc = gkyl_range_idx(&conf_range, idx); gkyl_rect_grid_cell_center(&up->conf_grid, idx, xc); - double* alpha_surf_d = (double*) gkyl_array_fetch(alpha_surf, loc); - double* sgn_alpha_surf_d = (double*) gkyl_array_fetch(sgn_alpha_surf, loc); - int* const_sgn_alpha_d = (int*) gkyl_array_fetch(const_sgn_alpha, loc); - for (int dir = 0; diralpha_surf[dir](xc, up->conf_grid.dx, - (const double*) gkyl_array_cfetch(phi, loc), - alpha_surf_d, sgn_alpha_surf_d); + double *alpha_surf_d = (double *)gkyl_array_fetch(alpha_surf, loc); + double *sgn_alpha_surf_d = (double *)gkyl_array_fetch(sgn_alpha_surf, loc); + int *const_sgn_alpha_d = (int *)gkyl_array_fetch(const_sgn_alpha, loc); + for (int dir = 0; dir < cdim; ++dir) { + const_sgn_alpha_d[dir] = up->alpha_surf[dir]( + xc, up->conf_grid.dx, (const double *)gkyl_array_cfetch(phi, loc), alpha_surf_d, + sgn_alpha_surf_d + ); // If the configuration space index is at the local configuration space upper value, we - // we are at the configuration space upper edge and we also need to evaluate - // alpha = +1 to avoid evaluating the geometry information in the ghost cells + // we are at the configuration space upper edge and we also need to evaluate + // alpha = +1 to avoid evaluating the geometry information in the ghost cells // where it is not defined when computing the final surface alpha we need // (since the surface alpha array stores only the *lower* surface expansion) if (idx[dir] == conf_range.upper[dir]) { gkyl_copy_int_arr(cdim, idx, idx_edge); - idx_edge[dir] = idx_edge[dir]+1; + idx_edge[dir] = idx_edge[dir] + 1; long loc_ext = gkyl_range_idx(&conf_ext_range, idx_edge); - double* alpha_surf_ext_d = (double*) gkyl_array_fetch(alpha_surf, loc_ext); - double* sgn_alpha_surf_ext_d = (double*) gkyl_array_fetch(sgn_alpha_surf, loc_ext); - int* const_sgn_alpha_ext_d = (int*) gkyl_array_fetch(const_sgn_alpha, loc_ext); - const_sgn_alpha_ext_d[dir] = up->alpha_edge_surf[dir](xc, up->conf_grid.dx, - (const double*) gkyl_array_fetch(phi, loc), - alpha_surf_ext_d, sgn_alpha_surf_ext_d); - } + double *alpha_surf_ext_d = (double *)gkyl_array_fetch(alpha_surf, loc_ext); + double *sgn_alpha_surf_ext_d = (double *)gkyl_array_fetch(sgn_alpha_surf, loc_ext); + int *const_sgn_alpha_ext_d = (int *)gkyl_array_fetch(const_sgn_alpha, loc_ext); + const_sgn_alpha_ext_d[dir] = up->alpha_edge_surf[dir]( + xc, up->conf_grid.dx, (const double *)gkyl_array_fetch(phi, loc), alpha_surf_ext_d, + sgn_alpha_surf_ext_d + ); + } } } } -// Host-side wrapper for configuration-space surface alpha computation. -void -gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf_cu(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, - const struct gkyl_array *phi, - struct gkyl_array* alpha_surf, struct gkyl_array* sgn_alpha_surf, struct gkyl_array* const_sgn_alpha) +// Host-side wrapper for configuration-space surface alpha computation. +void gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf_cu( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *conf_ext_range, const struct gkyl_array *phi, + struct gkyl_array *alpha_surf, struct gkyl_array *sgn_alpha_surf, + struct gkyl_array *const_sgn_alpha +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf_cu_kernel<<>>(up->on_dev, - *conf_range, *conf_ext_range, - phi->on_dev, alpha_surf->on_dev, sgn_alpha_surf->on_dev, const_sgn_alpha->on_dev); + gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf_cu_kernel<< > >( + up->on_dev, *conf_range, *conf_ext_range, phi->on_dev, alpha_surf->on_dev, + sgn_alpha_surf->on_dev, const_sgn_alpha->on_dev + ); } -__global__ void -gkyl_canonical_pb_fluid_vars_subtract_zonal_cu_kernel(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - struct gkyl_range conf_range, struct gkyl_range x_range, - const struct gkyl_array *phi_zonal, const struct gkyl_array *n_zonal, - struct gkyl_array *adiabatic_coupling_phi_n) +__global__ void gkyl_canonical_pb_fluid_vars_subtract_zonal_cu_kernel( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, struct gkyl_range conf_range, + struct gkyl_range x_range, const struct gkyl_array *phi_zonal, const struct gkyl_array *n_zonal, + struct gkyl_array *adiabatic_coupling_phi_n +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -95,27 +95,25 @@ gkyl_canonical_pb_fluid_vars_subtract_zonal_cu_kernel(struct gkyl_dg_calc_canoni // convert back to a linear index on the super-range (with ghost cells) // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - long loc_1d = gkyl_range_idx(&x_range, idx); + long loc_1d = gkyl_range_idx(&x_range, idx); - const double *phi_zonal_d = (const double*) gkyl_array_cfetch(phi_zonal, loc_1d); - const double *n_zonal_d = (const double*) gkyl_array_cfetch(n_zonal, loc_1d); + const double *phi_zonal_d = (const double *)gkyl_array_cfetch(phi_zonal, loc_1d); + const double *n_zonal_d = (const double *)gkyl_array_cfetch(n_zonal, loc_1d); - double *adiabatic_coupling_phi_n_d = (double*) gkyl_array_fetch(adiabatic_coupling_phi_n, loc); - up->subtract_zonal(phi_zonal_d, n_zonal_d, adiabatic_coupling_phi_n_d); + double *adiabatic_coupling_phi_n_d = (double *)gkyl_array_fetch(adiabatic_coupling_phi_n, loc); + up->subtract_zonal(phi_zonal_d, n_zonal_d, adiabatic_coupling_phi_n_d); } } -__global__ void -gkyl_canonical_pb_fluid_vars_source_cu_kernel(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - struct gkyl_range conf_range, - const struct gkyl_array *phi, const struct gkyl_array *n0, - const struct gkyl_array *adiabatic_coupling_phi_n, struct gkyl_array *rhs) +__global__ void gkyl_canonical_pb_fluid_vars_source_cu_kernel( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, struct gkyl_range conf_range, + const struct gkyl_array *phi, const struct gkyl_array *n0, + const struct gkyl_array *adiabatic_coupling_phi_n, struct gkyl_array *rhs +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -125,115 +123,123 @@ gkyl_canonical_pb_fluid_vars_source_cu_kernel(struct gkyl_dg_calc_canonical_pb_f // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *phi_d = (const double*) gkyl_array_cfetch(phi, loc); - const double *n0_d = (const double*) gkyl_array_cfetch(n0, loc); + const double *phi_d = (const double *)gkyl_array_cfetch(phi, loc); + const double *n0_d = (const double *)gkyl_array_cfetch(n0, loc); - double* rhs_d = (double*) gkyl_array_fetch(rhs, loc); - up->canonical_pb_fluid_source(up->conf_grid.dx, up->alpha, phi_d, n0_d, - adiabatic_coupling_phi_n ? (const double*) gkyl_array_cfetch(adiabatic_coupling_phi_n, loc) : 0, - rhs_d); + double *rhs_d = (double *)gkyl_array_fetch(rhs, loc); + up->canonical_pb_fluid_source( + up->conf_grid.dx, up->alpha, phi_d, n0_d, + adiabatic_coupling_phi_n ? (const double *)gkyl_array_cfetch(adiabatic_coupling_phi_n, loc) : + 0, + rhs_d + ); } } // Host-side wrapper for source update of canonical PB fluid systems. -void -gkyl_canonical_pb_fluid_vars_source_cu(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array *phi, const struct gkyl_array *n0, - const struct gkyl_array *fluid, struct gkyl_array *rhs) +void gkyl_canonical_pb_fluid_vars_source_cu( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *phi, const struct gkyl_array *n0, const struct gkyl_array *fluid, + struct gkyl_array *rhs +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - // If alpha is specified, we are solving Hasegawa-Wakatani and need to check - // whether we are solving the modified version of Hasegawa-Wakatani which + // If alpha is specified, we are solving Hasegawa-Wakatani and need to check + // whether we are solving the modified version of Hasegawa-Wakatani which // requires computing the zonal components of phi, n: f_zonal = 1/Ly int f dy - // and subtracting the zonal components off the adiabatic coupling, f_tilde = f - f_zonal. + // and subtracting the zonal components off the adiabatic coupling, f_tilde = f - f_zonal. // Otherwise, we just copy n and phi into a temporary array for use in the updater. if (up->alpha > 0.0) { gkyl_array_set_offset(up->n, 1.0, fluid, up->conf_basis.num_basis); gkyl_array_set_offset(up->adiabatic_coupling_phi_n, 1.0, phi, 0); gkyl_array_set_offset(up->adiabatic_coupling_phi_n, 1.0, up->n, up->conf_basis.num_basis); if (up->is_modified) { - // Compute the zonal components of phi and n. + // Compute the zonal components of phi and n. gkyl_array_average_advance(up->int_y, phi, up->phi_zonal); gkyl_array_average_advance(up->int_y, up->n, up->n_zonal); - gkyl_canonical_pb_fluid_vars_subtract_zonal_cu_kernel<<>>(up->on_dev, - *conf_range, up->x_local, up->phi_zonal->on_dev, up->n_zonal->on_dev, - up->adiabatic_coupling_phi_n->on_dev); + gkyl_canonical_pb_fluid_vars_subtract_zonal_cu_kernel<< > >( + up->on_dev, *conf_range, up->x_local, up->phi_zonal->on_dev, up->n_zonal->on_dev, + up->adiabatic_coupling_phi_n->on_dev + ); } } - gkyl_canonical_pb_fluid_vars_source_cu_kernel<<>>(up->on_dev, - *conf_range, phi->on_dev, n0->on_dev, - up->adiabatic_coupling_phi_n ? up->adiabatic_coupling_phi_n->on_dev : 0, - rhs->on_dev); + gkyl_canonical_pb_fluid_vars_source_cu_kernel<< > >( + up->on_dev, *conf_range, phi->on_dev, n0->on_dev, + up->adiabatic_coupling_phi_n ? up->adiabatic_coupling_phi_n->on_dev : 0, rhs->on_dev + ); } - // CUDA kernel to set device pointers to canonical pb vars kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_calc_canoncial_pb_vars_set_cu_dev_ptrs(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - enum gkyl_basis_type b_type, int cdim, int poly_order, enum gkyl_eqn_type eqn_type, bool is_modified) +__global__ static void dg_calc_canoncial_pb_vars_set_cu_dev_ptrs( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, enum gkyl_basis_type b_type, int cdim, + int poly_order, enum gkyl_eqn_type eqn_type, bool is_modified +) { if (eqn_type == GKYL_EQN_CAN_PB_HASEGAWA_MIMA) { - up->canonical_pb_fluid_source = choose_canonical_pb_fluid_hasegawa_mima_source_kern(b_type, cdim, poly_order); - } - else if (eqn_type == GKYL_EQN_CAN_PB_HASEGAWA_WAKATANI) { - up->canonical_pb_fluid_source = choose_canonical_pb_fluid_hasegawa_wakatani_source_kern(b_type, cdim, poly_order); + up->canonical_pb_fluid_source = + choose_canonical_pb_fluid_hasegawa_mima_source_kern(b_type, cdim, poly_order); + } else if (eqn_type == GKYL_EQN_CAN_PB_HASEGAWA_WAKATANI) { + up->canonical_pb_fluid_source = + choose_canonical_pb_fluid_hasegawa_wakatani_source_kern(b_type, cdim, poly_order); if (is_modified) { up->subtract_zonal = choose_canonical_pb_fluid_subtract_zonal_kern(b_type, cdim, poly_order); } + } else { + // Default source kernel; immediately returns and does not do anything. + up->canonical_pb_fluid_source = + choose_canonical_pb_fluid_default_source_kern(b_type, cdim, poly_order); } - else { - // Default source kernel; immediately returns and does not do anything. - up->canonical_pb_fluid_source = choose_canonical_pb_fluid_default_source_kern(b_type, cdim, poly_order); - } - for (int d=0; dalpha_surf[d] = choose_canonical_pb_fluid_alpha_surf_kern(b_type, d, cdim, poly_order); - up->alpha_edge_surf[d] = choose_canonical_pb_fluid_alpha_edge_surf_kern(b_type, d, cdim, poly_order); + up->alpha_edge_surf[d] = + choose_canonical_pb_fluid_alpha_edge_surf_kern(b_type, d, cdim, poly_order); } } - -gkyl_dg_calc_canonical_pb_fluid_vars* -gkyl_dg_calc_canonical_pb_fluid_vars_cu_dev_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, - const struct gkyl_wv_eqn *wv_eqn) -{ - struct gkyl_dg_calc_canonical_pb_fluid_vars *up = (struct gkyl_dg_calc_canonical_pb_fluid_vars *) gkyl_malloc(sizeof(gkyl_dg_calc_canonical_pb_fluid_vars)); +gkyl_dg_calc_canonical_pb_fluid_vars *gkyl_dg_calc_canonical_pb_fluid_vars_cu_dev_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_wv_eqn *wv_eqn +) +{ + struct gkyl_dg_calc_canonical_pb_fluid_vars *up = (struct gkyl_dg_calc_canonical_pb_fluid_vars *) + gkyl_malloc(sizeof(gkyl_dg_calc_canonical_pb_fluid_vars)); up->conf_grid = *conf_grid; - up->conf_basis = *conf_basis; + up->conf_basis = *conf_basis; int cdim = conf_basis->ndim; int poly_order = conf_basis->poly_order; up->cdim = cdim; up->alpha = 0.0; - up->is_modified = 0; + up->is_modified = 0; up->adiabatic_coupling_phi_n = 0; if (wv_eqn->type == GKYL_EQN_CAN_PB_HASEGAWA_WAKATANI) { - up->alpha = gkyl_wv_can_pb_hasegawa_wakatani_alpha(wv_eqn); - up->is_modified = gkyl_wv_can_pb_hasegawa_wakatani_is_modified(wv_eqn); + up->alpha = gkyl_wv_can_pb_hasegawa_wakatani_alpha(wv_eqn); + up->is_modified = gkyl_wv_can_pb_hasegawa_wakatani_is_modified(wv_eqn); // Temporary array for holding the density and combined potential and density for computing the adiabatic coupling. // These are stored separately from the input phi and fluid arrays in case we are solving the - // modified Hasegawa-Wakatani system and need to subtract the zonal components. + // modified Hasegawa-Wakatani system and need to subtract the zonal components. up->n = gkyl_array_cu_dev_new(GKYL_DOUBLE, conf_basis->num_basis, conf_ext_range->volume); - // Component 0 is n, Component 1 is phi. - up->adiabatic_coupling_phi_n = gkyl_array_cu_dev_new(GKYL_DOUBLE, 2*conf_basis->num_basis, conf_ext_range->volume); + // Component 0 is n, Component 1 is phi. + up->adiabatic_coupling_phi_n = + gkyl_array_cu_dev_new(GKYL_DOUBLE, 2 * conf_basis->num_basis, conf_ext_range->volume); // Set up the array averaging to correctly subtact the zonal component of fluctuations // Currently assumes that updater has *no decomposition* in y and thus owns the whole y range. if (up->is_modified) { - // Make the one-dimensional x basis, and ranges for constructing the average. + // Make the one-dimensional x basis, and ranges for constructing the average. struct gkyl_basis basis_x; gkyl_cart_modal_serendip(&basis_x, 1, poly_order); gkyl_range_init(&up->x_local, 1, &conf_range->lower[0], &conf_range->upper[0]); gkyl_range_init(&up->x_local_ext, 1, &conf_ext_range->lower[0], &conf_ext_range->upper[0]); // Integration over y only, (x,y) to (x). - int int_dim_y[] = {0,1,0}; + int int_dim_y[] = {0, 1, 0}; struct gkyl_array_average_inp inp_int_y = { .grid = &up->conf_grid, .basis = up->conf_basis, @@ -243,24 +249,29 @@ gkyl_dg_calc_canonical_pb_fluid_vars_cu_dev_new(const struct gkyl_rect_grid *con .local_avg_ext = &up->x_local_ext, .weight = NULL, .avg_dim = int_dim_y, - .use_gpu = true, // We will perform the average on GPUs + .use_gpu = true // We will perform the average on GPUs }; up->int_y = gkyl_array_average_inew(&inp_int_y); up->phi_zonal = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis_x.num_basis, up->x_local_ext.volume); up->n_zonal = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis_x.num_basis, up->x_local_ext.volume); - } + } } up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_calc_canonical_pb_fluid_vars *up_cu = (struct gkyl_dg_calc_canonical_pb_fluid_vars *) gkyl_cu_malloc(sizeof(gkyl_dg_calc_canonical_pb_fluid_vars)); + struct gkyl_dg_calc_canonical_pb_fluid_vars *up_cu = + (struct gkyl_dg_calc_canonical_pb_fluid_vars *)gkyl_cu_malloc( + sizeof(gkyl_dg_calc_canonical_pb_fluid_vars) + ); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_calc_canonical_pb_fluid_vars), GKYL_CU_MEMCPY_H2D); - dg_calc_canoncial_pb_vars_set_cu_dev_ptrs<<<1,1>>>(up_cu, conf_basis->b_type, cdim, poly_order, wv_eqn->type, up->is_modified); + dg_calc_canoncial_pb_vars_set_cu_dev_ptrs<<<1, 1> > >( + up_cu, conf_basis->b_type, cdim, poly_order, wv_eqn->type, up->is_modified + ); // set parent on_dev pointer up->on_dev = up_cu; - + return up; } diff --git a/vlasov/zero/dg_calc_canonical_pb_vars.c b/vlasov/zero/dg_calc_canonical_pb_vars.c index 3932136392..65f5a1a981 100644 --- a/vlasov/zero/dg_calc_canonical_pb_vars.c +++ b/vlasov/zero/dg_calc_canonical_pb_vars.c @@ -9,16 +9,16 @@ #include #include -gkyl_dg_calc_canonical_pb_vars* -gkyl_dg_calc_canonical_pb_vars_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, bool use_gpu) +gkyl_dg_calc_canonical_pb_vars *gkyl_dg_calc_canonical_pb_vars_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { - return gkyl_dg_calc_canonical_pb_vars_cu_dev_new(phase_grid, - conf_basis, phase_basis); - } -#endif + if (use_gpu) { + return gkyl_dg_calc_canonical_pb_vars_cu_dev_new(phase_grid, conf_basis, phase_basis); + } +#endif gkyl_dg_calc_canonical_pb_vars *up = gkyl_malloc(sizeof(gkyl_dg_calc_canonical_pb_vars)); up->phase_grid = *phase_grid; @@ -29,32 +29,46 @@ gkyl_dg_calc_canonical_pb_vars_new(const struct gkyl_rect_grid *phase_grid, up->cdim = cdim; up->pdim = pdim; - up->canonical_pb_pressure = choose_canonical_pb_pressure_kern(phase_basis->b_type, cv_index[cdim].vdim[vdim], cdim, poly_order); - up->canonical_pb_covariant_u_i = choose_canonical_pb_m1i_contra_to_cov_kern(phase_basis->b_type, cv_index[cdim].vdim[vdim], cdim, poly_order); - for (int d=0; dalpha_surf[d] = choose_canonical_pb_alpha_surf_kern(phase_basis->b_type, d, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order); - up->alpha_edge_surf[d] = choose_canonical_pb_alpha_edge_surf_kern(phase_basis->b_type, d, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order); + up->canonical_pb_pressure = choose_canonical_pb_pressure_kern( + phase_basis->b_type, cv_index[cdim].vdim[vdim], cdim, poly_order + ); + up->canonical_pb_covariant_u_i = choose_canonical_pb_m1i_contra_to_cov_kern( + phase_basis->b_type, cv_index[cdim].vdim[vdim], cdim, poly_order + ); + for (int d = 0; d < cdim; ++d) { + up->alpha_surf[d] = choose_canonical_pb_alpha_surf_kern( + phase_basis->b_type, d, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order + ); + up->alpha_edge_surf[d] = choose_canonical_pb_alpha_edge_surf_kern( + phase_basis->b_type, d, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order + ); } - for (int d=0; dalpha_surf[d+cdim] = choose_canonical_pb_alpha_surf_v_kern(phase_basis->b_type, d, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order); + for (int d = 0; d < vdim; ++d) { + up->alpha_surf[d + cdim] = choose_canonical_pb_alpha_surf_v_kern( + phase_basis->b_type, d, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order + ); } up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void gkyl_dg_calc_canonical_pb_vars_alpha_surf(struct gkyl_dg_calc_canonical_pb_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const struct gkyl_range *phase_ext_range, - struct gkyl_array *hamil, - struct gkyl_array* alpha_surf, struct gkyl_array* sgn_alpha_surf, struct gkyl_array* const_sgn_alpha) +void gkyl_dg_calc_canonical_pb_vars_alpha_surf( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *phase_ext_range, + struct gkyl_array *hamil, struct gkyl_array *alpha_surf, struct gkyl_array *sgn_alpha_surf, + struct gkyl_array *const_sgn_alpha +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(alpha_surf)) { - return gkyl_dg_calc_canonical_pb_vars_alpha_surf_cu(up, conf_range, phase_range, phase_ext_range, hamil, - alpha_surf, sgn_alpha_surf, const_sgn_alpha); + return gkyl_dg_calc_canonical_pb_vars_alpha_surf_cu( + up, conf_range, phase_range, phase_ext_range, hamil, alpha_surf, sgn_alpha_surf, + const_sgn_alpha + ); } #endif int pdim = up->pdim; @@ -71,52 +85,58 @@ void gkyl_dg_calc_canonical_pb_vars_alpha_surf(struct gkyl_dg_calc_canonical_pb_ long loc_phase = gkyl_range_idx(phase_range, idx); gkyl_rect_grid_cell_center(&up->phase_grid, idx, xc); - double* alpha_surf_d = gkyl_array_fetch(alpha_surf, loc_phase); - double* sgn_alpha_surf_d = gkyl_array_fetch(sgn_alpha_surf, loc_phase); - int* const_sgn_alpha_d = gkyl_array_fetch(const_sgn_alpha, loc_phase); + double *alpha_surf_d = gkyl_array_fetch(alpha_surf, loc_phase); + double *sgn_alpha_surf_d = gkyl_array_fetch(sgn_alpha_surf, loc_phase); + int *const_sgn_alpha_d = gkyl_array_fetch(const_sgn_alpha, loc_phase); // Fill in the velocity space alpha_surf - for (int dir = 0; diralpha_surf[dir+cdim](xc, up->phase_grid.dx, - (const double*) gkyl_array_cfetch(hamil, loc_phase), - alpha_surf_d, sgn_alpha_surf_d); + for (int dir = 0; dir < vdim; ++dir) { + const_sgn_alpha_d[dir + cdim] = up->alpha_surf[dir + cdim]( + xc, up->phase_grid.dx, (const double *)gkyl_array_cfetch(hamil, loc_phase), alpha_surf_d, + sgn_alpha_surf_d + ); } // Fill in the conf space alpha_surf - for (int dir = 0; diralpha_surf[dir](xc, up->phase_grid.dx, - (const double*) gkyl_array_cfetch(hamil, loc_phase), - alpha_surf_d, sgn_alpha_surf_d); + for (int dir = 0; dir < cdim; ++dir) { + const_sgn_alpha_d[dir] = up->alpha_surf[dir]( + xc, up->phase_grid.dx, (const double *)gkyl_array_cfetch(hamil, loc_phase), alpha_surf_d, + sgn_alpha_surf_d + ); // If the phase space index is at the local configuration space upper value, we - // we are at the configuration space upper edge and we also need to evaluate - // alpha = +1 to avoid evaluating the geometry information in the ghost cells + // we are at the configuration space upper edge and we also need to evaluate + // alpha = +1 to avoid evaluating the geometry information in the ghost cells // where it is not defined when computing the final surface alpha we need // (since the surface alpha array stores only the *lower* surface expansion) if (idx[dir] == conf_range->upper[dir]) { gkyl_copy_int_arr(pdim, idx, idx_edge); - idx_edge[dir] = idx_edge[dir]+1; + idx_edge[dir] = idx_edge[dir] + 1; long loc_phase_ext = gkyl_range_idx(phase_ext_range, idx_edge); - double* alpha_surf_ext_d = gkyl_array_fetch(alpha_surf, loc_phase_ext); - double* sgn_alpha_surf_ext_d = gkyl_array_fetch(sgn_alpha_surf, loc_phase_ext); - int* const_sgn_alpha_ext_d = gkyl_array_fetch(const_sgn_alpha, loc_phase_ext); - const_sgn_alpha_ext_d[dir] = up->alpha_edge_surf[dir](xc, up->phase_grid.dx, - (const double*) gkyl_array_cfetch(hamil, loc_phase), - alpha_surf_ext_d, sgn_alpha_surf_ext_d); - } + double *alpha_surf_ext_d = gkyl_array_fetch(alpha_surf, loc_phase_ext); + double *sgn_alpha_surf_ext_d = gkyl_array_fetch(sgn_alpha_surf, loc_phase_ext); + int *const_sgn_alpha_ext_d = gkyl_array_fetch(const_sgn_alpha, loc_phase_ext); + const_sgn_alpha_ext_d[dir] = up->alpha_edge_surf[dir]( + xc, up->phase_grid.dx, (const double *)gkyl_array_cfetch(hamil, loc_phase), + alpha_surf_ext_d, sgn_alpha_surf_ext_d + ); + } } } } - -void gkyl_canonical_pb_contra_to_covariant_m1i(struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array *h_ij, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, - struct gkyl_array *V_drift_cov, struct gkyl_array *M1i_cov) +void gkyl_canonical_pb_contra_to_covariant_m1i( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *h_ij, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, + struct gkyl_array *V_drift_cov, struct gkyl_array *M1i_cov +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(V_drift_cov)) { - return gkyl_canonical_pb_contra_to_covariant_m1i_cu(up, conf_range, h_ij, V_drift, M1i, V_drift_cov, M1i_cov); + return gkyl_canonical_pb_contra_to_covariant_m1i_cu( + up, conf_range, h_ij, V_drift, M1i, V_drift_cov, M1i_cov + ); } #endif int cdim = up->cdim; @@ -128,7 +148,7 @@ void gkyl_canonical_pb_contra_to_covariant_m1i(struct gkyl_dg_calc_canonical_pb_ const double *h_ij_d = gkyl_array_cfetch(h_ij, loc); const double *v_i_d = gkyl_array_cfetch(V_drift, loc); const double *nv_i_d = gkyl_array_cfetch(M1i, loc); - + double *v_i_cov_d = gkyl_array_fetch(V_drift_cov, loc); double *nv_i_cov_d = gkyl_array_fetch(M1i_cov, loc); @@ -136,10 +156,11 @@ void gkyl_canonical_pb_contra_to_covariant_m1i(struct gkyl_dg_calc_canonical_pb_ } } -void gkyl_canonical_pb_pressure(struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array *h_ij_inv, - const struct gkyl_array *MEnergy, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, - struct gkyl_array *pressure) +void gkyl_canonical_pb_pressure( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *h_ij_inv, const struct gkyl_array *MEnergy, + const struct gkyl_array *V_drift, const struct gkyl_array *M1i, struct gkyl_array *pressure +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(pressure)) { @@ -157,7 +178,7 @@ void gkyl_canonical_pb_pressure(struct gkyl_dg_calc_canonical_pb_vars *up, const const double *v_j_d = gkyl_array_cfetch(V_drift, loc); const double *nv_i_d = gkyl_array_cfetch(M1i, loc); - double* d_Jv_P_d = gkyl_array_fetch(pressure, loc); + double *d_Jv_P_d = gkyl_array_fetch(pressure, loc); up->canonical_pb_pressure(h_ij_inv_d, MEnergy_d, v_j_d, nv_i_d, d_Jv_P_d); } @@ -165,8 +186,8 @@ void gkyl_canonical_pb_pressure(struct gkyl_dg_calc_canonical_pb_vars *up, const void gkyl_dg_calc_canonical_pb_vars_release(gkyl_dg_calc_canonical_pb_vars *up) { - - if (GKYL_IS_CU_ALLOC(up->flags)) + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/vlasov/zero/dg_calc_canonical_pb_vars_cu.cu b/vlasov/zero/dg_calc_canonical_pb_vars_cu.cu index abd646410d..d7f00bd4b0 100644 --- a/vlasov/zero/dg_calc_canonical_pb_vars_cu.cu +++ b/vlasov/zero/dg_calc_canonical_pb_vars_cu.cu @@ -14,88 +14,90 @@ extern "C" { #include } - -__global__ void -gkyl_dg_calc_canonical_pb_vars_alpha_surf_cu_kernel(struct gkyl_dg_calc_canonical_pb_vars *up, - const struct gkyl_range conf_range, const struct gkyl_range phase_range, const struct gkyl_range phase_ext_range, - struct gkyl_array *hamil, - struct gkyl_array* alpha_surf, struct gkyl_array* sgn_alpha_surf, struct gkyl_array* const_sgn_alpha) +__global__ void gkyl_dg_calc_canonical_pb_vars_alpha_surf_cu_kernel( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range conf_range, + const struct gkyl_range phase_range, const struct gkyl_range phase_ext_range, + struct gkyl_array *hamil, struct gkyl_array *alpha_surf, struct gkyl_array *sgn_alpha_surf, + struct gkyl_array *const_sgn_alpha +) { int pdim = up->pdim; int cdim = up->cdim; int vdim = pdim - cdim; int idx[GKYL_MAX_DIM], idx_edge[GKYL_MAX_DIM]; double xc[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < phase_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < phase_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange - gkyl_sub_range_inv_idx(&phase_range, linc1, idx); + gkyl_sub_range_inv_idx(&phase_range, linc1, idx); long loc_phase = gkyl_range_idx(&phase_range, idx); gkyl_rect_grid_cell_center(&up->phase_grid, idx, xc); - double* alpha_surf_d = (double*) gkyl_array_fetch(alpha_surf, loc_phase); - double* sgn_alpha_surf_d = (double*) gkyl_array_fetch(sgn_alpha_surf, loc_phase); - int* const_sgn_alpha_d = (int*) gkyl_array_fetch(const_sgn_alpha, loc_phase); - for (int dir = 0; diralpha_surf[dir+cdim](xc, up->phase_grid.dx, - (const double*) gkyl_array_cfetch(hamil, loc_phase), - alpha_surf_d, sgn_alpha_surf_d); + double *alpha_surf_d = (double *)gkyl_array_fetch(alpha_surf, loc_phase); + double *sgn_alpha_surf_d = (double *)gkyl_array_fetch(sgn_alpha_surf, loc_phase); + int *const_sgn_alpha_d = (int *)gkyl_array_fetch(const_sgn_alpha, loc_phase); + for (int dir = 0; dir < vdim; ++dir) { + const_sgn_alpha_d[dir + cdim] = up->alpha_surf[dir + cdim]( + xc, up->phase_grid.dx, (const double *)gkyl_array_cfetch(hamil, loc_phase), alpha_surf_d, + sgn_alpha_surf_d + ); } - for (int dir = 0; diralpha_surf[dir](xc, up->phase_grid.dx, - (const double*) gkyl_array_cfetch(hamil, loc_phase), - alpha_surf_d, sgn_alpha_surf_d); + for (int dir = 0; dir < cdim; ++dir) { + const_sgn_alpha_d[dir] = up->alpha_surf[dir]( + xc, up->phase_grid.dx, (const double *)gkyl_array_cfetch(hamil, loc_phase), alpha_surf_d, + sgn_alpha_surf_d + ); // If the phase space index is at the local configuration space upper value, we - // we are at the configuration space upper edge and we also need to evaluate - // alpha = +1 to avoid evaluating the geometry information in the ghost cells + // we are at the configuration space upper edge and we also need to evaluate + // alpha = +1 to avoid evaluating the geometry information in the ghost cells // where it is not defined when computing the final surface alpha we need // (since the surface alpha array stores only the *lower* surface expansion) if (idx[dir] == conf_range.upper[dir]) { gkyl_copy_int_arr(pdim, idx, idx_edge); - idx_edge[dir] = idx_edge[dir]+1; + idx_edge[dir] = idx_edge[dir] + 1; long loc_phase_ext = gkyl_range_idx(&phase_ext_range, idx_edge); - double* alpha_surf_ext_d = (double*) gkyl_array_fetch(alpha_surf, loc_phase_ext); - double* sgn_alpha_surf_ext_d = (double*) gkyl_array_fetch(sgn_alpha_surf, loc_phase_ext); - int* const_sgn_alpha_ext_d = (int*) gkyl_array_fetch(const_sgn_alpha, loc_phase_ext); - const_sgn_alpha_ext_d[dir] = up->alpha_edge_surf[dir](xc, up->phase_grid.dx, - (const double*) gkyl_array_fetch(hamil, loc_phase), - alpha_surf_ext_d, sgn_alpha_surf_ext_d); - } + double *alpha_surf_ext_d = (double *)gkyl_array_fetch(alpha_surf, loc_phase_ext); + double *sgn_alpha_surf_ext_d = (double *)gkyl_array_fetch(sgn_alpha_surf, loc_phase_ext); + int *const_sgn_alpha_ext_d = (int *)gkyl_array_fetch(const_sgn_alpha, loc_phase_ext); + const_sgn_alpha_ext_d[dir] = up->alpha_edge_surf[dir]( + xc, up->phase_grid.dx, (const double *)gkyl_array_fetch(hamil, loc_phase), + alpha_surf_ext_d, sgn_alpha_surf_ext_d + ); + } } } } // Host-side wrapper -void -gkyl_dg_calc_canonical_pb_vars_alpha_surf_cu(struct gkyl_dg_calc_canonical_pb_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const struct gkyl_range *phase_ext_range, - struct gkyl_array *hamil, - struct gkyl_array* alpha_surf, struct gkyl_array* sgn_alpha_surf, struct gkyl_array* const_sgn_alpha) +void gkyl_dg_calc_canonical_pb_vars_alpha_surf_cu( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *phase_ext_range, + struct gkyl_array *hamil, struct gkyl_array *alpha_surf, struct gkyl_array *sgn_alpha_surf, + struct gkyl_array *const_sgn_alpha +) { int nblocks = phase_range->nblocks; int nthreads = phase_range->nthreads; - gkyl_dg_calc_canonical_pb_vars_alpha_surf_cu_kernel<<>>(up->on_dev, - *conf_range, *phase_range, *phase_ext_range, - hamil->on_dev, alpha_surf->on_dev, sgn_alpha_surf->on_dev, const_sgn_alpha->on_dev); + gkyl_dg_calc_canonical_pb_vars_alpha_surf_cu_kernel<< > >( + up->on_dev, *conf_range, *phase_range, *phase_ext_range, hamil->on_dev, alpha_surf->on_dev, + sgn_alpha_surf->on_dev, const_sgn_alpha->on_dev + ); } /* Convert the bulk velocity from contravariant to covaraint components for can-pb*/ -__global__ void -gkyl_canonical_pb_contra_to_covariant_m1i_cu_kernel(struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range conf_range, - const struct gkyl_array *h_ij, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, struct gkyl_array *V_drift_cov, - struct gkyl_array *M1i_cov) +__global__ void gkyl_canonical_pb_contra_to_covariant_m1i_cu_kernel( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range conf_range, + const struct gkyl_array *h_ij, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, + struct gkyl_array *V_drift_cov, struct gkyl_array *M1i_cov +) { int cdim = up->cdim; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -105,41 +107,41 @@ gkyl_canonical_pb_contra_to_covariant_m1i_cu_kernel(struct gkyl_dg_calc_canonica // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *h_ij_d = (const double*) gkyl_array_cfetch(h_ij, loc); - const double *v_j_d = (const double*) gkyl_array_cfetch(V_drift, loc); - const double *nv_i_d = (const double*) gkyl_array_cfetch(M1i, loc); - double *v_i_cov_d = (double*) gkyl_array_fetch(V_drift_cov, loc); - double *nv_i_cov_d = (double*) gkyl_array_fetch(M1i_cov, loc); + const double *h_ij_d = (const double *)gkyl_array_cfetch(h_ij, loc); + const double *v_j_d = (const double *)gkyl_array_cfetch(V_drift, loc); + const double *nv_i_d = (const double *)gkyl_array_cfetch(M1i, loc); + double *v_i_cov_d = (double *)gkyl_array_fetch(V_drift_cov, loc); + double *nv_i_cov_d = (double *)gkyl_array_fetch(M1i_cov, loc); up->canonical_pb_covariant_u_i(h_ij_d, v_j_d, nv_i_d, v_i_cov_d, nv_i_cov_d); } } // Host-side wrapper -void -gkyl_canonical_pb_contra_to_covariant_m1i_cu(struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array *h_ij, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, struct gkyl_array *V_drift_cov, - struct gkyl_array *M1i_cov) +void gkyl_canonical_pb_contra_to_covariant_m1i_cu( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *h_ij, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, + struct gkyl_array *V_drift_cov, struct gkyl_array *M1i_cov +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_canonical_pb_contra_to_covariant_m1i_cu_kernel<<>>(up->on_dev, - *conf_range, h_ij->on_dev, V_drift->on_dev, M1i->on_dev, V_drift_cov->on_dev, M1i_cov->on_dev); + gkyl_canonical_pb_contra_to_covariant_m1i_cu_kernel<< > >( + up->on_dev, *conf_range, h_ij->on_dev, V_drift->on_dev, M1i->on_dev, V_drift_cov->on_dev, + M1i_cov->on_dev + ); } - /* Compute the pressure for can-pb*/ -__global__ void -gkyl_canonical_pb_pressure_cu_kernel(struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range conf_range, - const struct gkyl_array *h_ij_inv, - const struct gkyl_array *MEnergy, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, - struct gkyl_array *pressure) +__global__ void gkyl_canonical_pb_pressure_cu_kernel( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range conf_range, + const struct gkyl_array *h_ij_inv, const struct gkyl_array *MEnergy, + const struct gkyl_array *V_drift, const struct gkyl_array *M1i, struct gkyl_array *pressure +) { int cdim = up->cdim; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -149,53 +151,60 @@ gkyl_canonical_pb_pressure_cu_kernel(struct gkyl_dg_calc_canonical_pb_vars *up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *h_ij_inv_d = (const double*) gkyl_array_cfetch(h_ij_inv, loc); - const double *MEnergy_d = (const double*) gkyl_array_cfetch(MEnergy, loc); - const double *v_j_d = (const double*) gkyl_array_cfetch(V_drift, loc); - const double *nv_i_d = (const double*) gkyl_array_cfetch(M1i, loc); + const double *h_ij_inv_d = (const double *)gkyl_array_cfetch(h_ij_inv, loc); + const double *MEnergy_d = (const double *)gkyl_array_cfetch(MEnergy, loc); + const double *v_j_d = (const double *)gkyl_array_cfetch(V_drift, loc); + const double *nv_i_d = (const double *)gkyl_array_cfetch(M1i, loc); - double* d_Jv_P_d = (double*) gkyl_array_fetch(pressure, loc); + double *d_Jv_P_d = (double *)gkyl_array_fetch(pressure, loc); up->canonical_pb_pressure(h_ij_inv_d, MEnergy_d, v_j_d, nv_i_d, d_Jv_P_d); } } // Host-side wrapper -void -gkyl_canonical_pb_pressure_cu(struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array *h_ij_inv, - const struct gkyl_array *MEnergy, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, - struct gkyl_array *pressure) +void gkyl_canonical_pb_pressure_cu( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *h_ij_inv, const struct gkyl_array *MEnergy, + const struct gkyl_array *V_drift, const struct gkyl_array *M1i, struct gkyl_array *pressure +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_canonical_pb_pressure_cu_kernel<<>>(up->on_dev, - *conf_range, h_ij_inv->on_dev, MEnergy->on_dev, V_drift->on_dev, M1i->on_dev, pressure->on_dev); + gkyl_canonical_pb_pressure_cu_kernel<< > >( + up->on_dev, *conf_range, h_ij_inv->on_dev, MEnergy->on_dev, V_drift->on_dev, M1i->on_dev, + pressure->on_dev + ); } - // CUDA kernel to set device pointers to canonical pb vars kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void - dg_calc_canoncial_pb_vars_set_cu_dev_ptrs(struct gkyl_dg_calc_canonical_pb_vars *up, - enum gkyl_basis_type b_type, int cv_index, int cdim, int vdim, int poly_order) +__global__ static void dg_calc_canoncial_pb_vars_set_cu_dev_ptrs( + struct gkyl_dg_calc_canonical_pb_vars *up, enum gkyl_basis_type b_type, int cv_index, int cdim, + int vdim, int poly_order +) { up->canonical_pb_pressure = choose_canonical_pb_pressure_kern(b_type, cv_index, cdim, poly_order); - up->canonical_pb_covariant_u_i = choose_canonical_pb_m1i_contra_to_cov_kern(b_type, cv_index, cdim, poly_order); - for (int d=0; dalpha_surf[d] = choose_canonical_pb_alpha_surf_kern(b_type, d, cv_index, cdim, vdim, poly_order); - up->alpha_edge_surf[d] = choose_canonical_pb_alpha_edge_surf_kern(b_type, d, cv_index, cdim, vdim, poly_order); + up->canonical_pb_covariant_u_i = + choose_canonical_pb_m1i_contra_to_cov_kern(b_type, cv_index, cdim, poly_order); + for (int d = 0; d < cdim; ++d) { + up->alpha_surf[d] = + choose_canonical_pb_alpha_surf_kern(b_type, d, cv_index, cdim, vdim, poly_order); + up->alpha_edge_surf[d] = + choose_canonical_pb_alpha_edge_surf_kern(b_type, d, cv_index, cdim, vdim, poly_order); } - for (int d=0; dalpha_surf[d+cdim] = choose_canonical_pb_alpha_surf_v_kern(b_type, d, cv_index, cdim, vdim, poly_order); + for (int d = 0; d < vdim; ++d) { + up->alpha_surf[d + cdim] = + choose_canonical_pb_alpha_surf_v_kern(b_type, d, cv_index, cdim, vdim, poly_order); } } - -gkyl_dg_calc_canonical_pb_vars* -gkyl_dg_calc_canonical_pb_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis) -{ - struct gkyl_dg_calc_canonical_pb_vars *up = (struct gkyl_dg_calc_canonical_pb_vars *) gkyl_malloc(sizeof(gkyl_dg_calc_canonical_pb_vars)); +gkyl_dg_calc_canonical_pb_vars *gkyl_dg_calc_canonical_pb_vars_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis +) +{ + struct gkyl_dg_calc_canonical_pb_vars *up = + (struct gkyl_dg_calc_canonical_pb_vars *)gkyl_malloc(sizeof(gkyl_dg_calc_canonical_pb_vars)); up->phase_grid = *phase_grid; int cdim = conf_basis->ndim; @@ -208,13 +217,16 @@ gkyl_dg_calc_canonical_pb_vars_cu_dev_new(const struct gkyl_rect_grid *phase_gri up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_calc_canonical_pb_vars *up_cu = (struct gkyl_dg_calc_canonical_pb_vars *) gkyl_cu_malloc(sizeof(gkyl_dg_calc_canonical_pb_vars)); + struct gkyl_dg_calc_canonical_pb_vars *up_cu = + (struct gkyl_dg_calc_canonical_pb_vars *)gkyl_cu_malloc(sizeof(gkyl_dg_calc_canonical_pb_vars)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_calc_canonical_pb_vars), GKYL_CU_MEMCPY_H2D); - dg_calc_canoncial_pb_vars_set_cu_dev_ptrs<<<1,1>>>(up_cu, phase_basis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order); + dg_calc_canoncial_pb_vars_set_cu_dev_ptrs<<<1, 1> > >( + up_cu, phase_basis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order + ); // set parent on_dev pointer up->on_dev = up_cu; - + return up; } diff --git a/vlasov/zero/dg_calc_em_vars.c b/vlasov/zero/dg_calc_em_vars.c index 88c7d4ffb6..c0a1af76de 100644 --- a/vlasov/zero/dg_calc_em_vars.c +++ b/vlasov/zero/dg_calc_em_vars.c @@ -9,18 +9,19 @@ #include #include -gkyl_dg_calc_em_vars* -gkyl_dg_calc_em_vars_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, - double limiter_fac, bool is_ExB, bool use_gpu) +gkyl_dg_calc_em_vars *gkyl_dg_calc_em_vars_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *cbasis, + const struct gkyl_range *mem_range, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_geom *geom, double limiter_fac, bool is_ExB, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { - return gkyl_dg_calc_em_vars_cu_dev_new(conf_grid, cbasis, - mem_range, wv_eqn, geom, limiter_fac, is_ExB); - } -#endif + if (use_gpu) { + return gkyl_dg_calc_em_vars_cu_dev_new( + conf_grid, cbasis, mem_range, wv_eqn, geom, limiter_fac, is_ExB + ); + } +#endif gkyl_dg_calc_em_vars *up = gkyl_malloc(sizeof(gkyl_dg_calc_em_vars)); up->conf_grid = *conf_grid; @@ -33,58 +34,57 @@ gkyl_dg_calc_em_vars_new(const struct gkyl_rect_grid *conf_grid, up->mem_range = *mem_range; up->wv_eqn = gkyl_wv_eqn_acquire(wv_eqn); - up->geom = gkyl_wave_geom_acquire(geom); + up->geom = gkyl_wave_geom_acquire(geom); if (is_ExB) { up->Ncomp = 3; up->em_calc_temp = choose_em_calc_num_ExB_kern(b_type, cdim, poly_order); up->em_set = choose_em_set_ExB_kern(b_type, cdim, poly_order); up->em_copy = choose_em_copy_ExB_kern(b_type, cdim, poly_order); - } - else { + } else { up->Ncomp = 6; up->em_calc_temp = choose_em_calc_BB_kern(b_type, cdim, poly_order); up->em_set = choose_em_set_bvar_kern(b_type, cdim, poly_order); - up->em_copy = choose_em_copy_bvar_kern(b_type, cdim, poly_order); + up->em_copy = choose_em_copy_bvar_kern(b_type, cdim, poly_order); // Fetch the kernels in each direction - for (int d=0; dem_div_b[d] = choose_em_div_b_kern(d, b_type, cdim, poly_order); + for (int d = 0; d < cdim; ++d) { + up->em_div_b[d] = choose_em_div_b_kern(d, b_type, cdim, poly_order); up->em_limiter[d] = choose_em_limiter_kern(d, b_type, cdim, poly_order); } } // Limiter factor for relationship between slopes and cell average differences // By default, this factor is 1/sqrt(3) because cell_avg(f) = f0/sqrt(2^cdim) - // and a cell slope estimate from two adjacent cells is (for the x variation): + // and a cell slope estimate from two adjacent cells is (for the x variation): // integral(psi_1 [cell_avg(f_{i+1}) - cell_avg(f_{i})]*x) = sqrt(2^cdim)/sqrt(3)*[cell_avg(f_{i+1}) - cell_avg(f_{i})] // where psi_1 is the x cell slope basis in our orthonormal expansion psi_1 = sqrt(3)/sqrt(2^cdim)*x // This factor can be made smaller (larger) to increase (decrease) the diffusion from the slope limiter if (limiter_fac == 0.0) { up->limiter_fac = 0.5773502691896258; - } - else { + } else { up->limiter_fac = limiter_fac; } - // There are Ncomp more linear systems to be solved + // There are Ncomp more linear systems to be solved // 6 components of bb and 3 components of E x B - up->As = gkyl_nmat_new(up->Ncomp*mem_range->volume, nc, nc); - up->xs = gkyl_nmat_new(up->Ncomp*mem_range->volume, nc, 1); + up->As = gkyl_nmat_new(up->Ncomp * mem_range->volume, nc, nc); + up->xs = gkyl_nmat_new(up->Ncomp * mem_range->volume, nc, 1); up->mem = gkyl_nmat_linsolve_lu_new(up->As->num, up->As->nr); - // 6 component temporary variable for either storing B_i B_j (for computing bb) + // 6 component temporary variable for either storing B_i B_j (for computing bb) // or (E x B)_i and B_i^2 (for computing E x B/|B|^2) - up->temp_var = gkyl_array_new(GKYL_DOUBLE, 6*nc, mem_range->volume); + up->temp_var = gkyl_array_new(GKYL_DOUBLE, 6 * nc, mem_range->volume); up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void gkyl_dg_calc_em_vars_advance(struct gkyl_dg_calc_em_vars *up, - const struct gkyl_array* em, struct gkyl_array* cell_avg_magB2, - struct gkyl_array* out, struct gkyl_array* out_surf) +void gkyl_dg_calc_em_vars_advance( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_array *em, struct gkyl_array *cell_avg_magB2, + struct gkyl_array *out, struct gkyl_array *out_surf +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(out)) { @@ -100,7 +100,7 @@ void gkyl_dg_calc_em_vars_advance(struct gkyl_dg_calc_em_vars *up, long loc = gkyl_range_idx(&up->mem_range, iter.idx); const double *em_d = gkyl_array_cfetch(em, loc); - int* cell_avg_magB2_d = gkyl_array_fetch(cell_avg_magB2, loc); + int *cell_avg_magB2_d = gkyl_array_fetch(cell_avg_magB2, loc); up->em_calc_temp(em_d, gkyl_array_fetch(up->temp_var, loc)); cell_avg_magB2_d[0] = up->em_set(count, up->As, up->xs, gkyl_array_cfetch(up->temp_var, loc)); @@ -126,12 +126,14 @@ void gkyl_dg_calc_em_vars_advance(struct gkyl_dg_calc_em_vars *up, up->em_copy(count, up->xs, em_d, cell_avg_magB2_d, out_d, out_surf_d); count += up->Ncomp; - } + } } -void gkyl_dg_calc_em_vars_div_b(struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* bvar_surf, const struct gkyl_array* bvar, - struct gkyl_array* max_b, struct gkyl_array* div_b) +void gkyl_dg_calc_em_vars_div_b( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *bvar_surf, const struct gkyl_array *bvar, struct gkyl_array *max_b, + struct gkyl_array *div_b +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(div_b)) { @@ -153,27 +155,29 @@ void gkyl_dg_calc_em_vars_div_b(struct gkyl_dg_calc_em_vars *up, const struct gk double *max_b_d = gkyl_array_fetch(max_b, linc); double *div_b_d = gkyl_array_fetch(div_b, linc); - for (int dir=0; direm_div_b[dir](up->conf_grid.dx, - bvar_surf_l, bvar_surf_c, bvar_surf_r, - bvar_d, max_b_d, div_b_d); + up->em_div_b[dir]( + up->conf_grid.dx, bvar_surf_l, bvar_surf_c, bvar_surf_r, bvar_d, max_b_d, div_b_d + ); } } } -void gkyl_dg_calc_em_vars_limiter(struct gkyl_dg_calc_em_vars *up, - const struct gkyl_range *conf_range, struct gkyl_array* em) +void gkyl_dg_calc_em_vars_limiter( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, struct gkyl_array *em +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(em)) { @@ -191,19 +195,20 @@ void gkyl_dg_calc_em_vars_limiter(struct gkyl_dg_calc_em_vars *up, const struct gkyl_wave_cell_geom *geom = gkyl_wave_geom_get(up->geom, idxc); double *em_c = gkyl_array_fetch(em, linc); - for (int dir=0; direm_limiter[dir](up->limiter_fac, up->wv_eqn, geom, em_l, em_c, em_r); + up->em_limiter[dir](up->limiter_fac, up->wv_eqn, geom, em_l, em_c, em_r); } } } @@ -217,8 +222,9 @@ void gkyl_dg_calc_em_vars_release(gkyl_dg_calc_em_vars *up) gkyl_nmat_release(up->xs); gkyl_nmat_linsolve_lu_release(up->mem); gkyl_array_release(up->temp_var); - - if (GKYL_IS_CU_ALLOC(up->flags)) + + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/vlasov/zero/dg_calc_em_vars_cu.cu b/vlasov/zero/dg_calc_em_vars_cu.cu index 8400a971e2..79e7e8b2ec 100644 --- a/vlasov/zero/dg_calc_em_vars_cu.cu +++ b/vlasov/zero/dg_calc_em_vars_cu.cu @@ -13,17 +13,16 @@ extern "C" { #include } -__global__ static void -gkyl_dg_calc_em_vars_set_cu_kernel(struct gkyl_dg_calc_em_vars* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* em, struct gkyl_array* cell_avg_magB2, struct gkyl_array* temp_var) +__global__ static void gkyl_dg_calc_em_vars_set_cu_kernel( + struct gkyl_dg_calc_em_vars *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, const struct gkyl_array *em, struct gkyl_array *cell_avg_magB2, + struct gkyl_array *temp_var +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -33,28 +32,27 @@ gkyl_dg_calc_em_vars_set_cu_kernel(struct gkyl_dg_calc_em_vars* up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->Ncomp; + long count = linc1 * up->Ncomp; - const double *em_d = (const double*) gkyl_array_cfetch(em, loc); - int *cell_avg_magB2_d = (int*) gkyl_array_fetch(cell_avg_magB2, loc); + const double *em_d = (const double *)gkyl_array_cfetch(em, loc); + int *cell_avg_magB2_d = (int *)gkyl_array_fetch(cell_avg_magB2, loc); - up->em_calc_temp(em_d, (double*) gkyl_array_fetch(temp_var, loc)); - cell_avg_magB2_d[0] = up->em_set(count, As, xs, (const double*) gkyl_array_cfetch(temp_var, loc)); + up->em_calc_temp(em_d, (double *)gkyl_array_fetch(temp_var, loc)); + cell_avg_magB2_d[0] = + up->em_set(count, As, xs, (const double *)gkyl_array_cfetch(temp_var, loc)); } } -__global__ static void -gkyl_dg_calc_em_vars_copy_cu_kernel(struct gkyl_dg_calc_em_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* em, struct gkyl_array* cell_avg_magB2, - struct gkyl_array* out, struct gkyl_array* out_surf) +__global__ static void gkyl_dg_calc_em_vars_copy_cu_kernel( + struct gkyl_dg_calc_em_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + const struct gkyl_array *em, struct gkyl_array *cell_avg_magB2, struct gkyl_array *out, + struct gkyl_array *out_surf +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -64,50 +62,50 @@ gkyl_dg_calc_em_vars_copy_cu_kernel(struct gkyl_dg_calc_em_vars* up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->Ncomp; + long count = linc1 * up->Ncomp; - const double *em_d = (const double*) gkyl_array_cfetch(em, loc); - int *cell_avg_magB2_d = (int*) gkyl_array_fetch(cell_avg_magB2, loc); - double *out_d = (double*) gkyl_array_fetch(out, loc); - double *out_surf_d = (double*) gkyl_array_fetch(out_surf, loc); + const double *em_d = (const double *)gkyl_array_cfetch(em, loc); + int *cell_avg_magB2_d = (int *)gkyl_array_fetch(cell_avg_magB2, loc); + double *out_d = (double *)gkyl_array_fetch(out, loc); + double *out_surf_d = (double *)gkyl_array_fetch(out_surf, loc); up->em_copy(count, xs, em_d, cell_avg_magB2_d, out_d, out_surf_d); } } -void gkyl_dg_calc_em_vars_advance_cu(struct gkyl_dg_calc_em_vars *up, - const struct gkyl_array* em, struct gkyl_array* cell_avg_magB2, - struct gkyl_array* out, struct gkyl_array* out_surf) +void gkyl_dg_calc_em_vars_advance_cu( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_array *em, struct gkyl_array *cell_avg_magB2, + struct gkyl_array *out, struct gkyl_array *out_surf +) { gkyl_array_clear(up->temp_var, 0.0); struct gkyl_range conf_range = up->mem_range; - - gkyl_dg_calc_em_vars_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, - em->on_dev, cell_avg_magB2->on_dev, up->temp_var->on_dev); + + gkyl_dg_calc_em_vars_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, em->on_dev, cell_avg_magB2->on_dev, + up->temp_var->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_dg_calc_em_vars_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, - em->on_dev, cell_avg_magB2->on_dev, - out->on_dev, out_surf->on_dev); + gkyl_dg_calc_em_vars_copy_cu_kernel<< > >( + up->on_dev, up->xs->on_dev, conf_range, em->on_dev, cell_avg_magB2->on_dev, out->on_dev, + out_surf->on_dev + ); } -__global__ void -gkyl_dg_calc_em_vars_div_b_cu_kernel(struct gkyl_dg_calc_em_vars *up, struct gkyl_range conf_range, - const struct gkyl_array* bvar_surf, const struct gkyl_array* bvar, - struct gkyl_array* max_b, struct gkyl_array* div_b) +__global__ void gkyl_dg_calc_em_vars_div_b_cu_kernel( + struct gkyl_dg_calc_em_vars *up, struct gkyl_range conf_range, const struct gkyl_array *bvar_surf, + const struct gkyl_array *bvar, struct gkyl_array *max_b, struct gkyl_array *div_b +) { int cdim = up->cdim; int idxl[GKYL_MAX_DIM], idxc[GKYL_MAX_DIM], idxr[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -117,123 +115,127 @@ gkyl_dg_calc_em_vars_div_b_cu_kernel(struct gkyl_dg_calc_em_vars *up, struct gky // linc will have jumps in it to jump over ghost cells long linc = gkyl_range_idx(&conf_range, idxc); - const double *bvar_surf_c = (const double*) gkyl_array_cfetch(bvar_surf, linc); - const double *bvar_d = (const double*) gkyl_array_cfetch(bvar, linc); + const double *bvar_surf_c = (const double *)gkyl_array_cfetch(bvar_surf, linc); + const double *bvar_d = (const double *)gkyl_array_cfetch(bvar, linc); - double *max_b_d = (double*) gkyl_array_fetch(max_b, linc); - double *div_b_d = (double*) gkyl_array_fetch(div_b, linc); + double *max_b_d = (double *)gkyl_array_fetch(max_b, linc); + double *div_b_d = (double *)gkyl_array_fetch(div_b, linc); - for (int dir=0; direm_div_b[dir](up->conf_grid.dx, - bvar_surf_l, bvar_surf_c, bvar_surf_r, - bvar_d, max_b_d, div_b_d); + const double *bvar_surf_l = (const double *)gkyl_array_cfetch(bvar_surf, linl); + const double *bvar_surf_r = (const double *)gkyl_array_cfetch(bvar_surf, linr); + + up->em_div_b[dir]( + up->conf_grid.dx, bvar_surf_l, bvar_surf_c, bvar_surf_r, bvar_d, max_b_d, div_b_d + ); } } } -// Host-side wrapper for div(b) and max(|b_i|) variable calculations -void -gkyl_dg_calc_em_vars_div_b_cu(struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* bvar_surf, const struct gkyl_array* bvar, - struct gkyl_array* max_b, struct gkyl_array* div_b) +// Host-side wrapper for div(b) and max(|b_i|) variable calculations +void gkyl_dg_calc_em_vars_div_b_cu( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *bvar_surf, const struct gkyl_array *bvar, struct gkyl_array *max_b, + struct gkyl_array *div_b +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_em_vars_div_b_cu_kernel<<>>(up->on_dev, *conf_range, - bvar_surf->on_dev, bvar->on_dev, - max_b->on_dev, div_b->on_dev); + gkyl_dg_calc_em_vars_div_b_cu_kernel<< > >( + up->on_dev, *conf_range, bvar_surf->on_dev, bvar->on_dev, max_b->on_dev, div_b->on_dev + ); } -__global__ void -gkyl_dg_calc_em_vars_limiter_cu_kernel(struct gkyl_dg_calc_em_vars *up, struct gkyl_range conf_range, - struct gkyl_array* em) +__global__ void gkyl_dg_calc_em_vars_limiter_cu_kernel( + struct gkyl_dg_calc_em_vars *up, struct gkyl_range conf_range, struct gkyl_array *em +) { int cdim = up->cdim; int idxl[GKYL_MAX_DIM], idxc[GKYL_MAX_DIM], idxr[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange gkyl_sub_range_inv_idx(&conf_range, linc1, idxc); - const struct gkyl_wave_cell_geom *geom = gkyl_wave_geom_get(up->geom, idxc); + const struct gkyl_wave_cell_geom *geom = gkyl_wave_geom_get(up->geom, idxc); // convert back to a linear index on the super-range (with ghost cells) // linc will have jumps in it to jump over ghost cells long linc = gkyl_range_idx(&conf_range, idxc); - double *em_c = (double*) gkyl_array_fetch(em, linc); + double *em_c = (double *)gkyl_array_fetch(em, linc); - for (int dir=0; direm_limiter[dir](up->limiter_fac, up->wv_eqn, geom, em_l, em_c, em_r); } } } // Host-side wrapper for slope limiter of em variables -void -gkyl_dg_calc_em_vars_limiter_cu(struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, - struct gkyl_array* em) +void gkyl_dg_calc_em_vars_limiter_cu( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, struct gkyl_array *em +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_em_vars_limiter_cu_kernel<<>>(up->on_dev, *conf_range, em->on_dev); + gkyl_dg_calc_em_vars_limiter_cu_kernel<< > >( + up->on_dev, *conf_range, em->on_dev + ); } // CUDA kernel to set device pointers to em vars kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_calc_em_vars_set_cu_dev_ptrs(struct gkyl_dg_calc_em_vars *up, enum gkyl_basis_type b_type, - int cdim, int poly_order, bool is_ExB) +__global__ static void dg_calc_em_vars_set_cu_dev_ptrs( + struct gkyl_dg_calc_em_vars *up, enum gkyl_basis_type b_type, int cdim, int poly_order, + bool is_ExB +) { if (is_ExB) { up->em_calc_temp = choose_em_calc_num_ExB_kern(b_type, cdim, poly_order); up->em_set = choose_em_set_ExB_kern(b_type, cdim, poly_order); up->em_copy = choose_em_copy_ExB_kern(b_type, cdim, poly_order); - } - else { + } else { up->em_calc_temp = choose_em_calc_BB_kern(b_type, cdim, poly_order); up->em_set = choose_em_set_bvar_kern(b_type, cdim, poly_order); - up->em_copy = choose_em_copy_bvar_kern(b_type, cdim, poly_order); + up->em_copy = choose_em_copy_bvar_kern(b_type, cdim, poly_order); // Fetch the kernels in each direction - for (int d=0; dem_div_b[d] = choose_em_div_b_kern(d, b_type, cdim, poly_order); - up->em_limiter[d] = choose_em_limiter_kern(d, b_type, cdim, poly_order); + for (int d = 0; d < cdim; ++d) { + up->em_div_b[d] = choose_em_div_b_kern(d, b_type, cdim, poly_order); + up->em_limiter[d] = choose_em_limiter_kern(d, b_type, cdim, poly_order); } } } -gkyl_dg_calc_em_vars* -gkyl_dg_calc_em_vars_cu_dev_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *wg, - double limiter_fac, bool is_ExB) +gkyl_dg_calc_em_vars *gkyl_dg_calc_em_vars_cu_dev_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *cbasis, + const struct gkyl_range *mem_range, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_geom *wg, double limiter_fac, bool is_ExB +) { - struct gkyl_dg_calc_em_vars *up = (struct gkyl_dg_calc_em_vars*) gkyl_malloc(sizeof(gkyl_dg_calc_em_vars)); + struct gkyl_dg_calc_em_vars *up = + (struct gkyl_dg_calc_em_vars *)gkyl_malloc(sizeof(gkyl_dg_calc_em_vars)); up->conf_grid = *conf_grid; int nc = cbasis->num_basis; @@ -254,46 +256,45 @@ gkyl_dg_calc_em_vars_cu_dev_new(const struct gkyl_rect_grid *conf_grid, if (is_ExB) { up->Ncomp = 3; - } - else { + } else { up->Ncomp = 6; } // Limiter factor for relationship between slopes and cell average differences // By default, this factor is 1/sqrt(3) because cell_avg(f) = f0/sqrt(2^cdim) - // and a cell slope estimate from two adjacent cells is (for the x variation): + // and a cell slope estimate from two adjacent cells is (for the x variation): // integral(psi_1 [cell_avg(f_{i+1}) - cell_avg(f_{i})]*x) = sqrt(2^cdim)/sqrt(3)*[cell_avg(f_{i+1}) - cell_avg(f_{i})] // where psi_1 is the x cell slope basis in our orthonormal expansion psi_1 = sqrt(3)/sqrt(2^cdim)*x // This factor can be made smaller (larger) to increase (decrease) the diffusion from the slope limiter if (limiter_fac == 0.0) { up->limiter_fac = 0.5773502691896258; - } - else { + } else { up->limiter_fac = limiter_fac; } - // There are Ncomp more linear systems to be solved + // There are Ncomp more linear systems to be solved // 6 components of bb and 3 components of E x B - up->As = gkyl_nmat_cu_dev_new(up->Ncomp*mem_range->volume, nc, nc); - up->xs = gkyl_nmat_cu_dev_new(up->Ncomp*mem_range->volume, nc, 1); + up->As = gkyl_nmat_cu_dev_new(up->Ncomp * mem_range->volume, nc, nc); + up->xs = gkyl_nmat_cu_dev_new(up->Ncomp * mem_range->volume, nc, 1); up->mem = gkyl_nmat_linsolve_lu_cu_dev_new(up->As->num, up->As->nr); - // 6 component temporary variable for either storing B_i B_j (for computing bb) + // 6 component temporary variable for either storing B_i B_j (for computing bb) // or (E x B)_i and B_i^2 (for computing E x B/|B|^2) - up->temp_var = gkyl_array_cu_dev_new(GKYL_DOUBLE, 6*nc, mem_range->volume); + up->temp_var = gkyl_array_cu_dev_new(GKYL_DOUBLE, 6 * nc, mem_range->volume); up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_calc_em_vars *up_cu = (struct gkyl_dg_calc_em_vars*) gkyl_cu_malloc(sizeof(gkyl_dg_calc_em_vars)); + struct gkyl_dg_calc_em_vars *up_cu = + (struct gkyl_dg_calc_em_vars *)gkyl_cu_malloc(sizeof(gkyl_dg_calc_em_vars)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_calc_em_vars), GKYL_CU_MEMCPY_H2D); - dg_calc_em_vars_set_cu_dev_ptrs<<<1,1>>>(up_cu, b_type, cdim, poly_order, is_ExB); + dg_calc_em_vars_set_cu_dev_ptrs<<<1, 1> > >(up_cu, b_type, cdim, poly_order, is_ExB); // set parent on_dev pointer up->on_dev = up_cu; - up->wv_eqn = eqn; // updater should store host pointer - up->geom = geom; - + up->wv_eqn = eqn; // updater should store host pointer + up->geom = geom; + return up; } diff --git a/vlasov/zero/dg_calc_fluid_em_coupling.c b/vlasov/zero/dg_calc_fluid_em_coupling.c index a6f5054841..d3dfc1127b 100644 --- a/vlasov/zero/dg_calc_fluid_em_coupling.c +++ b/vlasov/zero/dg_calc_fluid_em_coupling.c @@ -8,18 +8,16 @@ #include #include -struct gkyl_dg_calc_fluid_em_coupling* -gkyl_dg_calc_fluid_em_coupling_new(const struct gkyl_basis* cbasis, - const struct gkyl_range *mem_range, - int num_fluids, double qbym[GKYL_MAX_SPECIES], double epsilon0, - bool use_gpu) +struct gkyl_dg_calc_fluid_em_coupling *gkyl_dg_calc_fluid_em_coupling_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, int num_fluids, + double qbym[GKYL_MAX_SPECIES], double epsilon0, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { - return gkyl_dg_calc_fluid_em_coupling_cu_dev_new(cbasis, mem_range, - num_fluids, qbym, epsilon0); - } -#endif + if (use_gpu) { + return gkyl_dg_calc_fluid_em_coupling_cu_dev_new(cbasis, mem_range, num_fluids, qbym, epsilon0); + } +#endif gkyl_dg_calc_fluid_em_coupling *up = gkyl_malloc(sizeof(gkyl_dg_calc_fluid_em_coupling)); int nc = cbasis->num_basis; @@ -36,8 +34,9 @@ gkyl_dg_calc_fluid_em_coupling_new(const struct gkyl_basis* cbasis, // Linear system size is nc*(3*num_fluids + 3) up->num_fluids = num_fluids; - up->As = gkyl_nmat_new(mem_range->volume, nc*(3*up->num_fluids + 3), nc*(3*up->num_fluids + 3)); - up->xs = gkyl_nmat_new(mem_range->volume, nc*(3*up->num_fluids + 3), 1); + up->As = + gkyl_nmat_new(mem_range->volume, nc * (3 * up->num_fluids + 3), nc * (3 * up->num_fluids + 3)); + up->xs = gkyl_nmat_new(mem_range->volume, nc * (3 * up->num_fluids + 3), 1); up->mem = gkyl_nmat_linsolve_lu_new(up->As->num, up->As->nr); // Needed constants for the source solve @@ -49,20 +48,22 @@ gkyl_dg_calc_fluid_em_coupling_new(const struct gkyl_basis* cbasis, up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void -gkyl_dg_calc_fluid_em_coupling_advance(struct gkyl_dg_calc_fluid_em_coupling *up, double dt, - const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - struct gkyl_array* fluid[GKYL_MAX_SPECIES], struct gkyl_array* em) +void gkyl_dg_calc_fluid_em_coupling_advance( + struct gkyl_dg_calc_fluid_em_coupling *up, double dt, + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], const struct gkyl_array *ext_em, + const struct gkyl_array *app_current, struct gkyl_array *fluid[GKYL_MAX_SPECIES], + struct gkyl_array *em +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(em)) { - return gkyl_dg_calc_fluid_em_coupling_advance_cu(up, - dt, app_accel, ext_em, app_current, fluid, em); + return gkyl_dg_calc_fluid_em_coupling_advance_cu( + up, dt, app_accel, ext_em, app_current, fluid, em + ); } #endif int num_fluids = up->num_fluids; @@ -76,7 +77,7 @@ gkyl_dg_calc_fluid_em_coupling_advance(struct gkyl_dg_calc_fluid_em_coupling *up while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&up->mem_range, iter.idx); - for (int n=0; nfluid_em_coupling_set(count, up->num_fluids, up->qbym, up->epsilon0, dt, - up->As, up->xs, - app_accels, ext_em_d, app_current_d, - fluids, em_d); + up->fluid_em_coupling_set( + count, up->num_fluids, up->qbym, up->epsilon0, dt, up->As, up->xs, app_accels, ext_em_d, + app_current_d, fluids, em_d + ); count += 1; } @@ -100,28 +101,27 @@ gkyl_dg_calc_fluid_em_coupling_advance(struct gkyl_dg_calc_fluid_em_coupling *up while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&up->mem_range, iter.idx); - for (int n=0; nfluid_em_coupling_copy(count, up->num_fluids, up->qbym, up->epsilon0, - up->xs, fluids, em_d); + up->fluid_em_coupling_copy(count, up->num_fluids, up->qbym, up->epsilon0, up->xs, fluids, em_d); count += 1; } } -void -gkyl_dg_calc_fluid_em_coupling_energy(struct gkyl_dg_calc_fluid_em_coupling *up, - const struct gkyl_array* ke_old, const struct gkyl_array* ke_new, struct gkyl_array* fluid) +void gkyl_dg_calc_fluid_em_coupling_energy( + struct gkyl_dg_calc_fluid_em_coupling *up, const struct gkyl_array *ke_old, + const struct gkyl_array *ke_new, struct gkyl_array *fluid +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(fluid)) { - return gkyl_dg_calc_fluid_em_coupling_energy_cu(up, - ke_old, ke_new, fluid); + return gkyl_dg_calc_fluid_em_coupling_energy_cu(up, ke_old, ke_new, fluid); } -#endif +#endif struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &up->mem_range); while (gkyl_range_iter_next(&iter)) { @@ -136,15 +136,15 @@ gkyl_dg_calc_fluid_em_coupling_energy(struct gkyl_dg_calc_fluid_em_coupling *up, } } -void -gkyl_dg_calc_fluid_em_coupling_release(gkyl_dg_calc_fluid_em_coupling *up) +void gkyl_dg_calc_fluid_em_coupling_release(gkyl_dg_calc_fluid_em_coupling *up) { gkyl_nmat_release(up->As); gkyl_nmat_release(up->xs); gkyl_nmat_linsolve_lu_release(up->mem); - - if (GKYL_IS_CU_ALLOC(up->flags)) + + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/vlasov/zero/dg_calc_fluid_em_coupling_cu.cu b/vlasov/zero/dg_calc_fluid_em_coupling_cu.cu index 9aa39220a7..55a90cd0be 100644 --- a/vlasov/zero/dg_calc_fluid_em_coupling_cu.cu +++ b/vlasov/zero/dg_calc_fluid_em_coupling_cu.cu @@ -13,22 +13,20 @@ extern "C" { #include } -__global__ static void -gkyl_dg_calc_fluid_em_coupling_set_one_fluid_cu_kernel(gkyl_dg_calc_fluid_em_coupling* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, double dt, - const struct gkyl_array* app_accel, - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - struct gkyl_array* fluid, struct gkyl_array* em) +__global__ static void gkyl_dg_calc_fluid_em_coupling_set_one_fluid_cu_kernel( + gkyl_dg_calc_fluid_em_coupling *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, double dt, const struct gkyl_array *app_accel, + const struct gkyl_array *ext_em, const struct gkyl_array *app_current, struct gkyl_array *fluid, + struct gkyl_array *em +) { int num_fluids = up->num_fluids; double *fluids[GKYL_MAX_SPECIES]; - const double *app_accels[GKYL_MAX_SPECIES]; + const double *app_accels[GKYL_MAX_SPECIES]; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -38,30 +36,30 @@ gkyl_dg_calc_fluid_em_coupling_set_one_fluid_cu_kernel(gkyl_dg_calc_fluid_em_cou // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - fluids[0] = (double*) gkyl_array_fetch(fluid, loc); - app_accels[0] = (const double*) gkyl_array_cfetch(app_accel, loc); - const double *ext_em_d = (const double*) gkyl_array_cfetch(ext_em, loc); - const double *app_current_d = (const double*) gkyl_array_cfetch(app_current, loc); - double *em_d = (double*) gkyl_array_fetch(em, loc); + fluids[0] = (double *)gkyl_array_fetch(fluid, loc); + app_accels[0] = (const double *)gkyl_array_cfetch(app_accel, loc); + const double *ext_em_d = (const double *)gkyl_array_cfetch(ext_em, loc); + const double *app_current_d = (const double *)gkyl_array_cfetch(app_current, loc); + double *em_d = (double *)gkyl_array_fetch(em, loc); - up->fluid_em_coupling_set(linc1, up->num_fluids, up->qbym, up->epsilon0, dt, - As, xs, app_accels, ext_em_d, app_current_d, fluids, em_d); + up->fluid_em_coupling_set( + linc1, up->num_fluids, up->qbym, up->epsilon0, dt, As, xs, app_accels, ext_em_d, + app_current_d, fluids, em_d + ); } } -__global__ static void -gkyl_dg_calc_fluid_em_coupling_copy_one_fluid_cu_kernel(gkyl_dg_calc_fluid_em_coupling* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, - struct gkyl_array* fluid, struct gkyl_array* em) +__global__ static void gkyl_dg_calc_fluid_em_coupling_copy_one_fluid_cu_kernel( + gkyl_dg_calc_fluid_em_coupling *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + struct gkyl_array *fluid, struct gkyl_array *em +) { int num_fluids = up->num_fluids; - double *fluids[GKYL_MAX_SPECIES]; + double *fluids[GKYL_MAX_SPECIES]; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -71,30 +69,28 @@ gkyl_dg_calc_fluid_em_coupling_copy_one_fluid_cu_kernel(gkyl_dg_calc_fluid_em_co // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - fluids[0] = (double*) gkyl_array_fetch(fluid, loc); - double *em_d = (double*) gkyl_array_fetch(em, loc); + fluids[0] = (double *)gkyl_array_fetch(fluid, loc); + double *em_d = (double *)gkyl_array_fetch(em, loc); - up->fluid_em_coupling_copy(linc1, up->num_fluids, up->qbym, up->epsilon0, - xs, fluids, em_d); + up->fluid_em_coupling_copy(linc1, up->num_fluids, up->qbym, up->epsilon0, xs, fluids, em_d); } } -__global__ static void -gkyl_dg_calc_fluid_em_coupling_set_two_fluids_cu_kernel(gkyl_dg_calc_fluid_em_coupling* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, double dt, - const struct gkyl_array* app_accel_1, const struct gkyl_array* app_accel_2, - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - struct gkyl_array* fluid_1, struct gkyl_array* fluid_2, struct gkyl_array* em) +__global__ static void gkyl_dg_calc_fluid_em_coupling_set_two_fluids_cu_kernel( + gkyl_dg_calc_fluid_em_coupling *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, double dt, const struct gkyl_array *app_accel_1, + const struct gkyl_array *app_accel_2, const struct gkyl_array *ext_em, + const struct gkyl_array *app_current, struct gkyl_array *fluid_1, struct gkyl_array *fluid_2, + struct gkyl_array *em +) { int num_fluids = up->num_fluids; double *fluids[GKYL_MAX_SPECIES]; - const double *app_accels[GKYL_MAX_SPECIES]; + const double *app_accels[GKYL_MAX_SPECIES]; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -104,32 +100,32 @@ gkyl_dg_calc_fluid_em_coupling_set_two_fluids_cu_kernel(gkyl_dg_calc_fluid_em_co // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - fluids[0] = (double*) gkyl_array_fetch(fluid_1, loc); - fluids[1] = (double*) gkyl_array_fetch(fluid_2, loc); - app_accels[0] = (const double*) gkyl_array_cfetch(app_accel_1, loc); - app_accels[1] = (const double*) gkyl_array_cfetch(app_accel_2, loc); - const double *ext_em_d = (const double*) gkyl_array_cfetch(ext_em, loc); - const double *app_current_d = (const double*) gkyl_array_cfetch(app_current, loc); - double *em_d = (double*) gkyl_array_fetch(em, loc); - - up->fluid_em_coupling_set(linc1, up->num_fluids, up->qbym, up->epsilon0, dt, - As, xs, app_accels, ext_em_d, app_current_d, fluids, em_d); + fluids[0] = (double *)gkyl_array_fetch(fluid_1, loc); + fluids[1] = (double *)gkyl_array_fetch(fluid_2, loc); + app_accels[0] = (const double *)gkyl_array_cfetch(app_accel_1, loc); + app_accels[1] = (const double *)gkyl_array_cfetch(app_accel_2, loc); + const double *ext_em_d = (const double *)gkyl_array_cfetch(ext_em, loc); + const double *app_current_d = (const double *)gkyl_array_cfetch(app_current, loc); + double *em_d = (double *)gkyl_array_fetch(em, loc); + + up->fluid_em_coupling_set( + linc1, up->num_fluids, up->qbym, up->epsilon0, dt, As, xs, app_accels, ext_em_d, + app_current_d, fluids, em_d + ); } } -__global__ static void -gkyl_dg_calc_fluid_em_coupling_copy_two_fluids_cu_kernel(gkyl_dg_calc_fluid_em_coupling* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, - struct gkyl_array* fluid_1, struct gkyl_array* fluid_2, struct gkyl_array* em) +__global__ static void gkyl_dg_calc_fluid_em_coupling_copy_two_fluids_cu_kernel( + gkyl_dg_calc_fluid_em_coupling *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + struct gkyl_array *fluid_1, struct gkyl_array *fluid_2, struct gkyl_array *em +) { int num_fluids = up->num_fluids; - double *fluids[GKYL_MAX_SPECIES]; + double *fluids[GKYL_MAX_SPECIES]; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -139,62 +135,66 @@ gkyl_dg_calc_fluid_em_coupling_copy_two_fluids_cu_kernel(gkyl_dg_calc_fluid_em_c // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - fluids[0] = (double*) gkyl_array_fetch(fluid_1, loc); - fluids[1] = (double*) gkyl_array_fetch(fluid_2, loc); - double *em_d = (double*) gkyl_array_fetch(em, loc); + fluids[0] = (double *)gkyl_array_fetch(fluid_1, loc); + fluids[1] = (double *)gkyl_array_fetch(fluid_2, loc); + double *em_d = (double *)gkyl_array_fetch(em, loc); - up->fluid_em_coupling_copy(linc1, up->num_fluids, up->qbym, up->epsilon0, - xs, fluids, em_d); + up->fluid_em_coupling_copy(linc1, up->num_fluids, up->qbym, up->epsilon0, xs, fluids, em_d); } } // Host-side wrapper for primitive variable calculation -void gkyl_dg_calc_fluid_em_coupling_advance_cu(struct gkyl_dg_calc_fluid_em_coupling *up, double dt, - const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - struct gkyl_array* fluid[GKYL_MAX_SPECIES], struct gkyl_array* em) +void gkyl_dg_calc_fluid_em_coupling_advance_cu( + struct gkyl_dg_calc_fluid_em_coupling *up, double dt, + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], const struct gkyl_array *ext_em, + const struct gkyl_array *app_current, struct gkyl_array *fluid[GKYL_MAX_SPECIES], + struct gkyl_array *em +) { struct gkyl_range conf_range = up->mem_range; int num_fluids = up->num_fluids; if (num_fluids == 1) { - gkyl_dg_calc_fluid_em_coupling_set_one_fluid_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, dt, - app_accel[0]->on_dev, ext_em->on_dev, app_current->on_dev, - fluid[0]->on_dev, em->on_dev); - } - else if (num_fluids == 2) { - gkyl_dg_calc_fluid_em_coupling_set_two_fluids_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, dt, - app_accel[0]->on_dev, app_accel[1]->on_dev, ext_em->on_dev, app_current->on_dev, - fluid[0]->on_dev, fluid[1]->on_dev, em->on_dev); + gkyl_dg_calc_fluid_em_coupling_set_one_fluid_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, dt, app_accel[0]->on_dev, + ext_em->on_dev, app_current->on_dev, fluid[0]->on_dev, em->on_dev + ); + } else if (num_fluids == 2) { + gkyl_dg_calc_fluid_em_coupling_set_two_fluids_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, dt, app_accel[0]->on_dev, + app_accel[1]->on_dev, ext_em->on_dev, app_current->on_dev, fluid[0]->on_dev, fluid[1]->on_dev, + em->on_dev + ); } bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); if (num_fluids == 1) { - gkyl_dg_calc_fluid_em_coupling_copy_one_fluid_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, fluid[0]->on_dev, em->on_dev); - } - else if (num_fluids == 2) { - gkyl_dg_calc_fluid_em_coupling_copy_two_fluids_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, fluid[0]->on_dev, fluid[1]->on_dev, em->on_dev); + gkyl_dg_calc_fluid_em_coupling_copy_one_fluid_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->xs->on_dev, conf_range, fluid[0]->on_dev, em->on_dev + ); + } else if (num_fluids == 2) { + gkyl_dg_calc_fluid_em_coupling_copy_two_fluids_cu_kernel<<< + conf_range.nblocks, conf_range.nthreads> > >( + up->on_dev, up->xs->on_dev, conf_range, fluid[0]->on_dev, fluid[1]->on_dev, em->on_dev + ); } } -__global__ void -gkyl_calc_fluid_em_coupling_energy_cu_kernel(struct gkyl_dg_calc_fluid_em_coupling *up, - struct gkyl_range conf_range, - const struct gkyl_array* ke_old, const struct gkyl_array* ke_new, struct gkyl_array* fluid) -{ +__global__ void gkyl_calc_fluid_em_coupling_energy_cu_kernel( + struct gkyl_dg_calc_fluid_em_coupling *up, struct gkyl_range conf_range, + const struct gkyl_array *ke_old, const struct gkyl_array *ke_new, struct gkyl_array *fluid +) +{ int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -204,42 +204,46 @@ gkyl_calc_fluid_em_coupling_energy_cu_kernel(struct gkyl_dg_calc_fluid_em_coupli // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *ke_old_d = (const double*) gkyl_array_cfetch(ke_old, loc); - const double *ke_new_d = (const double*) gkyl_array_cfetch(ke_new, loc); + const double *ke_old_d = (const double *)gkyl_array_cfetch(ke_old, loc); + const double *ke_new_d = (const double *)gkyl_array_cfetch(ke_new, loc); - double *fluid_d = (double*) gkyl_array_fetch(fluid, loc); + double *fluid_d = (double *)gkyl_array_fetch(fluid, loc); up->fluid_em_coupling_energy(ke_old_d, ke_new_d, fluid_d); } } // Host-side wrapper for kinetic energy calculation -void gkyl_dg_calc_fluid_em_coupling_energy_cu(struct gkyl_dg_calc_fluid_em_coupling *up, - const struct gkyl_array* ke_old, const struct gkyl_array* ke_new, struct gkyl_array* fluid) +void gkyl_dg_calc_fluid_em_coupling_energy_cu( + struct gkyl_dg_calc_fluid_em_coupling *up, const struct gkyl_array *ke_old, + const struct gkyl_array *ke_new, struct gkyl_array *fluid +) { struct gkyl_range conf_range = up->mem_range; - gkyl_calc_fluid_em_coupling_energy_cu_kernel<<>>(up->on_dev, - conf_range, ke_old->on_dev, ke_new->on_dev, fluid->on_dev); + gkyl_calc_fluid_em_coupling_energy_cu_kernel<< > >( + up->on_dev, conf_range, ke_old->on_dev, ke_new->on_dev, fluid->on_dev + ); } // CUDA kernel to set device pointers to fluid vars kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_calc_fluid_em_coupling_set_cu_dev_ptrs(struct gkyl_dg_calc_fluid_em_coupling *up, - enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ static void dg_calc_fluid_em_coupling_set_cu_dev_ptrs( + struct gkyl_dg_calc_fluid_em_coupling *up, enum gkyl_basis_type b_type, int cdim, int poly_order +) { up->fluid_em_coupling_set = choose_fluid_em_coupling_set_kern(b_type, cdim, poly_order); up->fluid_em_coupling_copy = choose_fluid_em_coupling_copy_kern(b_type, cdim, poly_order); up->fluid_em_coupling_energy = choose_fluid_em_coupling_energy_kern(b_type, cdim, poly_order); } -gkyl_dg_calc_fluid_em_coupling* -gkyl_dg_calc_fluid_em_coupling_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_range *mem_range, - int num_fluids, double qbym[GKYL_MAX_SPECIES], double epsilon0) +gkyl_dg_calc_fluid_em_coupling *gkyl_dg_calc_fluid_em_coupling_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, int num_fluids, + double qbym[GKYL_MAX_SPECIES], double epsilon0 +) { - struct gkyl_dg_calc_fluid_em_coupling *up = (struct gkyl_dg_calc_fluid_em_coupling*) gkyl_malloc(sizeof(gkyl_dg_calc_fluid_em_coupling)); + struct gkyl_dg_calc_fluid_em_coupling *up = + (struct gkyl_dg_calc_fluid_em_coupling *)gkyl_malloc(sizeof(gkyl_dg_calc_fluid_em_coupling)); int nc = cbasis->num_basis; int cdim = cbasis->ndim; @@ -251,8 +255,10 @@ gkyl_dg_calc_fluid_em_coupling_cu_dev_new(const struct gkyl_basis* cbasis, // Linear system size is nc*(3*num_fluids + 3) up->num_fluids = num_fluids; - up->As = gkyl_nmat_cu_dev_new(mem_range->volume, nc*(3*up->num_fluids + 3), nc*(3*up->num_fluids + 3)); - up->xs = gkyl_nmat_cu_dev_new(mem_range->volume, nc*(3*up->num_fluids + 3), 1); + up->As = gkyl_nmat_cu_dev_new( + mem_range->volume, nc * (3 * up->num_fluids + 3), nc * (3 * up->num_fluids + 3) + ); + up->xs = gkyl_nmat_cu_dev_new(mem_range->volume, nc * (3 * up->num_fluids + 3), 1); up->mem = gkyl_nmat_linsolve_lu_cu_dev_new(up->As->num, up->As->nr); // Needed constants for the source solve @@ -264,10 +270,11 @@ gkyl_dg_calc_fluid_em_coupling_cu_dev_new(const struct gkyl_basis* cbasis, up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_calc_fluid_em_coupling *up_cu = (struct gkyl_dg_calc_fluid_em_coupling*) gkyl_cu_malloc(sizeof(gkyl_dg_calc_fluid_em_coupling)); + struct gkyl_dg_calc_fluid_em_coupling *up_cu = + (struct gkyl_dg_calc_fluid_em_coupling *)gkyl_cu_malloc(sizeof(gkyl_dg_calc_fluid_em_coupling)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_calc_fluid_em_coupling), GKYL_CU_MEMCPY_H2D); - dg_calc_fluid_em_coupling_set_cu_dev_ptrs<<<1,1>>>(up_cu, b_type, cdim, poly_order); + dg_calc_fluid_em_coupling_set_cu_dev_ptrs<<<1, 1> > >(up_cu, b_type, cdim, poly_order); // set parent on_dev pointer up->on_dev = up_cu; diff --git a/vlasov/zero/dg_calc_fluid_vars.c b/vlasov/zero/dg_calc_fluid_vars.c index 3d715c1107..39aed3b67a 100644 --- a/vlasov/zero/dg_calc_fluid_vars.c +++ b/vlasov/zero/dg_calc_fluid_vars.c @@ -10,23 +10,25 @@ #include #include -gkyl_dg_calc_fluid_vars* -gkyl_dg_calc_fluid_vars_new(const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, - const struct gkyl_basis* cbasis, const struct gkyl_range *mem_range, - double limiter_fac, bool use_gpu) +gkyl_dg_calc_fluid_vars *gkyl_dg_calc_fluid_vars_new( + const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, double limiter_fac, + bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_calc_fluid_vars_cu_dev_new(wv_eqn, geom, cbasis, mem_range, limiter_fac); - } -#endif + } +#endif gkyl_dg_calc_fluid_vars *up = gkyl_malloc(sizeof(gkyl_dg_calc_fluid_vars)); up->eqn_type = wv_eqn->type; up->wv_eqn = gkyl_wv_eqn_acquire(wv_eqn); - up->geom = gkyl_wave_geom_acquire(geom); - if (up->eqn_type == GKYL_EQN_EULER) + up->geom = gkyl_wave_geom_acquire(geom); + if (up->eqn_type == GKYL_EQN_EULER) { up->param = gkyl_wv_euler_gas_gamma(up->wv_eqn); + } int nc = cbasis->num_basis; int cdim = cbasis->ndim; @@ -44,40 +46,43 @@ gkyl_dg_calc_fluid_vars_new(const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_ up->fluid_int = choose_fluid_int_kern(b_type, cdim, poly_order); up->fluid_source = choose_fluid_source_kern(b_type, cdim, poly_order); // Fetch the kernels in each direction - for (int d=0; dfluid_limiter[d] = choose_fluid_limiter_kern(d, b_type, cdim, poly_order); + } // Limiter factor for relationship between slopes and cell average differences // By default, this factor is 1/sqrt(3) because cell_avg(f) = f0/sqrt(2^cdim) - // and a cell slope estimate from two adjacent cells is (for the x variation): + // and a cell slope estimate from two adjacent cells is (for the x variation): // integral(psi_1 [cell_avg(f_{i+1}) - cell_avg(f_{i})]*x) = sqrt(2^cdim)/sqrt(3)*[cell_avg(f_{i+1}) - cell_avg(f_{i})] // where psi_1 is the x cell slope basis in our orthonormal expansion psi_1 = sqrt(3)/sqrt(2^cdim)*x // This factor can be made smaller (larger) to increase (decrease) the diffusion from the slope limiter - if (limiter_fac == 0.0) + if (limiter_fac == 0.0) { up->limiter_fac = 0.5773502691896258; - else + } else { up->limiter_fac = limiter_fac; + } - // There are Ncomp*range->volume linear systems to be solved - // 3 components: ux, uy, uz, - up->As = gkyl_nmat_new(up->Ncomp*mem_range->volume, nc, nc); - up->xs = gkyl_nmat_new(up->Ncomp*mem_range->volume, nc, 1); + // There are Ncomp*range->volume linear systems to be solved + // 3 components: ux, uy, uz, + up->As = gkyl_nmat_new(up->Ncomp * mem_range->volume, nc, nc); + up->xs = gkyl_nmat_new(up->Ncomp * mem_range->volume, nc, 1); up->mem = gkyl_nmat_linsolve_lu_new(up->As->num, up->As->nr); up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void gkyl_dg_calc_fluid_vars_advance(struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_array* fluid, - struct gkyl_array* cell_avg_prim, struct gkyl_array* u, struct gkyl_array* u_surf) +void gkyl_dg_calc_fluid_vars_advance( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_array *fluid, + struct gkyl_array *cell_avg_prim, struct gkyl_array *u, struct gkyl_array *u_surf +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(u)) { - return gkyl_dg_calc_fluid_vars_advance_cu(up, - fluid, cell_avg_prim, u, u_surf); + return gkyl_dg_calc_fluid_vars_advance_cu(up, fluid, cell_avg_prim, u, u_surf); } #endif @@ -90,7 +95,7 @@ void gkyl_dg_calc_fluid_vars_advance(struct gkyl_dg_calc_fluid_vars *up, const s const double *fluid_d = gkyl_array_cfetch(fluid, loc); - int* cell_avg_prim_d = gkyl_array_fetch(cell_avg_prim, loc); + int *cell_avg_prim_d = gkyl_array_fetch(cell_avg_prim, loc); cell_avg_prim_d[0] = up->fluid_set(count, up->As, up->xs, fluid_d); @@ -107,8 +112,8 @@ void gkyl_dg_calc_fluid_vars_advance(struct gkyl_dg_calc_fluid_vars *up, const s while (gkyl_range_iter_next(&iter)) { long loc = gkyl_range_idx(&up->mem_range, iter.idx); - double* u_d = gkyl_array_fetch(u, loc); - double* u_surf_d = gkyl_array_fetch(u_surf, loc); + double *u_d = gkyl_array_fetch(u, loc); + double *u_surf_d = gkyl_array_fetch(u_surf, loc); up->fluid_copy(count, up->xs, u_d, u_surf_d); @@ -116,15 +121,15 @@ void gkyl_dg_calc_fluid_vars_advance(struct gkyl_dg_calc_fluid_vars *up, const s } } -void gkyl_dg_calc_fluid_vars_pressure(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* fluid, const struct gkyl_array* u, - struct gkyl_array* p, struct gkyl_array* p_surf) +void gkyl_dg_calc_fluid_vars_pressure( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u, struct gkyl_array *p, + struct gkyl_array *p_surf +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(p)) { - return gkyl_dg_calc_fluid_vars_pressure_cu(up, conf_range, - fluid, u, p, p_surf); + return gkyl_dg_calc_fluid_vars_pressure_cu(up, conf_range, fluid, u, p, p_surf); } #endif struct gkyl_range_iter iter; @@ -136,22 +141,21 @@ void gkyl_dg_calc_fluid_vars_pressure(struct gkyl_dg_calc_fluid_vars *up, const double *fluid_d = gkyl_array_cfetch(fluid, loc); const double *u_d = gkyl_array_cfetch(u, loc); - double* p_d = gkyl_array_fetch(p, loc); - double* p_surf_d = gkyl_array_fetch(p_surf, loc); + double *p_d = gkyl_array_fetch(p, loc); + double *p_surf_d = gkyl_array_fetch(p_surf, loc); up->fluid_pressure(up->param, fluid_d, u_d, p_d, p_surf_d); } } -void gkyl_dg_calc_fluid_vars_ke(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* fluid, const struct gkyl_array* u, - struct gkyl_array* ke) +void gkyl_dg_calc_fluid_vars_ke( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u, struct gkyl_array *ke +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(ke)) { - return gkyl_dg_calc_fluid_vars_ke_cu(up, conf_range, - fluid, u, ke); + return gkyl_dg_calc_fluid_vars_ke_cu(up, conf_range, fluid, u, ke); } #endif struct gkyl_range_iter iter; @@ -163,14 +167,15 @@ void gkyl_dg_calc_fluid_vars_ke(struct gkyl_dg_calc_fluid_vars *up, const double *fluid_d = gkyl_array_cfetch(fluid, loc); const double *u_d = gkyl_array_cfetch(u, loc); - double* ke_d = gkyl_array_fetch(ke, loc); + double *ke_d = gkyl_array_fetch(ke, loc); up->fluid_ke(fluid_d, u_d, ke_d); } } -void gkyl_dg_calc_fluid_vars_limiter(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, struct gkyl_array* fluid) +void gkyl_dg_calc_fluid_vars_limiter( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, struct gkyl_array *fluid +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(fluid)) { @@ -188,32 +193,33 @@ void gkyl_dg_calc_fluid_vars_limiter(struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_wave_cell_geom *geom = gkyl_wave_geom_get(up->geom, idxc); double *fluid_c = gkyl_array_fetch(fluid, linc); - for (int dir=0; dirfluid_limiter[dir](up->limiter_fac, up->wv_eqn, geom, fluid_l, fluid_c, fluid_r); + up->fluid_limiter[dir](up->limiter_fac, up->wv_eqn, geom, fluid_l, fluid_c, fluid_r); } } } -void gkyl_dg_calc_fluid_integrated_vars(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* fluid, - const struct gkyl_array* u_i, const struct gkyl_array* p_ij, - struct gkyl_array* fluid_int_vars) +void gkyl_dg_calc_fluid_integrated_vars( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u_i, const struct gkyl_array *p_ij, + struct gkyl_array *fluid_int_vars +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(fluid_int_vars)) { - return gkyl_dg_calc_fluid_integrated_vars_cu(up, conf_range, - fluid, u_i, p_ij, fluid_int_vars); + return gkyl_dg_calc_fluid_integrated_vars_cu(up, conf_range, fluid, u_i, p_ij, fluid_int_vars); } #endif @@ -225,21 +231,20 @@ void gkyl_dg_calc_fluid_integrated_vars(struct gkyl_dg_calc_fluid_vars *up, const double *fluid_d = gkyl_array_cfetch(fluid, loc); const double *u_i_d = gkyl_array_cfetch(u_i, loc); const double *p_ij_d = gkyl_array_cfetch(p_ij, loc); - + double *fluid_int_vars_d = gkyl_array_fetch(fluid_int_vars, loc); up->fluid_int(fluid_d, u_i_d, p_ij_d, fluid_int_vars_d); } } -void gkyl_dg_calc_fluid_vars_source(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* app_accel, const struct gkyl_array* fluid, - struct gkyl_array* rhs) +void gkyl_dg_calc_fluid_vars_source( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *app_accel, const struct gkyl_array *fluid, struct gkyl_array *rhs +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(rhs)) { - return gkyl_dg_calc_fluid_vars_source_cu(up, conf_range, - app_accel, fluid, rhs); + return gkyl_dg_calc_fluid_vars_source_cu(up, conf_range, app_accel, fluid, rhs); } #endif @@ -259,14 +264,15 @@ void gkyl_dg_calc_fluid_vars_source(struct gkyl_dg_calc_fluid_vars *up, void gkyl_dg_calc_fluid_vars_release(gkyl_dg_calc_fluid_vars *up) { gkyl_wv_eqn_release(up->wv_eqn); - gkyl_wave_geom_release(up->geom); + gkyl_wave_geom_release(up->geom); gkyl_nmat_release(up->As); gkyl_nmat_release(up->xs); gkyl_nmat_linsolve_lu_release(up->mem); - - if (GKYL_IS_CU_ALLOC(up->flags)) + + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/vlasov/zero/dg_calc_fluid_vars_cu.cu b/vlasov/zero/dg_calc_fluid_vars_cu.cu index be7fb72038..213598d69a 100644 --- a/vlasov/zero/dg_calc_fluid_vars_cu.cu +++ b/vlasov/zero/dg_calc_fluid_vars_cu.cu @@ -15,17 +15,15 @@ extern "C" { #include } -__global__ static void -gkyl_dg_calc_fluid_vars_set_cu_kernel(gkyl_dg_calc_fluid_vars* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* fluid, struct gkyl_array* cell_avg_prim) +__global__ static void gkyl_dg_calc_fluid_vars_set_cu_kernel( + gkyl_dg_calc_fluid_vars *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, const struct gkyl_array *fluid, struct gkyl_array *cell_avg_prim +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -35,27 +33,25 @@ gkyl_dg_calc_fluid_vars_set_cu_kernel(gkyl_dg_calc_fluid_vars* up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->Ncomp; + long count = linc1 * up->Ncomp; - const double *fluid_d = (const double*) gkyl_array_cfetch(fluid, loc); + const double *fluid_d = (const double *)gkyl_array_cfetch(fluid, loc); - int* cell_avg_prim_d = (int*) gkyl_array_fetch(cell_avg_prim, loc); + int *cell_avg_prim_d = (int *)gkyl_array_fetch(cell_avg_prim, loc); cell_avg_prim_d[0] = up->fluid_set(count, As, xs, fluid_d); } } -__global__ static void -gkyl_dg_calc_fluid_vars_copy_cu_kernel(gkyl_dg_calc_fluid_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, - struct gkyl_array* prim, struct gkyl_array* prim_surf) +__global__ static void gkyl_dg_calc_fluid_vars_copy_cu_kernel( + gkyl_dg_calc_fluid_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + struct gkyl_array *prim, struct gkyl_array *prim_surf +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -65,46 +61,46 @@ gkyl_dg_calc_fluid_vars_copy_cu_kernel(gkyl_dg_calc_fluid_vars* up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->Ncomp; + long count = linc1 * up->Ncomp; - double* prim_d = (double*) gkyl_array_fetch(prim, loc); - double* prim_surf_d = (double*) gkyl_array_fetch(prim_surf, loc); + double *prim_d = (double *)gkyl_array_fetch(prim, loc); + double *prim_surf_d = (double *)gkyl_array_fetch(prim_surf, loc); up->fluid_copy(count, xs, prim_d, prim_surf_d); } } // Host-side wrapper for primitive variable calculation -void gkyl_dg_calc_fluid_vars_advance_cu(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_array* fluid, struct gkyl_array* cell_avg_prim, - struct gkyl_array* prim, struct gkyl_array* prim_surf) +void gkyl_dg_calc_fluid_vars_advance_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_array *fluid, + struct gkyl_array *cell_avg_prim, struct gkyl_array *prim, struct gkyl_array *prim_surf +) { struct gkyl_range conf_range = up->mem_range; - - gkyl_dg_calc_fluid_vars_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, - fluid->on_dev, cell_avg_prim->on_dev); + + gkyl_dg_calc_fluid_vars_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, fluid->on_dev, cell_avg_prim->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_dg_calc_fluid_vars_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, prim->on_dev, prim_surf->on_dev); + gkyl_dg_calc_fluid_vars_copy_cu_kernel<< > >( + up->on_dev, up->xs->on_dev, conf_range, prim->on_dev, prim_surf->on_dev + ); } -__global__ void -gkyl_calc_fluid_vars_pressure_cu_kernel(struct gkyl_dg_calc_fluid_vars *up, struct gkyl_range conf_range, - const struct gkyl_array* fluid, const struct gkyl_array* u, - struct gkyl_array* p, struct gkyl_array* p_surf) -{ +__global__ void gkyl_calc_fluid_vars_pressure_cu_kernel( + struct gkyl_dg_calc_fluid_vars *up, struct gkyl_range conf_range, const struct gkyl_array *fluid, + const struct gkyl_array *u, struct gkyl_array *p, struct gkyl_array *p_surf +) +{ int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -114,38 +110,38 @@ gkyl_calc_fluid_vars_pressure_cu_kernel(struct gkyl_dg_calc_fluid_vars *up, stru // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *fluid_d = (const double*) gkyl_array_cfetch(fluid, loc); - const double *u_d = (const double*) gkyl_array_cfetch(u, loc); + const double *fluid_d = (const double *)gkyl_array_cfetch(fluid, loc); + const double *u_d = (const double *)gkyl_array_cfetch(u, loc); - double *p_d = (double*) gkyl_array_fetch(p, loc); - double *p_surf_d = (double*) gkyl_array_fetch(p_surf, loc); + double *p_d = (double *)gkyl_array_fetch(p, loc); + double *p_surf_d = (double *)gkyl_array_fetch(p_surf, loc); up->fluid_pressure(up->param, fluid_d, u_d, p_d, p_surf_d); } } // Host-side wrapper for pressure calculation -void gkyl_dg_calc_fluid_vars_pressure_cu(struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* fluid, const struct gkyl_array* u, - struct gkyl_array* p, struct gkyl_array* p_surf) +void gkyl_dg_calc_fluid_vars_pressure_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u, struct gkyl_array *p, + struct gkyl_array *p_surf +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_calc_fluid_vars_pressure_cu_kernel<<>>(up->on_dev, *conf_range, - fluid->on_dev, u->on_dev, - p->on_dev, p_surf->on_dev); + gkyl_calc_fluid_vars_pressure_cu_kernel<< > >( + up->on_dev, *conf_range, fluid->on_dev, u->on_dev, p->on_dev, p_surf->on_dev + ); } -__global__ void -gkyl_calc_fluid_vars_ke_cu_kernel(struct gkyl_dg_calc_fluid_vars *up, struct gkyl_range conf_range, - const struct gkyl_array* fluid, const struct gkyl_array* u, - struct gkyl_array* ke) -{ +__global__ void gkyl_calc_fluid_vars_ke_cu_kernel( + struct gkyl_dg_calc_fluid_vars *up, struct gkyl_range conf_range, const struct gkyl_array *fluid, + const struct gkyl_array *u, struct gkyl_array *ke +) +{ int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -155,87 +151,86 @@ gkyl_calc_fluid_vars_ke_cu_kernel(struct gkyl_dg_calc_fluid_vars *up, struct gky // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *fluid_d = (const double*) gkyl_array_cfetch(fluid, loc); - const double *u_d = (const double*) gkyl_array_cfetch(u, loc); + const double *fluid_d = (const double *)gkyl_array_cfetch(fluid, loc); + const double *u_d = (const double *)gkyl_array_cfetch(u, loc); - double *ke_d = (double*) gkyl_array_fetch(ke, loc); + double *ke_d = (double *)gkyl_array_fetch(ke, loc); up->fluid_ke(fluid_d, u_d, ke_d); } } // Host-side wrapper for kinetic energy calculation -void gkyl_dg_calc_fluid_vars_ke_cu(struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* fluid, const struct gkyl_array* u, - struct gkyl_array* ke) +void gkyl_dg_calc_fluid_vars_ke_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u, struct gkyl_array *ke +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_calc_fluid_vars_ke_cu_kernel<<>>(up->on_dev, *conf_range, - fluid->on_dev, u->on_dev, - ke->on_dev); + gkyl_calc_fluid_vars_ke_cu_kernel<< > >( + up->on_dev, *conf_range, fluid->on_dev, u->on_dev, ke->on_dev + ); } -__global__ void -gkyl_dg_calc_fluid_vars_limiter_cu_kernel(struct gkyl_dg_calc_fluid_vars *up, struct gkyl_range conf_range, - struct gkyl_array* fluid) +__global__ void gkyl_dg_calc_fluid_vars_limiter_cu_kernel( + struct gkyl_dg_calc_fluid_vars *up, struct gkyl_range conf_range, struct gkyl_array *fluid +) { int cdim = up->cdim; int idxl[GKYL_MAX_DIM], idxc[GKYL_MAX_DIM], idxr[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange gkyl_sub_range_inv_idx(&conf_range, linc1, idxc); - const struct gkyl_wave_cell_geom *geom = gkyl_wave_geom_get(up->geom, idxc); + const struct gkyl_wave_cell_geom *geom = gkyl_wave_geom_get(up->geom, idxc); // convert back to a linear index on the super-range (with ghost cells) // linc will have jumps in it to jump over ghost cells long linc = gkyl_range_idx(&conf_range, idxc); - double *fluid_c = (double*) gkyl_array_fetch(fluid, linc); + double *fluid_c = (double *)gkyl_array_fetch(fluid, linc); - for (int dir=0; dirfluid_limiter[dir](up->limiter_fac, up->wv_eqn, geom, fluid_l, fluid_c, fluid_r); } } } // Host-side wrapper for slope limiter of fluid variables -void -gkyl_dg_calc_fluid_vars_limiter_cu(struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, - struct gkyl_array* fluid) +void gkyl_dg_calc_fluid_vars_limiter_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, struct gkyl_array *fluid +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_fluid_vars_limiter_cu_kernel<<>>(up->on_dev, *conf_range, fluid->on_dev); + gkyl_dg_calc_fluid_vars_limiter_cu_kernel<< > >( + up->on_dev, *conf_range, fluid->on_dev + ); } -__global__ void -gkyl_dg_calc_fluid_integrated_vars_cu_kernel(struct gkyl_dg_calc_fluid_vars *up, - struct gkyl_range conf_range, const struct gkyl_array* fluid, - const struct gkyl_array* u_i, const struct gkyl_array* p_ij, - struct gkyl_array* int_fluid_vars) +__global__ void gkyl_dg_calc_fluid_integrated_vars_cu_kernel( + struct gkyl_dg_calc_fluid_vars *up, struct gkyl_range conf_range, const struct gkyl_array *fluid, + const struct gkyl_array *u_i, const struct gkyl_array *p_ij, struct gkyl_array *int_fluid_vars +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -245,40 +240,38 @@ gkyl_dg_calc_fluid_integrated_vars_cu_kernel(struct gkyl_dg_calc_fluid_vars *up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *fluid_d = (const double*) gkyl_array_cfetch(fluid, loc); - const double *u_i_d = (const double*) gkyl_array_cfetch(u_i, loc); - const double *p_ij_d = (const double*) gkyl_array_cfetch(p_ij, loc); + const double *fluid_d = (const double *)gkyl_array_cfetch(fluid, loc); + const double *u_i_d = (const double *)gkyl_array_cfetch(u_i, loc); + const double *p_ij_d = (const double *)gkyl_array_cfetch(p_ij, loc); - double *int_fluid_vars_d = (double*) gkyl_array_fetch(int_fluid_vars, loc); + double *int_fluid_vars_d = (double *)gkyl_array_fetch(int_fluid_vars, loc); up->fluid_int(fluid_d, u_i_d, p_ij_d, int_fluid_vars_d); } } // Host-side wrapper for fluid integrated variables calculation -void -gkyl_dg_calc_fluid_integrated_vars_cu(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* fluid, - const struct gkyl_array* u_i, const struct gkyl_array* p_ij, - struct gkyl_array* int_fluid_vars) +void gkyl_dg_calc_fluid_integrated_vars_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u_i, const struct gkyl_array *p_ij, + struct gkyl_array *int_fluid_vars +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_fluid_integrated_vars_cu_kernel<<>>(up->on_dev, *conf_range, - fluid->on_dev, u_i->on_dev, p_ij->on_dev, int_fluid_vars->on_dev); + gkyl_dg_calc_fluid_integrated_vars_cu_kernel<< > >( + up->on_dev, *conf_range, fluid->on_dev, u_i->on_dev, p_ij->on_dev, int_fluid_vars->on_dev + ); } -__global__ void -gkyl_dg_calc_fluid_vars_source_cu_kernel(struct gkyl_dg_calc_fluid_vars *up, - struct gkyl_range conf_range, - const struct gkyl_array* app_accel, const struct gkyl_array* fluid, - struct gkyl_array* rhs) +__global__ void gkyl_dg_calc_fluid_vars_source_cu_kernel( + struct gkyl_dg_calc_fluid_vars *up, struct gkyl_range conf_range, + const struct gkyl_array *app_accel, const struct gkyl_array *fluid, struct gkyl_array *rhs +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -288,32 +281,33 @@ gkyl_dg_calc_fluid_vars_source_cu_kernel(struct gkyl_dg_calc_fluid_vars *up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *app_accel_d = (const double*) gkyl_array_cfetch(app_accel, loc); - const double *fluid_d = (const double*) gkyl_array_cfetch(fluid, loc); + const double *app_accel_d = (const double *)gkyl_array_cfetch(app_accel, loc); + const double *fluid_d = (const double *)gkyl_array_cfetch(fluid, loc); - double *rhs_d = (double*) gkyl_array_fetch(rhs, loc); + double *rhs_d = (double *)gkyl_array_fetch(rhs, loc); up->fluid_source(app_accel_d, fluid_d, rhs_d); } } // Host-side wrapper for fluid source term calculations -void -gkyl_dg_calc_fluid_vars_source_cu(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* app_accel, const struct gkyl_array* fluid, - struct gkyl_array* rhs) +void gkyl_dg_calc_fluid_vars_source_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *app_accel, const struct gkyl_array *fluid, struct gkyl_array *rhs +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_fluid_vars_source_cu_kernel<<>>(up->on_dev, *conf_range, - app_accel->on_dev, fluid->on_dev, rhs->on_dev); + gkyl_dg_calc_fluid_vars_source_cu_kernel<< > >( + up->on_dev, *conf_range, app_accel->on_dev, fluid->on_dev, rhs->on_dev + ); } // CUDA kernel to set device pointers to fluid vars kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_calc_fluid_vars_set_cu_dev_ptrs(struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_wv_eqn *wv_eqn, - enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ static void dg_calc_fluid_vars_set_cu_dev_ptrs( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_wv_eqn *wv_eqn, enum gkyl_basis_type b_type, + int cdim, int poly_order +) { up->fluid_set = choose_fluid_set_kern(b_type, cdim, poly_order); up->fluid_copy = choose_fluid_copy_kern(b_type, cdim, poly_order); @@ -322,20 +316,23 @@ dg_calc_fluid_vars_set_cu_dev_ptrs(struct gkyl_dg_calc_fluid_vars *up, const str up->fluid_int = choose_fluid_int_kern(b_type, cdim, poly_order); up->fluid_source = choose_fluid_source_kern(b_type, cdim, poly_order); // Fetch the kernels in each direction - for (int d=0; dfluid_limiter[d] = choose_fluid_limiter_kern(d, b_type, cdim, poly_order); + } } -gkyl_dg_calc_fluid_vars* -gkyl_dg_calc_fluid_vars_cu_dev_new(const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *wg, - const struct gkyl_basis* cbasis, const struct gkyl_range *mem_range, - double limiter_fac) +gkyl_dg_calc_fluid_vars *gkyl_dg_calc_fluid_vars_cu_dev_new( + const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *wg, + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, double limiter_fac +) { - struct gkyl_dg_calc_fluid_vars *up = (struct gkyl_dg_calc_fluid_vars*) gkyl_malloc(sizeof(gkyl_dg_calc_fluid_vars)); + struct gkyl_dg_calc_fluid_vars *up = + (struct gkyl_dg_calc_fluid_vars *)gkyl_malloc(sizeof(gkyl_dg_calc_fluid_vars)); up->eqn_type = wv_eqn->type; - if (up->eqn_type == GKYL_EQN_EULER) + if (up->eqn_type == GKYL_EQN_EULER) { up->param = gkyl_wv_euler_gas_gamma(wv_eqn); + } // acquire pointer to wave equation object struct gkyl_wv_eqn *eqn = gkyl_wv_eqn_acquire(wv_eqn); @@ -356,33 +353,35 @@ gkyl_dg_calc_fluid_vars_cu_dev_new(const struct gkyl_wv_eqn *wv_eqn, const struc // Limiter factor for relationship between slopes and cell average differences // By default, this factor is 1/sqrt(3) because cell_avg(f) = f0/sqrt(2^cdim) - // and a cell slope estimate from two adjacent cells is (for the x variation): + // and a cell slope estimate from two adjacent cells is (for the x variation): // integral(psi_1 [cell_avg(f_{i+1}) - cell_avg(f_{i})]*x) = sqrt(2^cdim)/sqrt(3)*[cell_avg(f_{i+1}) - cell_avg(f_{i})] // where psi_1 is the x cell slope basis in our orthonormal expansion psi_1 = sqrt(3)/sqrt(2^cdim)*x // This factor can be made smaller (larger) to increase (decrease) the diffusion from the slope limiter - if (limiter_fac == 0.0) + if (limiter_fac == 0.0) { up->limiter_fac = 0.5773502691896258; - else + } else { up->limiter_fac = limiter_fac; + } - // There are Ncomp*range->volume linear systems to be solved - up->As = gkyl_nmat_cu_dev_new(up->Ncomp*mem_range->volume, nc, nc); - up->xs = gkyl_nmat_cu_dev_new(up->Ncomp*mem_range->volume, nc, 1); + // There are Ncomp*range->volume linear systems to be solved + up->As = gkyl_nmat_cu_dev_new(up->Ncomp * mem_range->volume, nc, nc); + up->xs = gkyl_nmat_cu_dev_new(up->Ncomp * mem_range->volume, nc, 1); up->mem = gkyl_nmat_linsolve_lu_cu_dev_new(up->As->num, up->As->nr); up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_calc_fluid_vars *up_cu = (struct gkyl_dg_calc_fluid_vars*) gkyl_cu_malloc(sizeof(gkyl_dg_calc_fluid_vars)); + struct gkyl_dg_calc_fluid_vars *up_cu = + (struct gkyl_dg_calc_fluid_vars *)gkyl_cu_malloc(sizeof(gkyl_dg_calc_fluid_vars)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_calc_fluid_vars), GKYL_CU_MEMCPY_H2D); - dg_calc_fluid_vars_set_cu_dev_ptrs<<<1,1>>>(up_cu, wv_eqn->on_dev, b_type, cdim, poly_order); + dg_calc_fluid_vars_set_cu_dev_ptrs<<<1, 1> > >(up_cu, wv_eqn->on_dev, b_type, cdim, poly_order); // set parent on_dev pointer up->on_dev = up_cu; - - up->wv_eqn = eqn; // updater should store host pointer - up->geom = geom; + + up->wv_eqn = eqn; // updater should store host pointer + up->geom = geom; return up; } diff --git a/vlasov/zero/dg_calc_prim_vars.c b/vlasov/zero/dg_calc_prim_vars.c index 9c457c7eb9..9d84ecc305 100644 --- a/vlasov/zero/dg_calc_prim_vars.c +++ b/vlasov/zero/dg_calc_prim_vars.c @@ -6,22 +6,26 @@ #include #include -void gkyl_calc_prim_vars_u_from_statevec(gkyl_dg_bin_op_mem *mem, struct gkyl_basis basis, const struct gkyl_range *range, - const struct gkyl_array* statevec, struct gkyl_array* u_i) +void gkyl_calc_prim_vars_u_from_statevec( + gkyl_dg_bin_op_mem *mem, struct gkyl_basis basis, const struct gkyl_range *range, + const struct gkyl_array *statevec, struct gkyl_array *u_i +) { // Find number of components of flow vector - int num_comp = u_i->ncomp/basis.num_basis; - for (int i = 0; incomp / basis.num_basis; + for (int i = 0; i < num_comp; ++i) { + gkyl_dg_div_op_range(mem, &basis, i, u_i, i + 1, statevec, 0, statevec, range); + } } -void gkyl_calc_prim_vars_u_from_rhou(gkyl_dg_bin_op_mem *mem, struct gkyl_basis basis, const struct gkyl_range *range, - const struct gkyl_array* rho, const struct gkyl_array* rhou, struct gkyl_array* u_i) +void gkyl_calc_prim_vars_u_from_rhou( + gkyl_dg_bin_op_mem *mem, struct gkyl_basis basis, const struct gkyl_range *range, + const struct gkyl_array *rho, const struct gkyl_array *rhou, struct gkyl_array *u_i +) { // Find number of components of flow vector - int num_comp = u_i->ncomp/basis.num_basis; - for (int i = 0; incomp / basis.num_basis; + for (int i = 0; i < num_comp; ++i) { + gkyl_dg_div_op_range(mem, &basis, i, u_i, i, rhou, 0, rho, range); + } } diff --git a/vlasov/zero/dg_calc_sr_vars.c b/vlasov/zero/dg_calc_sr_vars.c index 78510e8b82..3c78d248a6 100644 --- a/vlasov/zero/dg_calc_sr_vars.c +++ b/vlasov/zero/dg_calc_sr_vars.c @@ -8,17 +8,19 @@ #include #include -gkyl_dg_calc_sr_vars* -gkyl_dg_calc_sr_vars_new(const struct gkyl_rect_grid *phase_grid, const struct gkyl_rect_grid *vel_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *vel_basis, - const struct gkyl_range *mem_range, const struct gkyl_range *vel_range, bool use_gpu) +gkyl_dg_calc_sr_vars *gkyl_dg_calc_sr_vars_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_rect_grid *vel_grid, + const struct gkyl_basis *conf_basis, const struct gkyl_basis *vel_basis, + const struct gkyl_range *mem_range, const struct gkyl_range *vel_range, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { - return gkyl_dg_calc_sr_vars_cu_dev_new(phase_grid, vel_grid, - conf_basis, vel_basis, mem_range, vel_range); - } -#endif + if (use_gpu) { + return gkyl_dg_calc_sr_vars_cu_dev_new( + phase_grid, vel_grid, conf_basis, vel_basis, mem_range, vel_range + ); + } +#endif gkyl_dg_calc_sr_vars *up = gkyl_malloc(sizeof(*up)); up->phase_grid = *phase_grid; @@ -43,23 +45,24 @@ gkyl_dg_calc_sr_vars_new(const struct gkyl_rect_grid *phase_grid, const struct g up->sr_GammaV = choose_sr_vars_GammaV_kern(b_type, cdim, vdim, poly_order); up->sr_pressure = choose_sr_vars_pressure_kern(b_type, cdim, vdim, poly_order); - // Linear system for solving for the drift velocity V_drift = M1i/M0 - // and then computing the rest-frame density n = GammaV_inv*M0 + // Linear system for solving for the drift velocity V_drift = M1i/M0 + // and then computing the rest-frame density n = GammaV_inv*M0 // where GammaV_inv = sqrt(1 - |V_drift|^2) - up->Ncomp = vdim; - up->As = gkyl_nmat_new(up->Ncomp*mem_range->volume, nc, nc); - up->xs = gkyl_nmat_new(up->Ncomp*mem_range->volume, nc, 1); + up->Ncomp = vdim; + up->As = gkyl_nmat_new(up->Ncomp * mem_range->volume, nc, nc); + up->xs = gkyl_nmat_new(up->Ncomp * mem_range->volume, nc, 1); up->mem = gkyl_nmat_linsolve_lu_new(up->As->num, up->As->nr); up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void gkyl_calc_sr_vars_init_p_vars(struct gkyl_dg_calc_sr_vars *up, - struct gkyl_array* gamma, struct gkyl_array* gamma_inv) +void gkyl_calc_sr_vars_init_p_vars( + struct gkyl_dg_calc_sr_vars *up, struct gkyl_array *gamma, struct gkyl_array *gamma_inv +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(gamma)) { @@ -68,7 +71,7 @@ void gkyl_calc_sr_vars_init_p_vars(struct gkyl_dg_calc_sr_vars *up, #endif // Cell center array - double xc[GKYL_MAX_DIM]; + double xc[GKYL_MAX_DIM]; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, &up->vel_range); while (gkyl_range_iter_next(&iter)) { @@ -81,8 +84,10 @@ void gkyl_calc_sr_vars_init_p_vars(struct gkyl_dg_calc_sr_vars *up, } } -void gkyl_dg_calc_sr_vars_n(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_array* M0, const struct gkyl_array* M1i, struct gkyl_array* n) +void gkyl_dg_calc_sr_vars_n( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_array *M0, const struct gkyl_array *M1i, + struct gkyl_array *n +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(n)) { @@ -118,7 +123,7 @@ void gkyl_dg_calc_sr_vars_n(struct gkyl_dg_calc_sr_vars *up, long loc = gkyl_range_idx(&up->mem_range, iter.idx); const double *M0_d = gkyl_array_cfetch(M0, loc); - double* n_d = gkyl_array_fetch(n, loc); + double *n_d = gkyl_array_fetch(n, loc); up->sr_n_copy(count, up->xs, M0_d, n_d); @@ -126,15 +131,15 @@ void gkyl_dg_calc_sr_vars_n(struct gkyl_dg_calc_sr_vars *up, } } -void gkyl_dg_calc_sr_vars_GammaV(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* u_i, struct gkyl_array* u_i_sq, - struct gkyl_array* GammaV, struct gkyl_array* GammaV_sq) +void gkyl_dg_calc_sr_vars_GammaV( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *u_i, struct gkyl_array *u_i_sq, struct gkyl_array *GammaV, + struct gkyl_array *GammaV_sq +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(GammaV)) { - return gkyl_dg_calc_sr_vars_GammaV_cu(up, conf_range, - u_i, u_i_sq, GammaV, GammaV_sq); + return gkyl_dg_calc_sr_vars_GammaV_cu(up, conf_range, u_i, u_i_sq, GammaV, GammaV_sq); } #endif @@ -148,26 +153,26 @@ void gkyl_dg_calc_sr_vars_GammaV(struct gkyl_dg_calc_sr_vars *up, double *GammaV_d = gkyl_array_fetch(GammaV, loc_conf); double *GammaV_sq_d = gkyl_array_fetch(GammaV_sq, loc_conf); - up->sr_GammaV(u_i_d, u_i_sq_d, GammaV_d, GammaV_sq_d); + up->sr_GammaV(u_i_d, u_i_sq_d, GammaV_d, GammaV_sq_d); } } -void gkyl_dg_calc_sr_vars_pressure(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* gamma, const struct gkyl_array* gamma_inv, - const struct gkyl_array* u_i, const struct gkyl_array* u_i_sq, - const struct gkyl_array* GammaV, const struct gkyl_array* GammaV_sq, - const struct gkyl_array* f, struct gkyl_array* sr_pressure) +void gkyl_dg_calc_sr_vars_pressure( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *gamma, + const struct gkyl_array *gamma_inv, const struct gkyl_array *u_i, const struct gkyl_array *u_i_sq, + const struct gkyl_array *GammaV, const struct gkyl_array *GammaV_sq, const struct gkyl_array *f, + struct gkyl_array *sr_pressure +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(sr_pressure)) { - return gkyl_dg_calc_sr_vars_pressure_cu(up, - conf_range, phase_range, - gamma, gamma_inv, u_i, u_i_sq, GammaV, GammaV_sq, - f, sr_pressure); + return gkyl_dg_calc_sr_vars_pressure_cu( + up, conf_range, phase_range, gamma, gamma_inv, u_i, u_i_sq, GammaV, GammaV_sq, f, sr_pressure + ); } #endif - gkyl_array_clear(sr_pressure, 0.0); + gkyl_array_clear(sr_pressure, 0.0); int cdim = conf_range->ndim; int pdim = phase_range->ndim; @@ -182,8 +187,8 @@ void gkyl_dg_calc_sr_vars_pressure(struct gkyl_dg_calc_sr_vars *up, long loc_conf = gkyl_range_idx(conf_range, iter.idx); long loc_phase = gkyl_range_idx(phase_range, iter.idx); - for (int i=0; ivel_range, idx_vel); @@ -197,10 +202,11 @@ void gkyl_dg_calc_sr_vars_pressure(struct gkyl_dg_calc_sr_vars *up, double *sr_pressure_d = gkyl_array_fetch(sr_pressure, loc_conf); - up->sr_pressure(xc, up->phase_grid.dx, - gamma_d, gamma_inv_d, u_i_d, u_i_sq_d, GammaV_d, GammaV_sq_d, - f_d, sr_pressure_d); - } + up->sr_pressure( + xc, up->phase_grid.dx, gamma_d, gamma_inv_d, u_i_d, u_i_sq_d, GammaV_d, GammaV_sq_d, f_d, + sr_pressure_d + ); + } } void gkyl_dg_calc_sr_vars_release(gkyl_dg_calc_sr_vars *up) @@ -209,7 +215,8 @@ void gkyl_dg_calc_sr_vars_release(gkyl_dg_calc_sr_vars *up) gkyl_nmat_release(up->xs); gkyl_nmat_linsolve_lu_release(up->mem); - if (GKYL_IS_CU_ALLOC(up->flags)) + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } diff --git a/vlasov/zero/dg_calc_sr_vars_cu.cu b/vlasov/zero/dg_calc_sr_vars_cu.cu index dd44cb60aa..2f92f4637f 100644 --- a/vlasov/zero/dg_calc_sr_vars_cu.cu +++ b/vlasov/zero/dg_calc_sr_vars_cu.cu @@ -13,18 +13,16 @@ extern "C" { #include } -__global__ void -gkyl_calc_sr_vars_init_p_vars_cu_kernel(gkyl_dg_calc_sr_vars* up, - struct gkyl_array* gamma, struct gkyl_array* gamma_inv) +__global__ void gkyl_calc_sr_vars_init_p_vars_cu_kernel( + gkyl_dg_calc_sr_vars *up, struct gkyl_array *gamma, struct gkyl_array *gamma_inv +) { int idx[GKYL_MAX_DIM]; // Cell center array - double xc[GKYL_MAX_DIM]; + double xc[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < up->vel_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < up->vel_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -35,34 +33,33 @@ gkyl_calc_sr_vars_init_p_vars_cu_kernel(gkyl_dg_calc_sr_vars* up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&up->vel_range, idx); - double *gamma_d = (double*) gkyl_array_fetch(gamma, loc); - double *gamma_inv_d = (double*) gkyl_array_fetch(gamma_inv, loc); + double *gamma_d = (double *)gkyl_array_fetch(gamma, loc); + double *gamma_inv_d = (double *)gkyl_array_fetch(gamma_inv, loc); up->sr_p_vars(xc, up->vel_grid.dx, gamma_d, gamma_inv_d); } } -// Host-side wrapper for initialization of momentum variables (gamma, gamma_inv) -void -gkyl_calc_sr_vars_init_p_vars_cu(struct gkyl_dg_calc_sr_vars *up, - struct gkyl_array* gamma, struct gkyl_array* gamma_inv) +// Host-side wrapper for initialization of momentum variables (gamma, gamma_inv) +void gkyl_calc_sr_vars_init_p_vars_cu( + struct gkyl_dg_calc_sr_vars *up, struct gkyl_array *gamma, struct gkyl_array *gamma_inv +) { int nblocks = up->vel_range.nblocks; int nthreads = up->vel_range.nthreads; - gkyl_calc_sr_vars_init_p_vars_cu_kernel<<>>(up->on_dev, - gamma->on_dev, gamma_inv->on_dev); + gkyl_calc_sr_vars_init_p_vars_cu_kernel<< > >( + up->on_dev, gamma->on_dev, gamma_inv->on_dev + ); } -__global__ static void -gkyl_dg_calc_sr_vars_n_set_cu_kernel(gkyl_dg_calc_sr_vars* up, - struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* M0, const struct gkyl_array* M1i) +__global__ static void gkyl_dg_calc_sr_vars_n_set_cu_kernel( + gkyl_dg_calc_sr_vars *up, struct gkyl_nmat *As, struct gkyl_nmat *xs, + struct gkyl_range conf_range, const struct gkyl_array *M0, const struct gkyl_array *M1i +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -72,26 +69,24 @@ gkyl_dg_calc_sr_vars_n_set_cu_kernel(gkyl_dg_calc_sr_vars* up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->Ncomp; + long count = linc1 * up->Ncomp; - const double *M0_d = (const double*) gkyl_array_cfetch(M0, loc); - const double *M1i_d = (const double*) gkyl_array_cfetch(M1i, loc); + const double *M0_d = (const double *)gkyl_array_cfetch(M0, loc); + const double *M1i_d = (const double *)gkyl_array_cfetch(M1i, loc); up->sr_n_set(count, As, xs, M0_d, M1i_d); } } -__global__ static void -gkyl_dg_calc_sr_vars_n_copy_cu_kernel(gkyl_dg_calc_sr_vars* up, - struct gkyl_nmat *xs, struct gkyl_range conf_range, - const struct gkyl_array* M0, struct gkyl_array* n) +__global__ static void gkyl_dg_calc_sr_vars_n_copy_cu_kernel( + gkyl_dg_calc_sr_vars *up, struct gkyl_nmat *xs, struct gkyl_range conf_range, + const struct gkyl_array *M0, struct gkyl_array *n +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -101,46 +96,46 @@ gkyl_dg_calc_sr_vars_n_copy_cu_kernel(gkyl_dg_calc_sr_vars* up, // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); // fetch the correct count in the matrix (since we solve Ncomp systems in each cell) - long count = linc1*up->Ncomp; + long count = linc1 * up->Ncomp; - const double *M0_d = (const double*) gkyl_array_cfetch(M0, loc); - double* n_d = (double*) gkyl_array_fetch(n, loc); + const double *M0_d = (const double *)gkyl_array_cfetch(M0, loc); + double *n_d = (double *)gkyl_array_fetch(n, loc); up->sr_n_copy(count, xs, M0_d, n_d); } } // Host-side wrapper for SR rest-frame density calculation -void gkyl_dg_calc_sr_vars_n_cu(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_array* M0, const struct gkyl_array* M1i, struct gkyl_array* n) +void gkyl_dg_calc_sr_vars_n_cu( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_array *M0, const struct gkyl_array *M1i, + struct gkyl_array *n +) { struct gkyl_range conf_range = up->mem_range; - - gkyl_dg_calc_sr_vars_n_set_cu_kernel<<>>(up->on_dev, - up->As->on_dev, up->xs->on_dev, conf_range, - M0->on_dev, M1i->on_dev); + + gkyl_dg_calc_sr_vars_n_set_cu_kernel<< > >( + up->on_dev, up->As->on_dev, up->xs->on_dev, conf_range, M0->on_dev, M1i->on_dev + ); if (up->poly_order > 1) { bool status = gkyl_nmat_linsolve_lu_pa(up->mem, up->As, up->xs); assert(status); } - gkyl_dg_calc_sr_vars_n_copy_cu_kernel<<>>(up->on_dev, - up->xs->on_dev, conf_range, M0->on_dev, n->on_dev); + gkyl_dg_calc_sr_vars_n_copy_cu_kernel<< > >( + up->on_dev, up->xs->on_dev, conf_range, M0->on_dev, n->on_dev + ); } -__global__ void -gkyl_dg_calc_sr_vars_GammaV_cu_kernel(struct gkyl_dg_calc_sr_vars *up, - struct gkyl_range conf_range, - const struct gkyl_array* u_i, struct gkyl_array* u_i_sq, - struct gkyl_array* GammaV, struct gkyl_array* GammaV_sq) +__global__ void gkyl_dg_calc_sr_vars_GammaV_cu_kernel( + struct gkyl_dg_calc_sr_vars *up, struct gkyl_range conf_range, const struct gkyl_array *u_i, + struct gkyl_array *u_i_sq, struct gkyl_array *GammaV, struct gkyl_array *GammaV_sq +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -150,35 +145,35 @@ gkyl_dg_calc_sr_vars_GammaV_cu_kernel(struct gkyl_dg_calc_sr_vars *up, // linc will have jumps in it to jump over ghost cells long loc_conf = gkyl_range_idx(&conf_range, idx); - const double *u_i_d = (const double*) gkyl_array_cfetch(u_i, loc_conf); - double *u_i_sq_d = (double*) gkyl_array_fetch(u_i_sq, loc_conf); - double *GammaV_d = (double*) gkyl_array_fetch(GammaV, loc_conf); - double *GammaV_sq_d = (double*) gkyl_array_fetch(GammaV_sq, loc_conf); + const double *u_i_d = (const double *)gkyl_array_cfetch(u_i, loc_conf); + double *u_i_sq_d = (double *)gkyl_array_fetch(u_i_sq, loc_conf); + double *GammaV_d = (double *)gkyl_array_fetch(GammaV, loc_conf); + double *GammaV_sq_d = (double *)gkyl_array_fetch(GammaV_sq, loc_conf); - up->sr_GammaV(u_i_d, u_i_sq_d, GammaV_d, GammaV_sq_d); + up->sr_GammaV(u_i_d, u_i_sq_d, GammaV_d, GammaV_sq_d); } } // Host-side wrapper for derived quantities from bulk four-velocity -void -gkyl_dg_calc_sr_vars_GammaV_cu(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* u_i, struct gkyl_array* u_i_sq, - struct gkyl_array* GammaV, struct gkyl_array* GammaV_sq) +void gkyl_dg_calc_sr_vars_GammaV_cu( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *u_i, struct gkyl_array *u_i_sq, struct gkyl_array *GammaV, + struct gkyl_array *GammaV_sq +) { int nblocks = conf_range->nblocks; int nthreads = conf_range->nthreads; - gkyl_dg_calc_sr_vars_GammaV_cu_kernel<<>>(up->on_dev, *conf_range, - u_i->on_dev, u_i_sq->on_dev, GammaV->on_dev, GammaV_sq->on_dev); + gkyl_dg_calc_sr_vars_GammaV_cu_kernel<< > >( + up->on_dev, *conf_range, u_i->on_dev, u_i_sq->on_dev, GammaV->on_dev, GammaV_sq->on_dev + ); } -__global__ void -gkyl_dg_calc_sr_vars_pressure_cu_kernel(struct gkyl_dg_calc_sr_vars *up, - struct gkyl_range conf_range, struct gkyl_range phase_range, - const struct gkyl_array* gamma, const struct gkyl_array* gamma_inv, - const struct gkyl_array* u_i, const struct gkyl_array* u_i_sq, - const struct gkyl_array* GammaV, const struct gkyl_array* GammaV_sq, - const struct gkyl_array* f, struct gkyl_array* sr_pressure) +__global__ void gkyl_dg_calc_sr_vars_pressure_cu_kernel( + struct gkyl_dg_calc_sr_vars *up, struct gkyl_range conf_range, struct gkyl_range phase_range, + const struct gkyl_array *gamma, const struct gkyl_array *gamma_inv, const struct gkyl_array *u_i, + const struct gkyl_array *u_i_sq, const struct gkyl_array *GammaV, + const struct gkyl_array *GammaV_sq, const struct gkyl_array *f, struct gkyl_array *sr_pressure +) { int cdim = conf_range.ndim; int pdim = phase_range.ndim; @@ -187,10 +182,8 @@ gkyl_dg_calc_sr_vars_pressure_cu_kernel(struct gkyl_dg_calc_sr_vars *up, int idx_vel[GKYL_MAX_DIM]; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < phase_range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < phase_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -202,60 +195,60 @@ gkyl_dg_calc_sr_vars_pressure_cu_kernel(struct gkyl_dg_calc_sr_vars *up, long loc_conf = gkyl_range_idx(&conf_range, idx); long loc_phase = gkyl_range_idx(&phase_range, idx); - for (int i=0; ivel_range, idx_vel); - const double *gamma_d = (const double*) gkyl_array_cfetch(gamma, loc_vel); - const double *gamma_inv_d = (const double*) gkyl_array_cfetch(gamma_inv, loc_vel); - const double *u_i_d = (const double*) gkyl_array_cfetch(u_i, loc_conf); - const double *u_i_sq_d = (const double*) gkyl_array_cfetch(u_i_sq, loc_conf); - const double *GammaV_d = (const double*) gkyl_array_cfetch(GammaV, loc_conf); - const double *GammaV_sq_d = (const double*) gkyl_array_cfetch(GammaV_sq, loc_conf); - const double *f_d = (const double*) gkyl_array_cfetch(f, loc_phase); + const double *gamma_d = (const double *)gkyl_array_cfetch(gamma, loc_vel); + const double *gamma_inv_d = (const double *)gkyl_array_cfetch(gamma_inv, loc_vel); + const double *u_i_d = (const double *)gkyl_array_cfetch(u_i, loc_conf); + const double *u_i_sq_d = (const double *)gkyl_array_cfetch(u_i_sq, loc_conf); + const double *GammaV_d = (const double *)gkyl_array_cfetch(GammaV, loc_conf); + const double *GammaV_sq_d = (const double *)gkyl_array_cfetch(GammaV_sq, loc_conf); + const double *f_d = (const double *)gkyl_array_cfetch(f, loc_phase); double momLocal[32]; // hard-coded to max confBasis.num_basis (3x p=3 Ser) for now. - for (unsigned int k=0; k<32; ++k) { + for (unsigned int k = 0; k < 32; ++k) { momLocal[k] = 0.0; } - up->sr_pressure(xc, up->phase_grid.dx, - gamma_d, gamma_inv_d, u_i_d, u_i_sq_d, GammaV_d, GammaV_sq_d, - f_d, &momLocal[0]); + up->sr_pressure( + xc, up->phase_grid.dx, gamma_d, gamma_inv_d, u_i_d, u_i_sq_d, GammaV_d, GammaV_sq_d, f_d, + &momLocal[0] + ); // Accumulate output to output array atomically to avoid race conditions - double *sr_pressure_d = (double*) gkyl_array_fetch(sr_pressure, loc_conf); + double *sr_pressure_d = (double *)gkyl_array_fetch(sr_pressure, loc_conf); for (unsigned int k = 0; k < sr_pressure->ncomp; ++k) { atomicAdd(&sr_pressure_d[k], momLocal[k]); - } - } + } + } } // Host-side wrapper for rest-frame pressure calculation -void -gkyl_dg_calc_sr_vars_pressure_cu(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* gamma, const struct gkyl_array* gamma_inv, - const struct gkyl_array* u_i, const struct gkyl_array* u_i_sq, - const struct gkyl_array* GammaV, const struct gkyl_array* GammaV_sq, - const struct gkyl_array* f, struct gkyl_array* sr_pressure) +void gkyl_dg_calc_sr_vars_pressure_cu( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *gamma, + const struct gkyl_array *gamma_inv, const struct gkyl_array *u_i, const struct gkyl_array *u_i_sq, + const struct gkyl_array *GammaV, const struct gkyl_array *GammaV_sq, const struct gkyl_array *f, + struct gkyl_array *sr_pressure +) { int nblocks = phase_range->nblocks; int nthreads = phase_range->nthreads; - gkyl_array_clear(sr_pressure, 0.0); - gkyl_dg_calc_sr_vars_pressure_cu_kernel<<>>(up->on_dev, - *conf_range, *phase_range, - gamma->on_dev, gamma_inv->on_dev, - u_i->on_dev, u_i_sq->on_dev, GammaV->on_dev, GammaV_sq->on_dev, - f->on_dev, sr_pressure->on_dev); + gkyl_array_clear(sr_pressure, 0.0); + gkyl_dg_calc_sr_vars_pressure_cu_kernel<< > >( + up->on_dev, *conf_range, *phase_range, gamma->on_dev, gamma_inv->on_dev, u_i->on_dev, + u_i_sq->on_dev, GammaV->on_dev, GammaV_sq->on_dev, f->on_dev, sr_pressure->on_dev + ); } // CUDA kernel to set device pointers to sr vars kernel functions // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_calc_sr_vars_set_cu_dev_ptrs(struct gkyl_dg_calc_sr_vars *up, - enum gkyl_basis_type b_type, enum gkyl_basis_type b_type_v, - int cdim, int vdim, int poly_order, int poly_order_v) +__global__ static void dg_calc_sr_vars_set_cu_dev_ptrs( + struct gkyl_dg_calc_sr_vars *up, enum gkyl_basis_type b_type, enum gkyl_basis_type b_type_v, + int cdim, int vdim, int poly_order, int poly_order_v +) { up->sr_p_vars = choose_sr_p_vars_kern(b_type_v, vdim, poly_order_v); up->sr_n_set = choose_sr_vars_n_set_kern(b_type, cdim, vdim, poly_order); @@ -264,12 +257,13 @@ dg_calc_sr_vars_set_cu_dev_ptrs(struct gkyl_dg_calc_sr_vars *up, up->sr_pressure = choose_sr_vars_pressure_kern(b_type, cdim, vdim, poly_order); } -gkyl_dg_calc_sr_vars* -gkyl_dg_calc_sr_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, const struct gkyl_rect_grid *vel_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *vel_basis, - const struct gkyl_range *mem_range, const struct gkyl_range *vel_range) +gkyl_dg_calc_sr_vars *gkyl_dg_calc_sr_vars_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_rect_grid *vel_grid, + const struct gkyl_basis *conf_basis, const struct gkyl_basis *vel_basis, + const struct gkyl_range *mem_range, const struct gkyl_range *vel_range +) { - struct gkyl_dg_calc_sr_vars *up = (struct gkyl_dg_calc_sr_vars*) gkyl_malloc(sizeof(*up)); + struct gkyl_dg_calc_sr_vars *up = (struct gkyl_dg_calc_sr_vars *)gkyl_malloc(sizeof(*up)); up->phase_grid = *phase_grid; up->vel_grid = *vel_grid; @@ -287,24 +281,27 @@ gkyl_dg_calc_sr_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, const s int poly_order_v = vel_basis->poly_order; enum gkyl_basis_type b_type_v = vel_basis->b_type; - // Linear system for solving for the drift velocity V_drift = M1i/M0 - // and then computing the rest-frame density n = GammaV_inv*M0 + // Linear system for solving for the drift velocity V_drift = M1i/M0 + // and then computing the rest-frame density n = GammaV_inv*M0 // where GammaV_inv = sqrt(1 - |V_drift|^2) - up->Ncomp = vdim; - up->As = gkyl_nmat_cu_dev_new(up->Ncomp*mem_range->volume, nc, nc); - up->xs = gkyl_nmat_cu_dev_new(up->Ncomp*mem_range->volume, nc, 1); + up->Ncomp = vdim; + up->As = gkyl_nmat_cu_dev_new(up->Ncomp * mem_range->volume, nc, nc); + up->xs = gkyl_nmat_cu_dev_new(up->Ncomp * mem_range->volume, nc, 1); up->mem = gkyl_nmat_linsolve_lu_cu_dev_new(up->As->num, up->As->nr); up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_dg_calc_sr_vars *up_cu = (struct gkyl_dg_calc_sr_vars*) gkyl_cu_malloc(sizeof(*up_cu)); + struct gkyl_dg_calc_sr_vars *up_cu = + (struct gkyl_dg_calc_sr_vars *)gkyl_cu_malloc(sizeof(*up_cu)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_dg_calc_sr_vars), GKYL_CU_MEMCPY_H2D); - dg_calc_sr_vars_set_cu_dev_ptrs<<<1,1>>>(up_cu, b_type, b_type_v, cdim, vdim, poly_order, poly_order_v); + dg_calc_sr_vars_set_cu_dev_ptrs<<<1, 1> > >( + up_cu, b_type, b_type_v, cdim, vdim, poly_order, poly_order_v + ); // set parent on_dev pointer up->on_dev = up_cu; - + return up; } diff --git a/vlasov/zero/dg_canonical_pb.c b/vlasov/zero/dg_canonical_pb.c index d1b5ee3695..1517c8d1b3 100644 --- a/vlasov/zero/dg_canonical_pb.c +++ b/vlasov/zero/dg_canonical_pb.c @@ -9,23 +9,23 @@ #include #include "gkyl_dg_eqn.h" -void -gkyl_canonical_pb_free(const struct gkyl_ref_count *ref) +void gkyl_canonical_pb_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); - + if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object struct dg_canonical_pb *canonical_pb = container_of(base->on_dev, struct dg_canonical_pb, eqn); gkyl_cu_free(canonical_pb); } - + struct dg_canonical_pb *canonical_pb = container_of(base, struct dg_canonical_pb, eqn); gkyl_free(canonical_pb); } -void -gkyl_canonical_pb_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_auxfields auxin) +void gkyl_canonical_pb_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_dg_eqn_is_cu_dev(eqn)) { @@ -41,19 +41,19 @@ gkyl_canonical_pb_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_ca canonical_pb->auxfields.const_sgn_alpha = auxin.const_sgn_alpha; } -struct gkyl_dg_eqn* -gkyl_dg_canonical_pb_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* phase_range, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_canonical_pb_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_canonical_pb_cu_dev_new(cbasis, pbasis, phase_range); - } + } #endif struct dg_canonical_pb *canonical_pb = gkyl_malloc(sizeof(struct dg_canonical_pb)); - - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; canonical_pb->cdim = cdim; @@ -65,104 +65,128 @@ gkyl_dg_canonical_pb_new(const struct gkyl_basis* cbasis, const struct gkyl_basi canonical_pb->eqn.boundary_diag_term = boundary_diag; const gkyl_dg_canonical_pb_vol_kern_list *vol_kernels; - const gkyl_dg_canonical_pb_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, *stream_surf_z_kernels; - const gkyl_dg_canonical_pb_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, *accel_surf_vz_kernels; - const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list *stream_boundary_surf_x_kernels, *stream_boundary_surf_y_kernels, - *stream_boundary_surf_z_kernels; - const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, *accel_boundary_surf_vy_kernels, - *accel_boundary_surf_vz_kernels; - + const gkyl_dg_canonical_pb_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, + *stream_surf_z_kernels; + const gkyl_dg_canonical_pb_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, + *accel_surf_vz_kernels; + const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list *stream_boundary_surf_x_kernels, + *stream_boundary_surf_y_kernels, *stream_boundary_surf_z_kernels; + const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, + *accel_boundary_surf_vy_kernels, *accel_boundary_surf_vz_kernels; + switch (pbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Verify that the poly-order is 2 for ser case - assert(poly_order == 2); - vol_kernels = ser_vol_kernels; - stream_surf_x_kernels = ser_stream_surf_x_kernels; - stream_surf_y_kernels = ser_stream_surf_y_kernels; - stream_surf_z_kernels = ser_stream_surf_z_kernels; - accel_surf_vx_kernels = ser_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_accel_surf_vz_kernels; - stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; - accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; - break; - - case GKYL_BASIS_MODAL_HYBRID: - // Verify that the poly-order is 1 for hybrid case - assert(poly_order == 1); - vol_kernels = ser_vol_kernels; - stream_surf_x_kernels = ser_stream_surf_x_kernels; - stream_surf_y_kernels = ser_stream_surf_y_kernels; - stream_surf_z_kernels = ser_stream_surf_z_kernels; - accel_surf_vx_kernels = ser_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_accel_surf_vz_kernels; - stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; - accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = tensor_vol_kernels; - stream_surf_x_kernels = tensor_stream_surf_x_kernels; - stream_surf_y_kernels = tensor_stream_surf_y_kernels; - stream_surf_z_kernels = tensor_stream_surf_z_kernels; - accel_surf_vx_kernels = tensor_accel_surf_vx_kernels; - accel_surf_vy_kernels = tensor_accel_surf_vy_kernels; - accel_surf_vz_kernels = tensor_accel_surf_vz_kernels; - stream_boundary_surf_x_kernels = tensor_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = tensor_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = tensor_stream_boundary_surf_z_kernels; - accel_boundary_surf_vx_kernels = tensor_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = tensor_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = tensor_accel_boundary_surf_vz_kernels; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + // Verify that the poly-order is 2 for ser case + assert(poly_order == 2); + vol_kernels = ser_vol_kernels; + stream_surf_x_kernels = ser_stream_surf_x_kernels; + stream_surf_y_kernels = ser_stream_surf_y_kernels; + stream_surf_z_kernels = ser_stream_surf_z_kernels; + accel_surf_vx_kernels = ser_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_accel_surf_vz_kernels; + stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; + accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; + break; + + case GKYL_BASIS_MODAL_HYBRID: + // Verify that the poly-order is 1 for hybrid case + assert(poly_order == 1); + vol_kernels = ser_vol_kernels; + stream_surf_x_kernels = ser_stream_surf_x_kernels; + stream_surf_y_kernels = ser_stream_surf_y_kernels; + stream_surf_z_kernels = ser_stream_surf_z_kernels; + accel_surf_vx_kernels = ser_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_accel_surf_vz_kernels; + stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; + accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = tensor_vol_kernels; + stream_surf_x_kernels = tensor_stream_surf_x_kernels; + stream_surf_y_kernels = tensor_stream_surf_y_kernels; + stream_surf_z_kernels = tensor_stream_surf_z_kernels; + accel_surf_vx_kernels = tensor_accel_surf_vx_kernels; + accel_surf_vy_kernels = tensor_accel_surf_vy_kernels; + accel_surf_vz_kernels = tensor_accel_surf_vz_kernels; + stream_boundary_surf_x_kernels = tensor_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = tensor_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = tensor_stream_boundary_surf_z_kernels; + accel_boundary_surf_vx_kernels = tensor_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = tensor_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = tensor_accel_boundary_surf_vz_kernels; + break; + + default: + assert(false); + break; + } int cv_index_val = cv_index[cdim].vdim[vdim]; - canonical_pb->eqn.vol_term = CK(vol_kernels,cv_index_val,poly_order); - - canonical_pb->stream_surf[0] = CK(stream_surf_x_kernels,cv_index_val,poly_order); - if (cdim>1) - canonical_pb->stream_surf[1] = CK(stream_surf_y_kernels,cv_index_val,poly_order); - if (cdim>2) - canonical_pb->stream_surf[2] = CK(stream_surf_z_kernels,cv_index_val,poly_order); - - canonical_pb->accel_surf[0] = CK(accel_surf_vx_kernels,cv_index_val,poly_order); - if (vdim>1) - canonical_pb->accel_surf[1] = CK(accel_surf_vy_kernels,cv_index_val,poly_order); - if (vdim>2) - canonical_pb->accel_surf[2] = CK(accel_surf_vz_kernels,cv_index_val,poly_order); - - canonical_pb->stream_boundary_surf[0] = CK(stream_boundary_surf_x_kernels,cv_index_val,poly_order); - if (cdim>1) - canonical_pb->stream_boundary_surf[1] = CK(stream_boundary_surf_y_kernels,cv_index_val,poly_order); - if (cdim>2) - canonical_pb->stream_boundary_surf[2] = CK(stream_boundary_surf_z_kernels,cv_index_val,poly_order); - - canonical_pb->accel_boundary_surf[0] = CK(accel_boundary_surf_vx_kernels,cv_index_val,poly_order); - if (vdim>1) - canonical_pb->accel_boundary_surf[1] = CK(accel_boundary_surf_vy_kernels,cv_index_val,poly_order); - if (vdim>2) - canonical_pb->accel_boundary_surf[2] = CK(accel_boundary_surf_vz_kernels,cv_index_val,poly_order); + canonical_pb->eqn.vol_term = CK(vol_kernels, cv_index_val, poly_order); + + canonical_pb->stream_surf[0] = CK(stream_surf_x_kernels, cv_index_val, poly_order); + if (cdim > 1) { + canonical_pb->stream_surf[1] = CK(stream_surf_y_kernels, cv_index_val, poly_order); + } + if (cdim > 2) { + canonical_pb->stream_surf[2] = CK(stream_surf_z_kernels, cv_index_val, poly_order); + } + + canonical_pb->accel_surf[0] = CK(accel_surf_vx_kernels, cv_index_val, poly_order); + if (vdim > 1) { + canonical_pb->accel_surf[1] = CK(accel_surf_vy_kernels, cv_index_val, poly_order); + } + if (vdim > 2) { + canonical_pb->accel_surf[2] = CK(accel_surf_vz_kernels, cv_index_val, poly_order); + } + + canonical_pb->stream_boundary_surf[0] = + CK(stream_boundary_surf_x_kernels, cv_index_val, poly_order); + if (cdim > 1) { + canonical_pb->stream_boundary_surf[1] = + CK(stream_boundary_surf_y_kernels, cv_index_val, poly_order); + } + if (cdim > 2) { + canonical_pb->stream_boundary_surf[2] = + CK(stream_boundary_surf_z_kernels, cv_index_val, poly_order); + } + + canonical_pb->accel_boundary_surf[0] = + CK(accel_boundary_surf_vx_kernels, cv_index_val, poly_order); + if (vdim > 1) { + canonical_pb->accel_boundary_surf[1] = + CK(accel_boundary_surf_vy_kernels, cv_index_val, poly_order); + } + if (vdim > 2) { + canonical_pb->accel_boundary_surf[2] = + CK(accel_boundary_surf_vz_kernels, cv_index_val, poly_order); + } // ensure non-NULL pointers - for (int i=0; istream_surf[i]); - for (int i=0; iaccel_surf[i]); - for (int i=0; iaccel_boundary_surf[i]); - for (int i=0; istream_boundary_surf[i]); + for (int i = 0; i < cdim; ++i) { + assert(canonical_pb->stream_surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(canonical_pb->accel_surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(canonical_pb->accel_boundary_surf[i]); + } + for (int i = 0; i < cdim; ++i) { + assert(canonical_pb->stream_boundary_surf[i]); + } - canonical_pb->auxfields.hamil = 0; + canonical_pb->auxfields.hamil = 0; canonical_pb->auxfields.alpha_surf = 0; canonical_pb->auxfields.sgn_alpha_surf = 0; canonical_pb->auxfields.const_sgn_alpha = 0; @@ -173,15 +197,16 @@ gkyl_dg_canonical_pb_new(const struct gkyl_basis* cbasis, const struct gkyl_basi canonical_pb->eqn.ref_count = gkyl_ref_count_init(gkyl_canonical_pb_free); canonical_pb->eqn.on_dev = &canonical_pb->eqn; // CPU eqn obj points to itself - + return &canonical_pb->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_canonical_pb_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* phase_range) +struct gkyl_dg_eqn *gkyl_dg_canonical_pb_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range +) { assert(false); return 0; diff --git a/vlasov/zero/dg_canonical_pb_cu.cu b/vlasov/zero/dg_canonical_pb_cu.cu index 42c072cea8..0738113031 100644 --- a/vlasov/zero/dg_canonical_pb_cu.cu +++ b/vlasov/zero/dg_canonical_pb_cu.cu @@ -17,10 +17,11 @@ extern "C" { // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_canonical_pb_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array *hamil, const struct gkyl_array *alpha_surf, - const struct gkyl_array *sgn_alpha_surf, const struct gkyl_array *const_sgn_alpha) +__global__ static void gkyl_canonical_pb_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *hamil, + const struct gkyl_array *alpha_surf, const struct gkyl_array *sgn_alpha_surf, + const struct gkyl_array *const_sgn_alpha +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); canonical_pb->auxfields.hamil = hamil; @@ -29,22 +30,24 @@ gkyl_canonical_pb_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, canonical_pb->auxfields.const_sgn_alpha = const_sgn_alpha; } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_canonical_pb_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_auxfields auxin) +void gkyl_canonical_pb_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_auxfields auxin +) { - gkyl_canonical_pb_set_auxfields_cu_kernel<<<1,1>>>(eqn, - auxin.hamil->on_dev, auxin.alpha_surf->on_dev, - auxin.sgn_alpha_surf->on_dev, auxin.const_sgn_alpha->on_dev); + gkyl_canonical_pb_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.hamil->on_dev, auxin.alpha_surf->on_dev, auxin.sgn_alpha_surf->on_dev, + auxin.const_sgn_alpha->on_dev + ); } // CUDA kernel to set device pointers to range object and canonical_pb kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_canonical_pb_set_cu_dev_ptrs(struct dg_canonical_pb *canonical_pb, enum gkyl_basis_type b_type, int cv_index, - int cdim, int vdim, int poly_order) +__global__ static void dg_canonical_pb_set_cu_dev_ptrs( + struct dg_canonical_pb *canonical_pb, enum gkyl_basis_type b_type, int cv_index, int cdim, + int vdim, int poly_order +) { - - canonical_pb->auxfields.hamil = 0; + canonical_pb->auxfields.hamil = 0; canonical_pb->auxfields.alpha_surf = 0; canonical_pb->auxfields.sgn_alpha_surf = 0; canonical_pb->auxfields.const_sgn_alpha = 0; @@ -54,108 +57,119 @@ dg_canonical_pb_set_cu_dev_ptrs(struct dg_canonical_pb *canonical_pb, enum gkyl_ canonical_pb->eqn.boundary_diag_term = boundary_diag; const gkyl_dg_canonical_pb_vol_kern_list *vol_kernels; - const gkyl_dg_canonical_pb_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, *stream_surf_z_kernels; - const gkyl_dg_canonical_pb_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, *accel_surf_vz_kernels; - const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list *stream_boundary_surf_x_kernels, *stream_boundary_surf_y_kernels, - *stream_boundary_surf_z_kernels; - const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, *accel_boundary_surf_vy_kernels, - *accel_boundary_surf_vz_kernels; - + const gkyl_dg_canonical_pb_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, + *stream_surf_z_kernels; + const gkyl_dg_canonical_pb_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, + *accel_surf_vz_kernels; + const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list *stream_boundary_surf_x_kernels, + *stream_boundary_surf_y_kernels, *stream_boundary_surf_z_kernels; + const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, + *accel_boundary_surf_vy_kernels, *accel_boundary_surf_vz_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Verify that the poly-order is 2 for ser case - assert(poly_order == 2); - vol_kernels = ser_vol_kernels; - stream_surf_x_kernels = ser_stream_surf_x_kernels; - stream_surf_y_kernels = ser_stream_surf_y_kernels; - stream_surf_z_kernels = ser_stream_surf_z_kernels; - accel_surf_vx_kernels = ser_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_accel_surf_vz_kernels; - stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; - accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; - break; - - case GKYL_BASIS_MODAL_HYBRID: - // Verify that the poly-order is 1 for hybrid case - assert(poly_order == 1); - vol_kernels = ser_vol_kernels; - stream_surf_x_kernels = ser_stream_surf_x_kernels; - stream_surf_y_kernels = ser_stream_surf_y_kernels; - stream_surf_z_kernels = ser_stream_surf_z_kernels; - accel_surf_vx_kernels = ser_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_accel_surf_vz_kernels; - stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; - accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = tensor_vol_kernels; - stream_surf_x_kernels = tensor_stream_surf_x_kernels; - stream_surf_y_kernels = tensor_stream_surf_y_kernels; - stream_surf_z_kernels = tensor_stream_surf_z_kernels; - accel_surf_vx_kernels = tensor_accel_surf_vx_kernels; - accel_surf_vy_kernels = tensor_accel_surf_vy_kernels; - accel_surf_vz_kernels = tensor_accel_surf_vz_kernels; - stream_boundary_surf_x_kernels = tensor_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = tensor_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = tensor_stream_boundary_surf_z_kernels; - accel_boundary_surf_vx_kernels = tensor_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = tensor_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = tensor_accel_boundary_surf_vz_kernels; - break; - - default: - assert(false); - break; - } - - canonical_pb->eqn.vol_term = CK(vol_kernels,cv_index,poly_order); - - canonical_pb->stream_surf[0] = CK(stream_surf_x_kernels,cv_index,poly_order); - if (cdim>1) - canonical_pb->stream_surf[1] = CK(stream_surf_y_kernels,cv_index,poly_order); - if (cdim>2) - canonical_pb->stream_surf[2] = CK(stream_surf_z_kernels,cv_index,poly_order); - - canonical_pb->accel_surf[0] = CK(accel_surf_vx_kernels,cv_index,poly_order); - if (vdim>1) - canonical_pb->accel_surf[1] = CK(accel_surf_vy_kernels,cv_index,poly_order); - if (vdim>2) - canonical_pb->accel_surf[2] = CK(accel_surf_vz_kernels,cv_index,poly_order); - - canonical_pb->stream_boundary_surf[0] = CK(stream_boundary_surf_x_kernels,cv_index,poly_order); - if (cdim>1) - canonical_pb->stream_boundary_surf[1] = CK(stream_boundary_surf_y_kernels,cv_index,poly_order); - if (cdim>2) - canonical_pb->stream_boundary_surf[2] = CK(stream_boundary_surf_z_kernels,cv_index,poly_order); - - canonical_pb->accel_boundary_surf[0] = CK(accel_boundary_surf_vx_kernels,cv_index,poly_order); - if (vdim>1) - canonical_pb->accel_boundary_surf[1] = CK(accel_boundary_surf_vy_kernels,cv_index,poly_order); - if (vdim>2) - canonical_pb->accel_boundary_surf[2] = CK(accel_boundary_surf_vz_kernels,cv_index,poly_order); + case GKYL_BASIS_MODAL_SERENDIPITY: + // Verify that the poly-order is 2 for ser case + assert(poly_order == 2); + vol_kernels = ser_vol_kernels; + stream_surf_x_kernels = ser_stream_surf_x_kernels; + stream_surf_y_kernels = ser_stream_surf_y_kernels; + stream_surf_z_kernels = ser_stream_surf_z_kernels; + accel_surf_vx_kernels = ser_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_accel_surf_vz_kernels; + stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; + accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; + break; + + case GKYL_BASIS_MODAL_HYBRID: + // Verify that the poly-order is 1 for hybrid case + assert(poly_order == 1); + vol_kernels = ser_vol_kernels; + stream_surf_x_kernels = ser_stream_surf_x_kernels; + stream_surf_y_kernels = ser_stream_surf_y_kernels; + stream_surf_z_kernels = ser_stream_surf_z_kernels; + accel_surf_vx_kernels = ser_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_accel_surf_vz_kernels; + stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; + accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = tensor_vol_kernels; + stream_surf_x_kernels = tensor_stream_surf_x_kernels; + stream_surf_y_kernels = tensor_stream_surf_y_kernels; + stream_surf_z_kernels = tensor_stream_surf_z_kernels; + accel_surf_vx_kernels = tensor_accel_surf_vx_kernels; + accel_surf_vy_kernels = tensor_accel_surf_vy_kernels; + accel_surf_vz_kernels = tensor_accel_surf_vz_kernels; + stream_boundary_surf_x_kernels = tensor_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = tensor_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = tensor_stream_boundary_surf_z_kernels; + accel_boundary_surf_vx_kernels = tensor_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = tensor_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = tensor_accel_boundary_surf_vz_kernels; + break; + + default: + assert(false); + break; + } + + canonical_pb->eqn.vol_term = CK(vol_kernels, cv_index, poly_order); + + canonical_pb->stream_surf[0] = CK(stream_surf_x_kernels, cv_index, poly_order); + if (cdim > 1) { + canonical_pb->stream_surf[1] = CK(stream_surf_y_kernels, cv_index, poly_order); + } + if (cdim > 2) { + canonical_pb->stream_surf[2] = CK(stream_surf_z_kernels, cv_index, poly_order); + } + + canonical_pb->accel_surf[0] = CK(accel_surf_vx_kernels, cv_index, poly_order); + if (vdim > 1) { + canonical_pb->accel_surf[1] = CK(accel_surf_vy_kernels, cv_index, poly_order); + } + if (vdim > 2) { + canonical_pb->accel_surf[2] = CK(accel_surf_vz_kernels, cv_index, poly_order); + } + + canonical_pb->stream_boundary_surf[0] = CK(stream_boundary_surf_x_kernels, cv_index, poly_order); + if (cdim > 1) { + canonical_pb->stream_boundary_surf[1] = + CK(stream_boundary_surf_y_kernels, cv_index, poly_order); + } + if (cdim > 2) { + canonical_pb->stream_boundary_surf[2] = + CK(stream_boundary_surf_z_kernels, cv_index, poly_order); + } + + canonical_pb->accel_boundary_surf[0] = CK(accel_boundary_surf_vx_kernels, cv_index, poly_order); + if (vdim > 1) { + canonical_pb->accel_boundary_surf[1] = CK(accel_boundary_surf_vy_kernels, cv_index, poly_order); + } + if (vdim > 2) { + canonical_pb->accel_boundary_surf[2] = CK(accel_boundary_surf_vz_kernels, cv_index, poly_order); + } } - - -struct gkyl_dg_eqn* -gkyl_dg_canonical_pb_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* phase_range) +struct gkyl_dg_eqn *gkyl_dg_canonical_pb_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range +) { - struct dg_canonical_pb *canonical_pb = (struct dg_canonical_pb*) gkyl_malloc(sizeof(struct dg_canonical_pb)); - + struct dg_canonical_pb *canonical_pb = + (struct dg_canonical_pb *)gkyl_malloc(sizeof(struct dg_canonical_pb)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; canonical_pb->cdim = cdim; @@ -169,10 +183,13 @@ gkyl_dg_canonical_pb_cu_dev_new(const struct gkyl_basis* cbasis, const struct gk canonical_pb->eqn.ref_count = gkyl_ref_count_init(gkyl_canonical_pb_free); // copy the host struct to device struct - struct dg_canonical_pb *canonical_pb_cu = (struct dg_canonical_pb*) gkyl_cu_malloc(sizeof(struct dg_canonical_pb)); + struct dg_canonical_pb *canonical_pb_cu = + (struct dg_canonical_pb *)gkyl_cu_malloc(sizeof(struct dg_canonical_pb)); gkyl_cu_memcpy(canonical_pb_cu, canonical_pb, sizeof(struct dg_canonical_pb), GKYL_CU_MEMCPY_H2D); - dg_canonical_pb_set_cu_dev_ptrs<<<1,1>>>(canonical_pb_cu, pbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order); + dg_canonical_pb_set_cu_dev_ptrs<<<1, 1> > >( + canonical_pb_cu, pbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order + ); // set parent on_dev pointer canonical_pb->eqn.on_dev = &canonical_pb_cu->eqn; diff --git a/vlasov/zero/dg_canonical_pb_fluid.c b/vlasov/zero/dg_canonical_pb_fluid.c index 8290521c94..1a14bd6cfe 100644 --- a/vlasov/zero/dg_canonical_pb_fluid.c +++ b/vlasov/zero/dg_canonical_pb_fluid.c @@ -10,25 +10,27 @@ #include "gkyl_dg_eqn.h" // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_canonical_pb_fluid_free(const struct gkyl_ref_count *ref) +void gkyl_canonical_pb_fluid_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); - + if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object - struct dg_canonical_pb_fluid *can_pb_fluid = container_of(base->on_dev, struct dg_canonical_pb_fluid, eqn); + struct dg_canonical_pb_fluid *can_pb_fluid = + container_of(base->on_dev, struct dg_canonical_pb_fluid, eqn); gkyl_cu_free(can_pb_fluid); } - - struct dg_canonical_pb_fluid *can_pb_fluid = container_of(base, struct dg_canonical_pb_fluid, eqn); + + struct dg_canonical_pb_fluid *can_pb_fluid = + container_of(base, struct dg_canonical_pb_fluid, eqn); gkyl_free(can_pb_fluid); } -void -gkyl_canonical_pb_fluid_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_fluid_auxfields auxin) +void gkyl_canonical_pb_fluid_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_fluid_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_dg_eqn_is_cu_dev(eqn)) { @@ -44,14 +46,15 @@ gkyl_canonical_pb_fluid_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl can_pb_fluid->auxfields.const_sgn_alpha = auxin.const_sgn_alpha; } -struct gkyl_dg_eqn* -gkyl_dg_canonical_pb_fluid_new(const struct gkyl_basis* cbasis, - const struct gkyl_range* conf_range, const struct gkyl_wv_eqn *wv_eqn, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_canonical_pb_fluid_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, + const struct gkyl_wv_eqn *wv_eqn, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_canonical_pb_fluid_cu_dev_new(cbasis, conf_range, wv_eqn); - } + } #endif struct dg_canonical_pb_fluid *can_pb_fluid = gkyl_malloc(sizeof(struct dg_canonical_pb_fluid)); @@ -66,47 +69,47 @@ gkyl_dg_canonical_pb_fluid_new(const struct gkyl_basis* cbasis, const gkyl_dg_canonical_pb_fluid_vol_kern_list *vol_kernels; const gkyl_dg_canonical_pb_fluid_surf_kern_list *surf_x_kernels, *surf_y_kernels; - + switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (can_pb_fluid->eqn.num_equations == 2) { - vol_kernels = ser_two_fluid_vol_kernels; - surf_x_kernels = ser_two_fluid_surf_x_kernels; - surf_y_kernels = ser_two_fluid_surf_y_kernels; - } - else { - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - } - break; - - case GKYL_BASIS_MODAL_TENSOR: - if (can_pb_fluid->eqn.num_equations == 2) { - vol_kernels = tensor_two_fluid_vol_kernels; - surf_x_kernels = tensor_two_fluid_surf_x_kernels; - surf_y_kernels = tensor_two_fluid_surf_y_kernels; - } - else { - vol_kernels = tensor_vol_kernels; - surf_x_kernels = tensor_surf_x_kernels; - surf_y_kernels = tensor_surf_y_kernels; - } - break; - - default: - assert(false); - break; - } - can_pb_fluid->eqn.vol_term = CK(vol_kernels,cdim,poly_order); - - can_pb_fluid->surf[0] = CK(surf_x_kernels,cdim,poly_order); - can_pb_fluid->surf[1] = CK(surf_y_kernels,cdim,poly_order); + case GKYL_BASIS_MODAL_SERENDIPITY: + if (can_pb_fluid->eqn.num_equations == 2) { + vol_kernels = ser_two_fluid_vol_kernels; + surf_x_kernels = ser_two_fluid_surf_x_kernels; + surf_y_kernels = ser_two_fluid_surf_y_kernels; + } else { + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + } + break; + + case GKYL_BASIS_MODAL_TENSOR: + if (can_pb_fluid->eqn.num_equations == 2) { + vol_kernels = tensor_two_fluid_vol_kernels; + surf_x_kernels = tensor_two_fluid_surf_x_kernels; + surf_y_kernels = tensor_two_fluid_surf_y_kernels; + } else { + vol_kernels = tensor_vol_kernels; + surf_x_kernels = tensor_surf_x_kernels; + surf_y_kernels = tensor_surf_y_kernels; + } + break; + + default: + assert(false); + break; + } + can_pb_fluid->eqn.vol_term = CK(vol_kernels, cdim, poly_order); + + can_pb_fluid->surf[0] = CK(surf_x_kernels, cdim, poly_order); + can_pb_fluid->surf[1] = CK(surf_y_kernels, cdim, poly_order); // ensure non-NULL pointers - for (int i=0; isurf[i]); + for (int i = 0; i < cdim; ++i) { + assert(can_pb_fluid->surf[i]); + } - can_pb_fluid->auxfields.phi = 0; + can_pb_fluid->auxfields.phi = 0; can_pb_fluid->auxfields.alpha_surf = 0; can_pb_fluid->auxfields.sgn_alpha_surf = 0; can_pb_fluid->auxfields.const_sgn_alpha = 0; @@ -117,15 +120,16 @@ gkyl_dg_canonical_pb_fluid_new(const struct gkyl_basis* cbasis, can_pb_fluid->eqn.ref_count = gkyl_ref_count_init(gkyl_canonical_pb_fluid_free); can_pb_fluid->eqn.on_dev = &can_pb_fluid->eqn; // CPU eqn obj points to itself - + return &can_pb_fluid->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_canonical_pb_fluid_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_range* conf_range, const struct gkyl_wv_eqn *wv_eqn) +struct gkyl_dg_eqn *gkyl_dg_canonical_pb_fluid_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, + const struct gkyl_wv_eqn *wv_eqn +) { assert(false); return 0; diff --git a/vlasov/zero/dg_canonical_pb_fluid_cu.cu b/vlasov/zero/dg_canonical_pb_fluid_cu.cu index dffdc289ff..8d6707b476 100644 --- a/vlasov/zero/dg_canonical_pb_fluid_cu.cu +++ b/vlasov/zero/dg_canonical_pb_fluid_cu.cu @@ -15,15 +15,15 @@ extern "C" { #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_canonical_pb_fluid_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array *phi, const struct gkyl_array *alpha_surf, - const struct gkyl_array *sgn_alpha_surf, const struct gkyl_array *const_sgn_alpha) +__global__ static void gkyl_canonical_pb_fluid_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *phi, const struct gkyl_array *alpha_surf, + const struct gkyl_array *sgn_alpha_surf, const struct gkyl_array *const_sgn_alpha +) { struct dg_canonical_pb_fluid *can_pb_fluid = container_of(eqn, struct dg_canonical_pb_fluid, eqn); can_pb_fluid->auxfields.phi = phi; @@ -32,22 +32,24 @@ gkyl_canonical_pb_fluid_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, can_pb_fluid->auxfields.const_sgn_alpha = const_sgn_alpha; } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_canonical_pb_fluid_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_fluid_auxfields auxin) +void gkyl_canonical_pb_fluid_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_fluid_auxfields auxin +) { - gkyl_canonical_pb_fluid_set_auxfields_cu_kernel<<<1,1>>>(eqn, - auxin.phi->on_dev, auxin.alpha_surf->on_dev, - auxin.sgn_alpha_surf->on_dev, auxin.const_sgn_alpha->on_dev); + gkyl_canonical_pb_fluid_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.phi->on_dev, auxin.alpha_surf->on_dev, auxin.sgn_alpha_surf->on_dev, + auxin.const_sgn_alpha->on_dev + ); } // CUDA kernel to set device pointers to range object and canonical_pb_fluid kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_canonical_pb_fluid_set_cu_dev_ptrs(struct dg_canonical_pb_fluid *can_pb_fluid, enum gkyl_basis_type b_type, - int cdim, int poly_order, int num_equations) +__global__ static void dg_canonical_pb_fluid_set_cu_dev_ptrs( + struct dg_canonical_pb_fluid *can_pb_fluid, enum gkyl_basis_type b_type, int cdim, int poly_order, + int num_equations +) { - - can_pb_fluid->auxfields.phi = 0; + can_pb_fluid->auxfields.phi = 0; can_pb_fluid->auxfields.alpha_surf = 0; can_pb_fluid->auxfields.sgn_alpha_surf = 0; can_pb_fluid->auxfields.const_sgn_alpha = 0; @@ -56,53 +58,50 @@ dg_canonical_pb_fluid_set_cu_dev_ptrs(struct dg_canonical_pb_fluid *can_pb_fluid const gkyl_dg_canonical_pb_fluid_vol_kern_list *vol_kernels; const gkyl_dg_canonical_pb_fluid_surf_kern_list *surf_x_kernels, *surf_y_kernels; - + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (num_equations == 2) { - vol_kernels = ser_two_fluid_vol_kernels; - surf_x_kernels = ser_two_fluid_surf_x_kernels; - surf_y_kernels = ser_two_fluid_surf_y_kernels; - } - else { - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - } - break; - - case GKYL_BASIS_MODAL_TENSOR: - if (num_equations == 2) { - vol_kernels = tensor_two_fluid_vol_kernels; - surf_x_kernels = tensor_two_fluid_surf_x_kernels; - surf_y_kernels = tensor_two_fluid_surf_y_kernels; - } - else { - vol_kernels = tensor_vol_kernels; - surf_x_kernels = tensor_surf_x_kernels; - surf_y_kernels = tensor_surf_y_kernels; - } - break; - - default: - assert(false); - break; - } - - can_pb_fluid->eqn.vol_term = CK(vol_kernels,cdim,poly_order); - - can_pb_fluid->surf[0] = CK(surf_x_kernels,cdim,poly_order); - can_pb_fluid->surf[1] = CK(surf_y_kernels,cdim,poly_order); + case GKYL_BASIS_MODAL_SERENDIPITY: + if (num_equations == 2) { + vol_kernels = ser_two_fluid_vol_kernels; + surf_x_kernels = ser_two_fluid_surf_x_kernels; + surf_y_kernels = ser_two_fluid_surf_y_kernels; + } else { + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + } + break; + + case GKYL_BASIS_MODAL_TENSOR: + if (num_equations == 2) { + vol_kernels = tensor_two_fluid_vol_kernels; + surf_x_kernels = tensor_two_fluid_surf_x_kernels; + surf_y_kernels = tensor_two_fluid_surf_y_kernels; + } else { + vol_kernels = tensor_vol_kernels; + surf_x_kernels = tensor_surf_x_kernels; + surf_y_kernels = tensor_surf_y_kernels; + } + break; + + default: + assert(false); + break; + } + + can_pb_fluid->eqn.vol_term = CK(vol_kernels, cdim, poly_order); + + can_pb_fluid->surf[0] = CK(surf_x_kernels, cdim, poly_order); + can_pb_fluid->surf[1] = CK(surf_y_kernels, cdim, poly_order); } - - -struct gkyl_dg_eqn* -gkyl_dg_canonical_pb_fluid_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_range* conf_range, const struct gkyl_wv_eqn *wv_eqn) +struct gkyl_dg_eqn *gkyl_dg_canonical_pb_fluid_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, + const struct gkyl_wv_eqn *wv_eqn +) { - struct dg_canonical_pb_fluid *can_pb_fluid = (struct dg_canonical_pb_fluid*) gkyl_malloc(sizeof(struct dg_canonical_pb_fluid)); - + struct dg_canonical_pb_fluid *can_pb_fluid = + (struct dg_canonical_pb_fluid *)gkyl_malloc(sizeof(struct dg_canonical_pb_fluid)); int cdim = cbasis->ndim; int poly_order = cbasis->poly_order; @@ -119,10 +118,15 @@ gkyl_dg_canonical_pb_fluid_cu_dev_new(const struct gkyl_basis* cbasis, can_pb_fluid->eqn.ref_count = gkyl_ref_count_init(gkyl_canonical_pb_fluid_free); // copy the host struct to device struct - struct dg_canonical_pb_fluid *can_pb_fluid_cu = (struct dg_canonical_pb_fluid*) gkyl_cu_malloc(sizeof(struct dg_canonical_pb_fluid)); - gkyl_cu_memcpy(can_pb_fluid_cu, can_pb_fluid, sizeof(struct dg_canonical_pb_fluid), GKYL_CU_MEMCPY_H2D); - - dg_canonical_pb_fluid_set_cu_dev_ptrs<<<1,1>>>(can_pb_fluid_cu, cbasis->b_type, cdim, poly_order, num_equations); + struct dg_canonical_pb_fluid *can_pb_fluid_cu = + (struct dg_canonical_pb_fluid *)gkyl_cu_malloc(sizeof(struct dg_canonical_pb_fluid)); + gkyl_cu_memcpy( + can_pb_fluid_cu, can_pb_fluid, sizeof(struct dg_canonical_pb_fluid), GKYL_CU_MEMCPY_H2D + ); + + dg_canonical_pb_fluid_set_cu_dev_ptrs<<<1, 1> > >( + can_pb_fluid_cu, cbasis->b_type, cdim, poly_order, num_equations + ); // set parent on_dev pointer can_pb_fluid->eqn.on_dev = &can_pb_fluid_cu->eqn; diff --git a/vlasov/zero/dg_diffusion_fluid.c b/vlasov/zero/dg_diffusion_fluid.c index c72985bceb..9703c0bc03 100644 --- a/vlasov/zero/dg_diffusion_fluid.c +++ b/vlasov/zero/dg_diffusion_fluid.c @@ -8,23 +8,24 @@ #include #include -void -gkyl_dg_diffusion_fluid_free(const struct gkyl_ref_count *ref) +void gkyl_dg_diffusion_fluid_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object - struct dg_diffusion_fluid *diffusion = container_of(base->on_dev, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = + container_of(base->on_dev, struct dg_diffusion_fluid, eqn); gkyl_cu_free(diffusion); } - + struct dg_diffusion_fluid *diffusion = container_of(base, struct dg_diffusion_fluid, eqn); gkyl_free(diffusion); } -void -gkyl_dg_diffusion_fluid_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_fluid_auxfields auxin) +void gkyl_dg_diffusion_fluid_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_fluid_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(auxin.D)) { @@ -32,20 +33,24 @@ gkyl_dg_diffusion_fluid_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl return; } #endif - + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); diffusion->auxfields.D = auxin.D; } -struct gkyl_dg_eqn* -gkyl_dg_diffusion_fluid_new(const struct gkyl_basis *basis, bool is_diff_const, int num_equations, - const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_diffusion_fluid_new( + const struct gkyl_basis *basis, bool is_diff_const, int num_equations, const bool *diff_in_dir, + int diff_order, const struct gkyl_range *diff_range, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) - return gkyl_dg_diffusion_fluid_cu_dev_new(basis, is_diff_const, num_equations, diff_in_dir, diff_order, diff_range); + if (use_gpu) { + return gkyl_dg_diffusion_fluid_cu_dev_new( + basis, is_diff_const, num_equations, diff_in_dir, diff_order, diff_range + ); + } #endif - + struct dg_diffusion_fluid *diffusion = gkyl_malloc(sizeof(struct dg_diffusion_fluid)); int ndim = basis->ndim; @@ -54,41 +59,56 @@ gkyl_dg_diffusion_fluid_new(const struct gkyl_basis *basis, bool is_diff_const, diffusion->num_equations = num_equations; diffusion->const_coeff = is_diff_const; diffusion->num_basis = basis->num_basis; - for (int d=0; ddiff_in_dir[d] = diff_in_dir[d]; + for (int d = 0; d < ndim; d++) { + diffusion->diff_in_dir[d] = diff_in_dir[d]; + } const gkyl_dg_diffusion_fluid_vol_kern_list *vol_kernels; const gkyl_dg_diffusion_fluid_surf_kern_list *surfx_kernels; const gkyl_dg_diffusion_fluid_surf_kern_list *surfy_kernels; - const gkyl_dg_diffusion_fluid_surf_kern_list *surfz_kernels; + const gkyl_dg_diffusion_fluid_surf_kern_list *surfz_kernels; const gkyl_dg_diffusion_fluid_boundary_surf_kern_list *boundary_surfx_kernels; const gkyl_dg_diffusion_fluid_boundary_surf_kern_list *boundary_surfy_kernels; - const gkyl_dg_diffusion_fluid_boundary_surf_kern_list *boundary_surfz_kernels; + const gkyl_dg_diffusion_fluid_boundary_surf_kern_list *boundary_surfz_kernels; switch (basis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = diffusion->const_coeff? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff ; - surfx_kernels = diffusion->const_coeff? ser_surfx_kernels_constcoeff : ser_surfx_kernels_varcoeff ; - surfy_kernels = diffusion->const_coeff? ser_surfy_kernels_constcoeff : ser_surfy_kernels_varcoeff ; - surfz_kernels = diffusion->const_coeff? ser_surfz_kernels_constcoeff : ser_surfz_kernels_varcoeff ; - boundary_surfx_kernels = diffusion->const_coeff? ser_boundary_surfx_kernels_constcoeff : ser_boundary_surfx_kernels_varcoeff; - boundary_surfy_kernels = diffusion->const_coeff? ser_boundary_surfy_kernels_constcoeff : ser_boundary_surfy_kernels_varcoeff; - boundary_surfz_kernels = diffusion->const_coeff? ser_boundary_surfz_kernels_constcoeff : ser_boundary_surfz_kernels_varcoeff; - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = diffusion->const_coeff? tensor_vol_kernels_constcoeff : tensor_vol_kernels_varcoeff ; - surfx_kernels = diffusion->const_coeff? tensor_surfx_kernels_constcoeff : tensor_surfx_kernels_varcoeff ; - surfy_kernels = diffusion->const_coeff? tensor_surfy_kernels_constcoeff : tensor_surfy_kernels_varcoeff ; - surfz_kernels = diffusion->const_coeff? tensor_surfz_kernels_constcoeff : tensor_surfz_kernels_varcoeff ; - boundary_surfx_kernels = diffusion->const_coeff? tensor_boundary_surfx_kernels_constcoeff : tensor_boundary_surfx_kernels_varcoeff; - boundary_surfy_kernels = diffusion->const_coeff? tensor_boundary_surfy_kernels_constcoeff : tensor_boundary_surfy_kernels_varcoeff; - boundary_surfz_kernels = diffusion->const_coeff? tensor_boundary_surfz_kernels_constcoeff : tensor_boundary_surfz_kernels_varcoeff; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = diffusion->const_coeff ? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff; + surfx_kernels = diffusion->const_coeff ? ser_surfx_kernels_constcoeff : + ser_surfx_kernels_varcoeff; + surfy_kernels = diffusion->const_coeff ? ser_surfy_kernels_constcoeff : + ser_surfy_kernels_varcoeff; + surfz_kernels = diffusion->const_coeff ? ser_surfz_kernels_constcoeff : + ser_surfz_kernels_varcoeff; + boundary_surfx_kernels = diffusion->const_coeff ? ser_boundary_surfx_kernels_constcoeff : + ser_boundary_surfx_kernels_varcoeff; + boundary_surfy_kernels = diffusion->const_coeff ? ser_boundary_surfy_kernels_constcoeff : + ser_boundary_surfy_kernels_varcoeff; + boundary_surfz_kernels = diffusion->const_coeff ? ser_boundary_surfz_kernels_constcoeff : + ser_boundary_surfz_kernels_varcoeff; + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = diffusion->const_coeff ? tensor_vol_kernels_constcoeff : + tensor_vol_kernels_varcoeff; + surfx_kernels = diffusion->const_coeff ? tensor_surfx_kernels_constcoeff : + tensor_surfx_kernels_varcoeff; + surfy_kernels = diffusion->const_coeff ? tensor_surfy_kernels_constcoeff : + tensor_surfy_kernels_varcoeff; + surfz_kernels = diffusion->const_coeff ? tensor_surfz_kernels_constcoeff : + tensor_surfz_kernels_varcoeff; + boundary_surfx_kernels = diffusion->const_coeff ? tensor_boundary_surfx_kernels_constcoeff : + tensor_boundary_surfx_kernels_varcoeff; + boundary_surfy_kernels = diffusion->const_coeff ? tensor_boundary_surfy_kernels_constcoeff : + tensor_boundary_surfy_kernels_varcoeff; + boundary_surfz_kernels = diffusion->const_coeff ? tensor_boundary_surfz_kernels_constcoeff : + tensor_boundary_surfz_kernels_varcoeff; + break; + + default: + assert(false); + break; + } int dirs_linidx = diffdirs_linidx(diff_in_dir, ndim); @@ -99,19 +119,25 @@ gkyl_dg_diffusion_fluid_new(const struct gkyl_basis *basis, bool is_diff_const, diffusion->eqn.vol_term = CKVOL(vol_kernels, ndim, diff_order, poly_order, dirs_linidx); diffusion->surf[0] = CKSURF(surfx_kernels, diff_order, ndim, poly_order); - if (ndim>1) + if (ndim > 1) { diffusion->surf[1] = CKSURF(surfy_kernels, diff_order, ndim, poly_order); - if (ndim>2) + } + if (ndim > 2) { diffusion->surf[2] = CKSURF(surfz_kernels, diff_order, ndim, poly_order); + } diffusion->boundary_surf[0] = CKSURF(boundary_surfx_kernels, diff_order, ndim, poly_order); - if (ndim>1) + if (ndim > 1) { diffusion->boundary_surf[1] = CKSURF(boundary_surfy_kernels, diff_order, ndim, poly_order); - if (ndim>2) + } + if (ndim > 2) { diffusion->boundary_surf[2] = CKSURF(boundary_surfz_kernels, diff_order, ndim, poly_order); + } // Ensure non-NULL pointers. - for (int i=0; isurf[i]); + for (int i = 0; i < ndim; ++i) { + assert(diffusion->surf[i]); + } diffusion->auxfields.D = 0; diffusion->diff_range = *diff_range; @@ -119,6 +145,6 @@ gkyl_dg_diffusion_fluid_new(const struct gkyl_basis *basis, bool is_diff_const, diffusion->eqn.flags = 0; diffusion->eqn.ref_count = gkyl_ref_count_init(gkyl_dg_diffusion_fluid_free); diffusion->eqn.on_dev = &diffusion->eqn; - + return &diffusion->eqn; } diff --git a/vlasov/zero/dg_diffusion_fluid_cu.cu b/vlasov/zero/dg_diffusion_fluid_cu.cu index 1d03e848e2..2280840485 100644 --- a/vlasov/zero/dg_diffusion_fluid_cu.cu +++ b/vlasov/zero/dg_diffusion_fluid_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include } @@ -12,24 +12,28 @@ extern "C" { // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_dg_diffusion_fluid_set_auxfields_cu_kernel(const struct gkyl_dg_eqn* eqn, const struct gkyl_array* D) +__global__ static void gkyl_dg_diffusion_fluid_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *D +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); diffusion->auxfields.D = D; } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_dg_diffusion_fluid_set_auxfields_cu(const struct gkyl_dg_eqn* eqn, struct gkyl_dg_diffusion_fluid_auxfields auxin) +void gkyl_dg_diffusion_fluid_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_fluid_auxfields auxin +) { - gkyl_dg_diffusion_fluid_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.D->on_dev); + gkyl_dg_diffusion_fluid_set_auxfields_cu_kernel<<<1, 1> > >(eqn, auxin.D->on_dev); } -__global__ void static -dg_diffusion_fluid_set_cu_dev_ptrs(struct dg_diffusion_fluid *diffusion, enum gkyl_basis_type b_type, int cdim, int poly_order, int diff_order, int diffdirs_linidx) +__global__ void static dg_diffusion_fluid_set_cu_dev_ptrs( + struct dg_diffusion_fluid *diffusion, enum gkyl_basis_type b_type, int cdim, int poly_order, + int diff_order, int diffdirs_linidx +) { - diffusion->auxfields.D = 0; + diffusion->auxfields.D = 0; const gkyl_dg_diffusion_fluid_vol_kern_list *vol_kernels; const gkyl_dg_diffusion_fluid_surf_kern_list *surfx_kernels; @@ -40,19 +44,25 @@ dg_diffusion_fluid_set_cu_dev_ptrs(struct dg_diffusion_fluid *diffusion, enum gk const gkyl_dg_diffusion_fluid_boundary_surf_kern_list *boundary_surfz_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = diffusion->const_coeff? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff ; - surfx_kernels = diffusion->const_coeff? ser_surfx_kernels_constcoeff : ser_surfx_kernels_varcoeff ; - surfy_kernels = diffusion->const_coeff? ser_surfy_kernels_constcoeff : ser_surfy_kernels_varcoeff ; - surfz_kernels = diffusion->const_coeff? ser_surfz_kernels_constcoeff : ser_surfz_kernels_varcoeff ; - boundary_surfx_kernels = diffusion->const_coeff? ser_boundary_surfx_kernels_constcoeff : ser_boundary_surfx_kernels_varcoeff; - boundary_surfy_kernels = diffusion->const_coeff? ser_boundary_surfy_kernels_constcoeff : ser_boundary_surfy_kernels_varcoeff; - boundary_surfz_kernels = diffusion->const_coeff? ser_boundary_surfz_kernels_constcoeff : ser_boundary_surfz_kernels_varcoeff; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = diffusion->const_coeff ? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff; + surfx_kernels = diffusion->const_coeff ? ser_surfx_kernels_constcoeff : + ser_surfx_kernels_varcoeff; + surfy_kernels = diffusion->const_coeff ? ser_surfy_kernels_constcoeff : + ser_surfy_kernels_varcoeff; + surfz_kernels = diffusion->const_coeff ? ser_surfz_kernels_constcoeff : + ser_surfz_kernels_varcoeff; + boundary_surfx_kernels = diffusion->const_coeff ? ser_boundary_surfx_kernels_constcoeff : + ser_boundary_surfx_kernels_varcoeff; + boundary_surfy_kernels = diffusion->const_coeff ? ser_boundary_surfy_kernels_constcoeff : + ser_boundary_surfy_kernels_varcoeff; + boundary_surfz_kernels = diffusion->const_coeff ? ser_boundary_surfz_kernels_constcoeff : + ser_boundary_surfz_kernels_varcoeff; + break; + + default: + assert(false); + break; } diffusion->eqn.num_equations = diffusion->num_equations; @@ -62,23 +72,29 @@ dg_diffusion_fluid_set_cu_dev_ptrs(struct dg_diffusion_fluid *diffusion, enum gk diffusion->eqn.vol_term = CKVOL(vol_kernels, cdim, diff_order, poly_order, diffdirs_linidx); diffusion->surf[0] = CKSURF(surfx_kernels, diff_order, cdim, poly_order); - if (cdim>1) + if (cdim > 1) { diffusion->surf[1] = CKSURF(surfy_kernels, diff_order, cdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { diffusion->surf[2] = CKSURF(surfz_kernels, diff_order, cdim, poly_order); + } diffusion->boundary_surf[0] = CKSURF(boundary_surfx_kernels, diff_order, cdim, poly_order); - if (cdim>1) + if (cdim > 1) { diffusion->boundary_surf[1] = CKSURF(boundary_surfy_kernels, diff_order, cdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { diffusion->boundary_surf[2] = CKSURF(boundary_surfz_kernels, diff_order, cdim, poly_order); + } } -struct gkyl_dg_eqn* -gkyl_dg_diffusion_fluid_cu_dev_new(const struct gkyl_basis *basis, bool is_diff_const, - int num_equations, const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range) +struct gkyl_dg_eqn *gkyl_dg_diffusion_fluid_cu_dev_new( + const struct gkyl_basis *basis, bool is_diff_const, int num_equations, const bool *diff_in_dir, + int diff_order, const struct gkyl_range *diff_range +) { - struct dg_diffusion_fluid* diffusion = (struct dg_diffusion_fluid*) gkyl_malloc(sizeof(struct dg_diffusion_fluid)); + struct dg_diffusion_fluid *diffusion = + (struct dg_diffusion_fluid *)gkyl_malloc(sizeof(struct dg_diffusion_fluid)); int cdim = basis->ndim; int poly_order = basis->poly_order; @@ -86,7 +102,9 @@ gkyl_dg_diffusion_fluid_cu_dev_new(const struct gkyl_basis *basis, bool is_diff_ diffusion->num_equations = num_equations; diffusion->const_coeff = is_diff_const; diffusion->num_basis = basis->num_basis; - for (int d=0; ddiff_in_dir[d] = diff_in_dir[d]; + for (int d = 0; d < cdim; d++) { + diffusion->diff_in_dir[d] = diff_in_dir[d]; + } int dirs_linidx = diffdirs_linidx(diff_in_dir, cdim); @@ -97,9 +115,12 @@ gkyl_dg_diffusion_fluid_cu_dev_new(const struct gkyl_basis *basis, bool is_diff_ diffusion->eqn.ref_count = gkyl_ref_count_init(gkyl_dg_diffusion_fluid_free); // copy the host struct to device struct - struct dg_diffusion_fluid* diffusion_cu = (struct dg_diffusion_fluid*) gkyl_cu_malloc(sizeof(struct dg_diffusion_fluid)); + struct dg_diffusion_fluid *diffusion_cu = + (struct dg_diffusion_fluid *)gkyl_cu_malloc(sizeof(struct dg_diffusion_fluid)); gkyl_cu_memcpy(diffusion_cu, diffusion, sizeof(struct dg_diffusion_fluid), GKYL_CU_MEMCPY_H2D); - dg_diffusion_fluid_set_cu_dev_ptrs<<<1,1>>>(diffusion_cu, basis->b_type, cdim, poly_order, diff_order, dirs_linidx); + dg_diffusion_fluid_set_cu_dev_ptrs<<<1, 1> > >( + diffusion_cu, basis->b_type, cdim, poly_order, diff_order, dirs_linidx + ); // set parent on_dev pointer diffusion->eqn.on_dev = &diffusion_cu->eqn; diff --git a/vlasov/zero/dg_diffusion_gen.c b/vlasov/zero/dg_diffusion_gen.c index 25e167c2ef..b0d41ef4b4 100644 --- a/vlasov/zero/dg_diffusion_gen.c +++ b/vlasov/zero/dg_diffusion_gen.c @@ -9,25 +9,26 @@ #include // "Choose Kernel" based on cdim and polynomial order -#define CK(lst, cdim, poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_diffusion_gen_free(const struct gkyl_ref_count* ref) +void gkyl_diffusion_gen_free(const struct gkyl_ref_count *ref) { - struct gkyl_dg_eqn* base = container_of(ref, struct gkyl_dg_eqn, ref_count); + struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object - struct dg_diffusion_gen* diffusion_gen = container_of(base->on_dev, struct dg_diffusion_gen, eqn); + struct dg_diffusion_gen *diffusion_gen = + container_of(base->on_dev, struct dg_diffusion_gen, eqn); gkyl_cu_free(diffusion_gen); } - - struct dg_diffusion_gen* diffusion_gen = container_of(base, struct dg_diffusion_gen, eqn); + + struct dg_diffusion_gen *diffusion_gen = container_of(base, struct dg_diffusion_gen, eqn); gkyl_free(diffusion_gen); } -void -gkyl_diffusion_gen_set_auxfields(const struct gkyl_dg_eqn* eqn, struct gkyl_dg_diffusion_gen_auxfields auxin) +void gkyl_diffusion_gen_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_gen_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(auxin.Dij)) { @@ -35,53 +36,55 @@ gkyl_diffusion_gen_set_auxfields(const struct gkyl_dg_eqn* eqn, struct gkyl_dg_d return; } #endif - - struct dg_diffusion_gen* diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); + + struct dg_diffusion_gen *diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); diffusion_gen->auxfields.Dij = auxin.Dij; } -struct gkyl_dg_eqn* -gkyl_dg_diffusion_gen_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_diffusion_gen_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) + if (use_gpu) { return gkyl_dg_diffusion_gen_cu_dev_new(cbasis, conf_range); + } #endif - - struct dg_diffusion_gen* diffusion_gen = gkyl_malloc(sizeof(struct dg_diffusion_gen)); + + struct dg_diffusion_gen *diffusion_gen = gkyl_malloc(sizeof(struct dg_diffusion_gen)); int cdim = cbasis->ndim; int poly_order = cbasis->poly_order; - const gkyl_dg_diffusion_gen_vol_kern_list* vol_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_xx_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_xy_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_xz_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_yx_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_yy_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_yz_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_zx_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_zy_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_zz_kernels; + const gkyl_dg_diffusion_gen_vol_kern_list *vol_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_xx_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_xy_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_xz_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_yx_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_yy_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_yz_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_zx_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_zy_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_zz_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_xx_kernels = ser_surf_xx_kernels; - surf_xy_kernels = ser_surf_xy_kernels; - surf_xz_kernels = ser_surf_xz_kernels; - surf_yx_kernels = ser_surf_yx_kernels; - surf_yy_kernels = ser_surf_yy_kernels; - surf_yz_kernels = ser_surf_yz_kernels; - surf_zx_kernels = ser_surf_zx_kernels; - surf_zy_kernels = ser_surf_zy_kernels; - surf_zz_kernels = ser_surf_zz_kernels; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_xx_kernels = ser_surf_xx_kernels; + surf_xy_kernels = ser_surf_xy_kernels; + surf_xz_kernels = ser_surf_xz_kernels; + surf_yx_kernels = ser_surf_yx_kernels; + surf_yy_kernels = ser_surf_yy_kernels; + surf_yz_kernels = ser_surf_yz_kernels; + surf_zx_kernels = ser_surf_zx_kernels; + surf_zy_kernels = ser_surf_zy_kernels; + surf_zz_kernels = ser_surf_zz_kernels; + break; + + default: + assert(false); + break; + } diffusion_gen->eqn.num_equations = 1; diffusion_gen->eqn.gen_surf_term = surf; @@ -90,12 +93,12 @@ gkyl_dg_diffusion_gen_new(const struct gkyl_basis* cbasis, const struct gkyl_ran diffusion_gen->eqn.vol_term = CK(vol_kernels, cdim, poly_order); diffusion_gen->surf[0][0] = CK(surf_xx_kernels, cdim, poly_order); - if (cdim>1) { + if (cdim > 1) { diffusion_gen->surf[0][1] = CK(surf_xy_kernels, cdim, poly_order); diffusion_gen->surf[1][0] = CK(surf_yx_kernels, cdim, poly_order); diffusion_gen->surf[1][1] = CK(surf_yy_kernels, cdim, poly_order); } - if (cdim>2) { + if (cdim > 2) { diffusion_gen->surf[0][2] = CK(surf_xz_kernels, cdim, poly_order); diffusion_gen->surf[1][2] = CK(surf_yz_kernels, cdim, poly_order); diffusion_gen->surf[2][0] = CK(surf_zx_kernels, cdim, poly_order); @@ -104,7 +107,9 @@ gkyl_dg_diffusion_gen_new(const struct gkyl_basis* cbasis, const struct gkyl_ran } // ensure non-NULL pointers - for (int i=0; isurf[i]); + for (int i = 0; i < cdim; ++i) { + assert(diffusion_gen->surf[i]); + } diffusion_gen->auxfields.Dij = 0; diffusion_gen->conf_range = *conf_range; @@ -112,14 +117,15 @@ gkyl_dg_diffusion_gen_new(const struct gkyl_basis* cbasis, const struct gkyl_ran diffusion_gen->eqn.flags = 0; diffusion_gen->eqn.ref_count = gkyl_ref_count_init(gkyl_diffusion_gen_free); diffusion_gen->eqn.on_dev = &diffusion_gen->eqn; - + return &diffusion_gen->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_diffusion_gen_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range) +struct gkyl_dg_eqn *gkyl_dg_diffusion_gen_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range +) { assert(false); return 0; diff --git a/vlasov/zero/dg_diffusion_gen_cu.cu b/vlasov/zero/dg_diffusion_gen_cu.cu index 5dc0a94261..e0a48d77b7 100644 --- a/vlasov/zero/dg_diffusion_gen_cu.cu +++ b/vlasov/zero/dg_diffusion_gen_cu.cu @@ -3,77 +3,80 @@ extern "C" { #include #include -#include +#include #include } #include -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_diffusion_gen_set_auxfields_cu_kernel(const struct gkyl_dg_eqn* eqn, const struct gkyl_array* Dij) +__global__ static void gkyl_diffusion_gen_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *Dij +) { - struct dg_diffusion_gen* diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); + struct dg_diffusion_gen *diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); diffusion_gen->auxfields.Dij = Dij; } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_diffusion_gen_set_auxfields_cu(const struct gkyl_dg_eqn* eqn, struct gkyl_dg_diffusion_gen_auxfields auxin) +void gkyl_diffusion_gen_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_gen_auxfields auxin +) { - gkyl_diffusion_gen_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.Dij->on_dev); + gkyl_diffusion_gen_set_auxfields_cu_kernel<<<1, 1> > >(eqn, auxin.Dij->on_dev); } -__global__ void static -dg_diffusion_gen_set_cu_dev_ptrs(struct dg_diffusion_gen* diffusion_gen, enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ void static dg_diffusion_gen_set_cu_dev_ptrs( + struct dg_diffusion_gen *diffusion_gen, enum gkyl_basis_type b_type, int cdim, int poly_order +) { - diffusion_gen->auxfields.Dij = 0; - - const gkyl_dg_diffusion_gen_vol_kern_list* vol_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_xx_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_xy_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_xz_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_yx_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_yy_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_yz_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_zx_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_zy_kernels; - const gkyl_dg_diffusion_gen_surf_kern_list* surf_zz_kernels; + diffusion_gen->auxfields.Dij = 0; + + const gkyl_dg_diffusion_gen_vol_kern_list *vol_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_xx_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_xy_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_xz_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_yx_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_yy_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_yz_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_zx_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_zy_kernels; + const gkyl_dg_diffusion_gen_surf_kern_list *surf_zz_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_xx_kernels = ser_surf_xx_kernels; - surf_xy_kernels = ser_surf_xy_kernels; - surf_xz_kernels = ser_surf_xz_kernels; - surf_yx_kernels = ser_surf_yx_kernels; - surf_yy_kernels = ser_surf_yy_kernels; - surf_yz_kernels = ser_surf_yz_kernels; - surf_zx_kernels = ser_surf_zx_kernels; - surf_zy_kernels = ser_surf_zy_kernels; - surf_zz_kernels = ser_surf_zz_kernels; - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_xx_kernels = ser_surf_xx_kernels; + surf_xy_kernels = ser_surf_xy_kernels; + surf_xz_kernels = ser_surf_xz_kernels; + surf_yx_kernels = ser_surf_yx_kernels; + surf_yy_kernels = ser_surf_yy_kernels; + surf_yz_kernels = ser_surf_yz_kernels; + surf_zx_kernels = ser_surf_zx_kernels; + surf_zy_kernels = ser_surf_zy_kernels; + surf_zz_kernels = ser_surf_zz_kernels; + break; + + default: + assert(false); + break; + } + diffusion_gen->eqn.gen_surf_term = surf; - + diffusion_gen->eqn.vol_term = CK(vol_kernels, cdim, poly_order); diffusion_gen->surf[0][0] = CK(surf_xx_kernels, cdim, poly_order); - if (cdim>1) { + if (cdim > 1) { diffusion_gen->surf[0][1] = CK(surf_xy_kernels, cdim, poly_order); diffusion_gen->surf[1][0] = CK(surf_yx_kernels, cdim, poly_order); diffusion_gen->surf[1][1] = CK(surf_yy_kernels, cdim, poly_order); } - if (cdim>2) { + if (cdim > 2) { diffusion_gen->surf[0][2] = CK(surf_xz_kernels, cdim, poly_order); diffusion_gen->surf[1][2] = CK(surf_yz_kernels, cdim, poly_order); diffusion_gen->surf[2][0] = CK(surf_zx_kernels, cdim, poly_order); @@ -82,10 +85,12 @@ dg_diffusion_gen_set_cu_dev_ptrs(struct dg_diffusion_gen* diffusion_gen, enum gk } } -struct gkyl_dg_eqn* -gkyl_dg_diffusion_gen_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range) +struct gkyl_dg_eqn *gkyl_dg_diffusion_gen_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range +) { - struct dg_diffusion_gen* diffusion_gen = (struct dg_diffusion_gen*) gkyl_malloc(sizeof(struct dg_diffusion_gen)); + struct dg_diffusion_gen *diffusion_gen = + (struct dg_diffusion_gen *)gkyl_malloc(sizeof(struct dg_diffusion_gen)); // set basic parameters diffusion_gen->eqn.num_equations = 1; @@ -96,9 +101,14 @@ gkyl_dg_diffusion_gen_cu_dev_new(const struct gkyl_basis* cbasis, const struct g diffusion_gen->eqn.ref_count = gkyl_ref_count_init(gkyl_diffusion_gen_free); // copy the host struct to device struct - struct dg_diffusion_gen* diffusion_gen_cu = (struct dg_diffusion_gen*) gkyl_cu_malloc(sizeof(struct dg_diffusion_gen)); - gkyl_cu_memcpy(diffusion_gen_cu, diffusion_gen, sizeof(struct dg_diffusion_gen), GKYL_CU_MEMCPY_H2D); - dg_diffusion_gen_set_cu_dev_ptrs<<<1,1>>>(diffusion_gen_cu, cbasis->b_type, cbasis->ndim, cbasis->poly_order); + struct dg_diffusion_gen *diffusion_gen_cu = + (struct dg_diffusion_gen *)gkyl_cu_malloc(sizeof(struct dg_diffusion_gen)); + gkyl_cu_memcpy( + diffusion_gen_cu, diffusion_gen, sizeof(struct dg_diffusion_gen), GKYL_CU_MEMCPY_H2D + ); + dg_diffusion_gen_set_cu_dev_ptrs<<<1, 1> > >( + diffusion_gen_cu, cbasis->b_type, cbasis->ndim, cbasis->poly_order + ); // set parent on_dev pointer diffusion_gen->eqn.on_dev = &diffusion_gen_cu->eqn; diff --git a/vlasov/zero/dg_diffusion_vlasov.c b/vlasov/zero/dg_diffusion_vlasov.c index 1b75de5236..a399b94941 100644 --- a/vlasov/zero/dg_diffusion_vlasov.c +++ b/vlasov/zero/dg_diffusion_vlasov.c @@ -8,23 +8,24 @@ #include #include -void -gkyl_dg_diffusion_vlasov_free(const struct gkyl_ref_count *ref) +void gkyl_dg_diffusion_vlasov_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object - struct dg_diffusion_vlasov *diffusion = container_of(base->on_dev, struct dg_diffusion_vlasov, eqn); + struct dg_diffusion_vlasov *diffusion = + container_of(base->on_dev, struct dg_diffusion_vlasov, eqn); gkyl_cu_free(diffusion); } - + struct dg_diffusion_vlasov *diffusion = container_of(base, struct dg_diffusion_vlasov, eqn); gkyl_free(diffusion); } -void -gkyl_dg_diffusion_vlasov_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_vlasov_auxfields auxin) +void gkyl_dg_diffusion_vlasov_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_vlasov_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(auxin.D)) { @@ -32,21 +33,24 @@ gkyl_dg_diffusion_vlasov_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gky return; } #endif - + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); diffusion->auxfields.D = auxin.D; } -struct gkyl_dg_eqn* -gkyl_dg_diffusion_vlasov_new(const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, - bool is_diff_const, const bool *diff_in_dir, int diff_order, - const struct gkyl_range *diff_range, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_diffusion_vlasov_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, + const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if (use_gpu) - return gkyl_dg_diffusion_vlasov_cu_dev_new(basis, cbasis, is_diff_const, diff_in_dir, diff_order, diff_range); + if (use_gpu) { + return gkyl_dg_diffusion_vlasov_cu_dev_new( + basis, cbasis, is_diff_const, diff_in_dir, diff_order, diff_range + ); + } #endif - + struct dg_diffusion_vlasov *diffusion = gkyl_malloc(sizeof(struct dg_diffusion_vlasov)); int cdim = cbasis->ndim; @@ -55,31 +59,39 @@ gkyl_dg_diffusion_vlasov_new(const struct gkyl_basis *basis, const struct gkyl_b diffusion->const_coeff = is_diff_const; diffusion->num_basis = basis->num_basis; - for (int d=0; ddiff_in_dir[d] = diff_in_dir[d]; + for (int d = 0; d < cdim; d++) { + diffusion->diff_in_dir[d] = diff_in_dir[d]; + } const gkyl_dg_diffusion_vlasov_vol_kern_list *vol_kernels; const gkyl_dg_diffusion_vlasov_surf_kern_list *surfx_kernels; const gkyl_dg_diffusion_vlasov_surf_kern_list *surfy_kernels; - const gkyl_dg_diffusion_vlasov_surf_kern_list *surfz_kernels; + const gkyl_dg_diffusion_vlasov_surf_kern_list *surfz_kernels; const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list *boundary_surfx_kernels; const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list *boundary_surfy_kernels; - const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list *boundary_surfz_kernels; + const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list *boundary_surfz_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = diffusion->const_coeff? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff ; - surfx_kernels = diffusion->const_coeff? ser_vlasov_surfx_kernels_constcoeff : ser_vlasov_surfx_kernels_varcoeff ; - surfy_kernels = diffusion->const_coeff? ser_vlasov_surfy_kernels_constcoeff : ser_vlasov_surfy_kernels_varcoeff ; - surfz_kernels = diffusion->const_coeff? ser_vlasov_surfz_kernels_constcoeff : ser_vlasov_surfz_kernels_varcoeff ; - boundary_surfx_kernels = diffusion->const_coeff? ser_vlasov_boundary_surfx_kernels_constcoeff : ser_vlasov_boundary_surfx_kernels_varcoeff; - boundary_surfy_kernels = diffusion->const_coeff? ser_vlasov_boundary_surfy_kernels_constcoeff : ser_vlasov_boundary_surfy_kernels_varcoeff; - boundary_surfz_kernels = diffusion->const_coeff? ser_vlasov_boundary_surfz_kernels_constcoeff : ser_vlasov_boundary_surfz_kernels_varcoeff; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = diffusion->const_coeff ? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff; + surfx_kernels = diffusion->const_coeff ? ser_vlasov_surfx_kernels_constcoeff : + ser_vlasov_surfx_kernels_varcoeff; + surfy_kernels = diffusion->const_coeff ? ser_vlasov_surfy_kernels_constcoeff : + ser_vlasov_surfy_kernels_varcoeff; + surfz_kernels = diffusion->const_coeff ? ser_vlasov_surfz_kernels_constcoeff : + ser_vlasov_surfz_kernels_varcoeff; + boundary_surfx_kernels = diffusion->const_coeff ? ser_vlasov_boundary_surfx_kernels_constcoeff : + ser_vlasov_boundary_surfx_kernels_varcoeff; + boundary_surfy_kernels = diffusion->const_coeff ? ser_vlasov_boundary_surfy_kernels_constcoeff : + ser_vlasov_boundary_surfy_kernels_varcoeff; + boundary_surfz_kernels = diffusion->const_coeff ? ser_vlasov_boundary_surfz_kernels_constcoeff : + ser_vlasov_boundary_surfz_kernels_varcoeff; + break; + + default: + assert(false); + break; + } int dirs_linidx = diffdirs_linidx(diff_in_dir, cdim); @@ -90,19 +102,27 @@ gkyl_dg_diffusion_vlasov_new(const struct gkyl_basis *basis, const struct gkyl_b diffusion->eqn.vol_term = CKVOL(vol_kernels, cdim, diff_order, poly_order, dirs_linidx); diffusion->surf[0] = CKSURF(surfx_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>1) + if (cdim > 1) { diffusion->surf[1] = CKSURF(surfy_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { diffusion->surf[2] = CKSURF(surfz_kernels, diff_order, cdim, vdim, poly_order); + } diffusion->boundary_surf[0] = CKSURF(boundary_surfx_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>1) - diffusion->boundary_surf[1] = CKSURF(boundary_surfy_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>2) - diffusion->boundary_surf[2] = CKSURF(boundary_surfz_kernels, diff_order, cdim, vdim, poly_order); + if (cdim > 1) { + diffusion->boundary_surf[1] = + CKSURF(boundary_surfy_kernels, diff_order, cdim, vdim, poly_order); + } + if (cdim > 2) { + diffusion->boundary_surf[2] = + CKSURF(boundary_surfz_kernels, diff_order, cdim, vdim, poly_order); + } // Ensure non-NULL pointers. - for (int i=0; isurf[i]); + for (int i = 0; i < cdim; ++i) { + assert(diffusion->surf[i]); + } diffusion->auxfields.D = 0; diffusion->diff_range = *diff_range; @@ -110,6 +130,6 @@ gkyl_dg_diffusion_vlasov_new(const struct gkyl_basis *basis, const struct gkyl_b diffusion->eqn.flags = 0; diffusion->eqn.ref_count = gkyl_ref_count_init(gkyl_dg_diffusion_vlasov_free); diffusion->eqn.on_dev = &diffusion->eqn; - + return &diffusion->eqn; } diff --git a/vlasov/zero/dg_diffusion_vlasov_cu.cu b/vlasov/zero/dg_diffusion_vlasov_cu.cu index 6a68dcf10d..5e7cf3bba0 100644 --- a/vlasov/zero/dg_diffusion_vlasov_cu.cu +++ b/vlasov/zero/dg_diffusion_vlasov_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include } @@ -12,24 +12,28 @@ extern "C" { // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_dg_diffusion_vlasov_set_auxfields_cu_kernel(const struct gkyl_dg_eqn* eqn, const struct gkyl_array* D) +__global__ static void gkyl_dg_diffusion_vlasov_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *D +) { - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); diffusion->auxfields.D = D; } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_dg_diffusion_vlasov_set_auxfields_cu(const struct gkyl_dg_eqn* eqn, struct gkyl_dg_diffusion_vlasov_auxfields auxin) +void gkyl_dg_diffusion_vlasov_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_vlasov_auxfields auxin +) { - gkyl_dg_diffusion_vlasov_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.D->on_dev); + gkyl_dg_diffusion_vlasov_set_auxfields_cu_kernel<<<1, 1> > >(eqn, auxin.D->on_dev); } -__global__ void static -dg_diffusion_vlasov_set_cu_dev_ptrs(struct dg_diffusion_vlasov *diffusion, enum gkyl_basis_type b_type, int cdim, int vdim, int poly_order, int diff_order, int diffdirs_linidx) +__global__ void static dg_diffusion_vlasov_set_cu_dev_ptrs( + struct dg_diffusion_vlasov *diffusion, enum gkyl_basis_type b_type, int cdim, int vdim, + int poly_order, int diff_order, int diffdirs_linidx +) { - diffusion->auxfields.D = 0; + diffusion->auxfields.D = 0; const gkyl_dg_diffusion_vlasov_vol_kern_list *vol_kernels; const gkyl_dg_diffusion_vlasov_surf_kern_list *surfx_kernels; @@ -40,19 +44,25 @@ dg_diffusion_vlasov_set_cu_dev_ptrs(struct dg_diffusion_vlasov *diffusion, enum const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list *boundary_surfz_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = diffusion->const_coeff? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff ; - surfx_kernels = diffusion->const_coeff? ser_vlasov_surfx_kernels_constcoeff : ser_vlasov_surfx_kernels_varcoeff ; - surfy_kernels = diffusion->const_coeff? ser_vlasov_surfy_kernels_constcoeff : ser_vlasov_surfy_kernels_varcoeff ; - surfz_kernels = diffusion->const_coeff? ser_vlasov_surfz_kernels_constcoeff : ser_vlasov_surfz_kernels_varcoeff ; - boundary_surfx_kernels = diffusion->const_coeff? ser_vlasov_boundary_surfx_kernels_constcoeff : ser_vlasov_boundary_surfx_kernels_varcoeff; - boundary_surfy_kernels = diffusion->const_coeff? ser_vlasov_boundary_surfy_kernels_constcoeff : ser_vlasov_boundary_surfy_kernels_varcoeff; - boundary_surfz_kernels = diffusion->const_coeff? ser_vlasov_boundary_surfz_kernels_constcoeff : ser_vlasov_boundary_surfz_kernels_varcoeff; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = diffusion->const_coeff ? ser_vol_kernels_constcoeff : ser_vol_kernels_varcoeff; + surfx_kernels = diffusion->const_coeff ? ser_vlasov_surfx_kernels_constcoeff : + ser_vlasov_surfx_kernels_varcoeff; + surfy_kernels = diffusion->const_coeff ? ser_vlasov_surfy_kernels_constcoeff : + ser_vlasov_surfy_kernels_varcoeff; + surfz_kernels = diffusion->const_coeff ? ser_vlasov_surfz_kernels_constcoeff : + ser_vlasov_surfz_kernels_varcoeff; + boundary_surfx_kernels = diffusion->const_coeff ? ser_vlasov_boundary_surfx_kernels_constcoeff : + ser_vlasov_boundary_surfx_kernels_varcoeff; + boundary_surfy_kernels = diffusion->const_coeff ? ser_vlasov_boundary_surfy_kernels_constcoeff : + ser_vlasov_boundary_surfy_kernels_varcoeff; + boundary_surfz_kernels = diffusion->const_coeff ? ser_vlasov_boundary_surfz_kernels_constcoeff : + ser_vlasov_boundary_surfz_kernels_varcoeff; + break; + + default: + assert(false); + break; } diffusion->eqn.num_equations = 1; @@ -62,23 +72,31 @@ dg_diffusion_vlasov_set_cu_dev_ptrs(struct dg_diffusion_vlasov *diffusion, enum diffusion->eqn.vol_term = CKVOL(vol_kernels, cdim, diff_order, poly_order, diffdirs_linidx); diffusion->surf[0] = CKSURF(surfx_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>1) + if (cdim > 1) { diffusion->surf[1] = CKSURF(surfy_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { diffusion->surf[2] = CKSURF(surfz_kernels, diff_order, cdim, vdim, poly_order); + } diffusion->boundary_surf[0] = CKSURF(boundary_surfx_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>1) - diffusion->boundary_surf[1] = CKSURF(boundary_surfy_kernels, diff_order, cdim, vdim, poly_order); - if (cdim>2) - diffusion->boundary_surf[2] = CKSURF(boundary_surfz_kernels, diff_order, cdim, vdim, poly_order); + if (cdim > 1) { + diffusion->boundary_surf[1] = + CKSURF(boundary_surfy_kernels, diff_order, cdim, vdim, poly_order); + } + if (cdim > 2) { + diffusion->boundary_surf[2] = + CKSURF(boundary_surfz_kernels, diff_order, cdim, vdim, poly_order); + } } -struct gkyl_dg_eqn* -gkyl_dg_diffusion_vlasov_cu_dev_new(const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, - bool is_diff_const, const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range) +struct gkyl_dg_eqn *gkyl_dg_diffusion_vlasov_cu_dev_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, + const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range +) { - struct dg_diffusion_vlasov* diffusion = (struct dg_diffusion_vlasov*) gkyl_malloc(sizeof(struct dg_diffusion_vlasov)); + struct dg_diffusion_vlasov *diffusion = + (struct dg_diffusion_vlasov *)gkyl_malloc(sizeof(struct dg_diffusion_vlasov)); int cdim = cbasis->ndim; int vdim = basis->ndim - cdim; @@ -86,7 +104,9 @@ gkyl_dg_diffusion_vlasov_cu_dev_new(const struct gkyl_basis *basis, const struct diffusion->const_coeff = is_diff_const; diffusion->num_basis = basis->num_basis; - for (int d=0; ddiff_in_dir[d] = diff_in_dir[d]; + for (int d = 0; d < cdim; d++) { + diffusion->diff_in_dir[d] = diff_in_dir[d]; + } int dirs_linidx = diffdirs_linidx(diff_in_dir, cdim); @@ -97,9 +117,12 @@ gkyl_dg_diffusion_vlasov_cu_dev_new(const struct gkyl_basis *basis, const struct diffusion->eqn.ref_count = gkyl_ref_count_init(gkyl_dg_diffusion_vlasov_free); // copy the host struct to device struct - struct dg_diffusion_vlasov* diffusion_cu = (struct dg_diffusion_vlasov*) gkyl_cu_malloc(sizeof(struct dg_diffusion_vlasov)); + struct dg_diffusion_vlasov *diffusion_cu = + (struct dg_diffusion_vlasov *)gkyl_cu_malloc(sizeof(struct dg_diffusion_vlasov)); gkyl_cu_memcpy(diffusion_cu, diffusion, sizeof(struct dg_diffusion_vlasov), GKYL_CU_MEMCPY_H2D); - dg_diffusion_vlasov_set_cu_dev_ptrs<<<1,1>>>(diffusion_cu, cbasis->b_type, cdim, vdim, poly_order, diff_order, dirs_linidx); + dg_diffusion_vlasov_set_cu_dev_ptrs<<<1, 1> > >( + diffusion_cu, cbasis->b_type, cdim, vdim, poly_order, diff_order, dirs_linidx + ); // set parent on_dev pointer diffusion->eqn.on_dev = &diffusion_cu->eqn; diff --git a/vlasov/zero/dg_eqn.c b/vlasov/zero/dg_eqn.c index 82fcc3a724..bce63cf444 100644 --- a/vlasov/zero/dg_eqn.c +++ b/vlasov/zero/dg_eqn.c @@ -1,21 +1,18 @@ #include #include -bool -gkyl_dg_eqn_is_cu_dev(const struct gkyl_dg_eqn *eqn) +bool gkyl_dg_eqn_is_cu_dev(const struct gkyl_dg_eqn *eqn) { return GKYL_IS_CU_ALLOC(eqn->flags); } -struct gkyl_dg_eqn* -gkyl_dg_eqn_acquire(const struct gkyl_dg_eqn* eqn) +struct gkyl_dg_eqn *gkyl_dg_eqn_acquire(const struct gkyl_dg_eqn *eqn) { gkyl_ref_count_inc(&eqn->ref_count); - return (struct gkyl_dg_eqn*) eqn; + return (struct gkyl_dg_eqn *)eqn; } -void -gkyl_dg_eqn_release(const struct gkyl_dg_eqn* eqn) +void gkyl_dg_eqn_release(const struct gkyl_dg_eqn *eqn) { gkyl_ref_count_dec(&eqn->ref_count); } diff --git a/vlasov/zero/dg_euler.c b/vlasov/zero/dg_euler.c index ae3f78ad9b..654bd85b3c 100644 --- a/vlasov/zero/dg_euler.c +++ b/vlasov/zero/dg_euler.c @@ -12,10 +12,9 @@ #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_dg_euler_free(const struct gkyl_ref_count *ref) +void gkyl_dg_euler_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); struct dg_euler *euler = container_of(base, struct dg_euler, eqn); @@ -26,12 +25,11 @@ gkyl_dg_euler_free(const struct gkyl_ref_count *ref) // free inner on_dev object struct dg_euler *euler_cu = container_of(base->on_dev, struct dg_euler, eqn); gkyl_cu_free(euler_cu); - } + } gkyl_free(euler); } -void -gkyl_euler_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_auxfields auxin) +void gkyl_euler_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_auxfields auxin) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(auxin.u)) { @@ -47,14 +45,15 @@ gkyl_euler_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_aux euler->auxfields.p_surf = auxin.p_surf; } -struct gkyl_dg_eqn* -gkyl_dg_euler_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_euler_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, + const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_euler_cu_dev_new(cbasis, conf_range, wv_eqn, geom); - } + } #endif struct dg_euler *euler = gkyl_malloc(sizeof(struct dg_euler)); @@ -65,24 +64,24 @@ gkyl_dg_euler_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf const gkyl_dg_euler_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - surf_z_kernels = ser_surf_z_kernels; - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - surf_x_kernels = ten_surf_x_kernels; - surf_y_kernels = ten_surf_y_kernels; - surf_z_kernels = ten_surf_z_kernels; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + surf_z_kernels = ser_surf_z_kernels; + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + surf_x_kernels = ten_surf_x_kernels; + surf_y_kernels = ten_surf_y_kernels; + surf_z_kernels = ten_surf_z_kernels; + break; + + default: + assert(false); + break; + } euler->eqn_type = wv_eqn->type; euler->eqn.num_equations = wv_eqn->num_equations; @@ -96,33 +95,38 @@ gkyl_dg_euler_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf euler->eqn.vol_term = CK(vol_kernels, cdim, poly_order); euler->surf[0] = CK(surf_x_kernels, cdim, poly_order); - if (cdim>1) + if (cdim > 1) { euler->surf[1] = CK(surf_y_kernels, cdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { euler->surf[2] = CK(surf_z_kernels, cdim, poly_order); + } - // ensure non-NULL pointers - for (int i=0; isurf[i]); + // ensure non-NULL pointers + for (int i = 0; i < cdim; ++i) { + assert(euler->surf[i]); + } - euler->auxfields.u = 0; - euler->auxfields.p = 0; - euler->auxfields.u_surf = 0; - euler->auxfields.p_surf = 0; + euler->auxfields.u = 0; + euler->auxfields.p = 0; + euler->auxfields.u_surf = 0; + euler->auxfields.p_surf = 0; euler->conf_range = *conf_range; - + euler->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(euler->eqn.flags); euler->eqn.ref_count = gkyl_ref_count_init(gkyl_dg_euler_free); euler->eqn.on_dev = &euler->eqn; // CPU eqn obj points to itself - + return &euler->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_euler_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom) +struct gkyl_dg_eqn *gkyl_dg_euler_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, + const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom +) { assert(false); return 0; diff --git a/vlasov/zero/dg_euler_cu.cu b/vlasov/zero/dg_euler_cu.cu index 04afc30b13..eae3d1aa47 100644 --- a/vlasov/zero/dg_euler_cu.cu +++ b/vlasov/zero/dg_euler_cu.cu @@ -13,15 +13,15 @@ extern "C" { #include -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_euler_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array *u, const struct gkyl_array *u_surf, - const struct gkyl_array *p, const struct gkyl_array *p_surf) +__global__ static void gkyl_euler_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *u, const struct gkyl_array *u_surf, + const struct gkyl_array *p, const struct gkyl_array *p_surf +) { struct dg_euler *euler = container_of(eqn, struct dg_euler, eqn); euler->auxfields.u = u; @@ -31,60 +31,65 @@ gkyl_euler_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_euler_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_auxfields auxin) +void gkyl_euler_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_auxfields auxin) { - gkyl_euler_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.u->on_dev, auxin.u_surf->on_dev, auxin.p->on_dev, auxin.p_surf->on_dev); + gkyl_euler_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.u->on_dev, auxin.u_surf->on_dev, auxin.p->on_dev, auxin.p_surf->on_dev + ); } -__global__ void static -dg_euler_set_cu_dev_ptrs(struct dg_euler* euler, enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ void static dg_euler_set_cu_dev_ptrs( + struct dg_euler *euler, enum gkyl_basis_type b_type, int cdim, int poly_order +) { - euler->auxfields.u = 0; - euler->auxfields.p = 0; - euler->auxfields.u_surf = 0; - euler->auxfields.p_surf = 0; + euler->auxfields.u = 0; + euler->auxfields.p = 0; + euler->auxfields.u_surf = 0; + euler->auxfields.p_surf = 0; const gkyl_dg_euler_vol_kern_list *vol_kernels; - const gkyl_dg_euler_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; - + const gkyl_dg_euler_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - surf_z_kernels = ser_surf_z_kernels; - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - surf_x_kernels = ten_surf_x_kernels; - surf_y_kernels = ten_surf_y_kernels; - surf_z_kernels = ten_surf_z_kernels; - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + surf_z_kernels = ser_surf_z_kernels; + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + surf_x_kernels = ten_surf_x_kernels; + surf_y_kernels = ten_surf_y_kernels; + surf_z_kernels = ten_surf_z_kernels; + break; + + default: + assert(false); + break; + } + euler->eqn.surf_term = surf; euler->eqn.boundary_surf_term = boundary_surf; - euler->eqn.vol_term = CK(vol_kernels, cdim, poly_order); + euler->eqn.vol_term = CK(vol_kernels, cdim, poly_order); euler->surf[0] = CK(surf_x_kernels, cdim, poly_order); - if (cdim>1) + if (cdim > 1) { euler->surf[1] = CK(surf_y_kernels, cdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { euler->surf[2] = CK(surf_z_kernels, cdim, poly_order); + } } -struct gkyl_dg_eqn* -gkyl_dg_euler_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *wg) +struct gkyl_dg_eqn *gkyl_dg_euler_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, + const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *wg +) { - struct dg_euler *euler = (struct dg_euler*) gkyl_malloc(sizeof(struct dg_euler)); + struct dg_euler *euler = (struct dg_euler *)gkyl_malloc(sizeof(struct dg_euler)); euler->eqn_type = wv_eqn->type; euler->eqn.num_equations = wv_eqn->num_equations; @@ -105,16 +110,16 @@ gkyl_dg_euler_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_rang euler->eqn.ref_count = gkyl_ref_count_init(gkyl_dg_euler_free); // copy the host struct to device struct - struct dg_euler *euler_cu = (struct dg_euler*) gkyl_cu_malloc(sizeof(struct dg_euler)); + struct dg_euler *euler_cu = (struct dg_euler *)gkyl_cu_malloc(sizeof(struct dg_euler)); gkyl_cu_memcpy(euler_cu, euler, sizeof(struct dg_euler), GKYL_CU_MEMCPY_H2D); - dg_euler_set_cu_dev_ptrs<<<1,1>>>(euler_cu, cbasis->b_type, cbasis->ndim, cbasis->poly_order); + dg_euler_set_cu_dev_ptrs<<<1, 1> > >(euler_cu, cbasis->b_type, cbasis->ndim, cbasis->poly_order); // set parent on_dev pointer euler->eqn.on_dev = &euler_cu->eqn; // updater should store host pointers - euler->wv_eqn = eqn; - euler->geom = geom; + euler->wv_eqn = eqn; + euler->geom = geom; return &euler->eqn; } diff --git a/vlasov/zero/dg_fpo_vlasov_diff.c b/vlasov/zero/dg_fpo_vlasov_diff.c index c76394b42e..e6de466c89 100644 --- a/vlasov/zero/dg_fpo_vlasov_diff.c +++ b/vlasov/zero/dg_fpo_vlasov_diff.c @@ -9,25 +9,26 @@ #include // "Choose Kernel" based on cdim and polynomial order -#define CK(lst, cdim, poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_fpo_vlasov_diff_free(const struct gkyl_ref_count* ref) +void gkyl_fpo_vlasov_diff_free(const struct gkyl_ref_count *ref) { - struct gkyl_dg_eqn* base = container_of(ref, struct gkyl_dg_eqn, ref_count); + struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object - struct dg_fpo_vlasov_diff* fpo_vlasov_diff = container_of(base->on_dev, struct dg_fpo_vlasov_diff, eqn); + struct dg_fpo_vlasov_diff *fpo_vlasov_diff = + container_of(base->on_dev, struct dg_fpo_vlasov_diff, eqn); gkyl_cu_free(fpo_vlasov_diff); } - - struct dg_fpo_vlasov_diff* fpo_vlasov_diff = container_of(base, struct dg_fpo_vlasov_diff, eqn); + + struct dg_fpo_vlasov_diff *fpo_vlasov_diff = container_of(base, struct dg_fpo_vlasov_diff, eqn); gkyl_free(fpo_vlasov_diff); } -void -gkyl_fpo_vlasov_diff_set_auxfields(const struct gkyl_dg_eqn* eqn, struct gkyl_dg_fpo_vlasov_diff_auxfields auxin) +void gkyl_fpo_vlasov_diff_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_diff_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_array_is_cu_dev(auxin.g)) { @@ -35,20 +36,22 @@ gkyl_fpo_vlasov_diff_set_auxfields(const struct gkyl_dg_eqn* eqn, struct gkyl_dg return; } #endif - - struct dg_fpo_vlasov_diff* fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); + + struct dg_fpo_vlasov_diff *fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); fpo_vlasov_diff->auxfields.g = auxin.g; } -struct gkyl_dg_eqn* -gkyl_dg_fpo_vlasov_diff_new(const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_fpo_vlasov_diff_new( + const struct gkyl_basis *pbasis, const struct gkyl_range *phase_range, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) + if (use_gpu) { return gkyl_dg_fpo_vlasov_diff_cu_dev_new(pbasis, phase_range); + } #endif - - struct dg_fpo_vlasov_diff* fpo_vlasov_diff = gkyl_malloc(sizeof(struct dg_fpo_vlasov_diff)); + + struct dg_fpo_vlasov_diff *fpo_vlasov_diff = gkyl_malloc(sizeof(struct dg_fpo_vlasov_diff)); // Vlasov Fokker-Planck operator only defined in 3 velocity dimensions int pdim = pbasis->ndim, vdim = 3, cdim = pdim - vdim; @@ -61,55 +64,55 @@ gkyl_dg_fpo_vlasov_diff_new(const struct gkyl_basis* pbasis, const struct gkyl_r fpo_vlasov_diff->eqn.gen_surf_term = surf; fpo_vlasov_diff->eqn.gen_boundary_surf_term = boundary_surf; - const gkyl_dg_fpo_vlasov_diff_vol_kern_list* vol_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_xx_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_xy_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_xz_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_yx_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_yy_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_yz_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_zx_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_zy_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_zz_kernels; - - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_xx_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_xy_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_xz_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_yx_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_yy_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_yz_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_zx_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_zy_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_zz_kernels; + const gkyl_dg_fpo_vlasov_diff_vol_kern_list *vol_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_xx_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_xy_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_xz_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_yx_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_yy_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_yz_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_zx_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_zy_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_zz_kernels; + + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_xx_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_xy_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_xz_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_yx_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_yy_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_yz_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_zx_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_zy_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_zz_kernels; switch (pbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_xx_kernels = ser_surf_xx_kernels; - surf_xy_kernels = ser_surf_xy_kernels; - surf_xz_kernels = ser_surf_xz_kernels; - surf_yx_kernels = ser_surf_yx_kernels; - surf_yy_kernels = ser_surf_yy_kernels; - surf_yz_kernels = ser_surf_yz_kernels; - surf_zx_kernels = ser_surf_zx_kernels; - surf_zy_kernels = ser_surf_zy_kernels; - surf_zz_kernels = ser_surf_zz_kernels; - - boundary_surf_xx_kernels = ser_boundary_surf_xx_kernels; - boundary_surf_xy_kernels = ser_boundary_surf_xy_kernels; - boundary_surf_xz_kernels = ser_boundary_surf_xz_kernels; - boundary_surf_yx_kernels = ser_boundary_surf_yx_kernels; - boundary_surf_yy_kernels = ser_boundary_surf_yy_kernels; - boundary_surf_yz_kernels = ser_boundary_surf_yz_kernels; - boundary_surf_zx_kernels = ser_boundary_surf_zx_kernels; - boundary_surf_zy_kernels = ser_boundary_surf_zy_kernels; - boundary_surf_zz_kernels = ser_boundary_surf_zz_kernels; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_xx_kernels = ser_surf_xx_kernels; + surf_xy_kernels = ser_surf_xy_kernels; + surf_xz_kernels = ser_surf_xz_kernels; + surf_yx_kernels = ser_surf_yx_kernels; + surf_yy_kernels = ser_surf_yy_kernels; + surf_yz_kernels = ser_surf_yz_kernels; + surf_zx_kernels = ser_surf_zx_kernels; + surf_zy_kernels = ser_surf_zy_kernels; + surf_zz_kernels = ser_surf_zz_kernels; + + boundary_surf_xx_kernels = ser_boundary_surf_xx_kernels; + boundary_surf_xy_kernels = ser_boundary_surf_xy_kernels; + boundary_surf_xz_kernels = ser_boundary_surf_xz_kernels; + boundary_surf_yx_kernels = ser_boundary_surf_yx_kernels; + boundary_surf_yy_kernels = ser_boundary_surf_yy_kernels; + boundary_surf_yz_kernels = ser_boundary_surf_yz_kernels; + boundary_surf_zx_kernels = ser_boundary_surf_zx_kernels; + boundary_surf_zy_kernels = ser_boundary_surf_zy_kernels; + boundary_surf_zz_kernels = ser_boundary_surf_zz_kernels; + break; + + default: + assert(false); + break; + } fpo_vlasov_diff->eqn.vol_term = CK(vol_kernels, cdim, poly_order); @@ -134,13 +137,17 @@ gkyl_dg_fpo_vlasov_diff_new(const struct gkyl_basis* pbasis, const struct gkyl_r fpo_vlasov_diff->boundary_surf[2][2] = CK(boundary_surf_zz_kernels, cdim, poly_order); // ensure non-NULL pointers - for (int i=0; isurf[i][j]); + } + } - for (int i=0; iboundary_surf[i][j]); + } + } fpo_vlasov_diff->auxfields.g = 0; fpo_vlasov_diff->phase_range = *phase_range; @@ -149,14 +156,15 @@ gkyl_dg_fpo_vlasov_diff_new(const struct gkyl_basis* pbasis, const struct gkyl_r GKYL_CLEAR_CU_ALLOC(fpo_vlasov_diff->eqn.flags); fpo_vlasov_diff->eqn.ref_count = gkyl_ref_count_init(gkyl_fpo_vlasov_diff_free); fpo_vlasov_diff->eqn.on_dev = &fpo_vlasov_diff->eqn; - + return &fpo_vlasov_diff->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_fpo_vlasov_diff_cu_dev_new(const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range) +struct gkyl_dg_eqn *gkyl_dg_fpo_vlasov_diff_cu_dev_new( + const struct gkyl_basis *pbasis, const struct gkyl_range *phase_range +) { assert(false); return 0; diff --git a/vlasov/zero/dg_fpo_vlasov_diff_cu.cu b/vlasov/zero/dg_fpo_vlasov_diff_cu.cu index 616cac21fa..58c079355e 100644 --- a/vlasov/zero/dg_fpo_vlasov_diff_cu.cu +++ b/vlasov/zero/dg_fpo_vlasov_diff_cu.cu @@ -3,93 +3,96 @@ extern "C" { #include #include -#include +#include #include } #include // "Choose Kernel" based on cdim and polynomial order -#define CK(lst, cdim, poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] // CUDA kernel to set pointer to g (second Rosenbluth potential). // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_fpo_vlasov_diff_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, const struct gkyl_array *g) +__global__ static void gkyl_fpo_vlasov_diff_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *g +) { struct dg_fpo_vlasov_diff *fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); fpo_vlasov_diff->auxfields.g = g; } //// Host-side wrapper for device kernels setting g (second Rosenbluth potential). -void -gkyl_fpo_vlasov_diff_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_diff_auxfields auxin) +void gkyl_fpo_vlasov_diff_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_diff_auxfields auxin +) { - gkyl_fpo_vlasov_diff_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.g->on_dev); + gkyl_fpo_vlasov_diff_set_auxfields_cu_kernel<<<1, 1> > >(eqn, auxin.g->on_dev); } // CUDA kernel to set device pointers to range object and vlasov fpo kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_fpo_vlasov_diff_set_cu_dev_ptrs(struct dg_fpo_vlasov_diff *fpo_vlasov_diff, enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ static void dg_fpo_vlasov_diff_set_cu_dev_ptrs( + struct dg_fpo_vlasov_diff *fpo_vlasov_diff, enum gkyl_basis_type b_type, int cdim, int poly_order +) { - fpo_vlasov_diff->auxfields.g = 0; + fpo_vlasov_diff->auxfields.g = 0; fpo_vlasov_diff->eqn.gen_surf_term = surf; fpo_vlasov_diff->eqn.gen_boundary_surf_term = boundary_surf; - const gkyl_dg_fpo_vlasov_diff_vol_kern_list* vol_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_xx_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_xy_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_xz_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_yx_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_yy_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_yz_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_zx_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_zy_kernels; - const gkyl_dg_fpo_vlasov_diff_surf_kern_list* surf_zz_kernels; - - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_xx_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_xy_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_xz_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_yx_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_yy_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_yz_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_zx_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_zy_kernels; - const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list* boundary_surf_zz_kernels; - + const gkyl_dg_fpo_vlasov_diff_vol_kern_list *vol_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_xx_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_xy_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_xz_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_yx_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_yy_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_yz_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_zx_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_zy_kernels; + const gkyl_dg_fpo_vlasov_diff_surf_kern_list *surf_zz_kernels; + + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_xx_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_xy_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_xz_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_yx_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_yy_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_yz_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_zx_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_zy_kernels; + const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list *boundary_surf_zz_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_xx_kernels = ser_surf_xx_kernels; - surf_xy_kernels = ser_surf_xy_kernels; - surf_xz_kernels = ser_surf_xz_kernels; - surf_yx_kernels = ser_surf_yx_kernels; - surf_yy_kernels = ser_surf_yy_kernels; - surf_yz_kernels = ser_surf_yz_kernels; - surf_zx_kernels = ser_surf_zx_kernels; - surf_zy_kernels = ser_surf_zy_kernels; - surf_zz_kernels = ser_surf_zz_kernels; - - boundary_surf_xx_kernels = ser_boundary_surf_xx_kernels; - boundary_surf_xy_kernels = ser_boundary_surf_xy_kernels; - boundary_surf_xz_kernels = ser_boundary_surf_xz_kernels; - boundary_surf_yx_kernels = ser_boundary_surf_yx_kernels; - boundary_surf_yy_kernels = ser_boundary_surf_yy_kernels; - boundary_surf_yz_kernels = ser_boundary_surf_yz_kernels; - boundary_surf_zx_kernels = ser_boundary_surf_zx_kernels; - boundary_surf_zy_kernels = ser_boundary_surf_zy_kernels; - boundary_surf_zz_kernels = ser_boundary_surf_zz_kernels; - - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_xx_kernels = ser_surf_xx_kernels; + surf_xy_kernels = ser_surf_xy_kernels; + surf_xz_kernels = ser_surf_xz_kernels; + surf_yx_kernels = ser_surf_yx_kernels; + surf_yy_kernels = ser_surf_yy_kernels; + surf_yz_kernels = ser_surf_yz_kernels; + surf_zx_kernels = ser_surf_zx_kernels; + surf_zy_kernels = ser_surf_zy_kernels; + surf_zz_kernels = ser_surf_zz_kernels; + + boundary_surf_xx_kernels = ser_boundary_surf_xx_kernels; + boundary_surf_xy_kernels = ser_boundary_surf_xy_kernels; + boundary_surf_xz_kernels = ser_boundary_surf_xz_kernels; + boundary_surf_yx_kernels = ser_boundary_surf_yx_kernels; + boundary_surf_yy_kernels = ser_boundary_surf_yy_kernels; + boundary_surf_yz_kernels = ser_boundary_surf_yz_kernels; + boundary_surf_zx_kernels = ser_boundary_surf_zx_kernels; + boundary_surf_zy_kernels = ser_boundary_surf_zy_kernels; + boundary_surf_zz_kernels = ser_boundary_surf_zz_kernels; + + break; + + default: + assert(false); + break; + } + fpo_vlasov_diff->eqn.vol_term = CK(vol_kernels, cdim, poly_order); fpo_vlasov_diff->surf[0][0] = CK(surf_xx_kernels, cdim, poly_order); @@ -113,11 +116,12 @@ dg_fpo_vlasov_diff_set_cu_dev_ptrs(struct dg_fpo_vlasov_diff *fpo_vlasov_diff, e fpo_vlasov_diff->boundary_surf[2][2] = CK(boundary_surf_zz_kernels, cdim, poly_order); } -struct gkyl_dg_eqn* -gkyl_dg_fpo_vlasov_diff_cu_dev_new(const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range) +struct gkyl_dg_eqn *gkyl_dg_fpo_vlasov_diff_cu_dev_new( + const struct gkyl_basis *pbasis, const struct gkyl_range *phase_range +) { struct dg_fpo_vlasov_diff *fpo_vlasov_diff = - (struct dg_fpo_vlasov_diff*) gkyl_malloc(sizeof(struct dg_fpo_vlasov_diff)); + (struct dg_fpo_vlasov_diff *)gkyl_malloc(sizeof(struct dg_fpo_vlasov_diff)); // Vlasov Fokker-Planck operator only defined in 3 velocity dimensions int pdim = pbasis->ndim, vdim = 3, cdim = pdim - vdim; @@ -135,15 +139,17 @@ gkyl_dg_fpo_vlasov_diff_cu_dev_new(const struct gkyl_basis* pbasis, const struct // copy the host struct to device struct struct dg_fpo_vlasov_diff *fpo_vlasov_diff_cu = - (struct dg_fpo_vlasov_diff*) gkyl_cu_malloc(sizeof(struct dg_fpo_vlasov_diff)); + (struct dg_fpo_vlasov_diff *)gkyl_cu_malloc(sizeof(struct dg_fpo_vlasov_diff)); - gkyl_cu_memcpy(fpo_vlasov_diff_cu, fpo_vlasov_diff, - sizeof(struct dg_fpo_vlasov_diff), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + fpo_vlasov_diff_cu, fpo_vlasov_diff, sizeof(struct dg_fpo_vlasov_diff), GKYL_CU_MEMCPY_H2D + ); - dg_fpo_vlasov_diff_set_cu_dev_ptrs<<<1,1>>>(fpo_vlasov_diff_cu, - pbasis->b_type, cdim, poly_order); + dg_fpo_vlasov_diff_set_cu_dev_ptrs<<<1, 1> > >( + fpo_vlasov_diff_cu, pbasis->b_type, cdim, poly_order + ); fpo_vlasov_diff->eqn.on_dev = &fpo_vlasov_diff_cu->eqn; - + return &fpo_vlasov_diff->eqn; } diff --git a/vlasov/zero/dg_fpo_vlasov_drag.c b/vlasov/zero/dg_fpo_vlasov_drag.c index c7d2004bca..e71e0b5521 100644 --- a/vlasov/zero/dg_fpo_vlasov_drag.c +++ b/vlasov/zero/dg_fpo_vlasov_drag.c @@ -9,44 +9,46 @@ #include // "Choose Kernel" based on cdim and polynomial order -#define CK(lst, cdim, poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_fpo_vlasov_drag_free(const struct gkyl_ref_count* ref) +void gkyl_fpo_vlasov_drag_free(const struct gkyl_ref_count *ref) { - struct gkyl_dg_eqn* base = container_of(ref, struct gkyl_dg_eqn, ref_count); - struct dg_fpo_vlasov_drag *fpo_vlasov_drag = container_of(base, struct dg_fpo_vlasov_drag, eqn); + struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); + struct dg_fpo_vlasov_drag *fpo_vlasov_drag = container_of(base, struct dg_fpo_vlasov_drag, eqn); - if (GKYL_IS_CU_ALLOC(fpo_vlasov_drag->eqn.flags)) + if (GKYL_IS_CU_ALLOC(fpo_vlasov_drag->eqn.flags)) { gkyl_cu_free(fpo_vlasov_drag->eqn.on_dev); - + } + gkyl_free(fpo_vlasov_drag); } -void -gkyl_fpo_vlasov_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, const struct gkyl_dg_fpo_vlasov_drag_auxfields auxin) +void gkyl_fpo_vlasov_drag_set_auxfields( + const struct gkyl_dg_eqn *eqn, const struct gkyl_dg_fpo_vlasov_drag_auxfields auxin +) { - #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(auxin.h)) { - gkyl_fpo_vlasov_drag_set_auxfields_cu(eqn->on_dev, auxin); - return; - } + if (gkyl_array_is_cu_dev(auxin.h)) { + gkyl_fpo_vlasov_drag_set_auxfields_cu(eqn->on_dev, auxin); + return; + } #endif struct dg_fpo_vlasov_drag *fpo_vlasov_drag = container_of(eqn, struct dg_fpo_vlasov_drag, eqn); fpo_vlasov_drag->auxfields.h = auxin.h; } -struct gkyl_dg_eqn* -gkyl_dg_fpo_vlasov_drag_new(const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_fpo_vlasov_drag_new( + const struct gkyl_basis *pbasis, const struct gkyl_range *phase_range, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) + if (use_gpu) { return gkyl_dg_fpo_vlasov_drag_cu_dev_new(pbasis, phase_range); + } #endif - struct dg_fpo_vlasov_drag* fpo_vlasov_drag = gkyl_malloc(sizeof(struct dg_fpo_vlasov_drag)); + struct dg_fpo_vlasov_drag *fpo_vlasov_drag = gkyl_malloc(sizeof(struct dg_fpo_vlasov_drag)); // Vlasov Fokker-Planck operator only defined in 3 velocity dimensions int pdim = pbasis->ndim, vdim = 3, cdim = pdim - vdim; @@ -61,24 +63,24 @@ gkyl_dg_fpo_vlasov_drag_new(const struct gkyl_basis* pbasis, const struct gkyl_r const gkyl_dg_fpo_vlasov_drag_vol_kern_list *vol_kernels; const gkyl_dg_fpo_vlasov_drag_surf_kern_list *surf_vx_kernels, *surf_vy_kernels, *surf_vz_kernels; - const gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list *boundary_surf_vx_kernels, *boundary_surf_vy_kernels, - *boundary_surf_vz_kernels; - + const gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list *boundary_surf_vx_kernels, + *boundary_surf_vy_kernels, *boundary_surf_vz_kernels; + switch (pbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vx_kernels = ser_surf_vx_kernels; - surf_vy_kernels = ser_surf_vy_kernels; - surf_vz_kernels = ser_surf_vz_kernels; - boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; - boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; - boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vx_kernels = ser_surf_vx_kernels; + surf_vy_kernels = ser_surf_vy_kernels; + surf_vz_kernels = ser_surf_vz_kernels; + boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; + boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; + boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; + break; + + default: + assert(false); + break; + } fpo_vlasov_drag->eqn.vol_term = CK(vol_kernels, cdim, poly_order); @@ -91,8 +93,12 @@ gkyl_dg_fpo_vlasov_drag_new(const struct gkyl_basis* pbasis, const struct gkyl_r fpo_vlasov_drag->boundary_surf[2] = CK(boundary_surf_vz_kernels, cdim, poly_order); // ensure non-NULL pointers - for (int i=0; isurf[i]); - for (int i=0; iboundary_surf[i]); + for (int i = 0; i < vdim; ++i) { + assert(fpo_vlasov_drag->surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(fpo_vlasov_drag->boundary_surf[i]); + } fpo_vlasov_drag->auxfields.h = 0; fpo_vlasov_drag->phase_range = *phase_range; @@ -101,14 +107,15 @@ gkyl_dg_fpo_vlasov_drag_new(const struct gkyl_basis* pbasis, const struct gkyl_r GKYL_CLEAR_CU_ALLOC(fpo_vlasov_drag->eqn.flags); fpo_vlasov_drag->eqn.ref_count = gkyl_ref_count_init(gkyl_fpo_vlasov_drag_free); fpo_vlasov_drag->eqn.on_dev = &fpo_vlasov_drag->eqn; - + return &fpo_vlasov_drag->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_fpo_vlasov_drag_cu_dev_new(const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range) +struct gkyl_dg_eqn *gkyl_dg_fpo_vlasov_drag_cu_dev_new( + const struct gkyl_basis *pbasis, const struct gkyl_range *phase_range +) { assert(false); return 0; diff --git a/vlasov/zero/dg_fpo_vlasov_drag_cu.cu b/vlasov/zero/dg_fpo_vlasov_drag_cu.cu index 2f9f69f3c3..26722d3948 100644 --- a/vlasov/zero/dg_fpo_vlasov_drag_cu.cu +++ b/vlasov/zero/dg_fpo_vlasov_drag_cu.cu @@ -3,64 +3,67 @@ extern "C" { #include #include -#include +#include #include } #include // "Choose Kernel" based on cdim and polynomial order -#define CK(lst, cdim, poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] // CUDA kernel to set pointer to g (second Rosenbluth potential). // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_fpo_vlasov_drag_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, const struct gkyl_array *h) +__global__ static void gkyl_fpo_vlasov_drag_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *h +) { struct dg_fpo_vlasov_drag *fpo_vlasov_drag = container_of(eqn, struct dg_fpo_vlasov_drag, eqn); fpo_vlasov_drag->auxfields.h = h; } //// Host-side wrapper for device kernels setting g (second Rosenbluth potential). -void -gkyl_fpo_vlasov_drag_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_drag_auxfields auxin) +void gkyl_fpo_vlasov_drag_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_drag_auxfields auxin +) { - gkyl_fpo_vlasov_drag_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.h->on_dev); + gkyl_fpo_vlasov_drag_set_auxfields_cu_kernel<<<1, 1> > >(eqn, auxin.h->on_dev); } // CUDA kernel to set device pointers to range object and vlasov fpo kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_fpo_vlasov_drag_set_cu_dev_ptrs(struct dg_fpo_vlasov_drag *fpo_vlasov_drag, enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ static void dg_fpo_vlasov_drag_set_cu_dev_ptrs( + struct dg_fpo_vlasov_drag *fpo_vlasov_drag, enum gkyl_basis_type b_type, int cdim, int poly_order +) { - fpo_vlasov_drag->auxfields.h = 0; + fpo_vlasov_drag->auxfields.h = 0; fpo_vlasov_drag->eqn.surf_term = surf; fpo_vlasov_drag->eqn.boundary_surf_term = boundary_surf; const gkyl_dg_fpo_vlasov_drag_vol_kern_list *vol_kernels; const gkyl_dg_fpo_vlasov_drag_surf_kern_list *surf_vx_kernels, *surf_vy_kernels, *surf_vz_kernels; - const gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list *boundary_surf_vx_kernels, *boundary_surf_vy_kernels, - *boundary_surf_vz_kernels; - + const gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list *boundary_surf_vx_kernels, + *boundary_surf_vy_kernels, *boundary_surf_vz_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vx_kernels = ser_surf_vx_kernels; - surf_vy_kernels = ser_surf_vy_kernels; - surf_vz_kernels = ser_surf_vz_kernels; - boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; - boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; - boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; - - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vx_kernels = ser_surf_vx_kernels; + surf_vy_kernels = ser_surf_vy_kernels; + surf_vz_kernels = ser_surf_vz_kernels; + boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; + boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; + boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; + + break; + + default: + assert(false); + break; + } + fpo_vlasov_drag->eqn.vol_term = CK(vol_kernels, cdim, poly_order); fpo_vlasov_drag->surf[0] = CK(surf_vx_kernels, cdim, poly_order); @@ -72,11 +75,12 @@ dg_fpo_vlasov_drag_set_cu_dev_ptrs(struct dg_fpo_vlasov_drag *fpo_vlasov_drag, e fpo_vlasov_drag->boundary_surf[2] = CK(boundary_surf_vz_kernels, cdim, poly_order); } -struct gkyl_dg_eqn* -gkyl_dg_fpo_vlasov_drag_cu_dev_new(const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range) +struct gkyl_dg_eqn *gkyl_dg_fpo_vlasov_drag_cu_dev_new( + const struct gkyl_basis *pbasis, const struct gkyl_range *phase_range +) { struct dg_fpo_vlasov_drag *fpo_vlasov_drag = - (struct dg_fpo_vlasov_drag*) gkyl_malloc(sizeof(struct dg_fpo_vlasov_drag)); + (struct dg_fpo_vlasov_drag *)gkyl_malloc(sizeof(struct dg_fpo_vlasov_drag)); // Vlasov Fokker-Planck operator only defined in 3 velocity dimensions int pdim = pbasis->ndim, vdim = 3, cdim = pdim - vdim; @@ -94,15 +98,17 @@ gkyl_dg_fpo_vlasov_drag_cu_dev_new(const struct gkyl_basis* pbasis, const struct // copy the host struct to device struct struct dg_fpo_vlasov_drag *fpo_vlasov_drag_cu = - (struct dg_fpo_vlasov_drag*) gkyl_cu_malloc(sizeof(struct dg_fpo_vlasov_drag)); + (struct dg_fpo_vlasov_drag *)gkyl_cu_malloc(sizeof(struct dg_fpo_vlasov_drag)); - gkyl_cu_memcpy(fpo_vlasov_drag_cu, fpo_vlasov_drag, - sizeof(struct dg_fpo_vlasov_drag), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + fpo_vlasov_drag_cu, fpo_vlasov_drag, sizeof(struct dg_fpo_vlasov_drag), GKYL_CU_MEMCPY_H2D + ); - dg_fpo_vlasov_drag_set_cu_dev_ptrs<<<1,1>>>(fpo_vlasov_drag_cu, - pbasis->b_type, cdim, poly_order); + dg_fpo_vlasov_drag_set_cu_dev_ptrs<<<1, 1> > >( + fpo_vlasov_drag_cu, pbasis->b_type, cdim, poly_order + ); fpo_vlasov_drag->eqn.on_dev = &fpo_vlasov_drag_cu->eqn; - + return &fpo_vlasov_drag->eqn; } diff --git a/vlasov/zero/dg_lbo_vlasov_diff.c b/vlasov/zero/dg_lbo_vlasov_diff.c index 4ec2c53773..9f1e01433a 100644 --- a/vlasov/zero/dg_lbo_vlasov_diff.c +++ b/vlasov/zero/dg_lbo_vlasov_diff.c @@ -8,27 +8,27 @@ #include #include -void -gkyl_lbo_vlasov_diff_free(const struct gkyl_ref_count* ref) +void gkyl_lbo_vlasov_diff_free(const struct gkyl_ref_count *ref) { - struct gkyl_dg_eqn* base = container_of(ref, struct gkyl_dg_eqn, ref_count); - struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(base, struct dg_lbo_vlasov_diff, eqn); + struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); + struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(base, struct dg_lbo_vlasov_diff, eqn); - if (GKYL_IS_CU_ALLOC(lbo_vlasov_diff->eqn.flags)) + if (GKYL_IS_CU_ALLOC(lbo_vlasov_diff->eqn.flags)) { gkyl_cu_free(lbo_vlasov_diff->eqn.on_dev); - + } + gkyl_free(lbo_vlasov_diff); } -void -gkyl_lbo_vlasov_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, const struct gkyl_dg_lbo_vlasov_diff_auxfields auxin) +void gkyl_lbo_vlasov_diff_set_auxfields( + const struct gkyl_dg_eqn *eqn, const struct gkyl_dg_lbo_vlasov_diff_auxfields auxin +) { - #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(auxin.nuSum) && gkyl_array_is_cu_dev(auxin.nuPrimMomsSum)) { - gkyl_lbo_vlasov_diff_set_auxfields_cu(eqn->on_dev, auxin); - return; - } + if (gkyl_array_is_cu_dev(auxin.nuSum) && gkyl_array_is_cu_dev(auxin.nuPrimMomsSum)) { + gkyl_lbo_vlasov_diff_set_auxfields_cu(eqn->on_dev, auxin); + return; + } #endif struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); @@ -36,19 +36,19 @@ gkyl_lbo_vlasov_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, const struct g lbo_vlasov_diff->auxfields.nuPrimMomsSum = auxin.nuPrimMomsSum; } - -struct gkyl_dg_eqn* -gkyl_dg_lbo_vlasov_diff_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_lbo_vlasov_diff_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_lbo_vlasov_diff_cu_dev_new(cbasis, pbasis, conf_range, pgrid); - } + } #endif - struct dg_lbo_vlasov_diff* lbo_vlasov_diff = gkyl_malloc(sizeof(struct dg_lbo_vlasov_diff)); + struct dg_lbo_vlasov_diff *lbo_vlasov_diff = gkyl_malloc(sizeof(struct dg_lbo_vlasov_diff)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; lbo_vlasov_diff->cdim = cdim; @@ -60,50 +60,58 @@ gkyl_dg_lbo_vlasov_diff_new(const struct gkyl_basis* cbasis, const struct gkyl_b lbo_vlasov_diff->eqn.boundary_surf_term = boundary_surf; lbo_vlasov_diff->vMaxSq = -1.; - for (int d=0; dviMax[d] = pgrid->upper[cdim+d]; - lbo_vlasov_diff->vMaxSq = fmax(lbo_vlasov_diff->vMaxSq, pow(pgrid->upper[cdim+d],2)); + for (int d = 0; d < vdim; d++) { + lbo_vlasov_diff->viMax[d] = pgrid->upper[cdim + d]; + lbo_vlasov_diff->vMaxSq = fmax(lbo_vlasov_diff->vMaxSq, pow(pgrid->upper[cdim + d], 2)); } lbo_vlasov_diff->num_cbasis = cbasis->num_basis; const gkyl_dg_lbo_vlasov_diff_vol_kern_list *vol_kernels; const gkyl_dg_lbo_vlasov_diff_surf_kern_list *surf_vx_kernels, *surf_vy_kernels, *surf_vz_kernels; - const gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list *boundary_surf_vx_kernels, *boundary_surf_vy_kernels, - *boundary_surf_vz_kernels; - + const gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list *boundary_surf_vx_kernels, + *boundary_surf_vy_kernels, *boundary_surf_vz_kernels; + switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vx_kernels = ser_surf_vx_kernels; - surf_vy_kernels = ser_surf_vy_kernels; - surf_vz_kernels = ser_surf_vz_kernels; - boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; - boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; - boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vx_kernels = ser_surf_vx_kernels; + surf_vy_kernels = ser_surf_vy_kernels; + surf_vz_kernels = ser_surf_vz_kernels; + boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; + boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; + boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; + break; + + default: + assert(false); + break; + } lbo_vlasov_diff->eqn.vol_term = CK(vol_kernels, cdim, vdim, poly_order); lbo_vlasov_diff->surf[0] = CK(surf_vx_kernels, cdim, vdim, poly_order); - if (vdim>1) + if (vdim > 1) { lbo_vlasov_diff->surf[1] = CK(surf_vy_kernels, cdim, vdim, poly_order); - if (vdim>2) + } + if (vdim > 2) { lbo_vlasov_diff->surf[2] = CK(surf_vz_kernels, cdim, vdim, poly_order); + } lbo_vlasov_diff->boundary_surf[0] = CK(boundary_surf_vx_kernels, cdim, vdim, poly_order); - if (vdim>1) + if (vdim > 1) { lbo_vlasov_diff->boundary_surf[1] = CK(boundary_surf_vy_kernels, cdim, vdim, poly_order); - if (vdim>2) + } + if (vdim > 2) { lbo_vlasov_diff->boundary_surf[2] = CK(boundary_surf_vz_kernels, cdim, vdim, poly_order); + } // ensure non-NULL pointers - for (int i=0; isurf[i]); - for (int i=0; iboundary_surf[i]); + for (int i = 0; i < vdim; ++i) { + assert(lbo_vlasov_diff->surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(lbo_vlasov_diff->boundary_surf[i]); + } lbo_vlasov_diff->auxfields.nuSum = 0; lbo_vlasov_diff->auxfields.nuPrimMomsSum = 0; @@ -113,15 +121,16 @@ gkyl_dg_lbo_vlasov_diff_new(const struct gkyl_basis* cbasis, const struct gkyl_b GKYL_CLEAR_CU_ALLOC(lbo_vlasov_diff->eqn.flags); lbo_vlasov_diff->eqn.ref_count = gkyl_ref_count_init(gkyl_lbo_vlasov_diff_free); lbo_vlasov_diff->eqn.on_dev = &lbo_vlasov_diff->eqn; - + return &lbo_vlasov_diff->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_lbo_vlasov_diff_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid) +struct gkyl_dg_eqn *gkyl_dg_lbo_vlasov_diff_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +) { assert(false); return 0; diff --git a/vlasov/zero/dg_lbo_vlasov_diff_cu.cu b/vlasov/zero/dg_lbo_vlasov_diff_cu.cu index 33a7b2ac87..3f9d8e7b00 100644 --- a/vlasov/zero/dg_lbo_vlasov_diff_cu.cu +++ b/vlasov/zero/dg_lbo_vlasov_diff_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include } @@ -12,9 +12,10 @@ extern "C" { // CUDA kernel to set pointer to nuSum, nuUSum and nuVtSqSum. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_lbo_vlasov_diff_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nuSum, - const struct gkyl_array *nuPrimMomsSum) +__global__ static void gkyl_lbo_vlasov_diff_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nuSum, + const struct gkyl_array *nuPrimMomsSum +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); lbo_vlasov_diff->auxfields.nuSum = nuSum; @@ -22,70 +23,78 @@ gkyl_lbo_vlasov_diff_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, cons } //// Host-side wrapper for device kernels setting nuSum, nuUSum and nuVtSqSum. -void -gkyl_lbo_vlasov_diff_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_diff_auxfields auxin) +void gkyl_lbo_vlasov_diff_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_diff_auxfields auxin +) { - gkyl_lbo_vlasov_diff_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.nuSum->on_dev, - auxin.nuPrimMomsSum->on_dev); + gkyl_lbo_vlasov_diff_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.nuSum->on_dev, auxin.nuPrimMomsSum->on_dev + ); } // CUDA kernel to set device pointers to range object and vlasov LBO kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_lbo_vlasov_diff_set_cu_dev_ptrs(struct dg_lbo_vlasov_diff *lbo_vlasov_diff, enum gkyl_basis_type b_type, - int cv_index, int cdim, int vdim, int poly_order) +__global__ static void dg_lbo_vlasov_diff_set_cu_dev_ptrs( + struct dg_lbo_vlasov_diff *lbo_vlasov_diff, enum gkyl_basis_type b_type, int cv_index, int cdim, + int vdim, int poly_order +) { - lbo_vlasov_diff->auxfields.nuSum = 0; - lbo_vlasov_diff->auxfields.nuPrimMomsSum = 0; + lbo_vlasov_diff->auxfields.nuSum = 0; + lbo_vlasov_diff->auxfields.nuPrimMomsSum = 0; lbo_vlasov_diff->eqn.surf_term = surf; lbo_vlasov_diff->eqn.boundary_surf_term = boundary_surf; const gkyl_dg_lbo_vlasov_diff_vol_kern_list *vol_kernels; const gkyl_dg_lbo_vlasov_diff_surf_kern_list *surf_vx_kernels, *surf_vy_kernels, *surf_vz_kernels; - const gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list *boundary_surf_vx_kernels, *boundary_surf_vy_kernels, - *boundary_surf_vz_kernels; - + const gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list *boundary_surf_vx_kernels, + *boundary_surf_vy_kernels, *boundary_surf_vz_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vx_kernels = ser_surf_vx_kernels; - surf_vy_kernels = ser_surf_vy_kernels; - surf_vz_kernels = ser_surf_vz_kernels; - boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; - boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; - boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; - - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vx_kernels = ser_surf_vx_kernels; + surf_vy_kernels = ser_surf_vy_kernels; + surf_vz_kernels = ser_surf_vz_kernels; + boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; + boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; + boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; + + break; + + default: + assert(false); + break; + } + lbo_vlasov_diff->eqn.vol_term = vol_kernels[cv_index].kernels[poly_order]; lbo_vlasov_diff->surf[0] = surf_vx_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { lbo_vlasov_diff->surf[1] = surf_vy_kernels[cv_index].kernels[poly_order]; - if (vdim>2) + } + if (vdim > 2) { lbo_vlasov_diff->surf[2] = surf_vz_kernels[cv_index].kernels[poly_order]; + } lbo_vlasov_diff->boundary_surf[0] = boundary_surf_vx_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { lbo_vlasov_diff->boundary_surf[1] = boundary_surf_vy_kernels[cv_index].kernels[poly_order]; - if (vdim>2) + } + if (vdim > 2) { lbo_vlasov_diff->boundary_surf[2] = boundary_surf_vz_kernels[cv_index].kernels[poly_order]; + } } -struct gkyl_dg_eqn* -gkyl_dg_lbo_vlasov_diff_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid) +struct gkyl_dg_eqn *gkyl_dg_lbo_vlasov_diff_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = - (struct dg_lbo_vlasov_diff*) gkyl_malloc(sizeof(struct dg_lbo_vlasov_diff)); + (struct dg_lbo_vlasov_diff *)gkyl_malloc(sizeof(struct dg_lbo_vlasov_diff)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; lbo_vlasov_diff->cdim = cdim; @@ -96,9 +105,9 @@ gkyl_dg_lbo_vlasov_diff_cu_dev_new(const struct gkyl_basis* cbasis, const struct lbo_vlasov_diff->conf_range = *conf_range; lbo_vlasov_diff->vMaxSq = -1.; - for (int d=0; dviMax[d] = pgrid->upper[cdim+d]; - lbo_vlasov_diff->vMaxSq = fmax(lbo_vlasov_diff->vMaxSq, pow(pgrid->upper[cdim+d],2)); + for (int d = 0; d < vdim; d++) { + lbo_vlasov_diff->viMax[d] = pgrid->upper[cdim + d]; + lbo_vlasov_diff->vMaxSq = fmax(lbo_vlasov_diff->vMaxSq, pow(pgrid->upper[cdim + d], 2)); } lbo_vlasov_diff->num_cbasis = cbasis->num_basis; @@ -108,15 +117,17 @@ gkyl_dg_lbo_vlasov_diff_cu_dev_new(const struct gkyl_basis* cbasis, const struct // copy the host struct to device struct struct dg_lbo_vlasov_diff *lbo_vlasov_diff_cu = - (struct dg_lbo_vlasov_diff*) gkyl_cu_malloc(sizeof(struct dg_lbo_vlasov_diff)); + (struct dg_lbo_vlasov_diff *)gkyl_cu_malloc(sizeof(struct dg_lbo_vlasov_diff)); - gkyl_cu_memcpy(lbo_vlasov_diff_cu, lbo_vlasov_diff, - sizeof(struct dg_lbo_vlasov_diff), GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + lbo_vlasov_diff_cu, lbo_vlasov_diff, sizeof(struct dg_lbo_vlasov_diff), GKYL_CU_MEMCPY_H2D + ); - dg_lbo_vlasov_diff_set_cu_dev_ptrs<<<1,1>>>(lbo_vlasov_diff_cu, - cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order); + dg_lbo_vlasov_diff_set_cu_dev_ptrs<<<1, 1> > >( + lbo_vlasov_diff_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order + ); lbo_vlasov_diff->eqn.on_dev = &lbo_vlasov_diff_cu->eqn; - + return &lbo_vlasov_diff->eqn; } diff --git a/vlasov/zero/dg_lbo_vlasov_drag.c b/vlasov/zero/dg_lbo_vlasov_drag.c index 0baf5b0a8d..a949b8b08a 100644 --- a/vlasov/zero/dg_lbo_vlasov_drag.c +++ b/vlasov/zero/dg_lbo_vlasov_drag.c @@ -8,27 +8,27 @@ #include #include -void -gkyl_lbo_vlasov_drag_free(const struct gkyl_ref_count* ref) +void gkyl_lbo_vlasov_drag_free(const struct gkyl_ref_count *ref) { - struct gkyl_dg_eqn* base = container_of(ref, struct gkyl_dg_eqn, ref_count); - struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(base, struct dg_lbo_vlasov_drag, eqn); + struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); + struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(base, struct dg_lbo_vlasov_drag, eqn); - if (GKYL_IS_CU_ALLOC(lbo_vlasov_drag->eqn.flags)) + if (GKYL_IS_CU_ALLOC(lbo_vlasov_drag->eqn.flags)) { gkyl_cu_free(lbo_vlasov_drag->eqn.on_dev); - + } + gkyl_free(lbo_vlasov_drag); } -void -gkyl_lbo_vlasov_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, const struct gkyl_dg_lbo_vlasov_drag_auxfields auxin) +void gkyl_lbo_vlasov_drag_set_auxfields( + const struct gkyl_dg_eqn *eqn, const struct gkyl_dg_lbo_vlasov_drag_auxfields auxin +) { - #ifdef GKYL_HAVE_CUDA - if (gkyl_array_is_cu_dev(auxin.nuSum) && gkyl_array_is_cu_dev(auxin.nuPrimMomsSum)) { - gkyl_lbo_vlasov_drag_set_auxfields_cu(eqn->on_dev, auxin); - return; - } + if (gkyl_array_is_cu_dev(auxin.nuSum) && gkyl_array_is_cu_dev(auxin.nuPrimMomsSum)) { + gkyl_lbo_vlasov_drag_set_auxfields_cu(eqn->on_dev, auxin); + return; + } #endif struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); @@ -36,18 +36,19 @@ gkyl_lbo_vlasov_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, const struct g lbo_vlasov_drag->auxfields.nuPrimMomsSum = auxin.nuPrimMomsSum; } -struct gkyl_dg_eqn* -gkyl_dg_lbo_vlasov_drag_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_lbo_vlasov_drag_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_lbo_vlasov_drag_cu_dev_new(cbasis, pbasis, conf_range, pgrid); - } + } #endif - struct dg_lbo_vlasov_drag* lbo_vlasov_drag = gkyl_malloc(sizeof(struct dg_lbo_vlasov_drag)); + struct dg_lbo_vlasov_drag *lbo_vlasov_drag = gkyl_malloc(sizeof(struct dg_lbo_vlasov_drag)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; lbo_vlasov_drag->cdim = cdim; @@ -59,50 +60,58 @@ gkyl_dg_lbo_vlasov_drag_new(const struct gkyl_basis* cbasis, const struct gkyl_b lbo_vlasov_drag->eqn.boundary_surf_term = boundary_surf; lbo_vlasov_drag->vMaxSq = -1.; - for (int d=0; dviMax[d] = pgrid->upper[cdim+d]; - lbo_vlasov_drag->vMaxSq = fmax(lbo_vlasov_drag->vMaxSq, pow(pgrid->upper[cdim+d],2)); + for (int d = 0; d < vdim; d++) { + lbo_vlasov_drag->viMax[d] = pgrid->upper[cdim + d]; + lbo_vlasov_drag->vMaxSq = fmax(lbo_vlasov_drag->vMaxSq, pow(pgrid->upper[cdim + d], 2)); } lbo_vlasov_drag->num_cbasis = cbasis->num_basis; const gkyl_dg_lbo_vlasov_drag_vol_kern_list *vol_kernels; const gkyl_dg_lbo_vlasov_drag_surf_kern_list *surf_vx_kernels, *surf_vy_kernels, *surf_vz_kernels; - const gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list *boundary_surf_vx_kernels, *boundary_surf_vy_kernels, - *boundary_surf_vz_kernels; - + const gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list *boundary_surf_vx_kernels, + *boundary_surf_vy_kernels, *boundary_surf_vz_kernels; + switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vx_kernels = ser_surf_vx_kernels; - surf_vy_kernels = ser_surf_vy_kernels; - surf_vz_kernels = ser_surf_vz_kernels; - boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; - boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; - boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; - break; - - default: - assert(false); - break; - } + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vx_kernels = ser_surf_vx_kernels; + surf_vy_kernels = ser_surf_vy_kernels; + surf_vz_kernels = ser_surf_vz_kernels; + boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; + boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; + boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; + break; + + default: + assert(false); + break; + } lbo_vlasov_drag->eqn.vol_term = CK(vol_kernels, cdim, vdim, poly_order); lbo_vlasov_drag->surf[0] = CK(surf_vx_kernels, cdim, vdim, poly_order); - if (vdim>1) + if (vdim > 1) { lbo_vlasov_drag->surf[1] = CK(surf_vy_kernels, cdim, vdim, poly_order); - if (vdim>2) + } + if (vdim > 2) { lbo_vlasov_drag->surf[2] = CK(surf_vz_kernels, cdim, vdim, poly_order); + } lbo_vlasov_drag->boundary_surf[0] = CK(boundary_surf_vx_kernels, cdim, vdim, poly_order); - if (vdim>1) + if (vdim > 1) { lbo_vlasov_drag->boundary_surf[1] = CK(boundary_surf_vy_kernels, cdim, vdim, poly_order); - if (vdim>2) + } + if (vdim > 2) { lbo_vlasov_drag->boundary_surf[2] = CK(boundary_surf_vz_kernels, cdim, vdim, poly_order); + } // ensure non-NULL pointers - for (int i=0; isurf[i]); - for (int i=0; iboundary_surf[i]); + for (int i = 0; i < vdim; ++i) { + assert(lbo_vlasov_drag->surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(lbo_vlasov_drag->boundary_surf[i]); + } lbo_vlasov_drag->auxfields.nuSum = 0; lbo_vlasov_drag->auxfields.nuPrimMomsSum = 0; @@ -112,15 +121,16 @@ gkyl_dg_lbo_vlasov_drag_new(const struct gkyl_basis* cbasis, const struct gkyl_b GKYL_CLEAR_CU_ALLOC(lbo_vlasov_drag->eqn.flags); lbo_vlasov_drag->eqn.ref_count = gkyl_ref_count_init(gkyl_lbo_vlasov_drag_free); lbo_vlasov_drag->eqn.on_dev = &lbo_vlasov_drag->eqn; - + return &lbo_vlasov_drag->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_lbo_vlasov_drag_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid) +struct gkyl_dg_eqn *gkyl_dg_lbo_vlasov_drag_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +) { assert(false); return 0; diff --git a/vlasov/zero/dg_lbo_vlasov_drag_cu.cu b/vlasov/zero/dg_lbo_vlasov_drag_cu.cu index 40537de90f..3684fe5fce 100644 --- a/vlasov/zero/dg_lbo_vlasov_drag_cu.cu +++ b/vlasov/zero/dg_lbo_vlasov_drag_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include } @@ -12,9 +12,10 @@ extern "C" { // CUDA kernel to set pointer to nuSum, sum of collisionalities // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_lbo_vlasov_drag_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nuSum, - const struct gkyl_array *nuPrimMomsSum) +__global__ static void gkyl_lbo_vlasov_drag_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *nuSum, + const struct gkyl_array *nuPrimMomsSum +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); lbo_vlasov_drag->auxfields.nuSum = nuSum; @@ -22,70 +23,78 @@ gkyl_lbo_vlasov_drag_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, cons } //// Host-side wrapper for device kernels setting nuSum, nuUSum and nuVtSqSum. -void -gkyl_lbo_vlasov_drag_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_drag_auxfields auxin) +void gkyl_lbo_vlasov_drag_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_drag_auxfields auxin +) { - gkyl_lbo_vlasov_drag_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.nuSum->on_dev, - auxin.nuPrimMomsSum->on_dev); + gkyl_lbo_vlasov_drag_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.nuSum->on_dev, auxin.nuPrimMomsSum->on_dev + ); } // CUDA kernel to set device pointers to range object and vlasov LBO kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_lbo_vlasov_drag_set_cu_dev_ptrs(struct dg_lbo_vlasov_drag *lbo_vlasov_drag, enum gkyl_basis_type b_type, - int cv_index, int cdim, int vdim, int poly_order) +__global__ static void dg_lbo_vlasov_drag_set_cu_dev_ptrs( + struct dg_lbo_vlasov_drag *lbo_vlasov_drag, enum gkyl_basis_type b_type, int cv_index, int cdim, + int vdim, int poly_order +) { - lbo_vlasov_drag->auxfields.nuSum = 0; - lbo_vlasov_drag->auxfields.nuPrimMomsSum = 0; + lbo_vlasov_drag->auxfields.nuSum = 0; + lbo_vlasov_drag->auxfields.nuPrimMomsSum = 0; lbo_vlasov_drag->eqn.surf_term = surf; lbo_vlasov_drag->eqn.boundary_surf_term = boundary_surf; const gkyl_dg_lbo_vlasov_drag_vol_kern_list *vol_kernels; const gkyl_dg_lbo_vlasov_drag_surf_kern_list *surf_vx_kernels, *surf_vy_kernels, *surf_vz_kernels; - const gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list *boundary_surf_vx_kernels, *boundary_surf_vy_kernels, - *boundary_surf_vz_kernels; - + const gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list *boundary_surf_vx_kernels, + *boundary_surf_vy_kernels, *boundary_surf_vz_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_vx_kernels = ser_surf_vx_kernels; - surf_vy_kernels = ser_surf_vy_kernels; - surf_vz_kernels = ser_surf_vz_kernels; - boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; - boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; - boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; - - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_vx_kernels = ser_surf_vx_kernels; + surf_vy_kernels = ser_surf_vy_kernels; + surf_vz_kernels = ser_surf_vz_kernels; + boundary_surf_vx_kernels = ser_boundary_surf_vx_kernels; + boundary_surf_vy_kernels = ser_boundary_surf_vy_kernels; + boundary_surf_vz_kernels = ser_boundary_surf_vz_kernels; + + break; + + default: + assert(false); + break; + } + lbo_vlasov_drag->eqn.vol_term = vol_kernels[cv_index].kernels[poly_order]; lbo_vlasov_drag->surf[0] = surf_vx_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { lbo_vlasov_drag->surf[1] = surf_vy_kernels[cv_index].kernels[poly_order]; - if (vdim>2) + } + if (vdim > 2) { lbo_vlasov_drag->surf[2] = surf_vz_kernels[cv_index].kernels[poly_order]; + } lbo_vlasov_drag->boundary_surf[0] = boundary_surf_vx_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { lbo_vlasov_drag->boundary_surf[1] = boundary_surf_vy_kernels[cv_index].kernels[poly_order]; - if (vdim>2) + } + if (vdim > 2) { lbo_vlasov_drag->boundary_surf[2] = boundary_surf_vz_kernels[cv_index].kernels[poly_order]; + } } -struct gkyl_dg_eqn* -gkyl_dg_lbo_vlasov_drag_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid) +struct gkyl_dg_eqn *gkyl_dg_lbo_vlasov_drag_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = - (struct dg_lbo_vlasov_drag*) gkyl_malloc(sizeof(struct dg_lbo_vlasov_drag)); + (struct dg_lbo_vlasov_drag *)gkyl_malloc(sizeof(struct dg_lbo_vlasov_drag)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; lbo_vlasov_drag->cdim = cdim; @@ -96,9 +105,9 @@ gkyl_dg_lbo_vlasov_drag_cu_dev_new(const struct gkyl_basis* cbasis, const struct lbo_vlasov_drag->conf_range = *conf_range; lbo_vlasov_drag->vMaxSq = -1.; - for (int d=0; dviMax[d] = pgrid->upper[cdim+d]; - lbo_vlasov_drag->vMaxSq = fmax(lbo_vlasov_drag->vMaxSq, pow(pgrid->upper[cdim+d],2)); + for (int d = 0; d < vdim; d++) { + lbo_vlasov_drag->viMax[d] = pgrid->upper[cdim + d]; + lbo_vlasov_drag->vMaxSq = fmax(lbo_vlasov_drag->vMaxSq, pow(pgrid->upper[cdim + d], 2)); } lbo_vlasov_drag->num_cbasis = cbasis->num_basis; @@ -108,15 +117,17 @@ gkyl_dg_lbo_vlasov_drag_cu_dev_new(const struct gkyl_basis* cbasis, const struct // copy the host struct to device struct struct dg_lbo_vlasov_drag *lbo_vlasov_drag_cu = - (struct dg_lbo_vlasov_drag*) gkyl_cu_malloc(sizeof(struct dg_lbo_vlasov_drag)); + (struct dg_lbo_vlasov_drag *)gkyl_cu_malloc(sizeof(struct dg_lbo_vlasov_drag)); + + gkyl_cu_memcpy( + lbo_vlasov_drag_cu, lbo_vlasov_drag, sizeof(struct dg_lbo_vlasov_drag), GKYL_CU_MEMCPY_H2D + ); - gkyl_cu_memcpy(lbo_vlasov_drag_cu, lbo_vlasov_drag, - sizeof(struct dg_lbo_vlasov_drag), GKYL_CU_MEMCPY_H2D); + dg_lbo_vlasov_drag_set_cu_dev_ptrs<<<1, 1> > >( + lbo_vlasov_drag_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order + ); - dg_lbo_vlasov_drag_set_cu_dev_ptrs<<<1,1>>>(lbo_vlasov_drag_cu, - cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order); + lbo_vlasov_drag->eqn.on_dev = &lbo_vlasov_drag_cu->eqn; - lbo_vlasov_drag->eqn.on_dev = &lbo_vlasov_drag_cu->eqn; - return &lbo_vlasov_drag->eqn; } diff --git a/vlasov/zero/dg_maxwell.c b/vlasov/zero/dg_maxwell.c index 741b5df93c..b0e942de97 100644 --- a/vlasov/zero/dg_maxwell.c +++ b/vlasov/zero/dg_maxwell.c @@ -9,10 +9,9 @@ #include // "Choose Kernel" based on cdim and polyorder -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -void -gkyl_maxwell_free(const struct gkyl_ref_count *ref) +void gkyl_maxwell_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); @@ -20,20 +19,21 @@ gkyl_maxwell_free(const struct gkyl_ref_count *ref) // free inner on_dev object struct dg_maxwell *maxwell = container_of(base->on_dev, struct dg_maxwell, eqn); gkyl_cu_free(maxwell); - } - + } + struct dg_maxwell *maxwell = container_of(base, struct dg_maxwell, eqn); gkyl_free(maxwell); } -struct gkyl_dg_eqn* -gkyl_dg_maxwell_new(const struct gkyl_basis* cbasis, - double lightSpeed, double elcErrorSpeedFactor, double mgnErrorSpeedFactor, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_maxwell_new( + const struct gkyl_basis *cbasis, double lightSpeed, double elcErrorSpeedFactor, + double mgnErrorSpeedFactor, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_maxwell_cu_dev_new(cbasis, lightSpeed, elcErrorSpeedFactor, mgnErrorSpeedFactor); - } + } #endif struct dg_maxwell *maxwell = gkyl_malloc(sizeof(struct dg_maxwell)); @@ -44,59 +44,64 @@ gkyl_dg_maxwell_new(const struct gkyl_basis* cbasis, const gkyl_dg_maxwell_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - surf_z_kernels = ser_surf_z_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - surf_x_kernels = ten_surf_x_kernels; - surf_y_kernels = ten_surf_y_kernels; - surf_z_kernels = ten_surf_z_kernels; - - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + surf_z_kernels = ser_surf_z_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + surf_x_kernels = ten_surf_x_kernels; + surf_y_kernels = ten_surf_y_kernels; + surf_z_kernels = ten_surf_z_kernels; + + break; + + default: + assert(false); + break; + } + maxwell->eqn.num_equations = 8; maxwell->eqn.surf_term = surf; maxwell->eqn.boundary_surf_term = boundary_surf; maxwell->maxwell_data.c = lightSpeed; - maxwell->maxwell_data.chi = lightSpeed*elcErrorSpeedFactor; - maxwell->maxwell_data.gamma = lightSpeed*mgnErrorSpeedFactor; + maxwell->maxwell_data.chi = lightSpeed * elcErrorSpeedFactor; + maxwell->maxwell_data.gamma = lightSpeed * mgnErrorSpeedFactor; maxwell->eqn.vol_term = CK(vol_kernels, cdim, poly_order); maxwell->surf[0] = CK(surf_x_kernels, cdim, poly_order); - if (cdim>1) + if (cdim > 1) { maxwell->surf[1] = CK(surf_y_kernels, cdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { maxwell->surf[2] = CK(surf_z_kernels, cdim, poly_order); + } - // ensure non-NULL pointers - for (int i=0; isurf[i]); + // ensure non-NULL pointers + for (int i = 0; i < cdim; ++i) { + assert(maxwell->surf[i]); + } maxwell->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(maxwell->eqn.flags); maxwell->eqn.ref_count = gkyl_ref_count_init(gkyl_maxwell_free); maxwell->eqn.on_dev = &maxwell->eqn; // CPU eqn obj points to itself - + return &maxwell->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_maxwell_cu_dev_new(const struct gkyl_basis* cbasis, - double lightSpeed, double elcErrorSpeedFactor, double mgnErrorSpeedFactor) +struct gkyl_dg_eqn *gkyl_dg_maxwell_cu_dev_new( + const struct gkyl_basis *cbasis, double lightSpeed, double elcErrorSpeedFactor, + double mgnErrorSpeedFactor +) { assert(false); return 0; diff --git a/vlasov/zero/dg_maxwell_cu.cu b/vlasov/zero/dg_maxwell_cu.cu index 38ba05a28e..fcc5155cb6 100644 --- a/vlasov/zero/dg_maxwell_cu.cu +++ b/vlasov/zero/dg_maxwell_cu.cu @@ -3,74 +3,80 @@ extern "C" { #include #include -#include +#include #include } #include -#define CK(lst,cdim,poly_order) lst[cdim-1].kernels[poly_order] +#define CK(lst, cdim, poly_order) lst[cdim - 1].kernels[poly_order] -__global__ void static -dg_maxwell_set_cu_dev_ptrs(struct dg_maxwell* maxwell, enum gkyl_basis_type b_type, int cdim, int poly_order) +__global__ void static dg_maxwell_set_cu_dev_ptrs( + struct dg_maxwell *maxwell, enum gkyl_basis_type b_type, int cdim, int poly_order +) { const gkyl_dg_maxwell_vol_kern_list *vol_kernels; - const gkyl_dg_maxwell_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; - + const gkyl_dg_maxwell_surf_kern_list *surf_x_kernels, *surf_y_kernels, *surf_z_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - vol_kernels = ser_vol_kernels; - surf_x_kernels = ser_surf_x_kernels; - surf_y_kernels = ser_surf_y_kernels; - surf_z_kernels = ser_surf_z_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - vol_kernels = ten_vol_kernels; - surf_x_kernels = ten_surf_x_kernels; - surf_y_kernels = ten_surf_y_kernels; - surf_z_kernels = ten_surf_z_kernels; - - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + vol_kernels = ser_vol_kernels; + surf_x_kernels = ser_surf_x_kernels; + surf_y_kernels = ser_surf_y_kernels; + surf_z_kernels = ser_surf_z_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + vol_kernels = ten_vol_kernels; + surf_x_kernels = ten_surf_x_kernels; + surf_y_kernels = ten_surf_y_kernels; + surf_z_kernels = ten_surf_z_kernels; + + break; + + default: + assert(false); + break; + } + maxwell->eqn.surf_term = surf; maxwell->eqn.boundary_surf_term = boundary_surf; maxwell->eqn.vol_term = CK(vol_kernels, cdim, poly_order); maxwell->surf[0] = CK(surf_x_kernels, cdim, poly_order); - if (cdim>1) + if (cdim > 1) { maxwell->surf[1] = CK(surf_y_kernels, cdim, poly_order); - if (cdim>2) + } + if (cdim > 2) { maxwell->surf[2] = CK(surf_z_kernels, cdim, poly_order); + } } -struct gkyl_dg_eqn* -gkyl_dg_maxwell_cu_dev_new(const struct gkyl_basis* cbasis, - double lightSpeed, double elcErrorSpeedFactor, double mgnErrorSpeedFactor) +struct gkyl_dg_eqn *gkyl_dg_maxwell_cu_dev_new( + const struct gkyl_basis *cbasis, double lightSpeed, double elcErrorSpeedFactor, + double mgnErrorSpeedFactor +) { - struct dg_maxwell *maxwell = (struct dg_maxwell*) gkyl_malloc(sizeof(struct dg_maxwell)); + struct dg_maxwell *maxwell = (struct dg_maxwell *)gkyl_malloc(sizeof(struct dg_maxwell)); // set basic parameters maxwell->eqn.num_equations = 8; maxwell->maxwell_data.c = lightSpeed; - maxwell->maxwell_data.chi = lightSpeed*elcErrorSpeedFactor; - maxwell->maxwell_data.gamma = lightSpeed*mgnErrorSpeedFactor; + maxwell->maxwell_data.chi = lightSpeed * elcErrorSpeedFactor; + maxwell->maxwell_data.gamma = lightSpeed * mgnErrorSpeedFactor; maxwell->eqn.flags = 0; GKYL_SET_CU_ALLOC(maxwell->eqn.flags); maxwell->eqn.ref_count = gkyl_ref_count_init(gkyl_maxwell_free); // copy the host struct to device struct - struct dg_maxwell *maxwell_cu = (struct dg_maxwell*) gkyl_cu_malloc(sizeof(struct dg_maxwell)); + struct dg_maxwell *maxwell_cu = (struct dg_maxwell *)gkyl_cu_malloc(sizeof(struct dg_maxwell)); gkyl_cu_memcpy(maxwell_cu, maxwell, sizeof(struct dg_maxwell), GKYL_CU_MEMCPY_H2D); - dg_maxwell_set_cu_dev_ptrs<<<1,1>>>(maxwell_cu, cbasis->b_type, cbasis->ndim, cbasis->poly_order); + dg_maxwell_set_cu_dev_ptrs<<<1, 1> > >( + maxwell_cu, cbasis->b_type, cbasis->ndim, cbasis->poly_order + ); // set parent on_dev pointer maxwell->eqn.on_dev = &maxwell_cu->eqn; diff --git a/vlasov/zero/dg_updater_diffusion_fluid.c b/vlasov/zero/dg_updater_diffusion_fluid.c index fab1f74492..63134c6088 100644 --- a/vlasov/zero/dg_updater_diffusion_fluid.c +++ b/vlasov/zero/dg_updater_diffusion_fluid.c @@ -10,55 +10,67 @@ #include #include -struct gkyl_dg_eqn* +struct gkyl_dg_eqn * gkyl_dg_updater_diffusion_fluid_acquire_eqn(const struct gkyl_dg_updater_diffusion_fluid *up) { return gkyl_dg_eqn_acquire(up->dgeqn); } -struct gkyl_dg_updater_diffusion_fluid* -gkyl_dg_updater_diffusion_fluid_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, bool is_diff_const, int num_equations, - const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range, - const bool *is_zero_flux_dir, bool use_gpu) +struct gkyl_dg_updater_diffusion_fluid *gkyl_dg_updater_diffusion_fluid_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, bool is_diff_const, + int num_equations, const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range, + const bool *is_zero_flux_dir, bool use_gpu +) { - struct gkyl_dg_updater_diffusion_fluid *up = gkyl_malloc(sizeof(struct gkyl_dg_updater_diffusion_fluid)); + struct gkyl_dg_updater_diffusion_fluid *up = + gkyl_malloc(sizeof(struct gkyl_dg_updater_diffusion_fluid)); int ndim = basis->ndim; up->use_gpu = use_gpu; bool is_dir_diffusive[GKYL_MAX_CDIM]; - for (int d=0; ddgeqn = gkyl_dg_diffusion_fluid_new(basis, is_diff_const, num_equations, is_dir_diffusive, - diff_order, diff_range, up->use_gpu); + up->dgeqn = gkyl_dg_diffusion_fluid_new( + basis, is_diff_const, num_equations, is_dir_diffusive, diff_order, diff_range, up->use_gpu + ); int num_up_dirs = 0; - for (int d=0; dhyperdg = gkyl_hyper_dg_new(grid, basis, up->dgeqn, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu); + up->hyperdg = gkyl_hyper_dg_new( + grid, basis, up->dgeqn, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu + ); up->diffusion_tm = 0.0; return up; } -void -gkyl_dg_updater_diffusion_fluid_advance(struct gkyl_dg_updater_diffusion_fluid *up, - const struct gkyl_range *update_rng, const struct gkyl_array *coeff, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT cflrate, - struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_diffusion_fluid_advance( + struct gkyl_dg_updater_diffusion_fluid *up, const struct gkyl_range *update_rng, + const struct gkyl_array *coeff, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT cflrate, struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); // Set arrays needed and call the specific advance method required - gkyl_dg_diffusion_fluid_set_auxfields(up->dgeqn, (struct gkyl_dg_diffusion_fluid_auxfields) { .D = coeff }); + gkyl_dg_diffusion_fluid_set_auxfields( + up->dgeqn, (struct gkyl_dg_diffusion_fluid_auxfields){.D = coeff} + ); gkyl_hyper_dg_advance(up->hyperdg, update_rng, fIn, cflrate, rhs); up->diffusion_tm += gkyl_time_diff_now_sec(wst); } @@ -66,13 +78,10 @@ gkyl_dg_updater_diffusion_fluid_advance(struct gkyl_dg_updater_diffusion_fluid * struct gkyl_dg_updater_diffusion_fluid_tm gkyl_dg_updater_diffusion_fluid_get_tm(const struct gkyl_dg_updater_diffusion_fluid *up) { - return (struct gkyl_dg_updater_diffusion_fluid_tm) { - .diffusion_tm = up->diffusion_tm, - }; + return (struct gkyl_dg_updater_diffusion_fluid_tm){.diffusion_tm = up->diffusion_tm}; } -void -gkyl_dg_updater_diffusion_fluid_release(struct gkyl_dg_updater_diffusion_fluid *up) +void gkyl_dg_updater_diffusion_fluid_release(struct gkyl_dg_updater_diffusion_fluid *up) { gkyl_dg_eqn_release(up->dgeqn); gkyl_hyper_dg_release(up->hyperdg); diff --git a/vlasov/zero/dg_updater_diffusion_gen.c b/vlasov/zero/dg_updater_diffusion_gen.c index db7265a9d0..d843f595a1 100644 --- a/vlasov/zero/dg_updater_diffusion_gen.c +++ b/vlasov/zero/dg_updater_diffusion_gen.c @@ -10,53 +10,58 @@ #include #include -struct gkyl_dg_eqn* +struct gkyl_dg_eqn * gkyl_dg_updater_diffusion_gen_acquire_eqn(const struct gkyl_dg_updater_diffusion_gen *up) { return gkyl_dg_eqn_acquire(up->dgeqn); } -struct gkyl_dg_updater_diffusion_gen* -gkyl_dg_updater_diffusion_gen_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, const struct gkyl_range *diff_range, bool use_gpu) +struct gkyl_dg_updater_diffusion_gen *gkyl_dg_updater_diffusion_gen_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_range *diff_range, bool use_gpu +) { - struct gkyl_dg_updater_diffusion_gen *up = gkyl_malloc(sizeof(struct gkyl_dg_updater_diffusion_gen)); + struct gkyl_dg_updater_diffusion_gen *up = + gkyl_malloc(sizeof(struct gkyl_dg_updater_diffusion_gen)); up->use_gpu = use_gpu; up->dgeqn = gkyl_dg_diffusion_gen_new(basis, diff_range, up->use_gpu); int ndim = basis->ndim; - int up_dirs[GKYL_MAX_DIM], zero_flux_flags[2*GKYL_MAX_DIM]; - for (int d=0; dhyperdg = gkyl_hyper_dg_new(grid, basis, up->dgeqn, ndim, up_dirs, zero_flux_flags, 1, up->use_gpu); + up->hyperdg = + gkyl_hyper_dg_new(grid, basis, up->dgeqn, ndim, up_dirs, zero_flux_flags, 1, up->use_gpu); up->diffusion_tm = 0.0; return up; } -void -gkyl_dg_updater_diffusion_gen_advance(struct gkyl_dg_updater_diffusion_gen *up, - const struct gkyl_range *update_rng, const struct gkyl_array *coeff, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT cflrate, - struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_diffusion_gen_advance( + struct gkyl_dg_updater_diffusion_gen *up, const struct gkyl_range *update_rng, + const struct gkyl_array *coeff, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT cflrate, struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); // Set arrays needed and call the specific advance method required - gkyl_diffusion_gen_set_auxfields(up->dgeqn, (struct gkyl_dg_diffusion_gen_auxfields) { .Dij = coeff }); + gkyl_diffusion_gen_set_auxfields( + up->dgeqn, (struct gkyl_dg_diffusion_gen_auxfields){.Dij = coeff} + ); #ifdef GKYL_HAVE_CUDA -// if (up->use_gpu) -// // hyper_dg_gen_stencil NOT YET IMPLEMENTED ON DEVICE -// gkyl_hyper_dg_gen_stencil_advance_cu(up->hyperdg, update_rng, fIn, cflrate, rhs); -// else -// gkyl_hyper_dg_gen_stencil_advance(up->hyperdg, update_rng, fIn, cflrate, rhs); - assert(false); + // if (up->use_gpu) + // // hyper_dg_gen_stencil NOT YET IMPLEMENTED ON DEVICE + // gkyl_hyper_dg_gen_stencil_advance_cu(up->hyperdg, update_rng, fIn, cflrate, rhs); + // else + // gkyl_hyper_dg_gen_stencil_advance(up->hyperdg, update_rng, fIn, cflrate, rhs); + assert(false); #else - gkyl_hyper_dg_gen_stencil_advance(up->hyperdg, update_rng, fIn, cflrate, rhs); + gkyl_hyper_dg_gen_stencil_advance(up->hyperdg, update_rng, fIn, cflrate, rhs); #endif up->diffusion_tm += gkyl_time_diff_now_sec(wst); } @@ -64,13 +69,10 @@ gkyl_dg_updater_diffusion_gen_advance(struct gkyl_dg_updater_diffusion_gen *up, struct gkyl_dg_updater_diffusion_gen_tm gkyl_dg_updater_diffusion_gen_get_tm(const struct gkyl_dg_updater_diffusion_gen *up) { - return (struct gkyl_dg_updater_diffusion_gen_tm) { - .diffusion_tm = up->diffusion_tm, - }; + return (struct gkyl_dg_updater_diffusion_gen_tm){.diffusion_tm = up->diffusion_tm}; } -void -gkyl_dg_updater_diffusion_gen_release(struct gkyl_dg_updater_diffusion_gen *up) +void gkyl_dg_updater_diffusion_gen_release(struct gkyl_dg_updater_diffusion_gen *up) { gkyl_dg_eqn_release(up->dgeqn); gkyl_hyper_dg_release(up->hyperdg); diff --git a/vlasov/zero/dg_updater_diffusion_vlasov.c b/vlasov/zero/dg_updater_diffusion_vlasov.c index 5ab41a9c44..a52f6a7344 100644 --- a/vlasov/zero/dg_updater_diffusion_vlasov.c +++ b/vlasov/zero/dg_updater_diffusion_vlasov.c @@ -10,56 +10,68 @@ #include #include -struct gkyl_dg_eqn* +struct gkyl_dg_eqn * gkyl_dg_updater_diffusion_vlasov_acquire_eqn(const struct gkyl_dg_updater_diffusion_vlasov *up) { return gkyl_dg_eqn_acquire(up->dgeqn); } -struct gkyl_dg_updater_diffusion_vlasov* -gkyl_dg_updater_diffusion_vlasov_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, - const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range, - const bool *is_zero_flux_dir, bool use_gpu) +struct gkyl_dg_updater_diffusion_vlasov *gkyl_dg_updater_diffusion_vlasov_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_basis *cbasis, bool is_diff_const, const bool *diff_in_dir, int diff_order, + const struct gkyl_range *diff_range, const bool *is_zero_flux_dir, bool use_gpu +) { - struct gkyl_dg_updater_diffusion_vlasov *up = gkyl_malloc(sizeof(struct gkyl_dg_updater_diffusion_vlasov)); + struct gkyl_dg_updater_diffusion_vlasov *up = + gkyl_malloc(sizeof(struct gkyl_dg_updater_diffusion_vlasov)); int pdim = basis->ndim; int cdim = cbasis->ndim; up->use_gpu = use_gpu; bool is_dir_diffusive[GKYL_MAX_CDIM]; - for (int d=0; ddgeqn = gkyl_dg_diffusion_vlasov_new(basis, cbasis, is_diff_const, is_dir_diffusive, - diff_order, diff_range, up->use_gpu); + up->dgeqn = gkyl_dg_diffusion_vlasov_new( + basis, cbasis, is_diff_const, is_dir_diffusive, diff_order, diff_range, up->use_gpu + ); int num_up_dirs = 0; - for (int d=0; dhyperdg = gkyl_hyper_dg_new(grid, basis, up->dgeqn, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu); + up->hyperdg = gkyl_hyper_dg_new( + grid, basis, up->dgeqn, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu + ); up->diffusion_tm = 0.0; return up; } -void -gkyl_dg_updater_diffusion_vlasov_advance(struct gkyl_dg_updater_diffusion_vlasov *up, - const struct gkyl_range *update_rng, const struct gkyl_array *coeff, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT cflrate, - struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_diffusion_vlasov_advance( + struct gkyl_dg_updater_diffusion_vlasov *up, const struct gkyl_range *update_rng, + const struct gkyl_array *coeff, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT cflrate, struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); // Set arrays needed and call the specific advance method required - gkyl_dg_diffusion_vlasov_set_auxfields(up->dgeqn, (struct gkyl_dg_diffusion_vlasov_auxfields) { .D = coeff }); + gkyl_dg_diffusion_vlasov_set_auxfields( + up->dgeqn, (struct gkyl_dg_diffusion_vlasov_auxfields){.D = coeff} + ); gkyl_hyper_dg_advance(up->hyperdg, update_rng, fIn, cflrate, rhs); up->diffusion_tm += gkyl_time_diff_now_sec(wst); } @@ -67,13 +79,10 @@ gkyl_dg_updater_diffusion_vlasov_advance(struct gkyl_dg_updater_diffusion_vlasov struct gkyl_dg_updater_diffusion_vlasov_tm gkyl_dg_updater_diffusion_vlasov_get_tm(const struct gkyl_dg_updater_diffusion_vlasov *up) { - return (struct gkyl_dg_updater_diffusion_vlasov_tm) { - .diffusion_tm = up->diffusion_tm, - }; + return (struct gkyl_dg_updater_diffusion_vlasov_tm){.diffusion_tm = up->diffusion_tm}; } -void -gkyl_dg_updater_diffusion_vlasov_release(struct gkyl_dg_updater_diffusion_vlasov *up) +void gkyl_dg_updater_diffusion_vlasov_release(struct gkyl_dg_updater_diffusion_vlasov *up) { gkyl_dg_eqn_release(up->dgeqn); gkyl_hyper_dg_release(up->hyperdg); diff --git a/vlasov/zero/dg_updater_fluid.c b/vlasov/zero/dg_updater_fluid.c index 3cbd9c8006..9ea8bcda01 100644 --- a/vlasov/zero/dg_updater_fluid.c +++ b/vlasov/zero/dg_updater_fluid.c @@ -13,16 +13,16 @@ #include #include -struct gkyl_dg_eqn* -gkyl_dg_updater_fluid_acquire_eqn(const gkyl_dg_updater_fluid* fluid) +struct gkyl_dg_eqn *gkyl_dg_updater_fluid_acquire_eqn(const gkyl_dg_updater_fluid *fluid) { return gkyl_dg_eqn_acquire(fluid->eqn_fluid); } -gkyl_dg_updater_fluid* -gkyl_dg_updater_fluid_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, void *aux_inp, bool use_gpu) +gkyl_dg_updater_fluid *gkyl_dg_updater_fluid_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_range *conf_range, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_geom *geom, void *aux_inp, bool use_gpu +) { gkyl_dg_updater_fluid *up = gkyl_malloc(sizeof(gkyl_dg_updater_fluid)); up->eqn_id = wv_eqn->type; @@ -31,53 +31,50 @@ gkyl_dg_updater_fluid_new(const struct gkyl_rect_grid *grid, up->eqn_fluid = gkyl_dg_advection_new(cbasis, conf_range, up->use_gpu); struct gkyl_dg_advection_auxfields *adv_in = aux_inp; gkyl_advection_set_auxfields(up->eqn_fluid, *adv_in); - } - else if (up->eqn_id == GKYL_EQN_EULER) { + } else if (up->eqn_id == GKYL_EQN_EULER) { up->eqn_fluid = gkyl_dg_euler_new(cbasis, conf_range, wv_eqn, geom, up->use_gpu); struct gkyl_dg_euler_auxfields *euler_inp = aux_inp; gkyl_euler_set_auxfields(up->eqn_fluid, *euler_inp); - } - else { + } else { up->eqn_fluid = gkyl_dg_canonical_pb_fluid_new(cbasis, conf_range, wv_eqn, up->use_gpu); struct gkyl_dg_canonical_pb_fluid_auxfields *dg_can_pb_fluid_inp = aux_inp; - gkyl_canonical_pb_fluid_set_auxfields(up->eqn_fluid, *dg_can_pb_fluid_inp); + gkyl_canonical_pb_fluid_set_auxfields(up->eqn_fluid, *dg_can_pb_fluid_inp); } int cdim = cbasis->ndim; - int up_dirs[GKYL_MAX_DIM], zero_flux_flags[2*GKYL_MAX_DIM]; - for (int d=0; dup_fluid = gkyl_hyper_dg_new(grid, cbasis, up->eqn_fluid, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu); + up->up_fluid = gkyl_hyper_dg_new( + grid, cbasis, up->eqn_fluid, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu + ); up->fluid_tm = 0.0; return up; } -void -gkyl_dg_updater_fluid_advance(gkyl_dg_updater_fluid *fluid, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fluidIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_fluid_advance( + gkyl_dg_updater_fluid *fluid, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fluidIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(fluid->up_fluid, update_rng, fluidIn, cflrate, rhs); fluid->fluid_tm += gkyl_time_diff_now_sec(wst); } -struct gkyl_dg_updater_fluid_tm -gkyl_dg_updater_fluid_get_tm(const gkyl_dg_updater_fluid *fluid) +struct gkyl_dg_updater_fluid_tm gkyl_dg_updater_fluid_get_tm(const gkyl_dg_updater_fluid *fluid) { - return (struct gkyl_dg_updater_fluid_tm) { - .fluid_tm = fluid->fluid_tm, - }; + return (struct gkyl_dg_updater_fluid_tm){.fluid_tm = fluid->fluid_tm}; } -void -gkyl_dg_updater_fluid_release(gkyl_dg_updater_fluid* fluid) +void gkyl_dg_updater_fluid_release(gkyl_dg_updater_fluid *fluid) { gkyl_dg_eqn_release(fluid->eqn_fluid); gkyl_hyper_dg_release(fluid->up_fluid); diff --git a/vlasov/zero/dg_updater_fpo_vlasov.c b/vlasov/zero/dg_updater_fpo_vlasov.c index 7f4ebb409e..73d872d349 100644 --- a/vlasov/zero/dg_updater_fpo_vlasov.c +++ b/vlasov/zero/dg_updater_fpo_vlasov.c @@ -11,9 +11,10 @@ #include #include -struct gkyl_dg_updater_collisions* -gkyl_dg_updater_fpo_vlasov_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis *pbasis, - const struct gkyl_range *phase_range, bool use_gpu) +struct gkyl_dg_updater_collisions *gkyl_dg_updater_fpo_vlasov_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, bool use_gpu +) { struct gkyl_dg_updater_collisions *up = gkyl_malloc(sizeof(gkyl_dg_updater_collisions)); @@ -24,40 +25,49 @@ gkyl_dg_updater_fpo_vlasov_new(const struct gkyl_rect_grid *grid, const struct g int vdim = 3; int cdim = pdim - vdim; int num_up_dirs = vdim; - int up_dirs[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim - vdim; + } - int zero_flux_flags[2*GKYL_MAX_DIM] = { 0 }; - for (int d=cdim; ddiff = gkyl_hyper_dg_new(grid, pbasis, up->coll_diff, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu); - up->drag = gkyl_hyper_dg_new(grid, pbasis, up->coll_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu); + int zero_flux_flags[2 * GKYL_MAX_DIM] = {0}; + for (int d = cdim; d < pdim; ++d) { + zero_flux_flags[d] = zero_flux_flags[d + pdim] = 1; + } + + up->diff = gkyl_hyper_dg_new( + grid, pbasis, up->coll_diff, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu + ); + up->drag = gkyl_hyper_dg_new( + grid, pbasis, up->coll_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu + ); + + up->diff_tm = 0.0; + up->drag_tm = 0.0; - up->diff_tm = 0.0; up->drag_tm = 0.0; - return up; } -void -gkyl_dg_updater_fpo_vlasov_advance(struct gkyl_dg_updater_collisions *fpo, - const struct gkyl_range *update_rng, - const struct gkyl_array *h, const struct gkyl_array *g, - const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_fpo_vlasov_advance( + struct gkyl_dg_updater_collisions *fpo, const struct gkyl_range *update_rng, + const struct gkyl_array *h, const struct gkyl_array *g, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { // Set arrays needed - gkyl_fpo_vlasov_drag_set_auxfields(fpo->coll_drag, - (struct gkyl_dg_fpo_vlasov_drag_auxfields) { .h = h }); - gkyl_fpo_vlasov_diff_set_auxfields(fpo->coll_diff, - (struct gkyl_dg_fpo_vlasov_diff_auxfields) { .g = g }); + gkyl_fpo_vlasov_drag_set_auxfields( + fpo->coll_drag, (struct gkyl_dg_fpo_vlasov_drag_auxfields){.h = h} + ); + gkyl_fpo_vlasov_diff_set_auxfields( + fpo->coll_diff, (struct gkyl_dg_fpo_vlasov_diff_auxfields){.g = g} + ); struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(fpo->drag, update_rng, fIn, cflrate, rhs); fpo->drag_tm += gkyl_time_diff_now_sec(wst); - // Fokker-Planck diffusion requires generalized hyper dg operator due to + // Fokker-Planck diffusion requires generalized hyper dg operator due to // off diagonal terms in diffusion tensor and mixed partial derivatives wst = gkyl_wall_clock(); gkyl_hyper_dg_gen_stencil_advance(fpo->diff, update_rng, fIn, cflrate, rhs); @@ -67,14 +77,10 @@ gkyl_dg_updater_fpo_vlasov_advance(struct gkyl_dg_updater_collisions *fpo, struct gkyl_dg_updater_fpo_vlasov_tm gkyl_dg_updater_fpo_vlasov_get_tm(const struct gkyl_dg_updater_collisions *coll) { - return (struct gkyl_dg_updater_fpo_vlasov_tm) { - .diff_tm = coll->diff_tm, - .drag_tm = coll->drag_tm - }; + return (struct gkyl_dg_updater_fpo_vlasov_tm){.diff_tm = coll->diff_tm, .drag_tm = coll->drag_tm}; } -void -gkyl_dg_updater_fpo_vlasov_release(struct gkyl_dg_updater_collisions* coll) +void gkyl_dg_updater_fpo_vlasov_release(struct gkyl_dg_updater_collisions *coll) { gkyl_dg_eqn_release(coll->coll_diff); gkyl_dg_eqn_release(coll->coll_drag); @@ -85,24 +91,26 @@ gkyl_dg_updater_fpo_vlasov_release(struct gkyl_dg_updater_collisions* coll) #ifdef GKYL_HAVE_CUDA -void -gkyl_dg_updater_fpo_vlasov_advance_cu(struct gkyl_dg_updater_collisions *fpo, - const struct gkyl_range *update_rng, - const struct gkyl_array *h, const struct gkyl_array *g, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT cflrate, - struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_fpo_vlasov_advance_cu( + struct gkyl_dg_updater_collisions *fpo, const struct gkyl_range *update_rng, + const struct gkyl_array *h, const struct gkyl_array *g, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { // Set arrays needed - gkyl_fpo_vlasov_drag_set_auxfields(fpo->coll_drag, - (struct gkyl_dg_fpo_vlasov_drag_auxfields) { .h = h }); - gkyl_fpo_vlasov_diff_set_auxfields(fpo->coll_diff, - (struct gkyl_dg_fpo_vlasov_diff_auxfields) { .g = g }); + gkyl_fpo_vlasov_drag_set_auxfields( + fpo->coll_drag, (struct gkyl_dg_fpo_vlasov_drag_auxfields){.h = h} + ); + gkyl_fpo_vlasov_diff_set_auxfields( + fpo->coll_diff, (struct gkyl_dg_fpo_vlasov_diff_auxfields){.g = g} + ); struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(fpo->drag, update_rng, fIn, cflrate, rhs); fpo->drag_tm += gkyl_time_diff_now_sec(wst); - // Fokker-Planck diffusion requires generalized hyper dg operator due to + // Fokker-Planck diffusion requires generalized hyper dg operator due to // off diagonal terms in diffusion tensor and mixed partial derivatives wst = gkyl_wall_clock(); //gkyl_hyper_dg_gen_stencil_advance_cu(fpo->diff, update_rng, fIn, cflrate, rhs); @@ -113,11 +121,11 @@ gkyl_dg_updater_fpo_vlasov_advance_cu(struct gkyl_dg_updater_collisions *fpo, #ifndef GKYL_HAVE_CUDA -void -gkyl_dg_updater_fpo_vlasov_advance_cu(struct gkyl_dg_updater_collisions *fpo, - const struct gkyl_range *update_rng, - const struct gkyl_array *h, const struct gkyl_array *g, - const struct gkyl_array *fIn, struct gkyl_array *cflrate, struct gkyl_array *rhs) +void gkyl_dg_updater_fpo_vlasov_advance_cu( + struct gkyl_dg_updater_collisions *fpo, const struct gkyl_range *update_rng, + const struct gkyl_array *h, const struct gkyl_array *g, const struct gkyl_array *fIn, + struct gkyl_array *cflrate, struct gkyl_array *rhs +) { assert(false); } diff --git a/vlasov/zero/dg_updater_lbo_vlasov.c b/vlasov/zero/dg_updater_lbo_vlasov.c index d2fb2be81d..38646ddfa4 100644 --- a/vlasov/zero/dg_updater_lbo_vlasov.c +++ b/vlasov/zero/dg_updater_lbo_vlasov.c @@ -9,45 +9,54 @@ #include #include -struct gkyl_dg_updater_collisions* -gkyl_dg_updater_lbo_vlasov_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *conf_range, - struct gkyl_dg_lbo_vlasov_drag_auxfields *drag_inp, struct gkyl_dg_lbo_vlasov_diff_auxfields *diff_inp, - bool use_gpu) +struct gkyl_dg_updater_collisions *gkyl_dg_updater_lbo_vlasov_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, + struct gkyl_dg_lbo_vlasov_drag_auxfields *drag_inp, + struct gkyl_dg_lbo_vlasov_diff_auxfields *diff_inp, bool use_gpu +) { struct gkyl_dg_updater_collisions *up = gkyl_malloc(sizeof(gkyl_dg_updater_collisions)); up->use_gpu = use_gpu; - up->coll_drag = gkyl_dg_lbo_vlasov_drag_new(conf_basis, phase_basis, conf_range, phase_grid, use_gpu); + up->coll_drag = + gkyl_dg_lbo_vlasov_drag_new(conf_basis, phase_basis, conf_range, phase_grid, use_gpu); gkyl_lbo_vlasov_drag_set_auxfields(up->coll_drag, *drag_inp); - up->coll_diff = gkyl_dg_lbo_vlasov_diff_new(conf_basis, phase_basis, conf_range, phase_grid, use_gpu); + up->coll_diff = + gkyl_dg_lbo_vlasov_diff_new(conf_basis, phase_basis, conf_range, phase_grid, use_gpu); gkyl_lbo_vlasov_diff_set_auxfields(up->coll_diff, *diff_inp); int cdim = conf_basis->ndim, pdim = phase_basis->ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int num_up_dirs = vdim; - int up_dirs[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim - vdim; + } - int zero_flux_flags[2*GKYL_MAX_DIM] = { 0 }; - for (int d=cdim; ddrag = gkyl_hyper_dg_new(phase_grid, phase_basis, up->coll_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu); - up->diff = gkyl_hyper_dg_new(phase_grid, phase_basis, up->coll_diff, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu); + up->drag = gkyl_hyper_dg_new( + phase_grid, phase_basis, up->coll_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu + ); + up->diff = gkyl_hyper_dg_new( + phase_grid, phase_basis, up->coll_diff, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu + ); - up->diff_tm = 0.0; + up->diff_tm = 0.0; up->drag_tm = 0.0; - + return up; } -void -gkyl_dg_updater_lbo_vlasov_advance(struct gkyl_dg_updater_collisions *lbo, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_lbo_vlasov_advance( + struct gkyl_dg_updater_collisions *lbo, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(lbo->drag, update_rng, fIn, cflrate, rhs); @@ -61,14 +70,10 @@ gkyl_dg_updater_lbo_vlasov_advance(struct gkyl_dg_updater_collisions *lbo, struct gkyl_dg_updater_lbo_vlasov_tm gkyl_dg_updater_lbo_vlasov_get_tm(const gkyl_dg_updater_collisions *coll) { - return (struct gkyl_dg_updater_lbo_vlasov_tm) { - .diff_tm = coll->diff_tm, - .drag_tm = coll->drag_tm - }; + return (struct gkyl_dg_updater_lbo_vlasov_tm){.diff_tm = coll->diff_tm, .drag_tm = coll->drag_tm}; } -void -gkyl_dg_updater_lbo_vlasov_release(gkyl_dg_updater_collisions* coll) +void gkyl_dg_updater_lbo_vlasov_release(gkyl_dg_updater_collisions *coll) { gkyl_dg_eqn_release(coll->coll_drag); gkyl_dg_eqn_release(coll->coll_diff); diff --git a/vlasov/zero/dg_updater_moment.c b/vlasov/zero/dg_updater_moment.c index 88bd606e74..304fa0dd87 100644 --- a/vlasov/zero/dg_updater_moment.c +++ b/vlasov/zero/dg_updater_moment.c @@ -13,90 +13,87 @@ #include #include -struct gkyl_mom_type* -gkyl_dg_updater_moment_acquire_type(const gkyl_dg_updater_moment* moment) +struct gkyl_mom_type *gkyl_dg_updater_moment_acquire_type(const gkyl_dg_updater_moment *moment) { return gkyl_mom_type_acquire(moment->type); } -int -gkyl_dg_updater_moment_num_mom(const gkyl_dg_updater_moment* moment) +int gkyl_dg_updater_moment_num_mom(const gkyl_dg_updater_moment *moment) { return gkyl_mom_type_num_mom(moment->type); } -struct gkyl_dg_updater_moment* -gkyl_dg_updater_moment_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, - const struct gkyl_range *phase_range, - enum gkyl_model_id model_id, void *aux_inp, - enum gkyl_distribution_moments mom_type, bool is_integrated, bool use_gpu) +struct gkyl_dg_updater_moment *gkyl_dg_updater_moment_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_range, + const struct gkyl_range *vel_range, const struct gkyl_range *phase_range, + enum gkyl_model_id model_id, void *aux_inp, enum gkyl_distribution_moments mom_type, + bool is_integrated, bool use_gpu +) { gkyl_dg_updater_moment *up = gkyl_malloc(sizeof(gkyl_dg_updater_moment)); up->model_id = model_id; up->use_gpu = use_gpu; if (up->model_id == GKYL_MODEL_SR) { - if (is_integrated) - up->type = gkyl_int_mom_vlasov_sr_new(cbasis, pbasis, conf_range, vel_range, mom_type, use_gpu); - else + if (is_integrated) { + up->type = + gkyl_int_mom_vlasov_sr_new(cbasis, pbasis, conf_range, vel_range, mom_type, use_gpu); + } else { up->type = gkyl_mom_vlasov_sr_new(cbasis, pbasis, conf_range, vel_range, mom_type, use_gpu); + } struct gkyl_mom_vlasov_sr_auxfields *sr_inp = aux_inp; gkyl_mom_vlasov_sr_set_auxfields(up->type, *sr_inp); - } - else if ((up->model_id == GKYL_MODEL_CANONICAL_PB || up->model_id == GKYL_MODEL_CANONICAL_PB_GR) - && (mom_type == GKYL_F_MOMENT_M1_FROM_H || mom_type == GKYL_F_MOMENT_ENERGY - || (is_integrated && mom_type == GKYL_F_MOMENT_M0M1M2))) { - if (is_integrated) + } else if ((up->model_id == GKYL_MODEL_CANONICAL_PB || up->model_id == GKYL_MODEL_CANONICAL_PB_GR + ) && + (mom_type == GKYL_F_MOMENT_M1_FROM_H || mom_type == GKYL_F_MOMENT_ENERGY || + (is_integrated && mom_type == GKYL_F_MOMENT_M0M1M2))) { + if (is_integrated) { up->type = gkyl_int_mom_canonical_pb_new(cbasis, pbasis, phase_range, mom_type, use_gpu); - else + } else { up->type = gkyl_mom_canonical_pb_new(cbasis, pbasis, phase_range, mom_type, use_gpu); - + } + struct gkyl_mom_canonical_pb_auxfields *can_pb_inp = aux_inp; gkyl_mom_canonical_pb_set_auxfields(up->type, *can_pb_inp); - } - else { - if (is_integrated) + } else { + if (is_integrated) { up->type = gkyl_int_mom_vlasov_new(cbasis, pbasis, mom_type, use_gpu); - else + } else { up->type = gkyl_mom_vlasov_new(cbasis, pbasis, mom_type, use_gpu); + } } up->up_moment = gkyl_mom_calc_new(grid, up->type, use_gpu); up->moment_tm = 0.0; - + return up; } -void -gkyl_dg_updater_moment_advance(struct gkyl_dg_updater_moment *moment, - const struct gkyl_range *update_phase_rng, const struct gkyl_range *update_conf_rng, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT mout) -{ +void gkyl_dg_updater_moment_advance( + struct gkyl_dg_updater_moment *moment, const struct gkyl_range *update_phase_rng, + const struct gkyl_range *update_conf_rng, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT mout +) +{ struct timespec wst = gkyl_wall_clock(); if (moment->use_gpu) { gkyl_mom_calc_advance_cu(moment->up_moment, update_phase_rng, update_conf_rng, fIn, mout); - } - else { + } else { gkyl_mom_calc_advance(moment->up_moment, update_phase_rng, update_conf_rng, fIn, mout); } moment->moment_tm += gkyl_time_diff_now_sec(wst); } -struct gkyl_dg_updater_moment_tm -gkyl_dg_updater_moment_get_tm(const gkyl_dg_updater_moment *moment) +struct gkyl_dg_updater_moment_tm gkyl_dg_updater_moment_get_tm(const gkyl_dg_updater_moment *moment) { - return (struct gkyl_dg_updater_moment_tm) { - .moment_tm = moment->moment_tm, - }; + return (struct gkyl_dg_updater_moment_tm){.moment_tm = moment->moment_tm}; } -void -gkyl_dg_updater_moment_release(gkyl_dg_updater_moment* moment) +void gkyl_dg_updater_moment_release(gkyl_dg_updater_moment *moment) { gkyl_mom_type_release(moment->type); gkyl_mom_calc_release(moment->up_moment); diff --git a/vlasov/zero/dg_updater_rad_vlasov.c b/vlasov/zero/dg_updater_rad_vlasov.c index cb45d4bb99..d6f2e57057 100644 --- a/vlasov/zero/dg_updater_rad_vlasov.c +++ b/vlasov/zero/dg_updater_rad_vlasov.c @@ -9,40 +9,46 @@ #include #include -struct gkyl_dg_updater_rad_vlasov* -gkyl_dg_updater_rad_vlasov_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *conf_range, struct gkyl_dg_lbo_vlasov_drag_auxfields *drag_inp, - bool use_gpu) +struct gkyl_dg_updater_rad_vlasov *gkyl_dg_updater_rad_vlasov_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, + struct gkyl_dg_lbo_vlasov_drag_auxfields *drag_inp, bool use_gpu +) { struct gkyl_dg_updater_rad_vlasov *up = gkyl_malloc(sizeof(*up)); up->use_gpu = use_gpu; - up->rad_drag = gkyl_dg_lbo_vlasov_drag_new(conf_basis, phase_basis, conf_range, phase_grid, use_gpu); + up->rad_drag = + gkyl_dg_lbo_vlasov_drag_new(conf_basis, phase_basis, conf_range, phase_grid, use_gpu); gkyl_lbo_vlasov_drag_set_auxfields(up->rad_drag, *drag_inp); int cdim = conf_basis->ndim, pdim = phase_basis->ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int num_up_dirs = vdim; - int up_dirs[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim - vdim; + } - int zero_flux_flags[GKYL_MAX_DIM] = { 0 }; - for (int d=cdim; ddrag = gkyl_hyper_dg_new(phase_grid, phase_basis, up->rad_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu); + up->drag = gkyl_hyper_dg_new( + phase_grid, phase_basis, up->rad_drag, num_up_dirs, up_dirs, zero_flux_flags, 1, use_gpu + ); + + up->drag_tm = 0.0; - up->drag_tm = 0.0; - return up; } -void -gkyl_dg_updater_rad_vlasov_advance(struct gkyl_dg_updater_rad_vlasov *rad, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_rad_vlasov_advance( + struct gkyl_dg_updater_rad_vlasov *rad, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(rad->drag, update_rng, fIn, cflrate, rhs); @@ -52,13 +58,10 @@ gkyl_dg_updater_rad_vlasov_advance(struct gkyl_dg_updater_rad_vlasov *rad, struct gkyl_dg_updater_rad_vlasov_tm gkyl_dg_updater_rad_vlasov_get_tm(const gkyl_dg_updater_rad_vlasov *rad) { - return (struct gkyl_dg_updater_rad_vlasov_tm) { - .drag_tm = rad->drag_tm - }; + return (struct gkyl_dg_updater_rad_vlasov_tm){.drag_tm = rad->drag_tm}; } -void -gkyl_dg_updater_rad_vlasov_release(gkyl_dg_updater_rad_vlasov *rad) +void gkyl_dg_updater_rad_vlasov_release(gkyl_dg_updater_rad_vlasov *rad) { gkyl_dg_eqn_release(rad->rad_drag); gkyl_hyper_dg_release(rad->drag); diff --git a/vlasov/zero/dg_updater_vlasov.c b/vlasov/zero/dg_updater_vlasov.c index 4c81c859d9..5bb8f30792 100644 --- a/vlasov/zero/dg_updater_vlasov.c +++ b/vlasov/zero/dg_updater_vlasov.c @@ -12,83 +12,86 @@ #include #include -struct gkyl_dg_eqn* -gkyl_dg_updater_vlasov_acquire_eqn(const gkyl_dg_updater_vlasov* vlasov) +struct gkyl_dg_eqn *gkyl_dg_updater_vlasov_acquire_eqn(const gkyl_dg_updater_vlasov *vlasov) { return gkyl_dg_eqn_acquire(vlasov->eqn_vlasov); } -struct gkyl_dg_updater_vlasov_tm -gkyl_dg_updater_vlasov_get_tm(const gkyl_dg_updater_vlasov *vlasov) +struct gkyl_dg_updater_vlasov_tm gkyl_dg_updater_vlasov_get_tm(const gkyl_dg_updater_vlasov *vlasov) { - return (struct gkyl_dg_updater_vlasov_tm) { - .vlasov_tm = vlasov->vlasov_tm, - }; + return (struct gkyl_dg_updater_vlasov_tm){.vlasov_tm = vlasov->vlasov_tm}; } -gkyl_dg_updater_vlasov* -gkyl_dg_updater_vlasov_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, const struct gkyl_range *phase_range, - const bool *is_zero_flux_bc, enum gkyl_model_id model_id, enum gkyl_field_id field_id, void *aux_inp, bool use_gpu) +gkyl_dg_updater_vlasov *gkyl_dg_updater_vlasov_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_range, + const struct gkyl_range *vel_range, const struct gkyl_range *phase_range, + const bool *is_zero_flux_bc, enum gkyl_model_id model_id, enum gkyl_field_id field_id, + void *aux_inp, bool use_gpu +) { gkyl_dg_updater_vlasov *up = gkyl_malloc(sizeof(gkyl_dg_updater_vlasov)); up->model_id = model_id; up->field_id = field_id; up->use_gpu = use_gpu; if (up->model_id == GKYL_MODEL_SR) { - up->eqn_vlasov = gkyl_dg_vlasov_sr_new(cbasis, pbasis, conf_range, vel_range, up->field_id, up->use_gpu); + up->eqn_vlasov = + gkyl_dg_vlasov_sr_new(cbasis, pbasis, conf_range, vel_range, up->field_id, up->use_gpu); struct gkyl_dg_vlasov_sr_auxfields *sr_inp = aux_inp; gkyl_vlasov_sr_set_auxfields(up->eqn_vlasov, *sr_inp); - } - else if (up->model_id == GKYL_MODEL_CANONICAL_PB || up->model_id == GKYL_MODEL_CANONICAL_PB_GR) { + } else if (up->model_id == GKYL_MODEL_CANONICAL_PB || + up->model_id == GKYL_MODEL_CANONICAL_PB_GR) { up->eqn_vlasov = gkyl_dg_canonical_pb_new(cbasis, pbasis, phase_range, up->use_gpu); struct gkyl_dg_canonical_pb_auxfields *canonical_pb_inp = aux_inp; - gkyl_canonical_pb_set_auxfields(up->eqn_vlasov, *canonical_pb_inp); - } - else { - up->eqn_vlasov = gkyl_dg_vlasov_new(cbasis, pbasis, conf_range, phase_range, up->model_id, up->field_id, up->use_gpu); + gkyl_canonical_pb_set_auxfields(up->eqn_vlasov, *canonical_pb_inp); + } else { + up->eqn_vlasov = gkyl_dg_vlasov_new( + cbasis, pbasis, conf_range, phase_range, up->model_id, up->field_id, up->use_gpu + ); struct gkyl_dg_vlasov_auxfields *vlasov_inp = aux_inp; - gkyl_vlasov_set_auxfields(up->eqn_vlasov, *vlasov_inp); + gkyl_vlasov_set_auxfields(up->eqn_vlasov, *vlasov_inp); } int cdim = cbasis->ndim, pdim = pbasis->ndim; - int vdim = pdim-cdim; - int up_dirs[GKYL_MAX_DIM], zero_flux_flags[2*GKYL_MAX_DIM]; - for (int d=0; dmodel_id == GKYL_MODEL_CANONICAL_PB || up->model_id == GKYL_MODEL_CANONICAL_PB_GR) { - for (int d=cdim; dmodel_id == GKYL_MODEL_CANONICAL_PB || + up->model_id == GKYL_MODEL_CANONICAL_PB_GR) { + for (int d = cdim; d < pdim; ++d) { up_dirs[d] = d; - zero_flux_flags[d] = zero_flux_flags[d+pdim] = 1; // zero-flux BCs in vel-space + zero_flux_flags[d] = zero_flux_flags[d + pdim] = 1; // zero-flux BCs in vel-space } num_up_dirs = pdim; } - up->hdg_vlasov = gkyl_hyper_dg_new(grid, pbasis, up->eqn_vlasov, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu); + up->hdg_vlasov = gkyl_hyper_dg_new( + grid, pbasis, up->eqn_vlasov, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu + ); up->vlasov_tm = 0.0; - + return up; } -void -gkyl_dg_updater_vlasov_advance(gkyl_dg_updater_vlasov *vlasov, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_vlasov_advance( + gkyl_dg_updater_vlasov *vlasov, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(vlasov->hdg_vlasov, update_rng, fIn, cflrate, rhs); vlasov->vlasov_tm += gkyl_time_diff_now_sec(wst); } -void -gkyl_dg_updater_vlasov_release(gkyl_dg_updater_vlasov* vlasov) +void gkyl_dg_updater_vlasov_release(gkyl_dg_updater_vlasov *vlasov) { gkyl_dg_eqn_release(vlasov->eqn_vlasov); gkyl_hyper_dg_release(vlasov->hdg_vlasov); diff --git a/vlasov/zero/dg_updater_vlasov_poisson.c b/vlasov/zero/dg_updater_vlasov_poisson.c index 8ea66c6b19..2216bf84f6 100644 --- a/vlasov/zero/dg_updater_vlasov_poisson.c +++ b/vlasov/zero/dg_updater_vlasov_poisson.c @@ -10,8 +10,7 @@ #include #include -struct gkyl_dg_eqn* -gkyl_dg_updater_vlasov_poisson_acquire_eqn(const gkyl_dg_updater_vlasov* vlasov) +struct gkyl_dg_eqn *gkyl_dg_updater_vlasov_poisson_acquire_eqn(const gkyl_dg_updater_vlasov *vlasov) { return gkyl_dg_eqn_acquire(vlasov->eqn_vlasov); } @@ -19,60 +18,66 @@ gkyl_dg_updater_vlasov_poisson_acquire_eqn(const gkyl_dg_updater_vlasov* vlasov) struct gkyl_dg_updater_vlasov_tm gkyl_dg_updater_vlasov_poisson_get_tm(const gkyl_dg_updater_vlasov *vlasov) { - return (struct gkyl_dg_updater_vlasov_tm) { - .vlasov_tm = vlasov->vlasov_tm, - }; + return (struct gkyl_dg_updater_vlasov_tm){.vlasov_tm = vlasov->vlasov_tm}; } -gkyl_dg_updater_vlasov* -gkyl_dg_updater_vlasov_poisson_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, const struct gkyl_range *phase_range, - const bool *is_zero_flux_bc, enum gkyl_model_id model_id, enum gkyl_field_id field_id, void *aux_inp, bool use_gpu) +gkyl_dg_updater_vlasov *gkyl_dg_updater_vlasov_poisson_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_range, + const struct gkyl_range *vel_range, const struct gkyl_range *phase_range, + const bool *is_zero_flux_bc, enum gkyl_model_id model_id, enum gkyl_field_id field_id, + void *aux_inp, bool use_gpu +) { gkyl_dg_updater_vlasov *up = gkyl_malloc(sizeof(*up)); up->use_gpu = use_gpu; - up->eqn_vlasov = gkyl_dg_vlasov_poisson_new(cbasis, pbasis, conf_range, phase_range, model_id, field_id, up->use_gpu); + up->eqn_vlasov = gkyl_dg_vlasov_poisson_new( + cbasis, pbasis, conf_range, phase_range, model_id, field_id, up->use_gpu + ); struct gkyl_dg_vlasov_poisson_auxfields *vlasov_inp = aux_inp; - gkyl_vlasov_poisson_set_auxfields(up->eqn_vlasov, *vlasov_inp); + gkyl_vlasov_poisson_set_auxfields(up->eqn_vlasov, *vlasov_inp); int cdim = cbasis->ndim, pdim = pbasis->ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int up_dirs[GKYL_MAX_DIM] = {0}; int num_up_dirs = pdim; - for (int d=0; dhdg_vlasov = gkyl_hyper_dg_new(grid, pbasis, up->eqn_vlasov, - num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu); + up->hdg_vlasov = gkyl_hyper_dg_new( + grid, pbasis, up->eqn_vlasov, num_up_dirs, up_dirs, zero_flux_flags, 1, up->use_gpu + ); up->vlasov_tm = 0.0; - + return up; } -void -gkyl_dg_updater_vlasov_poisson_advance(gkyl_dg_updater_vlasov *vlasov, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_dg_updater_vlasov_poisson_advance( + gkyl_dg_updater_vlasov *vlasov, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { struct timespec wst = gkyl_wall_clock(); gkyl_hyper_dg_advance(vlasov->hdg_vlasov, update_rng, fIn, cflrate, rhs); vlasov->vlasov_tm += gkyl_time_diff_now_sec(wst); } -void -gkyl_dg_updater_vlasov_poisson_release(gkyl_dg_updater_vlasov* vlasov) +void gkyl_dg_updater_vlasov_poisson_release(gkyl_dg_updater_vlasov *vlasov) { gkyl_dg_eqn_release(vlasov->eqn_vlasov); gkyl_hyper_dg_release(vlasov->hdg_vlasov); diff --git a/vlasov/zero/dg_vlasov.c b/vlasov/zero/dg_vlasov.c index e4cfccb870..eeed7c1fcc 100644 --- a/vlasov/zero/dg_vlasov.c +++ b/vlasov/zero/dg_vlasov.c @@ -9,23 +9,21 @@ #include #include -void -gkyl_vlasov_free(const struct gkyl_ref_count *ref) +void gkyl_vlasov_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); - + if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object struct dg_vlasov *vlasov = container_of(base->on_dev, struct dg_vlasov, eqn); gkyl_cu_free(vlasov); } - + struct dg_vlasov *vlasov = container_of(base, struct dg_vlasov, eqn); gkyl_free(vlasov); } -void -gkyl_vlasov_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_auxfields auxin) +void gkyl_vlasov_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_auxfields auxin) { #ifdef GKYL_HAVE_CUDA if (gkyl_dg_eqn_is_cu_dev(eqn)) { @@ -35,27 +33,27 @@ gkyl_vlasov_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_a #endif struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); - vlasov->auxfields.field = auxin.field; - vlasov->auxfields.cot_vec = auxin.cot_vec; + vlasov->auxfields.field = auxin.field; + vlasov->auxfields.cot_vec = auxin.cot_vec; vlasov->auxfields.alpha_surf = auxin.alpha_surf; vlasov->auxfields.sgn_alpha_surf = auxin.sgn_alpha_surf; vlasov->auxfields.const_sgn_alpha = auxin.const_sgn_alpha; } -struct gkyl_dg_eqn* -gkyl_dg_vlasov_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* phase_range, - enum gkyl_model_id model_id, enum gkyl_field_id field_id, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_vlasov_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, + enum gkyl_model_id model_id, enum gkyl_field_id field_id, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_vlasov_cu_dev_new(cbasis, pbasis, conf_range, phase_range, model_id, field_id); - } + } #endif struct dg_vlasov *vlasov = gkyl_malloc(sizeof(struct dg_vlasov)); - - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; vlasov->cdim = cdim; @@ -69,106 +67,115 @@ gkyl_dg_vlasov_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pba const gkyl_dg_vlasov_stream_vol_kern_list *stream_vol_kernels; const gkyl_dg_vlasov_vol_kern_list *vol_kernels; - const gkyl_dg_vlasov_stream_surf_kern_list *stream_surf_x_kernels, - *stream_surf_y_kernels, + const gkyl_dg_vlasov_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, *stream_surf_z_kernels; - const gkyl_dg_vlasov_accel_surf_kern_list *accel_surf_vx_kernels, - *accel_surf_vy_kernels, + const gkyl_dg_vlasov_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, *accel_surf_vz_kernels; - const gkyl_dg_vlasov_stream_boundary_surf_kern_list *stream_boundary_surf_x_kernels, - *stream_boundary_surf_y_kernels, - *stream_boundary_surf_z_kernels; + const gkyl_dg_vlasov_stream_boundary_surf_kern_list *stream_boundary_surf_x_kernels, + *stream_boundary_surf_y_kernels, *stream_boundary_surf_z_kernels; + + const gkyl_dg_vlasov_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, + *accel_boundary_surf_vy_kernels, *accel_boundary_surf_vz_kernels; - const gkyl_dg_vlasov_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, - *accel_boundary_surf_vy_kernels, - *accel_boundary_surf_vz_kernels; - switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - stream_vol_kernels = ser_stream_vol_kernels; - vol_kernels = ser_vol_kernels; - - stream_surf_x_kernels = ser_stream_surf_x_kernels; - stream_surf_y_kernels = ser_stream_surf_y_kernels; - stream_surf_z_kernels = ser_stream_surf_z_kernels; - - accel_surf_vx_kernels = ser_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_accel_surf_vz_kernels; - - stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; - - accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - stream_vol_kernels = tensor_stream_vol_kernels; - vol_kernels = tensor_vol_kernels; - - stream_surf_x_kernels = tensor_stream_surf_x_kernels; - stream_surf_y_kernels = tensor_stream_surf_y_kernels; - stream_surf_z_kernels = tensor_stream_surf_z_kernels; - - accel_surf_vx_kernels = tensor_accel_surf_vx_kernels; - accel_surf_vy_kernels = tensor_accel_surf_vy_kernels; - accel_surf_vz_kernels = tensor_accel_surf_vz_kernels; - - stream_boundary_surf_x_kernels = tensor_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = tensor_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = tensor_stream_boundary_surf_z_kernels; - - accel_boundary_surf_vx_kernels = tensor_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = tensor_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = tensor_accel_boundary_surf_vz_kernels; - - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + stream_vol_kernels = ser_stream_vol_kernels; + vol_kernels = ser_vol_kernels; + + stream_surf_x_kernels = ser_stream_surf_x_kernels; + stream_surf_y_kernels = ser_stream_surf_y_kernels; + stream_surf_z_kernels = ser_stream_surf_z_kernels; + + accel_surf_vx_kernels = ser_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_accel_surf_vz_kernels; + + stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; + + accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + stream_vol_kernels = tensor_stream_vol_kernels; + vol_kernels = tensor_vol_kernels; + + stream_surf_x_kernels = tensor_stream_surf_x_kernels; + stream_surf_y_kernels = tensor_stream_surf_y_kernels; + stream_surf_z_kernels = tensor_stream_surf_z_kernels; + + accel_surf_vx_kernels = tensor_accel_surf_vx_kernels; + accel_surf_vy_kernels = tensor_accel_surf_vy_kernels; + accel_surf_vz_kernels = tensor_accel_surf_vz_kernels; + + stream_boundary_surf_x_kernels = tensor_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = tensor_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = tensor_stream_boundary_surf_z_kernels; + + accel_boundary_surf_vx_kernels = tensor_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = tensor_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = tensor_accel_boundary_surf_vz_kernels; + + break; + + default: + assert(false); + break; } if (field_id == GKYL_FIELD_NULL) { - vlasov->eqn.vol_term = CK(stream_vol_kernels,cdim,vdim,poly_order); - } - else { - vlasov->eqn.vol_term = CK(vol_kernels,cdim,vdim,poly_order); - vlasov->accel_surf[0] = CK(accel_surf_vx_kernels,cdim,vdim,poly_order); - if (vdim>1) - vlasov->accel_surf[1] = CK(accel_surf_vy_kernels,cdim,vdim,poly_order); - if (vdim>2) - vlasov->accel_surf[2] = CK(accel_surf_vz_kernels,cdim,vdim,poly_order); - - vlasov->accel_boundary_surf[0] = CK(accel_boundary_surf_vx_kernels,cdim,vdim,poly_order); - if (vdim>1) - vlasov->accel_boundary_surf[1] = CK(accel_boundary_surf_vy_kernels,cdim,vdim,poly_order); - if (vdim>2) - vlasov->accel_boundary_surf[2] = CK(accel_boundary_surf_vz_kernels,cdim,vdim,poly_order); + vlasov->eqn.vol_term = CK(stream_vol_kernels, cdim, vdim, poly_order); + } else { + vlasov->eqn.vol_term = CK(vol_kernels, cdim, vdim, poly_order); + vlasov->accel_surf[0] = CK(accel_surf_vx_kernels, cdim, vdim, poly_order); + if (vdim > 1) { + vlasov->accel_surf[1] = CK(accel_surf_vy_kernels, cdim, vdim, poly_order); + } + if (vdim > 2) { + vlasov->accel_surf[2] = CK(accel_surf_vz_kernels, cdim, vdim, poly_order); + } + + vlasov->accel_boundary_surf[0] = CK(accel_boundary_surf_vx_kernels, cdim, vdim, poly_order); + if (vdim > 1) { + vlasov->accel_boundary_surf[1] = CK(accel_boundary_surf_vy_kernels, cdim, vdim, poly_order); + } + if (vdim > 2) { + vlasov->accel_boundary_surf[2] = CK(accel_boundary_surf_vz_kernels, cdim, vdim, poly_order); + } } // Streaming kernels are the same for each field_id - vlasov->stream_surf[0] = CK(stream_surf_x_kernels,cdim,vdim,poly_order); - if (cdim>1) - vlasov->stream_surf[1] = CK(stream_surf_y_kernels,cdim,vdim,poly_order); - if (cdim>2) - vlasov->stream_surf[2] = CK(stream_surf_z_kernels,cdim,vdim,poly_order); - - vlasov->stream_boundary_surf[0] = CK(stream_boundary_surf_x_kernels,cdim,vdim,poly_order); - if (cdim>1) - vlasov->stream_boundary_surf[1] = CK(stream_boundary_surf_y_kernels,cdim,vdim,poly_order); - if (cdim>2) - vlasov->stream_boundary_surf[2] = CK(stream_boundary_surf_z_kernels,cdim,vdim,poly_order); + vlasov->stream_surf[0] = CK(stream_surf_x_kernels, cdim, vdim, poly_order); + if (cdim > 1) { + vlasov->stream_surf[1] = CK(stream_surf_y_kernels, cdim, vdim, poly_order); + } + if (cdim > 2) { + vlasov->stream_surf[2] = CK(stream_surf_z_kernels, cdim, vdim, poly_order); + } + + vlasov->stream_boundary_surf[0] = CK(stream_boundary_surf_x_kernels, cdim, vdim, poly_order); + if (cdim > 1) { + vlasov->stream_boundary_surf[1] = CK(stream_boundary_surf_y_kernels, cdim, vdim, poly_order); + } + if (cdim > 2) { + vlasov->stream_boundary_surf[2] = CK(stream_boundary_surf_z_kernels, cdim, vdim, poly_order); + } // ensure non-NULL pointers - for (int i=0; istream_surf[i]); + for (int i = 0; i < cdim; ++i) { + assert(vlasov->stream_surf[i]); + } if (field_id != GKYL_FIELD_NULL) { - for (int i=0; iaccel_surf[i]); - for (int i=0; iaccel_boundary_surf[i]); + for (int i = 0; i < vdim; ++i) { + assert(vlasov->accel_surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(vlasov->accel_boundary_surf[i]); + } } vlasov->auxfields.field = 0; @@ -178,22 +185,23 @@ gkyl_dg_vlasov_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pba vlasov->auxfields.const_sgn_alpha = 0; vlasov->conf_range = *conf_range; vlasov->phase_range = *phase_range; - + vlasov->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(vlasov->eqn.flags); vlasov->eqn.ref_count = gkyl_ref_count_init(gkyl_vlasov_free); vlasov->eqn.on_dev = &vlasov->eqn; // CPU eqn obj points to itself - + return &vlasov->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* phase_range, - enum gkyl_model_id model_id, enum gkyl_field_id field_id) +struct gkyl_dg_eqn *gkyl_dg_vlasov_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, + enum gkyl_model_id model_id, enum gkyl_field_id field_id +) { assert(false); return 0; diff --git a/vlasov/zero/dg_vlasov_cu.cu b/vlasov/zero/dg_vlasov_cu.cu index e68e50d527..e603693197 100644 --- a/vlasov/zero/dg_vlasov_cu.cu +++ b/vlasov/zero/dg_vlasov_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include } @@ -12,37 +12,39 @@ extern "C" { // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_vlasov_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array *field, const struct gkyl_array *cot_vec, - const struct gkyl_array *alpha_surf, const struct gkyl_array *sgn_alpha_surf, const struct gkyl_array *const_sgn_alpha) +__global__ static void gkyl_vlasov_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *field, const struct gkyl_array *cot_vec, + const struct gkyl_array *alpha_surf, const struct gkyl_array *sgn_alpha_surf, + const struct gkyl_array *const_sgn_alpha +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); - vlasov->auxfields.field = field; - vlasov->auxfields.cot_vec = cot_vec; + vlasov->auxfields.field = field; + vlasov->auxfields.cot_vec = cot_vec; vlasov->auxfields.alpha_surf = alpha_surf; vlasov->auxfields.sgn_alpha_surf = sgn_alpha_surf; vlasov->auxfields.const_sgn_alpha = const_sgn_alpha; } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_vlasov_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_auxfields auxin) +void gkyl_vlasov_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_auxfields auxin +) { - gkyl_vlasov_set_auxfields_cu_kernel<<<1,1>>>(eqn, - auxin.field ? auxin.field->on_dev : 0, - auxin.cot_vec ? auxin.cot_vec->on_dev : 0, + gkyl_vlasov_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.field ? auxin.field->on_dev : 0, auxin.cot_vec ? auxin.cot_vec->on_dev : 0, auxin.alpha_surf ? auxin.alpha_surf->on_dev : 0, auxin.sgn_alpha_surf ? auxin.sgn_alpha_surf->on_dev : 0, - auxin.const_sgn_alpha ? auxin.const_sgn_alpha->on_dev : 0); + auxin.const_sgn_alpha ? auxin.const_sgn_alpha->on_dev : 0 + ); } // CUDA kernel to set device pointers to range object and vlasov kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_vlasov_set_cu_dev_ptrs(struct dg_vlasov *vlasov, enum gkyl_basis_type b_type, - int cv_index, int cdim, int vdim, int poly_order, - enum gkyl_model_id model_id, enum gkyl_field_id field_id) +__global__ static void dg_vlasov_set_cu_dev_ptrs( + struct dg_vlasov *vlasov, enum gkyl_basis_type b_type, int cv_index, int cdim, int vdim, + int poly_order, enum gkyl_model_id model_id, enum gkyl_field_id field_id +) { vlasov->auxfields.field = 0; vlasov->auxfields.cot_vec = 0; @@ -57,111 +59,115 @@ dg_vlasov_set_cu_dev_ptrs(struct dg_vlasov *vlasov, enum gkyl_basis_type b_type, const gkyl_dg_vlasov_stream_vol_kern_list *stream_vol_kernels; const gkyl_dg_vlasov_vol_kern_list *vol_kernels; - const gkyl_dg_vlasov_stream_surf_kern_list *stream_surf_x_kernels, - *stream_surf_y_kernels, + const gkyl_dg_vlasov_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, *stream_surf_z_kernels; - const gkyl_dg_vlasov_accel_surf_kern_list *accel_surf_vx_kernels, - *accel_surf_vy_kernels, + const gkyl_dg_vlasov_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, *accel_surf_vz_kernels; - const gkyl_dg_vlasov_stream_boundary_surf_kern_list *stream_boundary_surf_x_kernels, - *stream_boundary_surf_y_kernels, - *stream_boundary_surf_z_kernels; - - const gkyl_dg_vlasov_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, - *accel_boundary_surf_vy_kernels, - *accel_boundary_surf_vz_kernels; - + const gkyl_dg_vlasov_stream_boundary_surf_kern_list *stream_boundary_surf_x_kernels, + *stream_boundary_surf_y_kernels, *stream_boundary_surf_z_kernels; + + const gkyl_dg_vlasov_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, + *accel_boundary_surf_vy_kernels, *accel_boundary_surf_vz_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - stream_vol_kernels = ser_stream_vol_kernels; - vol_kernels = ser_vol_kernels; - - stream_surf_x_kernels = ser_stream_surf_x_kernels; - stream_surf_y_kernels = ser_stream_surf_y_kernels; - stream_surf_z_kernels = ser_stream_surf_z_kernels; - - accel_surf_vx_kernels = ser_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_accel_surf_vz_kernels; - - stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; - - accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; - - break; - - case GKYL_BASIS_MODAL_TENSOR: - stream_vol_kernels = tensor_stream_vol_kernels; - vol_kernels = tensor_vol_kernels; - - stream_surf_x_kernels = tensor_stream_surf_x_kernels; - stream_surf_y_kernels = tensor_stream_surf_y_kernels; - stream_surf_z_kernels = tensor_stream_surf_z_kernels; - - accel_surf_vx_kernels = tensor_accel_surf_vx_kernels; - accel_surf_vy_kernels = tensor_accel_surf_vy_kernels; - accel_surf_vz_kernels = tensor_accel_surf_vz_kernels; - - stream_boundary_surf_x_kernels = tensor_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = tensor_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = tensor_stream_boundary_surf_z_kernels; - - accel_boundary_surf_vx_kernels = tensor_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = tensor_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = tensor_accel_boundary_surf_vz_kernels; - - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + stream_vol_kernels = ser_stream_vol_kernels; + vol_kernels = ser_vol_kernels; + + stream_surf_x_kernels = ser_stream_surf_x_kernels; + stream_surf_y_kernels = ser_stream_surf_y_kernels; + stream_surf_z_kernels = ser_stream_surf_z_kernels; + + accel_surf_vx_kernels = ser_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_accel_surf_vz_kernels; + + stream_boundary_surf_x_kernels = ser_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = ser_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = ser_stream_boundary_surf_z_kernels; + + accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; + + break; + + case GKYL_BASIS_MODAL_TENSOR: + stream_vol_kernels = tensor_stream_vol_kernels; + vol_kernels = tensor_vol_kernels; + + stream_surf_x_kernels = tensor_stream_surf_x_kernels; + stream_surf_y_kernels = tensor_stream_surf_y_kernels; + stream_surf_z_kernels = tensor_stream_surf_z_kernels; + + accel_surf_vx_kernels = tensor_accel_surf_vx_kernels; + accel_surf_vy_kernels = tensor_accel_surf_vy_kernels; + accel_surf_vz_kernels = tensor_accel_surf_vz_kernels; + + stream_boundary_surf_x_kernels = tensor_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = tensor_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = tensor_stream_boundary_surf_z_kernels; + + accel_boundary_surf_vx_kernels = tensor_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = tensor_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = tensor_accel_boundary_surf_vz_kernels; + + break; + + default: + assert(false); + break; } if (field_id == GKYL_FIELD_NULL) { vlasov->eqn.vol_term = stream_vol_kernels[cv_index].kernels[poly_order]; - } - else { + } else { vlasov->eqn.vol_term = vol_kernels[cv_index].kernels[poly_order]; - + vlasov->accel_surf[0] = accel_surf_vx_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { vlasov->accel_surf[1] = accel_surf_vy_kernels[cv_index].kernels[poly_order]; - if (vdim>2) + } + if (vdim > 2) { vlasov->accel_surf[2] = accel_surf_vz_kernels[cv_index].kernels[poly_order]; - + } + vlasov->accel_boundary_surf[0] = accel_boundary_surf_vx_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { vlasov->accel_boundary_surf[1] = accel_boundary_surf_vy_kernels[cv_index].kernels[poly_order]; - if (vdim>2) + } + if (vdim > 2) { vlasov->accel_boundary_surf[2] = accel_boundary_surf_vz_kernels[cv_index].kernels[poly_order]; + } } // Streaming kernels are the same for each field_id vlasov->stream_surf[0] = stream_surf_x_kernels[cv_index].kernels[poly_order]; - if (cdim>1) + if (cdim > 1) { vlasov->stream_surf[1] = stream_surf_y_kernels[cv_index].kernels[poly_order]; - if (cdim>2) + } + if (cdim > 2) { vlasov->stream_surf[2] = stream_surf_z_kernels[cv_index].kernels[poly_order]; - + } + vlasov->stream_boundary_surf[0] = stream_boundary_surf_x_kernels[cv_index].kernels[poly_order]; - if (cdim>1) + if (cdim > 1) { vlasov->stream_boundary_surf[1] = stream_boundary_surf_y_kernels[cv_index].kernels[poly_order]; - if (cdim>2) - vlasov->stream_boundary_surf[2] = stream_boundary_surf_z_kernels[cv_index].kernels[poly_order]; + } + if (cdim > 2) { + vlasov->stream_boundary_surf[2] = stream_boundary_surf_z_kernels[cv_index].kernels[poly_order]; + } } -struct gkyl_dg_eqn* -gkyl_dg_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* phase_range, - enum gkyl_model_id model_id, enum gkyl_field_id field_id) +struct gkyl_dg_eqn *gkyl_dg_vlasov_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, + enum gkyl_model_id model_id, enum gkyl_field_id field_id +) { - struct dg_vlasov *vlasov = (struct dg_vlasov*) gkyl_malloc(sizeof(struct dg_vlasov)); + struct dg_vlasov *vlasov = (struct dg_vlasov *)gkyl_malloc(sizeof(struct dg_vlasov)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; vlasov->cdim = cdim; @@ -176,14 +182,15 @@ gkyl_dg_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_bas vlasov->eqn.ref_count = gkyl_ref_count_init(gkyl_vlasov_free); // copy the host struct to device struct - struct dg_vlasov *vlasov_cu = (struct dg_vlasov*) gkyl_cu_malloc(sizeof(struct dg_vlasov)); + struct dg_vlasov *vlasov_cu = (struct dg_vlasov *)gkyl_cu_malloc(sizeof(struct dg_vlasov)); gkyl_cu_memcpy(vlasov_cu, vlasov, sizeof(struct dg_vlasov), GKYL_CU_MEMCPY_H2D); - dg_vlasov_set_cu_dev_ptrs<<<1,1>>>(vlasov_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], - cdim, vdim, poly_order, model_id, field_id); + dg_vlasov_set_cu_dev_ptrs<<<1, 1> > >( + vlasov_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order, model_id, field_id + ); // set parent on_dev pointer vlasov->eqn.on_dev = &vlasov_cu->eqn; - + return &vlasov->eqn; } diff --git a/vlasov/zero/dg_vlasov_poisson.c b/vlasov/zero/dg_vlasov_poisson.c index 326e595ed1..dcc96c1aad 100644 --- a/vlasov/zero/dg_vlasov_poisson.c +++ b/vlasov/zero/dg_vlasov_poisson.c @@ -9,23 +9,23 @@ #include #include -void -gkyl_vlasov_poisson_free(const struct gkyl_ref_count *ref) +void gkyl_vlasov_poisson_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); - + if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object struct dg_vlasov_poisson *vlasov = container_of(base->on_dev, struct dg_vlasov_poisson, eqn); gkyl_cu_free(vlasov); } - + struct dg_vlasov_poisson *vlasov = container_of(base, struct dg_vlasov_poisson, eqn); gkyl_free(vlasov); } -void -gkyl_vlasov_poisson_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_poisson_auxfields auxin) +void gkyl_vlasov_poisson_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_poisson_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_dg_eqn_is_cu_dev(eqn)) { @@ -35,23 +35,26 @@ gkyl_vlasov_poisson_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_ #endif struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); - vlasov->auxfields.potentials = auxin.potentials; - vlasov->auxfields.fields_ext = auxin.fields_ext; + vlasov->auxfields.potentials = auxin.potentials; + vlasov->auxfields.fields_ext = auxin.fields_ext; } -struct gkyl_dg_eqn* -gkyl_dg_vlasov_poisson_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* phase_range, - enum gkyl_model_id model_id, enum gkyl_field_id field_id, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_vlasov_poisson_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, + enum gkyl_model_id model_id, enum gkyl_field_id field_id, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { - return gkyl_dg_vlasov_poisson_cu_dev_new(cbasis, pbasis, conf_range, phase_range, model_id, field_id); - } + return gkyl_dg_vlasov_poisson_cu_dev_new( + cbasis, pbasis, conf_range, phase_range, model_id, field_id + ); + } #endif struct dg_vlasov_poisson *vlasov = gkyl_malloc(sizeof(*vlasov)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; vlasov->cdim = cdim; @@ -63,100 +66,114 @@ gkyl_dg_vlasov_poisson_new(const struct gkyl_basis* cbasis, const struct gkyl_ba const gkyl_dg_vlasov_poisson_vol_kern_list *vol_kernels; - const gkyl_dg_vlasov_poisson_stream_surf_kern_list *stream_surf_x_kernels, - *stream_surf_y_kernels, *stream_surf_z_kernels; - const gkyl_dg_vlasov_poisson_accel_surf_kern_list *accel_surf_vx_kernels, - *accel_surf_vy_kernels, *accel_surf_vz_kernels; + const gkyl_dg_vlasov_poisson_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, + *stream_surf_z_kernels; + const gkyl_dg_vlasov_poisson_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, + *accel_surf_vz_kernels; - const gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list *stream_boundary_surf_x_kernels, + const gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list *stream_boundary_surf_x_kernels, *stream_boundary_surf_y_kernels, *stream_boundary_surf_z_kernels; - const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, + const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, *accel_boundary_surf_vy_kernels, *accel_boundary_surf_vz_kernels; - + switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Streaming kernels are the same for each field_id. - stream_surf_x_kernels = ser_poisson_stream_surf_x_kernels; - stream_surf_y_kernels = ser_poisson_stream_surf_y_kernels; - stream_surf_z_kernels = ser_poisson_stream_surf_z_kernels; - stream_boundary_surf_x_kernels = ser_poisson_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = ser_poisson_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = ser_poisson_stream_boundary_surf_z_kernels; - - if (field_id == GKYL_FIELD_PHI) { - vol_kernels = ser_poisson_vol_kernels; - accel_surf_vx_kernels = ser_poisson_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_poisson_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_poisson_accel_surf_vz_kernels; - accel_boundary_surf_vx_kernels = ser_poisson_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_poisson_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_poisson_accel_boundary_surf_vz_kernels; - } else if (field_id == GKYL_FIELD_PHI_EXT_POTENTIALS) { - vol_kernels = ser_poisson_ext_phiA_vol_kernels; - accel_surf_vx_kernels = ser_poisson_ext_phiA_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_poisson_ext_phiA_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_poisson_ext_phiA_accel_surf_vz_kernels; - accel_boundary_surf_vx_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vz_kernels; - } else if (field_id == GKYL_FIELD_PHI_EXT_FIELDS) { - vol_kernels = ser_poisson_ext_EB_vol_kernels; - accel_surf_vx_kernels = ser_poisson_ext_EB_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_poisson_ext_EB_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_poisson_ext_EB_accel_surf_vz_kernels; - accel_boundary_surf_vx_kernels = ser_poisson_ext_EB_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_poisson_ext_EB_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_poisson_ext_EB_accel_boundary_surf_vz_kernels; - } - - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + // Streaming kernels are the same for each field_id. + stream_surf_x_kernels = ser_poisson_stream_surf_x_kernels; + stream_surf_y_kernels = ser_poisson_stream_surf_y_kernels; + stream_surf_z_kernels = ser_poisson_stream_surf_z_kernels; + stream_boundary_surf_x_kernels = ser_poisson_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = ser_poisson_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = ser_poisson_stream_boundary_surf_z_kernels; + + if (field_id == GKYL_FIELD_PHI) { + vol_kernels = ser_poisson_vol_kernels; + accel_surf_vx_kernels = ser_poisson_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_poisson_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_poisson_accel_surf_vz_kernels; + accel_boundary_surf_vx_kernels = ser_poisson_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_poisson_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_poisson_accel_boundary_surf_vz_kernels; + } else if (field_id == GKYL_FIELD_PHI_EXT_POTENTIALS) { + vol_kernels = ser_poisson_ext_phiA_vol_kernels; + accel_surf_vx_kernels = ser_poisson_ext_phiA_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_poisson_ext_phiA_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_poisson_ext_phiA_accel_surf_vz_kernels; + accel_boundary_surf_vx_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vz_kernels; + } else if (field_id == GKYL_FIELD_PHI_EXT_FIELDS) { + vol_kernels = ser_poisson_ext_EB_vol_kernels; + accel_surf_vx_kernels = ser_poisson_ext_EB_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_poisson_ext_EB_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_poisson_ext_EB_accel_surf_vz_kernels; + accel_boundary_surf_vx_kernels = ser_poisson_ext_EB_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_poisson_ext_EB_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_poisson_ext_EB_accel_boundary_surf_vz_kernels; + } + + break; + + default: + assert(false); + break; } - vlasov->eqn.vol_term = CK(vol_kernels,cdim,vdim,poly_order); + vlasov->eqn.vol_term = CK(vol_kernels, cdim, vdim, poly_order); - vlasov->stream_surf[0] = CK(stream_surf_x_kernels,cdim,vdim,poly_order); - if (cdim>1) - vlasov->stream_surf[1] = CK(stream_surf_y_kernels,cdim,vdim,poly_order); - if (cdim>2) - vlasov->stream_surf[2] = CK(stream_surf_z_kernels,cdim,vdim,poly_order); + vlasov->stream_surf[0] = CK(stream_surf_x_kernels, cdim, vdim, poly_order); + if (cdim > 1) { + vlasov->stream_surf[1] = CK(stream_surf_y_kernels, cdim, vdim, poly_order); + } + if (cdim > 2) { + vlasov->stream_surf[2] = CK(stream_surf_z_kernels, cdim, vdim, poly_order); + } - vlasov->stream_boundary_surf[0] = CK(stream_boundary_surf_x_kernels,cdim,vdim,poly_order); - if (cdim>1) - vlasov->stream_boundary_surf[1] = CK(stream_boundary_surf_y_kernels,cdim,vdim,poly_order); - if (cdim>2) - vlasov->stream_boundary_surf[2] = CK(stream_boundary_surf_z_kernels,cdim,vdim,poly_order); + vlasov->stream_boundary_surf[0] = CK(stream_boundary_surf_x_kernels, cdim, vdim, poly_order); + if (cdim > 1) { + vlasov->stream_boundary_surf[1] = CK(stream_boundary_surf_y_kernels, cdim, vdim, poly_order); + } + if (cdim > 2) { + vlasov->stream_boundary_surf[2] = CK(stream_boundary_surf_z_kernels, cdim, vdim, poly_order); + } - vlasov->accel_surf[0] = CK(accel_surf_vx_kernels,cdim,vdim,poly_order); - if (vdim>1) - vlasov->accel_surf[1] = CK(accel_surf_vy_kernels,cdim,vdim,poly_order); - if (vdim>2) - vlasov->accel_surf[2] = CK(accel_surf_vz_kernels,cdim,vdim,poly_order); + vlasov->accel_surf[0] = CK(accel_surf_vx_kernels, cdim, vdim, poly_order); + if (vdim > 1) { + vlasov->accel_surf[1] = CK(accel_surf_vy_kernels, cdim, vdim, poly_order); + } + if (vdim > 2) { + vlasov->accel_surf[2] = CK(accel_surf_vz_kernels, cdim, vdim, poly_order); + } - vlasov->accel_boundary_surf[0] = CK(accel_boundary_surf_vx_kernels,cdim,vdim,poly_order); - if (vdim>1) - vlasov->accel_boundary_surf[1] = CK(accel_boundary_surf_vy_kernels,cdim,vdim,poly_order); - if (vdim>2) - vlasov->accel_boundary_surf[2] = CK(accel_boundary_surf_vz_kernels,cdim,vdim,poly_order); + vlasov->accel_boundary_surf[0] = CK(accel_boundary_surf_vx_kernels, cdim, vdim, poly_order); + if (vdim > 1) { + vlasov->accel_boundary_surf[1] = CK(accel_boundary_surf_vy_kernels, cdim, vdim, poly_order); + } + if (vdim > 2) { + vlasov->accel_boundary_surf[2] = CK(accel_boundary_surf_vz_kernels, cdim, vdim, poly_order); + } // Ensure non-NULL pointers. - for (int i=0; istream_surf[i]); - for (int i=0; iaccel_surf[i]); - for (int i=0; iaccel_boundary_surf[i]); + for (int i = 0; i < cdim; ++i) { + assert(vlasov->stream_surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(vlasov->accel_surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(vlasov->accel_boundary_surf[i]); + } vlasov->auxfields.potentials = 0; vlasov->auxfields.fields_ext = 0; vlasov->conf_range = *conf_range; vlasov->phase_range = *phase_range; - + vlasov->eqn.flags = 0; GKYL_CLEAR_CU_ALLOC(vlasov->eqn.flags); vlasov->eqn.ref_count = gkyl_ref_count_init(gkyl_vlasov_poisson_free); vlasov->eqn.on_dev = &vlasov->eqn; // CPU eqn obj points to itself - + return &vlasov->eqn; } diff --git a/vlasov/zero/dg_vlasov_poisson_cu.cu b/vlasov/zero/dg_vlasov_poisson_cu.cu index a4435f31c8..953dd4702a 100644 --- a/vlasov/zero/dg_vlasov_poisson_cu.cu +++ b/vlasov/zero/dg_vlasov_poisson_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include } @@ -12,28 +12,31 @@ extern "C" { // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_vlasov_poisson_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, const struct gkyl_array *pots, - const struct gkyl_array *EBext) +__global__ static void gkyl_vlasov_poisson_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *pots, const struct gkyl_array *EBext +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); - vlasov->auxfields.potentials = pots; - vlasov->auxfields.fields_ext = EBext; + vlasov->auxfields.potentials = pots; + vlasov->auxfields.fields_ext = EBext; } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_vlasov_poisson_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_poisson_auxfields auxin) +void gkyl_vlasov_poisson_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_poisson_auxfields auxin +) { - gkyl_vlasov_poisson_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.potentials->on_dev, auxin.fields_ext->on_dev); + gkyl_vlasov_poisson_set_auxfields_cu_kernel<<<1, 1> > >( + eqn, auxin.potentials->on_dev, auxin.fields_ext->on_dev + ); } // CUDA kernel to set device pointers to range object and vlasov kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_vlasov_poisson_set_cu_dev_ptrs(struct dg_vlasov_poisson *vlasov, enum gkyl_basis_type b_type, - int cv_index, int cdim, int vdim, int poly_order, - enum gkyl_model_id model_id, enum gkyl_field_id field_id) +__global__ static void dg_vlasov_poisson_set_cu_dev_ptrs( + struct dg_vlasov_poisson *vlasov, enum gkyl_basis_type b_type, int cv_index, int cdim, int vdim, + int poly_order, enum gkyl_model_id model_id, enum gkyl_field_id field_id +) { vlasov->auxfields.potentials = 0; vlasov->auxfields.fields_ext = 0; @@ -43,93 +46,103 @@ dg_vlasov_poisson_set_cu_dev_ptrs(struct dg_vlasov_poisson *vlasov, enum gkyl_ba const gkyl_dg_vlasov_poisson_vol_kern_list *vol_kernels; - const gkyl_dg_vlasov_poisson_stream_surf_kern_list *stream_surf_x_kernels, - *stream_surf_y_kernels, *stream_surf_z_kernels; - const gkyl_dg_vlasov_poisson_accel_surf_kern_list *accel_surf_vx_kernels, - *accel_surf_vy_kernels, *accel_surf_vz_kernels; + const gkyl_dg_vlasov_poisson_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, + *stream_surf_z_kernels; + const gkyl_dg_vlasov_poisson_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, + *accel_surf_vz_kernels; const gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list *stream_boundary_surf_x_kernels, *stream_boundary_surf_y_kernels, *stream_boundary_surf_z_kernels; const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, *accel_boundary_surf_vy_kernels, *accel_boundary_surf_vz_kernels; - + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - stream_surf_x_kernels = ser_poisson_stream_surf_x_kernels; - stream_surf_y_kernels = ser_poisson_stream_surf_y_kernels; - stream_surf_z_kernels = ser_poisson_stream_surf_z_kernels; - stream_boundary_surf_x_kernels = ser_poisson_stream_boundary_surf_x_kernels; - stream_boundary_surf_y_kernels = ser_poisson_stream_boundary_surf_y_kernels; - stream_boundary_surf_z_kernels = ser_poisson_stream_boundary_surf_z_kernels; - - if (field_id == GKYL_FIELD_PHI) { - vol_kernels = ser_poisson_vol_kernels; - accel_surf_vx_kernels = ser_poisson_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_poisson_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_poisson_accel_surf_vz_kernels; - accel_boundary_surf_vx_kernels = ser_poisson_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_poisson_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_poisson_accel_boundary_surf_vz_kernels; - } else if (field_id == GKYL_FIELD_PHI_EXT_POTENTIALS) { - vol_kernels = ser_poisson_ext_phiA_vol_kernels; - accel_surf_vx_kernels = ser_poisson_ext_phiA_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_poisson_ext_phiA_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_poisson_ext_phiA_accel_surf_vz_kernels; - accel_boundary_surf_vx_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vz_kernels; - } else if (field_id == GKYL_FIELD_PHI_EXT_FIELDS) { - vol_kernels = ser_poisson_ext_EB_vol_kernels; - accel_surf_vx_kernels = ser_poisson_ext_EB_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_poisson_ext_EB_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_poisson_ext_EB_accel_surf_vz_kernels; - accel_boundary_surf_vx_kernels = ser_poisson_ext_EB_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_poisson_ext_EB_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_poisson_ext_EB_accel_boundary_surf_vz_kernels; - } - - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + stream_surf_x_kernels = ser_poisson_stream_surf_x_kernels; + stream_surf_y_kernels = ser_poisson_stream_surf_y_kernels; + stream_surf_z_kernels = ser_poisson_stream_surf_z_kernels; + stream_boundary_surf_x_kernels = ser_poisson_stream_boundary_surf_x_kernels; + stream_boundary_surf_y_kernels = ser_poisson_stream_boundary_surf_y_kernels; + stream_boundary_surf_z_kernels = ser_poisson_stream_boundary_surf_z_kernels; + + if (field_id == GKYL_FIELD_PHI) { + vol_kernels = ser_poisson_vol_kernels; + accel_surf_vx_kernels = ser_poisson_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_poisson_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_poisson_accel_surf_vz_kernels; + accel_boundary_surf_vx_kernels = ser_poisson_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_poisson_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_poisson_accel_boundary_surf_vz_kernels; + } else if (field_id == GKYL_FIELD_PHI_EXT_POTENTIALS) { + vol_kernels = ser_poisson_ext_phiA_vol_kernels; + accel_surf_vx_kernels = ser_poisson_ext_phiA_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_poisson_ext_phiA_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_poisson_ext_phiA_accel_surf_vz_kernels; + accel_boundary_surf_vx_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_poisson_ext_phiA_accel_boundary_surf_vz_kernels; + } else if (field_id == GKYL_FIELD_PHI_EXT_FIELDS) { + vol_kernels = ser_poisson_ext_EB_vol_kernels; + accel_surf_vx_kernels = ser_poisson_ext_EB_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_poisson_ext_EB_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_poisson_ext_EB_accel_surf_vz_kernels; + accel_boundary_surf_vx_kernels = ser_poisson_ext_EB_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_poisson_ext_EB_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_poisson_ext_EB_accel_boundary_surf_vz_kernels; + } + + break; + + default: + assert(false); + break; } vlasov->eqn.vol_term = vol_kernels[cv_index].kernels[poly_order]; vlasov->stream_surf[0] = stream_surf_x_kernels[cv_index].kernels[poly_order]; - if (cdim>1) + if (cdim > 1) { vlasov->stream_surf[1] = stream_surf_y_kernels[cv_index].kernels[poly_order]; - if (cdim>2) + } + if (cdim > 2) { vlasov->stream_surf[2] = stream_surf_z_kernels[cv_index].kernels[poly_order]; + } vlasov->stream_boundary_surf[0] = stream_boundary_surf_x_kernels[cv_index].kernels[poly_order]; - if (cdim>1) + if (cdim > 1) { vlasov->stream_boundary_surf[1] = stream_boundary_surf_y_kernels[cv_index].kernels[poly_order]; - if (cdim>2) + } + if (cdim > 2) { vlasov->stream_boundary_surf[2] = stream_boundary_surf_z_kernels[cv_index].kernels[poly_order]; + } vlasov->accel_surf[0] = accel_surf_vx_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { vlasov->accel_surf[1] = accel_surf_vy_kernels[cv_index].kernels[poly_order]; - if (vdim>2) + } + if (vdim > 2) { vlasov->accel_surf[2] = accel_surf_vz_kernels[cv_index].kernels[poly_order]; + } vlasov->accel_boundary_surf[0] = accel_boundary_surf_vx_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { vlasov->accel_boundary_surf[1] = accel_boundary_surf_vy_kernels[cv_index].kernels[poly_order]; - if (vdim>2) + } + if (vdim > 2) { vlasov->accel_boundary_surf[2] = accel_boundary_surf_vz_kernels[cv_index].kernels[poly_order]; + } } -struct gkyl_dg_eqn* -gkyl_dg_vlasov_poisson_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* phase_range, - enum gkyl_model_id model_id, enum gkyl_field_id field_id) +struct gkyl_dg_eqn *gkyl_dg_vlasov_poisson_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, + enum gkyl_model_id model_id, enum gkyl_field_id field_id +) { - struct dg_vlasov_poisson *vlasov = (struct dg_vlasov_poisson*) gkyl_malloc(sizeof(struct dg_vlasov_poisson)); + struct dg_vlasov_poisson *vlasov = + (struct dg_vlasov_poisson *)gkyl_malloc(sizeof(struct dg_vlasov_poisson)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; vlasov->cdim = cdim; @@ -144,14 +157,16 @@ gkyl_dg_vlasov_poisson_cu_dev_new(const struct gkyl_basis* cbasis, const struct vlasov->eqn.ref_count = gkyl_ref_count_init(gkyl_vlasov_poisson_free); // copy the host struct to device struct - struct dg_vlasov_poisson *vlasov_cu = (struct dg_vlasov_poisson*) gkyl_cu_malloc(sizeof(struct dg_vlasov_poisson)); + struct dg_vlasov_poisson *vlasov_cu = + (struct dg_vlasov_poisson *)gkyl_cu_malloc(sizeof(struct dg_vlasov_poisson)); gkyl_cu_memcpy(vlasov_cu, vlasov, sizeof(struct dg_vlasov_poisson), GKYL_CU_MEMCPY_H2D); - dg_vlasov_poisson_set_cu_dev_ptrs<<<1,1>>>(vlasov_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], - cdim, vdim, poly_order, model_id, field_id); + dg_vlasov_poisson_set_cu_dev_ptrs<<<1, 1> > >( + vlasov_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order, model_id, field_id + ); // set parent on_dev pointer vlasov->eqn.on_dev = &vlasov_cu->eqn; - + return &vlasov->eqn; } diff --git a/vlasov/zero/dg_vlasov_sr.c b/vlasov/zero/dg_vlasov_sr.c index 4b1e927baa..a0c592d08b 100644 --- a/vlasov/zero/dg_vlasov_sr.c +++ b/vlasov/zero/dg_vlasov_sr.c @@ -9,23 +9,23 @@ #include #include -void -gkyl_vlasov_sr_free(const struct gkyl_ref_count *ref) +void gkyl_vlasov_sr_free(const struct gkyl_ref_count *ref) { struct gkyl_dg_eqn *base = container_of(ref, struct gkyl_dg_eqn, ref_count); - + if (gkyl_dg_eqn_is_cu_dev(base)) { // free inner on_dev object struct dg_vlasov_sr *vlasov_sr = container_of(base->on_dev, struct dg_vlasov_sr, eqn); gkyl_cu_free(vlasov_sr); } - + struct dg_vlasov_sr *vlasov_sr = container_of(base, struct dg_vlasov_sr, eqn); gkyl_free(vlasov_sr); } -void -gkyl_vlasov_sr_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_sr_auxfields auxin) +void gkyl_vlasov_sr_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_sr_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_dg_eqn_is_cu_dev(eqn)) { @@ -39,20 +39,20 @@ gkyl_vlasov_sr_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlaso vlasov_sr->auxfields.gamma = auxin.gamma; } -struct gkyl_dg_eqn* -gkyl_dg_vlasov_sr_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* vel_range, - enum gkyl_field_id field_id, bool use_gpu) +struct gkyl_dg_eqn *gkyl_dg_vlasov_sr_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_field_id field_id, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_dg_vlasov_sr_cu_dev_new(cbasis, pbasis, conf_range, vel_range, field_id); - } + } #endif struct dg_vlasov_sr *vlasov_sr = gkyl_malloc(sizeof(struct dg_vlasov_sr)); - - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; vlasov_sr->cdim = cdim; @@ -64,60 +64,75 @@ gkyl_dg_vlasov_sr_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* const gkyl_dg_vlasov_sr_stream_vol_kern_list *stream_vol_kernels; const gkyl_dg_vlasov_sr_vol_kern_list *vol_kernels; - const gkyl_dg_vlasov_sr_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, *stream_surf_z_kernels; - const gkyl_dg_vlasov_sr_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, *accel_surf_vz_kernels; - const gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, *accel_boundary_surf_vy_kernels, - *accel_boundary_surf_vz_kernels; - + const gkyl_dg_vlasov_sr_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, + *stream_surf_z_kernels; + const gkyl_dg_vlasov_sr_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, + *accel_surf_vz_kernels; + const gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, + *accel_boundary_surf_vy_kernels, *accel_boundary_surf_vz_kernels; + switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - stream_vol_kernels = ser_stream_vol_kernels; - vol_kernels = ser_vol_kernels; - stream_surf_x_kernels = ser_stream_surf_x_kernels; - stream_surf_y_kernels = ser_stream_surf_y_kernels; - stream_surf_z_kernels = ser_stream_surf_z_kernels; - accel_surf_vx_kernels = ser_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_accel_surf_vz_kernels; - accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; - - break; - - default: - assert(false); - break; - } - if (field_id == GKYL_FIELD_NULL) - vlasov_sr->eqn.vol_term = CK(stream_vol_kernels,cdim,vdim,poly_order); - else - vlasov_sr->eqn.vol_term = CK(vol_kernels,cdim,vdim,poly_order); - - vlasov_sr->stream_surf[0] = CK(stream_surf_x_kernels,cdim,vdim,poly_order); - if (cdim>1) - vlasov_sr->stream_surf[1] = CK(stream_surf_y_kernels,cdim,vdim,poly_order); - if (cdim>2) - vlasov_sr->stream_surf[2] = CK(stream_surf_z_kernels,cdim,vdim,poly_order); - - vlasov_sr->accel_surf[0] = CK(accel_surf_vx_kernels,cdim,vdim,poly_order); - if (vdim>1) - vlasov_sr->accel_surf[1] = CK(accel_surf_vy_kernels,cdim,vdim,poly_order); - if (vdim>2) - vlasov_sr->accel_surf[2] = CK(accel_surf_vz_kernels,cdim,vdim,poly_order); - - vlasov_sr->accel_boundary_surf[0] = CK(accel_boundary_surf_vx_kernels,cdim,vdim,poly_order); - if (vdim>1) - vlasov_sr->accel_boundary_surf[1] = CK(accel_boundary_surf_vy_kernels,cdim,vdim,poly_order); - if (vdim>2) - vlasov_sr->accel_boundary_surf[2] = CK(accel_boundary_surf_vz_kernels,cdim,vdim,poly_order); + case GKYL_BASIS_MODAL_SERENDIPITY: + stream_vol_kernels = ser_stream_vol_kernels; + vol_kernels = ser_vol_kernels; + stream_surf_x_kernels = ser_stream_surf_x_kernels; + stream_surf_y_kernels = ser_stream_surf_y_kernels; + stream_surf_z_kernels = ser_stream_surf_z_kernels; + accel_surf_vx_kernels = ser_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_accel_surf_vz_kernels; + accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; + + break; + + default: + assert(false); + break; + } + if (field_id == GKYL_FIELD_NULL) { + vlasov_sr->eqn.vol_term = CK(stream_vol_kernels, cdim, vdim, poly_order); + } else { + vlasov_sr->eqn.vol_term = CK(vol_kernels, cdim, vdim, poly_order); + } + + vlasov_sr->stream_surf[0] = CK(stream_surf_x_kernels, cdim, vdim, poly_order); + if (cdim > 1) { + vlasov_sr->stream_surf[1] = CK(stream_surf_y_kernels, cdim, vdim, poly_order); + } + if (cdim > 2) { + vlasov_sr->stream_surf[2] = CK(stream_surf_z_kernels, cdim, vdim, poly_order); + } + + vlasov_sr->accel_surf[0] = CK(accel_surf_vx_kernels, cdim, vdim, poly_order); + if (vdim > 1) { + vlasov_sr->accel_surf[1] = CK(accel_surf_vy_kernels, cdim, vdim, poly_order); + } + if (vdim > 2) { + vlasov_sr->accel_surf[2] = CK(accel_surf_vz_kernels, cdim, vdim, poly_order); + } + + vlasov_sr->accel_boundary_surf[0] = CK(accel_boundary_surf_vx_kernels, cdim, vdim, poly_order); + if (vdim > 1) { + vlasov_sr->accel_boundary_surf[1] = CK(accel_boundary_surf_vy_kernels, cdim, vdim, poly_order); + } + if (vdim > 2) { + vlasov_sr->accel_boundary_surf[2] = CK(accel_boundary_surf_vz_kernels, cdim, vdim, poly_order); + } // ensure non-NULL pointers - for (int i=0; istream_surf[i]); - for (int i=0; iaccel_surf[i]); - for (int i=0; iaccel_boundary_surf[i]); + for (int i = 0; i < cdim; ++i) { + assert(vlasov_sr->stream_surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(vlasov_sr->accel_surf[i]); + } + for (int i = 0; i < vdim; ++i) { + assert(vlasov_sr->accel_boundary_surf[i]); + } - vlasov_sr->auxfields.qmem = 0; + vlasov_sr->auxfields.qmem = 0; vlasov_sr->conf_range = *conf_range; vlasov_sr->vel_range = *vel_range; @@ -128,16 +143,17 @@ gkyl_dg_vlasov_sr_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* vlasov_sr->eqn.ref_count = gkyl_ref_count_init(gkyl_vlasov_sr_free); vlasov_sr->eqn.on_dev = &vlasov_sr->eqn; // CPU eqn obj points to itself - + return &vlasov_sr->eqn; } #ifndef GKYL_HAVE_CUDA -struct gkyl_dg_eqn* -gkyl_dg_vlasov_sr_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* vel_range, - enum gkyl_field_id field_id) +struct gkyl_dg_eqn *gkyl_dg_vlasov_sr_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_field_id field_id +) { assert(false); return 0; diff --git a/vlasov/zero/dg_vlasov_sr_cu.cu b/vlasov/zero/dg_vlasov_sr_cu.cu index 769f139c9c..7e1ca66bbf 100644 --- a/vlasov/zero/dg_vlasov_sr_cu.cu +++ b/vlasov/zero/dg_vlasov_sr_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include #include } @@ -13,9 +13,9 @@ extern "C" { // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_vlasov_sr_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, - const struct gkyl_array *qmem, const struct gkyl_array *gamma) +__global__ static void gkyl_vlasov_sr_set_auxfields_cu_kernel( + const struct gkyl_dg_eqn *eqn, const struct gkyl_array *qmem, const struct gkyl_array *gamma +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); vlasov_sr->auxfields.qmem = qmem; @@ -23,83 +23,97 @@ gkyl_vlasov_sr_set_auxfields_cu_kernel(const struct gkyl_dg_eqn *eqn, } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_vlasov_sr_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_sr_auxfields auxin) +void gkyl_vlasov_sr_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_sr_auxfields auxin +) { - gkyl_vlasov_sr_set_auxfields_cu_kernel<<<1,1>>>(eqn, auxin.qmem->on_dev, auxin.gamma->on_dev); + gkyl_vlasov_sr_set_auxfields_cu_kernel<<<1, 1> > >(eqn, auxin.qmem->on_dev, auxin.gamma->on_dev); } // CUDA kernel to set device pointers to range object and vlasov kernel function // Doing function pointer stuff in here avoids troublesome cudaMemcpyFromSymbol -__global__ static void -dg_vlasov_sr_set_cu_dev_ptrs(struct dg_vlasov_sr *vlasov_sr, enum gkyl_basis_type b_type, - int cv_index, int cdim, int vdim, int poly_order, enum gkyl_field_id field_id) +__global__ static void dg_vlasov_sr_set_cu_dev_ptrs( + struct dg_vlasov_sr *vlasov_sr, enum gkyl_basis_type b_type, int cv_index, int cdim, int vdim, + int poly_order, enum gkyl_field_id field_id +) { - vlasov_sr->auxfields.qmem = 0; - vlasov_sr->auxfields.gamma= 0; + vlasov_sr->auxfields.qmem = 0; + vlasov_sr->auxfields.gamma = 0; vlasov_sr->eqn.surf_term = surf; vlasov_sr->eqn.boundary_surf_term = boundary_surf; const gkyl_dg_vlasov_sr_stream_vol_kern_list *stream_vol_kernels; const gkyl_dg_vlasov_sr_vol_kern_list *vol_kernels; - const gkyl_dg_vlasov_sr_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, *stream_surf_z_kernels; - const gkyl_dg_vlasov_sr_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, *accel_surf_vz_kernels; - const gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, *accel_boundary_surf_vy_kernels, - *accel_boundary_surf_vz_kernels; - + const gkyl_dg_vlasov_sr_stream_surf_kern_list *stream_surf_x_kernels, *stream_surf_y_kernels, + *stream_surf_z_kernels; + const gkyl_dg_vlasov_sr_accel_surf_kern_list *accel_surf_vx_kernels, *accel_surf_vy_kernels, + *accel_surf_vz_kernels; + const gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list *accel_boundary_surf_vx_kernels, + *accel_boundary_surf_vy_kernels, *accel_boundary_surf_vz_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - stream_vol_kernels = ser_stream_vol_kernels; - vol_kernels = ser_vol_kernels; - stream_surf_x_kernels = ser_stream_surf_x_kernels; - stream_surf_y_kernels = ser_stream_surf_y_kernels; - stream_surf_z_kernels = ser_stream_surf_z_kernels; - accel_surf_vx_kernels = ser_accel_surf_vx_kernels; - accel_surf_vy_kernels = ser_accel_surf_vy_kernels; - accel_surf_vz_kernels = ser_accel_surf_vz_kernels; - accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; - accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; - accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; - - break; - - default: - assert(false); - break; - } - if (field_id == GKYL_FIELD_NULL) + case GKYL_BASIS_MODAL_SERENDIPITY: + stream_vol_kernels = ser_stream_vol_kernels; + vol_kernels = ser_vol_kernels; + stream_surf_x_kernels = ser_stream_surf_x_kernels; + stream_surf_y_kernels = ser_stream_surf_y_kernels; + stream_surf_z_kernels = ser_stream_surf_z_kernels; + accel_surf_vx_kernels = ser_accel_surf_vx_kernels; + accel_surf_vy_kernels = ser_accel_surf_vy_kernels; + accel_surf_vz_kernels = ser_accel_surf_vz_kernels; + accel_boundary_surf_vx_kernels = ser_accel_boundary_surf_vx_kernels; + accel_boundary_surf_vy_kernels = ser_accel_boundary_surf_vy_kernels; + accel_boundary_surf_vz_kernels = ser_accel_boundary_surf_vz_kernels; + + break; + + default: + assert(false); + break; + } + if (field_id == GKYL_FIELD_NULL) { vlasov_sr->eqn.vol_term = stream_vol_kernels[cv_index].kernels[poly_order]; - else + } else { vlasov_sr->eqn.vol_term = vol_kernels[cv_index].kernels[poly_order]; + } vlasov_sr->stream_surf[0] = stream_surf_x_kernels[cv_index].kernels[poly_order]; - if (cdim>1) + if (cdim > 1) { vlasov_sr->stream_surf[1] = stream_surf_y_kernels[cv_index].kernels[poly_order]; - if (cdim>2) + } + if (cdim > 2) { vlasov_sr->stream_surf[2] = stream_surf_z_kernels[cv_index].kernels[poly_order]; + } vlasov_sr->accel_surf[0] = accel_surf_vx_kernels[cv_index].kernels[poly_order]; - if (vdim>1) + if (vdim > 1) { vlasov_sr->accel_surf[1] = accel_surf_vy_kernels[cv_index].kernels[poly_order]; - if (vdim>2) + } + if (vdim > 2) { vlasov_sr->accel_surf[2] = accel_surf_vz_kernels[cv_index].kernels[poly_order]; + } vlasov_sr->accel_boundary_surf[0] = accel_boundary_surf_vx_kernels[cv_index].kernels[poly_order]; - if (vdim>1) - vlasov_sr->accel_boundary_surf[1] = accel_boundary_surf_vy_kernels[cv_index].kernels[poly_order]; - if (vdim>2) - vlasov_sr->accel_boundary_surf[2] = accel_boundary_surf_vz_kernels[cv_index].kernels[poly_order]; + if (vdim > 1) { + vlasov_sr->accel_boundary_surf[1] = + accel_boundary_surf_vy_kernels[cv_index].kernels[poly_order]; + } + if (vdim > 2) { + vlasov_sr->accel_boundary_surf[2] = + accel_boundary_surf_vz_kernels[cv_index].kernels[poly_order]; + } } -struct gkyl_dg_eqn* -gkyl_dg_vlasov_sr_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* vel_range, - enum gkyl_field_id field_id) +struct gkyl_dg_eqn *gkyl_dg_vlasov_sr_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_field_id field_id +) { - struct dg_vlasov_sr *vlasov_sr = (struct dg_vlasov_sr*) gkyl_malloc(sizeof(struct dg_vlasov_sr)); + struct dg_vlasov_sr *vlasov_sr = (struct dg_vlasov_sr *)gkyl_malloc(sizeof(struct dg_vlasov_sr)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; vlasov_sr->cdim = cdim; @@ -114,14 +128,16 @@ gkyl_dg_vlasov_sr_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_ vlasov_sr->eqn.ref_count = gkyl_ref_count_init(gkyl_vlasov_sr_free); // copy the host struct to device struct - struct dg_vlasov_sr *vlasov_sr_cu = (struct dg_vlasov_sr*) gkyl_cu_malloc(sizeof(struct dg_vlasov_sr)); + struct dg_vlasov_sr *vlasov_sr_cu = + (struct dg_vlasov_sr *)gkyl_cu_malloc(sizeof(struct dg_vlasov_sr)); gkyl_cu_memcpy(vlasov_sr_cu, vlasov_sr, sizeof(struct dg_vlasov_sr), GKYL_CU_MEMCPY_H2D); - dg_vlasov_sr_set_cu_dev_ptrs<<<1,1>>>(vlasov_sr_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], - cdim, vdim, poly_order, field_id); + dg_vlasov_sr_set_cu_dev_ptrs<<<1, 1> > >( + vlasov_sr_cu, cbasis->b_type, cv_index[cdim].vdim[vdim], cdim, vdim, poly_order, field_id + ); // set parent on_dev pointer vlasov_sr->eqn.on_dev = &vlasov_sr_cu->eqn; - + return &vlasov_sr->eqn; } diff --git a/vlasov/zero/emission_elastic_model.c b/vlasov/zero/emission_elastic_model.c index ca31298cc8..34c4042b0d 100644 --- a/vlasov/zero/emission_elastic_model.c +++ b/vlasov/zero/emission_elastic_model.c @@ -2,9 +2,9 @@ #include #include -struct gkyl_emission_elastic_model* -gkyl_emission_elastic_furman_pivi_new(double charge, double P1_inf, double P1_hat, - double E_hat, double W, double p, bool use_gpu) +struct gkyl_emission_elastic_model *gkyl_emission_elastic_furman_pivi_new( + double charge, double P1_inf, double P1_hat, double E_hat, double W, double p, bool use_gpu +) { struct gkyl_emission_elastic_furman_pivi *model = gkyl_malloc(sizeof(struct gkyl_emission_elastic_furman_pivi)); @@ -22,12 +22,12 @@ gkyl_emission_elastic_furman_pivi_new(double charge, double P1_inf, double P1_ha return &model->elastic; } -struct gkyl_emission_elastic_model* +struct gkyl_emission_elastic_model * gkyl_emission_elastic_cazaux_new(double charge, double E_f, double phi, bool use_gpu) { struct gkyl_emission_elastic_cazaux *model = gkyl_malloc(sizeof(struct gkyl_emission_elastic_cazaux)); - + model->E_f = E_f; model->phi = phi; model->elastic.charge = charge; @@ -38,12 +38,12 @@ gkyl_emission_elastic_cazaux_new(double charge, double E_f, double phi, bool use return &model->elastic; } -struct gkyl_emission_elastic_model* +struct gkyl_emission_elastic_model * gkyl_emission_elastic_constant_new(double charge, double delta, bool use_gpu) { struct gkyl_emission_elastic_constant *model = - gkyl_malloc(sizeof(struct gkyl_emission_elastic_constant)); - + gkyl_malloc(sizeof(struct gkyl_emission_elastic_constant)); + model->delta = delta; model->elastic.charge = charge; model->elastic.function = gkyl_emission_elastic_constant_yield; @@ -53,15 +53,14 @@ gkyl_emission_elastic_constant_new(double charge, double delta, bool use_gpu) return &model->elastic; } -struct gkyl_emission_elastic_model* -gkyl_emission_elastic_model_acquire(const struct gkyl_emission_elastic_model* model) +struct gkyl_emission_elastic_model * +gkyl_emission_elastic_model_acquire(const struct gkyl_emission_elastic_model *model) { gkyl_ref_count_inc(&model->ref_count); - return (struct gkyl_emission_elastic_model*) model; + return (struct gkyl_emission_elastic_model *)model; } -void -gkyl_emission_elastic_model_release(const struct gkyl_emission_elastic_model* model) +void gkyl_emission_elastic_model_release(const struct gkyl_emission_elastic_model *model) { gkyl_ref_count_dec(&model->ref_count); } diff --git a/vlasov/zero/emission_spectrum_model.c b/vlasov/zero/emission_spectrum_model.c index 6c152bcf54..553e3650ee 100644 --- a/vlasov/zero/emission_spectrum_model.c +++ b/vlasov/zero/emission_spectrum_model.c @@ -3,12 +3,12 @@ #include #include -struct gkyl_emission_spectrum_model* +struct gkyl_emission_spectrum_model * gkyl_emission_spectrum_chung_everhart_new(double charge, double phi, bool use_gpu) { struct gkyl_emission_spectrum_chung_everhart *model = gkyl_malloc(sizeof(struct gkyl_emission_spectrum_chung_everhart)); - + model->phi = phi; model->spectrum.charge = charge; model->spectrum.distribution = gkyl_emission_spectrum_chung_everhart_dist; @@ -19,7 +19,7 @@ gkyl_emission_spectrum_chung_everhart_new(double charge, double phi, bool use_gp model->spectrum.ref_count = gkyl_ref_count_init(gkyl_emission_spectrum_chung_everhart_free); #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { model->spectrum.on_dev = gkyl_emission_spectrum_chung_everhart_cu_dev_new(model, charge, phi); } #endif @@ -27,7 +27,7 @@ gkyl_emission_spectrum_chung_everhart_new(double charge, double phi, bool use_gp return &model->spectrum; } -struct gkyl_emission_spectrum_model* +struct gkyl_emission_spectrum_model * gkyl_emission_spectrum_gaussian_new(double charge, double E_0, double tau, bool use_gpu) { struct gkyl_emission_spectrum_gaussian *model = @@ -44,7 +44,7 @@ gkyl_emission_spectrum_gaussian_new(double charge, double E_0, double tau, bool model->spectrum.ref_count = gkyl_ref_count_init(gkyl_emission_spectrum_gaussian_free); #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { model->spectrum.on_dev = gkyl_emission_spectrum_gaussian_cu_dev_new(model, charge, E_0, tau); } #endif @@ -52,7 +52,7 @@ gkyl_emission_spectrum_gaussian_new(double charge, double E_0, double tau, bool return &model->spectrum; } -struct gkyl_emission_spectrum_model* +struct gkyl_emission_spectrum_model * gkyl_emission_spectrum_maxwellian_new(double charge, double vt, bool use_gpu) { struct gkyl_emission_spectrum_maxwellian *model = @@ -68,7 +68,7 @@ gkyl_emission_spectrum_maxwellian_new(double charge, double vt, bool use_gpu) model->spectrum.ref_count = gkyl_ref_count_init(gkyl_emission_spectrum_maxwellian_free); #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { model->spectrum.on_dev = gkyl_emission_spectrum_maxwellian_cu_dev_new(model, charge, vt); } #endif @@ -76,21 +76,19 @@ gkyl_emission_spectrum_maxwellian_new(double charge, double vt, bool use_gpu) return &model->spectrum; } -bool -gkyl_emission_spectrum_model_is_cu_dev(const struct gkyl_emission_spectrum_model *model) +bool gkyl_emission_spectrum_model_is_cu_dev(const struct gkyl_emission_spectrum_model *model) { return GKYL_IS_CU_ALLOC(model->flags); } -struct gkyl_emission_spectrum_model* -gkyl_emission_spectrum_model_acquire(const struct gkyl_emission_spectrum_model* spectrum) +struct gkyl_emission_spectrum_model * +gkyl_emission_spectrum_model_acquire(const struct gkyl_emission_spectrum_model *spectrum) { gkyl_ref_count_inc(&spectrum->ref_count); - return (struct gkyl_emission_spectrum_model*) spectrum; + return (struct gkyl_emission_spectrum_model *)spectrum; } -void -gkyl_emission_spectrum_model_release(const struct gkyl_emission_spectrum_model* spectrum) +void gkyl_emission_spectrum_model_release(const struct gkyl_emission_spectrum_model *spectrum) { gkyl_ref_count_dec(&spectrum->ref_count); } diff --git a/vlasov/zero/emission_spectrum_model_cu.cu b/vlasov/zero/emission_spectrum_model_cu.cu index 486b367562..0c97e20ecd 100644 --- a/vlasov/zero/emission_spectrum_model_cu.cu +++ b/vlasov/zero/emission_spectrum_model_cu.cu @@ -3,10 +3,10 @@ extern "C" { #include #include -#include +#include } -#include +#include __global__ static void chung_everhart_set_cu_dev_ptrs(struct gkyl_emission_spectrum_chung_everhart *model) @@ -14,69 +14,71 @@ chung_everhart_set_cu_dev_ptrs(struct gkyl_emission_spectrum_chung_everhart *mod model->spectrum.normalization = gkyl_emission_spectrum_chung_everhart_norm; } -__global__ static void -gaussian_set_cu_dev_ptrs(struct gkyl_emission_spectrum_gaussian *model) +__global__ static void gaussian_set_cu_dev_ptrs(struct gkyl_emission_spectrum_gaussian *model) { model->spectrum.normalization = gkyl_emission_spectrum_gaussian_norm; } -__global__ static void -maxwellian_set_cu_dev_ptrs(struct gkyl_emission_spectrum_maxwellian *model) +__global__ static void maxwellian_set_cu_dev_ptrs(struct gkyl_emission_spectrum_maxwellian *model) { model->spectrum.normalization = gkyl_emission_spectrum_maxwellian_norm; } -struct gkyl_emission_spectrum_model* -gkyl_emission_spectrum_chung_everhart_cu_dev_new(struct gkyl_emission_spectrum_chung_everhart *model, - double charge, double phi) +struct gkyl_emission_spectrum_model *gkyl_emission_spectrum_chung_everhart_cu_dev_new( + struct gkyl_emission_spectrum_chung_everhart *model, double charge, double phi +) { struct gkyl_emission_spectrum_chung_everhart *model_cu = - (struct gkyl_emission_spectrum_chung_everhart*) - gkyl_cu_malloc(sizeof(struct gkyl_emission_spectrum_chung_everhart)); + (struct gkyl_emission_spectrum_chung_everhart *)gkyl_cu_malloc( + sizeof(struct gkyl_emission_spectrum_chung_everhart) + ); model->spectrum.flags = 0; GKYL_SET_CU_ALLOC(model->spectrum.flags); - gkyl_cu_memcpy(model_cu, model, sizeof(struct gkyl_emission_spectrum_chung_everhart), - GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + model_cu, model, sizeof(struct gkyl_emission_spectrum_chung_everhart), GKYL_CU_MEMCPY_H2D + ); - chung_everhart_set_cu_dev_ptrs<<<1,1>>>(model_cu); + chung_everhart_set_cu_dev_ptrs<<<1, 1> > >(model_cu); return &model_cu->spectrum; } -struct gkyl_emission_spectrum_model* -gkyl_emission_spectrum_gaussian_cu_dev_new(struct gkyl_emission_spectrum_gaussian *model, - double charge, double E_0, double tau) +struct gkyl_emission_spectrum_model *gkyl_emission_spectrum_gaussian_cu_dev_new( + struct gkyl_emission_spectrum_gaussian *model, double charge, double E_0, double tau +) { - struct gkyl_emission_spectrum_gaussian *model_cu = (struct gkyl_emission_spectrum_gaussian*) + struct gkyl_emission_spectrum_gaussian *model_cu = (struct gkyl_emission_spectrum_gaussian *) gkyl_cu_malloc(sizeof(struct gkyl_emission_spectrum_gaussian)); model->spectrum.flags = 0; GKYL_SET_CU_ALLOC(model->spectrum.flags); - gkyl_cu_memcpy(model_cu, model, sizeof(struct gkyl_emission_spectrum_gaussian), - GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + model_cu, model, sizeof(struct gkyl_emission_spectrum_gaussian), GKYL_CU_MEMCPY_H2D + ); - gaussian_set_cu_dev_ptrs<<<1,1>>>(model_cu); + gaussian_set_cu_dev_ptrs<<<1, 1> > >(model_cu); return &model_cu->spectrum; } -struct gkyl_emission_spectrum_model* -gkyl_emission_spectrum_maxwellian_cu_dev_new(struct gkyl_emission_spectrum_maxwellian *model, - double charge, double vt) +struct gkyl_emission_spectrum_model *gkyl_emission_spectrum_maxwellian_cu_dev_new( + struct gkyl_emission_spectrum_maxwellian *model, double charge, double vt +) { - struct gkyl_emission_spectrum_maxwellian *model_cu = (struct gkyl_emission_spectrum_maxwellian*) + struct gkyl_emission_spectrum_maxwellian *model_cu = (struct gkyl_emission_spectrum_maxwellian *) gkyl_cu_malloc(sizeof(struct gkyl_emission_spectrum_maxwellian)); model->spectrum.flags = 0; GKYL_SET_CU_ALLOC(model->spectrum.flags); - gkyl_cu_memcpy(model_cu, model, sizeof(struct gkyl_emission_spectrum_maxwellian), - GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + model_cu, model, sizeof(struct gkyl_emission_spectrum_maxwellian), GKYL_CU_MEMCPY_H2D + ); - maxwellian_set_cu_dev_ptrs<<<1,1>>>(model_cu); + maxwellian_set_cu_dev_ptrs<<<1, 1> > >(model_cu); return &model_cu->spectrum; } diff --git a/vlasov/zero/emission_yield_model.c b/vlasov/zero/emission_yield_model.c index deb6d2dccc..75cb580260 100644 --- a/vlasov/zero/emission_yield_model.c +++ b/vlasov/zero/emission_yield_model.c @@ -3,19 +3,21 @@ #include #include -struct gkyl_emission_yield_model* -gkyl_emission_yield_furman_pivi_new(double charge, double deltahat_ts, double Ehat_ts, double t1, - double t2, double t3, double t4, double s, bool use_gpu) +struct gkyl_emission_yield_model *gkyl_emission_yield_furman_pivi_new( + double charge, double deltahat_ts, double Ehat_ts, double t1, double t2, double t3, double t4, + double s, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { - return gkyl_emission_yield_furman_pivi_cu_dev_new(charge, deltahat_ts, Ehat_ts, - t1, t2, t3, t4, s); + if (use_gpu) { + return gkyl_emission_yield_furman_pivi_cu_dev_new( + charge, deltahat_ts, Ehat_ts, t1, t2, t3, t4, s + ); } #endif struct gkyl_emission_yield_furman_pivi *model = gkyl_malloc(sizeof(struct gkyl_emission_yield_furman_pivi)); - + model->deltahat_ts = deltahat_ts; model->Ehat_ts = Ehat_ts; model->t1 = t1; @@ -33,17 +35,18 @@ gkyl_emission_yield_furman_pivi_new(double charge, double deltahat_ts, double Eh return &model->yield; } -struct gkyl_emission_yield_model* -gkyl_emission_yield_schou_new(double charge, double int_wall, double a2, double a3, double a4, - double a5, double nw, bool use_gpu) +struct gkyl_emission_yield_model *gkyl_emission_yield_schou_new( + double charge, double int_wall, double a2, double a3, double a4, double a5, double nw, + bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_emission_yield_schou_cu_dev_new(charge, int_wall, a2, a3, a4, a5, nw); } #endif struct gkyl_emission_yield_schou *model = gkyl_malloc(sizeof(struct gkyl_emission_yield_schou)); - + model->int_wall = int_wall; model->a2 = a2; model->a3 = a3; @@ -60,18 +63,21 @@ gkyl_emission_yield_schou_new(double charge, double int_wall, double a2, double return &model->yield; } -struct gkyl_emission_yield_model* -gkyl_emission_yield_schou_srim_new(double charge, double int_wall, double lorentz_norm, double E0, - double tau, double alpha, double beta, double gauss_norm, double gauss_E0, double gauss_tau, bool use_gpu) +struct gkyl_emission_yield_model *gkyl_emission_yield_schou_srim_new( + double charge, double int_wall, double lorentz_norm, double E0, double tau, double alpha, + double beta, double gauss_norm, double gauss_E0, double gauss_tau, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { - return gkyl_emission_yield_schou_srim_cu_dev_new(charge, int_wall, lorentz_norm, E0, tau, alpha, beta, - gauss_norm, gauss_E0, gauss_tau); + if (use_gpu) { + return gkyl_emission_yield_schou_srim_cu_dev_new( + charge, int_wall, lorentz_norm, E0, tau, alpha, beta, gauss_norm, gauss_E0, gauss_tau + ); } #endif - struct gkyl_emission_yield_schou_srim *model = gkyl_malloc(sizeof(struct gkyl_emission_yield_schou_srim)); - + struct gkyl_emission_yield_schou_srim *model = + gkyl_malloc(sizeof(struct gkyl_emission_yield_schou_srim)); + model->int_wall = int_wall; model->lorentz_norm = lorentz_norm; model->E0 = E0; @@ -91,17 +97,17 @@ gkyl_emission_yield_schou_srim_new(double charge, double int_wall, double lorent return &model->yield; } -struct gkyl_emission_yield_model* +struct gkyl_emission_yield_model * gkyl_emission_yield_constant_new(double charge, double delta, bool use_gpu) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_emission_yield_constant_cu_dev_new(charge, delta); } #endif struct gkyl_emission_yield_constant *model = gkyl_malloc(sizeof(struct gkyl_emission_yield_constant)); - + model->delta = delta; model->yield.charge = charge; model->yield.function = gkyl_emission_yield_constant_yield; @@ -113,21 +119,19 @@ gkyl_emission_yield_constant_new(double charge, double delta, bool use_gpu) return &model->yield; } -bool -gkyl_emission_yield_model_is_cu_dev(const struct gkyl_emission_yield_model *model) +bool gkyl_emission_yield_model_is_cu_dev(const struct gkyl_emission_yield_model *model) { return GKYL_IS_CU_ALLOC(model->flags); } -struct gkyl_emission_yield_model* -gkyl_emission_yield_model_acquire(const struct gkyl_emission_yield_model* model) +struct gkyl_emission_yield_model * +gkyl_emission_yield_model_acquire(const struct gkyl_emission_yield_model *model) { gkyl_ref_count_inc(&model->ref_count); - return (struct gkyl_emission_yield_model*) model; + return (struct gkyl_emission_yield_model *)model; } -void -gkyl_emission_yield_model_release(const struct gkyl_emission_yield_model* model) +void gkyl_emission_yield_model_release(const struct gkyl_emission_yield_model *model) { gkyl_ref_count_dec(&model->ref_count); } diff --git a/vlasov/zero/emission_yield_model_cu.cu b/vlasov/zero/emission_yield_model_cu.cu index 490b0bc90d..8e91fbaae4 100644 --- a/vlasov/zero/emission_yield_model_cu.cu +++ b/vlasov/zero/emission_yield_model_cu.cu @@ -3,40 +3,37 @@ extern "C" { #include #include -#include +#include } -#include +#include -__global__ static void -furman_pivi_set_cu_dev_ptrs(struct gkyl_emission_yield_furman_pivi *model) +__global__ static void furman_pivi_set_cu_dev_ptrs(struct gkyl_emission_yield_furman_pivi *model) { model->yield.function = gkyl_emission_yield_furman_pivi_yield; } -__global__ static void -schou_set_cu_dev_ptrs(struct gkyl_emission_yield_schou *model) +__global__ static void schou_set_cu_dev_ptrs(struct gkyl_emission_yield_schou *model) { model->yield.function = gkyl_emission_yield_schou_yield; } -__global__ static void -schou_srim_set_cu_dev_ptrs(struct gkyl_emission_yield_schou_srim *model) +__global__ static void schou_srim_set_cu_dev_ptrs(struct gkyl_emission_yield_schou_srim *model) { model->yield.function = gkyl_emission_yield_schou_srim_yield; } -__global__ static void -constant_set_cu_dev_ptrs(struct gkyl_emission_yield_constant *model) +__global__ static void constant_set_cu_dev_ptrs(struct gkyl_emission_yield_constant *model) { model->yield.function = gkyl_emission_yield_constant_yield; } -struct gkyl_emission_yield_model* -gkyl_emission_yield_furman_pivi_cu_dev_new(double charge, double deltahat_ts, double Ehat_ts, - double t1, double t2, double t3, double t4, double s) +struct gkyl_emission_yield_model *gkyl_emission_yield_furman_pivi_cu_dev_new( + double charge, double deltahat_ts, double Ehat_ts, double t1, double t2, double t3, double t4, + double s +) { - struct gkyl_emission_yield_furman_pivi *model = (struct gkyl_emission_yield_furman_pivi*) + struct gkyl_emission_yield_furman_pivi *model = (struct gkyl_emission_yield_furman_pivi *) gkyl_malloc(sizeof(struct gkyl_emission_yield_furman_pivi)); model->deltahat_ts = deltahat_ts; @@ -52,24 +49,25 @@ gkyl_emission_yield_furman_pivi_cu_dev_new(double charge, double deltahat_ts, do GKYL_SET_CU_ALLOC(model->yield.flags); model->yield.ref_count = gkyl_ref_count_init(gkyl_emission_yield_furman_pivi_free); - struct gkyl_emission_yield_furman_pivi *model_cu = (struct gkyl_emission_yield_furman_pivi*) + struct gkyl_emission_yield_furman_pivi *model_cu = (struct gkyl_emission_yield_furman_pivi *) gkyl_cu_malloc(sizeof(struct gkyl_emission_yield_furman_pivi)); - gkyl_cu_memcpy(model_cu, model, sizeof(struct gkyl_emission_yield_furman_pivi), - GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + model_cu, model, sizeof(struct gkyl_emission_yield_furman_pivi), GKYL_CU_MEMCPY_H2D + ); - furman_pivi_set_cu_dev_ptrs<<<1,1>>>(model_cu); + furman_pivi_set_cu_dev_ptrs<<<1, 1> > >(model_cu); model->yield.on_dev = &model_cu->yield; return &model->yield; } -struct gkyl_emission_yield_model* -gkyl_emission_yield_schou_cu_dev_new(double charge, double int_wall, double a2, double a3, - double a4, double a5, double nw) +struct gkyl_emission_yield_model *gkyl_emission_yield_schou_cu_dev_new( + double charge, double int_wall, double a2, double a3, double a4, double a5, double nw +) { - struct gkyl_emission_yield_schou *model = (struct gkyl_emission_yield_schou*) - gkyl_malloc(sizeof(struct gkyl_emission_yield_schou)); + struct gkyl_emission_yield_schou *model = + (struct gkyl_emission_yield_schou *)gkyl_malloc(sizeof(struct gkyl_emission_yield_schou)); model->int_wall = int_wall; model->a2 = a2; @@ -83,22 +81,23 @@ gkyl_emission_yield_schou_cu_dev_new(double charge, double int_wall, double a2, GKYL_SET_CU_ALLOC(model->yield.flags); model->yield.ref_count = gkyl_ref_count_init(gkyl_emission_yield_schou_free); - struct gkyl_emission_yield_schou *model_cu = (struct gkyl_emission_yield_schou*) - gkyl_cu_malloc(sizeof(struct gkyl_emission_yield_schou)); + struct gkyl_emission_yield_schou *model_cu = + (struct gkyl_emission_yield_schou *)gkyl_cu_malloc(sizeof(struct gkyl_emission_yield_schou)); gkyl_cu_memcpy(model_cu, model, sizeof(struct gkyl_emission_yield_schou), GKYL_CU_MEMCPY_H2D); - schou_set_cu_dev_ptrs<<<1,1>>>(model_cu); + schou_set_cu_dev_ptrs<<<1, 1> > >(model_cu); model->yield.on_dev = &model_cu->yield; return &model->yield; } -struct gkyl_emission_yield_model* -gkyl_emission_yield_schou_srim_cu_dev_new(double charge, double int_wall, double lorentz_norm, double E0, double tau, - double alpha, double beta, double gauss_norm, double gauss_E0, double gauss_tau) +struct gkyl_emission_yield_model *gkyl_emission_yield_schou_srim_cu_dev_new( + double charge, double int_wall, double lorentz_norm, double E0, double tau, double alpha, + double beta, double gauss_norm, double gauss_E0, double gauss_tau +) { - struct gkyl_emission_yield_schou_srim *model = (struct gkyl_emission_yield_schou_srim*) + struct gkyl_emission_yield_schou_srim *model = (struct gkyl_emission_yield_schou_srim *) gkyl_malloc(sizeof(struct gkyl_emission_yield_schou_srim)); model->int_wall = int_wall; @@ -116,22 +115,22 @@ gkyl_emission_yield_schou_srim_cu_dev_new(double charge, double int_wall, double GKYL_SET_CU_ALLOC(model->yield.flags); model->yield.ref_count = gkyl_ref_count_init(gkyl_emission_yield_schou_srim_free); - struct gkyl_emission_yield_schou_srim *model_cu = (struct gkyl_emission_yield_schou_srim*) + struct gkyl_emission_yield_schou_srim *model_cu = (struct gkyl_emission_yield_schou_srim *) gkyl_cu_malloc(sizeof(struct gkyl_emission_yield_schou_srim)); gkyl_cu_memcpy(model_cu, model, sizeof(struct gkyl_emission_yield_schou_srim), GKYL_CU_MEMCPY_H2D); - schou_srim_set_cu_dev_ptrs<<<1,1>>>(model_cu); + schou_srim_set_cu_dev_ptrs<<<1, 1> > >(model_cu); model->yield.on_dev = &model_cu->yield; return &model->yield; } -struct gkyl_emission_yield_model* +struct gkyl_emission_yield_model * gkyl_emission_yield_constant_cu_dev_new(double charge, double delta) { - struct gkyl_emission_yield_constant *model = (struct gkyl_emission_yield_constant*) - gkyl_malloc(sizeof(struct gkyl_emission_yield_constant)); + struct gkyl_emission_yield_constant *model = + (struct gkyl_emission_yield_constant *)gkyl_malloc(sizeof(struct gkyl_emission_yield_constant)); model->delta = delta; model->yield.charge = charge; @@ -140,11 +139,12 @@ gkyl_emission_yield_constant_cu_dev_new(double charge, double delta) GKYL_SET_CU_ALLOC(model->yield.flags); model->yield.ref_count = gkyl_ref_count_init(gkyl_emission_yield_constant_free); - struct gkyl_emission_yield_constant *model_cu = (struct gkyl_emission_yield_constant*) - gkyl_cu_malloc(sizeof(struct gkyl_emission_yield_constant)); + struct gkyl_emission_yield_constant *model_cu = + (struct gkyl_emission_yield_constant *)gkyl_cu_malloc(sizeof(struct gkyl_emission_yield_constant + )); gkyl_cu_memcpy(model_cu, model, sizeof(struct gkyl_emission_yield_constant), GKYL_CU_MEMCPY_H2D); - constant_set_cu_dev_ptrs<<<1,1>>>(model_cu); + constant_set_cu_dev_ptrs<<<1, 1> > >(model_cu); model->yield.on_dev = &model_cu->yield; diff --git a/vlasov/zero/ghost_surf_calc.c b/vlasov/zero/ghost_surf_calc.c index da84024e05..3b1a9056b9 100644 --- a/vlasov/zero/ghost_surf_calc.c +++ b/vlasov/zero/ghost_surf_calc.c @@ -9,10 +9,10 @@ #include #include -void -gkyl_ghost_surf_calc_advance(gkyl_ghost_surf_calc *gcalc, - const struct gkyl_range *phase_rng, - const struct gkyl_array *fIn, struct gkyl_array *rhs) +void gkyl_ghost_surf_calc_advance( + gkyl_ghost_surf_calc *gcalc, const struct gkyl_range *phase_rng, const struct gkyl_array *fIn, + struct gkyl_array *rhs +) { // Ghost and skin index and cell center coordinates. int idxg[GKYL_MAX_DIM], idxs[GKYL_MAX_DIM]; @@ -20,15 +20,15 @@ gkyl_ghost_surf_calc_advance(gkyl_ghost_surf_calc *gcalc, struct gkyl_range edge_rng; struct gkyl_range_iter edge_iter; - - int clower_idx[GKYL_MAX_DIM], cupper_idx[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim; ++d) { + int clower_idx[GKYL_MAX_DIM], cupper_idx[GKYL_MAX_DIM] = {0}; + + for (int d = 0; d < phase_rng->ndim; ++d) { clower_idx[d] = phase_rng->lower[d]; cupper_idx[d] = phase_rng->upper[d]; } - for (int dir=0; dircdim; ++dir) { + for (int dir = 0; dir < gcalc->cdim; ++dir) { // Ghost surf at lower boundary. clower_idx[dir] = phase_rng->lower[dir]; cupper_idx[dir] = phase_rng->lower[dir]; @@ -43,12 +43,12 @@ gkyl_ghost_surf_calc_advance(gkyl_ghost_surf_calc *gcalc, gkyl_rect_grid_cell_center(&gcalc->grid, idxg, xcg); gkyl_rect_grid_cell_center(&gcalc->grid, idxs, xcs); - long ling = gkyl_range_idx(&edge_rng, idxg); + long ling = gkyl_range_idx(&edge_rng, idxg); long lins = gkyl_range_idx(&edge_rng, idxs); - gcalc->equation->boundary_surf_term(gcalc->equation, dir, xcs, xcg, - gcalc->grid.dx, gcalc->grid.dx, idxs, idxg, -1, - gkyl_array_cfetch(fIn, lins), gkyl_array_cfetch(fIn, ling), gkyl_array_fetch(rhs, ling) + gcalc->equation->boundary_surf_term( + gcalc->equation, dir, xcs, xcg, gcalc->grid.dx, gcalc->grid.dx, idxs, idxg, -1, + gkyl_array_cfetch(fIn, lins), gkyl_array_cfetch(fIn, ling), gkyl_array_fetch(rhs, ling) ); } @@ -69,9 +69,9 @@ gkyl_ghost_surf_calc_advance(gkyl_ghost_surf_calc *gcalc, long lins = gkyl_range_idx(&edge_rng, idxs); long ling = gkyl_range_idx(&edge_rng, idxg); - gcalc->equation->boundary_surf_term(gcalc->equation, dir, xcs, xcg, - gcalc->grid.dx, gcalc->grid.dx, idxs, idxg, 1, - gkyl_array_cfetch(fIn, lins), gkyl_array_cfetch(fIn, ling), gkyl_array_fetch(rhs, ling) + gcalc->equation->boundary_surf_term( + gcalc->equation, dir, xcs, xcg, gcalc->grid.dx, gcalc->grid.dx, idxs, idxg, 1, + gkyl_array_cfetch(fIn, lins), gkyl_array_cfetch(fIn, ling), gkyl_array_fetch(rhs, ling) ); } @@ -81,50 +81,50 @@ gkyl_ghost_surf_calc_advance(gkyl_ghost_surf_calc *gcalc, } } -gkyl_ghost_surf_calc* -gkyl_ghost_surf_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_dg_eqn *equation, int cdim, bool use_gpu) +gkyl_ghost_surf_calc *gkyl_ghost_surf_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_dg_eqn *equation, int cdim, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_ghost_surf_calc_cu_dev_new(grid, equation, cdim); - } + } #endif gkyl_ghost_surf_calc *up = gkyl_malloc(sizeof(gkyl_ghost_surf_calc)); up->grid = *grid; up->equation = gkyl_dg_eqn_acquire(equation); up->cdim = cdim; - + up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); - + up->on_dev = up; - + return up; } -void -gkyl_ghost_surf_calc_release(gkyl_ghost_surf_calc* up) +void gkyl_ghost_surf_calc_release(gkyl_ghost_surf_calc *up) { gkyl_dg_eqn_release(up->equation); - if (GKYL_IS_CU_ALLOC(up->flags)) + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } #ifndef GKYL_HAVE_CUDA -void -gkyl_ghost_surf_calc_advance_cu(gkyl_ghost_surf_calc *gcalc, - const struct gkyl_range *phase_rng, - const struct gkyl_array *fIn, struct gkyl_array *rhs) +void gkyl_ghost_surf_calc_advance_cu( + gkyl_ghost_surf_calc *gcalc, const struct gkyl_range *phase_rng, const struct gkyl_array *fIn, + struct gkyl_array *rhs +) { assert(false); } -gkyl_ghost_surf_calc* -gkyl_ghost_surf_calc_cu_dev_new(const struct gkyl_rect_grid *grid, - const struct gkyl_dg_eqn *equation, int cdim) +gkyl_ghost_surf_calc *gkyl_ghost_surf_calc_cu_dev_new( + const struct gkyl_rect_grid *grid, const struct gkyl_dg_eqn *equation, int cdim +) { assert(false); } diff --git a/vlasov/zero/ghost_surf_calc_cu.cu b/vlasov/zero/ghost_surf_calc_cu.cu index 5425e0285e..f12e4fd17d 100644 --- a/vlasov/zero/ghost_surf_calc_cu.cu +++ b/vlasov/zero/ghost_surf_calc_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include #include #include @@ -13,16 +13,16 @@ extern "C" { #include } -__global__ static void -gkyl_ghost_surf_calc_advance_cu_ker(const struct gkyl_ghost_surf_calc *gcalc, - int dir, int edge, struct gkyl_range edge_rng, - const struct gkyl_array* fIn, struct gkyl_array* rhs) +__global__ static void gkyl_ghost_surf_calc_advance_cu_ker( + const struct gkyl_ghost_surf_calc *gcalc, int dir, int edge, struct gkyl_range edge_rng, + const struct gkyl_array *fIn, struct gkyl_array *rhs +) { double xcg[GKYL_MAX_DIM], xcs[GKYL_MAX_DIM]; int idxg[GKYL_MAX_DIM], idxs[GKYL_MAX_DIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < edge_rng.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < edge_rng.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&edge_rng, tid, idxg); gkyl_copy_int_arr(edge_rng.ndim, idxg, idxs); idxs[dir] -= edge; @@ -33,31 +33,31 @@ gkyl_ghost_surf_calc_advance_cu_ker(const struct gkyl_ghost_surf_calc *gcalc, long lincg = gkyl_range_idx(&edge_rng, idxg); long lincs = gkyl_range_idx(&edge_rng, idxs); - const double* fgptr = (const double*) gkyl_array_cfetch(fIn, lincg); - const double* fsptr = (const double*) gkyl_array_cfetch(fIn, lincs); - - gcalc->equation->boundary_surf_term(gcalc->equation, - dir, xcs, xcg, gcalc->grid.dx, gcalc->grid.dx, idxs, idxg, - edge, fsptr, fgptr, (double*) gkyl_array_fetch(rhs, lincg) + const double *fgptr = (const double *)gkyl_array_cfetch(fIn, lincg); + const double *fsptr = (const double *)gkyl_array_cfetch(fIn, lincs); + + gcalc->equation->boundary_surf_term( + gcalc->equation, dir, xcs, xcg, gcalc->grid.dx, gcalc->grid.dx, idxs, idxg, edge, fsptr, + fgptr, (double *)gkyl_array_fetch(rhs, lincg) ); } } -void -gkyl_ghost_surf_calc_advance_cu(struct gkyl_ghost_surf_calc *gcalc, - const struct gkyl_range *phase_rng, - const struct gkyl_array *fIn, struct gkyl_array *rhs) +void gkyl_ghost_surf_calc_advance_cu( + struct gkyl_ghost_surf_calc *gcalc, const struct gkyl_range *phase_rng, + const struct gkyl_array *fIn, struct gkyl_array *rhs +) { struct gkyl_range edge_rng; int nblocks, nthreads; int edge; - int clower_idx[GKYL_MAX_DIM], cupper_idx[GKYL_MAX_DIM] = { 0 }; - for (int dim=0; dimndim; ++dim) { + int clower_idx[GKYL_MAX_DIM], cupper_idx[GKYL_MAX_DIM] = {0}; + for (int dim = 0; dim < phase_rng->ndim; ++dim) { clower_idx[dim] = phase_rng->lower[dim]; cupper_idx[dim] = phase_rng->upper[dim]; } - - for(int dir=0; dircdim; ++dir) { + + for (int dir = 0; dir < gcalc->cdim; ++dir) { edge = -1; clower_idx[dir] = phase_rng->lower[dir]; cupper_idx[dir] = phase_rng->lower[dir]; @@ -65,8 +65,9 @@ gkyl_ghost_surf_calc_advance_cu(struct gkyl_ghost_surf_calc *gcalc, nblocks = edge_rng.nblocks; nthreads = edge_rng.nthreads; - gkyl_ghost_surf_calc_advance_cu_ker<<>>(gcalc->on_dev, dir, - edge, edge_rng, fIn->on_dev, rhs->on_dev); + gkyl_ghost_surf_calc_advance_cu_ker<< > >( + gcalc->on_dev, dir, edge, edge_rng, fIn->on_dev, rhs->on_dev + ); edge = 1; clower_idx[dir] = phase_rng->upper[dir]; @@ -75,8 +76,9 @@ gkyl_ghost_surf_calc_advance_cu(struct gkyl_ghost_surf_calc *gcalc, nblocks = edge_rng.nblocks; nthreads = edge_rng.nthreads; - gkyl_ghost_surf_calc_advance_cu_ker<<>>(gcalc->on_dev, dir, - edge, edge_rng, fIn->on_dev, rhs->on_dev); + gkyl_ghost_surf_calc_advance_cu_ker<< > >( + gcalc->on_dev, dir, edge, edge_rng, fIn->on_dev, rhs->on_dev + ); // Reset indices for loop over each velocity dimension clower_idx[dir] = phase_rng->lower[dir]; @@ -84,25 +86,27 @@ gkyl_ghost_surf_calc_advance_cu(struct gkyl_ghost_surf_calc *gcalc, } } -struct gkyl_ghost_surf_calc* -gkyl_ghost_surf_calc_cu_dev_new(const struct gkyl_rect_grid *grid, - const struct gkyl_dg_eqn *equation, int cdim) +struct gkyl_ghost_surf_calc *gkyl_ghost_surf_calc_cu_dev_new( + const struct gkyl_rect_grid *grid, const struct gkyl_dg_eqn *equation, int cdim +) { - struct gkyl_ghost_surf_calc *up = (struct gkyl_ghost_surf_calc*) gkyl_malloc(sizeof(struct gkyl_ghost_surf_calc)); + struct gkyl_ghost_surf_calc *up = + (struct gkyl_ghost_surf_calc *)gkyl_malloc(sizeof(struct gkyl_ghost_surf_calc)); up->grid = *grid; up->cdim = cdim; - + struct gkyl_dg_eqn *eqn = gkyl_dg_eqn_acquire(equation); up->equation = eqn->on_dev; - + up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - struct gkyl_ghost_surf_calc *up_cu = (struct gkyl_ghost_surf_calc*) gkyl_cu_malloc(sizeof(struct gkyl_ghost_surf_calc)); + struct gkyl_ghost_surf_calc *up_cu = + (struct gkyl_ghost_surf_calc *)gkyl_cu_malloc(sizeof(struct gkyl_ghost_surf_calc)); gkyl_cu_memcpy(up_cu, up, sizeof(struct gkyl_ghost_surf_calc), GKYL_CU_MEMCPY_H2D); up->on_dev = up_cu; - + up->equation = eqn; - + return up; } diff --git a/vlasov/zero/gkyl_bc_basic.h b/vlasov/zero/gkyl_bc_basic.h index 5b05a8e5fc..7ab661bec6 100644 --- a/vlasov/zero/gkyl_bc_basic.h +++ b/vlasov/zero/gkyl_bc_basic.h @@ -5,21 +5,21 @@ #include // BC types in this updater. -enum gkyl_bc_basic_type { - GKYL_BC_COPY = 0, - GKYL_BC_ABSORB, - GKYL_BC_REFLECT, - GKYL_BC_DISTF_REFLECT, - GKYL_BC_MAXWELL_PEC, - GKYL_BC_MAXWELL_SYM, - GKYL_BC_MAXWELL_RESERVOIR, +enum gkyl_bc_basic_type { + GKYL_BC_COPY = 0, + GKYL_BC_ABSORB, + GKYL_BC_REFLECT, + GKYL_BC_DISTF_REFLECT, + GKYL_BC_MAXWELL_PEC, + GKYL_BC_MAXWELL_SYM, + GKYL_BC_MAXWELL_RESERVOIR, GKYL_BC_FIXED_FUNC, GKYL_BC_PKPM_SPECIES_REFLECT, - GKYL_BC_PKPM_MOM_REFLECT, + GKYL_BC_PKPM_MOM_REFLECT, GKYL_BC_PKPM_MOM_NO_SLIP, - GKYL_BC_EULER_REFLECT, + GKYL_BC_EULER_REFLECT, GKYL_BC_EULER_NO_SLIP, - GKYL_BC_CONF_BOUNDARY_VALUE, + GKYL_BC_CONF_BOUNDARY_VALUE }; // Object type @@ -42,9 +42,11 @@ typedef struct gkyl_bc_basic gkyl_bc_basic; * @param use_gpu Boolean to indicate whether to use the GPU. * @return New updater pointer. */ -struct gkyl_bc_basic* gkyl_bc_basic_new(int dir, enum gkyl_edge_loc edge, enum gkyl_bc_basic_type bctype, - const struct gkyl_basis *basis, const struct gkyl_range *skin_r, - const struct gkyl_range *ghost_r, int num_comp, int cdim, bool use_gpu); +struct gkyl_bc_basic *gkyl_bc_basic_new( + int dir, enum gkyl_edge_loc edge, enum gkyl_bc_basic_type bctype, const struct gkyl_basis *basis, + const struct gkyl_range *skin_r, const struct gkyl_range *ghost_r, int num_comp, int cdim, + bool use_gpu +); /** * Advance boundary conditions *in special case where buffer is fixed in time*. @@ -55,7 +57,9 @@ struct gkyl_bc_basic* gkyl_bc_basic_new(int dir, enum gkyl_edge_loc edge, enum g * @param buff_arr Buffer array, big enough for ghost cells at this boundary. * @param f_arr Field array to apply BC to. */ -void gkyl_bc_basic_buffer_fixed_func(const struct gkyl_bc_basic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr); +void gkyl_bc_basic_buffer_fixed_func( + const struct gkyl_bc_basic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr +); /** * Advance boundary conditions. Fill buffer array based on boundary conditions and copy @@ -65,7 +69,9 @@ void gkyl_bc_basic_buffer_fixed_func(const struct gkyl_bc_basic *up, struct gkyl * @param buff_arr Buffer array, big enough for ghost cells at this boundary. * @param f_arr Field array to apply BC to. */ -void gkyl_bc_basic_advance(const struct gkyl_bc_basic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr); +void gkyl_bc_basic_advance( + const struct gkyl_bc_basic *up, struct gkyl_array *buff_arr, struct gkyl_array *f_arr +); /** * Free memory associated with bc_basic updater. diff --git a/vlasov/zero/gkyl_bc_basic_priv.h b/vlasov/zero/gkyl_bc_basic_priv.h index 12f872680e..aefac15c53 100644 --- a/vlasov/zero/gkyl_bc_basic_priv.h +++ b/vlasov/zero/gkyl_bc_basic_priv.h @@ -31,9 +31,10 @@ struct gkyl_bc_basic { * @param num_comp Number of components (DOFs) within a cell. * @return Pointer to array_copy_func which can be passed to array_copy_fn methods. */ -struct gkyl_array_copy_func* gkyl_bc_basic_create_arr_copy_func_cu(int dir, - enum gkyl_edge_loc edge, int cdim, enum gkyl_bc_basic_type bctype, - const struct gkyl_basis *basis, int num_comp); +struct gkyl_array_copy_func *gkyl_bc_basic_create_arr_copy_func_cu( + int dir, enum gkyl_edge_loc edge, int cdim, enum gkyl_bc_basic_type bctype, + const struct gkyl_basis *basis, int num_comp +); #endif @@ -46,138 +47,121 @@ struct dg_bc_ctx { const struct gkyl_basis *basis; // basis function. }; -GKYL_CU_D -static void -copy_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void copy_bc(size_t nc, double *out, const double *inp, void *ctx) { - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int num_comp = mc->ncomp; - for (int c=0; cdir; mc->basis->flip_odd_sign(dir, inp, out); } -GKYL_CU_D -static void -species_absorb_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void species_absorb_bc(size_t nc, double *out, const double *inp, void *ctx) { - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int num_comp = mc->ncomp; - for (int c=0; cdir, cdim = mc->cdim; mc->basis->flip_odd_sign(dir, inp, out); - mc->basis->flip_odd_sign(dir+cdim, out, out); + mc->basis->flip_odd_sign(dir + cdim, out, out); } -GKYL_CU_D -static void -conf_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void conf_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) { - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int dir = mc->dir; int cdim = mc->cdim; enum gkyl_edge_loc edge = mc->edge; if (cdim == 1) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-sqrt(3.0)*inp[1]; - } - else { - out[0] = inp[0]+sqrt(3.0)*inp[1]; + out[0] = inp[0] - sqrt(3.0) * inp[1]; + } else { + out[0] = inp[0] + sqrt(3.0) * inp[1]; } out[1] = 0.0; - } - else if (cdim == 2) { + } else if (cdim == 2) { if (dir == 0) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-sqrt(3.0)*inp[1]; - out[2] = inp[2]-sqrt(3.0)*inp[3]; - } - else { - out[0] = inp[0]+sqrt(3.0)*inp[1]; - out[2] = inp[2]+sqrt(3.0)*inp[3]; + out[0] = inp[0] - sqrt(3.0) * inp[1]; + out[2] = inp[2] - sqrt(3.0) * inp[3]; + } else { + out[0] = inp[0] + sqrt(3.0) * inp[1]; + out[2] = inp[2] + sqrt(3.0) * inp[3]; } out[1] = 0.0; out[3] = 0.0; - } - else if (dir == 1) { + } else if (dir == 1) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-sqrt(3.0)*inp[2]; - out[1] = inp[1]-sqrt(3.0)*inp[3]; - } - else { - out[0] = inp[0]+sqrt(3.0)*inp[2]; - out[1] = inp[1]+sqrt(3.0)*inp[3]; + out[0] = inp[0] - sqrt(3.0) * inp[2]; + out[1] = inp[1] - sqrt(3.0) * inp[3]; + } else { + out[0] = inp[0] + sqrt(3.0) * inp[2]; + out[1] = inp[1] + sqrt(3.0) * inp[3]; } out[2] = 0.0; out[3] = 0.0; } - } - else if (cdim == 3) { + } else if (cdim == 3) { if (dir == 0) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-sqrt(3.0)*inp[1]; - out[2] = inp[2]-sqrt(3.0)*inp[4]; - out[3] = inp[3]-sqrt(3.0)*inp[5]; - out[6] = inp[6]-sqrt(3.0)*inp[7]; - } - else { - out[0] = inp[0]+sqrt(3.0)*inp[1]; - out[2] = inp[2]+sqrt(3.0)*inp[4]; - out[3] = inp[3]+sqrt(3.0)*inp[5]; - out[6] = inp[6]+sqrt(3.0)*inp[7]; + out[0] = inp[0] - sqrt(3.0) * inp[1]; + out[2] = inp[2] - sqrt(3.0) * inp[4]; + out[3] = inp[3] - sqrt(3.0) * inp[5]; + out[6] = inp[6] - sqrt(3.0) * inp[7]; + } else { + out[0] = inp[0] + sqrt(3.0) * inp[1]; + out[2] = inp[2] + sqrt(3.0) * inp[4]; + out[3] = inp[3] + sqrt(3.0) * inp[5]; + out[6] = inp[6] + sqrt(3.0) * inp[7]; } out[1] = 0.0; out[4] = 0.0; out[5] = 0.0; out[7] = 0.0; - } - else if (dir == 1) { + } else if (dir == 1) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-sqrt(3.0)*inp[2]; - out[1] = inp[1]-sqrt(3.0)*inp[4]; - out[3] = inp[3]-sqrt(3.0)*inp[6]; - out[5] = inp[5]-sqrt(3.0)*inp[7]; - } - else { - out[0] = inp[0]+sqrt(3.0)*inp[2]; - out[1] = inp[1]+sqrt(3.0)*inp[4]; - out[3] = inp[3]+sqrt(3.0)*inp[6]; - out[5] = inp[5]+sqrt(3.0)*inp[7]; + out[0] = inp[0] - sqrt(3.0) * inp[2]; + out[1] = inp[1] - sqrt(3.0) * inp[4]; + out[3] = inp[3] - sqrt(3.0) * inp[6]; + out[5] = inp[5] - sqrt(3.0) * inp[7]; + } else { + out[0] = inp[0] + sqrt(3.0) * inp[2]; + out[1] = inp[1] + sqrt(3.0) * inp[4]; + out[3] = inp[3] + sqrt(3.0) * inp[6]; + out[5] = inp[5] + sqrt(3.0) * inp[7]; } out[2] = 0.0; out[4] = 0.0; out[6] = 0.0; out[7] = 0.0; - } - else if (dir == 2) { + } else if (dir == 2) { if (edge == GKYL_LOWER_EDGE) { - out[0] = inp[0]-sqrt(3.0)*inp[3]; - out[1] = inp[1]-sqrt(3.0)*inp[5]; - out[2] = inp[2]-sqrt(3.0)*inp[6]; - out[4] = inp[4]-sqrt(3.0)*inp[7]; - } - else { - out[0] = inp[0]+sqrt(3.0)*inp[3]; - out[1] = inp[1]+sqrt(3.0)*inp[5]; - out[2] = inp[2]+sqrt(3.0)*inp[6]; - out[4] = inp[4]+sqrt(3.0)*inp[7]; + out[0] = inp[0] - sqrt(3.0) * inp[3]; + out[1] = inp[1] - sqrt(3.0) * inp[5]; + out[2] = inp[2] - sqrt(3.0) * inp[6]; + out[4] = inp[4] - sqrt(3.0) * inp[7]; + } else { + out[0] = inp[0] + sqrt(3.0) * inp[3]; + out[1] = inp[1] + sqrt(3.0) * inp[5]; + out[2] = inp[2] + sqrt(3.0) * inp[6]; + out[4] = inp[4] + sqrt(3.0) * inp[7]; } out[3] = 0.0; out[5] = 0.0; @@ -188,204 +172,192 @@ conf_boundary_value_bc(size_t nc, double *out, const double *inp, void *ctx) } enum { M_EX, M_EY, M_EZ, M_BX, M_BY, M_BZ }; // components of EM field -GKYL_CU_D static const int m_flip_even[3][3] = { // zero tangent E and zero normal B +GKYL_CU_D static const int m_flip_even[3][3] = { + // zero tangent E and zero normal B {M_BX, M_EY, M_EZ}, {M_BY, M_EX, M_EZ}, - {M_BZ, M_EX, M_EY}, + {M_BZ, M_EX, M_EY} }; -GKYL_CU_D static const int m_flip_odd[3][3] = { // zero gradient - { M_EX, M_BY, M_BZ }, - { M_EY, M_BX, M_BZ }, - { M_EZ, M_BX, M_BY }, +GKYL_CU_D static const int m_flip_odd[3][3] = { + // zero gradient + {M_EX, M_BY, M_BZ}, + {M_EY, M_BX, M_BZ}, + {M_EZ, M_BX, M_BY} }; // Maxwell's perfect electrical conductor (zero normal B and zero tangent E) -GKYL_CU_D -static void -maxwell_pec_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void maxwell_pec_bc(size_t nc, double *out, const double *inp, void *ctx) { - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int dir = mc->dir; int nbasis = mc->basis->num_basis; const int *feven = m_flip_even[dir]; const int *fodd = m_flip_odd[dir]; - for (int i=0; i<3; ++i) { - int eloc = nbasis*feven[i], oloc = nbasis*fodd[i]; + for (int i = 0; i < 3; ++i) { + int eloc = nbasis * feven[i], oloc = nbasis * fodd[i]; mc->basis->flip_even_sign(dir, &inp[eloc], &out[eloc]); mc->basis->flip_odd_sign(dir, &inp[oloc], &out[oloc]); } // correction potentials - int eloc = nbasis*6, oloc = nbasis*7; + int eloc = nbasis * 6, oloc = nbasis * 7; mc->basis->flip_even_sign(dir, &inp[eloc], &out[eloc]); mc->basis->flip_odd_sign(dir, &inp[oloc], &out[oloc]); } -GKYL_CU_D static const int m_sym_flip_even[3][3] = { // zero tangent B and zero normal E - { M_EX, M_BY, M_BZ }, - { M_EY, M_BX, M_BZ }, - { M_EZ, M_BX, M_BY }, +GKYL_CU_D static const int m_sym_flip_even[3][3] = { + // zero tangent B and zero normal E + {M_EX, M_BY, M_BZ}, + {M_EY, M_BX, M_BZ}, + {M_EZ, M_BX, M_BY} }; -GKYL_CU_D static const int m_sym_flip_odd[3][3] = { // zero gradient - { M_BX, M_EY, M_EZ }, - { M_BY, M_EX, M_EZ }, - { M_BZ, M_EX, M_EY }, +GKYL_CU_D static const int m_sym_flip_odd[3][3] = { + // zero gradient + {M_BX, M_EY, M_EZ}, + {M_BY, M_EX, M_EZ}, + {M_BZ, M_EX, M_EY} }; // Maxwell's symmetry BC (zero normal E and zero tangent B) -GKYL_CU_D -static void -maxwell_sym_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void maxwell_sym_bc(size_t nc, double *out, const double *inp, void *ctx) { - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int dir = mc->dir; int nbasis = mc->basis->num_basis; const int *feven = m_sym_flip_even[dir]; const int *fodd = m_sym_flip_odd[dir]; - for (int i=0; i<3; ++i) { - int eloc = nbasis*feven[i], oloc = nbasis*fodd[i]; + for (int i = 0; i < 3; ++i) { + int eloc = nbasis * feven[i], oloc = nbasis * fodd[i]; mc->basis->flip_even_sign(dir, &inp[eloc], &out[eloc]); mc->basis->flip_odd_sign(dir, &inp[oloc], &out[oloc]); } // correction potentials - int eloc = nbasis*6, oloc = nbasis*7; + int eloc = nbasis * 6, oloc = nbasis * 7; mc->basis->flip_even_sign(dir, &inp[eloc], &out[eloc]); mc->basis->flip_odd_sign(dir, &inp[oloc], &out[oloc]); } // Reservoir Maxwell's BCs for heat flux problem // Based on Roberg-Clark et al. PRL 2018 -// NOTE: ONLY WORKS WITH X BOUNDARY -GKYL_CU_D -static void -maxwell_reservoir_bc(size_t nc, double *out, const double *inp, void *ctx) +// NOTE: ONLY WORKS WITH X BOUNDARY +GKYL_CU_D static void maxwell_reservoir_bc(size_t nc, double *out, const double *inp, void *ctx) { - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int dir = mc->dir; int nbasis = mc->basis->num_basis; // Zero gradient for Ex, Ez, Bx, Bz - mc->basis->flip_odd_sign(dir, &inp[nbasis*0], &out[nbasis*0]); - mc->basis->flip_odd_sign(dir, &inp[nbasis*2], &out[nbasis*2]); - mc->basis->flip_odd_sign(dir, &inp[nbasis*3], &out[nbasis*3]); - mc->basis->flip_odd_sign(dir, &inp[nbasis*5], &out[nbasis*5]); + mc->basis->flip_odd_sign(dir, &inp[nbasis * 0], &out[nbasis * 0]); + mc->basis->flip_odd_sign(dir, &inp[nbasis * 2], &out[nbasis * 2]); + mc->basis->flip_odd_sign(dir, &inp[nbasis * 3], &out[nbasis * 3]); + mc->basis->flip_odd_sign(dir, &inp[nbasis * 5], &out[nbasis * 5]); // Zero Ey and By - mc->basis->flip_even_sign(dir, &inp[nbasis*1], &out[nbasis*1]); - mc->basis->flip_even_sign(dir, &inp[nbasis*4], &out[nbasis*4]); + mc->basis->flip_even_sign(dir, &inp[nbasis * 1], &out[nbasis * 1]); + mc->basis->flip_even_sign(dir, &inp[nbasis * 4], &out[nbasis * 4]); // correction potentials - int eloc = nbasis*6, oloc = nbasis*7; + int eloc = nbasis * 6, oloc = nbasis * 7; mc->basis->flip_even_sign(dir, &inp[eloc], &out[eloc]); mc->basis->flip_odd_sign(dir, &inp[oloc], &out[oloc]); } // Reflecting wall BCs for PKPM momentum -GKYL_CU_D -static void -pkpm_mom_reflect_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void pkpm_mom_reflect_bc(size_t nc, double *out, const double *inp, void *ctx) { - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int dir = mc->dir; int nbasis = mc->basis->num_basis; // reflect normal component (zero normal) and zero gradient in other components - for (int i=0; i<3; ++i) { - int loc = nbasis*i; - if (i == dir) + for (int i = 0; i < 3; ++i) { + int loc = nbasis * i; + if (i == dir) { mc->basis->flip_even_sign(dir, &inp[loc], &out[loc]); - else + } else { mc->basis->flip_odd_sign(dir, &inp[loc], &out[loc]); + } } } // No-slip wall BCs for PKPM momentum -GKYL_CU_D -static void -pkpm_mom_no_slip_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void pkpm_mom_no_slip_bc(size_t nc, double *out, const double *inp, void *ctx) { - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int dir = mc->dir; int nbasis = mc->basis->num_basis; // zero normal and zero tangent - for (int i=0; i<3; ++i) { - int loc = nbasis*i; + for (int i = 0; i < 3; ++i) { + int loc = nbasis * i; mc->basis->flip_even_sign(dir, &inp[loc], &out[loc]); - } + } } -GKYL_CU_D -static void -pkpm_species_reflect_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void pkpm_species_reflect_bc(size_t nc, double *out, const double *inp, void *ctx) { - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int dir = mc->dir, cdim = mc->cdim; int nbasis = mc->basis->num_basis; - int f_loc = 0*nbasis; - int g_loc = 1*nbasis; + int f_loc = 0 * nbasis; + int g_loc = 1 * nbasis; // reflect F_0 mc->basis->flip_odd_sign(dir, &inp[f_loc], &out[f_loc]); - mc->basis->flip_odd_sign(dir+cdim, &out[f_loc], &out[f_loc]); + mc->basis->flip_odd_sign(dir + cdim, &out[f_loc], &out[f_loc]); // reflect G mc->basis->flip_odd_sign(dir, &inp[g_loc], &out[g_loc]); - mc->basis->flip_odd_sign(dir+cdim, &out[g_loc], &out[g_loc]); + mc->basis->flip_odd_sign(dir + cdim, &out[g_loc], &out[g_loc]); } // Reflecting wall BCs for Euler equations -GKYL_CU_D -static void -euler_reflect_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void euler_reflect_bc(size_t nc, double *out, const double *inp, void *ctx) { - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int dir = mc->dir; int nbasis = mc->basis->num_basis; // Copy BCs for density and energy - for (int c=0; cbasis->flip_even_sign(dir, &inp[loc], &out[loc]); - } - else { + } else { mc->basis->flip_odd_sign(dir, &inp[loc], &out[loc]); } } } // No-slip wall BCs for Euler equations -GKYL_CU_D -static void -euler_no_slip_bc(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void euler_no_slip_bc(size_t nc, double *out, const double *inp, void *ctx) { - struct dg_bc_ctx *mc = (struct dg_bc_ctx*) ctx; + struct dg_bc_ctx *mc = (struct dg_bc_ctx *)ctx; int dir = mc->dir; int nbasis = mc->basis->num_basis; // Copy BCs for density and energy - for (int c=0; cbasis->flip_even_sign(dir, &inp[loc], &out[loc]); - } + } } diff --git a/vlasov/zero/gkyl_bc_emission.h b/vlasov/zero/gkyl_bc_emission.h index a73d167e2d..a831e8e0b9 100644 --- a/vlasov/zero/gkyl_bc_emission.h +++ b/vlasov/zero/gkyl_bc_emission.h @@ -15,7 +15,6 @@ struct gkyl_bc_emission_ctx { char in_species[GKYL_MAX_SPECIES][128]; }; - /** * Create the ctx struct required for the emitting wall boundary condition * @@ -28,11 +27,12 @@ struct gkyl_bc_emission_ctx { * @param in_species Table of impacting species names * @return New ctx structure */ -struct gkyl_bc_emission_ctx* -gkyl_bc_emission_new(int num_species, double t_bound, bool elastic, +struct gkyl_bc_emission_ctx *gkyl_bc_emission_new( + int num_species, double t_bound, bool elastic, struct gkyl_emission_spectrum_model *spectrum_model[], struct gkyl_emission_yield_model *yield_model[], - struct gkyl_emission_elastic_model *elastic_model, char in_species[][128]); + struct gkyl_emission_elastic_model *elastic_model, char in_species[][128] +); /** * Copper preset for secondary electron emission @@ -43,9 +43,9 @@ gkyl_bc_emission_new(int num_species, double t_bound, bool elastic, * @param use_gpu bool to determine if on GPU * @return New ctx structure */ -struct gkyl_bc_emission_ctx* -gkyl_bc_emission_secondary_electron_copper_new(int num_species, double t_bound, - char in_species[][128], bool use_gpu); +struct gkyl_bc_emission_ctx *gkyl_bc_emission_secondary_electron_copper_new( + int num_species, double t_bound, char in_species[][128], bool use_gpu +); /** * Oxidized lithium preset for secondary electron emission @@ -56,9 +56,9 @@ gkyl_bc_emission_secondary_electron_copper_new(int num_species, double t_bound, * @param use_gpu bool to determine if on GPU * @return New ctx structure */ -struct gkyl_bc_emission_ctx* -gkyl_bc_emission_secondary_electron_lithium_oxidized_new(int num_species, double t_bound, - char in_species[][128], bool use_gpu); +struct gkyl_bc_emission_ctx *gkyl_bc_emission_secondary_electron_lithium_oxidized_new( + int num_species, double t_bound, char in_species[][128], bool use_gpu +); /** * Clean (no oxidation) lithium preset for secondary electron emission @@ -69,9 +69,9 @@ gkyl_bc_emission_secondary_electron_lithium_oxidized_new(int num_species, double * @param use_gpu bool to determine if on GPU * @return New ctx structure */ -struct gkyl_bc_emission_ctx* -gkyl_bc_emission_secondary_electron_lithium_clean_new(int num_species, double t_bound, - char in_species[][128], bool use_gpu); +struct gkyl_bc_emission_ctx *gkyl_bc_emission_secondary_electron_lithium_clean_new( + int num_species, double t_bound, char in_species[][128], bool use_gpu +); /** * Copper preset for ion-impact secondary electron emission @@ -82,20 +82,21 @@ gkyl_bc_emission_secondary_electron_lithium_clean_new(int num_species, double t_ * @param use_gpu bool to determine if on GPU * @return New ctx structure */ -struct gkyl_bc_emission_ctx* -gkyl_bc_emission_ion_impact_copper_new(int num_species, double t_bound, - char in_species[][128], bool use_gpu); +struct gkyl_bc_emission_ctx *gkyl_bc_emission_ion_impact_copper_new( + int num_species, double t_bound, char in_species[][128], bool use_gpu +); -struct gkyl_bc_emission_ctx* gkyl_bc_emission_secondary_electron_copper_new(int num_species, - double t_bound, char in_species[][128], bool use_gpu); +struct gkyl_bc_emission_ctx *gkyl_bc_emission_secondary_electron_copper_new( + int num_species, double t_bound, char in_species[][128], bool use_gpu +); -struct gkyl_bc_emission_ctx* gkyl_bc_emission_ion_impact_copper_new(int num_species, double t_bound, - char in_species[][128], bool use_gpu); +struct gkyl_bc_emission_ctx *gkyl_bc_emission_ion_impact_copper_new( + int num_species, double t_bound, char in_species[][128], bool use_gpu +); /** * Free memory associated with bc_emission struct. * * @param ctx BC ctx. */ -void -gkyl_bc_emission_release(struct gkyl_bc_emission_ctx *ctx); +void gkyl_bc_emission_release(struct gkyl_bc_emission_ctx *ctx); diff --git a/vlasov/zero/gkyl_bc_emission_elastic.h b/vlasov/zero/gkyl_bc_emission_elastic.h index b4ccdb35cf..1cd0c4a890 100644 --- a/vlasov/zero/gkyl_bc_emission_elastic.h +++ b/vlasov/zero/gkyl_bc_emission_elastic.h @@ -29,12 +29,12 @@ typedef struct gkyl_bc_emission_elastic gkyl_bc_emission_elastic; * @param use_gpu Boolean to indicate whether to use the GPU * @return New updater pointer */ -struct gkyl_bc_emission_elastic* -gkyl_bc_emission_elastic_new(struct gkyl_emission_elastic_model *elastic_model, - struct gkyl_array *elastic_yield, int dir, enum gkyl_edge_loc edge, int cdim, - int vdim, double mass, int ncomp, struct gkyl_rect_grid *grid, struct gkyl_range *emit_buff_r, - int poly_order, const struct gkyl_basis *dev_basis, struct gkyl_basis *basis, - struct gkyl_array *proj_buffer, bool use_gpu); +struct gkyl_bc_emission_elastic *gkyl_bc_emission_elastic_new( + struct gkyl_emission_elastic_model *elastic_model, struct gkyl_array *elastic_yield, int dir, + enum gkyl_edge_loc edge, int cdim, int vdim, double mass, int ncomp, struct gkyl_rect_grid *grid, + struct gkyl_range *emit_buff_r, int poly_order, const struct gkyl_basis *dev_basis, + struct gkyl_basis *basis, struct gkyl_array *proj_buffer, bool use_gpu +); /** * @param up BC updater @@ -45,10 +45,11 @@ gkyl_bc_emission_elastic_new(struct gkyl_emission_elastic_model *elastic_model, * @param elastic_yield Projection of elastic yield model onto basis * @param basis Pointer to basis functions on host */ -void -gkyl_bc_emission_elastic_advance(const struct gkyl_bc_emission_elastic *up, - struct gkyl_range *emit_skin_r, struct gkyl_array *buff_arr, struct gkyl_array *f_skin, - struct gkyl_array *f_emit, struct gkyl_array *elastic_yield, struct gkyl_basis *basis); +void gkyl_bc_emission_elastic_advance( + const struct gkyl_bc_emission_elastic *up, struct gkyl_range *emit_skin_r, + struct gkyl_array *buff_arr, struct gkyl_array *f_skin, struct gkyl_array *f_emit, + struct gkyl_array *elastic_yield, struct gkyl_basis *basis +); /** * @param dir Direction in which to apply BC @@ -57,14 +58,13 @@ gkyl_bc_emission_elastic_advance(const struct gkyl_bc_emission_elastic *up, * @param ncomp Number of components * @param use_gpu Boolean to indicate whether to use the GPU */ -struct gkyl_array_copy_func* -gkyl_bc_emission_elastic_create_arr_copy_func(int dir, int cdim, - const struct gkyl_basis *basis, int ncomp, bool use_gpu); +struct gkyl_array_copy_func *gkyl_bc_emission_elastic_create_arr_copy_func( + int dir, int cdim, const struct gkyl_basis *basis, int ncomp, bool use_gpu +); /** * Free memory associated with bc_emission_elastic updater. * * @param up BC updater. */ -void -gkyl_bc_emission_elastic_release(struct gkyl_bc_emission_elastic *up); +void gkyl_bc_emission_elastic_release(struct gkyl_bc_emission_elastic *up); diff --git a/vlasov/zero/gkyl_bc_emission_elastic_priv.h b/vlasov/zero/gkyl_bc_emission_elastic_priv.h index fbb94264c7..fb30841b5a 100644 --- a/vlasov/zero/gkyl_bc_emission_elastic_priv.h +++ b/vlasov/zero/gkyl_bc_emission_elastic_priv.h @@ -25,24 +25,22 @@ struct bc_elastic_ctx { const struct gkyl_basis *basis; // basis function. }; -GKYL_CU_D -static void -reflection(size_t nc, double *out, const double *inp, void *ctx) +GKYL_CU_D static void reflection(size_t nc, double *out, const double *inp, void *ctx) { - struct bc_elastic_ctx *bc_ctx = (struct bc_elastic_ctx *) ctx; + struct bc_elastic_ctx *bc_ctx = (struct bc_elastic_ctx *)ctx; int dir = bc_ctx->dir, cdim = bc_ctx->cdim; - + bc_ctx->basis->flip_odd_sign(dir, inp, out); - bc_ctx->basis->flip_odd_sign(dir+cdim, out, out); + bc_ctx->basis->flip_odd_sign(dir + cdim, out, out); } -struct gkyl_array_copy_func* -gkyl_bc_emission_elastic_create_arr_copy_func_cu(int dir, int cdim, const struct gkyl_basis *basis, - int ncomp); +struct gkyl_array_copy_func *gkyl_bc_emission_elastic_create_arr_copy_func_cu( + int dir, int cdim, const struct gkyl_basis *basis, int ncomp +); -void -gkyl_bc_emission_elastic_set_extern_params_cu(const struct gkyl_bc_emission_elastic *up, - int cdim, int vdim, double mass); +void gkyl_bc_emission_elastic_set_extern_params_cu( + const struct gkyl_bc_emission_elastic *up, int cdim, int vdim, double mass +); #ifdef GKYL_HAVE_CUDA @@ -57,8 +55,9 @@ gkyl_bc_emission_elastic_set_extern_params_cu(const struct gkyl_bc_emission_elas * @param elastic_yield Projection of elastic yield model onto basis * @param basis Pointer to basis functions on host */ -void -gkyl_bc_emission_elastic_advance_cu(const struct gkyl_bc_emission_elastic *up, - struct gkyl_range *emit_skin_r, struct gkyl_array *buff_arr, struct gkyl_array *f_skin, - struct gkyl_array *f_emit, struct gkyl_array *elastic_yield, struct gkyl_basis *basis); +void gkyl_bc_emission_elastic_advance_cu( + const struct gkyl_bc_emission_elastic *up, struct gkyl_range *emit_skin_r, + struct gkyl_array *buff_arr, struct gkyl_array *f_skin, struct gkyl_array *f_emit, + struct gkyl_array *elastic_yield, struct gkyl_basis *basis +); #endif diff --git a/vlasov/zero/gkyl_bc_emission_spectrum.h b/vlasov/zero/gkyl_bc_emission_spectrum.h index e087b4478c..8832824b26 100644 --- a/vlasov/zero/gkyl_bc_emission_spectrum.h +++ b/vlasov/zero/gkyl_bc_emission_spectrum.h @@ -34,13 +34,14 @@ typedef struct gkyl_bc_emission_spectrum gkyl_bc_emission_spectrum; * @param use_gpu Boolean to indicate whether to use the GPU * @return New updater pointer */ -struct gkyl_bc_emission_spectrum* -gkyl_bc_emission_spectrum_new(struct gkyl_emission_spectrum_model *spectrum_model, +struct gkyl_bc_emission_spectrum *gkyl_bc_emission_spectrum_new( + struct gkyl_emission_spectrum_model *spectrum_model, struct gkyl_emission_yield_model *yield_model, struct gkyl_array *yield, - struct gkyl_array *spectrum, int dir, enum gkyl_edge_loc edge, int cdim, int vdim, - double mass_in, double mass_out, struct gkyl_range *impact_buff_r, struct gkyl_range *emit_buff_r, + struct gkyl_array *spectrum, int dir, enum gkyl_edge_loc edge, int cdim, int vdim, double mass_in, + double mass_out, struct gkyl_range *impact_buff_r, struct gkyl_range *emit_buff_r, struct gkyl_rect_grid *impact_grid, struct gkyl_rect_grid *emit_grid, int poly_order, - struct gkyl_basis *basis, struct gkyl_array *proj_buffer, bool use_gpu); + struct gkyl_basis *basis, struct gkyl_array *proj_buffer, bool use_gpu +); /** * @param up BC updater @@ -55,12 +56,12 @@ gkyl_bc_emission_spectrum_new(struct gkyl_emission_spectrum_model *spectrum_mode * @param flux Flux into boundary * @param k Normalization factor */ -void -gkyl_bc_emission_spectrum_advance(const struct gkyl_bc_emission_spectrum *up, - struct gkyl_range *impact_buff_r, struct gkyl_range *impact_cbuff_r, - struct gkyl_range *emit_buff_r, struct gkyl_array *bflux, struct gkyl_array *f_emit, - struct gkyl_array *yield, struct gkyl_array *spectrum, struct gkyl_array *weight, - struct gkyl_array *flux, struct gkyl_array *k); +void gkyl_bc_emission_spectrum_advance( + const struct gkyl_bc_emission_spectrum *up, struct gkyl_range *impact_buff_r, + struct gkyl_range *impact_cbuff_r, struct gkyl_range *emit_buff_r, struct gkyl_array *bflux, + struct gkyl_array *f_emit, struct gkyl_array *yield, struct gkyl_array *spectrum, + struct gkyl_array *weight, struct gkyl_array *flux, struct gkyl_array *k +); /** * Loop over impacting species velocity space and calculate SEY at cell centers @@ -70,9 +71,10 @@ gkyl_bc_emission_spectrum_advance(const struct gkyl_bc_emission_spectrum *up, * @param grid Impacting species boundary grid * @param impact_buff_r Range over the impacting species buffer array */ -void -gkyl_bc_emission_spectrum_sey_calc(const struct gkyl_bc_emission_spectrum *up, - struct gkyl_array *yield, struct gkyl_rect_grid *grid, const struct gkyl_range *impact_buffer_r); +void gkyl_bc_emission_spectrum_sey_calc( + const struct gkyl_bc_emission_spectrum *up, struct gkyl_array *yield, struct gkyl_rect_grid *grid, + const struct gkyl_range *impact_buffer_r +); /** * Create range over velocity space into wall. @@ -83,14 +85,14 @@ gkyl_bc_emission_spectrum_sey_calc(const struct gkyl_bc_emission_spectrum *up, * @param nghost Number of ghost cells. * @param edge Lower or upper edge at which to apply BC (emission_spectrum gkyl_edge_loc). */ -void -gkyl_bc_emission_flux_ranges(struct gkyl_range *impact_buff_r, int dir, - const struct gkyl_range *parent, const int *nghost, enum gkyl_edge_loc edge); +void gkyl_bc_emission_flux_ranges( + struct gkyl_range *impact_buff_r, int dir, const struct gkyl_range *parent, const int *nghost, + enum gkyl_edge_loc edge +); /** * Free memory associated with bc_emission_spectrum updater. * * @param up BC updater. */ -void -gkyl_bc_emission_spectrum_release(struct gkyl_bc_emission_spectrum *up); +void gkyl_bc_emission_spectrum_release(struct gkyl_bc_emission_spectrum *up); diff --git a/vlasov/zero/gkyl_bc_emission_spectrum_priv.h b/vlasov/zero/gkyl_bc_emission_spectrum_priv.h index 90be2ac078..36f8343c73 100644 --- a/vlasov/zero/gkyl_bc_emission_spectrum_priv.h +++ b/vlasov/zero/gkyl_bc_emission_spectrum_priv.h @@ -21,21 +21,23 @@ struct gkyl_bc_emission_spectrum { }; // Function to calculate the weighted mean of the SE yield -GKYL_CU_D -static void -bc_weighted_delta(const double *inp, int cdim, int dir, enum gkyl_edge_loc edge, double xc[GKYL_MAX_DIM], const double *gain, double *weight) +GKYL_CU_D static void bc_weighted_delta( + const double *inp, int cdim, int dir, enum gkyl_edge_loc edge, double xc[GKYL_MAX_DIM], + const double *gain, double *weight +) { - if ((edge == GKYL_LOWER_EDGE && xc[cdim+dir] < 0) || (edge == GKYL_UPPER_EDGE && xc[cdim+dir] > 0)) { - weight[0] += inp[0]*gain[0]; + if ((edge == GKYL_LOWER_EDGE && xc[cdim + dir] < 0) || + (edge == GKYL_UPPER_EDGE && xc[cdim + dir] > 0)) { + weight[0] += inp[0] * gain[0]; weight[1] += inp[0]; } } #ifdef GKYL_HAVE_CUDA -void -gkyl_bc_emission_spectrum_set_extern_params_cu(const struct gkyl_bc_emission_spectrum *up, - int cdim, int vdim, double mass_in, double mass_out); +void gkyl_bc_emission_spectrum_set_extern_params_cu( + const struct gkyl_bc_emission_spectrum *up, int cdim, int vdim, double mass_in, double mass_out +); /** * CUDA device function to set up function to apply boundary conditions. @@ -54,12 +56,12 @@ gkyl_bc_emission_spectrum_set_extern_params_cu(const struct gkyl_bc_emission_spe * @param conf_r Configuration space range * @param buff_r Buffer array range */ -void -gkyl_bc_emission_spectrum_advance_cu(const struct gkyl_bc_emission_spectrum *up, - struct gkyl_range *impact_buff_r, struct gkyl_range *impact_cbuff_r, - struct gkyl_range *emit_buff_r, struct gkyl_array *bflux, struct gkyl_array *f_emit, - struct gkyl_array *yield, struct gkyl_array *spectrum, struct gkyl_array *weight, - struct gkyl_array *flux, struct gkyl_array *k); +void gkyl_bc_emission_spectrum_advance_cu( + const struct gkyl_bc_emission_spectrum *up, struct gkyl_range *impact_buff_r, + struct gkyl_range *impact_cbuff_r, struct gkyl_range *emit_buff_r, struct gkyl_array *bflux, + struct gkyl_array *f_emit, struct gkyl_array *yield, struct gkyl_array *spectrum, + struct gkyl_array *weight, struct gkyl_array *flux, struct gkyl_array *k +); /** * CUDA device function to set up function to calculate SEY @@ -69,8 +71,9 @@ gkyl_bc_emission_spectrum_advance_cu(const struct gkyl_bc_emission_spectrum *up, * @param gamma SE yield values on incoming ghost space * @param ghost_r Incoming ghost space range */ -void -gkyl_bc_emission_spectrum_sey_calc_cu(const struct gkyl_bc_emission_spectrum *up, - struct gkyl_array *yield, struct gkyl_rect_grid *grid, const struct gkyl_range *gamma_r); +void gkyl_bc_emission_spectrum_sey_calc_cu( + const struct gkyl_bc_emission_spectrum *up, struct gkyl_array *yield, struct gkyl_rect_grid *grid, + const struct gkyl_range *gamma_r +); #endif diff --git a/vlasov/zero/gkyl_bgk_collisions.h b/vlasov/zero/gkyl_bgk_collisions.h index 5b322ce65b..0260f59131 100644 --- a/vlasov/zero/gkyl_bgk_collisions.h +++ b/vlasov/zero/gkyl_bgk_collisions.h @@ -20,8 +20,9 @@ typedef struct gkyl_bgk_collisions gkyl_bgk_collisions; * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -gkyl_bgk_collisions* gkyl_bgk_collisions_new(const struct gkyl_basis *cbasis, - const struct gkyl_basis *pbasis, bool use_gpu); +gkyl_bgk_collisions *gkyl_bgk_collisions_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, bool use_gpu +); /** * Advance BGK operator (compute the BGK contribution to df/dt). @@ -37,14 +38,15 @@ gkyl_bgk_collisions* gkyl_bgk_collisions_new(const struct gkyl_basis *cbasis, * @param out BGK contribution to df/dt. * @param cflfreq Output CFL frequency. */ -void gkyl_bgk_collisions_advance(const gkyl_bgk_collisions *up, - const struct gkyl_range *crange, const struct gkyl_range *prange, +void gkyl_bgk_collisions_advance( + const gkyl_bgk_collisions *up, const struct gkyl_range *crange, const struct gkyl_range *prange, const struct gkyl_array *nu, const struct gkyl_array *nufM, const struct gkyl_array *fin, - bool implicit_step, double dt, struct gkyl_array *out, struct gkyl_array *cflfreq); + bool implicit_step, double dt, struct gkyl_array *out, struct gkyl_array *cflfreq +); /** * Delete updater. * * @param pob Updater to delete. */ -void gkyl_bgk_collisions_release(gkyl_bgk_collisions* up); +void gkyl_bgk_collisions_release(gkyl_bgk_collisions *up); diff --git a/vlasov/zero/gkyl_bgk_collisions_priv.h b/vlasov/zero/gkyl_bgk_collisions_priv.h index feb2cf7a27..c07c6997d1 100644 --- a/vlasov/zero/gkyl_bgk_collisions_priv.h +++ b/vlasov/zero/gkyl_bgk_collisions_priv.h @@ -16,8 +16,8 @@ struct gkyl_bgk_collisions { bool use_gpu; }; -void -gkyl_bgk_collisions_advance_cu(const gkyl_bgk_collisions *up, - const struct gkyl_range *crange, const struct gkyl_range *prange, +void gkyl_bgk_collisions_advance_cu( + const gkyl_bgk_collisions *up, const struct gkyl_range *crange, const struct gkyl_range *prange, const struct gkyl_array *nu, const struct gkyl_array *nufM, const struct gkyl_array *fin, - bool implicit_step, double dt, struct gkyl_array *out, struct gkyl_array *cflfreq); + bool implicit_step, double dt, struct gkyl_array *out, struct gkyl_array *cflfreq +); diff --git a/vlasov/zero/gkyl_dg_advection.h b/vlasov/zero/gkyl_dg_advection.h index 50f5a6b0a4..a7029ec9b5 100644 --- a/vlasov/zero/gkyl_dg_advection.h +++ b/vlasov/zero/gkyl_dg_advection.h @@ -8,7 +8,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_advection_auxfields { +struct gkyl_dg_advection_auxfields { const struct gkyl_array *u_i; }; @@ -19,7 +19,9 @@ struct gkyl_dg_advection_auxfields { * @param conf_range Configuration space range for use in indexing advection velocity * @return Pointer to advection equation object */ -struct gkyl_dg_eqn* gkyl_dg_advection_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_advection_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, bool use_gpu +); /** * Create a new advection equation object that lives on NV-GPU @@ -28,7 +30,8 @@ struct gkyl_dg_eqn* gkyl_dg_advection_new(const struct gkyl_basis* cbasis, const * @param conf_range Configuration space range for use in indexing advection velocity * @return Pointer to advection equation object */ -struct gkyl_dg_eqn* gkyl_dg_advection_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range); +struct gkyl_dg_eqn * +gkyl_dg_advection_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range); /** * Set the auxiliary fields (e.g. advection velocity u) needed in updating advection equation. @@ -36,7 +39,9 @@ struct gkyl_dg_eqn* gkyl_dg_advection_cu_dev_new(const struct gkyl_basis* cbasis * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_advection_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_advection_auxfields auxin); +void gkyl_advection_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_advection_auxfields auxin +); #ifdef GKYL_HAVE_CUDA @@ -46,6 +51,8 @@ void gkyl_advection_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_ * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_advection_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_advection_auxfields auxin); +void gkyl_advection_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_advection_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_advection_priv.h b/vlasov/zero/gkyl_dg_advection_priv.h index 5e190d15aa..054fd3e528 100644 --- a/vlasov/zero/gkyl_dg_advection_priv.h +++ b/vlasov/zero/gkyl_dg_advection_priv.h @@ -8,16 +8,21 @@ // functions // Types for various kernels -typedef double (*advection_surf_t)(const double *w, const double *dx, - const double *ul, const double *uc, const double *ur, - const double *ql, const double *qc, const double *qr, double* GKYL_RESTRICT out); +typedef double (*advection_surf_t)( + const double *w, const double *dx, const double *ul, const double *uc, const double *ur, + const double *ql, const double *qc, const double *qr, double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_advection_vol_kern_list; -typedef struct { advection_surf_t kernels[3]; } gkyl_dg_advection_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_advection_vol_kern_list; +typedef struct { + advection_surf_t kernels[3]; +} gkyl_dg_advection_surf_kern_list; struct dg_advection { - struct gkyl_dg_eqn eqn; // Base object + struct gkyl_dg_eqn eqn; // Base object advection_surf_t surf[3]; // pointers to surface kernels struct gkyl_range conf_range; // configuration space range struct gkyl_dg_advection_auxfields auxfields; // Auxiliary fields. @@ -28,102 +33,104 @@ struct dg_advection { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_advection_vol_1x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_advection_vol_1x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_advection *advection = container_of(eqn, struct dg_advection, eqn); long cidx = gkyl_range_idx(&advection->conf_range, idx); - return advection_vol_1x_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut); + return advection_vol_1x_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_advection_vol_1x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_advection_vol_1x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_advection *advection = container_of(eqn, struct dg_advection, eqn); long cidx = gkyl_range_idx(&advection->conf_range, idx); - return advection_vol_1x_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut); + return advection_vol_1x_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_advection_vol_2x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_advection_vol_2x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_advection *advection = container_of(eqn, struct dg_advection, eqn); long cidx = gkyl_range_idx(&advection->conf_range, idx); - return advection_vol_2x_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut); + return advection_vol_2x_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_advection_vol_2x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_advection_vol_2x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_advection *advection = container_of(eqn, struct dg_advection, eqn); long cidx = gkyl_range_idx(&advection->conf_range, idx); - return advection_vol_2x_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut); + return advection_vol_2x_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_advection_vol_3x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_advection_vol_3x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_advection *advection = container_of(eqn, struct dg_advection, eqn); long cidx = gkyl_range_idx(&advection->conf_range, idx); - return advection_vol_3x_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut); + return advection_vol_3x_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_advection_vol_3x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_advection_vol_3x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_advection *advection = container_of(eqn, struct dg_advection, eqn); long cidx = gkyl_range_idx(&advection->conf_range, idx); - return advection_vol_3x_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut); + return advection_vol_3x_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(advection->auxfields.u_i, cidx), qIn, qRhsOut + ); } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_advection_vol_kern_list ser_vol_kernels[] = { - { NULL, kernel_advection_vol_1x_ser_p1, kernel_advection_vol_1x_ser_p2 }, // 0 - { NULL, kernel_advection_vol_2x_ser_p1, kernel_advection_vol_2x_ser_p2 }, // 1 - { NULL, kernel_advection_vol_3x_ser_p1, kernel_advection_vol_3x_ser_p2 }, // 2 +GKYL_CU_D static const gkyl_dg_advection_vol_kern_list ser_vol_kernels[] = { + {NULL, kernel_advection_vol_1x_ser_p1, kernel_advection_vol_1x_ser_p2}, // 0 + {NULL, kernel_advection_vol_2x_ser_p1, kernel_advection_vol_2x_ser_p2}, // 1 + {NULL, kernel_advection_vol_3x_ser_p1, kernel_advection_vol_3x_ser_p2} // 2 }; // Surface kernel list: x-direction -GKYL_CU_D -static const gkyl_dg_advection_surf_kern_list ser_surf_x_kernels[] = { - { NULL, advection_surfx_1x_ser_p1, advection_surfx_1x_ser_p2 }, // 0 - { NULL, advection_surfx_2x_ser_p1, advection_surfx_2x_ser_p2 }, // 1 - { NULL, advection_surfx_3x_ser_p1, advection_surfx_3x_ser_p2 }, // 2 +GKYL_CU_D static const gkyl_dg_advection_surf_kern_list ser_surf_x_kernels[] = { + {NULL, advection_surfx_1x_ser_p1, advection_surfx_1x_ser_p2}, // 0 + {NULL, advection_surfx_2x_ser_p1, advection_surfx_2x_ser_p2}, // 1 + {NULL, advection_surfx_3x_ser_p1, advection_surfx_3x_ser_p2} // 2 }; // Surface kernel list: y-direction -GKYL_CU_D -static const gkyl_dg_advection_surf_kern_list ser_surf_y_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, advection_surfy_2x_ser_p1, advection_surfy_2x_ser_p2 }, // 1 - { NULL, advection_surfy_3x_ser_p1, advection_surfy_3x_ser_p2 }, // 2 +GKYL_CU_D static const gkyl_dg_advection_surf_kern_list ser_surf_y_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, advection_surfy_2x_ser_p1, advection_surfy_2x_ser_p2}, // 1 + {NULL, advection_surfy_3x_ser_p1, advection_surfy_3x_ser_p2} // 2 }; // Surface kernel list: z-direction -GKYL_CU_D -static const gkyl_dg_advection_surf_kern_list ser_surf_z_kernels[] = { - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, advection_surfz_3x_ser_p1, advection_surfz_3x_ser_p2 }, // 2 +GKYL_CU_D static const gkyl_dg_advection_surf_kern_list ser_surf_z_kernels[] = { + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, advection_surfz_3x_ser_p1, advection_surfz_3x_ser_p2} // 2 }; /** @@ -133,14 +140,12 @@ static const gkyl_dg_advection_surf_kern_list ser_surf_z_kernels[] = { */ void gkyl_advection_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_advection *advection = container_of(eqn, struct dg_advection, eqn); @@ -148,21 +153,18 @@ surf(const struct gkyl_dg_eqn *eqn, long cidx_c = gkyl_range_idx(&advection->conf_range, idxC); long cidx_r = gkyl_range_idx(&advection->conf_range, idxR); - return advection->surf[dir](xcC, dxC, - (const double*) gkyl_array_cfetch(advection->auxfields.u_i, cidx_l), - (const double*) gkyl_array_cfetch(advection->auxfields.u_i, cidx_c), - (const double*) gkyl_array_cfetch(advection->auxfields.u_i, cidx_r), - qInL, qInC, qInR, qRhsOut); + return advection->surf[dir]( + xcC, dxC, (const double *)gkyl_array_cfetch(advection->auxfields.u_i, cidx_l), + (const double *)gkyl_array_cfetch(advection->auxfields.u_i, cidx_c), + (const double *)gkyl_array_cfetch(advection->auxfields.u_i, cidx_r), qInL, qInC, qInR, qRhsOut + ); } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { return 0.; } diff --git a/vlasov/zero/gkyl_dg_calc_canonical_pb_fluid_vars.h b/vlasov/zero/gkyl_dg_calc_canonical_pb_fluid_vars.h index b6ea84d28a..4d0eff6a68 100644 --- a/vlasov/zero/gkyl_dg_calc_canonical_pb_fluid_vars.h +++ b/vlasov/zero/gkyl_dg_calc_canonical_pb_fluid_vars.h @@ -31,19 +31,21 @@ typedef struct gkyl_dg_calc_canonical_pb_fluid_vars gkyl_dg_calc_canonical_pb_fl * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_dg_calc_canonical_pb_fluid_vars* -gkyl_dg_calc_canonical_pb_fluid_vars_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, - const struct gkyl_wv_eqn *wv_eqn, bool use_gpu); +struct gkyl_dg_calc_canonical_pb_fluid_vars *gkyl_dg_calc_canonical_pb_fluid_vars_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_wv_eqn *wv_eqn, bool use_gpu +); /** * Create new updater to compute canonical_pb general geometry variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_dg_calc_canonical_pb_fluid_vars* -gkyl_dg_calc_canonical_pb_fluid_vars_cu_dev_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, - const struct gkyl_wv_eqn *wv_eqn); +struct gkyl_dg_calc_canonical_pb_fluid_vars *gkyl_dg_calc_canonical_pb_fluid_vars_cu_dev_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, + const struct gkyl_wv_eqn *wv_eqn +); /** * Compute surface expansion of configuration space flux alpha = {z, phi} @@ -58,10 +60,12 @@ gkyl_dg_calc_canonical_pb_fluid_vars_cu_dev_new(const struct gkyl_rect_grid *con * @param const_sgn_alpha Output boolean array for if sign(alpha) is a constant on the surface * If sign(alpha) is a constant, kernels are simpler and we exploit this fact. */ -void gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, - const struct gkyl_array* phi, - struct gkyl_array* alpha_surf, struct gkyl_array* sgn_alpha_surf, struct gkyl_array* const_sgn_alpha); +void gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *conf_ext_range, const struct gkyl_array *phi, + struct gkyl_array *alpha_surf, struct gkyl_array *sgn_alpha_surf, + struct gkyl_array *const_sgn_alpha +); /** * Compute source update to canonical PB fluid system, such as the adiabatic coupling and turbulence drive @@ -74,9 +78,11 @@ void gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf(struct gkyl_dg_calc_canonic * @param fluid Input array of fluid variables * @param rhs Output increment to fluid variables from sources */ -void gkyl_canonical_pb_fluid_vars_source(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array *background_n_gradient, const struct gkyl_array *phi, - const struct gkyl_array *fluid, struct gkyl_array *rhs); +void gkyl_canonical_pb_fluid_vars_source( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *background_n_gradient, const struct gkyl_array *phi, + const struct gkyl_array *fluid, struct gkyl_array *rhs +); /** * Delete pointer to updater to compute canonical PB fluid variables. @@ -89,11 +95,15 @@ void gkyl_dg_calc_canonical_pb_fluid_vars_release(struct gkyl_dg_calc_canonical_ * Host-side wrappers for canonical PB fluid variable operations on device */ -void gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf_cu(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *conf_ext_range, - const struct gkyl_array* phi, - struct gkyl_array* alpha_surf, struct gkyl_array* sgn_alpha_surf, struct gkyl_array* const_sgn_alpha); +void gkyl_dg_calc_canonical_pb_fluid_vars_alpha_surf_cu( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *conf_ext_range, const struct gkyl_array *phi, + struct gkyl_array *alpha_surf, struct gkyl_array *sgn_alpha_surf, + struct gkyl_array *const_sgn_alpha +); -void gkyl_canonical_pb_fluid_vars_source_cu(struct gkyl_dg_calc_canonical_pb_fluid_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array *background_n_gradient, const struct gkyl_array *phi, - const struct gkyl_array *fluid, struct gkyl_array *rhs); +void gkyl_canonical_pb_fluid_vars_source_cu( + struct gkyl_dg_calc_canonical_pb_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *background_n_gradient, const struct gkyl_array *phi, + const struct gkyl_array *fluid, struct gkyl_array *rhs +); diff --git a/vlasov/zero/gkyl_dg_calc_canonical_pb_fluid_vars_priv.h b/vlasov/zero/gkyl_dg_calc_canonical_pb_fluid_vars_priv.h index ead4852570..fa9c790a0f 100644 --- a/vlasov/zero/gkyl_dg_calc_canonical_pb_fluid_vars_priv.h +++ b/vlasov/zero/gkyl_dg_calc_canonical_pb_fluid_vars_priv.h @@ -11,44 +11,57 @@ #include #include -typedef int (*canonical_pb_fluid_alpha_surf_t)(const double *w, const double *dxv, const double *phi, - double* GKYL_RESTRICT alpha_surf, double* GKYL_RESTRICT sgn_alpha_surf); -typedef void (*canonical_pb_fluid_source_t)(const double *dxv, double alpha, - const double *phi, const double *n0, - const double *adiabatic_coupling_phi_n, double* GKYL_RESTRICT rhs); -typedef void (*canonical_pb_fluid_subtract_zonal_t)(const double *phi_zonal, const double *n_zonal, - double* GKYL_RESTRICT adiabatic_coupling_phi_n); +typedef int (*canonical_pb_fluid_alpha_surf_t)( + const double *w, const double *dxv, const double *phi, double *GKYL_RESTRICT alpha_surf, + double *GKYL_RESTRICT sgn_alpha_surf +); +typedef void (*canonical_pb_fluid_source_t)( + const double *dxv, double alpha, const double *phi, const double *n0, + const double *adiabatic_coupling_phi_n, double *GKYL_RESTRICT rhs +); +typedef void (*canonical_pb_fluid_subtract_zonal_t)( + const double *phi_zonal, const double *n_zonal, double *GKYL_RESTRICT adiabatic_coupling_phi_n +); // for use in kernel tables -typedef struct { canonical_pb_fluid_alpha_surf_t kernels[3]; } gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list; -typedef struct { canonical_pb_fluid_source_t kernels[3]; } gkyl_dg_canonical_pb_fluid_source_kern_list; -typedef struct { canonical_pb_fluid_subtract_zonal_t kernels[3]; } gkyl_dg_canonical_pb_fluid_subtract_zonal_kern_list; +typedef struct { + canonical_pb_fluid_alpha_surf_t kernels[3]; +} gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list; +typedef struct { + canonical_pb_fluid_source_t kernels[3]; +} gkyl_dg_canonical_pb_fluid_source_kern_list; +typedef struct { + canonical_pb_fluid_subtract_zonal_t kernels[3]; +} gkyl_dg_canonical_pb_fluid_subtract_zonal_kern_list; struct gkyl_dg_calc_canonical_pb_fluid_vars { struct gkyl_rect_grid conf_grid; // Configuration-space grid for cell spacing and cell center struct gkyl_basis conf_basis; // Configuration-space basis int cdim; // Configuration-space dimensionality double alpha; // Adiabaticity parameter for adiabatic coupling of vorticity and density. - double kappa; // Constant density gradient scale length (for turbulence drive). - bool is_modified; // Boolean parameter for if we are doing the modified Hasegawa-Wakatani. + double kappa; // Constant density gradient scale length (for turbulence drive). + bool is_modified; // Boolean parameter for if we are doing the modified Hasegawa-Wakatani. - canonical_pb_fluid_alpha_surf_t alpha_surf[3]; // kernel for computing surface expansion of configuration space flux alpha - canonical_pb_fluid_alpha_surf_t alpha_edge_surf[3]; // kernel for computing surface expansion of configuration space flux alpha - // at upper configuration space edge + canonical_pb_fluid_alpha_surf_t + alpha_surf[3]; // kernel for computing surface expansion of configuration space flux alpha + canonical_pb_fluid_alpha_surf_t + alpha_edge_surf[3]; // kernel for computing surface expansion of configuration space flux alpha + // at upper configuration space edge - canonical_pb_fluid_source_t canonical_pb_fluid_source; // Canonical pb fluid variables source function + canonical_pb_fluid_source_t + canonical_pb_fluid_source; // Canonical pb fluid variables source function - canonical_pb_fluid_subtract_zonal_t subtract_zonal; // Function for subtracting zonal component - // of n and phi in modified Hasegawa-Wakatani + canonical_pb_fluid_subtract_zonal_t subtract_zonal; // Function for subtracting zonal component + // of n and phi in modified Hasegawa-Wakatani - // Specific memory for Hasegawa-Wakatani to compute adiabatic coupling and if we are - // solving modified Hasegawa-Wakatani, subtract the zonal component of n and phi. + // Specific memory for Hasegawa-Wakatani to compute adiabatic coupling and if we are + // solving modified Hasegawa-Wakatani, subtract the zonal component of n and phi. struct gkyl_array *n; // Density (second component of Hasegawa-Wakatani system) struct gkyl_array *adiabatic_coupling_phi_n; // combined (phi, n) array for adiabatic coupling struct gkyl_range x_local; // x range for the zonal components after integrating over y - struct gkyl_range x_local_ext; // extended x range for the zonal components after integrating over y - struct gkyl_array *phi_zonal; // 1/Ly int phi dy + struct gkyl_range x_local_ext; // extended x range for the zonal components after integrating over y + struct gkyl_array *phi_zonal; // 1/Ly int phi dy struct gkyl_array *n_zonal; // 1/Ly int n dy struct gkyl_array_average *int_y; // Updater for computing zonal components by averaging in y @@ -57,267 +70,273 @@ struct gkyl_dg_calc_canonical_pb_fluid_vars { }; // Canonical PB fluid alpha surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list ser_canonical_pb_fluid_alpha_surfx_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_alpha_surfx_2x_ser_p1, canonical_pb_alpha_surfx_2x_ser_p2 }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list + ser_canonical_pb_fluid_alpha_surfx_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_alpha_surfx_2x_ser_p1, canonical_pb_alpha_surfx_2x_ser_p2}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB fluid alpha upper edge of configuration space surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list ser_canonical_pb_fluid_alpha_edge_surfx_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_alpha_edge_surfx_2x_ser_p1, canonical_pb_alpha_edge_surfx_2x_ser_p2 }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list + ser_canonical_pb_fluid_alpha_edge_surfx_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_alpha_edge_surfx_2x_ser_p1, canonical_pb_alpha_edge_surfx_2x_ser_p2}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB fluid alpha surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list ser_canonical_pb_fluid_alpha_surfy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_alpha_surfy_2x_ser_p1, canonical_pb_alpha_surfy_2x_ser_p2 }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list + ser_canonical_pb_fluid_alpha_surfy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_alpha_surfy_2x_ser_p1, canonical_pb_alpha_surfy_2x_ser_p2}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB fluid alpha upper edge of configuration space surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list ser_canonical_pb_fluid_alpha_edge_surfy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_alpha_edge_surfy_2x_ser_p1, canonical_pb_alpha_edge_surfy_2x_ser_p2 }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list + ser_canonical_pb_fluid_alpha_edge_surfy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_alpha_edge_surfy_2x_ser_p1, canonical_pb_alpha_edge_surfy_2x_ser_p2}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB fluid alpha surface expansions in x (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list tensor_canonical_pb_fluid_alpha_surfx_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_alpha_surfx_2x_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list + tensor_canonical_pb_fluid_alpha_surfx_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_alpha_surfx_2x_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB fluid alpha upper edge of configuration space surface expansions in x (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list tensor_canonical_pb_fluid_alpha_edge_surfx_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_alpha_edge_surfx_2x_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list + tensor_canonical_pb_fluid_alpha_edge_surfx_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_alpha_edge_surfx_2x_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB fluid alpha surface expansions in y (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list tensor_canonical_pb_fluid_alpha_surfy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_alpha_surfy_2x_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list + tensor_canonical_pb_fluid_alpha_surfy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_alpha_surfy_2x_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB fluid alpha upper edge of configuration space surface expansions in y (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list tensor_canonical_pb_fluid_alpha_edge_surfy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_alpha_edge_surfy_2x_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_alpha_surf_kern_list + tensor_canonical_pb_fluid_alpha_edge_surfy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_alpha_edge_surfy_2x_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB Hasegawa-Mima source update (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_source_kern_list ser_canonical_pb_fluid_hasegawa_mima_source_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_fluid_hasegawa_mima_source_2x_ser_p1, canonical_pb_fluid_hasegawa_mima_source_2x_ser_p2 }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_source_kern_list + ser_canonical_pb_fluid_hasegawa_mima_source_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_fluid_hasegawa_mima_source_2x_ser_p1, + canonical_pb_fluid_hasegawa_mima_source_2x_ser_p2}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB Hasegawa-Mima source update (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_source_kern_list tensor_canonical_pb_fluid_hasegawa_mima_source_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_fluid_hasegawa_mima_source_2x_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_source_kern_list + tensor_canonical_pb_fluid_hasegawa_mima_source_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_fluid_hasegawa_mima_source_2x_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB Hasegawa-Wakatani source update (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_source_kern_list ser_canonical_pb_fluid_hasegawa_wakatani_source_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_fluid_hasegawa_wakatani_source_2x_ser_p1, canonical_pb_fluid_hasegawa_wakatani_source_2x_ser_p2 }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_source_kern_list + ser_canonical_pb_fluid_hasegawa_wakatani_source_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_fluid_hasegawa_wakatani_source_2x_ser_p1, + canonical_pb_fluid_hasegawa_wakatani_source_2x_ser_p2}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB Hasegawa-Wakatani source update (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_source_kern_list tensor_canonical_pb_fluid_hasegawa_wakatani_source_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_fluid_hasegawa_wakatani_source_2x_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_source_kern_list + tensor_canonical_pb_fluid_hasegawa_wakatani_source_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_fluid_hasegawa_wakatani_source_2x_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB Hasegawa-Wakatani subtract zonal component update (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_subtract_zonal_kern_list ser_canonical_pb_fluid_subtract_zonal_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_fluid_subtract_zonal_2x_ser_p1, canonical_pb_fluid_subtract_zonal_2x_ser_p2 }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_subtract_zonal_kern_list + ser_canonical_pb_fluid_subtract_zonal_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_fluid_subtract_zonal_2x_ser_p1, canonical_pb_fluid_subtract_zonal_2x_ser_p2 + }, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Canonical PB Hasegawa-Wakatani subtract zonal componente update (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_subtract_zonal_kern_list tensor_canonical_pb_fluid_subtract_zonal_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_fluid_subtract_zonal_2x_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_subtract_zonal_kern_list + tensor_canonical_pb_fluid_subtract_zonal_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_fluid_subtract_zonal_2x_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; -GKYL_CU_D -static canonical_pb_fluid_alpha_surf_t -choose_canonical_pb_fluid_alpha_surf_kern(enum gkyl_basis_type b_type, int dir, int cdim, int poly_order) +GKYL_CU_D static canonical_pb_fluid_alpha_surf_t choose_canonical_pb_fluid_alpha_surf_kern( + enum gkyl_basis_type b_type, int dir, int cdim, int poly_order +) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (dir == 0) - return ser_canonical_pb_fluid_alpha_surfx_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ser_canonical_pb_fluid_alpha_surfy_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return tensor_canonical_pb_fluid_alpha_surfx_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return tensor_canonical_pb_fluid_alpha_surfy_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + if (dir == 0) { + return ser_canonical_pb_fluid_alpha_surfx_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ser_canonical_pb_fluid_alpha_surfy_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return tensor_canonical_pb_fluid_alpha_surfx_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return tensor_canonical_pb_fluid_alpha_surfy_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } -GKYL_CU_D -static canonical_pb_fluid_alpha_surf_t -choose_canonical_pb_fluid_alpha_edge_surf_kern(enum gkyl_basis_type b_type, int dir, int cdim, int poly_order) +GKYL_CU_D static canonical_pb_fluid_alpha_surf_t choose_canonical_pb_fluid_alpha_edge_surf_kern( + enum gkyl_basis_type b_type, int dir, int cdim, int poly_order +) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (dir == 0) - return ser_canonical_pb_fluid_alpha_edge_surfx_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ser_canonical_pb_fluid_alpha_edge_surfy_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return tensor_canonical_pb_fluid_alpha_edge_surfx_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return tensor_canonical_pb_fluid_alpha_edge_surfy_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + if (dir == 0) { + return ser_canonical_pb_fluid_alpha_edge_surfx_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ser_canonical_pb_fluid_alpha_edge_surfy_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return tensor_canonical_pb_fluid_alpha_edge_surfx_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return tensor_canonical_pb_fluid_alpha_edge_surfy_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } -GKYL_CU_D -static canonical_pb_fluid_source_t -choose_canonical_pb_fluid_hasegawa_mima_source_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) +GKYL_CU_D static canonical_pb_fluid_source_t choose_canonical_pb_fluid_hasegawa_mima_source_kern( + enum gkyl_basis_type b_type, int cdim, int poly_order +) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_canonical_pb_fluid_hasegawa_mima_source_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return tensor_canonical_pb_fluid_hasegawa_mima_source_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_canonical_pb_fluid_hasegawa_mima_source_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return tensor_canonical_pb_fluid_hasegawa_mima_source_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static canonical_pb_fluid_source_t -choose_canonical_pb_fluid_hasegawa_wakatani_source_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) +GKYL_CU_D static canonical_pb_fluid_source_t +choose_canonical_pb_fluid_hasegawa_wakatani_source_kern( + enum gkyl_basis_type b_type, int cdim, int poly_order +) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_canonical_pb_fluid_hasegawa_wakatani_source_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return tensor_canonical_pb_fluid_hasegawa_wakatani_source_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_canonical_pb_fluid_hasegawa_wakatani_source_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return tensor_canonical_pb_fluid_hasegawa_wakatani_source_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static canonical_pb_fluid_source_t +GKYL_CU_D static canonical_pb_fluid_source_t choose_canonical_pb_fluid_default_source_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { return canonical_pb_fluid_default_source; } -GKYL_CU_D -static canonical_pb_fluid_subtract_zonal_t +GKYL_CU_D static canonical_pb_fluid_subtract_zonal_t choose_canonical_pb_fluid_subtract_zonal_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_canonical_pb_fluid_subtract_zonal_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return tensor_canonical_pb_fluid_subtract_zonal_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_canonical_pb_fluid_subtract_zonal_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return tensor_canonical_pb_fluid_subtract_zonal_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } diff --git a/vlasov/zero/gkyl_dg_calc_canonical_pb_vars.h b/vlasov/zero/gkyl_dg_calc_canonical_pb_vars.h index 09e239a47e..487b754812 100644 --- a/vlasov/zero/gkyl_dg_calc_canonical_pb_vars.h +++ b/vlasov/zero/gkyl_dg_calc_canonical_pb_vars.h @@ -20,17 +20,19 @@ typedef struct gkyl_dg_calc_canonical_pb_vars gkyl_dg_calc_canonical_pb_vars; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_dg_calc_canonical_pb_vars* -gkyl_dg_calc_canonical_pb_vars_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, bool use_gpu); +struct gkyl_dg_calc_canonical_pb_vars *gkyl_dg_calc_canonical_pb_vars_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, bool use_gpu +); /** * Create new updater to compute canonical_pb general geometry variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_dg_calc_canonical_pb_vars* -gkyl_dg_calc_canonical_pb_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis); +struct gkyl_dg_calc_canonical_pb_vars *gkyl_dg_calc_canonical_pb_vars_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis +); /** * Compute surface expansion of phase space flux alpha = {z, H} @@ -46,18 +48,22 @@ gkyl_dg_calc_canonical_pb_vars_cu_dev_new(const struct gkyl_rect_grid *phase_gri * @param const_sgn_alpha Output boolean array for if sign(alpha) is a constant on the surface * If sign(alpha) is a constant, kernels are simpler and we exploit this fact. */ -void gkyl_dg_calc_canonical_pb_vars_alpha_surf(struct gkyl_dg_calc_canonical_pb_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const struct gkyl_range *phase_ext_range, - struct gkyl_array* hamil, - struct gkyl_array* alpha_surf, struct gkyl_array* sgn_alpha_surf, struct gkyl_array* const_sgn_alpha); +void gkyl_dg_calc_canonical_pb_vars_alpha_surf( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *phase_ext_range, + struct gkyl_array *hamil, struct gkyl_array *alpha_surf, struct gkyl_array *sgn_alpha_surf, + struct gkyl_array *const_sgn_alpha +); /** * Host-side wrappers for canonical_pb general geometry variable operations on device */ -void gkyl_dg_calc_canonical_pb_vars_alpha_surf_cu(struct gkyl_dg_calc_canonical_pb_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, const struct gkyl_range *phase_ext_range, - struct gkyl_array* hamil, - struct gkyl_array* alpha_surf, struct gkyl_array* sgn_alpha_surf, struct gkyl_array* const_sgn_alpha); +void gkyl_dg_calc_canonical_pb_vars_alpha_surf_cu( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_range *phase_ext_range, + struct gkyl_array *hamil, struct gkyl_array *alpha_surf, struct gkyl_array *sgn_alpha_surf, + struct gkyl_array *const_sgn_alpha +); /** * Convert the contravaraint components to covariant components of the momentum @@ -71,16 +77,20 @@ void gkyl_dg_calc_canonical_pb_vars_alpha_surf_cu(struct gkyl_dg_calc_canonical_ * @param V_drift_cov Drift velocity moment expansion (covariant components) * @param M1i_cov Drift velocity times density moment expansion (covariant components) */ -void gkyl_canonical_pb_contra_to_covariant_m1i(struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array *h_ij, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, struct gkyl_array *V_drift_cov, - struct gkyl_array *M1i_cov); +void gkyl_canonical_pb_contra_to_covariant_m1i( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *h_ij, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, + struct gkyl_array *V_drift_cov, struct gkyl_array *M1i_cov +); - /** +/** * Host-side wrappers for canonical_pb pressure operations on device */ -void gkyl_canonical_pb_contra_to_covariant_m1i_cu(struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array *h_ij, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, struct gkyl_array *V_drift_cov, - struct gkyl_array *M1i_cov); +void gkyl_canonical_pb_contra_to_covariant_m1i_cu( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *h_ij, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, + struct gkyl_array *V_drift_cov, struct gkyl_array *M1i_cov +); /** * Compute the pressure moment from the energy and velocity moments @@ -94,18 +104,20 @@ void gkyl_canonical_pb_contra_to_covariant_m1i_cu(struct gkyl_dg_calc_canonical_ * @param M1i Drift velocity times density moment expansion (contravariant components) * @param pressure Output, scalar pressure expansion */ -void gkyl_canonical_pb_pressure(struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array *h_ij_inv, - const struct gkyl_array *MEnergy, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, - struct gkyl_array *pressure); +void gkyl_canonical_pb_pressure( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *h_ij_inv, const struct gkyl_array *MEnergy, + const struct gkyl_array *V_drift, const struct gkyl_array *M1i, struct gkyl_array *pressure +); - /** +/** * Host-side wrappers for canonical_pb pressure operations on device */ -void gkyl_canonical_pb_pressure_cu(struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array *h_ij_inv, - const struct gkyl_array *MEnergy, const struct gkyl_array *V_drift, const struct gkyl_array *M1i, - struct gkyl_array *pressure); +void gkyl_canonical_pb_pressure_cu( + struct gkyl_dg_calc_canonical_pb_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *h_ij_inv, const struct gkyl_array *MEnergy, + const struct gkyl_array *V_drift, const struct gkyl_array *M1i, struct gkyl_array *pressure +); /** * Delete pointer to updater to compute canonical_pb general geometry variables. diff --git a/vlasov/zero/gkyl_dg_calc_canonical_pb_vars_priv.h b/vlasov/zero/gkyl_dg_calc_canonical_pb_vars_priv.h index a89a7b1e2f..35149b03a8 100644 --- a/vlasov/zero/gkyl_dg_calc_canonical_pb_vars_priv.h +++ b/vlasov/zero/gkyl_dg_calc_canonical_pb_vars_priv.h @@ -11,26 +11,41 @@ #include #include -typedef int (*canonical_pb_alpha_surf_t)(const double *w, const double *dxv, const double *hamil, - double* GKYL_RESTRICT alpha_surf, double* GKYL_RESTRICT sgn_alpha_surf); -typedef void (*canonical_pb_m1i_contra_to_cov_t)(const double *h_ij, const double *v_i, const double *nv_i, - double* GKYL_RESTRICT v_i_cov, double* GKYL_RESTRICT nv_i_cov); -typedef void (*canonical_pb_pressure_t)(const double *h_ij_inv, const double *MEnergy, const double *v_i, - const double *nv_i, double* GKYL_RESTRICT d_Jv_P); +typedef int (*canonical_pb_alpha_surf_t)( + const double *w, const double *dxv, const double *hamil, double *GKYL_RESTRICT alpha_surf, + double *GKYL_RESTRICT sgn_alpha_surf +); +typedef void (*canonical_pb_m1i_contra_to_cov_t)( + const double *h_ij, const double *v_i, const double *nv_i, double *GKYL_RESTRICT v_i_cov, + double *GKYL_RESTRICT nv_i_cov +); +typedef void (*canonical_pb_pressure_t)( + const double *h_ij_inv, const double *MEnergy, const double *v_i, const double *nv_i, + double *GKYL_RESTRICT d_Jv_P +); // for use in kernel tables -typedef struct { canonical_pb_alpha_surf_t kernels[3]; } gkyl_dg_canonical_pb_alpha_surf_kern_list; -typedef struct { canonical_pb_m1i_contra_to_cov_t kernels[3]; } gkyl_dg_canonical_pb_m1i_contra_to_cov_kern_list; -typedef struct { canonical_pb_pressure_t kernels[3]; } gkyl_dg_canonical_pb_pressure_kern_list; +typedef struct { + canonical_pb_alpha_surf_t kernels[3]; +} gkyl_dg_canonical_pb_alpha_surf_kern_list; +typedef struct { + canonical_pb_m1i_contra_to_cov_t kernels[3]; +} gkyl_dg_canonical_pb_m1i_contra_to_cov_kern_list; +typedef struct { + canonical_pb_pressure_t kernels[3]; +} gkyl_dg_canonical_pb_pressure_kern_list; struct gkyl_dg_calc_canonical_pb_vars { struct gkyl_rect_grid phase_grid; // Phase space grid for cell spacing and cell center int cdim; // Configuration space dimensionality int pdim; // Phase space dimensionality - canonical_pb_alpha_surf_t alpha_surf[6]; // kernel for computing surface expansion of phase space flux alpha - canonical_pb_alpha_surf_t alpha_edge_surf[3]; // kernel for computing surface expansion of phase space flux alpha - // at upper configuration space edge - canonical_pb_m1i_contra_to_cov_t canonical_pb_covariant_u_i; // Canonical pb covariant u_i components + canonical_pb_alpha_surf_t + alpha_surf[6]; // kernel for computing surface expansion of phase space flux alpha + canonical_pb_alpha_surf_t + alpha_edge_surf[3]; // kernel for computing surface expansion of phase space flux alpha + // at upper configuration space edge + canonical_pb_m1i_contra_to_cov_t + canonical_pb_covariant_u_i; // Canonical pb covariant u_i components canonical_pb_pressure_t canonical_pb_pressure; // Canonical pb pressure uint32_t flags; struct gkyl_dg_calc_canonical_pb_vars *on_dev; // pointer to itself or device data @@ -38,520 +53,550 @@ struct gkyl_dg_calc_canonical_pb_vars { // The cv_index[cd].vdim[cd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // // Serendipity surface kernels general geometry // // canonical_pb general geometry phase space flux alpha surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list ser_canonical_pb_alpha_surfx_kernels[] = { - // 1x kernels - { NULL, canonical_pb_alpha_surfx_1x1v_ser_p1, canonical_pb_alpha_surfx_1x1v_ser_p2 }, // 0 - { NULL, canonical_pb_alpha_surfx_1x2v_ser_p1, canonical_pb_alpha_surfx_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_alpha_surfx_1x3v_ser_p1, canonical_pb_alpha_surfx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_surfx_2x2v_ser_p1, canonical_pb_alpha_surfx_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_alpha_surfx_2x3v_ser_p1, canonical_pb_alpha_surfx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + ser_canonical_pb_alpha_surfx_kernels[] = { + // 1x kernels + {NULL, canonical_pb_alpha_surfx_1x1v_ser_p1, canonical_pb_alpha_surfx_1x1v_ser_p2}, // 0 + {NULL, canonical_pb_alpha_surfx_1x2v_ser_p1, canonical_pb_alpha_surfx_1x2v_ser_p2}, // 1 + {NULL, canonical_pb_alpha_surfx_1x3v_ser_p1, canonical_pb_alpha_surfx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_surfx_2x2v_ser_p1, canonical_pb_alpha_surfx_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_alpha_surfx_2x3v_ser_p1, canonical_pb_alpha_surfx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha edge surface expansions in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list ser_canonical_pb_alpha_edge_surfx_kernels[] = { - // 1x kernels - { NULL, canonical_pb_alpha_edge_surfx_1x1v_ser_p1, canonical_pb_alpha_edge_surfx_1x1v_ser_p2 }, // 0 - { NULL, canonical_pb_alpha_edge_surfx_1x2v_ser_p1, canonical_pb_alpha_edge_surfx_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_alpha_edge_surfx_1x3v_ser_p1, canonical_pb_alpha_edge_surfx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_edge_surfx_2x2v_ser_p1, canonical_pb_alpha_edge_surfx_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_alpha_edge_surfx_2x3v_ser_p1, canonical_pb_alpha_edge_surfx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + ser_canonical_pb_alpha_edge_surfx_kernels[] = { + // 1x kernels + {NULL, canonical_pb_alpha_edge_surfx_1x1v_ser_p1, canonical_pb_alpha_edge_surfx_1x1v_ser_p2 + }, // 0 + {NULL, canonical_pb_alpha_edge_surfx_1x2v_ser_p1, canonical_pb_alpha_edge_surfx_1x2v_ser_p2 + }, // 1 + {NULL, canonical_pb_alpha_edge_surfx_1x3v_ser_p1, canonical_pb_alpha_edge_surfx_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_edge_surfx_2x2v_ser_p1, canonical_pb_alpha_edge_surfx_2x2v_ser_p2 + }, // 3 + {NULL, canonical_pb_alpha_edge_surfx_2x3v_ser_p1, canonical_pb_alpha_edge_surfx_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list ser_canonical_pb_alpha_surfy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_surfy_2x2v_ser_p1, canonical_pb_alpha_surfy_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_alpha_surfy_2x3v_ser_p1, canonical_pb_alpha_surfy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + ser_canonical_pb_alpha_surfy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_surfy_2x2v_ser_p1, canonical_pb_alpha_surfy_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_alpha_surfy_2x3v_ser_p1, canonical_pb_alpha_surfy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha edge surface expansions in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list ser_canonical_pb_alpha_edge_surfy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_edge_surfy_2x2v_ser_p1, canonical_pb_alpha_edge_surfy_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_alpha_edge_surfy_2x3v_ser_p1, canonical_pb_alpha_edge_surfy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + ser_canonical_pb_alpha_edge_surfy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_edge_surfy_2x2v_ser_p1, canonical_pb_alpha_edge_surfy_2x2v_ser_p2 + }, // 3 + {NULL, canonical_pb_alpha_edge_surfy_2x3v_ser_p1, canonical_pb_alpha_edge_surfy_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list ser_canonical_pb_alpha_surfz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + ser_canonical_pb_alpha_surfz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha edge surface expansions in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list ser_canonical_pb_alpha_edge_surfz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + ser_canonical_pb_alpha_edge_surfz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // // Serendipity surface kernels general geometry // // canonical_pb general geometry phase space flux alpha surface expansions in vx (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list ser_canonical_pb_alpha_surfvx_kernels[] = { - // 1x kernels - { NULL, canonical_pb_alpha_surfvx_1x1v_ser_p1, canonical_pb_alpha_surfvx_1x1v_ser_p2 }, // 0 - { NULL, canonical_pb_alpha_surfvx_1x2v_ser_p1, canonical_pb_alpha_surfvx_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_alpha_surfvx_1x3v_ser_p1, canonical_pb_alpha_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_surfvx_2x2v_ser_p1, canonical_pb_alpha_surfvx_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_alpha_surfvx_2x3v_ser_p1, canonical_pb_alpha_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + ser_canonical_pb_alpha_surfvx_kernels[] = { + // 1x kernels + {NULL, canonical_pb_alpha_surfvx_1x1v_ser_p1, canonical_pb_alpha_surfvx_1x1v_ser_p2}, // 0 + {NULL, canonical_pb_alpha_surfvx_1x2v_ser_p1, canonical_pb_alpha_surfvx_1x2v_ser_p2}, // 1 + {NULL, canonical_pb_alpha_surfvx_1x3v_ser_p1, canonical_pb_alpha_surfvx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_surfvx_2x2v_ser_p1, canonical_pb_alpha_surfvx_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_alpha_surfvx_2x3v_ser_p1, canonical_pb_alpha_surfvx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; - // canonical_pb general geometry phase space flux alpha surface expansions in vy (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list ser_canonical_pb_alpha_surfvy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, canonical_pb_alpha_surfvy_1x2v_ser_p1, canonical_pb_alpha_surfvy_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_alpha_surfvy_1x3v_ser_p1, canonical_pb_alpha_surfvy_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_surfvy_2x2v_ser_p1, canonical_pb_alpha_surfvy_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_alpha_surfvy_2x3v_ser_p1, canonical_pb_alpha_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + ser_canonical_pb_alpha_surfvy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, canonical_pb_alpha_surfvy_1x2v_ser_p1, canonical_pb_alpha_surfvy_1x2v_ser_p2}, // 1 + {NULL, canonical_pb_alpha_surfvy_1x3v_ser_p1, canonical_pb_alpha_surfvy_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_surfvy_2x2v_ser_p1, canonical_pb_alpha_surfvy_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_alpha_surfvy_2x3v_ser_p1, canonical_pb_alpha_surfvy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha surface expansions in vz (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list ser_canonical_pb_alpha_surfvz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, canonical_pb_alpha_surfvz_1x3v_ser_p1, canonical_pb_alpha_surfvz_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, canonical_pb_alpha_surfvz_2x3v_ser_p1, canonical_pb_alpha_surfvz_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + ser_canonical_pb_alpha_surfvz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, canonical_pb_alpha_surfvz_1x3v_ser_p1, canonical_pb_alpha_surfvz_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, canonical_pb_alpha_surfvz_2x3v_ser_p1, canonical_pb_alpha_surfvz_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // canonical_pb contravaraint to covariant conversion (Serendipity kernels) -// (Jnu_i = h_{ij}Jnu^i and u_i = h_{ij}u^j) -GKYL_CU_D -static const gkyl_dg_canonical_pb_m1i_contra_to_cov_kern_list ser_canonical_pb_m1i_contra_to_cov_kernels[] = { - // 1x kernels - { NULL, canonical_pb_vars_m1i_contra_to_cov_1x1v_ser_p1, canonical_pb_vars_m1i_contra_to_cov_1x1v_ser_p2 }, // 0 - { NULL, canonical_pb_vars_m1i_contra_to_cov_1x2v_ser_p1, canonical_pb_vars_m1i_contra_to_cov_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_vars_m1i_contra_to_cov_1x3v_ser_p1, canonical_pb_vars_m1i_contra_to_cov_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_vars_m1i_contra_to_cov_2x2v_ser_p1, canonical_pb_vars_m1i_contra_to_cov_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_vars_m1i_contra_to_cov_2x3v_ser_p1, canonical_pb_vars_m1i_contra_to_cov_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +// (Jnu_i = h_{ij}Jnu^i and u_i = h_{ij}u^j) +GKYL_CU_D static const gkyl_dg_canonical_pb_m1i_contra_to_cov_kern_list + ser_canonical_pb_m1i_contra_to_cov_kernels[] = { + // 1x kernels + {NULL, canonical_pb_vars_m1i_contra_to_cov_1x1v_ser_p1, + canonical_pb_vars_m1i_contra_to_cov_1x1v_ser_p2}, // 0 + {NULL, canonical_pb_vars_m1i_contra_to_cov_1x2v_ser_p1, + canonical_pb_vars_m1i_contra_to_cov_1x2v_ser_p2}, // 1 + {NULL, canonical_pb_vars_m1i_contra_to_cov_1x3v_ser_p1, + canonical_pb_vars_m1i_contra_to_cov_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_vars_m1i_contra_to_cov_2x2v_ser_p1, + canonical_pb_vars_m1i_contra_to_cov_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_vars_m1i_contra_to_cov_2x3v_ser_p1, + canonical_pb_vars_m1i_contra_to_cov_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; - // canonical_pb Pressure (d*P*Jv = 2*E - n*h^{ij}*u_i*u_j) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_pressure_kern_list ser_canonical_pb_pressure_kernels[] = { - // 1x kernels - { NULL, canonical_pb_vars_pressure_1x1v_ser_p1, canonical_pb_vars_pressure_1x1v_ser_p2 }, // 0 - { NULL, canonical_pb_vars_pressure_1x2v_ser_p1, canonical_pb_vars_pressure_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_vars_pressure_1x3v_ser_p1, canonical_pb_vars_pressure_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_vars_pressure_2x2v_ser_p1, canonical_pb_vars_pressure_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_vars_pressure_2x3v_ser_p1, canonical_pb_vars_pressure_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_pressure_kern_list ser_canonical_pb_pressure_kernels[] = + { + // 1x kernels + {NULL, canonical_pb_vars_pressure_1x1v_ser_p1, canonical_pb_vars_pressure_1x1v_ser_p2}, // 0 + {NULL, canonical_pb_vars_pressure_1x2v_ser_p1, canonical_pb_vars_pressure_1x2v_ser_p2}, // 1 + {NULL, canonical_pb_vars_pressure_1x3v_ser_p1, canonical_pb_vars_pressure_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_vars_pressure_2x2v_ser_p1, canonical_pb_vars_pressure_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_vars_pressure_2x3v_ser_p1, canonical_pb_vars_pressure_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // // Tensor surface kernels general geometry // // canonical_pb general geometry phase space flux alpha surface expansions in x (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list tensor_canonical_pb_alpha_surfx_kernels[] = { - // 1x kernels - { NULL, canonical_pb_alpha_surfx_1x1v_tensor_p1, canonical_pb_alpha_surfx_1x1v_tensor_p2 }, // 0 - { NULL, canonical_pb_alpha_surfx_1x2v_tensor_p1, canonical_pb_alpha_surfx_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_alpha_surfx_1x3v_tensor_p1, canonical_pb_alpha_surfx_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_surfx_2x2v_tensor_p1, canonical_pb_alpha_surfx_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_alpha_surfx_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_alpha_surfx_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + tensor_canonical_pb_alpha_surfx_kernels[] = { + // 1x kernels + {NULL, canonical_pb_alpha_surfx_1x1v_tensor_p1, canonical_pb_alpha_surfx_1x1v_tensor_p2}, // 0 + {NULL, canonical_pb_alpha_surfx_1x2v_tensor_p1, canonical_pb_alpha_surfx_1x2v_tensor_p2}, // 1 + {NULL, canonical_pb_alpha_surfx_1x3v_tensor_p1, canonical_pb_alpha_surfx_1x3v_tensor_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_surfx_2x2v_tensor_p1, canonical_pb_alpha_surfx_2x2v_tensor_p2}, // 3 + {NULL, canonical_pb_alpha_surfx_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_alpha_surfx_3x3v_tensor_p1, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha edge surface expansions in x (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list tensor_canonical_pb_alpha_edge_surfx_kernels[] = { - // 1x kernels - { NULL, canonical_pb_alpha_edge_surfx_1x1v_tensor_p1, canonical_pb_alpha_edge_surfx_1x1v_tensor_p2 }, // 0 - { NULL, canonical_pb_alpha_edge_surfx_1x2v_tensor_p1, canonical_pb_alpha_edge_surfx_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_alpha_edge_surfx_1x3v_tensor_p1, canonical_pb_alpha_edge_surfx_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_edge_surfx_2x2v_tensor_p1, canonical_pb_alpha_edge_surfx_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_alpha_edge_surfx_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_alpha_edge_surfx_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + tensor_canonical_pb_alpha_edge_surfx_kernels[] = { + // 1x kernels + {NULL, canonical_pb_alpha_edge_surfx_1x1v_tensor_p1, + canonical_pb_alpha_edge_surfx_1x1v_tensor_p2}, // 0 + {NULL, canonical_pb_alpha_edge_surfx_1x2v_tensor_p1, + canonical_pb_alpha_edge_surfx_1x2v_tensor_p2}, // 1 + {NULL, canonical_pb_alpha_edge_surfx_1x3v_tensor_p1, + canonical_pb_alpha_edge_surfx_1x3v_tensor_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_edge_surfx_2x2v_tensor_p1, + canonical_pb_alpha_edge_surfx_2x2v_tensor_p2}, // 3 + {NULL, canonical_pb_alpha_edge_surfx_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_alpha_edge_surfx_3x3v_tensor_p1, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha surface expansions in y (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list tensor_canonical_pb_alpha_surfy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_surfy_2x2v_tensor_p1, canonical_pb_alpha_surfy_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_alpha_surfy_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_alpha_surfy_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + tensor_canonical_pb_alpha_surfy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_surfy_2x2v_tensor_p1, canonical_pb_alpha_surfy_2x2v_tensor_p2}, // 3 + {NULL, canonical_pb_alpha_surfy_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_alpha_surfy_3x3v_tensor_p1, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha edge surface expansions in y (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list tensor_canonical_pb_alpha_edge_surfy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_edge_surfy_2x2v_tensor_p1, canonical_pb_alpha_edge_surfy_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_alpha_edge_surfy_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_alpha_edge_surfy_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + tensor_canonical_pb_alpha_edge_surfy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_edge_surfy_2x2v_tensor_p1, + canonical_pb_alpha_edge_surfy_2x2v_tensor_p2}, // 3 + {NULL, canonical_pb_alpha_edge_surfy_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_alpha_edge_surfy_3x3v_tensor_p1, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha surface expansions in z (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list tensor_canonical_pb_alpha_surfz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_alpha_surfz_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + tensor_canonical_pb_alpha_surfz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_alpha_surfz_3x3v_tensor_p1, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha edge surface expansions in z (tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list tensor_canonical_pb_alpha_edge_surfz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_alpha_edge_surfz_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + tensor_canonical_pb_alpha_edge_surfz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_alpha_edge_surfz_3x3v_tensor_p1, NULL} // 5 }; // // Tensor surface kernels general geometry // // canonical_pb general geometry phase space flux alpha surface expansions in vx (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list tensor_canonical_pb_alpha_surfvx_kernels[] = { - // 1x kernels - { NULL, canonical_pb_alpha_surfvx_1x1v_tensor_p1, canonical_pb_alpha_surfvx_1x1v_tensor_p2 }, // 0 - { NULL, canonical_pb_alpha_surfvx_1x2v_tensor_p1, canonical_pb_alpha_surfvx_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_alpha_surfvx_1x3v_tensor_p1, canonical_pb_alpha_surfvx_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_surfvx_2x2v_tensor_p1, canonical_pb_alpha_surfvx_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_alpha_surfvx_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_alpha_surfvx_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + tensor_canonical_pb_alpha_surfvx_kernels[] = { + // 1x kernels + {NULL, canonical_pb_alpha_surfvx_1x1v_tensor_p1, canonical_pb_alpha_surfvx_1x1v_tensor_p2}, // 0 + {NULL, canonical_pb_alpha_surfvx_1x2v_tensor_p1, canonical_pb_alpha_surfvx_1x2v_tensor_p2}, // 1 + {NULL, canonical_pb_alpha_surfvx_1x3v_tensor_p1, canonical_pb_alpha_surfvx_1x3v_tensor_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_surfvx_2x2v_tensor_p1, canonical_pb_alpha_surfvx_2x2v_tensor_p2}, // 3 + {NULL, canonical_pb_alpha_surfvx_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_alpha_surfvx_3x3v_tensor_p1, NULL} // 5 }; - // canonical_pb general geometry phase space flux alpha surface expansions in vy (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list tensor_canonical_pb_alpha_surfvy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, canonical_pb_alpha_surfvy_1x2v_tensor_p1, canonical_pb_alpha_surfvy_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_alpha_surfvy_1x3v_tensor_p1, canonical_pb_alpha_surfvy_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_alpha_surfvy_2x2v_tensor_p1, canonical_pb_alpha_surfvy_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_alpha_surfvy_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_alpha_surfvy_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + tensor_canonical_pb_alpha_surfvy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, canonical_pb_alpha_surfvy_1x2v_tensor_p1, canonical_pb_alpha_surfvy_1x2v_tensor_p2}, // 1 + {NULL, canonical_pb_alpha_surfvy_1x3v_tensor_p1, canonical_pb_alpha_surfvy_1x3v_tensor_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_alpha_surfvy_2x2v_tensor_p1, canonical_pb_alpha_surfvy_2x2v_tensor_p2}, // 3 + {NULL, canonical_pb_alpha_surfvy_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_alpha_surfvy_3x3v_tensor_p1, NULL} // 5 }; // canonical_pb general geometry phase space flux alpha surface expansions in vz (tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_alpha_surf_kern_list tensor_canonical_pb_alpha_surfvz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, canonical_pb_alpha_surfvz_1x3v_tensor_p1, canonical_pb_alpha_surfvz_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, canonical_pb_alpha_surfvz_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_alpha_surfvz_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_alpha_surf_kern_list + tensor_canonical_pb_alpha_surfvz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, canonical_pb_alpha_surfvz_1x3v_tensor_p1, canonical_pb_alpha_surfvz_1x3v_tensor_p2}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, canonical_pb_alpha_surfvz_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_alpha_surfvz_3x3v_tensor_p1, NULL} // 5 }; // canonical_pb contravaraint to covariant conversion (Tensor kernels) -// (Jnu_i = h_{ij}Jnu^i and u_i = h_{ij}u^j) -GKYL_CU_D -static const gkyl_dg_canonical_pb_m1i_contra_to_cov_kern_list tensor_canonical_pb_m1i_contra_to_cov_kernels[] = { - // 1x kernels - { NULL, canonical_pb_vars_m1i_contra_to_cov_1x1v_tensor_p1, canonical_pb_vars_m1i_contra_to_cov_1x1v_tensor_p2 }, // 0 - { NULL, canonical_pb_vars_m1i_contra_to_cov_1x2v_tensor_p1, canonical_pb_vars_m1i_contra_to_cov_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_vars_m1i_contra_to_cov_1x3v_tensor_p1, canonical_pb_vars_m1i_contra_to_cov_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_vars_m1i_contra_to_cov_2x2v_tensor_p1, canonical_pb_vars_m1i_contra_to_cov_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_vars_m1i_contra_to_cov_2x3v_tensor_p1, NULL }, //4 - // 3x kernels - { NULL, canonical_pb_vars_m1i_contra_to_cov_3x3v_tensor_p1, NULL }, // 5 +// (Jnu_i = h_{ij}Jnu^i and u_i = h_{ij}u^j) +GKYL_CU_D static const gkyl_dg_canonical_pb_m1i_contra_to_cov_kern_list + tensor_canonical_pb_m1i_contra_to_cov_kernels[] = { + // 1x kernels + {NULL, canonical_pb_vars_m1i_contra_to_cov_1x1v_tensor_p1, + canonical_pb_vars_m1i_contra_to_cov_1x1v_tensor_p2}, // 0 + {NULL, canonical_pb_vars_m1i_contra_to_cov_1x2v_tensor_p1, + canonical_pb_vars_m1i_contra_to_cov_1x2v_tensor_p2}, // 1 + {NULL, canonical_pb_vars_m1i_contra_to_cov_1x3v_tensor_p1, + canonical_pb_vars_m1i_contra_to_cov_1x3v_tensor_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_vars_m1i_contra_to_cov_2x2v_tensor_p1, + canonical_pb_vars_m1i_contra_to_cov_2x2v_tensor_p2}, // 3 + {NULL, canonical_pb_vars_m1i_contra_to_cov_2x3v_tensor_p1, NULL}, //4 + // 3x kernels + {NULL, canonical_pb_vars_m1i_contra_to_cov_3x3v_tensor_p1, NULL} // 5 }; - // canonical_pb Pressure (d*P*Jv = h^{ij}*M2_{ij} - n*h^{ij}*u_i*u_j) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_canonical_pb_pressure_kern_list tensor_canonical_pb_pressure_kernels[] = { - // 1x kernels - { NULL, canonical_pb_vars_pressure_1x1v_tensor_p1, canonical_pb_vars_pressure_1x1v_tensor_p2 }, // 0 - { NULL, canonical_pb_vars_pressure_1x2v_tensor_p1, canonical_pb_vars_pressure_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_vars_pressure_1x3v_tensor_p1, canonical_pb_vars_pressure_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_vars_pressure_2x2v_tensor_p1, canonical_pb_vars_pressure_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_vars_pressure_2x3v_tensor_p1, NULL }, //4 - // 3x kernels - { NULL, canonical_pb_vars_pressure_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_pressure_kern_list + tensor_canonical_pb_pressure_kernels[] = { + // 1x kernels + {NULL, canonical_pb_vars_pressure_1x1v_tensor_p1, canonical_pb_vars_pressure_1x1v_tensor_p2 + }, // 0 + {NULL, canonical_pb_vars_pressure_1x2v_tensor_p1, canonical_pb_vars_pressure_1x2v_tensor_p2 + }, // 1 + {NULL, canonical_pb_vars_pressure_1x3v_tensor_p1, canonical_pb_vars_pressure_1x3v_tensor_p2 + }, // 2 + // 2x kernels + {NULL, canonical_pb_vars_pressure_2x2v_tensor_p1, canonical_pb_vars_pressure_2x2v_tensor_p2 + }, // 3 + {NULL, canonical_pb_vars_pressure_2x3v_tensor_p1, NULL}, //4 + // 3x kernels + {NULL, canonical_pb_vars_pressure_3x3v_tensor_p1, NULL} // 5 }; - -GKYL_CU_D -static canonical_pb_alpha_surf_t -choose_canonical_pb_alpha_surf_kern(enum gkyl_basis_type b_type, int dir, int cv_index, int cdim, int vdim, int poly_order) +GKYL_CU_D static canonical_pb_alpha_surf_t choose_canonical_pb_alpha_surf_kern( + enum gkyl_basis_type b_type, int dir, int cv_index, int cdim, int vdim, int poly_order +) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Verify that the poly-order is 2 for ser case - assert(poly_order == 2); - if (dir == 0) - return ser_canonical_pb_alpha_surfx_kernels[cv_index].kernels[poly_order]; - else if (dir == 1) - return ser_canonical_pb_alpha_surfy_kernels[cv_index].kernels[poly_order]; - else if (dir == 2) - return ser_canonical_pb_alpha_surfz_kernels[cv_index].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_HYBRID: - // Verify that the poly-order is 1 for hybrid case - assert(poly_order == 1); - if (dir == 0) - return ser_canonical_pb_alpha_surfx_kernels[cv_index].kernels[poly_order]; - else if (dir == 1) - return ser_canonical_pb_alpha_surfy_kernels[cv_index].kernels[poly_order]; - else if (dir == 2) - return ser_canonical_pb_alpha_surfz_kernels[cv_index].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return tensor_canonical_pb_alpha_surfx_kernels[cv_index].kernels[poly_order]; - else if (dir == 1) - return tensor_canonical_pb_alpha_surfy_kernels[cv_index].kernels[poly_order]; - else if (dir == 2) - return tensor_canonical_pb_alpha_surfz_kernels[cv_index].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + // Verify that the poly-order is 2 for ser case + assert(poly_order == 2); + if (dir == 0) { + return ser_canonical_pb_alpha_surfx_kernels[cv_index].kernels[poly_order]; + } else if (dir == 1) { + return ser_canonical_pb_alpha_surfy_kernels[cv_index].kernels[poly_order]; + } else if (dir == 2) { + return ser_canonical_pb_alpha_surfz_kernels[cv_index].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_HYBRID: + // Verify that the poly-order is 1 for hybrid case + assert(poly_order == 1); + if (dir == 0) { + return ser_canonical_pb_alpha_surfx_kernels[cv_index].kernels[poly_order]; + } else if (dir == 1) { + return ser_canonical_pb_alpha_surfy_kernels[cv_index].kernels[poly_order]; + } else if (dir == 2) { + return ser_canonical_pb_alpha_surfz_kernels[cv_index].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return tensor_canonical_pb_alpha_surfx_kernels[cv_index].kernels[poly_order]; + } else if (dir == 1) { + return tensor_canonical_pb_alpha_surfy_kernels[cv_index].kernels[poly_order]; + } else if (dir == 2) { + return tensor_canonical_pb_alpha_surfz_kernels[cv_index].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } -GKYL_CU_D -static canonical_pb_alpha_surf_t -choose_canonical_pb_alpha_edge_surf_kern(enum gkyl_basis_type b_type, int dir, int cv_index, int cdim, int vdim, int poly_order) +GKYL_CU_D static canonical_pb_alpha_surf_t choose_canonical_pb_alpha_edge_surf_kern( + enum gkyl_basis_type b_type, int dir, int cv_index, int cdim, int vdim, int poly_order +) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Verify that the poly-order is 2 for ser case - assert(poly_order == 2); - if (dir == 0) - return ser_canonical_pb_alpha_edge_surfx_kernels[cv_index].kernels[poly_order]; - else if (dir == 1) - return ser_canonical_pb_alpha_edge_surfy_kernels[cv_index].kernels[poly_order]; - else if (dir == 2) - return ser_canonical_pb_alpha_edge_surfz_kernels[cv_index].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_HYBRID: - // Verify that the poly-order is 1 for hybrid case - assert(poly_order == 1); - if (dir == 0) - return ser_canonical_pb_alpha_edge_surfx_kernels[cv_index].kernels[poly_order]; - else if (dir == 1) - return ser_canonical_pb_alpha_edge_surfy_kernels[cv_index].kernels[poly_order]; - else if (dir == 2) - return ser_canonical_pb_alpha_edge_surfz_kernels[cv_index].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return tensor_canonical_pb_alpha_edge_surfx_kernels[cv_index].kernels[poly_order]; - else if (dir == 1) - return tensor_canonical_pb_alpha_edge_surfy_kernels[cv_index].kernels[poly_order]; - else if (dir == 2) - return tensor_canonical_pb_alpha_edge_surfz_kernels[cv_index].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + // Verify that the poly-order is 2 for ser case + assert(poly_order == 2); + if (dir == 0) { + return ser_canonical_pb_alpha_edge_surfx_kernels[cv_index].kernels[poly_order]; + } else if (dir == 1) { + return ser_canonical_pb_alpha_edge_surfy_kernels[cv_index].kernels[poly_order]; + } else if (dir == 2) { + return ser_canonical_pb_alpha_edge_surfz_kernels[cv_index].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_HYBRID: + // Verify that the poly-order is 1 for hybrid case + assert(poly_order == 1); + if (dir == 0) { + return ser_canonical_pb_alpha_edge_surfx_kernels[cv_index].kernels[poly_order]; + } else if (dir == 1) { + return ser_canonical_pb_alpha_edge_surfy_kernels[cv_index].kernels[poly_order]; + } else if (dir == 2) { + return ser_canonical_pb_alpha_edge_surfz_kernels[cv_index].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return tensor_canonical_pb_alpha_edge_surfx_kernels[cv_index].kernels[poly_order]; + } else if (dir == 1) { + return tensor_canonical_pb_alpha_edge_surfy_kernels[cv_index].kernels[poly_order]; + } else if (dir == 2) { + return tensor_canonical_pb_alpha_edge_surfz_kernels[cv_index].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } - -GKYL_CU_D -static canonical_pb_alpha_surf_t -choose_canonical_pb_alpha_surf_v_kern(enum gkyl_basis_type b_type, int dir, int cv_index, int cdim, int vdim, int poly_order) +GKYL_CU_D static canonical_pb_alpha_surf_t choose_canonical_pb_alpha_surf_v_kern( + enum gkyl_basis_type b_type, int dir, int cv_index, int cdim, int vdim, int poly_order +) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Verify that the poly-order is 2 for ser case - assert(poly_order == 2); - if (dir == 0) - return ser_canonical_pb_alpha_surfvx_kernels[cv_index].kernels[poly_order]; - else if (dir == 1) - return ser_canonical_pb_alpha_surfvy_kernels[cv_index].kernels[poly_order]; - else if (dir == 2) - return ser_canonical_pb_alpha_surfvz_kernels[cv_index].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_HYBRID: - // Verify that the poly-order is 1 for hybrid case - assert(poly_order == 1); - if (dir == 0) - return ser_canonical_pb_alpha_surfvx_kernels[cv_index].kernels[poly_order]; - else if (dir == 1) - return ser_canonical_pb_alpha_surfvy_kernels[cv_index].kernels[poly_order]; - else if (dir == 2) - return ser_canonical_pb_alpha_surfvz_kernels[cv_index].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return tensor_canonical_pb_alpha_surfvx_kernels[cv_index].kernels[poly_order]; - else if (dir == 1) - return tensor_canonical_pb_alpha_surfvy_kernels[cv_index].kernels[poly_order]; - else if (dir == 2) - return tensor_canonical_pb_alpha_surfvz_kernels[cv_index].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + // Verify that the poly-order is 2 for ser case + assert(poly_order == 2); + if (dir == 0) { + return ser_canonical_pb_alpha_surfvx_kernels[cv_index].kernels[poly_order]; + } else if (dir == 1) { + return ser_canonical_pb_alpha_surfvy_kernels[cv_index].kernels[poly_order]; + } else if (dir == 2) { + return ser_canonical_pb_alpha_surfvz_kernels[cv_index].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_HYBRID: + // Verify that the poly-order is 1 for hybrid case + assert(poly_order == 1); + if (dir == 0) { + return ser_canonical_pb_alpha_surfvx_kernels[cv_index].kernels[poly_order]; + } else if (dir == 1) { + return ser_canonical_pb_alpha_surfvy_kernels[cv_index].kernels[poly_order]; + } else if (dir == 2) { + return ser_canonical_pb_alpha_surfvz_kernels[cv_index].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return tensor_canonical_pb_alpha_surfvx_kernels[cv_index].kernels[poly_order]; + } else if (dir == 1) { + return tensor_canonical_pb_alpha_surfvy_kernels[cv_index].kernels[poly_order]; + } else if (dir == 2) { + return tensor_canonical_pb_alpha_surfvz_kernels[cv_index].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } -GKYL_CU_D -static canonical_pb_m1i_contra_to_cov_t -choose_canonical_pb_m1i_contra_to_cov_kern(enum gkyl_basis_type b_type, int cv_index, int cdim, int poly_order) +GKYL_CU_D static canonical_pb_m1i_contra_to_cov_t choose_canonical_pb_m1i_contra_to_cov_kern( + enum gkyl_basis_type b_type, int cv_index, int cdim, int poly_order +) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Verify that the poly-order is 2 for ser case - assert(poly_order == 2); - return ser_canonical_pb_m1i_contra_to_cov_kernels[cv_index].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_HYBRID: - // Verify that the poly-order is 1 for hybrid case - assert(poly_order == 1); - return ser_canonical_pb_m1i_contra_to_cov_kernels[cv_index].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return tensor_canonical_pb_m1i_contra_to_cov_kernels[cv_index].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + // Verify that the poly-order is 2 for ser case + assert(poly_order == 2); + return ser_canonical_pb_m1i_contra_to_cov_kernels[cv_index].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_HYBRID: + // Verify that the poly-order is 1 for hybrid case + assert(poly_order == 1); + return ser_canonical_pb_m1i_contra_to_cov_kernels[cv_index].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return tensor_canonical_pb_m1i_contra_to_cov_kernels[cv_index].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static canonical_pb_pressure_t -choose_canonical_pb_pressure_kern(enum gkyl_basis_type b_type, int cv_index, int cdim, int poly_order) +GKYL_CU_D static canonical_pb_pressure_t choose_canonical_pb_pressure_kern( + enum gkyl_basis_type b_type, int cv_index, int cdim, int poly_order +) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Verify that the poly-order is 2 for ser case - assert(poly_order == 2); - return ser_canonical_pb_pressure_kernels[cv_index].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_HYBRID: - // Verify that the poly-order is 1 for hybrid case - assert(poly_order == 1); - return ser_canonical_pb_pressure_kernels[cv_index].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return tensor_canonical_pb_pressure_kernels[cv_index].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + // Verify that the poly-order is 2 for ser case + assert(poly_order == 2); + return ser_canonical_pb_pressure_kernels[cv_index].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_HYBRID: + // Verify that the poly-order is 1 for hybrid case + assert(poly_order == 1); + return ser_canonical_pb_pressure_kernels[cv_index].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return tensor_canonical_pb_pressure_kernels[cv_index].kernels[poly_order]; + break; + default: + assert(false); + break; } } \ No newline at end of file diff --git a/vlasov/zero/gkyl_dg_calc_em_vars.h b/vlasov/zero/gkyl_dg_calc_em_vars.h index 057c79e520..e0610b677b 100644 --- a/vlasov/zero/gkyl_dg_calc_em_vars.h +++ b/vlasov/zero/gkyl_dg_calc_em_vars.h @@ -7,7 +7,6 @@ #include #include - // Object type typedef struct gkyl_dg_calc_em_vars gkyl_dg_calc_em_vars; @@ -39,21 +38,21 @@ typedef struct gkyl_dg_calc_em_vars gkyl_dg_calc_em_vars; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_dg_calc_em_vars* -gkyl_dg_calc_em_vars_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis* cbasis, const struct gkyl_range *mem_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, - double limiter_fac, bool is_ExB, bool use_gpu); +struct gkyl_dg_calc_em_vars *gkyl_dg_calc_em_vars_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *cbasis, + const struct gkyl_range *mem_range, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_geom *geom, double limiter_fac, bool is_ExB, bool use_gpu +); /** * Create new updater to compute EM variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_dg_calc_em_vars* -gkyl_dg_calc_em_vars_cu_dev_new(const struct gkyl_rect_grid *conf_grid, - const struct gkyl_basis* cbasis, const struct gkyl_range *conf_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, - double limiter_fac, bool is_ExB); +struct gkyl_dg_calc_em_vars *gkyl_dg_calc_em_vars_cu_dev_new( + const struct gkyl_rect_grid *conf_grid, const struct gkyl_basis *cbasis, + const struct gkyl_range *conf_range, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_geom *geom, double limiter_fac, bool is_ExB +); /** * Compute either @@ -73,9 +72,10 @@ gkyl_dg_calc_em_vars_cu_dev_new(const struct gkyl_rect_grid *conf_grid, * @param out Output array of volume expansion of either magnetic field unit vector and unit tensor or E x B velocity * @param out_surf Output array of surface expansion of EM variable */ -void gkyl_dg_calc_em_vars_advance(struct gkyl_dg_calc_em_vars *up, - const struct gkyl_array* em, struct gkyl_array* cell_avg_magB2, - struct gkyl_array* out, struct gkyl_array* out_surf); +void gkyl_dg_calc_em_vars_advance( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_array *em, struct gkyl_array *cell_avg_magB2, + struct gkyl_array *out, struct gkyl_array *out_surf +); /** * Compute div(b) and max(|b_i|) penalization @@ -87,9 +87,11 @@ void gkyl_dg_calc_em_vars_advance(struct gkyl_dg_calc_em_vars *up, * @param max_b Output array of max(|b_i|) penalization * @param div_b Output array of div(b) */ -void gkyl_dg_calc_em_vars_div_b(struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* bvar_surf, const struct gkyl_array* bvar, - struct gkyl_array* max_b, struct gkyl_array* div_b); +void gkyl_dg_calc_em_vars_div_b( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *bvar_surf, const struct gkyl_array *bvar, struct gkyl_array *max_b, + struct gkyl_array *div_b +); /** * Limit slopes for EM variables @@ -98,8 +100,9 @@ void gkyl_dg_calc_em_vars_div_b(struct gkyl_dg_calc_em_vars *up, const struct gk * @param conf_range Configuration space range * @param em Input (and Output after limiting) array of em variables [Ex, Ey, Ez, Bx, By, Bz, phi, psi] */ -void gkyl_dg_calc_em_vars_limiter(struct gkyl_dg_calc_em_vars *up, - const struct gkyl_range *conf_range, struct gkyl_array* em); +void gkyl_dg_calc_em_vars_limiter( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, struct gkyl_array *em +); /** * Delete pointer to updater to compute EM variables. @@ -112,14 +115,17 @@ void gkyl_dg_calc_em_vars_release(struct gkyl_dg_calc_em_vars *up); * Host-side wrappers for em vars operations on device */ -void gkyl_dg_calc_em_vars_advance_cu(struct gkyl_dg_calc_em_vars *up, - const struct gkyl_array* em, struct gkyl_array* cell_avg_magB2, - struct gkyl_array* out, struct gkyl_array* out_surf); - -void gkyl_dg_calc_em_vars_div_b_cu(struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, - const struct gkyl_array* bvar_surf, const struct gkyl_array* bvar, - struct gkyl_array* max_b, struct gkyl_array* div_b); +void gkyl_dg_calc_em_vars_advance_cu( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_array *em, struct gkyl_array *cell_avg_magB2, + struct gkyl_array *out, struct gkyl_array *out_surf +); -void gkyl_dg_calc_em_vars_limiter_cu(struct gkyl_dg_calc_em_vars *up, - const struct gkyl_range *conf_range, struct gkyl_array* em); +void gkyl_dg_calc_em_vars_div_b_cu( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *bvar_surf, const struct gkyl_array *bvar, struct gkyl_array *max_b, + struct gkyl_array *div_b +); +void gkyl_dg_calc_em_vars_limiter_cu( + struct gkyl_dg_calc_em_vars *up, const struct gkyl_range *conf_range, struct gkyl_array *em +); diff --git a/vlasov/zero/gkyl_dg_calc_em_vars_priv.h b/vlasov/zero/gkyl_dg_calc_em_vars_priv.h index 5337208fe0..b88914b1ba 100644 --- a/vlasov/zero/gkyl_dg_calc_em_vars_priv.h +++ b/vlasov/zero/gkyl_dg_calc_em_vars_priv.h @@ -11,30 +11,51 @@ #include #include -typedef void (*em_calc_temp_t)(const double *em, double* GKYL_RESTRICT out); +typedef void (*em_calc_temp_t)(const double *em, double *GKYL_RESTRICT out); typedef int (*em_set_t)(int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, const double *temp); -typedef void (*em_copy_t)(int count, struct gkyl_nmat *x, const double *em, int* cell_avg_magB2, - double* GKYL_RESTRICT out, double* GKYL_RESTRICT out_surf); +typedef void (*em_copy_t)( + int count, struct gkyl_nmat *x, const double *em, int *cell_avg_magB2, double *GKYL_RESTRICT out, + double *GKYL_RESTRICT out_surf +); -typedef void (*em_div_b_t)(const double *dxv, - const double *bvar_surf_l, const double *bvar_surf_c, const double *bvar_surf_r, - const double *bvar_c, double* GKYL_RESTRICT max_b, double* GKYL_RESTRICT div_b); +typedef void (*em_div_b_t)( + const double *dxv, const double *bvar_surf_l, const double *bvar_surf_c, + const double *bvar_surf_r, const double *bvar_c, double *GKYL_RESTRICT max_b, + double *GKYL_RESTRICT div_b +); -typedef void (*em_limiter_t)(double limiter_fac, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_cell_geom *geom, - double *ql, double *qc, double *qr); +typedef void (*em_limiter_t)( + double limiter_fac, const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_cell_geom *geom, + double *ql, double *qc, double *qr +); // for use in kernel tables -typedef struct { em_calc_temp_t kernels[4]; } gkyl_dg_em_calc_BB_kern_list; -typedef struct { em_calc_temp_t kernels[4]; } gkyl_dg_em_calc_num_ExB_kern_list; -typedef struct { em_set_t kernels[4]; } gkyl_dg_em_set_bvar_kern_list; -typedef struct { em_set_t kernels[4]; } gkyl_dg_em_set_ExB_kern_list; -typedef struct { em_copy_t kernels[4]; } gkyl_dg_em_copy_bvar_kern_list; -typedef struct { em_copy_t kernels[4]; } gkyl_dg_em_copy_ExB_kern_list; -typedef struct { em_div_b_t kernels[4]; } gkyl_dg_em_div_b_kern_list; -typedef struct { em_limiter_t kernels[4]; } gkyl_dg_em_limiter_kern_list; +typedef struct { + em_calc_temp_t kernels[4]; +} gkyl_dg_em_calc_BB_kern_list; +typedef struct { + em_calc_temp_t kernels[4]; +} gkyl_dg_em_calc_num_ExB_kern_list; +typedef struct { + em_set_t kernels[4]; +} gkyl_dg_em_set_bvar_kern_list; +typedef struct { + em_set_t kernels[4]; +} gkyl_dg_em_set_ExB_kern_list; +typedef struct { + em_copy_t kernels[4]; +} gkyl_dg_em_copy_bvar_kern_list; +typedef struct { + em_copy_t kernels[4]; +} gkyl_dg_em_copy_ExB_kern_list; +typedef struct { + em_div_b_t kernels[4]; +} gkyl_dg_em_div_b_kern_list; +typedef struct { + em_limiter_t kernels[4]; +} gkyl_dg_em_limiter_kern_list; struct gkyl_dg_calc_em_vars { struct gkyl_rect_grid conf_grid; // Configuration space grid for cell spacing and cell center @@ -44,7 +65,8 @@ struct gkyl_dg_calc_em_vars { const struct gkyl_wv_eqn *wv_eqn; // Wave equation for characteristic limiting of solution const struct gkyl_wave_geom *geom; // Wave geometry for rotating solution - double limiter_fac; // Factor for relationship between cell slopes and cell average differences (by default: 1/sqrt(3)) + double + limiter_fac; // Factor for relationship between cell slopes and cell average differences (by default: 1/sqrt(3)) struct gkyl_nmat *As, *xs; // matrices for LHS and RHS gkyl_nmat_mem *mem; // memory for use in batched linear solve @@ -52,8 +74,8 @@ struct gkyl_dg_calc_em_vars { int Ncomp; // number of components in the linear solve (3 for E x B, 6 for bb) em_calc_temp_t em_calc_temp; // kernel for intermediate variable computation - em_set_t em_set; // kernel for setting matrices for linear solve - em_copy_t em_copy; // kernel for copying solution to output, also computes needed surface expansions + em_set_t em_set; // kernel for setting matrices for linear solve + em_copy_t em_copy; // kernel for copying solution to output, also computes needed surface expansions em_div_b_t em_div_b[3]; // kernel for computing div(b) and max(|b_i|) penalization em_limiter_t em_limiter[3]; // kernel for limiting slopes of em variables @@ -62,356 +84,328 @@ struct gkyl_dg_calc_em_vars { }; // Compute BB tensor for computing bb and b (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_em_calc_BB_kern_list ser_em_calc_BB_kernels[] = { - { NULL, em_calc_BB_1x_ser_p1, em_calc_BB_1x_ser_p2, em_calc_BB_1x_ser_p3 }, // 0 - { NULL, em_calc_BB_2x_ser_p1, NULL, NULL }, // 1 - { NULL, em_calc_BB_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_calc_BB_kern_list ser_em_calc_BB_kernels[] = { + {NULL, em_calc_BB_1x_ser_p1, em_calc_BB_1x_ser_p2, em_calc_BB_1x_ser_p3}, // 0 + {NULL, em_calc_BB_2x_ser_p1, NULL, NULL}, // 1 + {NULL, em_calc_BB_3x_ser_p1, NULL, NULL} // 2 }; // Compute BB tensor for computing bb and b (Tensor basis) -GKYL_CU_D -static const gkyl_dg_em_calc_BB_kern_list ten_em_calc_BB_kernels[] = { - { NULL, em_calc_BB_1x_ser_p1, em_calc_BB_1x_ser_p2, em_calc_BB_1x_ser_p3 }, // 0 - { NULL, em_calc_BB_2x_ser_p1, em_calc_BB_2x_tensor_p2, NULL }, // 1 - { NULL, em_calc_BB_3x_ser_p1, em_calc_BB_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_calc_BB_kern_list ten_em_calc_BB_kernels[] = { + {NULL, em_calc_BB_1x_ser_p1, em_calc_BB_1x_ser_p2, em_calc_BB_1x_ser_p3}, // 0 + {NULL, em_calc_BB_2x_ser_p1, em_calc_BB_2x_tensor_p2, NULL}, // 1 + {NULL, em_calc_BB_3x_ser_p1, em_calc_BB_3x_tensor_p2, NULL} // 2 }; // Compute (E x B)_i and B_i^2 (numerator and denominator of E x B velocity) (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_em_calc_num_ExB_kern_list ser_em_calc_num_ExB_kernels[] = { - { NULL, em_calc_num_ExB_1x_ser_p1, em_calc_num_ExB_1x_ser_p2, em_calc_num_ExB_1x_ser_p3 }, // 0 - { NULL, em_calc_num_ExB_2x_ser_p1, NULL, NULL }, // 1 - { NULL, em_calc_num_ExB_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_calc_num_ExB_kern_list ser_em_calc_num_ExB_kernels[] = { + {NULL, em_calc_num_ExB_1x_ser_p1, em_calc_num_ExB_1x_ser_p2, em_calc_num_ExB_1x_ser_p3}, // 0 + {NULL, em_calc_num_ExB_2x_ser_p1, NULL, NULL}, // 1 + {NULL, em_calc_num_ExB_3x_ser_p1, NULL, NULL} // 2 }; // Compute (E x B)_i and B_i^2 (numerator and denominator of E x B velocity) (Tensor basis) -GKYL_CU_D -static const gkyl_dg_em_calc_num_ExB_kern_list ten_em_calc_num_ExB_kernels[] = { - { NULL, em_calc_num_ExB_1x_ser_p1, em_calc_num_ExB_1x_ser_p2, em_calc_num_ExB_1x_ser_p3 }, // 0 - { NULL, em_calc_num_ExB_2x_ser_p1, em_calc_num_ExB_2x_tensor_p2, NULL }, // 1 - { NULL, em_calc_num_ExB_3x_ser_p1, em_calc_num_ExB_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_calc_num_ExB_kern_list ten_em_calc_num_ExB_kernels[] = { + {NULL, em_calc_num_ExB_1x_ser_p1, em_calc_num_ExB_1x_ser_p2, em_calc_num_ExB_1x_ser_p3}, // 0 + {NULL, em_calc_num_ExB_2x_ser_p1, em_calc_num_ExB_2x_tensor_p2, NULL}, // 1 + {NULL, em_calc_num_ExB_3x_ser_p1, em_calc_num_ExB_3x_tensor_p2, NULL} // 2 }; // Set matrices for computing bb, p=1 analytically solved (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_em_set_bvar_kern_list ser_em_set_bvar_kernels[] = { - { NULL, em_set_bvar_1x_ser_p1, em_set_bvar_1x_ser_p2, em_set_bvar_1x_ser_p3 }, // 0 - { NULL, em_set_bvar_2x_ser_p1, NULL, NULL }, // 1 - { NULL, em_set_bvar_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_set_bvar_kern_list ser_em_set_bvar_kernels[] = { + {NULL, em_set_bvar_1x_ser_p1, em_set_bvar_1x_ser_p2, em_set_bvar_1x_ser_p3}, // 0 + {NULL, em_set_bvar_2x_ser_p1, NULL, NULL}, // 1 + {NULL, em_set_bvar_3x_ser_p1, NULL, NULL} // 2 }; // Set matrices for computing bb, p=1 analytically solved (Tensor basis) -GKYL_CU_D -static const gkyl_dg_em_set_bvar_kern_list ten_em_set_bvar_kernels[] = { - { NULL, em_set_bvar_1x_ser_p1, em_set_bvar_1x_ser_p2, em_set_bvar_1x_ser_p3 }, // 0 - { NULL, em_set_bvar_2x_ser_p1, em_set_bvar_2x_tensor_p2, NULL }, // 1 - { NULL, em_set_bvar_3x_ser_p1, em_set_bvar_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_set_bvar_kern_list ten_em_set_bvar_kernels[] = { + {NULL, em_set_bvar_1x_ser_p1, em_set_bvar_1x_ser_p2, em_set_bvar_1x_ser_p3}, // 0 + {NULL, em_set_bvar_2x_ser_p1, em_set_bvar_2x_tensor_p2, NULL}, // 1 + {NULL, em_set_bvar_3x_ser_p1, em_set_bvar_3x_tensor_p2, NULL} // 2 }; // Set matrices for computing ExB, p=1 analytically solved (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_em_set_ExB_kern_list ser_em_set_ExB_kernels[] = { - { NULL, em_set_ExB_1x_ser_p1, em_set_ExB_1x_ser_p2, em_set_ExB_1x_ser_p3 }, // 0 - { NULL, em_set_ExB_2x_ser_p1, NULL, NULL }, // 1 - { NULL, em_set_ExB_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_set_ExB_kern_list ser_em_set_ExB_kernels[] = { + {NULL, em_set_ExB_1x_ser_p1, em_set_ExB_1x_ser_p2, em_set_ExB_1x_ser_p3}, // 0 + {NULL, em_set_ExB_2x_ser_p1, NULL, NULL}, // 1 + {NULL, em_set_ExB_3x_ser_p1, NULL, NULL} // 2 }; // Set matrices for computing ExB, p=1 analytically solved (Tensor basis) -GKYL_CU_D -static const gkyl_dg_em_set_ExB_kern_list ten_em_set_ExB_kernels[] = { - { NULL, em_set_ExB_1x_ser_p1, em_set_ExB_1x_ser_p2, em_set_ExB_1x_ser_p3 }, // 0 - { NULL, em_set_ExB_2x_ser_p1, em_set_ExB_2x_tensor_p2, NULL }, // 1 - { NULL, em_set_ExB_3x_ser_p1, em_set_ExB_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_set_ExB_kern_list ten_em_set_ExB_kernels[] = { + {NULL, em_set_ExB_1x_ser_p1, em_set_ExB_1x_ser_p2, em_set_ExB_1x_ser_p3}, // 0 + {NULL, em_set_ExB_2x_ser_p1, em_set_ExB_2x_tensor_p2, NULL}, // 1 + {NULL, em_set_ExB_3x_ser_p1, em_set_ExB_3x_tensor_p2, NULL} // 2 }; // Magnetic field unit vector and unit tensor kernel list copy solution (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_em_copy_bvar_kern_list ser_em_copy_bvar_kernels[] = { - { NULL, em_copy_bvar_1x_ser_p1, em_copy_bvar_1x_ser_p2, em_copy_bvar_1x_ser_p3 }, // 0 - { NULL, em_copy_bvar_2x_ser_p1, NULL, NULL }, // 1 - { NULL, em_copy_bvar_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_copy_bvar_kern_list ser_em_copy_bvar_kernels[] = { + {NULL, em_copy_bvar_1x_ser_p1, em_copy_bvar_1x_ser_p2, em_copy_bvar_1x_ser_p3}, // 0 + {NULL, em_copy_bvar_2x_ser_p1, NULL, NULL}, // 1 + {NULL, em_copy_bvar_3x_ser_p1, NULL, NULL} // 2 }; // Magnetic field unit vector and unit tensor kernel list copy solution (Tensor basis) -GKYL_CU_D -static const gkyl_dg_em_copy_bvar_kern_list ten_em_copy_bvar_kernels[] = { - { NULL, em_copy_bvar_1x_ser_p1, em_copy_bvar_1x_ser_p2, em_copy_bvar_1x_ser_p3 }, // 0 - { NULL, em_copy_bvar_2x_ser_p1, em_copy_bvar_2x_tensor_p2, NULL }, // 1 - { NULL, em_copy_bvar_3x_ser_p1, em_copy_bvar_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_copy_bvar_kern_list ten_em_copy_bvar_kernels[] = { + {NULL, em_copy_bvar_1x_ser_p1, em_copy_bvar_1x_ser_p2, em_copy_bvar_1x_ser_p3}, // 0 + {NULL, em_copy_bvar_2x_ser_p1, em_copy_bvar_2x_tensor_p2, NULL}, // 1 + {NULL, em_copy_bvar_3x_ser_p1, em_copy_bvar_3x_tensor_p2, NULL} // 2 }; // E x B velocity kernel list copy solution (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_em_copy_ExB_kern_list ser_em_copy_ExB_kernels[] = { - { NULL, em_copy_ExB_1x_ser_p1, em_copy_ExB_1x_ser_p2, em_copy_ExB_1x_ser_p3 }, // 0 - { NULL, em_copy_ExB_2x_ser_p1, NULL, NULL }, // 1 - { NULL, em_copy_ExB_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_copy_ExB_kern_list ser_em_copy_ExB_kernels[] = { + {NULL, em_copy_ExB_1x_ser_p1, em_copy_ExB_1x_ser_p2, em_copy_ExB_1x_ser_p3}, // 0 + {NULL, em_copy_ExB_2x_ser_p1, NULL, NULL}, // 1 + {NULL, em_copy_ExB_3x_ser_p1, NULL, NULL} // 2 }; // E x B velocity kernel list copy solution (Tensor basis) -GKYL_CU_D -static const gkyl_dg_em_copy_ExB_kern_list ten_em_copy_ExB_kernels[] = { - { NULL, em_copy_ExB_1x_ser_p1, em_copy_ExB_1x_ser_p2, em_copy_ExB_1x_ser_p3 }, // 0 - { NULL, em_copy_ExB_2x_ser_p1, em_copy_ExB_2x_tensor_p2, NULL }, // 1 - { NULL, em_copy_ExB_3x_ser_p1, em_copy_ExB_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_copy_ExB_kern_list ten_em_copy_ExB_kernels[] = { + {NULL, em_copy_ExB_1x_ser_p1, em_copy_ExB_1x_ser_p2, em_copy_ExB_1x_ser_p3}, // 0 + {NULL, em_copy_ExB_2x_ser_p1, em_copy_ExB_2x_tensor_p2, NULL}, // 1 + {NULL, em_copy_ExB_3x_ser_p1, em_copy_ExB_3x_tensor_p2, NULL} // 2 }; // div(b) and max(|b_i|) penalization (in x) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_em_div_b_kern_list ser_em_div_b_x_kernels[] = { - { NULL, em_div_b_x_1x_ser_p1, em_div_b_x_1x_ser_p2, em_div_b_x_1x_ser_p3 }, // 0 - { NULL, em_div_b_x_2x_ser_p1, NULL, NULL }, // 1 - { NULL, em_div_b_x_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_div_b_kern_list ser_em_div_b_x_kernels[] = { + {NULL, em_div_b_x_1x_ser_p1, em_div_b_x_1x_ser_p2, em_div_b_x_1x_ser_p3}, // 0 + {NULL, em_div_b_x_2x_ser_p1, NULL, NULL}, // 1 + {NULL, em_div_b_x_3x_ser_p1, NULL, NULL} // 2 }; // div(b) and max(|b_i|) penalization (in y) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_em_div_b_kern_list ser_em_div_b_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, em_div_b_y_2x_ser_p1, NULL, NULL }, // 1 - { NULL, em_div_b_y_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_div_b_kern_list ser_em_div_b_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, em_div_b_y_2x_ser_p1, NULL, NULL}, // 1 + {NULL, em_div_b_y_3x_ser_p1, NULL, NULL} // 2 }; // div(b) and max(|b_i|) penalization (in z) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_em_div_b_kern_list ser_em_div_b_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, em_div_b_z_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_div_b_kern_list ser_em_div_b_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, em_div_b_z_3x_ser_p1, NULL, NULL} // 2 }; // div(b) and max(|b_i|) penalization (in x) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_em_div_b_kern_list ten_em_div_b_x_kernels[] = { - { NULL, em_div_b_x_1x_ser_p1, em_div_b_x_1x_ser_p2, em_div_b_x_1x_ser_p3 }, // 0 - { NULL, em_div_b_x_2x_ser_p1, em_div_b_x_2x_tensor_p2, NULL }, // 1 - { NULL, em_div_b_x_3x_ser_p1, em_div_b_x_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_div_b_kern_list ten_em_div_b_x_kernels[] = { + {NULL, em_div_b_x_1x_ser_p1, em_div_b_x_1x_ser_p2, em_div_b_x_1x_ser_p3}, // 0 + {NULL, em_div_b_x_2x_ser_p1, em_div_b_x_2x_tensor_p2, NULL}, // 1 + {NULL, em_div_b_x_3x_ser_p1, em_div_b_x_3x_tensor_p2, NULL} // 2 }; // div(b) and max(|b_i|) penalization (in y) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_em_div_b_kern_list ten_em_div_b_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, em_div_b_y_2x_ser_p1, em_div_b_y_2x_tensor_p2, NULL }, // 1 - { NULL, em_div_b_y_3x_ser_p1, em_div_b_y_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_div_b_kern_list ten_em_div_b_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, em_div_b_y_2x_ser_p1, em_div_b_y_2x_tensor_p2, NULL}, // 1 + {NULL, em_div_b_y_3x_ser_p1, em_div_b_y_3x_tensor_p2, NULL} // 2 }; // div(b) and max(|b_i|) penalization (in z) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_em_div_b_kern_list ten_em_div_b_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, em_div_b_z_3x_ser_p1, em_div_b_z_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_div_b_kern_list ten_em_div_b_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, em_div_b_z_3x_ser_p1, em_div_b_z_3x_tensor_p2, NULL} // 2 }; // Characteristic limiter in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_em_limiter_kern_list ser_em_limiter_x_kernels[] = { - { NULL, em_vars_limiterx_1x_ser_p1, em_vars_limiterx_1x_ser_p2, em_vars_limiterx_1x_ser_p3 }, // 0 - { NULL, em_vars_limiterx_2x_ser_p1, NULL, NULL }, // 1 - { NULL, em_vars_limiterx_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_limiter_kern_list ser_em_limiter_x_kernels[] = { + {NULL, em_vars_limiterx_1x_ser_p1, em_vars_limiterx_1x_ser_p2, em_vars_limiterx_1x_ser_p3}, // 0 + {NULL, em_vars_limiterx_2x_ser_p1, NULL, NULL}, // 1 + {NULL, em_vars_limiterx_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_em_limiter_kern_list ser_em_limiter_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, em_vars_limitery_2x_ser_p1, NULL, NULL }, // 1 - { NULL, em_vars_limitery_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_limiter_kern_list ser_em_limiter_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, em_vars_limitery_2x_ser_p1, NULL, NULL}, // 1 + {NULL, em_vars_limitery_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_em_limiter_kern_list ser_em_limiter_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, em_vars_limiterz_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_limiter_kern_list ser_em_limiter_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, em_vars_limiterz_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in x (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_em_limiter_kern_list ten_em_limiter_x_kernels[] = { - { NULL, em_vars_limiterx_1x_ser_p1, em_vars_limiterx_1x_ser_p2, em_vars_limiterx_1x_ser_p3 }, // 0 - { NULL, em_vars_limiterx_2x_ser_p1, em_vars_limiterx_2x_tensor_p2, NULL }, // 1 - { NULL, em_vars_limiterx_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_limiter_kern_list ten_em_limiter_x_kernels[] = { + {NULL, em_vars_limiterx_1x_ser_p1, em_vars_limiterx_1x_ser_p2, em_vars_limiterx_1x_ser_p3}, // 0 + {NULL, em_vars_limiterx_2x_ser_p1, em_vars_limiterx_2x_tensor_p2, NULL}, // 1 + {NULL, em_vars_limiterx_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in y (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_em_limiter_kern_list ten_em_limiter_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, em_vars_limitery_2x_ser_p1, em_vars_limitery_2x_tensor_p2, NULL }, // 1 - { NULL, em_vars_limitery_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_limiter_kern_list ten_em_limiter_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, em_vars_limitery_2x_ser_p1, em_vars_limitery_2x_tensor_p2, NULL}, // 1 + {NULL, em_vars_limitery_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in z (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_em_limiter_kern_list ten_em_limiter_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, em_vars_limiterz_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_em_limiter_kern_list ten_em_limiter_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, em_vars_limiterz_3x_ser_p1, NULL, NULL} // 2 }; -GKYL_CU_D -static em_calc_temp_t +GKYL_CU_D static em_calc_temp_t choose_em_calc_BB_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_em_calc_BB_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_em_calc_BB_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_em_calc_BB_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_em_calc_BB_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static em_calc_temp_t +GKYL_CU_D static em_calc_temp_t choose_em_calc_num_ExB_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_em_calc_num_ExB_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_em_calc_num_ExB_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_em_calc_num_ExB_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_em_calc_num_ExB_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static em_set_t +GKYL_CU_D static em_set_t choose_em_set_bvar_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_em_set_bvar_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_em_set_bvar_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_em_set_bvar_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_em_set_bvar_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static em_set_t +GKYL_CU_D static em_set_t choose_em_set_ExB_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_em_set_ExB_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_em_set_ExB_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_em_set_ExB_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_em_set_ExB_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static em_copy_t +GKYL_CU_D static em_copy_t choose_em_copy_bvar_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_em_copy_bvar_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_em_copy_bvar_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_em_copy_bvar_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_em_copy_bvar_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static em_copy_t +GKYL_CU_D static em_copy_t choose_em_copy_ExB_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_em_copy_ExB_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_em_copy_ExB_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_em_copy_ExB_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_em_copy_ExB_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static em_div_b_t +GKYL_CU_D static em_div_b_t choose_em_div_b_kern(int dir, enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (dir == 0) - return ser_em_div_b_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ser_em_div_b_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ser_em_div_b_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return ten_em_div_b_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ten_em_div_b_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ten_em_div_b_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + if (dir == 0) { + return ser_em_div_b_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ser_em_div_b_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ser_em_div_b_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return ten_em_div_b_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ten_em_div_b_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ten_em_div_b_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } -GKYL_CU_D -static em_limiter_t +GKYL_CU_D static em_limiter_t choose_em_limiter_kern(int dir, enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (dir == 0) - return ser_em_limiter_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ser_em_limiter_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ser_em_limiter_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return ten_em_limiter_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ten_em_limiter_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ten_em_limiter_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + if (dir == 0) { + return ser_em_limiter_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ser_em_limiter_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ser_em_limiter_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return ten_em_limiter_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ten_em_limiter_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ten_em_limiter_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } diff --git a/vlasov/zero/gkyl_dg_calc_fluid_em_coupling.h b/vlasov/zero/gkyl_dg_calc_fluid_em_coupling.h index 18b65d14b4..1a503cf79e 100644 --- a/vlasov/zero/gkyl_dg_calc_fluid_em_coupling.h +++ b/vlasov/zero/gkyl_dg_calc_fluid_em_coupling.h @@ -29,20 +29,19 @@ typedef struct gkyl_dg_calc_fluid_em_coupling gkyl_dg_calc_fluid_em_coupling; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_dg_calc_fluid_em_coupling* -gkyl_dg_calc_fluid_em_coupling_new(const struct gkyl_basis* cbasis, - const struct gkyl_range *mem_range, - int num_fluids, double qbym[GKYL_MAX_SPECIES], double epsilon0, - bool use_gpu); +struct gkyl_dg_calc_fluid_em_coupling *gkyl_dg_calc_fluid_em_coupling_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, int num_fluids, + double qbym[GKYL_MAX_SPECIES], double epsilon0, bool use_gpu +); /** * Create new updater to compute fluid variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_dg_calc_fluid_em_coupling* -gkyl_dg_calc_fluid_em_coupling_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_range *mem_range, - int num_fluids, double qbym[GKYL_MAX_SPECIES], double epsilon0); +struct gkyl_dg_calc_fluid_em_coupling *gkyl_dg_calc_fluid_em_coupling_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, int num_fluids, + double qbym[GKYL_MAX_SPECIES], double epsilon0 +); /** * Compute the updated fluid momentum and electric field implicitly from time-centered source solve. @@ -57,10 +56,12 @@ gkyl_dg_calc_fluid_em_coupling_cu_dev_new(const struct gkyl_basis* cbasis, * (update is done in place with electric field modified to new time) * */ -void gkyl_dg_calc_fluid_em_coupling_advance(struct gkyl_dg_calc_fluid_em_coupling *up, double dt, - const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - struct gkyl_array* fluid[GKYL_MAX_SPECIES], struct gkyl_array* em); +void gkyl_dg_calc_fluid_em_coupling_advance( + struct gkyl_dg_calc_fluid_em_coupling *up, double dt, + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], const struct gkyl_array *ext_em, + const struct gkyl_array *app_current, struct gkyl_array *fluid[GKYL_MAX_SPECIES], + struct gkyl_array *em +); /** * Compute the updated fluid energy (if Euler/5-moment) from updated momentum and old pressure. @@ -72,8 +73,10 @@ void gkyl_dg_calc_fluid_em_coupling_advance(struct gkyl_dg_calc_fluid_em_couplin * (update is done in place utilizing momentum at new time to compute energy at new time) * */ -void gkyl_dg_calc_fluid_em_coupling_energy(struct gkyl_dg_calc_fluid_em_coupling *up, - const struct gkyl_array* u_i_new, const struct gkyl_array* p_old, struct gkyl_array* fluid); +void gkyl_dg_calc_fluid_em_coupling_energy( + struct gkyl_dg_calc_fluid_em_coupling *up, const struct gkyl_array *u_i_new, + const struct gkyl_array *p_old, struct gkyl_array *fluid +); /** * Delete pointer to updater to compute fluid variables. @@ -86,10 +89,14 @@ void gkyl_dg_calc_fluid_em_coupling_release(struct gkyl_dg_calc_fluid_em_couplin * Host-side wrappers for fluid vars operations on device */ -void gkyl_dg_calc_fluid_em_coupling_advance_cu(struct gkyl_dg_calc_fluid_em_coupling *up, double dt, - const struct gkyl_array* app_accel[GKYL_MAX_SPECIES], - const struct gkyl_array* ext_em, const struct gkyl_array* app_current, - struct gkyl_array* fluid[GKYL_MAX_SPECIES], struct gkyl_array* em); +void gkyl_dg_calc_fluid_em_coupling_advance_cu( + struct gkyl_dg_calc_fluid_em_coupling *up, double dt, + const struct gkyl_array *app_accel[GKYL_MAX_SPECIES], const struct gkyl_array *ext_em, + const struct gkyl_array *app_current, struct gkyl_array *fluid[GKYL_MAX_SPECIES], + struct gkyl_array *em +); -void gkyl_dg_calc_fluid_em_coupling_energy_cu(struct gkyl_dg_calc_fluid_em_coupling *up, - const struct gkyl_array* u_i_new, const struct gkyl_array* p_old, struct gkyl_array* fluid); +void gkyl_dg_calc_fluid_em_coupling_energy_cu( + struct gkyl_dg_calc_fluid_em_coupling *up, const struct gkyl_array *u_i_new, + const struct gkyl_array *p_old, struct gkyl_array *fluid +); diff --git a/vlasov/zero/gkyl_dg_calc_fluid_em_coupling_priv.h b/vlasov/zero/gkyl_dg_calc_fluid_em_coupling_priv.h index cc14797ecb..d06f90fd0a 100644 --- a/vlasov/zero/gkyl_dg_calc_fluid_em_coupling_priv.h +++ b/vlasov/zero/gkyl_dg_calc_fluid_em_coupling_priv.h @@ -11,23 +11,32 @@ #include #include -typedef void (*fluid_em_coupling_set_t)(int count, - int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, double dt, - struct gkyl_nmat *A, struct gkyl_nmat *rhs, - const double *app_accel[GKYL_MAX_SPECIES], const double *ext_em, const double *app_current, - double* GKYL_RESTRICT fluid[GKYL_MAX_SPECIES], double* GKYL_RESTRICT em); - -typedef void (*fluid_em_coupling_copy_t)(int count, - int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, - struct gkyl_nmat *x, double* GKYL_RESTRICT fluid[GKYL_MAX_SPECIES], double* GKYL_RESTRICT em); - -typedef void (*fluid_em_coupling_energy_t)(const double* ke_old, const double* ke_new, - double* GKYL_RESTRICT fluid); +typedef void (*fluid_em_coupling_set_t)( + int count, int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, double dt, + struct gkyl_nmat *A, struct gkyl_nmat *rhs, const double *app_accel[GKYL_MAX_SPECIES], + const double *ext_em, const double *app_current, double *GKYL_RESTRICT fluid[GKYL_MAX_SPECIES], + double *GKYL_RESTRICT em +); + +typedef void (*fluid_em_coupling_copy_t)( + int count, int num_species, double qbym[GKYL_MAX_SPECIES], double epsilon0, struct gkyl_nmat *x, + double *GKYL_RESTRICT fluid[GKYL_MAX_SPECIES], double *GKYL_RESTRICT em +); + +typedef void (*fluid_em_coupling_energy_t)( + const double *ke_old, const double *ke_new, double *GKYL_RESTRICT fluid +); // for use in kernel tables -typedef struct { fluid_em_coupling_set_t kernels[4]; } gkyl_dg_fluid_em_coupling_set_kern_list; -typedef struct { fluid_em_coupling_copy_t kernels[4]; } gkyl_dg_fluid_em_coupling_copy_kern_list; -typedef struct { fluid_em_coupling_energy_t kernels[4]; } gkyl_dg_fluid_em_coupling_energy_kern_list; +typedef struct { + fluid_em_coupling_set_t kernels[4]; +} gkyl_dg_fluid_em_coupling_set_kern_list; +typedef struct { + fluid_em_coupling_copy_t kernels[4]; +} gkyl_dg_fluid_em_coupling_copy_kern_list; +typedef struct { + fluid_em_coupling_energy_t kernels[4]; +} gkyl_dg_fluid_em_coupling_energy_kern_list; struct gkyl_dg_calc_fluid_em_coupling { int cdim; // Configuration space dimensionality @@ -37,9 +46,10 @@ struct gkyl_dg_calc_fluid_em_coupling { struct gkyl_nmat *As, *xs; // matrices for LHS and RHS gkyl_nmat_mem *mem; // memory for use in batched linear solve - fluid_em_coupling_set_t fluid_em_coupling_set; // kernel for setting matrices for linear solve + fluid_em_coupling_set_t fluid_em_coupling_set; // kernel for setting matrices for linear solve fluid_em_coupling_copy_t fluid_em_coupling_copy; // kernel for copying solution to output - fluid_em_coupling_energy_t fluid_em_coupling_energy; // kernel for computing energy from updated solution (for Euler/5-moment) + fluid_em_coupling_energy_t + fluid_em_coupling_energy; // kernel for computing energy from updated solution (for Euler/5-moment) int num_fluids; // number of fluids being implicitly solved for double qbym[GKYL_MAX_SPECIES]; // charge/mass ratio for each species @@ -50,100 +60,103 @@ struct gkyl_dg_calc_fluid_em_coupling { }; // Set matrices for computing implicit source solve for fluid-em coupling (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_em_coupling_set_kern_list ser_fluid_em_coupling_set_kernels[] = { - { NULL, fluid_em_coupling_set_1x_ser_p1, fluid_em_coupling_set_1x_ser_p2, fluid_em_coupling_set_1x_ser_p3 }, // 0 - { NULL, fluid_em_coupling_set_2x_ser_p1, NULL, NULL }, // 1 - { NULL, fluid_em_coupling_set_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_em_coupling_set_kern_list ser_fluid_em_coupling_set_kernels[] = + { + {NULL, fluid_em_coupling_set_1x_ser_p1, fluid_em_coupling_set_1x_ser_p2, + fluid_em_coupling_set_1x_ser_p3}, // 0 + {NULL, fluid_em_coupling_set_2x_ser_p1, NULL, NULL}, // 1 + {NULL, fluid_em_coupling_set_3x_ser_p1, NULL, NULL} // 2 }; // Set matrices for computing implicit source solve for fluid-em coupling (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_em_coupling_set_kern_list ten_fluid_em_coupling_set_kernels[] = { - { NULL, fluid_em_coupling_set_1x_ser_p1, fluid_em_coupling_set_1x_ser_p2, fluid_em_coupling_set_1x_ser_p3 }, // 0 - { NULL, fluid_em_coupling_set_2x_ser_p1, fluid_em_coupling_set_2x_tensor_p2, NULL }, // 1 - { NULL, fluid_em_coupling_set_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_em_coupling_set_kern_list ten_fluid_em_coupling_set_kernels[] = + { + {NULL, fluid_em_coupling_set_1x_ser_p1, fluid_em_coupling_set_1x_ser_p2, + fluid_em_coupling_set_1x_ser_p3}, // 0 + {NULL, fluid_em_coupling_set_2x_ser_p1, fluid_em_coupling_set_2x_tensor_p2, NULL}, // 1 + {NULL, fluid_em_coupling_set_3x_ser_p1, NULL, NULL} // 2 }; // Copy solution for implicit source solve for fluid-em coupling (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_em_coupling_copy_kern_list ser_fluid_em_coupling_copy_kernels[] = { - { NULL, fluid_em_coupling_copy_1x_ser_p1, fluid_em_coupling_copy_1x_ser_p2, fluid_em_coupling_copy_1x_ser_p3 }, // 0 - { NULL, fluid_em_coupling_copy_2x_ser_p1, NULL, NULL }, // 1 - { NULL, fluid_em_coupling_copy_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_em_coupling_copy_kern_list + ser_fluid_em_coupling_copy_kernels[] = { + {NULL, fluid_em_coupling_copy_1x_ser_p1, fluid_em_coupling_copy_1x_ser_p2, + fluid_em_coupling_copy_1x_ser_p3}, // 0 + {NULL, fluid_em_coupling_copy_2x_ser_p1, NULL, NULL}, // 1 + {NULL, fluid_em_coupling_copy_3x_ser_p1, NULL, NULL} // 2 }; // Copy solution for implicit source solve for fluid-em coupling (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_em_coupling_copy_kern_list ten_fluid_em_coupling_copy_kernels[] = { - { NULL, fluid_em_coupling_copy_1x_ser_p1, fluid_em_coupling_copy_1x_ser_p2, fluid_em_coupling_copy_1x_ser_p3 }, // 0 - { NULL, fluid_em_coupling_copy_2x_ser_p1, fluid_em_coupling_copy_2x_tensor_p2, NULL }, // 1 - { NULL, fluid_em_coupling_copy_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_em_coupling_copy_kern_list + ten_fluid_em_coupling_copy_kernels[] = { + {NULL, fluid_em_coupling_copy_1x_ser_p1, fluid_em_coupling_copy_1x_ser_p2, + fluid_em_coupling_copy_1x_ser_p3}, // 0 + {NULL, fluid_em_coupling_copy_2x_ser_p1, fluid_em_coupling_copy_2x_tensor_p2, NULL}, // 1 + {NULL, fluid_em_coupling_copy_3x_ser_p1, NULL, NULL} // 2 }; // Compute energy from updated kinetic energy and old kinetic energy (Euler/5-moment) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_em_coupling_energy_kern_list ser_fluid_em_coupling_energy_kernels[] = { - { NULL, fluid_em_coupling_energy_1x_ser_p1, fluid_em_coupling_energy_1x_ser_p2, fluid_em_coupling_energy_1x_ser_p3 }, // 0 - { NULL, fluid_em_coupling_energy_2x_ser_p1, NULL, NULL }, // 1 - { NULL, fluid_em_coupling_energy_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_em_coupling_energy_kern_list + ser_fluid_em_coupling_energy_kernels[] = { + {NULL, fluid_em_coupling_energy_1x_ser_p1, fluid_em_coupling_energy_1x_ser_p2, + fluid_em_coupling_energy_1x_ser_p3}, // 0 + {NULL, fluid_em_coupling_energy_2x_ser_p1, NULL, NULL}, // 1 + {NULL, fluid_em_coupling_energy_3x_ser_p1, NULL, NULL} // 2 }; // Compute energy from updated kinetic energy and old kinetic energy (Euler/5-moment) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_em_coupling_energy_kern_list ten_fluid_em_coupling_energy_kernels[] = { - { NULL, fluid_em_coupling_energy_1x_ser_p1, fluid_em_coupling_energy_1x_ser_p2, fluid_em_coupling_energy_1x_ser_p3 }, // 0 - { NULL, fluid_em_coupling_energy_2x_ser_p1, fluid_em_coupling_energy_2x_tensor_p2, NULL }, // 1 - { NULL, fluid_em_coupling_energy_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_em_coupling_energy_kern_list + ten_fluid_em_coupling_energy_kernels[] = { + {NULL, fluid_em_coupling_energy_1x_ser_p1, fluid_em_coupling_energy_1x_ser_p2, + fluid_em_coupling_energy_1x_ser_p3}, // 0 + {NULL, fluid_em_coupling_energy_2x_ser_p1, fluid_em_coupling_energy_2x_tensor_p2, NULL}, // 1 + {NULL, fluid_em_coupling_energy_3x_ser_p1, NULL, NULL} // 2 }; -GKYL_CU_D -static fluid_em_coupling_set_t +GKYL_CU_D static fluid_em_coupling_set_t choose_fluid_em_coupling_set_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_fluid_em_coupling_set_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_fluid_em_coupling_set_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_fluid_em_coupling_set_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_fluid_em_coupling_set_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static fluid_em_coupling_copy_t +GKYL_CU_D static fluid_em_coupling_copy_t choose_fluid_em_coupling_copy_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_fluid_em_coupling_copy_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_fluid_em_coupling_copy_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_fluid_em_coupling_copy_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_fluid_em_coupling_copy_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static fluid_em_coupling_energy_t +GKYL_CU_D static fluid_em_coupling_energy_t choose_fluid_em_coupling_energy_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_fluid_em_coupling_energy_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_fluid_em_coupling_energy_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_fluid_em_coupling_energy_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_fluid_em_coupling_energy_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } diff --git a/vlasov/zero/gkyl_dg_calc_fluid_vars.h b/vlasov/zero/gkyl_dg_calc_fluid_vars.h index fc4095a287..e78b70c130 100644 --- a/vlasov/zero/gkyl_dg_calc_fluid_vars.h +++ b/vlasov/zero/gkyl_dg_calc_fluid_vars.h @@ -38,19 +38,20 @@ typedef struct gkyl_dg_calc_fluid_vars gkyl_dg_calc_fluid_vars; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_dg_calc_fluid_vars* -gkyl_dg_calc_fluid_vars_new(const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, - const struct gkyl_basis* cbasis, const struct gkyl_range *mem_range, - double limiter_fac, bool use_gpu); +struct gkyl_dg_calc_fluid_vars *gkyl_dg_calc_fluid_vars_new( + const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, double limiter_fac, + bool use_gpu +); /** * Create new updater to compute fluid variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_dg_calc_fluid_vars* -gkyl_dg_calc_fluid_vars_cu_dev_new(const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, - const struct gkyl_basis* cbasis, const struct gkyl_range *mem_range, - double limiter_fac); +struct gkyl_dg_calc_fluid_vars *gkyl_dg_calc_fluid_vars_cu_dev_new( + const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, + const struct gkyl_basis *cbasis, const struct gkyl_range *mem_range, double limiter_fac +); /** * Compute flow velocity from mass density and momentum density. @@ -65,8 +66,10 @@ gkyl_dg_calc_fluid_vars_cu_dev_new(const struct gkyl_wv_eqn *wv_eqn, const struc * ux_yl, ux_yr, uy_yl, uy_yr, uz_yl, uz_yr, * ux_zl, ux_zr, uy_zl, uy_zr, uz_zl, uz_zr] */ -void gkyl_dg_calc_fluid_vars_advance(struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_array* fluid, - struct gkyl_array* cell_avg_prim, struct gkyl_array* u, struct gkyl_array* u_surf); +void gkyl_dg_calc_fluid_vars_advance( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_array *fluid, + struct gkyl_array *cell_avg_prim, struct gkyl_array *u, struct gkyl_array *u_surf +); /** * Compute pressure from fluid variables in the volume and at needed surfaces @@ -78,10 +81,11 @@ void gkyl_dg_calc_fluid_vars_advance(struct gkyl_dg_calc_fluid_vars *up, const s * @param p Output array of volume expansion of pressure * @param p_surf Output array of surface expansion of pressure [p_xl, p_xr, p_yl, p_yr, p_zl, p_zr] */ -void gkyl_dg_calc_fluid_vars_pressure(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* fluid, const struct gkyl_array* u, - struct gkyl_array* p, struct gkyl_array* p_surf); +void gkyl_dg_calc_fluid_vars_pressure( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u, struct gkyl_array *p, + struct gkyl_array *p_surf +); /** * Compute kinetic energy from fluid variables in the volume @@ -92,10 +96,10 @@ void gkyl_dg_calc_fluid_vars_pressure(struct gkyl_dg_calc_fluid_vars *up, * @param u Input array of volume expansion of flow velocity [ux, uy, uz] * @param ke Output array of volume expansion of kinetic energy */ -void gkyl_dg_calc_fluid_vars_ke(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* fluid, const struct gkyl_array* u, - struct gkyl_array* ke); +void gkyl_dg_calc_fluid_vars_ke( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u, struct gkyl_array *ke +); /** * Limit slopes for fluid variables @@ -104,8 +108,9 @@ void gkyl_dg_calc_fluid_vars_ke(struct gkyl_dg_calc_fluid_vars *up, * @param conf_range Configuration space range * @param fluid Input (and Output after limiting) array of fluid variables [rho, rho ux, rho uy, rho uz, ...] */ -void gkyl_dg_calc_fluid_vars_limiter(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, struct gkyl_array* fluid); +void gkyl_dg_calc_fluid_vars_limiter( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, struct gkyl_array *fluid +); /** * Compute integrated fluid variables (rho, rhoux, rhouy, rhouz, rhou^2, ...). @@ -121,10 +126,11 @@ void gkyl_dg_calc_fluid_vars_limiter(struct gkyl_dg_calc_fluid_vars *up, * @param p_ij Input array of pressure * @param int_fluid_vars Output array of integrated variables (6 components) */ -void gkyl_dg_calc_fluid_integrated_vars(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* fluid, - const struct gkyl_array* u_i, const struct gkyl_array* p_ij, - struct gkyl_array* fluid_int_vars); +void gkyl_dg_calc_fluid_integrated_vars( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u_i, const struct gkyl_array *p_ij, + struct gkyl_array *fluid_int_vars +); /** * Compute fluid model source terms. @@ -135,10 +141,10 @@ void gkyl_dg_calc_fluid_integrated_vars(struct gkyl_dg_calc_fluid_vars *up, * @param fluid Input array of fluid variables [rho, rhoux, rhouy, rhouz, ...] * @param rhs Output increment to fluid variables */ -void gkyl_dg_calc_fluid_vars_source(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* app_accel, const struct gkyl_array* fluid, - struct gkyl_array* rhs); +void gkyl_dg_calc_fluid_vars_source( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *app_accel, const struct gkyl_array *fluid, struct gkyl_array *rhs +); /** * Delete pointer to updater to compute fluid variables. @@ -151,28 +157,33 @@ void gkyl_dg_calc_fluid_vars_release(struct gkyl_dg_calc_fluid_vars *up); * Host-side wrappers for fluid vars operations on device */ -void gkyl_dg_calc_fluid_vars_advance_cu(struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_array* fluid, - struct gkyl_array* cell_avg_prim, struct gkyl_array* u, struct gkyl_array* u_surf); - -void gkyl_dg_calc_fluid_vars_pressure_cu(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* fluid, const struct gkyl_array* u, - struct gkyl_array* p, struct gkyl_array* p_surf); - -void gkyl_dg_calc_fluid_vars_ke_cu(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* fluid, const struct gkyl_array* u, - struct gkyl_array* ke); - -void gkyl_dg_calc_fluid_vars_limiter_cu(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, struct gkyl_array* fluid); - -void gkyl_dg_calc_fluid_integrated_vars_cu(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_array* fluid, - const struct gkyl_array* u_i, const struct gkyl_array* p_ij, - struct gkyl_array* fluid_int_vars); - -void gkyl_dg_calc_fluid_vars_source_cu(struct gkyl_dg_calc_fluid_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* app_accel, const struct gkyl_array* fluid, - struct gkyl_array* rhs); +void gkyl_dg_calc_fluid_vars_advance_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_array *fluid, + struct gkyl_array *cell_avg_prim, struct gkyl_array *u, struct gkyl_array *u_surf +); + +void gkyl_dg_calc_fluid_vars_pressure_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u, struct gkyl_array *p, + struct gkyl_array *p_surf +); + +void gkyl_dg_calc_fluid_vars_ke_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u, struct gkyl_array *ke +); + +void gkyl_dg_calc_fluid_vars_limiter_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, struct gkyl_array *fluid +); + +void gkyl_dg_calc_fluid_integrated_vars_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *fluid, const struct gkyl_array *u_i, const struct gkyl_array *p_ij, + struct gkyl_array *fluid_int_vars +); + +void gkyl_dg_calc_fluid_vars_source_cu( + struct gkyl_dg_calc_fluid_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *app_accel, const struct gkyl_array *fluid, struct gkyl_array *rhs +); diff --git a/vlasov/zero/gkyl_dg_calc_fluid_vars_priv.h b/vlasov/zero/gkyl_dg_calc_fluid_vars_priv.h index de2e2d5b5f..6a591ec621 100644 --- a/vlasov/zero/gkyl_dg_calc_fluid_vars_priv.h +++ b/vlasov/zero/gkyl_dg_calc_fluid_vars_priv.h @@ -12,56 +12,78 @@ #include #include -typedef int (*fluid_set_t)(int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, - const double *fluid); +typedef int (*fluid_set_t)( + int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, const double *fluid +); -typedef void (*fluid_copy_t)(int count, struct gkyl_nmat *x, - double* GKYL_RESTRICT u, double* GKYL_RESTRICT u_surf); +typedef void (*fluid_copy_t)( + int count, struct gkyl_nmat *x, double *GKYL_RESTRICT u, double *GKYL_RESTRICT u_surf +); -typedef void (*fluid_pressure_t)(double gas_gamma, const double *fluid, const double *u, - double* GKYL_RESTRICT p, double* GKYL_RESTRICT p_surf); +typedef void (*fluid_pressure_t)( + double gas_gamma, const double *fluid, const double *u, double *GKYL_RESTRICT p, + double *GKYL_RESTRICT p_surf +); -typedef void (*fluid_ke_t)(const double *fluid, const double *u, - double* GKYL_RESTRICT ke); +typedef void (*fluid_ke_t)(const double *fluid, const double *u, double *GKYL_RESTRICT ke); -typedef void (*fluid_limiter_t)(double limiter_fac, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_cell_geom *geom, - double *fluid_l, double *fluid_c, double *fluid_r); +typedef void (*fluid_limiter_t)( + double limiter_fac, const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_cell_geom *geom, + double *fluid_l, double *fluid_c, double *fluid_r +); -typedef void (*fluid_int_t)(const double *fluid, - const double* u_i, const double* p_ij, - double* GKYL_RESTRICT int_fluid_vars); +typedef void (*fluid_int_t)( + const double *fluid, const double *u_i, const double *p_ij, double *GKYL_RESTRICT int_fluid_vars +); -typedef void (*fluid_source_t)(const double* app_accel, const double* fluid, - double* GKYL_RESTRICT out); +typedef void (*fluid_source_t)( + const double *app_accel, const double *fluid, double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { fluid_set_t kernels[4]; } gkyl_dg_fluid_set_kern_list; -typedef struct { fluid_copy_t kernels[4]; } gkyl_dg_fluid_copy_kern_list; -typedef struct { fluid_pressure_t kernels[4]; } gkyl_dg_fluid_pressure_kern_list; -typedef struct { fluid_ke_t kernels[4]; } gkyl_dg_fluid_ke_kern_list; -typedef struct { fluid_limiter_t kernels[4]; } gkyl_dg_fluid_limiter_kern_list; -typedef struct { fluid_int_t kernels[4]; } gkyl_dg_fluid_int_kern_list; -typedef struct { fluid_source_t kernels[4]; } gkyl_dg_fluid_source_kern_list; +typedef struct { + fluid_set_t kernels[4]; +} gkyl_dg_fluid_set_kern_list; +typedef struct { + fluid_copy_t kernels[4]; +} gkyl_dg_fluid_copy_kern_list; +typedef struct { + fluid_pressure_t kernels[4]; +} gkyl_dg_fluid_pressure_kern_list; +typedef struct { + fluid_ke_t kernels[4]; +} gkyl_dg_fluid_ke_kern_list; +typedef struct { + fluid_limiter_t kernels[4]; +} gkyl_dg_fluid_limiter_kern_list; +typedef struct { + fluid_int_t kernels[4]; +} gkyl_dg_fluid_int_kern_list; +typedef struct { + fluid_source_t kernels[4]; +} gkyl_dg_fluid_source_kern_list; struct gkyl_dg_calc_fluid_vars { enum gkyl_eqn_type eqn_type; // Equation type const struct gkyl_wv_eqn *wv_eqn; // Wave equation for characteristic limiting of solution const struct gkyl_wave_geom *geom; // Wave geometry for rotating solution - double param; // parameter for computing primitive moments/limiting solution (vt for isothermal Euler, gas_gammas for Euler) + double + param; // parameter for computing primitive moments/limiting solution (vt for isothermal Euler, gas_gammas for Euler) int cdim; // Configuration space dimensionality int poly_order; // polynomial order (determines whether we solve linear system or use basis_inv method) struct gkyl_range mem_range; // Configuration space range for linear solve - double limiter_fac; // Factor for relationship between cell slopes and cell average differences (by default: 1/sqrt(3)) + double + limiter_fac; // Factor for relationship between cell slopes and cell average differences (by default: 1/sqrt(3)) struct gkyl_nmat *As, *xs; // matrices for LHS and RHS gkyl_nmat_mem *mem; // memory for use in batched linear solve int Ncomp; // number of components in the linear solve (6 variables being solved for) - fluid_set_t fluid_set; // kernel for setting matrices for linear solve - fluid_copy_t fluid_copy; // kernel for copying solution to output; also computed needed surface expansions + fluid_set_t fluid_set; // kernel for setting matrices for linear solve + fluid_copy_t + fluid_copy; // kernel for copying solution to output; also computed needed surface expansions fluid_pressure_t fluid_pressure; // kernel for computing pressure (Volume and surface expansion) fluid_ke_t fluid_ke; // kernel for computing kinetic energy (Volume expansion) fluid_limiter_t fluid_limiter[3]; // kernel for limiting slopes of fluid variables @@ -73,278 +95,265 @@ struct gkyl_dg_calc_fluid_vars { }; // Set matrices for computing fluid flow velocity (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_set_kern_list ser_fluid_set_kernels[] = { - { NULL, fluid_vars_u_set_1x_ser_p1, fluid_vars_u_set_1x_ser_p2, fluid_vars_u_set_1x_ser_p3 }, // 0 - { NULL, fluid_vars_u_set_2x_ser_p1, NULL, NULL }, // 1 - { NULL, fluid_vars_u_set_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_set_kern_list ser_fluid_set_kernels[] = { + {NULL, fluid_vars_u_set_1x_ser_p1, fluid_vars_u_set_1x_ser_p2, fluid_vars_u_set_1x_ser_p3}, // 0 + {NULL, fluid_vars_u_set_2x_ser_p1, NULL, NULL}, // 1 + {NULL, fluid_vars_u_set_3x_ser_p1, NULL, NULL} // 2 }; // Set matrices for computing fluid flow velocity (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_set_kern_list ten_fluid_set_kernels[] = { - { NULL, fluid_vars_u_set_1x_ser_p1, fluid_vars_u_set_1x_ser_p2, fluid_vars_u_set_1x_ser_p3 }, // 0 - { NULL, fluid_vars_u_set_2x_ser_p1, fluid_vars_u_set_2x_tensor_p2, NULL }, // 1 - { NULL, fluid_vars_u_set_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_set_kern_list ten_fluid_set_kernels[] = { + {NULL, fluid_vars_u_set_1x_ser_p1, fluid_vars_u_set_1x_ser_p2, fluid_vars_u_set_1x_ser_p3}, // 0 + {NULL, fluid_vars_u_set_2x_ser_p1, fluid_vars_u_set_2x_tensor_p2, NULL}, // 1 + {NULL, fluid_vars_u_set_3x_ser_p1, NULL, NULL} // 2 }; // Copy solution for fluid flow velocity (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_copy_kern_list ser_fluid_copy_kernels[] = { - { NULL, fluid_vars_u_copy_1x_ser_p1, fluid_vars_u_copy_1x_ser_p2, fluid_vars_u_copy_1x_ser_p3 }, // 0 - { NULL, fluid_vars_u_copy_2x_ser_p1, NULL, NULL }, // 1 - { NULL, fluid_vars_u_copy_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_copy_kern_list ser_fluid_copy_kernels[] = { + {NULL, fluid_vars_u_copy_1x_ser_p1, fluid_vars_u_copy_1x_ser_p2, fluid_vars_u_copy_1x_ser_p3 + }, // 0 + {NULL, fluid_vars_u_copy_2x_ser_p1, NULL, NULL}, // 1 + {NULL, fluid_vars_u_copy_3x_ser_p1, NULL, NULL} // 2 }; // Copy solution for fluid flow velocity (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_copy_kern_list ten_fluid_copy_kernels[] = { - { NULL, fluid_vars_u_copy_1x_ser_p1, fluid_vars_u_copy_1x_ser_p2, fluid_vars_u_copy_1x_ser_p3 }, // 0 - { NULL, fluid_vars_u_copy_2x_ser_p1, fluid_vars_u_copy_2x_tensor_p2, NULL }, // 1 - { NULL, fluid_vars_u_copy_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_copy_kern_list ten_fluid_copy_kernels[] = { + {NULL, fluid_vars_u_copy_1x_ser_p1, fluid_vars_u_copy_1x_ser_p2, fluid_vars_u_copy_1x_ser_p3 + }, // 0 + {NULL, fluid_vars_u_copy_2x_ser_p1, fluid_vars_u_copy_2x_tensor_p2, NULL}, // 1 + {NULL, fluid_vars_u_copy_3x_ser_p1, NULL, NULL} // 2 }; // Scalar pressure Isothermal Euler -> p = vth*rho; Euler -> p = (gas_gamma - 1)*(E - 1/2 rho u^2) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_pressure_kern_list ser_fluid_pressure_kernels[] = { - { NULL, fluid_vars_pressure_1x_ser_p1, fluid_vars_pressure_1x_ser_p2, fluid_vars_pressure_1x_ser_p3 }, // 0 - { NULL, fluid_vars_pressure_2x_ser_p1, NULL, NULL }, // 1 - { NULL, fluid_vars_pressure_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_pressure_kern_list ser_fluid_pressure_kernels[] = { + {NULL, fluid_vars_pressure_1x_ser_p1, fluid_vars_pressure_1x_ser_p2, fluid_vars_pressure_1x_ser_p3 + }, // 0 + {NULL, fluid_vars_pressure_2x_ser_p1, NULL, NULL}, // 1 + {NULL, fluid_vars_pressure_3x_ser_p1, NULL, NULL} // 2 }; // Scalar pressure Isothermal Euler -> p = vth*rho; Euler -> p = (gas_gamma - 1)*(E - 1/2 rho u^2) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_pressure_kern_list ten_fluid_pressure_kernels[] = { - { NULL, fluid_vars_pressure_1x_ser_p1, fluid_vars_pressure_1x_ser_p2, fluid_vars_pressure_1x_ser_p3 }, // 0 - { NULL, fluid_vars_pressure_2x_ser_p1, fluid_vars_pressure_2x_tensor_p2, NULL }, // 1 - { NULL, fluid_vars_pressure_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_pressure_kern_list ten_fluid_pressure_kernels[] = { + {NULL, fluid_vars_pressure_1x_ser_p1, fluid_vars_pressure_1x_ser_p2, fluid_vars_pressure_1x_ser_p3 + }, // 0 + {NULL, fluid_vars_pressure_2x_ser_p1, fluid_vars_pressure_2x_tensor_p2, NULL}, // 1 + {NULL, fluid_vars_pressure_3x_ser_p1, NULL, NULL} // 2 }; // Kinetic energy = 1/2 (rho ux^2 + rho uy^2 + rho uz^2) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_ke_kern_list ser_fluid_ke_kernels[] = { - { NULL, fluid_vars_ke_1x_ser_p1, fluid_vars_ke_1x_ser_p2, fluid_vars_ke_1x_ser_p3 }, // 0 - { NULL, fluid_vars_ke_2x_ser_p1, NULL, NULL }, // 1 - { NULL, fluid_vars_ke_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_ke_kern_list ser_fluid_ke_kernels[] = { + {NULL, fluid_vars_ke_1x_ser_p1, fluid_vars_ke_1x_ser_p2, fluid_vars_ke_1x_ser_p3}, // 0 + {NULL, fluid_vars_ke_2x_ser_p1, NULL, NULL}, // 1 + {NULL, fluid_vars_ke_3x_ser_p1, NULL, NULL} // 2 }; // Kinetic energy = 1/2 (rho ux^2 + rho uy^2 + rho uz^2) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_ke_kern_list ten_fluid_ke_kernels[] = { - { NULL, fluid_vars_ke_1x_ser_p1, fluid_vars_ke_1x_ser_p2, fluid_vars_ke_1x_ser_p3 }, // 0 - { NULL, fluid_vars_ke_2x_ser_p1, fluid_vars_ke_2x_tensor_p2, NULL }, // 1 - { NULL, fluid_vars_ke_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_ke_kern_list ten_fluid_ke_kernels[] = { + {NULL, fluid_vars_ke_1x_ser_p1, fluid_vars_ke_1x_ser_p2, fluid_vars_ke_1x_ser_p3}, // 0 + {NULL, fluid_vars_ke_2x_ser_p1, fluid_vars_ke_2x_tensor_p2, NULL}, // 1 + {NULL, fluid_vars_ke_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in x (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_limiter_kern_list ser_fluid_limiter_x_kernels[] = { - { NULL, fluid_vars_limiterx_1x_ser_p1, fluid_vars_limiterx_1x_ser_p2, fluid_vars_limiterx_1x_ser_p3 }, // 0 - { NULL, fluid_vars_limiterx_2x_ser_p1, NULL, NULL }, // 1 - { NULL, fluid_vars_limiterx_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_limiter_kern_list ser_fluid_limiter_x_kernels[] = { + {NULL, fluid_vars_limiterx_1x_ser_p1, fluid_vars_limiterx_1x_ser_p2, fluid_vars_limiterx_1x_ser_p3 + }, // 0 + {NULL, fluid_vars_limiterx_2x_ser_p1, NULL, NULL}, // 1 + {NULL, fluid_vars_limiterx_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in y (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_limiter_kern_list ser_fluid_limiter_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, fluid_vars_limitery_2x_ser_p1, NULL, NULL }, // 1 - { NULL, fluid_vars_limitery_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_limiter_kern_list ser_fluid_limiter_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, fluid_vars_limitery_2x_ser_p1, NULL, NULL}, // 1 + {NULL, fluid_vars_limitery_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in z (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_limiter_kern_list ser_fluid_limiter_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, fluid_vars_limiterz_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_limiter_kern_list ser_fluid_limiter_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, fluid_vars_limiterz_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in x (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_limiter_kern_list ten_fluid_limiter_x_kernels[] = { - { NULL, fluid_vars_limiterx_1x_ser_p1, fluid_vars_limiterx_1x_ser_p2, fluid_vars_limiterx_1x_ser_p3 }, // 0 - { NULL, fluid_vars_limiterx_2x_ser_p1, fluid_vars_limiterx_2x_tensor_p2, NULL }, // 1 - { NULL, fluid_vars_limiterx_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_limiter_kern_list ten_fluid_limiter_x_kernels[] = { + {NULL, fluid_vars_limiterx_1x_ser_p1, fluid_vars_limiterx_1x_ser_p2, fluid_vars_limiterx_1x_ser_p3 + }, // 0 + {NULL, fluid_vars_limiterx_2x_ser_p1, fluid_vars_limiterx_2x_tensor_p2, NULL}, // 1 + {NULL, fluid_vars_limiterx_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in y (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_limiter_kern_list ten_fluid_limiter_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, fluid_vars_limitery_2x_ser_p1, fluid_vars_limitery_2x_tensor_p2, NULL }, // 1 - { NULL, fluid_vars_limitery_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_limiter_kern_list ten_fluid_limiter_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, fluid_vars_limitery_2x_ser_p1, fluid_vars_limitery_2x_tensor_p2, NULL}, // 1 + {NULL, fluid_vars_limitery_3x_ser_p1, NULL, NULL} // 2 }; // Characteristic limiter in z (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_limiter_kern_list ten_fluid_limiter_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, fluid_vars_limiterz_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_limiter_kern_list ten_fluid_limiter_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, fluid_vars_limiterz_3x_ser_p1, NULL, NULL} // 2 }; // Fluid integrated variables integral (rho, rhoux, rhouy, rhouz, rhou^2, p) (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_int_kern_list ser_fluid_int_kernels[] = { - { NULL, fluid_vars_integrated_1x_ser_p1, fluid_vars_integrated_1x_ser_p2, fluid_vars_integrated_1x_ser_p3 }, // 0 - { NULL, fluid_vars_integrated_2x_ser_p1, NULL, NULL }, // 1 - { NULL, fluid_vars_integrated_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_int_kern_list ser_fluid_int_kernels[] = { + {NULL, fluid_vars_integrated_1x_ser_p1, fluid_vars_integrated_1x_ser_p2, + fluid_vars_integrated_1x_ser_p3}, // 0 + {NULL, fluid_vars_integrated_2x_ser_p1, NULL, NULL}, // 1 + {NULL, fluid_vars_integrated_3x_ser_p1, NULL, NULL} // 2 }; // Fluid integrated variables integral (rho, rhoux, rhouy, rhouz, rhou^2, p) (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_int_kern_list ten_fluid_int_kernels[] = { - { NULL, fluid_vars_integrated_1x_ser_p1, fluid_vars_integrated_1x_ser_p2, fluid_vars_integrated_1x_ser_p3 }, // 0 - { NULL, fluid_vars_integrated_2x_ser_p1, fluid_vars_integrated_2x_tensor_p2, NULL }, // 1 - { NULL, fluid_vars_integrated_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_int_kern_list ten_fluid_int_kernels[] = { + {NULL, fluid_vars_integrated_1x_ser_p1, fluid_vars_integrated_1x_ser_p2, + fluid_vars_integrated_1x_ser_p3}, // 0 + {NULL, fluid_vars_integrated_2x_ser_p1, fluid_vars_integrated_2x_tensor_p2, NULL}, // 1 + {NULL, fluid_vars_integrated_3x_ser_p1, NULL, NULL} // 2 }; // Fluid explicit source solve (Serendipity kernels) -GKYL_CU_D -static const gkyl_dg_fluid_source_kern_list ser_fluid_source_kernels[] = { - { NULL, fluid_vars_source_1x_ser_p1, fluid_vars_source_1x_ser_p2, fluid_vars_source_1x_ser_p3 }, // 0 - { NULL, fluid_vars_source_2x_ser_p1, NULL, NULL }, // 1 - { NULL, fluid_vars_source_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_source_kern_list ser_fluid_source_kernels[] = { + {NULL, fluid_vars_source_1x_ser_p1, fluid_vars_source_1x_ser_p2, fluid_vars_source_1x_ser_p3 + }, // 0 + {NULL, fluid_vars_source_2x_ser_p1, NULL, NULL}, // 1 + {NULL, fluid_vars_source_3x_ser_p1, NULL, NULL} // 2 }; // Fluid explicit source solve (Tensor kernels) -GKYL_CU_D -static const gkyl_dg_fluid_source_kern_list ten_fluid_source_kernels[] = { - { NULL, fluid_vars_source_1x_ser_p1, fluid_vars_source_1x_ser_p2, fluid_vars_source_1x_ser_p3 }, // 0 - { NULL, fluid_vars_source_2x_ser_p1, fluid_vars_source_2x_tensor_p2, NULL }, // 1 - { NULL, fluid_vars_source_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_fluid_source_kern_list ten_fluid_source_kernels[] = { + {NULL, fluid_vars_source_1x_ser_p1, fluid_vars_source_1x_ser_p2, fluid_vars_source_1x_ser_p3 + }, // 0 + {NULL, fluid_vars_source_2x_ser_p1, fluid_vars_source_2x_tensor_p2, NULL}, // 1 + {NULL, fluid_vars_source_3x_ser_p1, NULL, NULL} // 2 }; -GKYL_CU_D -static fluid_set_t +GKYL_CU_D static fluid_set_t choose_fluid_set_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_fluid_set_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_fluid_set_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_fluid_set_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_fluid_set_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static fluid_copy_t +GKYL_CU_D static fluid_copy_t choose_fluid_copy_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_fluid_copy_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_fluid_copy_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_fluid_copy_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_fluid_copy_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static fluid_pressure_t +GKYL_CU_D static fluid_pressure_t choose_fluid_pressure_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_fluid_pressure_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_fluid_pressure_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_fluid_pressure_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_fluid_pressure_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static fluid_ke_t +GKYL_CU_D static fluid_ke_t choose_fluid_ke_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_fluid_ke_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_fluid_ke_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_fluid_ke_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_fluid_ke_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static fluid_limiter_t +GKYL_CU_D static fluid_limiter_t choose_fluid_limiter_kern(int dir, enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - if (dir == 0) - return ser_fluid_limiter_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ser_fluid_limiter_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ser_fluid_limiter_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - case GKYL_BASIS_MODAL_TENSOR: - if (dir == 0) - return ten_fluid_limiter_x_kernels[cdim-1].kernels[poly_order]; - else if (dir == 1) - return ten_fluid_limiter_y_kernels[cdim-1].kernels[poly_order]; - else if (dir == 2) - return ten_fluid_limiter_z_kernels[cdim-1].kernels[poly_order]; - else - return NULL; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + if (dir == 0) { + return ser_fluid_limiter_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ser_fluid_limiter_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ser_fluid_limiter_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + case GKYL_BASIS_MODAL_TENSOR: + if (dir == 0) { + return ten_fluid_limiter_x_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 1) { + return ten_fluid_limiter_y_kernels[cdim - 1].kernels[poly_order]; + } else if (dir == 2) { + return ten_fluid_limiter_z_kernels[cdim - 1].kernels[poly_order]; + } else { + return NULL; + } + break; + default: + assert(false); + break; } } -GKYL_CU_D -static fluid_int_t +GKYL_CU_D static fluid_int_t choose_fluid_int_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_fluid_int_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_fluid_int_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_fluid_int_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_fluid_int_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static fluid_source_t +GKYL_CU_D static fluid_source_t choose_fluid_source_kern(enum gkyl_basis_type b_type, int cdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_fluid_source_kernels[cdim-1].kernels[poly_order]; - break; - case GKYL_BASIS_MODAL_TENSOR: - return ten_fluid_source_kernels[cdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_fluid_source_kernels[cdim - 1].kernels[poly_order]; + break; + case GKYL_BASIS_MODAL_TENSOR: + return ten_fluid_source_kernels[cdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } diff --git a/vlasov/zero/gkyl_dg_calc_prim_vars.h b/vlasov/zero/gkyl_dg_calc_prim_vars.h index d49a3ef349..f53c8cf023 100644 --- a/vlasov/zero/gkyl_dg_calc_prim_vars.h +++ b/vlasov/zero/gkyl_dg_calc_prim_vars.h @@ -21,8 +21,10 @@ * @param statevec Input state vector which contains *both* density and momentum * @param u_i Output array of bulk flow velocity */ -void gkyl_calc_prim_vars_u_from_statevec(gkyl_dg_bin_op_mem *mem, struct gkyl_basis basis, const struct gkyl_range *range, - const struct gkyl_array* statevec, struct gkyl_array* u_i); +void gkyl_calc_prim_vars_u_from_statevec( + gkyl_dg_bin_op_mem *mem, struct gkyl_basis basis, const struct gkyl_range *range, + const struct gkyl_array *statevec, struct gkyl_array *u_i +); /** * Compute u from input density and momentum vectors. @@ -38,5 +40,7 @@ void gkyl_calc_prim_vars_u_from_statevec(gkyl_dg_bin_op_mem *mem, struct gkyl_ba * @param rhou Input momentum * @param u_i Output array of bulk flow velocity */ -void gkyl_calc_prim_vars_u_from_rhou(gkyl_dg_bin_op_mem *mem, struct gkyl_basis basis, const struct gkyl_range *range, - const struct gkyl_array* rho, const struct gkyl_array* rhou, struct gkyl_array* u_i); +void gkyl_calc_prim_vars_u_from_rhou( + gkyl_dg_bin_op_mem *mem, struct gkyl_basis basis, const struct gkyl_range *range, + const struct gkyl_array *rho, const struct gkyl_array *rhou, struct gkyl_array *u_i +); diff --git a/vlasov/zero/gkyl_dg_calc_sr_vars.h b/vlasov/zero/gkyl_dg_calc_sr_vars.h index 7b3204044e..09ffa575bc 100644 --- a/vlasov/zero/gkyl_dg_calc_sr_vars.h +++ b/vlasov/zero/gkyl_dg_calc_sr_vars.h @@ -34,19 +34,21 @@ typedef struct gkyl_dg_calc_sr_vars gkyl_dg_calc_sr_vars; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_dg_calc_sr_vars* -gkyl_dg_calc_sr_vars_new(const struct gkyl_rect_grid *phase_grid, const struct gkyl_rect_grid *vel_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *vel_basis, - const struct gkyl_range *mem_range, const struct gkyl_range *vel_range, bool use_gpu); +struct gkyl_dg_calc_sr_vars *gkyl_dg_calc_sr_vars_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_rect_grid *vel_grid, + const struct gkyl_basis *conf_basis, const struct gkyl_basis *vel_basis, + const struct gkyl_range *mem_range, const struct gkyl_range *vel_range, bool use_gpu +); /** * Create new updater to compute relativistic variables on * NV-GPU. See new() method for documentation. */ -struct gkyl_dg_calc_sr_vars* -gkyl_dg_calc_sr_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, const struct gkyl_rect_grid *vel_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *vel_basis, - const struct gkyl_range *mem_range, const struct gkyl_range *vel_range); +struct gkyl_dg_calc_sr_vars *gkyl_dg_calc_sr_vars_cu_dev_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_rect_grid *vel_grid, + const struct gkyl_basis *conf_basis, const struct gkyl_basis *vel_basis, + const struct gkyl_range *mem_range, const struct gkyl_range *vel_range +); /** * Compute the momentum grid variables for special relativistic simulations @@ -57,8 +59,9 @@ gkyl_dg_calc_sr_vars_cu_dev_new(const struct gkyl_rect_grid *phase_grid, const s * @param gamma Output array of particle Lorentz boost factor, gamma = sqrt(1 + p^2) * @param gamma_inv Output array of inverse particle Lorentz boost factor, 1/gamma = 1/sqrt(1 + p^2) */ -void gkyl_calc_sr_vars_init_p_vars(struct gkyl_dg_calc_sr_vars *up, - struct gkyl_array* gamma, struct gkyl_array* gamma_inv); +void gkyl_calc_sr_vars_init_p_vars( + struct gkyl_dg_calc_sr_vars *up, struct gkyl_array *gamma, struct gkyl_array *gamma_inv +); /** * Compute the rest-frame density n = GammaV_inv*M0 where GammaV_inv = sqrt(1 - |V_drift|^2). @@ -79,8 +82,10 @@ void gkyl_calc_sr_vars_init_p_vars(struct gkyl_dg_calc_sr_vars *up, * @param M1i Input lab-frame flux = GammaV*n*V_drift * @param n Output rest-frame density. */ -void gkyl_dg_calc_sr_vars_n(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_array* M0, const struct gkyl_array* M1i, struct gkyl_array* n); +void gkyl_dg_calc_sr_vars_n( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_array *M0, const struct gkyl_array *M1i, + struct gkyl_array *n +); /** * Compute derived quantities from spatial component of the bulk four-velocity u_i = GammaV*V_drift. @@ -94,10 +99,11 @@ void gkyl_dg_calc_sr_vars_n(struct gkyl_dg_calc_sr_vars *up, * @param GammaV Output Lorentz boost factor for the bulk four-velocity sqrt(1 + |u_i|^2) * @param GammaV_sq Output square of the Lorentz boost factor for the bulk four-velocity */ -void gkyl_dg_calc_sr_vars_GammaV(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* u_i, struct gkyl_array* u_i_sq, - struct gkyl_array* GammaV, struct gkyl_array* GammaV_sq); +void gkyl_dg_calc_sr_vars_GammaV( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *u_i, struct gkyl_array *u_i_sq, struct gkyl_array *GammaV, + struct gkyl_array *GammaV_sq +); /** * Compute the rest-frame pressure = n*T. The rest-frame pressure is computed as a velocity moment. @@ -120,12 +126,13 @@ void gkyl_dg_calc_sr_vars_GammaV(struct gkyl_dg_calc_sr_vars *up, * @param f Input distribution function * @param sr_pressure Output pressure */ -void gkyl_dg_calc_sr_vars_pressure(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* gamma, const struct gkyl_array* gamma_inv, - const struct gkyl_array* u_i, const struct gkyl_array* u_i_sq, - const struct gkyl_array* GammaV, const struct gkyl_array* GammaV_sq, - const struct gkyl_array* f, struct gkyl_array* sr_pressure); +void gkyl_dg_calc_sr_vars_pressure( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *gamma, + const struct gkyl_array *gamma_inv, const struct gkyl_array *u_i, const struct gkyl_array *u_i_sq, + const struct gkyl_array *GammaV, const struct gkyl_array *GammaV_sq, const struct gkyl_array *f, + struct gkyl_array *sr_pressure +); /** * Delete pointer to updater to compute sr variables. @@ -138,20 +145,25 @@ void gkyl_dg_calc_sr_vars_release(struct gkyl_dg_calc_sr_vars *up); * Host-side wrappers for sr vars operations on device */ -void gkyl_calc_sr_vars_init_p_vars_cu(struct gkyl_dg_calc_sr_vars *up, - struct gkyl_array* gamma, struct gkyl_array* gamma_inv); +void gkyl_calc_sr_vars_init_p_vars_cu( + struct gkyl_dg_calc_sr_vars *up, struct gkyl_array *gamma, struct gkyl_array *gamma_inv +); -void gkyl_dg_calc_sr_vars_n_cu(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_array* M0, const struct gkyl_array* M1i, struct gkyl_array* n); +void gkyl_dg_calc_sr_vars_n_cu( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_array *M0, const struct gkyl_array *M1i, + struct gkyl_array *n +); -void gkyl_dg_calc_sr_vars_GammaV_cu(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_range *conf_range, - const struct gkyl_array* u_i, struct gkyl_array* u_i_sq, - struct gkyl_array* GammaV, struct gkyl_array* GammaV_sq); +void gkyl_dg_calc_sr_vars_GammaV_cu( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_array *u_i, struct gkyl_array *u_i_sq, struct gkyl_array *GammaV, + struct gkyl_array *GammaV_sq +); -void gkyl_dg_calc_sr_vars_pressure_cu(struct gkyl_dg_calc_sr_vars *up, - const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, - const struct gkyl_array* gamma, const struct gkyl_array* gamma_inv, - const struct gkyl_array* u_i, const struct gkyl_array* u_i_sq, - const struct gkyl_array* GammaV, const struct gkyl_array* GammaV_sq, - const struct gkyl_array* f, struct gkyl_array* sr_pressure); +void gkyl_dg_calc_sr_vars_pressure_cu( + struct gkyl_dg_calc_sr_vars *up, const struct gkyl_range *conf_range, + const struct gkyl_range *phase_range, const struct gkyl_array *gamma, + const struct gkyl_array *gamma_inv, const struct gkyl_array *u_i, const struct gkyl_array *u_i_sq, + const struct gkyl_array *GammaV, const struct gkyl_array *GammaV_sq, const struct gkyl_array *f, + struct gkyl_array *sr_pressure +); diff --git a/vlasov/zero/gkyl_dg_calc_sr_vars_priv.h b/vlasov/zero/gkyl_dg_calc_sr_vars_priv.h index b5cb1bf2b0..cc220d76c6 100644 --- a/vlasov/zero/gkyl_dg_calc_sr_vars_priv.h +++ b/vlasov/zero/gkyl_dg_calc_sr_vars_priv.h @@ -11,195 +11,207 @@ #include #include -typedef void (*p_vars_t)(const double *w, const double *dv, - double* GKYL_RESTRICT gamma, double* GKYL_RESTRICT gamma_inv); +typedef void (*p_vars_t)( + const double *w, const double *dv, double *GKYL_RESTRICT gamma, double *GKYL_RESTRICT gamma_inv +); -typedef void (*sr_n_set_t)(int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, - const double *M0, const double *M1i); +typedef void (*sr_n_set_t)( + int count, struct gkyl_nmat *A, struct gkyl_nmat *rhs, const double *M0, const double *M1i +); -typedef void (*sr_n_copy_t)(int count, struct gkyl_nmat *x, - const double *M0, double* GKYL_RESTRICT n); +typedef void (*sr_n_copy_t)( + int count, struct gkyl_nmat *x, const double *M0, double *GKYL_RESTRICT n +); -typedef void (*sr_GammaV_t)(const double *u_i, double* GKYL_RESTRICT u_i_sq, - double* GKYL_RESTRICT GammaV, double* GKYL_RESTRICT GammaV_sq); +typedef void (*sr_GammaV_t)( + const double *u_i, double *GKYL_RESTRICT u_i_sq, double *GKYL_RESTRICT GammaV, + double *GKYL_RESTRICT GammaV_sq +); -typedef void (*sr_pressure_t)(const double *w, const double *dxv, - const double *gamma, const double *gamma_inv, - const double *u_i, const double *u_i_sq, - const double *GammaV, const double *GammaV_sq, - const double *f, double* GKYL_RESTRICT sr_pressure); +typedef void (*sr_pressure_t)( + const double *w, const double *dxv, const double *gamma, const double *gamma_inv, + const double *u_i, const double *u_i_sq, const double *GammaV, const double *GammaV_sq, + const double *f, double *GKYL_RESTRICT sr_pressure +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -GKYL_CU_D -static struct { int vdim[4]; } cv_index[] = { +GKYL_CU_D static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // for use in kernel tables -typedef struct { p_vars_t kernels[3]; } gkyl_dg_sr_p_vars_kern_list; -typedef struct { sr_n_set_t kernels[3]; } gkyl_dg_sr_vars_n_set_kern_list; -typedef struct { sr_n_copy_t kernels[3]; } gkyl_dg_sr_vars_n_copy_kern_list; -typedef struct { sr_GammaV_t kernels[3]; } gkyl_dg_sr_vars_GammaV_kern_list; -typedef struct { sr_pressure_t kernels[3]; } gkyl_dg_sr_vars_pressure_kern_list; +typedef struct { + p_vars_t kernels[3]; +} gkyl_dg_sr_p_vars_kern_list; +typedef struct { + sr_n_set_t kernels[3]; +} gkyl_dg_sr_vars_n_set_kern_list; +typedef struct { + sr_n_copy_t kernels[3]; +} gkyl_dg_sr_vars_n_copy_kern_list; +typedef struct { + sr_GammaV_t kernels[3]; +} gkyl_dg_sr_vars_GammaV_kern_list; +typedef struct { + sr_pressure_t kernels[3]; +} gkyl_dg_sr_vars_pressure_kern_list; struct gkyl_dg_calc_sr_vars { - struct gkyl_rect_grid phase_grid; // Phase-space grid for cell spacing and cell center - // in pressure velocity moment computation. - struct gkyl_rect_grid vel_grid; // Momentum (four-velocity)-space grid for cell spacing and cell center - // in gamma and 1/gamma computation. + struct gkyl_rect_grid phase_grid; // Phase-space grid for cell spacing and cell center + // in pressure velocity moment computation. + struct gkyl_rect_grid + vel_grid; // Momentum (four-velocity)-space grid for cell spacing and cell center + // in gamma and 1/gamma computation. struct gkyl_range vel_range; // Momentum (four-velocity)-space range. int poly_order; // polynomial order (determines whether we solve linear system or use basis_inv method). struct gkyl_range mem_range; // Configuration-space range for linear solve. - struct gkyl_nmat *As, *xs; // matrices for LHS and RHS for V_drift solve to find rest-frame density. - gkyl_nmat_mem *mem; // memory for use in batched linear solve for V_drift solve to find rest-frame density. + struct gkyl_nmat *As, + *xs; // matrices for LHS and RHS for V_drift solve to find rest-frame density. + gkyl_nmat_mem + *mem; // memory for use in batched linear solve for V_drift solve to find rest-frame density. int Ncomp; // number of components in the linear solve (vdim components of V_drift from weak division). - p_vars_t sr_p_vars; // kernel for computing gamma = sqrt(1 + p^2) and its inverse on momentum (four-velocity) grid. + p_vars_t + sr_p_vars; // kernel for computing gamma = sqrt(1 + p^2) and its inverse on momentum (four-velocity) grid. sr_n_set_t sr_n_set; // kernel for setting matrices for linear solve for rest-frame density. - sr_n_copy_t sr_n_copy; // kernel for copying solution for V_drift from weak division and computing rest-frame density. + sr_n_copy_t + sr_n_copy; // kernel for copying solution for V_drift from weak division and computing rest-frame density. sr_GammaV_t sr_GammaV; // kernel for computing bulk four-velocity derived quantities such as GammaV. - sr_pressure_t sr_pressure; // kernel for computing rest-frame pressure as a velocity moment of distribution function. + sr_pressure_t + sr_pressure; // kernel for computing rest-frame pressure as a velocity moment of distribution function. uint32_t flags; struct gkyl_dg_calc_sr_vars *on_dev; // pointer to itself or device data. }; // Particle Lorentz boost factor gamma = sqrt(1 + p^2) (also 1/gamma) kernel list (Serendipity kernels). -GKYL_CU_D -static const gkyl_dg_sr_p_vars_kern_list ser_sr_p_vars_kernels[] = { +GKYL_CU_D static const gkyl_dg_sr_p_vars_kern_list ser_sr_p_vars_kernels[] = { // 1x kernels - { NULL, NULL, sr_vars_lorentz_1v_ser_p2 }, // 0 - { NULL, NULL, sr_vars_lorentz_2v_ser_p2 }, // 1 - { NULL, NULL, sr_vars_lorentz_3v_ser_p2 }, // 2 + {NULL, NULL, sr_vars_lorentz_1v_ser_p2}, // 0 + {NULL, NULL, sr_vars_lorentz_2v_ser_p2}, // 1 + {NULL, NULL, sr_vars_lorentz_3v_ser_p2} // 2 }; // Set matrices for computing rest-frame density kernel list (Serendipity kernels). -GKYL_CU_D -static const gkyl_dg_sr_vars_n_set_kern_list ser_sr_vars_n_set_kernels[] = { +GKYL_CU_D static const gkyl_dg_sr_vars_n_set_kern_list ser_sr_vars_n_set_kernels[] = { // 1x kernels - { NULL, sr_vars_n_set_1x1v_ser_p1, sr_vars_n_set_1x1v_ser_p2 }, // 0 - { NULL, sr_vars_n_set_1x2v_ser_p1, sr_vars_n_set_1x2v_ser_p2 }, // 1 - { NULL, sr_vars_n_set_1x3v_ser_p1, sr_vars_n_set_1x3v_ser_p2 }, // 2 + {NULL, sr_vars_n_set_1x1v_ser_p1, sr_vars_n_set_1x1v_ser_p2}, // 0 + {NULL, sr_vars_n_set_1x2v_ser_p1, sr_vars_n_set_1x2v_ser_p2}, // 1 + {NULL, sr_vars_n_set_1x3v_ser_p1, sr_vars_n_set_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, sr_vars_n_set_2x2v_ser_p1, sr_vars_n_set_2x2v_ser_p2 }, // 3 - { NULL, sr_vars_n_set_2x3v_ser_p1, sr_vars_n_set_2x3v_ser_p2 }, // 4 + {NULL, sr_vars_n_set_2x2v_ser_p1, sr_vars_n_set_2x2v_ser_p2}, // 3 + {NULL, sr_vars_n_set_2x3v_ser_p1, sr_vars_n_set_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, sr_vars_n_set_3x3v_ser_p1, NULL }, // 5 + {NULL, sr_vars_n_set_3x3v_ser_p1, NULL} // 5 }; // Copy solution for computing rest-frame density kernel list (Serendipity kernels). -GKYL_CU_D -static const gkyl_dg_sr_vars_n_copy_kern_list ser_sr_vars_n_copy_kernels[] = { +GKYL_CU_D static const gkyl_dg_sr_vars_n_copy_kern_list ser_sr_vars_n_copy_kernels[] = { // 1x kernels - { NULL, sr_vars_n_copy_1x1v_ser_p1, sr_vars_n_copy_1x1v_ser_p2 }, // 0 - { NULL, sr_vars_n_copy_1x2v_ser_p1, sr_vars_n_copy_1x2v_ser_p2 }, // 1 - { NULL, sr_vars_n_copy_1x3v_ser_p1, sr_vars_n_copy_1x3v_ser_p2 }, // 2 + {NULL, sr_vars_n_copy_1x1v_ser_p1, sr_vars_n_copy_1x1v_ser_p2}, // 0 + {NULL, sr_vars_n_copy_1x2v_ser_p1, sr_vars_n_copy_1x2v_ser_p2}, // 1 + {NULL, sr_vars_n_copy_1x3v_ser_p1, sr_vars_n_copy_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, sr_vars_n_copy_2x2v_ser_p1, sr_vars_n_copy_2x2v_ser_p2 }, // 3 - { NULL, sr_vars_n_copy_2x3v_ser_p1, sr_vars_n_copy_2x3v_ser_p2 }, // 4 + {NULL, sr_vars_n_copy_2x2v_ser_p1, sr_vars_n_copy_2x2v_ser_p2}, // 3 + {NULL, sr_vars_n_copy_2x3v_ser_p1, sr_vars_n_copy_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, sr_vars_n_copy_3x3v_ser_p1, NULL }, // 5 + {NULL, sr_vars_n_copy_3x3v_ser_p1, NULL} // 5 }; // Compute bulk four-velocity derived quantities kernel list (Serendipity kernels). -GKYL_CU_D -static const gkyl_dg_sr_vars_GammaV_kern_list ser_sr_vars_GammaV_kernels[] = { +GKYL_CU_D static const gkyl_dg_sr_vars_GammaV_kern_list ser_sr_vars_GammaV_kernels[] = { // 1x kernels - { NULL, sr_vars_GammaV_1x1v_ser_p1, sr_vars_GammaV_1x1v_ser_p2 }, // 0 - { NULL, sr_vars_GammaV_1x2v_ser_p1, sr_vars_GammaV_1x2v_ser_p2 }, // 1 - { NULL, sr_vars_GammaV_1x3v_ser_p1, sr_vars_GammaV_1x3v_ser_p2 }, // 2 + {NULL, sr_vars_GammaV_1x1v_ser_p1, sr_vars_GammaV_1x1v_ser_p2}, // 0 + {NULL, sr_vars_GammaV_1x2v_ser_p1, sr_vars_GammaV_1x2v_ser_p2}, // 1 + {NULL, sr_vars_GammaV_1x3v_ser_p1, sr_vars_GammaV_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, sr_vars_GammaV_2x2v_ser_p1, sr_vars_GammaV_2x2v_ser_p2 }, // 3 - { NULL, sr_vars_GammaV_2x3v_ser_p1, sr_vars_GammaV_2x3v_ser_p2 }, // 4 + {NULL, sr_vars_GammaV_2x2v_ser_p1, sr_vars_GammaV_2x2v_ser_p2}, // 3 + {NULL, sr_vars_GammaV_2x3v_ser_p1, sr_vars_GammaV_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, sr_vars_GammaV_3x3v_ser_p1, NULL }, // 5 + {NULL, sr_vars_GammaV_3x3v_ser_p1, NULL} // 5 }; // Compute rest-frame pressure kernel list (Serendipity kernels). -GKYL_CU_D -static const gkyl_dg_sr_vars_pressure_kern_list ser_sr_vars_pressure_kernels[] = { +GKYL_CU_D static const gkyl_dg_sr_vars_pressure_kern_list ser_sr_vars_pressure_kernels[] = { // 1x kernels - { NULL, sr_vars_pressure_1x1v_ser_p1, sr_vars_pressure_1x1v_ser_p2 }, // 0 - { NULL, sr_vars_pressure_1x2v_ser_p1, sr_vars_pressure_1x2v_ser_p2 }, // 1 - { NULL, sr_vars_pressure_1x3v_ser_p1, sr_vars_pressure_1x3v_ser_p2 }, // 2 + {NULL, sr_vars_pressure_1x1v_ser_p1, sr_vars_pressure_1x1v_ser_p2}, // 0 + {NULL, sr_vars_pressure_1x2v_ser_p1, sr_vars_pressure_1x2v_ser_p2}, // 1 + {NULL, sr_vars_pressure_1x3v_ser_p1, sr_vars_pressure_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, sr_vars_pressure_2x2v_ser_p1, sr_vars_pressure_2x2v_ser_p2 }, // 3 - { NULL, sr_vars_pressure_2x3v_ser_p1, sr_vars_pressure_2x3v_ser_p2 }, // 4 + {NULL, sr_vars_pressure_2x2v_ser_p1, sr_vars_pressure_2x2v_ser_p2}, // 3 + {NULL, sr_vars_pressure_2x3v_ser_p1, sr_vars_pressure_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, sr_vars_pressure_3x3v_ser_p1, NULL }, // 5 + {NULL, sr_vars_pressure_3x3v_ser_p1, NULL} // 5 }; -GKYL_CU_D -static p_vars_t +GKYL_CU_D static p_vars_t choose_sr_p_vars_kern(enum gkyl_basis_type b_type, int vdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_sr_p_vars_kernels[vdim-1].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_sr_p_vars_kernels[vdim - 1].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static sr_n_set_t +GKYL_CU_D static sr_n_set_t choose_sr_vars_n_set_kern(enum gkyl_basis_type b_type, int cdim, int vdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_sr_vars_n_set_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_sr_vars_n_set_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static sr_n_copy_t +GKYL_CU_D static sr_n_copy_t choose_sr_vars_n_copy_kern(enum gkyl_basis_type b_type, int cdim, int vdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_sr_vars_n_copy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_sr_vars_n_copy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static sr_GammaV_t +GKYL_CU_D static sr_GammaV_t choose_sr_vars_GammaV_kern(enum gkyl_basis_type b_type, int cdim, int vdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_sr_vars_GammaV_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_sr_vars_GammaV_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; + break; + default: + assert(false); + break; } } -GKYL_CU_D -static sr_pressure_t +GKYL_CU_D static sr_pressure_t choose_sr_vars_pressure_kern(enum gkyl_basis_type b_type, int cdim, int vdim, int poly_order) { switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - return ser_sr_vars_pressure_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + return ser_sr_vars_pressure_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; + break; + default: + assert(false); + break; } } diff --git a/vlasov/zero/gkyl_dg_canonical_pb.h b/vlasov/zero/gkyl_dg_canonical_pb.h index 3250a44966..556144febf 100644 --- a/vlasov/zero/gkyl_dg_canonical_pb.h +++ b/vlasov/zero/gkyl_dg_canonical_pb.h @@ -9,7 +9,7 @@ // Struct containing the pointers to auxiliary fields. // Specified hamiltonian in *Canonical* cordinates -struct gkyl_dg_canonical_pb_auxfields { +struct gkyl_dg_canonical_pb_auxfields { const struct gkyl_array *hamil; const struct gkyl_array *alpha_surf; const struct gkyl_array *sgn_alpha_surf; @@ -25,8 +25,10 @@ struct gkyl_dg_canonical_pb_auxfields { * @param use_gpu bool to determine if on GPU * @return Pointer to special canonical-pb equation object */ -struct gkyl_dg_eqn* gkyl_dg_canonical_pb_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_canonical_pb_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, bool use_gpu +); /** * Create a new special canonical-pb equation object that lives on NV-GPU @@ -37,8 +39,10 @@ struct gkyl_dg_eqn* gkyl_dg_canonical_pb_new(const struct gkyl_basis* cbasis, * (special canonical-pb-Maxwell vs. special relativistic neutrals) * @return Pointer to special canonical-pb equation object */ -struct gkyl_dg_eqn* gkyl_dg_canonical_pb_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range); +struct gkyl_dg_eqn *gkyl_dg_canonical_pb_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range +); /** * Set the auxiliary fields @@ -46,8 +50,9 @@ struct gkyl_dg_eqn* gkyl_dg_canonical_pb_cu_dev_new(const struct gkyl_basis* cba * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_canonical_pb_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_auxfields auxin); - +void gkyl_canonical_pb_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_auxfields auxin +); #ifdef GKYL_HAVE_CUDA /** @@ -56,6 +61,8 @@ void gkyl_canonical_pb_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_ * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_canonical_pb_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_auxfields auxin); +void gkyl_canonical_pb_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_canonical_pb_fluid.h b/vlasov/zero/gkyl_dg_canonical_pb_fluid.h index 168c5639f2..e165f85f77 100644 --- a/vlasov/zero/gkyl_dg_canonical_pb_fluid.h +++ b/vlasov/zero/gkyl_dg_canonical_pb_fluid.h @@ -10,7 +10,7 @@ // Struct containing the pointers to auxiliary fields. // Potential is in *Canonical* cordinates. -struct gkyl_dg_canonical_pb_fluid_auxfields { +struct gkyl_dg_canonical_pb_fluid_auxfields { const struct gkyl_array *phi; const struct gkyl_array *alpha_surf; const struct gkyl_array *sgn_alpha_surf; @@ -29,15 +29,19 @@ struct gkyl_dg_canonical_pb_fluid_auxfields { * @param use_gpu bool to determine if on GPU * @return Pointer to special canonical-pb equation object */ -struct gkyl_dg_eqn* gkyl_dg_canonical_pb_fluid_new(const struct gkyl_basis* cbasis, - const struct gkyl_range* conf_range, const struct gkyl_wv_eqn *wv_eqn, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_canonical_pb_fluid_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, + const struct gkyl_wv_eqn *wv_eqn, bool use_gpu +); /** * Create a new canonical-pb equation object for fluid systems object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_dg_eqn* gkyl_dg_canonical_pb_fluid_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_range* conf_range, const struct gkyl_wv_eqn *wv_eqn); +struct gkyl_dg_eqn *gkyl_dg_canonical_pb_fluid_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, + const struct gkyl_wv_eqn *wv_eqn +); /** * Set the auxiliary fields @@ -45,8 +49,9 @@ struct gkyl_dg_eqn* gkyl_dg_canonical_pb_fluid_cu_dev_new(const struct gkyl_basi * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_canonical_pb_fluid_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_fluid_auxfields auxin); - +void gkyl_canonical_pb_fluid_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_fluid_auxfields auxin +); #ifdef GKYL_HAVE_CUDA /** @@ -55,6 +60,8 @@ void gkyl_canonical_pb_fluid_set_auxfields(const struct gkyl_dg_eqn *eqn, struct * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_canonical_pb_fluid_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_fluid_auxfields auxin); +void gkyl_canonical_pb_fluid_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_canonical_pb_fluid_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_canonical_pb_fluid_priv.h b/vlasov/zero/gkyl_dg_canonical_pb_fluid_priv.h index 44cad87f9f..861084ede9 100644 --- a/vlasov/zero/gkyl_dg_canonical_pb_fluid_priv.h +++ b/vlasov/zero/gkyl_dg_canonical_pb_fluid_priv.h @@ -10,16 +10,21 @@ #include // Types for various kernels -typedef double (*canonical_pb_fluid_surf_t)(const double *w, const double *dxv, - const double *phi, - const double *alpha_surf_edge, const double *alpha_surf_skin, - const double *sgn_alpha_surf_edge, const double *sgn_alpha_surf_skin, - const int *const_sgn_alpha_edge, const int *const_sgn_alpha_skin, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); +typedef double (*canonical_pb_fluid_surf_t)( + const double *w, const double *dxv, const double *phi, const double *alpha_surf_edge, + const double *alpha_surf_skin, const double *sgn_alpha_surf_edge, + const double *sgn_alpha_surf_skin, const int *const_sgn_alpha_edge, + const int *const_sgn_alpha_skin, const double *fl, const double *fc, const double *fr, + double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_canonical_pb_fluid_vol_kern_list; -typedef struct { canonical_pb_fluid_surf_t kernels[3]; } gkyl_dg_canonical_pb_fluid_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_canonical_pb_fluid_vol_kern_list; +typedef struct { + canonical_pb_fluid_surf_t kernels[3]; +} gkyl_dg_canonical_pb_fluid_surf_kern_list; struct dg_canonical_pb_fluid { struct gkyl_dg_eqn eqn; // Base object @@ -34,52 +39,50 @@ struct dg_canonical_pb_fluid { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_canonical_pb_fluid_vol_2x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_fluid_vol_2x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb_fluid *can_pb_fluid = container_of(eqn, struct dg_canonical_pb_fluid, eqn); long cidx = gkyl_range_idx(&can_pb_fluid->conf_range, idx); - return canonical_pb_vol_2x_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(can_pb_fluid->auxfields.phi, cidx), - qIn, qRhsOut); + return canonical_pb_vol_2x_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(can_pb_fluid->auxfields.phi, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_fluid_vol_2x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_fluid_vol_2x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb_fluid *can_pb_fluid = container_of(eqn, struct dg_canonical_pb_fluid, eqn); long cidx = gkyl_range_idx(&can_pb_fluid->conf_range, idx); - return canonical_pb_vol_2x_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(can_pb_fluid->auxfields.phi, cidx), - qIn, qRhsOut); + return canonical_pb_vol_2x_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(can_pb_fluid->auxfields.phi, cidx), qIn, qRhsOut + ); } // Volume kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, kernel_canonical_pb_fluid_vol_2x_ser_p1, kernel_canonical_pb_fluid_vol_2x_ser_p2 }, // 1 + {NULL, kernel_canonical_pb_fluid_vol_2x_ser_p1, kernel_canonical_pb_fluid_vol_2x_ser_p2}, // 1 // 3x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL} // 2 }; // Volume kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_vol_kern_list tensor_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_vol_kern_list tensor_vol_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, kernel_canonical_pb_fluid_vol_2x_ser_p1, NULL }, // 1 + {NULL, kernel_canonical_pb_fluid_vol_2x_ser_p1, NULL}, // 1 // 3x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL} // 2 }; // @@ -88,140 +91,133 @@ static const gkyl_dg_canonical_pb_fluid_vol_kern_list tensor_vol_kernels[] = { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_canonical_pb_two_fluid_vol_2x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_two_fluid_vol_2x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb_fluid *can_pb_fluid = container_of(eqn, struct dg_canonical_pb_fluid, eqn); long cidx = gkyl_range_idx(&can_pb_fluid->conf_range, idx); - return canonical_pb_two_fluid_vol_2x_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(can_pb_fluid->auxfields.phi, cidx), - qIn, qRhsOut); + return canonical_pb_two_fluid_vol_2x_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(can_pb_fluid->auxfields.phi, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_two_fluid_vol_2x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_two_fluid_vol_2x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb_fluid *can_pb_fluid = container_of(eqn, struct dg_canonical_pb_fluid, eqn); long cidx = gkyl_range_idx(&can_pb_fluid->conf_range, idx); - return canonical_pb_two_fluid_vol_2x_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(can_pb_fluid->auxfields.phi, cidx), - qIn, qRhsOut); + return canonical_pb_two_fluid_vol_2x_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(can_pb_fluid->auxfields.phi, cidx), qIn, qRhsOut + ); } // Volume kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_vol_kern_list ser_two_fluid_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_vol_kern_list ser_two_fluid_vol_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, kernel_canonical_pb_two_fluid_vol_2x_ser_p1, kernel_canonical_pb_two_fluid_vol_2x_ser_p2 }, // 1 + {NULL, kernel_canonical_pb_two_fluid_vol_2x_ser_p1, kernel_canonical_pb_two_fluid_vol_2x_ser_p2 + }, // 1 // 3x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL} // 2 }; // Volume kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_vol_kern_list tensor_two_fluid_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_vol_kern_list tensor_two_fluid_vol_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, kernel_canonical_pb_two_fluid_vol_2x_ser_p1, NULL }, // 1 + {NULL, kernel_canonical_pb_two_fluid_vol_2x_ser_p1, NULL}, // 1 // 3x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL} // 2 }; // Surface kernel list: x-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_surf_kern_list ser_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_surf_kern_list ser_surf_x_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, canonical_pb_surfx_2x_ser_p1, canonical_pb_surfx_2x_ser_p2 }, // 1 + {NULL, canonical_pb_surfx_2x_ser_p1, canonical_pb_surfx_2x_ser_p2}, // 1 // 3x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL} // 2 }; // Surface kernel list: x-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_surf_kern_list tensor_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_surf_kern_list tensor_surf_x_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, canonical_pb_surfx_2x_ser_p1, NULL }, // 1 + {NULL, canonical_pb_surfx_2x_ser_p1, NULL}, // 1 // 3x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL} // 2 }; // Surface kernel list: y-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_surf_kern_list ser_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_surf_kern_list ser_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, canonical_pb_surfy_2x_ser_p1, canonical_pb_surfy_2x_ser_p2 }, // 1 + {NULL, canonical_pb_surfy_2x_ser_p1, canonical_pb_surfy_2x_ser_p2}, // 1 // 3x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL} // 2 }; // Surface kernel list: y-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_surf_kern_list tensor_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_surf_kern_list tensor_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, canonical_pb_surfy_2x_ser_p1, NULL }, // 1 + {NULL, canonical_pb_surfy_2x_ser_p1, NULL}, // 1 // 3x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL} // 2 }; // Surface two fluid kernel list: x-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_surf_kern_list ser_two_fluid_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_surf_kern_list ser_two_fluid_surf_x_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, canonical_pb_two_fluid_surfx_2x_ser_p1, canonical_pb_two_fluid_surfx_2x_ser_p2 }, // 1 + {NULL, canonical_pb_two_fluid_surfx_2x_ser_p1, canonical_pb_two_fluid_surfx_2x_ser_p2}, // 1 // 3x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL} // 2 }; // Surface two fluid kernel list: x-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_surf_kern_list tensor_two_fluid_surf_x_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_two_fluid_surfx_2x_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_surf_kern_list tensor_two_fluid_surf_x_kernels[] = + { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_two_fluid_surfx_2x_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; // Surface two fluid kernel list: y-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_surf_kern_list ser_two_fluid_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_surf_kern_list ser_two_fluid_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 + {NULL, NULL, NULL}, // 0 // 2x kernels - { NULL, canonical_pb_two_fluid_surfy_2x_ser_p1, canonical_pb_two_fluid_surfy_2x_ser_p2 }, // 1 + {NULL, canonical_pb_two_fluid_surfy_2x_ser_p1, canonical_pb_two_fluid_surfy_2x_ser_p2}, // 1 // 3x kernels - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL} // 2 }; // Surface two fluid kernel list: y-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_canonical_pb_fluid_surf_kern_list tensor_two_fluid_surf_y_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - // 2x kernels - { NULL, canonical_pb_two_fluid_surfy_2x_ser_p1, NULL }, // 1 - // 3x kernels - { NULL, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_canonical_pb_fluid_surf_kern_list tensor_two_fluid_surf_y_kernels[] = + { + // 1x kernels + {NULL, NULL, NULL}, // 0 + // 2x kernels + {NULL, canonical_pb_two_fluid_surfy_2x_ser_p1, NULL}, // 1 + // 3x kernels + {NULL, NULL, NULL} // 2 }; /** @@ -231,15 +227,13 @@ static const gkyl_dg_canonical_pb_fluid_surf_kern_list tensor_two_fluid_surf_y_k */ void gkyl_canonical_pb_fluid_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) -{ +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) +{ // Each cell owns the *lower* edge surface alpha // Since alpha is continuous, fetch alpha_surf in center cell for lower edge // and fetch alpha_surf in right cell for upper edge @@ -247,15 +241,16 @@ surf(const struct gkyl_dg_eqn *eqn, long cidxC = gkyl_range_idx(&can_pb_fluid->conf_range, idxC); long cidxR = gkyl_range_idx(&can_pb_fluid->conf_range, idxR); if (dir < can_pb_fluid->cdim) { - return can_pb_fluid->surf[dir](xcC, dxC, - (const double*) gkyl_array_cfetch(can_pb_fluid->auxfields.phi, cidxC), - (const double*) gkyl_array_cfetch(can_pb_fluid->auxfields.alpha_surf, cidxC), - (const double*) gkyl_array_cfetch(can_pb_fluid->auxfields.alpha_surf, cidxR), - (const double*) gkyl_array_cfetch(can_pb_fluid->auxfields.sgn_alpha_surf, cidxC), - (const double*) gkyl_array_cfetch(can_pb_fluid->auxfields.sgn_alpha_surf, cidxR), - (const int*) gkyl_array_cfetch(can_pb_fluid->auxfields.const_sgn_alpha, cidxC), - (const int*) gkyl_array_cfetch(can_pb_fluid->auxfields.const_sgn_alpha, cidxR), - qInL, qInC, qInR, qRhsOut); + return can_pb_fluid->surf[dir]( + xcC, dxC, (const double *)gkyl_array_cfetch(can_pb_fluid->auxfields.phi, cidxC), + (const double *)gkyl_array_cfetch(can_pb_fluid->auxfields.alpha_surf, cidxC), + (const double *)gkyl_array_cfetch(can_pb_fluid->auxfields.alpha_surf, cidxR), + (const double *)gkyl_array_cfetch(can_pb_fluid->auxfields.sgn_alpha_surf, cidxC), + (const double *)gkyl_array_cfetch(can_pb_fluid->auxfields.sgn_alpha_surf, cidxR), + (const int *)gkyl_array_cfetch(can_pb_fluid->auxfields.const_sgn_alpha, cidxC), + (const int *)gkyl_array_cfetch(can_pb_fluid->auxfields.const_sgn_alpha, cidxR), qInL, qInC, + qInR, qRhsOut + ); } return 0.; } diff --git a/vlasov/zero/gkyl_dg_canonical_pb_priv.h b/vlasov/zero/gkyl_dg_canonical_pb_priv.h index f637fb3288..c3f82eb05b 100644 --- a/vlasov/zero/gkyl_dg_canonical_pb_priv.h +++ b/vlasov/zero/gkyl_dg_canonical_pb_priv.h @@ -10,41 +10,53 @@ #include // Types for various kernels -typedef double (*canonical_pb_stream_surf_t)(const double *w, const double *dxv, - const double *hamil, - const double *alpha_surf_edge, const double *alpha_surf_skin, - const double *sgn_alpha_surf_edge, const double *sgn_alpha_surf_skin, - const int *const_sgn_alpha_edge, const int *const_sgn_alpha_skin, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); - -typedef double (*canonical_pb_accel_surf_t)(const double *w, const double *dxv, - const double *hamil, - const double *alpha_surf_l, const double *alpha_surf_r, - const double *sgn_alpha_surf_l, const double *sgn_alpha_surf_r, - const int *const_sgn_alpha_l, const int *const_sgn_alpha_r, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); - -typedef double (*canonical_pb_accel_boundary_surf_t)(const double *w, const double *dxv, - const double *hamil, - const double *alpha_surf_edge, const double *alpha_surf_skin, - const double *sgn_alpha_surf_edge, const double *sgn_alpha_surf_skin, - const int *const_sgn_alpha_edge, const int *const_sgn_alpha_skin, - const int edge, const double *fedge, const double *fskin, double* GKYL_RESTRICT out); - -typedef double (*canonical_pb_stream_boundary_surf_t)(const double *w, const double *dxv, - const double *hamil, - const double *alpha_surf_edge, const double *alpha_surf_skin, - const double *sgn_alpha_surf_edge, const double *sgn_alpha_surf_skin, - const int *const_sgn_alpha_edge, const int *const_sgn_alpha_skin, - const int edge, const double *fedge, const double *fskin, double* GKYL_RESTRICT out); - +typedef double (*canonical_pb_stream_surf_t)( + const double *w, const double *dxv, const double *hamil, const double *alpha_surf_edge, + const double *alpha_surf_skin, const double *sgn_alpha_surf_edge, + const double *sgn_alpha_surf_skin, const int *const_sgn_alpha_edge, + const int *const_sgn_alpha_skin, const double *fl, const double *fc, const double *fr, + double *GKYL_RESTRICT out +); + +typedef double (*canonical_pb_accel_surf_t)( + const double *w, const double *dxv, const double *hamil, const double *alpha_surf_l, + const double *alpha_surf_r, const double *sgn_alpha_surf_l, const double *sgn_alpha_surf_r, + const int *const_sgn_alpha_l, const int *const_sgn_alpha_r, const double *fl, const double *fc, + const double *fr, double *GKYL_RESTRICT out +); + +typedef double (*canonical_pb_accel_boundary_surf_t)( + const double *w, const double *dxv, const double *hamil, const double *alpha_surf_edge, + const double *alpha_surf_skin, const double *sgn_alpha_surf_edge, + const double *sgn_alpha_surf_skin, const int *const_sgn_alpha_edge, + const int *const_sgn_alpha_skin, const int edge, const double *fedge, const double *fskin, + double *GKYL_RESTRICT out +); + +typedef double (*canonical_pb_stream_boundary_surf_t)( + const double *w, const double *dxv, const double *hamil, const double *alpha_surf_edge, + const double *alpha_surf_skin, const double *sgn_alpha_surf_edge, + const double *sgn_alpha_surf_skin, const int *const_sgn_alpha_edge, + const int *const_sgn_alpha_skin, const int edge, const double *fedge, const double *fskin, + double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_canonical_pb_vol_kern_list; -typedef struct { canonical_pb_stream_surf_t kernels[3]; } gkyl_dg_canonical_pb_stream_surf_kern_list; -typedef struct { canonical_pb_accel_surf_t kernels[3]; } gkyl_dg_canonical_pb_accel_surf_kern_list; -typedef struct { canonical_pb_stream_boundary_surf_t kernels[3]; } gkyl_dg_canonical_pb_stream_boundary_surf_kern_list; -typedef struct { canonical_pb_accel_boundary_surf_t kernels[3]; } gkyl_dg_canonical_pb_accel_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_canonical_pb_vol_kern_list; +typedef struct { + canonical_pb_stream_surf_t kernels[3]; +} gkyl_dg_canonical_pb_stream_surf_kern_list; +typedef struct { + canonical_pb_accel_surf_t kernels[3]; +} gkyl_dg_canonical_pb_accel_surf_kern_list; +typedef struct { + canonical_pb_stream_boundary_surf_t kernels[3]; +} gkyl_dg_canonical_pb_stream_boundary_surf_kern_list; +typedef struct { + canonical_pb_accel_boundary_surf_t kernels[3]; +} gkyl_dg_canonical_pb_accel_boundary_surf_kern_list; struct dg_canonical_pb { struct gkyl_dg_eqn eqn; // Base object @@ -62,161 +74,161 @@ struct dg_canonical_pb { // The cv_index[cd].vdim[cd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; - // // Serendipity volume kernels // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x1v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x1v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_2x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_2x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_2x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_2x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_2x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_2x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_2x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_2x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_2x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_2x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_2x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_2x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_canonical_pb_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, kernel_canonical_pb_vol_1x1v_ser_p1, kernel_canonical_pb_vol_1x1v_ser_p2 }, // 0 - { NULL, kernel_canonical_pb_vol_1x2v_ser_p1, kernel_canonical_pb_vol_1x2v_ser_p2 }, // 1 - { NULL, kernel_canonical_pb_vol_1x3v_ser_p1, kernel_canonical_pb_vol_1x3v_ser_p2 }, // 2 + {NULL, kernel_canonical_pb_vol_1x1v_ser_p1, kernel_canonical_pb_vol_1x1v_ser_p2}, // 0 + {NULL, kernel_canonical_pb_vol_1x2v_ser_p1, kernel_canonical_pb_vol_1x2v_ser_p2}, // 1 + {NULL, kernel_canonical_pb_vol_1x3v_ser_p1, kernel_canonical_pb_vol_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_canonical_pb_vol_2x2v_ser_p1, kernel_canonical_pb_vol_2x2v_ser_p2 }, // 3 - { NULL, kernel_canonical_pb_vol_2x3v_ser_p1, kernel_canonical_pb_vol_2x3v_ser_p2 }, // 4 + {NULL, kernel_canonical_pb_vol_2x2v_ser_p1, kernel_canonical_pb_vol_2x2v_ser_p2}, // 3 + {NULL, kernel_canonical_pb_vol_2x3v_ser_p1, kernel_canonical_pb_vol_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; // @@ -224,323 +236,313 @@ static const gkyl_dg_canonical_pb_vol_kern_list ser_vol_kernels[] = { // // Streaming surface kernel list: x-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_surf_kern_list ser_stream_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_surf_kern_list ser_stream_surf_x_kernels[] = { // 1x kernels - { NULL, canonical_pb_surfx_1x1v_ser_p1, canonical_pb_surfx_1x1v_ser_p2 }, // 0 - { NULL, canonical_pb_surfx_1x2v_ser_p1, canonical_pb_surfx_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_surfx_1x3v_ser_p1, canonical_pb_surfx_1x3v_ser_p2 }, // 2 + {NULL, canonical_pb_surfx_1x1v_ser_p1, canonical_pb_surfx_1x1v_ser_p2}, // 0 + {NULL, canonical_pb_surfx_1x2v_ser_p1, canonical_pb_surfx_1x2v_ser_p2}, // 1 + {NULL, canonical_pb_surfx_1x3v_ser_p1, canonical_pb_surfx_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, canonical_pb_surfx_2x2v_ser_p1, canonical_pb_surfx_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_surfx_2x3v_ser_p1, canonical_pb_surfx_2x3v_ser_p2 }, // 4 + {NULL, canonical_pb_surfx_2x2v_ser_p1, canonical_pb_surfx_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_surfx_2x3v_ser_p1, canonical_pb_surfx_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; // Streaming surface kernel list: y-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_surf_kern_list ser_stream_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_surf_kern_list ser_stream_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 // 2x kernels - { NULL, canonical_pb_surfy_2x2v_ser_p1, canonical_pb_surfy_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_surfy_2x3v_ser_p1, canonical_pb_surfy_2x3v_ser_p2 }, // 4 + {NULL, canonical_pb_surfy_2x2v_ser_p1, canonical_pb_surfy_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_surfy_2x3v_ser_p1, canonical_pb_surfy_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; // Streaming surface kernel list: z-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_surf_kern_list ser_stream_surf_z_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_surf_kern_list ser_stream_surf_z_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; // Acceleration surface kernel list: vx-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_surf_kern_list ser_accel_surf_vx_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_surf_kern_list ser_accel_surf_vx_kernels[] = { // 1x kernels - { NULL, canonical_pb_surfvx_1x1v_ser_p1, canonical_pb_surfvx_1x1v_ser_p2 }, // 0 - { NULL, canonical_pb_surfvx_1x2v_ser_p1, canonical_pb_surfvx_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_surfvx_1x3v_ser_p1, canonical_pb_surfvx_1x3v_ser_p2 }, // 2 + {NULL, canonical_pb_surfvx_1x1v_ser_p1, canonical_pb_surfvx_1x1v_ser_p2}, // 0 + {NULL, canonical_pb_surfvx_1x2v_ser_p1, canonical_pb_surfvx_1x2v_ser_p2}, // 1 + {NULL, canonical_pb_surfvx_1x3v_ser_p1, canonical_pb_surfvx_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, canonical_pb_surfvx_2x2v_ser_p1, canonical_pb_surfvx_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_surfvx_2x3v_ser_p1, canonical_pb_surfvx_2x3v_ser_p2 }, // 4 + {NULL, canonical_pb_surfvx_2x2v_ser_p1, canonical_pb_surfvx_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_surfvx_2x3v_ser_p1, canonical_pb_surfvx_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; // Acceleration surface kernel list: vy-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_surf_kern_list ser_accel_surf_vy_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_surf_kern_list ser_accel_surf_vy_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, canonical_pb_surfvy_1x2v_ser_p1, canonical_pb_surfvy_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_surfvy_1x3v_ser_p1, canonical_pb_surfvy_1x3v_ser_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, canonical_pb_surfvy_1x2v_ser_p1, canonical_pb_surfvy_1x2v_ser_p2}, // 1 + {NULL, canonical_pb_surfvy_1x3v_ser_p1, canonical_pb_surfvy_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, canonical_pb_surfvy_2x2v_ser_p1, canonical_pb_surfvy_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_surfvy_2x3v_ser_p1, canonical_pb_surfvy_2x3v_ser_p2 }, // 4 + {NULL, canonical_pb_surfvy_2x2v_ser_p1, canonical_pb_surfvy_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_surfvy_2x3v_ser_p1, canonical_pb_surfvy_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; // Acceleration surface kernel list: vz-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_surf_kern_list ser_accel_surf_vz_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_surf_kern_list ser_accel_surf_vz_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, canonical_pb_surfvz_1x3v_ser_p1, canonical_pb_surfvz_1x3v_ser_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, canonical_pb_surfvz_1x3v_ser_p1, canonical_pb_surfvz_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, canonical_pb_surfvz_2x3v_ser_p1, canonical_pb_surfvz_2x3v_ser_p2 }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, canonical_pb_surfvz_2x3v_ser_p1, canonical_pb_surfvz_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vx-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list ser_accel_boundary_surf_vx_kernels[] = { - // 1x kernels - { NULL, canonical_pb_boundary_surfvx_1x1v_ser_p1, canonical_pb_boundary_surfvx_1x1v_ser_p2 }, // 0 - { NULL, canonical_pb_boundary_surfvx_1x2v_ser_p1, canonical_pb_boundary_surfvx_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_boundary_surfvx_1x3v_ser_p1, canonical_pb_boundary_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_boundary_surfvx_2x2v_ser_p1, canonical_pb_boundary_surfvx_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_boundary_surfvx_2x3v_ser_p1, canonical_pb_boundary_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list + ser_accel_boundary_surf_vx_kernels[] = { + // 1x kernels + {NULL, canonical_pb_boundary_surfvx_1x1v_ser_p1, canonical_pb_boundary_surfvx_1x1v_ser_p2}, // 0 + {NULL, canonical_pb_boundary_surfvx_1x2v_ser_p1, canonical_pb_boundary_surfvx_1x2v_ser_p2}, // 1 + {NULL, canonical_pb_boundary_surfvx_1x3v_ser_p1, canonical_pb_boundary_surfvx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_boundary_surfvx_2x2v_ser_p1, canonical_pb_boundary_surfvx_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_boundary_surfvx_2x3v_ser_p1, canonical_pb_boundary_surfvx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vy-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list ser_accel_boundary_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, canonical_pb_boundary_surfvy_1x2v_ser_p1, canonical_pb_boundary_surfvy_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_boundary_surfvy_1x3v_ser_p1, canonical_pb_boundary_surfvy_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_boundary_surfvy_2x2v_ser_p1, canonical_pb_boundary_surfvy_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_boundary_surfvy_2x3v_ser_p1, canonical_pb_boundary_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list + ser_accel_boundary_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, canonical_pb_boundary_surfvy_1x2v_ser_p1, canonical_pb_boundary_surfvy_1x2v_ser_p2}, // 1 + {NULL, canonical_pb_boundary_surfvy_1x3v_ser_p1, canonical_pb_boundary_surfvy_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_boundary_surfvy_2x2v_ser_p1, canonical_pb_boundary_surfvy_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_boundary_surfvy_2x3v_ser_p1, canonical_pb_boundary_surfvy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vz-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list ser_accel_boundary_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, canonical_pb_boundary_surfvz_1x3v_ser_p1, canonical_pb_boundary_surfvz_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, canonical_pb_boundary_surfvz_2x3v_ser_p1, canonical_pb_boundary_surfvz_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list + ser_accel_boundary_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, canonical_pb_boundary_surfvz_1x3v_ser_p1, canonical_pb_boundary_surfvz_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, canonical_pb_boundary_surfvz_2x3v_ser_p1, canonical_pb_boundary_surfvz_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; - // Stream boundary surface kernel (zero-flux BCs) list: x-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list ser_stream_boundary_surf_x_kernels[] = { - // 1x kernels - { NULL, canonical_pb_boundary_surfx_1x1v_ser_p1, canonical_pb_boundary_surfx_1x1v_ser_p2 }, // 0 - { NULL, canonical_pb_boundary_surfx_1x2v_ser_p1, canonical_pb_boundary_surfx_1x2v_ser_p2 }, // 1 - { NULL, canonical_pb_boundary_surfx_1x3v_ser_p1, canonical_pb_boundary_surfx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_boundary_surfx_2x2v_ser_p1, canonical_pb_boundary_surfx_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_boundary_surfx_2x3v_ser_p1, canonical_pb_boundary_surfx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list + ser_stream_boundary_surf_x_kernels[] = { + // 1x kernels + {NULL, canonical_pb_boundary_surfx_1x1v_ser_p1, canonical_pb_boundary_surfx_1x1v_ser_p2}, // 0 + {NULL, canonical_pb_boundary_surfx_1x2v_ser_p1, canonical_pb_boundary_surfx_1x2v_ser_p2}, // 1 + {NULL, canonical_pb_boundary_surfx_1x3v_ser_p1, canonical_pb_boundary_surfx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, canonical_pb_boundary_surfx_2x2v_ser_p1, canonical_pb_boundary_surfx_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_boundary_surfx_2x3v_ser_p1, canonical_pb_boundary_surfx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Stream boundary surface kernel (zero-flux BCs) list: y-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list ser_stream_boundary_surf_y_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, canonical_pb_boundary_surfy_2x2v_ser_p1, canonical_pb_boundary_surfy_2x2v_ser_p2 }, // 3 - { NULL, canonical_pb_boundary_surfy_2x3v_ser_p1, canonical_pb_boundary_surfy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list + ser_stream_boundary_surf_y_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, canonical_pb_boundary_surfy_2x2v_ser_p1, canonical_pb_boundary_surfy_2x2v_ser_p2}, // 3 + {NULL, canonical_pb_boundary_surfy_2x3v_ser_p1, canonical_pb_boundary_surfy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Stream boundary surface kernel (zero-flux BCs) list: z-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list ser_stream_boundary_surf_z_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list + ser_stream_boundary_surf_z_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; - // // Tensor volume kernels // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x1v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x1v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x1v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x1v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x1v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x1v_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x1v_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x2v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x2v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x2v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x2v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x2v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x2v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x2v_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x2v_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x3v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x3v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x3v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x3v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_1x3v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_1x3v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_1x3v_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_1x3v_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_2x2v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_2x2v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_2x2v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_2x2v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_2x2v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_2x2v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_2x2v_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_2x2v_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } - -GKYL_CU_DH -static double -kernel_canonical_pb_vol_2x3v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_2x3v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_2x3v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_2x3v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_canonical_pb_vol_3x3v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_canonical_pb_vol_3x3v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); long pidx = gkyl_range_idx(&canonical_pb->phase_range, idx); - return canonical_pb_vol_3x3v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), - qIn, qRhsOut); + return canonical_pb_vol_3x3v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidx), qIn, qRhsOut + ); } // Volume kernel list for relativistic streaming + EM -GKYL_CU_D -static const gkyl_dg_canonical_pb_vol_kern_list tensor_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_vol_kern_list tensor_vol_kernels[] = { // 1x kernels - { NULL, kernel_canonical_pb_vol_1x1v_tensor_p1, kernel_canonical_pb_vol_1x1v_tensor_p2 }, // 0 - { NULL, kernel_canonical_pb_vol_1x2v_tensor_p1, kernel_canonical_pb_vol_1x2v_tensor_p2 }, // 1 - { NULL, kernel_canonical_pb_vol_1x3v_tensor_p1, kernel_canonical_pb_vol_1x3v_tensor_p2 }, // 2 + {NULL, kernel_canonical_pb_vol_1x1v_tensor_p1, kernel_canonical_pb_vol_1x1v_tensor_p2}, // 0 + {NULL, kernel_canonical_pb_vol_1x2v_tensor_p1, kernel_canonical_pb_vol_1x2v_tensor_p2}, // 1 + {NULL, kernel_canonical_pb_vol_1x3v_tensor_p1, kernel_canonical_pb_vol_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, kernel_canonical_pb_vol_2x2v_tensor_p1, kernel_canonical_pb_vol_2x2v_tensor_p2 }, // 3 - { NULL, kernel_canonical_pb_vol_2x3v_tensor_p1, NULL }, // 4 + {NULL, kernel_canonical_pb_vol_2x2v_tensor_p1, kernel_canonical_pb_vol_2x2v_tensor_p2}, // 3 + {NULL, kernel_canonical_pb_vol_2x3v_tensor_p1, NULL}, // 4 // 3x kernels - { NULL, kernel_canonical_pb_vol_3x3v_tensor_p1, NULL }, // 2 + {NULL, kernel_canonical_pb_vol_3x3v_tensor_p1, NULL} // 2 }; // @@ -548,176 +550,182 @@ static const gkyl_dg_canonical_pb_vol_kern_list tensor_vol_kernels[] = { // // Streaming surface kernel list: x-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_surf_kern_list tensor_stream_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_surf_kern_list tensor_stream_surf_x_kernels[] = { // 1x kernels - { NULL, canonical_pb_surfx_1x1v_tensor_p1, canonical_pb_surfx_1x1v_tensor_p2 }, // 0 - { NULL, canonical_pb_surfx_1x2v_tensor_p1, canonical_pb_surfx_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_surfx_1x3v_tensor_p1, canonical_pb_surfx_1x3v_tensor_p2 }, // 2 + {NULL, canonical_pb_surfx_1x1v_tensor_p1, canonical_pb_surfx_1x1v_tensor_p2}, // 0 + {NULL, canonical_pb_surfx_1x2v_tensor_p1, canonical_pb_surfx_1x2v_tensor_p2}, // 1 + {NULL, canonical_pb_surfx_1x3v_tensor_p1, canonical_pb_surfx_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, canonical_pb_surfx_2x2v_tensor_p1, canonical_pb_surfx_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_surfx_2x3v_tensor_p1, NULL }, // 4 + {NULL, canonical_pb_surfx_2x2v_tensor_p1, canonical_pb_surfx_2x2v_tensor_p2}, // 3 + {NULL, canonical_pb_surfx_2x3v_tensor_p1, NULL}, // 4 // 3x kernels - { NULL, canonical_pb_surfx_3x3v_tensor_p1, NULL }, // 5 + {NULL, canonical_pb_surfx_3x3v_tensor_p1, NULL} // 5 }; // Streaming surface kernel list: y-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_surf_kern_list tensor_stream_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_surf_kern_list tensor_stream_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 // 2x kernels - { NULL, canonical_pb_surfy_2x2v_tensor_p1, canonical_pb_surfy_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_surfy_2x3v_tensor_p1, NULL }, // 4 + {NULL, canonical_pb_surfy_2x2v_tensor_p1, canonical_pb_surfy_2x2v_tensor_p2}, // 3 + {NULL, canonical_pb_surfy_2x3v_tensor_p1, NULL}, // 4 // 3x kernels - { NULL, canonical_pb_surfy_3x3v_tensor_p1, NULL }, // 2 + {NULL, canonical_pb_surfy_3x3v_tensor_p1, NULL} // 2 }; // Streaming surface kernel list: z-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_surf_kern_list tensor_stream_surf_z_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_surf_kern_list tensor_stream_surf_z_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 // 3x kernels - { NULL, canonical_pb_surfz_3x3v_tensor_p1, NULL }, // 5 + {NULL, canonical_pb_surfz_3x3v_tensor_p1, NULL} // 5 }; // Acceleration surface kernel list: vx-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_surf_kern_list tensor_accel_surf_vx_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_surf_kern_list tensor_accel_surf_vx_kernels[] = { // 1x kernels - { NULL, canonical_pb_surfvx_1x1v_tensor_p1, canonical_pb_surfvx_1x1v_tensor_p2 }, // 0 - { NULL, canonical_pb_surfvx_1x2v_tensor_p1, canonical_pb_surfvx_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_surfvx_1x3v_tensor_p1, canonical_pb_surfvx_1x3v_tensor_p2 }, // 2 + {NULL, canonical_pb_surfvx_1x1v_tensor_p1, canonical_pb_surfvx_1x1v_tensor_p2}, // 0 + {NULL, canonical_pb_surfvx_1x2v_tensor_p1, canonical_pb_surfvx_1x2v_tensor_p2}, // 1 + {NULL, canonical_pb_surfvx_1x3v_tensor_p1, canonical_pb_surfvx_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, canonical_pb_surfvx_2x2v_tensor_p1, canonical_pb_surfvx_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_surfvx_2x3v_tensor_p1, NULL }, // 4 + {NULL, canonical_pb_surfvx_2x2v_tensor_p1, canonical_pb_surfvx_2x2v_tensor_p2}, // 3 + {NULL, canonical_pb_surfvx_2x3v_tensor_p1, NULL}, // 4 // 3x kernels - { NULL, canonical_pb_surfvx_3x3v_tensor_p1, NULL }, // 5 + {NULL, canonical_pb_surfvx_3x3v_tensor_p1, NULL} // 5 }; // Acceleration surface kernel list: vy-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_surf_kern_list tensor_accel_surf_vy_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_surf_kern_list tensor_accel_surf_vy_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, canonical_pb_surfvy_1x2v_tensor_p1, canonical_pb_surfvy_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_surfvy_1x3v_tensor_p1, canonical_pb_surfvy_1x3v_tensor_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, canonical_pb_surfvy_1x2v_tensor_p1, canonical_pb_surfvy_1x2v_tensor_p2}, // 1 + {NULL, canonical_pb_surfvy_1x3v_tensor_p1, canonical_pb_surfvy_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, canonical_pb_surfvy_2x2v_tensor_p1, canonical_pb_surfvy_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_surfvy_2x3v_tensor_p1, NULL }, // 4 + {NULL, canonical_pb_surfvy_2x2v_tensor_p1, canonical_pb_surfvy_2x2v_tensor_p2}, // 3 + {NULL, canonical_pb_surfvy_2x3v_tensor_p1, NULL}, // 4 // 3x kernels - { NULL, canonical_pb_surfvy_3x3v_tensor_p1, NULL }, // 5 + {NULL, canonical_pb_surfvy_3x3v_tensor_p1, NULL} // 5 }; // Acceleration surface kernel list: vz-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_surf_kern_list tensor_accel_surf_vz_kernels[] = { +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_surf_kern_list tensor_accel_surf_vz_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, canonical_pb_surfvz_1x3v_tensor_p1, canonical_pb_surfvz_1x3v_tensor_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, canonical_pb_surfvz_1x3v_tensor_p1, canonical_pb_surfvz_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, canonical_pb_surfvz_2x3v_tensor_p1, NULL }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, canonical_pb_surfvz_2x3v_tensor_p1, NULL}, // 4 // 3x kernels - { NULL, canonical_pb_surfvz_3x3v_tensor_p1, NULL }, // 5 + {NULL, canonical_pb_surfvz_3x3v_tensor_p1, NULL} // 5 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vx-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list tensor_accel_boundary_surf_vx_kernels[] = { - // 1x kernels - { NULL, canonical_pb_boundary_surfvx_1x1v_tensor_p1, canonical_pb_boundary_surfvx_1x1v_tensor_p2 }, // 0 - { NULL, canonical_pb_boundary_surfvx_1x2v_tensor_p1, canonical_pb_boundary_surfvx_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_boundary_surfvx_1x3v_tensor_p1, canonical_pb_boundary_surfvx_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_boundary_surfvx_2x2v_tensor_p1, canonical_pb_boundary_surfvx_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_boundary_surfvx_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_boundary_surfvx_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list + tensor_accel_boundary_surf_vx_kernels[] = { + // 1x kernels + {NULL, canonical_pb_boundary_surfvx_1x1v_tensor_p1, canonical_pb_boundary_surfvx_1x1v_tensor_p2 + }, // 0 + {NULL, canonical_pb_boundary_surfvx_1x2v_tensor_p1, canonical_pb_boundary_surfvx_1x2v_tensor_p2 + }, // 1 + {NULL, canonical_pb_boundary_surfvx_1x3v_tensor_p1, canonical_pb_boundary_surfvx_1x3v_tensor_p2 + }, // 2 + // 2x kernels + {NULL, canonical_pb_boundary_surfvx_2x2v_tensor_p1, canonical_pb_boundary_surfvx_2x2v_tensor_p2 + }, // 3 + {NULL, canonical_pb_boundary_surfvx_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_boundary_surfvx_3x3v_tensor_p1, NULL} // 5 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vy-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list tensor_accel_boundary_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, canonical_pb_boundary_surfvy_1x2v_tensor_p1, canonical_pb_boundary_surfvy_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_boundary_surfvy_1x3v_tensor_p1, canonical_pb_boundary_surfvy_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_boundary_surfvy_2x2v_tensor_p1, canonical_pb_boundary_surfvy_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_boundary_surfvy_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_boundary_surfvy_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list + tensor_accel_boundary_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, canonical_pb_boundary_surfvy_1x2v_tensor_p1, canonical_pb_boundary_surfvy_1x2v_tensor_p2 + }, // 1 + {NULL, canonical_pb_boundary_surfvy_1x3v_tensor_p1, canonical_pb_boundary_surfvy_1x3v_tensor_p2 + }, // 2 + // 2x kernels + {NULL, canonical_pb_boundary_surfvy_2x2v_tensor_p1, canonical_pb_boundary_surfvy_2x2v_tensor_p2 + }, // 3 + {NULL, canonical_pb_boundary_surfvy_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_boundary_surfvy_3x3v_tensor_p1, NULL} // 5 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vz-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list tensor_accel_boundary_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, canonical_pb_boundary_surfvz_1x3v_tensor_p1, canonical_pb_boundary_surfvz_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, canonical_pb_boundary_surfvz_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_boundary_surfvz_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_accel_boundary_surf_kern_list + tensor_accel_boundary_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, canonical_pb_boundary_surfvz_1x3v_tensor_p1, canonical_pb_boundary_surfvz_1x3v_tensor_p2 + }, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, canonical_pb_boundary_surfvz_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_boundary_surfvz_3x3v_tensor_p1, NULL} // 5 }; - // Stream boundary surface kernel (zero-flux BCs) list: x-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list tensor_stream_boundary_surf_x_kernels[] = { - // 1x kernels - { NULL, canonical_pb_boundary_surfx_1x1v_tensor_p1, canonical_pb_boundary_surfx_1x1v_tensor_p2 }, // 0 - { NULL, canonical_pb_boundary_surfx_1x2v_tensor_p1, canonical_pb_boundary_surfx_1x2v_tensor_p2 }, // 1 - { NULL, canonical_pb_boundary_surfx_1x3v_tensor_p1, canonical_pb_boundary_surfx_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, canonical_pb_boundary_surfx_2x2v_tensor_p1, canonical_pb_boundary_surfx_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_boundary_surfx_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_boundary_surfx_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list + tensor_stream_boundary_surf_x_kernels[] = { + // 1x kernels + {NULL, canonical_pb_boundary_surfx_1x1v_tensor_p1, canonical_pb_boundary_surfx_1x1v_tensor_p2 + }, // 0 + {NULL, canonical_pb_boundary_surfx_1x2v_tensor_p1, canonical_pb_boundary_surfx_1x2v_tensor_p2 + }, // 1 + {NULL, canonical_pb_boundary_surfx_1x3v_tensor_p1, canonical_pb_boundary_surfx_1x3v_tensor_p2 + }, // 2 + // 2x kernels + {NULL, canonical_pb_boundary_surfx_2x2v_tensor_p1, canonical_pb_boundary_surfx_2x2v_tensor_p2 + }, // 3 + {NULL, canonical_pb_boundary_surfx_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_boundary_surfx_3x3v_tensor_p1, NULL} // 5 }; // Stream boundary surface kernel (zero-flux BCs) list: y-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list tensor_stream_boundary_surf_y_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, canonical_pb_boundary_surfy_2x2v_tensor_p1, canonical_pb_boundary_surfy_2x2v_tensor_p2 }, // 3 - { NULL, canonical_pb_boundary_surfy_2x3v_tensor_p1, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_boundary_surfy_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list + tensor_stream_boundary_surf_y_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, canonical_pb_boundary_surfy_2x2v_tensor_p1, canonical_pb_boundary_surfy_2x2v_tensor_p2 + }, // 3 + {NULL, canonical_pb_boundary_surfy_2x3v_tensor_p1, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_boundary_surfy_3x3v_tensor_p1, NULL} // 5 }; // Stream boundary surface kernel (zero-flux BCs) list: z-direction -GKYL_CU_D -static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list tensor_stream_boundary_surf_z_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 - // 3x kernels - { NULL, canonical_pb_boundary_surfz_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list + tensor_stream_boundary_surf_z_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 + // 3x kernels + {NULL, canonical_pb_boundary_surfz_3x3v_tensor_p1, NULL} // 5 }; // "Choose Kernel" based on cdim, vdim and polyorder -#define CK(lst,cv_index,poly_order) lst[cv_index].kernels[poly_order] +#define CK(lst, cv_index, poly_order) lst[cv_index].kernels[poly_order] /** * Free vlasov eqn object. @@ -726,15 +734,13 @@ static const gkyl_dg_canonical_pb_stream_boundary_surf_kern_list tensor_stream_b */ void gkyl_canonical_pb_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) -{ +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) +{ // Each cell owns the *lower* edge surface alpha // Since alpha is continuous, fetch alpha_surf in center cell for lower edge // and fetch alpha_surf in right cell for upper edge @@ -742,80 +748,78 @@ surf(const struct gkyl_dg_eqn *eqn, long pidxC = gkyl_range_idx(&canonical_pb->phase_range, idxC); long pidxR = gkyl_range_idx(&canonical_pb->phase_range, idxR); if (dir < canonical_pb->cdim) { - return canonical_pb->stream_surf[dir](xcC, dxC, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidxC), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxC), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxR), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxC), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxR), - (const int*) gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxC), - (const int*) gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxR), - qInL, qInC, qInR, qRhsOut); - } - else { - return canonical_pb->accel_surf[dir-canonical_pb->cdim](xcC, dxC, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidxC), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxC), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxR), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxC), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxR), - (const int*) gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxC), - (const int*) gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxR), - qInL, qInC, qInR, qRhsOut); + return canonical_pb->stream_surf[dir]( + xcC, dxC, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidxC), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxC), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxR), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxC), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxR), + (const int *)gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxC), + (const int *)gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxR), qInL, qInC, + qInR, qRhsOut + ); + } else { + return canonical_pb->accel_surf[dir - canonical_pb->cdim]( + xcC, dxC, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidxC), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxC), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxR), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxC), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxR), + (const int *)gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxC), + (const int *)gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxR), qInL, qInC, + qInR, qRhsOut + ); } return 0.; } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_canonical_pb *canonical_pb = container_of(eqn, struct dg_canonical_pb, eqn); if (dir < canonical_pb->cdim) { // Each cell owns the *lower* edge surface alpha long pidxEdge = gkyl_range_idx(&canonical_pb->phase_range, idxEdge); long pidxSkin = gkyl_range_idx(&canonical_pb->phase_range, idxSkin); - return canonical_pb->stream_boundary_surf[dir](xcSkin, dxSkin, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidxSkin), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxEdge), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxSkin), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxEdge), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxSkin), - (const int*) gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxEdge), - (const int*) gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxSkin), - edge, qInEdge, qInSkin, qRhsOut); + return canonical_pb->stream_boundary_surf[dir]( + xcSkin, dxSkin, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidxSkin), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxEdge), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxSkin), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxEdge), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxSkin), + (const int *)gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxEdge), + (const int *)gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxSkin), edge, + qInEdge, qInSkin, qRhsOut + ); } if (dir >= canonical_pb->cdim) { // Each cell owns the *lower* edge surface alpha long pidxEdge = gkyl_range_idx(&canonical_pb->phase_range, idxEdge); long pidxSkin = gkyl_range_idx(&canonical_pb->phase_range, idxSkin); - return canonical_pb->accel_boundary_surf[dir-canonical_pb->cdim](xcSkin, dxSkin, - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidxSkin), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxEdge), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxSkin), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxEdge), - (const double*) gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxSkin), - (const int*) gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxEdge), - (const int*) gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxSkin), - edge, qInEdge, qInSkin, qRhsOut); + return canonical_pb->accel_boundary_surf[dir - canonical_pb->cdim]( + xcSkin, dxSkin, (const double *)gkyl_array_cfetch(canonical_pb->auxfields.hamil, pidxSkin), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxEdge), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.alpha_surf, pidxSkin), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxEdge), + (const double *)gkyl_array_cfetch(canonical_pb->auxfields.sgn_alpha_surf, pidxSkin), + (const int *)gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxEdge), + (const int *)gkyl_array_cfetch(canonical_pb->auxfields.const_sgn_alpha, pidxSkin), edge, + qInEdge, qInSkin, qRhsOut + ); } return 0.; } -GKYL_CU_D -static double -boundary_diag(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_diag( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { - return boundary_surf(eqn, dir, xcEdge, xcSkin, dxEdge, dxSkin, idxEdge, idxSkin, edge, qInEdge, qInSkin, qRhsOut); + return boundary_surf( + eqn, dir, xcEdge, xcSkin, dxEdge, dxSkin, idxEdge, idxSkin, edge, qInEdge, qInSkin, qRhsOut + ); } - diff --git a/vlasov/zero/gkyl_dg_diffusion_fluid.h b/vlasov/zero/gkyl_dg_diffusion_fluid.h index 107bf2d310..129643b5db 100644 --- a/vlasov/zero/gkyl_dg_diffusion_fluid.h +++ b/vlasov/zero/gkyl_dg_diffusion_fluid.h @@ -7,7 +7,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_diffusion_fluid_auxfields { +struct gkyl_dg_diffusion_fluid_auxfields { const struct gkyl_array *D; }; @@ -23,8 +23,10 @@ struct gkyl_dg_diffusion_fluid_auxfields { * @param use_gpu Whether to run on host or device. * @return Pointer to diffusion equation object */ -struct gkyl_dg_eqn* gkyl_dg_diffusion_fluid_new(const struct gkyl_basis *basis, bool is_diff_const, - int num_equations, const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_diffusion_fluid_new( + const struct gkyl_basis *basis, bool is_diff_const, int num_equations, const bool *diff_in_dir, + int diff_order, const struct gkyl_range *diff_range, bool use_gpu +); /** * Set the auxiliary fields (e.g. diffusion tensor D) needed in updating diffusion equation. @@ -32,7 +34,9 @@ struct gkyl_dg_eqn* gkyl_dg_diffusion_fluid_new(const struct gkyl_basis *basis, * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_dg_diffusion_fluid_set_auxfields(const struct gkyl_dg_eqn* eqn, struct gkyl_dg_diffusion_fluid_auxfields auxin); +void gkyl_dg_diffusion_fluid_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_fluid_auxfields auxin +); #ifdef GKYL_HAVE_CUDA @@ -42,6 +46,8 @@ void gkyl_dg_diffusion_fluid_set_auxfields(const struct gkyl_dg_eqn* eqn, struct * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_dg_diffusion_fluid_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_fluid_auxfields auxin); +void gkyl_dg_diffusion_fluid_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_fluid_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_diffusion_fluid_priv.h b/vlasov/zero/gkyl_dg_diffusion_fluid_priv.h index 5dad9a132b..250269ddda 100644 --- a/vlasov/zero/gkyl_dg_diffusion_fluid_priv.h +++ b/vlasov/zero/gkyl_dg_diffusion_fluid_priv.h @@ -7,33 +7,44 @@ // private header for use in fluid diffusion DG equation object creation // functions -static inline int diffdirs_linidx(const bool *isdirdiff, int cdim) { +static inline int diffdirs_linidx(const bool *isdirdiff, int cdim) +{ // Compute the linear index into the array of volume kernels (one // kernel for each combination of diffusive directions). bool diff_in_dir[GKYL_MAX_CDIM]; - if (isdirdiff) - for (int d=0; dconst_coeff? (const double *) gkyl_array_cfetch(diffusion->auxfields.D, 0) : (const double *) gkyl_array_cfetch(diffusion->auxfields.D, gkyl_range_idx(&diffusion->diff_range, idx)) +#define _cfD(idx) \ + diffusion->const_coeff ? (const double *)gkyl_array_cfetch(diffusion->auxfields.D, 0) : \ + (const double *)gkyl_array_cfetch( \ + diffusion->auxfields.D, gkyl_range_idx(&diffusion->diff_range, idx) \ + ) // for use in kernel tables -typedef struct { vol_termf_t kernels[7]; } gkyl_dg_diffusion_fluid_vol_kern_list_diffdir; -typedef struct { gkyl_dg_diffusion_fluid_vol_kern_list_diffdir list[2]; } gkyl_dg_diffusion_fluid_vol_kern_list_polyOrder; -typedef struct { gkyl_dg_diffusion_fluid_vol_kern_list_polyOrder list[3]; } gkyl_dg_diffusion_fluid_vol_kern_list; +typedef struct { + vol_termf_t kernels[7]; +} gkyl_dg_diffusion_fluid_vol_kern_list_diffdir; +typedef struct { + gkyl_dg_diffusion_fluid_vol_kern_list_diffdir list[2]; +} gkyl_dg_diffusion_fluid_vol_kern_list_polyOrder; +typedef struct { + gkyl_dg_diffusion_fluid_vol_kern_list_polyOrder list[3]; +} gkyl_dg_diffusion_fluid_vol_kern_list; // for use in kernel tables -typedef struct { diffusion_surf_t kernels[2]; } gkyl_dg_diffusion_fluid_surf_kernels_polyOrder; -typedef struct { gkyl_dg_diffusion_fluid_surf_kernels_polyOrder list[3]; } gkyl_dg_diffusion_fluid_surf_kern_list; +typedef struct { + diffusion_surf_t kernels[2]; +} gkyl_dg_diffusion_fluid_surf_kernels_polyOrder; +typedef struct { + gkyl_dg_diffusion_fluid_surf_kernels_polyOrder list[3]; +} gkyl_dg_diffusion_fluid_surf_kern_list; -typedef struct { diffusion_boundary_surf_t kernels[2]; } gkyl_dg_diffusion_fluid_boundary_surf_kernels_polyOrder; -typedef struct { gkyl_dg_diffusion_fluid_boundary_surf_kernels_polyOrder list[3]; } gkyl_dg_diffusion_fluid_boundary_surf_kern_list; +typedef struct { + diffusion_boundary_surf_t kernels[2]; +} gkyl_dg_diffusion_fluid_boundary_surf_kernels_polyOrder; +typedef struct { + gkyl_dg_diffusion_fluid_boundary_surf_kernels_polyOrder list[3]; +} gkyl_dg_diffusion_fluid_boundary_surf_kern_list; // ............... Homogeneous (constant) diffusion coefficient ............... // @@ -66,934 +95,1339 @@ typedef struct { gkyl_dg_diffusion_fluid_boundary_surf_kernels_polyOrder list[3] // Need to be separated like this for GPU build // 1x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_1x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_1x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_1x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_1x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 1x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_1x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_1x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_1x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_1x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_1x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_1x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_1x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_1x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 1x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_1x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_1x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_1x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_1x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 2x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 2x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 2x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // Volume kernel list. -GKYL_CU_D -static const gkyl_dg_diffusion_fluid_vol_kern_list ser_vol_kernels_constcoeff[] = { - // 1x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_fluid_order2_vol_1x_ser_p1_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order2_vol_1x_ser_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {ker_dg_diffusion_fluid_order4_vol_1x_ser_p1_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order4_vol_1x_ser_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order6_vol_1x_ser_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 2x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 3x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxy,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsyz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz}, - {ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxy,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsyz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz},}, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_vol_kern_list + ser_vol_kernels_constcoeff[] = + { + // 1x + { + .list = + {// 2nd order diffusion. + {.list = + {{ker_dg_diffusion_fluid_order2_vol_1x_ser_p1_constcoeff_diffdirsx, NULL, NULL, NULL, + NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order2_vol_1x_ser_p2_constcoeff_diffdirsx, NULL, NULL, NULL, + NULL, NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{ker_dg_diffusion_fluid_order4_vol_1x_ser_p1_constcoeff_diffdirsx, NULL, NULL, NULL, NULL, NULL, NULL}, {ker_dg_diffusion_fluid_order4_vol_1x_ser_p2_constcoeff_diffdirsx, NULL, NULL, NULL, NULL, NULL, NULL}} + }, + // 6th order diffusion. + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {ker_dg_diffusion_fluid_order6_vol_1x_ser_p2_constcoeff_diffdirsx, NULL, NULL, NULL, NULL, NULL, NULL}} + } + } }, - // 4th order diffusion. - {.list={ - {ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxy,ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsz,ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxz,ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsyz,ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz}, - {ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxy,ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsz,ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxz,ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsyz,ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz},}, + // 2x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}, + {ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order4_vol_2x_ser_p1_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}, + {ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order4_vol_2x_ser_p2_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order6_vol_2x_ser_p2_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}} + } }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxy,ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsz,ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxz,ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsyz,ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz},}, - }, - }, - }, + // 3x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxy, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsyz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz}, + {ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz}}}, + // 4th order diffusion. + {.list = + {{ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxy, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsz, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxz, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsyz, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz}, + {ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsz, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_fluid_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsz, + ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_fluid_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz}}} + } + } }; // Surface kernel list: x-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list ser_surfx_kernels_constcoeff[] = { // 2nd order diffusion. - {.list= { - { dg_diffusion_fluid_order2_surfx_1x_ser_p1_constcoeff, dg_diffusion_fluid_order2_surfx_1x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order2_surfx_2x_ser_p1_constcoeff, dg_diffusion_fluid_order2_surfx_2x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order2_surfx_3x_ser_p1_constcoeff, dg_diffusion_fluid_order2_surfx_3x_ser_p2_constcoeff },}, - }, + {.list = + {{dg_diffusion_fluid_order2_surfx_1x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_surfx_1x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order2_surfx_2x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_surfx_2x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order2_surfx_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_surfx_3x_ser_p2_constcoeff}}}, // 4th order diffusion. - {.list= { - { dg_diffusion_fluid_order4_surfx_1x_ser_p1_constcoeff, dg_diffusion_fluid_order4_surfx_1x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order4_surfx_2x_ser_p1_constcoeff, dg_diffusion_fluid_order4_surfx_2x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order4_surfx_3x_ser_p1_constcoeff, dg_diffusion_fluid_order4_surfx_3x_ser_p2_constcoeff },}, - }, + {.list = + {{dg_diffusion_fluid_order4_surfx_1x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_surfx_1x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order4_surfx_2x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_surfx_2x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order4_surfx_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_surfx_3x_ser_p2_constcoeff}}}, // 6th order diffusion. - {.list= { - { NULL, dg_diffusion_fluid_order6_surfx_1x_ser_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_surfx_2x_ser_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_surfx_3x_ser_p2_constcoeff },}, - }, + {.list = + {{NULL, dg_diffusion_fluid_order6_surfx_1x_ser_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_surfx_2x_ser_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_surfx_3x_ser_p2_constcoeff}}} }; // Surface kernel list: y-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list ser_surfy_kernels_constcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { dg_diffusion_fluid_order2_surfy_2x_ser_p1_constcoeff, dg_diffusion_fluid_order2_surfy_2x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order2_surfy_3x_ser_p1_constcoeff, dg_diffusion_fluid_order2_surfy_3x_ser_p2_constcoeff },}, - }, + {.list = + {{NULL, NULL}, + {dg_diffusion_fluid_order2_surfy_2x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_surfy_2x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order2_surfy_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_surfy_3x_ser_p2_constcoeff}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { dg_diffusion_fluid_order4_surfy_2x_ser_p1_constcoeff, dg_diffusion_fluid_order4_surfy_2x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order4_surfy_3x_ser_p1_constcoeff, dg_diffusion_fluid_order4_surfy_3x_ser_p2_constcoeff },}, - }, + {.list = + {{NULL, NULL}, + {dg_diffusion_fluid_order4_surfy_2x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_surfy_2x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order4_surfy_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_surfy_3x_ser_p2_constcoeff}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order6_surfy_2x_ser_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_surfy_3x_ser_p2_constcoeff },}, - }, + {.list = + {{NULL, NULL}, + {NULL, dg_diffusion_fluid_order6_surfy_2x_ser_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_surfy_3x_ser_p2_constcoeff}}} }; // Surface kernel list: z-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list ser_surfz_kernels_constcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_fluid_order2_surfz_3x_ser_p1_constcoeff, dg_diffusion_fluid_order2_surfz_3x_ser_p2_constcoeff },}, - }, + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_fluid_order2_surfz_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_surfz_3x_ser_p2_constcoeff}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_fluid_order4_surfz_3x_ser_p1_constcoeff, dg_diffusion_fluid_order4_surfz_3x_ser_p2_constcoeff },}, - }, + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_fluid_order4_surfz_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_surfz_3x_ser_p2_constcoeff}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order6_surfz_3x_ser_p2_constcoeff },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, dg_diffusion_fluid_order6_surfz_3x_ser_p2_constcoeff}} + } }; // Boundary surface kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list ser_boundary_surfx_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { dg_diffusion_fluid_order2_boundary_surfx_1x_ser_p1_constcoeff, dg_diffusion_fluid_order2_boundary_surfx_1x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order2_boundary_surfx_2x_ser_p1_constcoeff, dg_diffusion_fluid_order2_boundary_surfx_2x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order2_boundary_surfx_3x_ser_p1_constcoeff, dg_diffusion_fluid_order2_boundary_surfx_3x_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { dg_diffusion_fluid_order4_boundary_surfx_1x_ser_p1_constcoeff, dg_diffusion_fluid_order4_boundary_surfx_1x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order4_boundary_surfx_2x_ser_p1_constcoeff, dg_diffusion_fluid_order4_boundary_surfx_2x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order4_boundary_surfx_3x_ser_p1_constcoeff, dg_diffusion_fluid_order4_boundary_surfx_3x_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, dg_diffusion_fluid_order6_boundary_surfx_1x_ser_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_boundary_surfx_2x_ser_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_boundary_surfx_3x_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + ser_boundary_surfx_kernels_constcoeff[] = { + // 2nd order diffusion. + {.list = + {{dg_diffusion_fluid_order2_boundary_surfx_1x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_boundary_surfx_1x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order2_boundary_surfx_2x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_boundary_surfx_2x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order2_boundary_surfx_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_boundary_surfx_3x_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{dg_diffusion_fluid_order4_boundary_surfx_1x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_boundary_surfx_1x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order4_boundary_surfx_2x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_boundary_surfx_2x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order4_boundary_surfx_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_boundary_surfx_3x_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, dg_diffusion_fluid_order6_boundary_surfx_1x_ser_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_boundary_surfx_2x_ser_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_boundary_surfx_3x_ser_p2_constcoeff}}} }; // Boundary surface kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list ser_boundary_surfy_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { dg_diffusion_fluid_order2_boundary_surfy_2x_ser_p1_constcoeff, dg_diffusion_fluid_order2_boundary_surfy_2x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order2_boundary_surfy_3x_ser_p1_constcoeff, dg_diffusion_fluid_order2_boundary_surfy_3x_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { dg_diffusion_fluid_order4_boundary_surfy_2x_ser_p1_constcoeff, dg_diffusion_fluid_order4_boundary_surfy_2x_ser_p2_constcoeff }, - { dg_diffusion_fluid_order4_boundary_surfy_3x_ser_p1_constcoeff, dg_diffusion_fluid_order4_boundary_surfy_3x_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order6_boundary_surfy_2x_ser_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_boundary_surfy_3x_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + ser_boundary_surfy_kernels_constcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {dg_diffusion_fluid_order2_boundary_surfy_2x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_boundary_surfy_2x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order2_boundary_surfy_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_boundary_surfy_3x_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {dg_diffusion_fluid_order4_boundary_surfy_2x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_boundary_surfy_2x_ser_p2_constcoeff}, + {dg_diffusion_fluid_order4_boundary_surfy_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_boundary_surfy_3x_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, dg_diffusion_fluid_order6_boundary_surfy_2x_ser_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_boundary_surfy_3x_ser_p2_constcoeff}}} }; // Boundary surface kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list ser_boundary_surfz_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_fluid_order2_boundary_surfz_3x_ser_p1_constcoeff, dg_diffusion_fluid_order2_boundary_surfz_3x_ser_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_fluid_order4_boundary_surfz_3x_ser_p1_constcoeff, dg_diffusion_fluid_order4_boundary_surfz_3x_ser_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order6_boundary_surfz_3x_ser_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + ser_boundary_surfz_kernels_constcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_fluid_order2_boundary_surfz_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order2_boundary_surfz_3x_ser_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_fluid_order4_boundary_surfz_3x_ser_p1_constcoeff, + dg_diffusion_fluid_order4_boundary_surfz_3x_ser_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_fluid_order6_boundary_surfz_3x_ser_p2_constcoeff}}} }; // Tensor volume kernels // Need to be separated like this for GPU build // 1x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_tensor_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_tensor_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_1x_tensor_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_1x_tensor_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 1x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_1x_tensor_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_1x_tensor_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_1x_tensor_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_1x_tensor_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 1x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_1x_tensor_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_1x_tensor_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_1x_tensor_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_1x_tensor_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 2x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 2x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 2x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // Volume kernel list. -GKYL_CU_D -static const gkyl_dg_diffusion_fluid_vol_kern_list tensor_vol_kernels_constcoeff[] = { - // 1x - {.list={ - // 2nd order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order2_vol_1x_tensor_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order4_vol_1x_tensor_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order6_vol_1x_tensor_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 2x - {.list={ - // 2nd order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 3x - {.list={ - // 2nd order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxy,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsz,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxz,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsyz,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxyz},}, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_vol_kern_list + tensor_vol_kernels_constcoeff[] = + { + // 1x + { + .list = + {// 2nd order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order2_vol_1x_tensor_p2_constcoeff_diffdirsx, NULL, NULL, + NULL, NULL, NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {ker_dg_diffusion_fluid_order4_vol_1x_tensor_p2_constcoeff_diffdirsx, NULL, NULL, NULL, NULL, NULL, NULL}} + }, + // 6th order diffusion. + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {ker_dg_diffusion_fluid_order6_vol_1x_tensor_p2_constcoeff_diffdirsx, NULL, NULL, NULL, NULL, NULL, NULL}} + } + } }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxy,ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsz,ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxz,ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsyz,ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxyz},}, + // 2x + { + .list = + { + // 2nd order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order4_vol_2x_tensor_p2_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order6_vol_2x_tensor_p2_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}} + } }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsx,ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsy,ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxy,ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsz,ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxz,ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsyz,ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxyz},}, - }, - }, - }, + // 3x + { + .list = + { + // 2nd order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsz, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_constcoeff_diffdirsxyz}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsz, + ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_fluid_order4_vol_3x_tensor_p2_constcoeff_diffdirsxyz}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsx, + ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsy, + ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsz, + ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_fluid_order6_vol_3x_tensor_p2_constcoeff_diffdirsxyz}}} + } + } }; // Surface kernel list: x-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list tensor_surfx_kernels_constcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, dg_diffusion_fluid_order2_surfx_1x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order2_surfx_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order2_surfx_3x_tensor_p2_constcoeff },}, - }, + {.list = + {{NULL, dg_diffusion_fluid_order2_surfx_1x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order2_surfx_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order2_surfx_3x_tensor_p2_constcoeff}}}, // 4th order diffusion. - {.list= { - { NULL, dg_diffusion_fluid_order4_surfx_1x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order4_surfx_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order4_surfx_3x_tensor_p2_constcoeff },}, - }, + {.list = + {{NULL, dg_diffusion_fluid_order4_surfx_1x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order4_surfx_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order4_surfx_3x_tensor_p2_constcoeff}}}, // 6th order diffusion. - {.list= { - { NULL, dg_diffusion_fluid_order6_surfx_1x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_surfx_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_surfx_3x_tensor_p2_constcoeff },}, - }, + {.list = + {{NULL, dg_diffusion_fluid_order6_surfx_1x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_surfx_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_surfx_3x_tensor_p2_constcoeff}}} }; // Surface kernel list: y-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list tensor_surfy_kernels_constcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order2_surfy_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order2_surfy_3x_tensor_p2_constcoeff },}, - }, + {.list = + {{NULL, NULL}, + {NULL, dg_diffusion_fluid_order2_surfy_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order2_surfy_3x_tensor_p2_constcoeff}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order4_surfy_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order4_surfy_3x_tensor_p2_constcoeff },}, - }, + {.list = + {{NULL, NULL}, + {NULL, dg_diffusion_fluid_order4_surfy_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order4_surfy_3x_tensor_p2_constcoeff}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order6_surfy_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_surfy_3x_tensor_p2_constcoeff },}, - }, + {.list = + {{NULL, NULL}, + {NULL, dg_diffusion_fluid_order6_surfy_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_surfy_3x_tensor_p2_constcoeff}}} }; // Surface kernel list: z-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list tensor_surfz_kernels_constcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order2_surfz_3x_tensor_p2_constcoeff },}, - }, + {.list = + {{NULL, NULL}, {NULL, NULL}, {NULL, dg_diffusion_fluid_order2_surfz_3x_tensor_p2_constcoeff}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order4_surfz_3x_tensor_p2_constcoeff },}, - }, + {.list = + {{NULL, NULL}, {NULL, NULL}, {NULL, dg_diffusion_fluid_order4_surfz_3x_tensor_p2_constcoeff}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order6_surfz_3x_tensor_p2_constcoeff },}, - }, + {.list = + {{NULL, NULL}, {NULL, NULL}, {NULL, dg_diffusion_fluid_order6_surfz_3x_tensor_p2_constcoeff}}} }; // Boundary surface kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list tensor_boundary_surfx_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, dg_diffusion_fluid_order2_boundary_surfx_1x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order2_boundary_surfx_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order2_boundary_surfx_3x_tensor_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, dg_diffusion_fluid_order4_boundary_surfx_1x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order4_boundary_surfx_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order4_boundary_surfx_3x_tensor_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, dg_diffusion_fluid_order6_boundary_surfx_1x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_boundary_surfx_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_boundary_surfx_3x_tensor_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + tensor_boundary_surfx_kernels_constcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, dg_diffusion_fluid_order2_boundary_surfx_1x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order2_boundary_surfx_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order2_boundary_surfx_3x_tensor_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{NULL, dg_diffusion_fluid_order4_boundary_surfx_1x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order4_boundary_surfx_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order4_boundary_surfx_3x_tensor_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, dg_diffusion_fluid_order6_boundary_surfx_1x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_boundary_surfx_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_boundary_surfx_3x_tensor_p2_constcoeff}}} }; // Boundary surface kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list tensor_boundary_surfy_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order2_boundary_surfy_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order2_boundary_surfy_3x_tensor_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order4_boundary_surfy_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order4_boundary_surfy_3x_tensor_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order6_boundary_surfy_2x_tensor_p2_constcoeff }, - { NULL, dg_diffusion_fluid_order6_boundary_surfy_3x_tensor_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + tensor_boundary_surfy_kernels_constcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, dg_diffusion_fluid_order2_boundary_surfy_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order2_boundary_surfy_3x_tensor_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, dg_diffusion_fluid_order4_boundary_surfy_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order4_boundary_surfy_3x_tensor_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, dg_diffusion_fluid_order6_boundary_surfy_2x_tensor_p2_constcoeff}, + {NULL, dg_diffusion_fluid_order6_boundary_surfy_3x_tensor_p2_constcoeff}}} }; // Boundary surface kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list tensor_boundary_surfz_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order2_boundary_surfz_3x_tensor_p2_constcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order4_boundary_surfz_3x_tensor_p2_constcoeff },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order6_boundary_surfz_3x_tensor_p2_constcoeff },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + tensor_boundary_surfz_kernels_constcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_fluid_order2_boundary_surfz_3x_tensor_p2_constcoeff}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_fluid_order4_boundary_surfz_3x_tensor_p2_constcoeff}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_fluid_order6_boundary_surfz_3x_tensor_p2_constcoeff}}} }; // ............... Inhomogeneous (spatially varying) diffusion coefficient ............... // @@ -1002,630 +1436,673 @@ GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list tensor_bo // Need to be separated like this for GPU build // 1x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_ser_p1_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_ser_p1_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_1x_ser_p1_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_ser_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_ser_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_1x_ser_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); } // 2x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); return dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // Volume kernel list. -GKYL_CU_D -static const gkyl_dg_diffusion_fluid_vol_kern_list ser_vol_kernels_varcoeff[] = { - // 1x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_fluid_order2_vol_1x_ser_p1_varcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order2_vol_1x_ser_p2_varcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 2x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsxy,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 3x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxy,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsyz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz}, - {ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxy,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsyz,ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz},}, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_vol_kern_list + ser_vol_kernels_varcoeff[] = + { + // 1x + { + .list = + {// 2nd order diffusion. + {.list = + {{ker_dg_diffusion_fluid_order2_vol_1x_ser_p1_varcoeff_diffdirsx, NULL, NULL, NULL, + NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order2_vol_1x_ser_p2_varcoeff_diffdirsx, NULL, NULL, NULL, + NULL, NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL, NULL}} + }, + // 6th order diffusion. + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL, NULL}} + } + } }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, + // 2x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_2x_ser_p1_varcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}, + {ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_2x_ser_p2_varcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}} + } }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, + // 3x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxy, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsyz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz}, + {ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxy, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsyz, + ker_dg_diffusion_fluid_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}} + } + } }; // Surface kernel list: x-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list ser_surfx_kernels_varcoeff[] = { // 2nd order diffusion. - {.list= { - { dg_diffusion_fluid_order2_surfx_1x_ser_p1_varcoeff, dg_diffusion_fluid_order2_surfx_1x_ser_p2_varcoeff }, - { dg_diffusion_fluid_order2_surfx_2x_ser_p1_varcoeff, dg_diffusion_fluid_order2_surfx_2x_ser_p2_varcoeff }, - { dg_diffusion_fluid_order2_surfx_3x_ser_p1_varcoeff, dg_diffusion_fluid_order2_surfx_3x_ser_p2_varcoeff },}, - }, + {.list = + {{dg_diffusion_fluid_order2_surfx_1x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_surfx_1x_ser_p2_varcoeff}, + {dg_diffusion_fluid_order2_surfx_2x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_surfx_2x_ser_p2_varcoeff}, + {dg_diffusion_fluid_order2_surfx_3x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_surfx_3x_ser_p2_varcoeff}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Surface kernel list: y-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list ser_surfy_kernels_varcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { dg_diffusion_fluid_order2_surfy_2x_ser_p1_varcoeff, dg_diffusion_fluid_order2_surfy_2x_ser_p2_varcoeff }, - { dg_diffusion_fluid_order2_surfy_3x_ser_p1_varcoeff, dg_diffusion_fluid_order2_surfy_3x_ser_p2_varcoeff },}, - }, + {.list = + {{NULL, NULL}, + {dg_diffusion_fluid_order2_surfy_2x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_surfy_2x_ser_p2_varcoeff}, + {dg_diffusion_fluid_order2_surfy_3x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_surfy_3x_ser_p2_varcoeff}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Surface kernel list: z-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list ser_surfz_kernels_varcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_fluid_order2_surfz_3x_ser_p1_varcoeff, dg_diffusion_fluid_order2_surfz_3x_ser_p2_varcoeff },}, - }, + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_fluid_order2_surfz_3x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_surfz_3x_ser_p2_varcoeff}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list ser_boundary_surfx_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { dg_diffusion_fluid_order2_boundary_surfx_1x_ser_p1_varcoeff, dg_diffusion_fluid_order2_boundary_surfx_1x_ser_p2_varcoeff }, - { dg_diffusion_fluid_order2_boundary_surfx_2x_ser_p1_varcoeff, dg_diffusion_fluid_order2_boundary_surfx_2x_ser_p2_varcoeff }, - { dg_diffusion_fluid_order2_boundary_surfx_3x_ser_p1_varcoeff, dg_diffusion_fluid_order2_boundary_surfx_3x_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + ser_boundary_surfx_kernels_varcoeff[] = { + // 2nd order diffusion. + {.list = + {{dg_diffusion_fluid_order2_boundary_surfx_1x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_boundary_surfx_1x_ser_p2_varcoeff}, + {dg_diffusion_fluid_order2_boundary_surfx_2x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_boundary_surfx_2x_ser_p2_varcoeff}, + {dg_diffusion_fluid_order2_boundary_surfx_3x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_boundary_surfx_3x_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list ser_boundary_surfy_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { dg_diffusion_fluid_order2_boundary_surfy_2x_ser_p1_varcoeff, dg_diffusion_fluid_order2_boundary_surfy_2x_ser_p2_varcoeff }, - { dg_diffusion_fluid_order2_boundary_surfy_3x_ser_p1_varcoeff, dg_diffusion_fluid_order2_boundary_surfy_3x_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + ser_boundary_surfy_kernels_varcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {dg_diffusion_fluid_order2_boundary_surfy_2x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_boundary_surfy_2x_ser_p2_varcoeff}, + {dg_diffusion_fluid_order2_boundary_surfy_3x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_boundary_surfy_3x_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list ser_boundary_surfz_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_fluid_order2_boundary_surfz_3x_ser_p1_varcoeff, dg_diffusion_fluid_order2_boundary_surfz_3x_ser_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + ser_boundary_surfz_kernels_varcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_fluid_order2_boundary_surfz_3x_ser_p1_varcoeff, + dg_diffusion_fluid_order2_boundary_surfz_3x_ser_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Tensor volume kernels // Need to be separated like this for GPU build // 1x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_tensor_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_1x_tensor_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_1x_tensor_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_1x_tensor_p2_varcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 2x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + return dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // Volume kernel list. -GKYL_CU_D -static const gkyl_dg_diffusion_fluid_vol_kern_list tensor_vol_kernels_varcoeff[] = { - // 1x - {.list={ - // 2nd order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order2_vol_1x_tensor_p2_varcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 2x - {.list={ - // 2nd order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_vol_kern_list + tensor_vol_kernels_varcoeff[] = + { + // 1x + { + .list = + {// 2nd order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order2_vol_1x_tensor_p2_varcoeff_diffdirsx, NULL, NULL, NULL, + NULL, NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL, NULL}} + }, + // 6th order diffusion. + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL, NULL}} + } + } }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, + // 2x + { + .list = + { + // 2nd order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_2x_tensor_p2_varcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}} + } }, - }, - }, - // 3x - {.list={ - // 2nd order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsx,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsy,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxy,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsz,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxz,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsyz,ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxyz},}, - }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, + // 3x + { + .list = + { + // 2nd order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsx, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsy, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxy, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsz, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxz, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsyz, + ker_dg_diffusion_fluid_order2_vol_3x_tensor_p2_varcoeff_diffdirsxyz}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}} + } + } }; // Surface kernel list: x-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list tensor_surfx_kernels_varcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, dg_diffusion_fluid_order2_surfx_1x_tensor_p2_varcoeff }, - { NULL, dg_diffusion_fluid_order2_surfx_2x_tensor_p2_varcoeff }, - { NULL, dg_diffusion_fluid_order2_surfx_3x_tensor_p2_varcoeff },}, - }, + {.list = + {{NULL, dg_diffusion_fluid_order2_surfx_1x_tensor_p2_varcoeff}, + {NULL, dg_diffusion_fluid_order2_surfx_2x_tensor_p2_varcoeff}, + {NULL, dg_diffusion_fluid_order2_surfx_3x_tensor_p2_varcoeff}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Surface kernel list: y-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list tensor_surfy_kernels_varcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order2_surfy_2x_tensor_p2_varcoeff }, - { NULL, dg_diffusion_fluid_order2_surfy_3x_tensor_p2_varcoeff },}, - }, + {.list = + {{NULL, NULL}, + {NULL, dg_diffusion_fluid_order2_surfy_2x_tensor_p2_varcoeff}, + {NULL, dg_diffusion_fluid_order2_surfy_3x_tensor_p2_varcoeff}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Surface kernel list: z-direction GKYL_CU_D static const gkyl_dg_diffusion_fluid_surf_kern_list tensor_surfz_kernels_varcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order2_surfz_3x_tensor_p2_varcoeff },}, - }, + {.list = + {{NULL, NULL}, {NULL, NULL}, {NULL, dg_diffusion_fluid_order2_surfz_3x_tensor_p2_varcoeff}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list tensor_boundary_surfx_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, dg_diffusion_fluid_order2_boundary_surfx_1x_tensor_p2_varcoeff }, - { NULL, dg_diffusion_fluid_order2_boundary_surfx_2x_tensor_p2_varcoeff }, - { NULL, dg_diffusion_fluid_order2_boundary_surfx_3x_tensor_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + tensor_boundary_surfx_kernels_varcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, dg_diffusion_fluid_order2_boundary_surfx_1x_tensor_p2_varcoeff}, + {NULL, dg_diffusion_fluid_order2_boundary_surfx_2x_tensor_p2_varcoeff}, + {NULL, dg_diffusion_fluid_order2_boundary_surfx_3x_tensor_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list tensor_boundary_surfy_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order2_boundary_surfy_2x_tensor_p2_varcoeff }, - { NULL, dg_diffusion_fluid_order2_boundary_surfy_3x_tensor_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + tensor_boundary_surfy_kernels_varcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, dg_diffusion_fluid_order2_boundary_surfy_2x_tensor_p2_varcoeff}, + {NULL, dg_diffusion_fluid_order2_boundary_surfy_3x_tensor_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list tensor_boundary_surfz_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_fluid_order2_boundary_surfz_3x_tensor_p2_varcoeff },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_fluid_boundary_surf_kern_list + tensor_boundary_surfz_kernels_varcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_fluid_order2_boundary_surfz_3x_tensor_p2_varcoeff}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Macro for choosing volume and surface kernels. -#define CKVOL(lst,cdim,diff_order,poly_order,diffdir_linidx) lst[cdim-1].list[diff_order/2-1].list[poly_order-1].kernels[diffdir_linidx] -#define CKSURF(lst,diff_order,cdim,poly_order) lst[diff_order/2-1].list[cdim-1].kernels[poly_order-1] +#define CKVOL(lst, cdim, diff_order, poly_order, diffdir_linidx) \ + lst[cdim - 1].list[diff_order / 2 - 1].list[poly_order - 1].kernels[diffdir_linidx] +#define CKSURF(lst, diff_order, cdim, poly_order) \ + lst[diff_order / 2 - 1].list[cdim - 1].kernels[poly_order - 1] + +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); -GKYL_CU_D static double surf(const struct gkyl_dg_eqn* eqn, int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, - double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - if (diffusion->diff_in_dir[dir]) { - for (int c=0; cnum_equations; c++) { - int off = c*diffusion->num_basis; - diffusion->surf[dir](xcC, dxC, _cfD(idxC), qInL+off, qInC+off, qInR+off, qRhsOut+off); + for (int c = 0; c < diffusion->num_equations; c++) { + int off = c * diffusion->num_basis; + diffusion->surf[dir](xcC, dxC, _cfD(idxC), qInL + off, qInC + off, qInR + off, qRhsOut + off); } } - return 0.; // CFL frequency computed in volume term. + return 0.; // CFL frequency computed in volume term. } -GKYL_CU_D static double boundary_surf(const struct gkyl_dg_eqn* eqn, int dir, - const double* xcEdge, const double* xcSkin, const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_fluid* diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); - +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_fluid *diffusion = container_of(eqn, struct dg_diffusion_fluid, eqn); + if (diffusion->diff_in_dir[dir]) { - for (int c=0; cnum_equations; c++) { - int off = c*diffusion->num_basis; - diffusion->boundary_surf[dir](xcSkin, dxSkin, _cfD(idxSkin), edge, qInSkin+off, qInEdge+off, qRhsOut+off); + for (int c = 0; c < diffusion->num_equations; c++) { + int off = c * diffusion->num_basis; + diffusion->boundary_surf[dir]( + xcSkin, dxSkin, _cfD(idxSkin), edge, qInSkin + off, qInEdge + off, qRhsOut + off + ); } } - return 0.; // CFL frequency computed in volume term. + return 0.; // CFL frequency computed in volume term. } #undef _cfD @@ -1635,7 +2112,7 @@ GKYL_CU_D static double boundary_surf(const struct gkyl_dg_eqn* eqn, int dir, * * @param ref Reference counter for constant diffusion equation */ -void gkyl_dg_diffusion_fluid_free(const struct gkyl_ref_count* ref); +void gkyl_dg_diffusion_fluid_free(const struct gkyl_ref_count *ref); #ifdef GKYL_HAVE_CUDA /** @@ -1649,7 +2126,8 @@ void gkyl_dg_diffusion_fluid_free(const struct gkyl_ref_count* ref); * @param diff_range Range object to index the diffusion coefficient. * @return Pointer to diffusion equation object */ -struct gkyl_dg_eqn* -gkyl_dg_diffusion_fluid_cu_dev_new(const struct gkyl_basis *basis, bool is_diff_const, - int num_equations, const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range); +struct gkyl_dg_eqn *gkyl_dg_diffusion_fluid_cu_dev_new( + const struct gkyl_basis *basis, bool is_diff_const, int num_equations, const bool *diff_in_dir, + int diff_order, const struct gkyl_range *diff_range +); #endif diff --git a/vlasov/zero/gkyl_dg_diffusion_gen.h b/vlasov/zero/gkyl_dg_diffusion_gen.h index 99ed9982d2..42c09ea7e9 100644 --- a/vlasov/zero/gkyl_dg_diffusion_gen.h +++ b/vlasov/zero/gkyl_dg_diffusion_gen.h @@ -8,8 +8,8 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_diffusion_gen_auxfields { - const struct gkyl_array* Dij; +struct gkyl_dg_diffusion_gen_auxfields { + const struct gkyl_array *Dij; }; /** @@ -20,7 +20,9 @@ struct gkyl_dg_diffusion_gen_auxfields { * @param range Range for use in indexing (generic) diffusion tensor * @return Pointer to generic diffusion equation object */ -struct gkyl_dg_eqn* gkyl_dg_diffusion_gen_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_diffusion_gen_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, bool use_gpu +); /** * Create a new generic diffusion equation object that lives on NV-GPU (one which may have non-zero off-diagonal tensor elements). @@ -30,7 +32,9 @@ struct gkyl_dg_eqn* gkyl_dg_diffusion_gen_new(const struct gkyl_basis* cbasis, c * @param conf_range Configuration space range for use in indexing (generic) diffusion tensor * @return Pointer to generic diffusion equation object */ -struct gkyl_dg_eqn* gkyl_dg_diffusion_gen_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range); +struct gkyl_dg_eqn *gkyl_dg_diffusion_gen_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range +); /** * Set the auxiliary fields (e.g. diffusion tensor D) needed in updating generic diffusion equation. @@ -38,7 +42,9 @@ struct gkyl_dg_eqn* gkyl_dg_diffusion_gen_cu_dev_new(const struct gkyl_basis* cb * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_diffusion_gen_set_auxfields(const struct gkyl_dg_eqn* eqn, struct gkyl_dg_diffusion_gen_auxfields auxin); +void gkyl_diffusion_gen_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_gen_auxfields auxin +); #ifdef GKYL_HAVE_CUDA @@ -48,6 +54,8 @@ void gkyl_diffusion_gen_set_auxfields(const struct gkyl_dg_eqn* eqn, struct gkyl * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_diffusion_gen_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_gen_auxfields auxin); +void gkyl_diffusion_gen_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_gen_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_diffusion_gen_priv.h b/vlasov/zero/gkyl_dg_diffusion_gen_priv.h index 81ac79d11d..ebeae15119 100644 --- a/vlasov/zero/gkyl_dg_diffusion_gen_priv.h +++ b/vlasov/zero/gkyl_dg_diffusion_gen_priv.h @@ -8,13 +8,17 @@ // functions // Types for various kernels -typedef double (*diffusion_gen_surf_t)(const double *w, const double *dx, - const double* D, const double *q[27], - double* GKYL_RESTRICT out); +typedef double (*diffusion_gen_surf_t)( + const double *w, const double *dx, const double *D, const double *q[27], double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_diffusion_gen_vol_kern_list; -typedef struct { diffusion_gen_surf_t kernels[3]; } gkyl_dg_diffusion_gen_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_diffusion_gen_vol_kern_list; +typedef struct { + diffusion_gen_surf_t kernels[3]; +} gkyl_dg_diffusion_gen_surf_kern_list; struct dg_diffusion_gen { struct gkyl_dg_eqn eqn; @@ -28,140 +32,130 @@ struct dg_diffusion_gen { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_dg_diffusion_gen_vol_2x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_diffusion_gen_vol_2x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_gen* diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); - + struct dg_diffusion_gen *diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); + long cidx = gkyl_range_idx(&diffusion_gen->conf_range, idx); - - return dg_diffusion_gen_vol_2x_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(diffusion_gen->auxfields.Dij, cidx), - qIn, qRhsOut); + + return dg_diffusion_gen_vol_2x_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(diffusion_gen->auxfields.Dij, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_dg_diffusion_gen_vol_2x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_diffusion_gen_vol_2x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_gen* diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); - + struct dg_diffusion_gen *diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); + long cidx = gkyl_range_idx(&diffusion_gen->conf_range, idx); - - return dg_diffusion_gen_vol_2x_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(diffusion_gen->auxfields.Dij, cidx), - qIn, qRhsOut); + + return dg_diffusion_gen_vol_2x_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(diffusion_gen->auxfields.Dij, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_dg_diffusion_gen_vol_3x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_diffusion_gen_vol_3x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_gen* diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); - + struct dg_diffusion_gen *diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); + long cidx = gkyl_range_idx(&diffusion_gen->conf_range, idx); - - return dg_diffusion_gen_vol_3x_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(diffusion_gen->auxfields.Dij, cidx), - qIn, qRhsOut); + + return dg_diffusion_gen_vol_3x_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(diffusion_gen->auxfields.Dij, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_dg_diffusion_gen_vol_3x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_dg_diffusion_gen_vol_3x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_gen* diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); - + struct dg_diffusion_gen *diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); + long cidx = gkyl_range_idx(&diffusion_gen->conf_range, idx); - - return dg_diffusion_gen_vol_3x_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(diffusion_gen->auxfields.Dij, cidx), - qIn, qRhsOut); + + return dg_diffusion_gen_vol_3x_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(diffusion_gen->auxfields.Dij, cidx), qIn, qRhsOut + ); } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_diffusion_gen_vol_kern_list ser_vol_kernels[] = { - { NULL, NULL, NULL }, // general diffusion is not implemented for 1D, use diffusion instead - { NULL, kernel_dg_diffusion_gen_vol_2x_ser_p1, kernel_dg_diffusion_gen_vol_2x_ser_p2 }, - { NULL, kernel_dg_diffusion_gen_vol_3x_ser_p1, kernel_dg_diffusion_gen_vol_3x_ser_p2 }, +GKYL_CU_D static const gkyl_dg_diffusion_gen_vol_kern_list ser_vol_kernels[] = { + {NULL, NULL, NULL}, // general diffusion is not implemented for 1D, use diffusion instead + {NULL, kernel_dg_diffusion_gen_vol_2x_ser_p1, kernel_dg_diffusion_gen_vol_2x_ser_p2}, + {NULL, kernel_dg_diffusion_gen_vol_3x_ser_p1, kernel_dg_diffusion_gen_vol_3x_ser_p2} }; // Surface kernel list: xx-direction -GKYL_CU_D -static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_xx_kernels[] = { - { NULL, NULL, NULL }, // general diffusion is not implemented for 1D, use diffusion instead - { NULL, dg_diffusion_gen_surfxx_2x_ser_p1, dg_diffusion_gen_surfxx_2x_ser_p2 }, - { NULL, dg_diffusion_gen_surfxx_3x_ser_p1, dg_diffusion_gen_surfxx_3x_ser_p2 }, +GKYL_CU_D static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_xx_kernels[] = { + {NULL, NULL, NULL}, // general diffusion is not implemented for 1D, use diffusion instead + {NULL, dg_diffusion_gen_surfxx_2x_ser_p1, dg_diffusion_gen_surfxx_2x_ser_p2}, + {NULL, dg_diffusion_gen_surfxx_3x_ser_p1, dg_diffusion_gen_surfxx_3x_ser_p2} }; // Surface kernel list: xy-direction -GKYL_CU_D -static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_xy_kernels[] = { - { NULL, NULL, NULL },// general diffusion is not implemented for 1D, use diffusion instead - { NULL, dg_diffusion_gen_surfxy_2x_ser_p1, dg_diffusion_gen_surfxy_2x_ser_p2 }, - { NULL, dg_diffusion_gen_surfxy_3x_ser_p1, dg_diffusion_gen_surfxy_3x_ser_p2 }, +GKYL_CU_D static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_xy_kernels[] = { + {NULL, NULL, NULL}, // general diffusion is not implemented for 1D, use diffusion instead + {NULL, dg_diffusion_gen_surfxy_2x_ser_p1, dg_diffusion_gen_surfxy_2x_ser_p2}, + {NULL, dg_diffusion_gen_surfxy_3x_ser_p1, dg_diffusion_gen_surfxy_3x_ser_p2} }; // Surface kernel list: xz-direction -GKYL_CU_D -static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_xz_kernels[] = { - { NULL, NULL, NULL }, // general diffusion is not implemented for 1D, use diffusion instead - { NULL, NULL, NULL }, // no z-direction in 2D - { NULL, dg_diffusion_gen_surfxz_3x_ser_p1, dg_diffusion_gen_surfxz_3x_ser_p2 }, +GKYL_CU_D static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_xz_kernels[] = { + {NULL, NULL, NULL}, // general diffusion is not implemented for 1D, use diffusion instead + {NULL, NULL, NULL}, // no z-direction in 2D + {NULL, dg_diffusion_gen_surfxz_3x_ser_p1, dg_diffusion_gen_surfxz_3x_ser_p2} }; // Surface kernel list: yx-direction -GKYL_CU_D -static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_yx_kernels[] = { - { NULL, NULL, NULL }, // general diffusion is not implemented for 1D, use diffusion instead - { NULL, dg_diffusion_gen_surfyx_2x_ser_p1, dg_diffusion_gen_surfyx_2x_ser_p2 }, - { NULL, dg_diffusion_gen_surfyx_3x_ser_p1, dg_diffusion_gen_surfyx_3x_ser_p2 }, +GKYL_CU_D static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_yx_kernels[] = { + {NULL, NULL, NULL}, // general diffusion is not implemented for 1D, use diffusion instead + {NULL, dg_diffusion_gen_surfyx_2x_ser_p1, dg_diffusion_gen_surfyx_2x_ser_p2}, + {NULL, dg_diffusion_gen_surfyx_3x_ser_p1, dg_diffusion_gen_surfyx_3x_ser_p2} }; // Surface kernel list: yy-direction -GKYL_CU_D -static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_yy_kernels[] = { - { NULL, NULL, NULL }, // general diffusion is not implemented for 1D, use diffusion instead - { NULL, dg_diffusion_gen_surfyy_2x_ser_p1, dg_diffusion_gen_surfyy_2x_ser_p2 }, - { NULL, dg_diffusion_gen_surfyy_3x_ser_p1, dg_diffusion_gen_surfyy_3x_ser_p2 }, +GKYL_CU_D static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_yy_kernels[] = { + {NULL, NULL, NULL}, // general diffusion is not implemented for 1D, use diffusion instead + {NULL, dg_diffusion_gen_surfyy_2x_ser_p1, dg_diffusion_gen_surfyy_2x_ser_p2}, + {NULL, dg_diffusion_gen_surfyy_3x_ser_p1, dg_diffusion_gen_surfyy_3x_ser_p2} }; // Surface kernel list: yz-direction -GKYL_CU_D -static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_yz_kernels[] = { - { NULL, NULL, NULL }, // general diffusion is not implemented for 1D, use diffusion instead - { NULL, NULL, NULL }, // no z-direction in 2D - { NULL, dg_diffusion_gen_surfyz_3x_ser_p1, dg_diffusion_gen_surfyz_3x_ser_p2 }, +GKYL_CU_D static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_yz_kernels[] = { + {NULL, NULL, NULL}, // general diffusion is not implemented for 1D, use diffusion instead + {NULL, NULL, NULL}, // no z-direction in 2D + {NULL, dg_diffusion_gen_surfyz_3x_ser_p1, dg_diffusion_gen_surfyz_3x_ser_p2} }; // Surface kernel list: zx-direction -GKYL_CU_D -static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_zx_kernels[] = { - { NULL, NULL, NULL }, // general diffusion is not implemented for 1D, use diffusion instead - { NULL, NULL, NULL }, // no z-direction in 2D - { NULL, dg_diffusion_gen_surfzx_3x_ser_p1, dg_diffusion_gen_surfzx_3x_ser_p2 }, +GKYL_CU_D static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_zx_kernels[] = { + {NULL, NULL, NULL}, // general diffusion is not implemented for 1D, use diffusion instead + {NULL, NULL, NULL}, // no z-direction in 2D + {NULL, dg_diffusion_gen_surfzx_3x_ser_p1, dg_diffusion_gen_surfzx_3x_ser_p2} }; // Surface kernel list: zy-direction -GKYL_CU_D -static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_zy_kernels[] = { - { NULL, NULL, NULL }, // general diffusion is not implemented for 1D, use diffusion instead - { NULL, NULL, NULL }, // no z-direction in 2D - { NULL, dg_diffusion_gen_surfzy_3x_ser_p1, dg_diffusion_gen_surfzy_3x_ser_p2 }, +GKYL_CU_D static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_zy_kernels[] = { + {NULL, NULL, NULL}, // general diffusion is not implemented for 1D, use diffusion instead + {NULL, NULL, NULL}, // no z-direction in 2D + {NULL, dg_diffusion_gen_surfzy_3x_ser_p1, dg_diffusion_gen_surfzy_3x_ser_p2} }; // Surface kernel list: zz-direction -GKYL_CU_D -static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_zz_kernels[] = { - { NULL, NULL, NULL }, // general diffusion is not implemented for 1D, use diffusion instead - { NULL, NULL, NULL }, // no z-direction in 2D - { NULL, dg_diffusion_gen_surfzz_3x_ser_p1, dg_diffusion_gen_surfzz_3x_ser_p2 }, +GKYL_CU_D static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_zz_kernels[] = { + {NULL, NULL, NULL}, // general diffusion is not implemented for 1D, use diffusion instead + {NULL, NULL, NULL}, // no z-direction in 2D + {NULL, dg_diffusion_gen_surfzz_3x_ser_p1, dg_diffusion_gen_surfzz_3x_ser_p2} }; /** @@ -169,19 +163,18 @@ static const gkyl_dg_diffusion_gen_surf_kern_list ser_surf_zz_kernels[] = { * * @param ref Reference counter for constant diffusion_gen equation */ -void gkyl_diffusion_gen_free(const struct gkyl_ref_count* ref); - -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn* eqn, int dir1, int dir2, - const double* xc, const double* dxc, const int* idxc, - long sz_dim, const int idx[27][GKYL_MAX_DIM], const double* qIn[27], - double* GKYL_RESTRICT qRhsOut) +void gkyl_diffusion_gen_free(const struct gkyl_ref_count *ref); + +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir1, int dir2, const double *xc, const double *dxc, + const int *idxc, long sz_dim, const int idx[27][GKYL_MAX_DIM], const double *qIn[27], + double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_gen* diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); + struct dg_diffusion_gen *diffusion_gen = container_of(eqn, struct dg_diffusion_gen, eqn); long cidx = gkyl_range_idx(&diffusion_gen->conf_range, idxc); - - return diffusion_gen->surf[dir1][dir2](xc, dxc, - (const double*) gkyl_array_cfetch(diffusion_gen->auxfields.Dij, cidx), - qIn, qRhsOut); + + return diffusion_gen->surf[dir1][dir2]( + xc, dxc, (const double *)gkyl_array_cfetch(diffusion_gen->auxfields.Dij, cidx), qIn, qRhsOut + ); } diff --git a/vlasov/zero/gkyl_dg_diffusion_vlasov.h b/vlasov/zero/gkyl_dg_diffusion_vlasov.h index b5f301505f..67d13c398a 100644 --- a/vlasov/zero/gkyl_dg_diffusion_vlasov.h +++ b/vlasov/zero/gkyl_dg_diffusion_vlasov.h @@ -7,7 +7,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_diffusion_vlasov_auxfields { +struct gkyl_dg_diffusion_vlasov_auxfields { const struct gkyl_array *D; }; @@ -23,9 +23,10 @@ struct gkyl_dg_diffusion_vlasov_auxfields { * @param use_gpu Whether to run on host or device. * @return Pointer to diffusion equation object */ -struct gkyl_dg_eqn* gkyl_dg_diffusion_vlasov_new(const struct gkyl_basis *basis, - const struct gkyl_basis *cbasis, bool is_diff_const, const bool *diff_in_dir, - int diff_order, const struct gkyl_range *diff_range, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_diffusion_vlasov_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, + const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range, bool use_gpu +); /** * Set the auxiliary fields (e.g. diffusion tensor D) needed in updating diffusion equation. @@ -33,7 +34,9 @@ struct gkyl_dg_eqn* gkyl_dg_diffusion_vlasov_new(const struct gkyl_basis *basis, * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_dg_diffusion_vlasov_set_auxfields(const struct gkyl_dg_eqn* eqn, struct gkyl_dg_diffusion_vlasov_auxfields auxin); +void gkyl_dg_diffusion_vlasov_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_vlasov_auxfields auxin +); #ifdef GKYL_HAVE_CUDA @@ -43,6 +46,8 @@ void gkyl_dg_diffusion_vlasov_set_auxfields(const struct gkyl_dg_eqn* eqn, struc * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_dg_diffusion_vlasov_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_vlasov_auxfields auxin); +void gkyl_dg_diffusion_vlasov_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_diffusion_vlasov_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_diffusion_vlasov_priv.h b/vlasov/zero/gkyl_dg_diffusion_vlasov_priv.h index f80b41692b..eea4b13e33 100644 --- a/vlasov/zero/gkyl_dg_diffusion_vlasov_priv.h +++ b/vlasov/zero/gkyl_dg_diffusion_vlasov_priv.h @@ -7,33 +7,44 @@ // private header for use in diffusion DG equation object creation // functions -static inline int diffdirs_linidx(const bool *isdirdiff, int cdim) { +static inline int diffdirs_linidx(const bool *isdirdiff, int cdim) +{ // Compute the linear index into the array of volume kernels (one // kernel for each combination of diffusive directions). bool diff_in_dir[GKYL_MAX_CDIM]; - if (isdirdiff) - for (int d=0; dconst_coeff? (const double *) gkyl_array_cfetch(diffusion->auxfields.D, 0) : (const double *) gkyl_array_cfetch(diffusion->auxfields.D, gkyl_range_idx(&diffusion->diff_range, idx)) +#define _cfD(idx) \ + diffusion->const_coeff ? (const double *)gkyl_array_cfetch(diffusion->auxfields.D, 0) : \ + (const double *)gkyl_array_cfetch( \ + diffusion->auxfields.D, gkyl_range_idx(&diffusion->diff_range, idx) \ + ) // for use in kernel tables -typedef struct { vol_termf_t kernels[7]; } gkyl_dg_diffusion_vlasov_vol_kern_list_diffdir; -typedef struct { gkyl_dg_diffusion_vlasov_vol_kern_list_diffdir list[2]; } gkyl_dg_diffusion_vlasov_vol_kern_list_polyOrder; -typedef struct { gkyl_dg_diffusion_vlasov_vol_kern_list_polyOrder list[3]; } gkyl_dg_diffusion_vlasov_vol_kern_list; +typedef struct { + vol_termf_t kernels[7]; +} gkyl_dg_diffusion_vlasov_vol_kern_list_diffdir; +typedef struct { + gkyl_dg_diffusion_vlasov_vol_kern_list_diffdir list[2]; +} gkyl_dg_diffusion_vlasov_vol_kern_list_polyOrder; +typedef struct { + gkyl_dg_diffusion_vlasov_vol_kern_list_polyOrder list[3]; +} gkyl_dg_diffusion_vlasov_vol_kern_list; // for use in kernel tables -typedef struct { diffusion_surf_t kernels[2]; } gkyl_dg_diffusion_vlasov_surf_kernels_polyOrder; -typedef struct { gkyl_dg_diffusion_vlasov_surf_kernels_polyOrder list[6]; } gkyl_dg_diffusion_vlasov_surf_kern_list; +typedef struct { + diffusion_surf_t kernels[2]; +} gkyl_dg_diffusion_vlasov_surf_kernels_polyOrder; +typedef struct { + gkyl_dg_diffusion_vlasov_surf_kernels_polyOrder list[6]; +} gkyl_dg_diffusion_vlasov_surf_kern_list; -typedef struct { diffusion_boundary_surf_t kernels[2]; } gkyl_dg_diffusion_vlasov_boundary_surf_kernels_polyOrder; -typedef struct { gkyl_dg_diffusion_vlasov_boundary_surf_kernels_polyOrder list[6]; } gkyl_dg_diffusion_vlasov_boundary_surf_kern_list; +typedef struct { + diffusion_boundary_surf_t kernels[2]; +} gkyl_dg_diffusion_vlasov_boundary_surf_kernels_polyOrder; +typedef struct { + gkyl_dg_diffusion_vlasov_boundary_surf_kernels_polyOrder list[6]; +} gkyl_dg_diffusion_vlasov_boundary_surf_kern_list; // ............... Homogeneous (constant) diffusion coefficient ............... // @@ -66,605 +95,881 @@ typedef struct { gkyl_dg_diffusion_vlasov_boundary_surf_kernels_polyOrder list[6 // Need to be separated like this for GPU build // 1x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_1x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_1x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_1x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_1x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_1x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_1x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_1x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_1x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 1x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_1x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_1x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_1x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_1x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_1x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_1x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_1x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_1x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 1x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_1x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_1x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order6_vol_1x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order6_vol_1x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 2x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 2x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 2x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 4th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 6th order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // Volume kernel list. -GKYL_CU_D -static const gkyl_dg_diffusion_vlasov_vol_kern_list ser_vol_kernels_constcoeff[] = { - // 1x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_vlasov_order2_vol_1x_ser_p1_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_vlasov_order2_vol_1x_ser_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, +GKYL_CU_D static const gkyl_dg_diffusion_vlasov_vol_kern_list + ser_vol_kernels_constcoeff[] = + { + // 1x + { + .list = + {// 2nd order diffusion. + {.list = + {{ker_dg_diffusion_vlasov_order2_vol_1x_ser_p1_constcoeff_diffdirsx, NULL, NULL, NULL, + NULL, NULL, NULL}, + {ker_dg_diffusion_vlasov_order2_vol_1x_ser_p2_constcoeff_diffdirsx, NULL, NULL, NULL, + NULL, NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{ker_dg_diffusion_vlasov_order4_vol_1x_ser_p1_constcoeff_diffdirsx, NULL, NULL, NULL, NULL, NULL, NULL}, {ker_dg_diffusion_vlasov_order4_vol_1x_ser_p2_constcoeff_diffdirsx, NULL, NULL, NULL, NULL, NULL, NULL}} + }, + // 6th order diffusion. + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {ker_dg_diffusion_vlasov_order6_vol_1x_ser_p2_constcoeff_diffdirsx, NULL, NULL, NULL, NULL, NULL, NULL}} + } + } }, - // 4th order diffusion. - {.list={ - {ker_dg_diffusion_vlasov_order4_vol_1x_ser_p1_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_vlasov_order4_vol_1x_ser_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, + // 2x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}, + {ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}, + {ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}} + } }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_vlasov_order6_vol_1x_ser_p2_constcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 2x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_vlasov_order4_vol_2x_ser_p1_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_vlasov_order4_vol_2x_ser_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_vlasov_order6_vol_2x_ser_p2_constcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 3x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxy,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsyz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz}, - {ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxy,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsyz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz},}, - }, - // 4th order diffusion. - {.list={ - {ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsx,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsy,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxy,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsz,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxz,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsyz,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz}, - {ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxy,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsz,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxz,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsyz,ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsx,ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsy,ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxy,ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsz,ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxz,ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsyz,ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz},}, - }, - }, - }, + // 3x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxy, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsyz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_constcoeff_diffdirsxyz}, + {ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_constcoeff_diffdirsxyz}}}, + // 4th order diffusion. + {.list = + {{ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxy, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsz, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxz, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsyz, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p1_constcoeff_diffdirsxyz}, + {ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsz, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_vlasov_order4_vol_3x_ser_p2_constcoeff_diffdirsxyz}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxy, + ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsz, + ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxz, + ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsyz, + ker_dg_diffusion_vlasov_order6_vol_3x_ser_p2_constcoeff_diffdirsxyz}}} + } + } }; // Surface kernel list: x-direction GKYL_CU_D static const gkyl_dg_diffusion_vlasov_surf_kern_list ser_vlasov_surfx_kernels_constcoeff[] = { // 2nd order diffusion. - {.list= { - { dg_diffusion_vlasov_order2_surfx_1x1v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfx_1x1v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order2_surfx_1x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfx_1x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order2_surfx_1x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfx_1x3v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order2_surfx_2x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfx_2x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order2_surfx_2x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfx_2x3v_ser_p2_constcoeff }, -// { dg_diffusion_vlasov_order2_surfx_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfx_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{dg_diffusion_vlasov_order2_surfx_1x1v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_surfx_1x1v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order2_surfx_1x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_surfx_1x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order2_surfx_1x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_surfx_1x3v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order2_surfx_2x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_surfx_2x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order2_surfx_2x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_surfx_2x3v_ser_p2_constcoeff}, + // { dg_diffusion_vlasov_order2_surfx_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfx_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, // 4th order diffusion. - {.list= { - { dg_diffusion_vlasov_order4_surfx_1x1v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfx_1x1v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order4_surfx_1x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfx_1x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order4_surfx_1x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfx_1x3v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order4_surfx_2x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfx_2x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order4_surfx_2x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfx_2x3v_ser_p2_constcoeff }, -// { dg_diffusion_vlasov_order4_surfx_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfx_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{dg_diffusion_vlasov_order4_surfx_1x1v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_surfx_1x1v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order4_surfx_1x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_surfx_1x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order4_surfx_1x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_surfx_1x3v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order4_surfx_2x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_surfx_2x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order4_surfx_2x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_surfx_2x3v_ser_p2_constcoeff}, + // { dg_diffusion_vlasov_order4_surfx_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfx_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, dg_diffusion_vlasov_order6_surfx_1x1v_ser_p2_constcoeff }, - { NULL, dg_diffusion_vlasov_order6_surfx_1x2v_ser_p2_constcoeff }, - { NULL, dg_diffusion_vlasov_order6_surfx_1x3v_ser_p2_constcoeff }, - { NULL, dg_diffusion_vlasov_order6_surfx_2x2v_ser_p2_constcoeff }, - { NULL, dg_diffusion_vlasov_order6_surfx_2x3v_ser_p2_constcoeff }, -// { NULL, dg_diffusion_vlasov_order6_surfx_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{NULL, dg_diffusion_vlasov_order6_surfx_1x1v_ser_p2_constcoeff}, + {NULL, dg_diffusion_vlasov_order6_surfx_1x2v_ser_p2_constcoeff}, + {NULL, dg_diffusion_vlasov_order6_surfx_1x3v_ser_p2_constcoeff}, + {NULL, dg_diffusion_vlasov_order6_surfx_2x2v_ser_p2_constcoeff}, + {NULL, dg_diffusion_vlasov_order6_surfx_2x3v_ser_p2_constcoeff}, + // { NULL, dg_diffusion_vlasov_order6_surfx_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}} }; // Surface kernel list: y-direction GKYL_CU_D static const gkyl_dg_diffusion_vlasov_surf_kern_list ser_vlasov_surfy_kernels_constcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_vlasov_order2_surfy_2x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfy_2x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order2_surfy_2x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfy_2x3v_ser_p2_constcoeff }, -// { dg_diffusion_vlasov_order2_surfy_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfy_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_vlasov_order2_surfy_2x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_surfy_2x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order2_surfy_2x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_surfy_2x3v_ser_p2_constcoeff}, + // { dg_diffusion_vlasov_order2_surfy_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfy_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_vlasov_order4_surfy_2x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfy_2x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order4_surfy_2x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfy_2x3v_ser_p2_constcoeff }, -// { dg_diffusion_vlasov_order4_surfy_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfy_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_vlasov_order4_surfy_2x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_surfy_2x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order4_surfy_2x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_surfy_2x3v_ser_p2_constcoeff}, + // { dg_diffusion_vlasov_order4_surfy_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfy_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_vlasov_order6_surfy_2x2v_ser_p2_constcoeff }, - { NULL, dg_diffusion_vlasov_order6_surfy_2x3v_ser_p2_constcoeff }, -// { NULL, dg_diffusion_vlasov_order6_surfy_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_vlasov_order6_surfy_2x2v_ser_p2_constcoeff}, + {NULL, dg_diffusion_vlasov_order6_surfy_2x3v_ser_p2_constcoeff}, + // { NULL, dg_diffusion_vlasov_order6_surfy_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}} }; // Surface kernel list: z-direction GKYL_CU_D static const gkyl_dg_diffusion_vlasov_surf_kern_list ser_vlasov_surfz_kernels_constcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, -// { dg_diffusion_vlasov_order2_surfz_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfz_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + // { dg_diffusion_vlasov_order2_surfz_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_surfz_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, -// { dg_diffusion_vlasov_order4_surfz_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfz_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + // { dg_diffusion_vlasov_order4_surfz_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_surfz_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, -// { NULL, dg_diffusion_vlasov_order6_surfz_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + // { NULL, dg_diffusion_vlasov_order6_surfz_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}} }; // Boundary surface kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list ser_vlasov_boundary_surfx_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { dg_diffusion_vlasov_order2_boundary_surfx_1x1v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfx_1x1v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order2_boundary_surfx_1x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfx_1x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order2_boundary_surfx_1x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfx_1x3v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order2_boundary_surfx_2x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfx_2x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order2_boundary_surfx_2x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfx_2x3v_ser_p2_constcoeff }, -// { dg_diffusion_vlasov_order2_boundary_surfx_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfx_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, - // 4th order diffusion. - {.list= { - { dg_diffusion_vlasov_order4_boundary_surfx_1x1v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfx_1x1v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order4_boundary_surfx_1x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfx_1x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order4_boundary_surfx_1x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfx_1x3v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order4_boundary_surfx_2x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfx_2x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order4_boundary_surfx_2x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfx_2x3v_ser_p2_constcoeff }, -// { dg_diffusion_vlasov_order4_boundary_surfx_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfx_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, dg_diffusion_vlasov_order6_boundary_surfx_1x1v_ser_p2_constcoeff }, - { NULL, dg_diffusion_vlasov_order6_boundary_surfx_1x2v_ser_p2_constcoeff }, - { NULL, dg_diffusion_vlasov_order6_boundary_surfx_1x3v_ser_p2_constcoeff }, - { NULL, dg_diffusion_vlasov_order6_boundary_surfx_2x2v_ser_p2_constcoeff }, - { NULL, dg_diffusion_vlasov_order6_boundary_surfx_2x3v_ser_p2_constcoeff }, -// { NULL, dg_diffusion_vlasov_order6_boundary_surfx_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list + ser_vlasov_boundary_surfx_kernels_constcoeff[] = { + // 2nd order diffusion. + {.list = + {{dg_diffusion_vlasov_order2_boundary_surfx_1x1v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_boundary_surfx_1x1v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order2_boundary_surfx_1x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_boundary_surfx_1x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order2_boundary_surfx_1x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_boundary_surfx_1x3v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order2_boundary_surfx_2x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_boundary_surfx_2x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order2_boundary_surfx_2x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_boundary_surfx_2x3v_ser_p2_constcoeff}, + // { dg_diffusion_vlasov_order2_boundary_surfx_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfx_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{dg_diffusion_vlasov_order4_boundary_surfx_1x1v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_boundary_surfx_1x1v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order4_boundary_surfx_1x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_boundary_surfx_1x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order4_boundary_surfx_1x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_boundary_surfx_1x3v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order4_boundary_surfx_2x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_boundary_surfx_2x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order4_boundary_surfx_2x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_boundary_surfx_2x3v_ser_p2_constcoeff}, + // { dg_diffusion_vlasov_order4_boundary_surfx_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfx_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, dg_diffusion_vlasov_order6_boundary_surfx_1x1v_ser_p2_constcoeff}, + {NULL, dg_diffusion_vlasov_order6_boundary_surfx_1x2v_ser_p2_constcoeff}, + {NULL, dg_diffusion_vlasov_order6_boundary_surfx_1x3v_ser_p2_constcoeff}, + {NULL, dg_diffusion_vlasov_order6_boundary_surfx_2x2v_ser_p2_constcoeff}, + {NULL, dg_diffusion_vlasov_order6_boundary_surfx_2x3v_ser_p2_constcoeff}, + // { NULL, dg_diffusion_vlasov_order6_boundary_surfx_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}} }; // Boundary surface kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list ser_vlasov_boundary_surfy_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_vlasov_order2_boundary_surfy_2x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfy_2x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order2_boundary_surfy_2x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfy_2x3v_ser_p2_constcoeff }, -// { dg_diffusion_vlasov_order2_boundary_surfy_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfy_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_vlasov_order4_boundary_surfy_2x2v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfy_2x2v_ser_p2_constcoeff }, - { dg_diffusion_vlasov_order4_boundary_surfy_2x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfy_2x3v_ser_p2_constcoeff }, -// { dg_diffusion_vlasov_order4_boundary_surfy_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfy_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, dg_diffusion_vlasov_order6_boundary_surfy_2x2v_ser_p2_constcoeff }, - { NULL, dg_diffusion_vlasov_order6_boundary_surfy_2x3v_ser_p2_constcoeff }, -// { NULL, dg_diffusion_vlasov_order6_boundary_surfy_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list + ser_vlasov_boundary_surfy_kernels_constcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_vlasov_order2_boundary_surfy_2x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_boundary_surfy_2x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order2_boundary_surfy_2x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order2_boundary_surfy_2x3v_ser_p2_constcoeff}, + // { dg_diffusion_vlasov_order2_boundary_surfy_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfy_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_vlasov_order4_boundary_surfy_2x2v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_boundary_surfy_2x2v_ser_p2_constcoeff}, + {dg_diffusion_vlasov_order4_boundary_surfy_2x3v_ser_p1_constcoeff, + dg_diffusion_vlasov_order4_boundary_surfy_2x3v_ser_p2_constcoeff}, + // { dg_diffusion_vlasov_order4_boundary_surfy_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfy_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, dg_diffusion_vlasov_order6_boundary_surfy_2x2v_ser_p2_constcoeff}, + {NULL, dg_diffusion_vlasov_order6_boundary_surfy_2x3v_ser_p2_constcoeff}, + // { NULL, dg_diffusion_vlasov_order6_boundary_surfy_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}} }; // Boundary surface kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list ser_vlasov_boundary_surfz_kernels_constcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, -// { dg_diffusion_vlasov_order2_boundary_surfz_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfz_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, -// { dg_diffusion_vlasov_order4_boundary_surfz_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfz_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, -// { NULL, dg_diffusion_vlasov_order6_boundary_surfz_3x3v_ser_p2_constcoeff },}, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list + ser_vlasov_boundary_surfz_kernels_constcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + // { dg_diffusion_vlasov_order2_boundary_surfz_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order2_boundary_surfz_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + // { dg_diffusion_vlasov_order4_boundary_surfz_3x3v_ser_p1_constcoeff, dg_diffusion_vlasov_order4_boundary_surfz_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + // { NULL, dg_diffusion_vlasov_order6_boundary_surfz_3x3v_ser_p2_constcoeff },}, + {NULL, NULL}}} }; // ............... Inhomogeneous (spatially varying) diffusion coefficient ............... // @@ -673,430 +978,466 @@ GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list ser_vlas // Need to be separated like this for GPU build // 1x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_1x_ser_p1_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_1x_ser_p1_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_1x_ser_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_1x_ser_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_1x_ser_p1_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_1x_ser_p1_varcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_1x_ser_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_1x_ser_p2_varcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 2x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // 3x 2nd order diffusion. -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsx(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsx(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxy(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxy(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsyz(xc, dx, _cfD(idx), qIn, qRhsOut); -} -GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz(xc, dx, _cfD(idx), qIn, qRhsOut); +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsx( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsx( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxy( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxy( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); +} +GKYL_CU_DH static double ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + return dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz( + xc, dx, _cfD(idx), qIn, qRhsOut + ); } // Volume kernel list. -GKYL_CU_D -static const gkyl_dg_diffusion_vlasov_vol_kern_list ser_vol_kernels_varcoeff[] = { - // 1x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_vlasov_order2_vol_1x_ser_p1_varcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_vlasov_order2_vol_1x_ser_p2_varcoeff_diffdirsx,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, - // 2x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsx,ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsy,ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsxy,NULL,NULL,NULL,NULL}, - {ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsx,ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsy,ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsxy,NULL,NULL,NULL,NULL},}, - }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, +GKYL_CU_D static const gkyl_dg_diffusion_vlasov_vol_kern_list + ser_vol_kernels_varcoeff[] = + { + // 1x + { + .list = + {// 2nd order diffusion. + {.list = + {{ker_dg_diffusion_vlasov_order2_vol_1x_ser_p1_varcoeff_diffdirsx, NULL, NULL, NULL, + NULL, NULL, NULL}, + {ker_dg_diffusion_vlasov_order2_vol_1x_ser_p2_varcoeff_diffdirsx, NULL, NULL, NULL, + NULL, NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL, NULL}} + }, + // 6th order diffusion. + {.list = {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL, NULL}} + } + } }, - }, - }, - // 3x - {.list={ - // 2nd order diffusion. - {.list={ - {ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsx,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsy,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxy,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsyz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz}, - {ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsx,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsy,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxy,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsyz,ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz},}, + // 2x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order2_vol_2x_ser_p1_varcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}, + {ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order2_vol_2x_ser_p2_varcoeff_diffdirsxy, NULL, NULL, + NULL, NULL}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}} + } }, - // 4th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - // 6th order diffusion. - {.list={ - {NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {NULL,NULL,NULL,NULL,NULL,NULL,NULL},}, - }, - }, - }, + // 3x + { + .list = + { + // 2nd order diffusion. + {.list = + {{ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxy, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsyz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p1_varcoeff_diffdirsxyz}, + {ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsx, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsy, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxy, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsyz, + ker_dg_diffusion_vlasov_order2_vol_3x_ser_p2_varcoeff_diffdirsxyz}}}, + // 4th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}}, + // 6th order diffusion. + {.list = + {{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}} + } + } }; // Surface kernel list: x-direction GKYL_CU_D static const gkyl_dg_diffusion_vlasov_surf_kern_list ser_vlasov_surfx_kernels_varcoeff[] = { // 2nd order diffusion. - {.list= { - { dg_diffusion_vlasov_order2_surfx_1x1v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfx_1x1v_ser_p2_varcoeff }, - { dg_diffusion_vlasov_order2_surfx_1x2v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfx_1x2v_ser_p2_varcoeff }, - { dg_diffusion_vlasov_order2_surfx_1x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfx_1x3v_ser_p2_varcoeff }, - { dg_diffusion_vlasov_order2_surfx_2x2v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfx_2x2v_ser_p2_varcoeff }, - { dg_diffusion_vlasov_order2_surfx_2x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfx_2x3v_ser_p2_varcoeff }, -// { dg_diffusion_vlasov_order2_surfx_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfx_3x3v_ser_p2_varcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{dg_diffusion_vlasov_order2_surfx_1x1v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_surfx_1x1v_ser_p2_varcoeff}, + {dg_diffusion_vlasov_order2_surfx_1x2v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_surfx_1x2v_ser_p2_varcoeff}, + {dg_diffusion_vlasov_order2_surfx_1x3v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_surfx_1x3v_ser_p2_varcoeff}, + {dg_diffusion_vlasov_order2_surfx_2x2v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_surfx_2x2v_ser_p2_varcoeff}, + {dg_diffusion_vlasov_order2_surfx_2x3v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_surfx_2x3v_ser_p2_varcoeff}, + // { dg_diffusion_vlasov_order2_surfx_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfx_3x3v_ser_p2_varcoeff },}, + {NULL, NULL}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Surface kernel list: y-direction GKYL_CU_D static const gkyl_dg_diffusion_vlasov_surf_kern_list ser_vlasov_surfy_kernels_varcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_vlasov_order2_surfy_2x2v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfy_2x2v_ser_p2_varcoeff }, - { dg_diffusion_vlasov_order2_surfy_2x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfy_2x3v_ser_p2_varcoeff }, -// { dg_diffusion_vlasov_order2_surfy_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfy_3x3v_ser_p2_varcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_vlasov_order2_surfy_2x2v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_surfy_2x2v_ser_p2_varcoeff}, + {dg_diffusion_vlasov_order2_surfy_2x3v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_surfy_2x3v_ser_p2_varcoeff}, + // { dg_diffusion_vlasov_order2_surfy_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfy_3x3v_ser_p2_varcoeff },}, + {NULL, NULL}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Surface kernel list: z-direction GKYL_CU_D static const gkyl_dg_diffusion_vlasov_surf_kern_list ser_vlasov_surfz_kernels_varcoeff[] = { // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, -// { dg_diffusion_vlasov_order2_surfz_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfz_3x3v_ser_p2_varcoeff },}, - { NULL, NULL },}, - }, + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + // { dg_diffusion_vlasov_order2_surfz_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_surfz_3x3v_ser_p2_varcoeff },}, + {NULL, NULL}}}, // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: x-direction -GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list ser_vlasov_boundary_surfx_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { dg_diffusion_vlasov_order2_boundary_surfx_1x1v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfx_1x1v_ser_p2_varcoeff }, - { dg_diffusion_vlasov_order2_boundary_surfx_1x2v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfx_1x2v_ser_p2_varcoeff }, - { dg_diffusion_vlasov_order2_boundary_surfx_1x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfx_1x3v_ser_p2_varcoeff }, - { dg_diffusion_vlasov_order2_boundary_surfx_2x2v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfx_2x2v_ser_p2_varcoeff }, - { dg_diffusion_vlasov_order2_boundary_surfx_2x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfx_2x3v_ser_p2_varcoeff }, -// { dg_diffusion_vlasov_order2_boundary_surfx_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfx_3x3v_ser_p2_varcoeff },}, - { NULL, NULL },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list + ser_vlasov_boundary_surfx_kernels_varcoeff[] = { + // 2nd order diffusion. + {.list = + {{dg_diffusion_vlasov_order2_boundary_surfx_1x1v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_boundary_surfx_1x1v_ser_p2_varcoeff}, + {dg_diffusion_vlasov_order2_boundary_surfx_1x2v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_boundary_surfx_1x2v_ser_p2_varcoeff}, + {dg_diffusion_vlasov_order2_boundary_surfx_1x3v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_boundary_surfx_1x3v_ser_p2_varcoeff}, + {dg_diffusion_vlasov_order2_boundary_surfx_2x2v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_boundary_surfx_2x2v_ser_p2_varcoeff}, + {dg_diffusion_vlasov_order2_boundary_surfx_2x3v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_boundary_surfx_2x3v_ser_p2_varcoeff}, + // { dg_diffusion_vlasov_order2_boundary_surfx_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfx_3x3v_ser_p2_varcoeff },}, + {NULL, NULL}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: y-direction -GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list ser_vlasov_boundary_surfy_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { dg_diffusion_vlasov_order2_boundary_surfy_2x2v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfy_2x2v_ser_p2_varcoeff }, - { dg_diffusion_vlasov_order2_boundary_surfy_2x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfy_2x3v_ser_p2_varcoeff }, -// { dg_diffusion_vlasov_order2_boundary_surfy_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfy_3x3v_ser_p2_varcoeff },}, - { NULL, NULL },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list + ser_vlasov_boundary_surfy_kernels_varcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {dg_diffusion_vlasov_order2_boundary_surfy_2x2v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_boundary_surfy_2x2v_ser_p2_varcoeff}, + {dg_diffusion_vlasov_order2_boundary_surfy_2x3v_ser_p1_varcoeff, + dg_diffusion_vlasov_order2_boundary_surfy_2x3v_ser_p2_varcoeff}, + // { dg_diffusion_vlasov_order2_boundary_surfy_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfy_3x3v_ser_p2_varcoeff },}, + {NULL, NULL}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; // Boundary surface kernel list: z-direction -GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list ser_vlasov_boundary_surfz_kernels_varcoeff[] = { - // 2nd order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, -// { dg_diffusion_vlasov_order2_boundary_surfz_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfz_3x3v_ser_p2_varcoeff },}, - { NULL, NULL },}, - }, - // 4th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, - // 6th order diffusion. - {.list= { - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL }, - { NULL, NULL },}, - }, +GKYL_CU_D static const gkyl_dg_diffusion_vlasov_boundary_surf_kern_list + ser_vlasov_boundary_surfz_kernels_varcoeff[] = { + // 2nd order diffusion. + {.list = + {{NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + // { dg_diffusion_vlasov_order2_boundary_surfz_3x3v_ser_p1_varcoeff, dg_diffusion_vlasov_order2_boundary_surfz_3x3v_ser_p2_varcoeff },}, + {NULL, NULL}}}, + // 4th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}, + // 6th order diffusion. + {.list = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}} }; -#define SURFKERIDX(cdim,vdim) cdim-1+vdim-1+GKYL_MIN2(1,cdim-1) +#define SURFKERIDX(cdim, vdim) cdim - 1 + vdim - 1 + GKYL_MIN2(1, cdim - 1) // Macro for choosing volume and surface kernels. -#define CKVOL(lst,cdim,diff_order,poly_order,diffdir_linidx) lst[cdim-1].list[diff_order/2-1].list[poly_order-1].kernels[diffdir_linidx] -#define CKSURF(lst,diff_order,cdim,vdim,poly_order) lst[diff_order/2-1].list[SURFKERIDX(cdim,vdim)].kernels[poly_order-1] +#define CKVOL(lst, cdim, diff_order, poly_order, diffdir_linidx) \ + lst[cdim - 1].list[diff_order / 2 - 1].list[poly_order - 1].kernels[diffdir_linidx] +#define CKSURF(lst, diff_order, cdim, vdim, poly_order) \ + lst[diff_order / 2 - 1].list[SURFKERIDX(cdim, vdim)].kernels[poly_order - 1] /** * Free diffusion equation object * * @param ref Reference counter for constant diffusion equation */ -void gkyl_dg_diffusion_vlasov_free(const struct gkyl_ref_count* ref); +void gkyl_dg_diffusion_vlasov_free(const struct gkyl_ref_count *ref); -GKYL_CU_D static double surf(const struct gkyl_dg_eqn* eqn, int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, - double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - - if (diffusion->diff_in_dir[dir]) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + + if (diffusion->diff_in_dir[dir]) { diffusion->surf[dir](xcC, dxC, _cfD(idxC), qInL, qInC, qInR, qRhsOut); + } - return 0.; // CFL frequency computed in volume term. + return 0.; // CFL frequency computed in volume term. } -GKYL_CU_D static double boundary_surf(const struct gkyl_dg_eqn* eqn, int dir, - const double* xcEdge, const double* xcSkin, const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) -{ - struct dg_diffusion_vlasov* diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); - - if (diffusion->diff_in_dir[dir]) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) +{ + struct dg_diffusion_vlasov *diffusion = container_of(eqn, struct dg_diffusion_vlasov, eqn); + + if (diffusion->diff_in_dir[dir]) { diffusion->boundary_surf[dir](xcSkin, dxSkin, _cfD(idxSkin), edge, qInSkin, qInEdge, qRhsOut); + } - return 0.; // CFL frequency computed in volume term. + return 0.; // CFL frequency computed in volume term. } #undef _cfD @@ -1114,7 +1455,8 @@ GKYL_CU_D static double boundary_surf(const struct gkyl_dg_eqn* eqn, int dir, * @param use_gpu Whether to run on host or device. * @return Pointer to diffusion equation object */ -struct gkyl_dg_eqn* -gkyl_dg_diffusion_vlasov_cu_dev_new(const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, - bool is_diff_const, const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range); +struct gkyl_dg_eqn *gkyl_dg_diffusion_vlasov_cu_dev_new( + const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, + const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range +); #endif diff --git a/vlasov/zero/gkyl_dg_eqn.h b/vlasov/zero/gkyl_dg_eqn.h index 0f8437a189..5bbcaa2d45 100644 --- a/vlasov/zero/gkyl_dg_eqn.h +++ b/vlasov/zero/gkyl_dg_eqn.h @@ -9,25 +9,25 @@ struct gkyl_dg_eqn; // Function pointer type for volume kernel -typedef double (*vol_termf_t)(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, - const double* qIn, double* GKYL_RESTRICT qRhsOut); +typedef double (*vol_termf_t)( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +); // Function pointer type for surface kernel -typedef double (*surf_termf_t)(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut); +typedef double (*surf_termf_t)( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +); // Function pointer type for boundary surface kernel -typedef double (*boundary_surf_termf_t)(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut); +typedef double (*boundary_surf_termf_t)( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +); // Function pointer type for generic stencil kernel // Similar to surface kernel, but size of input arrays unspecified @@ -37,11 +37,11 @@ typedef double (*boundary_surf_termf_t)(const struct gkyl_dg_eqn *eqn, // NOTE: Takes the index of the cell being updated (idxc) and array of indices // (idx) so we can fetch auxiliary variables easily for neighbors or just // the cell being updated. Need size of integer array (sz_dim) -typedef double (*gen_termf_t)(const struct gkyl_dg_eqn *eqn, - int dir1, int dir2, - const double* xc, const double* dxc, const int* idxc, - long sz_dim, const int idx[27][GKYL_MAX_DIM], const double* qIn[27], - double* GKYL_RESTRICT qRhsOut); +typedef double (*gen_termf_t)( + const struct gkyl_dg_eqn *eqn, int dir1, int dir2, const double *xc, const double *dxc, + const int *idxc, long sz_dim, const int idx[27][GKYL_MAX_DIM], const double *qIn[27], + double *GKYL_RESTRICT qRhsOut +); struct gkyl_dg_eqn { int num_equations; // Number of equations in system. @@ -51,10 +51,10 @@ struct gkyl_dg_eqn { boundary_surf_termf_t boundary_diag_term; // Boundary diagnotic kernel. gen_termf_t gen_surf_term; // Generic stencil kernel with input variable size unspecified. gen_termf_t gen_boundary_surf_term; // Generic stencil kernel with input variable size unspecified - // for boundary surface updates. + // for boundary surface updates. uint32_t flags; struct gkyl_ref_count ref_count; // Reference count. - struct gkyl_dg_eqn *on_dev; // Pointer to itself or device data. + struct gkyl_dg_eqn *on_dev; // Pointer to itself or device data. }; // context for use in BCs @@ -78,7 +78,7 @@ bool gkyl_dg_eqn_is_cu_dev(const struct gkyl_dg_eqn *eqn); * * @param eqn Equation object. */ -struct gkyl_dg_eqn* gkyl_dg_eqn_acquire(const struct gkyl_dg_eqn* eqn); +struct gkyl_dg_eqn *gkyl_dg_eqn_acquire(const struct gkyl_dg_eqn *eqn); /** * Compute the volume term in a DG discretization. @@ -91,11 +91,10 @@ struct gkyl_dg_eqn* gkyl_dg_eqn_acquire(const struct gkyl_dg_eqn* eqn); * @param qRhsOut Output RHS for use in an explicit time-stepping scheme * @return cfl frequency *if volume term is computing stable time step* (otherwise returns 0.0) */ -GKYL_CU_DH -static inline double -gkyl_dg_eqn_vol_update(const struct gkyl_dg_eqn *eqn, - const double* xc, const double* dx, const int* idx, - const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static inline double gkyl_dg_eqn_vol_update( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return eqn->vol_term(eqn, xc, dx, idx, qIn, qRhsOut); } @@ -120,20 +119,16 @@ gkyl_dg_eqn_vol_update(const struct gkyl_dg_eqn *eqn, * @param qRhsOut Output RHS for use in an explicit time-stepping scheme in center cell (the cell being updated) * @return cfl frequency *if surface term is computing stable time step* (otherwise returns 0.0) */ -GKYL_CU_DH -static inline double -gkyl_dg_eqn_surf_update(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static inline double gkyl_dg_eqn_surf_update( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { - return eqn->surf_term(eqn, dir, - xcL, xcC, xcR, - dxL, dxC, dxR, - idxL, idxC, idxR, - qInL, qInC, qInR, qRhsOut); + return eqn->surf_term( + eqn, dir, xcL, xcC, xcR, dxL, dxC, dxR, idxL, idxC, idxR, qInL, qInC, qInR, qRhsOut + ); } /** @@ -153,20 +148,15 @@ gkyl_dg_eqn_surf_update(const struct gkyl_dg_eqn *eqn, * @param qRhsOut Output RHS for use in an explicit time-stepping scheme in skin cell (the cell being updated) * @return cfl frequency *if boundary surface term is computing stable time step* (otherwise returns 0.0) */ -GKYL_CU_DH -static inline double -gkyl_dg_eqn_boundary_surf_update(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static inline double gkyl_dg_eqn_boundary_surf_update( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { - return eqn->boundary_surf_term(eqn, dir, - xcEdge, xcSkin, - dxEdge, dxSkin, - idxEdge, idxSkin, edge, - qInEdge, qInSkin, qRhsOut); + return eqn->boundary_surf_term( + eqn, dir, xcEdge, xcSkin, dxEdge, dxSkin, idxEdge, idxSkin, edge, qInEdge, qInSkin, qRhsOut + ); } /** @@ -187,20 +177,15 @@ gkyl_dg_eqn_boundary_surf_update(const struct gkyl_dg_eqn *eqn, * @param qRhsOut Output RHS for use in an explicit time-stepping scheme in skin cell (the cell being updated) * @return cfl frequency *if boundary surface term is computing stable time step* (otherwise returns 0.0) */ -GKYL_CU_DH -static inline double -gkyl_dg_eqn_boundary_diag_update(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static inline double gkyl_dg_eqn_boundary_diag_update( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { - return eqn->boundary_diag_term(eqn, dir, - xcEdge, xcSkin, - dxEdge, dxSkin, - idxEdge, idxSkin, edge, - qInEdge, qInSkin, qRhsOut); + return eqn->boundary_diag_term( + eqn, dir, xcEdge, xcSkin, dxEdge, dxSkin, idxEdge, idxSkin, edge, qInEdge, qInSkin, qRhsOut + ); } /** diff --git a/vlasov/zero/gkyl_dg_euler.h b/vlasov/zero/gkyl_dg_euler.h index 347e8912d5..092c7dd48f 100644 --- a/vlasov/zero/gkyl_dg_euler.h +++ b/vlasov/zero/gkyl_dg_euler.h @@ -10,7 +10,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_euler_auxfields { +struct gkyl_dg_euler_auxfields { const struct gkyl_array *u; const struct gkyl_array *p; const struct gkyl_array *u_surf; @@ -27,15 +27,19 @@ struct gkyl_dg_euler_auxfields { * @param use_gpu Boolean to determine whether equation object is on host or device * @return Pointer to euler equation object */ -struct gkyl_dg_eqn* gkyl_dg_euler_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_euler_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, + const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, bool use_gpu +); /** * Create new Euler equation object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_dg_eqn* gkyl_dg_euler_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_range* conf_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom); +struct gkyl_dg_eqn *gkyl_dg_euler_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, + const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom +); /** * Set the auxiliary fields (e.g. velocity u = rho*u/rho) needed in updating euler equation. @@ -52,6 +56,8 @@ void gkyl_euler_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_eule * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_euler_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_auxfields auxin); +void gkyl_euler_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_euler_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_euler_priv.h b/vlasov/zero/gkyl_dg_euler_priv.h index ef9e9391e9..5ae09b3a0f 100644 --- a/vlasov/zero/gkyl_dg_euler_priv.h +++ b/vlasov/zero/gkyl_dg_euler_priv.h @@ -12,19 +12,24 @@ // functions // Types for various kernels -typedef double (*euler_surf_t)(const double *w, const double *dxv, const struct gkyl_wv_eqn *wv_eqn, - const struct gkyl_wave_cell_geom *geom_l, const struct gkyl_wave_cell_geom *geom_r, - const double *u_surf_l, const double *u_surf_c, const double *u_surf_r, - const double *p_surf_l, const double *p_surf_c, const double *p_surf_r, - const double *fluid_l, const double *fluid_c, const double *fluid_r, - double* GKYL_RESTRICT out); +typedef double (*euler_surf_t)( + const double *w, const double *dxv, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_cell_geom *geom_l, const struct gkyl_wave_cell_geom *geom_r, + const double *u_surf_l, const double *u_surf_c, const double *u_surf_r, const double *p_surf_l, + const double *p_surf_c, const double *p_surf_r, const double *fluid_l, const double *fluid_c, + const double *fluid_r, double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[4]; } gkyl_dg_euler_vol_kern_list; -typedef struct { euler_surf_t kernels[4]; } gkyl_dg_euler_surf_kern_list; +typedef struct { + vol_termf_t kernels[4]; +} gkyl_dg_euler_vol_kern_list; +typedef struct { + euler_surf_t kernels[4]; +} gkyl_dg_euler_surf_kern_list; struct dg_euler { - struct gkyl_dg_eqn eqn; // Base object + struct gkyl_dg_eqn eqn; // Base object euler_surf_t surf[3]; // pointers to surface kernels enum gkyl_eqn_type eqn_type; // Equation type const struct gkyl_wv_eqn *wv_eqn; // wave equation object for Roe solve @@ -34,152 +39,144 @@ struct dg_euler { struct gkyl_dg_euler_auxfields auxfields; // Auxiliary fields. }; -GKYL_CU_DH -static double -kernel_euler_vol_1x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_euler_vol_1x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_euler *euler = container_of(eqn, struct dg_euler, eqn); long cidx = gkyl_range_idx(&euler->conf_range, idx); - return euler_vol_1x_ser_p1(xc, dx, euler->gas_gamma, - (const double*) gkyl_array_cfetch(euler->auxfields.u, cidx), - (const double*) gkyl_array_cfetch(euler->auxfields.p, cidx), - qIn, qRhsOut); + return euler_vol_1x_ser_p1( + xc, dx, euler->gas_gamma, (const double *)gkyl_array_cfetch(euler->auxfields.u, cidx), + (const double *)gkyl_array_cfetch(euler->auxfields.p, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_euler_vol_1x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_euler_vol_1x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_euler *euler = container_of(eqn, struct dg_euler, eqn); long cidx = gkyl_range_idx(&euler->conf_range, idx); - return euler_vol_1x_ser_p2(xc, dx, euler->gas_gamma, - (const double*) gkyl_array_cfetch(euler->auxfields.u, cidx), - (const double*) gkyl_array_cfetch(euler->auxfields.p, cidx), - qIn, qRhsOut); + return euler_vol_1x_ser_p2( + xc, dx, euler->gas_gamma, (const double *)gkyl_array_cfetch(euler->auxfields.u, cidx), + (const double *)gkyl_array_cfetch(euler->auxfields.p, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_euler_vol_1x_ser_p3(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_euler_vol_1x_ser_p3( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_euler *euler = container_of(eqn, struct dg_euler, eqn); long cidx = gkyl_range_idx(&euler->conf_range, idx); - return euler_vol_1x_ser_p3(xc, dx, euler->gas_gamma, - (const double*) gkyl_array_cfetch(euler->auxfields.u, cidx), - (const double*) gkyl_array_cfetch(euler->auxfields.p, cidx), - qIn, qRhsOut); + return euler_vol_1x_ser_p3( + xc, dx, euler->gas_gamma, (const double *)gkyl_array_cfetch(euler->auxfields.u, cidx), + (const double *)gkyl_array_cfetch(euler->auxfields.p, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_euler_vol_2x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_euler_vol_2x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_euler *euler = container_of(eqn, struct dg_euler, eqn); long cidx = gkyl_range_idx(&euler->conf_range, idx); - return euler_vol_2x_ser_p1(xc, dx, euler->gas_gamma, - (const double*) gkyl_array_cfetch(euler->auxfields.u, cidx), - (const double*) gkyl_array_cfetch(euler->auxfields.p, cidx), - qIn, qRhsOut); + return euler_vol_2x_ser_p1( + xc, dx, euler->gas_gamma, (const double *)gkyl_array_cfetch(euler->auxfields.u, cidx), + (const double *)gkyl_array_cfetch(euler->auxfields.p, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_euler_vol_2x_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_euler_vol_2x_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_euler *euler = container_of(eqn, struct dg_euler, eqn); long cidx = gkyl_range_idx(&euler->conf_range, idx); - return euler_vol_2x_tensor_p2(xc, dx, euler->gas_gamma, - (const double*) gkyl_array_cfetch(euler->auxfields.u, cidx), - (const double*) gkyl_array_cfetch(euler->auxfields.p, cidx), - qIn, qRhsOut); + return euler_vol_2x_tensor_p2( + xc, dx, euler->gas_gamma, (const double *)gkyl_array_cfetch(euler->auxfields.u, cidx), + (const double *)gkyl_array_cfetch(euler->auxfields.p, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_euler_vol_3x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_euler_vol_3x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_euler *euler = container_of(eqn, struct dg_euler, eqn); long cidx = gkyl_range_idx(&euler->conf_range, idx); - return euler_vol_3x_ser_p1(xc, dx, euler->gas_gamma, - (const double*) gkyl_array_cfetch(euler->auxfields.u, cidx), - (const double*) gkyl_array_cfetch(euler->auxfields.p, cidx), - qIn, qRhsOut); + return euler_vol_3x_ser_p1( + xc, dx, euler->gas_gamma, (const double *)gkyl_array_cfetch(euler->auxfields.u, cidx), + (const double *)gkyl_array_cfetch(euler->auxfields.p, cidx), qIn, qRhsOut + ); } // Volume kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_euler_vol_kern_list ser_vol_kernels[] = { - { NULL, kernel_euler_vol_1x_ser_p1, kernel_euler_vol_1x_ser_p2, kernel_euler_vol_1x_ser_p3 }, // 0 - { NULL, kernel_euler_vol_2x_ser_p1, NULL, NULL }, // 1 - { NULL, kernel_euler_vol_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_vol_kern_list ser_vol_kernels[] = { + {NULL, kernel_euler_vol_1x_ser_p1, kernel_euler_vol_1x_ser_p2, kernel_euler_vol_1x_ser_p3}, // 0 + {NULL, kernel_euler_vol_2x_ser_p1, NULL, NULL}, // 1 + {NULL, kernel_euler_vol_3x_ser_p1, NULL, NULL} // 2 }; // Surface kernel list: x-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_euler_surf_kern_list ser_surf_x_kernels[] = { - { NULL, euler_surfx_1x_ser_p1, euler_surfx_1x_ser_p2, euler_surfx_1x_ser_p3 }, // 0 - { NULL, euler_surfx_2x_ser_p1, NULL, NULL }, // 1 - { NULL, euler_surfx_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_surf_kern_list ser_surf_x_kernels[] = { + {NULL, euler_surfx_1x_ser_p1, euler_surfx_1x_ser_p2, euler_surfx_1x_ser_p3}, // 0 + {NULL, euler_surfx_2x_ser_p1, NULL, NULL}, // 1 + {NULL, euler_surfx_3x_ser_p1, NULL, NULL} // 2 }; // Surface kernel list: y-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_euler_surf_kern_list ser_surf_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, euler_surfy_2x_ser_p1, NULL, NULL }, // 1 - { NULL, euler_surfy_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_surf_kern_list ser_surf_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, euler_surfy_2x_ser_p1, NULL, NULL}, // 1 + {NULL, euler_surfy_3x_ser_p1, NULL, NULL} // 2 }; // Surface kernel list: z-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_euler_surf_kern_list ser_surf_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, euler_surfz_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_surf_kern_list ser_surf_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, euler_surfz_3x_ser_p1, NULL, NULL} // 2 }; // Volume kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_dg_euler_vol_kern_list ten_vol_kernels[] = { - { NULL, kernel_euler_vol_1x_ser_p1, kernel_euler_vol_1x_ser_p2, kernel_euler_vol_1x_ser_p3 }, // 0 - { NULL, kernel_euler_vol_2x_ser_p1, kernel_euler_vol_2x_tensor_p2, NULL }, // 1 - { NULL, kernel_euler_vol_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_vol_kern_list ten_vol_kernels[] = { + {NULL, kernel_euler_vol_1x_ser_p1, kernel_euler_vol_1x_ser_p2, kernel_euler_vol_1x_ser_p3}, // 0 + {NULL, kernel_euler_vol_2x_ser_p1, kernel_euler_vol_2x_tensor_p2, NULL}, // 1 + {NULL, kernel_euler_vol_3x_ser_p1, NULL, NULL} // 2 }; // Surface kernel list: x-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_euler_surf_kern_list ten_surf_x_kernels[] = { - { NULL, euler_surfx_1x_ser_p1, euler_surfx_1x_ser_p2, euler_surfx_1x_ser_p3 }, // 0 - { NULL, euler_surfx_2x_ser_p1, euler_surfx_2x_tensor_p2, NULL }, // 1 - { NULL, euler_surfx_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_surf_kern_list ten_surf_x_kernels[] = { + {NULL, euler_surfx_1x_ser_p1, euler_surfx_1x_ser_p2, euler_surfx_1x_ser_p3}, // 0 + {NULL, euler_surfx_2x_ser_p1, euler_surfx_2x_tensor_p2, NULL}, // 1 + {NULL, euler_surfx_3x_ser_p1, NULL, NULL} // 2 }; // Surface kernel list: y-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_euler_surf_kern_list ten_surf_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, euler_surfy_2x_ser_p1, euler_surfy_2x_tensor_p2, NULL }, // 1 - { NULL, euler_surfy_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_surf_kern_list ten_surf_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, euler_surfy_2x_ser_p1, euler_surfy_2x_tensor_p2, NULL}, // 1 + {NULL, euler_surfy_3x_ser_p1, NULL, NULL} // 2 }; // Surface kernel list: z-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_euler_surf_kern_list ten_surf_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, euler_surfz_3x_ser_p1, NULL, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_euler_surf_kern_list ten_surf_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, euler_surfz_3x_ser_p1, NULL, NULL} // 2 }; /** @@ -189,14 +186,12 @@ static const gkyl_dg_euler_surf_kern_list ten_surf_z_kernels[] = { */ void gkyl_dg_euler_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_euler *euler = container_of(eqn, struct dg_euler, eqn); @@ -207,25 +202,22 @@ surf(const struct gkyl_dg_eqn *eqn, const struct gkyl_wave_cell_geom *geom_l = gkyl_wave_geom_get(euler->geom, idxC); const struct gkyl_wave_cell_geom *geom_r = gkyl_wave_geom_get(euler->geom, idxR); - return euler->surf[dir](xcC, dxC, - euler->wv_eqn, geom_l, geom_r, - (const double*) gkyl_array_cfetch(euler->auxfields.u_surf, cidx_l), - (const double*) gkyl_array_cfetch(euler->auxfields.u_surf, cidx_c), - (const double*) gkyl_array_cfetch(euler->auxfields.u_surf, cidx_r), - (const double*) gkyl_array_cfetch(euler->auxfields.p_surf, cidx_l), - (const double*) gkyl_array_cfetch(euler->auxfields.p_surf, cidx_c), - (const double*) gkyl_array_cfetch(euler->auxfields.p_surf, cidx_r), - qInL, qInC, qInR, qRhsOut); + return euler->surf[dir]( + xcC, dxC, euler->wv_eqn, geom_l, geom_r, + (const double *)gkyl_array_cfetch(euler->auxfields.u_surf, cidx_l), + (const double *)gkyl_array_cfetch(euler->auxfields.u_surf, cidx_c), + (const double *)gkyl_array_cfetch(euler->auxfields.u_surf, cidx_r), + (const double *)gkyl_array_cfetch(euler->auxfields.p_surf, cidx_l), + (const double *)gkyl_array_cfetch(euler->auxfields.p_surf, cidx_c), + (const double *)gkyl_array_cfetch(euler->auxfields.p_surf, cidx_r), qInL, qInC, qInR, qRhsOut + ); } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { return 0.; } diff --git a/vlasov/zero/gkyl_dg_fpo_vlasov_diff.h b/vlasov/zero/gkyl_dg_fpo_vlasov_diff.h index 2116b275c0..19d91be0d3 100644 --- a/vlasov/zero/gkyl_dg_fpo_vlasov_diff.h +++ b/vlasov/zero/gkyl_dg_fpo_vlasov_diff.h @@ -17,7 +17,9 @@ struct gkyl_dg_fpo_vlasov_diff_auxfields { * @param phase_range phase space range for use in indexing diffusion flux term * @return Pointer to fpo equation object */ -struct gkyl_dg_eqn* gkyl_dg_fpo_vlasov_diff_new(const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_fpo_vlasov_diff_new( + const struct gkyl_basis *pbasis, const struct gkyl_range *phase_range, bool use_gpu +); /** * Create a new FPO diffusion equation object that lives on NV-GPU @@ -26,7 +28,9 @@ struct gkyl_dg_eqn* gkyl_dg_fpo_vlasov_diff_new(const struct gkyl_basis* pbasis, * @param phase_range phase space range for use in indexing diffusion flux term * @return Pointer to fpo equation object */ -struct gkyl_dg_eqn* gkyl_dg_fpo_vlasov_diff_cu_dev_new(const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range); +struct gkyl_dg_eqn *gkyl_dg_fpo_vlasov_diff_cu_dev_new( + const struct gkyl_basis *pbasis, const struct gkyl_range *phase_range +); /** * Set auxiliary fields needed in updating the diffusion flux term (D = grad(grad(g)), g solved for externally). @@ -34,7 +38,9 @@ struct gkyl_dg_eqn* gkyl_dg_fpo_vlasov_diff_cu_dev_new(const struct gkyl_basis* * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_fpo_vlasov_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_diff_auxfields auxin); +void gkyl_fpo_vlasov_diff_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_diff_auxfields auxin +); #ifdef GKYL_HAVE_CUDA @@ -44,6 +50,8 @@ void gkyl_fpo_vlasov_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gk * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_fpo_vlasov_diff_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_diff_auxfields auxin); +void gkyl_fpo_vlasov_diff_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_diff_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_fpo_vlasov_diff_priv.h b/vlasov/zero/gkyl_dg_fpo_vlasov_diff_priv.h index 1402a7c174..3554e19a85 100644 --- a/vlasov/zero/gkyl_dg_fpo_vlasov_diff_priv.h +++ b/vlasov/zero/gkyl_dg_fpo_vlasov_diff_priv.h @@ -6,14 +6,21 @@ // functions // Types for various kernels -typedef double (*fpo_vlasov_diff_surf_t)(const double *w, const double *dx, - const double* g[27], const double *f[27], - double* GKYL_RESTRICT out); +typedef double (*fpo_vlasov_diff_surf_t)( + const double *w, const double *dx, const double *g[27], const double *f[27], + double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_fpo_vlasov_diff_vol_kern_list; -typedef struct { fpo_vlasov_diff_surf_t kernels[3]; } gkyl_dg_fpo_vlasov_diff_surf_kern_list; -typedef struct { fpo_vlasov_diff_surf_t kernels[3]; } gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_fpo_vlasov_diff_vol_kern_list; +typedef struct { + fpo_vlasov_diff_surf_t kernels[3]; +} gkyl_dg_fpo_vlasov_diff_surf_kern_list; +typedef struct { + fpo_vlasov_diff_surf_t kernels[3]; +} gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list; struct dg_fpo_vlasov_diff { struct gkyl_dg_eqn eqn; // Base object @@ -30,43 +37,43 @@ struct dg_fpo_vlasov_diff { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_fpo_vlasov_diff_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_fpo_vlasov_diff_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_fpo_vlasov_diff* fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); - + struct dg_fpo_vlasov_diff *fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); + long pidx = gkyl_range_idx(&fpo_vlasov_diff->phase_range, idx); - - return fpo_vlasov_diff_vol_1x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(fpo_vlasov_diff->auxfields.g, pidx), - qIn, qRhsOut); + + return fpo_vlasov_diff_vol_1x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(fpo_vlasov_diff->auxfields.g, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_fpo_vlasov_diff_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_fpo_vlasov_diff_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { - struct dg_fpo_vlasov_diff* fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); - + struct dg_fpo_vlasov_diff *fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); + long pidx = gkyl_range_idx(&fpo_vlasov_diff->phase_range, idx); - - return fpo_vlasov_diff_vol_1x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(fpo_vlasov_diff->auxfields.g, pidx), - qIn, qRhsOut); + + return fpo_vlasov_diff_vol_1x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(fpo_vlasov_diff->auxfields.g, pidx), qIn, qRhsOut + ); } // GKYL_CU_DH // static double -// kernel_fpo_vlasov_diff_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, +// kernel_fpo_vlasov_diff_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, // const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) // { // struct dg_fpo_vlasov_diff* fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); - + // long pidx = gkyl_range_idx(&fpo_vlasov_diff->phase_range, idx); - + // return fpo_vlasov_diff_vol_2x3v_ser_p1(xc, dx, // (const double*) gkyl_array_cfetch(fpo_vlasov_diff->auxfields.g, pidx), // qIn, qRhsOut); @@ -74,13 +81,13 @@ kernel_fpo_vlasov_diff_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const doub // GKYL_CU_DH // static double -// kernel_fpo_vlasov_diff_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, +// kernel_fpo_vlasov_diff_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, // const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) // { // struct dg_fpo_vlasov_diff* fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); - + // long pidx = gkyl_range_idx(&fpo_vlasov_diff->phase_range, idx); - + // return fpo_vlasov_diff_vol_2x3v_ser_p2(xc, dx, // (const double*) gkyl_array_cfetch(fpo_vlasov_diff->auxfields.g, pidx), // qIn, qRhsOut); @@ -88,220 +95,147 @@ kernel_fpo_vlasov_diff_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const doub // GKYL_CU_DH // static double -// kernel_fpo_vlasov_diff_vol_3x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, +// kernel_fpo_vlasov_diff_vol_3x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, // const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) // { // struct dg_fpo_vlasov_diff* fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); - + // long pidx = gkyl_range_idx(&fpo_vlasov_diff->phase_range, idx); - + // return fpo_vlasov_diff_vol_3x3v_ser_p1(xc, dx, // (const double*) gkyl_array_cfetch(fpo_vlasov_diff->auxfields.g, pidx), // qIn, qRhsOut); // } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_vol_kern_list ser_vol_kernels[] = { // { NULL, kernel_fpo_vlasov_diff_vol_1x3v_ser_p1, kernel_fpo_vlasov_diff_vol_1x3v_ser_p2 }, // 0 // { NULL, kernel_fpo_vlasov_diff_vol_2x3v_ser_p1, kernel_fpo_vlasov_diff_vol_2x3v_ser_p2 }, // 1 // { NULL, kernel_fpo_vlasov_diff_vol_3x3v_ser_p1, NULL }, // 2 - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL} }; // Surface kernel list: xx-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_xx_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_xx_kernels[] = + {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Surface kernel list: xy-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_xy_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_xy_kernels[] = + {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Surface kernel list: xz-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_xz_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_xz_kernels[] = + {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Surface kernel list: yx-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_yx_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_yx_kernels[] = + {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Surface kernel list: yy-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_yy_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_yy_kernels[] = + {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Surface kernel list: yz-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_yz_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_yz_kernels[] = + {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Surface kernel list: zx-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_zx_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_zx_kernels[] = + {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Surface kernel list: zy-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_zy_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_zy_kernels[] = + {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Surface kernel list: zz-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_zz_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_surf_kern_list ser_surf_zz_kernels[] = + {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Boundary Surface kernel list: xx-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_xx_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_xx_kernels[] = {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Boundary Surface kernel list: xy-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_xy_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_xy_kernels[] = {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Boundary Surface kernel list: xz-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_xz_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_xz_kernels[] = {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Boundary Surface kernel list: yx-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_yx_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_yx_kernels[] = {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Boundary Surface kernel list: yy-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_yy_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_yy_kernels[] = {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Boundary Surface kernel list: yz-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_yz_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_yz_kernels[] = {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Boundary Surface kernel list: zx-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_zx_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_zx_kernels[] = {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Boundary Surface kernel list: zy-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_zy_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_zy_kernels[] = {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; // Boundary Surface kernel list: zz-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_zz_kernels[] = { - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, -}; +GKYL_CU_D static const gkyl_dg_fpo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_zz_kernels[] = {{NULL, NULL, NULL}, {NULL, NULL, NULL}, {NULL, NULL, NULL}}; /** * Free fpo_vlasov_diff equation object * * @param ref Reference counter for constant fpo_vlasov_diff equation */ -void gkyl_fpo_vlasov_diff_free(const struct gkyl_ref_count* ref); - -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn* eqn, int dir1, int dir2, - const double* xc, const double* dxc, const int* idxc, - long sz_dim, const int idx[27][GKYL_MAX_DIM], const double* qIn[27], - double* GKYL_RESTRICT qRhsOut) +void gkyl_fpo_vlasov_diff_free(const struct gkyl_ref_count *ref); + +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir1, int dir2, const double *xc, const double *dxc, + const int *idxc, long sz_dim, const int idx[27][GKYL_MAX_DIM], const double *qIn[27], + double *GKYL_RESTRICT qRhsOut +) { - struct dg_fpo_vlasov_diff* fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); + struct dg_fpo_vlasov_diff *fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); int cdim = fpo_vlasov_diff->cdim; - const double* g_d[27]; - for (int i=0; iauxfields.g, - gkyl_range_idx(&fpo_vlasov_diff->phase_range, idx[i])); + const double *g_d[27]; + for (int i = 0; i < sz_dim; ++i) { + g_d[i] = (const double *)gkyl_array_cfetch( + fpo_vlasov_diff->auxfields.g, gkyl_range_idx(&fpo_vlasov_diff->phase_range, idx[i]) + ); } if (dir1 >= cdim && dir2 >= cdim) { - return fpo_vlasov_diff->surf[dir1-cdim][dir2-cdim](xc, dxc, g_d, qIn, qRhsOut); + return fpo_vlasov_diff->surf[dir1 - cdim][dir2 - cdim](xc, dxc, g_d, qIn, qRhsOut); } return 0.; } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn* eqn, int dir1, int dir2, - const double* xc, const double* dxc, const int* idxc, - long sz_dim, const int idx[27][GKYL_MAX_DIM], const double* qIn[27], - double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir1, int dir2, const double *xc, const double *dxc, + const int *idxc, long sz_dim, const int idx[27][GKYL_MAX_DIM], const double *qIn[27], + double *GKYL_RESTRICT qRhsOut +) { - struct dg_fpo_vlasov_diff* fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); + struct dg_fpo_vlasov_diff *fpo_vlasov_diff = container_of(eqn, struct dg_fpo_vlasov_diff, eqn); int cdim = fpo_vlasov_diff->cdim; - const double* g_d[27]; - for (int i=0; iauxfields.g, - gkyl_range_idx(&fpo_vlasov_diff->phase_range, idx[i])); + const double *g_d[27]; + for (int i = 0; i < sz_dim; ++i) { + if (idx[i]) { + g_d[i] = (const double *)gkyl_array_cfetch( + fpo_vlasov_diff->auxfields.g, gkyl_range_idx(&fpo_vlasov_diff->phase_range, idx[i]) + ); } } if (dir1 >= cdim && dir2 >= cdim) { - return fpo_vlasov_diff->surf[dir1-cdim][dir2-cdim](xc, dxc, g_d, qIn, qRhsOut); + return fpo_vlasov_diff->surf[dir1 - cdim][dir2 - cdim](xc, dxc, g_d, qIn, qRhsOut); } return 0.; } diff --git a/vlasov/zero/gkyl_dg_fpo_vlasov_drag.h b/vlasov/zero/gkyl_dg_fpo_vlasov_drag.h index 15dd577397..30e19c55be 100644 --- a/vlasov/zero/gkyl_dg_fpo_vlasov_drag.h +++ b/vlasov/zero/gkyl_dg_fpo_vlasov_drag.h @@ -17,7 +17,9 @@ struct gkyl_dg_fpo_vlasov_drag_auxfields { * @param phase_range phase space range for use in indexing drag flux term * @return Pointer to fpo equation object */ -struct gkyl_dg_eqn* gkyl_dg_fpo_vlasov_drag_new(const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_fpo_vlasov_drag_new( + const struct gkyl_basis *pbasis, const struct gkyl_range *phase_range, bool use_gpu +); /** * Create a new FPO drag equation object that lives on NV-GPU @@ -26,7 +28,9 @@ struct gkyl_dg_eqn* gkyl_dg_fpo_vlasov_drag_new(const struct gkyl_basis* pbasis, * @param phase_range phase space range for use in indexing drag flux term * @return Pointer to fpo equation object */ -struct gkyl_dg_eqn* gkyl_dg_fpo_vlasov_drag_cu_dev_new(const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range); +struct gkyl_dg_eqn *gkyl_dg_fpo_vlasov_drag_cu_dev_new( + const struct gkyl_basis *pbasis, const struct gkyl_range *phase_range +); /** * Set auxiliary fields needed in updating the drag flux term (a = grad(h), h solved for externally). @@ -34,7 +38,9 @@ struct gkyl_dg_eqn* gkyl_dg_fpo_vlasov_drag_cu_dev_new(const struct gkyl_basis* * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_fpo_vlasov_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_drag_auxfields auxin); +void gkyl_fpo_vlasov_drag_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_drag_auxfields auxin +); #ifdef GKYL_HAVE_CUDA @@ -44,6 +50,8 @@ void gkyl_fpo_vlasov_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gk * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_fpo_vlasov_drag_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_drag_auxfields auxin); +void gkyl_fpo_vlasov_drag_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_fpo_vlasov_drag_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_fpo_vlasov_drag_priv.h b/vlasov/zero/gkyl_dg_fpo_vlasov_drag_priv.h index 688ea74b02..5f89da3d8d 100644 --- a/vlasov/zero/gkyl_dg_fpo_vlasov_drag_priv.h +++ b/vlasov/zero/gkyl_dg_fpo_vlasov_drag_priv.h @@ -5,18 +5,26 @@ #include // Types for various kernels -typedef double (*fpo_vlasov_drag_surf_t)(const double *w, const double *dxv, - const double *h, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); +typedef double (*fpo_vlasov_drag_surf_t)( + const double *w, const double *dxv, const double *h, const double *fl, const double *fc, + const double *fr, double *GKYL_RESTRICT out +); -typedef double (*fpo_vlasov_drag_boundary_surf_t)(const double *w, const double *dxv, - const double *h, - const int edge, const double *fSkin, const double *fEdge, double* GKYL_RESTRICT out); +typedef double (*fpo_vlasov_drag_boundary_surf_t)( + const double *w, const double *dxv, const double *h, const int edge, const double *fSkin, + const double *fEdge, double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_fpo_vlasov_drag_vol_kern_list; -typedef struct { fpo_vlasov_drag_surf_t kernels[3]; } gkyl_dg_fpo_vlasov_drag_surf_kern_list; -typedef struct { fpo_vlasov_drag_boundary_surf_t kernels[3]; } gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_fpo_vlasov_drag_vol_kern_list; +typedef struct { + fpo_vlasov_drag_surf_t kernels[3]; +} gkyl_dg_fpo_vlasov_drag_surf_kern_list; +typedef struct { + fpo_vlasov_drag_boundary_surf_t kernels[3]; +} gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list; struct dg_fpo_vlasov_drag { struct gkyl_dg_eqn eqn; // Base object @@ -33,180 +41,172 @@ struct dg_fpo_vlasov_drag { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_fpo_vlasov_drag_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_fpo_vlasov_drag_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_fpo_vlasov_drag *fpo_vlasov_drag = container_of(eqn, struct dg_fpo_vlasov_drag, eqn); long pidx = gkyl_range_idx(&fpo_vlasov_drag->phase_range, idx); - return fpo_vlasov_drag_vol_1x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), - qIn, qRhsOut); + return fpo_vlasov_drag_vol_1x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_fpo_vlasov_drag_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_fpo_vlasov_drag_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_fpo_vlasov_drag *fpo_vlasov_drag = container_of(eqn, struct dg_fpo_vlasov_drag, eqn); long pidx = gkyl_range_idx(&fpo_vlasov_drag->phase_range, idx); - return fpo_vlasov_drag_vol_1x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), - qIn, qRhsOut); + return fpo_vlasov_drag_vol_1x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), qIn, qRhsOut + ); } // GKYL_CU_DH // static double -// kernel_fpo_vlasov_drag_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, +// kernel_fpo_vlasov_drag_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, // const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) // { // struct dg_fpo_vlasov_drag *fpo_vlasov_drag = container_of(eqn, struct dg_fpo_vlasov_drag, eqn); // long pidx = gkyl_range_idx(&fpo_vlasov_drag->phase_range, idx); -// return fpo_vlasov_drag_vol_2x3v_ser_p1(xc, dx, -// (const double*) gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), +// return fpo_vlasov_drag_vol_2x3v_ser_p1(xc, dx, +// (const double*) gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), // qIn, qRhsOut); // } // GKYL_CU_DH // static double -// kernel_fpo_vlasov_drag_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, +// kernel_fpo_vlasov_drag_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, // const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) // { // struct dg_fpo_vlasov_drag *fpo_vlasov_drag = container_of(eqn, struct dg_fpo_vlasov_drag, eqn); // long pidx = gkyl_range_idx(&fpo_vlasov_drag->phase_range, idx); -// return fpo_vlasov_drag_vol_2x3v_ser_p2(xc, dx, -// (const double*) gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), +// return fpo_vlasov_drag_vol_2x3v_ser_p2(xc, dx, +// (const double*) gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), // qIn, qRhsOut); // } // GKYL_CU_DH // static double -// kernel_fpo_vlasov_drag_vol_3x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, +// kernel_fpo_vlasov_drag_vol_3x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, // const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) // { // struct dg_fpo_vlasov_drag *fpo_vlasov_drag = container_of(eqn, struct dg_fpo_vlasov_drag, eqn); // long pidx = gkyl_range_idx(&fpo_vlasov_drag->phase_range, idx); -// return fpo_vlasov_drag_vol_3x3v_ser_p1(xc, dx, -// (const double*) gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), +// return fpo_vlasov_drag_vol_3x3v_ser_p1(xc, dx, +// (const double*) gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), // qIn, qRhsOut); // } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_drag_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_fpo_vlasov_drag_vol_kern_list ser_vol_kernels[] = { // { NULL, kernel_fpo_vlasov_drag_vol_1x3v_ser_p1, kernel_fpo_vlasov_drag_vol_1x3v_ser_p2 }, // 0 // { NULL, kernel_fpo_vlasov_drag_vol_2x3v_ser_p1, kernel_fpo_vlasov_drag_vol_2x3v_ser_p2 }, // 1 // { NULL, kernel_fpo_vlasov_drag_vol_3x3v_ser_p1, NULL }, // 2 - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL} }; // Surface kernel list: vx-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_drag_surf_kern_list ser_surf_vx_kernels[] = { +GKYL_CU_D static const gkyl_dg_fpo_vlasov_drag_surf_kern_list ser_surf_vx_kernels[] = { // { NULL, fpo_vlasov_drag_surfvx_1x3v_ser_p1, fpo_vlasov_drag_surfvx_1x3v_ser_p2 }, // 0 // { NULL, fpo_vlasov_drag_surfvx_2x3v_ser_p1, fpo_vlasov_drag_surfvx_2x3v_ser_p2 }, // 1 // { NULL, fpo_vlasov_drag_surfvx_3x3v_ser_p1, NULL }, // 2 - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL} }; // Surface kernel list: vy-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_drag_surf_kern_list ser_surf_vy_kernels[] = { +GKYL_CU_D static const gkyl_dg_fpo_vlasov_drag_surf_kern_list ser_surf_vy_kernels[] = { // { NULL, fpo_vlasov_drag_surfvy_1x3v_ser_p1, fpo_vlasov_drag_surfvy_1x3v_ser_p2 }, // 0 // { NULL, fpo_vlasov_drag_surfvy_2x3v_ser_p1, fpo_vlasov_drag_surfvy_2x3v_ser_p2 }, // 1 // { NULL, fpo_vlasov_drag_surfvy_3x3v_ser_p1, NULL }, // 2 - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL} }; // Surface kernel list: vz-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_drag_surf_kern_list ser_surf_vz_kernels[] = { +GKYL_CU_D static const gkyl_dg_fpo_vlasov_drag_surf_kern_list ser_surf_vz_kernels[] = { // { NULL, fpo_vlasov_drag_surfvz_1x3v_ser_p1, fpo_vlasov_drag_surfvz_1x3v_ser_p2 }, // 0 // { NULL, fpo_vlasov_drag_surfvz_2x3v_ser_p1, fpo_vlasov_drag_surfvz_2x3v_ser_p2 }, // 1 // { NULL, fpo_vlasov_drag_surfvz_3x3v_ser_p1, NULL }, // 2 - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL} }; // Boundary Surface kernel list: vx-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list ser_boundary_surf_vx_kernels[] = { - // { NULL, fpo_vlasov_drag_boundary_surfvx_1x3v_ser_p1, fpo_vlasov_drag_boundary_surfvx_1x3v_ser_p2 }, // 0 - // { NULL, fpo_vlasov_drag_boundary_surfvx_2x3v_ser_p1, fpo_vlasov_drag_boundary_surfvx_2x3v_ser_p2 }, // 1 - // { NULL, fpo_vlasov_drag_boundary_surfvx_3x3v_ser_p1, NULL }, // 2 - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, +GKYL_CU_D static const gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list + ser_boundary_surf_vx_kernels[] = { + // { NULL, fpo_vlasov_drag_boundary_surfvx_1x3v_ser_p1, fpo_vlasov_drag_boundary_surfvx_1x3v_ser_p2 }, // 0 + // { NULL, fpo_vlasov_drag_boundary_surfvx_2x3v_ser_p1, fpo_vlasov_drag_boundary_surfvx_2x3v_ser_p2 }, // 1 + // { NULL, fpo_vlasov_drag_boundary_surfvx_3x3v_ser_p1, NULL }, // 2 + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL} }; // Boundary Surface kernel list: vy-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list ser_boundary_surf_vy_kernels[] = { - // { NULL, fpo_vlasov_drag_boundary_surfvy_1x3v_ser_p1, fpo_vlasov_drag_boundary_surfvy_1x3v_ser_p2 }, // 0 - // { NULL, fpo_vlasov_drag_boundary_surfvy_2x3v_ser_p1, fpo_vlasov_drag_boundary_surfvy_2x3v_ser_p2 }, // 1 - // { NULL, fpo_vlasov_drag_boundary_surfvy_3x3v_ser_p1, NULL }, // 2 - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, +GKYL_CU_D static const gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list + ser_boundary_surf_vy_kernels[] = { + // { NULL, fpo_vlasov_drag_boundary_surfvy_1x3v_ser_p1, fpo_vlasov_drag_boundary_surfvy_1x3v_ser_p2 }, // 0 + // { NULL, fpo_vlasov_drag_boundary_surfvy_2x3v_ser_p1, fpo_vlasov_drag_boundary_surfvy_2x3v_ser_p2 }, // 1 + // { NULL, fpo_vlasov_drag_boundary_surfvy_3x3v_ser_p1, NULL }, // 2 + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL} }; // Boundary Surface kernel list: vz-direction -GKYL_CU_D -static const gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list ser_boundary_surf_vz_kernels[] = { - // { NULL, fpo_vlasov_drag_boundary_surfvz_1x3v_ser_p1, fpo_vlasov_drag_boundary_surfvz_1x3v_ser_p2 }, // 0 - // { NULL, fpo_vlasov_drag_boundary_surfvz_2x3v_ser_p1, fpo_vlasov_drag_boundary_surfvz_2x3v_ser_p2 }, // 1 - // { NULL, fpo_vlasov_drag_boundary_surfvz_3x3v_ser_p1, NULL }, // 2 - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, - { NULL, NULL, NULL }, +GKYL_CU_D static const gkyl_dg_fpo_vlasov_drag_boundary_surf_kern_list + ser_boundary_surf_vz_kernels[] = { + // { NULL, fpo_vlasov_drag_boundary_surfvz_1x3v_ser_p1, fpo_vlasov_drag_boundary_surfvz_1x3v_ser_p2 }, // 0 + // { NULL, fpo_vlasov_drag_boundary_surfvz_2x3v_ser_p1, fpo_vlasov_drag_boundary_surfvz_2x3v_ser_p2 }, // 1 + // { NULL, fpo_vlasov_drag_boundary_surfvz_3x3v_ser_p1, NULL }, // 2 + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {NULL, NULL, NULL} }; -void gkyl_fpo_vlasov_drag_free(const struct gkyl_ref_count* ref); +void gkyl_fpo_vlasov_drag_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_fpo_vlasov_drag *fpo_vlasov_drag = container_of(eqn, struct dg_fpo_vlasov_drag, eqn); long pidx = gkyl_range_idx(&fpo_vlasov_drag->phase_range, idxC); if (dir >= fpo_vlasov_drag->cdim) { - return fpo_vlasov_drag->surf[dir-fpo_vlasov_drag->cdim](xcC, dxC, - (const double*) gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), - qInL, qInC, qInR, qRhsOut); + return fpo_vlasov_drag->surf[dir - fpo_vlasov_drag->cdim]( + xcC, dxC, (const double *)gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), qInL, qInC, + qInR, qRhsOut + ); } return 0.; } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_fpo_vlasov_drag *fpo_vlasov_drag = container_of(eqn, struct dg_fpo_vlasov_drag, eqn); long pidx = gkyl_range_idx(&fpo_vlasov_drag->phase_range, idxSkin); if (dir >= fpo_vlasov_drag->cdim) { - return fpo_vlasov_drag->boundary_surf[dir-fpo_vlasov_drag->cdim](xcSkin, dxSkin, - (const double*) gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), - edge, qInSkin, qInEdge, qRhsOut); + return fpo_vlasov_drag->boundary_surf[dir - fpo_vlasov_drag->cdim]( + xcSkin, dxSkin, (const double *)gkyl_array_cfetch(fpo_vlasov_drag->auxfields.h, pidx), edge, + qInSkin, qInEdge, qRhsOut + ); } return 0.; } - diff --git a/vlasov/zero/gkyl_dg_lbo_vlasov_diff.h b/vlasov/zero/gkyl_dg_lbo_vlasov_diff.h index 838d807ef1..71fbb89a75 100644 --- a/vlasov/zero/gkyl_dg_lbo_vlasov_diff.h +++ b/vlasov/zero/gkyl_dg_lbo_vlasov_diff.h @@ -7,7 +7,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_lbo_vlasov_diff_auxfields { +struct gkyl_dg_lbo_vlasov_diff_auxfields { const struct gkyl_array *nuSum; const struct gkyl_array *nuPrimMomsSum; }; @@ -21,9 +21,10 @@ struct gkyl_dg_lbo_vlasov_diff_auxfields { * @param pgrid Phase-space grid object. * @return Pointer to LBO equation object */ -struct gkyl_dg_eqn* gkyl_dg_lbo_vlasov_diff_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - const struct gkyl_rect_grid *pgrid, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_lbo_vlasov_diff_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu +); /** * Create a new LBO equation object that lives on NV-GPU @@ -34,8 +35,10 @@ struct gkyl_dg_eqn* gkyl_dg_lbo_vlasov_diff_new(const struct gkyl_basis* cbasis, * @param pgrid Phase-space grid object. * @return Pointer to LBO equation object */ -struct gkyl_dg_eqn* gkyl_dg_lbo_vlasov_diff_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid); +struct gkyl_dg_eqn *gkyl_dg_lbo_vlasov_diff_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +); /** * Set auxiliary fields needed in updating the diffusion flux term. @@ -44,7 +47,9 @@ struct gkyl_dg_eqn* gkyl_dg_lbo_vlasov_diff_cu_dev_new(const struct gkyl_basis* * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_lbo_vlasov_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_diff_auxfields auxin); +void gkyl_lbo_vlasov_diff_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_diff_auxfields auxin +); #ifdef GKYL_HAVE_CUDA @@ -55,6 +60,8 @@ void gkyl_lbo_vlasov_diff_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gk * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_lbo_vlasov_diff_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_diff_auxfields auxin); +void gkyl_lbo_vlasov_diff_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_diff_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_lbo_vlasov_diff_priv.h b/vlasov/zero/gkyl_dg_lbo_vlasov_diff_priv.h index f972693a2c..dded973161 100644 --- a/vlasov/zero/gkyl_dg_lbo_vlasov_diff_priv.h +++ b/vlasov/zero/gkyl_dg_lbo_vlasov_diff_priv.h @@ -5,27 +5,37 @@ #include // Types for various kernels -typedef double (*lbo_vlasov_diff_surf_t)(const double *w, const double *dxv, - const double *nuSum, const double *nuPrimMomsSum, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); +typedef double (*lbo_vlasov_diff_surf_t)( + const double *w, const double *dxv, const double *nuSum, const double *nuPrimMomsSum, + const double *fl, const double *fc, const double *fr, double *GKYL_RESTRICT out +); -typedef double (*lbo_vlasov_diff_boundary_surf_t)(const double *w, const double *dxv, - const double *nuSum, const double *nuPrimMomsSum, - const int edge, const double *fSkin, const double *fEdge, double* GKYL_RESTRICT out); +typedef double (*lbo_vlasov_diff_boundary_surf_t)( + const double *w, const double *dxv, const double *nuSum, const double *nuPrimMomsSum, + const int edge, const double *fSkin, const double *fEdge, double *GKYL_RESTRICT out +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_lbo_vlasov_diff_vol_kern_list; -typedef struct { lbo_vlasov_diff_surf_t kernels[3]; } gkyl_dg_lbo_vlasov_diff_surf_kern_list; -typedef struct { lbo_vlasov_diff_boundary_surf_t kernels[3]; } gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_lbo_vlasov_diff_vol_kern_list; +typedef struct { + lbo_vlasov_diff_surf_t kernels[3]; +} gkyl_dg_lbo_vlasov_diff_surf_kern_list; +typedef struct { + lbo_vlasov_diff_boundary_surf_t kernels[3]; +} gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list; // "Choose Kernel" based on cdim, vdim and polyorder #define CK(lst, cdim, vd, poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] @@ -43,19 +53,20 @@ struct dg_lbo_vlasov_diff { int num_cbasis; }; -GKYL_CU_DH -static inline bool -checkPrimMomCross(struct dg_lbo_vlasov_diff *lbo_vlasov_diff, - const double* nuSum_p, const double* nuUSum_p, const double* nuVtSqSum_p) { +GKYL_CU_DH static inline bool checkPrimMomCross( + struct dg_lbo_vlasov_diff *lbo_vlasov_diff, const double *nuSum_p, const double *nuUSum_p, + const double *nuVtSqSum_p +) +{ bool noPrimMomCross = true; - for (int d=0; dvdim; d++) { - if (fabs(nuUSum_p[d*lbo_vlasov_diff->num_cbasis]/nuSum_p[0]) > lbo_vlasov_diff->viMax[d]) { - noPrimMomCross = false; - break; + for (int d = 0; d < lbo_vlasov_diff->vdim; d++) { + if (fabs(nuUSum_p[d * lbo_vlasov_diff->num_cbasis] / nuSum_p[0]) > lbo_vlasov_diff->viMax[d]) { + noPrimMomCross = false; + break; } } - noPrimMomCross = noPrimMomCross && ((nuVtSqSum_p[0]>0.) - && (nuVtSqSum_p[0]/nuSum_p[0] < lbo_vlasov_diff->vMaxSq)); + noPrimMomCross = noPrimMomCross && ((nuVtSqSum_p[0] > 0.) && + (nuVtSqSum_p[0] / nuSum_p[0] < lbo_vlasov_diff->vMaxSq)); return noPrimMomCross; } @@ -64,369 +75,374 @@ checkPrimMomCross(struct dg_lbo_vlasov_diff *lbo_vlasov_diff, // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_lbo_vlasov_diff_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_diff_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_diff_vol_1x1v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_diff_vol_1x1v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_diff_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_diff_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_diff_vol_1x1v_ser_p2(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_diff_vol_1x1v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_diff_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_diff_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_diff_vol_1x2v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_diff_vol_1x2v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_diff_vol_1x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_diff_vol_1x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_diff_vol_1x2v_ser_p2(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_diff_vol_1x2v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_diff_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_diff_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_diff_vol_1x3v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_diff_vol_1x3v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_diff_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_diff_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_diff_vol_1x3v_ser_p2(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_diff_vol_1x3v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_diff_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_diff_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_diff_vol_2x2v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_diff_vol_2x2v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_diff_vol_2x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_diff_vol_2x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_diff_vol_2x2v_ser_p2(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_diff_vol_2x2v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_diff_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_diff_vol_2x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_diff_vol_2x3v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_diff_vol_2x3v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_diff_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_diff_vol_2x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_diff_vol_2x3v_ser_p2(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_diff_vol_2x3v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_diff_vol_3x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_diff_vol_3x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_diff_vol_3x3v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_diff_vol_3x3v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_diff_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_vlasov_diff_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, kernel_lbo_vlasov_diff_vol_1x1v_ser_p1, kernel_lbo_vlasov_diff_vol_1x1v_ser_p2 }, // 0 - { NULL, kernel_lbo_vlasov_diff_vol_1x2v_ser_p1, kernel_lbo_vlasov_diff_vol_1x2v_ser_p2 }, // 1 - { NULL, kernel_lbo_vlasov_diff_vol_1x3v_ser_p1, kernel_lbo_vlasov_diff_vol_1x3v_ser_p2 }, // 2 + {NULL, kernel_lbo_vlasov_diff_vol_1x1v_ser_p1, kernel_lbo_vlasov_diff_vol_1x1v_ser_p2}, // 0 + {NULL, kernel_lbo_vlasov_diff_vol_1x2v_ser_p1, kernel_lbo_vlasov_diff_vol_1x2v_ser_p2}, // 1 + {NULL, kernel_lbo_vlasov_diff_vol_1x3v_ser_p1, kernel_lbo_vlasov_diff_vol_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_lbo_vlasov_diff_vol_2x2v_ser_p1, kernel_lbo_vlasov_diff_vol_2x2v_ser_p2 }, // 3 - { NULL, kernel_lbo_vlasov_diff_vol_2x3v_ser_p1, kernel_lbo_vlasov_diff_vol_2x3v_ser_p2 }, // 4 + {NULL, kernel_lbo_vlasov_diff_vol_2x2v_ser_p1, kernel_lbo_vlasov_diff_vol_2x2v_ser_p2}, // 3 + {NULL, kernel_lbo_vlasov_diff_vol_2x3v_ser_p1, kernel_lbo_vlasov_diff_vol_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_lbo_vlasov_diff_vol_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_lbo_vlasov_diff_vol_3x3v_ser_p1, NULL} // 5 }; // Constant nu surface kernel list: vx-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_diff_surf_kern_list ser_surf_vx_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_vlasov_diff_surf_kern_list ser_surf_vx_kernels[] = { // 1x kernels - { NULL, lbo_vlasov_diff_surfvx_1x1v_ser_p1, lbo_vlasov_diff_surfvx_1x1v_ser_p2 }, // 0 - { NULL, lbo_vlasov_diff_surfvx_1x2v_ser_p1, lbo_vlasov_diff_surfvx_1x2v_ser_p2 }, // 1 - { NULL, lbo_vlasov_diff_surfvx_1x3v_ser_p1, lbo_vlasov_diff_surfvx_1x3v_ser_p2 }, // 2 + {NULL, lbo_vlasov_diff_surfvx_1x1v_ser_p1, lbo_vlasov_diff_surfvx_1x1v_ser_p2}, // 0 + {NULL, lbo_vlasov_diff_surfvx_1x2v_ser_p1, lbo_vlasov_diff_surfvx_1x2v_ser_p2}, // 1 + {NULL, lbo_vlasov_diff_surfvx_1x3v_ser_p1, lbo_vlasov_diff_surfvx_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, lbo_vlasov_diff_surfvx_2x2v_ser_p1, lbo_vlasov_diff_surfvx_2x2v_ser_p2 }, // 3 - { NULL, lbo_vlasov_diff_surfvx_2x3v_ser_p1, lbo_vlasov_diff_surfvx_2x3v_ser_p2 }, // + {NULL, lbo_vlasov_diff_surfvx_2x2v_ser_p1, lbo_vlasov_diff_surfvx_2x2v_ser_p2}, // 3 + {NULL, lbo_vlasov_diff_surfvx_2x3v_ser_p1, lbo_vlasov_diff_surfvx_2x3v_ser_p2}, // // 3x kernels - { NULL, lbo_vlasov_diff_surfvx_3x3v_ser_p1, NULL }, // 5 + {NULL, lbo_vlasov_diff_surfvx_3x3v_ser_p1, NULL} // 5 }; // Constant nu surface kernel list: vy-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_diff_surf_kern_list ser_surf_vy_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_vlasov_diff_surf_kern_list ser_surf_vy_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, lbo_vlasov_diff_surfvy_1x2v_ser_p1, lbo_vlasov_diff_surfvy_1x2v_ser_p2 }, // 1 - { NULL, lbo_vlasov_diff_surfvy_1x3v_ser_p1, lbo_vlasov_diff_surfvy_1x3v_ser_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, lbo_vlasov_diff_surfvy_1x2v_ser_p1, lbo_vlasov_diff_surfvy_1x2v_ser_p2}, // 1 + {NULL, lbo_vlasov_diff_surfvy_1x3v_ser_p1, lbo_vlasov_diff_surfvy_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, lbo_vlasov_diff_surfvy_2x2v_ser_p1, lbo_vlasov_diff_surfvy_2x2v_ser_p2 }, // 3 - { NULL, lbo_vlasov_diff_surfvy_2x3v_ser_p1, lbo_vlasov_diff_surfvy_2x3v_ser_p2 }, // 4 + {NULL, lbo_vlasov_diff_surfvy_2x2v_ser_p1, lbo_vlasov_diff_surfvy_2x2v_ser_p2}, // 3 + {NULL, lbo_vlasov_diff_surfvy_2x3v_ser_p1, lbo_vlasov_diff_surfvy_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, lbo_vlasov_diff_surfvy_3x3v_ser_p1, NULL }, // 5 + {NULL, lbo_vlasov_diff_surfvy_3x3v_ser_p1, NULL} // 5 }; // Constant nu surface kernel list: vz-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_diff_surf_kern_list ser_surf_vz_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_vlasov_diff_surf_kern_list ser_surf_vz_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, lbo_vlasov_diff_surfvz_1x3v_ser_p1, lbo_vlasov_diff_surfvz_1x3v_ser_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, lbo_vlasov_diff_surfvz_1x3v_ser_p1, lbo_vlasov_diff_surfvz_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, lbo_vlasov_diff_surfvz_2x3v_ser_p1, lbo_vlasov_diff_surfvz_2x3v_ser_p2 }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, lbo_vlasov_diff_surfvz_2x3v_ser_p1, lbo_vlasov_diff_surfvz_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, lbo_vlasov_diff_surfvz_3x3v_ser_p1, NULL }, // 5 + {NULL, lbo_vlasov_diff_surfvz_3x3v_ser_p1, NULL} // 5 }; // Constant nu boundary surface kernel (zero-flux BCs) list: vx-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_vx_kernels[] = { - // 1x kernels - { NULL, lbo_vlasov_diff_boundary_surfvx_1x1v_ser_p1, lbo_vlasov_diff_boundary_surfvx_1x1v_ser_p2 }, // 0 - { NULL, lbo_vlasov_diff_boundary_surfvx_1x2v_ser_p1, lbo_vlasov_diff_boundary_surfvx_1x2v_ser_p2 }, // 1 - { NULL, lbo_vlasov_diff_boundary_surfvx_1x3v_ser_p1, lbo_vlasov_diff_boundary_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, lbo_vlasov_diff_boundary_surfvx_2x2v_ser_p1, lbo_vlasov_diff_boundary_surfvx_2x2v_ser_p2 }, // 3 - { NULL, lbo_vlasov_diff_boundary_surfvx_2x3v_ser_p1, lbo_vlasov_diff_boundary_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, lbo_vlasov_diff_boundary_surfvx_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_vx_kernels[] = { + // 1x kernels + {NULL, lbo_vlasov_diff_boundary_surfvx_1x1v_ser_p1, lbo_vlasov_diff_boundary_surfvx_1x1v_ser_p2 + }, // 0 + {NULL, lbo_vlasov_diff_boundary_surfvx_1x2v_ser_p1, lbo_vlasov_diff_boundary_surfvx_1x2v_ser_p2 + }, // 1 + {NULL, lbo_vlasov_diff_boundary_surfvx_1x3v_ser_p1, lbo_vlasov_diff_boundary_surfvx_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, lbo_vlasov_diff_boundary_surfvx_2x2v_ser_p1, lbo_vlasov_diff_boundary_surfvx_2x2v_ser_p2 + }, // 3 + {NULL, lbo_vlasov_diff_boundary_surfvx_2x3v_ser_p1, lbo_vlasov_diff_boundary_surfvx_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, lbo_vlasov_diff_boundary_surfvx_3x3v_ser_p1, NULL} // 5 }; // Constant nu boundary surface kernel (zero-flux BCs) list: vy-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, lbo_vlasov_diff_boundary_surfvy_1x2v_ser_p1, lbo_vlasov_diff_boundary_surfvy_1x2v_ser_p2 }, // 1 - { NULL, lbo_vlasov_diff_boundary_surfvy_1x3v_ser_p1, lbo_vlasov_diff_boundary_surfvy_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, lbo_vlasov_diff_boundary_surfvy_2x2v_ser_p1, lbo_vlasov_diff_boundary_surfvy_2x2v_ser_p2 }, // 3 - { NULL, lbo_vlasov_diff_boundary_surfvy_2x3v_ser_p1, lbo_vlasov_diff_boundary_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, lbo_vlasov_diff_boundary_surfvy_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, lbo_vlasov_diff_boundary_surfvy_1x2v_ser_p1, lbo_vlasov_diff_boundary_surfvy_1x2v_ser_p2 + }, // 1 + {NULL, lbo_vlasov_diff_boundary_surfvy_1x3v_ser_p1, lbo_vlasov_diff_boundary_surfvy_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, lbo_vlasov_diff_boundary_surfvy_2x2v_ser_p1, lbo_vlasov_diff_boundary_surfvy_2x2v_ser_p2 + }, // 3 + {NULL, lbo_vlasov_diff_boundary_surfvy_2x3v_ser_p1, lbo_vlasov_diff_boundary_surfvy_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, lbo_vlasov_diff_boundary_surfvy_3x3v_ser_p1, NULL} // 5 }; // Constant nu boundary surface kernel (zero-flux BCs) list: vz-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list ser_boundary_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, lbo_vlasov_diff_boundary_surfvz_1x3v_ser_p1, lbo_vlasov_diff_boundary_surfvz_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, lbo_vlasov_diff_boundary_surfvz_2x3v_ser_p1, lbo_vlasov_diff_boundary_surfvz_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, lbo_vlasov_diff_boundary_surfvz_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_lbo_vlasov_diff_boundary_surf_kern_list + ser_boundary_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, lbo_vlasov_diff_boundary_surfvz_1x3v_ser_p1, lbo_vlasov_diff_boundary_surfvz_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, lbo_vlasov_diff_boundary_surfvz_2x3v_ser_p1, lbo_vlasov_diff_boundary_surfvz_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, lbo_vlasov_diff_boundary_surfvz_3x3v_ser_p1, NULL} // 5 }; -void gkyl_lbo_vlasov_diff_free(const struct gkyl_ref_count* ref); +void gkyl_lbo_vlasov_diff_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idxC); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if ((dir >= lbo_vlasov_diff->cdim) && (noPrimMomCross)) { - return lbo_vlasov_diff->surf[dir-lbo_vlasov_diff->cdim](xcC, dxC, - nuSum_p, nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut); + return lbo_vlasov_diff->surf[dir - lbo_vlasov_diff->cdim]( + xcC, dxC, nuSum_p, nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut + ); } return 0.; } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_diff *lbo_vlasov_diff = container_of(eqn, struct dg_lbo_vlasov_diff, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_diff->conf_range, idxSkin); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim*lbo_vlasov_diff->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_diff->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_diff->vdim * lbo_vlasov_diff->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_diff, nuSum_p, nuUSum_p, nuVtSqSum_p); if ((dir >= lbo_vlasov_diff->cdim) && (noPrimMomCross)) { - return lbo_vlasov_diff->boundary_surf[dir-lbo_vlasov_diff->cdim](xcSkin, dxSkin, - nuSum_p, nuPrimMomsSum_p, edge, qInSkin, qInEdge, qRhsOut); + return lbo_vlasov_diff->boundary_surf[dir - lbo_vlasov_diff->cdim]( + xcSkin, dxSkin, nuSum_p, nuPrimMomsSum_p, edge, qInSkin, qInEdge, qRhsOut + ); } return 0.; } - diff --git a/vlasov/zero/gkyl_dg_lbo_vlasov_drag.h b/vlasov/zero/gkyl_dg_lbo_vlasov_drag.h index 9c5c3b16cc..f4fa008ac4 100644 --- a/vlasov/zero/gkyl_dg_lbo_vlasov_drag.h +++ b/vlasov/zero/gkyl_dg_lbo_vlasov_drag.h @@ -21,9 +21,10 @@ struct gkyl_dg_lbo_vlasov_drag_auxfields { * @param pgrid Phase-space grid object. * @return Pointer to LBO equation object */ -struct gkyl_dg_eqn* gkyl_dg_lbo_vlasov_drag_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - const struct gkyl_rect_grid *pgrid, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_lbo_vlasov_drag_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid, bool use_gpu +); /** * Create a new LBO equation object that lives on NV-GPU @@ -34,8 +35,10 @@ struct gkyl_dg_eqn* gkyl_dg_lbo_vlasov_drag_new(const struct gkyl_basis* cbasis, * @param pgrid Phase-space grid object. * @return Pointer to LBO equation object */ -struct gkyl_dg_eqn* gkyl_dg_lbo_vlasov_drag_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, const struct gkyl_rect_grid *pgrid); +struct gkyl_dg_eqn *gkyl_dg_lbo_vlasov_drag_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_rect_grid *pgrid +); /** * Set auxiliary fields needed in updating the drag flux term. @@ -44,7 +47,9 @@ struct gkyl_dg_eqn* gkyl_dg_lbo_vlasov_drag_cu_dev_new(const struct gkyl_basis* * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_lbo_vlasov_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_drag_auxfields auxin); +void gkyl_lbo_vlasov_drag_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_drag_auxfields auxin +); #ifdef GKYL_HAVE_CUDA @@ -55,6 +60,8 @@ void gkyl_lbo_vlasov_drag_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gk * @param eqn Equation pointer * @param auxfields Pointer to struct of aux fields. */ -void gkyl_lbo_vlasov_drag_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_drag_auxfields auxin); +void gkyl_lbo_vlasov_drag_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_lbo_vlasov_drag_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_lbo_vlasov_drag_priv.h b/vlasov/zero/gkyl_dg_lbo_vlasov_drag_priv.h index 8460ac5cf4..b35a1f0c05 100644 --- a/vlasov/zero/gkyl_dg_lbo_vlasov_drag_priv.h +++ b/vlasov/zero/gkyl_dg_lbo_vlasov_drag_priv.h @@ -5,27 +5,37 @@ #include // Types for various kernels -typedef double (*lbo_vlasov_drag_surf_t)(const double *w, const double *dxv, - const double *nuSum, const double *nuPrimMomsSum, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); +typedef double (*lbo_vlasov_drag_surf_t)( + const double *w, const double *dxv, const double *nuSum, const double *nuPrimMomsSum, + const double *fl, const double *fc, const double *fr, double *GKYL_RESTRICT out +); -typedef double (*lbo_vlasov_drag_boundary_surf_t)(const double *w, const double *dxv, - const double *nuSum, const double *nuPrimMomsSum, - const int edge, const double *fSkin, const double *fEdge, double* GKYL_RESTRICT out); +typedef double (*lbo_vlasov_drag_boundary_surf_t)( + const double *w, const double *dxv, const double *nuSum, const double *nuPrimMomsSum, + const int edge, const double *fSkin, const double *fEdge, double *GKYL_RESTRICT out +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_lbo_vlasov_drag_vol_kern_list; -typedef struct { lbo_vlasov_drag_surf_t kernels[3]; } gkyl_dg_lbo_vlasov_drag_surf_kern_list; -typedef struct { lbo_vlasov_drag_boundary_surf_t kernels[3]; } gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_lbo_vlasov_drag_vol_kern_list; +typedef struct { + lbo_vlasov_drag_surf_t kernels[3]; +} gkyl_dg_lbo_vlasov_drag_surf_kern_list; +typedef struct { + lbo_vlasov_drag_boundary_surf_t kernels[3]; +} gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list; // "Choose Kernel" based on cdim, vdim and polyorder #define CK(lst, cdim, vd, poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] @@ -43,19 +53,20 @@ struct dg_lbo_vlasov_drag { int num_cbasis; }; -GKYL_CU_DH -static inline bool -checkPrimMomCross(struct dg_lbo_vlasov_drag *lbo_vlasov_drag, - const double* nuSum_p, const double* nuUSum_p, const double* nuVtSqSum_p) { +GKYL_CU_DH static inline bool checkPrimMomCross( + struct dg_lbo_vlasov_drag *lbo_vlasov_drag, const double *nuSum_p, const double *nuUSum_p, + const double *nuVtSqSum_p +) +{ bool noPrimMomCross = true; - for (int d=0; dvdim; d++) { - if (fabs(nuUSum_p[d*lbo_vlasov_drag->num_cbasis]/nuSum_p[0]) > lbo_vlasov_drag->viMax[d]) { - noPrimMomCross = false; - break; + for (int d = 0; d < lbo_vlasov_drag->vdim; d++) { + if (fabs(nuUSum_p[d * lbo_vlasov_drag->num_cbasis] / nuSum_p[0]) > lbo_vlasov_drag->viMax[d]) { + noPrimMomCross = false; + break; } } - noPrimMomCross = noPrimMomCross && ((nuVtSqSum_p[0]>0.) - && (nuVtSqSum_p[0]/nuSum_p[0] < lbo_vlasov_drag->vMaxSq)); + noPrimMomCross = noPrimMomCross && ((nuVtSqSum_p[0] > 0.) && + (nuVtSqSum_p[0] / nuSum_p[0] < lbo_vlasov_drag->vMaxSq)); return noPrimMomCross; } @@ -64,369 +75,374 @@ checkPrimMomCross(struct dg_lbo_vlasov_drag *lbo_vlasov_drag, // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_lbo_vlasov_drag_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_drag_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_drag_vol_1x1v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_drag_vol_1x1v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_drag_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_drag_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_drag_vol_1x1v_ser_p2(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_drag_vol_1x1v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_drag_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_drag_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_drag_vol_1x2v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_drag_vol_1x2v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_drag_vol_1x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_drag_vol_1x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_drag_vol_1x2v_ser_p2(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_drag_vol_1x2v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_drag_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_drag_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_drag_vol_1x3v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_drag_vol_1x3v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_drag_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_drag_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_drag_vol_1x3v_ser_p2(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_drag_vol_1x3v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_drag_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_drag_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_drag_vol_2x2v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_drag_vol_2x2v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_drag_vol_2x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_drag_vol_2x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_drag_vol_2x2v_ser_p2(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_drag_vol_2x2v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_drag_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_drag_vol_2x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_drag_vol_2x3v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_drag_vol_2x3v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_drag_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_drag_vol_2x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_drag_vol_2x3v_ser_p2(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_drag_vol_2x3v_ser_p2(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } -GKYL_CU_DH -static double -kernel_lbo_vlasov_drag_vol_3x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_lbo_vlasov_drag_vol_3x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idx); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if (noPrimMomCross) { - return lbo_vlasov_drag_vol_3x3v_ser_p1(xc, dx, - nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); + return lbo_vlasov_drag_vol_3x3v_ser_p1(xc, dx, nuSum_p, nuPrimMomsSum_p, qIn, qRhsOut); } else { return 0.; } } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_drag_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_vlasov_drag_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, kernel_lbo_vlasov_drag_vol_1x1v_ser_p1, kernel_lbo_vlasov_drag_vol_1x1v_ser_p2 }, // 0 - { NULL, kernel_lbo_vlasov_drag_vol_1x2v_ser_p1, kernel_lbo_vlasov_drag_vol_1x2v_ser_p2 }, // 1 - { NULL, kernel_lbo_vlasov_drag_vol_1x3v_ser_p1, kernel_lbo_vlasov_drag_vol_1x3v_ser_p2 }, // 2 + {NULL, kernel_lbo_vlasov_drag_vol_1x1v_ser_p1, kernel_lbo_vlasov_drag_vol_1x1v_ser_p2}, // 0 + {NULL, kernel_lbo_vlasov_drag_vol_1x2v_ser_p1, kernel_lbo_vlasov_drag_vol_1x2v_ser_p2}, // 1 + {NULL, kernel_lbo_vlasov_drag_vol_1x3v_ser_p1, kernel_lbo_vlasov_drag_vol_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_lbo_vlasov_drag_vol_2x2v_ser_p1, kernel_lbo_vlasov_drag_vol_2x2v_ser_p2 }, // 3 - { NULL, kernel_lbo_vlasov_drag_vol_2x3v_ser_p1, kernel_lbo_vlasov_drag_vol_2x3v_ser_p2 }, // 4 + {NULL, kernel_lbo_vlasov_drag_vol_2x2v_ser_p1, kernel_lbo_vlasov_drag_vol_2x2v_ser_p2}, // 3 + {NULL, kernel_lbo_vlasov_drag_vol_2x3v_ser_p1, kernel_lbo_vlasov_drag_vol_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_lbo_vlasov_drag_vol_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_lbo_vlasov_drag_vol_3x3v_ser_p1, NULL} // 5 }; // Constant nu surface kernel list: vx-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_drag_surf_kern_list ser_surf_vx_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_vlasov_drag_surf_kern_list ser_surf_vx_kernels[] = { // 1x kernels - { NULL, lbo_vlasov_drag_surfvx_1x1v_ser_p1, lbo_vlasov_drag_surfvx_1x1v_ser_p2 }, // 0 - { NULL, lbo_vlasov_drag_surfvx_1x2v_ser_p1, lbo_vlasov_drag_surfvx_1x2v_ser_p2 }, // 1 - { NULL, lbo_vlasov_drag_surfvx_1x3v_ser_p1, lbo_vlasov_drag_surfvx_1x3v_ser_p2 }, // 2 + {NULL, lbo_vlasov_drag_surfvx_1x1v_ser_p1, lbo_vlasov_drag_surfvx_1x1v_ser_p2}, // 0 + {NULL, lbo_vlasov_drag_surfvx_1x2v_ser_p1, lbo_vlasov_drag_surfvx_1x2v_ser_p2}, // 1 + {NULL, lbo_vlasov_drag_surfvx_1x3v_ser_p1, lbo_vlasov_drag_surfvx_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, lbo_vlasov_drag_surfvx_2x2v_ser_p1, lbo_vlasov_drag_surfvx_2x2v_ser_p2 }, // 3 - { NULL, lbo_vlasov_drag_surfvx_2x3v_ser_p1, lbo_vlasov_drag_surfvx_2x3v_ser_p2 }, // + {NULL, lbo_vlasov_drag_surfvx_2x2v_ser_p1, lbo_vlasov_drag_surfvx_2x2v_ser_p2}, // 3 + {NULL, lbo_vlasov_drag_surfvx_2x3v_ser_p1, lbo_vlasov_drag_surfvx_2x3v_ser_p2}, // // 3x kernels - { NULL, lbo_vlasov_drag_surfvx_3x3v_ser_p1, NULL }, // 5 + {NULL, lbo_vlasov_drag_surfvx_3x3v_ser_p1, NULL} // 5 }; // Constant nu surface kernel list: vy-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_drag_surf_kern_list ser_surf_vy_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_vlasov_drag_surf_kern_list ser_surf_vy_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, lbo_vlasov_drag_surfvy_1x2v_ser_p1, lbo_vlasov_drag_surfvy_1x2v_ser_p2 }, // 1 - { NULL, lbo_vlasov_drag_surfvy_1x3v_ser_p1, lbo_vlasov_drag_surfvy_1x3v_ser_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, lbo_vlasov_drag_surfvy_1x2v_ser_p1, lbo_vlasov_drag_surfvy_1x2v_ser_p2}, // 1 + {NULL, lbo_vlasov_drag_surfvy_1x3v_ser_p1, lbo_vlasov_drag_surfvy_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, lbo_vlasov_drag_surfvy_2x2v_ser_p1, lbo_vlasov_drag_surfvy_2x2v_ser_p2 }, // 3 - { NULL, lbo_vlasov_drag_surfvy_2x3v_ser_p1, lbo_vlasov_drag_surfvy_2x3v_ser_p2 }, // 4 + {NULL, lbo_vlasov_drag_surfvy_2x2v_ser_p1, lbo_vlasov_drag_surfvy_2x2v_ser_p2}, // 3 + {NULL, lbo_vlasov_drag_surfvy_2x3v_ser_p1, lbo_vlasov_drag_surfvy_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, lbo_vlasov_drag_surfvy_3x3v_ser_p1, NULL }, // 5 + {NULL, lbo_vlasov_drag_surfvy_3x3v_ser_p1, NULL} // 5 }; // Constant nu surface kernel list: vz-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_drag_surf_kern_list ser_surf_vz_kernels[] = { +GKYL_CU_D static const gkyl_dg_lbo_vlasov_drag_surf_kern_list ser_surf_vz_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, lbo_vlasov_drag_surfvz_1x3v_ser_p1, lbo_vlasov_drag_surfvz_1x3v_ser_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, lbo_vlasov_drag_surfvz_1x3v_ser_p1, lbo_vlasov_drag_surfvz_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, lbo_vlasov_drag_surfvz_2x3v_ser_p1, lbo_vlasov_drag_surfvz_2x3v_ser_p2 }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, lbo_vlasov_drag_surfvz_2x3v_ser_p1, lbo_vlasov_drag_surfvz_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, lbo_vlasov_drag_surfvz_3x3v_ser_p1, NULL }, // 5 + {NULL, lbo_vlasov_drag_surfvz_3x3v_ser_p1, NULL} // 5 }; // Constant nu boundary surface kernel (zero-flux BCs) list: vx-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list ser_boundary_surf_vx_kernels[] = { - // 1x kernels - { NULL, lbo_vlasov_drag_boundary_surfvx_1x1v_ser_p1, lbo_vlasov_drag_boundary_surfvx_1x1v_ser_p2 }, // 0 - { NULL, lbo_vlasov_drag_boundary_surfvx_1x2v_ser_p1, lbo_vlasov_drag_boundary_surfvx_1x2v_ser_p2 }, // 1 - { NULL, lbo_vlasov_drag_boundary_surfvx_1x3v_ser_p1, lbo_vlasov_drag_boundary_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, lbo_vlasov_drag_boundary_surfvx_2x2v_ser_p1, lbo_vlasov_drag_boundary_surfvx_2x2v_ser_p2 }, // 3 - { NULL, lbo_vlasov_drag_boundary_surfvx_2x3v_ser_p1, lbo_vlasov_drag_boundary_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, lbo_vlasov_drag_boundary_surfvx_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list + ser_boundary_surf_vx_kernels[] = { + // 1x kernels + {NULL, lbo_vlasov_drag_boundary_surfvx_1x1v_ser_p1, lbo_vlasov_drag_boundary_surfvx_1x1v_ser_p2 + }, // 0 + {NULL, lbo_vlasov_drag_boundary_surfvx_1x2v_ser_p1, lbo_vlasov_drag_boundary_surfvx_1x2v_ser_p2 + }, // 1 + {NULL, lbo_vlasov_drag_boundary_surfvx_1x3v_ser_p1, lbo_vlasov_drag_boundary_surfvx_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, lbo_vlasov_drag_boundary_surfvx_2x2v_ser_p1, lbo_vlasov_drag_boundary_surfvx_2x2v_ser_p2 + }, // 3 + {NULL, lbo_vlasov_drag_boundary_surfvx_2x3v_ser_p1, lbo_vlasov_drag_boundary_surfvx_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, lbo_vlasov_drag_boundary_surfvx_3x3v_ser_p1, NULL} // 5 }; // Constant nu boundary surface kernel (zero-flux BCs) list: vy-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list ser_boundary_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, lbo_vlasov_drag_boundary_surfvy_1x2v_ser_p1, lbo_vlasov_drag_boundary_surfvy_1x2v_ser_p2 }, // 1 - { NULL, lbo_vlasov_drag_boundary_surfvy_1x3v_ser_p1, lbo_vlasov_drag_boundary_surfvy_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, lbo_vlasov_drag_boundary_surfvy_2x2v_ser_p1, lbo_vlasov_drag_boundary_surfvy_2x2v_ser_p2 }, // 3 - { NULL, lbo_vlasov_drag_boundary_surfvy_2x3v_ser_p1, lbo_vlasov_drag_boundary_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, lbo_vlasov_drag_boundary_surfvy_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list + ser_boundary_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, lbo_vlasov_drag_boundary_surfvy_1x2v_ser_p1, lbo_vlasov_drag_boundary_surfvy_1x2v_ser_p2 + }, // 1 + {NULL, lbo_vlasov_drag_boundary_surfvy_1x3v_ser_p1, lbo_vlasov_drag_boundary_surfvy_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, lbo_vlasov_drag_boundary_surfvy_2x2v_ser_p1, lbo_vlasov_drag_boundary_surfvy_2x2v_ser_p2 + }, // 3 + {NULL, lbo_vlasov_drag_boundary_surfvy_2x3v_ser_p1, lbo_vlasov_drag_boundary_surfvy_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, lbo_vlasov_drag_boundary_surfvy_3x3v_ser_p1, NULL} // 5 }; // Constant nu boundary surface kernel (zero-flux BCs) list: vz-direction -GKYL_CU_D -static const gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list ser_boundary_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, lbo_vlasov_drag_boundary_surfvz_1x3v_ser_p1, lbo_vlasov_drag_boundary_surfvz_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, lbo_vlasov_drag_boundary_surfvz_2x3v_ser_p1, lbo_vlasov_drag_boundary_surfvz_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, lbo_vlasov_drag_boundary_surfvz_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_lbo_vlasov_drag_boundary_surf_kern_list + ser_boundary_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, lbo_vlasov_drag_boundary_surfvz_1x3v_ser_p1, lbo_vlasov_drag_boundary_surfvz_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, lbo_vlasov_drag_boundary_surfvz_2x3v_ser_p1, lbo_vlasov_drag_boundary_surfvz_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, lbo_vlasov_drag_boundary_surfvz_3x3v_ser_p1, NULL} // 5 }; -void gkyl_lbo_vlasov_drag_free(const struct gkyl_ref_count* ref); +void gkyl_lbo_vlasov_drag_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idxC); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if ((dir >= lbo_vlasov_drag->cdim) && (noPrimMomCross)) { - return lbo_vlasov_drag->surf[dir-lbo_vlasov_drag->cdim](xcC, dxC, - nuSum_p, nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut); + return lbo_vlasov_drag->surf[dir - lbo_vlasov_drag->cdim]( + xcC, dxC, nuSum_p, nuPrimMomsSum_p, qInL, qInC, qInR, qRhsOut + ); } return 0.; } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_lbo_vlasov_drag *lbo_vlasov_drag = container_of(eqn, struct dg_lbo_vlasov_drag, eqn); long cidx = gkyl_range_idx(&lbo_vlasov_drag->conf_range, idxSkin); - const double* nuSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); - const double* nuPrimMomsSum_p = (const double*) gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); - const double* nuUSum_p = nuPrimMomsSum_p; - const double* nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim*lbo_vlasov_drag->num_cbasis]; + const double *nuSum_p = (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuSum, cidx); + const double *nuPrimMomsSum_p = + (const double *)gkyl_array_cfetch(lbo_vlasov_drag->auxfields.nuPrimMomsSum, cidx); + const double *nuUSum_p = nuPrimMomsSum_p; + const double *nuVtSqSum_p = &nuPrimMomsSum_p[lbo_vlasov_drag->vdim * lbo_vlasov_drag->num_cbasis]; bool noPrimMomCross = checkPrimMomCross(lbo_vlasov_drag, nuSum_p, nuUSum_p, nuVtSqSum_p); if ((dir >= lbo_vlasov_drag->cdim) && (noPrimMomCross)) { - return lbo_vlasov_drag->boundary_surf[dir-lbo_vlasov_drag->cdim](xcSkin, dxSkin, - nuSum_p, nuPrimMomsSum_p, edge, qInSkin, qInEdge, qRhsOut); + return lbo_vlasov_drag->boundary_surf[dir - lbo_vlasov_drag->cdim]( + xcSkin, dxSkin, nuSum_p, nuPrimMomsSum_p, edge, qInSkin, qInEdge, qRhsOut + ); } return 0.; } - diff --git a/vlasov/zero/gkyl_dg_maxwell.h b/vlasov/zero/gkyl_dg_maxwell.h index 8ccd399269..dd8443a10c 100644 --- a/vlasov/zero/gkyl_dg_maxwell.h +++ b/vlasov/zero/gkyl_dg_maxwell.h @@ -13,8 +13,10 @@ * @param mgnErrorSpeedFactor Factor multiplying lightSpeed for div B correction * @return Pointer to Maxwell equation object */ -struct gkyl_dg_eqn* gkyl_dg_maxwell_new(const struct gkyl_basis* cbasis, - double lightSpeed, double elcErrorSpeedFactor, double mgnErrorSpeedFactor, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_maxwell_new( + const struct gkyl_basis *cbasis, double lightSpeed, double elcErrorSpeedFactor, + double mgnErrorSpeedFactor, bool use_gpu +); /* * Create a new Maxwell equation object that lives on NV-GPU. @@ -25,5 +27,7 @@ struct gkyl_dg_eqn* gkyl_dg_maxwell_new(const struct gkyl_basis* cbasis, * @param mgnErrorSpeedFactor Factor multiplying lightSpeed for div B correction * @return Pointer to Maxwell equation object */ -struct gkyl_dg_eqn* gkyl_dg_maxwell_cu_dev_new(const struct gkyl_basis* cbasis, - double lightSpeed, double elcErrorSpeedFactor, double mgnErrorSpeedFactor); +struct gkyl_dg_eqn *gkyl_dg_maxwell_cu_dev_new( + const struct gkyl_basis *cbasis, double lightSpeed, double elcErrorSpeedFactor, + double mgnErrorSpeedFactor +); diff --git a/vlasov/zero/gkyl_dg_maxwell_priv.h b/vlasov/zero/gkyl_dg_maxwell_priv.h index 13587bd86b..1ff7c3751c 100644 --- a/vlasov/zero/gkyl_dg_maxwell_priv.h +++ b/vlasov/zero/gkyl_dg_maxwell_priv.h @@ -8,15 +8,21 @@ // functions // Types for various kernels -typedef double (*maxwell_surf_t)(const gkyl_maxwell_inp *meq, const double *w, const double *dx, - const double *ql, const double *qc, const double *qr, double* GKYL_RESTRICT out); +typedef double (*maxwell_surf_t)( + const gkyl_maxwell_inp *meq, const double *w, const double *dx, const double *ql, + const double *qc, const double *qr, double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vol_termf_t kernels[4]; } gkyl_dg_maxwell_vol_kern_list; -typedef struct { maxwell_surf_t kernels[4]; } gkyl_dg_maxwell_surf_kern_list; +typedef struct { + vol_termf_t kernels[4]; +} gkyl_dg_maxwell_vol_kern_list; +typedef struct { + maxwell_surf_t kernels[4]; +} gkyl_dg_maxwell_surf_kern_list; struct dg_maxwell { - struct gkyl_dg_eqn eqn; // Base object + struct gkyl_dg_eqn eqn; // Base object gkyl_maxwell_inp maxwell_data; // Parameters needed by kernels maxwell_surf_t surf[3]; // pointers to surface kernels }; @@ -26,158 +32,153 @@ struct dg_maxwell { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_maxwell_vol_1x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_maxwell_vol_1x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); return maxwell_vol_1x_ser_p1(&maxwell->maxwell_data, xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_maxwell_vol_1x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_maxwell_vol_1x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); return maxwell_vol_1x_ser_p2(&maxwell->maxwell_data, xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_maxwell_vol_1x_ser_p3(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_maxwell_vol_1x_ser_p3( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); return maxwell_vol_1x_ser_p3(&maxwell->maxwell_data, xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_maxwell_vol_2x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_maxwell_vol_2x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); return maxwell_vol_2x_ser_p1(&maxwell->maxwell_data, xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_maxwell_vol_2x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_maxwell_vol_2x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); return maxwell_vol_2x_ser_p2(&maxwell->maxwell_data, xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_maxwell_vol_2x_ser_p3(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_maxwell_vol_2x_ser_p3( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); return maxwell_vol_2x_ser_p3(&maxwell->maxwell_data, xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_maxwell_vol_2x_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_maxwell_vol_2x_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); return maxwell_vol_2x_tensor_p2(&maxwell->maxwell_data, xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_maxwell_vol_3x_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_maxwell_vol_3x_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); return maxwell_vol_3x_ser_p1(&maxwell->maxwell_data, xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_maxwell_vol_3x_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_maxwell_vol_3x_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); return maxwell_vol_3x_ser_p2(&maxwell->maxwell_data, xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_maxwell_vol_3x_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_maxwell_vol_3x_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); return maxwell_vol_3x_tensor_p2(&maxwell->maxwell_data, xc, dx, qIn, qRhsOut); } // Volume kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_maxwell_vol_kern_list ser_vol_kernels[] = { - { NULL, kernel_maxwell_vol_1x_ser_p1, kernel_maxwell_vol_1x_ser_p2, kernel_maxwell_vol_1x_ser_p3 }, // 0 - { NULL, kernel_maxwell_vol_2x_ser_p1, kernel_maxwell_vol_2x_ser_p2, kernel_maxwell_vol_2x_ser_p3 }, // 1 - { NULL, kernel_maxwell_vol_3x_ser_p1, kernel_maxwell_vol_3x_ser_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_maxwell_vol_kern_list ser_vol_kernels[] = { + {NULL, kernel_maxwell_vol_1x_ser_p1, kernel_maxwell_vol_1x_ser_p2, kernel_maxwell_vol_1x_ser_p3 + }, // 0 + {NULL, kernel_maxwell_vol_2x_ser_p1, kernel_maxwell_vol_2x_ser_p2, kernel_maxwell_vol_2x_ser_p3 + }, // 1 + {NULL, kernel_maxwell_vol_3x_ser_p1, kernel_maxwell_vol_3x_ser_p2, NULL} // 2 }; // Volume kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_dg_maxwell_vol_kern_list ten_vol_kernels[] = { - { NULL, kernel_maxwell_vol_1x_ser_p1, kernel_maxwell_vol_1x_ser_p2, kernel_maxwell_vol_1x_ser_p3 }, // 0 - { NULL, kernel_maxwell_vol_2x_ser_p1, kernel_maxwell_vol_2x_tensor_p2, NULL }, // 1 - { NULL, kernel_maxwell_vol_3x_ser_p1, kernel_maxwell_vol_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_maxwell_vol_kern_list ten_vol_kernels[] = { + {NULL, kernel_maxwell_vol_1x_ser_p1, kernel_maxwell_vol_1x_ser_p2, kernel_maxwell_vol_1x_ser_p3 + }, // 0 + {NULL, kernel_maxwell_vol_2x_ser_p1, kernel_maxwell_vol_2x_tensor_p2, NULL}, // 1 + {NULL, kernel_maxwell_vol_3x_ser_p1, kernel_maxwell_vol_3x_tensor_p2, NULL} // 2 }; // Surface kernel list: x-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_maxwell_surf_kern_list ser_surf_x_kernels[] = { - { NULL, maxwell_surfx_1x_ser_p1, maxwell_surfx_1x_ser_p2, maxwell_surfx_1x_ser_p3 }, // 0 - { NULL, maxwell_surfx_2x_ser_p1, maxwell_surfx_2x_ser_p2, maxwell_surfx_2x_ser_p3 }, // 1 - { NULL, maxwell_surfx_3x_ser_p1, maxwell_surfx_3x_ser_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_maxwell_surf_kern_list ser_surf_x_kernels[] = { + {NULL, maxwell_surfx_1x_ser_p1, maxwell_surfx_1x_ser_p2, maxwell_surfx_1x_ser_p3}, // 0 + {NULL, maxwell_surfx_2x_ser_p1, maxwell_surfx_2x_ser_p2, maxwell_surfx_2x_ser_p3}, // 1 + {NULL, maxwell_surfx_3x_ser_p1, maxwell_surfx_3x_ser_p2, NULL} // 2 }; // Surface kernel list: x-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_maxwell_surf_kern_list ten_surf_x_kernels[] = { - { NULL, maxwell_surfx_1x_ser_p1, maxwell_surfx_1x_ser_p2, maxwell_surfx_1x_ser_p3 }, // 0 - { NULL, maxwell_surfx_2x_ser_p1, maxwell_surfx_2x_tensor_p2, NULL }, // 1 - { NULL, maxwell_surfx_3x_ser_p1, maxwell_surfx_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_maxwell_surf_kern_list ten_surf_x_kernels[] = { + {NULL, maxwell_surfx_1x_ser_p1, maxwell_surfx_1x_ser_p2, maxwell_surfx_1x_ser_p3}, // 0 + {NULL, maxwell_surfx_2x_ser_p1, maxwell_surfx_2x_tensor_p2, NULL}, // 1 + {NULL, maxwell_surfx_3x_ser_p1, maxwell_surfx_3x_tensor_p2, NULL} // 2 }; // Surface kernel list: y-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_maxwell_surf_kern_list ser_surf_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, maxwell_surfy_2x_ser_p1, maxwell_surfy_2x_ser_p2, maxwell_surfy_2x_ser_p3 }, // 1 - { NULL, maxwell_surfy_3x_ser_p1, maxwell_surfy_3x_ser_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_maxwell_surf_kern_list ser_surf_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, maxwell_surfy_2x_ser_p1, maxwell_surfy_2x_ser_p2, maxwell_surfy_2x_ser_p3}, // 1 + {NULL, maxwell_surfy_3x_ser_p1, maxwell_surfy_3x_ser_p2, NULL} // 2 }; // Surface kernel list: y-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_maxwell_surf_kern_list ten_surf_y_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, maxwell_surfy_2x_ser_p1, maxwell_surfy_2x_tensor_p2, NULL }, // 1 - { NULL, maxwell_surfy_3x_ser_p1, maxwell_surfy_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_maxwell_surf_kern_list ten_surf_y_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, maxwell_surfy_2x_ser_p1, maxwell_surfy_2x_tensor_p2, NULL}, // 1 + {NULL, maxwell_surfy_3x_ser_p1, maxwell_surfy_3x_tensor_p2, NULL} // 2 }; // Surface kernel list: z-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_maxwell_surf_kern_list ser_surf_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, maxwell_surfz_3x_ser_p1, maxwell_surfz_3x_ser_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_maxwell_surf_kern_list ser_surf_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, maxwell_surfz_3x_ser_p1, maxwell_surfz_3x_ser_p2, NULL} // 2 }; // Surface kernel list: z-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_maxwell_surf_kern_list ten_surf_z_kernels[] = { - { NULL, NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL, NULL }, // 1 - { NULL, maxwell_surfz_3x_ser_p1, maxwell_surfz_3x_tensor_p2, NULL }, // 2 +GKYL_CU_D static const gkyl_dg_maxwell_surf_kern_list ten_surf_z_kernels[] = { + {NULL, NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL, NULL}, // 1 + {NULL, maxwell_surfz_3x_ser_p1, maxwell_surfz_3x_tensor_p2, NULL} // 2 }; /** @@ -187,28 +188,22 @@ static const gkyl_dg_maxwell_surf_kern_list ten_surf_z_kernels[] = { */ void gkyl_maxwell_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_maxwell *maxwell = container_of(eqn, struct dg_maxwell, eqn); - return maxwell->surf[dir](&maxwell->maxwell_data, xcC, dxC, - qInL, qInC, qInR, qRhsOut); + return maxwell->surf[dir](&maxwell->maxwell_data, xcC, dxC, qInL, qInC, qInR, qRhsOut); } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { return 0.; } diff --git a/vlasov/zero/gkyl_dg_updater_diffusion_fluid.h b/vlasov/zero/gkyl_dg_updater_diffusion_fluid.h index 89ebe4ce58..c0a879b4bf 100644 --- a/vlasov/zero/gkyl_dg_updater_diffusion_fluid.h +++ b/vlasov/zero/gkyl_dg_updater_diffusion_fluid.h @@ -28,9 +28,11 @@ struct gkyl_dg_updater_diffusion_fluid_tm { * @param use_gpu Whether to run on host or device. * @return New diff updater object */ -struct gkyl_dg_updater_diffusion_fluid* gkyl_dg_updater_diffusion_fluid_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, bool is_diff_const, int num_equations, const bool *diff_in_dir, - int diff_order, const struct gkyl_range *diff_range, const bool *is_zero_flux_dir, bool use_gpu); +struct gkyl_dg_updater_diffusion_fluid *gkyl_dg_updater_diffusion_fluid_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, bool is_diff_const, + int num_equations, const bool *diff_in_dir, int diff_order, const struct gkyl_range *diff_range, + const bool *is_zero_flux_dir, bool use_gpu +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -45,10 +47,11 @@ struct gkyl_dg_updater_diffusion_fluid* gkyl_dg_updater_diffusion_fluid_new(cons * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_diffusion_fluid_advance(struct gkyl_dg_updater_diffusion_fluid *up, - const struct gkyl_range *update_rng, const struct gkyl_array *coeff, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT cflrate, - struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_diffusion_fluid_advance( + struct gkyl_dg_updater_diffusion_fluid *up, const struct gkyl_range *update_rng, + const struct gkyl_array *coeff, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT cflrate, struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in diffusion terms @@ -56,7 +59,8 @@ void gkyl_dg_updater_diffusion_fluid_advance(struct gkyl_dg_updater_diffusion_fl * @param diffusion Updater object * @return timers */ -struct gkyl_dg_updater_diffusion_fluid_tm gkyl_dg_updater_diffusion_fluid_get_tm(const struct gkyl_dg_updater_diffusion_fluid *up); +struct gkyl_dg_updater_diffusion_fluid_tm +gkyl_dg_updater_diffusion_fluid_get_tm(const struct gkyl_dg_updater_diffusion_fluid *up); /** * Delete updater. diff --git a/vlasov/zero/gkyl_dg_updater_diffusion_gen.h b/vlasov/zero/gkyl_dg_updater_diffusion_gen.h index beac97a5bd..41d2a46053 100644 --- a/vlasov/zero/gkyl_dg_updater_diffusion_gen.h +++ b/vlasov/zero/gkyl_dg_updater_diffusion_gen.h @@ -24,8 +24,10 @@ struct gkyl_dg_updater_diffusion_gen_tm { * @param use_gpu Whether to run on host or device. * @return New diff updater object */ -struct gkyl_dg_updater_diffusion_gen* gkyl_dg_updater_diffusion_gen_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, const struct gkyl_range *diff_range, bool use_gpu); +struct gkyl_dg_updater_diffusion_gen *gkyl_dg_updater_diffusion_gen_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_range *diff_range, bool use_gpu +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -40,10 +42,11 @@ struct gkyl_dg_updater_diffusion_gen* gkyl_dg_updater_diffusion_gen_new(const st * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_diffusion_gen_advance(struct gkyl_dg_updater_diffusion_gen *up, - const struct gkyl_range *update_rng, const struct gkyl_array *coeff, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT cflrate, - struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_diffusion_gen_advance( + struct gkyl_dg_updater_diffusion_gen *up, const struct gkyl_range *update_rng, + const struct gkyl_array *coeff, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT cflrate, struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in diffusion terms @@ -51,7 +54,8 @@ void gkyl_dg_updater_diffusion_gen_advance(struct gkyl_dg_updater_diffusion_gen * @param diffusion Updater object * @return timers */ -struct gkyl_dg_updater_diffusion_gen_tm gkyl_dg_updater_diffusion_gen_get_tm(const struct gkyl_dg_updater_diffusion_gen *up); +struct gkyl_dg_updater_diffusion_gen_tm +gkyl_dg_updater_diffusion_gen_get_tm(const struct gkyl_dg_updater_diffusion_gen *up); /** * Delete updater. diff --git a/vlasov/zero/gkyl_dg_updater_diffusion_vlasov.h b/vlasov/zero/gkyl_dg_updater_diffusion_vlasov.h index 135f534c6a..e805d5cc0a 100644 --- a/vlasov/zero/gkyl_dg_updater_diffusion_vlasov.h +++ b/vlasov/zero/gkyl_dg_updater_diffusion_vlasov.h @@ -28,9 +28,11 @@ struct gkyl_dg_updater_diffusion_vlasov_tm { * @param use_gpu Whether to run on host or device. * @return New diff updater object */ -struct gkyl_dg_updater_diffusion_vlasov* gkyl_dg_updater_diffusion_vlasov_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, const struct gkyl_basis *cbasis, bool is_diff_const, const bool *diff_in_dir, - int diff_order, const struct gkyl_range *diff_range, const bool *is_zero_flux_dir, bool use_gpu); +struct gkyl_dg_updater_diffusion_vlasov *gkyl_dg_updater_diffusion_vlasov_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_basis *cbasis, bool is_diff_const, const bool *diff_in_dir, int diff_order, + const struct gkyl_range *diff_range, const bool *is_zero_flux_dir, bool use_gpu +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -45,10 +47,11 @@ struct gkyl_dg_updater_diffusion_vlasov* gkyl_dg_updater_diffusion_vlasov_new(co * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_diffusion_vlasov_advance(struct gkyl_dg_updater_diffusion_vlasov *up, - const struct gkyl_range *update_rng, const struct gkyl_array *coeff, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT cflrate, - struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_diffusion_vlasov_advance( + struct gkyl_dg_updater_diffusion_vlasov *up, const struct gkyl_range *update_rng, + const struct gkyl_array *coeff, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT cflrate, struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in diffusion terms @@ -56,7 +59,8 @@ void gkyl_dg_updater_diffusion_vlasov_advance(struct gkyl_dg_updater_diffusion_v * @param diffusion Updater object * @return timers */ -struct gkyl_dg_updater_diffusion_vlasov_tm gkyl_dg_updater_diffusion_vlasov_get_tm(const struct gkyl_dg_updater_diffusion_vlasov *up); +struct gkyl_dg_updater_diffusion_vlasov_tm +gkyl_dg_updater_diffusion_vlasov_get_tm(const struct gkyl_dg_updater_diffusion_vlasov *up); /** * Delete updater. diff --git a/vlasov/zero/gkyl_dg_updater_fluid.h b/vlasov/zero/gkyl_dg_updater_fluid.h index 91a4edf76d..c00146a3e9 100644 --- a/vlasov/zero/gkyl_dg_updater_fluid.h +++ b/vlasov/zero/gkyl_dg_updater_fluid.h @@ -30,9 +30,11 @@ struct gkyl_dg_updater_fluid_tm { * * @return New fluid updater object */ -gkyl_dg_updater_fluid* gkyl_dg_updater_fluid_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_range *conf_range, - const struct gkyl_wv_eqn *wv_eqn, const struct gkyl_wave_geom *geom, void *aux_inp, bool use_gpu); +gkyl_dg_updater_fluid *gkyl_dg_updater_fluid_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_range *conf_range, const struct gkyl_wv_eqn *wv_eqn, + const struct gkyl_wave_geom *geom, void *aux_inp, bool use_gpu +); /** * Acquire fluid equation object @@ -41,8 +43,7 @@ gkyl_dg_updater_fluid* gkyl_dg_updater_fluid_new(const struct gkyl_rect_grid *gr * * @return fluid equation object */ -struct gkyl_dg_eqn* -gkyl_dg_updater_fluid_acquire_eqn(const gkyl_dg_updater_fluid* fluid); +struct gkyl_dg_eqn *gkyl_dg_updater_fluid_acquire_eqn(const gkyl_dg_updater_fluid *fluid); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -56,9 +57,11 @@ gkyl_dg_updater_fluid_acquire_eqn(const gkyl_dg_updater_fluid* fluid); * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_fluid_advance(gkyl_dg_updater_fluid *fluid, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_fluid_advance( + gkyl_dg_updater_fluid *fluid, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in drag and diffusion terms @@ -73,4 +76,4 @@ struct gkyl_dg_updater_fluid_tm gkyl_dg_updater_fluid_get_tm(const gkyl_dg_updat * * @param fluid Updater to delete. */ -void gkyl_dg_updater_fluid_release(gkyl_dg_updater_fluid* fluid); +void gkyl_dg_updater_fluid_release(gkyl_dg_updater_fluid *fluid); diff --git a/vlasov/zero/gkyl_dg_updater_fpo_vlasov.h b/vlasov/zero/gkyl_dg_updater_fpo_vlasov.h index b08716ecd0..95651e749a 100644 --- a/vlasov/zero/gkyl_dg_updater_fpo_vlasov.h +++ b/vlasov/zero/gkyl_dg_updater_fpo_vlasov.h @@ -23,9 +23,10 @@ struct gkyl_dg_updater_fpo_vlasov_tm { * @param use_gpu Boolean to determine whether struct objects are on host or device * @return New fpo updater object */ -struct gkyl_dg_updater_collisions* -gkyl_dg_updater_fpo_vlasov_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *pbasis, const struct gkyl_range *phase_range, bool use_gpu); +struct gkyl_dg_updater_collisions *gkyl_dg_updater_fpo_vlasov_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, bool use_gpu +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -41,17 +42,19 @@ gkyl_dg_updater_fpo_vlasov_new(const struct gkyl_rect_grid *grid, * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_fpo_vlasov_advance(struct gkyl_dg_updater_collisions *fpo, - const struct gkyl_range *update_rng, - const struct gkyl_array *h, const struct gkyl_array *g, - const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_fpo_vlasov_advance( + struct gkyl_dg_updater_collisions *fpo, const struct gkyl_range *update_rng, + const struct gkyl_array *h, const struct gkyl_array *g, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); -void gkyl_dg_updater_fpo_vlasov_advance_cu(struct gkyl_dg_updater_collisions *fpo, - const struct gkyl_range *update_rng, - const struct gkyl_array *h, const struct gkyl_array *g, - const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_fpo_vlasov_advance_cu( + struct gkyl_dg_updater_collisions *fpo, const struct gkyl_range *update_rng, + const struct gkyl_array *h, const struct gkyl_array *g, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in drag and diffusion terms @@ -59,11 +62,12 @@ void gkyl_dg_updater_fpo_vlasov_advance_cu(struct gkyl_dg_updater_collisions *fp * @param lbo Updater object * @return timers */ -struct gkyl_dg_updater_fpo_vlasov_tm gkyl_dg_updater_fpo_vlasov_get_tm(const struct gkyl_dg_updater_collisions *coll); +struct gkyl_dg_updater_fpo_vlasov_tm +gkyl_dg_updater_fpo_vlasov_get_tm(const struct gkyl_dg_updater_collisions *coll); /** * Delete updater. * * @param lbo Updater to delete. */ -void gkyl_dg_updater_fpo_vlasov_release(struct gkyl_dg_updater_collisions* coll); +void gkyl_dg_updater_fpo_vlasov_release(struct gkyl_dg_updater_collisions *coll); diff --git a/vlasov/zero/gkyl_dg_updater_lbo_vlasov.h b/vlasov/zero/gkyl_dg_updater_lbo_vlasov.h index 758cf52a6e..ac38b59461 100644 --- a/vlasov/zero/gkyl_dg_updater_lbo_vlasov.h +++ b/vlasov/zero/gkyl_dg_updater_lbo_vlasov.h @@ -27,12 +27,12 @@ struct gkyl_dg_updater_lbo_vlasov_tm { * @param use_gpu Bool for whether updater is on host or device * @return New LBO updater object */ -struct gkyl_dg_updater_collisions* -gkyl_dg_updater_lbo_vlasov_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *conf_range, - struct gkyl_dg_lbo_vlasov_drag_auxfields *drag_inp, struct gkyl_dg_lbo_vlasov_diff_auxfields *diff_inp, - bool use_gpu); +struct gkyl_dg_updater_collisions *gkyl_dg_updater_lbo_vlasov_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, + struct gkyl_dg_lbo_vlasov_drag_auxfields *drag_inp, + struct gkyl_dg_lbo_vlasov_diff_auxfields *diff_inp, bool use_gpu +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -48,9 +48,11 @@ gkyl_dg_updater_lbo_vlasov_new(const struct gkyl_rect_grid *phase_grid, * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_lbo_vlasov_advance(struct gkyl_dg_updater_collisions *lbo, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_lbo_vlasov_advance( + struct gkyl_dg_updater_collisions *lbo, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in drag and diffusion terms @@ -58,11 +60,12 @@ void gkyl_dg_updater_lbo_vlasov_advance(struct gkyl_dg_updater_collisions *lbo, * @param lbo Updater object * @return timers */ -struct gkyl_dg_updater_lbo_vlasov_tm gkyl_dg_updater_lbo_vlasov_get_tm(const struct gkyl_dg_updater_collisions *coll); +struct gkyl_dg_updater_lbo_vlasov_tm +gkyl_dg_updater_lbo_vlasov_get_tm(const struct gkyl_dg_updater_collisions *coll); /** * Delete updater. * * @param lbo Updater to delete. */ -void gkyl_dg_updater_lbo_vlasov_release(struct gkyl_dg_updater_collisions* coll); +void gkyl_dg_updater_lbo_vlasov_release(struct gkyl_dg_updater_collisions *coll); diff --git a/vlasov/zero/gkyl_dg_updater_moment.h b/vlasov/zero/gkyl_dg_updater_moment.h index 70d7a0b23a..7bda5c6d08 100644 --- a/vlasov/zero/gkyl_dg_updater_moment.h +++ b/vlasov/zero/gkyl_dg_updater_moment.h @@ -32,13 +32,13 @@ typedef struct gkyl_dg_updater_moment_tm gkyl_dg_updater_moment_tm; * * @return New moment updater object */ -struct gkyl_dg_updater_moment* -gkyl_dg_updater_moment_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, - const struct gkyl_range *phase_range, - enum gkyl_model_id model_id, void *aux_inp, - enum gkyl_distribution_moments mom_type, bool is_integrated, bool use_gpu); +struct gkyl_dg_updater_moment *gkyl_dg_updater_moment_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_range, + const struct gkyl_range *vel_range, const struct gkyl_range *phase_range, + enum gkyl_model_id model_id, void *aux_inp, enum gkyl_distribution_moments mom_type, + bool is_integrated, bool use_gpu +); /** * Acquire moment object @@ -47,8 +47,8 @@ gkyl_dg_updater_moment_new(const struct gkyl_rect_grid *grid, * * @return moment type object */ -struct gkyl_mom_type* -gkyl_dg_updater_moment_acquire_type(const struct gkyl_dg_updater_moment* moment); +struct gkyl_mom_type * +gkyl_dg_updater_moment_acquire_type(const struct gkyl_dg_updater_moment *moment); /** * Acquire number of moments @@ -57,8 +57,7 @@ gkyl_dg_updater_moment_acquire_type(const struct gkyl_dg_updater_moment* moment) * * @return number of moments */ -int -gkyl_dg_updater_moment_num_mom(const struct gkyl_dg_updater_moment* moment); +int gkyl_dg_updater_moment_num_mom(const struct gkyl_dg_updater_moment *moment); /** * Compute moment. The update_phase_rng and update_conf_rng MUST be a sub-range of the @@ -72,10 +71,11 @@ gkyl_dg_updater_moment_num_mom(const struct gkyl_dg_updater_moment* moment); * @param fIn Input to updater * @param mout Output moment */ -void -gkyl_dg_updater_moment_advance(struct gkyl_dg_updater_moment *moment, - const struct gkyl_range *update_phase_rng, const struct gkyl_range *update_conf_rng, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT mout); +void gkyl_dg_updater_moment_advance( + struct gkyl_dg_updater_moment *moment, const struct gkyl_range *update_phase_rng, + const struct gkyl_range *update_conf_rng, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT mout +); /** * Return total time spent in computing moments @@ -83,11 +83,12 @@ gkyl_dg_updater_moment_advance(struct gkyl_dg_updater_moment *moment, * @param moment Updater object * @return timers */ -struct gkyl_dg_updater_moment_tm gkyl_dg_updater_moment_get_tm(const struct gkyl_dg_updater_moment *moment); +struct gkyl_dg_updater_moment_tm +gkyl_dg_updater_moment_get_tm(const struct gkyl_dg_updater_moment *moment); /** * Delete updater. * * @param moment Updater to delete. */ -void gkyl_dg_updater_moment_release(struct gkyl_dg_updater_moment* moment); +void gkyl_dg_updater_moment_release(struct gkyl_dg_updater_moment *moment); diff --git a/vlasov/zero/gkyl_dg_updater_rad_vlasov.h b/vlasov/zero/gkyl_dg_updater_rad_vlasov.h index 41c70f6120..bd195db0ae 100644 --- a/vlasov/zero/gkyl_dg_updater_rad_vlasov.h +++ b/vlasov/zero/gkyl_dg_updater_rad_vlasov.h @@ -25,11 +25,11 @@ struct gkyl_dg_updater_rad_vlasov_tm { * @param use_gpu Bool for whether updater is on host or device * @return New radiation updater object */ -struct gkyl_dg_updater_rad_vlasov* -gkyl_dg_updater_rad_vlasov_new(const struct gkyl_rect_grid *phase_grid, - const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, - const struct gkyl_range *conf_range, struct gkyl_dg_lbo_vlasov_drag_auxfields *drag_inp, - bool use_gpu); +struct gkyl_dg_updater_rad_vlasov *gkyl_dg_updater_rad_vlasov_new( + const struct gkyl_rect_grid *phase_grid, const struct gkyl_basis *conf_basis, + const struct gkyl_basis *phase_basis, const struct gkyl_range *conf_range, + struct gkyl_dg_lbo_vlasov_drag_auxfields *drag_inp, bool use_gpu +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -43,9 +43,11 @@ gkyl_dg_updater_rad_vlasov_new(const struct gkyl_rect_grid *phase_grid, * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_rad_vlasov_advance(struct gkyl_dg_updater_rad_vlasov *rad, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_rad_vlasov_advance( + struct gkyl_dg_updater_rad_vlasov *rad, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in drag terms @@ -53,7 +55,8 @@ void gkyl_dg_updater_rad_vlasov_advance(struct gkyl_dg_updater_rad_vlasov *rad, * @param rad Updater object * @return timers */ -struct gkyl_dg_updater_rad_vlasov_tm gkyl_dg_updater_rad_vlasov_get_tm(const struct gkyl_dg_updater_rad_vlasov *rad); +struct gkyl_dg_updater_rad_vlasov_tm +gkyl_dg_updater_rad_vlasov_get_tm(const struct gkyl_dg_updater_rad_vlasov *rad); /** * Delete updater. diff --git a/vlasov/zero/gkyl_dg_updater_vlasov.h b/vlasov/zero/gkyl_dg_updater_vlasov.h index b9a6b10014..816e01621a 100644 --- a/vlasov/zero/gkyl_dg_updater_vlasov.h +++ b/vlasov/zero/gkyl_dg_updater_vlasov.h @@ -29,10 +29,13 @@ typedef struct gkyl_dg_updater_vlasov gkyl_dg_updater_vlasov; * * @return New vlasov updater object */ -gkyl_dg_updater_vlasov* gkyl_dg_updater_vlasov_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, const struct gkyl_range *phase_range, - const bool *is_zero_flux_bc, enum gkyl_model_id model_id, enum gkyl_field_id field_id, void *aux_inp, bool use_gpu); +gkyl_dg_updater_vlasov *gkyl_dg_updater_vlasov_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_range, + const struct gkyl_range *vel_range, const struct gkyl_range *phase_range, + const bool *is_zero_flux_bc, enum gkyl_model_id model_id, enum gkyl_field_id field_id, + void *aux_inp, bool use_gpu +); /** * Acquire Vlasov equation object @@ -41,8 +44,7 @@ gkyl_dg_updater_vlasov* gkyl_dg_updater_vlasov_new(const struct gkyl_rect_grid * * * @return Vlasov equation object */ -struct gkyl_dg_eqn* -gkyl_dg_updater_vlasov_acquire_eqn(const gkyl_dg_updater_vlasov* vlasov); +struct gkyl_dg_eqn *gkyl_dg_updater_vlasov_acquire_eqn(const gkyl_dg_updater_vlasov *vlasov); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -56,9 +58,11 @@ gkyl_dg_updater_vlasov_acquire_eqn(const gkyl_dg_updater_vlasov* vlasov); * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_dg_updater_vlasov_advance(gkyl_dg_updater_vlasov *vlasov, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_vlasov_advance( + gkyl_dg_updater_vlasov *vlasov, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in vlasov equation @@ -66,11 +70,12 @@ void gkyl_dg_updater_vlasov_advance(gkyl_dg_updater_vlasov *vlasov, * @param vlasov Updater object * @return timers */ -struct gkyl_dg_updater_vlasov_tm gkyl_dg_updater_vlasov_get_tm(const gkyl_dg_updater_vlasov *vlasov); +struct gkyl_dg_updater_vlasov_tm gkyl_dg_updater_vlasov_get_tm(const gkyl_dg_updater_vlasov *vlasov +); /** * Delete updater. * * @param vlasov Updater to delete. */ -void gkyl_dg_updater_vlasov_release(gkyl_dg_updater_vlasov* vlasov); +void gkyl_dg_updater_vlasov_release(gkyl_dg_updater_vlasov *vlasov); diff --git a/vlasov/zero/gkyl_dg_updater_vlasov_poisson.h b/vlasov/zero/gkyl_dg_updater_vlasov_poisson.h index 3c54654523..0f3eefa21f 100644 --- a/vlasov/zero/gkyl_dg_updater_vlasov_poisson.h +++ b/vlasov/zero/gkyl_dg_updater_vlasov_poisson.h @@ -28,10 +28,13 @@ typedef struct gkyl_dg_updater_vlasov gkyl_dg_updater_vlasov; * * @return New vlasov_poisson updater object. */ -gkyl_dg_updater_vlasov* gkyl_dg_updater_vlasov_poisson_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, const struct gkyl_range *phase_range, - const bool *is_zero_flux_dir, enum gkyl_model_id model_id, enum gkyl_field_id field_id, void *aux_inp, bool use_gpu); +gkyl_dg_updater_vlasov *gkyl_dg_updater_vlasov_poisson_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_range, + const struct gkyl_range *vel_range, const struct gkyl_range *phase_range, + const bool *is_zero_flux_dir, enum gkyl_model_id model_id, enum gkyl_field_id field_id, + void *aux_inp, bool use_gpu +); /** * Acquire Vlasov-Poisson equation object @@ -40,8 +43,7 @@ gkyl_dg_updater_vlasov* gkyl_dg_updater_vlasov_poisson_new(const struct gkyl_rec * * @return Vlasov-Poisson equation object */ -struct gkyl_dg_eqn* -gkyl_dg_updater_vlasov_poisson_acquire_eqn(const gkyl_dg_updater_vlasov* up); +struct gkyl_dg_eqn *gkyl_dg_updater_vlasov_poisson_acquire_eqn(const gkyl_dg_updater_vlasov *up); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -55,9 +57,11 @@ gkyl_dg_updater_vlasov_poisson_acquire_eqn(const gkyl_dg_updater_vlasov* up); * @param cflrate CFL scalar rate (frequency) array. * @param rhs RHS output. */ -void gkyl_dg_updater_vlasov_poisson_advance(gkyl_dg_updater_vlasov *up, - const struct gkyl_range *update_rng, const struct gkyl_array* GKYL_RESTRICT fIn, - struct gkyl_array* GKYL_RESTRICT cflrate, struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_dg_updater_vlasov_poisson_advance( + gkyl_dg_updater_vlasov *up, const struct gkyl_range *update_rng, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Return total time spent in vlasov equation @@ -65,11 +69,12 @@ void gkyl_dg_updater_vlasov_poisson_advance(gkyl_dg_updater_vlasov *up, * @param up Updater object. * @return timers. */ -struct gkyl_dg_updater_vlasov_tm gkyl_dg_updater_vlasov_poisson_get_tm(const gkyl_dg_updater_vlasov *up); +struct gkyl_dg_updater_vlasov_tm +gkyl_dg_updater_vlasov_poisson_get_tm(const gkyl_dg_updater_vlasov *up); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_dg_updater_vlasov_poisson_release(gkyl_dg_updater_vlasov* up); +void gkyl_dg_updater_vlasov_poisson_release(gkyl_dg_updater_vlasov *up); diff --git a/vlasov/zero/gkyl_dg_updater_vlasov_priv.h b/vlasov/zero/gkyl_dg_updater_vlasov_priv.h index 6023eea9a3..20a86fbf1c 100644 --- a/vlasov/zero/gkyl_dg_updater_vlasov_priv.h +++ b/vlasov/zero/gkyl_dg_updater_vlasov_priv.h @@ -6,7 +6,8 @@ struct gkyl_dg_updater_vlasov { enum gkyl_model_id model_id; // Identifier for model (e.g., SR, PKPM, see gkyl_eqn_type.h) - enum gkyl_field_id field_id; // Identifier for field type (e.g., Maxwell's, Poisson, see gkyl_eqn_type.h) + enum gkyl_field_id + field_id; // Identifier for field type (e.g., Maxwell's, Poisson, see gkyl_eqn_type.h) bool use_gpu; // Boolean for if the update is performed on GPUs struct gkyl_dg_eqn *eqn_vlasov; // Equation object struct gkyl_hyper_dg *hdg_vlasov; // solvers for specific Vlasov equation diff --git a/vlasov/zero/gkyl_dg_updater_vlasov_timers.h b/vlasov/zero/gkyl_dg_updater_vlasov_timers.h index c98be2a807..1d3808fa53 100644 --- a/vlasov/zero/gkyl_dg_updater_vlasov_timers.h +++ b/vlasov/zero/gkyl_dg_updater_vlasov_timers.h @@ -4,4 +4,3 @@ struct gkyl_dg_updater_vlasov_tm { double vlasov_tm; // time for vlasov updates }; - diff --git a/vlasov/zero/gkyl_dg_vlasov.h b/vlasov/zero/gkyl_dg_vlasov.h index d4a4793757..4aabc1da15 100644 --- a/vlasov/zero/gkyl_dg_vlasov.h +++ b/vlasov/zero/gkyl_dg_vlasov.h @@ -8,13 +8,16 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_vlasov_auxfields { - const struct gkyl_array *field; // q/m*(E_tot,B_tot) for Maxwell's, q/m*(phi_tot,A_ext) for Poisson's - const struct gkyl_array *cot_vec; // cotangent vectors (e^i) used in volume term if general geometry enabled - const struct gkyl_array *alpha_surf; // Pointer to surface expansion of phase space flux alpha - // used in general geometry for v^i = v . e^i at the surface. +struct gkyl_dg_vlasov_auxfields { + const struct gkyl_array + *field; // q/m*(E_tot,B_tot) for Maxwell's, q/m*(phi_tot,A_ext) for Poisson's + const struct gkyl_array + *cot_vec; // cotangent vectors (e^i) used in volume term if general geometry enabled + const struct gkyl_array *alpha_surf; // Pointer to surface expansion of phase space flux alpha + // used in general geometry for v^i = v . e^i at the surface. const struct gkyl_array *sgn_alpha_surf; // Pointer to sign(alpha_surf) at quadrature points. - const struct gkyl_array *const_sgn_alpha; // Pointer to integer array for if sign(alpha_surf) is single-signed. + const struct gkyl_array + *const_sgn_alpha; // Pointer to integer array for if sign(alpha_surf) is single-signed. }; /** @@ -29,9 +32,11 @@ struct gkyl_dg_vlasov_auxfields { * @param use_gpu bool to determine if on GPU * @return Pointer to Vlasov equation object */ -struct gkyl_dg_eqn* gkyl_dg_vlasov_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, const struct gkyl_range* phase_range, - enum gkyl_model_id model_id, enum gkyl_field_id field_id, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_vlasov_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, + enum gkyl_model_id model_id, enum gkyl_field_id field_id, bool use_gpu +); /** * Create a new Vlasov equation object that lives on NV-GPU @@ -44,9 +49,11 @@ struct gkyl_dg_eqn* gkyl_dg_vlasov_new(const struct gkyl_basis* cbasis, * @param field_id enum to determine what type of EM fields (Vlasov-Maxwell vs. Vlasov-Poisson vs. neutrals) * @return Pointer to Vlasov equation object */ -struct gkyl_dg_eqn* gkyl_dg_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, const struct gkyl_range* phase_range, - enum gkyl_model_id model_id, enum gkyl_field_id field_id); +struct gkyl_dg_eqn *gkyl_dg_vlasov_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, + enum gkyl_model_id model_id, enum gkyl_field_id field_id +); /** * Set the auxiliary fields (e.g. q/m*EM) needed in updating the force terms. @@ -63,7 +70,8 @@ void gkyl_vlasov_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vla * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_vlasov_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_auxfields auxin); - +void gkyl_vlasov_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_vlasov_poisson.h b/vlasov/zero/gkyl_dg_vlasov_poisson.h index d37a5fe848..6b5ac36333 100644 --- a/vlasov/zero/gkyl_dg_vlasov_poisson.h +++ b/vlasov/zero/gkyl_dg_vlasov_poisson.h @@ -8,7 +8,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_vlasov_poisson_auxfields { +struct gkyl_dg_vlasov_poisson_auxfields { const struct gkyl_array *potentials; // (q/m)*(phi+phi_ext,A_ext). const struct gkyl_array *fields_ext; // (q/m)*(E,B). }; @@ -25,9 +25,11 @@ struct gkyl_dg_vlasov_poisson_auxfields { * @param use_gpu bool to determine if on GPU * @return Pointer to Vlasov equation object */ -struct gkyl_dg_eqn* gkyl_dg_vlasov_poisson_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, const struct gkyl_range* phase_range, - enum gkyl_model_id model_id, enum gkyl_field_id field_id, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_vlasov_poisson_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, + enum gkyl_model_id model_id, enum gkyl_field_id field_id, bool use_gpu +); /** * Set the auxiliary fields (e.g. (q/m)*(phi+phi_ext,A_ext) or @@ -36,4 +38,6 @@ struct gkyl_dg_eqn* gkyl_dg_vlasov_poisson_new(const struct gkyl_basis* cbasis, * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_vlasov_poisson_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_poisson_auxfields auxin); +void gkyl_vlasov_poisson_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_poisson_auxfields auxin +); diff --git a/vlasov/zero/gkyl_dg_vlasov_poisson_priv.h b/vlasov/zero/gkyl_dg_vlasov_poisson_priv.h index 2d973944ac..8ebe0e540b 100644 --- a/vlasov/zero/gkyl_dg_vlasov_poisson_priv.h +++ b/vlasov/zero/gkyl_dg_vlasov_poisson_priv.h @@ -10,54 +10,79 @@ #include // Types for various kernels -typedef double (*vlasov_poisson_stream_surf_t)(const double *w, const double *dxv, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); - -typedef double (*vlasov_poisson_stream_boundary_surf_t)(const double *w, const double *dxv, - const int edge, const double *fEdge, const double *fSkin, double* GKYL_RESTRICT out); - -typedef double (*vlasov_poisson_accel_surf_t)(const double *w, const double *dxv, - const double *pots, const double *EBext, const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); - -typedef double (*vlasov_poisson_accel_boundary_surf_t)(const double *w, const double *dxv, - const double *pots, const double *EBext, const int edge, const double *fEdge, const double *fSkin, double* GKYL_RESTRICT out); +typedef double (*vlasov_poisson_stream_surf_t)( + const double *w, const double *dxv, const double *fl, const double *fc, const double *fr, + double *GKYL_RESTRICT out +); + +typedef double (*vlasov_poisson_stream_boundary_surf_t)( + const double *w, const double *dxv, const int edge, const double *fEdge, const double *fSkin, + double *GKYL_RESTRICT out +); + +typedef double (*vlasov_poisson_accel_surf_t)( + const double *w, const double *dxv, const double *pots, const double *EBext, const double *fl, + const double *fc, const double *fr, double *GKYL_RESTRICT out +); + +typedef double (*vlasov_poisson_accel_boundary_surf_t)( + const double *w, const double *dxv, const double *pots, const double *EBext, const int edge, + const double *fEdge, const double *fSkin, double *GKYL_RESTRICT out +); // Null kernels used for vxB term in case without external fields. -GKYL_CU_DH static double kernel_vlasov_poisson_zero_accel_surf(const double *w, const double *dxv, - const double *pots, const double *EBext, const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out) +GKYL_CU_DH static double kernel_vlasov_poisson_zero_accel_surf( + const double *w, const double *dxv, const double *pots, const double *EBext, const double *fl, + const double *fc, const double *fr, double *GKYL_RESTRICT out +) { return 0.0; } -GKYL_CU_DH static double kernel_vlasov_poisson_zero_accel_boundary_surf(const double *w, const double *dxv, - const double *pots, const double *EBext, const int edge, const double *fEdge, const double *fSkin, double* GKYL_RESTRICT out) +GKYL_CU_DH static double kernel_vlasov_poisson_zero_accel_boundary_surf( + const double *w, const double *dxv, const double *pots, const double *EBext, const int edge, + const double *fEdge, const double *fSkin, double *GKYL_RESTRICT out +) { return 0.0; } // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_vlasov_poisson_vol_kern_list; - -typedef struct { vlasov_poisson_stream_surf_t kernels[3]; } gkyl_dg_vlasov_poisson_stream_surf_kern_list; -typedef struct { vlasov_poisson_accel_surf_t kernels[3]; } gkyl_dg_vlasov_poisson_accel_surf_kern_list; - -typedef struct { vlasov_poisson_stream_boundary_surf_t kernels[3]; } gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list; -typedef struct { vlasov_poisson_accel_boundary_surf_t kernels[3]; } gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_vlasov_poisson_vol_kern_list; + +typedef struct { + vlasov_poisson_stream_surf_t kernels[3]; +} gkyl_dg_vlasov_poisson_stream_surf_kern_list; +typedef struct { + vlasov_poisson_accel_surf_t kernels[3]; +} gkyl_dg_vlasov_poisson_accel_surf_kern_list; + +typedef struct { + vlasov_poisson_stream_boundary_surf_t kernels[3]; +} gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list; +typedef struct { + vlasov_poisson_accel_boundary_surf_t kernels[3]; +} gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list; struct dg_vlasov_poisson { struct gkyl_dg_eqn eqn; // Base object. int cdim; // Config-space dimensions. int pdim; // Phase-space dimensions. vlasov_poisson_stream_surf_t stream_surf[3]; // Surface terms for streaming. - vlasov_poisson_stream_boundary_surf_t stream_boundary_surf[3]; // Boundary surface terms for streaming + vlasov_poisson_stream_boundary_surf_t + stream_boundary_surf[3]; // Boundary surface terms for streaming vlasov_poisson_accel_surf_t accel_surf[3]; // Surface terms for acceleration. vlasov_poisson_accel_boundary_surf_t accel_boundary_surf[3]; // Surface terms for acceleration struct gkyl_range conf_range; // Configuration space range (for indexing fields) @@ -70,87 +95,94 @@ struct dg_vlasov_poisson { // // Streaming surface kernel list: x-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_stream_surf_kern_list ser_poisson_stream_surf_x_kernels[] = { - // 1x kernels - { NULL, vlasov_poisson_surfx_1x1v_ser_p1, vlasov_poisson_surfx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_poisson_surfx_1x2v_ser_p1, vlasov_poisson_surfx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_surfx_1x3v_ser_p1, vlasov_poisson_surfx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_surfx_2x2v_ser_p1, vlasov_poisson_surfx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_surfx_2x3v_ser_p1, vlasov_poisson_surfx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_stream_surf_kern_list + ser_poisson_stream_surf_x_kernels[] = { + // 1x kernels + {NULL, vlasov_poisson_surfx_1x1v_ser_p1, vlasov_poisson_surfx_1x1v_ser_p2}, // 0 + {NULL, vlasov_poisson_surfx_1x2v_ser_p1, vlasov_poisson_surfx_1x2v_ser_p2}, // 1 + {NULL, vlasov_poisson_surfx_1x3v_ser_p1, vlasov_poisson_surfx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_poisson_surfx_2x2v_ser_p1, vlasov_poisson_surfx_2x2v_ser_p2}, // 3 + {NULL, vlasov_poisson_surfx_2x3v_ser_p1, vlasov_poisson_surfx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Streaming surface kernel list: y-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_stream_surf_kern_list ser_poisson_stream_surf_y_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, vlasov_poisson_surfy_2x2v_ser_p1, vlasov_poisson_surfy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_surfy_2x3v_ser_p1, vlasov_poisson_surfy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_stream_surf_kern_list + ser_poisson_stream_surf_y_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, vlasov_poisson_surfy_2x2v_ser_p1, vlasov_poisson_surfy_2x2v_ser_p2}, // 3 + {NULL, vlasov_poisson_surfy_2x3v_ser_p1, vlasov_poisson_surfy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Streaming surface kernel list: z-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_stream_surf_kern_list ser_poisson_stream_surf_z_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_stream_surf_kern_list + ser_poisson_stream_surf_z_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Streaming boundary surface kernel list: x-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list ser_poisson_stream_boundary_surf_x_kernels[] = { - // 1x kernels - { NULL, vlasov_poisson_boundary_surfx_1x1v_ser_p1, vlasov_poisson_boundary_surfx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_poisson_boundary_surfx_1x2v_ser_p1, vlasov_poisson_boundary_surfx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_boundary_surfx_1x3v_ser_p1, vlasov_poisson_boundary_surfx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_boundary_surfx_2x2v_ser_p1, vlasov_poisson_boundary_surfx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_boundary_surfx_2x3v_ser_p1, vlasov_poisson_boundary_surfx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list + ser_poisson_stream_boundary_surf_x_kernels[] = { + // 1x kernels + {NULL, vlasov_poisson_boundary_surfx_1x1v_ser_p1, vlasov_poisson_boundary_surfx_1x1v_ser_p2 + }, // 0 + {NULL, vlasov_poisson_boundary_surfx_1x2v_ser_p1, vlasov_poisson_boundary_surfx_1x2v_ser_p2 + }, // 1 + {NULL, vlasov_poisson_boundary_surfx_1x3v_ser_p1, vlasov_poisson_boundary_surfx_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, vlasov_poisson_boundary_surfx_2x2v_ser_p1, vlasov_poisson_boundary_surfx_2x2v_ser_p2 + }, // 3 + {NULL, vlasov_poisson_boundary_surfx_2x3v_ser_p1, vlasov_poisson_boundary_surfx_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Streaming boundary surface kernel list: y-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list ser_poisson_stream_boundary_surf_y_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, vlasov_poisson_boundary_surfy_2x2v_ser_p1, vlasov_poisson_boundary_surfy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_boundary_surfy_2x3v_ser_p1, vlasov_poisson_boundary_surfy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list + ser_poisson_stream_boundary_surf_y_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, vlasov_poisson_boundary_surfy_2x2v_ser_p1, vlasov_poisson_boundary_surfy_2x2v_ser_p2 + }, // 3 + {NULL, vlasov_poisson_boundary_surfy_2x3v_ser_p1, vlasov_poisson_boundary_surfy_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Streaming boundary surface kernel list: z-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list ser_poisson_stream_boundary_surf_z_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list + ser_poisson_stream_boundary_surf_z_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // @@ -158,232 +190,242 @@ static const gkyl_dg_vlasov_poisson_stream_boundary_surf_kern_list ser_poisson_s // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_vlasov_poisson_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_vol_1x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_vol_1x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_vol_1x1v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_vol_1x1v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_vol_1x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_vol_1x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_vol_1x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_vol_1x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_vol_1x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_vol_1x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_vol_1x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_vol_1x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_vol_1x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_vol_1x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_vol_2x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_vol_2x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_vol_2x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_vol_2x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_vol_2x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_vol_2x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_vol_2x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_vol_2x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_vol_2x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_vol_2x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_vol_2x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_vol_2x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } // Volume kernel list, phi only -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_vol_kern_list ser_poisson_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_poisson_vol_kern_list ser_poisson_vol_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_poisson_vol_1x1v_ser_p1, kernel_vlasov_poisson_vol_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_poisson_vol_1x2v_ser_p1, kernel_vlasov_poisson_vol_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_poisson_vol_1x3v_ser_p1, kernel_vlasov_poisson_vol_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_poisson_vol_1x1v_ser_p1, kernel_vlasov_poisson_vol_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_poisson_vol_1x2v_ser_p1, kernel_vlasov_poisson_vol_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_poisson_vol_1x3v_ser_p1, kernel_vlasov_poisson_vol_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_poisson_vol_2x2v_ser_p1, kernel_vlasov_poisson_vol_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_poisson_vol_2x3v_ser_p1, kernel_vlasov_poisson_vol_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_poisson_vol_2x2v_ser_p1, kernel_vlasov_poisson_vol_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_poisson_vol_2x3v_ser_p1, kernel_vlasov_poisson_vol_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; // Acceleration (phi only) surface kernel list: vx-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_surf_kern_list ser_poisson_accel_surf_vx_kernels[] = { - // 1x kernels - { NULL, vlasov_poisson_surfvx_1x1v_ser_p1, vlasov_poisson_surfvx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_poisson_surfvx_1x2v_ser_p1, vlasov_poisson_surfvx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_surfvx_1x3v_ser_p1, vlasov_poisson_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_surfvx_2x2v_ser_p1, vlasov_poisson_surfvx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_surfvx_2x3v_ser_p1, vlasov_poisson_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_surf_kern_list + ser_poisson_accel_surf_vx_kernels[] = { + // 1x kernels + {NULL, vlasov_poisson_surfvx_1x1v_ser_p1, vlasov_poisson_surfvx_1x1v_ser_p2}, // 0 + {NULL, vlasov_poisson_surfvx_1x2v_ser_p1, vlasov_poisson_surfvx_1x2v_ser_p2}, // 1 + {NULL, vlasov_poisson_surfvx_1x3v_ser_p1, vlasov_poisson_surfvx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_poisson_surfvx_2x2v_ser_p1, vlasov_poisson_surfvx_2x2v_ser_p2}, // 3 + {NULL, vlasov_poisson_surfvx_2x3v_ser_p1, vlasov_poisson_surfvx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (phi only) surface kernel list: vy-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_surf_kern_list ser_poisson_accel_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, kernel_vlasov_poisson_zero_accel_surf, kernel_vlasov_poisson_zero_accel_surf }, // 1 - { NULL, kernel_vlasov_poisson_zero_accel_surf, kernel_vlasov_poisson_zero_accel_surf }, // 2 - // 2x kernels - { NULL, vlasov_poisson_surfvy_2x2v_ser_p1, vlasov_poisson_surfvy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_surfvy_2x3v_ser_p1, vlasov_poisson_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_surf_kern_list + ser_poisson_accel_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, kernel_vlasov_poisson_zero_accel_surf, kernel_vlasov_poisson_zero_accel_surf}, // 1 + {NULL, kernel_vlasov_poisson_zero_accel_surf, kernel_vlasov_poisson_zero_accel_surf}, // 2 + // 2x kernels + {NULL, vlasov_poisson_surfvy_2x2v_ser_p1, vlasov_poisson_surfvy_2x2v_ser_p2}, // 3 + {NULL, vlasov_poisson_surfvy_2x3v_ser_p1, vlasov_poisson_surfvy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (phi only) surface kernel list: vz-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_surf_kern_list ser_poisson_accel_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, kernel_vlasov_poisson_zero_accel_surf, kernel_vlasov_poisson_zero_accel_surf }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, kernel_vlasov_poisson_zero_accel_surf, kernel_vlasov_poisson_zero_accel_surf }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_surf_kern_list + ser_poisson_accel_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, kernel_vlasov_poisson_zero_accel_surf, kernel_vlasov_poisson_zero_accel_surf}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, kernel_vlasov_poisson_zero_accel_surf, kernel_vlasov_poisson_zero_accel_surf}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (phi only) boundary surface kernel (zero-flux BCs) list: vx-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_accel_boundary_surf_vx_kernels[] = { - // 1x kernels - { NULL, vlasov_poisson_boundary_surfvx_1x1v_ser_p1, vlasov_poisson_boundary_surfvx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_poisson_boundary_surfvx_1x2v_ser_p1, vlasov_poisson_boundary_surfvx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_boundary_surfvx_1x3v_ser_p1, vlasov_poisson_boundary_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_boundary_surfvx_2x2v_ser_p1, vlasov_poisson_boundary_surfvx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_boundary_surfvx_2x3v_ser_p1, vlasov_poisson_boundary_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list + ser_poisson_accel_boundary_surf_vx_kernels[] = { + // 1x kernels + {NULL, vlasov_poisson_boundary_surfvx_1x1v_ser_p1, vlasov_poisson_boundary_surfvx_1x1v_ser_p2 + }, // 0 + {NULL, vlasov_poisson_boundary_surfvx_1x2v_ser_p1, vlasov_poisson_boundary_surfvx_1x2v_ser_p2 + }, // 1 + {NULL, vlasov_poisson_boundary_surfvx_1x3v_ser_p1, vlasov_poisson_boundary_surfvx_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, vlasov_poisson_boundary_surfvx_2x2v_ser_p1, vlasov_poisson_boundary_surfvx_2x2v_ser_p2 + }, // 3 + {NULL, vlasov_poisson_boundary_surfvx_2x3v_ser_p1, vlasov_poisson_boundary_surfvx_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (phi only) boundary surface kernel (zero-flux BCs) list: vy-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_accel_boundary_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, kernel_vlasov_poisson_zero_accel_boundary_surf, kernel_vlasov_poisson_zero_accel_boundary_surf }, // 1 - { NULL, kernel_vlasov_poisson_zero_accel_boundary_surf, kernel_vlasov_poisson_zero_accel_boundary_surf }, // 2 - // 2x kernels - { NULL, vlasov_poisson_boundary_surfvy_2x2v_ser_p1, vlasov_poisson_boundary_surfvy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_boundary_surfvy_2x3v_ser_p1, vlasov_poisson_boundary_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list + ser_poisson_accel_boundary_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, kernel_vlasov_poisson_zero_accel_boundary_surf, + kernel_vlasov_poisson_zero_accel_boundary_surf}, // 1 + {NULL, kernel_vlasov_poisson_zero_accel_boundary_surf, + kernel_vlasov_poisson_zero_accel_boundary_surf}, // 2 + // 2x kernels + {NULL, vlasov_poisson_boundary_surfvy_2x2v_ser_p1, vlasov_poisson_boundary_surfvy_2x2v_ser_p2 + }, // 3 + {NULL, vlasov_poisson_boundary_surfvy_2x3v_ser_p1, vlasov_poisson_boundary_surfvy_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (phi only) boundary surface kernel (zero-flux BCs) list: vz-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_accel_boundary_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, kernel_vlasov_poisson_zero_accel_boundary_surf, kernel_vlasov_poisson_zero_accel_boundary_surf }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, kernel_vlasov_poisson_zero_accel_boundary_surf, kernel_vlasov_poisson_zero_accel_boundary_surf }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list + ser_poisson_accel_boundary_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, kernel_vlasov_poisson_zero_accel_boundary_surf, + kernel_vlasov_poisson_zero_accel_boundary_surf}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, kernel_vlasov_poisson_zero_accel_boundary_surf, + kernel_vlasov_poisson_zero_accel_boundary_surf}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // @@ -391,231 +433,257 @@ static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_ac // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_phiA_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_phiA_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_phiA_vol_1x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_ext_phiA_vol_1x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_phiA_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_phiA_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_phiA_vol_1x1v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_ext_phiA_vol_1x1v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_phiA_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_phiA_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_phiA_vol_1x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_ext_phiA_vol_1x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_phiA_vol_1x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_phiA_vol_1x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_phiA_vol_1x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_ext_phiA_vol_1x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_phiA_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_phiA_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_phiA_vol_1x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_ext_phiA_vol_1x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_phiA_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_phiA_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_phiA_vol_1x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_ext_phiA_vol_1x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_phiA_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_phiA_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_phiA_vol_2x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_ext_phiA_vol_2x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_phiA_vol_2x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_phiA_vol_2x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_phiA_vol_2x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_ext_phiA_vol_2x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_phiA_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_phiA_vol_2x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_phiA_vol_2x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_ext_phiA_vol_2x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_phiA_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_phiA_vol_2x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_phiA_vol_2x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - 0, qIn, qRhsOut); + return vlasov_poisson_ext_phiA_vol_2x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), 0, qIn, qRhsOut + ); } // Volume kernel list (with external phi and A). -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_vol_kern_list ser_poisson_ext_phiA_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_poisson_vol_kern_list ser_poisson_ext_phiA_vol_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_poisson_ext_phiA_vol_1x1v_ser_p1, kernel_vlasov_poisson_ext_phiA_vol_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_poisson_ext_phiA_vol_1x2v_ser_p1, kernel_vlasov_poisson_ext_phiA_vol_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_poisson_ext_phiA_vol_1x3v_ser_p1, kernel_vlasov_poisson_ext_phiA_vol_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_poisson_ext_phiA_vol_1x1v_ser_p1, + kernel_vlasov_poisson_ext_phiA_vol_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_poisson_ext_phiA_vol_1x2v_ser_p1, + kernel_vlasov_poisson_ext_phiA_vol_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_poisson_ext_phiA_vol_1x3v_ser_p1, + kernel_vlasov_poisson_ext_phiA_vol_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_poisson_ext_phiA_vol_2x2v_ser_p1, kernel_vlasov_poisson_ext_phiA_vol_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_poisson_ext_phiA_vol_2x3v_ser_p1, kernel_vlasov_poisson_ext_phiA_vol_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_poisson_ext_phiA_vol_2x2v_ser_p1, + kernel_vlasov_poisson_ext_phiA_vol_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_poisson_ext_phiA_vol_2x3v_ser_p1, + kernel_vlasov_poisson_ext_phiA_vol_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; // Acceleration (phi and A) surface kernel list: vx-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_surf_kern_list ser_poisson_ext_phiA_accel_surf_vx_kernels[] = { - // 1x kernels - { NULL, vlasov_poisson_ext_phiA_surfvx_1x1v_ser_p1, vlasov_poisson_ext_phiA_surfvx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_poisson_ext_phiA_surfvx_1x2v_ser_p1, vlasov_poisson_ext_phiA_surfvx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_ext_phiA_surfvx_1x3v_ser_p1, vlasov_poisson_ext_phiA_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_ext_phiA_surfvx_2x2v_ser_p1, vlasov_poisson_ext_phiA_surfvx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_ext_phiA_surfvx_2x3v_ser_p1, vlasov_poisson_ext_phiA_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_surf_kern_list + ser_poisson_ext_phiA_accel_surf_vx_kernels[] = { + // 1x kernels + {NULL, vlasov_poisson_ext_phiA_surfvx_1x1v_ser_p1, vlasov_poisson_ext_phiA_surfvx_1x1v_ser_p2 + }, // 0 + {NULL, vlasov_poisson_ext_phiA_surfvx_1x2v_ser_p1, vlasov_poisson_ext_phiA_surfvx_1x2v_ser_p2 + }, // 1 + {NULL, vlasov_poisson_ext_phiA_surfvx_1x3v_ser_p1, vlasov_poisson_ext_phiA_surfvx_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, vlasov_poisson_ext_phiA_surfvx_2x2v_ser_p1, vlasov_poisson_ext_phiA_surfvx_2x2v_ser_p2 + }, // 3 + {NULL, vlasov_poisson_ext_phiA_surfvx_2x3v_ser_p1, vlasov_poisson_ext_phiA_surfvx_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (phi and A) surface kernel list: vy-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_surf_kern_list ser_poisson_ext_phiA_accel_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, vlasov_poisson_ext_phiA_surfvy_1x2v_ser_p1, vlasov_poisson_ext_phiA_surfvy_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_ext_phiA_surfvy_1x3v_ser_p1, vlasov_poisson_ext_phiA_surfvy_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_ext_phiA_surfvy_2x2v_ser_p1, vlasov_poisson_ext_phiA_surfvy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_ext_phiA_surfvy_2x3v_ser_p1, vlasov_poisson_ext_phiA_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_surf_kern_list + ser_poisson_ext_phiA_accel_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, vlasov_poisson_ext_phiA_surfvy_1x2v_ser_p1, vlasov_poisson_ext_phiA_surfvy_1x2v_ser_p2 + }, // 1 + {NULL, vlasov_poisson_ext_phiA_surfvy_1x3v_ser_p1, vlasov_poisson_ext_phiA_surfvy_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, vlasov_poisson_ext_phiA_surfvy_2x2v_ser_p1, vlasov_poisson_ext_phiA_surfvy_2x2v_ser_p2 + }, // 3 + {NULL, vlasov_poisson_ext_phiA_surfvy_2x3v_ser_p1, vlasov_poisson_ext_phiA_surfvy_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (phi and A) surface kernel list: vz-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_surf_kern_list ser_poisson_ext_phiA_accel_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, vlasov_poisson_ext_phiA_surfvz_1x3v_ser_p1, vlasov_poisson_ext_phiA_surfvz_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, vlasov_poisson_ext_phiA_surfvz_2x3v_ser_p1, vlasov_poisson_ext_phiA_surfvz_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_surf_kern_list + ser_poisson_ext_phiA_accel_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, vlasov_poisson_ext_phiA_surfvz_1x3v_ser_p1, vlasov_poisson_ext_phiA_surfvz_1x3v_ser_p2 + }, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, vlasov_poisson_ext_phiA_surfvz_2x3v_ser_p1, vlasov_poisson_ext_phiA_surfvz_2x3v_ser_p2 + }, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (phi and A) boundary surface kernel (zero-flux BCs) list: vx-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_ext_phiA_accel_boundary_surf_vx_kernels[] = { - // 1x kernels - { NULL, vlasov_poisson_ext_phiA_boundary_surfvx_1x1v_ser_p1, vlasov_poisson_ext_phiA_boundary_surfvx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_poisson_ext_phiA_boundary_surfvx_1x2v_ser_p1, vlasov_poisson_ext_phiA_boundary_surfvx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_ext_phiA_boundary_surfvx_1x3v_ser_p1, vlasov_poisson_ext_phiA_boundary_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_ext_phiA_boundary_surfvx_2x2v_ser_p1, vlasov_poisson_ext_phiA_boundary_surfvx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_ext_phiA_boundary_surfvx_2x3v_ser_p1, vlasov_poisson_ext_phiA_boundary_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list + ser_poisson_ext_phiA_accel_boundary_surf_vx_kernels[] = { + // 1x kernels + {NULL, vlasov_poisson_ext_phiA_boundary_surfvx_1x1v_ser_p1, + vlasov_poisson_ext_phiA_boundary_surfvx_1x1v_ser_p2}, // 0 + {NULL, vlasov_poisson_ext_phiA_boundary_surfvx_1x2v_ser_p1, + vlasov_poisson_ext_phiA_boundary_surfvx_1x2v_ser_p2}, // 1 + {NULL, vlasov_poisson_ext_phiA_boundary_surfvx_1x3v_ser_p1, + vlasov_poisson_ext_phiA_boundary_surfvx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_poisson_ext_phiA_boundary_surfvx_2x2v_ser_p1, + vlasov_poisson_ext_phiA_boundary_surfvx_2x2v_ser_p2}, // 3 + {NULL, vlasov_poisson_ext_phiA_boundary_surfvx_2x3v_ser_p1, + vlasov_poisson_ext_phiA_boundary_surfvx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (phi and A) boundary surface kernel (zero-flux BCs) list: vy-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_ext_phiA_accel_boundary_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, vlasov_poisson_ext_phiA_boundary_surfvy_1x2v_ser_p1, vlasov_poisson_ext_phiA_boundary_surfvy_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_ext_phiA_boundary_surfvy_1x3v_ser_p1, vlasov_poisson_ext_phiA_boundary_surfvy_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_ext_phiA_boundary_surfvy_2x2v_ser_p1, vlasov_poisson_ext_phiA_boundary_surfvy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_ext_phiA_boundary_surfvy_2x3v_ser_p1, vlasov_poisson_ext_phiA_boundary_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list + ser_poisson_ext_phiA_accel_boundary_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, vlasov_poisson_ext_phiA_boundary_surfvy_1x2v_ser_p1, + vlasov_poisson_ext_phiA_boundary_surfvy_1x2v_ser_p2}, // 1 + {NULL, vlasov_poisson_ext_phiA_boundary_surfvy_1x3v_ser_p1, + vlasov_poisson_ext_phiA_boundary_surfvy_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_poisson_ext_phiA_boundary_surfvy_2x2v_ser_p1, + vlasov_poisson_ext_phiA_boundary_surfvy_2x2v_ser_p2}, // 3 + {NULL, vlasov_poisson_ext_phiA_boundary_surfvy_2x3v_ser_p1, + vlasov_poisson_ext_phiA_boundary_surfvy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (phi and A) boundary surface kernel (zero-flux BCs) list: vz-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_ext_phiA_accel_boundary_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, vlasov_poisson_ext_phiA_boundary_surfvz_1x3v_ser_p1, vlasov_poisson_ext_phiA_boundary_surfvz_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, vlasov_poisson_ext_phiA_boundary_surfvz_2x3v_ser_p1, vlasov_poisson_ext_phiA_boundary_surfvz_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list + ser_poisson_ext_phiA_accel_boundary_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, vlasov_poisson_ext_phiA_boundary_surfvz_1x3v_ser_p1, + vlasov_poisson_ext_phiA_boundary_surfvz_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, vlasov_poisson_ext_phiA_boundary_surfvz_2x3v_ser_p1, + vlasov_poisson_ext_phiA_boundary_surfvz_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // @@ -623,245 +691,260 @@ static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_ex // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_EB_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_EB_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_EB_vol_1x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - qIn, qRhsOut); + return vlasov_poisson_ext_EB_vol_1x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_EB_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_EB_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_EB_vol_1x1v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - qIn, qRhsOut); + return vlasov_poisson_ext_EB_vol_1x1v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_EB_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_EB_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_EB_vol_1x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - qIn, qRhsOut); + return vlasov_poisson_ext_EB_vol_1x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_EB_vol_1x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_EB_vol_1x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_EB_vol_1x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - qIn, qRhsOut); + return vlasov_poisson_ext_EB_vol_1x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_EB_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_EB_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_EB_vol_1x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - qIn, qRhsOut); + return vlasov_poisson_ext_EB_vol_1x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_EB_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_EB_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_EB_vol_1x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - qIn, qRhsOut); + return vlasov_poisson_ext_EB_vol_1x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_EB_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_EB_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_EB_vol_2x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - qIn, qRhsOut); + return vlasov_poisson_ext_EB_vol_2x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_EB_vol_2x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_EB_vol_2x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_EB_vol_2x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - qIn, qRhsOut); + return vlasov_poisson_ext_EB_vol_2x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_EB_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_EB_vol_2x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_EB_vol_2x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - qIn, qRhsOut); + return vlasov_poisson_ext_EB_vol_2x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_poisson_ext_EB_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_poisson_ext_EB_vol_2x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_poisson_ext_EB_vol_2x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - qIn, qRhsOut); + return vlasov_poisson_ext_EB_vol_2x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), qIn, qRhsOut + ); } // Volume kernel list (with external E and B). -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_vol_kern_list ser_poisson_ext_EB_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_poisson_vol_kern_list ser_poisson_ext_EB_vol_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_poisson_ext_EB_vol_1x1v_ser_p1, kernel_vlasov_poisson_ext_EB_vol_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_poisson_ext_EB_vol_1x2v_ser_p1, kernel_vlasov_poisson_ext_EB_vol_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_poisson_ext_EB_vol_1x3v_ser_p1, kernel_vlasov_poisson_ext_EB_vol_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_poisson_ext_EB_vol_1x1v_ser_p1, kernel_vlasov_poisson_ext_EB_vol_1x1v_ser_p2 + }, // 0 + {NULL, kernel_vlasov_poisson_ext_EB_vol_1x2v_ser_p1, kernel_vlasov_poisson_ext_EB_vol_1x2v_ser_p2 + }, // 1 + {NULL, kernel_vlasov_poisson_ext_EB_vol_1x3v_ser_p1, kernel_vlasov_poisson_ext_EB_vol_1x3v_ser_p2 + }, // 2 // 2x kernels - { NULL, kernel_vlasov_poisson_ext_EB_vol_2x2v_ser_p1, kernel_vlasov_poisson_ext_EB_vol_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_poisson_ext_EB_vol_2x3v_ser_p1, kernel_vlasov_poisson_ext_EB_vol_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_poisson_ext_EB_vol_2x2v_ser_p1, kernel_vlasov_poisson_ext_EB_vol_2x2v_ser_p2 + }, // 3 + {NULL, kernel_vlasov_poisson_ext_EB_vol_2x3v_ser_p1, kernel_vlasov_poisson_ext_EB_vol_2x3v_ser_p2 + }, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; // Acceleration (E and B) surface kernel list: vx-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_surf_kern_list ser_poisson_ext_EB_accel_surf_vx_kernels[] = { - // 1x kernels - { NULL, vlasov_poisson_ext_EB_surfvx_1x1v_ser_p1, vlasov_poisson_ext_EB_surfvx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_poisson_ext_EB_surfvx_1x2v_ser_p1, vlasov_poisson_ext_EB_surfvx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_ext_EB_surfvx_1x3v_ser_p1, vlasov_poisson_ext_EB_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_ext_EB_surfvx_2x2v_ser_p1, vlasov_poisson_ext_EB_surfvx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_ext_EB_surfvx_2x3v_ser_p1, vlasov_poisson_ext_EB_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_surf_kern_list + ser_poisson_ext_EB_accel_surf_vx_kernels[] = { + // 1x kernels + {NULL, vlasov_poisson_ext_EB_surfvx_1x1v_ser_p1, vlasov_poisson_ext_EB_surfvx_1x1v_ser_p2}, // 0 + {NULL, vlasov_poisson_ext_EB_surfvx_1x2v_ser_p1, vlasov_poisson_ext_EB_surfvx_1x2v_ser_p2}, // 1 + {NULL, vlasov_poisson_ext_EB_surfvx_1x3v_ser_p1, vlasov_poisson_ext_EB_surfvx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_poisson_ext_EB_surfvx_2x2v_ser_p1, vlasov_poisson_ext_EB_surfvx_2x2v_ser_p2}, // 3 + {NULL, vlasov_poisson_ext_EB_surfvx_2x3v_ser_p1, vlasov_poisson_ext_EB_surfvx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (E and B) surface kernel list: vy-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_surf_kern_list ser_poisson_ext_EB_accel_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, vlasov_poisson_ext_EB_surfvy_1x2v_ser_p1, vlasov_poisson_ext_EB_surfvy_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_ext_EB_surfvy_1x3v_ser_p1, vlasov_poisson_ext_EB_surfvy_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_ext_EB_surfvy_2x2v_ser_p1, vlasov_poisson_ext_EB_surfvy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_ext_EB_surfvy_2x3v_ser_p1, vlasov_poisson_ext_EB_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_surf_kern_list + ser_poisson_ext_EB_accel_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, vlasov_poisson_ext_EB_surfvy_1x2v_ser_p1, vlasov_poisson_ext_EB_surfvy_1x2v_ser_p2}, // 1 + {NULL, vlasov_poisson_ext_EB_surfvy_1x3v_ser_p1, vlasov_poisson_ext_EB_surfvy_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_poisson_ext_EB_surfvy_2x2v_ser_p1, vlasov_poisson_ext_EB_surfvy_2x2v_ser_p2}, // 3 + {NULL, vlasov_poisson_ext_EB_surfvy_2x3v_ser_p1, vlasov_poisson_ext_EB_surfvy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (E and B) surface kernel list: vz-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_surf_kern_list ser_poisson_ext_EB_accel_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, vlasov_poisson_ext_EB_surfvz_1x3v_ser_p1, vlasov_poisson_ext_EB_surfvz_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, vlasov_poisson_ext_EB_surfvz_2x3v_ser_p1, vlasov_poisson_ext_EB_surfvz_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_surf_kern_list + ser_poisson_ext_EB_accel_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, vlasov_poisson_ext_EB_surfvz_1x3v_ser_p1, vlasov_poisson_ext_EB_surfvz_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, vlasov_poisson_ext_EB_surfvz_2x3v_ser_p1, vlasov_poisson_ext_EB_surfvz_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (E and B) boundary surface kernel (zero-flux BCs) list: vx-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_ext_EB_accel_boundary_surf_vx_kernels[] = { - // 1x kernels - { NULL, vlasov_poisson_ext_EB_boundary_surfvx_1x1v_ser_p1, vlasov_poisson_ext_EB_boundary_surfvx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_poisson_ext_EB_boundary_surfvx_1x2v_ser_p1, vlasov_poisson_ext_EB_boundary_surfvx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_ext_EB_boundary_surfvx_1x3v_ser_p1, vlasov_poisson_ext_EB_boundary_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_ext_EB_boundary_surfvx_2x2v_ser_p1, vlasov_poisson_ext_EB_boundary_surfvx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_ext_EB_boundary_surfvx_2x3v_ser_p1, vlasov_poisson_ext_EB_boundary_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list + ser_poisson_ext_EB_accel_boundary_surf_vx_kernels[] = { + // 1x kernels + {NULL, vlasov_poisson_ext_EB_boundary_surfvx_1x1v_ser_p1, + vlasov_poisson_ext_EB_boundary_surfvx_1x1v_ser_p2}, // 0 + {NULL, vlasov_poisson_ext_EB_boundary_surfvx_1x2v_ser_p1, + vlasov_poisson_ext_EB_boundary_surfvx_1x2v_ser_p2}, // 1 + {NULL, vlasov_poisson_ext_EB_boundary_surfvx_1x3v_ser_p1, + vlasov_poisson_ext_EB_boundary_surfvx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_poisson_ext_EB_boundary_surfvx_2x2v_ser_p1, + vlasov_poisson_ext_EB_boundary_surfvx_2x2v_ser_p2}, // 3 + {NULL, vlasov_poisson_ext_EB_boundary_surfvx_2x3v_ser_p1, + vlasov_poisson_ext_EB_boundary_surfvx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (E and B) boundary surface kernel (zero-flux BCs) list: vy-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_ext_EB_accel_boundary_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, vlasov_poisson_ext_EB_boundary_surfvy_1x2v_ser_p1, vlasov_poisson_ext_EB_boundary_surfvy_1x2v_ser_p2 }, // 1 - { NULL, vlasov_poisson_ext_EB_boundary_surfvy_1x3v_ser_p1, vlasov_poisson_ext_EB_boundary_surfvy_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_poisson_ext_EB_boundary_surfvy_2x2v_ser_p1, vlasov_poisson_ext_EB_boundary_surfvy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_poisson_ext_EB_boundary_surfvy_2x3v_ser_p1, vlasov_poisson_ext_EB_boundary_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list + ser_poisson_ext_EB_accel_boundary_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, vlasov_poisson_ext_EB_boundary_surfvy_1x2v_ser_p1, + vlasov_poisson_ext_EB_boundary_surfvy_1x2v_ser_p2}, // 1 + {NULL, vlasov_poisson_ext_EB_boundary_surfvy_1x3v_ser_p1, + vlasov_poisson_ext_EB_boundary_surfvy_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_poisson_ext_EB_boundary_surfvy_2x2v_ser_p1, + vlasov_poisson_ext_EB_boundary_surfvy_2x2v_ser_p2}, // 3 + {NULL, vlasov_poisson_ext_EB_boundary_surfvy_2x3v_ser_p1, + vlasov_poisson_ext_EB_boundary_surfvy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // Acceleration (E and B) boundary surface kernel (zero-flux BCs) list: vz-direction -GKYL_CU_D -static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_ext_EB_accel_boundary_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, vlasov_poisson_ext_EB_boundary_surfvz_1x3v_ser_p1, vlasov_poisson_ext_EB_boundary_surfvz_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, vlasov_poisson_ext_EB_boundary_surfvz_2x3v_ser_p1, vlasov_poisson_ext_EB_boundary_surfvz_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, NULL, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list + ser_poisson_ext_EB_accel_boundary_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, vlasov_poisson_ext_EB_boundary_surfvz_1x3v_ser_p1, + vlasov_poisson_ext_EB_boundary_surfvz_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, vlasov_poisson_ext_EB_boundary_surfvz_2x3v_ser_p1, + vlasov_poisson_ext_EB_boundary_surfvz_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, NULL, NULL} // 5 }; // "Choose Kernel" based on cdim, vdim and polyorder -#define CK(lst,cdim,vd,poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] +#define CK(lst, cdim, vd, poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] /** * Free vlasov eqn object. @@ -870,51 +953,44 @@ static const gkyl_dg_vlasov_poisson_accel_boundary_surf_kern_list ser_poisson_ex */ void gkyl_vlasov_poisson_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); if (dir < vlasov->cdim) { - return vlasov->stream_surf[dir](xcC, dxC, - qInL, qInC, qInR, qRhsOut); - } - else { + return vlasov->stream_surf[dir](xcC, dxC, qInL, qInC, qInR, qRhsOut); + } else { long cidx = gkyl_range_idx(&vlasov->conf_range, idxC); - return vlasov->accel_surf[dir-vlasov->cdim](xcC, dxC, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - qInL, qInC, qInR, qRhsOut); + return vlasov->accel_surf[dir - vlasov->cdim]( + xcC, dxC, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), qInL, qInC, qInR, + qRhsOut + ); } } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_poisson *vlasov = container_of(eqn, struct dg_vlasov_poisson, eqn); if (dir < vlasov->cdim) { - return vlasov->stream_boundary_surf[dir](xcSkin, dxSkin, - edge, qInEdge, qInSkin, qRhsOut); - } - else { + return vlasov->stream_boundary_surf[dir](xcSkin, dxSkin, edge, qInEdge, qInSkin, qRhsOut); + } else { long cidx = gkyl_range_idx(&vlasov->conf_range, idxSkin); - return vlasov->accel_boundary_surf[dir-vlasov->cdim](xcSkin, dxSkin, - (const double*) gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), - (const double*) gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), - edge, qInEdge, qInSkin, qRhsOut); + return vlasov->accel_boundary_surf[dir - vlasov->cdim]( + xcSkin, dxSkin, (const double *)gkyl_array_cfetch(vlasov->auxfields.potentials, cidx), + (const double *)gkyl_array_cfetch(vlasov->auxfields.fields_ext, cidx), edge, qInEdge, qInSkin, + qRhsOut + ); } return 0.; } @@ -931,9 +1007,11 @@ boundary_surf(const struct gkyl_dg_eqn *eqn, * @param field_id enum to determine what type of fields (e.g. phi or phi and A_ext). * @return Pointer to Vlasov equation object */ -struct gkyl_dg_eqn* gkyl_dg_vlasov_poisson_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, const struct gkyl_range* phase_range, - enum gkyl_model_id model_id, enum gkyl_field_id field_id); +struct gkyl_dg_eqn *gkyl_dg_vlasov_poisson_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *phase_range, + enum gkyl_model_id model_id, enum gkyl_field_id field_id +); /** * CUDA device function to set auxiliary fields (e.g. q/m*EM) needed in updating the force terms. @@ -941,5 +1019,7 @@ struct gkyl_dg_eqn* gkyl_dg_vlasov_poisson_cu_dev_new(const struct gkyl_basis* c * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_vlasov_poisson_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_poisson_auxfields auxin); +void gkyl_vlasov_poisson_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_poisson_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_vlasov_priv.h b/vlasov/zero/gkyl_dg_vlasov_priv.h index 9a4961932d..6c595b99db 100644 --- a/vlasov/zero/gkyl_dg_vlasov_priv.h +++ b/vlasov/zero/gkyl_dg_vlasov_priv.h @@ -10,44 +10,64 @@ #include // Types for various kernels -typedef double (*vlasov_stream_surf_t)(const double *w, const double *dxv, - const double *alpha_surf_l, const double *alpha_surf_r, - const double *sgn_alpha_surf_l, const double *sgn_alpha_surf_r, - const int *const_sgn_alpha_l, const int *const_sgn_alpha_r, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); - -typedef double (*vlasov_stream_boundary_surf_t)(const double *w, const double *dxv, - const double *alpha_surf_edge, const double *alpha_surf_skin, - const double *sgn_alpha_surf_edge, const double *sgn_alpha_surf_skin, - const int *const_sgn_alpha_edge, const int *const_sgn_alpha_skin, - const int edge, const double *fEdge, const double *fSkin, double* GKYL_RESTRICT out); - -typedef double (*vlasov_accel_surf_t)(const double *w, const double *dxv, - const double *field, const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); - -typedef double (*vlasov_accel_boundary_surf_t)(const double *w, const double *dxv, - const double *field, const int edge, const double *fEdge, const double *fSkin, double* GKYL_RESTRICT out); +typedef double (*vlasov_stream_surf_t)( + const double *w, const double *dxv, const double *alpha_surf_l, const double *alpha_surf_r, + const double *sgn_alpha_surf_l, const double *sgn_alpha_surf_r, const int *const_sgn_alpha_l, + const int *const_sgn_alpha_r, const double *fl, const double *fc, const double *fr, + double *GKYL_RESTRICT out +); + +typedef double (*vlasov_stream_boundary_surf_t)( + const double *w, const double *dxv, const double *alpha_surf_edge, const double *alpha_surf_skin, + const double *sgn_alpha_surf_edge, const double *sgn_alpha_surf_skin, + const int *const_sgn_alpha_edge, const int *const_sgn_alpha_skin, const int edge, + const double *fEdge, const double *fSkin, double *GKYL_RESTRICT out +); + +typedef double (*vlasov_accel_surf_t)( + const double *w, const double *dxv, const double *field, const double *fl, const double *fc, + const double *fr, double *GKYL_RESTRICT out +); + +typedef double (*vlasov_accel_boundary_surf_t)( + const double *w, const double *dxv, const double *field, const int edge, const double *fEdge, + const double *fSkin, double *GKYL_RESTRICT out +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_vlasov_stream_vol_kern_list; -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_vlasov_vol_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_vlasov_stream_vol_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_vlasov_vol_kern_list; -typedef struct { vlasov_stream_surf_t kernels[3]; } gkyl_dg_vlasov_stream_surf_kern_list; +typedef struct { + vlasov_stream_surf_t kernels[3]; +} gkyl_dg_vlasov_stream_surf_kern_list; -typedef struct { vlasov_stream_boundary_surf_t kernels[3]; } gkyl_dg_vlasov_stream_boundary_surf_kern_list; +typedef struct { + vlasov_stream_boundary_surf_t kernels[3]; +} gkyl_dg_vlasov_stream_boundary_surf_kern_list; -typedef struct { vlasov_accel_surf_t kernels[3]; } gkyl_dg_vlasov_accel_surf_kern_list; +typedef struct { + vlasov_accel_surf_t kernels[3]; +} gkyl_dg_vlasov_accel_surf_kern_list; -typedef struct { vlasov_accel_boundary_surf_t kernels[3]; } gkyl_dg_vlasov_accel_boundary_surf_kern_list; +typedef struct { + vlasov_accel_boundary_surf_t kernels[3]; +} gkyl_dg_vlasov_accel_boundary_surf_kern_list; struct dg_vlasov { struct gkyl_dg_eqn eqn; // Base object. @@ -67,106 +87,105 @@ struct dg_vlasov { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x1v_ser_p1(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x1v_ser_p2(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x2v_ser_p1(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x2v_ser_p2(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x3v_ser_p1(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x3v_ser_p2(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_2x2v_ser_p1(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_2x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_2x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_2x2v_ser_p2(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_2x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_2x3v_ser_p1(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_2x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_2x3v_ser_p2(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_3x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_3x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_3x3v_ser_p1(xc, dx, qIn, qRhsOut); } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_vlasov_stream_vol_kern_list ser_stream_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_stream_vol_kern_list ser_stream_vol_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_stream_vol_1x1v_ser_p1, kernel_vlasov_stream_vol_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_stream_vol_1x2v_ser_p1, kernel_vlasov_stream_vol_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_stream_vol_1x3v_ser_p1, kernel_vlasov_stream_vol_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_stream_vol_1x1v_ser_p1, kernel_vlasov_stream_vol_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_stream_vol_1x2v_ser_p1, kernel_vlasov_stream_vol_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_stream_vol_1x3v_ser_p1, kernel_vlasov_stream_vol_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_stream_vol_2x2v_ser_p1, kernel_vlasov_stream_vol_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_stream_vol_2x3v_ser_p1, kernel_vlasov_stream_vol_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_stream_vol_2x2v_ser_p1, kernel_vlasov_stream_vol_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_stream_vol_2x3v_ser_p1, kernel_vlasov_stream_vol_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_stream_vol_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_vlasov_stream_vol_3x3v_ser_p1, NULL} // 5 }; // @@ -174,106 +193,105 @@ static const gkyl_dg_vlasov_stream_vol_kern_list ser_stream_vol_kernels[] = { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x1v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x1v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x1v_tensor_p1(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x1v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x1v_tensor_p2(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x2v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x2v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x2v_tensor_p1(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x2v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x2v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x2v_tensor_p2(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x3v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x3v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x3v_tensor_p1(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_1x3v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_1x3v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_1x3v_tensor_p2(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_2x2v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_2x2v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_2x2v_tensor_p1(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_2x2v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_2x2v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_2x2v_tensor_p2(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_2x3v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_2x3v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_2x3v_tensor_p1(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_2x3v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_2x3v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_2x3v_tensor_p2(xc, dx, qIn, qRhsOut); } -GKYL_CU_DH -static double -kernel_vlasov_stream_vol_3x3v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_stream_vol_3x3v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { return vlasov_stream_vol_3x3v_tensor_p1(xc, dx, qIn, qRhsOut); } // Volume kernel list -GKYL_CU_D -static const gkyl_dg_vlasov_stream_vol_kern_list tensor_stream_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_stream_vol_kern_list tensor_stream_vol_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_stream_vol_1x1v_tensor_p1, kernel_vlasov_stream_vol_1x1v_tensor_p2 }, // 0 - { NULL, kernel_vlasov_stream_vol_1x2v_tensor_p1, kernel_vlasov_stream_vol_1x2v_tensor_p2 }, // 1 - { NULL, kernel_vlasov_stream_vol_1x3v_tensor_p1, kernel_vlasov_stream_vol_1x3v_tensor_p2 }, // 2 + {NULL, kernel_vlasov_stream_vol_1x1v_tensor_p1, kernel_vlasov_stream_vol_1x1v_tensor_p2}, // 0 + {NULL, kernel_vlasov_stream_vol_1x2v_tensor_p1, kernel_vlasov_stream_vol_1x2v_tensor_p2}, // 1 + {NULL, kernel_vlasov_stream_vol_1x3v_tensor_p1, kernel_vlasov_stream_vol_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_stream_vol_2x2v_tensor_p1, kernel_vlasov_stream_vol_2x2v_tensor_p2 }, // 3 - { NULL, kernel_vlasov_stream_vol_2x3v_tensor_p1, kernel_vlasov_stream_vol_2x3v_tensor_p2 }, // 4 + {NULL, kernel_vlasov_stream_vol_2x2v_tensor_p1, kernel_vlasov_stream_vol_2x2v_tensor_p2}, // 3 + {NULL, kernel_vlasov_stream_vol_2x3v_tensor_p1, kernel_vlasov_stream_vol_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_stream_vol_3x3v_tensor_p1, NULL }, // 5 + {NULL, kernel_vlasov_stream_vol_3x3v_tensor_p1, NULL} // 5 }; // @@ -281,160 +299,159 @@ static const gkyl_dg_vlasov_stream_vol_kern_list tensor_stream_vol_kernels[] = { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_vlasov_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x1v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x1v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_1x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_2x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_2x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_2x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_2x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_2x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_2x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_2x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_2x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_2x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_2x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_2x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_2x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_3x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_3x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_3x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_3x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_D -static const gkyl_dg_vlasov_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_vol_1x1v_ser_p1, kernel_vlasov_vol_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_vol_1x2v_ser_p1, kernel_vlasov_vol_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_vol_1x3v_ser_p1, kernel_vlasov_vol_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_vol_1x1v_ser_p1, kernel_vlasov_vol_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_vol_1x2v_ser_p1, kernel_vlasov_vol_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_vol_1x3v_ser_p1, kernel_vlasov_vol_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_vol_2x2v_ser_p1, kernel_vlasov_vol_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_vol_2x3v_ser_p1, kernel_vlasov_vol_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_vol_2x2v_ser_p1, kernel_vlasov_vol_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_vol_2x3v_ser_p1, kernel_vlasov_vol_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_vol_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_vlasov_vol_3x3v_ser_p1, NULL} // 5 }; // @@ -442,501 +459,487 @@ static const gkyl_dg_vlasov_vol_kern_list ser_vol_kernels[] = { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_vlasov_vol_1x1v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x1v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x1v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x1v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_1x1v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x1v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x1v_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x1v_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_1x2v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x2v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x2v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x2v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_1x2v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x2v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x2v_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x2v_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_1x3v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x3v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x3v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x3v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_1x3v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_1x3v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_1x3v_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_1x3v_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_2x2v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_2x2v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_2x2v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_2x2v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_2x2v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_2x2v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_2x2v_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_2x2v_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_2x3v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_2x3v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_2x3v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_2x3v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_2x3v_tensor_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_2x3v_tensor_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_2x3v_tensor_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_2x3v_tensor_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_vol_3x3v_tensor_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_vol_3x3v_tensor_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); long cidx = gkyl_range_idx(&vlasov->conf_range, idx); - return vlasov_vol_3x3v_tensor_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx), - qIn, qRhsOut); + return vlasov_vol_3x3v_tensor_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx), qIn, qRhsOut + ); } -GKYL_CU_D -static const gkyl_dg_vlasov_vol_kern_list tensor_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_vol_kern_list tensor_vol_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_vol_1x1v_tensor_p1, kernel_vlasov_vol_1x1v_tensor_p2 }, // 0 - { NULL, kernel_vlasov_vol_1x2v_tensor_p1, kernel_vlasov_vol_1x2v_tensor_p2 }, // 1 - { NULL, kernel_vlasov_vol_1x3v_tensor_p1, kernel_vlasov_vol_1x3v_tensor_p2 }, // 2 + {NULL, kernel_vlasov_vol_1x1v_tensor_p1, kernel_vlasov_vol_1x1v_tensor_p2}, // 0 + {NULL, kernel_vlasov_vol_1x2v_tensor_p1, kernel_vlasov_vol_1x2v_tensor_p2}, // 1 + {NULL, kernel_vlasov_vol_1x3v_tensor_p1, kernel_vlasov_vol_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_vol_2x2v_tensor_p1, kernel_vlasov_vol_2x2v_tensor_p2 }, // 3 - { NULL, kernel_vlasov_vol_2x3v_tensor_p1, kernel_vlasov_vol_2x3v_tensor_p2 }, // 4 + {NULL, kernel_vlasov_vol_2x2v_tensor_p1, kernel_vlasov_vol_2x2v_tensor_p2}, // 3 + {NULL, kernel_vlasov_vol_2x3v_tensor_p1, kernel_vlasov_vol_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_vol_3x3v_tensor_p1, NULL }, // 5 + {NULL, kernel_vlasov_vol_3x3v_tensor_p1, NULL} // 5 }; // Streaming surface kernel list: x-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_surf_kern_list ser_stream_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_stream_surf_kern_list ser_stream_surf_x_kernels[] = { // 1x kernels - { NULL, vlasov_surfx_1x1v_ser_p1, vlasov_surfx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_surfx_1x2v_ser_p1, vlasov_surfx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_surfx_1x3v_ser_p1, vlasov_surfx_1x3v_ser_p2 }, // 2 + {NULL, vlasov_surfx_1x1v_ser_p1, vlasov_surfx_1x1v_ser_p2}, // 0 + {NULL, vlasov_surfx_1x2v_ser_p1, vlasov_surfx_1x2v_ser_p2}, // 1 + {NULL, vlasov_surfx_1x3v_ser_p1, vlasov_surfx_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_surfx_2x2v_ser_p1, vlasov_surfx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_surfx_2x3v_ser_p1, vlasov_surfx_2x3v_ser_p2 }, // 4 + {NULL, vlasov_surfx_2x2v_ser_p1, vlasov_surfx_2x2v_ser_p2}, // 3 + {NULL, vlasov_surfx_2x3v_ser_p1, vlasov_surfx_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_surfx_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_surfx_3x3v_ser_p1, NULL} // 5 }; // Streaming surface kernel list: x-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_surf_kern_list tensor_stream_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_stream_surf_kern_list tensor_stream_surf_x_kernels[] = { // 1x kernels - { NULL, vlasov_surfx_1x1v_tensor_p1, vlasov_surfx_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_surfx_1x2v_tensor_p1, vlasov_surfx_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_surfx_1x3v_tensor_p1, vlasov_surfx_1x3v_tensor_p2 }, // 2 + {NULL, vlasov_surfx_1x1v_tensor_p1, vlasov_surfx_1x1v_tensor_p2}, // 0 + {NULL, vlasov_surfx_1x2v_tensor_p1, vlasov_surfx_1x2v_tensor_p2}, // 1 + {NULL, vlasov_surfx_1x3v_tensor_p1, vlasov_surfx_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, vlasov_surfx_2x2v_tensor_p1, vlasov_surfx_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_surfx_2x3v_tensor_p1, vlasov_surfx_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_surfx_2x2v_tensor_p1, vlasov_surfx_2x2v_tensor_p2}, // 3 + {NULL, vlasov_surfx_2x3v_tensor_p1, vlasov_surfx_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_surfx_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_surfx_3x3v_tensor_p1, NULL} // 5 }; - // Streaming surface kernel list: y-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_surf_kern_list ser_stream_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_stream_surf_kern_list ser_stream_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 // 2x kernels - { NULL, vlasov_surfy_2x2v_ser_p1, vlasov_surfy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_surfy_2x3v_ser_p1, vlasov_surfy_2x3v_ser_p2 }, // 4 + {NULL, vlasov_surfy_2x2v_ser_p1, vlasov_surfy_2x2v_ser_p2}, // 3 + {NULL, vlasov_surfy_2x3v_ser_p1, vlasov_surfy_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_surfy_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_surfy_3x3v_ser_p1, NULL} // 5 }; // Streaming surface kernel list: y-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_surf_kern_list tensor_stream_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_stream_surf_kern_list tensor_stream_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 // 2x kernels - { NULL, vlasov_surfy_2x2v_tensor_p1, vlasov_surfy_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_surfy_2x3v_tensor_p1, vlasov_surfy_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_surfy_2x2v_tensor_p1, vlasov_surfy_2x2v_tensor_p2}, // 3 + {NULL, vlasov_surfy_2x3v_tensor_p1, vlasov_surfy_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_surfy_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_surfy_3x3v_tensor_p1, NULL} // 5 }; // Streaming surface kernel list: z-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_surf_kern_list ser_stream_surf_z_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_stream_surf_kern_list ser_stream_surf_z_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 // 3x kernels - { NULL, vlasov_surfz_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_surfz_3x3v_ser_p1, NULL} // 5 }; // Streaming surface kernel list: z-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_surf_kern_list tensor_stream_surf_z_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_stream_surf_kern_list tensor_stream_surf_z_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 // 3x kernels - { NULL, vlasov_surfz_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_surfz_3x3v_tensor_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) surface kernel list: vx-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_surf_kern_list ser_accel_surf_vx_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_accel_surf_kern_list ser_accel_surf_vx_kernels[] = { // 1x kernels - { NULL, vlasov_surfvx_1x1v_ser_p1, vlasov_surfvx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_surfvx_1x2v_ser_p1, vlasov_surfvx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_surfvx_1x3v_ser_p1, vlasov_surfvx_1x3v_ser_p2 }, // 2 + {NULL, vlasov_surfvx_1x1v_ser_p1, vlasov_surfvx_1x1v_ser_p2}, // 0 + {NULL, vlasov_surfvx_1x2v_ser_p1, vlasov_surfvx_1x2v_ser_p2}, // 1 + {NULL, vlasov_surfvx_1x3v_ser_p1, vlasov_surfvx_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_surfvx_2x2v_ser_p1, vlasov_surfvx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_surfvx_2x3v_ser_p1, vlasov_surfvx_2x3v_ser_p2 }, // 4 + {NULL, vlasov_surfvx_2x2v_ser_p1, vlasov_surfvx_2x2v_ser_p2}, // 3 + {NULL, vlasov_surfvx_2x3v_ser_p1, vlasov_surfvx_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_surfvx_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_surfvx_3x3v_ser_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) surface kernel list: vx-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_surf_kern_list tensor_accel_surf_vx_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_accel_surf_kern_list tensor_accel_surf_vx_kernels[] = { // 1x kernels - { NULL, vlasov_surfvx_1x1v_tensor_p1, vlasov_surfvx_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_surfvx_1x2v_tensor_p1, vlasov_surfvx_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_surfvx_1x3v_tensor_p1, vlasov_surfvx_1x3v_tensor_p2 }, // 2 + {NULL, vlasov_surfvx_1x1v_tensor_p1, vlasov_surfvx_1x1v_tensor_p2}, // 0 + {NULL, vlasov_surfvx_1x2v_tensor_p1, vlasov_surfvx_1x2v_tensor_p2}, // 1 + {NULL, vlasov_surfvx_1x3v_tensor_p1, vlasov_surfvx_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, vlasov_surfvx_2x2v_tensor_p1, vlasov_surfvx_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_surfvx_2x3v_tensor_p1, vlasov_surfvx_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_surfvx_2x2v_tensor_p1, vlasov_surfvx_2x2v_tensor_p2}, // 3 + {NULL, vlasov_surfvx_2x3v_tensor_p1, vlasov_surfvx_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_surfvx_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_surfvx_3x3v_tensor_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) surface kernel list: vy-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_surf_kern_list ser_accel_surf_vy_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_accel_surf_kern_list ser_accel_surf_vy_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, vlasov_surfvy_1x2v_ser_p1, vlasov_surfvy_1x2v_ser_p2 }, // 1 - { NULL, vlasov_surfvy_1x3v_ser_p1, vlasov_surfvy_1x3v_ser_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, vlasov_surfvy_1x2v_ser_p1, vlasov_surfvy_1x2v_ser_p2}, // 1 + {NULL, vlasov_surfvy_1x3v_ser_p1, vlasov_surfvy_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_surfvy_2x2v_ser_p1, vlasov_surfvy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_surfvy_2x3v_ser_p1, vlasov_surfvy_2x3v_ser_p2 }, // 4 + {NULL, vlasov_surfvy_2x2v_ser_p1, vlasov_surfvy_2x2v_ser_p2}, // 3 + {NULL, vlasov_surfvy_2x3v_ser_p1, vlasov_surfvy_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_surfvy_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_surfvy_3x3v_ser_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) surface kernel list: vy-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_surf_kern_list tensor_accel_surf_vy_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_accel_surf_kern_list tensor_accel_surf_vy_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, vlasov_surfvy_1x2v_tensor_p1, vlasov_surfvy_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_surfvy_1x3v_tensor_p1, vlasov_surfvy_1x3v_tensor_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, vlasov_surfvy_1x2v_tensor_p1, vlasov_surfvy_1x2v_tensor_p2}, // 1 + {NULL, vlasov_surfvy_1x3v_tensor_p1, vlasov_surfvy_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, vlasov_surfvy_2x2v_tensor_p1, vlasov_surfvy_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_surfvy_2x3v_tensor_p1, vlasov_surfvy_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_surfvy_2x2v_tensor_p1, vlasov_surfvy_2x2v_tensor_p2}, // 3 + {NULL, vlasov_surfvy_2x3v_tensor_p1, vlasov_surfvy_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_surfvy_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_surfvy_3x3v_tensor_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) surface kernel list: vz-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_surf_kern_list ser_accel_surf_vz_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_accel_surf_kern_list ser_accel_surf_vz_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, vlasov_surfvz_1x3v_ser_p1, vlasov_surfvz_1x3v_ser_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, vlasov_surfvz_1x3v_ser_p1, vlasov_surfvz_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, vlasov_surfvz_2x3v_ser_p1, vlasov_surfvz_2x3v_ser_p2 }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, vlasov_surfvz_2x3v_ser_p1, vlasov_surfvz_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_surfvz_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_surfvz_3x3v_ser_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) surface kernel list: vz-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_surf_kern_list tensor_accel_surf_vz_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_accel_surf_kern_list tensor_accel_surf_vz_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, vlasov_surfvz_1x3v_tensor_p1, vlasov_surfvz_1x3v_tensor_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, vlasov_surfvz_1x3v_tensor_p1, vlasov_surfvz_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, vlasov_surfvz_2x3v_tensor_p1, vlasov_surfvz_2x3v_tensor_p2 }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, vlasov_surfvz_2x3v_tensor_p1, vlasov_surfvz_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_surfvz_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_surfvz_3x3v_tensor_p1, NULL} // 5 }; // Streaming boundary surface kernel list: x-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_boundary_surf_kern_list ser_stream_boundary_surf_x_kernels[] = { - // 1x kernels - { NULL, vlasov_boundary_surfx_1x1v_ser_p1, vlasov_boundary_surfx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_boundary_surfx_1x2v_ser_p1, vlasov_boundary_surfx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_boundary_surfx_1x3v_ser_p1, vlasov_boundary_surfx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_boundary_surfx_2x2v_ser_p1, vlasov_boundary_surfx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_boundary_surfx_2x3v_ser_p1, vlasov_boundary_surfx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfx_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_stream_boundary_surf_kern_list + ser_stream_boundary_surf_x_kernels[] = { + // 1x kernels + {NULL, vlasov_boundary_surfx_1x1v_ser_p1, vlasov_boundary_surfx_1x1v_ser_p2}, // 0 + {NULL, vlasov_boundary_surfx_1x2v_ser_p1, vlasov_boundary_surfx_1x2v_ser_p2}, // 1 + {NULL, vlasov_boundary_surfx_1x3v_ser_p1, vlasov_boundary_surfx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_boundary_surfx_2x2v_ser_p1, vlasov_boundary_surfx_2x2v_ser_p2}, // 3 + {NULL, vlasov_boundary_surfx_2x3v_ser_p1, vlasov_boundary_surfx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfx_3x3v_ser_p1, NULL} // 5 }; // Streaming boundary surface kernel list: x-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_boundary_surf_kern_list tensor_stream_boundary_surf_x_kernels[] = { - // 1x kernels - { NULL, vlasov_boundary_surfx_1x1v_tensor_p1, vlasov_boundary_surfx_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_boundary_surfx_1x2v_tensor_p1, vlasov_boundary_surfx_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_boundary_surfx_1x3v_tensor_p1, vlasov_boundary_surfx_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, vlasov_boundary_surfx_2x2v_tensor_p1, vlasov_boundary_surfx_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_boundary_surfx_2x3v_tensor_p1, vlasov_boundary_surfx_2x3v_tensor_p2 }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfx_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_stream_boundary_surf_kern_list + tensor_stream_boundary_surf_x_kernels[] = { + // 1x kernels + {NULL, vlasov_boundary_surfx_1x1v_tensor_p1, vlasov_boundary_surfx_1x1v_tensor_p2}, // 0 + {NULL, vlasov_boundary_surfx_1x2v_tensor_p1, vlasov_boundary_surfx_1x2v_tensor_p2}, // 1 + {NULL, vlasov_boundary_surfx_1x3v_tensor_p1, vlasov_boundary_surfx_1x3v_tensor_p2}, // 2 + // 2x kernels + {NULL, vlasov_boundary_surfx_2x2v_tensor_p1, vlasov_boundary_surfx_2x2v_tensor_p2}, // 3 + {NULL, vlasov_boundary_surfx_2x3v_tensor_p1, vlasov_boundary_surfx_2x3v_tensor_p2}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfx_3x3v_tensor_p1, NULL} // 5 }; // Streaming boundary surface kernel list: y-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_boundary_surf_kern_list ser_stream_boundary_surf_y_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, vlasov_boundary_surfy_2x2v_ser_p1, vlasov_boundary_surfy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_boundary_surfy_2x3v_ser_p1, vlasov_boundary_surfy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfy_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_stream_boundary_surf_kern_list + ser_stream_boundary_surf_y_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, vlasov_boundary_surfy_2x2v_ser_p1, vlasov_boundary_surfy_2x2v_ser_p2}, // 3 + {NULL, vlasov_boundary_surfy_2x3v_ser_p1, vlasov_boundary_surfy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfy_3x3v_ser_p1, NULL} // 5 }; // Streaming boundary surface kernel list: y-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_boundary_surf_kern_list tensor_stream_boundary_surf_y_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, vlasov_boundary_surfy_2x2v_tensor_p1, vlasov_boundary_surfy_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_boundary_surfy_2x3v_tensor_p1, vlasov_boundary_surfy_2x3v_tensor_p2 }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfy_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_stream_boundary_surf_kern_list + tensor_stream_boundary_surf_y_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, vlasov_boundary_surfy_2x2v_tensor_p1, vlasov_boundary_surfy_2x2v_tensor_p2}, // 3 + {NULL, vlasov_boundary_surfy_2x3v_tensor_p1, vlasov_boundary_surfy_2x3v_tensor_p2}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfy_3x3v_tensor_p1, NULL} // 5 }; // Streaming boundary surface kernel list: z-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_boundary_surf_kern_list ser_stream_boundary_surf_z_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfz_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_stream_boundary_surf_kern_list + ser_stream_boundary_surf_z_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfz_3x3v_ser_p1, NULL} // 5 }; // Streaming boundary surface kernel list: z-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_stream_boundary_surf_kern_list tensor_stream_boundary_surf_z_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfz_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_stream_boundary_surf_kern_list + tensor_stream_boundary_surf_z_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfz_3x3v_tensor_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) boundary surface kernel (zero-flux BCs) list: vx-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_boundary_surf_kern_list ser_accel_boundary_surf_vx_kernels[] = { - // 1x kernels - { NULL, vlasov_boundary_surfvx_1x1v_ser_p1, vlasov_boundary_surfvx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_boundary_surfvx_1x2v_ser_p1, vlasov_boundary_surfvx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_boundary_surfvx_1x3v_ser_p1, vlasov_boundary_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_boundary_surfvx_2x2v_ser_p1, vlasov_boundary_surfvx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_boundary_surfvx_2x3v_ser_p1, vlasov_boundary_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfvx_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_accel_boundary_surf_kern_list + ser_accel_boundary_surf_vx_kernels[] = { + // 1x kernels + {NULL, vlasov_boundary_surfvx_1x1v_ser_p1, vlasov_boundary_surfvx_1x1v_ser_p2}, // 0 + {NULL, vlasov_boundary_surfvx_1x2v_ser_p1, vlasov_boundary_surfvx_1x2v_ser_p2}, // 1 + {NULL, vlasov_boundary_surfvx_1x3v_ser_p1, vlasov_boundary_surfvx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_boundary_surfvx_2x2v_ser_p1, vlasov_boundary_surfvx_2x2v_ser_p2}, // 3 + {NULL, vlasov_boundary_surfvx_2x3v_ser_p1, vlasov_boundary_surfvx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfvx_3x3v_ser_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) boundary surface kernel (zero-flux BCs) list: vx-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_boundary_surf_kern_list tensor_accel_boundary_surf_vx_kernels[] = { - // 1x kernels - { NULL, vlasov_boundary_surfvx_1x1v_tensor_p1, vlasov_boundary_surfvx_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_boundary_surfvx_1x2v_tensor_p1, vlasov_boundary_surfvx_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_boundary_surfvx_1x3v_tensor_p1, vlasov_boundary_surfvx_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, vlasov_boundary_surfvx_2x2v_tensor_p1, vlasov_boundary_surfvx_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_boundary_surfvx_2x3v_tensor_p1, vlasov_boundary_surfvx_2x3v_tensor_p2 }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfvx_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_accel_boundary_surf_kern_list + tensor_accel_boundary_surf_vx_kernels[] = { + // 1x kernels + {NULL, vlasov_boundary_surfvx_1x1v_tensor_p1, vlasov_boundary_surfvx_1x1v_tensor_p2}, // 0 + {NULL, vlasov_boundary_surfvx_1x2v_tensor_p1, vlasov_boundary_surfvx_1x2v_tensor_p2}, // 1 + {NULL, vlasov_boundary_surfvx_1x3v_tensor_p1, vlasov_boundary_surfvx_1x3v_tensor_p2}, // 2 + // 2x kernels + {NULL, vlasov_boundary_surfvx_2x2v_tensor_p1, vlasov_boundary_surfvx_2x2v_tensor_p2}, // 3 + {NULL, vlasov_boundary_surfvx_2x3v_tensor_p1, vlasov_boundary_surfvx_2x3v_tensor_p2}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfvx_3x3v_tensor_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) boundary surface kernel (zero-flux BCs) list: vy-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_boundary_surf_kern_list ser_accel_boundary_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, vlasov_boundary_surfvy_1x2v_ser_p1, vlasov_boundary_surfvy_1x2v_ser_p2 }, // 1 - { NULL, vlasov_boundary_surfvy_1x3v_ser_p1, vlasov_boundary_surfvy_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_boundary_surfvy_2x2v_ser_p1, vlasov_boundary_surfvy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_boundary_surfvy_2x3v_ser_p1, vlasov_boundary_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfvy_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_accel_boundary_surf_kern_list + ser_accel_boundary_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, vlasov_boundary_surfvy_1x2v_ser_p1, vlasov_boundary_surfvy_1x2v_ser_p2}, // 1 + {NULL, vlasov_boundary_surfvy_1x3v_ser_p1, vlasov_boundary_surfvy_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_boundary_surfvy_2x2v_ser_p1, vlasov_boundary_surfvy_2x2v_ser_p2}, // 3 + {NULL, vlasov_boundary_surfvy_2x3v_ser_p1, vlasov_boundary_surfvy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfvy_3x3v_ser_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) boundary surface kernel (zero-flux BCs) list: vy-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_boundary_surf_kern_list tensor_accel_boundary_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, vlasov_boundary_surfvy_1x2v_tensor_p1, vlasov_boundary_surfvy_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_boundary_surfvy_1x3v_tensor_p1, vlasov_boundary_surfvy_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, vlasov_boundary_surfvy_2x2v_tensor_p1, vlasov_boundary_surfvy_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_boundary_surfvy_2x3v_tensor_p1, vlasov_boundary_surfvy_2x3v_tensor_p2 }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfvy_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_accel_boundary_surf_kern_list + tensor_accel_boundary_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, vlasov_boundary_surfvy_1x2v_tensor_p1, vlasov_boundary_surfvy_1x2v_tensor_p2}, // 1 + {NULL, vlasov_boundary_surfvy_1x3v_tensor_p1, vlasov_boundary_surfvy_1x3v_tensor_p2}, // 2 + // 2x kernels + {NULL, vlasov_boundary_surfvy_2x2v_tensor_p1, vlasov_boundary_surfvy_2x2v_tensor_p2}, // 3 + {NULL, vlasov_boundary_surfvy_2x3v_tensor_p1, vlasov_boundary_surfvy_2x3v_tensor_p2}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfvy_3x3v_tensor_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) boundary surface kernel (zero-flux BCs) list: vz-direction (Serendipity basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_boundary_surf_kern_list ser_accel_boundary_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, vlasov_boundary_surfvz_1x3v_ser_p1, vlasov_boundary_surfvz_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, vlasov_boundary_surfvz_2x3v_ser_p1, vlasov_boundary_surfvz_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfvz_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_accel_boundary_surf_kern_list + ser_accel_boundary_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, vlasov_boundary_surfvz_1x3v_ser_p1, vlasov_boundary_surfvz_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, vlasov_boundary_surfvz_2x3v_ser_p1, vlasov_boundary_surfvz_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfvz_3x3v_ser_p1, NULL} // 5 }; // Acceleration (full Vlasov-Maxwell) boundary surface kernel (zero-flux BCs) list: vz-direction (Tensor basis) -GKYL_CU_D -static const gkyl_dg_vlasov_accel_boundary_surf_kern_list tensor_accel_boundary_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, vlasov_boundary_surfvz_1x3v_tensor_p1, vlasov_boundary_surfvz_1x3v_tensor_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, vlasov_boundary_surfvz_2x3v_tensor_p1, vlasov_boundary_surfvz_2x3v_tensor_p2 }, // 4 - // 3x kernels - { NULL, vlasov_boundary_surfvz_3x3v_tensor_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_accel_boundary_surf_kern_list + tensor_accel_boundary_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, vlasov_boundary_surfvz_1x3v_tensor_p1, vlasov_boundary_surfvz_1x3v_tensor_p2}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, vlasov_boundary_surfvz_2x3v_tensor_p1, vlasov_boundary_surfvz_2x3v_tensor_p2}, // 4 + // 3x kernels + {NULL, vlasov_boundary_surfvz_3x3v_tensor_p1, NULL} // 5 }; // "Choose Kernel" based on cdim, vdim and polyorder -#define CK(lst,cdim,vd,poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] +#define CK(lst, cdim, vd, poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] /** * Free vlasov eqn object. @@ -945,14 +948,12 @@ static const gkyl_dg_vlasov_accel_boundary_surf_kern_list tensor_accel_boundary_ */ void gkyl_vlasov_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); @@ -962,33 +963,44 @@ surf(const struct gkyl_dg_eqn *eqn, // and fetch alpha_surf in right cell for upper edge long pidxC = gkyl_range_idx(&vlasov->phase_range, idxC); long pidxR = gkyl_range_idx(&vlasov->phase_range, idxR); - return vlasov->stream_surf[dir] - (xcC, dxC, - vlasov->auxfields.alpha_surf ? (const double*) gkyl_array_cfetch(vlasov->auxfields.alpha_surf, pidxC) : 0, - vlasov->auxfields.alpha_surf ? (const double*) gkyl_array_cfetch(vlasov->auxfields.alpha_surf, pidxR) : 0, - vlasov->auxfields.sgn_alpha_surf ? (const double*) gkyl_array_cfetch(vlasov->auxfields.sgn_alpha_surf, pidxC) : 0, - vlasov->auxfields.sgn_alpha_surf ? (const double*) gkyl_array_cfetch(vlasov->auxfields.sgn_alpha_surf, pidxR) : 0, - vlasov->auxfields.const_sgn_alpha ? (const int*) gkyl_array_cfetch(vlasov->auxfields.const_sgn_alpha, pidxC) : 0, - vlasov->auxfields.const_sgn_alpha ? (const int*) gkyl_array_cfetch(vlasov->auxfields.const_sgn_alpha, pidxR) : 0, - qInL, qInC, qInR, qRhsOut); - } - else { + return vlasov->stream_surf[dir]( + xcC, dxC, + vlasov->auxfields.alpha_surf ? + (const double *)gkyl_array_cfetch(vlasov->auxfields.alpha_surf, pidxC) : + 0, + vlasov->auxfields.alpha_surf ? + (const double *)gkyl_array_cfetch(vlasov->auxfields.alpha_surf, pidxR) : + 0, + vlasov->auxfields.sgn_alpha_surf ? + (const double *)gkyl_array_cfetch(vlasov->auxfields.sgn_alpha_surf, pidxC) : + 0, + vlasov->auxfields.sgn_alpha_surf ? + (const double *)gkyl_array_cfetch(vlasov->auxfields.sgn_alpha_surf, pidxR) : + 0, + vlasov->auxfields.const_sgn_alpha ? + (const int *)gkyl_array_cfetch(vlasov->auxfields.const_sgn_alpha, pidxC) : + 0, + vlasov->auxfields.const_sgn_alpha ? + (const int *)gkyl_array_cfetch(vlasov->auxfields.const_sgn_alpha, pidxR) : + 0, + qInL, qInC, qInR, qRhsOut + ); + } else { long cidx = gkyl_range_idx(&vlasov->conf_range, idxC); - return vlasov->accel_surf[dir-vlasov->cdim] - (xcC, dxC, - vlasov->auxfields.field ? (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx) : 0, - qInL, qInC, qInR, qRhsOut); + return vlasov->accel_surf[dir - vlasov->cdim]( + xcC, dxC, + vlasov->auxfields.field ? (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx) : + 0, + qInL, qInC, qInR, qRhsOut + ); } } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov *vlasov = container_of(eqn, struct dg_vlasov, eqn); @@ -996,33 +1008,47 @@ boundary_surf(const struct gkyl_dg_eqn *eqn, // Each cell owns the *lower* edge surface alpha long pidxEdge = gkyl_range_idx(&vlasov->phase_range, idxEdge); long pidxSkin = gkyl_range_idx(&vlasov->phase_range, idxSkin); - return vlasov->stream_boundary_surf[dir] - (xcSkin, dxSkin, - vlasov->auxfields.alpha_surf ? (const double*) gkyl_array_cfetch(vlasov->auxfields.alpha_surf, pidxEdge) : 0, - vlasov->auxfields.alpha_surf ? (const double*) gkyl_array_cfetch(vlasov->auxfields.alpha_surf, pidxSkin) : 0, - vlasov->auxfields.sgn_alpha_surf ? (const double*) gkyl_array_cfetch(vlasov->auxfields.sgn_alpha_surf, pidxEdge) : 0, - vlasov->auxfields.sgn_alpha_surf ? (const double*) gkyl_array_cfetch(vlasov->auxfields.sgn_alpha_surf, pidxSkin) : 0, - vlasov->auxfields.const_sgn_alpha ? (const int*) gkyl_array_cfetch(vlasov->auxfields.const_sgn_alpha, pidxEdge) : 0, - vlasov->auxfields.const_sgn_alpha ? (const int*) gkyl_array_cfetch(vlasov->auxfields.const_sgn_alpha, pidxSkin) : 0, - edge, qInEdge, qInSkin, qRhsOut); + return vlasov->stream_boundary_surf[dir]( + xcSkin, dxSkin, + vlasov->auxfields.alpha_surf ? + (const double *)gkyl_array_cfetch(vlasov->auxfields.alpha_surf, pidxEdge) : + 0, + vlasov->auxfields.alpha_surf ? + (const double *)gkyl_array_cfetch(vlasov->auxfields.alpha_surf, pidxSkin) : + 0, + vlasov->auxfields.sgn_alpha_surf ? + (const double *)gkyl_array_cfetch(vlasov->auxfields.sgn_alpha_surf, pidxEdge) : + 0, + vlasov->auxfields.sgn_alpha_surf ? + (const double *)gkyl_array_cfetch(vlasov->auxfields.sgn_alpha_surf, pidxSkin) : + 0, + vlasov->auxfields.const_sgn_alpha ? + (const int *)gkyl_array_cfetch(vlasov->auxfields.const_sgn_alpha, pidxEdge) : + 0, + vlasov->auxfields.const_sgn_alpha ? + (const int *)gkyl_array_cfetch(vlasov->auxfields.const_sgn_alpha, pidxSkin) : + 0, + edge, qInEdge, qInSkin, qRhsOut + ); } else if (dir >= vlasov->cdim) { long cidx = gkyl_range_idx(&vlasov->conf_range, idxSkin); - return vlasov->accel_boundary_surf[dir-vlasov->cdim] - (xcSkin, dxSkin, - vlasov->auxfields.field ? (const double*) gkyl_array_cfetch(vlasov->auxfields.field, cidx) : 0, - edge, qInEdge, qInSkin, qRhsOut); + return vlasov->accel_boundary_surf[dir - vlasov->cdim]( + xcSkin, dxSkin, + vlasov->auxfields.field ? (const double *)gkyl_array_cfetch(vlasov->auxfields.field, cidx) : + 0, + edge, qInEdge, qInSkin, qRhsOut + ); } return 0.; } -GKYL_CU_D -static double -boundary_diag(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_diag( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { - return boundary_surf(eqn, dir, xcEdge, xcSkin, dxEdge, dxSkin, idxEdge, idxSkin, edge, qInEdge, qInSkin, qRhsOut); + return boundary_surf( + eqn, dir, xcEdge, xcSkin, dxEdge, dxSkin, idxEdge, idxSkin, edge, qInEdge, qInSkin, qRhsOut + ); } diff --git a/vlasov/zero/gkyl_dg_vlasov_sr.h b/vlasov/zero/gkyl_dg_vlasov_sr.h index 5ffcb1156e..0b7ec0a3c5 100644 --- a/vlasov/zero/gkyl_dg_vlasov_sr.h +++ b/vlasov/zero/gkyl_dg_vlasov_sr.h @@ -8,7 +8,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_dg_vlasov_sr_auxfields { +struct gkyl_dg_vlasov_sr_auxfields { const struct gkyl_array *qmem; // q/m * EM const struct gkyl_array *gamma; // gamma = sqrt(1 + p^2), particle Lorentz factor }; @@ -25,10 +25,11 @@ struct gkyl_dg_vlasov_sr_auxfields { * @param use_gpu bool to determine if on GPU * @return Pointer to special relativistic Vlasov equation object */ -struct gkyl_dg_eqn* gkyl_dg_vlasov_sr_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* vel_range, - enum gkyl_field_id field_id, bool use_gpu); +struct gkyl_dg_eqn *gkyl_dg_vlasov_sr_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_field_id field_id, bool use_gpu +); /** * Create a new special relativistic Vlasov equation object that lives on NV-GPU @@ -41,10 +42,11 @@ struct gkyl_dg_eqn* gkyl_dg_vlasov_sr_new(const struct gkyl_basis* cbasis, * (special relativistic Vlasov-Maxwell vs. special relativistic neutrals) * @return Pointer to special relativistic Vlasov equation object */ -struct gkyl_dg_eqn* gkyl_dg_vlasov_sr_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* vel_range, - enum gkyl_field_id field_id); +struct gkyl_dg_eqn *gkyl_dg_vlasov_sr_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_field_id field_id +); /** * Set the auxiliary fields (e.g. q/m*EM) needed in updating the force terms. @@ -52,8 +54,9 @@ struct gkyl_dg_eqn* gkyl_dg_vlasov_sr_cu_dev_new(const struct gkyl_basis* cbasis * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_vlasov_sr_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_sr_auxfields auxin); - +void gkyl_vlasov_sr_set_auxfields( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_sr_auxfields auxin +); #ifdef GKYL_HAVE_CUDA /** @@ -62,6 +65,8 @@ void gkyl_vlasov_sr_set_auxfields(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_ * @param eqn Equation pointer. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_vlasov_sr_set_auxfields_cu(const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_sr_auxfields auxin); +void gkyl_vlasov_sr_set_auxfields_cu( + const struct gkyl_dg_eqn *eqn, struct gkyl_dg_vlasov_sr_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_dg_vlasov_sr_priv.h b/vlasov/zero/gkyl_dg_vlasov_sr_priv.h index 9d24fa72d3..0488eedf53 100644 --- a/vlasov/zero/gkyl_dg_vlasov_sr_priv.h +++ b/vlasov/zero/gkyl_dg_vlasov_sr_priv.h @@ -10,33 +10,48 @@ #include // Types for various kernels -typedef double (*vlasov_sr_stream_surf_t)(const double *w, const double *dxv, - const double *gamma, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); +typedef double (*vlasov_sr_stream_surf_t)( + const double *w, const double *dxv, const double *gamma, const double *fl, const double *fc, + const double *fr, double *GKYL_RESTRICT out +); -typedef double (*vlasov_sr_accel_surf_t)(const double *w, const double *dxv, - const double *gamma, const double *qmem, - const double *fl, const double *fc, const double *fr, double* GKYL_RESTRICT out); +typedef double (*vlasov_sr_accel_surf_t)( + const double *w, const double *dxv, const double *gamma, const double *qmem, const double *fl, + const double *fc, const double *fr, double *GKYL_RESTRICT out +); -typedef double (*vlasov_sr_accel_boundary_surf_t)(const double *w, const double *dxv, - const double *gamma, const double *qmem, - const int edge, const double *fEdge, const double *fSkin, double* GKYL_RESTRICT out); +typedef double (*vlasov_sr_accel_boundary_surf_t)( + const double *w, const double *dxv, const double *gamma, const double *qmem, const int edge, + const double *fEdge, const double *fSkin, double *GKYL_RESTRICT out +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // for use in kernel tables -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_vlasov_sr_stream_vol_kern_list; -typedef struct { vol_termf_t kernels[3]; } gkyl_dg_vlasov_sr_vol_kern_list; -typedef struct { vlasov_sr_stream_surf_t kernels[3]; } gkyl_dg_vlasov_sr_stream_surf_kern_list; -typedef struct { vlasov_sr_accel_surf_t kernels[3]; } gkyl_dg_vlasov_sr_accel_surf_kern_list; -typedef struct { vlasov_sr_accel_boundary_surf_t kernels[3]; } gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_vlasov_sr_stream_vol_kern_list; +typedef struct { + vol_termf_t kernels[3]; +} gkyl_dg_vlasov_sr_vol_kern_list; +typedef struct { + vlasov_sr_stream_surf_t kernels[3]; +} gkyl_dg_vlasov_sr_stream_surf_kern_list; +typedef struct { + vlasov_sr_accel_surf_t kernels[3]; +} gkyl_dg_vlasov_sr_accel_surf_kern_list; +typedef struct { + vlasov_sr_accel_boundary_surf_t kernels[3]; +} gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list; struct dg_vlasov_sr { struct gkyl_dg_eqn eqn; // Base object @@ -55,216 +70,226 @@ struct dg_vlasov_sr { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_vlasov_sr_stream_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_stream_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_stream_vol_1x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, - qIn, qRhsOut); + return vlasov_sr_stream_vol_1x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_stream_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_stream_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_stream_vol_1x1v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, - qIn, qRhsOut); + return vlasov_sr_stream_vol_1x1v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_stream_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_stream_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_stream_vol_1x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, - qIn, qRhsOut); + return vlasov_sr_stream_vol_1x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_stream_vol_1x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_stream_vol_1x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_stream_vol_1x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, - qIn, qRhsOut); + return vlasov_sr_stream_vol_1x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_stream_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_stream_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_stream_vol_1x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, - qIn, qRhsOut); + return vlasov_sr_stream_vol_1x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_stream_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_stream_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_stream_vol_1x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, - qIn, qRhsOut); + return vlasov_sr_stream_vol_1x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_stream_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_stream_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_stream_vol_2x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, - qIn, qRhsOut); + return vlasov_sr_stream_vol_2x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_stream_vol_2x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_stream_vol_2x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_stream_vol_2x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, - qIn, qRhsOut); + return vlasov_sr_stream_vol_2x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_stream_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_stream_vol_2x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_stream_vol_2x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, - qIn, qRhsOut); + return vlasov_sr_stream_vol_2x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_stream_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_stream_vol_2x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_stream_vol_2x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, - qIn, qRhsOut); + return vlasov_sr_stream_vol_2x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_stream_vol_3x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_stream_vol_3x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_stream_vol_3x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, - qIn, qRhsOut); + return vlasov_sr_stream_vol_3x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), 0, qIn, qRhsOut + ); } // Volume kernel list for relativistic streaming only -GKYL_CU_D -static const gkyl_dg_vlasov_sr_stream_vol_kern_list ser_stream_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_sr_stream_vol_kern_list ser_stream_vol_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_sr_stream_vol_1x1v_ser_p1, kernel_vlasov_sr_stream_vol_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_sr_stream_vol_1x2v_ser_p1, kernel_vlasov_sr_stream_vol_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_sr_stream_vol_1x3v_ser_p1, kernel_vlasov_sr_stream_vol_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_sr_stream_vol_1x1v_ser_p1, kernel_vlasov_sr_stream_vol_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_sr_stream_vol_1x2v_ser_p1, kernel_vlasov_sr_stream_vol_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_sr_stream_vol_1x3v_ser_p1, kernel_vlasov_sr_stream_vol_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_sr_stream_vol_2x2v_ser_p1, kernel_vlasov_sr_stream_vol_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_sr_stream_vol_2x3v_ser_p1, kernel_vlasov_sr_stream_vol_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_sr_stream_vol_2x2v_ser_p1, kernel_vlasov_sr_stream_vol_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_sr_stream_vol_2x3v_ser_p1, kernel_vlasov_sr_stream_vol_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_sr_stream_vol_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_vlasov_sr_stream_vol_3x3v_ser_p1, NULL} // 5 }; // @@ -272,227 +297,237 @@ static const gkyl_dg_vlasov_sr_stream_vol_kern_list ser_stream_vol_kernels[] = { // Need to be separated like this for GPU build // -GKYL_CU_DH -static double -kernel_vlasov_sr_vol_1x1v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_vol_1x1v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_vol_1x1v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), - qIn, qRhsOut); + return vlasov_sr_vol_1x1v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_vol_1x1v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_vol_1x1v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_vol_1x1v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), - qIn, qRhsOut); + return vlasov_sr_vol_1x1v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_vol_1x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_vol_1x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_vol_1x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), - qIn, qRhsOut); + return vlasov_sr_vol_1x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_vol_1x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_vol_1x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_vol_1x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), - qIn, qRhsOut); + return vlasov_sr_vol_1x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_vol_1x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_vol_1x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_vol_1x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), - qIn, qRhsOut); + return vlasov_sr_vol_1x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_vol_1x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_vol_1x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_vol_1x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), - qIn, qRhsOut); + return vlasov_sr_vol_1x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_vol_2x2v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_vol_2x2v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_vol_2x2v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), - qIn, qRhsOut); + return vlasov_sr_vol_2x2v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_vol_2x2v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_vol_2x2v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_vol_2x2v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), - qIn, qRhsOut); + return vlasov_sr_vol_2x2v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_vol_2x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_vol_2x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_vol_2x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), - qIn, qRhsOut); + return vlasov_sr_vol_2x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_vol_2x3v_ser_p2(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_vol_2x3v_ser_p2( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_vol_2x3v_ser_p2(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), - qIn, qRhsOut); + return vlasov_sr_vol_2x3v_ser_p2( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), qIn, qRhsOut + ); } -GKYL_CU_DH -static double -kernel_vlasov_sr_vol_3x3v_ser_p1(const struct gkyl_dg_eqn *eqn, const double* xc, const double* dx, - const int* idx, const double* qIn, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_DH static double kernel_vlasov_sr_vol_3x3v_ser_p1( + const struct gkyl_dg_eqn *eqn, const double *xc, const double *dx, const int *idx, + const double *qIn, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idx[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idx[vlasov_sr->cdim + i]; + } long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idx); long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); - return vlasov_sr_vol_3x3v_ser_p1(xc, dx, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), - qIn, qRhsOut); + return vlasov_sr_vol_3x3v_ser_p1( + xc, dx, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx), qIn, qRhsOut + ); } // Volume kernel list for relativistic streaming + EM -GKYL_CU_D -static const gkyl_dg_vlasov_sr_vol_kern_list ser_vol_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_sr_vol_kern_list ser_vol_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_sr_vol_1x1v_ser_p1, kernel_vlasov_sr_vol_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_sr_vol_1x2v_ser_p1, kernel_vlasov_sr_vol_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_sr_vol_1x3v_ser_p1, kernel_vlasov_sr_vol_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_sr_vol_1x1v_ser_p1, kernel_vlasov_sr_vol_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_sr_vol_1x2v_ser_p1, kernel_vlasov_sr_vol_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_sr_vol_1x3v_ser_p1, kernel_vlasov_sr_vol_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_sr_vol_2x2v_ser_p1, kernel_vlasov_sr_vol_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_sr_vol_2x3v_ser_p1, kernel_vlasov_sr_vol_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_sr_vol_2x2v_ser_p1, kernel_vlasov_sr_vol_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_sr_vol_2x3v_ser_p1, kernel_vlasov_sr_vol_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_sr_vol_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_vlasov_sr_vol_3x3v_ser_p1, NULL} // 5 }; // @@ -500,133 +535,127 @@ static const gkyl_dg_vlasov_sr_vol_kern_list ser_vol_kernels[] = { // // Streaming surface kernel list: x-direction -GKYL_CU_D -static const gkyl_dg_vlasov_sr_stream_surf_kern_list ser_stream_surf_x_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_sr_stream_surf_kern_list ser_stream_surf_x_kernels[] = { // 1x kernels - { NULL, vlasov_sr_surfx_1x1v_ser_p1, vlasov_sr_surfx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_sr_surfx_1x2v_ser_p1, vlasov_sr_surfx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_sr_surfx_1x3v_ser_p1, vlasov_sr_surfx_1x3v_ser_p2 }, // 2 + {NULL, vlasov_sr_surfx_1x1v_ser_p1, vlasov_sr_surfx_1x1v_ser_p2}, // 0 + {NULL, vlasov_sr_surfx_1x2v_ser_p1, vlasov_sr_surfx_1x2v_ser_p2}, // 1 + {NULL, vlasov_sr_surfx_1x3v_ser_p1, vlasov_sr_surfx_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_sr_surfx_2x2v_ser_p1, vlasov_sr_surfx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_sr_surfx_2x3v_ser_p1, vlasov_sr_surfx_2x3v_ser_p2 }, // 4 + {NULL, vlasov_sr_surfx_2x2v_ser_p1, vlasov_sr_surfx_2x2v_ser_p2}, // 3 + {NULL, vlasov_sr_surfx_2x3v_ser_p1, vlasov_sr_surfx_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_sr_surfx_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_sr_surfx_3x3v_ser_p1, NULL} // 5 }; // Streaming surface kernel list: y-direction -GKYL_CU_D -static const gkyl_dg_vlasov_sr_stream_surf_kern_list ser_stream_surf_y_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_sr_stream_surf_kern_list ser_stream_surf_y_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 // 2x kernels - { NULL, vlasov_sr_surfy_2x2v_ser_p1, vlasov_sr_surfy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_sr_surfy_2x3v_ser_p1, vlasov_sr_surfy_2x3v_ser_p2 }, // 4 + {NULL, vlasov_sr_surfy_2x2v_ser_p1, vlasov_sr_surfy_2x2v_ser_p2}, // 3 + {NULL, vlasov_sr_surfy_2x3v_ser_p1, vlasov_sr_surfy_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_sr_surfy_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_sr_surfy_3x3v_ser_p1, NULL} // 5 }; // Streaming surface kernel list: z-direction -GKYL_CU_D -static const gkyl_dg_vlasov_sr_stream_surf_kern_list ser_stream_surf_z_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_sr_stream_surf_kern_list ser_stream_surf_z_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, NULL, NULL }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, NULL, NULL}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, NULL, NULL }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, NULL, NULL}, // 4 // 3x kernels - { NULL, vlasov_sr_surfz_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_sr_surfz_3x3v_ser_p1, NULL} // 5 }; // Acceleration surface kernel list: vx-direction -GKYL_CU_D -static const gkyl_dg_vlasov_sr_accel_surf_kern_list ser_accel_surf_vx_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_sr_accel_surf_kern_list ser_accel_surf_vx_kernels[] = { // 1x kernels - { NULL, vlasov_sr_surfvx_1x1v_ser_p1, vlasov_sr_surfvx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_sr_surfvx_1x2v_ser_p1, vlasov_sr_surfvx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_sr_surfvx_1x3v_ser_p1, vlasov_sr_surfvx_1x3v_ser_p2 }, // 2 + {NULL, vlasov_sr_surfvx_1x1v_ser_p1, vlasov_sr_surfvx_1x1v_ser_p2}, // 0 + {NULL, vlasov_sr_surfvx_1x2v_ser_p1, vlasov_sr_surfvx_1x2v_ser_p2}, // 1 + {NULL, vlasov_sr_surfvx_1x3v_ser_p1, vlasov_sr_surfvx_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_sr_surfvx_2x2v_ser_p1, vlasov_sr_surfvx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_sr_surfvx_2x3v_ser_p1, vlasov_sr_surfvx_2x3v_ser_p2 }, // 4 + {NULL, vlasov_sr_surfvx_2x2v_ser_p1, vlasov_sr_surfvx_2x2v_ser_p2}, // 3 + {NULL, vlasov_sr_surfvx_2x3v_ser_p1, vlasov_sr_surfvx_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_sr_surfvx_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_sr_surfvx_3x3v_ser_p1, NULL} // 5 }; // Acceleration surface kernel list: vy-direction -GKYL_CU_D -static const gkyl_dg_vlasov_sr_accel_surf_kern_list ser_accel_surf_vy_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_sr_accel_surf_kern_list ser_accel_surf_vy_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, vlasov_sr_surfvy_1x2v_ser_p1, vlasov_sr_surfvy_1x2v_ser_p2 }, // 1 - { NULL, vlasov_sr_surfvy_1x3v_ser_p1, vlasov_sr_surfvy_1x3v_ser_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, vlasov_sr_surfvy_1x2v_ser_p1, vlasov_sr_surfvy_1x2v_ser_p2}, // 1 + {NULL, vlasov_sr_surfvy_1x3v_ser_p1, vlasov_sr_surfvy_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_sr_surfvy_2x2v_ser_p1, vlasov_sr_surfvy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_sr_surfvy_2x3v_ser_p1, vlasov_sr_surfvy_2x3v_ser_p2 }, // 4 + {NULL, vlasov_sr_surfvy_2x2v_ser_p1, vlasov_sr_surfvy_2x2v_ser_p2}, // 3 + {NULL, vlasov_sr_surfvy_2x3v_ser_p1, vlasov_sr_surfvy_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_sr_surfvy_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_sr_surfvy_3x3v_ser_p1, NULL} // 5 }; // Acceleration surface kernel list: vz-direction -GKYL_CU_D -static const gkyl_dg_vlasov_sr_accel_surf_kern_list ser_accel_surf_vz_kernels[] = { +GKYL_CU_D static const gkyl_dg_vlasov_sr_accel_surf_kern_list ser_accel_surf_vz_kernels[] = { // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, vlasov_sr_surfvz_1x3v_ser_p1, vlasov_sr_surfvz_1x3v_ser_p2 }, // 2 + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, vlasov_sr_surfvz_1x3v_ser_p1, vlasov_sr_surfvz_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, vlasov_sr_surfvz_2x3v_ser_p1, vlasov_sr_surfvz_2x3v_ser_p2 }, // 4 + {NULL, NULL, NULL}, // 3 + {NULL, vlasov_sr_surfvz_2x3v_ser_p1, vlasov_sr_surfvz_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_sr_surfvz_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_sr_surfvz_3x3v_ser_p1, NULL} // 5 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vx-direction -GKYL_CU_D -static const gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list ser_accel_boundary_surf_vx_kernels[] = { - // 1x kernels - { NULL, vlasov_sr_boundary_surfvx_1x1v_ser_p1, vlasov_sr_boundary_surfvx_1x1v_ser_p2 }, // 0 - { NULL, vlasov_sr_boundary_surfvx_1x2v_ser_p1, vlasov_sr_boundary_surfvx_1x2v_ser_p2 }, // 1 - { NULL, vlasov_sr_boundary_surfvx_1x3v_ser_p1, vlasov_sr_boundary_surfvx_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_sr_boundary_surfvx_2x2v_ser_p1, vlasov_sr_boundary_surfvx_2x2v_ser_p2 }, // 3 - { NULL, vlasov_sr_boundary_surfvx_2x3v_ser_p1, vlasov_sr_boundary_surfvx_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, vlasov_sr_boundary_surfvx_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list + ser_accel_boundary_surf_vx_kernels[] = { + // 1x kernels + {NULL, vlasov_sr_boundary_surfvx_1x1v_ser_p1, vlasov_sr_boundary_surfvx_1x1v_ser_p2}, // 0 + {NULL, vlasov_sr_boundary_surfvx_1x2v_ser_p1, vlasov_sr_boundary_surfvx_1x2v_ser_p2}, // 1 + {NULL, vlasov_sr_boundary_surfvx_1x3v_ser_p1, vlasov_sr_boundary_surfvx_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_sr_boundary_surfvx_2x2v_ser_p1, vlasov_sr_boundary_surfvx_2x2v_ser_p2}, // 3 + {NULL, vlasov_sr_boundary_surfvx_2x3v_ser_p1, vlasov_sr_boundary_surfvx_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, vlasov_sr_boundary_surfvx_3x3v_ser_p1, NULL} // 5 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vy-direction -GKYL_CU_D -static const gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list ser_accel_boundary_surf_vy_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, vlasov_sr_boundary_surfvy_1x2v_ser_p1, vlasov_sr_boundary_surfvy_1x2v_ser_p2 }, // 1 - { NULL, vlasov_sr_boundary_surfvy_1x3v_ser_p1, vlasov_sr_boundary_surfvy_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, vlasov_sr_boundary_surfvy_2x2v_ser_p1, vlasov_sr_boundary_surfvy_2x2v_ser_p2 }, // 3 - { NULL, vlasov_sr_boundary_surfvy_2x3v_ser_p1, vlasov_sr_boundary_surfvy_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, vlasov_sr_boundary_surfvy_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list + ser_accel_boundary_surf_vy_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, vlasov_sr_boundary_surfvy_1x2v_ser_p1, vlasov_sr_boundary_surfvy_1x2v_ser_p2}, // 1 + {NULL, vlasov_sr_boundary_surfvy_1x3v_ser_p1, vlasov_sr_boundary_surfvy_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, vlasov_sr_boundary_surfvy_2x2v_ser_p1, vlasov_sr_boundary_surfvy_2x2v_ser_p2}, // 3 + {NULL, vlasov_sr_boundary_surfvy_2x3v_ser_p1, vlasov_sr_boundary_surfvy_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, vlasov_sr_boundary_surfvy_3x3v_ser_p1, NULL} // 5 }; // Acceleration boundary surface kernel (zero-flux BCs) list: vz-direction -GKYL_CU_D -static const gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list ser_accel_boundary_surf_vz_kernels[] = { - // 1x kernels - { NULL, NULL, NULL }, // 0 - { NULL, NULL, NULL }, // 1 - { NULL, vlasov_sr_boundary_surfvz_1x3v_ser_p1, vlasov_sr_boundary_surfvz_1x3v_ser_p2 }, // 2 - // 2x kernels - { NULL, NULL, NULL }, // 3 - { NULL, vlasov_sr_boundary_surfvz_2x3v_ser_p1, vlasov_sr_boundary_surfvz_2x3v_ser_p2 }, // 4 - // 3x kernels - { NULL, vlasov_sr_boundary_surfvz_3x3v_ser_p1, NULL }, // 5 +GKYL_CU_D static const gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list + ser_accel_boundary_surf_vz_kernels[] = { + // 1x kernels + {NULL, NULL, NULL}, // 0 + {NULL, NULL, NULL}, // 1 + {NULL, vlasov_sr_boundary_surfvz_1x3v_ser_p1, vlasov_sr_boundary_surfvz_1x3v_ser_p2}, // 2 + // 2x kernels + {NULL, NULL, NULL}, // 3 + {NULL, vlasov_sr_boundary_surfvz_2x3v_ser_p1, vlasov_sr_boundary_surfvz_2x3v_ser_p2}, // 4 + // 3x kernels + {NULL, vlasov_sr_boundary_surfvz_3x3v_ser_p1, NULL} // 5 }; // "Choose Kernel" based on cdim, vdim and polyorder -#define CK(lst,cdim,vd,poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] +#define CK(lst, cdim, vd, poly_order) lst[cv_index[cdim].vdim[vd]].kernels[poly_order] /** * Free vlasov eqn object. @@ -635,61 +664,61 @@ static const gkyl_dg_vlasov_sr_accel_boundary_surf_kern_list ser_accel_boundary_ */ void gkyl_vlasov_sr_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static double -surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcL, const double* xcC, const double* xcR, - const double* dxL, const double* dxC, const double* dxR, - const int* idxL, const int* idxC, const int* idxR, - const double* qInL, const double* qInC, const double* qInR, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcL, const double *xcC, const double *xcR, + const double *dxL, const double *dxC, const double *dxR, const int *idxL, const int *idxC, + const int *idxR, const double *qInL, const double *qInC, const double *qInR, + double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idxC[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idxC[vlasov_sr->cdim + i]; + } long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); if (dir < vlasov_sr->cdim) { - return vlasov_sr->stream_surf[dir] - (xcC, dxC, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - qInL, qInC, qInR, qRhsOut); - } - else { + return vlasov_sr->stream_surf[dir]( + xcC, dxC, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), qInL, qInC, + qInR, qRhsOut + ); + } else { long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idxC); - return vlasov_sr->accel_surf[dir-vlasov_sr->cdim] - (xcC, dxC, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - vlasov_sr->auxfields.qmem ? (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx) : 0, - qInL, qInC, qInR, qRhsOut); + return vlasov_sr->accel_surf[dir - vlasov_sr->cdim]( + xcC, dxC, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + vlasov_sr->auxfields.qmem ? + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx) : + 0, + qInL, qInC, qInR, qRhsOut + ); } } -GKYL_CU_D -static double -boundary_surf(const struct gkyl_dg_eqn *eqn, - int dir, - const double* xcEdge, const double* xcSkin, - const double* dxEdge, const double* dxSkin, - const int* idxEdge, const int* idxSkin, const int edge, - const double* qInEdge, const double* qInSkin, double* GKYL_RESTRICT qRhsOut) +GKYL_CU_D static double boundary_surf( + const struct gkyl_dg_eqn *eqn, int dir, const double *xcEdge, const double *xcSkin, + const double *dxEdge, const double *dxSkin, const int *idxEdge, const int *idxSkin, + const int edge, const double *qInEdge, const double *qInSkin, double *GKYL_RESTRICT qRhsOut +) { struct dg_vlasov_sr *vlasov_sr = container_of(eqn, struct dg_vlasov_sr, eqn); int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ipdim-vlasov_sr->cdim; ++i) - idx_vel[i] = idxSkin[vlasov_sr->cdim+i]; + for (int i = 0; i < vlasov_sr->pdim - vlasov_sr->cdim; ++i) { + idx_vel[i] = idxSkin[vlasov_sr->cdim + i]; + } long vidx = gkyl_range_idx(&vlasov_sr->vel_range, idx_vel); if (dir >= vlasov_sr->cdim) { long cidx = gkyl_range_idx(&vlasov_sr->conf_range, idxSkin); - return vlasov_sr->accel_boundary_surf[dir-vlasov_sr->cdim] - (xcSkin, dxSkin, - (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), - vlasov_sr->auxfields.qmem ? (const double*) gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx) : 0, - edge, qInEdge, qInSkin, qRhsOut); + return vlasov_sr->accel_boundary_surf[dir - vlasov_sr->cdim]( + xcSkin, dxSkin, (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.gamma, vidx), + vlasov_sr->auxfields.qmem ? + (const double *)gkyl_array_cfetch(vlasov_sr->auxfields.qmem, cidx) : + 0, + edge, qInEdge, qInSkin, qRhsOut + ); } return 0.; } diff --git a/vlasov/zero/gkyl_emission_elastic_model.h b/vlasov/zero/gkyl_emission_elastic_model.h index 81a0d37fe1..a3fa211866 100644 --- a/vlasov/zero/gkyl_emission_elastic_model.h +++ b/vlasov/zero/gkyl_emission_elastic_model.h @@ -43,45 +43,41 @@ struct gkyl_emission_elastic_constant { // Free functions -static void -gkyl_emission_elastic_furman_pivi_free(const struct gkyl_ref_count *ref) +static void gkyl_emission_elastic_furman_pivi_free(const struct gkyl_ref_count *ref) { struct gkyl_emission_elastic_model *elastic = container_of(ref, struct gkyl_emission_elastic_model, ref_count); - struct gkyl_emission_elastic_furman_pivi *model = container_of(elastic, - struct gkyl_emission_elastic_furman_pivi, elastic); + struct gkyl_emission_elastic_furman_pivi *model = + container_of(elastic, struct gkyl_emission_elastic_furman_pivi, elastic); gkyl_free(model); } -static void -gkyl_emission_elastic_cazaux_free(const struct gkyl_ref_count *ref) +static void gkyl_emission_elastic_cazaux_free(const struct gkyl_ref_count *ref) { struct gkyl_emission_elastic_model *elastic = container_of(ref, struct gkyl_emission_elastic_model, ref_count); - struct gkyl_emission_elastic_cazaux *model = container_of(elastic, - struct gkyl_emission_elastic_cazaux, elastic); + struct gkyl_emission_elastic_cazaux *model = + container_of(elastic, struct gkyl_emission_elastic_cazaux, elastic); gkyl_free(model); } -static void -gkyl_emission_elastic_constant_free(const struct gkyl_ref_count *ref) +static void gkyl_emission_elastic_constant_free(const struct gkyl_ref_count *ref) { struct gkyl_emission_elastic_model *elastic = container_of(ref, struct gkyl_emission_elastic_model, ref_count); - struct gkyl_emission_elastic_constant *model = container_of(elastic, - struct gkyl_emission_elastic_constant, elastic); + struct gkyl_emission_elastic_constant *model = + container_of(elastic, struct gkyl_emission_elastic_constant, elastic); gkyl_free(model); } // Furman-Pivi SEY calculation -GKYL_CU_D -static void +GKYL_CU_D static void gkyl_emission_elastic_furman_pivi_yield(double t, const double *xn, double *fout, void *ctx) // Electron impact model adapted from https://link.aps.org/doi/10.1103/PhysRevSTAB.5.124404 { - struct gkyl_emission_elastic_model *elastic = (struct gkyl_emission_elastic_model *) ctx; - const struct gkyl_emission_elastic_furman_pivi *model = container_of(elastic, - struct gkyl_emission_elastic_furman_pivi, elastic); + struct gkyl_emission_elastic_model *elastic = (struct gkyl_emission_elastic_model *)ctx; + const struct gkyl_emission_elastic_furman_pivi *model = + container_of(elastic, struct gkyl_emission_elastic_furman_pivi, elastic); int cdim = elastic->cdim; int vdim = elastic->vdim; @@ -96,21 +92,20 @@ gkyl_emission_elastic_furman_pivi_yield(double t, const double *xn, double *fout double E = 0.0; double mu = 1.0; // currently hardcoded to normal, will add angular dependence later - for (int d=0; dcdim; int vdim = elastic->vdim; double mass = elastic->mass; @@ -119,23 +114,22 @@ gkyl_emission_elastic_cazaux_yield(double t, const double *xn, double *fout, voi double phi = model->phi; double E = 0.0; - for (int d=0; ddelta; fout[0] = delta; @@ -153,9 +147,9 @@ gkyl_emission_elastic_constant_yield(double t, const double *xn, double *fout, v * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_elastic_model* -gkyl_emission_elastic_furman_pivi_new(double charge, double P1_inf, double P1_hat, double E_hat, - double W, double p, bool use_gpu); +struct gkyl_emission_elastic_model *gkyl_emission_elastic_furman_pivi_new( + double charge, double P1_inf, double P1_hat, double E_hat, double W, double p, bool use_gpu +); /** * Create the elastic emission model using Cazaux @@ -166,7 +160,7 @@ gkyl_emission_elastic_furman_pivi_new(double charge, double P1_inf, double P1_ha * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_elastic_model* +struct gkyl_emission_elastic_model * gkyl_emission_elastic_cazaux_new(double charge, double E_f, double phi, bool use_gpu); /** @@ -177,7 +171,7 @@ gkyl_emission_elastic_cazaux_new(double charge, double E_f, double phi, bool use * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_elastic_model* +struct gkyl_emission_elastic_model * gkyl_emission_elastic_constant_new(double charge, double delta, bool use_gpu); /** @@ -187,13 +181,12 @@ gkyl_emission_elastic_constant_new(double charge, double delta, bool use_gpu); * @param model Model object. * @return Acquired model obj pointer */ -struct gkyl_emission_elastic_model* -gkyl_emission_elastic_model_acquire(const struct gkyl_emission_elastic_model* model); +struct gkyl_emission_elastic_model * +gkyl_emission_elastic_model_acquire(const struct gkyl_emission_elastic_model *model); /** * Delete model object * * @param model Model object to delete. */ -void -gkyl_emission_elastic_model_release(const struct gkyl_emission_elastic_model* model); +void gkyl_emission_elastic_model_release(const struct gkyl_emission_elastic_model *model); diff --git a/vlasov/zero/gkyl_emission_spectrum_model.h b/vlasov/zero/gkyl_emission_spectrum_model.h index 324981c98f..bbe388727c 100644 --- a/vlasov/zero/gkyl_emission_spectrum_model.h +++ b/vlasov/zero/gkyl_emission_spectrum_model.h @@ -8,8 +8,10 @@ struct gkyl_emission_spectrum_model; typedef void (*emission_spectrum_dist_func_t)(double t, const double *xn, double *fout, void *ctx); -typedef void (*emission_spectrum_norm_func_t)(double *out, struct gkyl_emission_spectrum_model *spectrum, - const double *flux, double effective_delta); +typedef void (*emission_spectrum_norm_func_t)( + double *out, struct gkyl_emission_spectrum_model *spectrum, const double *flux, + double effective_delta +); // Base model type struct gkyl_emission_spectrum_model { @@ -19,7 +21,7 @@ struct gkyl_emission_spectrum_model { double charge; emission_spectrum_dist_func_t distribution; emission_spectrum_norm_func_t normalization; - + uint32_t flags; struct gkyl_emission_spectrum_model *on_dev; struct gkyl_ref_count ref_count; // reference count @@ -52,70 +54,65 @@ struct gkyl_emission_spectrum_maxwellian { * @param model Model to check * @return true if model on device, false otherwise */ -bool -gkyl_emission_spectrum_model_is_cu_dev(const struct gkyl_emission_spectrum_model *model); +bool gkyl_emission_spectrum_model_is_cu_dev(const struct gkyl_emission_spectrum_model *model); -static void -gkyl_emission_spectrum_chung_everhart_free(const struct gkyl_ref_count *ref) +static void gkyl_emission_spectrum_chung_everhart_free(const struct gkyl_ref_count *ref) { struct gkyl_emission_spectrum_model *spectrum = container_of(ref, struct gkyl_emission_spectrum_model, ref_count); if (gkyl_emission_spectrum_model_is_cu_dev(spectrum)) { - struct gkyl_emission_spectrum_chung_everhart *model = container_of(spectrum->on_dev, - struct gkyl_emission_spectrum_chung_everhart, spectrum); + struct gkyl_emission_spectrum_chung_everhart *model = + container_of(spectrum->on_dev, struct gkyl_emission_spectrum_chung_everhart, spectrum); gkyl_cu_free(model); } - struct gkyl_emission_spectrum_chung_everhart *model = container_of(spectrum, - struct gkyl_emission_spectrum_chung_everhart, spectrum); + struct gkyl_emission_spectrum_chung_everhart *model = + container_of(spectrum, struct gkyl_emission_spectrum_chung_everhart, spectrum); gkyl_free(model); } -static void -gkyl_emission_spectrum_gaussian_free(const struct gkyl_ref_count *ref) +static void gkyl_emission_spectrum_gaussian_free(const struct gkyl_ref_count *ref) { struct gkyl_emission_spectrum_model *spectrum = container_of(ref, struct gkyl_emission_spectrum_model, ref_count); if (gkyl_emission_spectrum_model_is_cu_dev(spectrum)) { - struct gkyl_emission_spectrum_gaussian *model = container_of(spectrum->on_dev, - struct gkyl_emission_spectrum_gaussian, spectrum); + struct gkyl_emission_spectrum_gaussian *model = + container_of(spectrum->on_dev, struct gkyl_emission_spectrum_gaussian, spectrum); gkyl_cu_free(model); } - struct gkyl_emission_spectrum_gaussian *model = container_of(spectrum, - struct gkyl_emission_spectrum_gaussian, spectrum); + struct gkyl_emission_spectrum_gaussian *model = + container_of(spectrum, struct gkyl_emission_spectrum_gaussian, spectrum); gkyl_free(model); } -static void -gkyl_emission_spectrum_maxwellian_free(const struct gkyl_ref_count *ref) +static void gkyl_emission_spectrum_maxwellian_free(const struct gkyl_ref_count *ref) { struct gkyl_emission_spectrum_model *spectrum = container_of(ref, struct gkyl_emission_spectrum_model, ref_count); if (gkyl_emission_spectrum_model_is_cu_dev(spectrum)) { - struct gkyl_emission_spectrum_maxwellian *model = container_of(spectrum->on_dev, - struct gkyl_emission_spectrum_maxwellian, spectrum); + struct gkyl_emission_spectrum_maxwellian *model = + container_of(spectrum->on_dev, struct gkyl_emission_spectrum_maxwellian, spectrum); gkyl_cu_free(model); } - struct gkyl_emission_spectrum_maxwellian *model = container_of(spectrum, - struct gkyl_emission_spectrum_maxwellian, spectrum); + struct gkyl_emission_spectrum_maxwellian *model = + container_of(spectrum, struct gkyl_emission_spectrum_maxwellian, spectrum); gkyl_free(model); } // Model distribution functions -GKYL_CU_D -static void +GKYL_CU_D static void gkyl_emission_spectrum_chung_everhart_dist(double t, const double *xn, double *fout, void *ctx) { - struct gkyl_emission_spectrum_model *spectrum = (struct gkyl_emission_spectrum_model *) ctx; - const struct gkyl_emission_spectrum_chung_everhart *model = container_of(spectrum, - struct gkyl_emission_spectrum_chung_everhart, spectrum); - + struct gkyl_emission_spectrum_model *spectrum = (struct gkyl_emission_spectrum_model *)ctx; + const struct gkyl_emission_spectrum_chung_everhart *model = + container_of(spectrum, struct gkyl_emission_spectrum_chung_everhart, spectrum); + int cdim = spectrum->cdim; int vdim = spectrum->vdim; double mass = spectrum->mass; @@ -123,20 +120,19 @@ gkyl_emission_spectrum_chung_everhart_dist(double t, const double *xn, double *f double phi = model->phi; double E = 0.0; - for (int d=0; dcdim; int vdim = spectrum->vdim; double mass = spectrum->mass; @@ -146,20 +142,19 @@ gkyl_emission_spectrum_gaussian_dist(double t, const double *xn, double *fout, v double E = 0.0; double mu = 1.0; // currently hardcoded to normal, will add angular dependence later - for (int d=0; dcdim; int vdim = spectrum->vdim; double mass = spectrum->mass; @@ -167,59 +162,57 @@ gkyl_emission_spectrum_maxwellian_dist(double t, const double *xn, double *fout, double vt = model->vt; double v_sq = 0.0; - for (int d=0; dmass; double charge = spectrum->charge; double phi = model->phi; - - out[0] = 6.0*effective_delta*flux[0]*phi*phi*mass/fabs(charge); + + out[0] = 6.0 * effective_delta * flux[0] * phi * phi * mass / fabs(charge); } // Gaussian normalization factor -GKYL_CU_D -static void -gkyl_emission_spectrum_gaussian_norm(double *out, - struct gkyl_emission_spectrum_model *spectrum, const double *flux, - double effective_delta) +GKYL_CU_D static void gkyl_emission_spectrum_gaussian_norm( + double *out, struct gkyl_emission_spectrum_model *spectrum, const double *flux, + double effective_delta +) { - const struct gkyl_emission_spectrum_gaussian *model = container_of(spectrum, - struct gkyl_emission_spectrum_gaussian, spectrum); + const struct gkyl_emission_spectrum_gaussian *model = + container_of(spectrum, struct gkyl_emission_spectrum_gaussian, spectrum); double mass = spectrum->mass; double charge = spectrum->charge; double E_0 = model->E_0; double tau = model->tau; - out[0] = effective_delta*flux[0]*mass/(sqrt(2.0*M_PI)*E_0*tau*exp(tau*tau/2.0)*fabs(charge)); + out[0] = effective_delta * flux[0] * mass / + (sqrt(2.0 * M_PI) * E_0 * tau * exp(tau * tau / 2.0) * fabs(charge)); } // Maxwellian normalization factor */ -GKYL_CU_D -static void -gkyl_emission_spectrum_maxwellian_norm(double *out, - struct gkyl_emission_spectrum_model *spectrum, const double *flux, - double effective_delta) +GKYL_CU_D static void gkyl_emission_spectrum_maxwellian_norm( + double *out, struct gkyl_emission_spectrum_model *spectrum, const double *flux, + double effective_delta +) { - const struct gkyl_emission_spectrum_maxwellian *model = container_of(spectrum, - struct gkyl_emission_spectrum_maxwellian, spectrum); + const struct gkyl_emission_spectrum_maxwellian *model = + container_of(spectrum, struct gkyl_emission_spectrum_maxwellian, spectrum); double vt = model->vt; int vdim = spectrum->vdim; - - out[0] = effective_delta*flux[0]/(pow(2.0*M_PI, (vdim - 1)/2.0)*pow(vt, vdim + 1)); + + out[0] = effective_delta * flux[0] / (pow(2.0 * M_PI, (vdim - 1) / 2.0) * pow(vt, vdim + 1)); } /** @@ -230,7 +223,7 @@ gkyl_emission_spectrum_maxwellian_norm(double *out, * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_spectrum_model* +struct gkyl_emission_spectrum_model * gkyl_emission_spectrum_chung_everhart_new(double charge, double phi, bool use_gpu); /** @@ -242,7 +235,7 @@ gkyl_emission_spectrum_chung_everhart_new(double charge, double phi, bool use_gp * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_spectrum_model* +struct gkyl_emission_spectrum_model * gkyl_emission_spectrum_gaussian_new(double charge, double E_0, double tau, bool use_gpu); /** @@ -253,7 +246,7 @@ gkyl_emission_spectrum_gaussian_new(double charge, double E_0, double tau, bool * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_spectrum_model* +struct gkyl_emission_spectrum_model * gkyl_emission_spectrum_maxwellian_new(double charge, double vt, bool use_gpu); /** @@ -263,16 +256,15 @@ gkyl_emission_spectrum_maxwellian_new(double charge, double vt, bool use_gpu); * @param model Model object. * @return Acquired model obj pointer */ -struct gkyl_emission_spectrum_model* -gkyl_emission_spectrum_model_acquire(const struct gkyl_emission_spectrum_model* model); +struct gkyl_emission_spectrum_model * +gkyl_emission_spectrum_model_acquire(const struct gkyl_emission_spectrum_model *model); /** * Delete model object * * @param model Model object to delete. */ -void -gkyl_emission_spectrum_model_release(const struct gkyl_emission_spectrum_model* model); +void gkyl_emission_spectrum_model_release(const struct gkyl_emission_spectrum_model *model); /** * Create the emission spectrum model using the Chung-Everhart distribution on NV-GPU @@ -282,9 +274,9 @@ gkyl_emission_spectrum_model_release(const struct gkyl_emission_spectrum_model* * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_spectrum_model* -gkyl_emission_spectrum_chung_everhart_cu_dev_new(struct gkyl_emission_spectrum_chung_everhart *model, - double charge, double phi); +struct gkyl_emission_spectrum_model *gkyl_emission_spectrum_chung_everhart_cu_dev_new( + struct gkyl_emission_spectrum_chung_everhart *model, double charge, double phi +); /** * Create the emission spectrum model using the logarithmic Gaussian distribution on NV-GPU @@ -295,9 +287,9 @@ gkyl_emission_spectrum_chung_everhart_cu_dev_new(struct gkyl_emission_spectrum_c * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_spectrum_model* -gkyl_emission_spectrum_gaussian_cu_dev_new(struct gkyl_emission_spectrum_gaussian *model, - double charge, double E_0, double tau); +struct gkyl_emission_spectrum_model *gkyl_emission_spectrum_gaussian_cu_dev_new( + struct gkyl_emission_spectrum_gaussian *model, double charge, double E_0, double tau +); /** * Create the emission spectrum model using the Maxwellian distribution on NV-GPU @@ -307,6 +299,6 @@ gkyl_emission_spectrum_gaussian_cu_dev_new(struct gkyl_emission_spectrum_gaussia * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_spectrum_model* -gkyl_emission_spectrum_maxwellian_cu_dev_new(struct gkyl_emission_spectrum_maxwellian *model, - double charge, double vt); +struct gkyl_emission_spectrum_model *gkyl_emission_spectrum_maxwellian_cu_dev_new( + struct gkyl_emission_spectrum_maxwellian *model, double charge, double vt +); diff --git a/vlasov/zero/gkyl_emission_yield_model.h b/vlasov/zero/gkyl_emission_yield_model.h index bed93ff70e..9fab96b2e4 100644 --- a/vlasov/zero/gkyl_emission_yield_model.h +++ b/vlasov/zero/gkyl_emission_yield_model.h @@ -8,8 +8,9 @@ // Object type struct gkyl_emission_yield_model; -typedef void (*emission_yield_func_t)(double *out, struct gkyl_emission_yield_model *yield, - double xc[GKYL_MAX_DIM]); +typedef void (*emission_yield_func_t)( + double *out, struct gkyl_emission_yield_model *yield, double xc[GKYL_MAX_DIM] +); // Base model type struct gkyl_emission_yield_model { @@ -75,88 +76,82 @@ struct gkyl_emission_yield_constant { * @param model Model to check * @return true if model on device, false otherwise */ -bool -gkyl_emission_yield_model_is_cu_dev(const struct gkyl_emission_yield_model *model); +bool gkyl_emission_yield_model_is_cu_dev(const struct gkyl_emission_yield_model *model); -static void -gkyl_emission_yield_furman_pivi_free(const struct gkyl_ref_count *ref) +static void gkyl_emission_yield_furman_pivi_free(const struct gkyl_ref_count *ref) { struct gkyl_emission_yield_model *yield = container_of(ref, struct gkyl_emission_yield_model, ref_count); if (gkyl_emission_yield_model_is_cu_dev(yield)) { - struct gkyl_emission_yield_furman_pivi *model = container_of(yield->on_dev, - struct gkyl_emission_yield_furman_pivi, yield); + struct gkyl_emission_yield_furman_pivi *model = + container_of(yield->on_dev, struct gkyl_emission_yield_furman_pivi, yield); gkyl_cu_free(model); } - struct gkyl_emission_yield_furman_pivi *model = container_of(yield, - struct gkyl_emission_yield_furman_pivi, yield); + struct gkyl_emission_yield_furman_pivi *model = + container_of(yield, struct gkyl_emission_yield_furman_pivi, yield); gkyl_free(model); } -static void -gkyl_emission_yield_schou_free(const struct gkyl_ref_count *ref) +static void gkyl_emission_yield_schou_free(const struct gkyl_ref_count *ref) { struct gkyl_emission_yield_model *yield = container_of(ref, struct gkyl_emission_yield_model, ref_count); if (gkyl_emission_yield_model_is_cu_dev(yield)) { - struct gkyl_emission_yield_schou *model = container_of(yield->on_dev, - struct gkyl_emission_yield_schou, yield); + struct gkyl_emission_yield_schou *model = + container_of(yield->on_dev, struct gkyl_emission_yield_schou, yield); gkyl_cu_free(model); } - struct gkyl_emission_yield_schou *model = container_of(yield, - struct gkyl_emission_yield_schou, yield); + struct gkyl_emission_yield_schou *model = + container_of(yield, struct gkyl_emission_yield_schou, yield); gkyl_free(model); } // SRIM -static void -gkyl_emission_yield_schou_srim_free(const struct gkyl_ref_count *ref) +static void gkyl_emission_yield_schou_srim_free(const struct gkyl_ref_count *ref) { struct gkyl_emission_yield_model *yield = container_of(ref, struct gkyl_emission_yield_model, ref_count); if (gkyl_emission_yield_model_is_cu_dev(yield)) { - struct gkyl_emission_yield_schou_srim *model = container_of(yield->on_dev, - struct gkyl_emission_yield_schou_srim, yield); + struct gkyl_emission_yield_schou_srim *model = + container_of(yield->on_dev, struct gkyl_emission_yield_schou_srim, yield); gkyl_cu_free(model); } - struct gkyl_emission_yield_schou_srim *model = container_of(yield, - struct gkyl_emission_yield_schou_srim, yield); + struct gkyl_emission_yield_schou_srim *model = + container_of(yield, struct gkyl_emission_yield_schou_srim, yield); gkyl_free(model); } -static void -gkyl_emission_yield_constant_free(const struct gkyl_ref_count *ref) +static void gkyl_emission_yield_constant_free(const struct gkyl_ref_count *ref) { struct gkyl_emission_yield_model *yield = container_of(ref, struct gkyl_emission_yield_model, ref_count); if (gkyl_emission_yield_model_is_cu_dev(yield)) { - struct gkyl_emission_yield_constant *model = container_of(yield->on_dev, - struct gkyl_emission_yield_constant, yield); + struct gkyl_emission_yield_constant *model = + container_of(yield->on_dev, struct gkyl_emission_yield_constant, yield); gkyl_cu_free(model); } - struct gkyl_emission_yield_constant *model = container_of(yield, - struct gkyl_emission_yield_constant, yield); + struct gkyl_emission_yield_constant *model = + container_of(yield, struct gkyl_emission_yield_constant, yield); gkyl_free(model); } // Furman-Pivi SEY calculation */ -GKYL_CU_D -static void -gkyl_emission_yield_furman_pivi_yield(double *out, struct gkyl_emission_yield_model *yield, - double xc[GKYL_MAX_DIM]) +GKYL_CU_D static void gkyl_emission_yield_furman_pivi_yield( + double *out, struct gkyl_emission_yield_model *yield, double xc[GKYL_MAX_DIM] +) // Electron impact model adapted from https://link.aps.org/doi/10.1103/PhysRevSTAB.5.124404 { - const struct gkyl_emission_yield_furman_pivi *model = container_of(yield, - struct gkyl_emission_yield_furman_pivi, yield); - + const struct gkyl_emission_yield_furman_pivi *model = + container_of(yield, struct gkyl_emission_yield_furman_pivi, yield); + int cdim = yield->cdim; int vdim = yield->vdim; double mass = yield->mass; @@ -169,63 +164,64 @@ gkyl_emission_yield_furman_pivi_yield(double *out, struct gkyl_emission_yield_mo double t3 = model->t3; double t4 = model->t4; double s = model->s; - + double E = 0.0; double mu = 1.0; // currently hardcoded to normal, will add angular dependence later - for (int d=0; dcdim; int vdim = yield->vdim; double mass = yield->mass; double charge = yield->charge; double int_wall = model->int_wall; - double A2 = model->a2; // Note: Starts at 2 to match notation from source: https://doi.org/10.1093/jicru_os25.2.18 + double A2 = + model + ->a2; // Note: Starts at 2 to match notation from source: https://doi.org/10.1093/jicru_os25.2.18 double A3 = model->a3; double A4 = model->a4; double A5 = model->a5; - double nw = model->nw; // Number density of wall material in m^-3 + double nw = model->nw; // Number density of wall material in m^-3 double E = 0.0; - for (int d=0; dcdim; int vdim = yield->vdim; double mass = yield->mass; @@ -241,31 +237,30 @@ gkyl_emission_yield_schou_srim_yield(double *out, struct gkyl_emission_yield_mod double gauss_tau = model->gauss_tau; double E = 0.0; - for (int d=0; ddelta; out[0] = delta; @@ -285,9 +280,10 @@ gkyl_emission_yield_constant_yield(double *out, struct gkyl_emission_yield_model * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_yield_model* -gkyl_emission_yield_furman_pivi_new(double charge, double deltahat_ts, double Ehat_ts, double t1, - double t2, double t3, double t4, double s, bool use_gpu); +struct gkyl_emission_yield_model *gkyl_emission_yield_furman_pivi_new( + double charge, double deltahat_ts, double Ehat_ts, double t1, double t2, double t3, double t4, + double s, bool use_gpu +); /** * Create the emission yield model using Schou @@ -302,9 +298,10 @@ gkyl_emission_yield_furman_pivi_new(double charge, double deltahat_ts, double Eh * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_yield_model* -gkyl_emission_yield_schou_new(double charge, double int_wall, double a2, double a3, double a4, - double a5, double nw, bool use_gpu); +struct gkyl_emission_yield_model *gkyl_emission_yield_schou_new( + double charge, double int_wall, double a2, double a3, double a4, double a5, double nw, + bool use_gpu +); /** * Create the emission yield model using Schou (SRIM ion stopping power) @@ -322,9 +319,10 @@ gkyl_emission_yield_schou_new(double charge, double int_wall, double a2, double * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_yield_model* -gkyl_emission_yield_schou_srim_new(double charge, double int_wall, double lorentz_norm, double E0, double tau, double alpha, - double beta, double gauss_norm, double gauss_E0, double gauss_tau, bool use_gpu); +struct gkyl_emission_yield_model *gkyl_emission_yield_schou_srim_new( + double charge, double int_wall, double lorentz_norm, double E0, double tau, double alpha, + double beta, double gauss_norm, double gauss_E0, double gauss_tau, bool use_gpu +); /** * Create the emission yield model using a constant yield @@ -334,7 +332,7 @@ gkyl_emission_yield_schou_srim_new(double charge, double int_wall, double lorent * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_yield_model* +struct gkyl_emission_yield_model * gkyl_emission_yield_constant_new(double charge, double delta, bool use_gpu); /** @@ -344,16 +342,15 @@ gkyl_emission_yield_constant_new(double charge, double delta, bool use_gpu); * @param model Model object. * @return Acquired model obj pointer */ -struct gkyl_emission_yield_model* -gkyl_emission_yield_model_acquire(const struct gkyl_emission_yield_model* model); +struct gkyl_emission_yield_model * +gkyl_emission_yield_model_acquire(const struct gkyl_emission_yield_model *model); /** * Delete model object * * @param model Model object to delete. */ -void -gkyl_emission_yield_model_release(const struct gkyl_emission_yield_model* model); +void gkyl_emission_yield_model_release(const struct gkyl_emission_yield_model *model); /** * Create the emission yield model using Furman-Pivi on NV-GPU @@ -368,10 +365,10 @@ gkyl_emission_yield_model_release(const struct gkyl_emission_yield_model* model) * @param s Fitting parameter * @return New model */ -struct gkyl_emission_yield_model* -gkyl_emission_yield_furman_pivi_cu_dev_new(double charge, double deltahat_ts, double Ehat_ts, - double t1, double t2, double t3, double t4, double s); - +struct gkyl_emission_yield_model *gkyl_emission_yield_furman_pivi_cu_dev_new( + double charge, double deltahat_ts, double Ehat_ts, double t1, double t2, double t3, double t4, + double s +); /** * Create the emission yield model using Schou on NV-GPU @@ -386,9 +383,9 @@ gkyl_emission_yield_furman_pivi_cu_dev_new(double charge, double deltahat_ts, do * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_yield_model* -gkyl_emission_yield_schou_cu_dev_new(double charge, double int_wall, double a2, double a3, - double a4, double a5, double nw); +struct gkyl_emission_yield_model *gkyl_emission_yield_schou_cu_dev_new( + double charge, double int_wall, double a2, double a3, double a4, double a5, double nw +); /** * Create the emission yield model using Schou (SRIM stopping power) on NV-GPU @@ -406,9 +403,10 @@ gkyl_emission_yield_schou_cu_dev_new(double charge, double int_wall, double a2, * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_yield_model* -gkyl_emission_yield_schou_srim_cu_dev_new(double charge, double int_wall, double lorentz_norm, double E0, double tau, - double alpha, double beta, double gauss_norm, double gauss_E0, double gauss_tau); +struct gkyl_emission_yield_model *gkyl_emission_yield_schou_srim_cu_dev_new( + double charge, double int_wall, double lorentz_norm, double E0, double tau, double alpha, + double beta, double gauss_norm, double gauss_E0, double gauss_tau +); /** * Create the emission yield model using a constant yield on NV-GPU @@ -418,5 +416,5 @@ gkyl_emission_yield_schou_srim_cu_dev_new(double charge, double int_wall, double * @param use_gpu bool to determine if on GPU * @return New model */ -struct gkyl_emission_yield_model* +struct gkyl_emission_yield_model * gkyl_emission_yield_constant_cu_dev_new(double charge, double delta); diff --git a/vlasov/zero/gkyl_ghost_surf_calc.h b/vlasov/zero/gkyl_ghost_surf_calc.h index 7d1debf4fd..774ed5ceee 100644 --- a/vlasov/zero/gkyl_ghost_surf_calc.h +++ b/vlasov/zero/gkyl_ghost_surf_calc.h @@ -17,8 +17,9 @@ typedef struct gkyl_ghost_surf_calc gkyl_ghost_surf_calc; * @param equation Equation object * @param use_gpu bool to determine if on GPU */ -struct gkyl_ghost_surf_calc* gkyl_ghost_surf_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_dg_eqn *equation, int cdim, bool use_gpu); +struct gkyl_ghost_surf_calc *gkyl_ghost_surf_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_dg_eqn *equation, int cdim, bool use_gpu +); /** * Create new updater on CUDA device to update equations in the ghost cells using DG algorithm. @@ -26,8 +27,9 @@ struct gkyl_ghost_surf_calc* gkyl_ghost_surf_calc_new(const struct gkyl_rect_gri * @param grid_cu Grid object (on device) * @param equation Equation object */ -struct gkyl_ghost_surf_calc* gkyl_ghost_surf_calc_cu_dev_new(const struct gkyl_rect_grid *grid, - const struct gkyl_dg_eqn *equation, int cdim); +struct gkyl_ghost_surf_calc *gkyl_ghost_surf_calc_cu_dev_new( + const struct gkyl_rect_grid *grid, const struct gkyl_dg_eqn *equation, int cdim +); /** * Compute RHS of DG update in the ghost cells. The update_rng MUST be the external range @@ -39,18 +41,20 @@ struct gkyl_ghost_surf_calc* gkyl_ghost_surf_calc_cu_dev_new(const struct gkyl_r * @param fIn Input to updater * @param rhs RHS output */ -void gkyl_ghost_surf_calc_advance(gkyl_ghost_surf_calc *gcalc, - const struct gkyl_range *phase_rng, - const struct gkyl_array *fIn, struct gkyl_array *rhs); +void gkyl_ghost_surf_calc_advance( + gkyl_ghost_surf_calc *gcalc, const struct gkyl_range *phase_rng, const struct gkyl_array *fIn, + struct gkyl_array *rhs +); // CUDA call -void gkyl_ghost_surf_calc_advance_cu(gkyl_ghost_surf_calc *gcalc, - const struct gkyl_range *phase_rng, - const struct gkyl_array *fIn, struct gkyl_array *rhs); - +void gkyl_ghost_surf_calc_advance_cu( + gkyl_ghost_surf_calc *gcalc, const struct gkyl_range *phase_rng, const struct gkyl_array *fIn, + struct gkyl_array *rhs +); + /** * Delete updater. * * @param gcalc Updater to delete. */ -void gkyl_ghost_surf_calc_release(gkyl_ghost_surf_calc* gcalc); +void gkyl_ghost_surf_calc_release(gkyl_ghost_surf_calc *gcalc); diff --git a/vlasov/zero/gkyl_hyper_dg.h b/vlasov/zero/gkyl_hyper_dg.h index b1eda3dd2e..f76ef451f5 100644 --- a/vlasov/zero/gkyl_hyper_dg.h +++ b/vlasov/zero/gkyl_hyper_dg.h @@ -22,10 +22,11 @@ typedef struct gkyl_hyper_dg gkyl_hyper_dg; * @param update_vol_term Set to 0 to skip volume update * @param use_gpu bool to determine if on GPU */ -gkyl_hyper_dg* gkyl_hyper_dg_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, const struct gkyl_dg_eqn *equation, - int num_up_dirs, int update_dirs[GKYL_MAX_DIM], int zero_flux_flags[2*GKYL_MAX_DIM], - int update_vol_term, bool use_gpu); +gkyl_hyper_dg *gkyl_hyper_dg_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_dg_eqn *equation, int num_up_dirs, int update_dirs[GKYL_MAX_DIM], + int zero_flux_flags[2 * GKYL_MAX_DIM], int update_vol_term, bool use_gpu +); /** * Compute RHS of DG update. The update_rng MUST be a sub-range of the @@ -39,8 +40,10 @@ gkyl_hyper_dg* gkyl_hyper_dg_new(const struct gkyl_rect_grid *grid, * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_hyper_dg_advance(gkyl_hyper_dg *up, const struct gkyl_range *update_rng, - const struct gkyl_array *fIn, struct gkyl_array *cflrate, struct gkyl_array *rhs); +void gkyl_hyper_dg_advance( + gkyl_hyper_dg *up, const struct gkyl_range *update_rng, const struct gkyl_array *fIn, + struct gkyl_array *cflrate, struct gkyl_array *rhs +); /** * Compute RHS of DG generic stencil update. @@ -57,9 +60,10 @@ void gkyl_hyper_dg_advance(gkyl_hyper_dg *up, const struct gkyl_range *update_rn * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_hyper_dg_gen_stencil_advance(gkyl_hyper_dg* up, const struct gkyl_range *update_rng, - const struct gkyl_array *fIn, struct gkyl_array *cflrate, - struct gkyl_array *rhs); +void gkyl_hyper_dg_gen_stencil_advance( + gkyl_hyper_dg *up, const struct gkyl_range *update_rng, const struct gkyl_array *fIn, + struct gkyl_array *cflrate, struct gkyl_array *rhs +); /** * Set if volume term should be computed or not. @@ -68,10 +72,10 @@ void gkyl_hyper_dg_gen_stencil_advance(gkyl_hyper_dg* up, const struct gkyl_rang * @param update_vol_term Set to 1 to update vol term, 0 otherwise */ void gkyl_hyper_dg_set_update_vol(gkyl_hyper_dg *up, int update_vol_term); - + /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_hyper_dg_release(gkyl_hyper_dg* up); +void gkyl_hyper_dg_release(gkyl_hyper_dg *up); diff --git a/vlasov/zero/gkyl_hyper_dg_priv.h b/vlasov/zero/gkyl_hyper_dg_priv.h index 0bfb53a1a0..ee15aa593d 100644 --- a/vlasov/zero/gkyl_hyper_dg_priv.h +++ b/vlasov/zero/gkyl_hyper_dg_priv.h @@ -11,7 +11,7 @@ struct gkyl_hyper_dg { int num_up_dirs; // number of update directions int update_dirs[GKYL_MAX_DIM]; // directions to update // zero_flux_flags[d] == 1 means zero-flux BC in 'd' - int zero_flux_flags[2*GKYL_MAX_DIM]; + int zero_flux_flags[2 * GKYL_MAX_DIM]; int update_vol_term; // should we update volume term? const struct gkyl_dg_eqn *equation; // equation object @@ -33,10 +33,11 @@ struct gkyl_hyper_dg { * @param zero_flux_flags[2*GKYL_MAX_DIM] Flags to indicate if boundary has zero-flux BCs * @param update_vol_term Set to 0 to skip volume update */ -gkyl_hyper_dg* gkyl_hyper_dg_cu_dev_new(const struct gkyl_rect_grid *grid_cu, - const struct gkyl_basis *basis, const struct gkyl_dg_eqn *equation_cu, - int num_up_dirs, int update_dirs[GKYL_MAX_DIM], int zero_flux_flags[2*GKYL_MAX_DIM], - int update_vol_term); +gkyl_hyper_dg *gkyl_hyper_dg_cu_dev_new( + const struct gkyl_rect_grid *grid_cu, const struct gkyl_basis *basis, + const struct gkyl_dg_eqn *equation_cu, int num_up_dirs, int update_dirs[GKYL_MAX_DIM], + int zero_flux_flags[2 * GKYL_MAX_DIM], int update_vol_term +); /** * Compute RHS of DG update on the device. The update_rng MUST be a sub-range of the @@ -50,9 +51,11 @@ gkyl_hyper_dg* gkyl_hyper_dg_cu_dev_new(const struct gkyl_rect_grid *grid_cu, * @param cflrate CFL scalar rate (frequency) array (units of 1/[T]) * @param rhs RHS output */ -void gkyl_hyper_dg_advance_cu(gkyl_hyper_dg* up, const struct gkyl_range *update_range, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT cflrate, - struct gkyl_array* GKYL_RESTRICT rhs); +void gkyl_hyper_dg_advance_cu( + gkyl_hyper_dg *up, const struct gkyl_range *update_range, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +); /** * Set if volume term should be computed or not. @@ -60,7 +63,6 @@ void gkyl_hyper_dg_advance_cu(gkyl_hyper_dg* up, const struct gkyl_range *update * @param up Hyper DG updater object * @param update_vol_term Set to 1 to update vol term, 0 otherwise */ -void -gkyl_hyper_dg_set_update_vol_cu(gkyl_hyper_dg *up, int update_vol_term); +void gkyl_hyper_dg_set_update_vol_cu(gkyl_hyper_dg *up, int update_vol_term); #endif diff --git a/vlasov/zero/gkyl_mom_bcorr_lbo_vlasov.h b/vlasov/zero/gkyl_mom_bcorr_lbo_vlasov.h index b4151eb26d..aa8ab25575 100644 --- a/vlasov/zero/gkyl_mom_bcorr_lbo_vlasov.h +++ b/vlasov/zero/gkyl_mom_bcorr_lbo_vlasov.h @@ -11,15 +11,15 @@ * @param vBoundary Values at the edges of velocity space. * @param use_gpu bool to determine if on GPU */ -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_vlasov_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const double* vBoundary, - bool use_gpu); +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_vlasov_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, const double *vBoundary, + bool use_gpu +); /** * Create new LBO Vlasov boundary correction moment type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const double* vBoundary); +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_vlasov_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, const double *vBoundary +); diff --git a/vlasov/zero/gkyl_mom_bcorr_lbo_vlasov_priv.h b/vlasov/zero/gkyl_mom_bcorr_lbo_vlasov_priv.h index ec4cbe6052..656fe7d1cc 100644 --- a/vlasov/zero/gkyl_mom_bcorr_lbo_vlasov_priv.h +++ b/vlasov/zero/gkyl_mom_bcorr_lbo_vlasov_priv.h @@ -8,37 +8,42 @@ #include #include -typedef void (*lbo_vlasov_momf_t)(const int *idx, enum gkyl_vel_edge edge, const double *vBoundary, - const double *dxv, const double *fIn, double* GKYL_RESTRICT out); +typedef void (*lbo_vlasov_momf_t)( + const int *idx, enum gkyl_vel_edge edge, const double *vBoundary, const double *dxv, + const double *fIn, double *GKYL_RESTRICT out +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // for use in kernel tables -typedef struct { lbo_vlasov_momf_t kernels[3]; } gkyl_mom_bcorr_lbo_vlasov_kern_list; +typedef struct { + lbo_vlasov_momf_t kernels[3]; +} gkyl_mom_bcorr_lbo_vlasov_kern_list; // // Serendipity basis kernels // // boundary integral moment correction kernel lists (both momentum and energy) -GKYL_CU_D -static const gkyl_mom_bcorr_lbo_vlasov_kern_list ser_mom_bcorr_lbo_vlasov_kernels[] = { +GKYL_CU_D static const gkyl_mom_bcorr_lbo_vlasov_kern_list ser_mom_bcorr_lbo_vlasov_kernels[] = { // 1x kernels - { NULL, mom_bcorr_lbo_vlasov_1x1v_ser_p1, mom_bcorr_lbo_vlasov_1x1v_ser_p2 }, // 0 - { NULL, mom_bcorr_lbo_vlasov_1x2v_ser_p1, mom_bcorr_lbo_vlasov_1x2v_ser_p2 }, // 1 - { NULL, mom_bcorr_lbo_vlasov_1x3v_ser_p1, mom_bcorr_lbo_vlasov_1x3v_ser_p2 }, // 2 + {NULL, mom_bcorr_lbo_vlasov_1x1v_ser_p1, mom_bcorr_lbo_vlasov_1x1v_ser_p2}, // 0 + {NULL, mom_bcorr_lbo_vlasov_1x2v_ser_p1, mom_bcorr_lbo_vlasov_1x2v_ser_p2}, // 1 + {NULL, mom_bcorr_lbo_vlasov_1x3v_ser_p1, mom_bcorr_lbo_vlasov_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, mom_bcorr_lbo_vlasov_2x2v_ser_p1, mom_bcorr_lbo_vlasov_2x2v_ser_p2 }, // 3 - { NULL, mom_bcorr_lbo_vlasov_2x3v_ser_p1, mom_bcorr_lbo_vlasov_2x3v_ser_p2 }, // 4 + {NULL, mom_bcorr_lbo_vlasov_2x2v_ser_p1, mom_bcorr_lbo_vlasov_2x2v_ser_p2}, // 3 + {NULL, mom_bcorr_lbo_vlasov_2x3v_ser_p1, mom_bcorr_lbo_vlasov_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, mom_bcorr_lbo_vlasov_3x3v_ser_p1, NULL }, // 5 + {NULL, mom_bcorr_lbo_vlasov_3x3v_ser_p1, NULL} // 5 }; // @@ -61,18 +66,19 @@ static const gkyl_mom_bcorr_lbo_vlasov_kern_list ser_mom_bcorr_lbo_vlasov_kernel struct mom_type_bcorr_lbo_vlasov { struct gkyl_mom_type momt; lbo_vlasov_momf_t kernel; // moment calculation kernel - double vBoundary[2*GKYL_MAX_DIM]; + double vBoundary[2 * GKYL_MAX_DIM]; }; void gkyl_mom_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static void -kernel(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_D static void kernel( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - struct mom_type_bcorr_lbo_vlasov *mom_bcorr = container_of(momt, struct mom_type_bcorr_lbo_vlasov, momt); + struct mom_type_bcorr_lbo_vlasov *mom_bcorr = + container_of(momt, struct mom_type_bcorr_lbo_vlasov, momt); enum gkyl_vel_edge edge = *(enum gkyl_vel_edge *)param; - + return mom_bcorr->kernel(idx, edge, mom_bcorr->vBoundary, dx, f, out); } diff --git a/vlasov/zero/gkyl_mom_calc.h b/vlasov/zero/gkyl_mom_calc.h index 55590c9162..c81bc031fe 100644 --- a/vlasov/zero/gkyl_mom_calc.h +++ b/vlasov/zero/gkyl_mom_calc.h @@ -18,17 +18,15 @@ typedef struct gkyl_mom_calc gkyl_mom_calc; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_mom_calc* -gkyl_mom_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_mom_type *momt, bool use_gpu); +struct gkyl_mom_calc * +gkyl_mom_calc_new(const struct gkyl_rect_grid *grid, const struct gkyl_mom_type *momt, bool use_gpu); /** * Create new updater to compute moments of distribution function on * NV-GPU. See new() method for documentation. */ -struct gkyl_mom_calc* -gkyl_mom_calc_cu_dev_new(const struct gkyl_rect_grid *grid, - const struct gkyl_mom_type *momt); +struct gkyl_mom_calc * +gkyl_mom_calc_cu_dev_new(const struct gkyl_rect_grid *grid, const struct gkyl_mom_type *momt); /** * Compute moment of distribution function. The phase_rng and conf_rng @@ -42,17 +40,21 @@ gkyl_mom_calc_cu_dev_new(const struct gkyl_rect_grid *grid, * @param fin Input distribution function array * @param mout Output moment array */ -void gkyl_mom_calc_advance(const struct gkyl_mom_calc* calc, - const struct gkyl_range *phase_rng, const struct gkyl_range *conf_rng, - const struct gkyl_array *GKYL_RESTRICT fin, struct gkyl_array *GKYL_RESTRICT mout); +void gkyl_mom_calc_advance( + const struct gkyl_mom_calc *calc, const struct gkyl_range *phase_rng, + const struct gkyl_range *conf_rng, const struct gkyl_array *GKYL_RESTRICT fin, + struct gkyl_array *GKYL_RESTRICT mout +); -void gkyl_mom_calc_advance_cu(const struct gkyl_mom_calc* mcalc, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *GKYL_RESTRICT fin, struct gkyl_array *GKYL_RESTRICT mout); +void gkyl_mom_calc_advance_cu( + const struct gkyl_mom_calc *mcalc, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *GKYL_RESTRICT fin, + struct gkyl_array *GKYL_RESTRICT mout +); /** * Delete pointer to moment calculator updater. * * @param calc Updater to delete. */ -void gkyl_mom_calc_release(gkyl_mom_calc* calc); +void gkyl_mom_calc_release(gkyl_mom_calc *calc); diff --git a/vlasov/zero/gkyl_mom_calc_bcorr.h b/vlasov/zero/gkyl_mom_calc_bcorr.h index 6b9ce952eb..0dae65d215 100644 --- a/vlasov/zero/gkyl_mom_calc_bcorr.h +++ b/vlasov/zero/gkyl_mom_calc_bcorr.h @@ -18,9 +18,9 @@ typedef struct gkyl_mom_calc_bcorr gkyl_mom_calc_bcorr; * @param momt Moment type object for boundary correction * @param use_gpu bool to determine if on GPU */ -struct gkyl_mom_calc_bcorr* -gkyl_mom_calc_bcorr_new(const struct gkyl_rect_grid *grid, - const struct gkyl_mom_type *momt, bool use_gpu); +struct gkyl_mom_calc_bcorr *gkyl_mom_calc_bcorr_new( + const struct gkyl_rect_grid *grid, const struct gkyl_mom_type *momt, bool use_gpu +); /** * Compute boundary correction moments. @@ -31,30 +31,32 @@ gkyl_mom_calc_bcorr_new(const struct gkyl_rect_grid *grid, * @param fIn Input to updater * @param out Output */ -void gkyl_mom_calc_bcorr_advance(const struct gkyl_mom_calc_bcorr *bcorr, - const struct gkyl_range *phase_rng, const struct gkyl_range *conf_rng, - const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT out); - +void gkyl_mom_calc_bcorr_advance( + const struct gkyl_mom_calc_bcorr *bcorr, const struct gkyl_range *phase_rng, + const struct gkyl_range *conf_rng, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT out +); + /** * Delete updater. * * @param bcorr Updater to delete. */ -void gkyl_mom_calc_bcorr_release(struct gkyl_mom_calc_bcorr* up); +void gkyl_mom_calc_bcorr_release(struct gkyl_mom_calc_bcorr *up); // "derived" class constructors -struct gkyl_mom_calc_bcorr* -gkyl_mom_calc_bcorr_lbo_vlasov_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const double* vBoundary, bool use_gpu); - -struct gkyl_mom_calc_bcorr* -gkyl_mom_calc_bcorr_lbo_pkpm_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const double* vBoundary, double mass, bool use_gpu); - -struct gkyl_mom_calc_bcorr* -gkyl_mom_calc_bcorr_lbo_gyrokinetic_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - double mass, const struct gkyl_velocity_map *vel_map, - bool use_gpu); +struct gkyl_mom_calc_bcorr *gkyl_mom_calc_bcorr_lbo_vlasov_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const double *vBoundary, bool use_gpu +); + +struct gkyl_mom_calc_bcorr *gkyl_mom_calc_bcorr_lbo_pkpm_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const double *vBoundary, double mass, bool use_gpu +); + +struct gkyl_mom_calc_bcorr *gkyl_mom_calc_bcorr_lbo_gyrokinetic_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, double mass, const struct gkyl_velocity_map *vel_map, + bool use_gpu +); diff --git a/vlasov/zero/gkyl_mom_calc_bcorr_priv.h b/vlasov/zero/gkyl_mom_calc_bcorr_priv.h index 9eb5a1ca29..b890899a6c 100644 --- a/vlasov/zero/gkyl_mom_calc_bcorr_priv.h +++ b/vlasov/zero/gkyl_mom_calc_bcorr_priv.h @@ -21,9 +21,8 @@ struct gkyl_mom_calc_bcorr { * Create new updater to update boundary corrections on NV-GPU: * see new() method above for documentation. */ -struct gkyl_mom_calc_bcorr* -gkyl_mom_calc_bcorr_cu_dev_new(const struct gkyl_rect_grid *grid, - const struct gkyl_mom_type *momt); +struct gkyl_mom_calc_bcorr * +gkyl_mom_calc_bcorr_cu_dev_new(const struct gkyl_rect_grid *grid, const struct gkyl_mom_type *momt); /** * Compute boundary correction moments. @@ -34,7 +33,9 @@ gkyl_mom_calc_bcorr_cu_dev_new(const struct gkyl_rect_grid *grid, * @param fIn Input to updater * @param out Output */ -void gkyl_mom_calc_bcorr_advance_cu(const struct gkyl_mom_calc_bcorr *bcorr, - const struct gkyl_range *phase_rng, const struct gkyl_range *conf_rng, - const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT out); +void gkyl_mom_calc_bcorr_advance_cu( + const struct gkyl_mom_calc_bcorr *bcorr, const struct gkyl_range *phase_rng, + const struct gkyl_range *conf_rng, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT out +); #endif diff --git a/vlasov/zero/gkyl_mom_canonical_pb.h b/vlasov/zero/gkyl_mom_canonical_pb.h index a59d9bdda9..153ccb010d 100644 --- a/vlasov/zero/gkyl_mom_canonical_pb.h +++ b/vlasov/zero/gkyl_mom_canonical_pb.h @@ -5,7 +5,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_mom_canonical_pb_auxfields { +struct gkyl_mom_canonical_pb_auxfields { const struct gkyl_array *hamil; // hamiltonian function }; @@ -20,9 +20,10 @@ struct gkyl_mom_canonical_pb_auxfields { * @param mom_type Name of moment to compute. * @param use_gpu bool to determine if on GPU */ -struct gkyl_mom_type* gkyl_mom_canonical_pb_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range, enum gkyl_distribution_moments mom_type, - bool use_gpu); +struct gkyl_mom_type *gkyl_mom_canonical_pb_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, enum gkyl_distribution_moments mom_type, bool use_gpu +); /** * Create new canonical-pb integrated moment type @@ -34,9 +35,10 @@ struct gkyl_mom_type* gkyl_mom_canonical_pb_new(const struct gkyl_basis* cbasis, * @param mom_type Name of moment to compute. * @param use_gpu bool to determine if on GPU */ -struct gkyl_mom_type* gkyl_int_mom_canonical_pb_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range, enum gkyl_distribution_moments mom_type, - bool use_gpu); +struct gkyl_mom_type *gkyl_int_mom_canonical_pb_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, enum gkyl_distribution_moments mom_type, bool use_gpu +); /** * Set the auxiliary fields needed in computing moments. @@ -44,5 +46,6 @@ struct gkyl_mom_type* gkyl_int_mom_canonical_pb_new(const struct gkyl_basis* cba * @param momt moment type. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_mom_canonical_pb_set_auxfields(const struct gkyl_mom_type *momt, - struct gkyl_mom_canonical_pb_auxfields auxin); +void gkyl_mom_canonical_pb_set_auxfields( + const struct gkyl_mom_type *momt, struct gkyl_mom_canonical_pb_auxfields auxin +); diff --git a/vlasov/zero/gkyl_mom_canonical_pb_priv.h b/vlasov/zero/gkyl_mom_canonical_pb_priv.h index a9a183a552..6a25ef5fef 100644 --- a/vlasov/zero/gkyl_mom_canonical_pb_priv.h +++ b/vlasov/zero/gkyl_mom_canonical_pb_priv.h @@ -18,11 +18,13 @@ struct mom_type_canonical_pb { // The cv_index[cd].vdim[cd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // for use in kernel tables @@ -30,520 +32,559 @@ typedef struct { momf_t kernels[3]; } gkyl_canonical_pb_mom_kern_list; -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x3v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x3v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x3v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x3v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_2x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_2x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_2x3v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_2x3v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_2x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_2x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_2x3v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_2x3v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } - -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x3v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x3v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x3v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x3v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } - -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_2x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_2x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_2x3v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_2x3v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_2x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_2x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_2x3v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_2x3v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } - // // Serendipity basis kernels // // MEnergy kernel list -GKYL_CU_D -static const gkyl_canonical_pb_mom_kern_list ser_menergy_kernels[] = { +GKYL_CU_D static const gkyl_canonical_pb_mom_kern_list ser_menergy_kernels[] = { // 1x kernels - { NULL, kernel_canonical_pb_MEnergy_1x1v_ser_p1, kernel_canonical_pb_MEnergy_1x1v_ser_p2 }, // 0 - { NULL, kernel_canonical_pb_MEnergy_1x2v_ser_p1, kernel_canonical_pb_MEnergy_1x2v_ser_p2 }, // 1 - { NULL, kernel_canonical_pb_MEnergy_1x3v_ser_p1, kernel_canonical_pb_MEnergy_1x3v_ser_p2 }, // 2 + {NULL, kernel_canonical_pb_MEnergy_1x1v_ser_p1, kernel_canonical_pb_MEnergy_1x1v_ser_p2}, // 0 + {NULL, kernel_canonical_pb_MEnergy_1x2v_ser_p1, kernel_canonical_pb_MEnergy_1x2v_ser_p2}, // 1 + {NULL, kernel_canonical_pb_MEnergy_1x3v_ser_p1, kernel_canonical_pb_MEnergy_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_canonical_pb_MEnergy_2x2v_ser_p1, kernel_canonical_pb_MEnergy_2x2v_ser_p2 }, // 3 - { NULL, kernel_canonical_pb_MEnergy_2x3v_ser_p1, kernel_canonical_pb_MEnergy_2x3v_ser_p2 }, // 4 + {NULL, kernel_canonical_pb_MEnergy_2x2v_ser_p1, kernel_canonical_pb_MEnergy_2x2v_ser_p2}, // 3 + {NULL, kernel_canonical_pb_MEnergy_2x3v_ser_p1, kernel_canonical_pb_MEnergy_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; // Integrated moment kernel list -GKYL_CU_D -static const gkyl_canonical_pb_mom_kern_list ser_int_five_moments_kernels[] = { +GKYL_CU_D static const gkyl_canonical_pb_mom_kern_list ser_int_five_moments_kernels[] = { // 1x kernels - { NULL, kernel_canonical_pb_int_five_moments_1x1v_ser_p1, kernel_canonical_pb_int_five_moments_1x1v_ser_p2 }, // 0 - { NULL, kernel_canonical_pb_int_five_moments_1x2v_ser_p1, kernel_canonical_pb_int_five_moments_1x2v_ser_p2 }, // 1 - { NULL, kernel_canonical_pb_int_five_moments_1x3v_ser_p1, kernel_canonical_pb_int_five_moments_1x3v_ser_p2 }, // 2 + {NULL, kernel_canonical_pb_int_five_moments_1x1v_ser_p1, + kernel_canonical_pb_int_five_moments_1x1v_ser_p2}, // 0 + {NULL, kernel_canonical_pb_int_five_moments_1x2v_ser_p1, + kernel_canonical_pb_int_five_moments_1x2v_ser_p2}, // 1 + {NULL, kernel_canonical_pb_int_five_moments_1x3v_ser_p1, + kernel_canonical_pb_int_five_moments_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_canonical_pb_int_five_moments_2x2v_ser_p1, kernel_canonical_pb_int_five_moments_2x2v_ser_p2 }, // 3 - { NULL, kernel_canonical_pb_int_five_moments_2x3v_ser_p1, kernel_canonical_pb_int_five_moments_2x3v_ser_p2 }, // 4 + {NULL, kernel_canonical_pb_int_five_moments_2x2v_ser_p1, + kernel_canonical_pb_int_five_moments_2x2v_ser_p2}, // 3 + {NULL, kernel_canonical_pb_int_five_moments_2x3v_ser_p1, + kernel_canonical_pb_int_five_moments_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; - -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x1v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x1v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x1v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x1v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x1v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x1v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x1v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x1v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x2v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x2v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x2v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x2v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x2v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x2v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x2v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x2v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x3v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x3v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x3v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x3v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_1x3v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_1x3v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_1x3v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_1x3v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_2x2v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_2x2v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_2x2v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_2x2v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_2x2v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_2x2v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_2x2v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_2x2v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_2x3v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_2x3v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_2x3v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_2x3v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_MEnergy_3x3v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_MEnergy_3x3v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_MEnergy_3x3v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_MEnergy_3x3v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x1v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x1v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x1v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x1v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x1v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x1v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x1v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x1v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x2v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x2v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x2v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x2v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x2v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x2v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x2v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x2v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x3v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x3v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x3v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x3v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_1x3v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_1x3v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_1x3v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_1x3v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_2x2v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_2x2v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_2x2v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_2x2v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_2x2v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_2x2v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_2x2v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_2x2v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_2x3v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_2x3v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_2x3v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_2x3v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_int_five_moments_3x3v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_int_five_moments_3x3v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_int_five_moments_3x3v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_int_five_moments_3x3v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } // @@ -551,291 +592,319 @@ kernel_canonical_pb_int_five_moments_3x3v_tensor_p1(const struct gkyl_mom_type * // // MEnergy kernel list -GKYL_CU_D -static const gkyl_canonical_pb_mom_kern_list tensor_menergy_kernels[] = { +GKYL_CU_D static const gkyl_canonical_pb_mom_kern_list tensor_menergy_kernels[] = { // 1x kernels - { NULL, kernel_canonical_pb_MEnergy_1x1v_tensor_p1, kernel_canonical_pb_MEnergy_1x1v_tensor_p2 }, // 0 - { NULL, kernel_canonical_pb_MEnergy_1x2v_tensor_p1, kernel_canonical_pb_MEnergy_1x2v_tensor_p2 }, // 1 - { NULL, kernel_canonical_pb_MEnergy_1x3v_tensor_p1, kernel_canonical_pb_MEnergy_1x3v_tensor_p2 }, // 2 + {NULL, kernel_canonical_pb_MEnergy_1x1v_tensor_p1, kernel_canonical_pb_MEnergy_1x1v_tensor_p2 + }, // 0 + {NULL, kernel_canonical_pb_MEnergy_1x2v_tensor_p1, kernel_canonical_pb_MEnergy_1x2v_tensor_p2 + }, // 1 + {NULL, kernel_canonical_pb_MEnergy_1x3v_tensor_p1, kernel_canonical_pb_MEnergy_1x3v_tensor_p2 + }, // 2 // 2x kernels - { NULL, kernel_canonical_pb_MEnergy_2x2v_tensor_p1, kernel_canonical_pb_MEnergy_2x2v_tensor_p2 }, // 3 - { NULL, kernel_canonical_pb_MEnergy_2x3v_tensor_p1, NULL }, // 4 + {NULL, kernel_canonical_pb_MEnergy_2x2v_tensor_p1, kernel_canonical_pb_MEnergy_2x2v_tensor_p2 + }, // 3 + {NULL, kernel_canonical_pb_MEnergy_2x3v_tensor_p1, NULL}, // 4 // 3x kernels - { NULL, kernel_canonical_pb_MEnergy_3x3v_tensor_p1, NULL }, // 5 + {NULL, kernel_canonical_pb_MEnergy_3x3v_tensor_p1, NULL} // 5 }; // Integrated moment kernel list -GKYL_CU_D -static const gkyl_canonical_pb_mom_kern_list tensor_int_five_moments_kernels[] = { +GKYL_CU_D static const gkyl_canonical_pb_mom_kern_list tensor_int_five_moments_kernels[] = { // 1x kernels - { NULL, kernel_canonical_pb_int_five_moments_1x1v_tensor_p1, kernel_canonical_pb_int_five_moments_1x1v_tensor_p2 }, // 0 - { NULL, kernel_canonical_pb_int_five_moments_1x2v_tensor_p1, kernel_canonical_pb_int_five_moments_1x2v_tensor_p2 }, // 1 - { NULL, kernel_canonical_pb_int_five_moments_1x3v_tensor_p1, kernel_canonical_pb_int_five_moments_1x3v_tensor_p2 }, // 2 + {NULL, kernel_canonical_pb_int_five_moments_1x1v_tensor_p1, + kernel_canonical_pb_int_five_moments_1x1v_tensor_p2}, // 0 + {NULL, kernel_canonical_pb_int_five_moments_1x2v_tensor_p1, + kernel_canonical_pb_int_five_moments_1x2v_tensor_p2}, // 1 + {NULL, kernel_canonical_pb_int_five_moments_1x3v_tensor_p1, + kernel_canonical_pb_int_five_moments_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, kernel_canonical_pb_int_five_moments_2x2v_tensor_p1, kernel_canonical_pb_int_five_moments_2x2v_tensor_p2 }, // 3 - { NULL, kernel_canonical_pb_int_five_moments_2x3v_tensor_p1, NULL }, // 4 + {NULL, kernel_canonical_pb_int_five_moments_2x2v_tensor_p1, + kernel_canonical_pb_int_five_moments_2x2v_tensor_p2}, // 3 + {NULL, kernel_canonical_pb_int_five_moments_2x3v_tensor_p1, NULL}, // 4 // 3x kernels - { NULL, kernel_canonical_pb_int_five_moments_3x3v_tensor_p1, NULL }, // 5 + {NULL, kernel_canonical_pb_int_five_moments_3x3v_tensor_p1, NULL} // 5 }; - -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x1v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x1v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x1v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x1v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x3v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x3v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x3v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x3v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_2x2v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_2x2v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_2x2v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_2x2v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_2x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_2x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_2x3v_ser_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_2x3v_ser_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_2x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_2x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_2x3v_ser_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_2x3v_ser_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } - // // Serendipity basis kernels // // M1i_from_H kernel list -GKYL_CU_D -static const gkyl_canonical_pb_mom_kern_list ser_m1i_from_h_kernels[] = { +GKYL_CU_D static const gkyl_canonical_pb_mom_kern_list ser_m1i_from_h_kernels[] = { // 1x kernels - { NULL, kernel_canonical_pb_M1i_from_H_1x1v_ser_p1, kernel_canonical_pb_M1i_from_H_1x1v_ser_p2 }, // 0 - { NULL, kernel_canonical_pb_M1i_from_H_1x2v_ser_p1, kernel_canonical_pb_M1i_from_H_1x2v_ser_p2 }, // 1 - { NULL, kernel_canonical_pb_M1i_from_H_1x3v_ser_p1, kernel_canonical_pb_M1i_from_H_1x3v_ser_p2 }, // 2 + {NULL, kernel_canonical_pb_M1i_from_H_1x1v_ser_p1, kernel_canonical_pb_M1i_from_H_1x1v_ser_p2 + }, // 0 + {NULL, kernel_canonical_pb_M1i_from_H_1x2v_ser_p1, kernel_canonical_pb_M1i_from_H_1x2v_ser_p2 + }, // 1 + {NULL, kernel_canonical_pb_M1i_from_H_1x3v_ser_p1, kernel_canonical_pb_M1i_from_H_1x3v_ser_p2 + }, // 2 // 2x kernels - { NULL, kernel_canonical_pb_M1i_from_H_2x2v_ser_p1, kernel_canonical_pb_M1i_from_H_2x2v_ser_p2 }, // 3 - { NULL, kernel_canonical_pb_M1i_from_H_2x3v_ser_p1, kernel_canonical_pb_M1i_from_H_2x3v_ser_p2 }, // 4 + {NULL, kernel_canonical_pb_M1i_from_H_2x2v_ser_p1, kernel_canonical_pb_M1i_from_H_2x2v_ser_p2 + }, // 3 + {NULL, kernel_canonical_pb_M1i_from_H_2x3v_ser_p1, kernel_canonical_pb_M1i_from_H_2x3v_ser_p2 + }, // 4 // 3x kernels - { NULL, NULL, NULL }, // 5 + {NULL, NULL, NULL} // 5 }; -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x1v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x1v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x1v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x1v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x1v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x1v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x1v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x1v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x2v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x2v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x2v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x2v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x2v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x2v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x2v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x2v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x3v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x3v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x3v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x3v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_1x3v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_1x3v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_1x3v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_1x3v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_2x2v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_2x2v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_2x2v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_2x2v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_2x2v_tensor_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_2x2v_tensor_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_2x2v_tensor_p2(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_2x2v_tensor_p2( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_2x3v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_2x3v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_2x3v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_2x3v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } -GKYL_CU_DH -static void -kernel_canonical_pb_M1i_from_H_3x3v_tensor_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_canonical_pb_M1i_from_H_3x3v_tensor_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); long pidx = gkyl_range_idx(&mom_can_pb->phase_range, idx); - return canonical_pb_M1i_from_H_3x3v_tensor_p1(dx, - (const double*) gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out); + return canonical_pb_M1i_from_H_3x3v_tensor_p1( + dx, (const double *)gkyl_array_cfetch(mom_can_pb->auxfields.hamil, pidx), f, out + ); } // @@ -843,20 +912,22 @@ kernel_canonical_pb_M1i_from_H_3x3v_tensor_p1(const struct gkyl_mom_type *momt, // // M1i_from_H kernel list -GKYL_CU_D -static const gkyl_canonical_pb_mom_kern_list tensor_m1i_from_h_kernels[] = { +GKYL_CU_D static const gkyl_canonical_pb_mom_kern_list tensor_m1i_from_h_kernels[] = { // 1x kernels - { NULL, kernel_canonical_pb_M1i_from_H_1x1v_tensor_p1, kernel_canonical_pb_M1i_from_H_1x1v_tensor_p2 }, // 0 - { NULL, kernel_canonical_pb_M1i_from_H_1x2v_tensor_p1, kernel_canonical_pb_M1i_from_H_1x2v_tensor_p2 }, // 1 - { NULL, kernel_canonical_pb_M1i_from_H_1x3v_tensor_p1, kernel_canonical_pb_M1i_from_H_1x3v_tensor_p2 }, // 2 + {NULL, kernel_canonical_pb_M1i_from_H_1x1v_tensor_p1, + kernel_canonical_pb_M1i_from_H_1x1v_tensor_p2}, // 0 + {NULL, kernel_canonical_pb_M1i_from_H_1x2v_tensor_p1, + kernel_canonical_pb_M1i_from_H_1x2v_tensor_p2}, // 1 + {NULL, kernel_canonical_pb_M1i_from_H_1x3v_tensor_p1, + kernel_canonical_pb_M1i_from_H_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, kernel_canonical_pb_M1i_from_H_2x2v_tensor_p1, kernel_canonical_pb_M1i_from_H_2x2v_tensor_p2 }, // 3 - { NULL, kernel_canonical_pb_M1i_from_H_2x3v_tensor_p1, NULL }, // 4 + {NULL, kernel_canonical_pb_M1i_from_H_2x2v_tensor_p1, + kernel_canonical_pb_M1i_from_H_2x2v_tensor_p2}, // 3 + {NULL, kernel_canonical_pb_M1i_from_H_2x3v_tensor_p1, NULL}, // 4 // 3x kernels - { NULL, kernel_canonical_pb_M1i_from_H_3x3v_tensor_p1, NULL }, // 5 + {NULL, kernel_canonical_pb_M1i_from_H_3x3v_tensor_p1, NULL} // 5 }; - /** * Free moment object. * @@ -869,15 +940,19 @@ void gkyl_mom_can_pb_free(const struct gkyl_ref_count *ref); * Create new canonical-pb moment type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_mom_type* gkyl_mom_canonical_pb_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range, enum gkyl_distribution_moments mom_type); +struct gkyl_mom_type *gkyl_mom_canonical_pb_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, enum gkyl_distribution_moments mom_type +); /** * Create new canonical-pb integrated moment type * object on NV-GPU: see new() method above for documentation. */ -struct gkyl_mom_type* gkyl_int_mom_canonical_pb_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* phase_range, enum gkyl_distribution_moments mom_type); +struct gkyl_mom_type *gkyl_int_mom_canonical_pb_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, enum gkyl_distribution_moments mom_type +); /** * CUDA device function to set auxiliary fields needed in computing moments. @@ -885,7 +960,8 @@ struct gkyl_mom_type* gkyl_int_mom_canonical_pb_cu_dev_new(const struct gkyl_bas * @param momt moment type. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_mom_canonical_pb_set_auxfields_cu(const struct gkyl_mom_type *momt, - struct gkyl_mom_canonical_pb_auxfields auxin); +void gkyl_mom_canonical_pb_set_auxfields_cu( + const struct gkyl_mom_type *momt, struct gkyl_mom_canonical_pb_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_mom_vlasov.h b/vlasov/zero/gkyl_mom_vlasov.h index fdbcd31f4a..cefe96315c 100644 --- a/vlasov/zero/gkyl_mom_vlasov.h +++ b/vlasov/zero/gkyl_mom_vlasov.h @@ -12,9 +12,10 @@ * @param mom_type Name of moment to compute. * @param use_gpu bool to determine if on GPU */ -struct gkyl_mom_type* -gkyl_mom_vlasov_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, enum gkyl_distribution_moments mom_type, bool use_gpu); +struct gkyl_mom_type *gkyl_mom_vlasov_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + enum gkyl_distribution_moments mom_type, bool use_gpu +); /** * Create new integrated Vlasov moment type object. Lab-frame @@ -25,6 +26,7 @@ gkyl_mom_vlasov_new(const struct gkyl_basis* cbasis, * @param mom_type Name of moment to compute. * @param use_gpu bool to determine if on GPU */ -struct gkyl_mom_type* -gkyl_int_mom_vlasov_new(const struct gkyl_basis *cbasis, - const struct gkyl_basis *pbasis, enum gkyl_distribution_moments mom_type, bool use_gpu); +struct gkyl_mom_type *gkyl_int_mom_vlasov_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + enum gkyl_distribution_moments mom_type, bool use_gpu +); diff --git a/vlasov/zero/gkyl_mom_vlasov_priv.h b/vlasov/zero/gkyl_mom_vlasov_priv.h index c106877fdf..fd7881144d 100644 --- a/vlasov/zero/gkyl_mom_vlasov_priv.h +++ b/vlasov/zero/gkyl_mom_vlasov_priv.h @@ -8,242 +8,230 @@ // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; -typedef void (*vlasov_momf_t)(const double *xc, const double *dx, - const int *idx, const double *fIn, double* GKYL_RESTRICT out); +typedef void (*vlasov_momf_t)( + const double *xc, const double *dx, const int *idx, const double *fIn, double *GKYL_RESTRICT out +); // for use in kernel tables -typedef struct { vlasov_momf_t kernels[3]; } gkyl_mom_kern_list; +typedef struct { + vlasov_momf_t kernels[3]; +} gkyl_mom_kern_list; // M0 kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_mom_kern_list ser_m0_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list ser_m0_kernels[] = { // 1x kernels - { NULL, vlasov_M0_1x1v_ser_p1, vlasov_M0_1x1v_ser_p2 }, // 0 - { NULL, vlasov_M0_1x2v_ser_p1, vlasov_M0_1x2v_ser_p2 }, // 1 - { NULL, vlasov_M0_1x3v_ser_p1, vlasov_M0_1x3v_ser_p2 }, // 2 + {NULL, vlasov_M0_1x1v_ser_p1, vlasov_M0_1x1v_ser_p2}, // 0 + {NULL, vlasov_M0_1x2v_ser_p1, vlasov_M0_1x2v_ser_p2}, // 1 + {NULL, vlasov_M0_1x3v_ser_p1, vlasov_M0_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_M0_2x2v_ser_p1, vlasov_M0_2x2v_ser_p2 }, // 3 - { NULL, vlasov_M0_2x3v_ser_p1, vlasov_M0_2x3v_ser_p2 }, // 4 + {NULL, vlasov_M0_2x2v_ser_p1, vlasov_M0_2x2v_ser_p2}, // 3 + {NULL, vlasov_M0_2x3v_ser_p1, vlasov_M0_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_M0_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_M0_3x3v_ser_p1, NULL} // 5 }; // M0 kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_mom_kern_list tensor_m0_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list tensor_m0_kernels[] = { // 1x kernels - { NULL, vlasov_M0_1x1v_tensor_p1, vlasov_M0_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_M0_1x2v_tensor_p1, vlasov_M0_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_M0_1x3v_tensor_p1, vlasov_M0_1x3v_tensor_p2 }, // 2 + {NULL, vlasov_M0_1x1v_tensor_p1, vlasov_M0_1x1v_tensor_p2}, // 0 + {NULL, vlasov_M0_1x2v_tensor_p1, vlasov_M0_1x2v_tensor_p2}, // 1 + {NULL, vlasov_M0_1x3v_tensor_p1, vlasov_M0_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, vlasov_M0_2x2v_tensor_p1, vlasov_M0_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_M0_2x3v_tensor_p1, vlasov_M0_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_M0_2x2v_tensor_p1, vlasov_M0_2x2v_tensor_p2}, // 3 + {NULL, vlasov_M0_2x3v_tensor_p1, vlasov_M0_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_M0_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_M0_3x3v_tensor_p1, NULL} // 5 }; // M1i kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_mom_kern_list ser_m1i_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list ser_m1i_kernels[] = { // 1x kernels - { NULL, vlasov_M1i_1x1v_ser_p1, vlasov_M1i_1x1v_ser_p2 }, // 0 - { NULL, vlasov_M1i_1x2v_ser_p1, vlasov_M1i_1x2v_ser_p2 }, // 1 - { NULL, vlasov_M1i_1x3v_ser_p1, vlasov_M1i_1x3v_ser_p2 }, // 2 + {NULL, vlasov_M1i_1x1v_ser_p1, vlasov_M1i_1x1v_ser_p2}, // 0 + {NULL, vlasov_M1i_1x2v_ser_p1, vlasov_M1i_1x2v_ser_p2}, // 1 + {NULL, vlasov_M1i_1x3v_ser_p1, vlasov_M1i_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_M1i_2x2v_ser_p1, vlasov_M1i_2x2v_ser_p2 }, // 3 - { NULL, vlasov_M1i_2x3v_ser_p1, vlasov_M1i_2x3v_ser_p2 }, // 4 + {NULL, vlasov_M1i_2x2v_ser_p1, vlasov_M1i_2x2v_ser_p2}, // 3 + {NULL, vlasov_M1i_2x3v_ser_p1, vlasov_M1i_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_M1i_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_M1i_3x3v_ser_p1, NULL} // 5 }; // M1i kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_mom_kern_list tensor_m1i_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list tensor_m1i_kernels[] = { // 1x kernels - { NULL, vlasov_M1i_1x1v_tensor_p1, vlasov_M1i_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_M1i_1x2v_tensor_p1, vlasov_M1i_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_M1i_1x3v_tensor_p1, vlasov_M1i_1x3v_tensor_p2 }, // 2 + {NULL, vlasov_M1i_1x1v_tensor_p1, vlasov_M1i_1x1v_tensor_p2}, // 0 + {NULL, vlasov_M1i_1x2v_tensor_p1, vlasov_M1i_1x2v_tensor_p2}, // 1 + {NULL, vlasov_M1i_1x3v_tensor_p1, vlasov_M1i_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, vlasov_M1i_2x2v_tensor_p1, vlasov_M1i_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_M1i_2x3v_tensor_p1, vlasov_M1i_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_M1i_2x2v_tensor_p1, vlasov_M1i_2x2v_tensor_p2}, // 3 + {NULL, vlasov_M1i_2x3v_tensor_p1, vlasov_M1i_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_M1i_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_M1i_3x3v_tensor_p1, NULL} // 5 }; - // M2 kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_mom_kern_list ser_m2_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list ser_m2_kernels[] = { // 1x kernels - { NULL, vlasov_M2_1x1v_ser_p1, vlasov_M2_1x1v_ser_p2 }, // 0 - { NULL, vlasov_M2_1x2v_ser_p1, vlasov_M2_1x2v_ser_p2 }, // 1 - { NULL, vlasov_M2_1x3v_ser_p1, vlasov_M2_1x3v_ser_p2 }, // 2 + {NULL, vlasov_M2_1x1v_ser_p1, vlasov_M2_1x1v_ser_p2}, // 0 + {NULL, vlasov_M2_1x2v_ser_p1, vlasov_M2_1x2v_ser_p2}, // 1 + {NULL, vlasov_M2_1x3v_ser_p1, vlasov_M2_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_M2_2x2v_ser_p1, vlasov_M2_2x2v_ser_p2 }, // 3 - { NULL, vlasov_M2_2x3v_ser_p1, vlasov_M2_2x3v_ser_p2 }, // 4 + {NULL, vlasov_M2_2x2v_ser_p1, vlasov_M2_2x2v_ser_p2}, // 3 + {NULL, vlasov_M2_2x3v_ser_p1, vlasov_M2_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_M2_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_M2_3x3v_ser_p1, NULL} // 5 }; // M2 kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_mom_kern_list tensor_m2_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list tensor_m2_kernels[] = { // 1x kernels - { NULL, vlasov_M2_1x1v_tensor_p1, vlasov_M2_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_M2_1x2v_tensor_p1, vlasov_M2_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_M2_1x3v_tensor_p1, vlasov_M2_1x3v_tensor_p2 }, // 2 + {NULL, vlasov_M2_1x1v_tensor_p1, vlasov_M2_1x1v_tensor_p2}, // 0 + {NULL, vlasov_M2_1x2v_tensor_p1, vlasov_M2_1x2v_tensor_p2}, // 1 + {NULL, vlasov_M2_1x3v_tensor_p1, vlasov_M2_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, vlasov_M2_2x2v_tensor_p1, vlasov_M2_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_M2_2x3v_tensor_p1, vlasov_M2_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_M2_2x2v_tensor_p1, vlasov_M2_2x2v_tensor_p2}, // 3 + {NULL, vlasov_M2_2x3v_tensor_p1, vlasov_M2_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_M2_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_M2_3x3v_tensor_p1, NULL} // 5 }; // M2ij kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_mom_kern_list ser_m2ij_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list ser_m2ij_kernels[] = { // 1x kernels - { NULL, vlasov_M2ij_1x1v_ser_p1, vlasov_M2ij_1x1v_ser_p2 }, // 0 - { NULL, vlasov_M2ij_1x2v_ser_p1, vlasov_M2ij_1x2v_ser_p2 }, // 1 - { NULL, vlasov_M2ij_1x3v_ser_p1, vlasov_M2ij_1x3v_ser_p2 }, // 2 + {NULL, vlasov_M2ij_1x1v_ser_p1, vlasov_M2ij_1x1v_ser_p2}, // 0 + {NULL, vlasov_M2ij_1x2v_ser_p1, vlasov_M2ij_1x2v_ser_p2}, // 1 + {NULL, vlasov_M2ij_1x3v_ser_p1, vlasov_M2ij_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_M2ij_2x2v_ser_p1, vlasov_M2ij_2x2v_ser_p2 }, // 3 - { NULL, vlasov_M2ij_2x3v_ser_p1, vlasov_M2ij_2x3v_ser_p2 }, // 4 + {NULL, vlasov_M2ij_2x2v_ser_p1, vlasov_M2ij_2x2v_ser_p2}, // 3 + {NULL, vlasov_M2ij_2x3v_ser_p1, vlasov_M2ij_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_M2ij_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_M2ij_3x3v_ser_p1, NULL} // 5 }; // M2ij kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_mom_kern_list tensor_m2ij_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list tensor_m2ij_kernels[] = { // 1x kernels - { NULL, vlasov_M2ij_1x1v_tensor_p1, vlasov_M2ij_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_M2ij_1x2v_tensor_p1, vlasov_M2ij_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_M2ij_1x3v_tensor_p1, vlasov_M2ij_1x3v_tensor_p2 }, // 2 + {NULL, vlasov_M2ij_1x1v_tensor_p1, vlasov_M2ij_1x1v_tensor_p2}, // 0 + {NULL, vlasov_M2ij_1x2v_tensor_p1, vlasov_M2ij_1x2v_tensor_p2}, // 1 + {NULL, vlasov_M2ij_1x3v_tensor_p1, vlasov_M2ij_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, vlasov_M2ij_2x2v_tensor_p1, vlasov_M2ij_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_M2ij_2x3v_tensor_p1, vlasov_M2ij_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_M2ij_2x2v_tensor_p1, vlasov_M2ij_2x2v_tensor_p2}, // 3 + {NULL, vlasov_M2ij_2x3v_tensor_p1, vlasov_M2ij_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_M2ij_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_M2ij_3x3v_tensor_p1, NULL} // 5 }; // M3i kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_mom_kern_list ser_m3i_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list ser_m3i_kernels[] = { // 1x kernels - { NULL, vlasov_M3i_1x1v_ser_p1, vlasov_M3i_1x1v_ser_p2 }, // 0 - { NULL, vlasov_M3i_1x2v_ser_p1, vlasov_M3i_1x2v_ser_p2 }, // 1 - { NULL, vlasov_M3i_1x3v_ser_p1, vlasov_M3i_1x3v_ser_p2 }, // 2 + {NULL, vlasov_M3i_1x1v_ser_p1, vlasov_M3i_1x1v_ser_p2}, // 0 + {NULL, vlasov_M3i_1x2v_ser_p1, vlasov_M3i_1x2v_ser_p2}, // 1 + {NULL, vlasov_M3i_1x3v_ser_p1, vlasov_M3i_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_M3i_2x2v_ser_p1, vlasov_M3i_2x2v_ser_p2 }, // 3 - { NULL, vlasov_M3i_2x3v_ser_p1, vlasov_M3i_2x3v_ser_p2 }, // 4 + {NULL, vlasov_M3i_2x2v_ser_p1, vlasov_M3i_2x2v_ser_p2}, // 3 + {NULL, vlasov_M3i_2x3v_ser_p1, vlasov_M3i_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_M3i_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_M3i_3x3v_ser_p1, NULL} // 5 }; // M3i kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_mom_kern_list tensor_m3i_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list tensor_m3i_kernels[] = { // 1x kernels - { NULL, vlasov_M3i_1x1v_tensor_p1, vlasov_M3i_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_M3i_1x2v_tensor_p1, vlasov_M3i_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_M3i_1x3v_tensor_p1, vlasov_M3i_1x3v_tensor_p2 }, // 2 + {NULL, vlasov_M3i_1x1v_tensor_p1, vlasov_M3i_1x1v_tensor_p2}, // 0 + {NULL, vlasov_M3i_1x2v_tensor_p1, vlasov_M3i_1x2v_tensor_p2}, // 1 + {NULL, vlasov_M3i_1x3v_tensor_p1, vlasov_M3i_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, vlasov_M3i_2x2v_tensor_p1, vlasov_M3i_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_M3i_2x3v_tensor_p1, vlasov_M3i_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_M3i_2x2v_tensor_p1, vlasov_M3i_2x2v_tensor_p2}, // 3 + {NULL, vlasov_M3i_2x3v_tensor_p1, vlasov_M3i_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_M3i_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_M3i_3x3v_tensor_p1, NULL} // 5 }; // M3ijk kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_mom_kern_list ser_m3ijk_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list ser_m3ijk_kernels[] = { // 1x kernels - { NULL, vlasov_M3ijk_1x1v_ser_p1, vlasov_M3ijk_1x1v_ser_p2 }, // 0 - { NULL, vlasov_M3ijk_1x2v_ser_p1, vlasov_M3ijk_1x2v_ser_p2 }, // 1 - { NULL, vlasov_M3ijk_1x3v_ser_p1, vlasov_M3ijk_1x3v_ser_p2 }, // 2 + {NULL, vlasov_M3ijk_1x1v_ser_p1, vlasov_M3ijk_1x1v_ser_p2}, // 0 + {NULL, vlasov_M3ijk_1x2v_ser_p1, vlasov_M3ijk_1x2v_ser_p2}, // 1 + {NULL, vlasov_M3ijk_1x3v_ser_p1, vlasov_M3ijk_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_M3ijk_2x2v_ser_p1, vlasov_M3ijk_2x2v_ser_p2 }, // 3 - { NULL, vlasov_M3ijk_2x3v_ser_p1, vlasov_M3ijk_2x3v_ser_p2 }, // 4 + {NULL, vlasov_M3ijk_2x2v_ser_p1, vlasov_M3ijk_2x2v_ser_p2}, // 3 + {NULL, vlasov_M3ijk_2x3v_ser_p1, vlasov_M3ijk_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_M3ijk_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_M3ijk_3x3v_ser_p1, NULL} // 5 }; // M3ijk kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_mom_kern_list tensor_m3ijk_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list tensor_m3ijk_kernels[] = { // 1x kernels - { NULL, vlasov_M3ijk_1x1v_tensor_p1, vlasov_M3ijk_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_M3ijk_1x2v_tensor_p1, vlasov_M3ijk_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_M3ijk_1x3v_tensor_p1, vlasov_M3ijk_1x3v_tensor_p2 }, // 2 + {NULL, vlasov_M3ijk_1x1v_tensor_p1, vlasov_M3ijk_1x1v_tensor_p2}, // 0 + {NULL, vlasov_M3ijk_1x2v_tensor_p1, vlasov_M3ijk_1x2v_tensor_p2}, // 1 + {NULL, vlasov_M3ijk_1x3v_tensor_p1, vlasov_M3ijk_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, vlasov_M3ijk_2x2v_tensor_p1, vlasov_M3ijk_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_M3ijk_2x3v_tensor_p1, vlasov_M3ijk_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_M3ijk_2x2v_tensor_p1, vlasov_M3ijk_2x2v_tensor_p2}, // 3 + {NULL, vlasov_M3ijk_2x3v_tensor_p1, vlasov_M3ijk_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_M3ijk_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_M3ijk_3x3v_tensor_p1, NULL} // 5 }; // Five moments (Zeroth, First, and Second moment together) kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_mom_kern_list ser_five_moments_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list ser_five_moments_kernels[] = { // 1x kernels - { NULL, vlasov_five_moments_1x1v_ser_p1, vlasov_five_moments_1x1v_ser_p2 }, // 0 - { NULL, vlasov_five_moments_1x2v_ser_p1, vlasov_five_moments_1x2v_ser_p2 }, // 1 - { NULL, vlasov_five_moments_1x3v_ser_p1, vlasov_five_moments_1x3v_ser_p2 }, // 2 + {NULL, vlasov_five_moments_1x1v_ser_p1, vlasov_five_moments_1x1v_ser_p2}, // 0 + {NULL, vlasov_five_moments_1x2v_ser_p1, vlasov_five_moments_1x2v_ser_p2}, // 1 + {NULL, vlasov_five_moments_1x3v_ser_p1, vlasov_five_moments_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_five_moments_2x2v_ser_p1, vlasov_five_moments_2x2v_ser_p2 }, // 3 - { NULL, vlasov_five_moments_2x3v_ser_p1, vlasov_five_moments_2x3v_ser_p2 }, // 4 + {NULL, vlasov_five_moments_2x2v_ser_p1, vlasov_five_moments_2x2v_ser_p2}, // 3 + {NULL, vlasov_five_moments_2x3v_ser_p1, vlasov_five_moments_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_five_moments_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_five_moments_3x3v_ser_p1, NULL} // 5 }; // Five moments (Zeroth, First, and Second moment together) kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_mom_kern_list tensor_five_moments_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list tensor_five_moments_kernels[] = { // 1x kernels - { NULL, vlasov_five_moments_1x1v_tensor_p1, vlasov_five_moments_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_five_moments_1x2v_tensor_p1, vlasov_five_moments_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_five_moments_1x3v_tensor_p1, vlasov_five_moments_1x3v_tensor_p2 }, // 2 + {NULL, vlasov_five_moments_1x1v_tensor_p1, vlasov_five_moments_1x1v_tensor_p2}, // 0 + {NULL, vlasov_five_moments_1x2v_tensor_p1, vlasov_five_moments_1x2v_tensor_p2}, // 1 + {NULL, vlasov_five_moments_1x3v_tensor_p1, vlasov_five_moments_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, vlasov_five_moments_2x2v_tensor_p1, vlasov_five_moments_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_five_moments_2x3v_tensor_p1, vlasov_five_moments_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_five_moments_2x2v_tensor_p1, vlasov_five_moments_2x2v_tensor_p2}, // 3 + {NULL, vlasov_five_moments_2x3v_tensor_p1, vlasov_five_moments_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_five_moments_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_five_moments_3x3v_tensor_p1, NULL} // 5 }; // Integrated moments kernel list (Serendipity basis) -GKYL_CU_D -static const gkyl_mom_kern_list ser_int_five_moments_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list ser_int_five_moments_kernels[] = { // 1x kernels - { NULL, vlasov_int_five_moments_1x1v_ser_p1, vlasov_int_five_moments_1x1v_ser_p2 }, // 0 - { NULL, vlasov_int_five_moments_1x2v_ser_p1, vlasov_int_five_moments_1x2v_ser_p2 }, // 1 - { NULL, vlasov_int_five_moments_1x3v_ser_p1, vlasov_int_five_moments_1x3v_ser_p2 }, // 2 + {NULL, vlasov_int_five_moments_1x1v_ser_p1, vlasov_int_five_moments_1x1v_ser_p2}, // 0 + {NULL, vlasov_int_five_moments_1x2v_ser_p1, vlasov_int_five_moments_1x2v_ser_p2}, // 1 + {NULL, vlasov_int_five_moments_1x3v_ser_p1, vlasov_int_five_moments_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_int_five_moments_2x2v_ser_p1, vlasov_int_five_moments_2x2v_ser_p2 }, // 3 - { NULL, vlasov_int_five_moments_2x3v_ser_p1, vlasov_int_five_moments_2x3v_ser_p2 }, // 4 + {NULL, vlasov_int_five_moments_2x2v_ser_p1, vlasov_int_five_moments_2x2v_ser_p2}, // 3 + {NULL, vlasov_int_five_moments_2x3v_ser_p1, vlasov_int_five_moments_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_int_five_moments_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_int_five_moments_3x3v_ser_p1, NULL} // 5 }; // Integrated moments kernel list (Tensor basis) -GKYL_CU_D -static const gkyl_mom_kern_list tensor_int_five_moments_kernels[] = { +GKYL_CU_D static const gkyl_mom_kern_list tensor_int_five_moments_kernels[] = { // 1x kernels - { NULL, vlasov_int_five_moments_1x1v_tensor_p1, vlasov_int_five_moments_1x1v_tensor_p2 }, // 0 - { NULL, vlasov_int_five_moments_1x2v_tensor_p1, vlasov_int_five_moments_1x2v_tensor_p2 }, // 1 - { NULL, vlasov_int_five_moments_1x3v_tensor_p1, vlasov_int_five_moments_1x3v_tensor_p2 }, // 2 + {NULL, vlasov_int_five_moments_1x1v_tensor_p1, vlasov_int_five_moments_1x1v_tensor_p2}, // 0 + {NULL, vlasov_int_five_moments_1x2v_tensor_p1, vlasov_int_five_moments_1x2v_tensor_p2}, // 1 + {NULL, vlasov_int_five_moments_1x3v_tensor_p1, vlasov_int_five_moments_1x3v_tensor_p2}, // 2 // 2x kernels - { NULL, vlasov_int_five_moments_2x2v_tensor_p1, vlasov_int_five_moments_2x2v_tensor_p2 }, // 3 - { NULL, vlasov_int_five_moments_2x3v_tensor_p1, vlasov_int_five_moments_2x3v_tensor_p2 }, // 4 + {NULL, vlasov_int_five_moments_2x2v_tensor_p1, vlasov_int_five_moments_2x2v_tensor_p2}, // 3 + {NULL, vlasov_int_five_moments_2x3v_tensor_p1, vlasov_int_five_moments_2x3v_tensor_p2}, // 4 // 3x kernels - { NULL, vlasov_int_five_moments_3x3v_tensor_p1, NULL }, // 5 + {NULL, vlasov_int_five_moments_3x3v_tensor_p1, NULL} // 5 }; struct mom_type_vlasov { @@ -258,10 +246,10 @@ struct mom_type_vlasov { */ void gkyl_mom_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static void -kernel(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_D static void kernel( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov *mom_vlasov = container_of(momt, struct mom_type_vlasov, momt); return mom_vlasov->kernel(xc, dx, idx, f, out); @@ -272,15 +260,17 @@ kernel(const struct gkyl_mom_type *momt, const double *xc, const double *dx, * Create new Vlasov moment type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_mom_type* -gkyl_mom_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, enum gkyl_distribution_moments mom_type); +struct gkyl_mom_type *gkyl_mom_vlasov_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + enum gkyl_distribution_moments mom_type +); /** * Create new integrated Vlasov moment type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_mom_type* -gkyl_int_mom_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, enum gkyl_distribution_moments mom_type); +struct gkyl_mom_type *gkyl_int_mom_vlasov_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + enum gkyl_distribution_moments mom_type +); #endif diff --git a/vlasov/zero/gkyl_mom_vlasov_sr.h b/vlasov/zero/gkyl_mom_vlasov_sr.h index b1c42197ae..1a89b8bd6a 100644 --- a/vlasov/zero/gkyl_mom_vlasov_sr.h +++ b/vlasov/zero/gkyl_mom_vlasov_sr.h @@ -5,7 +5,7 @@ #include // Struct containing the pointers to auxiliary fields. -struct gkyl_mom_vlasov_sr_auxfields { +struct gkyl_mom_vlasov_sr_auxfields { const struct gkyl_array *gamma; // gamma = sqrt(1 + p^2) }; @@ -22,9 +22,11 @@ struct gkyl_mom_vlasov_sr_auxfields { * @param mom_type Name of moment to compute. * @param use_gpu bool to determine if on GPU */ -struct gkyl_mom_type* gkyl_mom_vlasov_sr_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - const struct gkyl_range* vel_range, enum gkyl_distribution_moments mom_type, bool use_gpu); +struct gkyl_mom_type *gkyl_mom_vlasov_sr_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_distribution_moments mom_type, bool use_gpu +); /** * Create new special relativistic Vlasov integrated moment type @@ -38,9 +40,11 @@ struct gkyl_mom_type* gkyl_mom_vlasov_sr_new(const struct gkyl_basis* cbasis, * @param mom_type Name of moment to compute. * @param use_gpu bool to determine if on GPU */ -struct gkyl_mom_type* gkyl_int_mom_vlasov_sr_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - const struct gkyl_range* vel_range, enum gkyl_distribution_moments mom_type, bool use_gpu); +struct gkyl_mom_type *gkyl_int_mom_vlasov_sr_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_distribution_moments mom_type, bool use_gpu +); /** * Set the auxiliary fields needed in computing moments. @@ -48,5 +52,6 @@ struct gkyl_mom_type* gkyl_int_mom_vlasov_sr_new(const struct gkyl_basis* cbasis * @param momt moment type. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_mom_vlasov_sr_set_auxfields(const struct gkyl_mom_type *momt, - struct gkyl_mom_vlasov_sr_auxfields auxin); +void gkyl_mom_vlasov_sr_set_auxfields( + const struct gkyl_mom_type *momt, struct gkyl_mom_vlasov_sr_auxfields auxin +); diff --git a/vlasov/zero/gkyl_mom_vlasov_sr_priv.h b/vlasov/zero/gkyl_mom_vlasov_sr_priv.h index 06e5444cf3..d6d249fc0c 100644 --- a/vlasov/zero/gkyl_mom_vlasov_sr_priv.h +++ b/vlasov/zero/gkyl_mom_vlasov_sr_priv.h @@ -19,11 +19,13 @@ struct mom_type_vlasov_sr { // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // for use in kernel tables @@ -31,1280 +33,1335 @@ typedef struct { momf_t kernels[3]; } gkyl_vlasov_sr_mom_kern_list; -GKYL_CU_DH -static void -kernel_vlasov_sr_M0_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M0_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M0_1x1v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M0_1x1v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M0_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M0_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M0_1x1v_ser_p2(xc, dx, idx, f, out); + return vlasov_sr_M0_1x1v_ser_p2(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M0_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M0_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M0_1x2v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M0_1x2v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M0_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M0_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M0_1x2v_ser_p2(xc, dx, idx, f, out); + return vlasov_sr_M0_1x2v_ser_p2(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M0_1x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M0_1x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M0_1x3v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M0_1x3v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M0_1x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M0_1x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M0_1x3v_ser_p2(xc, dx, idx, f, out); + return vlasov_sr_M0_1x3v_ser_p2(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M0_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M0_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M0_2x2v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M0_2x2v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M0_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M0_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M0_2x2v_ser_p2(xc, dx, idx, f, out); + return vlasov_sr_M0_2x2v_ser_p2(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M0_2x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M0_2x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M0_2x3v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M0_2x3v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M0_2x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M0_2x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M0_2x3v_ser_p2(xc, dx, idx, f, out); + return vlasov_sr_M0_2x3v_ser_p2(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M0_3x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M0_3x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M0_3x3v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M0_3x3v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M1i_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M1i_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M1i_1x1v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M1i_1x1v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M1i_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M1i_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M1i_1x1v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M1i_1x1v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M1i_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M1i_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M1i_1x2v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M1i_1x2v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M1i_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M1i_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M1i_1x2v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M1i_1x2v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M1i_1x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M1i_1x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M1i_1x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M1i_1x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M1i_1x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M1i_1x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M1i_1x3v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M1i_1x3v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M1i_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M1i_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M1i_2x2v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M1i_2x2v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M1i_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M1i_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M1i_2x2v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M1i_2x2v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M1i_2x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M1i_2x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M1i_2x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M1i_2x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M1i_2x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M1i_2x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M1i_2x3v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M1i_2x3v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M1i_3x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M1i_3x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M1i_3x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M1i_3x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M2_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M2_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M2_1x1v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M2_1x1v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M2_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M2_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M2_1x1v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M2_1x1v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M2_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M2_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M2_1x2v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M2_1x2v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M2_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M2_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M2_1x2v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M2_1x2v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M2_1x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M2_1x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M2_1x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M2_1x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M2_1x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M2_1x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M2_1x3v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M2_1x3v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M2_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M2_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M2_2x2v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M2_2x2v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M2_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M2_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M2_2x2v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M2_2x2v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M2_2x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M2_2x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M2_2x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M2_2x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M2_2x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M2_2x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M2_2x3v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M2_2x3v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M2_3x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M2_3x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_M2_3x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_M2_3x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M3i_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M3i_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M3i_1x1v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M3i_1x1v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M3i_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M3i_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M3i_1x1v_ser_p2(xc, dx, idx, f, out); + return vlasov_sr_M3i_1x1v_ser_p2(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M3i_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M3i_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M3i_1x2v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M3i_1x2v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M3i_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M3i_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M3i_1x2v_ser_p2(xc, dx, idx, f, out); + return vlasov_sr_M3i_1x2v_ser_p2(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M3i_1x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M3i_1x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M3i_1x3v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M3i_1x3v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M3i_1x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M3i_1x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M3i_1x3v_ser_p2(xc, dx, idx, f, out); + return vlasov_sr_M3i_1x3v_ser_p2(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M3i_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M3i_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M3i_2x2v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M3i_2x2v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M3i_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M3i_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M3i_2x2v_ser_p2(xc, dx, idx, f, out); + return vlasov_sr_M3i_2x2v_ser_p2(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M3i_2x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M3i_2x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M3i_2x3v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M3i_2x3v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M3i_2x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M3i_2x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M3i_2x3v_ser_p2(xc, dx, idx, f, out); + return vlasov_sr_M3i_2x3v_ser_p2(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_M3i_3x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_M3i_3x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { - return vlasov_sr_M3i_3x3v_ser_p1(xc, dx, idx, f, out); + return vlasov_sr_M3i_3x3v_ser_p1(xc, dx, idx, f, out); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Ni_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Ni_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Ni_1x1v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Ni_1x1v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Ni_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Ni_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Ni_1x1v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Ni_1x1v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Ni_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Ni_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Ni_1x2v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Ni_1x2v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Ni_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Ni_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Ni_1x2v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Ni_1x2v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Ni_1x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Ni_1x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Ni_1x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Ni_1x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Ni_1x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Ni_1x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Ni_1x3v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Ni_1x3v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Ni_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Ni_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Ni_2x2v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Ni_2x2v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Ni_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Ni_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Ni_2x2v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Ni_2x2v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Ni_2x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Ni_2x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Ni_2x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Ni_2x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Ni_2x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Ni_2x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Ni_2x3v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Ni_2x3v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Ni_3x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Ni_3x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Ni_3x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Ni_3x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Tij_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Tij_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Tij_1x1v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Tij_1x1v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Tij_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Tij_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Tij_1x1v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Tij_1x1v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Tij_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Tij_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Tij_1x2v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Tij_1x2v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Tij_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Tij_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Tij_1x2v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Tij_1x2v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Tij_1x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Tij_1x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Tij_1x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Tij_1x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Tij_1x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Tij_1x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Tij_1x3v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Tij_1x3v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Tij_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Tij_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Tij_2x2v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Tij_2x2v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Tij_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Tij_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Tij_2x2v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Tij_2x2v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Tij_2x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Tij_2x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Tij_2x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Tij_2x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Tij_2x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Tij_2x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Tij_2x3v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Tij_2x3v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_Tij_3x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_Tij_3x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_Tij_3x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_Tij_3x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_int_five_moments_1x1v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_int_five_moments_1x1v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_int_five_moments_1x1v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_int_five_moments_1x1v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_int_five_moments_1x1v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_int_five_moments_1x1v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_int_five_moments_1x1v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_int_five_moments_1x1v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_int_five_moments_1x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_int_five_moments_1x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_int_five_moments_1x2v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_int_five_moments_1x2v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_int_five_moments_1x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_int_five_moments_1x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_int_five_moments_1x2v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_int_five_moments_1x2v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_int_five_moments_1x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_int_five_moments_1x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_int_five_moments_1x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_int_five_moments_1x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_int_five_moments_1x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_int_five_moments_1x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_int_five_moments_1x3v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_int_five_moments_1x3v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_int_five_moments_2x2v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_int_five_moments_2x2v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_int_five_moments_2x2v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_int_five_moments_2x2v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_int_five_moments_2x2v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_int_five_moments_2x2v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_int_five_moments_2x2v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_int_five_moments_2x2v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_int_five_moments_2x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_int_five_moments_2x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_int_five_moments_2x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_int_five_moments_2x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_int_five_moments_2x3v_ser_p2(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_int_five_moments_2x3v_ser_p2( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_int_five_moments_2x3v_ser_p2(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_int_five_moments_2x3v_ser_p2( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } -GKYL_CU_DH -static void -kernel_vlasov_sr_int_five_moments_3x3v_ser_p1(const struct gkyl_mom_type *momt, const double *xc, const double *dx, - const int *idx, const double *f, double* out, void *param) +GKYL_CU_DH static void kernel_vlasov_sr_int_five_moments_3x3v_ser_p1( + const struct gkyl_mom_type *momt, const double *xc, const double *dx, const int *idx, + const double *f, double *out, void *param +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); int cdim = mom_vm_sr->momt.cdim; int pdim = mom_vm_sr->momt.pdim; int idx_vel[GKYL_MAX_DIM]; - for (int i=0; ivel_range, idx_vel); - return vlasov_sr_int_five_moments_3x3v_ser_p1(xc, dx, idx, - (const double*) gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), - f, out); + return vlasov_sr_int_five_moments_3x3v_ser_p1( + xc, dx, idx, (const double *)gkyl_array_cfetch(mom_vm_sr->auxfields.gamma, vidx), f, out + ); } // @@ -1312,101 +1369,99 @@ kernel_vlasov_sr_int_five_moments_3x3v_ser_p1(const struct gkyl_mom_type *momt, // // M0 kernel list -GKYL_CU_D -static const gkyl_vlasov_sr_mom_kern_list ser_m0_kernels[] = { +GKYL_CU_D static const gkyl_vlasov_sr_mom_kern_list ser_m0_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_sr_M0_1x1v_ser_p1, kernel_vlasov_sr_M0_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_sr_M0_1x2v_ser_p1, kernel_vlasov_sr_M0_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_sr_M0_1x3v_ser_p1, kernel_vlasov_sr_M0_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_sr_M0_1x1v_ser_p1, kernel_vlasov_sr_M0_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_sr_M0_1x2v_ser_p1, kernel_vlasov_sr_M0_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_sr_M0_1x3v_ser_p1, kernel_vlasov_sr_M0_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_sr_M0_2x2v_ser_p1, kernel_vlasov_sr_M0_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_sr_M0_2x3v_ser_p1, kernel_vlasov_sr_M0_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_sr_M0_2x2v_ser_p1, kernel_vlasov_sr_M0_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_sr_M0_2x3v_ser_p1, kernel_vlasov_sr_M0_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_sr_M0_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_vlasov_sr_M0_3x3v_ser_p1, NULL} // 5 }; // M1i kernel list -GKYL_CU_D -static const gkyl_vlasov_sr_mom_kern_list ser_m1i_kernels[] = { +GKYL_CU_D static const gkyl_vlasov_sr_mom_kern_list ser_m1i_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_sr_M1i_1x1v_ser_p1, kernel_vlasov_sr_M1i_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_sr_M1i_1x2v_ser_p1, kernel_vlasov_sr_M1i_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_sr_M1i_1x3v_ser_p1, kernel_vlasov_sr_M1i_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_sr_M1i_1x1v_ser_p1, kernel_vlasov_sr_M1i_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_sr_M1i_1x2v_ser_p1, kernel_vlasov_sr_M1i_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_sr_M1i_1x3v_ser_p1, kernel_vlasov_sr_M1i_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_sr_M1i_2x2v_ser_p1, kernel_vlasov_sr_M1i_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_sr_M1i_2x3v_ser_p1, kernel_vlasov_sr_M1i_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_sr_M1i_2x2v_ser_p1, kernel_vlasov_sr_M1i_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_sr_M1i_2x3v_ser_p1, kernel_vlasov_sr_M1i_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_sr_M1i_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_vlasov_sr_M1i_3x3v_ser_p1, NULL} // 5 }; // M2 kernel list -GKYL_CU_D -static const gkyl_vlasov_sr_mom_kern_list ser_m2_kernels[] = { +GKYL_CU_D static const gkyl_vlasov_sr_mom_kern_list ser_m2_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_sr_M2_1x1v_ser_p1, kernel_vlasov_sr_M2_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_sr_M2_1x2v_ser_p1, kernel_vlasov_sr_M2_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_sr_M2_1x3v_ser_p1, kernel_vlasov_sr_M2_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_sr_M2_1x1v_ser_p1, kernel_vlasov_sr_M2_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_sr_M2_1x2v_ser_p1, kernel_vlasov_sr_M2_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_sr_M2_1x3v_ser_p1, kernel_vlasov_sr_M2_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_sr_M2_2x2v_ser_p1, kernel_vlasov_sr_M2_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_sr_M2_2x3v_ser_p1, kernel_vlasov_sr_M2_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_sr_M2_2x2v_ser_p1, kernel_vlasov_sr_M2_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_sr_M2_2x3v_ser_p1, kernel_vlasov_sr_M2_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_sr_M2_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_vlasov_sr_M2_3x3v_ser_p1, NULL} // 5 }; // M3i kernel list -GKYL_CU_D -static const gkyl_vlasov_sr_mom_kern_list ser_m3i_kernels[] = { +GKYL_CU_D static const gkyl_vlasov_sr_mom_kern_list ser_m3i_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_sr_M3i_1x1v_ser_p1, kernel_vlasov_sr_M3i_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_sr_M3i_1x2v_ser_p1, kernel_vlasov_sr_M3i_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_sr_M3i_1x3v_ser_p1, kernel_vlasov_sr_M3i_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_sr_M3i_1x1v_ser_p1, kernel_vlasov_sr_M3i_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_sr_M3i_1x2v_ser_p1, kernel_vlasov_sr_M3i_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_sr_M3i_1x3v_ser_p1, kernel_vlasov_sr_M3i_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_sr_M3i_2x2v_ser_p1, kernel_vlasov_sr_M3i_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_sr_M3i_2x3v_ser_p1, kernel_vlasov_sr_M3i_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_sr_M3i_2x2v_ser_p1, kernel_vlasov_sr_M3i_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_sr_M3i_2x3v_ser_p1, kernel_vlasov_sr_M3i_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_sr_M3i_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_vlasov_sr_M3i_3x3v_ser_p1, NULL} // 5 }; // Ni = (M0, M1i) kernel list -GKYL_CU_D -static const gkyl_vlasov_sr_mom_kern_list ser_Ni_kernels[] = { +GKYL_CU_D static const gkyl_vlasov_sr_mom_kern_list ser_Ni_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_sr_Ni_1x1v_ser_p1, kernel_vlasov_sr_Ni_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_sr_Ni_1x2v_ser_p1, kernel_vlasov_sr_Ni_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_sr_Ni_1x3v_ser_p1, kernel_vlasov_sr_Ni_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_sr_Ni_1x1v_ser_p1, kernel_vlasov_sr_Ni_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_sr_Ni_1x2v_ser_p1, kernel_vlasov_sr_Ni_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_sr_Ni_1x3v_ser_p1, kernel_vlasov_sr_Ni_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_sr_Ni_2x2v_ser_p1, kernel_vlasov_sr_Ni_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_sr_Ni_2x3v_ser_p1, kernel_vlasov_sr_Ni_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_sr_Ni_2x2v_ser_p1, kernel_vlasov_sr_Ni_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_sr_Ni_2x3v_ser_p1, kernel_vlasov_sr_Ni_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_sr_Ni_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_vlasov_sr_Ni_3x3v_ser_p1, NULL} // 5 }; // Tij = (M2, M3i (vdim components), Stress tensor (vdim*(vdim+1))/2 components)) kernel list -GKYL_CU_D -static const gkyl_vlasov_sr_mom_kern_list ser_Tij_kernels[] = { +GKYL_CU_D static const gkyl_vlasov_sr_mom_kern_list ser_Tij_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_sr_Tij_1x1v_ser_p1, kernel_vlasov_sr_Tij_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_sr_Tij_1x2v_ser_p1, kernel_vlasov_sr_Tij_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_sr_Tij_1x3v_ser_p1, kernel_vlasov_sr_Tij_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_sr_Tij_1x1v_ser_p1, kernel_vlasov_sr_Tij_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_sr_Tij_1x2v_ser_p1, kernel_vlasov_sr_Tij_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_sr_Tij_1x3v_ser_p1, kernel_vlasov_sr_Tij_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_sr_Tij_2x2v_ser_p1, kernel_vlasov_sr_Tij_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_sr_Tij_2x3v_ser_p1, kernel_vlasov_sr_Tij_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_sr_Tij_2x2v_ser_p1, kernel_vlasov_sr_Tij_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_sr_Tij_2x3v_ser_p1, kernel_vlasov_sr_Tij_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_sr_Tij_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_vlasov_sr_Tij_3x3v_ser_p1, NULL} // 5 }; // Integrated moment kernel list -GKYL_CU_D -static const gkyl_vlasov_sr_mom_kern_list ser_int_five_moments_kernels[] = { +GKYL_CU_D static const gkyl_vlasov_sr_mom_kern_list ser_int_five_moments_kernels[] = { // 1x kernels - { NULL, kernel_vlasov_sr_int_five_moments_1x1v_ser_p1, kernel_vlasov_sr_int_five_moments_1x1v_ser_p2 }, // 0 - { NULL, kernel_vlasov_sr_int_five_moments_1x2v_ser_p1, kernel_vlasov_sr_int_five_moments_1x2v_ser_p2 }, // 1 - { NULL, kernel_vlasov_sr_int_five_moments_1x3v_ser_p1, kernel_vlasov_sr_int_five_moments_1x3v_ser_p2 }, // 2 + {NULL, kernel_vlasov_sr_int_five_moments_1x1v_ser_p1, + kernel_vlasov_sr_int_five_moments_1x1v_ser_p2}, // 0 + {NULL, kernel_vlasov_sr_int_five_moments_1x2v_ser_p1, + kernel_vlasov_sr_int_five_moments_1x2v_ser_p2}, // 1 + {NULL, kernel_vlasov_sr_int_five_moments_1x3v_ser_p1, + kernel_vlasov_sr_int_five_moments_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, kernel_vlasov_sr_int_five_moments_2x2v_ser_p1, kernel_vlasov_sr_int_five_moments_2x2v_ser_p2 }, // 3 - { NULL, kernel_vlasov_sr_int_five_moments_2x3v_ser_p1, kernel_vlasov_sr_int_five_moments_2x3v_ser_p2 }, // 4 + {NULL, kernel_vlasov_sr_int_five_moments_2x2v_ser_p1, + kernel_vlasov_sr_int_five_moments_2x2v_ser_p2}, // 3 + {NULL, kernel_vlasov_sr_int_five_moments_2x3v_ser_p1, + kernel_vlasov_sr_int_five_moments_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, kernel_vlasov_sr_int_five_moments_3x3v_ser_p1, NULL }, // 5 + {NULL, kernel_vlasov_sr_int_five_moments_3x3v_ser_p1, NULL} // 5 }; /** @@ -1421,17 +1476,21 @@ void gkyl_mom_vm_sr_free(const struct gkyl_ref_count *ref); * Create new special relativistic Vlasov moment type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_mom_type* gkyl_mom_vlasov_sr_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - const struct gkyl_range* vel_range, enum gkyl_distribution_moments mom_type); +struct gkyl_mom_type *gkyl_mom_vlasov_sr_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_distribution_moments mom_type +); /** * Create new special relativistic Vlasov integrated moment type * object on NV-GPU: see new() method above for documentation. */ -struct gkyl_mom_type* gkyl_int_mom_vlasov_sr_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, const struct gkyl_range* conf_range, - const struct gkyl_range* vel_range, enum gkyl_distribution_moments mom_type); +struct gkyl_mom_type *gkyl_int_mom_vlasov_sr_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_distribution_moments mom_type +); /** * CUDA device function to set auxiliary fields needed in computing moments. @@ -1439,6 +1498,7 @@ struct gkyl_mom_type* gkyl_int_mom_vlasov_sr_cu_dev_new(const struct gkyl_basis* * @param momt moment type. * @param auxfields Pointer to struct of aux fields. */ -void gkyl_mom_vlasov_sr_set_auxfields_cu(const struct gkyl_mom_type *momt, - struct gkyl_mom_vlasov_sr_auxfields auxin); +void gkyl_mom_vlasov_sr_set_auxfields_cu( + const struct gkyl_mom_type *momt, struct gkyl_mom_vlasov_sr_auxfields auxin +); #endif diff --git a/vlasov/zero/gkyl_positivity_shift_vlasov.h b/vlasov/zero/gkyl_positivity_shift_vlasov.h index 4ec349f67c..2044f4b960 100644 --- a/vlasov/zero/gkyl_positivity_shift_vlasov.h +++ b/vlasov/zero/gkyl_positivity_shift_vlasov.h @@ -21,9 +21,10 @@ typedef struct gkyl_positivity_shift_vlasov gkyl_positivity_shift_vlasov; * @param use_gpu bool to determine if on GPU. * @return New positivity shift updater pointer. */ -struct gkyl_positivity_shift_vlasov* -gkyl_positivity_shift_vlasov_new(struct gkyl_basis cbasis, struct gkyl_basis pbasis, - struct gkyl_rect_grid pgrid, const struct gkyl_range *conf_rng_ext, bool use_gpu); +struct gkyl_positivity_shift_vlasov *gkyl_positivity_shift_vlasov_new( + struct gkyl_basis cbasis, struct gkyl_basis pbasis, struct gkyl_rect_grid pgrid, + const struct gkyl_range *conf_rng_ext, bool use_gpu +); /** * Run the positivity shift updater in the indicated range. @@ -35,16 +36,15 @@ gkyl_positivity_shift_vlasov_new(struct gkyl_basis cbasis, struct gkyl_basis pba * @param m0 Output M0 moment array. * @param delta_m0 M0 moment of the shift in f. */ -void -gkyl_positivity_shift_vlasov_advance(gkyl_positivity_shift_vlasov* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - struct gkyl_array *GKYL_RESTRICT distf, struct gkyl_array *GKYL_RESTRICT m0, - struct gkyl_array *GKYL_RESTRICT delta_m0); +void gkyl_positivity_shift_vlasov_advance( + gkyl_positivity_shift_vlasov *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, struct gkyl_array *GKYL_RESTRICT distf, + struct gkyl_array *GKYL_RESTRICT m0, struct gkyl_array *GKYL_RESTRICT delta_m0 +); /** * Release the memory associated with this positivity shift updater. * * @param up Positivity shift updater. */ -void -gkyl_positivity_shift_vlasov_release(gkyl_positivity_shift_vlasov* up); +void gkyl_positivity_shift_vlasov_release(gkyl_positivity_shift_vlasov *up); diff --git a/vlasov/zero/gkyl_positivity_shift_vlasov_priv.h b/vlasov/zero/gkyl_positivity_shift_vlasov_priv.h index 0bca46c705..93666b3407 100644 --- a/vlasov/zero/gkyl_positivity_shift_vlasov_priv.h +++ b/vlasov/zero/gkyl_positivity_shift_vlasov_priv.h @@ -12,71 +12,73 @@ enum gkyl_positivity_shift_type { GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY = 0, - GKYL_POSITIVITY_SHIFT_TYPE_MRS_LIMITER, // Moe-Rossmanith-Seal limiter. + GKYL_POSITIVITY_SHIFT_TYPE_MRS_LIMITER // Moe-Rossmanith-Seal limiter. }; // Function pointer type for sheath reflection kernels. typedef bool (*m0_pos_check_t)(const double *m0); typedef bool (*shift_t)(double ffloor, double *distf); -typedef void (*m0_t)(const double *xc, const double *dx, - const int *idx, const double *fIn, double* GKYL_RESTRICT out); - -typedef struct { m0_pos_check_t kernels[3]; } pos_shift_vlasov_kern_list_m0_pos_check; // For use in kernel tables. -typedef struct { shift_t kernels[3]; } pos_shift_vlasov_kern_list_shift; // For use in kernel tables. -typedef struct { m0_t kernels[3]; } pos_shift_vlasov_kern_list_m0; // For use in kernel tables. +typedef void (*m0_t)( + const double *xc, const double *dx, const int *idx, const double *fIn, double *GKYL_RESTRICT out +); + +typedef struct { + m0_pos_check_t kernels[3]; +} pos_shift_vlasov_kern_list_m0_pos_check; // For use in kernel tables. +typedef struct { + shift_t kernels[3]; +} pos_shift_vlasov_kern_list_shift; // For use in kernel tables. +typedef struct { + m0_t kernels[3]; +} pos_shift_vlasov_kern_list_m0; // For use in kernel tables. // Serendipity kernels. -GKYL_CU_D -static const pos_shift_vlasov_kern_list_m0_pos_check pos_shift_vlasov_kern_list_m0_pos_check_tensor[] = { - { positivity_shift_vlasov_conf_pos_check_1x_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_conf_pos_check_2x_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_conf_pos_check_3x_tensor_p1, NULL, NULL }, -}; - -GKYL_CU_D -static const pos_shift_vlasov_kern_list_shift pos_shift_vlasov_kern_list_shift_tensor[] = { - { positivity_shift_vlasov_shift_only_1x1v_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_shift_only_1x2v_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_shift_only_1x3v_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_shift_only_2x2v_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_shift_only_2x3v_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_shift_only_3x3v_tensor_p1, NULL, NULL }, +GKYL_CU_D static const pos_shift_vlasov_kern_list_m0_pos_check + pos_shift_vlasov_kern_list_m0_pos_check_tensor[] = { + {positivity_shift_vlasov_conf_pos_check_1x_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_conf_pos_check_2x_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_conf_pos_check_3x_tensor_p1, NULL, NULL} }; -GKYL_CU_D -static const pos_shift_vlasov_kern_list_shift pos_shift_vlasov_kern_list_MRSlimiter_tensor[] = { - { positivity_shift_vlasov_MRS_limiter_1x1v_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_MRS_limiter_1x2v_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_MRS_limiter_1x3v_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_MRS_limiter_2x2v_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_MRS_limiter_2x3v_tensor_p1, NULL, NULL }, - { positivity_shift_vlasov_MRS_limiter_3x3v_tensor_p1, NULL, NULL }, +GKYL_CU_D static const pos_shift_vlasov_kern_list_shift pos_shift_vlasov_kern_list_shift_tensor[] = + {{positivity_shift_vlasov_shift_only_1x1v_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_shift_only_1x2v_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_shift_only_1x3v_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_shift_only_2x2v_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_shift_only_2x3v_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_shift_only_3x3v_tensor_p1, NULL, NULL}}; + +GKYL_CU_D static const pos_shift_vlasov_kern_list_shift + pos_shift_vlasov_kern_list_MRSlimiter_tensor[] = { + {positivity_shift_vlasov_MRS_limiter_1x1v_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_MRS_limiter_1x2v_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_MRS_limiter_1x3v_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_MRS_limiter_2x2v_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_MRS_limiter_2x3v_tensor_p1, NULL, NULL}, + {positivity_shift_vlasov_MRS_limiter_3x3v_tensor_p1, NULL, NULL} }; -GKYL_CU_D -static const pos_shift_vlasov_kern_list_m0 pos_shift_vlasov_kern_list_m0_tensor[] = { - { vlasov_M0_1x1v_tensor_p1, NULL, NULL }, - { vlasov_M0_1x2v_tensor_p1, NULL, NULL }, - { vlasov_M0_1x3v_tensor_p1, NULL, NULL }, - { vlasov_M0_2x2v_tensor_p1, NULL, NULL }, - { vlasov_M0_2x3v_tensor_p1, NULL, NULL }, - { vlasov_M0_3x3v_tensor_p1, NULL, NULL }, +GKYL_CU_D static const pos_shift_vlasov_kern_list_m0 pos_shift_vlasov_kern_list_m0_tensor[] = { + {vlasov_M0_1x1v_tensor_p1, NULL, NULL}, {vlasov_M0_1x2v_tensor_p1, NULL, NULL}, + {vlasov_M0_1x3v_tensor_p1, NULL, NULL}, {vlasov_M0_2x2v_tensor_p1, NULL, NULL}, + {vlasov_M0_2x3v_tensor_p1, NULL, NULL}, {vlasov_M0_3x3v_tensor_p1, NULL, NULL} }; // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -GKYL_CU_D -static struct { int vdim[4]; } pos_shift_vlasov_cv_index[] = { +GKYL_CU_D static struct { + int vdim[4]; +} pos_shift_vlasov_cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; struct gkyl_positivity_shift_vlasov_kernels { m0_pos_check_t is_m0_positive; // Kernels that checks if m0 is positive. - shift_t shift; // Kernel that shifts f to enforce positivity if needed. - m0_t m0; // Kernel that computes the number density. + shift_t shift; // Kernel that shifts f to enforce positivity if needed. + m0_t m0; // Kernel that computes the number density. inv_op_t conf_inv_op; // Conf-space weak inversion (1/A) kernel (p=1 only). mul_op_t conf_mul_op; // Conf-space weak multiplication kernel. mul_op_t conf_phase_mul_op; // Conf-phase weak multiplication kernel. @@ -84,10 +86,10 @@ struct gkyl_positivity_shift_vlasov_kernels { // Primary struct in this updater. struct gkyl_positivity_shift_vlasov { - int num_cbasis; // Number of conf-space basis monomials. - struct gkyl_rect_grid grid; // Phase-space grid. - double *ffloor; // Minimum f to shift distribution to when it's <0. - double ffloor_fac; // ffloor = max(f)*ffloor_fac. + int num_cbasis; // Number of conf-space basis monomials. + struct gkyl_rect_grid grid; // Phase-space grid. + double *ffloor; // Minimum f to shift distribution to when it's <0. + double ffloor_fac; // ffloor = max(f)*ffloor_fac. double cellav_fac; // Factor multiplying 0th DG coefficient to give cellav. bool use_gpu; struct gkyl_positivity_shift_vlasov_kernels *kernels; @@ -97,21 +99,22 @@ struct gkyl_positivity_shift_vlasov { #ifdef GKYL_HAVE_CUDA // Declaration of cuda device functions. -void -pos_shift_vlasov_choose_shift_kernel_cu(struct gkyl_positivity_shift_vlasov_kernels *kernels, - struct gkyl_basis cbasis, struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype); +void pos_shift_vlasov_choose_shift_kernel_cu( + struct gkyl_positivity_shift_vlasov_kernels *kernels, struct gkyl_basis cbasis, + struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype +); -void -gkyl_positivity_shift_vlasov_advance_cu(gkyl_positivity_shift_vlasov* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - struct gkyl_array *GKYL_RESTRICT distf, struct gkyl_array *GKYL_RESTRICT m0, - struct gkyl_array *GKYL_RESTRICT delta_m0); +void gkyl_positivity_shift_vlasov_advance_cu( + gkyl_positivity_shift_vlasov *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, struct gkyl_array *GKYL_RESTRICT distf, + struct gkyl_array *GKYL_RESTRICT m0, struct gkyl_array *GKYL_RESTRICT delta_m0 +); #endif -GKYL_CU_D -static void pos_shift_vlasov_choose_shift_kernel(struct gkyl_positivity_shift_vlasov_kernels *kernels, - struct gkyl_basis cbasis, struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype, - bool use_gpu) +GKYL_CU_D static void pos_shift_vlasov_choose_shift_kernel( + struct gkyl_positivity_shift_vlasov_kernels *kernels, struct gkyl_basis cbasis, + struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { @@ -122,33 +125,33 @@ static void pos_shift_vlasov_choose_shift_kernel(struct gkyl_positivity_shift_vl enum gkyl_basis_type cbasis_type = cbasis.b_type, pbasis_type = pbasis.b_type; int cdim = cbasis.ndim, pdim = pbasis.ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int poly_order = pbasis.poly_order; int plin = pos_shift_vlasov_cv_index[cdim].vdim[vdim]; switch (pbasis_type) { - case GKYL_BASIS_MODAL_TENSOR: - kernels->is_m0_positive = pos_shift_vlasov_kern_list_m0_pos_check_tensor[cdim-1].kernels[poly_order-1]; - kernels->shift = stype == GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY? - pos_shift_vlasov_kern_list_shift_tensor[plin].kernels[poly_order-1] : - pos_shift_vlasov_kern_list_MRSlimiter_tensor[plin].kernels[poly_order-1]; - kernels->m0 = pos_shift_vlasov_kern_list_m0_tensor[plin].kernels[poly_order-1]; - kernels->conf_phase_mul_op = choose_mul_conf_phase_kern(pbasis_type, cdim, vdim, poly_order); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_TENSOR: + kernels->is_m0_positive = + pos_shift_vlasov_kern_list_m0_pos_check_tensor[cdim - 1].kernels[poly_order - 1]; + kernels->shift = stype == GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY ? + pos_shift_vlasov_kern_list_shift_tensor[plin].kernels[poly_order - 1] : + pos_shift_vlasov_kern_list_MRSlimiter_tensor[plin].kernels[poly_order - 1]; + kernels->m0 = pos_shift_vlasov_kern_list_m0_tensor[plin].kernels[poly_order - 1]; + kernels->conf_phase_mul_op = choose_mul_conf_phase_kern(pbasis_type, cdim, vdim, poly_order); + break; + default: + assert(false); + break; } switch (cbasis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - kernels->conf_inv_op = choose_ser_inv_kern(cdim, poly_order); - kernels->conf_mul_op = choose_ser_mul_kern(cdim, poly_order); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + kernels->conf_inv_op = choose_ser_inv_kern(cdim, poly_order); + kernels->conf_mul_op = choose_ser_mul_kern(cdim, poly_order); + break; + default: + assert(false); + break; } - } diff --git a/vlasov/zero/gkyl_prim_bgk_cross_calc.h b/vlasov/zero/gkyl_prim_bgk_cross_calc.h index 9cda181169..100d3a8605 100644 --- a/vlasov/zero/gkyl_prim_bgk_cross_calc.h +++ b/vlasov/zero/gkyl_prim_bgk_cross_calc.h @@ -24,14 +24,14 @@ * @param range Range in which we'll compute m0_s*delta_s. * @return crossprims Cross primitive moments, u_sri and v_tsr^2. */ -void gkyl_prim_bgk_cross_calc_advance(struct gkyl_basis basis, - int vdim_phys, const struct gkyl_array* m0sdeltas, - double massself, const struct gkyl_array* primsself, - double massother, const struct gkyl_array* primsother, - const struct gkyl_range *range, struct gkyl_array* crossprims); +void gkyl_prim_bgk_cross_calc_advance( + struct gkyl_basis basis, int vdim_phys, const struct gkyl_array *m0sdeltas, double massself, + const struct gkyl_array *primsself, double massother, const struct gkyl_array *primsother, + const struct gkyl_range *range, struct gkyl_array *crossprims +); -void gkyl_prim_bgk_cross_calc_advance_cu(struct gkyl_basis basis, - int vdim_phys, const struct gkyl_array* m0sdeltas, - double massself, const struct gkyl_array* primsself, - double massother, const struct gkyl_array* primsother, - const struct gkyl_range *range, struct gkyl_array* crossprims); +void gkyl_prim_bgk_cross_calc_advance_cu( + struct gkyl_basis basis, int vdim_phys, const struct gkyl_array *m0sdeltas, double massself, + const struct gkyl_array *primsself, double massother, const struct gkyl_array *primsother, + const struct gkyl_range *range, struct gkyl_array *crossprims +); diff --git a/vlasov/zero/gkyl_prim_cross_m0deltas.h b/vlasov/zero/gkyl_prim_cross_m0deltas.h index fa362530da..f9a317a2ff 100644 --- a/vlasov/zero/gkyl_prim_cross_m0deltas.h +++ b/vlasov/zero/gkyl_prim_cross_m0deltas.h @@ -22,9 +22,10 @@ typedef struct gkyl_prim_cross_m0deltas gkyl_prim_cross_m0deltas; * @param use_gpu boolean indicating whether to use the GPU. * @return New updater pointer. */ -gkyl_prim_cross_m0deltas* gkyl_prim_cross_m0deltas_new(bool normNu, - const struct gkyl_basis *basis, const struct gkyl_range *range, - double betap1, bool use_gpu); +gkyl_prim_cross_m0deltas *gkyl_prim_cross_m0deltas_new( + bool normNu, const struct gkyl_basis *basis, const struct gkyl_range *range, double betap1, + bool use_gpu +); /** * Compute @@ -43,14 +44,15 @@ gkyl_prim_cross_m0deltas* gkyl_prim_cross_m0deltas_new(bool normNu, * @param out Output array. * @return New updater pointer. */ -void gkyl_prim_cross_m0deltas_advance(gkyl_prim_cross_m0deltas *up, - double massself, const struct gkyl_array* m0self, const struct gkyl_array* nuself, - double massother, const struct gkyl_array* m0other, const struct gkyl_array* nuother, - struct gkyl_array* out); +void gkyl_prim_cross_m0deltas_advance( + gkyl_prim_cross_m0deltas *up, double massself, const struct gkyl_array *m0self, + const struct gkyl_array *nuself, double massother, const struct gkyl_array *m0other, + const struct gkyl_array *nuother, struct gkyl_array *out +); /** * Delete updater. * * @param pob Updater to delete. */ -void gkyl_prim_cross_m0deltas_release(gkyl_prim_cross_m0deltas* up); +void gkyl_prim_cross_m0deltas_release(gkyl_prim_cross_m0deltas *up); diff --git a/vlasov/zero/gkyl_prim_cross_m0deltas_priv.h b/vlasov/zero/gkyl_prim_cross_m0deltas_priv.h index d7dd669573..99e32cd834 100644 --- a/vlasov/zero/gkyl_prim_cross_m0deltas_priv.h +++ b/vlasov/zero/gkyl_prim_cross_m0deltas_priv.h @@ -28,8 +28,9 @@ struct gkyl_prim_cross_m0deltas { * @param out Output array. * @return New updater pointer. */ -void gkyl_prim_cross_m0deltas_advance_cu(gkyl_prim_cross_m0deltas *up, - double massself, const struct gkyl_array* m0self, const struct gkyl_array* nuself, - double massother, const struct gkyl_array* m0other, const struct gkyl_array* nuother, - struct gkyl_array* out); +void gkyl_prim_cross_m0deltas_advance_cu( + gkyl_prim_cross_m0deltas *up, double massself, const struct gkyl_array *m0self, + const struct gkyl_array *nuself, double massother, const struct gkyl_array *m0other, + const struct gkyl_array *nuother, struct gkyl_array *out +); #endif diff --git a/vlasov/zero/gkyl_prim_lbo_calc.h b/vlasov/zero/gkyl_prim_lbo_calc.h index ee65669d06..b0c518f119 100644 --- a/vlasov/zero/gkyl_prim_lbo_calc.h +++ b/vlasov/zero/gkyl_prim_lbo_calc.h @@ -18,9 +18,9 @@ typedef struct gkyl_prim_lbo_calc gkyl_prim_lbo_calc; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_prim_lbo_calc* -gkyl_prim_lbo_calc_new(const struct gkyl_rect_grid *grid, - struct gkyl_prim_lbo_type *prim, bool use_gpu); +struct gkyl_prim_lbo_calc *gkyl_prim_lbo_calc_new( + const struct gkyl_rect_grid *grid, struct gkyl_prim_lbo_type *prim, bool use_gpu +); /** * Compute primitive moments of distribution function. The phase_rng and conf_rng @@ -35,37 +35,38 @@ gkyl_prim_lbo_calc_new(const struct gkyl_rect_grid *grid, * @param nu Collision frequency. * @param prim_moms_out Output drift velocity and thermal speed squared. */ -void gkyl_prim_lbo_calc_advance(struct gkyl_prim_lbo_calc* calc, - const struct gkyl_range *conf_rng, const struct gkyl_array *moms, +void gkyl_prim_lbo_calc_advance( + struct gkyl_prim_lbo_calc *calc, const struct gkyl_range *conf_rng, const struct gkyl_array *moms, const struct gkyl_array *boundary_corrections, const struct gkyl_array *nu, - struct gkyl_array *prim_moms_out); + struct gkyl_array *prim_moms_out +); /** * Delete pointer to primitive moment calculator updater. * * @param calc Updater to delete. */ -void gkyl_prim_lbo_calc_release(struct gkyl_prim_lbo_calc* calc); +void gkyl_prim_lbo_calc_release(struct gkyl_prim_lbo_calc *calc); /** * Return pointer to primitive moment type structure. * @param calc Updater pointer. */ -const struct gkyl_prim_lbo_type* gkyl_prim_lbo_calc_get_prim(gkyl_prim_lbo_calc* calc); +const struct gkyl_prim_lbo_type *gkyl_prim_lbo_calc_get_prim(gkyl_prim_lbo_calc *calc); // "derived" class constructors -struct gkyl_prim_lbo_calc* -gkyl_prim_lbo_vlasov_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_rng, bool use_gpu); +struct gkyl_prim_lbo_calc *gkyl_prim_lbo_vlasov_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_rng, bool use_gpu +); -struct gkyl_prim_lbo_calc* -gkyl_prim_lbo_pkpm_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_rng, bool use_gpu); +struct gkyl_prim_lbo_calc *gkyl_prim_lbo_pkpm_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_rng, bool use_gpu +); -struct gkyl_prim_lbo_calc* -gkyl_prim_lbo_gyrokinetic_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_rng, bool use_gpu); +struct gkyl_prim_lbo_calc *gkyl_prim_lbo_gyrokinetic_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_rng, bool use_gpu +); diff --git a/vlasov/zero/gkyl_prim_lbo_calc_priv.h b/vlasov/zero/gkyl_prim_lbo_calc_priv.h index 148d343f71..0340edecba 100644 --- a/vlasov/zero/gkyl_prim_lbo_calc_priv.h +++ b/vlasov/zero/gkyl_prim_lbo_calc_priv.h @@ -20,9 +20,8 @@ struct gkyl_prim_lbo_calc { * Create new updater to compute primitive moments of distribution function on * NV-GPU. See new() method for documentation. */ -struct gkyl_prim_lbo_calc* -gkyl_prim_lbo_calc_cu_dev_new(const struct gkyl_rect_grid *grid, - struct gkyl_prim_lbo_type *prim); +struct gkyl_prim_lbo_calc * +gkyl_prim_lbo_calc_cu_dev_new(const struct gkyl_rect_grid *grid, struct gkyl_prim_lbo_type *prim); /** * Compute primitive moments of distribution function. The phase_rng and conf_rng @@ -36,8 +35,9 @@ gkyl_prim_lbo_calc_cu_dev_new(const struct gkyl_rect_grid *grid, * @param boundary_corrections Momentum and Energy boundary corrections * @param prim_moms_out Output drift velocity and thermal speed squared. */ -void gkyl_prim_lbo_calc_advance_cu(struct gkyl_prim_lbo_calc* calc, - const struct gkyl_range *conf_rng, const struct gkyl_array *moms, +void gkyl_prim_lbo_calc_advance_cu( + struct gkyl_prim_lbo_calc *calc, const struct gkyl_range *conf_rng, const struct gkyl_array *moms, const struct gkyl_array *boundary_corrections, const struct gkyl_array *nu, - struct gkyl_array* prim_moms_out); + struct gkyl_array *prim_moms_out +); #endif diff --git a/vlasov/zero/gkyl_prim_lbo_cross_calc.h b/vlasov/zero/gkyl_prim_lbo_cross_calc.h index 6c283d4d68..163281fa77 100644 --- a/vlasov/zero/gkyl_prim_lbo_cross_calc.h +++ b/vlasov/zero/gkyl_prim_lbo_cross_calc.h @@ -18,9 +18,9 @@ typedef struct gkyl_prim_lbo_cross_calc gkyl_prim_lbo_cross_calc; * @param use_gpu bool to determine if on GPU * @return New updater pointer. */ -struct gkyl_prim_lbo_cross_calc* -gkyl_prim_lbo_cross_calc_new(const struct gkyl_rect_grid *grid, - struct gkyl_prim_lbo_type *prim, bool use_gpu); +struct gkyl_prim_lbo_cross_calc *gkyl_prim_lbo_cross_calc_new( + const struct gkyl_rect_grid *grid, struct gkyl_prim_lbo_type *prim, bool use_gpu +); /** * Compute cross-primitive moments of distribution function. The conf_rng @@ -41,34 +41,35 @@ gkyl_prim_lbo_cross_calc_new(const struct gkyl_rect_grid *grid, * @param nu Collision frequency. * @param prim_moms_out Output drift velocity and thermal speed squared. */ -void gkyl_prim_lbo_cross_calc_advance(struct gkyl_prim_lbo_cross_calc* calc, - const struct gkyl_range *conf_rng, const struct gkyl_array *alphaE, - double self_m, const struct gkyl_array *self_moms, const struct gkyl_array *self_prim_moms, - double other_m, const struct gkyl_array *other_moms, const struct gkyl_array *other_prim_moms, - const struct gkyl_array *boundary_corrections, const struct gkyl_array *nu, - struct gkyl_array *prim_moms_out); +void gkyl_prim_lbo_cross_calc_advance( + struct gkyl_prim_lbo_cross_calc *calc, const struct gkyl_range *conf_rng, + const struct gkyl_array *alphaE, double self_m, const struct gkyl_array *self_moms, + const struct gkyl_array *self_prim_moms, double other_m, const struct gkyl_array *other_moms, + const struct gkyl_array *other_prim_moms, const struct gkyl_array *boundary_corrections, + const struct gkyl_array *nu, struct gkyl_array *prim_moms_out +); /** * Delete pointer to primitive moment calculator updater. * * @param calc Updater to delete. */ -void gkyl_prim_lbo_cross_calc_release(gkyl_prim_lbo_cross_calc* calc); +void gkyl_prim_lbo_cross_calc_release(gkyl_prim_lbo_cross_calc *calc); /** * Return pointer to primitive moment type structure. * @param calc Updater pointer. */ -const struct gkyl_prim_lbo_type* gkyl_prim_lbo_cross_calc_get_prim(gkyl_prim_lbo_cross_calc* calc); +const struct gkyl_prim_lbo_type *gkyl_prim_lbo_cross_calc_get_prim(gkyl_prim_lbo_cross_calc *calc); // "derived" class constructors -struct gkyl_prim_lbo_cross_calc* -gkyl_prim_lbo_vlasov_cross_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_rng, bool use_gpu); +struct gkyl_prim_lbo_cross_calc *gkyl_prim_lbo_vlasov_cross_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_rng, bool use_gpu +); -struct gkyl_prim_lbo_cross_calc* -gkyl_prim_lbo_gyrokinetic_cross_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_rng, bool use_gpu); +struct gkyl_prim_lbo_cross_calc *gkyl_prim_lbo_gyrokinetic_cross_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_rng, bool use_gpu +); diff --git a/vlasov/zero/gkyl_prim_lbo_cross_calc_priv.h b/vlasov/zero/gkyl_prim_lbo_cross_calc_priv.h index 5999164224..4715ace570 100644 --- a/vlasov/zero/gkyl_prim_lbo_cross_calc_priv.h +++ b/vlasov/zero/gkyl_prim_lbo_cross_calc_priv.h @@ -21,9 +21,9 @@ struct gkyl_prim_lbo_cross_calc { * Create new updater to compute cross-primitive moments of * distribution function on NV-GPU. See new() method for documentation. */ -struct gkyl_prim_lbo_cross_calc* -gkyl_prim_lbo_cross_calc_cu_dev_new(const struct gkyl_rect_grid *grid, - struct gkyl_prim_lbo_type *prim); +struct gkyl_prim_lbo_cross_calc *gkyl_prim_lbo_cross_calc_cu_dev_new( + const struct gkyl_rect_grid *grid, struct gkyl_prim_lbo_type *prim +); /** * Compute cross-primitive moments of distribution function. The conf_rng @@ -44,10 +44,11 @@ gkyl_prim_lbo_cross_calc_cu_dev_new(const struct gkyl_rect_grid *grid, * @param nu Collision frequency. * @param prim_moms_out Output drift velocity and thermal speed squared. */ -void gkyl_prim_lbo_cross_calc_advance_cu(struct gkyl_prim_lbo_cross_calc* calc, - const struct gkyl_range *conf_rng, const struct gkyl_array *alpha_E, - double self_m, const struct gkyl_array *self_moms, const struct gkyl_array *self_prim_moms, - double other_m, const struct gkyl_array *other_moms, const struct gkyl_array *other_prim_moms, - const struct gkyl_array *boundary_corrections, const struct gkyl_array *nu, - struct gkyl_array *prim_moms_out); -#endif +void gkyl_prim_lbo_cross_calc_advance_cu( + struct gkyl_prim_lbo_cross_calc *calc, const struct gkyl_range *conf_rng, + const struct gkyl_array *alpha_E, double self_m, const struct gkyl_array *self_moms, + const struct gkyl_array *self_prim_moms, double other_m, const struct gkyl_array *other_moms, + const struct gkyl_array *other_prim_moms, const struct gkyl_array *boundary_corrections, + const struct gkyl_array *nu, struct gkyl_array *prim_moms_out +); +#endif diff --git a/vlasov/zero/gkyl_prim_lbo_type.h b/vlasov/zero/gkyl_prim_lbo_type.h index 96883601f5..fadbe176ef 100644 --- a/vlasov/zero/gkyl_prim_lbo_type.h +++ b/vlasov/zero/gkyl_prim_lbo_type.h @@ -7,16 +7,18 @@ struct gkyl_prim_lbo_type; // Self-primitive moment kernel pointer type -typedef void (*self_prim_t)(const struct gkyl_prim_lbo_type *prim, - struct gkyl_mat *A, struct gkyl_mat *rhs, const int* idx, - const double *moms, const double *boundary_corrections, const double *nu); +typedef void (*self_prim_t)( + const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, const int *idx, + const double *moms, const double *boundary_corrections, const double *nu +); // Cross-primitive moment kernel pointer type -typedef void (*cross_prim_t)(const struct gkyl_prim_lbo_type *prim, - struct gkyl_mat *A, struct gkyl_mat *rhs, const int* idx, const double *greene, - const double m_self, const double *moms_self, const double *prim_moms_self, +typedef void (*cross_prim_t)( + const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, const int *idx, + const double *greene, const double m_self, const double *moms_self, const double *prim_moms_self, const double m_other, const double *moms_other, const double *prim_moms_other, - const double *boundary_corrections, const double *nu); + const double *boundary_corrections, const double *nu +); struct gkyl_prim_lbo_type { int cdim; // config-space dim @@ -39,11 +41,11 @@ struct gkyl_prim_lbo_type { * * @param prim Primitive moment object. */ -struct gkyl_prim_lbo_type* gkyl_prim_lbo_type_acquire(const struct gkyl_prim_lbo_type* prim); +struct gkyl_prim_lbo_type *gkyl_prim_lbo_type_acquire(const struct gkyl_prim_lbo_type *prim); /** * Delete primitive moment object * * @param prim Primitive moment object to delete. */ -void gkyl_prim_lbo_type_release(const struct gkyl_prim_lbo_type* prim); +void gkyl_prim_lbo_type_release(const struct gkyl_prim_lbo_type *prim); diff --git a/vlasov/zero/gkyl_prim_lbo_vlasov.h b/vlasov/zero/gkyl_prim_lbo_vlasov.h index 5d72d3bf98..c98017482e 100644 --- a/vlasov/zero/gkyl_prim_lbo_vlasov.h +++ b/vlasov/zero/gkyl_prim_lbo_vlasov.h @@ -11,14 +11,13 @@ * @param use_gpu bool to determine if on GPU * @return Pointer to Vlasov primitive moment object */ -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_vlasov_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, bool use_gpu); +struct gkyl_prim_lbo_type *gkyl_prim_lbo_vlasov_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, bool use_gpu +); /** * Create a new Vlasov primitive type object on NV-GPU: * see new() method above for documentation. */ -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis); +struct gkyl_prim_lbo_type * +gkyl_prim_lbo_vlasov_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis); diff --git a/vlasov/zero/gkyl_prim_lbo_vlasov_priv.h b/vlasov/zero/gkyl_prim_lbo_vlasov_priv.h index bd07e519fd..2db772ea61 100644 --- a/vlasov/zero/gkyl_prim_lbo_vlasov_priv.h +++ b/vlasov/zero/gkyl_prim_lbo_vlasov_priv.h @@ -6,63 +6,70 @@ #include #include -typedef void (*vlasov_self_prim_t)(struct gkyl_mat *A, struct gkyl_mat *rhs, - const double *moms, const double *boundary_corrections, const double *nu); +typedef void (*vlasov_self_prim_t)( + struct gkyl_mat *A, struct gkyl_mat *rhs, const double *moms, const double *boundary_corrections, + const double *nu +); -typedef void (*vlasov_cross_prim_t)(struct gkyl_mat *A, struct gkyl_mat *rhs, const double *greene, - const double m_self, const double *moms_self, const double *prim_moms_self, - const double m_other, const double *moms_other, const double *prim_moms_other, - const double *boundary_corrections, const double *nu); +typedef void (*vlasov_cross_prim_t)( + struct gkyl_mat *A, struct gkyl_mat *rhs, const double *greene, const double m_self, + const double *moms_self, const double *prim_moms_self, const double m_other, + const double *moms_other, const double *prim_moms_other, const double *boundary_corrections, + const double *nu +); // The cv_index[cd].vdim[vd] is used to index the various list of // kernels below -static struct { int vdim[4]; } cv_index[] = { +static struct { + int vdim[4]; +} cv_index[] = { {-1, -1, -1, -1}, // 0x makes no sense - {-1, 0, 1, 2}, // 1x kernel indices - {-1, -1, 3, 4}, // 2x kernel indices - {-1, -1, -1, 5}, // 3x kernel indices + {-1, 0, 1, 2}, // 1x kernel indices + {-1, -1, 3, 4}, // 2x kernel indices + {-1, -1, -1, 5} // 3x kernel indices }; // for use in kernel tables -typedef struct { vlasov_self_prim_t kernels[3]; } gkyl_prim_lbo_vlasov_self_kern_list; -typedef struct { vlasov_cross_prim_t kernels[3]; } gkyl_prim_lbo_vlasov_cross_kern_list; - +typedef struct { + vlasov_self_prim_t kernels[3]; +} gkyl_prim_lbo_vlasov_self_kern_list; +typedef struct { + vlasov_cross_prim_t kernels[3]; +} gkyl_prim_lbo_vlasov_cross_kern_list; // // Serendipity basis kernels // // self-primitive moment kernel list -GKYL_CU_D -static const gkyl_prim_lbo_vlasov_self_kern_list ser_self_prim_kernels[] = { +GKYL_CU_D static const gkyl_prim_lbo_vlasov_self_kern_list ser_self_prim_kernels[] = { // 1x kernels - { NULL, vlasov_self_prim_moments_1x1v_ser_p1, vlasov_self_prim_moments_1x1v_ser_p2 }, // 0 - { NULL, vlasov_self_prim_moments_1x2v_ser_p1, vlasov_self_prim_moments_1x2v_ser_p2 }, // 1 - { NULL, vlasov_self_prim_moments_1x3v_ser_p1, vlasov_self_prim_moments_1x3v_ser_p2 }, // 2 + {NULL, vlasov_self_prim_moments_1x1v_ser_p1, vlasov_self_prim_moments_1x1v_ser_p2}, // 0 + {NULL, vlasov_self_prim_moments_1x2v_ser_p1, vlasov_self_prim_moments_1x2v_ser_p2}, // 1 + {NULL, vlasov_self_prim_moments_1x3v_ser_p1, vlasov_self_prim_moments_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_self_prim_moments_2x2v_ser_p1, vlasov_self_prim_moments_2x2v_ser_p2 }, // 3 - { NULL, vlasov_self_prim_moments_2x3v_ser_p1, vlasov_self_prim_moments_2x3v_ser_p2 }, // 4 + {NULL, vlasov_self_prim_moments_2x2v_ser_p1, vlasov_self_prim_moments_2x2v_ser_p2}, // 3 + {NULL, vlasov_self_prim_moments_2x3v_ser_p1, vlasov_self_prim_moments_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_self_prim_moments_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_self_prim_moments_3x3v_ser_p1, NULL} // 5 }; // cross-primitive moment kernel list -GKYL_CU_D -static const gkyl_prim_lbo_vlasov_cross_kern_list ser_cross_prim_kernels[] = { +GKYL_CU_D static const gkyl_prim_lbo_vlasov_cross_kern_list ser_cross_prim_kernels[] = { // 1x kernels - { NULL, vlasov_cross_prim_moments_1x1v_ser_p1, vlasov_cross_prim_moments_1x1v_ser_p2 }, // 0 - { NULL, vlasov_cross_prim_moments_1x2v_ser_p1, vlasov_cross_prim_moments_1x2v_ser_p2 }, // 1 - { NULL, vlasov_cross_prim_moments_1x3v_ser_p1, vlasov_cross_prim_moments_1x3v_ser_p2 }, // 2 + {NULL, vlasov_cross_prim_moments_1x1v_ser_p1, vlasov_cross_prim_moments_1x1v_ser_p2}, // 0 + {NULL, vlasov_cross_prim_moments_1x2v_ser_p1, vlasov_cross_prim_moments_1x2v_ser_p2}, // 1 + {NULL, vlasov_cross_prim_moments_1x3v_ser_p1, vlasov_cross_prim_moments_1x3v_ser_p2}, // 2 // 2x kernels - { NULL, vlasov_cross_prim_moments_2x2v_ser_p1, vlasov_cross_prim_moments_2x2v_ser_p2 }, // 3 - { NULL, vlasov_cross_prim_moments_2x3v_ser_p1, vlasov_cross_prim_moments_2x3v_ser_p2 }, // 4 + {NULL, vlasov_cross_prim_moments_2x2v_ser_p1, vlasov_cross_prim_moments_2x2v_ser_p2}, // 3 + {NULL, vlasov_cross_prim_moments_2x3v_ser_p1, vlasov_cross_prim_moments_2x3v_ser_p2}, // 4 // 3x kernels - { NULL, vlasov_cross_prim_moments_3x3v_ser_p1, NULL }, // 5 + {NULL, vlasov_cross_prim_moments_3x3v_ser_p1, NULL} // 5 }; struct prim_lbo_type_vlasov { struct gkyl_prim_lbo_type prim; // Base object - vlasov_self_prim_t self_prim; // Self-primitive moments kernel + vlasov_self_prim_t self_prim; // Self-primitive moments kernel vlasov_cross_prim_t cross_prim; // Cross-primitive moments kernels }; @@ -73,26 +80,27 @@ struct prim_lbo_type_vlasov { */ void prim_lbo_vlasov_free(const struct gkyl_ref_count *ref); -GKYL_CU_D -static void -self_prim(const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, - const int *idx, const double *moms, const double *boundary_corrections, const double *nu) +GKYL_CU_D static void self_prim( + const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, const int *idx, + const double *moms, const double *boundary_corrections, const double *nu +) { struct prim_lbo_type_vlasov *prim_vlasov = container_of(prim, struct prim_lbo_type_vlasov, prim); return prim_vlasov->self_prim(A, rhs, moms, boundary_corrections, nu); } -GKYL_CU_D -static void -cross_prim(const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, - const int *idx, const double *greene, - const double m_self, const double *moms_self, const double *prim_moms_self, +GKYL_CU_D static void cross_prim( + const struct gkyl_prim_lbo_type *prim, struct gkyl_mat *A, struct gkyl_mat *rhs, const int *idx, + const double *greene, const double m_self, const double *moms_self, const double *prim_moms_self, const double m_other, const double *moms_other, const double *prim_moms_other, - const double *boundary_corrections, const double *nu) + const double *boundary_corrections, const double *nu +) { struct prim_lbo_type_vlasov *prim_vlasov = container_of(prim, struct prim_lbo_type_vlasov, prim); - return prim_vlasov->cross_prim(A, rhs, greene, m_self, moms_self, prim_moms_self, - m_other, moms_other, prim_moms_other, boundary_corrections, nu); + return prim_vlasov->cross_prim( + A, rhs, greene, m_self, moms_self, prim_moms_self, m_other, moms_other, prim_moms_other, + boundary_corrections, nu + ); } diff --git a/vlasov/zero/gkyl_spitzer_coll_freq.h b/vlasov/zero/gkyl_spitzer_coll_freq.h index 1c448a24b4..b11d35f24e 100644 --- a/vlasov/zero/gkyl_spitzer_coll_freq.h +++ b/vlasov/zero/gkyl_spitzer_coll_freq.h @@ -20,8 +20,10 @@ typedef struct gkyl_spitzer_coll_freq gkyl_spitzer_coll_freq; * @param hbar Planck's constant divided by 2*pi. * @return New updater pointer. */ -gkyl_spitzer_coll_freq* gkyl_spitzer_coll_freq_new(const struct gkyl_basis *basis, - int num_quad, double nufrac, double eps0, double hbar, bool use_gpu); +gkyl_spitzer_coll_freq *gkyl_spitzer_coll_freq_new( + const struct gkyl_basis *basis, int num_quad, double nufrac, double eps0, double hbar, + bool use_gpu +); /** * Scale the normalized collision frequency, normNu, by @@ -36,10 +38,11 @@ gkyl_spitzer_coll_freq* gkyl_spitzer_coll_freq_new(const struct gkyl_basis *basi * @param normNu Normalized collision frequency to scale. * @param nuOut Output collision frequency. */ -void gkyl_spitzer_coll_freq_advance_normnu(const gkyl_spitzer_coll_freq *up, - const struct gkyl_range *range, const struct gkyl_array *momsSelf, double vtSqMinSelf, - const struct gkyl_array *momsOther, double vtSqMinOther, - double normNu, struct gkyl_array *nuOut); +void gkyl_spitzer_coll_freq_advance_normnu( + const gkyl_spitzer_coll_freq *up, const struct gkyl_range *range, + const struct gkyl_array *momsSelf, double vtSqMinSelf, const struct gkyl_array *momsOther, + double vtSqMinOther, double normNu, struct gkyl_array *nuOut +); /** * Compute the Spitzer collision frequency from scratch. Coulomb Logarithm @@ -58,19 +61,18 @@ void gkyl_spitzer_coll_freq_advance_normnu(const gkyl_spitzer_coll_freq *up, * @param vtSqMinOther Minimum vtSq of the other species supported by the grid. * @param nuOut Output collision frequency. */ -void gkyl_spitzer_coll_freq_advance(const gkyl_spitzer_coll_freq *up, - const struct gkyl_range *range, const struct gkyl_array *bmag, - double qSelf, double mSelf, const struct gkyl_array *momsSelf, double vtSqMinSelf, - double qOther, double mOther, const struct gkyl_array *momsOther, double vtSqMinOther, - struct gkyl_array *nuOut); +void gkyl_spitzer_coll_freq_advance( + const gkyl_spitzer_coll_freq *up, const struct gkyl_range *range, const struct gkyl_array *bmag, + double qSelf, double mSelf, const struct gkyl_array *momsSelf, double vtSqMinSelf, double qOther, + double mOther, const struct gkyl_array *momsOther, double vtSqMinOther, struct gkyl_array *nuOut +); /** * Delete updater. * * @param pob Updater to delete. */ -void gkyl_spitzer_coll_freq_release(gkyl_spitzer_coll_freq* up); - +void gkyl_spitzer_coll_freq_release(gkyl_spitzer_coll_freq *up); /** * @@ -94,8 +96,10 @@ void gkyl_spitzer_coll_freq_release(gkyl_spitzer_coll_freq* up); * @param hbar Planck's constant divided by 2*pi. * @param eV Elementary charge. */ -double gkyl_calc_Morse_alpha_E_const(double ns, double nr, double ms, double mr, double qs, double qr, - double Ts, double Tr, double bmag, double eps0, double hbar, double eV); +double gkyl_calc_Morse_alpha_E_const( + double ns, double nr, double ms, double mr, double qs, double qr, double Ts, double Tr, + double bmag, double eps0, double hbar, double eV +); /** * Calculate alpha_E from Morse Phys. Fluids 6, 10 (1963) @@ -114,6 +118,7 @@ double gkyl_calc_Morse_alpha_E_const(double ns, double nr, double ms, double mr, * @param hbar Planck's constant divided by 2*pi. * @param eV Elementary charge. */ -double gkyl_calc_Morse_alpha_E(double ns, double nr, double ms, double mr, double qs, double qr, - double Ts, double Tr, double bmag, double eps0, double hbar, double eV); - +double gkyl_calc_Morse_alpha_E( + double ns, double nr, double ms, double mr, double qs, double qr, double Ts, double Tr, + double bmag, double eps0, double hbar, double eV +); diff --git a/vlasov/zero/gkyl_spitzer_coll_freq_priv.h b/vlasov/zero/gkyl_spitzer_coll_freq_priv.h index 105d26dd6b..7ca759f9d3 100644 --- a/vlasov/zero/gkyl_spitzer_coll_freq_priv.h +++ b/vlasov/zero/gkyl_spitzer_coll_freq_priv.h @@ -14,22 +14,21 @@ struct gkyl_spitzer_coll_freq { struct gkyl_array *basis_at_ords; // conf-space basis functions at ordinates struct gkyl_array *fun_at_ords; // function (Maxwellian) evaluated at - // ordinates in a cell. + // ordinates in a cell. // Time independent factors that can be precomputed. double hbar_fac, r4pieps0_fac, nufraceps0_fac, cellav_fac; double eps0; }; -void -gkyl_spitzer_coll_freq_advance_normnu_cu(const gkyl_spitzer_coll_freq *up, - const struct gkyl_range *range, const struct gkyl_array *momsSelf, double vtSqMinSelf, - const struct gkyl_array *momsOther, double vtSqMinOther, - double normNu, struct gkyl_array *nuOut); - -void -gkyl_spitzer_coll_freq_advance_cu(const gkyl_spitzer_coll_freq *up, - const struct gkyl_range *range, const struct gkyl_array *bmag, - double qSelf, double mSelf, const struct gkyl_array *momsSelf, double vtSqMinSelf, - double qOther, double mOther, const struct gkyl_array *momsOther, double vtSqMinOther, - struct gkyl_array *nuOut); +void gkyl_spitzer_coll_freq_advance_normnu_cu( + const gkyl_spitzer_coll_freq *up, const struct gkyl_range *range, + const struct gkyl_array *momsSelf, double vtSqMinSelf, const struct gkyl_array *momsOther, + double vtSqMinOther, double normNu, struct gkyl_array *nuOut +); + +void gkyl_spitzer_coll_freq_advance_cu( + const gkyl_spitzer_coll_freq *up, const struct gkyl_range *range, const struct gkyl_array *bmag, + double qSelf, double mSelf, const struct gkyl_array *momsSelf, double vtSqMinSelf, double qOther, + double mOther, const struct gkyl_array *momsOther, double vtSqMinOther, struct gkyl_array *nuOut +); diff --git a/vlasov/zero/gkyl_velocity_map.h b/vlasov/zero/gkyl_velocity_map.h index b7054bfa45..76413f6b6a 100644 --- a/vlasov/zero/gkyl_velocity_map.h +++ b/vlasov/zero/gkyl_velocity_map.h @@ -12,7 +12,7 @@ typedef void (*mapc2p_t)(double t, const double *zc, double *vp, void *ctx); // Velocity space mappings. struct gkyl_mapc2p_inp { mapc2p_t mapping; // univariate mapping vp[0](zc[0]), vp[1](zc[1]), etc. - void *ctx; // Context for mapping. + void *ctx; // Context for mapping. }; // Object type. @@ -25,15 +25,15 @@ struct gkyl_velocity_map { struct gkyl_range local, local_ext; // Local & extended local phase-space range. struct gkyl_range local_vel, local_ext_vel; // Local & extended local velocity-space range. struct gkyl_array *jacobvel; // Velocity space Jacobian. - struct gkyl_basis *vmap_basis; // Basis for velocity mapping. + struct gkyl_basis *vmap_basis; // Basis for velocity mapping. struct gkyl_array *vmap; // Velocity mapping in each velocity direction. struct gkyl_array *vmap_prime; // Derivative of the velocity mappings. struct gkyl_array *vmap_sq; // Velocity mapping in each velocity direction squared. struct gkyl_velocity_map *on_dev; // Device copy of itself. - double vbounds[2*GKYL_MAX_VDIM]; // Velocity at the boundaries. + double vbounds[2 * GKYL_MAX_VDIM]; // Velocity at the boundaries. // For internal/private use only: struct gkyl_array *vmap_ho; // Host copy of vmap. - struct gkyl_basis vmap_basis_ho; // Host basis for velocity mapping. + struct gkyl_basis vmap_basis_ho; // Host basis for velocity mapping. uint32_t flags; struct gkyl_ref_count ref_count; }; @@ -53,10 +53,11 @@ struct gkyl_velocity_map { * @param use_gpu Whether to create a device copy of this new object. * @return New velocity map object. */ -struct gkyl_velocity_map* gkyl_velocity_map_new(struct gkyl_mapc2p_inp mapc2p_in, - struct gkyl_rect_grid grid, struct gkyl_rect_grid grid_vel, - struct gkyl_range local, struct gkyl_range local_ext, - struct gkyl_range local_vel, struct gkyl_range local_ext_vel, bool use_gpu); +struct gkyl_velocity_map *gkyl_velocity_map_new( + struct gkyl_mapc2p_inp mapc2p_in, struct gkyl_rect_grid grid, struct gkyl_rect_grid grid_vel, + struct gkyl_range local, struct gkyl_range local_ext, struct gkyl_range local_vel, + struct gkyl_range local_ext_vel, bool use_gpu +); /** * Write the velocity map and its jacobian to file. @@ -66,9 +67,10 @@ struct gkyl_velocity_map* gkyl_velocity_map_new(struct gkyl_mapc2p_inp mapc2p_in * @param app_name Name of the app. * @param species_name Name of the species. */ -void -gkyl_velocity_map_write(const struct gkyl_velocity_map* gvm, struct gkyl_comm* species_comm, - const char* app_name, const char* species_name); +void gkyl_velocity_map_write( + const struct gkyl_velocity_map *gvm, struct gkyl_comm *species_comm, const char *app_name, + const char *species_name +); /** * Evaluate the velocity mappings at the v-space boundary to get the @@ -77,8 +79,7 @@ gkyl_velocity_map_write(const struct gkyl_velocity_map* gvm, struct gkyl_comm* s * @param gvm Velocity map object. * @param vbounds Host array of v-space boundary values (size 2*GKYL_MAX_VDIM). */ -void -gkyl_velocity_map_get_boundary_values(const struct gkyl_velocity_map* gvm, double *vbounds); +void gkyl_velocity_map_get_boundary_values(const struct gkyl_velocity_map *gvm, double *vbounds); /** * Reduce (i.e. get the min or max) the cell length in physical @@ -88,8 +89,9 @@ gkyl_velocity_map_get_boundary_values(const struct gkyl_velocity_map* gvm, doubl * @param op GKYL_MIN or GKYL_MAX. * @param dv_m Min/Max velocity cell length on the grid. */ -void -gkyl_velocity_map_reduce_dv(const struct gkyl_velocity_map* gvm, enum gkyl_array_op op, double *dv_m); +void gkyl_velocity_map_reduce_dv( + const struct gkyl_velocity_map *gvm, enum gkyl_array_op op, double *dv_m +); /** * Reduce (i.e. get the min or max) the cell length in physical @@ -100,9 +102,10 @@ gkyl_velocity_map_reduce_dv(const struct gkyl_velocity_map* gvm, enum gkyl_array * @param range_vel Velocity range to get min/max dv from. * @param dv_m Min/Max velocity cell length on the grid. */ -void -gkyl_velocity_map_reduce_dv_range(const struct gkyl_velocity_map* gvm, enum gkyl_array_op op, - double *dv_m, struct gkyl_range range_vel); +void gkyl_velocity_map_reduce_dv_range( + const struct gkyl_velocity_map *gvm, enum gkyl_array_op op, double *dv_m, + struct gkyl_range range_vel +); /** * Evaluate the velocity mapping at a specific computational (velocity) coordinate. @@ -112,8 +115,7 @@ gkyl_velocity_map_reduce_dv_range(const struct gkyl_velocity_map* gvm, enum gkyl * @param zc Computational velocity coordinates. * @param vp Resulting physical velocity coordinates. */ -void -gkyl_velocity_map_eval_c2p(const struct gkyl_velocity_map* gvm, const double *zc, double *vp); +void gkyl_velocity_map_eval_c2p(const struct gkyl_velocity_map *gvm, const double *zc, double *vp); /** * Indicate if this velocity map object is allocated on the GPU. @@ -121,7 +123,7 @@ gkyl_velocity_map_eval_c2p(const struct gkyl_velocity_map* gvm, const double *zc * @param gvm Velocity map object. * @return */ -bool gkyl_velocity_map_is_cu_dev(const struct gkyl_velocity_map* gvm); +bool gkyl_velocity_map_is_cu_dev(const struct gkyl_velocity_map *gvm); /** * Create a new pointer to the velocity map object. @@ -129,7 +131,7 @@ bool gkyl_velocity_map_is_cu_dev(const struct gkyl_velocity_map* gvm); * * @param New pointer to the velocity map object. */ -struct gkyl_velocity_map* gkyl_velocity_map_acquire(const struct gkyl_velocity_map* gvm); +struct gkyl_velocity_map *gkyl_velocity_map_acquire(const struct gkyl_velocity_map *gvm); /** * Release pointer to (and eventually memory associated with) diff --git a/vlasov/zero/gkyl_velocity_map_priv.h b/vlasov/zero/gkyl_velocity_map_priv.h index 73a5976611..e4b327b623 100644 --- a/vlasov/zero/gkyl_velocity_map_priv.h +++ b/vlasov/zero/gkyl_velocity_map_priv.h @@ -1,14 +1,14 @@ #include // Allocate double array (filled with zeros). -static struct gkyl_array* -mkarr(bool on_gpu, long nc, long size) +static struct gkyl_array *mkarr(bool on_gpu, long nc, long size) { - struct gkyl_array* a; - if (on_gpu) + struct gkyl_array *a; + if (on_gpu) { a = gkyl_array_cu_dev_new(GKYL_DOUBLE, nc, size); - else + } else { a = gkyl_array_new(GKYL_DOUBLE, nc, size); + } return a; } @@ -18,8 +18,7 @@ mkarr(bool on_gpu, long nc, long size) * * @param ref Reference counter for this object. */ -void -gkyl_velocity_map_free(const struct gkyl_ref_count *ref); +void gkyl_velocity_map_free(const struct gkyl_ref_count *ref); #ifdef GKYL_HAVE_CUDA @@ -30,6 +29,6 @@ gkyl_velocity_map_free(const struct gkyl_ref_count *ref); * @param gvm_ho Host side velocity map object. * @return New velocity map object with device pointers. */ -struct gkyl_velocity_map* gkyl_velocity_map_new_cu_dev(struct gkyl_velocity_map *gvm_ho); +struct gkyl_velocity_map *gkyl_velocity_map_new_cu_dev(struct gkyl_velocity_map *gvm_ho); #endif diff --git a/vlasov/zero/gkyl_vlasov_lte_correct.h b/vlasov/zero/gkyl_vlasov_lte_correct.h index 06b277d052..d7bc1be38d 100644 --- a/vlasov/zero/gkyl_vlasov_lte_correct.h +++ b/vlasov/zero/gkyl_vlasov_lte_correct.h @@ -18,20 +18,22 @@ struct gkyl_vlasov_lte_correct_inp { const struct gkyl_basis *vel_basis; // Velocity-space basis functions const struct gkyl_basis *phase_basis; // Phase-space basis functions const struct gkyl_range *conf_range; // Configuration-space range - const struct gkyl_range *conf_range_ext; // Extended configuration-space range (for internal memory allocations) + const struct gkyl_range + *conf_range_ext; // Extended configuration-space range (for internal memory allocations) const struct gkyl_range *vel_range; // velocity space range const struct gkyl_velocity_map *vel_map; // Velocity space mapping object. const struct gkyl_range *phase_range; // phase space range const struct gkyl_array *gamma; // SR quantitiy: gamma = sqrt(1 + p^2) const struct gkyl_array *gamma_inv; // SR quantitiy: 1/gamma = 1/sqrt(1 + p^2) const struct gkyl_array *h_ij; // (Can-pb quantitiy) metric tensor (covariant components) - const struct gkyl_array *h_ij_inv; // (Can-pb quantitiy) inverse metric tensor (contravariant components) - const struct gkyl_array *det_h; // (Can-pb quantitiy) determinant of the metric tensor + const struct gkyl_array + *h_ij_inv; // (Can-pb quantitiy) inverse metric tensor (contravariant components) + const struct gkyl_array *det_h; // (Can-pb quantitiy) determinant of the metric tensor const struct gkyl_array *hamil; // (Can-pb quantitiy) Hamiltonian enum gkyl_model_id model_id; // Enum identifier for model type (e.g., SR, see gkyl_eqn_type.h) enum gkyl_quad_type quad_type; // type of quadrature to use: defaults to Gaussian bool use_last_converged; // Boolean for if we are using the results of the iterative scheme - // *even if* the scheme fails to converge. + // *even if* the scheme fails to converge. bool use_gpu; // bool for gpu usage double eps; // tolerance for the iterator int max_iter; // number of total iterations @@ -42,7 +44,7 @@ struct gkyl_vlasov_lte_correct_status { bool iter_converged; // true if iterations converged int num_iter; // number of iterations for the correction double error[5]; // error in each moment, up to 5 (vdim+2) components -}; +}; /** * Create new updater to correct the LTE (local thermodynamic equlibrium) distribution @@ -52,7 +54,7 @@ struct gkyl_vlasov_lte_correct_status { * @param inp Input parameters defined in gkyl_vlasov_lte_correct_inp struct. * @return New updater pointer. */ -struct gkyl_vlasov_lte_correct* +struct gkyl_vlasov_lte_correct * gkyl_vlasov_lte_correct_inew(const struct gkyl_vlasov_lte_correct_inp *inp); /** @@ -69,18 +71,19 @@ gkyl_vlasov_lte_correct_inew(const struct gkyl_vlasov_lte_correct_inp *inp); * @param conf_local Local configuration space range * @return Status of correction */ -struct gkyl_vlasov_lte_correct_status gkyl_vlasov_lte_correct_all_moments(gkyl_vlasov_lte_correct *up, - struct gkyl_array *f_lte, const struct gkyl_array *moms_target, - const struct gkyl_range *phase_local, const struct gkyl_range *conf_local); +struct gkyl_vlasov_lte_correct_status gkyl_vlasov_lte_correct_all_moments( + gkyl_vlasov_lte_correct *up, struct gkyl_array *f_lte, const struct gkyl_array *moms_target, + const struct gkyl_range *phase_local, const struct gkyl_range *conf_local +); /** * Host-side wrapper for computing the absolute value of the * difference in cell averages between the target moments and iterative moments. */ -void gkyl_vlasov_lte_correct_all_moments_abs_diff_cu(const struct gkyl_range *conf_range, - int num_comp, int nc, - const struct gkyl_array *moms_target, const struct gkyl_array *moms_iter, - struct gkyl_array *moms_abs_diff); +void gkyl_vlasov_lte_correct_all_moments_abs_diff_cu( + const struct gkyl_range *conf_range, int num_comp, int nc, const struct gkyl_array *moms_target, + const struct gkyl_array *moms_iter, struct gkyl_array *moms_abs_diff +); /** * Delete updater. diff --git a/vlasov/zero/gkyl_vlasov_lte_correct_priv.h b/vlasov/zero/gkyl_vlasov_lte_correct_priv.h index a60ce67685..169298d984 100644 --- a/vlasov/zero/gkyl_vlasov_lte_correct_priv.h +++ b/vlasov/zero/gkyl_vlasov_lte_correct_priv.h @@ -7,8 +7,7 @@ #include #include -struct gkyl_vlasov_lte_correct -{ +struct gkyl_vlasov_lte_correct { int num_conf_basis; // Number of configuration-space basis functions int num_comp; // Number of components being corrected vdim+2 (n, V_drift, T/m) @@ -26,9 +25,9 @@ struct gkyl_vlasov_lte_correct double eps; // tolerance for the iterator int max_iter; // number of total iterations bool use_last_converged; // Boolean for if we are using the results of the iterative scheme - // *even if* the scheme fails to converge. + // *even if* the scheme fails to converge. bool use_gpu; // Boolean if we are performing projection on device. - double *error_cu; // error on device if using GPUs + double *error_cu; // error on device if using GPUs struct gkyl_array *abs_diff_moms; }; diff --git a/vlasov/zero/gkyl_vlasov_lte_moments.h b/vlasov/zero/gkyl_vlasov_lte_moments.h index b3243521d9..4f2b7dda43 100644 --- a/vlasov/zero/gkyl_vlasov_lte_moments.h +++ b/vlasov/zero/gkyl_vlasov_lte_moments.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include // Object type typedef struct gkyl_vlasov_lte_moments gkyl_vlasov_lte_moments; @@ -16,21 +16,22 @@ struct gkyl_vlasov_lte_moments_inp { const struct gkyl_basis *vel_basis; // Velocity-space basis functions const struct gkyl_basis *phase_basis; // Phase-space basis functions const struct gkyl_range *conf_range; // Configuration-space range - const struct gkyl_range *conf_range_ext; // Extended configuration-space range (for internal memory allocations) + const struct gkyl_range + *conf_range_ext; // Extended configuration-space range (for internal memory allocations) const struct gkyl_range *vel_range; // Velocity-space range const struct gkyl_range *phase_range; // Phase-space range const struct gkyl_array *gamma; // SR quantitiy: gamma = sqrt(1 + p^2) const struct gkyl_array *gamma_inv; // SR quantitiy: 1/gamma = 1/sqrt(1 + p^2) const struct gkyl_array *h_ij; // Can-pb quantity: metric tensor (covariant components) - const struct gkyl_array *h_ij_inv; // Can-pb quantity: Inverse metric tensor (contravaraint components) + const struct gkyl_array + *h_ij_inv; // Can-pb quantity: Inverse metric tensor (contravaraint components) const struct gkyl_array *det_h; // Can-pb quantity: determinant of the metric tensor const struct gkyl_array *hamil; // Can-pb quantity: hamiltonian enum gkyl_model_id model_id; // Enum identifier for model type (e.g., SR, see gkyl_eqn_type.h) - double mass; // Mass factor + double mass; // Mass factor bool use_gpu; // bool for gpu useage }; - /** * Create new updater to compute the moments for the equivalent LTE (local thermodynamic equlibrium) * distribution function (Maxwellian for non-relativistic/Maxwell-Juttner for relativistic) @@ -40,7 +41,7 @@ struct gkyl_vlasov_lte_moments_inp { * @param inp Input parameters defined in gkyl_vlasov_lte_moments_inp struct. * @return New updater pointer. */ -struct gkyl_vlasov_lte_moments* +struct gkyl_vlasov_lte_moments * gkyl_vlasov_lte_moments_inew(const struct gkyl_vlasov_lte_moments_inp *inp); /** @@ -55,9 +56,10 @@ gkyl_vlasov_lte_moments_inew(const struct gkyl_vlasov_lte_moments_inp *inp); * @param fin Input distribution function * @param density Output stationary-frame density */ -void gkyl_vlasov_lte_density_moment_advance(struct gkyl_vlasov_lte_moments *lte_moms, - const struct gkyl_range *phase_local, const struct gkyl_range *conf_local, - const struct gkyl_array *fin, struct gkyl_array *density); +void gkyl_vlasov_lte_density_moment_advance( + struct gkyl_vlasov_lte_moments *lte_moms, const struct gkyl_range *phase_local, + const struct gkyl_range *conf_local, const struct gkyl_array *fin, struct gkyl_array *density +); /** * Compute the moments of an arbitrary distribution function for the equivalent @@ -72,13 +74,14 @@ void gkyl_vlasov_lte_density_moment_advance(struct gkyl_vlasov_lte_moments *lte_ * @param fin Input distribution function * @param moms Output LTE moments (n, V_drift, T/m) */ -void gkyl_vlasov_lte_moments_advance(struct gkyl_vlasov_lte_moments *lte_moms, - const struct gkyl_range *phase_local, const struct gkyl_range *conf_local, - const struct gkyl_array *fin, struct gkyl_array *moms); +void gkyl_vlasov_lte_moments_advance( + struct gkyl_vlasov_lte_moments *lte_moms, const struct gkyl_range *phase_local, + const struct gkyl_range *conf_local, const struct gkyl_array *fin, struct gkyl_array *moms +); /** * Delete updater. * * @param lte_moms Updater to delete. */ -void gkyl_vlasov_lte_moments_release(gkyl_vlasov_lte_moments* lte_moms); +void gkyl_vlasov_lte_moments_release(gkyl_vlasov_lte_moments *lte_moms); diff --git a/vlasov/zero/gkyl_vlasov_lte_moments_priv.h b/vlasov/zero/gkyl_vlasov_lte_moments_priv.h index 7373f7f179..47fec24660 100644 --- a/vlasov/zero/gkyl_vlasov_lte_moments_priv.h +++ b/vlasov/zero/gkyl_vlasov_lte_moments_priv.h @@ -9,8 +9,7 @@ #include #include -struct gkyl_vlasov_lte_moments -{ +struct gkyl_vlasov_lte_moments { struct gkyl_basis conf_basis; // Configuration-space basis struct gkyl_basis phase_basis; // Phase-space basis int num_conf_basis; // Number of configuration-space basis functions @@ -18,10 +17,10 @@ struct gkyl_vlasov_lte_moments enum gkyl_model_id model_id; // Enum identifier for model type (e.g., SR, see gkyl_eqn_type.h) double mass; // Species mass - struct gkyl_array *M0; - struct gkyl_array *M1i; + struct gkyl_array *M0; + struct gkyl_array *M1i; struct gkyl_array *V_drift; - struct gkyl_array *V_drift_dot_M1i; + struct gkyl_array *V_drift_dot_M1i; struct gkyl_array *pressure; struct gkyl_array *temperature; struct gkyl_dg_bin_op_mem *mem; @@ -43,12 +42,12 @@ struct gkyl_vlasov_lte_moments struct gkyl_array *h_ij_inv; struct gkyl_array *det_h; struct gkyl_dg_calc_canonical_pb_vars *can_pb_vars; - struct gkyl_array *M1i_cov; + struct gkyl_array *M1i_cov; struct gkyl_array *V_drift_cov; }; }; - struct gkyl_dg_updater_moment *M0_calc; + struct gkyl_dg_updater_moment *M0_calc; struct gkyl_dg_updater_moment *M1i_calc; struct gkyl_dg_updater_moment *Pcalc; }; diff --git a/vlasov/zero/gkyl_vlasov_lte_proj_on_basis.h b/vlasov/zero/gkyl_vlasov_lte_proj_on_basis.h index f2f45e070d..caf2b9c6ba 100644 --- a/vlasov/zero/gkyl_vlasov_lte_proj_on_basis.h +++ b/vlasov/zero/gkyl_vlasov_lte_proj_on_basis.h @@ -18,14 +18,16 @@ struct gkyl_vlasov_lte_proj_on_basis_inp { const struct gkyl_basis *vel_basis; // Velocity-space basis functions const struct gkyl_basis *phase_basis; // Phase-space basis functions const struct gkyl_range *conf_range; // Configuration-space range - const struct gkyl_range *conf_range_ext; // Extended configuration-space range (for internal memory allocations) + const struct gkyl_range + *conf_range_ext; // Extended configuration-space range (for internal memory allocations) const struct gkyl_range *vel_range; // velocity space range const struct gkyl_range *phase_range; // phase space range const struct gkyl_array *gamma; // SR quantitiy: gamma = sqrt(1 + p^2) const struct gkyl_array *gamma_inv; // SR quantitiy: 1/gamma = 1/sqrt(1 + p^2) const struct gkyl_velocity_map *vel_map; // Velocity space mapping object. const struct gkyl_array *h_ij; // (Can-bp quantity) metric tensor (covariant components) - const struct gkyl_array *h_ij_inv; // (Can-bp quantity) inverse of the metric tensor (contravariant components) + const struct gkyl_array + *h_ij_inv; // (Can-bp quantity) inverse of the metric tensor (contravariant components) const struct gkyl_array *det_h; // (Can-bp quantity) determinant of the metric tensor const struct gkyl_array *hamil; // (Can-bp quantity) Hamiltonian enum gkyl_model_id model_id; // Enum identifier for model type (e.g., SR, see gkyl_eqn_type.h) @@ -45,7 +47,7 @@ struct gkyl_vlasov_lte_proj_on_basis_inp { * @param inp Input parameters defined in gkyl_vlasov_lte_proj_on_basis_inp struct. * @return New updater pointer. */ -struct gkyl_vlasov_lte_proj_on_basis* +struct gkyl_vlasov_lte_proj_on_basis * gkyl_vlasov_lte_proj_on_basis_inew(const struct gkyl_vlasov_lte_proj_on_basis_inp *inp); /** @@ -63,27 +65,30 @@ gkyl_vlasov_lte_proj_on_basis_inew(const struct gkyl_vlasov_lte_proj_on_basis_in * Note: LTE moments are defined in stationary frame (frame moving at V_drift) * @param f_lte Output LTE distribution function */ -void gkyl_vlasov_lte_proj_on_basis_advance(gkyl_vlasov_lte_proj_on_basis *up, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *moms_lte, struct gkyl_array *f_lte); +void gkyl_vlasov_lte_proj_on_basis_advance( + gkyl_vlasov_lte_proj_on_basis *up, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *moms_lte, struct gkyl_array *f_lte +); /** * Host-side wrapper for initial canonical-pb vars */ -void gkyl_vlasov_lte_proj_on_basis_geom_quad_vars_cu(gkyl_vlasov_lte_proj_on_basis *up, - const struct gkyl_range *conf_range, const struct gkyl_array *h_ij, - const struct gkyl_array *h_ij_inv, const struct gkyl_array *det_h); +void gkyl_vlasov_lte_proj_on_basis_geom_quad_vars_cu( + gkyl_vlasov_lte_proj_on_basis *up, const struct gkyl_range *conf_range, + const struct gkyl_array *h_ij, const struct gkyl_array *h_ij_inv, const struct gkyl_array *det_h +); /** * Host-side wrapper for projection of LTE distribution function on device */ -void gkyl_vlasov_lte_proj_on_basis_advance_cu(gkyl_vlasov_lte_proj_on_basis *up, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *moms_lte, struct gkyl_array *f_lte); +void gkyl_vlasov_lte_proj_on_basis_advance_cu( + gkyl_vlasov_lte_proj_on_basis *up, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *moms_lte, struct gkyl_array *f_lte +); /** * Delete updater. * * @param up Updater to delete. */ -void gkyl_vlasov_lte_proj_on_basis_release(gkyl_vlasov_lte_proj_on_basis* up); +void gkyl_vlasov_lte_proj_on_basis_release(gkyl_vlasov_lte_proj_on_basis *up); diff --git a/vlasov/zero/gkyl_vlasov_lte_proj_on_basis_priv.h b/vlasov/zero/gkyl_vlasov_lte_proj_on_basis_priv.h index 466ba12437..a60afc623a 100644 --- a/vlasov/zero/gkyl_vlasov_lte_proj_on_basis_priv.h +++ b/vlasov/zero/gkyl_vlasov_lte_proj_on_basis_priv.h @@ -10,26 +10,28 @@ #include #include #include -#include +#include #include #include -GKYL_CU_DH -static inline void -comp_to_phys(int ndim, const double *eta, - const double * GKYL_RESTRICT dx, const double * GKYL_RESTRICT xc, - double* GKYL_RESTRICT xout) +GKYL_CU_DH static inline void comp_to_phys( + int ndim, const double *eta, const double *GKYL_RESTRICT dx, const double *GKYL_RESTRICT xc, + double *GKYL_RESTRICT xout +) { - for (int d=0; d #include -static void -create_offsets(struct gkyl_hyper_dg *up, const struct gkyl_range *range, long offsets[]) +static void create_offsets(struct gkyl_hyper_dg *up, const struct gkyl_range *range, long offsets[]) { // Construct the offsets *only* in the directions being updated. // No need to load the neighbors that are not needed for the update. int lower_offset[GKYL_MAX_DIM] = {0}; int upper_offset[GKYL_MAX_DIM] = {0}; - for (int d=0; dnum_up_dirs; ++d) { + for (int d = 0; d < up->num_up_dirs; ++d) { int dir = up->update_dirs[d]; lower_offset[dir] = -1; upper_offset[dir] = 1; - } + } // box spanning stencil struct gkyl_range box3; @@ -30,12 +29,12 @@ create_offsets(struct gkyl_hyper_dg *up, const struct gkyl_range *range, long of gkyl_range_iter_init(&iter3, &box3); // construct list of offsets int count = 0; - while (gkyl_range_iter_next(&iter3)) + while (gkyl_range_iter_next(&iter3)) { offsets[count++] = gkyl_range_offset(range, iter3.idx); + } } -void -gkyl_hyper_dg_set_update_vol(gkyl_hyper_dg *up, int update_vol_term) +void gkyl_hyper_dg_set_update_vol(gkyl_hyper_dg *up, int update_vol_term) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { @@ -46,9 +45,10 @@ gkyl_hyper_dg_set_update_vol(gkyl_hyper_dg *up, int update_vol_term) up->update_vol_term = update_vol_term; } -void -gkyl_hyper_dg_advance(struct gkyl_hyper_dg *up, const struct gkyl_range *update_range, - const struct gkyl_array *fIn, struct gkyl_array *cflrate, struct gkyl_array *rhs) +void gkyl_hyper_dg_advance( + struct gkyl_hyper_dg *up, const struct gkyl_range *update_range, const struct gkyl_array *fIn, + struct gkyl_array *cflrate, struct gkyl_array *rhs +) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { @@ -72,64 +72,63 @@ gkyl_hyper_dg_advance(struct gkyl_hyper_dg *up, const struct gkyl_range *update_ long linc = gkyl_range_idx(update_range, idxc); if (up->update_vol_term) { double cflr = up->equation->vol_term( - up->equation, xcc, up->grid.dx, idxc, - gkyl_array_cfetch(fIn, linc), gkyl_array_fetch(rhs, linc) + up->equation, xcc, up->grid.dx, idxc, gkyl_array_cfetch(fIn, linc), + gkyl_array_fetch(rhs, linc) ); double *cflrate_d = gkyl_array_fetch(cflrate, linc); cflrate_d[0] += cflr; // frequencies are additive } - - for (int d=0; dnum_up_dirs; ++d) { + + for (int d = 0; d < up->num_up_dirs; ++d) { int dir = up->update_dirs[d]; double cfls = 0.0; // Assumes update_range owns lower and upper edges of the domain - if ((up->zero_flux_flags[dir] && idxc[dir] == update_range->lower[dir]) || - (up->zero_flux_flags[dir+ndim] && idxc[dir] == update_range->upper[dir]) ) { + if ((up->zero_flux_flags[dir] && idxc[dir] == update_range->lower[dir]) || + (up->zero_flux_flags[dir + ndim] && idxc[dir] == update_range->upper[dir])) { gkyl_copy_int_arr(ndim, iter.idx, idx_edge); edge = (idxc[dir] == update_range->lower[dir]) ? -1 : 1; // idx_edge stores interior edge index (first index away from skin cell) - idx_edge[dir] = idx_edge[dir]-edge; + idx_edge[dir] = idx_edge[dir] - edge; gkyl_rect_grid_cell_center(&up->grid, idx_edge, xc_edge); long lin_edge = gkyl_range_idx(update_range, idx_edge); - cfls = up->equation->boundary_surf_term(up->equation, - dir, xc_edge, xcc, up->grid.dx, up->grid.dx, - idx_edge, idxc, edge, + cfls = up->equation->boundary_surf_term( + up->equation, dir, xc_edge, xcc, up->grid.dx, up->grid.dx, idx_edge, idxc, edge, gkyl_array_cfetch(fIn, lin_edge), gkyl_array_cfetch(fIn, linc), gkyl_array_fetch(rhs, linc) ); - } - else { + } else { gkyl_copy_int_arr(ndim, iter.idx, idxl); gkyl_copy_int_arr(ndim, iter.idx, idxr); - idxl[dir] = idxl[dir]-1; idxr[dir] = idxr[dir]+1; - + idxl[dir] = idxl[dir] - 1; + idxr[dir] = idxr[dir] + 1; + gkyl_rect_grid_cell_center(&up->grid, idxl, xcl); gkyl_rect_grid_cell_center(&up->grid, idxr, xcr); - long linl = gkyl_range_idx(update_range, idxl); + long linl = gkyl_range_idx(update_range, idxl); long linr = gkyl_range_idx(update_range, idxr); - cfls = up->equation->surf_term(up->equation, - dir, xcl, xcc, xcr, up->grid.dx, up->grid.dx, up->grid.dx, - idxl, idxc, idxr, + cfls = up->equation->surf_term( + up->equation, dir, xcl, xcc, xcr, up->grid.dx, up->grid.dx, up->grid.dx, idxl, idxc, idxr, gkyl_array_cfetch(fIn, linl), gkyl_array_cfetch(fIn, linc), gkyl_array_cfetch(fIn, linr), gkyl_array_fetch(rhs, linc) ); } double *cflrate_d = gkyl_array_fetch(cflrate, linc); - cflrate_d[0] += cfls; // frequencies are additive + cflrate_d[0] += cfls; // frequencies are additive } } } -void -gkyl_hyper_dg_gen_stencil_advance(gkyl_hyper_dg *up, const struct gkyl_range *update_range, - const struct gkyl_array *fIn, struct gkyl_array *cflrate, struct gkyl_array *rhs) +void gkyl_hyper_dg_gen_stencil_advance( + gkyl_hyper_dg *up, const struct gkyl_range *update_range, const struct gkyl_array *fIn, + struct gkyl_array *cflrate, struct gkyl_array *rhs +) { int ndim = up->ndim; - long sz[] = { 3, 9, 27 }; - long sz_dim = sz[up->num_up_dirs-1]; + long sz[] = {3, 9, 27}; + long sz_dim = sz[up->num_up_dirs - 1]; long offsets[sz_dim]; create_offsets(up, update_range, offsets); @@ -141,7 +140,7 @@ gkyl_hyper_dg_gen_stencil_advance(gkyl_hyper_dg *up, const struct gkyl_range *up int idx[sz_dim][GKYL_MAX_DIM]; double xc[sz_dim][GKYL_MAX_DIM]; double dx[sz_dim][GKYL_MAX_DIM]; - const double* fIn_d[sz_dim]; + const double *fIn_d[sz_dim]; // bool for checking if index is in the domain int in_grid = 1; @@ -155,31 +154,32 @@ gkyl_hyper_dg_gen_stencil_advance(gkyl_hyper_dg *up, const struct gkyl_range *up gkyl_copy_int_arr(ndim, iter.idx, idxc); gkyl_rect_grid_cell_center(&up->grid, idxc, xcc); double cflr = up->equation->vol_term( - up->equation, xcc, up->grid.dx, idxc, - gkyl_array_cfetch(fIn, linc), gkyl_array_fetch(rhs, linc) + up->equation, xcc, up->grid.dx, idxc, gkyl_array_cfetch(fIn, linc), + gkyl_array_fetch(rhs, linc) ); double *cflrate_d = gkyl_array_fetch(cflrate, linc); cflrate_d[0] += cflr; // frequencies are additive // Get pointers to all neighbor values (i.e., 9 cells in 2D, 27 cells in 3D) - for (int i=0; inum_up_dirs; ++d) { + for (int d = 0; d < up->num_up_dirs; ++d) { int dir = up->update_dirs[d]; if (idx[i][dir] < update_range->lower[dir] || idx[i][dir] > update_range->upper[dir]) { in_grid = 0; } } - + // Only if the index is in the domain, fetch the pointer (otherwise pointer stays NULL) if (in_grid) { gkyl_rect_grid_cell_center(&up->grid, idx[i], xc[i]); - for (int j=0; jgrid.dx[j]; + } fIn_d[i] = gkyl_array_cfetch(fIn, linc + offsets[i]); } // reset in_grid for next neighbor value check @@ -188,24 +188,21 @@ gkyl_hyper_dg_gen_stencil_advance(gkyl_hyper_dg *up, const struct gkyl_range *up // Loop over surfaces and update using any/all neighbors needed // NOTE: ASSUMES UNIFORM GRIDS FOR NOW - for (int d1=0; d1num_up_dirs; ++d1) { - for (int d2=0; d2num_up_dirs; ++d2) { + for (int d1 = 0; d1 < up->num_up_dirs; ++d1) { + for (int d2 = 0; d2 < up->num_up_dirs; ++d2) { double cfls = 0.0; int dir1 = up->update_dirs[d1]; int dir2 = up->update_dirs[d2]; // Assumes update_range owns lower and upper edges of the domain - if (idxc[dir1] == update_range->lower[dir1] || idxc[dir1] == update_range->upper[dir1] - || idxc[dir2] == update_range->lower[dir2] || idxc[dir2] == update_range->upper[dir2]) { - cfls = up->equation->gen_boundary_surf_term(up->equation, - dir1, dir2, xcc, up->grid.dx, idxc, - sz_dim, idx, fIn_d, + if (idxc[dir1] == update_range->lower[dir1] || idxc[dir1] == update_range->upper[dir1] || + idxc[dir2] == update_range->lower[dir2] || idxc[dir2] == update_range->upper[dir2]) { + cfls = up->equation->gen_boundary_surf_term( + up->equation, dir1, dir2, xcc, up->grid.dx, idxc, sz_dim, idx, fIn_d, gkyl_array_fetch(rhs, linc) ); - } - else { - cfls = up->equation->gen_surf_term(up->equation, - dir1, dir2, xcc, up->grid.dx, idxc, - sz_dim, idx, fIn_d, + } else { + cfls = up->equation->gen_surf_term( + up->equation, dir1, dir2, xcc, up->grid.dx, idxc, sz_dim, idx, fIn_d, gkyl_array_fetch(rhs, linc) ); } @@ -216,16 +213,18 @@ gkyl_hyper_dg_gen_stencil_advance(gkyl_hyper_dg *up, const struct gkyl_range *up } } -gkyl_hyper_dg* -gkyl_hyper_dg_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, const struct gkyl_dg_eqn *equation, - int num_up_dirs, int update_dirs[GKYL_MAX_DIM], int zero_flux_flags[2*GKYL_MAX_DIM], - int update_vol_term, bool use_gpu) +gkyl_hyper_dg *gkyl_hyper_dg_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_dg_eqn *equation, int num_up_dirs, int update_dirs[GKYL_MAX_DIM], + int zero_flux_flags[2 * GKYL_MAX_DIM], int update_vol_term, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { - return gkyl_hyper_dg_cu_dev_new(grid, basis, equation, num_up_dirs, update_dirs, zero_flux_flags, update_vol_term); - } + return gkyl_hyper_dg_cu_dev_new( + grid, basis, equation, num_up_dirs, update_dirs, zero_flux_flags, update_vol_term + ); + } #endif gkyl_hyper_dg *up = gkyl_malloc(sizeof(gkyl_hyper_dg)); @@ -234,29 +233,31 @@ gkyl_hyper_dg_new(const struct gkyl_rect_grid *grid, up->num_basis = basis->num_basis; up->num_up_dirs = num_up_dirs; - for (int i=0; iupdate_dirs[i] = update_dirs[i]; + } - for (int i=0; i<2*GKYL_MAX_DIM; ++i) + for (int i = 0; i < 2 * GKYL_MAX_DIM; ++i) { up->zero_flux_flags[i] = zero_flux_flags[i]; - + } + up->update_vol_term = update_vol_term; up->equation = gkyl_dg_eqn_acquire(equation); up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); - + up->on_dev = up; // on host, on_dev points to itself up->use_gpu = use_gpu; return up; } -void gkyl_hyper_dg_release(struct gkyl_hyper_dg* up) +void gkyl_hyper_dg_release(struct gkyl_hyper_dg *up) { gkyl_dg_eqn_release(up->equation); - if (GKYL_IS_CU_ALLOC(up->flags)) + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } - diff --git a/vlasov/zero/hyper_dg_cu.cu b/vlasov/zero/hyper_dg_cu.cu index 8d61466e8f..034ae5596d 100644 --- a/vlasov/zero/hyper_dg_cu.cu +++ b/vlasov/zero/hyper_dg_cu.cu @@ -20,10 +20,10 @@ gkyl_hyper_dg_set_update_vol_cu_kernel(gkyl_hyper_dg *up, int update_vol_term) up->update_vol_term = update_vol_term; } -__global__ static void -gkyl_hyper_dg_advance_cu_kernel(gkyl_hyper_dg* up, struct gkyl_range update_range, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT cflrate, - struct gkyl_array* GKYL_RESTRICT rhs) +__global__ static void gkyl_hyper_dg_advance_cu_kernel( + gkyl_hyper_dg *up, struct gkyl_range update_range, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT cflrate, struct gkyl_array *GKYL_RESTRICT rhs +) { int ndim = up->ndim; int idxl[GKYL_MAX_DIM], idxc[GKYL_MAX_DIM], idxr[GKYL_MAX_DIM]; @@ -31,8 +31,8 @@ gkyl_hyper_dg_advance_cu_kernel(gkyl_hyper_dg* up, struct gkyl_range update_rang // integer used for selecting between left-edge zero-flux BCs and right-edge zero-flux BCs int edge; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < update_range.volume; linc1 += blockDim.x*gridDim.x) { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < update_range.volume; + linc1 += blockDim.x * gridDim.x) { // inverse index from linc1 to idxc // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idxc={1,1,...} // since update_range is a subrange @@ -45,94 +45,95 @@ gkyl_hyper_dg_advance_cu_kernel(gkyl_hyper_dg* up, struct gkyl_range update_rang if (up->update_vol_term) { double cflr = up->equation->vol_term( - up->equation, xcc, up->grid.dx, idxc, - (const double*) gkyl_array_cfetch(fIn, linc), (double*) gkyl_array_fetch(rhs, linc) + up->equation, xcc, up->grid.dx, idxc, (const double *)gkyl_array_cfetch(fIn, linc), + (double *)gkyl_array_fetch(rhs, linc) ); - double *cflrate_d = (double*) gkyl_array_fetch(cflrate, linc); + double *cflrate_d = (double *)gkyl_array_fetch(cflrate, linc); cflrate_d[0] += cflr; // frequencies are additive } - - for (int d=0; dnum_up_dirs; ++d) { + + for (int d = 0; d < up->num_up_dirs; ++d) { int dir = up->update_dirs[d]; double cfls = 0.0; gkyl_copy_int_arr(ndim, idxc, idxl); gkyl_copy_int_arr(ndim, idxc, idxr); // TODO: fix for arbitrary subrange - if ((up->zero_flux_flags[dir] && idxc[dir] == update_range.lower[dir]) || - (up->zero_flux_flags[dir+ndim] && idxc[dir] == update_range.upper[dir])) { + if ((up->zero_flux_flags[dir] && idxc[dir] == update_range.lower[dir]) || + (up->zero_flux_flags[dir + ndim] && idxc[dir] == update_range.upper[dir])) { edge = (idxc[dir] == update_range.lower[dir]) ? -1 : 1; // use idxl to store interior edge index (first index away from skin cell) - idxl[dir] = idxl[dir]-edge; + idxl[dir] = idxl[dir] - edge; gkyl_rect_grid_cell_center(&up->grid, idxl, xcl); long linl = gkyl_range_idx(&update_range, idxl); - cfls = up->equation->boundary_surf_term(up->equation, - dir, xcl, xcc, up->grid.dx, up->grid.dx, - idxl, idxc, edge, - (const double*) gkyl_array_cfetch(fIn, linl), (const double*) gkyl_array_cfetch(fIn, linc), - (double*) gkyl_array_fetch(rhs, linc) + cfls = up->equation->boundary_surf_term( + up->equation, dir, xcl, xcc, up->grid.dx, up->grid.dx, idxl, idxc, edge, + (const double *)gkyl_array_cfetch(fIn, linl), + (const double *)gkyl_array_cfetch(fIn, linc), (double *)gkyl_array_fetch(rhs, linc) ); - } - else { - idxl[dir] = idxl[dir]-1; - idxr[dir] = idxr[dir]+1; + } else { + idxl[dir] = idxl[dir] - 1; + idxr[dir] = idxr[dir] + 1; gkyl_rect_grid_cell_center(&up->grid, idxl, xcl); gkyl_rect_grid_cell_center(&up->grid, idxr, xcr); - long linl = gkyl_range_idx(&update_range, idxl); + long linl = gkyl_range_idx(&update_range, idxl); long linr = gkyl_range_idx(&update_range, idxr); - cfls = up->equation->surf_term(up->equation, - dir, xcl, xcc, xcr, up->grid.dx, up->grid.dx, up->grid.dx, - idxl, idxc, idxr, - (const double*) gkyl_array_cfetch(fIn, linl), (const double*) gkyl_array_cfetch(fIn, linc), - (const double*) gkyl_array_cfetch(fIn, linr), (double*) gkyl_array_fetch(rhs, linc) + cfls = up->equation->surf_term( + up->equation, dir, xcl, xcc, xcr, up->grid.dx, up->grid.dx, up->grid.dx, idxl, idxc, idxr, + (const double *)gkyl_array_cfetch(fIn, linl), + (const double *)gkyl_array_cfetch(fIn, linc), + (const double *)gkyl_array_cfetch(fIn, linr), (double *)gkyl_array_fetch(rhs, linc) ); } - double *cflrate_d = (double*) gkyl_array_fetch(cflrate, linc); - cflrate_d[0] += cfls; // frequencies are additive + double *cflrate_d = (double *)gkyl_array_fetch(cflrate, linc); + cflrate_d[0] += cfls; // frequencies are additive } } } // wrapper to call advance kernel on device -void -gkyl_hyper_dg_advance_cu(gkyl_hyper_dg* up, const struct gkyl_range *update_range, - const struct gkyl_array* GKYL_RESTRICT fIn, struct gkyl_array* GKYL_RESTRICT cflrate, - struct gkyl_array* GKYL_RESTRICT rhs) +void gkyl_hyper_dg_advance_cu( + gkyl_hyper_dg *up, const struct gkyl_range *update_range, + const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT cflrate, + struct gkyl_array *GKYL_RESTRICT rhs +) { int nblocks = update_range->nblocks; int nthreads = update_range->nthreads; - gkyl_hyper_dg_advance_cu_kernel<<>>(up->on_dev, *update_range, - fIn->on_dev, cflrate->on_dev, rhs->on_dev); + gkyl_hyper_dg_advance_cu_kernel<< > >( + up->on_dev, *update_range, fIn->on_dev, cflrate->on_dev, rhs->on_dev + ); } -void -gkyl_hyper_dg_set_update_vol_cu(gkyl_hyper_dg *up, int update_vol_term) +void gkyl_hyper_dg_set_update_vol_cu(gkyl_hyper_dg *up, int update_vol_term) { - gkyl_hyper_dg_set_update_vol_cu_kernel<<<1,1>>>(up, update_vol_term); + gkyl_hyper_dg_set_update_vol_cu_kernel<<<1, 1> > >(up, update_vol_term); } -gkyl_hyper_dg* -gkyl_hyper_dg_cu_dev_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *basis, const struct gkyl_dg_eqn *equation, - int num_up_dirs, int update_dirs[GKYL_MAX_DIM], int zero_flux_flags[2*GKYL_MAX_DIM], - int update_vol_term) +gkyl_hyper_dg *gkyl_hyper_dg_cu_dev_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *basis, + const struct gkyl_dg_eqn *equation, int num_up_dirs, int update_dirs[GKYL_MAX_DIM], + int zero_flux_flags[2 * GKYL_MAX_DIM], int update_vol_term +) { - gkyl_hyper_dg *up = (gkyl_hyper_dg*) gkyl_malloc(sizeof(gkyl_hyper_dg)); + gkyl_hyper_dg *up = (gkyl_hyper_dg *)gkyl_malloc(sizeof(gkyl_hyper_dg)); up->ndim = basis->ndim; up->num_basis = basis->num_basis; up->num_up_dirs = num_up_dirs; up->grid = *grid; - for (int i=0; iupdate_dirs[i] = update_dirs[i]; + } - for (int i=0; i<2*GKYL_MAX_DIM; ++i) + for (int i = 0; i < 2 * GKYL_MAX_DIM; ++i) { up->zero_flux_flags[i] = zero_flux_flags[i]; - + } + up->update_vol_term = update_vol_term; // aquire pointer to equation object @@ -141,9 +142,9 @@ gkyl_hyper_dg_cu_dev_new(const struct gkyl_rect_grid *grid, up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - + // copy host struct to device struct - gkyl_hyper_dg *up_cu = (gkyl_hyper_dg*) gkyl_cu_malloc(sizeof(gkyl_hyper_dg)); + gkyl_hyper_dg *up_cu = (gkyl_hyper_dg *)gkyl_cu_malloc(sizeof(gkyl_hyper_dg)); gkyl_cu_memcpy(up_cu, up, sizeof(struct gkyl_hyper_dg), GKYL_CU_MEMCPY_H2D); up->on_dev = up_cu; // set parent pointer diff --git a/vlasov/zero/mom_bcorr_lbo_vlasov.c b/vlasov/zero/mom_bcorr_lbo_vlasov.c index 6efb61b035..42c9979180 100644 --- a/vlasov/zero/mom_bcorr_lbo_vlasov.c +++ b/vlasov/zero/mom_bcorr_lbo_vlasov.c @@ -8,29 +8,30 @@ #include #include -void -mom_free(const struct gkyl_ref_count *ref) +void mom_free(const struct gkyl_ref_count *ref) { struct gkyl_mom_type *momt = container_of(ref, struct gkyl_mom_type, ref_count); - if (GKYL_IS_CU_ALLOC(momt->flags)) + if (GKYL_IS_CU_ALLOC(momt->flags)) { gkyl_cu_free(momt->on_dev); + } gkyl_free(momt); } - -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_vlasov_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const double* vBoundary, bool use_gpu) +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_vlasov_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, const double *vBoundary, + bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_mom_bcorr_lbo_vlasov_cu_dev_new(cbasis, pbasis, vBoundary); - } -#endif - struct mom_type_bcorr_lbo_vlasov *mom_bcorr = gkyl_malloc(sizeof(struct mom_type_bcorr_lbo_vlasov)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + } +#endif + struct mom_type_bcorr_lbo_vlasov *mom_bcorr = + gkyl_malloc(sizeof(struct mom_type_bcorr_lbo_vlasov)); + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_bcorr->momt.cdim = cdim; @@ -39,7 +40,7 @@ gkyl_mom_bcorr_lbo_vlasov_new(const struct gkyl_basis* cbasis, const struct gkyl mom_bcorr->momt.num_config = cbasis->num_basis; mom_bcorr->momt.num_phase = pbasis->num_basis; mom_bcorr->momt.kernel = kernel; - for (int d=0; dvBoundary[d] = vBoundary[d]; mom_bcorr->vBoundary[d + vdim] = vBoundary[d + vdim]; } @@ -48,37 +49,38 @@ gkyl_mom_bcorr_lbo_vlasov_new(const struct gkyl_basis* cbasis, const struct gkyl const gkyl_mom_bcorr_lbo_vlasov_kern_list *mom_bcorr_lbo_vlasov_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - mom_bcorr_lbo_vlasov_kernels = ser_mom_bcorr_lbo_vlasov_kernels; - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + mom_bcorr_lbo_vlasov_kernels = ser_mom_bcorr_lbo_vlasov_kernels; + break; /* case GKYL_BASIS_MODAL_TENSOR: */ /* mom_bcorr_lbo_vlasov_kernels = ten_mom_bcorr_lbo_vlasov_kernels; */ /* break; */ - default: - assert(false); - break; + default: + assert(false); + break; } assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != mom_bcorr_lbo_vlasov_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); mom_bcorr->kernel = mom_bcorr_lbo_vlasov_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - mom_bcorr->momt.num_mom = vdim+1; + mom_bcorr->momt.num_mom = vdim + 1; mom_bcorr->momt.flags = 0; GKYL_CLEAR_CU_ALLOC(mom_bcorr->momt.flags); mom_bcorr->momt.ref_count = gkyl_ref_count_init(mom_free); mom_bcorr->momt.on_dev = &mom_bcorr->momt; - + return &mom_bcorr->momt; } #ifndef GKYL_HAVE_CUDA -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, const double* vBoundary) +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_vlasov_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, const double *vBoundary +) { assert(false); } diff --git a/vlasov/zero/mom_bcorr_lbo_vlasov_cu.cu b/vlasov/zero/mom_bcorr_lbo_vlasov_cu.cu index 2e9355c8c6..c30e1791f8 100644 --- a/vlasov/zero/mom_bcorr_lbo_vlasov_cu.cu +++ b/vlasov/zero/mom_bcorr_lbo_vlasov_cu.cu @@ -10,9 +10,10 @@ extern "C" { #include } -__global__ -static void -gkyl_mom_bcorr_lbo_vlasov_set_cu_dev_ptrs(struct mom_type_bcorr_lbo_vlasov* mom_bcorr, enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx) +__global__ static void gkyl_mom_bcorr_lbo_vlasov_set_cu_dev_ptrs( + struct mom_type_bcorr_lbo_vlasov *mom_bcorr, enum gkyl_basis_type b_type, int vdim, + int poly_order, int tblidx +) { mom_bcorr->momt.kernel = kernel; @@ -24,26 +25,28 @@ gkyl_mom_bcorr_lbo_vlasov_set_cu_dev_ptrs(struct mom_type_bcorr_lbo_vlasov* mom_ mom_bcorr_lbo_vlasov_kernels = ser_mom_bcorr_lbo_vlasov_kernels; break; - // case GKYL_BASIS_MODAL_TENSOR: - // mom_bcorr_lbo_vlasov_kernels = ten_mom_bcorr_lbo_vlasov_kernels; - // break; + // case GKYL_BASIS_MODAL_TENSOR: + // mom_bcorr_lbo_vlasov_kernels = ten_mom_bcorr_lbo_vlasov_kernels; + // break; default: assert(false); break; } mom_bcorr->kernel = mom_bcorr_lbo_vlasov_kernels[tblidx].kernels[poly_order]; - mom_bcorr->momt.num_mom = vdim+1; + mom_bcorr->momt.num_mom = vdim + 1; } -struct gkyl_mom_type* -gkyl_mom_bcorr_lbo_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, const double *vBoundary) +struct gkyl_mom_type *gkyl_mom_bcorr_lbo_vlasov_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, const double *vBoundary +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_bcorr_lbo_vlasov *mom_bcorr = (struct mom_type_bcorr_lbo_vlasov*) gkyl_malloc(sizeof(struct mom_type_bcorr_lbo_vlasov)); + struct mom_type_bcorr_lbo_vlasov *mom_bcorr = + (struct mom_type_bcorr_lbo_vlasov *)gkyl_malloc(sizeof(struct mom_type_bcorr_lbo_vlasov)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_bcorr->momt.cdim = cdim; @@ -51,26 +54,28 @@ gkyl_mom_bcorr_lbo_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, const stru mom_bcorr->momt.poly_order = poly_order; mom_bcorr->momt.num_config = cbasis->num_basis; mom_bcorr->momt.num_phase = pbasis->num_basis; - for (int d=0; dvBoundary[d] = vBoundary[d]; mom_bcorr->vBoundary[d + vdim] = vBoundary[d + vdim]; } - mom_bcorr->momt.num_mom = vdim+1; // number of moments + mom_bcorr->momt.num_mom = vdim + 1; // number of moments mom_bcorr->momt.flags = 0; GKYL_SET_CU_ALLOC(mom_bcorr->momt.flags); mom_bcorr->momt.ref_count = gkyl_ref_count_init(gkyl_mom_free); // copy struct to device - struct mom_type_bcorr_lbo_vlasov *mom_bcorr_cu = (struct mom_type_bcorr_lbo_vlasov*) - gkyl_cu_malloc(sizeof(struct mom_type_bcorr_lbo_vlasov)); - gkyl_cu_memcpy(mom_bcorr_cu, mom_bcorr, sizeof(struct mom_type_bcorr_lbo_vlasov), GKYL_CU_MEMCPY_H2D); + struct mom_type_bcorr_lbo_vlasov *mom_bcorr_cu = + (struct mom_type_bcorr_lbo_vlasov *)gkyl_cu_malloc(sizeof(struct mom_type_bcorr_lbo_vlasov)); + gkyl_cu_memcpy( + mom_bcorr_cu, mom_bcorr, sizeof(struct mom_type_bcorr_lbo_vlasov), GKYL_CU_MEMCPY_H2D + ); assert(cv_index[cdim].vdim[vdim] != -1); - - gkyl_mom_bcorr_lbo_vlasov_set_cu_dev_ptrs<<<1,1>>>(mom_bcorr_cu, cbasis->b_type, - vdim, poly_order, cv_index[cdim].vdim[vdim]); + gkyl_mom_bcorr_lbo_vlasov_set_cu_dev_ptrs<<<1, 1> > >( + mom_bcorr_cu, cbasis->b_type, vdim, poly_order, cv_index[cdim].vdim[vdim] + ); mom_bcorr->momt.on_dev = &mom_bcorr_cu->momt; diff --git a/vlasov/zero/mom_calc.c b/vlasov/zero/mom_calc.c index 6bc19f2857..f123911d91 100644 --- a/vlasov/zero/mom_calc.c +++ b/vlasov/zero/mom_calc.c @@ -6,17 +6,16 @@ #include -struct gkyl_mom_calc* -gkyl_mom_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_mom_type *momt, bool use_gpu) +struct gkyl_mom_calc * +gkyl_mom_calc_new(const struct gkyl_rect_grid *grid, const struct gkyl_mom_type *momt, bool use_gpu) { #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_mom_calc_cu_dev_new(grid, momt); - } + } #endif gkyl_mom_calc *up = gkyl_malloc(sizeof(gkyl_mom_calc)); - + up->grid = *grid; up->momt = gkyl_mom_type_acquire(momt); @@ -27,26 +26,30 @@ gkyl_mom_calc_new(const struct gkyl_rect_grid *grid, return up; } -static inline void -copy_idx_arrays(int cdim, int pdim, const int *cidx, const int *vidx, int *out) +static inline void copy_idx_arrays(int cdim, int pdim, const int *cidx, const int *vidx, int *out) { - for (int i=0; indim; ++d) rem_dir[d] = 1; + + int pidx[GKYL_MAX_DIM], rem_dir[GKYL_MAX_DIM] = {0}; + for (int d = 0; d < conf_rng->ndim; ++d) { + rem_dir[d] = 1; + } gkyl_array_clear_range(mout, 0.0, conf_rng); @@ -61,40 +64,41 @@ gkyl_mom_calc_advance(const struct gkyl_mom_calc* calc, gkyl_range_iter_no_split_init(&vel_iter, &vel_rng); while (gkyl_range_iter_next(&vel_iter)) { - copy_idx_arrays(conf_rng->ndim, phase_rng->ndim, conf_iter.idx, vel_iter.idx, pidx); gkyl_rect_grid_cell_center(&calc->grid, pidx, xc); - + long fidx = gkyl_range_idx(&vel_rng, vel_iter.idx); - gkyl_mom_type_calc(calc->momt, xc, calc->grid.dx, pidx, - gkyl_array_cfetch(fin, fidx), gkyl_array_fetch(mout, midx), 0 + gkyl_mom_type_calc( + calc->momt, xc, calc->grid.dx, pidx, gkyl_array_cfetch(fin, fidx), + gkyl_array_fetch(mout, midx), 0 ); } } } -void gkyl_mom_calc_release(gkyl_mom_calc* up) +void gkyl_mom_calc_release(gkyl_mom_calc *up) { gkyl_mom_type_release(up->momt); - if (GKYL_IS_CU_ALLOC(up->flags)) + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } #ifndef GKYL_HAVE_CUDA -void -gkyl_mom_calc_advance_cu(const struct gkyl_mom_calc* mcalc, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *GKYL_RESTRICT fin, struct gkyl_array *GKYL_RESTRICT mout) +void gkyl_mom_calc_advance_cu( + const struct gkyl_mom_calc *mcalc, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *GKYL_RESTRICT fin, + struct gkyl_array *GKYL_RESTRICT mout +) { assert(false); } -gkyl_mom_calc* -gkyl_mom_calc_cu_dev_new(const struct gkyl_rect_grid *grid, - const struct gkyl_mom_type *momt) +gkyl_mom_calc * +gkyl_mom_calc_cu_dev_new(const struct gkyl_rect_grid *grid, const struct gkyl_mom_type *momt) { assert(false); } diff --git a/vlasov/zero/mom_calc_bcorr.c b/vlasov/zero/mom_calc_bcorr.c index 9eadb91fb4..8f7f302e3f 100644 --- a/vlasov/zero/mom_calc_bcorr.c +++ b/vlasov/zero/mom_calc_bcorr.c @@ -10,14 +10,14 @@ #include #include -struct gkyl_mom_calc_bcorr* -gkyl_mom_calc_bcorr_new(const struct gkyl_rect_grid *grid, - const struct gkyl_mom_type *momt, bool use_gpu) +struct gkyl_mom_calc_bcorr *gkyl_mom_calc_bcorr_new( + const struct gkyl_rect_grid *grid, const struct gkyl_mom_type *momt, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_mom_calc_bcorr_cu_dev_new(grid, momt); - } + } #endif gkyl_mom_calc_bcorr *up = gkyl_malloc(sizeof(gkyl_mom_calc_bcorr)); up->grid = *grid; @@ -25,23 +25,25 @@ gkyl_mom_calc_bcorr_new(const struct gkyl_rect_grid *grid, up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; - + return up; } -static inline void -copy_idx_arrays(int cdim, int pdim, const int *cidx, const int *vidx, int *out) +static inline void copy_idx_arrays(int cdim, int pdim, const int *cidx, const int *vidx, int *out) { - for (int i=0; iflags)) { @@ -53,22 +55,25 @@ gkyl_mom_calc_bcorr_advance(const struct gkyl_mom_calc_bcorr *bcorr, double xc[GKYL_MAX_DIM]; struct gkyl_range vel_rng; struct gkyl_range_iter conf_iter, vel_iter; - - int pidx[GKYL_MAX_DIM], rem_dir[GKYL_MAX_DIM] = { 0 }; + + int pidx[GKYL_MAX_DIM], rem_dir[GKYL_MAX_DIM] = {0}; enum gkyl_vel_edge edge; int pdim = phase_rng->ndim; int cdim = conf_rng->ndim; int vdim = pdim - cdim; - - for (int d=0; dupper[cdim + d]; gkyl_range_deflate(&vel_rng, phase_rng, rem_dir, pidx); gkyl_range_iter_no_split_init(&vel_iter, &vel_rng); - + while (gkyl_range_iter_next(&vel_iter)) { - for (int i=0; igrid, pidx, xc); - + long fidx = gkyl_range_idx(&vel_rng, vel_iter.idx); - gkyl_mom_type_calc(bcorr->momt, xc, bcorr->grid.dx, pidx, - gkyl_array_cfetch(fIn, fidx), gkyl_array_fetch(out, midx), &edge + gkyl_mom_type_calc( + bcorr->momt, xc, bcorr->grid.dx, pidx, gkyl_array_cfetch(fIn, fidx), + gkyl_array_fetch(out, midx), &edge ); } - + // loop over lower edge of velocity space edge = d; pidx[cdim + d] = phase_rng->lower[cdim + d]; gkyl_range_deflate(&vel_rng, phase_rng, rem_dir, pidx); gkyl_range_iter_no_split_init(&vel_iter, &vel_rng); - + while (gkyl_range_iter_next(&vel_iter)) { - for (int i=0; igrid, pidx, xc); - + long fidx = gkyl_range_idx(&vel_rng, vel_iter.idx); - gkyl_mom_type_calc(bcorr->momt, xc, bcorr->grid.dx, pidx, - gkyl_array_cfetch(fIn, fidx), gkyl_array_fetch(out, midx), &edge + gkyl_mom_type_calc( + bcorr->momt, xc, bcorr->grid.dx, pidx, gkyl_array_cfetch(fIn, fidx), + gkyl_array_fetch(out, midx), &edge ); } rem_dir[cdim + d] = 0; @@ -128,27 +138,28 @@ gkyl_mom_calc_bcorr_advance(const struct gkyl_mom_calc_bcorr *bcorr, } } -void -gkyl_mom_calc_bcorr_release(gkyl_mom_calc_bcorr* up) +void gkyl_mom_calc_bcorr_release(gkyl_mom_calc_bcorr *up) { gkyl_mom_type_release(up->momt); - if (GKYL_IS_CU_ALLOC(up->flags)) + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } #ifndef GKYL_HAVE_CUDA -struct gkyl_mom_calc_bcorr* +struct gkyl_mom_calc_bcorr * gkyl_mom_calc_bcorr_cu_dev_new(const struct gkyl_rect_grid *grid, const struct gkyl_mom_type *momt) { assert(false); } -void -gkyl_mom_calc_bcorr_advance_cu(const struct gkyl_mom_calc_bcorr *bcorr, - const struct gkyl_range *phase_rng, const struct gkyl_range *conf_rng, - const struct gkyl_array *GKYL_RESTRICT fIn, struct gkyl_array *GKYL_RESTRICT out) +void gkyl_mom_calc_bcorr_advance_cu( + const struct gkyl_mom_calc_bcorr *bcorr, const struct gkyl_range *phase_rng, + const struct gkyl_range *conf_rng, const struct gkyl_array *GKYL_RESTRICT fIn, + struct gkyl_array *GKYL_RESTRICT out +) { assert(false); } diff --git a/vlasov/zero/mom_calc_bcorr_cu.cu b/vlasov/zero/mom_calc_bcorr_cu.cu index eb90e4831f..fb1f35409c 100644 --- a/vlasov/zero/mom_calc_bcorr_cu.cu +++ b/vlasov/zero/mom_calc_bcorr_cu.cu @@ -3,7 +3,7 @@ extern "C" { #include #include -#include +#include #include #include #include @@ -13,58 +13,61 @@ extern "C" { #include } -__global__ static void -gkyl_mom_calc_bcorr_advance_cu_ker(const struct gkyl_mom_calc_bcorr* bcorr, - const struct gkyl_range conf_rng, struct gkyl_range vel_rng, - enum gkyl_vel_edge edge, const struct gkyl_array* fin, struct gkyl_array* out) +__global__ static void gkyl_mom_calc_bcorr_advance_cu_ker( + const struct gkyl_mom_calc_bcorr *bcorr, const struct gkyl_range conf_rng, + struct gkyl_range vel_rng, enum gkyl_vel_edge edge, const struct gkyl_array *fin, + struct gkyl_array *out +) { double xc[GKYL_MAX_DIM]; int pidx[GKYL_MAX_DIM], cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < vel_rng.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < vel_rng.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&vel_rng, tid, pidx); gkyl_rect_grid_cell_center(&bcorr->grid, pidx, xc); long lincP = gkyl_range_idx(&vel_rng, pidx); - const double* fptr = (const double*) gkyl_array_cfetch(fin, lincP); + const double *fptr = (const double *)gkyl_array_cfetch(fin, lincP); double momLocal[96]; // hard-coded to max confBasis.num_basis (3x p=3 Ser) for now. - for (unsigned int k=0; k<96; ++k) + for (unsigned int k = 0; k < 96; ++k) { momLocal[k] = 0.0; + } // reduce local f to local mom bcorr->momt->kernel(bcorr->momt, xc, bcorr->grid.dx, pidx, fptr, &momLocal[0], &edge); // get conf-space linear index. - for (unsigned int k = 0; k < conf_rng.ndim; k++) + for (unsigned int k = 0; k < conf_rng.ndim; k++) { cidx[k] = pidx[k]; + } long lincC = gkyl_range_idx(&conf_rng, cidx); - double* mptr = (double*) gkyl_array_fetch(out, lincC); + double *mptr = (double *)gkyl_array_fetch(out, lincC); for (unsigned int k = 0; k < out->ncomp; ++k) { - atomicAdd(&mptr[k], momLocal[k]); + atomicAdd(&mptr[k], momLocal[k]); } } } -void -gkyl_mom_calc_bcorr_advance_cu(const struct gkyl_mom_calc_bcorr *bcorr, - const struct gkyl_range *phase_rng, const struct gkyl_range *conf_rng, - const struct gkyl_array *GKYL_RESTRICT fin, struct gkyl_array *GKYL_RESTRICT out) +void gkyl_mom_calc_bcorr_advance_cu( + const struct gkyl_mom_calc_bcorr *bcorr, const struct gkyl_range *phase_rng, + const struct gkyl_range *conf_rng, const struct gkyl_array *GKYL_RESTRICT fin, + struct gkyl_array *GKYL_RESTRICT out +) { struct gkyl_range vel_rng; int nblocks, nthreads; - int vlower_idx[GKYL_MAX_DIM], vupper_idx[GKYL_MAX_DIM] = { 0 }; - for (int dim=0; dimndim; ++dim) { + int vlower_idx[GKYL_MAX_DIM], vupper_idx[GKYL_MAX_DIM] = {0}; + for (int dim = 0; dim < phase_rng->ndim; ++dim) { vlower_idx[dim] = phase_rng->lower[dim]; vupper_idx[dim] = phase_rng->upper[dim]; } enum gkyl_vel_edge edge; - + gkyl_array_clear_range(out, 0.0, conf_rng); - - for(int d=0; dndim - conf_rng->ndim; ++d) { - + + for (int d = 0; d < phase_rng->ndim - conf_rng->ndim; ++d) { edge = gkyl_vel_edge(d + GKYL_MAX_CDIM); vlower_idx[conf_rng->ndim + d] = phase_rng->upper[conf_rng->ndim + d]; vupper_idx[conf_rng->ndim + d] = phase_rng->upper[conf_rng->ndim + d]; @@ -72,8 +75,9 @@ gkyl_mom_calc_bcorr_advance_cu(const struct gkyl_mom_calc_bcorr *bcorr, nblocks = vel_rng.nblocks; nthreads = vel_rng.nthreads; - gkyl_mom_calc_bcorr_advance_cu_ker<<>>(bcorr->on_dev, - *conf_rng, vel_rng, edge, fin->on_dev, out->on_dev); + gkyl_mom_calc_bcorr_advance_cu_ker<< > >( + bcorr->on_dev, *conf_rng, vel_rng, edge, fin->on_dev, out->on_dev + ); edge = gkyl_vel_edge(d); vlower_idx[conf_rng->ndim + d] = phase_rng->lower[conf_rng->ndim + d]; @@ -82,8 +86,9 @@ gkyl_mom_calc_bcorr_advance_cu(const struct gkyl_mom_calc_bcorr *bcorr, nblocks = vel_rng.nblocks; nthreads = vel_rng.nthreads; - gkyl_mom_calc_bcorr_advance_cu_ker<<>>(bcorr->on_dev, - *conf_rng, vel_rng, edge, fin->on_dev, out->on_dev); + gkyl_mom_calc_bcorr_advance_cu_ker<< > >( + bcorr->on_dev, *conf_rng, vel_rng, edge, fin->on_dev, out->on_dev + ); // Reset indices for loop over each velocity dimension vlower_idx[conf_rng->ndim + d] = phase_rng->lower[conf_rng->ndim + d]; @@ -91,24 +96,23 @@ gkyl_mom_calc_bcorr_advance_cu(const struct gkyl_mom_calc_bcorr *bcorr, } } -gkyl_mom_calc_bcorr* -gkyl_mom_calc_bcorr_cu_dev_new(const struct gkyl_rect_grid *grid, - const struct gkyl_mom_type *momt) +gkyl_mom_calc_bcorr * +gkyl_mom_calc_bcorr_cu_dev_new(const struct gkyl_rect_grid *grid, const struct gkyl_mom_type *momt) { - gkyl_mom_calc_bcorr *up = (gkyl_mom_calc_bcorr*) gkyl_malloc(sizeof(gkyl_mom_calc_bcorr)); + gkyl_mom_calc_bcorr *up = (gkyl_mom_calc_bcorr *)gkyl_malloc(sizeof(gkyl_mom_calc_bcorr)); up->grid = *grid; - + struct gkyl_mom_type *mt = gkyl_mom_type_acquire(momt); up->momt = mt->on_dev; up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - gkyl_mom_calc_bcorr *up_cu = (gkyl_mom_calc_bcorr*) gkyl_cu_malloc(sizeof(gkyl_mom_calc_bcorr)); + gkyl_mom_calc_bcorr *up_cu = (gkyl_mom_calc_bcorr *)gkyl_cu_malloc(sizeof(gkyl_mom_calc_bcorr)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_mom_calc_bcorr), GKYL_CU_MEMCPY_H2D); up->momt = mt; up->on_dev = up_cu; - + return up; } diff --git a/vlasov/zero/mom_calc_bcorr_vlasov.c b/vlasov/zero/mom_calc_bcorr_vlasov.c index 48dbaa5367..82aaed6533 100644 --- a/vlasov/zero/mom_calc_bcorr_vlasov.c +++ b/vlasov/zero/mom_calc_bcorr_vlasov.c @@ -12,14 +12,14 @@ #include // "derived" class constructors -struct gkyl_mom_calc_bcorr* -gkyl_mom_calc_bcorr_lbo_vlasov_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const double* vBoundary, bool use_gpu) +struct gkyl_mom_calc_bcorr *gkyl_mom_calc_bcorr_lbo_vlasov_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const double *vBoundary, bool use_gpu +) { struct gkyl_mom_type *bcorr_type; // LBO boundary corrections moment type - bcorr_type = gkyl_mom_bcorr_lbo_vlasov_new(cbasis, pbasis, vBoundary, use_gpu); - struct gkyl_mom_calc_bcorr* calc = gkyl_mom_calc_bcorr_new(grid, bcorr_type, use_gpu); + bcorr_type = gkyl_mom_bcorr_lbo_vlasov_new(cbasis, pbasis, vBoundary, use_gpu); + struct gkyl_mom_calc_bcorr *calc = gkyl_mom_calc_bcorr_new(grid, bcorr_type, use_gpu); // Since calc now has pointer to specific type, decrease reference counter of type // so that eventual gkyl_mom_calc_bcorr_release method on calculator deallocates specific type data gkyl_mom_type_release(bcorr_type); diff --git a/vlasov/zero/mom_calc_cu.cu b/vlasov/zero/mom_calc_cu.cu index 503a7e2074..14a0103712 100644 --- a/vlasov/zero/mom_calc_cu.cu +++ b/vlasov/zero/mom_calc_cu.cu @@ -10,56 +10,60 @@ extern "C" { #include } -__global__ static void -gkyl_mom_calc_advance_cu_ker(const gkyl_mom_calc* mcalc, - const struct gkyl_range phase_range, const struct gkyl_range conf_range, - const struct gkyl_array* GKYL_RESTRICT fin, struct gkyl_array* GKYL_RESTRICT mout) +__global__ static void gkyl_mom_calc_advance_cu_ker( + const gkyl_mom_calc *mcalc, const struct gkyl_range phase_range, + const struct gkyl_range conf_range, const struct gkyl_array *GKYL_RESTRICT fin, + struct gkyl_array *GKYL_RESTRICT mout +) { double xc[GKYL_MAX_DIM]; int pidx[GKYL_MAX_DIM], cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < phase_range.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < phase_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&phase_range, tid, pidx); gkyl_rect_grid_cell_center(&mcalc->grid, pidx, xc); long lincP = gkyl_range_idx(&phase_range, pidx); - const double* fptr = (const double*) gkyl_array_cfetch(fin, lincP); + const double *fptr = (const double *)gkyl_array_cfetch(fin, lincP); double momLocal[96]; // hard-coded to 3 * max confBasis.num_basis (3x p=3 Ser) for now. - for (unsigned int k=0; k<96; ++k) + for (unsigned int k = 0; k < 96; ++k) { momLocal[k] = 0.0; + } // reduce local f to local mom mcalc->momt->kernel(mcalc->momt, xc, mcalc->grid.dx, pidx, fptr, &momLocal[0], 0); // get conf-space linear index. - for (unsigned int k = 0; k < conf_range.ndim; k++) + for (unsigned int k = 0; k < conf_range.ndim; k++) { cidx[k] = pidx[k]; + } long lincC = gkyl_range_idx(&conf_range, cidx); - double* mptr = (double*) gkyl_array_fetch(mout, lincC); + double *mptr = (double *)gkyl_array_fetch(mout, lincC); for (unsigned int k = 0; k < mout->ncomp; ++k) { - atomicAdd(&mptr[k], momLocal[k]); + atomicAdd(&mptr[k], momLocal[k]); } } } -void -gkyl_mom_calc_advance_cu(const gkyl_mom_calc* mcalc, - const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, - const struct gkyl_array *GKYL_RESTRICT fin, struct gkyl_array *GKYL_RESTRICT mout) +void gkyl_mom_calc_advance_cu( + const gkyl_mom_calc *mcalc, const struct gkyl_range *phase_range, + const struct gkyl_range *conf_range, const struct gkyl_array *GKYL_RESTRICT fin, + struct gkyl_array *GKYL_RESTRICT mout +) { int nblocks = phase_range->nblocks, nthreads = phase_range->nthreads; gkyl_array_clear_range(mout, 0.0, conf_range); - gkyl_mom_calc_advance_cu_ker<<>> - (mcalc->on_dev, *phase_range, *conf_range, fin->on_dev, mout->on_dev); + gkyl_mom_calc_advance_cu_ker<< > >( + mcalc->on_dev, *phase_range, *conf_range, fin->on_dev, mout->on_dev + ); } -gkyl_mom_calc* -gkyl_mom_calc_cu_dev_new(const struct gkyl_rect_grid *grid, - const struct gkyl_mom_type *momt) +gkyl_mom_calc * +gkyl_mom_calc_cu_dev_new(const struct gkyl_rect_grid *grid, const struct gkyl_mom_type *momt) { - gkyl_mom_calc *up = (gkyl_mom_calc*) gkyl_malloc(sizeof(gkyl_mom_calc)); + gkyl_mom_calc *up = (gkyl_mom_calc *)gkyl_malloc(sizeof(gkyl_mom_calc)); up->grid = *grid; struct gkyl_mom_type *mt = gkyl_mom_type_acquire(momt); @@ -68,7 +72,7 @@ gkyl_mom_calc_cu_dev_new(const struct gkyl_rect_grid *grid, up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - gkyl_mom_calc *up_cu = (gkyl_mom_calc*) gkyl_cu_malloc(sizeof(gkyl_mom_calc)); + gkyl_mom_calc *up_cu = (gkyl_mom_calc *)gkyl_cu_malloc(sizeof(gkyl_mom_calc)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_mom_calc), GKYL_CU_MEMCPY_H2D); up->momt = mt; // host portion of struct should have host copy diff --git a/vlasov/zero/mom_canonical_pb.c b/vlasov/zero/mom_canonical_pb.c index 574c89280c..afcc6dfd0f 100644 --- a/vlasov/zero/mom_canonical_pb.c +++ b/vlasov/zero/mom_canonical_pb.c @@ -8,17 +8,18 @@ #include #include -void -gkyl_mom_can_pb_free(const struct gkyl_ref_count *ref) +void gkyl_mom_can_pb_free(const struct gkyl_ref_count *ref) { struct gkyl_mom_type *momt = container_of(ref, struct gkyl_mom_type, ref_count); - if (GKYL_IS_CU_ALLOC(momt->flags)) + if (GKYL_IS_CU_ALLOC(momt->flags)) { gkyl_cu_free(momt->on_dev); + } gkyl_free(momt); } -void -gkyl_mom_canonical_pb_set_auxfields(const struct gkyl_mom_type *momt, struct gkyl_mom_canonical_pb_auxfields auxin) +void gkyl_mom_canonical_pb_set_auxfields( + const struct gkyl_mom_type *momt, struct gkyl_mom_canonical_pb_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_mom_type_is_cu_dev(momt)) { @@ -31,19 +32,20 @@ gkyl_mom_canonical_pb_set_auxfields(const struct gkyl_mom_type *momt, struct gky mom_can_pb->auxfields.hamil = auxin.hamil; } -struct gkyl_mom_type* -gkyl_mom_canonical_pb_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* phase_range, enum gkyl_distribution_moments mom_type, bool use_gpu) +struct gkyl_mom_type *gkyl_mom_canonical_pb_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, enum gkyl_distribution_moments mom_type, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_mom_canonical_pb_cu_dev_new(cbasis, pbasis, phase_range, mom_type); - } -#endif + } +#endif struct mom_type_canonical_pb *mom_can_pb = gkyl_malloc(sizeof(struct mom_type_canonical_pb)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = pbasis->poly_order; mom_can_pb->momt.cdim = cdim; @@ -57,45 +59,43 @@ gkyl_mom_canonical_pb_new(const struct gkyl_basis* cbasis, const struct gkyl_bas const gkyl_canonical_pb_mom_kern_list *m1i_from_h_kernels; switch (pbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Verify that the poly-order is 2 for ser case - assert(poly_order == 2); - menergy_kernels = ser_menergy_kernels; - m1i_from_h_kernels = ser_m1i_from_h_kernels; - break; - - case GKYL_BASIS_MODAL_HYBRID: - // Verify that the poly-order is 1 for hybrid case - assert(poly_order == 1); - menergy_kernels = ser_menergy_kernels; - m1i_from_h_kernels = ser_m1i_from_h_kernels; - break; - - case GKYL_BASIS_MODAL_TENSOR: - menergy_kernels = tensor_menergy_kernels; - m1i_from_h_kernels = tensor_m1i_from_h_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + // Verify that the poly-order is 2 for ser case + assert(poly_order == 2); + menergy_kernels = ser_menergy_kernels; + m1i_from_h_kernels = ser_m1i_from_h_kernels; + break; + + case GKYL_BASIS_MODAL_HYBRID: + // Verify that the poly-order is 1 for hybrid case + assert(poly_order == 1); + menergy_kernels = ser_menergy_kernels; + m1i_from_h_kernels = ser_m1i_from_h_kernels; + break; + + case GKYL_BASIS_MODAL_TENSOR: + menergy_kernels = tensor_menergy_kernels; + m1i_from_h_kernels = tensor_m1i_from_h_kernels; + break; + + default: + assert(false); + break; } - if (mom_type == GKYL_F_MOMENT_ENERGY) { // Energy int( f*H ) + if (mom_type == GKYL_F_MOMENT_ENERGY) { // Energy int( f*H ) assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != menergy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_can_pb->momt.kernel = menergy_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_can_pb->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M1_FROM_H) { + } else if (mom_type == GKYL_F_MOMENT_M1_FROM_H) { assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m1i_from_h_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_can_pb->momt.kernel = m1i_from_h_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_can_pb->momt.num_mom = vdim; - } - else { + } else { // string not recognized gkyl_exit("gkyl_mom_type_canonical_pb: Unrecognized moment requested!"); } @@ -107,15 +107,16 @@ gkyl_mom_canonical_pb_new(const struct gkyl_basis* cbasis, const struct gkyl_bas mom_can_pb->momt.flags = 0; GKYL_CLEAR_CU_ALLOC(mom_can_pb->momt.flags); mom_can_pb->momt.ref_count = gkyl_ref_count_init(gkyl_mom_can_pb_free); - + mom_can_pb->momt.on_dev = &mom_can_pb->momt; // on host, self-reference - + return &mom_can_pb->momt; } -struct gkyl_mom_type* -gkyl_int_mom_canonical_pb_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* phase_range, enum gkyl_distribution_moments mom_type, bool use_gpu) +struct gkyl_mom_type *gkyl_int_mom_canonical_pb_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, enum gkyl_distribution_moments mom_type, bool use_gpu +) { // Integrates all moments [ mM0, M1i_from_H, MEnergy ] assert(cbasis->poly_order == pbasis->poly_order); @@ -123,10 +124,10 @@ gkyl_int_mom_canonical_pb_new(const struct gkyl_basis* cbasis, const struct gkyl #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_int_mom_canonical_pb_cu_dev_new(cbasis, pbasis, phase_range, mom_type); - } -#endif + } +#endif struct mom_type_canonical_pb *mom_can_pb = gkyl_malloc(sizeof(struct mom_type_canonical_pb)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_can_pb->momt.cdim = cdim; @@ -136,40 +137,40 @@ gkyl_int_mom_canonical_pb_new(const struct gkyl_basis* cbasis, const struct gkyl mom_can_pb->momt.num_phase = pbasis->num_basis; // Choose kernel tables based on basis-function type. - const gkyl_canonical_pb_mom_kern_list *int_five_moments_kernels; - + const gkyl_canonical_pb_mom_kern_list *int_five_moments_kernels; + // Set kernel pointer. switch (pbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Verify that the poly-order is 2 for ser case. - assert(poly_order == 2); - int_five_moments_kernels = ser_int_five_moments_kernels; - break; - - case GKYL_BASIS_MODAL_HYBRID: - // Verify that the poly-order is 1 for hybrid case. - assert(poly_order == 1); - int_five_moments_kernels = ser_int_five_moments_kernels; - break; - - case GKYL_BASIS_MODAL_TENSOR: - int_five_moments_kernels = tensor_int_five_moments_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + // Verify that the poly-order is 2 for ser case. + assert(poly_order == 2); + int_five_moments_kernels = ser_int_five_moments_kernels; + break; + + case GKYL_BASIS_MODAL_HYBRID: + // Verify that the poly-order is 1 for hybrid case. + assert(poly_order == 1); + int_five_moments_kernels = ser_int_five_moments_kernels; + break; + + case GKYL_BASIS_MODAL_TENSOR: + int_five_moments_kernels = tensor_int_five_moments_kernels; + break; + + default: + assert(false); + break; } assert(cv_index[cdim].vdim[vdim] != -1); if (mom_type == GKYL_F_MOMENT_M0M1M2) { assert(NULL != int_five_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - mom_can_pb->momt.kernel = int_five_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - mom_can_pb->momt.num_mom = vdim+2; - } - else { - fprintf(stderr,"Moment option %d not available.\n",mom_type); + mom_can_pb->momt.kernel = + int_five_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; + mom_can_pb->momt.num_mom = vdim + 2; + } else { + fprintf(stderr, "Moment option %d not available.\n", mom_type); assert(false); } @@ -180,8 +181,8 @@ gkyl_int_mom_canonical_pb_new(const struct gkyl_basis* cbasis, const struct gkyl mom_can_pb->momt.flags = 0; GKYL_CLEAR_CU_ALLOC(mom_can_pb->momt.flags); mom_can_pb->momt.ref_count = gkyl_ref_count_init(gkyl_mom_can_pb_free); - + mom_can_pb->momt.on_dev = &mom_can_pb->momt; // on host, self-reference - - return &mom_can_pb->momt; + + return &mom_can_pb->momt; } diff --git a/vlasov/zero/mom_canonical_pb_cu.cu b/vlasov/zero/mom_canonical_pb_cu.cu index 172b953785..0eaff1c2e5 100644 --- a/vlasov/zero/mom_canonical_pb_cu.cu +++ b/vlasov/zero/mom_canonical_pb_cu.cu @@ -14,28 +14,27 @@ extern "C" { #include -static int -v_num_mom(int vdim, enum gkyl_distribution_moments mom_type) +static int v_num_mom(int vdim, enum gkyl_distribution_moments mom_type) { int num_mom = 0; - + switch (mom_type) { - case GKYL_F_MOMENT_ENERGY: - num_mom = 1; - break; - - case GKYL_F_MOMENT_M1_FROM_H: - num_mom = vdim; - break; - - case GKYL_F_MOMENT_M0M1M2: - num_mom = 2+vdim; - break; - - default: // Can't happen. - fprintf(stderr,"Moment option %d not available.\n",mom_type); - assert(false); - break; + case GKYL_F_MOMENT_ENERGY: + num_mom = 1; + break; + + case GKYL_F_MOMENT_M1_FROM_H: + num_mom = vdim; + break; + + case GKYL_F_MOMENT_M0M1M2: + num_mom = 2 + vdim; + break; + + default: // Can't happen. + fprintf(stderr, "Moment option %d not available.\n", mom_type); + assert(false); + break; } return num_mom; @@ -44,84 +43,85 @@ v_num_mom(int vdim, enum gkyl_distribution_moments mom_type) // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_mom_canonical_pb_set_auxfields_cu_kernel(const struct gkyl_mom_type *momt, - const struct gkyl_array *hamil) +__global__ static void gkyl_mom_canonical_pb_set_auxfields_cu_kernel( + const struct gkyl_mom_type *momt, const struct gkyl_array *hamil +) { struct mom_type_canonical_pb *mom_can_pb = container_of(momt, struct mom_type_canonical_pb, momt); mom_can_pb->auxfields.hamil = hamil; } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_mom_canonical_pb_set_auxfields_cu(const struct gkyl_mom_type *momt, struct gkyl_mom_canonical_pb_auxfields auxin) +void gkyl_mom_canonical_pb_set_auxfields_cu( + const struct gkyl_mom_type *momt, struct gkyl_mom_canonical_pb_auxfields auxin +) { - gkyl_mom_canonical_pb_set_auxfields_cu_kernel<<<1,1>>>(momt, auxin.hamil->on_dev); + gkyl_mom_canonical_pb_set_auxfields_cu_kernel<<<1, 1> > >(momt, auxin.hamil->on_dev); } - -__global__ -static void -set_cu_ptrs(struct mom_type_canonical_pb* mom_can_pb, enum gkyl_distribution_moments mom_type, - enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx) +__global__ static void set_cu_ptrs( + struct mom_type_canonical_pb *mom_can_pb, enum gkyl_distribution_moments mom_type, + enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx +) { mom_can_pb->auxfields.hamil = 0; - + // choose kernel tables based on basis-function type const gkyl_canonical_pb_mom_kern_list *menergy_kernels; const gkyl_canonical_pb_mom_kern_list *m1i_from_h_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Verify that the poly-order is 2 for ser case - assert(poly_order == 2); - menergy_kernels = ser_menergy_kernels; - m1i_from_h_kernels = ser_m1i_from_h_kernels; - break; - - case GKYL_BASIS_MODAL_HYBRID: - // Verify that the poly-order is 1 for hybrid case - assert(poly_order == 1); - menergy_kernels = ser_menergy_kernels; - m1i_from_h_kernels = ser_m1i_from_h_kernels; - break; - - case GKYL_BASIS_MODAL_TENSOR: - menergy_kernels = tensor_menergy_kernels; - m1i_from_h_kernels = tensor_m1i_from_h_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + // Verify that the poly-order is 2 for ser case + assert(poly_order == 2); + menergy_kernels = ser_menergy_kernels; + m1i_from_h_kernels = ser_m1i_from_h_kernels; + break; + + case GKYL_BASIS_MODAL_HYBRID: + // Verify that the poly-order is 1 for hybrid case + assert(poly_order == 1); + menergy_kernels = ser_menergy_kernels; + m1i_from_h_kernels = ser_m1i_from_h_kernels; + break; + + case GKYL_BASIS_MODAL_TENSOR: + menergy_kernels = tensor_menergy_kernels; + m1i_from_h_kernels = tensor_m1i_from_h_kernels; + break; + + default: + assert(false); + break; } - + switch (mom_type) { - case GKYL_F_MOMENT_ENERGY: - mom_can_pb->momt.kernel = menergy_kernels[tblidx].kernels[poly_order]; - mom_can_pb->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M1_FROM_H: - mom_can_pb->momt.kernel = m1i_from_h_kernels[tblidx].kernels[poly_order]; - mom_can_pb->momt.num_mom = vdim; - break; - - default: // can't happen - break; + case GKYL_F_MOMENT_ENERGY: + mom_can_pb->momt.kernel = menergy_kernels[tblidx].kernels[poly_order]; + mom_can_pb->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M1_FROM_H: + mom_can_pb->momt.kernel = m1i_from_h_kernels[tblidx].kernels[poly_order]; + mom_can_pb->momt.num_mom = vdim; + break; + + default: // can't happen + break; } } -struct gkyl_mom_type* -gkyl_mom_canonical_pb_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* phase_range, enum gkyl_distribution_moments mom_type) +struct gkyl_mom_type *gkyl_mom_canonical_pb_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, enum gkyl_distribution_moments mom_type +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_canonical_pb *mom_can_pb = (struct mom_type_canonical_pb*) - gkyl_malloc(sizeof(struct mom_type_canonical_pb)); - - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + struct mom_type_canonical_pb *mom_can_pb = + (struct mom_type_canonical_pb *)gkyl_malloc(sizeof(struct mom_type_canonical_pb)); + + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_can_pb->momt.cdim = cdim; @@ -137,77 +137,79 @@ gkyl_mom_canonical_pb_cu_dev_new(const struct gkyl_basis* cbasis, const struct g mom_can_pb->momt.flags = 0; GKYL_SET_CU_ALLOC(mom_can_pb->momt.flags); mom_can_pb->momt.ref_count = gkyl_ref_count_init(gkyl_mom_can_pb_free); - + // copy struct to device - struct mom_type_canonical_pb *momt_cu = (struct mom_type_canonical_pb*) - gkyl_cu_malloc(sizeof(struct mom_type_canonical_pb)); + struct mom_type_canonical_pb *momt_cu = + (struct mom_type_canonical_pb *)gkyl_cu_malloc(sizeof(struct mom_type_canonical_pb)); gkyl_cu_memcpy(momt_cu, mom_can_pb, sizeof(struct mom_type_canonical_pb), GKYL_CU_MEMCPY_H2D); assert(cv_index[cdim].vdim[vdim] != -1); - set_cu_ptrs<<<1,1>>>(momt_cu, mom_type, pbasis->b_type, - vdim, poly_order, cv_index[cdim].vdim[vdim]); + set_cu_ptrs<<<1, 1> > >( + momt_cu, mom_type, pbasis->b_type, vdim, poly_order, cv_index[cdim].vdim[vdim] + ); mom_can_pb->momt.on_dev = &momt_cu->momt; - + return &mom_can_pb->momt; } -__global__ -static void -set_int_cu_ptrs(struct mom_type_canonical_pb* mom_can_pb, enum gkyl_distribution_moments mom_type, - enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx) +__global__ static void set_int_cu_ptrs( + struct mom_type_canonical_pb *mom_can_pb, enum gkyl_distribution_moments mom_type, + enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx +) { mom_can_pb->auxfields.hamil = 0; // Coose kernel tables based on basis-function type. const gkyl_canonical_pb_mom_kern_list *int_five_moments_kernels; - + // Set kernel pointer. switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - // Verify that the poly-order is 2 for ser case - assert(poly_order == 2); - int_five_moments_kernels = ser_int_five_moments_kernels; - break; - - case GKYL_BASIS_MODAL_HYBRID: - // Verify that the poly-order is 1 for hybrid case - assert(poly_order == 1); - int_five_moments_kernels = ser_int_five_moments_kernels; - break; - - case GKYL_BASIS_MODAL_TENSOR: - int_five_moments_kernels = tensor_int_five_moments_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + // Verify that the poly-order is 2 for ser case + assert(poly_order == 2); + int_five_moments_kernels = ser_int_five_moments_kernels; + break; + + case GKYL_BASIS_MODAL_HYBRID: + // Verify that the poly-order is 1 for hybrid case + assert(poly_order == 1); + int_five_moments_kernels = ser_int_five_moments_kernels; + break; + + case GKYL_BASIS_MODAL_TENSOR: + int_five_moments_kernels = tensor_int_five_moments_kernels; + break; + + default: + assert(false); + break; } switch (mom_type) { - case GKYL_F_MOMENT_M0M1M2: - mom_can_pb->momt.kernel = int_five_moments_kernels[tblidx].kernels[poly_order]; - mom_can_pb->momt.num_mom = 2+vdim; - break; - - default: - assert(false); - break; + case GKYL_F_MOMENT_M0M1M2: + mom_can_pb->momt.kernel = int_five_moments_kernels[tblidx].kernels[poly_order]; + mom_can_pb->momt.num_mom = 2 + vdim; + break; + + default: + assert(false); + break; } } -struct gkyl_mom_type * -gkyl_int_mom_canonical_pb_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* phase_range, enum gkyl_distribution_moments mom_type) +struct gkyl_mom_type *gkyl_int_mom_canonical_pb_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *phase_range, enum gkyl_distribution_moments mom_type +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_canonical_pb *mom_can_pb = (struct mom_type_canonical_pb*) - gkyl_malloc(sizeof(struct mom_type_canonical_pb)); - - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + struct mom_type_canonical_pb *mom_can_pb = + (struct mom_type_canonical_pb *)gkyl_malloc(sizeof(struct mom_type_canonical_pb)); + + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_can_pb->momt.cdim = cdim; @@ -223,17 +225,17 @@ gkyl_int_mom_canonical_pb_cu_dev_new(const struct gkyl_basis* cbasis, const stru mom_can_pb->momt.flags = 0; GKYL_SET_CU_ALLOC(mom_can_pb->momt.flags); mom_can_pb->momt.ref_count = gkyl_ref_count_init(gkyl_mom_can_pb_free); - + // copy struct to device - struct mom_type_canonical_pb *momt_cu = (struct mom_type_canonical_pb*) - gkyl_cu_malloc(sizeof(struct mom_type_canonical_pb)); + struct mom_type_canonical_pb *momt_cu = + (struct mom_type_canonical_pb *)gkyl_cu_malloc(sizeof(struct mom_type_canonical_pb)); gkyl_cu_memcpy(momt_cu, mom_can_pb, sizeof(struct mom_type_canonical_pb), GKYL_CU_MEMCPY_H2D); - set_int_cu_ptrs<<<1,1>>>(momt_cu, mom_type, pbasis->b_type, - vdim, poly_order, cv_index[cdim].vdim[vdim]); + set_int_cu_ptrs<<<1, 1> > >( + momt_cu, mom_type, pbasis->b_type, vdim, poly_order, cv_index[cdim].vdim[vdim] + ); mom_can_pb->momt.on_dev = &momt_cu->momt; - + return &mom_can_pb->momt; } - diff --git a/vlasov/zero/mom_vlasov.c b/vlasov/zero/mom_vlasov.c index 885a0029c1..fb36671016 100644 --- a/vlasov/zero/mom_vlasov.c +++ b/vlasov/zero/mom_vlasov.c @@ -8,28 +8,29 @@ #include #include -void -gkyl_mom_free(const struct gkyl_ref_count *ref) +void gkyl_mom_free(const struct gkyl_ref_count *ref) { struct gkyl_mom_type *momt = container_of(ref, struct gkyl_mom_type, ref_count); - if (GKYL_IS_CU_ALLOC(momt->flags)) + if (GKYL_IS_CU_ALLOC(momt->flags)) { gkyl_cu_free(momt->on_dev); + } gkyl_free(momt); } -struct gkyl_mom_type* -gkyl_mom_vlasov_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, enum gkyl_distribution_moments mom_type, bool use_gpu) +struct gkyl_mom_type *gkyl_mom_vlasov_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + enum gkyl_distribution_moments mom_type, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_mom_vlasov_cu_dev_new(cbasis, pbasis, mom_type); - } + } #endif struct mom_type_vlasov *mom_vm = gkyl_malloc(sizeof(struct mom_type_vlasov)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_vm->momt.cdim = cdim; @@ -40,87 +41,81 @@ gkyl_mom_vlasov_new(const struct gkyl_basis* cbasis, mom_vm->momt.kernel = kernel; // choose kernel tables based on basis-function type - const gkyl_mom_kern_list *m0_kernels, *m1i_kernels, - *m2_kernels, *m2ij_kernels, *m3i_kernels, *m3ijk_kernels, *five_moments_kernels; + const gkyl_mom_kern_list *m0_kernels, *m1i_kernels, *m2_kernels, *m2ij_kernels, *m3i_kernels, + *m3ijk_kernels, *five_moments_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - m0_kernels = ser_m0_kernels; - m1i_kernels = ser_m1i_kernels; - m2_kernels = ser_m2_kernels; - m2ij_kernels = ser_m2ij_kernels; - m3i_kernels = ser_m3i_kernels; - m3ijk_kernels = ser_m3ijk_kernels; - five_moments_kernels = ser_five_moments_kernels; - break; - - case GKYL_BASIS_MODAL_TENSOR: - m0_kernels = tensor_m0_kernels; - m1i_kernels = tensor_m1i_kernels; - m2_kernels = tensor_m2_kernels; - m2ij_kernels = tensor_m2ij_kernels; - m3i_kernels = tensor_m3i_kernels; - m3ijk_kernels = tensor_m3ijk_kernels; - five_moments_kernels = tensor_five_moments_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + m0_kernels = ser_m0_kernels; + m1i_kernels = ser_m1i_kernels; + m2_kernels = ser_m2_kernels; + m2ij_kernels = ser_m2ij_kernels; + m3i_kernels = ser_m3i_kernels; + m3ijk_kernels = ser_m3ijk_kernels; + five_moments_kernels = ser_five_moments_kernels; + break; + + case GKYL_BASIS_MODAL_TENSOR: + m0_kernels = tensor_m0_kernels; + m1i_kernels = tensor_m1i_kernels; + m2_kernels = tensor_m2_kernels; + m2ij_kernels = tensor_m2ij_kernels; + m3i_kernels = tensor_m3i_kernels; + m3ijk_kernels = tensor_m3ijk_kernels; + five_moments_kernels = tensor_five_moments_kernels; + break; + + default: + assert(false); + break; } if (mom_type == GKYL_F_MOMENT_M0) { // density assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m0_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm->kernel = m0_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_vm->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M1) { // momentum + } else if (mom_type == GKYL_F_MOMENT_M1) { // momentum assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m1i_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm->kernel = m1i_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_vm->momt.num_mom = vdim; - } - else if (mom_type == GKYL_F_MOMENT_M2) { // energy + } else if (mom_type == GKYL_F_MOMENT_M2) { // energy assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m2_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm->kernel = m2_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_vm->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M2IJ) { // pressure tensor in lab-frame + } else if (mom_type == GKYL_F_MOMENT_M2IJ) { // pressure tensor in lab-frame assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m2ij_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm->kernel = m2ij_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - mom_vm->momt.num_mom = vdim*(vdim+1)/2; - } - else if (mom_type == GKYL_F_MOMENT_M3) { // heat-flux vector in lab-frame + mom_vm->momt.num_mom = vdim * (vdim + 1) / 2; + } else if (mom_type == GKYL_F_MOMENT_M3) { // heat-flux vector in lab-frame assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m3i_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm->kernel = m3i_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_vm->momt.num_mom = vdim; - } - else if (mom_type == GKYL_F_MOMENT_M3IJK) { // heat-flux tensor in lab-frame + } else if (mom_type == GKYL_F_MOMENT_M3IJK) { // heat-flux tensor in lab-frame assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m3ijk_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm->kernel = m3ijk_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - int m3ijk_count[] = { 1, 4, 10 }; - mom_vm->momt.num_mom = m3ijk_count[vdim-1]; - } - else if (mom_type == GKYL_F_MOMENT_M0M1M2) { // Zeroth, First, and Second moment computed together + int m3ijk_count[] = {1, 4, 10}; + mom_vm->momt.num_mom = m3ijk_count[vdim - 1]; + } else if (mom_type == + GKYL_F_MOMENT_M0M1M2) { // Zeroth, First, and Second moment computed together assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != five_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm->kernel = five_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - mom_vm->momt.num_mom = 2+vdim; - } - else { + mom_vm->momt.num_mom = 2 + vdim; + } else { // string not recognized gkyl_exit("gkyl_mom_type_vlasov: Unrecognized moment requested!"); } @@ -128,25 +123,26 @@ gkyl_mom_vlasov_new(const struct gkyl_basis* cbasis, mom_vm->momt.flags = 0; GKYL_CLEAR_CU_ALLOC(mom_vm->momt.flags); mom_vm->momt.ref_count = gkyl_ref_count_init(gkyl_mom_free); - + mom_vm->momt.on_dev = &mom_vm->momt; // on host, self-reference - + return &mom_vm->momt; } -struct gkyl_mom_type * -gkyl_int_mom_vlasov_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - enum gkyl_distribution_moments mom_type, bool use_gpu) +struct gkyl_mom_type *gkyl_int_mom_vlasov_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + enum gkyl_distribution_moments mom_type, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_int_mom_vlasov_cu_dev_new(cbasis, pbasis, mom_type); - } + } #endif struct mom_type_vlasov *mom_vm = gkyl_malloc(sizeof(struct mom_type_vlasov)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_vm->momt.cdim = cdim; @@ -155,42 +151,41 @@ gkyl_int_mom_vlasov_new(const struct gkyl_basis* cbasis, const struct gkyl_basis mom_vm->momt.num_config = cbasis->num_basis; mom_vm->momt.num_phase = pbasis->num_basis; mom_vm->momt.kernel = kernel; - + // Choose kernel tables based on basis-function type. const gkyl_mom_kern_list *int_five_moments_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - int_five_moments_kernels = ser_int_five_moments_kernels; - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + int_five_moments_kernels = ser_int_five_moments_kernels; + break; - case GKYL_BASIS_MODAL_TENSOR: - int_five_moments_kernels = tensor_int_five_moments_kernels; - break; + case GKYL_BASIS_MODAL_TENSOR: + int_five_moments_kernels = tensor_int_five_moments_kernels; + break; - default: - assert(false); - break; - } + default: + assert(false); + break; + } - assert(cv_index[cdim].vdim[vdim] != -1); + assert(cv_index[cdim].vdim[vdim] != -1); if (mom_type == GKYL_F_MOMENT_M0M1M2) { // Zeroth, First, and Second moment computed together assert(NULL != int_five_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm->kernel = int_five_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - mom_vm->momt.num_mom = 2+vdim; - } - else { - fprintf(stderr,"Moment option %d not available.\n",mom_type); + mom_vm->momt.num_mom = 2 + vdim; + } else { + fprintf(stderr, "Moment option %d not available.\n", mom_type); assert(false); } mom_vm->momt.flags = 0; GKYL_CLEAR_CU_ALLOC(mom_vm->momt.flags); mom_vm->momt.ref_count = gkyl_ref_count_init(gkyl_mom_free); - + mom_vm->momt.on_dev = &mom_vm->momt; // on host, self-reference - - return &mom_vm->momt; + + return &mom_vm->momt; } diff --git a/vlasov/zero/mom_vlasov_cu.cu b/vlasov/zero/mom_vlasov_cu.cu index fafea25e78..a0ec1ab200 100644 --- a/vlasov/zero/mom_vlasov_cu.cu +++ b/vlasov/zero/mom_vlasov_cu.cu @@ -12,134 +12,134 @@ extern "C" { #include } -static int -v_num_mom(int vdim, enum gkyl_distribution_moments mom_type) +static int v_num_mom(int vdim, enum gkyl_distribution_moments mom_type) { - int m3ijk_count[] = { 1, 4, 10 }; + int m3ijk_count[] = {1, 4, 10}; int num_mom = 0; - + switch (mom_type) { - case GKYL_F_MOMENT_M0: - case GKYL_F_MOMENT_M2: - num_mom = 1; - break; - - case GKYL_F_MOMENT_M1: - case GKYL_F_MOMENT_M3: - num_mom = vdim; - break; - - case GKYL_F_MOMENT_M2IJ: - num_mom = vdim*(vdim+1)/2; - break; - - case GKYL_F_MOMENT_M3IJK: - num_mom = m3ijk_count[vdim-1]; - break; - - case GKYL_F_MOMENT_M0M1M2: - num_mom = vdim+2; - break; - - default: // Can't happen. - fprintf(stderr,"Moment option %d not available.\n",mom_type); - assert(false); - break; + case GKYL_F_MOMENT_M0: + case GKYL_F_MOMENT_M2: + num_mom = 1; + break; + + case GKYL_F_MOMENT_M1: + case GKYL_F_MOMENT_M3: + num_mom = vdim; + break; + + case GKYL_F_MOMENT_M2IJ: + num_mom = vdim * (vdim + 1) / 2; + break; + + case GKYL_F_MOMENT_M3IJK: + num_mom = m3ijk_count[vdim - 1]; + break; + + case GKYL_F_MOMENT_M0M1M2: + num_mom = vdim + 2; + break; + + default: // Can't happen. + fprintf(stderr, "Moment option %d not available.\n", mom_type); + assert(false); + break; } return num_mom; } -__global__ -static void -set_cu_ptrs(struct mom_type_vlasov* momt, enum gkyl_distribution_moments mom_type, - enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx) +__global__ static void set_cu_ptrs( + struct mom_type_vlasov *momt, enum gkyl_distribution_moments mom_type, + enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx +) { - int m3ijk_count[] = { 1, 4, 10 }; + int m3ijk_count[] = {1, 4, 10}; momt->momt.kernel = kernel; - + // choose kernel tables based on basis-function type - const gkyl_mom_kern_list *m0_kernels, *m1i_kernels, - *m2_kernels, *m2ij_kernels, *m3i_kernels, *m3ijk_kernels, *five_moments_kernels; - + const gkyl_mom_kern_list *m0_kernels, *m1i_kernels, *m2_kernels, *m2ij_kernels, *m3i_kernels, + *m3ijk_kernels, *five_moments_kernels; + switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - m0_kernels = ser_m0_kernels; - m1i_kernels = ser_m1i_kernels; - m2_kernels = ser_m2_kernels; - m2ij_kernels = ser_m2ij_kernels; - m3i_kernels = ser_m3i_kernels; - m3ijk_kernels = ser_m3ijk_kernels; - five_moments_kernels = ser_five_moments_kernels; - break; - - case GKYL_BASIS_MODAL_TENSOR: - m0_kernels = tensor_m0_kernels; - m1i_kernels = tensor_m1i_kernels; - m2_kernels = tensor_m2_kernels; - m2ij_kernels = tensor_m2ij_kernels; - m3i_kernels = tensor_m3i_kernels; - m3ijk_kernels = tensor_m3ijk_kernels; - five_moments_kernels = tensor_five_moments_kernels; - break; - - default: - assert(false); - break; - } - + case GKYL_BASIS_MODAL_SERENDIPITY: + m0_kernels = ser_m0_kernels; + m1i_kernels = ser_m1i_kernels; + m2_kernels = ser_m2_kernels; + m2ij_kernels = ser_m2ij_kernels; + m3i_kernels = ser_m3i_kernels; + m3ijk_kernels = ser_m3ijk_kernels; + five_moments_kernels = ser_five_moments_kernels; + break; + + case GKYL_BASIS_MODAL_TENSOR: + m0_kernels = tensor_m0_kernels; + m1i_kernels = tensor_m1i_kernels; + m2_kernels = tensor_m2_kernels; + m2ij_kernels = tensor_m2ij_kernels; + m3i_kernels = tensor_m3i_kernels; + m3ijk_kernels = tensor_m3ijk_kernels; + five_moments_kernels = tensor_five_moments_kernels; + break; + + default: + assert(false); + break; + } + switch (mom_type) { - case GKYL_F_MOMENT_M0: - momt->kernel = m0_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M1: - momt->kernel = m1i_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = vdim; - break; - - case GKYL_F_MOMENT_M2: - momt->kernel = m2_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M2IJ: - momt->kernel = m2ij_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = vdim*(vdim+1)/2; - break; - - case GKYL_F_MOMENT_M3: - momt->kernel = m3i_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = vdim; - break; - - case GKYL_F_MOMENT_M3IJK: - momt->kernel = m3ijk_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = m3ijk_count[vdim-1]; - break; - - case GKYL_F_MOMENT_M0M1M2: - momt->kernel = five_moments_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = vdim+2; - break; - - default: // can't happen - break; + case GKYL_F_MOMENT_M0: + momt->kernel = m0_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M1: + momt->kernel = m1i_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = vdim; + break; + + case GKYL_F_MOMENT_M2: + momt->kernel = m2_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M2IJ: + momt->kernel = m2ij_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = vdim * (vdim + 1) / 2; + break; + + case GKYL_F_MOMENT_M3: + momt->kernel = m3i_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = vdim; + break; + + case GKYL_F_MOMENT_M3IJK: + momt->kernel = m3ijk_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = m3ijk_count[vdim - 1]; + break; + + case GKYL_F_MOMENT_M0M1M2: + momt->kernel = five_moments_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = vdim + 2; + break; + + default: // can't happen + break; } } -struct gkyl_mom_type* -gkyl_mom_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, enum gkyl_distribution_moments mom_type) +struct gkyl_mom_type *gkyl_mom_vlasov_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + enum gkyl_distribution_moments mom_type +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_vlasov *momt = (struct mom_type_vlasov*) - gkyl_malloc(sizeof(struct mom_type_vlasov)); - - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + struct mom_type_vlasov *momt = + (struct mom_type_vlasov *)gkyl_malloc(sizeof(struct mom_type_vlasov)); + + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; momt->momt.cdim = cdim; @@ -153,26 +153,27 @@ gkyl_mom_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, momt->momt.flags = 0; GKYL_SET_CU_ALLOC(momt->momt.flags); momt->momt.ref_count = gkyl_ref_count_init(gkyl_mom_free); - + // copy struct to device - struct mom_type_vlasov *momt_cu = (struct mom_type_vlasov*) - gkyl_cu_malloc(sizeof(struct mom_type_vlasov)); + struct mom_type_vlasov *momt_cu = + (struct mom_type_vlasov *)gkyl_cu_malloc(sizeof(struct mom_type_vlasov)); gkyl_cu_memcpy(momt_cu, momt, sizeof(struct mom_type_vlasov), GKYL_CU_MEMCPY_H2D); assert(cv_index[cdim].vdim[vdim] != -1); - set_cu_ptrs<<<1,1>>>(momt_cu, mom_type, cbasis->b_type, - vdim, poly_order, cv_index[cdim].vdim[vdim]); + set_cu_ptrs<<<1, 1> > >( + momt_cu, mom_type, cbasis->b_type, vdim, poly_order, cv_index[cdim].vdim[vdim] + ); momt->momt.on_dev = &momt_cu->momt; - + return &momt->momt; } -__global__ -static void -set_int_cu_ptrs(struct mom_type_vlasov* momt, enum gkyl_distribution_moments mom_type, - enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx) +__global__ static void set_int_cu_ptrs( + struct mom_type_vlasov *momt, enum gkyl_distribution_moments mom_type, + enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx +) { momt->momt.kernel = kernel; @@ -181,41 +182,42 @@ set_int_cu_ptrs(struct mom_type_vlasov* momt, enum gkyl_distribution_moments mom // Set kernel pointer. switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - int_five_moments_kernels = ser_int_five_moments_kernels; - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + int_five_moments_kernels = ser_int_five_moments_kernels; + break; - case GKYL_BASIS_MODAL_TENSOR: - int_five_moments_kernels = tensor_int_five_moments_kernels; - break; + case GKYL_BASIS_MODAL_TENSOR: + int_five_moments_kernels = tensor_int_five_moments_kernels; + break; - default: - assert(false); - break; + default: + assert(false); + break; } switch (mom_type) { - case GKYL_F_MOMENT_M0M1M2: - momt->kernel = int_five_moments_kernels[tblidx].kernels[poly_order]; - momt->momt.num_mom = 2+vdim; - break; - - default: - assert(false); - break; + case GKYL_F_MOMENT_M0M1M2: + momt->kernel = int_five_moments_kernels[tblidx].kernels[poly_order]; + momt->momt.num_mom = 2 + vdim; + break; + + default: + assert(false); + break; } } -struct gkyl_mom_type * -gkyl_int_mom_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, enum gkyl_distribution_moments mom_type) +struct gkyl_mom_type *gkyl_int_mom_vlasov_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + enum gkyl_distribution_moments mom_type +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_vlasov *momt = (struct mom_type_vlasov*) - gkyl_malloc(sizeof(struct mom_type_vlasov)); - - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + struct mom_type_vlasov *momt = + (struct mom_type_vlasov *)gkyl_malloc(sizeof(struct mom_type_vlasov)); + + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; momt->momt.cdim = cdim; @@ -229,16 +231,17 @@ gkyl_int_mom_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, momt->momt.flags = 0; GKYL_SET_CU_ALLOC(momt->momt.flags); momt->momt.ref_count = gkyl_ref_count_init(gkyl_mom_free); - + // copy struct to device - struct mom_type_vlasov *momt_cu = (struct mom_type_vlasov*) - gkyl_cu_malloc(sizeof(struct mom_type_vlasov)); + struct mom_type_vlasov *momt_cu = + (struct mom_type_vlasov *)gkyl_cu_malloc(sizeof(struct mom_type_vlasov)); gkyl_cu_memcpy(momt_cu, momt, sizeof(struct mom_type_vlasov), GKYL_CU_MEMCPY_H2D); - set_int_cu_ptrs<<<1,1>>>(momt_cu, mom_type, cbasis->b_type, - vdim, poly_order, cv_index[cdim].vdim[vdim]); + set_int_cu_ptrs<<<1, 1> > >( + momt_cu, mom_type, cbasis->b_type, vdim, poly_order, cv_index[cdim].vdim[vdim] + ); momt->momt.on_dev = &momt_cu->momt; - + return &momt->momt; } diff --git a/vlasov/zero/mom_vlasov_sr.c b/vlasov/zero/mom_vlasov_sr.c index 1a805969f9..7c61a73998 100644 --- a/vlasov/zero/mom_vlasov_sr.c +++ b/vlasov/zero/mom_vlasov_sr.c @@ -8,17 +8,18 @@ #include #include -void -gkyl_mom_vm_sr_free(const struct gkyl_ref_count *ref) +void gkyl_mom_vm_sr_free(const struct gkyl_ref_count *ref) { struct gkyl_mom_type *momt = container_of(ref, struct gkyl_mom_type, ref_count); - if (GKYL_IS_CU_ALLOC(momt->flags)) + if (GKYL_IS_CU_ALLOC(momt->flags)) { gkyl_cu_free(momt->on_dev); + } gkyl_free(momt); } -void -gkyl_mom_vlasov_sr_set_auxfields(const struct gkyl_mom_type *momt, struct gkyl_mom_vlasov_sr_auxfields auxin) +void gkyl_mom_vlasov_sr_set_auxfields( + const struct gkyl_mom_type *momt, struct gkyl_mom_vlasov_sr_auxfields auxin +) { #ifdef GKYL_HAVE_CUDA if (gkyl_mom_type_is_cu_dev(momt)) { @@ -31,20 +32,21 @@ gkyl_mom_vlasov_sr_set_auxfields(const struct gkyl_mom_type *momt, struct gkyl_m mom_vm_sr->auxfields.gamma = auxin.gamma; } -struct gkyl_mom_type* -gkyl_mom_vlasov_sr_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* vel_range, - enum gkyl_distribution_moments mom_type, bool use_gpu) +struct gkyl_mom_type *gkyl_mom_vlasov_sr_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_distribution_moments mom_type, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_mom_vlasov_sr_cu_dev_new(cbasis, pbasis, conf_range, vel_range, mom_type); - } -#endif + } +#endif struct mom_type_vlasov_sr *mom_vm_sr = gkyl_malloc(sizeof(struct mom_type_vlasov_sr)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_vm_sr->momt.cdim = cdim; @@ -54,68 +56,62 @@ gkyl_mom_vlasov_sr_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* mom_vm_sr->momt.num_phase = pbasis->num_basis; // choose kernel tables based on basis-function type - const gkyl_vlasov_sr_mom_kern_list *m0_kernels, *m1i_kernels, - *m2_kernels, *m3i_kernels, *Ni_kernels, *Tij_kernels; + const gkyl_vlasov_sr_mom_kern_list *m0_kernels, *m1i_kernels, *m2_kernels, *m3i_kernels, + *Ni_kernels, *Tij_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - m0_kernels = ser_m0_kernels; - m1i_kernels = ser_m1i_kernels; - m2_kernels = ser_m2_kernels; - m3i_kernels = ser_m3i_kernels; - Ni_kernels = ser_Ni_kernels; - Tij_kernels = ser_Tij_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + m0_kernels = ser_m0_kernels; + m1i_kernels = ser_m1i_kernels; + m2_kernels = ser_m2_kernels; + m3i_kernels = ser_m3i_kernels; + Ni_kernels = ser_Ni_kernels; + Tij_kernels = ser_Tij_kernels; + break; + + default: + assert(false); + break; } if (mom_type == GKYL_F_MOMENT_M0) { // density (GammaV*n) assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m0_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm_sr->momt.kernel = m0_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_vm_sr->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M1) { // mass flux (GammaV*n*V_drift) + } else if (mom_type == GKYL_F_MOMENT_M1) { // mass flux (GammaV*n*V_drift) assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m1i_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm_sr->momt.kernel = m1i_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_vm_sr->momt.num_mom = vdim; - } - else if (mom_type == GKYL_F_MOMENT_M2) { // total energy = integral(gamma*f) velocity moment + } else if (mom_type == GKYL_F_MOMENT_M2) { // total energy = integral(gamma*f) velocity moment assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m2_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm_sr->momt.kernel = m2_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_vm_sr->momt.num_mom = 1; - } - else if (mom_type == GKYL_F_MOMENT_M3) { // energy flux = integral(p*f) velocity moment + } else if (mom_type == GKYL_F_MOMENT_M3) { // energy flux = integral(p*f) velocity moment assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != m3i_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm_sr->momt.kernel = m3i_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; mom_vm_sr->momt.num_mom = vdim; - } - else if (mom_type == GKYL_F_MOMENT_NI) { // 4-momentum (M0, M1i) + } else if (mom_type == GKYL_F_MOMENT_NI) { // 4-momentum (M0, M1i) assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != Ni_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm_sr->momt.kernel = Ni_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - mom_vm_sr->momt.num_mom = 1+vdim; - } - else if (mom_type == GKYL_F_MOMENT_TIJ) { // Stress-energy tensor (M2, M3i (vdim components), - // Stress tensor (vdim*(vdim+1))/2 components)) + mom_vm_sr->momt.num_mom = 1 + vdim; + } else if (mom_type == GKYL_F_MOMENT_TIJ) { // Stress-energy tensor (M2, M3i (vdim components), + // Stress tensor (vdim*(vdim+1))/2 components)) assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != Tij_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + mom_vm_sr->momt.kernel = Tij_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - mom_vm_sr->momt.num_mom = 1+vdim+(vdim*(vdim+1))/2; - } - else { + mom_vm_sr->momt.num_mom = 1 + vdim + (vdim * (vdim + 1)) / 2; + } else { // string not recognized gkyl_exit("gkyl_mom_type_vlasov_sr: Unrecognized moment requested!"); } @@ -128,25 +124,27 @@ gkyl_mom_vlasov_sr_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* mom_vm_sr->momt.flags = 0; GKYL_CLEAR_CU_ALLOC(mom_vm_sr->momt.flags); mom_vm_sr->momt.ref_count = gkyl_ref_count_init(gkyl_mom_vm_sr_free); - + mom_vm_sr->momt.on_dev = &mom_vm_sr->momt; // on host, self-reference - + return &mom_vm_sr->momt; } -struct gkyl_mom_type* -gkyl_int_mom_vlasov_sr_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* vel_range, enum gkyl_distribution_moments mom_type, bool use_gpu) +struct gkyl_mom_type *gkyl_int_mom_vlasov_sr_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_distribution_moments mom_type, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_int_mom_vlasov_sr_cu_dev_new(cbasis, pbasis, conf_range, vel_range, mom_type); - } -#endif + } +#endif struct mom_type_vlasov_sr *mom_vm_sr = gkyl_malloc(sizeof(struct mom_type_vlasov_sr)); - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_vm_sr->momt.cdim = cdim; @@ -156,28 +154,28 @@ gkyl_int_mom_vlasov_sr_new(const struct gkyl_basis* cbasis, const struct gkyl_ba mom_vm_sr->momt.num_phase = pbasis->num_basis; // Choose kernel tables based on basis-function type - const gkyl_vlasov_sr_mom_kern_list *int_five_moments_kernels; - + const gkyl_vlasov_sr_mom_kern_list *int_five_moments_kernels; + // Set kernel pointer. switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - int_five_moments_kernels = ser_int_five_moments_kernels; - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + int_five_moments_kernels = ser_int_five_moments_kernels; + break; - default: - assert(false); - break; + default: + assert(false); + break; } assert(cv_index[cdim].vdim[vdim] != -1); if (mom_type == GKYL_F_MOMENT_M0ENERGYM3) { assert(NULL != int_five_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - mom_vm_sr->momt.kernel = int_five_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; - mom_vm_sr->momt.num_mom = 2+vdim; - } - else { - fprintf(stderr,"Moment option %d not available.\n",mom_type); + mom_vm_sr->momt.kernel = + int_five_moments_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; + mom_vm_sr->momt.num_mom = 2 + vdim; + } else { + fprintf(stderr, "Moment option %d not available.\n", mom_type); assert(false); } @@ -189,8 +187,8 @@ gkyl_int_mom_vlasov_sr_new(const struct gkyl_basis* cbasis, const struct gkyl_ba mom_vm_sr->momt.flags = 0; GKYL_CLEAR_CU_ALLOC(mom_vm_sr->momt.flags); mom_vm_sr->momt.ref_count = gkyl_ref_count_init(gkyl_mom_vm_sr_free); - + mom_vm_sr->momt.on_dev = &mom_vm_sr->momt; // on host, self-reference - - return &mom_vm_sr->momt; + + return &mom_vm_sr->momt; } diff --git a/vlasov/zero/mom_vlasov_sr_cu.cu b/vlasov/zero/mom_vlasov_sr_cu.cu index ab9093ca3d..08d44c19eb 100644 --- a/vlasov/zero/mom_vlasov_sr_cu.cu +++ b/vlasov/zero/mom_vlasov_sr_cu.cu @@ -12,38 +12,37 @@ extern "C" { #include } -static int -v_num_mom(int vdim, enum gkyl_distribution_moments mom_type) +static int v_num_mom(int vdim, enum gkyl_distribution_moments mom_type) { int num_mom = 0; - + switch (mom_type) { - case GKYL_F_MOMENT_M0: - case GKYL_F_MOMENT_M2: - num_mom = 1; - break; - - case GKYL_F_MOMENT_M1: - case GKYL_F_MOMENT_M3: - num_mom = vdim; - break; - - case GKYL_F_MOMENT_NI: - num_mom = vdim+1; - break; - - case GKYL_F_MOMENT_TIJ: - num_mom = 1+vdim+(vdim*(vdim+1))/2; - break; - - case GKYL_F_MOMENT_M0ENERGYM3: - num_mom = vdim+2; - break; - - default: // Can't happen. - fprintf(stderr,"Moment option %d not available.\n",mom_type); - assert(false); - break; + case GKYL_F_MOMENT_M0: + case GKYL_F_MOMENT_M2: + num_mom = 1; + break; + + case GKYL_F_MOMENT_M1: + case GKYL_F_MOMENT_M3: + num_mom = vdim; + break; + + case GKYL_F_MOMENT_NI: + num_mom = vdim + 1; + break; + + case GKYL_F_MOMENT_TIJ: + num_mom = 1 + vdim + (vdim * (vdim + 1)) / 2; + break; + + case GKYL_F_MOMENT_M0ENERGYM3: + num_mom = vdim + 2; + break; + + default: // Can't happen. + fprintf(stderr, "Moment option %d not available.\n", mom_type); + assert(false); + break; } return num_mom; @@ -52,96 +51,97 @@ v_num_mom(int vdim, enum gkyl_distribution_moments mom_type) // CUDA kernel to set pointer to auxiliary fields. // This is required because eqn object lives on device, // and so its members cannot be modified without a full __global__ kernel on device. -__global__ static void -gkyl_mom_vlasov_sr_set_auxfields_cu_kernel(const struct gkyl_mom_type *momt, - const struct gkyl_array *gamma) +__global__ static void gkyl_mom_vlasov_sr_set_auxfields_cu_kernel( + const struct gkyl_mom_type *momt, const struct gkyl_array *gamma +) { struct mom_type_vlasov_sr *mom_vm_sr = container_of(momt, struct mom_type_vlasov_sr, momt); mom_vm_sr->auxfields.gamma = gamma; } // Host-side wrapper for set_auxfields_cu_kernel -void -gkyl_mom_vlasov_sr_set_auxfields_cu(const struct gkyl_mom_type *momt, struct gkyl_mom_vlasov_sr_auxfields auxin) +void gkyl_mom_vlasov_sr_set_auxfields_cu( + const struct gkyl_mom_type *momt, struct gkyl_mom_vlasov_sr_auxfields auxin +) { - gkyl_mom_vlasov_sr_set_auxfields_cu_kernel<<<1,1>>>(momt, auxin.gamma->on_dev); + gkyl_mom_vlasov_sr_set_auxfields_cu_kernel<<<1, 1> > >(momt, auxin.gamma->on_dev); } - -__global__ -static void -set_cu_ptrs(struct mom_type_vlasov_sr* mom_vm_sr, enum gkyl_distribution_moments mom_type, - enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx) +__global__ static void set_cu_ptrs( + struct mom_type_vlasov_sr *mom_vm_sr, enum gkyl_distribution_moments mom_type, + enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx +) { mom_vm_sr->auxfields.gamma = 0; - + // choose kernel tables based on basis-function type - const gkyl_vlasov_sr_mom_kern_list *m0_kernels, *m1i_kernels, - *m2_kernels, *m3i_kernels, *Ni_kernels, *Tij_kernels; + const gkyl_vlasov_sr_mom_kern_list *m0_kernels, *m1i_kernels, *m2_kernels, *m3i_kernels, + *Ni_kernels, *Tij_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - m0_kernels = ser_m0_kernels; - m1i_kernels = ser_m1i_kernels; - m2_kernels = ser_m2_kernels; - m3i_kernels = ser_m3i_kernels; - Ni_kernels = ser_Ni_kernels; - Tij_kernels = ser_Tij_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + m0_kernels = ser_m0_kernels; + m1i_kernels = ser_m1i_kernels; + m2_kernels = ser_m2_kernels; + m3i_kernels = ser_m3i_kernels; + Ni_kernels = ser_Ni_kernels; + Tij_kernels = ser_Tij_kernels; + break; + + default: + assert(false); + break; } - + switch (mom_type) { - case GKYL_F_MOMENT_M0: - mom_vm_sr->momt.kernel = m0_kernels[tblidx].kernels[poly_order]; - mom_vm_sr->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M1: - mom_vm_sr->momt.kernel = m1i_kernels[tblidx].kernels[poly_order]; - mom_vm_sr->momt.num_mom = vdim; - break; - - case GKYL_F_MOMENT_M2: - mom_vm_sr->momt.kernel = m2_kernels[tblidx].kernels[poly_order]; - mom_vm_sr->momt.num_mom = 1; - break; - - case GKYL_F_MOMENT_M3: - mom_vm_sr->momt.kernel = m3i_kernels[tblidx].kernels[poly_order]; - mom_vm_sr->momt.num_mom = vdim; - break; - - case GKYL_F_MOMENT_NI: - mom_vm_sr->momt.kernel = Ni_kernels[tblidx].kernels[poly_order]; - mom_vm_sr->momt.num_mom = 1+vdim; - break; - - case GKYL_F_MOMENT_TIJ: - mom_vm_sr->momt.kernel = Tij_kernels[tblidx].kernels[poly_order]; - mom_vm_sr->momt.num_mom = 1+vdim+(vdim*(vdim+1))/2; - break; - - default: // can't happen - assert(false); - break; + case GKYL_F_MOMENT_M0: + mom_vm_sr->momt.kernel = m0_kernels[tblidx].kernels[poly_order]; + mom_vm_sr->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M1: + mom_vm_sr->momt.kernel = m1i_kernels[tblidx].kernels[poly_order]; + mom_vm_sr->momt.num_mom = vdim; + break; + + case GKYL_F_MOMENT_M2: + mom_vm_sr->momt.kernel = m2_kernels[tblidx].kernels[poly_order]; + mom_vm_sr->momt.num_mom = 1; + break; + + case GKYL_F_MOMENT_M3: + mom_vm_sr->momt.kernel = m3i_kernels[tblidx].kernels[poly_order]; + mom_vm_sr->momt.num_mom = vdim; + break; + + case GKYL_F_MOMENT_NI: + mom_vm_sr->momt.kernel = Ni_kernels[tblidx].kernels[poly_order]; + mom_vm_sr->momt.num_mom = 1 + vdim; + break; + + case GKYL_F_MOMENT_TIJ: + mom_vm_sr->momt.kernel = Tij_kernels[tblidx].kernels[poly_order]; + mom_vm_sr->momt.num_mom = 1 + vdim + (vdim * (vdim + 1)) / 2; + break; + + default: // can't happen + assert(false); + break; } } -struct gkyl_mom_type* -gkyl_mom_vlasov_sr_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* vel_range, - enum gkyl_distribution_moments mom_type) +struct gkyl_mom_type *gkyl_mom_vlasov_sr_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_distribution_moments mom_type +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_vlasov_sr *mom_vm_sr = (struct mom_type_vlasov_sr*) - gkyl_malloc(sizeof(struct mom_type_vlasov_sr)); - - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + struct mom_type_vlasov_sr *mom_vm_sr = + (struct mom_type_vlasov_sr *)gkyl_malloc(sizeof(struct mom_type_vlasov_sr)); + + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_vm_sr->momt.cdim = cdim; @@ -158,65 +158,68 @@ gkyl_mom_vlasov_sr_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl mom_vm_sr->momt.flags = 0; GKYL_SET_CU_ALLOC(mom_vm_sr->momt.flags); mom_vm_sr->momt.ref_count = gkyl_ref_count_init(gkyl_mom_vm_sr_free); - + // copy struct to device - struct mom_type_vlasov_sr *momt_cu = (struct mom_type_vlasov_sr*) - gkyl_cu_malloc(sizeof(struct mom_type_vlasov_sr)); + struct mom_type_vlasov_sr *momt_cu = + (struct mom_type_vlasov_sr *)gkyl_cu_malloc(sizeof(struct mom_type_vlasov_sr)); gkyl_cu_memcpy(momt_cu, mom_vm_sr, sizeof(struct mom_type_vlasov_sr), GKYL_CU_MEMCPY_H2D); assert(cv_index[cdim].vdim[vdim] != -1); - set_cu_ptrs<<<1,1>>>(momt_cu, mom_type, cbasis->b_type, - vdim, poly_order, cv_index[cdim].vdim[vdim]); + set_cu_ptrs<<<1, 1> > >( + momt_cu, mom_type, cbasis->b_type, vdim, poly_order, cv_index[cdim].vdim[vdim] + ); mom_vm_sr->momt.on_dev = &momt_cu->momt; - + return &mom_vm_sr->momt; } -__global__ -static void -set_int_cu_ptrs(struct mom_type_vlasov_sr* mom_vm_sr, enum gkyl_distribution_moments mom_type, - enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx) +__global__ static void set_int_cu_ptrs( + struct mom_type_vlasov_sr *mom_vm_sr, enum gkyl_distribution_moments mom_type, + enum gkyl_basis_type b_type, int vdim, int poly_order, int tblidx +) { mom_vm_sr->auxfields.gamma = 0; // choose kernel tables based on basis-function type - const gkyl_vlasov_sr_mom_kern_list *int_five_moments_kernels; - + const gkyl_vlasov_sr_mom_kern_list *int_five_moments_kernels; + // set kernel pointer switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - int_five_moments_kernels = ser_int_five_moments_kernels; - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + int_five_moments_kernels = ser_int_five_moments_kernels; + break; - default: - assert(false); - break; + default: + assert(false); + break; } switch (mom_type) { - case GKYL_F_MOMENT_M0ENERGYM3: - mom_vm_sr->momt.kernel = int_five_moments_kernels[tblidx].kernels[poly_order]; - mom_vm_sr->momt.num_mom = 2+vdim; - break; - - default: - assert(false); - break; + case GKYL_F_MOMENT_M0ENERGYM3: + mom_vm_sr->momt.kernel = int_five_moments_kernels[tblidx].kernels[poly_order]; + mom_vm_sr->momt.num_mom = 2 + vdim; + break; + + default: + assert(false); + break; } } -struct gkyl_mom_type * -gkyl_int_mom_vlasov_sr_cu_dev_new(const struct gkyl_basis* cbasis, const struct gkyl_basis* pbasis, - const struct gkyl_range* conf_range, const struct gkyl_range* vel_range, enum gkyl_distribution_moments mom_type) +struct gkyl_mom_type *gkyl_int_mom_vlasov_sr_cu_dev_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, + const struct gkyl_range *conf_range, const struct gkyl_range *vel_range, + enum gkyl_distribution_moments mom_type +) { assert(cbasis->poly_order == pbasis->poly_order); - struct mom_type_vlasov_sr *mom_vm_sr = (struct mom_type_vlasov_sr*) - gkyl_malloc(sizeof(struct mom_type_vlasov_sr)); - - int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim-cdim; + struct mom_type_vlasov_sr *mom_vm_sr = + (struct mom_type_vlasov_sr *)gkyl_malloc(sizeof(struct mom_type_vlasov_sr)); + + int cdim = cbasis->ndim, pdim = pbasis->ndim, vdim = pdim - cdim; int poly_order = cbasis->poly_order; mom_vm_sr->momt.cdim = cdim; @@ -233,16 +236,17 @@ gkyl_int_mom_vlasov_sr_cu_dev_new(const struct gkyl_basis* cbasis, const struct mom_vm_sr->momt.flags = 0; GKYL_SET_CU_ALLOC(mom_vm_sr->momt.flags); mom_vm_sr->momt.ref_count = gkyl_ref_count_init(gkyl_mom_vm_sr_free); - + // copy struct to device - struct mom_type_vlasov_sr *momt_cu = (struct mom_type_vlasov_sr*) - gkyl_cu_malloc(sizeof(struct mom_type_vlasov_sr)); + struct mom_type_vlasov_sr *momt_cu = + (struct mom_type_vlasov_sr *)gkyl_cu_malloc(sizeof(struct mom_type_vlasov_sr)); gkyl_cu_memcpy(momt_cu, mom_vm_sr, sizeof(struct mom_type_vlasov_sr), GKYL_CU_MEMCPY_H2D); - set_int_cu_ptrs<<<1,1>>>(momt_cu, mom_type, cbasis->b_type, - vdim, poly_order, cv_index[cdim].vdim[vdim]); + set_int_cu_ptrs<<<1, 1> > >( + momt_cu, mom_type, cbasis->b_type, vdim, poly_order, cv_index[cdim].vdim[vdim] + ); mom_vm_sr->momt.on_dev = &momt_cu->momt; - + return &mom_vm_sr->momt; } diff --git a/vlasov/zero/positivity_shift_vlasov.c b/vlasov/zero/positivity_shift_vlasov.c index 38b2a831e4..6b51596bb2 100644 --- a/vlasov/zero/positivity_shift_vlasov.c +++ b/vlasov/zero/positivity_shift_vlasov.c @@ -4,34 +4,35 @@ #include #include -struct gkyl_positivity_shift_vlasov* -gkyl_positivity_shift_vlasov_new(struct gkyl_basis cbasis, struct gkyl_basis pbasis, - struct gkyl_rect_grid grid, const struct gkyl_range *conf_rng_ext, bool use_gpu) +struct gkyl_positivity_shift_vlasov *gkyl_positivity_shift_vlasov_new( + struct gkyl_basis cbasis, struct gkyl_basis pbasis, struct gkyl_rect_grid grid, + const struct gkyl_range *conf_rng_ext, bool use_gpu +) { // Allocate space for new updater. struct gkyl_positivity_shift_vlasov *up = gkyl_malloc(sizeof(*up)); assert(pbasis.poly_order == 1); // Because of the way a rescale/division is - // done in advance. + // done in advance. up->ffloor_fac = 0.0; // ffloor will be set to max(f)*ffloor_fac. up->grid = grid; up->num_cbasis = cbasis.num_basis; up->use_gpu = use_gpu; - up->cellav_fac = 1./pow(sqrt(2.),pbasis.ndim); + up->cellav_fac = 1. / pow(sqrt(2.), pbasis.ndim); if (!use_gpu) { up->kernels = gkyl_malloc(sizeof(struct gkyl_positivity_shift_vlasov_kernels)); up->ffloor = gkyl_malloc(sizeof(double[1])); - up->ffloor[0] = 0.0; // Gets updated after 1st call to _advance. + up->ffloor[0] = 0.0; // Gets updated after 1st call to _advance. } #ifdef GKYL_HAVE_CUDA if (use_gpu) { up->kernels = gkyl_cu_malloc(sizeof(struct gkyl_positivity_shift_vlasov_kernels)); up->ffloor = gkyl_cu_malloc(sizeof(double[1])); - double ffloor_zero[] = {0.}; // Gets updated after 1st call to _advance. + double ffloor_zero[] = {0.}; // Gets updated after 1st call to _advance. gkyl_cu_memcpy(up->ffloor, ffloor_zero, sizeof(double[1]), GKYL_CU_MEMCPY_H2D); up->shiftedf = gkyl_array_cu_dev_new(GKYL_INT, 1, conf_rng_ext->volume); @@ -39,23 +40,22 @@ gkyl_positivity_shift_vlasov_new(struct gkyl_basis cbasis, struct gkyl_basis pba #endif // Choose kernels that shift f and compute int moms of Deltaf. - + enum gkyl_positivity_shift_type shift_type = GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY; pos_shift_vlasov_choose_shift_kernel(up->kernels, cbasis, pbasis, shift_type, use_gpu); return up; } -void -gkyl_positivity_shift_vlasov_advance(gkyl_positivity_shift_vlasov* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - struct gkyl_array *GKYL_RESTRICT distf, struct gkyl_array *GKYL_RESTRICT m0, - struct gkyl_array *GKYL_RESTRICT delta_m0) +void gkyl_positivity_shift_vlasov_advance( + gkyl_positivity_shift_vlasov *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, struct gkyl_array *GKYL_RESTRICT distf, + struct gkyl_array *GKYL_RESTRICT m0, struct gkyl_array *GKYL_RESTRICT delta_m0 +) { #ifdef GKYL_HAVE_CUDA if (up->use_gpu) { - gkyl_positivity_shift_vlasov_advance_cu(up, conf_rng, phase_rng, - distf, m0, delta_m0); + gkyl_positivity_shift_vlasov_advance_cu(up, conf_rng, phase_rng, distf, m0, delta_m0); return; } #endif @@ -68,7 +68,9 @@ gkyl_positivity_shift_vlasov_advance(gkyl_positivity_shift_vlasov* up, struct gkyl_range_iter conf_iter, vel_iter; int rem_dir[GKYL_MAX_DIM] = {0}; - for (int d=0; dndim; ++d) rem_dir[d] = 1; + for (int d = 0; d < conf_rng->ndim; ++d) { + rem_dir[d] = 1; + } gkyl_range_iter_init(&conf_iter, conf_rng); while (gkyl_range_iter_next(&conf_iter)) { @@ -77,7 +79,7 @@ gkyl_positivity_shift_vlasov_advance(gkyl_positivity_shift_vlasov* up, double *m0_c = gkyl_array_fetch(m0, clinidx); double *delta_m0_c = gkyl_array_fetch(delta_m0, clinidx); double m0in_c[num_cbasis]; - for (int k=0; kkernels->m0(xc, up->grid.dx, vel_iter.idx, distf_c, m0phase_in_c); // Add to the old number density. - for (int k=0; kkernels->shift(up->ffloor[0], distf_c); @@ -111,8 +115,9 @@ gkyl_positivity_shift_vlasov_advance(gkyl_positivity_shift_vlasov* up, if (shifted_node) { // Compute the new number density in this phase-space cell. double m0phase_out_c[num_cbasis]; - for (int k=0; kkernels->m0(xc, up->grid.dx, vel_iter.idx, distf_c, m0phase_out_c); if (up->kernels->is_m0_positive(m0phase_in_c)) { @@ -124,21 +129,22 @@ gkyl_positivity_shift_vlasov_advance(gkyl_positivity_shift_vlasov* up, up->kernels->conf_phase_mul_op(m0ratio_c, distf_c, distf_c); // Add contribution from this phase-space cell to the new number density. - for (int k=0; kkernels->conf_phase_mul_op(m0ratio_c, distf_c, distf_c); } - for (int k=0; kffloor[0] = up->ffloor_fac * distf_max * up->cellav_fac; } -void -gkyl_positivity_shift_vlasov_release(gkyl_positivity_shift_vlasov* up) +void gkyl_positivity_shift_vlasov_release(gkyl_positivity_shift_vlasov *up) { // Release memory associated with this updater. if (!up->use_gpu) { diff --git a/vlasov/zero/positivity_shift_vlasov_cu.cu b/vlasov/zero/positivity_shift_vlasov_cu.cu index 5c172d2a03..c63a36e9a6 100644 --- a/vlasov/zero/positivity_shift_vlasov_cu.cu +++ b/vlasov/zero/positivity_shift_vlasov_cu.cu @@ -8,79 +8,84 @@ extern "C" { } // CUDA kernel to set device pointers to kernels. -__global__ static void -gkyl_pos_shift_vlasov_set_cu_ker_ptrs(struct gkyl_positivity_shift_vlasov_kernels *kernels, - struct gkyl_basis cbasis, struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype) +__global__ static void gkyl_pos_shift_vlasov_set_cu_ker_ptrs( + struct gkyl_positivity_shift_vlasov_kernels *kernels, struct gkyl_basis cbasis, + struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype +) { int cdim = cbasis.ndim, pdim = pbasis.ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; enum gkyl_basis_type cbasis_type = cbasis.b_type, pbasis_type = pbasis.b_type; int poly_order = pbasis.poly_order; int plin = pos_shift_vlasov_cv_index[cdim].vdim[vdim]; switch (pbasis_type) { - case GKYL_BASIS_MODAL_TENSOR: - kernels->is_m0_positive = pos_shift_vlasov_kern_list_m0_pos_check_tensor[cdim-1].kernels[poly_order-1]; - kernels->shift = stype == GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY? - pos_shift_vlasov_kern_list_shift_tensor[plin].kernels[poly_order-1] : - pos_shift_vlasov_kern_list_MRSlimiter_tensor[plin].kernels[poly_order-1]; - kernels->m0 = pos_shift_vlasov_kern_list_m0_tensor[plin].kernels[poly_order-1]; - kernels->conf_phase_mul_op = choose_mul_conf_phase_kern(pbasis_type, cdim, vdim, poly_order); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_TENSOR: + kernels->is_m0_positive = + pos_shift_vlasov_kern_list_m0_pos_check_tensor[cdim - 1].kernels[poly_order - 1]; + kernels->shift = stype == GKYL_POSITIVITY_SHIFT_TYPE_SHIFT_ONLY ? + pos_shift_vlasov_kern_list_shift_tensor[plin].kernels[poly_order - 1] : + pos_shift_vlasov_kern_list_MRSlimiter_tensor[plin].kernels[poly_order - 1]; + kernels->m0 = pos_shift_vlasov_kern_list_m0_tensor[plin].kernels[poly_order - 1]; + kernels->conf_phase_mul_op = choose_mul_conf_phase_kern(pbasis_type, cdim, vdim, poly_order); + break; + default: + assert(false); + break; } switch (cbasis_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - kernels->conf_inv_op = choose_ser_inv_kern(cdim, poly_order); - kernels->conf_mul_op = choose_ser_mul_kern(cdim, poly_order); - break; - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + kernels->conf_inv_op = choose_ser_inv_kern(cdim, poly_order); + kernels->conf_mul_op = choose_ser_mul_kern(cdim, poly_order); + break; + default: + assert(false); + break; } }; -void -pos_shift_vlasov_choose_shift_kernel_cu(struct gkyl_positivity_shift_vlasov_kernels *kernels, - struct gkyl_basis cbasis, struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype) +void pos_shift_vlasov_choose_shift_kernel_cu( + struct gkyl_positivity_shift_vlasov_kernels *kernels, struct gkyl_basis cbasis, + struct gkyl_basis pbasis, enum gkyl_positivity_shift_type stype +) { - gkyl_pos_shift_vlasov_set_cu_ker_ptrs<<<1,1>>>(kernels, cbasis, pbasis, stype); + gkyl_pos_shift_vlasov_set_cu_ker_ptrs<<<1, 1> > >(kernels, cbasis, pbasis, stype); } // Function borrowed from array_reduce_cu.cu. -__device__ static __forceinline__ double -pos_shift_atomicMax_double(double *address, double val) +__device__ static __forceinline__ double pos_shift_atomicMax_double(double *address, double val) { unsigned long long int ret = __double_as_longlong(*address); - while(val > __longlong_as_double(ret)) - { + while (val > __longlong_as_double(ret)) { unsigned long long int old = ret; - if((ret = atomicCAS((unsigned long long int*)address, old, __double_as_longlong(val))) == old) + if ((ret = atomicCAS((unsigned long long int *)address, old, __double_as_longlong(val))) == + old) { break; + } } return __longlong_as_double(ret); } __global__ void -gkyl_positivity_shift_vlasov_advance_int_array_clear_cu_ker(struct gkyl_array* out, int val) +gkyl_positivity_shift_vlasov_advance_int_array_clear_cu_ker(struct gkyl_array *out, int val) { - int *out_d = (int*) out->data; - unsigned long start_id = threadIdx.x + blockIdx.x*blockDim.x; - unsigned long nelm = out->size*out->ncomp; - for (unsigned long linc = start_id; linc < nelm; linc += blockDim.x*gridDim.x) + int *out_d = (int *)out->data; + unsigned long start_id = threadIdx.x + blockIdx.x * blockDim.x; + unsigned long nelm = out->size * out->ncomp; + for (unsigned long linc = start_id; linc < nelm; linc += blockDim.x * gridDim.x) { out_d[linc] = val; + } } -__global__ static void -gkyl_positivity_shift_vlasov_advance_shift_cu_ker( +__global__ static void gkyl_positivity_shift_vlasov_advance_shift_cu_ker( struct gkyl_positivity_shift_vlasov_kernels *kers, const struct gkyl_rect_grid grid, - const struct gkyl_range conf_range, const struct gkyl_range phase_range, - double *ffloor, double ffloor_fac, double cellav_fac, struct gkyl_array* GKYL_RESTRICT shiftedf, - struct gkyl_array* GKYL_RESTRICT distf, struct gkyl_array* GKYL_RESTRICT m0, struct gkyl_array* GKYL_RESTRICT delta_m0) + const struct gkyl_range conf_range, const struct gkyl_range phase_range, double *ffloor, + double ffloor_fac, double cellav_fac, struct gkyl_array *GKYL_RESTRICT shiftedf, + struct gkyl_array *GKYL_RESTRICT distf, struct gkyl_array *GKYL_RESTRICT m0, + struct gkyl_array *GKYL_RESTRICT delta_m0 +) { int pidx[GKYL_MAX_DIM]; double xc[GKYL_MAX_DIM]; @@ -88,8 +93,8 @@ gkyl_positivity_shift_vlasov_advance_shift_cu_ker( double distf_max = -DBL_MAX; const int num_cbasis = 20; // MF 2024/09/03: Hardcoded to p=2 3x ser for now. - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < phase_range.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < phase_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&phase_range, tid, pidx); long clinidx = gkyl_range_idx(&conf_range, pidx); @@ -97,20 +102,22 @@ gkyl_positivity_shift_vlasov_advance_shift_cu_ker( gkyl_rect_grid_cell_center(&grid, pidx, xc); - int *shiftedf_c = (int*) gkyl_array_fetch(shiftedf, clinidx); - double *m0_c = (double*) gkyl_array_fetch(m0, clinidx); - double *delta_m0_c = (double*) gkyl_array_fetch(delta_m0, clinidx); - double *distf_c = (double*) gkyl_array_fetch(distf, plinidx); + int *shiftedf_c = (int *)gkyl_array_fetch(shiftedf, clinidx); + double *m0_c = (double *)gkyl_array_fetch(m0, clinidx); + double *delta_m0_c = (double *)gkyl_array_fetch(delta_m0, clinidx); + double *distf_c = (double *)gkyl_array_fetch(distf, plinidx); // Contribution to the old number density from this v-space cell. double m0Local_in[num_cbasis]; - for (unsigned int k=0; kncomp; ++k) + for (unsigned int k = 0; k < delta_m0->ncomp; ++k) { m0Local_in[k] = 0.0; + } kers->m0(xc, grid.dx, pidx, distf_c, m0Local_in); // Add to the old number density. - for (unsigned int k = 0; k < delta_m0->ncomp; ++k) + for (unsigned int k = 0; k < delta_m0->ncomp; ++k) { atomicAdd(&delta_m0_c[k], m0Local_in[k]); + } // Shift f if needed. bool shifted_node = kers->shift(ffloor[0], distf_c); @@ -118,8 +125,9 @@ gkyl_positivity_shift_vlasov_advance_shift_cu_ker( if (shifted_node) { // Compute the new number density local to this phase-space cell. double m0Local_out[num_cbasis]; - for (unsigned int k=0; kncomp; ++k) + for (unsigned int k = 0; k < m0->ncomp; ++k) { m0Local_out[k] = 0.0; + } kers->m0(xc, grid.dx, pidx, distf_c, m0Local_out); if (kers->is_m0_positive(m0Local_in)) { @@ -131,107 +139,107 @@ gkyl_positivity_shift_vlasov_advance_shift_cu_ker( kers->conf_phase_mul_op(m0ratio_c, distf_c, distf_c); // Add contribution from this phase-space cell to the new number density. - for (unsigned int k = 0; k < m0->ncomp; ++k) + for (unsigned int k = 0; k < m0->ncomp; ++k) { atomicAdd(&m0_c[k], m0Local_in[k]); - } - else { + } + } else { // Add contribution from this phase-space cell to the new number density. - for (unsigned int k = 0; k < m0->ncomp; ++k) + for (unsigned int k = 0; k < m0->ncomp; ++k) { atomicAdd(&m0_c[k], m0Local_out[k]); + } atomicOr(shiftedf_c, shifted_node); } - } - else { + } else { // Add contribution from this phase-space cell to the new number density. - for (unsigned int k = 0; k < m0->ncomp; ++k) + for (unsigned int k = 0; k < m0->ncomp; ++k) { atomicAdd(&m0_c[k], m0Local_in[k]); + } } distf_max = fmax(distf_max, distf_c[0]); - } pos_shift_atomicMax_double(ffloor, ffloor_fac * distf_max * cellav_fac); } -__global__ static void -gkyl_positivity_shift_vlasov_advance_scalef_cu_ker( - struct gkyl_positivity_shift_vlasov_kernels *kers, - const struct gkyl_range conf_range, const struct gkyl_range phase_range, - const struct gkyl_array* GKYL_RESTRICT shiftedf, const struct gkyl_array* GKYL_RESTRICT m0, - const struct gkyl_array* GKYL_RESTRICT delta_m0, struct gkyl_array* GKYL_RESTRICT distf) +__global__ static void gkyl_positivity_shift_vlasov_advance_scalef_cu_ker( + struct gkyl_positivity_shift_vlasov_kernels *kers, const struct gkyl_range conf_range, + const struct gkyl_range phase_range, const struct gkyl_array *GKYL_RESTRICT shiftedf, + const struct gkyl_array *GKYL_RESTRICT m0, const struct gkyl_array *GKYL_RESTRICT delta_m0, + struct gkyl_array *GKYL_RESTRICT distf +) { int pidx[GKYL_MAX_DIM]; const int num_cbasis = 20; // MF 2024/09/03: Hardcoded to p=2 3x ser for now. - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < phase_range.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < phase_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&phase_range, tid, pidx); long clinidx = gkyl_range_idx(&conf_range, pidx); - const int *shiftedf_c = (const int*) gkyl_array_cfetch(shiftedf, clinidx); + const int *shiftedf_c = (const int *)gkyl_array_cfetch(shiftedf, clinidx); if (shiftedf_c[0]) { - const double *delta_m0_c = (const double*) gkyl_array_cfetch(delta_m0, clinidx); + const double *delta_m0_c = (const double *)gkyl_array_cfetch(delta_m0, clinidx); if (kers->is_m0_positive(delta_m0_c)) { // Rescale f so it has the same m0 at this conf-space cell. - const double *m0_c = (const double*) gkyl_array_cfetch(m0, clinidx); + const double *m0_c = (const double *)gkyl_array_cfetch(m0, clinidx); double m0ratio_c[num_cbasis]; kers->conf_inv_op(m0_c, m0ratio_c); kers->conf_mul_op(delta_m0_c, m0ratio_c, m0ratio_c); long plinidx = gkyl_range_idx(&phase_range, pidx); - double *distf_c = (double*) gkyl_array_fetch(distf, plinidx); + double *distf_c = (double *)gkyl_array_fetch(distf, plinidx); kers->conf_phase_mul_op(m0ratio_c, distf_c, distf_c); } } } } -__global__ static void -gkyl_positivity_shift_vlasov_advance_m0fix_cu_ker( - struct gkyl_positivity_shift_vlasov_kernels *kers, - const struct gkyl_range conf_range, const struct gkyl_array* GKYL_RESTRICT shiftedf, - struct gkyl_array* GKYL_RESTRICT m0, struct gkyl_array* GKYL_RESTRICT delta_m0) +__global__ static void gkyl_positivity_shift_vlasov_advance_m0fix_cu_ker( + struct gkyl_positivity_shift_vlasov_kernels *kers, const struct gkyl_range conf_range, + const struct gkyl_array *GKYL_RESTRICT shiftedf, struct gkyl_array *GKYL_RESTRICT m0, + struct gkyl_array *GKYL_RESTRICT delta_m0 +) { int cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_range.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_range, tid, cidx); long clinidx = gkyl_range_idx(&conf_range, cidx); - const int *shiftedf_c = (const int*) gkyl_array_cfetch(shiftedf, clinidx); - double *delta_m0_c = (double*) gkyl_array_fetch(delta_m0, clinidx); + const int *shiftedf_c = (const int *)gkyl_array_cfetch(shiftedf, clinidx); + double *delta_m0_c = (double *)gkyl_array_fetch(delta_m0, clinidx); if (shiftedf_c[0]) { - double *m0_c = (double*) gkyl_array_fetch(m0, clinidx); + double *m0_c = (double *)gkyl_array_fetch(m0, clinidx); if (kers->is_m0_positive(delta_m0_c)) { - for (int k=0; kncomp; k++) { + for (int k = 0; k < m0->ncomp; k++) { m0_c[k] = delta_m0_c[k]; delta_m0_c[k] = 0.0; - } - } - else { - for (int k=0; kncomp; k++) + } + } else { + for (int k = 0; k < m0->ncomp; k++) { delta_m0_c[k] = m0_c[k] - delta_m0_c[k]; + } } - } - else { - for (int k=0; kncomp; k++) + } else { + for (int k = 0; k < m0->ncomp; k++) { delta_m0_c[k] = 0.0; + } } } } -void -gkyl_positivity_shift_vlasov_advance_cu(gkyl_positivity_shift_vlasov* up, - const struct gkyl_range *conf_rng, const struct gkyl_range *phase_rng, - struct gkyl_array *GKYL_RESTRICT distf, struct gkyl_array *GKYL_RESTRICT m0, - struct gkyl_array *GKYL_RESTRICT delta_m0) +void gkyl_positivity_shift_vlasov_advance_cu( + gkyl_positivity_shift_vlasov *up, const struct gkyl_range *conf_rng, + const struct gkyl_range *phase_rng, struct gkyl_array *GKYL_RESTRICT distf, + struct gkyl_array *GKYL_RESTRICT m0, struct gkyl_array *GKYL_RESTRICT delta_m0 +) { int nblocks_phase = phase_rng->nblocks, nthreads_phase = phase_rng->nthreads; int nblocks_conf = conf_rng->nblocks, nthreads_conf = conf_rng->nthreads; @@ -240,19 +248,24 @@ gkyl_positivity_shift_vlasov_advance_cu(gkyl_positivity_shift_vlasov* up, gkyl_array_clear_range(delta_m0, 0.0, conf_rng); // Set shiftedf boolean (int) to 0s. - gkyl_positivity_shift_vlasov_advance_int_array_clear_cu_ker<<>> - (up->shiftedf->on_dev, 0); + gkyl_positivity_shift_vlasov_advance_int_array_clear_cu_ker<< > >( + up->shiftedf->on_dev, 0 + ); // Shift f is needed & scale f locally if initial local contribution to M0 was >0. - gkyl_positivity_shift_vlasov_advance_shift_cu_ker<<>> - (up->kernels, up->grid, *conf_rng, *phase_rng, up->ffloor, up->ffloor_fac, - up->cellav_fac, up->shiftedf->on_dev, distf->on_dev, m0->on_dev, delta_m0->on_dev); + gkyl_positivity_shift_vlasov_advance_shift_cu_ker<< > >( + up->kernels, up->grid, *conf_rng, *phase_rng, up->ffloor, up->ffloor_fac, up->cellav_fac, + up->shiftedf->on_dev, distf->on_dev, m0->on_dev, delta_m0->on_dev + ); // If a shift took place, rescale f so it keeps the same M0. - gkyl_positivity_shift_vlasov_advance_scalef_cu_ker<<>> - (up->kernels, *conf_rng, *phase_rng, up->shiftedf->on_dev, m0->on_dev, delta_m0->on_dev, distf->on_dev); + gkyl_positivity_shift_vlasov_advance_scalef_cu_ker<< > >( + up->kernels, *conf_rng, *phase_rng, up->shiftedf->on_dev, m0->on_dev, delta_m0->on_dev, + distf->on_dev + ); // Ensure m0 and delta_m0 are correct based on whether a shift took place. - gkyl_positivity_shift_vlasov_advance_m0fix_cu_ker<<>> - (up->kernels, *conf_rng, up->shiftedf->on_dev, m0->on_dev, delta_m0->on_dev); + gkyl_positivity_shift_vlasov_advance_m0fix_cu_ker<< > >( + up->kernels, *conf_rng, up->shiftedf->on_dev, m0->on_dev, delta_m0->on_dev + ); } diff --git a/vlasov/zero/prim_bgk_cross_calc.c b/vlasov/zero/prim_bgk_cross_calc.c index 0375785fad..ac15ae0994 100644 --- a/vlasov/zero/prim_bgk_cross_calc.c +++ b/vlasov/zero/prim_bgk_cross_calc.c @@ -4,12 +4,11 @@ #include #include -void -gkyl_prim_bgk_cross_calc_advance(struct gkyl_basis basis, - int vdim_phys, const struct gkyl_array* m0sdeltas, - double massself, const struct gkyl_array* primsself, - double massother, const struct gkyl_array* primsother, - const struct gkyl_range *range, struct gkyl_array* crossprims) +void gkyl_prim_bgk_cross_calc_advance( + struct gkyl_basis basis, int vdim_phys, const struct gkyl_array *m0sdeltas, double massself, + const struct gkyl_array *primsself, double massother, const struct gkyl_array *primsother, + const struct gkyl_range *range, struct gkyl_array *crossprims +) { unsigned num_basis = basis.num_basis; assert(num_basis <= 20); // MF 2022/11/20: Hardcoded to a max of 3x p2 ser. @@ -17,10 +16,10 @@ gkyl_prim_bgk_cross_calc_advance(struct gkyl_basis basis, unsigned poly_order = basis.poly_order; mul_op_t mul_op = choose_ser_mul_kern(ndim, poly_order); - unsigned udim = primsself->ncomp/num_basis-1; - unsigned u_num_basis = udim*num_basis; - double massDiff = 0.5*(massself-massother)/vdim_phys; - double massSum = massself+massother; + unsigned udim = primsself->ncomp / num_basis - 1; + unsigned u_num_basis = udim * num_basis; + double massDiff = 0.5 * (massself - massother) / vdim_phys; + double massSum = massself + massother; struct gkyl_range_iter iter; gkyl_range_iter_init(&iter, range); @@ -43,50 +42,61 @@ gkyl_prim_bgk_cross_calc_advance(struct gkyl_basis basis, // u_sr = u_si - u_ri: array_set1(u_num_basis, ucross, 1., uself); - array_acc1(u_num_basis, ucross,-1., uother); + array_acc1(u_num_basis, ucross, -1., uother); // v_tsr^2 = (u_si-u_ri)^2 = (u_si-u_ri) . (u_si-u_ri) - double vbuf[20*3]; // MF 2022/11/20: Hardcoded to 3x p2 ser (3 components). - for (int k=0; k } -__global__ void -gkyl_prim_bgk_cross_calc_advance_cu_kernel(struct gkyl_basis basis, - int vdim_phys, const struct gkyl_array* m0sdeltas, - double massself, const struct gkyl_array* primsself, - double massother, const struct gkyl_array* primsother, - struct gkyl_range range, struct gkyl_array* crossprims) +__global__ void gkyl_prim_bgk_cross_calc_advance_cu_kernel( + struct gkyl_basis basis, int vdim_phys, const struct gkyl_array *m0sdeltas, double massself, + const struct gkyl_array *primsself, double massother, const struct gkyl_array *primsother, + struct gkyl_range range, struct gkyl_array *crossprims +) { unsigned num_basis = basis.num_basis; unsigned ndim = basis.ndim; unsigned poly_order = basis.poly_order; mul_op_t mul_op = choose_ser_mul_kern(ndim, poly_order); - unsigned udim = primsself->ncomp/num_basis-1; - unsigned u_num_basis = udim*num_basis; - double massDiff = 0.5*(massself-massother)/vdim_phys; - double massSum = massself+massother; + unsigned udim = primsself->ncomp / num_basis - 1; + unsigned u_num_basis = udim * num_basis; + double massDiff = 0.5 * (massself - massother) / vdim_phys; + double massSum = massself + massother; int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -40,11 +37,11 @@ gkyl_prim_bgk_cross_calc_advance_cu_kernel(struct gkyl_basis basis, // linc will have jumps in it to jump over ghost cells long start = gkyl_range_idx(&range, idx); - const double *m0sdeltas_d = (const double *) gkyl_array_cfetch(m0sdeltas, start); - const double *primsself_d = (const double *) gkyl_array_cfetch(primsself, start); - const double *primsother_d = (const double *) gkyl_array_cfetch(primsother, start); + const double *m0sdeltas_d = (const double *)gkyl_array_cfetch(m0sdeltas, start); + const double *primsself_d = (const double *)gkyl_array_cfetch(primsself, start); + const double *primsother_d = (const double *)gkyl_array_cfetch(primsother, start); - double *crossprims_d = (double *) gkyl_array_fetch(crossprims, start); + double *crossprims_d = (double *)gkyl_array_fetch(crossprims, start); // Pointers to each primitive moment (for simplicity). const double *uself = primsself_d; @@ -56,65 +53,76 @@ gkyl_prim_bgk_cross_calc_advance_cu_kernel(struct gkyl_basis basis, // u_sr = u_si - u_ri: array_set1(u_num_basis, ucross, 1., uself); - array_acc1(u_num_basis, ucross,-1., uother); + array_acc1(u_num_basis, ucross, -1., uother); // v_tsr^2 = (u_si-u_ri)^2 = (u_si-u_ri) . (u_si-u_ri) - double vbuf[20*3]; // MF 2022/11/20: Hardcoded to 3x p2 ser (3 components). - for (int k=0; knblocks; int nthreads = range->nthreads; - gkyl_prim_bgk_cross_calc_advance_cu_kernel<<>>(basis, - vdim_phys, m0sdeltas->on_dev, massself, primsself->on_dev, - massother, primsother->on_dev, *range, crossprims->on_dev); + gkyl_prim_bgk_cross_calc_advance_cu_kernel<< > >( + basis, vdim_phys, m0sdeltas->on_dev, massself, primsself->on_dev, massother, primsother->on_dev, + *range, crossprims->on_dev + ); } diff --git a/vlasov/zero/prim_cross_m0deltas.c b/vlasov/zero/prim_cross_m0deltas.c index 64a8c8b596..2fdb6e8ac5 100644 --- a/vlasov/zero/prim_cross_m0deltas.c +++ b/vlasov/zero/prim_cross_m0deltas.c @@ -5,9 +5,10 @@ #include #include -gkyl_prim_cross_m0deltas* -gkyl_prim_cross_m0deltas_new(bool normNu, const struct gkyl_basis *basis, - const struct gkyl_range *range, double betap1, bool use_gpu) +gkyl_prim_cross_m0deltas *gkyl_prim_cross_m0deltas_new( + bool normNu, const struct gkyl_basis *basis, const struct gkyl_range *range, double betap1, + bool use_gpu +) { gkyl_prim_cross_m0deltas *up = gkyl_malloc(sizeof(gkyl_prim_cross_m0deltas)); @@ -17,26 +18,28 @@ gkyl_prim_cross_m0deltas_new(bool normNu, const struct gkyl_basis *basis, up->normNu = normNu; up->basis = basis; up->range = range; - up->betap1T2 = betap1*2.0; + up->betap1T2 = betap1 * 2.0; up->use_gpu = use_gpu; // Preallocate memory for the weak division. - up->mem = use_gpu ? gkyl_dg_bin_op_mem_cu_dev_new(range->volume, basis->num_basis) - : gkyl_dg_bin_op_mem_new(range->volume, basis->num_basis); + up->mem = use_gpu ? gkyl_dg_bin_op_mem_cu_dev_new(range->volume, basis->num_basis) : + gkyl_dg_bin_op_mem_new(range->volume, basis->num_basis); return up; } -void -gkyl_prim_cross_m0deltas_advance(gkyl_prim_cross_m0deltas *up, - double massself, const struct gkyl_array* m0self, const struct gkyl_array* nuself, - double massother, const struct gkyl_array* m0other, const struct gkyl_array* nuother, - struct gkyl_array* out) +void gkyl_prim_cross_m0deltas_advance( + gkyl_prim_cross_m0deltas *up, double massself, const struct gkyl_array *m0self, + const struct gkyl_array *nuself, double massother, const struct gkyl_array *m0other, + const struct gkyl_array *nuother, struct gkyl_array *out +) { #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) - return gkyl_prim_cross_m0deltas_advance_cu(up, massself, m0self, nuself, - massother, m0other, nuother, out); + if (up->use_gpu) { + return gkyl_prim_cross_m0deltas_advance_cu( + up, massself, m0self, nuself, massother, m0other, nuother, out + ); + } #endif int num_basis = up->basis->num_basis; @@ -70,25 +73,25 @@ gkyl_prim_cross_m0deltas_advance(gkyl_prim_cross_m0deltas *up, // nu_sr*n_s*delta_s*(beta+1) = 2*(beta+1) * n_s * nu_sr * m_r * n_r * nu_rs / (m_s * n_s * nu_sr + m_r * n_r * nu_rs) mul_op(nuself_d, m0self_d, denom); mul_op(nuother_d, m0other_d, numer); - - for (int k=0; kbetap1T2*massother; + numer[k] *= up->betap1T2 * massother; } - - array_acc1(num_basis, denom, 1.0/up->betap1T2, numer); - + + array_acc1(num_basis, denom, 1.0 / up->betap1T2, numer); + mul_op(m0self_d, numer, numer); - if (up->normNu) + if (up->normNu) { mul_op(nuself_d, numer, numer); - } - else { + } + } else { // Both collision frequencies are zero, so set the numerator and // denominator to 1. In this case the collision operator will be turned // off anyway, so we just want to avoid a division by 0 here. denom[0] = 1.0; numer[0] = 1.0; - for (int k=1; kmem); gkyl_free(up); diff --git a/vlasov/zero/prim_cross_m0deltas_cu.cu b/vlasov/zero/prim_cross_m0deltas_cu.cu index 8e292dfd37..7ee1da5008 100644 --- a/vlasov/zero/prim_cross_m0deltas_cu.cu +++ b/vlasov/zero/prim_cross_m0deltas_cu.cu @@ -10,12 +10,12 @@ extern "C" { #include } -__global__ void -gkyl_prim_cross_m0deltas_set_op_range_cu_kernel(struct gkyl_nmat *As, struct gkyl_nmat *xs, - struct gkyl_basis basis, bool normNu, double betap1T2, - double massself, struct gkyl_array* m0self, struct gkyl_array* nuself, - double massother, struct gkyl_array* m0other, struct gkyl_array* nuother, - struct gkyl_range range, struct gkyl_array* out) +__global__ void gkyl_prim_cross_m0deltas_set_op_range_cu_kernel( + struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_basis basis, bool normNu, double betap1T2, + double massself, struct gkyl_array *m0self, struct gkyl_array *nuself, double massother, + struct gkyl_array *m0other, struct gkyl_array *nuother, struct gkyl_range range, + struct gkyl_array *out +) { int num_basis = basis.num_basis; int ndim = basis.ndim; @@ -27,10 +27,8 @@ gkyl_prim_cross_m0deltas_set_op_range_cu_kernel(struct gkyl_nmat *As, struct gky // MF 2022/11/19: Hardcoded to a max number of basis for 3x p2 ser. double denom[20], numer[20]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < range.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -40,10 +38,10 @@ gkyl_prim_cross_m0deltas_set_op_range_cu_kernel(struct gkyl_nmat *As, struct gky // linc will have jumps in it to jump over ghost cells long start = gkyl_range_idx(&range, idx); - const double *m0self_d = (const double*) gkyl_array_cfetch(m0self, start); - const double *nuself_d = (const double*) gkyl_array_cfetch(nuself, start); - const double *m0other_d = (const double*) gkyl_array_cfetch(m0other, start); - const double *nuother_d = (const double*) gkyl_array_cfetch(nuother, start); + const double *m0self_d = (const double *)gkyl_array_cfetch(m0self, start); + const double *nuself_d = (const double *)gkyl_array_cfetch(nuself, start); + const double *m0other_d = (const double *)gkyl_array_cfetch(m0other, start); + const double *nuother_d = (const double *)gkyl_array_cfetch(nuother, start); if (nuself_d[0] > 0.0 && nuother_d[0] > 0.0) { // compute the numerator and denominator, if collision frequency is @@ -53,25 +51,25 @@ gkyl_prim_cross_m0deltas_set_op_range_cu_kernel(struct gkyl_nmat *As, struct gky // nu_sr*n_s*delta_s*(beta+1) = 2*(beta+1) * n_s * nu_sr * m_r * n_r * nu_rs / (m_s * n_s * nu_sr + m_r * n_r * nu_rs) mul_op(nuself_d, m0self_d, denom); mul_op(nuother_d, m0other_d, numer); - - for (int k=0; krange->nblocks; int nthreads = up->range->nthreads; @@ -126,15 +123,17 @@ void gkyl_prim_cross_m0deltas_advance_cu(gkyl_prim_cross_m0deltas *up, struct gkyl_nmat *x_d = up->mem->xs; // Construct matrices using CUDA kernel. - gkyl_prim_cross_m0deltas_set_op_range_cu_kernel<<>>(A_d->on_dev, - x_d->on_dev, *up->basis, up->normNu, up->betap1T2, massself, m0self->on_dev, nuself->on_dev, - massother, m0other->on_dev, nuother->on_dev, *up->range, out->on_dev); + gkyl_prim_cross_m0deltas_set_op_range_cu_kernel<< > >( + A_d->on_dev, x_d->on_dev, *up->basis, up->normNu, up->betap1T2, massself, m0self->on_dev, + nuself->on_dev, massother, m0other->on_dev, nuother->on_dev, *up->range, out->on_dev + ); // Invert all matrices in batch mode. bool status = gkyl_nmat_linsolve_lu_pa(up->mem->lu_mem, A_d, x_d); assert(status); // Copy solution into array (also lives on the device). - gkyl_prim_cross_m0deltas_copy_sol_range_cu_kernel<<>>(x_d->on_dev, - *up->basis, out->on_dev, *up->range); + gkyl_prim_cross_m0deltas_copy_sol_range_cu_kernel<< > >( + x_d->on_dev, *up->basis, out->on_dev, *up->range + ); } diff --git a/vlasov/zero/prim_lbo_calc.c b/vlasov/zero/prim_lbo_calc.c index db8a031251..34d5e2ce74 100644 --- a/vlasov/zero/prim_lbo_calc.c +++ b/vlasov/zero/prim_lbo_calc.c @@ -7,15 +7,15 @@ #include #include -gkyl_prim_lbo_calc* -gkyl_prim_lbo_calc_new(const struct gkyl_rect_grid *grid, - struct gkyl_prim_lbo_type *prim, bool use_gpu) +gkyl_prim_lbo_calc *gkyl_prim_lbo_calc_new( + const struct gkyl_rect_grid *grid, struct gkyl_prim_lbo_type *prim, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_prim_lbo_calc_cu_dev_new(grid, prim); - } -#endif + } +#endif gkyl_prim_lbo_calc *up = gkyl_malloc(sizeof(gkyl_prim_lbo_calc)); up->grid = *grid; up->prim = gkyl_prim_lbo_type_acquire(prim); @@ -27,29 +27,29 @@ gkyl_prim_lbo_calc_new(const struct gkyl_rect_grid *grid, up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void -gkyl_prim_lbo_calc_advance(struct gkyl_prim_lbo_calc* calc, - const struct gkyl_range *conf_rng, const struct gkyl_array *moms, +void gkyl_prim_lbo_calc_advance( + struct gkyl_prim_lbo_calc *calc, const struct gkyl_range *conf_rng, const struct gkyl_array *moms, const struct gkyl_array *boundary_corrections, const struct gkyl_array *nu, - struct gkyl_array *prim_moms_out) + struct gkyl_array *prim_moms_out +) { #ifdef GKYL_HAVE_CUDA if (GKYL_IS_CU_ALLOC(calc->flags)) { gkyl_prim_lbo_calc_advance_cu(calc, conf_rng, moms, boundary_corrections, nu, prim_moms_out); return; } -#endif +#endif struct gkyl_range_iter conf_iter; // allocate memory for use in kernels int nc = calc->prim->num_config; int udim = calc->prim->udim; - int N = nc*(udim + 1); + int N = nc * (udim + 1); if (calc->is_first) { calc->As = gkyl_nmat_new(conf_rng->volume, N, N); @@ -68,11 +68,12 @@ gkyl_prim_lbo_calc_advance(struct gkyl_prim_lbo_calc* calc, struct gkyl_mat lhs = gkyl_nmat_get(calc->As, count); struct gkyl_mat rhs = gkyl_nmat_get(calc->xs, count); - gkyl_mat_clear(&lhs, 0.0); gkyl_mat_clear(&rhs, 0.0); + gkyl_mat_clear(&lhs, 0.0); + gkyl_mat_clear(&rhs, 0.0); - calc->prim->self_prim(calc->prim, &lhs, &rhs, conf_iter.idx, - gkyl_array_cfetch(moms, midx), gkyl_array_cfetch(boundary_corrections, midx), - gkyl_array_cfetch(nu, midx) + calc->prim->self_prim( + calc->prim, &lhs, &rhs, conf_iter.idx, gkyl_array_cfetch(moms, midx), + gkyl_array_cfetch(boundary_corrections, midx), gkyl_array_cfetch(nu, midx) ); count += 1; @@ -85,7 +86,7 @@ gkyl_prim_lbo_calc_advance(struct gkyl_prim_lbo_calc* calc, count = 0; while (gkyl_range_iter_next(&conf_iter)) { long midx = gkyl_range_idx(conf_rng, conf_iter.idx); - + struct gkyl_mat out = gkyl_nmat_get(calc->xs, count); double *prim_moms = gkyl_array_fetch(prim_moms_out, midx); prim_lbo_copy_sol(&out, nc, udim, prim_moms); @@ -93,42 +94,44 @@ gkyl_prim_lbo_calc_advance(struct gkyl_prim_lbo_calc* calc, } } -const struct gkyl_prim_lbo_type* gkyl_prim_lbo_calc_get_prim(gkyl_prim_lbo_calc* calc) +const struct gkyl_prim_lbo_type *gkyl_prim_lbo_calc_get_prim(gkyl_prim_lbo_calc *calc) { return calc->prim; } -void gkyl_prim_lbo_calc_release(gkyl_prim_lbo_calc* up) +void gkyl_prim_lbo_calc_release(gkyl_prim_lbo_calc *up) { gkyl_prim_lbo_type_release(up->prim); - if (up->As) + if (up->As) { gkyl_nmat_release(up->As); - if (up->xs) + } + if (up->xs) { gkyl_nmat_release(up->xs); - if (up->mem) + } + if (up->mem) { gkyl_nmat_linsolve_lu_release(up->mem); - - if (GKYL_IS_CU_ALLOC(up->flags)) + } + + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } #ifndef GKYL_HAVE_CUDA -gkyl_prim_lbo_calc* -gkyl_prim_lbo_calc_cu_dev_new(const struct gkyl_rect_grid *grid, - struct gkyl_prim_lbo_type *prim) +gkyl_prim_lbo_calc * +gkyl_prim_lbo_calc_cu_dev_new(const struct gkyl_rect_grid *grid, struct gkyl_prim_lbo_type *prim) { assert(false); return 0; } -void -gkyl_prim_lbo_calc_advance_cu(struct gkyl_prim_lbo_calc* calc, - const struct gkyl_range *conf_rng, - const struct gkyl_array* moms, const struct gkyl_array* boundary_corrections, - struct gkyl_array* prim_moms_out) +void gkyl_prim_lbo_calc_advance_cu( + struct gkyl_prim_lbo_calc *calc, const struct gkyl_range *conf_rng, const struct gkyl_array *moms, + const struct gkyl_array *boundary_corrections, struct gkyl_array *prim_moms_out +) { assert(false); } diff --git a/vlasov/zero/prim_lbo_calc_cu.cu b/vlasov/zero/prim_lbo_calc_cu.cu index 5831b61889..b2ee1bfebe 100644 --- a/vlasov/zero/prim_lbo_calc_cu.cu +++ b/vlasov/zero/prim_lbo_calc_cu.cu @@ -6,22 +6,20 @@ extern "C" { #include #include #include -#include +#include #include } -__global__ static void -gkyl_prim_lbo_calc_set_cu_ker(gkyl_prim_lbo_calc* calc, - struct gkyl_nmat *As, struct gkyl_nmat *xs, - struct gkyl_range conf_rng, const struct gkyl_array* moms, - const struct gkyl_array* boundary_corrections, const struct gkyl_array* nu) +__global__ static void gkyl_prim_lbo_calc_set_cu_ker( + gkyl_prim_lbo_calc *calc, struct gkyl_nmat *As, struct gkyl_nmat *xs, struct gkyl_range conf_rng, + const struct gkyl_array *moms, const struct gkyl_array *boundary_corrections, + const struct gkyl_array *nu +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_rng.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_rng.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -34,28 +32,27 @@ gkyl_prim_lbo_calc_set_cu_ker(gkyl_prim_lbo_calc* calc, struct gkyl_mat lhs = gkyl_nmat_get(As, linc1); struct gkyl_mat rhs = gkyl_nmat_get(xs, linc1); - const double *moms_d = (const double*) gkyl_array_cfetch(moms, start); - const double *boundary_corrections_d = (const double*) gkyl_array_cfetch(boundary_corrections, start); - const double *nu_d = (const double*) gkyl_array_cfetch(nu, start); + const double *moms_d = (const double *)gkyl_array_cfetch(moms, start); + const double *boundary_corrections_d = + (const double *)gkyl_array_cfetch(boundary_corrections, start); + const double *nu_d = (const double *)gkyl_array_cfetch(nu, start); - gkyl_mat_clear(&lhs, 0.0); gkyl_mat_clear(&rhs, 0.0); + gkyl_mat_clear(&lhs, 0.0); + gkyl_mat_clear(&rhs, 0.0); calc->prim->self_prim(calc->prim, &lhs, &rhs, idx, moms_d, boundary_corrections_d, nu_d); } } -__global__ static void -gkyl_prim_lbo_copy_sol_cu_ker(struct gkyl_nmat *xs, - struct gkyl_range conf_rng, - int nc, int udim, - struct gkyl_array* prim_moms_out) +__global__ static void gkyl_prim_lbo_copy_sol_cu_ker( + struct gkyl_nmat *xs, struct gkyl_range conf_rng, int nc, int udim, + struct gkyl_array *prim_moms_out +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_rng.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_rng.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -66,21 +63,21 @@ gkyl_prim_lbo_copy_sol_cu_ker(struct gkyl_nmat *xs, long start = gkyl_range_idx(&conf_rng, idx); struct gkyl_mat out_d = gkyl_nmat_get(xs, linc1); - double *prim_moms_out_d = (double*) gkyl_array_fetch(prim_moms_out, start); - + double *prim_moms_out_d = (double *)gkyl_array_fetch(prim_moms_out, start); + prim_lbo_copy_sol(&out_d, nc, udim, prim_moms_out_d); } } -void -gkyl_prim_lbo_calc_advance_cu(struct gkyl_prim_lbo_calc* calc, - const struct gkyl_range *conf_rng, const struct gkyl_array* moms, - const struct gkyl_array* boundary_corrections, const struct gkyl_array *nu, - struct gkyl_array* prim_moms_out) +void gkyl_prim_lbo_calc_advance_cu( + struct gkyl_prim_lbo_calc *calc, const struct gkyl_range *conf_rng, const struct gkyl_array *moms, + const struct gkyl_array *boundary_corrections, const struct gkyl_array *nu, + struct gkyl_array *prim_moms_out +) { int nc = calc->prim->num_config; int udim = calc->prim->udim; - int N = nc*(udim + 1); + int N = nc * (udim + 1); if (calc->is_first) { calc->As = gkyl_nmat_cu_dev_new(conf_rng->volume, N, N); @@ -89,22 +86,22 @@ gkyl_prim_lbo_calc_advance_cu(struct gkyl_prim_lbo_calc* calc, calc->is_first = false; } - gkyl_prim_lbo_calc_set_cu_ker<<nblocks, conf_rng->nthreads>>>(calc->on_dev, - calc->As->on_dev, calc->xs->on_dev, *conf_rng, - moms->on_dev, boundary_corrections->on_dev, nu->on_dev); - + gkyl_prim_lbo_calc_set_cu_ker<<nblocks, conf_rng->nthreads> > >( + calc->on_dev, calc->As->on_dev, calc->xs->on_dev, *conf_rng, moms->on_dev, + boundary_corrections->on_dev, nu->on_dev + ); + bool status = gkyl_nmat_linsolve_lu_pa(calc->mem, calc->As, calc->xs); - gkyl_prim_lbo_copy_sol_cu_ker<<nblocks, conf_rng->nthreads>>>(calc->xs->on_dev, - *conf_rng, nc, udim, - prim_moms_out->on_dev); + gkyl_prim_lbo_copy_sol_cu_ker<<nblocks, conf_rng->nthreads> > >( + calc->xs->on_dev, *conf_rng, nc, udim, prim_moms_out->on_dev + ); } -struct gkyl_prim_lbo_calc* -gkyl_prim_lbo_calc_cu_dev_new(const struct gkyl_rect_grid *grid, - struct gkyl_prim_lbo_type *prim) +struct gkyl_prim_lbo_calc * +gkyl_prim_lbo_calc_cu_dev_new(const struct gkyl_rect_grid *grid, struct gkyl_prim_lbo_type *prim) { - gkyl_prim_lbo_calc *up = (gkyl_prim_lbo_calc*) gkyl_malloc(sizeof(gkyl_prim_lbo_calc)); + gkyl_prim_lbo_calc *up = (gkyl_prim_lbo_calc *)gkyl_malloc(sizeof(gkyl_prim_lbo_calc)); up->grid = *grid; up->prim = prim; @@ -118,11 +115,11 @@ gkyl_prim_lbo_calc_cu_dev_new(const struct gkyl_rect_grid *grid, up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - gkyl_prim_lbo_calc *up_cu = (gkyl_prim_lbo_calc*) gkyl_cu_malloc(sizeof(gkyl_prim_lbo_calc)); + gkyl_prim_lbo_calc *up_cu = (gkyl_prim_lbo_calc *)gkyl_cu_malloc(sizeof(gkyl_prim_lbo_calc)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_prim_lbo_calc), GKYL_CU_MEMCPY_H2D); up->prim = pt; // host portion of struct should have host copy up->on_dev = up_cu; // host pointer - + return up; } diff --git a/vlasov/zero/prim_lbo_calc_vlasov.c b/vlasov/zero/prim_lbo_calc_vlasov.c index 0d14fd6c4d..a8ed9bc67c 100644 --- a/vlasov/zero/prim_lbo_calc_vlasov.c +++ b/vlasov/zero/prim_lbo_calc_vlasov.c @@ -9,10 +9,10 @@ #include // "derived" class constructors -struct gkyl_prim_lbo_calc* -gkyl_prim_lbo_vlasov_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_rng, bool use_gpu) +struct gkyl_prim_lbo_calc *gkyl_prim_lbo_vlasov_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_rng, bool use_gpu +) { struct gkyl_prim_lbo_type *prim; // LBO primitive moments type prim = gkyl_prim_lbo_vlasov_new(cbasis, pbasis, use_gpu); diff --git a/vlasov/zero/prim_lbo_cross_calc.c b/vlasov/zero/prim_lbo_cross_calc.c index 42d8d2c412..933383412e 100644 --- a/vlasov/zero/prim_lbo_cross_calc.c +++ b/vlasov/zero/prim_lbo_cross_calc.c @@ -8,15 +8,15 @@ #include #include -struct gkyl_prim_lbo_cross_calc* -gkyl_prim_lbo_cross_calc_new(const struct gkyl_rect_grid *grid, - struct gkyl_prim_lbo_type *prim, bool use_gpu) +struct gkyl_prim_lbo_cross_calc *gkyl_prim_lbo_cross_calc_new( + const struct gkyl_rect_grid *grid, struct gkyl_prim_lbo_type *prim, bool use_gpu +) { #ifdef GKYL_HAVE_CUDA if (use_gpu) { return gkyl_prim_lbo_cross_calc_cu_dev_new(grid, prim); - } -#endif + } +#endif gkyl_prim_lbo_cross_calc *up = gkyl_malloc(sizeof(gkyl_prim_lbo_cross_calc)); up->grid = *grid; up->prim = gkyl_prim_lbo_type_acquire(prim); @@ -28,32 +28,34 @@ gkyl_prim_lbo_cross_calc_new(const struct gkyl_rect_grid *grid, up->flags = 0; GKYL_CLEAR_CU_ALLOC(up->flags); up->on_dev = up; // self-reference on host - + return up; } -void -gkyl_prim_lbo_cross_calc_advance(struct gkyl_prim_lbo_cross_calc* calc, - const struct gkyl_range *conf_rng, const struct gkyl_array *alpha_E, - double self_m, const struct gkyl_array *self_moms, const struct gkyl_array *self_prim_moms, - double other_m, const struct gkyl_array *other_moms, const struct gkyl_array *other_prim_moms, - const struct gkyl_array *boundary_corrections, const struct gkyl_array *nu, - struct gkyl_array *prim_moms_out) +void gkyl_prim_lbo_cross_calc_advance( + struct gkyl_prim_lbo_cross_calc *calc, const struct gkyl_range *conf_rng, + const struct gkyl_array *alpha_E, double self_m, const struct gkyl_array *self_moms, + const struct gkyl_array *self_prim_moms, double other_m, const struct gkyl_array *other_moms, + const struct gkyl_array *other_prim_moms, const struct gkyl_array *boundary_corrections, + const struct gkyl_array *nu, struct gkyl_array *prim_moms_out +) { #ifdef GKYL_HAVE_CUDA if (GKYL_IS_CU_ALLOC(calc->flags)) { - gkyl_prim_lbo_cross_calc_advance_cu(calc, conf_rng, alpha_E, self_m, self_moms, self_prim_moms, - other_m, other_moms, other_prim_moms, boundary_corrections, nu, prim_moms_out); + gkyl_prim_lbo_cross_calc_advance_cu( + calc, conf_rng, alpha_E, self_m, self_moms, self_prim_moms, other_m, other_moms, + other_prim_moms, boundary_corrections, nu, prim_moms_out + ); return; } -#endif +#endif struct gkyl_range_iter conf_iter; // allocate memory for use in kernels int nc = calc->prim->num_config; int udim = calc->prim->udim; - int N = nc*(udim + 1); + int N = nc * (udim + 1); if (calc->is_first) { calc->As = gkyl_nmat_new(conf_rng->volume, N, N); @@ -61,7 +63,7 @@ gkyl_prim_lbo_cross_calc_advance(struct gkyl_prim_lbo_cross_calc* calc, calc->mem = gkyl_nmat_linsolve_lu_new(calc->As->num, calc->As->nr); calc->is_first = false; } - + // loop over configuration space cells. gkyl_range_iter_init(&conf_iter, conf_rng); long count = 0; @@ -71,11 +73,13 @@ gkyl_prim_lbo_cross_calc_advance(struct gkyl_prim_lbo_cross_calc* calc, struct gkyl_mat lhs = gkyl_nmat_get(calc->As, count); struct gkyl_mat rhs = gkyl_nmat_get(calc->xs, count); - gkyl_mat_clear(&lhs, 0.0); gkyl_mat_clear(&rhs, 0.0); + gkyl_mat_clear(&lhs, 0.0); + gkyl_mat_clear(&rhs, 0.0); - calc->prim->cross_prim(calc->prim, &lhs, &rhs, conf_iter.idx, gkyl_array_cfetch(alpha_E, midx), - self_m, gkyl_array_cfetch(self_moms, midx), gkyl_array_cfetch(self_prim_moms, midx), - other_m, gkyl_array_cfetch(other_moms, midx), gkyl_array_cfetch(other_prim_moms, midx), + calc->prim->cross_prim( + calc->prim, &lhs, &rhs, conf_iter.idx, gkyl_array_cfetch(alpha_E, midx), self_m, + gkyl_array_cfetch(self_moms, midx), gkyl_array_cfetch(self_prim_moms, midx), other_m, + gkyl_array_cfetch(other_moms, midx), gkyl_array_cfetch(other_prim_moms, midx), gkyl_array_cfetch(boundary_corrections, midx), gkyl_array_cfetch(nu, midx) ); @@ -93,30 +97,31 @@ gkyl_prim_lbo_cross_calc_advance(struct gkyl_prim_lbo_cross_calc* calc, struct gkyl_mat out = gkyl_nmat_get(calc->xs, count); prim_lbo_copy_sol(&out, nc, udim, gkyl_array_fetch(prim_moms_out, midx)); count += 1; - } } -const struct gkyl_prim_lbo_type* -gkyl_prim_lbo_cross_calc_get_prim(struct gkyl_prim_lbo_cross_calc* calc) +const struct gkyl_prim_lbo_type * +gkyl_prim_lbo_cross_calc_get_prim(struct gkyl_prim_lbo_cross_calc *calc) { return calc->prim; } -void -gkyl_prim_lbo_cross_calc_release(struct gkyl_prim_lbo_cross_calc* up) +void gkyl_prim_lbo_cross_calc_release(struct gkyl_prim_lbo_cross_calc *up) { gkyl_prim_lbo_type_release(up->prim); - if (up->As) + if (up->As) { gkyl_nmat_release(up->As); - if (up->xs) + } + if (up->xs) { gkyl_nmat_release(up->xs); - if (up->mem) + } + if (up->mem) { gkyl_nmat_linsolve_lu_release(up->mem); - - if (GKYL_IS_CU_ALLOC(up->flags)) + } + + if (GKYL_IS_CU_ALLOC(up->flags)) { gkyl_cu_free(up->on_dev); + } gkyl_free(up); } - diff --git a/vlasov/zero/prim_lbo_cross_calc_cu.cu b/vlasov/zero/prim_lbo_cross_calc_cu.cu index 4fe44c9bd6..35389cd2a7 100644 --- a/vlasov/zero/prim_lbo_cross_calc_cu.cu +++ b/vlasov/zero/prim_lbo_cross_calc_cu.cu @@ -6,25 +6,23 @@ extern "C" { #include #include #include -#include +#include #include #include } -__global__ static void -gkyl_prim_lbo_cross_calc_set_cu_ker(gkyl_prim_lbo_cross_calc* calc, - struct gkyl_nmat *As, struct gkyl_nmat *xs, - const struct gkyl_range conf_rng, const struct gkyl_array *alpha_E, - double self_m, const struct gkyl_array *self_moms, const struct gkyl_array *self_prim_moms, - double other_m, const struct gkyl_array *other_moms, const struct gkyl_array *other_prim_moms, - const struct gkyl_array *boundary_corrections, const struct gkyl_array *nu) +__global__ static void gkyl_prim_lbo_cross_calc_set_cu_ker( + gkyl_prim_lbo_cross_calc *calc, struct gkyl_nmat *As, struct gkyl_nmat *xs, + const struct gkyl_range conf_rng, const struct gkyl_array *alpha_E, double self_m, + const struct gkyl_array *self_moms, const struct gkyl_array *self_prim_moms, double other_m, + const struct gkyl_array *other_moms, const struct gkyl_array *other_prim_moms, + const struct gkyl_array *boundary_corrections, const struct gkyl_array *nu +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_rng.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_rng.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -37,36 +35,34 @@ gkyl_prim_lbo_cross_calc_set_cu_ker(gkyl_prim_lbo_cross_calc* calc, struct gkyl_mat lhs = gkyl_nmat_get(As, linc1); struct gkyl_mat rhs = gkyl_nmat_get(xs, linc1); - const double *alpha_E_d = (const double*) gkyl_array_cfetch(alpha_E, start); - const double *self_moms_d = (const double*) gkyl_array_cfetch(self_moms, start); - const double *self_prim_moms_d = (const double*) gkyl_array_cfetch(self_prim_moms, start); - const double *other_moms_d = (const double*) gkyl_array_cfetch(other_moms, start); - const double *other_prim_moms_d = (const double*) gkyl_array_cfetch(other_prim_moms, start); - const double *boundary_corrections_d = (const double*) gkyl_array_cfetch(boundary_corrections, start); - const double *nu_d = (const double*) gkyl_array_cfetch(nu, start); - - gkyl_mat_clear(&lhs, 0.0); gkyl_mat_clear(&rhs, 0.0); - - calc->prim->cross_prim(calc->prim, &lhs, &rhs, idx, alpha_E_d, - self_m, self_moms_d, self_prim_moms_d, - other_m, other_moms_d, other_prim_moms_d, - boundary_corrections_d, nu_d + const double *alpha_E_d = (const double *)gkyl_array_cfetch(alpha_E, start); + const double *self_moms_d = (const double *)gkyl_array_cfetch(self_moms, start); + const double *self_prim_moms_d = (const double *)gkyl_array_cfetch(self_prim_moms, start); + const double *other_moms_d = (const double *)gkyl_array_cfetch(other_moms, start); + const double *other_prim_moms_d = (const double *)gkyl_array_cfetch(other_prim_moms, start); + const double *boundary_corrections_d = + (const double *)gkyl_array_cfetch(boundary_corrections, start); + const double *nu_d = (const double *)gkyl_array_cfetch(nu, start); + + gkyl_mat_clear(&lhs, 0.0); + gkyl_mat_clear(&rhs, 0.0); + + calc->prim->cross_prim( + calc->prim, &lhs, &rhs, idx, alpha_E_d, self_m, self_moms_d, self_prim_moms_d, other_m, + other_moms_d, other_prim_moms_d, boundary_corrections_d, nu_d ); } } -__global__ static void -gkyl_prim_lbo_copy_sol_cu_ker(struct gkyl_nmat *xs, - const struct gkyl_range conf_rng, - int nc, int udim, - struct gkyl_array* prim_moms_out) +__global__ static void gkyl_prim_lbo_copy_sol_cu_ker( + struct gkyl_nmat *xs, const struct gkyl_range conf_rng, int nc, int udim, + struct gkyl_array *prim_moms_out +) { int idx[GKYL_MAX_DIM]; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_rng.volume; - linc1 += gridDim.x*blockDim.x) - { + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_rng.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -77,49 +73,50 @@ gkyl_prim_lbo_copy_sol_cu_ker(struct gkyl_nmat *xs, long start = gkyl_range_idx(&conf_rng, idx); struct gkyl_mat out_d = gkyl_nmat_get(xs, linc1); - double *prim_moms_d = (double*) gkyl_array_fetch(prim_moms_out, start); - + double *prim_moms_d = (double *)gkyl_array_fetch(prim_moms_out, start); + prim_lbo_copy_sol(&out_d, nc, udim, prim_moms_d); } } -void -gkyl_prim_lbo_cross_calc_advance_cu(struct gkyl_prim_lbo_cross_calc* calc, - const struct gkyl_range *conf_rng, const struct gkyl_array *alpha_E, - double self_m, const struct gkyl_array *self_moms, const struct gkyl_array *self_prim_moms, - double other_m, const struct gkyl_array *other_moms, const struct gkyl_array *other_prim_moms, - const struct gkyl_array *boundary_corrections, const struct gkyl_array *nu, - struct gkyl_array *prim_moms_out) +void gkyl_prim_lbo_cross_calc_advance_cu( + struct gkyl_prim_lbo_cross_calc *calc, const struct gkyl_range *conf_rng, + const struct gkyl_array *alpha_E, double self_m, const struct gkyl_array *self_moms, + const struct gkyl_array *self_prim_moms, double other_m, const struct gkyl_array *other_moms, + const struct gkyl_array *other_prim_moms, const struct gkyl_array *boundary_corrections, + const struct gkyl_array *nu, struct gkyl_array *prim_moms_out +) { int nc = calc->prim->num_config; int udim = calc->prim->udim; - int N = nc*(udim + 1); - + int N = nc * (udim + 1); + if (calc->is_first) { calc->As = gkyl_nmat_cu_dev_new(conf_rng->volume, N, N); calc->xs = gkyl_nmat_cu_dev_new(conf_rng->volume, N, 1); calc->mem = gkyl_nmat_linsolve_lu_cu_dev_new(calc->As->num, calc->As->nr); calc->is_first = false; } - - gkyl_prim_lbo_cross_calc_set_cu_ker<<nblocks, conf_rng->nthreads>>>(calc->on_dev, - calc->As->on_dev, calc->xs->on_dev, *conf_rng, alpha_E->on_dev, - self_m, self_moms->on_dev, self_prim_moms->on_dev, - other_m, other_moms->on_dev, other_prim_moms->on_dev, - boundary_corrections->on_dev, nu->on_dev); - + + gkyl_prim_lbo_cross_calc_set_cu_ker<<nblocks, conf_rng->nthreads> > >( + calc->on_dev, calc->As->on_dev, calc->xs->on_dev, *conf_rng, alpha_E->on_dev, self_m, + self_moms->on_dev, self_prim_moms->on_dev, other_m, other_moms->on_dev, other_prim_moms->on_dev, + boundary_corrections->on_dev, nu->on_dev + ); + bool status = gkyl_nmat_linsolve_lu_pa(calc->mem, calc->As, calc->xs); - - gkyl_prim_lbo_copy_sol_cu_ker<<nblocks, conf_rng->nthreads>>>(calc->xs->on_dev, - *conf_rng, nc, udim, - prim_moms_out->on_dev); + + gkyl_prim_lbo_copy_sol_cu_ker<<nblocks, conf_rng->nthreads> > >( + calc->xs->on_dev, *conf_rng, nc, udim, prim_moms_out->on_dev + ); } -gkyl_prim_lbo_cross_calc* -gkyl_prim_lbo_cross_calc_cu_dev_new(const struct gkyl_rect_grid *grid, - struct gkyl_prim_lbo_type *prim) +gkyl_prim_lbo_cross_calc *gkyl_prim_lbo_cross_calc_cu_dev_new( + const struct gkyl_rect_grid *grid, struct gkyl_prim_lbo_type *prim +) { - gkyl_prim_lbo_cross_calc *up = (gkyl_prim_lbo_cross_calc*) gkyl_malloc(sizeof(gkyl_prim_lbo_cross_calc)); + gkyl_prim_lbo_cross_calc *up = + (gkyl_prim_lbo_cross_calc *)gkyl_malloc(sizeof(gkyl_prim_lbo_cross_calc)); up->grid = *grid; up->prim = prim; @@ -133,11 +130,12 @@ gkyl_prim_lbo_cross_calc_cu_dev_new(const struct gkyl_rect_grid *grid, up->flags = 0; GKYL_SET_CU_ALLOC(up->flags); - gkyl_prim_lbo_cross_calc *up_cu = (gkyl_prim_lbo_cross_calc*) gkyl_cu_malloc(sizeof(gkyl_prim_lbo_cross_calc)); + gkyl_prim_lbo_cross_calc *up_cu = + (gkyl_prim_lbo_cross_calc *)gkyl_cu_malloc(sizeof(gkyl_prim_lbo_cross_calc)); gkyl_cu_memcpy(up_cu, up, sizeof(gkyl_prim_lbo_cross_calc), GKYL_CU_MEMCPY_H2D); up->prim = pt; // host portion of struct should have host copy up->on_dev = up_cu; // host pointer - + return up; } diff --git a/vlasov/zero/prim_lbo_cross_calc_vlasov.c b/vlasov/zero/prim_lbo_cross_calc_vlasov.c index 2b2150343d..4552867523 100644 --- a/vlasov/zero/prim_lbo_cross_calc_vlasov.c +++ b/vlasov/zero/prim_lbo_cross_calc_vlasov.c @@ -9,10 +9,10 @@ #include // "derived" class constructors -struct gkyl_prim_lbo_cross_calc* -gkyl_prim_lbo_vlasov_cross_calc_new(const struct gkyl_rect_grid *grid, - const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, - const struct gkyl_range *conf_rng, bool use_gpu) +struct gkyl_prim_lbo_cross_calc *gkyl_prim_lbo_vlasov_cross_calc_new( + const struct gkyl_rect_grid *grid, const struct gkyl_basis *cbasis, + const struct gkyl_basis *pbasis, const struct gkyl_range *conf_rng, bool use_gpu +) { struct gkyl_prim_lbo_type *prim; // LBO primitive moments type prim = gkyl_prim_lbo_vlasov_new(cbasis, pbasis, use_gpu); diff --git a/vlasov/zero/prim_lbo_type.c b/vlasov/zero/prim_lbo_type.c index 394dcf316d..a2974d1955 100644 --- a/vlasov/zero/prim_lbo_type.c +++ b/vlasov/zero/prim_lbo_type.c @@ -1,14 +1,12 @@ #include -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_type_acquire(const struct gkyl_prim_lbo_type* prim) +struct gkyl_prim_lbo_type *gkyl_prim_lbo_type_acquire(const struct gkyl_prim_lbo_type *prim) { gkyl_ref_count_inc(&prim->ref_count); - return (struct gkyl_prim_lbo_type*) prim; + return (struct gkyl_prim_lbo_type *)prim; } -void -gkyl_prim_lbo_type_release(const struct gkyl_prim_lbo_type* prim) +void gkyl_prim_lbo_type_release(const struct gkyl_prim_lbo_type *prim) { gkyl_ref_count_dec(&prim->ref_count); } diff --git a/vlasov/zero/prim_lbo_vlasov.c b/vlasov/zero/prim_lbo_vlasov.c index a64759c4d4..963e896bbb 100644 --- a/vlasov/zero/prim_lbo_vlasov.c +++ b/vlasov/zero/prim_lbo_vlasov.c @@ -9,32 +9,32 @@ #include #include -void -prim_lbo_vlasov_free(const struct gkyl_ref_count *ref) +void prim_lbo_vlasov_free(const struct gkyl_ref_count *ref) { struct gkyl_prim_lbo_type *prim_ty = container_of(ref, struct gkyl_prim_lbo_type, ref_count); - if (GKYL_IS_CU_ALLOC(prim_ty->flag)) + if (GKYL_IS_CU_ALLOC(prim_ty->flag)) { gkyl_cu_free(prim_ty->on_dev); + } struct prim_lbo_type_vlasov *vlasov = container_of(prim_ty, struct prim_lbo_type_vlasov, prim); gkyl_free(vlasov); } -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_vlasov_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis, bool use_gpu) +struct gkyl_prim_lbo_type *gkyl_prim_lbo_vlasov_new( + const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis, bool use_gpu +) { assert(cbasis->poly_order == pbasis->poly_order); #ifdef GKYL_HAVE_CUDA - if(use_gpu) { + if (use_gpu) { return gkyl_prim_lbo_vlasov_cu_dev_new(cbasis, pbasis); - } -#endif + } +#endif struct prim_lbo_type_vlasov *prim_vlasov = gkyl_malloc(sizeof(struct prim_lbo_type_vlasov)); int cdim = prim_vlasov->prim.cdim = cbasis->ndim; int pdim = prim_vlasov->prim.pdim = pbasis->ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int poly_order = prim_vlasov->prim.poly_order = cbasis->poly_order; prim_vlasov->prim.num_config = cbasis->num_basis; prim_vlasov->prim.num_phase = pbasis->num_basis; @@ -47,19 +47,19 @@ gkyl_prim_lbo_vlasov_new(const struct gkyl_basis* cbasis, const gkyl_prim_lbo_vlasov_cross_kern_list *cross_prim_kernels; switch (cbasis->b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - self_prim_kernels = ser_self_prim_kernels; - cross_prim_kernels = ser_cross_prim_kernels; - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + self_prim_kernels = ser_self_prim_kernels; + cross_prim_kernels = ser_cross_prim_kernels; + break; - default: - assert(false); - break; + default: + assert(false); + break; } assert(cv_index[cdim].vdim[vdim] != -1); assert(NULL != self_prim_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); assert(NULL != cross_prim_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]); - + prim_vlasov->self_prim = self_prim_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; prim_vlasov->cross_prim = cross_prim_kernels[cv_index[cdim].vdim[vdim]].kernels[poly_order]; @@ -68,15 +68,14 @@ gkyl_prim_lbo_vlasov_new(const struct gkyl_basis* cbasis, prim_vlasov->prim.ref_count = gkyl_ref_count_init(prim_lbo_vlasov_free); prim_vlasov->prim.on_dev = &prim_vlasov->prim; - + return &prim_vlasov->prim; } #ifndef GKYL_HAVE_CUDA -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis) +struct gkyl_prim_lbo_type * +gkyl_prim_lbo_vlasov_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis) { assert(false); return 0; diff --git a/vlasov/zero/prim_lbo_vlasov_cu.cu b/vlasov/zero/prim_lbo_vlasov_cu.cu index 58881de64d..d1d4220b4d 100644 --- a/vlasov/zero/prim_lbo_vlasov_cu.cu +++ b/vlasov/zero/prim_lbo_vlasov_cu.cu @@ -10,40 +10,41 @@ extern "C" { #include } -__global__ static void -gkyl_prim_lbo_vlasov_set_cu_dev_ptrs(struct prim_lbo_type_vlasov *prim_vlasov, int cdim, int vdim, int poly_order, enum gkyl_basis_type b_type, int tblidx) +__global__ static void gkyl_prim_lbo_vlasov_set_cu_dev_ptrs( + struct prim_lbo_type_vlasov *prim_vlasov, int cdim, int vdim, int poly_order, + enum gkyl_basis_type b_type, int tblidx +) { prim_vlasov->prim.self_prim = self_prim; prim_vlasov->prim.cross_prim = cross_prim; - + // choose kernel tables based on basis-function type const gkyl_prim_lbo_vlasov_self_kern_list *self_prim_kernels; const gkyl_prim_lbo_vlasov_cross_kern_list *cross_prim_kernels; switch (b_type) { - case GKYL_BASIS_MODAL_SERENDIPITY: - self_prim_kernels = ser_self_prim_kernels; - cross_prim_kernels = ser_cross_prim_kernels; - break; - - default: - assert(false); - break; + case GKYL_BASIS_MODAL_SERENDIPITY: + self_prim_kernels = ser_self_prim_kernels; + cross_prim_kernels = ser_cross_prim_kernels; + break; + + default: + assert(false); + break; } prim_vlasov->self_prim = self_prim_kernels[tblidx].kernels[poly_order]; prim_vlasov->cross_prim = cross_prim_kernels[tblidx].kernels[poly_order]; } -struct gkyl_prim_lbo_type* -gkyl_prim_lbo_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, - const struct gkyl_basis* pbasis) +struct gkyl_prim_lbo_type * +gkyl_prim_lbo_vlasov_cu_dev_new(const struct gkyl_basis *cbasis, const struct gkyl_basis *pbasis) { assert(cbasis->poly_order == pbasis->poly_order); - + struct prim_lbo_type_vlasov *prim_vlasov = - (struct prim_lbo_type_vlasov*) gkyl_malloc(sizeof(struct prim_lbo_type_vlasov)); - + (struct prim_lbo_type_vlasov *)gkyl_malloc(sizeof(struct prim_lbo_type_vlasov)); + int cdim = prim_vlasov->prim.cdim = cbasis->ndim; int pdim = prim_vlasov->prim.pdim = pbasis->ndim; int vdim = pdim - cdim; @@ -55,18 +56,21 @@ gkyl_prim_lbo_vlasov_cu_dev_new(const struct gkyl_basis* cbasis, prim_vlasov->prim.flag = 0; GKYL_SET_CU_ALLOC(prim_vlasov->prim.flag); prim_vlasov->prim.ref_count = gkyl_ref_count_init(prim_lbo_vlasov_free); - + // copy the host struct to device struct - struct prim_lbo_type_vlasov *prim_vlasov_cu = (struct prim_lbo_type_vlasov*) - gkyl_cu_malloc(sizeof(struct prim_lbo_type_vlasov)); - gkyl_cu_memcpy(prim_vlasov_cu, prim_vlasov, sizeof(struct prim_lbo_type_vlasov), GKYL_CU_MEMCPY_H2D); + struct prim_lbo_type_vlasov *prim_vlasov_cu = + (struct prim_lbo_type_vlasov *)gkyl_cu_malloc(sizeof(struct prim_lbo_type_vlasov)); + gkyl_cu_memcpy( + prim_vlasov_cu, prim_vlasov, sizeof(struct prim_lbo_type_vlasov), GKYL_CU_MEMCPY_H2D + ); assert(cv_index[cdim].vdim[vdim] != -1); - - gkyl_prim_lbo_vlasov_set_cu_dev_ptrs<<<1,1>>>(prim_vlasov_cu, cdim, vdim, poly_order, - cbasis->b_type, cv_index[cdim].vdim[vdim]); + + gkyl_prim_lbo_vlasov_set_cu_dev_ptrs<<<1, 1> > >( + prim_vlasov_cu, cdim, vdim, poly_order, cbasis->b_type, cv_index[cdim].vdim[vdim] + ); prim_vlasov->prim.on_dev = &prim_vlasov_cu->prim; - + return &prim_vlasov->prim; } diff --git a/vlasov/zero/spitzer_coll_freq.c b/vlasov/zero/spitzer_coll_freq.c index 30c39e6abb..ca9db5de51 100644 --- a/vlasov/zero/spitzer_coll_freq.c +++ b/vlasov/zero/spitzer_coll_freq.c @@ -12,46 +12,58 @@ // Calculate the plasma frequency double plasma_frequency(double n, double m, double eps0, double eV) { - return sqrt(n*eV*eV/m/eps0); + return sqrt(n * eV * eV / m / eps0); } // Calculate the Coulomb Logarithm -double coulomb_log(double ns, double nr, double ms, double mr, double Ts, double Tr, - double qs, double qr, double bmag, double eps0, double hbar, double eV) +double coulomb_log( + double ns, double nr, double ms, double mr, double Ts, double Tr, double qs, double qr, + double bmag, double eps0, double hbar, double eV +) { - double vts = sqrt(Ts/ms); // Thermal velocity for species s - double vtr = sqrt(Tr/mr); // Thermal velocity for species r + double vts = sqrt(Ts / ms); // Thermal velocity for species s + double vtr = sqrt(Tr / mr); // Thermal velocity for species r double wps = plasma_frequency(ns, ms, eps0, eV); // Plasma Frequency for species s double wpr = plasma_frequency(nr, mr, eps0, eV); // Plasma frequency for species r - double wcs = qs*bmag/ms; // Cyclotron frequency for species s - double wcr = qr*bmag/mr; // Cyclotron frequency for species r - double inner1 = (wps*wps + wcs*wcs)/(Ts/ms + 3*Ts/ms) + (wpr*wpr + wcr*wcr)/(Tr/mr + 3*Ts/ms); - double u = 3*(vts*vts + vtr*vtr); // Relative velocity - double msr = ms*mr/(ms+mr); // Reduced mass - double inner2 = fmax(fabs(qs*qr)/(4*M_PI*eps0*msr*u*u), hbar/(2*sqrt(eV)*msr*u)); - double inner = (1/inner1)*(1/inner2/inner2) + 1; - return 0.5*log(inner); + double wcs = qs * bmag / ms; // Cyclotron frequency for species s + double wcr = qr * bmag / mr; // Cyclotron frequency for species r + double inner1 = (wps * wps + wcs * wcs) / (Ts / ms + 3 * Ts / ms) + + (wpr * wpr + wcr * wcr) / (Tr / mr + 3 * Ts / ms); + double u = 3 * (vts * vts + vtr * vtr); // Relative velocity + double msr = ms * mr / (ms + mr); // Reduced mass + double inner2 = + fmax(fabs(qs * qr) / (4 * M_PI * eps0 * msr * u * u), hbar / (2 * sqrt(eV) * msr * u)); + double inner = (1 / inner1) * (1 / inner2 / inner2) + 1; + return 0.5 * log(inner); } -double gkyl_calc_Morse_alpha_E_const(double ns, double nr, double ms, double mr, double qs, double qr, - double Ts, double Tr, double bmag, double eps0, double hbar, double eV) +double gkyl_calc_Morse_alpha_E_const( + double ns, double nr, double ms, double mr, double qs, double qr, double Ts, double Tr, + double bmag, double eps0, double hbar, double eV +) { - double clog = 0.5*( coulomb_log(ns, nr, ms, mr, Ts, Tr, qs, qr, bmag, eps0, hbar, eV) - +coulomb_log(nr, ns, mr, ms, Tr, Ts, qr, qs, bmag, eps0, hbar, eV) ); - return 2.0*pow(qs*qr,2)*clog/(3.0*pow(2.0*M_PI,1.5)*pow(eps0,2)*ms*mr); + double clog = 0.5 * (coulomb_log(ns, nr, ms, mr, Ts, Tr, qs, qr, bmag, eps0, hbar, eV) + + coulomb_log(nr, ns, mr, ms, Tr, Ts, qr, qs, bmag, eps0, hbar, eV)); + return 2.0 * pow(qs * qr, 2) * clog / (3.0 * pow(2.0 * M_PI, 1.5) * pow(eps0, 2) * ms * mr); } -double gkyl_calc_Morse_alpha_E(double ns, double nr, double ms, double mr, double qs, double qr, - double Ts, double Tr, double bmag, double eps0, double hbar, double eV) +double gkyl_calc_Morse_alpha_E( + double ns, double nr, double ms, double mr, double qs, double qr, double Ts, double Tr, + double bmag, double eps0, double hbar, double eV +) { - double alpha_E_fac = gkyl_calc_Morse_alpha_E_const(ns, nr, ms, mr, qs, qr, Ts, Tr, bmag, eps0, hbar, eV); - return alpha_E_fac * ns * nr / pow(sqrt(Ts/ms+Tr/mr),3.0); + double alpha_E_fac = + gkyl_calc_Morse_alpha_E_const(ns, nr, ms, mr, qs, qr, Ts, Tr, bmag, eps0, hbar, eV); + return alpha_E_fac * ns * nr / pow(sqrt(Ts / ms + Tr / mr), 3.0); } // create range to loop over quadrature points. -static inline struct gkyl_range get_qrange(int dim, int num_quad) { +static inline struct gkyl_range get_qrange(int dim, int num_quad) +{ int qshape[GKYL_MAX_DIM]; - for (int i=0; indim; double ordinates1[num_quad], weights1[num_quad]; @@ -96,25 +109,29 @@ init_quad_values(const struct gkyl_basis *basis, int num_quad, // set ordinates double *ord = gkyl_array_fetch(ordinates_ho, node); - for (int i=0; inum_basis, tot_quad); - for (int n=0; neval(gkyl_array_fetch(ordinates_ho, n), gkyl_array_fetch(basis_at_ords_ho, n)); + } - if (use_gpu) + if (use_gpu) { *basis_at_ords = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis->num_basis, tot_quad); - else + } else { *basis_at_ords = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, tot_quad); + } // copy host array to device array gkyl_array_copy(*weights, weights_ho); @@ -127,9 +144,10 @@ init_quad_values(const struct gkyl_basis *basis, int num_quad, return tot_quad; } -gkyl_spitzer_coll_freq* -gkyl_spitzer_coll_freq_new(const struct gkyl_basis *basis, int num_quad, - double nufrac, double eps0, double hbar, bool use_gpu) +gkyl_spitzer_coll_freq *gkyl_spitzer_coll_freq_new( + const struct gkyl_basis *basis, int num_quad, double nufrac, double eps0, double hbar, + bool use_gpu +) { struct gkyl_spitzer_coll_freq *up = gkyl_malloc(sizeof(struct gkyl_spitzer_coll_freq)); @@ -139,78 +157,82 @@ gkyl_spitzer_coll_freq_new(const struct gkyl_basis *basis, int num_quad, up->use_gpu = use_gpu; // initialize data needed for quadrature - up->tot_quad = init_quad_values(basis, num_quad, &up->weights, - &up->basis_at_ords, use_gpu); + up->tot_quad = init_quad_values(basis, num_quad, &up->weights, &up->basis_at_ords, use_gpu); - if (up->use_gpu) + if (up->use_gpu) { up->fun_at_ords = NULL; - else - up->fun_at_ords = gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad); // Only used in CPU implementation. + } else { + up->fun_at_ords = + gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad); // Only used in CPU implementation. + } up->eps0 = eps0; // Pre-compute time-independent factors for the case in which we calculate // the collision frequency from scratch (instead of normnu). - up->hbar_fac = hbar/(2.0*exp(0.5)); - up->r4pieps0_fac = 1./(4.*M_PI*eps0); - up->nufraceps0_fac = nufrac/(3.*sqrt(pow(2.*M_PI,3))*pow(eps0,2)); - up->cellav_fac = 1./pow(sqrt(2.),up->ndim); - + up->hbar_fac = hbar / (2.0 * exp(0.5)); + up->r4pieps0_fac = 1. / (4. * M_PI * eps0); + up->nufraceps0_fac = nufrac / (3. * sqrt(pow(2. * M_PI, 3)) * pow(eps0, 2)); + up->cellav_fac = 1. / pow(sqrt(2.), up->ndim); + return up; } static void -proj_on_basis(const gkyl_spitzer_coll_freq *up, const struct gkyl_array *fun_at_ords, double* f) +proj_on_basis(const gkyl_spitzer_coll_freq *up, const struct gkyl_array *fun_at_ords, double *f) { int num_basis = up->num_basis; int tot_quad = up->tot_quad; - const double* GKYL_RESTRICT weights = up->weights->data; - const double* GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; - const double* GKYL_RESTRICT func_at_ords = fun_at_ords->data; + const double *GKYL_RESTRICT weights = up->weights->data; + const double *GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; + const double *GKYL_RESTRICT func_at_ords = fun_at_ords->data; - for (int k=0; kbasis_at_ords, qidx); - double vtSqSelf_q=0., m0Other_q=0., vtSqOther_q=0.; - for (int k=0; knum_basis; ++k) { - vtSqSelf_q += vtSqSelf_d[k]*b_ord[k]; - m0Other_q += m0Other_d[k]*b_ord[k]; - vtSqOther_q += vtSqOther_d[k]*b_ord[k]; + double vtSqSelf_q = 0., m0Other_q = 0., vtSqOther_q = 0.; + for (int k = 0; k < up->num_basis; ++k) { + vtSqSelf_q += vtSqSelf_d[k] * b_ord[k]; + m0Other_q += m0Other_d[k] * b_ord[k]; + vtSqOther_q += vtSqOther_d[k] * b_ord[k]; } double *fq = gkyl_array_fetch(up->fun_at_ords, qidx); - if (m0Other_q<0.) { + if (m0Other_q < 0.) { fq[0] = 0.; } else if ((vtSqSelf_q < vtSqMinSelf) && (vtSqOther_q < vtSqMinOther)) { - fq[0] = normNu*m0Other_q/pow(sqrt(vtSqMinSelf+vtSqMinOther),3); + fq[0] = normNu * m0Other_q / pow(sqrt(vtSqMinSelf + vtSqMinOther), 3); } else if (vtSqSelf_q < vtSqMinSelf) { - fq[0] = normNu*m0Other_q/pow(sqrt(vtSqMinSelf+vtSqOther_q),3); + fq[0] = normNu * m0Other_q / pow(sqrt(vtSqMinSelf + vtSqOther_q), 3); } else if (vtSqOther_q < vtSqMinOther) { - fq[0] = normNu*m0Other_q/pow(sqrt(vtSqSelf_q+vtSqMinOther),3); + fq[0] = normNu * m0Other_q / pow(sqrt(vtSqSelf_q + vtSqMinOther), 3); } else { - fq[0] = normNu*m0Other_q/pow(sqrt(vtSqSelf_q+vtSqOther_q),3); + fq[0] = normNu * m0Other_q / pow(sqrt(vtSqSelf_q + vtSqOther_q), 3); } } @@ -218,22 +240,24 @@ calc_nu(const gkyl_spitzer_coll_freq *up, struct gkyl_range qrange, const double proj_on_basis(up, up->fun_at_ords, gkyl_array_fetch(nuOut, linidx)); } -void -gkyl_spitzer_coll_freq_advance_normnu(const gkyl_spitzer_coll_freq *up, - const struct gkyl_range *range, const struct gkyl_array *momsSelf, double vtSqMinSelf, - const struct gkyl_array *momsOther, double vtSqMinOther, - double normNu, struct gkyl_array *nuOut) +void gkyl_spitzer_coll_freq_advance_normnu( + const gkyl_spitzer_coll_freq *up, const struct gkyl_range *range, + const struct gkyl_array *momsSelf, double vtSqMinSelf, const struct gkyl_array *momsOther, + double vtSqMinOther, double normNu, struct gkyl_array *nuOut +) { // Scale project normNu*n_r/(v_ts^2+v_tr^2)^(3/2) onto the basis using // quadrature. #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) - return gkyl_spitzer_coll_freq_advance_normnu_cu(up, range, momsSelf, - vtSqMinSelf, momsOther, vtSqMinOther, normNu, nuOut); + if (up->use_gpu) { + return gkyl_spitzer_coll_freq_advance_normnu_cu( + up, range, momsSelf, vtSqMinSelf, momsOther, vtSqMinOther, normNu, nuOut + ); + } #endif - int vtsq_idx = momsSelf->ncomp-up->num_basis; + int vtsq_idx = momsSelf->ncomp - up->num_basis; // Create range to loop over quadrature points. struct gkyl_range qrange = get_qrange(up->ndim, up->num_quad); @@ -250,17 +274,18 @@ gkyl_spitzer_coll_freq_advance_normnu(const gkyl_spitzer_coll_freq *up, const double *m0Other_d = momsOther_d; const double *vtSqOther_d = &momsOther_d[vtsq_idx]; - calc_nu(up, qrange, vtSqSelf_d, vtSqMinSelf, m0Other_d, vtSqOther_d, vtSqMinOther, normNu, linidx, nuOut); + calc_nu( + up, qrange, vtSqSelf_d, vtSqMinSelf, m0Other_d, vtSqOther_d, vtSqMinOther, normNu, linidx, + nuOut + ); } - } -void -gkyl_spitzer_coll_freq_advance(const gkyl_spitzer_coll_freq *up, - const struct gkyl_range *range, const struct gkyl_array *bmag, - double qSelf, double mSelf, const struct gkyl_array *momsSelf, double vtSqMinSelf, - double qOther, double mOther, const struct gkyl_array *momsOther, double vtSqMinOther, - struct gkyl_array *nuOut) +void gkyl_spitzer_coll_freq_advance( + const gkyl_spitzer_coll_freq *up, const struct gkyl_range *range, const struct gkyl_array *bmag, + double qSelf, double mSelf, const struct gkyl_array *momsSelf, double vtSqMinSelf, double qOther, + double mOther, const struct gkyl_array *momsOther, double vtSqMinOther, struct gkyl_array *nuOut +) { // Compute the Spitzer-like collision frequency // nu_sr = nu_frac * (n_r/m_s)*(1/m_s+1/m_r) @@ -269,14 +294,17 @@ gkyl_spitzer_coll_freq_advance(const gkyl_spitzer_coll_freq *up, // where log(Lambda_sr) is the Coulomb logarithm (see Gkeyll docs). #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) - return gkyl_spitzer_coll_freq_advance_cu(up, range, bmag, qSelf, mSelf, momsSelf, - vtSqMinSelf, qOther, mOther, momsOther, vtSqMinOther, nuOut); + if (up->use_gpu) { + return gkyl_spitzer_coll_freq_advance_cu( + up, range, bmag, qSelf, mSelf, momsSelf, vtSqMinSelf, qOther, mOther, momsOther, vtSqMinOther, + nuOut + ); + } #endif - int vtsq_idx = momsSelf->ncomp-up->num_basis; - double mReduced = 1./(1./mSelf+1./mOther); - double timeConstFac = up->nufraceps0_fac*pow(qSelf*qOther,2)/(mSelf*mReduced); + int vtsq_idx = momsSelf->ncomp - up->num_basis; + double mReduced = 1. / (1. / mSelf + 1. / mOther); + double timeConstFac = up->nufraceps0_fac * pow(qSelf * qOther, 2) / (mSelf * mReduced); // Create range to loop over quadrature points. struct gkyl_range qrange = get_qrange(up->ndim, up->num_quad); @@ -296,41 +324,53 @@ gkyl_spitzer_coll_freq_advance(const gkyl_spitzer_coll_freq *up, const double *vtSqOther_d = &momsOther_d[vtsq_idx]; // Compute the Coulomb logarithm using cell-average values. - double bmagAv = bmag_d[0]*up->cellav_fac; - double m0SelfAv = m0Self_d[0] < 0.? 1.e-14 : m0Self_d[0]*up->cellav_fac; - double vtSqSelfAv = vtSqSelf_d[0] < vtSqMinSelf? vtSqMinSelf*up->cellav_fac : vtSqSelf_d[0]*up->cellav_fac; - double m0OtherAv = m0Other_d[0] < 0.? 1.e-14 : m0Other_d[0]*up->cellav_fac; - double vtSqOtherAv = vtSqOther_d[0] < vtSqMinOther? vtSqMinOther*up->cellav_fac : vtSqOther_d[0]*up->cellav_fac; + double bmagAv = bmag_d[0] * up->cellav_fac; + double m0SelfAv = m0Self_d[0] < 0. ? 1.e-14 : m0Self_d[0] * up->cellav_fac; + double vtSqSelfAv = vtSqSelf_d[0] < vtSqMinSelf ? vtSqMinSelf * up->cellav_fac : + vtSqSelf_d[0] * up->cellav_fac; + double m0OtherAv = m0Other_d[0] < 0. ? 1.e-14 : m0Other_d[0] * up->cellav_fac; + double vtSqOtherAv = vtSqOther_d[0] < vtSqMinOther ? vtSqMinOther * up->cellav_fac : + vtSqOther_d[0] * up->cellav_fac; - double omegaSqSumSelf = m0SelfAv*pow(qSelf,2)/(up->eps0*mSelf)+pow(qSelf*bmagAv/mSelf,2); - double omegaSqSumOther = m0OtherAv*pow(qOther,2)/(up->eps0*mOther)+pow(qOther*bmagAv/mOther,2); + double omegaSqSumSelf = + m0SelfAv * pow(qSelf, 2) / (up->eps0 * mSelf) + pow(qSelf * bmagAv / mSelf, 2); + double omegaSqSumOther = + m0OtherAv * pow(qOther, 2) / (up->eps0 * mOther) + pow(qOther * bmagAv / mOther, 2); - double rmaxSumSelf = omegaSqSumSelf/(vtSqSelfAv+3.*vtSqSelfAv)+omegaSqSumOther/(vtSqOtherAv+3.*vtSqSelfAv); - double rmaxSumOther = omegaSqSumSelf/(vtSqSelfAv+3.*vtSqOtherAv)+omegaSqSumOther/(vtSqOtherAv+3.*vtSqOtherAv); + double rmaxSumSelf = omegaSqSumSelf / (vtSqSelfAv + 3. * vtSqSelfAv) + + omegaSqSumOther / (vtSqOtherAv + 3. * vtSqSelfAv); + double rmaxSumOther = omegaSqSumSelf / (vtSqSelfAv + 3. * vtSqOtherAv) + + omegaSqSumOther / (vtSqOtherAv + 3. * vtSqOtherAv); - double rmaxSelf = 1./sqrt(rmaxSumSelf); - double rmaxOther = 1./sqrt(rmaxSumOther); + double rmaxSelf = 1. / sqrt(rmaxSumSelf); + double rmaxOther = 1. / sqrt(rmaxSumOther); - double uRelSq = 3.*(vtSqOtherAv+vtSqSelfAv); + double uRelSq = 3. * (vtSqOtherAv + vtSqSelfAv); - double rMin = GKYL_MAX2(fabs(qSelf*qOther)*up->r4pieps0_fac/(mReduced*uRelSq), up->hbar_fac/(mReduced*sqrt(uRelSq))); + double rMin = GKYL_MAX2( + fabs(qSelf * qOther) * up->r4pieps0_fac / (mReduced * uRelSq), + up->hbar_fac / (mReduced * sqrt(uRelSq)) + ); - double logLambda = 0.5*(0.5*log(1.+pow(rmaxSelf/rMin,2))+0.5*log(1.+pow(rmaxOther/rMin,2))); + double logLambda = + 0.5 * (0.5 * log(1. + pow(rmaxSelf / rMin, 2)) + 0.5 * log(1. + pow(rmaxOther / rMin, 2))); // Normalized nu (nu missing density and temperature factors). - double normNu = timeConstFac*logLambda; + double normNu = timeConstFac * logLambda; - calc_nu(up, qrange, vtSqSelf_d, vtSqMinSelf, m0Other_d, vtSqOther_d, vtSqMinOther, normNu, linidx, nuOut); + calc_nu( + up, qrange, vtSqSelf_d, vtSqMinSelf, m0Other_d, vtSqOther_d, vtSqMinOther, normNu, linidx, + nuOut + ); } - } -void -gkyl_spitzer_coll_freq_release(gkyl_spitzer_coll_freq* up) +void gkyl_spitzer_coll_freq_release(gkyl_spitzer_coll_freq *up) { gkyl_array_release(up->weights); gkyl_array_release(up->basis_at_ords); - if (!up->use_gpu) + if (!up->use_gpu) { gkyl_array_release(up->fun_at_ords); + } gkyl_free(up); } diff --git a/vlasov/zero/spitzer_coll_freq_cu.cu b/vlasov/zero/spitzer_coll_freq_cu.cu index c02dad3145..36c7b4d8ba 100644 --- a/vlasov/zero/spitzer_coll_freq_cu.cu +++ b/vlasov/zero/spitzer_coll_freq_cu.cu @@ -7,105 +7,108 @@ extern "C" { #include } -GKYL_CU_D void -calc_nu_cu(const struct gkyl_array* GKYL_RESTRICT basis_at_ords, const struct gkyl_array* GKYL_RESTRICT weights, - const double* vtSqSelf_d, double vtSqMinSelf, const double* GKYL_RESTRICT m0Other_d, - const double* vtSqOther_d, double vtSqMinOther, double normNu, long linidx, - struct gkyl_array* GKYL_RESTRICT nuOut) +GKYL_CU_D void calc_nu_cu( + const struct gkyl_array *GKYL_RESTRICT basis_at_ords, + const struct gkyl_array *GKYL_RESTRICT weights, const double *vtSqSelf_d, double vtSqMinSelf, + const double *GKYL_RESTRICT m0Other_d, const double *vtSqOther_d, double vtSqMinOther, + double normNu, long linidx, struct gkyl_array *GKYL_RESTRICT nuOut +) { // Perform the multiplication of normNu*n_r/(v_ts^2+v_tr^2)^(3/2) via // quadrature in one cell. int num_basis = basis_at_ords->ncomp; int tot_quad = basis_at_ords->size; - double *nuOut_d = (double *) gkyl_array_fetch(nuOut, linidx); - for (int k=0; kdata; - const double *bo_d = (const double *) basis_at_ords->data; - - for (int n=0; ndata; + const double *bo_d = (const double *)basis_at_ords->data; - const double *b_ord = (const double *) gkyl_array_cfetch(basis_at_ords, n); + for (int n = 0; n < tot_quad; ++n) { + const double *b_ord = (const double *)gkyl_array_cfetch(basis_at_ords, n); // Evaluate densities and thermal speeds (squared) at quad point. - double vtSqSelf_q=0., m0Other_q=0., vtSqOther_q=0.; - for (int k=0; kncomp-basis_at_ords->ncomp; + int vtsq_idx = momsSelf->ncomp - basis_at_ords->ncomp; int idx[3]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < range.volume; tid += blockDim.x*gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&range, tid, idx); long linidx = gkyl_range_idx(&range, idx); - const double *momsSelf_d = (const double *) gkyl_array_cfetch(momsSelf, linidx); - const double *momsOther_d = (const double *) gkyl_array_cfetch(momsOther, linidx); + const double *momsSelf_d = (const double *)gkyl_array_cfetch(momsSelf, linidx); + const double *momsOther_d = (const double *)gkyl_array_cfetch(momsOther, linidx); const double *vtSqSelf_d = &momsSelf_d[vtsq_idx]; const double *m0Other_d = momsOther_d; const double *vtSqOther_d = &momsOther_d[vtsq_idx]; - calc_nu_cu(basis_at_ords, weights, vtSqSelf_d, vtSqMinSelf, m0Other_d, vtSqOther_d, vtSqMinOther, normNu, linidx, nuOut); + calc_nu_cu( + basis_at_ords, weights, vtSqSelf_d, vtSqMinSelf, m0Other_d, vtSqOther_d, vtSqMinOther, normNu, + linidx, nuOut + ); } } -__global__ static void -gkyl_spitzer_coll_freq_advance_cu_ker(const struct gkyl_range range, - const struct gkyl_array* GKYL_RESTRICT basis_at_ords, const struct gkyl_array* GKYL_RESTRICT weights, - double nufraceps0_fac, double cellav_fac, double r4pieps0_fac, double hbar_fac, double eps0, - const struct gkyl_array* GKYL_RESTRICT bmag, - double qSelf, double mSelf, const struct gkyl_array* momsSelf, double vtSqMinSelf, - double qOther, double mOther, const struct gkyl_array* momsOther, double vtSqMinOther, - struct gkyl_array* GKYL_RESTRICT nuOut) +__global__ static void gkyl_spitzer_coll_freq_advance_cu_ker( + const struct gkyl_range range, const struct gkyl_array *GKYL_RESTRICT basis_at_ords, + const struct gkyl_array *GKYL_RESTRICT weights, double nufraceps0_fac, double cellav_fac, + double r4pieps0_fac, double hbar_fac, double eps0, const struct gkyl_array *GKYL_RESTRICT bmag, + double qSelf, double mSelf, const struct gkyl_array *momsSelf, double vtSqMinSelf, double qOther, + double mOther, const struct gkyl_array *momsOther, double vtSqMinOther, + struct gkyl_array *GKYL_RESTRICT nuOut +) { - int vtsq_idx = momsSelf->ncomp-basis_at_ords->ncomp; - double mReduced = 1./(1./mSelf+1./mOther); - double timeConstFac = nufraceps0_fac*pow(qSelf*qOther,2)/(mSelf*mReduced); + int vtsq_idx = momsSelf->ncomp - basis_at_ords->ncomp; + double mReduced = 1. / (1. / mSelf + 1. / mOther); + double timeConstFac = nufraceps0_fac * pow(qSelf * qOther, 2) / (mSelf * mReduced); int idx[3]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < range.volume; tid += blockDim.x*gridDim.x) { - + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&range, tid, idx); long linidx = gkyl_range_idx(&range, idx); - const double *bmag_d = (const double *) gkyl_array_cfetch(bmag, linidx); - const double *momsSelf_d = (const double *) gkyl_array_cfetch(momsSelf, linidx); - const double *momsOther_d = (const double *) gkyl_array_cfetch(momsOther, linidx); + const double *bmag_d = (const double *)gkyl_array_cfetch(bmag, linidx); + const double *momsSelf_d = (const double *)gkyl_array_cfetch(momsSelf, linidx); + const double *momsOther_d = (const double *)gkyl_array_cfetch(momsOther, linidx); const double *m0Self_d = momsSelf_d; const double *vtSqSelf_d = &momsSelf_d[vtsq_idx]; @@ -113,57 +116,70 @@ gkyl_spitzer_coll_freq_advance_cu_ker(const struct gkyl_range range, const double *vtSqOther_d = &momsOther_d[vtsq_idx]; // Compute the Coulomb logarithm using cell-average values. - double bmagAv = bmag_d[0]*cellav_fac; - double m0SelfAv = m0Self_d[0] < 0.? 1.e-14 : m0Self_d[0]*cellav_fac; - double vtSqSelfAv = vtSqSelf_d[0] < vtSqMinSelf? vtSqMinSelf*cellav_fac : vtSqSelf_d[0]*cellav_fac; - double m0OtherAv = m0Other_d[0] < 0.? 1.e-14 : m0Other_d[0]*cellav_fac; - double vtSqOtherAv = vtSqOther_d[0] < vtSqMinOther? vtSqMinOther*cellav_fac : vtSqOther_d[0]*cellav_fac; + double bmagAv = bmag_d[0] * cellav_fac; + double m0SelfAv = m0Self_d[0] < 0. ? 1.e-14 : m0Self_d[0] * cellav_fac; + double vtSqSelfAv = vtSqSelf_d[0] < vtSqMinSelf ? vtSqMinSelf * cellav_fac : + vtSqSelf_d[0] * cellav_fac; + double m0OtherAv = m0Other_d[0] < 0. ? 1.e-14 : m0Other_d[0] * cellav_fac; + double vtSqOtherAv = vtSqOther_d[0] < vtSqMinOther ? vtSqMinOther * cellav_fac : + vtSqOther_d[0] * cellav_fac; - double omegaSqSumSelf = m0SelfAv*pow(qSelf,2)/(eps0*mSelf)+pow(qSelf*bmagAv/mSelf,2); - double omegaSqSumOther = m0OtherAv*pow(qOther,2)/(eps0*mOther)+pow(qOther*bmagAv/mOther,2); + double omegaSqSumSelf = + m0SelfAv * pow(qSelf, 2) / (eps0 * mSelf) + pow(qSelf * bmagAv / mSelf, 2); + double omegaSqSumOther = + m0OtherAv * pow(qOther, 2) / (eps0 * mOther) + pow(qOther * bmagAv / mOther, 2); - double rmaxSumSelf = omegaSqSumSelf/(vtSqSelfAv+3.*vtSqSelfAv)+omegaSqSumOther/(vtSqOtherAv+3.*vtSqSelfAv); - double rmaxSumOther = omegaSqSumSelf/(vtSqSelfAv+3.*vtSqOtherAv)+omegaSqSumOther/(vtSqOtherAv+3.*vtSqOtherAv); + double rmaxSumSelf = omegaSqSumSelf / (vtSqSelfAv + 3. * vtSqSelfAv) + + omegaSqSumOther / (vtSqOtherAv + 3. * vtSqSelfAv); + double rmaxSumOther = omegaSqSumSelf / (vtSqSelfAv + 3. * vtSqOtherAv) + + omegaSqSumOther / (vtSqOtherAv + 3. * vtSqOtherAv); - double rmaxSelf = 1./sqrt(rmaxSumSelf); - double rmaxOther = 1./sqrt(rmaxSumOther); + double rmaxSelf = 1. / sqrt(rmaxSumSelf); + double rmaxOther = 1. / sqrt(rmaxSumOther); - double uRelSq = 3.*(vtSqOtherAv+vtSqSelfAv); + double uRelSq = 3. * (vtSqOtherAv + vtSqSelfAv); - double rMin = GKYL_MAX2(fabs(qSelf*qOther)*r4pieps0_fac/(mReduced*uRelSq), hbar_fac/(mReduced*sqrt(uRelSq))); + double rMin = GKYL_MAX2( + fabs(qSelf * qOther) * r4pieps0_fac / (mReduced * uRelSq), + hbar_fac / (mReduced * sqrt(uRelSq)) + ); - double logLambda = 0.5*(0.5*log(1.+pow(rmaxSelf/rMin,2))+0.5*log(1.+pow(rmaxOther/rMin,2))); + double logLambda = + 0.5 * (0.5 * log(1. + pow(rmaxSelf / rMin, 2)) + 0.5 * log(1. + pow(rmaxOther / rMin, 2))); // Normalized nu (nu missing density and temperature factors). - double normNu = timeConstFac*logLambda; + double normNu = timeConstFac * logLambda; - calc_nu_cu(basis_at_ords, weights, vtSqSelf_d, vtSqMinSelf, m0Other_d, vtSqOther_d, vtSqMinOther, normNu, linidx, nuOut); + calc_nu_cu( + basis_at_ords, weights, vtSqSelf_d, vtSqMinSelf, m0Other_d, vtSqOther_d, vtSqMinOther, normNu, + linidx, nuOut + ); } } -void -gkyl_spitzer_coll_freq_advance_normnu_cu(const gkyl_spitzer_coll_freq *up, - const struct gkyl_range *range, const struct gkyl_array *momsSelf, double vtSqMinSelf, - const struct gkyl_array *momsOther, double vtSqMinOther, - double normNu, struct gkyl_array *nuOut) +void gkyl_spitzer_coll_freq_advance_normnu_cu( + const gkyl_spitzer_coll_freq *up, const struct gkyl_range *range, + const struct gkyl_array *momsSelf, double vtSqMinSelf, const struct gkyl_array *momsOther, + double vtSqMinOther, double normNu, struct gkyl_array *nuOut +) { int nblocks = range->nblocks, nthreads = range->nthreads; - gkyl_spitzer_coll_freq_advance_normnu_cu_ker<<>> - (*range, up->basis_at_ords->on_dev, up->weights->on_dev, momsSelf->on_dev, vtSqMinSelf, - momsOther->on_dev, vtSqMinOther, normNu, nuOut->on_dev); + gkyl_spitzer_coll_freq_advance_normnu_cu_ker<< > >( + *range, up->basis_at_ords->on_dev, up->weights->on_dev, momsSelf->on_dev, vtSqMinSelf, + momsOther->on_dev, vtSqMinOther, normNu, nuOut->on_dev + ); } -void -gkyl_spitzer_coll_freq_advance_cu(const gkyl_spitzer_coll_freq *up, - const struct gkyl_range *range, const struct gkyl_array *bmag, - double qSelf, double mSelf, const struct gkyl_array *momsSelf, double vtSqMinSelf, - double qOther, double mOther, const struct gkyl_array *momsOther, double vtSqMinOther, - struct gkyl_array *nuOut) +void gkyl_spitzer_coll_freq_advance_cu( + const gkyl_spitzer_coll_freq *up, const struct gkyl_range *range, const struct gkyl_array *bmag, + double qSelf, double mSelf, const struct gkyl_array *momsSelf, double vtSqMinSelf, double qOther, + double mOther, const struct gkyl_array *momsOther, double vtSqMinOther, struct gkyl_array *nuOut +) { int nblocks = range->nblocks, nthreads = range->nthreads; - gkyl_spitzer_coll_freq_advance_cu_ker<<>> - (*range, up->basis_at_ords->on_dev, up->weights->on_dev, - up->nufraceps0_fac, up->cellav_fac, up->r4pieps0_fac, up->hbar_fac, up->eps0, bmag->on_dev, - qSelf, mSelf, momsSelf->on_dev, vtSqMinSelf, - qOther, mOther, momsOther->on_dev, vtSqMinOther, nuOut->on_dev); + gkyl_spitzer_coll_freq_advance_cu_ker<< > >( + *range, up->basis_at_ords->on_dev, up->weights->on_dev, up->nufraceps0_fac, up->cellav_fac, + up->r4pieps0_fac, up->hbar_fac, up->eps0, bmag->on_dev, qSelf, mSelf, momsSelf->on_dev, + vtSqMinSelf, qOther, mOther, momsOther->on_dev, vtSqMinOther, nuOut->on_dev + ); } diff --git a/vlasov/zero/velocity_map.c b/vlasov/zero/velocity_map.c index eb6c97716d..a965cc521c 100644 --- a/vlasov/zero/velocity_map.c +++ b/vlasov/zero/velocity_map.c @@ -17,23 +17,25 @@ struct mapc2p_vel_identity_ctx { // Comp. coords = phys. coords mapping (default). static inline void -mapc2p_vel_identity(double t, const double *zc, double* GKYL_RESTRICT vp, void *ctx) +mapc2p_vel_identity(double t, const double *zc, double *GKYL_RESTRICT vp, void *ctx) { struct mapc2p_vel_identity_ctx *identity_ctx = ctx; int vdim = identity_ctx->vdim; - for (int d=0; dvmap_basis); - else + } else { gkyl_cart_modal_basis_release(gvm->vmap_basis); + } #else gkyl_cart_modal_basis_release(gvm->vmap_basis); #endif @@ -43,17 +45,18 @@ gkyl_velocity_map_free(const struct gkyl_ref_count *ref) gkyl_array_release(gvm->jacobvel); gkyl_array_release(gvm->vmap_ho); - if (gkyl_velocity_map_is_cu_dev(gvm)) + if (gkyl_velocity_map_is_cu_dev(gvm)) { gkyl_cu_free(gvm->on_dev); + } gkyl_free(gvm); } -struct gkyl_velocity_map* -gkyl_velocity_map_new(struct gkyl_mapc2p_inp mapc2p_in, - struct gkyl_rect_grid grid, struct gkyl_rect_grid grid_vel, - struct gkyl_range local, struct gkyl_range local_ext, - struct gkyl_range local_vel, struct gkyl_range local_ext_vel, bool use_gpu) +struct gkyl_velocity_map *gkyl_velocity_map_new( + struct gkyl_mapc2p_inp mapc2p_in, struct gkyl_rect_grid grid, struct gkyl_rect_grid grid_vel, + struct gkyl_range local, struct gkyl_range local_ext, struct gkyl_range local_vel, + struct gkyl_range local_ext_vel, bool use_gpu +) { struct gkyl_velocity_map *gvm = gkyl_malloc(sizeof(*gvm)); @@ -81,56 +84,57 @@ gkyl_velocity_map_new(struct gkyl_mapc2p_inp mapc2p_in, // Need a host copy of vmap_basis for some IC projection options. gkyl_cart_modal_serendip(&gvm->vmap_basis_ho, 1, vmap_poly_order); - gvm->vmap = mkarr(false, vdim*gvm->vmap_basis->num_basis, gvm->local_ext_vel.volume); - gvm->vmap_sq = mkarr(false, vdim*vmap_sq_basis.num_basis, gvm->local_ext_vel.volume); + gvm->vmap = mkarr(false, vdim * gvm->vmap_basis->num_basis, gvm->local_ext_vel.volume); + gvm->vmap_sq = mkarr(false, vdim * vmap_sq_basis.num_basis, gvm->local_ext_vel.volume); gvm->vmap_prime = mkarr(false, vdim, gvm->local_ext_vel.volume); - gvm->jacobvel = mkarr(false, 1, gvm->local_ext.volume); + gvm->jacobvel = mkarr(false, 1, gvm->local_ext.volume); // Need a host copy of vmap for some IC setting options. - gvm->vmap_ho = gkyl_array_acquire(gvm->vmap); + gvm->vmap_ho = gkyl_array_acquire(gvm->vmap); // Project the velocity mapping (onto a vdim basis). - struct gkyl_array *vmap_vdim = mkarr(false, vdim*vmap_basis_vdim.num_basis, gvm->vmap->size); + struct gkyl_array *vmap_vdim = mkarr(false, vdim * vmap_basis_vdim.num_basis, gvm->vmap->size); struct gkyl_array *vmapc1 = mkarr(false, 1, gvm->vmap->size); gkyl_eval_on_nodes *evup; if (gvm->is_identity) { - struct mapc2p_vel_identity_ctx identity_ctx = { .vdim = vdim }; - evup = gkyl_eval_on_nodes_new(&gvm->grid_vel, &vmap_basis_vdim, - vdim, mapc2p_vel_identity, &identity_ctx); - } - else { - evup = gkyl_eval_on_nodes_new(&gvm->grid_vel, &vmap_basis_vdim, - vdim, mapc2p_in.mapping, mapc2p_in.ctx); + struct mapc2p_vel_identity_ctx identity_ctx = {.vdim = vdim}; + evup = gkyl_eval_on_nodes_new( + &gvm->grid_vel, &vmap_basis_vdim, vdim, mapc2p_vel_identity, &identity_ctx + ); + } else { + evup = gkyl_eval_on_nodes_new( + &gvm->grid_vel, &vmap_basis_vdim, vdim, mapc2p_in.mapping, mapc2p_in.ctx + ); } gkyl_eval_on_nodes_advance(evup, 0., &gvm->local_vel, vmap_vdim); // Extract the 1D basis expansions from the vdim basis expansion. - for (int d=0; dvmap_basis->num_basis; int numb_vdim = vmap_basis_vdim.num_basis; - gkyl_array_set_offset(vmapc1, 1./sqrt(vdim), vmap_vdim, d*numb_vdim); - gkyl_array_set_offset(gvm->vmap, 1., vmapc1, d*numb_1d); - gkyl_array_set_offset(vmapc1, 1./sqrt(vdim), vmap_vdim, d*numb_vdim+d+1); - gkyl_array_set_offset(gvm->vmap, 1., vmapc1, d*numb_1d+1); + gkyl_array_set_offset(vmapc1, 1. / sqrt(vdim), vmap_vdim, d * numb_vdim); + gkyl_array_set_offset(gvm->vmap, 1., vmapc1, d * numb_1d); + gkyl_array_set_offset(vmapc1, 1. / sqrt(vdim), vmap_vdim, d * numb_vdim + d + 1); + gkyl_array_set_offset(gvm->vmap, 1., vmapc1, d * numb_1d + 1); } gkyl_eval_on_nodes_release(evup); gkyl_array_release(vmapc1); gkyl_array_release(vmap_vdim); - struct gkyl_array *vmap1d = mkarr(false, gvm->vmap_basis->num_basis, gvm->vmap->size); - struct gkyl_array *vmap1d_p2 = mkarr(false, vmap_sq_basis.num_basis, gvm->vmap->size); + struct gkyl_array *vmap1d = mkarr(false, gvm->vmap_basis->num_basis, gvm->vmap->size); + struct gkyl_array *vmap1d_p2 = mkarr(false, vmap_sq_basis.num_basis, gvm->vmap->size); struct gkyl_array *vmap_prime1d = mkarr(false, 1, gvm->vmap_prime->size); gkyl_array_clear(vmap1d_p2, 0.); - for (int d=0; dvmap, d*gvm->vmap_basis->num_basis); + for (int d = 0; d < vdim; d++) { + gkyl_array_set_offset(vmap1d, 1., gvm->vmap, d * gvm->vmap_basis->num_basis); // Compute the square mapping via weak multiplication. gkyl_array_set_offset(vmap1d_p2, 1., vmap1d, 0); gkyl_dg_mul_op(&vmap_sq_basis, d, gvm->vmap_sq, 0, vmap1d_p2, 0, vmap1d_p2); // Compute the derivative of the mapping. - gkyl_array_set_offset(vmap_prime1d, sqrt(6.)/gvm->grid_vel.dx[d], vmap1d, 1); + gkyl_array_set_offset(vmap_prime1d, sqrt(6.) / gvm->grid_vel.dx[d], vmap1d, 1); gkyl_array_set_offset(gvm->vmap_prime, 1., vmap_prime1d, d); } gkyl_array_release(vmap1d); @@ -146,11 +150,14 @@ gkyl_velocity_map_new(struct gkyl_mapc2p_inp mapc2p_in, jacv_d[0] = 1.; int vidx[vdim]; - for (int d=0; dlocal_vel, vidx); double *vprime_d = gkyl_array_fetch(gvm->vmap_prime, vlinidx); - for (int d=0; dflags); } -void -gkyl_velocity_map_write(const struct gkyl_velocity_map* gvm, struct gkyl_comm* species_comm, - const char* app_name, const char* species_name) +void gkyl_velocity_map_write( + const struct gkyl_velocity_map *gvm, struct gkyl_comm *species_comm, const char *app_name, + const char *species_name +) { // Write out the velocity space mapping. struct gkyl_array *vmap_ho = gvm->vmap_ho, *jacobvel_ho = gvm->jacobvel; @@ -195,7 +202,7 @@ gkyl_velocity_map_write(const struct gkyl_velocity_map* gvm, struct gkyl_comm* s // Write out the velocity mapping. const char *fmt0 = "%s-%s_mapc2p_vel.gkyl"; sz = gkyl_calc_strlen(fmt0, app_name, species_name); - char fileNm0[sz+1]; // ensures no buffer overflow + char fileNm0[sz + 1]; // ensures no buffer overflow snprintf(fileNm0, sizeof fileNm0, fmt0, app_name, species_name); gkyl_grid_sub_array_write(&gvm->grid_vel, &gvm->local_vel, NULL, vmap_ho, fileNm0); } @@ -203,7 +210,7 @@ gkyl_velocity_map_write(const struct gkyl_velocity_map* gvm, struct gkyl_comm* s // Write out the velocity space Jacobian. const char *fmt1 = "%s-%s_jacobvel.gkyl"; sz = gkyl_calc_strlen(fmt1, app_name, species_name); - char fileNm1[sz+1]; // ensures no buffer overflow + char fileNm1[sz + 1]; // ensures no buffer overflow snprintf(fileNm1, sizeof fileNm1, fmt1, app_name, species_name); gkyl_comm_array_write(species_comm, &gvm->grid, &gvm->local, NULL, jacobvel_ho, fileNm1); @@ -212,79 +219,85 @@ gkyl_velocity_map_write(const struct gkyl_velocity_map* gvm, struct gkyl_comm* s } } -void -gkyl_velocity_map_get_boundary_values(const struct gkyl_velocity_map* gvm, double *vbounds) +void gkyl_velocity_map_get_boundary_values(const struct gkyl_velocity_map *gvm, double *vbounds) { int vdim = gvm->local_vel.ndim; - for (int d=0; dvmap_basis_ho.num_basis; + int off = d * gvm->vmap_basis_ho.num_basis; vlog[0] = -1.0; vlinidx = gkyl_range_idx(&gvm->local_vel, gvm->local_vel.lower); vmap_d = gkyl_array_fetch(gvm->vmap_ho, vlinidx); - vbounds[d] = gvm->vmap_basis_ho.eval_expand(vlog, off+vmap_d); + vbounds[d] = gvm->vmap_basis_ho.eval_expand(vlog, off + vmap_d); vlog[0] = 1.0; vlinidx = gkyl_range_idx(&gvm->local_vel, gvm->local_vel.upper); vmap_d = gkyl_array_fetch(gvm->vmap_ho, vlinidx); - vbounds[d + vdim] = gvm->vmap_basis_ho.eval_expand(vlog, off+vmap_d); + vbounds[d + vdim] = gvm->vmap_basis_ho.eval_expand(vlog, off + vmap_d); } } -void -gkyl_velocity_map_reduce_dv_range(const struct gkyl_velocity_map* gvm, enum gkyl_array_op op, - double *dv_m, struct gkyl_range range_vel) +void gkyl_velocity_map_reduce_dv_range( + const struct gkyl_velocity_map *gvm, enum gkyl_array_op op, double *dv_m, + struct gkyl_range range_vel +) { int vdim = gvm->local_vel.ndim; - if (op == GKYL_MIN) - for (int d=0; dvmap_ho, linidx); - for (int d=0; dvmap_basis_ho.num_basis; + for (int d = 0; d < vdim; ++d) { + int off = d * gvm->vmap_basis_ho.num_basis; double vlog[1]; vlog[0] = -1.0; - double vlo = gvm->vmap_basis_ho.eval_expand(vlog, off+vmap_d); + double vlo = gvm->vmap_basis_ho.eval_expand(vlog, off + vmap_d); vlog[0] = 1.0; - double vup = gvm->vmap_basis_ho.eval_expand(vlog, off+vmap_d); + double vup = gvm->vmap_basis_ho.eval_expand(vlog, off + vmap_d); double dv = vup - vlo; - if (op == GKYL_MIN) + if (op == GKYL_MIN) { dv_m[d] = GKYL_MIN2(dv_m[d], dv); - else if (op == GKYL_MAX) + } else if (op == GKYL_MAX) { dv_m[d] = GKYL_MAX2(dv_m[d], dv); + } } } } -void -gkyl_velocity_map_reduce_dv(const struct gkyl_velocity_map* gvm, enum gkyl_array_op op, double *dv_m) +void gkyl_velocity_map_reduce_dv( + const struct gkyl_velocity_map *gvm, enum gkyl_array_op op, double *dv_m +) { gkyl_velocity_map_reduce_dv_range(gvm, op, dv_m, gvm->local_vel); } -void -gkyl_velocity_map_eval_c2p(const struct gkyl_velocity_map* gvm, const double *zc, double *vp) +void gkyl_velocity_map_eval_c2p(const struct gkyl_velocity_map *gvm, const double *zc, double *vp) { // Find the index of the cell containing zc. int idx_zc[GKYL_MAX_VDIM]; - for(int d = 0; dlocal_ext_vel.ndim; d++){ - int idx = gvm->local_ext_vel.lower[d] + (int) floor((zc[d] - (gvm->grid_vel.lower[d]) )/gvm->grid_vel.dx[d]); + for (int d = 0; d < gvm->local_ext_vel.ndim; d++) { + int idx = gvm->local_ext_vel.lower[d] + + (int)floor((zc[d] - (gvm->grid_vel.lower[d])) / gvm->grid_vel.dx[d]); // Bound idx to the range in the grid. If it falls outside of that is due // to floating point arithmetic, or due to an error in the code. idx = GKYL_MIN2(idx, gvm->local_ext_vel.upper[d]); @@ -299,23 +312,21 @@ gkyl_velocity_map_eval_c2p(const struct gkyl_velocity_map* gvm, const double *zc double zc_cc[GKYL_MAX_VDIM]; gkyl_rect_grid_cell_center(&gvm->grid_vel, idx_zc, zc_cc); - for(int d=0; dlocal_ext_vel.ndim; d++){ + for (int d = 0; d < gvm->local_ext_vel.ndim; d++) { // Convert computational to logical coord. - double zlog[] = {(zc[d] - zc_cc[d]) / (0.5*gvm->grid_vel.dx[d])}; + double zlog[] = {(zc[d] - zc_cc[d]) / (0.5 * gvm->grid_vel.dx[d])}; // Evaluate vmap expansion at logical coord. - vp[d] = gvm->vmap_basis_ho.eval_expand(zlog, &vmap_c[d*gvm->vmap_basis_ho.num_basis]); + vp[d] = gvm->vmap_basis_ho.eval_expand(zlog, &vmap_c[d * gvm->vmap_basis_ho.num_basis]); } } -struct gkyl_velocity_map* -gkyl_velocity_map_acquire(const struct gkyl_velocity_map* gvm) +struct gkyl_velocity_map *gkyl_velocity_map_acquire(const struct gkyl_velocity_map *gvm) { gkyl_ref_count_inc(&gvm->ref_count); - return (struct gkyl_velocity_map*) gvm; + return (struct gkyl_velocity_map *)gvm; } -void -gkyl_velocity_map_release(const struct gkyl_velocity_map *gvm) +void gkyl_velocity_map_release(const struct gkyl_velocity_map *gvm) { gkyl_ref_count_dec(&gvm->ref_count); } diff --git a/vlasov/zero/velocity_map_cu.cu b/vlasov/zero/velocity_map_cu.cu index 0ddd9c95d9..43c8153cb3 100644 --- a/vlasov/zero/velocity_map_cu.cu +++ b/vlasov/zero/velocity_map_cu.cu @@ -7,41 +7,41 @@ extern "C" { #include } -struct gkyl_velocity_map* gkyl_velocity_map_new_cu_dev(struct gkyl_velocity_map *gvm_ho) +struct gkyl_velocity_map *gkyl_velocity_map_new_cu_dev(struct gkyl_velocity_map *gvm_ho) { - struct gkyl_velocity_map *gvm = (struct gkyl_velocity_map *) gkyl_malloc(sizeof(*gvm)); + struct gkyl_velocity_map *gvm = (struct gkyl_velocity_map *)gkyl_malloc(sizeof(*gvm)); - gvm->is_identity = gvm_ho->is_identity; - gvm->grid = gvm_ho->grid; - gvm->grid_vel = gvm_ho->grid_vel; - gvm->local = gvm_ho->local; - gvm->local_ext = gvm_ho->local_ext; - gvm->local_vel = gvm_ho->local_vel; + gvm->is_identity = gvm_ho->is_identity; + gvm->grid = gvm_ho->grid; + gvm->grid_vel = gvm_ho->grid_vel; + gvm->local = gvm_ho->local; + gvm->local_ext = gvm_ho->local_ext; + gvm->local_vel = gvm_ho->local_vel; gvm->local_ext_vel = gvm_ho->local_ext_vel; gvm->vmap_basis_ho = gvm_ho->vmap_basis_ho; - memcpy(gvm->vbounds, gvm_ho->vbounds, sizeof(double[2*GKYL_MAX_VDIM])); + memcpy(gvm->vbounds, gvm_ho->vbounds, sizeof(double[2 * GKYL_MAX_VDIM])); // Copy the host-side initialized object to the device. - struct gkyl_array *vmap = mkarr(true, gvm_ho->vmap ->ncomp, gvm_ho->vmap ->size); - struct gkyl_array *vmap_sq = mkarr(true, gvm_ho->vmap_sq ->ncomp, gvm_ho->vmap_sq ->size); + struct gkyl_array *vmap = mkarr(true, gvm_ho->vmap->ncomp, gvm_ho->vmap->size); + struct gkyl_array *vmap_sq = mkarr(true, gvm_ho->vmap_sq->ncomp, gvm_ho->vmap_sq->size); struct gkyl_array *vmap_prime = mkarr(true, gvm_ho->vmap_prime->ncomp, gvm_ho->vmap_prime->size); - struct gkyl_array *jacobvel = mkarr(true, gvm_ho->jacobvel ->ncomp, gvm_ho->jacobvel ->size); - struct gkyl_basis *vmap_basis = gkyl_cart_modal_serendip_cu_dev_new(gvm_ho->vmap_basis->ndim, - gvm_ho->vmap_basis->poly_order); + struct gkyl_array *jacobvel = mkarr(true, gvm_ho->jacobvel->ncomp, gvm_ho->jacobvel->size); + struct gkyl_basis *vmap_basis = + gkyl_cart_modal_serendip_cu_dev_new(gvm_ho->vmap_basis->ndim, gvm_ho->vmap_basis->poly_order); // Need a host copy of vmap for some IC projection options. - struct gkyl_array *vmap_ho = mkarr(false, gvm_ho->vmap ->ncomp, gvm_ho->vmap ->size); + struct gkyl_array *vmap_ho = mkarr(false, gvm_ho->vmap->ncomp, gvm_ho->vmap->size); - gkyl_array_copy(vmap , gvm_ho->vmap ); - gkyl_array_copy(vmap_sq , gvm_ho->vmap_sq ); + gkyl_array_copy(vmap, gvm_ho->vmap); + gkyl_array_copy(vmap_sq, gvm_ho->vmap_sq); gkyl_array_copy(vmap_prime, gvm_ho->vmap_prime); - gkyl_array_copy(jacobvel , gvm_ho->jacobvel ); - gkyl_array_copy(vmap_ho , gvm_ho->vmap_ho ); + gkyl_array_copy(jacobvel, gvm_ho->jacobvel); + gkyl_array_copy(vmap_ho, gvm_ho->vmap_ho); - gvm->vmap = vmap ->on_dev; - gvm->vmap_sq = vmap_sq ->on_dev; + gvm->vmap = vmap->on_dev; + gvm->vmap_sq = vmap_sq->on_dev; gvm->vmap_prime = vmap_prime->on_dev; - gvm->jacobvel = jacobvel ->on_dev; - gvm->vmap_ho = vmap ->on_dev; // MF 2024/05/06: I think this is safer. + gvm->jacobvel = jacobvel->on_dev; + gvm->vmap_ho = vmap->on_dev; // MF 2024/05/06: I think this is safer. gvm->vmap_basis = vmap_basis; gvm->flags = 0; @@ -49,16 +49,16 @@ struct gkyl_velocity_map* gkyl_velocity_map_new_cu_dev(struct gkyl_velocity_map gvm->ref_count = gkyl_ref_count_init(gkyl_velocity_map_free); // Initialize the device object. - struct gkyl_velocity_map *gvm_cu = (struct gkyl_velocity_map*) gkyl_cu_malloc(sizeof(*gvm_cu)); + struct gkyl_velocity_map *gvm_cu = (struct gkyl_velocity_map *)gkyl_cu_malloc(sizeof(*gvm_cu)); gkyl_cu_memcpy(gvm_cu, gvm, sizeof(struct gkyl_velocity_map), GKYL_CU_MEMCPY_H2D); gvm->on_dev = gvm_cu; // The returned object should store host pointers to gkyl_arrays. - gvm->vmap = vmap ; - gvm->vmap_sq = vmap_sq ; + gvm->vmap = vmap; + gvm->vmap_sq = vmap_sq; gvm->vmap_prime = vmap_prime; - gvm->jacobvel = jacobvel ; - gvm->vmap_ho = vmap_ho ; + gvm->jacobvel = jacobvel; + gvm->vmap_ho = vmap_ho; return gvm; } diff --git a/vlasov/zero/vlasov_lte_correct.c b/vlasov/zero/vlasov_lte_correct.c index d6da34be4b..72ae2cef43 100644 --- a/vlasov/zero/vlasov_lte_correct.c +++ b/vlasov/zero/vlasov_lte_correct.c @@ -14,7 +14,7 @@ #include -struct gkyl_vlasov_lte_correct* +struct gkyl_vlasov_lte_correct * gkyl_vlasov_lte_correct_inew(const struct gkyl_vlasov_lte_correct_inp *inp) { gkyl_vlasov_lte_correct *up = gkyl_malloc(sizeof(*up)); @@ -33,38 +33,43 @@ gkyl_vlasov_lte_correct_inew(const struct gkyl_vlasov_lte_correct_inp *inp) // (n, V_drift, T/m) being corrected // If the model is SR, V_drift is the spatial component of the four-velocity u_i = GammaV*V_drift int vdim = inp->phase_basis->ndim - inp->conf_basis->ndim; - up->num_comp = vdim+2; + up->num_comp = vdim + 2; long conf_local_ncells = inp->conf_range->volume; long conf_local_ext_ncells = inp->conf_range_ext->volume; // Individual moment memory: the iteration of the moments, the differences (d) and differences of differences (dd) if (up->use_gpu) { - up->moms_iter = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_comp*up->num_conf_basis, conf_local_ext_ncells); - up->d_moms = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_comp*up->num_conf_basis, conf_local_ext_ncells); - up->dd_moms = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_comp*up->num_conf_basis, conf_local_ext_ncells); - // Two additional GPU-specific allocations for iterating over the grid to find the absolute value of + up->moms_iter = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_comp * up->num_conf_basis, conf_local_ext_ncells); + up->d_moms = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_comp * up->num_conf_basis, conf_local_ext_ncells); + up->dd_moms = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_comp * up->num_conf_basis, conf_local_ext_ncells); + // Two additional GPU-specific allocations for iterating over the grid to find the absolute value of // the difference between the target and iterative moments, and the GPU-side array for performing the // thread-safe reduction to find the maximum error on the grid. up->abs_diff_moms = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_comp, conf_local_ext_ncells); up->error_cu = gkyl_cu_malloc(sizeof(double[up->num_comp])); + } else { + up->moms_iter = + gkyl_array_new(GKYL_DOUBLE, up->num_comp * up->num_conf_basis, conf_local_ext_ncells); + up->d_moms = + gkyl_array_new(GKYL_DOUBLE, up->num_comp * up->num_conf_basis, conf_local_ext_ncells); + up->dd_moms = + gkyl_array_new(GKYL_DOUBLE, up->num_comp * up->num_conf_basis, conf_local_ext_ncells); } - else { - up->moms_iter = gkyl_array_new(GKYL_DOUBLE, up->num_comp*up->num_conf_basis, conf_local_ext_ncells); - up->d_moms = gkyl_array_new(GKYL_DOUBLE, up->num_comp*up->num_conf_basis, conf_local_ext_ncells); - up->dd_moms = gkyl_array_new(GKYL_DOUBLE, up->num_comp*up->num_conf_basis, conf_local_ext_ncells); - } - // Allocate host-side error for checking convergence and returning in the status object + // Allocate host-side error for checking convergence and returning in the status object up->error = gkyl_malloc(sizeof(double[up->num_comp])); - // Moments structure + // Moments structure struct gkyl_vlasov_lte_moments_inp inp_mom = { .phase_grid = inp->phase_grid, .vel_grid = inp->vel_grid, .conf_basis = inp->conf_basis, .vel_basis = inp->vel_basis, .phase_basis = inp->phase_basis, - .conf_range = inp->conf_range, + .conf_range = inp->conf_range, .conf_range_ext = inp->conf_range_ext, .vel_range = inp->vel_range, .phase_range = inp->phase_range, @@ -75,12 +80,12 @@ gkyl_vlasov_lte_correct_inew(const struct gkyl_vlasov_lte_correct_inp *inp) .det_h = inp->det_h, .hamil = inp->hamil, .model_id = inp->model_id, - .use_gpu = inp->use_gpu, + .use_gpu = inp->use_gpu }; - up->moments_up = gkyl_vlasov_lte_moments_inew( &inp_mom ); + up->moments_up = gkyl_vlasov_lte_moments_inew(&inp_mom); // Create a projection updater for projecting the LTE distribution function - // Projection routine also corrects the density before returning + // Projection routine also corrects the density before returning // the LTE distribution function. struct gkyl_vlasov_lte_proj_on_basis_inp inp_proj = { .phase_grid = inp->phase_grid, @@ -96,25 +101,25 @@ gkyl_vlasov_lte_correct_inew(const struct gkyl_vlasov_lte_correct_inp *inp) .gamma_inv = inp->gamma_inv, .quad_type = inp->quad_type, .h_ij = inp->h_ij, - .h_ij_inv = inp->h_ij_inv, + .h_ij_inv = inp->h_ij_inv, .det_h = inp->det_h, .hamil = inp->hamil, .model_id = inp->model_id, - .use_gpu = inp->use_gpu, + .use_gpu = inp->use_gpu }; - up->proj_lte = gkyl_vlasov_lte_proj_on_basis_inew( &inp_proj ); + up->proj_lte = gkyl_vlasov_lte_proj_on_basis_inew(&inp_proj); return up; } -struct gkyl_vlasov_lte_correct_status -gkyl_vlasov_lte_correct_all_moments(gkyl_vlasov_lte_correct *up, - struct gkyl_array *f_lte, const struct gkyl_array *moms_target, - const struct gkyl_range *phase_local, const struct gkyl_range *conf_local) +struct gkyl_vlasov_lte_correct_status gkyl_vlasov_lte_correct_all_moments( + gkyl_vlasov_lte_correct *up, struct gkyl_array *f_lte, const struct gkyl_array *moms_target, + const struct gkyl_range *phase_local, const struct gkyl_range *conf_local +) { int num_comp = up->num_comp; int nc = up->num_conf_basis; - double tol = up->eps; // tolerance of the iterative scheme + double tol = up->eps; // tolerance of the iterative scheme int max_iter = up->max_iter; int niter = 0; @@ -123,7 +128,7 @@ gkyl_vlasov_lte_correct_all_moments(gkyl_vlasov_lte_correct *up, // Set initial max error to start the iteration. double max_error = 1.0; - for (int i=0; ierror[i] = 1.0; } // Copy the initial max error to GPU so initial error is set correctly (no uninitialized values). @@ -154,52 +159,62 @@ gkyl_vlasov_lte_correct_all_moments(gkyl_vlasov_lte_correct *up, if ((niter % 1) == 0) { if (up->use_gpu) { // We insure the reduction to find the maximum error is thread-safe on GPUs - // by first calling a specialized kernel for computing the absolute value + // by first calling a specialized kernel for computing the absolute value // of the difference of the cell averages, then calling reduce_range. - gkyl_vlasov_lte_correct_all_moments_abs_diff_cu(conf_local, - num_comp, nc, moms_target, up->moms_iter, up->abs_diff_moms); + gkyl_vlasov_lte_correct_all_moments_abs_diff_cu( + conf_local, num_comp, nc, moms_target, up->moms_iter, up->abs_diff_moms + ); gkyl_array_reduce_range(up->error_cu, up->abs_diff_moms, GKYL_MAX, conf_local); gkyl_cu_memcpy(up->error, up->error_cu, sizeof(double[num_comp]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { struct gkyl_range_iter biter; // Reset the maximum error - for (int i=0; ierror[i] = 0.0; } // Iterate over the input configuration-space range to find the maximum error gkyl_range_iter_init(&biter, conf_local); - while (gkyl_range_iter_next(&biter)){ + while (gkyl_range_iter_next(&biter)) { long midx = gkyl_range_idx(conf_local, biter.idx); const double *moms_local = gkyl_array_cfetch(up->moms_iter, midx); const double *moms_target_local = gkyl_array_cfetch(moms_target, midx); // Check the error in the absolute value of the cell average // Note: for density and temperature, this error is a relative error compared to the target moment value // so that we can converge to the correct target moments in SI units and minimize finite precision issues. - up->error[0] = fmax(fabs(moms_local[0*nc] - moms_target_local[0*nc])/moms_target_local[0*nc],fabs(up->error[0])); - int T_idx = num_comp-1; // T/m is always the last component - up->error[T_idx] = fmax(fabs(moms_local[T_idx*nc] - moms_target_local[T_idx*nc])/moms_target_local[T_idx*nc],fabs(up->error[T_idx])); + up->error[0] = fmax( + fabs(moms_local[0 * nc] - moms_target_local[0 * nc]) / moms_target_local[0 * nc], + fabs(up->error[0]) + ); + int T_idx = num_comp - 1; // T/m is always the last component + up->error[T_idx] = fmax( + fabs(moms_local[T_idx * nc] - moms_target_local[T_idx * nc]) / + moms_target_local[T_idx * nc], + fabs(up->error[T_idx]) + ); // However, V_drift may be ~ 0 and if it is, we need to use absolute error. We can converge safely using - // absolute error if V_drift ~ O(1). Otherwise, we use relative error for V_drift. - for (int d=1; derror[d] = fmax(fabs(moms_local[d*nc] - moms_target_local[d*nc]),fabs(up->error[d])); + // absolute error if V_drift ~ O(1). Otherwise, we use relative error for V_drift. + for (int d = 1; d < num_comp - 1; ++d) { + if (fabs(moms_target_local[d * nc]) < 1.0) { + up->error[d] = + fmax(fabs(moms_local[d * nc] - moms_target_local[d * nc]), fabs(up->error[d])); + } else { + up->error[d] = fmax( + fabs(moms_local[d * nc] - moms_target_local[d * nc]) / moms_target_local[d * nc], + fabs(up->error[d]) + ); } - else { - up->error[d] = fmax(fabs(moms_local[d*nc] - moms_target_local[d*nc])/moms_target_local[d*nc],fabs(up->error[d])); - } } // Check if density and temperature are positive, if they aren't we will break out of the iteration - ispositive_f_lte = (moms_local[0*nc] > 0.0) && ispositive_f_lte; - ispositive_f_lte = (moms_local[T_idx*nc] > 0.0) && ispositive_f_lte; + ispositive_f_lte = (moms_local[0 * nc] > 0.0) && ispositive_f_lte; + ispositive_f_lte = (moms_local[T_idx * nc] > 0.0) && ispositive_f_lte; } } } // Find the maximum error looping over the error in each component - max_error = 0.0; // reset maximum error - for (int d=0; derror[d]); } @@ -210,16 +225,16 @@ gkyl_vlasov_lte_correct_all_moments(gkyl_vlasov_lte_correct *up, // 2. Update the LTE distribution function using the corrected moments. // Projection routine also corrects the density before the next iteration. - gkyl_vlasov_lte_proj_on_basis_advance(up->proj_lte, - phase_local, conf_local, up->moms_iter, f_lte); + gkyl_vlasov_lte_proj_on_basis_advance( + up->proj_lte, phase_local, conf_local, up->moms_iter, f_lte + ); niter += 1; } if ((niter < max_iter) && (ispositive_f_lte) && (max_error < tol)) { corr_status = 0; - } - else { + } else { corr_status = 1; } @@ -227,48 +242,57 @@ gkyl_vlasov_lte_correct_all_moments(gkyl_vlasov_lte_correct *up, // we project the distribution function with the target moments. // We correct the density and then recompute moments/errors for this new projection. if (corr_status == 1 && !up->use_last_converged) { - gkyl_vlasov_lte_proj_on_basis_advance(up->proj_lte, - phase_local, conf_local, moms_target, f_lte); + gkyl_vlasov_lte_proj_on_basis_advance(up->proj_lte, phase_local, conf_local, moms_target, f_lte); gkyl_vlasov_lte_moments_advance(up->moments_up, phase_local, conf_local, f_lte, up->moms_iter); if (up->use_gpu) { // We insure the reduction to find the maximum error is thread-safe on GPUs - // by first calling a specialized kernel for computing the absolute value + // by first calling a specialized kernel for computing the absolute value // of the difference of the cell averages, then calling reduce_range. - gkyl_vlasov_lte_correct_all_moments_abs_diff_cu(conf_local, - num_comp, nc, moms_target, up->moms_iter, up->abs_diff_moms); + gkyl_vlasov_lte_correct_all_moments_abs_diff_cu( + conf_local, num_comp, nc, moms_target, up->moms_iter, up->abs_diff_moms + ); gkyl_array_reduce_range(up->error_cu, up->abs_diff_moms, GKYL_MAX, conf_local); gkyl_cu_memcpy(up->error, up->error_cu, sizeof(double[num_comp]), GKYL_CU_MEMCPY_D2H); - } - else { + } else { struct gkyl_range_iter biter; // Reset the maximum error - for (int i=0; ierror[i] = 0.0; } // Iterate over the input configuration-space range to find the maximum error gkyl_range_iter_init(&biter, conf_local); - while (gkyl_range_iter_next(&biter)){ + while (gkyl_range_iter_next(&biter)) { long midx = gkyl_range_idx(conf_local, biter.idx); const double *moms_local = gkyl_array_cfetch(up->moms_iter, midx); const double *moms_target_local = gkyl_array_cfetch(moms_target, midx); // Check the error in the absolute value of the cell average // Note: for density and temperature, this error is a relative error compared to the target moment value. - up->error[0] = fmax(fabs(moms_local[0*nc] - moms_target_local[0*nc])/moms_target_local[0*nc], fabs(up->error[0])); - int T_idx = num_comp-1; // T/m is always the last component - up->error[T_idx] = fmax(fabs(moms_local[T_idx*nc] - moms_target_local[T_idx*nc])/moms_target_local[T_idx*nc], fabs(up->error[T_idx])); - - // However, V_drift may be ~ 0 and if it is, we need to use absolute error. - // Otherwise, we use relative error for V_drift. - for (int d=1; derror[d] = fmax(fabs(moms_local[d*nc] - moms_target_local[d*nc]), fabs(up->error[d])); + up->error[0] = fmax( + fabs(moms_local[0 * nc] - moms_target_local[0 * nc]) / moms_target_local[0 * nc], + fabs(up->error[0]) + ); + int T_idx = num_comp - 1; // T/m is always the last component + up->error[T_idx] = fmax( + fabs(moms_local[T_idx * nc] - moms_target_local[T_idx * nc]) / + moms_target_local[T_idx * nc], + fabs(up->error[T_idx]) + ); + + // However, V_drift may be ~ 0 and if it is, we need to use absolute error. + // Otherwise, we use relative error for V_drift. + for (int d = 1; d < num_comp - 1; ++d) { + if (fabs(moms_target_local[d * nc]) < 1.0) { + up->error[d] = + fmax(fabs(moms_local[d * nc] - moms_target_local[d * nc]), fabs(up->error[d])); + } else { + up->error[d] = fmax( + fabs(moms_local[d * nc] - moms_target_local[d * nc]) / moms_target_local[d * nc], + fabs(up->error[d]) + ); } - else { - up->error[d] = fmax(fabs(moms_local[d*nc] - moms_target_local[d*nc])/moms_target_local[d*nc], fabs(up->error[d])); - } } } } @@ -277,14 +301,13 @@ gkyl_vlasov_lte_correct_all_moments(gkyl_vlasov_lte_correct *up, struct gkyl_vlasov_lte_correct_status status; status.iter_converged = corr_status; status.num_iter = niter; - for (int i=0; ierror[i]; } return status; } -void -gkyl_vlasov_lte_correct_release(gkyl_vlasov_lte_correct *up) +void gkyl_vlasov_lte_correct_release(gkyl_vlasov_lte_correct *up) { if (up->vel_map != 0) { gkyl_velocity_map_release(up->vel_map); @@ -307,11 +330,10 @@ gkyl_vlasov_lte_correct_release(gkyl_vlasov_lte_correct *up) #ifndef GKYL_HAVE_CUDA -void -gkyl_vlasov_lte_correct_all_moments_abs_diff_cu(const struct gkyl_range *conf_range, - int num_comp, int nc, - const struct gkyl_array *moms_target, const struct gkyl_array *moms_iter, - struct gkyl_array *moms_abs_diff) +void gkyl_vlasov_lte_correct_all_moments_abs_diff_cu( + const struct gkyl_range *conf_range, int num_comp, int nc, const struct gkyl_array *moms_target, + const struct gkyl_array *moms_iter, struct gkyl_array *moms_abs_diff +) { assert(false); } diff --git a/vlasov/zero/vlasov_lte_correct_cu.cu b/vlasov/zero/vlasov_lte_correct_cu.cu index 0ac80bb956..82a75e8cc6 100644 --- a/vlasov/zero/vlasov_lte_correct_cu.cu +++ b/vlasov/zero/vlasov_lte_correct_cu.cu @@ -6,8 +6,9 @@ extern "C" { #include } -static void -gkyl_parallelize_components_kernel_launch_dims(dim3* dimGrid, dim3* dimBlock, gkyl_range range, int ncomp) +static void gkyl_parallelize_components_kernel_launch_dims( + dim3 *dimGrid, dim3 *dimBlock, gkyl_range range, int ncomp +) { // Create a 2D thread grid so we launch ncomp*range.volume number of threads and can parallelize over components too dimBlock->y = ncomp; @@ -16,21 +17,18 @@ gkyl_parallelize_components_kernel_launch_dims(dim3* dimGrid, dim3* dimBlock, gk dimGrid->x = gkyl_int_div_up(range.volume, dimBlock->x); } -__global__ static void -gkyl_vlasov_lte_correct_all_moments_abs_diff_cu_ker(struct gkyl_range conf_range, - int num_comp, int nc, - const struct gkyl_array *moms_target, const struct gkyl_array *moms_iter, - struct gkyl_array *abs_diff_moms) +__global__ static void gkyl_vlasov_lte_correct_all_moments_abs_diff_cu_ker( + struct gkyl_range conf_range, int num_comp, int nc, const struct gkyl_array *moms_target, + const struct gkyl_array *moms_iter, struct gkyl_array *abs_diff_moms +) { int idx[GKYL_MAX_DIM]; // 2D thread grid - // linc2 = c where c is the component index - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; - for (unsigned long linc1 = threadIdx.x + blockIdx.x*blockDim.x; - linc1 < conf_range.volume; - linc1 += gridDim.x*blockDim.x) - { + // linc2 = c where c is the component index + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; + for (unsigned long linc1 = threadIdx.x + blockIdx.x * blockDim.x; linc1 < conf_range.volume; + linc1 += gridDim.x * blockDim.x) { // inverse index from linc1 to idx // must use gkyl_sub_range_inv_idx so that linc1=0 maps to idx={1,1,...} // since update_range is a subrange @@ -40,33 +38,33 @@ gkyl_vlasov_lte_correct_all_moments_abs_diff_cu_ker(struct gkyl_range conf_range // linc will have jumps in it to jump over ghost cells long loc = gkyl_range_idx(&conf_range, idx); - const double *moms_local = (const double*) gkyl_array_cfetch(moms_iter, loc); - const double *moms_target_local = (const double*) gkyl_array_cfetch(moms_target, loc); - double *abs_diff_moms_local = (double*) gkyl_array_fetch(abs_diff_moms, loc); + const double *moms_local = (const double *)gkyl_array_cfetch(moms_iter, loc); + const double *moms_target_local = (const double *)gkyl_array_cfetch(moms_target, loc); + double *abs_diff_moms_local = (double *)gkyl_array_fetch(abs_diff_moms, loc); - // Compute the absolute value of the difference of cell averages + // Compute the absolute value of the difference of cell averages // Note: max error found by follow-up thread-safe reduction operation // Also: for density and temperature, this error is a relative error compared to the target moment value // so that we can converge to the correct target moments in SI units and minimize finite precision issues. // However, V_drift may be ~ 0 and if it is, we need to use absolute error. We can converge safely using - // absolute error if V_drift ~ O(1). Otherwise, we use relative error for V_drift. - if (linc2 != 0 && linc2 != num_comp-1 && moms_target_local[linc2*nc] < 1.0) { - abs_diff_moms_local[linc2] = fabs(moms_local[linc2*nc] - moms_target_local[linc2*nc]); - } - else { - abs_diff_moms_local[linc2] = fabs(moms_local[linc2*nc] - moms_target_local[linc2*nc])/moms_target_local[linc2*nc]; + // absolute error if V_drift ~ O(1). Otherwise, we use relative error for V_drift. + if (linc2 != 0 && linc2 != num_comp - 1 && moms_target_local[linc2 * nc] < 1.0) { + abs_diff_moms_local[linc2] = fabs(moms_local[linc2 * nc] - moms_target_local[linc2 * nc]); + } else { + abs_diff_moms_local[linc2] = fabs(moms_local[linc2 * nc] - moms_target_local[linc2 * nc]) / + moms_target_local[linc2 * nc]; } } } -void -gkyl_vlasov_lte_correct_all_moments_abs_diff_cu(const struct gkyl_range *conf_range, - int num_comp, int nc, - const struct gkyl_array *moms_target, const struct gkyl_array *moms_iter, - struct gkyl_array *moms_abs_diff) +void gkyl_vlasov_lte_correct_all_moments_abs_diff_cu( + const struct gkyl_range *conf_range, int num_comp, int nc, const struct gkyl_array *moms_target, + const struct gkyl_array *moms_iter, struct gkyl_array *moms_abs_diff +) { dim3 dimGrid, dimBlock; gkyl_parallelize_components_kernel_launch_dims(&dimGrid, &dimBlock, *conf_range, num_comp); - gkyl_vlasov_lte_correct_all_moments_abs_diff_cu_ker<<>>(*conf_range, - num_comp, nc, moms_target->on_dev, moms_iter->on_dev, moms_abs_diff->on_dev); + gkyl_vlasov_lte_correct_all_moments_abs_diff_cu_ker<< > >( + *conf_range, num_comp, nc, moms_target->on_dev, moms_iter->on_dev, moms_abs_diff->on_dev + ); } \ No newline at end of file diff --git a/vlasov/zero/vlasov_lte_moments.c b/vlasov/zero/vlasov_lte_moments.c index 6e0b82ad25..ed03226f2c 100644 --- a/vlasov/zero/vlasov_lte_moments.c +++ b/vlasov/zero/vlasov_lte_moments.c @@ -15,7 +15,7 @@ #include -struct gkyl_vlasov_lte_moments* +struct gkyl_vlasov_lte_moments * gkyl_vlasov_lte_moments_inew(const struct gkyl_vlasov_lte_moments_inp *inp) { gkyl_vlasov_lte_moments *up = gkyl_malloc(sizeof(*up)); @@ -31,17 +31,19 @@ gkyl_vlasov_lte_moments_inew(const struct gkyl_vlasov_lte_moments_inp *inp) if (inp->use_gpu) { up->M0 = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); - up->M1i = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->vdim*up->num_conf_basis, conf_local_ext_ncells); - up->V_drift = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->vdim*up->num_conf_basis, conf_local_ext_ncells); - up->V_drift_dot_M1i = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); + up->M1i = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->vdim * up->num_conf_basis, conf_local_ext_ncells); + up->V_drift = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->vdim * up->num_conf_basis, conf_local_ext_ncells); + up->V_drift_dot_M1i = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); up->pressure = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); up->temperature = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); up->mem = gkyl_dg_bin_op_mem_cu_dev_new(conf_local_ncells, up->num_conf_basis); - } - else { + } else { up->M0 = gkyl_array_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); - up->M1i = gkyl_array_new(GKYL_DOUBLE, up->vdim*up->num_conf_basis, conf_local_ext_ncells); - up->V_drift = gkyl_array_new(GKYL_DOUBLE, up->vdim*up->num_conf_basis, conf_local_ext_ncells); + up->M1i = gkyl_array_new(GKYL_DOUBLE, up->vdim * up->num_conf_basis, conf_local_ext_ncells); + up->V_drift = gkyl_array_new(GKYL_DOUBLE, up->vdim * up->num_conf_basis, conf_local_ext_ncells); up->V_drift_dot_M1i = gkyl_array_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); up->pressure = gkyl_array_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); up->temperature = gkyl_array_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); @@ -52,203 +54,227 @@ gkyl_vlasov_lte_moments_inew(const struct gkyl_vlasov_lte_moments_inp *inp) // spatial components of the four-velocity squared, u_i^2 = (GammaV*V_drift)^2 // and bulk four-velocity Lorentz boost factor GammaV = sqrt(1 + |u_i|^2) and its square if (inp->use_gpu) { - up->V_drift_sq = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->vdim*up->num_conf_basis, conf_local_ext_ncells); + up->V_drift_sq = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->vdim * up->num_conf_basis, conf_local_ext_ncells); up->GammaV = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); up->GammaV_sq = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); - } - else { - up->V_drift_sq = gkyl_array_new(GKYL_DOUBLE, up->vdim*up->num_conf_basis, conf_local_ext_ncells); + } else { + up->V_drift_sq = + gkyl_array_new(GKYL_DOUBLE, up->vdim * up->num_conf_basis, conf_local_ext_ncells); up->GammaV = gkyl_array_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); up->GammaV_sq = gkyl_array_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); } - up->gamma = gkyl_array_acquire(inp->gamma); - up->gamma_inv = gkyl_array_acquire(inp->gamma_inv); - up->sr_vars = gkyl_dg_calc_sr_vars_new(inp->phase_grid, inp->vel_grid, - inp->conf_basis, inp->vel_basis, inp->conf_range, inp->vel_range, inp->use_gpu); + up->gamma = gkyl_array_acquire(inp->gamma); + up->gamma_inv = gkyl_array_acquire(inp->gamma_inv); + up->sr_vars = gkyl_dg_calc_sr_vars_new( + inp->phase_grid, inp->vel_grid, inp->conf_basis, inp->vel_basis, inp->conf_range, + inp->vel_range, inp->use_gpu + ); - // Set auxiliary fields for moment updates. - struct gkyl_mom_vlasov_sr_auxfields sr_inp = {.gamma = inp->gamma}; + // Set auxiliary fields for moment updates. + struct gkyl_mom_vlasov_sr_auxfields sr_inp = {.gamma = inp->gamma}; // Moment calculator for needed moments (M0, M1i) - up->M0_calc = gkyl_dg_updater_moment_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->vel_range, inp->phase_range, up->model_id, &sr_inp, GKYL_F_MOMENT_M0, false, inp->use_gpu); - up->M1i_calc = gkyl_dg_updater_moment_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->vel_range, inp->phase_range, up->model_id, &sr_inp, GKYL_F_MOMENT_M1, false, inp->use_gpu); - } - else if (up->model_id == GKYL_MODEL_CANONICAL_PB) { + up->M0_calc = gkyl_dg_updater_moment_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->vel_range, + inp->phase_range, up->model_id, &sr_inp, GKYL_F_MOMENT_M0, false, inp->use_gpu + ); + up->M1i_calc = gkyl_dg_updater_moment_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->vel_range, + inp->phase_range, up->model_id, &sr_inp, GKYL_F_MOMENT_M1, false, inp->use_gpu + ); + } else if (up->model_id == GKYL_MODEL_CANONICAL_PB) { up->h_ij = gkyl_array_acquire(inp->h_ij); up->h_ij_inv = gkyl_array_acquire(inp->h_ij_inv); up->det_h = gkyl_array_acquire(inp->det_h); if (inp->use_gpu) { - up->energy_moment = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); - up->M1i_cov = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->vdim*up->num_conf_basis, conf_local_ext_ncells); - up->V_drift_cov = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->vdim*up->num_conf_basis, conf_local_ext_ncells); - } - else { + up->energy_moment = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); + up->M1i_cov = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->vdim * up->num_conf_basis, conf_local_ext_ncells); + up->V_drift_cov = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->vdim * up->num_conf_basis, conf_local_ext_ncells); + } else { up->energy_moment = gkyl_array_new(GKYL_DOUBLE, up->num_conf_basis, conf_local_ext_ncells); - up->M1i_cov = gkyl_array_new(GKYL_DOUBLE, up->vdim*up->num_conf_basis, conf_local_ext_ncells); - up->V_drift_cov = gkyl_array_new(GKYL_DOUBLE, up->vdim*up->num_conf_basis, conf_local_ext_ncells); + up->M1i_cov = + gkyl_array_new(GKYL_DOUBLE, up->vdim * up->num_conf_basis, conf_local_ext_ncells); + up->V_drift_cov = + gkyl_array_new(GKYL_DOUBLE, up->vdim * up->num_conf_basis, conf_local_ext_ncells); } - up->can_pb_vars = gkyl_dg_calc_canonical_pb_vars_new(inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->use_gpu); - struct gkyl_mom_canonical_pb_auxfields can_pb_inp = {.hamil = inp->hamil}; + up->can_pb_vars = gkyl_dg_calc_canonical_pb_vars_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->use_gpu + ); + struct gkyl_mom_canonical_pb_auxfields can_pb_inp = {.hamil = inp->hamil}; // Moment calculator for needed moments (M0, M1i, and M2) // Temperature moment is modified by can-pb, requires computing g^{ij}w_iw_j kernel // Note: auxiliary field input is NULL (not used by non-relativistic simulations) - up->M0_calc = gkyl_dg_updater_moment_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->vel_range, inp->phase_range, up->model_id, 0, GKYL_F_MOMENT_M0, false, inp->use_gpu); - up->M1i_calc = gkyl_dg_updater_moment_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->vel_range, inp->phase_range, up->model_id, &can_pb_inp, GKYL_F_MOMENT_M1_FROM_H, false, inp->use_gpu); - up->Pcalc = gkyl_dg_updater_moment_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->vel_range, inp->phase_range, up->model_id, &can_pb_inp, GKYL_F_MOMENT_ENERGY, false, inp->use_gpu); - } - else { + up->M0_calc = gkyl_dg_updater_moment_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->vel_range, + inp->phase_range, up->model_id, 0, GKYL_F_MOMENT_M0, false, inp->use_gpu + ); + up->M1i_calc = gkyl_dg_updater_moment_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->vel_range, + inp->phase_range, up->model_id, &can_pb_inp, GKYL_F_MOMENT_M1_FROM_H, false, inp->use_gpu + ); + up->Pcalc = gkyl_dg_updater_moment_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->vel_range, + inp->phase_range, up->model_id, &can_pb_inp, GKYL_F_MOMENT_ENERGY, false, inp->use_gpu + ); + } else { // Moment calculator for needed moments (M0, M1i, and M2 for non-relativistic) // Note: auxiliary field input is NULL (not used by non-relativistic simulations) - up->M0_calc = gkyl_dg_updater_moment_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->vel_range, inp->phase_range, up->model_id, 0, GKYL_F_MOMENT_M0, false, inp->use_gpu); - up->M1i_calc = gkyl_dg_updater_moment_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->vel_range, inp->phase_range, up->model_id, 0, GKYL_F_MOMENT_M1, false, inp->use_gpu); - up->Pcalc = gkyl_dg_updater_moment_new(inp->phase_grid, inp->conf_basis, - inp->phase_basis, inp->conf_range, inp->vel_range, inp->phase_range, up->model_id, 0, GKYL_F_MOMENT_M2, false, inp->use_gpu); + up->M0_calc = gkyl_dg_updater_moment_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->vel_range, + inp->phase_range, up->model_id, 0, GKYL_F_MOMENT_M0, false, inp->use_gpu + ); + up->M1i_calc = gkyl_dg_updater_moment_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->vel_range, + inp->phase_range, up->model_id, 0, GKYL_F_MOMENT_M1, false, inp->use_gpu + ); + up->Pcalc = gkyl_dg_updater_moment_new( + inp->phase_grid, inp->conf_basis, inp->phase_basis, inp->conf_range, inp->vel_range, + inp->phase_range, up->model_id, 0, GKYL_F_MOMENT_M2, false, inp->use_gpu + ); } return up; } -void -gkyl_vlasov_lte_density_moment_advance(struct gkyl_vlasov_lte_moments *lte_moms, - const struct gkyl_range *phase_local, const struct gkyl_range *conf_local, - const struct gkyl_array *fin, struct gkyl_array *density_out) +void gkyl_vlasov_lte_density_moment_advance( + struct gkyl_vlasov_lte_moments *lte_moms, const struct gkyl_range *phase_local, + const struct gkyl_range *conf_local, const struct gkyl_array *fin, struct gkyl_array *density_out +) { // compute lab frame moment M0 - gkyl_dg_updater_moment_advance(lte_moms->M0_calc, phase_local, conf_local, - fin, lte_moms->M0); + gkyl_dg_updater_moment_advance(lte_moms->M0_calc, phase_local, conf_local, fin, lte_moms->M0); - // If we are relativistic, compute M1i and find the rest-frame density + // If we are relativistic, compute M1i and find the rest-frame density // n = Gamma_inv*M0 where Gamma_inv = sqrt(1 - |V_drift|^2) and V_drift = M1i/M0 if (lte_moms->model_id == GKYL_MODEL_SR) { - gkyl_dg_updater_moment_advance(lte_moms->M1i_calc, phase_local, conf_local, - fin, lte_moms->M1i); - gkyl_dg_calc_sr_vars_n(lte_moms->sr_vars, - lte_moms->M0, lte_moms->M1i, density_out); - } - else { + gkyl_dg_updater_moment_advance(lte_moms->M1i_calc, phase_local, conf_local, fin, lte_moms->M1i); + gkyl_dg_calc_sr_vars_n(lte_moms->sr_vars, lte_moms->M0, lte_moms->M1i, density_out); + } else { gkyl_array_set_range(density_out, 1.0, lte_moms->M0, conf_local); } } -void -gkyl_vlasov_lte_moments_advance(struct gkyl_vlasov_lte_moments *lte_moms, - const struct gkyl_range *phase_local, const struct gkyl_range *conf_local, - const struct gkyl_array *fin, struct gkyl_array *moms_out) +void gkyl_vlasov_lte_moments_advance( + struct gkyl_vlasov_lte_moments *lte_moms, const struct gkyl_range *phase_local, + const struct gkyl_range *conf_local, const struct gkyl_array *fin, struct gkyl_array *moms_out +) { int vdim = lte_moms->vdim; int num_conf_basis = lte_moms->num_conf_basis; // compute lab frame moments M0 and M1i - gkyl_dg_updater_moment_advance(lte_moms->M0_calc, phase_local, conf_local, - fin, lte_moms->M0); - gkyl_dg_updater_moment_advance(lte_moms->M1i_calc, phase_local, conf_local, - fin, lte_moms->M1i); + gkyl_dg_updater_moment_advance(lte_moms->M0_calc, phase_local, conf_local, fin, lte_moms->M0); + gkyl_dg_updater_moment_advance(lte_moms->M1i_calc, phase_local, conf_local, fin, lte_moms->M1i); if (lte_moms->model_id == GKYL_MODEL_SR) { // If we are relativistic, first compute rest-frame density n = Gamma_inv*M0, // Gamma_inv = sqrt(1 - |V_drift|^2), and V_drift = M1i/M0 (using weak division). // Done as a separate operator for robustness checks which insure V_drift < c. - gkyl_dg_calc_sr_vars_n(lte_moms->sr_vars, - lte_moms->M0, lte_moms->M1i, moms_out); + gkyl_dg_calc_sr_vars_n(lte_moms->sr_vars, lte_moms->M0, lte_moms->M1i, moms_out); // Isolate spatial component of the bulk four-velocity u_i = M1i/n = GammaV*V_drift // We store the output in the common V_drift array since we return the spatial - // component of the bulk four-velocity in the LTE moms array in relativity. + // component of the bulk four-velocity in the LTE moms array in relativity. for (int d = 0; d < vdim; ++d) { - gkyl_dg_div_op_range(lte_moms->mem, <e_moms->conf_basis, - d, lte_moms->V_drift, - d, lte_moms->M1i, 0, moms_out, conf_local); + gkyl_dg_div_op_range( + lte_moms->mem, <e_moms->conf_basis, d, lte_moms->V_drift, d, lte_moms->M1i, 0, moms_out, + conf_local + ); } - // Compute needed quantities for pressure velocity moment including + // Compute needed quantities for pressure velocity moment including // bulk four-velocity Lorentz boost factor GammaV = sqrt(1 + |u_i|^2) - gkyl_dg_calc_sr_vars_GammaV(lte_moms->sr_vars, conf_local, - lte_moms->V_drift, lte_moms->V_drift_sq, - lte_moms->GammaV, lte_moms->GammaV_sq); + gkyl_dg_calc_sr_vars_GammaV( + lte_moms->sr_vars, conf_local, lte_moms->V_drift, lte_moms->V_drift_sq, lte_moms->GammaV, + lte_moms->GammaV_sq + ); // Compute the pressure moment. // This moment is computed *in the stationary frame* with the appropriate weight. - // We find computing this moment *in the stationary frame* to be more accurate than - // computing the lab frame moment and then Lorentz transforming to the stationary frame. - gkyl_dg_calc_sr_vars_pressure(lte_moms->sr_vars, - conf_local, phase_local, - lte_moms->gamma, lte_moms->gamma_inv, - lte_moms->V_drift, lte_moms->V_drift_sq, - lte_moms->GammaV, lte_moms->GammaV_sq, - fin, lte_moms->pressure); - } - else { + // We find computing this moment *in the stationary frame* to be more accurate than + // computing the lab frame moment and then Lorentz transforming to the stationary frame. + gkyl_dg_calc_sr_vars_pressure( + lte_moms->sr_vars, conf_local, phase_local, lte_moms->gamma, lte_moms->gamma_inv, + lte_moms->V_drift, lte_moms->V_drift_sq, lte_moms->GammaV, lte_moms->GammaV_sq, fin, + lte_moms->pressure + ); + } else { // Isolate drift velocity by dividing M1i by M0 // (For Canonical-pb only: This actually computes Jv*nv/(Jv*n) eliminating Jn) for (int d = 0; d < vdim; ++d) { - gkyl_dg_div_op_range(lte_moms->mem, <e_moms->conf_basis, - d, lte_moms->V_drift, - d, lte_moms->M1i, 0, lte_moms->M0, conf_local); + gkyl_dg_div_op_range( + lte_moms->mem, <e_moms->conf_basis, d, lte_moms->V_drift, d, lte_moms->M1i, 0, + lte_moms->M0, conf_local + ); } // For non-relativistic Can-pb only if (lte_moms->model_id == GKYL_MODEL_CANONICAL_PB) { - // M1i computes contravariant u^i, covert here to covariant u_i // u_i = h_{ij}u^i (where V_drift = u^i, M1i = Jnu^i) // This functions converts both V_drift and M1i to covariant components - gkyl_canonical_pb_contra_to_covariant_m1i(lte_moms->can_pb_vars, conf_local, lte_moms->h_ij, - lte_moms->V_drift, lte_moms->M1i, lte_moms->V_drift_cov, lte_moms->M1i_cov); + gkyl_canonical_pb_contra_to_covariant_m1i( + lte_moms->can_pb_vars, conf_local, lte_moms->h_ij, lte_moms->V_drift, lte_moms->M1i, + lte_moms->V_drift_cov, lte_moms->M1i_cov + ); // Compute MEnergy - gkyl_dg_updater_moment_advance(lte_moms->Pcalc, phase_local, conf_local, - fin, lte_moms->energy_moment); + gkyl_dg_updater_moment_advance( + lte_moms->Pcalc, phase_local, conf_local, fin, lte_moms->energy_moment + ); // Take covaraint momentum components and M1i components - // Solve for d*P*Jv: d*P*Jv = 2*E - n*h^{ij}*u_i*u_j - // = 2*E - h^{ij}*M1_i*V_drift_j - gkyl_canonical_pb_pressure(lte_moms->can_pb_vars, conf_local, lte_moms->h_ij_inv, lte_moms->energy_moment, - lte_moms->V_drift_cov, lte_moms->M1i_cov, lte_moms->pressure); - } - else if (lte_moms->model_id == GKYL_MODEL_CANONICAL_PB_GR) { - + // Solve for d*P*Jv: d*P*Jv = 2*E - n*h^{ij}*u_i*u_j + // = 2*E - h^{ij}*M1_i*V_drift_j + gkyl_canonical_pb_pressure( + lte_moms->can_pb_vars, conf_local, lte_moms->h_ij_inv, lte_moms->energy_moment, + lte_moms->V_drift_cov, lte_moms->M1i_cov, lte_moms->pressure + ); + } else if (lte_moms->model_id == GKYL_MODEL_CANONICAL_PB_GR) { // Current no pressure/temperature or energy moments are defined for the // GR can-pb species assert(false); - } - else { + } else { // Compute the lab frame M2 = vdim*P/m + V_drift dot M1i. - gkyl_dg_updater_moment_advance(lte_moms->Pcalc, phase_local, conf_local, - fin, lte_moms->pressure); + gkyl_dg_updater_moment_advance( + lte_moms->Pcalc, phase_local, conf_local, fin, lte_moms->pressure + ); // Subtract off V_drift dot M1i from total M2 gkyl_array_clear(lte_moms->V_drift_dot_M1i, 0.0); - gkyl_dg_dot_product_op_range(<e_moms->conf_basis, - lte_moms->V_drift_dot_M1i, lte_moms->V_drift, lte_moms->M1i, conf_local); - gkyl_array_accumulate_range(lte_moms->pressure, -1.0, - lte_moms->V_drift_dot_M1i, conf_local); + gkyl_dg_dot_product_op_range( + <e_moms->conf_basis, lte_moms->V_drift_dot_M1i, lte_moms->V_drift, lte_moms->M1i, + conf_local + ); + gkyl_array_accumulate_range(lte_moms->pressure, -1.0, lte_moms->V_drift_dot_M1i, conf_local); } - // Rescale pressure by 1.0/vdim and set the first component of moms_out to be the density. - gkyl_array_scale(lte_moms->pressure, 1.0/vdim); + // Rescale pressure by 1.0/vdim and set the first component of moms_out to be the density. + gkyl_array_scale(lte_moms->pressure, 1.0 / vdim); gkyl_array_set_range(moms_out, 1.0, lte_moms->M0, conf_local); } - // ( T/m = P/(mn) ) - gkyl_dg_div_op_range(lte_moms->mem, <e_moms->conf_basis, - 0, lte_moms->temperature, - 0, lte_moms->pressure, 0, moms_out, conf_local); + // ( T/m = P/(mn) ) + gkyl_dg_div_op_range( + lte_moms->mem, <e_moms->conf_basis, 0, lte_moms->temperature, 0, lte_moms->pressure, 0, + moms_out, conf_local + ); // Save the outputs to moms_out (n, V_drift, T/m): - if (lte_moms->model_id == GKYL_MODEL_CANONICAL_PB || lte_moms->model_id == GKYL_MODEL_CANONICAL_PB_GR) { - gkyl_array_set_offset_range(moms_out, 1.0, lte_moms->V_drift_cov, 1*num_conf_basis, conf_local); + if (lte_moms->model_id == GKYL_MODEL_CANONICAL_PB || + lte_moms->model_id == GKYL_MODEL_CANONICAL_PB_GR) { + gkyl_array_set_offset_range( + moms_out, 1.0, lte_moms->V_drift_cov, 1 * num_conf_basis, conf_local + ); + } else { + gkyl_array_set_offset_range(moms_out, 1.0, lte_moms->V_drift, 1 * num_conf_basis, conf_local); } - else { - gkyl_array_set_offset_range(moms_out, 1.0, lte_moms->V_drift, 1*num_conf_basis, conf_local); - } - gkyl_array_set_offset_range(moms_out, 1.0, lte_moms->temperature, (vdim+1)*num_conf_basis, conf_local); + gkyl_array_set_offset_range( + moms_out, 1.0, lte_moms->temperature, (vdim + 1) * num_conf_basis, conf_local + ); } -void -gkyl_vlasov_lte_moments_release(gkyl_vlasov_lte_moments *lte_moms) +void gkyl_vlasov_lte_moments_release(gkyl_vlasov_lte_moments *lte_moms) { gkyl_array_release(lte_moms->M0); gkyl_array_release(lte_moms->M1i); @@ -264,9 +290,8 @@ gkyl_vlasov_lte_moments_release(gkyl_vlasov_lte_moments *lte_moms) gkyl_array_release(lte_moms->GammaV_sq); gkyl_array_release(lte_moms->gamma); gkyl_array_release(lte_moms->gamma_inv); - } - else if (lte_moms->model_id == GKYL_MODEL_CANONICAL_PB - || lte_moms->model_id == GKYL_MODEL_CANONICAL_PB_GR) { + } else if (lte_moms->model_id == GKYL_MODEL_CANONICAL_PB || + lte_moms->model_id == GKYL_MODEL_CANONICAL_PB_GR) { gkyl_array_release(lte_moms->h_ij); gkyl_array_release(lte_moms->h_ij_inv); gkyl_array_release(lte_moms->det_h); @@ -274,7 +299,7 @@ gkyl_vlasov_lte_moments_release(gkyl_vlasov_lte_moments *lte_moms) gkyl_dg_calc_canonical_pb_vars_release(lte_moms->can_pb_vars); gkyl_array_release(lte_moms->M1i_cov); gkyl_array_release(lte_moms->V_drift_cov); - } + } gkyl_dg_updater_moment_release(lte_moms->M0_calc); gkyl_dg_updater_moment_release(lte_moms->M1i_calc); diff --git a/vlasov/zero/vlasov_lte_proj_on_basis.c b/vlasov/zero/vlasov_lte_proj_on_basis.c index 14918aa8c8..77c974e039 100644 --- a/vlasov/zero/vlasov_lte_proj_on_basis.c +++ b/vlasov/zero/vlasov_lte_proj_on_basis.c @@ -17,8 +17,12 @@ static inline struct gkyl_range get_qrange(int cdim, int dim, int num_quad, int num_quad_v, bool *is_vdim_p2) { int qshape[GKYL_MAX_DIM]; - for (int i=0; indim; - int vdim = ndim-cdim; + int vdim = ndim - cdim; int num_quad_v = num_quad; // hybrid basis have p=2 in velocity space. - bool is_vdim_p2[] = {false, false, false}; // 3 is the max vdim. + bool is_vdim_p2[] = {false, false, false}; // 3 is the max vdim. if (basis->b_type == GKYL_BASIS_MODAL_HYBRID) { - num_quad_v = num_quad+1; - for (int d=0; dnum_basis, tot_quad); if (use_gpu) { *basis_at_ords = gkyl_array_cu_dev_new(GKYL_DOUBLE, basis->num_basis, tot_quad); - } - else { + } else { *basis_at_ords = gkyl_array_new(GKYL_DOUBLE, basis->num_basis, tot_quad); } - for (int n=0; neval(gkyl_array_fetch(ordinates_ho, n), gkyl_array_fetch(basis_at_ords_ho, n)); } @@ -158,21 +157,21 @@ init_quad_values(int cdim, const struct gkyl_basis *basis, return tot_quad; } -static void -gkyl_vlasov_lte_proj_on_basis_geom_quad_vars(gkyl_vlasov_lte_proj_on_basis *up, - const struct gkyl_range *conf_range, const struct gkyl_array *h_ij, - const struct gkyl_array *h_ij_inv, const struct gkyl_array *det_h) +static void gkyl_vlasov_lte_proj_on_basis_geom_quad_vars( + gkyl_vlasov_lte_proj_on_basis *up, const struct gkyl_range *conf_range, + const struct gkyl_array *h_ij, const struct gkyl_array *h_ij_inv, const struct gkyl_array *det_h +) { -// Setup the intial geometric vars, on GPU +// Setup the intial geometric vars, on GPU #ifdef GKYL_HAVE_CUDA - if (up->use_gpu) - return gkyl_vlasov_lte_proj_on_basis_geom_quad_vars_cu(up, conf_range, h_ij, - h_ij_inv, det_h); + if (up->use_gpu) { + return gkyl_vlasov_lte_proj_on_basis_geom_quad_vars_cu(up, conf_range, h_ij, h_ij_inv, det_h); + } #endif // Otherwise run the CPU Version to setup h_ij, h_ij_inv, det_h int cdim = up->cdim, pdim = up->pdim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int tot_conf_quad = up->tot_conf_quad; int num_conf_basis = up->num_conf_basis; @@ -192,23 +191,22 @@ gkyl_vlasov_lte_proj_on_basis_geom_quad_vars(gkyl_vlasov_lte_proj_on_basis *up, double *h_ij_inv_quad = gkyl_array_fetch(up->h_ij_inv_quad, midx); double *det_h_quad = gkyl_array_fetch(up->det_h_quad, midx); - // Sum over basis - for (int n=0; nconf_basis_at_ords, n); - for (int k=0; kvel_map = gkyl_velocity_map_acquire(inp->vel_map); } - int num_quad = up->conf_basis.poly_order+1; - // initialize data needed for conf-space quadrature - up->tot_conf_quad = init_quad_values(up->cdim, &up->conf_basis, - inp->quad_type, num_quad, - &up->conf_ordinates, &up->conf_weights, &up->conf_basis_at_ords, false); + int num_quad = up->conf_basis.poly_order + 1; + // initialize data needed for conf-space quadrature + up->tot_conf_quad = init_quad_values( + up->cdim, &up->conf_basis, inp->quad_type, num_quad, &up->conf_ordinates, &up->conf_weights, + &up->conf_basis_at_ords, false + ); - // initialize data needed for phase-space quadrature - up->tot_quad = init_quad_values(up->cdim, &up->phase_basis, - inp->quad_type, num_quad, - &up->ordinates, &up->weights, &up->basis_at_ords, false); + // initialize data needed for phase-space quadrature + up->tot_quad = init_quad_values( + up->cdim, &up->phase_basis, inp->quad_type, num_quad, &up->ordinates, &up->weights, + &up->basis_at_ords, false + ); - up->fun_at_ords = gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad); // Only used in CPU implementation. + up->fun_at_ords = + gkyl_array_new(GKYL_DOUBLE, 1, up->tot_quad); // Only used in CPU implementation. // To avoid creating iterators over ranges in device kernel, we'll // create a map between phase-space and conf-space ordinates. - int num_quad_v = num_quad; // Hybrid basis have p=2 in velocity space. + int num_quad_v = num_quad; // Hybrid basis have p=2 in velocity space. // hybrid basis have p=2 in velocity space. - bool is_vdim_p2[] = {false, false, false}; // 3 is the max vdim. + bool is_vdim_p2[] = {false, false, false}; // 3 is the max vdim. if (up->phase_basis.b_type == GKYL_BASIS_MODAL_HYBRID) { - num_quad_v = num_quad+1; - for (int d=0; duse_gpu) { - up->num_ratio = gkyl_array_cu_dev_new(GKYL_DOUBLE, up->conf_basis.num_basis, conf_local_ext_ncells); + up->num_ratio = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->conf_basis.num_basis, conf_local_ext_ncells); up->mem = gkyl_dg_bin_op_mem_cu_dev_new(conf_local_ncells, up->conf_basis.num_basis); - } - else { + } else { up->num_ratio = gkyl_array_new(GKYL_DOUBLE, up->conf_basis.num_basis, conf_local_ext_ncells); up->mem = gkyl_dg_bin_op_mem_new(conf_local_ncells, up->conf_basis.num_basis); } @@ -274,55 +275,65 @@ gkyl_vlasov_lte_proj_on_basis_inew(const struct gkyl_vlasov_lte_proj_on_basis_in // Allocate device copies of arrays needed for quadrature. int p2c_qidx_ho[up->phase_qrange.volume]; - up->p2c_qidx = (int*) gkyl_cu_malloc(sizeof(int)*up->phase_qrange.volume); + up->p2c_qidx = (int *)gkyl_cu_malloc(sizeof(int) * up->phase_qrange.volume); // Allocate f_lte_quad at phase-space quadrature points // moms_lte_quad (n, V_drift, T/m) at configuration-space quadrature points. // expamp_quad, the exponential pre-factor in the LTE distribution, at quadrature points. - up->f_lte_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->tot_quad, inp->conf_range_ext->volume*inp->vel_range->volume); - up->moms_lte_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->tot_conf_quad*(vdim+2), inp->conf_range_ext->volume); - up->expamp_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->tot_conf_quad, inp->conf_range_ext->volume); + up->f_lte_quad = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->tot_quad, inp->conf_range_ext->volume * inp->vel_range->volume + ); + up->moms_lte_quad = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->tot_conf_quad * (vdim + 2), inp->conf_range_ext->volume + ); + up->expamp_quad = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->tot_conf_quad, inp->conf_range_ext->volume); // Allocate the memory for computing the specific phase nodal to modal calculation struct gkyl_mat_mm_array_mem *phase_nodal_to_modal_mem_ho; - phase_nodal_to_modal_mem_ho = gkyl_mat_mm_array_mem_new(up->num_phase_basis, up->tot_quad, 1.0, 0.0, - GKYL_NO_TRANS, GKYL_NO_TRANS, false); + phase_nodal_to_modal_mem_ho = gkyl_mat_mm_array_mem_new( + up->num_phase_basis, up->tot_quad, 1.0, 0.0, GKYL_NO_TRANS, GKYL_NO_TRANS, false + ); // Compute the matrix A for the phase nodal to modal memory - const double *phase_w = (const double*) up->weights->data; - const double *phaseb_o = (const double*) up->basis_at_ords->data; - for (int n=0; ntot_quad; ++n){ - for (int k=0; knum_phase_basis; ++k){ - gkyl_mat_set(phase_nodal_to_modal_mem_ho->A, k, n, phase_w[n]*phaseb_o[k+up->num_phase_basis*n]); + const double *phase_w = (const double *)up->weights->data; + const double *phaseb_o = (const double *)up->basis_at_ords->data; + for (int n = 0; n < up->tot_quad; ++n) { + for (int k = 0; k < up->num_phase_basis; ++k) { + gkyl_mat_set( + phase_nodal_to_modal_mem_ho->A, k, n, phase_w[n] * phaseb_o[k + up->num_phase_basis * n] + ); } } - + // copy to device - up->phase_nodal_to_modal_mem = gkyl_mat_mm_array_mem_new(up->num_phase_basis, up->tot_quad, 1.0, 0.0, - GKYL_NO_TRANS, GKYL_NO_TRANS, up->use_gpu); + up->phase_nodal_to_modal_mem = gkyl_mat_mm_array_mem_new( + up->num_phase_basis, up->tot_quad, 1.0, 0.0, GKYL_NO_TRANS, GKYL_NO_TRANS, up->use_gpu + ); gkyl_mat_copy(up->phase_nodal_to_modal_mem->A, phase_nodal_to_modal_mem_ho->A); gkyl_mat_mm_array_mem_release(phase_nodal_to_modal_mem_ho); - // initialize data needed for conf-space quadrature on device - up->tot_conf_quad = init_quad_values(up->cdim, &up->conf_basis, - inp->quad_type, num_quad, - &up->conf_ordinates, &up->conf_weights, &up->conf_basis_at_ords, up->use_gpu); + // initialize data needed for conf-space quadrature on device + up->tot_conf_quad = init_quad_values( + up->cdim, &up->conf_basis, inp->quad_type, num_quad, &up->conf_ordinates, &up->conf_weights, + &up->conf_basis_at_ords, up->use_gpu + ); - // initialize data needed for phase-space quadrature on device - up->tot_quad = init_quad_values(up->cdim, &up->phase_basis, - inp->quad_type, num_quad, - &up->ordinates, &up->weights, &up->basis_at_ords, up->use_gpu); + // initialize data needed for phase-space quadrature on device + up->tot_quad = init_quad_values( + up->cdim, &up->phase_basis, inp->quad_type, num_quad, &up->ordinates, &up->weights, + &up->basis_at_ords, up->use_gpu + ); int pidx[GKYL_MAX_DIM]; - for (int n=0; ntot_quad; ++n) { + for (int n = 0; n < up->tot_quad; ++n) { gkyl_range_inv_idx(&up->phase_qrange, n, pidx); int cqidx = gkyl_range_idx(&up->conf_qrange, pidx); p2c_qidx_ho[n] = cqidx; } - gkyl_cu_memcpy(up->p2c_qidx, p2c_qidx_ho, sizeof(int)*up->phase_qrange.volume, GKYL_CU_MEMCPY_H2D); + gkyl_cu_memcpy( + up->p2c_qidx, p2c_qidx_ho, sizeof(int) * up->phase_qrange.volume, GKYL_CU_MEMCPY_H2D + ); } #endif @@ -336,26 +347,30 @@ gkyl_vlasov_lte_proj_on_basis_inew(const struct gkyl_vlasov_lte_proj_on_basis_in up->is_canonical_pb = true; // Allocate and obtain geometric variables at quadrature points for canonical-pb // since these quantities are time-independent. - if (up->use_gpu) { - up->h_ij_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->tot_conf_quad*(vdim*(vdim+1)/2), inp->conf_range_ext->volume); - up->h_ij_inv_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->tot_conf_quad*(vdim*(vdim+1)/2), inp->conf_range_ext->volume); - up->det_h_quad = gkyl_array_cu_dev_new(GKYL_DOUBLE, - up->tot_conf_quad, inp->conf_range_ext->volume); + if (up->use_gpu) { + up->h_ij_quad = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->tot_conf_quad * (vdim * (vdim + 1) / 2), inp->conf_range_ext->volume + ); + up->h_ij_inv_quad = gkyl_array_cu_dev_new( + GKYL_DOUBLE, up->tot_conf_quad * (vdim * (vdim + 1) / 2), inp->conf_range_ext->volume + ); + up->det_h_quad = + gkyl_array_cu_dev_new(GKYL_DOUBLE, up->tot_conf_quad, inp->conf_range_ext->volume); + } else { + up->h_ij_quad = gkyl_array_new( + GKYL_DOUBLE, up->tot_conf_quad * (vdim * (vdim + 1) / 2), inp->conf_range_ext->volume + ); + up->h_ij_inv_quad = gkyl_array_new( + GKYL_DOUBLE, up->tot_conf_quad * (vdim * (vdim + 1) / 2), inp->conf_range_ext->volume + ); + up->det_h_quad = gkyl_array_new(GKYL_DOUBLE, up->tot_conf_quad, inp->conf_range_ext->volume); } - else { - up->h_ij_quad = gkyl_array_new(GKYL_DOUBLE, - up->tot_conf_quad*(vdim*(vdim+1)/2), inp->conf_range_ext->volume); - up->h_ij_inv_quad = gkyl_array_new(GKYL_DOUBLE, - up->tot_conf_quad*(vdim*(vdim+1)/2), inp->conf_range_ext->volume); - up->det_h_quad = gkyl_array_new(GKYL_DOUBLE, - up->tot_conf_quad, inp->conf_range_ext->volume); - } - gkyl_array_clear(up->h_ij_quad, 0.0); - gkyl_array_clear(up->h_ij_inv_quad, 0.0); - gkyl_array_clear(up->det_h_quad, 0.0); - gkyl_vlasov_lte_proj_on_basis_geom_quad_vars(up, inp->conf_range, inp->h_ij, inp->h_ij_inv, inp->det_h); + gkyl_array_clear(up->h_ij_quad, 0.0); + gkyl_array_clear(up->h_ij_inv_quad, 0.0); + gkyl_array_clear(up->det_h_quad, 0.0); + gkyl_vlasov_lte_proj_on_basis_geom_quad_vars( + up, inp->conf_range, inp->h_ij, inp->h_ij_inv, inp->det_h + ); } // Store a LTE moment calculation updater to compute and correct the density @@ -365,7 +380,7 @@ gkyl_vlasov_lte_proj_on_basis_inew(const struct gkyl_vlasov_lte_proj_on_basis_in .conf_basis = inp->conf_basis, .vel_basis = inp->vel_basis, .phase_basis = inp->phase_basis, - .conf_range = inp->conf_range, + .conf_range = inp->conf_range, .conf_range_ext = inp->conf_range_ext, .vel_range = inp->vel_range, .phase_range = inp->phase_range, @@ -376,49 +391,52 @@ gkyl_vlasov_lte_proj_on_basis_inew(const struct gkyl_vlasov_lte_proj_on_basis_in .det_h = inp->det_h, .hamil = inp->hamil, .model_id = inp->model_id, - .use_gpu = inp->use_gpu, + .use_gpu = inp->use_gpu }; - up->moments_up = gkyl_vlasov_lte_moments_inew( &inp_mom ); + up->moments_up = gkyl_vlasov_lte_moments_inew(&inp_mom); return up; } -static void -proj_on_basis(const gkyl_vlasov_lte_proj_on_basis *up, const struct gkyl_array *fun_at_ords, double* f) +static void proj_on_basis( + const gkyl_vlasov_lte_proj_on_basis *up, const struct gkyl_array *fun_at_ords, double *f +) { int num_basis = up->num_phase_basis; int tot_quad = up->tot_quad; - const double* GKYL_RESTRICT weights = up->weights->data; - const double* GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; - const double* GKYL_RESTRICT func_at_ords = fun_at_ords->data; + const double *GKYL_RESTRICT weights = up->weights->data; + const double *GKYL_RESTRICT basis_at_ords = up->basis_at_ords->data; + const double *GKYL_RESTRICT func_at_ords = fun_at_ords->data; + + for (int k = 0; k < num_basis; ++k) { + f[k] = 0.0; + } - for (int k=0; kuse_gpu) + if (up->use_gpu) { return gkyl_vlasov_lte_proj_on_basis_advance_cu(up, phase_range, conf_range, moms_lte, f_lte); + } #endif - double f_floor = 1.e-40; + double f_floor = 1.e-40; int cdim = up->cdim, pdim = up->pdim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int tot_quad = up->tot_quad; - int num_phase_basis = up->num_phase_basis; + int num_phase_basis = up->num_phase_basis; int tot_conf_quad = up->tot_conf_quad; int num_conf_basis = up->num_conf_basis; @@ -426,8 +444,10 @@ gkyl_vlasov_lte_proj_on_basis_advance(gkyl_vlasov_lte_proj_on_basis *up, struct gkyl_range vel_rng; struct gkyl_range_iter conf_iter, vel_iter; - int pidx[GKYL_MAX_DIM], rem_dir[GKYL_MAX_DIM] = { 0 }; - for (int d=0; dndim; ++d) rem_dir[d] = 1; + int pidx[GKYL_MAX_DIM], rem_dir[GKYL_MAX_DIM] = {0}; + for (int d = 0; d < conf_range->ndim; ++d) { + rem_dir[d] = 1; + } double xc[GKYL_MAX_DIM], xmu[GKYL_MAX_DIM]; double n_quad[tot_conf_quad], V_drift_quad[tot_conf_quad][vdim], T_over_m_quad[tot_conf_quad]; @@ -442,50 +462,48 @@ gkyl_vlasov_lte_proj_on_basis_advance(gkyl_vlasov_lte_proj_on_basis *up, const double *moms_lte_d = gkyl_array_cfetch(moms_lte, midx); const double *n_d = moms_lte_d; const double *V_drift_d = &moms_lte_d[num_conf_basis]; - const double *T_over_m_d = &moms_lte_d[num_conf_basis*(vdim+1)]; + const double *T_over_m_d = &moms_lte_d[num_conf_basis * (vdim + 1)]; // Sum over basis for given LTE moments (n, V_drift, T/m) in the stationary frame - for (int n=0; nconf_basis_at_ords, n); // Zero out quadrature values n_quad[n] = 0.0; - for (int d=0; d 0.0) && (T_over_m_quad[n] > 0.0)) { if (up->is_relativistic) { - expamp_quad[n] = n_quad[n]*(1.0/(4.0*GKYL_PI*T_over_m_quad[n]))*(sqrt(2.0*T_over_m_quad[n]/GKYL_PI)); - } - else if (up->is_canonical_pb) { + expamp_quad[n] = n_quad[n] * (1.0 / (4.0 * GKYL_PI * T_over_m_quad[n])) * + (sqrt(2.0 * T_over_m_quad[n] / GKYL_PI)); + } else if (up->is_canonical_pb) { const double *det_h_quad = gkyl_array_cfetch(up->det_h_quad, midx); - expamp_quad[n] = (1.0/det_h_quad[n])*n_quad[n]/sqrt(pow(2.0*GKYL_PI*T_over_m_quad[n], vdim)); - } - else { - expamp_quad[n] = n_quad[n]/sqrt(pow(2.0*GKYL_PI*T_over_m_quad[n], vdim)); + expamp_quad[n] = + (1.0 / det_h_quad[n]) * n_quad[n] / sqrt(pow(2.0 * GKYL_PI * T_over_m_quad[n], vdim)); + } else { + expamp_quad[n] = n_quad[n] / sqrt(pow(2.0 * GKYL_PI * T_over_m_quad[n], vdim)); } - } - else { + } else { expamp_quad[n] = 0.0; - } + } } // inner loop over velocity space gkyl_range_deflate(&vel_rng, phase_range, rem_dir, conf_iter.idx); gkyl_range_iter_no_split_init(&vel_iter, &vel_rng); while (gkyl_range_iter_next(&vel_iter)) { - copy_idx_arrays(conf_range->ndim, phase_range->ndim, conf_iter.idx, vel_iter.idx, pidx); gkyl_rect_grid_cell_center(&up->phase_grid, pidx, xc); @@ -493,7 +511,6 @@ gkyl_vlasov_lte_proj_on_basis_advance(gkyl_vlasov_lte_proj_on_basis *up, // compute LTE distribution function at phase-space quadrature nodes gkyl_range_iter_init(&qiter, &up->phase_qrange); while (gkyl_range_iter_next(&qiter)) { - int cqidx = gkyl_range_idx(&up->conf_qrange, qiter.idx); int pqidx = gkyl_range_idx(&up->phase_qrange, qiter.idx); @@ -509,39 +526,42 @@ gkyl_vlasov_lte_proj_on_basis_advance(gkyl_vlasov_lte_proj_on_basis *up, double vu = 0.0; double uu = 0.0; // V_drift_quad is the spatial component of the four-velocity u_i = GammaV*V_drift - for (int d=0; dis_canonical_pb) { + fq[0] += expamp_quad[cqidx] * + exp( + (1.0 / T_over_m_quad[cqidx]) - + (1.0 / T_over_m_quad[cqidx]) * (GammaV_quad * sqrt(1.0 + uu) - vu) + ); + } else if (up->is_canonical_pb) { // Assumes a (particle) hamiltonian in canocial form: H = 1/2 g^{ij} p_i p_j const double *h_ij_inv_quad = gkyl_array_cfetch(up->h_ij_inv_quad, midx); double efact = 0.0; - for (int d0=0; d0moments_up, phase_range, conf_range, - f_lte, up->num_ratio); + // we construct through an expansion of the Bessel functions to avoid finite + // precision effects in such a way that we can recover arbitrary temperature + // relativistic LTE distributions by rescaling the distribution to the desired density. + gkyl_vlasov_lte_density_moment_advance( + up->moments_up, phase_range, conf_range, f_lte, up->num_ratio + ); // compute number density ratio: num_ratio = n/n0 // 0th component of moms_target is the target density - gkyl_dg_div_op_range(up->mem, &up->conf_basis, 0, up->num_ratio, - 0, moms_lte, 0, up->num_ratio, conf_range); + gkyl_dg_div_op_range( + up->mem, &up->conf_basis, 0, up->num_ratio, 0, moms_lte, 0, up->num_ratio, conf_range + ); // rescale distribution function - gkyl_dg_mul_conf_phase_op_range(&up->conf_basis, &up->phase_basis, - f_lte, up->num_ratio, f_lte, conf_range, phase_range); + gkyl_dg_mul_conf_phase_op_range( + &up->conf_basis, &up->phase_basis, f_lte, up->num_ratio, f_lte, conf_range, phase_range + ); } -void -gkyl_vlasov_lte_proj_on_basis_release(gkyl_vlasov_lte_proj_on_basis* up) +void gkyl_vlasov_lte_proj_on_basis_release(gkyl_vlasov_lte_proj_on_basis *up) { if (up->vel_map != 0) { gkyl_velocity_map_release(up->vel_map); diff --git a/vlasov/zero/vlasov_lte_proj_on_basis_cu.cu b/vlasov/zero/vlasov_lte_proj_on_basis_cu.cu index 03f5d83d08..bb990eb933 100644 --- a/vlasov/zero/vlasov_lte_proj_on_basis_cu.cu +++ b/vlasov/zero/vlasov_lte_proj_on_basis_cu.cu @@ -16,135 +16,135 @@ extern "C" { #include } -__global__ static void -gkyl_vlasov_lte_proj_on_basis_geom_quad_vars_cu_ker(struct gkyl_range conf_range, - const struct gkyl_array* conf_basis_at_ords, int vdim, const struct gkyl_array* h_ij, - const struct gkyl_array* h_ij_inv, const struct gkyl_array* det_h, - struct gkyl_array* h_ij_quad_d, struct gkyl_array* h_ij_inv_quad_d, struct gkyl_array* det_h_quad_d) -{ +__global__ static void gkyl_vlasov_lte_proj_on_basis_geom_quad_vars_cu_ker( + struct gkyl_range conf_range, const struct gkyl_array *conf_basis_at_ords, int vdim, + const struct gkyl_array *h_ij, const struct gkyl_array *h_ij_inv, const struct gkyl_array *det_h, + struct gkyl_array *h_ij_quad_d, struct gkyl_array *h_ij_inv_quad_d, + struct gkyl_array *det_h_quad_d +) +{ int num_conf_basis = conf_basis_at_ords->ncomp; int tot_conf_quad = conf_basis_at_ords->size; int cidx[GKYL_MAX_CDIM]; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_range.volume; tid += blockDim.x*gridDim.x) { + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_range, tid, cidx); long lincC = gkyl_range_idx(&conf_range, cidx); - const double *h_ij_d = (const double*) gkyl_array_cfetch(h_ij, lincC); - const double *h_ij_inv_d = (const double*) gkyl_array_cfetch(h_ij_inv, lincC); - const double *det_h_d = (const double*) gkyl_array_cfetch(det_h, lincC); - - double *h_ij_quad = (double*) gkyl_array_fetch(h_ij_quad_d, lincC); - double *h_ij_inv_quad = (double*) gkyl_array_fetch(h_ij_inv_quad_d, lincC); - double *det_h_quad = (double*) gkyl_array_fetch(det_h_quad_d, lincC); - - // Sum over basis for the geometric quantities at configuration-space quadrature points. - for (int n=0; npdim - up->cdim; int nblocks = conf_range->nblocks, nthreads = conf_range->nthreads; - gkyl_vlasov_lte_proj_on_basis_geom_quad_vars_cu_ker<<>>(*conf_range, - up->conf_basis_at_ords->on_dev, vdim, h_ij->on_dev, - h_ij_inv->on_dev, det_h->on_dev, up->h_ij_quad->on_dev, - up->h_ij_inv_quad->on_dev, up->det_h_quad->on_dev); + gkyl_vlasov_lte_proj_on_basis_geom_quad_vars_cu_ker<< > >( + *conf_range, up->conf_basis_at_ords->on_dev, vdim, h_ij->on_dev, h_ij_inv->on_dev, + det_h->on_dev, up->h_ij_quad->on_dev, up->h_ij_inv_quad->on_dev, up->det_h_quad->on_dev + ); } -static void -gkyl_parallelize_components_kernel_launch_dims(dim3* dimGrid, dim3* dimBlock, gkyl_range range, int ncomp) +static void gkyl_parallelize_components_kernel_launch_dims( + dim3 *dimGrid, dim3 *dimBlock, gkyl_range range, int ncomp +) { - // Create a 2D thread grid so we launch ncomp*range.volume number of threads + // Create a 2D thread grid so we launch ncomp*range.volume number of threads // so we can parallelize over components too dimBlock->y = ncomp; // ncomp *must* be less than 256 dimGrid->y = 1; - dimBlock->x = GKYL_DEFAULT_NUM_THREADS/ncomp; + dimBlock->x = GKYL_DEFAULT_NUM_THREADS / ncomp; dimGrid->x = gkyl_int_div_up(range.volume, dimBlock->x); } -__global__ static void -gkyl_vlasov_lte_proj_on_basis_moms_lte_quad_ker(struct gkyl_range conf_range, int vdim, - const struct gkyl_array* conf_basis_at_ords, - const struct gkyl_array* moms_lte, const struct gkyl_array* det_h_quad, - bool is_relativistic, bool is_canonical_pb, - struct gkyl_array* moms_lte_quad, struct gkyl_array* expamp_quad) +__global__ static void gkyl_vlasov_lte_proj_on_basis_moms_lte_quad_ker( + struct gkyl_range conf_range, int vdim, const struct gkyl_array *conf_basis_at_ords, + const struct gkyl_array *moms_lte, const struct gkyl_array *det_h_quad, bool is_relativistic, + bool is_canonical_pb, struct gkyl_array *moms_lte_quad, struct gkyl_array *expamp_quad +) { int num_conf_basis = conf_basis_at_ords->ncomp; - int tot_conf_quad = conf_basis_at_ords->size; + int tot_conf_quad = conf_basis_at_ords->size; int cidx[GKYL_MAX_CDIM]; // 2D thread grid // linc2 goes from 0 to tot_conf_quad - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < conf_range.volume; tid += blockDim.x*gridDim.x) { + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < conf_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&conf_range, tid, cidx); long lincC = gkyl_range_idx(&conf_range, cidx); - const double *moms_lte_d = (const double*) gkyl_array_cfetch(moms_lte, lincC); + const double *moms_lte_d = (const double *)gkyl_array_cfetch(moms_lte, lincC); - double *moms_lte_quad_d = (double*) gkyl_array_fetch(moms_lte_quad, lincC); + double *moms_lte_quad_d = (double *)gkyl_array_fetch(moms_lte_quad, lincC); // Sum over basis for given LTE moments (n, V_drift, T/m) in the stationary frame - // at configuration-space quadrature points. - const double *b_ord = (const double*) gkyl_array_cfetch(conf_basis_at_ords, linc2); - for (int k=0; k 0.0) && (T_over_m_quad[linc2] > 0.0)) { if (is_relativistic) { - expamp_quad_d[linc2] = n_quad[linc2]*(1.0/(4.0*GKYL_PI*T_over_m_quad[linc2]))*(sqrt(2.0*T_over_m_quad[linc2]/GKYL_PI)); - } - else if (is_canonical_pb) { - const double *det_h_quad_d = (const double*) gkyl_array_cfetch(det_h_quad, lincC); - expamp_quad_d[linc2] = (1.0/det_h_quad_d[linc2])*n_quad[linc2]/sqrt(pow(2.0*GKYL_PI*T_over_m_quad[linc2], vdim)); + expamp_quad_d[linc2] = n_quad[linc2] * (1.0 / (4.0 * GKYL_PI * T_over_m_quad[linc2])) * + (sqrt(2.0 * T_over_m_quad[linc2] / GKYL_PI)); + } else if (is_canonical_pb) { + const double *det_h_quad_d = (const double *)gkyl_array_cfetch(det_h_quad, lincC); + expamp_quad_d[linc2] = (1.0 / det_h_quad_d[linc2]) * n_quad[linc2] / + sqrt(pow(2.0 * GKYL_PI * T_over_m_quad[linc2], vdim)); + } else { + expamp_quad_d[linc2] = + n_quad[linc2] / sqrt(pow(2.0 * GKYL_PI * T_over_m_quad[linc2], vdim)); } - else { - expamp_quad_d[linc2] = n_quad[linc2]/sqrt(pow(2.0*GKYL_PI*T_over_m_quad[linc2], vdim)); - } - } - else { + } else { expamp_quad_d[linc2] = 0.0; - } + } } } -__global__ static void -gkyl_vlasov_lte_proj_on_basis_f_lte_quad_ker(struct gkyl_rect_grid phase_grid, - struct gkyl_range phase_range, struct gkyl_range conf_range, - const struct gkyl_array* conf_basis_at_ords, const struct gkyl_array* phase_ordinates, - const struct gkyl_array* moms_lte_quad, const struct gkyl_array* expamp_quad, - const struct gkyl_array* h_ij_inv_quad, - const int *p2c_qidx, bool is_relativistic, bool is_canonical_pb, - struct gkyl_array* f_lte_quad) +__global__ static void gkyl_vlasov_lte_proj_on_basis_f_lte_quad_ker( + struct gkyl_rect_grid phase_grid, struct gkyl_range phase_range, struct gkyl_range conf_range, + const struct gkyl_array *conf_basis_at_ords, const struct gkyl_array *phase_ordinates, + const struct gkyl_array *moms_lte_quad, const struct gkyl_array *expamp_quad, + const struct gkyl_array *h_ij_inv_quad, const int *p2c_qidx, bool is_relativistic, + bool is_canonical_pb, struct gkyl_array *f_lte_quad +) { double f_floor = 1.0e-40; int pdim = phase_range.ndim, cdim = conf_range.ndim; - int vdim = pdim-cdim; + int vdim = pdim - cdim; int tot_conf_quad = conf_basis_at_ords->size; double xc[GKYL_MAX_DIM], xmu[GKYL_MAX_DIM]; @@ -152,9 +152,9 @@ gkyl_vlasov_lte_proj_on_basis_f_lte_quad_ker(struct gkyl_rect_grid phase_grid, // 2D thread grid // linc2 goes from 0 to tot_phase_quad - long linc2 = threadIdx.y + blockIdx.y*blockDim.y; - for(unsigned long tid = threadIdx.x + blockIdx.x*blockDim.x; - tid < phase_range.volume; tid += blockDim.x*gridDim.x) { + long linc2 = threadIdx.y + blockIdx.y * blockDim.y; + for (unsigned long tid = threadIdx.x + blockIdx.x * blockDim.x; tid < phase_range.volume; + tid += blockDim.x * gridDim.x) { gkyl_sub_range_inv_idx(&phase_range, tid, pidx); // get configuration-space linear index. @@ -164,21 +164,22 @@ gkyl_vlasov_lte_proj_on_basis_f_lte_quad_ker(struct gkyl_rect_grid phase_grid, long lincC = gkyl_range_idx(&conf_range, cidx); // Fetch V_drift and T/m; density dependence already included in expamp_quad - const double *moms_lte_quad_d = (const double*) gkyl_array_cfetch(moms_lte_quad, lincC); + const double *moms_lte_quad_d = (const double *)gkyl_array_cfetch(moms_lte_quad, lincC); const double *V_drift_quad = &moms_lte_quad_d[tot_conf_quad]; - const double *T_over_m_quad = &moms_lte_quad_d[tot_conf_quad*(vdim+1)]; + const double *T_over_m_quad = &moms_lte_quad_d[tot_conf_quad * (vdim + 1)]; - const double *expamp_quad_d = (const double*) gkyl_array_cfetch(expamp_quad, lincC); + const double *expamp_quad_d = (const double *)gkyl_array_cfetch(expamp_quad, lincC); gkyl_rect_grid_cell_center(&phase_grid, pidx, xc); long lidx = gkyl_range_idx(&phase_range, pidx); // Select for a phase space index fq - double *fq = (double*) gkyl_array_fetch(f_lte_quad, lidx); + double *fq = (double *)gkyl_array_fetch(f_lte_quad, lidx); int cqidx = p2c_qidx[linc2]; - comp_to_phys(pdim, (const double*) gkyl_array_cfetch(phase_ordinates, linc2), - phase_grid.dx, xc, &xmu[0]); + comp_to_phys( + pdim, (const double *)gkyl_array_cfetch(phase_ordinates, linc2), phase_grid.dx, xc, &xmu[0] + ); fq[linc2] = f_floor; if (T_over_m_quad[cqidx] > 0.0) { @@ -187,90 +188,97 @@ gkyl_vlasov_lte_proj_on_basis_f_lte_quad_ker(struct gkyl_rect_grid phase_grid, double vu = 0.0; double uu = 0.0; // V_drift_quad is the spatial component of the four-velocity u_i = GammaV*V_drift - for (int d=0; dpdim - up->cdim; - gkyl_array_clear(up->moms_lte_quad, 0.0); + gkyl_array_clear(up->moms_lte_quad, 0.0); dim3 dimGrid_conf, dimBlock_conf; int tot_conf_quad = up->conf_basis_at_ords->size; - gkyl_parallelize_components_kernel_launch_dims(&dimGrid_conf, &dimBlock_conf, *conf_range, tot_conf_quad); - gkyl_vlasov_lte_proj_on_basis_moms_lte_quad_ker<<>>(*conf_range, - vdim, up->conf_basis_at_ords->on_dev, - moms_lte->on_dev, - up->is_canonical_pb ? up->det_h_quad->on_dev : 0, - up->is_relativistic, up->is_canonical_pb, - up->moms_lte_quad->on_dev, up->expamp_quad->on_dev); + gkyl_parallelize_components_kernel_launch_dims( + &dimGrid_conf, &dimBlock_conf, *conf_range, tot_conf_quad + ); + gkyl_vlasov_lte_proj_on_basis_moms_lte_quad_ker<< > >( + *conf_range, vdim, up->conf_basis_at_ords->on_dev, moms_lte->on_dev, + up->is_canonical_pb ? up->det_h_quad->on_dev : 0, up->is_relativistic, up->is_canonical_pb, + up->moms_lte_quad->on_dev, up->expamp_quad->on_dev + ); dim3 dimGrid, dimBlock; int tot_phase_quad = up->basis_at_ords->size; gkyl_parallelize_components_kernel_launch_dims(&dimGrid, &dimBlock, *phase_range, tot_phase_quad); - gkyl_vlasov_lte_proj_on_basis_f_lte_quad_ker<<>>(up->phase_grid, - *phase_range, *conf_range, - up->conf_basis_at_ords->on_dev, up->ordinates->on_dev, - up->moms_lte_quad->on_dev, up->expamp_quad->on_dev, - up->is_canonical_pb ? up->h_ij_inv_quad->on_dev : 0, - up->p2c_qidx, up->is_relativistic, up->is_canonical_pb, - up->f_lte_quad->on_dev); + gkyl_vlasov_lte_proj_on_basis_f_lte_quad_ker<< > >( + up->phase_grid, *phase_range, *conf_range, up->conf_basis_at_ords->on_dev, + up->ordinates->on_dev, up->moms_lte_quad->on_dev, up->expamp_quad->on_dev, + up->is_canonical_pb ? up->h_ij_inv_quad->on_dev : 0, up->p2c_qidx, up->is_relativistic, + up->is_canonical_pb, up->f_lte_quad->on_dev + ); // Call cublas to do the matrix multiplication nodal to modal conversion gkyl_mat_mm_array(up->phase_nodal_to_modal_mem, up->f_lte_quad, f_lte); // Correct the density of the projected LTE distribution function through rescaling. // This correction is needed especially for the relativistic LTE, whose pre-factor - // we construct through an expansion of the Bessel functions to avoid finite - // precision effects in such a way that we can recover arbitrary temperature - // relativistic LTE distributions by rescaling the distribution to the desired density. - gkyl_vlasov_lte_density_moment_advance(up->moments_up, phase_range, conf_range, - f_lte, up->num_ratio); + // we construct through an expansion of the Bessel functions to avoid finite + // precision effects in such a way that we can recover arbitrary temperature + // relativistic LTE distributions by rescaling the distribution to the desired density. + gkyl_vlasov_lte_density_moment_advance( + up->moments_up, phase_range, conf_range, f_lte, up->num_ratio + ); // compute number density ratio: num_ratio = n/n0 // 0th component of moms_target is the target density - gkyl_dg_div_op_range(up->mem, &up->conf_basis, 0, up->num_ratio, - 0, moms_lte, 0, up->num_ratio, conf_range); + gkyl_dg_div_op_range( + up->mem, &up->conf_basis, 0, up->num_ratio, 0, moms_lte, 0, up->num_ratio, conf_range + ); // rescale distribution function - gkyl_dg_mul_conf_phase_op_range(&up->conf_basis, &up->phase_basis, - f_lte, up->num_ratio, f_lte, conf_range, phase_range); + gkyl_dg_mul_conf_phase_op_range( + &up->conf_basis, &up->phase_basis, f_lte, up->num_ratio, f_lte, conf_range, phase_range + ); }